strands-darwin 0.0.3

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 (417) hide show
  1. package/README.md +140 -0
  2. package/README.zh-CN.md +140 -0
  3. package/dist/patches/@strands-agents+sdk+1.16.0.patch +1443 -0
  4. package/dist/src/agent/background-delegation.d.ts +67 -0
  5. package/dist/src/agent/background-delegation.js +159 -0
  6. package/dist/src/agent/background-delegation.js.map +1 -0
  7. package/dist/src/agent/call-stats.d.ts +118 -0
  8. package/dist/src/agent/call-stats.js +128 -0
  9. package/dist/src/agent/call-stats.js.map +1 -0
  10. package/dist/src/agent/compact.d.ts +108 -0
  11. package/dist/src/agent/compact.js +192 -0
  12. package/dist/src/agent/compact.js.map +1 -0
  13. package/dist/src/agent/context-anchor.d.ts +64 -0
  14. package/dist/src/agent/context-anchor.js +43 -0
  15. package/dist/src/agent/context-anchor.js.map +1 -0
  16. package/dist/src/agent/cost.d.ts +56 -0
  17. package/dist/src/agent/cost.js +44 -0
  18. package/dist/src/agent/cost.js.map +1 -0
  19. package/dist/src/agent/diagnostics.d.ts +212 -0
  20. package/dist/src/agent/diagnostics.js +374 -0
  21. package/dist/src/agent/diagnostics.js.map +1 -0
  22. package/dist/src/agent/instructions.d.ts +54 -0
  23. package/dist/src/agent/instructions.js +118 -0
  24. package/dist/src/agent/instructions.js.map +1 -0
  25. package/dist/src/agent/max-tokens-recovery.d.ts +17 -0
  26. package/dist/src/agent/max-tokens-recovery.js +65 -0
  27. package/dist/src/agent/max-tokens-recovery.js.map +1 -0
  28. package/dist/src/agent/model-call-budget.d.ts +8 -0
  29. package/dist/src/agent/model-call-budget.js +24 -0
  30. package/dist/src/agent/model-call-budget.js.map +1 -0
  31. package/dist/src/agent/model-retry.d.ts +134 -0
  32. package/dist/src/agent/model-retry.js +256 -0
  33. package/dist/src/agent/model-retry.js.map +1 -0
  34. package/dist/src/agent/permission-rules.d.ts +47 -0
  35. package/dist/src/agent/permission-rules.js +260 -0
  36. package/dist/src/agent/permission-rules.js.map +1 -0
  37. package/dist/src/agent/permission.d.ts +361 -0
  38. package/dist/src/agent/permission.js +797 -0
  39. package/dist/src/agent/permission.js.map +1 -0
  40. package/dist/src/agent/prompt-cache.d.ts +66 -0
  41. package/dist/src/agent/prompt-cache.js +194 -0
  42. package/dist/src/agent/prompt-cache.js.map +1 -0
  43. package/dist/src/agent/refusal.d.ts +20 -0
  44. package/dist/src/agent/refusal.js +23 -0
  45. package/dist/src/agent/refusal.js.map +1 -0
  46. package/dist/src/agent/retry-guard.d.ts +26 -0
  47. package/dist/src/agent/retry-guard.js +193 -0
  48. package/dist/src/agent/retry-guard.js.map +1 -0
  49. package/dist/src/agent/rewind.d.ts +29 -0
  50. package/dist/src/agent/rewind.js +118 -0
  51. package/dist/src/agent/rewind.js.map +1 -0
  52. package/dist/src/agent/runtime.d.ts +814 -0
  53. package/dist/src/agent/runtime.js +1596 -0
  54. package/dist/src/agent/runtime.js.map +1 -0
  55. package/dist/src/agent/safety-classifier.d.ts +11 -0
  56. package/dist/src/agent/safety-classifier.js +0 -0
  57. package/dist/src/agent/safety-classifier.js.map +1 -0
  58. package/dist/src/agent/sdk-logging.d.ts +49 -0
  59. package/dist/src/agent/sdk-logging.js +110 -0
  60. package/dist/src/agent/sdk-logging.js.map +1 -0
  61. package/dist/src/agent/session.d.ts +102 -0
  62. package/dist/src/agent/session.js +244 -0
  63. package/dist/src/agent/session.js.map +1 -0
  64. package/dist/src/agent/stream-resumption.d.ts +16 -0
  65. package/dist/src/agent/stream-resumption.js +33 -0
  66. package/dist/src/agent/stream-resumption.js.map +1 -0
  67. package/dist/src/agent/system-prompt.d.ts +50 -0
  68. package/dist/src/agent/system-prompt.js +161 -0
  69. package/dist/src/agent/system-prompt.js.map +1 -0
  70. package/dist/src/agent/thinking.d.ts +99 -0
  71. package/dist/src/agent/thinking.js +145 -0
  72. package/dist/src/agent/thinking.js.map +1 -0
  73. package/dist/src/agent/usage.d.ts +132 -0
  74. package/dist/src/agent/usage.js +233 -0
  75. package/dist/src/agent/usage.js.map +1 -0
  76. package/dist/src/agent/working-context.d.ts +51 -0
  77. package/dist/src/agent/working-context.js +160 -0
  78. package/dist/src/agent/working-context.js.map +1 -0
  79. package/dist/src/agents/child-recipe.d.ts +33 -0
  80. package/dist/src/agents/child-recipe.js +98 -0
  81. package/dist/src/agents/child-recipe.js.map +1 -0
  82. package/dist/src/agents/concurrency-limit.d.ts +25 -0
  83. package/dist/src/agents/concurrency-limit.js +43 -0
  84. package/dist/src/agents/concurrency-limit.js.map +1 -0
  85. package/dist/src/agents/dispatch-registry.d.ts +180 -0
  86. package/dist/src/agents/dispatch-registry.js +289 -0
  87. package/dist/src/agents/dispatch-registry.js.map +1 -0
  88. package/dist/src/agents/failed-child-text.d.ts +44 -0
  89. package/dist/src/agents/failed-child-text.js +69 -0
  90. package/dist/src/agents/failed-child-text.js.map +1 -0
  91. package/dist/src/agents/loader.d.ts +26 -0
  92. package/dist/src/agents/loader.js +134 -0
  93. package/dist/src/agents/loader.js.map +1 -0
  94. package/dist/src/agents/report-projection.d.ts +31 -0
  95. package/dist/src/agents/report-projection.js +125 -0
  96. package/dist/src/agents/report-projection.js.map +1 -0
  97. package/dist/src/agents/subagent-tool.d.ts +61 -0
  98. package/dist/src/agents/subagent-tool.js +180 -0
  99. package/dist/src/agents/subagent-tool.js.map +1 -0
  100. package/dist/src/agents/workflow-tool.d.ts +85 -0
  101. package/dist/src/agents/workflow-tool.js +530 -0
  102. package/dist/src/agents/workflow-tool.js.map +1 -0
  103. package/dist/src/cli-args.d.ts +39 -0
  104. package/dist/src/cli-args.js +198 -0
  105. package/dist/src/cli-args.js.map +1 -0
  106. package/dist/src/cli-doctor.d.ts +26 -0
  107. package/dist/src/cli-doctor.js +398 -0
  108. package/dist/src/cli-doctor.js.map +1 -0
  109. package/dist/src/cli-main.d.ts +1 -0
  110. package/dist/src/cli-main.js +279 -0
  111. package/dist/src/cli-main.js.map +1 -0
  112. package/dist/src/cli-sessions.d.ts +17 -0
  113. package/dist/src/cli-sessions.js +136 -0
  114. package/dist/src/cli-sessions.js.map +1 -0
  115. package/dist/src/cli-trajectory.d.ts +37 -0
  116. package/dist/src/cli-trajectory.js +303 -0
  117. package/dist/src/cli-trajectory.js.map +1 -0
  118. package/dist/src/cli-usage.d.ts +18 -0
  119. package/dist/src/cli-usage.js +53 -0
  120. package/dist/src/cli-usage.js.map +1 -0
  121. package/dist/src/cli.d.ts +2 -0
  122. package/dist/src/cli.js +29 -0
  123. package/dist/src/cli.js.map +1 -0
  124. package/dist/src/commands/custom-commands.d.ts +43 -0
  125. package/dist/src/commands/custom-commands.js +155 -0
  126. package/dist/src/commands/custom-commands.js.map +1 -0
  127. package/dist/src/commands/workflow-command.d.ts +26 -0
  128. package/dist/src/commands/workflow-command.js +56 -0
  129. package/dist/src/commands/workflow-command.js.map +1 -0
  130. package/dist/src/config.d.ts +463 -0
  131. package/dist/src/config.js +1457 -0
  132. package/dist/src/config.js.map +1 -0
  133. package/dist/src/context-overflow-error.d.ts +7 -0
  134. package/dist/src/context-overflow-error.js +26 -0
  135. package/dist/src/context-overflow-error.js.map +1 -0
  136. package/dist/src/dev-repl.d.ts +1 -0
  137. package/dist/src/dev-repl.js +365 -0
  138. package/dist/src/dev-repl.js.map +1 -0
  139. package/dist/src/headless-protocol.d.ts +147 -0
  140. package/dist/src/headless-protocol.js +359 -0
  141. package/dist/src/headless-protocol.js.map +1 -0
  142. package/dist/src/headless-runner.d.ts +30 -0
  143. package/dist/src/headless-runner.js +405 -0
  144. package/dist/src/headless-runner.js.map +1 -0
  145. package/dist/src/headless-stdin.d.ts +28 -0
  146. package/dist/src/headless-stdin.js +78 -0
  147. package/dist/src/headless-stdin.js.map +1 -0
  148. package/dist/src/headless.d.ts +106 -0
  149. package/dist/src/headless.js +229 -0
  150. package/dist/src/headless.js.map +1 -0
  151. package/dist/src/hooks/codex-hook-runner.d.ts +92 -0
  152. package/dist/src/hooks/codex-hook-runner.js +446 -0
  153. package/dist/src/hooks/codex-hook-runner.js.map +1 -0
  154. package/dist/src/hooks/codex-hooks.d.ts +23 -0
  155. package/dist/src/hooks/codex-hooks.js +152 -0
  156. package/dist/src/hooks/codex-hooks.js.map +1 -0
  157. package/dist/src/hooks/hook-process.d.ts +23 -0
  158. package/dist/src/hooks/hook-process.js +241 -0
  159. package/dist/src/hooks/hook-process.js.map +1 -0
  160. package/dist/src/hooks/lifecycle-hooks.d.ts +37 -0
  161. package/dist/src/hooks/lifecycle-hooks.js +153 -0
  162. package/dist/src/hooks/lifecycle-hooks.js.map +1 -0
  163. package/dist/src/hooks/tool-hooks.d.ts +63 -0
  164. package/dist/src/hooks/tool-hooks.js +350 -0
  165. package/dist/src/hooks/tool-hooks.js.map +1 -0
  166. package/dist/src/mcp/codegraph-preflight.d.ts +29 -0
  167. package/dist/src/mcp/codegraph-preflight.js +232 -0
  168. package/dist/src/mcp/codegraph-preflight.js.map +1 -0
  169. package/dist/src/mcp/registry.d.ts +133 -0
  170. package/dist/src/mcp/registry.js +209 -0
  171. package/dist/src/mcp/registry.js.map +1 -0
  172. package/dist/src/mcp/web-search-empty-results.d.ts +14 -0
  173. package/dist/src/mcp/web-search-empty-results.js +94 -0
  174. package/dist/src/mcp/web-search-empty-results.js.map +1 -0
  175. package/dist/src/memory/command.d.ts +11 -0
  176. package/dist/src/memory/command.js +253 -0
  177. package/dist/src/memory/command.js.map +1 -0
  178. package/dist/src/memory/controller.d.ts +51 -0
  179. package/dist/src/memory/controller.js +316 -0
  180. package/dist/src/memory/controller.js.map +1 -0
  181. package/dist/src/memory/prompt.d.ts +4 -0
  182. package/dist/src/memory/prompt.js +22 -0
  183. package/dist/src/memory/prompt.js.map +1 -0
  184. package/dist/src/memory/scheduler.d.ts +33 -0
  185. package/dist/src/memory/scheduler.js +134 -0
  186. package/dist/src/memory/scheduler.js.map +1 -0
  187. package/dist/src/memory/state.d.ts +112 -0
  188. package/dist/src/memory/state.js +355 -0
  189. package/dist/src/memory/state.js.map +1 -0
  190. package/dist/src/memory/store.d.ts +19 -0
  191. package/dist/src/memory/store.js +130 -0
  192. package/dist/src/memory/store.js.map +1 -0
  193. package/dist/src/memory/tools.d.ts +29 -0
  194. package/dist/src/memory/tools.js +22 -0
  195. package/dist/src/memory/tools.js.map +1 -0
  196. package/dist/src/memory/validation.d.ts +33 -0
  197. package/dist/src/memory/validation.js +159 -0
  198. package/dist/src/memory/validation.js.map +1 -0
  199. package/dist/src/npm-package/generate-patch.d.ts +23 -0
  200. package/dist/src/npm-package/generate-patch.js +88 -0
  201. package/dist/src/npm-package/generate-patch.js.map +1 -0
  202. package/dist/src/npm-package/patch-package-format.d.ts +43 -0
  203. package/dist/src/npm-package/patch-package-format.js +66 -0
  204. package/dist/src/npm-package/patch-package-format.js.map +1 -0
  205. package/dist/src/paths.d.ts +39 -0
  206. package/dist/src/paths.js +105 -0
  207. package/dist/src/paths.js.map +1 -0
  208. package/dist/src/pricing/cost.d.ts +182 -0
  209. package/dist/src/pricing/cost.js +215 -0
  210. package/dist/src/pricing/cost.js.map +1 -0
  211. package/dist/src/pricing/model-prices.d.ts +112 -0
  212. package/dist/src/pricing/model-prices.js +320 -0
  213. package/dist/src/pricing/model-prices.js.map +1 -0
  214. package/dist/src/sdk-patch-preflight.d.ts +23 -0
  215. package/dist/src/sdk-patch-preflight.js +71 -0
  216. package/dist/src/sdk-patch-preflight.js.map +1 -0
  217. package/dist/src/skills/builtin/commit-message/SKILL.md +45 -0
  218. package/dist/src/skills/builtin/commit-message/references/types.md +8 -0
  219. package/dist/src/skills/builtin/developer/SKILL.md +107 -0
  220. package/dist/src/skills/builtin/self-evolution-research/SKILL.md +150 -0
  221. package/dist/src/skills/builtin/self-evolution-research/scripts/roll-research-path.mjs +208 -0
  222. package/dist/src/skills/builtin/self-reflection/SKILL.md +172 -0
  223. package/dist/src/skills/builtin/self-reflection/references/reflection-template.md +90 -0
  224. package/dist/src/skills/builtin/self-reflection/scripts/locate-trajectory.mjs +175 -0
  225. package/dist/src/skills/loader.d.ts +26 -0
  226. package/dist/src/skills/loader.js +186 -0
  227. package/dist/src/skills/loader.js.map +1 -0
  228. package/dist/src/skills/plugin.d.ts +34 -0
  229. package/dist/src/skills/plugin.js +137 -0
  230. package/dist/src/skills/plugin.js.map +1 -0
  231. package/dist/src/skills/prompt.d.ts +8 -0
  232. package/dist/src/skills/prompt.js +214 -0
  233. package/dist/src/skills/prompt.js.map +1 -0
  234. package/dist/src/skills/resource-safety.d.ts +15 -0
  235. package/dist/src/skills/resource-safety.js +149 -0
  236. package/dist/src/skills/resource-safety.js.map +1 -0
  237. package/dist/src/tools/background-bash.d.ts +95 -0
  238. package/dist/src/tools/background-bash.js +639 -0
  239. package/dist/src/tools/background-bash.js.map +1 -0
  240. package/dist/src/tools/background-tail.d.ts +28 -0
  241. package/dist/src/tools/background-tail.js +75 -0
  242. package/dist/src/tools/background-tail.js.map +1 -0
  243. package/dist/src/tools/background-wait-contract.d.ts +4 -0
  244. package/dist/src/tools/background-wait-contract.js +7 -0
  245. package/dist/src/tools/background-wait-contract.js.map +1 -0
  246. package/dist/src/tools/file-editor-serial.d.ts +24 -0
  247. package/dist/src/tools/file-editor-serial.js +99 -0
  248. package/dist/src/tools/file-editor-serial.js.map +1 -0
  249. package/dist/src/tools/image-viewer.d.ts +43 -0
  250. package/dist/src/tools/image-viewer.js +256 -0
  251. package/dist/src/tools/image-viewer.js.map +1 -0
  252. package/dist/src/tools/update-plan.d.ts +30 -0
  253. package/dist/src/tools/update-plan.js +65 -0
  254. package/dist/src/tools/update-plan.js.map +1 -0
  255. package/dist/src/tools/web-fetch.d.ts +70 -0
  256. package/dist/src/tools/web-fetch.js +667 -0
  257. package/dist/src/tools/web-fetch.js.map +1 -0
  258. package/dist/src/trajectory/export.d.ts +31 -0
  259. package/dist/src/trajectory/export.js +116 -0
  260. package/dist/src/trajectory/export.js.map +1 -0
  261. package/dist/src/trajectory/fork.d.ts +19 -0
  262. package/dist/src/trajectory/fork.js +110 -0
  263. package/dist/src/trajectory/fork.js.map +1 -0
  264. package/dist/src/trajectory/memory-tool.d.ts +20 -0
  265. package/dist/src/trajectory/memory-tool.js +98 -0
  266. package/dist/src/trajectory/memory-tool.js.map +1 -0
  267. package/dist/src/trajectory/prompt-history.d.ts +62 -0
  268. package/dist/src/trajectory/prompt-history.js +256 -0
  269. package/dist/src/trajectory/prompt-history.js.map +1 -0
  270. package/dist/src/trajectory/reader.d.ts +21 -0
  271. package/dist/src/trajectory/reader.js +62 -0
  272. package/dist/src/trajectory/reader.js.map +1 -0
  273. package/dist/src/trajectory/record.d.ts +417 -0
  274. package/dist/src/trajectory/record.js +394 -0
  275. package/dist/src/trajectory/record.js.map +1 -0
  276. package/dist/src/trajectory/replay.d.ts +74 -0
  277. package/dist/src/trajectory/replay.js +285 -0
  278. package/dist/src/trajectory/replay.js.map +1 -0
  279. package/dist/src/trajectory/resume-recap.d.ts +43 -0
  280. package/dist/src/trajectory/resume-recap.js +68 -0
  281. package/dist/src/trajectory/resume-recap.js.map +1 -0
  282. package/dist/src/trajectory/search.d.ts +40 -0
  283. package/dist/src/trajectory/search.js +127 -0
  284. package/dist/src/trajectory/search.js.map +1 -0
  285. package/dist/src/trajectory/spend.d.ts +157 -0
  286. package/dist/src/trajectory/spend.js +264 -0
  287. package/dist/src/trajectory/spend.js.map +1 -0
  288. package/dist/src/trajectory/stream.d.ts +30 -0
  289. package/dist/src/trajectory/stream.js +30 -0
  290. package/dist/src/trajectory/stream.js.map +1 -0
  291. package/dist/src/trajectory/writer.d.ts +310 -0
  292. package/dist/src/trajectory/writer.js +636 -0
  293. package/dist/src/trajectory/writer.js.map +1 -0
  294. package/dist/src/tui/App.d.ts +109 -0
  295. package/dist/src/tui/App.js +2660 -0
  296. package/dist/src/tui/App.js.map +1 -0
  297. package/dist/src/tui/InputBox.d.ts +90 -0
  298. package/dist/src/tui/InputBox.js +129 -0
  299. package/dist/src/tui/InputBox.js.map +1 -0
  300. package/dist/src/tui/MarkdownText.d.ts +16 -0
  301. package/dist/src/tui/MarkdownText.js +117 -0
  302. package/dist/src/tui/MarkdownText.js.map +1 -0
  303. package/dist/src/tui/MessageList.d.ts +27 -0
  304. package/dist/src/tui/MessageList.js +61 -0
  305. package/dist/src/tui/MessageList.js.map +1 -0
  306. package/dist/src/tui/PermissionPrompt.d.ts +18 -0
  307. package/dist/src/tui/PermissionPrompt.js +114 -0
  308. package/dist/src/tui/PermissionPrompt.js.map +1 -0
  309. package/dist/src/tui/PlanChecklist.d.ts +7 -0
  310. package/dist/src/tui/PlanChecklist.js +12 -0
  311. package/dist/src/tui/PlanChecklist.js.map +1 -0
  312. package/dist/src/tui/QueuedMessages.d.ts +8 -0
  313. package/dist/src/tui/QueuedMessages.js +24 -0
  314. package/dist/src/tui/QueuedMessages.js.map +1 -0
  315. package/dist/src/tui/StartupScreen.d.ts +25 -0
  316. package/dist/src/tui/StartupScreen.js +51 -0
  317. package/dist/src/tui/StartupScreen.js.map +1 -0
  318. package/dist/src/tui/ToolCallPanel.d.ts +33 -0
  319. package/dist/src/tui/ToolCallPanel.js +112 -0
  320. package/dist/src/tui/ToolCallPanel.js.map +1 -0
  321. package/dist/src/tui/WelcomeHeader.d.ts +30 -0
  322. package/dist/src/tui/WelcomeHeader.js +69 -0
  323. package/dist/src/tui/WelcomeHeader.js.map +1 -0
  324. package/dist/src/tui/background-tool-presentation.d.ts +22 -0
  325. package/dist/src/tui/background-tool-presentation.js +209 -0
  326. package/dist/src/tui/background-tool-presentation.js.map +1 -0
  327. package/dist/src/tui/busy-suffix.d.ts +37 -0
  328. package/dist/src/tui/busy-suffix.js +39 -0
  329. package/dist/src/tui/busy-suffix.js.map +1 -0
  330. package/dist/src/tui/clipboard-image.d.ts +18 -0
  331. package/dist/src/tui/clipboard-image.js +109 -0
  332. package/dist/src/tui/clipboard-image.js.map +1 -0
  333. package/dist/src/tui/context-format.d.ts +43 -0
  334. package/dist/src/tui/context-format.js +71 -0
  335. package/dist/src/tui/context-format.js.map +1 -0
  336. package/dist/src/tui/copy-command.d.ts +68 -0
  337. package/dist/src/tui/copy-command.js +182 -0
  338. package/dist/src/tui/copy-command.js.map +1 -0
  339. package/dist/src/tui/edit-diff.d.ts +135 -0
  340. package/dist/src/tui/edit-diff.js +356 -0
  341. package/dist/src/tui/edit-diff.js.map +1 -0
  342. package/dist/src/tui/frame-budget.d.ts +351 -0
  343. package/dist/src/tui/frame-budget.js +446 -0
  344. package/dist/src/tui/frame-budget.js.map +1 -0
  345. package/dist/src/tui/help-format.d.ts +17 -0
  346. package/dist/src/tui/help-format.js +38 -0
  347. package/dist/src/tui/help-format.js.map +1 -0
  348. package/dist/src/tui/live-text.d.ts +51 -0
  349. package/dist/src/tui/live-text.js +154 -0
  350. package/dist/src/tui/live-text.js.map +1 -0
  351. package/dist/src/tui/markdown.d.ts +62 -0
  352. package/dist/src/tui/markdown.js +244 -0
  353. package/dist/src/tui/markdown.js.map +1 -0
  354. package/dist/src/tui/mcp-format.d.ts +28 -0
  355. package/dist/src/tui/mcp-format.js +67 -0
  356. package/dist/src/tui/mcp-format.js.map +1 -0
  357. package/dist/src/tui/path-completion.d.ts +119 -0
  358. package/dist/src/tui/path-completion.js +305 -0
  359. package/dist/src/tui/path-completion.js.map +1 -0
  360. package/dist/src/tui/permission-queue.d.ts +61 -0
  361. package/dist/src/tui/permission-queue.js +129 -0
  362. package/dist/src/tui/permission-queue.js.map +1 -0
  363. package/dist/src/tui/plan-format.d.ts +9 -0
  364. package/dist/src/tui/plan-format.js +30 -0
  365. package/dist/src/tui/plan-format.js.map +1 -0
  366. package/dist/src/tui/prompt-completion.d.ts +22 -0
  367. package/dist/src/tui/prompt-completion.js +46 -0
  368. package/dist/src/tui/prompt-completion.js.map +1 -0
  369. package/dist/src/tui/prompt-editor.d.ts +102 -0
  370. package/dist/src/tui/prompt-editor.js +379 -0
  371. package/dist/src/tui/prompt-editor.js.map +1 -0
  372. package/dist/src/tui/prompt-history-search.d.ts +53 -0
  373. package/dist/src/tui/prompt-history-search.js +123 -0
  374. package/dist/src/tui/prompt-history-search.js.map +1 -0
  375. package/dist/src/tui/prompt-queue.d.ts +58 -0
  376. package/dist/src/tui/prompt-queue.js +74 -0
  377. package/dist/src/tui/prompt-queue.js.map +1 -0
  378. package/dist/src/tui/prompt-recall.d.ts +74 -0
  379. package/dist/src/tui/prompt-recall.js +90 -0
  380. package/dist/src/tui/prompt-recall.js.map +1 -0
  381. package/dist/src/tui/react-environment.d.ts +11 -0
  382. package/dist/src/tui/react-environment.js +24 -0
  383. package/dist/src/tui/react-environment.js.map +1 -0
  384. package/dist/src/tui/rewind-search.d.ts +34 -0
  385. package/dist/src/tui/rewind-search.js +68 -0
  386. package/dist/src/tui/rewind-search.js.map +1 -0
  387. package/dist/src/tui/shell-command.d.ts +114 -0
  388. package/dist/src/tui/shell-command.js +310 -0
  389. package/dist/src/tui/shell-command.js.map +1 -0
  390. package/dist/src/tui/spend-advisory.d.ts +52 -0
  391. package/dist/src/tui/spend-advisory.js +64 -0
  392. package/dist/src/tui/spend-advisory.js.map +1 -0
  393. package/dist/src/tui/status-format.d.ts +120 -0
  394. package/dist/src/tui/status-format.js +192 -0
  395. package/dist/src/tui/status-format.js.map +1 -0
  396. package/dist/src/tui/subagent-format.d.ts +49 -0
  397. package/dist/src/tui/subagent-format.js +146 -0
  398. package/dist/src/tui/subagent-format.js.map +1 -0
  399. package/dist/src/tui/task-format.d.ts +29 -0
  400. package/dist/src/tui/task-format.js +87 -0
  401. package/dist/src/tui/task-format.js.map +1 -0
  402. package/dist/src/tui/terminal-bell.d.ts +20 -0
  403. package/dist/src/tui/terminal-bell.js +33 -0
  404. package/dist/src/tui/terminal-bell.js.map +1 -0
  405. package/dist/src/tui/tool-detail-presentation.d.ts +60 -0
  406. package/dist/src/tui/tool-detail-presentation.js +206 -0
  407. package/dist/src/tui/tool-detail-presentation.js.map +1 -0
  408. package/dist/src/tui/turn-state.d.ts +195 -0
  409. package/dist/src/tui/turn-state.js +548 -0
  410. package/dist/src/tui/turn-state.js.map +1 -0
  411. package/dist/src/tui/visual-language.d.ts +45 -0
  412. package/dist/src/tui/visual-language.js +57 -0
  413. package/dist/src/tui/visual-language.js.map +1 -0
  414. package/dist/src/version.d.ts +7 -0
  415. package/dist/src/version.js +38 -0
  416. package/dist/src/version.js.map +1 -0
  417. package/package.json +60 -0
@@ -0,0 +1,98 @@
1
+ /**
2
+ * The one child-agent construction recipe shared by every delegation surface.
3
+ *
4
+ * `SubagentTool` (one child per dispatch) and `WorkflowTool` (one child per DAG
5
+ * node) must build indistinguishable children: same system prompt composition,
6
+ * same per-definition tool filtering, same shared permission intervention, same
7
+ * dispatch-registry provenance and phase hooks, same max-tokens recovery, same
8
+ * model retry, same bash-session reaping. Extracting the recipe here is what keeps them from
9
+ * drifting — neither caller may construct a child `Agent` directly.
10
+ */
11
+ import { randomUUID } from 'node:crypto';
12
+ import { AfterModelCallEvent, AfterToolCallEvent, Agent, BeforeModelCallEvent, BeforeToolCallEvent, SummarizingConversationManager, } from '@strands-agents/sdk';
13
+ import { composeSystemPrompt } from '../agent/instructions.js';
14
+ import { installMaxTokensRecovery } from '../agent/max-tokens-recovery.js';
15
+ import { installModelRetry, retryNextAttempt } from '../agent/model-retry.js';
16
+ /**
17
+ * Builds one fresh, isolated child Agent and binds it to its dispatch record.
18
+ *
19
+ * The child never receives a `SessionManager`, parent messages, or a delegation
20
+ * tool; its conversation manager mirrors the main Agent's overflow strategy from
21
+ * the same config snapshot. Hooks expose only operation boundaries — never model
22
+ * messages, tool input/results, reasoning, or child transcript.
23
+ */
24
+ export function buildRecipeChild(options) {
25
+ const { definition, config, dispatch } = options;
26
+ const child = new Agent({
27
+ id: `darwin-${options.idPrefix}-${definition.name}-${randomUUID()}`,
28
+ name: definition.name,
29
+ description: definition.description,
30
+ model: options.model,
31
+ systemPrompt: composeSystemPrompt(definition.systemPrompt, options.projectInstructions),
32
+ tools: toolsForDefinition(definition, options.tools),
33
+ conversationManager: new SummarizingConversationManager({
34
+ summaryRatio: config.summaryRatio,
35
+ preserveRecentMessages: config.preserveRecentMessages,
36
+ }),
37
+ interventions: [options.intervention],
38
+ printer: false,
39
+ // Same opt-out as the parent: darwin's cancellable retry replaces the SDK default.
40
+ retryStrategy: null,
41
+ });
42
+ installMaxTokensRecovery(child);
43
+ // One private retry state per child. Its wait is published only as a closed dispatch
44
+ // phase (SER-067): two integers through the same `setPhase` every other phase uses,
45
+ // never the provider's reason text. `AfterModelCallEvent` hooks run in reverse
46
+ // registration order, so the `starting` hook below fires *before* the retry hook
47
+ // decides a wait — the observer, not hook order, is what puts the phase right.
48
+ const retry = installModelRetry(child, undefined, {
49
+ waitStarted: (state) => {
50
+ dispatch?.setPhase({ kind: 'waiting-on-model', attempt: retryNextAttempt(state), maxAttempts: state.maxAttempts });
51
+ },
52
+ // The timer elapsed and the next call begins now; a cancelled wait rethrows into
53
+ // the ordinary `AfterModelCallEvent`, whose hook below sets `starting` itself.
54
+ waitEnded: (_state, completed) => {
55
+ if (completed)
56
+ dispatch?.setPhase({ kind: 'model' });
57
+ },
58
+ });
59
+ // `BeforeModelCallEvent` precedes the middleware that performs the wait, so while a
60
+ // wait is pending the honest phase is still the wait, not `model`.
61
+ child.addHook(BeforeModelCallEvent, () => {
62
+ if (retry.retryWait() === undefined)
63
+ dispatch?.setPhase({ kind: 'model' });
64
+ });
65
+ child.addHook(AfterModelCallEvent, () => dispatch?.setPhase({ kind: 'starting' }));
66
+ child.addHook(BeforeToolCallEvent, (event) => {
67
+ dispatch?.setPhase({ kind: 'tool', toolName: event.toolUse.name });
68
+ });
69
+ child.addHook(AfterToolCallEvent, () => dispatch?.setPhase({ kind: 'starting' }));
70
+ // Before initialize(), so the first gated call resolves to its dispatch and a
71
+ // targeted cancellation can stop only this child.
72
+ dispatch?.attachAgent(child.id);
73
+ dispatch?.attachCancel(() => child.cancel());
74
+ // Clone: the SDK object is a live accumulator, and a frozen terminal reading
75
+ // must not keep mutating after the dispatch settles. Counters only — the
76
+ // meter carries no part of the child's transcript.
77
+ dispatch?.attachUsage(() => ({ ...child.metrics.accumulatedUsage }));
78
+ return child;
79
+ }
80
+ /** `tools` omitted means the whole eligible catalogue, `[]` none, a list an exact filter. */
81
+ export function toolsForDefinition(definition, tools) {
82
+ if (definition.tools === undefined)
83
+ return [...tools];
84
+ const allowed = new Set(definition.tools);
85
+ return tools.filter((candidate) => allowed.has(candidate.name));
86
+ }
87
+ /** Reaps the persistent shell associated with one child Agent, if it used bash. */
88
+ export async function stopBashSession(agent) {
89
+ if (!agent.tools.some((candidate) => candidate.name === 'bash'))
90
+ return;
91
+ try {
92
+ await agent.tool['bash']?.invoke({ mode: 'restart' }, { recordDirectToolCall: false });
93
+ }
94
+ catch {
95
+ // Cleanup is best-effort; the child's original result or failure takes priority.
96
+ }
97
+ }
98
+ //# sourceMappingURL=child-recipe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"child-recipe.js","sourceRoot":"","sources":["../../../src/agents/child-recipe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,KAAK,EACL,oBAAoB,EACpB,mBAAmB,EACnB,8BAA8B,GAC/B,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAoB9E;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAA2B;IAC1D,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IACjD,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC;QACtB,EAAE,EAAE,UAAU,OAAO,CAAC,QAAQ,IAAI,UAAU,CAAC,IAAI,IAAI,UAAU,EAAE,EAAE;QACnE,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,WAAW,EAAE,UAAU,CAAC,WAAW;QACnC,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,YAAY,EAAE,mBAAmB,CAAC,UAAU,CAAC,YAAY,EAAE,OAAO,CAAC,mBAAmB,CAAC;QACvF,KAAK,EAAE,kBAAkB,CAAC,UAAU,EAAE,OAAO,CAAC,KAAK,CAAC;QACpD,mBAAmB,EAAE,IAAI,8BAA8B,CAAC;YACtD,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,sBAAsB,EAAE,MAAM,CAAC,sBAAsB;SACtD,CAAC;QACF,aAAa,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC;QACrC,OAAO,EAAE,KAAK;QACd,mFAAmF;QACnF,aAAa,EAAE,IAAI;KACpB,CAAC,CAAC;IACH,wBAAwB,CAAC,KAAK,CAAC,CAAC;IAChC,qFAAqF;IACrF,oFAAoF;IACpF,+EAA+E;IAC/E,iFAAiF;IACjF,+EAA+E;IAC/E,MAAM,KAAK,GAAG,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE;QAChD,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE;YACrB,QAAQ,EAAE,QAAQ,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,gBAAgB,CAAC,KAAK,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;QACrH,CAAC;QACD,iFAAiF;QACjF,+EAA+E;QAC/E,SAAS,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE;YAC/B,IAAI,SAAS;gBAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;QACvD,CAAC;KACF,CAAC,CAAC;IACH,oFAAoF;IACpF,mEAAmE;IACnE,KAAK,CAAC,OAAO,CAAC,oBAAoB,EAAE,GAAG,EAAE;QACvC,IAAI,KAAK,CAAC,SAAS,EAAE,KAAK,SAAS;YAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;IACH,KAAK,CAAC,OAAO,CAAC,mBAAmB,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;IACnF,KAAK,CAAC,OAAO,CAAC,mBAAmB,EAAE,CAAC,KAAK,EAAE,EAAE;QAC3C,QAAQ,EAAE,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACrE,CAAC,CAAC,CAAC;IACH,KAAK,CAAC,OAAO,CAAC,kBAAkB,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;IAClF,8EAA8E;IAC9E,kDAAkD;IAClD,QAAQ,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAChC,QAAQ,EAAE,YAAY,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IAC7C,6EAA6E;IAC7E,yEAAyE;IACzE,mDAAmD;IACnD,QAAQ,EAAE,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC;IACrE,OAAO,KAAK,CAAC;AACf,CAAC;AAED,6FAA6F;AAC7F,MAAM,UAAU,kBAAkB,CAAC,UAA2B,EAAE,KAAsB;IACpF,IAAI,UAAU,CAAC,KAAK,KAAK,SAAS;QAAE,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC;IACtD,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAC1C,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,mFAAmF;AACnF,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,KAAY;IAChD,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,KAAK,MAAM,CAAC;QAAE,OAAO;IAExE,IAAI,CAAC;QACH,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC,CAAC;IACzF,CAAC;IAAC,MAAM,CAAC;QACP,iFAAiF;IACnF,CAAC;AACH,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * SER-061: the one ceiling on concurrently running child dispatches, shared by
3
+ * the `subagent` and `workflow` tools.
4
+ *
5
+ * The count is the existing {@link SubagentDispatchRegistry}'s `running`
6
+ * records — no second ledger, no new state. A refused call throws before any
7
+ * model, dispatch record or child exists, so the SDK turns it into an ordinary
8
+ * tool error result the model reads; the message tells it not to retry until a
9
+ * running dispatch settles, because settlement (the registry's terminal
10
+ * transition) is the only thing that frees a slot.
11
+ */
12
+ import { type AppConfig } from '../config.js';
13
+ /**
14
+ * The effective cap for one config snapshot. `loadConfig` always populates a
15
+ * positive integer; the fallback covers fixtures that build a partial config.
16
+ */
17
+ export declare function concurrencyCap(config: AppConfig): number;
18
+ /**
19
+ * One fixed message shape for both tools. `requested` is the number of slots
20
+ * the call needs (1 for `subagent`, the effective parallelism for `workflow`);
21
+ * anything above one adds a clause naming it and the free slots.
22
+ */
23
+ export declare function concurrencyLimitMessage(cap: number, running: number, requested?: number): string;
24
+ /** The clause both tool descriptions carry so the model knows a ceiling exists. */
25
+ export declare function concurrencyDescriptionClause(cap: number): string;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * SER-061: the one ceiling on concurrently running child dispatches, shared by
3
+ * the `subagent` and `workflow` tools.
4
+ *
5
+ * The count is the existing {@link SubagentDispatchRegistry}'s `running`
6
+ * records — no second ledger, no new state. A refused call throws before any
7
+ * model, dispatch record or child exists, so the SDK turns it into an ordinary
8
+ * tool error result the model reads; the message tells it not to retry until a
9
+ * running dispatch settles, because settlement (the registry's terminal
10
+ * transition) is the only thing that frees a slot.
11
+ */
12
+ import { DEFAULT_MAX_CONCURRENT_SUBAGENTS } from '../config.js';
13
+ /**
14
+ * The effective cap for one config snapshot. `loadConfig` always populates a
15
+ * positive integer; the fallback covers fixtures that build a partial config.
16
+ */
17
+ export function concurrencyCap(config) {
18
+ const value = config.maxConcurrentSubagents;
19
+ return value !== undefined && Number.isSafeInteger(value) && value >= 1
20
+ ? value
21
+ : DEFAULT_MAX_CONCURRENT_SUBAGENTS;
22
+ }
23
+ /**
24
+ * One fixed message shape for both tools. `requested` is the number of slots
25
+ * the call needs (1 for `subagent`, the effective parallelism for `workflow`);
26
+ * anything above one adds a clause naming it and the free slots.
27
+ */
28
+ export function concurrencyLimitMessage(cap, running, requested = 1) {
29
+ const free = Math.max(0, cap - running);
30
+ // A single-slot refusal only happens at the cap, where "N of N" already says
31
+ // everything; a multi-slot one names what it needs against what is free.
32
+ const need = requested > 1
33
+ ? ` This call needs ${requested} slots; ${free} ${free === 1 ? 'is' : 'are'} free.`
34
+ : '';
35
+ return (`Concurrent subagent limit reached: ${running} of ${cap} dispatches running.${need} ` +
36
+ 'Do not retry until one settles; wait for its result instead.');
37
+ }
38
+ /** The clause both tool descriptions carry so the model knows a ceiling exists. */
39
+ export function concurrencyDescriptionClause(cap) {
40
+ return (`At most ${cap} child dispatches run at once (config maxConcurrentSubagents); ` +
41
+ 'a call over the limit fails and must wait for a running dispatch to settle.');
42
+ }
43
+ //# sourceMappingURL=concurrency-limit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"concurrency-limit.js","sourceRoot":"","sources":["../../../src/agents/concurrency-limit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,gCAAgC,EAAkB,MAAM,cAAc,CAAC;AAEhF;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,MAAiB;IAC9C,MAAM,KAAK,GAAG,MAAM,CAAC,sBAAsB,CAAC;IAC5C,OAAO,KAAK,KAAK,SAAS,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;QACrE,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,gCAAgC,CAAC;AACvC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,GAAW,EAAE,OAAe,EAAE,SAAS,GAAG,CAAC;IACjF,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC;IACxC,6EAA6E;IAC7E,yEAAyE;IACzE,MAAM,IAAI,GAAG,SAAS,GAAG,CAAC;QACxB,CAAC,CAAC,oBAAoB,SAAS,WAAW,IAAI,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ;QACnF,CAAC,CAAC,EAAE,CAAC;IACP,OAAO,CACL,sCAAsC,OAAO,OAAO,GAAG,uBAAuB,IAAI,GAAG;QACrF,8DAA8D,CAC/D,CAAC;AACJ,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,4BAA4B,CAAC,GAAW;IACtD,OAAO,CACL,WAAW,GAAG,iEAAiE;QAC/E,6EAA6E,CAC9E,CAAC;AACJ,CAAC"}
@@ -0,0 +1,180 @@
1
+ import { type UsageTotals } from '../agent/usage.js';
2
+ export declare const SUBAGENT_HEARTBEAT_INTERVAL_MS = 30000;
3
+ /** `running` until the dispatch settles; terminal states are published once. */
4
+ export type SubagentDispatchState = 'running' | 'succeeded' | 'failed' | 'cancelled';
5
+ export type TerminalSubagentDispatchState = Exclude<SubagentDispatchState, 'running'>;
6
+ export type SubagentDispatchPhase = {
7
+ readonly kind: 'starting';
8
+ } | {
9
+ readonly kind: 'model';
10
+ } | {
11
+ readonly kind: 'tool';
12
+ readonly toolName: string;
13
+ }
14
+ /**
15
+ * The child's model call was throttled and its darwin-owned retry wait is pending
16
+ * (SER-067): `attempt` is the call about to be made, out of `maxAttempts`. Two
17
+ * integers from the child's own retry state — never the provider's reason text.
18
+ */
19
+ | {
20
+ readonly kind: 'waiting-on-model';
21
+ readonly attempt: number;
22
+ readonly maxAttempts: number;
23
+ };
24
+ export interface SubagentDispatchStatus {
25
+ /**
26
+ * Short, human-quotable dispatch identity derived from the parent `tool_use`
27
+ * id — the same id the live tool row, the `/agents` report, the permission
28
+ * label and the completion notice all show, so one dispatch reads as one thing
29
+ * everywhere.
30
+ */
31
+ readonly dispatchId: string;
32
+ readonly agentName: string;
33
+ /** Full delegated task text. Bounded only when rendered. */
34
+ readonly task: string;
35
+ readonly state: SubagentDispatchState;
36
+ readonly phase: SubagentDispatchPhase;
37
+ readonly startedAt: string;
38
+ readonly finishedAt: string | null;
39
+ /**
40
+ * The child's own `metrics.accumulatedUsage`: live while running, frozen at
41
+ * the terminal transition (a cancelled or failed child keeps what it spent).
42
+ * Counters only, never transcript; absent when the child never attached a
43
+ * reader or its meter could not be read.
44
+ */
45
+ readonly usage?: UsageTotals;
46
+ }
47
+ export interface SubagentDispatchProgress {
48
+ readonly dispatchId: string;
49
+ readonly agentName: string;
50
+ readonly phase: SubagentDispatchPhase;
51
+ readonly elapsedMs: number;
52
+ /** False for immediate safe phase updates; true for periodic user-visible heartbeats. */
53
+ readonly heartbeat: boolean;
54
+ }
55
+ /** What the permission gate carries on a request: who asked, in what dispatch. */
56
+ export interface SubagentDispatchSource {
57
+ readonly dispatchId: string;
58
+ /** Bounded for display, like {@link dispatchLabel} — prompts are display. */
59
+ readonly agentName: string;
60
+ /** Bounded, ready to render: `<agent>#<dispatchId>`. */
61
+ readonly label: string;
62
+ /**
63
+ * Declared `workflow` node write scopes (SER-065): normalized project-relative
64
+ * path prefixes, already validated by the tool. Absent for `subagent`
65
+ * dispatches and unscoped nodes, which the gate must treat exactly as before.
66
+ */
67
+ readonly writeScopes?: readonly string[];
68
+ }
69
+ /** Receives one immutable snapshot when a dispatch first reaches a terminal state. */
70
+ export type SubagentDispatchListener = (dispatch: Readonly<SubagentDispatchStatus>) => void;
71
+ export type SubagentDispatchProgressListener = (progress: Readonly<SubagentDispatchProgress>) => void;
72
+ export type SubagentCancelResult = {
73
+ readonly outcome: 'cancelled';
74
+ readonly dispatch: SubagentDispatchStatus;
75
+ } | {
76
+ readonly outcome: 'not-found' | 'ambiguous' | 'terminal' | 'already-requested';
77
+ };
78
+ /**
79
+ * The writer's half of one dispatch. Handed to the caller that started it so no
80
+ * record key has to be threaded through the dispatch flow.
81
+ */
82
+ export interface SubagentDispatchHandle {
83
+ readonly dispatchId: string;
84
+ /** Binds the child `Agent.id`, which only exists after the child is built. */
85
+ attachAgent(agentId: string): void;
86
+ /** Installs the only operation targeted cancellation may perform. */
87
+ attachCancel(cancel: () => void): void;
88
+ /**
89
+ * Installs a reader over the child's live usage meter — counters only, never
90
+ * transcript. Ignored once terminal, like {@link attachCancel}.
91
+ */
92
+ attachUsage(read: () => UsageTotals): void;
93
+ /** True even if cancellation arrived before child construction completed. */
94
+ cancellationRequested(): boolean;
95
+ /** Publishes only closed, reasoning-safe phase metadata. */
96
+ setPhase(phase: SubagentDispatchPhase): void;
97
+ /** First call wins; later calls are ignored, as are calls after one another. */
98
+ finish(state: TerminalSubagentDispatchState): void;
99
+ }
100
+ export interface SubagentDispatchRegistryOptions {
101
+ /** Narrow deterministic test seam; production is fixed at no more than 30 seconds. */
102
+ readonly heartbeatIntervalMs?: number;
103
+ readonly now?: () => number;
104
+ }
105
+ export declare class SubagentDispatchRegistry {
106
+ /** Insertion-ordered, keyed privately so two dispatches can share a display id. */
107
+ private readonly records;
108
+ /** Child `Agent.id` → private record key, for permission provenance. */
109
+ private readonly byAgentId;
110
+ private readonly listeners;
111
+ private readonly progressListeners;
112
+ private readonly heartbeatIntervalMs;
113
+ private readonly now;
114
+ constructor(options?: SubagentDispatchRegistryOptions);
115
+ begin(dispatch: {
116
+ agentName: string;
117
+ task: string;
118
+ toolUseId?: string | undefined;
119
+ /** `workflow` nodes only: normalized scopes the tool already validated. */
120
+ writeScopes?: readonly string[] | undefined;
121
+ }): SubagentDispatchHandle;
122
+ /** Snapshots every dispatch of this run in start order, finished ones included. */
123
+ list(): SubagentDispatchStatus[];
124
+ /**
125
+ * Dispatches not yet settled — the number the concurrency cap compares
126
+ * against. A `workflow` node counts from `begin()` even while the SDK graph has
127
+ * it waiting on a dependency; a slot frees only at the terminal transition.
128
+ */
129
+ runningCount(): number;
130
+ /**
131
+ * Every token this run's children have spent so far, summed over each
132
+ * dispatch's current snapshot usage — running children read live, finished
133
+ * ones report their frozen terminal reading. `dispatches` counts only the
134
+ * dispatches whose usage was included in the sum: one whose meter was never
135
+ * attached or could not be read is excluded rather than summed as zero.
136
+ * `undefined` when no dispatch ever reported usage, so every surface keeps
137
+ * its zero-dispatch form instead of inventing an all-zero children section.
138
+ */
139
+ totalUsage(): {
140
+ dispatches: number;
141
+ usage: UsageTotals;
142
+ } | undefined;
143
+ /** Subscribes to future terminal transitions; finished dispatches are not replayed. */
144
+ subscribe(listener: SubagentDispatchListener): () => void;
145
+ /** Safe phase changes and periodic heartbeats; neither is persisted or model-visible. */
146
+ subscribeProgress(listener: SubagentDispatchProgressListener): () => void;
147
+ /** User-only exact-id cancellation. Collisions fail closed rather than cancelling several children. */
148
+ cancel(dispatchId: string): SubagentCancelResult;
149
+ /**
150
+ * Resolves a permission request's origin. `undefined` means "not a tracked
151
+ * dispatch", which in darwin means the one assembled parent agent: the runtime
152
+ * builds exactly one `Agent` plus the children this registry records.
153
+ */
154
+ sourceFor(agentId: string): SubagentDispatchSource | undefined;
155
+ private invokeCancel;
156
+ private setPhase;
157
+ private publishProgress;
158
+ /** One terminal transition per dispatch; it also tears down the private timer/canceller. */
159
+ private finish;
160
+ }
161
+ /**
162
+ * Bounded display id for one dispatch.
163
+ *
164
+ * Pure in the parent `tool_use` id so the TUI reducer can compute the same id from
165
+ * a stream event without reaching into the registry. Provider ids carry a
166
+ * `tooluse_` prefix that distinguishes nothing, so it is dropped before the id is
167
+ * shortened. A missing id (a direct `.invoke()` outside a tool call) falls back to
168
+ * a random one rather than a shared placeholder.
169
+ */
170
+ export declare function shortDispatchId(toolUseId: string | undefined): string;
171
+ /**
172
+ * `<agent>#<dispatchId>` — the identity every surface shows for one dispatch: the
173
+ * prompt label, the `/agents` row, the live tool row and the completion notice.
174
+ * One definition, so those four can never drift apart, and the name is bounded
175
+ * here so a 64-character definition name cannot stretch any of them.
176
+ */
177
+ export declare function dispatchLabel(dispatch: {
178
+ agentName: string;
179
+ dispatchId: string;
180
+ }): string;
@@ -0,0 +1,289 @@
1
+ /**
2
+ * Per-dispatch state for the delegation tool, and the provenance the permission
3
+ * gate needs to say *which* agent asked.
4
+ *
5
+ * Shaped after {@link BackgroundBashManager}: the runtime owns one registry,
6
+ * consumers observe it (a snapshot list plus a terminal-transition subscription),
7
+ * and everything user-facing is bounded at presentation time. Nothing here reads
8
+ * a child's messages, tool payloads or reasoning — a dispatch record is name, task
9
+ * text, closed phase, state, timestamps and the child meter's usage counters, so
10
+ * observability cannot become a way for
11
+ * child transcript to reach the parent conversation.
12
+ *
13
+ * Read-heavy first, deliberately: concurrent dispatches share one working tree
14
+ * with no isolation, locking or conflict detection whatsoever. Nothing in this
15
+ * module makes concurrent *write* delegation safe, and it is not meant to —
16
+ * delegate reads/searches in parallel, and keep mutation on one agent at a time.
17
+ * The one write-related fact a record may carry is the `writeScopes` a
18
+ * `workflow` node *declared* (SER-065): normalized path prefixes handed through
19
+ * {@link SubagentDispatchSource} to the permission gate, which is the only
20
+ * thing that enforces them. The registry stores and reports; it never judges.
21
+ */
22
+ import { randomUUID } from 'node:crypto';
23
+ import { sumUsage } from '../agent/usage.js';
24
+ export const SUBAGENT_HEARTBEAT_INTERVAL_MS = 30_000;
25
+ /** Agent names are `[a-zA-Z0-9_-]{1,64}`, so a label needs a bound of its own. */
26
+ const AGENT_NAME_LABEL_LIMIT = 16;
27
+ export class SubagentDispatchRegistry {
28
+ /** Insertion-ordered, keyed privately so two dispatches can share a display id. */
29
+ records = new Map();
30
+ /** Child `Agent.id` → private record key, for permission provenance. */
31
+ byAgentId = new Map();
32
+ listeners = new Set();
33
+ progressListeners = new Set();
34
+ heartbeatIntervalMs;
35
+ now;
36
+ constructor(options = {}) {
37
+ this.heartbeatIntervalMs = Math.max(1, Math.min(SUBAGENT_HEARTBEAT_INTERVAL_MS, options.heartbeatIntervalMs ?? SUBAGENT_HEARTBEAT_INTERVAL_MS));
38
+ this.now = options.now ?? Date.now;
39
+ }
40
+ begin(dispatch) {
41
+ const key = randomUUID();
42
+ const startedAtMs = this.now();
43
+ const record = {
44
+ dispatchId: shortDispatchId(dispatch.toolUseId),
45
+ agentName: dispatch.agentName,
46
+ task: dispatch.task,
47
+ state: 'running',
48
+ phase: { kind: 'starting' },
49
+ startedAt: new Date(startedAtMs).toISOString(),
50
+ startedAtMs,
51
+ finishedAt: null,
52
+ cancellationRequested: false,
53
+ cancel: undefined,
54
+ readUsage: undefined,
55
+ usage: undefined,
56
+ heartbeat: undefined,
57
+ writeScopes: dispatch.writeScopes === undefined ? undefined : Object.freeze([...dispatch.writeScopes]),
58
+ };
59
+ this.records.set(key, record);
60
+ record.heartbeat = setInterval(() => this.publishProgress(record, true), this.heartbeatIntervalMs);
61
+ record.heartbeat.unref?.();
62
+ return {
63
+ dispatchId: record.dispatchId,
64
+ attachAgent: (agentId) => {
65
+ if (record.state === 'running')
66
+ this.byAgentId.set(agentId, key);
67
+ },
68
+ attachCancel: (cancel) => {
69
+ if (record.state !== 'running')
70
+ return;
71
+ record.cancel = cancel;
72
+ if (record.cancellationRequested)
73
+ this.invokeCancel(record);
74
+ },
75
+ attachUsage: (read) => {
76
+ if (record.state === 'running')
77
+ record.readUsage = read;
78
+ },
79
+ cancellationRequested: () => record.cancellationRequested,
80
+ setPhase: (phase) => this.setPhase(record, phase),
81
+ finish: (state) => this.finish(key, state),
82
+ };
83
+ }
84
+ /** Snapshots every dispatch of this run in start order, finished ones included. */
85
+ list() {
86
+ return [...this.records.values()].map(snapshot);
87
+ }
88
+ /**
89
+ * Dispatches not yet settled — the number the concurrency cap compares
90
+ * against. A `workflow` node counts from `begin()` even while the SDK graph has
91
+ * it waiting on a dependency; a slot frees only at the terminal transition.
92
+ */
93
+ runningCount() {
94
+ let running = 0;
95
+ for (const record of this.records.values())
96
+ if (record.state === 'running')
97
+ running += 1;
98
+ return running;
99
+ }
100
+ /**
101
+ * Every token this run's children have spent so far, summed over each
102
+ * dispatch's current snapshot usage — running children read live, finished
103
+ * ones report their frozen terminal reading. `dispatches` counts only the
104
+ * dispatches whose usage was included in the sum: one whose meter was never
105
+ * attached or could not be read is excluded rather than summed as zero.
106
+ * `undefined` when no dispatch ever reported usage, so every surface keeps
107
+ * its zero-dispatch form instead of inventing an all-zero children section.
108
+ */
109
+ totalUsage() {
110
+ const reported = [...this.records.values()]
111
+ .map((record) => currentUsage(record))
112
+ .filter((usage) => usage !== undefined);
113
+ if (reported.length === 0)
114
+ return undefined;
115
+ return { dispatches: reported.length, usage: sumUsage(reported) };
116
+ }
117
+ /** Subscribes to future terminal transitions; finished dispatches are not replayed. */
118
+ subscribe(listener) {
119
+ this.listeners.add(listener);
120
+ return () => this.listeners.delete(listener);
121
+ }
122
+ /** Safe phase changes and periodic heartbeats; neither is persisted or model-visible. */
123
+ subscribeProgress(listener) {
124
+ this.progressListeners.add(listener);
125
+ return () => this.progressListeners.delete(listener);
126
+ }
127
+ /** User-only exact-id cancellation. Collisions fail closed rather than cancelling several children. */
128
+ cancel(dispatchId) {
129
+ const matches = [...this.records.values()].filter((record) => record.dispatchId === dispatchId);
130
+ if (matches.length === 0)
131
+ return { outcome: 'not-found' };
132
+ if (matches.length > 1)
133
+ return { outcome: 'ambiguous' };
134
+ const record = matches[0];
135
+ if (record.state !== 'running')
136
+ return { outcome: 'terminal' };
137
+ if (record.cancellationRequested)
138
+ return { outcome: 'already-requested' };
139
+ record.cancellationRequested = true;
140
+ this.invokeCancel(record);
141
+ return { outcome: 'cancelled', dispatch: snapshot(record) };
142
+ }
143
+ /**
144
+ * Resolves a permission request's origin. `undefined` means "not a tracked
145
+ * dispatch", which in darwin means the one assembled parent agent: the runtime
146
+ * builds exactly one `Agent` plus the children this registry records.
147
+ */
148
+ sourceFor(agentId) {
149
+ const key = this.byAgentId.get(agentId);
150
+ const record = key === undefined ? undefined : this.records.get(key);
151
+ if (record === undefined)
152
+ return undefined;
153
+ return {
154
+ dispatchId: record.dispatchId,
155
+ agentName: boundedAgentName(record.agentName),
156
+ label: dispatchLabel(record),
157
+ ...(record.writeScopes === undefined ? {} : { writeScopes: record.writeScopes }),
158
+ };
159
+ }
160
+ invokeCancel(record) {
161
+ try {
162
+ record.cancel?.();
163
+ }
164
+ catch {
165
+ // Cancellation is best-effort and cannot corrupt the parent turn.
166
+ }
167
+ }
168
+ setPhase(record, phase) {
169
+ if (record.state !== 'running')
170
+ return;
171
+ record.phase = phase.kind === 'tool'
172
+ ? { kind: 'tool', toolName: boundedToolName(phase.toolName) }
173
+ : phase.kind === 'waiting-on-model'
174
+ ? { kind: 'waiting-on-model', attempt: boundedCount(phase.attempt), maxAttempts: boundedCount(phase.maxAttempts) }
175
+ : phase;
176
+ this.publishProgress(record, false);
177
+ }
178
+ publishProgress(record, heartbeat) {
179
+ if (record.state !== 'running')
180
+ return;
181
+ const progress = {
182
+ dispatchId: record.dispatchId,
183
+ agentName: boundedAgentName(record.agentName),
184
+ phase: record.phase,
185
+ elapsedMs: Math.max(0, Math.floor(this.now() - record.startedAtMs)),
186
+ heartbeat,
187
+ };
188
+ for (const listener of this.progressListeners) {
189
+ try {
190
+ listener(progress);
191
+ }
192
+ catch {
193
+ // Progress is advisory; observers cannot affect child execution.
194
+ }
195
+ }
196
+ }
197
+ /** One terminal transition per dispatch; it also tears down the private timer/canceller. */
198
+ finish(key, state) {
199
+ const record = this.records.get(key);
200
+ if (record === undefined || record.state !== 'running')
201
+ return;
202
+ // Freeze the meter's last reading before the terminal snapshot is published,
203
+ // so a cancelled or failed child still reports what it spent before settling.
204
+ record.usage = currentUsage(record);
205
+ record.readUsage = undefined;
206
+ record.state = state;
207
+ record.finishedAt = new Date(this.now()).toISOString();
208
+ if (record.heartbeat !== undefined)
209
+ clearInterval(record.heartbeat);
210
+ record.heartbeat = undefined;
211
+ record.cancel = undefined;
212
+ const completed = snapshot(record);
213
+ for (const listener of this.listeners) {
214
+ try {
215
+ listener(completed);
216
+ }
217
+ catch {
218
+ // Observers are advisory; the dispatch result is what matters.
219
+ }
220
+ }
221
+ }
222
+ }
223
+ function snapshot(record) {
224
+ const usage = currentUsage(record);
225
+ return {
226
+ dispatchId: record.dispatchId,
227
+ agentName: record.agentName,
228
+ task: record.task,
229
+ state: record.state,
230
+ phase: record.phase,
231
+ startedAt: record.startedAt,
232
+ finishedAt: record.finishedAt,
233
+ ...(usage !== undefined && { usage }),
234
+ };
235
+ }
236
+ /**
237
+ * One dispatch's current spend: the frozen terminal reading once finished, a
238
+ * live meter reading while running. A reader that throws degrades to
239
+ * `undefined` — an observer over a child's meter must never become a second
240
+ * reason a dispatch (or a projection over it) fails.
241
+ */
242
+ function currentUsage(record) {
243
+ if (record.usage !== undefined)
244
+ return record.usage;
245
+ if (record.readUsage === undefined)
246
+ return undefined;
247
+ try {
248
+ return record.readUsage();
249
+ }
250
+ catch {
251
+ return undefined;
252
+ }
253
+ }
254
+ /**
255
+ * Bounded display id for one dispatch.
256
+ *
257
+ * Pure in the parent `tool_use` id so the TUI reducer can compute the same id from
258
+ * a stream event without reaching into the registry. Provider ids carry a
259
+ * `tooluse_` prefix that distinguishes nothing, so it is dropped before the id is
260
+ * shortened. A missing id (a direct `.invoke()` outside a tool call) falls back to
261
+ * a random one rather than a shared placeholder.
262
+ */
263
+ export function shortDispatchId(toolUseId) {
264
+ const distinguishing = (toolUseId ?? '').replace(/^tool_?use[_-]?/i, '').replace(/[^a-zA-Z0-9]/g, '');
265
+ return distinguishing === '' ? randomUUID().replace(/-/g, '').slice(0, 8) : distinguishing.slice(0, 8);
266
+ }
267
+ /**
268
+ * `<agent>#<dispatchId>` — the identity every surface shows for one dispatch: the
269
+ * prompt label, the `/agents` row, the live tool row and the completion notice.
270
+ * One definition, so those four can never drift apart, and the name is bounded
271
+ * here so a 64-character definition name cannot stretch any of them.
272
+ */
273
+ export function dispatchLabel(dispatch) {
274
+ return `${boundedAgentName(dispatch.agentName)}#${dispatch.dispatchId}`;
275
+ }
276
+ /** Keeps a 64-character agent name from stretching a permission-prompt line. */
277
+ function boundedAgentName(name) {
278
+ return name.length <= AGENT_NAME_LABEL_LIMIT ? name : `${name.slice(0, AGENT_NAME_LABEL_LIMIT - 1)}…`;
279
+ }
280
+ /** Closed, bounded child tool metadata for progress. */
281
+ function boundedToolName(name) {
282
+ const normalized = name.replace(/[^a-zA-Z0-9_.-]/g, '').slice(0, 64);
283
+ return normalized === '' ? 'tool' : normalized;
284
+ }
285
+ /** A retry attempt counter as a closed non-negative integer; anything else degrades to 0. */
286
+ function boundedCount(value) {
287
+ return Number.isFinite(value) ? Math.max(0, Math.floor(value)) : 0;
288
+ }
289
+ //# sourceMappingURL=dispatch-registry.js.map