@draht/coding-agent 2026.7.13-1 → 2026.7.30

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 (288) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/README.md +1 -0
  3. package/dist/bun/cli.js +2 -0
  4. package/dist/bun/cli.js.map +1 -1
  5. package/dist/cli/args.d.ts.map +1 -1
  6. package/dist/cli/args.js +12 -2
  7. package/dist/cli/args.js.map +1 -1
  8. package/dist/cli/config-selector.js +1 -1
  9. package/dist/cli/config-selector.js.map +1 -1
  10. package/dist/cli/credential-print.d.ts +23 -0
  11. package/dist/cli/credential-print.d.ts.map +1 -0
  12. package/dist/cli/credential-print.js +116 -0
  13. package/dist/cli/credential-print.js.map +1 -0
  14. package/dist/cli/list-models.d.ts +2 -2
  15. package/dist/cli/list-models.d.ts.map +1 -1
  16. package/dist/cli/list-models.js +3 -3
  17. package/dist/cli/list-models.js.map +1 -1
  18. package/dist/cli/startup-ui.js +1 -1
  19. package/dist/cli/startup-ui.js.map +1 -1
  20. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  21. package/dist/core/agent-session-runtime.js +3 -0
  22. package/dist/core/agent-session-runtime.js.map +1 -1
  23. package/dist/core/agent-session-services.d.ts +3 -6
  24. package/dist/core/agent-session-services.d.ts.map +1 -1
  25. package/dist/core/agent-session-services.js +23 -9
  26. package/dist/core/agent-session-services.js.map +1 -1
  27. package/dist/core/agent-session.d.ts +52 -11
  28. package/dist/core/agent-session.d.ts.map +1 -1
  29. package/dist/core/agent-session.js +199 -101
  30. package/dist/core/agent-session.js.map +1 -1
  31. package/dist/core/auth-storage.d.ts +15 -103
  32. package/dist/core/auth-storage.d.ts.map +1 -1
  33. package/dist/core/auth-storage.js +46 -259
  34. package/dist/core/auth-storage.js.map +1 -1
  35. package/dist/core/cache-stats.d.ts +2 -2
  36. package/dist/core/cache-stats.d.ts.map +1 -1
  37. package/dist/core/cache-stats.js +1 -1
  38. package/dist/core/cache-stats.js.map +1 -1
  39. package/dist/core/compaction/branch-summarization.d.ts +8 -2
  40. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  41. package/dist/core/compaction/branch-summarization.js +8 -11
  42. package/dist/core/compaction/branch-summarization.js.map +1 -1
  43. package/dist/core/compaction/compaction.d.ts +19 -3
  44. package/dist/core/compaction/compaction.d.ts.map +1 -1
  45. package/dist/core/compaction/compaction.js +71 -26
  46. package/dist/core/compaction/compaction.js.map +1 -1
  47. package/dist/core/compaction/utils.d.ts +1 -1
  48. package/dist/core/compaction/utils.d.ts.map +1 -1
  49. package/dist/core/compaction/utils.js +6 -17
  50. package/dist/core/compaction/utils.js.map +1 -1
  51. package/dist/core/context-windows.d.ts +7 -0
  52. package/dist/core/context-windows.d.ts.map +1 -0
  53. package/dist/core/context-windows.js +35 -0
  54. package/dist/core/context-windows.js.map +1 -0
  55. package/dist/core/extensions/index.d.ts +1 -1
  56. package/dist/core/extensions/index.d.ts.map +1 -1
  57. package/dist/core/extensions/index.js.map +1 -1
  58. package/dist/core/extensions/loader.d.ts.map +1 -1
  59. package/dist/core/extensions/loader.js +18 -3
  60. package/dist/core/extensions/loader.js.map +1 -1
  61. package/dist/core/extensions/runner.d.ts +6 -1
  62. package/dist/core/extensions/runner.d.ts.map +1 -1
  63. package/dist/core/extensions/runner.js +80 -0
  64. package/dist/core/extensions/runner.js.map +1 -1
  65. package/dist/core/extensions/types.d.ts +48 -4
  66. package/dist/core/extensions/types.d.ts.map +1 -1
  67. package/dist/core/extensions/types.js.map +1 -1
  68. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  69. package/dist/core/extensions/wrapper.js +22 -3
  70. package/dist/core/extensions/wrapper.js.map +1 -1
  71. package/dist/core/footer-data-provider.d.ts +10 -0
  72. package/dist/core/footer-data-provider.d.ts.map +1 -1
  73. package/dist/core/footer-data-provider.js +1 -1
  74. package/dist/core/footer-data-provider.js.map +1 -1
  75. package/dist/core/keybindings.d.ts +13 -3
  76. package/dist/core/keybindings.d.ts.map +1 -1
  77. package/dist/core/keybindings.js +11 -3
  78. package/dist/core/keybindings.js.map +1 -1
  79. package/dist/core/model-config.d.ts +542 -0
  80. package/dist/core/model-config.d.ts.map +1 -0
  81. package/dist/core/model-config.js +247 -0
  82. package/dist/core/model-config.js.map +1 -0
  83. package/dist/core/model-registry.d.ts +17 -123
  84. package/dist/core/model-registry.d.ts.map +1 -1
  85. package/dist/core/model-registry.js +59 -730
  86. package/dist/core/model-registry.js.map +1 -1
  87. package/dist/core/model-resolver.d.ts +7 -6
  88. package/dist/core/model-resolver.d.ts.map +1 -1
  89. package/dist/core/model-resolver.js +41 -21
  90. package/dist/core/model-resolver.js.map +1 -1
  91. package/dist/core/model-runtime.d.ts +83 -0
  92. package/dist/core/model-runtime.d.ts.map +1 -0
  93. package/dist/core/model-runtime.js +431 -0
  94. package/dist/core/model-runtime.js.map +1 -0
  95. package/dist/core/models-store.d.ts +17 -0
  96. package/dist/core/models-store.d.ts.map +1 -0
  97. package/dist/core/models-store.js +46 -0
  98. package/dist/core/models-store.js.map +1 -0
  99. package/dist/core/package-manager.d.ts.map +1 -1
  100. package/dist/core/package-manager.js +31 -12
  101. package/dist/core/package-manager.js.map +1 -1
  102. package/dist/core/prompt-templates.d.ts +1 -0
  103. package/dist/core/prompt-templates.d.ts.map +1 -1
  104. package/dist/core/prompt-templates.js +4 -4
  105. package/dist/core/prompt-templates.js.map +1 -1
  106. package/dist/core/provider-composer.d.ts +55 -0
  107. package/dist/core/provider-composer.d.ts.map +1 -0
  108. package/dist/core/provider-composer.js +375 -0
  109. package/dist/core/provider-composer.js.map +1 -0
  110. package/dist/core/radius.d.ts +2 -0
  111. package/dist/core/radius.d.ts.map +1 -0
  112. package/dist/core/radius.js +2 -0
  113. package/dist/core/radius.js.map +1 -0
  114. package/dist/core/remote-catalog-provider.d.ts +5 -0
  115. package/dist/core/remote-catalog-provider.d.ts.map +1 -0
  116. package/dist/core/remote-catalog-provider.js +115 -0
  117. package/dist/core/remote-catalog-provider.js.map +1 -0
  118. package/dist/core/resource-loader.d.ts +15 -0
  119. package/dist/core/resource-loader.d.ts.map +1 -1
  120. package/dist/core/resource-loader.js +64 -9
  121. package/dist/core/resource-loader.js.map +1 -1
  122. package/dist/core/runtime-credentials.d.ts +15 -0
  123. package/dist/core/runtime-credentials.d.ts.map +1 -0
  124. package/dist/core/runtime-credentials.js +35 -0
  125. package/dist/core/runtime-credentials.js.map +1 -0
  126. package/dist/core/sdk.d.ts +3 -6
  127. package/dist/core/sdk.d.ts.map +1 -1
  128. package/dist/core/sdk.js +22 -21
  129. package/dist/core/sdk.js.map +1 -1
  130. package/dist/core/session-manager.d.ts +14 -6
  131. package/dist/core/session-manager.d.ts.map +1 -1
  132. package/dist/core/session-manager.js +116 -28
  133. package/dist/core/session-manager.js.map +1 -1
  134. package/dist/core/settings-manager.d.ts +1 -1
  135. package/dist/core/settings-manager.d.ts.map +1 -1
  136. package/dist/core/settings-manager.js.map +1 -1
  137. package/dist/core/system-prompt.d.ts.map +1 -1
  138. package/dist/core/system-prompt.js +2 -12
  139. package/dist/core/system-prompt.js.map +1 -1
  140. package/dist/core/tools/bash.d.ts +2 -0
  141. package/dist/core/tools/bash.d.ts.map +1 -1
  142. package/dist/core/tools/bash.js +34 -5
  143. package/dist/core/tools/bash.js.map +1 -1
  144. package/dist/core/tools/read.js +1 -1
  145. package/dist/core/tools/read.js.map +1 -1
  146. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  147. package/dist/core/tools/tool-definition-wrapper.js +3 -1
  148. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  149. package/dist/core/usage-totals.d.ts +19 -0
  150. package/dist/core/usage-totals.d.ts.map +1 -0
  151. package/dist/core/usage-totals.js +52 -0
  152. package/dist/core/usage-totals.js.map +1 -0
  153. package/dist/extensions/index.d.ts +3 -0
  154. package/dist/extensions/index.d.ts.map +1 -0
  155. package/dist/extensions/index.js +3 -0
  156. package/dist/extensions/index.js.map +1 -0
  157. package/dist/extensions/llama/client.d.ts +61 -0
  158. package/dist/extensions/llama/client.d.ts.map +1 -0
  159. package/dist/extensions/llama/client.js +300 -0
  160. package/dist/extensions/llama/client.js.map +1 -0
  161. package/dist/extensions/llama/huggingface.d.ts +23 -0
  162. package/dist/extensions/llama/huggingface.d.ts.map +1 -0
  163. package/dist/extensions/llama/huggingface.js +139 -0
  164. package/dist/extensions/llama/huggingface.js.map +1 -0
  165. package/dist/extensions/llama/index.d.ts +3 -0
  166. package/dist/extensions/llama/index.d.ts.map +1 -0
  167. package/dist/extensions/llama/index.js +208 -0
  168. package/dist/extensions/llama/index.js.map +1 -0
  169. package/dist/extensions/llama/provider.d.ts +10 -0
  170. package/dist/extensions/llama/provider.d.ts.map +1 -0
  171. package/dist/extensions/llama/provider.js +107 -0
  172. package/dist/extensions/llama/provider.js.map +1 -0
  173. package/dist/extensions/llama/ui.d.ts +42 -0
  174. package/dist/extensions/llama/ui.d.ts.map +1 -0
  175. package/dist/extensions/llama/ui.js +400 -0
  176. package/dist/extensions/llama/ui.js.map +1 -0
  177. package/dist/index.d.ts +4 -3
  178. package/dist/index.d.ts.map +1 -1
  179. package/dist/index.js +3 -3
  180. package/dist/index.js.map +1 -1
  181. package/dist/main.d.ts.map +1 -1
  182. package/dist/main.js +63 -16
  183. package/dist/main.js.map +1 -1
  184. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  185. package/dist/modes/interactive/components/assistant-message.js +22 -10
  186. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  187. package/dist/modes/interactive/components/custom-editor.js +1 -1
  188. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  189. package/dist/modes/interactive/components/custom-message.d.ts +3 -1
  190. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  191. package/dist/modes/interactive/components/custom-message.js +9 -2
  192. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  193. package/dist/modes/interactive/components/extension-editor.d.ts +1 -2
  194. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  195. package/dist/modes/interactive/components/extension-editor.js +16 -46
  196. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  197. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  198. package/dist/modes/interactive/components/footer.js +24 -23
  199. package/dist/modes/interactive/components/footer.js.map +1 -1
  200. package/dist/modes/interactive/components/login-dialog.d.ts +5 -5
  201. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  202. package/dist/modes/interactive/components/login-dialog.js +17 -8
  203. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  204. package/dist/modes/interactive/components/model-selector.d.ts +11 -4
  205. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  206. package/dist/modes/interactive/components/model-selector.js +74 -41
  207. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  208. package/dist/modes/interactive/components/oauth-selector.d.ts +4 -4
  209. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  210. package/dist/modes/interactive/components/oauth-selector.js +14 -25
  211. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  212. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  213. package/dist/modes/interactive/components/scoped-models-selector.js +22 -13
  214. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  215. package/dist/modes/interactive/components/tree-selector.d.ts +5 -0
  216. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  217. package/dist/modes/interactive/components/tree-selector.js +47 -12
  218. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  219. package/dist/modes/interactive/external-editor.d.ts +12 -0
  220. package/dist/modes/interactive/external-editor.d.ts.map +1 -0
  221. package/dist/modes/interactive/external-editor.js +37 -0
  222. package/dist/modes/interactive/external-editor.js.map +1 -0
  223. package/dist/modes/interactive/interactive-mode.d.ts +10 -7
  224. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  225. package/dist/modes/interactive/interactive-mode.js +369 -261
  226. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  227. package/dist/modes/rpc/rpc-client.d.ts +4 -0
  228. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  229. package/dist/modes/rpc/rpc-client.js +7 -0
  230. package/dist/modes/rpc/rpc-client.js.map +1 -1
  231. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  232. package/dist/modes/rpc/rpc-mode.js +20 -2
  233. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  234. package/dist/modes/rpc/rpc-types.d.ts +11 -0
  235. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  236. package/dist/modes/rpc/rpc-types.js.map +1 -1
  237. package/dist/package-manager-cli.d.ts.map +1 -1
  238. package/dist/package-manager-cli.js +67 -5
  239. package/dist/package-manager-cli.js.map +1 -1
  240. package/dist/utils/clipboard-native.d.ts +1 -0
  241. package/dist/utils/clipboard-native.d.ts.map +1 -1
  242. package/dist/utils/clipboard-native.js.map +1 -1
  243. package/dist/utils/clipboard.d.ts +2 -0
  244. package/dist/utils/clipboard.d.ts.map +1 -1
  245. package/dist/utils/clipboard.js +32 -8
  246. package/dist/utils/clipboard.js.map +1 -1
  247. package/dist/utils/version-check.d.ts.map +1 -1
  248. package/dist/utils/version-check.js +3 -1
  249. package/dist/utils/version-check.js.map +1 -1
  250. package/docs/compaction.md +9 -4
  251. package/docs/custom-provider.md +50 -16
  252. package/docs/environment-variables.md +88 -0
  253. package/docs/extensions.md +228 -15
  254. package/docs/index.md +2 -0
  255. package/docs/json.md +5 -1
  256. package/docs/keybindings.md +2 -0
  257. package/docs/llama-cpp.md +99 -0
  258. package/docs/models.md +13 -2
  259. package/docs/packages.md +1 -0
  260. package/docs/prompt-templates.md +1 -0
  261. package/docs/providers.md +36 -2
  262. package/docs/quickstart.md +1 -1
  263. package/docs/rpc.md +107 -7
  264. package/docs/sdk.md +3 -0
  265. package/docs/session-format.md +19 -3
  266. package/docs/settings.md +1 -1
  267. package/docs/tui.md +41 -26
  268. package/docs/usage.md +4 -14
  269. package/examples/extensions/custom-compaction.ts +4 -0
  270. package/examples/extensions/custom-provider-anthropic/index.ts +9 -3
  271. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  272. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  273. package/examples/extensions/custom-provider-qwen-cli/package.json +1 -1
  274. package/examples/extensions/gondolin/package.json +2 -2
  275. package/examples/extensions/handoff.ts +9 -1
  276. package/examples/extensions/kimi-deferred-tools.ts +61 -0
  277. package/examples/extensions/message-renderer.ts +2 -2
  278. package/examples/extensions/sandbox/package.json +1 -1
  279. package/examples/extensions/summarize.ts +3 -0
  280. package/examples/extensions/with-deps/package.json +1 -1
  281. package/examples/sdk/02-custom-model.ts +5 -8
  282. package/examples/sdk/09-api-keys-and-oauth.ts +15 -31
  283. package/examples/sdk/12-full-control.ts +9 -12
  284. package/package.json +10 -8
  285. package/dist/core/provider-display-names.d.ts +0 -2
  286. package/dist/core/provider-display-names.d.ts.map +0 -1
  287. package/dist/core/provider-display-names.js +0 -36
  288. package/dist/core/provider-display-names.js.map +0 -1
package/docs/providers.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Providers
2
2
 
3
- Pi supports subscription-based providers via OAuth and API key providers via environment variables or auth file. For each provider, pi knows all available models. The list is updated with every pi release.
3
+ Pi supports subscription-based providers via OAuth and API key providers via environment variables or auth file. Built-in catalogs ship with pi; configured providers may refresh newer catalogs and cache them in `~/.pi/agent/models-store.json` for offline use.
4
4
 
5
5
  ## Table of Contents
6
6
 
@@ -8,6 +8,7 @@ Pi supports subscription-based providers via OAuth and API key providers via env
8
8
  - [API Keys](#api-keys)
9
9
  - [Auth File](#auth-file)
10
10
  - [Cloud Providers](#cloud-providers)
11
+ - [llama.cpp](#llamacpp)
11
12
  - [Custom Providers](#custom-providers)
12
13
  - [Resolution Order](#resolution-order)
13
14
 
@@ -18,8 +19,11 @@ Use `/login` in interactive mode, then select a provider:
18
19
  - ChatGPT Plus/Pro (Codex)
19
20
  - Claude Pro/Max
20
21
  - GitHub Copilot
22
+ - xAI (Grok/X subscription)
23
+ - OpenRouter (OAuth-minted API key billed from OpenRouter credits)
24
+ - Radius
21
25
 
22
- Use `/logout` to clear credentials. Tokens are stored in `~/.pi/agent/auth.json` and auto-refresh when expired.
26
+ Use `/logout` to clear credentials. Tokens are stored in `~/.pi/agent/auth.json` and auto-refresh when expired. OpenRouter instead mints a user-controlled API key that does not expire automatically.
23
27
 
24
28
  ### OpenAI Codex
25
29
 
@@ -35,6 +39,22 @@ Anthropic subscription auth is active for Claude Pro/Max accounts. Third-party h
35
39
  - Press Enter for github.com, or enter your GitHub Enterprise Server domain
36
40
  - If you get "model not supported", enable it in VS Code: Copilot Chat → model selector → select model → "Enable"
37
41
 
42
+ ### xAI (Grok/X subscription)
43
+
44
+ - Run `/login xai`, then select **Use a subscription**
45
+ - `XAI_API_KEY` remains available through **Use an API key**
46
+
47
+ ### OpenRouter
48
+
49
+ - Run `/login openrouter`, then select **Sign in with OpenRouter** to open the OpenRouter PKCE authorization flow
50
+ - The authorization creates a user-controlled OpenRouter API key billed from your OpenRouter credits
51
+ - On remote/headless machines (e.g. over SSH) the browser cannot reach the loopback callback; paste the final redirect URL (or the authorization code) into the login prompt instead
52
+ - `OPENROUTER_API_KEY` remains available through **Use an API key**
53
+
54
+ ### Radius
55
+
56
+ Radius is a dynamic `pi-messages` gateway. `/login radius` stores OAuth tokens in `auth.json`; the gateway catalog is refreshed independently and cached in `models-store.json`. Custom Radius gateways can be declared in `models.json` with `"oauth": "radius"` and a gateway `baseUrl`.
57
+
38
58
  ## API Keys
39
59
 
40
60
  ### Environment Variables or Auth File
@@ -55,6 +75,7 @@ pi
55
75
  | DeepSeek | `DEEPSEEK_API_KEY` | `deepseek` |
56
76
  | NVIDIA NIM | `NVIDIA_API_KEY` | `nvidia` |
57
77
  | Google Gemini | `GEMINI_API_KEY` | `google` |
78
+ | Amazon Bedrock | `AWS_BEARER_TOKEN_BEDROCK` | `amazon-bedrock` |
58
79
  | Mistral | `MISTRAL_API_KEY` | `mistral` |
59
80
  | Groq | `GROQ_API_KEY` | `groq` |
60
81
  | Cerebras | `CEREBRAS_API_KEY` | `cerebras` |
@@ -67,12 +88,15 @@ pi
67
88
  | ZAI Coding Plan (China) | `ZAI_CODING_CN_API_KEY` | `zai-coding-cn` |
68
89
  | OpenCode Zen | `OPENCODE_API_KEY` | `opencode` |
69
90
  | OpenCode Go | `OPENCODE_API_KEY` | `opencode-go` |
91
+ | Radius | `RADIUS_API_KEY` | `radius` |
70
92
  | Hugging Face | `HF_TOKEN` | `huggingface` |
71
93
  | Fireworks | `FIREWORKS_API_KEY` | `fireworks` |
72
94
  | Together AI | `TOGETHER_API_KEY` | `together` |
73
95
  | Kimi For Coding | `KIMI_API_KEY` | `kimi-coding` |
74
96
  | MiniMax | `MINIMAX_API_KEY` | `minimax` |
75
97
  | MiniMax (China) | `MINIMAX_CN_API_KEY` | `minimax-cn` |
98
+ | Qwen Token Plan | `QWEN_TOKEN_PLAN_API_KEY` | `qwen-token-plan` |
99
+ | Qwen Token Plan (China) | `QWEN_TOKEN_PLAN_CN_API_KEY` | `qwen-token-plan-cn` |
76
100
  | Xiaomi MiMo | `XIAOMI_API_KEY` | `xiaomi` |
77
101
  | Xiaomi MiMo Token Plan (China) | `XIAOMI_TOKEN_PLAN_CN_API_KEY` | `xiaomi-token-plan-cn` |
78
102
  | Xiaomi MiMo Token Plan (Amsterdam) | `XIAOMI_TOKEN_PLAN_AMS_API_KEY` | `xiaomi-token-plan-ams` |
@@ -95,6 +119,8 @@ Store credentials in `~/.pi/agent/auth.json`:
95
119
  "opencode": { "type": "api_key", "key": "..." },
96
120
  "opencode-go": { "type": "api_key", "key": "..." },
97
121
  "together": { "type": "api_key", "key": "..." },
122
+ "qwen-token-plan": { "type": "api_key", "key": "sk-sp-..." },
123
+ "qwen-token-plan-cn": { "type": "api_key", "key": "sk-sp-..." },
98
124
  "xiaomi": { "type": "api_key", "key": "..." },
99
125
  "xiaomi-token-plan-cn": { "type": "api_key", "key": "..." },
100
126
  "xiaomi-token-plan-ams": { "type": "api_key", "key": "..." },
@@ -152,6 +178,8 @@ export AZURE_OPENAI_DEPLOYMENT_NAME_MAP=gpt-4=my-gpt4,gpt-4o=my-gpt4o
152
178
 
153
179
  ### Amazon Bedrock
154
180
 
181
+ Use `/login amazon-bedrock` to store a Bedrock API key, or configure one of the ambient AWS credential sources below:
182
+
155
183
  ```bash
156
184
  # Option 1: AWS Profile
157
185
  export AWS_PROFILE=your-profile
@@ -241,6 +269,12 @@ export GOOGLE_CLOUD_LOCATION=us-central1
241
269
 
242
270
  Or set `GOOGLE_APPLICATION_CREDENTIALS` to a service account key file.
243
271
 
272
+ ## llama.cpp
273
+
274
+ Pi supports the llama.cpp router server. Configure it with `/login llama.cpp`, manage loaded models with `/llama`, and select a loaded model with `/model`.
275
+
276
+ See [llama.cpp](llama-cpp.md) for server setup, model directory layout, environment variables, and command usage.
277
+
244
278
  ## Custom Providers
245
279
 
246
280
  **Via models.json:** Add Ollama, LM Studio, vLLM, or any provider that speaks a supported API (OpenAI Completions, OpenAI Responses, Anthropic Messages, Google Generative AI). See [models.md](models.md).
@@ -113,7 +113,7 @@ pi @README.md "Summarize this"
113
113
  pi @src/app.ts @src/app.test.ts "Review these together"
114
114
  ```
115
115
 
116
- Images can be pasted with Ctrl+V (Alt+V on Windows) or dragged into supported terminals.
116
+ Images or text can be pasted with Ctrl+V (Alt+V on Windows); images can also be dragged into supported terminals.
117
117
 
118
118
  ### Run shell commands
119
119
 
package/docs/rpc.md CHANGED
@@ -23,7 +23,7 @@ Common options:
23
23
  - **Responses**: JSON objects with `type: "response"` indicating command success/failure
24
24
  - **Events**: Agent events streamed to stdout as JSON lines
25
25
 
26
- All commands support an optional `id` field for request/response correlation. If provided, the corresponding response will include the same `id`.
26
+ All commands support an optional `id` field for request/response correlation. If provided, the corresponding response will include the same `id`. `bash_execution_update` events also include the `id` of their originating `bash` command.
27
27
 
28
28
  ### Framing
29
29
 
@@ -313,6 +313,26 @@ Response:
313
313
  }
314
314
  ```
315
315
 
316
+ #### get_available_thinking_levels
317
+
318
+ List the thinking levels supported by the current model. Returns `["off"]` for a model without reasoning support.
319
+
320
+ ```json
321
+ {"type": "get_available_thinking_levels"}
322
+ ```
323
+
324
+ Response:
325
+ ```json
326
+ {
327
+ "type": "response",
328
+ "command": "get_available_thinking_levels",
329
+ "success": true,
330
+ "data": {
331
+ "levels": ["off", "minimal", "low", "medium", "high"]
332
+ }
333
+ }
334
+ ```
335
+
316
336
  ### Queue Modes
317
337
 
318
338
  #### set_steering_mode
@@ -374,11 +394,22 @@ Response:
374
394
  "summary": "Summary of conversation...",
375
395
  "firstKeptEntryId": "abc123",
376
396
  "tokensBefore": 150000,
397
+ "estimatedTokensAfter": 32000,
398
+ "usage": {
399
+ "input": 32000,
400
+ "output": 1200,
401
+ "cacheRead": 0,
402
+ "cacheWrite": 0,
403
+ "totalTokens": 33200,
404
+ "cost": {"input": 0.01, "output": 0.02, "cacheRead": 0, "cacheWrite": 0, "total": 0.03}
405
+ },
377
406
  "details": {}
378
407
  }
379
408
  }
380
409
  ```
381
410
 
411
+ `estimatedTokensAfter` is a heuristic estimate over the rebuilt message context immediately after compaction, not a provider-exact token count. `usage` reports the LLM call or calls that generated the summary and may be omitted by custom compaction handlers.
412
+
382
413
  #### set_auto_compaction
383
414
 
384
415
  Enable or disable automatic compaction when context is nearly full.
@@ -424,15 +455,18 @@ Response:
424
455
 
425
456
  #### bash
426
457
 
427
- Execute a shell command and add output to conversation context.
458
+ Execute a shell command and add output to conversation context. Output streams as `bash_execution_update` events while the command runs; the response contains the final result.
428
459
 
429
460
  ```json
430
- {"type": "bash", "command": "ls -la"}
461
+ {"id": "req-1", "type": "bash", "command": "ls -la"}
431
462
  ```
432
463
 
464
+ Include an `id` to associate streamed `bash_execution_update` events with this command.
465
+
433
466
  Response:
434
467
  ```json
435
468
  {
469
+ "id": "req-1",
436
470
  "type": "response",
437
471
  "command": "bash",
438
472
  "success": true,
@@ -463,7 +497,7 @@ If output was truncated, includes `fullOutputPath`:
463
497
 
464
498
  **How bash results reach the LLM:**
465
499
 
466
- The `bash` command executes immediately and returns a `BashResult`. Internally, a `BashExecutionMessage` is created and stored in the agent's message state. This message does NOT emit an event.
500
+ The `bash` command executes immediately and returns a `BashResult`. Internally, a `BashExecutionMessage` is created and stored in the agent's message state.
467
501
 
468
502
  When the next `prompt` command is sent, all messages (including `BashExecutionMessage`) are transformed before being sent to the LLM. The `BashExecutionMessage` is converted to a `UserMessage` with this format:
469
503
 
@@ -478,7 +512,6 @@ drwxr-xr-x ...
478
512
  This means:
479
513
  1. Bash output is included in the LLM context on the **next prompt**, not immediately
480
514
  2. Multiple bash commands can be executed before a prompt; all outputs will be included
481
- 3. No event is emitted for the `BashExecutionMessage` itself
482
515
 
483
516
  #### abort_bash
484
517
 
@@ -534,7 +567,7 @@ Response:
534
567
  }
535
568
  ```
536
569
 
537
- `tokens` contains assistant usage totals for the current session state. `contextUsage` contains the actual current context-window estimate used for compaction and footer display.
570
+ `tokens` and `cost` include assistant messages, usage reported by tools, and compaction/branch-summary generation across the full session. `contextUsage` contains the actual current context-window estimate used for compaction and footer display.
538
571
 
539
572
  `contextUsage` is omitted when no model or context window is available. `contextUsage.tokens` and `contextUsage.percent` are `null` immediately after compaction until a fresh post-compaction assistant response provides valid usage data.
540
573
 
@@ -798,7 +831,7 @@ Each command has:
798
831
 
799
832
  ## Events
800
833
 
801
- Events are streamed to stdout as JSON lines during agent operation. Events do NOT include an `id` field (only responses do).
834
+ Events are streamed to stdout as JSON lines during agent operation. Events do not generally include an `id` field; `bash_execution_update` includes the `id` of its originating `bash` command when one was provided.
802
835
 
803
836
  ### Event Types
804
837
 
@@ -812,6 +845,7 @@ Events are streamed to stdout as JSON lines during agent operation. Events do NO
812
845
  | `message_start` | Message begins |
813
846
  | `message_update` | Streaming update (text/thinking/toolcall deltas) |
814
847
  | `message_end` | Message completes |
848
+ | `bash_execution_update` | Direct RPC bash command output chunk |
815
849
  | `tool_execution_start` | Tool begins execution |
816
850
  | `tool_execution_update` | Tool execution progress (streaming output) |
817
851
  | `tool_execution_end` | Tool completes |
@@ -820,6 +854,9 @@ Events are streamed to stdout as JSON lines during agent operation. Events do NO
820
854
  | `compaction_end` | Compaction completes |
821
855
  | `auto_retry_start` | Auto-retry begins (after transient error) |
822
856
  | `auto_retry_end` | Auto-retry completes (success or final failure) |
857
+ | `summarization_retry_scheduled` | Retry scheduled for a transient compaction or branch-summary summarization error |
858
+ | `summarization_retry_attempt_start` | Retried summarization request starts |
859
+ | `summarization_retry_finished` | Summarization retry loop completes |
823
860
  | `extension_error` | Extension threw an error |
824
861
 
825
862
  ### agent_start
@@ -917,6 +954,20 @@ Example streaming a text response:
917
954
  {"type":"message_update","message":{...},"assistantMessageEvent":{"type":"text_end","contentIndex":0,"content":"Hello world","partial":{...}}}
918
955
  ```
919
956
 
957
+ ### bash_execution_update
958
+
959
+ Emitted once for each output chunk from a direct `bash` command. `id` matches the command's `id`, allowing clients to associate output with the correct command.
960
+
961
+ Events stream all output while the command runs, even if the final `bash` response's `output` is truncated.
962
+
963
+ ```json
964
+ {
965
+ "type": "bash_execution_update",
966
+ "id": "req-1",
967
+ "delta": "total 48\n"
968
+ }
969
+ ```
970
+
920
971
  ### tool_execution_start / tool_execution_update / tool_execution_end
921
972
 
922
973
  Emitted when a tool begins, streams progress, and completes execution.
@@ -992,6 +1043,15 @@ The `reason` field is `"manual"`, `"threshold"`, or `"overflow"`.
992
1043
  "summary": "Summary of conversation...",
993
1044
  "firstKeptEntryId": "abc123",
994
1045
  "tokensBefore": 150000,
1046
+ "estimatedTokensAfter": 32000,
1047
+ "usage": {
1048
+ "input": 32000,
1049
+ "output": 1200,
1050
+ "cacheRead": 0,
1051
+ "cacheWrite": 0,
1052
+ "totalTokens": 33200,
1053
+ "cost": {"input": 0.01, "output": 0.02, "cacheRead": 0, "cacheWrite": 0, "total": 0.03}
1054
+ },
995
1055
  "details": {}
996
1056
  },
997
1057
  "aborted": false,
@@ -1037,6 +1097,36 @@ On final failure (max retries exceeded):
1037
1097
  }
1038
1098
  ```
1039
1099
 
1100
+ ### summarization_retry_scheduled / summarization_retry_attempt_start / summarization_retry_finished
1101
+
1102
+ Emitted when compaction or branch-summary summarization retries after a transient provider error. These events use the same retry settings as automatic assistant-turn retries.
1103
+
1104
+ ```json
1105
+ {
1106
+ "type": "summarization_retry_scheduled",
1107
+ "attempt": 1,
1108
+ "maxAttempts": 3,
1109
+ "delayMs": 2000,
1110
+ "errorMessage": "terminated"
1111
+ }
1112
+ ```
1113
+
1114
+ ```json
1115
+ {
1116
+ "type": "summarization_retry_attempt_start",
1117
+ "source": "compaction",
1118
+ "reason": "threshold"
1119
+ }
1120
+ ```
1121
+
1122
+ For branch summaries, `source` is `"branchSummary"` and no `reason` is present.
1123
+
1124
+ ```json
1125
+ {
1126
+ "type": "summarization_retry_finished"
1127
+ }
1128
+ ```
1129
+
1040
1130
  ### extension_error
1041
1131
 
1042
1132
  Emitted when an extension throws an error.
@@ -1344,11 +1434,21 @@ Stop reasons: `"stop"`, `"length"`, `"toolUse"`, `"error"`, `"aborted"`
1344
1434
  "toolCallId": "call_123",
1345
1435
  "toolName": "bash",
1346
1436
  "content": [{"type": "text", "text": "total 48\ndrwxr-xr-x ..."}],
1437
+ "usage": {
1438
+ "input": 100,
1439
+ "output": 50,
1440
+ "cacheRead": 0,
1441
+ "cacheWrite": 0,
1442
+ "totalTokens": 150,
1443
+ "cost": {"input": 0.0003, "output": 0.00075, "cacheRead": 0, "cacheWrite": 0, "total": 0.00105}
1444
+ },
1347
1445
  "isError": false,
1348
1446
  "timestamp": 1733234567890
1349
1447
  }
1350
1448
  ```
1351
1449
 
1450
+ `usage` is optional and reports nested LLM work performed by the tool. When present, it contributes to session token and cost totals.
1451
+
1352
1452
  ### BashExecutionMessage
1353
1453
 
1354
1454
  Created by the `bash` RPC command (not by LLM tool calls):
package/docs/sdk.md CHANGED
@@ -323,6 +323,9 @@ session.subscribe((event) => {
323
323
  case "compaction_end":
324
324
  case "auto_retry_start":
325
325
  case "auto_retry_end":
326
+ case "summarization_retry_scheduled":
327
+ case "summarization_retry_attempt_start":
328
+ case "summarization_retry_finished":
326
329
  break;
327
330
  }
328
331
  });
@@ -96,6 +96,7 @@ interface ToolResultMessage {
96
96
  toolName: string;
97
97
  content: (TextContent | ImageContent)[];
98
98
  details?: any; // Tool-specific metadata
99
+ usage?: Usage; // Nested LLM work performed by the tool
99
100
  isError: boolean;
100
101
  timestamp: number;
101
102
  }
@@ -116,6 +117,8 @@ interface Usage {
116
117
  }
117
118
  ```
118
119
 
120
+ The exported pi-ai `StopReason` type also includes `"pending"`, but that value is reserved for partial messages in streaming events. Terminal `done`/`error` messages replace it with a completion reason before pi persists the assistant message, so `"pending"` should never appear in session JSONL.
121
+
119
122
  ### Extended Message Types (from pi-coding-agent)
120
123
 
121
124
  ```typescript
@@ -231,9 +234,18 @@ Created when context is compacted. Stores a summary of earlier messages.
231
234
  {"type":"compaction","id":"f6g7h8i9","parentId":"e5f6g7h8","timestamp":"2024-12-03T14:10:00.000Z","summary":"User discussed X, Y, Z...","firstKeptEntryId":"c3d4e5f6","tokensBefore":50000}
232
235
  ```
233
236
 
237
+ Newer harness-generated compactions embed the retained post-compaction context directly on the entry, instead of `firstKeptEntryId`:
238
+
239
+ ```json
240
+ {"type":"compaction","id":"f6g7h8i9","parentId":"e5f6g7h8","timestamp":"2024-12-03T14:10:00.000Z","summary":"User discussed X, Y, Z...","tokensBefore":50000,"retainedTail":[{"role":"user","content":"latest request"},{"role":"assistant","content":[{"type":"text","text":"latest reply"}],"provider":"anthropic","model":"claude-sonnet-4-5","usage":{...},"stopReason":"stop"}]}
241
+ ```
242
+
234
243
  Optional fields:
244
+ - `usage`: LLM usage from generating the summary; included in session token and cost totals
245
+ - `retainedTail`: Materialized `AgentMessage[]` kept after compaction. This is optional only for backward compatibility with older sessions. Newer harness-generated compactions include it so we can rebuild context from this checkpoint without walking older entries before the compaction entry.
235
246
  - `details`: Implementation-specific data (e.g., `{ readFiles: string[], modifiedFiles: string[] }` for default, or custom data for extensions)
236
247
  - `fromHook`: `true` if generated by an extension, `false`/`undefined` if pi-generated (legacy field name)
248
+ - `firstKeptEntryId`: for compatibility with old entry format.
237
249
 
238
250
  ### BranchSummaryEntry
239
251
 
@@ -244,6 +256,7 @@ Created when switching branches via `/tree` with an LLM generated summary of the
244
256
  ```
245
257
 
246
258
  Optional fields:
259
+ - `usage`: LLM usage from generating the summary; included in session token and cost totals
247
260
  - `details`: File tracking data (`{ readFiles: string[], modifiedFiles: string[] }`) for default, or custom data for extensions
248
261
  - `fromHook`: `true` if generated by an extension, `false`/`undefined` if pi-generated (legacy field name)
249
262
 
@@ -311,8 +324,9 @@ Entries form a tree:
311
324
  1. Collects all entries on the path
312
325
  2. If a `CompactionEntry` is on the path:
313
326
  - Includes the compaction entry first
314
- - Then entries from `firstKeptEntryId` to compaction
315
- - Then entries after compaction
327
+ - If `retainedTail` is present, it acts as a self-contained checkpoint and entries after the compaction are included
328
+ - Otherwise entries from `firstKeptEntryId` to the compaction are included
329
+ - Then entries after compaction are included
316
330
  3. Preserves non-message entries in the selected range so interactive mode can render them
317
331
 
318
332
  `buildSessionContext()` builds on that entry list to produce the message list for the LLM:
@@ -320,11 +334,13 @@ Entries form a tree:
320
334
  1. Extracts current model and thinking level settings from the full path
321
335
  2. Converts selected entries to messages:
322
336
  - `message` -> stored `AgentMessage`
323
- - `compaction` -> `compactionSummary`
337
+ - `compaction` -> `compactionSummary` plus `retainedTail` when present
324
338
  - `branch_summary` -> `branchSummary`
325
339
  - `custom_message` -> `CustomMessage`
326
340
  - `custom` -> no context message
327
341
 
342
+ This makes newer compactions act like self-contained checkpoints. `retainedTail` is optional only so older sessions that only store `firstKeptEntryId` continue to load correctly.
343
+
328
344
  ## Parsing Example
329
345
 
330
346
  ```typescript
package/docs/settings.md CHANGED
@@ -130,7 +130,7 @@ Set `PI_SKIP_VERSION_CHECK=1` to disable the Pi version update check. Use `--off
130
130
  | `retry.provider.maxRetries` | number | `0` | Provider/SDK retry attempts |
131
131
  | `retry.provider.maxRetryDelayMs` | number | `60000` | Max server-requested delay before failing (60s) |
132
132
 
133
- When a provider requests a retry delay longer than `retry.provider.maxRetryDelayMs` (e.g., Google's "quota will reset after 5h"), the request fails immediately with an informative error instead of waiting silently. Set to `0` to disable the cap.
133
+ When a provider requests a retry delay longer than `retry.provider.maxRetryDelayMs`, the request fails immediately with an informative error instead of waiting silently. Set it to `0` to disable the limit.
134
134
 
135
135
  Keep `retry.provider.maxRetries` at `0` unless provider-level retries are explicitly needed. Setting it above `0` can make SDK/provider retries handle out-of-usage-limit errors before Pi sees them, which may block the agent until the provider quota resets in some circumstances.
136
136
 
package/docs/tui.md CHANGED
@@ -90,19 +90,32 @@ Without this propagation, typing with an IME (Chinese, Japanese, Korean, etc.) w
90
90
 
91
91
  ```typescript
92
92
  pi.on("session_start", async (_event, ctx) => {
93
- const handle = ctx.ui.custom(myComponent);
94
- // handle.requestRender() - trigger re-render
95
- // handle.close() - restore normal UI
93
+ const result = await ctx.ui.custom<string | null>((tui, theme, keybindings, done) =>
94
+ new MyComponent({
95
+ theme,
96
+ keybindings,
97
+ onChange: () => tui.requestRender(),
98
+ onSelect: (value) => done(value),
99
+ onCancel: () => done(null),
100
+ })
101
+ );
96
102
  });
97
103
  ```
98
104
 
99
- **In custom tools** via `pi.ui.custom()`:
105
+ **In custom tools** via `ctx.ui.custom()`:
100
106
 
101
107
  ```typescript
102
- async execute(toolCallId, params, onUpdate, ctx, signal) {
103
- const handle = pi.ui.custom(myComponent);
104
- // ...
105
- handle.close();
108
+ async execute(toolCallId, params, signal, onUpdate, ctx) {
109
+ const result = await ctx.ui.custom<string | null>((tui, theme, keybindings, done) =>
110
+ new MyComponent({
111
+ theme,
112
+ keybindings,
113
+ onChange: () => tui.requestRender(),
114
+ onSelect: (value) => done(value),
115
+ onCancel: () => done(null),
116
+ })
117
+ );
118
+ // Use result...
106
119
  }
107
120
  ```
108
121
 
@@ -374,24 +387,26 @@ Usage in an extension:
374
387
  ```typescript
375
388
  pi.registerCommand("pick", {
376
389
  description: "Pick an item",
377
- handler: async (args, ctx) => {
390
+ handler: async (_args, ctx) => {
378
391
  const items = ["Option A", "Option B", "Option C"];
379
- const selector = new MySelector(items);
380
-
381
- let handle: { close: () => void; requestRender: () => void };
382
-
383
- await new Promise<void>((resolve) => {
384
- selector.onSelect = (item) => {
385
- ctx.ui.notify(`Selected: ${item}`, "info");
386
- handle.close();
387
- resolve();
388
- };
389
- selector.onCancel = () => {
390
- handle.close();
391
- resolve();
392
+ const selected = await ctx.ui.custom<string | null>((tui, _theme, _keybindings, done) => {
393
+ const selector = new MySelector(items);
394
+ selector.onSelect = done;
395
+ selector.onCancel = () => done(null);
396
+
397
+ return {
398
+ render: (width) => selector.render(width),
399
+ handleInput: (data) => {
400
+ selector.handleInput(data);
401
+ tui.requestRender();
402
+ },
403
+ invalidate: () => selector.invalidate(),
392
404
  };
393
- handle = ctx.ui.custom(selector);
394
405
  });
406
+
407
+ if (selected !== null) {
408
+ ctx.ui.notify(`Selected: ${selected}`, "info");
409
+ }
395
410
  }
396
411
  });
397
412
  ```
@@ -486,7 +501,7 @@ class CachedComponent {
486
501
  }
487
502
  ```
488
503
 
489
- Call `invalidate()` when state changes, then `handle.requestRender()` to trigger re-render.
504
+ Call `invalidate()` when state changes, then use the injected `tui.requestRender()` to trigger re-render.
490
505
 
491
506
  ## Invalidation and Theme Changes
492
507
 
@@ -885,9 +900,9 @@ class VimEditor extends CustomEditor {
885
900
 
886
901
  export default function (pi: ExtensionAPI) {
887
902
  pi.on("session_start", (_event, ctx) => {
888
- // Factory receives theme and keybindings from the app
903
+ // Factory receives the TUI, theme, and keybindings from the app
889
904
  ctx.ui.setEditorComponent((tui, theme, keybindings) =>
890
- new VimEditor(theme, keybindings)
905
+ new VimEditor(tui, theme, keybindings)
891
906
  );
892
907
  });
893
908
  }
package/docs/usage.md CHANGED
@@ -11,7 +11,7 @@ The interface has four main areas:
11
11
  - **Startup header** - shortcuts, loaded context files, prompt templates, skills, and extensions
12
12
  - **Messages** - user messages, assistant responses, tool calls, tool results, notifications, errors, and extension UI
13
13
  - **Editor** - where you type; border color indicates the current thinking level
14
- - **Footer** - working directory, session name, token/cache usage, cost, context usage, and current model
14
+ - **Footer** - working directory, session name, token/cache usage, cost, context usage, and current model. Totals include assistant responses, usage reported by tools, and summary generation.
15
15
 
16
16
  The editor can be replaced temporarily by built-in UI such as `/settings` or by custom extension UI.
17
17
 
@@ -22,6 +22,7 @@ The editor can be replaced temporarily by built-in UI such as `/settings` or by
22
22
  | File reference | Type `@` to fuzzy-search project files |
23
23
  | Path completion | Press Tab to complete paths |
24
24
  | Multi-line input | Shift+Enter, or Ctrl+Enter on Windows Terminal |
25
+ | Copy response | Ctrl+X copies the last assistant message; in `/tree`, it copies the selected message |
25
26
  | Images | Paste with Ctrl+V, Alt+V on Windows, or drag into the terminal |
26
27
  | Shell command | `!command` runs and sends output to the model |
27
28
  | Hidden shell command | `!!command` runs without sending output to the model |
@@ -36,6 +37,7 @@ Type `/` in the editor to open command completion. Extensions can register custo
36
37
  | Command | Description |
37
38
  |---------|-------------|
38
39
  | `/login`, `/logout` | Manage OAuth or API-key credentials |
40
+ | [`/llama`](llama-cpp.md) | Download, load, and unload llama.cpp router models |
39
41
  | `/model` | Switch models |
40
42
  | `/scoped-models` | Enable/disable models for Ctrl+P cycling |
41
43
  | `/settings` | Thinking level, theme, message delivery, transport |
@@ -147,6 +149,7 @@ pi remove <source> [-l] # Remove package
147
149
  pi uninstall <source> [-l] # Alias for remove
148
150
  pi update [source|self|pi] # Update pi and packages; reconcile pinned git refs
149
151
  pi update --extensions # Update packages only; reconcile pinned git refs
152
+ pi update --models # Refresh model catalogs only
150
153
  pi update --self # Update pi only
151
154
  pi update --extension <src> # Update one package
152
155
  pi list # List installed packages
@@ -283,19 +286,6 @@ pi --tools read,grep,find,ls -p "Review the code"
283
286
  pi --exclude-tools ask_question
284
287
  ```
285
288
 
286
- ### Environment Variables
287
-
288
- | Variable | Description |
289
- |----------|-------------|
290
- | `PI_CODING_AGENT_DIR` | Override config directory; default is `~/.pi/agent` |
291
- | `PI_CODING_AGENT_SESSION_DIR` | Override session storage directory; overridden by `--session-dir` |
292
- | `PI_PACKAGE_DIR` | Override package directory, useful for Nix/Guix store paths |
293
- | `PI_OFFLINE` | Disable startup network operations, including update checks, package update checks, and install/update telemetry |
294
- | `PI_SKIP_VERSION_CHECK` | Skip the Pi version update check at startup. This prevents the `pi.dev` latest-version request |
295
- | `PI_TELEMETRY` | Override install/update telemetry and provider attribution headers: `1`/`true`/`yes` or `0`/`false`/`no`. This does not disable update checks |
296
- | `PI_CACHE_RETENTION` | Set to `long` for extended prompt cache where supported |
297
- | `VISUAL`, `EDITOR` | Fallback external editor for Ctrl+G when `externalEditor` is unset; defaults to Notepad on Windows and `nano` elsewhere |
298
-
299
289
  ## Design Principles
300
290
 
301
291
  Pi keeps the core small and pushes workflow-specific behavior into extensions, skills, prompt templates, and packages.
@@ -13,6 +13,7 @@
13
13
  * pi --extension examples/extensions/custom-compaction.ts
14
14
  */
15
15
 
16
+ import { uuidv7 } from "@draht/ai";
16
17
  import { complete } from "@draht/ai/compat";
17
18
  import type { ExtensionAPI } from "@draht/coding-agent";
18
19
  import { convertToLlm, serializeConversation } from "@draht/coding-agent";
@@ -96,6 +97,8 @@ ${conversationText}
96
97
  env: auth.env,
97
98
  maxTokens: 8192,
98
99
  signal,
100
+ cacheRetention: "none",
101
+ sessionId: uuidv7(),
99
102
  },
100
103
  );
101
104
 
@@ -116,6 +119,7 @@ ${conversationText}
116
119
  summary,
117
120
  firstKeptEntryId,
118
121
  tokensBefore,
122
+ usage: response.usage,
119
123
  },
120
124
  };
121
125
  } catch (error) {
@@ -46,7 +46,7 @@ import {
46
46
  import type { ExtensionAPI } from "@draht/coding-agent";
47
47
 
48
48
  // =============================================================================
49
- // OAuth Implementation (copied from packages/ai/src/utils/oauth/anthropic.ts)
49
+ // OAuth implementation adapted for the legacy extension compatibility interface.
50
50
  // =============================================================================
51
51
 
52
52
  const decode = (s: string) => atob(s);
@@ -353,7 +353,7 @@ function streamCustomAnthropic(
353
353
  totalTokens: 0,
354
354
  cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
355
355
  },
356
- stopReason: "stop",
356
+ stopReason: "pending",
357
357
  timestamp: Date.now(),
358
358
  };
359
359
 
@@ -546,8 +546,14 @@ function streamCustomAnthropic(
546
546
  if (options?.signal?.aborted) {
547
547
  throw new Error("Request was aborted");
548
548
  }
549
+ if (output.stopReason === "pending") {
550
+ throw new Error("Anthropic stream ended without a stop reason");
551
+ }
552
+ if (output.stopReason === "error" || output.stopReason === "aborted") {
553
+ throw new Error(output.errorMessage || "An unknown error occurred");
554
+ }
549
555
 
550
- stream.push({ type: "done", reason: output.stopReason as "stop" | "length" | "toolUse", message: output });
556
+ stream.push({ type: "done", reason: output.stopReason, message: output });
551
557
  stream.end();
552
558
  } catch (error) {
553
559
  for (const block of output.content) delete (block as any).index;
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "pi-extension-custom-provider-anthropic",
2
+ "name": "draht-extension-custom-provider-anthropic",
3
3
  "private": true,
4
4
  "version": "0.80.6",
5
5
  "type": "module",
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "pi-extension-custom-provider-gitlab-duo",
2
+ "name": "draht-extension-custom-provider-gitlab-duo",
3
3
  "private": true,
4
4
  "version": "0.80.6",
5
5
  "type": "module",