store

package
v0.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReviewStatusAwaitingReview = "awaiting_review"
	ReviewStatusRevising       = "revising"
	ReviewStatusApproved       = "approved"
	ReviewStatusCancelled      = "cancelled"
)

Review session statuses

View Source
const (
	CommentStatusOpen     = "open"
	CommentStatusResolved = "resolved"
	CommentStatusOrphan   = "orphaned"
)

Comment statuses

View Source
const (
	ReviewEventCommentAdded      = "comment_added"
	ReviewEventReplyAdded        = "reply_added"
	ReviewEventRevisionSubmitted = "revision_submitted"
	ReviewEventApproved          = "approved"
	ReviewEventCancelled         = "cancelled"
	ReviewEventRevisionRequested = "revision_requested"
)

Review event kinds

View Source
const (
	MaxLimit     = 1000
	DefaultLimit = 100
)

Limits for query bounds

Variables

This section is empty.

Functions

func PetArt added in v0.12.0

func PetArt(species string, alive bool) string

PetArt returns the ASCII art string for a pet given its species and alive state.

Types

type AnalyticsData added in v0.9.1

type AnalyticsData struct {
	FactsByDate      []DateCount    `json:"facts_by_date"`
	MessagesByDate   []DateCount    `json:"messages_by_date"`
	SessionsByDate   []DateCount    `json:"sessions_by_date"`
	FactsByDirectory map[string]int `json:"facts_by_directory"`
	TotalFacts       int            `json:"total_facts"`
	TotalMessages    int            `json:"total_messages"`
	TotalSessions    int            `json:"total_sessions"`
	FactsThisWeek    int            `json:"facts_this_week"`
	FactsLastWeek    int            `json:"facts_last_week"`
	MessagesThisWeek int            `json:"messages_this_week"`
	MessagesLastWeek int            `json:"messages_last_week"`
}

type BulkFact added in v0.8.4

type BulkFact struct {
	Content string   `json:"content"`
	Tags    []string `json:"tags,omitempty"`
}

type ContextWindowData added in v0.9.1

type ContextWindowData struct {
	InstanceID    string              `json:"instance_id"`
	Directory     string              `json:"directory"`
	TotalTokens   int                 `json:"total_tokens"`
	MaxTokens     int                 `json:"max_tokens"` // 200000
	FactCount     int                 `json:"fact_count"`
	FactTokens    int                 `json:"fact_tokens"`
	MessageCount  int                 `json:"message_count"`
	MessageTokens int                 `json:"message_tokens"`
	SystemTokens  int                 `json:"system_tokens"` // estimated overhead
	Items         []ContextWindowItem `json:"items"`
}

type ContextWindowItem added in v0.9.1

type ContextWindowItem struct {
	Type    string `json:"type"` // "fact", "message", "system"
	ID      int64  `json:"id"`
	Preview string `json:"preview"`
	Chars   int    `json:"chars"`
	Tokens  int    `json:"tokens"` // chars / 4
}

type DateCount added in v0.9.1

type DateCount struct {
	Date  string `json:"date"`
	Count int    `json:"count"`
}

type DirStats added in v0.9.0

type DirStats struct {
	Count  int       `json:"count"`
	Size   int       `json:"size"`
	Oldest time.Time `json:"oldest"`
	Newest time.Time `json:"newest"`
}

type Fact

type Fact struct {
	ID        int64      `json:"id"`
	Content   string     `json:"content"`
	Tags      []string   `json:"tags,omitempty"`
	SourceDir string     `json:"source_dir"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	DeletedAt *time.Time `json:"deleted_at,omitempty"`
}

type FactDocument added in v0.5.0

type FactDocument struct {
	Content   string `json:"content"`
	SourceDir string `json:"source_dir"`
}

FactDocument represents a fact for Bleve indexing

type FactStats added in v0.9.0

type FactStats struct {
	TotalFacts   int                 `json:"total_facts"`
	TotalSize    int                 `json:"total_size"`
	DeletedFacts int                 `json:"deleted_facts"`
	DeletedSize  int                 `json:"deleted_size"`
	ByDirectory  map[string]DirStats `json:"by_directory"`
}

type Instance

type Instance struct {
	ID            string    `json:"id"`
	DirectoryID   string    `json:"directory_id"`
	Name          string    `json:"name,omitempty"`
	PID           int       `json:"pid"`
	Directory     string    `json:"directory"`
	TTY           string    `json:"tty,omitempty"`
	IsLeader      bool      `json:"is_leader"`
	IsIdle        bool      `json:"is_idle"`
	StartedAt     time.Time `json:"started_at"`
	LastHeartbeat time.Time `json:"last_heartbeat"`
}

type Message

type Message struct {
	ID           int64      `json:"id"`
	FromInstance string     `json:"from_instance"`
	ToInstance   string     `json:"to_instance"`
	Content      string     `json:"content"`
	CreatedAt    time.Time  `json:"created_at"`
	ReadAt       *time.Time `json:"read_at,omitempty"`
}

type PetState added in v0.12.0

type PetState struct {
	ID          string    `json:"id"` // directory-scoped (workDir)
	Name        string    `json:"name"`
	Species     string    `json:"species"`      // egg, baby, child, teen, adult, elder
	Hunger      int       `json:"hunger"`       // 0-100 (0=starving, 100=full)
	Happiness   int       `json:"happiness"`    // 0-100
	Energy      int       `json:"energy"`       // 0-100
	TotalTokens int64     `json:"total_tokens"` // lifetime tokens consumed
	IsAlive     bool      `json:"is_alive"`
	BornAt      time.Time `json:"born_at"`
	LastFedAt   time.Time `json:"last_fed_at"`
	LastPlayAt  time.Time `json:"last_play_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

type ReviewComment added in v0.13.0

type ReviewComment struct {
	ID                    string    `json:"id"`
	SessionID             string    `json:"session_id"`
	RevisionIDCreated     string    `json:"revision_id_created"`
	ParentID              string    `json:"parent_id,omitempty"`
	AnchorSectionID       string    `json:"anchor_section_id"`
	AnchorTextFingerprint string    `json:"anchor_text_fingerprint"`
	AnchorStartOffset     int       `json:"anchor_start_offset"`
	AnchorEndOffset       int       `json:"anchor_end_offset"`
	Status                string    `json:"status"`
	Author                string    `json:"author"` // "user" or "agent"
	Body                  string    `json:"body"`
	CreatedAt             time.Time `json:"created_at"`
}

ReviewComment is a comment or threaded reply anchored to a plan revision.

type ReviewEvent added in v0.13.0

type ReviewEvent struct {
	ID          int64     `json:"id"`
	SessionID   string    `json:"session_id"`
	Kind        string    `json:"kind"`
	PayloadJSON string    `json:"payload_json"`
	CreatedAt   time.Time `json:"created_at"`
}

ReviewEvent is an audit-log entry that also signals the agent.

type ReviewRevision added in v0.13.0

type ReviewRevision struct {
	ID             string          `json:"id"`
	SessionID      string          `json:"session_id"`
	RevisionNumber int             `json:"revision_number"`
	PlanMarkdown   string          `json:"plan_markdown"`
	Sections       []ReviewSection `json:"sections"`
	CreatedAt      time.Time       `json:"created_at"`
}

ReviewRevision is one version of a plan within a session.

type ReviewSection added in v0.13.0

type ReviewSection struct {
	ID          string `json:"id"`           // stable slug from heading text
	Title       string `json:"title"`        // heading text
	Level       int    `json:"level"`        // 1..6
	StartOffset int    `json:"start_offset"` // byte offset in plan_markdown where this section starts (heading line)
	EndOffset   int    `json:"end_offset"`   // byte offset where the next equal-or-higher heading starts (exclusive)
}

ReviewSection is the parsed structural anchor for a markdown heading.

type ReviewSession added in v0.13.0

type ReviewSession struct {
	ID                string     `json:"id"`
	Title             string     `json:"title"`
	Status            string     `json:"status"`
	WorkDir           string     `json:"work_dir"`
	DirectoryID       string     `json:"directory_id"`
	InstanceID        string     `json:"instance_id"`
	CurrentRevisionID string     `json:"current_revision_id"`
	CreatedAt         time.Time  `json:"created_at"`
	UpdatedAt         time.Time  `json:"updated_at"`
	ApprovedAt        *time.Time `json:"approved_at,omitempty"`
}

ReviewSession is one plan-review interaction between agent and user.

type SQLiteStore

type SQLiteStore struct {
	// contains filtered or unexported fields
}

func NewSQLiteStore

func NewSQLiteStore(dataDir string) (*SQLiteStore, error)

func (*SQLiteStore) ActivityBoost added in v0.12.1

func (s *SQLiteStore) ActivityBoost(workDir string, amount int) error

ActivityBoost gives a small happiness boost for coding activities (Edit, Write, Bash, etc.) without resetting LastPlayAt, so natural decay still applies.

func (*SQLiteStore) AddFact

func (s *SQLiteStore) AddFact(content string, tags []string, sourceDir string) (*Fact, error)

func (*SQLiteStore) AddReviewComment added in v0.13.0

func (s *SQLiteStore) AddReviewComment(c ReviewComment) error

func (*SQLiteStore) AddReviewEvent added in v0.13.0

func (s *SQLiteStore) AddReviewEvent(e ReviewEvent) (int64, error)

func (*SQLiteStore) AddReviewRevision added in v0.13.0

func (s *SQLiteStore) AddReviewRevision(r ReviewRevision) error

func (*SQLiteStore) BulkAddFacts added in v0.8.4

func (s *SQLiteStore) BulkAddFacts(facts []BulkFact, sourceDir string) ([]Fact, error)

func (*SQLiteStore) BulkSoftDeleteFacts added in v0.8.4

func (s *SQLiteStore) BulkSoftDeleteFacts(ids []int64) (int, error)

func (*SQLiteStore) CheckDirectoryHasActiveInstance added in v0.8.0

func (s *SQLiteStore) CheckDirectoryHasActiveInstance(directoryID string) (bool, error)

func (*SQLiteStore) CleanupIndex added in v0.6.0

func (s *SQLiteStore) CleanupIndex()

CleanupIndex removes this instance's Bleve index. Call on shutdown for CLI commands.

func (*SQLiteStore) CleanupStaleInstances

func (s *SQLiteStore) CleanupStaleInstances(maxAge time.Duration) error

func (*SQLiteStore) Close

func (s *SQLiteStore) Close() error

func (*SQLiteStore) CompressFacts added in v0.9.0

func (s *SQLiteStore) CompressFacts(deleteIDs []int64, newFacts []BulkFact, sourceDir string) (int, []Fact, error)

CompressFacts atomically deletes old facts and adds new consolidated ones in a single transaction

func (*SQLiteStore) CreatePet added in v0.12.0

func (s *SQLiteStore) CreatePet(workDir string, name string) (*PetState, error)

func (*SQLiteStore) CreateReviewSession added in v0.13.0

func (s *SQLiteStore) CreateReviewSession(sess ReviewSession) error

func (*SQLiteStore) DeleteFact

func (s *SQLiteStore) DeleteFact(id int64) error

func (*SQLiteStore) DeleteSetting added in v0.10.0

func (s *SQLiteStore) DeleteSetting(key string) error

func (*SQLiteStore) FeedPet added in v0.12.0

func (s *SQLiteStore) FeedPet(workDir string, tokens int64) (*PetState, error)

func (*SQLiteStore) GetAllFacts added in v0.8.4

func (s *SQLiteStore) GetAllFacts() ([]Fact, error)

func (*SQLiteStore) GetAllFactsByDir added in v0.8.4

func (s *SQLiteStore) GetAllFactsByDir(sourceDir string) ([]Fact, error)

func (*SQLiteStore) GetAllMessages added in v0.4.5

func (s *SQLiteStore) GetAllMessages(limit int) ([]Message, error)

func (*SQLiteStore) GetAnalytics added in v0.9.1

func (s *SQLiteStore) GetAnalytics(timeRange string) (*AnalyticsData, error)

GetAnalytics returns time-series analytics data for facts, messages, and sessions

func (*SQLiteStore) GetFactByID

func (s *SQLiteStore) GetFactByID(id int64) (*Fact, error)

func (*SQLiteStore) GetFactStats added in v0.9.0

func (s *SQLiteStore) GetFactStats() (*FactStats, error)

GetFactStats returns statistics about all stored facts

func (*SQLiteStore) GetFacts

func (s *SQLiteStore) GetFacts(query string, tags []string, sourceDir string, limit int) ([]Fact, error)

func (*SQLiteStore) GetIdleInstancesWithUnreadMessages added in v0.4.5

func (s *SQLiteStore) GetIdleInstancesWithUnreadMessages() ([]Instance, error)

GetIdleInstancesWithUnreadMessages returns instances that are marked idle and have unread messages

func (*SQLiteStore) GetInstance

func (s *SQLiteStore) GetInstance(id string) (*Instance, error)

func (*SQLiteStore) GetInstances

func (s *SQLiteStore) GetInstances() ([]Instance, error)

func (*SQLiteStore) GetInstancesByDirectory added in v0.8.0

func (s *SQLiteStore) GetInstancesByDirectory(directoryID string) ([]Instance, error)

func (*SQLiteStore) GetLeader added in v0.4.5

func (s *SQLiteStore) GetLeader() (*Instance, error)

GetLeader returns the current leader instance, if any

func (*SQLiteStore) GetMessages

func (s *SQLiteStore) GetMessages(toInstance string, unreadOnly bool) ([]Message, error)

func (*SQLiteStore) GetPet added in v0.12.0

func (s *SQLiteStore) GetPet(workDir string) (*PetState, error)

func (*SQLiteStore) GetReviewComment added in v0.13.0

func (s *SQLiteStore) GetReviewComment(id string) (*ReviewComment, error)

func (*SQLiteStore) GetReviewRevision added in v0.13.0

func (s *SQLiteStore) GetReviewRevision(id string) (*ReviewRevision, error)

func (*SQLiteStore) GetReviewSession added in v0.13.0

func (s *SQLiteStore) GetReviewSession(id string) (*ReviewSession, error)

func (*SQLiteStore) GetSetting added in v0.10.0

func (s *SQLiteStore) GetSetting(key string) (string, error)

func (*SQLiteStore) Heartbeat

func (s *SQLiteStore) Heartbeat(id string) error

func (*SQLiteStore) InitIndex added in v0.6.0

func (s *SQLiteStore) InitIndex(instanceID string) error

InitIndex initializes a per-instance Bleve index for full-text search. Each instance gets its own index to avoid file locking issues between processes. Call this for long-running processes (MCP server, UI) that benefit from full-text search. Short-lived CLI commands can skip this and use SQLite-only search.

func (*SQLiteStore) ListReviewComments added in v0.13.0

func (s *SQLiteStore) ListReviewComments(sessionID string) ([]ReviewComment, error)

func (*SQLiteStore) ListReviewEvents added in v0.13.0

func (s *SQLiteStore) ListReviewEvents(sessionID string, afterID int64, limit int) ([]ReviewEvent, error)

func (*SQLiteStore) ListReviewRevisions added in v0.13.0

func (s *SQLiteStore) ListReviewRevisions(sessionID string) ([]ReviewRevision, error)

func (*SQLiteStore) ListReviewSessionsByInstance added in v0.13.0

func (s *SQLiteStore) ListReviewSessionsByInstance(instanceID string, statuses []string) ([]ReviewSession, error)

func (*SQLiteStore) ListReviewSessionsByStatus added in v0.13.0

func (s *SQLiteStore) ListReviewSessionsByStatus(statuses []string, limit int) ([]ReviewSession, error)

func (*SQLiteStore) MarkMessageRead

func (s *SQLiteStore) MarkMessageRead(id int64) error

func (*SQLiteStore) PlayWithPet added in v0.12.0

func (s *SQLiteStore) PlayWithPet(workDir string) (*PetState, error)

func (*SQLiteStore) PurgeDeletedFacts added in v0.9.0

func (s *SQLiteStore) PurgeDeletedFacts() (int, error)

PurgeDeletedFacts permanently removes all soft-deleted facts from the database

func (*SQLiteStore) RegisterInstance

func (s *SQLiteStore) RegisterInstance(id, directoryID, name, directory, tty string, pid int) error

func (*SQLiteStore) ReleaseLeadership added in v0.4.5

func (s *SQLiteStore) ReleaseLeadership(id string) error

ReleaseLeadership releases leadership for this instance

func (*SQLiteStore) RenameInstance added in v0.15.0

func (s *SQLiteStore) RenameInstance(oldID, newID, newName string) error

RenameInstance changes a running instance's name in place. Because the name is encoded into the instance ID ("directoryID:name"), this rewrites the primary key and migrates every row that references the old ID (messages in both directions and review sessions) atomically. It returns an error if the source instance no longer exists or if the target name is already taken by a different instance in the same directory.

func (*SQLiteStore) RenamePet added in v0.12.0

func (s *SQLiteStore) RenamePet(workDir string, name string) (*PetState, error)

func (*SQLiteStore) RevivePet added in v0.12.0

func (s *SQLiteStore) RevivePet(workDir string) (*PetState, error)

func (*SQLiteStore) SendMessage

func (s *SQLiteStore) SendMessage(from, to, content string) (*Message, error)

func (*SQLiteStore) SetIdle added in v0.4.5

func (s *SQLiteStore) SetIdle(id string, idle bool) error

SetIdle sets the idle status of an instance

func (*SQLiteStore) SetSetting added in v0.10.0

func (s *SQLiteStore) SetSetting(key, value string) error

func (*SQLiteStore) SoftDeleteFact added in v0.4.3

func (s *SQLiteStore) SoftDeleteFact(id int64) error

func (*SQLiteStore) TryBecomeLeader added in v0.4.5

func (s *SQLiteStore) TryBecomeLeader(id string) (bool, error)

TryBecomeLeader attempts to become leader if there is no current leader Returns true if this instance became leader

func (*SQLiteStore) UnregisterInstance

func (s *SQLiteStore) UnregisterInstance(id string) error

func (*SQLiteStore) UpdateFact added in v0.9.0

func (s *SQLiteStore) UpdateFact(id int64, content string, tags []string) (*Fact, error)

UpdateFact updates the content and/or tags of an existing fact

func (*SQLiteStore) UpdateReviewCommentAnchor added in v0.13.0

func (s *SQLiteStore) UpdateReviewCommentAnchor(id, sectionID, fingerprint string, startOffset, endOffset int, status string) error

func (*SQLiteStore) UpdateReviewCurrentRevision added in v0.13.0

func (s *SQLiteStore) UpdateReviewCurrentRevision(id, revisionID string) error

func (*SQLiteStore) UpdateReviewSessionStatus added in v0.13.0

func (s *SQLiteStore) UpdateReviewSessionStatus(id, status string) error

type Store

type Store interface {
	// Facts
	AddFact(content string, tags []string, sourceDir string) (*Fact, error)
	BulkAddFacts(facts []BulkFact, sourceDir string) ([]Fact, error)
	GetFacts(query string, tags []string, sourceDir string, limit int) ([]Fact, error)
	GetFactByID(id int64) (*Fact, error)
	GetAllFactsByDir(sourceDir string) ([]Fact, error)
	GetAllFacts() ([]Fact, error)
	DeleteFact(id int64) error
	SoftDeleteFact(id int64) error
	BulkSoftDeleteFacts(ids []int64) (int, error)
	UpdateFact(id int64, content string, tags []string) (*Fact, error)
	CompressFacts(deleteIDs []int64, newFacts []BulkFact, sourceDir string) (int, []Fact, error)
	PurgeDeletedFacts() (int, error)
	GetFactStats() (*FactStats, error)

	// Instances
	RegisterInstance(id, directoryID, name, directory, tty string, pid int) error
	Heartbeat(id string) error
	UnregisterInstance(id string) error
	RenameInstance(oldID, newID, newName string) error
	GetInstances() ([]Instance, error)
	GetInstance(id string) (*Instance, error)
	GetInstancesByDirectory(directoryID string) ([]Instance, error)
	CheckDirectoryHasActiveInstance(directoryID string) (bool, error)
	CleanupStaleInstances(maxAge time.Duration) error

	// Leader election
	TryBecomeLeader(id string) (bool, error)
	ReleaseLeadership(id string) error
	GetLeader() (*Instance, error)

	// Idle tracking
	SetIdle(id string, idle bool) error
	GetIdleInstancesWithUnreadMessages() ([]Instance, error)

	// Messages
	SendMessage(from, to, content string) (*Message, error)
	GetMessages(toInstance string, unreadOnly bool) ([]Message, error)
	GetAllMessages(limit int) ([]Message, error)
	MarkMessageRead(id int64) error

	// Analytics
	GetAnalytics(timeRange string) (*AnalyticsData, error)

	// Settings (key-value config)
	GetSetting(key string) (string, error)
	SetSetting(key, value string) error
	DeleteSetting(key string) error

	// Pet (Tamagotchi)
	GetPet(workDir string) (*PetState, error)
	CreatePet(workDir string, name string) (*PetState, error)
	FeedPet(workDir string, tokens int64) (*PetState, error)
	PlayWithPet(workDir string) (*PetState, error)
	ActivityBoost(workDir string, amount int) error
	RenamePet(workDir string, name string) (*PetState, error)
	RevivePet(workDir string) (*PetState, error)

	// Plan review
	CreateReviewSession(s ReviewSession) error
	GetReviewSession(id string) (*ReviewSession, error)
	UpdateReviewSessionStatus(id, status string) error
	UpdateReviewCurrentRevision(id, revisionID string) error
	ListReviewSessionsByStatus(statuses []string, limit int) ([]ReviewSession, error)
	ListReviewSessionsByInstance(instanceID string, statuses []string) ([]ReviewSession, error)

	AddReviewRevision(r ReviewRevision) error
	GetReviewRevision(id string) (*ReviewRevision, error)
	ListReviewRevisions(sessionID string) ([]ReviewRevision, error)

	AddReviewComment(c ReviewComment) error
	UpdateReviewCommentAnchor(id, sectionID, fingerprint string, startOffset, endOffset int, status string) error
	ListReviewComments(sessionID string) ([]ReviewComment, error)
	GetReviewComment(id string) (*ReviewComment, error)

	AddReviewEvent(e ReviewEvent) (int64, error)
	ListReviewEvents(sessionID string, afterID int64, limit int) ([]ReviewEvent, error)

	// Lifecycle
	Close() error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL