pi-namespace-patch 1.6.0-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 (222) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/README.md +4 -4
  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-NRY4NBZW.js → chunk-254Q5KJY.js} +2 -2
  7. package/dist/bundle/chunks/chunk-2BKJ4UF2.js +6 -0
  8. package/dist/bundle/chunks/{chunk-YOWSKVK7.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-EVSO24NP.js → chunk-DQUOASJG.js} +1 -1
  12. package/dist/bundle/chunks/{chunk-XGGZYFNG.js → chunk-ESCXDUHA.js} +2 -2
  13. package/dist/bundle/chunks/chunk-FZUFSFVS.js +44 -0
  14. package/dist/bundle/chunks/{chunk-X26YOAEH.js → chunk-GH2VPQ2P.js} +6 -5
  15. package/dist/bundle/chunks/{chunk-NRLRGOCX.js → chunk-HID5BUPP.js} +1 -1
  16. package/dist/bundle/chunks/chunk-HRA5GXRL.js +9 -0
  17. package/dist/bundle/chunks/{chunk-Q5VBELS7.js → chunk-HXTNJVK4.js} +58 -63
  18. package/dist/bundle/chunks/chunk-JIUMJLB6.js +16 -0
  19. package/dist/bundle/chunks/{chunk-I6HYYNH6.js → chunk-O5MXS5TI.js} +1 -1
  20. package/dist/bundle/chunks/chunk-OVXT2WQH.js +2 -0
  21. package/dist/bundle/chunks/chunk-QQT7J23Q.js +30 -0
  22. package/dist/bundle/chunks/{chunk-P5E5VM2N.js → chunk-S6XQ4444.js} +1 -1
  23. package/dist/bundle/chunks/chunk-TRIUHDLU.js +2 -0
  24. package/dist/bundle/chunks/{chunk-E6LJTZYC.js → chunk-VUZTGLGT.js} +1 -1
  25. package/dist/bundle/chunks/chunk-WLFBMTZ5.js +14 -0
  26. package/dist/bundle/chunks/{cli-SAXJLJPC.js → cli-IFNPONCI.js} +1 -1
  27. package/dist/bundle/chunks/cloudflare-workers-ai-system-one-K5LZ2XIM.js +2 -0
  28. package/dist/bundle/chunks/{easter-egg-3d-7CBVPJQ3.js → easter-egg-3d-JQSUSCKG.js} +1 -1
  29. package/dist/bundle/chunks/{execute-XDNPBEMU.js → execute-GM225T4M.js} +1 -1
  30. package/dist/bundle/chunks/github-copilot.js +1 -1
  31. package/dist/bundle/chunks/google-generative-ai-JMDVNM52.js +2 -0
  32. package/dist/bundle/chunks/google-vertex-RO3RU6D4.js +2 -0
  33. package/dist/bundle/chunks/{llama-cpp-classify-XXZYF3RR.js → llama-cpp-classify-V63YXBKJ.js} +2 -2
  34. package/dist/bundle/chunks/mistral-conversations-5QQ525XP.js +4 -0
  35. package/dist/bundle/chunks/openai-codex-responses-3OSG4LCA.js +2 -0
  36. package/dist/bundle/chunks/{openai-completions-4IC6AGTR.js → openai-completions-CDC7XEM5.js} +1 -1
  37. package/dist/bundle/chunks/{openai-decisions-LZ2RLVRX.js → openai-decisions-QKZUXNGS.js} +1 -1
  38. package/dist/bundle/chunks/openai-responses-3TUDNSSR.js +4 -0
  39. package/dist/bundle/chunks/openrouter-images-WOQ26ANM.js +2 -0
  40. package/dist/bundle/chunks/pi-decision-DNF2KAXD.js +2 -0
  41. package/dist/bundle/chunks/pi-messages-PQC5SMWL.js +2 -0
  42. package/dist/bundle/chunks/{runtime-F3SXQONS.js → runtime-T6TR2GDO.js} +1 -1
  43. package/dist/bundle/chunks/typesafe-system-one-Z5B3PAXZ.js +2 -0
  44. package/dist/bundle/chunks/virtual-modules-SNXUCAHU.js +2 -0
  45. package/dist/bundle/cli-runtime.js +1 -1
  46. package/dist/bundle/index.js +1 -1
  47. package/dist/bundle/rpc-entry.js +1 -1
  48. package/dist/cli/project-trust.d.ts.map +1 -1
  49. package/dist/cli/project-trust.js +6 -6
  50. package/dist/cli/project-trust.js.map +1 -1
  51. package/dist/cli/startup-ui.d.ts +3 -2
  52. package/dist/cli/startup-ui.d.ts.map +1 -1
  53. package/dist/cli/startup-ui.js +17 -23
  54. package/dist/cli/startup-ui.js.map +1 -1
  55. package/dist/core/agent-session.d.ts.map +1 -1
  56. package/dist/core/agent-session.js +1 -0
  57. package/dist/core/agent-session.js.map +1 -1
  58. package/dist/core/auth-storage.d.ts.map +1 -1
  59. package/dist/core/auth-storage.js +7 -1
  60. package/dist/core/auth-storage.js.map +1 -1
  61. package/dist/core/bash-executor.d.ts +3 -1
  62. package/dist/core/bash-executor.d.ts.map +1 -1
  63. package/dist/core/bash-executor.js +24 -13
  64. package/dist/core/bash-executor.js.map +1 -1
  65. package/dist/core/extensions/runner.d.ts.map +1 -1
  66. package/dist/core/extensions/runner.js +2 -1
  67. package/dist/core/extensions/runner.js.map +1 -1
  68. package/dist/core/extensions/types.d.ts +9 -1
  69. package/dist/core/extensions/types.d.ts.map +1 -1
  70. package/dist/core/extensions/types.js.map +1 -1
  71. package/dist/core/messages.d.ts +4 -0
  72. package/dist/core/messages.d.ts.map +1 -1
  73. package/dist/core/messages.js +10 -2
  74. package/dist/core/messages.js.map +1 -1
  75. package/dist/core/model-resolver.js +1 -1
  76. package/dist/core/model-resolver.js.map +1 -1
  77. package/dist/core/model-runtime.d.ts.map +1 -1
  78. package/dist/core/model-runtime.js +6 -2
  79. package/dist/core/model-runtime.js.map +1 -1
  80. package/dist/core/project-trust.d.ts.map +1 -1
  81. package/dist/core/project-trust.js +1 -1
  82. package/dist/core/project-trust.js.map +1 -1
  83. package/dist/core/provider-composer.d.ts +1 -0
  84. package/dist/core/provider-composer.d.ts.map +1 -1
  85. package/dist/core/provider-composer.js.map +1 -1
  86. package/dist/core/resolve-config-value.d.ts +2 -0
  87. package/dist/core/resolve-config-value.d.ts.map +1 -1
  88. package/dist/core/resolve-config-value.js +4 -0
  89. package/dist/core/resolve-config-value.js.map +1 -1
  90. package/dist/core/session-manager.d.ts.map +1 -1
  91. package/dist/core/session-manager.js +10 -6
  92. package/dist/core/session-manager.js.map +1 -1
  93. package/dist/core/settings-defaults.d.ts +6 -1
  94. package/dist/core/settings-defaults.d.ts.map +1 -1
  95. package/dist/core/settings-defaults.js +6 -1
  96. package/dist/core/settings-defaults.js.map +1 -1
  97. package/dist/core/settings-manager.d.ts +6 -4
  98. package/dist/core/settings-manager.d.ts.map +1 -1
  99. package/dist/core/settings-manager.js +23 -8
  100. package/dist/core/settings-manager.js.map +1 -1
  101. package/dist/core/settings-schema.d.ts +16 -2
  102. package/dist/core/settings-schema.d.ts.map +1 -1
  103. package/dist/core/settings-schema.js +23 -4
  104. package/dist/core/settings-schema.js.map +1 -1
  105. package/dist/core/tools/bash.d.ts +3 -0
  106. package/dist/core/tools/bash.d.ts.map +1 -1
  107. package/dist/core/tools/bash.js +24 -9
  108. package/dist/core/tools/bash.js.map +1 -1
  109. package/dist/core/tools/output-accumulator.d.ts +16 -4
  110. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  111. package/dist/core/tools/output-accumulator.js +47 -41
  112. package/dist/core/tools/output-accumulator.js.map +1 -1
  113. package/dist/core/tools/renderers/bash.d.ts.map +1 -1
  114. package/dist/core/tools/renderers/bash.js +9 -3
  115. package/dist/core/tools/renderers/bash.js.map +1 -1
  116. package/dist/core/tools/truncate.d.ts +1 -1
  117. package/dist/core/tools/truncate.d.ts.map +1 -1
  118. package/dist/core/tools/truncate.js +11 -5
  119. package/dist/core/tools/truncate.js.map +1 -1
  120. package/dist/extensions/llama/client.d.ts.map +1 -1
  121. package/dist/extensions/llama/client.js +3 -13
  122. package/dist/extensions/llama/client.js.map +1 -1
  123. package/dist/extensions/mcp/resources.d.ts.map +1 -1
  124. package/dist/extensions/mcp/resources.js +3 -3
  125. package/dist/extensions/mcp/resources.js.map +1 -1
  126. package/dist/extensions/mcp/tools.d.ts +1 -9
  127. package/dist/extensions/mcp/tools.d.ts.map +1 -1
  128. package/dist/extensions/mcp/tools.js +8 -124
  129. package/dist/extensions/mcp/tools.js.map +1 -1
  130. package/dist/main.js +1 -1
  131. package/dist/main.js.map +1 -1
  132. package/dist/modes/interactive/components/bash-execution.d.ts +2 -1
  133. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  134. package/dist/modes/interactive/components/bash-execution.js +6 -3
  135. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  136. package/dist/modes/interactive/components/first-time-setup.d.ts +3 -5
  137. package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -1
  138. package/dist/modes/interactive/components/first-time-setup.js +15 -45
  139. package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
  140. package/dist/modes/interactive/components/mermaid.d.ts.map +1 -1
  141. package/dist/modes/interactive/components/mermaid.js +13 -4
  142. package/dist/modes/interactive/components/mermaid.js.map +1 -1
  143. package/dist/modes/interactive/components/oauth-selector.d.ts +13 -1
  144. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  145. package/dist/modes/interactive/components/oauth-selector.js +10 -9
  146. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  147. package/dist/modes/interactive/components/settings-selector.d.ts +3 -3
  148. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  149. package/dist/modes/interactive/components/settings-selector.js +56 -35
  150. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  151. package/dist/modes/interactive/external-editor.d.ts.map +1 -1
  152. package/dist/modes/interactive/external-editor.js +13 -3
  153. package/dist/modes/interactive/external-editor.js.map +1 -1
  154. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  155. package/dist/modes/interactive/interactive-mode.js +45 -34
  156. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  157. package/dist/modes/interactive/program-status-reporter.d.ts +2 -0
  158. package/dist/modes/interactive/program-status-reporter.d.ts.map +1 -1
  159. package/dist/modes/interactive/program-status-reporter.js +4 -0
  160. package/dist/modes/interactive/program-status-reporter.js.map +1 -1
  161. package/dist/modes/interactive/session-share.d.ts.map +1 -1
  162. package/dist/modes/interactive/session-share.js +9 -1
  163. package/dist/modes/interactive/session-share.js.map +1 -1
  164. package/dist/modes/print-mode.d.ts.map +1 -1
  165. package/dist/modes/print-mode.js +1 -4
  166. package/dist/modes/print-mode.js.map +1 -1
  167. package/dist/modes/rpc/jsonl.d.ts.map +1 -1
  168. package/dist/modes/rpc/jsonl.js +13 -13
  169. package/dist/modes/rpc/jsonl.js.map +1 -1
  170. package/dist/modes/rpc/rpc-mode.js +4 -4
  171. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  172. package/dist/package-manager-cli.d.ts.map +1 -1
  173. package/dist/package-manager-cli.js +10 -1
  174. package/dist/package-manager-cli.js.map +1 -1
  175. package/dist/utils/clipboard.js +1 -1
  176. package/dist/utils/clipboard.js.map +1 -1
  177. package/dist/utils/output-files.d.ts +20 -4
  178. package/dist/utils/output-files.d.ts.map +1 -1
  179. package/dist/utils/output-files.js +37 -2
  180. package/dist/utils/output-files.js.map +1 -1
  181. package/dist/utils/shell.d.ts +2 -1
  182. package/dist/utils/shell.d.ts.map +1 -1
  183. package/dist/utils/shell.js +56 -7
  184. package/dist/utils/shell.js.map +1 -1
  185. package/docs/cli.md +1 -1
  186. package/docs/codemode.md +6 -4
  187. package/docs/extensions.md +14 -4
  188. package/docs/llama-cpp.md +3 -3
  189. package/docs/message-types.md +1 -0
  190. package/docs/models-configuration.md +10 -2
  191. package/docs/models.md +28 -10
  192. package/docs/providers.md +3 -3
  193. package/docs/rpc-commands.md +1 -1
  194. package/docs/settings.md +4 -1
  195. package/docs/shell-aliases.md +1 -1
  196. package/docs/windows.md +2 -1
  197. package/examples/extensions/subagent/index.ts +3 -2
  198. package/examples/rpc-extension-ui.ts +8 -7
  199. package/package.json +6 -6
  200. package/schemas/models.schema.json +2 -2
  201. package/schemas/settings.schema.json +30 -5
  202. package/dist/bundle/chunks/anthropic-messages-WAFIHSF7.js +0 -6
  203. package/dist/bundle/chunks/azure-openai-responses-EB4MRIM4.js +0 -2
  204. package/dist/bundle/chunks/chunk-EEBRZED2.js +0 -44
  205. package/dist/bundle/chunks/chunk-F7LEMV2T.js +0 -2
  206. package/dist/bundle/chunks/chunk-ILDLA2JW.js +0 -9
  207. package/dist/bundle/chunks/chunk-NV3NPOPF.js +0 -20
  208. package/dist/bundle/chunks/chunk-PMRZO46Y.js +0 -2
  209. package/dist/bundle/chunks/chunk-RCNEHRMW.js +0 -2
  210. package/dist/bundle/chunks/chunk-WIVXJPHQ.js +0 -30
  211. package/dist/bundle/chunks/chunk-X6RQRO3L.js +0 -16
  212. package/dist/bundle/chunks/chunk-Y55SJART.js +0 -13
  213. package/dist/bundle/chunks/cloudflare-workers-ai-system-one-AMCR7QEI.js +0 -2
  214. package/dist/bundle/chunks/google-generative-ai-43M4N5LK.js +0 -2
  215. package/dist/bundle/chunks/google-vertex-2B3PASK2.js +0 -2
  216. package/dist/bundle/chunks/mistral-conversations-E3D5ZQKB.js +0 -5
  217. package/dist/bundle/chunks/openai-codex-responses-MSQDSDUR.js +0 -10
  218. package/dist/bundle/chunks/openai-responses-MCO3BHCC.js +0 -4
  219. package/dist/bundle/chunks/openrouter-images-SHUJ3VSG.js +0 -2
  220. package/dist/bundle/chunks/pi-messages-NIKOQ4O7.js +0 -8
  221. package/dist/bundle/chunks/typesafe-system-one-R2CDUWNO.js +0 -2
  222. package/dist/bundle/chunks/virtual-modules-C2UILCKW.js +0 -2
@@ -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,CA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I,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IAC7E,OAAO;QACN,IAAI,MAAM;YACT,OAAO,MAAM,CAAC;QACf,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,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E;QAC1E,IAAI,CAAC;YACJ,MAAM,KAAK,GAAG,KAAK,CAClB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,aAAa,EAAE,UAAU,EAAE,cAAc,CAAC,EACzE,CAAC,IAAI,EAAE,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;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AAI;aACjB,CAAC,CAAC;YACH,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// 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
 
@@ -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 | | |
@@ -192,6 +192,14 @@ Also applies to `azure-openai-responses` and `openai-codex-responses`.
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
193
  | `supportsStrictMode` | boolean | `false` | Whether the model supports strict (schema-constrained) function tools. |
194
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. |
202
+
195
203
  ### `typesafe-system-one`
196
204
 
197
205
  Also applies to `cloudflare-workers-ai-system-one`.
package/docs/models.md CHANGED
@@ -111,6 +111,20 @@ Use `promptCache` to declare the provider's best-effort cache lifetime in second
111
111
 
112
112
  Choose the conservative end of any published range. A model without a lifetime for the active tier is not eligible for cache warming. A `modelOverrides` entry can set `inputLimits` or `promptCache` for a built-in or extension model, including a model accessed through a validated proxy. See [`cacheWarming`](settings.md#model-and-thinking).
113
113
 
114
+ ### Map thinking levels
115
+
116
+ Use `thinkingLevelMap` to choose which thinking levels `/thinking` offers and which provider value Pi sends for each:
117
+
118
+ ```json
119
+ {
120
+ "id": "reasoning-model",
121
+ "reasoning": true,
122
+ "thinkingLevelMap": { "minimal": null, "xhigh": "xhigh", "max": "max" }
123
+ }
124
+ ```
125
+
126
+ A string is sent to the provider as the effort value, and `null` hides the level. Levels left out use the provider's default value for `off` through `high`. `xhigh` and `max` are opt-in: Pi offers them only when the map gives them a string, which must be a value the provider accepts. Set the map in `models.json`, on a custom model or in a `modelOverrides` entry for a built-in model, not in `settings.json`.
127
+
114
128
  ### Configure sampling by thinking level
115
129
 
116
130
  OpenAI-compatible APIs support free-form `samplingParams` model defaults and `samplingParamsByThinkingLevel` overrides. The latter uses Pi thinking-level keys (`off`, `minimal`, `low`, `medium`, `high`, `xhigh`, and `max`), not provider values from `thinkingLevelMap`:
@@ -139,9 +153,11 @@ Pi first clamps unsupported thinking levels, then merges model `samplingParams`,
139
153
 
140
154
  Compatibility settings should describe verified differences in the endpoint's request or response behavior. Do not enable them based only on an endpoint advertising OpenAI or Anthropic compatibility.
141
155
 
142
- ## Use classifier models
156
+ <a id="use-classifier-models"></a>
143
157
 
144
- Classifier models do not chat. They answer typed questions about JSON state: pick one of several choices, answer yes or no, or give a score, each with probabilities. Pi includes TypeSafe's Jev model from these providers, Cloudflare's Clef, Clef Flash, and Clef Omni models from Workers AI and OpenRouter, OpenAI's GPT-6 Luna through the [Decisions API](https://developers.openai.com/api/docs/guides/decisions), and Microsoft-Decision-1 through GitHub Copilot:
158
+ ## Use decision models
159
+
160
+ Decision models (listed in Pi's API under the `classifier` model type) do not chat. They answer typed questions about JSON state: pick one of several choices, answer yes or no, or give a score, each with probabilities. Pi includes TypeSafe's Jev model from these providers, Cloudflare's Clef, Clef Flash, and Clef Omni models from Workers AI and OpenRouter, OpenAI's GPT-6 Luna through the [Decisions API](https://developers.openai.com/api/docs/guides/decisions), and GPT-6 Luna Decisions and Microsoft-Decision-1 through GitHub Copilot:
145
161
 
146
162
  | Provider | Model IDs | Authentication |
147
163
  |---|---|---|
@@ -151,13 +167,15 @@ Classifier models do not chat. They answer typed questions about JSON state: pic
151
167
  | `vercel-ai-gateway` | `typesafe-ai/jev` | `AI_GATEWAY_API_KEY` |
152
168
  | `opencode` | `jev-1.13`, `jev-1.13-free` | `OPENCODE_API_KEY` |
153
169
  | `openai` | `gpt-6-luna` | `OPENAI_API_KEY` |
154
- | `github-copilot` | `microsoft-decision-1` | `COPILOT_GITHUB_TOKEN` or `/login` |
170
+ | `github-copilot` | `gpt-6-luna-decisions`, `microsoft-decision-1` | `COPILOT_GITHUB_TOKEN` or `/login` |
155
171
 
156
- Chat models on a [llama.cpp router](llama-cpp.md#classification) are also listed as classifier models.
172
+ Chat models on a [llama.cpp router](llama-cpp.md#classification) are also listed under the `classifier` model type.
157
173
 
158
174
  OpenAI's Decisions API needs an API key. Sign in with ChatGPT credentials do not work with it, so `gpt-6-luna` is not listed as available while `openai` is logged in through `/login`, even when `OPENAI_API_KEY` is set; log out of `openai` to use the key. The API rejects inputs above 922K tokens, but requests that run longer than about five seconds, currently above roughly 600K input tokens, fail with a gateway timeout.
159
175
 
160
- Classifier models do not appear in `/model`. The model reaches them through the [`codemode`](cli.md#enable-codemode) tool, which is off unless an MCP server turned it on. Enable it with `"defaultTools": ["+codemode"]` in [settings](settings.md#tools). Scripts then list classifier models with `models.getAvailableOfType("classifier")` and call `models.classify(model, { state, questions })`:
176
+ Which GitHub Copilot decision models an account can use depends on its plan: Microsoft-Decision-1 is limited to Business and Enterprise, and organizations can turn models off. With `/login`, pi lists only the decision models in the account's Copilot model catalog. With `COPILOT_GITHUB_TOKEN` it lists both.
177
+
178
+ Decision models do not appear in `/model`. The model reaches them through the [`codemode`](cli.md#enable-codemode) tool, which is off unless an MCP server turned it on. Enable it with `"defaultTools": ["+codemode"]` in [settings](settings.md#tools). Scripts then list decision models with `models.getAvailableOfType("classifier")` and call `models.classify(model, { state, questions })`:
161
179
 
162
180
  ```js
163
181
  const jev = await models.getModelOfType("classifier", "typesafe", "jev-latest");
@@ -176,19 +194,19 @@ return result.answers;
176
194
 
177
195
  [Codemode](codemode.md#classify) describes the question and answer types.
178
196
 
179
- Classifier models whose `input` includes `"image"` also judge images passed in `images`; other classifier models return an error for them. Image input works with GPT-6 Luna, with Jev from `typesafe` and `cloudflare-workers-ai`, with Clef from `cloudflare-workers-ai`, and with the OpenRouter models whose catalog lists image input. Jev takes PNG and JPEG images, and image input is experimental on TypeSafe's own API. Clef takes PNG, JPEG, and WebP images, at most four per request. Jev from `vercel-ai-gateway` and `opencode` takes text only.
197
+ Decision models whose `input` includes `"image"` also judge images passed in `images`; other decision models return an error for them. Image input works with GPT-6 Luna, with Jev from `typesafe` and `cloudflare-workers-ai`, with Clef from `cloudflare-workers-ai`, and with the OpenRouter models whose catalog lists image input. Jev takes PNG and JPEG images, and image input is experimental on TypeSafe's own API. Clef takes PNG, JPEG, and WebP images, at most four per request. Jev from `vercel-ai-gateway` and `opencode` takes text only.
180
198
 
181
- Each System One service takes images in its own request format, set by the model's `compat.imageInput`. Built-in models set it, so overriding a provider's `baseUrl` keeps it. A custom provider that proxies another service's classifiers sets it in its provider-level `compat` in `models.json` (see [System One compatibility](models-configuration.md#typesafe-system-one)). OpenRouter in particular answers requests in TypeSafe's format without an error but drops the images.
199
+ Each System One service takes images in its own request format, set by the model's `compat.imageInput`. Built-in models set it, so overriding a provider's `baseUrl` keeps it. A custom provider that proxies another service's decision models sets it in its provider-level `compat` in `models.json` (see [System One compatibility](models-configuration.md#typesafe-system-one)). OpenRouter in particular answers requests in TypeSafe's format without an error but drops the images.
182
200
 
183
- When the service reports token counts, as all System One services do, `result.usage` carries them with their cost. Pi adds the usage of a script's classifier calls to the `codemode` tool result, so it counts toward the session cost in the footer and `/session`. The cost uses the model's catalog price; models without one, such as TypeSafe's direct `jev-latest`, report tokens at no cost.
201
+ When the service reports token counts, as all System One services do, `result.usage` carries them with their cost. Pi adds the usage of a script's `classify()` calls to the `codemode` tool result, so it counts toward the session cost in the footer and `/session`. The cost uses the model's catalog price; models without one, such as TypeSafe's direct `jev-latest`, report tokens at no cost.
184
202
 
185
- Extensions call classifiers through `ctx.modelRegistry.classify()`, without codemode. [Virtual models](virtual-models.md#route-requests) can use them to route requests; see the `jev-router.ts` example.
203
+ Extensions call decision models through `ctx.modelRegistry.classify()`, without codemode. [Virtual models](virtual-models.md#route-requests) can use them to route requests; see the `jev-router.ts` example.
186
204
 
187
205
  ## Use image models
188
206
 
189
207
  Image models generate images from a prompt and optional input images. Pi lists OpenRouter's image models, such as `google/gemini-2.5-flash-image` and `black-forest-labs/flux.2-pro`, under the `openrouter` provider; they use the same `OPENROUTER_API_KEY` or `/login` credential as its chat models.
190
208
 
191
- Like classifier models, image models do not appear in `/model`; the model reaches them through the [`codemode`](cli.md#enable-codemode) tool. Scripts list them with `models.getAvailableOfType("image")` and call `models.generateImages(model, { input })`. The result's `output` holds base64 image blocks, which `image()` attaches to the `codemode` result so the model sees them:
209
+ Like decision models, image models do not appear in `/model`; the model reaches them through the [`codemode`](cli.md#enable-codemode) tool. Scripts list them with `models.getAvailableOfType("image")` and call `models.generateImages(model, { input })`. The result's `output` holds base64 image blocks, which `image()` attaches to the `codemode` result so the model sees them:
192
210
 
193
211
  ```js
194
212
  const painter = await models.getModelOfType("image", "openrouter", "google/gemini-2.5-flash-image");
package/docs/providers.md CHANGED
@@ -47,7 +47,7 @@ This table covers providers with a single primary API-key variable. Providers th
47
47
  | ZAI Coding Plan (China) | `ZAI_CODING_CN_API_KEY` |
48
48
  | OpenCode Zen and Go | `OPENCODE_API_KEY` |
49
49
  | Radius | `RADIUS_API_KEY` |
50
- | TypeSafe ([classifier models](models.md#use-classifier-models)) | `TYPESAFE_API_KEY` |
50
+ | TypeSafe ([decision models](models.md#use-decision-models)) | `TYPESAFE_API_KEY` |
51
51
  | Hugging Face | `HF_TOKEN` |
52
52
  | Fireworks | `FIREWORKS_API_KEY` |
53
53
  | Together AI | `TOGETHER_API_KEY` |
@@ -83,7 +83,7 @@ To use a secret manager without writing the resolved key to disk, set a provider
83
83
  }
84
84
  ```
85
85
 
86
- Pi runs the command when the key is first needed and caches its standard output for the process lifetime. Empty output, a timeout, or a nonzero exit leaves the key unresolved until Pi restarts.
86
+ Pi runs the command when the key is first needed and caches its standard output for the process lifetime. Empty output, a timeout, or a nonzero exit leaves the key unresolved: `/login` shows the provider as `stored key did not resolve`. To retry, for example after signing in to the secret manager, enter the same `!command` again in `/login`, or restart Pi.
87
87
 
88
88
  ## Provider Specific Config
89
89
 
@@ -119,7 +119,7 @@ Radius authentication uses its gateway catalog and caches refreshed model metada
119
119
 
120
120
  Authenticate with `/login openrouter` or `OPENROUTER_API_KEY`.
121
121
 
122
- With a key, Pi lists only the OpenRouter chat models that key may use, with the key's context size, max output, and prices. These come from OpenRouter's `/models/user` endpoint and reflect guardrails and provider restrictions set in OpenRouter. Image and classifier models are not filtered.
122
+ With a key, Pi lists only the OpenRouter chat models that key may use, with the key's context size, max output, and prices. These come from OpenRouter's `/models/user` endpoint and reflect guardrails and provider restrictions set in OpenRouter. Image and decision models are not filtered.
123
123
 
124
124
  Pi refreshes the list in the background at startup in interactive mode, when `/model` opens, after `/login`, and on `pi update --models`. The last list is saved and used offline and in `pi -p` and RPC mode. After switching keys outside `/login`, the previous key's list stays until the next refresh.
125
125
 
@@ -474,7 +474,7 @@ Response:
474
474
  }
475
475
  ```
476
476
 
477
- If output was truncated, includes `fullOutputPath`:
477
+ If output was truncated, includes `fullOutputPath`, or `fullOutputError` with the reason when the full output could not be saved (for example a full temp directory):
478
478
  ```json
479
479
  {
480
480
  "type": "response",