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,667 @@
1
+ /**
2
+ * `web_fetch` — one GET of one web page, returned as a bounded readable text
3
+ * projection. A sibling of the SDK `http_request` singleton, never a wrapper
4
+ * around it: `http_request` keeps returning the raw body, this tool trades the
5
+ * raw bytes for something a model can read in one round (HTML → text, a stated
6
+ * code-point budget, a truncation notice). It is registered on the parent only
7
+ * and stays classified through the unknown-tool fail-closed `execute` path.
8
+ */
9
+ import { tool } from '@strands-agents/sdk';
10
+ import { z } from 'zod';
11
+ export const WEB_FETCH_TOOL_NAME = 'web_fetch';
12
+ /** Hard ceiling on the returned body; `maxChars` may lower it, never raise it. */
13
+ export const WEB_FETCH_MAX_CHARS = 40_000;
14
+ /** The raw download stops here so one huge page never fills memory. */
15
+ export const WEB_FETCH_MAX_DOWNLOAD_BYTES = 4 * 1024 * 1024;
16
+ /** Same-host redirect hops followed before the fetch gives up. */
17
+ export const WEB_FETCH_MAX_REDIRECTS = 5;
18
+ export const WEB_FETCH_TIMEOUT_SECONDS = 30;
19
+ export const WEB_FETCH_MAX_URL_CHARS = 4_096;
20
+ /** Markdown first: servers with content negotiation then skip the HTML round entirely. */
21
+ export const WEB_FETCH_ACCEPT = 'text/markdown, text/plain;q=0.9, text/html;q=0.8, */*;q=0.1';
22
+ export const WEB_FETCH_USER_AGENT = 'darwin-coding-agent (+https://github.com/xiehust/strands-darwin)';
23
+ /** Wording of the truncation notice; `N` is the code points shown, `M` the total. */
24
+ export const WEB_FETCH_TRUNCATION_NOTICE = '[truncated: N of M code points]';
25
+ export const WEB_FETCH_LOSSY_NOTICE = 'HTML converted to readable text (lossy: scripts, styles, navigation, layout and attributes dropped); use http_request for the raw body.';
26
+ export function formatTruncationNotice(shown, total) {
27
+ return WEB_FETCH_TRUNCATION_NOTICE.replace('N', String(shown)).replace('M', String(total));
28
+ }
29
+ export const webFetchInputSchema = z.object({
30
+ url: z
31
+ .string()
32
+ .min(1)
33
+ .max(WEB_FETCH_MAX_URL_CHARS)
34
+ .describe('Absolute http(s) URL of the page to fetch; http:// is upgraded to https://'),
35
+ maxChars: z
36
+ .number()
37
+ .int()
38
+ .positive()
39
+ .optional()
40
+ .describe(`Lower the returned body's code-point budget (default and ceiling ${WEB_FETCH_MAX_CHARS})`),
41
+ });
42
+ /**
43
+ * Validates the scheme and upgrades `http:` to `https:`. Anything that is not an
44
+ * absolute http(s) URL is refused here, before any request is made.
45
+ */
46
+ export function normalizeWebFetchUrl(raw) {
47
+ let parsed;
48
+ try {
49
+ parsed = new URL(raw);
50
+ }
51
+ catch {
52
+ throw new Error(`web_fetch: not an absolute URL: ${clip(raw, 200)}`);
53
+ }
54
+ if (parsed.protocol === 'https:')
55
+ return { url: parsed.href, upgraded: false };
56
+ if (parsed.protocol === 'http:') {
57
+ parsed.protocol = 'https:';
58
+ return { url: parsed.href, upgraded: true };
59
+ }
60
+ throw new Error(`web_fetch: only http(s) URLs are fetched, not ${parsed.protocol.replace(/:$/, '')}: ${clip(raw, 200)}`);
61
+ }
62
+ const REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
63
+ /** Performs the GET, redirect policy, content classification and bounding. */
64
+ export async function fetchWebPage(input, options = {}) {
65
+ const fetchImpl = options.fetchImpl ?? globalThis.fetch;
66
+ const notice = [];
67
+ const budget = Math.min(input.maxChars ?? WEB_FETCH_MAX_CHARS, WEB_FETCH_MAX_CHARS);
68
+ if (input.maxChars !== undefined && input.maxChars > WEB_FETCH_MAX_CHARS) {
69
+ notice.push(`maxChars ${input.maxChars} exceeds the ceiling; clamped to ${WEB_FETCH_MAX_CHARS} code points.`);
70
+ }
71
+ const first = normalizeWebFetchUrl(input.url);
72
+ if (first.upgraded)
73
+ notice.push(`Upgraded ${input.url} to ${first.url}.`);
74
+ let current = first.url;
75
+ const requestInit = {
76
+ method: 'GET',
77
+ headers: { Accept: WEB_FETCH_ACCEPT, 'User-Agent': WEB_FETCH_USER_AGENT },
78
+ redirect: 'manual',
79
+ ...(options.signal === undefined ? {} : { signal: options.signal }),
80
+ };
81
+ let response;
82
+ for (let hop = 0; hop <= WEB_FETCH_MAX_REDIRECTS; hop += 1) {
83
+ response = await fetchImpl(current, requestInit);
84
+ if (!REDIRECT_STATUSES.has(response.status))
85
+ break;
86
+ const location = response.headers.get('location');
87
+ const contentType = response.headers.get('content-type') ?? '';
88
+ await discardBody(response);
89
+ if (location === null) {
90
+ notice.push(`HTTP ${response.status} without a Location header; nothing to follow.`);
91
+ return { url: current, status: response.status, contentType, body: '', notice };
92
+ }
93
+ let target;
94
+ try {
95
+ target = new URL(location, current);
96
+ }
97
+ catch {
98
+ throw new Error(`web_fetch: HTTP ${response.status} from ${current} redirects to an invalid Location: ${clip(location, 200)}`);
99
+ }
100
+ if (target.host !== new URL(current).host) {
101
+ notice.push(`Redirect not followed: ${current} → ${target.href} (host ${target.host} differs from ${new URL(current).host}). ` +
102
+ 'Call web_fetch with the target URL to follow it.');
103
+ return { url: current, status: response.status, contentType, body: '', notice };
104
+ }
105
+ const next = normalizeWebFetchUrl(target.href);
106
+ if (next.upgraded)
107
+ notice.push(`Upgraded redirect target ${target.href} to ${next.url}.`);
108
+ if (hop === WEB_FETCH_MAX_REDIRECTS) {
109
+ throw new Error(`web_fetch: more than ${WEB_FETCH_MAX_REDIRECTS} redirects starting from ${first.url}; last target ${next.url}`);
110
+ }
111
+ current = next.url;
112
+ response = undefined;
113
+ }
114
+ if (response === undefined)
115
+ throw new Error(`web_fetch: no response for ${current}`);
116
+ const rawContentType = response.headers.get('content-type') ?? '';
117
+ const { mediaType, charset } = parseContentType(rawContentType);
118
+ if (!response.ok)
119
+ notice.push(`HTTP ${response.status}${response.statusText === '' ? '' : ` ${response.statusText}`}.`);
120
+ const declaredKind = mediaType === '' ? undefined : classifyMediaType(mediaType);
121
+ if (declaredKind === 'binary') {
122
+ const length = response.headers.get('content-length');
123
+ await discardBody(response);
124
+ throw new Error(`web_fetch: ${current} returned non-text content (${mediaType}${length === null ? ', unknown length' : `, ${length} bytes`}); ` +
125
+ 'the body was not read. Use http_request or bash (curl -o) if the bytes are needed.');
126
+ }
127
+ const download = await readBounded(response);
128
+ if (download.capped) {
129
+ notice.push(`Download stopped at ${WEB_FETCH_MAX_DOWNLOAD_BYTES} bytes; the page continues beyond what was read.`);
130
+ }
131
+ const kind = declaredKind ?? sniffKind(download.bytes);
132
+ if (kind === 'binary') {
133
+ throw new Error(`web_fetch: ${current} returned non-text content (no content type declared, ${download.bytes.byteLength} bytes read); ` +
134
+ 'the body was not returned.');
135
+ }
136
+ let text = decodeText(download.bytes, charset);
137
+ if (download.capped)
138
+ text = text.replace(/\uFFFD$/, '');
139
+ if (kind === 'html') {
140
+ text = htmlToText(text, current);
141
+ notice.push(WEB_FETCH_LOSSY_NOTICE);
142
+ }
143
+ const bounded = boundCodePoints(text, budget);
144
+ if (bounded.total > bounded.shown)
145
+ notice.push(formatTruncationNotice(bounded.shown, bounded.total));
146
+ return { url: current, status: response.status, contentType: rawContentType, body: bounded.body, notice };
147
+ }
148
+ export const webFetch = tool({
149
+ name: WEB_FETCH_TOOL_NAME,
150
+ description: 'Fetches one web page with GET and returns a bounded readable text projection: markdown and plain text are kept as is, ' +
151
+ 'HTML is converted to headings, paragraphs, lists, links as "text (url)" and fenced code — a lossy projection that drops ' +
152
+ 'scripts, styles, navigation and layout. http:// is upgraded to https://; same-host redirects are followed, cross-host ' +
153
+ `redirects are reported instead of followed. The body is capped at ${WEB_FETCH_MAX_CHARS} code points (maxChars may lower it) ` +
154
+ `with an explicit "${WEB_FETCH_TRUNCATION_NOTICE}" notice. Use http_request for the raw, unconverted body or other methods.`,
155
+ inputSchema: webFetchInputSchema,
156
+ callback: async (input, context) => {
157
+ // Abort on timeout or tool-execution cancellation, whichever comes first —
158
+ // the same composition the SDK http_request callback uses, built here.
159
+ const timeoutSignal = AbortSignal.timeout(WEB_FETCH_TIMEOUT_SECONDS * 1000);
160
+ const signal = context ? AbortSignal.any([timeoutSignal, context.cancelSignal]) : timeoutSignal;
161
+ try {
162
+ return await fetchWebPage(input, { signal });
163
+ }
164
+ catch (error) {
165
+ if (error instanceof Error && (error.name === 'AbortError' || error.name === 'TimeoutError')) {
166
+ const reason = timeoutSignal.aborted ? `timed out after ${WEB_FETCH_TIMEOUT_SECONDS} seconds` : 'cancelled';
167
+ throw new Error(`web_fetch: request ${reason}: GET ${clip(input.url, 200)}`, { cause: error });
168
+ }
169
+ throw error;
170
+ }
171
+ },
172
+ });
173
+ const TEXTUAL_APPLICATION_TYPES = new Set([
174
+ 'application/json',
175
+ 'application/ld+json',
176
+ 'application/xml',
177
+ 'application/javascript',
178
+ 'application/ecmascript',
179
+ 'application/x-javascript',
180
+ 'application/yaml',
181
+ 'application/x-yaml',
182
+ 'application/toml',
183
+ 'application/x-sh',
184
+ 'application/graphql',
185
+ 'application/x-ndjson',
186
+ 'application/sql',
187
+ 'application/x-www-form-urlencoded',
188
+ ]);
189
+ function classifyMediaType(mediaType) {
190
+ if (mediaType === 'text/html' || mediaType === 'application/xhtml+xml')
191
+ return 'html';
192
+ if (mediaType.startsWith('text/'))
193
+ return 'text';
194
+ if (TEXTUAL_APPLICATION_TYPES.has(mediaType) || mediaType.endsWith('+json') || mediaType.endsWith('+xml'))
195
+ return 'text';
196
+ return 'binary';
197
+ }
198
+ /** Only consulted when the server declared no content type at all. */
199
+ function sniffKind(bytes) {
200
+ const sample = bytes.subarray(0, 1024);
201
+ if (sample.includes(0))
202
+ return 'binary';
203
+ const head = new TextDecoder('utf-8', { fatal: false }).decode(sample).replace(/^\uFEFF/, '').trimStart().toLowerCase();
204
+ return head.startsWith('<!doctype html') || head.startsWith('<html') ? 'html' : 'text';
205
+ }
206
+ function parseContentType(raw) {
207
+ const [type = '', ...params] = raw.split(';');
208
+ const mediaType = type.trim().toLowerCase();
209
+ let charset;
210
+ for (const param of params) {
211
+ const match = /^\s*charset\s*=\s*"?([^";]+)"?\s*$/i.exec(param);
212
+ if (match?.[1] !== undefined)
213
+ charset = match[1].trim();
214
+ }
215
+ return { mediaType, charset };
216
+ }
217
+ function decodeText(bytes, charset) {
218
+ let decoder;
219
+ try {
220
+ decoder = new TextDecoder(charset ?? 'utf-8', { fatal: false });
221
+ }
222
+ catch {
223
+ decoder = new TextDecoder('utf-8', { fatal: false });
224
+ }
225
+ return decoder.decode(bytes).replace(/^\uFEFF/, '');
226
+ }
227
+ async function readBounded(response) {
228
+ const stream = response.body;
229
+ if (stream === null)
230
+ return { bytes: new Uint8Array(0), capped: false };
231
+ const reader = stream.getReader();
232
+ const chunks = [];
233
+ let total = 0;
234
+ let capped = false;
235
+ try {
236
+ for (;;) {
237
+ const { done, value } = await reader.read();
238
+ if (done)
239
+ break;
240
+ if (total + value.byteLength > WEB_FETCH_MAX_DOWNLOAD_BYTES) {
241
+ chunks.push(value.subarray(0, WEB_FETCH_MAX_DOWNLOAD_BYTES - total));
242
+ total = WEB_FETCH_MAX_DOWNLOAD_BYTES;
243
+ capped = true;
244
+ await reader.cancel().catch(() => undefined);
245
+ break;
246
+ }
247
+ chunks.push(value);
248
+ total += value.byteLength;
249
+ }
250
+ }
251
+ finally {
252
+ reader.releaseLock();
253
+ }
254
+ const bytes = new Uint8Array(total);
255
+ let offset = 0;
256
+ for (const chunk of chunks) {
257
+ bytes.set(chunk, offset);
258
+ offset += chunk.byteLength;
259
+ }
260
+ return { bytes, capped };
261
+ }
262
+ async function discardBody(response) {
263
+ try {
264
+ await response.body?.cancel();
265
+ }
266
+ catch {
267
+ // A body that is already consumed or errored has nothing left to release.
268
+ }
269
+ }
270
+ /** Cuts at a code-point boundary and reports both figures for the notice. */
271
+ export function boundCodePoints(text, budget) {
272
+ let total = 0;
273
+ let cut = text.length;
274
+ for (let index = 0; index < text.length;) {
275
+ const codePoint = text.codePointAt(index) ?? 0;
276
+ if (total === budget)
277
+ cut = Math.min(cut, index);
278
+ total += 1;
279
+ index += codePoint > 0xffff ? 2 : 1;
280
+ }
281
+ if (total <= budget)
282
+ return { body: text, shown: total, total };
283
+ return { body: text.slice(0, cut), shown: budget, total };
284
+ }
285
+ function clip(value, max) {
286
+ return value.length <= max ? value : `${value.slice(0, max)}…`;
287
+ }
288
+ // ---------------------------------------------------------------------------
289
+ // HTML → readable text (dependency-free projection)
290
+ /** Subtrees that never carry readable content; `head` keeps only its `title`. */
291
+ const DROPPED_ELEMENTS = new Set(['script', 'style', 'noscript', 'template', 'svg', 'nav', 'header', 'footer', 'aside']);
292
+ /** Raw-text elements whose content is not parsed for tags. */
293
+ const RAW_TEXT_ELEMENTS = new Set(['script', 'style', 'textarea', 'title']);
294
+ const BLOCK_ELEMENTS = new Set([
295
+ 'address', 'article', 'blockquote', 'body', 'dd', 'details', 'dialog', 'div', 'dl', 'dt', 'fieldset',
296
+ 'figcaption', 'figure', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'html', 'legend', 'li', 'main',
297
+ 'ol', 'option', 'p', 'pre', 'section', 'summary', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'ul',
298
+ ]);
299
+ /** Elements that separate paragraphs rather than lines. */
300
+ const PARAGRAPH_ELEMENTS = new Set([
301
+ 'article', 'blockquote', 'details', 'dialog', 'div', 'dl', 'fieldset', 'figure', 'form', 'h1', 'h2', 'h3', 'h4',
302
+ 'h5', 'h6', 'hr', 'main', 'ol', 'p', 'pre', 'section', 'table', 'ul',
303
+ ]);
304
+ const VOID_ELEMENTS = new Set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'source', 'track', 'wbr']);
305
+ const NAMED_ENTITIES = {
306
+ amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", nbsp: '\u00a0', copy: '©', reg: '®', trade: '™',
307
+ hellip: '…', mdash: '—', ndash: '–', lsquo: '‘', rsquo: '’', ldquo: '“', rdquo: '”', laquo: '«', raquo: '»',
308
+ bull: '•', middot: '·', times: '×', deg: '°', euro: '€', pound: '£', yen: '¥', cent: '¢', sect: '§', para: '¶',
309
+ larr: '←', rarr: '→', uarr: '↑', darr: '↓', harr: '↔', rArr: '⇒', lArr: '⇐', hArr: '⇔', check: '✓', ne: '≠',
310
+ le: '≤', ge: '≥', plusmn: '±', frac12: '½', frac14: '¼', frac34: '¾', shy: '', zwj: '\u200d', zwnj: '\u200c',
311
+ };
312
+ export function decodeEntities(text) {
313
+ if (!text.includes('&'))
314
+ return text;
315
+ return text.replace(/&(#x[0-9a-f]+|#[0-9]+|[a-z][a-z0-9]*);/gi, (whole, entity) => {
316
+ if (entity[0] === '#') {
317
+ const code = entity[1] === 'x' || entity[1] === 'X' ? Number.parseInt(entity.slice(2), 16) : Number.parseInt(entity.slice(1), 10);
318
+ if (!Number.isFinite(code) || code < 0 || code > 0x10ffff || (code >= 0xd800 && code <= 0xdfff))
319
+ return whole;
320
+ return code === 0 ? '' : String.fromCodePoint(code);
321
+ }
322
+ const named = NAMED_ENTITIES[entity] ?? NAMED_ENTITIES[entity.toLowerCase()];
323
+ return named ?? whole;
324
+ });
325
+ }
326
+ /** Accumulates lines, applying block-quote prefixes and whitespace collapsing outside `pre`. */
327
+ class TextBuilder {
328
+ lines = [];
329
+ current = '';
330
+ quoteDepth = 0;
331
+ preDepth = 0;
332
+ pendingBlank = false;
333
+ pendingBlankDepth = 0;
334
+ get length() {
335
+ return this.current.length;
336
+ }
337
+ sliceCurrent(from) {
338
+ return this.current.slice(from);
339
+ }
340
+ inPre() {
341
+ return this.preDepth > 0;
342
+ }
343
+ enterPre() {
344
+ this.preDepth += 1;
345
+ }
346
+ leavePre() {
347
+ this.preDepth = Math.max(0, this.preDepth - 1);
348
+ }
349
+ enterQuote() {
350
+ this.quoteDepth += 1;
351
+ }
352
+ leaveQuote() {
353
+ this.quoteDepth = Math.max(0, this.quoteDepth - 1);
354
+ }
355
+ text(raw) {
356
+ if (raw === '')
357
+ return;
358
+ if (this.preDepth > 0) {
359
+ const parts = raw.split('\n');
360
+ for (const [index, part] of parts.entries()) {
361
+ if (index > 0)
362
+ this.endLine(true);
363
+ this.current += part;
364
+ }
365
+ return;
366
+ }
367
+ const collapsed = raw.replace(/[\t\n\f\r \u00a0]+/g, ' ');
368
+ if (collapsed === ' ' && (this.current === '' || this.current.endsWith(' ')))
369
+ return;
370
+ const startsWithSpace = collapsed.startsWith(' ');
371
+ if (startsWithSpace && (this.current === '' || this.current.endsWith(' '))) {
372
+ this.current += collapsed.slice(1);
373
+ }
374
+ else {
375
+ this.current += collapsed;
376
+ }
377
+ }
378
+ /** Appends without whitespace collapsing (markers such as `- ` or a link URL). */
379
+ literal(marker) {
380
+ this.current += marker;
381
+ }
382
+ endLine(keepBlank = false) {
383
+ const prefix = '> '.repeat(this.quoteDepth);
384
+ const line = this.preDepth > 0 ? this.current : this.current.trimEnd();
385
+ if (line !== '' || keepBlank) {
386
+ if (this.pendingBlank && this.lines.length > 0)
387
+ this.lines.push('> '.repeat(this.pendingBlankDepth).trimEnd());
388
+ this.pendingBlank = false;
389
+ this.lines.push(`${prefix}${line}`);
390
+ }
391
+ this.current = '';
392
+ }
393
+ /** A paragraph separator; consecutive requests collapse to the shallowest quote depth. */
394
+ blank() {
395
+ this.endLine();
396
+ this.pendingBlankDepth = this.pendingBlank ? Math.min(this.pendingBlankDepth, this.quoteDepth) : this.quoteDepth;
397
+ this.pendingBlank = true;
398
+ }
399
+ toString() {
400
+ this.endLine();
401
+ return this.lines.join('\n').replace(/\n{3,}/g, '\n\n').trim();
402
+ }
403
+ }
404
+ function parseTag(html, start) {
405
+ // `start` points at '<'. Returns undefined when this is not a tag.
406
+ let index = start + 1;
407
+ let closing = false;
408
+ if (html[index] === '/') {
409
+ closing = true;
410
+ index += 1;
411
+ }
412
+ const nameStart = index;
413
+ while (index < html.length && /[A-Za-z0-9:-]/.test(html[index]))
414
+ index += 1;
415
+ if (index === nameStart)
416
+ return undefined;
417
+ const name = html.slice(nameStart, index).toLowerCase();
418
+ const attributes = new Map();
419
+ let selfClosing = false;
420
+ for (;;) {
421
+ while (index < html.length && /\s/.test(html[index]))
422
+ index += 1;
423
+ if (index >= html.length)
424
+ return { name, attributes, closing, selfClosing, end: html.length };
425
+ const char = html[index];
426
+ if (char === '>')
427
+ return { name, attributes, closing, selfClosing, end: index + 1 };
428
+ if (char === '/') {
429
+ selfClosing = true;
430
+ index += 1;
431
+ continue;
432
+ }
433
+ const attrStart = index;
434
+ while (index < html.length && !/[\s=/>]/.test(html[index]))
435
+ index += 1;
436
+ if (index === attrStart) {
437
+ index += 1;
438
+ continue;
439
+ }
440
+ const attrName = html.slice(attrStart, index).toLowerCase();
441
+ let value = '';
442
+ let probe = index;
443
+ while (probe < html.length && /\s/.test(html[probe]))
444
+ probe += 1;
445
+ if (html[probe] === '=') {
446
+ probe += 1;
447
+ while (probe < html.length && /\s/.test(html[probe]))
448
+ probe += 1;
449
+ const quote = html[probe];
450
+ if (quote === '"' || quote === "'") {
451
+ const close = html.indexOf(quote, probe + 1);
452
+ value = close === -1 ? html.slice(probe + 1) : html.slice(probe + 1, close);
453
+ index = close === -1 ? html.length : close + 1;
454
+ }
455
+ else {
456
+ const valueStart = probe;
457
+ while (probe < html.length && !/[\s>]/.test(html[probe]))
458
+ probe += 1;
459
+ value = html.slice(valueStart, probe);
460
+ index = probe;
461
+ }
462
+ }
463
+ if (!attributes.has(attrName))
464
+ attributes.set(attrName, decodeEntities(value));
465
+ }
466
+ }
467
+ function skipUntilClose(html, from, name) {
468
+ // Raw-text and dropped subtrees: for raw-text elements only the literal close
469
+ // tag ends them; for others, nested same-name elements are counted.
470
+ if (RAW_TEXT_ELEMENTS.has(name)) {
471
+ const close = new RegExp(`</${name}\\s*>`, 'ig');
472
+ close.lastIndex = from;
473
+ const match = close.exec(html);
474
+ return match === null ? html.length : match.index + match[0].length;
475
+ }
476
+ let depth = 1;
477
+ let index = from;
478
+ while (index < html.length) {
479
+ const lt = html.indexOf('<', index);
480
+ if (lt === -1)
481
+ return html.length;
482
+ const tag = parseTag(html, lt);
483
+ if (tag === undefined) {
484
+ index = lt + 1;
485
+ continue;
486
+ }
487
+ if (tag.name === name) {
488
+ if (tag.closing) {
489
+ depth -= 1;
490
+ if (depth === 0)
491
+ return tag.end;
492
+ }
493
+ else if (!tag.selfClosing && !VOID_ELEMENTS.has(name)) {
494
+ depth += 1;
495
+ }
496
+ }
497
+ index = tag.end;
498
+ }
499
+ return html.length;
500
+ }
501
+ function resolveHref(href, baseUrl) {
502
+ const trimmed = href.trim();
503
+ if (trimmed === '' || trimmed.startsWith('#') || /^javascript:/i.test(trimmed))
504
+ return undefined;
505
+ try {
506
+ const resolved = new URL(trimmed, baseUrl);
507
+ return resolved.protocol === 'http:' || resolved.protocol === 'https:' || resolved.protocol === 'mailto:'
508
+ ? resolved.href
509
+ : undefined;
510
+ }
511
+ catch {
512
+ return undefined;
513
+ }
514
+ }
515
+ /**
516
+ * Converts one HTML document to readable markdown-ish text: headings, paragraphs,
517
+ * `- ` list items, `> ` quotes, fenced `pre`, `text (url)` links, `[image: alt]`.
518
+ * Every decision is local to one tag, so malformed markup degrades to plain text
519
+ * instead of failing.
520
+ */
521
+ export function htmlToText(html, baseUrl) {
522
+ const out = new TextBuilder();
523
+ const openLinks = [];
524
+ let title;
525
+ let rowHasCell = false;
526
+ let index = 0;
527
+ while (index < html.length) {
528
+ const lt = html.indexOf('<', index);
529
+ if (lt === -1) {
530
+ out.text(decodeEntities(html.slice(index)));
531
+ break;
532
+ }
533
+ if (lt > index)
534
+ out.text(decodeEntities(html.slice(index, lt)));
535
+ if (html.startsWith('<!--', lt)) {
536
+ const close = html.indexOf('-->', lt + 4);
537
+ index = close === -1 ? html.length : close + 3;
538
+ continue;
539
+ }
540
+ if (html.startsWith('<!', lt) || html.startsWith('<?', lt)) {
541
+ const close = html.indexOf('>', lt);
542
+ index = close === -1 ? html.length : close + 1;
543
+ continue;
544
+ }
545
+ const tag = parseTag(html, lt);
546
+ if (tag === undefined) {
547
+ out.text('<');
548
+ index = lt + 1;
549
+ continue;
550
+ }
551
+ index = tag.end;
552
+ const { name } = tag;
553
+ if (!tag.closing && name === 'title' && title === undefined) {
554
+ const end = skipUntilClose(html, index, name);
555
+ const inner = html.slice(index, end).replace(/<\/title\s*>$/i, '');
556
+ title = decodeEntities(inner).replace(/\s+/g, ' ').trim();
557
+ index = end;
558
+ continue;
559
+ }
560
+ if (!tag.closing && !tag.selfClosing && (DROPPED_ELEMENTS.has(name) || RAW_TEXT_ELEMENTS.has(name))) {
561
+ index = skipUntilClose(html, index, name);
562
+ continue;
563
+ }
564
+ if (name === 'head')
565
+ continue;
566
+ if (name === 'br') {
567
+ out.endLine();
568
+ continue;
569
+ }
570
+ if (name === 'img') {
571
+ const alt = (tag.attributes.get('alt') ?? '').trim();
572
+ out.text(alt === '' ? '[image]' : `[image: ${alt}]`);
573
+ continue;
574
+ }
575
+ if (name === 'hr') {
576
+ out.blank();
577
+ out.literal('---');
578
+ out.blank();
579
+ continue;
580
+ }
581
+ if (name === 'a') {
582
+ if (!tag.closing) {
583
+ openLinks.push({ href: resolveHref(tag.attributes.get('href') ?? '', baseUrl), start: out.length });
584
+ }
585
+ else {
586
+ const link = openLinks.pop();
587
+ if (link?.href !== undefined) {
588
+ const text = out.sliceCurrent(link.start).trim();
589
+ if (text !== '' && text !== link.href)
590
+ out.literal(` (${link.href})`);
591
+ else if (text === '')
592
+ out.text(link.href);
593
+ }
594
+ }
595
+ continue;
596
+ }
597
+ if (name === 'code' && !out.inPre()) {
598
+ out.literal('`');
599
+ continue;
600
+ }
601
+ if (name === 'pre') {
602
+ if (!tag.closing) {
603
+ out.blank();
604
+ out.literal('```');
605
+ out.endLine();
606
+ out.enterPre();
607
+ }
608
+ else {
609
+ out.endLine();
610
+ out.leavePre();
611
+ out.literal('```');
612
+ out.blank();
613
+ }
614
+ continue;
615
+ }
616
+ if (name === 'blockquote') {
617
+ if (!tag.closing) {
618
+ out.blank();
619
+ out.enterQuote();
620
+ }
621
+ else {
622
+ out.leaveQuote();
623
+ out.blank();
624
+ }
625
+ continue;
626
+ }
627
+ if (/^h[1-6]$/.test(name)) {
628
+ out.blank();
629
+ if (!tag.closing)
630
+ out.literal(`${'#'.repeat(Number(name[1]))} `);
631
+ continue;
632
+ }
633
+ if (name === 'li') {
634
+ out.endLine();
635
+ if (!tag.closing)
636
+ out.literal('- ');
637
+ continue;
638
+ }
639
+ if (name === 'tr') {
640
+ rowHasCell = false;
641
+ out.endLine();
642
+ continue;
643
+ }
644
+ if (name === 'td' || name === 'th') {
645
+ if (!tag.closing) {
646
+ if (rowHasCell)
647
+ out.literal(' | ');
648
+ rowHasCell = true;
649
+ }
650
+ continue;
651
+ }
652
+ if (PARAGRAPH_ELEMENTS.has(name)) {
653
+ out.blank();
654
+ continue;
655
+ }
656
+ if (BLOCK_ELEMENTS.has(name)) {
657
+ out.endLine();
658
+ continue;
659
+ }
660
+ }
661
+ const body = out.toString();
662
+ if (title !== undefined && title !== '' && !body.startsWith(`# ${title}`)) {
663
+ return body === '' ? `# ${title}` : `# ${title}\n\n${body}`;
664
+ }
665
+ return body;
666
+ }
667
+ //# sourceMappingURL=web-fetch.js.map