Documentation
¶
Index ¶
- Variables
- func BuildAfterToolCallback(w *Worker, sessionID, project string, excludedTools map[string]bool) ...
- func BuildMemoryCallback(w *Worker, sessionID, project string) func(toolName string, toolInput, toolOutput map[string]any)
- func HasFTS5(db *sql.DB) bool
- func OpenDB(dbPath string) (*sql.DB, error)
- func StripPrivate(s string) string
- func StripPrivateFromMap(m map[string]any) map[string]any
- type AfterStoreHook
- type Compressor
- type ContextGenerator
- type Observation
- type ObservationType
- type RawObservation
- type SQLiteStore
- func (s *SQLiteStore) Close() error
- func (s *SQLiteStore) CompleteSession(ctx context.Context, sessionID string) error
- func (s *SQLiteStore) CreateSession(ctx context.Context, sess *Session) error
- func (s *SQLiteStore) GetObservations(ctx context.Context, ids []int64) ([]*Observation, error)
- func (s *SQLiteStore) InsertObservation(ctx context.Context, obs *Observation) error
- func (s *SQLiteStore) RecentObservations(ctx context.Context, project string, limit int) ([]*Observation, error)
- func (s *SQLiteStore) RecentSummaries(ctx context.Context, project string, limit int) ([]*SessionSummary, error)
- func (s *SQLiteStore) Search(ctx context.Context, q SearchQuery) (*SearchResult, error)
- func (s *SQLiteStore) SearchSummaries(ctx context.Context, query string, project string) ([]*SessionSummary, error)
- func (s *SQLiteStore) Timeline(ctx context.Context, anchorID int64, before, after int) ([]*Observation, error)
- func (s *SQLiteStore) UpsertSummary(ctx context.Context, sum *SessionSummary) error
- type SearchQuery
- type SearchResult
- type SearchResultRow
- type Session
- type SessionSummary
- type Store
- type SubagentCompressor
- type Worker
Constants ¶
This section is empty.
Variables ¶
var ValidObservationTypes = map[ObservationType]bool{ TypeDecision: true, TypeBugfix: true, TypeFeature: true, TypeRefactor: true, TypeDiscovery: true, TypeChange: true, }
ValidObservationTypes is the set of allowed observation types.
Functions ¶
func BuildAfterToolCallback ¶
func BuildAfterToolCallback(w *Worker, sessionID, project string, excludedTools map[string]bool) func(ctx toolpkg.Context, t toolpkg.Tool, args, result map[string]any, toolErr error) (map[string]any, error)
BuildAfterToolCallback creates an ADK AfterToolCallback that enqueues observations. It wraps the worker's Enqueue in the ADK callback signature for direct use with agent callbacks.
func BuildMemoryCallback ¶
func BuildMemoryCallback(w *Worker, sessionID, project string) func(toolName string, toolInput, toolOutput map[string]any)
BuildMemoryCallback creates an ADK AfterToolCallback that enqueues observations to the worker.
func OpenDB ¶
OpenDB opens (or creates) a SQLite database at the given path with WAL mode and runs pending migrations. Pass ":memory:" for in-memory databases.
func StripPrivate ¶
StripPrivate replaces all <private>...</private> tags with [PRIVATE].
Types ¶
type AfterStoreHook ¶ added in v0.0.15
type AfterStoreHook func(ctx context.Context, obs *Observation)
AfterStoreHook is called after an observation is successfully stored. Implementations must not block the pipeline — errors should be logged, not returned.
type Compressor ¶
type Compressor interface {
CompressObservation(ctx context.Context, raw RawObservation) (*Observation, error)
}
Compressor transforms raw tool observations into structured observations.
type ContextGenerator ¶
type ContextGenerator struct {
// contains filtered or unexported fields
}
ContextGenerator builds markdown context from recent observations for system instruction injection.
func NewContextGenerator ¶
func NewContextGenerator(store Store, tokenBudget int) *ContextGenerator
NewContextGenerator creates a ContextGenerator with the given store and token budget.
type Observation ¶
type Observation struct {
ID int64
SessionID string
Project string
Title string
Type ObservationType
Text string
SourceFiles []string // stored as JSON array
ToolName string
PromptNumber int
DiscoveryTokens int
CreatedAt time.Time
}
Observation is a compressed, structured record of a tool usage event.
type ObservationType ¶
type ObservationType string
ObservationType classifies what an observation represents.
const ( TypeDecision ObservationType = "decision" TypeBugfix ObservationType = "bugfix" TypeFeature ObservationType = "feature" TypeRefactor ObservationType = "refactor" TypeDiscovery ObservationType = "discovery" TypeChange ObservationType = "change" )
type RawObservation ¶
type RawObservation struct {
SessionID string
Project string
ToolName string
ToolInput map[string]any
ToolOutput map[string]any
Timestamp time.Time
}
RawObservation is the uncompressed tool event captured by AfterToolCallback.
type SQLiteStore ¶
type SQLiteStore struct {
// contains filtered or unexported fields
}
SQLiteStore implements Store using a SQLite database.
func NewSQLiteStore ¶
func NewSQLiteStore(db *sql.DB) *SQLiteStore
NewSQLiteStore creates a new SQLiteStore wrapping the given database.
func (*SQLiteStore) Close ¶
func (s *SQLiteStore) Close() error
Close closes the underlying database connection.
func (*SQLiteStore) CompleteSession ¶
func (s *SQLiteStore) CompleteSession(ctx context.Context, sessionID string) error
CompleteSession marks a session as completed with a timestamp.
func (*SQLiteStore) CreateSession ¶
func (s *SQLiteStore) CreateSession(ctx context.Context, sess *Session) error
CreateSession inserts a new session record.
func (*SQLiteStore) GetObservations ¶
func (s *SQLiteStore) GetObservations(ctx context.Context, ids []int64) ([]*Observation, error)
GetObservations fetches observations by IDs. Missing IDs are silently skipped.
func (*SQLiteStore) InsertObservation ¶
func (s *SQLiteStore) InsertObservation(ctx context.Context, obs *Observation) error
InsertObservation inserts a new observation, marshaling SourceFiles as JSON.
func (*SQLiteStore) RecentObservations ¶
func (s *SQLiteStore) RecentObservations(ctx context.Context, project string, limit int) ([]*Observation, error)
RecentObservations returns the most recent observations for a project.
func (*SQLiteStore) RecentSummaries ¶
func (s *SQLiteStore) RecentSummaries(ctx context.Context, project string, limit int) ([]*SessionSummary, error)
RecentSummaries returns the most recent session summaries for a project.
func (*SQLiteStore) Search ¶
func (s *SQLiteStore) Search(ctx context.Context, q SearchQuery) (*SearchResult, error)
Search performs FTS5 full-text search over observations, returning compact result rows. Falls back to LIKE matching if FTS5 is unavailable.
func (*SQLiteStore) SearchSummaries ¶
func (s *SQLiteStore) SearchSummaries(ctx context.Context, query string, project string) ([]*SessionSummary, error)
SearchSummaries performs FTS5 search over session summaries. Falls back to LIKE if FTS5 is unavailable.
func (*SQLiteStore) Timeline ¶
func (s *SQLiteStore) Timeline(ctx context.Context, anchorID int64, before, after int) ([]*Observation, error)
Timeline returns observations around an anchor observation, from the same project. It fetches `before` observations created before the anchor and `after` observations after it.
func (*SQLiteStore) UpsertSummary ¶
func (s *SQLiteStore) UpsertSummary(ctx context.Context, sum *SessionSummary) error
UpsertSummary inserts or replaces a session summary.
type SearchQuery ¶
type SearchQuery struct {
Query string
Project string
Type ObservationType
Limit int
Offset int
}
SearchQuery describes a full-text search request.
type SearchResult ¶
type SearchResult struct {
Rows []SearchResultRow `json:"results"`
Total int `json:"total"`
}
SearchResult contains paginated search results.
type SearchResultRow ¶
type SearchResultRow struct {
ID int64 `json:"id"`
Title string `json:"title"`
Type ObservationType `json:"type"`
CreatedAt time.Time `json:"created_at"`
ReadCost int `json:"read"`
WorkCost int `json:"work"`
}
SearchResultRow is a compact representation of one search match.
type Session ¶
type Session struct {
ID int64
SessionID string
Project string
UserPrompt string
StartedAt time.Time
CompletedAt *time.Time
Status string // "active", "completed", "failed"
}
Session represents a single agent interaction session.
type SessionSummary ¶
type SessionSummary struct {
ID int64
SessionID string
Project string
Request string
Investigated string
Learned string
Completed string
NextSteps string
DiscoveryTokens int
CreatedAt time.Time
}
SessionSummary is a structured summary generated at session end.
type Store ¶
type Store interface {
CreateSession(ctx context.Context, s *Session) error
CompleteSession(ctx context.Context, sessionID string) error
InsertObservation(ctx context.Context, obs *Observation) error
GetObservations(ctx context.Context, ids []int64) ([]*Observation, error)
RecentObservations(ctx context.Context, project string, limit int) ([]*Observation, error)
UpsertSummary(ctx context.Context, sum *SessionSummary) error
RecentSummaries(ctx context.Context, project string, limit int) ([]*SessionSummary, error)
Search(ctx context.Context, q SearchQuery) (*SearchResult, error)
Timeline(ctx context.Context, anchorID int64, before, after int) ([]*Observation, error)
Close() error
}
Store defines the interface for memory persistence operations.
type SubagentCompressor ¶
type SubagentCompressor struct {
// contains filtered or unexported fields
}
SubagentCompressor uses a bundled subagent to compress raw observations.
func NewSubagentCompressor ¶
func NewSubagentCompressor(orch *subagent.Orchestrator) *SubagentCompressor
NewSubagentCompressor creates a compressor that uses the memory-compressor subagent.
func (*SubagentCompressor) CompressObservation ¶
func (c *SubagentCompressor) CompressObservation(ctx context.Context, raw RawObservation) (*Observation, error)
CompressObservation sends raw observation data to the memory-compressor subagent and parses the structured response.
func (*SubagentCompressor) SummarizeSession ¶
func (c *SubagentCompressor) SummarizeSession(ctx context.Context, sessionID, project string, observations []*Observation) (*SessionSummary, error)
SummarizeSession creates a session summary from a list of observations.
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker is a background goroutine that drains raw observations, applies privacy filtering, compresses them, and stores the results.
func NewWorker ¶
func NewWorker(store Store, compressor Compressor, bufSize int) *Worker
NewWorker creates a Worker with the given buffer size for the observation channel.
func (*Worker) Enqueue ¶
func (w *Worker) Enqueue(obs RawObservation)
Enqueue sends a raw observation to the worker. Non-blocking: drops and logs if full.
func (*Worker) OnAfterStore ¶ added in v0.0.15
func (w *Worker) OnAfterStore(hook AfterStoreHook)
OnAfterStore registers a hook that runs after each observation is stored. Must be called before Start.