open-multi-agent-kit 0.95.2 → 0.96.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.
- package/CHANGELOG.md +20 -0
- package/README.md +15 -0
- package/dist/approvals/approval-receipt-store.d.ts.map +1 -1
- package/dist/approvals/approval-receipt-store.js +25 -0
- package/dist/approvals/approval-receipt-store.js.map +1 -1
- package/dist/core/agent-session.d.ts +2 -2
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +41 -17
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/provider-resilience.d.ts +7 -0
- package/dist/core/provider-resilience.d.ts.map +1 -1
- package/dist/core/provider-resilience.js +11 -0
- package/dist/core/provider-resilience.js.map +1 -1
- package/dist/core/subagent-orchestration.d.ts.map +1 -1
- package/dist/core/subagent-orchestration.js +4 -2
- package/dist/core/subagent-orchestration.js.map +1 -1
- package/dist/core/tools/diagnostics.d.ts.map +1 -1
- package/dist/core/tools/diagnostics.js +8 -2
- package/dist/core/tools/diagnostics.js.map +1 -1
- package/dist/guardrails/evidence-protocol.d.ts +10 -0
- package/dist/guardrails/evidence-protocol.d.ts.map +1 -0
- package/dist/guardrails/evidence-protocol.js +34 -0
- package/dist/guardrails/evidence-protocol.js.map +1 -0
- package/dist/guardrails/evidence-system.d.ts +3 -1
- package/dist/guardrails/evidence-system.d.ts.map +1 -1
- package/dist/guardrails/evidence-system.js +22 -14
- package/dist/guardrails/evidence-system.js.map +1 -1
- package/dist/guardrails/replay-ledger-lock-owner.d.ts.map +1 -1
- package/dist/guardrails/replay-ledger-lock-owner.js +3 -1
- package/dist/guardrails/replay-ledger-lock-owner.js.map +1 -1
- package/dist/guardrails/replay-payload-hash.d.ts +6 -0
- package/dist/guardrails/replay-payload-hash.d.ts.map +1 -0
- package/dist/guardrails/replay-payload-hash.js +24 -0
- package/dist/guardrails/replay-payload-hash.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/types/evidence.d.ts +11 -3
- package/dist/types/evidence.d.ts.map +1 -1
- package/dist/types/evidence.js.map +1 -1
- package/docs/book-to-skill.md +79 -0
- package/docs/compaction.md +10 -0
- package/docs/docs.json +8 -0
- package/docs/index.md +3 -0
- package/docs/models.md +12 -0
- package/docs/provider-resilience.md +37 -56
- package/docs/providers.md +4 -0
- package/docs/run-protocol.md +72 -0
- package/docs/sdk.md +15 -2
- package/docs/sessions.md +6 -0
- package/docs/settings.md +2 -0
- package/docs/skills.md +9 -1
- package/docs/usage.md +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +37 -15
- package/package.json +8 -5
- package/dist/core/context-budget-compressors.d.ts +0 -50
- package/dist/core/context-budget-compressors.d.ts.map +0 -1
- package/dist/core/context-budget-compressors.js +0 -166
- package/dist/core/context-budget-compressors.js.map +0 -1
- package/dist/core/extensions/loader.js.bak-sharedjiti-20260812-111246 +0 -553
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evidence-system.js","sourceRoot":"","sources":["../../src/guardrails/evidence-system.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAe1C,OAAO,EAAE,uBAA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tF,EAAE,CACF,CAAC;QAEF,IAAI,SAAS,CAAC,UAAU,EAAE,CAAC;YAC1B,KAAK,CAAC,IAAI,CAAC,mBAAmB,SAAS,CAAC,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;QAC3D,CAAC;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAAA,CACxB;IAED,KAAK,CAAC,QAAsB,EAAE,SAA0B,EAAU;QACjE,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QAClD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,YAAY,CAAC,CAAC;QAC9E,SAAS,CAAC,IAAI,CAAC,CAAC;QAChB,aAAa,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QACvC,OAAO,IAAI,CAAC;IAAA,CACZ;CACD","sourcesContent":["// allow: SIZE_OK - evidence ledger guardrails: tamper-evident replay chain + fail-closed parsing.\nimport { createHash } from \"node:crypto\";\nimport { existsSync, mkdirSync, writeFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport type {\n\tEvidenceCommandDescriptor,\n\tEvidenceItem,\n\tEvidenceReceiptMode,\n\tEvidenceStatus,\n\tMergeGateResult,\n\tMergeGateStatus,\n\tReplayEvent,\n\tReplayLedger,\n\tReplayLedgerHead,\n\tTaskContract,\n\tVerifiedReplayLedgerSnapshot,\n\tWorkspaceScope,\n} from \"../types/evidence.ts\";\nimport { redactCommandDescriptor } from \"./command-redaction.ts\";\nimport {\n\ttype CommandHmacBinder,\n\tlatestRelevantWorkspaceMutationSeq,\n\tparseVerifiedLedgerSnapshot,\n\treplayPayloadMatches,\n\tverifyCommandAttestation,\n\tverifyWorkspaceBinding,\n} from \"./evidence-attestation.ts\";\n\nexport { latestRelevantWorkspaceMutationSeq } from \"./evidence-attestation.ts\";\n\nimport {\n\tcomputeEvidenceCommandSha256,\n\tconstantTimeSha256Equal,\n\tevidenceReceiptReplayPayload,\n\tparseSha256Hex,\n\tvalidateEvidenceReceipt,\n} from \"./evidence-receipt.ts\";\nimport { ReplayLedgerStore, replayLedgerHeadsEqual } from \"./replay-ledger-store.ts\";\n\nfunction sha256(input: string): string {\n\treturn createHash(\"sha256\").update(input).digest(\"hex\");\n}\n\nfunction ensureDir(path: string): void {\n\tconst dir = dirname(path);\n\tif (!existsSync(dir)) {\n\t\tmkdirSync(dir, { recursive: true });\n\t}\n}\n\n// ============================================================================\n// TaskContract\n// ============================================================================\n\nexport class TaskContractBuilder {\n\tprivate goalId: string;\n\tprivate completionClaim: string = \"\";\n\tprivate requiredEvidence: EvidenceItem[] = [];\n\tprivate finalRisk: string = \"\";\n\tprivate verdict: \"pass\" | \"fail\" | \"conditional\" = \"fail\";\n\tprivate createdAt: string;\n\tprivate updatedAt: string;\n\n\tconstructor(goalId: string) {\n\t\tthis.goalId = goalId;\n\t\tconst now = new Date().toISOString();\n\t\tthis.createdAt = now;\n\t\tthis.updatedAt = now;\n\t}\n\n\tsetClaim(claim: string): this {\n\t\tthis.completionClaim = claim;\n\t\tthis.touch();\n\t\treturn this;\n\t}\n\n\taddRequiredEvidence(evidence: Omit<EvidenceItem, \"timestamp\" | \"status\">): this {\n\t\tthis.requiredEvidence.push({\n\t\t\t...evidence,\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tstatus: \"pending\",\n\t\t});\n\t\tthis.touch();\n\t\treturn this;\n\t}\n\n\tsetFinalRisk(risk: string): this {\n\t\tthis.finalRisk = risk;\n\t\tthis.touch();\n\t\treturn this;\n\t}\n\n\tsetVerdict(verdict: \"pass\" | \"fail\" | \"conditional\"): this {\n\t\tthis.verdict = verdict;\n\t\tthis.touch();\n\t\treturn this;\n\t}\n\n\tupdateEvidenceStatus(claim: string, status: EvidenceStatus, gapReason?: string): this {\n\t\tconst item = this.requiredEvidence.find((e) => e.claim === claim);\n\t\tif (item) {\n\t\t\titem.status = status;\n\t\t\titem.gapReason = gapReason;\n\t\t\titem.timestamp = new Date().toISOString();\n\t\t\tthis.touch();\n\t\t}\n\t\treturn this;\n\t}\n\n\tprivate touch(): void {\n\t\tthis.updatedAt = new Date().toISOString();\n\t}\n\n\tbuild(): TaskContract {\n\t\treturn structuredClone({\n\t\t\tgoalId: this.goalId,\n\t\t\tcompletionClaim: this.completionClaim,\n\t\t\trequiredEvidence: this.requiredEvidence,\n\t\t\tfinalRisk: this.finalRisk,\n\t\t\tverdict: this.verdict,\n\t\t\tcreatedAt: this.createdAt,\n\t\t\tupdatedAt: this.updatedAt,\n\t\t});\n\t}\n\n\t/** Parse and validate a serialized TaskContract. Fails closed on any shape violation. */\n\tstatic fromJSON(json: string): TaskContract {\n\t\tconst raw: unknown = JSON.parse(json);\n\t\tif (raw === null || typeof raw !== \"object\" || Array.isArray(raw)) {\n\t\t\tthrow new Error(\"TaskContract JSON must be an object\");\n\t\t}\n\t\tconst { goalId, completionClaim, finalRisk, verdict, createdAt, updatedAt, requiredEvidence } = raw as Record<\n\t\t\tstring,\n\t\t\tunknown\n\t\t>;\n\t\tif (\n\t\t\ttypeof goalId !== \"string\" ||\n\t\t\ttypeof completionClaim !== \"string\" ||\n\t\t\ttypeof finalRisk !== \"string\" ||\n\t\t\ttypeof createdAt !== \"string\" ||\n\t\t\ttypeof updatedAt !== \"string\"\n\t\t) {\n\t\t\tthrow new Error(\"TaskContract JSON has missing or mistyped string fields\");\n\t\t}\n\t\tif (verdict !== \"pass\" && verdict !== \"fail\" && verdict !== \"conditional\") {\n\t\t\tthrow new Error(`TaskContract verdict must be pass|fail|conditional, got ${String(verdict)}`);\n\t\t}\n\t\tif (!Array.isArray(requiredEvidence)) {\n\t\t\tthrow new Error(\"TaskContract requiredEvidence must be an array\");\n\t\t}\n\t\treturn {\n\t\t\tgoalId,\n\t\t\tcompletionClaim,\n\t\t\tfinalRisk,\n\t\t\tverdict,\n\t\t\tcreatedAt,\n\t\t\tupdatedAt,\n\t\t\trequiredEvidence: requiredEvidence.map((item, index) => parseEvidenceItem(item, index)),\n\t\t};\n\t}\n\n\tstatic toJSON(contract: TaskContract): string {\n\t\treturn JSON.stringify(contract, null, 2);\n\t}\n}\n\nconst EVIDENCE_STATUSES: ReadonlySet<string> = new Set([\"pending\", \"gathering\", \"satisfied\", \"failed\", \"waived\"]);\n\nfunction optionalStringField(value: unknown, field: string, index: number): string | undefined {\n\tif (value !== undefined && typeof value !== \"string\") {\n\t\tthrow new Error(`TaskContract evidence[${index}].${field} must be a string when present`);\n\t}\n\treturn value;\n}\n\nfunction parseEvidenceItem(raw: unknown, index: number): EvidenceItem {\n\tif (raw === null || typeof raw !== \"object\" || Array.isArray(raw)) {\n\t\tthrow new Error(`TaskContract evidence[${index}] must be an object`);\n\t}\n\tconst item = raw as Record<string, unknown>;\n\tconst { claim, category, timestamp, status } = item;\n\tif (typeof claim !== \"string\" || typeof category !== \"string\" || typeof timestamp !== \"string\") {\n\t\tthrow new Error(`TaskContract evidence[${index}] has missing or mistyped fields`);\n\t}\n\tif (typeof status !== \"string\" || !EVIDENCE_STATUSES.has(status)) {\n\t\tthrow new Error(`TaskContract evidence[${index}] has invalid status ${String(status)}`);\n\t}\n\tconst receiptSchemaVersion = item.receiptSchemaVersion;\n\tif (receiptSchemaVersion !== undefined && receiptSchemaVersion !== 3) {\n\t\tthrow new Error(`TaskContract evidence[${index}].receiptSchemaVersion must be 3 when present`);\n\t}\n\tconst receiptCommandSha256 = optionalStringField(item.receiptCommandSha256, \"receiptCommandSha256\", index);\n\treturn {\n\t\tclaim,\n\t\tcategory: category as EvidenceItem[\"category\"],\n\t\ttimestamp,\n\t\tstatus: status as EvidenceStatus,\n\t\tartifactPath: optionalStringField(item.artifactPath, \"artifactPath\", index),\n\t\tverificationCommand: optionalStringField(item.verificationCommand, \"verificationCommand\", index),\n\t\thash: optionalStringField(item.hash, \"hash\", index),\n\t\treceiptId: optionalStringField(item.receiptId, \"receiptId\", index),\n\t\treceiptSchemaVersion,\n\t\t...(receiptCommandSha256 !== undefined\n\t\t\t? { receiptCommandSha256: parseSha256Hex(receiptCommandSha256, \"receiptCommandSha256\") }\n\t\t\t: {}),\n\t\treceiptLaneId: optionalStringField(item.receiptLaneId, \"receiptLaneId\", index),\n\t\tgapReason: optionalStringField(item.gapReason, \"gapReason\", index),\n\t};\n}\n\n// ============================================================================\n// ReplayLedger\n// ============================================================================\n\n/** prevHash sentinel for the first event in a replay chain. */\nconst GENESIS_HASH = \"genesis\";\n\nfunction computeEventHash(event: Omit<ReplayEvent, \"eventHash\">): string {\n\treturn sha256(\n\t\tJSON.stringify([\n\t\t\tevent.seq,\n\t\t\tevent.type,\n\t\t\tevent.timestamp,\n\t\t\tevent.goalId,\n\t\t\tevent.laneId ?? null,\n\t\t\tevent.payloadHash,\n\t\t\tevent.prevHash,\n\t\t]),\n\t);\n}\n\nfunction parseReplayEventLine(line: string, lineNumber: number): ReplayEvent {\n\tlet raw: unknown;\n\ttry {\n\t\traw = JSON.parse(line);\n\t} catch {\n\t\tthrow new Error(`Replay ledger corrupted at line ${lineNumber}: invalid JSON`);\n\t}\n\tif (raw === null || typeof raw !== \"object\" || Array.isArray(raw)) {\n\t\tthrow new Error(`Replay ledger corrupted at line ${lineNumber}: event must be an object`);\n\t}\n\tconst event = raw as Record<string, unknown>;\n\tconst { seq, type, timestamp, goalId, laneId, payloadHash, prevHash, eventHash } = event;\n\tif (\n\t\ttypeof seq !== \"number\" ||\n\t\ttypeof type !== \"string\" ||\n\t\ttypeof timestamp !== \"string\" ||\n\t\ttypeof goalId !== \"string\" ||\n\t\ttypeof payloadHash !== \"string\" ||\n\t\ttypeof prevHash !== \"string\" ||\n\t\ttypeof eventHash !== \"string\" ||\n\t\t(laneId !== undefined && typeof laneId !== \"string\") ||\n\t\t!(\"payload\" in event)\n\t) {\n\t\tthrow new Error(`Replay ledger corrupted at line ${lineNumber}: event fields are missing or mistyped`);\n\t}\n\treturn {\n\t\tseq,\n\t\ttype: type as ReplayEvent[\"type\"],\n\t\ttimestamp,\n\t\tgoalId,\n\t\tlaneId,\n\t\tpayload: event.payload,\n\t\tpayloadHash,\n\t\tprevHash,\n\t\teventHash,\n\t};\n}\n\nfunction parseReplayLedgerBytes(bytes: Buffer, goalId: string): ReplayEvent[] {\n\tconst lines = bytes\n\t\t.toString(\"utf8\")\n\t\t.split(\"\\n\")\n\t\t.filter((line) => line.trim().length > 0);\n\tconst events: ReplayEvent[] = [];\n\tlet prevHash = GENESIS_HASH;\n\tfor (let index = 0; index < lines.length; index++) {\n\t\tconst event = parseReplayEventLine(lines[index], index + 1);\n\t\tif (event.goalId !== goalId) throw new Error(`Replay ledger goal mismatch at line ${index + 1}`);\n\t\tif (event.seq !== index + 1) {\n\t\t\tthrow new Error(`Replay ledger corrupted at line ${index + 1}: expected seq ${index + 1}, got ${event.seq}`);\n\t\t}\n\t\tif (event.prevHash !== prevHash) throw new Error(`Replay ledger chain broken at line ${index + 1}`);\n\t\tif (sha256(JSON.stringify(event.payload)) !== event.payloadHash) {\n\t\t\tthrow new Error(`Replay ledger payload tampered at line ${index + 1} (seq ${event.seq})`);\n\t\t}\n\t\tif (computeEventHash(event) !== event.eventHash) {\n\t\t\tthrow new Error(`Replay ledger event hash mismatch at line ${index + 1} (seq ${event.seq})`);\n\t\t}\n\t\tprevHash = event.eventHash;\n\t\tevents.push(event);\n\t}\n\treturn events;\n}\n\nexport class ReplayLedgerManager {\n\tprivate readonly goalId: string;\n\tprivate readonly ledgerPath: string;\n\tprivate readonly store: ReplayLedgerStore;\n\tprivate events: ReplayEvent[] = [];\n\tprivate committedHead: ReplayLedgerHead;\n\n\tconstructor(goalId: string, ledgerPath: string, expectedHead?: ReplayLedgerHead) {\n\t\tthis.goalId = goalId;\n\t\tthis.ledgerPath = ledgerPath;\n\t\tthis.committedHead = { fileIdentity: null, size: 0, lastSeq: 0, lastHash: GENESIS_HASH };\n\t\tthis.store = new ReplayLedgerStore(ledgerPath, (bytes) => {\n\t\t\tconst events = parseReplayLedgerBytes(bytes, goalId);\n\t\t\tconst last = events.at(-1);\n\t\t\treturn { lastSeq: last?.seq ?? 0, lastHash: last?.eventHash ?? GENESIS_HASH };\n\t\t});\n\t\tthis.refresh(expectedHead);\n\t}\n\n\tprivate refresh(expectedHead?: ReplayLedgerHead): void {\n\t\tconst snapshot = this.store.load(expectedHead);\n\t\tthis.events = parseReplayLedgerBytes(snapshot.bytes, this.goalId);\n\t\tthis.committedHead = snapshot.head;\n\t}\n\n\tappend(\n\t\tevent: Omit<ReplayEvent, \"seq\" | \"timestamp\" | \"payloadHash\" | \"prevHash\" | \"eventHash\">,\n\t\texpectedHead: ReplayLedgerHead = this.committedHead,\n\t): ReplayEvent {\n\t\tif (event.goalId !== this.goalId) throw new Error(\"Replay event goalId does not match the ledger\");\n\t\tif (!replayLedgerHeadsEqual(expectedHead, this.committedHead)) {\n\t\t\tthrow new Error(\"Replay manager expected-head CAS is stale\");\n\t\t}\n\t\tconst payloadHash = sha256(JSON.stringify(event.payload));\n\t\tconst chained: Omit<ReplayEvent, \"eventHash\"> = {\n\t\t\t...event,\n\t\t\tseq: expectedHead.lastSeq + 1,\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tpayloadHash,\n\t\t\tprevHash: expectedHead.lastHash,\n\t\t};\n\t\tconst fullEvent: ReplayEvent = { ...chained, eventHash: computeEventHash(chained) };\n\t\tthis.committedHead = this.store.append(\n\t\t\tBuffer.from(`${JSON.stringify(fullEvent)}\\n`, \"utf8\"),\n\t\t\tfullEvent.seq,\n\t\t\tfullEvent.eventHash,\n\t\t\texpectedHead,\n\t\t);\n\t\tthis.events.push(fullEvent);\n\t\treturn structuredClone(fullEvent);\n\t}\n\n\t/** Compatibility no-op that still verifies the caller's expected committed head. */\n\tpersist(expectedHead: ReplayLedgerHead = this.committedHead): void {\n\t\tthis.getVerifiedSnapshot(expectedHead);\n\t}\n\n\tload(expectedHead: ReplayLedgerHead = this.committedHead): void {\n\t\tthis.refresh(expectedHead);\n\t}\n\n\tgetCommittedHead(): ReplayLedgerHead {\n\t\treturn structuredClone(this.committedHead);\n\t}\n\n\tgetVerifiedSnapshot(expectedHead: ReplayLedgerHead = this.committedHead): VerifiedReplayLedgerSnapshot {\n\t\tthis.refresh(expectedHead);\n\t\treturn structuredClone({ events: this.events, head: this.committedHead });\n\t}\n\n\tgetEvents(): ReadonlyArray<ReplayEvent> {\n\t\treturn structuredClone(this.events);\n\t}\n\n\tgetLedger(): Readonly<ReplayLedger> {\n\t\treturn structuredClone({\n\t\t\tgoalId: this.goalId,\n\t\t\tevents: this.events,\n\t\t\tledgerPath: this.ledgerPath,\n\t\t\tlastPersistedSeq: this.committedHead.lastSeq,\n\t\t});\n\t}\n\n\treplay<T>(handler: (event: ReplayEvent) => T | undefined): T[] {\n\t\treturn this.events.map(handler).filter((result): result is T => result !== undefined);\n\t}\n\n\texportToFile(path: string): void {\n\t\tensureDir(path);\n\t\twriteFileSync(path, JSON.stringify(this.events, null, 2), \"utf8\");\n\t}\n}\n\n// ============================================================================\n// EvidenceGate\n// ============================================================================\n\nexport interface EvidenceGateOptions {\n\t/** Minimum number of satisfied evidence items required. */\n\tminEvidenceCount?: number;\n\t/** Require at least one artifact with a SHA-256 hash in explicit legacy mode. */\n\trequireHash?: boolean;\n\t/** Require at least one verification command in explicit legacy mode. */\n\trequireVerificationCommand?: boolean;\n\t/** Receipt policy. Defaults to prefer; legacy must be selected explicitly. */\n\treceiptMode?: EvidenceReceiptMode;\n\t/** Resolve a serialized or decoded receipt by ID. The gate validates the returned value. */\n\tresolveReceipt?: (receiptId: string) => unknown;\n\t/** Strict source: one expected-head, file-identity, suffix, and chain-verified snapshot. */\n\tresolveVerifiedLedgerSnapshot?: () => VerifiedReplayLedgerSnapshot;\n\t/** Prefer-mode migration source; strict mode requires resolveVerifiedLedgerSnapshot. */\n\tresolveLedgerEvent?: (seq: number) => ReplayEvent | undefined;\n\t/** Recapture the receipt's workspace scope (same kind and scope) for freshness comparison. */\n\tcaptureWorkspaceFingerprint?: (scope: WorkspaceScope) => unknown;\n\t/**\n\t * Optional freshness source: the latest replay-ledger sequence of a workspace mutation\n\t * relevant to the given scope, or null/undefined when none is known. When configured,\n\t * the receipt's verified ledger seq must strictly exceed this value; a throwing or\n\t * out-of-contract source is a hard block (positive safe integers only).\n\t */\n\tresolveLatestWorkspaceMutationSeq?: (scope: WorkspaceScope) => number | null | undefined;\n\t/** Ephemeral trust anchor used to verify the original command's keyed attestation. */\n\tcommandAttestationBinder?: Pick<CommandHmacBinder, \"verify\">;\n\t/** Resolve the original command inside the same trust boundary as the binder. */\n\tresolveAttestedCommand?: (receiptId: string) => EvidenceCommandDescriptor | undefined;\n}\n\ninterface ReceiptCheckIssue {\n\treadonly message: string;\n\treadonly hard: boolean;\n}\n\nfunction receiptCheckIssue(message: string, hard: boolean): ReceiptCheckIssue {\n\treturn { message, hard };\n}\n\nfunction receiptIssue(\n\titem: EvidenceItem,\n\tcontract: TaskContract,\n\toptions: EvidenceGateOptions,\n): ReceiptCheckIssue | undefined {\n\tif (!item.receiptId) {\n\t\treturn receiptCheckIssue(`Execution receipt is missing for evidence \"${item.claim}\".`, false);\n\t}\n\tconst strict = options.receiptMode === \"strict\";\n\tif (item.receiptSchemaVersion !== 3 && (item.receiptSchemaVersion !== undefined || strict)) {\n\t\treturn receiptCheckIssue(`Execution receipt schema metadata is invalid for evidence \"${item.claim}\".`, true);\n\t}\n\tif (!options.resolveReceipt) {\n\t\treturn receiptCheckIssue(`Execution receipt resolver is missing for evidence \"${item.claim}\".`, false);\n\t}\n\n\tlet rawReceipt: unknown;\n\ttry {\n\t\trawReceipt = options.resolveReceipt(item.receiptId);\n\t} catch {\n\t\treturn receiptCheckIssue(`Execution receipt resolver failed for evidence \"${item.claim}\".`, true);\n\t}\n\tif (rawReceipt === undefined) {\n\t\treturn receiptCheckIssue(`Execution receipt is missing for evidence \"${item.claim}\".`, false);\n\t}\n\n\ttry {\n\t\tconst receipt = validateEvidenceReceipt(rawReceipt);\n\t\tif (receipt.core.receiptId !== item.receiptId) {\n\t\t\treturn receiptCheckIssue(`Execution receipt ID does not match evidence \"${item.claim}\".`, true);\n\t\t}\n\t\tif (receipt.core.goalId !== contract.goalId) {\n\t\t\treturn receiptCheckIssue(`Execution receipt goal does not match evidence \"${item.claim}\".`, true);\n\t\t}\n\t\tif (receipt.core.claim !== item.claim) {\n\t\t\treturn receiptCheckIssue(`Execution receipt claim does not match evidence \"${item.claim}\".`, true);\n\t\t}\n\t\tif (receipt.core.status !== \"passed\" || receipt.core.exitCode !== 0) {\n\t\t\treturn receiptCheckIssue(\n\t\t\t\t`Execution receipt for evidence \"${item.claim}\" did not pass with exit code 0.`,\n\t\t\t\ttrue,\n\t\t\t);\n\t\t}\n\n\t\tif (item.receiptCommandSha256 === undefined) {\n\t\t\treturn receiptCheckIssue(`Execution receipt command binding is missing for evidence \"${item.claim}\".`, false);\n\t\t}\n\t\tconst receiptCommandSha256 = computeEvidenceCommandSha256(receipt.core.command);\n\t\tif (!constantTimeSha256Equal(item.receiptCommandSha256, receiptCommandSha256)) {\n\t\t\treturn receiptCheckIssue(`Execution receipt command does not match evidence \"${item.claim}\".`, true);\n\t\t}\n\t\tconst attestationIssue = verifyCommandAttestation({\n\t\t\treceiptId: receipt.core.receiptId,\n\t\t\tbinding: receipt.core.commandBinding,\n\t\t\tpersistedCommand: receipt.core.command,\n\t\t\tpersistedSummary: receipt.core.commandRedaction,\n\t\t\tbinder: options.commandAttestationBinder,\n\t\t\tresolveCommand: options.resolveAttestedCommand,\n\t\t\tredact: redactCommandDescriptor,\n\t\t});\n\t\tif (attestationIssue !== undefined) {\n\t\t\treturn receiptCheckIssue(\n\t\t\t\t`Execution receipt command attestation ${attestationIssue.detail} for evidence \"${item.claim}\".`,\n\t\t\t\tattestationIssue.hard,\n\t\t\t);\n\t\t}\n\n\t\tif (receipt.core.laneId !== undefined && item.receiptLaneId === undefined) {\n\t\t\treturn receiptCheckIssue(`Execution receipt lane binding is missing for evidence \"${item.claim}\".`, false);\n\t\t}\n\t\tif (item.receiptLaneId !== receipt.core.laneId) {\n\t\t\treturn receiptCheckIssue(`Execution receipt lane does not match evidence \"${item.claim}\".`, true);\n\t\t}\n\n\t\tconst workspaceIssue = verifyWorkspaceBinding(receipt.core.workspaceAfter, options.captureWorkspaceFingerprint);\n\t\tif (workspaceIssue !== undefined) {\n\t\t\treturn receiptCheckIssue(\n\t\t\t\t`Execution receipt ${workspaceIssue.detail} for evidence \"${item.claim}\".`,\n\t\t\t\tworkspaceIssue.hard,\n\t\t\t);\n\t\t}\n\n\t\tlet snapshot: VerifiedReplayLedgerSnapshot | undefined;\n\t\tif (options.resolveVerifiedLedgerSnapshot !== undefined) {\n\t\t\ttry {\n\t\t\t\tsnapshot = parseVerifiedLedgerSnapshot(\n\t\t\t\t\toptions.resolveVerifiedLedgerSnapshot(),\n\t\t\t\t\tcontract.goalId,\n\t\t\t\t\tparseReplayLedgerBytes,\n\t\t\t\t);\n\t\t\t} catch {\n\t\t\t\treturn receiptCheckIssue(\n\t\t\t\t\t`Execution receipt verified ledger snapshot failed for evidence \"${item.claim}\".`,\n\t\t\t\t\ttrue,\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (strict) {\n\t\t\treturn receiptCheckIssue(\n\t\t\t\t`Execution receipt verified ledger snapshot is missing for evidence \"${item.claim}\".`,\n\t\t\t\tfalse,\n\t\t\t);\n\t\t}\n\t\tlet latestMutationSeq =\n\t\t\tsnapshot === undefined\n\t\t\t\t? null\n\t\t\t\t: latestRelevantWorkspaceMutationSeq(snapshot.events, receipt.core.workspaceAfter.scope);\n\t\tif (snapshot === undefined && options.resolveLatestWorkspaceMutationSeq !== undefined) {\n\t\t\tlet resolved: unknown;\n\t\t\ttry {\n\t\t\t\tresolved = options.resolveLatestWorkspaceMutationSeq(receipt.core.workspaceAfter.scope);\n\t\t\t} catch {\n\t\t\t\treturn receiptCheckIssue(\n\t\t\t\t\t`Execution receipt workspace-mutation freshness source failed for evidence \"${item.claim}\".`,\n\t\t\t\t\ttrue,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (resolved !== null && resolved !== undefined) {\n\t\t\t\tif (!Number.isSafeInteger(resolved) || (resolved as number) <= 0) {\n\t\t\t\t\treturn receiptCheckIssue(\n\t\t\t\t\t\t`Execution receipt workspace-mutation freshness source is malformed for evidence \"${item.claim}\".`,\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tlatestMutationSeq = resolved as number;\n\t\t\t}\n\t\t}\n\n\t\tconst binding = receipt.envelope.ledgerBinding;\n\t\tif (!binding) {\n\t\t\treturn receiptCheckIssue(\n\t\t\t\t`Execution receipt ledger binding is missing for evidence \"${item.claim}\".`,\n\t\t\t\tlatestMutationSeq !== null,\n\t\t\t);\n\t\t}\n\t\tconst event = snapshot\n\t\t\t? snapshot.events.find((candidate) => candidate.seq === binding.seq)\n\t\t\t: options.resolveLedgerEvent?.(binding.seq);\n\t\tif (!event && snapshot === undefined && !options.resolveLedgerEvent) {\n\t\t\treturn receiptCheckIssue(\n\t\t\t\t`Execution receipt ledger resolver is missing for evidence \"${item.claim}\".`,\n\t\t\t\tlatestMutationSeq !== null,\n\t\t\t);\n\t\t}\n\t\tconst replayPayload = evidenceReceiptReplayPayload(receipt);\n\t\tif (\n\t\t\t!event ||\n\t\t\tevent.seq !== binding.seq ||\n\t\t\tevent.type !== \"evidence_receipt\" ||\n\t\t\tevent.goalId !== contract.goalId ||\n\t\t\tevent.laneId !== receipt.core.laneId ||\n\t\t\t!constantTimeSha256Equal(event.eventHash, binding.eventHash) ||\n\t\t\t!replayPayloadMatches(event.payload, replayPayload.receiptId, replayPayload.coreSha256)\n\t\t) {\n\t\t\treturn receiptCheckIssue(`Execution receipt ledger binding does not match evidence \"${item.claim}\".`, true);\n\t\t}\n\t\tif (latestMutationSeq !== null && event.seq <= latestMutationSeq) {\n\t\t\treturn receiptCheckIssue(\n\t\t\t\t`Execution receipt is stale: workspace mutation seq ${latestMutationSeq} does not precede receipt ledger seq ${event.seq} for evidence \"${item.claim}\".`,\n\t\t\t\ttrue,\n\t\t\t);\n\t\t}\n\t} catch {\n\t\treturn receiptCheckIssue(`Execution receipt is invalid for evidence \"${item.claim}\".`, true);\n\t}\n\treturn undefined;\n}\n\nexport class EvidenceGate {\n\tprivate options: EvidenceGateOptions;\n\n\tconstructor(options: EvidenceGateOptions = {}) {\n\t\tthis.options = {\n\t\t\tminEvidenceCount: 1,\n\t\t\trequireHash: true,\n\t\t\trequireVerificationCommand: true,\n\t\t\treceiptMode: \"prefer\",\n\t\t\t...options,\n\t\t};\n\t}\n\n\tcheck(contract: TaskContract): MergeGateResult {\n\t\tconst evidence = contract.requiredEvidence;\n\t\tconst satisfied = evidence.filter((e) => e.status === \"satisfied\");\n\t\tconst failed = evidence.filter((e) => e.status === \"failed\");\n\t\tconst pending = evidence.filter((e) => e.status === \"pending\" || e.status === \"gathering\");\n\t\tconst mode = this.options.receiptMode ?? \"prefer\";\n\t\tconst checks: string[] = [];\n\t\tlet hardReceiptFailure = false;\n\n\t\tif (satisfied.length < (this.options.minEvidenceCount ?? 1)) {\n\t\t\tchecks.push(`Only ${satisfied.length}/${this.options.minEvidenceCount} required evidence items satisfied.`);\n\t\t}\n\t\tif (failed.length > 0) {\n\t\t\tchecks.push(`${failed.length} evidence item(s) failed.`);\n\t\t}\n\n\t\tif (mode === \"legacy\") {\n\t\t\tif (this.options.requireHash) {\n\t\t\t\tconst hashed = satisfied.filter((e) => e.hash && e.hash.length > 0);\n\t\t\t\tif (hashed.length === 0) checks.push(\"No satisfied evidence has a SHA-256 hash.\");\n\t\t\t}\n\t\t\tif (this.options.requireVerificationCommand) {\n\t\t\t\tconst withCommand = satisfied.filter((e) => e.verificationCommand && e.verificationCommand.length > 0);\n\t\t\t\tif (withCommand.length === 0) checks.push(\"No satisfied evidence has a verification command.\");\n\t\t\t}\n\t\t} else {\n\t\t\tconst unsatisfied = evidence.filter((item) => item.status !== \"satisfied\");\n\t\t\tif (unsatisfied.length > 0) {\n\t\t\t\tchecks.push(`${unsatisfied.length} required evidence item(s) are not satisfied.`);\n\t\t\t}\n\t\t\tfor (const item of satisfied) {\n\t\t\t\tconst issue = receiptIssue(item, contract, this.options);\n\t\t\t\tif (issue) {\n\t\t\t\t\tchecks.push(issue.message);\n\t\t\t\t\thardReceiptFailure ||= issue.hard;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (contract.verdict === \"fail\" || (mode !== \"legacy\" && contract.verdict !== \"pass\")) {\n\t\t\tchecks.push(`Task contract verdict is '${contract.verdict}'.`);\n\t\t}\n\n\t\tlet status: MergeGateStatus;\n\t\tlet reason: string;\n\t\tlet suggestion: string | undefined;\n\t\tif (checks.length === 0) {\n\t\t\tstatus = \"open\";\n\t\t\treason = `Evidence gate passed: ${satisfied.length}/${evidence.length} evidence items satisfied.`;\n\t\t} else {\n\t\t\tconst contractFailure = mode === \"legacy\" ? contract.verdict === \"fail\" : contract.verdict !== \"pass\";\n\t\t\tconst hasHardFailure = failed.length > 0 || contractFailure || hardReceiptFailure || mode === \"strict\";\n\t\t\tstatus = hasHardFailure ? \"blocked\" : mode === \"prefer\" || pending.length > 0 ? \"conditional\" : \"blocked\";\n\t\t\treason = checks.join(\"; \");\n\t\t\tsuggestion = `Gather remaining evidence (${pending.length} pending) and re-run verification.`;\n\t\t}\n\n\t\treturn {\n\t\t\tgateId: \"evidence-gate\",\n\t\t\tstatus,\n\t\t\treason,\n\t\t\tsuggestion,\n\t\t\tevidenceChecked: evidence,\n\t\t};\n\t}\n}\n\n// ============================================================================\n// FailClosedMergeGate\n// ============================================================================\n\nexport class FailClosedMergeGate {\n\tprivate gates: EvidenceGate[];\n\n\tconstructor(gates: EvidenceGate[] = [new EvidenceGate()]) {\n\t\tthis.gates = gates;\n\t}\n\n\tcheck(contract: TaskContract): MergeGateResult {\n\t\tconst results = this.gates.map((gate) => gate.check(contract));\n\t\tconst blocked = results.filter((r) => r.status === \"blocked\");\n\t\tconst conditional = results.filter((r) => r.status === \"conditional\");\n\n\t\tif (blocked.length > 0) {\n\t\t\treturn {\n\t\t\t\tgateId: \"fail-closed-merge-gate\",\n\t\t\t\tstatus: \"blocked\",\n\t\t\t\treason: `Blocked by ${blocked.length} gate(s): ${blocked.map((b) => b.reason).join(\"; \")}`,\n\t\t\t\tsuggestion: \"Resolve all blocking conditions before merge.\",\n\t\t\t\tevidenceChecked: contract.requiredEvidence,\n\t\t\t};\n\t\t}\n\n\t\tif (conditional.length > 0) {\n\t\t\treturn {\n\t\t\t\tgateId: \"fail-closed-merge-gate\",\n\t\t\t\tstatus: \"conditional\",\n\t\t\t\treason: `Conditional pass: ${conditional.length} gate(s) have pending conditions.`,\n\t\t\t\tsuggestion: \"Complete pending evidence or waive with explicit approval.\",\n\t\t\t\tevidenceChecked: contract.requiredEvidence,\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\tgateId: \"fail-closed-merge-gate\",\n\t\t\tstatus: \"open\",\n\t\t\treason: \"All merge gates passed. Evidence verified and contract verdict is acceptable.\",\n\t\t\tevidenceChecked: contract.requiredEvidence,\n\t\t};\n\t}\n}\n\n// ============================================================================\n// Verify Reporter v2\n// ============================================================================\n\n/** Escape pipes/newlines so untrusted claim or command text cannot restructure the report table. */\nfunction escapeTableCell(value: string): string {\n\treturn value.replace(/\\\\/g, \"\\\\\\\\\").replace(/\\|/g, \"\\\\|\").replace(/\\r?\\n/g, \" \");\n}\n\nexport interface VerifyReporterV2Options {\n\toutputDir: string;\n\tgoalId: string;\n}\n\nexport class VerifyReporterV2 {\n\tprivate options: VerifyReporterV2Options;\n\n\tconstructor(options: VerifyReporterV2Options) {\n\t\tthis.options = options;\n\t}\n\n\trender(contract: TaskContract, mergeGate: MergeGateResult): string {\n\t\tconst lines: string[] = [\n\t\t\t`## OMK Verification Report v2 — ${contract.goalId}`,\n\t\t\t\"\",\n\t\t\t\"### Contract\",\n\t\t\t\"\",\n\t\t\t`| Field | Value |`,\n\t\t\t`|-------|-------|`,\n\t\t\t`| Claim | ${escapeTableCell(contract.completionClaim)} |`,\n\t\t\t`| Verdict | ${contract.verdict} |`,\n\t\t\t`| Final Risk | ${escapeTableCell(contract.finalRisk)} |`,\n\t\t\t\"\",\n\t\t\t\"### Evidence\",\n\t\t\t\"\",\n\t\t\t`| Claim | Status | Artifact | Command |`,\n\t\t\t`|-------|--------|----------|----------|`,\n\t\t];\n\n\t\tfor (const ev of contract.requiredEvidence) {\n\t\t\tlines.push(\n\t\t\t\t`| ${escapeTableCell(ev.claim)} | ${ev.status} | ${escapeTableCell(ev.artifactPath ?? \"—\")} | ${escapeTableCell(ev.verificationCommand ?? \"—\")} |`,\n\t\t\t);\n\t\t}\n\n\t\tlines.push(\n\t\t\t\"\",\n\t\t\t\"### Merge Gate\",\n\t\t\t\"\",\n\t\t\t`| Gate | Status | Reason |`,\n\t\t\t`|------|--------|--------|`,\n\t\t\t`| ${mergeGate.gateId} | ${mergeGate.status} | ${escapeTableCell(mergeGate.reason)} |`,\n\t\t\t\"\",\n\t\t);\n\n\t\tif (mergeGate.suggestion) {\n\t\t\tlines.push(`**Suggestion:** ${mergeGate.suggestion}`, \"\");\n\t\t}\n\n\t\treturn lines.join(\"\\n\");\n\t}\n\n\twrite(contract: TaskContract, mergeGate: MergeGateResult): string {\n\t\tconst markdown = this.render(contract, mergeGate);\n\t\tconst path = join(this.options.outputDir, `${this.options.goalId}.verify.md`);\n\t\tensureDir(path);\n\t\twriteFileSync(path, markdown, \"utf-8\");\n\t\treturn path;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"evidence-system.js","sourceRoot":"","sources":["../../src/guardrails/evidence-system.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,IAAI,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AAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,YAAY,CAAC,CAAC;QAC9E,SAAS,CAAC,IAAI,CAAC,CAAC;QAChB,aAAa,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QACvC,OAAO,IAAI,CAAC;IAAA,CACZ;CACD","sourcesContent":["// allow: SIZE_OK - evidence ledger guardrails: tamper-evident replay chain + fail-closed parsing.\nimport { createHash } from \"node:crypto\";\nimport { existsSync, mkdirSync, writeFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport type {\n\tEvidenceCommandDescriptor,\n\tEvidenceItem,\n\tEvidenceReceiptMode,\n\tEvidenceStatus,\n\tMergeGateResult,\n\tMergeGateStatus,\n\tReplayEvent,\n\tReplayLedger,\n\tReplayLedgerHead,\n\tTaskContract,\n\tVerifiedReplayLedgerSnapshot,\n\tWorkspaceScope,\n} from \"../types/evidence.ts\";\nimport { redactCommandDescriptor } from \"./command-redaction.ts\";\nimport {\n\ttype CommandHmacBinder,\n\tlatestRelevantWorkspaceMutationSeq,\n\tparseVerifiedLedgerSnapshot,\n\treplayPayloadMatches,\n\tverifyCommandAttestation,\n\tverifyWorkspaceBinding,\n} from \"./evidence-attestation.ts\";\n\nexport { latestRelevantWorkspaceMutationSeq } from \"./evidence-attestation.ts\";\n\nimport {\n\tcomputeEvidenceCommandSha256,\n\tconstantTimeSha256Equal,\n\tevidenceReceiptReplayPayload,\n\tparseSha256Hex,\n\tvalidateEvidenceReceipt,\n} from \"./evidence-receipt.ts\";\nimport { ReplayLedgerStore, replayLedgerHeadsEqual } from \"./replay-ledger-store.ts\";\nimport {\n\tcomputeReplayPayloadHash,\n\tJCS_REPLAY_PAYLOAD_HASH_ALGORITHM,\n\tLEGACY_REPLAY_PAYLOAD_HASH_ALGORITHM,\n} from \"./replay-payload-hash.ts\";\n\nfunction sha256(input: string): string {\n\treturn createHash(\"sha256\").update(input).digest(\"hex\");\n}\n\nfunction ensureDir(path: string): void {\n\tconst dir = dirname(path);\n\tif (!existsSync(dir)) {\n\t\tmkdirSync(dir, { recursive: true });\n\t}\n}\n\n// ============================================================================\n// TaskContract\n// ============================================================================\n\nexport class TaskContractBuilder {\n\tprivate goalId: string;\n\tprivate completionClaim: string = \"\";\n\tprivate requiredEvidence: EvidenceItem[] = [];\n\tprivate finalRisk: string = \"\";\n\tprivate verdict: \"pass\" | \"fail\" | \"conditional\" = \"fail\";\n\tprivate createdAt: string;\n\tprivate updatedAt: string;\n\n\tconstructor(goalId: string) {\n\t\tthis.goalId = goalId;\n\t\tconst now = new Date().toISOString();\n\t\tthis.createdAt = now;\n\t\tthis.updatedAt = now;\n\t}\n\n\tsetClaim(claim: string): this {\n\t\tthis.completionClaim = claim;\n\t\tthis.touch();\n\t\treturn this;\n\t}\n\n\taddRequiredEvidence(evidence: Omit<EvidenceItem, \"timestamp\" | \"status\">): this {\n\t\tthis.requiredEvidence.push({\n\t\t\t...evidence,\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tstatus: \"pending\",\n\t\t});\n\t\tthis.touch();\n\t\treturn this;\n\t}\n\n\tsetFinalRisk(risk: string): this {\n\t\tthis.finalRisk = risk;\n\t\tthis.touch();\n\t\treturn this;\n\t}\n\n\t/** @deprecated Use `evaluateTask()` from `omk-protocol`; verdicts are derived, not mutated. */\n\tsetVerdict(verdict: \"pass\" | \"fail\" | \"conditional\"): this {\n\t\tthis.verdict = verdict;\n\t\tthis.touch();\n\t\treturn this;\n\t}\n\n\t/** @deprecated Append a protocol Observation and re-evaluate instead of mutating evidence state. */\n\tupdateEvidenceStatus(claim: string, status: EvidenceStatus, gapReason?: string): this {\n\t\tconst item = this.requiredEvidence.find((e) => e.claim === claim);\n\t\tif (item) {\n\t\t\titem.status = status;\n\t\t\titem.gapReason = gapReason;\n\t\t\titem.timestamp = new Date().toISOString();\n\t\t\tthis.touch();\n\t\t}\n\t\treturn this;\n\t}\n\n\tprivate touch(): void {\n\t\tthis.updatedAt = new Date().toISOString();\n\t}\n\n\tbuild(): TaskContract {\n\t\treturn structuredClone({\n\t\t\tgoalId: this.goalId,\n\t\t\tcompletionClaim: this.completionClaim,\n\t\t\trequiredEvidence: this.requiredEvidence,\n\t\t\tfinalRisk: this.finalRisk,\n\t\t\tverdict: this.verdict,\n\t\t\tcreatedAt: this.createdAt,\n\t\t\tupdatedAt: this.updatedAt,\n\t\t});\n\t}\n\n\t/** Parse and validate a serialized TaskContract. Fails closed on any shape violation. */\n\tstatic fromJSON(json: string): TaskContract {\n\t\tconst raw: unknown = JSON.parse(json);\n\t\tif (raw === null || typeof raw !== \"object\" || Array.isArray(raw)) {\n\t\t\tthrow new Error(\"TaskContract JSON must be an object\");\n\t\t}\n\t\tconst { goalId, completionClaim, finalRisk, verdict, createdAt, updatedAt, requiredEvidence } = raw as Record<\n\t\t\tstring,\n\t\t\tunknown\n\t\t>;\n\t\tif (\n\t\t\ttypeof goalId !== \"string\" ||\n\t\t\ttypeof completionClaim !== \"string\" ||\n\t\t\ttypeof finalRisk !== \"string\" ||\n\t\t\ttypeof createdAt !== \"string\" ||\n\t\t\ttypeof updatedAt !== \"string\"\n\t\t) {\n\t\t\tthrow new Error(\"TaskContract JSON has missing or mistyped string fields\");\n\t\t}\n\t\tif (verdict !== \"pass\" && verdict !== \"fail\" && verdict !== \"conditional\") {\n\t\t\tthrow new Error(`TaskContract verdict must be pass|fail|conditional, got ${String(verdict)}`);\n\t\t}\n\t\tif (!Array.isArray(requiredEvidence)) {\n\t\t\tthrow new Error(\"TaskContract requiredEvidence must be an array\");\n\t\t}\n\t\treturn {\n\t\t\tgoalId,\n\t\t\tcompletionClaim,\n\t\t\tfinalRisk,\n\t\t\tverdict,\n\t\t\tcreatedAt,\n\t\t\tupdatedAt,\n\t\t\trequiredEvidence: requiredEvidence.map((item, index) => parseEvidenceItem(item, index)),\n\t\t};\n\t}\n\n\tstatic toJSON(contract: TaskContract): string {\n\t\treturn JSON.stringify(contract, null, 2);\n\t}\n}\n\nconst EVIDENCE_STATUSES: ReadonlySet<string> = new Set([\"pending\", \"gathering\", \"satisfied\", \"failed\", \"waived\"]);\n\nfunction optionalStringField(value: unknown, field: string, index: number): string | undefined {\n\tif (value !== undefined && typeof value !== \"string\") {\n\t\tthrow new Error(`TaskContract evidence[${index}].${field} must be a string when present`);\n\t}\n\treturn value;\n}\n\nfunction parseEvidenceItem(raw: unknown, index: number): EvidenceItem {\n\tif (raw === null || typeof raw !== \"object\" || Array.isArray(raw)) {\n\t\tthrow new Error(`TaskContract evidence[${index}] must be an object`);\n\t}\n\tconst item = raw as Record<string, unknown>;\n\tconst { claim, category, timestamp, status } = item;\n\tif (typeof claim !== \"string\" || typeof category !== \"string\" || typeof timestamp !== \"string\") {\n\t\tthrow new Error(`TaskContract evidence[${index}] has missing or mistyped fields`);\n\t}\n\tif (typeof status !== \"string\" || !EVIDENCE_STATUSES.has(status)) {\n\t\tthrow new Error(`TaskContract evidence[${index}] has invalid status ${String(status)}`);\n\t}\n\tconst receiptSchemaVersion = item.receiptSchemaVersion;\n\tif (receiptSchemaVersion !== undefined && receiptSchemaVersion !== 3) {\n\t\tthrow new Error(`TaskContract evidence[${index}].receiptSchemaVersion must be 3 when present`);\n\t}\n\tconst receiptCommandSha256 = optionalStringField(item.receiptCommandSha256, \"receiptCommandSha256\", index);\n\treturn {\n\t\tclaim,\n\t\tcategory: category as EvidenceItem[\"category\"],\n\t\ttimestamp,\n\t\tstatus: status as EvidenceStatus,\n\t\tartifactPath: optionalStringField(item.artifactPath, \"artifactPath\", index),\n\t\tverificationCommand: optionalStringField(item.verificationCommand, \"verificationCommand\", index),\n\t\thash: optionalStringField(item.hash, \"hash\", index),\n\t\treceiptId: optionalStringField(item.receiptId, \"receiptId\", index),\n\t\treceiptSchemaVersion,\n\t\t...(receiptCommandSha256 !== undefined\n\t\t\t? { receiptCommandSha256: parseSha256Hex(receiptCommandSha256, \"receiptCommandSha256\") }\n\t\t\t: {}),\n\t\treceiptLaneId: optionalStringField(item.receiptLaneId, \"receiptLaneId\", index),\n\t\tgapReason: optionalStringField(item.gapReason, \"gapReason\", index),\n\t};\n}\n\n// ============================================================================\n// ReplayLedger\n// ============================================================================\n\n/** prevHash sentinel for the first event in a replay chain. */\nconst GENESIS_HASH = \"genesis\";\n\nfunction computeEventHash(event: Omit<ReplayEvent, \"eventHash\">): string {\n\tconst metadata = [event.seq, event.type, event.timestamp, event.goalId, event.laneId ?? null];\n\tconst material =\n\t\tevent.payloadHashAlgorithm === undefined\n\t\t\t? [...metadata, event.payloadHash, event.prevHash]\n\t\t\t: [...metadata, event.payloadHashAlgorithm, event.payloadHash, event.prevHash];\n\treturn sha256(JSON.stringify(material));\n}\n\nfunction parseReplayEventLine(line: string, lineNumber: number): ReplayEvent {\n\tlet raw: unknown;\n\ttry {\n\t\traw = JSON.parse(line);\n\t} catch {\n\t\tthrow new Error(`Replay ledger corrupted at line ${lineNumber}: invalid JSON`);\n\t}\n\tif (raw === null || typeof raw !== \"object\" || Array.isArray(raw)) {\n\t\tthrow new Error(`Replay ledger corrupted at line ${lineNumber}: event must be an object`);\n\t}\n\tconst event = raw as Record<string, unknown>;\n\tconst { seq, type, timestamp, goalId, laneId, payloadHashAlgorithm, payloadHash, prevHash, eventHash } = event;\n\tif (\n\t\ttypeof seq !== \"number\" ||\n\t\ttypeof type !== \"string\" ||\n\t\ttypeof timestamp !== \"string\" ||\n\t\ttypeof goalId !== \"string\" ||\n\t\ttypeof payloadHash !== \"string\" ||\n\t\ttypeof prevHash !== \"string\" ||\n\t\ttypeof eventHash !== \"string\" ||\n\t\t(laneId !== undefined && typeof laneId !== \"string\") ||\n\t\t!(\"payload\" in event)\n\t) {\n\t\tthrow new Error(`Replay ledger corrupted at line ${lineNumber}: event fields are missing or mistyped`);\n\t}\n\tif (\n\t\tpayloadHashAlgorithm !== undefined &&\n\t\tpayloadHashAlgorithm !== LEGACY_REPLAY_PAYLOAD_HASH_ALGORITHM &&\n\t\tpayloadHashAlgorithm !== JCS_REPLAY_PAYLOAD_HASH_ALGORITHM\n\t) {\n\t\tthrow new Error(`Replay ledger corrupted at line ${lineNumber}: unsupported payload hash algorithm`);\n\t}\n\tconst parsed: ReplayEvent = {\n\t\tseq,\n\t\ttype: type as ReplayEvent[\"type\"],\n\t\ttimestamp,\n\t\tgoalId,\n\t\tlaneId,\n\t\tpayload: event.payload,\n\t\tpayloadHash,\n\t\tprevHash,\n\t\teventHash,\n\t};\n\treturn payloadHashAlgorithm === undefined ? parsed : { ...parsed, payloadHashAlgorithm };\n}\n\nfunction parseReplayLedgerBytes(bytes: Buffer, goalId: string): ReplayEvent[] {\n\tconst lines = bytes\n\t\t.toString(\"utf8\")\n\t\t.split(\"\\n\")\n\t\t.filter((line) => line.trim().length > 0);\n\tconst events: ReplayEvent[] = [];\n\tlet prevHash = GENESIS_HASH;\n\tfor (let index = 0; index < lines.length; index++) {\n\t\tconst event = parseReplayEventLine(lines[index], index + 1);\n\t\tif (event.goalId !== goalId) throw new Error(`Replay ledger goal mismatch at line ${index + 1}`);\n\t\tif (event.seq !== index + 1) {\n\t\t\tthrow new Error(`Replay ledger corrupted at line ${index + 1}: expected seq ${index + 1}, got ${event.seq}`);\n\t\t}\n\t\tif (event.prevHash !== prevHash) throw new Error(`Replay ledger chain broken at line ${index + 1}`);\n\t\tconst payloadHashAlgorithm = event.payloadHashAlgorithm ?? LEGACY_REPLAY_PAYLOAD_HASH_ALGORITHM;\n\t\tif (computeReplayPayloadHash(event.payload, payloadHashAlgorithm) !== event.payloadHash) {\n\t\t\tthrow new Error(`Replay ledger payload tampered at line ${index + 1} (seq ${event.seq})`);\n\t\t}\n\t\tif (computeEventHash(event) !== event.eventHash) {\n\t\t\tthrow new Error(`Replay ledger event hash mismatch at line ${index + 1} (seq ${event.seq})`);\n\t\t}\n\t\tprevHash = event.eventHash;\n\t\tevents.push(event);\n\t}\n\treturn events;\n}\n\nexport class ReplayLedgerManager {\n\tprivate readonly goalId: string;\n\tprivate readonly ledgerPath: string;\n\tprivate readonly store: ReplayLedgerStore;\n\tprivate events: ReplayEvent[] = [];\n\tprivate committedHead: ReplayLedgerHead;\n\n\tconstructor(goalId: string, ledgerPath: string, expectedHead?: ReplayLedgerHead) {\n\t\tthis.goalId = goalId;\n\t\tthis.ledgerPath = ledgerPath;\n\t\tthis.committedHead = { fileIdentity: null, size: 0, lastSeq: 0, lastHash: GENESIS_HASH };\n\t\tthis.store = new ReplayLedgerStore(ledgerPath, (bytes) => {\n\t\t\tconst events = parseReplayLedgerBytes(bytes, goalId);\n\t\t\tconst last = events[events.length - 1];\n\t\t\treturn { lastSeq: last?.seq ?? 0, lastHash: last?.eventHash ?? GENESIS_HASH };\n\t\t});\n\t\tthis.refresh(expectedHead);\n\t}\n\n\tprivate refresh(expectedHead?: ReplayLedgerHead): void {\n\t\tconst snapshot = this.store.load(expectedHead);\n\t\tthis.events = parseReplayLedgerBytes(snapshot.bytes, this.goalId);\n\t\tthis.committedHead = snapshot.head;\n\t}\n\n\tappend(\n\t\tevent: Omit<ReplayEvent, \"seq\" | \"timestamp\" | \"payloadHashAlgorithm\" | \"payloadHash\" | \"prevHash\" | \"eventHash\">,\n\t\texpectedHead: ReplayLedgerHead = this.committedHead,\n\t): ReplayEvent {\n\t\tif (event.goalId !== this.goalId) throw new Error(\"Replay event goalId does not match the ledger\");\n\t\tif (!replayLedgerHeadsEqual(expectedHead, this.committedHead)) {\n\t\t\tthrow new Error(\"Replay manager expected-head CAS is stale\");\n\t\t}\n\t\tconst payloadHashAlgorithm = JCS_REPLAY_PAYLOAD_HASH_ALGORITHM;\n\t\tconst payloadHash = computeReplayPayloadHash(event.payload, payloadHashAlgorithm);\n\t\tconst chained: Omit<ReplayEvent, \"eventHash\"> = {\n\t\t\t...event,\n\t\t\tseq: expectedHead.lastSeq + 1,\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tpayloadHashAlgorithm,\n\t\t\tpayloadHash,\n\t\t\tprevHash: expectedHead.lastHash,\n\t\t};\n\t\tconst fullEvent: ReplayEvent = { ...chained, eventHash: computeEventHash(chained) };\n\t\tthis.committedHead = this.store.append(\n\t\t\tBuffer.from(`${JSON.stringify(fullEvent)}\\n`, \"utf8\"),\n\t\t\tfullEvent.seq,\n\t\t\tfullEvent.eventHash,\n\t\t\texpectedHead,\n\t\t);\n\t\tthis.events.push(fullEvent);\n\t\treturn structuredClone(fullEvent);\n\t}\n\n\t/** Compatibility no-op that still verifies the caller's expected committed head. */\n\tpersist(expectedHead: ReplayLedgerHead = this.committedHead): void {\n\t\tthis.getVerifiedSnapshot(expectedHead);\n\t}\n\n\tload(expectedHead: ReplayLedgerHead = this.committedHead): void {\n\t\tthis.refresh(expectedHead);\n\t}\n\n\tgetCommittedHead(): ReplayLedgerHead {\n\t\treturn structuredClone(this.committedHead);\n\t}\n\n\tgetVerifiedSnapshot(expectedHead: ReplayLedgerHead = this.committedHead): VerifiedReplayLedgerSnapshot {\n\t\tthis.refresh(expectedHead);\n\t\treturn structuredClone({ events: this.events, head: this.committedHead });\n\t}\n\n\tgetEvents(): ReadonlyArray<ReplayEvent> {\n\t\treturn structuredClone(this.events);\n\t}\n\n\tgetLedger(): Readonly<ReplayLedger> {\n\t\treturn structuredClone({\n\t\t\tgoalId: this.goalId,\n\t\t\tevents: this.events,\n\t\t\tledgerPath: this.ledgerPath,\n\t\t\tlastPersistedSeq: this.committedHead.lastSeq,\n\t\t});\n\t}\n\n\treplay<T>(handler: (event: ReplayEvent) => T | undefined): T[] {\n\t\treturn this.events.map(handler).filter((result): result is T => result !== undefined);\n\t}\n\n\texportToFile(path: string): void {\n\t\tensureDir(path);\n\t\twriteFileSync(path, JSON.stringify(this.events, null, 2), \"utf8\");\n\t}\n}\n\n// ============================================================================\n// EvidenceGate\n// ============================================================================\n\nexport interface EvidenceGateOptions {\n\t/** Minimum number of satisfied evidence items required. */\n\tminEvidenceCount?: number;\n\t/** Require at least one artifact with a SHA-256 hash in explicit legacy mode. */\n\trequireHash?: boolean;\n\t/** Require at least one verification command in explicit legacy mode. */\n\trequireVerificationCommand?: boolean;\n\t/** Receipt policy. Defaults to prefer; legacy must be selected explicitly. */\n\treceiptMode?: EvidenceReceiptMode;\n\t/** Resolve a serialized or decoded receipt by ID. The gate validates the returned value. */\n\tresolveReceipt?: (receiptId: string) => unknown;\n\t/** Strict source: one expected-head, file-identity, suffix, and chain-verified snapshot. */\n\tresolveVerifiedLedgerSnapshot?: () => VerifiedReplayLedgerSnapshot;\n\t/** Prefer-mode migration source; strict mode requires resolveVerifiedLedgerSnapshot. */\n\tresolveLedgerEvent?: (seq: number) => ReplayEvent | undefined;\n\t/** Recapture the receipt's workspace scope (same kind and scope) for freshness comparison. */\n\tcaptureWorkspaceFingerprint?: (scope: WorkspaceScope) => unknown;\n\t/**\n\t * Optional freshness source: the latest replay-ledger sequence of a workspace mutation\n\t * relevant to the given scope, or null/undefined when none is known. When configured,\n\t * the receipt's verified ledger seq must strictly exceed this value; a throwing or\n\t * out-of-contract source is a hard block (positive safe integers only).\n\t */\n\tresolveLatestWorkspaceMutationSeq?: (scope: WorkspaceScope) => number | null | undefined;\n\t/** Ephemeral trust anchor used to verify the original command's keyed attestation. */\n\tcommandAttestationBinder?: Pick<CommandHmacBinder, \"verify\">;\n\t/** Resolve the original command inside the same trust boundary as the binder. */\n\tresolveAttestedCommand?: (receiptId: string) => EvidenceCommandDescriptor | undefined;\n}\n\ninterface ReceiptCheckIssue {\n\treadonly message: string;\n\treadonly hard: boolean;\n}\n\nfunction receiptCheckIssue(message: string, hard: boolean): ReceiptCheckIssue {\n\treturn { message, hard };\n}\n\nfunction receiptIssue(\n\titem: EvidenceItem,\n\tcontract: TaskContract,\n\toptions: EvidenceGateOptions,\n): ReceiptCheckIssue | undefined {\n\tif (!item.receiptId) {\n\t\treturn receiptCheckIssue(`Execution receipt is missing for evidence \"${item.claim}\".`, false);\n\t}\n\tconst strict = options.receiptMode === \"strict\";\n\tif (item.receiptSchemaVersion !== 3 && (item.receiptSchemaVersion !== undefined || strict)) {\n\t\treturn receiptCheckIssue(`Execution receipt schema metadata is invalid for evidence \"${item.claim}\".`, true);\n\t}\n\tif (!options.resolveReceipt) {\n\t\treturn receiptCheckIssue(`Execution receipt resolver is missing for evidence \"${item.claim}\".`, false);\n\t}\n\n\tlet rawReceipt: unknown;\n\ttry {\n\t\trawReceipt = options.resolveReceipt(item.receiptId);\n\t} catch {\n\t\treturn receiptCheckIssue(`Execution receipt resolver failed for evidence \"${item.claim}\".`, true);\n\t}\n\tif (rawReceipt === undefined) {\n\t\treturn receiptCheckIssue(`Execution receipt is missing for evidence \"${item.claim}\".`, false);\n\t}\n\n\ttry {\n\t\tconst receipt = validateEvidenceReceipt(rawReceipt);\n\t\tif (receipt.core.receiptId !== item.receiptId) {\n\t\t\treturn receiptCheckIssue(`Execution receipt ID does not match evidence \"${item.claim}\".`, true);\n\t\t}\n\t\tif (receipt.core.goalId !== contract.goalId) {\n\t\t\treturn receiptCheckIssue(`Execution receipt goal does not match evidence \"${item.claim}\".`, true);\n\t\t}\n\t\tif (receipt.core.claim !== item.claim) {\n\t\t\treturn receiptCheckIssue(`Execution receipt claim does not match evidence \"${item.claim}\".`, true);\n\t\t}\n\t\tif (receipt.core.status !== \"passed\" || receipt.core.exitCode !== 0) {\n\t\t\treturn receiptCheckIssue(\n\t\t\t\t`Execution receipt for evidence \"${item.claim}\" did not pass with exit code 0.`,\n\t\t\t\ttrue,\n\t\t\t);\n\t\t}\n\n\t\tif (item.receiptCommandSha256 === undefined) {\n\t\t\treturn receiptCheckIssue(`Execution receipt command binding is missing for evidence \"${item.claim}\".`, false);\n\t\t}\n\t\tconst receiptCommandSha256 = computeEvidenceCommandSha256(receipt.core.command);\n\t\tif (!constantTimeSha256Equal(item.receiptCommandSha256, receiptCommandSha256)) {\n\t\t\treturn receiptCheckIssue(`Execution receipt command does not match evidence \"${item.claim}\".`, true);\n\t\t}\n\t\tconst attestationIssue = verifyCommandAttestation({\n\t\t\treceiptId: receipt.core.receiptId,\n\t\t\tbinding: receipt.core.commandBinding,\n\t\t\tpersistedCommand: receipt.core.command,\n\t\t\tpersistedSummary: receipt.core.commandRedaction,\n\t\t\tbinder: options.commandAttestationBinder,\n\t\t\tresolveCommand: options.resolveAttestedCommand,\n\t\t\tredact: redactCommandDescriptor,\n\t\t});\n\t\tif (attestationIssue !== undefined) {\n\t\t\treturn receiptCheckIssue(\n\t\t\t\t`Execution receipt command attestation ${attestationIssue.detail} for evidence \"${item.claim}\".`,\n\t\t\t\tattestationIssue.hard,\n\t\t\t);\n\t\t}\n\n\t\tif (receipt.core.laneId !== undefined && item.receiptLaneId === undefined) {\n\t\t\treturn receiptCheckIssue(`Execution receipt lane binding is missing for evidence \"${item.claim}\".`, false);\n\t\t}\n\t\tif (item.receiptLaneId !== receipt.core.laneId) {\n\t\t\treturn receiptCheckIssue(`Execution receipt lane does not match evidence \"${item.claim}\".`, true);\n\t\t}\n\n\t\tconst workspaceIssue = verifyWorkspaceBinding(receipt.core.workspaceAfter, options.captureWorkspaceFingerprint);\n\t\tif (workspaceIssue !== undefined) {\n\t\t\treturn receiptCheckIssue(\n\t\t\t\t`Execution receipt ${workspaceIssue.detail} for evidence \"${item.claim}\".`,\n\t\t\t\tworkspaceIssue.hard,\n\t\t\t);\n\t\t}\n\n\t\tlet snapshot: VerifiedReplayLedgerSnapshot | undefined;\n\t\tif (options.resolveVerifiedLedgerSnapshot !== undefined) {\n\t\t\ttry {\n\t\t\t\tsnapshot = parseVerifiedLedgerSnapshot(\n\t\t\t\t\toptions.resolveVerifiedLedgerSnapshot(),\n\t\t\t\t\tcontract.goalId,\n\t\t\t\t\tparseReplayLedgerBytes,\n\t\t\t\t);\n\t\t\t} catch {\n\t\t\t\treturn receiptCheckIssue(\n\t\t\t\t\t`Execution receipt verified ledger snapshot failed for evidence \"${item.claim}\".`,\n\t\t\t\t\ttrue,\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (strict) {\n\t\t\treturn receiptCheckIssue(\n\t\t\t\t`Execution receipt verified ledger snapshot is missing for evidence \"${item.claim}\".`,\n\t\t\t\tfalse,\n\t\t\t);\n\t\t}\n\t\tlet latestMutationSeq =\n\t\t\tsnapshot === undefined\n\t\t\t\t? null\n\t\t\t\t: latestRelevantWorkspaceMutationSeq(snapshot.events, receipt.core.workspaceAfter.scope);\n\t\tif (snapshot === undefined && options.resolveLatestWorkspaceMutationSeq !== undefined) {\n\t\t\tlet resolved: unknown;\n\t\t\ttry {\n\t\t\t\tresolved = options.resolveLatestWorkspaceMutationSeq(receipt.core.workspaceAfter.scope);\n\t\t\t} catch {\n\t\t\t\treturn receiptCheckIssue(\n\t\t\t\t\t`Execution receipt workspace-mutation freshness source failed for evidence \"${item.claim}\".`,\n\t\t\t\t\ttrue,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (resolved !== null && resolved !== undefined) {\n\t\t\t\tif (!Number.isSafeInteger(resolved) || (resolved as number) <= 0) {\n\t\t\t\t\treturn receiptCheckIssue(\n\t\t\t\t\t\t`Execution receipt workspace-mutation freshness source is malformed for evidence \"${item.claim}\".`,\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tlatestMutationSeq = resolved as number;\n\t\t\t}\n\t\t}\n\n\t\tconst binding = receipt.envelope.ledgerBinding;\n\t\tif (!binding) {\n\t\t\treturn receiptCheckIssue(\n\t\t\t\t`Execution receipt ledger binding is missing for evidence \"${item.claim}\".`,\n\t\t\t\tlatestMutationSeq !== null,\n\t\t\t);\n\t\t}\n\t\tconst event = snapshot\n\t\t\t? snapshot.events.find((candidate) => candidate.seq === binding.seq)\n\t\t\t: options.resolveLedgerEvent?.(binding.seq);\n\t\tif (!event && snapshot === undefined && !options.resolveLedgerEvent) {\n\t\t\treturn receiptCheckIssue(\n\t\t\t\t`Execution receipt ledger resolver is missing for evidence \"${item.claim}\".`,\n\t\t\t\tlatestMutationSeq !== null,\n\t\t\t);\n\t\t}\n\t\tconst replayPayload = evidenceReceiptReplayPayload(receipt);\n\t\tif (\n\t\t\t!event ||\n\t\t\tevent.seq !== binding.seq ||\n\t\t\tevent.type !== \"evidence_receipt\" ||\n\t\t\tevent.goalId !== contract.goalId ||\n\t\t\tevent.laneId !== receipt.core.laneId ||\n\t\t\t!constantTimeSha256Equal(event.eventHash, binding.eventHash) ||\n\t\t\t!replayPayloadMatches(event.payload, replayPayload.receiptId, replayPayload.coreSha256)\n\t\t) {\n\t\t\treturn receiptCheckIssue(`Execution receipt ledger binding does not match evidence \"${item.claim}\".`, true);\n\t\t}\n\t\tif (latestMutationSeq !== null && event.seq <= latestMutationSeq) {\n\t\t\treturn receiptCheckIssue(\n\t\t\t\t`Execution receipt is stale: workspace mutation seq ${latestMutationSeq} does not precede receipt ledger seq ${event.seq} for evidence \"${item.claim}\".`,\n\t\t\t\ttrue,\n\t\t\t);\n\t\t}\n\t} catch {\n\t\treturn receiptCheckIssue(`Execution receipt is invalid for evidence \"${item.claim}\".`, true);\n\t}\n\treturn undefined;\n}\n\nexport class EvidenceGate {\n\tprivate options: EvidenceGateOptions;\n\n\tconstructor(options: EvidenceGateOptions = {}) {\n\t\tthis.options = {\n\t\t\tminEvidenceCount: 1,\n\t\t\trequireHash: true,\n\t\t\trequireVerificationCommand: true,\n\t\t\treceiptMode: \"prefer\",\n\t\t\t...options,\n\t\t};\n\t}\n\n\tcheck(contract: TaskContract): MergeGateResult {\n\t\tconst evidence = contract.requiredEvidence;\n\t\tconst satisfied = evidence.filter((e) => e.status === \"satisfied\");\n\t\tconst failed = evidence.filter((e) => e.status === \"failed\");\n\t\tconst pending = evidence.filter((e) => e.status === \"pending\" || e.status === \"gathering\");\n\t\tconst mode = this.options.receiptMode ?? \"prefer\";\n\t\tconst checks: string[] = [];\n\t\tlet hardReceiptFailure = false;\n\n\t\tif (satisfied.length < (this.options.minEvidenceCount ?? 1)) {\n\t\t\tchecks.push(`Only ${satisfied.length}/${this.options.minEvidenceCount} required evidence items satisfied.`);\n\t\t}\n\t\tif (failed.length > 0) {\n\t\t\tchecks.push(`${failed.length} evidence item(s) failed.`);\n\t\t}\n\n\t\tif (mode === \"legacy\") {\n\t\t\tif (this.options.requireHash) {\n\t\t\t\tconst hashed = satisfied.filter((e) => e.hash && e.hash.length > 0);\n\t\t\t\tif (hashed.length === 0) checks.push(\"No satisfied evidence has a SHA-256 hash.\");\n\t\t\t}\n\t\t\tif (this.options.requireVerificationCommand) {\n\t\t\t\tconst withCommand = satisfied.filter((e) => e.verificationCommand && e.verificationCommand.length > 0);\n\t\t\t\tif (withCommand.length === 0) checks.push(\"No satisfied evidence has a verification command.\");\n\t\t\t}\n\t\t} else {\n\t\t\tconst unsatisfied = evidence.filter((item) => item.status !== \"satisfied\");\n\t\t\tif (unsatisfied.length > 0) {\n\t\t\t\tchecks.push(`${unsatisfied.length} required evidence item(s) are not satisfied.`);\n\t\t\t}\n\t\t\tfor (const item of satisfied) {\n\t\t\t\tconst issue = receiptIssue(item, contract, this.options);\n\t\t\t\tif (issue) {\n\t\t\t\t\tchecks.push(issue.message);\n\t\t\t\t\thardReceiptFailure ||= issue.hard;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (contract.verdict === \"fail\" || (mode !== \"legacy\" && contract.verdict !== \"pass\")) {\n\t\t\tchecks.push(`Task contract verdict is '${contract.verdict}'.`);\n\t\t}\n\n\t\tlet status: MergeGateStatus;\n\t\tlet reason: string;\n\t\tlet suggestion: string | undefined;\n\t\tif (checks.length === 0) {\n\t\t\tstatus = \"open\";\n\t\t\treason = `Evidence gate passed: ${satisfied.length}/${evidence.length} evidence items satisfied.`;\n\t\t} else {\n\t\t\tconst contractFailure = mode === \"legacy\" ? contract.verdict === \"fail\" : contract.verdict !== \"pass\";\n\t\t\tconst hasHardFailure = failed.length > 0 || contractFailure || hardReceiptFailure || mode === \"strict\";\n\t\t\tstatus = hasHardFailure ? \"blocked\" : mode === \"prefer\" || pending.length > 0 ? \"conditional\" : \"blocked\";\n\t\t\treason = checks.join(\"; \");\n\t\t\tsuggestion = `Gather remaining evidence (${pending.length} pending) and re-run verification.`;\n\t\t}\n\n\t\treturn {\n\t\t\tgateId: \"evidence-gate\",\n\t\t\tstatus,\n\t\t\treason,\n\t\t\tsuggestion,\n\t\t\tevidenceChecked: evidence,\n\t\t};\n\t}\n}\n\n// ============================================================================\n// FailClosedMergeGate\n// ============================================================================\n\nexport class FailClosedMergeGate {\n\tprivate gates: EvidenceGate[];\n\n\tconstructor(gates: EvidenceGate[] = [new EvidenceGate()]) {\n\t\tthis.gates = gates;\n\t}\n\n\tcheck(contract: TaskContract): MergeGateResult {\n\t\tconst results = this.gates.map((gate) => gate.check(contract));\n\t\tconst blocked = results.filter((r) => r.status === \"blocked\");\n\t\tconst conditional = results.filter((r) => r.status === \"conditional\");\n\n\t\tif (blocked.length > 0) {\n\t\t\treturn {\n\t\t\t\tgateId: \"fail-closed-merge-gate\",\n\t\t\t\tstatus: \"blocked\",\n\t\t\t\treason: `Blocked by ${blocked.length} gate(s): ${blocked.map((b) => b.reason).join(\"; \")}`,\n\t\t\t\tsuggestion: \"Resolve all blocking conditions before merge.\",\n\t\t\t\tevidenceChecked: contract.requiredEvidence,\n\t\t\t};\n\t\t}\n\n\t\tif (conditional.length > 0) {\n\t\t\treturn {\n\t\t\t\tgateId: \"fail-closed-merge-gate\",\n\t\t\t\tstatus: \"conditional\",\n\t\t\t\treason: `Conditional pass: ${conditional.length} gate(s) have pending conditions.`,\n\t\t\t\tsuggestion: \"Complete pending evidence or waive with explicit approval.\",\n\t\t\t\tevidenceChecked: contract.requiredEvidence,\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\tgateId: \"fail-closed-merge-gate\",\n\t\t\tstatus: \"open\",\n\t\t\treason: \"All merge gates passed. Evidence verified and contract verdict is acceptable.\",\n\t\t\tevidenceChecked: contract.requiredEvidence,\n\t\t};\n\t}\n}\n\n// ============================================================================\n// Verify Reporter v2\n// ============================================================================\n\n/** Escape pipes/newlines so untrusted claim or command text cannot restructure the report table. */\nfunction escapeTableCell(value: string): string {\n\treturn value.replace(/\\\\/g, \"\\\\\\\\\").replace(/\\|/g, \"\\\\|\").replace(/\\r?\\n/g, \" \");\n}\n\nexport interface VerifyReporterV2Options {\n\toutputDir: string;\n\tgoalId: string;\n}\n\nexport class VerifyReporterV2 {\n\tprivate options: VerifyReporterV2Options;\n\n\tconstructor(options: VerifyReporterV2Options) {\n\t\tthis.options = options;\n\t}\n\n\trender(contract: TaskContract, mergeGate: MergeGateResult): string {\n\t\tconst lines: string[] = [\n\t\t\t`## OMK Verification Report v2 — ${contract.goalId}`,\n\t\t\t\"\",\n\t\t\t\"### Contract\",\n\t\t\t\"\",\n\t\t\t`| Field | Value |`,\n\t\t\t`|-------|-------|`,\n\t\t\t`| Claim | ${escapeTableCell(contract.completionClaim)} |`,\n\t\t\t`| Verdict | ${contract.verdict} |`,\n\t\t\t`| Final Risk | ${escapeTableCell(contract.finalRisk)} |`,\n\t\t\t\"\",\n\t\t\t\"### Evidence\",\n\t\t\t\"\",\n\t\t\t`| Claim | Status | Artifact | Command |`,\n\t\t\t`|-------|--------|----------|----------|`,\n\t\t];\n\n\t\tfor (const ev of contract.requiredEvidence) {\n\t\t\tlines.push(\n\t\t\t\t`| ${escapeTableCell(ev.claim)} | ${ev.status} | ${escapeTableCell(ev.artifactPath ?? \"—\")} | ${escapeTableCell(ev.verificationCommand ?? \"—\")} |`,\n\t\t\t);\n\t\t}\n\n\t\tlines.push(\n\t\t\t\"\",\n\t\t\t\"### Merge Gate\",\n\t\t\t\"\",\n\t\t\t`| Gate | Status | Reason |`,\n\t\t\t`|------|--------|--------|`,\n\t\t\t`| ${mergeGate.gateId} | ${mergeGate.status} | ${escapeTableCell(mergeGate.reason)} |`,\n\t\t\t\"\",\n\t\t);\n\n\t\tif (mergeGate.suggestion) {\n\t\t\tlines.push(`**Suggestion:** ${mergeGate.suggestion}`, \"\");\n\t\t}\n\n\t\treturn lines.join(\"\\n\");\n\t}\n\n\twrite(contract: TaskContract, mergeGate: MergeGateResult): string {\n\t\tconst markdown = this.render(contract, mergeGate);\n\t\tconst path = join(this.options.outputDir, `${this.options.goalId}.verify.md`);\n\t\tensureDir(path);\n\t\twriteFileSync(path, markdown, \"utf-8\");\n\t\treturn path;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replay-ledger-lock-owner.d.ts","sourceRoot":"","sources":["../../src/guardrails/replay-ledger-lock-owner.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,SAAS,GAAG;IACvB,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC;IAC1B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC/B,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,2BAA2B,GACpC;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAC1D;IAAE,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAA;CAAE,GAC5B;IAAE,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAA;CAAE,CAAC;AAErC,MAAM,MAAM,iCAAiC,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,2BAA2B,CAAC;AAE7F,qBAAa,qBAAsB,SAAQ,KAAK;IAC/C,QAAQ,CAAC,IAAI,2BAA2B;CACxC;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAG5D;
|
|
1
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GAAG,SAAS,CAY7F;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,iCAAiC,GAAG,OAAO,CAU7G;AAED,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,MAAM,GAAG,2BAA2B,CAavF;AAED;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAAC,MAAM,EAAE,MAAM,GAAG,2BAA2B,CAM5F;AAgBD,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,2BAA2B,CAS/E","sourcesContent":["import { spawnSync } from \"node:child_process\";\nimport { randomUUID } from \"node:crypto\";\nimport { closeSync, constants as fsConstants, fstatSync, openSync, readFileSync } from \"node:fs\";\n\nconst MAX_LOCK_RECORD_BYTES = 512;\nconst MAX_CLOCK_SKEW_MS = 60_000;\n/** Hard bounds on what one `ps` child process may contribute on Darwin. */\nconst DARWIN_PS_TIMEOUT_MS = 5_000;\nconst DARWIN_PS_MAX_OUTPUT_BYTES = 4_096;\nconst MAX_DARWIN_LSTART_CHARS = 512;\nconst OWNER_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;\nconst PROCESS_START_TOKEN = /^[A-Za-z0-9._:-]{1,128}$/;\n\nexport type LockOwner = {\n\treadonly schemaVersion: 2;\n\treadonly pid: number;\n\treadonly processStartToken: string | null;\n\treadonly acquiredAtMs: number;\n\treadonly ownerId: string;\n};\n\nexport type LockOwnerSnapshot = {\n\treadonly owner: LockOwner;\n\treadonly dev: string;\n\treadonly ino: string;\n};\n\nexport type ReplayLedgerProcessIdentity =\n\t| { readonly state: \"present\"; readonly startToken: string }\n\t| { readonly state: \"absent\" }\n\t| { readonly state: \"unavailable\" };\n\nexport type ReplayLedgerProcessIdentityReader = (pid: number) => ReplayLedgerProcessIdentity;\n\nexport class ReplayLedgerLockError extends Error {\n\treadonly name = \"ReplayLedgerLockError\";\n}\n\nexport function errorCode(error: unknown): string | undefined {\n\tif (typeof error !== \"object\" || error === null || !(\"code\" in error)) return undefined;\n\treturn typeof error.code === \"string\" ? error.code : undefined;\n}\n\nfunction ownerInteger(value: unknown): number {\n\tif (typeof value !== \"number\" || !Number.isSafeInteger(value) || value <= 0) {\n\t\tthrow new ReplayLedgerLockError(\"replay lock owner record is invalid\");\n\t}\n\treturn value;\n}\n\nfunction parseOwner(bytes: Buffer): LockOwner {\n\tif (bytes.byteLength === 0 || bytes.byteLength > MAX_LOCK_RECORD_BYTES) {\n\t\tthrow new ReplayLedgerLockError(\"replay lock owner record is outside its size bound\");\n\t}\n\tlet value: unknown;\n\ttry {\n\t\tvalue = JSON.parse(bytes.toString(\"utf8\"));\n\t} catch (error) {\n\t\tconst malformed = new ReplayLedgerLockError(\"replay lock owner record is malformed\");\n\t\tObject.defineProperty(malformed, \"cause\", { configurable: true, value: error, writable: true });\n\t\tthrow malformed;\n\t}\n\tif (\n\t\ttypeof value !== \"object\" ||\n\t\tvalue === null ||\n\t\tArray.isArray(value) ||\n\t\tObject.keys(value).sort().join(\",\") !== \"acquiredAtMs,ownerId,pid,processStartToken,schemaVersion\" ||\n\t\t!(\"schemaVersion\" in value) ||\n\t\tvalue.schemaVersion !== 2 ||\n\t\t!(\"pid\" in value) ||\n\t\t!(\"processStartToken\" in value) ||\n\t\t!(\"acquiredAtMs\" in value) ||\n\t\t!(\"ownerId\" in value) ||\n\t\ttypeof value.ownerId !== \"string\" ||\n\t\t!OWNER_ID.test(value.ownerId) ||\n\t\t(value.processStartToken !== null &&\n\t\t\t(typeof value.processStartToken !== \"string\" || !PROCESS_START_TOKEN.test(value.processStartToken)))\n\t) {\n\t\tthrow new ReplayLedgerLockError(\"replay lock owner record is invalid\");\n\t}\n\tconst pid = ownerInteger(value.pid);\n\tconst acquiredAtMs = ownerInteger(value.acquiredAtMs);\n\tif (acquiredAtMs > Date.now() + MAX_CLOCK_SKEW_MS) {\n\t\tthrow new ReplayLedgerLockError(\"replay lock owner record is invalid\");\n\t}\n\treturn { schemaVersion: 2, pid, processStartToken: value.processStartToken, acquiredAtMs, ownerId: value.ownerId };\n}\n\nexport function readLockOwner(path: string): LockOwnerSnapshot {\n\tconst fd = openSync(path, fsConstants.O_RDONLY | (fsConstants.O_NOFOLLOW ?? 0));\n\ttry {\n\t\tconst before = fstatSync(fd, { bigint: true });\n\t\tif (!before.isFile() || before.size <= 0n || before.size > BigInt(MAX_LOCK_RECORD_BYTES)) {\n\t\t\tthrow new ReplayLedgerLockError(\"replay lock owner record is outside its size bound\");\n\t\t}\n\t\tconst bytes = readFileSync(fd);\n\t\tconst after = fstatSync(fd, { bigint: true });\n\t\tif (\n\t\t\tbefore.dev !== after.dev ||\n\t\t\tbefore.ino !== after.ino ||\n\t\t\tbefore.size !== after.size ||\n\t\t\tafter.size !== BigInt(bytes.length)\n\t\t) {\n\t\t\tthrow new ReplayLedgerLockError(\"replay lock owner record changed during inspection\");\n\t\t}\n\t\treturn { owner: parseOwner(bytes), dev: String(after.dev), ino: String(after.ino) };\n\t} finally {\n\t\tcloseSync(fd);\n\t}\n}\n\nexport function lockOwnersEqual(left: LockOwnerSnapshot, right: LockOwnerSnapshot): boolean {\n\treturn (\n\t\tleft.dev === right.dev &&\n\t\tleft.ino === right.ino &&\n\t\tleft.owner.ownerId === right.owner.ownerId &&\n\t\tleft.owner.pid === right.owner.pid &&\n\t\tleft.owner.processStartToken === right.owner.processStartToken &&\n\t\tleft.owner.acquiredAtMs === right.owner.acquiredAtMs\n\t);\n}\n\nexport function createLockOwner(processIdentity: ReplayLedgerProcessIdentityReader): LockOwner {\n\tconst identity = processIdentity(process.pid);\n\tif (identity.state !== \"present\" || !PROCESS_START_TOKEN.test(identity.startToken)) {\n\t\tthrow new ReplayLedgerLockError(\"replay lock acquisition requires process-start identity\");\n\t}\n\treturn {\n\t\tschemaVersion: 2,\n\t\tpid: process.pid,\n\t\tprocessStartToken: identity.startToken,\n\t\tacquiredAtMs: Date.now(),\n\t\townerId: randomUUID(),\n\t};\n}\n\nexport function lockOwnerIsDead(owner: LockOwner, processIdentity: ReplayLedgerProcessIdentityReader): boolean {\n\tconst current = processIdentity(owner.pid);\n\tif (current.state === \"unavailable\") {\n\t\tthrow new ReplayLedgerLockError(\"replay lock owner liveness could not be established\");\n\t}\n\tif (current.state === \"absent\") return true;\n\tif (owner.processStartToken === null) {\n\t\tthrow new ReplayLedgerLockError(\"replay lock recovery requires process-start identity\");\n\t}\n\treturn current.startToken !== owner.processStartToken;\n}\n\nexport function parseLinuxProcessIdentityStat(stat: string): ReplayLedgerProcessIdentity {\n\tif (stat.length > 4_096) return { state: \"unavailable\" };\n\tconst close = stat.lastIndexOf(\")\");\n\tif (close < 0) return { state: \"unavailable\" };\n\tconst fields = stat\n\t\t.slice(close + 2)\n\t\t.trim()\n\t\t.split(/\\s+/);\n\tif ([\"Z\", \"X\", \"x\"].includes(fields[0] ?? \"\")) return { state: \"absent\" };\n\tconst startTime = fields[19];\n\treturn startTime !== undefined && /^\\d+$/.test(startTime)\n\t\t? { state: \"present\", startToken: `linux:${startTime}` }\n\t\t: { state: \"unavailable\" };\n}\n\n/**\n * Parses BSD `ps -o lstart=` output (e.g. `Wed Aug 12 14:30:00 2026`).\n * lstart is fixed for the lifetime of a pid, so `darwin:<epochMs>` is a\n * stable per-process-instance token accepted by PROCESS_START_TOKEN.\n * Empty output means ps matched no process; anything unparseable fails closed.\n */\nexport function parseDarwinProcessIdentityLstart(lstart: string): ReplayLedgerProcessIdentity {\n\tconst trimmed = lstart.trim();\n\tif (trimmed === \"\") return { state: \"absent\" };\n\tif (trimmed.length > MAX_DARWIN_LSTART_CHARS) return { state: \"unavailable\" };\n\tconst epochMs = Date.parse(trimmed);\n\treturn Number.isFinite(epochMs) ? { state: \"present\", startToken: `darwin:${epochMs}` } : { state: \"unavailable\" };\n}\n\nfunction inspectDarwinProcessIdentity(pid: number): ReplayLedgerProcessIdentity {\n\tif (!Number.isSafeInteger(pid) || pid <= 0) return { state: \"unavailable\" };\n\tconst result = spawnSync(\"ps\", [\"-o\", \"lstart=\", \"-p\", String(pid)], {\n\t\tencoding: \"utf8\",\n\t\ttimeout: DARWIN_PS_TIMEOUT_MS,\n\t\tmaxBuffer: DARWIN_PS_MAX_OUTPUT_BYTES,\n\t});\n\tif (result.error) return { state: \"unavailable\" };\n\t// BSD ps exits 1 when no process matches the pid; other non-zero is fail-closed.\n\tif (result.status === 1) return { state: \"absent\" };\n\tif (result.status !== 0) return { state: \"unavailable\" };\n\treturn parseDarwinProcessIdentityLstart(result.stdout ?? \"\");\n}\n\nexport function inspectProcessIdentity(pid: number): ReplayLedgerProcessIdentity {\n\tif (process.platform === \"darwin\") return inspectDarwinProcessIdentity(pid);\n\tif (process.platform !== \"linux\") return { state: \"unavailable\" };\n\ttry {\n\t\treturn parseLinuxProcessIdentityStat(readFileSync(`/proc/${pid}/stat`, \"utf8\"));\n\t} catch (error) {\n\t\tif (!(error instanceof Error)) throw error;\n\t\treturn errorCode(error) === \"ENOENT\" ? { state: \"absent\" } : { state: \"unavailable\" };\n\t}\n}\n"]}
|
|
@@ -32,7 +32,9 @@ function parseOwner(bytes) {
|
|
|
32
32
|
value = JSON.parse(bytes.toString("utf8"));
|
|
33
33
|
}
|
|
34
34
|
catch (error) {
|
|
35
|
-
|
|
35
|
+
const malformed = new ReplayLedgerLockError("replay lock owner record is malformed");
|
|
36
|
+
Object.defineProperty(malformed, "cause", { configurable: true, value: error, writable: true });
|
|
37
|
+
throw malformed;
|
|
36
38
|
}
|
|
37
39
|
if (typeof value !== "object" ||
|
|
38
40
|
value === null ||
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replay-ledger-lock-owner.js","sourceRoot":"","sources":["../../src/guardrails/replay-ledger-lock-owner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,SAAS,IAAI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AAM,KAAK,CAAC;QAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC;IACzD,OAAO,gCAAgC,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;AAAA,CAC7D;AAED,MAAM,UAAU,sBAAsB,CAAC,GAAW,EAA+B;IAChF,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ;QAAE,OAAO,4BAA4B,CAAC,GAAG,CAAC,CAAC;IAC5E,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO;QAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC;IAClE,IAAI,CAAC;QACJ,OAAO,6BAA6B,CAAC,YAAY,CAAC,SAAS,GAAG,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;IACjF,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;YAAE,MAAM,KAAK,CAAC;QAC3C,OAAO,SAAS,CAAC,KAAK,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC;IACvF,CAAC;AAAA,CACD","sourcesContent":["import { spawnSync } from \"node:child_process\";\nimport { randomUUID } from \"node:crypto\";\nimport { closeSync, constants as fsConstants, fstatSync, openSync, readFileSync } from \"node:fs\";\n\nconst MAX_LOCK_RECORD_BYTES = 512;\nconst MAX_CLOCK_SKEW_MS = 60_000;\n/** Hard bounds on what one `ps` child process may contribute on Darwin. */\nconst DARWIN_PS_TIMEOUT_MS = 5_000;\nconst DARWIN_PS_MAX_OUTPUT_BYTES = 4_096;\nconst MAX_DARWIN_LSTART_CHARS = 512;\nconst OWNER_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;\nconst PROCESS_START_TOKEN = /^[A-Za-z0-9._:-]{1,128}$/;\n\nexport type LockOwner = {\n\treadonly schemaVersion: 2;\n\treadonly pid: number;\n\treadonly processStartToken: string | null;\n\treadonly acquiredAtMs: number;\n\treadonly ownerId: string;\n};\n\nexport type LockOwnerSnapshot = {\n\treadonly owner: LockOwner;\n\treadonly dev: string;\n\treadonly ino: string;\n};\n\nexport type ReplayLedgerProcessIdentity =\n\t| { readonly state: \"present\"; readonly startToken: string }\n\t| { readonly state: \"absent\" }\n\t| { readonly state: \"unavailable\" };\n\nexport type ReplayLedgerProcessIdentityReader = (pid: number) => ReplayLedgerProcessIdentity;\n\nexport class ReplayLedgerLockError extends Error {\n\treadonly name = \"ReplayLedgerLockError\";\n}\n\nexport function errorCode(error: unknown): string | undefined {\n\tif (typeof error !== \"object\" || error === null || !(\"code\" in error)) return undefined;\n\treturn typeof error.code === \"string\" ? error.code : undefined;\n}\n\nfunction ownerInteger(value: unknown): number {\n\tif (typeof value !== \"number\" || !Number.isSafeInteger(value) || value <= 0) {\n\t\tthrow new ReplayLedgerLockError(\"replay lock owner record is invalid\");\n\t}\n\treturn value;\n}\n\nfunction parseOwner(bytes: Buffer): LockOwner {\n\tif (bytes.byteLength === 0 || bytes.byteLength > MAX_LOCK_RECORD_BYTES) {\n\t\tthrow new ReplayLedgerLockError(\"replay lock owner record is outside its size bound\");\n\t}\n\tlet value: unknown;\n\ttry {\n\t\tvalue = JSON.parse(bytes.toString(\"utf8\"));\n\t} catch (error) {\n\t\tthrow new ReplayLedgerLockError(\"replay lock owner record is malformed\", { cause: error });\n\t}\n\tif (\n\t\ttypeof value !== \"object\" ||\n\t\tvalue === null ||\n\t\tArray.isArray(value) ||\n\t\tObject.keys(value).sort().join(\",\") !== \"acquiredAtMs,ownerId,pid,processStartToken,schemaVersion\" ||\n\t\t!(\"schemaVersion\" in value) ||\n\t\tvalue.schemaVersion !== 2 ||\n\t\t!(\"pid\" in value) ||\n\t\t!(\"processStartToken\" in value) ||\n\t\t!(\"acquiredAtMs\" in value) ||\n\t\t!(\"ownerId\" in value) ||\n\t\ttypeof value.ownerId !== \"string\" ||\n\t\t!OWNER_ID.test(value.ownerId) ||\n\t\t(value.processStartToken !== null &&\n\t\t\t(typeof value.processStartToken !== \"string\" || !PROCESS_START_TOKEN.test(value.processStartToken)))\n\t) {\n\t\tthrow new ReplayLedgerLockError(\"replay lock owner record is invalid\");\n\t}\n\tconst pid = ownerInteger(value.pid);\n\tconst acquiredAtMs = ownerInteger(value.acquiredAtMs);\n\tif (acquiredAtMs > Date.now() + MAX_CLOCK_SKEW_MS) {\n\t\tthrow new ReplayLedgerLockError(\"replay lock owner record is invalid\");\n\t}\n\treturn { schemaVersion: 2, pid, processStartToken: value.processStartToken, acquiredAtMs, ownerId: value.ownerId };\n}\n\nexport function readLockOwner(path: string): LockOwnerSnapshot {\n\tconst fd = openSync(path, fsConstants.O_RDONLY | (fsConstants.O_NOFOLLOW ?? 0));\n\ttry {\n\t\tconst before = fstatSync(fd, { bigint: true });\n\t\tif (!before.isFile() || before.size <= 0n || before.size > BigInt(MAX_LOCK_RECORD_BYTES)) {\n\t\t\tthrow new ReplayLedgerLockError(\"replay lock owner record is outside its size bound\");\n\t\t}\n\t\tconst bytes = readFileSync(fd);\n\t\tconst after = fstatSync(fd, { bigint: true });\n\t\tif (\n\t\t\tbefore.dev !== after.dev ||\n\t\t\tbefore.ino !== after.ino ||\n\t\t\tbefore.size !== after.size ||\n\t\t\tafter.size !== BigInt(bytes.length)\n\t\t) {\n\t\t\tthrow new ReplayLedgerLockError(\"replay lock owner record changed during inspection\");\n\t\t}\n\t\treturn { owner: parseOwner(bytes), dev: String(after.dev), ino: String(after.ino) };\n\t} finally {\n\t\tcloseSync(fd);\n\t}\n}\n\nexport function lockOwnersEqual(left: LockOwnerSnapshot, right: LockOwnerSnapshot): boolean {\n\treturn (\n\t\tleft.dev === right.dev &&\n\t\tleft.ino === right.ino &&\n\t\tleft.owner.ownerId === right.owner.ownerId &&\n\t\tleft.owner.pid === right.owner.pid &&\n\t\tleft.owner.processStartToken === right.owner.processStartToken &&\n\t\tleft.owner.acquiredAtMs === right.owner.acquiredAtMs\n\t);\n}\n\nexport function createLockOwner(processIdentity: ReplayLedgerProcessIdentityReader): LockOwner {\n\tconst identity = processIdentity(process.pid);\n\tif (identity.state !== \"present\" || !PROCESS_START_TOKEN.test(identity.startToken)) {\n\t\tthrow new ReplayLedgerLockError(\"replay lock acquisition requires process-start identity\");\n\t}\n\treturn {\n\t\tschemaVersion: 2,\n\t\tpid: process.pid,\n\t\tprocessStartToken: identity.startToken,\n\t\tacquiredAtMs: Date.now(),\n\t\townerId: randomUUID(),\n\t};\n}\n\nexport function lockOwnerIsDead(owner: LockOwner, processIdentity: ReplayLedgerProcessIdentityReader): boolean {\n\tconst current = processIdentity(owner.pid);\n\tif (current.state === \"unavailable\") {\n\t\tthrow new ReplayLedgerLockError(\"replay lock owner liveness could not be established\");\n\t}\n\tif (current.state === \"absent\") return true;\n\tif (owner.processStartToken === null) {\n\t\tthrow new ReplayLedgerLockError(\"replay lock recovery requires process-start identity\");\n\t}\n\treturn current.startToken !== owner.processStartToken;\n}\n\nexport function parseLinuxProcessIdentityStat(stat: string): ReplayLedgerProcessIdentity {\n\tif (stat.length > 4_096) return { state: \"unavailable\" };\n\tconst close = stat.lastIndexOf(\")\");\n\tif (close < 0) return { state: \"unavailable\" };\n\tconst fields = stat\n\t\t.slice(close + 2)\n\t\t.trim()\n\t\t.split(/\\s+/);\n\tif ([\"Z\", \"X\", \"x\"].includes(fields[0] ?? \"\")) return { state: \"absent\" };\n\tconst startTime = fields[19];\n\treturn startTime !== undefined && /^\\d+$/.test(startTime)\n\t\t? { state: \"present\", startToken: `linux:${startTime}` }\n\t\t: { state: \"unavailable\" };\n}\n\n/**\n * Parses BSD `ps -o lstart=` output (e.g. `Wed Aug 12 14:30:00 2026`).\n * lstart is fixed for the lifetime of a pid, so `darwin:<epochMs>` is a\n * stable per-process-instance token accepted by PROCESS_START_TOKEN.\n * Empty output means ps matched no process; anything unparseable fails closed.\n */\nexport function parseDarwinProcessIdentityLstart(lstart: string): ReplayLedgerProcessIdentity {\n\tconst trimmed = lstart.trim();\n\tif (trimmed === \"\") return { state: \"absent\" };\n\tif (trimmed.length > MAX_DARWIN_LSTART_CHARS) return { state: \"unavailable\" };\n\tconst epochMs = Date.parse(trimmed);\n\treturn Number.isFinite(epochMs) ? { state: \"present\", startToken: `darwin:${epochMs}` } : { state: \"unavailable\" };\n}\n\nfunction inspectDarwinProcessIdentity(pid: number): ReplayLedgerProcessIdentity {\n\tif (!Number.isSafeInteger(pid) || pid <= 0) return { state: \"unavailable\" };\n\tconst result = spawnSync(\"ps\", [\"-o\", \"lstart=\", \"-p\", String(pid)], {\n\t\tencoding: \"utf8\",\n\t\ttimeout: DARWIN_PS_TIMEOUT_MS,\n\t\tmaxBuffer: DARWIN_PS_MAX_OUTPUT_BYTES,\n\t});\n\tif (result.error) return { state: \"unavailable\" };\n\t// BSD ps exits 1 when no process matches the pid; other non-zero is fail-closed.\n\tif (result.status === 1) return { state: \"absent\" };\n\tif (result.status !== 0) return { state: \"unavailable\" };\n\treturn parseDarwinProcessIdentityLstart(result.stdout ?? \"\");\n}\n\nexport function inspectProcessIdentity(pid: number): ReplayLedgerProcessIdentity {\n\tif (process.platform === \"darwin\") return inspectDarwinProcessIdentity(pid);\n\tif (process.platform !== \"linux\") return { state: \"unavailable\" };\n\ttry {\n\t\treturn parseLinuxProcessIdentityStat(readFileSync(`/proc/${pid}/stat`, \"utf8\"));\n\t} catch (error) {\n\t\tif (!(error instanceof Error)) throw error;\n\t\treturn errorCode(error) === \"ENOENT\" ? { state: \"absent\" } : { state: \"unavailable\" };\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"replay-ledger-lock-owner.js","sourceRoot":"","sources":["../../src/guardrails/replay-ledger-lock-owner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,C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AAC,KAAK;QAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC;IAClD,iFAAiF;IACjF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;IACpD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC;IACzD,OAAO,gCAAgC,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;AAAA,CAC7D;AAED,MAAM,UAAU,sBAAsB,CAAC,GAAW,EAA+B;IAChF,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ;QAAE,OAAO,4BAA4B,CAAC,GAAG,CAAC,CAAC;IAC5E,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO;QAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC;IAClE,IAAI,CAAC;QACJ,OAAO,6BAA6B,CAAC,YAAY,CAAC,SAAS,GAAG,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;IACjF,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;YAAE,MAAM,KAAK,CAAC;QAC3C,OAAO,SAAS,CAAC,KAAK,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC;IACvF,CAAC;AAAA,CACD","sourcesContent":["import { spawnSync } from \"node:child_process\";\nimport { randomUUID } from \"node:crypto\";\nimport { closeSync, constants as fsConstants, fstatSync, openSync, readFileSync } from \"node:fs\";\n\nconst MAX_LOCK_RECORD_BYTES = 512;\nconst MAX_CLOCK_SKEW_MS = 60_000;\n/** Hard bounds on what one `ps` child process may contribute on Darwin. */\nconst DARWIN_PS_TIMEOUT_MS = 5_000;\nconst DARWIN_PS_MAX_OUTPUT_BYTES = 4_096;\nconst MAX_DARWIN_LSTART_CHARS = 512;\nconst OWNER_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;\nconst PROCESS_START_TOKEN = /^[A-Za-z0-9._:-]{1,128}$/;\n\nexport type LockOwner = {\n\treadonly schemaVersion: 2;\n\treadonly pid: number;\n\treadonly processStartToken: string | null;\n\treadonly acquiredAtMs: number;\n\treadonly ownerId: string;\n};\n\nexport type LockOwnerSnapshot = {\n\treadonly owner: LockOwner;\n\treadonly dev: string;\n\treadonly ino: string;\n};\n\nexport type ReplayLedgerProcessIdentity =\n\t| { readonly state: \"present\"; readonly startToken: string }\n\t| { readonly state: \"absent\" }\n\t| { readonly state: \"unavailable\" };\n\nexport type ReplayLedgerProcessIdentityReader = (pid: number) => ReplayLedgerProcessIdentity;\n\nexport class ReplayLedgerLockError extends Error {\n\treadonly name = \"ReplayLedgerLockError\";\n}\n\nexport function errorCode(error: unknown): string | undefined {\n\tif (typeof error !== \"object\" || error === null || !(\"code\" in error)) return undefined;\n\treturn typeof error.code === \"string\" ? error.code : undefined;\n}\n\nfunction ownerInteger(value: unknown): number {\n\tif (typeof value !== \"number\" || !Number.isSafeInteger(value) || value <= 0) {\n\t\tthrow new ReplayLedgerLockError(\"replay lock owner record is invalid\");\n\t}\n\treturn value;\n}\n\nfunction parseOwner(bytes: Buffer): LockOwner {\n\tif (bytes.byteLength === 0 || bytes.byteLength > MAX_LOCK_RECORD_BYTES) {\n\t\tthrow new ReplayLedgerLockError(\"replay lock owner record is outside its size bound\");\n\t}\n\tlet value: unknown;\n\ttry {\n\t\tvalue = JSON.parse(bytes.toString(\"utf8\"));\n\t} catch (error) {\n\t\tconst malformed = new ReplayLedgerLockError(\"replay lock owner record is malformed\");\n\t\tObject.defineProperty(malformed, \"cause\", { configurable: true, value: error, writable: true });\n\t\tthrow malformed;\n\t}\n\tif (\n\t\ttypeof value !== \"object\" ||\n\t\tvalue === null ||\n\t\tArray.isArray(value) ||\n\t\tObject.keys(value).sort().join(\",\") !== \"acquiredAtMs,ownerId,pid,processStartToken,schemaVersion\" ||\n\t\t!(\"schemaVersion\" in value) ||\n\t\tvalue.schemaVersion !== 2 ||\n\t\t!(\"pid\" in value) ||\n\t\t!(\"processStartToken\" in value) ||\n\t\t!(\"acquiredAtMs\" in value) ||\n\t\t!(\"ownerId\" in value) ||\n\t\ttypeof value.ownerId !== \"string\" ||\n\t\t!OWNER_ID.test(value.ownerId) ||\n\t\t(value.processStartToken !== null &&\n\t\t\t(typeof value.processStartToken !== \"string\" || !PROCESS_START_TOKEN.test(value.processStartToken)))\n\t) {\n\t\tthrow new ReplayLedgerLockError(\"replay lock owner record is invalid\");\n\t}\n\tconst pid = ownerInteger(value.pid);\n\tconst acquiredAtMs = ownerInteger(value.acquiredAtMs);\n\tif (acquiredAtMs > Date.now() + MAX_CLOCK_SKEW_MS) {\n\t\tthrow new ReplayLedgerLockError(\"replay lock owner record is invalid\");\n\t}\n\treturn { schemaVersion: 2, pid, processStartToken: value.processStartToken, acquiredAtMs, ownerId: value.ownerId };\n}\n\nexport function readLockOwner(path: string): LockOwnerSnapshot {\n\tconst fd = openSync(path, fsConstants.O_RDONLY | (fsConstants.O_NOFOLLOW ?? 0));\n\ttry {\n\t\tconst before = fstatSync(fd, { bigint: true });\n\t\tif (!before.isFile() || before.size <= 0n || before.size > BigInt(MAX_LOCK_RECORD_BYTES)) {\n\t\t\tthrow new ReplayLedgerLockError(\"replay lock owner record is outside its size bound\");\n\t\t}\n\t\tconst bytes = readFileSync(fd);\n\t\tconst after = fstatSync(fd, { bigint: true });\n\t\tif (\n\t\t\tbefore.dev !== after.dev ||\n\t\t\tbefore.ino !== after.ino ||\n\t\t\tbefore.size !== after.size ||\n\t\t\tafter.size !== BigInt(bytes.length)\n\t\t) {\n\t\t\tthrow new ReplayLedgerLockError(\"replay lock owner record changed during inspection\");\n\t\t}\n\t\treturn { owner: parseOwner(bytes), dev: String(after.dev), ino: String(after.ino) };\n\t} finally {\n\t\tcloseSync(fd);\n\t}\n}\n\nexport function lockOwnersEqual(left: LockOwnerSnapshot, right: LockOwnerSnapshot): boolean {\n\treturn (\n\t\tleft.dev === right.dev &&\n\t\tleft.ino === right.ino &&\n\t\tleft.owner.ownerId === right.owner.ownerId &&\n\t\tleft.owner.pid === right.owner.pid &&\n\t\tleft.owner.processStartToken === right.owner.processStartToken &&\n\t\tleft.owner.acquiredAtMs === right.owner.acquiredAtMs\n\t);\n}\n\nexport function createLockOwner(processIdentity: ReplayLedgerProcessIdentityReader): LockOwner {\n\tconst identity = processIdentity(process.pid);\n\tif (identity.state !== \"present\" || !PROCESS_START_TOKEN.test(identity.startToken)) {\n\t\tthrow new ReplayLedgerLockError(\"replay lock acquisition requires process-start identity\");\n\t}\n\treturn {\n\t\tschemaVersion: 2,\n\t\tpid: process.pid,\n\t\tprocessStartToken: identity.startToken,\n\t\tacquiredAtMs: Date.now(),\n\t\townerId: randomUUID(),\n\t};\n}\n\nexport function lockOwnerIsDead(owner: LockOwner, processIdentity: ReplayLedgerProcessIdentityReader): boolean {\n\tconst current = processIdentity(owner.pid);\n\tif (current.state === \"unavailable\") {\n\t\tthrow new ReplayLedgerLockError(\"replay lock owner liveness could not be established\");\n\t}\n\tif (current.state === \"absent\") return true;\n\tif (owner.processStartToken === null) {\n\t\tthrow new ReplayLedgerLockError(\"replay lock recovery requires process-start identity\");\n\t}\n\treturn current.startToken !== owner.processStartToken;\n}\n\nexport function parseLinuxProcessIdentityStat(stat: string): ReplayLedgerProcessIdentity {\n\tif (stat.length > 4_096) return { state: \"unavailable\" };\n\tconst close = stat.lastIndexOf(\")\");\n\tif (close < 0) return { state: \"unavailable\" };\n\tconst fields = stat\n\t\t.slice(close + 2)\n\t\t.trim()\n\t\t.split(/\\s+/);\n\tif ([\"Z\", \"X\", \"x\"].includes(fields[0] ?? \"\")) return { state: \"absent\" };\n\tconst startTime = fields[19];\n\treturn startTime !== undefined && /^\\d+$/.test(startTime)\n\t\t? { state: \"present\", startToken: `linux:${startTime}` }\n\t\t: { state: \"unavailable\" };\n}\n\n/**\n * Parses BSD `ps -o lstart=` output (e.g. `Wed Aug 12 14:30:00 2026`).\n * lstart is fixed for the lifetime of a pid, so `darwin:<epochMs>` is a\n * stable per-process-instance token accepted by PROCESS_START_TOKEN.\n * Empty output means ps matched no process; anything unparseable fails closed.\n */\nexport function parseDarwinProcessIdentityLstart(lstart: string): ReplayLedgerProcessIdentity {\n\tconst trimmed = lstart.trim();\n\tif (trimmed === \"\") return { state: \"absent\" };\n\tif (trimmed.length > MAX_DARWIN_LSTART_CHARS) return { state: \"unavailable\" };\n\tconst epochMs = Date.parse(trimmed);\n\treturn Number.isFinite(epochMs) ? { state: \"present\", startToken: `darwin:${epochMs}` } : { state: \"unavailable\" };\n}\n\nfunction inspectDarwinProcessIdentity(pid: number): ReplayLedgerProcessIdentity {\n\tif (!Number.isSafeInteger(pid) || pid <= 0) return { state: \"unavailable\" };\n\tconst result = spawnSync(\"ps\", [\"-o\", \"lstart=\", \"-p\", String(pid)], {\n\t\tencoding: \"utf8\",\n\t\ttimeout: DARWIN_PS_TIMEOUT_MS,\n\t\tmaxBuffer: DARWIN_PS_MAX_OUTPUT_BYTES,\n\t});\n\tif (result.error) return { state: \"unavailable\" };\n\t// BSD ps exits 1 when no process matches the pid; other non-zero is fail-closed.\n\tif (result.status === 1) return { state: \"absent\" };\n\tif (result.status !== 0) return { state: \"unavailable\" };\n\treturn parseDarwinProcessIdentityLstart(result.stdout ?? \"\");\n}\n\nexport function inspectProcessIdentity(pid: number): ReplayLedgerProcessIdentity {\n\tif (process.platform === \"darwin\") return inspectDarwinProcessIdentity(pid);\n\tif (process.platform !== \"linux\") return { state: \"unavailable\" };\n\ttry {\n\t\treturn parseLinuxProcessIdentityStat(readFileSync(`/proc/${pid}/stat`, \"utf8\"));\n\t} catch (error) {\n\t\tif (!(error instanceof Error)) throw error;\n\t\treturn errorCode(error) === \"ENOENT\" ? { state: \"absent\" } : { state: \"unavailable\" };\n\t}\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ReplayPayloadHashAlgorithm } from "../types/evidence.ts";
|
|
2
|
+
export declare const LEGACY_REPLAY_PAYLOAD_HASH_ALGORITHM: "json-stringify-v1";
|
|
3
|
+
export declare const JCS_REPLAY_PAYLOAD_HASH_ALGORITHM: "jcs-rfc8785-v2";
|
|
4
|
+
export declare function serializeReplayPayload(payload: unknown, algorithm: ReplayPayloadHashAlgorithm): string;
|
|
5
|
+
export declare function computeReplayPayloadHash(payload: unknown, algorithm: ReplayPayloadHashAlgorithm): string;
|
|
6
|
+
//# sourceMappingURL=replay-payload-hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay-payload-hash.d.ts","sourceRoot":"","sources":["../../src/guardrails/replay-payload-hash.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAEvE,eAAO,MAAM,oCAAoC,qBAA+B,CAAC;AACjF,eAAO,MAAM,iCAAiC,kBAA4B,CAAC;AAE3E,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,0BAA0B,GAAG,MAAM,CAatG;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,0BAA0B,GAAG,MAAM,CAExG","sourcesContent":["import { createHash } from \"node:crypto\";\nimport canonicalize from \"canonicalize\";\nimport type { ReplayPayloadHashAlgorithm } from \"../types/evidence.ts\";\n\nexport const LEGACY_REPLAY_PAYLOAD_HASH_ALGORITHM = \"json-stringify-v1\" as const;\nexport const JCS_REPLAY_PAYLOAD_HASH_ALGORITHM = \"jcs-rfc8785-v2\" as const;\n\nexport function serializeReplayPayload(payload: unknown, algorithm: ReplayPayloadHashAlgorithm): string {\n\tlet serialized: string | undefined;\n\tif (algorithm === LEGACY_REPLAY_PAYLOAD_HASH_ALGORITHM) {\n\t\tserialized = JSON.stringify(payload);\n\t} else if (algorithm === JCS_REPLAY_PAYLOAD_HASH_ALGORITHM) {\n\t\tserialized = canonicalize(payload);\n\t} else {\n\t\tthrow new TypeError(`Unsupported replay payload hash algorithm: ${String(algorithm)}`);\n\t}\n\tif (serialized === undefined) {\n\t\tthrow new TypeError(`Replay payload is not valid JSON for ${algorithm}`);\n\t}\n\treturn serialized;\n}\n\nexport function computeReplayPayloadHash(payload: unknown, algorithm: ReplayPayloadHashAlgorithm): string {\n\treturn createHash(\"sha256\").update(serializeReplayPayload(payload, algorithm)).digest(\"hex\");\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import canonicalize from "canonicalize";
|
|
3
|
+
export const LEGACY_REPLAY_PAYLOAD_HASH_ALGORITHM = "json-stringify-v1";
|
|
4
|
+
export const JCS_REPLAY_PAYLOAD_HASH_ALGORITHM = "jcs-rfc8785-v2";
|
|
5
|
+
export function serializeReplayPayload(payload, algorithm) {
|
|
6
|
+
let serialized;
|
|
7
|
+
if (algorithm === LEGACY_REPLAY_PAYLOAD_HASH_ALGORITHM) {
|
|
8
|
+
serialized = JSON.stringify(payload);
|
|
9
|
+
}
|
|
10
|
+
else if (algorithm === JCS_REPLAY_PAYLOAD_HASH_ALGORITHM) {
|
|
11
|
+
serialized = canonicalize(payload);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
throw new TypeError(`Unsupported replay payload hash algorithm: ${String(algorithm)}`);
|
|
15
|
+
}
|
|
16
|
+
if (serialized === undefined) {
|
|
17
|
+
throw new TypeError(`Replay payload is not valid JSON for ${algorithm}`);
|
|
18
|
+
}
|
|
19
|
+
return serialized;
|
|
20
|
+
}
|
|
21
|
+
export function computeReplayPayloadHash(payload, algorithm) {
|
|
22
|
+
return createHash("sha256").update(serializeReplayPayload(payload, algorithm)).digest("hex");
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=replay-payload-hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay-payload-hash.js","sourceRoot":"","sources":["../../src/guardrails/replay-payload-hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,YAAY,MAAM,cAAc,CAAC;AAGxC,MAAM,CAAC,MAAM,oCAAoC,GAAG,mBAA4B,CAAC;AACjF,MAAM,CAAC,MAAM,iCAAiC,GAAG,gBAAyB,CAAC;AAE3E,MAAM,UAAU,sBAAsB,CAAC,OAAgB,EAAE,SAAqC,EAAU;IACvG,IAAI,UAA8B,CAAC;IACnC,IAAI,SAAS,KAAK,oCAAoC,EAAE,CAAC;QACxD,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;SAAM,IAAI,SAAS,KAAK,iCAAiC,EAAE,CAAC;QAC5D,UAAU,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;SAAM,CAAC;QACP,MAAM,IAAI,SAAS,CAAC,8CAA8C,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IACxF,CAAC;IACD,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC9B,MAAM,IAAI,SAAS,CAAC,wCAAwC,SAAS,EAAE,CAAC,CAAC;IAC1E,CAAC;IACD,OAAO,UAAU,CAAC;AAAA,CAClB;AAED,MAAM,UAAU,wBAAwB,CAAC,OAAgB,EAAE,SAAqC,EAAU;IACzG,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,sBAAsB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAAA,CAC7F","sourcesContent":["import { createHash } from \"node:crypto\";\nimport canonicalize from \"canonicalize\";\nimport type { ReplayPayloadHashAlgorithm } from \"../types/evidence.ts\";\n\nexport const LEGACY_REPLAY_PAYLOAD_HASH_ALGORITHM = \"json-stringify-v1\" as const;\nexport const JCS_REPLAY_PAYLOAD_HASH_ALGORITHM = \"jcs-rfc8785-v2\" as const;\n\nexport function serializeReplayPayload(payload: unknown, algorithm: ReplayPayloadHashAlgorithm): string {\n\tlet serialized: string | undefined;\n\tif (algorithm === LEGACY_REPLAY_PAYLOAD_HASH_ALGORITHM) {\n\t\tserialized = JSON.stringify(payload);\n\t} else if (algorithm === JCS_REPLAY_PAYLOAD_HASH_ALGORITHM) {\n\t\tserialized = canonicalize(payload);\n\t} else {\n\t\tthrow new TypeError(`Unsupported replay payload hash algorithm: ${String(algorithm)}`);\n\t}\n\tif (serialized === undefined) {\n\t\tthrow new TypeError(`Replay payload is not valid JSON for ${algorithm}`);\n\t}\n\treturn serialized;\n}\n\nexport function computeReplayPayloadHash(payload: unknown, algorithm: ReplayPayloadHashAlgorithm): string {\n\treturn createHash(\"sha256\").update(serializeReplayPayload(payload, algorithm)).digest(\"hex\");\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export { type BashOperations, type BashSpawnContext, type BashSpawnHook, type Ba
|
|
|
34
34
|
export { createVerifiedBashOperations, executeVerifiedBash, executeVerifiedLocalBash, VERIFIED_BASH_REDACTION_POLICY_ID, VerifiedBashAdapterError, type VerifiedBashExecutionRequest, type VerifiedBashOperationsBinding, type VerifiedLocalBashExecutionRequest, } from "./core/verified-bash-adapter.ts";
|
|
35
35
|
export { isVerifiedBashEnabled, resolveSessionWorkspaceScope } from "./core/verified-bash-runtime.ts";
|
|
36
36
|
export { type CommandHmacBinder, CommandRedactionError, createCommandHmacBinder, EVIDENCE_COMMAND_REDACTION_POLICY_ID, MAX_COMMAND_REDACTION_PLACEHOLDERS, parseCommandHmacBinding, parseCommandRedactionSummary, type RedactedCommandDescriptor, redactCommandDescriptor, } from "./guardrails/command-redaction.ts";
|
|
37
|
+
export { evidenceReceiptToObservation } from "./guardrails/evidence-protocol.ts";
|
|
37
38
|
export { computeEvidenceCommandSha256, computeEvidenceReceiptCoreSha256, constantTimeSha256Equal, createEvidenceReceipt, evidenceReceiptReplayPayload, isSafeEvidenceReceiptId, isSha256Hex, parseEvidenceReceipt, parseSha256Hex, validateEvidenceReceipt, withEvidenceReceiptEnvelope, } from "./guardrails/evidence-receipt.ts";
|
|
38
39
|
export { EvidenceReceiptStore, type EvidenceReceiptStoreFaultStage, type EvidenceReceiptStoreOptions, } from "./guardrails/evidence-receipt-store.ts";
|
|
39
40
|
export { EvidenceGate, type EvidenceGateOptions, FailClosedMergeGate, latestRelevantWorkspaceMutationSeq, ReplayLedgerManager, TaskContractBuilder, } from "./guardrails/evidence-system.ts";
|
|
@@ -43,7 +44,7 @@ export { type MainOptions, main } from "./main.ts";
|
|
|
43
44
|
export { InteractiveMode, type InteractiveModeOptions, type ModelInfo, type PrintModeOptions, RpcClient, type RpcClientOptions, type RpcCommand, type RpcEventListener, type RpcResponse, type RpcSessionState, runPrintMode, runRpcMode, } from "./modes/index.ts";
|
|
44
45
|
export { ArminComponent, AssistantMessageComponent, BashExecutionComponent, BorderedLoader, BranchSummaryMessageComponent, CompactionSummaryMessageComponent, CustomEditor, CustomMessageComponent, DynamicBorder, ExtensionEditorComponent, ExtensionInputComponent, ExtensionSelectorComponent, FooterComponent, keyHint, keyText, LoginDialogComponent, ModelSelectorComponent, OAuthSelectorComponent, type RenderDiffOptions, rawKeyHint, renderDiff, SessionSelectorComponent, type SettingsCallbacks, type SettingsConfig, SettingsSelectorComponent, ShowImagesSelectorComponent, SkillInvocationMessageComponent, ThemeSelectorComponent, ThinkingSelectorComponent, ToolExecutionComponent, type ToolExecutionOptions, TreeSelectorComponent, truncateToVisualLines, UserMessageComponent, UserMessageSelectorComponent, type VisualTruncateResult, } from "./modes/interactive/components/index.ts";
|
|
45
46
|
export { getLanguageFromPath, getMarkdownTheme, getSelectListTheme, getSettingsListTheme, highlightCode, initTheme, Theme, type ThemeColor, } from "./modes/interactive/theme/theme.ts";
|
|
46
|
-
export type { ArtifactSetWorkspaceFingerprint, ArtifactState, CommandHmacBinding, CommandRedactionPlaceholder, CommandRedactionPlaceholderType, CommandRedactionSummary, EvidenceCommandDescriptor, EvidenceExecutor, EvidenceItem, EvidenceReceipt, EvidenceReceiptDisposition, EvidenceReceiptLedgerBinding, EvidenceReceiptMode, FileArtifactState, GitWorkspaceFingerprint, GitWorkspaceState, MissingArtifactState, ReplayEvent, ReplayEventType, Sha256Hex, TaskContract, WorkspaceFingerprint, WorkspaceMutationReplayPayload, WorkspaceScope, } from "./types/evidence.ts";
|
|
47
|
+
export type { ArtifactSetWorkspaceFingerprint, ArtifactState, CommandHmacBinding, CommandRedactionPlaceholder, CommandRedactionPlaceholderType, CommandRedactionSummary, EvidenceCommandDescriptor, EvidenceExecutor, EvidenceItem, EvidenceReceipt, EvidenceReceiptDisposition, EvidenceReceiptLedgerBinding, EvidenceReceiptMode, FileArtifactState, GitWorkspaceFingerprint, GitWorkspaceState, MissingArtifactState, ReplayEvent, ReplayEventType, ReplayPayloadHashAlgorithm, Sha256Hex, TaskContract, WorkspaceFingerprint, WorkspaceMutationReplayPayload, WorkspaceScope, } from "./types/evidence.ts";
|
|
47
48
|
export { copyToClipboard } from "./utils/clipboard.ts";
|
|
48
49
|
export { parseFrontmatter, stripFrontmatter } from "./utils/frontmatter.ts";
|
|
49
50
|
export { convertToPng } from "./utils/image-convert.ts";
|