@astralyn/pi 1.4.11 → 1.5.0

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 (546) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/dist/bundle/chunks/anthropic-messages-G5ZGBHOH.js +6 -0
  3. package/dist/bundle/chunks/azure-openai-responses-EMPTMYNF.js +2 -0
  4. package/dist/bundle/chunks/bedrock-converse-stream.js +22 -15
  5. package/dist/bundle/chunks/chunk-AXX7FFFD.js +2 -0
  6. package/dist/bundle/chunks/chunk-FNGB3ASD.js +2 -0
  7. package/dist/bundle/chunks/chunk-FPALVF3F.js +4 -0
  8. package/dist/bundle/chunks/chunk-H3UF54OB.js +9 -0
  9. package/dist/bundle/chunks/chunk-IC6JXX2J.js +10 -0
  10. package/dist/bundle/chunks/{chunk-TH3QDDPD.js → chunk-IRUUTK4W.js} +1 -1
  11. package/dist/bundle/chunks/{chunk-MZJC45TM.js → chunk-J7L6O5XA.js} +3 -3
  12. package/dist/bundle/chunks/{chunk-DLVLAQEG.js → chunk-KBFO53OG.js} +3 -3
  13. package/dist/bundle/chunks/{chunk-TPVFPFJP.js → chunk-P7VXFB2M.js} +1 -1
  14. package/dist/bundle/chunks/chunk-PSYLMRL6.js +9 -0
  15. package/dist/bundle/chunks/chunk-QNZARXLE.js +82 -0
  16. package/dist/bundle/chunks/chunk-R3YHAMWH.js +1503 -0
  17. package/dist/bundle/chunks/chunk-RAIYJ5FC.js +4 -0
  18. package/dist/bundle/chunks/{chunk-OV2VMHBX.js → chunk-SR6EWNPW.js} +1 -1
  19. package/dist/bundle/chunks/chunk-TA3YH2ZI.js +16 -0
  20. package/dist/bundle/chunks/{chunk-NUQMVNKQ.js → chunk-THAJ4BZF.js} +58 -62
  21. package/dist/bundle/chunks/{chunk-24FY4C5S.js → chunk-TRSJS3FM.js} +1 -1
  22. package/dist/bundle/chunks/chunk-ZRI3ICDE.js +2 -0
  23. package/dist/bundle/chunks/{cli-MBFCFGI2.js → cli-LAZQG54B.js} +11 -9
  24. package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-7BKATOEJ.js → cloudflare-workers-ai-system-one-4L2ABUJE.js} +1 -1
  25. package/dist/bundle/chunks/{execute-VLAIP26K.js → execute-ACWDKC3C.js} +1 -1
  26. package/dist/bundle/chunks/github-copilot.js +1 -1
  27. package/dist/bundle/chunks/{google-generative-ai-HTUSU45F.js → google-generative-ai-OOVDGS5W.js} +1 -1
  28. package/dist/bundle/chunks/{google-vertex-AVQV4P76.js → google-vertex-IK5RNG7J.js} +1 -1
  29. package/dist/bundle/chunks/image-resize-worker.js +1 -1
  30. package/dist/bundle/chunks/kimi-coding.js +1 -1
  31. package/dist/bundle/chunks/{llama-cpp-classify-27QYLJZY.js → llama-cpp-classify-XHAVT37C.js} +1 -1
  32. package/dist/bundle/chunks/meta.js +1 -1
  33. package/dist/bundle/chunks/mistral-conversations-Z56KY4OJ.js +5 -0
  34. package/dist/bundle/chunks/{openai-codex-responses-Q25MHDFX.js → openai-codex-responses-5NAH3SK6.js} +1 -1
  35. package/dist/bundle/chunks/openai-completions-S7S6PO3J.js +7 -0
  36. package/dist/bundle/chunks/{openai-decisions-3WYFPGSK.js → openai-decisions-7A36EAHE.js} +1 -1
  37. package/dist/bundle/chunks/{openai-responses-E4BNZIQK.js → openai-responses-ZQRZJKH4.js} +1 -1
  38. package/dist/bundle/chunks/{openrouter-images-CBP3OPOD.js → openrouter-images-X7PX72ON.js} +1 -1
  39. package/dist/bundle/chunks/pi-messages-TXNWPLI4.js +8 -0
  40. package/dist/bundle/chunks/radius.js +1 -1
  41. package/dist/bundle/chunks/{runtime-3RPOJS5T.js → runtime-X3XOMNXQ.js} +1 -1
  42. package/dist/bundle/chunks/{typesafe-system-one-BNICP2LS.js → typesafe-system-one-XJGMSHWL.js} +1 -1
  43. package/dist/bundle/chunks/virtual-modules-T2KLVAFL.js +2 -0
  44. package/dist/bundle/cli.js +1 -1
  45. package/dist/bundle/index.js +1 -1
  46. package/dist/bundle/rpc-entry.js +1 -1
  47. package/dist/cli/args.d.ts.map +1 -1
  48. package/dist/cli/args.js +8 -7
  49. package/dist/cli/args.js.map +1 -1
  50. package/dist/config.d.ts +10 -0
  51. package/dist/config.d.ts.map +1 -1
  52. package/dist/config.js +24 -5
  53. package/dist/config.js.map +1 -1
  54. package/dist/core/agent-session-runtime.d.ts +0 -5
  55. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  56. package/dist/core/agent-session-runtime.js +12 -28
  57. package/dist/core/agent-session-runtime.js.map +1 -1
  58. package/dist/core/agent-session.d.ts +21 -14
  59. package/dist/core/agent-session.d.ts.map +1 -1
  60. package/dist/core/agent-session.js +67 -93
  61. package/dist/core/agent-session.js.map +1 -1
  62. package/dist/core/compaction/branch-summarization.d.ts +4 -2
  63. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  64. package/dist/core/compaction/branch-summarization.js +16 -4
  65. package/dist/core/compaction/branch-summarization.js.map +1 -1
  66. package/dist/core/exec.d.ts +9 -1
  67. package/dist/core/exec.d.ts.map +1 -1
  68. package/dist/core/exec.js +104 -60
  69. package/dist/core/exec.js.map +1 -1
  70. package/dist/core/export-html/template.css +9 -0
  71. package/dist/core/export-html/template.js +165 -45
  72. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  73. package/dist/core/export-html/tool-renderer.js +5 -0
  74. package/dist/core/export-html/tool-renderer.js.map +1 -1
  75. package/dist/core/extensions/index.d.ts +1 -1
  76. package/dist/core/extensions/index.d.ts.map +1 -1
  77. package/dist/core/extensions/index.js.map +1 -1
  78. package/dist/core/extensions/loader.d.ts.map +1 -1
  79. package/dist/core/extensions/loader.js +7 -6
  80. package/dist/core/extensions/loader.js.map +1 -1
  81. package/dist/core/extensions/pi-ai-extension-view.d.ts +19 -0
  82. package/dist/core/extensions/pi-ai-extension-view.d.ts.map +1 -0
  83. package/dist/core/extensions/pi-ai-extension-view.js +22 -0
  84. package/dist/core/extensions/pi-ai-extension-view.js.map +1 -0
  85. package/dist/core/extensions/runner.d.ts +0 -1
  86. package/dist/core/extensions/runner.d.ts.map +1 -1
  87. package/dist/core/extensions/runner.js +7 -12
  88. package/dist/core/extensions/runner.js.map +1 -1
  89. package/dist/core/extensions/types.d.ts +41 -23
  90. package/dist/core/extensions/types.d.ts.map +1 -1
  91. package/dist/core/extensions/types.js.map +1 -1
  92. package/dist/core/extensions/virtual-modules.d.ts.map +1 -1
  93. package/dist/core/extensions/virtual-modules.js +8 -7
  94. package/dist/core/extensions/virtual-modules.js.map +1 -1
  95. package/dist/core/mcp-servers.d.ts +11 -4
  96. package/dist/core/mcp-servers.d.ts.map +1 -1
  97. package/dist/core/mcp-servers.js +15 -5
  98. package/dist/core/mcp-servers.js.map +1 -1
  99. package/dist/core/model-config.d.ts +1678 -2029
  100. package/dist/core/model-config.d.ts.map +1 -1
  101. package/dist/core/model-config.js +2 -3
  102. package/dist/core/model-config.js.map +1 -1
  103. package/dist/core/model-resolver.d.ts.map +1 -1
  104. package/dist/core/model-resolver.js +16 -10
  105. package/dist/core/model-resolver.js.map +1 -1
  106. package/dist/core/package-manager.d.ts +14 -0
  107. package/dist/core/package-manager.d.ts.map +1 -1
  108. package/dist/core/package-manager.js +160 -46
  109. package/dist/core/package-manager.js.map +1 -1
  110. package/dist/core/pi-ai-schemas.d.ts +163 -0
  111. package/dist/core/pi-ai-schemas.d.ts.map +1 -0
  112. package/dist/core/pi-ai-schemas.js +21 -0
  113. package/dist/core/pi-ai-schemas.js.map +1 -0
  114. package/dist/core/pi-manifest.d.ts +1 -0
  115. package/dist/core/pi-manifest.d.ts.map +1 -1
  116. package/dist/core/pi-manifest.js +4 -0
  117. package/dist/core/pi-manifest.js.map +1 -1
  118. package/dist/core/project-trust.js +1 -1
  119. package/dist/core/project-trust.js.map +1 -1
  120. package/dist/core/quiescence.d.ts +24 -0
  121. package/dist/core/quiescence.d.ts.map +1 -0
  122. package/dist/core/quiescence.js +81 -0
  123. package/dist/core/quiescence.js.map +1 -0
  124. package/dist/core/resource-loader.d.ts +4 -1
  125. package/dist/core/resource-loader.d.ts.map +1 -1
  126. package/dist/core/resource-loader.js +41 -28
  127. package/dist/core/resource-loader.js.map +1 -1
  128. package/dist/core/sdk.d.ts.map +1 -1
  129. package/dist/core/sdk.js +3 -1
  130. package/dist/core/sdk.js.map +1 -1
  131. package/dist/core/session-manager.d.ts +7 -0
  132. package/dist/core/session-manager.d.ts.map +1 -1
  133. package/dist/core/session-manager.js +32 -13
  134. package/dist/core/session-manager.js.map +1 -1
  135. package/dist/core/settings-manager.d.ts +2 -0
  136. package/dist/core/settings-manager.d.ts.map +1 -1
  137. package/dist/core/settings-manager.js +11 -0
  138. package/dist/core/settings-manager.js.map +1 -1
  139. package/dist/core/settings-schema.d.ts +4 -2
  140. package/dist/core/settings-schema.d.ts.map +1 -1
  141. package/dist/core/settings-schema.js +8 -1
  142. package/dist/core/settings-schema.js.map +1 -1
  143. package/dist/core/skills.d.ts.map +1 -1
  144. package/dist/core/skills.js +6 -14
  145. package/dist/core/skills.js.map +1 -1
  146. package/dist/core/slash-command-name.d.ts +6 -0
  147. package/dist/core/slash-command-name.d.ts.map +1 -0
  148. package/dist/core/slash-command-name.js +11 -0
  149. package/dist/core/slash-command-name.js.map +1 -0
  150. package/dist/core/slash-commands.js +2 -2
  151. package/dist/core/slash-commands.js.map +1 -1
  152. package/dist/core/source-info.d.ts +9 -0
  153. package/dist/core/source-info.d.ts.map +1 -1
  154. package/dist/core/source-info.js +13 -0
  155. package/dist/core/source-info.js.map +1 -1
  156. package/dist/core/system-prompt.d.ts.map +1 -1
  157. package/dist/core/system-prompt.js +5 -6
  158. package/dist/core/system-prompt.js.map +1 -1
  159. package/dist/core/tasks/codec.d.ts +14 -0
  160. package/dist/core/tasks/codec.d.ts.map +1 -1
  161. package/dist/core/tasks/codec.js +57 -4
  162. package/dist/core/tasks/codec.js.map +1 -1
  163. package/dist/core/tasks/record.d.ts +1 -7
  164. package/dist/core/tasks/record.d.ts.map +1 -1
  165. package/dist/core/tasks/record.js +0 -18
  166. package/dist/core/tasks/record.js.map +1 -1
  167. package/dist/core/tasks/reminder.d.ts +3 -2
  168. package/dist/core/tasks/reminder.d.ts.map +1 -1
  169. package/dist/core/tasks/reminder.js +4 -3
  170. package/dist/core/tasks/reminder.js.map +1 -1
  171. package/dist/core/tasks/runtime.d.ts +0 -2
  172. package/dist/core/tasks/runtime.d.ts.map +1 -1
  173. package/dist/core/tasks/runtime.js +2 -15
  174. package/dist/core/tasks/runtime.js.map +1 -1
  175. package/dist/core/tasks/session.d.ts +9 -2
  176. package/dist/core/tasks/session.d.ts.map +1 -1
  177. package/dist/core/tasks/session.js +23 -9
  178. package/dist/core/tasks/session.js.map +1 -1
  179. package/dist/core/tasks/types.d.ts +1 -18
  180. package/dist/core/tasks/types.d.ts.map +1 -1
  181. package/dist/core/tasks/types.js +1 -1
  182. package/dist/core/tasks/types.js.map +1 -1
  183. package/dist/core/tools/bash.d.ts +8 -7
  184. package/dist/core/tools/bash.d.ts.map +1 -1
  185. package/dist/core/tools/bash.js +6 -5
  186. package/dist/core/tools/bash.js.map +1 -1
  187. package/dist/core/tools/edit.d.ts +3 -3
  188. package/dist/core/tools/edit.d.ts.map +1 -1
  189. package/dist/core/tools/edit.js +2 -4
  190. package/dist/core/tools/edit.js.map +1 -1
  191. package/dist/core/tools/find.d.ts +2 -2
  192. package/dist/core/tools/find.d.ts.map +1 -1
  193. package/dist/core/tools/find.js.map +1 -1
  194. package/dist/core/tools/grep.d.ts +2 -2
  195. package/dist/core/tools/grep.d.ts.map +1 -1
  196. package/dist/core/tools/grep.js +1 -1
  197. package/dist/core/tools/grep.js.map +1 -1
  198. package/dist/core/tools/ls.d.ts +2 -2
  199. package/dist/core/tools/ls.d.ts.map +1 -1
  200. package/dist/core/tools/ls.js.map +1 -1
  201. package/dist/core/tools/powershell.d.ts +1 -5
  202. package/dist/core/tools/powershell.d.ts.map +1 -1
  203. package/dist/core/tools/read.d.ts +2 -2
  204. package/dist/core/tools/read.d.ts.map +1 -1
  205. package/dist/core/tools/read.js.map +1 -1
  206. package/dist/core/tools/render-utils.d.ts +4 -6
  207. package/dist/core/tools/render-utils.d.ts.map +1 -1
  208. package/dist/core/tools/render-utils.js +19 -41
  209. package/dist/core/tools/render-utils.js.map +1 -1
  210. package/dist/core/tools/renderers/bash.d.ts.map +1 -1
  211. package/dist/core/tools/renderers/bash.js +3 -25
  212. package/dist/core/tools/renderers/bash.js.map +1 -1
  213. package/dist/core/tools/renderers/write.d.ts.map +1 -1
  214. package/dist/core/tools/renderers/write.js +18 -19
  215. package/dist/core/tools/renderers/write.js.map +1 -1
  216. package/dist/core/tools/shell-execution.d.ts +20 -13
  217. package/dist/core/tools/shell-execution.d.ts.map +1 -1
  218. package/dist/core/tools/shell-execution.js +165 -183
  219. package/dist/core/tools/shell-execution.js.map +1 -1
  220. package/dist/core/tools/shell-tool.d.ts +9 -14
  221. package/dist/core/tools/shell-tool.d.ts.map +1 -1
  222. package/dist/core/tools/shell-tool.js +38 -66
  223. package/dist/core/tools/shell-tool.js.map +1 -1
  224. package/dist/core/tools/tool-definition-wrapper.d.ts +14 -4
  225. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  226. package/dist/core/tools/tool-definition-wrapper.js +2 -3
  227. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  228. package/dist/core/tools/write.d.ts +2 -2
  229. package/dist/core/tools/write.d.ts.map +1 -1
  230. package/dist/core/tools/write.js.map +1 -1
  231. package/dist/core/trust-manager.d.ts.map +1 -1
  232. package/dist/core/trust-manager.js +30 -13
  233. package/dist/core/trust-manager.js.map +1 -1
  234. package/dist/core/usage-totals.d.ts +0 -9
  235. package/dist/core/usage-totals.d.ts.map +1 -1
  236. package/dist/core/usage-totals.js +24 -91
  237. package/dist/core/usage-totals.js.map +1 -1
  238. package/dist/extensions/agent/activity-lines.d.ts +2 -3
  239. package/dist/extensions/agent/activity-lines.d.ts.map +1 -1
  240. package/dist/extensions/agent/activity-lines.js +5 -9
  241. package/dist/extensions/agent/activity-lines.js.map +1 -1
  242. package/dist/extensions/agent/activity.d.ts +0 -2
  243. package/dist/extensions/agent/activity.d.ts.map +1 -1
  244. package/dist/extensions/agent/activity.js +1 -1
  245. package/dist/extensions/agent/activity.js.map +1 -1
  246. package/dist/extensions/agent/progress.d.ts +0 -3
  247. package/dist/extensions/agent/progress.d.ts.map +1 -1
  248. package/dist/extensions/agent/progress.js +2 -8
  249. package/dist/extensions/agent/progress.js.map +1 -1
  250. package/dist/extensions/agent/render.js +1 -1
  251. package/dist/extensions/agent/render.js.map +1 -1
  252. package/dist/extensions/agent/tool.d.ts.map +1 -1
  253. package/dist/extensions/agent/tool.js +0 -6
  254. package/dist/extensions/agent/tool.js.map +1 -1
  255. package/dist/{core/isolated-session.d.ts → extensions/agent/worker-session.d.ts} +6 -6
  256. package/dist/extensions/agent/worker-session.d.ts.map +1 -0
  257. package/dist/{core/isolated-session.js → extensions/agent/worker-session.js} +9 -9
  258. package/dist/extensions/agent/worker-session.js.map +1 -0
  259. package/dist/extensions/agent/worker.d.ts +0 -3
  260. package/dist/extensions/agent/worker.d.ts.map +1 -1
  261. package/dist/extensions/agent/worker.js +2 -3
  262. package/dist/extensions/agent/worker.js.map +1 -1
  263. package/dist/extensions/btw/agent.d.ts.map +1 -1
  264. package/dist/extensions/btw/agent.js +2 -1
  265. package/dist/extensions/btw/agent.js.map +1 -1
  266. package/dist/extensions/cached-compaction/render.d.ts.map +1 -1
  267. package/dist/extensions/cached-compaction/render.js +3 -3
  268. package/dist/extensions/cached-compaction/render.js.map +1 -1
  269. package/dist/extensions/codemode/renderer.d.ts.map +1 -1
  270. package/dist/extensions/codemode/renderer.js +6 -2
  271. package/dist/extensions/codemode/renderer.js.map +1 -1
  272. package/dist/extensions/codemode/tool.d.ts +2 -1
  273. package/dist/extensions/codemode/tool.d.ts.map +1 -1
  274. package/dist/extensions/codemode/tool.js +33 -8
  275. package/dist/extensions/codemode/tool.js.map +1 -1
  276. package/dist/extensions/deepwiki/schema.d.ts.map +1 -1
  277. package/dist/extensions/deepwiki/schema.js +1 -1
  278. package/dist/extensions/deepwiki/schema.js.map +1 -1
  279. package/dist/extensions/llama/ui.d.ts.map +1 -1
  280. package/dist/extensions/llama/ui.js +16 -4
  281. package/dist/extensions/llama/ui.js.map +1 -1
  282. package/dist/extensions/mcp/cli.d.ts.map +1 -1
  283. package/dist/extensions/mcp/cli.js +34 -8
  284. package/dist/extensions/mcp/cli.js.map +1 -1
  285. package/dist/extensions/mcp/oauth.d.ts +1 -1
  286. package/dist/extensions/mcp/oauth.d.ts.map +1 -1
  287. package/dist/extensions/mcp/oauth.js +36 -13
  288. package/dist/extensions/mcp/oauth.js.map +1 -1
  289. package/dist/extensions/mcp/ui.d.ts +1 -0
  290. package/dist/extensions/mcp/ui.d.ts.map +1 -1
  291. package/dist/extensions/mcp/ui.js +33 -24
  292. package/dist/extensions/mcp/ui.js.map +1 -1
  293. package/dist/extensions/run-summary/index.d.ts +1 -1
  294. package/dist/extensions/run-summary/index.d.ts.map +1 -1
  295. package/dist/extensions/run-summary/index.js +11 -23
  296. package/dist/extensions/run-summary/index.js.map +1 -1
  297. package/dist/extensions/statusline/usage.d.ts.map +1 -1
  298. package/dist/extensions/statusline/usage.js +2 -1
  299. package/dist/extensions/statusline/usage.js.map +1 -1
  300. package/dist/extensions/tasks/tool/schema.d.ts.map +1 -1
  301. package/dist/extensions/tasks/tool/schema.js +1 -1
  302. package/dist/extensions/tasks/tool/schema.js.map +1 -1
  303. package/dist/extensions/tasks/ui/completion-render.d.ts +5 -1
  304. package/dist/extensions/tasks/ui/completion-render.d.ts.map +1 -1
  305. package/dist/extensions/tasks/ui/completion-render.js +25 -70
  306. package/dist/extensions/tasks/ui/completion-render.js.map +1 -1
  307. package/dist/extensions/tasks/ui/inspector.d.ts +1 -1
  308. package/dist/extensions/tasks/ui/inspector.d.ts.map +1 -1
  309. package/dist/extensions/tasks/ui/inspector.js +0 -6
  310. package/dist/extensions/tasks/ui/inspector.js.map +1 -1
  311. package/dist/extensions/tasks/ui/manager.d.ts +1 -1
  312. package/dist/extensions/tasks/ui/manager.d.ts.map +1 -1
  313. package/dist/extensions/tasks/ui/manager.js.map +1 -1
  314. package/dist/extensions/tasks/ui/views.d.ts +2 -4
  315. package/dist/extensions/tasks/ui/views.d.ts.map +1 -1
  316. package/dist/extensions/tasks/ui/views.js +3 -7
  317. package/dist/extensions/tasks/ui/views.js.map +1 -1
  318. package/dist/extensions/tool-presentation/fallback.d.ts.map +1 -0
  319. package/dist/{modes/interactive/tool-view → extensions/tool-presentation}/fallback.js +5 -5
  320. package/dist/extensions/tool-presentation/fallback.js.map +1 -0
  321. package/dist/extensions/tool-presentation/index.js +1 -1
  322. package/dist/extensions/tool-presentation/index.js.map +1 -1
  323. package/dist/{modes/interactive/tool-view → extensions/tool-presentation}/shell.d.ts +1 -1
  324. package/dist/extensions/tool-presentation/shell.d.ts.map +1 -0
  325. package/dist/{modes/interactive/tool-view → extensions/tool-presentation}/shell.js +3 -3
  326. package/dist/extensions/tool-presentation/shell.js.map +1 -0
  327. package/dist/extensions/tool-search/tool.d.ts +21 -6
  328. package/dist/extensions/tool-search/tool.d.ts.map +1 -1
  329. package/dist/extensions/tool-search/tool.js +104 -36
  330. package/dist/extensions/tool-search/tool.js.map +1 -1
  331. package/dist/index.d.ts +2 -2
  332. package/dist/index.d.ts.map +1 -1
  333. package/dist/index.js.map +1 -1
  334. package/dist/main.d.ts.map +1 -1
  335. package/dist/main.js +15 -8
  336. package/dist/main.js.map +1 -1
  337. package/dist/modes/interactive/components/assistant-message.d.ts +5 -3
  338. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  339. package/dist/modes/interactive/components/assistant-message.js +61 -45
  340. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  341. package/dist/modes/interactive/components/config-selector-skills.d.ts +54 -0
  342. package/dist/modes/interactive/components/config-selector-skills.d.ts.map +1 -0
  343. package/dist/modes/interactive/components/config-selector-skills.js +178 -0
  344. package/dist/modes/interactive/components/config-selector-skills.js.map +1 -0
  345. package/dist/modes/interactive/components/config-selector.d.ts +2 -11
  346. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  347. package/dist/modes/interactive/components/config-selector.js +31 -181
  348. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  349. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  350. package/dist/modes/interactive/components/custom-editor.js +7 -0
  351. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  352. package/dist/modes/interactive/components/custom-entry.d.ts.map +1 -1
  353. package/dist/modes/interactive/components/custom-entry.js +2 -1
  354. package/dist/modes/interactive/components/custom-entry.js.map +1 -1
  355. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  356. package/dist/modes/interactive/components/custom-message.js +2 -1
  357. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  358. package/dist/modes/interactive/components/extension-editor.d.ts +2 -0
  359. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  360. package/dist/modes/interactive/components/extension-editor.js +4 -0
  361. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  362. package/dist/modes/interactive/components/login-dialog.d.ts +5 -0
  363. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  364. package/dist/modes/interactive/components/login-dialog.js +103 -10
  365. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  366. package/dist/modes/interactive/components/markdown-transform.d.ts +2 -1
  367. package/dist/modes/interactive/components/markdown-transform.d.ts.map +1 -1
  368. package/dist/modes/interactive/components/markdown-transform.js +3 -2
  369. package/dist/modes/interactive/components/markdown-transform.js.map +1 -1
  370. package/dist/modes/interactive/components/model-selector.d.ts +1 -0
  371. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  372. package/dist/modes/interactive/components/model-selector.js +17 -6
  373. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  374. package/dist/modes/interactive/components/oauth-selector.d.ts +1 -0
  375. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  376. package/dist/modes/interactive/components/oauth-selector.js +13 -4
  377. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  378. package/dist/modes/interactive/components/scoped-models-selector.d.ts +1 -0
  379. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  380. package/dist/modes/interactive/components/scoped-models-selector.js +14 -3
  381. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  382. package/dist/modes/interactive/components/session-selector-search.d.ts +4 -0
  383. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
  384. package/dist/modes/interactive/components/session-selector-search.js +86 -22
  385. package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
  386. package/dist/modes/interactive/components/session-selector.d.ts +2 -1
  387. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  388. package/dist/modes/interactive/components/session-selector.js +15 -23
  389. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  390. package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -1
  391. package/dist/modes/interactive/components/settings-submenu.js +2 -0
  392. package/dist/modes/interactive/components/settings-submenu.js.map +1 -1
  393. package/dist/modes/interactive/components/tool-execution.d.ts +7 -0
  394. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  395. package/dist/modes/interactive/components/tool-execution.js +48 -9
  396. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  397. package/dist/modes/interactive/components/tree-selector.d.ts +1 -0
  398. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  399. package/dist/modes/interactive/components/tree-selector.js +5 -6
  400. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  401. package/dist/modes/interactive/components/user-message-selector.d.ts +1 -0
  402. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
  403. package/dist/modes/interactive/components/user-message-selector.js +9 -1
  404. package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
  405. package/dist/modes/interactive/components/user-message.d.ts +3 -1
  406. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  407. package/dist/modes/interactive/components/user-message.js +4 -2
  408. package/dist/modes/interactive/components/user-message.js.map +1 -1
  409. package/dist/modes/interactive/editor-host.d.ts.map +1 -1
  410. package/dist/modes/interactive/editor-host.js +3 -2
  411. package/dist/modes/interactive/editor-host.js.map +1 -1
  412. package/dist/modes/interactive/external-editor.d.ts +1 -0
  413. package/dist/modes/interactive/external-editor.d.ts.map +1 -1
  414. package/dist/modes/interactive/external-editor.js +17 -5
  415. package/dist/modes/interactive/external-editor.js.map +1 -1
  416. package/dist/modes/interactive/interactive-mode.d.ts +8 -12
  417. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  418. package/dist/modes/interactive/interactive-mode.js +169 -112
  419. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  420. package/dist/modes/interactive/model-search.d.ts +10 -0
  421. package/dist/modes/interactive/model-search.d.ts.map +1 -1
  422. package/dist/modes/interactive/model-search.js +21 -0
  423. package/dist/modes/interactive/model-search.js.map +1 -1
  424. package/dist/modes/interactive/theme/theme.d.ts +10 -0
  425. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  426. package/dist/modes/interactive/theme/theme.js +30 -23
  427. package/dist/modes/interactive/theme/theme.js.map +1 -1
  428. package/dist/modes/interactive/tool-view/chat.d.ts +2 -2
  429. package/dist/modes/interactive/tool-view/chat.d.ts.map +1 -1
  430. package/dist/modes/interactive/tool-view/chat.js +22 -19
  431. package/dist/modes/interactive/tool-view/chat.js.map +1 -1
  432. package/dist/modes/interactive/transcript-layout.d.ts +2 -0
  433. package/dist/modes/interactive/transcript-layout.d.ts.map +1 -1
  434. package/dist/modes/interactive/transcript-layout.js +5 -2
  435. package/dist/modes/interactive/transcript-layout.js.map +1 -1
  436. package/dist/modes/rpc/rpc-client.d.ts +9 -1
  437. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  438. package/dist/modes/rpc/rpc-client.js +23 -23
  439. package/dist/modes/rpc/rpc-client.js.map +1 -1
  440. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  441. package/dist/modes/rpc/rpc-mode.js +0 -3
  442. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  443. package/dist/package-manager-cli.d.ts.map +1 -1
  444. package/dist/package-manager-cli.js +55 -4
  445. package/dist/package-manager-cli.js.map +1 -1
  446. package/dist/utils/ansi.d.ts.map +1 -1
  447. package/dist/utils/ansi.js +5 -2
  448. package/dist/utils/ansi.js.map +1 -1
  449. package/dist/utils/clipboard-command.d.ts.map +1 -1
  450. package/dist/utils/clipboard-command.js +4 -0
  451. package/dist/utils/clipboard-command.js.map +1 -1
  452. package/dist/utils/git.d.ts +1 -1
  453. package/dist/utils/git.d.ts.map +1 -1
  454. package/dist/utils/git.js.map +1 -1
  455. package/dist/utils/image-resize-core.d.ts.map +1 -1
  456. package/dist/utils/image-resize-core.js +5 -3
  457. package/dist/utils/image-resize-core.js.map +1 -1
  458. package/dist/utils/open-browser.d.ts.map +1 -1
  459. package/dist/utils/open-browser.js +4 -1
  460. package/dist/utils/open-browser.js.map +1 -1
  461. package/dist/utils/paths.d.ts +17 -0
  462. package/dist/utils/paths.d.ts.map +1 -1
  463. package/dist/utils/paths.js +42 -1
  464. package/dist/utils/paths.js.map +1 -1
  465. package/dist/utils/shell.d.ts.map +1 -1
  466. package/dist/utils/shell.js +14 -0
  467. package/dist/utils/shell.js.map +1 -1
  468. package/dist/utils/syntax-highlight.d.ts +5 -0
  469. package/dist/utils/syntax-highlight.d.ts.map +1 -1
  470. package/dist/utils/syntax-highlight.js +7 -0
  471. package/dist/utils/syntax-highlight.js.map +1 -1
  472. package/dist/utils/tools-manager.d.ts.map +1 -1
  473. package/dist/utils/tools-manager.js +30 -35
  474. package/dist/utils/tools-manager.js.map +1 -1
  475. package/dist/utils/usage.d.ts +5 -0
  476. package/dist/utils/usage.d.ts.map +1 -0
  477. package/dist/utils/usage.js +16 -0
  478. package/dist/utils/usage.js.map +1 -0
  479. package/docs/bundled/README.md +1 -1
  480. package/docs/bundled/extensions/agent.md +5 -5
  481. package/docs/bundled/extensions/run-summary.md +4 -4
  482. package/docs/bundled/tasks.md +2 -4
  483. package/docs/bundled/tool-presentation.md +2 -2
  484. package/docs/custom-provider.md +1 -1
  485. package/docs/environment-variables.md +2 -0
  486. package/docs/extensions.md +36 -21
  487. package/docs/keybindings.md +1 -1
  488. package/docs/llama-cpp.md +17 -12
  489. package/docs/mcp.md +6 -4
  490. package/docs/packages.md +26 -1
  491. package/docs/rpc.md +1 -1
  492. package/docs/sdk.md +7 -5
  493. package/docs/session-format.md +2 -2
  494. package/docs/sessions.md +10 -0
  495. package/docs/settings.md +5 -4
  496. package/docs/terminal-setup.md +2 -2
  497. package/docs/tmux.md +6 -0
  498. package/docs/tui.md +12 -7
  499. package/docs/usage.md +19 -9
  500. package/docs/windows.md +29 -0
  501. package/examples/extensions/README.md +2 -1
  502. package/examples/extensions/custom-provider-anthropic/index.ts +27 -31
  503. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  504. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  505. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  506. package/examples/extensions/debug-provider.ts +2 -2
  507. package/examples/extensions/gondolin/package-lock.json +19 -29
  508. package/examples/extensions/gondolin/package.json +2 -2
  509. package/examples/extensions/preset.ts +2 -0
  510. package/examples/extensions/reload-runtime.ts +17 -5
  511. package/examples/extensions/tools.ts +2 -0
  512. package/examples/extensions/with-deps/package-lock.json +2 -2
  513. package/examples/extensions/with-deps/package.json +1 -1
  514. package/package.json +9 -9
  515. package/schemas/models.schema.json +36 -36
  516. package/schemas/settings.schema.json +17 -0
  517. package/dist/bundle/chunks/anthropic-messages-HWL6AS7T.js +0 -6
  518. package/dist/bundle/chunks/azure-openai-responses-4YYPDYV5.js +0 -2
  519. package/dist/bundle/chunks/chunk-6JS2SOFO.js +0 -11
  520. package/dist/bundle/chunks/chunk-ANCZPKX7.js +0 -2
  521. package/dist/bundle/chunks/chunk-FEZ5RM2B.js +0 -2
  522. package/dist/bundle/chunks/chunk-LPF7HQ3S.js +0 -4
  523. package/dist/bundle/chunks/chunk-MMNIHCU7.js +0 -2
  524. package/dist/bundle/chunks/chunk-PUU43PDV.js +0 -1484
  525. package/dist/bundle/chunks/chunk-R267VV5T.js +0 -82
  526. package/dist/bundle/chunks/chunk-RVKT7OUB.js +0 -9
  527. package/dist/bundle/chunks/chunk-SA2AQYEI.js +0 -7
  528. package/dist/bundle/chunks/chunk-ZAIGBRV5.js +0 -16
  529. package/dist/bundle/chunks/mistral-conversations-V2JJTMJ5.js +0 -5
  530. package/dist/bundle/chunks/openai-completions-TXZXILJR.js +0 -7
  531. package/dist/bundle/chunks/pi-messages-LBJQ4NGP.js +0 -8
  532. package/dist/bundle/chunks/virtual-modules-63XNTSVN.js +0 -2
  533. package/dist/core/isolated-session.d.ts.map +0 -1
  534. package/dist/core/isolated-session.js.map +0 -1
  535. package/dist/modes/interactive/tool-view/fallback.d.ts.map +0 -1
  536. package/dist/modes/interactive/tool-view/fallback.js.map +0 -1
  537. package/dist/modes/interactive/tool-view/shell.d.ts.map +0 -1
  538. package/dist/modes/interactive/tool-view/shell.js.map +0 -1
  539. package/dist/utils/path-identity.d.ts +0 -12
  540. package/dist/utils/path-identity.d.ts.map +0 -1
  541. package/dist/utils/path-identity.js +0 -63
  542. package/dist/utils/path-identity.js.map +0 -1
  543. package/examples/extensions/sandbox/index.ts +0 -321
  544. package/examples/extensions/sandbox/package-lock.json +0 -92
  545. package/examples/extensions/sandbox/package.json +0 -19
  546. /package/dist/{modes/interactive/tool-view → extensions/tool-presentation}/fallback.d.ts +0 -0
@@ -7,11 +7,15 @@
7
7
  */
8
8
  import { Container, Text } from "@earendil-works/pi-tui";
9
9
  import { keyHint } from "../../../modes/interactive/components/keybinding-hints.js";
10
- import { getLanguageFromPath, highlightCode } from "../../../modes/interactive/theme/theme.js";
10
+ import { CodeHighlighter, getLanguageFromPath, highlightCode, } from "../../../modes/interactive/theme/theme.js";
11
11
  import { normalizeDisplayText, renderToolPath, replaceTabs, str } from "../render-utils.js";
12
12
  class WriteCallRenderComponent extends Text {
13
13
  constructor() {
14
14
  super("", 0, 0);
15
+ // A streamed call highlights its first lines on every delta, which stop changing once the file is longer, and a
16
+ // complete call highlights the whole file on every update and expand toggle. Either way the row reuses the last
17
+ // highlighting; it also holds the only copy of a complete call's displayed source.
18
+ this.highlighter = new CodeHighlighter();
15
19
  }
16
20
  }
17
21
  const WRITE_PARTIAL_FULL_HIGHLIGHT_LINES = 50;
@@ -19,12 +23,12 @@ function highlightSingleLine(line, lang) {
19
23
  const highlighted = highlightCode(line, lang);
20
24
  return highlighted[0] ?? "";
21
25
  }
22
- function refreshWriteHighlightPrefix(cache) {
26
+ function refreshWriteHighlightPrefix(cache, highlighter) {
23
27
  const prefixCount = Math.min(WRITE_PARTIAL_FULL_HIGHLIGHT_LINES, cache.normalizedLines.length);
24
28
  if (prefixCount === 0)
25
29
  return;
26
30
  const prefixSource = cache.normalizedLines.slice(0, prefixCount).join("\n");
27
- const prefixHighlighted = highlightCode(prefixSource, cache.lang);
31
+ const prefixHighlighted = highlighter.highlight(prefixSource, cache.lang);
28
32
  for (let i = 0; i < prefixCount; i++) {
29
33
  cache.highlightedLines[i] =
30
34
  prefixHighlighted[i] ?? highlightSingleLine(cache.normalizedLines[i] ?? "", cache.lang);
@@ -44,16 +48,15 @@ function rebuildWriteHighlightCacheFull(rawPath, fileContent) {
44
48
  highlightedLines: highlightCode(normalized, lang),
45
49
  };
46
50
  }
47
- function updateWriteHighlightCacheIncremental(cache, rawPath, fileContent) {
51
+ function updateWriteHighlightCacheIncremental(cache, rawPath, fileContent, highlighter) {
48
52
  const lang = rawPath ? getLanguageFromPath(rawPath) : undefined;
49
53
  if (!lang)
50
54
  return undefined;
51
55
  if (!cache)
52
56
  return rebuildWriteHighlightCacheFull(rawPath, fileContent);
53
- if (cache.lang !== lang || cache.rawPath !== rawPath)
54
- return rebuildWriteHighlightCacheFull(rawPath, fileContent);
55
- if (!fileContent.startsWith(cache.rawContent))
57
+ if (cache.lang !== lang || cache.rawPath !== rawPath || !fileContent.startsWith(cache.rawContent)) {
56
58
  return rebuildWriteHighlightCacheFull(rawPath, fileContent);
59
+ }
57
60
  if (fileContent.length === cache.rawContent.length)
58
61
  return cache;
59
62
  const deltaRaw = fileContent.slice(cache.rawContent.length);
@@ -72,7 +75,7 @@ function updateWriteHighlightCacheIncremental(cache, rawPath, fileContent) {
72
75
  cache.normalizedLines.push(segments[i]);
73
76
  cache.highlightedLines.push(highlightSingleLine(segments[i], cache.lang));
74
77
  }
75
- refreshWriteHighlightPrefix(cache);
78
+ refreshWriteHighlightPrefix(cache, highlighter);
76
79
  return cache;
77
80
  }
78
81
  function trimTrailingEmptyLines(lines) {
@@ -82,7 +85,7 @@ function trimTrailingEmptyLines(lines) {
82
85
  }
83
86
  return lines.slice(0, end);
84
87
  }
85
- function formatWriteCall(args, options, theme, cache, cwd) {
88
+ function formatWriteCall(args, options, theme, cache, highlighter, cwd) {
86
89
  const rawPath = str(args?.file_path ?? args?.path);
87
90
  const fileContent = str(args?.content);
88
91
  const pathDisplay = renderToolPath(rawPath, theme, cwd);
@@ -93,7 +96,7 @@ function formatWriteCall(args, options, theme, cache, cwd) {
93
96
  else if (fileContent) {
94
97
  const lang = rawPath ? getLanguageFromPath(rawPath) : undefined;
95
98
  const renderedLines = lang
96
- ? (cache?.highlightedLines ?? highlightCode(replaceTabs(normalizeDisplayText(fileContent)), lang))
99
+ ? (cache?.highlightedLines ?? highlighter.highlight(replaceTabs(normalizeDisplayText(fileContent)), lang))
97
100
  : normalizeDisplayText(fileContent).split("\n");
98
101
  const lines = trimTrailingEmptyLines(renderedLines);
99
102
  const totalLines = lines.length;
@@ -126,15 +129,11 @@ export const writeRenderers = {
126
129
  const rawPath = str(renderArgs?.file_path ?? renderArgs?.path);
127
130
  const fileContent = str(renderArgs?.content);
128
131
  const component = context.lastComponent ?? new WriteCallRenderComponent();
129
- if (fileContent !== null) {
130
- component.cache = context.argsComplete
131
- ? rebuildWriteHighlightCacheFull(rawPath, fileContent)
132
- : updateWriteHighlightCacheIncremental(component.cache, rawPath, fileContent);
133
- }
134
- else {
135
- component.cache = undefined;
136
- }
137
- component.setText(formatWriteCall(renderArgs, { expanded: context.expanded, isPartial: context.isPartial }, theme, component.cache, context.cwd));
132
+ component.cache =
133
+ fileContent !== null && !context.argsComplete
134
+ ? updateWriteHighlightCacheIncremental(component.cache, rawPath, fileContent, component.highlighter)
135
+ : undefined;
136
+ component.setText(formatWriteCall(renderArgs, { expanded: context.expanded, isPartial: context.isPartial }, theme, component.cache, component.highlighter, context.cwd));
138
137
  return component;
139
138
  },
140
139
  renderResult(result, _options, theme, context) {
@@ -1 +1 @@
1
- {"version":3,"file":"write.js","sourceRoot":"","sources":["../../../../src/core/tools/renderers/write.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,2DAA2D,CAAC;AACpF,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAc,MAAM,2CAA2C,CAAC;AAE3G,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAS5F,MAAM,wBAAyB,SAAQ,IAAI;IAG1C;QACC,KAAK,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACjB,CAAC;CACD;AACD,MAAM,kCAAkC,GAAG,EAAE,CAAC;AAC9C,SAAS,mBAAmB,CAAC,IAAY,EAAE,IAAY;IACtD,MAAM,WAAW,GAAG,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9C,OAAO,WAAW,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAC7B,CAAC;AACD,SAAS,2BAA2B,CAAC,KAA0B;IAC9D,MAAM,WAAW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AAC,8BAA8B,CAAC,OAAO,EAAE,WAAW,CAAC;gBACtD,CAAC,CAAC,oCAAoC,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;QAChF,CAAC;aAAM,CAAC;YACP,SAAS,CAAC,KAAK,GAAG,SAAS,CAAC;QAC7B,CAAC;QACD,SAAS,CAAC,OAAO,CAChB,eAAe,CACd,UAAU,EACV,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,EAC5D,KAAK,EACL,SAAS,CAAC,KAAK,EACf,OAAO,CAAC,GAAG,CACX,CACD,CAAC;QACF,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO;QAC5C,MAAM,MAAM,GAAG,iBAAiB,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC;QACjF,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,SAAS,GAAI,OAAO,CAAC,aAAuC,IAAI,IAAI,SAAS,EAAE,CAAC;YACtF,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,OAAO,SAAS,CAAC;QAClB,CAAC;QACD,MAAM,IAAI,GAAI,OAAO,CAAC,aAAkC,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC/E,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC;IACb,CAAC;CACD,CAAC","sourcesContent":["/**\n * Presentation for the write tool.\n *\n * Renderers live apart from the implementation so a process that only displays tool output does not\n * load the execution path or its typebox parameter schema. `write.ts` spreads these into its\n * definition, so the tool's public shape is unchanged.\n */\n\nimport { Container, Text } from \"@earendil-works/pi-tui\";\nimport { keyHint } from \"../../../modes/interactive/components/keybinding-hints.ts\";\nimport { getLanguageFromPath, highlightCode, type Theme } from \"../../../modes/interactive/theme/theme.ts\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../../extensions/types.ts\";\nimport { normalizeDisplayText, renderToolPath, replaceTabs, str } from \"../render-utils.ts\";\n\ntype WriteHighlightCache = {\n\trawPath: string | null;\n\tlang: string;\n\trawContent: string;\n\tnormalizedLines: string[];\n\thighlightedLines: string[];\n};\nclass WriteCallRenderComponent extends Text {\n\tcache?: WriteHighlightCache;\n\n\tconstructor() {\n\t\tsuper(\"\", 0, 0);\n\t}\n}\nconst WRITE_PARTIAL_FULL_HIGHLIGHT_LINES = 50;\nfunction highlightSingleLine(line: string, lang: string): string {\n\tconst highlighted = highlightCode(line, lang);\n\treturn highlighted[0] ?? \"\";\n}\nfunction refreshWriteHighlightPrefix(cache: WriteHighlightCache): void {\n\tconst prefixCount = Math.min(WRITE_PARTIAL_FULL_HIGHLIGHT_LINES, cache.normalizedLines.length);\n\tif (prefixCount === 0) return;\n\tconst prefixSource = cache.normalizedLines.slice(0, prefixCount).join(\"\\n\");\n\tconst prefixHighlighted = highlightCode(prefixSource, cache.lang);\n\tfor (let i = 0; i < prefixCount; i++) {\n\t\tcache.highlightedLines[i] =\n\t\t\tprefixHighlighted[i] ?? highlightSingleLine(cache.normalizedLines[i] ?? \"\", cache.lang);\n\t}\n}\nfunction rebuildWriteHighlightCacheFull(rawPath: string | null, fileContent: string): WriteHighlightCache | undefined {\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tif (!lang) return undefined;\n\tconst displayContent = normalizeDisplayText(fileContent);\n\tconst normalized = replaceTabs(displayContent);\n\treturn {\n\t\trawPath,\n\t\tlang,\n\t\trawContent: fileContent,\n\t\tnormalizedLines: normalized.split(\"\\n\"),\n\t\thighlightedLines: highlightCode(normalized, lang),\n\t};\n}\nfunction updateWriteHighlightCacheIncremental(\n\tcache: WriteHighlightCache | undefined,\n\trawPath: string | null,\n\tfileContent: string,\n): WriteHighlightCache | undefined {\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tif (!lang) return undefined;\n\tif (!cache) return rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\tif (cache.lang !== lang || cache.rawPath !== rawPath) return rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\tif (!fileContent.startsWith(cache.rawContent)) return rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\tif (fileContent.length === cache.rawContent.length) return cache;\n\n\tconst deltaRaw = fileContent.slice(cache.rawContent.length);\n\tconst deltaDisplay = normalizeDisplayText(deltaRaw);\n\tconst deltaNormalized = replaceTabs(deltaDisplay);\n\tcache.rawContent = fileContent;\n\tif (cache.normalizedLines.length === 0) {\n\t\tcache.normalizedLines.push(\"\");\n\t\tcache.highlightedLines.push(\"\");\n\t}\n\n\tconst segments = deltaNormalized.split(\"\\n\");\n\tconst lastIndex = cache.normalizedLines.length - 1;\n\tcache.normalizedLines[lastIndex] += segments[0];\n\tcache.highlightedLines[lastIndex] = highlightSingleLine(cache.normalizedLines[lastIndex], cache.lang);\n\tfor (let i = 1; i < segments.length; i++) {\n\t\tcache.normalizedLines.push(segments[i]);\n\t\tcache.highlightedLines.push(highlightSingleLine(segments[i], cache.lang));\n\t}\n\trefreshWriteHighlightPrefix(cache);\n\treturn cache;\n}\nfunction trimTrailingEmptyLines(lines: string[]): string[] {\n\tlet end = lines.length;\n\twhile (end > 0 && lines[end - 1] === \"\") {\n\t\tend--;\n\t}\n\treturn lines.slice(0, end);\n}\nfunction formatWriteCall(\n\targs: { path?: string; file_path?: string; content?: string } | undefined,\n\toptions: ToolRenderResultOptions,\n\ttheme: Theme,\n\tcache: WriteHighlightCache | undefined,\n\tcwd: string,\n): string {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst fileContent = str(args?.content);\n\tconst pathDisplay = renderToolPath(rawPath, theme, cwd);\n\tlet text = `${theme.fg(\"toolTitle\", theme.bold(\"write\"))} ${pathDisplay}`;\n\n\tif (fileContent === null) {\n\t\ttext += `\\n\\n${theme.fg(\"error\", \"[invalid content arg - expected string]\")}`;\n\t} else if (fileContent) {\n\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\t\tconst renderedLines = lang\n\t\t\t? (cache?.highlightedLines ?? highlightCode(replaceTabs(normalizeDisplayText(fileContent)), lang))\n\t\t\t: normalizeDisplayText(fileContent).split(\"\\n\");\n\t\tconst lines = trimTrailingEmptyLines(renderedLines);\n\t\tconst totalLines = lines.length;\n\t\tconst maxLines = options.expanded ? lines.length : 10;\n\t\tconst displayLines = lines.slice(0, maxLines);\n\t\tconst remaining = lines.length - maxLines;\n\t\ttext += `\\n\\n${displayLines.map((line) => (lang ? line : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\")}`;\n\t\tif (remaining > 0) {\n\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines, ${totalLines} total,`)} ${keyHint(\"app.tools.expand\", \"to expand\")}${theme.fg(\"muted\", \")\")}`;\n\t\t}\n\t}\n\n\treturn text;\n}\nfunction formatWriteResult(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>; isError?: boolean },\n\ttheme: Theme,\n): string | undefined {\n\tif (!result.isError) {\n\t\treturn undefined;\n\t}\n\tconst output = result.content\n\t\t.filter((c) => c.type === \"text\")\n\t\t.map((c) => c.text || \"\")\n\t\t.join(\"\\n\");\n\tif (!output) {\n\t\treturn undefined;\n\t}\n\treturn `\\n${theme.fg(\"error\", output)}`;\n}\n\nexport const writeRenderers: Pick<ToolDefinition<any, any>, \"renderCall\" | \"renderResult\"> = {\n\trenderCall(args, theme, context) {\n\t\tconst renderArgs = args as { path?: string; file_path?: string; content?: string } | undefined;\n\t\tconst rawPath = str(renderArgs?.file_path ?? renderArgs?.path);\n\t\tconst fileContent = str(renderArgs?.content);\n\t\tconst component =\n\t\t\t(context.lastComponent as WriteCallRenderComponent | undefined) ?? new WriteCallRenderComponent();\n\t\tif (fileContent !== null) {\n\t\t\tcomponent.cache = context.argsComplete\n\t\t\t\t? rebuildWriteHighlightCacheFull(rawPath, fileContent)\n\t\t\t\t: updateWriteHighlightCacheIncremental(component.cache, rawPath, fileContent);\n\t\t} else {\n\t\t\tcomponent.cache = undefined;\n\t\t}\n\t\tcomponent.setText(\n\t\t\tformatWriteCall(\n\t\t\t\trenderArgs,\n\t\t\t\t{ expanded: context.expanded, isPartial: context.isPartial },\n\t\t\t\ttheme,\n\t\t\t\tcomponent.cache,\n\t\t\t\tcontext.cwd,\n\t\t\t),\n\t\t);\n\t\treturn component;\n\t},\n\trenderResult(result, _options, theme, context) {\n\t\tconst output = formatWriteResult({ ...result, isError: context.isError }, theme);\n\t\tif (!output) {\n\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\tcomponent.clear();\n\t\t\treturn component;\n\t\t}\n\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\ttext.setText(output);\n\t\treturn text;\n\t},\n};\n"]}
1
+ {"version":3,"file":"write.js","sourceRoot":"","sources":["../../../../src/core/tools/renderers/write.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,2DAA2D,CAAC;AACpF,OAAO,EACN,eAAe,EACf,mBAAmB,EACnB,aAAa,GAEb,MAAM,2CAA2C,CAAC;AAEnD,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAS5F,MAAM,wBAAyB,SAAQ,IAAI;IAQ1C;QACC,KAAK,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QANjB,gHAAgH;QAChH,gHAAgH;QAChH,mFAAmF;QAC1E,gBAAW,GAAG,IAAI,eAAe,EAAE,CAAC;IAI7C,CAAC;CACD;AACD,MAAM,kCAAkC,GAAG,EAAE,CAAC;AA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the write tool.\n *\n * Renderers live apart from the implementation so a process that only displays tool output does not\n * load the execution path or its typebox parameter schema. `write.ts` spreads these into its\n * definition, so the tool's public shape is unchanged.\n */\n\nimport { Container, Text } from \"@earendil-works/pi-tui\";\nimport { keyHint } from \"../../../modes/interactive/components/keybinding-hints.ts\";\nimport {\n\tCodeHighlighter,\n\tgetLanguageFromPath,\n\thighlightCode,\n\ttype Theme,\n} from \"../../../modes/interactive/theme/theme.ts\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../../extensions/types.ts\";\nimport { normalizeDisplayText, renderToolPath, replaceTabs, str } from \"../render-utils.ts\";\n\ntype WriteHighlightCache = {\n\trawPath: string | null;\n\tlang: string;\n\trawContent: string;\n\tnormalizedLines: string[];\n\thighlightedLines: string[];\n};\nclass WriteCallRenderComponent extends Text {\n\t// Line by line highlighting of a call whose content is still streaming.\n\tcache?: WriteHighlightCache;\n\t// A streamed call highlights its first lines on every delta, which stop changing once the file is longer, and a\n\t// complete call highlights the whole file on every update and expand toggle. Either way the row reuses the last\n\t// highlighting; it also holds the only copy of a complete call's displayed source.\n\treadonly highlighter = new CodeHighlighter();\n\n\tconstructor() {\n\t\tsuper(\"\", 0, 0);\n\t}\n}\nconst WRITE_PARTIAL_FULL_HIGHLIGHT_LINES = 50;\nfunction highlightSingleLine(line: string, lang: string): string {\n\tconst highlighted = highlightCode(line, lang);\n\treturn highlighted[0] ?? \"\";\n}\nfunction refreshWriteHighlightPrefix(cache: WriteHighlightCache, highlighter: CodeHighlighter): void {\n\tconst prefixCount = Math.min(WRITE_PARTIAL_FULL_HIGHLIGHT_LINES, cache.normalizedLines.length);\n\tif (prefixCount === 0) return;\n\tconst prefixSource = cache.normalizedLines.slice(0, prefixCount).join(\"\\n\");\n\tconst prefixHighlighted = highlighter.highlight(prefixSource, cache.lang);\n\tfor (let i = 0; i < prefixCount; i++) {\n\t\tcache.highlightedLines[i] =\n\t\t\tprefixHighlighted[i] ?? highlightSingleLine(cache.normalizedLines[i] ?? \"\", cache.lang);\n\t}\n}\nfunction rebuildWriteHighlightCacheFull(rawPath: string | null, fileContent: string): WriteHighlightCache | undefined {\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tif (!lang) return undefined;\n\tconst displayContent = normalizeDisplayText(fileContent);\n\tconst normalized = replaceTabs(displayContent);\n\treturn {\n\t\trawPath,\n\t\tlang,\n\t\trawContent: fileContent,\n\t\tnormalizedLines: normalized.split(\"\\n\"),\n\t\thighlightedLines: highlightCode(normalized, lang),\n\t};\n}\nfunction updateWriteHighlightCacheIncremental(\n\tcache: WriteHighlightCache | undefined,\n\trawPath: string | null,\n\tfileContent: string,\n\thighlighter: CodeHighlighter,\n): WriteHighlightCache | undefined {\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tif (!lang) return undefined;\n\tif (!cache) return rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\tif (cache.lang !== lang || cache.rawPath !== rawPath || !fileContent.startsWith(cache.rawContent)) {\n\t\treturn rebuildWriteHighlightCacheFull(rawPath, fileContent);\n\t}\n\tif (fileContent.length === cache.rawContent.length) return cache;\n\n\tconst deltaRaw = fileContent.slice(cache.rawContent.length);\n\tconst deltaDisplay = normalizeDisplayText(deltaRaw);\n\tconst deltaNormalized = replaceTabs(deltaDisplay);\n\tcache.rawContent = fileContent;\n\tif (cache.normalizedLines.length === 0) {\n\t\tcache.normalizedLines.push(\"\");\n\t\tcache.highlightedLines.push(\"\");\n\t}\n\n\tconst segments = deltaNormalized.split(\"\\n\");\n\tconst lastIndex = cache.normalizedLines.length - 1;\n\tcache.normalizedLines[lastIndex] += segments[0];\n\tcache.highlightedLines[lastIndex] = highlightSingleLine(cache.normalizedLines[lastIndex], cache.lang);\n\tfor (let i = 1; i < segments.length; i++) {\n\t\tcache.normalizedLines.push(segments[i]);\n\t\tcache.highlightedLines.push(highlightSingleLine(segments[i], cache.lang));\n\t}\n\trefreshWriteHighlightPrefix(cache, highlighter);\n\treturn cache;\n}\nfunction trimTrailingEmptyLines(lines: readonly string[]): string[] {\n\tlet end = lines.length;\n\twhile (end > 0 && lines[end - 1] === \"\") {\n\t\tend--;\n\t}\n\treturn lines.slice(0, end);\n}\nfunction formatWriteCall(\n\targs: { path?: string; file_path?: string; content?: string } | undefined,\n\toptions: ToolRenderResultOptions,\n\ttheme: Theme,\n\tcache: WriteHighlightCache | undefined,\n\thighlighter: CodeHighlighter,\n\tcwd: string,\n): string {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst fileContent = str(args?.content);\n\tconst pathDisplay = renderToolPath(rawPath, theme, cwd);\n\tlet text = `${theme.fg(\"toolTitle\", theme.bold(\"write\"))} ${pathDisplay}`;\n\n\tif (fileContent === null) {\n\t\ttext += `\\n\\n${theme.fg(\"error\", \"[invalid content arg - expected string]\")}`;\n\t} else if (fileContent) {\n\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\t\tconst renderedLines = lang\n\t\t\t? (cache?.highlightedLines ?? highlighter.highlight(replaceTabs(normalizeDisplayText(fileContent)), lang))\n\t\t\t: normalizeDisplayText(fileContent).split(\"\\n\");\n\t\tconst lines = trimTrailingEmptyLines(renderedLines);\n\t\tconst totalLines = lines.length;\n\t\tconst maxLines = options.expanded ? lines.length : 10;\n\t\tconst displayLines = lines.slice(0, maxLines);\n\t\tconst remaining = lines.length - maxLines;\n\t\ttext += `\\n\\n${displayLines.map((line) => (lang ? line : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\")}`;\n\t\tif (remaining > 0) {\n\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines, ${totalLines} total,`)} ${keyHint(\"app.tools.expand\", \"to expand\")}${theme.fg(\"muted\", \")\")}`;\n\t\t}\n\t}\n\n\treturn text;\n}\nfunction formatWriteResult(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>; isError?: boolean },\n\ttheme: Theme,\n): string | undefined {\n\tif (!result.isError) {\n\t\treturn undefined;\n\t}\n\tconst output = result.content\n\t\t.filter((c) => c.type === \"text\")\n\t\t.map((c) => c.text || \"\")\n\t\t.join(\"\\n\");\n\tif (!output) {\n\t\treturn undefined;\n\t}\n\treturn `\\n${theme.fg(\"error\", output)}`;\n}\n\nexport const writeRenderers: Pick<ToolDefinition<any, any>, \"renderCall\" | \"renderResult\"> = {\n\trenderCall(args, theme, context) {\n\t\tconst renderArgs = args as { path?: string; file_path?: string; content?: string } | undefined;\n\t\tconst rawPath = str(renderArgs?.file_path ?? renderArgs?.path);\n\t\tconst fileContent = str(renderArgs?.content);\n\t\tconst component =\n\t\t\t(context.lastComponent as WriteCallRenderComponent | undefined) ?? new WriteCallRenderComponent();\n\t\tcomponent.cache =\n\t\t\tfileContent !== null && !context.argsComplete\n\t\t\t\t? updateWriteHighlightCacheIncremental(component.cache, rawPath, fileContent, component.highlighter)\n\t\t\t\t: undefined;\n\t\tcomponent.setText(\n\t\t\tformatWriteCall(\n\t\t\t\trenderArgs,\n\t\t\t\t{ expanded: context.expanded, isPartial: context.isPartial },\n\t\t\t\ttheme,\n\t\t\t\tcomponent.cache,\n\t\t\t\tcomponent.highlighter,\n\t\t\t\tcontext.cwd,\n\t\t\t),\n\t\t);\n\t\treturn component;\n\t},\n\trenderResult(result, _options, theme, context) {\n\t\tconst output = formatWriteResult({ ...result, isError: context.isError }, theme);\n\t\tif (!output) {\n\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\tcomponent.clear();\n\t\t\treturn component;\n\t\t}\n\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\ttext.setText(output);\n\t\treturn text;\n\t},\n};\n"]}
@@ -1,22 +1,29 @@
1
+ import type { AgentToolResult } from "@earendil-works/pi-agent-core";
1
2
  import type { TaskCompletion, TaskControl } from "../tasks/types.ts";
2
- import type { BashOperations, BashSpawnContext } from "./bash.ts";
3
+ import { type BashOperations } from "./bash.ts";
4
+ import { OutputAccumulator } from "./output-accumulator.ts";
3
5
  import type { BashToolDetails } from "./shell-tool.ts";
4
6
  export declare const MAX_BACKGROUND_OUTPUT_BYTES: number;
5
- interface ShellExecutionOptions {
7
+ type ShellDetails = BashToolDetails | undefined;
8
+ type ShellControl = TaskControl<ShellDetails>;
9
+ /** The parts the native body runs with when it executes as a task. */
10
+ export interface ShellTaskParts {
11
+ createOutput: () => OutputAccumulator;
12
+ operations: BashOperations;
13
+ onUpdate: (result: AgentToolResult<ShellDetails>) => void;
14
+ }
15
+ export interface ShellTaskOptions {
16
+ control: ShellControl;
6
17
  operations: BashOperations;
7
- context: BashSpawnContext;
8
18
  tempFilePrefix: string;
9
19
  timeout?: number;
10
- /** The task this command runs as; its signal cancels the process. */
11
- control: TaskControl<BashToolDetails | undefined>;
12
- /**
13
- * The command belongs to a session task, which may leave the foreground: its output log is
14
- * created and attached to the task from the first byte, and a final snapshot is always
15
- * published. Otherwise the log is created only if output is truncated.
16
- */
17
- taskLog: boolean;
20
+ /** Runs the native tool body once with the task's parts. */
21
+ execute: (parts: ShellTaskParts) => Promise<AgentToolResult<ShellDetails>>;
18
22
  }
19
- /** One process and one output owner across foreground/background handoff. */
20
- export declare function runShellCommand(options: ShellExecutionOptions): Promise<TaskCompletion<BashToolDetails | undefined>>;
23
+ /**
24
+ * One process and one output owner across foreground/background handoff. The task result holds
25
+ * the command's output only; its failure is the completion's `error`.
26
+ */
27
+ export declare function runShellTask(options: ShellTaskOptions): Promise<TaskCompletion<ShellDetails>>;
21
28
  export {};
22
29
  //# sourceMappingURL=shell-execution.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shell-execution.d.ts","sourceRoot":"","sources":["../../../src/core/tools/shell-execution.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAGlE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,i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AAY,CAAC;IACtB,UAAU,EAAE,cAAc,CAAC;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4DAA4D;IAC5D,OAAO,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,OAAO,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,CAAC;CAC3E;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CA4DnG"}
@@ -1,214 +1,196 @@
1
+ /**
2
+ * Runs the native shell tool body (`bash.ts`) as one session task. The native body owns the
3
+ * process, progress, output formatting and structured result; this adapter only supplies the
4
+ * task's output log, its background limits and acceptance, and translates the native outcome
5
+ * into a task completion.
6
+ */
1
7
  import { unlink } from "node:fs/promises";
2
8
  import { boundText } from "../tasks/output.js";
9
+ import { resolveTimeoutMs } from "./bash.js";
3
10
  import { OutputAccumulator } from "./output-accumulator.js";
4
- import { BASH_UPDATE_THROTTLE_MS } from "./renderers/bash.js";
5
- import { formatSize } from "./truncate.js";
6
11
  export const MAX_BACKGROUND_OUTPUT_BYTES = 20 * 1024 * 1024;
7
- /** Interpret the documented BashOperations error markers once, before formatting output. */
8
- function shellFailure(error) {
9
- if (error instanceof Error && error.message === "aborted")
10
- return { status: "cancelled", error: "Command aborted" };
11
- if (error instanceof Error && error.message.startsWith("timeout:"))
12
- return { status: "timeout", error: `Command timed out after ${error.message.split(":")[1]} seconds` };
13
- return { status: "failed", error: boundText(error instanceof Error ? error.message : String(error), 4096) };
14
- }
15
- function formatOutput(output, snapshot, taskLog, emptyText) {
16
- const truncation = snapshot.truncation;
17
- let text = snapshot.content || emptyText;
18
- let details = taskLog ? { fullOutputPath: snapshot.fullOutputPath } : undefined;
19
- if (truncation.truncated) {
20
- details = { truncation, fullOutputPath: snapshot.fullOutputPath };
21
- const startLine = truncation.totalLines - truncation.outputLines + 1;
22
- const endLine = truncation.totalLines;
23
- if (truncation.lastLinePartial) {
24
- const lastLineSize = formatSize(output.getLastLineBytes());
25
- text += `\n\n[Showing last ${formatSize(truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${snapshot.fullOutputPath}]`;
26
- }
27
- else if (truncation.truncatedBy === "lines") {
28
- text += `\n\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines}. Full output: ${snapshot.fullOutputPath}]`;
29
- }
30
- else {
31
- text += `\n\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines} (${formatSize(truncation.maxBytes)} limit). Full output: ${snapshot.fullOutputPath}]`;
32
- }
12
+ /** Background snapshots stay within the task result budget, so the bounded result keeps the newest output. */
13
+ const BACKGROUND_SNAPSHOT_BYTES = 40 * 1024;
14
+ const OUTPUT_LIMIT_ERROR = "Background command exceeded the 20 MiB output limit";
15
+ /**
16
+ * A session task's output: persisted from the first byte to the log attached to the task, and
17
+ * bounded once the task is background work. A write failure or the background cap cancels the
18
+ * task instead of throwing through the process's data observer.
19
+ */
20
+ class TaskOutput extends OutputAccumulator {
21
+ constructor(control, options) {
22
+ super({ ...options, persistFromStart: true });
23
+ this.control = control;
33
24
  }
34
- return { text, details };
35
- }
36
- /** One process and one output owner across foreground/background handoff. */
37
- export async function runShellCommand(options) {
38
- const { operations, context, control, taskLog, timeout } = options;
39
- const signal = control.signal;
40
- const output = new OutputAccumulator({ tempFilePrefix: options.tempFilePrefix, persistFromStart: taskLog });
41
- const startedAt = performance.now();
42
- let outputError;
43
- let acceptingOutput = true;
44
- let unsubscribe;
45
- let updateTimer;
46
- let updateDirty = false;
47
- let lastUpdateAt = 0;
48
- const failOutput = (error) => {
49
- if (outputError)
25
+ append(data) {
26
+ if (this.error)
50
27
  return;
51
- outputError = error instanceof Error ? error : new Error(String(error));
52
28
  try {
53
- control.cancel();
54
- }
55
- catch {
56
- // Late data must not throw through a process observer.
57
- }
58
- };
59
- const checkOutputLimit = () => {
60
- if (control.mode === "background" && output.getTotalBytes() > MAX_BACKGROUND_OUTPUT_BYTES) {
61
- failOutput(new Error("Background command exceeded the 20 MiB output limit"));
62
- }
63
- };
64
- const snapshot = () => output.snapshot({
65
- persistIfTruncated: true,
66
- maxBytes: control.mode === "background" ? 40 * 1024 : undefined,
67
- });
68
- const publish = (snapshot) => {
69
- const result = {
70
- content: snapshot ? [{ type: "text", text: snapshot.content }] : [],
71
- details: snapshot
72
- ? {
73
- truncation: snapshot.truncation.truncated ? snapshot.truncation : undefined,
74
- fullOutputPath: snapshot.fullOutputPath,
75
- }
76
- : undefined,
77
- };
78
- control.publish({ result });
79
- };
80
- const emitOutputUpdate = () => {
81
- if (!updateDirty)
82
- return;
83
- updateDirty = false;
84
- lastUpdateAt = Date.now();
85
- publish(snapshot());
86
- };
87
- const clearUpdateTimer = () => {
88
- if (updateTimer)
89
- clearTimeout(updateTimer);
90
- updateTimer = undefined;
91
- };
92
- const scheduleOutputUpdate = () => {
93
- updateDirty = true;
94
- const delay = BASH_UPDATE_THROTTLE_MS - (Date.now() - lastUpdateAt);
95
- if (delay <= 0) {
96
- clearUpdateTimer();
97
- emitOutputUpdate();
29
+ const room = MAX_BACKGROUND_OUTPUT_BYTES - this.getTotalBytes();
30
+ if (this.control.mode === "background" && data.length > room) {
31
+ super.append(data.subarray(0, Math.max(0, room)));
32
+ this.fail(new Error(OUTPUT_LIMIT_ERROR));
33
+ }
34
+ else
35
+ super.append(data);
98
36
  }
99
- else {
100
- updateTimer ??= setTimeout(() => {
101
- updateTimer = undefined;
102
- emitOutputUpdate();
103
- }, delay);
37
+ catch (error) {
38
+ this.fail(error);
104
39
  }
105
- };
106
- const handleData = (data) => {
107
- if (!acceptingOutput || outputError)
40
+ }
41
+ snapshot(options = {}) {
42
+ return super.snapshot(this.control.mode === "background" ? { ...options, maxBytes: BACKGROUND_SNAPSHOT_BYTES } : options);
43
+ }
44
+ /** A detach must check output written while in the foreground, preserving it. */
45
+ checkLimit() {
46
+ if (this.control.mode === "background" && this.getTotalBytes() > MAX_BACKGROUND_OUTPUT_BYTES)
47
+ this.fail(new Error(OUTPUT_LIMIT_ERROR));
48
+ }
49
+ fail(error) {
50
+ if (this.error)
108
51
  return;
52
+ this.error = error instanceof Error ? error : new Error(String(error));
109
53
  try {
110
- if (control.mode === "background" && output.getTotalBytes() + data.length > MAX_BACKGROUND_OUTPUT_BYTES) {
111
- const remaining = Math.max(0, MAX_BACKGROUND_OUTPUT_BYTES - output.getTotalBytes());
112
- output.append(data.subarray(0, remaining));
113
- failOutput(new Error("Background command exceeded the 20 MiB output limit"));
114
- }
115
- else
116
- output.append(data);
117
- scheduleOutputUpdate();
54
+ this.control.cancel();
118
55
  }
119
- catch (error) {
120
- failOutput(error);
56
+ catch {
57
+ // Late data must not throw through a process observer.
121
58
  }
59
+ }
60
+ }
61
+ /** Interpret the documented BashOperations error markers and exit codes as the native body states them. */
62
+ function processFailure(outcome) {
63
+ const { error, exitCode } = outcome;
64
+ if (error instanceof Error && error.message === "aborted")
65
+ return { status: "cancelled", error: "Command aborted" };
66
+ if (error instanceof Error && error.message.startsWith("timeout:"))
67
+ return { status: "timeout", error: `Command timed out after ${error.message.split(":")[1]} seconds` };
68
+ if (error !== undefined)
69
+ return { status: "failed", error: errorMessage(error) };
70
+ if (exitCode === null)
71
+ return { status: "failed", error: "Command terminated without an exit code" };
72
+ if (exitCode !== undefined && exitCode !== 0)
73
+ return { status: "failed", error: `Command exited with code ${exitCode}` };
74
+ return undefined;
75
+ }
76
+ function errorMessage(error) {
77
+ return boundText(error instanceof Error ? error.message : String(error), 4096);
78
+ }
79
+ /** The native body appends its failure status to the output; a task keeps them apart. */
80
+ function withoutStatus(text, status) {
81
+ if (text === status)
82
+ return "";
83
+ const suffix = `\n\n${status}`;
84
+ return text.endsWith(suffix) ? text.slice(0, -suffix.length) : text;
85
+ }
86
+ function resultText(result) {
87
+ return result.content
88
+ .filter((part) => part.type === "text")
89
+ .map((part) => part.text)
90
+ .join("\n");
91
+ }
92
+ /**
93
+ * One process and one output owner across foreground/background handoff. The task result holds
94
+ * the command's output only; its failure is the completion's `error`.
95
+ */
96
+ export async function runShellTask(options) {
97
+ const { control } = options;
98
+ if (control.signal.aborted)
99
+ throw new Error("Command aborted");
100
+ resolveTimeoutMs(options.timeout);
101
+ const output = new TaskOutput(control, { tempFilePrefix: options.tempFilePrefix });
102
+ const path = output.snapshot().fullOutputPath;
103
+ const cleanup = async () => {
104
+ await output.closeTempFile();
105
+ await unlink(path).catch((error) => {
106
+ if (error.code !== "ENOENT")
107
+ throw error;
108
+ });
122
109
  };
123
110
  try {
124
- if (taskLog) {
125
- const path = output.snapshot().fullOutputPath;
126
- const cleanup = async () => {
127
- await output.closeTempFile();
128
- await unlink(path).catch((error) => {
129
- if (error.code !== "ENOENT")
130
- throw error;
131
- });
132
- };
111
+ control.attachOutput(path, cleanup);
112
+ }
113
+ catch (error) {
114
+ await cleanup();
115
+ throw error;
116
+ }
117
+ const unsubscribe = control.onModeChange(() => output.checkLimit());
118
+ const spawned = {};
119
+ const operations = {
120
+ exec: (command, cwd, execOptions) => {
121
+ let running;
133
122
  try {
134
- control.attachOutput(path, cleanup);
123
+ running = options.operations.exec(command, cwd, execOptions);
135
124
  }
136
125
  catch (error) {
137
- await cleanup();
126
+ spawned.error = error;
138
127
  throw error;
139
128
  }
140
- }
141
- // Detach must check a silent foreground log too, preserving bytes already written.
142
- unsubscribe = control.onModeChange(checkOutputLimit);
143
- publish();
144
- let failure;
145
- let exitCode;
129
+ // The process exists, so a handoff can no longer start it twice.
130
+ control.accept();
131
+ return running.then((result) => {
132
+ spawned.exitCode = result.exitCode;
133
+ return result;
134
+ }, (error) => {
135
+ spawned.error = error;
136
+ throw error;
137
+ });
138
+ },
139
+ };
140
+ let result;
141
+ let thrown;
142
+ try {
146
143
  try {
147
- if (signal?.aborted)
148
- throw new Error("aborted");
149
- const execution = operations.exec(context.command, context.cwd, {
150
- onData: handleData,
151
- signal,
152
- timeout,
153
- env: context.env,
144
+ result = await options.execute({
145
+ createOutput: () => output,
146
+ operations,
147
+ onUpdate: (update) => control.publish({ result: update }),
154
148
  });
155
- control.accept();
156
- ({ exitCode } = await execution);
157
- if (exitCode === null) {
158
- failure = { status: "failed", error: "Command terminated without an exit code" };
159
- }
160
- else if (exitCode !== 0) {
161
- failure = { status: "failed", error: `Command exited with code ${exitCode}` };
162
- }
163
149
  }
164
150
  catch (error) {
165
- failure = shellFailure(error);
151
+ thrown = error;
166
152
  }
167
- acceptingOutput = false;
168
- output.finish();
169
- clearUpdateTimer();
170
- if (taskLog)
171
- publish(snapshot());
172
- else
173
- emitOutputUpdate();
174
- const final = snapshot();
175
- await output.closeTempFile();
176
- // Final progress/cleanup can re-enter handoff. Classify policy cancellation
177
- // after those callbacks, independently of the process's abort marker.
178
- if (outputError)
179
- failure = { status: "failed", error: boundText(outputError.message, 4096) };
180
- const { text, details } = formatOutput(output, final, taskLog, failure ? "" : "(no output)");
181
- const fullOutput = typeof exitCode === "number" && !outputError ? await output.readFullOutput(1024 * 1024) : undefined;
182
- return {
183
- status: failure?.status,
184
- error: failure?.error,
185
- ...(exitCode !== undefined ? { facts: [["Exit", exitCode === null ? "signal" : String(exitCode)]] } : {}),
186
- result: {
187
- ...(fullOutput && typeof exitCode === "number"
188
- ? {
189
- structuredContent: {
190
- output: fullOutput.content,
191
- truncated: fullOutput.truncated,
192
- ...(fullOutput.truncated && final.fullOutputPath
193
- ? { full_output_path: final.fullOutputPath }
194
- : {}),
195
- exit_code: exitCode,
196
- wall_time_seconds: Math.round((performance.now() - startedAt) / 100) / 10,
197
- },
198
- ...(failure ? { isError: true } : {}),
199
- }
200
- : {}),
201
- // The command's output only: its failure is the completion's `error`, composed where a result is shown.
202
- content: [{ type: "text", text }],
203
- details,
204
- },
205
- };
206
153
  }
207
154
  finally {
208
- acceptingOutput = false;
209
- unsubscribe?.();
210
- clearUpdateTimer();
155
+ unsubscribe();
211
156
  await output.closeTempFile();
212
157
  }
158
+ return shellCompletion(output, path, spawned, result, thrown);
159
+ }
160
+ function shellCompletion(output, path, spawned, result, thrown) {
161
+ const started = "exitCode" in spawned || "error" in spawned;
162
+ const failure = processFailure(spawned) ?? (thrown === undefined ? undefined : { status: "failed", error: errorMessage(thrown) });
163
+ // The native result or error carries the formatted output; a raw operations error carries none.
164
+ const formatted = result !== undefined
165
+ ? resultText(result)
166
+ : thrown instanceof Error && thrown !== spawned.error && started
167
+ ? thrown.message
168
+ : started
169
+ ? output.snapshot().content
170
+ : "";
171
+ const text = failure ? withoutStatus(formatted, failure.error) : formatted;
172
+ const truncation = output.snapshot().truncation;
173
+ const details = {
174
+ ...(result?.details ?? (truncation.truncated ? { truncation } : {})),
175
+ fullOutputPath: path,
176
+ };
177
+ // A cancellation the output policy caused is that policy's failure, not the process's abort.
178
+ const policy = output.error ? { status: "failed", error: errorMessage(output.error) } : undefined;
179
+ const settled = policy ?? failure;
180
+ const keepStructured = result?.structuredContent !== undefined && !policy;
181
+ return {
182
+ status: settled?.status,
183
+ error: settled?.error,
184
+ ...(spawned.exitCode !== undefined
185
+ ? { facts: [["Exit", spawned.exitCode === null ? "signal" : String(spawned.exitCode)]] }
186
+ : {}),
187
+ result: {
188
+ ...(keepStructured
189
+ ? { structuredContent: result.structuredContent, ...(settled ? { isError: true } : {}) }
190
+ : {}),
191
+ content: [{ type: "text", text }],
192
+ details,
193
+ },
194
+ };
213
195
  }
214
196
  //# sourceMappingURL=shell-execution.js.map