{"modulePath":"github.com/memcode-ai/memcode","version":"v0.56.16","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package store\n\nPackage store is the persistence layer for the memcode state engine. The event log is the source of truth; entities, edges, objectives and current\\_state are materialized projections. Everything sits behind the Store interface so the local SQLite backend can be swapped for a cloud backend (e.g. Postgres) later without touching callers.\n\n## Types\n\n```go\ntype Claim struct {\n\tID               string\n\tType             string // doctrine | preference | command | decision | warning\n\tText             string\n\tScope            string\n\tStatus           string // candidate | current | stale | conflicted | rejected\n\tConfidence       string\n\tEvidence         string\n\tSourcePath       string\n\tSourceModifiedAt string\n\tExtractedAt      time.Time\n}\n```\nClaim is an adjudicated assertion extracted from sources + evidence.\n\n```go\ntype Edge struct {\n\tSrc       string\n\tDst       string\n\tKind      string\n\tAttrs     json.RawMessage\n\tValidFrom *time.Time\n\tValidTo   *time.Time\n}\n```\nEdge is a typed relationship between two entities.\n\n```go\ntype EdgeFilter struct {\n\tSrc  string\n\tDst  string\n\tKind string\n}\n```\nEdgeFilter narrows ListEdges. Empty fields are wildcards.\n\n```go\ntype Entity struct {\n\tID        string // \"\u003ckind\u003e:\u003ckey\u003e\"\n\tKind      string\n\tKey       string\n\tAttrs     json.RawMessage\n\tValidFrom *time.Time\n\tValidTo   *time.Time\n}\n```\nEntity is a node in the top-down model (subsystem, concept, doctrine, …).\n\n```go\ntype Event struct {\n\tID        int64\n\tTS        time.Time\n\tKind      string\n\tActor     string\n\tPayload   json.RawMessage\n\tValidFrom *time.Time\n\tValidTo   *time.Time\n}\n```\nEvent is one row in the append-only log — the source of truth.\n\n```go\ntype EventFilter struct {\n\tKinds []string // any-of; empty = all kinds\n\tLimit int      // 0 = no limit\n}\n```\nEventFilter narrows ListEvents. Zero value matches everything.\n\n```go\ntype Objective struct {\n\tID        string\n\tTitle     string\n\tStatus    string\n\tPriority  int\n\tParentID  string\n\tCreatedAt time.Time\n\tUpdatedAt time.Time\n}\n```\nObjective is a human-authored goal.\n\n```go\ntype PreferenceCandidate struct {\n\tID            string\n\tAxis          string\n\tText          string\n\tScope         string\n\tWeight        float64\n\tSignalCount   int\n\tSessionCount  int\n\tFirstSeen     time.Time\n\tLastSeen      time.Time\n\tStatus        string // candidate | confirmed | demoted\n\tConfirmedPath string\n\tEvidence      json.RawMessage\n}\n```\nPreferenceCandidate is a behavior-derived directive that accumulated enough weighted evidence to be a standing preference candidate. Materialized from preference\\_signal events by the prefs reducer. The event log is the source of truth; this table is a projection rebuilt atomically by prefs.Reduce.\n\n```go\ntype State struct {\n\tScope         string\n\tLayer         string\n\tBody          json.RawMessage\n\tSourceEventID *int64\n\tRefreshedAt   time.Time\n}\n```\nState is one materialized current\\_state layer for a scope.\n\n```go\ntype Store interface {\n\tAppendEvent(ctx context.Context, e Event) (int64, error)\n\tListEvents(ctx context.Context, f EventFilter) ([]Event, error)\n\t// SessionActivity maps each session id stamped in event payloads to its\n\t// newest event time, ignoring events of a kind in skipKinds.\n\tSessionActivity(ctx context.Context, skipKinds []string) (map[string]time.Time, error)\n\t// DeleteSessionEvents removes the events of the given sessions except the\n\t// kinds in keepKinds (see sessions.go).\n\tDeleteSessionEvents(ctx context.Context, sessionIDs, keepKinds []string) (int64, error)\n\n\tUpsertEntity(ctx context.Context, e Entity) error\n\tListEntities(ctx context.Context, kind string) ([]Entity, error) // kind=\"\" = all\n\tGetEntity(ctx context.Context, id string) (Entity, bool, error)\n\n\tUpsertEdge(ctx context.Context, e Edge) error\n\tListEdges(ctx context.Context, f EdgeFilter) ([]Edge, error)\n\n\tCreateObjective(ctx context.Context, o Objective) error\n\tUpdateObjective(ctx context.Context, o Objective) error\n\tGetObjective(ctx context.Context, id string) (Objective, bool, error)\n\tListObjectives(ctx context.Context) ([]Objective, error)\n\n\tPutState(ctx context.Context, s State) error\n\tGetState(ctx context.Context, scope, layer string) (State, bool, error)\n\n\tAddClaim(ctx context.Context, c Claim) error\n\tListClaims(ctx context.Context) ([]Claim, error)\n\tClearClaims(ctx context.Context) error\n\n\tAddPreferenceCandidate(ctx context.Context, c PreferenceCandidate) error\n\tListPreferenceCandidates(ctx context.Context) ([]PreferenceCandidate, error)\n\tClearPreferenceCandidates(ctx context.Context) error\n\tUpdatePreferenceCandidateStatus(ctx context.Context, id, status, confirmedPath string, weight float64) error\n\n\t// RunInTx runs fn inside a single database transaction. fn receives a Tx that\n\t// exposes the claim-mutation methods (and may grow more as needed). The\n\t// transaction commits when fn returns nil and rolls back on any error. This is\n\t// the atomicity seam for operations that must not leave a partial state — e.g.\n\t// learn.Run's clear+re-insert claim rebuild. Additive: callers that don't use\n\t// it are unaffected.\n\tRunInTx(ctx context.Context, fn func(Tx) error) error\n\n\tClose() error\n}\n```\nStore is the persistence contract for the engine.\n\n```go\nfunc Open(ctx context.Context, path string) (Store, error)\n```\nOpen opens (creating if needed) the SQLite database at path and applies the schema. The returned Store is safe for sequential use by a single CLI process.\n\n```go\ntype Tx interface {\n\tClearClaims(ctx context.Context) error\n\tAddClaim(ctx context.Context, c Claim) error\n\tClearPreferenceCandidates(ctx context.Context) error\n\tAddPreferenceCandidate(ctx context.Context, c PreferenceCandidate) error\n}\n```\nTx is a transaction-scoped handle to the claim-mutation methods. It exists so a caller can make multiple writes atomically (e.g. ClearClaims + a batch of AddClaim) without exposing the raw \\*sql.Tx. Methods mirror their Store counterparts — same SQL, same semantics — just executed against the transaction.\n\n","path":"github.com/memcode-ai/memcode/internal/store","name":"store","synopsis":"Package store is the persistence layer for the memcode state engine.","isRedistributable":true}
