store

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package store handles all SQLite persistence for spec. No other package opens the database or writes raw SQL.

Index

Constants

View Source
const (
	SurfaceCLI = "cli"
	SurfaceTUI = "tui"
	SurfaceMCP = "mcp"
)

Sync audit surfaces — which client triggered a sync action.

View Source
const (
	OutcomeOK       = "ok"
	OutcomeQueued   = "queued"
	OutcomeConflict = "conflict"
	OutcomeError    = "error"
)

Sync audit outcomes.

View Source
const (
	QueueStatusQueued          = "queued"           // awaiting flush
	QueueStatusNeedsResolution = "needs-resolution" // same-section conflict; needs a human
)

Queued-push states.

Variables

This section is empty.

Functions

func DefaultDBPath

func DefaultDBPath() string

DefaultDBPath returns the default database path.

Types

type ActivityEntry

type ActivityEntry struct {
	ID        int64
	SpecID    string
	EventType string
	Summary   string
	Metadata  string
	UserName  string
	CreatedAt time.Time
}

ActivityEntry represents a single event in the activity log.

type CacheEntry

type CacheEntry struct {
	Value     string
	Fresh     bool
	FetchedAt time.Time
}

CacheEntry holds a cached value along with its metadata.

type DB

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

DB wraps a SQLite database connection.

func Open

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

Open opens or creates the SQLite database at the given path.

func OpenMemory

func OpenMemory() (*DB, error)

OpenMemory opens an in-memory SQLite database for testing.

func (*DB) ActivityCountByType

func (db *DB) ActivityCountByType(since time.Time) (map[string]int, error)

ActivityCountByType returns event counts grouped by event_type since the given time.

func (*DB) ActivityForSpec

func (db *DB) ActivityForSpec(specID string, limit int) ([]ActivityEntry, error)

ActivityForSpec returns activity entries for a specific spec.

func (*DB) ActivityForType

func (db *DB) ActivityForType(eventType string, since time.Time) ([]ActivityEntry, error)

ActivityForType returns all entries of a specific event type since the given time.

func (*DB) ActivityLog

func (db *DB) ActivityLog(specID, eventType, summary, metadata, userName string) error

ActivityLog appends an event to the activity log.

func (*DB) ActivityPrune

func (db *DB) ActivityPrune(olderThan time.Duration) (int64, error)

ActivityPrune removes activity older than the given duration.

func (*DB) ActivitySince

func (db *DB) ActivitySince(since time.Time) ([]ActivityEntry, error)

ActivitySince returns activity entries since the given time.

func (*DB) CacheClear

func (db *DB) CacheClear() error

CacheClear removes all cache entries.

func (*DB) CacheDelete

func (db *DB) CacheDelete(key string) error

CacheDelete removes a cache entry.

func (*DB) CacheGet

func (db *DB) CacheGet(key string) (value string, fresh bool, err error)

CacheGet retrieves a cached value by key. Returns the value and whether the cache entry is still fresh (within TTL). Returns "", false if not found.

func (*DB) CacheGetEntry

func (db *DB) CacheGetEntry(key string) (CacheEntry, error)

CacheGetEntry retrieves a cache entry with full metadata including fetch time.

func (*DB) CacheSet

func (db *DB) CacheSet(key, value string, ttlSeconds int) error

CacheSet stores a value in the cache with the given TTL in seconds.

func (*DB) Close

func (db *DB) Close() error

Close closes the database connection.

func (*DB) Conn

func (db *DB) Conn() *sql.DB

Conn returns the underlying sql.DB for direct queries.

func (*DB) EmbeddingDeleteSpec

func (db *DB) EmbeddingDeleteSpec(specID string) error

EmbeddingDeleteSpec removes all embeddings for a spec.

func (*DB) EmbeddingSearch

func (db *DB) EmbeddingSearch(queryVector []float32, limit int) ([]EmbeddingEntry, error)

EmbeddingSearch finds the most similar embeddings to the query vector. Uses brute-force cosine similarity (sufficient for hundreds of specs).

func (*DB) EmbeddingUpsert

func (db *DB) EmbeddingUpsert(specID, section, content string, vector []float32, model string) error

EmbeddingUpsert inserts or updates an embedding for a spec section.

func (*DB) FocusedSpecClear

func (db *DB) FocusedSpecClear() error

FocusedSpecClear clears the globally focused spec ID.

func (*DB) FocusedSpecGet

func (db *DB) FocusedSpecGet() (string, error)

FocusedSpecGet returns the globally focused spec ID, if one is set.

func (*DB) FocusedSpecSet

func (db *DB) FocusedSpecSet(specID string) error

FocusedSpecSet stores the globally focused spec ID.

func (*DB) LastFetchGet added in v0.12.0

func (db *DB) LastFetchGet(repoKey string) (time.Time, error)

LastFetchGet returns the timestamp of the last successful fetch for a specs repo (keyed by "owner/repo"), or the zero time if none is recorded.

func (*DB) LastFetchSet added in v0.12.0

func (db *DB) LastFetchSet(repoKey string, at time.Time) error

LastFetchSet records the timestamp of a successful fetch for a specs repo.

func (*DB) QueuePushCount added in v0.12.0

func (db *DB) QueuePushCount(repoKey string) (int, error)

QueuePushCount returns the number of queued (flushable) entries for a repo.

func (*DB) QueuePushEnqueue added in v0.12.0

func (db *DB) QueuePushEnqueue(q QueuedPush) (int64, error)

QueuePushEnqueue records a queued (offline / contention-exhausted) push.

func (*DB) QueuePushMark added in v0.12.0

func (db *DB) QueuePushMark(id int64, status, detail string) error

QueuePushMark updates a queued entry's status (e.g. needs-resolution).

func (*DB) QueuePushPending added in v0.12.0

func (db *DB) QueuePushPending(repoKey string) ([]QueuedPush, error)

QueuePushPending returns queued entries for a repo that should be flushed, oldest first. Entries marked needs-resolution are excluded — they require a human and must not be retried automatically.

func (*DB) QueuePushResolve added in v0.12.0

func (db *DB) QueuePushResolve(id int64) error

QueuePushResolve removes a queued entry once it has been flushed.

func (*DB) SessionDelete

func (db *DB) SessionDelete(specID string) error

SessionDelete removes a session.

func (*DB) SessionGet

func (db *DB) SessionGet(specID string) (string, error)

SessionGet retrieves the session state JSON for a spec.

func (*DB) SessionList

func (db *DB) SessionList() ([]string, error)

SessionList returns all active sessions.

func (*DB) SessionMostRecent

func (db *DB) SessionMostRecent() (string, error)

SessionMostRecent returns the spec ID of the most recently updated session.

func (*DB) SessionSet

func (db *DB) SessionSet(specID, state string) error

SessionSet stores session state for a spec.

func (*DB) SyncAuditLog added in v0.12.0

func (db *DB) SyncAuditLog(entry SyncAuditEntry) error

SyncAuditLog appends one sync audit entry and prunes the table to maxAuditRows.

func (*DB) SyncAuditRecent added in v0.12.0

func (db *DB) SyncAuditRecent(limit int) ([]SyncAuditEntry, error)

SyncAuditRecent returns the most recent sync audit entries, newest first.

func (*DB) SyncStateForSpec

func (db *DB) SyncStateForSpec(specID string) (map[string]map[string]SyncStateEntry, error)

SyncStateForSpec returns all sync state entries for a spec keyed by section and direction.

func (*DB) SyncStateGet

func (db *DB) SyncStateGet(specID, section, direction string) (*SyncStateEntry, error)

SyncStateGet returns the last synced hash for a spec section and direction.

func (*DB) SyncStateSet

func (db *DB) SyncStateSet(specID, section, direction, hash string) error

SyncStateSet upserts the last synced hash for a spec section and direction.

type EmbeddingEntry

type EmbeddingEntry struct {
	ID        int64
	SpecID    string
	Section   string
	Content   string
	Vector    []float32
	Model     string
	UpdatedAt time.Time
}

EmbeddingEntry represents a stored embedding.

type QueuedPush added in v0.12.0

type QueuedPush struct {
	ID        int64
	RepoKey   string // owner/repo — scopes the queue to a clone
	Branch    string
	CommitSHA string // local commit to flush
	Surface   string
	Trigger   string
	SpecID    string
	Status    string // queued | needs-resolution
	Detail    string
	CreatedAt time.Time
	UpdatedAt time.Time
}

QueuedPush records a committed-but-unpushed operation that must be flushed to the remote on a later online operation. Each entry is reconciled independently so one conflict never strands the rest (SPEC-013 §7.1).

type SyncAuditEntry added in v0.12.0

type SyncAuditEntry struct {
	ID        int64
	Op        string // fetch | commit | push | recover | queue-flush
	Actor     string // git user.name
	Surface   string // cli | tui | mcp
	Trigger   string // command/action name
	SpecID    string // optional
	Outcome   string // ok | queued | conflict | error
	Detail    string // free-form context
	CreatedAt time.Time
}

SyncAuditEntry is one recorded sync operation (fetch / commit / push / deferral / auto-recovery) with actor, surface, trigger, and outcome.

type SyncStateEntry

type SyncStateEntry struct {
	SpecID    string
	Section   string
	Direction string
	Hash      string
	SyncedAt  time.Time
}

SyncStateEntry records the last hash synced for one spec section and direction.

Jump to

Keyboard shortcuts

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