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,639 @@
1
+ /** Session-owned background processes exposed through the existing bash tool. */
2
+ import { spawn } from 'node:child_process';
3
+ import { randomUUID } from 'node:crypto';
4
+ import { constants } from 'node:fs';
5
+ import { mkdir, open } from 'node:fs/promises';
6
+ import path from 'node:path';
7
+ import { tool } from '@strands-agents/sdk';
8
+ import { bash as sdkBash, createBash } from '@strands-agents/sdk/vended-tools/bash';
9
+ import { z } from 'zod';
10
+ import { sessionPaths } from '../agent/session.js';
11
+ import { OUTPUT_SENSITIVE_WAIT_MAX_MS, TERMINAL_FOCUSED_WAIT_MAX_MS, TERMINAL_WAIT_TIMEOUT_INSTRUCTION, } from './background-wait-contract.js';
12
+ export { OUTPUT_SENSITIVE_WAIT_MAX_MS, TERMINAL_FOCUSED_WAIT_MAX_MS, TERMINAL_WAIT_TIMEOUT_INSTRUCTION, } from './background-wait-contract.js';
13
+ const OUTPUT_LIMIT = 64 * 1024;
14
+ const TERM_GRACE_MS = 500;
15
+ const KILL_GRACE_MS = 500;
16
+ const POLL_MS = 20;
17
+ const activeProcessGroups = new Set();
18
+ let exitCleanupInstalled = false;
19
+ function installExitCleanup() {
20
+ if (exitCleanupInstalled)
21
+ return;
22
+ exitCleanupInstalled = true;
23
+ // The SDK bash module owns SIGINT/SIGTERM handlers which call process.exit().
24
+ // The synchronous exit event is consequently the only reliable composition point.
25
+ process.on('exit', () => {
26
+ for (const pid of activeProcessGroups) {
27
+ try {
28
+ process.kill(-pid, 'SIGKILL');
29
+ }
30
+ catch {
31
+ // The group already disappeared or the OS refused the last-resort signal.
32
+ }
33
+ }
34
+ });
35
+ }
36
+ export class BackgroundBashManager {
37
+ projectRoot;
38
+ openFile;
39
+ tasks = new Map();
40
+ launches = new Set();
41
+ listeners = new Set();
42
+ outputDirectory;
43
+ shutdownController = new AbortController();
44
+ closing = false;
45
+ constructor(projectRoot, sessionId, openFile = open) {
46
+ this.projectRoot = projectRoot;
47
+ this.openFile = openFile;
48
+ this.outputDirectory = path.join(sessionPaths(projectRoot).sessionsDir, sessionId, 'background');
49
+ installExitCleanup();
50
+ }
51
+ start(command) {
52
+ if (this.closing)
53
+ return Promise.reject(new Error('Background bash manager is shutting down'));
54
+ // Register the whole launch before its first asynchronous setup completes. shutdown()
55
+ // latches `closing`, waits this set, and only then takes its stop snapshot.
56
+ const launch = this.launch(command);
57
+ this.launches.add(launch);
58
+ void launch.then(() => this.launches.delete(launch), () => this.launches.delete(launch));
59
+ return launch;
60
+ }
61
+ async status(taskId) {
62
+ const task = this.lookup(taskId);
63
+ return this.serialize(task, () => this.snapshot(task));
64
+ }
65
+ /** Snapshots every current-runtime task in deterministic launch order. */
66
+ async list() {
67
+ return Promise.all([...this.tasks.values()].map((task) => this.serialize(task, () => this.snapshot(task))));
68
+ }
69
+ /** Subscribes to future terminal transitions; completed tasks are not replayed. */
70
+ subscribe(listener) {
71
+ this.listeners.add(listener);
72
+ return () => this.listeners.delete(listener);
73
+ }
74
+ async output(taskId) {
75
+ const task = this.lookup(taskId);
76
+ return this.serialize(task, () => this.readOutput(task));
77
+ }
78
+ async wait(taskId, waitMs, signal, wakeOnOutput = true) {
79
+ const task = this.lookup(taskId);
80
+ const maxWaitMs = wakeOnOutput ? OUTPUT_SENSITIVE_WAIT_MAX_MS : TERMINAL_FOCUSED_WAIT_MAX_MS;
81
+ if (!Number.isInteger(waitMs) || waitMs < 1 || waitMs > maxWaitMs) {
82
+ const focus = wakeOnOutput ? 'output-sensitive' : 'terminal-focused';
83
+ throw new Error(`Background bash ${focus} waitMs must be an integer from 1 to ${maxWaitMs}`);
84
+ }
85
+ if (!wakeOnOutput)
86
+ return this.waitForTerminal(task, waitMs, signal);
87
+ const deadline = Date.now() + waitMs;
88
+ const initialState = task.state;
89
+ const initialCursor = task.cursor;
90
+ while (true) {
91
+ const { output, status } = await this.serialize(task, async () => ({
92
+ output: await this.readOutput(task),
93
+ status: await this.snapshot(task),
94
+ }));
95
+ if (output.output !== '')
96
+ return { reason: 'output', status, output };
97
+ if (status.state !== 'running')
98
+ return { reason: 'terminal', status, output };
99
+ if (task.cursor !== initialCursor || task.state !== initialState) {
100
+ return { reason: 'changed', status, output };
101
+ }
102
+ if (signal?.aborted === true)
103
+ return { reason: 'cancelled', status, output };
104
+ if (this.closing)
105
+ return { reason: 'shutdown', status, output };
106
+ const remaining = deadline - Date.now();
107
+ if (remaining <= 0)
108
+ return { reason: 'timeout', status, output };
109
+ const interrupted = await waitForInterruption(Math.min(POLL_MS, remaining), signal, this.shutdownController.signal);
110
+ if (interrupted === 'cancelled' || interrupted === 'shutdown') {
111
+ const final = await this.serialize(task, async () => ({
112
+ output: await this.readOutput(task),
113
+ status: await this.snapshot(task),
114
+ }));
115
+ if (final.output.output !== '')
116
+ return { reason: 'output', ...final };
117
+ if (final.status.state !== 'running')
118
+ return { reason: 'terminal', ...final };
119
+ return { reason: interrupted, ...final };
120
+ }
121
+ }
122
+ }
123
+ async waitForTerminal(task, waitMs, signal) {
124
+ const deadline = Date.now() + waitMs;
125
+ let output;
126
+ while (true) {
127
+ const observed = await this.serialize(task, async () => {
128
+ output = await this.aggregateWaitOutput(task, output);
129
+ return this.snapshot(task);
130
+ });
131
+ if (observed.state !== 'running')
132
+ return this.finishTerminalWait(task, 'terminal', output);
133
+ if (signal?.aborted === true)
134
+ return this.finishTerminalWait(task, 'cancelled', output);
135
+ if (this.closing)
136
+ return this.finishTerminalWait(task, 'shutdown', output);
137
+ const remaining = deadline - Date.now();
138
+ if (remaining <= 0)
139
+ return this.finishTerminalWait(task, 'timeout', output);
140
+ const interrupted = await waitForInterruption(Math.min(POLL_MS, remaining), signal, this.shutdownController.signal);
141
+ if (interrupted === 'cancelled' || interrupted === 'shutdown') {
142
+ return this.finishTerminalWait(task, interrupted, output);
143
+ }
144
+ }
145
+ }
146
+ async finishTerminalWait(task, reason, output) {
147
+ const final = await this.serialize(task, async () => {
148
+ const aggregated = await this.aggregateWaitOutput(task, output);
149
+ return {
150
+ output: aggregated ?? await this.readOutput(task),
151
+ status: await this.snapshot(task),
152
+ };
153
+ });
154
+ const finalReason = final.status.state === 'running' ? reason : 'terminal';
155
+ return {
156
+ reason: finalReason,
157
+ ...final,
158
+ ...(finalReason === 'timeout'
159
+ ? { instruction: TERMINAL_WAIT_TIMEOUT_INSTRUCTION }
160
+ : {}),
161
+ };
162
+ }
163
+ async aggregateWaitOutput(task, output) {
164
+ const consumed = output === undefined ? 0 : output.endOffset - output.startOffset;
165
+ // Once another cursor consumer takes a range, this wait's eventual output can
166
+ // no longer be extended contiguously. Keep the retained prefix and leave all
167
+ // later bytes to the shared cursor instead of misrepresenting its offsets.
168
+ if (output !== undefined && (task.cursor !== output.endOffset || consumed >= OUTPUT_LIMIT)) {
169
+ return { ...output, hasMore: await this.hasUnreadOutput(task) };
170
+ }
171
+ const next = await this.readOutput(task, OUTPUT_LIMIT - consumed);
172
+ if (next.output === '') {
173
+ return output === undefined ? undefined : { ...output, hasMore: next.hasMore };
174
+ }
175
+ if (output === undefined)
176
+ return next;
177
+ return {
178
+ ...output,
179
+ output: output.output + next.output,
180
+ endOffset: next.endOffset,
181
+ hasMore: next.hasMore,
182
+ };
183
+ }
184
+ async hasUnreadOutput(task) {
185
+ const handle = await this.openOwnedLog(task);
186
+ try {
187
+ return (await handle.stat()).size > task.cursor;
188
+ }
189
+ finally {
190
+ await handle.close();
191
+ }
192
+ }
193
+ stop(taskId) {
194
+ const task = this.lookup(taskId);
195
+ if (task.state !== 'running')
196
+ return this.status(taskId);
197
+ if (task.stopPromise !== undefined)
198
+ return task.stopPromise;
199
+ // Set precedence before entering the queue: a close callback already performing
200
+ // natural cleanup must still settle as stopped when this call races it.
201
+ task.stopRequested = true;
202
+ const stopping = this.serialize(task, async () => {
203
+ if (task.state === 'running') {
204
+ const cleaned = await cleanupProcessGroup(task.pid);
205
+ if (cleaned)
206
+ await this.finish(task, 'stopped');
207
+ }
208
+ return this.snapshot(task);
209
+ });
210
+ task.stopPromise = stopping;
211
+ return stopping;
212
+ }
213
+ async shutdown() {
214
+ this.closing = true;
215
+ this.shutdownController.abort();
216
+ await Promise.allSettled([...this.launches]);
217
+ const running = [...this.tasks.values()].filter((task) => task.state === 'running');
218
+ await Promise.allSettled(running.map((task) => this.stop(task.id)));
219
+ }
220
+ async launch(command) {
221
+ const id = `bg-${randomUUID()}`;
222
+ await mkdir(this.outputDirectory, { recursive: true });
223
+ const outputPath = path.join(this.outputDirectory, `${id}.log`);
224
+ const handle = await this.openFile(outputPath, 'wx', 0o600);
225
+ let outputIdentity;
226
+ try {
227
+ outputIdentity = await handle.stat();
228
+ }
229
+ catch (error) {
230
+ await handle.close().catch(() => undefined);
231
+ throw error;
232
+ }
233
+ let child;
234
+ let closed;
235
+ try {
236
+ // The latch is checked immediately before spawn. A shutdown racing directory/file
237
+ // setup either prevents spawn here or waits for this launch and then sees the task.
238
+ if (this.closing)
239
+ throw new Error('Background bash manager is shutting down');
240
+ child = spawn('/bin/bash', ['-lc', command], {
241
+ cwd: this.projectRoot,
242
+ env: process.env,
243
+ detached: true,
244
+ stdio: ['ignore', handle.fd, handle.fd],
245
+ });
246
+ // Register as soon as Node exposes the pid, before yielding to the event
247
+ // loop for the spawn confirmation. A signal-triggered process.exit() in
248
+ // that narrow window must still kill the new group.
249
+ if (child.pid !== undefined)
250
+ activeProcessGroups.add(child.pid);
251
+ closed = new Promise((resolve) => {
252
+ child?.once('close', (code, signal) => resolve({ code, signal }));
253
+ });
254
+ await new Promise((resolve, reject) => {
255
+ const onSpawn = () => {
256
+ // Keep the one-shot error listener after spawn as well: ChildProcess may
257
+ // still emit an asynchronous error, and an unhandled event would crash.
258
+ resolve();
259
+ };
260
+ const onError = (error) => {
261
+ child?.off('spawn', onSpawn);
262
+ reject(error);
263
+ };
264
+ child?.once('spawn', onSpawn);
265
+ child?.once('error', onError);
266
+ });
267
+ }
268
+ catch (error) {
269
+ if (child?.pid !== undefined)
270
+ await cleanupProcessGroup(child.pid);
271
+ await handle.close().catch(() => undefined);
272
+ throw error;
273
+ }
274
+ // The child inherited the descriptor; close only the parent's copy. A close
275
+ // failure after spawn is treated as launch failure so no untracked process
276
+ // escapes into runtime shutdown.
277
+ try {
278
+ await handle.close();
279
+ }
280
+ catch (error) {
281
+ if (child.pid !== undefined)
282
+ await cleanupProcessGroup(child.pid);
283
+ throw error;
284
+ }
285
+ const pid = child.pid;
286
+ if (pid === undefined)
287
+ throw new Error('Background bash spawned without a process id');
288
+ const task = {
289
+ id,
290
+ command,
291
+ pid,
292
+ outputPath,
293
+ outputDevice: outputIdentity.dev,
294
+ outputInode: outputIdentity.ino,
295
+ startedAt: new Date().toISOString(),
296
+ child,
297
+ state: 'running',
298
+ finishedAt: null,
299
+ exitCode: null,
300
+ signal: null,
301
+ cursor: 0,
302
+ stopRequested: false,
303
+ serial: Promise.resolve(),
304
+ };
305
+ this.tasks.set(id, task);
306
+ void closed.then(({ code, signal }) => {
307
+ task.exitCode = code;
308
+ task.signal = signal;
309
+ return this.serialize(task, async () => {
310
+ if (task.state !== 'running')
311
+ return;
312
+ // A shell leader can exit while descendants retain its process group. Do not
313
+ // report terminal completion until that entire ownership boundary is gone.
314
+ const cleaned = await cleanupProcessGroup(task.pid);
315
+ if (cleaned) {
316
+ const state = task.stopRequested ? 'stopped' : code === 0 ? 'succeeded' : 'failed';
317
+ await this.finish(task, state);
318
+ }
319
+ });
320
+ }).catch(() => undefined);
321
+ return { taskId: id, pid, outputPath };
322
+ }
323
+ async finish(task, state) {
324
+ if (task.state !== 'running')
325
+ return;
326
+ task.state = state;
327
+ task.finishedAt = new Date().toISOString();
328
+ // Notification delivery must survive diagnostic-file failures. snapshot()
329
+ // already degrades open/stat problems to outputBytes:null; keep close errors in
330
+ // that same domain instead of turning a completed task into a missing event.
331
+ let snapshot;
332
+ try {
333
+ snapshot = Object.freeze(await this.snapshot(task));
334
+ }
335
+ catch {
336
+ snapshot = Object.freeze(this.taskMetadata(task, null));
337
+ }
338
+ for (const listener of [...this.listeners]) {
339
+ try {
340
+ Promise.resolve(listener(snapshot)).catch(() => undefined);
341
+ }
342
+ catch {
343
+ // Observers cannot fail process cleanup or suppress other listeners.
344
+ }
345
+ }
346
+ }
347
+ lookup(taskId) {
348
+ if (!/^bg-[0-9a-f-]{36}$/.test(taskId)) {
349
+ throw new Error(`Invalid background bash task id: ${JSON.stringify(taskId)}`);
350
+ }
351
+ const task = this.tasks.get(taskId);
352
+ if (task === undefined)
353
+ throw new Error(`Unknown background bash task: ${taskId}`);
354
+ return task;
355
+ }
356
+ serialize(task, operation) {
357
+ const result = task.serial.then(operation, operation);
358
+ task.serial = result.then(() => undefined, () => undefined);
359
+ return result;
360
+ }
361
+ async snapshot(task) {
362
+ let outputBytes = null;
363
+ let handle;
364
+ try {
365
+ handle = await this.openOwnedLog(task);
366
+ outputBytes = (await handle.stat()).size;
367
+ }
368
+ catch {
369
+ // Process metadata remains useful when a retained log was externally removed.
370
+ }
371
+ finally {
372
+ try {
373
+ await handle?.close();
374
+ }
375
+ catch {
376
+ outputBytes = null;
377
+ }
378
+ }
379
+ return this.taskMetadata(task, outputBytes);
380
+ }
381
+ taskMetadata(task, outputBytes) {
382
+ return {
383
+ taskId: task.id,
384
+ state: task.state,
385
+ command: task.command,
386
+ pid: task.pid,
387
+ startedAt: task.startedAt,
388
+ finishedAt: task.finishedAt,
389
+ exitCode: task.exitCode,
390
+ signal: task.signal,
391
+ outputPath: task.outputPath,
392
+ outputBytes,
393
+ };
394
+ }
395
+ async readOutput(task, limit = OUTPUT_LIMIT) {
396
+ let handle;
397
+ let size;
398
+ try {
399
+ handle = await this.openOwnedLog(task);
400
+ size = (await handle.stat()).size;
401
+ }
402
+ catch (error) {
403
+ await handle?.close();
404
+ throw new Error(`Cannot read background task log ${task.outputPath}: ${errorMessage(error)}`);
405
+ }
406
+ const startOffset = task.cursor;
407
+ const available = Math.max(0, size - startOffset);
408
+ if (available === 0) {
409
+ await handle.close();
410
+ return { taskId: task.id, output: '', startOffset, endOffset: startOffset, hasMore: false, outputPath: task.outputPath };
411
+ }
412
+ const bytesToRead = Math.min(available, limit + 3);
413
+ const buffer = Buffer.allocUnsafe(bytesToRead);
414
+ let bytesRead;
415
+ try {
416
+ ({ bytesRead } = await handle.read(buffer, 0, bytesToRead, startOffset));
417
+ }
418
+ catch (error) {
419
+ throw new Error(`Cannot read background task log ${task.outputPath}: ${errorMessage(error)}`);
420
+ }
421
+ finally {
422
+ await handle.close();
423
+ }
424
+ const data = buffer.subarray(0, bytesRead);
425
+ const terminalEof = task.state !== 'running' && startOffset + bytesRead >= size;
426
+ const consumed = completeUtf8Boundary(data, Math.min(limit, bytesRead), terminalEof);
427
+ const output = data.subarray(0, consumed).toString('utf8');
428
+ task.cursor += consumed;
429
+ return {
430
+ taskId: task.id,
431
+ output,
432
+ startOffset,
433
+ endOffset: task.cursor,
434
+ hasMore: size > task.cursor,
435
+ outputPath: task.outputPath,
436
+ };
437
+ }
438
+ async openOwnedLog(task) {
439
+ const handle = await this.openFile(task.outputPath, constants.O_RDONLY | constants.O_NOFOLLOW);
440
+ try {
441
+ const metadata = await handle.stat();
442
+ if (!metadata.isFile() || metadata.dev !== task.outputDevice || metadata.ino !== task.outputInode) {
443
+ throw new Error('the task log was replaced');
444
+ }
445
+ return handle;
446
+ }
447
+ catch (error) {
448
+ await handle.close();
449
+ throw error;
450
+ }
451
+ }
452
+ }
453
+ function completeUtf8Boundary(data, boundary, terminalEof) {
454
+ if (boundary === 0 || (terminalEof && boundary === data.length))
455
+ return boundary;
456
+ let lead = boundary - 1;
457
+ while (lead >= Math.max(0, boundary - 3) && (data[lead] & 0xc0) === 0x80)
458
+ lead -= 1;
459
+ if (lead < 0)
460
+ return boundary;
461
+ const first = data[lead];
462
+ const expected = first < 0x80 ? 1 : first >= 0xc2 && first <= 0xdf ? 2 : first <= 0xef ? 3 : first <= 0xf4 ? 4 : 1;
463
+ const present = boundary - lead;
464
+ if (expected <= present)
465
+ return boundary;
466
+ const needed = expected - present;
467
+ if (boundary + needed <= data.length) {
468
+ for (let index = boundary; index < boundary + needed; index += 1) {
469
+ if ((data[index] & 0xc0) !== 0x80)
470
+ return boundary;
471
+ }
472
+ return boundary + needed;
473
+ }
474
+ // A growing file may currently end in half a code point. Keep those bytes for
475
+ // the next poll; at terminal EOF malformed bytes are decoded with replacement.
476
+ return terminalEof ? boundary : lead;
477
+ }
478
+ async function cleanupProcessGroup(pid) {
479
+ if (!groupExists(pid)) {
480
+ activeProcessGroups.delete(pid);
481
+ return true;
482
+ }
483
+ signalGroup(pid, 'SIGTERM');
484
+ if (await waitForGroupExit(pid, TERM_GRACE_MS))
485
+ return true;
486
+ signalGroup(pid, 'SIGKILL');
487
+ return waitForGroupExit(pid, KILL_GRACE_MS);
488
+ }
489
+ function signalGroup(pid, signal) {
490
+ try {
491
+ process.kill(-pid, signal);
492
+ }
493
+ catch (error) {
494
+ if (!isNoSuchProcess(error))
495
+ return;
496
+ }
497
+ }
498
+ function groupExists(pid) {
499
+ try {
500
+ process.kill(-pid, 0);
501
+ return true;
502
+ }
503
+ catch (error) {
504
+ return !isNoSuchProcess(error);
505
+ }
506
+ }
507
+ async function waitForGroupExit(pid, timeoutMs) {
508
+ const deadline = Date.now() + timeoutMs;
509
+ while (groupExists(pid) && Date.now() < deadline) {
510
+ await new Promise((resolve) => setTimeout(resolve, POLL_MS));
511
+ }
512
+ const gone = !groupExists(pid);
513
+ if (gone)
514
+ activeProcessGroups.delete(pid);
515
+ return gone;
516
+ }
517
+ async function waitForInterruption(timeoutMs, callerSignal, shutdownSignal) {
518
+ if (callerSignal?.aborted === true)
519
+ return 'cancelled';
520
+ if (shutdownSignal.aborted)
521
+ return 'shutdown';
522
+ return new Promise((resolve) => {
523
+ let settled = false;
524
+ const finish = (result) => {
525
+ if (settled)
526
+ return;
527
+ settled = true;
528
+ clearTimeout(timer);
529
+ callerSignal?.removeEventListener('abort', onCancelled);
530
+ shutdownSignal.removeEventListener('abort', onShutdown);
531
+ resolve(result);
532
+ };
533
+ const onCancelled = () => finish('cancelled');
534
+ const onShutdown = () => finish('shutdown');
535
+ const timer = setTimeout(() => finish('elapsed'), timeoutMs);
536
+ callerSignal?.addEventListener('abort', onCancelled, { once: true });
537
+ shutdownSignal.addEventListener('abort', onShutdown, { once: true });
538
+ if (callerSignal?.aborted === true)
539
+ finish('cancelled');
540
+ else if (shutdownSignal.aborted)
541
+ finish('shutdown');
542
+ });
543
+ }
544
+ function isNoSuchProcess(error) {
545
+ return error instanceof Error && 'code' in error && error.code === 'ESRCH';
546
+ }
547
+ function errorMessage(error) {
548
+ return error instanceof Error ? error.message : String(error);
549
+ }
550
+ // Bedrock requires every tool input schema's top-level JSON `type` to be
551
+ // `object`; a Zod union serializes as a top-level `anyOf` and the request is
552
+ // rejected before the model can call it. Keep one object and enforce the
553
+ // mode-specific shape in refinement instead.
554
+ const inputSchema = z.object({
555
+ mode: z.enum(['execute', 'restart', 'start', 'list', 'status', 'output', 'wait', 'stop'])
556
+ .describe('Operation mode — required on every call; execute runs one foreground command in the persistent shell (a bare {command} without mode is rejected)'),
557
+ command: z.string().optional().describe('Command required by execute and start; ignored by status, output, wait, and stop'),
558
+ timeout: z.number().positive().optional().describe('Timeout in seconds for execute mode; ignored by start'),
559
+ taskId: z.string().optional().describe('Session-local task id required by status, output, wait, and stop'),
560
+ waitMs: z.number().int().min(1).max(TERMINAL_FOCUSED_WAIT_MAX_MS).optional()
561
+ .describe(`Bounded wait in milliseconds, required only by wait mode: at most ${OUTPUT_SENSITIVE_WAIT_MAX_MS} by default, or ${TERMINAL_FOCUSED_WAIT_MAX_MS} only with wakeOnOutput:false`),
562
+ wakeOnOutput: z.boolean().optional()
563
+ .describe('Wait mode only: false retains intermediate output and wakes only on terminal state, cancellation, shutdown, or timeout; defaults to true'),
564
+ }).strict().superRefine((input, context) => {
565
+ if (input.mode === 'execute' && input.command === undefined) {
566
+ context.addIssue({ code: 'custom', path: ['command'], message: 'command is required in execute mode' });
567
+ }
568
+ if (input.mode === 'start' && (input.command === undefined || input.command.trim() === '')) {
569
+ context.addIssue({ code: 'custom', path: ['command'], message: 'command is required in start mode' });
570
+ }
571
+ if ((input.mode === 'status' || input.mode === 'output' || input.mode === 'wait' || input.mode === 'stop') && !input.taskId) {
572
+ context.addIssue({ code: 'custom', path: ['taskId'], message: `taskId is required in ${input.mode} mode` });
573
+ }
574
+ if (input.mode === 'wait' && input.waitMs === undefined) {
575
+ context.addIssue({ code: 'custom', path: ['waitMs'], message: 'waitMs is required in wait mode' });
576
+ }
577
+ if (input.mode === 'wait' && input.waitMs !== undefined &&
578
+ input.wakeOnOutput !== false && input.waitMs > OUTPUT_SENSITIVE_WAIT_MAX_MS) {
579
+ context.addIssue({
580
+ code: 'custom',
581
+ path: ['waitMs'],
582
+ message: `waitMs above ${OUTPUT_SENSITIVE_WAIT_MAX_MS} requires wakeOnOutput:false`,
583
+ });
584
+ }
585
+ if (input.mode !== 'execute' && input.mode !== 'restart' && input.mode !== 'start' && input.timeout !== undefined) {
586
+ context.addIssue({ code: 'custom', path: ['timeout'], message: `timeout is not accepted in ${input.mode} mode` });
587
+ }
588
+ if (input.mode === 'list' && input.command !== undefined) {
589
+ context.addIssue({ code: 'custom', path: ['command'], message: 'command is not accepted in list mode' });
590
+ }
591
+ if ((input.mode === 'start' || input.mode === 'list') && input.taskId !== undefined) {
592
+ context.addIssue({ code: 'custom', path: ['taskId'], message: `taskId is not accepted in ${input.mode} mode` });
593
+ }
594
+ if (input.mode !== 'wait' && input.waitMs !== undefined) {
595
+ context.addIssue({ code: 'custom', path: ['waitMs'], message: `waitMs is not accepted in ${input.mode} mode` });
596
+ }
597
+ if (input.mode !== 'wait' && input.wakeOnOutput !== undefined) {
598
+ context.addIssue({ code: 'custom', path: ['wakeOnOutput'], message: `wakeOnOutput is not accepted in ${input.mode} mode` });
599
+ }
600
+ });
601
+ /** Configures the pinned SDK foreground tool from Darwin's verified project root. */
602
+ export function createForegroundBashTool(projectRoot) {
603
+ return createBash({ cwd: projectRoot, projectRoot });
604
+ }
605
+ export function createBackgroundBashTool(manager, foreground = sdkBash) {
606
+ return tool({
607
+ name: 'bash',
608
+ description: 'Runs foreground commands in a persistent shell and session-owned background commands. ' +
609
+ 'Modes: execute, restart, start, list, status, output, wait, and stop. ' +
610
+ 'Never block execute mode with sleep to wait for something slow: start the command in the background, ' +
611
+ 'do other work, then use wait with taskId and waitMs. ' +
612
+ `Output-sensitive waits use 1-${OUTPUT_SENSITIVE_WAIT_MAX_MS} ms and return {reason, status, output}; by default they wake on output or another consumer changing the cursor. ` +
613
+ `Set wakeOnOutput:false for a terminal-focused wait up to ${TERMINAL_FOCUSED_WAIT_MAX_MS} ms that aggregates intermediate output and wakes only on terminal state, cancellation, shutdown, or timeout. ` +
614
+ 'A still-running terminal-focused timeout tells you to call wait again before ending when later work depends on completion; background completion does not resume the agent. ' +
615
+ 'A plain ssh in execute mode waits on a tty and hangs the call: pass -T -o BatchMode=yes and run it as a background task (start, then wait). ' +
616
+ 'Foreground execute runs with stdin from /dev/null: anything that prompts or reads stdin gets EOF at once and fails, so pass the command\'s non-interactive flags (-y, --yes, --force, --no-input).',
617
+ inputSchema,
618
+ callback: (input, context) => {
619
+ switch (input.mode) {
620
+ case 'execute':
621
+ case 'restart':
622
+ return foreground.invoke(input, context);
623
+ case 'start':
624
+ return manager.start(input.command);
625
+ case 'list':
626
+ return manager.list();
627
+ case 'status':
628
+ return manager.status(input.taskId);
629
+ case 'output':
630
+ return manager.output(input.taskId);
631
+ case 'wait':
632
+ return manager.wait(input.taskId, input.waitMs, context?.agent.cancelSignal, input.wakeOnOutput);
633
+ case 'stop':
634
+ return manager.stop(input.taskId);
635
+ }
636
+ },
637
+ });
638
+ }
639
+ //# sourceMappingURL=background-bash.js.map