@namzu/sdk 59.0.0 → 60.1.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 (370) hide show
  1. package/CHANGELOG.md +120 -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/bridge/a2a/mapper.d.ts.map +1 -1
  6. package/dist/bridge/a2a/mapper.js +16 -0
  7. package/dist/bridge/a2a/mapper.js.map +1 -1
  8. package/dist/bridge/acp/update.d.ts.map +1 -1
  9. package/dist/bridge/acp/update.js +1 -0
  10. package/dist/bridge/acp/update.js.map +1 -1
  11. package/dist/bridge/sse/mapper.d.ts.map +1 -1
  12. package/dist/bridge/sse/mapper.js +12 -0
  13. package/dist/bridge/sse/mapper.js.map +1 -1
  14. package/dist/compaction/context-window.d.ts +53 -0
  15. package/dist/compaction/context-window.d.ts.map +1 -1
  16. package/dist/compaction/context-window.js +141 -2
  17. package/dist/compaction/context-window.js.map +1 -1
  18. package/dist/constants/continuation.d.ts +9 -0
  19. package/dist/constants/continuation.d.ts.map +1 -1
  20. package/dist/constants/continuation.js +9 -0
  21. package/dist/constants/continuation.js.map +1 -1
  22. package/dist/contracts/session/api.d.ts +7 -1
  23. package/dist/contracts/session/api.d.ts.map +1 -1
  24. package/dist/execution/workflow/index.d.ts +3 -1
  25. package/dist/execution/workflow/index.d.ts.map +1 -1
  26. package/dist/execution/workflow/index.js +2 -1
  27. package/dist/execution/workflow/index.js.map +1 -1
  28. package/dist/execution/workflow/journal.d.ts +24 -4
  29. package/dist/execution/workflow/journal.d.ts.map +1 -1
  30. package/dist/execution/workflow/journal.js +131 -9
  31. package/dist/execution/workflow/journal.js.map +1 -1
  32. package/dist/execution/workflow/prelude.d.ts +2 -0
  33. package/dist/execution/workflow/prelude.d.ts.map +1 -1
  34. package/dist/execution/workflow/prelude.js +49 -8
  35. package/dist/execution/workflow/prelude.js.map +1 -1
  36. package/dist/execution/workflow/resume.d.ts +59 -0
  37. package/dist/execution/workflow/resume.d.ts.map +1 -0
  38. package/dist/execution/workflow/resume.js +273 -0
  39. package/dist/execution/workflow/resume.js.map +1 -0
  40. package/dist/execution/workflow/runtime.d.ts.map +1 -1
  41. package/dist/execution/workflow/runtime.js +112 -8
  42. package/dist/execution/workflow/runtime.js.map +1 -1
  43. package/dist/execution/workflow/types.d.ts +105 -1
  44. package/dist/execution/workflow/types.d.ts.map +1 -1
  45. package/dist/index.d.ts +3 -0
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +4 -0
  48. package/dist/index.js.map +1 -1
  49. package/dist/manager/session/turn-recorder.d.ts.map +1 -1
  50. package/dist/manager/session/turn-recorder.js +1 -0
  51. package/dist/manager/session/turn-recorder.js.map +1 -1
  52. package/dist/plugin/compat.d.ts +24 -0
  53. package/dist/plugin/compat.d.ts.map +1 -0
  54. package/dist/plugin/compat.js +149 -0
  55. package/dist/plugin/compat.js.map +1 -0
  56. package/dist/plugin/loader.d.ts +2 -1
  57. package/dist/plugin/loader.d.ts.map +1 -1
  58. package/dist/plugin/loader.js +6 -0
  59. package/dist/plugin/loader.js.map +1 -1
  60. package/dist/pricing/index.d.ts.map +1 -1
  61. package/dist/pricing/index.js +2 -1
  62. package/dist/pricing/index.js.map +1 -1
  63. package/dist/process/kill-tree.d.ts +44 -0
  64. package/dist/process/kill-tree.d.ts.map +1 -1
  65. package/dist/process/kill-tree.js +102 -4
  66. package/dist/process/kill-tree.js.map +1 -1
  67. package/dist/prompt/coding-agent-doctrine.d.ts +1 -1
  68. package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
  69. package/dist/prompt/coding-agent-doctrine.js +9 -1
  70. package/dist/prompt/coding-agent-doctrine.js.map +1 -1
  71. package/dist/provider/collect-chat-completion.d.ts.map +1 -1
  72. package/dist/provider/collect-chat-completion.js +4 -0
  73. package/dist/provider/collect-chat-completion.js.map +1 -1
  74. package/dist/provider/fallback.d.ts.map +1 -1
  75. package/dist/provider/fallback.js +11 -0
  76. package/dist/provider/fallback.js.map +1 -1
  77. package/dist/provider/idle-timeout.d.ts.map +1 -1
  78. package/dist/provider/idle-timeout.js +5 -0
  79. package/dist/provider/idle-timeout.js.map +1 -1
  80. package/dist/provider/mock.d.ts +2 -0
  81. package/dist/provider/mock.d.ts.map +1 -1
  82. package/dist/provider/mock.js +16 -8
  83. package/dist/provider/mock.js.map +1 -1
  84. package/dist/provider/model-window-suffix.d.ts +18 -0
  85. package/dist/provider/model-window-suffix.d.ts.map +1 -0
  86. package/dist/provider/model-window-suffix.js +78 -0
  87. package/dist/provider/model-window-suffix.js.map +1 -0
  88. package/dist/provider/retry.d.ts.map +1 -1
  89. package/dist/provider/retry.js +5 -0
  90. package/dist/provider/retry.js.map +1 -1
  91. package/dist/public-runtime.d.ts +5 -3
  92. package/dist/public-runtime.d.ts.map +1 -1
  93. package/dist/public-runtime.js +5 -4
  94. package/dist/public-runtime.js.map +1 -1
  95. package/dist/public-types.d.ts +1 -0
  96. package/dist/public-types.d.ts.map +1 -1
  97. package/dist/registry/command/kernel-commands.d.ts +1 -4
  98. package/dist/registry/command/kernel-commands.d.ts.map +1 -1
  99. package/dist/registry/command/kernel-commands.js +0 -28
  100. package/dist/registry/command/kernel-commands.js.map +1 -1
  101. package/dist/runtime/jobs/awaited-jobs.d.ts +6 -0
  102. package/dist/runtime/jobs/awaited-jobs.d.ts.map +1 -1
  103. package/dist/runtime/jobs/awaited-jobs.js +11 -0
  104. package/dist/runtime/jobs/awaited-jobs.js.map +1 -1
  105. package/dist/runtime/jobs/host-exit-finalizer.d.ts +20 -0
  106. package/dist/runtime/jobs/host-exit-finalizer.d.ts.map +1 -0
  107. package/dist/runtime/jobs/host-exit-finalizer.js +57 -0
  108. package/dist/runtime/jobs/host-exit-finalizer.js.map +1 -0
  109. package/dist/runtime/jobs/liveness.d.ts +67 -0
  110. package/dist/runtime/jobs/liveness.d.ts.map +1 -0
  111. package/dist/runtime/jobs/liveness.js +94 -0
  112. package/dist/runtime/jobs/liveness.js.map +1 -0
  113. package/dist/runtime/jobs/registry.d.ts +21 -0
  114. package/dist/runtime/jobs/registry.d.ts.map +1 -1
  115. package/dist/runtime/jobs/registry.js +104 -2
  116. package/dist/runtime/jobs/registry.js.map +1 -1
  117. package/dist/runtime/jobs/wake-budget.d.ts +35 -0
  118. package/dist/runtime/jobs/wake-budget.d.ts.map +1 -0
  119. package/dist/runtime/jobs/wake-budget.js +48 -0
  120. package/dist/runtime/jobs/wake-budget.js.map +1 -0
  121. package/dist/runtime/query/detached-calls.d.ts +65 -0
  122. package/dist/runtime/query/detached-calls.d.ts.map +1 -0
  123. package/dist/runtime/query/detached-calls.js +116 -0
  124. package/dist/runtime/query/detached-calls.js.map +1 -0
  125. package/dist/runtime/query/executor.d.ts +4 -1
  126. package/dist/runtime/query/executor.d.ts.map +1 -1
  127. package/dist/runtime/query/executor.js +90 -6
  128. package/dist/runtime/query/executor.js.map +1 -1
  129. package/dist/runtime/query/index.d.ts +34 -0
  130. package/dist/runtime/query/index.d.ts.map +1 -1
  131. package/dist/runtime/query/index.js +32 -5
  132. package/dist/runtime/query/index.js.map +1 -1
  133. package/dist/runtime/query/iteration/effort-clamp.d.ts +13 -0
  134. package/dist/runtime/query/iteration/effort-clamp.d.ts.map +1 -0
  135. package/dist/runtime/query/iteration/effort-clamp.js +42 -0
  136. package/dist/runtime/query/iteration/effort-clamp.js.map +1 -0
  137. package/dist/runtime/query/iteration/index.d.ts +34 -0
  138. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  139. package/dist/runtime/query/iteration/index.js +199 -6
  140. package/dist/runtime/query/iteration/index.js.map +1 -1
  141. package/dist/runtime/query/iteration/outstanding-work.d.ts.map +1 -1
  142. package/dist/runtime/query/iteration/outstanding-work.js +11 -3
  143. package/dist/runtime/query/iteration/outstanding-work.js.map +1 -1
  144. package/dist/runtime/query/iteration/phases/context.d.ts +9 -0
  145. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  146. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  147. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  148. package/dist/runtime/query/iteration/phases/tool-review.js +63 -1
  149. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  150. package/dist/runtime/query/iteration/stream-turn.d.ts.map +1 -1
  151. package/dist/runtime/query/iteration/stream-turn.js +6 -0
  152. package/dist/runtime/query/iteration/stream-turn.js.map +1 -1
  153. package/dist/runtime/query/session-storage.d.ts.map +1 -1
  154. package/dist/runtime/query/session-storage.js +8 -3
  155. package/dist/runtime/query/session-storage.js.map +1 -1
  156. package/dist/runtime/query/steering.d.ts +29 -3
  157. package/dist/runtime/query/steering.d.ts.map +1 -1
  158. package/dist/runtime/query/steering.js +58 -3
  159. package/dist/runtime/query/steering.js.map +1 -1
  160. package/dist/runtime/query/tooling.d.ts +1 -0
  161. package/dist/runtime/query/tooling.d.ts.map +1 -1
  162. package/dist/runtime/query/tooling.js +1 -0
  163. package/dist/runtime/query/tooling.js.map +1 -1
  164. package/dist/runtime/system-events.d.ts +5 -0
  165. package/dist/runtime/system-events.d.ts.map +1 -1
  166. package/dist/runtime/system-events.js +7 -1
  167. package/dist/runtime/system-events.js.map +1 -1
  168. package/dist/sandbox/denial.d.ts +11 -0
  169. package/dist/sandbox/denial.d.ts.map +1 -0
  170. package/dist/sandbox/denial.js +61 -0
  171. package/dist/sandbox/denial.js.map +1 -0
  172. package/dist/sandbox/file-walk-program.d.ts.map +1 -1
  173. package/dist/sandbox/file-walk-program.js +31 -13
  174. package/dist/sandbox/file-walk-program.js.map +1 -1
  175. package/dist/sandbox/file-walk.d.ts +2 -0
  176. package/dist/sandbox/file-walk.d.ts.map +1 -1
  177. package/dist/sandbox/file-walk.js +64 -13
  178. package/dist/sandbox/file-walk.js.map +1 -1
  179. package/dist/sandbox/ignore-matcher.d.ts +30 -0
  180. package/dist/sandbox/ignore-matcher.d.ts.map +1 -0
  181. package/dist/sandbox/ignore-matcher.js +11 -0
  182. package/dist/sandbox/ignore-matcher.js.map +1 -0
  183. package/dist/sandbox/ignore-source.d.ts +26 -0
  184. package/dist/sandbox/ignore-source.d.ts.map +1 -0
  185. package/dist/sandbox/ignore-source.js +221 -0
  186. package/dist/sandbox/ignore-source.js.map +1 -0
  187. package/dist/sandbox/provider/local.d.ts.map +1 -1
  188. package/dist/sandbox/provider/local.js +11 -1
  189. package/dist/sandbox/provider/local.js.map +1 -1
  190. package/dist/scheduler/completion-inbox.d.ts.map +1 -1
  191. package/dist/scheduler/completion-inbox.js +1 -0
  192. package/dist/scheduler/completion-inbox.js.map +1 -1
  193. package/dist/session/log-hash.d.ts.map +1 -1
  194. package/dist/session/log-hash.js +18 -1
  195. package/dist/session/log-hash.js.map +1 -1
  196. package/dist/store/memory/disk.d.ts.map +1 -1
  197. package/dist/store/memory/disk.js +1 -1
  198. package/dist/store/memory/disk.js.map +1 -1
  199. package/dist/store/memory/markdown.d.ts.map +1 -1
  200. package/dist/store/memory/markdown.js +1 -1
  201. package/dist/store/memory/markdown.js.map +1 -1
  202. package/dist/store/memory/operation-lock.d.ts +20 -4
  203. package/dist/store/memory/operation-lock.d.ts.map +1 -1
  204. package/dist/store/memory/operation-lock.js +235 -58
  205. package/dist/store/memory/operation-lock.js.map +1 -1
  206. package/dist/store/session-index/sqlite.d.ts.map +1 -1
  207. package/dist/store/session-index/sqlite.js +169 -16
  208. package/dist/store/session-index/sqlite.js.map +1 -1
  209. package/dist/tools/builtins/bash.d.ts.map +1 -1
  210. package/dist/tools/builtins/bash.js +10 -4
  211. package/dist/tools/builtins/bash.js.map +1 -1
  212. package/dist/tools/builtins/computer-use.d.ts +35 -0
  213. package/dist/tools/builtins/computer-use.d.ts.map +1 -1
  214. package/dist/tools/builtins/computer-use.js +512 -67
  215. package/dist/tools/builtins/computer-use.js.map +1 -1
  216. package/dist/tools/builtins/glob.d.ts +1 -0
  217. package/dist/tools/builtins/glob.d.ts.map +1 -1
  218. package/dist/tools/builtins/glob.js +65 -28
  219. package/dist/tools/builtins/glob.js.map +1 -1
  220. package/dist/tools/builtins/grep.d.ts +2 -0
  221. package/dist/tools/builtins/grep.d.ts.map +1 -1
  222. package/dist/tools/builtins/grep.js +94 -40
  223. package/dist/tools/builtins/grep.js.map +1 -1
  224. package/dist/tools/builtins/job.d.ts +1 -1
  225. package/dist/tools/builtins/job.d.ts.map +1 -1
  226. package/dist/tools/builtins/job.js +34 -7
  227. package/dist/tools/builtins/job.js.map +1 -1
  228. package/dist/tools/builtins/search-support.d.ts +44 -0
  229. package/dist/tools/builtins/search-support.d.ts.map +1 -0
  230. package/dist/tools/builtins/search-support.js +89 -0
  231. package/dist/tools/builtins/search-support.js.map +1 -0
  232. package/dist/tools/builtins/wait-for-job-bounds.d.ts +2 -0
  233. package/dist/tools/builtins/wait-for-job-bounds.d.ts.map +1 -1
  234. package/dist/tools/builtins/wait-for-job-bounds.js +3 -1
  235. package/dist/tools/builtins/wait-for-job-bounds.js.map +1 -1
  236. package/dist/tools/builtins/wait-for-job.d.ts +1 -1
  237. package/dist/tools/builtins/wait-for-job.d.ts.map +1 -1
  238. package/dist/tools/builtins/wait-for-job.js +13 -2
  239. package/dist/tools/builtins/wait-for-job.js.map +1 -1
  240. package/dist/tools/command-shell.d.ts.map +1 -1
  241. package/dist/tools/command-shell.js +14 -5
  242. package/dist/tools/command-shell.js.map +1 -1
  243. package/dist/turn/reporter.d.ts.map +1 -1
  244. package/dist/turn/reporter.js +11 -0
  245. package/dist/turn/reporter.js.map +1 -1
  246. package/dist/types/agent/query.d.ts +2 -0
  247. package/dist/types/agent/query.d.ts.map +1 -1
  248. package/dist/types/computer-use/index.d.ts +129 -13
  249. package/dist/types/computer-use/index.d.ts.map +1 -1
  250. package/dist/types/computer-use/index.js.map +1 -1
  251. package/dist/types/message/index.d.ts +1 -1
  252. package/dist/types/message/index.d.ts.map +1 -1
  253. package/dist/types/message/index.js +1 -0
  254. package/dist/types/message/index.js.map +1 -1
  255. package/dist/types/plugin/index.d.ts +24 -0
  256. package/dist/types/plugin/index.d.ts.map +1 -1
  257. package/dist/types/plugin/index.js +4 -0
  258. package/dist/types/plugin/index.js.map +1 -1
  259. package/dist/types/provider/chat.d.ts +19 -0
  260. package/dist/types/provider/chat.d.ts.map +1 -1
  261. package/dist/types/provider/config.d.ts +7 -0
  262. package/dist/types/provider/config.d.ts.map +1 -1
  263. package/dist/types/provider/index.d.ts +1 -1
  264. package/dist/types/provider/index.d.ts.map +1 -1
  265. package/dist/types/provider/interface.d.ts +15 -0
  266. package/dist/types/provider/interface.d.ts.map +1 -1
  267. package/dist/types/provider/stream.d.ts +6 -0
  268. package/dist/types/provider/stream.d.ts.map +1 -1
  269. package/dist/types/sandbox/index.d.ts +38 -1
  270. package/dist/types/sandbox/index.d.ts.map +1 -1
  271. package/dist/types/sandbox/index.js.map +1 -1
  272. package/dist/types/session/events.d.ts +34 -0
  273. package/dist/types/session/events.d.ts.map +1 -1
  274. package/dist/types/session/events.js.map +1 -1
  275. package/dist/types/session/records.d.ts +298 -34
  276. package/dist/types/session/records.d.ts.map +1 -1
  277. package/dist/types/session/records.js +35 -1
  278. package/dist/types/session/records.js.map +1 -1
  279. package/dist/types/session/stop-reason.d.ts +11 -0
  280. package/dist/types/session/stop-reason.d.ts.map +1 -1
  281. package/dist/types/tool/index.d.ts +30 -0
  282. package/dist/types/tool/index.d.ts.map +1 -1
  283. package/dist/types/tool/index.js.map +1 -1
  284. package/dist/types/tool/presentation.d.ts +8 -0
  285. package/dist/types/tool/presentation.d.ts.map +1 -1
  286. package/package.json +1 -1
  287. package/src/agents/QueryAgent.ts +1 -0
  288. package/src/bridge/a2a/mapper.ts +19 -0
  289. package/src/bridge/acp/update.ts +6 -1
  290. package/src/bridge/sse/mapper.ts +13 -0
  291. package/src/compaction/context-window.ts +163 -2
  292. package/src/constants/continuation.ts +13 -0
  293. package/src/contracts/session/api.ts +6 -0
  294. package/src/execution/workflow/index.ts +14 -1
  295. package/src/execution/workflow/journal.ts +161 -11
  296. package/src/execution/workflow/prelude.ts +51 -8
  297. package/src/execution/workflow/resume.ts +313 -0
  298. package/src/execution/workflow/runtime.ts +127 -9
  299. package/src/execution/workflow/types.ts +109 -1
  300. package/src/index.ts +17 -0
  301. package/src/manager/session/turn-recorder.ts +1 -0
  302. package/src/plugin/compat.ts +173 -0
  303. package/src/plugin/loader.ts +7 -1
  304. package/src/pricing/index.ts +2 -1
  305. package/src/process/kill-tree.ts +106 -4
  306. package/src/prompt/coding-agent-doctrine.ts +9 -1
  307. package/src/provider/collect-chat-completion.ts +3 -0
  308. package/src/provider/fallback.ts +17 -0
  309. package/src/provider/idle-timeout.ts +9 -0
  310. package/src/provider/mock.ts +19 -9
  311. package/src/provider/model-window-suffix.ts +85 -0
  312. package/src/provider/retry.ts +9 -0
  313. package/src/public-runtime.ts +21 -2
  314. package/src/public-types.ts +1 -0
  315. package/src/registry/command/kernel-commands.ts +1 -32
  316. package/src/runtime/jobs/awaited-jobs.ts +11 -0
  317. package/src/runtime/jobs/host-exit-finalizer.ts +67 -0
  318. package/src/runtime/jobs/liveness.ts +144 -0
  319. package/src/runtime/jobs/registry.ts +114 -2
  320. package/src/runtime/jobs/wake-budget.ts +55 -0
  321. package/src/runtime/query/detached-calls.ts +135 -0
  322. package/src/runtime/query/executor.ts +92 -10
  323. package/src/runtime/query/index.ts +65 -7
  324. package/src/runtime/query/iteration/effort-clamp.ts +46 -0
  325. package/src/runtime/query/iteration/index.ts +260 -6
  326. package/src/runtime/query/iteration/outstanding-work.ts +12 -3
  327. package/src/runtime/query/iteration/phases/context.ts +9 -0
  328. package/src/runtime/query/iteration/phases/tool-review.ts +73 -8
  329. package/src/runtime/query/iteration/stream-turn.ts +5 -0
  330. package/src/runtime/query/session-storage.ts +8 -3
  331. package/src/runtime/query/steering.ts +77 -6
  332. package/src/runtime/query/tooling.ts +2 -0
  333. package/src/runtime/system-events.ts +12 -1
  334. package/src/sandbox/denial.ts +79 -0
  335. package/src/sandbox/file-walk-program.ts +32 -13
  336. package/src/sandbox/file-walk.ts +75 -12
  337. package/src/sandbox/ignore-matcher.ts +46 -0
  338. package/src/sandbox/ignore-source.ts +220 -0
  339. package/src/sandbox/provider/local.ts +11 -1
  340. package/src/scheduler/completion-inbox.ts +1 -0
  341. package/src/session/log-hash.ts +21 -0
  342. package/src/store/memory/disk.ts +1 -0
  343. package/src/store/memory/markdown.ts +1 -0
  344. package/src/store/memory/operation-lock.ts +288 -57
  345. package/src/store/session-index/sqlite.ts +171 -16
  346. package/src/tools/builtins/bash.ts +11 -4
  347. package/src/tools/builtins/computer-use.ts +593 -68
  348. package/src/tools/builtins/glob.ts +79 -32
  349. package/src/tools/builtins/grep.ts +107 -43
  350. package/src/tools/builtins/job.ts +42 -12
  351. package/src/tools/builtins/search-support.ts +107 -0
  352. package/src/tools/builtins/wait-for-job-bounds.ts +5 -1
  353. package/src/tools/builtins/wait-for-job.ts +14 -2
  354. package/src/tools/command-shell.ts +13 -5
  355. package/src/turn/reporter.ts +12 -0
  356. package/src/types/agent/query.ts +2 -0
  357. package/src/types/computer-use/index.ts +157 -15
  358. package/src/types/message/index.ts +5 -3
  359. package/src/types/plugin/index.ts +8 -0
  360. package/src/types/provider/chat.ts +20 -0
  361. package/src/types/provider/config.ts +7 -0
  362. package/src/types/provider/index.ts +1 -0
  363. package/src/types/provider/interface.ts +20 -0
  364. package/src/types/provider/stream.ts +6 -0
  365. package/src/types/sandbox/index.ts +40 -1
  366. package/src/types/session/events.ts +65 -5
  367. package/src/types/session/records.ts +39 -2
  368. package/src/types/session/stop-reason.ts +11 -0
  369. package/src/types/tool/index.ts +30 -0
  370. package/src/types/tool/presentation.ts +8 -0
@@ -71,6 +71,7 @@ import type { Logger } from '../../utils/logger.js'
71
71
  import { compressShellOutput } from '../../utils/shell-compress.js'
72
72
  import { parseStructuredResultJson } from '../../utils/structured-result-json.js'
73
73
  import { type BackgroundJobRegistry, type JobProcess, bindOwner } from '../jobs/registry.js'
74
+ import { type BatchDetach, stillRunningResult } from './detached-calls.js'
74
75
  import {
75
76
  type ToolAdmissionHost,
76
77
  formatFailedToolOutput,
@@ -412,6 +413,8 @@ export interface ToolExecutorConfig {
412
413
  * recorder gets no hold rather than a marking call that goes nowhere.
413
414
  */
414
415
  onJobAwaited?: (id: string) => void
416
+ /** Where a tool result that handed the model a job's exit says so; see `ToolContext.backgroundJobs.markCollected`. */
417
+ onJobCollected?: (id: string) => void
415
418
  /** The longest a monitor may live in this turn; see `QueryParams.monitorTimeoutCapMs`. */
416
419
  monitorTimeoutCapMs?: number
417
420
  /**
@@ -1429,6 +1432,7 @@ export class ToolExecutor {
1429
1432
  preparedBatch?: PreparedToolBatch,
1430
1433
  declines?: ToolCallDeclines,
1431
1434
  review?: ReviewedExecution,
1435
+ detach?: BatchDetach,
1432
1436
  ): Promise<ToolExecutionBatch> {
1433
1437
  const toolCalls = response.message.toolCalls
1434
1438
  if (!toolCalls) {
@@ -1455,9 +1459,9 @@ export class ToolExecutor {
1455
1459
  if (refusal) {
1456
1460
  const refused = new Map(denials)
1457
1461
  for (const call of toolCalls) if (!refused.has(call.id)) refused.set(call.id, refusal)
1458
- return await this.runBatch(toolCalls, refused, prior, owned, declines, review)
1462
+ return await this.runBatch(toolCalls, refused, prior, owned, declines, review, detach)
1459
1463
  }
1460
- return await this.runBatch(toolCalls, denials, prior, owned, declines, review)
1464
+ return await this.runBatch(toolCalls, denials, prior, owned, declines, review, detach)
1461
1465
  } finally {
1462
1466
  // Cleared so a later single execution outside a batch resolves
1463
1467
  // live rather than inheriting the last batch's sample.
@@ -1472,6 +1476,7 @@ export class ToolExecutor {
1472
1476
  preparedBatch?: OwnedPreparedToolBatch,
1473
1477
  declines?: ToolCallDeclines,
1474
1478
  review?: ReviewedExecution,
1479
+ detach?: BatchDetach,
1475
1480
  ): Promise<ToolExecutionBatch> {
1476
1481
  this.log.debug('Executing tool batch', {
1477
1482
  [NAMZU.TURN_ID]: this.config.turnId,
@@ -1507,6 +1512,17 @@ export class ToolExecutor {
1507
1512
  // (which let the last writer clobber the rest). Results are written by
1508
1513
  // index to preserve the original tool-call order.
1509
1514
  const results: ToolCallOutcome[] = new Array(toolCalls.length)
1515
+ // Calls handed back to the model as still running (see `detach`), and the
1516
+ // ones among them whose real outcome has been reported.
1517
+ const handedBack = new Set<string>()
1518
+ const reported = new Set<string>()
1519
+ // Calls that have begun; one queued behind a serial or barrier call has not.
1520
+ const started = new Set<string>()
1521
+ const reportLate = (outcome: ToolCallOutcome): void => {
1522
+ if (reported.has(outcome.toolCallId)) return
1523
+ reported.add(outcome.toolCallId)
1524
+ detach?.calls.settle(outcome)
1525
+ }
1510
1526
  const parallel: Promise<void>[] = []
1511
1527
  let serial: Promise<void> = Promise.resolve()
1512
1528
  let barrier: Promise<void> | undefined
@@ -1623,13 +1639,32 @@ export class ToolExecutor {
1623
1639
  }
1624
1640
  const run = async () => {
1625
1641
  try {
1626
- results[i] = await this.executeSingle(
1627
- toolCall,
1628
- ctx,
1629
- recordObservation,
1630
- () => progress.close(),
1631
- preparedCall,
1632
- )
1642
+ let outcome: ToolCallOutcome
1643
+ started.add(toolCall.id)
1644
+ try {
1645
+ outcome = await this.executeSingle(
1646
+ toolCall,
1647
+ ctx,
1648
+ recordObservation,
1649
+ () => progress.close(),
1650
+ preparedCall,
1651
+ )
1652
+ } catch (error) {
1653
+ // A call already answered with the placeholder has no batch
1654
+ // left to fail; its failure is its outcome.
1655
+ if (!handedBack.has(toolCall.id)) throw error
1656
+ reportLate({
1657
+ toolCallId: toolCall.id,
1658
+ toolName: toolCall.function.name,
1659
+ output: `Error: Tool "${toolCall.function.name}" did not complete — ${
1660
+ error instanceof Error ? error.message : String(error)
1661
+ }`,
1662
+ isError: true,
1663
+ })
1664
+ return
1665
+ }
1666
+ if (handedBack.has(toolCall.id)) reportLate(outcome)
1667
+ else results[i] = outcome
1633
1668
  } finally {
1634
1669
  await progress.close()
1635
1670
  }
@@ -1664,7 +1699,46 @@ export class ToolExecutor {
1664
1699
  schedule(safe ? gated : run, safe, isBarrier)
1665
1700
  })
1666
1701
  if (review) await this.walkReviewed(reviewUnits, results, review)
1667
- await Promise.all([...parallel, serial])
1702
+ const completion = Promise.all([...parallel, serial])
1703
+ if (detach && !review) {
1704
+ const first = await Promise.race([
1705
+ completion.then(() => 'finished' as const),
1706
+ detach.requested.then(() => 'requested' as const),
1707
+ ])
1708
+ if (first === 'requested' && toolCalls.some((_, i) => results[i] === undefined)) {
1709
+ // The operator wrote while calls were still running. Answer each
1710
+ // unfinished call with the placeholder so the model can read the
1711
+ // message now; the calls keep running and report themselves.
1712
+ toolCalls.forEach((toolCall, i) => {
1713
+ if (results[i]) return
1714
+ handedBack.add(toolCall.id)
1715
+ detach.calls.begin(toolCall.id, toolCall.function.name)
1716
+ results[i] = {
1717
+ toolCallId: toolCall.id,
1718
+ toolName: toolCall.function.name,
1719
+ output: stillRunningResult(toolCall.function.name, started.has(toolCall.id)),
1720
+ isError: false,
1721
+ }
1722
+ })
1723
+ const settleRest = (): void => {
1724
+ for (const id of handedBack) {
1725
+ if (reported.has(id)) continue
1726
+ const name = toolCalls.find((call) => call.id === id)?.function.name ?? 'tool'
1727
+ reportLate({
1728
+ toolCallId: id,
1729
+ toolName: name,
1730
+ output: `Error: Tool "${name}" did not complete — the batch failed before it produced a result.`,
1731
+ isError: true,
1732
+ })
1733
+ }
1734
+ }
1735
+ completion.then(settleRest, settleRest)
1736
+ } else {
1737
+ await completion
1738
+ }
1739
+ } else {
1740
+ await completion
1741
+ }
1668
1742
 
1669
1743
  // Whatever failed above left a hole in `results`; fill every one, so
1670
1744
  // the invariant holds by construction rather than by everything having
@@ -2205,6 +2279,13 @@ export class ToolExecutor {
2205
2279
  ...(this.config.additionalDirectories?.length
2206
2280
  ? { additionalDirectories: this.config.additionalDirectories }
2207
2281
  : {}),
2282
+ ...(this.config.authorizationGate
2283
+ ? {
2284
+ readDenied: (absolutePath: string) =>
2285
+ this.evaluatePreparedAuthorization('read', { path: absolutePath })?.decision ===
2286
+ 'deny',
2287
+ }
2288
+ : {}),
2208
2289
  ...(this.outputDirectory()
2209
2290
  ? { retainedOutputDirectory: this.outputDirectory() as string }
2210
2291
  : {}),
@@ -2300,6 +2381,7 @@ export class ToolExecutor {
2300
2381
  }
2301
2382
  : {}),
2302
2383
  ...(this.config.onJobAwaited ? { onAwaited: this.config.onJobAwaited } : {}),
2384
+ ...(this.config.onJobCollected ? { onCollected: this.config.onJobCollected } : {}),
2303
2385
  ...(this.config.monitorTimeoutCapMs !== undefined
2304
2386
  ? { monitorTimeoutCapMs: this.config.monitorTimeoutCapMs }
2305
2387
  : {}),
@@ -113,6 +113,7 @@ import {
113
113
  SandboxAcquisitionStopped,
114
114
  createDeferredSandbox,
115
115
  } from './deferred-sandbox.js'
116
+ import { DetachedCalls } from './detached-calls.js'
116
117
  import type { EventTranslator } from './events.js'
117
118
  import { finalizeTurn } from './finalize-turn.js'
118
119
  import { GuardCoordinator } from './guard.js'
@@ -150,6 +151,7 @@ import { acquireSandbox } from './sandbox-lifecycle.js'
150
151
  import {
151
152
  SteeringBinding,
152
153
  type SteeringChannel,
154
+ formatJobExitNotice,
153
155
  formatMonitorEnd,
154
156
  formatMonitorEvent,
155
157
  isOperatorUserMessage,
@@ -375,6 +377,20 @@ export interface QueryParams {
375
377
  * before; `0` stops at the first cut-off.
376
378
  */
377
379
  maxOutputContinuations?: number
380
+ /**
381
+ * What the turn does when the model declines to answer (its provider
382
+ * finished the reply as a refusal or a safety block).
383
+ *
384
+ * `'auto'` (the default) re-runs the refused request once on another model
385
+ * of the same provider (the one the provider recommends, or the one its
386
+ * own fallback order names) and keeps that model for the rest of the turn;
387
+ * a `model_refusal` event names the swap so a host can keep it for later
388
+ * turns. `'off'` never changes the model: the turn tries once more on the
389
+ * same model only when the refused reply had partial output, and otherwise
390
+ * settles with stop reason `'refused'`. A refused reply is never added to
391
+ * the history sent next.
392
+ */
393
+ refusalFallback?: 'auto' | 'off'
378
394
 
379
395
  /**
380
396
  * Model-visible size cap for a single tool result. Over-budget output is
@@ -808,6 +824,28 @@ export interface QueryParams {
808
824
  */
809
825
  waitForInbound?: (signal: AbortSignal) => Promise<void>
810
826
 
827
+ /**
828
+ * Answer the operator while a long tool call is still running.
829
+ *
830
+ * Default off. When on, and `waitForOperator` reports the operator wrote while
831
+ * a batch had been running for two seconds, each call not yet finished is answered with a "still running"
832
+ * placeholder so the model can read the message and reply at once. The
833
+ * calls are not interrupted and not repeated: their real results reach the
834
+ * model later in a message that names each call, and the turn is held open
835
+ * for them like any outstanding work. The host's wake is then also consulted
836
+ * during tool batches, not only when the turn would otherwise end. Ignored
837
+ * under per-call review, where the batch is waiting on a person.
838
+ */
839
+ answerWhileCallsRun?: boolean
840
+
841
+ /**
842
+ * Resolve when the operator wrote, and for no other reason. It is what
843
+ * `answerWhileCallsRun` listens to: a notice from a child agent or mail from
844
+ * a peer also wakes `waitForInbound`, but must not hand a running call back.
845
+ * Abort removes the waiter, as for `waitForInbound`.
846
+ */
847
+ waitForOperator?: (signal: AbortSignal) => Promise<void>
848
+
811
849
  /** Durable host input: normal append, flush and exact acknowledgement before inference. Requires sessionLog. */
812
850
  durableInbound?: DurableInboundSource
813
851
 
@@ -1484,6 +1522,21 @@ export async function* query(params: QueryParams): AsyncGenerator<SessionEvent,
1484
1522
  )
1485
1523
  : undefined
1486
1524
  awaitedJobs?.attach()
1525
+ // A tool result has handed the model this job's exit: the notice that
1526
+ // would announce the same exit is taken back, and the host is told it was
1527
+ // delivered so the session does not wake the model for it either.
1528
+ const collectJob = (id: string): void => {
1529
+ const withdrawn = jobNotices?.withdraw(id) ?? false
1530
+ awaitedJobs?.collected(id)
1531
+ if (!pendingJobNoticeIds.delete(id) && !withdrawn) return
1532
+ try {
1533
+ params.onJobNoticeDelivered?.([id])
1534
+ } catch (error) {
1535
+ ctx.log.warn('A background job notice observer failed', {
1536
+ 'exception.message': error instanceof Error ? error.message : String(error),
1537
+ })
1538
+ }
1539
+ }
1487
1540
 
1488
1541
  // Turn-scoped, like `toolGrants` below: what a skill loaded in this turn
1489
1542
  // pre-approves ends with the turn. Shared by the executor, where the
@@ -1513,6 +1566,7 @@ export async function* query(params: QueryParams): AsyncGenerator<SessionEvent,
1513
1566
  ...(params.backgroundJobs ? { backgroundJobs: params.backgroundJobs } : {}),
1514
1567
  ...(params.backgroundJobOwner ? { backgroundJobOwner: params.backgroundJobOwner } : {}),
1515
1568
  ...(awaitedJobs ? { onJobAwaited: (id: string) => awaitedJobs.expect(id) } : {}),
1569
+ ...(awaitedJobs ? { onJobCollected: collectJob } : {}),
1516
1570
  ...(awaitedJobs ? { onMonitorStarted: (id: string) => awaitedJobs.expectMonitor(id) } : {}),
1517
1571
  ...(params.monitorTimeoutCapMs !== undefined
1518
1572
  ? { monitorTimeoutCapMs: params.monitorTimeoutCapMs }
@@ -1611,13 +1665,13 @@ export async function* query(params: QueryParams): AsyncGenerator<SessionEvent,
1611
1665
  .catch(() => {})
1612
1666
  return
1613
1667
  }
1614
- const outcome =
1615
- job.status === 'killed'
1616
- ? 'was stopped'
1617
- : `exited with code ${job.exitCode ?? 'unknown'}${job.signal ? ` (${job.signal})` : ''}`
1618
- jobNotices?.steer(
1619
- `Background job ${job.id} (${job.command}) ${outcome}. Read its output with the job tool if you need it.`,
1620
- )
1668
+ let inlineOutput: ReturnType<NonNullable<typeof params.backgroundJobs>['read']> | undefined
1669
+ try {
1670
+ inlineOutput = params.backgroundJobs?.read(job.id)
1671
+ } catch {
1672
+ // The record is gone; the notice still stands without its output.
1673
+ }
1674
+ jobNotices?.steer(formatJobExitNotice(job, inlineOutput), job.id)
1621
1675
  pendingJobNoticeIds.add(job.id)
1622
1676
  void eventTranslator
1623
1677
  .emitEvent({
@@ -1821,6 +1875,9 @@ export async function* query(params: QueryParams): AsyncGenerator<SessionEvent,
1821
1875
  ...(monitorNotices ? { monitorNotices } : {}),
1822
1876
  ...(monitorNotices ? { onMonitorNoticeDelivered: acknowledgeMonitorNotices } : {}),
1823
1877
  ...(awaitedJobs ? { awaitedJobs } : {}),
1878
+ ...(params.answerWhileCallsRun && params.waitForOperator
1879
+ ? { detachedCalls: new DetachedCalls(params.waitForOperator) }
1880
+ : {}),
1824
1881
  checkpointMgr,
1825
1882
  planManager: ctx.planManager,
1826
1883
  taskGateway: taskScheduler,
@@ -1840,6 +1897,7 @@ export async function* query(params: QueryParams): AsyncGenerator<SessionEvent,
1840
1897
  ...(params.maxOutputContinuations !== undefined
1841
1898
  ? { maxOutputContinuations: params.maxOutputContinuations }
1842
1899
  : {}),
1900
+ ...(params.refusalFallback !== undefined ? { refusalFallback: params.refusalFallback } : {}),
1843
1901
  ...(params.inboundMessages ? { inboundMessages: params.inboundMessages } : {}),
1844
1902
  ...(params.reminders ? { reminders: params.reminders } : {}),
1845
1903
  ...(params.durableInbound ? { durableInbound: params.durableInbound } : {}),
@@ -0,0 +1,46 @@
1
+ import type { LLMProvider, ReasoningEffort, ThinkingConfig } from '../../../types/provider/index.js'
2
+
3
+ /** Lowest to highest, the order the effort menus are drawn in. */
4
+ const EFFORT_ORDER: readonly ReasoningEffort[] = [
5
+ 'none',
6
+ 'minimal',
7
+ 'low',
8
+ 'medium',
9
+ 'high',
10
+ 'xhigh',
11
+ 'max',
12
+ 'ultra',
13
+ ]
14
+
15
+ /**
16
+ * The effort to send to `model` when the turn was configured for another one.
17
+ *
18
+ * A level the model does not offer is rejected by some drivers, so a request
19
+ * moved to a different model (a refusal fallback, a live model pick) carries
20
+ * the nearest level that model supports: the next one down when there is one,
21
+ * otherwise the lowest one above. The menu comes from the provider, never from
22
+ * a copy here. A provider that cannot say what the model offers, or a level
23
+ * the model already offers, leaves the effort exactly as configured.
24
+ */
25
+ export function effortForModel(
26
+ provider: LLMProvider,
27
+ model: string,
28
+ effort: ReasoningEffort,
29
+ thinking?: ThinkingConfig,
30
+ ): ReasoningEffort {
31
+ let menu: readonly ReasoningEffort[] | undefined
32
+ try {
33
+ menu = provider.reasoningEffortLevelsFor
34
+ ? provider.reasoningEffortLevelsFor(model, thinking)
35
+ : provider.effortLevelsFor?.(model, thinking)
36
+ } catch {
37
+ return effort
38
+ }
39
+ if (!menu || menu.length === 0 || menu.includes(effort)) return effort
40
+ const rank = (level: ReasoningEffort) => EFFORT_ORDER.indexOf(level)
41
+ const wanted = rank(effort)
42
+ if (wanted < 0) return effort
43
+ const ranked = menu.filter((level) => rank(level) >= 0).sort((a, b) => rank(a) - rank(b))
44
+ const below = ranked.filter((level) => rank(level) < wanted)
45
+ return below[below.length - 1] ?? ranked[0] ?? effort
46
+ }