@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
@@ -1 +1 @@
1
- {"version":3,"file":"shell-execution.js","sourceRoot":"","sources":["../../../src/core/tools/shell-execution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG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C,GAAG,EAAE;yBACzE;wBACD,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;qBACrC;oBACF,CAAC,CAAC,EAAE,CAAC;gBACN,wGAAwG;gBACxG,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;gBACjC,OAAO;aACP;SACD,CAAC;IACH,CAAC;YAAS,CAAC;QACV,eAAe,GAAG,KAAK,CAAC;QACxB,WAAW,EAAE,EAAE,CAAC;QAChB,gBAAgB,EAAE,CAAC;QACnB,MAAM,MAAM,CAAC,aAAa,EAAE,CAAC;IAC9B,CAAC;AACF,CAAC","sourcesContent":["import { unlink } from \"node:fs/promises\";\nimport type { AgentToolResult } from \"@earendil-works/pi-agent-core\";\nimport { boundText } from \"../tasks/output.ts\";\nimport type { TaskCompletion, TaskControl } from \"../tasks/types.ts\";\nimport type { BashOperations, BashSpawnContext } from \"./bash.ts\";\nimport { OutputAccumulator, type OutputSnapshot } from \"./output-accumulator.ts\";\nimport { BASH_UPDATE_THROTTLE_MS } from \"./renderers/bash.ts\";\nimport type { BashToolDetails } from \"./shell-tool.ts\";\nimport { formatSize } from \"./truncate.ts\";\n\nexport const MAX_BACKGROUND_OUTPUT_BYTES = 20 * 1024 * 1024;\n\ninterface ShellExecutionOptions {\n\toperations: BashOperations;\n\tcontext: BashSpawnContext;\n\ttempFilePrefix: string;\n\ttimeout?: number;\n\t/** The task this command runs as; its signal cancels the process. */\n\tcontrol: TaskControl<BashToolDetails | undefined>;\n\t/**\n\t * The command belongs to a session task, which may leave the foreground: its output log is\n\t * created and attached to the task from the first byte, and a final snapshot is always\n\t * published. Otherwise the log is created only if output is truncated.\n\t */\n\ttaskLog: boolean;\n}\n\ninterface ShellFailure {\n\tstatus: \"failed\" | \"cancelled\" | \"timeout\";\n\terror: string;\n}\n\n/** Interpret the documented BashOperations error markers once, before formatting output. */\nfunction shellFailure(error: unknown): ShellFailure {\n\tif (error instanceof Error && error.message === \"aborted\") return { status: \"cancelled\", error: \"Command aborted\" };\n\tif (error instanceof Error && error.message.startsWith(\"timeout:\"))\n\t\treturn { status: \"timeout\", error: `Command timed out after ${error.message.split(\":\")[1]} seconds` };\n\treturn { status: \"failed\", error: boundText(error instanceof Error ? error.message : String(error), 4096) };\n}\n\nfunction formatOutput(\n\toutput: OutputAccumulator,\n\tsnapshot: OutputSnapshot,\n\ttaskLog: boolean,\n\temptyText: string,\n): { text: string; details: BashToolDetails | undefined } {\n\tconst truncation = snapshot.truncation;\n\tlet text = snapshot.content || emptyText;\n\tlet details: BashToolDetails | undefined = taskLog ? { fullOutputPath: snapshot.fullOutputPath } : undefined;\n\tif (truncation.truncated) {\n\t\tdetails = { truncation, fullOutputPath: snapshot.fullOutputPath };\n\t\tconst startLine = truncation.totalLines - truncation.outputLines + 1;\n\t\tconst endLine = truncation.totalLines;\n\t\tif (truncation.lastLinePartial) {\n\t\t\tconst lastLineSize = formatSize(output.getLastLineBytes());\n\t\t\ttext += `\\n\\n[Showing last ${formatSize(truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${snapshot.fullOutputPath}]`;\n\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines}. Full output: ${snapshot.fullOutputPath}]`;\n\t\t} else {\n\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines} (${formatSize(truncation.maxBytes)} limit). Full output: ${snapshot.fullOutputPath}]`;\n\t\t}\n\t}\n\treturn { text, details };\n}\n\n/** One process and one output owner across foreground/background handoff. */\nexport async function runShellCommand(\n\toptions: ShellExecutionOptions,\n): Promise<TaskCompletion<BashToolDetails | undefined>> {\n\tconst { operations, context, control, taskLog, timeout } = options;\n\tconst signal = control.signal;\n\tconst output = new OutputAccumulator({ tempFilePrefix: options.tempFilePrefix, persistFromStart: taskLog });\n\tconst startedAt = performance.now();\n\tlet outputError: Error | undefined;\n\tlet acceptingOutput = true;\n\tlet unsubscribe: (() => void) | undefined;\n\tlet updateTimer: NodeJS.Timeout | undefined;\n\tlet updateDirty = false;\n\tlet lastUpdateAt = 0;\n\n\tconst failOutput = (error: unknown) => {\n\t\tif (outputError) return;\n\t\toutputError = error instanceof Error ? error : new Error(String(error));\n\t\ttry {\n\t\t\tcontrol.cancel();\n\t\t} catch {\n\t\t\t// Late data must not throw through a process observer.\n\t\t}\n\t};\n\tconst checkOutputLimit = () => {\n\t\tif (control.mode === \"background\" && output.getTotalBytes() > MAX_BACKGROUND_OUTPUT_BYTES) {\n\t\t\tfailOutput(new Error(\"Background command exceeded the 20 MiB output limit\"));\n\t\t}\n\t};\n\tconst snapshot = () =>\n\t\toutput.snapshot({\n\t\t\tpersistIfTruncated: true,\n\t\t\tmaxBytes: control.mode === \"background\" ? 40 * 1024 : undefined,\n\t\t});\n\tconst publish = (snapshot?: OutputSnapshot) => {\n\t\tconst result: AgentToolResult<BashToolDetails | undefined> = {\n\t\t\tcontent: snapshot ? [{ type: \"text\", text: snapshot.content }] : [],\n\t\t\tdetails: snapshot\n\t\t\t\t? {\n\t\t\t\t\t\ttruncation: snapshot.truncation.truncated ? snapshot.truncation : undefined,\n\t\t\t\t\t\tfullOutputPath: snapshot.fullOutputPath,\n\t\t\t\t\t}\n\t\t\t\t: undefined,\n\t\t};\n\t\tcontrol.publish({ result });\n\t};\n\tconst emitOutputUpdate = () => {\n\t\tif (!updateDirty) return;\n\t\tupdateDirty = false;\n\t\tlastUpdateAt = Date.now();\n\t\tpublish(snapshot());\n\t};\n\tconst clearUpdateTimer = () => {\n\t\tif (updateTimer) clearTimeout(updateTimer);\n\t\tupdateTimer = undefined;\n\t};\n\tconst scheduleOutputUpdate = () => {\n\t\tupdateDirty = true;\n\t\tconst delay = BASH_UPDATE_THROTTLE_MS - (Date.now() - lastUpdateAt);\n\t\tif (delay <= 0) {\n\t\t\tclearUpdateTimer();\n\t\t\temitOutputUpdate();\n\t\t} else {\n\t\t\tupdateTimer ??= setTimeout(() => {\n\t\t\t\tupdateTimer = undefined;\n\t\t\t\temitOutputUpdate();\n\t\t\t}, delay);\n\t\t}\n\t};\n\tconst handleData = (data: Buffer) => {\n\t\tif (!acceptingOutput || outputError) return;\n\t\ttry {\n\t\t\tif (control.mode === \"background\" && output.getTotalBytes() + data.length > MAX_BACKGROUND_OUTPUT_BYTES) {\n\t\t\t\tconst remaining = Math.max(0, MAX_BACKGROUND_OUTPUT_BYTES - output.getTotalBytes());\n\t\t\t\toutput.append(data.subarray(0, remaining));\n\t\t\t\tfailOutput(new Error(\"Background command exceeded the 20 MiB output limit\"));\n\t\t\t} else output.append(data);\n\t\t\tscheduleOutputUpdate();\n\t\t} catch (error) {\n\t\t\tfailOutput(error);\n\t\t}\n\t};\n\n\ttry {\n\t\tif (taskLog) {\n\t\t\tconst path = output.snapshot().fullOutputPath!;\n\t\t\tconst cleanup = async () => {\n\t\t\t\tawait output.closeTempFile();\n\t\t\t\tawait unlink(path).catch((error: NodeJS.ErrnoException) => {\n\t\t\t\t\tif (error.code !== \"ENOENT\") throw error;\n\t\t\t\t});\n\t\t\t};\n\t\t\ttry {\n\t\t\t\tcontrol.attachOutput(path, cleanup);\n\t\t\t} catch (error) {\n\t\t\t\tawait cleanup();\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\t// Detach must check a silent foreground log too, preserving bytes already written.\n\t\tunsubscribe = control.onModeChange(checkOutputLimit);\n\t\tpublish();\n\t\tlet failure: ShellFailure | undefined;\n\t\tlet exitCode: number | null | undefined;\n\t\ttry {\n\t\t\tif (signal?.aborted) throw new Error(\"aborted\");\n\t\t\tconst execution = operations.exec(context.command, context.cwd, {\n\t\t\t\tonData: handleData,\n\t\t\t\tsignal,\n\t\t\t\ttimeout,\n\t\t\t\tenv: context.env,\n\t\t\t});\n\t\t\tcontrol.accept();\n\t\t\t({ exitCode } = await execution);\n\t\t\tif (exitCode === null) {\n\t\t\t\tfailure = { status: \"failed\", error: \"Command terminated without an exit code\" };\n\t\t\t} else if (exitCode !== 0) {\n\t\t\t\tfailure = { status: \"failed\", error: `Command exited with code ${exitCode}` };\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tfailure = shellFailure(error);\n\t\t}\n\t\tacceptingOutput = false;\n\t\toutput.finish();\n\t\tclearUpdateTimer();\n\t\tif (taskLog) publish(snapshot());\n\t\telse emitOutputUpdate();\n\t\tconst final = snapshot();\n\t\tawait output.closeTempFile();\n\t\t// Final progress/cleanup can re-enter handoff. Classify policy cancellation\n\t\t// after those callbacks, independently of the process's abort marker.\n\t\tif (outputError) failure = { status: \"failed\", error: boundText(outputError.message, 4096) };\n\t\tconst { text, details } = formatOutput(output, final, taskLog, failure ? \"\" : \"(no output)\");\n\t\tconst fullOutput =\n\t\t\ttypeof exitCode === \"number\" && !outputError ? await output.readFullOutput(1024 * 1024) : undefined;\n\t\treturn {\n\t\t\tstatus: failure?.status,\n\t\t\terror: failure?.error,\n\t\t\t...(exitCode !== undefined ? { facts: [[\"Exit\", exitCode === null ? \"signal\" : String(exitCode)]] } : {}),\n\t\t\tresult: {\n\t\t\t\t...(fullOutput && typeof exitCode === \"number\"\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tstructuredContent: {\n\t\t\t\t\t\t\t\toutput: fullOutput.content,\n\t\t\t\t\t\t\t\ttruncated: fullOutput.truncated,\n\t\t\t\t\t\t\t\t...(fullOutput.truncated && final.fullOutputPath\n\t\t\t\t\t\t\t\t\t? { full_output_path: final.fullOutputPath }\n\t\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\t\texit_code: exitCode,\n\t\t\t\t\t\t\t\twall_time_seconds: Math.round((performance.now() - startedAt) / 100) / 10,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t...(failure ? { isError: true } : {}),\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\t// The command's output only: its failure is the completion's `error`, composed where a result is shown.\n\t\t\t\tcontent: [{ type: \"text\", text }],\n\t\t\t\tdetails,\n\t\t\t},\n\t\t};\n\t} finally {\n\t\tacceptingOutput = false;\n\t\tunsubscribe?.();\n\t\tclearUpdateTimer();\n\t\tawait output.closeTempFile();\n\t}\n}\n"]}
1
+ {"version":3,"file":"shell-execution.js","sourceRoot":"","sources":["../../../src/core/tools/shell-execution.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAuB,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAsD,MAAM,yBAAyB,CAAC;AAGhH,MAAM,CAAC,MAAM,2BAA2B,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAC5D,8GAA8G;AAC9G,MAAM,yBAAyB,GAAG,EAAE,GAAG,IAAI,CAAC;AAC5C,MAAM,kBAAkB,GAAG,qDAAqD,CAAC;AAKjF;;;;GAIG;AACH,MAAM,UAAW,SAAQ,iBAAiB;IAIzC,YAAY,OAAqB,EAAE,OAAiC;QACnE,KAAK,CAAC,EAAE,GAAG,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC,CAAC;QAC9C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAEQ,MAAM,CAAC,IAAY;QAC3B,IAAI,IAAI,CAAC,KAAK;YAAE,OAAO;QACvB,IAAI,CAAC;YACJ,MAAM,IAAI,GAAG,2BAA2B,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;YAChE,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,YAAY,IAAI,IAAI,CAAC,MAAM,GAAG,IAAI,EAAE,CAAC;gBAC9D,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAA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,cAAc,EAAE,IAAI;KACpB,CAAC;IACF,6FAA6F;IAC7F,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,QAAiB,EAAE,KAAK,EAAE,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3G,MAAM,OAAO,GAAG,MAAM,IAAI,OAAO,CAAC;IAClC,MAAM,cAAc,GAAG,MAAM,EAAE,iBAAiB,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC;IAC1E,OAAO;QACN,MAAM,EAAE,OAAO,EAAE,MAAM;QACvB,KAAK,EAAE,OAAO,EAAE,KAAK;QACrB,GAAG,CAAC,OAAO,CAAC,QAAQ,KAAK,SAAS;YACjC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE;YACxF,CAAC,CAAC,EAAE,CAAC;QACN,MAAM,EAAE;YACP,GAAG,CAAC,cAAc;gBACjB,CAAC,CAAC,EAAE,iBAAiB,EAAE,MAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE;gBACzF,CAAC,CAAC,EAAE,CAAC;YACN,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;YACjC,OAAO;SACP;KACD,CAAC;AACH,CAAC","sourcesContent":["/**\n * Runs the native shell tool body (`bash.ts`) as one session task. The native body owns the\n * process, progress, output formatting and structured result; this adapter only supplies the\n * task's output log, its background limits and acceptance, and translates the native outcome\n * into a task completion.\n */\nimport { unlink } from \"node:fs/promises\";\nimport type { AgentToolResult } from \"@earendil-works/pi-agent-core\";\nimport { boundText } from \"../tasks/output.ts\";\nimport type { TaskCompletion, TaskControl, TaskTerminalStatus } from \"../tasks/types.ts\";\nimport { type BashOperations, resolveTimeoutMs } from \"./bash.ts\";\nimport { OutputAccumulator, type OutputAccumulatorOptions, type OutputSnapshot } from \"./output-accumulator.ts\";\nimport type { BashToolDetails } from \"./shell-tool.ts\";\n\nexport const MAX_BACKGROUND_OUTPUT_BYTES = 20 * 1024 * 1024;\n/** Background snapshots stay within the task result budget, so the bounded result keeps the newest output. */\nconst BACKGROUND_SNAPSHOT_BYTES = 40 * 1024;\nconst OUTPUT_LIMIT_ERROR = \"Background command exceeded the 20 MiB output limit\";\n\ntype ShellDetails = BashToolDetails | undefined;\ntype ShellControl = TaskControl<ShellDetails>;\n\n/**\n * A session task's output: persisted from the first byte to the log attached to the task, and\n * bounded once the task is background work. A write failure or the background cap cancels the\n * task instead of throwing through the process's data observer.\n */\nclass TaskOutput extends OutputAccumulator {\n\terror?: Error;\n\tprivate readonly control: ShellControl;\n\n\tconstructor(control: ShellControl, options: OutputAccumulatorOptions) {\n\t\tsuper({ ...options, persistFromStart: true });\n\t\tthis.control = control;\n\t}\n\n\toverride append(data: Buffer): void {\n\t\tif (this.error) return;\n\t\ttry {\n\t\t\tconst room = MAX_BACKGROUND_OUTPUT_BYTES - this.getTotalBytes();\n\t\t\tif (this.control.mode === \"background\" && data.length > room) {\n\t\t\t\tsuper.append(data.subarray(0, Math.max(0, room)));\n\t\t\t\tthis.fail(new Error(OUTPUT_LIMIT_ERROR));\n\t\t\t} else super.append(data);\n\t\t} catch (error) {\n\t\t\tthis.fail(error);\n\t\t}\n\t}\n\n\toverride snapshot(options: Parameters<OutputAccumulator[\"snapshot\"]>[0] = {}): OutputSnapshot {\n\t\treturn super.snapshot(\n\t\t\tthis.control.mode === \"background\" ? { ...options, maxBytes: BACKGROUND_SNAPSHOT_BYTES } : options,\n\t\t);\n\t}\n\n\t/** A detach must check output written while in the foreground, preserving it. */\n\tcheckLimit(): void {\n\t\tif (this.control.mode === \"background\" && this.getTotalBytes() > MAX_BACKGROUND_OUTPUT_BYTES)\n\t\t\tthis.fail(new Error(OUTPUT_LIMIT_ERROR));\n\t}\n\n\tprivate fail(error: unknown): void {\n\t\tif (this.error) return;\n\t\tthis.error = error instanceof Error ? error : new Error(String(error));\n\t\ttry {\n\t\t\tthis.control.cancel();\n\t\t} catch {\n\t\t\t// Late data must not throw through a process observer.\n\t\t}\n\t}\n}\n\ninterface ShellFailure {\n\tstatus: Extract<TaskTerminalStatus, \"failed\" | \"cancelled\" | \"timeout\">;\n\terror: string;\n}\n\n/** What the process itself reported, recorded before the native body formats it. */\ninterface ProcessOutcome {\n\texitCode?: number | null;\n\terror?: unknown;\n}\n\n/** Interpret the documented BashOperations error markers and exit codes as the native body states them. */\nfunction processFailure(outcome: ProcessOutcome): ShellFailure | undefined {\n\tconst { error, exitCode } = outcome;\n\tif (error instanceof Error && error.message === \"aborted\") return { status: \"cancelled\", error: \"Command aborted\" };\n\tif (error instanceof Error && error.message.startsWith(\"timeout:\"))\n\t\treturn { status: \"timeout\", error: `Command timed out after ${error.message.split(\":\")[1]} seconds` };\n\tif (error !== undefined) return { status: \"failed\", error: errorMessage(error) };\n\tif (exitCode === null) return { status: \"failed\", error: \"Command terminated without an exit code\" };\n\tif (exitCode !== undefined && exitCode !== 0)\n\t\treturn { status: \"failed\", error: `Command exited with code ${exitCode}` };\n\treturn undefined;\n}\n\nfunction errorMessage(error: unknown): string {\n\treturn boundText(error instanceof Error ? error.message : String(error), 4096);\n}\n\n/** The native body appends its failure status to the output; a task keeps them apart. */\nfunction withoutStatus(text: string, status: string): string {\n\tif (text === status) return \"\";\n\tconst suffix = `\\n\\n${status}`;\n\treturn text.endsWith(suffix) ? text.slice(0, -suffix.length) : text;\n}\n\nfunction resultText(result: AgentToolResult<ShellDetails>): string {\n\treturn result.content\n\t\t.filter((part) => part.type === \"text\")\n\t\t.map((part) => part.text)\n\t\t.join(\"\\n\");\n}\n\n/** The parts the native body runs with when it executes as a task. */\nexport interface ShellTaskParts {\n\tcreateOutput: () => OutputAccumulator;\n\toperations: BashOperations;\n\tonUpdate: (result: AgentToolResult<ShellDetails>) => void;\n}\n\nexport interface ShellTaskOptions {\n\tcontrol: ShellControl;\n\toperations: BashOperations;\n\ttempFilePrefix: string;\n\ttimeout?: number;\n\t/** Runs the native tool body once with the task's parts. */\n\texecute: (parts: ShellTaskParts) => Promise<AgentToolResult<ShellDetails>>;\n}\n\n/**\n * One process and one output owner across foreground/background handoff. The task result holds\n * the command's output only; its failure is the completion's `error`.\n */\nexport async function runShellTask(options: ShellTaskOptions): Promise<TaskCompletion<ShellDetails>> {\n\tconst { control } = options;\n\tif (control.signal.aborted) throw new Error(\"Command aborted\");\n\tresolveTimeoutMs(options.timeout);\n\tconst output = new TaskOutput(control, { tempFilePrefix: options.tempFilePrefix });\n\tconst path = output.snapshot().fullOutputPath!;\n\tconst cleanup = async () => {\n\t\tawait output.closeTempFile();\n\t\tawait unlink(path).catch((error: NodeJS.ErrnoException) => {\n\t\t\tif (error.code !== \"ENOENT\") throw error;\n\t\t});\n\t};\n\ttry {\n\t\tcontrol.attachOutput(path, cleanup);\n\t} catch (error) {\n\t\tawait cleanup();\n\t\tthrow error;\n\t}\n\tconst unsubscribe = control.onModeChange(() => output.checkLimit());\n\tconst spawned: ProcessOutcome = {};\n\tconst operations: BashOperations = {\n\t\texec: (command, cwd, execOptions) => {\n\t\t\tlet running: ReturnType<BashOperations[\"exec\"]>;\n\t\t\ttry {\n\t\t\t\trunning = options.operations.exec(command, cwd, execOptions);\n\t\t\t} catch (error) {\n\t\t\t\tspawned.error = error;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\t// The process exists, so a handoff can no longer start it twice.\n\t\t\tcontrol.accept();\n\t\t\treturn running.then(\n\t\t\t\t(result) => {\n\t\t\t\t\tspawned.exitCode = result.exitCode;\n\t\t\t\t\treturn result;\n\t\t\t\t},\n\t\t\t\t(error: unknown) => {\n\t\t\t\t\tspawned.error = error;\n\t\t\t\t\tthrow error;\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t};\n\tlet result: AgentToolResult<ShellDetails> | undefined;\n\tlet thrown: unknown;\n\ttry {\n\t\ttry {\n\t\t\tresult = await options.execute({\n\t\t\t\tcreateOutput: () => output,\n\t\t\t\toperations,\n\t\t\t\tonUpdate: (update) => control.publish({ result: update }),\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tthrown = error;\n\t\t}\n\t} finally {\n\t\tunsubscribe();\n\t\tawait output.closeTempFile();\n\t}\n\treturn shellCompletion(output, path, spawned, result, thrown);\n}\n\nfunction shellCompletion(\n\toutput: TaskOutput,\n\tpath: string,\n\tspawned: ProcessOutcome,\n\tresult: AgentToolResult<ShellDetails> | undefined,\n\tthrown: unknown,\n): TaskCompletion<ShellDetails> {\n\tconst started = \"exitCode\" in spawned || \"error\" in spawned;\n\tconst failure =\n\t\tprocessFailure(spawned) ?? (thrown === undefined ? undefined : { status: \"failed\", error: errorMessage(thrown) });\n\t// The native result or error carries the formatted output; a raw operations error carries none.\n\tconst formatted =\n\t\tresult !== undefined\n\t\t\t? resultText(result)\n\t\t\t: thrown instanceof Error && thrown !== spawned.error && started\n\t\t\t\t? thrown.message\n\t\t\t\t: started\n\t\t\t\t\t? output.snapshot().content\n\t\t\t\t\t: \"\";\n\tconst text = failure ? withoutStatus(formatted, failure.error) : formatted;\n\tconst truncation = output.snapshot().truncation;\n\tconst details: BashToolDetails = {\n\t\t...(result?.details ?? (truncation.truncated ? { truncation } : {})),\n\t\tfullOutputPath: path,\n\t};\n\t// A cancellation the output policy caused is that policy's failure, not the process's abort.\n\tconst policy = output.error ? { status: \"failed\" as const, error: errorMessage(output.error) } : undefined;\n\tconst settled = policy ?? failure;\n\tconst keepStructured = result?.structuredContent !== undefined && !policy;\n\treturn {\n\t\tstatus: settled?.status,\n\t\terror: settled?.error,\n\t\t...(spawned.exitCode !== undefined\n\t\t\t? { facts: [[\"Exit\", spawned.exitCode === null ? \"signal\" : String(spawned.exitCode)]] }\n\t\t\t: {}),\n\t\tresult: {\n\t\t\t...(keepStructured\n\t\t\t\t? { structuredContent: result!.structuredContent, ...(settled ? { isError: true } : {}) }\n\t\t\t\t: {}),\n\t\t\tcontent: [{ type: \"text\", text }],\n\t\t\tdetails,\n\t\t},\n\t};\n}\n"]}
@@ -1,37 +1,32 @@
1
+ /**
2
+ * The managed shell tools: the native shell definition (`bash.ts`) plus a `background` parameter,
3
+ * adapted to the session's Tasks. The native body stays the one owner of execution, progress,
4
+ * output formatting and results; outside a session it runs unchanged.
5
+ */
1
6
  import { type Static, Type } from "typebox";
2
7
  import type { ToolDefinition } from "../extensions/types.ts";
3
- import { type BashOperations, type BashToolOptions, type ShellToolConfig } from "./bash.ts";
4
- import { type TruncationResult } from "./truncate.ts";
8
+ import { type BashOperations, type BashRenderState, type BashToolOptions, type BashToolDetails as NativeBashToolDetails, type ShellToolConfig } from "./bash.ts";
5
9
  declare const bashSchema: Type.TObject<{
10
+ background: Type.TOptional<Type.TBoolean>;
6
11
  command: Type.TString;
7
12
  timeout: Type.TOptional<Type.TNumber>;
8
- background: Type.TOptional<Type.TBoolean>;
9
13
  }>;
10
14
  export declare const bashToolSystemPromptContribution: {
11
15
  readonly snippet: "Execute bash commands, foreground or background";
12
16
  readonly guidelines: readonly ["You can inspect PI_* environment variables for current model and session details."];
13
17
  };
14
18
  export type BashToolInput = Static<typeof bashSchema>;
15
- export interface BashToolDetails {
16
- truncation?: TruncationResult;
17
- fullOutputPath?: string;
19
+ export interface BashToolDetails extends NativeBashToolDetails {
18
20
  /** Settled handoff snapshot, not a command completion or exit code. */
19
21
  background?: {
20
22
  kind: "background";
21
23
  taskId: string;
22
24
  };
23
25
  }
24
- export type BashRenderState = {
25
- dispose?: () => void;
26
- };
27
26
  export declare function createShellToolDefinition(cwd: string, config: ShellToolConfig, options: BashToolOptions & {
28
27
  operations: BashOperations;
29
28
  }): ToolDefinition<typeof bashSchema, BashToolDetails | undefined, BashRenderState>;
30
29
  export declare function createBashToolDefinition(cwd: string, options?: BashToolOptions): ReturnType<typeof createShellToolDefinition>;
31
- export declare function createBashTool(cwd: string, options?: BashToolOptions): import("@earendil-works/pi-agent-core").AgentTool<Type.TObject<{
32
- command: Type.TString;
33
- timeout: Type.TOptional<Type.TNumber>;
34
- background: Type.TOptional<Type.TBoolean>;
35
- }>, BashToolDetails | undefined>;
30
+ export declare function createBashTool(cwd: string, options?: BashToolOptions): import("@earendil-works/pi-agent-core").AgentTool<any, BashToolDetails | undefined>;
36
31
  export {};
37
32
  //# sourceMappingURL=shell-tool.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shell-tool.d.ts","sourceRoot":"","sources":["../../../src/core/tools/shell-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAoB,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG/E,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,eAAe,EAGpB,KAAK,eAAe,EACpB,MAAM,WAAW,CAAC;AAKnB,OAAO,EAAwC,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAE5F,QAAA,MAAM,UAAU;;;;EASd,CAAC;AAEH,eAAO,MAAM,gCAAgC;;;CAGnC,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAetD,MAAM,WAAW,eAAe;IAC/B,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,uEAAuE;IACvE,UAAU,CAAC,EAAE;QAAE,IAAI,EAAE,YAAY,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CACpD;AAED,MAAM,MAAM,eAAe,GAAG;IAC7B,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAyBF,wBAAgB,y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,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,EAAE,eAAe,CAAC,CAiEjF;AAYD,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACvB,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAK9C;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,uFAQpE"}
@@ -1,15 +1,16 @@
1
+ /**
2
+ * The managed shell tools: the native shell definition (`bash.ts`) plus a `background` parameter,
3
+ * adapted to the session's Tasks. The native body stays the one owner of execution, progress,
4
+ * output formatting and results; outside a session it runs unchanged.
5
+ */
1
6
  import { Type } from "typebox";
2
- import { TaskRuntime } from "../tasks/runtime.js";
3
- import { TASKS_TOOL_NAME } from "../tasks/types.js";
4
- import { resolveSpawnContext, resolveTimeoutMs, } from "./bash.js";
5
- import { createShellRenderers } from "./renderers/bash.js";
6
- import { runShellCommand } from "./shell-execution.js";
7
+ import { TASK_BACKGROUND_REJECTION, TASKS_TOOL_NAME, } from "../tasks/types.js";
8
+ import { createShellToolDefinition as createNativeShellToolDefinition, bashOutputSchema as nativeOutputSchema, bashSchema as nativeSchema, } from "./bash.js";
9
+ import { runShellTask } from "./shell-execution.js";
7
10
  import { createLocalBashOperations } from "./shell-operations.js";
8
11
  import { wrapToolDefinition } from "./tool-definition-wrapper.js";
9
- import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES } from "./truncate.js";
10
12
  const bashSchema = Type.Object({
11
- command: Type.String({ description: "Shell command to execute" }),
12
- timeout: Type.Optional(Type.Number({ description: "Timeout in seconds (optional, no default timeout)" })),
13
+ ...nativeSchema.properties,
13
14
  background: Type.Optional(Type.Boolean({
14
15
  description: "true returns a managed task ID immediately and runs the command in the background, and you are notified when it completes — do not poll for its result; omit or false to block until exit",
15
16
  })),
@@ -19,17 +20,10 @@ export const bashToolSystemPromptContribution = {
19
20
  guidelines: ["You can inspect PI_* environment variables for current model and session details."],
20
21
  };
21
22
  const bashOutputSchema = Type.Union([
22
- Type.Object({
23
- output: Type.String({
24
- description: "Combined stdout and stderr, up to 1 MiB, keeping head and tail when truncated.",
25
- }),
26
- truncated: Type.Boolean(),
27
- full_output_path: Type.Optional(Type.String()),
28
- exit_code: Type.Number(),
29
- wall_time_seconds: Type.Number(),
30
- }),
23
+ nativeOutputSchema,
31
24
  Type.Object({ task_id: Type.String(), status: Type.String() }),
32
25
  ]);
26
+ const BACKGROUND_GUIDANCE = `Choose the mode per call: foreground (default) blocks until the command exits — use it when your next step needs the output; background: true returns immediately with a task ID — use it for long-running work (builds, servers, watchers, big test suites) or when you have independent work to continue. A handoff is not completion: the result arrives later as an automatic completion notification; meanwhile use ${TASKS_TOOL_NAME} read to inspect output and ${TASKS_TOOL_NAME} kill to stop it. Background output is limited to 20 MiB.`;
33
27
  /**
34
28
  * Translate terminal shell failures to the native foreground tool contract once. A task result
35
29
  * holds the command's output only; the foreground text is that output followed by the failure.
@@ -52,61 +46,40 @@ function shellToolResult(completion) {
52
46
  return completion.result;
53
47
  }
54
48
  export function createShellToolDefinition(cwd, config, options) {
55
- const ops = options.operations;
56
- const commandPrefix = options?.commandPrefix;
57
- const exposeSessionEnvironment = options?.exposeSessionEnvironment ?? true;
58
- const spawnHook = options?.spawnHook;
49
+ const native = createNativeShellToolDefinition(cwd, config, options);
59
50
  return {
60
- name: config.name,
61
- label: config.label,
62
- description: `Execute a ${config.shellName} command in the current working directory. Returns stdout and stderr, truncated to the last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first); the full output is saved to a temp file. Optionally provide a timeout in seconds (no default). Choose the mode per call: foreground (default) blocks until the command exits — use it when your next step needs the output; background: true returns immediately with a task ID — use it for long-running work (builds, servers, watchers, big test suites) or when you have independent work to continue. A handoff is not completion: the result arrives later as an automatic completion notification; meanwhile use ${TASKS_TOOL_NAME} read to inspect output and ${TASKS_TOOL_NAME} kill to stop it. Background output is limited to 20 MiB.`,
63
- promptSnippet: config.promptSnippet,
64
- promptGuidelines: exposeSessionEnvironment && config.promptGuidelines ? [...config.promptGuidelines] : undefined,
51
+ ...native,
52
+ description: `${native.description} ${BACKGROUND_GUIDANCE}`,
65
53
  parameters: bashSchema,
66
54
  outputSchema: bashOutputSchema,
67
- constrainedSampling: { type: "json_schema", strict: "prefer" },
68
- async execute(toolCallId, { command, timeout, background }, parentSignal, originalUpdate, ctx) {
69
- const sessionTasks = ctx?.tasks;
70
- if (sessionTasks?.closed)
55
+ async execute(toolCallId, { command, timeout, background }, parentSignal, onUpdate, ctx) {
56
+ const tasks = ctx?.tasks;
57
+ if (!tasks) {
58
+ if (background)
59
+ throw new Error(TASK_BACKGROUND_REJECTION);
60
+ return native.execute(toolCallId, { command, timeout }, parentSignal, onUpdate, ctx);
61
+ }
62
+ if (tasks.closed)
71
63
  throw new Error("Task service is closed");
72
- if (!sessionTasks && background)
73
- throw new Error("Background execution is not available in this host. No command was started.");
74
- // Without a session the command still runs as a task, on a throwaway runtime that never backgrounds.
75
- const standalone = sessionTasks ? undefined : new TaskRuntime();
76
- const run = async (control) => {
77
- if (control.signal.aborted)
78
- throw new Error("Command aborted");
79
- resolveTimeoutMs(timeout);
80
- const resolvedCommand = commandPrefix ? `${commandPrefix}\n${command}` : command;
81
- const spawnContext = resolveSpawnContext(resolvedCommand, ctx?.cwd || cwd, spawnHook, exposeSessionEnvironment, ctx);
64
+ const outcome = await tasks.execute({
65
+ kind: config.name,
66
+ label: config.shellName[0].toUpperCase() + config.shellName.slice(1),
67
+ title: command,
68
+ input: { label: "Command", text: command, truncated: false, language: config.name },
69
+ facts: [["Directory", ctx.cwd || cwd]],
70
+ toolCallId,
71
+ background,
72
+ signal: parentSignal,
73
+ onUpdate,
82
74
  // A setup throw settles the task as failed, or cancelled once its signal fired.
83
- return await runShellCommand({
84
- operations: ops,
85
- context: spawnContext,
75
+ run: (control) => runShellTask({
76
+ control,
77
+ operations: options.operations,
86
78
  tempFilePrefix: config.tempFilePrefix,
87
79
  timeout,
88
- control,
89
- taskLog: sessionTasks !== undefined,
90
- });
91
- };
92
- let outcome;
93
- try {
94
- outcome = await (sessionTasks ?? standalone).execute({
95
- kind: config.name,
96
- label: config.shellName[0].toUpperCase() + config.shellName.slice(1),
97
- title: command,
98
- input: { label: "Command", text: command, truncated: false, language: config.name },
99
- facts: [["Directory", ctx?.cwd || cwd]],
100
- toolCallId,
101
- background,
102
- signal: parentSignal,
103
- onUpdate: originalUpdate,
104
- run,
105
- });
106
- }
107
- finally {
108
- standalone?.close();
109
- }
80
+ execute: (parts) => createNativeShellToolDefinition(cwd, { ...config, createOutput: parts.createOutput }, { ...options, operations: parts.operations }).execute(toolCallId, { command, timeout }, control.signal, parts.onUpdate, ctx),
81
+ }),
82
+ });
110
83
  if (outcome.kind === "result")
111
84
  return shellToolResult(outcome);
112
85
  const tail = `Task ID: ${outcome.task.id}. Status: ${outcome.task.status}. Completion arrives and wakes you automatically — do not poll or wait on it; continue with other work, or end your turn and hand back to the user. If you would only wait for the result, prefer foreground next time. Use ${TASKS_TOOL_NAME} read to inspect output or ${TASKS_TOOL_NAME} kill to stop it.`;
@@ -130,7 +103,6 @@ export function createShellToolDefinition(cwd, config, options) {
130
103
  },
131
104
  };
132
105
  },
133
- ...createShellRenderers(config),
134
106
  };
135
107
  }
136
108
  const bashToolConfig = {
@@ -1 +1 @@
1
- {"version":3,"file":"shell-tool.js","sourceRoot":"","sources":["../../../src/core/tools/shell-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,eAAe,EAA+D,MAAM,mBAAmB,CAAC;AACjH,OAAO,EAGN,mBAAmB,EACnB,gBAAgB,GAEhB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,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IACb,SAAS,EAAE,MAAM;IACjB,MAAM,EAAE,GAAG;IACX,aAAa,EAAE,gCAAgC,CAAC,OAAO;IACvD,gBAAgB,EAAE,gCAAgC,CAAC,UAAU;IAC7D,cAAc,EAAE,SAAS;CACzB,CAAC;AAEF,MAAM,UAAU,wBAAwB,CACvC,GAAW,EACX,OAAyB;IAEzB,OAAO,yBAAyB,CAAC,GAAG,EAAE,cAAc,EAAE;QACrD,GAAG,OAAO;QACV,UAAU,EAAE,OAAO,EAAE,UAAU,IAAI,yBAAyB,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;KAC/F,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,OAAyB;IACpE,MAAM,UAAU,GAAG,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC1D,MAAM,IAAI,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;IAC5C,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;QACnB,aAAa,EAAE,UAAU,CAAC,aAAa;QACvC,gBAAgB,EAAE,UAAU,CAAC,gBAAgB;KAC7C,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { ExtensionContext, ToolDefinition } from \"../extensions/types.ts\";\nimport { TaskRuntime } from \"../tasks/runtime.ts\";\nimport { TASKS_TOOL_NAME, type TaskCompletion, type TaskControl, type TaskToolOutcome } from \"../tasks/types.ts\";\nimport {\n\ttype BashOperations,\n\ttype BashToolOptions,\n\tresolveSpawnContext,\n\tresolveTimeoutMs,\n\ttype ShellToolConfig,\n} from \"./bash.ts\";\nimport { createShellRenderers } from \"./renderers/bash.ts\";\nimport { runShellCommand } from \"./shell-execution.ts\";\nimport { createLocalBashOperations } from \"./shell-operations.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, type TruncationResult } from \"./truncate.ts\";\n\nconst bashSchema = Type.Object({\n\tcommand: Type.String({ description: \"Shell command to execute\" }),\n\ttimeout: Type.Optional(Type.Number({ description: \"Timeout in seconds (optional, no default timeout)\" })),\n\tbackground: Type.Optional(\n\t\tType.Boolean({\n\t\t\tdescription:\n\t\t\t\t\"true returns a managed task ID immediately and runs the command in the background, and you are notified when it completes — do not poll for its result; omit or false to block until exit\",\n\t\t}),\n\t),\n});\n\nexport const bashToolSystemPromptContribution = {\n\tsnippet: \"Execute bash commands, foreground or background\",\n\tguidelines: [\"You can inspect PI_* environment variables for current model and session details.\"],\n} as const;\n\nexport type BashToolInput = Static<typeof bashSchema>;\n\nconst bashOutputSchema = Type.Union([\n\tType.Object({\n\t\toutput: Type.String({\n\t\t\tdescription: \"Combined stdout and stderr, up to 1 MiB, keeping head and tail when truncated.\",\n\t\t}),\n\t\ttruncated: Type.Boolean(),\n\t\tfull_output_path: Type.Optional(Type.String()),\n\t\texit_code: Type.Number(),\n\t\twall_time_seconds: Type.Number(),\n\t}),\n\tType.Object({ task_id: Type.String(), status: Type.String() }),\n]);\n\nexport interface BashToolDetails {\n\ttruncation?: TruncationResult;\n\tfullOutputPath?: string;\n\t/** Settled handoff snapshot, not a command completion or exit code. */\n\tbackground?: { kind: \"background\"; taskId: string };\n}\n\nexport type BashRenderState = {\n\tdispose?: () => void;\n};\n\n/**\n * Translate terminal shell failures to the native foreground tool contract once. A task result\n * holds the command's output only; the foreground text is that output followed by the failure.\n */\nfunction shellToolResult(completion: TaskCompletion<BashToolDetails | undefined>) {\n\tconst status = completion.status;\n\tconst output = completion.result.content\n\t\t.filter((part) => part.type === \"text\")\n\t\t.map((part) => part.text)\n\t\t.join(\"\\n\");\n\tconst withError = (error: string) => (output ? `${output}\\n\\n${error}` : error);\n\tif (completion.result.structuredContent) {\n\t\tif (!completion.result.isError || !completion.error) return completion.result;\n\t\treturn { ...completion.result, content: [{ type: \"text\" as const, text: withError(completion.error) }] };\n\t}\n\tif (status === \"failed\" || status === \"timeout\" || status === \"cancelled\") {\n\t\tthrow new Error(\n\t\t\tcompletion.error ? withError(completion.error) : `${output ? `${output}\\n\\n` : \"\"}Command ${status}`,\n\t\t);\n\t}\n\treturn completion.result;\n}\n\nexport function createShellToolDefinition(\n\tcwd: string,\n\tconfig: ShellToolConfig,\n\toptions: BashToolOptions & { operations: BashOperations },\n): ToolDefinition<typeof bashSchema, BashToolDetails | undefined, BashRenderState> {\n\tconst ops = options.operations;\n\tconst commandPrefix = options?.commandPrefix;\n\tconst exposeSessionEnvironment = options?.exposeSessionEnvironment ?? true;\n\tconst spawnHook = options?.spawnHook;\n\treturn {\n\t\tname: config.name,\n\t\tlabel: config.label,\n\t\tdescription: `Execute a ${config.shellName} command in the current working directory. Returns stdout and stderr, truncated to the last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first); the full output is saved to a temp file. Optionally provide a timeout in seconds (no default). Choose the mode per call: foreground (default) blocks until the command exits — use it when your next step needs the output; background: true returns immediately with a task ID — use it for long-running work (builds, servers, watchers, big test suites) or when you have independent work to continue. A handoff is not completion: the result arrives later as an automatic completion notification; meanwhile use ${TASKS_TOOL_NAME} read to inspect output and ${TASKS_TOOL_NAME} kill to stop it. Background output is limited to 20 MiB.`,\n\t\tpromptSnippet: config.promptSnippet,\n\t\tpromptGuidelines: exposeSessionEnvironment && config.promptGuidelines ? [...config.promptGuidelines] : undefined,\n\t\tparameters: bashSchema,\n\t\toutputSchema: bashOutputSchema,\n\t\tconstrainedSampling: { type: \"json_schema\", strict: \"prefer\" },\n\t\tasync execute(\n\t\t\ttoolCallId,\n\t\t\t{ command, timeout, background }: BashToolInput,\n\t\t\tparentSignal?: AbortSignal,\n\t\t\toriginalUpdate?,\n\t\t\tctx?: ExtensionContext,\n\t\t) {\n\t\t\tconst sessionTasks = ctx?.tasks;\n\t\t\tif (sessionTasks?.closed) throw new Error(\"Task service is closed\");\n\t\t\tif (!sessionTasks && background)\n\t\t\t\tthrow new Error(\"Background execution is not available in this host. No command was started.\");\n\t\t\t// Without a session the command still runs as a task, on a throwaway runtime that never backgrounds.\n\t\t\tconst standalone = sessionTasks ? undefined : new TaskRuntime();\n\t\t\tconst run = async (\n\t\t\t\tcontrol: TaskControl<BashToolDetails | undefined>,\n\t\t\t): Promise<TaskCompletion<BashToolDetails | undefined>> => {\n\t\t\t\tif (control.signal.aborted) throw new Error(\"Command aborted\");\n\t\t\t\tresolveTimeoutMs(timeout);\n\t\t\t\tconst resolvedCommand = commandPrefix ? `${commandPrefix}\\n${command}` : command;\n\t\t\t\tconst spawnContext = resolveSpawnContext(\n\t\t\t\t\tresolvedCommand,\n\t\t\t\t\tctx?.cwd || cwd,\n\t\t\t\t\tspawnHook,\n\t\t\t\t\texposeSessionEnvironment,\n\t\t\t\t\tctx,\n\t\t\t\t);\n\t\t\t\t// A setup throw settles the task as failed, or cancelled once its signal fired.\n\t\t\t\treturn await runShellCommand({\n\t\t\t\t\toperations: ops,\n\t\t\t\t\tcontext: spawnContext,\n\t\t\t\t\ttempFilePrefix: config.tempFilePrefix,\n\t\t\t\t\ttimeout,\n\t\t\t\t\tcontrol,\n\t\t\t\t\ttaskLog: sessionTasks !== undefined,\n\t\t\t\t});\n\t\t\t};\n\t\t\tlet outcome: TaskToolOutcome<BashToolDetails | undefined>;\n\t\t\ttry {\n\t\t\t\toutcome = await (sessionTasks ?? standalone!).execute<BashToolDetails | undefined>({\n\t\t\t\t\tkind: config.name,\n\t\t\t\t\tlabel: config.shellName[0]!.toUpperCase() + config.shellName.slice(1),\n\t\t\t\t\ttitle: command,\n\t\t\t\t\tinput: { label: \"Command\", text: command, truncated: false, language: config.name },\n\t\t\t\t\tfacts: [[\"Directory\", ctx?.cwd || cwd]],\n\t\t\t\t\ttoolCallId,\n\t\t\t\t\tbackground,\n\t\t\t\t\tsignal: parentSignal,\n\t\t\t\t\tonUpdate: originalUpdate,\n\t\t\t\t\trun,\n\t\t\t\t});\n\t\t\t} finally {\n\t\t\t\tstandalone?.close();\n\t\t\t}\n\t\t\tif (outcome.kind === \"result\") return shellToolResult(outcome);\n\t\t\tconst tail = `Task ID: ${outcome.task.id}. Status: ${outcome.task.status}. Completion arrives and wakes you automatically — do not poll or wait on it; continue with other work, or end your turn and hand back to the user. If you would only wait for the result, prefer foreground next time. Use ${TASKS_TOOL_NAME} read to inspect output or ${TASKS_TOOL_NAME} kill to stop it.`;\n\t\t\t// Shell execution can become background work in two ways, and the model has to know which\n\t\t\t// one it got: a submitted background command starts from an empty log, while a detached\n\t\t\t// one already holds output and keeps its original timeout.\n\t\t\tconst handoff =\n\t\t\t\toutcome.reason === \"submitted\"\n\t\t\t\t\t? `Command handed to background. ${tail}`\n\t\t\t\t\t: `Command moved to the background while it was running, by the user. The execution continues unchanged — no restart, and a supplied timeout is still measured from command startup. Output produced so far is already in the log, so ${TASKS_TOOL_NAME} read now returns partial output, not a fresh start. ${tail}`;\n\t\t\treturn {\n\t\t\t\tstructuredContent: { task_id: outcome.task.id, status: outcome.task.status },\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\ttext: `${handoff}${outcome.task.outputPath ? `\\nFull output: ${outcome.task.outputPath}` : \"\"}`,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdetails: {\n\t\t\t\t\tbackground: { kind: \"background\", taskId: outcome.task.id },\n\t\t\t\t\tfullOutputPath: outcome.task.outputPath,\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t\t...createShellRenderers(config),\n\t};\n}\n\nconst bashToolConfig: ShellToolConfig = {\n\tname: \"bash\",\n\tlabel: \"bash\",\n\tshellName: \"bash\",\n\tprompt: \"$\",\n\tpromptSnippet: bashToolSystemPromptContribution.snippet,\n\tpromptGuidelines: bashToolSystemPromptContribution.guidelines,\n\ttempFilePrefix: \"pi-bash\",\n};\n\nexport function createBashToolDefinition(\n\tcwd: string,\n\toptions?: BashToolOptions,\n): ReturnType<typeof createShellToolDefinition> {\n\treturn createShellToolDefinition(cwd, bashToolConfig, {\n\t\t...options,\n\t\toperations: options?.operations ?? createLocalBashOperations({ shellPath: options?.shellPath }),\n\t});\n}\n\nexport function createBashTool(cwd: string, options?: BashToolOptions) {\n\tconst definition = createBashToolDefinition(cwd, options);\n\tconst tool = wrapToolDefinition(definition);\n\tObject.assign(tool, {\n\t\tpromptSnippet: definition.promptSnippet,\n\t\tpromptGuidelines: definition.promptGuidelines,\n\t});\n\treturn tool;\n}\n"]}
1
+ {"version":3,"file":"shell-tool.js","sourceRoot":"","sources":["../../../src/core/tools/shell-tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EACN,yBAAyB,EACzB,eAAe,GAGf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAIN,yBAAyB,IAAI,+BAA+B,EAE5D,gBAAgB,IAAI,kBAAkB,EACtC,UAAU,IAAI,YAAY,GAE1B,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC;IAC9B,GAAG,YAAY,CAAC,UAAU;IAC1B,UAAU,EAAE,IAAI,CAAC,QAAQ,CACxB,IAAI,CAAC,OAAO,CAAC;QACZ,WAAW,EACV,2LAA2L;KAC5L,CAAC,CACF;CACD,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gCAAgC,GAAG;IAC/C,OAAO,EAAE,iDAAiD;IAC1D,UAAU,EAAE,CAAC,mFAAmF,CAAC;CACxF,CAAC;AAIX,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC;IACnC,kBAAkB;IAClB,IAAI,CAAC,MAAM,CA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CAAC;IAC5C,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;QACnB,aAAa,EAAE,UAAU,CAAC,aAAa;QACvC,gBAAgB,EAAE,UAAU,CAAC,gBAAgB;KAC7C,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["/**\n * The managed shell tools: the native shell definition (`bash.ts`) plus a `background` parameter,\n * adapted to the session's Tasks. The native body stays the one owner of execution, progress,\n * output formatting and results; outside a session it runs unchanged.\n */\nimport { type Static, Type } from \"typebox\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport {\n\tTASK_BACKGROUND_REJECTION,\n\tTASKS_TOOL_NAME,\n\ttype TaskCompletion,\n\ttype TaskToolOutcome,\n} from \"../tasks/types.ts\";\nimport {\n\ttype BashOperations,\n\ttype BashRenderState,\n\ttype BashToolOptions,\n\tcreateShellToolDefinition as createNativeShellToolDefinition,\n\ttype BashToolDetails as NativeBashToolDetails,\n\tbashOutputSchema as nativeOutputSchema,\n\tbashSchema as nativeSchema,\n\ttype ShellToolConfig,\n} from \"./bash.ts\";\nimport { runShellTask } from \"./shell-execution.ts\";\nimport { createLocalBashOperations } from \"./shell-operations.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst bashSchema = Type.Object({\n\t...nativeSchema.properties,\n\tbackground: Type.Optional(\n\t\tType.Boolean({\n\t\t\tdescription:\n\t\t\t\t\"true returns a managed task ID immediately and runs the command in the background, and you are notified when it completes — do not poll for its result; omit or false to block until exit\",\n\t\t}),\n\t),\n});\n\nexport const bashToolSystemPromptContribution = {\n\tsnippet: \"Execute bash commands, foreground or background\",\n\tguidelines: [\"You can inspect PI_* environment variables for current model and session details.\"],\n} as const;\n\nexport type BashToolInput = Static<typeof bashSchema>;\n\nconst bashOutputSchema = Type.Union([\n\tnativeOutputSchema,\n\tType.Object({ task_id: Type.String(), status: Type.String() }),\n]);\n\nexport interface BashToolDetails extends NativeBashToolDetails {\n\t/** Settled handoff snapshot, not a command completion or exit code. */\n\tbackground?: { kind: \"background\"; taskId: string };\n}\n\nconst BACKGROUND_GUIDANCE = `Choose the mode per call: foreground (default) blocks until the command exits — use it when your next step needs the output; background: true returns immediately with a task ID — use it for long-running work (builds, servers, watchers, big test suites) or when you have independent work to continue. A handoff is not completion: the result arrives later as an automatic completion notification; meanwhile use ${TASKS_TOOL_NAME} read to inspect output and ${TASKS_TOOL_NAME} kill to stop it. Background output is limited to 20 MiB.`;\n\n/**\n * Translate terminal shell failures to the native foreground tool contract once. A task result\n * holds the command's output only; the foreground text is that output followed by the failure.\n */\nfunction shellToolResult(completion: TaskCompletion<BashToolDetails | undefined>) {\n\tconst status = completion.status;\n\tconst output = completion.result.content\n\t\t.filter((part) => part.type === \"text\")\n\t\t.map((part) => part.text)\n\t\t.join(\"\\n\");\n\tconst withError = (error: string) => (output ? `${output}\\n\\n${error}` : error);\n\tif (completion.result.structuredContent) {\n\t\tif (!completion.result.isError || !completion.error) return completion.result;\n\t\treturn { ...completion.result, content: [{ type: \"text\" as const, text: withError(completion.error) }] };\n\t}\n\tif (status === \"failed\" || status === \"timeout\" || status === \"cancelled\") {\n\t\tthrow new Error(\n\t\t\tcompletion.error ? withError(completion.error) : `${output ? `${output}\\n\\n` : \"\"}Command ${status}`,\n\t\t);\n\t}\n\treturn completion.result;\n}\n\nexport function createShellToolDefinition(\n\tcwd: string,\n\tconfig: ShellToolConfig,\n\toptions: BashToolOptions & { operations: BashOperations },\n): ToolDefinition<typeof bashSchema, BashToolDetails | undefined, BashRenderState> {\n\tconst native = createNativeShellToolDefinition(cwd, config, options);\n\treturn {\n\t\t...native,\n\t\tdescription: `${native.description} ${BACKGROUND_GUIDANCE}`,\n\t\tparameters: bashSchema,\n\t\toutputSchema: bashOutputSchema,\n\t\tasync execute(toolCallId, { command, timeout, background }: BashToolInput, parentSignal, onUpdate, ctx) {\n\t\t\tconst tasks = ctx?.tasks;\n\t\t\tif (!tasks) {\n\t\t\t\tif (background) throw new Error(TASK_BACKGROUND_REJECTION);\n\t\t\t\treturn native.execute(toolCallId, { command, timeout }, parentSignal, onUpdate, ctx);\n\t\t\t}\n\t\t\tif (tasks.closed) throw new Error(\"Task service is closed\");\n\t\t\tconst outcome: TaskToolOutcome<BashToolDetails | undefined> = await tasks.execute<BashToolDetails | undefined>(\n\t\t\t\t{\n\t\t\t\t\tkind: config.name,\n\t\t\t\t\tlabel: config.shellName[0]!.toUpperCase() + config.shellName.slice(1),\n\t\t\t\t\ttitle: command,\n\t\t\t\t\tinput: { label: \"Command\", text: command, truncated: false, language: config.name },\n\t\t\t\t\tfacts: [[\"Directory\", ctx.cwd || cwd]],\n\t\t\t\t\ttoolCallId,\n\t\t\t\t\tbackground,\n\t\t\t\t\tsignal: parentSignal,\n\t\t\t\t\tonUpdate,\n\t\t\t\t\t// A setup throw settles the task as failed, or cancelled once its signal fired.\n\t\t\t\t\trun: (control) =>\n\t\t\t\t\t\trunShellTask({\n\t\t\t\t\t\t\tcontrol,\n\t\t\t\t\t\t\toperations: options.operations,\n\t\t\t\t\t\t\ttempFilePrefix: config.tempFilePrefix,\n\t\t\t\t\t\t\ttimeout,\n\t\t\t\t\t\t\texecute: (parts) =>\n\t\t\t\t\t\t\t\tcreateNativeShellToolDefinition(\n\t\t\t\t\t\t\t\t\tcwd,\n\t\t\t\t\t\t\t\t\t{ ...config, createOutput: parts.createOutput },\n\t\t\t\t\t\t\t\t\t{ ...options, operations: parts.operations },\n\t\t\t\t\t\t\t\t).execute(toolCallId, { command, timeout }, control.signal, parts.onUpdate, ctx),\n\t\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (outcome.kind === \"result\") return shellToolResult(outcome);\n\t\t\tconst tail = `Task ID: ${outcome.task.id}. Status: ${outcome.task.status}. Completion arrives and wakes you automatically — do not poll or wait on it; continue with other work, or end your turn and hand back to the user. If you would only wait for the result, prefer foreground next time. Use ${TASKS_TOOL_NAME} read to inspect output or ${TASKS_TOOL_NAME} kill to stop it.`;\n\t\t\t// Shell execution can become background work in two ways, and the model has to know which\n\t\t\t// one it got: a submitted background command starts from an empty log, while a detached\n\t\t\t// one already holds output and keeps its original timeout.\n\t\t\tconst handoff =\n\t\t\t\toutcome.reason === \"submitted\"\n\t\t\t\t\t? `Command handed to background. ${tail}`\n\t\t\t\t\t: `Command moved to the background while it was running, by the user. The execution continues unchanged — no restart, and a supplied timeout is still measured from command startup. Output produced so far is already in the log, so ${TASKS_TOOL_NAME} read now returns partial output, not a fresh start. ${tail}`;\n\t\t\treturn {\n\t\t\t\tstructuredContent: { task_id: outcome.task.id, status: outcome.task.status },\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\ttext: `${handoff}${outcome.task.outputPath ? `\\nFull output: ${outcome.task.outputPath}` : \"\"}`,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdetails: {\n\t\t\t\t\tbackground: { kind: \"background\", taskId: outcome.task.id },\n\t\t\t\t\tfullOutputPath: outcome.task.outputPath,\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n\nconst bashToolConfig: ShellToolConfig = {\n\tname: \"bash\",\n\tlabel: \"bash\",\n\tshellName: \"bash\",\n\tprompt: \"$\",\n\tpromptSnippet: bashToolSystemPromptContribution.snippet,\n\tpromptGuidelines: bashToolSystemPromptContribution.guidelines,\n\ttempFilePrefix: \"pi-bash\",\n};\n\nexport function createBashToolDefinition(\n\tcwd: string,\n\toptions?: BashToolOptions,\n): ReturnType<typeof createShellToolDefinition> {\n\treturn createShellToolDefinition(cwd, bashToolConfig, {\n\t\t...options,\n\t\toperations: options?.operations ?? createLocalBashOperations({ shellPath: options?.shellPath }),\n\t});\n}\n\nexport function createBashTool(cwd: string, options?: BashToolOptions) {\n\tconst definition = createBashToolDefinition(cwd, options);\n\tconst tool = wrapToolDefinition(definition);\n\tObject.assign(tool, {\n\t\tpromptSnippet: definition.promptSnippet,\n\t\tpromptGuidelines: definition.promptGuidelines,\n\t});\n\treturn tool;\n}\n"]}
@@ -1,9 +1,19 @@
1
- import type { AgentTool } from "@earendil-works/pi-agent-core";
2
- import type { TSchema } from "typebox";
1
+ import type { AgentTool, AgentToolResult, AgentToolUpdateCallback } from "@earendil-works/pi-agent-core";
2
+ import type { Static, TSchema } from "typebox";
3
3
  import type { ExtensionToolContext, ToolDefinition } from "../extensions/types.ts";
4
+ /**
5
+ * An `AgentTool` with a TypeBox parameter schema whose `execute` and `prepareArguments` are typed by TypeBox's
6
+ * `Static`, as the built-in tools are (pi-agent-core types `params` through pi-schema, which maps only the common
7
+ * TypeBox kinds). Spreads into a `ToolDefinition` of the same schema.
8
+ */
9
+ export type TypeBoxAgentTool<TParams extends TSchema = TSchema, TDetails = any> = Omit<AgentTool<TParams, TDetails>, "prepareArguments" | "execute"> & {
10
+ prepareArguments?: (args: unknown) => Static<TParams>;
11
+ execute: (toolCallId: string, params: Static<TParams>, signal?: AbortSignal, onUpdate?: AgentToolUpdateCallback<TDetails>) => Promise<AgentToolResult<TDetails>>;
12
+ };
13
+ /** Creates the context for one tool call. */
4
14
  export type ToolContextFactory = (toolCallId: string, signal: AbortSignal | undefined) => ExtensionToolContext;
5
15
  /** Wrap a ToolDefinition into an AgentTool for the core runtime. */
6
- export declare function wrapToolDefinition<TParams extends TSchema, TDetails = unknown>(definition: ToolDefinition<TParams, TDetails>, ctxFactory?: ToolContextFactory): AgentTool<TParams, TDetails>;
16
+ export declare function wrapToolDefinition<TDetails = unknown>(definition: ToolDefinition<any, TDetails>, ctxFactory?: ToolContextFactory): AgentTool<any, TDetails>;
7
17
  /** Wrap multiple ToolDefinitions into AgentTools for the core runtime. */
8
18
  export declare function wrapToolDefinitions(definitions: ToolDefinition<any, any>[], ctxFactory?: ToolContextFactory): AgentTool<any>[];
9
19
  /**
@@ -12,5 +22,5 @@ export declare function wrapToolDefinitions(definitions: ToolDefinition<any, any
12
22
  * This keeps AgentSession's internal registry definition-first even when a caller
13
23
  * provides plain AgentTool overrides that do not include prompt metadata or renderers.
14
24
  */
15
- export declare function createToolDefinitionFromAgentTool<TParams extends TSchema, TDetails>(tool: AgentTool<TParams, TDetails>): ToolDefinition<TParams, TDetails>;
25
+ export declare function createToolDefinitionFromAgentTool(tool: AgentTool<any>): ToolDefinition<any, unknown>;
16
26
  //# sourceMappingURL=tool-definition-wrapper.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tool-definition-wrapper.d.ts","sourceRoot":"","sources":["../../../src/core/tools/tool-definition-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE/D,OAAO,KAAK,EAAU,OAAO,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAGnF,MAAM,MAAM,kBAAkB,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,SAAS,KAAK,oBAAoB,CAAC;AA4H/G,oEAAoE;AACpE,wBAAgB,kBAAkB,CAAC,OAAO,SAAS,OAAO,EAAE,QAAQ,GAAG,OAAO,EAC7E,UAAU,EAAE,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,EAC7C,UAAU,CAAC,EAAE,kBAAkB,GAC7B,SAAS,CAAC,OAAO,EAAE,QAAQ,CAAC,CAmB9B;AAED,0EAA0E;AAC1E,wBAAgB,mBAAmB,CAClC,WAAW,EAAE,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EACvC,UAAU,CAAC,EAAE,kBAAkB,GAC7B,SAAS,CAAC,GAAG,CAAC,EAAE,CAElB;AAED;;;;;GAKG;AACH,wBAAgB,iCAAiC,CAAC,OAAO,SAAS,OAAO,EAAE,QAAQ,EAClF,IAAI,EAAE,SAAS,CAAC,OAAO,EAAE,QAAQ,CAAC,GAChC,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,CAYnC"}
1
+ {"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AAG,EAAE,GAAG,CAAC,EAAE,EACvC,UAAU,CAAC,EAAE,kBAAkB,GAC7B,SAAS,CAAC,GAAG,CAAC,EAAE,CAElB;AAED;;;;;GAKG;AACH,wBAAgB,iCAAiC,CAAC,IAAI,EAAE,SAAS,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC,CAYpG"}
@@ -15,8 +15,7 @@ function isRecord(value) {
15
15
  * validator's own report says where validation failed; these hints say what
16
16
  * the legal shape is. Union variants (`anyOf`, e.g. a nullable field) are
17
17
  * walked through so nested shapes still get hints. Paths use the validator's
18
- * dotted style
19
- * (`tasks[0].prompt`). Non-null unknown fields are reported rather than
18
+ * dotted style (`tasks.0.prompt`). Non-null unknown fields are reported rather than
20
19
  * silently dropped: a field like `prompt_extra` may carry briefing content
21
20
  * the caller intended to send.
22
21
  */
@@ -35,7 +34,7 @@ function collectFieldHints(schema, args) {
35
34
  }
36
35
  if (node.type === "array" && Array.isArray(value)) {
37
36
  for (let index = 0; index < value.length; index++) {
38
- visit(node.items, value[index], `${path}[${index}]`);
37
+ visit(node.items, value[index], `${path}.${index}`);
39
38
  }
40
39
  return;
41
40
  }
@@ -1 +1 @@
1
- {"version":3,"file":"tool-definition-wrapper.js","sourceRoot":"","sources":["../../../src/core/tools/tool-definition-wrapper.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAG/E,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAI7C,MAAM,yBAAyB,GAAG,2BAA2B,CAAC;AAC9D,MAAM,WAAW,GAAG,YAAY,CAAC;AACjC,MAAM,4BAA4B,GAAG,CAAC,GAAG,IAAI,CAAC;AAC9C,MAAM,4BAA4B,GAAG,EAAE,CAAC;AACxC,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK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,EAAE,IAAI,CAAC,YAAY;QAC/B,mBAAmB,EAAE,IAAI,CAAC,mBAAmB;QAC7C,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;QACvC,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC;KAC3G,CAAC;AACH,CAAC","sourcesContent":["import type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport { type JsonObject, validateToolArguments } from \"@earendil-works/pi-ai\";\nimport type { Static, TSchema } from \"typebox\";\nimport type { ExtensionToolContext, ToolDefinition } from \"../extensions/types.ts\";\nimport { truncateHead } from \"./truncate.ts\";\n\nexport type ToolContextFactory = (toolCallId: string, signal: AbortSignal | undefined) => ExtensionToolContext;\n\nconst RECEIVED_ARGUMENTS_MARKER = \"\\n\\nReceived arguments:\\n\";\nconst HINT_MARKER = \"\\n\\nHint: \";\nconst RECEIVED_ARGUMENTS_MAX_BYTES = 2 * 1024;\nconst RECEIVED_ARGUMENTS_MAX_LINES = 40;\nconst FIELD_HINTS_MAX = 10;\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\n/**\n * Walk schema and arguments in sync to name, at every object with\n * `additionalProperties: false`, the non-null fields the schema does not\n * declare, and at every object, the required fields the arguments lack. The\n * validator's own report says where validation failed; these hints say what\n * the legal shape is. Union variants (`anyOf`, e.g. a nullable field) are\n * walked through so nested shapes still get hints. Paths use the validator's\n * dotted style\n * (`tasks[0].prompt`). Non-null unknown fields are reported rather than\n * silently dropped: a field like `prompt_extra` may carry briefing content\n * the caller intended to send.\n */\nfunction collectFieldHints(schema: unknown, args: unknown): string[] {\n\tconst hints: string[] = [];\n\tconst visit = (node: unknown, value: unknown, path: string): void => {\n\t\tif (hints.length >= FIELD_HINTS_MAX || !isRecord(node)) return;\n\t\tif (Array.isArray(node.anyOf)) {\n\t\t\t// Only nullable single-shape unions have unambiguous field requirements.\n\t\t\t// Alternative object shapes must not contribute contradictory hints.\n\t\t\tconst variants = node.anyOf.filter((variant: unknown) => !isRecord(variant) || variant.type !== \"null\");\n\t\t\tif (value !== null && variants.length === 1) visit(variants[0], value, path);\n\t\t\treturn;\n\t\t}\n\t\tif (node.type === \"array\" && Array.isArray(value)) {\n\t\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\t\tvisit(node.items, value[index], `${path}[${index}]`);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (node.type !== \"object\" || !isRecord(value)) return;\n\t\tconst properties = isRecord(node.properties) ? node.properties : {};\n\t\tconst fields = Object.keys(properties);\n\t\tconst where = path || \"root\";\n\t\tif (node.additionalProperties === false) {\n\t\t\tfor (const [key, entry] of Object.entries(value)) {\n\t\t\t\tif (entry !== null && !(key in properties) && hints.length < FIELD_HINTS_MAX) {\n\t\t\t\t\tconst subject = path ? `${path}.${key}` : key;\n\t\t\t\t\thints.push(`${subject} is not a field; fields at ${where}: ${fields.join(\", \")}`);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (Array.isArray(node.required)) {\n\t\t\tfor (const key of node.required) {\n\t\t\t\tif (typeof key === \"string\" && value[key] === undefined && hints.length < FIELD_HINTS_MAX) {\n\t\t\t\t\tconst subject = path ? `${path}.${key}` : key;\n\t\t\t\t\thints.push(`${subject} is required; fields at ${where}: ${fields.join(\", \")}`);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (const key of fields) {\n\t\t\tif (value[key] !== undefined && value[key] !== null) {\n\t\t\t\tvisit(properties[key], value[key], path ? `${path}.${key}` : key);\n\t\t\t}\n\t\t}\n\t};\n\tvisit(schema, args, \"\");\n\treturn hints;\n}\n\n/**\n * Rebuild pi-ai's validation error so a model can self-correct: the legal\n * fields are named next to each offending one, and the echoed arguments are\n * bounded (a 50KB tool argument must not be reflected whole into context).\n * The `Validation failed for tool \"<name>\":` prefix stays intact — the\n * question tool's renderer parses it.\n */\nfunction enrichValidationError(error: unknown, parameters: TSchema, args: unknown): Error {\n\tconst message = error instanceof Error ? error.message : String(error);\n\t// A definition synthesized from an already-wrapped tool enriches on the\n\t// inside; do not stack a second layer of hints on the same failure.\n\tif (message.includes(HINT_MARKER)) return error instanceof Error ? error : new Error(message);\n\tconst hints = collectFieldHints(parameters, args);\n\tconst markerIndex = message.indexOf(RECEIVED_ARGUMENTS_MARKER);\n\tconst head = markerIndex === -1 ? message : message.slice(0, markerIndex);\n\tconst received = markerIndex === -1 ? \"\" : message.slice(markerIndex + RECEIVED_ARGUMENTS_MARKER.length);\n\tlet enriched = hints.length > 0 ? `${head}\\n\\nHint: ${hints.join(\"\\nHint: \")}` : head;\n\tif (markerIndex !== -1) {\n\t\tconst bounded = truncateHead(received, {\n\t\t\tmaxBytes: RECEIVED_ARGUMENTS_MAX_BYTES,\n\t\t\tmaxLines: RECEIVED_ARGUMENTS_MAX_LINES,\n\t\t});\n\t\tenriched += `${RECEIVED_ARGUMENTS_MARKER}${bounded.content}`;\n\t\tif (bounded.truncated) enriched += \"\\n… (arguments truncated)\";\n\t}\n\treturn new Error(enriched);\n}\n\n/**\n * Pre-validate prepared arguments so a validation failure reaches the model\n * with field-level hints. Valid arguments pass through untouched and are\n * validated again by the agent loop as before.\n */\nfunction wrapPrepareArguments<TParams extends TSchema, TDetails>(\n\tdefinition: ToolDefinition<TParams, TDetails>,\n): (raw: unknown) => Static<TParams> {\n\tconst tool = { name: definition.name, description: definition.description, parameters: definition.parameters };\n\treturn (raw: unknown): Static<TParams> => {\n\t\tconst args = definition.prepareArguments ? definition.prepareArguments(raw) : raw;\n\t\ttry {\n\t\t\tvalidateToolArguments(tool, {\n\t\t\t\ttype: \"toolCall\",\n\t\t\t\tid: \"\",\n\t\t\t\tname: definition.name,\n\t\t\t\targuments: args as JsonObject,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tthrow enrichValidationError(error, definition.parameters, args);\n\t\t}\n\t\treturn args as Static<TParams>;\n\t};\n}\n\n/** Wrap a ToolDefinition into an AgentTool for the core runtime. */\nexport function wrapToolDefinition<TParams extends TSchema, TDetails = unknown>(\n\tdefinition: ToolDefinition<TParams, TDetails>,\n\tctxFactory?: ToolContextFactory,\n): AgentTool<TParams, TDetails> {\n\treturn {\n\t\tname: definition.name,\n\t\tlabel: definition.label,\n\t\tdescription: definition.description,\n\t\tparameters: definition.parameters,\n\t\toutputSchema: definition.outputSchema,\n\t\tconstrainedSampling: definition.constrainedSampling,\n\t\tprepareArguments: wrapPrepareArguments(definition),\n\t\texecutionMode: definition.executionMode,\n\t\texecute: (toolCallId, params, signal, onUpdate, ctx?: ExtensionToolContext) =>\n\t\t\tdefinition.execute(\n\t\t\t\ttoolCallId,\n\t\t\t\tparams,\n\t\t\t\tsignal,\n\t\t\t\tonUpdate,\n\t\t\t\tctx ?? (ctxFactory?.(toolCallId, signal) as ExtensionToolContext),\n\t\t\t),\n\t};\n}\n\n/** Wrap multiple ToolDefinitions into AgentTools for the core runtime. */\nexport function wrapToolDefinitions(\n\tdefinitions: ToolDefinition<any, any>[],\n\tctxFactory?: ToolContextFactory,\n): AgentTool<any>[] {\n\treturn definitions.map((definition) => wrapToolDefinition(definition, ctxFactory));\n}\n\n/**\n * Synthesize a minimal ToolDefinition from an AgentTool.\n *\n * This keeps AgentSession's internal registry definition-first even when a caller\n * provides plain AgentTool overrides that do not include prompt metadata or renderers.\n */\nexport function createToolDefinitionFromAgentTool<TParams extends TSchema, TDetails>(\n\ttool: AgentTool<TParams, TDetails>,\n): ToolDefinition<TParams, TDetails> {\n\treturn {\n\t\tname: tool.name,\n\t\tlabel: tool.label,\n\t\tdescription: tool.description,\n\t\tparameters: tool.parameters,\n\t\toutputSchema: tool.outputSchema,\n\t\tconstrainedSampling: tool.constrainedSampling,\n\t\tprepareArguments: tool.prepareArguments,\n\t\texecutionMode: tool.executionMode,\n\t\texecute: async (toolCallId, params, signal, onUpdate) => tool.execute(toolCallId, params, signal, onUpdate),\n\t};\n}\n"]}
1
+ {"version":3,"file":"tool-definition-wrapper.js","sourceRoot":"","sources":["../../../src/core/tools/tool-definition-wrapper.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAG/E,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAuB7C,MAAM,yBAAyB,GAAG,2BAA2B,CAAC;AAC9D,MAAM,WAAW,GAAG,YAAY,CAAC;AACjC,MAAM,4BAA4B,GAAG,CAAC,GAAG,IAAI,CAAC;AAC9C,MAAM,4BAA4B,GAAG,EAAE,CAAC;AACxC,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAS,iBAAiB,CAAC,MAAe,EAAE,IAAa;IACxD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,KAAK,GAAG,CAAC,IAAa,EAAE,KAAc,EAAE,IAAY,EAAQ,EAAE;QACnE,IAAI,KAAK,CAAC,MAAM,IAAI,eAAe,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,OAAO;QAC/D,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/B,yEAAyE;YACzE,qEAAqE;YACrE,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,OAAgB,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC;YACxG,IAAI,KAAK,KAAK,IAAI,IAA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,UAAU,CAAC,OAAO,CACjB,UAAU,EACV,MAAM,EACN,MAAM,EACN,QAAQ,EACR,GAAG,IAAK,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,CAA0B,CACjE;KACF,CAAC;AACH,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,mBAAmB,CAClC,WAAuC,EACvC,UAA+B;IAE/B,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,kBAAkB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;AACpF,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iCAAiC,CAAC,IAAoB;IACrE,OAAO;QACN,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,UAAU,EAAE,IAAI,CAAC,UAAiB;QAClC,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,mBAAmB,EAAE,IAAI,CAAC,mBAAmB;QAC7C,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;QACvC,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC;KAC3G,CAAC;AACH,CAAC","sourcesContent":["import type { AgentTool, AgentToolResult, AgentToolUpdateCallback } from \"@earendil-works/pi-agent-core\";\nimport { type JsonObject, validateToolArguments } from \"@earendil-works/pi-ai\";\nimport type { Static, TSchema } from \"typebox\";\nimport type { ExtensionToolContext, ToolDefinition } from \"../extensions/types.ts\";\nimport { truncateHead } from \"./truncate.ts\";\n\n/**\n * An `AgentTool` with a TypeBox parameter schema whose `execute` and `prepareArguments` are typed by TypeBox's\n * `Static`, as the built-in tools are (pi-agent-core types `params` through pi-schema, which maps only the common\n * TypeBox kinds). Spreads into a `ToolDefinition` of the same schema.\n */\nexport type TypeBoxAgentTool<TParams extends TSchema = TSchema, TDetails = any> = Omit<\n\tAgentTool<TParams, TDetails>,\n\t\"prepareArguments\" | \"execute\"\n> & {\n\tprepareArguments?: (args: unknown) => Static<TParams>;\n\texecute: (\n\t\ttoolCallId: string,\n\t\tparams: Static<TParams>,\n\t\tsignal?: AbortSignal,\n\t\tonUpdate?: AgentToolUpdateCallback<TDetails>,\n\t) => Promise<AgentToolResult<TDetails>>;\n};\n\n/** Creates the context for one tool call. */\nexport type ToolContextFactory = (toolCallId: string, signal: AbortSignal | undefined) => ExtensionToolContext;\n\nconst RECEIVED_ARGUMENTS_MARKER = \"\\n\\nReceived arguments:\\n\";\nconst HINT_MARKER = \"\\n\\nHint: \";\nconst RECEIVED_ARGUMENTS_MAX_BYTES = 2 * 1024;\nconst RECEIVED_ARGUMENTS_MAX_LINES = 40;\nconst FIELD_HINTS_MAX = 10;\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\n/**\n * Walk schema and arguments in sync to name, at every object with\n * `additionalProperties: false`, the non-null fields the schema does not\n * declare, and at every object, the required fields the arguments lack. The\n * validator's own report says where validation failed; these hints say what\n * the legal shape is. Union variants (`anyOf`, e.g. a nullable field) are\n * walked through so nested shapes still get hints. Paths use the validator's\n * dotted style (`tasks.0.prompt`). Non-null unknown fields are reported rather than\n * silently dropped: a field like `prompt_extra` may carry briefing content\n * the caller intended to send.\n */\nfunction collectFieldHints(schema: unknown, args: unknown): string[] {\n\tconst hints: string[] = [];\n\tconst visit = (node: unknown, value: unknown, path: string): void => {\n\t\tif (hints.length >= FIELD_HINTS_MAX || !isRecord(node)) return;\n\t\tif (Array.isArray(node.anyOf)) {\n\t\t\t// Only nullable single-shape unions have unambiguous field requirements.\n\t\t\t// Alternative object shapes must not contribute contradictory hints.\n\t\t\tconst variants = node.anyOf.filter((variant: unknown) => !isRecord(variant) || variant.type !== \"null\");\n\t\t\tif (value !== null && variants.length === 1) visit(variants[0], value, path);\n\t\t\treturn;\n\t\t}\n\t\tif (node.type === \"array\" && Array.isArray(value)) {\n\t\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\t\tvisit(node.items, value[index], `${path}.${index}`);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (node.type !== \"object\" || !isRecord(value)) return;\n\t\tconst properties = isRecord(node.properties) ? node.properties : {};\n\t\tconst fields = Object.keys(properties);\n\t\tconst where = path || \"root\";\n\t\tif (node.additionalProperties === false) {\n\t\t\tfor (const [key, entry] of Object.entries(value)) {\n\t\t\t\tif (entry !== null && !(key in properties) && hints.length < FIELD_HINTS_MAX) {\n\t\t\t\t\tconst subject = path ? `${path}.${key}` : key;\n\t\t\t\t\thints.push(`${subject} is not a field; fields at ${where}: ${fields.join(\", \")}`);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (Array.isArray(node.required)) {\n\t\t\tfor (const key of node.required) {\n\t\t\t\tif (typeof key === \"string\" && value[key] === undefined && hints.length < FIELD_HINTS_MAX) {\n\t\t\t\t\tconst subject = path ? `${path}.${key}` : key;\n\t\t\t\t\thints.push(`${subject} is required; fields at ${where}: ${fields.join(\", \")}`);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (const key of fields) {\n\t\t\tif (value[key] !== undefined && value[key] !== null) {\n\t\t\t\tvisit(properties[key], value[key], path ? `${path}.${key}` : key);\n\t\t\t}\n\t\t}\n\t};\n\tvisit(schema, args, \"\");\n\treturn hints;\n}\n\n/**\n * Rebuild pi-ai's validation error so a model can self-correct: the legal\n * fields are named next to each offending one, and the echoed arguments are\n * bounded (a 50KB tool argument must not be reflected whole into context).\n * The `Validation failed for tool \"<name>\":` prefix stays intact — the\n * question tool's renderer parses it.\n */\nfunction enrichValidationError(error: unknown, parameters: TSchema, args: unknown): Error {\n\tconst message = error instanceof Error ? error.message : String(error);\n\t// A definition synthesized from an already-wrapped tool enriches on the\n\t// inside; do not stack a second layer of hints on the same failure.\n\tif (message.includes(HINT_MARKER)) return error instanceof Error ? error : new Error(message);\n\tconst hints = collectFieldHints(parameters, args);\n\tconst markerIndex = message.indexOf(RECEIVED_ARGUMENTS_MARKER);\n\tconst head = markerIndex === -1 ? message : message.slice(0, markerIndex);\n\tconst received = markerIndex === -1 ? \"\" : message.slice(markerIndex + RECEIVED_ARGUMENTS_MARKER.length);\n\tlet enriched = hints.length > 0 ? `${head}\\n\\nHint: ${hints.join(\"\\nHint: \")}` : head;\n\tif (markerIndex !== -1) {\n\t\tconst bounded = truncateHead(received, {\n\t\t\tmaxBytes: RECEIVED_ARGUMENTS_MAX_BYTES,\n\t\t\tmaxLines: RECEIVED_ARGUMENTS_MAX_LINES,\n\t\t});\n\t\tenriched += `${RECEIVED_ARGUMENTS_MARKER}${bounded.content}`;\n\t\tif (bounded.truncated) enriched += \"\\n… (arguments truncated)\";\n\t}\n\treturn new Error(enriched);\n}\n\n/**\n * Pre-validate prepared arguments so a validation failure reaches the model\n * with field-level hints. Valid arguments pass through untouched and are\n * validated again by the agent loop as before.\n */\nfunction wrapPrepareArguments(definition: ToolDefinition<any, any>): (raw: unknown) => unknown {\n\tconst tool = { name: definition.name, description: definition.description, parameters: definition.parameters };\n\treturn (raw: unknown): unknown => {\n\t\tconst args = definition.prepareArguments ? definition.prepareArguments(raw) : raw;\n\t\ttry {\n\t\t\tvalidateToolArguments(tool, {\n\t\t\t\ttype: \"toolCall\",\n\t\t\t\tid: \"\",\n\t\t\t\tname: definition.name,\n\t\t\t\targuments: args as JsonObject,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tthrow enrichValidationError(error, definition.parameters, args);\n\t\t}\n\t\treturn args;\n\t};\n}\n\n/** Wrap a ToolDefinition into an AgentTool for the core runtime. */\nexport function wrapToolDefinition<TDetails = unknown>(\n\tdefinition: ToolDefinition<any, TDetails>,\n\tctxFactory?: ToolContextFactory,\n): AgentTool<any, TDetails> {\n\treturn {\n\t\tname: definition.name,\n\t\tlabel: definition.label,\n\t\tdescription: definition.description,\n\t\tparameters: definition.parameters,\n\t\toutputSchema: definition.outputSchema,\n\t\tconstrainedSampling: definition.constrainedSampling,\n\t\tprepareArguments: wrapPrepareArguments(definition),\n\t\texecutionMode: definition.executionMode,\n\t\texecute: (toolCallId, params, signal, onUpdate, ctx?: ExtensionToolContext) =>\n\t\t\tdefinition.execute(\n\t\t\t\ttoolCallId,\n\t\t\t\tparams,\n\t\t\t\tsignal,\n\t\t\t\tonUpdate,\n\t\t\t\tctx ?? (ctxFactory?.(toolCallId, signal) as ExtensionToolContext),\n\t\t\t),\n\t};\n}\n\n/** Wrap multiple ToolDefinitions into AgentTools for the core runtime. */\nexport function wrapToolDefinitions(\n\tdefinitions: ToolDefinition<any, any>[],\n\tctxFactory?: ToolContextFactory,\n): AgentTool<any>[] {\n\treturn definitions.map((definition) => wrapToolDefinition(definition, ctxFactory));\n}\n\n/**\n * Synthesize a minimal ToolDefinition from an AgentTool.\n *\n * This keeps AgentSession's internal registry definition-first even when a caller\n * provides plain AgentTool overrides that do not include prompt metadata or renderers.\n */\nexport function createToolDefinitionFromAgentTool(tool: AgentTool<any>): ToolDefinition<any, unknown> {\n\treturn {\n\t\tname: tool.name,\n\t\tlabel: tool.label,\n\t\tdescription: tool.description,\n\t\tparameters: tool.parameters as any,\n\t\toutputSchema: tool.outputSchema,\n\t\tconstrainedSampling: tool.constrainedSampling,\n\t\tprepareArguments: tool.prepareArguments,\n\t\texecutionMode: tool.executionMode,\n\t\texecute: async (toolCallId, params, signal, onUpdate) => tool.execute(toolCallId, params, signal, onUpdate),\n\t};\n}\n"]}
@@ -1,6 +1,6 @@
1
- import type { AgentTool } from "@earendil-works/pi-agent-core";
2
1
  import { type Static, Type } from "typebox";
3
2
  import type { ToolDefinition } from "../extensions/types.ts";
3
+ import { type TypeBoxAgentTool } from "./tool-definition-wrapper.ts";
4
4
  declare const writeSchema: Type.TObject<{
5
5
  path: Type.TString;
6
6
  content: Type.TString;
@@ -25,6 +25,6 @@ export interface WriteToolOptions {
25
25
  operations?: WriteOperations;
26
26
  }
27
27
  export declare function createWriteToolDefinition(cwd: string, options?: WriteToolOptions): ToolDefinition<typeof writeSchema, undefined>;
28
- export declare function createWriteTool(cwd: string, options?: WriteToolOptions): AgentTool<typeof writeSchema>;
28
+ export declare function createWriteTool(cwd: string, options?: WriteToolOptions): TypeBoxAgentTool<typeof writeSchema>;
29
29
  export {};
30
30
  //# sourceMappingURL=write.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/core/tools/write.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAG/D,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAoB,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAM/E,QAAA,MAAM,WAAW;;;EAGf,CAAC;AAEH,eAAO,MAAM,iCAAiC;;;CAGpC,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,CAAC;AAExD;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B,8BAA8B;IAC9B,SAAS,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE,mCAAmC;IACnC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC;AAOD,MAAM,WAAW,gBAAgB;IAChC,oEAAoE;IACpE,UAAU,CAAC,EAAE,eAAe,CAAC;CAC7B;AAED,wBAAgB,yBAAyB,CACxC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,gBAAgB,GACxB,cAAc,CAAC,OAAO,WAAW,EAAE,SAAS,CAAC,CA8C/C;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC,OAAO,WAAW,CAAC,CAEtG"}
1
+ {"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/core/tools/write.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAoB,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAI/E,OAAO,EAAE,KAAK,gBAAgB,EAAsB,MAAM,8BAA8B,CAAC;AAEzF,QAAA,MAAM,WAAW;;;EAGf,CAAC;AAEH,eAAO,MAAM,iCAAiC;;;CAGpC,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,CAAC;AAExD;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B,8BAA8B;IAC9B,SAAS,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE,mCAAmC;IACnC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC;AAOD,MAAM,WAAW,gBAAgB;IAChC,oEAAoE;IACpE,UAAU,CAAC,EAAE,eAAe,CAAC;CAC7B;AAED,wBAAgB,yBAAyB,CACxC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,gBAAgB,GACxB,cAAc,CAAC,OAAO,WAAW,EAAE,SAAS,CAAC,CA8C/C;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,gBAAgB,CAAC,OAAO,WAAW,CAAC,CAE7G"}
@@ -1 +1 @@
1
- {"version":3,"file":"write.js","sourceRoot":"","sources":["../../../src/core/tools/write.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,OAAO,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AC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AACpE,CAAC","sourcesContent":["import type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport { mkdir as fsMkdir, writeFile as fsWriteFile } from \"fs/promises\";\nimport { dirname } from \"path\";\nimport { type Static, Type } from \"typebox\";\nimport type { ExtensionContext, ToolDefinition } from \"../extensions/types.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { writeRenderers } from \"./renderers/write.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst writeSchema = Type.Object({\n\tpath: Type.String({ description: \"Path to the file to write (relative or absolute)\" }),\n\tcontent: Type.String({ description: \"Content to write to the file\" }),\n});\n\nexport const writeToolSystemPromptContribution = {\n\tsnippet: \"Create or overwrite files\",\n\tguidelines: [\"Use write only for new files or complete rewrites.\"],\n} as const;\n\nexport type WriteToolInput = Static<typeof writeSchema>;\n\n/**\n * Pluggable operations for the write tool.\n * Override these to delegate file writing to remote systems (for example SSH).\n */\nexport interface WriteOperations {\n\t/** Write content to a file */\n\twriteFile: (absolutePath: string, content: string) => Promise<void>;\n\t/** Create directory recursively */\n\tmkdir: (dir: string) => Promise<void>;\n}\n\nconst defaultWriteOperations: WriteOperations = {\n\twriteFile: (path, content) => fsWriteFile(path, content, \"utf-8\"),\n\tmkdir: (dir) => fsMkdir(dir, { recursive: true }).then(() => {}),\n};\n\nexport interface WriteToolOptions {\n\t/** Custom operations for file writing. Default: local filesystem */\n\toperations?: WriteOperations;\n}\n\nexport function createWriteToolDefinition(\n\tcwd: string,\n\toptions?: WriteToolOptions,\n): ToolDefinition<typeof writeSchema, undefined> {\n\tconst ops = options?.operations ?? defaultWriteOperations;\n\treturn {\n\t\tname: \"write\",\n\t\tlabel: \"write\",\n\t\tdescription:\n\t\t\t\"Write content to a file. Creates the file if it doesn't exist, overwrites if it does. Automatically creates parent directories.\",\n\t\tpromptSnippet: writeToolSystemPromptContribution.snippet,\n\t\tpromptGuidelines: [...writeToolSystemPromptContribution.guidelines],\n\t\tparameters: writeSchema,\n\t\tconstrainedSampling: { type: \"json_schema\", strict: \"prefer\" },\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ path, content }: { path: string; content: string },\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\tctx?: ExtensionContext,\n\t\t) {\n\t\t\tconst absolutePath = resolveToCwd(path, ctx?.cwd || cwd);\n\t\t\tconst dir = dirname(absolutePath);\n\t\t\treturn withFileMutationQueue(absolutePath, async () => {\n\t\t\t\t// Do not reject from an abort event listener here: that would release the\n\t\t\t\t// mutation queue while an in-flight filesystem operation may still finish.\n\t\t\t\t// Checking signal.aborted after each await observes the same aborts while\n\t\t\t\t// keeping the queue locked until the current operation has settled.\n\t\t\t\tconst throwIfAborted = (): void => {\n\t\t\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\t\t};\n\n\t\t\t\tthrowIfAborted();\n\t\t\t\t// Create parent directories if needed.\n\t\t\t\tawait ops.mkdir(dir);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Write the file contents.\n\t\t\t\tawait ops.writeFile(absolutePath, content);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: `Successfully wrote to ${path}` }],\n\t\t\t\t\tdetails: undefined,\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\t...writeRenderers,\n\t};\n}\n\nexport function createWriteTool(cwd: string, options?: WriteToolOptions): AgentTool<typeof writeSchema> {\n\treturn wrapToolDefinition(createWriteToolDefinition(cwd, options));\n}\n"]}
1
+ {"version":3,"file":"write.js","sourceRoot":"","sources":["../../../src/core/tools/write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,M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, writeFile as fsWriteFile } from \"fs/promises\";\nimport { dirname } from \"path\";\nimport { type Static, Type } from \"typebox\";\nimport type { ExtensionContext, ToolDefinition } from \"../extensions/types.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { writeRenderers } from \"./renderers/write.ts\";\nimport { type TypeBoxAgentTool, wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst writeSchema = Type.Object({\n\tpath: Type.String({ description: \"Path to the file to write (relative or absolute)\" }),\n\tcontent: Type.String({ description: \"Content to write to the file\" }),\n});\n\nexport const writeToolSystemPromptContribution = {\n\tsnippet: \"Create or overwrite files\",\n\tguidelines: [\"Use write only for new files or complete rewrites.\"],\n} as const;\n\nexport type WriteToolInput = Static<typeof writeSchema>;\n\n/**\n * Pluggable operations for the write tool.\n * Override these to delegate file writing to remote systems (for example SSH).\n */\nexport interface WriteOperations {\n\t/** Write content to a file */\n\twriteFile: (absolutePath: string, content: string) => Promise<void>;\n\t/** Create directory recursively */\n\tmkdir: (dir: string) => Promise<void>;\n}\n\nconst defaultWriteOperations: WriteOperations = {\n\twriteFile: (path, content) => fsWriteFile(path, content, \"utf-8\"),\n\tmkdir: (dir) => fsMkdir(dir, { recursive: true }).then(() => {}),\n};\n\nexport interface WriteToolOptions {\n\t/** Custom operations for file writing. Default: local filesystem */\n\toperations?: WriteOperations;\n}\n\nexport function createWriteToolDefinition(\n\tcwd: string,\n\toptions?: WriteToolOptions,\n): ToolDefinition<typeof writeSchema, undefined> {\n\tconst ops = options?.operations ?? defaultWriteOperations;\n\treturn {\n\t\tname: \"write\",\n\t\tlabel: \"write\",\n\t\tdescription:\n\t\t\t\"Write content to a file. Creates the file if it doesn't exist, overwrites if it does. Automatically creates parent directories.\",\n\t\tpromptSnippet: writeToolSystemPromptContribution.snippet,\n\t\tpromptGuidelines: [...writeToolSystemPromptContribution.guidelines],\n\t\tparameters: writeSchema,\n\t\tconstrainedSampling: { type: \"json_schema\", strict: \"prefer\" },\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ path, content }: { path: string; content: string },\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\tctx?: ExtensionContext,\n\t\t) {\n\t\t\tconst absolutePath = resolveToCwd(path, ctx?.cwd || cwd);\n\t\t\tconst dir = dirname(absolutePath);\n\t\t\treturn withFileMutationQueue(absolutePath, async () => {\n\t\t\t\t// Do not reject from an abort event listener here: that would release the\n\t\t\t\t// mutation queue while an in-flight filesystem operation may still finish.\n\t\t\t\t// Checking signal.aborted after each await observes the same aborts while\n\t\t\t\t// keeping the queue locked until the current operation has settled.\n\t\t\t\tconst throwIfAborted = (): void => {\n\t\t\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\t\t};\n\n\t\t\t\tthrowIfAborted();\n\t\t\t\t// Create parent directories if needed.\n\t\t\t\tawait ops.mkdir(dir);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Write the file contents.\n\t\t\t\tawait ops.writeFile(absolutePath, content);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: `Successfully wrote to ${path}` }],\n\t\t\t\t\tdetails: undefined,\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\t...writeRenderers,\n\t};\n}\n\nexport function createWriteTool(cwd: string, options?: WriteToolOptions): TypeBoxAgentTool<typeof writeSchema> {\n\treturn wrapToolDefinition(createWriteToolDefinition(cwd, options));\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"trust-manager.d.ts","sourceRoot":"","sources":["../../src/core/trust-manager.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,IAAI,CAAC;AAElD,MAAM,WAAW,sBAAsB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IAClC,IAAI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