pi-namespace-patch 1.5.2-namespace.1 → 1.6.1-namespace.1

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 (353) hide show
  1. package/CHANGELOG.md +147 -0
  2. package/README.md +5 -5
  3. package/dist/bundle/chunks/anthropic-messages-NVZIQUC2.js +3 -0
  4. package/dist/bundle/chunks/azure-openai-responses-NLMT4M2I.js +2 -0
  5. package/dist/bundle/chunks/bedrock-converse-stream.js +5 -5
  6. package/dist/bundle/chunks/{chunk-AUUCDC7R.js → chunk-254Q5KJY.js} +2 -2
  7. package/dist/bundle/chunks/chunk-2BKJ4UF2.js +6 -0
  8. package/dist/bundle/chunks/{chunk-RKNK4Y6L.js → chunk-5QZEKD66.js} +1 -1
  9. package/dist/bundle/chunks/chunk-ASV47SSA.js +2 -0
  10. package/dist/bundle/chunks/chunk-DPMEYYP2.js +20 -0
  11. package/dist/bundle/chunks/chunk-DQUOASJG.js +2 -0
  12. package/dist/bundle/chunks/{chunk-4UNPP53I.js → chunk-ESCXDUHA.js} +2 -2
  13. package/dist/bundle/chunks/chunk-FZUFSFVS.js +44 -0
  14. package/dist/bundle/chunks/{chunk-FF6XOTWB.js → chunk-GH2VPQ2P.js} +14 -12
  15. package/dist/bundle/chunks/{chunk-WL4TUXY7.js → chunk-HID5BUPP.js} +1 -1
  16. package/dist/bundle/chunks/chunk-HRA5GXRL.js +9 -0
  17. package/dist/bundle/chunks/{chunk-ITPADMEB.js → chunk-HXTNJVK4.js} +104 -106
  18. package/dist/bundle/chunks/chunk-INODY4DR.js +2 -0
  19. package/dist/bundle/chunks/chunk-JIUMJLB6.js +16 -0
  20. package/dist/bundle/chunks/chunk-LWG2CUTI.js +31 -0
  21. package/dist/bundle/chunks/{chunk-VKJQ6CME.js → chunk-O5MXS5TI.js} +1 -1
  22. package/dist/bundle/chunks/chunk-OVXT2WQH.js +2 -0
  23. package/dist/bundle/chunks/chunk-QQT7J23Q.js +30 -0
  24. package/dist/bundle/chunks/{chunk-BT5GUSNR.js → chunk-S6XQ4444.js} +1 -1
  25. package/dist/bundle/chunks/chunk-TRIUHDLU.js +2 -0
  26. package/dist/bundle/chunks/{chunk-FMPAMX2W.js → chunk-VUZTGLGT.js} +1 -1
  27. package/dist/bundle/chunks/chunk-WLFBMTZ5.js +14 -0
  28. package/dist/bundle/chunks/{cli-CJJQRPM4.js → cli-IFNPONCI.js} +1 -1
  29. package/dist/bundle/chunks/cloudflare-workers-ai-system-one-K5LZ2XIM.js +2 -0
  30. package/dist/bundle/chunks/{easter-egg-3d-GEVPKQF6.js → easter-egg-3d-JQSUSCKG.js} +1 -1
  31. package/dist/bundle/chunks/{execute-L2EEDV3L.js → execute-GM225T4M.js} +1 -1
  32. package/dist/bundle/chunks/github-copilot.js +1 -1
  33. package/dist/bundle/chunks/google-generative-ai-JMDVNM52.js +2 -0
  34. package/dist/bundle/chunks/google-vertex-RO3RU6D4.js +2 -0
  35. package/dist/bundle/chunks/{llama-cpp-classify-EJXCQRUQ.js → llama-cpp-classify-V63YXBKJ.js} +2 -2
  36. package/dist/bundle/chunks/mistral-conversations-5QQ525XP.js +4 -0
  37. package/dist/bundle/chunks/openai-codex-responses-3OSG4LCA.js +2 -0
  38. package/dist/bundle/chunks/{openai-completions-HRZOSLBO.js → openai-completions-CDC7XEM5.js} +2 -2
  39. package/dist/bundle/chunks/{openai-decisions-F66BDLOM.js → openai-decisions-QKZUXNGS.js} +1 -1
  40. package/dist/bundle/chunks/openai-responses-3TUDNSSR.js +4 -0
  41. package/dist/bundle/chunks/openrouter-images-WOQ26ANM.js +2 -0
  42. package/dist/bundle/chunks/pi-decision-DNF2KAXD.js +2 -0
  43. package/dist/bundle/chunks/pi-messages-PQC5SMWL.js +2 -0
  44. package/dist/bundle/chunks/{runtime-J5ZSBGTX.js → runtime-T6TR2GDO.js} +1 -1
  45. package/dist/bundle/chunks/typesafe-system-one-Z5B3PAXZ.js +2 -0
  46. package/dist/bundle/chunks/virtual-modules-SNXUCAHU.js +2 -0
  47. package/dist/bundle/cli-runtime.js +1 -1
  48. package/dist/bundle/index.js +1 -1
  49. package/dist/bundle/rpc-entry.js +1 -1
  50. package/dist/cli/args.d.ts.map +1 -1
  51. package/dist/cli/args.js +4 -2
  52. package/dist/cli/args.js.map +1 -1
  53. package/dist/cli/config-selector.d.ts.map +1 -1
  54. package/dist/cli/config-selector.js +9 -6
  55. package/dist/cli/config-selector.js.map +1 -1
  56. package/dist/cli/project-trust.d.ts.map +1 -1
  57. package/dist/cli/project-trust.js +6 -6
  58. package/dist/cli/project-trust.js.map +1 -1
  59. package/dist/cli/session-picker.d.ts.map +1 -1
  60. package/dist/cli/session-picker.js +9 -6
  61. package/dist/cli/session-picker.js.map +1 -1
  62. package/dist/cli/startup-ui.d.ts +3 -2
  63. package/dist/cli/startup-ui.d.ts.map +1 -1
  64. package/dist/cli/startup-ui.js +21 -23
  65. package/dist/cli/startup-ui.js.map +1 -1
  66. package/dist/core/agent-session-runtime.d.ts +11 -0
  67. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  68. package/dist/core/agent-session-runtime.js +19 -0
  69. package/dist/core/agent-session-runtime.js.map +1 -1
  70. package/dist/core/agent-session.d.ts +6 -3
  71. package/dist/core/agent-session.d.ts.map +1 -1
  72. package/dist/core/agent-session.js +22 -13
  73. package/dist/core/agent-session.js.map +1 -1
  74. package/dist/core/auth-storage.d.ts.map +1 -1
  75. package/dist/core/auth-storage.js +7 -1
  76. package/dist/core/auth-storage.js.map +1 -1
  77. package/dist/core/bash-executor.d.ts +3 -1
  78. package/dist/core/bash-executor.d.ts.map +1 -1
  79. package/dist/core/bash-executor.js +24 -13
  80. package/dist/core/bash-executor.js.map +1 -1
  81. package/dist/core/exec.d.ts +1 -0
  82. package/dist/core/exec.d.ts.map +1 -1
  83. package/dist/core/exec.js +4 -1
  84. package/dist/core/exec.js.map +1 -1
  85. package/dist/core/export-html/ansi-to-html.d.ts +6 -1
  86. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
  87. package/dist/core/export-html/ansi-to-html.js +57 -20
  88. package/dist/core/export-html/ansi-to-html.js.map +1 -1
  89. package/dist/core/export-html/template.js +1 -1
  90. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  91. package/dist/core/export-html/tool-renderer.js +2 -3
  92. package/dist/core/export-html/tool-renderer.js.map +1 -1
  93. package/dist/core/extensions/loader.d.ts.map +1 -1
  94. package/dist/core/extensions/loader.js +18 -1
  95. package/dist/core/extensions/loader.js.map +1 -1
  96. package/dist/core/extensions/runner.d.ts.map +1 -1
  97. package/dist/core/extensions/runner.js +7 -1
  98. package/dist/core/extensions/runner.js.map +1 -1
  99. package/dist/core/extensions/types.d.ts +14 -1
  100. package/dist/core/extensions/types.d.ts.map +1 -1
  101. package/dist/core/extensions/types.js.map +1 -1
  102. package/dist/core/messages.d.ts +4 -0
  103. package/dist/core/messages.d.ts.map +1 -1
  104. package/dist/core/messages.js +10 -2
  105. package/dist/core/messages.js.map +1 -1
  106. package/dist/core/model-resolver.d.ts +0 -8
  107. package/dist/core/model-resolver.d.ts.map +1 -1
  108. package/dist/core/model-resolver.js +4 -68
  109. package/dist/core/model-resolver.js.map +1 -1
  110. package/dist/core/model-runtime.d.ts.map +1 -1
  111. package/dist/core/model-runtime.js +6 -2
  112. package/dist/core/model-runtime.js.map +1 -1
  113. package/dist/core/package-manager.d.ts +16 -0
  114. package/dist/core/package-manager.d.ts.map +1 -1
  115. package/dist/core/package-manager.js +45 -2
  116. package/dist/core/package-manager.js.map +1 -1
  117. package/dist/core/project-trust.d.ts.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/provider-composer.d.ts +1 -0
  121. package/dist/core/provider-composer.d.ts.map +1 -1
  122. package/dist/core/provider-composer.js.map +1 -1
  123. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  124. package/dist/core/remote-catalog-provider.js +7 -0
  125. package/dist/core/remote-catalog-provider.js.map +1 -1
  126. package/dist/core/resolve-config-value.d.ts +2 -0
  127. package/dist/core/resolve-config-value.d.ts.map +1 -1
  128. package/dist/core/resolve-config-value.js +4 -0
  129. package/dist/core/resolve-config-value.js.map +1 -1
  130. package/dist/core/resource-loader.d.ts +5 -1
  131. package/dist/core/resource-loader.d.ts.map +1 -1
  132. package/dist/core/resource-loader.js +2 -0
  133. package/dist/core/resource-loader.js.map +1 -1
  134. package/dist/core/session-manager.d.ts.map +1 -1
  135. package/dist/core/session-manager.js +55 -42
  136. package/dist/core/session-manager.js.map +1 -1
  137. package/dist/core/settings-defaults.d.ts +6 -1
  138. package/dist/core/settings-defaults.d.ts.map +1 -1
  139. package/dist/core/settings-defaults.js +6 -1
  140. package/dist/core/settings-defaults.js.map +1 -1
  141. package/dist/core/settings-manager.d.ts +6 -4
  142. package/dist/core/settings-manager.d.ts.map +1 -1
  143. package/dist/core/settings-manager.js +23 -8
  144. package/dist/core/settings-manager.js.map +1 -1
  145. package/dist/core/settings-schema.d.ts +16 -2
  146. package/dist/core/settings-schema.d.ts.map +1 -1
  147. package/dist/core/settings-schema.js +23 -4
  148. package/dist/core/settings-schema.js.map +1 -1
  149. package/dist/core/tools/bash.d.ts +3 -0
  150. package/dist/core/tools/bash.d.ts.map +1 -1
  151. package/dist/core/tools/bash.js +24 -9
  152. package/dist/core/tools/bash.js.map +1 -1
  153. package/dist/core/tools/find.d.ts.map +1 -1
  154. package/dist/core/tools/find.js +27 -16
  155. package/dist/core/tools/find.js.map +1 -1
  156. package/dist/core/tools/grep.js +1 -1
  157. package/dist/core/tools/grep.js.map +1 -1
  158. package/dist/core/tools/output-accumulator.d.ts +16 -4
  159. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  160. package/dist/core/tools/output-accumulator.js +47 -38
  161. package/dist/core/tools/output-accumulator.js.map +1 -1
  162. package/dist/core/tools/read.d.ts +5 -0
  163. package/dist/core/tools/read.d.ts.map +1 -1
  164. package/dist/core/tools/read.js +10 -15
  165. package/dist/core/tools/read.js.map +1 -1
  166. package/dist/core/tools/renderers/bash.d.ts.map +1 -1
  167. package/dist/core/tools/renderers/bash.js +9 -3
  168. package/dist/core/tools/renderers/bash.js.map +1 -1
  169. package/dist/core/tools/renderers/read.d.ts.map +1 -1
  170. package/dist/core/tools/renderers/read.js +6 -2
  171. package/dist/core/tools/renderers/read.js.map +1 -1
  172. package/dist/core/tools/truncate.d.ts +1 -1
  173. package/dist/core/tools/truncate.d.ts.map +1 -1
  174. package/dist/core/tools/truncate.js +11 -5
  175. package/dist/core/tools/truncate.js.map +1 -1
  176. package/dist/extensions/llama/client.d.ts.map +1 -1
  177. package/dist/extensions/llama/client.js +3 -13
  178. package/dist/extensions/llama/client.js.map +1 -1
  179. package/dist/extensions/llama/provider.d.ts +1 -1
  180. package/dist/extensions/llama/provider.d.ts.map +1 -1
  181. package/dist/extensions/llama/provider.js +6 -4
  182. package/dist/extensions/llama/provider.js.map +1 -1
  183. package/dist/extensions/mcp/index.d.ts.map +1 -1
  184. package/dist/extensions/mcp/index.js +4 -7
  185. package/dist/extensions/mcp/index.js.map +1 -1
  186. package/dist/extensions/mcp/resources.d.ts.map +1 -1
  187. package/dist/extensions/mcp/resources.js +3 -3
  188. package/dist/extensions/mcp/resources.js.map +1 -1
  189. package/dist/extensions/mcp/tools.d.ts +1 -9
  190. package/dist/extensions/mcp/tools.d.ts.map +1 -1
  191. package/dist/extensions/mcp/tools.js +8 -124
  192. package/dist/extensions/mcp/tools.js.map +1 -1
  193. package/dist/main.d.ts.map +1 -1
  194. package/dist/main.js +40 -17
  195. package/dist/main.js.map +1 -1
  196. package/dist/modes/diagnostics-stderr.d.ts +4 -0
  197. package/dist/modes/diagnostics-stderr.d.ts.map +1 -0
  198. package/dist/modes/diagnostics-stderr.js +11 -0
  199. package/dist/modes/diagnostics-stderr.js.map +1 -0
  200. package/dist/modes/interactive/components/assistant-message.d.ts +2 -1
  201. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  202. package/dist/modes/interactive/components/assistant-message.js +9 -3
  203. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  204. package/dist/modes/interactive/components/bash-execution.d.ts +2 -1
  205. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  206. package/dist/modes/interactive/components/bash-execution.js +6 -3
  207. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  208. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  209. package/dist/modes/interactive/components/config-selector.js +5 -2
  210. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  211. package/dist/modes/interactive/components/first-time-setup.d.ts +3 -5
  212. package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -1
  213. package/dist/modes/interactive/components/first-time-setup.js +15 -45
  214. package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
  215. package/dist/modes/interactive/components/mermaid.d.ts.map +1 -1
  216. package/dist/modes/interactive/components/mermaid.js +13 -4
  217. package/dist/modes/interactive/components/mermaid.js.map +1 -1
  218. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  219. package/dist/modes/interactive/components/model-selector.js +5 -2
  220. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  221. package/dist/modes/interactive/components/oauth-selector.d.ts +14 -2
  222. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  223. package/dist/modes/interactive/components/oauth-selector.js +17 -12
  224. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  225. package/dist/modes/interactive/components/radius-login-selector.d.ts.map +1 -1
  226. package/dist/modes/interactive/components/radius-login-selector.js +2 -1
  227. package/dist/modes/interactive/components/radius-login-selector.js.map +1 -1
  228. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  229. package/dist/modes/interactive/components/scoped-models-selector.js +9 -1
  230. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  231. package/dist/modes/interactive/components/session-selector.d.ts +8 -1
  232. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  233. package/dist/modes/interactive/components/session-selector.js +41 -9
  234. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  235. package/dist/modes/interactive/components/settings-selector.d.ts +3 -3
  236. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  237. package/dist/modes/interactive/components/settings-selector.js +56 -35
  238. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  239. package/dist/modes/interactive/components/settings-submenu.d.ts +1 -1
  240. package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -1
  241. package/dist/modes/interactive/components/settings-submenu.js +5 -1
  242. package/dist/modes/interactive/components/settings-submenu.js.map +1 -1
  243. package/dist/modes/interactive/components/themed-text.d.ts +1 -1
  244. package/dist/modes/interactive/components/themed-text.d.ts.map +1 -1
  245. package/dist/modes/interactive/components/themed-text.js.map +1 -1
  246. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  247. package/dist/modes/interactive/components/thinking-selector.js +5 -1
  248. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  249. package/dist/modes/interactive/components/tool-execution.d.ts +1 -1
  250. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  251. package/dist/modes/interactive/components/tool-execution.js +3 -1
  252. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  253. package/dist/modes/interactive/components/user-message.d.ts +2 -1
  254. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  255. package/dist/modes/interactive/components/user-message.js +9 -3
  256. package/dist/modes/interactive/components/user-message.js.map +1 -1
  257. package/dist/modes/interactive/components/visual-truncate.d.ts +2 -2
  258. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
  259. package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
  260. package/dist/modes/interactive/external-editor.d.ts.map +1 -1
  261. package/dist/modes/interactive/external-editor.js +13 -3
  262. package/dist/modes/interactive/external-editor.js.map +1 -1
  263. package/dist/modes/interactive/interactive-mode.d.ts +1 -1
  264. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  265. package/dist/modes/interactive/interactive-mode.js +116 -70
  266. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  267. package/dist/modes/interactive/program-status-reporter.d.ts +2 -0
  268. package/dist/modes/interactive/program-status-reporter.d.ts.map +1 -1
  269. package/dist/modes/interactive/program-status-reporter.js +4 -0
  270. package/dist/modes/interactive/program-status-reporter.js.map +1 -1
  271. package/dist/modes/interactive/session-share.d.ts.map +1 -1
  272. package/dist/modes/interactive/session-share.js +11 -1
  273. package/dist/modes/interactive/session-share.js.map +1 -1
  274. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  275. package/dist/modes/interactive/theme/theme.js +1 -0
  276. package/dist/modes/interactive/theme/theme.js.map +1 -1
  277. package/dist/modes/print-mode.d.ts.map +1 -1
  278. package/dist/modes/print-mode.js +17 -17
  279. package/dist/modes/print-mode.js.map +1 -1
  280. package/dist/modes/rpc/jsonl.d.ts.map +1 -1
  281. package/dist/modes/rpc/jsonl.js +13 -13
  282. package/dist/modes/rpc/jsonl.js.map +1 -1
  283. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  284. package/dist/modes/rpc/rpc-mode.js +19 -27
  285. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  286. package/dist/package-manager-cli.d.ts.map +1 -1
  287. package/dist/package-manager-cli.js +24 -2
  288. package/dist/package-manager-cli.js.map +1 -1
  289. package/dist/utils/changelog.d.ts.map +1 -1
  290. package/dist/utils/changelog.js +3 -2
  291. package/dist/utils/changelog.js.map +1 -1
  292. package/dist/utils/clipboard.js +1 -1
  293. package/dist/utils/clipboard.js.map +1 -1
  294. package/dist/utils/flush-stdout.d.ts +8 -0
  295. package/dist/utils/flush-stdout.d.ts.map +1 -0
  296. package/dist/utils/flush-stdout.js +23 -0
  297. package/dist/utils/flush-stdout.js.map +1 -0
  298. package/dist/utils/output-files.d.ts +20 -4
  299. package/dist/utils/output-files.d.ts.map +1 -1
  300. package/dist/utils/output-files.js +37 -2
  301. package/dist/utils/output-files.js.map +1 -1
  302. package/dist/utils/shell.d.ts +2 -1
  303. package/dist/utils/shell.d.ts.map +1 -1
  304. package/dist/utils/shell.js +56 -7
  305. package/dist/utils/shell.js.map +1 -1
  306. package/docs/cli.md +1 -1
  307. package/docs/codemode.md +6 -4
  308. package/docs/extensions.md +18 -8
  309. package/docs/llama-cpp.md +3 -3
  310. package/docs/message-types.md +1 -0
  311. package/docs/models-configuration.md +14 -5
  312. package/docs/models.md +28 -10
  313. package/docs/nvidia-rtx-llama-cpp.md +5 -5
  314. package/docs/providers.md +7 -5
  315. package/docs/rpc-commands.md +2 -2
  316. package/docs/settings.md +4 -1
  317. package/docs/shell-aliases.md +1 -1
  318. package/docs/tui.md +2 -0
  319. package/docs/windows.md +2 -1
  320. package/examples/extensions/gondolin/index.ts +4 -7
  321. package/examples/extensions/subagent/index.ts +3 -2
  322. package/examples/rpc-extension-ui.ts +8 -7
  323. package/package.json +8 -8
  324. package/schemas/models.schema.json +4 -4
  325. package/schemas/settings.schema.json +30 -5
  326. package/dist/bundle/chunks/anthropic-messages-CA3HHOL3.js +0 -6
  327. package/dist/bundle/chunks/azure-openai-responses-76TWS6DT.js +0 -2
  328. package/dist/bundle/chunks/chunk-4KSTFUIK.js +0 -19
  329. package/dist/bundle/chunks/chunk-BAC3QPNW.js +0 -9
  330. package/dist/bundle/chunks/chunk-CF5GWZHW.js +0 -31
  331. package/dist/bundle/chunks/chunk-GFUN2N5K.js +0 -2
  332. package/dist/bundle/chunks/chunk-IQUU5XIT.js +0 -2
  333. package/dist/bundle/chunks/chunk-PMRZO46Y.js +0 -2
  334. package/dist/bundle/chunks/chunk-QN4TOIZN.js +0 -16
  335. package/dist/bundle/chunks/chunk-V7SLUK6A.js +0 -44
  336. package/dist/bundle/chunks/chunk-WU5T6NR4.js +0 -30
  337. package/dist/bundle/chunks/chunk-Y55SJART.js +0 -13
  338. package/dist/bundle/chunks/chunk-ZBIZYD6W.js +0 -2
  339. package/dist/bundle/chunks/chunk-ZGYS4UTC.js +0 -2
  340. package/dist/bundle/chunks/cloudflare-workers-ai-system-one-U4J7D646.js +0 -2
  341. package/dist/bundle/chunks/google-generative-ai-D5B6W47J.js +0 -2
  342. package/dist/bundle/chunks/google-vertex-U4H5YDEW.js +0 -2
  343. package/dist/bundle/chunks/mistral-conversations-S277EKLB.js +0 -5
  344. package/dist/bundle/chunks/openai-codex-responses-TEQRB65N.js +0 -10
  345. package/dist/bundle/chunks/openai-responses-BAKFWTGE.js +0 -4
  346. package/dist/bundle/chunks/openrouter-images-VXF5TVIK.js +0 -2
  347. package/dist/bundle/chunks/pi-messages-UBJKNDRN.js +0 -8
  348. package/dist/bundle/chunks/typesafe-system-one-56TEMIHL.js +0 -2
  349. package/dist/bundle/chunks/virtual-modules-PXSRIPHJ.js +0 -2
  350. package/dist/utils/deprecation.d.ts +0 -4
  351. package/dist/utils/deprecation.d.ts.map +0 -1
  352. package/dist/utils/deprecation.js +0 -13
  353. package/dist/utils/deprecation.js.map +0 -1
@@ -0,0 +1,23 @@
1
+ const STDOUT_FLUSH_TIMEOUT_MS = 1000;
2
+ /**
3
+ * Wait until stdout has written everything queued before this call, for at most one second.
4
+ * process.exit() drops queued writes, which include the terminal mode resets from stopping a TUI (#12133).
5
+ * The timeout keeps a stalled terminal from blocking exit. An empty write is used because "drain" only
6
+ * fires after a write filled the buffer.
7
+ */
8
+ export function flushStdout() {
9
+ return new Promise((resolve) => {
10
+ const finish = (error) => {
11
+ clearTimeout(timer);
12
+ // A failed write, e.g. EPIPE on a closed stdout, also emits "error" after its callback. Keep the
13
+ // listener then, so that event is not an uncaught exception.
14
+ if (!error)
15
+ process.stdout.off("error", finish);
16
+ resolve();
17
+ };
18
+ const timer = setTimeout(finish, STDOUT_FLUSH_TIMEOUT_MS);
19
+ process.stdout.on("error", finish);
20
+ process.stdout.write("", finish);
21
+ });
22
+ }
23
+ //# sourceMappingURL=flush-stdout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flush-stdout.js","sourceRoot":"","sources":["../../src/utils/flush-stdout.ts"],"names":[],"mappings":"AAAA,MAAM,uBAAuB,GAAG,IAAI,CAAC;AAErC;;;;;GAKG;AACH,MAAM,UAAU,WAAW;IAC1B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC9B,MAAM,MAAM,GAAG,CAAC,KAAoB,EAAQ,EAAE;YAC7C,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,iGAAiG;YACjG,6DAA6D;YAC7D,IAAI,CAAC,KAAK;gBAAE,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAChD,OAAO,EAAE,CAAC;QACX,CAAC,CAAC;QACF,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;QAC1D,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACnC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["const STDOUT_FLUSH_TIMEOUT_MS = 1000;\n\n/**\n * Wait until stdout has written everything queued before this call, for at most one second.\n * process.exit() drops queued writes, which include the terminal mode resets from stopping a TUI (#12133).\n * The timeout keeps a stalled terminal from blocking exit. An empty write is used because \"drain\" only\n * fires after a write filled the buffer.\n */\nexport function flushStdout(): Promise<void> {\n\treturn new Promise((resolve) => {\n\t\tconst finish = (error?: Error | null): void => {\n\t\t\tclearTimeout(timer);\n\t\t\t// A failed write, e.g. EPIPE on a closed stdout, also emits \"error\" after its callback. Keep the\n\t\t\t// listener then, so that event is not an uncaught exception.\n\t\t\tif (!error) process.stdout.off(\"error\", finish);\n\t\t\tresolve();\n\t\t};\n\t\tconst timer = setTimeout(finish, STDOUT_FLUSH_TIMEOUT_MS);\n\t\tprocess.stdout.on(\"error\", finish);\n\t\tprocess.stdout.write(\"\", finish);\n\t});\n}\n"]}
@@ -4,12 +4,28 @@
4
4
  * Every output file is created here, so where they are stored can change in one place. Today they
5
5
  * go to the OS temp directory.
6
6
  */
7
- import { type WriteStream } from "node:fs";
8
7
  /** Write `data` to a new output file and return its path. */
9
8
  export declare function writeOutputFile(prefix: string, extension: string, data: string | Uint8Array): Promise<string>;
10
- /** Open a new output file for streamed output. */
11
- export declare function createOutputFileStream(prefix: string, extension: string): {
9
+ /** Where streamed output ended up: a complete file, or why it could not be saved. */
10
+ export type OutputFileResult = {
11
+ kind: "saved";
12
12
  path: string;
13
- stream: WriteStream;
13
+ } | {
14
+ kind: "failed";
15
+ error: string;
14
16
  };
17
+ /**
18
+ * An output file written while output streams in. Open and write failures (full disk, quota, unwritable
19
+ * temp dir) never throw: they arrive later as stream events, and an unhandled one would crash the
20
+ * process. The first failure drops the file instead, and `close()` reports why.
21
+ */
22
+ export interface OutputFileStream {
23
+ /** `saved` while writing has not failed; the file is complete only once `close()` resolves. */
24
+ readonly result: OutputFileResult;
25
+ write(data: string | Uint8Array): void;
26
+ /** Flush and close the file. Never rejects. */
27
+ close(): Promise<OutputFileResult>;
28
+ }
29
+ /** Open a new output file for streamed output. */
30
+ export declare function createOutputFileStream(prefix: string, extension: string): OutputFileStream;
15
31
  //# sourceMappingURL=output-files.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"output-files.d.ts","sourceRoot":"","sources":["../../src/utils/output-files.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AAa9D,6DAA6D;AAC7D,wBAAsB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAKnH;AAED,kDAAkD;AAClD,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAE,CAG/G"}
1
+ {"version":3,"file":"output-files.d.ts","sourceRoot":"","sources":["../../src/utils/output-files.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgBH,6DAA6D;AAC7D,wBAAsB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAKnH;AAED,qFAAqF;AACrF,MAAM,MAAM,gBAAgB,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnG;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAChC,+FAA+F;IAC/F,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAClC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAAC;IACvC,+CAA+C;IAC/C,KAAK,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAAC;CACnC;AAED,kDAAkD;AAClD,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,gBAAgB,CAkC1F"}
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import { randomBytes } from "node:crypto";
8
8
  import { createWriteStream } from "node:fs";
9
- import { writeFile } from "node:fs/promises";
9
+ import { rm, writeFile } from "node:fs/promises";
10
10
  import { tmpdir } from "node:os";
11
11
  import { join } from "node:path";
12
12
  /** Output can carry private data, so only the user may read the files. */
@@ -25,6 +25,41 @@ export async function writeOutputFile(prefix, extension, data) {
25
25
  /** Open a new output file for streamed output. */
26
26
  export function createOutputFileStream(prefix, extension) {
27
27
  const path = createOutputFilePath(prefix, extension);
28
- return { path, stream: createWriteStream(path, { mode: OUTPUT_FILE_MODE, flags: "wx" }) };
28
+ const stream = createWriteStream(path, { mode: OUTPUT_FILE_MODE, flags: "wx" });
29
+ let result = { kind: "saved", path };
30
+ let opened = false;
31
+ let removed;
32
+ stream.once("open", () => {
33
+ opened = true;
34
+ });
35
+ stream.on("error", (cause) => {
36
+ if (result.kind === "saved")
37
+ result = { kind: "failed", error: cause.message };
38
+ // A partial file would pass for the full output. A failed open (`wx` found a file) leaves
39
+ // the path alone: whatever is there is not ours.
40
+ if (opened)
41
+ removed ??= rm(path, { force: true }).catch(() => { });
42
+ });
43
+ // `close`, not `finish`: closing the descriptor can still fail (delayed ENOSPC or EDQUOT on quota,
44
+ // NFS or FUSE file systems), and that error comes after `finish`. It always comes before `close`.
45
+ const closed = new Promise((resolve) => stream.once("close", resolve));
46
+ return {
47
+ get result() {
48
+ return result;
49
+ },
50
+ write(data) {
51
+ // Not after a failure, and not after `close()`: a write after `end()` would fail the file.
52
+ if (result.kind === "saved" && stream.writable)
53
+ stream.write(data);
54
+ },
55
+ async close() {
56
+ // A stream destroyed by an error is already closing; `end()` would do nothing.
57
+ if (!stream.destroyed)
58
+ stream.end();
59
+ await closed;
60
+ await removed;
61
+ return result;
62
+ },
63
+ };
29
64
  }
30
65
  //# sourceMappingURL=output-files.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"output-files.js","sourceRoot":"","sources":["../../src/utils/output-files.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAoB,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,0EAA0E;AAC1E,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAE/B,kGAAkG;AAClG,SAAS,oBAAoB,CAAC,MAAc,EAAE,SAAiB;IAC9D,OAAO,IAAI,CAAC,MAAM,EAAE,EAAE,GAAG,MAAM,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,SAAS,EAAE,CAAC,CAAC;AAClF,CAAC;AAED,6DAA6D;AAC7D,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,MAAc,EAAE,SAAiB,EAAE,IAAyB;IACjG,MAAM,IAAI,GAAG,oBAAoB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACrD,6DAA6D;IAC7D,MAAM,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACpE,OAAO,IAAI,CAAC;AACb,CAAC;AAED,kDAAkD;AAClD,MAAM,UAAU,sBAAsB,CAAC,MAAc,EAAE,SAAiB;IACvE,MAAM,IAAI,GAAG,oBAAoB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACrD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,iBAAiB,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;AAC3F,CAAC","sourcesContent":["/**\n * Output files: files pi writes so the model can use output it was not shown in full, such as the\n * full text of truncated tool output, binary MCP resources, and images shown by codemode scripts.\n * Every output file is created here, so where they are stored can change in one place. Today they\n * go to the OS temp directory.\n */\n\nimport { randomBytes } from \"node:crypto\";\nimport { createWriteStream, type WriteStream } from \"node:fs\";\nimport { writeFile } from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\n\n/** Output can carry private data, so only the user may read the files. */\nconst OUTPUT_FILE_MODE = 0o600;\n\n/** A new, unused path: `<dir>/<prefix>-<random hex><extension>`. `extension` includes the dot. */\nfunction createOutputFilePath(prefix: string, extension: string): string {\n\treturn join(tmpdir(), `${prefix}-${randomBytes(8).toString(\"hex\")}${extension}`);\n}\n\n/** Write `data` to a new output file and return its path. */\nexport async function writeOutputFile(prefix: string, extension: string, data: string | Uint8Array): Promise<string> {\n\tconst path = createOutputFilePath(prefix, extension);\n\t// `wx` never follows a link someone else placed at the path.\n\tawait writeFile(path, data, { mode: OUTPUT_FILE_MODE, flag: \"wx\" });\n\treturn path;\n}\n\n/** Open a new output file for streamed output. */\nexport function createOutputFileStream(prefix: string, extension: string): { path: string; stream: WriteStream } {\n\tconst path = createOutputFilePath(prefix, extension);\n\treturn { path, stream: createWriteStream(path, { mode: OUTPUT_FILE_MODE, flags: \"wx\" }) };\n}\n"]}
1
+ {"version":3,"file":"output-files.js","sourceRoot":"","sources":["../../src/utils/output-files.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAoB,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,0EAA0E;AAC1E,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAE/B,kGAAkG;AAClG,SAAS,oBAAoB,CAAC,MAAc,EAAE,SAAiB;IAC9D,OAAO,IAAI,CAAC,MAAM,EAAE,EAAE,GAAG,MAAM,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,SAAS,EAAE,CAAC,CAAC;AAClF,CAAC;AAED,6DAA6D;AAC7D,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,MAAc,EAAE,SAAiB,EAAE,IAAyB;IACjG,MAAM,IAAI,GAAG,oBAAoB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACrD,6DAA6D;IAC7D,MAAM,SAAS,CAAC,IAAI,EAAE,IAAI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,CAAC;QACD,KAAK,CAAC,IAAI;YACT,2FAA2F;YAC3F,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,IAAI,MAAM,CAAC,QAAQ;gBAAE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACpE,CAAC;QACD,KAAK,CAAC,KAAK;YACV,+EAA+E;YAC/E,IAAI,CAAC,MAAM,CAAC,SAAS;gBAAE,MAAM,CAAC,GAAG,EAAE,CAAC;YACpC,MAAM,MAAM,CAAC;YACb,MAAM,OAAO,CAAC;YACd,OAAO,MAAM,CAAC;QACf,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["/**\n * Output files: files pi writes so the model can use output it was not shown in full, such as the\n * full text of truncated tool output, binary MCP resources, and images shown by codemode scripts.\n * Every output file is created here, so where they are stored can change in one place. Today they\n * go to the OS temp directory.\n */\n\nimport { randomBytes } from \"node:crypto\";\nimport { createWriteStream, type WriteStream } from \"node:fs\";\nimport { rm, writeFile } from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\n\n/** Output can carry private data, so only the user may read the files. */\nconst OUTPUT_FILE_MODE = 0o600;\n\n/** A new, unused path: `<dir>/<prefix>-<random hex><extension>`. `extension` includes the dot. */\nfunction createOutputFilePath(prefix: string, extension: string): string {\n\treturn join(tmpdir(), `${prefix}-${randomBytes(8).toString(\"hex\")}${extension}`);\n}\n\n/** Write `data` to a new output file and return its path. */\nexport async function writeOutputFile(prefix: string, extension: string, data: string | Uint8Array): Promise<string> {\n\tconst path = createOutputFilePath(prefix, extension);\n\t// `wx` never follows a link someone else placed at the path.\n\tawait writeFile(path, data, { mode: OUTPUT_FILE_MODE, flag: \"wx\" });\n\treturn path;\n}\n\n/** Where streamed output ended up: a complete file, or why it could not be saved. */\nexport type OutputFileResult = { kind: \"saved\"; path: string } | { kind: \"failed\"; error: string };\n\n/**\n * An output file written while output streams in. Open and write failures (full disk, quota, unwritable\n * temp dir) never throw: they arrive later as stream events, and an unhandled one would crash the\n * process. The first failure drops the file instead, and `close()` reports why.\n */\nexport interface OutputFileStream {\n\t/** `saved` while writing has not failed; the file is complete only once `close()` resolves. */\n\treadonly result: OutputFileResult;\n\twrite(data: string | Uint8Array): void;\n\t/** Flush and close the file. Never rejects. */\n\tclose(): Promise<OutputFileResult>;\n}\n\n/** Open a new output file for streamed output. */\nexport function createOutputFileStream(prefix: string, extension: string): OutputFileStream {\n\tconst path = createOutputFilePath(prefix, extension);\n\tconst stream: WriteStream = createWriteStream(path, { mode: OUTPUT_FILE_MODE, flags: \"wx\" });\n\tlet result: OutputFileResult = { kind: \"saved\", path };\n\tlet opened = false;\n\tlet removed: Promise<void> | undefined;\n\tstream.once(\"open\", () => {\n\t\topened = true;\n\t});\n\tstream.on(\"error\", (cause) => {\n\t\tif (result.kind === \"saved\") result = { kind: \"failed\", error: cause.message };\n\t\t// A partial file would pass for the full output. A failed open (`wx` found a file) leaves\n\t\t// the path alone: whatever is there is not ours.\n\t\tif (opened) removed ??= rm(path, { force: true }).catch(() => {});\n\t});\n\t// `close`, not `finish`: closing the descriptor can still fail (delayed ENOSPC or EDQUOT on quota,\n\t// NFS or FUSE file systems), and that error comes after `finish`. It always comes before `close`.\n\tconst closed = new Promise<void>((resolve) => stream.once(\"close\", resolve));\n\treturn {\n\t\tget result() {\n\t\t\treturn result;\n\t\t},\n\t\twrite(data) {\n\t\t\t// Not after a failure, and not after `close()`: a write after `end()` would fail the file.\n\t\t\tif (result.kind === \"saved\" && stream.writable) stream.write(data);\n\t\t},\n\t\tasync close() {\n\t\t\t// A stream destroyed by an error is already closing; `end()` would do nothing.\n\t\t\tif (!stream.destroyed) stream.end();\n\t\t\tawait closed;\n\t\t\tawait removed;\n\t\t\treturn result;\n\t\t},\n\t};\n}\n"]}
@@ -7,7 +7,7 @@ export interface ShellConfig {
7
7
  * Resolve shell configuration based on platform and an optional explicit shell path.
8
8
  * Resolution order:
9
9
  * 1. User-specified shellPath
10
- * 2. On Windows: Git Bash in known locations, then bash on PATH
10
+ * 2. On Windows: Git Bash in known locations, then Git Bash of git on PATH, then bash on PATH
11
11
  * 3. On Unix: /bin/bash, then bash on PATH, then fallback to sh
12
12
  */
13
13
  export declare function getShellConfig(customShellPath?: string): ShellConfig;
@@ -24,6 +24,7 @@ export declare function getShellEnv(): NodeJS.ProcessEnv;
24
24
  export declare function sanitizeBinaryOutput(str: string): string;
25
25
  export declare function trackDetachedChildPid(pid: number): void;
26
26
  export declare function untrackDetachedChildPid(pid: number): void;
27
+ /** Kill every tracked shell process tree. On Windows this blocks until taskkill finishes. */
27
28
  export declare function killTrackedDetachedChildren(): void;
28
29
  /**
29
30
  * Kill a process and all its children (cross-platform)
@@ -1 +1 @@
1
- {"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../../src/utils/shell.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,WAAW;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACpC;AAqED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,WAAW,CAqDpE;AAED,eAAO,MAAM,eAAe,YAAI,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,QAAQ,EAAE,UAAU,CAAU,CAAC;AAEpH,6EAA6E;AAC7E,wBAAgB,mBAAmB,IAAI,WAAW,CAyBjD;AAED,wBAAgB,WAAW,IAAI,MAAM,CAAC,UAAU,CAY/C;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGxD;AAQD,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEvD;AAED,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEzD;AAED,wBAAgB,2BAA2B,IAAI,IAAI,CAKlD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CA4CjD"}
1
+ {"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../../src/utils/shell.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,WAAW;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACpC;AA2FD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,WAAW,CA6DpE;AAED,eAAO,MAAM,eAAe,YAAI,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,QAAQ,EAAE,UAAU,CAAU,CAAC;AAEpH,6EAA6E;AAC7E,wBAAgB,mBAAmB,IAAI,WAAW,CAyBjD;AAED,wBAAgB,WAAW,IAAI,MAAM,CAAC,UAAU,CAY/C;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGxD;AAQD,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEvD;AAED,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEzD;AAED,6FAA6F;AAC7F,wBAAgB,2BAA2B,IAAI,IAAI,CAkBlD;AAOD;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAuCjD"}
@@ -66,11 +66,34 @@ function findExecutableOnPath(executable) {
66
66
  }
67
67
  return null;
68
68
  }
69
+ // Keep in sync with packages/durable/src/env/node.ts.
70
+ // Git for Windows reports its POSIX shell as `<root>/usr/bin/sh.exe`.
71
+ const GIT_FOR_WINDOWS_SHELL_SUFFIX = win32.join("usr", "bin", "sh.exe");
72
+ /**
73
+ * Find Git Bash of the Git for Windows installation whose git.exe is on PATH. Git itself reports
74
+ * where it is installed (`git var GIT_SHELL_PATH`, Git 2.47+), so this works for any install
75
+ * directory and any PATH layout (`cmd`, `bin`, `mingw64\bin`, `ucrt64\bin`, package-manager shims).
76
+ * It returns `<root>\bin\bash.exe`, not the shell Git reports: that launcher sets up MSYSTEM and
77
+ * PATH, without which `usr\bin\bash.exe` cannot find tools like `ls`.
78
+ */
79
+ function findGitBashOfGitOnPath() {
80
+ const git = findExecutableOnPath("git.exe");
81
+ if (!git)
82
+ return null;
83
+ const result = spawnSync(git, ["var", "GIT_SHELL_PATH"], { encoding: "utf-8", timeout: 5000, windowsHide: true });
84
+ if (result.status !== 0)
85
+ return null;
86
+ const gitShell = win32.normalize(result.stdout.trim());
87
+ if (!gitShell.toLowerCase().endsWith(`\\${GIT_FOR_WINDOWS_SHELL_SUFFIX}`))
88
+ return null;
89
+ const bash = win32.join(gitShell.slice(0, -GIT_FOR_WINDOWS_SHELL_SUFFIX.length), "bin", "bash.exe");
90
+ return shellPathExists(bash) ? bash : null;
91
+ }
69
92
  /**
70
93
  * Resolve shell configuration based on platform and an optional explicit shell path.
71
94
  * Resolution order:
72
95
  * 1. User-specified shellPath
73
- * 2. On Windows: Git Bash in known locations, then bash on PATH
96
+ * 2. On Windows: Git Bash in known locations, then Git Bash of git on PATH, then bash on PATH
74
97
  * 3. On Unix: /bin/bash, then bash on PATH, then fallback to sh
75
98
  */
76
99
  export function getShellConfig(customShellPath) {
@@ -97,7 +120,13 @@ export function getShellConfig(customShellPath) {
97
120
  return getBashShellConfig(path);
98
121
  }
99
122
  }
100
- // 3. Fallback: search bash.exe on PATH (Cygwin, MSYS2, WSL, etc.)
123
+ // 3. Git Bash installed elsewhere, found through git on PATH. This must precede the generic
124
+ // bash.exe lookup, which usually finds the WSL launcher in System32 first.
125
+ const gitBash = findGitBashOfGitOnPath();
126
+ if (gitBash) {
127
+ return getBashShellConfig(gitBash);
128
+ }
129
+ // 4. Fallback: search bash.exe on PATH (Cygwin, MSYS2, WSL, etc.)
101
130
  const bashOnPath = findExecutableOnPath("bash.exe");
102
131
  if (bashOnPath) {
103
132
  return getBashShellConfig(bashOnPath);
@@ -106,7 +135,8 @@ export function getShellConfig(customShellPath) {
106
135
  ` 1. Install Git for Windows: https://git-scm.com/download/win\n` +
107
136
  ` 2. Add your bash to PATH (Cygwin, MSYS2, etc.)\n` +
108
137
  " 3. Set shellPath in settings.json\n\n" +
109
- `Searched Git Bash in:\n${paths.map((p) => ` ${p}`).join("\n")}`);
138
+ `Searched Git Bash in:\n${paths.map((p) => ` ${p}`).join("\n")}\n` +
139
+ " the Git for Windows installation of git.exe on PATH");
110
140
  }
111
141
  // Unix: try /bin/bash, then bash on PATH, then fallback to sh
112
142
  if (shellPathExists("/bin/bash")) {
@@ -177,20 +207,39 @@ export function trackDetachedChildPid(pid) {
177
207
  export function untrackDetachedChildPid(pid) {
178
208
  trackedDetachedChildPids.delete(pid);
179
209
  }
210
+ /** Kill every tracked shell process tree. On Windows this blocks until taskkill finishes. */
180
211
  export function killTrackedDetachedChildren() {
181
- for (const pid of trackedDetachedChildPids) {
182
- killProcessTree(pid);
212
+ if (trackedDetachedChildPids.size === 0)
213
+ return;
214
+ if (process.platform === "win32") {
215
+ // Callers exit right after this. Exiting kills the shell (libuv's job object), and taskkill /T
216
+ // then no longer finds the shell's descendants, so wait for taskkill. windowsHide gives it its own
217
+ // console, so a console close (SIGHUP) does not end it too.
218
+ const pidArgs = [...trackedDetachedChildPids].flatMap((pid) => ["/PID", String(pid)]);
219
+ spawnSync(getTaskkillPath(), ["/F", "/T", ...pidArgs], {
220
+ stdio: "ignore",
221
+ timeout: 2000,
222
+ windowsHide: true,
223
+ });
224
+ }
225
+ else {
226
+ for (const pid of trackedDetachedChildPids) {
227
+ killProcessTree(pid);
228
+ }
183
229
  }
184
230
  trackedDetachedChildPids.clear();
185
231
  }
232
+ // Use the trusted System32 executable so cleanup does not depend on PATH.
233
+ function getTaskkillPath() {
234
+ return join(process.env.SystemRoot || "C:\\Windows", "System32", "taskkill.exe");
235
+ }
186
236
  /**
187
237
  * Kill a process and all its children (cross-platform)
188
238
  */
189
239
  export function killProcessTree(pid) {
190
240
  if (process.platform === "win32") {
191
- // Use the trusted System32 executable so cleanup does not depend on PATH.
192
241
  try {
193
- const child = spawn(join(process.env.SystemRoot || "C:\\Windows", "System32", "taskkill.exe"), ["/F", "/T", "/PID", String(pid)], {
242
+ const child = spawn(getTaskkillPath(), ["/F", "/T", "/PID", String(pid)], {
194
243
  stdio: "ignore",
195
244
  detached: true,
196
245
  windowsHide: true,
@@ -1 +1 @@
1
- {"version":3,"file":"shell.js","sourceRoot":"","sources":["../../src/utils/shell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAQzC,sDAAsD;AACtD,SAAS,mBAAmB,CAAC,IAAY;IACxC,MAAM,UAAU,GAAG,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;IACvD,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;IAC1C,IAAI,UAAU,EAAE,CAAC;QAChB,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,UAAU,CAAC;YAAE,OAAO,KAAK,CAAC;QACpD,OAAO,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,IAAI,CACpC,CAAC,SAAS,EAAE,EAAE,CAAC,UAAU,KAAK,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,WAAW,EAAE,CACzF,CAAC;IACH,CAAC;IACD,uFAAuF;IACvF,OAAO,sDAAsD,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AAChF,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAa;I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AAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,EACjC;gBACC,KAAK,EAAE,QAAQ;gBACf,QAAQ,EAAE,IAAI;gBACd,WAAW,EAAE,IAAI;aACjB,CACD,CAAC;YACF,kFAAkF;YAClF,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACR,mCAAmC;QACpC,CAAC;IACF,CAAC;SAAM,CAAC;QACP,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACnC,oFAAoF;YACpF,kFAAkF;YAClF,kFAAkF;YAClF,mFAAmF;YACnF,mFAAmF;YACnF,sFAAsF;YACtF,IAAI,CAAC;gBACJ,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;YAC/B,CAAC;YAAC,MAAM,CAAC;gBACR,kFAAkF;YACnF,CAAC;QACF,CAAC;QACD,gCAAgC;QAChC,IAAI,CAAC;YACJ,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACR,iEAAiE;YACjE,IAAI,CAAC;gBACJ,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;YAC9B,CAAC;YAAC,MAAM,CAAC;gBACR,uBAAuB;YACxB,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import { accessSync, constants } from \"node:fs\";\nimport { delimiter, join, win32 } from \"node:path\";\nimport { spawn, spawnSync } from \"child_process\";\nimport { getBinDir } from \"../config.ts\";\n\nexport interface ShellConfig {\n\tshell: string;\n\targs: string[];\n\tcommandTransport?: \"argv\" | \"stdin\";\n}\n\n// Keep in sync with packages/durable/src/env/node.ts.\nfunction isLegacyWslBashPath(path: string): boolean {\n\tconst normalized = win32.normalize(path).toLowerCase();\n\tconst systemRoot = process.env.SystemRoot;\n\tif (systemRoot) {\n\t\tif (!/^[a-z]:[\\\\/]/i.test(systemRoot)) return false;\n\t\treturn [\"System32\", \"Sysnative\"].some(\n\t\t\t(directory) => normalized === win32.join(systemRoot, directory, \"bash.exe\").toLowerCase(),\n\t\t);\n\t}\n\t// Fall back to conventional launcher paths only when the Windows directory is unknown.\n\treturn /^[a-z]:\\\\windows\\\\(?:system32|sysnative)\\\\bash\\.exe$/.test(normalized);\n}\n\nfunction getBashShellConfig(shell: string): ShellConfig {\n\treturn isLegacyWslBashPath(shell) ? { shell, args: [\"-s\"], commandTransport: \"stdin\" } : { shell, args: [\"-c\"] };\n}\n\n// Matches harness-v2's pathExists (packages/durable/src/env/node.ts).\n// On Unix this is identical to existsSync() (both are access(F_OK)), just\n// spelled with try/catch. On Windows we explicitly avoid existsSync(): its\n// extra stat check rejects runnable Store aliases (nodejs/node#36790).\nfunction shellPathExists(path: string): boolean {\n\ttry {\n\t\taccessSync(path, constants.F_OK);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction findExecutableOnPath(executable: string): string | null {\n\tif (process.platform === \"win32\") {\n\t\t// Windows: use 'where' and check the returned path.\n\t\ttry {\n\t\t\tconst result = spawnSync(\"where\", [executable], {\n\t\t\t\tencoding: \"utf-8\",\n\t\t\t\ttimeout: 5000,\n\t\t\t\twindowsHide: true,\n\t\t\t});\n\t\t\tif (result.status === 0 && result.stdout) {\n\t\t\t\tconst firstMatch = result.stdout.trim().split(/\\r?\\n/)[0];\n\t\t\t\tif (firstMatch && shellPathExists(firstMatch)) {\n\t\t\t\t\treturn firstMatch;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore errors\n\t\t}\n\t\treturn null;\n\t}\n\n\t// Unix: Use 'which' and trust its output (handles Termux and special filesystems)\n\ttry {\n\t\tconst result = spawnSync(\"which\", [executable], { encoding: \"utf-8\", timeout: 5000 });\n\t\tif (result.status === 0 && result.stdout) {\n\t\t\tconst firstMatch = result.stdout.trim().split(/\\r?\\n/)[0];\n\t\t\tif (firstMatch) {\n\t\t\t\treturn firstMatch;\n\t\t\t}\n\t\t}\n\t} catch {\n\t\t// Ignore errors\n\t}\n\treturn null;\n}\n\n/**\n * Resolve shell configuration based on platform and an optional explicit shell path.\n * Resolution order:\n * 1. User-specified shellPath\n * 2. On Windows: Git Bash in known locations, then bash on PATH\n * 3. On Unix: /bin/bash, then bash on PATH, then fallback to sh\n */\nexport function getShellConfig(customShellPath?: string): ShellConfig {\n\t// 1. Check user-specified shell path\n\tif (customShellPath) {\n\t\tif (shellPathExists(customShellPath)) {\n\t\t\treturn getBashShellConfig(customShellPath);\n\t\t}\n\t\tthrow new Error(`Custom shell path not found: ${customShellPath}`);\n\t}\n\n\tif (process.platform === \"win32\") {\n\t\t// 2. Try Git Bash in known locations\n\t\tconst paths: string[] = [];\n\t\tconst programFiles = process.env.ProgramFiles;\n\t\tif (programFiles) {\n\t\t\tpaths.push(`${programFiles}\\\\Git\\\\bin\\\\bash.exe`);\n\t\t}\n\t\tconst programFilesX86 = process.env[\"ProgramFiles(x86)\"];\n\t\tif (programFilesX86) {\n\t\t\tpaths.push(`${programFilesX86}\\\\Git\\\\bin\\\\bash.exe`);\n\t\t}\n\n\t\tfor (const path of paths) {\n\t\t\tif (shellPathExists(path)) {\n\t\t\t\treturn getBashShellConfig(path);\n\t\t\t}\n\t\t}\n\n\t\t// 3. Fallback: search bash.exe on PATH (Cygwin, MSYS2, WSL, etc.)\n\t\tconst bashOnPath = findExecutableOnPath(\"bash.exe\");\n\t\tif (bashOnPath) {\n\t\t\treturn getBashShellConfig(bashOnPath);\n\t\t}\n\n\t\tthrow new Error(\n\t\t\t`No bash shell found. Options:\\n` +\n\t\t\t\t` 1. Install Git for Windows: https://git-scm.com/download/win\\n` +\n\t\t\t\t` 2. Add your bash to PATH (Cygwin, MSYS2, etc.)\\n` +\n\t\t\t\t\" 3. Set shellPath in settings.json\\n\\n\" +\n\t\t\t\t`Searched Git Bash in:\\n${paths.map((p) => ` ${p}`).join(\"\\n\")}`,\n\t\t);\n\t}\n\n\t// Unix: try /bin/bash, then bash on PATH, then fallback to sh\n\tif (shellPathExists(\"/bin/bash\")) {\n\t\treturn getBashShellConfig(\"/bin/bash\");\n\t}\n\n\tconst bashOnPath = findExecutableOnPath(\"bash\");\n\tif (bashOnPath) {\n\t\treturn getBashShellConfig(bashOnPath);\n\t}\n\n\treturn { shell: \"sh\", args: [\"-c\"] };\n}\n\nexport const POWERSHELL_ARGS = [\"-NoProfile\", \"-NonInteractive\", \"-ExecutionPolicy\", \"Bypass\", \"-Command\"] as const;\n\n/** Resolve PowerShell on Windows, preferring PowerShell 7 when available. */\nexport function getPowerShellConfig(): ShellConfig {\n\tif (process.platform !== \"win32\") {\n\t\tthrow new Error(\"The powershell tool is only available on Windows.\");\n\t}\n\n\tlet shell = findExecutableOnPath(\"pwsh.exe\");\n\t// Installation directories may be on any drive and need not be on PATH.\n\tconst programFiles = process.env.ProgramFiles;\n\tif (!shell && programFiles) {\n\t\tconst pwsh7 = win32.join(programFiles, \"PowerShell\", \"7\", \"pwsh.exe\");\n\t\tif (shellPathExists(pwsh7)) shell = pwsh7;\n\t}\n\n\tshell ??= findExecutableOnPath(\"powershell.exe\");\n\tconst systemRoot = process.env.SystemRoot;\n\tif (!shell && systemRoot) {\n\t\tconst windowsPowerShell = win32.join(systemRoot, \"System32\", \"WindowsPowerShell\", \"v1.0\", \"powershell.exe\");\n\t\tif (shellPathExists(windowsPowerShell)) shell = windowsPowerShell;\n\t}\n\n\tif (!shell) {\n\t\tthrow new Error(\"No PowerShell executable found. Install PowerShell or add powershell.exe/pwsh.exe to PATH.\");\n\t}\n\n\treturn { shell, args: [...POWERSHELL_ARGS] };\n}\n\nexport function getShellEnv(): NodeJS.ProcessEnv {\n\tconst binDir = getBinDir();\n\tconst pathKey = Object.keys(process.env).find((key) => key.toLowerCase() === \"path\") ?? \"PATH\";\n\tconst currentPath = process.env[pathKey] ?? \"\";\n\tconst pathEntries = currentPath.split(delimiter).filter(Boolean);\n\tconst hasBinDir = pathEntries.includes(binDir);\n\tconst updatedPath = hasBinDir ? currentPath : [binDir, currentPath].filter(Boolean).join(delimiter);\n\n\treturn {\n\t\t...process.env,\n\t\t[pathKey]: updatedPath,\n\t};\n}\n\n/**\n * Sanitize binary output for display/storage.\n * Removes characters that crash string-width or cause display issues:\n * - Control characters (except tab, newline, carriage return)\n * - Unicode interlinear annotation characters U+FFF9..U+FFFB (crash string-width due to a bug)\n */\nexport function sanitizeBinaryOutput(str: string): string {\n\t// All removed characters are single UTF-16 code units, so surrogate pairs are never split.\n\treturn str.replace(/[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F\\uFFF9-\\uFFFB]/g, \"\");\n}\n\n/**\n * Detached child processes must be tracked so they can be killed on parent\n * shutdown signals (SIGHUP/SIGTERM).\n */\nconst trackedDetachedChildPids = new Set<number>();\n\nexport function trackDetachedChildPid(pid: number): void {\n\ttrackedDetachedChildPids.add(pid);\n}\n\nexport function untrackDetachedChildPid(pid: number): void {\n\ttrackedDetachedChildPids.delete(pid);\n}\n\nexport function killTrackedDetachedChildren(): void {\n\tfor (const pid of trackedDetachedChildPids) {\n\t\tkillProcessTree(pid);\n\t}\n\ttrackedDetachedChildPids.clear();\n}\n\n/**\n * Kill a process and all its children (cross-platform)\n */\nexport function killProcessTree(pid: number): void {\n\tif (process.platform === \"win32\") {\n\t\t// Use the trusted System32 executable so cleanup does not depend on PATH.\n\t\ttry {\n\t\t\tconst child = spawn(\n\t\t\t\tjoin(process.env.SystemRoot || \"C:\\\\Windows\", \"System32\", \"taskkill.exe\"),\n\t\t\t\t[\"/F\", \"/T\", \"/PID\", String(pid)],\n\t\t\t\t{\n\t\t\t\t\tstdio: \"ignore\",\n\t\t\t\t\tdetached: true,\n\t\t\t\t\twindowsHide: true,\n\t\t\t\t},\n\t\t\t);\n\t\t\t// A failed spawn emits \"error\" asynchronously; consume it to avoid crashing Node.\n\t\t\tchild.once(\"error\", () => {});\n\t\t} catch {\n\t\t\t// Ignore errors if taskkill fails.\n\t\t}\n\t} else {\n\t\tif (process.platform === \"darwin\") {\n\t\t\t// macOS signals group members individually after releasing the group lock. A killed\n\t\t\t// child can wake its waiting shell before that shell is signalled, letting `a; b`\n\t\t\t// start b during cancellation (#11252). Stop the group first to reduce this race;\n\t\t\t// this is best-effort, not an atomic freeze. SIGKILL also kills stopped processes.\n\t\t\t// Linux holds tasklist_lock across group signalling; child exit notification needs\n\t\t\t// its write lock, so the shell is signalled before observing the killed child's exit.\n\t\t\ttry {\n\t\t\t\tprocess.kill(-pid, \"SIGSTOP\");\n\t\t\t} catch {\n\t\t\t\t// A failed stop must not prevent the kill attempt or its single-process fallback.\n\t\t\t}\n\t\t}\n\t\t// Use SIGKILL on Unix/Linux/Mac\n\t\ttry {\n\t\t\tprocess.kill(-pid, \"SIGKILL\");\n\t\t} catch {\n\t\t\t// Fallback to killing just the child if process group kill fails\n\t\t\ttry {\n\t\t\t\tprocess.kill(pid, \"SIGKILL\");\n\t\t\t} catch {\n\t\t\t\t// Process already dead\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"shell.js","sourceRoot":"","sources":["../../src/utils/shell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAQzC,sDAAsD;AACtD,SAAS,mBAAmB,CAAC,IAAY;IACxC,MAAM,UAAU,GAAG,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;IACvD,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;IAC1C,IAAI,UAA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pC,CAAC;IACF,CAAC;SAAM,CAAC;QACP,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACnC,oFAAoF;YACpF,kFAAkF;YAClF,kFAAkF;YAClF,mFAAmF;YACnF,mFAAmF;YACnF,sFAAsF;YACtF,IAAI,CAAC;gBACJ,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;YAC/B,CAAC;YAAC,MAAM,CAAC;gBACR,kFAAkF;YACnF,CAAC;QACF,CAAC;QACD,gCAAgC;QAChC,IAAI,CAAC;YACJ,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACR,iEAAiE;YACjE,IAAI,CAAC;gBACJ,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;YAC9B,CAAC;YAAC,MAAM,CAAC;gBACR,uBAAuB;YACxB,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import { accessSync, constants } from \"node:fs\";\nimport { delimiter, join, win32 } from \"node:path\";\nimport { spawn, spawnSync } from \"child_process\";\nimport { getBinDir } from \"../config.ts\";\n\nexport interface ShellConfig {\n\tshell: string;\n\targs: string[];\n\tcommandTransport?: \"argv\" | \"stdin\";\n}\n\n// Keep in sync with packages/durable/src/env/node.ts.\nfunction isLegacyWslBashPath(path: string): boolean {\n\tconst normalized = win32.normalize(path).toLowerCase();\n\tconst systemRoot = process.env.SystemRoot;\n\tif (systemRoot) {\n\t\tif (!/^[a-z]:[\\\\/]/i.test(systemRoot)) return false;\n\t\treturn [\"System32\", \"Sysnative\"].some(\n\t\t\t(directory) => normalized === win32.join(systemRoot, directory, \"bash.exe\").toLowerCase(),\n\t\t);\n\t}\n\t// Fall back to conventional launcher paths only when the Windows directory is unknown.\n\treturn /^[a-z]:\\\\windows\\\\(?:system32|sysnative)\\\\bash\\.exe$/.test(normalized);\n}\n\nfunction getBashShellConfig(shell: string): ShellConfig {\n\treturn isLegacyWslBashPath(shell) ? { shell, args: [\"-s\"], commandTransport: \"stdin\" } : { shell, args: [\"-c\"] };\n}\n\n// Matches harness-v2's pathExists (packages/durable/src/env/node.ts).\n// On Unix this is identical to existsSync() (both are access(F_OK)), just\n// spelled with try/catch. On Windows we explicitly avoid existsSync(): its\n// extra stat check rejects runnable Store aliases (nodejs/node#36790).\nfunction shellPathExists(path: string): boolean {\n\ttry {\n\t\taccessSync(path, constants.F_OK);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction findExecutableOnPath(executable: string): string | null {\n\tif (process.platform === \"win32\") {\n\t\t// Windows: use 'where' and check the returned path.\n\t\ttry {\n\t\t\tconst result = spawnSync(\"where\", [executable], {\n\t\t\t\tencoding: \"utf-8\",\n\t\t\t\ttimeout: 5000,\n\t\t\t\twindowsHide: true,\n\t\t\t});\n\t\t\tif (result.status === 0 && result.stdout) {\n\t\t\t\tconst firstMatch = result.stdout.trim().split(/\\r?\\n/)[0];\n\t\t\t\tif (firstMatch && shellPathExists(firstMatch)) {\n\t\t\t\t\treturn firstMatch;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore errors\n\t\t}\n\t\treturn null;\n\t}\n\n\t// Unix: Use 'which' and trust its output (handles Termux and special filesystems)\n\ttry {\n\t\tconst result = spawnSync(\"which\", [executable], { encoding: \"utf-8\", timeout: 5000 });\n\t\tif (result.status === 0 && result.stdout) {\n\t\t\tconst firstMatch = result.stdout.trim().split(/\\r?\\n/)[0];\n\t\t\tif (firstMatch) {\n\t\t\t\treturn firstMatch;\n\t\t\t}\n\t\t}\n\t} catch {\n\t\t// Ignore errors\n\t}\n\treturn null;\n}\n\n// Keep in sync with packages/durable/src/env/node.ts.\n// Git for Windows reports its POSIX shell as `<root>/usr/bin/sh.exe`.\nconst GIT_FOR_WINDOWS_SHELL_SUFFIX = win32.join(\"usr\", \"bin\", \"sh.exe\");\n\n/**\n * Find Git Bash of the Git for Windows installation whose git.exe is on PATH. Git itself reports\n * where it is installed (`git var GIT_SHELL_PATH`, Git 2.47+), so this works for any install\n * directory and any PATH layout (`cmd`, `bin`, `mingw64\\bin`, `ucrt64\\bin`, package-manager shims).\n * It returns `<root>\\bin\\bash.exe`, not the shell Git reports: that launcher sets up MSYSTEM and\n * PATH, without which `usr\\bin\\bash.exe` cannot find tools like `ls`.\n */\nfunction findGitBashOfGitOnPath(): string | null {\n\tconst git = findExecutableOnPath(\"git.exe\");\n\tif (!git) return null;\n\tconst result = spawnSync(git, [\"var\", \"GIT_SHELL_PATH\"], { encoding: \"utf-8\", timeout: 5000, windowsHide: true });\n\tif (result.status !== 0) return null;\n\tconst gitShell = win32.normalize(result.stdout.trim());\n\tif (!gitShell.toLowerCase().endsWith(`\\\\${GIT_FOR_WINDOWS_SHELL_SUFFIX}`)) return null;\n\tconst bash = win32.join(gitShell.slice(0, -GIT_FOR_WINDOWS_SHELL_SUFFIX.length), \"bin\", \"bash.exe\");\n\treturn shellPathExists(bash) ? bash : null;\n}\n\n/**\n * Resolve shell configuration based on platform and an optional explicit shell path.\n * Resolution order:\n * 1. User-specified shellPath\n * 2. On Windows: Git Bash in known locations, then Git Bash of git on PATH, then bash on PATH\n * 3. On Unix: /bin/bash, then bash on PATH, then fallback to sh\n */\nexport function getShellConfig(customShellPath?: string): ShellConfig {\n\t// 1. Check user-specified shell path\n\tif (customShellPath) {\n\t\tif (shellPathExists(customShellPath)) {\n\t\t\treturn getBashShellConfig(customShellPath);\n\t\t}\n\t\tthrow new Error(`Custom shell path not found: ${customShellPath}`);\n\t}\n\n\tif (process.platform === \"win32\") {\n\t\t// 2. Try Git Bash in known locations\n\t\tconst paths: string[] = [];\n\t\tconst programFiles = process.env.ProgramFiles;\n\t\tif (programFiles) {\n\t\t\tpaths.push(`${programFiles}\\\\Git\\\\bin\\\\bash.exe`);\n\t\t}\n\t\tconst programFilesX86 = process.env[\"ProgramFiles(x86)\"];\n\t\tif (programFilesX86) {\n\t\t\tpaths.push(`${programFilesX86}\\\\Git\\\\bin\\\\bash.exe`);\n\t\t}\n\n\t\tfor (const path of paths) {\n\t\t\tif (shellPathExists(path)) {\n\t\t\t\treturn getBashShellConfig(path);\n\t\t\t}\n\t\t}\n\n\t\t// 3. Git Bash installed elsewhere, found through git on PATH. This must precede the generic\n\t\t// bash.exe lookup, which usually finds the WSL launcher in System32 first.\n\t\tconst gitBash = findGitBashOfGitOnPath();\n\t\tif (gitBash) {\n\t\t\treturn getBashShellConfig(gitBash);\n\t\t}\n\n\t\t// 4. Fallback: search bash.exe on PATH (Cygwin, MSYS2, WSL, etc.)\n\t\tconst bashOnPath = findExecutableOnPath(\"bash.exe\");\n\t\tif (bashOnPath) {\n\t\t\treturn getBashShellConfig(bashOnPath);\n\t\t}\n\n\t\tthrow new Error(\n\t\t\t`No bash shell found. Options:\\n` +\n\t\t\t\t` 1. Install Git for Windows: https://git-scm.com/download/win\\n` +\n\t\t\t\t` 2. Add your bash to PATH (Cygwin, MSYS2, etc.)\\n` +\n\t\t\t\t\" 3. Set shellPath in settings.json\\n\\n\" +\n\t\t\t\t`Searched Git Bash in:\\n${paths.map((p) => ` ${p}`).join(\"\\n\")}\\n` +\n\t\t\t\t\" the Git for Windows installation of git.exe on PATH\",\n\t\t);\n\t}\n\n\t// Unix: try /bin/bash, then bash on PATH, then fallback to sh\n\tif (shellPathExists(\"/bin/bash\")) {\n\t\treturn getBashShellConfig(\"/bin/bash\");\n\t}\n\n\tconst bashOnPath = findExecutableOnPath(\"bash\");\n\tif (bashOnPath) {\n\t\treturn getBashShellConfig(bashOnPath);\n\t}\n\n\treturn { shell: \"sh\", args: [\"-c\"] };\n}\n\nexport const POWERSHELL_ARGS = [\"-NoProfile\", \"-NonInteractive\", \"-ExecutionPolicy\", \"Bypass\", \"-Command\"] as const;\n\n/** Resolve PowerShell on Windows, preferring PowerShell 7 when available. */\nexport function getPowerShellConfig(): ShellConfig {\n\tif (process.platform !== \"win32\") {\n\t\tthrow new Error(\"The powershell tool is only available on Windows.\");\n\t}\n\n\tlet shell = findExecutableOnPath(\"pwsh.exe\");\n\t// Installation directories may be on any drive and need not be on PATH.\n\tconst programFiles = process.env.ProgramFiles;\n\tif (!shell && programFiles) {\n\t\tconst pwsh7 = win32.join(programFiles, \"PowerShell\", \"7\", \"pwsh.exe\");\n\t\tif (shellPathExists(pwsh7)) shell = pwsh7;\n\t}\n\n\tshell ??= findExecutableOnPath(\"powershell.exe\");\n\tconst systemRoot = process.env.SystemRoot;\n\tif (!shell && systemRoot) {\n\t\tconst windowsPowerShell = win32.join(systemRoot, \"System32\", \"WindowsPowerShell\", \"v1.0\", \"powershell.exe\");\n\t\tif (shellPathExists(windowsPowerShell)) shell = windowsPowerShell;\n\t}\n\n\tif (!shell) {\n\t\tthrow new Error(\"No PowerShell executable found. Install PowerShell or add powershell.exe/pwsh.exe to PATH.\");\n\t}\n\n\treturn { shell, args: [...POWERSHELL_ARGS] };\n}\n\nexport function getShellEnv(): NodeJS.ProcessEnv {\n\tconst binDir = getBinDir();\n\tconst pathKey = Object.keys(process.env).find((key) => key.toLowerCase() === \"path\") ?? \"PATH\";\n\tconst currentPath = process.env[pathKey] ?? \"\";\n\tconst pathEntries = currentPath.split(delimiter).filter(Boolean);\n\tconst hasBinDir = pathEntries.includes(binDir);\n\tconst updatedPath = hasBinDir ? currentPath : [binDir, currentPath].filter(Boolean).join(delimiter);\n\n\treturn {\n\t\t...process.env,\n\t\t[pathKey]: updatedPath,\n\t};\n}\n\n/**\n * Sanitize binary output for display/storage.\n * Removes characters that crash string-width or cause display issues:\n * - Control characters (except tab, newline, carriage return)\n * - Unicode interlinear annotation characters U+FFF9..U+FFFB (crash string-width due to a bug)\n */\nexport function sanitizeBinaryOutput(str: string): string {\n\t// All removed characters are single UTF-16 code units, so surrogate pairs are never split.\n\treturn str.replace(/[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F\\uFFF9-\\uFFFB]/g, \"\");\n}\n\n/**\n * Detached child processes must be tracked so they can be killed on parent\n * shutdown signals (SIGHUP/SIGTERM).\n */\nconst trackedDetachedChildPids = new Set<number>();\n\nexport function trackDetachedChildPid(pid: number): void {\n\ttrackedDetachedChildPids.add(pid);\n}\n\nexport function untrackDetachedChildPid(pid: number): void {\n\ttrackedDetachedChildPids.delete(pid);\n}\n\n/** Kill every tracked shell process tree. On Windows this blocks until taskkill finishes. */\nexport function killTrackedDetachedChildren(): void {\n\tif (trackedDetachedChildPids.size === 0) return;\n\tif (process.platform === \"win32\") {\n\t\t// Callers exit right after this. Exiting kills the shell (libuv's job object), and taskkill /T\n\t\t// then no longer finds the shell's descendants, so wait for taskkill. windowsHide gives it its own\n\t\t// console, so a console close (SIGHUP) does not end it too.\n\t\tconst pidArgs = [...trackedDetachedChildPids].flatMap((pid) => [\"/PID\", String(pid)]);\n\t\tspawnSync(getTaskkillPath(), [\"/F\", \"/T\", ...pidArgs], {\n\t\t\tstdio: \"ignore\",\n\t\t\ttimeout: 2000,\n\t\t\twindowsHide: true,\n\t\t});\n\t} else {\n\t\tfor (const pid of trackedDetachedChildPids) {\n\t\t\tkillProcessTree(pid);\n\t\t}\n\t}\n\ttrackedDetachedChildPids.clear();\n}\n\n// Use the trusted System32 executable so cleanup does not depend on PATH.\nfunction getTaskkillPath(): string {\n\treturn join(process.env.SystemRoot || \"C:\\\\Windows\", \"System32\", \"taskkill.exe\");\n}\n\n/**\n * Kill a process and all its children (cross-platform)\n */\nexport function killProcessTree(pid: number): void {\n\tif (process.platform === \"win32\") {\n\t\ttry {\n\t\t\tconst child = spawn(getTaskkillPath(), [\"/F\", \"/T\", \"/PID\", String(pid)], {\n\t\t\t\tstdio: \"ignore\",\n\t\t\t\tdetached: true,\n\t\t\t\twindowsHide: true,\n\t\t\t});\n\t\t\t// A failed spawn emits \"error\" asynchronously; consume it to avoid crashing Node.\n\t\t\tchild.once(\"error\", () => {});\n\t\t} catch {\n\t\t\t// Ignore errors if taskkill fails.\n\t\t}\n\t} else {\n\t\tif (process.platform === \"darwin\") {\n\t\t\t// macOS signals group members individually after releasing the group lock. A killed\n\t\t\t// child can wake its waiting shell before that shell is signalled, letting `a; b`\n\t\t\t// start b during cancellation (#11252). Stop the group first to reduce this race;\n\t\t\t// this is best-effort, not an atomic freeze. SIGKILL also kills stopped processes.\n\t\t\t// Linux holds tasklist_lock across group signalling; child exit notification needs\n\t\t\t// its write lock, so the shell is signalled before observing the killed child's exit.\n\t\t\ttry {\n\t\t\t\tprocess.kill(-pid, \"SIGSTOP\");\n\t\t\t} catch {\n\t\t\t\t// A failed stop must not prevent the kill attempt or its single-process fallback.\n\t\t\t}\n\t\t}\n\t\t// Use SIGKILL on Unix/Linux/Mac\n\t\ttry {\n\t\t\tprocess.kill(-pid, \"SIGKILL\");\n\t\t} catch {\n\t\t\t// Fallback to killing just the child if process group kill fails\n\t\t\ttry {\n\t\t\t\tprocess.kill(pid, \"SIGKILL\");\n\t\t\t} catch {\n\t\t\t\t// Process already dead\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
package/docs/cli.md CHANGED
@@ -173,7 +173,7 @@ This keeps `read`, `bash`, `edit`, and `write` and adds `codemode`. For one invo
173
173
  pi --tools +codemode
174
174
  ```
175
175
 
176
- Codemode is useful without MCP: scripts can run several tool calls in parallel, filter large output before it reaches the model, call classifier models such as TypeSafe's Jev through `models.classify()` (see [Classifier models](models.md#use-classifier-models)), and generate images through `models.generateImages()` (see [Image models](models.md#use-image-models)).
176
+ Codemode is useful without MCP: scripts can run several tool calls in parallel, filter large output before it reaches the model, call decision models such as TypeSafe's Jev through `models.classify()` (see [Use decision models](models.md#use-decision-models)), and generate images through `models.generateImages()` (see [Use image models](models.md#use-image-models)).
177
177
 
178
178
  ### How codemode works
179
179
 
package/docs/codemode.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Codemode
2
2
 
3
- The `codemode` tool lets the model write a JavaScript script that calls pi's other tools and runs non-LLM models, such as classifiers and image models. Only the script's output reaches the model, so a script can run calls in parallel and filter large results before the model sees them. To turn it on, see [Enable codemode](cli.md#enable-codemode).
3
+ The `codemode` tool lets the model write a JavaScript script that calls pi's other tools and runs non-LLM models, such as decision models and image models. Only the script's output reaches the model, so a script can run calls in parallel and filter large results before the model sees them. To turn it on, see [Enable codemode](cli.md#enable-codemode).
4
4
 
5
5
  ## Scripts
6
6
 
@@ -40,7 +40,7 @@ Every tool the session can call is a method of `tools`, named by its identifier:
40
40
 
41
41
  What a call resolves to depends on the tool:
42
42
 
43
- - Tools with an output schema resolve to a structured value. `bash` resolves to `{ output, truncated, full_output_path?, exit_code, wall_time_seconds }`, also for non-zero exit codes. Its `output` is not limited to the 2000 lines or 50KB the model sees: it holds up to 1 MiB, and longer output keeps its first and last 512 KiB around an omission marker, with `truncated` set and the full output in `full_output_path`.
43
+ - Tools with an output schema resolve to a structured value. `bash` resolves to `{ output, truncated, full_output_path?, full_output_error?, exit_code, wall_time_seconds }`, also for non-zero exit codes. Its `output` is not limited to the 2000 lines or 50KB the model sees: it holds up to 1 MiB, and longer output keeps its first and last 512 KiB around an omission marker, with `truncated` set and the full output in `full_output_path`. When the full output could not be saved (for example a full temp directory), `full_output_error` says why and `output` holds only the retained tail.
44
44
  - MCP tools resolve to their `CallToolResult`, including `isError` and `structuredContent`.
45
45
  - `read` resolves to the file's text, or for an image to an image block `{ type: "image", data, mimeType, note }` that `image()` shows. `data` is the base64 image the model would see and `note` the text that goes with it, such as resize hints.
46
46
  - Other tools, such as `edit` and `write`, resolve to their text output.
@@ -59,7 +59,7 @@ The store is for small state such as IDs, cursors, or summaries. One value may h
59
59
 
60
60
  ## Models
61
61
 
62
- `models` reaches the model catalog and runs non-LLM models with the session's credentials: classifiers, which answer typed questions about JSON state and, for some models, images, and image models, which generate images. Chat models are listed but cannot be run from scripts. Which classifier and image models exist is described in [Use classifier models](models.md#use-classifier-models) and [Use image models](models.md#use-image-models).
62
+ `models` reaches the model catalog and runs non-LLM models with the session's credentials: decision models (type `"classifier"`), which answer typed questions about JSON state and, for some models, images, and image models, which generate images. Chat models are listed but cannot be run from scripts. Which decision and image models exist is described in [Use decision models](models.md#use-decision-models) and [Use image models](models.md#use-image-models).
63
63
 
64
64
  ```ts
65
65
  type ModelType = "chat" | "image" | "classifier";
@@ -120,6 +120,8 @@ interface ClassifierResult {
120
120
  /** Answers by question ID. */
121
121
  answers: Record<string, ClassifierAnswer>;
122
122
  usage?: ModelUsage;
123
+ /** Provider-specific response ID when reported, such as OpenRouter's generation ID. */
124
+ responseId?: string;
123
125
  stopReason: "stop" | "error" | "aborted";
124
126
  errorMessage?: string;
125
127
  }
@@ -165,7 +167,7 @@ return results.map((result, i) =>
165
167
  );
166
168
  ```
167
169
 
168
- Classifiers whose `input` includes `"image"` also judge images. `tools.read()` returns an image file as an image block that `images` accepts. Other classifiers return an error result when `images` is not empty.
170
+ Decision models whose `input` includes `"image"` also judge images. `tools.read()` returns an image file as an image block that `images` accepts. Other decision models return an error result when `images` is not empty.
169
171
 
170
172
  ```js
171
173
  const luna = await models.getModelOfType("classifier", "openai", "gpt-6-luna");
@@ -355,7 +355,7 @@ The model request runs these hooks in order:
355
355
  2. `context_with_system` (can modify the full transcript)
356
356
  3. `before_provider_headers` (can mutate headers)
357
357
  4. `before_provider_request` (can inspect or replace the payload)
358
- 5. `after_provider_response` (status and headers, before the stream is consumed)
358
+ 5. `after_provider_response` (status and headers of each HTTP response, including errors and retried attempts; successful responses fire before their stream is consumed)
359
359
  6. `provider_stream_event` (raw parsed stream events) and `message_start` / `message_update` / `message_end` for the assistant message
360
360
 
361
361
  A tool call that executes runs these hooks in order:
@@ -882,7 +882,7 @@ The payload is the full request. Providers that continue from a previous respons
882
882
 
883
883
  #### after_provider_response
884
884
 
885
- Fired after an HTTP response is received and before its stream body is consumed. Handlers run in extension load order.
885
+ Fired for each HTTP response the provider receives, including error responses (4xx/5xx) and responses to retried attempts, so one request can fire it more than once. Successful responses fire before their stream body is consumed. Handlers run in extension load order.
886
886
 
887
887
  ```typescript
888
888
  pi.on("after_provider_response", (event, ctx) => {
@@ -894,7 +894,7 @@ pi.on("after_provider_response", (event, ctx) => {
894
894
  });
895
895
  ```
896
896
 
897
- Header availability depends on provider and transport. Providers that abstract HTTP responses may not expose headers.
897
+ Coverage depends on provider and transport. Some providers report empty headers or only some responses. It does not fire for errors that arrive inside an already started SSE stream, or for WebSocket transports, including a WebSocket connection that fails to open.
898
898
 
899
899
  #### provider_stream_event
900
900
 
@@ -1225,7 +1225,7 @@ Use `ctx.modelRegistry.streamSimple(model, context, options)` for provider-neutr
1225
1225
 
1226
1226
  `streamSimple()` returns an `AssistantMessageEventStream`. Iterate it for response events and await `.result()` for the final message. Setup failures produce error events and error results.
1227
1227
 
1228
- For non-chat models, `findOfType()`, `getModelsOfType()`, `getAvailableOfType()`, and `getModelOfType()` look up image and classifier models, and `classify()` and `generateImages()` call them. See [Use classifier models](models.md#use-classifier-models) and [Use image models](models.md#use-image-models).
1228
+ For non-chat models, `findOfType()`, `getModelsOfType()`, `getAvailableOfType()`, and `getModelOfType()` look up image and decision (`"classifier"`) models, and `classify()` and `generateImages()` call them. See [Use decision models](models.md#use-decision-models) and [Use image models](models.md#use-image-models).
1229
1229
 
1230
1230
  ### ctx.signal
1231
1231
 
@@ -1903,7 +1903,7 @@ const result = await pi.exec("git", ["status"], { signal, timeout: 5000 });
1903
1903
  // result.stdout, result.stderr, result.code, result.killed, result.truncated
1904
1904
  ```
1905
1905
 
1906
- Options: `signal` and `timeout` terminate the command, `cwd` sets the working directory, and `maxBuffer` limits stdout and stderr combined (default 256 MiB). When output exceeds `maxBuffer`, pi terminates the command and returns the output up to the limit with `truncated: true`, `killed: true`, and a nonzero `code`. `killed` is true whenever pi terminated the command: timeout, abort, or `maxBuffer`. A command that ignores SIGTERM gets SIGKILL after 5 seconds.
1906
+ Options: `signal` and `timeout` terminate the command, `cwd` sets the working directory, and `maxBuffer` limits stdout and stderr combined (default 256 MiB). When output exceeds `maxBuffer`, pi terminates the command and returns the output up to the limit with `truncated: true`, `killed: true`, and a nonzero `code`. `killed` is true whenever pi terminated the command: timeout, abort, or `maxBuffer`. A command that ignores SIGTERM gets SIGKILL after 5 seconds. A command terminated by a signal, by pi or otherwise, reports 128 + the signal number as `code`, like a shell: 143 for SIGTERM, 137 for SIGKILL.
1907
1907
 
1908
1908
  ### pi.getActiveTools() / pi.getAllTools() / pi.setActiveTools(names)
1909
1909
 
@@ -1989,7 +1989,7 @@ import { createProvider, openAICompletionsApi } from "@earendil-works/pi-ai/comp
1989
1989
  const provider = createProvider({
1990
1990
  id: "local-server",
1991
1991
  name: "Local Server",
1992
- baseUrl: "http://localhost:8080/v1",
1992
+ baseUrl: "http://localhost:9931/v1",
1993
1993
  auth: {
1994
1994
  apiKey: {
1995
1995
  name: "Local server setup",
@@ -2033,11 +2033,11 @@ pi.registerProvider("my-proxy", {
2033
2033
 
2034
2034
  // Register a live llama.cpp catalog without persisting discovered models
2035
2035
  pi.registerProvider("llama.cpp", {
2036
- baseUrl: "http://localhost:8080/v1",
2036
+ baseUrl: "http://localhost:9931/v1",
2037
2037
  apiKey: "local",
2038
2038
  api: "openai-completions",
2039
2039
  async refreshModels({ signal }) {
2040
- const response = await fetch("http://localhost:8080/v1/models", { signal });
2040
+ const response = await fetch("http://localhost:9931/v1/models", { signal });
2041
2041
  const { data } = (await response.json()) as { data: Array<{ id: string }> };
2042
2042
  return data.map(({ id }) => ({
2043
2043
  id,
@@ -2888,6 +2888,16 @@ if (confirmed) {
2888
2888
 
2889
2889
  See [examples/extensions/timed-confirm.ts](../examples/extensions/timed-confirm.ts) for complete examples.
2890
2890
 
2891
+ #### Program Status Kind
2892
+
2893
+ While a dialog waits, terminals that support [program status](terminal-setup.md#program-status) show pi as blocked, with the first line of the title as the message. `confirm()` reports `"permission"`, `select()` and `input()` report `"question"`. Pass `blockedKind` when the dialog asks for something else, for example a select that approves an action:
2894
+
2895
+ ```typescript
2896
+ const choice = await ctx.ui.select("Deploy to production?", ["Deploy", "Deploy and tag", "Cancel"], {
2897
+ blockedKind: "permission", // "permission" | "question" | "auth"
2898
+ });
2899
+ ```
2900
+
2891
2901
  ### Widgets, Status, and Footer
2892
2902
 
2893
2903
  ```typescript
package/docs/llama-cpp.md CHANGED
@@ -96,10 +96,10 @@ If the router disconnects, `/llama` shows **Retry** and **Close**. Retry reconne
96
96
 
97
97
  ## Classification
98
98
 
99
- Classifier models answer typed `choice`, `bool`, and `score` questions about JSON state, like TypeSafe's Jev models. The model reaches them from [`codemode`](cli.md#enable-codemode) scripts, and extensions through `ctx.modelRegistry.classify()`; see [Classifier models](models.md#use-classifier-models). Pi lists llama.cpp models as classifiers in two ways:
99
+ Decision models answer typed `choice`, `bool`, and `score` questions about JSON state, like TypeSafe's Jev models. The model reaches them from [`codemode`](cli.md#enable-codemode) scripts, and extensions through `ctx.modelRegistry.classify()`; see [Use decision models](models.md#use-decision-models). Pi lists llama.cpp models under the `classifier` model type in two ways:
100
100
 
101
- - **Decision models** such as [Julia-1, Laya, Kev, lev, and OpenJev](https://huggingface.co/collections/ggml-org/decision-models-6abf80cca3c83f127060a769) answer natively through llama.cpp's `/v1/systemone` endpoint. They appear only as classifiers, with the `typesafe-system-one` API, and not in `/model`.
102
- - **Chat models** are also listed as classifiers with the same ID and the `llama-cpp-classify` API, which reads answers from next-token probabilities as described below.
101
+ - **Decision models** such as [Julia-1, Laya, Kev, lev, and OpenJev](https://huggingface.co/collections/ggml-org/decision-models-6abf80cca3c83f127060a769) answer natively through llama.cpp's `/v1/systemone` endpoint. They appear only under the `classifier` model type, with the `typesafe-system-one` API, and not in `/model`.
102
+ - **Chat models** are also listed under the `classifier` model type with the same ID and the `llama-cpp-classify` API, which reads answers from next-token probabilities as described below.
103
103
 
104
104
  llama.cpp 0.6.0 and later report decision models in the router's model list: their `architecture.output_modalities` contains `decisions`. The router reads this from the GGUF metadata without loading the model, so Pi recognizes unloaded and sleeping decision models too. Older llama.cpp builds do not report it, and Pi lists their decision models as chat models.
105
105
 
@@ -210,6 +210,7 @@ interface BashExecutionMessage {
210
210
  cancelled: boolean;
211
211
  truncated: boolean;
212
212
  fullOutputPath?: string;
213
+ fullOutputError?: string; // why the full output could not be saved, when truncated
213
214
  excludeFromContext?: boolean;
214
215
  timestamp: number;
215
216
  }
@@ -34,7 +34,7 @@ Each `models` entry adds a model to the provider. An entry whose `id` matches an
34
34
  | `api` | string | | Overrides the provider api. |
35
35
  | `baseUrl` | string | | Overrides the provider baseUrl. |
36
36
  | `reasoning` | boolean | `false` | Whether the model supports thinking. |
37
- | `thinkingLevelMap` | object | | Provider value sent for each thinking level. null marks a level unsupported. Levels the model does not map use the provider's default value through high; xhigh and max are unsupported. |
37
+ | `thinkingLevelMap` | object | | Provider value sent for each thinking level. A string is sent to the provider; null hides the level. Levels left out use the provider's default value for off through high; xhigh and max are opt-in and only offered when mapped to a string. |
38
38
  | `input` | `("text" \| "image")[]` | `["text"]` | |
39
39
  | `inputLimits` | [object](#input-limits) | | |
40
40
  | `cost` | object | | |
@@ -64,7 +64,7 @@ Each `modelOverrides` key is the ID of a built-in or extension model. Unknown ID
64
64
  |---|---|---|---|
65
65
  | `name` | string | | Display name, also matched by --model patterns. |
66
66
  | `reasoning` | boolean | | Whether the model supports thinking. |
67
- | `thinkingLevelMap` | object | | Provider value sent for each thinking level. null marks a level unsupported. Levels the model does not map use the provider's default value through high; xhigh and max are unsupported. |
67
+ | `thinkingLevelMap` | object | | Provider value sent for each thinking level. A string is sent to the provider; null hides the level. Levels left out use the provider's default value for off through high; xhigh and max are opt-in and only offered when mapped to a string. |
68
68
  | `input` | `("text" \| "image")[]` | | |
69
69
  | `inputLimits` | [object](#input-limits) | | |
70
70
  | `cost` | object | | |
@@ -111,7 +111,7 @@ See [Describe model input and caching](models.md#describe-model-input-and-cachin
111
111
  | Field | Type | Default | Description |
112
112
  |---|---|---|---|
113
113
  | `supportsStore` | boolean | | Whether the provider supports the store field. Default: auto-detected from URL. |
114
- | `supportsDeveloperRole` | boolean | | Whether the provider supports the developer role instead of system. Default: auto-detected from URL. |
114
+ | `supportsDeveloperRole` | boolean | | Whether to send system messages of reasoning models (the system prompt and mid-conversation system messages) with the developer role instead of system. Default: true only for api.openai.com. |
115
115
  | `supportsReasoningEffort` | boolean | | Whether the provider supports reasoning_effort. Default: auto-detected from URL. |
116
116
  | `supportsUsageInStreaming` | boolean | `true` | Whether the provider supports stream_options.include_usage for token usage in streaming responses. |
117
117
  | `supportsFinishReason` | boolean | `true` | Whether streamed responses include finish_reason. When false, pi infers stop or toolUse when the stream ends. |
@@ -157,7 +157,7 @@ Also applies to `azure-openai-responses` and `openai-codex-responses`.
157
157
  | `supportsAdditionalTools` | boolean | `false` | Whether the model supports message-anchored additional_tools input items. |
158
158
  | `supportsToolSearch` | boolean | `false` | Whether the model supports client-executed tool search for transcript-anchored additions. |
159
159
  | `supportsExplicitPromptCacheMode` | boolean | `false` | Whether the model accepts prompt_cache_options. Older OpenAI models reject the parameter. |
160
- | `supportsMidConvoEffort` | boolean | `false` | Whether thinking level changes are sent as configuration_update input items instead of changing reasoning.effort, so a change keeps the prompt cache. Only used by the openai-responses API, and ignored with Sign in with ChatGPT on the openai provider. |
160
+ | `supportsMidConvoEffort` | boolean | `false` | Whether thinking level changes are sent as configuration_update input items instead of changing reasoning.effort, so a change keeps the prompt cache. Used by the openai-responses and openai-codex-responses APIs, and ignored with Sign in with ChatGPT on the openai provider. |
161
161
  | `supportsMaxOutputTokens` | boolean | `true` | Whether the provider accepts max_output_tokens. Some Codex-protocol gateways reject it. |
162
162
 
163
163
  ### `anthropic-messages`
@@ -176,7 +176,7 @@ Also applies to `azure-openai-responses` and `openai-codex-responses`.
176
176
  | `supportsMidConvoEffort` | boolean | `false` | Whether the exact model transport supports effort-only system messages and thinking binding controls. |
177
177
  | `supportsMidConvoSystemMessages` | boolean | `false` | Whether the exact model accepts system-role messages inside the conversation. When false, later system messages are folded into the top-level system prompt. |
178
178
  | `supportsMidConvoToolChanges` | boolean | `false` | Whether the exact model accepts mid-conversation tool_addition and tool_removal blocks. Requires supportsMidConvoSystemMessages. |
179
- | `supportsMessageThreads` | boolean | | Whether the endpoint supports Anthropic message threads, which let a request with a session id send only the new messages and continue from the previous reply. Default: true for provider anthropic with a baseUrl on api.anthropic.com, false otherwise. Set true for gateways that forward the thread request field. |
179
+ | `supportsMessageThreads` | boolean | | Whether the endpoint supports Anthropic message threads, which let a request with a session id send only the new messages and continue from the previous reply. Default: true for a baseUrl on api.anthropic.com, false otherwise. Set true for gateways that forward the thread request field. |
180
180
  | `allowedFallbackModels` | `object[]` | | Models Anthropic accepts for server-side refusal fallback, with local pricing metadata for returned fallback responses. When absent or empty, callers must omit fallbacks; Anthropic rejects the field for models with no permitted fallback targets. |
181
181
 
182
182
  ### `bedrock-converse-stream`
@@ -190,6 +190,15 @@ Also applies to `azure-openai-responses` and `openai-codex-responses`.
190
190
  | Field | Type | Default | Description |
191
191
  |---|---|---|---|
192
192
  | `supportsMidConvoSystemMessages` | boolean | `false` | Whether the exact model accepts system messages after the conversation has started. When false, later system messages are folded into the leading system message. |
193
+ | `supportsStrictMode` | boolean | `false` | Whether the model supports strict (schema-constrained) function tools. |
194
+
195
+ ### `google-generative-ai`
196
+
197
+ Also applies to `google-vertex`.
198
+
199
+ | Field | Type | Default | Description |
200
+ |---|---|---|---|
201
+ | `supportsStrictMode` | boolean | | Whether the model enforces strict tools through Gemini's VALIDATED function-calling mode. Default: true for model IDs containing gemini-3 or a later version, such as gemini-3-pro or vendor-gemini-4-argon, false otherwise. Set true for Gemini 3+ models served under IDs without the version. |
193
202
 
194
203
  ### `typesafe-system-one`
195
204