open-multi-agent-kit 0.90.9 → 0.91.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/CHANGELOG.md +22 -3
  2. package/README.md +14 -1
  3. package/dist/core/agent-session.d.ts +27 -0
  4. package/dist/core/agent-session.d.ts.map +1 -1
  5. package/dist/core/agent-session.js +188 -25
  6. package/dist/core/agent-session.js.map +1 -1
  7. package/dist/core/command-safety.d.ts.map +1 -1
  8. package/dist/core/command-safety.js +0 -8
  9. package/dist/core/command-safety.js.map +1 -1
  10. package/dist/core/footer-data-provider.d.ts +7 -1
  11. package/dist/core/footer-data-provider.d.ts.map +1 -1
  12. package/dist/core/footer-data-provider.js +12 -0
  13. package/dist/core/footer-data-provider.js.map +1 -1
  14. package/dist/core/index.d.ts +1 -0
  15. package/dist/core/index.d.ts.map +1 -1
  16. package/dist/core/index.js +1 -0
  17. package/dist/core/index.js.map +1 -1
  18. package/dist/core/metrics-sampler.d.ts +20 -0
  19. package/dist/core/metrics-sampler.d.ts.map +1 -1
  20. package/dist/core/metrics-sampler.js +52 -0
  21. package/dist/core/metrics-sampler.js.map +1 -1
  22. package/dist/core/model-registry.d.ts.map +1 -1
  23. package/dist/core/model-registry.js +4 -1
  24. package/dist/core/model-registry.js.map +1 -1
  25. package/dist/core/model-resolver.d.ts.map +1 -1
  26. package/dist/core/model-resolver.js +15 -6
  27. package/dist/core/model-resolver.js.map +1 -1
  28. package/dist/core/provider-resilience.d.ts +51 -0
  29. package/dist/core/provider-resilience.d.ts.map +1 -0
  30. package/dist/core/provider-resilience.js +86 -0
  31. package/dist/core/provider-resilience.js.map +1 -0
  32. package/dist/core/run-journal.d.ts.map +1 -1
  33. package/dist/core/run-journal.js +14 -22
  34. package/dist/core/run-journal.js.map +1 -1
  35. package/dist/core/session-termination.d.ts +8 -2
  36. package/dist/core/session-termination.d.ts.map +1 -1
  37. package/dist/core/session-termination.js +45 -3
  38. package/dist/core/session-termination.js.map +1 -1
  39. package/dist/core/settings-manager.d.ts +30 -0
  40. package/dist/core/settings-manager.d.ts.map +1 -1
  41. package/dist/core/settings-manager.js +17 -0
  42. package/dist/core/settings-manager.js.map +1 -1
  43. package/dist/core/tools/grep.d.ts.map +1 -1
  44. package/dist/core/tools/grep.js +47 -0
  45. package/dist/core/tools/grep.js.map +1 -1
  46. package/dist/core/tools/omp-pure-seams.d.ts +41 -0
  47. package/dist/core/tools/omp-pure-seams.d.ts.map +1 -0
  48. package/dist/core/tools/omp-pure-seams.js +142 -0
  49. package/dist/core/tools/omp-pure-seams.js.map +1 -0
  50. package/dist/core/tools/omp-seam-runtime.d.ts +100 -0
  51. package/dist/core/tools/omp-seam-runtime.d.ts.map +1 -0
  52. package/dist/core/tools/omp-seam-runtime.js +40 -0
  53. package/dist/core/tools/omp-seam-runtime.js.map +1 -0
  54. package/dist/core/tools/read.d.ts.map +1 -1
  55. package/dist/core/tools/read.js +34 -1
  56. package/dist/core/tools/read.js.map +1 -1
  57. package/dist/modes/interactive/components/footer.d.ts +1 -1
  58. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  59. package/dist/modes/interactive/components/footer.js +11 -8
  60. package/dist/modes/interactive/components/footer.js.map +1 -1
  61. package/dist/modes/interactive/theme/omk-aurora-dark.json +80 -0
  62. package/dist/modes/interactive/theme/omk-aurora-light.json +80 -0
  63. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  64. package/dist/modes/interactive/theme/theme.js +5 -0
  65. package/dist/modes/interactive/theme/theme.js.map +1 -1
  66. package/docs/adaptorch-preview.md +1 -1
  67. package/docs/provider-resilience.md +87 -0
  68. package/docs/settings.md +30 -0
  69. package/docs/themes.md +2 -0
  70. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  71. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  72. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  73. package/examples/extensions/gondolin/package-lock.json +2 -2
  74. package/examples/extensions/gondolin/package.json +1 -1
  75. package/examples/extensions/sandbox/package-lock.json +2 -2
  76. package/examples/extensions/sandbox/package.json +1 -1
  77. package/examples/extensions/with-deps/package-lock.json +2 -2
  78. package/examples/extensions/with-deps/package.json +1 -1
  79. package/npm-shrinkwrap.json +22 -13
  80. package/package.json +6 -5
@@ -1 +1 @@
1
- {"version":3,"file":"run-journal.js","sourceRoot":"","sources":["../../src/core/run-journal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACN,mCAAmC,EACnC,kCAAkC,GAElC,MAAM,0BAA0B,CAAC;AAElC,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAU,CAAC;AACrD,+EAA+E;AAC/E,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAC3C,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,CAAC;AA4I7C,MAAM,MAAM,GAAG,gBAAgB,CAAC;AAChC,MAAM,YAAY,GAAG,IAAI,WAAW,EAAE,CAAC;AACvC,MAAM,YAAY,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAE/D,MAAM,kBAAkB,GAAiC,IAAI,GAAG,CAAkB;IACjF,aAAa;IACb,cAAc;IACd,eAAe;IACf,eAAe;IACf,cAAc;IACd,sBAAsB;IACtB,qBAAqB;CACrB,CAAC,CAAC;AACH,MAAM,eAAe,GAAiC,IAAI,GAAG,CAAkB;IAC9E,cAAc;IACd,eAAe;IACf,eAAe;CACf,CAAC,CAAC;AACH,MAAM,YAAY,GAAiC,IAAI,GAAG,CAAkB;IAC3E,cAAc;IACd,sBAAsB;IACtB,qBAAqB;CACrB,CAAC,CAAC;AACH,MAAM,iBAAiB,GAAG;IACzB,YAAY;IACZ,UAAU;IACV,aAAa;IACb,SAAS;IACT,WAAW;IACX,kBAAkB;IAClB,qBAAqB;IACrB,QAAQ;IACR,aAA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ector.\n *\n * Runtime purity: this module performs no I/O and uses no Node-specific\n * primitives. It relies only on `TextEncoder`/`TextDecoder`, `JSON`, the pure\n * `Date` string parser, and ordinary language built-ins. It consults no wall\n * clock, draws no entropy, invokes no cryptographic primitives, and mutates no\n * global state. Every record hash is recomputed from a caller-injected\n * synchronous `RunJournalHashFn`, both when records are constructed by\n * {@link RunJournal} and when raw bytes are inspected by\n * {@link inspectRunJournal}. There is no opaque mode that skips hashing.\n */\nimport {\n\tassertPreRedactedTerminationMessage,\n\tSESSION_TERMINATION_SCHEMA_VERSION,\n\ttype SessionTermination,\n} from \"./session-termination.ts\";\n\nexport const RUN_JOURNAL_SCHEMA_VERSION = 1 as const;\n/** Sixty-four zero bits; the `prevHash` of the first record in every chain. */\nexport const GENESIS_HASH = \"0\".repeat(64);\nexport const MAX_RUN_JOURNAL_ID_LENGTH = 128;\n\n/** Synchronous, pure hash function injected by the caller. Must return 64 lowercase hex chars. */\nexport type RunJournalHashFn = (bytes: Uint8Array) => string;\n\n/** Audit-only journal events; they never open, close, or otherwise affect a run. */\nexport type RunJournalAuditEvent = \"tool_timeout\" | \"tool_late_settlement\" | \"transcript_repaired\";\n\nexport type RunJournalEvent = \"run_started\" | \"run_finished\" | \"run_recovered\" | \"run_abandoned\" | RunJournalAuditEvent;\n\nexport type RunJournalFindingCode =\n\t| \"trailing_fragment\"\n\t| \"invalid_utf8\"\n\t| \"malformed_json\"\n\t| \"schema\"\n\t| \"seq_gap\"\n\t| \"seq_regression\"\n\t| \"hash_shape\"\n\t| \"hash_mismatch\"\n\t| \"hash_chain_break\"\n\t| \"orphan_terminal\"\n\t| \"duplicate_terminal\"\n\t| \"duplicate_start\"\n\t| \"interleaved_run\"\n\t| \"run_unclosed\"\n\t| \"recovered_source_invalid\"\n\t| \"termination_mismatch\"\n\t| \"session_mismatch\"\n\t| \"session_revision_regression\";\n\nexport interface RunJournalRecordBase {\n\treadonly schemaVersion: typeof RUN_JOURNAL_SCHEMA_VERSION;\n\treadonly seq: number;\n\treadonly event: RunJournalEvent;\n\treadonly runId: string;\n\treadonly sessionId: string;\n\treadonly sessionRevision: number;\n\t/** Canonical caller-supplied ISO-8601 UTC instant. */\n\treadonly timestamp: string;\n\t/** Hash of the previous record (`GENESIS_HASH` for the first record). */\n\treadonly prevHash: string;\n\t/** Recomputed hash of this record's canonical material (without `hash`). */\n\treadonly hash: string;\n}\n\nexport interface RunJournalStartedRecord extends RunJournalRecordBase {\n\treadonly event: \"run_started\";\n}\n\nexport interface RunJournalTerminalRecord extends RunJournalRecordBase {\n\treadonly event: \"run_finished\" | \"run_recovered\" | \"run_abandoned\";\n\treadonly termination: SessionTermination;\n}\n\n/** Bounded structured payload persisted with an audit record. */\nexport interface RunJournalAuditDetails {\n\treadonly toolCallId?: string;\n\treadonly toolName?: string;\n\treadonly disposition?: \"completed\" | \"failed\" | \"blocked\" | \"aborted\" | \"timeout\" | \"skipped\";\n\treadonly outcome?: \"resolved\" | \"rejected\";\n\treadonly timeoutMs?: number;\n\treadonly executionStarted?: boolean;\n\treadonly insertedToolCallIds?: readonly string[];\n\treadonly reason?: string;\n\treadonly sessionRisk?: \"elevated\";\n}\n\nexport interface RunJournalAuditRecord extends RunJournalRecordBase {\n\treadonly event: RunJournalAuditEvent;\n\treadonly details: RunJournalAuditDetails;\n}\n\nexport type RunJournalRecord = RunJournalStartedRecord | RunJournalTerminalRecord | RunJournalAuditRecord;\n\nexport interface RunJournalFinding {\n\treadonly code: RunJournalFindingCode;\n\treadonly line?: number;\n\treadonly runId?: string;\n}\n\nexport interface RunJournalCompletePrefix {\n\treadonly byteCount: number;\n\treadonly lineCount: number;\n}\n\nexport interface RunJournalReport {\n\treadonly ok: boolean;\n\treadonly completePrefix: RunJournalCompletePrefix;\n\treadonly trailingByteCount: number;\n\treadonly records: readonly RunJournalRecord[];\n\treadonly openRunId: string | null;\n\treadonly findings: readonly RunJournalFinding[];\n}\n\nexport interface RunJournalConstructorInit {\n\treadonly hashFn: RunJournalHashFn;\n\treadonly sessionId: string;\n\treadonly runId: string;\n\treadonly sessionRevision: number;\n\treadonly timestamp: string;\n\t/**\n\t * When `false`, the constructor does not append the initial `run_started`\n\t * record: the journal starts closed and accepts audit records (and later\n\t * explicit `start()` calls). Default `true` preserves existing behavior.\n\t */\n\treadonly openInitialRun?: boolean;\n\t/**\n\t * Trusted caller-supplied continuation chain-head `prevHash`. Defaults to\n\t * `GENESIS_HASH` for a new journal. The writer treats this as a trusted\n\t * baseline that pins the first record to an external chain; it is never\n\t * re-derived.\n\t */\n\treadonly prevHash?: string;\n\t/**\n\t * Trusted caller-supplied continuation chain-head `seq`. Defaults to `0` for\n\t * a new journal. Treated as a trusted baseline; the writer advances from it\n\t * but never re-derives it.\n\t */\n\treadonly seq?: number;\n}\n\nexport interface RunJournalStartInput {\n\treadonly runId: string;\n\treadonly sessionRevision: number;\n\treadonly timestamp: string;\n}\n\nexport interface RunJournalTerminalInput {\n\treadonly termination: SessionTermination;\n\treadonly sessionRevision: number;\n\treadonly timestamp: string;\n}\n\nexport interface RunJournalAuditInput {\n\treadonly event: RunJournalAuditEvent;\n\treadonly details: RunJournalAuditDetails;\n\treadonly sessionRevision: number;\n\treadonly timestamp: string;\n}\n\nconst HASH64 = /^[0-9a-f]{64}$/;\nconst TEXT_ENCODER = new TextEncoder();\nconst TEXT_DECODER = new TextDecoder(\"utf-8\", { fatal: true });\n\nconst RUN_JOURNAL_EVENTS: ReadonlySet<RunJournalEvent> = new Set<RunJournalEvent>([\n\t\"run_started\",\n\t\"run_finished\",\n\t\"run_recovered\",\n\t\"run_abandoned\",\n\t\"tool_timeout\",\n\t\"tool_late_settlement\",\n\t\"transcript_repaired\",\n]);\nconst TERMINAL_EVENTS: ReadonlySet<RunJournalEvent> = new Set<RunJournalEvent>([\n\t\"run_finished\",\n\t\"run_recovered\",\n\t\"run_abandoned\",\n]);\nconst AUDIT_EVENTS: ReadonlySet<RunJournalEvent> = new Set<RunJournalEvent>([\n\t\"tool_timeout\",\n\t\"tool_late_settlement\",\n\t\"transcript_repaired\",\n]);\nconst AUDIT_DETAIL_KEYS = [\n\t\"toolCallId\",\n\t\"toolName\",\n\t\"disposition\",\n\t\"outcome\",\n\t\"timeoutMs\",\n\t\"executionStarted\",\n\t\"insertedToolCallIds\",\n\t\"reason\",\n\t\"sessionRisk\",\n] as const;\nconst AUDIT_DISPOSITIONS: ReadonlySet<string> = new Set([\n\t\"completed\",\n\t\"failed\",\n\t\"blocked\",\n\t\"aborted\",\n\t\"timeout\",\n\t\"skipped\",\n]);\nconst AUDIT_OUTCOMES: ReadonlySet<string> = new Set([\"resolved\", \"rejected\"]);\nconst MAX_AUDIT_INSERTED_IDS = 64;\nconst MAX_AUDIT_REASON_LENGTH = 512;\nconst COMMON_RECORD_KEYS = [\n\t\"schemaVersion\",\n\t\"seq\",\n\t\"event\",\n\t\"runId\",\n\t\"sessionId\",\n\t\"sessionRevision\",\n\t\"timestamp\",\n\t\"prevHash\",\n\t\"hash\",\n] as const;\n\nconst SESSION_TERMINATION_KINDS: ReadonlySet<string> = new Set([\n\t\"completed\",\n\t\"user_abort\",\n\t\"provider_abort\",\n\t\"provider_auth\",\n\t\"provider_rate_limit\",\n\t\"provider_network\",\n\t\"provider_protocol\",\n\t\"context_overflow\",\n\t\"tool_timeout\",\n\t\"tool_fatal\",\n\t\"compaction\",\n\t\"persistence\",\n\t\"process_signal\",\n\t\"process_crash\",\n\t\"transcript_invalid\",\n\t\"configuration\",\n\t\"internal_error\",\n]);\nconst SESSION_TERMINATION_PHASES: ReadonlySet<string> = new Set([\n\t\"completed\",\n\t\"control\",\n\t\"preflight\",\n\t\"provider\",\n\t\"tool\",\n\t\"compaction\",\n\t\"persistence\",\n\t\"process\",\n\t\"resume\",\n]);\nconst SESSION_TERMINATION_SOURCES: ReadonlySet<string> = new Set([\"observed\", \"inferred_on_resume\"]);\nconst SESSION_SIDE_EFFECTS: ReadonlySet<string> = new Set([\"none\", \"possible\", \"confirmed\"]);\nconst SESSION_PROCESS_SIGNALS: ReadonlySet<string> = new Set([\"SIGINT\", \"SIGTERM\", \"SIGHUP\", \"SIGQUIT\"]);\nconst SESSION_TRANSCRIPT_ISSUES: ReadonlySet<string> = new Set([\n\t\"missing_result\",\n\t\"duplicate_result\",\n\t\"orphan_result\",\n\t\"duplicate_call_id\",\n\t\"interleaved_non_result\",\n\t\"invalid_jsonl\",\n\t\"invalid_tree\",\n\t\"unsupported_version\",\n\t\"trailing_fragment\",\n]);\nconst TERMINATION_ALLOWED_KEYS = [\n\t\"schemaVersion\",\n\t\"sessionId\",\n\t\"runId\",\n\t\"kind\",\n\t\"phase\",\n\t\"source\",\n\t\"message\",\n\t\"causeCode\",\n\t\"nextAction\",\n\t\"retryable\",\n\t\"safeToAutoRetry\",\n\t\"sideEffects\",\n\t\"timestamp\",\n\t\"retryAfterMs\",\n\t\"provider\",\n\t\"model\",\n\t\"toolCallId\",\n\t\"toolName\",\n\t\"processSignal\",\n\t\"transcriptIssue\",\n] as const;\n\n/** High-confidence credential shapes; rejected at every trust boundary. */\nconst CREDENTIAL_SHAPES = [\n\t/-----BEGIN [A-Z ]*PRIVATE KEY-----/i,\n\t/\\bsk-[A-Za-z0-9_-]{16,}\\b/,\n\t/\\bgh[pousr]_[A-Za-z0-9]{16,}\\b/,\n\t/\\bgithub_pat_[A-Za-z0-9_]{16,}\\b/,\n\t/\\bxox[baprs]-[A-Za-z0-9-]{16,}\\b/,\n\t/\\bAKIA[A-Z0-9]{16}\\b/,\n\t/\\beyJ[A-Za-z0-9_-]{8,}\\.[A-Za-z0-9_-]{8,}\\.[A-Za-z0-9_-]{8,}\\b/,\n\t/\\bBearer\\s+[A-Za-z0-9._~+/-]{8,}={0,2}\\b/i,\n\t/(?:^|[^A-Za-z0-9])(?:[A-Za-z0-9]+[_-])*(?:authorization|api[-_ ]?key|access[-_ ]?token|token|password|secret(?:[-_ ]?key)?|private[-_ ]?key|cookie)[\"']?\\s*[:=]/i,\n] as const;\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * Asserts `value` is a plain data record: an object (never an array) with a\n * plain prototype, only data (non-accessor) own properties, and no keys outside\n * `allowedKeys`. Descriptors are inspected without ever executing a getter, so\n * raw accessor execution is never exposed at the trust boundary. Returns void;\n * it narrows nothing so typed callers keep their static field types.\n */\nfunction assertPlainDataRecord(value: unknown, name: string, allowedKeys: readonly string[]): void {\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n\t\tthrow new TypeError(`${name} must be a plain object`);\n\t}\n\tconst prototype = Object.getPrototypeOf(value);\n\tif (prototype !== null && prototype !== Object.prototype) {\n\t\tthrow new TypeError(`${name} must be a plain object`);\n\t}\n\tconst descriptors = Object.getOwnPropertyDescriptors(value);\n\tfor (const key of Object.keys(descriptors)) {\n\t\tconst descriptor = descriptors[key];\n\t\tif (descriptor !== undefined && !(\"value\" in descriptor)) {\n\t\t\tthrow new TypeError(`${name} must not define accessor properties`);\n\t\t}\n\t\tif (!allowedKeys.includes(key)) {\n\t\t\tthrow new TypeError(`${name} must contain only bounded fields`);\n\t\t}\n\t}\n}\n\nfunction looksLikeCredential(value: string): boolean {\n\treturn CREDENTIAL_SHAPES.some((pattern) => pattern.test(value));\n}\n\nfunction isBoundedIdentifier(value: unknown): value is string {\n\treturn (\n\t\ttypeof value === \"string\" &&\n\t\tvalue.length > 0 &&\n\t\tvalue.length <= MAX_RUN_JOURNAL_ID_LENGTH &&\n\t\t!/[\\u0000-\\u001f\\u007f]/.test(value)\n\t);\n}\n\nfunction assertIdentifier(value: unknown, name: string, maxLength: number): asserts value is string {\n\tif (typeof value !== \"string\" || value.length === 0 || value.length > maxLength) {\n\t\tthrow new TypeError(`${name} must be 1-${maxLength} characters of bounded text`);\n\t}\n\tif (/[\\u0000-\\u001f\\u007f]/.test(value)) {\n\t\tthrow new TypeError(`${name} must not contain C0 or DEL control characters`);\n\t}\n}\n\nfunction rejectCredential(value: string, name: string): void {\n\tif (looksLikeCredential(value)) {\n\t\tthrow new TypeError(`${name} contains a credential-shaped literal`);\n\t}\n}\n\nfunction isCanonicalTimestamp(value: unknown): value is string {\n\tif (typeof value !== \"string\") return false;\n\tconst parsed = new Date(value);\n\treturn Number.isFinite(parsed.getTime()) && parsed.toISOString() === value;\n}\n\nfunction assertCanonicalTimestamp(value: unknown, name: string): asserts value is string {\n\tif (!isCanonicalTimestamp(value)) {\n\t\tthrow new TypeError(`${name} must be a canonical ISO-8601 UTC instant`);\n\t}\n}\n\nfunction assertSafeNonNegativeInt(value: unknown, name: string): asserts value is number {\n\tif (typeof value !== \"number\" || !Number.isSafeInteger(value) || value < 0) {\n\t\tthrow new TypeError(`${name} must be a non-negative safe integer`);\n\t}\n}\n\nfunction isValidHashShape(value: unknown): value is string {\n\treturn typeof value === \"string\" && HASH64.test(value);\n}\n\nfunction assertHashShape(value: unknown, name: string): asserts value is string {\n\tif (!isValidHashShape(value)) {\n\t\tthrow new TypeError(`${name} must be 64 lowercase hex characters`);\n\t}\n}\n\nfunction deepFreeze<T>(value: T): T {\n\tif (typeof value !== \"object\" || value === null || Object.isFrozen(value)) return value;\n\tfor (const child of Object.values(value as Record<string, unknown>)) deepFreeze(child);\n\treturn Object.freeze(value);\n}\n\n/** Recursively key-sorted JSON serialization. Deterministic across runtimes and key insertion order. */\nexport function canonicalJson(value: unknown): string {\n\tif (value === null) return \"null\";\n\tif (Array.isArray(value)) return `[${value.map(canonicalJson).join(\",\")}]`;\n\tif (typeof value === \"object\") {\n\t\tconst object = value as Record<string, unknown>;\n\t\tconst parts: string[] = [];\n\t\tfor (const key of Object.keys(object).sort()) {\n\t\t\tconst child = object[key];\n\t\t\tif (child === undefined) continue;\n\t\t\tparts.push(`${JSON.stringify(key)}:${canonicalJson(child)}`);\n\t\t}\n\t\treturn `{${parts.join(\",\")}}`;\n\t}\n\treturn JSON.stringify(value);\n}\n\n/** Defensively drop a stray `hash` key so the material never includes it, regardless of caller. */\nfunction stripHashKey(record: unknown): Record<string, unknown> {\n\tif (typeof record !== \"object\" || record === null) return {};\n\tconst clone: Record<string, unknown> = {};\n\tfor (const [key, value] of Object.entries(record)) {\n\t\tif (key !== \"hash\") clone[key] = value;\n\t}\n\treturn clone;\n}\n\n/** Canonical material of a record (everything except `hash`) over which the hash is computed. */\nexport function serializeRunJournalMaterial(record: Readonly<Omit<RunJournalRecord, \"hash\">>): string {\n\treturn canonicalJson(stripHashKey(record));\n}\n\n/** Canonical, key-sorted serialization of a full record (including `hash`). */\nexport function serializeRunJournalLine(record: Readonly<RunJournalRecord>): string {\n\treturn canonicalJson(record);\n}\n\nfunction assertBoundedSessionTermination(\n\tvalue: unknown,\n\texpectedRunId: string,\n\texpectedSessionId: string,\n): asserts value is SessionTermination {\n\tassertPlainDataRecord(value, \"termination\", TERMINATION_ALLOWED_KEYS);\n\tconst v = value as Record<string, unknown>;\n\tif (v.schemaVersion !== SESSION_TERMINATION_SCHEMA_VERSION) {\n\t\tthrow new TypeError(\"termination schemaVersion must match the supported version\");\n\t}\n\tif (typeof v.runId !== \"string\" || v.runId !== expectedRunId) {\n\t\tthrow new TypeError(\"termination runId must match the record runId\");\n\t}\n\tif (typeof v.sessionId !== \"string\" || v.sessionId !== expectedSessionId) {\n\t\tthrow new TypeError(\"termination sessionId must match the record sessionId\");\n\t}\n\tif (typeof v.kind !== \"string\" || !SESSION_TERMINATION_KINDS.has(v.kind)) {\n\t\tthrow new TypeError(\"termination kind is out of bounds\");\n\t}\n\tif (typeof v.phase !== \"string\" || !SESSION_TERMINATION_PHASES.has(v.phase)) {\n\t\tthrow new TypeError(\"termination phase is out of bounds\");\n\t}\n\tif (typeof v.source !== \"string\" || !SESSION_TERMINATION_SOURCES.has(v.source)) {\n\t\tthrow new TypeError(\"termination source is out of bounds\");\n\t}\n\tif (typeof v.message !== \"string\") {\n\t\tthrow new TypeError(\"termination message must be a string\");\n\t}\n\tassertPreRedactedTerminationMessage(v.message);\n\tif (typeof v.causeCode !== \"string\" || !/^[a-z_]+\\.[a-z_]+$/.test(v.causeCode)) {\n\t\tthrow new TypeError(\"termination causeCode is out of bounds\");\n\t}\n\tif (typeof v.nextAction !== \"string\") {\n\t\tthrow new TypeError(\"termination nextAction must be a string\");\n\t}\n\tassertPreRedactedTerminationMessage(v.nextAction);\n\tif (typeof v.retryable !== \"boolean\" || typeof v.safeToAutoRetry !== \"boolean\") {\n\t\tthrow new TypeError(\"termination retry flags must be booleans\");\n\t}\n\tif (typeof v.sideEffects !== \"string\" || !SESSION_SIDE_EFFECTS.has(v.sideEffects)) {\n\t\tthrow new TypeError(\"termination sideEffects is out of bounds\");\n\t}\n\tassertCanonicalTimestamp(v.timestamp, \"termination.timestamp\");\n\tif (v.retryAfterMs !== undefined) assertSafeNonNegativeInt(v.retryAfterMs, \"termination.retryAfterMs\");\n\tif (v.provider !== undefined) {\n\t\tassertIdentifier(v.provider, \"termination.provider\", 128);\n\t\trejectCredential(v.provider, \"termination.provider\");\n\t}\n\tif (v.model !== undefined) {\n\t\tassertIdentifier(v.model, \"termination.model\", 256);\n\t\trejectCredential(v.model, \"termination.model\");\n\t}\n\tif (v.toolCallId !== undefined) {\n\t\tassertIdentifier(v.toolCallId, \"termination.toolCallId\", 512);\n\t\trejectCredential(v.toolCallId, \"termination.toolCallId\");\n\t}\n\tif (v.toolName !== undefined) {\n\t\tassertIdentifier(v.toolName, \"termination.toolName\", 128);\n\t\trejectCredential(v.toolName, \"termination.toolName\");\n\t}\n\tif (v.processSignal !== undefined) {\n\t\tif (typeof v.processSignal !== \"string\" || !SESSION_PROCESS_SIGNALS.has(v.processSignal)) {\n\t\t\tthrow new TypeError(\"termination processSignal is out of bounds\");\n\t\t}\n\t}\n\tif (v.transcriptIssue !== undefined) {\n\t\tif (typeof v.transcriptIssue !== \"string\" || !SESSION_TRANSCRIPT_ISSUES.has(v.transcriptIssue)) {\n\t\t\tthrow new TypeError(\"termination transcriptIssue is out of bounds\");\n\t\t}\n\t}\n\tassertTerminationCoherence(v as unknown as SessionTermination);\n}\n\nfunction assertTerminationCoherence(termination: SessionTermination): void {\n\tconst dot = termination.causeCode.indexOf(\".\");\n\tconst area = dot >= 0 ? termination.causeCode.slice(0, dot) : \"\";\n\tconst suffix = dot >= 0 ? termination.causeCode.slice(dot + 1) : \"\";\n\n\tlet expectedKind: string;\n\tlet expectedPhase: string;\n\tlet expectedRetryable: boolean;\n\tlet processSignalRequired = false;\n\tlet transcriptRequired = false;\n\tlet transcriptSuffix: string | null = null;\n\n\tswitch (area) {\n\t\tcase \"session\":\n\t\t\tif (suffix === \"completed\") {\n\t\t\t\texpectedKind = \"completed\";\n\t\t\t\texpectedPhase = \"completed\";\n\t\t\t\texpectedRetryable = false;\n\t\t\t} else if (suffix === \"user_abort\") {\n\t\t\t\texpectedKind = \"user_abort\";\n\t\t\t\texpectedPhase = \"control\";\n\t\t\t\texpectedRetryable = false;\n\t\t\t} else {\n\t\t\t\tthrow new TypeError(\"termination causeCode is incoherent\");\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"provider\":\n\t\t\tswitch (suffix) {\n\t\t\t\tcase \"abort\":\n\t\t\t\t\texpectedKind = \"provider_abort\";\n\t\t\t\t\texpectedPhase = \"provider\";\n\t\t\t\t\texpectedRetryable = true;\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"auth\":\n\t\t\t\t\texpectedKind = \"provider_auth\";\n\t\t\t\t\texpectedPhase = \"provider\";\n\t\t\t\t\texpectedRetryable = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"rate_limit\":\n\t\t\t\t\texpectedKind = \"provider_rate_limit\";\n\t\t\t\t\texpectedPhase = \"provider\";\n\t\t\t\t\texpectedRetryable = true;\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"network\":\n\t\t\t\t\texpectedKind = \"provider_network\";\n\t\t\t\t\texpectedPhase = \"provider\";\n\t\t\t\t\texpectedRetryable = true;\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"protocol\":\n\t\t\t\t\texpectedKind = \"provider_protocol\";\n\t\t\t\t\texpectedPhase = \"provider\";\n\t\t\t\t\texpectedRetryable = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"context_overflow\":\n\t\t\t\t\texpectedKind = \"context_overflow\";\n\t\t\t\t\texpectedPhase = \"provider\";\n\t\t\t\t\texpectedRetryable = true;\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new TypeError(\"termination causeCode is incoherent\");\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"tool\":\n\t\t\tif (suffix === \"timeout\") {\n\t\t\t\texpectedKind = \"tool_timeout\";\n\t\t\t\texpectedPhase = \"tool\";\n\t\t\t\texpectedRetryable = true;\n\t\t\t} else if (suffix === \"fatal\") {\n\t\t\t\texpectedKind = \"tool_fatal\";\n\t\t\t\texpectedPhase = \"tool\";\n\t\t\t\texpectedRetryable = false;\n\t\t\t} else {\n\t\t\t\tthrow new TypeError(\"termination causeCode is incoherent\");\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"compaction\":\n\t\t\tif (suffix === \"aborted\" || suffix === \"failed\" || suffix === \"stale\") {\n\t\t\t\texpectedKind = \"compaction\";\n\t\t\t\texpectedPhase = \"compaction\";\n\t\t\t\texpectedRetryable = true;\n\t\t\t} else {\n\t\t\t\tthrow new TypeError(\"termination causeCode is incoherent\");\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"persistence\":\n\t\t\tif (\n\t\t\t\tsuffix === \"read_failed\" ||\n\t\t\t\tsuffix === \"append_failed\" ||\n\t\t\t\tsuffix === \"replace_failed\" ||\n\t\t\t\tsuffix === \"fsync_failed\" ||\n\t\t\t\tsuffix === \"lock_failed\"\n\t\t\t) {\n\t\t\t\texpectedKind = \"persistence\";\n\t\t\t\texpectedPhase = \"persistence\";\n\t\t\t\texpectedRetryable = true;\n\t\t\t} else {\n\t\t\t\tthrow new TypeError(\"termination causeCode is incoherent\");\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"process\":\n\t\t\tif (suffix === \"signal\") {\n\t\t\t\texpectedKind = \"process_signal\";\n\t\t\t\texpectedPhase = \"process\";\n\t\t\t\texpectedRetryable = false;\n\t\t\t\tprocessSignalRequired = true;\n\t\t\t} else if (suffix === \"crash\") {\n\t\t\t\texpectedKind = \"process_crash\";\n\t\t\t\texpectedPhase = \"resume\";\n\t\t\t\texpectedRetryable = true;\n\t\t\t} else {\n\t\t\t\tthrow new TypeError(\"termination causeCode is incoherent\");\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"transcript\":\n\t\t\tif (SESSION_TRANSCRIPT_ISSUES.has(suffix)) {\n\t\t\t\texpectedKind = \"transcript_invalid\";\n\t\t\t\texpectedPhase = termination.source === \"inferred_on_resume\" ? \"resume\" : \"preflight\";\n\t\t\t\texpectedRetryable = false;\n\t\t\t\ttranscriptRequired = true;\n\t\t\t\ttranscriptSuffix = suffix;\n\t\t\t} else {\n\t\t\t\tthrow new TypeError(\"termination causeCode is incoherent\");\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"configuration\":\n\t\t\tif (suffix === \"invalid\") {\n\t\t\t\texpectedKind = \"configuration\";\n\t\t\t\texpectedPhase = \"preflight\";\n\t\t\t\texpectedRetryable = false;\n\t\t\t} else {\n\t\t\t\tthrow new TypeError(\"termination causeCode is incoherent\");\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"internal\":\n\t\t\tif (suffix === \"unclassified\") {\n\t\t\t\texpectedKind = \"internal_error\";\n\t\t\t\texpectedPhase = \"preflight\";\n\t\t\t\texpectedRetryable = false;\n\t\t\t} else {\n\t\t\t\tthrow new TypeError(\"termination causeCode is incoherent\");\n\t\t\t}\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tthrow new TypeError(\"termination causeCode is incoherent\");\n\t}\n\n\tif (termination.kind !== expectedKind) {\n\t\tthrow new TypeError(\"termination kind is incoherent with causeCode\");\n\t}\n\tif (termination.phase !== expectedPhase) {\n\t\tthrow new TypeError(\"termination phase is incoherent with causeCode\");\n\t}\n\tif (termination.retryable !== expectedRetryable) {\n\t\tthrow new TypeError(\"termination retryable flag is incoherent with causeCode\");\n\t}\n\tif (processSignalRequired) {\n\t\tif (termination.processSignal === undefined) {\n\t\t\tthrow new TypeError(\"termination processSignal is required for signal causes\");\n\t\t}\n\t} else if (termination.processSignal !== undefined) {\n\t\tthrow new TypeError(\"termination processSignal is only valid for signal causes\");\n\t}\n\tif (transcriptRequired) {\n\t\tif (termination.transcriptIssue === undefined) {\n\t\t\tthrow new TypeError(\"termination transcriptIssue is required for transcript causes\");\n\t\t} else if (termination.transcriptIssue !== transcriptSuffix) {\n\t\t\tthrow new TypeError(\"termination transcriptIssue must match the transcript cause\");\n\t\t}\n\t} else if (termination.transcriptIssue !== undefined) {\n\t\tthrow new TypeError(\"termination transcriptIssue is only valid for transcript causes\");\n\t}\n\n\tconst expectedSafeToAutoRetry =\n\t\ttermination.retryable &&\n\t\ttermination.source === \"observed\" &&\n\t\ttermination.sideEffects === \"none\" &&\n\t\t(termination.kind === \"provider_rate_limit\" || termination.kind === \"provider_network\");\n\tif (termination.safeToAutoRetry !== expectedSafeToAutoRetry) {\n\t\tthrow new TypeError(\"termination safeToAutoRetry flag is incoherent\");\n\t}\n}\n\nfunction assertBoundedAuditDetails(value: unknown): asserts value is RunJournalAuditDetails {\n\tassertPlainDataRecord(value, \"audit details\", AUDIT_DETAIL_KEYS);\n\tconst v = value as Record<string, unknown>;\n\tif (v.toolCallId !== undefined) {\n\t\tassertIdentifier(v.toolCallId, \"details.toolCallId\", 512);\n\t\trejectCredential(v.toolCallId, \"details.toolCallId\");\n\t}\n\tif (v.toolName !== undefined) {\n\t\tassertIdentifier(v.toolName, \"details.toolName\", 128);\n\t\trejectCredential(v.toolName, \"details.toolName\");\n\t}\n\tif (v.disposition !== undefined && (typeof v.disposition !== \"string\" || !AUDIT_DISPOSITIONS.has(v.disposition))) {\n\t\tthrow new TypeError(\"details.disposition is out of bounds\");\n\t}\n\tif (v.outcome !== undefined && (typeof v.outcome !== \"string\" || !AUDIT_OUTCOMES.has(v.outcome))) {\n\t\tthrow new TypeError(\"details.outcome is out of bounds\");\n\t}\n\tif (v.timeoutMs !== undefined) {\n\t\tassertSafeNonNegativeInt(v.timeoutMs, \"details.timeoutMs\");\n\t}\n\tif (v.executionStarted !== undefined && typeof v.executionStarted !== \"boolean\") {\n\t\tthrow new TypeError(\"details.executionStarted must be a boolean\");\n\t}\n\tif (v.insertedToolCallIds !== undefined) {\n\t\tif (!Array.isArray(v.insertedToolCallIds) || v.insertedToolCallIds.length > MAX_AUDIT_INSERTED_IDS) {\n\t\t\tthrow new TypeError(\"details.insertedToolCallIds must be a bounded array\");\n\t\t}\n\t\tfor (const id of v.insertedToolCallIds) {\n\t\t\tassertIdentifier(id, \"details.insertedToolCallIds[]\", 512);\n\t\t\trejectCredential(id, \"details.insertedToolCallIds[]\");\n\t\t}\n\t}\n\tif (v.reason !== undefined) {\n\t\tassertIdentifier(v.reason, \"details.reason\", MAX_AUDIT_REASON_LENGTH);\n\t\trejectCredential(v.reason, \"details.reason\");\n\t}\n\tif (v.sessionRisk !== undefined && v.sessionRisk !== \"elevated\") {\n\t\tthrow new TypeError(\"details.sessionRisk is out of bounds\");\n\t}\n}\n\nfunction isTerminalCoherentWithEvent(\n\tevent: \"run_finished\" | \"run_recovered\" | \"run_abandoned\",\n\ttermination: SessionTermination,\n): boolean {\n\tif (event === \"run_recovered\") {\n\t\treturn (\n\t\t\ttermination.source === \"inferred_on_resume\" &&\n\t\t\ttermination.kind === \"process_crash\" &&\n\t\t\ttermination.phase === \"resume\"\n\t\t);\n\t}\n\tif (termination.source !== \"observed\") return false;\n\t// process_crash is only coherent with an inferred_on_resume (run_recovered) source.\n\tif (termination.kind === \"process_crash\") return false;\n\treturn true;\n}\n\nfunction assertTerminalCoherentWithEvent(\n\tevent: \"run_finished\" | \"run_recovered\" | \"run_abandoned\",\n\ttermination: SessionTermination,\n): void {\n\tif (isTerminalCoherentWithEvent(event, termination)) return;\n\tif (event === \"run_recovered\") {\n\t\tthrow new TypeError(\n\t\t\t\"run_recovered requires a coherent process_crash termination (source inferred_on_resume, phase resume)\",\n\t\t);\n\t}\n\tif (termination.kind === \"process_crash\") {\n\t\tthrow new TypeError(\"process_crash terminations may only appear on run_recovered events\");\n\t}\n\tthrow new TypeError(\"run_finished and run_abandoned require a termination source of observed\");\n}\n\n/**\n * Append-only run-journal writer. The constructor records the first\n * `run_started` event (and recomputes its hash); {@link RunJournal.start} opens\n * subsequent runs after a terminal event, while {@link RunJournal.finish},\n * {@link RunJournal.abandon}, and {@link RunJournal.recover} close the currently\n * open run. Exactly one run is open at a time.\n */\nexport class RunJournal {\n\tprivate readonly hashFn: RunJournalHashFn;\n\tprivate readonly sessionId: string;\n\tprivate readonly startedRunIds: Set<string> = new Set();\n\tprivate readonly terminatedRunIds: Set<string> = new Set();\n\tprivate readonly mutableRecords: RunJournalRecord[] = [];\n\tprivate recordsSnapshot: readonly RunJournalRecord[] = Object.freeze([]) as readonly RunJournalRecord[];\n\tprivate lastSessionRevision = 0;\n\tprivate prevHash: string;\n\tprivate nextSeq: number;\n\tprivate openRun: { readonly runId: string; readonly sessionId: string } | null = null;\n\n\tconstructor(init: RunJournalConstructorInit) {\n\t\tassertPlainDataRecord(init, \"RunJournalConstructorInit\", [\n\t\t\t\"hashFn\",\n\t\t\t\"sessionId\",\n\t\t\t\"runId\",\n\t\t\t\"sessionRevision\",\n\t\t\t\"timestamp\",\n\t\t\t\"prevHash\",\n\t\t\t\"seq\",\n\t\t\t\"openInitialRun\",\n\t\t]);\n\t\tif (init.openInitialRun !== undefined && typeof init.openInitialRun !== \"boolean\") {\n\t\t\tthrow new TypeError(\"openInitialRun must be a boolean\");\n\t\t}\n\t\tif (typeof init.hashFn !== \"function\") {\n\t\t\tthrow new TypeError(\"hashFn must be a function\");\n\t\t}\n\t\tthis.hashFn = init.hashFn;\n\t\tassertIdentifier(init.sessionId, \"sessionId\", MAX_RUN_JOURNAL_ID_LENGTH);\n\t\trejectCredential(init.sessionId, \"sessionId\");\n\t\tthis.sessionId = init.sessionId;\n\t\tconst startSeq = init.seq ?? 0;\n\t\tassertSafeNonNegativeInt(startSeq, \"seq\");\n\t\tconst startPrevHash = init.prevHash ?? GENESIS_HASH;\n\t\tassertHashShape(startPrevHash, \"prevHash\");\n\t\tthis.prevHash = startPrevHash;\n\t\tthis.nextSeq = startSeq;\n\t\tif (init.openInitialRun !== false) {\n\t\t\tthis.appendStarted({\n\t\t\t\trunId: init.runId,\n\t\t\t\tsessionRevision: init.sessionRevision,\n\t\t\t\ttimestamp: init.timestamp,\n\t\t\t});\n\t\t} else {\n\t\t\t// Audit-first journal: validate the seed runId shape, append nothing.\n\t\t\tassertIdentifier(init.runId, \"runId\", MAX_RUN_JOURNAL_ID_LENGTH);\n\t\t\trejectCredential(init.runId, \"runId\");\n\t\t}\n\t}\n\n\tstart(input: RunJournalStartInput): RunJournalStartedRecord {\n\t\treturn this.appendStarted(input);\n\t}\n\n\tfinish(input: RunJournalTerminalInput): RunJournalTerminalRecord {\n\t\treturn this.appendTerminal(\"run_finished\", input);\n\t}\n\n\tabandon(input: RunJournalTerminalInput): RunJournalTerminalRecord {\n\t\treturn this.appendTerminal(\"run_abandoned\", input);\n\t}\n\n\trecover(input: RunJournalTerminalInput): RunJournalTerminalRecord {\n\t\treturn this.appendTerminal(\"run_recovered\", input);\n\t}\n\n\t/**\n\t * Append an audit-only record. Allowed with or without an open run; never\n\t * opens, closes, or otherwise mutates run state. The record joins the same\n\t * seq/hash chain as lifecycle records.\n\t */\n\taudit(input: RunJournalAuditInput): RunJournalAuditRecord {\n\t\tassertPlainDataRecord(input, \"RunJournalAuditInput\", [\"event\", \"details\", \"sessionRevision\", \"timestamp\"]);\n\t\tif (typeof input.event !== \"string\" || !AUDIT_EVENTS.has(input.event as RunJournalEvent)) {\n\t\t\tthrow new TypeError(\"audit event is out of bounds\");\n\t\t}\n\t\tassertSafeNonNegativeInt(input.sessionRevision, \"sessionRevision\");\n\t\tif (input.sessionRevision < this.lastSessionRevision) {\n\t\t\tthrow new Error(\"sessionRevision must not regress across the journal\");\n\t\t}\n\t\tassertCanonicalTimestamp(input.timestamp, \"timestamp\");\n\t\tassertBoundedAuditDetails(input.details);\n\t\tconst base: Omit<RunJournalAuditRecord, \"hash\"> = {\n\t\t\tschemaVersion: RUN_JOURNAL_SCHEMA_VERSION,\n\t\t\tseq: this.nextSeq,\n\t\t\tevent: input.event as RunJournalAuditEvent,\n\t\t\trunId: this.openRun === null ? \"none\" : this.openRun.runId,\n\t\t\tsessionId: this.sessionId,\n\t\t\tsessionRevision: input.sessionRevision,\n\t\t\ttimestamp: input.timestamp,\n\t\t\tprevHash: this.prevHash,\n\t\t\tdetails: input.details,\n\t\t};\n\t\tconst record = this.seal(base);\n\t\tthis.mutableRecords.push(record);\n\t\tthis.prevHash = record.hash;\n\t\tthis.nextSeq += 1;\n\t\tthis.lastSessionRevision = input.sessionRevision;\n\t\tthis.refreshRecordsSnapshot();\n\t\treturn record;\n\t}\n\n\tget records(): readonly RunJournalRecord[] {\n\t\treturn this.recordsSnapshot;\n\t}\n\n\tget openRunId(): string | null {\n\t\treturn this.openRun === null ? null : this.openRun.runId;\n\t}\n\n\tserialize(): string {\n\t\tif (this.mutableRecords.length === 0) return \"\";\n\t\treturn `${this.mutableRecords.map((record) => serializeRunJournalLine(record)).join(\"\\n\")}\\n`;\n\t}\n\n\ttoBytes(): Uint8Array {\n\t\treturn TEXT_ENCODER.encode(this.serialize());\n\t}\n\n\tprivate refreshRecordsSnapshot(): void {\n\t\tthis.recordsSnapshot = Object.freeze([...this.mutableRecords]) as readonly RunJournalRecord[];\n\t}\n\n\tprivate appendStarted(input: RunJournalStartInput): RunJournalStartedRecord {\n\t\tassertPlainDataRecord(input, \"RunJournalStartInput\", [\"runId\", \"sessionRevision\", \"timestamp\"]);\n\t\tassertIdentifier(input.runId, \"runId\", MAX_RUN_JOURNAL_ID_LENGTH);\n\t\trejectCredential(input.runId, \"runId\");\n\t\tassertSafeNonNegativeInt(input.sessionRevision, \"sessionRevision\");\n\t\tif (input.sessionRevision < this.lastSessionRevision) {\n\t\t\tthrow new Error(\"sessionRevision must not regress across the journal\");\n\t\t}\n\t\tassertCanonicalTimestamp(input.timestamp, \"timestamp\");\n\t\tif (this.openRun !== null) {\n\t\t\tthrow new Error(\"a run is already open; terminate it before starting another\");\n\t\t}\n\t\tif (this.startedRunIds.has(input.runId)) {\n\t\t\tthrow new Error(\"runId was already started earlier in this journal\");\n\t\t}\n\t\tconst base: Omit<RunJournalStartedRecord, \"hash\"> = {\n\t\t\tschemaVersion: RUN_JOURNAL_SCHEMA_VERSION,\n\t\t\tseq: this.nextSeq,\n\t\t\tevent: \"run_started\",\n\t\t\trunId: input.runId,\n\t\t\tsessionId: this.sessionId,\n\t\t\tsessionRevision: input.sessionRevision,\n\t\t\ttimestamp: input.timestamp,\n\t\t\tprevHash: this.prevHash,\n\t\t};\n\t\tconst record = this.seal(base);\n\t\tthis.mutableRecords.push(record);\n\t\tthis.startedRunIds.add(input.runId);\n\t\tthis.openRun = Object.freeze({ runId: input.runId, sessionId: this.sessionId });\n\t\tthis.prevHash = record.hash;\n\t\tthis.nextSeq += 1;\n\t\tthis.lastSessionRevision = input.sessionRevision;\n\t\tthis.refreshRecordsSnapshot();\n\t\treturn record;\n\t}\n\n\tprivate appendTerminal(\n\t\tevent: \"run_finished\" | \"run_recovered\" | \"run_abandoned\",\n\t\tinput: RunJournalTerminalInput,\n\t): RunJournalTerminalRecord {\n\t\tassertPlainDataRecord(input, \"RunJournalTerminalInput\", [\"termination\", \"sessionRevision\", \"timestamp\"]);\n\t\tif (this.openRun === null) {\n\t\t\tthrow new Error(\"no run is open; start a run before terminating it\");\n\t\t}\n\t\tassertSafeNonNegativeInt(input.sessionRevision, \"sessionRevision\");\n\t\tif (input.sessionRevision < this.lastSessionRevision) {\n\t\t\tthrow new Error(\"sessionRevision must not regress across the journal\");\n\t\t}\n\t\tassertCanonicalTimestamp(input.timestamp, \"timestamp\");\n\t\tassertBoundedSessionTermination(input.termination, this.openRun.runId, this.sessionId);\n\t\tassertTerminalCoherentWithEvent(event, input.termination);\n\t\tif (input.timestamp !== input.termination.timestamp) {\n\t\t\tthrow new TypeError(\"terminal event timestamp must equal termination timestamp\");\n\t\t}\n\t\tif (this.terminatedRunIds.has(this.openRun.runId)) {\n\t\t\tthrow new Error(\"the open run was already terminated\");\n\t\t}\n\t\tconst base: Omit<RunJournalTerminalRecord, \"hash\"> = {\n\t\t\tschemaVersion: RUN_JOURNAL_SCHEMA_VERSION,\n\t\t\tseq: this.nextSeq,\n\t\t\tevent,\n\t\t\trunId: this.openRun.runId,\n\t\t\tsessionId: this.sessionId,\n\t\t\tsessionRevision: input.sessionRevision,\n\t\t\ttimestamp: input.timestamp,\n\t\t\tprevHash: this.prevHash,\n\t\t\ttermination: input.termination,\n\t\t};\n\t\tconst record = this.seal(base);\n\t\tthis.mutableRecords.push(record);\n\t\tthis.terminatedRunIds.add(this.openRun.runId);\n\t\tthis.openRun = null;\n\t\tthis.prevHash = record.hash;\n\t\tthis.nextSeq += 1;\n\t\tthis.lastSessionRevision = input.sessionRevision;\n\t\tthis.refreshRecordsSnapshot();\n\t\treturn record;\n\t}\n\n\tprivate seal<T extends Omit<RunJournalRecord, \"hash\">>(base: T): T & { readonly hash: string } {\n\t\tconst material = serializeRunJournalMaterial(base);\n\t\tlet hash: string;\n\t\ttry {\n\t\t\thash = this.hashFn(TEXT_ENCODER.encode(material));\n\t\t} catch (error) {\n\t\t\tthrow new TypeError(\"hashFn threw while sealing a record; failing closed\", { cause: error });\n\t\t}\n\t\tif (!isValidHashShape(hash)) {\n\t\t\tthrow new TypeError(\"hashFn must return 64 lowercase hex characters\");\n\t\t}\n\t\treturn deepFreeze({ ...base, hash }) as T & { readonly hash: string };\n\t}\n}\n\ninterface CommonShape {\n\treadonly schemaVersion: 1;\n\treadonly seq: number;\n\treadonly event: RunJournalEvent;\n\treadonly runId: string;\n\treadonly sessionId: string;\n\treadonly sessionRevision: number;\n\treadonly timestamp: string;\n\treadonly prevHash: string;\n\treadonly hash: string;\n}\n\nfunction validateCommonShape(value: unknown): CommonShape | null {\n\tif (!isPlainObject(value)) return null;\n\tconst rawEvent = (value as { event?: unknown }).event;\n\tconst isTerminal = typeof rawEvent === \"string\" && TERMINAL_EVENTS.has(rawEvent as RunJournalEvent);\n\tconst isAudit = typeof rawEvent === \"string\" && AUDIT_EVENTS.has(rawEvent as RunJournalEvent);\n\tconst allowed: readonly string[] = isTerminal\n\t\t? [...COMMON_RECORD_KEYS, \"termination\"]\n\t\t: isAudit\n\t\t\t? [...COMMON_RECORD_KEYS, \"details\"]\n\t\t\t: COMMON_RECORD_KEYS;\n\tif (Object.keys(value).some((key) => !allowed.includes(key))) {\n\t\treturn null;\n\t}\n\tconst hasTermination = \"termination\" in value;\n\tif (isTerminal !== hasTermination) return null;\n\tif (isAudit !== \"details\" in value) return null;\n\tif (value.schemaVersion !== RUN_JOURNAL_SCHEMA_VERSION) return null;\n\tif (typeof value.event !== \"string\" || !RUN_JOURNAL_EVENTS.has(value.event as RunJournalEvent)) return null;\n\tif (typeof value.seq !== \"number\" || !Number.isSafeInteger(value.seq) || value.seq < 0) return null;\n\tif (!isBoundedIdentifier(value.runId) || looksLikeCredential(value.runId)) return null;\n\tif (!isBoundedIdentifier(value.sessionId) || looksLikeCredential(value.sessionId)) return null;\n\tif (\n\t\ttypeof value.sessionRevision !== \"number\" ||\n\t\t!Number.isSafeInteger(value.sessionRevision) ||\n\t\tvalue.sessionRevision < 0\n\t) {\n\t\treturn null;\n\t}\n\tif (!isCanonicalTimestamp(value.timestamp)) return null;\n\tif (typeof value.prevHash !== \"string\" || typeof value.hash !== \"string\") return null;\n\treturn {\n\t\tschemaVersion: RUN_JOURNAL_SCHEMA_VERSION,\n\t\tseq: value.seq,\n\t\tevent: value.event as RunJournalEvent,\n\t\trunId: value.runId,\n\t\tsessionId: value.sessionId,\n\t\tsessionRevision: value.sessionRevision,\n\t\ttimestamp: value.timestamp,\n\t\tprevHash: value.prevHash,\n\t\thash: value.hash,\n\t};\n}\n\ntype TerminationProbe =\n\t| { readonly kind: \"ok\"; readonly termination: SessionTermination }\n\t| { readonly kind: \"mismatch\" }\n\t| {\n\t\t\treadonly kind: \"source\";\n\t };\n\nfunction probeTermination(\n\trawTermination: unknown,\n\trunId: string,\n\tsessionId: string,\n\tevent: RunJournalEvent,\n): TerminationProbe {\n\tlet termination: SessionTermination;\n\ttry {\n\t\tassertBoundedSessionTermination(rawTermination, runId, sessionId);\n\t\ttermination = rawTermination as SessionTermination;\n\t} catch {\n\t\treturn { kind: \"mismatch\" };\n\t}\n\tif (!isTerminalCoherentWithEvent(event as RunJournalTerminalRecord[\"event\"], termination)) {\n\t\treturn { kind: \"source\" };\n\t}\n\treturn { kind: \"ok\", termination };\n}\n\nfunction addFinding(findings: RunJournalFinding[], finding: RunJournalFinding): void {\n\tfindings.push(Object.freeze({ ...finding }));\n}\n\n/**\n * Inspect the complete-line prefix of a run-journal byte sequence without\n * mutating or repairing it. Only bytes through the final newline are parsed;\n * trailing bytes are reported as a fragment and never parsed. Every hash is\n * recomputed with the injected `hashFn`. The returned report is deeply frozen.\n */\nexport function inspectRunJournal(bytes: Uint8Array, hashFn: RunJournalHashFn): RunJournalReport {\n\tconst findings: RunJournalFinding[] = [];\n\n\tlet lastNewline = -1;\n\tfor (let index = bytes.byteLength - 1; index >= 0; index -= 1) {\n\t\tif (bytes[index] === 0x0a) {\n\t\t\tlastNewline = index;\n\t\t\tbreak;\n\t\t}\n\t}\n\tconst completeByteCount = lastNewline + 1;\n\tconst trailingByteCount = bytes.byteLength - completeByteCount;\n\tif (trailingByteCount > 0) addFinding(findings, { code: \"trailing_fragment\" });\n\n\tconst completeBytes = bytes.subarray(0, completeByteCount);\n\tlet lineCount = 0;\n\tconst parsedLines: { readonly line: number; readonly value: unknown }[] = [];\n\tif (completeByteCount > 0) {\n\t\tlet text: string | undefined;\n\t\ttry {\n\t\t\ttext = TEXT_DECODER.decode(completeBytes);\n\t\t} catch {\n\t\t\taddFinding(findings, { code: \"invalid_utf8\" });\n\t\t}\n\t\tif (text !== undefined) {\n\t\t\tconst body = text.slice(0, -1);\n\t\t\tconst lines = body.length === 0 ? [] : body.split(\"\\n\");\n\t\t\tlineCount = lines.length;\n\t\t\tfor (let index = 0; index < lines.length; index += 1) {\n\t\t\t\tconst lineNumber = index + 1;\n\t\t\t\tconst line = lines[index];\n\t\t\t\tif (line.trim().length === 0) {\n\t\t\t\t\taddFinding(findings, { code: \"malformed_json\", line: lineNumber });\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tparsedLines.push({ line: lineNumber, value: JSON.parse(line) });\n\t\t\t\t} catch {\n\t\t\t\t\taddFinding(findings, { code: \"malformed_json\", line: lineNumber });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tlet openRun: { runId: string; sessionId: string } | null = null;\n\tconst seenStarts = new Set<string>();\n\tconst terminatedRuns = new Set<string>();\n\tlet expectedSeq = 0;\n\tlet lastHash = GENESIS_HASH;\n\tlet journalSessionId: string | null = null;\n\tlet lastRevision = 0;\n\tconst validRecords: RunJournalRecord[] = [];\n\n\tfor (const { line, value } of parsedLines) {\n\t\tconst common = validateCommonShape(value);\n\t\tif (common === null) {\n\t\t\taddFinding(findings, { code: \"schema\", line });\n\t\t\tcontinue;\n\t\t}\n\t\tlet auditDetails: RunJournalAuditDetails | null = null;\n\t\tif (AUDIT_EVENTS.has(common.event)) {\n\t\t\ttry {\n\t\t\t\tassertBoundedAuditDetails((value as Record<string, unknown>).details);\n\t\t\t\tauditDetails = (value as { details: RunJournalAuditDetails }).details;\n\t\t\t} catch {\n\t\t\t\taddFinding(findings, { code: \"schema\", line });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tlet termination: SessionTermination | null = null;\n\t\tif (TERMINAL_EVENTS.has(common.event)) {\n\t\t\tconst probe = probeTermination(\n\t\t\t\t(value as Record<string, unknown>).termination,\n\t\t\t\tcommon.runId,\n\t\t\t\tcommon.sessionId,\n\t\t\t\tcommon.event,\n\t\t\t);\n\t\t\tif (probe.kind === \"mismatch\") {\n\t\t\t\taddFinding(findings, { code: \"termination_mismatch\", line, runId: common.runId });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (probe.kind === \"source\") {\n\t\t\t\taddFinding(findings, { code: \"recovered_source_invalid\", line, runId: common.runId });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttermination = probe.termination;\n\t\t\tif (common.timestamp !== termination.timestamp) {\n\t\t\t\taddFinding(findings, { code: \"termination_mismatch\", line, runId: common.runId });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tif (journalSessionId === null) {\n\t\t\tjournalSessionId = common.sessionId;\n\t\t} else if (common.sessionId !== journalSessionId) {\n\t\t\taddFinding(findings, { code: \"session_mismatch\", line, runId: common.runId });\n\t\t\tcontinue;\n\t\t}\n\t\tif (common.sessionRevision < lastRevision) {\n\t\t\taddFinding(findings, { code: \"session_revision_regression\", line, runId: common.runId });\n\t\t\tcontinue;\n\t\t}\n\t\tlastRevision = common.sessionRevision;\n\n\t\tconst baseRecord = {\n\t\t\tschemaVersion: RUN_JOURNAL_SCHEMA_VERSION,\n\t\t\tseq: common.seq,\n\t\t\tevent: common.event,\n\t\t\trunId: common.runId,\n\t\t\tsessionId: common.sessionId,\n\t\t\tsessionRevision: common.sessionRevision,\n\t\t\ttimestamp: common.timestamp,\n\t\t\tprevHash: common.prevHash,\n\t\t};\n\t\tconst recordWithoutHash = (\n\t\t\ttermination !== null\n\t\t\t\t? { ...baseRecord, termination }\n\t\t\t\t: auditDetails !== null\n\t\t\t\t\t? { ...baseRecord, details: auditDetails }\n\t\t\t\t\t: baseRecord\n\t\t) as Omit<RunJournalRecord, \"hash\">;\n\n\t\tif (common.seq > expectedSeq) addFinding(findings, { code: \"seq_gap\", line });\n\t\telse if (common.seq < expectedSeq) addFinding(findings, { code: \"seq_regression\", line });\n\t\texpectedSeq = common.seq + 1;\n\n\t\tconst hashShapeOk = isValidHashShape(common.hash);\n\t\tconst prevHashShapeOk = isValidHashShape(common.prevHash);\n\t\tif (!hashShapeOk || !prevHashShapeOk) addFinding(findings, { code: \"hash_shape\", line });\n\n\t\tconst material = serializeRunJournalMaterial(recordWithoutHash);\n\t\tlet recomputeOk = false;\n\t\ttry {\n\t\t\tconst recomputed = hashFn(TEXT_ENCODER.encode(material));\n\t\t\trecomputeOk = isValidHashShape(recomputed) && recomputed === common.hash;\n\t\t} catch {\n\t\t\trecomputeOk = false;\n\t\t}\n\t\tif (!recomputeOk) addFinding(findings, { code: \"hash_mismatch\", line });\n\n\t\tif (common.prevHash !== lastHash) addFinding(findings, { code: \"hash_chain_break\", line });\n\t\tif (hashShapeOk) lastHash = common.hash;\n\n\t\tif (AUDIT_EVENTS.has(common.event)) {\n\t\t\t// Audit records never affect the run-state machine.\n\t\t} else if (common.event === \"run_started\") {\n\t\t\tif (seenStarts.has(common.runId)) addFinding(findings, { code: \"duplicate_start\", line, runId: common.runId });\n\t\t\tif (openRun !== null && openRun.runId !== common.runId) {\n\t\t\t\taddFinding(findings, { code: \"interleaved_run\", line, runId: common.runId });\n\t\t\t} else if (openRun === null) {\n\t\t\t\topenRun = { runId: common.runId, sessionId: common.sessionId };\n\t\t\t}\n\t\t\tseenStarts.add(common.runId);\n\t\t} else {\n\t\t\tif (terminatedRuns.has(common.runId)) {\n\t\t\t\taddFinding(findings, { code: \"duplicate_terminal\", line, runId: common.runId });\n\t\t\t} else if (openRun === null || openRun.runId !== common.runId) {\n\t\t\t\taddFinding(findings, { code: \"orphan_terminal\", line, runId: common.runId });\n\t\t\t} else {\n\t\t\t\tterminatedRuns.add(common.runId);\n\t\t\t\topenRun = null;\n\t\t\t}\n\t\t}\n\n\t\tconst record = { ...recordWithoutHash, hash: common.hash } as RunJournalRecord;\n\t\tvalidRecords.push(deepFreeze(record) as RunJournalRecord);\n\t}\n\n\tif (openRun !== null) addFinding(findings, { code: \"run_unclosed\", runId: openRun.runId });\n\n\treturn deepFreeze({\n\t\tok: findings.length === 0,\n\t\tcompletePrefix: Object.freeze({ byteCount: completeByteCount, lineCount }),\n\t\ttrailingByteCount,\n\t\trecords: Object.freeze(validRecords) as readonly RunJournalRecord[],\n\t\topenRunId: openRun === null ? null : openRun.runId,\n\t\tfindings: Object.freeze(findings) as readonly RunJournalFinding[],\n\t}) as RunJournalReport;\n}\n"]}
1
+ {"version":3,"file":"run-journal.js","sourceRoot":"","sources":["../../src/core/run-journal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACN,mCAAmC,EACnC,+BAA+B,EAC/B,kCAAkC,GAElC,MAAM,0BAA0B,CAAC;AAElC,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAU,CAAC;AACrD,+EAA+E;AAC/E,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAC3C,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,CAAC;AA4I7C,MAAM,MAAM,GAAG,gBAAgB,CAAC;AAChC,MAAM,YAAY,GAAG,IAAI,WAAW,EAAE,CAAC;AACvC,MAAM,YAAY,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAE/D,MAAM,kBAAkB,GAAiC,IAAI,GAAG,CAAkB;IACjF,aAAa;IACb,cAAc;IACd,eAAe;IACf,eAAe;IACf,cAAc;IACd,sBAAsB;IACtB,qBAAqB;CACrB,CAAC,CAAC;AACH,MAAM,eAAe,GAAiC,IAAI,GAAG,CAAkB;IAC9E,cAAc;IACd,eAAe;IACf,eAAe;CACf,CAAC,CAAC;AACH,MAAM,YAAY,GAAiC,IAAI,GAAG,CAAkB;IAC3E,cAAc;IACd,sBAAsB;IACtB,qBAAqB;CACrB,CAAC,CAAC;AACH,MAAM,iBAAiB,GAAG;IACzB,YAAY;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,QAAQ,CAAiC;KACjE,CAAqB,CAAC;AAAA,CACvB","sourcesContent":["/**\n * Pure, browser-safe run-journal format and complete-prefix integrity inspector.\n *\n * Runtime purity: this module performs no I/O and uses no Node-specific\n * primitives. It relies only on `TextEncoder`/`TextDecoder`, `JSON`, the pure\n * `Date` string parser, and ordinary language built-ins. It consults no wall\n * clock, draws no entropy, invokes no cryptographic primitives, and mutates no\n * global state. Every record hash is recomputed from a caller-injected\n * synchronous `RunJournalHashFn`, both when records are constructed by\n * {@link RunJournal} and when raw bytes are inspected by\n * {@link inspectRunJournal}. There is no opaque mode that skips hashing.\n */\nimport {\n\tassertPreRedactedTerminationMessage,\n\tSESSION_TERMINATION_KIND_VALUES,\n\tSESSION_TERMINATION_SCHEMA_VERSION,\n\ttype SessionTermination,\n} from \"./session-termination.ts\";\n\nexport const RUN_JOURNAL_SCHEMA_VERSION = 1 as const;\n/** Sixty-four zero bits; the `prevHash` of the first record in every chain. */\nexport const GENESIS_HASH = \"0\".repeat(64);\nexport const MAX_RUN_JOURNAL_ID_LENGTH = 128;\n\n/** Synchronous, pure hash function injected by the caller. Must return 64 lowercase hex chars. */\nexport type RunJournalHashFn = (bytes: Uint8Array) => string;\n\n/** Audit-only journal events; they never open, close, or otherwise affect a run. */\nexport type RunJournalAuditEvent = \"tool_timeout\" | \"tool_late_settlement\" | \"transcript_repaired\";\n\nexport type RunJournalEvent = \"run_started\" | \"run_finished\" | \"run_recovered\" | \"run_abandoned\" | RunJournalAuditEvent;\n\nexport type RunJournalFindingCode =\n\t| \"trailing_fragment\"\n\t| \"invalid_utf8\"\n\t| \"malformed_json\"\n\t| \"schema\"\n\t| \"seq_gap\"\n\t| \"seq_regression\"\n\t| \"hash_shape\"\n\t| \"hash_mismatch\"\n\t| \"hash_chain_break\"\n\t| \"orphan_terminal\"\n\t| \"duplicate_terminal\"\n\t| \"duplicate_start\"\n\t| \"interleaved_run\"\n\t| \"run_unclosed\"\n\t| \"recovered_source_invalid\"\n\t| \"termination_mismatch\"\n\t| \"session_mismatch\"\n\t| \"session_revision_regression\";\n\nexport interface RunJournalRecordBase {\n\treadonly schemaVersion: typeof RUN_JOURNAL_SCHEMA_VERSION;\n\treadonly seq: number;\n\treadonly event: RunJournalEvent;\n\treadonly runId: string;\n\treadonly sessionId: string;\n\treadonly sessionRevision: number;\n\t/** Canonical caller-supplied ISO-8601 UTC instant. */\n\treadonly timestamp: string;\n\t/** Hash of the previous record (`GENESIS_HASH` for the first record). */\n\treadonly prevHash: string;\n\t/** Recomputed hash of this record's canonical material (without `hash`). */\n\treadonly hash: string;\n}\n\nexport interface RunJournalStartedRecord extends RunJournalRecordBase {\n\treadonly event: \"run_started\";\n}\n\nexport interface RunJournalTerminalRecord extends RunJournalRecordBase {\n\treadonly event: \"run_finished\" | \"run_recovered\" | \"run_abandoned\";\n\treadonly termination: SessionTermination;\n}\n\n/** Bounded structured payload persisted with an audit record. */\nexport interface RunJournalAuditDetails {\n\treadonly toolCallId?: string;\n\treadonly toolName?: string;\n\treadonly disposition?: \"completed\" | \"failed\" | \"blocked\" | \"aborted\" | \"timeout\" | \"skipped\";\n\treadonly outcome?: \"resolved\" | \"rejected\";\n\treadonly timeoutMs?: number;\n\treadonly executionStarted?: boolean;\n\treadonly insertedToolCallIds?: readonly string[];\n\treadonly reason?: string;\n\treadonly sessionRisk?: \"elevated\";\n}\n\nexport interface RunJournalAuditRecord extends RunJournalRecordBase {\n\treadonly event: RunJournalAuditEvent;\n\treadonly details: RunJournalAuditDetails;\n}\n\nexport type RunJournalRecord = RunJournalStartedRecord | RunJournalTerminalRecord | RunJournalAuditRecord;\n\nexport interface RunJournalFinding {\n\treadonly code: RunJournalFindingCode;\n\treadonly line?: number;\n\treadonly runId?: string;\n}\n\nexport interface RunJournalCompletePrefix {\n\treadonly byteCount: number;\n\treadonly lineCount: number;\n}\n\nexport interface RunJournalReport {\n\treadonly ok: boolean;\n\treadonly completePrefix: RunJournalCompletePrefix;\n\treadonly trailingByteCount: number;\n\treadonly records: readonly RunJournalRecord[];\n\treadonly openRunId: string | null;\n\treadonly findings: readonly RunJournalFinding[];\n}\n\nexport interface RunJournalConstructorInit {\n\treadonly hashFn: RunJournalHashFn;\n\treadonly sessionId: string;\n\treadonly runId: string;\n\treadonly sessionRevision: number;\n\treadonly timestamp: string;\n\t/**\n\t * When `false`, the constructor does not append the initial `run_started`\n\t * record: the journal starts closed and accepts audit records (and later\n\t * explicit `start()` calls). Default `true` preserves existing behavior.\n\t */\n\treadonly openInitialRun?: boolean;\n\t/**\n\t * Trusted caller-supplied continuation chain-head `prevHash`. Defaults to\n\t * `GENESIS_HASH` for a new journal. The writer treats this as a trusted\n\t * baseline that pins the first record to an external chain; it is never\n\t * re-derived.\n\t */\n\treadonly prevHash?: string;\n\t/**\n\t * Trusted caller-supplied continuation chain-head `seq`. Defaults to `0` for\n\t * a new journal. Treated as a trusted baseline; the writer advances from it\n\t * but never re-derives it.\n\t */\n\treadonly seq?: number;\n}\n\nexport interface RunJournalStartInput {\n\treadonly runId: string;\n\treadonly sessionRevision: number;\n\treadonly timestamp: string;\n}\n\nexport interface RunJournalTerminalInput {\n\treadonly termination: SessionTermination;\n\treadonly sessionRevision: number;\n\treadonly timestamp: string;\n}\n\nexport interface RunJournalAuditInput {\n\treadonly event: RunJournalAuditEvent;\n\treadonly details: RunJournalAuditDetails;\n\treadonly sessionRevision: number;\n\treadonly timestamp: string;\n}\n\nconst HASH64 = /^[0-9a-f]{64}$/;\nconst TEXT_ENCODER = new TextEncoder();\nconst TEXT_DECODER = new TextDecoder(\"utf-8\", { fatal: true });\n\nconst RUN_JOURNAL_EVENTS: ReadonlySet<RunJournalEvent> = new Set<RunJournalEvent>([\n\t\"run_started\",\n\t\"run_finished\",\n\t\"run_recovered\",\n\t\"run_abandoned\",\n\t\"tool_timeout\",\n\t\"tool_late_settlement\",\n\t\"transcript_repaired\",\n]);\nconst TERMINAL_EVENTS: ReadonlySet<RunJournalEvent> = new Set<RunJournalEvent>([\n\t\"run_finished\",\n\t\"run_recovered\",\n\t\"run_abandoned\",\n]);\nconst AUDIT_EVENTS: ReadonlySet<RunJournalEvent> = new Set<RunJournalEvent>([\n\t\"tool_timeout\",\n\t\"tool_late_settlement\",\n\t\"transcript_repaired\",\n]);\nconst AUDIT_DETAIL_KEYS = [\n\t\"toolCallId\",\n\t\"toolName\",\n\t\"disposition\",\n\t\"outcome\",\n\t\"timeoutMs\",\n\t\"executionStarted\",\n\t\"insertedToolCallIds\",\n\t\"reason\",\n\t\"sessionRisk\",\n] as const;\nconst AUDIT_DISPOSITIONS: ReadonlySet<string> = new Set([\n\t\"completed\",\n\t\"failed\",\n\t\"blocked\",\n\t\"aborted\",\n\t\"timeout\",\n\t\"skipped\",\n]);\nconst AUDIT_OUTCOMES: ReadonlySet<string> = new Set([\"resolved\", \"rejected\"]);\nconst MAX_AUDIT_INSERTED_IDS = 64;\nconst MAX_AUDIT_REASON_LENGTH = 512;\nconst COMMON_RECORD_KEYS = [\n\t\"schemaVersion\",\n\t\"seq\",\n\t\"event\",\n\t\"runId\",\n\t\"sessionId\",\n\t\"sessionRevision\",\n\t\"timestamp\",\n\t\"prevHash\",\n\t\"hash\",\n] as const;\n\nconst SESSION_TERMINATION_KINDS: ReadonlySet<string> = new Set(SESSION_TERMINATION_KIND_VALUES);\nconst SESSION_TERMINATION_PHASES: ReadonlySet<string> = new Set([\n\t\"completed\",\n\t\"control\",\n\t\"preflight\",\n\t\"provider\",\n\t\"tool\",\n\t\"compaction\",\n\t\"persistence\",\n\t\"process\",\n\t\"resume\",\n]);\nconst SESSION_TERMINATION_SOURCES: ReadonlySet<string> = new Set([\"observed\", \"inferred_on_resume\"]);\nconst SESSION_SIDE_EFFECTS: ReadonlySet<string> = new Set([\"none\", \"possible\", \"confirmed\"]);\nconst SESSION_PROCESS_SIGNALS: ReadonlySet<string> = new Set([\"SIGINT\", \"SIGTERM\", \"SIGHUP\", \"SIGQUIT\"]);\nconst SESSION_TRANSCRIPT_ISSUES: ReadonlySet<string> = new Set([\n\t\"missing_result\",\n\t\"duplicate_result\",\n\t\"orphan_result\",\n\t\"duplicate_call_id\",\n\t\"interleaved_non_result\",\n\t\"invalid_jsonl\",\n\t\"invalid_tree\",\n\t\"unsupported_version\",\n\t\"trailing_fragment\",\n]);\nconst TERMINATION_ALLOWED_KEYS = [\n\t\"schemaVersion\",\n\t\"sessionId\",\n\t\"runId\",\n\t\"kind\",\n\t\"phase\",\n\t\"source\",\n\t\"message\",\n\t\"causeCode\",\n\t\"nextAction\",\n\t\"retryable\",\n\t\"safeToAutoRetry\",\n\t\"sideEffects\",\n\t\"timestamp\",\n\t\"retryAfterMs\",\n\t\"provider\",\n\t\"model\",\n\t\"toolCallId\",\n\t\"toolName\",\n\t\"processSignal\",\n\t\"transcriptIssue\",\n] as const;\n\n/** High-confidence credential shapes; rejected at every trust boundary. */\nconst CREDENTIAL_SHAPES = [\n\t/-----BEGIN [A-Z ]*PRIVATE KEY-----/i,\n\t/\\bsk-[A-Za-z0-9_-]{16,}\\b/,\n\t/\\bgh[pousr]_[A-Za-z0-9]{16,}\\b/,\n\t/\\bgithub_pat_[A-Za-z0-9_]{16,}\\b/,\n\t/\\bxox[baprs]-[A-Za-z0-9-]{16,}\\b/,\n\t/\\bAKIA[A-Z0-9]{16}\\b/,\n\t/\\beyJ[A-Za-z0-9_-]{8,}\\.[A-Za-z0-9_-]{8,}\\.[A-Za-z0-9_-]{8,}\\b/,\n\t/\\bBearer\\s+[A-Za-z0-9._~+/-]{8,}={0,2}\\b/i,\n\t/(?:^|[^A-Za-z0-9])(?:[A-Za-z0-9]+[_-])*(?:authorization|api[-_ ]?key|access[-_ ]?token|token|password|secret(?:[-_ ]?key)?|private[-_ ]?key|cookie)[\"']?\\s*[:=]/i,\n] as const;\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * Asserts `value` is a plain data record: an object (never an array) with a\n * plain prototype, only data (non-accessor) own properties, and no keys outside\n * `allowedKeys`. Descriptors are inspected without ever executing a getter, so\n * raw accessor execution is never exposed at the trust boundary. Returns void;\n * it narrows nothing so typed callers keep their static field types.\n */\nfunction assertPlainDataRecord(value: unknown, name: string, allowedKeys: readonly string[]): void {\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n\t\tthrow new TypeError(`${name} must be a plain object`);\n\t}\n\tconst prototype = Object.getPrototypeOf(value);\n\tif (prototype !== null && prototype !== Object.prototype) {\n\t\tthrow new TypeError(`${name} must be a plain object`);\n\t}\n\tconst descriptors = Object.getOwnPropertyDescriptors(value);\n\tfor (const key of Object.keys(descriptors)) {\n\t\tconst descriptor = descriptors[key];\n\t\tif (descriptor !== undefined && !(\"value\" in descriptor)) {\n\t\t\tthrow new TypeError(`${name} must not define accessor properties`);\n\t\t}\n\t\tif (!allowedKeys.includes(key)) {\n\t\t\tthrow new TypeError(`${name} must contain only bounded fields`);\n\t\t}\n\t}\n}\n\nfunction looksLikeCredential(value: string): boolean {\n\treturn CREDENTIAL_SHAPES.some((pattern) => pattern.test(value));\n}\n\nfunction isBoundedIdentifier(value: unknown): value is string {\n\treturn (\n\t\ttypeof value === \"string\" &&\n\t\tvalue.length > 0 &&\n\t\tvalue.length <= MAX_RUN_JOURNAL_ID_LENGTH &&\n\t\t!/[\\u0000-\\u001f\\u007f]/.test(value)\n\t);\n}\n\nfunction assertIdentifier(value: unknown, name: string, maxLength: number): asserts value is string {\n\tif (typeof value !== \"string\" || value.length === 0 || value.length > maxLength) {\n\t\tthrow new TypeError(`${name} must be 1-${maxLength} characters of bounded text`);\n\t}\n\tif (/[\\u0000-\\u001f\\u007f]/.test(value)) {\n\t\tthrow new TypeError(`${name} must not contain C0 or DEL control characters`);\n\t}\n}\n\nfunction rejectCredential(value: string, name: string): void {\n\tif (looksLikeCredential(value)) {\n\t\tthrow new TypeError(`${name} contains a credential-shaped literal`);\n\t}\n}\n\nfunction isCanonicalTimestamp(value: unknown): value is string {\n\tif (typeof value !== \"string\") return false;\n\tconst parsed = new Date(value);\n\treturn Number.isFinite(parsed.getTime()) && parsed.toISOString() === value;\n}\n\nfunction assertCanonicalTimestamp(value: unknown, name: string): asserts value is string {\n\tif (!isCanonicalTimestamp(value)) {\n\t\tthrow new TypeError(`${name} must be a canonical ISO-8601 UTC instant`);\n\t}\n}\n\nfunction assertSafeNonNegativeInt(value: unknown, name: string): asserts value is number {\n\tif (typeof value !== \"number\" || !Number.isSafeInteger(value) || value < 0) {\n\t\tthrow new TypeError(`${name} must be a non-negative safe integer`);\n\t}\n}\n\nfunction isValidHashShape(value: unknown): value is string {\n\treturn typeof value === \"string\" && HASH64.test(value);\n}\n\nfunction assertHashShape(value: unknown, name: string): asserts value is string {\n\tif (!isValidHashShape(value)) {\n\t\tthrow new TypeError(`${name} must be 64 lowercase hex characters`);\n\t}\n}\n\nfunction deepFreeze<T>(value: T): T {\n\tif (typeof value !== \"object\" || value === null || Object.isFrozen(value)) return value;\n\tfor (const child of Object.values(value as Record<string, unknown>)) deepFreeze(child);\n\treturn Object.freeze(value);\n}\n\n/** Recursively key-sorted JSON serialization. Deterministic across runtimes and key insertion order. */\nexport function canonicalJson(value: unknown): string {\n\tif (value === null) return \"null\";\n\tif (Array.isArray(value)) return `[${value.map(canonicalJson).join(\",\")}]`;\n\tif (typeof value === \"object\") {\n\t\tconst object = value as Record<string, unknown>;\n\t\tconst parts: string[] = [];\n\t\tfor (const key of Object.keys(object).sort()) {\n\t\t\tconst child = object[key];\n\t\t\tif (child === undefined) continue;\n\t\t\tparts.push(`${JSON.stringify(key)}:${canonicalJson(child)}`);\n\t\t}\n\t\treturn `{${parts.join(\",\")}}`;\n\t}\n\treturn JSON.stringify(value);\n}\n\n/** Defensively drop a stray `hash` key so the material never includes it, regardless of caller. */\nfunction stripHashKey(record: unknown): Record<string, unknown> {\n\tif (typeof record !== \"object\" || record === null) return {};\n\tconst clone: Record<string, unknown> = {};\n\tfor (const [key, value] of Object.entries(record)) {\n\t\tif (key !== \"hash\") clone[key] = value;\n\t}\n\treturn clone;\n}\n\n/** Canonical material of a record (everything except `hash`) over which the hash is computed. */\nexport function serializeRunJournalMaterial(record: Readonly<Omit<RunJournalRecord, \"hash\">>): string {\n\treturn canonicalJson(stripHashKey(record));\n}\n\n/** Canonical, key-sorted serialization of a full record (including `hash`). */\nexport function serializeRunJournalLine(record: Readonly<RunJournalRecord>): string {\n\treturn canonicalJson(record);\n}\n\nfunction assertBoundedSessionTermination(\n\tvalue: unknown,\n\texpectedRunId: string,\n\texpectedSessionId: string,\n): asserts value is SessionTermination {\n\tassertPlainDataRecord(value, \"termination\", TERMINATION_ALLOWED_KEYS);\n\tconst v = value as Record<string, unknown>;\n\tif (v.schemaVersion !== SESSION_TERMINATION_SCHEMA_VERSION) {\n\t\tthrow new TypeError(\"termination schemaVersion must match the supported version\");\n\t}\n\tif (typeof v.runId !== \"string\" || v.runId !== expectedRunId) {\n\t\tthrow new TypeError(\"termination runId must match the record runId\");\n\t}\n\tif (typeof v.sessionId !== \"string\" || v.sessionId !== expectedSessionId) {\n\t\tthrow new TypeError(\"termination sessionId must match the record sessionId\");\n\t}\n\tif (typeof v.kind !== \"string\" || !SESSION_TERMINATION_KINDS.has(v.kind)) {\n\t\tthrow new TypeError(\"termination kind is out of bounds\");\n\t}\n\tif (typeof v.phase !== \"string\" || !SESSION_TERMINATION_PHASES.has(v.phase)) {\n\t\tthrow new TypeError(\"termination phase is out of bounds\");\n\t}\n\tif (typeof v.source !== \"string\" || !SESSION_TERMINATION_SOURCES.has(v.source)) {\n\t\tthrow new TypeError(\"termination source is out of bounds\");\n\t}\n\tif (typeof v.message !== \"string\") {\n\t\tthrow new TypeError(\"termination message must be a string\");\n\t}\n\tassertPreRedactedTerminationMessage(v.message);\n\tif (typeof v.causeCode !== \"string\" || !/^[a-z_]+\\.[a-z_]+$/.test(v.causeCode)) {\n\t\tthrow new TypeError(\"termination causeCode is out of bounds\");\n\t}\n\tif (typeof v.nextAction !== \"string\") {\n\t\tthrow new TypeError(\"termination nextAction must be a string\");\n\t}\n\tassertPreRedactedTerminationMessage(v.nextAction);\n\tif (typeof v.retryable !== \"boolean\" || typeof v.safeToAutoRetry !== \"boolean\") {\n\t\tthrow new TypeError(\"termination retry flags must be booleans\");\n\t}\n\tif (typeof v.sideEffects !== \"string\" || !SESSION_SIDE_EFFECTS.has(v.sideEffects)) {\n\t\tthrow new TypeError(\"termination sideEffects is out of bounds\");\n\t}\n\tassertCanonicalTimestamp(v.timestamp, \"termination.timestamp\");\n\tif (v.retryAfterMs !== undefined) assertSafeNonNegativeInt(v.retryAfterMs, \"termination.retryAfterMs\");\n\tif (v.provider !== undefined) {\n\t\tassertIdentifier(v.provider, \"termination.provider\", 128);\n\t\trejectCredential(v.provider, \"termination.provider\");\n\t}\n\tif (v.model !== undefined) {\n\t\tassertIdentifier(v.model, \"termination.model\", 256);\n\t\trejectCredential(v.model, \"termination.model\");\n\t}\n\tif (v.toolCallId !== undefined) {\n\t\tassertIdentifier(v.toolCallId, \"termination.toolCallId\", 512);\n\t\trejectCredential(v.toolCallId, \"termination.toolCallId\");\n\t}\n\tif (v.toolName !== undefined) {\n\t\tassertIdentifier(v.toolName, \"termination.toolName\", 128);\n\t\trejectCredential(v.toolName, \"termination.toolName\");\n\t}\n\tif (v.processSignal !== undefined) {\n\t\tif (typeof v.processSignal !== \"string\" || !SESSION_PROCESS_SIGNALS.has(v.processSignal)) {\n\t\t\tthrow new TypeError(\"termination processSignal is out of bounds\");\n\t\t}\n\t}\n\tif (v.transcriptIssue !== undefined) {\n\t\tif (typeof v.transcriptIssue !== \"string\" || !SESSION_TRANSCRIPT_ISSUES.has(v.transcriptIssue)) {\n\t\t\tthrow new TypeError(\"termination transcriptIssue is out of bounds\");\n\t\t}\n\t}\n\tassertTerminationCoherence(v as unknown as SessionTermination);\n}\n\nfunction assertTerminationCoherence(termination: SessionTermination): void {\n\tconst dot = termination.causeCode.indexOf(\".\");\n\tconst area = dot >= 0 ? termination.causeCode.slice(0, dot) : \"\";\n\tconst suffix = dot >= 0 ? termination.causeCode.slice(dot + 1) : \"\";\n\n\tlet expectedKind: string;\n\tlet expectedPhase: string;\n\tlet expectedRetryable: boolean;\n\tlet processSignalRequired = false;\n\tlet transcriptRequired = false;\n\tlet transcriptSuffix: string | null = null;\n\n\tswitch (area) {\n\t\tcase \"session\":\n\t\t\tif (suffix === \"completed\") {\n\t\t\t\texpectedKind = \"completed\";\n\t\t\t\texpectedPhase = \"completed\";\n\t\t\t\texpectedRetryable = false;\n\t\t\t} else if (suffix === \"user_abort\") {\n\t\t\t\texpectedKind = \"user_abort\";\n\t\t\t\texpectedPhase = \"control\";\n\t\t\t\texpectedRetryable = false;\n\t\t\t} else {\n\t\t\t\tthrow new TypeError(\"termination causeCode is incoherent\");\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"provider\":\n\t\t\tswitch (suffix) {\n\t\t\t\tcase \"abort\":\n\t\t\t\t\texpectedKind = \"provider_abort\";\n\t\t\t\t\texpectedPhase = \"provider\";\n\t\t\t\t\texpectedRetryable = true;\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"auth\":\n\t\t\t\t\texpectedKind = \"provider_auth\";\n\t\t\t\t\texpectedPhase = \"provider\";\n\t\t\t\t\texpectedRetryable = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"rate_limit\":\n\t\t\t\t\texpectedKind = \"provider_rate_limit\";\n\t\t\t\t\texpectedPhase = \"provider\";\n\t\t\t\t\texpectedRetryable = true;\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"network\":\n\t\t\t\t\texpectedKind = \"provider_network\";\n\t\t\t\t\texpectedPhase = \"provider\";\n\t\t\t\t\texpectedRetryable = true;\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"protocol\":\n\t\t\t\t\texpectedKind = \"provider_protocol\";\n\t\t\t\t\texpectedPhase = \"provider\";\n\t\t\t\t\t// Orphan tool_call_id / sticky transcript shape — retry after sanitize.\n\t\t\t\t\texpectedRetryable = true;\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"refusal\":\n\t\t\t\t\texpectedKind = \"provider_refusal\";\n\t\t\t\t\texpectedPhase = \"provider\";\n\t\t\t\t\texpectedRetryable = true;\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"context_overflow\":\n\t\t\t\t\texpectedKind = \"context_overflow\";\n\t\t\t\t\texpectedPhase = \"provider\";\n\t\t\t\t\texpectedRetryable = true;\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new TypeError(\"termination causeCode is incoherent\");\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"tool\":\n\t\t\tif (suffix === \"timeout\") {\n\t\t\t\texpectedKind = \"tool_timeout\";\n\t\t\t\texpectedPhase = \"tool\";\n\t\t\t\texpectedRetryable = true;\n\t\t\t} else if (suffix === \"fatal\") {\n\t\t\t\texpectedKind = \"tool_fatal\";\n\t\t\t\texpectedPhase = \"tool\";\n\t\t\t\texpectedRetryable = false;\n\t\t\t} else {\n\t\t\t\tthrow new TypeError(\"termination causeCode is incoherent\");\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"compaction\":\n\t\t\tif (suffix === \"aborted\" || suffix === \"failed\" || suffix === \"stale\") {\n\t\t\t\texpectedKind = \"compaction\";\n\t\t\t\texpectedPhase = \"compaction\";\n\t\t\t\texpectedRetryable = true;\n\t\t\t} else {\n\t\t\t\tthrow new TypeError(\"termination causeCode is incoherent\");\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"persistence\":\n\t\t\tif (\n\t\t\t\tsuffix === \"read_failed\" ||\n\t\t\t\tsuffix === \"append_failed\" ||\n\t\t\t\tsuffix === \"replace_failed\" ||\n\t\t\t\tsuffix === \"fsync_failed\" ||\n\t\t\t\tsuffix === \"lock_failed\"\n\t\t\t) {\n\t\t\t\texpectedKind = \"persistence\";\n\t\t\t\texpectedPhase = \"persistence\";\n\t\t\t\texpectedRetryable = true;\n\t\t\t} else {\n\t\t\t\tthrow new TypeError(\"termination causeCode is incoherent\");\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"process\":\n\t\t\tif (suffix === \"signal\") {\n\t\t\t\texpectedKind = \"process_signal\";\n\t\t\t\texpectedPhase = \"process\";\n\t\t\t\texpectedRetryable = false;\n\t\t\t\tprocessSignalRequired = true;\n\t\t\t} else if (suffix === \"crash\") {\n\t\t\t\texpectedKind = \"process_crash\";\n\t\t\t\texpectedPhase = \"resume\";\n\t\t\t\texpectedRetryable = true;\n\t\t\t} else {\n\t\t\t\tthrow new TypeError(\"termination causeCode is incoherent\");\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"transcript\":\n\t\t\tif (SESSION_TRANSCRIPT_ISSUES.has(suffix)) {\n\t\t\t\texpectedKind = \"transcript_invalid\";\n\t\t\t\texpectedPhase = termination.source === \"inferred_on_resume\" ? \"resume\" : \"preflight\";\n\t\t\t\texpectedRetryable = false;\n\t\t\t\ttranscriptRequired = true;\n\t\t\t\ttranscriptSuffix = suffix;\n\t\t\t} else {\n\t\t\t\tthrow new TypeError(\"termination causeCode is incoherent\");\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"configuration\":\n\t\t\tif (suffix === \"invalid\") {\n\t\t\t\texpectedKind = \"configuration\";\n\t\t\t\texpectedPhase = \"preflight\";\n\t\t\t\texpectedRetryable = false;\n\t\t\t} else {\n\t\t\t\tthrow new TypeError(\"termination causeCode is incoherent\");\n\t\t\t}\n\t\t\tbreak;\n\t\tcase \"internal\":\n\t\t\tif (suffix === \"unclassified\") {\n\t\t\t\texpectedKind = \"internal_error\";\n\t\t\t\texpectedPhase = \"preflight\";\n\t\t\t\texpectedRetryable = false;\n\t\t\t} else {\n\t\t\t\tthrow new TypeError(\"termination causeCode is incoherent\");\n\t\t\t}\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tthrow new TypeError(\"termination causeCode is incoherent\");\n\t}\n\n\tif (termination.kind !== expectedKind) {\n\t\tthrow new TypeError(\"termination kind is incoherent with causeCode\");\n\t}\n\tif (termination.phase !== expectedPhase) {\n\t\tthrow new TypeError(\"termination phase is incoherent with causeCode\");\n\t}\n\tif (termination.retryable !== expectedRetryable) {\n\t\tthrow new TypeError(\"termination retryable flag is incoherent with causeCode\");\n\t}\n\tif (processSignalRequired) {\n\t\tif (termination.processSignal === undefined) {\n\t\t\tthrow new TypeError(\"termination processSignal is required for signal causes\");\n\t\t}\n\t} else if (termination.processSignal !== undefined) {\n\t\tthrow new TypeError(\"termination processSignal is only valid for signal causes\");\n\t}\n\tif (transcriptRequired) {\n\t\tif (termination.transcriptIssue === undefined) {\n\t\t\tthrow new TypeError(\"termination transcriptIssue is required for transcript causes\");\n\t\t} else if (termination.transcriptIssue !== transcriptSuffix) {\n\t\t\tthrow new TypeError(\"termination transcriptIssue must match the transcript cause\");\n\t\t}\n\t} else if (termination.transcriptIssue !== undefined) {\n\t\tthrow new TypeError(\"termination transcriptIssue is only valid for transcript causes\");\n\t}\n\n\t// Keep in lockstep with isSafeToAutoRetry() in session-termination.ts.\n\t// provider_refusal: Fable/Claude false-positive safety stops may auto-retry once when sideEffects=none.\n\tconst expectedSafeToAutoRetry =\n\t\ttermination.retryable &&\n\t\ttermination.source === \"observed\" &&\n\t\ttermination.sideEffects === \"none\" &&\n\t\t(termination.kind === \"provider_rate_limit\" ||\n\t\t\ttermination.kind === \"provider_network\" ||\n\t\t\ttermination.kind === \"provider_refusal\");\n\tif (termination.safeToAutoRetry !== expectedSafeToAutoRetry) {\n\t\tthrow new TypeError(\"termination safeToAutoRetry flag is incoherent\");\n\t}\n}\n\nfunction assertBoundedAuditDetails(value: unknown): asserts value is RunJournalAuditDetails {\n\tassertPlainDataRecord(value, \"audit details\", AUDIT_DETAIL_KEYS);\n\tconst v = value as Record<string, unknown>;\n\tif (v.toolCallId !== undefined) {\n\t\tassertIdentifier(v.toolCallId, \"details.toolCallId\", 512);\n\t\trejectCredential(v.toolCallId, \"details.toolCallId\");\n\t}\n\tif (v.toolName !== undefined) {\n\t\tassertIdentifier(v.toolName, \"details.toolName\", 128);\n\t\trejectCredential(v.toolName, \"details.toolName\");\n\t}\n\tif (v.disposition !== undefined && (typeof v.disposition !== \"string\" || !AUDIT_DISPOSITIONS.has(v.disposition))) {\n\t\tthrow new TypeError(\"details.disposition is out of bounds\");\n\t}\n\tif (v.outcome !== undefined && (typeof v.outcome !== \"string\" || !AUDIT_OUTCOMES.has(v.outcome))) {\n\t\tthrow new TypeError(\"details.outcome is out of bounds\");\n\t}\n\tif (v.timeoutMs !== undefined) {\n\t\tassertSafeNonNegativeInt(v.timeoutMs, \"details.timeoutMs\");\n\t}\n\tif (v.executionStarted !== undefined && typeof v.executionStarted !== \"boolean\") {\n\t\tthrow new TypeError(\"details.executionStarted must be a boolean\");\n\t}\n\tif (v.insertedToolCallIds !== undefined) {\n\t\tif (!Array.isArray(v.insertedToolCallIds) || v.insertedToolCallIds.length > MAX_AUDIT_INSERTED_IDS) {\n\t\t\tthrow new TypeError(\"details.insertedToolCallIds must be a bounded array\");\n\t\t}\n\t\tfor (const id of v.insertedToolCallIds) {\n\t\t\tassertIdentifier(id, \"details.insertedToolCallIds[]\", 512);\n\t\t\trejectCredential(id, \"details.insertedToolCallIds[]\");\n\t\t}\n\t}\n\tif (v.reason !== undefined) {\n\t\tassertIdentifier(v.reason, \"details.reason\", MAX_AUDIT_REASON_LENGTH);\n\t\trejectCredential(v.reason, \"details.reason\");\n\t}\n\tif (v.sessionRisk !== undefined && v.sessionRisk !== \"elevated\") {\n\t\tthrow new TypeError(\"details.sessionRisk is out of bounds\");\n\t}\n}\n\nfunction isTerminalCoherentWithEvent(\n\tevent: \"run_finished\" | \"run_recovered\" | \"run_abandoned\",\n\ttermination: SessionTermination,\n): boolean {\n\tif (event === \"run_recovered\") {\n\t\treturn (\n\t\t\ttermination.source === \"inferred_on_resume\" &&\n\t\t\ttermination.kind === \"process_crash\" &&\n\t\t\ttermination.phase === \"resume\"\n\t\t);\n\t}\n\tif (termination.source !== \"observed\") return false;\n\t// process_crash is only coherent with an inferred_on_resume (run_recovered) source.\n\tif (termination.kind === \"process_crash\") return false;\n\treturn true;\n}\n\nfunction assertTerminalCoherentWithEvent(\n\tevent: \"run_finished\" | \"run_recovered\" | \"run_abandoned\",\n\ttermination: SessionTermination,\n): void {\n\tif (isTerminalCoherentWithEvent(event, termination)) return;\n\tif (event === \"run_recovered\") {\n\t\tthrow new TypeError(\n\t\t\t\"run_recovered requires a coherent process_crash termination (source inferred_on_resume, phase resume)\",\n\t\t);\n\t}\n\tif (termination.kind === \"process_crash\") {\n\t\tthrow new TypeError(\"process_crash terminations may only appear on run_recovered events\");\n\t}\n\tthrow new TypeError(\"run_finished and run_abandoned require a termination source of observed\");\n}\n\n/**\n * Append-only run-journal writer. The constructor records the first\n * `run_started` event (and recomputes its hash); {@link RunJournal.start} opens\n * subsequent runs after a terminal event, while {@link RunJournal.finish},\n * {@link RunJournal.abandon}, and {@link RunJournal.recover} close the currently\n * open run. Exactly one run is open at a time.\n */\nexport class RunJournal {\n\tprivate readonly hashFn: RunJournalHashFn;\n\tprivate readonly sessionId: string;\n\tprivate readonly startedRunIds: Set<string> = new Set();\n\tprivate readonly terminatedRunIds: Set<string> = new Set();\n\tprivate readonly mutableRecords: RunJournalRecord[] = [];\n\tprivate recordsSnapshot: readonly RunJournalRecord[] = Object.freeze([]) as readonly RunJournalRecord[];\n\tprivate lastSessionRevision = 0;\n\tprivate prevHash: string;\n\tprivate nextSeq: number;\n\tprivate openRun: { readonly runId: string; readonly sessionId: string } | null = null;\n\n\tconstructor(init: RunJournalConstructorInit) {\n\t\tassertPlainDataRecord(init, \"RunJournalConstructorInit\", [\n\t\t\t\"hashFn\",\n\t\t\t\"sessionId\",\n\t\t\t\"runId\",\n\t\t\t\"sessionRevision\",\n\t\t\t\"timestamp\",\n\t\t\t\"prevHash\",\n\t\t\t\"seq\",\n\t\t\t\"openInitialRun\",\n\t\t]);\n\t\tif (init.openInitialRun !== undefined && typeof init.openInitialRun !== \"boolean\") {\n\t\t\tthrow new TypeError(\"openInitialRun must be a boolean\");\n\t\t}\n\t\tif (typeof init.hashFn !== \"function\") {\n\t\t\tthrow new TypeError(\"hashFn must be a function\");\n\t\t}\n\t\tthis.hashFn = init.hashFn;\n\t\tassertIdentifier(init.sessionId, \"sessionId\", MAX_RUN_JOURNAL_ID_LENGTH);\n\t\trejectCredential(init.sessionId, \"sessionId\");\n\t\tthis.sessionId = init.sessionId;\n\t\tconst startSeq = init.seq ?? 0;\n\t\tassertSafeNonNegativeInt(startSeq, \"seq\");\n\t\tconst startPrevHash = init.prevHash ?? GENESIS_HASH;\n\t\tassertHashShape(startPrevHash, \"prevHash\");\n\t\tthis.prevHash = startPrevHash;\n\t\tthis.nextSeq = startSeq;\n\t\tif (init.openInitialRun !== false) {\n\t\t\tthis.appendStarted({\n\t\t\t\trunId: init.runId,\n\t\t\t\tsessionRevision: init.sessionRevision,\n\t\t\t\ttimestamp: init.timestamp,\n\t\t\t});\n\t\t} else {\n\t\t\t// Audit-first journal: validate the seed runId shape, append nothing.\n\t\t\tassertIdentifier(init.runId, \"runId\", MAX_RUN_JOURNAL_ID_LENGTH);\n\t\t\trejectCredential(init.runId, \"runId\");\n\t\t}\n\t}\n\n\tstart(input: RunJournalStartInput): RunJournalStartedRecord {\n\t\treturn this.appendStarted(input);\n\t}\n\n\tfinish(input: RunJournalTerminalInput): RunJournalTerminalRecord {\n\t\treturn this.appendTerminal(\"run_finished\", input);\n\t}\n\n\tabandon(input: RunJournalTerminalInput): RunJournalTerminalRecord {\n\t\treturn this.appendTerminal(\"run_abandoned\", input);\n\t}\n\n\trecover(input: RunJournalTerminalInput): RunJournalTerminalRecord {\n\t\treturn this.appendTerminal(\"run_recovered\", input);\n\t}\n\n\t/**\n\t * Append an audit-only record. Allowed with or without an open run; never\n\t * opens, closes, or otherwise mutates run state. The record joins the same\n\t * seq/hash chain as lifecycle records.\n\t */\n\taudit(input: RunJournalAuditInput): RunJournalAuditRecord {\n\t\tassertPlainDataRecord(input, \"RunJournalAuditInput\", [\"event\", \"details\", \"sessionRevision\", \"timestamp\"]);\n\t\tif (typeof input.event !== \"string\" || !AUDIT_EVENTS.has(input.event as RunJournalEvent)) {\n\t\t\tthrow new TypeError(\"audit event is out of bounds\");\n\t\t}\n\t\tassertSafeNonNegativeInt(input.sessionRevision, \"sessionRevision\");\n\t\tif (input.sessionRevision < this.lastSessionRevision) {\n\t\t\tthrow new Error(\"sessionRevision must not regress across the journal\");\n\t\t}\n\t\tassertCanonicalTimestamp(input.timestamp, \"timestamp\");\n\t\tassertBoundedAuditDetails(input.details);\n\t\tconst base: Omit<RunJournalAuditRecord, \"hash\"> = {\n\t\t\tschemaVersion: RUN_JOURNAL_SCHEMA_VERSION,\n\t\t\tseq: this.nextSeq,\n\t\t\tevent: input.event as RunJournalAuditEvent,\n\t\t\trunId: this.openRun === null ? \"none\" : this.openRun.runId,\n\t\t\tsessionId: this.sessionId,\n\t\t\tsessionRevision: input.sessionRevision,\n\t\t\ttimestamp: input.timestamp,\n\t\t\tprevHash: this.prevHash,\n\t\t\tdetails: input.details,\n\t\t};\n\t\tconst record = this.seal(base);\n\t\tthis.mutableRecords.push(record);\n\t\tthis.prevHash = record.hash;\n\t\tthis.nextSeq += 1;\n\t\tthis.lastSessionRevision = input.sessionRevision;\n\t\tthis.refreshRecordsSnapshot();\n\t\treturn record;\n\t}\n\n\tget records(): readonly RunJournalRecord[] {\n\t\treturn this.recordsSnapshot;\n\t}\n\n\tget openRunId(): string | null {\n\t\treturn this.openRun === null ? null : this.openRun.runId;\n\t}\n\n\tserialize(): string {\n\t\tif (this.mutableRecords.length === 0) return \"\";\n\t\treturn `${this.mutableRecords.map((record) => serializeRunJournalLine(record)).join(\"\\n\")}\\n`;\n\t}\n\n\ttoBytes(): Uint8Array {\n\t\treturn TEXT_ENCODER.encode(this.serialize());\n\t}\n\n\tprivate refreshRecordsSnapshot(): void {\n\t\tthis.recordsSnapshot = Object.freeze([...this.mutableRecords]) as readonly RunJournalRecord[];\n\t}\n\n\tprivate appendStarted(input: RunJournalStartInput): RunJournalStartedRecord {\n\t\tassertPlainDataRecord(input, \"RunJournalStartInput\", [\"runId\", \"sessionRevision\", \"timestamp\"]);\n\t\tassertIdentifier(input.runId, \"runId\", MAX_RUN_JOURNAL_ID_LENGTH);\n\t\trejectCredential(input.runId, \"runId\");\n\t\tassertSafeNonNegativeInt(input.sessionRevision, \"sessionRevision\");\n\t\tif (input.sessionRevision < this.lastSessionRevision) {\n\t\t\tthrow new Error(\"sessionRevision must not regress across the journal\");\n\t\t}\n\t\tassertCanonicalTimestamp(input.timestamp, \"timestamp\");\n\t\tif (this.openRun !== null) {\n\t\t\tthrow new Error(\"a run is already open; terminate it before starting another\");\n\t\t}\n\t\tif (this.startedRunIds.has(input.runId)) {\n\t\t\tthrow new Error(\"runId was already started earlier in this journal\");\n\t\t}\n\t\tconst base: Omit<RunJournalStartedRecord, \"hash\"> = {\n\t\t\tschemaVersion: RUN_JOURNAL_SCHEMA_VERSION,\n\t\t\tseq: this.nextSeq,\n\t\t\tevent: \"run_started\",\n\t\t\trunId: input.runId,\n\t\t\tsessionId: this.sessionId,\n\t\t\tsessionRevision: input.sessionRevision,\n\t\t\ttimestamp: input.timestamp,\n\t\t\tprevHash: this.prevHash,\n\t\t};\n\t\tconst record = this.seal(base);\n\t\tthis.mutableRecords.push(record);\n\t\tthis.startedRunIds.add(input.runId);\n\t\tthis.openRun = Object.freeze({ runId: input.runId, sessionId: this.sessionId });\n\t\tthis.prevHash = record.hash;\n\t\tthis.nextSeq += 1;\n\t\tthis.lastSessionRevision = input.sessionRevision;\n\t\tthis.refreshRecordsSnapshot();\n\t\treturn record;\n\t}\n\n\tprivate appendTerminal(\n\t\tevent: \"run_finished\" | \"run_recovered\" | \"run_abandoned\",\n\t\tinput: RunJournalTerminalInput,\n\t): RunJournalTerminalRecord {\n\t\tassertPlainDataRecord(input, \"RunJournalTerminalInput\", [\"termination\", \"sessionRevision\", \"timestamp\"]);\n\t\tif (this.openRun === null) {\n\t\t\tthrow new Error(\"no run is open; start a run before terminating it\");\n\t\t}\n\t\tassertSafeNonNegativeInt(input.sessionRevision, \"sessionRevision\");\n\t\tif (input.sessionRevision < this.lastSessionRevision) {\n\t\t\tthrow new Error(\"sessionRevision must not regress across the journal\");\n\t\t}\n\t\tassertCanonicalTimestamp(input.timestamp, \"timestamp\");\n\t\tassertBoundedSessionTermination(input.termination, this.openRun.runId, this.sessionId);\n\t\tassertTerminalCoherentWithEvent(event, input.termination);\n\t\tif (input.timestamp !== input.termination.timestamp) {\n\t\t\tthrow new TypeError(\"terminal event timestamp must equal termination timestamp\");\n\t\t}\n\t\tif (this.terminatedRunIds.has(this.openRun.runId)) {\n\t\t\tthrow new Error(\"the open run was already terminated\");\n\t\t}\n\t\tconst base: Omit<RunJournalTerminalRecord, \"hash\"> = {\n\t\t\tschemaVersion: RUN_JOURNAL_SCHEMA_VERSION,\n\t\t\tseq: this.nextSeq,\n\t\t\tevent,\n\t\t\trunId: this.openRun.runId,\n\t\t\tsessionId: this.sessionId,\n\t\t\tsessionRevision: input.sessionRevision,\n\t\t\ttimestamp: input.timestamp,\n\t\t\tprevHash: this.prevHash,\n\t\t\ttermination: input.termination,\n\t\t};\n\t\tconst record = this.seal(base);\n\t\tthis.mutableRecords.push(record);\n\t\tthis.terminatedRunIds.add(this.openRun.runId);\n\t\tthis.openRun = null;\n\t\tthis.prevHash = record.hash;\n\t\tthis.nextSeq += 1;\n\t\tthis.lastSessionRevision = input.sessionRevision;\n\t\tthis.refreshRecordsSnapshot();\n\t\treturn record;\n\t}\n\n\tprivate seal<T extends Omit<RunJournalRecord, \"hash\">>(base: T): T & { readonly hash: string } {\n\t\tconst material = serializeRunJournalMaterial(base);\n\t\tlet hash: string;\n\t\ttry {\n\t\t\thash = this.hashFn(TEXT_ENCODER.encode(material));\n\t\t} catch (error) {\n\t\t\tthrow new TypeError(\"hashFn threw while sealing a record; failing closed\", { cause: error });\n\t\t}\n\t\tif (!isValidHashShape(hash)) {\n\t\t\tthrow new TypeError(\"hashFn must return 64 lowercase hex characters\");\n\t\t}\n\t\treturn deepFreeze({ ...base, hash }) as T & { readonly hash: string };\n\t}\n}\n\ninterface CommonShape {\n\treadonly schemaVersion: 1;\n\treadonly seq: number;\n\treadonly event: RunJournalEvent;\n\treadonly runId: string;\n\treadonly sessionId: string;\n\treadonly sessionRevision: number;\n\treadonly timestamp: string;\n\treadonly prevHash: string;\n\treadonly hash: string;\n}\n\nfunction validateCommonShape(value: unknown): CommonShape | null {\n\tif (!isPlainObject(value)) return null;\n\tconst rawEvent = (value as { event?: unknown }).event;\n\tconst isTerminal = typeof rawEvent === \"string\" && TERMINAL_EVENTS.has(rawEvent as RunJournalEvent);\n\tconst isAudit = typeof rawEvent === \"string\" && AUDIT_EVENTS.has(rawEvent as RunJournalEvent);\n\tconst allowed: readonly string[] = isTerminal\n\t\t? [...COMMON_RECORD_KEYS, \"termination\"]\n\t\t: isAudit\n\t\t\t? [...COMMON_RECORD_KEYS, \"details\"]\n\t\t\t: COMMON_RECORD_KEYS;\n\tif (Object.keys(value).some((key) => !allowed.includes(key))) {\n\t\treturn null;\n\t}\n\tconst hasTermination = \"termination\" in value;\n\tif (isTerminal !== hasTermination) return null;\n\tif (isAudit !== \"details\" in value) return null;\n\tif (value.schemaVersion !== RUN_JOURNAL_SCHEMA_VERSION) return null;\n\tif (typeof value.event !== \"string\" || !RUN_JOURNAL_EVENTS.has(value.event as RunJournalEvent)) return null;\n\tif (typeof value.seq !== \"number\" || !Number.isSafeInteger(value.seq) || value.seq < 0) return null;\n\tif (!isBoundedIdentifier(value.runId) || looksLikeCredential(value.runId)) return null;\n\tif (!isBoundedIdentifier(value.sessionId) || looksLikeCredential(value.sessionId)) return null;\n\tif (\n\t\ttypeof value.sessionRevision !== \"number\" ||\n\t\t!Number.isSafeInteger(value.sessionRevision) ||\n\t\tvalue.sessionRevision < 0\n\t) {\n\t\treturn null;\n\t}\n\tif (!isCanonicalTimestamp(value.timestamp)) return null;\n\tif (typeof value.prevHash !== \"string\" || typeof value.hash !== \"string\") return null;\n\treturn {\n\t\tschemaVersion: RUN_JOURNAL_SCHEMA_VERSION,\n\t\tseq: value.seq,\n\t\tevent: value.event as RunJournalEvent,\n\t\trunId: value.runId,\n\t\tsessionId: value.sessionId,\n\t\tsessionRevision: value.sessionRevision,\n\t\ttimestamp: value.timestamp,\n\t\tprevHash: value.prevHash,\n\t\thash: value.hash,\n\t};\n}\n\ntype TerminationProbe =\n\t| { readonly kind: \"ok\"; readonly termination: SessionTermination }\n\t| { readonly kind: \"mismatch\" }\n\t| {\n\t\t\treadonly kind: \"source\";\n\t };\n\nfunction probeTermination(\n\trawTermination: unknown,\n\trunId: string,\n\tsessionId: string,\n\tevent: RunJournalEvent,\n): TerminationProbe {\n\tlet termination: SessionTermination;\n\ttry {\n\t\tassertBoundedSessionTermination(rawTermination, runId, sessionId);\n\t\ttermination = rawTermination as SessionTermination;\n\t} catch {\n\t\treturn { kind: \"mismatch\" };\n\t}\n\tif (!isTerminalCoherentWithEvent(event as RunJournalTerminalRecord[\"event\"], termination)) {\n\t\treturn { kind: \"source\" };\n\t}\n\treturn { kind: \"ok\", termination };\n}\n\nfunction addFinding(findings: RunJournalFinding[], finding: RunJournalFinding): void {\n\tfindings.push(Object.freeze({ ...finding }));\n}\n\n/**\n * Inspect the complete-line prefix of a run-journal byte sequence without\n * mutating or repairing it. Only bytes through the final newline are parsed;\n * trailing bytes are reported as a fragment and never parsed. Every hash is\n * recomputed with the injected `hashFn`. The returned report is deeply frozen.\n */\nexport function inspectRunJournal(bytes: Uint8Array, hashFn: RunJournalHashFn): RunJournalReport {\n\tconst findings: RunJournalFinding[] = [];\n\n\tlet lastNewline = -1;\n\tfor (let index = bytes.byteLength - 1; index >= 0; index -= 1) {\n\t\tif (bytes[index] === 0x0a) {\n\t\t\tlastNewline = index;\n\t\t\tbreak;\n\t\t}\n\t}\n\tconst completeByteCount = lastNewline + 1;\n\tconst trailingByteCount = bytes.byteLength - completeByteCount;\n\tif (trailingByteCount > 0) addFinding(findings, { code: \"trailing_fragment\" });\n\n\tconst completeBytes = bytes.subarray(0, completeByteCount);\n\tlet lineCount = 0;\n\tconst parsedLines: { readonly line: number; readonly value: unknown }[] = [];\n\tif (completeByteCount > 0) {\n\t\tlet text: string | undefined;\n\t\ttry {\n\t\t\ttext = TEXT_DECODER.decode(completeBytes);\n\t\t} catch {\n\t\t\taddFinding(findings, { code: \"invalid_utf8\" });\n\t\t}\n\t\tif (text !== undefined) {\n\t\t\tconst body = text.slice(0, -1);\n\t\t\tconst lines = body.length === 0 ? [] : body.split(\"\\n\");\n\t\t\tlineCount = lines.length;\n\t\t\tfor (let index = 0; index < lines.length; index += 1) {\n\t\t\t\tconst lineNumber = index + 1;\n\t\t\t\tconst line = lines[index];\n\t\t\t\tif (line.trim().length === 0) {\n\t\t\t\t\taddFinding(findings, { code: \"malformed_json\", line: lineNumber });\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tparsedLines.push({ line: lineNumber, value: JSON.parse(line) });\n\t\t\t\t} catch {\n\t\t\t\t\taddFinding(findings, { code: \"malformed_json\", line: lineNumber });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tlet openRun: { runId: string; sessionId: string } | null = null;\n\tconst seenStarts = new Set<string>();\n\tconst terminatedRuns = new Set<string>();\n\tlet expectedSeq = 0;\n\tlet lastHash = GENESIS_HASH;\n\tlet journalSessionId: string | null = null;\n\tlet lastRevision = 0;\n\tconst validRecords: RunJournalRecord[] = [];\n\n\tfor (const { line, value } of parsedLines) {\n\t\tconst common = validateCommonShape(value);\n\t\tif (common === null) {\n\t\t\taddFinding(findings, { code: \"schema\", line });\n\t\t\tcontinue;\n\t\t}\n\t\tlet auditDetails: RunJournalAuditDetails | null = null;\n\t\tif (AUDIT_EVENTS.has(common.event)) {\n\t\t\ttry {\n\t\t\t\tassertBoundedAuditDetails((value as Record<string, unknown>).details);\n\t\t\t\tauditDetails = (value as { details: RunJournalAuditDetails }).details;\n\t\t\t} catch {\n\t\t\t\taddFinding(findings, { code: \"schema\", line });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tlet termination: SessionTermination | null = null;\n\t\tif (TERMINAL_EVENTS.has(common.event)) {\n\t\t\tconst probe = probeTermination(\n\t\t\t\t(value as Record<string, unknown>).termination,\n\t\t\t\tcommon.runId,\n\t\t\t\tcommon.sessionId,\n\t\t\t\tcommon.event,\n\t\t\t);\n\t\t\tif (probe.kind === \"mismatch\") {\n\t\t\t\taddFinding(findings, { code: \"termination_mismatch\", line, runId: common.runId });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (probe.kind === \"source\") {\n\t\t\t\taddFinding(findings, { code: \"recovered_source_invalid\", line, runId: common.runId });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttermination = probe.termination;\n\t\t\tif (common.timestamp !== termination.timestamp) {\n\t\t\t\taddFinding(findings, { code: \"termination_mismatch\", line, runId: common.runId });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tif (journalSessionId === null) {\n\t\t\tjournalSessionId = common.sessionId;\n\t\t} else if (common.sessionId !== journalSessionId) {\n\t\t\taddFinding(findings, { code: \"session_mismatch\", line, runId: common.runId });\n\t\t\tcontinue;\n\t\t}\n\t\tif (common.sessionRevision < lastRevision) {\n\t\t\taddFinding(findings, { code: \"session_revision_regression\", line, runId: common.runId });\n\t\t\tcontinue;\n\t\t}\n\t\tlastRevision = common.sessionRevision;\n\n\t\tconst baseRecord = {\n\t\t\tschemaVersion: RUN_JOURNAL_SCHEMA_VERSION,\n\t\t\tseq: common.seq,\n\t\t\tevent: common.event,\n\t\t\trunId: common.runId,\n\t\t\tsessionId: common.sessionId,\n\t\t\tsessionRevision: common.sessionRevision,\n\t\t\ttimestamp: common.timestamp,\n\t\t\tprevHash: common.prevHash,\n\t\t};\n\t\tconst recordWithoutHash = (\n\t\t\ttermination !== null\n\t\t\t\t? { ...baseRecord, termination }\n\t\t\t\t: auditDetails !== null\n\t\t\t\t\t? { ...baseRecord, details: auditDetails }\n\t\t\t\t\t: baseRecord\n\t\t) as Omit<RunJournalRecord, \"hash\">;\n\n\t\tif (common.seq > expectedSeq) addFinding(findings, { code: \"seq_gap\", line });\n\t\telse if (common.seq < expectedSeq) addFinding(findings, { code: \"seq_regression\", line });\n\t\texpectedSeq = common.seq + 1;\n\n\t\tconst hashShapeOk = isValidHashShape(common.hash);\n\t\tconst prevHashShapeOk = isValidHashShape(common.prevHash);\n\t\tif (!hashShapeOk || !prevHashShapeOk) addFinding(findings, { code: \"hash_shape\", line });\n\n\t\tconst material = serializeRunJournalMaterial(recordWithoutHash);\n\t\tlet recomputeOk = false;\n\t\ttry {\n\t\t\tconst recomputed = hashFn(TEXT_ENCODER.encode(material));\n\t\t\trecomputeOk = isValidHashShape(recomputed) && recomputed === common.hash;\n\t\t} catch {\n\t\t\trecomputeOk = false;\n\t\t}\n\t\tif (!recomputeOk) addFinding(findings, { code: \"hash_mismatch\", line });\n\n\t\tif (common.prevHash !== lastHash) addFinding(findings, { code: \"hash_chain_break\", line });\n\t\tif (hashShapeOk) lastHash = common.hash;\n\n\t\tif (AUDIT_EVENTS.has(common.event)) {\n\t\t\t// Audit records never affect the run-state machine.\n\t\t} else if (common.event === \"run_started\") {\n\t\t\tif (seenStarts.has(common.runId)) addFinding(findings, { code: \"duplicate_start\", line, runId: common.runId });\n\t\t\tif (openRun !== null && openRun.runId !== common.runId) {\n\t\t\t\taddFinding(findings, { code: \"interleaved_run\", line, runId: common.runId });\n\t\t\t} else if (openRun === null) {\n\t\t\t\topenRun = { runId: common.runId, sessionId: common.sessionId };\n\t\t\t}\n\t\t\tseenStarts.add(common.runId);\n\t\t} else {\n\t\t\tif (terminatedRuns.has(common.runId)) {\n\t\t\t\taddFinding(findings, { code: \"duplicate_terminal\", line, runId: common.runId });\n\t\t\t} else if (openRun === null || openRun.runId !== common.runId) {\n\t\t\t\taddFinding(findings, { code: \"orphan_terminal\", line, runId: common.runId });\n\t\t\t} else {\n\t\t\t\tterminatedRuns.add(common.runId);\n\t\t\t\topenRun = null;\n\t\t\t}\n\t\t}\n\n\t\tconst record = { ...recordWithoutHash, hash: common.hash } as RunJournalRecord;\n\t\tvalidRecords.push(deepFreeze(record) as RunJournalRecord);\n\t}\n\n\tif (openRun !== null) addFinding(findings, { code: \"run_unclosed\", runId: openRun.runId });\n\n\treturn deepFreeze({\n\t\tok: findings.length === 0,\n\t\tcompletePrefix: Object.freeze({ byteCount: completeByteCount, lineCount }),\n\t\ttrailingByteCount,\n\t\trecords: Object.freeze(validRecords) as readonly RunJournalRecord[],\n\t\topenRunId: openRun === null ? null : openRun.runId,\n\t\tfindings: Object.freeze(findings) as readonly RunJournalFinding[],\n\t}) as RunJournalReport;\n}\n"]}
@@ -1,11 +1,17 @@
1
1
  export declare const SESSION_TERMINATION_SCHEMA_VERSION: 1;
2
2
  export declare const MAX_SESSION_TERMINATION_MESSAGE_LENGTH = 512;
3
- export type SessionTerminationKind = "completed" | "user_abort" | "provider_abort" | "provider_auth" | "provider_rate_limit" | "provider_network" | "provider_protocol" | "context_overflow" | "transcript_invalid" | "tool_timeout" | "tool_fatal" | "compaction" | "persistence" | "process_signal" | "process_crash" | "configuration" | "internal_error";
3
+ /**
4
+ * Canonical list of termination kinds. The run-journal validator derives its
5
+ * runtime bounds from this tuple so a newly added kind can never crash
6
+ * journaling with "termination kind is out of bounds" again.
7
+ */
8
+ export declare const SESSION_TERMINATION_KIND_VALUES: readonly ["completed", "user_abort", "provider_abort", "provider_auth", "provider_rate_limit", "provider_network", "provider_protocol", "provider_refusal", "context_overflow", "transcript_invalid", "tool_timeout", "tool_fatal", "compaction", "persistence", "process_signal", "process_crash", "configuration", "internal_error"];
9
+ export type SessionTerminationKind = (typeof SESSION_TERMINATION_KIND_VALUES)[number];
4
10
  export type SessionTerminationPhase = "completed" | "control" | "preflight" | "provider" | "tool" | "compaction" | "persistence" | "process" | "resume";
5
11
  export type SessionTerminationSource = "observed" | "inferred_on_resume";
6
12
  export type SessionSideEffects = "none" | "possible" | "confirmed";
7
13
  export type SessionProcessSignal = "SIGINT" | "SIGTERM" | "SIGHUP" | "SIGQUIT";
8
- export type ProviderTerminationCauseCode = "abort" | "auth" | "rate_limit" | "network" | "protocol" | "context_overflow";
14
+ export type ProviderTerminationCauseCode = "abort" | "auth" | "rate_limit" | "network" | "protocol" | "refusal" | "context_overflow";
9
15
  export type ToolTerminationCauseCode = "timeout" | "fatal";
10
16
  export type CompactionTerminationCauseCode = "aborted" | "failed" | "stale";
11
17
  export type PersistenceTerminationCauseCode = "read_failed" | "append_failed" | "replace_failed" | "fsync_failed" | "lock_failed";
@@ -1 +1 @@
1
- {"version":3,"file":"session-termination.d.ts","sourceRoot":"","sources":["../../src/core/session-termination.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kCAAkC,GAAa,CAAC;AAC7D,eAAO,MAAM,sCAAsC,MAAM,CAAC;AAE1D,MAAM,MAAM,sBAAsB,GAC/B,WAAW,GACX,YAAY,GACZ,gBAAgB,GAChB,eAAe,GACf,qBAAqB,GACrB,kBAAkB,GAClB,mBAAmB,GACnB,kBAAkB,GAClB,oBAAoB,GACpB,cAAc,GACd,YAAY,GACZ,YAAY,GACZ,aAAa,GACb,gBAAgB,GAChB,eAAe,GACf,eAAe,GACf,gBAAgB,CAAC;AAEpB,MAAM,MAAM,uBAAuB,GAChC,WAAW,GACX,SAAS,GACT,WAAW,GACX,UAAU,GACV,MAAM,GACN,YAAY,GACZ,aAAa,GACb,SAAS,GACT,QAAQ,CAAC;AAEZ,MAAM,MAAM,wBAAwB,GAAG,UAAU,GAAG,oBAAoB,CAAC;AACzE,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,UAAU,GAAG,WAAW,CAAC;AACnE,MAAM,MAAM,oBAAoB,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE/E,MAAM,MAAM,4BAA4B,GACrC,OAAO,GACP,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E;AACxE,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,kBAAkB,GAAG,MAAM,CAchF;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,+BAA+B,GAAG,kBAAkB,CA2CrG","sourcesContent":["export const SESSION_TERMINATION_SCHEMA_VERSION = 1 as const;\nexport const MAX_SESSION_TERMINATION_MESSAGE_LENGTH = 512;\n\nexport type SessionTerminationKind =\n\t| \"completed\"\n\t| \"user_abort\"\n\t| \"provider_abort\"\n\t| \"provider_auth\"\n\t| \"provider_rate_limit\"\n\t| \"provider_network\"\n\t| \"provider_protocol\"\n\t| \"context_overflow\"\n\t| \"transcript_invalid\"\n\t| \"tool_timeout\"\n\t| \"tool_fatal\"\n\t| \"compaction\"\n\t| \"persistence\"\n\t| \"process_signal\"\n\t| \"process_crash\"\n\t| \"configuration\"\n\t| \"internal_error\";\n\nexport type SessionTerminationPhase =\n\t| \"completed\"\n\t| \"control\"\n\t| \"preflight\"\n\t| \"provider\"\n\t| \"tool\"\n\t| \"compaction\"\n\t| \"persistence\"\n\t| \"process\"\n\t| \"resume\";\n\nexport type SessionTerminationSource = \"observed\" | \"inferred_on_resume\";\nexport type SessionSideEffects = \"none\" | \"possible\" | \"confirmed\";\nexport type SessionProcessSignal = \"SIGINT\" | \"SIGTERM\" | \"SIGHUP\" | \"SIGQUIT\";\n\nexport type ProviderTerminationCauseCode =\n\t| \"abort\"\n\t| \"auth\"\n\t| \"rate_limit\"\n\t| \"network\"\n\t| \"protocol\"\n\t| \"context_overflow\";\nexport type ToolTerminationCauseCode = \"timeout\" | \"fatal\";\nexport type CompactionTerminationCauseCode = \"aborted\" | \"failed\" | \"stale\";\nexport type PersistenceTerminationCauseCode =\n\t| \"read_failed\"\n\t| \"append_failed\"\n\t| \"replace_failed\"\n\t| \"fsync_failed\"\n\t| \"lock_failed\";\nexport type TranscriptTerminationCauseCode =\n\t| \"missing_result\"\n\t| \"duplicate_result\"\n\t| \"orphan_result\"\n\t| \"duplicate_call_id\"\n\t| \"interleaved_non_result\"\n\t| \"invalid_jsonl\"\n\t| \"invalid_tree\"\n\t| \"unsupported_version\"\n\t| \"trailing_fragment\";\nexport type SessionTerminationCauseCode =\n\t| \"session.completed\"\n\t| \"session.user_abort\"\n\t| `provider.${ProviderTerminationCauseCode}`\n\t| `tool.${ToolTerminationCauseCode}`\n\t| `compaction.${CompactionTerminationCauseCode}`\n\t| `persistence.${PersistenceTerminationCauseCode}`\n\t| \"process.signal\"\n\t| \"process.crash\"\n\t| `transcript.${TranscriptTerminationCauseCode}`\n\t| \"configuration.invalid\"\n\t| \"internal.unclassified\";\n\nexport type SessionTerminationCause =\n\t| { readonly area: \"completed\" }\n\t| { readonly area: \"user\"; readonly code: \"abort\" }\n\t| { readonly area: \"provider\"; readonly code: ProviderTerminationCauseCode }\n\t| { readonly area: \"tool\"; readonly code: ToolTerminationCauseCode }\n\t| { readonly area: \"compaction\"; readonly code: CompactionTerminationCauseCode }\n\t| { readonly area: \"persistence\"; readonly code: PersistenceTerminationCauseCode }\n\t| { readonly area: \"process\"; readonly code: \"signal\"; readonly signal: SessionProcessSignal }\n\t| { readonly area: \"process\"; readonly code: \"crash\" }\n\t| { readonly area: \"transcript\"; readonly code: TranscriptTerminationCauseCode }\n\t| { readonly area: \"configuration\"; readonly code: \"invalid\" }\n\t| { readonly area: \"internal\"; readonly code: \"unclassified\" };\n\nexport interface ClassifySessionTerminationInput {\n\treadonly sessionId: string;\n\treadonly runId: string;\n\t/** Deterministic caller-provided ISO-8601 timestamp. */\n\treadonly timestamp: string;\n\treadonly source: SessionTerminationSource;\n\t/** Caller-supplied, pre-redacted diagnostic text. */\n\treadonly message: string;\n\treadonly cause: SessionTerminationCause;\n\treadonly sideEffects: SessionSideEffects;\n\treadonly retryAfterMs?: number;\n\treadonly provider?: string;\n\treadonly model?: string;\n\treadonly toolCallId?: string;\n\treadonly toolName?: string;\n}\n\nexport interface SessionTermination {\n\treadonly schemaVersion: typeof SESSION_TERMINATION_SCHEMA_VERSION;\n\treadonly sessionId: string;\n\treadonly runId: string;\n\treadonly kind: SessionTerminationKind;\n\treadonly phase: SessionTerminationPhase;\n\treadonly source: SessionTerminationSource;\n\treadonly message: string;\n\treadonly causeCode: SessionTerminationCauseCode;\n\t/** Stable operator guidance suitable for print, JSON, RPC, and TUI surfaces. */\n\treadonly nextAction: string;\n\treadonly retryable: boolean;\n\treadonly safeToAutoRetry: boolean;\n\treadonly sideEffects: SessionSideEffects;\n\treadonly timestamp: string;\n\treadonly retryAfterMs?: number;\n\treadonly provider?: string;\n\treadonly model?: string;\n\treadonly toolCallId?: string;\n\treadonly toolName?: string;\n\treadonly processSignal?: SessionProcessSignal;\n\treadonly transcriptIssue?: TranscriptTerminationCauseCode;\n}\n\nexport class SessionTerminationError extends Error {\n\treadonly termination: SessionTermination;\n\n\tconstructor(message: string, termination: SessionTermination) {\n\t\tsuper(message);\n\t\tthis.name = \"SessionTerminationError\";\n\t\tthis.termination = termination;\n\t}\n}\n\ninterface Classification {\n\treadonly kind: SessionTerminationKind;\n\treadonly phase: SessionTerminationPhase;\n\treadonly causeCode: SessionTerminationCauseCode;\n\treadonly retryable: boolean;\n\treadonly processSignal?: SessionProcessSignal;\n\treadonly transcriptIssue?: TranscriptTerminationCauseCode;\n}\n\nconst CREDENTIAL_SHAPES = [\n\t/-----BEGIN [A-Z ]*PRIVATE KEY-----/i,\n\t/\\b(?:sk-[A-Za-z0-9_-]{16,}|github_pat_[A-Za-z0-9_]{16,}|gh[pousr]_[A-Za-z0-9]{16,}|xox[baprs]-[A-Za-z0-9-]{16,}|AKIA[A-Z0-9]{16})\\b/,\n\t/\\bBearer\\s+[A-Za-z0-9._~+/-]{8,}={0,2}\\b/i,\n\t/\\beyJ[A-Za-z0-9_-]{8,}\\.[A-Za-z0-9_-]{8,}\\.[A-Za-z0-9_-]{8,}\\b/,\n\t/(?:^|[^A-Za-z0-9])(?:[A-Za-z0-9]+[_-])*(?:authorization|api[-_ ]?key|access[-_ ]?token|token|password|secret(?:[-_ ]?key)?|private[-_ ]?key|cookie)[\"']?\\s*[:=]/i,\n] as const;\n\nconst TOP_LEVEL_KEYS = new Set([\n\t\"sessionId\",\n\t\"runId\",\n\t\"timestamp\",\n\t\"source\",\n\t\"message\",\n\t\"cause\",\n\t\"sideEffects\",\n\t\"retryAfterMs\",\n\t\"provider\",\n\t\"model\",\n\t\"toolCallId\",\n\t\"toolName\",\n]);\nconst PROVIDER_CAUSE_CODES = new Set<ProviderTerminationCauseCode>([\n\t\"abort\",\n\t\"auth\",\n\t\"rate_limit\",\n\t\"network\",\n\t\"protocol\",\n\t\"context_overflow\",\n]);\nconst TOOL_CAUSE_CODES = new Set<ToolTerminationCauseCode>([\"timeout\", \"fatal\"]);\nconst COMPACTION_CAUSE_CODES = new Set<CompactionTerminationCauseCode>([\"aborted\", \"failed\", \"stale\"]);\nconst PERSISTENCE_CAUSE_CODES = new Set<PersistenceTerminationCauseCode>([\n\t\"read_failed\",\n\t\"append_failed\",\n\t\"replace_failed\",\n\t\"fsync_failed\",\n\t\"lock_failed\",\n]);\nconst TRANSCRIPT_CAUSE_CODES = new Set<TranscriptTerminationCauseCode>([\n\t\"missing_result\",\n\t\"duplicate_result\",\n\t\"orphan_result\",\n\t\"duplicate_call_id\",\n\t\"interleaved_non_result\",\n\t\"invalid_jsonl\",\n\t\"invalid_tree\",\n\t\"unsupported_version\",\n\t\"trailing_fragment\",\n]);\nconst PROCESS_SIGNALS = new Set<SessionProcessSignal>([\"SIGINT\", \"SIGTERM\", \"SIGHUP\", \"SIGQUIT\"]);\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction hasOnlyKeys(value: Record<string, unknown>, keys: readonly string[]): boolean {\n\tconst allowed = new Set(keys);\n\treturn Object.keys(value).every((key) => allowed.has(key));\n}\n\nfunction assertCause(cause: unknown): asserts cause is SessionTerminationCause {\n\tif (!isRecord(cause) || typeof cause.area !== \"string\") {\n\t\tthrow new TypeError(\"cause must be a bounded structured termination cause\");\n\t}\n\tconst code = cause.code;\n\tlet valid = false;\n\tswitch (cause.area) {\n\t\tcase \"completed\":\n\t\t\tvalid = hasOnlyKeys(cause, [\"area\"]);\n\t\t\tbreak;\n\t\tcase \"user\":\n\t\t\tvalid = code === \"abort\" && hasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"provider\":\n\t\t\tvalid =\n\t\t\t\ttypeof code === \"string\" &&\n\t\t\t\tPROVIDER_CAUSE_CODES.has(code as ProviderTerminationCauseCode) &&\n\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"tool\":\n\t\t\tvalid =\n\t\t\t\ttypeof code === \"string\" &&\n\t\t\t\tTOOL_CAUSE_CODES.has(code as ToolTerminationCauseCode) &&\n\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"compaction\":\n\t\t\tvalid =\n\t\t\t\ttypeof code === \"string\" &&\n\t\t\t\tCOMPACTION_CAUSE_CODES.has(code as CompactionTerminationCauseCode) &&\n\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"persistence\":\n\t\t\tvalid =\n\t\t\t\ttypeof code === \"string\" &&\n\t\t\t\tPERSISTENCE_CAUSE_CODES.has(code as PersistenceTerminationCauseCode) &&\n\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"process\":\n\t\t\tvalid =\n\t\t\t\t(code === \"crash\" && hasOnlyKeys(cause, [\"area\", \"code\"])) ||\n\t\t\t\t(code === \"signal\" &&\n\t\t\t\t\ttypeof cause.signal === \"string\" &&\n\t\t\t\t\tPROCESS_SIGNALS.has(cause.signal as SessionProcessSignal) &&\n\t\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\", \"signal\"]));\n\t\t\tbreak;\n\t\tcase \"transcript\":\n\t\t\tvalid =\n\t\t\t\ttypeof code === \"string\" &&\n\t\t\t\tTRANSCRIPT_CAUSE_CODES.has(code as TranscriptTerminationCauseCode) &&\n\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"configuration\":\n\t\t\tvalid = code === \"invalid\" && hasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"internal\":\n\t\t\tvalid = code === \"unclassified\" && hasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t}\n\tif (!valid) throw new TypeError(\"cause must be a bounded structured termination cause\");\n}\n\nfunction assertClassifierInput(input: unknown): asserts input is ClassifySessionTerminationInput {\n\tif (!isRecord(input) || Object.keys(input).some((key) => !TOP_LEVEL_KEYS.has(key))) {\n\t\tthrow new TypeError(\"input must contain only bounded structured termination fields\");\n\t}\n\tif (\n\t\ttypeof input.sessionId !== \"string\" ||\n\t\ttypeof input.runId !== \"string\" ||\n\t\ttypeof input.timestamp !== \"string\" ||\n\t\ttypeof input.message !== \"string\" ||\n\t\t(input.source !== \"observed\" && input.source !== \"inferred_on_resume\") ||\n\t\t(input.sideEffects !== \"none\" && input.sideEffects !== \"possible\" && input.sideEffects !== \"confirmed\") ||\n\t\t(input.retryAfterMs !== undefined && typeof input.retryAfterMs !== \"number\") ||\n\t\t(input.provider !== undefined && typeof input.provider !== \"string\") ||\n\t\t(input.model !== undefined && typeof input.model !== \"string\") ||\n\t\t(input.toolCallId !== undefined && typeof input.toolCallId !== \"string\") ||\n\t\t(input.toolName !== undefined && typeof input.toolName !== \"string\")\n\t) {\n\t\tthrow new TypeError(\"input must contain only bounded structured termination fields\");\n\t}\n\tassertCause(input.cause);\n}\n\nfunction assertIdentifier(value: string, name: string, maxLength: number): void {\n\tif (value.length === 0 || value.length > maxLength || /[\\u0000-\\u001f\\u007f]/.test(value)) {\n\t\tthrow new TypeError(`${name} must be non-empty bounded text without C0 or DEL control characters`);\n\t}\n}\n\n/** Validate text at the termination trust boundary without attempting redaction. */\nexport function assertPreRedactedTerminationMessage(message: string): void {\n\tif (message.length === 0 || message.length > MAX_SESSION_TERMINATION_MESSAGE_LENGTH) {\n\t\tthrow new TypeError(\n\t\t\t`message must contain 1-${MAX_SESSION_TERMINATION_MESSAGE_LENGTH} characters of pre-redacted text`,\n\t\t);\n\t}\n\tif (message.includes(\"\\0\")) {\n\t\tthrow new TypeError(\"message must not contain NUL\");\n\t}\n\tif (CREDENTIAL_SHAPES.some((pattern) => pattern.test(message))) {\n\t\tthrow new TypeError(\"message contains a credential-shaped literal; redact it before classification\");\n\t}\n}\n\nfunction assertTimestamp(timestamp: string): void {\n\tconst parsed = new Date(timestamp);\n\tif (!Number.isFinite(parsed.getTime()) || parsed.toISOString() !== timestamp) {\n\t\tthrow new TypeError(\"timestamp must be a canonical ISO-8601 UTC instant\");\n\t}\n}\n\nfunction classifyProvider(code: ProviderTerminationCauseCode): Classification {\n\tswitch (code) {\n\t\tcase \"abort\":\n\t\t\treturn {\n\t\t\t\tkind: \"provider_abort\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.abort\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"auth\":\n\t\t\treturn {\n\t\t\t\tkind: \"provider_auth\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.auth\",\n\t\t\t\tretryable: false,\n\t\t\t};\n\t\tcase \"rate_limit\":\n\t\t\treturn {\n\t\t\t\tkind: \"provider_rate_limit\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.rate_limit\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"network\":\n\t\t\treturn {\n\t\t\t\tkind: \"provider_network\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.network\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"protocol\":\n\t\t\treturn {\n\t\t\t\tkind: \"provider_protocol\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.protocol\",\n\t\t\t\tretryable: false,\n\t\t\t};\n\t\tcase \"context_overflow\":\n\t\t\treturn {\n\t\t\t\tkind: \"context_overflow\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.context_overflow\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t}\n}\n\nfunction classifyCause(cause: SessionTerminationCause, source: SessionTerminationSource): Classification {\n\tswitch (cause.area) {\n\t\tcase \"completed\":\n\t\t\treturn {\n\t\t\t\tkind: \"completed\",\n\t\t\t\tphase: \"completed\",\n\t\t\t\tcauseCode: \"session.completed\",\n\t\t\t\tretryable: false,\n\t\t\t};\n\t\tcase \"user\":\n\t\t\treturn {\n\t\t\t\tkind: \"user_abort\",\n\t\t\t\tphase: \"control\",\n\t\t\t\tcauseCode: \"session.user_abort\",\n\t\t\t\tretryable: false,\n\t\t\t};\n\t\tcase \"provider\":\n\t\t\treturn classifyProvider(cause.code);\n\t\tcase \"tool\":\n\t\t\treturn cause.code === \"timeout\"\n\t\t\t\t? { kind: \"tool_timeout\", phase: \"tool\", causeCode: \"tool.timeout\", retryable: true }\n\t\t\t\t: { kind: \"tool_fatal\", phase: \"tool\", causeCode: \"tool.fatal\", retryable: false };\n\t\tcase \"compaction\":\n\t\t\treturn {\n\t\t\t\tkind: \"compaction\",\n\t\t\t\tphase: \"compaction\",\n\t\t\t\tcauseCode: `compaction.${cause.code}`,\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"persistence\":\n\t\t\treturn {\n\t\t\t\tkind: \"persistence\",\n\t\t\t\tphase: \"persistence\",\n\t\t\t\tcauseCode: `persistence.${cause.code}`,\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"process\":\n\t\t\tif (cause.code === \"signal\") {\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"process_signal\",\n\t\t\t\t\tphase: \"process\",\n\t\t\t\t\tcauseCode: \"process.signal\",\n\t\t\t\t\tretryable: false,\n\t\t\t\t\tprocessSignal: cause.signal,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tkind: \"process_crash\",\n\t\t\t\tphase: \"resume\",\n\t\t\t\tcauseCode: \"process.crash\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"transcript\":\n\t\t\treturn {\n\t\t\t\tkind: \"transcript_invalid\",\n\t\t\t\tphase: source === \"inferred_on_resume\" ? \"resume\" : \"preflight\",\n\t\t\t\tcauseCode: `transcript.${cause.code}`,\n\t\t\t\tretryable: false,\n\t\t\t\ttranscriptIssue: cause.code,\n\t\t\t};\n\t\tcase \"configuration\":\n\t\t\treturn {\n\t\t\t\tkind: \"configuration\",\n\t\t\t\tphase: \"preflight\",\n\t\t\t\tcauseCode: \"configuration.invalid\",\n\t\t\t\tretryable: false,\n\t\t\t};\n\t\tcase \"internal\":\n\t\t\treturn {\n\t\t\t\tkind: \"internal_error\",\n\t\t\t\tphase: \"preflight\",\n\t\t\t\tcauseCode: \"internal.unclassified\",\n\t\t\t\tretryable: false,\n\t\t\t};\n\t}\n}\n\nfunction isSafeToAutoRetry(classification: Classification, input: ClassifySessionTerminationInput): boolean {\n\treturn (\n\t\tclassification.retryable &&\n\t\tinput.source === \"observed\" &&\n\t\tinput.sideEffects === \"none\" &&\n\t\t(classification.kind === \"provider_rate_limit\" || classification.kind === \"provider_network\")\n\t);\n}\n\nfunction nextActionFor(classification: Classification, input: ClassifySessionTerminationInput): string {\n\tswitch (classification.kind) {\n\t\tcase \"completed\":\n\t\t\treturn \"No recovery action is required; continue with the next prompt.\";\n\t\tcase \"user_abort\":\n\t\t\treturn \"Review possible partial side effects, then retry only if intended.\";\n\t\tcase \"provider_abort\":\n\t\t\treturn \"Confirm provider availability, then retry the request.\";\n\t\tcase \"provider_auth\":\n\t\t\treturn `Run /login${input.provider ? ` ${input.provider}` : \"\"} or configure valid credentials, then retry.`;\n\t\tcase \"provider_rate_limit\":\n\t\t\treturn \"Wait for the provider retry window or choose another model, then retry.\";\n\t\tcase \"provider_network\":\n\t\t\treturn \"Check network and provider connectivity, then retry.\";\n\t\tcase \"provider_protocol\":\n\t\t\treturn \"Check provider compatibility and response diagnostics before retrying.\";\n\t\tcase \"context_overflow\":\n\t\t\treturn \"Compact or reduce context, or switch to a larger-context model.\";\n\t\tcase \"tool_timeout\":\n\t\t\treturn \"Inspect possible tool side effects and increase the tool timeout only if safe.\";\n\t\tcase \"tool_fatal\":\n\t\t\treturn \"Inspect the failed tool result and repair its configuration before retrying.\";\n\t\tcase \"compaction\":\n\t\t\treturn \"Retry compaction after resolving the reported barrier or stale transaction.\";\n\t\tcase \"persistence\":\n\t\t\treturn `Run omk session doctor --session ${input.sessionId} before resuming.`;\n\t\tcase \"process_signal\":\n\t\t\treturn \"Review possible partial side effects before resuming the session.\";\n\t\tcase \"process_crash\":\n\t\t\treturn `Run omk session doctor --session ${input.sessionId} and review partial side effects.`;\n\t\tcase \"transcript_invalid\":\n\t\t\treturn `Run omk session doctor --session ${input.sessionId}; do not resume until integrity passes.`;\n\t\tcase \"configuration\":\n\t\t\treturn \"Correct the provider, model, tool, or session configuration and retry.\";\n\t\tcase \"internal_error\":\n\t\t\treturn `Inspect run ${input.runId} diagnostics and the run journal before retrying.`;\n\t}\n}\n\n/** Concise actionable rendering shared by non-JSON and TUI surfaces. */\nexport function formatSessionTermination(termination: SessionTermination): string {\n\tconst route =\n\t\ttermination.provider || termination.model\n\t\t\t? `${termination.provider ?? \"unknown\"}/${termination.model ?? \"unknown\"}`\n\t\t\t: \"n/a\";\n\treturn [\n\t\t`kind=${termination.kind}`,\n\t\t`provider/model=${route}`,\n\t\t`retryable=${termination.retryable}`,\n\t\t`cause=${termination.causeCode}`,\n\t\t`message=${termination.message}`,\n\t\t`run=${termination.runId}`,\n\t\t`next=${termination.nextAction}`,\n\t].join(\" \");\n}\n\n/**\n * Classify a bounded, structured termination cause. This intentionally accepts\n * no raw Error value, stack, provider body, or arbitrary cause code.\n */\nexport function classifySessionTermination(input: ClassifySessionTerminationInput): SessionTermination {\n\tassertClassifierInput(input);\n\tassertIdentifier(input.sessionId, \"sessionId\", 128);\n\tassertIdentifier(input.runId, \"runId\", 128);\n\tassertTimestamp(input.timestamp);\n\tassertPreRedactedTerminationMessage(input.message);\n\tif (input.provider !== undefined) assertIdentifier(input.provider, \"provider\", 128);\n\tif (input.model !== undefined) assertIdentifier(input.model, \"model\", 256);\n\tif (input.toolCallId !== undefined) assertIdentifier(input.toolCallId, \"toolCallId\", 512);\n\tif (input.toolName !== undefined) assertIdentifier(input.toolName, \"toolName\", 128);\n\tif (input.retryAfterMs !== undefined && (!Number.isSafeInteger(input.retryAfterMs) || input.retryAfterMs < 0)) {\n\t\tthrow new TypeError(\"retryAfterMs must be a non-negative safe integer\");\n\t}\n\tif (input.cause.area === \"process\" && input.cause.code === \"crash\" && input.source !== \"inferred_on_resume\") {\n\t\tthrow new TypeError(\"process crashes may only be classified as inferred_on_resume\");\n\t}\n\tif (input.cause.area === \"process\" && input.cause.code === \"signal\" && input.source !== \"observed\") {\n\t\tthrow new TypeError(\"process signals must be observed\");\n\t}\n\n\tconst classification = classifyCause(input.cause, input.source);\n\treturn Object.freeze({\n\t\tschemaVersion: SESSION_TERMINATION_SCHEMA_VERSION,\n\t\tsessionId: input.sessionId,\n\t\trunId: input.runId,\n\t\tkind: classification.kind,\n\t\tphase: classification.phase,\n\t\tsource: input.source,\n\t\tmessage: input.message,\n\t\tcauseCode: classification.causeCode,\n\t\tnextAction: nextActionFor(classification, input),\n\t\tretryable: classification.retryable,\n\t\tsafeToAutoRetry: isSafeToAutoRetry(classification, input),\n\t\tsideEffects: input.sideEffects,\n\t\ttimestamp: input.timestamp,\n\t\t...(input.retryAfterMs === undefined ? {} : { retryAfterMs: input.retryAfterMs }),\n\t\t...(input.provider === undefined ? {} : { provider: input.provider }),\n\t\t...(input.model === undefined ? {} : { model: input.model }),\n\t\t...(input.toolCallId === undefined ? {} : { toolCallId: input.toolCallId }),\n\t\t...(input.toolName === undefined ? {} : { toolName: input.toolName }),\n\t\t...(classification.processSignal === undefined ? {} : { processSignal: classification.processSignal }),\n\t\t...(classification.transcriptIssue === undefined ? {} : { transcriptIssue: classification.transcriptIssue }),\n\t});\n}\n"]}
1
+ {"version":3,"file":"session-termination.d.ts","sourceRoot":"","sources":["../../src/core/session-termination.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kCAAkC,GAAa,CAAC;AAC7D,eAAO,MAAM,sCAAsC,MAAM,CAAC;AAE1D;;;;GAIG;AACH,eAAO,MAAM,+BAA+B,wUAmBlC,CAAC;AAEX,MAAM,MAAM,sBAAsB,GAAG,CAAC,OAAO,+BAA+B,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtF,MAAM,MAAM,uBAAuB,GAChC,WAAW,GACX,SAAS,GACT,WAAW,GACX,UAAU,GACV,MAAM,GACN,YAAY,GACZ,aAAa,GACb,SAAS,GACT,QAAQ,CAAC;AAEZ,MAAM,MAAM,wBAAwB,GAAG,UAAU,GAAG,oBAAoB,CAAC;AACzE,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,UAAU,GAAG,WAAW,CAAC;AACnE,MAAM,MAAM,oBAAoB,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE/E,MAAM,MAAM,4BAA4B,GACrC,OAAO,GACP,MAAM,GACN,YAAY,GACZ,SAAS,GACT,UAAU,GACV,SAAS,GACT,kBAAkB,CAAC;AACtB,MAAM,MAAM,wBAAwB,GAAG,SAAS,GAAG,OAAO,CAAC;AAC3D,MAAM,MAAM,8BAA8B,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;AAC5E,MAAM,MAAM,+BAA+B,GACxC,aAAa,GACb,eAAe,GACf,gBAAgB,GAChB,cAAc,GACd,aAAa,CAAC;AACjB,MAAM,MAAM,8BAA8B,GACvC,gBAAgB,GAChB,kBAAkB,GAClB,eAAe,GACf,mBAAmB,GACnB,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AAE,2BAA2B,CAAC;IAChD,gFAAgF;IAChF,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;IAClC,QAAQ,CAAC,WAAW,EAAE,kBAAkB,CAAC;IACzC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,aAAa,CAAC,EAAE,oBAAoB,CAAC;IAC9C,QAAQ,CAAC,eAAe,CAAC,EAAE,8BAA8B,CAAC;CAC1D;AAED,qBAAa,uBAAwB,SAAQ,KAAK;IACjD,QAAQ,CAAC,WAAW,EAAE,kBAAkB,CAAC;IAEzC,YAAY,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,kBAAkB,EAI3D;CACD;AAkKD,oFAAoF;AACpF,wBAAgB,mCAAmC,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAYzE;AAqMD,wEAAwE;AACxE,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,kBAAkB,GAAG,MAAM,CAchF;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,+BAA+B,GAAG,kBAAkB,CA2CrG","sourcesContent":["export const SESSION_TERMINATION_SCHEMA_VERSION = 1 as const;\nexport const MAX_SESSION_TERMINATION_MESSAGE_LENGTH = 512;\n\n/**\n * Canonical list of termination kinds. The run-journal validator derives its\n * runtime bounds from this tuple so a newly added kind can never crash\n * journaling with \"termination kind is out of bounds\" again.\n */\nexport const SESSION_TERMINATION_KIND_VALUES = [\n\t\"completed\",\n\t\"user_abort\",\n\t\"provider_abort\",\n\t\"provider_auth\",\n\t\"provider_rate_limit\",\n\t\"provider_network\",\n\t\"provider_protocol\",\n\t\"provider_refusal\",\n\t\"context_overflow\",\n\t\"transcript_invalid\",\n\t\"tool_timeout\",\n\t\"tool_fatal\",\n\t\"compaction\",\n\t\"persistence\",\n\t\"process_signal\",\n\t\"process_crash\",\n\t\"configuration\",\n\t\"internal_error\",\n] as const;\n\nexport type SessionTerminationKind = (typeof SESSION_TERMINATION_KIND_VALUES)[number];\n\nexport type SessionTerminationPhase =\n\t| \"completed\"\n\t| \"control\"\n\t| \"preflight\"\n\t| \"provider\"\n\t| \"tool\"\n\t| \"compaction\"\n\t| \"persistence\"\n\t| \"process\"\n\t| \"resume\";\n\nexport type SessionTerminationSource = \"observed\" | \"inferred_on_resume\";\nexport type SessionSideEffects = \"none\" | \"possible\" | \"confirmed\";\nexport type SessionProcessSignal = \"SIGINT\" | \"SIGTERM\" | \"SIGHUP\" | \"SIGQUIT\";\n\nexport type ProviderTerminationCauseCode =\n\t| \"abort\"\n\t| \"auth\"\n\t| \"rate_limit\"\n\t| \"network\"\n\t| \"protocol\"\n\t| \"refusal\"\n\t| \"context_overflow\";\nexport type ToolTerminationCauseCode = \"timeout\" | \"fatal\";\nexport type CompactionTerminationCauseCode = \"aborted\" | \"failed\" | \"stale\";\nexport type PersistenceTerminationCauseCode =\n\t| \"read_failed\"\n\t| \"append_failed\"\n\t| \"replace_failed\"\n\t| \"fsync_failed\"\n\t| \"lock_failed\";\nexport type TranscriptTerminationCauseCode =\n\t| \"missing_result\"\n\t| \"duplicate_result\"\n\t| \"orphan_result\"\n\t| \"duplicate_call_id\"\n\t| \"interleaved_non_result\"\n\t| \"invalid_jsonl\"\n\t| \"invalid_tree\"\n\t| \"unsupported_version\"\n\t| \"trailing_fragment\";\nexport type SessionTerminationCauseCode =\n\t| \"session.completed\"\n\t| \"session.user_abort\"\n\t| `provider.${ProviderTerminationCauseCode}`\n\t| `tool.${ToolTerminationCauseCode}`\n\t| `compaction.${CompactionTerminationCauseCode}`\n\t| `persistence.${PersistenceTerminationCauseCode}`\n\t| \"process.signal\"\n\t| \"process.crash\"\n\t| `transcript.${TranscriptTerminationCauseCode}`\n\t| \"configuration.invalid\"\n\t| \"internal.unclassified\";\n\nexport type SessionTerminationCause =\n\t| { readonly area: \"completed\" }\n\t| { readonly area: \"user\"; readonly code: \"abort\" }\n\t| { readonly area: \"provider\"; readonly code: ProviderTerminationCauseCode }\n\t| { readonly area: \"tool\"; readonly code: ToolTerminationCauseCode }\n\t| { readonly area: \"compaction\"; readonly code: CompactionTerminationCauseCode }\n\t| { readonly area: \"persistence\"; readonly code: PersistenceTerminationCauseCode }\n\t| { readonly area: \"process\"; readonly code: \"signal\"; readonly signal: SessionProcessSignal }\n\t| { readonly area: \"process\"; readonly code: \"crash\" }\n\t| { readonly area: \"transcript\"; readonly code: TranscriptTerminationCauseCode }\n\t| { readonly area: \"configuration\"; readonly code: \"invalid\" }\n\t| { readonly area: \"internal\"; readonly code: \"unclassified\" };\n\nexport interface ClassifySessionTerminationInput {\n\treadonly sessionId: string;\n\treadonly runId: string;\n\t/** Deterministic caller-provided ISO-8601 timestamp. */\n\treadonly timestamp: string;\n\treadonly source: SessionTerminationSource;\n\t/** Caller-supplied, pre-redacted diagnostic text. */\n\treadonly message: string;\n\treadonly cause: SessionTerminationCause;\n\treadonly sideEffects: SessionSideEffects;\n\treadonly retryAfterMs?: number;\n\treadonly provider?: string;\n\treadonly model?: string;\n\treadonly toolCallId?: string;\n\treadonly toolName?: string;\n}\n\nexport interface SessionTermination {\n\treadonly schemaVersion: typeof SESSION_TERMINATION_SCHEMA_VERSION;\n\treadonly sessionId: string;\n\treadonly runId: string;\n\treadonly kind: SessionTerminationKind;\n\treadonly phase: SessionTerminationPhase;\n\treadonly source: SessionTerminationSource;\n\treadonly message: string;\n\treadonly causeCode: SessionTerminationCauseCode;\n\t/** Stable operator guidance suitable for print, JSON, RPC, and TUI surfaces. */\n\treadonly nextAction: string;\n\treadonly retryable: boolean;\n\treadonly safeToAutoRetry: boolean;\n\treadonly sideEffects: SessionSideEffects;\n\treadonly timestamp: string;\n\treadonly retryAfterMs?: number;\n\treadonly provider?: string;\n\treadonly model?: string;\n\treadonly toolCallId?: string;\n\treadonly toolName?: string;\n\treadonly processSignal?: SessionProcessSignal;\n\treadonly transcriptIssue?: TranscriptTerminationCauseCode;\n}\n\nexport class SessionTerminationError extends Error {\n\treadonly termination: SessionTermination;\n\n\tconstructor(message: string, termination: SessionTermination) {\n\t\tsuper(message);\n\t\tthis.name = \"SessionTerminationError\";\n\t\tthis.termination = termination;\n\t}\n}\n\ninterface Classification {\n\treadonly kind: SessionTerminationKind;\n\treadonly phase: SessionTerminationPhase;\n\treadonly causeCode: SessionTerminationCauseCode;\n\treadonly retryable: boolean;\n\treadonly processSignal?: SessionProcessSignal;\n\treadonly transcriptIssue?: TranscriptTerminationCauseCode;\n}\n\nconst CREDENTIAL_SHAPES = [\n\t/-----BEGIN [A-Z ]*PRIVATE KEY-----/i,\n\t/\\b(?:sk-[A-Za-z0-9_-]{16,}|github_pat_[A-Za-z0-9_]{16,}|gh[pousr]_[A-Za-z0-9]{16,}|xox[baprs]-[A-Za-z0-9-]{16,}|AKIA[A-Z0-9]{16})\\b/,\n\t/\\bBearer\\s+[A-Za-z0-9._~+/-]{8,}={0,2}\\b/i,\n\t/\\beyJ[A-Za-z0-9_-]{8,}\\.[A-Za-z0-9_-]{8,}\\.[A-Za-z0-9_-]{8,}\\b/,\n\t/(?:^|[^A-Za-z0-9])(?:[A-Za-z0-9]+[_-])*(?:authorization|api[-_ ]?key|access[-_ ]?token|token|password|secret(?:[-_ ]?key)?|private[-_ ]?key|cookie)[\"']?\\s*[:=]/i,\n] as const;\n\nconst TOP_LEVEL_KEYS = new Set([\n\t\"sessionId\",\n\t\"runId\",\n\t\"timestamp\",\n\t\"source\",\n\t\"message\",\n\t\"cause\",\n\t\"sideEffects\",\n\t\"retryAfterMs\",\n\t\"provider\",\n\t\"model\",\n\t\"toolCallId\",\n\t\"toolName\",\n]);\nconst PROVIDER_CAUSE_CODES = new Set<ProviderTerminationCauseCode>([\n\t\"abort\",\n\t\"auth\",\n\t\"rate_limit\",\n\t\"network\",\n\t\"protocol\",\n\t\"refusal\",\n\t\"context_overflow\",\n]);\nconst TOOL_CAUSE_CODES = new Set<ToolTerminationCauseCode>([\"timeout\", \"fatal\"]);\nconst COMPACTION_CAUSE_CODES = new Set<CompactionTerminationCauseCode>([\"aborted\", \"failed\", \"stale\"]);\nconst PERSISTENCE_CAUSE_CODES = new Set<PersistenceTerminationCauseCode>([\n\t\"read_failed\",\n\t\"append_failed\",\n\t\"replace_failed\",\n\t\"fsync_failed\",\n\t\"lock_failed\",\n]);\nconst TRANSCRIPT_CAUSE_CODES = new Set<TranscriptTerminationCauseCode>([\n\t\"missing_result\",\n\t\"duplicate_result\",\n\t\"orphan_result\",\n\t\"duplicate_call_id\",\n\t\"interleaved_non_result\",\n\t\"invalid_jsonl\",\n\t\"invalid_tree\",\n\t\"unsupported_version\",\n\t\"trailing_fragment\",\n]);\nconst PROCESS_SIGNALS = new Set<SessionProcessSignal>([\"SIGINT\", \"SIGTERM\", \"SIGHUP\", \"SIGQUIT\"]);\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction hasOnlyKeys(value: Record<string, unknown>, keys: readonly string[]): boolean {\n\tconst allowed = new Set(keys);\n\treturn Object.keys(value).every((key) => allowed.has(key));\n}\n\nfunction assertCause(cause: unknown): asserts cause is SessionTerminationCause {\n\tif (!isRecord(cause) || typeof cause.area !== \"string\") {\n\t\tthrow new TypeError(\"cause must be a bounded structured termination cause\");\n\t}\n\tconst code = cause.code;\n\tlet valid = false;\n\tswitch (cause.area) {\n\t\tcase \"completed\":\n\t\t\tvalid = hasOnlyKeys(cause, [\"area\"]);\n\t\t\tbreak;\n\t\tcase \"user\":\n\t\t\tvalid = code === \"abort\" && hasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"provider\":\n\t\t\tvalid =\n\t\t\t\ttypeof code === \"string\" &&\n\t\t\t\tPROVIDER_CAUSE_CODES.has(code as ProviderTerminationCauseCode) &&\n\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"tool\":\n\t\t\tvalid =\n\t\t\t\ttypeof code === \"string\" &&\n\t\t\t\tTOOL_CAUSE_CODES.has(code as ToolTerminationCauseCode) &&\n\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"compaction\":\n\t\t\tvalid =\n\t\t\t\ttypeof code === \"string\" &&\n\t\t\t\tCOMPACTION_CAUSE_CODES.has(code as CompactionTerminationCauseCode) &&\n\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"persistence\":\n\t\t\tvalid =\n\t\t\t\ttypeof code === \"string\" &&\n\t\t\t\tPERSISTENCE_CAUSE_CODES.has(code as PersistenceTerminationCauseCode) &&\n\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"process\":\n\t\t\tvalid =\n\t\t\t\t(code === \"crash\" && hasOnlyKeys(cause, [\"area\", \"code\"])) ||\n\t\t\t\t(code === \"signal\" &&\n\t\t\t\t\ttypeof cause.signal === \"string\" &&\n\t\t\t\t\tPROCESS_SIGNALS.has(cause.signal as SessionProcessSignal) &&\n\t\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\", \"signal\"]));\n\t\t\tbreak;\n\t\tcase \"transcript\":\n\t\t\tvalid =\n\t\t\t\ttypeof code === \"string\" &&\n\t\t\t\tTRANSCRIPT_CAUSE_CODES.has(code as TranscriptTerminationCauseCode) &&\n\t\t\t\thasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"configuration\":\n\t\t\tvalid = code === \"invalid\" && hasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t\tcase \"internal\":\n\t\t\tvalid = code === \"unclassified\" && hasOnlyKeys(cause, [\"area\", \"code\"]);\n\t\t\tbreak;\n\t}\n\tif (!valid) throw new TypeError(\"cause must be a bounded structured termination cause\");\n}\n\nfunction assertClassifierInput(input: unknown): asserts input is ClassifySessionTerminationInput {\n\tif (!isRecord(input) || Object.keys(input).some((key) => !TOP_LEVEL_KEYS.has(key))) {\n\t\tthrow new TypeError(\"input must contain only bounded structured termination fields\");\n\t}\n\tif (\n\t\ttypeof input.sessionId !== \"string\" ||\n\t\ttypeof input.runId !== \"string\" ||\n\t\ttypeof input.timestamp !== \"string\" ||\n\t\ttypeof input.message !== \"string\" ||\n\t\t(input.source !== \"observed\" && input.source !== \"inferred_on_resume\") ||\n\t\t(input.sideEffects !== \"none\" && input.sideEffects !== \"possible\" && input.sideEffects !== \"confirmed\") ||\n\t\t(input.retryAfterMs !== undefined && typeof input.retryAfterMs !== \"number\") ||\n\t\t(input.provider !== undefined && typeof input.provider !== \"string\") ||\n\t\t(input.model !== undefined && typeof input.model !== \"string\") ||\n\t\t(input.toolCallId !== undefined && typeof input.toolCallId !== \"string\") ||\n\t\t(input.toolName !== undefined && typeof input.toolName !== \"string\")\n\t) {\n\t\tthrow new TypeError(\"input must contain only bounded structured termination fields\");\n\t}\n\tassertCause(input.cause);\n}\n\nfunction assertIdentifier(value: string, name: string, maxLength: number): void {\n\tif (value.length === 0 || value.length > maxLength || /[\\u0000-\\u001f\\u007f]/.test(value)) {\n\t\tthrow new TypeError(`${name} must be non-empty bounded text without C0 or DEL control characters`);\n\t}\n}\n\n/** Validate text at the termination trust boundary without attempting redaction. */\nexport function assertPreRedactedTerminationMessage(message: string): void {\n\tif (message.length === 0 || message.length > MAX_SESSION_TERMINATION_MESSAGE_LENGTH) {\n\t\tthrow new TypeError(\n\t\t\t`message must contain 1-${MAX_SESSION_TERMINATION_MESSAGE_LENGTH} characters of pre-redacted text`,\n\t\t);\n\t}\n\tif (message.includes(\"\\0\")) {\n\t\tthrow new TypeError(\"message must not contain NUL\");\n\t}\n\tif (CREDENTIAL_SHAPES.some((pattern) => pattern.test(message))) {\n\t\tthrow new TypeError(\"message contains a credential-shaped literal; redact it before classification\");\n\t}\n}\n\nfunction assertTimestamp(timestamp: string): void {\n\tconst parsed = new Date(timestamp);\n\tif (!Number.isFinite(parsed.getTime()) || parsed.toISOString() !== timestamp) {\n\t\tthrow new TypeError(\"timestamp must be a canonical ISO-8601 UTC instant\");\n\t}\n}\n\nfunction classifyProvider(code: ProviderTerminationCauseCode): Classification {\n\tswitch (code) {\n\t\tcase \"abort\":\n\t\t\treturn {\n\t\t\t\tkind: \"provider_abort\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.abort\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"auth\":\n\t\t\treturn {\n\t\t\t\tkind: \"provider_auth\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.auth\",\n\t\t\t\tretryable: false,\n\t\t\t};\n\t\tcase \"rate_limit\":\n\t\t\treturn {\n\t\t\t\tkind: \"provider_rate_limit\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.rate_limit\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"network\":\n\t\t\treturn {\n\t\t\t\tkind: \"provider_network\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.network\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"protocol\":\n\t\t\t// Many \"protocol\" stops are sticky transcript shape bugs (orphan tool_call_id)\n\t\t\t// that succeed after transform-messages sanitizes and the turn is retried.\n\t\t\t// Mark retryable so auto-retry can heal; safeToAutoRetry stays false (needs sanitize path).\n\t\t\treturn {\n\t\t\t\tkind: \"provider_protocol\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.protocol\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"context_overflow\":\n\t\t\treturn {\n\t\t\t\tkind: \"context_overflow\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.context_overflow\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"refusal\":\n\t\t\treturn {\n\t\t\t\tkind: \"provider_refusal\",\n\t\t\t\tphase: \"provider\",\n\t\t\t\tcauseCode: \"provider.refusal\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t}\n}\n\nfunction classifyCause(cause: SessionTerminationCause, source: SessionTerminationSource): Classification {\n\tswitch (cause.area) {\n\t\tcase \"completed\":\n\t\t\treturn {\n\t\t\t\tkind: \"completed\",\n\t\t\t\tphase: \"completed\",\n\t\t\t\tcauseCode: \"session.completed\",\n\t\t\t\tretryable: false,\n\t\t\t};\n\t\tcase \"user\":\n\t\t\treturn {\n\t\t\t\tkind: \"user_abort\",\n\t\t\t\tphase: \"control\",\n\t\t\t\tcauseCode: \"session.user_abort\",\n\t\t\t\tretryable: false,\n\t\t\t};\n\t\tcase \"provider\":\n\t\t\treturn classifyProvider(cause.code);\n\t\tcase \"tool\":\n\t\t\treturn cause.code === \"timeout\"\n\t\t\t\t? { kind: \"tool_timeout\", phase: \"tool\", causeCode: \"tool.timeout\", retryable: true }\n\t\t\t\t: { kind: \"tool_fatal\", phase: \"tool\", causeCode: \"tool.fatal\", retryable: false };\n\t\tcase \"compaction\":\n\t\t\treturn {\n\t\t\t\tkind: \"compaction\",\n\t\t\t\tphase: \"compaction\",\n\t\t\t\tcauseCode: `compaction.${cause.code}`,\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"persistence\":\n\t\t\treturn {\n\t\t\t\tkind: \"persistence\",\n\t\t\t\tphase: \"persistence\",\n\t\t\t\tcauseCode: `persistence.${cause.code}`,\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"process\":\n\t\t\tif (cause.code === \"signal\") {\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"process_signal\",\n\t\t\t\t\tphase: \"process\",\n\t\t\t\t\tcauseCode: \"process.signal\",\n\t\t\t\t\tretryable: false,\n\t\t\t\t\tprocessSignal: cause.signal,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tkind: \"process_crash\",\n\t\t\t\tphase: \"resume\",\n\t\t\t\tcauseCode: \"process.crash\",\n\t\t\t\tretryable: true,\n\t\t\t};\n\t\tcase \"transcript\":\n\t\t\treturn {\n\t\t\t\tkind: \"transcript_invalid\",\n\t\t\t\tphase: source === \"inferred_on_resume\" ? \"resume\" : \"preflight\",\n\t\t\t\tcauseCode: `transcript.${cause.code}`,\n\t\t\t\tretryable: false,\n\t\t\t\ttranscriptIssue: cause.code,\n\t\t\t};\n\t\tcase \"configuration\":\n\t\t\treturn {\n\t\t\t\tkind: \"configuration\",\n\t\t\t\tphase: \"preflight\",\n\t\t\t\tcauseCode: \"configuration.invalid\",\n\t\t\t\tretryable: false,\n\t\t\t};\n\t\tcase \"internal\":\n\t\t\treturn {\n\t\t\t\tkind: \"internal_error\",\n\t\t\t\tphase: \"preflight\",\n\t\t\t\tcauseCode: \"internal.unclassified\",\n\t\t\t\tretryable: false,\n\t\t\t};\n\t}\n}\n\nfunction isSafeToAutoRetry(classification: Classification, input: ClassifySessionTerminationInput): boolean {\n\t// provider_refusal: Fable/Claude often false-positive on benign turns. Safe to auto-retry once\n\t// when no tool side effects occurred (same class of recovery as rate_limit/network).\n\treturn (\n\t\tclassification.retryable &&\n\t\tinput.source === \"observed\" &&\n\t\tinput.sideEffects === \"none\" &&\n\t\t(classification.kind === \"provider_rate_limit\" ||\n\t\t\tclassification.kind === \"provider_network\" ||\n\t\t\tclassification.kind === \"provider_refusal\")\n\t);\n}\n\nfunction nextActionFor(classification: Classification, input: ClassifySessionTerminationInput): string {\n\tswitch (classification.kind) {\n\t\tcase \"completed\":\n\t\t\treturn \"No recovery action is required; continue with the next prompt.\";\n\t\tcase \"user_abort\":\n\t\t\treturn \"Review possible partial side effects, then retry only if intended.\";\n\t\tcase \"provider_abort\":\n\t\t\treturn \"Confirm provider availability, then retry the request.\";\n\t\tcase \"provider_auth\":\n\t\t\treturn `Run /login${input.provider ? ` ${input.provider}` : \"\"} or configure valid credentials, then retry.`;\n\t\tcase \"provider_rate_limit\":\n\t\t\treturn \"Wait for the provider retry window or choose another model, then retry.\";\n\t\tcase \"provider_network\":\n\t\t\treturn \"Check network and provider connectivity, then retry.\";\n\t\tcase \"provider_protocol\":\n\t\t\treturn \"Often an orphan tool_call_id / sticky transcript after a dropped error turn — auto-retry after sanitize, or /new session if it persists.\";\n\t\tcase \"provider_refusal\":\n\t\t\treturn \"Model declined this turn (content/safety stop). Usually a false positive on Fable/Claude — auto-retry once, or switch model (k3/grok-4.5/deepseek) / rephrase as a pure coding task.\";\n\t\tcase \"context_overflow\":\n\t\t\treturn \"Compact or reduce context, or switch to a larger-context model.\";\n\t\tcase \"tool_timeout\":\n\t\t\treturn \"Inspect possible tool side effects and increase the tool timeout only if safe.\";\n\t\tcase \"tool_fatal\":\n\t\t\treturn \"Inspect the failed tool result and repair its configuration before retrying.\";\n\t\tcase \"compaction\":\n\t\t\treturn \"Retry compaction after resolving the reported barrier or stale transaction.\";\n\t\tcase \"persistence\":\n\t\t\treturn `Run omk session doctor --session ${input.sessionId} before resuming.`;\n\t\tcase \"process_signal\":\n\t\t\treturn \"Review possible partial side effects before resuming the session.\";\n\t\tcase \"process_crash\":\n\t\t\treturn `Run omk session doctor --session ${input.sessionId} and review partial side effects.`;\n\t\tcase \"transcript_invalid\":\n\t\t\treturn `Run omk session doctor --session ${input.sessionId}; do not resume until integrity passes.`;\n\t\tcase \"configuration\":\n\t\t\treturn \"Correct the provider, model, tool, or session configuration and retry.\";\n\t\tcase \"internal_error\":\n\t\t\treturn `Inspect run ${input.runId} diagnostics and the run journal before retrying.`;\n\t}\n}\n\n/** Concise actionable rendering shared by non-JSON and TUI surfaces. */\nexport function formatSessionTermination(termination: SessionTermination): string {\n\tconst route =\n\t\ttermination.provider || termination.model\n\t\t\t? `${termination.provider ?? \"unknown\"}/${termination.model ?? \"unknown\"}`\n\t\t\t: \"n/a\";\n\treturn [\n\t\t`kind=${termination.kind}`,\n\t\t`provider/model=${route}`,\n\t\t`retryable=${termination.retryable}`,\n\t\t`cause=${termination.causeCode}`,\n\t\t`message=${termination.message}`,\n\t\t`run=${termination.runId}`,\n\t\t`next=${termination.nextAction}`,\n\t].join(\" \");\n}\n\n/**\n * Classify a bounded, structured termination cause. This intentionally accepts\n * no raw Error value, stack, provider body, or arbitrary cause code.\n */\nexport function classifySessionTermination(input: ClassifySessionTerminationInput): SessionTermination {\n\tassertClassifierInput(input);\n\tassertIdentifier(input.sessionId, \"sessionId\", 128);\n\tassertIdentifier(input.runId, \"runId\", 128);\n\tassertTimestamp(input.timestamp);\n\tassertPreRedactedTerminationMessage(input.message);\n\tif (input.provider !== undefined) assertIdentifier(input.provider, \"provider\", 128);\n\tif (input.model !== undefined) assertIdentifier(input.model, \"model\", 256);\n\tif (input.toolCallId !== undefined) assertIdentifier(input.toolCallId, \"toolCallId\", 512);\n\tif (input.toolName !== undefined) assertIdentifier(input.toolName, \"toolName\", 128);\n\tif (input.retryAfterMs !== undefined && (!Number.isSafeInteger(input.retryAfterMs) || input.retryAfterMs < 0)) {\n\t\tthrow new TypeError(\"retryAfterMs must be a non-negative safe integer\");\n\t}\n\tif (input.cause.area === \"process\" && input.cause.code === \"crash\" && input.source !== \"inferred_on_resume\") {\n\t\tthrow new TypeError(\"process crashes may only be classified as inferred_on_resume\");\n\t}\n\tif (input.cause.area === \"process\" && input.cause.code === \"signal\" && input.source !== \"observed\") {\n\t\tthrow new TypeError(\"process signals must be observed\");\n\t}\n\n\tconst classification = classifyCause(input.cause, input.source);\n\treturn Object.freeze({\n\t\tschemaVersion: SESSION_TERMINATION_SCHEMA_VERSION,\n\t\tsessionId: input.sessionId,\n\t\trunId: input.runId,\n\t\tkind: classification.kind,\n\t\tphase: classification.phase,\n\t\tsource: input.source,\n\t\tmessage: input.message,\n\t\tcauseCode: classification.causeCode,\n\t\tnextAction: nextActionFor(classification, input),\n\t\tretryable: classification.retryable,\n\t\tsafeToAutoRetry: isSafeToAutoRetry(classification, input),\n\t\tsideEffects: input.sideEffects,\n\t\ttimestamp: input.timestamp,\n\t\t...(input.retryAfterMs === undefined ? {} : { retryAfterMs: input.retryAfterMs }),\n\t\t...(input.provider === undefined ? {} : { provider: input.provider }),\n\t\t...(input.model === undefined ? {} : { model: input.model }),\n\t\t...(input.toolCallId === undefined ? {} : { toolCallId: input.toolCallId }),\n\t\t...(input.toolName === undefined ? {} : { toolName: input.toolName }),\n\t\t...(classification.processSignal === undefined ? {} : { processSignal: classification.processSignal }),\n\t\t...(classification.transcriptIssue === undefined ? {} : { transcriptIssue: classification.transcriptIssue }),\n\t});\n}\n"]}