@axtary/ledger 0.1.0 → 0.3.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/README.md CHANGED
@@ -11,13 +11,45 @@ npm install @axtary/ledger
11
11
  ## What It Does
12
12
 
13
13
  - Appends Axtary ledger records to local JSONL.
14
+ - Serializes concurrent processes with an inter-process lease lock.
15
+ - Appends in place and synchronizes the file plus directory metadata before
16
+ returning success; prior ledger bytes are never rewritten.
17
+ - Maintains a private O(1) head checkpoint and reconstructs it from the
18
+ verified JSONL chain after a crash or legacy-file migration.
14
19
  - Maintains a `previousLedgerHash -> ledgerHash` chain.
15
20
  - Reads ledger records back in order.
16
21
  - Verifies hash-chain continuity and record integrity.
17
22
  - Exports verified records by inclusive date range and decision type.
23
+ - Emits a detached signed attestation over an export, and an RFC 6962
24
+ transparency-log signed tree head (`merkleRoot`/`treeSize`) with inclusion and
25
+ consistency proofs (`proveLedgerInclusion`/`proveLedgerConsistency` +
26
+ `verifyLedgerInclusionProof`/`verifyLedgerConsistencyProof`). Inclusion proves
27
+ one record is committed by a signed head; consistency proves a later head
28
+ append-only-extends an earlier one. Both fail closed unless bound to a signed
29
+ head.
30
+ - Verifies cross-issuer evidence with `verifyCrossIssuerActionPass`: a pinned
31
+ public trust root, ActionPass token, ledger attestation bundle, inclusion
32
+ proof, and fresh status-list response must all agree before the report is
33
+ valid. This is verify-only and does not authorize execution.
34
+ - Reconstructs a delegation+execution incident offline from ledger records alone
35
+ (`analyzeForensics`/`reconstructIncident`) and asserts attenuation structure,
36
+ exact authorization→execution correlation, and cascade containment — a
37
+ read-only auditor primitive, not anomaly detection.
18
38
  - Formats verified exports as JSON, raw ledger JSONL, or SIEM-friendly JSONL events.
19
39
  - Syncs a verified export to an optional hosted endpoint.
40
+ - Exports opt-in OTLP/HTTP GenAI `execute_tool` spans from ledger records,
41
+ carrying decisions, reasons, hashes, and audit dimensions without payload
42
+ bodies or secrets.
43
+ - Keeps OTLP export and hosted sync network access explicit: both require the
44
+ caller to inject a fetch-compatible transport and fail closed without one, so
45
+ the package does not use ambient global network access on its own.
20
46
  - Fails closed on malformed JSONL records.
47
+ - Records parent-to-child ActionPass delegation edges inside the hash chain.
48
+ - Records denied, pending, committed, and rolled-back budget events with
49
+ configured cost/limit and usage before/after.
50
+ - Carries a payload-free, hash-bound audit context on new records (tenant,
51
+ agent, human owner, task, tool, and resource) so operator search does not
52
+ infer identity from hashes or provider summaries.
21
53
  - Carries trace IDs and sanitized provider evidence for GitHub, Slack, and Linear records when that evidence was present at decision time.
22
54
 
23
55
  ## Quickstart
@@ -44,11 +76,39 @@ console.log(verification.valid, verification.records.length);
44
76
 
45
77
  The ledger is local-first. It is not a database, SIEM, or remote audit service. It gives the proxy and adapters a durable local trail that can later be uploaded, exported, or re-verified. Export and sync both verify the full hash chain before returning or sending filtered records. SIEM JSONL events include timestamps, trace IDs, outcomes, provider/resource summaries, policy metadata, reasons, and hashes without expanding protected action payloads or credential-bearing provider responses.
46
78
 
79
+ OpenTelemetry export is an operational projection, not the audit proof.
80
+ `exportLedgerRecordsToOtlp` posts verified records to an OTLP/HTTP traces
81
+ endpoint, and `LocalJsonlLedger` can be constructed with `OtlpHttpTraceExporter`
82
+ to stream spans after durable append. The span shape uses standard GenAI tool
83
+ attributes (`gen_ai.operation.name`, `gen_ai.tool.name`, `gen_ai.tool.type`)
84
+ plus Axtary namespaced attributes for decision, reason, payload hash, ledger
85
+ hash, policy, pass id, trace/correlation id, and audit context. It never emits
86
+ normalized payload bodies, provider tokens, auth headers, result rows, file
87
+ contents, or raw shell commands.
88
+
89
+ `LocalJsonlLedger` uses a filesystem lease lock (`<ledger>.lock`) so separate
90
+ processes resolve and append against one chain head. The JSONL file is opened
91
+ in append mode, one line is written, and the file is synchronized. A private
92
+ `<ledger>.head.json` checkpoint (mode `0600`) stores byte length, line number,
93
+ and the last hash for steady-state O(1) appends; it is never treated as audit
94
+ evidence. The checkpoint is atomically replaced and the containing directory
95
+ is synchronized. If a process dies after the durable JSONL append but before
96
+ checkpoint replacement or lock release, the lease becomes stale and the next
97
+ writer verifies the JSONL chain, reconstructs the head, and continues.
98
+
47
99
  Hosted sync should use signed ledger sync tokens rather than dashboard user sessions. Sync tokens carry a signed `kid` so hosted verification can rotate keys with `AXTARY_LEDGER_SYNC_TOKEN_KID` and a JSON `AXTARY_LEDGER_SYNC_TOKEN_SECRETS` keyring. Hosted retention can be bounded with `AXTARY_LEDGER_SYNC_MAX_BATCHES`, `AXTARY_LEDGER_SYNC_MAX_AGE_DAYS`, or stricter limits embedded in the signed sync token.
48
100
 
49
101
  The hosted sync store now sits behind a persistence adapter. The default adapter is local JSON at `.axtary/hosted-ledger-sync.json`; set `AXTARY_LEDGER_SYNC_STORE=neon` plus `AXTARY_LEDGER_SYNC_DATABASE_URL` to use the Neon/Postgres adapter. Apply `migrations/neon/001_hosted_ledger_sync_batches.sql` for deployed environments; `docs/neon-hosted-sync-runbook.md` covers the hosted setup and verification flow. Source file paths can be reduced before storage with `AXTARY_LEDGER_SYNC_REDACT_SOURCE_FILE_PATH=basename` or `redact`. Hash-bound ledger record fields are preserved so synced evidence remains verifiable.
50
102
 
51
- Hosted audit search is available through `/api/ledger/sync?view=records` with optional `q`, `decision`, `from`, `to`, and `limit` query parameters. The ledger dashboard exposes those filters for tenant-scoped synced evidence, including record detail inspection, normalized provider resources, GitHub diff/file summaries, Slack channel/message evidence, Linear issue field changes, trace IDs, and batch-id drilldown. SIEM exports remain available through `/api/ledger/sync?format=siem-jsonl`.
103
+ Unified audit search is available through `/api/ledger/search` with optional
104
+ `q`, `decision`, `from`, `to`, and `limit` query parameters. In local dashboard
105
+ mode it searches the verified local JSONL chain plus tenant-scoped synced
106
+ batches; hosted mode searches only tenant-scoped synced evidence. The broad
107
+ query covers agent, human owner, task, tool, resource, hashes, policy, reasons,
108
+ traces, and provider evidence. Historical records without `auditContext`
109
+ remain valid but those identity dimensions are labeled unavailable. The older
110
+ `/api/ledger/sync?view=records` endpoint remains a synced-only view, and SIEM
111
+ exports remain available through `/api/ledger/sync?format=siem-jsonl`.
52
112
 
53
113
  Fail-closed and secret boundaries:
54
114
 
@@ -56,4 +116,6 @@ Fail-closed and secret boundaries:
56
116
  - Hosted sync accepts only verified exports through the sync route and keeps provider credentials, sync tokens, dashboard sessions, cookies, and auth headers out of stored batches and browser payloads.
57
117
  - Provider evidence is extracted from normalized actions, not raw provider HTTP responses. GitHub content payloads record paths and lengths rather than file bodies unless an explicit sanitized diff is supplied.
58
118
 
59
- Concurrent writers should coordinate through a single process or external file lock. The first proxy should own writes for a given ledger file.
119
+ Concurrent cooperating writers are serialized by the package lock. Direct
120
+ writes that bypass `LocalJsonlLedger` are unsupported; size drift is detected
121
+ before and after append and fails closed as `ledger_concurrent_write_detected`.
@@ -0,0 +1,81 @@
1
+ import type { NormalizedAction } from "@axtary/actionpass";
2
+ import { z } from "zod";
3
+ /**
4
+ * Behavioral observation store (risk-graph v0).
5
+ *
6
+ * This is the durable memory behind M5.6's deterministic novelty/sequence
7
+ * step-up. It records, per `(tenant, agentId)`, which `(tool, resource)`
8
+ * combinations and which `prevTool → tool` transitions have already been
9
+ * *executed*. From that it derives two booleans for an action:
10
+ *
11
+ * - `firstSeenCombo` — this agent has never executed this tool on this resource.
12
+ * - `abnormalSequence` — the transition from the agent's last executed tool to
13
+ * this one has never been executed before.
14
+ *
15
+ * HARD FENCE (PRD §4 non-goals): these are signals that only ever cause a
16
+ * `step_up`. Nothing here scores, ranks, or authorizes. `evaluate()` is
17
+ * read-only; an action only becomes "known" via `observe()`, which the proxy
18
+ * calls *after* a successful execution — so a denied or unapproved novel action
19
+ * is never silently whitelisted.
20
+ */
21
+ export declare const BEHAVIOR_STORE_VERSION = "axtary.behavior_store.v0";
22
+ export declare const BehaviorStoreSchema: z.ZodObject<{
23
+ schemaVersion: z.ZodLiteral<"axtary.behavior_store.v0">;
24
+ agents: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
25
+ combos: z.ZodDefault<z.ZodArray<z.ZodString>>;
26
+ transitions: z.ZodDefault<z.ZodArray<z.ZodString>>;
27
+ lastTool: z.ZodDefault<z.ZodNullable<z.ZodString>>;
28
+ }, z.core.$strip>>>;
29
+ }, z.core.$strip>;
30
+ export type BehaviorStoreData = z.infer<typeof BehaviorStoreSchema>;
31
+ export type BehaviorSignals = {
32
+ firstSeenCombo: boolean;
33
+ abnormalSequence: boolean;
34
+ };
35
+ /**
36
+ * Pure signal derivation against a loaded store. No IO, no mutation — the proxy
37
+ * uses this both for the durable file store and for tests/in-memory callers.
38
+ */
39
+ export declare function deriveBehaviorSignals(data: BehaviorStoreData, action: NormalizedAction): BehaviorSignals;
40
+ /**
41
+ * Fold an executed action into the store. Pure: returns the next state. Records
42
+ * the combo, the transition from the agent's last tool, and advances lastTool.
43
+ */
44
+ export declare function recordBehaviorObservation(data: BehaviorStoreData, action: NormalizedAction): BehaviorStoreData;
45
+ export interface BehaviorStore {
46
+ evaluate(action: NormalizedAction): Promise<BehaviorSignals>;
47
+ observe(action: NormalizedAction): Promise<void>;
48
+ }
49
+ /** In-memory store for tests and single-process callers. */
50
+ export declare class InMemoryBehaviorStore implements BehaviorStore {
51
+ private data;
52
+ evaluate(action: NormalizedAction): Promise<BehaviorSignals>;
53
+ observe(action: NormalizedAction): Promise<void>;
54
+ snapshot(): BehaviorStoreData;
55
+ }
56
+ export type FileBehaviorStoreOptions = {
57
+ lock?: {
58
+ staleMs?: number;
59
+ updateMs?: number;
60
+ retries?: number;
61
+ minTimeoutMs?: number;
62
+ maxTimeoutMs?: number;
63
+ };
64
+ };
65
+ /**
66
+ * Durable, lock-serialized behavior store shared across proxy/serve handlers
67
+ * and restarts, so novelty memory is not reset per process. `evaluate` is a
68
+ * lock-free read; `observe` is serialized under an inter-process lease and
69
+ * written `0600` via an atomic rename.
70
+ */
71
+ export declare class FileBehaviorStore implements BehaviorStore {
72
+ readonly filePath: string;
73
+ private readonly options;
74
+ constructor(filePath: string, options?: FileBehaviorStoreOptions);
75
+ evaluate(action: NormalizedAction): Promise<BehaviorSignals>;
76
+ observe(action: NormalizedAction): Promise<void>;
77
+ private read;
78
+ private write;
79
+ private acquireLock;
80
+ }
81
+ //# sourceMappingURL=behavior.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"behavior.d.ts","sourceRoot":"","sources":["../src/behavior.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,sBAAsB,6BAA6B,CAAC;AAWjE,eAAO,MAAM,mBAAmB;;;;;;;iBAI9B,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEpE,MAAM,MAAM,eAAe,GAAG;IAC5B,cAAc,EAAE,OAAO,CAAC;IACxB,gBAAgB,EAAE,OAAO,CAAC;CAC3B,CAAC;AAqBF;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,iBAAiB,EACvB,MAAM,EAAE,gBAAgB,GACvB,eAAe,CAoBjB;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,iBAAiB,EACvB,MAAM,EAAE,gBAAgB,GACvB,iBAAiB,CA0BnB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAC7D,OAAO,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAClD;AAED,4DAA4D;AAC5D,qBAAa,qBAAsB,YAAW,aAAa;IACzD,OAAO,CAAC,IAAI,CAAmC;IAEzC,QAAQ,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC;IAI5D,OAAO,CAAC,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CAAC,OAAO,IAAI,GAAG;gBACnC,MAAM,EAAE,GAAG;gBACX,UAAU,EAAE,WAAW,CAAC,YAAY,IAAI,EAAE;gBAC1C,UAAU,EAAE,WAAW,CAAC,YAAY,IAAI,GAAG;aAC5C;YACD,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE;gBACvB,iBAAiB,GAAG,KAAK,CAAC,OAAO,CAAC;YACpC,CAAC;SACF,CAAC,CAAC;QACH,IAAI,iBAAiB,KAAK,IAAI,EAAE,CAAC;YAC/B,MAAM,OAAO,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,mCAAmC,iBAAiB,EAAE,CAAC,CAAC;QAC1E,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
@@ -0,0 +1,52 @@
1
+ import type { DelegationLedgerEdge, LedgerRecord } from "@axtary/actionpass";
2
+ export declare const LEDGER_FORENSICS_VERSION = "axtary.ledger_forensics.v0";
3
+ export type ForensicExecution = {
4
+ recordIndex: number;
5
+ recordId: string;
6
+ status: "succeeded" | "failed";
7
+ occurredAt: string;
8
+ };
9
+ export type ForensicNode = {
10
+ passId: string;
11
+ parentPassId: string | null;
12
+ rootPassId: string;
13
+ depth: number;
14
+ recordIndices: number[];
15
+ executions: ForensicExecution[];
16
+ /** Chain index of the first revocation-denial record naming this pass. */
17
+ revokedAtIndex: number | null;
18
+ };
19
+ export type ForensicTimelineEntry = {
20
+ recordIndex: number;
21
+ recordId: string;
22
+ occurredAt: string;
23
+ passId: string | null;
24
+ decision: LedgerRecord["decision"];
25
+ reasons: string[];
26
+ executionStatus: "succeeded" | "failed" | null;
27
+ };
28
+ export type ForensicIncident = {
29
+ nodes: ForensicNode[];
30
+ edges: DelegationLedgerEdge[];
31
+ roots: string[];
32
+ timeline: ForensicTimelineEntry[];
33
+ };
34
+ export type ForensicProperty = {
35
+ property: "delegation_attenuation" | "forensic_reconstructibility" | "cascade_containment";
36
+ holds: boolean;
37
+ violations: string[];
38
+ };
39
+ export type ForensicReport = {
40
+ schemaVersion: typeof LEDGER_FORENSICS_VERSION;
41
+ recordCount: number;
42
+ roots: string[];
43
+ nodeCount: number;
44
+ edgeCount: number;
45
+ properties: ForensicProperty[];
46
+ valid: boolean;
47
+ };
48
+ /** Rebuild the delegation forest and execution timeline from ledger records. */
49
+ export declare function reconstructIncident(records: LedgerRecord[]): ForensicIncident;
50
+ /** Reconstruct the incident and assert the three forensic properties. */
51
+ export declare function analyzeForensics(records: LedgerRecord[]): ForensicReport;
52
+ //# sourceMappingURL=forensics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forensics.d.ts","sourceRoot":"","sources":["../src/forensics.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAE7E,eAAO,MAAM,wBAAwB,+BAA+B,CAAC;AAKrE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,WAAW,GAAG,QAAQ,CAAC;IAC/B,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,UAAU,EAAE,iBAAiB,EAAE,CAAC;IAChC,0EAA0E;IAC1E,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,QAAQ,EAAE,YAAY,CAAC,UAAU,CAAC,CAAC;IACnC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,eAAe,EAAE,WAAW,GAAG,QAAQ,GAAG,IAAI,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,KAAK,EAAE,oBAAoB,EAAE,CAAC;IAC9B,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,EAAE,qBAAqB,EAAE,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EACJ,wBAAwB,GACxB,6BAA6B,GAC7B,qBAAqB,CAAC;IAC1B,KAAK,EAAE,OAAO,CAAC;IACf,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,aAAa,EAAE,OAAO,wBAAwB,CAAC;IAC/C,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,gBAAgB,EAAE,CAAC;IAC/B,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;AAsBF,gFAAgF;AAChF,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,gBAAgB,CA+D7E;AAkBD,yEAAyE;AACzE,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,cAAc,CAuKxE"}
@@ -0,0 +1,249 @@
1
+ // Offline forensic reconstruction of a delegation+execution incident from the
2
+ // decision ledger alone (spec/actionpass-v0.md §9.5).
3
+ //
4
+ // Given an ordered list of verified ledger records, this rebuilds the delegation
5
+ // forest and execution timeline and deterministically asserts three properties:
6
+ //
7
+ // - delegation_attenuation — the recorded delegation structure is a
8
+ // well-formed, depth-monotonic, single-root tree (the ledger-visible
9
+ // evidence of attenuated delegation; strict scope-subset attenuation is
10
+ // enforced at issuance/verification in @axtary/actionpass, not re-derivable
11
+ // from the ledger because passes carry scope, the ledger carries hashes).
12
+ // - forensic_reconstructibility — every execution is attributable to a pass
13
+ // with a prior authorizing decision in the same chain; no orphan execution.
14
+ // - cascade_containment — once a pass is revoked (a deny record naming
15
+ // it with an `actionpass_revoked` reason), neither it nor any descendant
16
+ // records a later successful execution.
17
+ //
18
+ // This is a deterministic, read-only auditor primitive — not anomaly detection,
19
+ // scoring, or monitoring (PRD §4 non-goals). It reads records and reports facts.
20
+ export const LEDGER_FORENSICS_VERSION = "axtary.ledger_forensics.v0";
21
+ /** A reason token marking a record as a revocation denial for its pass. */
22
+ const REVOCATION_REASON = /(^|_)actionpass_revoked($|_)|(^|\b)actionpass_revoked\b/;
23
+ function ensureNode(nodes, passId) {
24
+ let node = nodes.get(passId);
25
+ if (!node) {
26
+ node = {
27
+ passId,
28
+ parentPassId: null,
29
+ rootPassId: passId,
30
+ depth: 0,
31
+ recordIndices: [],
32
+ executions: [],
33
+ revokedAtIndex: null,
34
+ };
35
+ nodes.set(passId, node);
36
+ }
37
+ return node;
38
+ }
39
+ /** Rebuild the delegation forest and execution timeline from ledger records. */
40
+ export function reconstructIncident(records) {
41
+ const nodes = new Map();
42
+ const edges = [];
43
+ const timeline = [];
44
+ records.forEach((record, index) => {
45
+ const passId = record.actionPassId ?? null;
46
+ if (record.delegation) {
47
+ edges.push(record.delegation);
48
+ const child = ensureNode(nodes, record.delegation.childPassId);
49
+ child.parentPassId = record.delegation.parentPassId;
50
+ child.rootPassId = record.delegation.rootPassId;
51
+ child.depth = record.delegation.depth;
52
+ // Surface the parent so a parent that only appears inside a child's edge
53
+ // still becomes a reconstructable node.
54
+ const parent = ensureNode(nodes, record.delegation.parentPassId);
55
+ parent.rootPassId = record.delegation.rootPassId;
56
+ if (record.delegation.parentPassId === record.delegation.rootPassId) {
57
+ parent.depth = 0;
58
+ parent.parentPassId = null;
59
+ }
60
+ }
61
+ if (passId) {
62
+ const node = ensureNode(nodes, passId);
63
+ node.recordIndices.push(index);
64
+ if (record.executionOutcome) {
65
+ node.executions.push({
66
+ recordIndex: index,
67
+ recordId: record.id,
68
+ status: record.executionOutcome.status,
69
+ occurredAt: record.occurredAt,
70
+ });
71
+ }
72
+ if (node.revokedAtIndex === null &&
73
+ record.reasons.some((reason) => REVOCATION_REASON.test(reason))) {
74
+ node.revokedAtIndex = index;
75
+ }
76
+ }
77
+ timeline.push({
78
+ recordIndex: index,
79
+ recordId: record.id,
80
+ occurredAt: record.occurredAt,
81
+ passId,
82
+ decision: record.decision,
83
+ reasons: record.reasons,
84
+ executionStatus: record.executionOutcome?.status ?? null,
85
+ });
86
+ });
87
+ const childIds = new Set(edges.map((edge) => edge.childPassId));
88
+ const roots = [...nodes.keys()].filter((id) => !childIds.has(id)).sort();
89
+ return {
90
+ nodes: [...nodes.values()].sort((a, b) => a.passId.localeCompare(b.passId)),
91
+ edges,
92
+ roots,
93
+ timeline,
94
+ };
95
+ }
96
+ /** All descendants (inclusive) of `passId` following parent->child edges. */
97
+ function subtree(passId, childrenOf) {
98
+ const out = new Set([passId]);
99
+ const stack = [passId];
100
+ while (stack.length > 0) {
101
+ const current = stack.pop();
102
+ for (const child of childrenOf.get(current) ?? []) {
103
+ if (!out.has(child)) {
104
+ out.add(child);
105
+ stack.push(child);
106
+ }
107
+ }
108
+ }
109
+ return out;
110
+ }
111
+ /** Reconstruct the incident and assert the three forensic properties. */
112
+ export function analyzeForensics(records) {
113
+ const incident = reconstructIncident(records);
114
+ const byId = new Map(incident.nodes.map((node) => [node.passId, node]));
115
+ const childrenOf = new Map();
116
+ for (const edge of incident.edges) {
117
+ const list = childrenOf.get(edge.parentPassId) ?? [];
118
+ list.push(edge.childPassId);
119
+ childrenOf.set(edge.parentPassId, list);
120
+ }
121
+ // 1. delegation_attenuation — depth-monotonic, single-root, acyclic tree.
122
+ const attenuation = [];
123
+ const edgeByChild = new Map();
124
+ for (const edge of incident.edges) {
125
+ const prior = edgeByChild.get(edge.childPassId);
126
+ if (prior && prior.parentPassId !== edge.parentPassId) {
127
+ attenuation.push(`multiple_parents:${edge.childPassId}`);
128
+ }
129
+ if (prior &&
130
+ (prior.rootPassId !== edge.rootPassId || prior.depth !== edge.depth)) {
131
+ attenuation.push(`edge_metadata_inconsistent:${edge.childPassId}`);
132
+ }
133
+ edgeByChild.set(edge.childPassId, prior ?? edge);
134
+ }
135
+ for (const edge of incident.edges) {
136
+ const parentEdge = edgeByChild.get(edge.parentPassId);
137
+ const expectedDepth = edge.parentPassId === edge.rootPassId
138
+ ? 1
139
+ : parentEdge
140
+ ? parentEdge.depth + 1
141
+ : null;
142
+ if (expectedDepth === null) {
143
+ attenuation.push(`root_unreachable:${edge.childPassId}:root=${edge.rootPassId}`);
144
+ }
145
+ else if (edge.depth !== expectedDepth) {
146
+ attenuation.push(`depth_not_monotonic:${edge.childPassId}:edge=${edge.depth}:expected=${expectedDepth}`);
147
+ }
148
+ if (parentEdge && parentEdge.rootPassId !== edge.rootPassId) {
149
+ attenuation.push(`root_inconsistent:${edge.childPassId}`);
150
+ }
151
+ }
152
+ // Walking the first recorded parent edge from any node must terminate at the
153
+ // declared root. Multiple-parent/metadata conflicts are reported above.
154
+ for (const node of incident.nodes) {
155
+ const visited = new Set();
156
+ let cursor = node.passId;
157
+ while (cursor) {
158
+ if (visited.has(cursor)) {
159
+ attenuation.push(`cycle_detected:${node.passId}`);
160
+ break;
161
+ }
162
+ visited.add(cursor);
163
+ cursor = edgeByChild.get(cursor)?.parentPassId ?? null;
164
+ }
165
+ const incoming = edgeByChild.get(node.passId);
166
+ if (incoming &&
167
+ !visited.has(incoming.rootPassId)) {
168
+ attenuation.push(`root_inconsistent:${node.passId}`);
169
+ }
170
+ }
171
+ // 2. forensic_reconstructibility — every execution points to the exact,
172
+ // earlier authorizing allow record for the same pass.
173
+ const reconstructibility = [];
174
+ const recordIndexById = new Map(records.map((record, index) => [record.id, index]));
175
+ records.forEach((record, index) => {
176
+ if (!record.executionOutcome)
177
+ return;
178
+ if (!record.actionPassId) {
179
+ reconstructibility.push(`execution_without_pass:${record.id}`);
180
+ return;
181
+ }
182
+ if (!record.correlationId) {
183
+ reconstructibility.push(`execution_without_correlation:${record.actionPassId}:${record.id}`);
184
+ return;
185
+ }
186
+ const authorizationIndex = recordIndexById.get(record.correlationId);
187
+ if (authorizationIndex === undefined) {
188
+ reconstructibility.push(`execution_authorization_missing:${record.actionPassId}:${record.id}`);
189
+ return;
190
+ }
191
+ if (authorizationIndex >= index) {
192
+ reconstructibility.push(`execution_authorization_not_prior:${record.actionPassId}:${record.id}`);
193
+ return;
194
+ }
195
+ const authorization = records[authorizationIndex];
196
+ if (authorization.actionPassId !== record.actionPassId) {
197
+ reconstructibility.push(`execution_authorization_pass_mismatch:${record.actionPassId}:${record.id}`);
198
+ return;
199
+ }
200
+ if (authorization.decision !== "allow") {
201
+ reconstructibility.push(`execution_without_authorization:${record.actionPassId}:${record.id}`);
202
+ }
203
+ });
204
+ // 3. cascade_containment — no descendant of a revoked pass succeeds afterward.
205
+ const containment = [];
206
+ for (const node of incident.nodes) {
207
+ if (node.revokedAtIndex === null)
208
+ continue;
209
+ const affected = subtree(node.passId, childrenOf);
210
+ for (const descendantId of affected) {
211
+ const descendant = byId.get(descendantId);
212
+ if (!descendant)
213
+ continue;
214
+ for (const execution of descendant.executions) {
215
+ if (execution.status === "succeeded" &&
216
+ execution.recordIndex > node.revokedAtIndex) {
217
+ containment.push(`post_revocation_success:revoked=${node.passId}:descendant=${descendantId}:record=${execution.recordId}`);
218
+ }
219
+ }
220
+ }
221
+ }
222
+ const properties = [
223
+ {
224
+ property: "delegation_attenuation",
225
+ holds: attenuation.length === 0,
226
+ violations: attenuation,
227
+ },
228
+ {
229
+ property: "forensic_reconstructibility",
230
+ holds: reconstructibility.length === 0,
231
+ violations: reconstructibility,
232
+ },
233
+ {
234
+ property: "cascade_containment",
235
+ holds: containment.length === 0,
236
+ violations: containment,
237
+ },
238
+ ];
239
+ return {
240
+ schemaVersion: LEDGER_FORENSICS_VERSION,
241
+ recordCount: records.length,
242
+ roots: incident.roots,
243
+ nodeCount: incident.nodes.length,
244
+ edgeCount: incident.edges.length,
245
+ properties,
246
+ valid: properties.every((property) => property.holds),
247
+ };
248
+ }
249
+ //# sourceMappingURL=forensics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forensics.js","sourceRoot":"","sources":["../src/forensics.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,sDAAsD;AACtD,EAAE;AACF,iFAAiF;AACjF,gFAAgF;AAChF,EAAE;AACF,0EAA0E;AAC1E,yEAAyE;AACzE,4EAA4E;AAC5E,gFAAgF;AAChF,8EAA8E;AAC9E,8EAA8E;AAC9E,gFAAgF;AAChF,gFAAgF;AAChF,6EAA6E;AAC7E,4CAA4C;AAC5C,EAAE;AACF,gFAAgF;AAChF,iFAAiF;AAIjF,MAAM,CAAC,MAAM,wBAAwB,GAAG,4BAA4B,CAAC;AAErE,2EAA2E;AAC3E,MAAM,iBAAiB,GAAG,yDAAyD,CAAC;AAwDpF,SAAS,UAAU,CACjB,KAAgC,EAChC,MAAc;IAEd,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC7B,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,IAAI,GAAG;YACL,MAAM;YACN,YAAY,EAAE,IAAI;YAClB,UAAU,EAAE,MAAM;YAClB,KAAK,EAAE,CAAC;YACR,aAAa,EAAE,EAAE;YACjB,UAAU,EAAE,EAAE;YACd,cAAc,EAAE,IAAI;SACrB,CAAC;QACF,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC1B,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,mBAAmB,CAAC,OAAuB;IACzD,MAAM,KAAK,GAAG,IAAI,GAAG,EAAwB,CAAC;IAC9C,MAAM,KAAK,GAA2B,EAAE,CAAC;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