@namzu/sdk 31.1.0 → 33.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 (355) hide show
  1. package/CHANGELOG.md +188 -0
  2. package/dist/agents/ReactiveAgent.d.ts.map +1 -1
  3. package/dist/agents/ReactiveAgent.js +4 -0
  4. package/dist/agents/ReactiveAgent.js.map +1 -1
  5. package/dist/agents/SupervisorAgent.d.ts.map +1 -1
  6. package/dist/agents/SupervisorAgent.js +4 -0
  7. package/dist/agents/SupervisorAgent.js.map +1 -1
  8. package/dist/agents/runAgent.d.ts +4 -0
  9. package/dist/agents/runAgent.d.ts.map +1 -1
  10. package/dist/agents/runAgent.js +4 -0
  11. package/dist/agents/runAgent.js.map +1 -1
  12. package/dist/authorization/gate.d.ts +1 -1
  13. package/dist/authorization/gate.js +1 -1
  14. package/dist/connector/index.d.ts +1 -1
  15. package/dist/connector/index.d.ts.map +1 -1
  16. package/dist/connector/index.js +1 -1
  17. package/dist/connector/index.js.map +1 -1
  18. package/dist/connector/mcp/adapter.d.ts.map +1 -1
  19. package/dist/connector/mcp/adapter.js +71 -16
  20. package/dist/connector/mcp/adapter.js.map +1 -1
  21. package/dist/connector/mcp/client.d.ts.map +1 -1
  22. package/dist/connector/mcp/client.js +3 -2
  23. package/dist/connector/mcp/client.js.map +1 -1
  24. package/dist/connector/mcp/http-redirect.d.ts +17 -0
  25. package/dist/connector/mcp/http-redirect.d.ts.map +1 -0
  26. package/dist/connector/mcp/http-redirect.js +31 -0
  27. package/dist/connector/mcp/http-redirect.js.map +1 -0
  28. package/dist/connector/mcp/http-sse.d.ts.map +1 -1
  29. package/dist/connector/mcp/http-sse.js +5 -0
  30. package/dist/connector/mcp/http-sse.js.map +1 -1
  31. package/dist/connector/mcp/image-admission.d.ts +16 -0
  32. package/dist/connector/mcp/image-admission.d.ts.map +1 -0
  33. package/dist/connector/mcp/image-admission.js +288 -0
  34. package/dist/connector/mcp/image-admission.js.map +1 -0
  35. package/dist/connector/mcp/stdio.d.ts +13 -0
  36. package/dist/connector/mcp/stdio.d.ts.map +1 -1
  37. package/dist/connector/mcp/stdio.js +66 -23
  38. package/dist/connector/mcp/stdio.js.map +1 -1
  39. package/dist/connector/mcp/streamable-http.d.ts.map +1 -1
  40. package/dist/connector/mcp/streamable-http.js +3 -0
  41. package/dist/connector/mcp/streamable-http.js.map +1 -1
  42. package/dist/constants/tools/index.js +1 -1
  43. package/dist/constants/tools/index.js.map +1 -1
  44. package/dist/directory/derive-supervisor.d.ts.map +1 -1
  45. package/dist/directory/derive-supervisor.js +5 -0
  46. package/dist/directory/derive-supervisor.js.map +1 -1
  47. package/dist/directory/derive.d.ts.map +1 -1
  48. package/dist/directory/derive.js +5 -0
  49. package/dist/directory/derive.js.map +1 -1
  50. package/dist/directory/load.d.ts.map +1 -1
  51. package/dist/directory/load.js +1 -0
  52. package/dist/directory/load.js.map +1 -1
  53. package/dist/directory/types.d.ts +2 -0
  54. package/dist/directory/types.d.ts.map +1 -1
  55. package/dist/execution/base.d.ts +13 -0
  56. package/dist/execution/base.d.ts.map +1 -1
  57. package/dist/execution/base.js +103 -8
  58. package/dist/execution/base.js.map +1 -1
  59. package/dist/execution/code-runtime/types.d.ts +11 -1
  60. package/dist/execution/code-runtime/types.d.ts.map +1 -1
  61. package/dist/execution/code-runtime/types.js.map +1 -1
  62. package/dist/execution/code-runtime/worker.d.ts.map +1 -1
  63. package/dist/execution/code-runtime/worker.js +67 -9
  64. package/dist/execution/code-runtime/worker.js.map +1 -1
  65. package/dist/execution/errors.d.ts +12 -0
  66. package/dist/execution/errors.d.ts.map +1 -0
  67. package/dist/execution/errors.js +21 -0
  68. package/dist/execution/errors.js.map +1 -0
  69. package/dist/execution/factory.d.ts.map +1 -1
  70. package/dist/execution/factory.js +1 -0
  71. package/dist/execution/factory.js.map +1 -1
  72. package/dist/execution/hybrid.d.ts +5 -0
  73. package/dist/execution/hybrid.d.ts.map +1 -1
  74. package/dist/execution/hybrid.js +36 -16
  75. package/dist/execution/hybrid.js.map +1 -1
  76. package/dist/execution/index.d.ts +1 -0
  77. package/dist/execution/index.d.ts.map +1 -1
  78. package/dist/execution/index.js +1 -0
  79. package/dist/execution/index.js.map +1 -1
  80. package/dist/execution/local.d.ts +13 -0
  81. package/dist/execution/local.d.ts.map +1 -1
  82. package/dist/execution/local.js +145 -19
  83. package/dist/execution/local.js.map +1 -1
  84. package/dist/execution/output.d.ts +27 -0
  85. package/dist/execution/output.d.ts.map +1 -0
  86. package/dist/execution/output.js +105 -0
  87. package/dist/execution/output.js.map +1 -0
  88. package/dist/execution/remote.d.ts +26 -2
  89. package/dist/execution/remote.d.ts.map +1 -1
  90. package/dist/execution/remote.js +86 -15
  91. package/dist/execution/remote.js.map +1 -1
  92. package/dist/manager/agent/lifecycle.d.ts.map +1 -1
  93. package/dist/manager/agent/lifecycle.js +1 -0
  94. package/dist/manager/agent/lifecycle.js.map +1 -1
  95. package/dist/plugin/lifecycle.d.ts.map +1 -1
  96. package/dist/plugin/lifecycle.js +9 -3
  97. package/dist/plugin/lifecycle.js.map +1 -1
  98. package/dist/process/kill-tree.d.ts +11 -13
  99. package/dist/process/kill-tree.d.ts.map +1 -1
  100. package/dist/process/kill-tree.js +11 -13
  101. package/dist/process/kill-tree.js.map +1 -1
  102. package/dist/provider/errors.d.ts +1 -0
  103. package/dist/provider/errors.d.ts.map +1 -1
  104. package/dist/provider/errors.js +39 -1
  105. package/dist/provider/errors.js.map +1 -1
  106. package/dist/provider/fallback.d.ts.map +1 -1
  107. package/dist/provider/fallback.js +31 -0
  108. package/dist/provider/fallback.js.map +1 -1
  109. package/dist/provider/idle-timeout.d.ts.map +1 -1
  110. package/dist/provider/idle-timeout.js +5 -0
  111. package/dist/provider/idle-timeout.js.map +1 -1
  112. package/dist/provider/retry.d.ts.map +1 -1
  113. package/dist/provider/retry.js +5 -0
  114. package/dist/provider/retry.js.map +1 -1
  115. package/dist/public-runtime.d.ts +7 -5
  116. package/dist/public-runtime.d.ts.map +1 -1
  117. package/dist/public-runtime.js +9 -4
  118. package/dist/public-runtime.js.map +1 -1
  119. package/dist/public-types.d.ts +2 -1
  120. package/dist/public-types.d.ts.map +1 -1
  121. package/dist/registry/tool/execute.d.ts +7 -1
  122. package/dist/registry/tool/execute.d.ts.map +1 -1
  123. package/dist/registry/tool/execute.js +201 -54
  124. package/dist/registry/tool/execute.js.map +1 -1
  125. package/dist/run/command-gate.d.ts.map +1 -1
  126. package/dist/run/command-gate.js +11 -0
  127. package/dist/run/command-gate.js.map +1 -1
  128. package/dist/run/reporter.d.ts.map +1 -1
  129. package/dist/run/reporter.js +6 -1
  130. package/dist/run/reporter.js.map +1 -1
  131. package/dist/run/workspace-fingerprint.d.ts +4 -4
  132. package/dist/run/workspace-fingerprint.d.ts.map +1 -1
  133. package/dist/run/workspace-fingerprint.js +6 -4
  134. package/dist/run/workspace-fingerprint.js.map +1 -1
  135. package/dist/runtime/bidi/index.d.ts +1 -1
  136. package/dist/runtime/bidi/index.d.ts.map +1 -1
  137. package/dist/runtime/bidi/index.js +1 -1
  138. package/dist/runtime/bidi/index.js.map +1 -1
  139. package/dist/runtime/bidi/session.d.ts +19 -0
  140. package/dist/runtime/bidi/session.d.ts.map +1 -1
  141. package/dist/runtime/bidi/session.js +150 -26
  142. package/dist/runtime/bidi/session.js.map +1 -1
  143. package/dist/runtime/query/executor.d.ts +43 -1
  144. package/dist/runtime/query/executor.d.ts.map +1 -1
  145. package/dist/runtime/query/executor.js +824 -174
  146. package/dist/runtime/query/executor.js.map +1 -1
  147. package/dist/runtime/query/index.d.ts +5 -0
  148. package/dist/runtime/query/index.d.ts.map +1 -1
  149. package/dist/runtime/query/index.js +47 -4
  150. package/dist/runtime/query/index.js.map +1 -1
  151. package/dist/runtime/query/iteration/index.d.ts +1 -0
  152. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  153. package/dist/runtime/query/iteration/index.js +34 -14
  154. package/dist/runtime/query/iteration/index.js.map +1 -1
  155. package/dist/runtime/query/iteration/phases/advisory.js +2 -2
  156. package/dist/runtime/query/iteration/phases/advisory.js.map +1 -1
  157. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  158. package/dist/runtime/query/iteration/phases/tool-review.js +84 -22
  159. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  160. package/dist/runtime/query/iteration/provider-rejected-image.d.ts +13 -0
  161. package/dist/runtime/query/iteration/provider-rejected-image.d.ts.map +1 -0
  162. package/dist/runtime/query/iteration/provider-rejected-image.js +91 -0
  163. package/dist/runtime/query/iteration/provider-rejected-image.js.map +1 -0
  164. package/dist/runtime/query/iteration/stream-turn.d.ts +4 -1
  165. package/dist/runtime/query/iteration/stream-turn.d.ts.map +1 -1
  166. package/dist/runtime/query/iteration/stream-turn.js +7 -3
  167. package/dist/runtime/query/iteration/stream-turn.js.map +1 -1
  168. package/dist/runtime/query/request-rich-content.d.ts +13 -0
  169. package/dist/runtime/query/request-rich-content.d.ts.map +1 -1
  170. package/dist/runtime/query/request-rich-content.js +173 -17
  171. package/dist/runtime/query/request-rich-content.js.map +1 -1
  172. package/dist/runtime/query/result.d.ts.map +1 -1
  173. package/dist/runtime/query/result.js +1 -0
  174. package/dist/runtime/query/result.js.map +1 -1
  175. package/dist/runtime/query/resume-pending.d.ts +5 -1
  176. package/dist/runtime/query/resume-pending.d.ts.map +1 -1
  177. package/dist/runtime/query/resume-pending.js +66 -1
  178. package/dist/runtime/query/resume-pending.js.map +1 -1
  179. package/dist/runtime/query/tool-output-budget.d.ts.map +1 -1
  180. package/dist/runtime/query/tool-output-budget.js +45 -16
  181. package/dist/runtime/query/tool-output-budget.js.map +1 -1
  182. package/dist/runtime/query/tooling.d.ts +6 -0
  183. package/dist/runtime/query/tooling.d.ts.map +1 -1
  184. package/dist/runtime/query/tooling.js +4 -0
  185. package/dist/runtime/query/tooling.js.map +1 -1
  186. package/dist/sandbox/provider/local.d.ts.map +1 -1
  187. package/dist/sandbox/provider/local.js +193 -41
  188. package/dist/sandbox/provider/local.js.map +1 -1
  189. package/dist/scheduler/delegating.d.ts +2 -1
  190. package/dist/scheduler/delegating.d.ts.map +1 -1
  191. package/dist/scheduler/delegating.js +6 -5
  192. package/dist/scheduler/delegating.js.map +1 -1
  193. package/dist/scheduler/local.d.ts +2 -1
  194. package/dist/scheduler/local.d.ts.map +1 -1
  195. package/dist/scheduler/local.js +2 -2
  196. package/dist/scheduler/local.js.map +1 -1
  197. package/dist/session/workspace/driver.d.ts +12 -4
  198. package/dist/session/workspace/driver.d.ts.map +1 -1
  199. package/dist/session/workspace/git-worktree.d.ts +17 -3
  200. package/dist/session/workspace/git-worktree.d.ts.map +1 -1
  201. package/dist/session/workspace/git-worktree.js +153 -34
  202. package/dist/session/workspace/git-worktree.js.map +1 -1
  203. package/dist/skills/registry.d.ts +15 -0
  204. package/dist/skills/registry.d.ts.map +1 -1
  205. package/dist/skills/registry.js +33 -0
  206. package/dist/skills/registry.js.map +1 -1
  207. package/dist/store/attachment/index.d.ts +24 -2
  208. package/dist/store/attachment/index.d.ts.map +1 -1
  209. package/dist/store/attachment/index.js +52 -5
  210. package/dist/store/attachment/index.js.map +1 -1
  211. package/dist/tools/builtins/computer-use.d.ts.map +1 -1
  212. package/dist/tools/builtins/computer-use.js +39 -2
  213. package/dist/tools/builtins/computer-use.js.map +1 -1
  214. package/dist/tools/builtins/lsp.d.ts +1 -1
  215. package/dist/tools/builtins/run-code.d.ts.map +1 -1
  216. package/dist/tools/builtins/run-code.js +24 -16
  217. package/dist/tools/builtins/run-code.js.map +1 -1
  218. package/dist/tools/builtins/skill.d.ts +2 -1
  219. package/dist/tools/builtins/skill.d.ts.map +1 -1
  220. package/dist/tools/builtins/skill.js +250 -6
  221. package/dist/tools/builtins/skill.js.map +1 -1
  222. package/dist/tools/coordinator/agent.d.ts.map +1 -1
  223. package/dist/tools/coordinator/agent.js +100 -30
  224. package/dist/tools/coordinator/agent.js.map +1 -1
  225. package/dist/types/agent/base.d.ts +4 -0
  226. package/dist/types/agent/base.d.ts.map +1 -1
  227. package/dist/types/agent/factory.d.ts +1 -0
  228. package/dist/types/agent/factory.d.ts.map +1 -1
  229. package/dist/types/agent/manager.d.ts +1 -1
  230. package/dist/types/agent/manager.d.ts.map +1 -1
  231. package/dist/types/agent/scheduler.d.ts +10 -1
  232. package/dist/types/agent/scheduler.d.ts.map +1 -1
  233. package/dist/types/authorization/index.d.ts +12 -12
  234. package/dist/types/bidi/index.d.ts +19 -2
  235. package/dist/types/bidi/index.d.ts.map +1 -1
  236. package/dist/types/computer-use/index.d.ts +18 -0
  237. package/dist/types/computer-use/index.d.ts.map +1 -1
  238. package/dist/types/connector/execution-context.d.ts +3 -1
  239. package/dist/types/connector/execution-context.d.ts.map +1 -1
  240. package/dist/types/execution/index.d.ts +43 -1
  241. package/dist/types/execution/index.d.ts.map +1 -1
  242. package/dist/types/hitl/index.d.ts +11 -0
  243. package/dist/types/hitl/index.d.ts.map +1 -1
  244. package/dist/types/hitl/index.js.map +1 -1
  245. package/dist/types/message/index.d.ts +31 -1
  246. package/dist/types/message/index.d.ts.map +1 -1
  247. package/dist/types/message/index.js +43 -0
  248. package/dist/types/message/index.js.map +1 -1
  249. package/dist/types/plugin/index.d.ts +14 -1
  250. package/dist/types/plugin/index.d.ts.map +1 -1
  251. package/dist/types/plugin/index.js +1 -0
  252. package/dist/types/plugin/index.js.map +1 -1
  253. package/dist/types/provider/error.d.ts +4 -1
  254. package/dist/types/provider/error.d.ts.map +1 -1
  255. package/dist/types/provider/interface.d.ts +14 -0
  256. package/dist/types/provider/interface.d.ts.map +1 -1
  257. package/dist/types/run/events.d.ts +10 -2
  258. package/dist/types/run/events.d.ts.map +1 -1
  259. package/dist/types/run/events.js.map +1 -1
  260. package/dist/types/sandbox/index.d.ts +15 -10
  261. package/dist/types/sandbox/index.d.ts.map +1 -1
  262. package/dist/types/sandbox/index.js.map +1 -1
  263. package/dist/types/tool/index.d.ts +129 -12
  264. package/dist/types/tool/index.d.ts.map +1 -1
  265. package/dist/types/tool/index.js.map +1 -1
  266. package/dist/types/workspace/ref.d.ts +5 -0
  267. package/dist/types/workspace/ref.d.ts.map +1 -1
  268. package/dist/utils/abort.d.ts +8 -0
  269. package/dist/utils/abort.d.ts.map +1 -1
  270. package/dist/utils/abort.js +16 -0
  271. package/dist/utils/abort.js.map +1 -1
  272. package/package.json +4 -4
  273. package/src/agents/ReactiveAgent.ts +4 -0
  274. package/src/agents/SupervisorAgent.ts +4 -0
  275. package/src/agents/runAgent.ts +8 -0
  276. package/src/authorization/gate.ts +1 -1
  277. package/src/connector/index.ts +2 -0
  278. package/src/connector/mcp/adapter.ts +82 -21
  279. package/src/connector/mcp/client.ts +2 -1
  280. package/src/connector/mcp/http-redirect.ts +32 -0
  281. package/src/connector/mcp/http-sse.ts +5 -0
  282. package/src/connector/mcp/image-admission.ts +272 -0
  283. package/src/connector/mcp/stdio.ts +63 -21
  284. package/src/connector/mcp/streamable-http.ts +3 -0
  285. package/src/constants/tools/index.ts +1 -1
  286. package/src/directory/derive-supervisor.ts +5 -0
  287. package/src/directory/derive.ts +5 -0
  288. package/src/directory/load.ts +1 -0
  289. package/src/directory/types.ts +2 -0
  290. package/src/execution/base.ts +124 -7
  291. package/src/execution/code-runtime/types.ts +15 -1
  292. package/src/execution/code-runtime/worker.ts +72 -9
  293. package/src/execution/errors.ts +24 -0
  294. package/src/execution/factory.ts +1 -0
  295. package/src/execution/hybrid.ts +47 -16
  296. package/src/execution/index.ts +1 -0
  297. package/src/execution/local.ts +164 -19
  298. package/src/execution/output.ts +104 -0
  299. package/src/execution/remote.ts +122 -17
  300. package/src/manager/agent/lifecycle.ts +1 -0
  301. package/src/plugin/lifecycle.ts +9 -3
  302. package/src/process/kill-tree.ts +11 -13
  303. package/src/provider/errors.ts +40 -1
  304. package/src/provider/fallback.ts +39 -0
  305. package/src/provider/idle-timeout.ts +8 -0
  306. package/src/provider/retry.ts +8 -0
  307. package/src/public-runtime.ts +23 -2
  308. package/src/public-types.ts +11 -0
  309. package/src/registry/tool/execute.ts +230 -64
  310. package/src/run/command-gate.ts +12 -0
  311. package/src/run/reporter.ts +7 -1
  312. package/src/run/workspace-fingerprint.ts +5 -4
  313. package/src/runtime/bidi/index.ts +1 -1
  314. package/src/runtime/bidi/session.ts +177 -28
  315. package/src/runtime/query/executor.ts +987 -172
  316. package/src/runtime/query/index.ts +59 -6
  317. package/src/runtime/query/iteration/index.ts +69 -29
  318. package/src/runtime/query/iteration/phases/advisory.ts +2 -2
  319. package/src/runtime/query/iteration/phases/tool-review.ts +87 -23
  320. package/src/runtime/query/iteration/provider-rejected-image.ts +106 -0
  321. package/src/runtime/query/iteration/stream-turn.ts +12 -2
  322. package/src/runtime/query/request-rich-content.ts +213 -15
  323. package/src/runtime/query/result.ts +1 -0
  324. package/src/runtime/query/resume-pending.ts +83 -1
  325. package/src/runtime/query/tool-output-budget.ts +52 -17
  326. package/src/runtime/query/tooling.ts +10 -0
  327. package/src/sandbox/provider/local.ts +213 -45
  328. package/src/scheduler/delegating.ts +6 -5
  329. package/src/scheduler/local.ts +3 -2
  330. package/src/session/workspace/driver.ts +12 -4
  331. package/src/session/workspace/git-worktree.ts +173 -34
  332. package/src/skills/registry.ts +47 -0
  333. package/src/store/attachment/index.ts +100 -15
  334. package/src/tools/builtins/computer-use.ts +45 -2
  335. package/src/tools/builtins/run-code.ts +24 -16
  336. package/src/tools/builtins/skill.ts +325 -7
  337. package/src/tools/coordinator/agent.ts +108 -33
  338. package/src/types/agent/base.ts +4 -0
  339. package/src/types/agent/factory.ts +1 -0
  340. package/src/types/agent/manager.ts +1 -1
  341. package/src/types/agent/scheduler.ts +10 -1
  342. package/src/types/bidi/index.ts +19 -2
  343. package/src/types/computer-use/index.ts +19 -0
  344. package/src/types/connector/execution-context.ts +3 -0
  345. package/src/types/execution/index.ts +46 -1
  346. package/src/types/hitl/index.ts +11 -0
  347. package/src/types/message/index.ts +78 -1
  348. package/src/types/plugin/index.ts +15 -0
  349. package/src/types/provider/error.ts +4 -1
  350. package/src/types/provider/interface.ts +18 -0
  351. package/src/types/run/events.ts +18 -4
  352. package/src/types/sandbox/index.ts +15 -10
  353. package/src/types/tool/index.ts +159 -15
  354. package/src/types/workspace/ref.ts +5 -0
  355. package/src/utils/abort.ts +18 -0
@@ -26,6 +26,32 @@ export interface ToolRegistryRef {
26
26
  * filesystem imports into every consumer's type graph.
27
27
  */
28
28
  export interface SkillRegistryRef {
29
+ /**
30
+ * Enumerate the metadata the model may use to discover a skill.
31
+ *
32
+ * Optional so an older structural registry that only supports named loads
33
+ * remains a valid host. `SkillTool` refuses its list mode when this member is
34
+ * absent: `names()` cannot distinguish a model skill from an operator-only
35
+ * one, so treating it as a safe catalog would disclose an authority boundary.
36
+ */
37
+ catalog?():
38
+ | readonly {
39
+ /** The name the registry accepts, which may be namespaced by its host. */
40
+ registeredName: string
41
+ description: string
42
+ location: string
43
+ allowedTools?: string
44
+ invocation?: 'model' | 'operator' | 'both'
45
+ }[]
46
+ | Promise<
47
+ readonly {
48
+ registeredName: string
49
+ description: string
50
+ location: string
51
+ allowedTools?: string
52
+ invocation?: 'model' | 'operator' | 'both'
53
+ }[]
54
+ >
29
55
  /**
30
56
  * Load a skill's full body, or `undefined` for a name nobody registered.
31
57
  *
@@ -68,7 +94,10 @@ export interface SkillRegistryRef {
68
94
  * outlives, or is billed to, somebody else's run.
69
95
  */
70
96
  export interface BackgroundJobRegistryRef {
71
- start(params: { command: string; workingDirectory: string }): { id: string; status: string }
97
+ start(params: { command: string; workingDirectory: string }): {
98
+ id: string
99
+ status: string
100
+ }
72
101
  get(id: string): { id: string; status: string; exitCode?: number }
73
102
  read(
74
103
  id: string,
@@ -158,6 +187,39 @@ export type ToolPauseOutcome =
158
187
 
159
188
  export type RequestToolPause = (request: ToolPauseRequest) => Promise<ToolPauseOutcome>
160
189
 
190
+ /**
191
+ * Where one tool execution entered the runtime from.
192
+ *
193
+ * The executor owns this value. A nested caller supplies only its private
194
+ * operation context to {@link ToolContext.dispatchTool}; the executor derives
195
+ * the parent id from the context it already issued, so a tool cannot relabel
196
+ * itself as somebody else's child.
197
+ */
198
+ export type ToolCallSource =
199
+ | { readonly kind: 'direct' }
200
+ | { readonly kind: 'nested'; readonly parentToolUseId: string }
201
+ | {
202
+ readonly kind: 'code'
203
+ readonly parentToolUseId: string
204
+ /** The code runtime's id, unique within the parent program. */
205
+ readonly runtimeToolCallId: string
206
+ }
207
+
208
+ /**
209
+ * Operation authority a trusted tool may narrow when it dispatches another
210
+ * tool.
211
+ *
212
+ * `signal` is fused with the parent call's signal; it can revoke authority
213
+ * earlier but can never extend the parent's lifetime. `runtimeToolCallId`
214
+ * identifies one request inside a model-authored program. The executor still
215
+ * chooses the child's event identity and the parent lineage; durable pause
216
+ * ownership stays with the model-issued ancestor present in the checkpoint.
217
+ */
218
+ export interface ToolDispatchOptions {
219
+ readonly signal?: AbortSignal
220
+ readonly runtimeToolCallId?: string
221
+ }
222
+
161
223
  export interface ToolContext {
162
224
  runId: RunId
163
225
  workingDirectory: string
@@ -242,7 +304,11 @@ export interface ToolContext {
242
304
  }>
243
305
  }
244
306
  readonly search?: {
245
- search(request: { query: string; limit?: number; signal?: AbortSignal }): Promise<{
307
+ search(request: {
308
+ query: string
309
+ limit?: number
310
+ signal?: AbortSignal
311
+ }): Promise<{
246
312
  query: string
247
313
  hits: readonly { title: string; url: string; snippet?: string }[]
248
314
  }>
@@ -257,7 +323,20 @@ export interface ToolContext {
257
323
  * the next batch — a skill loaded alongside other calls must not
258
324
  * retroactively refuse them.
259
325
  */
260
- adoptSkillScope?: (scope: { skill: string; allowedTools: readonly string[] }) => void
326
+ adoptSkillScope?: (scope: {
327
+ skill: string
328
+ allowedTools: readonly string[]
329
+ }) => void
330
+
331
+ /**
332
+ * Effective model-visible character cap for this tool result.
333
+ *
334
+ * Present on executor-owned calls so a tool that can paginate does so
335
+ * before the generic head+tail fallback loses its middle. `0` means the
336
+ * host disabled the cap; absent means a direct host invocation did not
337
+ * declare one.
338
+ */
339
+ maxToolOutputChars?: number
261
340
 
262
341
  /**
263
342
  * Run another tool through the same dispatch this call came through.
@@ -268,14 +347,23 @@ export interface ToolContext {
268
347
  * a property of holding a registry reference rather than a capability a
269
348
  * host wired deliberately.
270
349
  *
271
- * Available to every tool, which is worth being explicit about rather
272
- * than quietly true. Tools are host-installed code the model cannot add
273
- * one so the trust boundary this protects is the MODEL's reach, and
274
- * that is bounded where it has always been: `allowedTools` is enforced at
275
- * dispatch, so a tool calling through here reaches exactly what a
276
- * `tool_use` block would have.
350
+ * Available only for this invocation. The executor closes it when the
351
+ * visible call settles or is abandoned, aborts calls already started by
352
+ * it, and waits for their executor-owned terminal records before reporting
353
+ * the parent complete. Retaining the function does not retain authority.
354
+ *
355
+ * Tools are host-installed code — the model cannot add one — so the trust
356
+ * boundary this protects is the MODEL's reach. `allowedTools` is enforced
357
+ * again at dispatch. When the run has an operator authorization gate, a
358
+ * nested call must be explicitly allowed by that gate; a deny or an
359
+ * undecided call fails closed because another durable human review cannot
360
+ * be opened from inside the already-executing parent.
277
361
  */
278
- dispatchTool?: (name: string, input: unknown) => Promise<ToolResult>
362
+ dispatchTool?: (
363
+ name: string,
364
+ input: unknown,
365
+ options?: ToolDispatchOptions,
366
+ ) => Promise<ToolResult>
279
367
 
280
368
  /**
281
369
  * The `tool_use_id` of the assistant block that triggered this
@@ -287,6 +375,14 @@ export interface ToolContext {
287
375
  */
288
376
  toolUseId?: string
289
377
 
378
+ /**
379
+ * How this execution entered the tool registry.
380
+ *
381
+ * Present on executor-owned calls. Optional because a host may invoke a
382
+ * tool directly outside a run and construct its own minimal context.
383
+ */
384
+ source?: ToolCallSource
385
+
290
386
  /**
291
387
  * Raise a durable pause and wait for a human to resolve it.
292
388
  *
@@ -335,10 +431,16 @@ export interface ToolContext {
335
431
  * timed out.
336
432
  *
337
433
  * Fire-and-forget and never throws, so a tool can call it freely
338
- * without wrapping it. The model never sees these: progress answers
339
- * "is it still working?", which is a question only a human asks, and
340
- * putting it in the conversation would spend tokens telling the model
341
- * something it cannot act on.
434
+ * without wrapping it. This is latest state, not a log: while a host is
435
+ * consuming one update, later calls replace the single pending update.
436
+ * Each published message is capped at 8 KiB of UTF-8 with a visible
437
+ * omission marker, and every accepted update settles before that call's
438
+ * terminal event. Put complete output in `ToolResult`, not here.
439
+ *
440
+ * The model never sees these: progress answers "is it still working?",
441
+ * which is a question only a human asks, and putting it in the
442
+ * conversation would spend tokens telling the model something it cannot
443
+ * act on.
342
444
  *
343
445
  * Absent when the executing surface has no event stream to write to.
344
446
  */
@@ -587,6 +689,27 @@ export interface ToolExecutionResult extends ToolResult {
587
689
  permissionMessage?: string
588
690
  }
589
691
 
692
+ /**
693
+ * An input decoded exactly once by its owning tool registry.
694
+ *
695
+ * `input` is the detached, deeply frozen JSON review projection:
696
+ * authorization, approval UI, probes and audit all inspect this value. The
697
+ * registry privately retains a separate detached copy that
698
+ * {@link ToolRegistryContract.executePrepared} gives the tool. Caller-owned
699
+ * aliases therefore cannot change either side after preparation. A
700
+ * preparation is registry-owned and cannot be executed by a different
701
+ * registry or after that tool registration is replaced.
702
+ */
703
+ export interface PreparedToolExecution {
704
+ readonly toolName: string
705
+ readonly input: unknown
706
+ }
707
+
708
+ /** Result of decoding a tool input at the execution boundary. */
709
+ export type ToolPreparationResult =
710
+ | { readonly success: true; readonly prepared: PreparedToolExecution }
711
+ | { readonly success: false; readonly result: ToolExecutionResult }
712
+
590
713
  /**
591
714
  * Full tool registry contract — registration, lookup, execution, prompt generation.
592
715
  * Concrete implementation: `ToolRegistry` in `registry/tool/execute.ts`.
@@ -614,6 +737,23 @@ export interface ToolRegistryContract {
614
737
  searchDeferred(query: string): ToolDefinition[]
615
738
  getCallableTools(toolNames?: string[]): ToolDefinition[]
616
739
 
740
+ /**
741
+ * Decode/transform an input once, before authorization or human review.
742
+ *
743
+ * The returned preparation is opaque registry authority. Implementations
744
+ * must not run tool code here. They must detach both the executable value
745
+ * and `prepared.input` from caller/schema aliases, and make the latter a
746
+ * deeply immutable JSON projection of the exact value retained for
747
+ * execution. Unsupported mutable/exotic graphs fail closed.
748
+ */
749
+ prepareExecution(toolName: string, rawInput: unknown): ToolPreparationResult
750
+
751
+ /** Execute the exact value retained by `prepareExecution`, without parsing again. */
752
+ executePrepared(
753
+ prepared: PreparedToolExecution,
754
+ context: ToolContext,
755
+ ): Promise<ToolExecutionResult>
756
+
617
757
  execute(toolName: string, rawInput: unknown, context: ToolContext): Promise<ToolExecutionResult>
618
758
 
619
759
  size(): number
@@ -626,4 +766,8 @@ export interface ToolRegistryContract {
626
766
 
627
767
  export * from './repair.js'
628
768
 
629
- export type { ToolCallView, ToolPresentation, ToolResultView } from './presentation.js'
769
+ export type {
770
+ ToolCallView,
771
+ ToolPresentation,
772
+ ToolResultView,
773
+ } from './presentation.js'
@@ -49,6 +49,11 @@ export type WorkspaceBackendMeta = GitWorktreeBackendMeta
49
49
  * "which project is this directory" across sessions and process restarts.
50
50
  * The two words are close enough that the distinction has been rediscovered
51
51
  * more than once; it is written here so it does not have to be again.
52
+ *
53
+ * A persisted ref is recovery data for the backend configuration that created
54
+ * it, not authority for another driver instance to operate on an arbitrary
55
+ * resource. Reference drivers validate that affiliation before inspection,
56
+ * branching, or disposal.
52
57
  */
53
58
  export interface WorkspaceRef {
54
59
  id: WorkspaceId
@@ -1,3 +1,4 @@
1
+ import { EventEmitter } from 'node:events'
1
2
  import { toErrorMessage } from './error.js'
2
3
 
3
4
  /**
@@ -47,6 +48,23 @@ export function abortReasonText(reason: unknown): string | undefined {
47
48
  return text.length > 0 ? text : undefined
48
49
  }
49
50
 
51
+ /**
52
+ * Subscribe to caller cancellation without raising the Node 20.0 runtime floor.
53
+ *
54
+ * `addAbortListener` cannot be hidden by another listener calling
55
+ * `stopImmediatePropagation`. Both branches return an explicit disposer so a
56
+ * completed operation does not remain attached to a long-lived caller signal.
57
+ */
58
+ export function subscribeToAbort(signal: AbortSignal, listener: () => void): () => void {
59
+ if (typeof EventEmitter.addAbortListener === 'function') {
60
+ const subscription = EventEmitter.addAbortListener(signal, listener)
61
+ return () => subscription[Symbol.dispose]()
62
+ }
63
+
64
+ signal.addEventListener('abort', listener, { once: true })
65
+ return () => signal.removeEventListener('abort', listener)
66
+ }
67
+
50
68
  export function createChildAbortController(parent: AbortController): AbortController {
51
69
  const child = new AbortController()
52
70