dsh-boost 0.1.1 → 0.1.3

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 (52) hide show
  1. package/README.en.md +141 -51
  2. package/README.md +115 -47
  3. package/dist/admission/usage.js +41 -7
  4. package/dist/admission/usage.js.map +1 -1
  5. package/dist/gate/decide.js +33 -2
  6. package/dist/gate/decide.js.map +1 -1
  7. package/dist/hooks/llm-stream.js +232 -58
  8. package/dist/hooks/llm-stream.js.map +1 -1
  9. package/dist/hooks/post-execute.js +206 -39
  10. package/dist/hooks/post-execute.js.map +1 -1
  11. package/dist/hooks/session-state.js +18 -8
  12. package/dist/hooks/session-state.js.map +1 -1
  13. package/dist/index.js +601 -72
  14. package/dist/index.js.map +1 -1
  15. package/dist/scope/doc.js.map +1 -1
  16. package/dist/scope/store.js +24 -9
  17. package/dist/scope/store.js.map +1 -1
  18. package/dist/tools/boost.js +82 -2
  19. package/dist/tools/boost.js.map +1 -1
  20. package/package.json +9 -5
  21. package/dist/admission/fixed-cost.d.ts +0 -23
  22. package/dist/admission/ledger.d.ts +0 -113
  23. package/dist/admission/retrieval.d.ts +0 -65
  24. package/dist/admission/usage.d.ts +0 -75
  25. package/dist/config.d.ts +0 -43
  26. package/dist/gate/binding.d.ts +0 -113
  27. package/dist/gate/decide.d.ts +0 -82
  28. package/dist/gate/guard.d.ts +0 -69
  29. package/dist/gate/invalidate.d.ts +0 -112
  30. package/dist/gate/plan.d.ts +0 -86
  31. package/dist/hooks/clock.d.ts +0 -68
  32. package/dist/hooks/execute.d.ts +0 -79
  33. package/dist/hooks/llm-stream.d.ts +0 -283
  34. package/dist/hooks/pending.d.ts +0 -89
  35. package/dist/hooks/post-execute.d.ts +0 -257
  36. package/dist/hooks/session-state.d.ts +0 -158
  37. package/dist/hooks/synthesize.d.ts +0 -74
  38. package/dist/host/loader.d.ts +0 -23
  39. package/dist/host/platform.d.ts +0 -18
  40. package/dist/host/root.d.ts +0 -25
  41. package/dist/projection/apply.d.ts +0 -174
  42. package/dist/projection/canonicalise.d.ts +0 -43
  43. package/dist/projection/counters.d.ts +0 -65
  44. package/dist/projection/truncate.d.ts +0 -47
  45. package/dist/prompt/protocol.d.ts +0 -45
  46. package/dist/receipts/store.d.ts +0 -198
  47. package/dist/scope/doc.d.ts +0 -117
  48. package/dist/scope/resolve.d.ts +0 -91
  49. package/dist/scope/store.d.ts +0 -135
  50. package/dist/selector/jev.d.ts +0 -93
  51. package/dist/tools/boost.d.ts +0 -380
  52. package/dist/tools/family.d.ts +0 -26
@@ -8,16 +8,18 @@
8
8
  * - `tools/post-execute` first gates on the same cached scope judgement the
9
9
  * protocol section reads, then canonicalises the result and runs a
10
10
  * conservative invalidation check. It files the arriving receipt under
11
- * `'root'`, works the substitution decision (`decide` → admission → pending
12
- * queue / shadow receipt / fallback), then the double-projection guard, and
13
- * finally projects the receipt when the scope document asks for it. Order is
14
- * fixed: `next() → scope gate → canonicalise → invalidate → decide →
15
- * (shadow receipt | admit and enqueue | fallback) → double-projection guard →
16
- * projection → return the decision` (plan §Task 23b). A call with no
17
- * `exec.agent` is not the plugin's to inspect: the downstream decision is
18
- * returned untouched and a `skip:no-scope` receipt keeps the pass visible
19
- * (design §5.5). A call carrying `exec.parent` is a PTC inner dispatch and
20
- * returns before any of this: it is not the step's root receipt.
11
+ * `'root'`, then — only when the decision leaves that receipt visible
12
+ * (`projectionTargetOf`) — works the substitution decision (`decide` →
13
+ * admission → pending queue / shadow receipt / fallback), then the
14
+ * double-projection guard, and finally projects the receipt when the scope
15
+ * document asks for it. Order is fixed: `next() → scope gate → canonicalise
16
+ * → invalidate → visibility gate → decide → (shadow receipt | admit and
17
+ * enqueue | fallback) → double-projection guard → projection → return the
18
+ * decision` (plan §Task 23b). A call with no `exec.agent` is not the
19
+ * plugin's to inspect: the downstream decision is returned untouched and a
20
+ * `skip:no-scope` receipt keeps the pass visible (design §5.5). A call
21
+ * carrying `exec.parent` is a PTC inner dispatch and returns before any of
22
+ * this: it is not the step's root receipt.
21
23
  * - `llm/stream` is the model-request waterfall. Its body lives in
22
24
  * `./llm-stream.ts` (Task 23c-1) and is re-exported below: it lets the
23
25
  * plugin's own selector request through untouched, then answers a pending
@@ -86,7 +88,7 @@ import { DEFAULT_SCOPE, isVisible } from '../scope/doc.js';
86
88
  import { SELECTOR_SYSTEM_PROMPT, choose, selectorPromptText } from '../selector/jev.js';
87
89
  import { familyOf } from '../tools/family.js';
88
90
  import { rejectIfTampered } from './execute.js';
89
- import { receiptsStopped, sessionBudget, sessionClock, sessionUsage, settleDiscarded, streamHook, } from './llm-stream.js';
91
+ import { budgetWired, receiptsStopped, sessionBudget, sessionClock, sessionUsage, settleDiscarded, streamHook, } from './llm-stream.js';
90
92
  import { callIdFor } from './pending.js';
91
93
  import { ReceiptSessionState, appendReceipt, callPreview, clearAnchors, clearPlan, clearPending, clockTurnOf, peekPending, previewOf, } from './session-state.js';
92
94
  /**
@@ -667,25 +669,37 @@ function admittedFor(deps, sessionId, plan, overheadTokens) {
667
669
  *
668
670
  * A selector call is real spend, so this check runs before the selector is
669
671
  * priced or called; the consuming `takeBudget` stays at the commit point.
670
- * A missing or foreign budget means "not exhausted", matching `takeBudget`'s
671
- * no-cap contract. Shadow mode never calls this: it spends no step.
672
+ * `undefined` from `sessionBudget` has two different meanings (row 21): no
673
+ * budget is wired at all (no cap), or one is wired but was not lent to this
674
+ * session (exhausted, fail closed). Shadow mode never calls this: it spends no
675
+ * step.
672
676
  */
673
677
  function budgetExhausted(deps, sessionId) {
674
678
  try {
675
679
  const budget = sessionBudget(deps, sessionId);
676
- if (budget == null || typeof budget.exhausted !== 'function')
680
+ if (budget == null)
681
+ return budgetWired(deps);
682
+ if (typeof budget.exhausted !== 'function')
677
683
  return false;
678
684
  return budget.exhausted() === true;
679
685
  }
680
686
  catch {
681
- return false;
687
+ return budgetWired(deps);
682
688
  }
683
689
  }
684
- /** Claim one budget step; no budget wired means no cap is applied. */
690
+ /**
691
+ * Claim one budget step.
692
+ *
693
+ * No budget wired means no cap is applied. A wired budget that this session may
694
+ * not borrow is a refusal, not "no cap": `take` fails and the caller records
695
+ * `steps-exhausted` without enqueueing (row 21).
696
+ */
685
697
  function takeBudget(deps, sessionId) {
686
698
  try {
687
699
  const budget = sessionBudget(deps, sessionId);
688
- if (budget == null || typeof budget.take !== 'function')
700
+ if (budget == null)
701
+ return !budgetWired(deps);
702
+ if (typeof budget.take !== 'function')
689
703
  return true;
690
704
  return budget.take();
691
705
  }
@@ -722,10 +736,14 @@ function pendingCandidateOf(deps, sessionId) {
722
736
  * accepted dispatch is mirrored here together with the evidence that would
723
737
  * otherwise be parked for the next settlement.
724
738
  *
725
- * One record per session: a later accepted dispatch replaces it, a session
726
- * whose usage mark is already gone drops it, and a rollover consumes it. The
727
- * `HookDeps` key keeps two assemblies in one process from reading each other's
728
- * sessions. The record is small and per-session; it is never persisted.
739
+ * One record per session: a later accepted dispatch (or a later synthesis)
740
+ * replaces it, a session whose usage mark is already gone drops it, and a
741
+ * rollover consumes it. The `HookDeps` key keeps two assemblies in one process
742
+ * from reading each other's sessions. The record is small and per-session; it
743
+ * is never persisted. It is also written at synthesis time through
744
+ * {@link HookDeps.noteSynthesis}: a dispatch denied by `tools/pre-execute`
745
+ * never reaches `tools/execute`, and that skipped model round must still be
746
+ * reportable at a rollover (row 27).
729
747
  */
730
748
  const ACCEPTED_DISPATCH = new WeakMap();
731
749
  /** Mirror an accepted dispatch for a possible rollover settlement. */
@@ -746,7 +764,8 @@ function noteAcceptedDispatch(deps, sessionId, turn, candidateId, evidence) {
746
764
  *
747
765
  * The turn check is a staleness guard: the record that a pending mark belongs
748
766
  * to was written in the turn now rolling over. A record written in the new
749
- * turn cannot belong to it.
767
+ * turn cannot belong to it. The record's own turn is returned so the settled
768
+ * receipt pairs with the dispatch, not with the rollover (row 26).
750
769
  */
751
770
  function takeAcceptedDispatch(deps, sessionId, candidateId, turn) {
752
771
  const bySession = ACCEPTED_DISPATCH.get(deps);
@@ -755,7 +774,9 @@ function takeAcceptedDispatch(deps, sessionId, candidateId, turn) {
755
774
  if (record === undefined || record.candidateId !== candidateId || record.turn === turn) {
756
775
  return undefined;
757
776
  }
758
- return record.evidence === undefined ? {} : { evidence: record.evidence };
777
+ return record.evidence === undefined
778
+ ? { turn: record.turn }
779
+ : { turn: record.turn, evidence: record.evidence };
759
780
  }
760
781
  /** Drop the mirrored dispatch; no pending mark is waiting to settle it. */
761
782
  export function clearAcceptedDispatch(deps, sessionId) {
@@ -768,11 +789,13 @@ export function clearAcceptedDispatch(deps, sessionId) {
768
789
  * parallel tool result can roll the turn before that request; the mark must not
769
790
  * survive into the new turn, where it would pair with a request that is not the
770
791
  * substitution's next one. If `tools/execute` never accepted the synthesized
771
- * dispatch, the substitution did not run and the mark is a discard. If it did,
772
- * the model round really was skipped: the settlement line is written with
773
- * whatever sample the ledger holds (`'unknown'` when no after-mark request has
774
- * run yet) and with the evidence captured at dispatch, so the substitution is
775
- * reported instead of disappearing.
792
+ * dispatch, the substitution did not run and the mark is a discard. If it did
793
+ * — or if the synthesis itself was mirrored before a `tools/pre-execute`
794
+ * denial (row 27) — the model round really was skipped: the settlement line is
795
+ * written with whatever sample the ledger holds (`'unknown'` when no after-mark
796
+ * request has run yet), with the evidence captured at dispatch, and with the
797
+ * dispatch turn the mirror recorded rather than the rollover turn (row 26), so
798
+ * the substitution is reported instead of disappearing.
776
799
  */
777
800
  async function settleRollover(deps, sessionId, turn) {
778
801
  const candidateId = pendingCandidateOf(deps, sessionId);
@@ -808,13 +831,20 @@ async function settleRollover(deps, sessionId, turn) {
808
831
  version: 1,
809
832
  ts: new Date().toISOString(),
810
833
  sessionId,
811
- turn,
834
+ // Row 26: the substitution happened in the dispatch turn the mirror
835
+ // recorded. Stamping the rollover turn paired a turn-1 substitution with a
836
+ // turn-2 settled line, which reads as a saving from the wrong round.
837
+ turn: dispatched.turn,
812
838
  stepId: 'root',
813
839
  kind: 'substitute-settled',
814
840
  code: 'substitute-settled',
815
841
  candidateId,
816
842
  ...(dispatched.evidence ?? {}),
817
843
  saved_input_tokens: settled.saved_input_tokens,
844
+ // Row 7: the same pair of samples also yields the lower estimate; the
845
+ // settled line is the only place a measured saving exists, so both numbers
846
+ // travel together.
847
+ avoided_total_tokens: settled.avoided_total_tokens,
818
848
  cache_hit_delta: settled.cache_hit_delta,
819
849
  output_tokens: settled.output_tokens,
820
850
  });
@@ -1061,12 +1091,66 @@ async function chooseCandidate(deps, ctx, candidates, receiptText) {
1061
1091
  return undefined;
1062
1092
  }
1063
1093
  }
1094
+ // ---------------------------------------------------------------------------
1095
+ // Row 7: the step's admitted tool set
1096
+ // ---------------------------------------------------------------------------
1097
+ /**
1098
+ * Read this step's admission predicate, or `undefined` when it cannot be
1099
+ * verified.
1100
+ *
1101
+ * `view(scope)` takes the exact requesting agent; the host admits no other
1102
+ * scope. A missing `toolSet`, a missing `view` and a throwing `view` are all
1103
+ * "no evidence" and take the documented `no-toolset` path: the substitution
1104
+ * proceeds and records that it ran without admission evidence. Refusing on
1105
+ * absence would silently disable the feature on paths we cannot enumerate,
1106
+ * while a real model step always carries one (row 7).
1107
+ */
1108
+ function admissionViewOf(exec) {
1109
+ const toolSet = exec?.toolSet;
1110
+ if (toolSet == null || typeof toolSet.view !== 'function')
1111
+ return undefined;
1112
+ try {
1113
+ const view = toolSet.view(exec?.agent);
1114
+ if (view == null || typeof view.has !== 'function')
1115
+ return undefined;
1116
+ return (tool) => view.has(tool) === true;
1117
+ }
1118
+ catch {
1119
+ return undefined;
1120
+ }
1121
+ }
1122
+ /**
1123
+ * The args as they will arrive from the host.
1124
+ *
1125
+ * `JSON.stringify` collapses `-0` to `0` and rewrites non-finite numbers to
1126
+ * `null`, so a pending tree that skipped this round trip would disagree with
1127
+ * its own dispatched call: `sameLiteral` would report tampering and the planned
1128
+ * call would never run (review cod#2).
1129
+ */
1130
+ function jsonNormalise(args) {
1131
+ try {
1132
+ const text = JSON.stringify(args);
1133
+ if (text === undefined)
1134
+ return args;
1135
+ const parsed = JSON.parse(text);
1136
+ if (parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)) {
1137
+ return parsed;
1138
+ }
1139
+ return args;
1140
+ }
1141
+ catch {
1142
+ return args;
1143
+ }
1144
+ }
1064
1145
  /**
1065
1146
  * The substitution decision and its side effects.
1066
1147
  *
1067
1148
  * The fixed order is the plan's: existence of a plan and a receipt first, then
1068
- * `worthSubstituting`, then `budget.take()`. Nothing below spends budget on a
1069
- * decision that will not be dispatched.
1149
+ * `worthSubstituting`, then `budget.take()`. The step's admission filter
1150
+ * (row 7) runs inside `decide`, before the selector is priced and before the
1151
+ * budget is taken; when its evidence is unavailable the commit still happens
1152
+ * and a `substitute-skipped:no-toolset` line records that it did.
1153
+ * Nothing below spends budget on a decision that will not be dispatched.
1070
1154
  *
1071
1155
  * `ask-selector` is fulfilled here since Task 23c-2: the decision carries only
1072
1156
  * already-bound candidates, so the selector's choice is committed from
@@ -1123,6 +1207,12 @@ async function decideSubstitution(deps, ctx) {
1123
1207
  }));
1124
1208
  return;
1125
1209
  }
1210
+ // Row 7: this step's `ResolvedToolSet` is the host's admission set, so
1211
+ // `decide` drops a candidate whose tool it does not admit before the selector
1212
+ // or the budget is touched. Shadow mode is record-only and measures potential
1213
+ // across the whole whitelist, so it passes no admission filter.
1214
+ const admission = ctx.doc.shadow ? undefined : admissionViewOf(ctx.exec);
1215
+ const noToolset = !ctx.doc.shadow && admission === undefined;
1126
1216
  let decision;
1127
1217
  try {
1128
1218
  decision = decide({
@@ -1131,9 +1221,14 @@ async function decideSubstitution(deps, ctx) {
1131
1221
  receipts: ctx.state.receiptsFor(ctx.sessionId, ctx.turn),
1132
1222
  whitelist: SUBSTITUTION_WHITELIST,
1133
1223
  shadow: ctx.doc.shadow,
1224
+ ...(admission === undefined ? {} : { admitted: admission }),
1134
1225
  });
1135
1226
  }
1136
1227
  catch {
1228
+ // A throwing gate silently disabled substitution for this receipt, so make
1229
+ // it visible in `status.counts` (review row 24). The plan was already
1230
+ // consumed above; nothing can fire later from this failure.
1231
+ await appendReceipt(deps, ledgerEntry(ctx, 'skip', 'substitute-skipped:gate-error', { stepId: 'root' }));
1137
1232
  return;
1138
1233
  }
1139
1234
  // Substitution synthesises a dispatch and expects POSIX process semantics;
@@ -1263,8 +1358,14 @@ async function decideSubstitution(deps, ctx) {
1263
1358
  candidateId,
1264
1359
  // The candidate's tool name identifies the call; the executable args are
1265
1360
  // the *decision's* bound tree, never the plan's `$public` template.
1361
+ //
1362
+ // Normalised through a JSON round trip so the pending tree is byte-for-byte
1363
+ // what the host will hand back. `JSON.stringify` rewrites `-0` to `0` and
1364
+ // `Infinity`/`NaN` to `null`; without this, a legal plan arg of `-0` would
1365
+ // arrive as `0` and `sameLiteral` would report tampering, so the planned
1366
+ // call would never run (review cod#2).
1266
1367
  name: candidate.tool,
1267
- args: boundArgs,
1368
+ args: jsonNormalise(boundArgs),
1268
1369
  turn: ctx.turn,
1269
1370
  step,
1270
1371
  // The plan is one-shot (cleared above), so the evidence must travel with
@@ -1286,6 +1387,15 @@ async function decideSubstitution(deps, ctx) {
1286
1387
  }));
1287
1388
  return;
1288
1389
  }
1390
+ // Row 7: the commit is real but the admission evidence was not available.
1391
+ // Recording it here (not at the missing-evidence point above) means the note
1392
+ // names the candidate that actually committed and only exists when one did.
1393
+ if (noToolset) {
1394
+ await appendReceipt(deps, ledgerEntry(ctx, 'skip', 'substitute-skipped:no-toolset', {
1395
+ stepId: 'root',
1396
+ candidateId,
1397
+ }));
1398
+ }
1289
1399
  markSubstituted(deps, ctx.sessionId, candidateId);
1290
1400
  // Anchors name the templates the executed call was bound from: the decision's
1291
1401
  // args are already expanded, so only the plan copy still carries the
@@ -1552,15 +1662,45 @@ async function projectDecision(deps, receipt, decision, ctx) {
1552
1662
  * The decision + projection stage.
1553
1663
  *
1554
1664
  * Both seams live in one place so the listener's order is visible in one
1555
- * function: decide, then the double-projection guard, then project. A shadow
1556
- * substitution does not stop the projection: the two switches are independent
1557
- * (design §5.2-5), and in projection-shadow mode the projection writes only
1558
- * its accounting line.
1665
+ * function: the receipt-visibility gate, then decide, then the
1666
+ * double-projection guard, then project. A shadow substitution does not stop
1667
+ * the projection: the two switches are independent (design §5.2-5), and in
1668
+ * projection-shadow mode the projection writes only its accounting line.
1559
1669
  */
1560
1670
  async function applyDecision(deps, decision, ctx) {
1671
+ // Substitution is only legitimate while the receipt is what the model sees.
1672
+ // `decide` and its guards were evaluated against `ctx.receipt.text`; a
1673
+ // `block`, or an `accept` carrying a replacement `value`, hides that text, so
1674
+ // a commit would dispatch a call whose evidence the model never received
1675
+ // (review row 11). `projectionTargetOf` is the same visibility predicate
1676
+ // projection uses: it rejects `block` and any `accept` with a `value`, and
1677
+ // accepts an `accept` whose content is text (possibly rewritten).
1678
+ //
1679
+ // A hidden receipt still consumes the one-shot plan: the plan was written for
1680
+ // the call that produced it, and keeping it would let it fire against a later
1681
+ // receipt whose text it was not written for.
1682
+ //
1561
1683
  // Projection below runs for a shadow commit too: the decision side never
1562
1684
  // suppresses the projection ledger.
1563
- await decideSubstitution(deps, ctx);
1685
+ const visible = projectionTargetOf(decision, ctx.receipt, ctx.result);
1686
+ if (visible === undefined) {
1687
+ clearPlan(deps, ctx.sessionId);
1688
+ }
1689
+ else if (visible !== ctx.receipt.text) {
1690
+ // An `accept` carrying its own `content` shows the model text the plugin
1691
+ // never canonicalised, so every guard and every literal in the plan was
1692
+ // checked against something else. Projection may still run — it rewrites
1693
+ // the visible text deliberately — but a substitution must not commit on
1694
+ // evidence the model cannot see (review qr5#3).
1695
+ //
1696
+ // No receipt: this is the normal outer-shaper path (`dsh-spill-policy`
1697
+ // appends its footer in every session), not a degradation. A receipt here
1698
+ // would be one line per oversized receipt and would read as a failure.
1699
+ clearPlan(deps, ctx.sessionId);
1700
+ }
1701
+ else {
1702
+ await decideSubstitution(deps, ctx);
1703
+ }
1564
1704
  // Second-projection guard. Two host shapers are outer to this listener:
1565
1705
  //
1566
1706
  // - The spill policy registers with `{ prepend: true }`: it calls `next()`
@@ -1579,8 +1719,23 @@ async function applyDecision(deps, decision, ctx) {
1579
1719
  // to a receipt this listener already clipped. A family the plugin does not
1580
1720
  // project leaves the host shaper untouched.
1581
1721
  //
1582
- // Both the receiver as it arrived and the decision that will enter history
1583
- // are checked (design §5.4).
1722
+ // What these two checks can and cannot catch (review row 25):
1723
+ //
1724
+ // - The first reads `ctx.receipt.text`, captured before this listener
1725
+ // returns. The outer spill policy appends its footer to the decision
1726
+ // *after* this point, so this check can never see the host's own footer.
1727
+ // It can only fire when the tool's output already ends in a spill notice —
1728
+ // for example a `read` of a spill artifact, whose text carries the notice
1729
+ // literally. That is still a receipt that is already a preview, so
1730
+ // refusing to project it again is the intended, if narrow, guard.
1731
+ // - The second sees a replacement an inner listener wrote into the decision.
1732
+ // An outer shaper's footer is invisible to it too.
1733
+ //
1734
+ // Neither check is full double-spill detection: at this point the host's
1735
+ // footer does not exist yet, so projection and the outer spill policy can
1736
+ // both act on one receipt. That is fail-safe, not prevention: the
1737
+ // projection's own footer keeps the original retrievable, and the host's
1738
+ // second notice points at the projected text.
1584
1739
  if (await isAlreadySpilled(deps, ctx.receipt.text))
1585
1740
  return decision;
1586
1741
  const downstreamText = decisionTextOf(decision) ?? ctx.receipt.text;
@@ -1814,6 +1969,11 @@ async function appendDispatchRejected(deps, exec, entry, sessionId) {
1814
1969
  * then fails open.
1815
1970
  */
1816
1971
  async function inspectDispatch(deps, exec) {
1972
+ // Row 30: a PTC inner call carries `parent` and belongs to the enclosing
1973
+ // `run_code` step. Its host-assigned call id is not the root decision's, so
1974
+ // even a collision must not be read as our dispatch.
1975
+ if (exec.parent !== undefined)
1976
+ return { kind: 'next' };
1817
1977
  const sessionId = sessionIdOf(exec);
1818
1978
  if (sessionId === undefined)
1819
1979
  return { kind: 'next' };
@@ -1864,6 +2024,10 @@ async function inspectDispatch(deps, exec) {
1864
2024
  * not block every tool call in the process.
1865
2025
  */
1866
2026
  async function executeHook(deps, state, exec, next) {
2027
+ // Row 30: a PTC inner dispatch is the enclosing `run_code` step's business,
2028
+ // not this hook's; `next()` runs untouched so the inner tool still executes.
2029
+ if (exec?.parent !== undefined)
2030
+ return next();
1867
2031
  let outcome;
1868
2032
  try {
1869
2033
  outcome = await inspectDispatch(deps, exec);
@@ -1942,6 +2106,9 @@ export function registerHooks(ctx, deps) {
1942
2106
  // keeps the degradation warnings reachable without widening every caller's
1943
2107
  // deps literal. A deps object that already names one keeps it.
1944
2108
  deps.logger ??= ctx.logger;
2109
+ // Row 27: `llm/stream` records the synthesis through this seam, because the
2110
+ // mirror lives here and a denied dispatch never reaches `tools/execute`.
2111
+ deps.noteSynthesis ??= (sessionId, turn, candidateId, evidence) => noteAcceptedDispatch(deps, sessionId, turn, candidateId, evidence);
1945
2112
  registerProtocolSection(ctx, deps.scope);
1946
2113
  registerPostExecute(ctx, deps, state);
1947
2114
  registerLlmStream(ctx, deps);