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,192 @@
1
+ // `DEFAULT_SUMMARIZATION_PROMPT` reaches the package root only through the pinned
2
+ // SDK patch (`patches/@strands-agents__sdk@1.16.0.patch`, `dist/src/index.*`
3
+ // hunks): the SDK declares it in a module its `exports` map does not expose.
4
+ // Never copy the string here — a copy would drift from what the SDK sends when
5
+ // no focus is given.
6
+ import { DEFAULT_SUMMARIZATION_PROMPT, SummarizingConversationManager } from '@strands-agents/sdk';
7
+ /**
8
+ * `/compact` collapses every reducible old message in one command, leaving one
9
+ * summary plus the recent window. 0.8 is the SDK's maximum ratio and minimizes
10
+ * model calls; overflow recovery uses the configurable `summaryRatio` instead.
11
+ */
12
+ export const COMPACT_SUMMARY_RATIO = 0.8;
13
+ /** Upper bound on one `/compact <focus>` argument, in code points, after trimming. */
14
+ export const MAX_COMPACT_FOCUS_CODE_POINTS = 400;
15
+ /**
16
+ * The one fixed section appended after the SDK prompt when a focus is given. The
17
+ * focus is plain text under this heading — never parsed, never a command.
18
+ */
19
+ export const COMPACT_FOCUS_HEADING = "User's focus for this summary (keep what it names in detail):";
20
+ /**
21
+ * Trims a `/compact` argument; blank text means "no focus". Returns the trimmed
22
+ * text unbounded — {@link compactFocusRefusal} decides whether it may be used.
23
+ */
24
+ export function normalizeCompactFocus(text) {
25
+ const trimmed = text?.trim() ?? '';
26
+ return trimmed.length === 0 ? undefined : trimmed;
27
+ }
28
+ /** The notice for a focus over the cap, or undefined when the focus is acceptable. */
29
+ export function compactFocusRefusal(focus) {
30
+ if (focus === undefined)
31
+ return undefined;
32
+ const length = [...focus].length;
33
+ if (length <= MAX_COMPACT_FOCUS_CODE_POINTS)
34
+ return undefined;
35
+ return `/compact focus is too long (${length} code points; cap ${MAX_COMPACT_FOCUS_CODE_POINTS}) — compaction did not run`;
36
+ }
37
+ /**
38
+ * The summarizer system prompt: the SDK default verbatim, then — only with a
39
+ * focus — one blank line and the fixed focus section. Unfocused callers must not
40
+ * call this; they leave the manager's `summarizationSystemPrompt` unset so the
41
+ * SDK applies its own default and the request is identical to a plain `/compact`.
42
+ */
43
+ export function focusedSummarizationPrompt(focus) {
44
+ return `${DEFAULT_SUMMARIZATION_PROMPT}\n\n${COMPACT_FOCUS_HEADING}\n${focus}`;
45
+ }
46
+ /**
47
+ * Constructor config for one `/compact` manager. Without a focus the object has
48
+ * exactly the two keys the process-lifetime manager used to be built with, so the
49
+ * unfocused request cannot differ from before per-call construction existed.
50
+ *
51
+ * @throws When the focus is over the cap — refused before any manager, hook or
52
+ * model call exists.
53
+ */
54
+ export function compactionManagerConfig(preserveRecentMessages, focus) {
55
+ const refusal = compactFocusRefusal(focus);
56
+ if (refusal !== undefined)
57
+ throw new Error(refusal);
58
+ return {
59
+ summaryRatio: COMPACT_SUMMARY_RATIO,
60
+ preserveRecentMessages,
61
+ ...(focus !== undefined && { summarizationSystemPrompt: focusedSummarizationPrompt(focus) }),
62
+ };
63
+ }
64
+ /** One manager per `/compact` call: the focus is constructor-only in the SDK. */
65
+ export function createCompactionManager(preserveRecentMessages, focus) {
66
+ return new SummarizingConversationManager(compactionManagerConfig(preserveRecentMessages, focus));
67
+ }
68
+ /**
69
+ * The failure surfaced when the SDK's proactive `reduce()` swallows a summarization
70
+ * error and returns `false`. The SDK's own `proactive summarization failed` warning,
71
+ * routed through `routeSdkLogs`, carries the underlying cause right before this.
72
+ */
73
+ export const SWALLOWED_SUMMARIZATION_FAILURE = 'the summarizer made no reduction; the preceding sdk warning names the cause';
74
+ /**
75
+ * Summarizes every reducible old message, persists the result, and restores the
76
+ * original messages if summarization, counting, or persistence fails.
77
+ *
78
+ * Termination and honesty rules (SER-052):
79
+ * - a pass that returns `true` without lowering the message count is undone and
80
+ * ends the loop, so `compacted` / `messagesAfter` describe what really changed
81
+ * and the loop makes at most one summarizer call beyond the shrinking ones;
82
+ * - a pass that returns `false` is a summarization failure the SDK swallowed
83
+ * (proactive `reduce()` has no other `false` inside this loop) — it rejects and
84
+ * rolls back everything, never reports `compacted: true`.
85
+ * Both rules apply to focused and unfocused managers alike.
86
+ */
87
+ export async function compactConversation({ agent, model, manager, preserveRecentMessages, persist, }) {
88
+ const messagesBefore = agent.messages.length;
89
+ if (messagesBefore <= preserveRecentMessages + 1) {
90
+ return {
91
+ messagesBefore,
92
+ messagesAfter: messagesBefore,
93
+ estimatedTokensBefore: 0,
94
+ estimatedTokensAfter: 0,
95
+ estimatedTokensSaved: 0,
96
+ compacted: false,
97
+ };
98
+ }
99
+ const original = agent.messages.map((message) => message.clone());
100
+ const estimatedTokensBefore = await countConversationTokens(model, agent);
101
+ try {
102
+ let compacted = false;
103
+ while (agent.messages.length > preserveRecentMessages + 1) {
104
+ // A shallow snapshot is enough to undo one pass: the SDK splices the list
105
+ // and never mutates the messages themselves, so putting the same objects
106
+ // back leaves identity intact.
107
+ const beforePass = agent.messages.slice();
108
+ const reduced = await manager.reduce({ agent, model });
109
+ if (!reduced) {
110
+ // Inside this loop the SDK has no honest `false`: "insufficient messages"
111
+ // needs `length <= preserveRecentMessages` (excluded by the condition) and
112
+ // "all protected" needs `pinFirst` (never set here). Without an `error`
113
+ // argument the SDK swallows a summarization failure, logs it, and returns
114
+ // `false` — so this is that failure, and a rollback, never a no-op.
115
+ throw new Error(SWALLOWED_SUMMARIZATION_FAILURE);
116
+ }
117
+ if (agent.messages.length >= beforePass.length) {
118
+ // The SDK summarizes at most 80% of the list, so a 2-message history
119
+ // becomes "a summary of the oldest message plus the newest" — the same
120
+ // count, less fidelity, forever. Undo that pass and stop; `compacted`
121
+ // stays whatever the earlier, shrinking passes made it.
122
+ agent.messages.splice(0, agent.messages.length, ...beforePass);
123
+ break;
124
+ }
125
+ compacted = true;
126
+ }
127
+ const messagesAfter = agent.messages.length;
128
+ if (!compacted) {
129
+ return {
130
+ messagesBefore,
131
+ messagesAfter,
132
+ estimatedTokensBefore,
133
+ estimatedTokensAfter: estimatedTokensBefore,
134
+ estimatedTokensSaved: 0,
135
+ compacted: false,
136
+ };
137
+ }
138
+ const estimatedTokensAfter = await countConversationTokens(model, agent);
139
+ await persist();
140
+ return {
141
+ messagesBefore,
142
+ messagesAfter,
143
+ estimatedTokensBefore,
144
+ estimatedTokensAfter,
145
+ estimatedTokensSaved: Math.max(0, estimatedTokensBefore - estimatedTokensAfter),
146
+ compacted: true,
147
+ };
148
+ }
149
+ catch (error) {
150
+ agent.messages.splice(0, agent.messages.length, ...original);
151
+ throw error;
152
+ }
153
+ }
154
+ /**
155
+ * Repairs user-role messages that carry `reasoningBlock` content in place.
156
+ *
157
+ * The SDK's summarizer used to copy a thinking model's whole response —
158
+ * reasoning blocks included — into a user-role summary message; providers
159
+ * reject any later request containing it (`User messages cannot contain
160
+ * reasoning content`). A user message can never legally carry reasoning
161
+ * content on any provider, so dropping those blocks is always safe. Message
162
+ * object identity, order, and every non-reasoning block are preserved; the
163
+ * mutation is in-memory only, so the next ordinary save persists it.
164
+ *
165
+ * A message that would be left with zero blocks is left untouched and not
166
+ * counted: a poisoned summary always also carries its text block, so an
167
+ * all-reasoning user message is not the known poisoning — and an empty
168
+ * content array would itself be invalid, trading one rejection for another.
169
+ *
170
+ * @returns The number of messages repaired.
171
+ */
172
+ export function stripReasoningFromUserMessages(messages) {
173
+ let repaired = 0;
174
+ for (const message of messages) {
175
+ if (message.role !== 'user')
176
+ continue;
177
+ const kept = message.content.filter((block) => block.type !== 'reasoningBlock');
178
+ if (kept.length === message.content.length || kept.length === 0)
179
+ continue;
180
+ message.content.splice(0, message.content.length, ...kept);
181
+ repaired++;
182
+ }
183
+ return repaired;
184
+ }
185
+ /** Counts the complete assembled context the next model request will receive. */
186
+ export function countConversationTokens(model, agent) {
187
+ return model.countTokens(agent.messages, {
188
+ ...(agent.systemPrompt !== undefined && { systemPrompt: agent.systemPrompt }),
189
+ toolSpecs: agent.tools.map((tool) => tool.toolSpec),
190
+ });
191
+ }
192
+ //# sourceMappingURL=compact.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compact.js","sourceRoot":"","sources":["../../../src/agent/compact.ts"],"names":[],"mappings":"AAQA,kFAAkF;AAClF,6EAA6E;AAC7E,6EAA6E;AAC7E,+EAA+E;AAC/E,qBAAqB;AACrB,OAAO,EAAE,4BAA4B,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AAEnG;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,CAAC;AACzC,sFAAsF;AACtF,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAG,CAAC;AACjD;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,+DAA+D,CAAC;AAErG;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAwB;IAC5D,MAAM,OAAO,GAAG,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACnC,OAAO,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;AACpD,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,mBAAmB,CAAC,KAAyB;IAC3D,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,MAAM,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC;IACjC,IAAI,MAAM,IAAI,6BAA6B;QAAE,OAAO,SAAS,CAAC;IAC9D,OAAO,+BAA+B,MAAM,qBAAqB,6BAA6B,4BAA4B,CAAC;AAC7H,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CAAC,KAAa;IACtD,OAAO,GAAG,4BAA4B,OAAO,qBAAqB,KAAK,KAAK,EAAE,CAAC;AACjF,CAAC;AAED;;;;;;;GAO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CAAC,YAAY,EAAE,CAAC;QAC7E,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC;KACpD,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * The `/context` measurement anchor.
3
+ *
4
+ * darwin's context size has always been a character heuristic in practice: it asks
5
+ * `Model.countTokens`, and Bedrock's `CountTokens` refuses the inference-profile ids
6
+ * darwin requires, so the SDK caches the model as skipped and falls back to
7
+ * `chars/4` text plus `chars/2` tool-spec JSON. But the provider already reports what
8
+ * each request really cost, and `AgentRuntime` already observes those counters for
9
+ * `/usage`. This module is the pure state that carries one such measurement into the
10
+ * estimate: the prompt-token total of the most recent completed model call, plus
11
+ * where the conversation stood when it happened.
12
+ *
13
+ * With an anchor, `/context` is `measured base + heuristic tail`: the system prompt and
14
+ * every `toolSpec` — the biggest and most heuristic-hostile part of a request — become
15
+ * a measured number, and only the messages appended since that call are estimated. The
16
+ * residual error is therefore bounded by one call's worth of tail rather than
17
+ * accumulating over a session. Deliberately *not* a fitted `measured / heuristic`
18
+ * correction factor: that trades one unknown for another (tokenizer-, provider- and
19
+ * content-dependent), needs unjustifiable smoothing and clamps, and would silently
20
+ * scale everything downstream, including the context-pressure latch.
21
+ *
22
+ * Pure and non-throwing by construction, on `call-stats.ts`'s terms: allocation only,
23
+ * no SDK import, structural reads. The runtime observes model-call events between
24
+ * `stream()` and `yield`, so a malformed payload must cost the anchor, never the turn.
25
+ */
26
+ import type { AppConfig } from '../config.js';
27
+ import { type CompletedModelCall } from './call-stats.js';
28
+ /** One measured request, and the conversation position it measured. */
29
+ export interface ContextAnchor {
30
+ /**
31
+ * The provider's prompt-token total for that call ({@link requestInputTokens}):
32
+ * uncached input plus cache reads and writes, because a cached prefix still
33
+ * occupies the context window.
34
+ */
35
+ requestTokens: number;
36
+ /** `agent.messages.length` as observed when the call completed. */
37
+ messageCount: number;
38
+ /**
39
+ * The message object at `messageCount - 1`, by reference. Identity is the cheap
40
+ * way to notice that the history under the anchor was rewritten (compaction) rather
41
+ * than merely appended to — a length check alone cannot see a same-length rewrite.
42
+ */
43
+ boundary: unknown;
44
+ }
45
+ /**
46
+ * The anchor a completed model call installs, or `undefined` when the call is not a
47
+ * usable measurement — no `stopData`, counters the provider did not report, a split
48
+ * that cannot be made honestly, or an empty history.
49
+ *
50
+ * A call that measures nothing must not invalidate anything: the caller keeps the
51
+ * previous anchor, which is still the best measurement available.
52
+ */
53
+ export declare function anchorFromCall(call: CompletedModelCall, messages: readonly unknown[], config: AppConfig): ContextAnchor | undefined;
54
+ /**
55
+ * The anchor if it still describes this history, `undefined` otherwise.
56
+ *
57
+ * Valid means the conversation has only grown since the measurement: at least as many
58
+ * messages, and the same object still sitting on the boundary. `/compact` shortens and
59
+ * rewrites the array, `/rewind` and `/clear` build a successor runtime, and a model
60
+ * switch retires the measurement explicitly — so every way the base can stop being
61
+ * true ends here, in absence. A dropped anchor is never repaired, only replaced by the
62
+ * next completed call.
63
+ */
64
+ export declare function resolveAnchor(anchor: ContextAnchor | undefined, messages: readonly unknown[]): ContextAnchor | undefined;
@@ -0,0 +1,43 @@
1
+ import { readCallUsage } from './call-stats.js';
2
+ import { requestInputTokens } from './usage.js';
3
+ /**
4
+ * The anchor a completed model call installs, or `undefined` when the call is not a
5
+ * usable measurement — no `stopData`, counters the provider did not report, a split
6
+ * that cannot be made honestly, or an empty history.
7
+ *
8
+ * A call that measures nothing must not invalidate anything: the caller keeps the
9
+ * previous anchor, which is still the best measurement available.
10
+ */
11
+ export function anchorFromCall(call, messages, config) {
12
+ const usage = readCallUsage(call.message?.metadata?.usage);
13
+ if (usage === undefined)
14
+ return undefined;
15
+ const requestTokens = requestInputTokens(usage, config);
16
+ if (requestTokens === undefined || !Number.isFinite(requestTokens) || requestTokens < 0) {
17
+ return undefined;
18
+ }
19
+ const messageCount = messages.length;
20
+ if (messageCount < 1)
21
+ return undefined;
22
+ return { requestTokens, messageCount, boundary: messages[messageCount - 1] };
23
+ }
24
+ /**
25
+ * The anchor if it still describes this history, `undefined` otherwise.
26
+ *
27
+ * Valid means the conversation has only grown since the measurement: at least as many
28
+ * messages, and the same object still sitting on the boundary. `/compact` shortens and
29
+ * rewrites the array, `/rewind` and `/clear` build a successor runtime, and a model
30
+ * switch retires the measurement explicitly — so every way the base can stop being
31
+ * true ends here, in absence. A dropped anchor is never repaired, only replaced by the
32
+ * next completed call.
33
+ */
34
+ export function resolveAnchor(anchor, messages) {
35
+ if (anchor === undefined)
36
+ return undefined;
37
+ if (messages.length < anchor.messageCount)
38
+ return undefined;
39
+ if (messages[anchor.messageCount - 1] !== anchor.boundary)
40
+ return undefined;
41
+ return anchor;
42
+ }
43
+ //# sourceMappingURL=context-anchor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-anchor.js","sourceRoot":"","sources":["../../../src/agent/context-anchor.ts"],"names":[],"mappings":"AA0BA,OAAO,EAAE,aAAa,EAA2B,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAoBhD;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAC5B,IAAwB,EACxB,QAA4B,EAC5B,MAAiB;IAEjB,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC3D,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,MAAM,aAAa,GAAG,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACxD,IAAI,aAAa,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,aAAa,GAAG,CAAC,EAAE,CAAC;QACxF,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC;IACrC,IAAI,YAAY,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC;IACvC,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,CAAC,YAAY,GAAG,CAAC,CAAC,EAAE,CAAC;AAC/E,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAC3B,MAAiC,EACjC,QAA4B;IAE5B,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC3C,IAAI,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC,YAAY;QAAE,OAAO,SAAS,CAAC;IAC5D,IAAI,QAAQ,CAAC,MAAM,CAAC,YAAY,GAAG,CAAC,CAAC,KAAK,MAAM,CAAC,QAAQ;QAAE,OAAO,SAAS,CAAC;IAC5E,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Cost accounting on the live surfaces — `/status`, `/usage` and the headless
3
+ * `cost:` record — as the config-aware face of the pure arithmetic in
4
+ * `src/pricing/cost.ts`.
5
+ *
6
+ * Everything that computes or renders money is re-exported from there unchanged, so
7
+ * this module adds exactly one thing: the projection from the runtime's vocabulary
8
+ * (`UsageTotals` + `AppConfig`, via `usageBuckets`) into the `CostShare` the pure
9
+ * module prices. The trajectory readers make the same projection from a record
10
+ * (`src/trajectory/spend.ts`) without ever importing this file — one arithmetic, two
11
+ * entry points, no second implementation.
12
+ *
13
+ * A session is priced **per model**: the runtime tallies each model's share of the
14
+ * meter under the config in effect for its turns ({@link ModelUsageShare}), and the
15
+ * sum prices each share at its own rates. A single-model session renders exactly as
16
+ * the one-lookup wrappers ({@link describeCost}, {@link costFields}) always did.
17
+ */
18
+ import type { AppConfig } from '../config.js';
19
+ import { type CostBucket, type CostShare, type ModelPriceLookup } from '../pricing/cost.js';
20
+ import { type UsageTotals } from './usage.js';
21
+ export { COST_BASIS_LABEL, describePricingSource, describeSessionCost, estimateCost, formatModelList, formatUsd, formatUsdNumber, MAX_COST_MODEL_CHARS, sessionCost, sessionCostFields, type CostBucket, type CostBuckets, type CostEstimate, type CostShare, type MissingCostBucket, type MissingModelBucket, type ModelPriceLookup, type ModelRates, type SessionCost, type UnpricedModel, } from '../pricing/cost.js';
22
+ /**
23
+ * One model's share of this process's meter: the counters it incurred, the config
24
+ * that projects them into buckets (provider/API decide the split), and what the
25
+ * price cache says about it. `runtime.modelShares` is a list of these.
26
+ */
27
+ export interface ModelUsageShare {
28
+ config: AppConfig;
29
+ usage: UsageTotals;
30
+ lookup: ModelPriceLookup;
31
+ }
32
+ /** The pure module's unit, from the runtime's vocabulary. */
33
+ export declare function costShare(share: ModelUsageShare): CostShare;
34
+ /**
35
+ * The one-line cost statement `/status` and `/usage` print for a list of model
36
+ * shares — `describeSessionCost` over each share priced at its own rates. See that
37
+ * function for the exact wording; one share renders as {@link describeCost} does.
38
+ */
39
+ export declare function describeModelCosts(shares: readonly ModelUsageShare[]): string;
40
+ /** The headless `cost:` fields for a list of model shares (`-` is unknown, never 0). */
41
+ export declare function modelCostFields(shares: readonly ModelUsageShare[]): Record<CostBucket | 'total', string>;
42
+ /**
43
+ * The one-lookup form: one model, one meter — `/status`'s child lines (children run
44
+ * the live model's config) and every caller that has a single model to price.
45
+ */
46
+ export declare function describeCost(lookup: ModelPriceLookup, usage: UsageTotals, config: AppConfig): string;
47
+ /** The one-lookup form of {@link modelCostFields}. */
48
+ export declare function costFields(lookup: ModelPriceLookup, usage: UsageTotals, config: AppConfig): Record<CostBucket | 'total', string>;
49
+ /**
50
+ * Folds child spend into the live model's share — children run the parent's live
51
+ * model config, so their tokens are priced at its rates — appending a share when no
52
+ * parent turn ran on that model yet. Pure: returns a new list. A single-model
53
+ * session yields one share over `sumUsage([parent, children])`, the session-total
54
+ * projection `/status` always printed.
55
+ */
56
+ export declare function withChildUsage(shares: readonly ModelUsageShare[], children: UsageTotals, live: AppConfig, lookup: ModelPriceLookup): ModelUsageShare[];
@@ -0,0 +1,44 @@
1
+ import { describeSessionCost, sessionCost, sessionCostFields, } from '../pricing/cost.js';
2
+ import { sumUsage, usageBuckets } from './usage.js';
3
+ export { COST_BASIS_LABEL, describePricingSource, describeSessionCost, estimateCost, formatModelList, formatUsd, formatUsdNumber, MAX_COST_MODEL_CHARS, sessionCost, sessionCostFields, } from '../pricing/cost.js';
4
+ /** The pure module's unit, from the runtime's vocabulary. */
5
+ export function costShare(share) {
6
+ return { model: share.config.model, lookup: share.lookup, buckets: usageBuckets(share.usage, share.config) };
7
+ }
8
+ /**
9
+ * The one-line cost statement `/status` and `/usage` print for a list of model
10
+ * shares — `describeSessionCost` over each share priced at its own rates. See that
11
+ * function for the exact wording; one share renders as {@link describeCost} does.
12
+ */
13
+ export function describeModelCosts(shares) {
14
+ return describeSessionCost(sessionCost(shares.map(costShare)));
15
+ }
16
+ /** The headless `cost:` fields for a list of model shares (`-` is unknown, never 0). */
17
+ export function modelCostFields(shares) {
18
+ return sessionCostFields(sessionCost(shares.map(costShare)));
19
+ }
20
+ /**
21
+ * The one-lookup form: one model, one meter — `/status`'s child lines (children run
22
+ * the live model's config) and every caller that has a single model to price.
23
+ */
24
+ export function describeCost(lookup, usage, config) {
25
+ return describeModelCosts([{ config, usage, lookup }]);
26
+ }
27
+ /** The one-lookup form of {@link modelCostFields}. */
28
+ export function costFields(lookup, usage, config) {
29
+ return modelCostFields([{ config, usage, lookup }]);
30
+ }
31
+ /**
32
+ * Folds child spend into the live model's share — children run the parent's live
33
+ * model config, so their tokens are priced at its rates — appending a share when no
34
+ * parent turn ran on that model yet. Pure: returns a new list. A single-model
35
+ * session yields one share over `sumUsage([parent, children])`, the session-total
36
+ * projection `/status` always printed.
37
+ */
38
+ export function withChildUsage(shares, children, live, lookup) {
39
+ const index = shares.findIndex((share) => share.config.model === live.model && share.config.provider === live.provider);
40
+ if (index === -1)
41
+ return [...shares, { config: live, usage: children, lookup }];
42
+ return shares.map((share, at) => (at === index ? { ...share, usage: sumUsage([share.usage, children]) } : share));
43
+ }
44
+ //# sourceMappingURL=cost.js.map
@@ -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,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;AACtD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAkC,EAClC,QAAqB,EACrB,IAAe,EACf,MAAwB;IAExB,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,QAAQ,KAAK,IAAI,CAAC,QAAQ,CAAC,CAAC;IACxH,IAAI,KAAK,KAAK,CAAC,CAAC;QAAE,OAAO,CAAC,GAAG,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IAChF,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AACpH,CAAC"}
@@ -0,0 +1,212 @@
1
+ /**
2
+ * The opt-in per-session diagnostics log.
3
+ *
4
+ * Two channels darwin otherwise throws away meet in one file: the SDK's `debug`
5
+ * and `info` output — which is the *only* place the SDK says it was throttled
6
+ * (`models/bedrock.js`: `logger.debug('throttled | error_message=…')`), where it
7
+ * put its cache points, or that native token counting fell back to estimation —
8
+ * and darwin's own notices, which live in Ink's scrollback and die with the frame.
9
+ * `warn`/`error` are written here too even though they already reach the renderer,
10
+ * so one file holds the whole story rather than half of it.
11
+ *
12
+ * Off unless asked for: unlike default-on context offload, these lines
13
+ * interpolate provider payloads and can therefore carry conversation-derived
14
+ * material. With the feature off nothing here runs at all — `sdk-logging.ts`
15
+ * installs literal no-ops and `AgentRuntime` builds no log — so a default run is
16
+ * byte-for-byte the run it was before this module existed.
17
+ *
18
+ * It is an observer, under the same discipline the trajectory earned
19
+ * (`src/trajectory/`), and one bound stricter:
20
+ *
21
+ * 1. **It cannot affect a turn.** {@link DiagnosticsLog.write} is synchronous,
22
+ * catches everything, performs no I/O and never touches the console — the SDK's
23
+ * default `console.warn` tearing the Ink frame is why `sdk-logging.ts` exists at
24
+ * all. Appends run on a promise chain no caller awaits.
25
+ * 2. **It is bounded twice.** Per line and per file, like the record — and also per
26
+ * *pending* byte, which the record did not need: `logger.debug` is called
27
+ * synchronously from inside the SDK's own stream loop, so a long turn can offer
28
+ * lines faster than a disk accepts them. Diagnostic lines are then dropped and
29
+ * counted; a stream event never is.
30
+ * 3. **Every stop is written down.** Reaching a bound, dropping lines and failing to
31
+ * write all leave a line in the file (or a surfaced problem when the file is what
32
+ * failed). A log that went quiet without saying so would be worse than none.
33
+ *
34
+ * See `docs/architecture/load-bearing-decisions.md` § Session diagnostics.
35
+ */
36
+ import { open } from 'node:fs/promises';
37
+ /**
38
+ * Per line, in **code points** — the `headlessField` convention, so a multi-byte
39
+ * message cannot be cut mid-sequence. Matches the trajectory's field cap: a
40
+ * provider that echoes a whole rejected request back is the reason both exist.
41
+ */
42
+ export declare const MAX_DIAGNOSTIC_LINE_CHARS = 8000;
43
+ /**
44
+ * Per session file, in bytes.
45
+ *
46
+ * Deliberately an eighth of the trajectory's 64 MiB, and the difference is the
47
+ * point: a trajectory is the artifact you *keep*, so its bound has to leave a long
48
+ * session's history intact. This is scratch for one debugging session, nothing ever
49
+ * garbage-collects it (see `contextOffload` in `src/config.ts`), and 8 MiB is on the
50
+ * order of 80,000 lines — far past the point where a human tailing a file is still
51
+ * reading it. Whoever needs more than this needs a different tool, not a bigger file.
52
+ */
53
+ export declare const MAX_DIAGNOSTICS_BYTES: number;
54
+ /**
55
+ * Formatted-but-unwritten bytes held in memory, before arriving lines are dropped.
56
+ *
57
+ * The bound the trajectory does not have. It buffers one turn and flushes at the
58
+ * end, so its memory is bounded by a turn; this one accepts lines from inside the
59
+ * SDK's stream loop and flushes continuously, so a `debug` firehose against a slow
60
+ * disk is a real unbounded-growth path. Dropping is the correct failure here:
61
+ * blocking would delay the event the SDK was in the middle of, which the observer
62
+ * contract forbids outright.
63
+ */
64
+ export declare const MAX_DIAGNOSTICS_PENDING_BYTES: number;
65
+ /** Who produced the line. `sdk` is the SDK's own logger; `darwin` is this codebase. */
66
+ export type DiagnosticSource = 'sdk' | 'darwin';
67
+ /**
68
+ * How loud the line is. The SDK's four logger levels, which are a superset of the
69
+ * TUI's `NoticeSeverity` — so a notice's severity travels here unchanged.
70
+ */
71
+ export type DiagnosticLevel = 'debug' | 'info' | 'warn' | 'error';
72
+ export interface DiagnosticEntry {
73
+ source: DiagnosticSource;
74
+ level: DiagnosticLevel;
75
+ message: string;
76
+ }
77
+ /** What the TUI notice and the headless record report about this log. */
78
+ export interface DiagnosticsStatus {
79
+ file: string;
80
+ /** Lines appended by this process. */
81
+ linesThisRun: number;
82
+ /** Bytes appended by this process. */
83
+ bytesThisRun: number;
84
+ /** Lines dropped because the writer could not keep up. */
85
+ droppedLines: number;
86
+ /** Set once, on the first failure or when the budget stops logging. */
87
+ problem: string | undefined;
88
+ /** False once a problem or the budget has stopped it. */
89
+ active: boolean;
90
+ }
91
+ export interface DiagnosticsOptions {
92
+ file: string;
93
+ /** Written into the self-describing first line. */
94
+ run: DiagnosticsRunInfo;
95
+ /** Injected for tests that need a failing filesystem; production uses `fs.open`. */
96
+ openFile?: typeof open;
97
+ /**
98
+ * Per-file byte budget; defaults to {@link MAX_DIAGNOSTICS_BYTES}.
99
+ *
100
+ * Injectable for the same reason the recorder's is: the budget path latches logging
101
+ * off for the rest of a session, and a behaviour that only appears after 8 MiB of
102
+ * real writes is a behaviour nothing tests.
103
+ */
104
+ maxBytes?: number;
105
+ /** Pending-byte budget; defaults to {@link MAX_DIAGNOSTICS_PENDING_BYTES}. */
106
+ maxPendingBytes?: number;
107
+ }
108
+ /** The facts the first line states, so the file explains itself without a reader. */
109
+ export interface DiagnosticsRunInfo {
110
+ session: string;
111
+ darwinVersion: string;
112
+ provider: string;
113
+ model: string;
114
+ }
115
+ /**
116
+ * One line: `<ISO timestamp> <source> <level> — <message>`.
117
+ *
118
+ * Text rather than JSONL, unlike the trajectory, because the reader is a person with
119
+ * `tail -f` rather than a replay engine — and because these lines are already text
120
+ * the SDK formatted, so wrapping each one in an object would add punctuation and no
121
+ * structure. The parts stay unambiguous anyway: three fixed leading fields, then
122
+ * ` — ` (the `sdk warn — …` delimiter headless already uses) and the message.
123
+ *
124
+ * The message is collapsed to a single line, so one event is always exactly one line
125
+ * — a multi-line notice (`/usage`'s table, say) must not be able to break a reader
126
+ * that counts lines, and a `tail -f` that shows half an event is worse than one that
127
+ * shows a long one.
128
+ */
129
+ export declare function formatDiagnosticLine(at: string, entry: DiagnosticEntry): string;
130
+ export declare class DiagnosticsLog {
131
+ private readonly file;
132
+ private readonly openFile;
133
+ private readonly maxBytes;
134
+ private readonly maxPendingBytes;
135
+ /** Formatted-but-unwritten lines, in observation order. */
136
+ private pending;
137
+ private pendingBytes;
138
+ /** True while an append is in flight; see {@link flush}. */
139
+ private writing;
140
+ /** The serialized append chain: every write waits for the previous one. */
141
+ private chain;
142
+ private active;
143
+ private problem;
144
+ private linesThisRun;
145
+ private bytesThisRun;
146
+ private fileBytes;
147
+ private opened;
148
+ /** Dropped since the last line that reported drops, and in total. */
149
+ private droppedSinceReport;
150
+ private droppedLines;
151
+ constructor(options: DiagnosticsOptions);
152
+ /** Where the lines go. Reported so a caller can tell the user without guessing. */
153
+ get path(): string;
154
+ get status(): DiagnosticsStatus;
155
+ /**
156
+ * Records one line. Synchronous, no I/O, and it swallows its own failures.
157
+ *
158
+ * This is the whole observer contract in one method: it is called from inside the
159
+ * SDK's stream loop and from the TUI's dispatch path, so it may not await, may not
160
+ * throw, and may not write to the console. Everything it does is format a string,
161
+ * push it, and register a continuation on the append chain.
162
+ */
163
+ write(entry: DiagnosticEntry): void;
164
+ /**
165
+ * A sink for `routeSdkLogs`' verbose tap, bound once.
166
+ *
167
+ * Bound here rather than built at each call site so the two entry points cannot
168
+ * disagree about the `source` label, and so a caller never has to re-create a
169
+ * closure to satisfy narrowing on an optional log.
170
+ */
171
+ readonly sdkSink: (entry: {
172
+ level: DiagnosticLevel;
173
+ message: string;
174
+ }) => void;
175
+ /** A darwin-side line: what the TUI showed the user, with the severity it showed. */
176
+ readonly notice: (text: string, level?: DiagnosticLevel) => void;
177
+ /**
178
+ * Appends everything buffered so far — but only when the previous append has
179
+ * finished.
180
+ *
181
+ * The wait is the whole point, and it is where this differs from the trajectory's
182
+ * writer: that one flushes once per turn, so it can hand every batch straight to the
183
+ * chain. Lines here arrive continuously from inside the SDK's stream loop, and
184
+ * draining on every arrival would queue an unbounded number of batches — moving the
185
+ * unbounded growth from one array into a promise chain rather than removing it. By
186
+ * leaving lines in `pending` while a write is in flight, the pending-byte bound in
187
+ * {@link write} is the real bound on memory.
188
+ *
189
+ * Returns nothing on purpose: no caller on the streaming path may await this.
190
+ * `close()` is the one place the chain is awaited.
191
+ */
192
+ private flush;
193
+ /** Flushes and waits, so a session's last lines are durable before the process exits. */
194
+ close(): Promise<void>;
195
+ /** Latches the first failure and stops logging; never rethrows. */
196
+ private fail;
197
+ private append;
198
+ /** One line naming the drops since the last report, or nothing to report. */
199
+ private takeDroppedReport;
200
+ /**
201
+ * One-time setup for the first append of this process: creates the directory and
202
+ * measures what is already there, so the budget covers the whole session rather
203
+ * than only this run. Returns a newline guard when a previous run left a partial
204
+ * line, for the same reason the recorder does — an interrupted write stays one
205
+ * broken line instead of being glued onto the next good one. Nothing here modifies
206
+ * existing bytes.
207
+ */
208
+ private prepare;
209
+ private endsWithNewline;
210
+ /** Appends the final line and latches logging off for this session. */
211
+ private stopForBudget;
212
+ }