agentfootprint 9.85.0 → 9.86.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 (150) hide show
  1. package/CHANGELOG.md +376 -24
  2. package/dist/core/Agent.js +15 -4
  3. package/dist/core/Agent.js.map +1 -1
  4. package/dist/core/agent/AgentBuilder.js.map +1 -1
  5. package/dist/core/agent/buildAgentChart.js +5 -0
  6. package/dist/core/agent/buildAgentChart.js.map +1 -1
  7. package/dist/core/agent/buildDynamicAgentChart.js +22 -4
  8. package/dist/core/agent/buildDynamicAgentChart.js.map +1 -1
  9. package/dist/core/agent/buildToolRegistry.js +12 -1
  10. package/dist/core/agent/buildToolRegistry.js.map +1 -1
  11. package/dist/core/agent/selfCallNotice.js +20 -7
  12. package/dist/core/agent/selfCallNotice.js.map +1 -1
  13. package/dist/core/agent/skillBrains.js +3 -2
  14. package/dist/core/agent/skillBrains.js.map +1 -1
  15. package/dist/core/agent/stages/stepNudge.js +13 -4
  16. package/dist/core/agent/stages/stepNudge.js.map +1 -1
  17. package/dist/core/agent/stages/toolCalls.js +389 -58
  18. package/dist/core/agent/stages/toolCalls.js.map +1 -1
  19. package/dist/core/agent/stages/wrapUp.js +43 -6
  20. package/dist/core/agent/stages/wrapUp.js.map +1 -1
  21. package/dist/core/agent/window/currentRequest.js +4 -2
  22. package/dist/core/agent/window/currentRequest.js.map +1 -1
  23. package/dist/core/slots/buildToolsSlot.js +20 -4
  24. package/dist/core/slots/buildToolsSlot.js.map +1 -1
  25. package/dist/doors/skill-graph.js +4 -1
  26. package/dist/doors/skill-graph.js.map +1 -1
  27. package/dist/esm/core/Agent.js +15 -4
  28. package/dist/esm/core/Agent.js.map +1 -1
  29. package/dist/esm/core/agent/AgentBuilder.d.ts +2 -1
  30. package/dist/esm/core/agent/AgentBuilder.js.map +1 -1
  31. package/dist/esm/core/agent/buildAgentChart.js +5 -0
  32. package/dist/esm/core/agent/buildAgentChart.js.map +1 -1
  33. package/dist/esm/core/agent/buildDynamicAgentChart.js +22 -4
  34. package/dist/esm/core/agent/buildDynamicAgentChart.js.map +1 -1
  35. package/dist/esm/core/agent/buildToolRegistry.d.ts +20 -0
  36. package/dist/esm/core/agent/buildToolRegistry.js +12 -1
  37. package/dist/esm/core/agent/buildToolRegistry.js.map +1 -1
  38. package/dist/esm/core/agent/selfCallNotice.d.ts +20 -7
  39. package/dist/esm/core/agent/selfCallNotice.js +20 -7
  40. package/dist/esm/core/agent/selfCallNotice.js.map +1 -1
  41. package/dist/esm/core/agent/skillBrains.d.ts +12 -4
  42. package/dist/esm/core/agent/skillBrains.js +3 -2
  43. package/dist/esm/core/agent/skillBrains.js.map +1 -1
  44. package/dist/esm/core/agent/stages/stepNudge.d.ts +13 -4
  45. package/dist/esm/core/agent/stages/stepNudge.js +13 -4
  46. package/dist/esm/core/agent/stages/stepNudge.js.map +1 -1
  47. package/dist/esm/core/agent/stages/toolCalls.d.ts +171 -0
  48. package/dist/esm/core/agent/stages/toolCalls.js +385 -57
  49. package/dist/esm/core/agent/stages/toolCalls.js.map +1 -1
  50. package/dist/esm/core/agent/stages/wrapUp.d.ts +33 -2
  51. package/dist/esm/core/agent/stages/wrapUp.js +41 -5
  52. package/dist/esm/core/agent/stages/wrapUp.js.map +1 -1
  53. package/dist/esm/core/agent/types.d.ts +21 -4
  54. package/dist/esm/core/agent/window/currentRequest.d.ts +4 -2
  55. package/dist/esm/core/agent/window/currentRequest.js +4 -2
  56. package/dist/esm/core/agent/window/currentRequest.js.map +1 -1
  57. package/dist/esm/core/slots/buildToolsSlot.d.ts +1 -1
  58. package/dist/esm/core/slots/buildToolsSlot.js +20 -4
  59. package/dist/esm/core/slots/buildToolsSlot.js.map +1 -1
  60. package/dist/esm/doors/skill-graph.d.ts +1 -1
  61. package/dist/esm/doors/skill-graph.js +4 -1
  62. package/dist/esm/doors/skill-graph.js.map +1 -1
  63. package/dist/esm/events/payloads.d.ts +26 -2
  64. package/dist/esm/index.js +6 -5
  65. package/dist/esm/index.js.map +1 -1
  66. package/dist/esm/lib/injection-engine/index.d.ts +1 -1
  67. package/dist/esm/lib/injection-engine/index.js +4 -1
  68. package/dist/esm/lib/injection-engine/index.js.map +1 -1
  69. package/dist/esm/lib/injection-engine/skillGraph.d.ts +56 -0
  70. package/dist/esm/lib/injection-engine/skillGraph.js +29 -3
  71. package/dist/esm/lib/injection-engine/skillGraph.js.map +1 -1
  72. package/dist/esm/lib/injection-engine/skillSteps.d.ts +20 -1
  73. package/dist/esm/lib/injection-engine/skillSteps.js +24 -3
  74. package/dist/esm/lib/injection-engine/skillSteps.js.map +1 -1
  75. package/dist/esm/lib/injection-engine/skillToolDescriptors.d.ts +18 -0
  76. package/dist/esm/lib/injection-engine/skillToolDescriptors.js +103 -10
  77. package/dist/esm/lib/injection-engine/skillToolDescriptors.js.map +1 -1
  78. package/dist/esm/lib/injection-engine/types.d.ts +12 -10
  79. package/dist/esm/lib/injection-engine/types.js +5 -4
  80. package/dist/esm/lib/injection-engine/types.js.map +1 -1
  81. package/dist/esm/lib/saidByPerson.d.ts +48 -15
  82. package/dist/esm/lib/saidByPerson.js +52 -17
  83. package/dist/esm/lib/saidByPerson.js.map +1 -1
  84. package/dist/esm/lib/spokenIds.d.ts +52 -0
  85. package/dist/esm/lib/spokenIds.js +11 -0
  86. package/dist/esm/lib/spokenIds.js.map +1 -0
  87. package/dist/esm/lib/trace-toolpack/traceToolpack.js +12 -5
  88. package/dist/esm/lib/trace-toolpack/traceToolpack.js.map +1 -1
  89. package/dist/index.js +6 -5
  90. package/dist/index.js.map +1 -1
  91. package/dist/lib/injection-engine/index.js +5 -2
  92. package/dist/lib/injection-engine/index.js.map +1 -1
  93. package/dist/lib/injection-engine/skillGraph.js +31 -4
  94. package/dist/lib/injection-engine/skillGraph.js.map +1 -1
  95. package/dist/lib/injection-engine/skillSteps.js +24 -3
  96. package/dist/lib/injection-engine/skillSteps.js.map +1 -1
  97. package/dist/lib/injection-engine/skillToolDescriptors.js +103 -10
  98. package/dist/lib/injection-engine/skillToolDescriptors.js.map +1 -1
  99. package/dist/lib/injection-engine/types.js +5 -4
  100. package/dist/lib/injection-engine/types.js.map +1 -1
  101. package/dist/lib/saidByPerson.js +53 -18
  102. package/dist/lib/saidByPerson.js.map +1 -1
  103. package/dist/lib/spokenIds.js +15 -0
  104. package/dist/lib/spokenIds.js.map +1 -0
  105. package/dist/lib/trace-toolpack/traceToolpack.js +12 -5
  106. package/dist/lib/trace-toolpack/traceToolpack.js.map +1 -1
  107. package/dist/types/core/Agent.d.ts.map +1 -1
  108. package/dist/types/core/agent/AgentBuilder.d.ts +2 -1
  109. package/dist/types/core/agent/AgentBuilder.d.ts.map +1 -1
  110. package/dist/types/core/agent/buildAgentChart.d.ts.map +1 -1
  111. package/dist/types/core/agent/buildDynamicAgentChart.d.ts.map +1 -1
  112. package/dist/types/core/agent/buildToolRegistry.d.ts +20 -0
  113. package/dist/types/core/agent/buildToolRegistry.d.ts.map +1 -1
  114. package/dist/types/core/agent/selfCallNotice.d.ts +20 -7
  115. package/dist/types/core/agent/selfCallNotice.d.ts.map +1 -1
  116. package/dist/types/core/agent/skillBrains.d.ts +12 -4
  117. package/dist/types/core/agent/skillBrains.d.ts.map +1 -1
  118. package/dist/types/core/agent/stages/stepNudge.d.ts +13 -4
  119. package/dist/types/core/agent/stages/stepNudge.d.ts.map +1 -1
  120. package/dist/types/core/agent/stages/toolCalls.d.ts +171 -0
  121. package/dist/types/core/agent/stages/toolCalls.d.ts.map +1 -1
  122. package/dist/types/core/agent/stages/wrapUp.d.ts +33 -2
  123. package/dist/types/core/agent/stages/wrapUp.d.ts.map +1 -1
  124. package/dist/types/core/agent/types.d.ts +21 -4
  125. package/dist/types/core/agent/types.d.ts.map +1 -1
  126. package/dist/types/core/agent/window/currentRequest.d.ts +4 -2
  127. package/dist/types/core/agent/window/currentRequest.d.ts.map +1 -1
  128. package/dist/types/core/slots/buildToolsSlot.d.ts +1 -1
  129. package/dist/types/core/slots/buildToolsSlot.d.ts.map +1 -1
  130. package/dist/types/doors/skill-graph.d.ts +1 -1
  131. package/dist/types/doors/skill-graph.d.ts.map +1 -1
  132. package/dist/types/events/payloads.d.ts +26 -2
  133. package/dist/types/events/payloads.d.ts.map +1 -1
  134. package/dist/types/index.d.ts.map +1 -1
  135. package/dist/types/lib/injection-engine/index.d.ts +1 -1
  136. package/dist/types/lib/injection-engine/index.d.ts.map +1 -1
  137. package/dist/types/lib/injection-engine/skillGraph.d.ts +56 -0
  138. package/dist/types/lib/injection-engine/skillGraph.d.ts.map +1 -1
  139. package/dist/types/lib/injection-engine/skillSteps.d.ts +20 -1
  140. package/dist/types/lib/injection-engine/skillSteps.d.ts.map +1 -1
  141. package/dist/types/lib/injection-engine/skillToolDescriptors.d.ts +18 -0
  142. package/dist/types/lib/injection-engine/skillToolDescriptors.d.ts.map +1 -1
  143. package/dist/types/lib/injection-engine/types.d.ts +12 -10
  144. package/dist/types/lib/injection-engine/types.d.ts.map +1 -1
  145. package/dist/types/lib/saidByPerson.d.ts +48 -15
  146. package/dist/types/lib/saidByPerson.d.ts.map +1 -1
  147. package/dist/types/lib/spokenIds.d.ts +53 -0
  148. package/dist/types/lib/spokenIds.d.ts.map +1 -0
  149. package/dist/types/lib/trace-toolpack/traceToolpack.d.ts.map +1 -1
  150. package/package.json +1 -1
@@ -49,9 +49,11 @@ import { typedEmit } from '../../../recorders/core/typedEmit.js';
49
49
  import { extractSequence } from '../../../security/extractSequence.js';
50
50
  import { skillTarget } from '../../../security/skillTarget.js';
51
51
  import { menuOutstanding } from '../../../lib/injection-engine/routingPolicy.js';
52
+ import { classifySkillTarget, } from '../../../lib/injection-engine/skillGraph.js';
52
53
  import { skillActivationConfirmation } from '../../../lib/injection-engine/skillToolDescriptors.js';
53
54
  import { selfCallNotice, selfSkillTools } from '../selfCallNotice.js';
54
55
  import { parkedMemberIds } from '../../../maps/engagement/types.js';
56
+ import { spoken } from '../../../lib/spokenIds.js';
55
57
  import { unconfiguredCredentialProvider } from '../../../identity/types.js';
56
58
  import { bindArtifacts, unconfiguredArtifacts, } from '../../../artifacts/capability.js';
57
59
  import { resolveToolWants, wantsNeedsStoreRefusal } from '../../../artifacts/wants.js';
@@ -130,60 +132,208 @@ function reportingCredentials(provider, scope, toolName) {
130
132
  };
131
133
  }
132
134
  /**
133
- * The re-prompt a refused `read_skill` gets back. It is the model's only feedback,
134
- * so it names what IS allowed rather than only what isn't.
135
+ * Is this `read_skill` target the cursor's own skill AND is that cursor
136
+ * MOUNTED — the one owner of "this call would change nothing" (9.86.0).
135
137
  *
136
- * Three shapes, because "not reachable" has three different reasons and only the
137
- * first two share a fix:
138
- * • something is reachable → name it, and ask for one of those;
139
- * • a decision `tree()` → nothing is EVER reachable by `read_skill`, because a
140
- * tree has no cursor to move (8.5.0). Saying "no skills are reachable from
141
- * here" would invite the model to try again from somewhere else; there is no
142
- * "elsewhere", so the message explains the tree instead;
143
- * • a flat graph that happens to be at a dead end → the original message.
138
+ * ── WHY POSITION ALONE IS NOT THE ANSWER ────────────────────────────────
139
+ *
140
+ * `classifySkillTarget` answers a question about POSITION: is the target where
141
+ * the cursor stands? For most of the loop that settles it — the cursor's body
142
+ * is in that call's system prompt and its tools are on that call's wire, so
143
+ * asking to read it activates nothing, moves nothing and reveals nothing the
144
+ * request did not already carry.
145
+ *
146
+ * A PARKED map breaks that. Parking suppresses a map's contribution and leaves
147
+ * the cursor exactly where it was, so at a parked cursor the very same id is a
148
+ * RE-ENGAGEMENT: the gate admits it, the map engages, and the member's body and
149
+ * tools ride again on the next pass. That call moves something, which makes it
150
+ * a capability, which makes it the policy's question to answer.
151
+ *
152
+ * The dispatch gate has known this since 9.59.0 — it tests re-engagement BEFORE
153
+ * its self-call arm, which is this same fact written as two ordered arms. The
154
+ * `skill_read` permission gate, 480 lines upstream, has no arms to order: it
155
+ * asks one question and either spends the policy check or skips it, and it was
156
+ * asking `classifySkillTarget` alone. So a role whose checker hid a skill could
157
+ * have the model un-park and re-activate it. This function is the question that
158
+ * gate now asks, over the parked set `parkedNow` hands both of them.
159
+ *
160
+ * @example
161
+ * ```ts
162
+ * atMountedCursor({ cursor: 'audit', target: 'audit' }); // true — a stay
163
+ * atMountedCursor({ cursor: 'audit', target: 'audit', parked: new Set(['audit']) }); // false — a re-engagement
164
+ * atMountedCursor({ cursor: 'audit', target: 'billing' }); // false — a move
165
+ * ```
144
166
  */
145
- function skillRefusal(requestedId, allowed, isTree) {
146
- const head = `read_skill("${requestedId}") is not reachable from here. `;
147
- if (allowed.length > 0) {
148
- return `${head}Reachable skills: ${allowed.join(', ')}. Pick one of these, or finish.`;
149
- }
150
- if (isTree) {
151
- return (`read_skill("${requestedId}") cannot move a decision tree. A tree routes by ` +
152
- 'predicate on every iteration — it has no cursor to jump, so this skill would ' +
153
- 'not activate even though the tool accepted the name. Answer with the skill the ' +
154
- 'tree routed to, or finish.');
167
+ export function atMountedCursor(args) {
168
+ const stay = classifySkillTarget({
169
+ ...(args.cursor !== undefined && { cursor: args.cursor }),
170
+ target: args.target,
171
+ }) === 'self';
172
+ return stay && args.parked?.has(args.target) !== true;
173
+ }
174
+ /**
175
+ * What a call to a name nothing can dispatch gets back (9.86.0).
176
+ *
177
+ * `Unknown tool: X` was the whole sentence, on both dispatch doors, while
178
+ * `mcpServe` — the same library, one directory away — had been answering
179
+ * "Unknown tool 'rm_rf'. Served tools: echo, delete_account." for releases. The
180
+ * model that mistyped a name, or named one from a restored transcript, was told
181
+ * only that it was wrong, never what would have worked, and the cheapest repair
182
+ * (read the roster) was the one it could not make.
183
+ *
184
+ * The roster is the DISPATCH set — `registryByName` plus the provider cache —
185
+ * because that is the true statement about resolution: these are the names that
186
+ * answered to something. It is deliberately NOT the offer: the wire is narrowed
187
+ * by steps, parks and postures, and a held-out tool still dispatches by name, so
188
+ * an offer-shaped list would be a different (and here, false) claim.
189
+ *
190
+ * ── AND IT SAYS "RESOLVED", NOT "COULD BE DISPATCHED" ───────────────────
191
+ *
192
+ * The first draft said "Tools that could be dispatched on that call". Two gates
193
+ * sit between resolution and a tool running — the `tool_call` permission check
194
+ * and the middleware chain — so a name in this map can resolve and still be
195
+ * refused, and the sentence promised the model a dispatch the very next gate
196
+ * would decline. Neither gate is asked here: a `PermissionChecker` is a port
197
+ * (a hub call per name, with its own events and its own audit rows), and
198
+ * spending a whole permission sweep to phrase an error is a cost the sentence
199
+ * does not need. It reports what this map DID — resolve a name — and claims
200
+ * nothing about what would have happened next.
201
+ *
202
+ * The roster is role-filtered before it gets here (`dispatchRoster`), so a tool
203
+ * belonging to a skill the caller's policy hides is never named; and when the
204
+ * filter empties a stocked roster the clause is DROPPED, because "no tool name
205
+ * resolved" would be a denial of what the dispatch map is holding.
206
+ *
207
+ * Anchored past tense, like every other persistent result: "on that call" binds
208
+ * the roster to the finished call the result answers, so a later iteration that
209
+ * adds or drops a provider tool cannot make this sentence wrong. No exhortation
210
+ * — the model does not need to be told to try again.
211
+ *
212
+ * Exported for the producer registry, and used by BOTH dispatch doors so they
213
+ * cannot drift.
214
+ */
215
+ export function unknownToolResult(toolName, dispatchable) {
216
+ const head = `Unknown tool '${toolName}' on that call.`;
217
+ if (dispatchable.named.length > 0) {
218
+ return (`${head} Tool names that resolved to an implementation on that ` +
219
+ `call: ${dispatchable.named.join(', ')}.`);
155
220
  }
156
- return `${head}No skills are reachable from here — answer with the current skill, or finish.`;
221
+ // Held-but-unnameable: the map had entries this caller may not be told about.
222
+ // Omission is free; the negative below would be false.
223
+ return dispatchable.held
224
+ ? head
225
+ : `${head} No tool name resolved to an implementation on that call.`;
157
226
  }
158
227
  /**
159
- * The re-prompt a POSTURE-refused `read_skill` gets back (SG-C `strictness`).
160
- * The pick was REACHABLE — the graph would have granted it — so the message
161
- * must teach the posture, not the map: who routes here, and what the model may
162
- * still do (open skills, staying, finishing).
228
+ * THE ONE COMPOSER of every `read_skill` refusal (9.86.0) — reachability,
229
+ * posture and tree, from one set of inputs.
230
+ *
231
+ * ── WHY ONE ─────────────────────────────────────────────────────────────
232
+ *
233
+ * There were two, and they disagreed. `skillRefusal` named "Reachable skills:
234
+ * beta" from the graph's raw hop set; `postureRefusal`, forty lines below it in
235
+ * the same gate, answered a model that took that offer up with "read_skill here
236
+ * reaches only the open skills: gamma". Same call, same turn, opposite claims —
237
+ * and the second one cost a refusal from the escalation budget to discover.
238
+ * Neither had heard of the role filter, so both could name a skill the caller's
239
+ * policy hides. One composer, handed the FILTERED sets and the posture that
240
+ * will judge the next pick, cannot contradict itself that way.
241
+ *
242
+ * ── THE TENSE DISCIPLINE (the law `selfCallNotice` is written against) ──
243
+ *
244
+ * A tool result is composed on iteration N and re-read by the model on every
245
+ * later call of the turn, including the tool-less wrap-up. So every clause here
246
+ * is a PAST fact about ONE named call — the call the model made `read_skill`
247
+ * on — anchored by the phrase "that call", never by deixis ("this turn", "the
248
+ * call you just made") and never by a forecast ("you can call", "pick one of
249
+ * these"). What the model may do NEXT is owned by the `read_skill` DESCRIPTION,
250
+ * which is recomposed for every single request and may therefore speak in the
251
+ * present. Two owners, one tense each, and they can no longer disagree.
252
+ *
253
+ * ── AND WHY IT NEVER NAMES A HOP THE POSTURE WOULD DECLINE ──────────────
254
+ *
255
+ * Under `'rails'` the model does not route at all; under `'guard'` it routes
256
+ * only from an outstanding menu. Naming hops there is an offer the very next
257
+ * arm of this gate refuses. So those arms name no hop: they say who DID route,
258
+ * and (when there are any) which open skills were admitted anyway — open skills
259
+ * never reach the posture arm, so that clause cannot be contradicted.
260
+ *
261
+ * ── AND WHY AN EMPTY LIST IS NEVER A DENIAL ─────────────────────────────
262
+ *
263
+ * Every set arrives as {@link SpokenIds}, which carries whether the UNFILTERED
264
+ * set held anything. That is the difference between "nothing was reachable" and
265
+ * "nothing reachable may be named", and this composer used to say the first
266
+ * when the second was true — over a graph that was routing the cursor the whole
267
+ * time. Where the filter empties a set, the clause is omitted. A model told the
268
+ * map is a dead end stops asking for the door it may not be shown.
269
+ *
270
+ * Exported so a producer registry can list it beside the other model-facing
271
+ * composers rather than re-deriving what it says.
163
272
  */
164
- function postureRefusal(requestedId, posture, turnRoute, currentSkillId, openIds) {
165
- const openClause = openIds.length > 0
166
- ? ` read_skill here reaches only the open skills: ${openIds.join(', ')}.`
273
+ export function composeReadSkillRefusal(args) {
274
+ const { requestedId, targetClass, cursorId, hops, openIds, isTree, posture, menuOffered, routedDecisively, } = args;
275
+ const head = `read_skill("${requestedId}") was not granted on that call: `;
276
+ // Open skills are the one list every arm may name: they are admitted from
277
+ // every cursor and no posture governs them (the posture arm below is reached
278
+ // only by hops), so naming them cannot be falsified by the next call. There is
279
+ // no negative arm here and there never was — an unnamed open set is simply
280
+ // omitted, which is the shape the two arms below now share.
281
+ const openClause = openIds.named.length > 0
282
+ ? ` Open skills were admitted on that call: ${openIds.named.join(', ')}.`
167
283
  : '';
168
- if (posture === 'rails') {
169
- return (`read_skill("${requestedId}") was declined: this graph runs on rails — turn starts ` +
170
- `resolve by declared rule or scorer and transitions by declared routes; the model ` +
171
- `does not route itself.${openClause} Continue with the skill you are in` +
172
- `${currentSkillId !== undefined ? ` ('${currentSkillId}')` : ''}, or finish.`);
284
+ if (posture !== undefined) {
285
+ if (posture === 'rails') {
286
+ return (`${head}this graph's 'rails' posture reserves routing to the framework — turn ` +
287
+ `starts resolve by declared rule or scorer and transitions by declared routes — ` +
288
+ `so a model pick was not admitted on that call.${openClause}`);
289
+ }
290
+ if (menuOffered !== undefined && menuOffered.named.length > 0) {
291
+ return (`${head}this graph's 'guard' posture admits a routing pick only from the menu the ` +
292
+ `framework offered, and '${requestedId}' was not on it. The menu outstanding when ` +
293
+ `that call was made: ${menuOffered.named.join(', ')}.${openClause}`);
294
+ }
295
+ // A menu WAS outstanding and not one of its ids may be named to this
296
+ // caller. Neither of the other two sentences is available: naming the menu
297
+ // would leak it, and "no menu was outstanding" is false — as is the
298
+ // "declared routes moved the cursor instead" clause that rides with it,
299
+ // which is a second assertion about a turn that did not route that way. So
300
+ // this arm says the one thing that is true of that call and stops.
301
+ if (menuOffered !== undefined && menuOffered.held) {
302
+ return (`${head}this graph's 'guard' posture admits a routing pick only from the menu the ` +
303
+ `framework offered, and '${requestedId}' was not admitted on that call.${openClause}`);
304
+ }
305
+ return (`${head}this graph's 'guard' posture admits a routing pick only while the framework ` +
306
+ `has declared ambiguity, and no menu was outstanding when that call was made` +
307
+ `${routedDecisively === true ? " — the turn's start had already been resolved decisively" : ''}` +
308
+ `. Declared routes moved the cursor instead.${openClause}`);
173
309
  }
174
- // guard — either no menu is outstanding, or the pick was off it.
175
- if (turnRoute?.offered !== undefined && menuOutstanding(turnRoute, currentSkillId)) {
176
- return (`read_skill("${requestedId}") was declined: under this graph's 'guard' posture a ` +
177
- `routing pick must come from the offered menu — ${turnRoute.offered.join(', ')} — or ` +
178
- `stay (answer without calling read_skill).${openClause}`);
310
+ if (isTree === true) {
311
+ return (`${head}this map is a decision tree. A tree routes by predicate on every iteration ` +
312
+ `and keeps no cursor, so there was nothing for that pick to move and ` +
313
+ `'${requestedId}' was not activated by it.${openClause}`);
179
314
  }
180
- const decidedBy = turnRoute?.by === 'intent' || turnRoute?.by === 'entry'
181
- ? `the turn's start was resolved decisively this turn`
182
- : `no routing ambiguity is open this turn`;
183
- return (`read_skill("${requestedId}") was declined: this graph's 'guard' posture admits a ` +
184
- `routing pick only while the framework has declared ambiguity (an offered menu), and ` +
185
- `${decidedBy}; declared routes handle transitions.${openClause} Continue with the ` +
186
- `skill you are in${currentSkillId !== undefined ? ` ('${currentSkillId}')` : ''}, or finish.`);
315
+ // Reachability. `targetClass` is 'unreachable' by the time the gate calls
316
+ // this arm — 'self' is answered by the notice, 'hop' and 'open' are admitted
317
+ // — and it is carried rather than re-derived so the sentence and the verdict
318
+ // read the same classification.
319
+ const from = cursorId !== undefined ? `'${cursorId}'` : "the turn's start";
320
+ // The gate reaches this arm only with `'unreachable'`; the weaker sentence is
321
+ // for a caller that refused an admissible class for a reason of its own, and
322
+ // it is deliberately not an invented explanation of one.
323
+ const reason = targetClass === 'unreachable'
324
+ ? `'${requestedId}' was not reachable from ${from}.`
325
+ : `'${requestedId}' was not admitted from ${from}.`;
326
+ // OMIT, NEVER DENY. Three cases, not two: hops to name, no hops at all, and
327
+ // hops the graph holds that this caller may not be told about. The third used
328
+ // to fall into the second and assert "No skill was reachable from 'alpha'"
329
+ // while the graph routed 'alpha' to a skill the role hides — a denial of what
330
+ // the run holds, and the one shape omission is always safe against.
331
+ const hopClause = hops.named.length > 0
332
+ ? ` Skills reachable from ${from} when that call was made: ${hops.named.join(', ')}.`
333
+ : hops.held
334
+ ? ''
335
+ : ` No skill was reachable from ${from} when that call was made.`;
336
+ return `${head}${reason}${hopClause}${openClause}`;
187
337
  }
188
338
  /**
189
339
  * The args a `pauseHere` / `askHuman` call was running with, read back on the
@@ -775,6 +925,35 @@ export function buildToolCallsHandler(deps) {
775
925
  }
776
926
  const currentSkillId = scope.currentSkillId;
777
927
  const hops = deps.allowedSkillIds(currentSkillId);
928
+ // ── A PROPOSAL TO THE CURSOR'S OWN SKILL IS A STAY (9.86.0) ──────
929
+ // `makeReachableSkills` filters the cursor out of its own successor
930
+ // set — right for a MOVE, and this judge read it as "not reachable"
931
+ // and refused. A tool saying "stay where you are" asks for the state
932
+ // the run is already in: there is no cursor to move, no activation to
933
+ // append, and nothing to refuse. It is accepted as a no-op — no
934
+ // `pendingToolTransition`, no cursor move, and no `[tool effect
935
+ // refused: …]` suffix on a result that proposed nothing wrong.
936
+ //
937
+ // The event carries the existing `'accepted'` outcome plus an
938
+ // ADDITIVE `stay: true`, deliberately not a new enum member: an
939
+ // exhaustive switch over `outcome` in a consumer must keep compiling.
940
+ if (classifySkillTarget({
941
+ ...(currentSkillId !== undefined && { cursor: currentSkillId }),
942
+ target,
943
+ hops,
944
+ }) === 'self') {
945
+ typedEmit(scope, 'agentfootprint.tools.effect', {
946
+ kind: 'propose-transition',
947
+ outcome: 'accepted',
948
+ stay: true,
949
+ toolName: call.toolName,
950
+ toolCallId: call.toolCallId,
951
+ iteration: call.iteration,
952
+ targetSkillId: target,
953
+ reason: effect.reason,
954
+ });
955
+ continue;
956
+ }
778
957
  if (!hops.includes(target)) {
779
958
  refuse('propose-transition', `propose-transition → '${target}' was refused: '${target}' is not reachable from ` +
780
959
  `${currentSkillId !== undefined ? `'${currentSkillId}'` : 'the turn start'} per ` +
@@ -1424,6 +1603,62 @@ export function buildToolCallsHandler(deps) {
1424
1603
  const cached = providerToolCache?.current ?? [];
1425
1604
  return cached.find((t) => t.schema.name === toolName);
1426
1605
  };
1606
+ /**
1607
+ * Every member id of every map the kernel currently holds PARKED (9.86.0
1608
+ * fix pass) — asked of `parkedMemberIds`, the kernel's own owner of the fact.
1609
+ *
1610
+ * ONE reader for TWO gates. The `skill_read` permission gate and the graph's
1611
+ * dispatch gate both have to tell a stay from a re-engagement, and they sit
1612
+ * 480 lines apart; the second computed this and the first did not, which is
1613
+ * exactly how a role-hidden parked member became re-activatable. Answers with
1614
+ * `undefined` when no engagement plan is mounted, which is every agent that
1615
+ * never called `.maps()`.
1616
+ */
1617
+ const parkedNow = (scope) => deps.engagementPlan === undefined
1618
+ ? undefined
1619
+ : parkedMemberIds(deps.engagementPlan, scope.mapEngagement);
1620
+ /**
1621
+ * Every name `lookupTool` would resolve, in resolution order, through the
1622
+ * role filter (9.86.0) — the roster `unknownToolResult` names.
1623
+ *
1624
+ * Derived from the SAME two sources the lookup reads, so a name it reports is
1625
+ * a name that resolved. Then filtered by the SAME fact every other sentence in
1626
+ * this stage filters by: `scope.hiddenSkillIds`, the per-iteration answer to
1627
+ * "which skills may this caller be told about". The first draft applied
1628
+ * neither, and named a hidden skill's tool to a role that may not see the
1629
+ * skill — the leak the `read_skill` refusals had just closed, reappearing one
1630
+ * sentence over because the roster read the dispatch map raw.
1631
+ *
1632
+ * A tool is unnameable only when EVERY skill declaring it is hidden
1633
+ * (`deps.toolDeclaringSkills`, the build-time owner of that fact). A tool two
1634
+ * skills share is still named when either is visible — the same
1635
+ * sole-owner rule the step hold-out uses, for the same reason: a shared name
1636
+ * is somebody's escape hatch. Names nobody declares from a skill — static
1637
+ * `.tool()` registrations, `read_skill`, `skip_step`, provider-delivered
1638
+ * tools — have no owning skill and are never filtered.
1639
+ *
1640
+ * DISPATCH IS UNTOUCHED. `lookupTool` still resolves every name in the map:
1641
+ * a narrowing may take a name out of a sentence, never out of the dispatch
1642
+ * map. This filter governs only what the model is TOLD.
1643
+ */
1644
+ const dispatchRoster = (scope) => {
1645
+ const names = [...registryByName.keys()];
1646
+ const seen = new Set(names);
1647
+ for (const t of externalToolProvider ? providerToolCache?.current ?? [] : []) {
1648
+ if (seen.has(t.schema.name))
1649
+ continue;
1650
+ seen.add(t.schema.name);
1651
+ names.push(t.schema.name);
1652
+ }
1653
+ const hidden = new Set(scope.hiddenSkillIds ?? []);
1654
+ if (hidden.size === 0)
1655
+ return { named: names, held: names.length > 0 };
1656
+ const declaredBy = deps.toolDeclaringSkills;
1657
+ return spoken(names, (name) => {
1658
+ const owners = declaredBy?.get(name);
1659
+ return owners === undefined || owners.some((id) => !hidden.has(id));
1660
+ });
1661
+ };
1427
1662
  /**
1428
1663
  * The after-tool moment: the chain's last word, on a call that RAN.
1429
1664
  *
@@ -1481,7 +1716,7 @@ export function buildToolCallsHandler(deps) {
1481
1716
  // resume can't re-pause (resume returns void), so that is surfaced as an error.
1482
1717
  const resolveCredentialAndExecute = async (scope, tool, toolName, args, toolCallId, iteration, env) => {
1483
1718
  if (!tool)
1484
- return { result: `Unknown tool: ${toolName}`, error: true };
1719
+ return { result: unknownToolResult(toolName, dispatchRoster(scope)), error: true };
1485
1720
  // Declared artifact arguments (9.22.0) — the same resolution the batch
1486
1721
  // loop applies, at this door: a resumed call's refs are judged exactly
1487
1722
  // as an inline call's, BEFORE credentials, and a refusal means the tool
@@ -2114,7 +2349,37 @@ export function buildToolCallsHandler(deps) {
2114
2349
  checkerGoverns(permissionChecker, 'skill_read')) {
2115
2350
  const requestedSkillId = callArgs.id;
2116
2351
  if (typeof requestedSkillId === 'string' && requestedSkillId.length > 0) {
2117
- await askCapability('skill_read', skillTarget(requestedSkillId), `Skill '${requestedSkillId}' is not available in this context.`);
2352
+ // ── A SELF-CALL AT A MOUNTED CURSOR EXERCISES NO CAPABILITY ───
2353
+ // (9.86.0.) A MOUNTED cursor's own skill is already served: its
2354
+ // body is in that call's system prompt and its tools are on that
2355
+ // call's wire. Asking to read it activates nothing, moves nothing,
2356
+ // and reveals nothing the request did not already carry — so there
2357
+ // is no capability here for a policy to grant or deny, and denying
2358
+ // it told the model its current skill was "not available in this
2359
+ // context" while it was standing in it. That is the exact sentence
2360
+ // the self-call arm exists to stop the model reading. The gate's
2361
+ // self-call arm answers instead.
2362
+ //
2363
+ // A PARKED cursor is the one case where the same id is not a
2364
+ // no-op, and the skip is scoped to exclude it (9.86.0 fix pass):
2365
+ // parking suppressed the map's contribution, so the dispatch gate
2366
+ // 480 lines below reads that call as a RE-ENGAGEMENT and serves the
2367
+ // body and tools again on the next pass. That moves something, so
2368
+ // the policy keeps the question. `atMountedCursor` is where that
2369
+ // rule lives; the dispatch gate writes the same rule as two ordered
2370
+ // arms over the same `parkedNow` set. Every OTHER id still goes
2371
+ // through the policy, unchanged — this narrows nothing a role could
2372
+ // see.
2373
+ const stay = atMountedCursor({
2374
+ ...(typeof scope.currentSkillId === 'string' && {
2375
+ cursor: scope.currentSkillId,
2376
+ }),
2377
+ target: requestedSkillId,
2378
+ parked: parkedNow(scope),
2379
+ });
2380
+ if (!stay) {
2381
+ await askCapability('skill_read', skillTarget(requestedSkillId), `Skill '${requestedSkillId}' is not available in this context.`);
2382
+ }
2118
2383
  }
2119
2384
  }
2120
2385
  // ── Check-in gate (evidence-carrying human consent) ──────────────
@@ -2318,7 +2583,7 @@ export function buildToolCallsHandler(deps) {
2318
2583
  if (!credentialBlocked && !wantsBlocked) {
2319
2584
  try {
2320
2585
  if (!tool)
2321
- throw new Error(`Unknown tool: ${tc.name}`);
2586
+ throw new Error(unknownToolResult(tc.name, dispatchRoster(scope)));
2322
2587
  // Set BEFORE the await: a tool that throws has still run, and a
2323
2588
  // tool that does not exist has not. This flag is the entire
2324
2589
  // precondition of the after-tool moment below.
@@ -2490,9 +2755,44 @@ export function buildToolCallsHandler(deps) {
2490
2755
  const reqId = callArgs.id;
2491
2756
  if (typeof reqId === 'string' && reqId.length > 0) {
2492
2757
  const currentSkillId = scope.currentSkillId;
2758
+ // ── ADMISSION reads the graph; every SENTENCE reads the filter ──
2759
+ // Two sets, deliberately (9.86.0). `admissible` is the routing law:
2760
+ // what the graph and the mount actually grant, unfiltered, because a
2761
+ // narrowing may take a schema off the wire but never a name out of
2762
+ // the dispatch map — role visibility governs what the model is TOLD,
2763
+ // not what the gate admits. `hopsNamed` / `openNamed` are what any
2764
+ // sentence, and the `skill.rejected` payload, may NAME: the same
2765
+ // hidden set the description filtered itself with, resolved once by
2766
+ // the tools slot and carried here on scope. Without it the refusals
2767
+ // read the raw sets and could name a skill this role may never see —
2768
+ // the leak the description closed, one stage downstream. (A hidden
2769
+ // skill cannot reach this gate anyway: the `skill_read` permission
2770
+ // gate above denies it first, on the same checker. The filter is
2771
+ // what keeps that true by construction rather than by coincidence.)
2772
+ const hiddenIds = new Set(scope.hiddenSkillIds ?? []);
2773
+ const mayName = (id) => !hiddenIds.has(id);
2493
2774
  const hops = deps.allowedSkillIds(currentSkillId);
2494
- skillHop = hops.includes(reqId);
2495
- const allowed = dedupeIds([...hops, ...(deps.openSkillIds ?? [])]);
2775
+ const openAll = deps.openSkillIds ?? [];
2776
+ // `spoken` keeps BOTH halves — what may be named, and whether the
2777
+ // graph held anything before the filter ran. A composer handed only
2778
+ // the filtered array cannot tell "nothing was reachable" from
2779
+ // "nothing reachable may be named", and it used to assert the first.
2780
+ const hopsSpoken = spoken(hops, mayName);
2781
+ const openSpoken = spoken(openAll, mayName);
2782
+ const hopsNamed = hopsSpoken.named;
2783
+ const openNamed = openSpoken.named;
2784
+ // The ONE owner of "is this target the cursor?" — the same function
2785
+ // the description, the tool-effects judge and the permission gate
2786
+ // switch on, so a stay means the same thing in all four.
2787
+ const targetClass = classifySkillTarget({
2788
+ ...(currentSkillId !== undefined && { cursor: currentSkillId }),
2789
+ target: reqId,
2790
+ hops,
2791
+ open: openAll,
2792
+ });
2793
+ skillHop = targetClass === 'hop';
2794
+ const admissible = dedupeIds([...hops, ...openAll]);
2795
+ const allowed = dedupeIds([...hopsNamed, ...openNamed]);
2496
2796
  // ── The RE-ENGAGEMENT arm (9.59.0) — a third admission class ──
2497
2797
  // A pick must be routed by INTENT. The reachable set deliberately
2498
2798
  // excludes the node the cursor already occupies (`makeReachableSkills`
@@ -2510,15 +2810,13 @@ export function buildToolCallsHandler(deps) {
2510
2810
  // false, `pendingSkillPick` stays unwritten, and the pick lands on
2511
2811
  // `acceptedSkillPicks`, which the kernel's renewal feed reads as
2512
2812
  // explicit evidence and re-engages on the very next pass.
2513
- const parked = deps.engagementPlan === undefined
2514
- ? undefined
2515
- : parkedMemberIds(deps.engagementPlan, scope.mapEngagement);
2813
+ const parked = parkedNow(scope);
2516
2814
  const reengaging = parked?.has(reqId) === true;
2517
2815
  if (reengaging) {
2518
2816
  // Admitted. Nothing to refuse and no posture to apply: this is
2519
2817
  // not a hop, and a posture governs routing, not engagement.
2520
2818
  }
2521
- else if (currentSkillId !== undefined && reqId === currentSkillId) {
2819
+ else if (targetClass === 'self') {
2522
2820
  // ── The SELF-CALL arm (9.84.0) — BEFORE reachability ─────────
2523
2821
  // The cursor is in neither half of `allowed`, by construction:
2524
2822
  // `makeReachableSkills` filters it out of its own successor set
@@ -2593,9 +2891,16 @@ export function buildToolCallsHandler(deps) {
2593
2891
  });
2594
2892
  noteSkillRefusal(scope, iteration);
2595
2893
  }
2596
- else if (!allowed.includes(reqId)) {
2894
+ else if (!admissible.includes(reqId)) {
2597
2895
  skillRejected = true;
2598
- result = skillRefusal(reqId, allowed, deps.skillGraphIsTree === true);
2896
+ result = composeReadSkillRefusal({
2897
+ requestedId: reqId,
2898
+ targetClass,
2899
+ ...(currentSkillId !== undefined && { cursorId: currentSkillId }),
2900
+ hops: hopsSpoken,
2901
+ openIds: openSpoken,
2902
+ ...(deps.skillGraphIsTree === true && { isTree: true }),
2903
+ });
2599
2904
  typedEmit(scope, 'agentfootprint.skill.rejected', {
2600
2905
  requestedId: reqId,
2601
2906
  ...(currentSkillId !== undefined && { currentSkillId }),
@@ -2617,7 +2922,30 @@ export function buildToolCallsHandler(deps) {
2617
2922
  if (refusedByPosture) {
2618
2923
  skillRejected = true;
2619
2924
  skillHop = false; // a refused pick must not move the cursor below
2620
- result = postureRefusal(reqId, deps.skillStrictness, turnRoute, currentSkillId, deps.openSkillIds ?? []);
2925
+ // The posture arm names NO hop — under 'rails' the model does
2926
+ // not route, and under 'guard' it routes only from a menu — so
2927
+ // the composer is handed the menu when there IS one and an
2928
+ // empty hop list either way. Open skills are still named:
2929
+ // they never reach this arm, so nothing here can decline them.
2930
+ const menuNamed = turnRoute?.offered !== undefined && menuOutstanding(turnRoute, currentSkillId)
2931
+ ? spoken(turnRoute.offered, mayName)
2932
+ : undefined;
2933
+ result = composeReadSkillRefusal({
2934
+ requestedId: reqId,
2935
+ targetClass,
2936
+ ...(currentSkillId !== undefined && { cursorId: currentSkillId }),
2937
+ // No hop is named under a posture, and the graph's hop set
2938
+ // is not this arm's subject — `held: false` is the honest
2939
+ // shape, not a claim that nothing was reachable (this arm
2940
+ // never composes the reachability clause at all).
2941
+ hops: { named: [], held: false },
2942
+ openIds: openSpoken,
2943
+ posture: deps.skillStrictness,
2944
+ ...(menuNamed !== undefined && { menuOffered: menuNamed }),
2945
+ ...((turnRoute?.by === 'intent' || turnRoute?.by === 'entry') && {
2946
+ routedDecisively: true,
2947
+ }),
2948
+ });
2621
2949
  typedEmit(scope, 'agentfootprint.skill.rejected', {
2622
2950
  requestedId: reqId,
2623
2951
  ...(currentSkillId !== undefined && { currentSkillId }),