dsh-boost 0.0.0-stage → 0.1.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 (110) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +29 -0
  3. package/README.en.md +476 -0
  4. package/README.md +408 -2
  5. package/cordis.patch.yml +40 -0
  6. package/dist/admission/fixed-cost.d.ts +23 -0
  7. package/dist/admission/fixed-cost.js +61 -0
  8. package/dist/admission/fixed-cost.js.map +1 -0
  9. package/dist/admission/ledger.d.ts +113 -0
  10. package/dist/admission/ledger.js +176 -0
  11. package/dist/admission/ledger.js.map +1 -0
  12. package/dist/admission/retrieval.d.ts +65 -0
  13. package/dist/admission/retrieval.js +162 -0
  14. package/dist/admission/retrieval.js.map +1 -0
  15. package/dist/admission/usage.d.ts +75 -0
  16. package/dist/admission/usage.js +124 -0
  17. package/dist/admission/usage.js.map +1 -0
  18. package/dist/config.d.ts +43 -0
  19. package/dist/config.js +103 -0
  20. package/dist/config.js.map +1 -0
  21. package/dist/gate/binding.d.ts +113 -0
  22. package/dist/gate/binding.js +297 -0
  23. package/dist/gate/binding.js.map +1 -0
  24. package/dist/gate/decide.d.ts +82 -0
  25. package/dist/gate/decide.js +163 -0
  26. package/dist/gate/decide.js.map +1 -0
  27. package/dist/gate/guard.d.ts +69 -0
  28. package/dist/gate/guard.js +195 -0
  29. package/dist/gate/guard.js.map +1 -0
  30. package/dist/gate/invalidate.d.ts +112 -0
  31. package/dist/gate/invalidate.js +111 -0
  32. package/dist/gate/invalidate.js.map +1 -0
  33. package/dist/gate/plan.d.ts +86 -0
  34. package/dist/gate/plan.js +222 -0
  35. package/dist/gate/plan.js.map +1 -0
  36. package/dist/hooks/clock.d.ts +68 -0
  37. package/dist/hooks/clock.js +82 -0
  38. package/dist/hooks/clock.js.map +1 -0
  39. package/dist/hooks/execute.d.ts +79 -0
  40. package/dist/hooks/execute.js +128 -0
  41. package/dist/hooks/execute.js.map +1 -0
  42. package/dist/hooks/llm-stream.d.ts +276 -0
  43. package/dist/hooks/llm-stream.js +1008 -0
  44. package/dist/hooks/llm-stream.js.map +1 -0
  45. package/dist/hooks/pending.d.ts +89 -0
  46. package/dist/hooks/pending.js +115 -0
  47. package/dist/hooks/pending.js.map +1 -0
  48. package/dist/hooks/post-execute.d.ts +247 -0
  49. package/dist/hooks/post-execute.js +1776 -0
  50. package/dist/hooks/post-execute.js.map +1 -0
  51. package/dist/hooks/session-state.d.ts +158 -0
  52. package/dist/hooks/session-state.js +168 -0
  53. package/dist/hooks/session-state.js.map +1 -0
  54. package/dist/hooks/synthesize.d.ts +74 -0
  55. package/dist/hooks/synthesize.js +100 -0
  56. package/dist/hooks/synthesize.js.map +1 -0
  57. package/dist/host/loader.d.ts +23 -0
  58. package/dist/host/loader.js +31 -0
  59. package/dist/host/loader.js.map +1 -0
  60. package/dist/host/platform.d.ts +18 -0
  61. package/dist/host/platform.js +19 -0
  62. package/dist/host/platform.js.map +1 -0
  63. package/dist/host/root.d.ts +18 -0
  64. package/dist/host/root.js +43 -0
  65. package/dist/host/root.js.map +1 -0
  66. package/dist/index.d.ts +13 -0
  67. package/dist/index.js +866 -0
  68. package/dist/index.js.map +1 -0
  69. package/dist/projection/apply.d.ts +174 -0
  70. package/dist/projection/apply.js +137 -0
  71. package/dist/projection/apply.js.map +1 -0
  72. package/dist/projection/canonicalise.d.ts +43 -0
  73. package/dist/projection/canonicalise.js +43 -0
  74. package/dist/projection/canonicalise.js.map +1 -0
  75. package/dist/projection/counters.d.ts +65 -0
  76. package/dist/projection/counters.js +88 -0
  77. package/dist/projection/counters.js.map +1 -0
  78. package/dist/projection/truncate.d.ts +47 -0
  79. package/dist/projection/truncate.js +57 -0
  80. package/dist/projection/truncate.js.map +1 -0
  81. package/dist/prompt/protocol.d.ts +45 -0
  82. package/dist/prompt/protocol.js +56 -0
  83. package/dist/prompt/protocol.js.map +1 -0
  84. package/dist/receipts/store.d.ts +198 -0
  85. package/dist/receipts/store.js +734 -0
  86. package/dist/receipts/store.js.map +1 -0
  87. package/dist/scope/doc.d.ts +117 -0
  88. package/dist/scope/doc.js +158 -0
  89. package/dist/scope/doc.js.map +1 -0
  90. package/dist/scope/resolve.d.ts +91 -0
  91. package/dist/scope/resolve.js +146 -0
  92. package/dist/scope/resolve.js.map +1 -0
  93. package/dist/scope/store.d.ts +135 -0
  94. package/dist/scope/store.js +573 -0
  95. package/dist/scope/store.js.map +1 -0
  96. package/dist/selector/jev.d.ts +93 -0
  97. package/dist/selector/jev.js +171 -0
  98. package/dist/selector/jev.js.map +1 -0
  99. package/dist/tools/boost.d.ts +367 -0
  100. package/dist/tools/boost.js +768 -0
  101. package/dist/tools/boost.js.map +1 -0
  102. package/dist/tools/family.d.ts +26 -0
  103. package/dist/tools/family.js +26 -0
  104. package/dist/tools/family.js.map +1 -0
  105. package/dist/types.d.ts +113 -0
  106. package/dist/types.js +21 -0
  107. package/dist/types.js.map +1 -0
  108. package/locale/en.json +6 -0
  109. package/locale/zh.json +6 -0
  110. package/package.json +75 -4
@@ -0,0 +1,222 @@
1
+ /**
2
+ * Plan parsing: model-written text becomes typed candidates.
3
+ *
4
+ * The model may write one `<CHISEL_PLAN>` block listing candidate tool calls.
5
+ * This module is the only place that text becomes data; guard evaluation,
6
+ * binding and the selector all trust what it returns, so parsing is strict:
7
+ * a document either yields a fully validated plan or exactly one error code
8
+ * (`no-plan`, `bad-json`, `bad-shape`). Nothing is ever thrown and no partial
9
+ * plan escapes.
10
+ *
11
+ * Only the first block counts. The block is located with two linear `indexOf`
12
+ * scans (opening tag, then the next closing tag); a pathological document with
13
+ * many unterminated openers must not stall the event loop. A second block is
14
+ * ignored even when the first is malformed, and an opening tag without its
15
+ * closing tag is not a block at all (`no-plan`).
16
+ *
17
+ * "Only literals" is enforced against what JSON can carry: `JSON.parse` cannot
18
+ * produce a function, so the rule reduces to "`args` may contain no
19
+ * `$`-prefixed key other than `$public`". That restriction covers the whole
20
+ * `args` tree, including inside a `$public` subtree; the sanctioned template
21
+ * (`{ after, field }`, with `$scalar`/`$single` as *values*) has no nested
22
+ * `$`-prefixed key, so the two rules never conflict. The `$public` subtree is
23
+ * otherwise preserved verbatim: its `after`/`field` semantics are validated by
24
+ * binding (task 12), not here. A root-level `$public` (the whole `args` object
25
+ * replaced by a scalar) is also left to binding to reject.
26
+ *
27
+ * Candidate ids are single capital ASCII letters (`A`–`Z`) because the
28
+ * selector answers with exactly one character equal to a candidate id; that
29
+ * also means a plan with more than 26 candidates is rejected. `tool` must be
30
+ * non-empty after trimming. `args` is capped at 64 levels of nesting and may
31
+ * not use the prototype-affecting keys `__proto__`, `constructor` or
32
+ * `prototype`: those collide in receipt hashing today and would pollute any
33
+ * future merge of `args`.
34
+ *
35
+ * @module dsh-boost/gate/plan
36
+ */
37
+ const PLAN_OPEN = '<CHISEL_PLAN>';
38
+ const PLAN_CLOSE = '</CHISEL_PLAN>';
39
+ /** Candidate id: exactly one capital letter, which is also the selector's label. */
40
+ const CANDIDATE_ID = /^[A-Z]$/;
41
+ /** Nesting cap for `args`; recursive consumers (hashing, binding) cannot take more. */
42
+ const MAX_ARGS_DEPTH = 64;
43
+ /** Keys that reach `Object.prototype` on assignment or collide in receipt hashing. */
44
+ const UNSAFE_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
45
+ /** Every failure leaves through here: one return shape, never a throw. */
46
+ function fail(code) {
47
+ return { error: code };
48
+ }
49
+ /** JSON object, not `null` and not an array. */
50
+ function object(value) {
51
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
52
+ }
53
+ /** The scalar `json_equals` may compare against. */
54
+ function scalar(value) {
55
+ return typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean';
56
+ }
57
+ /** `json_equals` keeps `value` exactly as JSON parsed it (a number stays a number). */
58
+ function decodeJsonEquals(raw) {
59
+ if (!object(raw))
60
+ return undefined;
61
+ const { pointer, value } = raw;
62
+ if (typeof pointer !== 'string' || !scalar(value))
63
+ return undefined;
64
+ return { json_equals: { pointer, value } };
65
+ }
66
+ /**
67
+ * Non-empty substring match. The empty string would make `text_contains`
68
+ * vacuously true and let an always-passing guard escape `guard-trivial`.
69
+ */
70
+ function decodeText(form) {
71
+ return (value) => {
72
+ if (typeof value !== 'string' || value.length === 0)
73
+ return undefined;
74
+ return form === 'text_contains' ? { text_contains: value } : { text_not_contains: value };
75
+ };
76
+ }
77
+ /** Ordered table of the four forms; a guard must match exactly one of them. */
78
+ const GUARD_FORMS = [
79
+ { key: 'ok', decode: (value) => (value === true ? { ok: true } : undefined) },
80
+ { key: 'text_contains', decode: decodeText('text_contains') },
81
+ { key: 'text_not_contains', decode: decodeText('text_not_contains') },
82
+ { key: 'json_equals', decode: decodeJsonEquals },
83
+ ];
84
+ /**
85
+ * Decode one guard, or `undefined` when it matches none of the four forms.
86
+ *
87
+ * Exactly one form key must be present: two at once are ambiguous, and a
88
+ * present-but-malformed form key is not an "extra key" that may be dropped.
89
+ * Any other keys are ignored, and only the matched form survives.
90
+ */
91
+ function matchGuard(raw) {
92
+ if (!object(raw))
93
+ return undefined;
94
+ const forms = GUARD_FORMS.filter((form) => Object.hasOwn(raw, form.key));
95
+ if (forms.length !== 1)
96
+ return undefined;
97
+ const form = forms[0];
98
+ // `length === 1` above guarantees the head; the check is here to narrow the
99
+ // type without a bang, not because the array can be short.
100
+ if (form === undefined)
101
+ return undefined;
102
+ return form.decode(raw[form.key]);
103
+ }
104
+ /** Whether `value` can contain children (arrays included). */
105
+ function container(value) {
106
+ return typeof value === 'object' && value !== null;
107
+ }
108
+ /**
109
+ * Whether `args` uses a key this module cannot pass downstream.
110
+ *
111
+ * Two families are rejected anywhere in the tree: `$`-prefixed directives
112
+ * (except `$public`, whose contents are otherwise left to binding) and the
113
+ * prototype-affecting names `__proto__`, `constructor`, `prototype`. The
114
+ * latter are never legitimate tool-argument names. `receiptHash`'s `sortKeys`
115
+ * now builds through `Object.create(null)`, so an own `__proto__` key is hashed
116
+ * rather than swallowed (row 33); rejecting these names here is
117
+ * defence-in-depth, not a workaround for that hash bug.
118
+ *
119
+ * Only containers are stacked, so a large array of scalars costs one pass.
120
+ * The walk is iterative because `JSON.parse` accepts nesting far deeper than a
121
+ * recursive walk could survive, and depth is capped because downstream
122
+ * consumers are recursive.
123
+ */
124
+ function hasForbiddenKey(args) {
125
+ const stack = [{ value: args, depth: 1 }];
126
+ while (stack.length > 0) {
127
+ const frame = stack.pop();
128
+ if (frame === undefined)
129
+ break;
130
+ if (frame.depth > MAX_ARGS_DEPTH)
131
+ return true;
132
+ if (Array.isArray(frame.value)) {
133
+ for (const item of frame.value) {
134
+ if (container(item))
135
+ stack.push({ value: item, depth: frame.depth + 1 });
136
+ }
137
+ continue;
138
+ }
139
+ for (const [key, child] of Object.entries(frame.value)) {
140
+ if (key.startsWith('$') && key !== '$public')
141
+ return true;
142
+ if (UNSAFE_KEYS.has(key))
143
+ return true;
144
+ if (container(child))
145
+ stack.push({ value: child, depth: frame.depth + 1 });
146
+ }
147
+ }
148
+ return false;
149
+ }
150
+ /** Decode one step, or `undefined` when any required field is missing or malformed. */
151
+ function parseCandidate(raw) {
152
+ if (!object(raw))
153
+ return undefined;
154
+ const { id, tool, args, guards } = raw;
155
+ if (typeof id !== 'string' || !CANDIDATE_ID.test(id))
156
+ return undefined;
157
+ if (typeof tool !== 'string' || tool.trim().length === 0)
158
+ return undefined;
159
+ if (!object(args) || hasForbiddenKey(args))
160
+ return undefined;
161
+ if (!Array.isArray(guards))
162
+ return undefined;
163
+ const decoded = [];
164
+ for (const rawGuard of guards) {
165
+ const guard = matchGuard(rawGuard);
166
+ if (guard === undefined)
167
+ return undefined;
168
+ decoded.push(guard);
169
+ }
170
+ return { id, tool, args, guards: decoded };
171
+ }
172
+ /**
173
+ * Parse the first `<CHISEL_PLAN>` block out of one model response.
174
+ *
175
+ * Returns `{ plan }` only when the whole block is understood: a non-empty
176
+ * `steps` array whose ids are unique capital letters, each with a non-empty
177
+ * tool, a literal `args` object and decodable guards. Everything else collapses
178
+ * to one error code, so callers can never act on half a plan. `goal` is
179
+ * documentation: a missing or non-string value becomes `''`, never an error.
180
+ */
181
+ export function parsePlan(text) {
182
+ const open = text.indexOf(PLAN_OPEN);
183
+ const close = open === -1 ? -1 : text.indexOf(PLAN_CLOSE, open + PLAN_OPEN.length);
184
+ if (open === -1 || close === -1)
185
+ return fail('no-plan');
186
+ let root;
187
+ try {
188
+ root = JSON.parse(text.slice(open + PLAN_OPEN.length, close));
189
+ }
190
+ catch {
191
+ return fail('bad-json');
192
+ }
193
+ if (!object(root))
194
+ return fail('bad-shape');
195
+ if (!Array.isArray(root.steps) || root.steps.length === 0)
196
+ return fail('bad-shape');
197
+ const steps = [];
198
+ const seen = new Set();
199
+ for (const rawStep of root.steps) {
200
+ const step = parseCandidate(rawStep);
201
+ if (step === undefined)
202
+ return fail('bad-shape');
203
+ // Candidate ids key derived tool-call ids downstream; a duplicate would
204
+ // attribute one call's receipt to the other.
205
+ if (seen.has(step.id))
206
+ return fail('bad-shape');
207
+ seen.add(step.id);
208
+ steps.push(step);
209
+ }
210
+ return { plan: { goal: typeof root.goal === 'string' ? root.goal : '', steps } };
211
+ }
212
+ /**
213
+ * Whether a candidate has nothing to check.
214
+ *
215
+ * True when every guard is `{ ok: true }`, including the empty array: nothing
216
+ * to check means nothing to check. Any non-`ok` guard makes the candidate
217
+ * non-trivial, which is what substitution requires (design §5.2, `guard-trivial`).
218
+ */
219
+ export function isTrivial(c) {
220
+ return c.guards.every((guard) => 'ok' in guard && guard.ok === true);
221
+ }
222
+ //# sourceMappingURL=plan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plan.js","sourceRoot":"","sources":["../../src/gate/plan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AA0BH,MAAM,SAAS,GAAG,eAAe,CAAA;AACjC,MAAM,UAAU,GAAG,gBAAgB,CAAA;AAEnC,oFAAoF;AACpF,MAAM,YAAY,GAAG,SAAS,CAAA;AAE9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I,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,CAAA;AAClF,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,CAAY;IACpC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,IAAI,KAAK,IAAI,KAAK,CAAC,EAAE,KAAK,IAAI,CAAC,CAAA;AACtE,CAAC","sourcesContent":["/**\n * Plan parsing: model-written text becomes typed candidates.\n *\n * The model may write one `<CHISEL_PLAN>` block listing candidate tool calls.\n * This module is the only place that text becomes data; guard evaluation,\n * binding and the selector all trust what it returns, so parsing is strict:\n * a document either yields a fully validated plan or exactly one error code\n * (`no-plan`, `bad-json`, `bad-shape`). Nothing is ever thrown and no partial\n * plan escapes.\n *\n * Only the first block counts. The block is located with two linear `indexOf`\n * scans (opening tag, then the next closing tag); a pathological document with\n * many unterminated openers must not stall the event loop. A second block is\n * ignored even when the first is malformed, and an opening tag without its\n * closing tag is not a block at all (`no-plan`).\n *\n * \"Only literals\" is enforced against what JSON can carry: `JSON.parse` cannot\n * produce a function, so the rule reduces to \"`args` may contain no\n * `$`-prefixed key other than `$public`\". That restriction covers the whole\n * `args` tree, including inside a `$public` subtree; the sanctioned template\n * (`{ after, field }`, with `$scalar`/`$single` as *values*) has no nested\n * `$`-prefixed key, so the two rules never conflict. The `$public` subtree is\n * otherwise preserved verbatim: its `after`/`field` semantics are validated by\n * binding (task 12), not here. A root-level `$public` (the whole `args` object\n * replaced by a scalar) is also left to binding to reject.\n *\n * Candidate ids are single capital ASCII letters (`A`–`Z`) because the\n * selector answers with exactly one character equal to a candidate id; that\n * also means a plan with more than 26 candidates is rejected. `tool` must be\n * non-empty after trimming. `args` is capped at 64 levels of nesting and may\n * not use the prototype-affecting keys `__proto__`, `constructor` or\n * `prototype`: those collide in receipt hashing today and would pollute any\n * future merge of `args`.\n *\n * @module dsh-boost/gate/plan\n */\n\n/** A deterministic receipt predicate. `ok` alone is trivial (design §5.2). */\nexport type Guard =\n | { ok: true }\n | { text_contains: string }\n | { text_not_contains: string }\n | { json_equals: { pointer: string; value: string | number | boolean } }\n\n/** One tool call the model proposed. */\nexport interface Candidate {\n id: string\n tool: string\n args: Record<string, unknown>\n guards: Guard[]\n}\n\n/** A parsed plan: documentation plus the candidate steps. */\nexport interface Plan {\n goal: string\n steps: Candidate[]\n}\n\n/** Why a document did not yield a plan. */\ntype PlanError = 'no-plan' | 'bad-json' | 'bad-shape'\n\nconst PLAN_OPEN = '<CHISEL_PLAN>'\nconst PLAN_CLOSE = '</CHISEL_PLAN>'\n\n/** Candidate id: exactly one capital letter, which is also the selector's label. */\nconst CANDIDATE_ID = /^[A-Z]$/\n\n/** Nesting cap for `args`; recursive consumers (hashing, binding) cannot take more. */\nconst MAX_ARGS_DEPTH = 64\n\n/** Keys that reach `Object.prototype` on assignment or collide in receipt hashing. */\nconst UNSAFE_KEYS: ReadonlySet<string> = new Set(['__proto__', 'constructor', 'prototype'])\n\n/** Every failure leaves through here: one return shape, never a throw. */\nfunction fail(code: PlanError): { error: PlanError } {\n return { error: code }\n}\n\n/** JSON object, not `null` and not an array. */\nfunction object(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\n/** The scalar `json_equals` may compare against. */\nfunction scalar(value: unknown): value is string | number | boolean {\n return typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean'\n}\n\n/** `json_equals` keeps `value` exactly as JSON parsed it (a number stays a number). */\nfunction decodeJsonEquals(raw: unknown): Guard | undefined {\n if (!object(raw)) return undefined\n const { pointer, value } = raw\n if (typeof pointer !== 'string' || !scalar(value)) return undefined\n return { json_equals: { pointer, value } }\n}\n\n/**\n * Non-empty substring match. The empty string would make `text_contains`\n * vacuously true and let an always-passing guard escape `guard-trivial`.\n */\nfunction decodeText(form: 'text_contains' | 'text_not_contains') {\n return (value: unknown): Guard | undefined => {\n if (typeof value !== 'string' || value.length === 0) return undefined\n return form === 'text_contains' ? { text_contains: value } : { text_not_contains: value }\n }\n}\n\n/** One accepted guard form, plus the decoder for its value. */\ninterface GuardForm {\n readonly key: string\n readonly decode: (value: unknown) => Guard | undefined\n}\n\n/** Ordered table of the four forms; a guard must match exactly one of them. */\nconst GUARD_FORMS: readonly GuardForm[] = [\n { key: 'ok', decode: (value) => (value === true ? { ok: true } : undefined) },\n { key: 'text_contains', decode: decodeText('text_contains') },\n { key: 'text_not_contains', decode: decodeText('text_not_contains') },\n { key: 'json_equals', decode: decodeJsonEquals },\n]\n\n/**\n * Decode one guard, or `undefined` when it matches none of the four forms.\n *\n * Exactly one form key must be present: two at once are ambiguous, and a\n * present-but-malformed form key is not an \"extra key\" that may be dropped.\n * Any other keys are ignored, and only the matched form survives.\n */\nfunction matchGuard(raw: unknown): Guard | undefined {\n if (!object(raw)) return undefined\n const forms = GUARD_FORMS.filter((form) => Object.hasOwn(raw, form.key))\n if (forms.length !== 1) return undefined\n const form = forms[0]\n // `length === 1` above guarantees the head; the check is here to narrow the\n // type without a bang, not because the array can be short.\n if (form === undefined) return undefined\n return form.decode(raw[form.key])\n}\n\n/** Whether `value` can contain children (arrays included). */\nfunction container(value: unknown): value is Record<string, unknown> | unknown[] {\n return typeof value === 'object' && value !== null\n}\n\n/**\n * Whether `args` uses a key this module cannot pass downstream.\n *\n * Two families are rejected anywhere in the tree: `$`-prefixed directives\n * (except `$public`, whose contents are otherwise left to binding) and the\n * prototype-affecting names `__proto__`, `constructor`, `prototype`. The\n * latter are never legitimate tool-argument names. `receiptHash`'s `sortKeys`\n * now builds through `Object.create(null)`, so an own `__proto__` key is hashed\n * rather than swallowed (row 33); rejecting these names here is\n * defence-in-depth, not a workaround for that hash bug.\n *\n * Only containers are stacked, so a large array of scalars costs one pass.\n * The walk is iterative because `JSON.parse` accepts nesting far deeper than a\n * recursive walk could survive, and depth is capped because downstream\n * consumers are recursive.\n */\nfunction hasForbiddenKey(args: Record<string, unknown>): boolean {\n const stack: Array<{ value: unknown; depth: number }> = [{ value: args, depth: 1 }]\n while (stack.length > 0) {\n const frame = stack.pop()\n if (frame === undefined) break\n if (frame.depth > MAX_ARGS_DEPTH) return true\n if (Array.isArray(frame.value)) {\n for (const item of frame.value) {\n if (container(item)) stack.push({ value: item, depth: frame.depth + 1 })\n }\n continue\n }\n for (const [key, child] of Object.entries(frame.value as Record<string, unknown>)) {\n if (key.startsWith('$') && key !== '$public') return true\n if (UNSAFE_KEYS.has(key)) return true\n if (container(child)) stack.push({ value: child, depth: frame.depth + 1 })\n }\n }\n return false\n}\n\n/** Decode one step, or `undefined` when any required field is missing or malformed. */\nfunction parseCandidate(raw: unknown): Candidate | undefined {\n if (!object(raw)) return undefined\n const { id, tool, args, guards } = raw\n if (typeof id !== 'string' || !CANDIDATE_ID.test(id)) return undefined\n if (typeof tool !== 'string' || tool.trim().length === 0) return undefined\n if (!object(args) || hasForbiddenKey(args)) return undefined\n if (!Array.isArray(guards)) return undefined\n const decoded: Guard[] = []\n for (const rawGuard of guards) {\n const guard = matchGuard(rawGuard)\n if (guard === undefined) return undefined\n decoded.push(guard)\n }\n return { id, tool, args, guards: decoded }\n}\n\n/**\n * Parse the first `<CHISEL_PLAN>` block out of one model response.\n *\n * Returns `{ plan }` only when the whole block is understood: a non-empty\n * `steps` array whose ids are unique capital letters, each with a non-empty\n * tool, a literal `args` object and decodable guards. Everything else collapses\n * to one error code, so callers can never act on half a plan. `goal` is\n * documentation: a missing or non-string value becomes `''`, never an error.\n */\nexport function parsePlan(text: string): { plan: Plan } | { error: PlanError } {\n const open = text.indexOf(PLAN_OPEN)\n const close = open === -1 ? -1 : text.indexOf(PLAN_CLOSE, open + PLAN_OPEN.length)\n if (open === -1 || close === -1) return fail('no-plan')\n\n let root: unknown\n try {\n root = JSON.parse(text.slice(open + PLAN_OPEN.length, close))\n } catch {\n return fail('bad-json')\n }\n if (!object(root)) return fail('bad-shape')\n\n if (!Array.isArray(root.steps) || root.steps.length === 0) return fail('bad-shape')\n\n const steps: Candidate[] = []\n const seen = new Set<string>()\n for (const rawStep of root.steps) {\n const step = parseCandidate(rawStep)\n if (step === undefined) return fail('bad-shape')\n // Candidate ids key derived tool-call ids downstream; a duplicate would\n // attribute one call's receipt to the other.\n if (seen.has(step.id)) return fail('bad-shape')\n seen.add(step.id)\n steps.push(step)\n }\n\n return { plan: { goal: typeof root.goal === 'string' ? root.goal : '', steps } }\n}\n\n/**\n * Whether a candidate has nothing to check.\n *\n * True when every guard is `{ ok: true }`, including the empty array: nothing\n * to check means nothing to check. Any non-`ok` guard makes the candidate\n * non-trivial, which is what substitution requires (design §5.2, `guard-trivial`).\n */\nexport function isTrivial(c: Candidate): boolean {\n return c.guards.every((guard) => 'ok' in guard && guard.ok === true)\n}\n"]}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Turn clock: the host turn index and the host step index within that turn.
3
+ *
4
+ * A DSH turn is not one model request. `dsh-agent-loop` loops `step` and each
5
+ * iteration calls `agent/request`, so a single turn contains many requests.
6
+ * The clock therefore copies the host's turn number on every request and resets
7
+ * its per-turn state only when that number changes: the first request of a turn
8
+ * starts the turn, later requests in the same turn leave it alone. The host
9
+ * supplies both numbers with each request; the clock never derives either from
10
+ * a request count.
11
+ *
12
+ * The turn index is evidence (a receipt is keyed by `(session, turn)`) and the
13
+ * host's **step index** (`step()`) is what a derived tool-call id is built
14
+ * from: two substitutions of one candidate inside a turn must not share an id.
15
+ * The per-turn substitution cap is not this class: it is `StepBudget`
16
+ * (`admission/ledger.ts`), keyed per session by `SessionRuntime`. The class
17
+ * keeps only the host's numbers; a plugin-side counter would be a second,
18
+ * fabricated source of step identity and must never feed `stepId` or `callId`.
19
+ *
20
+ * The class is deliberately bare — no timers, no host calls, no I/O — so it is
21
+ * testable without a host and cannot advance on wall time.
22
+ *
23
+ * One instance covers one session: two concurrent sessions sharing an instance
24
+ * would mix their turn numbers. Per-session keying belongs to the caller
25
+ * (`SessionRuntime` does it); this class does not guess a key. The turn index
26
+ * is also clamped monotonic, so a reused instance can never move `turn()`
27
+ * backwards.
28
+ *
29
+ * @module dsh-boost/hooks/clock
30
+ */
31
+ /** Copies the host turn/step; nothing is derived from a request count. */
32
+ export declare class TurnClock {
33
+ /** Current host turn; 0 before the first request. */
34
+ private turnCount;
35
+ /**
36
+ * The host's step index within the current turn; 0 before the first event.
37
+ *
38
+ * This is the host's number, never a plugin-side count. It exists because a
39
+ * derived tool-call id must be unique per step: two substitutions of one
40
+ * candidate inside one turn must not share an id, or the host persists two
41
+ * assistant `tool_use` blocks with one id and Anthropic-style providers
42
+ * reject the request (design §5.3, T23a/T23b).
43
+ */
44
+ private hostStep;
45
+ /**
46
+ * Record one model request for `hostTurn`, optionally at `hostStep`.
47
+ *
48
+ * A new turn resets the host step index; another request in the same turn
49
+ * leaves it alone. The host numbers are authoritative — they are copied,
50
+ * never derived from a request count here.
51
+ *
52
+ * Non-finite turns are ignored: `NaN !== NaN`, so accepting one would set the
53
+ * turn to `NaN` and reset state on every later request. Backwards turns are
54
+ * ignored too, so a reused instance cannot make `turn()` decrease. The
55
+ * optional `hostStep` is ignored unless finite and greater than the current
56
+ * one: the host's step index advances within a turn, and letting it move
57
+ * backwards would let one step's call id be reused by the next.
58
+ *
59
+ * Called with the turn alone (the pre-`step()` signature), the step index
60
+ * stays at whatever the host last reported — it is never incremented here,
61
+ * because a plugin-side count is exactly what must not become a step number.
62
+ */
63
+ onModelRequest(hostTurn: number, hostStep?: number): void;
64
+ /** The current host turn; 0 before the first model request. */
65
+ turn(): number;
66
+ /** The host step index within the current turn; 0 before the first event. */
67
+ step(): number;
68
+ }
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Turn clock: the host turn index and the host step index within that turn.
3
+ *
4
+ * A DSH turn is not one model request. `dsh-agent-loop` loops `step` and each
5
+ * iteration calls `agent/request`, so a single turn contains many requests.
6
+ * The clock therefore copies the host's turn number on every request and resets
7
+ * its per-turn state only when that number changes: the first request of a turn
8
+ * starts the turn, later requests in the same turn leave it alone. The host
9
+ * supplies both numbers with each request; the clock never derives either from
10
+ * a request count.
11
+ *
12
+ * The turn index is evidence (a receipt is keyed by `(session, turn)`) and the
13
+ * host's **step index** (`step()`) is what a derived tool-call id is built
14
+ * from: two substitutions of one candidate inside a turn must not share an id.
15
+ * The per-turn substitution cap is not this class: it is `StepBudget`
16
+ * (`admission/ledger.ts`), keyed per session by `SessionRuntime`. The class
17
+ * keeps only the host's numbers; a plugin-side counter would be a second,
18
+ * fabricated source of step identity and must never feed `stepId` or `callId`.
19
+ *
20
+ * The class is deliberately bare — no timers, no host calls, no I/O — so it is
21
+ * testable without a host and cannot advance on wall time.
22
+ *
23
+ * One instance covers one session: two concurrent sessions sharing an instance
24
+ * would mix their turn numbers. Per-session keying belongs to the caller
25
+ * (`SessionRuntime` does it); this class does not guess a key. The turn index
26
+ * is also clamped monotonic, so a reused instance can never move `turn()`
27
+ * backwards.
28
+ *
29
+ * @module dsh-boost/hooks/clock
30
+ */
31
+ /** Copies the host turn/step; nothing is derived from a request count. */
32
+ export class TurnClock {
33
+ /** Current host turn; 0 before the first request. */
34
+ turnCount = 0;
35
+ /**
36
+ * The host's step index within the current turn; 0 before the first event.
37
+ *
38
+ * This is the host's number, never a plugin-side count. It exists because a
39
+ * derived tool-call id must be unique per step: two substitutions of one
40
+ * candidate inside one turn must not share an id, or the host persists two
41
+ * assistant `tool_use` blocks with one id and Anthropic-style providers
42
+ * reject the request (design §5.3, T23a/T23b).
43
+ */
44
+ hostStep = 0;
45
+ /**
46
+ * Record one model request for `hostTurn`, optionally at `hostStep`.
47
+ *
48
+ * A new turn resets the host step index; another request in the same turn
49
+ * leaves it alone. The host numbers are authoritative — they are copied,
50
+ * never derived from a request count here.
51
+ *
52
+ * Non-finite turns are ignored: `NaN !== NaN`, so accepting one would set the
53
+ * turn to `NaN` and reset state on every later request. Backwards turns are
54
+ * ignored too, so a reused instance cannot make `turn()` decrease. The
55
+ * optional `hostStep` is ignored unless finite and greater than the current
56
+ * one: the host's step index advances within a turn, and letting it move
57
+ * backwards would let one step's call id be reused by the next.
58
+ *
59
+ * Called with the turn alone (the pre-`step()` signature), the step index
60
+ * stays at whatever the host last reported — it is never incremented here,
61
+ * because a plugin-side count is exactly what must not become a step number.
62
+ */
63
+ onModelRequest(hostTurn, hostStep) {
64
+ const nextStep = typeof hostStep === 'number' && Number.isFinite(hostStep) ? hostStep : undefined;
65
+ if (!Number.isFinite(hostTurn) || hostTurn <= this.turnCount) {
66
+ if (nextStep !== undefined && nextStep > this.hostStep)
67
+ this.hostStep = nextStep;
68
+ return;
69
+ }
70
+ this.turnCount = hostTurn;
71
+ this.hostStep = nextStep !== undefined && nextStep >= 0 ? nextStep : 0;
72
+ }
73
+ /** The current host turn; 0 before the first model request. */
74
+ turn() {
75
+ return this.turnCount;
76
+ }
77
+ /** The host step index within the current turn; 0 before the first event. */
78
+ step() {
79
+ return this.hostStep;
80
+ }
81
+ }
82
+ //# sourceMappingURL=clock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clock.js","sourceRoot":"","sources":["../../src/hooks/clock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,0EAA0E;AAC1E,MAAM,OAAO,SAAS;IACpB,qDAAqD;IAC7C,SAAS,GAAG,CAAC,CAAA;IAErB;;;;;;;;OAQG;IACK,QAAQ,GAAG,CAAC,CAAA;IAEpB;;;;;;;;;;;;;;;;;OAiBG;IACH,cAAc,CAAC,QAAgB,EAAE,QAAiB;QAChD,MAAM,QAAQ,GAAG,OAAO,QAAQ,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAA;QACjG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YAC7D,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,GAAG,IAAI,CAAC,QAAQ;gBAAE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;YAChF,OAAM;QACR,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAA;QACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,KAAK,SAAS,IAAI,QAAQ,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;IACxE,CAAC;IAED,+DAA+D;IAC/D,IAAI;QACF,OAAO,IAAI,CAAC,SAAS,CAAA;IACvB,CAAC;IAED,6EAA6E;IAC7E,IAAI;QACF,OAAO,IAAI,CAAC,QAAQ,CAAA;IACtB,CAAC;CACF","sourcesContent":["/**\n * Turn clock: the host turn index and the host step index within that turn.\n *\n * A DSH turn is not one model request. `dsh-agent-loop` loops `step` and each\n * iteration calls `agent/request`, so a single turn contains many requests.\n * The clock therefore copies the host's turn number on every request and resets\n * its per-turn state only when that number changes: the first request of a turn\n * starts the turn, later requests in the same turn leave it alone. The host\n * supplies both numbers with each request; the clock never derives either from\n * a request count.\n *\n * The turn index is evidence (a receipt is keyed by `(session, turn)`) and the\n * host's **step index** (`step()`) is what a derived tool-call id is built\n * from: two substitutions of one candidate inside a turn must not share an id.\n * The per-turn substitution cap is not this class: it is `StepBudget`\n * (`admission/ledger.ts`), keyed per session by `SessionRuntime`. The class\n * keeps only the host's numbers; a plugin-side counter would be a second,\n * fabricated source of step identity and must never feed `stepId` or `callId`.\n *\n * The class is deliberately bare — no timers, no host calls, no I/O — so it is\n * testable without a host and cannot advance on wall time.\n *\n * One instance covers one session: two concurrent sessions sharing an instance\n * would mix their turn numbers. Per-session keying belongs to the caller\n * (`SessionRuntime` does it); this class does not guess a key. The turn index\n * is also clamped monotonic, so a reused instance can never move `turn()`\n * backwards.\n *\n * @module dsh-boost/hooks/clock\n */\n\n/** Copies the host turn/step; nothing is derived from a request count. */\nexport class TurnClock {\n /** Current host turn; 0 before the first request. */\n private turnCount = 0\n\n /**\n * The host's step index within the current turn; 0 before the first event.\n *\n * This is the host's number, never a plugin-side count. It exists because a\n * derived tool-call id must be unique per step: two substitutions of one\n * candidate inside one turn must not share an id, or the host persists two\n * assistant `tool_use` blocks with one id and Anthropic-style providers\n * reject the request (design §5.3, T23a/T23b).\n */\n private hostStep = 0\n\n /**\n * Record one model request for `hostTurn`, optionally at `hostStep`.\n *\n * A new turn resets the host step index; another request in the same turn\n * leaves it alone. The host numbers are authoritative — they are copied,\n * never derived from a request count here.\n *\n * Non-finite turns are ignored: `NaN !== NaN`, so accepting one would set the\n * turn to `NaN` and reset state on every later request. Backwards turns are\n * ignored too, so a reused instance cannot make `turn()` decrease. The\n * optional `hostStep` is ignored unless finite and greater than the current\n * one: the host's step index advances within a turn, and letting it move\n * backwards would let one step's call id be reused by the next.\n *\n * Called with the turn alone (the pre-`step()` signature), the step index\n * stays at whatever the host last reported — it is never incremented here,\n * because a plugin-side count is exactly what must not become a step number.\n */\n onModelRequest(hostTurn: number, hostStep?: number): void {\n const nextStep = typeof hostStep === 'number' && Number.isFinite(hostStep) ? hostStep : undefined\n if (!Number.isFinite(hostTurn) || hostTurn <= this.turnCount) {\n if (nextStep !== undefined && nextStep > this.hostStep) this.hostStep = nextStep\n return\n }\n this.turnCount = hostTurn\n this.hostStep = nextStep !== undefined && nextStep >= 0 ? nextStep : 0\n }\n\n /** The current host turn; 0 before the first model request. */\n turn(): number {\n return this.turnCount\n }\n\n /** The host step index within the current turn; 0 before the first event. */\n step(): number {\n return this.hostStep\n }\n}\n"]}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Dispatch tamper check: the call that arrived is the call that was decided.
3
+ *
4
+ * When the plugin substitutes a call it decides the args, then synthesizes a
5
+ * turn in which the model appears to have asked for them. Between the decision
6
+ * and `tools/execute` those args pass through a round trip; if what arrives
7
+ * differs from what was decided, the substitution has been tampered with — by a
8
+ * prompt injection, by the model rewriting its own call, or by a bug — and the
9
+ * call must be refused rather than executed.
10
+ *
11
+ * The comparison is structural and literal, and it proves equality only for the
12
+ * same tool name and the same parsed argument tree. Anything it cannot prove
13
+ * equal is refused; convenience is never a reason to accept.
14
+ *
15
+ * @module dsh-boost/hooks/execute
16
+ */
17
+ /**
18
+ * Whether two values are literally the same, without normalising anything.
19
+ *
20
+ * - Two non-objects compare with `Object.is`: `NaN` equals `NaN`, and `-0` does
21
+ * not equal `0`. That is the strictest reading; the point of this function is
22
+ * to refuse what it cannot prove.
23
+ * - Arrays compare element by element, in order, and by length. An array never
24
+ * equals a non-array.
25
+ * - Objects compare their own enumerable string keys: the key sets must match
26
+ * and every key's value must compare equal recursively. Key order is
27
+ * irrelevant, and a key whose value is `undefined` is still a key.
28
+ *
29
+ * Only own enumerable string keys participate, matching the host's
30
+ * "losslessly JSON-serializable parsed arguments": a plain record, an array or
31
+ * a scalar is the whole domain, and a non-plain object (a `Date`, a `Map`, a
32
+ * class instance) is compared by whatever own keys it exposes — a `Date`
33
+ * contributes none, exactly as the key rule says.
34
+ *
35
+ * The walk is depth-limited rather than cycle-aware: past
36
+ * {@link MAX_LITERAL_DEPTH} it answers `false`, which also terminates on a
37
+ * cyclic argument tree. A pair of distinct but structurally identical cycles is
38
+ * therefore refused — the guard cannot prove them equal without a cycle-aware
39
+ * walk, and refusing is the correct answer.
40
+ *
41
+ * @param a - first value, of any shape.
42
+ * @param b - second value, of any shape.
43
+ * @returns whether the two values are the same literal tree.
44
+ */
45
+ export declare function sameLiteral(a: unknown, b: unknown): boolean;
46
+ /**
47
+ * Refuse a dispatch whose arrival differs from the pending substitution.
48
+ *
49
+ * No `pending` entry means the plugin is not substituting this call, so it has
50
+ * nothing to say about it and the call proceeds. Otherwise the arriving tool
51
+ * `name` must be the decided name and the arriving parsed `arguments` must be
52
+ * literally equal to the decided `args`; any difference is a tampered dispatch.
53
+ *
54
+ * A zero-argument call can arrive with `arguments: undefined` while the pending
55
+ * entry stores `{}`; `undefined` alone is normalised to `{}` so substitution is
56
+ * not disabled for every zero-argument tool. `null` is a real value and is
57
+ * compared as one, so it does not match `{}`.
58
+ *
59
+ * This function only reports the verdict: it cannot see the queue, so it never
60
+ * clears the pending entry. `registerHooks` clears the queue after receiving a
61
+ * `reject` (Task 23b wires the lookup and the clearing).
62
+ *
63
+ * @param exec - the arriving dispatch: tool name and parsed arguments.
64
+ * @param pending - the decided substitution, or `undefined` when none applies.
65
+ * @returns `{reject: true, code: 'dispatch-rejected'}` on any mismatch, else
66
+ * `{reject: false}`.
67
+ */
68
+ export declare function rejectIfTampered(exec: {
69
+ name: string;
70
+ arguments: unknown;
71
+ }, pending: {
72
+ name: string;
73
+ args: Record<string, unknown>;
74
+ } | undefined): {
75
+ reject: true;
76
+ code: 'dispatch-rejected';
77
+ } | {
78
+ reject: false;
79
+ };
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Dispatch tamper check: the call that arrived is the call that was decided.
3
+ *
4
+ * When the plugin substitutes a call it decides the args, then synthesizes a
5
+ * turn in which the model appears to have asked for them. Between the decision
6
+ * and `tools/execute` those args pass through a round trip; if what arrives
7
+ * differs from what was decided, the substitution has been tampered with — by a
8
+ * prompt injection, by the model rewriting its own call, or by a bug — and the
9
+ * call must be refused rather than executed.
10
+ *
11
+ * The comparison is structural and literal, and it proves equality only for the
12
+ * same tool name and the same parsed argument tree. Anything it cannot prove
13
+ * equal is refused; convenience is never a reason to accept.
14
+ *
15
+ * @module dsh-boost/hooks/execute
16
+ */
17
+ /**
18
+ * Deepest container nest {@link sameLiteral} descends before refusing.
19
+ *
20
+ * Task 11 caps plan args at 64 levels (`MAX_ARGS_DEPTH` in `src/gate/plan.ts`,
21
+ * counted with the root at 1), so a legitimate dispatch never reaches this
22
+ * bound. The guard exists because the function is exported and must be total: a
23
+ * caller can hand it arbitrary depth or a cycle, and both must answer `false`
24
+ * instead of overflowing the stack or hanging.
25
+ */
26
+ const MAX_LITERAL_DEPTH = 64;
27
+ /**
28
+ * Whether two values are literally the same, without normalising anything.
29
+ *
30
+ * - Two non-objects compare with `Object.is`: `NaN` equals `NaN`, and `-0` does
31
+ * not equal `0`. That is the strictest reading; the point of this function is
32
+ * to refuse what it cannot prove.
33
+ * - Arrays compare element by element, in order, and by length. An array never
34
+ * equals a non-array.
35
+ * - Objects compare their own enumerable string keys: the key sets must match
36
+ * and every key's value must compare equal recursively. Key order is
37
+ * irrelevant, and a key whose value is `undefined` is still a key.
38
+ *
39
+ * Only own enumerable string keys participate, matching the host's
40
+ * "losslessly JSON-serializable parsed arguments": a plain record, an array or
41
+ * a scalar is the whole domain, and a non-plain object (a `Date`, a `Map`, a
42
+ * class instance) is compared by whatever own keys it exposes — a `Date`
43
+ * contributes none, exactly as the key rule says.
44
+ *
45
+ * The walk is depth-limited rather than cycle-aware: past
46
+ * {@link MAX_LITERAL_DEPTH} it answers `false`, which also terminates on a
47
+ * cyclic argument tree. A pair of distinct but structurally identical cycles is
48
+ * therefore refused — the guard cannot prove them equal without a cycle-aware
49
+ * walk, and refusing is the correct answer.
50
+ *
51
+ * @param a - first value, of any shape.
52
+ * @param b - second value, of any shape.
53
+ * @returns whether the two values are the same literal tree.
54
+ */
55
+ export function sameLiteral(a, b) {
56
+ const sameNode = (left, right, depth) => {
57
+ // Refuse before descending, so the recursion is bounded at every level —
58
+ // including one where both values happen to be identical.
59
+ if (depth > MAX_LITERAL_DEPTH)
60
+ return false;
61
+ // Identity is proof, and keeps `NaN` equal to itself: a cycle compared
62
+ // with itself terminates here at its closing edge.
63
+ if (Object.is(left, right))
64
+ return true;
65
+ const objectLeft = typeof left === 'object' && left !== null;
66
+ const objectRight = typeof right === 'object' && right !== null;
67
+ if (!objectLeft || !objectRight)
68
+ return false;
69
+ const arrayLeft = Array.isArray(left);
70
+ const arrayRight = Array.isArray(right);
71
+ if (arrayLeft !== arrayRight)
72
+ return false;
73
+ if (arrayLeft && arrayRight) {
74
+ if (left.length !== right.length)
75
+ return false;
76
+ for (let index = 0; index < left.length; index += 1) {
77
+ if (!sameNode(left[index], right[index], depth + 1))
78
+ return false;
79
+ }
80
+ return true;
81
+ }
82
+ const keysLeft = Object.keys(left);
83
+ const keysRight = Object.keys(right);
84
+ if (keysLeft.length !== keysRight.length)
85
+ return false;
86
+ for (const key of keysLeft) {
87
+ if (!Object.hasOwn(right, key))
88
+ return false;
89
+ const leftValue = left[key];
90
+ const rightValue = right[key];
91
+ if (!sameNode(leftValue, rightValue, depth + 1))
92
+ return false;
93
+ }
94
+ return true;
95
+ };
96
+ return sameNode(a, b, 0);
97
+ }
98
+ /**
99
+ * Refuse a dispatch whose arrival differs from the pending substitution.
100
+ *
101
+ * No `pending` entry means the plugin is not substituting this call, so it has
102
+ * nothing to say about it and the call proceeds. Otherwise the arriving tool
103
+ * `name` must be the decided name and the arriving parsed `arguments` must be
104
+ * literally equal to the decided `args`; any difference is a tampered dispatch.
105
+ *
106
+ * A zero-argument call can arrive with `arguments: undefined` while the pending
107
+ * entry stores `{}`; `undefined` alone is normalised to `{}` so substitution is
108
+ * not disabled for every zero-argument tool. `null` is a real value and is
109
+ * compared as one, so it does not match `{}`.
110
+ *
111
+ * This function only reports the verdict: it cannot see the queue, so it never
112
+ * clears the pending entry. `registerHooks` clears the queue after receiving a
113
+ * `reject` (Task 23b wires the lookup and the clearing).
114
+ *
115
+ * @param exec - the arriving dispatch: tool name and parsed arguments.
116
+ * @param pending - the decided substitution, or `undefined` when none applies.
117
+ * @returns `{reject: true, code: 'dispatch-rejected'}` on any mismatch, else
118
+ * `{reject: false}`.
119
+ */
120
+ export function rejectIfTampered(exec, pending) {
121
+ if (pending == null)
122
+ return { reject: false };
123
+ const arrived = exec.arguments === undefined ? {} : exec.arguments;
124
+ if (exec.name === pending.name && sameLiteral(arrived, pending.args))
125
+ return { reject: false };
126
+ return { reject: true, code: 'dispatch-rejected' };
127
+ }
128
+ //# sourceMappingURL=execute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute.js","sourceRoot":"","sources":["../../src/hooks/execute.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH;;;;;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,EAAE,CAAA;AACpD,CAAC","sourcesContent":["/**\n * Dispatch tamper check: the call that arrived is the call that was decided.\n *\n * When the plugin substitutes a call it decides the args, then synthesizes a\n * turn in which the model appears to have asked for them. Between the decision\n * and `tools/execute` those args pass through a round trip; if what arrives\n * differs from what was decided, the substitution has been tampered with — by a\n * prompt injection, by the model rewriting its own call, or by a bug — and the\n * call must be refused rather than executed.\n *\n * The comparison is structural and literal, and it proves equality only for the\n * same tool name and the same parsed argument tree. Anything it cannot prove\n * equal is refused; convenience is never a reason to accept.\n *\n * @module dsh-boost/hooks/execute\n */\n\n/**\n * Deepest container nest {@link sameLiteral} descends before refusing.\n *\n * Task 11 caps plan args at 64 levels (`MAX_ARGS_DEPTH` in `src/gate/plan.ts`,\n * counted with the root at 1), so a legitimate dispatch never reaches this\n * bound. The guard exists because the function is exported and must be total: a\n * caller can hand it arbitrary depth or a cycle, and both must answer `false`\n * instead of overflowing the stack or hanging.\n */\nconst MAX_LITERAL_DEPTH = 64\n\n/**\n * Whether two values are literally the same, without normalising anything.\n *\n * - Two non-objects compare with `Object.is`: `NaN` equals `NaN`, and `-0` does\n * not equal `0`. That is the strictest reading; the point of this function is\n * to refuse what it cannot prove.\n * - Arrays compare element by element, in order, and by length. An array never\n * equals a non-array.\n * - Objects compare their own enumerable string keys: the key sets must match\n * and every key's value must compare equal recursively. Key order is\n * irrelevant, and a key whose value is `undefined` is still a key.\n *\n * Only own enumerable string keys participate, matching the host's\n * \"losslessly JSON-serializable parsed arguments\": a plain record, an array or\n * a scalar is the whole domain, and a non-plain object (a `Date`, a `Map`, a\n * class instance) is compared by whatever own keys it exposes — a `Date`\n * contributes none, exactly as the key rule says.\n *\n * The walk is depth-limited rather than cycle-aware: past\n * {@link MAX_LITERAL_DEPTH} it answers `false`, which also terminates on a\n * cyclic argument tree. A pair of distinct but structurally identical cycles is\n * therefore refused — the guard cannot prove them equal without a cycle-aware\n * walk, and refusing is the correct answer.\n *\n * @param a - first value, of any shape.\n * @param b - second value, of any shape.\n * @returns whether the two values are the same literal tree.\n */\nexport function sameLiteral(a: unknown, b: unknown): boolean {\n const sameNode = (left: unknown, right: unknown, depth: number): boolean => {\n // Refuse before descending, so the recursion is bounded at every level —\n // including one where both values happen to be identical.\n if (depth > MAX_LITERAL_DEPTH) return false\n // Identity is proof, and keeps `NaN` equal to itself: a cycle compared\n // with itself terminates here at its closing edge.\n if (Object.is(left, right)) return true\n const objectLeft = typeof left === 'object' && left !== null\n const objectRight = typeof right === 'object' && right !== null\n if (!objectLeft || !objectRight) return false\n\n const arrayLeft = Array.isArray(left)\n const arrayRight = Array.isArray(right)\n if (arrayLeft !== arrayRight) return false\n if (arrayLeft && arrayRight) {\n if (left.length !== right.length) return false\n for (let index = 0; index < left.length; index += 1) {\n if (!sameNode(left[index], right[index], depth + 1)) return false\n }\n return true\n }\n\n const keysLeft = Object.keys(left)\n const keysRight = Object.keys(right)\n if (keysLeft.length !== keysRight.length) return false\n for (const key of keysLeft) {\n if (!Object.hasOwn(right, key)) return false\n const leftValue = (left as Record<string, unknown>)[key]\n const rightValue = (right as Record<string, unknown>)[key]\n if (!sameNode(leftValue, rightValue, depth + 1)) return false\n }\n return true\n }\n\n return sameNode(a, b, 0)\n}\n\n/**\n * Refuse a dispatch whose arrival differs from the pending substitution.\n *\n * No `pending` entry means the plugin is not substituting this call, so it has\n * nothing to say about it and the call proceeds. Otherwise the arriving tool\n * `name` must be the decided name and the arriving parsed `arguments` must be\n * literally equal to the decided `args`; any difference is a tampered dispatch.\n *\n * A zero-argument call can arrive with `arguments: undefined` while the pending\n * entry stores `{}`; `undefined` alone is normalised to `{}` so substitution is\n * not disabled for every zero-argument tool. `null` is a real value and is\n * compared as one, so it does not match `{}`.\n *\n * This function only reports the verdict: it cannot see the queue, so it never\n * clears the pending entry. `registerHooks` clears the queue after receiving a\n * `reject` (Task 23b wires the lookup and the clearing).\n *\n * @param exec - the arriving dispatch: tool name and parsed arguments.\n * @param pending - the decided substitution, or `undefined` when none applies.\n * @returns `{reject: true, code: 'dispatch-rejected'}` on any mismatch, else\n * `{reject: false}`.\n */\nexport function rejectIfTampered(\n exec: { name: string; arguments: unknown },\n pending: { name: string; args: Record<string, unknown> } | undefined,\n): { reject: true; code: 'dispatch-rejected' } | { reject: false } {\n if (pending == null) return { reject: false }\n const arrived = exec.arguments === undefined ? {} : exec.arguments\n if (exec.name === pending.name && sameLiteral(arrived, pending.args)) return { reject: false }\n return { reject: true, code: 'dispatch-rejected' }\n}\n"]}