/** * Filesystem storage of continual harness state: atomic writes, corruption * degradation to empty state, local/global merge rules, and the cross-session * refinement history. * @module dsh-continual-harness */ import type { HarnessEntry, HarnessState, RefinementResult } from './types.ts'; /** A fresh, empty harness state at the current schema version. */ export declare function emptyHarnessState(): HarnessState; /** Directory of the session-local store under the plugin-owned harness home. */ export declare function getLocalHarnessStateDir(home: string, sessionKey: string): string; /** Directory of the cross-session global store: the plugin-owned harness home itself. */ export declare function getGlobalHarnessStateDir(home: string): string; /** Migrate a parsed state payload to the current schema version. */ export declare function migrateHarnessState(parsed: unknown): { state: HarnessState; diagnostics: string[]; }; /** * Drop an out-of-domain `blastRadius` instead of dropping its entry. The load * guard discards a whole malformed entry, and losing a memory because one field * holds a stale or hand-edited value would break the backwards-compatibility * hard constraint. A cleared entry is refilled from history when a legal * declaration exists, so this normalizes rather than invents. */ export declare function normalizeBlastRadius(state: HarnessState): number; /** * Backfill `blastRadius` onto entries from the refinement history. * * Groups applied edits by `(kind, id)` and takes the radius declared by the * group's **last successful** edit; a group whose last successful edit declared * nothing — or that has no successful edit — leaves the entry **undeclared** * rather than inferring a value. Rejected edits are skipped, because their * recorded radius can be a `general` fallback rather than a declaration * (`AppliedRefinementEdit.blastRadius`). * * Idempotent: only entries that lack the field are touched, so a second run * over an already-backfilled state fills nothing. */ export declare function backfillBlastRadius(state: HarnessState): { filled: number; undeclared: number; }; /** * Read one store file: missing → empty; corrupt/future → backed up once * (`.corrupt.bak`), degraded to empty, and reported through * `onDiagnostics` — so the next commit can never silently destroy the only * copy of the user's entries. The file itself is never rewritten by load. */ export declare function loadHarnessState(dir: string, onDiagnostics?: (diagnostics: string[]) => void): HarnessState; /** * Merge a local state over a global one: plain ids resolve to local entries * and to global entries the local store does not shadow; a same-id global * entry shadowed by a local one survives under a `local:` id prefix. * Refinements concatenate with the local history first. */ export declare function mergeHarnessStates(global: HarnessState, local: HarnessState): HarnessState; /** Atomically persist a state file (tmp file + rename preserves mode). */ export declare function saveHarnessState(dir: string, state: HarnessState): void; /** Append one refinement record to a refinement journal (jsonl). */ export declare function appendRefinement(dir: string, result: RefinementResult): void; /** Append one global refinement to the cross-session history. */ export declare function appendGlobalRefinement(home: string, result: RefinementResult): void; /** Append one session-local refinement to the session's history journal. */ export declare function appendLocalRefinement(home: string, sessionKey: string, result: RefinementResult): void; /** Read the cross-session refinement history. */ export declare function loadGlobalRefinementHistory(home: string): RefinementResult[]; /** Read the session-local refinement history (full records kept for rollback). */ export declare function loadSessionRefinementHistory(home: string, sessionKey: string): RefinementResult[]; /** Merge histories with local session events first, de-duplicated by id. */ export declare function mergeRefinementHistory(local: RefinementResult[], global: RefinementResult[]): RefinementResult[]; /** Rotate the active usage log when it exceeds this size (default 1 MiB). */ export declare const USAGE_ROTATION_BYTES: number; /** * Append one injection telemetry event line under the harness home. * Delegates to the batch writer so rotation policy stays in one place. */ export declare function appendUsageEvent(home: string, event: { key: string; at: string; }): void; /** * Append many telemetry events in one open/write (batch, same timestamp). * * Rotation: once the active `usage.events.jsonl` reaches `rotationBytes`, it * is renamed to an epoch-stamped archive (`usage.events..jsonl`) before * the new lines are written, so the active file stays small while the full * history is preserved across archives. Archives are never auto-deleted (a * pruning policy is left to the operator). `rotationBytes` is injectable for * tests; production callers use the default threshold. */ export declare function appendUsageEvents(home: string, events: Array<{ key: string; at: string; }>, rotationBytes?: number): void; /** * Read the injection telemetry log across the active file and every rotated * archive; missing home → empty, bad lines skipped. Files are merged in name * order — epoch-stamped archives sort before the plain active file — so * event order is preserved across rotations. */ export declare function loadUsageEvents(home: string): Array<{ key: string; at: string; }>; /** Resolve the default harness home under the dsh home directory. */ export declare function defaultHarnessHome(): string; /** Directory of a harness store's parent file, for diagnostics. */ export declare function storeParentDir(dir: string): string; /** Whether a directory exists (used by the invariant companion). */ export declare function storeDirExists(dir: string): boolean; /** Validate an entry record shape (used by the invariant companion). */ export declare function isHarnessEntry(value: unknown): value is HarnessEntry; //# sourceMappingURL=storage.d.ts.map