@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
@@ -1 +1 @@
1
- {"version":3,"file":"elicitation-state.js","sourceRoot":"","sources":["../src/elicitation-state.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAgBH,4FAA4F;AAC5F,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAatC,SAAS,OAAO,CAAC,KAAc;IAC9B,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,CAAC,KAAK,QAAQ,IAAI,OAAO,KAAK,CAAC,CAAC,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACjG,OAAO,CACN,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;QACxB,CAAC,KAAK,CAAC,CAAC,KAAK,SAAS,IAAI,OAAO,KAAK,CAAC,CAAC,KAAK,QAAQ,CAAC;QACtD,CAAC,KAAK,CAAC,CAAC,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACnD,CAAC,KA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,KAAK,CAAC,CAAC,KAAK,QAAQ,CAAC;QACtD,CAAC,KAAK,CAAC,CAAC,KAAK,SAAS,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACxD,CAAC,KAAK,CAAC,CAAC,KAAK,SAAS,IAAI,OAAO,KAAK,CAAC,CAAC,KAAK,QAAQ,CAAC;QACtD,CAAC,KAAK,CAAC,CAAC,KAAK,SAAS,IAAI,OAAO,KAAK,CAAC,CAAC,KAAK,QAAQ,CAAC,CACtD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAc;IAC1C,OAAO,CACN,QAAQ,CAAC,KAAK,CAAC;QACf,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;QACtB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;QACtB,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;QACtB,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CACtB,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AACtE,CAAC"}
@@ -7,10 +7,12 @@
7
7
  * `executeCommand` as the callback, so their semantics are shared with the
8
8
  * core registry and DirectClient.
9
9
  */
10
- import type { BatchRequest, BatchResult, CommandContext, CommandMiddleware, CommandResult, ContextDefaults, PipelineRequest, PipelineResult, StreamChunk } from '@lushly-dev/afd-core';
10
+ import type { BatchRequest, BatchResult, CommandContext, CommandError, CommandMiddleware, CommandResult, ContextDefaults, PipelineRequest, PipelineResult, StreamChunk } from '@lushly-dev/afd-core';
11
11
  import { type ContextField } from './context-fields.js';
12
12
  import { type ContextState } from './context-scope.js';
13
+ import type { IdempotencyStep } from './idempotency-step.js';
13
14
  import type { ZodCommandDefinition } from './schema.js';
15
+ import type { EnhancedValidationResult } from './validation.js';
14
16
  export interface ExecutionDeps {
15
17
  commandMap: Map<string, ZodCommandDefinition>;
16
18
  middleware: CommandMiddleware[];
@@ -24,12 +26,56 @@ export interface ExecutionDeps {
24
26
  /** Declared context fields, validated on each call's context (`spec/context-fields.md`). */
25
27
  contextFields?: readonly ContextField[];
26
28
  /**
27
- * Whether refusals may name `afd-discover` and the `afd-context-*` tools, which only a host that
28
- * serves them can (`spec/error-codes.md`, "Suggestions name only tools the host provides").
29
- * Default `true`: the MCP server serves both. A direct registry without a tool surface sets
30
- * `false`.
29
+ * Whether the host serves the meta-tools (`afd-discover` and the rest) to the callers of this
30
+ * engine. A refusal names a command, in its suggestion and in its recovery, only where the
31
+ * caller can call it (`spec/recovery.md`, "Engine errors"): a meta-tool only when this is set,
32
+ * and any other command only when it is in `commandMap`, allowed in the active context, admitted
33
+ * by the call's `allow` list and shown under MCP authorization. Default `true`: the MCP server's
34
+ * router serves them. A direct registry without a tool surface, and in-process calls that reach
35
+ * the engine without the router, set `false`.
31
36
  */
32
- suggestTools?: boolean;
37
+ metaTools?: boolean;
38
+ /** Whether a command is hidden from the caller of `context` (MCP authorization, M6). */
39
+ hidden?: (name: string, context: CommandContext) => boolean;
40
+ /**
41
+ * Whether the caller of `context` is shown the command `name` (M6), so a refusal names it only
42
+ * then ({@link canCall}). The server passes the request's scope view here, so the engine, which
43
+ * `/direct` bundles, never loads `scope-view`. Default: every command is shown.
44
+ */
45
+ isShown?: (name: string, context: CommandContext | undefined) => boolean;
46
+ /** The commands the caller of `context` may be shown, for suggestions (M6). */
47
+ shown?: (commands: ZodCommandDefinition[], context: CommandContext) => ZodCommandDefinition[];
48
+ /**
49
+ * The validation of this run of `name` on `input`, when something other than the schema
50
+ * alone decides its data. The MCP server answers for a step of an `afd-batch` or `afd-pipe`
51
+ * approved up front, which runs on the input the human was shown (#1414).
52
+ */
53
+ validated?: (name: string, input: unknown, context: CommandContext) => Promise<EnhancedValidationResult<unknown> | undefined> | undefined;
54
+ /**
55
+ * The idempotency step (`spec/idempotency.md`, S1 to S13), shared by every engine of one server
56
+ * or registry. Without it, keys are still validated and delivered (K1 to K6).
57
+ */
58
+ idempotency?: IdempotencyStep;
59
+ /**
60
+ * The deadline the server gives a call that sets no `timeout` (`null` or unset: none), from
61
+ * which the step dates a reservation's lease (S7).
62
+ */
63
+ defaultTimeoutMs?: number | null;
64
+ /** Maximum commands accepted in a single batch (default: 500). */
65
+ maxBatchSize?: number;
66
+ /** Maximum parallelism accepted in a single batch (default: 16). */
67
+ maxBatchParallelism?: number;
68
+ /** Maximum validation issues reported in a single `VALIDATION_ERROR` (default: 100). */
69
+ maxValidationIssues?: number;
70
+ /**
71
+ * Optional host-verified relay hooks passed only by the Node MCP server (`server.ts`), keeping
72
+ * `relay-evidence.ts` out of browser `/direct` first-paint bundles.
73
+ */
74
+ relay?: {
75
+ transfer(from: CommandContext, to: CommandContext): void;
76
+ takeDispatch(context: CommandContext, commandName: string, data: unknown): CommandError | undefined;
77
+ clear(context: CommandContext): void;
78
+ };
33
79
  }
34
80
  export declare function createExecutionEngine(deps: ExecutionDeps): {
35
81
  executeCommand: (commandName: string, input: unknown, callerContext?: CommandContext) => Promise<CommandResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"execution.d.ts","sourceRoot":"","sources":["../src/execution.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACX,YAAY,EACZ,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,eAAe,EACf,cAAc,EACd,WAAW,EACX,MAAM,sBAAsB,CAAC;AAmB9B,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,KAAK,YAAY,EAAuB,MAAM,oBAAoB,CAAC;AAC5E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAQxD,MAAM,WAAW,aAAa;IAC7B,UAA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,GAAG,SAAS,CAAC,GAAG,SAAS,CAAC;IACxE;;;OAGG;IACH,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,kEAAkE;IAClE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oEAAoE;IACpE,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,wFAAwF;IACxF,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,KAAK,CAAC,EAAE;QACP,QAAQ,CAAC,IAAI,EAAE,cAAc,EAAE,EAAE,EAAE,cAAc,GAAG,IAAI,CAAC;QACzD,YAAY,CACX,OAAO,EAAE,cAAc,EACvB,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,OAAO,GACX,YAAY,GAAG,SAAS,CAAC;QAC5B,KAAK,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAAC;KACrC,CAAC;CACF;AAuBD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,aAAa;kCAoB1C,MAAM,SACZ,OAAO,kBACC,cAAc,KAC3B,OAAO,CAAC,aAAa,CAAC;4BAwQM,YAAY,YAAW,cAAc,KAAQ,OAAO,CAAC,WAAW,CAAC;+BActF,eAAe,YACf,cAAc,KACrB,OAAO,CAAC,cAAc,CAAC;iCAkCZ,MAAM,SACZ,OAAO,YACL,cAAc,KACrB,cAAc,CAAC,WAAW,EAAE,IAAI,EAAE,OAAO,CAAC;EAS7C"}
package/dist/execution.js CHANGED
@@ -7,13 +7,19 @@
7
7
  * `executeCommand` as the callback, so their semantics are shared with the
8
8
  * core registry and DirectClient.
9
9
  */
10
- import { executeBatch as executeCoreBatch, executePipeline as executeCorePipeline, executeStream as executeCoreStream, executionFailure, failure, isActorKind, truncateName, withContextDefaults, } from '@lushly-dev/afd-core';
10
+ import { executeBatch as executeCoreBatch, executePipeline as executeCorePipeline, executeStream as executeCoreStream, executionFailure, failure, invalidIdempotencyKeyError, isActorKind, withContextDefaults, } from '@lushly-dev/afd-core';
11
11
  import { commandNotAllowed } from '@lushly-dev/afd-core/internal/direct-allow';
12
+ import { setDispatchId, takeDispatchId } from '@lushly-dev/afd-core/internal/dispatch-id';
13
+ import { deliverIdempotencyKey, IDEMPOTENCY_KEY_SET_BY_ENGINE, requestIdempotencyContext, resolveIdempotencyKey, } from '@lushly-dev/afd-core/internal/idempotency';
14
+ import { beginAdmission, markEngineNext, markIdempotencyStepActed, needsAdmission, recordCallKey, takeAdmission, } from './approval-admission.js';
12
15
  import { filterAllowed, isCommandAllowed } from './command-allow.js';
13
- import { filterByContext, isAccessibleInContext, notFoundSuggestion, notInContextError, } from './command-routing.js';
16
+ import { canCall, filterByContext, isAccessibleInContext, notFoundError, notFoundNext, notInContextError, } from './command-routing.js';
14
17
  import { applyContextFields } from './context-fields.js';
15
18
  import { resolveContextState } from './context-scope.js';
16
- import { formatEnhancedValidationError, validateInputEnhanced } from './validation.js';
19
+ import { hostState } from './host-state.js';
20
+ import { offTape } from './journal-off-tape.js';
21
+ import { applyOutputBudget, checkOutputBudgetResult, EFFECTIVE_OUTPUT_BUDGET, SKIP_OUTPUT_BUDGET, } from './output-budget.js';
22
+ import { formatEnhancedValidationError, validateInputEnhanced, validationRecovery, } from './validation.js';
17
23
  // ═══════════════════════════════════════════════════════════════════════════════
18
24
  // EXECUTION ENGINE FACTORY
19
25
  // ═══════════════════════════════════════════════════════════════════════════════
@@ -36,7 +42,11 @@ function runHook(hook, onHookError) {
36
42
  }
37
43
  export function createExecutionEngine(deps) {
38
44
  const { commandMap, middleware, devMode, onCommand, onError } = deps;
39
- const suggestTools = deps.suggestTools ?? true;
45
+ const surface = {
46
+ metaTools: deps.metaTools ?? true,
47
+ command: (name) => commandMap.get(name),
48
+ shown: deps.isShown,
49
+ };
40
50
  /** Report to `onError`. A failing `onError` has nowhere left to report, so it is ignored. */
41
51
  function reportError(error) {
42
52
  runHook(() => onError?.(toError(error)), () => { });
@@ -52,29 +62,71 @@ export function createExecutionEngine(deps) {
52
62
  return failure(commandNotAllowed(commandName));
53
63
  }
54
64
  // One context object flows through every middleware into the handler.
65
+ // Read the non-enumerable stream marker from callerContext before spreading defaults,
66
+ // so it never leaks into middleware or handlers.
67
+ const skipOutputBudget = Boolean(callerContext[SKIP_OUTPUT_BUDGET]);
68
+ const step = deps.idempotency;
55
69
  const context = withContextDefaults(callerContext, deps.contextDefaults);
56
- const command = commandMap.get(commandName);
70
+ // This dispatch's id (spec/dispatch.md, "The dispatch id"): made here (or by the surface's
71
+ // own check before this engine, such as an app call's grant), never taken from the caller,
72
+ // and fixed on this context for every middleware and the handler (I3).
73
+ setDispatchId(context, takeDispatchId(context));
74
+ deps.relay?.transfer(callerContext, context);
75
+ const key = resolveIdempotencyKey(callerContext);
76
+ deliverIdempotencyKey(context, key);
77
+ // A command hidden from the caller (MCP authorization, M6) is looked up as a name that
78
+ // does not exist, before validation, middleware or the handler.
79
+ const command = deps.hidden?.(commandName, callerContext)
80
+ ? undefined
81
+ : commandMap.get(commandName);
57
82
  const activeContext = resolveContextState(context, deps.contextState)?.getActive();
83
+ // The command's own approval policy, for the approval middleware to decide from. This
84
+ // call's context is a fresh object, so no other call's admission applies to it.
85
+ if (command)
86
+ beginAdmission(context, command);
87
+ /** Whether this caller can call `name` here, decided once for the suggestion and recovery. */
88
+ const can = (name) => canCall(surface, name, callerContext, activeContext);
58
89
  if (!command) {
59
90
  // A few close matches, never the whole list: in lazy mode that would load
60
91
  // every command name into the agent's context on a single typo. Never one the call's
61
- // `allow` option refuses.
62
- const candidates = filterAllowed(filterByContext([...commandMap.values()], activeContext), callerContext);
63
- return failure({
64
- code: 'COMMAND_NOT_FOUND',
65
- message: `Command '${truncateName(commandName)}' not found`,
66
- suggestion: notFoundSuggestion(commandName, candidates.map((candidate) => candidate.name), suggestTools),
67
- });
92
+ // `allow` option refuses, nor one the caller is not shown.
93
+ const listed = [...commandMap.values()];
94
+ const candidates = filterAllowed(filterByContext(deps.shown?.(listed, callerContext) ?? listed, activeContext), callerContext);
95
+ return failure(notFoundError(commandName, candidates.map((candidate) => candidate.name), notFoundNext(can)));
68
96
  }
69
97
  if (activeContext && !isAccessibleInContext(command, activeContext)) {
70
- return failure(notInContextError(commandName, activeContext, suggestTools ? undefined : command.contexts));
98
+ return failure(notInContextError(commandName, activeContext, command.contexts, can));
99
+ }
100
+ // The key, between the context check and validation (spec/dispatch.md, "The idempotency
101
+ // step"): a malformed one fails the call before any middleware or handler (K2).
102
+ if (key.kind === 'invalid')
103
+ return failure(invalidIdempotencyKeyError());
104
+ // A task run carries no key for the step or the retry middleware (S11).
105
+ const taskRun = hostState(callerContext).taskRun === true;
106
+ recordCallKey(context, key.kind === 'key' && !taskRun);
107
+ const stepKey = step && key.kind === 'key' && command.idempotency === 'keyed' && !taskRun
108
+ ? key.key
109
+ : undefined;
110
+ // The step acts only where it can tell this caller apart (S3).
111
+ let principal;
112
+ if (step && stepKey !== undefined) {
113
+ const decided = step.principal(context);
114
+ if (decided.kind === 'refused')
115
+ return failure(decided.error);
116
+ if (decided.kind === 'internal')
117
+ return failure(step.internalError());
118
+ principal = decided.principal;
71
119
  }
72
120
  // Validate input with enhanced error messages. Schema callbacks (.refine,
73
121
  // .superRefine, .transform, .preprocess) run here, so an exception they throw
74
122
  // becomes a VALIDATION_ERROR result instead of rejecting.
75
123
  let validation;
76
124
  try {
77
- validation = validateInputEnhanced(command.inputSchema, input);
125
+ // The MCP server validates a step of an afd-batch or afd-pipe approved up front itself,
126
+ // to run it on the input the human was shown (#1414).
127
+ validation =
128
+ (await deps.validated?.(commandName, input, context)) ??
129
+ validateInputEnhanced(command.inputSchema, input, deps.maxValidationIssues);
78
130
  }
79
131
  catch (error) {
80
132
  const err = toError(error);
@@ -95,24 +147,112 @@ export function createExecutionEngine(deps) {
95
147
  expectedFields: validation.expectedFields,
96
148
  unexpectedFields: validation.unexpectedFields,
97
149
  missingFields: validation.missingFields,
150
+ truncated: validation.truncated,
151
+ limit: validation.limit,
152
+ }),
153
+ recovery: validationRecovery({
154
+ errors: validation.errors,
155
+ missingFields: validation.missingFields,
156
+ unexpectedFields: validation.unexpectedFields,
98
157
  }),
99
158
  details: {
100
159
  errors: validation.errors,
101
160
  expectedFields: validation.expectedFields,
102
161
  unexpectedFields: validation.unexpectedFields,
103
162
  missingFields: validation.missingFields,
163
+ ...(validation.truncated
164
+ ? {
165
+ truncated: true,
166
+ limit: validation.limit,
167
+ totalErrors: validation.totalErrors,
168
+ }
169
+ : {}),
104
170
  },
105
171
  });
106
172
  }
107
- const invalidField = applyContextFields(deps.contextFields ?? [], context, commandName);
173
+ const invalidField = applyContextFields(deps.contextFields ?? [], context, commandName, {
174
+ devMode,
175
+ onError: reportError,
176
+ });
108
177
  if (invalidField)
109
178
  return invalidField;
179
+ const invalidBudget = applyOutputBudget(command, context);
180
+ if (invalidBudget)
181
+ return invalidBudget;
182
+ const effectiveBudget = context.outputBudget;
183
+ if (effectiveBudget !== undefined) {
184
+ Object.defineProperty(context, EFFECTIVE_OUTPUT_BUDGET, { value: effectiveBudget });
185
+ }
110
186
  const data = validation.data;
187
+ // The call as the step compares it: its declared context fields and validated input (S4).
188
+ let stepCall;
189
+ if (step && stepKey !== undefined && principal !== undefined) {
190
+ const prepared = await step.prepare({
191
+ command: commandName,
192
+ key: stepKey,
193
+ fields: deps.contextFields?.map((field) => field.name) ?? [],
194
+ input: data,
195
+ context,
196
+ defaultTimeoutMs: deps.defaultTimeoutMs,
197
+ });
198
+ if (prepared.kind === 'refused')
199
+ return failure(prepared.error);
200
+ stepCall = prepared.call;
201
+ }
202
+ // When the chain, and the deadline the server's outermost link enforces, start on the step's
203
+ // clock: a reservation's lease counts from that deadline (S7).
204
+ let chainStartedAt = 0;
111
205
  // Build middleware chain
112
206
  const runHandler = async () => {
207
+ // A declared approval policy holds without the approval middleware: a command whose
208
+ // policy is not 'not-required' runs only when an approval step admitted this call. A
209
+ // policy function is not evaluated here; declaring one needs an approval step. The same
210
+ // holds for a policy given only in the middleware's `commands` list, once the middleware
211
+ // recorded that it gates this call.
212
+ // The admission must name this command and this validated input, and is taken here, so a
213
+ // second dispatch on the same context (a retry inside the chain) needs a second admission.
214
+ const admission = needsAdmission(context)
215
+ ? takeAdmission(context, commandName, data)
216
+ : 'admitted';
217
+ if (admission !== 'admitted') {
218
+ // 'mismatch': an approval step ran, but this dispatch is not the one it admitted (a
219
+ // retry placed after it, or the input changed after it), so the operator fixes the order.
220
+ return failure({
221
+ code: 'APPROVAL_UNAVAILABLE',
222
+ message: `${commandName} needs a person's approval, and this server cannot ask for it`,
223
+ suggestion: admission === 'missing'
224
+ ? `Tell the user that ${commandName} needs their approval and this server has no approval step; do not retry. The operator adds the approval middleware (createApprovalMiddleware) or removes the command's approval policy.`
225
+ : `Do not retry: this call is not the one approved. The operator moves middleware that retries or changes input before the approval middleware.`,
226
+ retryable: false,
227
+ // The operator fixes the approval setup.
228
+ recovery: { kind: 'external' },
229
+ details: { reason: admission === 'missing' ? 'no-approval-step' : 'admission-mismatch' },
230
+ });
231
+ }
232
+ const relayMismatch = deps.relay?.takeDispatch(context, commandName, data);
233
+ if (relayMismatch)
234
+ return failure(relayMismatch);
235
+ // Clear private relay evidence before the handler runs so nested in-process calls never see it.
236
+ deps.relay?.clear(context);
113
237
  const { clock } = context;
114
238
  const startTime = clock.now();
115
- const result = await command.handler(data, context);
239
+ // The idempotency step sits here, between the admission check and the handler (S1).
240
+ const rawResult = step
241
+ ? await step.run(stepCall, {
242
+ context,
243
+ commandName,
244
+ startedAt: chainStartedAt,
245
+ handler: () => command.handler(data, context),
246
+ onReserved: () => markIdempotencyStepActed(context),
247
+ reportError,
248
+ })
249
+ : await command.handler(data, context);
250
+ // Post-handler output budget check (spec/output-budgets.md, B5 & B6): runs before
251
+ // metadata stamping and before middleware or the journal see the result; skipped on
252
+ // buffered executeStream (B7).
253
+ const result = effectiveBudget !== undefined && !skipOutputBudget
254
+ ? checkOutputBudgetResult(command, effectiveBudget, rawResult)
255
+ : rawResult;
116
256
  // Build a new result rather than mutating the handler's (possibly frozen) object.
117
257
  // Read the actor after the handler: middleware (auth) may have refined it.
118
258
  return {
@@ -133,11 +273,17 @@ export function createExecutionEngine(deps) {
133
273
  if (!mw)
134
274
  continue;
135
275
  const currentNext = next;
276
+ // The journal reads a command's `secret` only from a middleware the engine invoked.
277
+ markEngineNext(context, currentNext);
136
278
  next = () => mw(commandName, data, context, currentNext);
137
279
  }
138
280
  let result;
281
+ if (step)
282
+ chainStartedAt = step.clock.now();
139
283
  try {
140
- result = await next();
284
+ // A call to a command declaring `secret` reads off every recording parent's tape, with or
285
+ // without a journal in this chain (`spec/journal.md`).
286
+ result = await (command.secret === true ? offTape(context, next) : next());
141
287
  }
142
288
  catch (error) {
143
289
  reportError(error);
@@ -157,7 +303,12 @@ export function createExecutionEngine(deps) {
157
303
  * error handling as a single call.
158
304
  */
159
305
  function executeBatch(request, context = {}) {
160
- return executeCoreBatch(request, executeCommand, context, { devMode });
306
+ // Each item runs under the key derived from the request's (spec/idempotency.md, K4).
307
+ return executeCoreBatch(request, executeCommand, requestIdempotencyContext(context), {
308
+ devMode,
309
+ maxBatchSize: deps.maxBatchSize,
310
+ maxBatchParallelism: deps.maxBatchParallelism,
311
+ });
161
312
  }
162
313
  /**
163
314
  * Execute a pipeline of chained commands with variable resolution.
@@ -172,6 +323,15 @@ export function createExecutionEngine(deps) {
172
323
  runnerContext.traceId = context.traceId;
173
324
  if (context.signal !== undefined)
174
325
  runnerContext.signal = context.signal;
326
+ // The request's key, from which each step's is derived (spec/idempotency.md, K4).
327
+ const keyed = requestIdempotencyContext(context);
328
+ if (keyed.idempotencyKey !== undefined) {
329
+ runnerContext.idempotencyKey = keyed.idempotencyKey;
330
+ const marked = keyed[IDEMPOTENCY_KEY_SET_BY_ENGINE];
331
+ if (marked !== undefined) {
332
+ runnerContext[IDEMPOTENCY_KEY_SET_BY_ENGINE] = marked;
333
+ }
334
+ }
175
335
  return executeCorePipeline(request, (name, input, stepContext) => executeCommand(name, input, { ...context, ...stepContext }), runnerContext);
176
336
  }
177
337
  /**
@@ -185,7 +345,11 @@ export function createExecutionEngine(deps) {
185
345
  * chunk.
186
346
  */
187
347
  function executeStream(commandName, input, context = {}) {
188
- return executeCoreStream(commandName, input, executeCommand, context, { devMode });
348
+ // B7: a streamed command's chunks are not checked by B5 in this version.
349
+ // Non-enumerable symbol keeps `context` structurally equal to the caller's object.
350
+ const streamContext = { ...context };
351
+ Object.defineProperty(streamContext, SKIP_OUTPUT_BUDGET, { value: true });
352
+ return executeCoreStream(commandName, input, executeCommand, streamContext, { devMode });
189
353
  }
190
354
  return { executeCommand, executeBatch, executePipeline, executeStream };
191
355
  }
@@ -1 +1 @@
1
- {"version":3,"file":"execution.js","sourceRoot":"","sources":["../src/execution.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAaH,OAAO,EACN,YAAY,IAAI,gBAAgB,EAChC,eAAe,IAAI,mBAAmB,EACtC,aAAa,IAAI,iBAAiB,EAClC,gBAAgB,EAChB,OAAO,EACP,WAAW,EACX,YAAY,EACZ,mBAAmB,GACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EACN,eAAe,EACf,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAqB,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAqB,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAG5E,OAAO,EAAE,6BAA6B,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AA2BvF,kFAAkF;AAClF,2BAA2B;AAC3B,kFAAkF;AAElF,SAAS,OAAO,CAAC,KAAc;IAC9B,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAA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,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,GAAG,OAAO,EAAE,GAAG,WAAW,EAAE,CAAC,EACzF,aAAa,CACb,CAAC;IACH,CAAC;IAED;;;;;;;;;OASG;IACH,SAAS,aAAa,CACrB,WAAmB,EACnB,KAAc,EACd,OAAO,GAAmB,EAAE;QAE5B,yEAAyE;QACzE,mFAAmF;QACnF,MAAM,aAAa,GAAmB,EAAE,GAAG,OAAO,EAAE,CAAC;QACrD,MAAM,CAAC,cAAc,CAAC,aAAa,EAAE,kBAAkB,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1E,OAAO,iBAAiB,CAAC,WAAW,EAAE,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IAC1F,CAAC;IAED,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,CAAC;AACzE,CAAC"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * @fileoverview Trusted host state: what the server's lanes and gates know about a call, kept
3
+ * apart from the values a handler sees on its `CommandContext` (#1743).
4
+ *
5
+ * The lanes and the admission pipeline (`admission.ts`) bind the call's session, scope view,
6
+ * channels and the rest here, once, as one frozen record. A context carries it as one opaque
7
+ * token under one module-private symbol. Spreading the context (`{ ...context, traceId }`) copies
8
+ * the token, so a command a handler runs with its own context is still decided under the caller's
9
+ * session and authorization. Nothing else can read, change or forge it:
10
+ *
11
+ * - the token is an empty frozen object; the record lives in this module's `WeakMap`, so
12
+ * `JSON.stringify`, `Object.keys` and the token itself reveal nothing;
13
+ * - tool arguments and `createContext` values are string keys, so they cannot reach the symbol;
14
+ * - a token this module did not mint is a forged one: it carries no state, and its command
15
+ * `allow` refuses every command (`command-allow.ts`), so forging never widens a call.
16
+ *
17
+ * A handler can still remove the token from its own context (its key is one of the context's own
18
+ * symbols), as it could remove each of the nine symbols this record replaced: what it then runs is
19
+ * a fresh in-process call, with the engine's own context state and no scope view or `allow`.
20
+ *
21
+ * The cross-copy records keyed under `Symbol.for` (approval admission, relay evidence, the
22
+ * journal, the output-budget ask) stay where they are: they are shared between installed copies
23
+ * of this package on purpose.
24
+ *
25
+ * Module-graph rule: loads nothing at run time, so the engine, the router and `/direct` stay
26
+ * browser-safe.
27
+ */
28
+ import type { CommandContext } from '@lushly-dev/afd-core';
29
+ import type { DirectAllow } from '@lushly-dev/afd-core/internal/direct-allow';
30
+ import type { ApprovalRelay, UpFrontApproval } from './approval-relay.js';
31
+ import type { ApproverCall } from './approver.js';
32
+ import type { ContextState } from './bootstrap/afd-context.js';
33
+ import type { ConfirmationChannel } from './confirmations.js';
34
+ import type { HumanRelayChannel } from './human-relay.js';
35
+ import type { IdempotencyCaller } from './idempotency-step.js';
36
+ import type { ScopeView } from './scope-view.js';
37
+ import type { TaskDispatch } from './task-dispatch.js';
38
+ /** Everything the host knows about a call that its handler must not read or change. */
39
+ export interface HostState {
40
+ /**
41
+ * The caller's context state: a session's, a request's, or `null` for a caller without one
42
+ * (a stateless HTTP request). Absent: the engine's own (stdio, in process).
43
+ */
44
+ readonly contextState?: ContextState | null;
45
+ /** The request's scope view under MCP authorization (M6). */
46
+ readonly scopeView?: ScopeView;
47
+ /** The approver's call, when the caller is an approver. */
48
+ readonly approver?: ApproverCall;
49
+ /** The approval relay of a call that can elicit. */
50
+ readonly approvalRelay?: ApprovalRelay;
51
+ /** The up-front approval of an `afd-batch` or `afd-pipe` step. */
52
+ readonly upFrontApproval?: UpFrontApproval;
53
+ /** What the request can carry for confirmations. */
54
+ readonly confirmationChannel?: ConfirmationChannel;
55
+ /** What the request can carry for a host-verified relay. */
56
+ readonly humanRelayChannel?: HumanRelayChannel;
57
+ /** MCP Tasks dispatch for the call. */
58
+ readonly taskDispatch?: TaskDispatch;
59
+ /** Who the lane says the caller is, for the idempotency step (`spec/idempotency.md`, S3). */
60
+ readonly idempotencyCaller?: IdempotencyCaller;
61
+ /** Set on a call that runs as an MCP task, on which the idempotency step never acts (S11). */
62
+ readonly taskRun?: true;
63
+ /** A direct registry call's `allow` predicate, combined with any it was nested in. */
64
+ readonly commandAllow?: DirectAllow;
65
+ /** Set on the state of a token this module did not mint. */
66
+ readonly forged?: true;
67
+ }
68
+ /**
69
+ * The host state `context` carries: empty without a token, and `{ forged: true }` for a token
70
+ * this module did not mint (any value under the symbol, `undefined` included).
71
+ */
72
+ export declare function hostState(context: CommandContext | undefined): Readonly<HostState>;
73
+ /** A copy of `context` whose host state is its own with `patch` applied (`undefined` removes). */
74
+ export declare function withHostState<T extends CommandContext>(context: T, patch: Partial<HostState>): T;
75
+ /**
76
+ * Apply `patch` to the host state of `context` itself, not a copy, when it carries one. Only the
77
+ * approval middleware does this, to release a step's up-front approval before its handler runs
78
+ * (`releaseUpFrontApproval`).
79
+ */
80
+ export declare function patchHostStateInPlace(context: CommandContext, patch: Partial<HostState>): void;
81
+ //# sourceMappingURL=host-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-state.d.ts","sourceRoot":"","sources":["../src/host-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4CAA4C,CAAC;AAC9E,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;A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ACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,IAAI,CAI9F"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @fileoverview Trusted host state: what the server's lanes and gates know about a call, kept
3
+ * apart from the values a handler sees on its `CommandContext` (#1743).
4
+ *
5
+ * The lanes and the admission pipeline (`admission.ts`) bind the call's session, scope view,
6
+ * channels and the rest here, once, as one frozen record. A context carries it as one opaque
7
+ * token under one module-private symbol. Spreading the context (`{ ...context, traceId }`) copies
8
+ * the token, so a command a handler runs with its own context is still decided under the caller's
9
+ * session and authorization. Nothing else can read, change or forge it:
10
+ *
11
+ * - the token is an empty frozen object; the record lives in this module's `WeakMap`, so
12
+ * `JSON.stringify`, `Object.keys` and the token itself reveal nothing;
13
+ * - tool arguments and `createContext` values are string keys, so they cannot reach the symbol;
14
+ * - a token this module did not mint is a forged one: it carries no state, and its command
15
+ * `allow` refuses every command (`command-allow.ts`), so forging never widens a call.
16
+ *
17
+ * A handler can still remove the token from its own context (its key is one of the context's own
18
+ * symbols), as it could remove each of the nine symbols this record replaced: what it then runs is
19
+ * a fresh in-process call, with the engine's own context state and no scope view or `allow`.
20
+ *
21
+ * The cross-copy records keyed under `Symbol.for` (approval admission, relay evidence, the
22
+ * journal, the output-budget ask) stay where they are: they are shared between installed copies
23
+ * of this package on purpose.
24
+ *
25
+ * Module-graph rule: loads nothing at run time, so the engine, the router and `/direct` stay
26
+ * browser-safe.
27
+ */
28
+ const HOST = Symbol('afd.hostState');
29
+ const EMPTY = Object.freeze({});
30
+ const FORGED = Object.freeze({ forged: true });
31
+ /** The records behind the tokens this module minted. */
32
+ const records = new WeakMap();
33
+ /** A new token for `state`. A forged state stays forged: `forged` is spread in with the rest. */
34
+ function mint(state) {
35
+ const token = Object.freeze({});
36
+ records.set(token, Object.freeze(state));
37
+ return token;
38
+ }
39
+ /**
40
+ * The host state `context` carries: empty without a token, and `{ forged: true }` for a token
41
+ * this module did not mint (any value under the symbol, `undefined` included).
42
+ */
43
+ export function hostState(context) {
44
+ if (!context || !(HOST in context))
45
+ return EMPTY;
46
+ return records.get(context[HOST]) ?? FORGED;
47
+ }
48
+ /** A copy of `context` whose host state is its own with `patch` applied (`undefined` removes). */
49
+ export function withHostState(context, patch) {
50
+ return { ...context, [HOST]: mint({ ...hostState(context), ...patch }) };
51
+ }
52
+ /**
53
+ * Apply `patch` to the host state of `context` itself, not a copy, when it carries one. Only the
54
+ * approval middleware does this, to release a step's up-front approval before its handler runs
55
+ * (`releaseUpFrontApproval`).
56
+ */
57
+ export function patchHostStateInPlace(context, patch) {
58
+ if (HOST in context) {
59
+ context[HOST] = mint({ ...hostState(context), ...patch });
60
+ }
61
+ }
62
+ //# sourceMappingURL=host-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-state.js","sourceRoot":"","sources":["../src/host-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AA4CH,MAAM,IAAI,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AACrC,MAAM,KAAK,GAAwB,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AACrD,MAAM,MAAM,GAAwB,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;AAEpE,wDAAwD;AACxD,MAAM,OAAO,GAAG,IAAI,OAAO,EAA+B,CAAC;AAE3D,iGAAiG;AACjG,SAAS,IAAI,CAAC,KAAgB;IAC7B,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAChC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACzC,OAAO,KAAK,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,OAAmC;IAC5D,IAAI,CAAC,OAAO,IAAI,CAAC,CAA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