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,797 @@
1
+ /**
2
+ * Permission gating for tool calls.
3
+ *
4
+ * Built on the SDK's intervention framework: a handler passed via
5
+ * `AgentConfig.interventions` gets `beforeToolCall` for every call and returns
6
+ * proceed or deny. Denial becomes an error tool result the model reads and
7
+ * responds to, so the agent loop keeps running.
8
+ *
9
+ * Approval is decided by an injected {@link PermissionBridge}, so the same gate
10
+ * drives a readline prompt today and the Ink prompt later.
11
+ */
12
+ import path from 'node:path';
13
+ import { isSensitiveDarwinPath } from '../paths.js';
14
+ import { InterventionActions, InterventionHandler } from '@strands-agents/sdk';
15
+ import { MANAGE_BACKGROUND_TASK_TOOL_NAME } from './background-delegation.js';
16
+ import { hasShellMetacharacters, matchesAnyRule, splitBashSegments, suggestRules, } from './permission-rules.js';
17
+ export const APPROVAL_MODES = ['default', 'auto', 'plan', 'yolo'];
18
+ export function isApprovalMode(value) {
19
+ return typeof value === 'string' && APPROVAL_MODES.includes(value);
20
+ }
21
+ /**
22
+ * One clause per mode, for a notice that has to say what the mode the user just
23
+ * typed actually does. The header words the same three states itself, because it
24
+ * has one row to spend and a notice does not.
25
+ */
26
+ export function describeApprovalMode(mode) {
27
+ switch (mode) {
28
+ case 'default':
29
+ return 'default — statically safe calls run silently; everything else asks';
30
+ case 'auto':
31
+ return 'auto — a model classifier judges what the static rules cannot clear; only flagged calls ask';
32
+ case 'plan':
33
+ return 'plan — read-only; write and execute calls are denied';
34
+ case 'yolo':
35
+ return 'yolo — every tool call runs without confirmation';
36
+ }
37
+ }
38
+ /**
39
+ * The one source every non-delegated call carries. Frozen because it is shared by
40
+ * every parent request: a consumer that mutated it would relabel all of them.
41
+ */
42
+ export const PARENT_PERMISSION_SOURCE = Object.freeze({
43
+ kind: 'parent',
44
+ label: 'parent',
45
+ });
46
+ /**
47
+ * A signal that never aborts, for the bridges and fixtures that construct a
48
+ * request themselves. Frozen into one instance on purpose: an
49
+ * {@link AbortController} per fixture would suggest withdrawal is in play there.
50
+ */
51
+ export const NEVER_WITHDRAWN = new AbortController().signal;
52
+ /** Approves everything without asking. For non-interactive runs and tests. */
53
+ export const allowAllBridge = async () => ({ allowed: true });
54
+ const DEFAULT_CLASSIFIER_TIMEOUT_MS = 5000;
55
+ /**
56
+ * How many times one tool call may be re-decided because the mode changed under
57
+ * it. Every restart costs the user a deliberate keystroke, so this is unreachable
58
+ * in practice; it exists so the loop is bounded by construction rather than by
59
+ * an argument about human behaviour. Reaching it denies — the fail-closed
60
+ * direction — and says why.
61
+ */
62
+ const MAX_MODE_CHANGE_RESTARTS = 16;
63
+ /** A decision abandoned because the mode changed while it was pending. */
64
+ const WITHDRAWN = Symbol('withdrawn');
65
+ export class PermissionGate extends InterventionHandler {
66
+ options;
67
+ name = 'darwin:permission-gate';
68
+ /** Config rules plus anything the user accepted during this session. */
69
+ rules;
70
+ /**
71
+ * Provenance of every rule in {@link rules}, keyed by the rule string. Kept as
72
+ * a side table rather than widening `rules` because the decision path
73
+ * (`matchesAnyRule`) reads the plain strings and must stay unchanged.
74
+ */
75
+ ruleOrigins = new Map();
76
+ /**
77
+ * Live enforcement policy, not `options.mode`: `/mode` moves it mid-session and
78
+ * every decision — parent and child, since they share this instance — reads it
79
+ * from here.
80
+ */
81
+ currentMode;
82
+ /**
83
+ * One controller per in-flight decision that is waiting on something external
84
+ * (a classifier verdict, or the user's answer). {@link setMode} aborts them all.
85
+ */
86
+ waiting = new Set();
87
+ constructor(options) {
88
+ super();
89
+ this.options = options;
90
+ this.rules = [...(options.allowRules ?? [])];
91
+ for (const rule of this.rules)
92
+ this.ruleOrigins.set(rule, 'configured');
93
+ this.currentMode = options.mode;
94
+ }
95
+ /** The mode enforcing right now. */
96
+ get mode() {
97
+ return this.currentMode;
98
+ }
99
+ /**
100
+ * Switches the mode for the rest of the session. **User-only**: nothing the
101
+ * model can emit reaches this — no tool mutates the gate, the value is never
102
+ * read back from a file after startup, and the two callers (the TUI's submit
103
+ * handler and the dev REPL's input loop) are fed by the keyboard alone.
104
+ *
105
+ * Every decision still pending is *withdrawn* rather than resolved: a
106
+ * classifier verdict answers a question only `auto` asks, and a prompt on screen
107
+ * was worded under the previous policy. The gate re-decides each of those calls
108
+ * from the top under the new mode, so no call is ever half-judged by two modes.
109
+ * One rule for every transition on purpose — the alternative is a table of which
110
+ * transitions are benign, and that table is where the bug would live.
111
+ *
112
+ * Deliberately not persisted: this changes *enforcement*, and a widening that
113
+ * outlives the session is exactly what the allow-rule exemptions exist to
114
+ * prevent (`./permission-rules.ts`).
115
+ */
116
+ setMode(next) {
117
+ const previous = this.currentMode;
118
+ if (next === previous)
119
+ return { mode: previous, previous, withdrawn: 0 };
120
+ this.currentMode = next;
121
+ // Copied before aborting: a bridge that drops its prompt synchronously lets
122
+ // the awaiting decision remove itself from this set as we iterate it.
123
+ const waiting = [...this.waiting];
124
+ for (const controller of waiting)
125
+ controller.abort();
126
+ return { mode: next, previous, withdrawn: waiting.length };
127
+ }
128
+ /**
129
+ * Starts honouring a rule immediately. Separate from persistence on purpose: a
130
+ * rule the user just accepted must hold for the rest of the session even if
131
+ * writing it to the config fails.
132
+ */
133
+ addAllowRule(rule) {
134
+ if (this.rules.includes(rule))
135
+ return;
136
+ this.rules.push(rule);
137
+ this.ruleOrigins.set(rule, 'session');
138
+ }
139
+ /**
140
+ * Stops honouring a rule immediately: the very next matching call goes back
141
+ * through the ordinary decision path and prompts. Removal-only by construction
142
+ * — this is the narrowing half of the rule lifecycle, and there is nothing it
143
+ * can add. Returns whether the rule was live, so the caller can refuse to
144
+ * "revoke" (and persist the removal of) a rule that was never in force.
145
+ */
146
+ removeAllowRule(rule) {
147
+ const index = this.rules.indexOf(rule);
148
+ if (index === -1)
149
+ return false;
150
+ this.rules.splice(index, 1);
151
+ this.ruleOrigins.delete(rule);
152
+ return true;
153
+ }
154
+ /** Rules currently in effect, config and session alike. */
155
+ get allowRules() {
156
+ return this.rules;
157
+ }
158
+ /**
159
+ * The live rules with their provenance, in the order they are consulted.
160
+ * A fresh array per call: the report must not hand out a mutable window onto
161
+ * the enforcement surface.
162
+ */
163
+ listAllowRules() {
164
+ return this.rules.map((rule) => ({ rule, origin: this.ruleOrigins.get(rule) ?? 'session' }));
165
+ }
166
+ /**
167
+ * Denies plan-mode mutation before hooks, rules, classifiers, or prompts can
168
+ * have side effects. Undefined means the ordinary permission flow still owns
169
+ * the call; callers must not treat it as approval.
170
+ *
171
+ * Reads the live mode, so entering plan mid-session guards the very next call
172
+ * and leaving it stops guarding immediately.
173
+ */
174
+ planGuard(toolName, input) {
175
+ if (this.currentMode !== 'plan')
176
+ return undefined;
177
+ const request = classify(toolName, input);
178
+ if (request.kind === 'read')
179
+ return undefined;
180
+ return InterventionActions.deny(`Plan mode blocked this ${request.kind} call to ${request.toolName}. ` +
181
+ `Continue with read-only inspection, or ask the user to run outside plan mode ` +
182
+ `(they can leave it with /mode default) before changing or executing anything.`);
183
+ }
184
+ /**
185
+ * Decides one call, restarting whenever the user changes the mode underneath it.
186
+ *
187
+ * The loop is the whole in-flight contract: a withdrawn decision is discarded,
188
+ * never applied, and the call is judged again from the top — plan guard first —
189
+ * by whatever mode is in force now.
190
+ */
191
+ async beforeToolCall(event) {
192
+ const promptIdentity = {};
193
+ for (let attempt = 1;; attempt += 1) {
194
+ const withdrawal = new AbortController();
195
+ this.waiting.add(withdrawal);
196
+ let action;
197
+ try {
198
+ action = await this.decideOnce(event, withdrawal.signal, promptIdentity);
199
+ }
200
+ finally {
201
+ this.waiting.delete(withdrawal);
202
+ }
203
+ if (action !== WITHDRAWN)
204
+ return action;
205
+ if (attempt >= MAX_MODE_CHANGE_RESTARTS) {
206
+ return InterventionActions.deny(`The permission mode changed ${attempt} times while ${event.toolUse.name} was waiting for a decision, ` +
207
+ `so darwin stopped re-asking. Tell the user, and try again once they have settled on a mode.`);
208
+ }
209
+ }
210
+ }
211
+ /**
212
+ * One pass of the decision, under the mode in force when it started.
213
+ *
214
+ * Returns {@link WITHDRAWN} instead of a decision when the mode changed while
215
+ * this pass was waiting on the classifier or on the user — including the case
216
+ * where the answer and the change land in the same tick, which is why the race
217
+ * re-checks `aborted` after the promise settles.
218
+ */
219
+ async decideOnce(event, withdrawn, promptIdentity) {
220
+ // Resolved for every call, not only the ones that prompt: a classifier or a
221
+ // bridge that wants to know whose work it is judging should not have to
222
+ // reconstruct it from the tool input.
223
+ const source = this.sourceOf(event.agent.id);
224
+ // A `workflow` node's declared write scopes (SER-065) are judged first: they
225
+ // are a structural fact of the DAG the parent declared, not a confirmation
226
+ // policy, so they hold in every mode (yolo included), never prompt, and are
227
+ // not something a rule or a classifier verdict can widen.
228
+ const scoped = this.writeScopeGuard(event.toolUse.name, event.toolUse.input, source);
229
+ if (scoped !== undefined)
230
+ return scoped;
231
+ const guarded = this.planGuard(event.toolUse.name, event.toolUse.input);
232
+ if (guarded !== undefined)
233
+ return guarded;
234
+ const base = classify(event.toolUse.name, event.toolUse.input);
235
+ const request = {
236
+ ...base,
237
+ ...assessRisk(base, this.options.projectRoot),
238
+ source,
239
+ promptIdentity,
240
+ suggestions: suggestRules(base, this.options.projectRoot),
241
+ withdrawn,
242
+ };
243
+ if (this.currentMode === 'yolo') {
244
+ return InterventionActions.proceed({ reason: 'yolo mode approves everything' });
245
+ }
246
+ if (request.risk === 'safe') {
247
+ return InterventionActions.proceed({ reason: request.riskReason });
248
+ }
249
+ // Before the classifier, not after: a rule the user wrote down should save the
250
+ // model call too, not just the prompt.
251
+ const matched = matchesAnyRule(this.rules, base, this.options.projectRoot);
252
+ if (matched !== undefined) {
253
+ return InterventionActions.proceed({ reason: `allowed by rule ${matched}` });
254
+ }
255
+ if (this.currentMode === 'auto') {
256
+ const verdict = await raceWithdrawal(this.classifierVerdict(request), withdrawn);
257
+ // The verdict answers "may auto mode skip the prompt", so a mode change
258
+ // makes it moot — discarded, exactly as the peer product documents.
259
+ if (verdict === WITHDRAWN)
260
+ return WITHDRAWN;
261
+ if (verdict.safe) {
262
+ return InterventionActions.proceed({ reason: `classifier: ${verdict.reason}` });
263
+ }
264
+ // Escalating to the human: show them why the classifier balked. The details
265
+ // array is our own copy (classify builds a fresh one per call), so pushing
266
+ // here cannot leak into other renders of the same tool call.
267
+ request.details.push({ label: 'Classifier', value: verdict.reason });
268
+ }
269
+ const decision = await raceWithdrawal(this.options.ask(request), withdrawn);
270
+ if (decision === WITHDRAWN)
271
+ return WITHDRAWN;
272
+ if (decision.allowed) {
273
+ // Only on approval: a rule attached to a refusal would be a contradiction.
274
+ if (decision.rule !== undefined)
275
+ this.addAllowRule(decision.rule);
276
+ return InterventionActions.proceed({ reason: 'approved by user' });
277
+ }
278
+ // deny() rather than confirm(): a rejected confirm reaches the model as
279
+ // `CONFIRMATION_FAILED: <prompt>`, which models misread as a system failure
280
+ // and retry. deny() controls the wording, and the SDK turns it into an error
281
+ // tool result that ends up in history as `DENIED: <reason>`.
282
+ return InterventionActions.deny(`The user denied permission to run ${request.toolName}. ` +
283
+ `Do not retry it or attempt the same action another way. ` +
284
+ `Tell the user what you wanted to do and ask how to proceed.`);
285
+ }
286
+ /**
287
+ * Who is asking. A tracked dispatch resolves to its child label; anything else
288
+ * is the parent, because the runtime assembles exactly one `Agent` and every
289
+ * other agent in the process is a dispatch this resolver knows about.
290
+ */
291
+ sourceOf(agentId) {
292
+ const dispatch = this.options.dispatchSource?.(agentId);
293
+ if (dispatch === undefined)
294
+ return PARENT_PERMISSION_SOURCE;
295
+ return {
296
+ kind: 'child',
297
+ label: dispatch.label,
298
+ dispatchId: dispatch.dispatchId,
299
+ agentName: dispatch.agentName,
300
+ ...(dispatch.writeScopes === undefined ? {} : { writeScopes: dispatch.writeScopes }),
301
+ };
302
+ }
303
+ /**
304
+ * Denies a scoped `workflow` node's `fileEditor` write that lands outside every
305
+ * declared scope. Undefined means the ordinary flow owns the call — including
306
+ * every parent call, every `subagent` dispatch, every unscoped node, `view`, and
307
+ * every other tool (bash is deliberately not covered: a command's write set is
308
+ * not statically knowable, and the description says so).
309
+ */
310
+ writeScopeGuard(toolName, input, source) {
311
+ if (source.kind !== 'child' || source.writeScopes === undefined)
312
+ return undefined;
313
+ const violation = writeScopeViolation(toolName, input, source.writeScopes, this.options.projectRoot);
314
+ if (violation === undefined)
315
+ return undefined;
316
+ return InterventionActions.deny(`Workflow node ${source.label} declared writeScopes [${source.writeScopes.join(', ')}] and ` +
317
+ `fileEditor ${violation.command} on ${violation.path} is outside every declared scope. ` +
318
+ `Do not retry this write or route it elsewhere outside your scope; ` +
319
+ `finish what lies inside it and report the out-of-scope change in your final answer.`);
320
+ }
321
+ /**
322
+ * Runs the classifier with a hard timeout. Every failure mode — missing
323
+ * classifier, throw, timeout, or a hung promise — collapses to "not safe", so
324
+ * degradation always lands on asking the user, never on silent approval.
325
+ */
326
+ async classifierVerdict(request) {
327
+ const { classifier, classifierTimeoutMs = DEFAULT_CLASSIFIER_TIMEOUT_MS } = this.options;
328
+ if (classifier === undefined) {
329
+ return { safe: false, reason: 'no classifier configured — asking user' };
330
+ }
331
+ try {
332
+ return await withTimeout(classifier(request), classifierTimeoutMs);
333
+ }
334
+ catch (error) {
335
+ const cause = error instanceof Error ? error.message : String(error);
336
+ return { safe: false, reason: `classifier unavailable (${cause}) — asking user` };
337
+ }
338
+ }
339
+ }
340
+ /**
341
+ * Resolves with {@link WITHDRAWN} as soon as the mode changes, and — the part that
342
+ * matters — also when the promise settles in the same tick as the change. A
343
+ * decision taken under a mode that is no longer in force is never applied, so the
344
+ * check happens after the settle, not only before the wait.
345
+ *
346
+ * A rejection still propagates: an `ask` that throws is a bridge failure, not a
347
+ * withdrawal, and the gate's callers have always seen it.
348
+ */
349
+ function raceWithdrawal(promise, withdrawn) {
350
+ if (withdrawn.aborted)
351
+ return Promise.resolve(WITHDRAWN);
352
+ return new Promise((resolve, reject) => {
353
+ const onAbort = () => resolve(WITHDRAWN);
354
+ withdrawn.addEventListener('abort', onAbort, { once: true });
355
+ promise.then((value) => {
356
+ withdrawn.removeEventListener('abort', onAbort);
357
+ resolve(withdrawn.aborted ? WITHDRAWN : value);
358
+ }, (error) => {
359
+ withdrawn.removeEventListener('abort', onAbort);
360
+ reject(error instanceof Error ? error : new Error(String(error)));
361
+ });
362
+ });
363
+ }
364
+ function withTimeout(promise, ms) {
365
+ return new Promise((resolve, reject) => {
366
+ const timer = setTimeout(() => reject(new Error(`timed out after ${ms}ms`)), ms);
367
+ promise.then((value) => {
368
+ clearTimeout(timer);
369
+ resolve(value);
370
+ }, (error) => {
371
+ clearTimeout(timer);
372
+ reject(error instanceof Error ? error : new Error(String(error)));
373
+ });
374
+ });
375
+ }
376
+ /**
377
+ * Maps a tool call to a permission decision and a renderable summary.
378
+ *
379
+ * Classification is `(toolName, input)`, not name alone: `fileEditor` is a single
380
+ * tool whose `command` spans reading and writing, so the name by itself cannot
381
+ * tell them apart.
382
+ *
383
+ * Unknown tools (including everything from MCP servers) default to `execute`,
384
+ * so a new tool is gated until someone classifies it deliberately.
385
+ */
386
+ export function classify(toolName, rawInput) {
387
+ const input = asRecord(rawInput);
388
+ switch (toolName) {
389
+ case 'bash':
390
+ return classifyBash(toolName, input, rawInput);
391
+ case 'fileEditor':
392
+ return classifyFileEditor(toolName, input, rawInput);
393
+ case 'load_skill':
394
+ return {
395
+ toolName,
396
+ kind: 'read',
397
+ summary: `load_skill: ${str(input['name']) ?? '(unnamed)'}`,
398
+ details: [],
399
+ input: rawInput,
400
+ };
401
+ case 'imageViewer':
402
+ return {
403
+ toolName,
404
+ kind: 'read',
405
+ summary: `imageViewer: ${firstLine(str(input['path']) ?? '(missing path)')}`,
406
+ details: [],
407
+ input: rawInput,
408
+ };
409
+ // The context offloader's own retrieval tool: it reads back a tool result
410
+ // this session already produced and stored. Unknown tools fail closed as
411
+ // `execute`, which would make every retrieval prompt the user for something
412
+ // they already approved once.
413
+ case 'retrieve_offloaded_content':
414
+ return {
415
+ toolName,
416
+ kind: 'read',
417
+ summary: `retrieve_offloaded_content: ${str(input['reference']) ?? '(no reference)'}`,
418
+ details: [],
419
+ input: rawInput,
420
+ };
421
+ case 'subagent':
422
+ return {
423
+ toolName,
424
+ kind: 'read',
425
+ summary: `subagent: ${str(input['agent']) ?? 'general'}`,
426
+ details: [{ label: 'Task', value: str(input['task']) ?? '(missing task)' }],
427
+ input: rawInput,
428
+ };
429
+ // Like `subagent`: launching the DAG is a read — every tool call each node
430
+ // makes is gated individually through the same shared intervention, with
431
+ // dispatch `source` provenance labelling which child asked.
432
+ case 'workflow': {
433
+ const nodes = Array.isArray(input['nodes']) ? input['nodes'] : [];
434
+ const listed = nodes
435
+ .map((node) => asRecord(node))
436
+ .map((node) => `${str(node['id']) ?? '(missing id)'}(${str(node['agent']) ?? 'general'})`)
437
+ .join(', ');
438
+ return {
439
+ toolName,
440
+ kind: 'read',
441
+ summary: `workflow: ${nodes.length} node${nodes.length === 1 ? '' : 's'}`,
442
+ details: [{ label: 'Nodes', value: firstLine(listed) }],
443
+ input: rawInput,
444
+ };
445
+ }
446
+ case 'update_plan':
447
+ return {
448
+ toolName,
449
+ kind: 'read',
450
+ summary: 'update_plan: replace progress checklist',
451
+ details: [],
452
+ input: rawInput,
453
+ };
454
+ case 'memory_recall':
455
+ return {
456
+ toolName,
457
+ kind: 'read',
458
+ summary: `memory_recall: ${firstLine(str(input['query']) ?? '(missing query)')}`,
459
+ details: [],
460
+ input: rawInput,
461
+ };
462
+ case 'memory_save': {
463
+ const evidence = asRecord(input['evidence']);
464
+ return {
465
+ toolName,
466
+ kind: 'write',
467
+ summary: `memory_save: ${str(input['key']) ?? '(missing key)'} · ${str(input['category']) ?? '(missing category)'}`,
468
+ details: [
469
+ { label: 'Title', value: firstLine(str(input['title']) ?? '(missing title)') },
470
+ ...(str(evidence['path']) === undefined ? [] : [{ label: 'Evidence', value: firstLine(str(evidence['path'])) }]),
471
+ ],
472
+ input: rawInput,
473
+ };
474
+ }
475
+ // The SDK backgroundTasks plugin's own tool (SER-064). `list`/`get` read the
476
+ // plugin's in-memory task table and nothing else. `cancel` stops a running
477
+ // child, so it keeps the fail-closed `execute` kind with a summary that says so:
478
+ // a model-driven cancel prompts in `default`, is denied in `plan`, and
479
+ // `/agents cancel <id>` stays the user-only path.
480
+ case MANAGE_BACKGROUND_TASK_TOOL_NAME: {
481
+ const mode = str(input['mode']);
482
+ const taskId = str(input['taskId']) ?? '(missing task id)';
483
+ if (mode === 'list') {
484
+ return { toolName, kind: 'read', summary: 'background tasks: list', details: [], input: rawInput };
485
+ }
486
+ if (mode === 'get') {
487
+ return { toolName, kind: 'read', summary: `background task: get ${taskId}`, details: [], input: rawInput };
488
+ }
489
+ return {
490
+ toolName,
491
+ kind: 'execute',
492
+ summary: `background task: ${mode ?? '(missing mode)'} ${taskId}`,
493
+ details: [{ label: 'Task', value: taskId }],
494
+ input: rawInput,
495
+ };
496
+ }
497
+ default:
498
+ return {
499
+ toolName,
500
+ kind: 'execute',
501
+ summary: `${toolName} (unrecognized tool — approval required)`,
502
+ details: [{ label: 'Input', value: pretty(rawInput) }],
503
+ input: rawInput,
504
+ };
505
+ }
506
+ }
507
+ function classifyBash(toolName, input, rawInput) {
508
+ const mode = str(input['mode']);
509
+ // Lifecycle operations observe or reduce only manager/session-owned work. They
510
+ // run no new user-supplied command and are therefore statically safe.
511
+ if (mode === 'restart') {
512
+ return { toolName, kind: 'read', summary: 'bash: restart session', details: [], input: rawInput };
513
+ }
514
+ if (mode === 'list') {
515
+ return { toolName, kind: 'read', summary: 'bash: list background tasks', details: [], input: rawInput };
516
+ }
517
+ if (mode === 'status' || mode === 'output' || mode === 'wait' || mode === 'stop') {
518
+ return {
519
+ toolName,
520
+ kind: 'read',
521
+ summary: `bash ${mode}: ${str(input['taskId']) ?? '(missing task id)'}`,
522
+ details: [],
523
+ input: rawInput,
524
+ };
525
+ }
526
+ const command = str(input['command']) ?? '';
527
+ const timeout = input['timeout'];
528
+ const details = [{ label: 'Command', value: command }];
529
+ if (mode !== 'start' && typeof timeout === 'number') {
530
+ details.push({ label: 'Timeout', value: `${timeout}s` });
531
+ }
532
+ return { toolName, kind: 'execute', summary: `bash: ${firstLine(command)}`, details, input: rawInput };
533
+ }
534
+ function classifyFileEditor(toolName, input, rawInput) {
535
+ const command = str(input['command']) ?? '(no command)';
536
+ const filePath = str(input['path']) ?? '(no path)';
537
+ if (command === 'view') {
538
+ return {
539
+ toolName,
540
+ kind: 'read',
541
+ summary: `fileEditor view: ${filePath}`,
542
+ details: [],
543
+ input: rawInput,
544
+ };
545
+ }
546
+ const details = [
547
+ { label: 'Path', value: filePath },
548
+ { label: 'Operation', value: command },
549
+ ];
550
+ switch (command) {
551
+ case 'create':
552
+ details.push({ label: 'New content', value: str(input['file_text']) ?? '', editContent: true });
553
+ break;
554
+ case 'str_replace':
555
+ // `replace_all: true` widens what approval means — every occurrence, one
556
+ // write — so the gate states it as its own row (SER-055); the kind and the
557
+ // summary are unchanged, and the diff still shows the one pair.
558
+ if (input['replace_all'] === true)
559
+ details.push({ label: 'Replace all', value: 'every occurrence' });
560
+ details.push({ label: 'Replace', value: str(input['old_str']) ?? '', editContent: true });
561
+ // new_str is optional: omitting it deletes the matched text.
562
+ details.push({
563
+ label: 'With',
564
+ value: str(input['new_str']) ?? '(deletes the matched text)',
565
+ editContent: true,
566
+ });
567
+ break;
568
+ case 'insert':
569
+ details.push({ label: 'At line', value: String(input['insert_line'] ?? '?') });
570
+ details.push({ label: 'Insert', value: str(input['new_str']) ?? '', editContent: true });
571
+ break;
572
+ default:
573
+ details.push({ label: 'Input', value: pretty(rawInput) });
574
+ }
575
+ return {
576
+ toolName,
577
+ kind: 'write',
578
+ summary: `fileEditor ${command}: ${filePath}`,
579
+ details,
580
+ input: rawInput,
581
+ };
582
+ }
583
+ /**
584
+ * Commands whose first word makes a bash segment provably read-only. `git` is
585
+ * handled separately because only some subcommands qualify.
586
+ */
587
+ const SAFE_BASH_COMMANDS = new Set([
588
+ 'ls',
589
+ 'cat',
590
+ 'head',
591
+ 'tail',
592
+ 'grep',
593
+ 'rg',
594
+ 'find',
595
+ 'pwd',
596
+ 'which',
597
+ 'wc',
598
+ 'echo',
599
+ ]);
600
+ const SAFE_GIT_SUBCOMMANDS = new Set(['status', 'log', 'diff', 'show', 'branch']);
601
+ /**
602
+ * Options that turn a whitelisted read-only command into a mutation. A segment
603
+ * whose first word is on the list is still `dangerous` when it carries one of
604
+ * these; the reason names the option so the prompt explains itself.
605
+ */
606
+ const MUTATING_FIND_OPTIONS = new Set([
607
+ '-delete',
608
+ '-exec',
609
+ '-execdir',
610
+ '-ok',
611
+ '-okdir',
612
+ '-fprint',
613
+ '-fprint0',
614
+ '-fprintf',
615
+ '-fls',
616
+ ]);
617
+ /** `git branch` short flags that delete, rename, copy or retarget a branch. */
618
+ const MUTATING_GIT_BRANCH_SHORT_FLAGS = new Set(['d', 'D', 'm', 'M', 'c', 'C', 'u']);
619
+ /** Their long spellings; `--set-upstream-to=<ref>` is matched on the part before `=`. */
620
+ const MUTATING_GIT_BRANCH_LONG_OPTIONS = new Set([
621
+ '--set-upstream-to',
622
+ '--unset-upstream',
623
+ '--edit-description',
624
+ '--delete',
625
+ '--move',
626
+ '--copy',
627
+ ]);
628
+ /** Read-only git subcommands that still write a file when given `--output`. */
629
+ const GIT_OUTPUT_SUBCOMMANDS = new Set(['log', 'diff', 'show']);
630
+ /** Sensitive file basenames a write must never touch silently. */
631
+ const ENV_FILE = /^\.env(\..+)?$/;
632
+ /**
633
+ * The static safety rules shared by `default` and `auto`. Whitelist only: a
634
+ * call is `safe` when the rules can *prove* it harmless, `dangerous` otherwise
635
+ * — including every unknown and MCP tool.
636
+ */
637
+ export function assessRisk(request, projectRoot) {
638
+ if (request.kind === 'read') {
639
+ return { risk: 'safe', riskReason: `${request.toolName} is read-only` };
640
+ }
641
+ const input = asRecord(request.input);
642
+ if (request.toolName === 'bash') {
643
+ return assessBashRisk(str(input['command']) ?? '');
644
+ }
645
+ if (request.toolName === 'fileEditor') {
646
+ return assessWriteRisk(str(input['path']) ?? '', projectRoot);
647
+ }
648
+ if (request.toolName === 'memory_save') {
649
+ return { risk: 'dangerous', riskReason: 'writes durable Darwin project memory' };
650
+ }
651
+ return { risk: 'dangerous', riskReason: 'unrecognized tool — cannot be classified as safe' };
652
+ }
653
+ function assessBashRisk(command) {
654
+ if (hasShellMetacharacters(command)) {
655
+ return { risk: 'dangerous', riskReason: 'command uses redirection or substitution' };
656
+ }
657
+ // Only safe when every chained segment is: see splitBashSegments.
658
+ const segments = splitBashSegments(command);
659
+ if (segments.length === 0) {
660
+ return { risk: 'dangerous', riskReason: 'empty command' };
661
+ }
662
+ for (const segment of segments) {
663
+ const [word = '', subcommand = '', ...rest] = segment.split(/\s+/);
664
+ if (word === 'git') {
665
+ if (!SAFE_GIT_SUBCOMMANDS.has(subcommand)) {
666
+ return { risk: 'dangerous', riskReason: `\`git ${subcommand}\` is not a read-only git command` };
667
+ }
668
+ const option = mutatingGitOption(subcommand, rest);
669
+ if (option !== undefined) {
670
+ return { risk: 'dangerous', riskReason: `\`${option}\` makes \`git ${subcommand}\` a mutating command` };
671
+ }
672
+ }
673
+ else if (!SAFE_BASH_COMMANDS.has(word)) {
674
+ return { risk: 'dangerous', riskReason: `\`${word}\` is not on the safe-command list` };
675
+ }
676
+ else if (word === 'find') {
677
+ const option = [subcommand, ...rest].find((arg) => MUTATING_FIND_OPTIONS.has(arg));
678
+ if (option !== undefined) {
679
+ return { risk: 'dangerous', riskReason: `\`${option}\` makes \`find\` a mutating command` };
680
+ }
681
+ }
682
+ }
683
+ return { risk: 'safe', riskReason: 'read-only command' };
684
+ }
685
+ /**
686
+ * The mutating option a whitelisted git subcommand carries, or undefined when
687
+ * every argument is read-only. Every token is scanned — including anything after
688
+ * a `--` separator — because a miss costs a prompt, never silent approval.
689
+ */
690
+ function mutatingGitOption(subcommand, args) {
691
+ for (const arg of args) {
692
+ if (subcommand === 'branch') {
693
+ if (arg.startsWith('--')) {
694
+ const name = arg.split('=', 1)[0] ?? arg;
695
+ if (MUTATING_GIT_BRANCH_LONG_OPTIONS.has(name))
696
+ return name;
697
+ }
698
+ else if (arg.startsWith('-') && arg.length > 1) {
699
+ // Combined short flags: `-Df` and `-fD` both delete.
700
+ const flag = [...arg.slice(1)].find((char) => MUTATING_GIT_BRANCH_SHORT_FLAGS.has(char));
701
+ if (flag !== undefined)
702
+ return `-${flag}`;
703
+ }
704
+ }
705
+ else if (GIT_OUTPUT_SUBCOMMANDS.has(subcommand)) {
706
+ if (arg === '--output' || arg.startsWith('--output='))
707
+ return '--output';
708
+ }
709
+ }
710
+ return undefined;
711
+ }
712
+ function assessWriteRisk(filePath, projectRoot) {
713
+ const resolved = path.resolve(projectRoot, filePath);
714
+ const relative = path.relative(projectRoot, resolved);
715
+ if (isSensitiveDarwinPath(projectRoot, resolved)) {
716
+ return { risk: 'dangerous', riskReason: "path is darwin's own configuration" };
717
+ }
718
+ if (relative === '' || relative.startsWith('..') || path.isAbsolute(relative)) {
719
+ return { risk: 'dangerous', riskReason: 'path is outside the project' };
720
+ }
721
+ const segments = relative.split(path.sep);
722
+ if (segments.includes('.git')) {
723
+ return { risk: 'dangerous', riskReason: 'path touches .git internals' };
724
+ }
725
+ if (ENV_FILE.test(path.basename(resolved))) {
726
+ return { risk: 'dangerous', riskReason: 'path is an environment file' };
727
+ }
728
+ // The agent must not silently rewrite its own permission mode.
729
+ if (relative === path.join('.darwin', 'config.json')) {
730
+ return { risk: 'dangerous', riskReason: "path is darwin's own configuration" };
731
+ }
732
+ return { risk: 'safe', riskReason: 'write inside the project' };
733
+ }
734
+ /** The `fileEditor` commands a declared write scope governs; `view` is a read and never judged. */
735
+ const SCOPED_FILE_EDITOR_COMMANDS = new Set(['create', 'str_replace', 'insert']);
736
+ /** Keeps a long or multi-line model-supplied path from stretching the denial reason. */
737
+ const SCOPE_PATH_DISPLAY_LIMIT = 200;
738
+ /**
739
+ * Whether one `fileEditor` write falls outside every declared scope (SER-065).
740
+ *
741
+ * Judged by `(toolName, input)` like the rest of the gate. `scopes` are the
742
+ * normalized project-relative prefixes `workflow` validated (no leading `./`,
743
+ * no trailing `/`, no `..`, never `.`); containment is by path segment, so
744
+ * `src/tui` covers `src/tui/App.tsx` but not `src/tuix`. The request path is
745
+ * resolved against `projectRoot` (absolute or relative), and one that escapes
746
+ * the project is outside every scope by construction. Any other tool, any other
747
+ * command, an unscoped caller — `undefined`, and the ordinary flow owns the call.
748
+ */
749
+ export function writeScopeViolation(toolName, rawInput, scopes, projectRoot) {
750
+ if (toolName !== 'fileEditor')
751
+ return undefined;
752
+ const input = asRecord(rawInput);
753
+ const command = str(input['command']) ?? '';
754
+ if (!SCOPED_FILE_EDITOR_COMMANDS.has(command))
755
+ return undefined;
756
+ const filePath = str(input['path']) ?? '';
757
+ if (scopes.some((scope) => pathWithinScope(filePath, scope, projectRoot)))
758
+ return undefined;
759
+ const shown = filePath === '' ? '(no path)' : firstLine(filePath);
760
+ return {
761
+ command,
762
+ path: shown.length > SCOPE_PATH_DISPLAY_LIMIT ? `${shown.slice(0, SCOPE_PATH_DISPLAY_LIMIT)}…` : shown,
763
+ };
764
+ }
765
+ /** Segment-wise containment of a request path in one normalized scope prefix. */
766
+ function pathWithinScope(filePath, scope, projectRoot) {
767
+ if (filePath === '')
768
+ return false;
769
+ const relative = path.relative(projectRoot, path.resolve(projectRoot, filePath));
770
+ if (relative === '' || relative.startsWith('..') || path.isAbsolute(relative))
771
+ return false;
772
+ const segments = relative.split(path.sep);
773
+ const prefix = scope.split('/');
774
+ return prefix.length <= segments.length && prefix.every((segment, index) => segments[index] === segment);
775
+ }
776
+ function asRecord(value) {
777
+ if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
778
+ return value;
779
+ }
780
+ return {};
781
+ }
782
+ function str(value) {
783
+ return typeof value === 'string' ? value : undefined;
784
+ }
785
+ function firstLine(text) {
786
+ const [line = ''] = text.split('\n');
787
+ return text.includes('\n') ? `${line} …` : line;
788
+ }
789
+ function pretty(value) {
790
+ try {
791
+ return JSON.stringify(value, null, 2) ?? String(value);
792
+ }
793
+ catch {
794
+ return String(value);
795
+ }
796
+ }
797
+ //# sourceMappingURL=permission.js.map