/** * journal — journal-first persistence for task runtime (G-026 M1, ADR-0004 #10). * * Order: event append (events.jsonl, flush+fsync) → snapshot (runtime.json, * atomic write) → tasks.jsonl compatibility projection. * events.jsonl is the source of truth; runtime.json is a derived index; * tasks.jsonl is a read-only compatibility projection for legacy consumers. * * Corruption handling (fail closed): * - half-written last line when the file ends without trailing newline → tolerated * only if the line itself is parseable; otherwise RuntimeCorruptError. * - non-sequential seq / duplicate seq / illegal state fields → RuntimeCorruptError. */ import { type RuntimeEvent, type RuntimeSnapshot, type TaskRuntimeLayout } from "./file-layout.js"; export interface JournalReadResult { events: RuntimeEvent[]; lastSeq: number; /** Total number of physical lines read (partial/corrupt lines counted). */ lineCount: number; } /** * Append a lifecycle event with monotonic seq persistence. * Marks the event committed, then caller writes snapshot. */ export declare function appendEvent(layout: TaskRuntimeLayout, event: Omit, opts?: { touch?: boolean; }): Promise; /** * Read and validate events.jsonl. * * - Empty/missing file → { events: [], lastSeq: 0 }. * - Trailing partial line WITHOUT newline terminator: if JSON.parse succeeds → keep; * if it fails or the line is mid-write garbage → RuntimeCorruptError (fail closed). * - seq must be strictly increasing integers starting at 1. */ export declare function readJournal(layout: TaskRuntimeLayout, opts?: { toleratePartial?: boolean; }): Promise; /** * Write the versioned runtime.json snapshot atomically. * runtime.json is an index derived from events + attempt dirs — NOT truth. */ export declare function writeSnapshot(layout: TaskRuntimeLayout, snapshot: RuntimeSnapshot): Promise; /** Read runtime.json; unknown/missing schema → fail closed. */ export declare function readSnapshot(layout: TaskRuntimeLayout): Promise;