store

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package store manages the brain's own SQLite database. It stores semantic summaries, cached violation explanations, SDLC state, decision history, and learned co-occurrence patterns. This is separate from Synapses' SQLite database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ADR

type ADR struct {
	ID           string   `json:"id"`
	Title        string   `json:"title"`
	Status       string   `json:"status"` // proposed | accepted | deprecated | superseded
	ContextText  string   `json:"context,omitempty"`
	Decision     string   `json:"decision"`
	Consequences string   `json:"consequences,omitempty"`
	LinkedFiles  []string `json:"linked_files,omitempty"` // file path glob patterns
	CreatedAt    string   `json:"created_at"`
	UpdatedAt    string   `json:"updated_at"`
}

ADR represents an Architectural Decision Record stored in brain.sqlite.

type ContextPattern

type ContextPattern struct {
	Trigger    string
	CoChange   string
	Reason     string
	Confidence float64
	CoCount    int
}

ContextPattern is a learned co-occurrence rule.

type DecisionLogEntry

type DecisionLogEntry struct {
	ID              string
	AgentID         string
	Phase           string
	EntityName      string
	Action          string
	RelatedEntities []string
	Outcome         string
	Notes           string
	CreatedAt       string
}

DecisionLogEntry is a row from decision_log.

type InsightCacheEntry

type InsightCacheEntry struct {
	Insight  string
	Concerns []string
}

InsightCacheEntry is a stored LLM-generated insight for a (node_id, phase) pair.

type SDLCConfigRow

type SDLCConfigRow struct {
	Phase       string
	QualityMode string
	UpdatedAt   string
	UpdatedBy   string
}

SDLCConfigRow is the stored project SDLC state.

type Store

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

Store is the brain's persistent SQLite store.

func Open

func Open(path string) (*Store, error)

Open opens (or creates) the brain SQLite database at the given path. Parent directories are created if they do not exist. Old data is pruned at startup (decision_log >30d, stale patterns >14d).

func (*Store) AllADRs

func (s *Store) AllADRs() ([]ADR, error)

AllADRs returns all ADRs ordered by updated_at descending.

func (*Store) AllPatterns

func (s *Store) AllPatterns() ([]ContextPattern, error)

AllPatterns returns all patterns ordered by confidence for CLI display.

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying database.

func (*Store) GetADR

func (s *Store) GetADR(id string) (ADR, error)

GetADR returns the ADR with the given ID, or an error if not found.

func (*Store) GetADRsForFile

func (s *Store) GetADRsForFile(filePath string, limit int) ([]ADR, error)

GetADRsForFile returns accepted ADRs whose linked_files patterns match the given file path. At most `limit` ADRs are returned; pass 0 for no limit.

func (*Store) GetDecisionLog

func (s *Store) GetDecisionLog(entityName string, limit int) ([]DecisionLogEntry, error)

GetDecisionLog returns up to limit decision log entries, optionally filtered by entityName (empty string = all), ordered by created_at DESC.

func (*Store) GetInsightCache

func (s *Store) GetInsightCache(nodeID, phase string) (entry InsightCacheEntry, found bool)

GetInsightCache returns the cached insight for a (nodeID, phase) pair. Returns ("", nil, false) if not cached or if the entry was pruned (>6h old).

func (*Store) GetPatternsForTriggers

func (s *Store) GetPatternsForTriggers(triggers []string, limit int) []ContextPattern

GetPatternsForTriggers returns the top patterns for any of the given trigger names. Results are ordered by confidence descending, capped at limit.

func (*Store) GetSDLCConfig

func (s *Store) GetSDLCConfig() SDLCConfigRow

GetSDLCConfig returns the current project SDLC config. Returns defaults if no config row exists.

func (*Store) GetSummaries

func (s *Store) GetSummaries(projectID string, nodeIDs []string) map[string]string

GetSummaries returns summaries for all given node IDs keyed by node ID. Missing nodes are omitted from the result map.

func (*Store) GetSummariesByName

func (s *Store) GetSummariesByName(names []string) map[string]string

GetSummariesByName returns summaries keyed by node_name for the given names. This is used by the contextbuilder to look up dep summaries by entity name.

func (*Store) GetSummary

func (s *Store) GetSummary(projectID, nodeID string) string

GetSummary returns the stored summary for a node, or "" if not found. Falls back to the empty-projectID (legacy) row if no project-scoped row exists.

func (*Store) GetViolationExplanation

func (s *Store) GetViolationExplanation(ruleID, sourceFile string) (explanation, fix string, found bool)

GetViolationExplanation returns the cached explanation for a rule+file pair. Returns ("", "", false) if not cached.

func (*Store) LogDecision

func (s *Store) LogDecision(agentID, phase, entityName, action string, relatedEntities []string, outcome, notes string) error

LogDecision inserts a new decision log entry.

func (*Store) Reset

func (s *Store) Reset() error

Reset deletes all brain data.

func (*Store) UpsertADR

func (s *Store) UpsertADR(adr ADR) error

UpsertADR creates or updates an ADR. ID must be non-empty.

func (*Store) UpsertInsightCache

func (s *Store) UpsertInsightCache(nodeID, phase, insight string, concerns []string) error

UpsertInsightCache stores a (nodeID, phase) → insight mapping. Existing entries are replaced (insight content may have improved).

func (*Store) UpsertPattern

func (s *Store) UpsertPattern(trigger, coChange, reason string) error

UpsertPattern adds or increments a co-occurrence pattern. coCount and totalCount are incremented; confidence is recomputed.

func (*Store) UpsertSDLCConfig

func (s *Store) UpsertSDLCConfig(phase, qualityMode, updatedBy string) error

UpsertSDLCConfig saves the SDLC config row.

func (*Store) UpsertSummary

func (s *Store) UpsertSummary(projectID, nodeID, nodeName, summary string, tags []string) error

UpsertSummary stores or updates the semantic summary and tags for a node. If the node already exists (re-ingest), the insight cache is invalidated for all phases — the old insight may no longer match the updated code. projectID scopes the summary; use "" for legacy/unscoped entries.

func (*Store) UpsertViolationExplanation

func (s *Store) UpsertViolationExplanation(ruleID, sourceFile, explanation, fix string) error

UpsertViolationExplanation caches a plain-English explanation for a rule+file pair.

Jump to

Keyboard shortcuts

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