import { type MemoryStore, type UtilityGate } from "../../core/memory.js"; import type { CheckpointStore } from "../../core/checkpoint-store.js"; import type { ToolResultStore } from "../../core/tool-result-store.js"; import { type EvictPolicy } from "../../core/session-store.js"; import type { SessionStore } from "../../core/session.js"; import { type FileCheckpointStoreOptions } from "./checkpoint-store.js"; import type { SessionPolicyStore } from "../../core/session-policy-store.js"; import type { FileSnapshotStore } from "../../core/file-snapshot-store.js"; import type { WorkflowJournalStore } from "../../core/workflow-journal-store.js"; export { FileCheckpointStore, type FileCheckpointStoreOptions } from "./checkpoint-store.js"; export { FileMemoryStore } from "./memory-store.js"; export { FileSessionRepo } from "./session-store.js"; export { FileToolResultStore } from "./tool-result-store.js"; export { FileSessionPolicyStore } from "./session-policy-store.js"; export { FileFileSnapshotStore } from "./file-snapshot-store.js"; export { FileWorkflowJournalStore, MAX_JOURNAL_RESULT_BYTES, oversizeJournalResult } from "./workflow-journal-store.js"; export { resolveDataRoot, sanitizeScope, sanitizePathComponent, createFileConsolidationLock } from "./fs-atomic.js"; export { atomicWriteFile, writeThenLink, ensureDir, readJsonlRecords, AppendLog } from "./fs-atomic.js"; /** * design/80 — the file-backed `StorageBackend` for the local (TOC) single-user binary: the 3rd store impl * alongside `InMemory*` and `Pg*`, selected purely by what the embedder injects into `RunnerDeps` (no engine * change). Construct one over a single data root and pass its four members straight into `RunnerDeps`: * * ```ts * const backend = new FileStorageBackend(); // ~/.ai-agent (or $AGENT_DATA_DIR) * const runner = new Runner({ * brain, * sessionStore: backend.sessionStore, * checkpointStore: backend.checkpointStore, * memoryStore: backend.memoryStore, * toolResultStore: backend.toolResultStore, * }); * // …on shutdown: * await backend.dispose(); * ``` * * **Single-instance-per-data-dir (§2.4 / §7 decision 4):** the constructor takes a coarse boot `flock` on * `root/LOCK`. A second `FileStorageBackend` over the same dir FAILS FAST ("another instance owns this data * dir"); a stale lock from a dead PID is pruned. This is the ONLY file lock here — the once-only checkpoint * CAS is in-process (one event loop), so there is no per-operation lock. Cross-process correct concurrency * is the Pg/TiDB backend's job, by design. */ export interface FileStorageBackendOptions { /** Data root. Default `$AGENT_DATA_DIR ?? ~/.ai-agent`, NFC-normalized + realpath-canonicalized. */ root?: string; /** Profile-injected promotable-write gate (design/77 §2). Threaded into `guardedMemoryStore`. */ utilityGate?: UtilityGate; /** `TtlSessionStore` idle-eviction policy. Default `"forget"` (§7 decision 5 — durable history is never * deleted by an idle timer). */ evict?: EvictPolicy; /** Checkpoint store tuning (fsync cadence for `put`, ledger compaction threshold). */ checkpoint?: FileCheckpointStoreOptions; /** design/101 §E19 — file-snapshot enumerator bounds (maxFiles/maxBytes/ignoreDirs). Default * {@link DEFAULT_SNAPSHOT_BOUNDS}. */ snapshotBounds?: Partial; /** design/81 Slice 5 — an optional {@link import("../../core/memory.js").Embedder}. Injected ⇒ the memory * store does portable (in-process) vector recall over a rebuildable sidecar index (`vectorMode:"portable"`); * absent ⇒ the lexical floor, byte-identical to before. Config-driven (the deployment injects it); OFF by * default. 🔴 the consolidation band `{0.05,0.3}` is tuned for the lexical distance — a real embedding model * needs it re-tuned + a no-mis-merge live check BEFORE production-enable (design/81 Slice 5 release gate). */ embedder?: import("../../core/memory.js").Embedder; } export declare class FileStorageBackend { /** The resolved, canonical data root all four stores live under. */ readonly root: string; readonly sessionStore: SessionStore; readonly checkpointStore: CheckpointStore; /** Wrapped in `guardedMemoryStore` (Gate-2 chokepoint). design/81: implements the id-addressable trio on * a lexical cosine-distance → `supportsConsolidation` is true → end-of-task consolidation lights up. */ readonly memoryStore: MemoryStore; readonly toolResultStore: ToolResultStore; /** design/99 §E6 — file-backed per-session permission rules (E6). Wire into `RunnerDeps.sessionPolicyStore` * for a local deployment that needs session rules to survive a restart. */ readonly sessionPolicyStore: SessionPolicyStore; /** design/101 §E19 — file-backed working-tree snapshots (rewind-files). Wire into * `RunnerDeps.fileSnapshotStore`. Content-addressed blobs persist across restarts (local-only; a remote env * defers rewind to its own VM-snapshot backend). */ readonly fileSnapshotStore: FileSnapshotStore; /** SVC-2 / [381]⑥ (onboarded per [375]) — file-backed durable workflow resume journal. Wire into * `RunnerDeps.workflowJournalStore` so `resumeFromRunId` survives a process restart on a TOC box. */ readonly workflowJournalStore: WorkflowJournalStore; /** * design/84 Seam B (TOC) — the per-scope consolidation lock for `consolidateScope`'s `acquire` injection * point: `consolidateScope(scope, { store: backend.memoryStore, llm, acquire: backend.consolidationLock })`. * Stops two OS processes sharing this data dir from consolidating the SAME scope at once (a busy scope ⇒ * `undefined` ⇒ the pass is a no-op). The locks live under `root/consolidation-locks/`. */ readonly consolidationLock: (scope: string) => (() => void) | undefined; private readonly lock; private readonly fileCheckpoints; private readonly fileMemory; private readonly ttl; private readonly fileWorkflowJournal; constructor(opts?: FileStorageBackendOptions); /** Release file handles + the boot lock (best-effort). Call on shutdown so a successor can acquire. */ dispose(): Promise; } //# sourceMappingURL=index.d.ts.map