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 @@
1
+ {"version":3,"file":"rewind-search.js","sourceRoot":"","sources":["../../../src/tui/rewind-search.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAC3C,MAAM,CAAC,MAAM,mCAAmC,GAAG,GAAG,CAAC;AACvD;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAmB1C,MAAM,UAAU,gBAAgB,CAC9B,QAAqB,EACrB,eAAuB,EACvB,WAAwC;IAExC,OAAO;QACL,QAAQ,EAAE,EAAE,GAAG,QAAQ,EAAE,MAAM,EAAE,EAAE,GAAG,QAAQ,CAAC,MAAM,EAAE,EAAE;QACzD,eAAe;QACf,WAAW,EAAE,CAAC,GAAG,WAAW,CAAC;QAC7B,KAAK,EAAE,EAAE;QACT,OAAO,EAAE,CAAC,GAAG,WAAW,CAAC;QACzB,QAAQ,EAAE,CAAC;KACZ,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,MAAoB,EAAE,QAAgB;IAC5E,MAAM,IAAI,GAAG,mCAAmC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;IAC5E,IAAI,IAAI,IAAI,CAAC,IAAI,QAAQ,KAAK,EAAE;QAAE,OAAO,MAAM,CAAC;IAChD,OAAO,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;AACjF,CAAC;AAED,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AAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IAClH,OAAO,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;AACpD,CAAC"}
@@ -0,0 +1,114 @@
1
+ /**
2
+ * The pseudo-tool name `!` runs under in the tool panel, finished rows and replay.
3
+ * Not a registered SDK tool: nothing the model can call carries this name through
4
+ * `classify()`, it exists only in presentation and in the trajectory record.
5
+ */
6
+ export declare const SHELL_TOOL_NAME = "shell";
7
+ /**
8
+ * Hard wall-clock cap on one `!` command. A hung command must not wedge the TUI:
9
+ * on expiry the process group gets SIGTERM, then SIGKILL after
10
+ * {@link SHELL_KILL_GRACE_MS}, and the result reports `timedOut`.
11
+ */
12
+ export declare const SHELL_TIMEOUT_MS = 120000;
13
+ /** Grace between the group's SIGTERM and the SIGKILL that follows it. */
14
+ export declare const SHELL_KILL_GRACE_MS = 2000;
15
+ /**
16
+ * The one bounded projection's caps. Deliberately below the trajectory writer's
17
+ * own `MAX_FIELD_CHARS` (8000), so the record's field cap never re-truncates what
18
+ * this module already bounded — the marker written is the marker read back.
19
+ */
20
+ export declare const SHELL_REPORT_CODE_POINTS = 4000;
21
+ export declare const SHELL_REPORT_LINES = 80;
22
+ /**
23
+ * Code points of output kept in memory while a command runs. Far above the
24
+ * projection caps on purpose: only the head is ever shown or recorded, so
25
+ * everything past this is *counted* (points and lines), never stored — a
26
+ * `yes`-style firehose costs arithmetic, not memory.
27
+ */
28
+ export declare const SHELL_STORE_CODE_POINTS = 32000;
29
+ /** The live panel's tail window: last lines, last code points. */
30
+ export declare const SHELL_LIVE_TAIL_LINES = 8;
31
+ export declare const SHELL_LIVE_TAIL_POINTS = 1000;
32
+ /**
33
+ * Recognizes a `!` draft. Only at the start of the (trimmed) draft — `!` anywhere
34
+ * else is ordinary text — and returns the command with the prefix stripped.
35
+ * A bare `!` returns `''`; the caller answers that with a notice, not an error.
36
+ */
37
+ export declare function parseShellCommand(draft: string): string | undefined;
38
+ /** What was collected: the stored head plus honest counts of what was not. */
39
+ export interface ShellOutputCapture {
40
+ /** Head of the merged stdout+stderr stream, capped at {@link SHELL_STORE_CODE_POINTS}. */
41
+ text: string;
42
+ /** Code points emitted beyond the stored head. */
43
+ droppedPoints: number;
44
+ /** Newlines emitted beyond the stored head. */
45
+ droppedLines: number;
46
+ }
47
+ export interface ShellCommandResult {
48
+ /** Process exit code; `null` when it died to a signal or never spawned. */
49
+ exitCode: number | null;
50
+ /** Signal that ended it, `null` for a plain exit. */
51
+ signal: string | null;
52
+ /** True when {@link SHELL_TIMEOUT_MS} (or the caller's override) expired. */
53
+ timedOut: boolean;
54
+ durationMs: number;
55
+ output: ShellOutputCapture;
56
+ /** Set when the process could not be spawned at all; `output.text` repeats it. */
57
+ spawnError?: string;
58
+ }
59
+ export interface RunningShellCommand {
60
+ done: Promise<ShellCommandResult>;
61
+ /** TERM the group now, KILL after the grace. Idempotent; `done` still settles. */
62
+ kill: () => void;
63
+ }
64
+ /**
65
+ * Runs one user command through `/bin/bash -c` in its own process group.
66
+ *
67
+ * stdout and stderr are merged in arrival order (each through its own UTF-8
68
+ * decoder, so a multi-byte character split across chunks survives). `onOutput`
69
+ * receives the {@link liveShellTail} projection, throttled to one emit per
70
+ * {@link LIVE_EMIT_INTERVAL_MS} with a final flush — never awaited, never able
71
+ * to throw into the collection path.
72
+ */
73
+ export declare function runShellCommand(command: string, options: {
74
+ cwd: string;
75
+ timeoutMs?: number;
76
+ onOutput?: (tail: string) => void;
77
+ }): RunningShellCommand;
78
+ /**
79
+ * The one bounded projection (PRD D4): head kept, loss stated with the same
80
+ * truncation marker every tool preview uses. When collection itself dropped
81
+ * output, those counts are folded into the marker so it never understates.
82
+ */
83
+ export declare function projectShellOutput(capture: ShellOutputCapture): string;
84
+ /**
85
+ * The live panel's tail: the last {@link SHELL_LIVE_TAIL_LINES} lines within
86
+ * {@link SHELL_LIVE_TAIL_POINTS} code points. A moving window, not a claim of
87
+ * completeness, so it carries no marker — the finished row and the record do.
88
+ */
89
+ export declare function liveShellTail(text: string): string;
90
+ /** Everything the finished row, the report and the record agree on. */
91
+ export interface ShellOutcome {
92
+ command: string;
93
+ exitCode: number | null;
94
+ signal: string | null;
95
+ timedOut: boolean;
96
+ durationMs: number;
97
+ }
98
+ /** `ok` only for a plain, in-time exit 0; a kill or timeout is a failure to state. */
99
+ export declare function shellOutcomeStatus(outcome: ShellOutcome): 'ok' | 'error';
100
+ /** How the outcome reads, everywhere it is stated. */
101
+ export declare function shellOutcomeSuffix(outcome: ShellOutcome): string;
102
+ /**
103
+ * The finished row's summary — also what replay prints, so it is composed from
104
+ * recorded fields only. Multi-line commands flatten to one line; the row is one
105
+ * truncate-end `<Text>` and the full command is in the user row above it.
106
+ */
107
+ export declare function shellOutcomeSummary(outcome: ShellOutcome): string;
108
+ /**
109
+ * The report held for the user's next prompt (PRD D5). Prepended to that prompt's
110
+ * text and sent through the ordinary `send()` path, so the trajectory `userInput`
111
+ * contract — "exactly what was handed to `agent.stream()`" — stays true without a
112
+ * special case. `output` is the already-bounded projection, never raw output.
113
+ */
114
+ export declare function composeShellReport(outcome: ShellOutcome, output: string): string;
@@ -0,0 +1,310 @@
1
+ /**
2
+ * The `!` prefix: a user-typed shell command run directly, without the model.
3
+ *
4
+ * Policy (SER-024, PRD `08-19-bang-shell-command`): a `!` command is
5
+ * *user-authorized* — it never enters the permission gate, whose subject is model
6
+ * tool calls; the user typing `!rm -rf build` is the user acting directly, exactly
7
+ * as they could in the terminal next door. What the gate never saw must still be
8
+ * visible and durable, so the command and its bounded output go to the transcript,
9
+ * to the trajectory record (`shellCommand`), and — held until the user's next
10
+ * prompt — into the conversation.
11
+ *
12
+ * Execution is a **bounded one-shot spawn**, deliberately not the runtime's
13
+ * persistent shell: that shell is serialized, so a hung `!` command would block
14
+ * the model's next `bash` call, and killing it would destroy shell state the model
15
+ * relies on. A one-shot owns its process group (`detached: true`), which makes
16
+ * TERM→KILL reaping self-contained — the same convention `background-bash.ts`
17
+ * uses. Stated tradeoff: `!cd` and `!export` persist nowhere.
18
+ *
19
+ * Output is collected head-first with the total counted, and projected **once**
20
+ * with the SER-009 vocabulary (`boundText`, `… truncated N code points` marker).
21
+ * That single projection is what the transcript shows, what the model will read,
22
+ * and what the record stores — three surfaces, one text.
23
+ */
24
+ import { spawn } from 'node:child_process';
25
+ import { StringDecoder } from 'node:string_decoder';
26
+ import { boundText, truncationMarker, } from './tool-detail-presentation.js';
27
+ /**
28
+ * The pseudo-tool name `!` runs under in the tool panel, finished rows and replay.
29
+ * Not a registered SDK tool: nothing the model can call carries this name through
30
+ * `classify()`, it exists only in presentation and in the trajectory record.
31
+ */
32
+ export const SHELL_TOOL_NAME = 'shell';
33
+ /**
34
+ * Hard wall-clock cap on one `!` command. A hung command must not wedge the TUI:
35
+ * on expiry the process group gets SIGTERM, then SIGKILL after
36
+ * {@link SHELL_KILL_GRACE_MS}, and the result reports `timedOut`.
37
+ */
38
+ export const SHELL_TIMEOUT_MS = 120_000;
39
+ /** Grace between the group's SIGTERM and the SIGKILL that follows it. */
40
+ export const SHELL_KILL_GRACE_MS = 2_000;
41
+ /**
42
+ * The one bounded projection's caps. Deliberately below the trajectory writer's
43
+ * own `MAX_FIELD_CHARS` (8000), so the record's field cap never re-truncates what
44
+ * this module already bounded — the marker written is the marker read back.
45
+ */
46
+ export const SHELL_REPORT_CODE_POINTS = 4_000;
47
+ export const SHELL_REPORT_LINES = 80;
48
+ /**
49
+ * Code points of output kept in memory while a command runs. Far above the
50
+ * projection caps on purpose: only the head is ever shown or recorded, so
51
+ * everything past this is *counted* (points and lines), never stored — a
52
+ * `yes`-style firehose costs arithmetic, not memory.
53
+ */
54
+ export const SHELL_STORE_CODE_POINTS = 32_000;
55
+ /** The live panel's tail window: last lines, last code points. */
56
+ export const SHELL_LIVE_TAIL_LINES = 8;
57
+ export const SHELL_LIVE_TAIL_POINTS = 1_000;
58
+ /** Minimum interval between live-output emits, so a chatty pipe cannot spam renders. */
59
+ const LIVE_EMIT_INTERVAL_MS = 100;
60
+ /**
61
+ * Recognizes a `!` draft. Only at the start of the (trimmed) draft — `!` anywhere
62
+ * else is ordinary text — and returns the command with the prefix stripped.
63
+ * A bare `!` returns `''`; the caller answers that with a notice, not an error.
64
+ */
65
+ export function parseShellCommand(draft) {
66
+ const text = draft.trim();
67
+ if (!text.startsWith('!'))
68
+ return undefined;
69
+ return text.slice(1).trim();
70
+ }
71
+ /**
72
+ * Runs one user command through `/bin/bash -c` in its own process group.
73
+ *
74
+ * stdout and stderr are merged in arrival order (each through its own UTF-8
75
+ * decoder, so a multi-byte character split across chunks survives). `onOutput`
76
+ * receives the {@link liveShellTail} projection, throttled to one emit per
77
+ * {@link LIVE_EMIT_INTERVAL_MS} with a final flush — never awaited, never able
78
+ * to throw into the collection path.
79
+ */
80
+ export function runShellCommand(command, options) {
81
+ const startedAt = Date.now();
82
+ const timeoutMs = options.timeoutMs ?? SHELL_TIMEOUT_MS;
83
+ const capture = { text: '', droppedPoints: 0, droppedLines: 0 };
84
+ let storedPoints = 0;
85
+ let timedOut = false;
86
+ let killGrace;
87
+ let emitTimer;
88
+ let emitDirty = false;
89
+ const emit = () => {
90
+ if (options.onOutput === undefined)
91
+ return;
92
+ try {
93
+ options.onOutput(liveShellTail(capture.text));
94
+ }
95
+ catch {
96
+ // A renderer problem must not become a collection problem.
97
+ }
98
+ };
99
+ const scheduleEmit = () => {
100
+ if (options.onOutput === undefined)
101
+ return;
102
+ if (emitTimer !== undefined) {
103
+ emitDirty = true;
104
+ return;
105
+ }
106
+ emit();
107
+ emitTimer = setTimeout(() => {
108
+ emitTimer = undefined;
109
+ if (emitDirty) {
110
+ emitDirty = false;
111
+ scheduleEmit();
112
+ }
113
+ }, LIVE_EMIT_INTERVAL_MS);
114
+ };
115
+ const collect = (piece) => {
116
+ if (piece === '')
117
+ return;
118
+ if (storedPoints < SHELL_STORE_CODE_POINTS) {
119
+ const points = [...piece];
120
+ const room = SHELL_STORE_CODE_POINTS - storedPoints;
121
+ if (points.length <= room) {
122
+ capture.text += piece;
123
+ storedPoints += points.length;
124
+ }
125
+ else {
126
+ const kept = points.slice(0, room).join('');
127
+ capture.text += kept;
128
+ storedPoints += room;
129
+ const rest = points.slice(room);
130
+ capture.droppedPoints += rest.length;
131
+ capture.droppedLines += rest.filter((point) => point === '\n').length;
132
+ }
133
+ }
134
+ else {
135
+ const points = [...piece];
136
+ capture.droppedPoints += points.length;
137
+ capture.droppedLines += points.filter((point) => point === '\n').length;
138
+ }
139
+ scheduleEmit();
140
+ };
141
+ let child;
142
+ const signalGroup = (signal) => {
143
+ const pid = child?.pid;
144
+ if (pid === undefined)
145
+ return;
146
+ try {
147
+ // Negative pid: the whole group, so a `!make` cannot orphan its children.
148
+ process.kill(-pid, signal);
149
+ }
150
+ catch {
151
+ // Already gone — the close handler settles the result.
152
+ }
153
+ };
154
+ const kill = () => {
155
+ if (killGrace !== undefined)
156
+ return;
157
+ signalGroup('SIGTERM');
158
+ killGrace = setTimeout(() => signalGroup('SIGKILL'), SHELL_KILL_GRACE_MS);
159
+ killGrace.unref?.();
160
+ };
161
+ const done = new Promise((resolve) => {
162
+ const settle = (result) => {
163
+ if (timeout !== undefined)
164
+ clearTimeout(timeout);
165
+ if (killGrace !== undefined)
166
+ clearTimeout(killGrace);
167
+ if (emitTimer !== undefined)
168
+ clearTimeout(emitTimer);
169
+ emitTimer = undefined;
170
+ // One last emit so the panel's final frame shows the final tail.
171
+ emit();
172
+ resolve({ ...result, durationMs: Date.now() - startedAt, output: capture });
173
+ };
174
+ let timeout;
175
+ try {
176
+ child = spawn('/bin/bash', ['-c', command], {
177
+ cwd: options.cwd,
178
+ env: process.env,
179
+ detached: true,
180
+ stdio: ['ignore', 'pipe', 'pipe'],
181
+ });
182
+ }
183
+ catch (error) {
184
+ const message = error instanceof Error ? error.message : String(error);
185
+ collect(`spawn failed: ${message}`);
186
+ settle({ exitCode: null, signal: null, timedOut: false, spawnError: message });
187
+ return;
188
+ }
189
+ timeout = setTimeout(() => {
190
+ timedOut = true;
191
+ kill();
192
+ }, timeoutMs);
193
+ timeout.unref?.();
194
+ const decodeInto = (stream) => {
195
+ if (stream === null)
196
+ return;
197
+ const decoder = new StringDecoder('utf8');
198
+ stream.on('data', (chunk) => collect(decoder.write(chunk)));
199
+ stream.on('end', () => collect(decoder.end()));
200
+ stream.on('error', () => {
201
+ // A broken pipe ends collection; the close handler still settles.
202
+ });
203
+ };
204
+ decodeInto(child.stdout);
205
+ decodeInto(child.stderr);
206
+ child.once('error', (error) => {
207
+ const message = error instanceof Error ? error.message : String(error);
208
+ collect(`spawn failed: ${message}`);
209
+ settle({ exitCode: null, signal: null, timedOut, spawnError: message });
210
+ });
211
+ child.once('close', (code, signal) => {
212
+ settle({ exitCode: code, signal, timedOut });
213
+ });
214
+ });
215
+ return { done, kill };
216
+ }
217
+ /**
218
+ * The one bounded projection (PRD D4): head kept, loss stated with the same
219
+ * truncation marker every tool preview uses. When collection itself dropped
220
+ * output, those counts are folded into the marker so it never understates.
221
+ */
222
+ export function projectShellOutput(capture) {
223
+ const bounded = boundText(capture.text, 'ok', {
224
+ codePoints: SHELL_REPORT_CODE_POINTS,
225
+ lines: SHELL_REPORT_LINES,
226
+ });
227
+ if (capture.droppedPoints === 0)
228
+ return bounded.join('\n');
229
+ // `boundText('ok')` appends its marker as the last line whenever it truncated;
230
+ // dropped output guarantees it did (the store cap is far above the projection
231
+ // caps). Recompute the marker over the true totals.
232
+ const truncated = bounded.join('\n') !== capture.text;
233
+ const kept = truncated ? bounded.slice(0, -1) : bounded;
234
+ const keptText = kept.join('\n');
235
+ const omittedPoints = Math.max(0, [...capture.text].length - [...keptText].length) + capture.droppedPoints;
236
+ const omittedLines = Math.max(0, capture.text.split('\n').length - kept.length) + capture.droppedLines;
237
+ return [...kept, truncationMarker(omittedPoints, omittedLines)].join('\n');
238
+ }
239
+ /**
240
+ * The live panel's tail: the last {@link SHELL_LIVE_TAIL_LINES} lines within
241
+ * {@link SHELL_LIVE_TAIL_POINTS} code points. A moving window, not a claim of
242
+ * completeness, so it carries no marker — the finished row and the record do.
243
+ */
244
+ export function liveShellTail(text) {
245
+ const lines = text.split('\n');
246
+ while (lines.length > 0 && lines[lines.length - 1] === '')
247
+ lines.pop();
248
+ const joined = lines.slice(-SHELL_LIVE_TAIL_LINES).join('\n');
249
+ const points = [...joined];
250
+ return points.length <= SHELL_LIVE_TAIL_POINTS
251
+ ? joined
252
+ : points.slice(-SHELL_LIVE_TAIL_POINTS).join('');
253
+ }
254
+ /** `ok` only for a plain, in-time exit 0; a kill or timeout is a failure to state. */
255
+ export function shellOutcomeStatus(outcome) {
256
+ return !outcome.timedOut && outcome.signal === null && outcome.exitCode === 0 ? 'ok' : 'error';
257
+ }
258
+ /** How the outcome reads, everywhere it is stated. */
259
+ export function shellOutcomeSuffix(outcome) {
260
+ if (outcome.timedOut)
261
+ return `(timed out after ${formatShellDuration(outcome.durationMs)})`;
262
+ if (outcome.signal !== null) {
263
+ return `(killed by ${outcome.signal} after ${formatShellDuration(outcome.durationMs)})`;
264
+ }
265
+ if (outcome.exitCode === null)
266
+ return '(did not start)';
267
+ return `(exit ${outcome.exitCode} in ${formatShellDuration(outcome.durationMs)})`;
268
+ }
269
+ /**
270
+ * The finished row's summary — also what replay prints, so it is composed from
271
+ * recorded fields only. Multi-line commands flatten to one line; the row is one
272
+ * truncate-end `<Text>` and the full command is in the user row above it.
273
+ */
274
+ export function shellOutcomeSummary(outcome) {
275
+ return `$ ${outcome.command.replace(/\s*\n\s*/g, ' ')} ${shellOutcomeSuffix(outcome)}`;
276
+ }
277
+ /**
278
+ * The report held for the user's next prompt (PRD D5). Prepended to that prompt's
279
+ * text and sent through the ordinary `send()` path, so the trajectory `userInput`
280
+ * contract — "exactly what was handed to `agent.stream()`" — stays true without a
281
+ * special case. `output` is the already-bounded projection, never raw output.
282
+ */
283
+ export function composeShellReport(outcome, output) {
284
+ return [
285
+ '<user-shell-command>',
286
+ `$ ${outcome.command}`,
287
+ shellOutcomeSuffix(outcome),
288
+ ...(output === '' ? ['(no output)'] : output.split('\n')),
289
+ '</user-shell-command>',
290
+ ].join('\n');
291
+ }
292
+ /**
293
+ * Duration for outcome suffixes. Sub-second commands — most `!` commands — keep
294
+ * their milliseconds; from one second up this matches `formatTaskDuration`'s
295
+ * whole-second reading. Recorded `durationMs` in, the same string out on live and
296
+ * replay alike.
297
+ */
298
+ function formatShellDuration(milliseconds) {
299
+ const clamped = Math.max(0, milliseconds);
300
+ if (clamped < 1000)
301
+ return `${clamped}ms`;
302
+ const seconds = Math.floor(clamped / 1000);
303
+ if (seconds < 60)
304
+ return `${seconds}s`;
305
+ const minutes = Math.floor(seconds / 60);
306
+ if (minutes < 60)
307
+ return `${minutes}m ${seconds % 60}s`;
308
+ return `${Math.floor(minutes / 60)}h ${minutes % 60}m`;
309
+ }
310
+ //# sourceMappingURL=shell-command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell-command.js","sourceRoot":"","sources":["../../../src/tui/shell-command.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EACL,SAAS,EACT,gBAAgB,GACjB,MAAM,+BAA+B,CAAC;AAEvC;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAC;AAEvC;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC;AAExC,yEAAyE;AACzE,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAEzC;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,CAAC;AAC9C,MAAM,CA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bounded
3
+ * transcript notice when cumulative cache reads keep climbing while recent model
4
+ * rounds each bought at most one tool call — the pattern where every round trip
5
+ * re-reads a huge cached prompt to do one small thing, and where batching edits,
6
+ * parallelizing independent reads, or `/compact` would genuinely help.
7
+ *
8
+ * Built on the context-pressure precedent (`context-format.ts`): a pure decision
9
+ * function held in an App ref, checked post-turn only, advising and never acting,
10
+ * silent whenever a metric is unknown, and rendered as an ordinary `<Static>`
11
+ * notice — no new live-frame row, no timer, no second channel.
12
+ *
13
+ * One deliberate difference from the context latch: cache reads are a lifetime
14
+ * accumulator, so "re-arm after a drop" cannot apply. The latch is a monotonic
15
+ * counter of the highest threshold multiple already announced — each crossed
16
+ * multiple of `cacheReadWarnTokens` may fire once, and a crossing whose pattern
17
+ * gate fails stays eligible until the pattern shows up (or the next multiple
18
+ * subsumes it). `/clear` resets it with the session, like every per-session latch.
19
+ */
20
+ /**
21
+ * How many recent completed calls the pattern gate examines — the same window
22
+ * `call-stats.ts` keeps (`RECENT_CALL_WINDOW`), restated here so this module needs
23
+ * nothing from `src/agent/**`.
24
+ */
25
+ export declare const SPEND_ADVISORY_WINDOW = 10;
26
+ /**
27
+ * How many of the windowed calls must have run ≤1 tool for the pattern to count.
28
+ * Eight of ten: an occasional parallel round does not acquit a session that is
29
+ * otherwise paying full context for single tool calls.
30
+ */
31
+ export declare const SPEND_ADVISORY_LOW_TOOL_CALLS = 8;
32
+ /** What one post-turn check reads. Every unknown input keeps the advisory silent. */
33
+ export interface SpendAdvisoryInput {
34
+ /** Cumulative parent `cacheReadInputTokens`; `undefined` until the provider reports it. */
35
+ cacheReadTokens: number | undefined;
36
+ /**
37
+ * toolUse counts of the recent completed calls (`callStats.recentToolUseCounts`);
38
+ * `undefined` when no stats exist — a session that never called the model.
39
+ */
40
+ recentToolUseCounts: readonly number[] | undefined;
41
+ /** `config.cacheReadWarnTokens`; 0 (or anything non-positive) disables. */
42
+ warnTokens: number;
43
+ }
44
+ /**
45
+ * Held in an App ref, like `ContextWarnLatch`: the counter must survive renders
46
+ * and reset only with the session.
47
+ */
48
+ export interface SpendAdvisoryLatch {
49
+ /** Returns a notice string when a new multiple is crossed with the pattern present, or null. */
50
+ check(input: SpendAdvisoryInput): string | null;
51
+ }
52
+ export declare function createSpendAdvisoryLatch(): SpendAdvisoryLatch;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * The repeated-long-context spend advisory (issue #8 follow-up A): one bounded
3
+ * transcript notice when cumulative cache reads keep climbing while recent model
4
+ * rounds each bought at most one tool call — the pattern where every round trip
5
+ * re-reads a huge cached prompt to do one small thing, and where batching edits,
6
+ * parallelizing independent reads, or `/compact` would genuinely help.
7
+ *
8
+ * Built on the context-pressure precedent (`context-format.ts`): a pure decision
9
+ * function held in an App ref, checked post-turn only, advising and never acting,
10
+ * silent whenever a metric is unknown, and rendered as an ordinary `<Static>`
11
+ * notice — no new live-frame row, no timer, no second channel.
12
+ *
13
+ * One deliberate difference from the context latch: cache reads are a lifetime
14
+ * accumulator, so "re-arm after a drop" cannot apply. The latch is a monotonic
15
+ * counter of the highest threshold multiple already announced — each crossed
16
+ * multiple of `cacheReadWarnTokens` may fire once, and a crossing whose pattern
17
+ * gate fails stays eligible until the pattern shows up (or the next multiple
18
+ * subsumes it). `/clear` resets it with the session, like every per-session latch.
19
+ */
20
+ /**
21
+ * How many recent completed calls the pattern gate examines — the same window
22
+ * `call-stats.ts` keeps (`RECENT_CALL_WINDOW`), restated here so this module needs
23
+ * nothing from `src/agent/**`.
24
+ */
25
+ export const SPEND_ADVISORY_WINDOW = 10;
26
+ /**
27
+ * How many of the windowed calls must have run ≤1 tool for the pattern to count.
28
+ * Eight of ten: an occasional parallel round does not acquit a session that is
29
+ * otherwise paying full context for single tool calls.
30
+ */
31
+ export const SPEND_ADVISORY_LOW_TOOL_CALLS = 8;
32
+ export function createSpendAdvisoryLatch() {
33
+ // Highest multiple of warnTokens already announced; monotonic on purpose —
34
+ // cacheRead never goes backwards, so neither does this.
35
+ let announced = 0;
36
+ return {
37
+ check(input) {
38
+ const warn = input.warnTokens;
39
+ if (!Number.isFinite(warn) || warn <= 0)
40
+ return null;
41
+ const read = input.cacheReadTokens;
42
+ if (typeof read !== 'number' || !Number.isFinite(read) || read < 0)
43
+ return null;
44
+ const multiple = Math.floor(read / warn);
45
+ if (multiple <= announced)
46
+ return null;
47
+ // The pattern gate. Not advancing `announced` on failure is deliberate: the
48
+ // crossing stays eligible, and fires on the first later turn whose recent
49
+ // rounds really do show the single-tool shape.
50
+ const counts = input.recentToolUseCounts;
51
+ if (counts === undefined)
52
+ return null;
53
+ const window = counts.slice(-SPEND_ADVISORY_WINDOW);
54
+ const low = window.filter((count) => typeof count === 'number' && Number.isFinite(count) && count <= 1).length;
55
+ if (low < SPEND_ADVISORY_LOW_TOOL_CALLS)
56
+ return null;
57
+ announced = multiple;
58
+ return (`cache reads passed ~${(multiple * warn).toLocaleString('en-US')} tokens and ` +
59
+ `${low} of the last ${window.length} model calls ran at most one tool — ` +
60
+ 'consider consolidating edits, batching independent reads in parallel, and /compact');
61
+ },
62
+ };
63
+ }
64
+ //# sourceMappingURL=spend-advisory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spend-advisory.js","sourceRoot":"","sources":["../../../src/tui/spend-advisory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAExC;;;;GAIG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAC;AAwB/C,MAAM,UAAU,wBAAwB;IACtC,2EAA2E;IAC3E,wDAAwD;IACxD,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,OAAO;QACL,KAAK,CAAC,KAAyB;YAC7B,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC;YAC9B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC;gBAAE,OAAO,I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