@lushly-dev/afd-server 2.4.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (279) hide show
  1. package/README.md +239 -56
  2. package/dist/admission.d.ts +137 -0
  3. package/dist/admission.d.ts.map +1 -0
  4. package/dist/admission.js +144 -0
  5. package/dist/admission.js.map +1 -0
  6. package/dist/app-call-registry.d.ts +31 -0
  7. package/dist/app-call-registry.d.ts.map +1 -0
  8. package/dist/app-call-registry.js +64 -0
  9. package/dist/app-call-registry.js.map +1 -0
  10. package/dist/approval-admission.d.ts +139 -0
  11. package/dist/approval-admission.d.ts.map +1 -0
  12. package/dist/approval-admission.js +252 -0
  13. package/dist/approval-admission.js.map +1 -0
  14. package/dist/approval-crypto.d.ts +37 -17
  15. package/dist/approval-crypto.d.ts.map +1 -1
  16. package/dist/approval-crypto.js +84 -75
  17. package/dist/approval-crypto.js.map +1 -1
  18. package/dist/approval-process-state.d.ts +21 -0
  19. package/dist/approval-process-state.d.ts.map +1 -0
  20. package/dist/approval-process-state.js +29 -0
  21. package/dist/approval-process-state.js.map +1 -0
  22. package/dist/approval-relay.d.ts +192 -9
  23. package/dist/approval-relay.d.ts.map +1 -1
  24. package/dist/approval-relay.js +45 -9
  25. package/dist/approval-relay.js.map +1 -1
  26. package/dist/approval-up-front.d.ts +40 -0
  27. package/dist/approval-up-front.d.ts.map +1 -0
  28. package/dist/approval-up-front.js +409 -0
  29. package/dist/approval-up-front.js.map +1 -0
  30. package/dist/approval.d.ts +65 -12
  31. package/dist/approval.d.ts.map +1 -1
  32. package/dist/approval.js +311 -47
  33. package/dist/approval.js.map +1 -1
  34. package/dist/approver.d.ts +84 -0
  35. package/dist/approver.d.ts.map +1 -0
  36. package/dist/approver.js +107 -0
  37. package/dist/approver.js.map +1 -0
  38. package/dist/auth-middleware-check.d.ts +23 -0
  39. package/dist/auth-middleware-check.d.ts.map +1 -0
  40. package/dist/auth-middleware-check.js +48 -0
  41. package/dist/auth-middleware-check.js.map +1 -0
  42. package/dist/bootstrap/afd-context.d.ts.map +1 -1
  43. package/dist/bootstrap/afd-context.js +27 -3
  44. package/dist/bootstrap/afd-context.js.map +1 -1
  45. package/dist/bootstrap/afd-docs.d.ts.map +1 -1
  46. package/dist/bootstrap/afd-docs.js +4 -0
  47. package/dist/bootstrap/afd-docs.js.map +1 -1
  48. package/dist/bootstrap/afd-help.d.ts +4 -1
  49. package/dist/bootstrap/afd-help.d.ts.map +1 -1
  50. package/dist/bootstrap/afd-help.js +19 -4
  51. package/dist/bootstrap/afd-help.js.map +1 -1
  52. package/dist/bootstrap/described-command.d.ts +3 -1
  53. package/dist/bootstrap/described-command.d.ts.map +1 -1
  54. package/dist/bootstrap/described-command.js.map +1 -1
  55. package/dist/command-allow.d.ts +4 -4
  56. package/dist/command-allow.d.ts.map +1 -1
  57. package/dist/command-allow.js +10 -15
  58. package/dist/command-allow.js.map +1 -1
  59. package/dist/command-routing.d.ts +56 -8
  60. package/dist/command-routing.d.ts.map +1 -1
  61. package/dist/command-routing.js +82 -16
  62. package/dist/command-routing.js.map +1 -1
  63. package/dist/command-timeout.d.ts +17 -0
  64. package/dist/command-timeout.d.ts.map +1 -0
  65. package/dist/command-timeout.js +99 -0
  66. package/dist/command-timeout.js.map +1 -0
  67. package/dist/confirmation-gate.d.ts +7 -7
  68. package/dist/confirmation-gate.d.ts.map +1 -1
  69. package/dist/confirmation-gate.js +26 -12
  70. package/dist/confirmation-gate.js.map +1 -1
  71. package/dist/confirmations.d.ts +28 -3
  72. package/dist/confirmations.d.ts.map +1 -1
  73. package/dist/confirmations.js +6 -7
  74. package/dist/confirmations.js.map +1 -1
  75. package/dist/context-fields.d.ts +16 -1
  76. package/dist/context-fields.d.ts.map +1 -1
  77. package/dist/context-fields.js +30 -13
  78. package/dist/context-fields.js.map +1 -1
  79. package/dist/context-scope.d.ts +3 -3
  80. package/dist/context-scope.d.ts.map +1 -1
  81. package/dist/context-scope.js +7 -8
  82. package/dist/context-scope.js.map +1 -1
  83. package/dist/define-core.d.ts +63 -1
  84. package/dist/define-core.d.ts.map +1 -1
  85. package/dist/define-core.js +27 -4
  86. package/dist/define-core.js.map +1 -1
  87. package/dist/define.d.ts +4 -3
  88. package/dist/define.d.ts.map +1 -1
  89. package/dist/define.js +1 -1
  90. package/dist/define.js.map +1 -1
  91. package/dist/direct-registry.d.ts +54 -8
  92. package/dist/direct-registry.d.ts.map +1 -1
  93. package/dist/direct-registry.js +64 -8
  94. package/dist/direct-registry.js.map +1 -1
  95. package/dist/direct-tool-surface.d.ts +1 -1
  96. package/dist/direct-tool-surface.d.ts.map +1 -1
  97. package/dist/direct-tool-surface.js +28 -6
  98. package/dist/direct-tool-surface.js.map +1 -1
  99. package/dist/direct.d.ts +6 -2
  100. package/dist/direct.d.ts.map +1 -1
  101. package/dist/direct.js +4 -1
  102. package/dist/direct.js.map +1 -1
  103. package/dist/elicitation-state.d.ts +5 -1
  104. package/dist/elicitation-state.d.ts.map +1 -1
  105. package/dist/elicitation-state.js +4 -1
  106. package/dist/elicitation-state.js.map +1 -1
  107. package/dist/execution.d.ts +52 -6
  108. package/dist/execution.d.ts.map +1 -1
  109. package/dist/execution.js +183 -19
  110. package/dist/execution.js.map +1 -1
  111. package/dist/host-state.d.ts +81 -0
  112. package/dist/host-state.d.ts.map +1 -0
  113. package/dist/host-state.js +62 -0
  114. package/dist/host-state.js.map +1 -0
  115. package/dist/http-handler.d.ts +48 -11
  116. package/dist/http-handler.d.ts.map +1 -1
  117. package/dist/http-handler.js +207 -58
  118. package/dist/http-handler.js.map +1 -1
  119. package/dist/http-security.d.ts +14 -1
  120. package/dist/http-security.d.ts.map +1 -1
  121. package/dist/http-security.js +79 -17
  122. package/dist/http-security.js.map +1 -1
  123. package/dist/http-sessions.d.ts +45 -5
  124. package/dist/http-sessions.d.ts.map +1 -1
  125. package/dist/http-sessions.js +52 -10
  126. package/dist/http-sessions.js.map +1 -1
  127. package/dist/http-sse.d.ts +9 -0
  128. package/dist/http-sse.d.ts.map +1 -1
  129. package/dist/http-sse.js +12 -3
  130. package/dist/http-sse.js.map +1 -1
  131. package/dist/human-relay.d.ts +195 -0
  132. package/dist/human-relay.d.ts.map +1 -0
  133. package/dist/human-relay.js +670 -0
  134. package/dist/human-relay.js.map +1 -0
  135. package/dist/idempotency-step.d.ts +231 -0
  136. package/dist/idempotency-step.d.ts.map +1 -0
  137. package/dist/idempotency-step.js +389 -0
  138. package/dist/idempotency-step.js.map +1 -0
  139. package/dist/idempotency-store.d.ts +107 -0
  140. package/dist/idempotency-store.d.ts.map +1 -0
  141. package/dist/idempotency-store.js +100 -0
  142. package/dist/idempotency-store.js.map +1 -0
  143. package/dist/index.d.ts +18 -8
  144. package/dist/index.d.ts.map +1 -1
  145. package/dist/index.js +15 -4
  146. package/dist/index.js.map +1 -1
  147. package/dist/instance-state.d.ts +53 -0
  148. package/dist/instance-state.d.ts.map +1 -0
  149. package/dist/instance-state.js +94 -0
  150. package/dist/instance-state.js.map +1 -0
  151. package/dist/journal-off-tape.d.ts +52 -0
  152. package/dist/journal-off-tape.d.ts.map +1 -0
  153. package/dist/journal-off-tape.js +150 -0
  154. package/dist/journal-off-tape.js.map +1 -0
  155. package/dist/journal-replay.d.ts.map +1 -1
  156. package/dist/journal-replay.js +48 -3
  157. package/dist/journal-replay.js.map +1 -1
  158. package/dist/journal-view.d.ts +50 -0
  159. package/dist/journal-view.d.ts.map +1 -0
  160. package/dist/journal-view.js +214 -0
  161. package/dist/journal-view.js.map +1 -0
  162. package/dist/journal.d.ts +34 -6
  163. package/dist/journal.d.ts.map +1 -1
  164. package/dist/journal.js +183 -47
  165. package/dist/journal.js.map +1 -1
  166. package/dist/json-rpc.d.ts +3 -2
  167. package/dist/json-rpc.d.ts.map +1 -1
  168. package/dist/json-rpc.js +5 -3
  169. package/dist/json-rpc.js.map +1 -1
  170. package/dist/lazy-tools.d.ts +27 -2
  171. package/dist/lazy-tools.d.ts.map +1 -1
  172. package/dist/lazy-tools.js +22 -4
  173. package/dist/lazy-tools.js.map +1 -1
  174. package/dist/mcp-auth-bearer.d.ts +2 -0
  175. package/dist/mcp-auth-bearer.d.ts.map +1 -1
  176. package/dist/mcp-auth-bearer.js +1 -1
  177. package/dist/mcp-auth-bearer.js.map +1 -1
  178. package/dist/mcp-auth-dispatch.d.ts +38 -0
  179. package/dist/mcp-auth-dispatch.d.ts.map +1 -0
  180. package/dist/mcp-auth-dispatch.js +113 -0
  181. package/dist/mcp-auth-dispatch.js.map +1 -0
  182. package/dist/mcp-auth-jwt.d.ts +3 -2
  183. package/dist/mcp-auth-jwt.d.ts.map +1 -1
  184. package/dist/mcp-auth-jwt.js.map +1 -1
  185. package/dist/mcp-auth-resource.d.ts +6 -2
  186. package/dist/mcp-auth-resource.d.ts.map +1 -1
  187. package/dist/mcp-auth-resource.js +6 -5
  188. package/dist/mcp-auth-resource.js.map +1 -1
  189. package/dist/mcp-auth-scopes.d.ts +84 -0
  190. package/dist/mcp-auth-scopes.d.ts.map +1 -0
  191. package/dist/mcp-auth-scopes.js +125 -0
  192. package/dist/mcp-auth-scopes.js.map +1 -0
  193. package/dist/mcp-auth-view.d.ts +50 -0
  194. package/dist/mcp-auth-view.d.ts.map +1 -0
  195. package/dist/mcp-auth-view.js +179 -0
  196. package/dist/mcp-auth-view.js.map +1 -0
  197. package/dist/mcp-auth.d.ts +94 -3
  198. package/dist/mcp-auth.d.ts.map +1 -1
  199. package/dist/mcp-auth.js +241 -23
  200. package/dist/mcp-auth.js.map +1 -1
  201. package/dist/mcp-modern.d.ts +80 -6
  202. package/dist/mcp-modern.d.ts.map +1 -1
  203. package/dist/mcp-modern.js +378 -91
  204. package/dist/mcp-modern.js.map +1 -1
  205. package/dist/meta-argument.d.ts +9 -8
  206. package/dist/meta-argument.d.ts.map +1 -1
  207. package/dist/meta-argument.js +28 -10
  208. package/dist/meta-argument.js.map +1 -1
  209. package/dist/meta-tools.js +2 -2
  210. package/dist/meta-tools.js.map +1 -1
  211. package/dist/middleware.d.ts +16 -1
  212. package/dist/middleware.d.ts.map +1 -1
  213. package/dist/middleware.js +57 -10
  214. package/dist/middleware.js.map +1 -1
  215. package/dist/output-budget.d.ts +77 -0
  216. package/dist/output-budget.d.ts.map +1 -0
  217. package/dist/output-budget.js +202 -0
  218. package/dist/output-budget.js.map +1 -0
  219. package/dist/principal-binding.js +1 -1
  220. package/dist/principal-binding.js.map +1 -1
  221. package/dist/relay-evidence.d.ts +74 -0
  222. package/dist/relay-evidence.d.ts.map +1 -0
  223. package/dist/relay-evidence.js +143 -0
  224. package/dist/relay-evidence.js.map +1 -0
  225. package/dist/resources.d.ts +35 -10
  226. package/dist/resources.d.ts.map +1 -1
  227. package/dist/resources.js +59 -18
  228. package/dist/resources.js.map +1 -1
  229. package/dist/schema.d.ts +4 -3
  230. package/dist/schema.d.ts.map +1 -1
  231. package/dist/schema.js +3 -3
  232. package/dist/schema.js.map +1 -1
  233. package/dist/scope-view.d.ts +65 -0
  234. package/dist/scope-view.d.ts.map +1 -0
  235. package/dist/scope-view.js +45 -0
  236. package/dist/scope-view.js.map +1 -0
  237. package/dist/server-types.d.ts +182 -27
  238. package/dist/server-types.d.ts.map +1 -1
  239. package/dist/server-types.js.map +1 -1
  240. package/dist/server.d.ts +26 -0
  241. package/dist/server.d.ts.map +1 -1
  242. package/dist/server.js +403 -61
  243. package/dist/server.js.map +1 -1
  244. package/dist/skills.d.ts.map +1 -1
  245. package/dist/skills.js +99 -3
  246. package/dist/skills.js.map +1 -1
  247. package/dist/task-dispatch.d.ts +35 -0
  248. package/dist/task-dispatch.d.ts.map +1 -0
  249. package/dist/task-dispatch.js +25 -0
  250. package/dist/task-dispatch.js.map +1 -0
  251. package/dist/tasks-runtime.d.ts +115 -0
  252. package/dist/tasks-runtime.d.ts.map +1 -0
  253. package/dist/tasks-runtime.js +760 -0
  254. package/dist/tasks-runtime.js.map +1 -0
  255. package/dist/tasks.d.ts +237 -0
  256. package/dist/tasks.d.ts.map +1 -0
  257. package/dist/tasks.js +321 -0
  258. package/dist/tasks.js.map +1 -0
  259. package/dist/tool-router.d.ts +68 -3
  260. package/dist/tool-router.d.ts.map +1 -1
  261. package/dist/tool-router.js +293 -70
  262. package/dist/tool-router.js.map +1 -1
  263. package/dist/tools.d.ts +32 -0
  264. package/dist/tools.d.ts.map +1 -1
  265. package/dist/tools.js +162 -55
  266. package/dist/tools.js.map +1 -1
  267. package/dist/up-front-steps.d.ts +35 -0
  268. package/dist/up-front-steps.d.ts.map +1 -0
  269. package/dist/up-front-steps.js +159 -0
  270. package/dist/up-front-steps.js.map +1 -0
  271. package/dist/validation.d.ts +38 -3
  272. package/dist/validation.d.ts.map +1 -1
  273. package/dist/validation.js +118 -23
  274. package/dist/validation.js.map +1 -1
  275. package/dist/verified-credentials.d.ts +13 -5
  276. package/dist/verified-credentials.d.ts.map +1 -1
  277. package/dist/verified-credentials.js +43 -10
  278. package/dist/verified-credentials.js.map +1 -1
  279. package/package.json +15 -11
@@ -3,28 +3,26 @@
3
3
  * one call.
4
4
  *
5
5
  * `DirectClient` passes its `allow` predicate to the registry as a call option, beside
6
- * `activeContext`. The registry binds it to the call's context under a private symbol, as it binds
6
+ * `activeContext`. The registry binds it to the call's host state (`host-state.ts`), as it binds
7
7
  * the context state (`context-scope.ts`), so the copies made for `afd-call`, batch items, pipeline
8
8
  * steps and grouped tools all carry it, and the engine and the tool router check every command the
9
9
  * call runs.
10
10
  *
11
- * The context holds an opaque frozen token, never the predicate: the predicate sits in a
12
- * module-private `WeakMap`, so a handler that lists its context's symbols finds an empty object it
13
- * cannot call, read or swap for another predicate (an unknown token denies everything). Tool
11
+ * The context holds the host state's opaque frozen token, never the predicate: a handler that lists
12
+ * its context's symbols finds an empty object it cannot call, read or swap for another predicate
13
+ * (a forged token denies everything). Tool
14
14
  * arguments and `createContext` values are plain JSON and string keys, so they cannot carry one. A
15
15
  * token handed back to `execute` (a handler passing its own context on) only narrows the next
16
16
  * call, never widens it. Nothing binds a token on the MCP lanes, so they are unchanged.
17
17
  */
18
18
  import { directAllows } from '@lushly-dev/afd-core/internal/direct-allow';
19
- const ALLOW = Symbol('afd.commandAllow');
20
- /** Tokens the registry minted, and the predicate each stands for. */
21
- const predicates = new WeakMap();
19
+ import { hostState, withHostState } from './host-state.js';
22
20
  /** The predicate bound to `context`: none when nothing is bound, deny-all for a forged token. */
23
21
  function boundAllow(context) {
24
- if (!context || !(ALLOW in context))
25
- return undefined;
26
- const token = context[ALLOW];
27
- return (token !== null && typeof token === 'object' && predicates.get(token)) || (() => false);
22
+ const state = hostState(context);
23
+ if (state.forged)
24
+ return () => false;
25
+ return state.commandAllow;
28
26
  }
29
27
  /**
30
28
  * Return `context` bound to `allow`, combined with any predicate it already carries: both must
@@ -37,10 +35,7 @@ export function bindCommandAllow(context, allow) {
37
35
  const combined = allow && carried
38
36
  ? (name) => directAllows(carried, name) && directAllows(allow, name)
39
37
  : (allow ?? carried);
40
- const token = Object.freeze({});
41
- predicates.set(token, combined);
42
- const bound = { ...context, [ALLOW]: token };
43
- return bound;
38
+ return withHostState(context, { commandAllow: combined });
44
39
  }
45
40
  /** Whether the predicate bound to `context`, if any, permits `name`. */
46
41
  export function isCommandAllowed(context, name) {
@@ -1 +1 @@
1
- {"version":3,"file":"command-allow.js","sourceRoot":"","sources":["../src/command-allow.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAAoB,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAE5F,MAAM,KAAK,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAEzC,qEAAqE;AACrE,MAAM,UAAU,GAAG,IAAI,OAAO,EAAuB,CAAC;AAItD,iGAAiG;AACjG,SAAS,UAAU,CAAC,OAAmC;IACtD,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC,KAAK,IAAI,OAAO,CAAC;QAAE,OAAO,SAAS,CAAC;IACtD,MAAM,KAAK,GAAI,OAAwB,CAAC,KAAK,CAAC,CAAC;IAC/C,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AI,CAAC,CAAC;AAC5C,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,aAAa,CAC5B,KAAU,EACV,OAAmC;IAEnC,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAClC,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAC/E,CAAC"}
@@ -2,7 +2,7 @@
2
2
  * @fileoverview Shared helpers for tool listing, tool routing, discovery and
3
3
  * execution: group/action derivation for the grouped strategy and context scoping.
4
4
  */
5
- import type { CommandError } from '@lushly-dev/afd-core';
5
+ import type { CommandContext, CommandError } from '@lushly-dev/afd-core';
6
6
  import type { ZodCommandDefinition } from './schema.js';
7
7
  /** Derives a grouped-strategy tool name from a command (`McpServerOptions.groupByFn`). */
8
8
  export type GroupByFn = (command: ZodCommandDefinition) => string | undefined;
@@ -30,25 +30,73 @@ export declare function commandAction(command: Pick<ZodCommandDefinition, 'name'
30
30
  export declare function isAccessibleInContext(command: Contextual, activeContext: string | null | undefined): boolean;
31
31
  /** Commands accessible in the active context (all of them when none is active). */
32
32
  export declare function filterByContext<T extends Contextual>(commands: T[], activeContext: string | null | undefined): T[];
33
+ /**
34
+ * The meta-tools the tool router serves, as core's `AFD_META_TOOL_NAMES` lists them (a test keeps
35
+ * the two equal). Written out here because the engine, which `/direct` and Loam's first paint
36
+ * bundle, reads them, and importing core's `builtin-tools` would split it into a chunk of its own.
37
+ */
38
+ export declare const ROUTED_META_TOOL_NAMES: readonly string[];
39
+ /**
40
+ * What a surface serves, for {@link canCall}: whether it routes the meta-tools, and the command
41
+ * it registers and exposes to the caller's interface under a name.
42
+ */
43
+ export interface CallableSurface {
44
+ /** Whether the surface serves the meta-tools (`afd-discover`, `afd-call` and the rest). */
45
+ metaTools: boolean;
46
+ /** The command registered and exposed under `name` on this surface, if any. */
47
+ command(name: string): Contextual | undefined;
48
+ /**
49
+ * Whether the caller of `context` is shown `name` under MCP authorization (M6). Absent, every
50
+ * command is shown. The callers that hold the request's scope view pass it in, so this module,
51
+ * which `/direct` and the engine bundle, never loads `scope-view`.
52
+ */
53
+ shown?(name: string, context: CommandContext | undefined): boolean;
54
+ }
55
+ /**
56
+ * Whether the caller of `context` can call `name` on `surface` (`spec/recovery.md`, rule 2 and
57
+ * "Engine errors"): served (a meta-tool on a surface that routes them) or registered and exposed,
58
+ * admitted by the call's `allow` list, shown to the caller under MCP authorization, and allowed in
59
+ * the active context. A refusal names a command, in its suggestion and in a `call` recovery,
60
+ * only when this holds, so the two never disagree. A meta-tool is called as its own tool, and
61
+ * the context and authorization checks do not apply to it.
62
+ */
63
+ export declare function canCall(surface: CallableSurface, name: string, context: CommandContext | undefined, activeContext: string | null | undefined): boolean;
64
+ /** The commands a `COMMAND_NOT_FOUND` suggestion and recovery may point to, in order. */
65
+ declare const NOT_FOUND_NEXT: readonly ['afd-discover', 'afd-help'];
66
+ /** The command a `COMMAND_NOT_FOUND` names next: the first of {@link NOT_FOUND_NEXT} `can` admits. */
67
+ export type NotFoundNext = (typeof NOT_FOUND_NEXT)[number];
68
+ /** The first command a not-found answer may point to, of those `can` admits; `null` for none. */
69
+ export declare function notFoundNext(can: (name: string) => boolean): NotFoundNext | null;
33
70
  /**
34
71
  * Recovery guidance for an unknown command name: at most
35
72
  * {@link MAX_NOT_FOUND_MATCHES} close matches (bounded fuzzy matching; none for
36
- * very long names) and a pointer to `afd-discover`. It never lists every
73
+ * very long names) and a pointer to `afd-discover` or `afd-help`. It never lists every
37
74
  * command, which in lazy mode would load the whole surface into the agent's
38
75
  * context on a single typo.
39
76
  *
40
77
  * @param commandName - The unknown name (untrusted; never echoed)
41
78
  * @param commandNames - Names the caller may call
42
- * @param discover - Whether the caller can call `afd-discover`. Without it the suggestion ends
43
- * as Rust's and C++'s do (`spec/error-codes.md`, "Suggestions name only tools the host provides")
79
+ * @param next - The command the caller can call to list the others ({@link notFoundNext}). With
80
+ * `null` the suggestion ends as Rust's and C++'s do (`spec/error-codes.md`, "Suggestions name
81
+ * only tools the host provides")
82
+ */
83
+ export declare function notFoundSuggestion(commandName: string, commandNames: string[], next?: NotFoundNext | null): string;
84
+ /**
85
+ * The `COMMAND_NOT_FOUND` error for an unknown name at lookup (a call, `afd-call`, a batch item or
86
+ * a pipeline step). Its suggestion and its recovery name the same command, `next`, or none
87
+ * (`spec/recovery.md`, "Engine errors").
44
88
  */
45
- export declare function notFoundSuggestion(commandName: string, commandNames: string[], discover?: boolean): string;
89
+ export declare function notFoundError(commandName: string, commandNames: string[], next: NotFoundNext | null): CommandError;
46
90
  /**
47
91
  * The `COMMAND_NOT_IN_CONTEXT` error for a command outside the active context.
48
92
  *
49
- * @param belongsTo - The command's contexts, when the caller cannot call the `afd-context-*`
50
- * tools: the suggestion then names them, as Rust's and C++'s do
93
+ * @param belongsTo - The command's contexts
94
+ * @param can - Whether the caller can call a command ({@link canCall}). When it can call
95
+ * `afd-context-list`, the suggestion and the recovery name it (and the suggestion names
96
+ * `afd-context-enter` too, when the caller can call that); otherwise the suggestion names the
97
+ * command's contexts, as Rust's and C++'s do, and the error carries no recovery. Default: every
98
+ * command can be called
51
99
  */
52
- export declare function notInContextError(commandName: string, activeContext: string, belongsTo?: readonly string[]): CommandError;
100
+ export declare function notInContextError(commandName: string, activeContext: string, belongsTo?: readonly string[], can?: (name: string) => boolean): CommandError;
53
101
  export {};
54
102
  //# sourceMappingURL=command-routing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"command-routing.d.ts","sourceRoot":"","sources":["../src/command-routing.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAExD,0FAA0F;AAC1F,MAAM,MAAM,SAAS,GA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OAAO,CACtB,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,cAAc,GAAG,SAAS,EACnC,aAAa,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GACtC,OAAO,CAOT;AAKD,yFAAyF;AACzF,QAAA,MAAM,cAAc,YAAI,cAAc,EAAE,UAAU,CAAU,CAAC;AAE7D,sGAAsG;AACtG,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAE3D,iGAAiG;AACjG,wBAAgB,YAAY,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAAG,YAAY,GAAG,IAAI,CAEhF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CACjC,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EAAE,EACtB,IAAI,GAAE,YAAY,GAAG,IAAqB,GACxC,MAAM,CAUR;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC5B,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EAAE,EACtB,IAAI,EAAE,YAAY,GAAG,IAAI,GACvB,YAAY,CAOd;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAChC,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,EACrB,SAAS,GAAE,SAAS,MAAM,EAAO,EACjC,GAAG,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAoB,GACzC,YAAY,CAiBd"}
@@ -2,7 +2,8 @@
2
2
  * @fileoverview Shared helpers for tool listing, tool routing, discovery and
3
3
  * execution: group/action derivation for the grouped strategy and context scoping.
4
4
  */
5
- import { findSimilarTools } from '@lushly-dev/afd-core';
5
+ import { findSimilarTools, truncateName } from '@lushly-dev/afd-core';
6
+ import { isCommandAllowed } from './command-allow.js';
6
7
  /**
7
8
  * Default group (and discovery category) of a command: its `category`, else the
8
9
  * first kebab-case segment of its name, else `'general'`.
@@ -42,45 +43,110 @@ export function filterByContext(commands, activeContext) {
42
43
  return commands;
43
44
  return commands.filter((command) => isAccessibleInContext(command, activeContext));
44
45
  }
46
+ /**
47
+ * The meta-tools the tool router serves, as core's `AFD_META_TOOL_NAMES` lists them (a test keeps
48
+ * the two equal). Written out here because the engine, which `/direct` and Loam's first paint
49
+ * bundle, reads them, and importing core's `builtin-tools` would split it into a chunk of its own.
50
+ */
51
+ export const ROUTED_META_TOOL_NAMES = [
52
+ 'afd-call',
53
+ 'afd-batch',
54
+ 'afd-pipe',
55
+ 'afd-discover',
56
+ 'afd-detail',
57
+ ];
58
+ /**
59
+ * Whether the caller of `context` can call `name` on `surface` (`spec/recovery.md`, rule 2 and
60
+ * "Engine errors"): served (a meta-tool on a surface that routes them) or registered and exposed,
61
+ * admitted by the call's `allow` list, shown to the caller under MCP authorization, and allowed in
62
+ * the active context. A refusal names a command, in its suggestion and in a `call` recovery,
63
+ * only when this holds, so the two never disagree. A meta-tool is called as its own tool, and
64
+ * the context and authorization checks do not apply to it.
65
+ */
66
+ export function canCall(surface, name, context, activeContext) {
67
+ if (!isCommandAllowed(context, name))
68
+ return false;
69
+ if (ROUTED_META_TOOL_NAMES.includes(name))
70
+ return surface.metaTools;
71
+ const command = surface.command(name);
72
+ if (!command)
73
+ return false;
74
+ if (surface.shown && !surface.shown(name, context))
75
+ return false;
76
+ return isAccessibleInContext(command, activeContext);
77
+ }
45
78
  /** How many close matches a `COMMAND_NOT_FOUND` suggestion names at most. */
46
79
  const MAX_NOT_FOUND_MATCHES = 3;
80
+ /** The commands a `COMMAND_NOT_FOUND` suggestion and recovery may point to, in order. */
81
+ const NOT_FOUND_NEXT = ['afd-discover', 'afd-help'];
82
+ /** The first command a not-found answer may point to, of those `can` admits; `null` for none. */
83
+ export function notFoundNext(can) {
84
+ return NOT_FOUND_NEXT.find((name) => can(name)) ?? null;
85
+ }
47
86
  /**
48
87
  * Recovery guidance for an unknown command name: at most
49
88
  * {@link MAX_NOT_FOUND_MATCHES} close matches (bounded fuzzy matching; none for
50
- * very long names) and a pointer to `afd-discover`. It never lists every
89
+ * very long names) and a pointer to `afd-discover` or `afd-help`. It never lists every
51
90
  * command, which in lazy mode would load the whole surface into the agent's
52
91
  * context on a single typo.
53
92
  *
54
93
  * @param commandName - The unknown name (untrusted; never echoed)
55
94
  * @param commandNames - Names the caller may call
56
- * @param discover - Whether the caller can call `afd-discover`. Without it the suggestion ends
57
- * as Rust's and C++'s do (`spec/error-codes.md`, "Suggestions name only tools the host provides")
95
+ * @param next - The command the caller can call to list the others ({@link notFoundNext}). With
96
+ * `null` the suggestion ends as Rust's and C++'s do (`spec/error-codes.md`, "Suggestions name
97
+ * only tools the host provides")
58
98
  */
59
- export function notFoundSuggestion(commandName, commandNames, discover = true) {
60
- const next = discover
61
- ? 'Use afd-discover to list all commands.'
99
+ export function notFoundSuggestion(commandName, commandNames, next = 'afd-discover') {
100
+ const pointer = next
101
+ ? `Use ${next} to list all commands.`
62
102
  : 'Check the command name against the available commands.';
63
103
  const [best, ...others] = findSimilarTools(commandName, commandNames, MAX_NOT_FOUND_MATCHES);
64
104
  if (best === undefined)
65
- return next;
105
+ return pointer;
66
106
  const alsoClose = others.length
67
107
  ? ` Other close matches: ${others.map((name) => `'${name}'`).join(', ')}.`
68
108
  : '';
69
- return `Did you mean '${best}'?${alsoClose} ${next}`;
109
+ return `Did you mean '${best}'?${alsoClose} ${pointer}`;
110
+ }
111
+ /**
112
+ * The `COMMAND_NOT_FOUND` error for an unknown name at lookup (a call, `afd-call`, a batch item or
113
+ * a pipeline step). Its suggestion and its recovery name the same command, `next`, or none
114
+ * (`spec/recovery.md`, "Engine errors").
115
+ */
116
+ export function notFoundError(commandName, commandNames, next) {
117
+ return {
118
+ code: 'COMMAND_NOT_FOUND',
119
+ message: `Command '${truncateName(commandName)}' not found`,
120
+ suggestion: notFoundSuggestion(commandName, commandNames, next),
121
+ ...(next && { recovery: { kind: 'call', command: next } }),
122
+ };
70
123
  }
71
124
  /**
72
125
  * The `COMMAND_NOT_IN_CONTEXT` error for a command outside the active context.
73
126
  *
74
- * @param belongsTo - The command's contexts, when the caller cannot call the `afd-context-*`
75
- * tools: the suggestion then names them, as Rust's and C++'s do
127
+ * @param belongsTo - The command's contexts
128
+ * @param can - Whether the caller can call a command ({@link canCall}). When it can call
129
+ * `afd-context-list`, the suggestion and the recovery name it (and the suggestion names
130
+ * `afd-context-enter` too, when the caller can call that); otherwise the suggestion names the
131
+ * command's contexts, as Rust's and C++'s do, and the error carries no recovery. Default: every
132
+ * command can be called
76
133
  */
77
- export function notInContextError(commandName, activeContext, belongsTo) {
78
- return {
134
+ export function notInContextError(commandName, activeContext, belongsTo = [], can = () => true) {
135
+ const error = {
79
136
  code: 'COMMAND_NOT_IN_CONTEXT',
80
137
  message: `Command '${commandName}' is not available in context '${activeContext}'`,
81
- suggestion: belongsTo
82
- ? `Switch to a context this command belongs to (${belongsTo.map((name) => `'${name}'`).join(', ')}), or call it with no active context.`
83
- : 'Use afd-context-list to see available contexts, or afd-context-enter to switch.',
138
+ };
139
+ const list = 'afd-context-list';
140
+ if (!can(list)) {
141
+ return {
142
+ ...error,
143
+ suggestion: `Switch to a context this command belongs to (${belongsTo.map((name) => `'${name}'`).join(', ')}), or call it with no active context.`,
144
+ };
145
+ }
146
+ return {
147
+ ...error,
148
+ suggestion: `Use ${list} to see available contexts${can('afd-context-enter') ? ', or afd-context-enter to switch' : ''}.`,
149
+ recovery: { kind: 'call', command: list },
84
150
  };
85
151
  }
86
152
  //# sourceMappingURL=command-routing.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"command-routing.js","sourceRoot":"","sources":["../src/command-routing.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AASxD;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAClC,OAAwD;IAExD,OAAO,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,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AAO;QACN,GAAG,KAAK;QACR,UAAU,EAAE,OAAO,IAAI,6BAA6B,GAAG,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,kCAAkC,CAAC,CAAC,CAAC,EAAE,GAAG;QACzH,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;KACzC,CAAC;AACH,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { CommandMiddleware } from '@lushly-dev/afd-core';
2
+ /** Normative server-level default per-command deadline in milliseconds (`spec/execution-controls.md`). */
3
+ export declare const DEFAULT_COMMAND_TIMEOUT_MS = 30000;
4
+ /**
5
+ * Validate and normalize `defaultTimeoutMs` for a server:
6
+ * - `undefined` → {@link DEFAULT_COMMAND_TIMEOUT_MS} (`30000`)
7
+ * - `0` or `null` → `null` (default deadline disabled)
8
+ * - positive finite number → that millisecond value
9
+ */
10
+ export declare function resolveDefaultTimeoutMs(value: number | null | undefined): number | null;
11
+ /**
12
+ * The standalone server's deadline boundary: outside user middleware, with a cancellation guard
13
+ * directly before the handler. Keep this out of `/direct`, whose callers use DirectClient's
14
+ * deadline, so in-process hosts that never set `context.timeout` do not bundle timer machinery.
15
+ */
16
+ export declare function withCommandDeadlines(middleware: readonly CommandMiddleware[], defaultTimeoutMs?: number | null): CommandMiddleware[];
17
+ //# sourceMappingURL=command-timeout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-timeout.d.ts","sourceRoot":"","sources":["../src/command-timeout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,iBAAiB,EAAiB,MAAM,sBAAsB,CAAC;AAI7F,0GAA0G;AAC1G,eAAO,MAAM,0BAA0B,QAAS,CAAC;AAEjD;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAOvF;AA0ED;;;;GAIG;AACH,wBAAgB,oBAAoB,CACnC,UAAU,EAAE,SAAS,iBAAiB,EAAE,EACxC,gBAAgB,GAAE,MAAM,GAAG,IAAW,GACpC,iBAAiB,EAAE,CAerB"}
@@ -0,0 +1,99 @@
1
+ import { failure, truncateName } from '@lushly-dev/afd-core';
2
+ import { idempotencyStepActed } from './approval-admission.js';
3
+ /** Normative server-level default per-command deadline in milliseconds (`spec/execution-controls.md`). */
4
+ export const DEFAULT_COMMAND_TIMEOUT_MS = 30_000;
5
+ /**
6
+ * Validate and normalize `defaultTimeoutMs` for a server:
7
+ * - `undefined` → {@link DEFAULT_COMMAND_TIMEOUT_MS} (`30000`)
8
+ * - `0` or `null` → `null` (default deadline disabled)
9
+ * - positive finite number → that millisecond value
10
+ */
11
+ export function resolveDefaultTimeoutMs(value) {
12
+ if (value === undefined)
13
+ return DEFAULT_COMMAND_TIMEOUT_MS;
14
+ if (value === null || value === 0)
15
+ return null;
16
+ if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) {
17
+ throw new RangeError('defaultTimeoutMs must be a positive finite number, 0, or null');
18
+ }
19
+ return value;
20
+ }
21
+ function cancelledBeforeStart(name) {
22
+ return failure({
23
+ code: 'COMMAND_CANCELLED',
24
+ message: `Command '${truncateName(name)}' was cancelled before it started`,
25
+ suggestion: 'Retry with a fresh signal if the command is still needed.',
26
+ retryable: false,
27
+ });
28
+ }
29
+ /** Bound middleware and handler execution by one per-command deadline. */
30
+ async function withCommandTimeout(name, context, execute, defaultTimeoutMs) {
31
+ const { timeout, signal } = context;
32
+ if (signal?.aborted)
33
+ return cancelledBeforeStart(name);
34
+ const effectiveTimeout = timeout === undefined ? defaultTimeoutMs : timeout;
35
+ // Match DirectClient: only positive, finite millisecond values enforce a deadline.
36
+ if (typeof effectiveTimeout !== 'number' ||
37
+ !Number.isFinite(effectiveTimeout) ||
38
+ effectiveTimeout <= 0) {
39
+ return execute();
40
+ }
41
+ const controller = new AbortController();
42
+ const effectiveSignal = signal ? AbortSignal.any([signal, controller.signal]) : controller.signal;
43
+ // Preserve Object.keys(context) when the server attaches a deadline signal to a call whose
44
+ // caller supplied none, so journal context digests stay identical to un-timed contexts.
45
+ Object.defineProperty(context, 'signal', {
46
+ value: effectiveSignal,
47
+ configurable: true,
48
+ writable: true,
49
+ enumerable: Boolean(signal),
50
+ });
51
+ let timer;
52
+ const timedOut = new Promise((resolve) => {
53
+ timer = setTimeout(() => {
54
+ // Settle the deadline first, so a handler completing on abort cannot win the race.
55
+ // Where the idempotency step holds the call's key, a repeat with that key is answered
56
+ // from its store, so it is safe (spec/idempotency.md, R3); anywhere else it is not.
57
+ const keyed = idempotencyStepActed(context);
58
+ resolve(failure({
59
+ code: 'TIMEOUT',
60
+ message: `Command '${truncateName(name)}' timed out after ${effectiveTimeout}ms`,
61
+ suggestion: keyed
62
+ ? 'Repeat the call with the same idempotency key and input: this server answers it from the first call, so the change is not applied twice.'
63
+ : 'Retry with a larger timeout. The command was signalled to abort but may have completed, so check its effect before retrying a mutation.',
64
+ retryable: true,
65
+ recovery: keyed ? { kind: 'retry' } : { kind: 'external' },
66
+ details: { command: name, timeoutMs: effectiveTimeout },
67
+ }));
68
+ controller.abort();
69
+ }, Math.min(Math.ceil(effectiveTimeout), 2_147_483_647));
70
+ });
71
+ try {
72
+ // The race also consumes late rejections from work that ignores cancellation.
73
+ return await Promise.race([execute(), timedOut]);
74
+ }
75
+ finally {
76
+ clearTimeout(timer);
77
+ }
78
+ }
79
+ /**
80
+ * The standalone server's deadline boundary: outside user middleware, with a cancellation guard
81
+ * directly before the handler. Keep this out of `/direct`, whose callers use DirectClient's
82
+ * deadline, so in-process hosts that never set `context.timeout` do not bundle timer machinery.
83
+ */
84
+ export function withCommandDeadlines(middleware, defaultTimeoutMs = null) {
85
+ const resolvedDefault = defaultTimeoutMs === null ? null : resolveDefaultTimeoutMs(defaultTimeoutMs);
86
+ return [
87
+ (name, _input, context, next) => withCommandTimeout(name, context, next, resolvedDefault),
88
+ ...middleware,
89
+ async (name, _input, context, next) => {
90
+ // A delayed approval must never start work after its caller received a timeout or
91
+ // cancelled the request, including an ungated step resuming after the shared plan.
92
+ if (context.signal?.aborted) {
93
+ return cancelledBeforeStart(name);
94
+ }
95
+ return next();
96
+ },
97
+ ];
98
+ }
99
+ //# sourceMappingURL=command-timeout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-timeout.js","sourceRoot":"","sources":["../src/command-timeout.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE/D,0GAA0G;AAC1G,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAgC;IACvE,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,0BAA0B,CAAC;IAC3D,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAC/C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACvE,MAAM,IAAI,UAAU,CAAC,+DAA+D,CAAC,CAAC;IACvF,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,SAAS,oBAAoB,CAAC,IAAY;IACzC,OAAO,OAAO,CAAC;QACd,IAAI,EAAE,mBAAmB;QACzB,OAAO,EAAE,YAAY,YAAY,CAAC,IAAI,CAAC,mCAAmC;QAC1E,UAAU,EAAE,2DAA2D;QACvE,SAAS,EAAE,KAAK;KAChB,CAAC,CAAC;AACJ,CAAC;AAED,0EAA0E;AAC1E,KAAK,UAAU,kBAAkB,CAChC,IAAY,EACZ,OAAuB,EACvB,OAAqC,EACrC,gBAA+B;IAE/B,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IACpC,IAAI,MAAM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AC;AACH,CAAC"}
@@ -1,15 +1,14 @@
1
1
  /**
2
- * @fileoverview The confirmation gate (`spec/command-metadata.md`, "Confirmations"): the check
2
+ * @fileoverview The confirmation gate (`spec/confirmations.md`): the check
3
3
  * that decides whether a call to confirm-gated commands may run, its binding digest, and the
4
- * check of the HTTP routes.
4
+ * confirmation channel of the HTTP routes.
5
5
  *
6
6
  * Split from `confirmations.ts` because the binding digest uses `node:crypto`: only the MCP server
7
7
  * (`server.ts`) and its HTTP handler import this module, so the tool router and the tool list stay
8
8
  * free of Node.js built-ins for `createDirectToolSurface`. In-process calls are never gated.
9
9
  */
10
10
  import type { IncomingMessage } from 'node:http';
11
- import type { CommandError } from '@lushly-dev/afd-core';
12
- import { type ConfirmationGate, type ConfirmationMode, type ConfirmationStep } from './confirmations.js';
11
+ import { type ConfirmationChannel, type ConfirmationGate, type ConfirmationMode, type ConfirmationStep } from './confirmations.js';
13
12
  import type { ZodCommandDefinition } from './schema.js';
14
13
  /**
15
14
  * The binding of a confirmation: a digest of the gated commands and their input. The lane that
@@ -25,8 +24,9 @@ export declare function createConfirmationGate(mode: ConfirmationMode, commands:
25
24
  /** Header that acknowledges confirm-gated commands on the HTTP routes: their names, comma-separated. */
26
25
  export declare const AFD_CONFIRM_HEADER = "afd-confirm";
27
26
  /**
28
- * The check of the HTTP routes (`/rpc`, `/batch`, `/stream`), which have no elicitation channel:
29
- * the confirmation error for a request, or `undefined` when it may run.
27
+ * What a request to the HTTP routes (`/rpc`, `/batch`, `/stream`) can carry for confirmations: no
28
+ * elicitation, and the command names its `Afd-Confirm` header acknowledges. The router's gate then
29
+ * decides it as it decides any call (`admission.ts`).
30
30
  */
31
- export declare function createHttpConfirmationCheck(gate: ConfirmationGate | undefined): (req: IncomingMessage, steps: ConfirmationStep[]) => Promise<CommandError | undefined>;
31
+ export declare function httpConfirmationChannel(req: IncomingMessage): ConfirmationChannel;
32
32
  //# sourceMappingURL=confirmation-gate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"confirmation-gate.d.ts","sourceRoot":"","sources":["../src/confirmation-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAEN,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EAErB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAcxD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,gBAAgB,EAAE,GAAG,MAAM,CAI9E;AAkBD;;;GAGG;AACH,wBAAgB,sBAAsB,CACrC,IAAI,EAAE,gBAAgB,EACtB,QAAQ,EAAE,SAAS,oBAAoB,EAAE,GACvC,gBAAgB,CAkElB;AAED,wGAAwG;AACxG,eAAO,MAAM,kBAAkB,gBAAgB,CAAC;AAehD;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,gBAAgB,GAAG,SAAS,SAEvE,eAAe,SACb,gBAAgB,EAAE,KACvB,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAWpC"}
1
+ {"version":3,"file":"confirmation-gate.d.ts","sourceRoot":"","sources":["../src/confirmation-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEjD,OAAO,EAEN,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EAErB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAcxD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,gBAAgB,EAAE,GAAG,MAAM,CAI9E;AAkBD;;;GAGG;AACH,wBAAgB,sBAAsB,CACrC,IAAI,EAAE,gBAAgB,EACtB,QAAQ,EAAE,SAAS,oBAAoB,EAAE,GACvC,gBAAgB,CA0ElB;AAED,wGAAwG;AACxG,eAAO,MAAM,kBAAkB,gBAAgB,CAAC;AAehD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,eAAe,GAAG,mBAAmB,CAajF"}
@@ -1,7 +1,7 @@
1
1
  /**
2
- * @fileoverview The confirmation gate (`spec/command-metadata.md`, "Confirmations"): the check
2
+ * @fileoverview The confirmation gate (`spec/confirmations.md`): the check
3
3
  * that decides whether a call to confirm-gated commands may run, its binding digest, and the
4
- * check of the HTTP routes.
4
+ * confirmation channel of the HTTP routes.
5
5
  *
6
6
  * Split from `confirmations.ts` because the binding digest uses `node:crypto`: only the MCP server
7
7
  * (`server.ts`) and its HTTP handler import this module, so the tool router and the tool list stay
@@ -56,7 +56,12 @@ export function createConfirmationGate(mode, commands) {
56
56
  throw new Error("confirmations must be 'off', 'enforce' or 'require-human'");
57
57
  }
58
58
  const byName = new Map(commands.map((command) => [command.name, command]));
59
- const gated = (steps) => mode === 'off' ? [] : steps.filter((step) => !!byName.get(step.command)?.confirmPrompt);
59
+ const gated = (steps) => mode === 'off'
60
+ ? []
61
+ : steps.filter((step) => {
62
+ const command = byName.get(step.command);
63
+ return !!command?.confirmPrompt && command.confirmationMode !== 'host-verified';
64
+ });
60
65
  return {
61
66
  mode,
62
67
  gated,
@@ -78,6 +83,7 @@ export function createConfirmationGate(mode, commands) {
78
83
  message: `The user did not confirm ${names.map((name) => `'${name}'`).join(', ')}`,
79
84
  suggestion: 'Do not run this again without asking the user first; the user chose not to proceed.',
80
85
  retryable: false,
86
+ recovery: { kind: 'stop' },
81
87
  details: { commands: names },
82
88
  },
83
89
  };
@@ -105,6 +111,8 @@ export function createConfirmationGate(mode, commands) {
105
111
  ? `Make sure the user intends this, then ${howToAcknowledge}.`
106
112
  : 'This server accepts only a confirmation from the user: use an MCP client that supports elicitation.',
107
113
  retryable: false,
114
+ // The user confirms, which never goes in a recovery's input (rule 5).
115
+ recovery: { kind: 'external' },
108
116
  details: { commands: names },
109
117
  },
110
118
  };
@@ -125,16 +133,22 @@ function headerAcknowledgement(req) {
125
133
  .filter(Boolean));
126
134
  }
127
135
  /**
128
- * The check of the HTTP routes (`/rpc`, `/batch`, `/stream`), which have no elicitation channel:
129
- * the confirmation error for a request, or `undefined` when it may run.
136
+ * What a request to the HTTP routes (`/rpc`, `/batch`, `/stream`) can carry for confirmations: no
137
+ * elicitation, and the command names its `Afd-Confirm` header acknowledges. The router's gate then
138
+ * decides it as it decides any call (`admission.ts`).
130
139
  */
131
- export function createHttpConfirmationCheck(gate) {
132
- return async (req, steps) => {
133
- if (!gate || gate.mode === 'off')
134
- return undefined;
135
- const names = [...new Set(gate.gated(steps).map((step) => step.command))];
136
- const outcome = await gate.check(steps, headerAcknowledgement(req), undefined, `repeat the request with the header 'Afd-Confirm: ${names.join(', ')}'`);
137
- return outcome.kind === 'error' ? outcome.error : undefined;
140
+ export function httpConfirmationChannel(req) {
141
+ return {
142
+ canElicit: false,
143
+ acknowledged: false,
144
+ response: async () => 'missing',
145
+ request: async () => {
146
+ throw new Error('The HTTP routes cannot ask for a confirmation');
147
+ },
148
+ acknowledgement: {
149
+ names: headerAcknowledgement(req),
150
+ how: (names) => `repeat the request with the header 'Afd-Confirm: ${names.join(', ')}'`,
151
+ },
138
152
  };
139
153
  }
140
154
  //# sourceMappingURL=confirmation-gate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"confirmation-gate.js","sourceRoot":"","sources":["../src/confirmation-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAKN,mBAAmB,GACnB,MAAM,oBAAoB,CAAC;AAG5B,wEAAwE;AACxE,S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