pi-namespace-patch 0.85.1 → 0.86.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 (330) hide show
  1. package/CHANGELOG.md +110 -0
  2. package/README.md +26 -705
  3. package/dist/bundle/chunks/anthropic-messages-MYU5ZMRF.js +6 -0
  4. package/dist/bundle/chunks/azure-openai-responses-HUSQ3GP2.js +2 -0
  5. package/dist/bundle/chunks/bedrock-converse-stream.js +47 -38
  6. package/dist/bundle/chunks/chunk-4YJERF5N.js +2 -0
  7. package/dist/bundle/chunks/chunk-A3JYRWB6.js +2 -0
  8. package/dist/bundle/chunks/chunk-CVPNLAPW.js +1562 -0
  9. package/dist/bundle/chunks/chunk-DTD7JQ7Y.js +42 -0
  10. package/dist/bundle/chunks/chunk-FUXEF6JQ.js +44 -0
  11. package/dist/bundle/chunks/{chunk-IDDQWTHI.js → chunk-RCZIEVGO.js} +10 -1
  12. package/dist/bundle/chunks/chunk-S7SZN6Z3.js +2 -0
  13. package/dist/bundle/chunks/chunk-WIUZI2CJ.js +11 -0
  14. package/dist/bundle/chunks/github-copilot.js +1 -1
  15. package/dist/bundle/chunks/google-generative-ai-IMS5EK2Y.js +2 -0
  16. package/dist/bundle/chunks/google-vertex-O4YJEQUW.js +2 -0
  17. package/dist/bundle/chunks/jiti-loader-C3NU2SDH.js +21 -0
  18. package/dist/bundle/chunks/jiti-static-loader-E6ANQD5T.js +2 -0
  19. package/dist/bundle/chunks/meta.js +2 -0
  20. package/dist/bundle/chunks/mistral-conversations-NOSQHBEY.js +5 -0
  21. package/dist/bundle/chunks/{node-KG362ECQ.js → node-O3RIBJRH.js} +1 -1
  22. package/dist/bundle/chunks/openai-codex-responses-QDSOTBBO.js +10 -0
  23. package/dist/bundle/chunks/openai-completions-CYGM3XXP.js +7 -0
  24. package/dist/bundle/chunks/openai-responses-HWEUZ6WZ.js +2 -0
  25. package/dist/bundle/chunks/{pi-messages-PML4SPVJ.js → pi-messages-GFKBWJHZ.js} +1 -1
  26. package/dist/bundle/chunks/virtual-modules-R7YYFUSE.js +2 -0
  27. package/dist/bundle/cli-runtime.js +3 -0
  28. package/dist/bundle/cli.js +4 -2
  29. package/dist/bundle/index.js +1 -1
  30. package/dist/bundle/rpc-entry.js +1 -1
  31. package/dist/cli/args.d.ts.map +1 -1
  32. package/dist/cli/args.js +1 -0
  33. package/dist/cli/args.js.map +1 -1
  34. package/dist/cli/session-picker.d.ts +1 -1
  35. package/dist/cli/session-picker.d.ts.map +1 -1
  36. package/dist/cli/session-picker.js.map +1 -1
  37. package/dist/config.d.ts.map +1 -1
  38. package/dist/config.js +1 -1
  39. package/dist/config.js.map +1 -1
  40. package/dist/core/agent-session.d.ts +56 -6
  41. package/dist/core/agent-session.d.ts.map +1 -1
  42. package/dist/core/agent-session.js +294 -157
  43. package/dist/core/agent-session.js.map +1 -1
  44. package/dist/core/bug-report-upload.d.ts +12 -0
  45. package/dist/core/bug-report-upload.d.ts.map +1 -0
  46. package/dist/core/bug-report-upload.js +22 -0
  47. package/dist/core/bug-report-upload.js.map +1 -0
  48. package/dist/core/bug-report.d.ts +176 -0
  49. package/dist/core/bug-report.d.ts.map +1 -0
  50. package/dist/core/bug-report.js +292 -0
  51. package/dist/core/bug-report.js.map +1 -0
  52. package/dist/core/cache-stats.d.ts.map +1 -1
  53. package/dist/core/cache-stats.js +12 -1
  54. package/dist/core/cache-stats.js.map +1 -1
  55. package/dist/core/cache-warmer.d.ts +102 -0
  56. package/dist/core/cache-warmer.d.ts.map +1 -0
  57. package/dist/core/cache-warmer.js +342 -0
  58. package/dist/core/cache-warmer.js.map +1 -0
  59. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  60. package/dist/core/compaction/branch-summarization.js +2 -2
  61. package/dist/core/compaction/branch-summarization.js.map +1 -1
  62. package/dist/core/compaction/compaction.d.ts +2 -2
  63. package/dist/core/compaction/compaction.d.ts.map +1 -1
  64. package/dist/core/compaction/compaction.js +11 -12
  65. package/dist/core/compaction/compaction.js.map +1 -1
  66. package/dist/core/crash-log.d.ts +22 -0
  67. package/dist/core/crash-log.d.ts.map +1 -0
  68. package/dist/core/crash-log.js +71 -0
  69. package/dist/core/crash-log.js.map +1 -0
  70. package/dist/core/experimental.d.ts +0 -4
  71. package/dist/core/experimental.d.ts.map +1 -1
  72. package/dist/core/experimental.js +0 -4
  73. package/dist/core/experimental.js.map +1 -1
  74. package/dist/core/extensions/index.d.ts +1 -1
  75. package/dist/core/extensions/index.d.ts.map +1 -1
  76. package/dist/core/extensions/index.js.map +1 -1
  77. package/dist/core/extensions/jiti-loader.d.ts +2 -0
  78. package/dist/core/extensions/jiti-loader.d.ts.map +1 -0
  79. package/dist/core/extensions/jiti-loader.js +4 -0
  80. package/dist/core/extensions/jiti-loader.js.map +1 -0
  81. package/dist/core/extensions/jiti-static-loader.d.ts +2 -0
  82. package/dist/core/extensions/jiti-static-loader.d.ts.map +1 -0
  83. package/dist/core/extensions/jiti-static-loader.js +4 -0
  84. package/dist/core/extensions/jiti-static-loader.js.map +1 -0
  85. package/dist/core/extensions/loader.d.ts.map +1 -1
  86. package/dist/core/extensions/loader.js +38 -51
  87. package/dist/core/extensions/loader.js.map +1 -1
  88. package/dist/core/extensions/runner.d.ts +10 -7
  89. package/dist/core/extensions/runner.d.ts.map +1 -1
  90. package/dist/core/extensions/runner.js +85 -67
  91. package/dist/core/extensions/runner.js.map +1 -1
  92. package/dist/core/extensions/types.d.ts +60 -50
  93. package/dist/core/extensions/types.d.ts.map +1 -1
  94. package/dist/core/extensions/types.js.map +1 -1
  95. package/dist/core/extensions/virtual-modules.d.ts +3 -0
  96. package/dist/core/extensions/virtual-modules.d.ts.map +1 -0
  97. package/dist/core/extensions/virtual-modules.js +38 -0
  98. package/dist/core/extensions/virtual-modules.js.map +1 -0
  99. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  100. package/dist/core/extensions/wrapper.js +1 -20
  101. package/dist/core/extensions/wrapper.js.map +1 -1
  102. package/dist/core/index.d.ts +2 -1
  103. package/dist/core/index.d.ts.map +1 -1
  104. package/dist/core/index.js.map +1 -1
  105. package/dist/core/keybindings.d.ts +1 -1
  106. package/dist/core/keybindings.d.ts.map +1 -1
  107. package/dist/core/keybindings.js +1 -1
  108. package/dist/core/keybindings.js.map +1 -1
  109. package/dist/core/messages.d.ts.map +1 -1
  110. package/dist/core/messages.js +1 -0
  111. package/dist/core/messages.js.map +1 -1
  112. package/dist/core/model-config.d.ts +101 -20
  113. package/dist/core/model-config.d.ts.map +1 -1
  114. package/dist/core/model-config.js +25 -18
  115. package/dist/core/model-config.js.map +1 -1
  116. package/dist/core/model-registry.d.ts +5 -1
  117. package/dist/core/model-registry.d.ts.map +1 -1
  118. package/dist/core/model-registry.js +8 -0
  119. package/dist/core/model-registry.js.map +1 -1
  120. package/dist/core/model-resolver.d.ts.map +1 -1
  121. package/dist/core/model-resolver.js +2 -1
  122. package/dist/core/model-resolver.js.map +1 -1
  123. package/dist/core/model-runtime.d.ts.map +1 -1
  124. package/dist/core/model-runtime.js +5 -3
  125. package/dist/core/model-runtime.js.map +1 -1
  126. package/dist/core/provider-composer.d.ts +3 -2
  127. package/dist/core/provider-composer.d.ts.map +1 -1
  128. package/dist/core/provider-composer.js +2 -0
  129. package/dist/core/provider-composer.js.map +1 -1
  130. package/dist/core/radius.d.ts +3 -0
  131. package/dist/core/radius.d.ts.map +1 -1
  132. package/dist/core/radius.js +6 -0
  133. package/dist/core/radius.js.map +1 -1
  134. package/dist/core/sdk.d.ts.map +1 -1
  135. package/dist/core/sdk.js +60 -38
  136. package/dist/core/sdk.js.map +1 -1
  137. package/dist/core/session-export.d.ts +6 -2
  138. package/dist/core/session-export.d.ts.map +1 -1
  139. package/dist/core/session-export.js +14 -13
  140. package/dist/core/session-export.js.map +1 -1
  141. package/dist/core/session-manager.d.ts +29 -6
  142. package/dist/core/session-manager.d.ts.map +1 -1
  143. package/dist/core/session-manager.js +159 -96
  144. package/dist/core/session-manager.js.map +1 -1
  145. package/dist/core/settings-manager.d.ts +20 -4
  146. package/dist/core/settings-manager.d.ts.map +1 -1
  147. package/dist/core/settings-manager.js +43 -7
  148. package/dist/core/settings-manager.js.map +1 -1
  149. package/dist/core/slash-commands.d.ts.map +1 -1
  150. package/dist/core/slash-commands.js +1 -0
  151. package/dist/core/slash-commands.js.map +1 -1
  152. package/dist/core/system-prompt.d.ts +49 -6
  153. package/dist/core/system-prompt.d.ts.map +1 -1
  154. package/dist/core/system-prompt.js +121 -92
  155. package/dist/core/system-prompt.js.map +1 -1
  156. package/dist/core/tools/bash.d.ts +2 -1
  157. package/dist/core/tools/bash.d.ts.map +1 -1
  158. package/dist/core/tools/bash.js +10 -4
  159. package/dist/core/tools/bash.js.map +1 -1
  160. package/dist/core/tools/edit.d.ts.map +1 -1
  161. package/dist/core/tools/edit.js +1 -2
  162. package/dist/core/tools/edit.js.map +1 -1
  163. package/dist/core/tools/read.d.ts.map +1 -1
  164. package/dist/core/tools/read.js +1 -2
  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 -1
  168. package/dist/core/tools/renderers/bash.js.map +1 -1
  169. package/dist/core/tools/write.d.ts.map +1 -1
  170. package/dist/core/tools/write.js +1 -2
  171. package/dist/core/tools/write.js.map +1 -1
  172. package/dist/core/usage-totals.d.ts +1 -1
  173. package/dist/core/usage-totals.d.ts.map +1 -1
  174. package/dist/core/usage-totals.js +5 -1
  175. package/dist/core/usage-totals.js.map +1 -1
  176. package/dist/extensions/llama/client.d.ts +2 -0
  177. package/dist/extensions/llama/client.d.ts.map +1 -1
  178. package/dist/extensions/llama/client.js +7 -3
  179. package/dist/extensions/llama/client.js.map +1 -1
  180. package/dist/extensions/llama/provider.d.ts.map +1 -1
  181. package/dist/extensions/llama/provider.js +20 -5
  182. package/dist/extensions/llama/provider.js.map +1 -1
  183. package/dist/index.d.ts +3 -2
  184. package/dist/index.d.ts.map +1 -1
  185. package/dist/index.js.map +1 -1
  186. package/dist/main.d.ts.map +1 -1
  187. package/dist/main.js +13 -9
  188. package/dist/main.js.map +1 -1
  189. package/dist/migrations.d.ts.map +1 -1
  190. package/dist/migrations.js +2 -2
  191. package/dist/migrations.js.map +1 -1
  192. package/dist/modes/interactive/bug-report.d.ts +16 -0
  193. package/dist/modes/interactive/bug-report.d.ts.map +1 -0
  194. package/dist/modes/interactive/bug-report.js +206 -0
  195. package/dist/modes/interactive/bug-report.js.map +1 -0
  196. package/dist/modes/interactive/chat-viewport.d.ts.map +1 -1
  197. package/dist/modes/interactive/chat-viewport.js +1 -1
  198. package/dist/modes/interactive/chat-viewport.js.map +1 -1
  199. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  200. package/dist/modes/interactive/components/branch-summary-message.js +12 -5
  201. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  202. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  203. package/dist/modes/interactive/components/compaction-summary-message.js +12 -5
  204. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  205. package/dist/modes/interactive/components/custom-editor.d.ts +3 -3
  206. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  207. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  208. package/dist/modes/interactive/components/extension-editor.d.ts +4 -1
  209. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  210. package/dist/modes/interactive/components/extension-editor.js +7 -2
  211. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  212. package/dist/modes/interactive/components/extension-input.d.ts +2 -0
  213. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  214. package/dist/modes/interactive/components/extension-input.js +6 -0
  215. package/dist/modes/interactive/components/extension-input.js.map +1 -1
  216. package/dist/modes/interactive/components/extension-selector.d.ts +1 -0
  217. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  218. package/dist/modes/interactive/components/extension-selector.js +4 -0
  219. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  220. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  221. package/dist/modes/interactive/components/footer.js +4 -1
  222. package/dist/modes/interactive/components/footer.js.map +1 -1
  223. package/dist/modes/interactive/components/session-selector.d.ts +5 -5
  224. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  225. package/dist/modes/interactive/components/session-selector.js +74 -48
  226. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  227. package/dist/modes/interactive/components/settings-selector.d.ts +3 -1
  228. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  229. package/dist/modes/interactive/components/settings-selector.js +11 -0
  230. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  231. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  232. package/dist/modes/interactive/components/skill-invocation-message.js +11 -4
  233. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  234. package/dist/modes/interactive/components/status-indicator.d.ts +2 -2
  235. package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
  236. package/dist/modes/interactive/components/status-indicator.js +7 -7
  237. package/dist/modes/interactive/components/status-indicator.js.map +1 -1
  238. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  239. package/dist/modes/interactive/components/tool-execution.js +18 -9
  240. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  241. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  242. package/dist/modes/interactive/components/tree-selector.js +2 -0
  243. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  244. package/dist/modes/interactive/interactive-mode.d.ts +15 -2
  245. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  246. package/dist/modes/interactive/interactive-mode.js +227 -84
  247. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  248. package/dist/modes/interactive/session-share.d.ts +2 -0
  249. package/dist/modes/interactive/session-share.d.ts.map +1 -1
  250. package/dist/modes/interactive/session-share.js +8 -4
  251. package/dist/modes/interactive/session-share.js.map +1 -1
  252. package/dist/modes/interactive/tui-renderer.d.ts.map +1 -1
  253. package/dist/modes/interactive/tui-renderer.js +2 -2
  254. package/dist/modes/interactive/tui-renderer.js.map +1 -1
  255. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  256. package/dist/modes/rpc/rpc-mode.js +2 -2
  257. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  258. package/dist/utils/clipboard-command.d.ts +7 -0
  259. package/dist/utils/clipboard-command.d.ts.map +1 -0
  260. package/dist/utils/clipboard-command.js +45 -0
  261. package/dist/utils/clipboard-command.js.map +1 -0
  262. package/dist/utils/clipboard-image.d.ts.map +1 -1
  263. package/dist/utils/clipboard-image.js +53 -81
  264. package/dist/utils/clipboard-image.js.map +1 -1
  265. package/dist/utils/clipboard.d.ts.map +1 -1
  266. package/dist/utils/clipboard.js +111 -121
  267. package/dist/utils/clipboard.js.map +1 -1
  268. package/dist/utils/version-check.d.ts.map +1 -1
  269. package/dist/utils/version-check.js +11 -4
  270. package/dist/utils/version-check.js.map +1 -1
  271. package/dist/utils/wsl.d.ts +3 -0
  272. package/dist/utils/wsl.d.ts.map +1 -0
  273. package/dist/utils/wsl.js +15 -0
  274. package/dist/utils/wsl.js.map +1 -0
  275. package/dist/utils/zip.d.ts +7 -0
  276. package/dist/utils/zip.d.ts.map +1 -0
  277. package/dist/utils/zip.js +60 -0
  278. package/dist/utils/zip.js.map +1 -0
  279. package/docs/compaction.md +39 -13
  280. package/docs/custom-provider.md +22 -13
  281. package/docs/development.md +4 -4
  282. package/docs/docs.json +4 -0
  283. package/docs/environment-variables.md +1 -0
  284. package/docs/extensions.md +57 -43
  285. package/docs/json.md +4 -4
  286. package/docs/models.md +33 -2
  287. package/docs/providers.md +10 -2
  288. package/docs/sdk.md +4 -2
  289. package/docs/security.md +1 -1
  290. package/docs/session-format.md +82 -40
  291. package/docs/sessions.md +27 -0
  292. package/docs/settings.md +60 -1
  293. package/docs/termux.md +0 -1
  294. package/docs/tui.md +2 -2
  295. package/docs/usage.md +1 -0
  296. package/examples/extensions/README.md +0 -1
  297. package/examples/extensions/custom-provider-anthropic/index.ts +18 -12
  298. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  299. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  300. package/examples/extensions/custom-provider-gitlab-duo/index.ts +2 -2
  301. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  302. package/examples/extensions/gondolin/package-lock.json +2 -2
  303. package/examples/extensions/gondolin/package.json +1 -1
  304. package/examples/extensions/prompt-customizer.ts +19 -67
  305. package/examples/extensions/sandbox/package-lock.json +2 -2
  306. package/examples/extensions/sandbox/package.json +1 -1
  307. package/examples/extensions/with-deps/package-lock.json +2 -2
  308. package/examples/extensions/with-deps/package.json +1 -1
  309. package/npm-shrinkwrap.json +435 -762
  310. package/package.json +17 -23
  311. package/dist/bundle/chunks/anthropic-messages-VWZZOSJQ.js +0 -6
  312. package/dist/bundle/chunks/azure-openai-responses-BJLAM6CD.js +0 -2
  313. package/dist/bundle/chunks/chunk-AXIIZGTV.js +0 -2
  314. package/dist/bundle/chunks/chunk-CLNPYIDP.js +0 -42
  315. package/dist/bundle/chunks/chunk-GMWCTUPB.js +0 -2
  316. package/dist/bundle/chunks/chunk-JJ2YFCJF.js +0 -1547
  317. package/dist/bundle/chunks/chunk-OUXLLA64.js +0 -11
  318. package/dist/bundle/chunks/chunk-U6ZMQKGD.js +0 -50
  319. package/dist/bundle/chunks/chunk-UAQELI3K.js +0 -2
  320. package/dist/bundle/chunks/google-generative-ai-Q2K7FBDI.js +0 -2
  321. package/dist/bundle/chunks/google-vertex-7UJBF4S7.js +0 -2
  322. package/dist/bundle/chunks/mistral-conversations-4M6BZBX6.js +0 -5
  323. package/dist/bundle/chunks/openai-codex-responses-R6VYZTVY.js +0 -10
  324. package/dist/bundle/chunks/openai-completions-EKZT2IH2.js +0 -7
  325. package/dist/bundle/chunks/openai-responses-TFDINO6W.js +0 -2
  326. package/dist/utils/clipboard-native.d.ts +0 -11
  327. package/dist/utils/clipboard-native.d.ts.map +0 -1
  328. package/dist/utils/clipboard-native.js +0 -20
  329. package/dist/utils/clipboard-native.js.map +0 -1
  330. package/examples/extensions/kimi-deferred-tools.ts +0 -61
@@ -0,0 +1,60 @@
1
+ import { writeFile } from "node:fs/promises";
2
+ import { crc32, deflateRawSync } from "node:zlib";
3
+ function dosDateTime(date) {
4
+ return {
5
+ time: (date.getHours() << 11) | (date.getMinutes() << 5) | (date.getSeconds() >> 1),
6
+ day: ((Math.max(1980, date.getFullYear()) - 1980) << 9) | ((date.getMonth() + 1) << 5) | date.getDate(),
7
+ };
8
+ }
9
+ /** Create the small, classic ZIP archives used by bug reports. */
10
+ function createZipArchive(entries) {
11
+ const files = [];
12
+ const directory = [];
13
+ const { time, day } = dosDateTime(new Date());
14
+ let offset = 0;
15
+ for (const entry of entries) {
16
+ const name = Buffer.from(entry.name);
17
+ const data = typeof entry.data === "string" ? Buffer.from(entry.data) : Buffer.from(entry.data);
18
+ const compressed = deflateRawSync(data);
19
+ const checksum = crc32(data);
20
+ const local = Buffer.alloc(30);
21
+ local.writeUInt32LE(0x04034b50, 0);
22
+ local.writeUInt16LE(20, 4);
23
+ local.writeUInt16LE(0x0800, 6);
24
+ local.writeUInt16LE(8, 8);
25
+ local.writeUInt16LE(time, 10);
26
+ local.writeUInt16LE(day, 12);
27
+ local.writeUInt32LE(checksum, 14);
28
+ local.writeUInt32LE(compressed.length, 18);
29
+ local.writeUInt32LE(data.length, 22);
30
+ local.writeUInt16LE(name.length, 26);
31
+ const central = Buffer.alloc(46);
32
+ central.writeUInt32LE(0x02014b50, 0);
33
+ central.writeUInt16LE(20, 4);
34
+ central.writeUInt16LE(20, 6);
35
+ central.writeUInt16LE(0x0800, 8);
36
+ central.writeUInt16LE(8, 10);
37
+ central.writeUInt16LE(time, 12);
38
+ central.writeUInt16LE(day, 14);
39
+ central.writeUInt32LE(checksum, 16);
40
+ central.writeUInt32LE(compressed.length, 20);
41
+ central.writeUInt32LE(data.length, 24);
42
+ central.writeUInt16LE(name.length, 28);
43
+ central.writeUInt32LE(offset, 42);
44
+ files.push(local, name, compressed);
45
+ directory.push(central, name);
46
+ offset += local.length + name.length + compressed.length;
47
+ }
48
+ const centralDirectory = Buffer.concat(directory);
49
+ const end = Buffer.alloc(22);
50
+ end.writeUInt32LE(0x06054b50, 0);
51
+ end.writeUInt16LE(entries.length, 8);
52
+ end.writeUInt16LE(entries.length, 10);
53
+ end.writeUInt32LE(centralDirectory.length, 12);
54
+ end.writeUInt32LE(offset, 16);
55
+ return Buffer.concat([...files, centralDirectory, end]);
56
+ }
57
+ export function writeZipArchive(filePath, entries) {
58
+ return writeFile(filePath, createZipArchive(entries));
59
+ }
60
+ //# sourceMappingURL=zip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zip.js","sourceRoot":"","sources":["../../src/utils/zip.ts"],"names":[],"mappings":"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","sourcesContent":["import { writeFile } from \"node:fs/promises\";\nimport { crc32, deflateRawSync } from \"node:zlib\";\n\ninterface ZipEntry {\n\tname: string;\n\tdata: string | Uint8Array;\n}\n\nfunction dosDateTime(date: Date): { time: number; day: number } {\n\treturn {\n\t\ttime: (date.getHours() << 11) | (date.getMinutes() << 5) | (date.getSeconds() >> 1),\n\t\tday: ((Math.max(1980, date.getFullYear()) - 1980) << 9) | ((date.getMonth() + 1) << 5) | date.getDate(),\n\t};\n}\n\n/** Create the small, classic ZIP archives used by bug reports. */\nfunction createZipArchive(entries: readonly ZipEntry[]): Buffer {\n\tconst files: Buffer[] = [];\n\tconst directory: Buffer[] = [];\n\tconst { time, day } = dosDateTime(new Date());\n\tlet offset = 0;\n\n\tfor (const entry of entries) {\n\t\tconst name = Buffer.from(entry.name);\n\t\tconst data = typeof entry.data === \"string\" ? Buffer.from(entry.data) : Buffer.from(entry.data);\n\t\tconst compressed = deflateRawSync(data);\n\t\tconst checksum = crc32(data);\n\n\t\tconst local = Buffer.alloc(30);\n\t\tlocal.writeUInt32LE(0x04034b50, 0);\n\t\tlocal.writeUInt16LE(20, 4);\n\t\tlocal.writeUInt16LE(0x0800, 6);\n\t\tlocal.writeUInt16LE(8, 8);\n\t\tlocal.writeUInt16LE(time, 10);\n\t\tlocal.writeUInt16LE(day, 12);\n\t\tlocal.writeUInt32LE(checksum, 14);\n\t\tlocal.writeUInt32LE(compressed.length, 18);\n\t\tlocal.writeUInt32LE(data.length, 22);\n\t\tlocal.writeUInt16LE(name.length, 26);\n\n\t\tconst central = Buffer.alloc(46);\n\t\tcentral.writeUInt32LE(0x02014b50, 0);\n\t\tcentral.writeUInt16LE(20, 4);\n\t\tcentral.writeUInt16LE(20, 6);\n\t\tcentral.writeUInt16LE(0x0800, 8);\n\t\tcentral.writeUInt16LE(8, 10);\n\t\tcentral.writeUInt16LE(time, 12);\n\t\tcentral.writeUInt16LE(day, 14);\n\t\tcentral.writeUInt32LE(checksum, 16);\n\t\tcentral.writeUInt32LE(compressed.length, 20);\n\t\tcentral.writeUInt32LE(data.length, 24);\n\t\tcentral.writeUInt16LE(name.length, 28);\n\t\tcentral.writeUInt32LE(offset, 42);\n\n\t\tfiles.push(local, name, compressed);\n\t\tdirectory.push(central, name);\n\t\toffset += local.length + name.length + compressed.length;\n\t}\n\n\tconst centralDirectory = Buffer.concat(directory);\n\tconst end = Buffer.alloc(22);\n\tend.writeUInt32LE(0x06054b50, 0);\n\tend.writeUInt16LE(entries.length, 8);\n\tend.writeUInt16LE(entries.length, 10);\n\tend.writeUInt32LE(centralDirectory.length, 12);\n\tend.writeUInt32LE(offset, 16);\n\treturn Buffer.concat([...files, centralDirectory, end]);\n}\n\nexport function writeZipArchive(filePath: string, entries: readonly ZipEntry[]): Promise<void> {\n\treturn writeFile(filePath, createZipArchive(entries));\n}\n"]}
@@ -2,12 +2,12 @@
2
2
 
3
3
  LLMs have limited context windows. When conversations grow too long, Pi uses compaction to summarize older content while preserving recent work. This page covers both auto-compaction and branch summarization.
4
4
 
5
- **Source files** ([pi-mono](https://github.com/earendil-works/pi-mono)):
6
- - [`packages/coding-agent/src/core/compaction/compaction.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/compaction/compaction.ts) - Auto-compaction logic
7
- - [`packages/coding-agent/src/core/compaction/branch-summarization.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/compaction/branch-summarization.ts) - Branch summarization
8
- - [`packages/coding-agent/src/core/compaction/utils.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/compaction/utils.ts) - Shared utilities (file tracking, serialization)
9
- - [`packages/coding-agent/src/core/session-manager.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/session-manager.ts) - Entry types (`CompactionEntry`, `BranchSummaryEntry`)
10
- - [`packages/coding-agent/src/core/extensions/types.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/extensions/types.ts) - Extension event types
5
+ **Source files** ([pi](https://github.com/earendil-works/pi)):
6
+ - [`packages/coding-agent/src/core/compaction/compaction.ts`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/compaction/compaction.ts) - Auto-compaction logic
7
+ - [`packages/coding-agent/src/core/compaction/branch-summarization.ts`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/compaction/branch-summarization.ts) - Branch summarization
8
+ - [`packages/coding-agent/src/core/compaction/utils.ts`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/compaction/utils.ts) - Shared utilities (file tracking, serialization)
9
+ - [`packages/coding-agent/src/core/session-manager.ts`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/session-manager.ts) - Entry types (`CompactionEntry`, `BranchSummaryEntry`)
10
+ - [`packages/coding-agent/src/core/extensions/types.ts`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/extensions/types.ts) - Extension event types
11
11
 
12
12
  For TypeScript definitions in your project, inspect `node_modules/@earendil-works/pi-coding-agent/dist/`.
13
13
 
@@ -120,7 +120,7 @@ Never cut at tool results (they must stay with their tool call).
120
120
 
121
121
  ### CompactionEntry Structure
122
122
 
123
- Defined in [`session-manager.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/session-manager.ts):
123
+ Defined in [`session-manager.ts`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/session-manager.ts):
124
124
 
125
125
  ```typescript
126
126
  interface CompactionEntry<T = unknown> {
@@ -145,7 +145,7 @@ interface CompactionDetails {
145
145
 
146
146
  Extensions can store any JSON-serializable data in `details`. The default compaction tracks file operations, but custom extension implementations can use their own structure. Generated and extension-provided summaries store their LLM `usage` when available so session totals include summarization work.
147
147
 
148
- See [`prepareCompaction()`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/compaction/compaction.ts) and [`compact()`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/compaction/compaction.ts) for the implementation. For direct programmatic summarization, `generateSummary()` returns the summary text and `generateSummaryWithUsage()` returns `{ text, usage }`.
148
+ See [`prepareCompaction()`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/compaction/compaction.ts) and [`compact()`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/compaction/compaction.ts) for the implementation. For direct programmatic summarization, `generateSummary()` returns the summary text and `generateSummaryWithUsage()` returns `{ text, usage }`.
149
149
 
150
150
  ## Branch Summarization
151
151
 
@@ -188,7 +188,7 @@ This means file tracking accumulates across multiple compactions or nested branc
188
188
 
189
189
  ### BranchSummaryEntry Structure
190
190
 
191
- Defined in [`session-manager.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/session-manager.ts):
191
+ Defined in [`session-manager.ts`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/session-manager.ts):
192
192
 
193
193
  ```typescript
194
194
  interface BranchSummaryEntry<T = unknown> {
@@ -212,7 +212,7 @@ interface BranchSummaryDetails {
212
212
 
213
213
  Same as compaction, extensions can store custom data in `details`.
214
214
 
215
- See [`collectEntriesForBranchSummary()`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/compaction/branch-summarization.ts), [`prepareBranchEntries()`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/compaction/branch-summarization.ts), and [`generateBranchSummary()`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/compaction/branch-summarization.ts) for the implementation.
215
+ See [`collectEntriesForBranchSummary()`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/compaction/branch-summarization.ts), [`prepareBranchEntries()`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/compaction/branch-summarization.ts), and [`generateBranchSummary()`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/compaction/branch-summarization.ts) for the implementation.
216
216
 
217
217
  ## Summary Format
218
218
 
@@ -256,7 +256,7 @@ path/to/changed.ts
256
256
 
257
257
  ### Message Serialization
258
258
 
259
- Before summarization, messages are serialized to text via [`serializeConversation()`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/compaction/utils.ts):
259
+ Before summarization, messages are serialized to text via [`serializeConversation()`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/compaction/utils.ts):
260
260
 
261
261
  ```
262
262
  [User]: What they said
@@ -272,7 +272,7 @@ Tool results are truncated to 2000 characters during serialization. Content beyo
272
272
 
273
273
  ## Custom Summarization via Extensions
274
274
 
275
- Extensions can intercept and customize both compaction and branch summarization. See [`extensions/types.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/extensions/types.ts) for event type definitions.
275
+ Extensions can intercept and customize both compaction and branch summarization. See [`extensions/types.ts`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/extensions/types.ts) for event type definitions.
276
276
 
277
277
  ### session_before_compact
278
278
 
@@ -288,7 +288,7 @@ pi.on("session_before_compact", async (event, ctx) => {
288
288
  // preparation.fileOps - extracted file operations
289
289
  // preparation.tokensBefore - context tokens before compaction
290
290
  // preparation.firstKeptEntryId - where kept messages start
291
- // preparation.settings - compaction settings
291
+ // preparation.settings - effective settings after applying model overrides
292
292
 
293
293
  // branchEntries - all entries on current branch (for custom state)
294
294
  // reason - "manual" (/compact), "threshold", or "overflow"
@@ -416,3 +416,29 @@ Configure compaction in `~/.pi/agent/settings.json` or `<project-dir>/.pi/settin
416
416
  | `keepRecentTokens` | `20000` | Recent tokens to keep (not summarized) |
417
417
 
418
418
  Disable auto-compaction with `"enabled": false`. You can still compact manually with `/compact`.
419
+
420
+ ### Per-model overrides
421
+
422
+ Use `compaction.modelOverrides` to tune token budgets for different models:
423
+
424
+ ```json
425
+ {
426
+ "compaction": {
427
+ "reserveTokens": 16384,
428
+ "keepRecentTokens": 20000,
429
+ "modelOverrides": {
430
+ "some-provider/big-model": {
431
+ "reserveTokens": 400000
432
+ }
433
+ }
434
+ }
435
+ }
436
+ ```
437
+
438
+ For a model with a 1M context window, this override triggers compaction above 600K tokens and keeps the ordinary 20000 recent tokens. Other models retain the ordinary 16384-token reserve. `reserveTokens` also influences summarization output limits, capped by the model's maximum output tokens; it is not solely a trigger threshold.
439
+
440
+ Keys are exact, case-sensitive `provider/modelId` values, including any slashes within the model ID. Each `reserveTokens` and `keepRecentTokens` value falls back independently from the model override to the ordinary setting to the built-in default. Values must be non-negative safe integers. Invalid values in the matching model override produce an error when read; only omitted fields fall back to the ordinary setting. Model override entries must be objects. Invalid ordinary token settings produce an error when read, even if the active model has a valid override. Only omitted ordinary values use built-in defaults. `enabled` remains global, not model-specific.
441
+
442
+ These resolved values are used for manual compaction, all automatic threshold checks, overflow recovery, and extension-visible `preparation.settings`. Model switches affect subsequent checks and compactions without changing ordinary settings. Compaction already in progress uses the model and settings captured for that operation. Branch summarization settings are unaffected.
443
+
444
+ Overrides work in both global and project settings. The files merge recursively before lookup, so a global model-specific value beats a project-wide fallback; a project must override that model entry to change it. See [settings.md](settings.md#per-model-compaction-overrides) for details.
@@ -397,34 +397,40 @@ interface OAuthCredentials {
397
397
  For providers with non-standard APIs, implement `streamSimple`. Study the existing API implementations before writing your own:
398
398
 
399
399
  **Reference implementations:**
400
- - [anthropic-messages.ts](https://github.com/earendil-works/pi-mono/blob/main/packages/ai/src/api/anthropic-messages.ts) - Anthropic Messages API
401
- - [mistral-conversations.ts](https://github.com/earendil-works/pi-mono/blob/main/packages/ai/src/api/mistral-conversations.ts) - Mistral Conversations API
402
- - [openai-completions.ts](https://github.com/earendil-works/pi-mono/blob/main/packages/ai/src/api/openai-completions.ts) - OpenAI Chat Completions
403
- - [openai-responses.ts](https://github.com/earendil-works/pi-mono/blob/main/packages/ai/src/api/openai-responses.ts) - OpenAI Responses API
404
- - [google-generative-ai.ts](https://github.com/earendil-works/pi-mono/blob/main/packages/ai/src/api/google-generative-ai.ts) - Google Generative AI
405
- - [bedrock-converse-stream.ts](https://github.com/earendil-works/pi-mono/blob/main/packages/ai/src/api/bedrock-converse-stream.ts) - AWS Bedrock
400
+ - [anthropic-messages.ts](https://github.com/earendil-works/pi/blob/main/packages/ai/src/api/anthropic-messages.ts) - Anthropic Messages API
401
+ - [mistral-conversations.ts](https://github.com/earendil-works/pi/blob/main/packages/ai/src/api/mistral-conversations.ts) - Mistral Conversations API
402
+ - [openai-completions.ts](https://github.com/earendil-works/pi/blob/main/packages/ai/src/api/openai-completions.ts) - OpenAI Chat Completions
403
+ - [openai-responses.ts](https://github.com/earendil-works/pi/blob/main/packages/ai/src/api/openai-responses.ts) - OpenAI Responses API
404
+ - [google-generative-ai.ts](https://github.com/earendil-works/pi/blob/main/packages/ai/src/api/google-generative-ai.ts) - Google Generative AI
405
+ - [bedrock-converse-stream.ts](https://github.com/earendil-works/pi/blob/main/packages/ai/src/api/bedrock-converse-stream.ts) - AWS Bedrock
406
406
 
407
407
  ### Stream Pattern
408
408
 
409
- All providers follow the same pattern:
409
+ All providers follow the same pattern. The context is a normalized transcript: the system prompt and tool declarations live in its system messages, so read them with `getCurrentSystemPrompt(context.messages)` and `getCurrentTools(context.messages)` rather than expecting `context.systemPrompt` or `context.tools`. Models that accept system messages mid-conversation can send them in place; otherwise call `collapseSystemMessages(context)` first to fold later system messages into the leading one.
410
410
 
411
411
  ```typescript
412
412
  import {
413
413
  type AssistantMessage,
414
414
  type AssistantMessageEventStream,
415
- type Context,
416
415
  type Model,
417
416
  type SimpleStreamOptions,
417
+ type TranscriptContext,
418
418
  calculateCost,
419
+ collapseSystemMessages,
419
420
  createAssistantMessageEventStream,
421
+ getCurrentSystemPrompt,
422
+ getCurrentTools,
420
423
  } from "@earendil-works/pi-ai";
421
424
 
422
425
  function streamMyProvider(
423
426
  model: Model<any>,
424
- context: Context,
427
+ context: TranscriptContext,
425
428
  options?: SimpleStreamOptions
426
429
  ): AssistantMessageEventStream {
427
430
  const stream = createAssistantMessageEventStream();
431
+ const transcript = collapseSystemMessages(context);
432
+ const systemPrompt = getCurrentSystemPrompt(transcript.messages);
433
+ const tools = getCurrentTools(transcript.messages);
428
434
 
429
435
  (async () => {
430
436
  // Initialize output message
@@ -571,7 +577,7 @@ When a request exceeds the model's context window, pi can recover automatically
571
577
  Detection runs on the finalized assistant message:
572
578
 
573
579
  - `stopReason === "error"`
574
- - `errorMessage` matches one of pi's known overflow patterns (see [`packages/ai/src/utils/overflow.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/ai/src/utils/overflow.ts))
580
+ - `errorMessage` matches one of pi's known overflow patterns (see [`packages/ai/src/utils/overflow.ts`](https://github.com/earendil-works/pi/blob/main/packages/ai/src/utils/overflow.ts))
575
581
 
576
582
  If your provider returns overflow errors with a message pi does not recognize, normalize the error from the same extension that registers the provider. Use a `message_end` handler to rewrite the assistant message so its `errorMessage` starts with a phrase pi recognizes. The generic fallback `context_length_exceeded` is the safest choice.
577
583
 
@@ -634,7 +640,7 @@ pi.registerProvider("my-provider", {
634
640
 
635
641
  ## Testing Your Implementation
636
642
 
637
- Test your provider against the same test suites used by built-in providers. Copy and adapt these test files from [packages/ai/test/](https://github.com/earendil-works/pi-mono/tree/main/packages/ai/test):
643
+ Test your provider against the same test suites used by built-in providers. Copy and adapt these test files from [packages/ai/test/](https://github.com/earendil-works/pi/tree/main/packages/ai/test):
638
644
 
639
645
  | Test | Purpose |
640
646
  |------|---------|
@@ -668,10 +674,10 @@ interface ProviderConfig {
668
674
  /** API type for streaming. Required at provider or model level when defining models. */
669
675
  api?: Api;
670
676
 
671
- /** Custom streaming implementation for non-standard APIs. */
677
+ /** Custom streaming implementation for non-standard APIs. Receives a normalized transcript. */
672
678
  streamSimple?: (
673
679
  model: Model<Api>,
674
- context: Context,
680
+ context: TranscriptContext,
675
681
  options?: SimpleStreamOptions
676
682
  ) => AssistantMessageEventStream;
677
683
 
@@ -727,6 +733,9 @@ interface ProviderModelConfig {
727
733
  cacheWrite: number;
728
734
  };
729
735
 
736
+ /** Best-effort prompt cache lifetime in seconds per retention tier. Unset disables cache warming. */
737
+ promptCache?: { short?: number; long?: number };
738
+
730
739
  /** Maximum context window size in tokens. */
731
740
  contextWindow: number;
732
741
 
@@ -1,12 +1,12 @@
1
1
  # Development
2
2
 
3
- See [AGENTS.md](https://github.com/earendil-works/pi-mono/blob/main/AGENTS.md) for additional guidelines.
3
+ See [AGENTS.md](https://github.com/earendil-works/pi/blob/main/AGENTS.md) for additional guidelines.
4
4
 
5
5
  ## Setup
6
6
 
7
7
  ```bash
8
- git clone https://github.com/earendil-works/pi-mono
9
- cd pi-mono
8
+ git clone https://github.com/earendil-works/pi
9
+ cd pi
10
10
  npm install
11
11
  npm run build
12
12
  ```
@@ -14,7 +14,7 @@ npm run build
14
14
  Run from source:
15
15
 
16
16
  ```bash
17
- /path/to/pi-mono/pi-test.sh
17
+ /path/to/pi/pi-test.sh
18
18
  ```
19
19
 
20
20
  The script can be run from any directory. Pi keeps the caller's current working directory.
package/docs/docs.json CHANGED
@@ -81,6 +81,10 @@
81
81
  {
82
82
  "title": "Reference",
83
83
  "items": [
84
+ {
85
+ "title": "Environment Variables",
86
+ "path": "environment-variables.md"
87
+ },
84
88
  {
85
89
  "title": "Session Format",
86
90
  "path": "session-format.md"
@@ -86,6 +86,7 @@ These variables are read by Pi itself:
86
86
  | `PI_TELEMETRY` | Override install/update telemetry and provider attribution headers: `1`/`true`/`yes` or `0`/`false`/`no` |
87
87
  | `PI_CACHE_RETENTION` | Set to `long` for extended provider prompt caching where supported |
88
88
  | `PI_SHARE_VIEWER_URL` | Override the base URL used by `/share` |
89
+ | `PI_RADIUS_GATEWAY` | Override the Radius gateway origin used by `/bug` uploads and Radius relay connections |
89
90
  | `PI_HARDWARE_CURSOR` | Set to `1` to show the hardware cursor; see [Terminal setup](terminal-setup.md) |
90
91
  | `PI_HYPERLINKS` | Override OSC 8 hyperlink detection with `1`, `0`, or `auto` |
91
92
  | `PI_IMAGE_PROTOCOL` | Override inline image detection with `kitty`, `iterm2`, `none`, or `auto` |
@@ -538,10 +538,13 @@ pi.on("before_agent_start", async (event, ctx) => {
538
538
  // event.systemPrompt - current chained system prompt for this handler
539
539
  // (includes changes from earlier before_agent_start handlers)
540
540
  // event.systemPromptOptions - structured options used to build the system prompt
541
- // .customPrompt - any custom system prompt (from --system-prompt, SYSTEM.md, or custom templates)
541
+ // .customPrompt - exact prompt prefix from --system-prompt, SYSTEM.md, or custom templates
542
+ // .forceSystemPrompt - optional exact replacement for the complete prompt
542
543
  // .selectedTools - tools currently active in the prompt
543
544
  // .toolSnippets - one-line descriptions for each tool
544
- // .promptGuidelines - custom guideline bullets
545
+ // .toolGuidelines - guideline bullets keyed by tool name
546
+ // .promptGuidelines - additional custom guideline bullets
547
+ // .sections - custom XML-wrapped sections keyed by tag name
545
548
  // .appendSystemPrompt - text from --append-system-prompt flags
546
549
  // .cwd - working directory
547
550
  // .contextFiles - AGENTS.md files and other loaded context files
@@ -560,7 +563,7 @@ pi.on("before_agent_start", async (event, ctx) => {
560
563
  });
561
564
  ```
562
565
 
563
- The `systemPromptOptions` field gives extensions access to the same structured data Pi uses to build the system prompt. This lets you inspect what Pi has loaded — custom prompts, guidelines, tool snippets, context files, skills — without re-discovering resources or re-parsing flags. Use it when your extension needs to make deep, informed changes to the system prompt while respecting user-provided configuration.
566
+ The `systemPromptOptions` field gives extensions access to the same structured data Pi uses to build the system prompt. Collections are mutable. Prefer changing `sections`, `selectedTools`, or `promptGuidelines`: Pi diffs the resulting prompt sections against what the model already has and appends one system message patching only the changed sections. Returning `systemPrompt`, or setting `forceSystemPrompt`, replaces the whole prompt for the run: every provider receives the forced text as its leading system prompt (a cache miss when it changes), and the session transcript keeps recording the structured sections. Tool selection changes update both the prompt contributions and executable provider tools; calling `pi.setActiveTools()` inside the handler has the same effect as editing `selectedTools`. Models that accept system messages mid-conversation receive the patch in place and keep their cached prefix; other models get the replayed prompt as their system prompt, which is a cache miss once per change.
564
567
 
565
568
  Inside `before_agent_start`, `event.systemPrompt` and `ctx.getSystemPrompt()` both reflect the chained system prompt as of the current handler. Later `before_agent_start` handlers can still modify it again.
566
569
 
@@ -735,6 +738,25 @@ pi.on("after_provider_response", (event, ctx) => {
735
738
 
736
739
  Header availability depends on provider and transport. Providers that abstract HTTP responses may not expose headers.
737
740
 
741
+ #### cache_warming_decision
742
+
743
+ Fired before each prompt-cache refresh with pi's decision filled in. The event carries only pi's cost estimates; use `ctx.model`, `ctx.isIdle()`, and `ctx.getContextUsage()` for everything else.
744
+
745
+ ```typescript
746
+ pi.on("cache_warming_decision", (event, ctx) => {
747
+ // event.warmCost: price of this refresh
748
+ // event.missCost: extra price of the next request if the entry is lost
749
+ // event.continuationProbability: pi's estimate that a request arrives in time
750
+ // event.action: "warm" | "stop", pi's decision
751
+
752
+ if (ctx.model?.provider === "my-provider") {
753
+ return { action: "stop" };
754
+ }
755
+ });
756
+ ```
757
+
758
+ Return `{ action: "warm" }` or `{ action: "stop" }` to override; the last handler that returns an action wins. `"stop"` ends warming until the next real request.
759
+
738
760
  ### Model Events
739
761
 
740
762
  #### model_select
@@ -906,6 +928,8 @@ pi.on("user_bash", (event, ctx) => {
906
928
  });
907
929
  ```
908
930
 
931
+ Returning `undefined` continues to the next handler, then local execution if none handles the event. A valid result stops propagation: `operations` executes the command through the supplied backend, while `result` records the completed command without executing it.
932
+
909
933
  ### Input Events
910
934
 
911
935
  #### input
@@ -1016,6 +1040,12 @@ Access to models, providers, and resolved authentication. `ctx.modelRegistry.get
1016
1040
 
1017
1041
  `ctx.scopedModels` is the read-only list of models scoped to the current session — the same set the `/scoped-models` command shows. It is resolved at session start from the `--models` CLI flag and the `enabledModels` setting (matched against the available catalogue with minimatch on `provider/modelId` or a bare `modelId`). It is empty when no scoping is configured, meaning every available model is usable. Each entry is `{ model, thinkingLevel? }`, where `thinkingLevel` is set only when a pattern pinned it (e.g. `anthropic/*:high`). Use it to populate a model picker that mirrors the built-in one instead of enumerating the whole catalogue via `ctx.modelRegistry.getAvailable()`.
1018
1042
 
1043
+ #### Streaming model calls
1044
+
1045
+ Use `ctx.modelRegistry.streamSimple(model, context, options)` for provider-neutral options such as `reasoning`, or `stream()` for API-specific options. Both use configured providers and resolve authentication, including for providers registered with `pi.registerProvider()`. Use these instead of `pi-ai/compat` streaming functions, which cannot see extension provider registrations.
1046
+
1047
+ Both return an `AssistantMessageEventStream`. Iterate it for response events and await `.result()` for the final message. Setup failures produce error events and error results.
1048
+
1019
1049
  ### ctx.signal
1020
1050
 
1021
1051
  The current agent abort signal, or `undefined` when no agent turn is active.
@@ -1119,7 +1149,7 @@ const options = ctx.getSystemPromptOptions();
1119
1149
  const contextPaths = options.contextFiles?.map((file) => file.path) ?? [];
1120
1150
  ```
1121
1151
 
1122
- This has the same shape and mutability as `before_agent_start` `event.systemPromptOptions`: custom prompt, active tools, tool snippets, prompt guidelines, appended system prompt text, cwd, loaded context files, and loaded skills. It may include full context file contents, so treat it as sensitive extension-local data and avoid exposing it through command lists, logs, or autocomplete metadata.
1152
+ This has the same shape and mutability as `before_agent_start` `event.systemPromptOptions`: custom or forced prompt, active tools, tool snippets, per-tool and custom rules, custom sections, appended prompt text, cwd, loaded context files, and loaded skills. It may include full context file contents, so treat it as sensitive extension-local data and avoid exposing it through command lists, logs, or autocomplete metadata.
1123
1153
 
1124
1154
  This reports the current base prompt inputs. It does not include per-turn `before_agent_start` chained system-prompt changes, later `context` event message mutations, or `before_provider_request` payload rewrites.
1125
1155
 
@@ -1197,7 +1227,7 @@ Options:
1197
1227
 
1198
1228
  ### ctx.navigateTree(targetId, options?)
1199
1229
 
1200
- Navigate to a different point in the session tree:
1230
+ Navigate to a different point in the session tree. Rejects while an agent response, manual or automatic compaction, or another tree navigation is active, even with `summarize: false`. These conflicts leave the active branch unchanged and reject the promise rather than returning `{ cancelled: true }`. Wait for the active operation to finish (for example, with `await ctx.waitForIdle()` in a command handler) and retry:
1201
1231
 
1202
1232
  ```typescript
1203
1233
  const result = await ctx.navigateTree("entry-id-456", {
@@ -1360,7 +1390,16 @@ export default function (pi: ExtensionAPI) {
1360
1390
 
1361
1391
  ### pi.on(event, handler)
1362
1392
 
1363
- Subscribe to events. See [Events](#events) for event types and return values.
1393
+ Subscribe to events. Returns an unsubscribe function that removes only that registration. See [Events](#events) for event types and return values.
1394
+
1395
+ ```typescript
1396
+ const unsubscribe = pi.on("agent_end", async (event) => {
1397
+ unsubscribe();
1398
+ await updateIntegration(event.messages);
1399
+ });
1400
+ ```
1401
+
1402
+ Handlers run in extension load order, then registration order within each extension. Adding or removing a handler does not affect a dispatch already in progress.
1364
1403
 
1365
1404
  ### pi.registerTool(definition)
1366
1405
 
@@ -2101,14 +2140,14 @@ See [examples/extensions/tool-override.ts](../examples/extensions/tool-override.
2101
2140
  **Your implementation must match the exact result shape**, including the `details` type. The UI and session logic depend on these shapes for rendering and state tracking.
2102
2141
 
2103
2142
  Built-in tool implementations:
2104
- - [read.ts](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/tools/read.ts) - `ReadToolDetails`
2105
- - [bash.ts](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/tools/bash.ts) - `BashToolDetails`
2106
- - [powershell.ts](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/tools/powershell.ts) - `PowerShellToolDetails`
2107
- - [edit.ts](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/tools/edit.ts)
2108
- - [write.ts](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/tools/write.ts)
2109
- - [grep.ts](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/tools/grep.ts) - `GrepToolDetails`
2110
- - [find.ts](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/tools/find.ts) - `FindToolDetails`
2111
- - [ls.ts](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/tools/ls.ts) - `LsToolDetails`
2143
+ - [read.ts](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/tools/read.ts) - `ReadToolDetails`
2144
+ - [bash.ts](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/tools/bash.ts) - `BashToolDetails`
2145
+ - [powershell.ts](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/tools/powershell.ts) - `PowerShellToolDetails`
2146
+ - [edit.ts](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/tools/edit.ts)
2147
+ - [write.ts](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/tools/write.ts)
2148
+ - [grep.ts](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/tools/grep.ts) - `GrepToolDetails`
2149
+ - [find.ts](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/tools/find.ts) - `FindToolDetails`
2150
+ - [ls.ts](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/tools/ls.ts) - `LsToolDetails`
2112
2151
 
2113
2152
  ### Remote Execution
2114
2153
 
@@ -2239,7 +2278,7 @@ export default function (pi: ExtensionAPI) {
2239
2278
 
2240
2279
  ### Custom Rendering
2241
2280
 
2242
- Tools can provide `renderCall` and `renderResult` for custom TUI display. See [tui.md](tui.md) for the full component API and [tool-execution.ts](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/modes/interactive/components/tool-execution.ts) for how tool rows are composed.
2281
+ Tools can provide `renderCall` and `renderResult` for custom TUI display. See [tui.md](tui.md) for the full component API and [tool-execution.ts](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/modes/interactive/components/tool-execution.ts) for how tool rows are composed.
2243
2282
 
2244
2283
  By default, tool output is wrapped in a `Box` that handles padding and background. A defined `renderCall` or `renderResult` must return a `Component`. If a slot renderer is not defined, `tool-execution.ts` uses fallback rendering for that slot.
2245
2284
 
@@ -2364,38 +2403,13 @@ If a slot renderer is not defined or throws:
2364
2403
 
2365
2404
  ### Dynamic Tool Loading
2366
2405
 
2367
- Extensions can register many tools while keeping only a small initial set active. A tool can then add more tools with `pi.setActiveTools()` during execution. Pi detects purely additive changes, records the newly available tool names on that tool result, and applies the updated active set before the next model request.
2368
-
2369
- This works with every model. Models with native deferred-loading support preserve the stable prompt prefix and load the new definitions at the tool-result position. Other models use the fallback described below.
2406
+ Extensions can register many tools while keeping only a small initial set active. A tool can then change the active set with `pi.setActiveTools()` during execution. Pi stores the initial prompt and tool loadout in the transcript's first system message, then appends tool and prompt deltas before the next model request. Providers that cannot represent a transition receive a complete transcript checkpoint, which may invalidate the cached prefix.
2370
2407
 
2371
2408
  The lifecycle is:
2372
2409
 
2373
2410
  1. Register every tool with `pi.registerTool()` so it appears in `pi.getAllTools()`.
2374
2411
  2. Keep loader tools, such as `search_tools`, active and leave searchable tools inactive.
2375
- 3. During loader execution, call `pi.setActiveTools([...currentTools, ...matchingTools])`. The change must be additive: do not remove currently active tools in the same call.
2376
- 4. Pi records which tools were added on the loader's tool result.
2377
- 5. Before the next model response, Pi exposes the added definitions using native deferred loading when supported, or the normal active tool list otherwise.
2378
-
2379
- You do not need to return provider-specific tool references or mark the loader as a special search tool. The active-tool change is the signal. Names passed to `pi.setActiveTools()` must already be registered; unknown names are ignored.
2380
-
2381
- #### Models with native deferred loading
2382
-
2383
- - **Anthropic**
2384
- - **Models:** Sonnet, Opus, Fable version 4.5 or newer (without Haiku)
2385
- - **Native representation:** Deferred definitions use `defer_loading`; the load point uses `tool_reference` content.
2386
- - **OpenAI**
2387
- - **Models:** `gpt-5.4` and newer family
2388
- - **Native representation:** Pi adds completed client `tool_search_call` and `tool_search_output` items at the load point.
2389
-
2390
- For a verified custom model or proxy, native handling can be enabled with `compat.supportsToolReferences: true` for `anthropic-messages`, or `compat.supportsToolSearch: true` for `openai-responses` and `openai-codex-responses`. Leave these disabled unless the endpoint and model accept the corresponding native protocol.
2391
-
2392
- #### Fallback behavior
2393
-
2394
- For all other models and providers, dynamic activation still works: Pi sends the complete current active tool list normally on the next request. The model can call the newly activated tools, but adding their definitions may invalidate the provider's cached prompt prefix.
2395
-
2396
- Pi also uses this safe fallback when the active set is not purely additive, such as replacing one group of tools with another. Tool removals therefore work, but they do not use deferred loading.
2397
-
2398
- For the best cache behavior, keep the loader tool active for the whole session and add tools instead of replacing the active set. Also note that activating a tool with `promptSnippet` or `promptGuidelines` rebuilds the system prompt; that system-prompt change can invalidate the prefix even when the provider supports deferred schemas. Lazily loaded tools should usually rely on their tool `description` and omit active-only prompt metadata.
2412
+ 3. During loader execution, call `pi.setActiveTools()` with the desired active tool names. Names must already be registered; unknown names are ignored.
2399
2413
 
2400
2414
  #### Search tool example
2401
2415
 
@@ -2497,7 +2511,7 @@ export default function (pi: ExtensionAPI) {
2497
2511
  }
2498
2512
  ```
2499
2513
 
2500
- When `search_tools` adds a match, the model receives that definition on the immediately following request. On a native-capable model the definition is anchored after the search result without changing the initial tool-schema prefix. On other models it appears in the normal tool list on that same following request.
2514
+ When `search_tools` adds a match, the model receives the complete updated tool list on the immediately following request.
2501
2515
 
2502
2516
  ## Custom UI
2503
2517
 
package/docs/json.md CHANGED
@@ -9,7 +9,7 @@ Outputs all session events as JSON lines to stdout. Useful for integrating pi in
9
9
  ## Event Types
10
10
 
11
11
  Wire events use `JsonAgentSessionEvent`. It matches
12
- [`AgentSessionEvent`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/agent-session.ts)
12
+ [`AgentSessionEvent`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/agent-session.ts)
13
13
  except that streaming message updates omit cumulative snapshots:
14
14
 
15
15
  ```typescript
@@ -31,7 +31,7 @@ type JsonAgentSessionEvent =
31
31
  `queue_update` emits the full pending steering and follow-up queues whenever they change. `compaction_start` and `compaction_end` cover both manual and automatic compaction.
32
32
 
33
33
  Other base events come from
34
- [`AgentEvent`](https://github.com/earendil-works/pi-mono/blob/main/packages/agent/src/types.ts):
34
+ [`AgentEvent`](https://github.com/earendil-works/pi/blob/main/packages/agent/src/types.ts):
35
35
 
36
36
  ```typescript
37
37
  type AgentEvent =
@@ -53,12 +53,12 @@ type AgentEvent =
53
53
 
54
54
  ## Message Types
55
55
 
56
- Base messages from [`packages/ai/src/types.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/ai/src/types.ts#L134):
56
+ Base messages from [`packages/ai/src/types.ts`](https://github.com/earendil-works/pi/blob/main/packages/ai/src/types.ts#L134):
57
57
  - `UserMessage` (line 134)
58
58
  - `AssistantMessage` (line 140)
59
59
  - `ToolResultMessage` (line 152)
60
60
 
61
- Extended messages from [`packages/coding-agent/src/core/messages.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/messages.ts#L29):
61
+ Extended messages from [`packages/coding-agent/src/core/messages.ts`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/messages.ts#L29):
62
62
  - `BashExecutionMessage` (line 29)
63
63
  - `CustomMessage` (line 46)
64
64
  - `BranchSummaryMessage` (line 55)