import type { GoalRecord, TodoTreePolicyRecord } from "./events.js"; import type { StreamReadOptions, StoreWriteOptions } from "./log.js"; import type { GoalClaimsSideTable, RestoredGoalStore, RestoreDiagnostic } from "./restore.js"; import type { GoalTodoNode } from "../core/types.js"; export declare const SNAPSHOT_FORMAT_VERSION = 1; export declare const SNAPSHOT_FILE_NAME = "snapshot.json"; export declare const SNAPSHOT_MARKER_FILE_NAME = "snapshot.marker.json"; export declare const SNAPSHOT_MARKER_SCHEMA = "pi-goals.snapshot-marker.v1"; export declare const DEFAULT_COMPACTION_THRESHOLD = 200; export interface GoalStoreSnapshot { formatVersion: typeof SNAPSHOT_FORMAT_VERSION; goalId: string; writtenAt: number; revisions: { goal: number; todos: number; }; goal?: GoalRecord; todoGraph: { goalId: string; revision: number; nodes: GoalTodoNode[]; policy?: TodoTreePolicyRecord; }; claims: GoalClaimsSideTable; } export interface SnapshotMarker { schema: typeof SNAPSHOT_MARKER_SCHEMA; goalId: string; snapshotWrittenAt: number; appendsSinceSnapshot: number; revisions: { goal: number; todos: number; }; } export type ReadSnapshotResult = { ok: true; snapshot: GoalStoreSnapshot; } | { ok: false; code: "snapshot_missing" | "snapshot_invalid"; message: string; }; export type CompactGoalStoreResult = { ok: true; snapshot: GoalStoreSnapshot; } | { ok: false; code: "restore_blocked" | "write_error"; message: string; diagnostics?: readonly RestoreDiagnostic[]; }; /** Atomically write the snapshot; refuses to write anything non-canonical. */ export declare function writeSnapshotFile(stateDir: string, goalId: string, snapshot: GoalStoreSnapshot): { ok: true; } | { ok: false; code: "write_error"; message: string; }; /** Strict snapshot read: missing file, bad JSON, or any invalid shape fails. */ export declare function readSnapshotFile(stateDir: string, goalId: string): ReadSnapshotResult; /** * Advisory marker read. The marker is compaction bookkeeping only (never * event lineage), so any read/parse failure resolves to undefined instead * of blocking the store. */ export declare function readSnapshotMarker(stateDir: string, goalId: string): SnapshotMarker | undefined; export declare function writeSnapshotMarker(stateDir: string, goalId: string, marker: SnapshotMarker): void; /** Build a snapshot payload from a successful restore (receipts excluded by design). */ export declare function buildSnapshotFromRestore(restored: RestoredGoalStore, writtenAt: number): GoalStoreSnapshot; /** * Compact one goal: restore → snapshot → rewrite the three logs to single * baseline markers → reset the marker counter. A restore-blocked goal is * never compacted (its counter stays bumped and the next append retries). */ export declare function compactGoalStore(stateDir: string, goalId: string, options?: StreamReadOptions): CompactGoalStoreResult; /** * Post-append bookkeeping for the goal's three streams: bump the advisory * marker counter, then compact once the threshold is reached (unless * compaction is off). Called by the log append APIs. */ export declare function noteGoalAppendAndMaybeCompact(stateDir: string, goalId: string, options?: StoreWriteOptions): void;