store

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangeLog

type ChangeLog struct {
	ID         string    `json:"id"`
	AgentID    string    `json:"agent_id"`
	CreatedAt  time.Time `json:"created_at"`
	EntityKind string    `json:"entity_kind"` // interest_point | wiki_page
	EntityID   string    `json:"entity_id"`
	Title      string    `json:"title"`
	Action     string    `json:"action"` // create | update | merge | archive | supersede | edge_change
	Edges      []LogEdge `json:"edges,omitempty"`
}

ChangeLog records one structural change: entity title, action, and the structural edges touched. No LLM-generated reason is stored.

type Claim

type Claim struct {
	ID         string     `json:"id"`
	AgentID    string     `json:"agent_id"`
	PageID     string     `json:"page_id"`
	Text       string     `json:"text"`
	Status     string     `json:"status"` // supported | contested | stale
	Confidence float64    `json:"confidence"`
	Evidence   []Evidence `json:"evidence"`
	Freshness  Freshness  `json:"freshness"`
}

Claim is a structured belief with evidence (core of the correction layer).

type Contradiction

type Contradiction struct {
	ID          string    `json:"id"`
	AgentID     string    `json:"agent_id"`
	LeftID      string    `json:"left_id"`
	RightID     string    `json:"right_id"`
	Description string    `json:"description"`
	Status      string    `json:"status"` // open | resolved
	CreatedAt   time.Time `json:"created_at"`
}

Contradiction records a detected contradiction pair.

type Edge

type Edge struct {
	SourceID  string    `json:"source_id"`
	TargetID  string    `json:"target_id"`
	Kind      EdgeType  `json:"kind"`
	Weight    float64   `json:"weight"`
	CreatedAt time.Time `json:"created_at"`
}

Edge is one directed relation in the adjacency table.

type EdgeType

type EdgeType string

EdgeType enumerates the five allowed edge kinds between wiki pages / interest points (merged from my-agent-core's 4 kinds + the has_page link).

const (
	EdgeRelated    EdgeType = "related"     // generic association
	EdgeContradict EdgeType = "contradicts" // contradiction (enforced bidirectionally)
	EdgeSequel     EdgeType = "sequel"      // sequence/evolution
	EdgeReference  EdgeType = "references"  // reference/source
	EdgeHasPage    EdgeType = "has_page"    // interest point → wiki page
)

type Evidence

type Evidence struct {
	Kind       string    `json:"kind"`                  // session | page | manual | web
	SourceID   string    `json:"source_id"`             // provenance: session_id / page_id / URL
	URL        string    `json:"url,omitempty"`         // source URL for web evidence
	TurnRange  [2]int    `json:"turn_range,omitempty"`  // in-session turn span (1-indexed, 0 = unknown)
	Query      string    `json:"query,omitempty"`       // the search query that surfaced this evidence
	CapturedAt time.Time `json:"captured_at,omitempty"` // when the evidence was captured
	Excerpt    string    `json:"excerpt"`
}

Evidence is one provenance record backing a claim, locatable to source (turn range in a session, or a web URL + the query that surfaced it).

type Freshness

type Freshness struct {
	Level     string    `json:"level"` // fresh | aging | stale | unknown
	UpdatedAt time.Time `json:"updated_at"`
	TTLDays   int       `json:"ttl_days"`
}

Freshness (recency) — carried by interest points/claims, maintained by the correction layer.

type InterestPage added in v0.2.2

type InterestPage struct {
	InterestPointID string
	PageID          string
	PageTitle       string
}

InterestPage is one (interest point → page) has_page association.

type InterestPoint

type InterestPoint struct {
	ID             string      `json:"id"`
	AgentID        string      `json:"agent_id"`
	Name           string      `json:"name"`
	Summary        string      `json:"summary"`
	Keywords       []string    `json:"keywords"`
	Importance     float64     `json:"importance"`
	Status         string      `json:"status"`     // active | archived
	Subjective     bool        `json:"subjective"` // subjective preference/opinion flag (exempt from web fact-check)
	TurnRange      [2]int      `json:"turn_range"` // source session's global turn range [start,end]
	EventTime      time.Time   `json:"event_time"` // event time (session start; session_date with received_at fallback)
	Reliability    Reliability `json:"reliability"`
	Freshness      Freshness   `json:"freshness"`
	FirstSeenAt    time.Time   `json:"first_seen_at"`
	LastSeenAt     time.Time   `json:"last_seen_at"`
	SeenCount      int         `json:"seen_count"`
	SourceSessions []string    `json:"source_session_ids"`
	// WikiWorthy is the LLM's verdict (selective mode) on whether this point
	// deserves its own wiki page. nil = not judged (treated as worthy).
	WikiWorthy *bool `json:"wiki_worthy,omitempty"`
}

InterestPoint is a first-class entity identified by fork analysis.

type LogEdge

type LogEdge struct {
	Action   string   `json:"action"` // add | remove
	SourceID string   `json:"source_id"`
	TargetID string   `json:"target_id"`
	Kind     EdgeType `json:"kind"`
	Weight   float64  `json:"weight"`
}

LogEdge is one structural edge change (add/remove) recorded in a ChangeLog. Only structural kinds (has_page/related/contradicts/sequel) are logged; references (wikilink rebuild diff) is excluded.

type Page

type Page struct {
	ID        string    `json:"id"`
	AgentID   string    `json:"agent_id"`
	PageType  PageType  `json:"page_type"`
	Title     string    `json:"title"`
	BodyMD    string    `json:"body_md"`           // markdown, may contain [[wikilink]]
	Status    string    `json:"status"`            // active | superseded | archived ("" treated as active)
	Tags      []string  `json:"tags,omitempty"`    // taxonomy tags
	Sources   []string  `json:"sources,omitempty"` // sources: web page URLs or existing page ids (may be empty for subjective points)
	EventTime time.Time `json:"event_time"`        // event time (session start)
	Claims    []Claim   `json:"claims"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Page is a wiki page in the store.

type PageType

type PageType string

PageType enumerates wiki page kinds.

const (
	PageEntity    PageType = "entity"
	PageConcept   PageType = "concept"
	PageSynthesis PageType = "synthesis"
	PageSource    PageType = "source"
)
type PendingLink struct {
	AgentID   string    `json:"agent_id"`
	SourceID  string    `json:"source_id"`
	Target    string    `json:"target"`
	CreatedAt time.Time `json:"created_at"`
}

PendingLink records a [[target]] wikilink in page sourceID whose target page does not exist yet (dead link). Used by RebuildEdges as a feedback loop so dead links are visible instead of silently dropped.

type Reliability

type Reliability struct {
	Confidence float64    `json:"confidence"` // 0~1
	Evidence   []Evidence `json:"evidence"`
	Status     string     `json:"status"` // supported | contested | unknown
}

Reliability (trustworthiness) — carried by interest points/claims, written by the correction layer.

type Replacement

type Replacement struct {
	// InterestPointID is the successor interest point (empty when the
	// successor is only reachable as a page).
	InterestPointID string
	// Page is the successor's wiki page when it exists (preferred target
	// for recall/search substitution).
	Page *Page
}

Replacement is the resolved successor of an archived/superseded entity: the far end of the sequel chain (old point --sequel--> new point), preferring the successor's wiki page when one exists.

type SQLiteStore

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

SQLiteStore implements Store backed by a single SQLite database file.

Concurrency design (preserving my-agent-core's multi-goroutine mechanism):

  • A sync.RWMutex guards the *sql.DB handle for open/close.
  • All writes from a single agent are serialized through an agent-keyed mutex map (per-agent write queue), so concurrent EndSession jobs for the same agent cannot interleave partial writes.

func Open

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

Open opens (creating if needed) the SQLite database at path and applies schema migrations.

File-backed databases open in WAL journal mode so concurrent readers never block the writer (and vice versa). ":memory:" keeps a single connection: it is a private per-connection database, so a pool would yield unrelated empty databases.

func (*SQLiteStore) AddEdgePair

func (s *SQLiteStore) AddEdgePair(ctx context.Context, agentID string, e Edge) error

AddEdgePair writes an edge and, for EdgeContradict, automatically creates the reverse edge (A→contradicts B implies B→contradicts A), enforcing the EnsureContradictPair invariant from the design.

func (*SQLiteStore) AddEdgePairs added in v0.2.0

func (s *SQLiteStore) AddEdgePairs(ctx context.Context, agentID string, edges []Edge) error

AddEdgePairs writes many edges in one transaction, enforcing the same bidirectional invariant for EdgeContradict. The batch amortizes the per-edge transaction cost during adjacency rebuild.

func (*SQLiteStore) AddUsage added in v0.2.0

func (s *SQLiteStore) AddUsage(ctx context.Context, date string, input, output, cacheHit int64) error

AddUsage increments the usage row for a date (YYYY-MM-DD) by the given delta, atomically (single upsert with x = x + excluded.x).

func (*SQLiteStore) AppendLog

func (s *SQLiteStore) AppendLog(ctx context.Context, l ChangeLog) error

AppendLog records one structural change. When a per-agent retain cap is set (SetLogRetain > 0), the oldest entries beyond the cap are pruned.

func (s *SQLiteStore) Backlinks(ctx context.Context, agentID, targetID string) ([]Edge, error)

Backlinks returns edges whose target is targetID (reverse lookup).

func (s *SQLiteStore) ClearPendingLink(ctx context.Context, agentID, sourceID, target string) error

ClearPendingLink removes a resolved pending link (its target page now exists). No-op when absent.

func (s *SQLiteStore) ClearPendingLinks(ctx context.Context, agentID, sourceID string, targets []string) error

ClearPendingLinks batch-removes resolved pending links for one source page.

func (*SQLiteStore) Close

func (s *SQLiteStore) Close() error

Close implements Store.

func (*SQLiteStore) CountContradictions added in v0.2.0

func (s *SQLiteStore) CountContradictions(ctx context.Context, agentID string) (int, error)

CountContradictions returns the number of contradictions for an agent.

func (*SQLiteStore) CountInterestPoints added in v0.2.0

func (s *SQLiteStore) CountInterestPoints(ctx context.Context, agentID string) (int, error)

CountInterestPoints returns the number of interest points for an agent without materializing rows (used by the stats endpoint).

func (*SQLiteStore) CountPages added in v0.2.0

func (s *SQLiteStore) CountPages(ctx context.Context, agentID string) (int, error)

CountPages returns the number of wiki pages for an agent.

func (*SQLiteStore) DB

func (s *SQLiteStore) DB() *sql.DB

DB exposes the underlying *sql.DB so the vec layer can share the same database/sql connection (single-binary, single-file store).

func (*SQLiteStore) DeleteEdgesFor

func (s *SQLiteStore) DeleteEdgesFor(ctx context.Context, agentID, sourceID string) error

DeleteEdgesFor removes all edges originating from sourceID.

func (*SQLiteStore) DeletePendingLinksFor

func (s *SQLiteStore) DeletePendingLinksFor(ctx context.Context, agentID, sourceID string) error

DeletePendingLinksFor removes all pending links for a source page.

func (*SQLiteStore) GetInterestPoint

func (s *SQLiteStore) GetInterestPoint(ctx context.Context, agentID, id string) (*InterestPoint, error)

func (*SQLiteStore) GetInterestPointsByIDs added in v0.2.0

func (s *SQLiteStore) GetInterestPointsByIDs(ctx context.Context, agentID string, ids []string) ([]InterestPoint, error)

GetInterestPointsByIDs returns interest points for the given ids in one query. Missing ids are silently skipped; result order is unspecified.

func (*SQLiteStore) GetPage

func (s *SQLiteStore) GetPage(ctx context.Context, agentID, id string) (*Page, error)

GetPage returns a single page WITHOUT its claims. Callers that need claims must fetch them explicitly via ListClaims (or ListClaimsForPageIDs for batches) — most readers (edge rebuild, wikilink resolution) only need the body/title, and eager claim loading made every page read an N+1.

func (*SQLiteStore) GetPagesByIDs added in v0.2.0

func (s *SQLiteStore) GetPagesByIDs(ctx context.Context, agentID string, ids []string) ([]Page, error)

GetPagesByIDs returns pages for the given ids in one query (no claims). Missing ids are silently skipped; result order is unspecified.

func (*SQLiteStore) GetTranscript

func (s *SQLiteStore) GetTranscript(ctx context.Context, agentID, sessionID string) (*Transcript, error)

func (*SQLiteStore) GetUsage added in v0.2.0

func (s *SQLiteStore) GetUsage(ctx context.Context, date string) (*UsageRow, error)

GetUsage returns one day's usage row, or nil when the day is absent.

func (*SQLiteStore) InterestPointPages added in v0.2.2

func (s *SQLiteStore) InterestPointPages(ctx context.Context, agentID string, ipIDs []string) ([]InterestPage, error)

InterestPointPages batch-resolves has_page edges from interest point ids to their wiki pages, joining the pages table for titles. Multi-to-one: one interest point may drive several pages (V2 clustered wikiloop).

func (*SQLiteStore) ListAgentIDs

func (s *SQLiteStore) ListAgentIDs(ctx context.Context) ([]string, error)

ListAgentIDs returns the distinct namespaces that have persisted interest points or wiki pages (empty entries are skipped). Used by the "all" namespace-sharing mode.

func (*SQLiteStore) ListClaims

func (s *SQLiteStore) ListClaims(ctx context.Context, agentID, pageID string) ([]Claim, error)

func (*SQLiteStore) ListClaimsForPageIDs added in v0.2.0

func (s *SQLiteStore) ListClaimsForPageIDs(ctx context.Context, agentID string, pageIDs []string) ([]Claim, error)

ListClaimsForPageIDs fetches claims for many pages in one query (no per-page round trips). Result order is unspecified; callers group by Claim.PageID.

func (*SQLiteStore) ListContradictions

func (s *SQLiteStore) ListContradictions(ctx context.Context, agentID string) ([]Contradiction, error)

func (*SQLiteStore) ListEdges added in v0.2.0

func (s *SQLiteStore) ListEdges(ctx context.Context, agentID string) ([]Edge, error)

ListEdges returns all edges for an agent (graph visualization). Order is unspecified (weight DESC, matching scanEdges callers' expectation).

func (*SQLiteStore) ListInterestPoints

func (s *SQLiteStore) ListInterestPoints(ctx context.Context, agentID string) ([]InterestPoint, error)

func (*SQLiteStore) ListLogs

func (s *SQLiteStore) ListLogs(ctx context.Context, agentID string, limit, offset int) ([]ChangeLog, error)

ListLogs returns change logs for an agent, newest first, with pagination. limit<=0 means no limit; offset starts from 0.

func (*SQLiteStore) ListPages

func (s *SQLiteStore) ListPages(ctx context.Context, agentID string, pageType PageType) ([]Page, error)
func (s *SQLiteStore) ListPendingLinks(ctx context.Context, agentID string) ([]PendingLink, error)

ListPendingLinks returns all dead-link records for an agent.

func (*SQLiteStore) ListTags

func (s *SQLiteStore) ListTags(ctx context.Context, agentID string) ([]TagCount, error)

ListTags aggregates all tags used across an agent's wiki pages, deduplicated and ordered by usage count descending. Built from the page tags JSON column (single source of truth — no separate tag table).

func (*SQLiteStore) ListUnprocessedTranscripts

func (s *SQLiteStore) ListUnprocessedTranscripts(ctx context.Context, agentID string) ([]Transcript, error)

func (*SQLiteStore) ListUsage added in v0.2.0

func (s *SQLiteStore) ListUsage(ctx context.Context, since string) ([]UsageRow, error)

ListUsage returns usage rows from (inclusive) a date onward, oldest first. An empty since returns all rows.

func (*SQLiteStore) MarkTranscriptProcessed

func (s *SQLiteStore) MarkTranscriptProcessed(ctx context.Context, agentID, sessionID string) error
func (s *SQLiteStore) Outlinks(ctx context.Context, agentID, sourceID string) ([]Edge, error)

Outlinks returns edges whose source is sourceID.

func (s *SQLiteStore) RecordPendingLink(ctx context.Context, agentID, sourceID, target string) error

RecordPendingLink notes a [[target]] in page sourceID whose target page does not exist yet (dead link). Upsert semantics: repeated calls update the timestamp instead of duplicating.

func (s *SQLiteStore) RecordPendingLinks(ctx context.Context, agentID, sourceID string, targets []string) error

RecordPendingLinks batch-records dead links for one source page.

func (*SQLiteStore) ResolveReplacement

func (s *SQLiteStore) ResolveReplacement(ctx context.Context, agentID, id string) (*Replacement, error)

ResolveReplacement walks the sequel chain from a possibly archived entity (interest point id or wiki page id) and returns its live successor, or nil when no sequel edge leads onward. A page id resolves to its backing interest point via the reverse has_page edge before walking sequels; the result prefers the successor page (resolved forward via has_page) over the bare successor interest point. Returns (nil, nil) when the entity is not archived and has no successor.

func (*SQLiteStore) SaveTranscript

func (s *SQLiteStore) SaveTranscript(ctx context.Context, t Transcript) error

func (*SQLiteStore) SearchInterestPointsByKeywords

func (s *SQLiteStore) SearchInterestPointsByKeywords(ctx context.Context, agentID, query string, limit int) ([]InterestPoint, error)

func (*SQLiteStore) SearchPagesByKeywords

func (s *SQLiteStore) SearchPagesByKeywords(ctx context.Context, agentID, query string, limit int) ([]Page, error)

func (*SQLiteStore) SetLogRetain

func (s *SQLiteStore) SetLogRetain(ctx context.Context, agentID string, n int) error

SetLogRetain sets the per-agent retention cap (0 = unlimited). Older entries beyond the cap are pruned on the next AppendLog.

func (*SQLiteStore) SetLogRetainDefault

func (s *SQLiteStore) SetLogRetainDefault(ctx context.Context, n int) error

SetLogRetainDefault sets the global default retention cap applied to agents without an explicit per-agent cap (0 = unlimited).

func (*SQLiteStore) UpsertClaim

func (s *SQLiteStore) UpsertClaim(ctx context.Context, c Claim) error

func (*SQLiteStore) UpsertContradiction

func (s *SQLiteStore) UpsertContradiction(ctx context.Context, c Contradiction) error

func (*SQLiteStore) UpsertEdge

func (s *SQLiteStore) UpsertEdge(ctx context.Context, agentID string, e Edge) error

UpsertEdge writes a single directed edge (no invariant enforcement). Prefer AddEdgePair for contradiction edges so the reverse direction is created automatically.

func (*SQLiteStore) UpsertInterestPoint

func (s *SQLiteStore) UpsertInterestPoint(ctx context.Context, p InterestPoint) error

func (*SQLiteStore) UpsertPage

func (s *SQLiteStore) UpsertPage(ctx context.Context, p Page) error

type Store

type Store interface {
	// ---- interest points ----
	UpsertInterestPoint(ctx context.Context, p InterestPoint) error
	GetInterestPoint(ctx context.Context, agentID, id string) (*InterestPoint, error)
	// GetInterestPointsByIDs fetches interest points by id in one query.
	GetInterestPointsByIDs(ctx context.Context, agentID string, ids []string) ([]InterestPoint, error)
	// InterestPointPages resolves each interest point id's has_page outlinks to
	// its wiki pages (multi-to-one: one point may map to several pages). Rows
	// are (interest_point_id, page_id, page_title); ids with no has_page are
	// absent. Used by IP_query and wiki_write has_page backfill.
	InterestPointPages(ctx context.Context, agentID string, ipIDs []string) ([]InterestPage, error)
	ListInterestPoints(ctx context.Context, agentID string) ([]InterestPoint, error)
	SearchInterestPointsByKeywords(ctx context.Context, agentID, query string, limit int) ([]InterestPoint, error)

	// ---- wiki pages ----
	UpsertPage(ctx context.Context, p Page) error
	GetPage(ctx context.Context, agentID, id string) (*Page, error)
	// GetPagesByIDs fetches pages by id in one query (no claims, order
	// unspecified, missing ids skipped). Batch counterpart to GetPage.
	GetPagesByIDs(ctx context.Context, agentID string, ids []string) ([]Page, error)
	ListPages(ctx context.Context, agentID string, pageType PageType) ([]Page, error)
	SearchPagesByKeywords(ctx context.Context, agentID, query string, limit int) ([]Page, error)
	// ListTags aggregates page tags for the agent (tag taxonomy), count desc.
	ListTags(ctx context.Context, agentID string) ([]TagCount, error)

	// ---- adjacency edges (wikilinks) ----
	UpsertEdge(ctx context.Context, agentID string, e Edge) error
	// AddEdgePair adds the edge and (for EdgeContradict) the reverse pair,
	// enforcing the EnsureContradictPair invariant.
	AddEdgePair(ctx context.Context, agentID string, e Edge) error
	// AddEdgePairs writes many edges in one transaction (same invariant).
	AddEdgePairs(ctx context.Context, agentID string, edges []Edge) error
	Outlinks(ctx context.Context, agentID, sourceID string) ([]Edge, error)
	Backlinks(ctx context.Context, agentID, targetID string) ([]Edge, error)
	// ListEdges returns all edges for an agent (graph visualization).
	ListEdges(ctx context.Context, agentID string) ([]Edge, error)
	DeleteEdgesFor(ctx context.Context, agentID, sourceID string) error
	// ResolveReplacement returns the live successor of an archived/superseded
	// entity (or nil), following sequel edges. Used by recall/search to
	// silently substitute superseded entities.
	ResolveReplacement(ctx context.Context, agentID, id string) (*Replacement, error)

	// ---- pending links (dead-link feedback) ----
	// RecordPendingLink notes a [[target]] in page sourceID that has no
	// matching page yet (dead link). Upsert semantics: repeated calls for the
	// same pair update the timestamp, not duplicate.
	RecordPendingLink(ctx context.Context, agentID, sourceID, target string) error
	// RecordPendingLinks batch-records dead links for one source page.
	RecordPendingLinks(ctx context.Context, agentID, sourceID string, targets []string) error
	// ClearPendingLink removes a resolved pending link (its target page now
	// exists). No-op when absent.
	ClearPendingLink(ctx context.Context, agentID, sourceID, target string) error
	// ClearPendingLinks batch-removes resolved pending links for one source page.
	ClearPendingLinks(ctx context.Context, agentID, sourceID string, targets []string) error
	// DeletePendingLinksFor removes all pending links for a source page
	// (used by RebuildEdges to refresh the dead-link set from current body).
	DeletePendingLinksFor(ctx context.Context, agentID, sourceID string) error
	ListPendingLinks(ctx context.Context, agentID string) ([]PendingLink, error)

	// ---- claims ----
	UpsertClaim(ctx context.Context, c Claim) error
	ListClaims(ctx context.Context, agentID, pageID string) ([]Claim, error)
	// ListClaimsForPageIDs fetches claims for many pages in one query.
	ListClaimsForPageIDs(ctx context.Context, agentID string, pageIDs []string) ([]Claim, error)

	// ---- contradictions ----
	UpsertContradiction(ctx context.Context, c Contradiction) error
	ListContradictions(ctx context.Context, agentID string) ([]Contradiction, error)

	// ---- transcripts ----
	SaveTranscript(ctx context.Context, t Transcript) error
	GetTranscript(ctx context.Context, agentID, sessionID string) (*Transcript, error)
	// ListUnprocessedTranscripts returns transcripts for agentID that have not
	// been marked processed (processed_at IS NULL), oldest first. Used by the
	// worker queue and manual fork to pull pending session-end data.
	ListUnprocessedTranscripts(ctx context.Context, agentID string) ([]Transcript, error)
	MarkTranscriptProcessed(ctx context.Context, agentID, sessionID string) error

	// ---- change log ----
	AppendLog(ctx context.Context, l ChangeLog) error
	ListLogs(ctx context.Context, agentID string, limit, offset int) ([]ChangeLog, error)
	SetLogRetain(ctx context.Context, agentID string, n int) error
	SetLogRetainDefault(ctx context.Context, n int) error

	// ListAgentIDs returns the distinct namespaces that have persisted data
	// (interest points or wiki pages). Used for the "all" namespace-sharing
	// mode to discover the full namespace set dynamically.
	ListAgentIDs(ctx context.Context) ([]string, error)

	// ---- stats (counts only, no full-row scans) ----
	CountInterestPoints(ctx context.Context, agentID string) (int, error)
	CountPages(ctx context.Context, agentID string) (int, error)
	CountContradictions(ctx context.Context, agentID string) (int, error)

	// ---- usage (token accounting, per day) ----
	AddUsage(ctx context.Context, date string, input, output, cacheHit int64) error
	GetUsage(ctx context.Context, date string) (*UsageRow, error)
	ListUsage(ctx context.Context, since string) ([]UsageRow, error)

	Close() error
}

Store is the facade interface for all persistent state, scoped by agent_id. Domain layers depend on this interface only (mock-friendly); the SQLite implementation lives in sqlite.go.

type TagCount

type TagCount struct {
	Tag   string `json:"tag"`
	Count int    `json:"count"`
}

TagCount is one aggregated tag with its usage count.

type Transcript

type Transcript struct {
	SessionID   string     `json:"session_id"`
	AgentID     string     `json:"agent_id"`
	TurnCount   int        `json:"turn_count"`
	RawTurns    string     `json:"raw_turns"`              // JSON: [{role, content}]
	ReceivedAt  time.Time  `json:"received_at"`            // server receive time
	SessionDate *time.Time `json:"session_date,omitempty"` // passed-through session start time (RFC3339, nullable)
	ProcessedAt *time.Time `json:"processed_at,omitempty"`
}

Transcript is a full conversation pushed at session end.

type UsageRow added in v0.2.0

type UsageRow struct {
	Date      string    `json:"date"`
	Input     int64     `json:"input_tokens"`
	Output    int64     `json:"output_tokens"`
	CacheHit  int64     `json:"cache_hit_tokens"`
	UpdatedAt time.Time `json:"updated_at"`
}

UsageRow is one day's aggregated token usage.

Jump to

Keyboard shortcuts

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