@namzu/sdk 71.1.0 → 73.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 (380) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/dist/agents/QueryAgent.d.ts.map +1 -1
  3. package/dist/agents/QueryAgent.js +1 -0
  4. package/dist/agents/QueryAgent.js.map +1 -1
  5. package/dist/agents/examples/SupervisorAgent.d.ts.map +1 -1
  6. package/dist/agents/examples/SupervisorAgent.js +5 -0
  7. package/dist/agents/examples/SupervisorAgent.js.map +1 -1
  8. package/dist/authorization/protected-paths.d.ts.map +1 -1
  9. package/dist/authorization/protected-paths.js +4 -0
  10. package/dist/authorization/protected-paths.js.map +1 -1
  11. package/dist/compaction/index.d.ts +1 -1
  12. package/dist/compaction/index.d.ts.map +1 -1
  13. package/dist/compaction/index.js +1 -1
  14. package/dist/compaction/index.js.map +1 -1
  15. package/dist/compaction/manual.d.ts +24 -1
  16. package/dist/compaction/manual.d.ts.map +1 -1
  17. package/dist/compaction/manual.js +80 -21
  18. package/dist/compaction/manual.js.map +1 -1
  19. package/dist/compaction/model-summary.d.ts +24 -6
  20. package/dist/compaction/model-summary.d.ts.map +1 -1
  21. package/dist/compaction/model-summary.js +108 -23
  22. package/dist/compaction/model-summary.js.map +1 -1
  23. package/dist/compaction/precompute.d.ts +179 -0
  24. package/dist/compaction/precompute.d.ts.map +1 -0
  25. package/dist/compaction/precompute.js +274 -0
  26. package/dist/compaction/precompute.js.map +1 -0
  27. package/dist/compaction/restore.d.ts +23 -0
  28. package/dist/compaction/restore.d.ts.map +1 -1
  29. package/dist/compaction/restore.js +59 -1
  30. package/dist/compaction/restore.js.map +1 -1
  31. package/dist/compaction/summary.d.ts +37 -2
  32. package/dist/compaction/summary.d.ts.map +1 -1
  33. package/dist/compaction/summary.js +46 -6
  34. package/dist/compaction/summary.js.map +1 -1
  35. package/dist/config/runtime.d.ts +4 -0
  36. package/dist/config/runtime.d.ts.map +1 -1
  37. package/dist/config/runtime.js +20 -3
  38. package/dist/config/runtime.js.map +1 -1
  39. package/dist/connector/index.d.ts +2 -2
  40. package/dist/connector/index.d.ts.map +1 -1
  41. package/dist/connector/index.js +1 -1
  42. package/dist/connector/index.js.map +1 -1
  43. package/dist/connector/mcp/client.d.ts +26 -6
  44. package/dist/connector/mcp/client.d.ts.map +1 -1
  45. package/dist/connector/mcp/client.js +49 -7
  46. package/dist/connector/mcp/client.js.map +1 -1
  47. package/dist/connector/mcp/index.d.ts +2 -0
  48. package/dist/connector/mcp/index.d.ts.map +1 -1
  49. package/dist/connector/mcp/index.js +1 -0
  50. package/dist/connector/mcp/index.js.map +1 -1
  51. package/dist/connector/mcp/sandbox-stdio.d.ts +67 -0
  52. package/dist/connector/mcp/sandbox-stdio.d.ts.map +1 -0
  53. package/dist/connector/mcp/sandbox-stdio.js +178 -0
  54. package/dist/connector/mcp/sandbox-stdio.js.map +1 -0
  55. package/dist/connector/mcp/stdio-program.d.ts +34 -0
  56. package/dist/connector/mcp/stdio-program.d.ts.map +1 -0
  57. package/dist/connector/mcp/stdio-program.js +47 -0
  58. package/dist/connector/mcp/stdio-program.js.map +1 -0
  59. package/dist/connector/mcp/stdio.d.ts.map +1 -1
  60. package/dist/connector/mcp/stdio.js +5 -2
  61. package/dist/connector/mcp/stdio.js.map +1 -1
  62. package/dist/connector/web/guarded-fetch.d.ts +51 -2
  63. package/dist/connector/web/guarded-fetch.d.ts.map +1 -1
  64. package/dist/connector/web/guarded-fetch.js +140 -19
  65. package/dist/connector/web/guarded-fetch.js.map +1 -1
  66. package/dist/connector/web/index.d.ts +2 -2
  67. package/dist/connector/web/index.d.ts.map +1 -1
  68. package/dist/connector/web/index.js +1 -1
  69. package/dist/connector/web/index.js.map +1 -1
  70. package/dist/manager/agent/lifecycle.d.ts.map +1 -1
  71. package/dist/manager/agent/lifecycle.js +9 -1
  72. package/dist/manager/agent/lifecycle.js.map +1 -1
  73. package/dist/manager/session/turn-recorder.d.ts +26 -0
  74. package/dist/manager/session/turn-recorder.d.ts.map +1 -1
  75. package/dist/manager/session/turn-recorder.js +72 -5
  76. package/dist/manager/session/turn-recorder.js.map +1 -1
  77. package/dist/peers/protocol.d.ts +9 -0
  78. package/dist/peers/protocol.d.ts.map +1 -1
  79. package/dist/peers/protocol.js +4 -0
  80. package/dist/peers/protocol.js.map +1 -1
  81. package/dist/peers/record.d.ts +6 -0
  82. package/dist/peers/record.d.ts.map +1 -1
  83. package/dist/peers/record.js +4 -0
  84. package/dist/peers/record.js.map +1 -1
  85. package/dist/plugin/hook-module/capabilities.d.ts.map +1 -1
  86. package/dist/plugin/hook-module/capabilities.js +24 -13
  87. package/dist/plugin/hook-module/capabilities.js.map +1 -1
  88. package/dist/plugin/hook-module/host.d.ts +31 -0
  89. package/dist/plugin/hook-module/host.d.ts.map +1 -1
  90. package/dist/plugin/hook-module/host.js +56 -13
  91. package/dist/plugin/hook-module/host.js.map +1 -1
  92. package/dist/plugin/hook-module/index.d.ts +3 -2
  93. package/dist/plugin/hook-module/index.d.ts.map +1 -1
  94. package/dist/plugin/hook-module/index.js +2 -1
  95. package/dist/plugin/hook-module/index.js.map +1 -1
  96. package/dist/plugin/index.d.ts +3 -2
  97. package/dist/plugin/index.d.ts.map +1 -1
  98. package/dist/plugin/index.js +2 -1
  99. package/dist/plugin/index.js.map +1 -1
  100. package/dist/plugin/shell-hook-execute.d.ts +55 -0
  101. package/dist/plugin/shell-hook-execute.d.ts.map +1 -0
  102. package/dist/plugin/shell-hook-execute.js +73 -0
  103. package/dist/plugin/shell-hook-execute.js.map +1 -0
  104. package/dist/plugin/shell-hook-restrict.d.ts +31 -0
  105. package/dist/plugin/shell-hook-restrict.d.ts.map +1 -0
  106. package/dist/plugin/shell-hook-restrict.js +69 -0
  107. package/dist/plugin/shell-hook-restrict.js.map +1 -0
  108. package/dist/plugin/shell-hook.d.ts +59 -2
  109. package/dist/plugin/shell-hook.d.ts.map +1 -1
  110. package/dist/plugin/shell-hook.js +79 -12
  111. package/dist/plugin/shell-hook.js.map +1 -1
  112. package/dist/public-runtime.d.ts +11 -7
  113. package/dist/public-runtime.d.ts.map +1 -1
  114. package/dist/public-runtime.js +9 -6
  115. package/dist/public-runtime.js.map +1 -1
  116. package/dist/public-tools.d.ts +1 -1
  117. package/dist/public-tools.d.ts.map +1 -1
  118. package/dist/public-tools.js +1 -1
  119. package/dist/public-tools.js.map +1 -1
  120. package/dist/public-types.d.ts +5 -2
  121. package/dist/public-types.d.ts.map +1 -1
  122. package/dist/registry/command/kernel-commands.d.ts +7 -1
  123. package/dist/registry/command/kernel-commands.d.ts.map +1 -1
  124. package/dist/registry/command/kernel-commands.js +40 -2
  125. package/dist/registry/command/kernel-commands.js.map +1 -1
  126. package/dist/registry/tool/execute.d.ts +8 -0
  127. package/dist/registry/tool/execute.d.ts.map +1 -1
  128. package/dist/registry/tool/execute.js +12 -0
  129. package/dist/registry/tool/execute.js.map +1 -1
  130. package/dist/runtime/jobs/websocket-source.d.ts +2 -22
  131. package/dist/runtime/jobs/websocket-source.d.ts.map +1 -1
  132. package/dist/runtime/jobs/websocket-source.js +2 -33
  133. package/dist/runtime/jobs/websocket-source.js.map +1 -1
  134. package/dist/runtime/query/budget-nudge.d.ts +27 -0
  135. package/dist/runtime/query/budget-nudge.d.ts.map +1 -0
  136. package/dist/runtime/query/budget-nudge.js +66 -0
  137. package/dist/runtime/query/budget-nudge.js.map +1 -0
  138. package/dist/runtime/query/compact-session.d.ts +9 -0
  139. package/dist/runtime/query/compact-session.d.ts.map +1 -1
  140. package/dist/runtime/query/compact-session.js +158 -76
  141. package/dist/runtime/query/compact-session.js.map +1 -1
  142. package/dist/runtime/query/events.d.ts +7 -0
  143. package/dist/runtime/query/events.d.ts.map +1 -1
  144. package/dist/runtime/query/events.js +29 -11
  145. package/dist/runtime/query/events.js.map +1 -1
  146. package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
  147. package/dist/runtime/query/executor/tool-call-admission.js +51 -10
  148. package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
  149. package/dist/runtime/query/guard.d.ts +8 -0
  150. package/dist/runtime/query/guard.d.ts.map +1 -1
  151. package/dist/runtime/query/guard.js +20 -0
  152. package/dist/runtime/query/guard.js.map +1 -1
  153. package/dist/runtime/query/index.d.ts +6 -0
  154. package/dist/runtime/query/index.d.ts.map +1 -1
  155. package/dist/runtime/query/index.js +3 -0
  156. package/dist/runtime/query/index.js.map +1 -1
  157. package/dist/runtime/query/iteration/index.d.ts +2 -0
  158. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  159. package/dist/runtime/query/iteration/index.js +27 -1
  160. package/dist/runtime/query/iteration/index.js.map +1 -1
  161. package/dist/runtime/query/iteration/phases/compaction.d.ts +1 -0
  162. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  163. package/dist/runtime/query/iteration/phases/compaction.js +164 -43
  164. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  165. package/dist/runtime/query/iteration/phases/context.d.ts +4 -0
  166. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  167. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  168. package/dist/runtime/query/iteration/phases/precompute.d.ts +60 -0
  169. package/dist/runtime/query/iteration/phases/precompute.d.ts.map +1 -0
  170. package/dist/runtime/query/iteration/phases/precompute.js +240 -0
  171. package/dist/runtime/query/iteration/phases/precompute.js.map +1 -0
  172. package/dist/runtime/query/turn/outcome-ledger.d.ts +14 -0
  173. package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
  174. package/dist/runtime/query/turn/outcome-ledger.js +28 -0
  175. package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
  176. package/dist/scheduler/completion-inbox.d.ts.map +1 -1
  177. package/dist/scheduler/completion-inbox.js +15 -0
  178. package/dist/scheduler/completion-inbox.js.map +1 -1
  179. package/dist/store/goal/gates.d.ts +53 -0
  180. package/dist/store/goal/gates.d.ts.map +1 -0
  181. package/dist/store/goal/gates.js +664 -0
  182. package/dist/store/goal/gates.js.map +1 -0
  183. package/dist/store/goal/index.d.ts +16 -1
  184. package/dist/store/goal/index.d.ts.map +1 -1
  185. package/dist/store/goal/index.js +74 -0
  186. package/dist/store/goal/index.js.map +1 -1
  187. package/dist/store/session-index/index.d.ts +13 -0
  188. package/dist/store/session-index/index.d.ts.map +1 -1
  189. package/dist/store/session-index/index.js +1 -0
  190. package/dist/store/session-index/index.js.map +1 -1
  191. package/dist/store/session-index/rebuild.d.ts +12 -0
  192. package/dist/store/session-index/rebuild.d.ts.map +1 -1
  193. package/dist/store/session-index/rebuild.js +20 -4
  194. package/dist/store/session-index/rebuild.js.map +1 -1
  195. package/dist/store/session-index/sqlite.d.ts +20 -0
  196. package/dist/store/session-index/sqlite.d.ts.map +1 -1
  197. package/dist/store/session-index/sqlite.js +50 -12
  198. package/dist/store/session-index/sqlite.js.map +1 -1
  199. package/dist/tools/admit-facts.d.ts.map +1 -1
  200. package/dist/tools/admit-facts.js +59 -0
  201. package/dist/tools/admit-facts.js.map +1 -1
  202. package/dist/tools/builtins/bash.js +1 -1
  203. package/dist/tools/builtins/bash.js.map +1 -1
  204. package/dist/tools/builtins/browser.d.ts.map +1 -1
  205. package/dist/tools/builtins/browser.js +2 -0
  206. package/dist/tools/builtins/browser.js.map +1 -1
  207. package/dist/tools/builtins/monitor.d.ts.map +1 -1
  208. package/dist/tools/builtins/monitor.js +1 -0
  209. package/dist/tools/builtins/monitor.js.map +1 -1
  210. package/dist/tools/builtins/search-tools.js +2 -2
  211. package/dist/tools/builtins/search-tools.js.map +1 -1
  212. package/dist/tools/builtins/sleep-guard.js +1 -1
  213. package/dist/tools/builtins/sleep-guard.js.map +1 -1
  214. package/dist/tools/builtins/wait-for-job.js +1 -1
  215. package/dist/tools/builtins/wait-for-job.js.map +1 -1
  216. package/dist/tools/coordinator/ask-user-question.d.ts.map +1 -1
  217. package/dist/tools/coordinator/ask-user-question.js +92 -3
  218. package/dist/tools/coordinator/ask-user-question.js.map +1 -1
  219. package/dist/tools/coordinator/index.d.ts.map +1 -1
  220. package/dist/tools/coordinator/index.js +3 -0
  221. package/dist/tools/coordinator/index.js.map +1 -1
  222. package/dist/tools/defineTool.d.ts +2 -0
  223. package/dist/tools/defineTool.d.ts.map +1 -1
  224. package/dist/tools/defineTool.js +3 -0
  225. package/dist/tools/defineTool.js.map +1 -1
  226. package/dist/tools/goal/confirmation.d.ts +40 -2
  227. package/dist/tools/goal/confirmation.d.ts.map +1 -1
  228. package/dist/tools/goal/confirmation.js +117 -0
  229. package/dist/tools/goal/confirmation.js.map +1 -1
  230. package/dist/tools/goal/index.d.ts.map +1 -1
  231. package/dist/tools/goal/index.js +14 -2
  232. package/dist/tools/goal/index.js.map +1 -1
  233. package/dist/tools/memory/save.d.ts.map +1 -1
  234. package/dist/tools/memory/save.js +1 -0
  235. package/dist/tools/memory/save.js.map +1 -1
  236. package/dist/tools/schedules/index.d.ts +1 -0
  237. package/dist/tools/schedules/index.d.ts.map +1 -1
  238. package/dist/tools/schedules/index.js +1 -0
  239. package/dist/tools/schedules/index.js.map +1 -1
  240. package/dist/tools/schedules/loop-tool.d.ts.map +1 -1
  241. package/dist/tools/schedules/loop-tool.js +1 -0
  242. package/dist/tools/schedules/loop-tool.js.map +1 -1
  243. package/dist/tools/schedules/present.d.ts.map +1 -1
  244. package/dist/tools/schedules/present.js +2 -0
  245. package/dist/tools/schedules/present.js.map +1 -1
  246. package/dist/tools/schedules/schedule-tool.d.ts.map +1 -1
  247. package/dist/tools/schedules/schedule-tool.js +79 -9
  248. package/dist/tools/schedules/schedule-tool.js.map +1 -1
  249. package/dist/tools/schedules/self-tool.d.ts +16 -0
  250. package/dist/tools/schedules/self-tool.d.ts.map +1 -0
  251. package/dist/tools/schedules/self-tool.js +140 -0
  252. package/dist/tools/schedules/self-tool.js.map +1 -0
  253. package/dist/tools/schedules/timer-tools.d.ts.map +1 -1
  254. package/dist/tools/schedules/timer-tools.js +1 -0
  255. package/dist/tools/schedules/timer-tools.js.map +1 -1
  256. package/dist/tools/schedules/types.d.ts +63 -0
  257. package/dist/tools/schedules/types.d.ts.map +1 -1
  258. package/dist/toolsets/manager.d.ts +10 -0
  259. package/dist/toolsets/manager.d.ts.map +1 -1
  260. package/dist/toolsets/manager.js +56 -7
  261. package/dist/toolsets/manager.js.map +1 -1
  262. package/dist/turn/memory-promoter.d.ts.map +1 -1
  263. package/dist/turn/memory-promoter.js +20 -4
  264. package/dist/turn/memory-promoter.js.map +1 -1
  265. package/dist/types/agent/base.d.ts +6 -0
  266. package/dist/types/agent/base.d.ts.map +1 -1
  267. package/dist/types/agent/supervisor.d.ts +10 -0
  268. package/dist/types/agent/supervisor.d.ts.map +1 -1
  269. package/dist/types/agent/task.d.ts +11 -0
  270. package/dist/types/agent/task.d.ts.map +1 -1
  271. package/dist/types/agent/task.js.map +1 -1
  272. package/dist/types/goal/index.d.ts +66 -0
  273. package/dist/types/goal/index.d.ts.map +1 -1
  274. package/dist/types/hitl/index.d.ts +8 -0
  275. package/dist/types/hitl/index.d.ts.map +1 -1
  276. package/dist/types/hitl/index.js.map +1 -1
  277. package/dist/types/message/index.d.ts +7 -0
  278. package/dist/types/message/index.d.ts.map +1 -1
  279. package/dist/types/message/index.js.map +1 -1
  280. package/dist/types/session/events.d.ts +7 -0
  281. package/dist/types/session/events.d.ts.map +1 -1
  282. package/dist/types/session/events.js.map +1 -1
  283. package/dist/types/session/outcome.d.ts +12 -0
  284. package/dist/types/session/outcome.d.ts.map +1 -1
  285. package/dist/types/session/outcome.js.map +1 -1
  286. package/dist/types/session/records.d.ts +79 -1
  287. package/dist/types/session/records.d.ts.map +1 -1
  288. package/dist/types/session/records.js +24 -0
  289. package/dist/types/session/records.js.map +1 -1
  290. package/dist/types/tool/index.d.ts +7 -0
  291. package/dist/types/tool/index.d.ts.map +1 -1
  292. package/dist/types/tool/index.js.map +1 -1
  293. package/dist/types/tool/presentation.d.ts +21 -0
  294. package/dist/types/tool/presentation.d.ts.map +1 -1
  295. package/package.json +6 -6
  296. package/src/agents/QueryAgent.ts +1 -0
  297. package/src/agents/examples/SupervisorAgent.ts +5 -0
  298. package/src/authorization/protected-paths.ts +4 -0
  299. package/src/compaction/index.ts +1 -0
  300. package/src/compaction/manual.ts +130 -23
  301. package/src/compaction/model-summary.ts +118 -23
  302. package/src/compaction/precompute.ts +390 -0
  303. package/src/compaction/restore.ts +74 -1
  304. package/src/compaction/summary.ts +69 -3
  305. package/src/config/runtime.ts +20 -3
  306. package/src/connector/index.ts +3 -0
  307. package/src/connector/mcp/client.ts +49 -7
  308. package/src/connector/mcp/index.ts +5 -0
  309. package/src/connector/mcp/sandbox-stdio.ts +214 -0
  310. package/src/connector/mcp/stdio-program.ts +68 -0
  311. package/src/connector/mcp/stdio.ts +5 -2
  312. package/src/connector/web/guarded-fetch.ts +197 -30
  313. package/src/connector/web/index.ts +4 -1
  314. package/src/manager/agent/lifecycle.ts +10 -1
  315. package/src/manager/session/turn-recorder.ts +92 -5
  316. package/src/peers/protocol.ts +4 -0
  317. package/src/peers/record.ts +4 -0
  318. package/src/plugin/hook-module/capabilities.ts +36 -14
  319. package/src/plugin/hook-module/host.ts +86 -13
  320. package/src/plugin/hook-module/index.ts +3 -0
  321. package/src/plugin/index.ts +3 -0
  322. package/src/plugin/shell-hook-execute.ts +126 -0
  323. package/src/plugin/shell-hook-restrict.ts +66 -0
  324. package/src/plugin/shell-hook.ts +138 -10
  325. package/src/public-runtime.ts +41 -0
  326. package/src/public-tools.ts +2 -0
  327. package/src/public-types.ts +21 -0
  328. package/src/registry/command/kernel-commands.ts +62 -3
  329. package/src/registry/tool/execute.ts +14 -0
  330. package/src/runtime/jobs/websocket-source.ts +2 -46
  331. package/src/runtime/query/budget-nudge.ts +92 -0
  332. package/src/runtime/query/compact-session.ts +195 -70
  333. package/src/runtime/query/events.ts +29 -11
  334. package/src/runtime/query/executor/tool-call-admission.ts +62 -17
  335. package/src/runtime/query/guard.ts +22 -0
  336. package/src/runtime/query/index.ts +10 -0
  337. package/src/runtime/query/iteration/index.ts +26 -1
  338. package/src/runtime/query/iteration/phases/compaction.ts +173 -43
  339. package/src/runtime/query/iteration/phases/context.ts +6 -0
  340. package/src/runtime/query/iteration/phases/precompute.ts +277 -0
  341. package/src/runtime/query/turn/outcome-ledger.ts +34 -0
  342. package/src/scheduler/completion-inbox.ts +14 -0
  343. package/src/store/goal/gates.ts +738 -0
  344. package/src/store/goal/index.ts +109 -0
  345. package/src/store/session-index/index.ts +14 -0
  346. package/src/store/session-index/rebuild.ts +22 -4
  347. package/src/store/session-index/sqlite.ts +63 -14
  348. package/src/tools/admit-facts.ts +64 -0
  349. package/src/tools/builtins/bash.ts +1 -1
  350. package/src/tools/builtins/browser.ts +4 -0
  351. package/src/tools/builtins/monitor.ts +2 -0
  352. package/src/tools/builtins/search-tools.ts +2 -2
  353. package/src/tools/builtins/sleep-guard.ts +1 -1
  354. package/src/tools/builtins/wait-for-job.ts +1 -1
  355. package/src/tools/coordinator/ask-user-question.ts +124 -13
  356. package/src/tools/coordinator/index.ts +3 -0
  357. package/src/tools/defineTool.ts +5 -0
  358. package/src/tools/goal/confirmation.ts +171 -3
  359. package/src/tools/goal/index.ts +15 -3
  360. package/src/tools/memory/save.ts +2 -0
  361. package/src/tools/schedules/index.ts +1 -0
  362. package/src/tools/schedules/loop-tool.ts +2 -0
  363. package/src/tools/schedules/present.ts +2 -0
  364. package/src/tools/schedules/schedule-tool.ts +84 -9
  365. package/src/tools/schedules/self-tool.ts +152 -0
  366. package/src/tools/schedules/timer-tools.ts +2 -0
  367. package/src/tools/schedules/types.ts +62 -0
  368. package/src/toolsets/manager.ts +55 -8
  369. package/src/turn/memory-promoter.ts +24 -3
  370. package/src/types/agent/base.ts +7 -0
  371. package/src/types/agent/supervisor.ts +11 -0
  372. package/src/types/agent/task.ts +12 -0
  373. package/src/types/goal/index.ts +72 -0
  374. package/src/types/hitl/index.ts +8 -0
  375. package/src/types/message/index.ts +7 -0
  376. package/src/types/session/events.ts +7 -0
  377. package/src/types/session/outcome.ts +16 -1
  378. package/src/types/session/records.ts +27 -0
  379. package/src/types/tool/index.ts +7 -0
  380. package/src/types/tool/presentation.ts +22 -0
@@ -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,
@@ -177,6 +177,13 @@ export interface SessionLogLocation {
177
177
  }
178
178
 
179
179
  export interface SessionIndex {
180
+ /**
181
+ * True while the index was opened on demand and no read has caught it up with
182
+ * the logs yet: the next list, search or lookup reads every log first, so a
183
+ * caller that makes a person wait can say so. Absent on a backend that does
184
+ * not defer.
185
+ */
186
+ readonly syncPending?: boolean
180
187
  readonly backend: 'sqlite' | 'scan'
181
188
  /** Derive (or continue deriving) one session from its records. */
182
189
  indexSession(input: SessionLogInput): Promise<IndexedSession | undefined>
@@ -216,6 +223,12 @@ export interface OpenSessionIndexOptions {
216
223
  * catch up with the logs in the background; every read waits for it.
217
224
  */
218
225
  readonly syncInBackground?: boolean
226
+ /**
227
+ * SQLite only: open without reading any log, and catch up with the logs the
228
+ * first time a read asks. A write never starts the catch-up. The scan
229
+ * backend reads on first use already.
230
+ */
231
+ readonly syncOnDemand?: boolean
219
232
  }
220
233
 
221
234
  /**
@@ -234,6 +247,7 @@ export async function openSessionIndex(
234
247
  home,
235
248
  path: options.path ?? join(home, 'index.sqlite'),
236
249
  ...(options.syncInBackground === true ? { syncInBackground: true } : {}),
250
+ ...(options.syncOnDemand === true ? { syncOnDemand: true } : {}),
237
251
  })
238
252
  }
239
253
 
@@ -745,8 +745,26 @@ export abstract class SessionIndexBase implements SessionIndex {
745
745
  return Promise.resolve()
746
746
  }
747
747
 
748
+ /**
749
+ * What a read about one session waits for. A backend that syncs on first read
750
+ * overrides it to bring only that session's rows current, so a lookup the turn
751
+ * itself makes does not read every log.
752
+ */
753
+ protected settledFor(_sessionId: SessionId | undefined): Promise<void> {
754
+ return this.settled()
755
+ }
756
+
757
+ /**
758
+ * What a write waits for: a catch-up already running, never one that has not
759
+ * started. A backend that syncs on first read overrides it, so a write at the
760
+ * start of a conversation does not pay for reading every log.
761
+ */
762
+ protected settledForWrite(): Promise<void> {
763
+ return this.settled()
764
+ }
765
+
748
766
  async getSession(sessionId: SessionId): Promise<IndexedSession | undefined> {
749
- await this.settled()
767
+ await this.settledFor(sessionId)
750
768
  return this.sessionNow(sessionId)
751
769
  }
752
770
 
@@ -765,7 +783,7 @@ export abstract class SessionIndexBase implements SessionIndex {
765
783
  * clears the row, so a write that ran beside it could be undone.
766
784
  */
767
785
  async indexSession(input: SessionLogInput): Promise<IndexedSession | undefined> {
768
- await this.settled()
786
+ await this.settledForWrite()
769
787
  return this.indexSessionNow(input)
770
788
  }
771
789
 
@@ -882,7 +900,7 @@ export abstract class SessionIndexBase implements SessionIndex {
882
900
  }
883
901
 
884
902
  async refresh(location: SessionLogLocation): Promise<SessionStaleness> {
885
- await this.settled()
903
+ await this.settledForWrite()
886
904
  return this.refreshNow(location)
887
905
  }
888
906
 
@@ -912,7 +930,7 @@ export abstract class SessionIndexBase implements SessionIndex {
912
930
  }
913
931
 
914
932
  async sync(home: string): Promise<void> {
915
- await this.settled()
933
+ await this.settledForWrite()
916
934
  return this.syncNow(home)
917
935
  }
918
936
 
@@ -477,6 +477,13 @@ export interface SqliteSessionIndexOptions {
477
477
  * longer waits on a home with thousands of logs.
478
478
  */
479
479
  readonly syncInBackground?: boolean
480
+ /**
481
+ * Return once the index is open and current in version, and read the logs
482
+ * only when something first asks for a list, a search or a lookup. Opening
483
+ * does no session work; that first read waits for the catch-up, later reads
484
+ * find it done, and a write never starts it.
485
+ */
486
+ readonly syncOnDemand?: boolean
480
487
  }
481
488
 
482
489
  export interface RebuildSqliteSessionIndexOptions extends SqliteSessionIndexOptions {
@@ -485,6 +492,8 @@ export interface RebuildSqliteSessionIndexOptions extends SqliteSessionIndexOpti
485
492
  * index already in place (another process finished first) discards its own.
486
493
  */
487
494
  readonly force?: boolean
495
+ /** Build the schema only and index no log; a later sync fills it. Opening on demand uses it. */
496
+ readonly empty?: boolean
488
497
  }
489
498
 
490
499
  /**
@@ -520,17 +529,52 @@ export class SqliteSessionIndex extends SessionIndexBase {
520
529
  readonly #sink: IndexSink
521
530
  readonly #statements = new Map<string, StatementSync>()
522
531
  #open = true
523
- /** The catch-up started by `syncInBackground`; reads wait on it. */
532
+ /** The catch-up started by `syncInBackground`, or on the first read under `syncOnDemand`; reads wait on it. */
524
533
  #catchUp: Promise<void> | undefined
534
+ /** The home a first read catches up with, kept only while the catch-up has not started. */
535
+ #pendingHome: string | undefined
536
+
537
+ /** True while opening promised a catch-up that no read has started yet. */
538
+ get syncPending(): boolean {
539
+ return this.#pendingHome !== undefined
540
+ }
541
+
542
+ /** True while a catch-up is reading the logs. */
543
+ get syncing(): boolean {
544
+ return this.#catchUp !== undefined && !this.#caughtUp
545
+ }
546
+ #caughtUp = false
525
547
 
526
548
  #startBackgroundSync(home: string): void {
527
- this.#catchUp = this.syncNow(home).catch(() => {
528
- // A failed catch-up (the index closed, a log vanished mid-read) leaves the
529
- // rows the last sync wrote; the next open syncs again.
530
- })
549
+ this.#pendingHome = undefined
550
+ this.#catchUp = this.syncNow(home)
551
+ .catch(() => {
552
+ // A failed catch-up (the index closed, a log vanished mid-read) leaves the
553
+ // rows the last sync wrote; the next open syncs again.
554
+ })
555
+ .then(() => {
556
+ this.#caughtUp = true
557
+ })
531
558
  }
532
559
 
533
560
  protected override async settled(): Promise<void> {
561
+ if (this.#pendingHome !== undefined) this.#startBackgroundSync(this.#pendingHome)
562
+ await this.#catchUp
563
+ }
564
+
565
+ /**
566
+ * A read about one session before any catch-up has started: bring that session's
567
+ * rows current from its own log and leave the other logs unread. A session with
568
+ * no row yet has no known log, so that read waits for the whole catch-up.
569
+ */
570
+ protected override async settledFor(sessionId: SessionId | undefined): Promise<void> {
571
+ if (this.#pendingHome === undefined || sessionId === undefined) return this.settled()
572
+ const row = this.readSession(sessionId)
573
+ if (row === undefined) return this.settled()
574
+ await this.refreshNow({ sessionId, slug: row.slug, logPath: row.logPath })
575
+ }
576
+
577
+ protected override async settledForWrite(): Promise<void> {
534
578
  await this.#catchUp
535
579
  }
536
580
 
@@ -740,7 +784,9 @@ export class SqliteSessionIndex extends SessionIndexBase {
740
784
  try {
741
785
  configure(db)
742
786
  db.exec(`BEGIN IMMEDIATE; ${SCHEMA} COMMIT;`)
743
- for (const log of await discoverSessionLogs(options.home)) await index.refresh(log)
787
+ if (options.empty !== true) {
788
+ for (const log of await discoverSessionLogs(options.home)) await index.refresh(log)
789
+ }
744
790
  } finally {
745
791
  index.close()
746
792
  }
@@ -764,7 +810,9 @@ export class SqliteSessionIndex extends SessionIndexBase {
764
810
  if (indexVersion(options.path) !== SESSION_INDEX_VERSION) {
765
811
  // Not forced: if another process renames a current index into place
766
812
  // first, this one discards its own and opens that one.
767
- await SqliteSessionIndex.rebuild(options)
813
+ await SqliteSessionIndex.rebuild(
814
+ options.syncOnDemand === true ? { ...options, empty: true } : options,
815
+ )
768
816
  } else {
769
817
  await sweepAbandonedRebuilds(options.path)
770
818
  }
@@ -780,7 +828,8 @@ export class SqliteSessionIndex extends SessionIndexBase {
780
828
  throw error
781
829
  }
782
830
  const index = new SqliteSessionIndex(db, options.path)
783
- if (options.syncInBackground === true) index.#startBackgroundSync(options.home)
831
+ if (options.syncOnDemand === true) index.#pendingHome = options.home
832
+ else if (options.syncInBackground === true) index.#startBackgroundSync(options.home)
784
833
  else await index.sync(options.home)
785
834
  return index
786
835
  }
@@ -885,7 +934,7 @@ export class SqliteSessionIndex extends SessionIndexBase {
885
934
  }
886
935
 
887
936
  async listTurns(sessionId: SessionId): Promise<IndexedTurn[]> {
888
- await this.settled()
937
+ await this.settledFor(sessionId)
889
938
  return this.#all(
890
939
  'SELECT * FROM turns WHERE session_id = ? ORDER BY started_at, id',
891
940
  sessionId,
@@ -893,7 +942,7 @@ export class SqliteSessionIndex extends SessionIndexBase {
893
942
  }
894
943
 
895
944
  async listChildren(sessionId: SessionId): Promise<ChildSessionSummary[]> {
896
- await this.settled()
945
+ await this.settledFor(sessionId)
897
946
  return this.#all(
898
947
  'SELECT * FROM children WHERE session_id = ? ORDER BY spawned_at, child_id',
899
948
  sessionId,
@@ -906,7 +955,7 @@ export class SqliteSessionIndex extends SessionIndexBase {
906
955
  async listPendingDecisions(
907
956
  options: { sessionId?: SessionId } = {},
908
957
  ): Promise<IndexedPendingDecision[]> {
909
- await this.settled()
958
+ await this.settledFor(options.sessionId)
910
959
  const rows =
911
960
  options.sessionId === undefined
912
961
  ? this.#all('SELECT * FROM pending_decisions ORDER BY session_id, decision_id')
@@ -934,7 +983,7 @@ export class SqliteSessionIndex extends SessionIndexBase {
934
983
  }
935
984
 
936
985
  async listExternalRefs(sessionId: SessionId): Promise<ExternalRefTarget[]> {
937
- await this.settled()
986
+ await this.settledFor(sessionId)
938
987
  return this.#all(
939
988
  'SELECT * FROM external_refs WHERE session_id = ? ORDER BY protocol, kind, external_id',
940
989
  sessionId,
@@ -942,7 +991,7 @@ export class SqliteSessionIndex extends SessionIndexBase {
942
991
  }
943
992
 
944
993
  async batches(options: { sessionId?: SessionId } = {}): Promise<IndexedBatch[]> {
945
- await this.settled()
994
+ await this.settledFor(options.sessionId)
946
995
  const rows =
947
996
  options.sessionId === undefined
948
997
  ? this.#all('SELECT * FROM batches ORDER BY session_id, batch_id')
@@ -954,7 +1003,7 @@ export class SqliteSessionIndex extends SessionIndexBase {
954
1003
  }
955
1004
 
956
1005
  async searchEvidence(options: EvidenceSearchOptions): Promise<EvidenceHit[]> {
957
- await this.settled()
1006
+ await this.settledFor(options.sessionId)
958
1007
  const match = evidenceMatcher(options)
959
1008
  const narrowing = ftsMatchExpression(options)
960
1009
  const limit = options.limit ?? 100
@@ -44,6 +44,34 @@ function flag(value: unknown): true | undefined {
44
44
  return value === true ? true : undefined
45
45
  }
46
46
 
47
+ /** The person's own words are kept whole well past an ordinary field's bound. */
48
+ const MAX_ANSWER_TEXT = 20_000
49
+
50
+ function answerText(value: unknown): string | undefined {
51
+ return typeof value === 'string' && value.length <= MAX_ANSWER_TEXT ? value : undefined
52
+ }
53
+
54
+ /**
55
+ * The person's own words, cut rather than dropped past the bound: a dropped
56
+ * field would leave an answered row with nothing after its arrow. The model
57
+ * already has the whole text in the tool result; this is what is drawn.
58
+ */
59
+ function ownWords(value: unknown): string | undefined {
60
+ if (typeof value !== 'string') return undefined
61
+ return value.length <= MAX_ANSWER_TEXT ? value : `${value.slice(0, MAX_ANSWER_TEXT - 1)}…`
62
+ }
63
+
64
+ function labels(value: unknown): readonly string[] | undefined {
65
+ if (!Array.isArray(value) || value.length > 50) return undefined
66
+ const out: string[] = []
67
+ for (const item of value) {
68
+ const label = answerText(item)
69
+ if (label === undefined) return undefined
70
+ out.push(label)
71
+ }
72
+ return out
73
+ }
74
+
47
75
  function pick<T extends object>(entries: Record<string, unknown>): T {
48
76
  const out: Record<string, unknown> = {}
49
77
  for (const [key, value] of Object.entries(entries)) if (value !== undefined) out[key] = value
@@ -210,6 +238,42 @@ export function admitToolFacts(value: unknown): ToolFacts | undefined {
210
238
  generatedImage: generated === undefined ? undefined : { prompt: generated },
211
239
  })
212
240
  }
241
+ case 'questions': {
242
+ const outcome =
243
+ value.outcome === 'discussed'
244
+ ? 'discussed'
245
+ : value.outcome === 'answered'
246
+ ? 'answered'
247
+ : undefined
248
+ if (outcome === undefined || !Array.isArray(value.questions)) return undefined
249
+ if (value.questions.length === 0 || value.questions.length > 8) return undefined
250
+ const questions: {
251
+ question: string
252
+ header?: string
253
+ options?: readonly string[]
254
+ picked?: readonly string[]
255
+ freeText?: string
256
+ answered: boolean
257
+ }[] = []
258
+ for (const entry of value.questions) {
259
+ if (!isRecord(entry)) return undefined
260
+ const question = answerText(entry.question)
261
+ if (question === undefined || typeof entry.answered !== 'boolean') return undefined
262
+ const header = answerText(entry.header)
263
+ const options = labels(entry.options)
264
+ const picked = labels(entry.picked)
265
+ const freeText = ownWords(entry.freeText)
266
+ questions.push({
267
+ question,
268
+ ...(header === undefined ? {} : { header }),
269
+ ...(options === undefined ? {} : { options }),
270
+ ...(picked === undefined ? {} : { picked }),
271
+ ...(freeText === undefined ? {} : { freeText }),
272
+ answered: entry.answered,
273
+ })
274
+ }
275
+ return { kind: 'questions', outcome, questions }
276
+ }
213
277
  case 'failure': {
214
278
  const reason = FAILURE_REASONS.find((candidate) => candidate === value.reason)
215
279
  if (reason === undefined) return undefined
@@ -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),
@@ -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'],