import * as fs from "node:fs"; import * as path from "node:path"; export type Issue12ObserverEvent = | { kind: "worker_check_fired"; token: string } | { kind: "wake_sent"; messageId: string } | { kind: "assistant_provider"; messageId: string } | { kind: "agent_settled"; messageId: string } | { kind: "worker_check_rearmed"; token: string }; /** * Append one real-time observer fact. The proof observer calls this at the point it * sees the corresponding durable/session transition; the metrics extractor later * validates these facts against the archived wake records and raw parent session. */ export function appendIssue12ObserverEvent(file: string, event: Issue12ObserverEvent, now = Date.now()): void { fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 }); fs.appendFileSync(file, `${JSON.stringify({ ...event, observedAt: new Date(now).toISOString() })}\n`, { encoding: "utf8", mode: 0o600, }); }