/** * MemoryStore, project memory substrate. * * Durable, provenance-rich memory for decisions, constraints, incidents, and * patterns. Backed by SQLite via SQLiteStore. Survives process restarts and is * queryable by runtime/panel/context enrichment consumers. * * Provenance links can reference: session, turn, task, event, or file. */ import { type MemoryVectorStats } from './memory-vector-store.js'; import { MemoryEmbeddingProviderRegistry, type MemoryEmbeddingDoctorReport } from './memory-embeddings.js'; export type MemoryClass = 'decision' | 'constraint' | 'incident' | 'pattern' | 'fact' | 'risk' | 'runbook' | 'architecture' | 'ownership'; export type MemoryScope = 'session' | 'project' | 'team'; export type MemoryReviewState = 'fresh' | 'reviewed' | 'stale' | 'contradicted'; export type ProvenanceLinkKind = 'session' | 'turn' | 'task' | 'event' | 'file'; export interface ProvenanceLink { kind: ProvenanceLinkKind; /** The referenced identifier (session ID, turn number, task ID, event ID, or file path). */ ref: string; /** Optional human-readable label. */ label?: string | undefined; } export interface MemoryRecord { /** Auto-assigned, unique within the store. */ id: string; /** Scope of the record for retrieval and sharing workflows. */ scope: MemoryScope; /** Memory class, governs retrieval priority and display grouping. */ cls: MemoryClass; /** Brief summary (one sentence). */ summary: string; /** Optional expanded detail. */ detail?: string | undefined; /** Tags for search and grouping. */ tags: string[]; /** Provenance links back to the source context. */ provenance: ProvenanceLink[]; /** Operator/state review signal. */ reviewState: MemoryReviewState; /** Confidence score from 0-100. Higher means the record is more trusted for retrieval. */ confidence: number; /** Last explicit review timestamp, if any. */ reviewedAt?: number | undefined; /** Reviewer identity, if recorded. */ reviewedBy?: string | undefined; /** If stale/contradicted, why. */ staleReason?: string | undefined; /** Creation timestamp (epoch ms). */ createdAt: number; /** Last updated timestamp (epoch ms). */ updatedAt: number; /** * Temporal validity window, start. Epoch ms. When set, the record is NOT * injected before this time (it is "pending"). Undefined means valid from * creation. Consulted at injection time; see memory-recall-contract.ts. */ validFrom?: number | undefined; /** * Temporal validity window, end. Epoch ms. When set, the record stops being * injected at/after this time (it is "expired"), but it is NOT deleted, and * read/list surfaces label it expired rather than silently dropping it. * Undefined means no expiry. */ validUntil?: number | undefined; } export type { MemoryTemporalStatus } from './memory-temporal.js'; export { memoryRecordTemporalStatus, isMemoryTemporallyActive } from './memory-temporal.js'; export interface MemoryLink { /** ID of the source record. */ fromId: string; /** ID of the target record. */ toId: string; /** Human-readable relationship label, e.g. "caused", "supersedes". */ relation: string; /** Creation timestamp (epoch ms). */ createdAt: number; } export interface MemorySearchFilter { scope?: MemoryScope | undefined; cls?: MemoryClass | undefined; tags?: string[] | undefined; /** Full-text substring match on summary and detail. */ query?: string | undefined; /** Use the sqlite-vec semantic index for query ranking when available. */ semantic?: boolean | undefined; /** Return records created after this timestamp. */ since?: number | undefined; /** Match a specific review state or a small set of states. */ reviewState?: MemoryReviewState | MemoryReviewState[] | undefined; /** Minimum confidence threshold, 0-100. */ minConfidence?: number | undefined; /** Restrict to records with at least one matching provenance kind. */ provenanceKinds?: ProvenanceLinkKind[] | undefined; /** Convenience flag for review queue retrieval. */ staleOnly?: boolean | undefined; limit?: number | undefined; } export interface MemoryAddOptions { scope?: MemoryScope | undefined; cls: MemoryClass; summary: string; detail?: string | undefined; tags?: string[] | undefined; provenance?: ProvenanceLink[] | undefined; /** Temporal validity window start (epoch ms). Undefined = valid from creation. */ validFrom?: number | undefined; /** Temporal validity window end (epoch ms). Undefined = no expiry. */ validUntil?: number | undefined; review?: { state?: MemoryReviewState | undefined; confidence?: number | undefined; reviewedAt?: number | undefined; reviewedBy?: string | undefined; staleReason?: string | undefined; }; } export interface MemoryReviewPatch { state?: MemoryReviewState | undefined; confidence?: number | undefined; reviewedBy?: string | undefined; staleReason?: string | undefined; } export interface MemoryBundle { schemaVersion: 'v1'; exportedAt: number; scope: MemoryScope | 'all'; recordCount: number; linkCount: number; records: MemoryRecord[]; links: MemoryLink[]; } export interface MemoryImportResult { importedRecords: number; skippedRecords: number; importedLinks: number; } export interface MemorySemanticSearchResult { record: MemoryRecord; distance: number; similarity: number; score: number; } export interface MemoryStoreOptions { embeddingRegistry: MemoryEmbeddingProviderRegistry; enableVectorIndex?: boolean | undefined; vectorDbPath?: string | undefined; } export interface MemoryDoctorReport { readonly vector: MemoryVectorStats; readonly embeddings: MemoryEmbeddingDoctorReport; readonly checkedAt: number; } export { MemoryRegistry } from './memory-registry.js'; export declare class MemoryStore { private sqlite; private vectorIndex; private ready; private rebuildVectorIndexPromise; private readonly embeddingRegistry; constructor(dbPath: string | undefined, options: MemoryStoreOptions); init(): Promise; get isReady(): boolean; /** The on-disk database path backing this store, or null when ephemeral. */ get dbPath(): string | null; /** Add a new memory record. Returns the created record. */ add(opts: MemoryAddOptions): Promise; /** Retrieve a single record by ID. */ get(id: string): MemoryRecord | null; /** Search records with an optional filter. */ search(filter?: MemorySearchFilter): MemoryRecord[]; searchSemantic(filter?: MemorySearchFilter): MemorySemanticSearchResult[]; reviewQueue(limit?: number, scope?: MemoryScope): MemoryRecord[]; exportBundle(filter?: MemorySearchFilter): MemoryBundle; importBundle(bundle: MemoryBundle): Promise; /** Create a directed link between two records. */ link(fromId: string, toId: string, relation: string): Promise; /** Get all links where this record is either source or target. */ linksFor(id: string): MemoryLink[]; /** * Update mutable fields of an existing record. For the temporal window, * `undefined` leaves the current bound unchanged while an explicit `null` * clears it (so the projection round-trip can both set and remove a window). */ update(id: string, patch: { scope?: MemoryScope; summary?: string; detail?: string; tags?: string[]; validFrom?: number | null; validUntil?: number | null; }): MemoryRecord | null; review(id: string, patch: MemoryReviewPatch): MemoryRecord | null; /** Delete a record and all its links. */ delete(id: string): boolean; rebuildVectorIndex(): MemoryVectorStats; rebuildVectorIndexAsync(): Promise; vectorStats(): MemoryVectorStats; doctor(): Promise; save(): Promise; close(): void; /** * Re-root the store to a new SQLite database path. * * Closes the existing SQLite handle and vector index, then re-opens both at * the new path. The caller is responsible for ensuring no writes are in-flight * when this is called (WorkspaceSwapManager enforces this via the busy-session * guard). * * @throws if the new SQLite store or vector index cannot be opened. */ reroot(newDbPath: string): Promise; private persist; } //# sourceMappingURL=memory-store.d.ts.map