@namzu/sdk 72.0.0 → 74.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 (394) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +34 -34
  3. package/dist/agents/examples/SupervisorAgent.d.ts.map +1 -1
  4. package/dist/agents/examples/SupervisorAgent.js +5 -0
  5. package/dist/agents/examples/SupervisorAgent.js.map +1 -1
  6. package/dist/authorization/protected-paths.d.ts +7 -0
  7. package/dist/authorization/protected-paths.d.ts.map +1 -1
  8. package/dist/authorization/protected-paths.js +11 -0
  9. package/dist/authorization/protected-paths.js.map +1 -1
  10. package/dist/authorization/readonly-commands.d.ts +23 -0
  11. package/dist/authorization/readonly-commands.d.ts.map +1 -1
  12. package/dist/authorization/readonly-commands.js +89 -3
  13. package/dist/authorization/readonly-commands.js.map +1 -1
  14. package/dist/authorization/shell-paths.d.ts +8 -0
  15. package/dist/authorization/shell-paths.d.ts.map +1 -1
  16. package/dist/authorization/shell-paths.js +125 -2
  17. package/dist/authorization/shell-paths.js.map +1 -1
  18. package/dist/bridge/acp/permission.d.ts +6 -0
  19. package/dist/bridge/acp/permission.d.ts.map +1 -1
  20. package/dist/bridge/acp/permission.js.map +1 -1
  21. package/dist/bridge/acp/server.d.ts.map +1 -1
  22. package/dist/bridge/acp/server.js +21 -3
  23. package/dist/bridge/acp/server.js.map +1 -1
  24. package/dist/compaction/context-window.d.ts.map +1 -1
  25. package/dist/compaction/context-window.js +11 -0
  26. package/dist/compaction/context-window.js.map +1 -1
  27. package/dist/compaction/manual.d.ts +16 -1
  28. package/dist/compaction/manual.d.ts.map +1 -1
  29. package/dist/compaction/manual.js +75 -13
  30. package/dist/compaction/manual.js.map +1 -1
  31. package/dist/compaction/plan.d.ts +2 -1
  32. package/dist/compaction/plan.d.ts.map +1 -1
  33. package/dist/compaction/plan.js +6 -5
  34. package/dist/compaction/plan.js.map +1 -1
  35. package/dist/compaction/precompute.d.ts +179 -0
  36. package/dist/compaction/precompute.d.ts.map +1 -0
  37. package/dist/compaction/precompute.js +274 -0
  38. package/dist/compaction/precompute.js.map +1 -0
  39. package/dist/compaction/retained-images.d.ts +16 -0
  40. package/dist/compaction/retained-images.d.ts.map +1 -0
  41. package/dist/compaction/retained-images.js +113 -0
  42. package/dist/compaction/retained-images.js.map +1 -0
  43. package/dist/compaction/token-estimate.d.ts +8 -3
  44. package/dist/compaction/token-estimate.d.ts.map +1 -1
  45. package/dist/compaction/token-estimate.js +76 -8
  46. package/dist/compaction/token-estimate.js.map +1 -1
  47. package/dist/compaction/tool-result-editing.d.ts.map +1 -1
  48. package/dist/compaction/tool-result-editing.js +15 -8
  49. package/dist/compaction/tool-result-editing.js.map +1 -1
  50. package/dist/config/runtime.d.ts +4 -0
  51. package/dist/config/runtime.d.ts.map +1 -1
  52. package/dist/config/runtime.js +17 -0
  53. package/dist/config/runtime.js.map +1 -1
  54. package/dist/constants/acp/index.d.ts +2 -0
  55. package/dist/constants/acp/index.d.ts.map +1 -1
  56. package/dist/constants/acp/index.js +2 -0
  57. package/dist/constants/acp/index.js.map +1 -1
  58. package/dist/manager/agent/lifecycle.d.ts.map +1 -1
  59. package/dist/manager/agent/lifecycle.js +8 -0
  60. package/dist/manager/agent/lifecycle.js.map +1 -1
  61. package/dist/manager/session/turn-recorder.d.ts +26 -0
  62. package/dist/manager/session/turn-recorder.d.ts.map +1 -1
  63. package/dist/manager/session/turn-recorder.js +72 -5
  64. package/dist/manager/session/turn-recorder.js.map +1 -1
  65. package/dist/peers/protocol.d.ts +9 -0
  66. package/dist/peers/protocol.d.ts.map +1 -1
  67. package/dist/peers/protocol.js +4 -0
  68. package/dist/peers/protocol.js.map +1 -1
  69. package/dist/peers/record.d.ts +6 -0
  70. package/dist/peers/record.d.ts.map +1 -1
  71. package/dist/peers/record.js +4 -0
  72. package/dist/peers/record.js.map +1 -1
  73. package/dist/plugin/index.d.ts +2 -2
  74. package/dist/plugin/index.d.ts.map +1 -1
  75. package/dist/plugin/index.js +1 -1
  76. package/dist/plugin/index.js.map +1 -1
  77. package/dist/plugin/shell-hook.d.ts +30 -0
  78. package/dist/plugin/shell-hook.d.ts.map +1 -1
  79. package/dist/plugin/shell-hook.js +35 -0
  80. package/dist/plugin/shell-hook.js.map +1 -1
  81. package/dist/pricing/catalogue.generated.d.ts.map +1 -1
  82. package/dist/pricing/catalogue.generated.js +178 -1
  83. package/dist/pricing/catalogue.generated.js.map +1 -1
  84. package/dist/provider/attribution.js +1 -1
  85. package/dist/provider/attribution.js.map +1 -1
  86. package/dist/public-runtime.d.ts +9 -5
  87. package/dist/public-runtime.d.ts.map +1 -1
  88. package/dist/public-runtime.js +12 -4
  89. package/dist/public-runtime.js.map +1 -1
  90. package/dist/public-tools.d.ts +1 -1
  91. package/dist/public-tools.d.ts.map +1 -1
  92. package/dist/public-tools.js +1 -1
  93. package/dist/public-tools.js.map +1 -1
  94. package/dist/public-types.d.ts +3 -2
  95. package/dist/public-types.d.ts.map +1 -1
  96. package/dist/rag/embedding.d.ts +5 -1
  97. package/dist/rag/embedding.d.ts.map +1 -1
  98. package/dist/rag/embedding.js +22 -7
  99. package/dist/rag/embedding.js.map +1 -1
  100. package/dist/registry/command/kernel-commands.d.ts +7 -1
  101. package/dist/registry/command/kernel-commands.d.ts.map +1 -1
  102. package/dist/registry/command/kernel-commands.js +40 -2
  103. package/dist/registry/command/kernel-commands.js.map +1 -1
  104. package/dist/registry/tool/execute.d.ts +8 -0
  105. package/dist/registry/tool/execute.d.ts.map +1 -1
  106. package/dist/registry/tool/execute.js +12 -0
  107. package/dist/registry/tool/execute.js.map +1 -1
  108. package/dist/runtime/query/abandon-turn.d.ts.map +1 -1
  109. package/dist/runtime/query/abandon-turn.js +9 -0
  110. package/dist/runtime/query/abandon-turn.js.map +1 -1
  111. package/dist/runtime/query/budget-nudge.d.ts +27 -0
  112. package/dist/runtime/query/budget-nudge.d.ts.map +1 -0
  113. package/dist/runtime/query/budget-nudge.js +66 -0
  114. package/dist/runtime/query/budget-nudge.js.map +1 -0
  115. package/dist/runtime/query/compact-session.d.ts +19 -3
  116. package/dist/runtime/query/compact-session.d.ts.map +1 -1
  117. package/dist/runtime/query/compact-session.js +180 -93
  118. package/dist/runtime/query/compact-session.js.map +1 -1
  119. package/dist/runtime/query/guard.d.ts +8 -0
  120. package/dist/runtime/query/guard.d.ts.map +1 -1
  121. package/dist/runtime/query/guard.js +20 -0
  122. package/dist/runtime/query/guard.js.map +1 -1
  123. package/dist/runtime/query/index.d.ts.map +1 -1
  124. package/dist/runtime/query/index.js +1 -0
  125. package/dist/runtime/query/index.js.map +1 -1
  126. package/dist/runtime/query/iteration/index.d.ts +2 -0
  127. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  128. package/dist/runtime/query/iteration/index.js +41 -1
  129. package/dist/runtime/query/iteration/index.js.map +1 -1
  130. package/dist/runtime/query/iteration/phases/compaction.d.ts +1 -0
  131. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  132. package/dist/runtime/query/iteration/phases/compaction.js +203 -45
  133. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  134. package/dist/runtime/query/iteration/phases/context.d.ts +2 -0
  135. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  136. package/dist/runtime/query/iteration/phases/context.js +1 -0
  137. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  138. package/dist/runtime/query/iteration/phases/precompute.d.ts +60 -0
  139. package/dist/runtime/query/iteration/phases/precompute.d.ts.map +1 -0
  140. package/dist/runtime/query/iteration/phases/precompute.js +240 -0
  141. package/dist/runtime/query/iteration/phases/precompute.js.map +1 -0
  142. package/dist/runtime/query/iteration/request-prefix.d.ts +21 -0
  143. package/dist/runtime/query/iteration/request-prefix.d.ts.map +1 -0
  144. package/dist/runtime/query/iteration/request-prefix.js +111 -0
  145. package/dist/runtime/query/iteration/request-prefix.js.map +1 -0
  146. package/dist/runtime/query/review-policy.d.ts +11 -3
  147. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  148. package/dist/runtime/query/review-policy.js +54 -3
  149. package/dist/runtime/query/review-policy.js.map +1 -1
  150. package/dist/runtime/query/turn/outcome-ledger.d.ts +14 -0
  151. package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
  152. package/dist/runtime/query/turn/outcome-ledger.js +28 -0
  153. package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
  154. package/dist/sandbox/exec-stdin.d.ts +21 -0
  155. package/dist/sandbox/exec-stdin.d.ts.map +1 -0
  156. package/dist/sandbox/exec-stdin.js +40 -0
  157. package/dist/sandbox/exec-stdin.js.map +1 -0
  158. package/dist/sandbox/file-walk.d.ts +12 -7
  159. package/dist/sandbox/file-walk.d.ts.map +1 -1
  160. package/dist/sandbox/file-walk.js +13 -4
  161. package/dist/sandbox/file-walk.js.map +1 -1
  162. package/dist/sandbox/ignore-matcher.d.ts +1 -0
  163. package/dist/sandbox/ignore-matcher.d.ts.map +1 -1
  164. package/dist/sandbox/ignore-matcher.js.map +1 -1
  165. package/dist/sandbox/ignore-source.js +1 -1
  166. package/dist/sandbox/index.d.ts +3 -2
  167. package/dist/sandbox/index.d.ts.map +1 -1
  168. package/dist/sandbox/index.js +2 -1
  169. package/dist/sandbox/index.js.map +1 -1
  170. package/dist/sandbox/provider/local.d.ts.map +1 -1
  171. package/dist/sandbox/provider/local.js +2 -0
  172. package/dist/sandbox/provider/local.js.map +1 -1
  173. package/dist/session/paths.d.ts +6 -0
  174. package/dist/session/paths.d.ts.map +1 -1
  175. package/dist/session/paths.js +7 -0
  176. package/dist/session/paths.js.map +1 -1
  177. package/dist/session-query/index.d.ts +1 -0
  178. package/dist/session-query/index.d.ts.map +1 -1
  179. package/dist/session-query/index.js +26 -15
  180. package/dist/session-query/index.js.map +1 -1
  181. package/dist/store/evidence/disk.js +3 -1
  182. package/dist/store/evidence/disk.js.map +1 -1
  183. package/dist/store/evidence/index-page.d.ts +1 -0
  184. package/dist/store/evidence/index-page.d.ts.map +1 -1
  185. package/dist/store/evidence/index-page.js +8 -0
  186. package/dist/store/evidence/index-page.js.map +1 -1
  187. package/dist/store/goal/gates.d.ts +53 -0
  188. package/dist/store/goal/gates.d.ts.map +1 -0
  189. package/dist/store/goal/gates.js +664 -0
  190. package/dist/store/goal/gates.js.map +1 -0
  191. package/dist/store/goal/index.d.ts +16 -1
  192. package/dist/store/goal/index.d.ts.map +1 -1
  193. package/dist/store/goal/index.js +74 -0
  194. package/dist/store/goal/index.js.map +1 -1
  195. package/dist/store/memory/operation-lock.d.ts.map +1 -1
  196. package/dist/store/memory/operation-lock.js +15 -1
  197. package/dist/store/memory/operation-lock.js.map +1 -1
  198. package/dist/store/session-log/core.d.ts.map +1 -1
  199. package/dist/store/session-log/core.js +23 -0
  200. package/dist/store/session-log/core.js.map +1 -1
  201. package/dist/tools/builtins/bash.js +1 -1
  202. package/dist/tools/builtins/bash.js.map +1 -1
  203. package/dist/tools/builtins/browser.d.ts.map +1 -1
  204. package/dist/tools/builtins/browser.js +2 -0
  205. package/dist/tools/builtins/browser.js.map +1 -1
  206. package/dist/tools/builtins/computer-use-image.d.ts +9 -0
  207. package/dist/tools/builtins/computer-use-image.d.ts.map +1 -1
  208. package/dist/tools/builtins/computer-use-image.js +21 -0
  209. package/dist/tools/builtins/computer-use-image.js.map +1 -1
  210. package/dist/tools/builtins/computer-use.d.ts +1 -9
  211. package/dist/tools/builtins/computer-use.d.ts.map +1 -1
  212. package/dist/tools/builtins/computer-use.js +2 -22
  213. package/dist/tools/builtins/computer-use.js.map +1 -1
  214. package/dist/tools/builtins/monitor.d.ts.map +1 -1
  215. package/dist/tools/builtins/monitor.js +1 -0
  216. package/dist/tools/builtins/monitor.js.map +1 -1
  217. package/dist/tools/builtins/search-tools.js +2 -2
  218. package/dist/tools/builtins/search-tools.js.map +1 -1
  219. package/dist/tools/builtins/sleep-guard.js +1 -1
  220. package/dist/tools/builtins/sleep-guard.js.map +1 -1
  221. package/dist/tools/builtins/wait-for-job.js +1 -1
  222. package/dist/tools/builtins/wait-for-job.js.map +1 -1
  223. package/dist/tools/coordinator/ask-user-question.d.ts.map +1 -1
  224. package/dist/tools/coordinator/ask-user-question.js +25 -0
  225. package/dist/tools/coordinator/ask-user-question.js.map +1 -1
  226. package/dist/tools/coordinator/index.d.ts.map +1 -1
  227. package/dist/tools/coordinator/index.js +3 -0
  228. package/dist/tools/coordinator/index.js.map +1 -1
  229. package/dist/tools/defineTool.d.ts +2 -0
  230. package/dist/tools/defineTool.d.ts.map +1 -1
  231. package/dist/tools/defineTool.js +3 -0
  232. package/dist/tools/defineTool.js.map +1 -1
  233. package/dist/tools/goal/confirmation.d.ts +40 -2
  234. package/dist/tools/goal/confirmation.d.ts.map +1 -1
  235. package/dist/tools/goal/confirmation.js +117 -0
  236. package/dist/tools/goal/confirmation.js.map +1 -1
  237. package/dist/tools/goal/index.d.ts.map +1 -1
  238. package/dist/tools/goal/index.js +14 -2
  239. package/dist/tools/goal/index.js.map +1 -1
  240. package/dist/tools/memory/save.d.ts.map +1 -1
  241. package/dist/tools/memory/save.js +1 -0
  242. package/dist/tools/memory/save.js.map +1 -1
  243. package/dist/tools/schedules/index.d.ts +1 -0
  244. package/dist/tools/schedules/index.d.ts.map +1 -1
  245. package/dist/tools/schedules/index.js +1 -0
  246. package/dist/tools/schedules/index.js.map +1 -1
  247. package/dist/tools/schedules/loop-tool.d.ts.map +1 -1
  248. package/dist/tools/schedules/loop-tool.js +1 -0
  249. package/dist/tools/schedules/loop-tool.js.map +1 -1
  250. package/dist/tools/schedules/present.d.ts.map +1 -1
  251. package/dist/tools/schedules/present.js +2 -0
  252. package/dist/tools/schedules/present.js.map +1 -1
  253. package/dist/tools/schedules/schedule-tool.d.ts.map +1 -1
  254. package/dist/tools/schedules/schedule-tool.js +79 -9
  255. package/dist/tools/schedules/schedule-tool.js.map +1 -1
  256. package/dist/tools/schedules/self-tool.d.ts +16 -0
  257. package/dist/tools/schedules/self-tool.d.ts.map +1 -0
  258. package/dist/tools/schedules/self-tool.js +140 -0
  259. package/dist/tools/schedules/self-tool.js.map +1 -0
  260. package/dist/tools/schedules/timer-tools.d.ts.map +1 -1
  261. package/dist/tools/schedules/timer-tools.js +1 -0
  262. package/dist/tools/schedules/timer-tools.js.map +1 -1
  263. package/dist/tools/schedules/types.d.ts +63 -0
  264. package/dist/tools/schedules/types.d.ts.map +1 -1
  265. package/dist/toolsets/manager.d.ts +14 -0
  266. package/dist/toolsets/manager.d.ts.map +1 -1
  267. package/dist/toolsets/manager.js +60 -7
  268. package/dist/toolsets/manager.js.map +1 -1
  269. package/dist/types/agent/supervisor.d.ts +10 -0
  270. package/dist/types/agent/supervisor.d.ts.map +1 -1
  271. package/dist/types/agent/task.d.ts +6 -0
  272. package/dist/types/agent/task.d.ts.map +1 -1
  273. package/dist/types/common/index.d.ts +20 -0
  274. package/dist/types/common/index.d.ts.map +1 -1
  275. package/dist/types/common/index.js +4 -1
  276. package/dist/types/common/index.js.map +1 -1
  277. package/dist/types/goal/index.d.ts +66 -0
  278. package/dist/types/goal/index.d.ts.map +1 -1
  279. package/dist/types/hitl/index.d.ts +11 -0
  280. package/dist/types/hitl/index.d.ts.map +1 -1
  281. package/dist/types/hitl/index.js.map +1 -1
  282. package/dist/types/rag/embedding.d.ts +4 -0
  283. package/dist/types/rag/embedding.d.ts.map +1 -1
  284. package/dist/types/sandbox/index.d.ts +19 -0
  285. package/dist/types/sandbox/index.d.ts.map +1 -1
  286. package/dist/types/sandbox/index.js.map +1 -1
  287. package/dist/types/session/events.d.ts +55 -0
  288. package/dist/types/session/events.d.ts.map +1 -1
  289. package/dist/types/session/events.js.map +1 -1
  290. package/dist/types/session/outcome.d.ts +12 -0
  291. package/dist/types/session/outcome.d.ts.map +1 -1
  292. package/dist/types/session/outcome.js.map +1 -1
  293. package/dist/types/session/records.d.ts +81 -1
  294. package/dist/types/session/records.d.ts.map +1 -1
  295. package/dist/types/session/records.js +33 -0
  296. package/dist/types/session/records.js.map +1 -1
  297. package/dist/types/tool/index.d.ts +7 -0
  298. package/dist/types/tool/index.d.ts.map +1 -1
  299. package/dist/types/tool/index.js.map +1 -1
  300. package/dist/utils/cost.d.ts +15 -0
  301. package/dist/utils/cost.d.ts.map +1 -1
  302. package/dist/utils/cost.js +24 -1
  303. package/dist/utils/cost.js.map +1 -1
  304. package/package.json +2 -2
  305. package/src/agents/examples/SupervisorAgent.ts +5 -0
  306. package/src/authorization/protected-paths.ts +11 -0
  307. package/src/authorization/readonly-commands.ts +85 -3
  308. package/src/authorization/shell-paths.ts +141 -3
  309. package/src/bridge/acp/permission.ts +6 -0
  310. package/src/bridge/acp/server.ts +20 -1
  311. package/src/compaction/context-window.ts +11 -0
  312. package/src/compaction/manual.ts +103 -17
  313. package/src/compaction/plan.ts +11 -5
  314. package/src/compaction/precompute.ts +390 -0
  315. package/src/compaction/retained-images.ts +130 -0
  316. package/src/compaction/token-estimate.ts +86 -8
  317. package/src/compaction/tool-result-editing.ts +20 -8
  318. package/src/config/runtime.ts +17 -0
  319. package/src/constants/acp/index.ts +2 -0
  320. package/src/manager/agent/lifecycle.ts +9 -0
  321. package/src/manager/session/turn-recorder.ts +92 -5
  322. package/src/peers/protocol.ts +4 -0
  323. package/src/peers/record.ts +4 -0
  324. package/src/plugin/index.ts +2 -0
  325. package/src/plugin/shell-hook.ts +60 -0
  326. package/src/pricing/catalogue.generated.ts +178 -1
  327. package/src/pricing/rates.source.json +155 -2
  328. package/src/provider/attribution.ts +1 -1
  329. package/src/public-runtime.ts +48 -0
  330. package/src/public-tools.ts +2 -0
  331. package/src/public-types.ts +8 -0
  332. package/src/rag/embedding.ts +23 -7
  333. package/src/registry/command/kernel-commands.ts +62 -3
  334. package/src/registry/tool/execute.ts +14 -0
  335. package/src/runtime/query/abandon-turn.ts +9 -0
  336. package/src/runtime/query/budget-nudge.ts +92 -0
  337. package/src/runtime/query/compact-session.ts +242 -87
  338. package/src/runtime/query/guard.ts +22 -0
  339. package/src/runtime/query/index.ts +1 -0
  340. package/src/runtime/query/iteration/index.ts +40 -1
  341. package/src/runtime/query/iteration/phases/compaction.ts +224 -46
  342. package/src/runtime/query/iteration/phases/context.ts +3 -0
  343. package/src/runtime/query/iteration/phases/precompute.ts +277 -0
  344. package/src/runtime/query/iteration/request-prefix.ts +161 -0
  345. package/src/runtime/query/review-policy.ts +79 -11
  346. package/src/runtime/query/turn/outcome-ledger.ts +34 -0
  347. package/src/sandbox/exec-stdin.ts +54 -0
  348. package/src/sandbox/file-walk.ts +25 -18
  349. package/src/sandbox/ignore-matcher.ts +1 -0
  350. package/src/sandbox/ignore-source.ts +1 -1
  351. package/src/sandbox/index.ts +8 -2
  352. package/src/sandbox/provider/local.ts +2 -0
  353. package/src/session/paths.ts +9 -0
  354. package/src/session-query/index.ts +23 -14
  355. package/src/store/evidence/disk.ts +3 -1
  356. package/src/store/evidence/index-page.ts +11 -0
  357. package/src/store/goal/gates.ts +738 -0
  358. package/src/store/goal/index.ts +109 -0
  359. package/src/store/memory/operation-lock.ts +19 -1
  360. package/src/store/session-log/core.ts +26 -0
  361. package/src/tools/builtins/bash.ts +1 -1
  362. package/src/tools/builtins/browser.ts +4 -0
  363. package/src/tools/builtins/computer-use-image.ts +20 -0
  364. package/src/tools/builtins/computer-use.ts +1 -20
  365. package/src/tools/builtins/monitor.ts +2 -0
  366. package/src/tools/builtins/search-tools.ts +2 -2
  367. package/src/tools/builtins/sleep-guard.ts +1 -1
  368. package/src/tools/builtins/wait-for-job.ts +1 -1
  369. package/src/tools/coordinator/ask-user-question.ts +37 -10
  370. package/src/tools/coordinator/index.ts +3 -0
  371. package/src/tools/defineTool.ts +5 -0
  372. package/src/tools/goal/confirmation.ts +171 -3
  373. package/src/tools/goal/index.ts +15 -3
  374. package/src/tools/memory/save.ts +2 -0
  375. package/src/tools/schedules/index.ts +1 -0
  376. package/src/tools/schedules/loop-tool.ts +2 -0
  377. package/src/tools/schedules/present.ts +2 -0
  378. package/src/tools/schedules/schedule-tool.ts +84 -9
  379. package/src/tools/schedules/self-tool.ts +152 -0
  380. package/src/tools/schedules/timer-tools.ts +2 -0
  381. package/src/tools/schedules/types.ts +62 -0
  382. package/src/toolsets/manager.ts +59 -8
  383. package/src/types/agent/supervisor.ts +11 -0
  384. package/src/types/agent/task.ts +7 -0
  385. package/src/types/common/index.ts +26 -1
  386. package/src/types/goal/index.ts +72 -0
  387. package/src/types/hitl/index.ts +11 -0
  388. package/src/types/rag/embedding.ts +7 -0
  389. package/src/types/sandbox/index.ts +19 -0
  390. package/src/types/session/events.ts +56 -0
  391. package/src/types/session/outcome.ts +16 -1
  392. package/src/types/session/records.ts +41 -0
  393. package/src/types/tool/index.ts +7 -0
  394. package/src/utils/cost.ts +44 -1
@@ -4,6 +4,8 @@ import { TenantIsolationError } from '../../session/errors.js'
4
4
  import type {
5
5
  GoalBlockReason,
6
6
  GoalConfirmedBy,
7
+ GoalGateRoundReport,
8
+ GoalGatesSpec,
7
9
  GoalGuards,
8
10
  GoalPhase,
9
11
  GoalRef,
@@ -21,6 +23,14 @@ import {
21
23
  revisionFileSegment,
22
24
  } from '../kv/revision-record-store.js'
23
25
  import { defineSchema } from '../schema.js'
26
+ import {
27
+ GOAL_GATES_BLOCK_CODE,
28
+ GOAL_GATE_MAX_TAIL_CHARS,
29
+ goalGateFailedNames,
30
+ goalGateTail,
31
+ goalGatesBlockSentence,
32
+ goalGatesFrom,
33
+ } from './gates.js'
24
34
 
25
35
  /** Current source-backed limit for a human goal objective. */
26
36
  export const MAX_GOAL_OBJECTIVE_CHARS = 4_000
@@ -47,6 +57,12 @@ export interface CreateSessionGoalParams {
47
57
  readonly guards?: GoalGuards
48
58
  /** Set only when this goal chooses; absent leaves the choice to the host's setting. */
49
59
  readonly confirmedBy?: GoalConfirmedBy
60
+ /**
61
+ * Commands the host runs at the end of each round; the goal completes only
62
+ * when they all pass. Checked here (see `parseGoalGateEntry`) and fixed for the
63
+ * life of the goal.
64
+ */
65
+ readonly gates?: GoalGatesSpec
50
66
  }
51
67
 
52
68
  export interface EditSessionGoalParams {
@@ -94,6 +110,19 @@ export interface SessionGoalStore {
94
110
  goalId: GoalId,
95
111
  outcome: GoalRoundOutcome,
96
112
  ): Promise<SessionGoal | null>
113
+ /**
114
+ * Write down what the gates showed when a round ended: the last result of
115
+ * each, and, once per admitted round, whether the round ended with a failing
116
+ * gate. The goal is blocked (`gates-failing`) when that many rounds in a row
117
+ * did, which is the cap on retries. A goal without gates, or a store written
118
+ * before this existed, returns `null` or lacks the method.
119
+ */
120
+ recordGateRound?(
121
+ sessionId: SessionId,
122
+ tenantId: TenantId,
123
+ goalId: GoalId,
124
+ report: GoalGateRoundReport,
125
+ ): Promise<SessionGoal | null>
97
126
  }
98
127
 
99
128
  /** What a resume may raise so that a goal stopped by a limit can go on. */
@@ -309,6 +338,14 @@ function goalGuards(value: GoalGuards | undefined): GoalGuards | undefined {
309
338
  return Object.keys(guards).length > 0 ? guards : undefined
310
339
  }
311
340
 
341
+ /** The authority's view of the gates that did not pass: what leads the next round. */
342
+ function failuresOf(
343
+ goal: SessionGoal,
344
+ ): Pick<GoalRoundAuthority, 'gateFailures'> | Record<string, never> {
345
+ const failing = goal.gates?.results.filter((result) => result.status !== 'passed') ?? []
346
+ return failing.length > 0 ? { gateFailures: failing } : {}
347
+ }
348
+
312
349
  function blockReason(value: GoalBlockReason): GoalBlockReason {
313
350
  if (
314
351
  typeof value?.code !== 'string' ||
@@ -384,6 +421,7 @@ abstract class SessionGoalStoreBase implements SessionGoalStore {
384
421
  const text = objective(params.objective)
385
422
  const maxRounds = maxGoalRounds(params.maxGoalRounds)
386
423
  const guards = goalGuards(params.guards)
424
+ const gates = goalGatesFrom(params.gates)
387
425
  if (
388
426
  params.confirmedBy !== undefined &&
389
427
  params.confirmedBy !== 'model' &&
@@ -410,6 +448,7 @@ abstract class SessionGoalStoreBase implements SessionGoalStore {
410
448
  roundsAdmitted: 0,
411
449
  ...(guards !== undefined ? { guards } : {}),
412
450
  ...(params.confirmedBy !== undefined ? { confirmedBy: params.confirmedBy } : {}),
451
+ ...(gates !== undefined ? { gates } : {}),
413
452
  createdAt: now,
414
453
  updatedAt: now,
415
454
  }
@@ -491,9 +530,18 @@ abstract class SessionGoalStoreBase implements SessionGoalStore {
491
530
  filled?.checkInEvery !== undefined &&
492
531
  filled.checkInEvery > 0 &&
493
532
  filled.checkInEvery !== goal.guards?.checkInEvery
533
+ // A resume gives the gates their retries back; their last results stay, so a
534
+ // gate that failed on these files is still not run again until they change.
535
+ const gates = goal.gates
536
+ ? (() => {
537
+ const { countedRound: _counted, ...kept } = goal.gates
538
+ return { ...kept, failingRounds: 0 }
539
+ })()
540
+ : undefined
494
541
  return {
495
542
  ...rest,
496
543
  phase: 'active',
544
+ ...(gates !== undefined ? { gates } : {}),
497
545
  ...(newCheckIn ? { checkedInAtRound: goal.roundsAdmitted } : {}),
498
546
  maxGoalRounds:
499
547
  raisedRounds !== undefined && raisedRounds > goal.maxGoalRounds
@@ -603,6 +651,7 @@ abstract class SessionGoalStoreBase implements SessionGoalStore {
603
651
  ...(goal.costUsd !== undefined ? { costUsd: goal.costUsd } : {}),
604
652
  ...(overBudget ? { wrapUp: true } : {}),
605
653
  ...(goal.missing && goal.missing.length > 0 ? { missing: goal.missing } : {}),
654
+ ...failuresOf(goal),
606
655
  }
607
656
  return {
608
657
  record: {
@@ -714,6 +763,66 @@ abstract class SessionGoalStoreBase implements SessionGoalStore {
714
763
  })
715
764
  }
716
765
 
766
+ async recordGateRound(
767
+ sessionId: SessionId,
768
+ tenantId: TenantId,
769
+ goalId: GoalId,
770
+ report: GoalGateRoundReport,
771
+ ): Promise<SessionGoal | null> {
772
+ const checked = await this.requireSession(sessionId, tenantId)
773
+ const id = asGoalId(goalId)
774
+ const before = await backendFor(this).read(checked)
775
+ if (!before || before.goal?.id !== id) return null
776
+ return await backendFor(this).transact<SessionGoal | null>(checked, (existing) => {
777
+ if (!existing) throw new GoalNotFoundError(checked)
778
+ assertTenant(existing, tenantId)
779
+ const goal = existing.goal
780
+ const now = this.now()
781
+ const keep = (result: SessionGoal | null, next: SessionGoal | null = existing.goal) => ({
782
+ record: {
783
+ sessionId: checked,
784
+ tenantId,
785
+ storageRevision: existing.storageRevision + 1,
786
+ goal: next,
787
+ updatedAt: now,
788
+ },
789
+ result,
790
+ })
791
+ if (!goal || goal.id !== id || goal.gates === undefined) return keep(null)
792
+ const gates = goal.gates
793
+ const results = report.results.slice(0, gates.entries.length).map((result) => ({
794
+ ...result,
795
+ ...(result.tail !== undefined
796
+ ? { tail: goalGateTail(result.tail, GOAL_GATE_MAX_TAIL_CHARS) }
797
+ : {}),
798
+ }))
799
+ const failed = goalGateFailedNames(results)
800
+ // A round that looks twice (the model was sent back and looked again) counts once.
801
+ const counted = gates.countedRound === report.round
802
+ const failingRounds =
803
+ failed.length === 0 ? 0 : counted ? gates.failingRounds : gates.failingRounds + 1
804
+ const nextGates = {
805
+ ...gates,
806
+ results,
807
+ failingRounds,
808
+ ...(failed.length === 0 ? {} : { countedRound: report.round }),
809
+ }
810
+ let updated: SessionGoal = { ...goal, gates: nextGates, updatedAt: now }
811
+ if (goal.phase === 'active' && failed.length > 0 && failingRounds >= gates.maxFailingRounds) {
812
+ updated = {
813
+ ...updated,
814
+ revision: goal.revision + 1,
815
+ phase: 'blocked',
816
+ blockedReason: {
817
+ code: GOAL_GATES_BLOCK_CODE,
818
+ message: goalGatesBlockSentence(gates, failed),
819
+ },
820
+ }
821
+ }
822
+ return keep(updated, updated)
823
+ })
824
+ }
825
+
717
826
  async completeGoal(sessionId: SessionId, tenantId: TenantId, ref: GoalRef): Promise<SessionGoal> {
718
827
  return await this.transition(
719
828
  sessionId,
@@ -122,11 +122,16 @@ async function inspect(path: string, env: Resolved): Promise<Inspection | undefi
122
122
  return { stats: before, content: '', pid: undefined, staleReason: undefined }
123
123
  const content = await readFile(path, 'utf8').catch((error: NodeJS.ErrnoException) => {
124
124
  if (error.code === 'ENOENT') return undefined
125
+ // Windows can deny reads while another handle still holds the lock file.
126
+ // Treat an unreadable owner as unverifiable, so it cannot be broken.
127
+ if (error.code === 'EACCES' || error.code === 'EPERM' || error.code === 'EBUSY') return null
125
128
  throw error
126
129
  })
127
130
  if (content === undefined) return undefined
128
131
  const after = await lstat(path).catch(() => undefined)
129
132
  if (!after || after.dev !== before.dev || after.ino !== before.ino) return undefined
133
+ if (content === null)
134
+ return { stats: before, content: '', pid: undefined, staleReason: undefined }
130
135
 
131
136
  const owner = parseOwner(content)
132
137
  if (owner) {
@@ -167,7 +172,20 @@ async function createOwned(
167
172
  try {
168
173
  handle = await open(path, 'wx', 0o600)
169
174
  } catch (error) {
170
- if ((error as NodeJS.ErrnoException).code === 'EEXIST') return undefined
175
+ const code = (error as NodeJS.ErrnoException).code
176
+ if (code === 'EEXIST') return undefined
177
+ // Windows reports an exclusive create over a file another process still
178
+ // holds open (or is deleting) as a sharing error, not EEXIST. When the
179
+ // path is there, it is occupied; otherwise the error is real.
180
+ if (code === 'EACCES' || code === 'EPERM' || code === 'EBUSY') {
181
+ if (
182
+ await lstat(path).then(
183
+ () => true,
184
+ () => false,
185
+ )
186
+ )
187
+ return undefined
188
+ }
171
189
  throw error
172
190
  }
173
191
  const owner = `${JSON.stringify({
@@ -976,6 +976,7 @@ export class SessionLogCore implements SessionLog {
976
976
  type !== 'message_replaced' &&
977
977
  type !== 'message_edited' &&
978
978
  type !== 'compaction' &&
979
+ type !== 'compaction_shed' &&
979
980
  type !== 'turn_completed'
980
981
  )
981
982
  return candidate
@@ -984,6 +985,31 @@ export class SessionLogCore implements SessionLog {
984
985
  // single large one never sits inline and bloats the log.
985
986
  const spillAbove = type === 'compaction' ? this.#compactionSpillAbove : this.#spillAbove
986
987
  if (size <= spillAbove) return candidate
988
+ if (type === 'compaction_shed') {
989
+ if (!Array.isArray(candidate.messages) || candidate.messagesSpill !== undefined)
990
+ return candidate
991
+ const messages = candidate.messages as Message[]
992
+ const messagesSpill = await this.#spills.write(
993
+ `shed:${String(candidate.id)}`,
994
+ 'messages',
995
+ JSON.stringify(messages),
996
+ )
997
+ // Keep the exact searchable text and tool pairing inline when they fit.
998
+ const projected = messages.map((message) => {
999
+ if (message.role === 'tool' && Array.isArray(message.content)) {
1000
+ return {
1001
+ ...message,
1002
+ content: message.content.filter((block) => block.type === 'text'),
1003
+ }
1004
+ }
1005
+ if (message.role === 'user') return { ...message, attachments: undefined }
1006
+ return message
1007
+ })
1008
+ const record = { ...candidate, messages: projected, messagesSpill }
1009
+ return Buffer.byteLength(`${JSON.stringify(record)}\n`, 'utf8') <= this.#spillAbove
1010
+ ? record
1011
+ : { ...record, messages: [] }
1012
+ }
987
1013
  if (type === 'turn_completed') {
988
1014
  if (typeof candidate.result !== 'string') return candidate
989
1015
  const ref = await this.#spillOrLose(
@@ -174,7 +174,7 @@ const inputSchema = z.object({
174
174
  .boolean()
175
175
  .optional()
176
176
  .describe(
177
- 'Start the command as a background job and return its id at once. You are told when it exits: end your turn or keep working, and do not poll or wait for it. A command that waits for a person (it prints a sign-in URL) goes here too, with no `timeout` wrapper: tell them the step and end your turn. For a persistent server, `wait_for_job` with output_contains observes its readiness marker; verify health separately. Use `job` action "read" for output. Background a command with this parameter, since `cmd &` is not a registered job: strict execution ownership can retire the allocation when the launcher exits with live descendants. An interactive application may belong to a dedicated computer only when that computer explicitly supports application lifetime; its launch result is not a registered job or proof the application has finished.',
177
+ 'Start the command as a background job and return its id at once. You are told when it exits: end your turn or keep working, and do not poll or wait for it. A command that waits for a person (it prints a sign-in URL) goes here too, with no `timeout` wrapper: tell them the step and end your turn. To wait for a condition, background an until-loop (`until <check>; do sleep 2; done`) and end your turn, or give it to `monitor`. For a persistent server, `wait_for_job` with output_contains observes its readiness marker; verify health separately. Use `job` action "read" for output. Background a command with this parameter, since `cmd &` is not a registered job: strict execution ownership can retire the allocation when the launcher exits with live descendants. An interactive application may belong to a dedicated computer only when that computer explicitly supports application lifetime; its launch result is not a registered job or proof the application has finished.',
178
178
  ),
179
179
  dangerously_disable_sandbox: z
180
180
  .boolean()
@@ -1177,6 +1177,8 @@ export function createBrowserTools(
1177
1177
 
1178
1178
  const browser = defineTool({
1179
1179
  name: BROWSER_TOOL_NAME,
1180
+ discoveryHint:
1181
+ 'Real browser: sign-in pages, script-drawn pages, reading what is on screen; use over web_fetch then',
1180
1182
  description: observeDescription(caps),
1181
1183
  inputSchema: observeSchema,
1182
1184
  // An unavailable host keeps the full enum: an empty one is invalid on
@@ -1240,6 +1242,8 @@ export function createBrowserTools(
1240
1242
 
1241
1243
  const browserAct = defineTool({
1242
1244
  name: BROWSER_ACT_TOOL_NAME,
1245
+ discoveryHint:
1246
+ 'Act on a browser page: click, type, fill a form, select, press a key, upload, answer a dialog',
1243
1247
  description: actDescription(caps),
1244
1248
  inputSchema: actSchema,
1245
1249
  modelInputSchema: actModelSchema(actActions.length > 0 ? actActions : ACT_ACTIONS),
@@ -52,6 +52,26 @@ export const HIGH_RES_SCREENSHOT_LIMITS: ScreenshotLimits = Object.freeze({
52
52
  maxTiles: 4784,
53
53
  })
54
54
 
55
+ /**
56
+ * The limits to fit a screenshot to for `model`: the high-resolution tier for
57
+ * a model known to read it (the 4.7 and later models of the vendor behind that
58
+ * tier, with or without a vendor prefix or a dated suffix), the standard tier for every
59
+ * other model, including one the table does not know. A wrong "high" costs a
60
+ * rejected tool result; a wrong "standard" only costs detail, so an unknown
61
+ * model gets the standard tier.
62
+ */
63
+ export function screenshotLimitsForModel(model: string | undefined): ScreenshotLimits {
64
+ if (model === undefined) return STANDARD_SCREENSHOT_LIMITS
65
+ const match = /claude-(?:opus|sonnet|haiku|fable)-(\d+)(?:[-.](\d{1,2})(?!\d))?/i.exec(model)
66
+ if (!match) return STANDARD_SCREENSHOT_LIMITS
67
+ const major = Number(match[1])
68
+ const minor = match[2] === undefined ? 0 : Number(match[2])
69
+ // A dated id such as `claude-sonnet-4-20250514` has no minor: the date is not one.
70
+ return major > 4 || (major === 4 && minor >= 7)
71
+ ? HIGH_RES_SCREENSHOT_LIMITS
72
+ : STANDARD_SCREENSHOT_LIMITS
73
+ }
74
+
55
75
  export interface ImageSize {
56
76
  readonly width: number
57
77
  readonly height: number
@@ -39,7 +39,6 @@ import {
39
39
  } from './computer-use-coordinates.js'
40
40
  import {
41
41
  type FittedImage,
42
- HIGH_RES_SCREENSHOT_LIMITS,
43
42
  STANDARD_SCREENSHOT_LIMITS,
44
43
  type ScreenshotLimits,
45
44
  cropAndFitPng,
@@ -55,25 +54,7 @@ export {
55
54
  } from './computer-use-image.js'
56
55
  export type { ImageSize, ScreenshotLimits } from './computer-use-image.js'
57
56
 
58
- /**
59
- * The limits to fit a screenshot to for `model`: the high-resolution tier for
60
- * a model known to read it (the 4.7 and later models of the vendor behind that
61
- * tier, with or without a vendor prefix or a dated suffix), the standard tier for every
62
- * other model, including one the table does not know. A wrong "high" costs a
63
- * rejected tool result; a wrong "standard" only costs detail, so an unknown
64
- * model gets the standard tier.
65
- */
66
- export function screenshotLimitsForModel(model: string | undefined): ScreenshotLimits {
67
- if (model === undefined) return STANDARD_SCREENSHOT_LIMITS
68
- const match = /claude-(?:opus|sonnet|haiku|fable)-(\d+)(?:[-.](\d{1,2})(?!\d))?/i.exec(model)
69
- if (!match) return STANDARD_SCREENSHOT_LIMITS
70
- const major = Number(match[1])
71
- const minor = match[2] === undefined ? 0 : Number(match[2])
72
- // A dated id such as `claude-sonnet-4-20250514` has no minor: the date is not one.
73
- return major > 4 || (major === 4 && minor >= 7)
74
- ? HIGH_RES_SCREENSHOT_LIMITS
75
- : STANDARD_SCREENSHOT_LIMITS
76
- }
57
+ export { screenshotLimitsForModel } from './computer-use-image.js'
77
58
 
78
59
  export const COMPUTER_USE_TOOL_NAME = 'computer_use' as const
79
60
 
@@ -170,6 +170,8 @@ const MONITOR_WEBSOCKET_NOT_SUPPORTED =
170
170
  export function createMonitorTool(options: MonitorToolOptions = {}) {
171
171
  return defineTool({
172
172
  name: MONITOR_TOOL_NAME,
173
+ discoveryHint:
174
+ 'Watch a command and hear each output line as it prints, while you keep working, instead of polling',
173
175
  description: MONITOR_DESCRIPTION,
174
176
  inputSchema,
175
177
  category: 'shell',
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod'
2
- import { toolDiscoveryHint } from '../../registry/tool/execute.js'
2
+ import { toolCatalogueHint } from '../../registry/tool/execute.js'
3
3
  import type { ToolDefinition } from '../../types/tool/index.js'
4
4
  import { defineTool } from '../defineTool.js'
5
5
 
@@ -202,7 +202,7 @@ export const SearchToolsTool = defineTool({
202
202
  if (nearMisses.length > 0) {
203
203
  const hints = nearMisses
204
204
  .map((t) => {
205
- const hint = toolDiscoveryHint(t.description)
205
+ const hint = toolCatalogueHint(t)
206
206
  return hint.length > 0 ? `- ${t.name}: ${hint}` : `- ${t.name}`
207
207
  })
208
208
  .join('\n')
@@ -27,7 +27,7 @@ export function leadingLongSleep(command: string): string | null {
27
27
 
28
28
  /** What the model is told when a long leading sleep is refused. */
29
29
  export function longSleepRefusal(what: string): string {
30
- return `Blocked: ${what}. Do not wait with sleeps. For a condition, run a background until-loop (\`until <check>; do sleep 2; done\`) with run_in_background: true and end your turn, you are told when it exits; for a stream of events, use monitor. Do not chain shorter sleeps to work around this block.`
30
+ return `Blocked: ${what}. Do not wait with sleeps. To wait until a condition is true, run a background until-loop (\`until <check>; do sleep 2; done\`) with run_in_background: true and end your turn, you are told when it exits, or give the same loop to monitor, where its exit or an output line is the event; for a stream of events, use monitor. Do not chain shorter sleeps to work around this block.`
31
31
  }
32
32
 
33
33
  /**
@@ -97,7 +97,7 @@ type WaitForJobInput = z.infer<typeof inputSchema>
97
97
  export const WaitForJobTool = defineTool({
98
98
  name: 'wait_for_job',
99
99
  description:
100
- 'Wait for an owned background job to exit, or set output_contains to observe an exact output marker while it stays running. Only for when the result is needed inside this step. Otherwise end your turn: you are told when a job exits. Never use it, or a short timeout_ms, for something that waits for a person. Output markers do not prove service health or completion and never express intent to wait until exit. A bounded wait returns output and next_offset without stopping the job; pass that cursor as from_offset to exclude earlier output.',
100
+ 'Wait for an owned background job to exit, or set output_contains to observe an exact output marker while it stays running. Only for a result needed inside this step in a host that cannot be woken later. Otherwise end your turn: you are told when a job exits, or use monitor. Never use it, or a short timeout_ms, for something that waits for a person. Output markers do not prove service health or completion and never express intent to wait until exit. A bounded wait returns output and next_offset without stopping the job; pass that cursor as from_offset to exclude earlier output.',
101
101
  inputSchema,
102
102
  category: 'shell',
103
103
  permissions: ['shell_execute'],
@@ -20,7 +20,7 @@ import type {
20
20
  UserQuestionOption,
21
21
  } from '../../types/hitl/index.js'
22
22
  import type { SessionId, TurnId } from '../../types/ids/index.js'
23
- import type { ToolDefinition, ToolFacts } from '../../types/tool/index.js'
23
+ import type { ToolDefinition, ToolFacts, ToolResult } from '../../types/tool/index.js'
24
24
  import { generateCheckpointId } from '../../utils/id.js'
25
25
  import { defineTool } from '../defineTool.js'
26
26
  import { questionOptions } from './question-options.js'
@@ -453,7 +453,22 @@ export function buildAskUserQuestionTool(config: AskUserQuestionToolOptions): To
453
453
  // registries by turn — concurrent parks on one turn clobber each
454
454
  // other and the first promise never resolves (the turn hangs to TTL).
455
455
  concurrencySafe: false,
456
+ // No deadline: the wait is a person's, and a person takes as long as
457
+ // they take. The executor's two-minute default is a bound for a tool
458
+ // call; at that bound it gave up on the question, told the model it had
459
+ // timed out, and the answers typed afterwards reached nobody. The wait
460
+ // still ends when the turn is stopped: `context.abortSignal` fires, is
461
+ // handed to the host below, and the host takes the question off screen.
462
+ timeoutMs: Number.POSITIVE_INFINITY,
456
463
  async execute(input, context) {
464
+ const gone = (): ToolResult => ({
465
+ success: false,
466
+ output: '',
467
+ error:
468
+ 'The question was withdrawn before the user answered it, so nothing was asked or answered.',
469
+ })
470
+ // A call that was abandoned before it began asks nothing.
471
+ if (context.abortSignal?.aborted) return gone()
457
472
  // A host that calls the tool without going through the registry
458
473
  // hands over the older single-question shape or unfilled defaults;
459
474
  // parsing again is a no-op for input the registry already parsed.
@@ -516,15 +531,23 @@ export function buildAskUserQuestionTool(config: AskUserQuestionToolOptions): To
516
531
 
517
532
  const decision =
518
533
  carried ??
519
- (await parkHandler({
520
- type: 'user_question',
521
- sessionId: config.sessionId ?? context.sessionId,
522
- turnId: config.turnId ?? context.turnId,
523
- // Provider correlation ids remain verbatim in questionData;
524
- // an unpersisted park gets its own safe checkpoint identifier.
525
- checkpointId: parkedAt ?? generateCheckpointId(),
526
- question: questionData,
527
- }))
534
+ (await parkHandler(
535
+ {
536
+ type: 'user_question',
537
+ sessionId: config.sessionId ?? context.sessionId,
538
+ turnId: config.turnId ?? context.turnId,
539
+ // Provider correlation ids remain verbatim in questionData;
540
+ // an unpersisted park gets its own safe checkpoint identifier.
541
+ checkpointId: parkedAt ?? generateCheckpointId(),
542
+ question: questionData,
543
+ },
544
+ // The signal is how the host learns nobody is waiting any more
545
+ // (the turn was stopped) and takes the question off screen.
546
+ {
547
+ transcript: () => context.conversation?.messages() ?? [],
548
+ ...(context.abortSignal ? { signal: context.abortSignal } : {}),
549
+ },
550
+ ))
528
551
 
529
552
  // Clear the park once the answer is in, so an approval queue
530
553
  // stops serving a question that has been answered.
@@ -549,6 +572,10 @@ export function buildAskUserQuestionTool(config: AskUserQuestionToolOptions): To
549
572
  : { question: first.question, answered: false },
550
573
  }
551
574
 
575
+ // Answers that arrive after the call was abandoned have no one to
576
+ // receive them: the turn that asked has stopped.
577
+ if (context.abortSignal?.aborted) return gone()
578
+
552
579
  if (decision.action === 'abort') {
553
580
  // One decline ends the whole batch: there is no partial refusal.
554
581
  return {
@@ -1302,6 +1302,9 @@ export function buildCoordinatorTools(opts: CoordinatorToolsOptions): ToolDefini
1302
1302
  // registry entry and deadlock the loser, so the executor must
1303
1303
  // serialize this tool exactly like the question tool.
1304
1304
  concurrencySafe: false,
1305
+ // A person decides, and takes as long as they take: no deadline. The
1306
+ // two-minute default abandoned the approval while it was on screen.
1307
+ timeoutMs: Number.POSITIVE_INFINITY,
1305
1308
  async execute({ title, summary, steps }) {
1306
1309
  const pm = getPlanManager()
1307
1310
  if (!pm) {
@@ -87,6 +87,8 @@ export interface DefineToolOptions<S extends z.ZodType> {
87
87
  pathArgument?: string
88
88
  /** Tools `search_tools` loads together with this one; see {@link ToolDefinition.loadsWith}. */
89
89
  loadsWith?: readonly string[]
90
+ /** The catalogue line of a deferred tool; see {@link ToolDefinition.discoveryHint}. */
91
+ discoveryHint?: string
90
92
  /** A refusal known before any reviewer is asked; see {@link ToolDefinition.refuseBeforeReview}. */
91
93
  refuseBeforeReview?: ToolDefinition<z.infer<S>>['refuseBeforeReview']
92
94
  /** The argument holding a canonical URL; see {@link ToolDefinition.urlArgument}. */
@@ -155,6 +157,9 @@ export function defineTool<S extends z.ZodType>(
155
157
  ...(options.loadsWith !== undefined && options.loadsWith.length > 0
156
158
  ? { loadsWith: options.loadsWith }
157
159
  : {}),
160
+ ...(options.discoveryHint !== undefined && options.discoveryHint.trim().length > 0
161
+ ? { discoveryHint: options.discoveryHint.trim() }
162
+ : {}),
158
163
  ...(options.refuseBeforeReview ? { refuseBeforeReview: options.refuseBeforeReview } : {}),
159
164
  ...(options.urlArgument !== undefined ? { urlArgument: options.urlArgument } : {}),
160
165
  ...(options.sandboxEscapeArgument !== undefined