@coderifts/agent-guard 1.7.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +181 -17
  2. package/dist/cjs/deploy-gate.d.ts +10 -3
  3. package/dist/cjs/deploy-gate.d.ts.map +1 -1
  4. package/dist/cjs/deploy-gate.js +7 -0
  5. package/dist/cjs/deploy-gate.js.map +1 -1
  6. package/dist/cjs/guard.d.ts.map +1 -1
  7. package/dist/cjs/guard.js +29 -1
  8. package/dist/cjs/guard.js.map +1 -1
  9. package/dist/cjs/index.d.ts +4 -2
  10. package/dist/cjs/index.d.ts.map +1 -1
  11. package/dist/cjs/index.js +10 -2
  12. package/dist/cjs/index.js.map +1 -1
  13. package/dist/cjs/merge-gate.d.ts +27 -4
  14. package/dist/cjs/merge-gate.d.ts.map +1 -1
  15. package/dist/cjs/merge-gate.js +22 -0
  16. package/dist/cjs/merge-gate.js.map +1 -1
  17. package/dist/cjs/receipt-chain.d.ts +52 -0
  18. package/dist/cjs/receipt-chain.d.ts.map +1 -0
  19. package/dist/cjs/receipt-chain.js +104 -0
  20. package/dist/cjs/receipt-chain.js.map +1 -0
  21. package/dist/cjs/tool-registry.d.ts.map +1 -1
  22. package/dist/cjs/tool-registry.js +7 -0
  23. package/dist/cjs/tool-registry.js.map +1 -1
  24. package/dist/cjs/types.d.ts +7 -0
  25. package/dist/cjs/types.d.ts.map +1 -1
  26. package/dist/cjs/with-coderifts.d.ts +114 -86
  27. package/dist/cjs/with-coderifts.d.ts.map +1 -1
  28. package/dist/cjs/with-coderifts.js +133 -113
  29. package/dist/cjs/with-coderifts.js.map +1 -1
  30. package/dist/esm/deploy-gate.d.ts +10 -3
  31. package/dist/esm/deploy-gate.d.ts.map +1 -1
  32. package/dist/esm/deploy-gate.js +7 -0
  33. package/dist/esm/deploy-gate.js.map +1 -1
  34. package/dist/esm/guard.d.ts.map +1 -1
  35. package/dist/esm/guard.js +29 -1
  36. package/dist/esm/guard.js.map +1 -1
  37. package/dist/esm/index.d.ts +4 -2
  38. package/dist/esm/index.d.ts.map +1 -1
  39. package/dist/esm/index.js +4 -2
  40. package/dist/esm/index.js.map +1 -1
  41. package/dist/esm/merge-gate.d.ts +27 -4
  42. package/dist/esm/merge-gate.d.ts.map +1 -1
  43. package/dist/esm/merge-gate.js +22 -0
  44. package/dist/esm/merge-gate.js.map +1 -1
  45. package/dist/esm/receipt-chain.d.ts +52 -0
  46. package/dist/esm/receipt-chain.d.ts.map +1 -0
  47. package/dist/esm/receipt-chain.js +98 -0
  48. package/dist/esm/receipt-chain.js.map +1 -0
  49. package/dist/esm/tool-registry.d.ts.map +1 -1
  50. package/dist/esm/tool-registry.js +7 -0
  51. package/dist/esm/tool-registry.js.map +1 -1
  52. package/dist/esm/types.d.ts +7 -0
  53. package/dist/esm/types.d.ts.map +1 -1
  54. package/dist/esm/with-coderifts.d.ts +114 -86
  55. package/dist/esm/with-coderifts.d.ts.map +1 -1
  56. package/dist/esm/with-coderifts.js +130 -112
  57. package/dist/esm/with-coderifts.js.map +1 -1
  58. package/package.json +1 -1
@@ -15,102 +15,51 @@
15
15
  * `composition_assurance` so the trace survives into any later coverageReport consumer. S2 adds NO
16
16
  * enforcement at call time.
17
17
  *
18
- * COMPOSITION OBSERVATION (this slice): optional `onEvent` is forwarded UNCHANGED onto the guard
19
- * config the composition builds (the same surface guardToolRegistry already spreads into
20
- * guardToolCall). Optional `onOutcome` is a composition-level hook: after each GUARDED tool's
21
- * execute returns a GuardOutcome, the composition invokes onOutcome then returns that outcome to the
22
- * host byte-identical. Observation is NOT enforcement — it does not change COMPOSITION_CALL_POLICY_COMPLETE,
23
- * coverage, residuals, or whether any tool runs.
18
+ * COMPOSITION OBSERVATION: optional `onEvent` is forwarded UNCHANGED onto the guard config.
19
+ * Optional `onSettledCall` is a composition-level hook: it fires EXACTLY ONCE for every SETTLED
20
+ * call through the RETURNED tool table (GUARDED | PASSTHROUGH | BYPASSED × RETURNED | THREW).
21
+ * Discriminant is an EXPLICIT TAG (`kind: 'settled_call'` plus route/terminal), never the absence of
22
+ * a field. On the GUARDED+RETURNED arm, `outcome` is non-optional. Observation is NOT enforcement —
23
+ * it does not change COMPOSITION_CALL_POLICY_COMPLETE, coverage, residuals, or whether any tool runs.
24
+ * The package holds NO counters and computes NO ratios at runtime; pure fold helpers are optional
25
+ * host-side tools (see foldTableSettledCalls / guardedFractionAmongRoutes).
24
26
  *
25
27
  * TELEMETRY GAPS (honest boundaries — read before claiming "every mutation was checked"):
26
28
  * - onEvent does NOT emit a dedicated event for BLOCK or REQUIRE_APPROVAL; after preflight_result
27
- * those paths return blocked with no further emit. Those outcomes ARE visible via onOutcome
28
- * (outcome.executed === false, outcome.verdict.kind === 'BLOCK' | 'APPROVAL'), not via onEvent.
29
+ * those paths return blocked with no further emit. Those outcomes ARE visible via onSettledCall
30
+ * on the GUARDED arm (outcome.executed === false, outcome.verdict.kind === 'BLOCK' | 'APPROVAL').
29
31
  * - The GuardEvent payload carries no envelope, receipt, or fingerprint — only optional decisionId
30
- * (and action/cause/signals/…). onOutcome carries the full GuardOutcome, including
31
- * outcome.verdict.envelope where the frozen path attached one (BLOCK / APPROVAL / ALLOW / MONITOR).
32
- * - onOutcome fires ONLY for guarded tools (_coderifts.guarded === true). Readonly passthrough
33
- * tools never enter guardToolCall and produce no GuardOutcome; they are not wrapped and never
34
- * fire onOutcome.
32
+ * (and action/cause/signals/…). GUARDED+RETURNED onSettledCall carries the full GuardOutcome,
33
+ * including outcome.verdict.envelope where the frozen path attached one.
34
+ * - onSettledCall sees ONLY calls through the table withCodeRifts returned. Host-invoked raw tools
35
+ * outside that table are invisible. Never treat observation as "total operations" or "100%
36
+ * enforcement coverage".
35
37
  * - onEvent is partial even for other branches (e.g. closed-availability stops may emit only
36
38
  * preflight_start; the declared type 'execution_skipped' is never emitted by the frozen core).
37
39
  * - Neither hook alone is a complete substrate for receipt carry-forward: onEvent lacks the
38
- * envelope/receipt; onOutcome exposes them when present but does not retain or re-inject them
39
- * across calls (that is a later slice).
40
+ * envelope/receipt; onSettledCall exposes them when present on the GUARDED+RETURNED arm but does
41
+ * not retain or re-inject them across calls (that is a later slice).
40
42
  *
41
43
  * S2 does NOT re-guard what the registry already fails closed on. A `forceReadonly`/`classify`
42
44
  * downgrade of a heuristic mutator is, under the registry's default `failOnUnguardedMutator:true`,
43
45
  * already a thrown `FORCE_READONLY_MUTATOR` (no report exists); when the caller passes
44
46
  * `failOnUnguardedMutator:false` it is already registry coverage 'BYPASSED', which fails any
45
- * `requireCoverage` above BYPASSED by the ordering alone. So there is deliberately NO second
46
- * composition-level abort for weakening overrides that would create two places that must agree. The
47
- * composition merely RECORDS the residual (composition_forced_readonly_on_heuristic_mutator /
48
- * composition_unknown_treated_as_readonly) so the reason the composition is narrower than it looks is
49
- * preserved on the assurance object. Registry-thrown errors propagate UNCHANGED (never wrapped or
50
- * swallowed).
51
- *
52
- * How the weakening residuals are derived, and their KNOWN LIMITATION (a frozen-registry property, not
53
- * a composition property): both residuals are read SOLELY from `registry_report.warnings` — the
54
- * composition never recomputes classification. The registry emits `force_readonly_on_mutator_heuristic`
55
- * ONLY for the downgrade of a HEURISTIC-classified mutator (a tool with no `classify` entry and no
56
- * `mutationClass`, whose NAME heuristic is mutating), reached via `forceReadonly` OR a `classify`
57
- * entry. Crucially, `forceReadonly` has NO effect on a tool the caller declared with an explicit
58
- * `mutationClass`: `resolveClass` (tool-registry.ts:154-165) returns on `tool.mutationClass` at :157,
59
- * BEFORE `forceReadonly` is consulted at :158 — so such a tool resolves `mutating`, stays guarded,
60
- * yields coverage 'COMPLETE', and emits NO warning. The composition therefore produces NO residual in
61
- * that case and CANNOT detect it: the caller's `forceReadonly` was silently ignored by the frozen
62
- * registry. This is a limitation of the frozen registry surface, recorded (not worked around) here and
63
- * pinned by a "documented limitation" test. The residual is named
64
- * `composition_forced_readonly_on_heuristic_mutator` so it does not promise coverage of the case it
65
- * cannot see.
47
+ * `requireCoverage` above BYPASSED by the ordering alone. The composition RECORDS residuals from
48
+ * registry warnings. When forceReadonly lists a tool that declared explicit mutationClass, the
49
+ * registry emits `force_readonly_ignored_explicit_mutation_class:<name>` (break-glass ignored).
66
50
  *
67
51
  * COMPOSITION_CALL_POLICY_COMPLETE (when the composition may claim product-level runtime
68
52
  * inescapability) requires ALL of the following — do not flip the constant when only a subset lands:
69
53
  * (1) Automatic binders for call shapes that ALREADY carry both sides of the change (old_string/
70
- * new_string, edits[]) — DONE (commit 582504a / defaultBinder lift). Not the same as covering
71
- * every real agent edit shape.
72
- * (2) Receipt carry-forward (S5) NOT done.
73
- * (3) A freshness-safe source of prior content for write-style calls (path + new content only),
74
- * where the host never supplied `before` — NOT done. The package performs no IO, so a prior it
75
- * was not given cannot be obtained; inventing one (including empty-string before) would send a
76
- * fabricated artifact to the oracle. That needs a host/guard freshness protocol, not another
77
- * binder rename. Flipping this constant on (1)+(2) alone is incorrect.
78
- *
79
- * STILL DELIBERATELY OUT OF SCOPE (later slices; not stubbed, not implied here): receipt carry-forward;
80
- * freshness-safe prior content for write-style calls; call-time STOP re-implementation (already
81
- * complete in the frozen guardToolCall path); WARN monitoring policy beyond the frozen sink gate;
82
- * framework adapters. (Both-sides edit-side lifting in defaultBinder is landed — see (1) above.)
54
+ * new_string, edits[]) — DONE. Not the same as covering every real agent edit shape.
55
+ * (2) Receipt carry-forward (S5) — host-threaded chaining is POSSIBLE (optional previousReceipt +
56
+ * verifyReceiptChainLinkage). NOT met for this constant: the composition holds no cursor.
57
+ * (3) A freshness-safe source of prior content for write-style calls (path + new content only)
58
+ * NOT done.
83
59
  *
84
60
  * THE TWO-SCOPE RULE (never merged):
85
- * - `registry_report` is EXACTLY what `guardToolRegistry` returned, passed through untouched. It may
86
- * legitimately state coverage 'COMPLETE' and claim.inescapable_runtime true that is the runtime
87
- * tool-boundary's own honest truth (Placement A).
88
- * - `composition_assurance` is the narrower PRODUCT-level statement — what withCodeRifts as a whole
89
- * is willing to claim today. It is computed SEPARATELY and never rewrites the registry's verdict.
90
- * Its S1 semantics are UNCHANGED in S2 and under observation: coverage stays 'PARTIAL',
91
- * inescapable_runtime stays false via the same COMPOSITION_CALL_POLICY_COMPLETE conjunction.
92
- * The two truths coexist; neither is derived by mutating the other.
93
- *
94
- * `requireCoverage` scope (read this before trusting a green construction): it constrains the
95
- * REGISTRY-level coverage ONLY. It CANNOT be used to demand composition-level runtime inescapability —
96
- * that remains unreachable while COMPOSITION_CALL_POLICY_COMPLETE is false (see the three conditions
97
- * above, not merely "binders + receipts"). A caller passing `requireCoverage:'COMPLETE'` is asserting
98
- * an expectation about the registry tool-boundary surface — NOT a product-level guarantee. The abort
99
- * text and this doc say so explicitly so nobody reads a green construction as product-level
100
- * enforcement.
101
- *
102
- * Operation semantics (accurate scope): `operationForClass` (tool-registry.ts) already derives a
103
- * per-tool operation from the tool's mutation class, OVERRIDING the guard config for specialised
104
- * classes (deploy→'deploy', publish→'publish', vcs-merge→'merge', …). The mandatory `operation` here
105
- * therefore governs generic mutating tools and acts as the session-level default; it does NOT override
106
- * a deploy-class tool's 'deploy'. It is mandatory because receipts bind to an operation and
107
- * merge != deploy: a silent default would risk evaluating a deploy under merge semantics.
108
- *
109
- * Abort discipline: pre-registry input problems (missing/empty operation, missing client, an invalid
110
- * requireCoverage value) are collected and thrown as ONE error listing ALL of them. The
111
- * requireCoverage-vs-actual check is necessarily sequenced AFTER the registry call (it needs the
112
- * registry's coverage), so it is its own abort; it cannot be batched with the pre-registry problems
113
- * because a valid operation+client are required even to reach the registry.
61
+ * - `registry_report` is EXACTLY what `guardToolRegistry` returned, passed through untouched.
62
+ * - `composition_assurance` is the narrower PRODUCT-level statement, computed SEPARATELY.
114
63
  */
115
64
  import type { RawTool, ProtectedTool, EnforcementCoverage, RegistryCoverageReport, ToolBinder, ToolMutationClass } from './tool-registry.js';
116
65
  import type { GuardConfig, GuardEvent, GuardOutcome } from './types.js';
@@ -122,14 +71,87 @@ export type WithCodeRiftsRegistryConfig = {
122
71
  forceReadonly?: string[];
123
72
  failOnUnguardedMutator?: boolean;
124
73
  };
74
+ /** Route of a settled call through the returned table. Explicit tag values — never inferred by field absence. */
75
+ export type CallRoute = 'GUARDED' | 'PASSTHROUGH' | 'BYPASSED';
76
+ /** How a settled call finished. Explicit tag values. */
77
+ export type CallTerminal = 'RETURNED' | 'THREW';
125
78
  /**
126
- * Composition-level observation of one guarded-tool return. Carries the tool name and the
127
- * GuardOutcome EXACTLY as returned by the frozen path — no summary, no extracted convenience fields.
128
- * Consumers that need the envelope read `outcome.verdict.envelope` (when present on that arm).
79
+ * One settled call through the tool table withCodeRifts returned.
80
+ *
81
+ * Discriminant is the EXPLICIT `kind: 'settled_call'` plus `route` and `terminal` tags never
82
+ * "outcome present vs missing". On GUARDED+RETURNED, `outcome` is required (non-optional).
83
+ *
84
+ * Replaces the former `ObservedOutcome` (`{ toolName, outcome }` only for guarded returns). The old
85
+ * name implied every observation carried a GuardOutcome and that only guarded tools were visible;
86
+ * both were false once passthrough/threw routes ship, so the name is retired rather than overloaded.
129
87
  */
130
- export type ObservedOutcome = {
88
+ export type SettledCallObservation = {
89
+ kind: 'settled_call';
90
+ route: 'GUARDED';
91
+ terminal: 'RETURNED';
131
92
  toolName: string;
132
93
  outcome: GuardOutcome<unknown>;
94
+ } | {
95
+ kind: 'settled_call';
96
+ route: 'GUARDED';
97
+ terminal: 'THREW';
98
+ toolName: string;
99
+ error: unknown;
100
+ } | {
101
+ kind: 'settled_call';
102
+ route: 'PASSTHROUGH';
103
+ terminal: 'RETURNED';
104
+ toolName: string;
105
+ result: unknown;
106
+ } | {
107
+ kind: 'settled_call';
108
+ route: 'PASSTHROUGH';
109
+ terminal: 'THREW';
110
+ toolName: string;
111
+ error: unknown;
112
+ } | {
113
+ kind: 'settled_call';
114
+ route: 'BYPASSED';
115
+ terminal: 'RETURNED';
116
+ toolName: string;
117
+ result: unknown;
118
+ } | {
119
+ kind: 'settled_call';
120
+ route: 'BYPASSED';
121
+ terminal: 'THREW';
122
+ toolName: string;
123
+ error: unknown;
124
+ };
125
+ /**
126
+ * Counts of settled-call routes from a host-collected event list.
127
+ * Names are route tags only — not "total operations" or "enforcement coverage".
128
+ */
129
+ export type TableSettledCallRouteCounts = {
130
+ GUARDED: number;
131
+ PASSTHROUGH: number;
132
+ BYPASSED: number;
133
+ };
134
+ /**
135
+ * Pure fold: count routes in a host-owned list of settled-call observations.
136
+ * The package never accumulates these at runtime.
137
+ */
138
+ export declare function foldTableSettledCalls(events: readonly SettledCallObservation[]): TableSettledCallRouteCounts;
139
+ /**
140
+ * Fraction of GUARDED among observed routes, or ABSENT when a ratio would be misleading.
141
+ *
142
+ * Returns `kind: 'absent'` (not zero) when:
143
+ * - no settled calls were observed, or
144
+ * - only a single route tag has a non-zero count (one-sided observation).
145
+ *
146
+ * Never returns a number that could be read as "0% enforcement" or "100% coverage" from partial data.
147
+ * The package does not call this automatically.
148
+ */
149
+ export declare function guardedFractionAmongRoutes(counts: TableSettledCallRouteCounts): {
150
+ kind: 'absent';
151
+ why: 'no_settled_calls' | 'one_route_only';
152
+ } | {
153
+ kind: 'present';
154
+ fraction: number;
133
155
  };
134
156
  export type WithCodeRiftsInput = {
135
157
  /** Raw tool list handed to the frozen guardToolRegistry (required). */
@@ -161,11 +183,17 @@ export type WithCodeRiftsInput = {
161
183
  */
162
184
  onEvent?: (e: GuardEvent) => void;
163
185
  /**
164
- * Optional. Invoked by the composition after each GUARDED tool execute returns, with toolName + the
165
- * unmodified GuardOutcome. Does not fire for readonly passthrough. Throws and rejected promises are
166
- * swallowed so observation never changes host-visible execution. See header TELEMETRY GAPS.
186
+ * Optional. Invoked once per SETTLED call through the returned tool table (every route and both
187
+ * terminals). Discriminated union see SettledCallObservation. Throws and rejected promises are
188
+ * swallowed so observation never changes host-visible execution. Replaces the former `onOutcome`
189
+ * (guarded-only) hook.
190
+ */
191
+ onSettledCall?: (o: SettledCallObservation) => void | PromiseLike<void>;
192
+ /**
193
+ * Optional prior chain-receipt token (or getter) forwarded onto GuardConfig.previousReceipt.
194
+ * Host-owned; the composition does not retain or advance it between calls.
167
195
  */
168
- onOutcome?: (o: ObservedOutcome) => void | PromiseLike<void>;
196
+ previousReceipt?: string | (() => string | undefined | null);
169
197
  };
170
198
  /** The narrower product-level statement, computed separately from the registry's own report. */
171
199
  export type CompositionAssurance = {
@@ -1 +1 @@
1
- {"version":3,"file":"with-coderifts.d.ts","sourceRoot":"","sources":["../../src/with-coderifts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiHG;AAGH,OAAO,KAAK,EACV,OAAO,EACP,aAAa,EACb,mBAAmB,EACnB,sBAAsB,EAEtB,UAAU,EACV,iBAAiB,EAClB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAExE,2FAA2F;AAC3F,MAAM,MAAM,2BAA2B,GAAG;IACxC,iBAAiB,CAAC,EAAE,UAAU,GAAG,UAAU,GAAG,QAAQ,CAAC;IACvD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACrC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,uEAAuE;IACvE,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,gHAA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vC;;;;OAIG;IACH,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,IAAI,CAAC;IAClC;;;;;OAKG;IACH,aAAa,CAAC,EAAE,CAAC,CAAC,EAAE,sBAAsB,KAAK,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IACxE;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC,CAAC;CAC9D,CAAC;AAEF,gGAAgG;AAChG,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,mBAAmB,EAAE,OAAO,CAAC;IAC7B,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,EAAE,aAAa,EAAE,CAAC;IACvB,mGAAmG;IACnG,eAAe,EAAE,sBAAsB,CAAC;IACxC,yEAAyE;IACzE,qBAAqB,EAAE,oBAAoB,CAAC;IAC5C,4FAA4F;IAC5F,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAmIF;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,mBAAmB,CAmH5E"}
@@ -15,104 +15,88 @@
15
15
  * `composition_assurance` so the trace survives into any later coverageReport consumer. S2 adds NO
16
16
  * enforcement at call time.
17
17
  *
18
- * COMPOSITION OBSERVATION (this slice): optional `onEvent` is forwarded UNCHANGED onto the guard
19
- * config the composition builds (the same surface guardToolRegistry already spreads into
20
- * guardToolCall). Optional `onOutcome` is a composition-level hook: after each GUARDED tool's
21
- * execute returns a GuardOutcome, the composition invokes onOutcome then returns that outcome to the
22
- * host byte-identical. Observation is NOT enforcement — it does not change COMPOSITION_CALL_POLICY_COMPLETE,
23
- * coverage, residuals, or whether any tool runs.
18
+ * COMPOSITION OBSERVATION: optional `onEvent` is forwarded UNCHANGED onto the guard config.
19
+ * Optional `onSettledCall` is a composition-level hook: it fires EXACTLY ONCE for every SETTLED
20
+ * call through the RETURNED tool table (GUARDED | PASSTHROUGH | BYPASSED × RETURNED | THREW).
21
+ * Discriminant is an EXPLICIT TAG (`kind: 'settled_call'` plus route/terminal), never the absence of
22
+ * a field. On the GUARDED+RETURNED arm, `outcome` is non-optional. Observation is NOT enforcement —
23
+ * it does not change COMPOSITION_CALL_POLICY_COMPLETE, coverage, residuals, or whether any tool runs.
24
+ * The package holds NO counters and computes NO ratios at runtime; pure fold helpers are optional
25
+ * host-side tools (see foldTableSettledCalls / guardedFractionAmongRoutes).
24
26
  *
25
27
  * TELEMETRY GAPS (honest boundaries — read before claiming "every mutation was checked"):
26
28
  * - onEvent does NOT emit a dedicated event for BLOCK or REQUIRE_APPROVAL; after preflight_result
27
- * those paths return blocked with no further emit. Those outcomes ARE visible via onOutcome
28
- * (outcome.executed === false, outcome.verdict.kind === 'BLOCK' | 'APPROVAL'), not via onEvent.
29
+ * those paths return blocked with no further emit. Those outcomes ARE visible via onSettledCall
30
+ * on the GUARDED arm (outcome.executed === false, outcome.verdict.kind === 'BLOCK' | 'APPROVAL').
29
31
  * - The GuardEvent payload carries no envelope, receipt, or fingerprint — only optional decisionId
30
- * (and action/cause/signals/…). onOutcome carries the full GuardOutcome, including
31
- * outcome.verdict.envelope where the frozen path attached one (BLOCK / APPROVAL / ALLOW / MONITOR).
32
- * - onOutcome fires ONLY for guarded tools (_coderifts.guarded === true). Readonly passthrough
33
- * tools never enter guardToolCall and produce no GuardOutcome; they are not wrapped and never
34
- * fire onOutcome.
32
+ * (and action/cause/signals/…). GUARDED+RETURNED onSettledCall carries the full GuardOutcome,
33
+ * including outcome.verdict.envelope where the frozen path attached one.
34
+ * - onSettledCall sees ONLY calls through the table withCodeRifts returned. Host-invoked raw tools
35
+ * outside that table are invisible. Never treat observation as "total operations" or "100%
36
+ * enforcement coverage".
35
37
  * - onEvent is partial even for other branches (e.g. closed-availability stops may emit only
36
38
  * preflight_start; the declared type 'execution_skipped' is never emitted by the frozen core).
37
39
  * - Neither hook alone is a complete substrate for receipt carry-forward: onEvent lacks the
38
- * envelope/receipt; onOutcome exposes them when present but does not retain or re-inject them
39
- * across calls (that is a later slice).
40
+ * envelope/receipt; onSettledCall exposes them when present on the GUARDED+RETURNED arm but does
41
+ * not retain or re-inject them across calls (that is a later slice).
40
42
  *
41
43
  * S2 does NOT re-guard what the registry already fails closed on. A `forceReadonly`/`classify`
42
44
  * downgrade of a heuristic mutator is, under the registry's default `failOnUnguardedMutator:true`,
43
45
  * already a thrown `FORCE_READONLY_MUTATOR` (no report exists); when the caller passes
44
46
  * `failOnUnguardedMutator:false` it is already registry coverage 'BYPASSED', which fails any
45
- * `requireCoverage` above BYPASSED by the ordering alone. So there is deliberately NO second
46
- * composition-level abort for weakening overrides that would create two places that must agree. The
47
- * composition merely RECORDS the residual (composition_forced_readonly_on_heuristic_mutator /
48
- * composition_unknown_treated_as_readonly) so the reason the composition is narrower than it looks is
49
- * preserved on the assurance object. Registry-thrown errors propagate UNCHANGED (never wrapped or
50
- * swallowed).
51
- *
52
- * How the weakening residuals are derived, and their KNOWN LIMITATION (a frozen-registry property, not
53
- * a composition property): both residuals are read SOLELY from `registry_report.warnings` — the
54
- * composition never recomputes classification. The registry emits `force_readonly_on_mutator_heuristic`
55
- * ONLY for the downgrade of a HEURISTIC-classified mutator (a tool with no `classify` entry and no
56
- * `mutationClass`, whose NAME heuristic is mutating), reached via `forceReadonly` OR a `classify`
57
- * entry. Crucially, `forceReadonly` has NO effect on a tool the caller declared with an explicit
58
- * `mutationClass`: `resolveClass` (tool-registry.ts:154-165) returns on `tool.mutationClass` at :157,
59
- * BEFORE `forceReadonly` is consulted at :158 — so such a tool resolves `mutating`, stays guarded,
60
- * yields coverage 'COMPLETE', and emits NO warning. The composition therefore produces NO residual in
61
- * that case and CANNOT detect it: the caller's `forceReadonly` was silently ignored by the frozen
62
- * registry. This is a limitation of the frozen registry surface, recorded (not worked around) here and
63
- * pinned by a "documented limitation" test. The residual is named
64
- * `composition_forced_readonly_on_heuristic_mutator` so it does not promise coverage of the case it
65
- * cannot see.
47
+ * `requireCoverage` above BYPASSED by the ordering alone. The composition RECORDS residuals from
48
+ * registry warnings. When forceReadonly lists a tool that declared explicit mutationClass, the
49
+ * registry emits `force_readonly_ignored_explicit_mutation_class:<name>` (break-glass ignored).
66
50
  *
67
51
  * COMPOSITION_CALL_POLICY_COMPLETE (when the composition may claim product-level runtime
68
52
  * inescapability) requires ALL of the following — do not flip the constant when only a subset lands:
69
53
  * (1) Automatic binders for call shapes that ALREADY carry both sides of the change (old_string/
70
- * new_string, edits[]) — DONE (commit 582504a / defaultBinder lift). Not the same as covering
71
- * every real agent edit shape.
72
- * (2) Receipt carry-forward (S5) NOT done.
73
- * (3) A freshness-safe source of prior content for write-style calls (path + new content only),
74
- * where the host never supplied `before` — NOT done. The package performs no IO, so a prior it
75
- * was not given cannot be obtained; inventing one (including empty-string before) would send a
76
- * fabricated artifact to the oracle. That needs a host/guard freshness protocol, not another
77
- * binder rename. Flipping this constant on (1)+(2) alone is incorrect.
78
- *
79
- * STILL DELIBERATELY OUT OF SCOPE (later slices; not stubbed, not implied here): receipt carry-forward;
80
- * freshness-safe prior content for write-style calls; call-time STOP re-implementation (already
81
- * complete in the frozen guardToolCall path); WARN monitoring policy beyond the frozen sink gate;
82
- * framework adapters. (Both-sides edit-side lifting in defaultBinder is landed — see (1) above.)
54
+ * new_string, edits[]) — DONE. Not the same as covering every real agent edit shape.
55
+ * (2) Receipt carry-forward (S5) — host-threaded chaining is POSSIBLE (optional previousReceipt +
56
+ * verifyReceiptChainLinkage). NOT met for this constant: the composition holds no cursor.
57
+ * (3) A freshness-safe source of prior content for write-style calls (path + new content only)
58
+ * NOT done.
83
59
  *
84
60
  * THE TWO-SCOPE RULE (never merged):
85
- * - `registry_report` is EXACTLY what `guardToolRegistry` returned, passed through untouched. It may
86
- * legitimately state coverage 'COMPLETE' and claim.inescapable_runtime true that is the runtime
87
- * tool-boundary's own honest truth (Placement A).
88
- * - `composition_assurance` is the narrower PRODUCT-level statement — what withCodeRifts as a whole
89
- * is willing to claim today. It is computed SEPARATELY and never rewrites the registry's verdict.
90
- * Its S1 semantics are UNCHANGED in S2 and under observation: coverage stays 'PARTIAL',
91
- * inescapable_runtime stays false via the same COMPOSITION_CALL_POLICY_COMPLETE conjunction.
92
- * The two truths coexist; neither is derived by mutating the other.
93
- *
94
- * `requireCoverage` scope (read this before trusting a green construction): it constrains the
95
- * REGISTRY-level coverage ONLY. It CANNOT be used to demand composition-level runtime inescapability —
96
- * that remains unreachable while COMPOSITION_CALL_POLICY_COMPLETE is false (see the three conditions
97
- * above, not merely "binders + receipts"). A caller passing `requireCoverage:'COMPLETE'` is asserting
98
- * an expectation about the registry tool-boundary surface — NOT a product-level guarantee. The abort
99
- * text and this doc say so explicitly so nobody reads a green construction as product-level
100
- * enforcement.
61
+ * - `registry_report` is EXACTLY what `guardToolRegistry` returned, passed through untouched.
62
+ * - `composition_assurance` is the narrower PRODUCT-level statement, computed SEPARATELY.
63
+ */
64
+ import { guardToolRegistry } from './tool-registry.js';
65
+ /**
66
+ * Pure fold: count routes in a host-owned list of settled-call observations.
67
+ * The package never accumulates these at runtime.
68
+ */
69
+ export function foldTableSettledCalls(events) {
70
+ const counts = { GUARDED: 0, PASSTHROUGH: 0, BYPASSED: 0 };
71
+ for (const e of events) {
72
+ if (e.kind !== 'settled_call')
73
+ continue;
74
+ counts[e.route] += 1;
75
+ }
76
+ return counts;
77
+ }
78
+ /**
79
+ * Fraction of GUARDED among observed routes, or ABSENT when a ratio would be misleading.
101
80
  *
102
- * Operation semantics (accurate scope): `operationForClass` (tool-registry.ts) already derives a
103
- * per-tool operation from the tool's mutation class, OVERRIDING the guard config for specialised
104
- * classes (deploy→'deploy', publish→'publish', vcs-merge→'merge', …). The mandatory `operation` here
105
- * therefore governs generic mutating tools and acts as the session-level default; it does NOT override
106
- * a deploy-class tool's 'deploy'. It is mandatory because receipts bind to an operation and
107
- * merge != deploy: a silent default would risk evaluating a deploy under merge semantics.
81
+ * Returns `kind: 'absent'` (not zero) when:
82
+ * - no settled calls were observed, or
83
+ * - only a single route tag has a non-zero count (one-sided observation).
108
84
  *
109
- * Abort discipline: pre-registry input problems (missing/empty operation, missing client, an invalid
110
- * requireCoverage value) are collected and thrown as ONE error listing ALL of them. The
111
- * requireCoverage-vs-actual check is necessarily sequenced AFTER the registry call (it needs the
112
- * registry's coverage), so it is its own abort; it cannot be batched with the pre-registry problems
113
- * because a valid operation+client are required even to reach the registry.
85
+ * Never returns a number that could be read as "0% enforcement" or "100% coverage" from partial data.
86
+ * The package does not call this automatically.
114
87
  */
115
- import { guardToolRegistry } from './tool-registry.js';
88
+ export function guardedFractionAmongRoutes(counts) {
89
+ const routesWithCalls = ['GUARDED', 'PASSTHROUGH', 'BYPASSED']
90
+ .filter((r) => counts[r] > 0);
91
+ if (routesWithCalls.length === 0) {
92
+ return { kind: 'absent', why: 'no_settled_calls' };
93
+ }
94
+ if (routesWithCalls.length === 1) {
95
+ return { kind: 'absent', why: 'one_route_only' };
96
+ }
97
+ const sum = counts.GUARDED + counts.PASSTHROUGH + counts.BYPASSED;
98
+ return { kind: 'present', fraction: counts.GUARDED / sum };
99
+ }
116
100
  /**
117
101
  * Whether the composition's call-time / content policy is complete enough to claim product-level
118
102
  * runtime inescapability. Stays FALSE until EVERY condition below is delivered — later slices ADD
@@ -120,23 +104,15 @@ import { guardToolRegistry } from './tool-registry.js';
120
104
  *
121
105
  * Conditions (all required; do NOT flip this constant because a subset landed):
122
106
  * (1) DONE — automatic binders for shapes that already carry both edit sides (old_string/new_string,
123
- * edits[] → artifacts). Commit 582504a. Does NOT cover write-style path+new-content-only calls.
107
+ * edits[] → artifacts). Does NOT cover write-style path+new-content-only calls.
124
108
  * (2) NOT DONE — receipt carry-forward (S5).
125
- * (3) NOT DONE — freshness-safe prior content for write-style calls. The package does no IO, so a
126
- * `before` the host never supplied cannot be obtained; inventing one (including empty string)
127
- * fabricates an oracle input. Needs a host/guard freshness protocol, not binder renaming.
128
- *
129
- * Historically this comment named only (1) and (2). That wording is narrower than reality: after (1)
130
- * shipped, a reader could think "binders + S5" was enough and flip the flag incorrectly. Do not.
109
+ * (3) NOT DONE — freshness-safe prior content for write-style calls.
131
110
  *
132
111
  * UNCHANGED by S2 / composition observation (observing ≠ enforcing). Value stays false until all three.
133
112
  */
134
113
  const COMPOSITION_CALL_POLICY_COMPLETE = false;
135
114
  const RESIDUAL_CALL_POLICY_INCOMPLETE = 'composition_call_policy_incomplete';
136
115
  // S2 weakening-override residuals — derived SOLELY from registry report.warnings (never recomputed).
137
- // The name says "heuristic_mutator" on purpose: the registry only emits the underlying warning for a
138
- // downgrade of a HEURISTIC-classified mutator (see the header limitation), so the residual must not
139
- // promise coverage of a downgrade it cannot see (an explicit-mutationClass tool).
140
116
  const RESIDUAL_FORCED_READONLY = 'composition_forced_readonly_on_heuristic_mutator';
141
117
  const RESIDUAL_UNKNOWN_READONLY = 'composition_unknown_treated_as_readonly';
142
118
  /**
@@ -159,25 +135,23 @@ function coverageRank(coverage) {
159
135
  : undefined;
160
136
  }
161
137
  /**
162
- * Invoke onOutcome without affecting the host call. Swallows synchronous throws AND rejected
138
+ * Invoke onSettledCall without affecting the host call. Swallows synchronous throws AND rejected
163
139
  * promises (unlike the frozen emit hook, which only try/catches sync throws and ignores returned
164
140
  * promises — that host-side footgun is deliberately not reproduced here).
165
141
  */
166
- async function safeOnOutcome(onOutcome, payload) {
142
+ async function safeOnSettledCall(onSettledCall, payload) {
167
143
  try {
168
- await Promise.resolve(onOutcome(payload));
144
+ await Promise.resolve(onSettledCall(payload));
169
145
  }
170
146
  catch {
171
147
  /* observation never changes execution */
172
148
  }
173
149
  }
174
150
  /**
175
- * Build a NEW ProtectedTool shell around a frozen guarded tool so we can replace execute without
176
- * mutating the frozen registry object. name / description / inputSchema / meta / _coderifts are
177
- * copied by reference (the _coderifts bag is already frozen by the registry). The new shell is
178
- * frozen for parity with registry tools.
151
+ * Build a NEW ProtectedTool shell so we can observe settle without mutating the frozen registry object.
152
+ * name / description / inputSchema / meta / _coderifts are copied by reference.
179
153
  */
180
- function wrapGuardedForObservation(tool, onOutcome) {
154
+ function wrapForSettledCallObservation(tool, route, onSettledCall) {
181
155
  const innerExecute = tool.execute;
182
156
  const toolName = tool.name;
183
157
  const shell = {
@@ -187,22 +161,63 @@ function wrapGuardedForObservation(tool, onOutcome) {
187
161
  meta: tool.meta,
188
162
  _coderifts: tool._coderifts,
189
163
  execute: async (args) => {
190
- // If the inner execute rejects, do NOT invent an outcome — propagate the rejection unchanged.
191
- const outcome = await innerExecute(args);
192
- await safeOnOutcome(onOutcome, {
193
- toolName,
194
- // Guarded execute always returns a GuardOutcome from guardToolCall; assert the type for callers.
195
- outcome: outcome,
196
- });
197
- // Host must receive the same object the unwrapped tool returned (reference-identical).
198
- return outcome;
164
+ try {
165
+ const result = await innerExecute(args);
166
+ if (route === 'GUARDED') {
167
+ await safeOnSettledCall(onSettledCall, {
168
+ kind: 'settled_call',
169
+ route: 'GUARDED',
170
+ terminal: 'RETURNED',
171
+ toolName,
172
+ // Guarded execute always returns a GuardOutcome from guardToolCall.
173
+ outcome: result,
174
+ });
175
+ }
176
+ else {
177
+ await safeOnSettledCall(onSettledCall, {
178
+ kind: 'settled_call',
179
+ route,
180
+ terminal: 'RETURNED',
181
+ toolName,
182
+ result,
183
+ });
184
+ }
185
+ // Host must receive the same object/value the unwrapped tool returned (reference-identical for objects).
186
+ return result;
187
+ }
188
+ catch (error) {
189
+ await safeOnSettledCall(onSettledCall, {
190
+ kind: 'settled_call',
191
+ route,
192
+ terminal: 'THREW',
193
+ toolName,
194
+ error,
195
+ });
196
+ throw error;
197
+ }
199
198
  },
200
199
  };
201
- // Match registry freeze discipline: freeze _coderifts if not already, freeze the shell.
202
200
  if (!Object.isFrozen(shell._coderifts))
203
201
  Object.freeze(shell._coderifts);
204
202
  return Object.freeze(shell);
205
203
  }
204
+ /** Tools forced to readonly via heuristic break-glass — observed as BYPASSED, not true PASSTHROUGH. */
205
+ function bypassedToolNames(report) {
206
+ const names = new Set();
207
+ for (const w of report.warnings) {
208
+ const prefix = 'force_readonly_on_mutator_heuristic:';
209
+ if (w.startsWith(prefix))
210
+ names.add(w.slice(prefix.length));
211
+ }
212
+ return names;
213
+ }
214
+ function routeForTool(tool, bypassed) {
215
+ if (tool._coderifts.guarded)
216
+ return 'GUARDED';
217
+ if (bypassed.has(tool.name))
218
+ return 'BYPASSED';
219
+ return 'PASSTHROUGH';
220
+ }
206
221
  /**
207
222
  * Wrap guardToolRegistry with a mandatory operation and a separately-computed composition assurance.
208
223
  * Fails at CONSTRUCTION (never at first tool call) for a missing client, a missing/empty operation, an
@@ -243,6 +258,9 @@ export function withCodeRifts(input) {
243
258
  if (input.onEvent !== undefined) {
244
259
  guard.onEvent = input.onEvent;
245
260
  }
261
+ if (input.previousReceipt !== undefined) {
262
+ guard.previousReceipt = input.previousReceipt;
263
+ }
246
264
  const config = {
247
265
  guard,
248
266
  unknownToolPolicy: reg.unknownToolPolicy ?? 'mutating',
@@ -289,14 +307,14 @@ export function withCodeRifts(input) {
289
307
  inescapable_runtime: compositionInescapableRuntime,
290
308
  residuals,
291
309
  };
292
- // Outcome observation: registry returns FROZEN ProtectedTool objects (and a frozen tools array).
293
- // We cannot reassign execute on a frozen tool, so we build NEW shells for guarded tools only when
294
- // onOutcome is provided. Readonly tools are left as the same object references (no GuardOutcome).
295
- // The tools ARRAY is also frozen by the registry — always return a fresh array when we wrap.
310
+ // Settled-call observation: registry returns FROZEN ProtectedTool objects (and a frozen tools array).
311
+ // We cannot reassign execute on a frozen tool, so we build NEW shells for EVERY tool in the table
312
+ // when onSettledCall is provided including passthrough and forced-bypass (readonly) tools.
296
313
  let toolsOut = tools;
297
- if (input.onOutcome) {
298
- const onOutcome = input.onOutcome;
299
- toolsOut = Object.freeze(tools.map((t) => (t._coderifts.guarded ? wrapGuardedForObservation(t, onOutcome) : t)));
314
+ if (input.onSettledCall) {
315
+ const onSettledCall = input.onSettledCall;
316
+ const bypassed = bypassedToolNames(report);
317
+ toolsOut = Object.freeze(tools.map((t) => wrapForSettledCallObservation(t, routeForTool(t, bypassed), onSettledCall)));
300
318
  }
301
319
  const result = {
302
320
  tools: toolsOut,