pi-namespace-patch 0.85.1 → 0.86.0-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.
- package/CHANGELOG.md +86 -0
- package/README.md +26 -705
- package/dist/bundle/chunks/anthropic-messages-MYU5ZMRF.js +6 -0
- package/dist/bundle/chunks/azure-openai-responses-HUSQ3GP2.js +2 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +47 -38
- package/dist/bundle/chunks/chunk-A3JYRWB6.js +2 -0
- package/dist/bundle/chunks/chunk-DTD7JQ7Y.js +42 -0
- package/dist/bundle/chunks/chunk-FUXEF6JQ.js +44 -0
- package/dist/bundle/chunks/chunk-IS2VY2NY.js +1561 -0
- package/dist/bundle/chunks/{chunk-IDDQWTHI.js → chunk-RCZIEVGO.js} +10 -1
- package/dist/bundle/chunks/chunk-S7SZN6Z3.js +2 -0
- package/dist/bundle/chunks/chunk-SXW7XMQG.js +2 -0
- package/dist/bundle/chunks/chunk-WIUZI2CJ.js +11 -0
- package/dist/bundle/chunks/github-copilot.js +1 -1
- package/dist/bundle/chunks/google-generative-ai-IMS5EK2Y.js +2 -0
- package/dist/bundle/chunks/google-vertex-O4YJEQUW.js +2 -0
- package/dist/bundle/chunks/jiti-loader-C3NU2SDH.js +21 -0
- package/dist/bundle/chunks/jiti-static-loader-E6ANQD5T.js +2 -0
- package/dist/bundle/chunks/mistral-conversations-NOSQHBEY.js +5 -0
- package/dist/bundle/chunks/{node-KG362ECQ.js → node-O3RIBJRH.js} +1 -1
- package/dist/bundle/chunks/openai-codex-responses-QDSOTBBO.js +10 -0
- package/dist/bundle/chunks/openai-completions-KQPOPEVM.js +7 -0
- package/dist/bundle/chunks/openai-responses-HWEUZ6WZ.js +2 -0
- package/dist/bundle/chunks/{pi-messages-PML4SPVJ.js → pi-messages-GFKBWJHZ.js} +1 -1
- package/dist/bundle/chunks/virtual-modules-UQVS3IVK.js +2 -0
- package/dist/bundle/cli.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/cli/session-picker.d.ts +1 -1
- package/dist/cli/session-picker.d.ts.map +1 -1
- package/dist/cli/session-picker.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -1
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session.d.ts +56 -6
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +294 -157
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/bug-report-upload.d.ts +12 -0
- package/dist/core/bug-report-upload.d.ts.map +1 -0
- package/dist/core/bug-report-upload.js +22 -0
- package/dist/core/bug-report-upload.js.map +1 -0
- package/dist/core/bug-report.d.ts +176 -0
- package/dist/core/bug-report.d.ts.map +1 -0
- package/dist/core/bug-report.js +292 -0
- package/dist/core/bug-report.js.map +1 -0
- package/dist/core/cache-stats.d.ts.map +1 -1
- package/dist/core/cache-stats.js +12 -1
- package/dist/core/cache-stats.js.map +1 -1
- package/dist/core/cache-warmer.d.ts +102 -0
- package/dist/core/cache-warmer.d.ts.map +1 -0
- package/dist/core/cache-warmer.js +342 -0
- package/dist/core/cache-warmer.js.map +1 -0
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +2 -2
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +2 -2
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +11 -12
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/crash-log.d.ts +22 -0
- package/dist/core/crash-log.d.ts.map +1 -0
- package/dist/core/crash-log.js +71 -0
- package/dist/core/crash-log.js.map +1 -0
- package/dist/core/experimental.d.ts +0 -4
- package/dist/core/experimental.d.ts.map +1 -1
- package/dist/core/experimental.js +0 -4
- package/dist/core/experimental.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/jiti-loader.d.ts +2 -0
- package/dist/core/extensions/jiti-loader.d.ts.map +1 -0
- package/dist/core/extensions/jiti-loader.js +4 -0
- package/dist/core/extensions/jiti-loader.js.map +1 -0
- package/dist/core/extensions/jiti-static-loader.d.ts +2 -0
- package/dist/core/extensions/jiti-static-loader.d.ts.map +1 -0
- package/dist/core/extensions/jiti-static-loader.js +4 -0
- package/dist/core/extensions/jiti-static-loader.js.map +1 -0
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +38 -51
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +10 -7
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +85 -67
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +60 -50
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/extensions/virtual-modules.d.ts +3 -0
- package/dist/core/extensions/virtual-modules.d.ts.map +1 -0
- package/dist/core/extensions/virtual-modules.js +38 -0
- package/dist/core/extensions/virtual-modules.js.map +1 -0
- package/dist/core/extensions/wrapper.d.ts.map +1 -1
- package/dist/core/extensions/wrapper.js +1 -20
- package/dist/core/extensions/wrapper.js.map +1 -1
- package/dist/core/index.d.ts +2 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/keybindings.d.ts +1 -1
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +1 -1
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/messages.js +1 -0
- package/dist/core/messages.js.map +1 -1
- package/dist/core/model-config.d.ts +101 -20
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +25 -18
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-registry.d.ts +5 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +8 -0
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +1 -1
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +5 -3
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/provider-composer.d.ts +3 -2
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +2 -0
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/radius.d.ts +3 -0
- package/dist/core/radius.d.ts.map +1 -1
- package/dist/core/radius.js +6 -0
- package/dist/core/radius.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +60 -38
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-export.d.ts +6 -2
- package/dist/core/session-export.d.ts.map +1 -1
- package/dist/core/session-export.js +14 -13
- package/dist/core/session-export.js.map +1 -1
- package/dist/core/session-manager.d.ts +29 -6
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +159 -96
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +20 -4
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +43 -7
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +1 -0
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/system-prompt.d.ts +49 -6
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +121 -92
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/bash.d.ts +2 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +10 -4
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +1 -2
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +1 -2
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/renderers/bash.d.ts.map +1 -1
- package/dist/core/tools/renderers/bash.js +9 -1
- package/dist/core/tools/renderers/bash.js.map +1 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +1 -2
- package/dist/core/tools/write.js.map +1 -1
- package/dist/core/usage-totals.d.ts +1 -1
- package/dist/core/usage-totals.d.ts.map +1 -1
- package/dist/core/usage-totals.js +5 -1
- package/dist/core/usage-totals.js.map +1 -1
- package/dist/extensions/llama/client.d.ts +2 -0
- package/dist/extensions/llama/client.d.ts.map +1 -1
- package/dist/extensions/llama/client.js +7 -3
- package/dist/extensions/llama/client.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts.map +1 -1
- package/dist/extensions/llama/provider.js +20 -5
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +13 -9
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +2 -2
- package/dist/migrations.js.map +1 -1
- package/dist/modes/interactive/bug-report.d.ts +14 -0
- package/dist/modes/interactive/bug-report.d.ts.map +1 -0
- package/dist/modes/interactive/bug-report.js +209 -0
- package/dist/modes/interactive/bug-report.js.map +1 -0
- package/dist/modes/interactive/chat-viewport.d.ts.map +1 -1
- package/dist/modes/interactive/chat-viewport.js +1 -1
- package/dist/modes/interactive/chat-viewport.js.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.js +12 -5
- package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.js +12 -5
- package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts +3 -3
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/extension-input.d.ts +2 -0
- package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-input.js +6 -0
- package/dist/modes/interactive/components/extension-input.js.map +1 -1
- package/dist/modes/interactive/components/extension-selector.d.ts +1 -0
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-selector.js +4 -0
- package/dist/modes/interactive/components/extension-selector.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +4 -1
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts +5 -5
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +74 -48
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +3 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +11 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.js +11 -4
- package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
- package/dist/modes/interactive/components/status-indicator.d.ts +2 -2
- package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
- package/dist/modes/interactive/components/status-indicator.js +7 -7
- package/dist/modes/interactive/components/status-indicator.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +18 -9
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +2 -0
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +13 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +220 -84
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/session-share.d.ts +2 -0
- package/dist/modes/interactive/session-share.d.ts.map +1 -1
- package/dist/modes/interactive/session-share.js +8 -4
- package/dist/modes/interactive/session-share.js.map +1 -1
- package/dist/modes/interactive/tui-renderer.d.ts.map +1 -1
- package/dist/modes/interactive/tui-renderer.js +2 -2
- package/dist/modes/interactive/tui-renderer.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +2 -2
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/utils/clipboard-command.d.ts +7 -0
- package/dist/utils/clipboard-command.d.ts.map +1 -0
- package/dist/utils/clipboard-command.js +45 -0
- package/dist/utils/clipboard-command.js.map +1 -0
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js +52 -69
- package/dist/utils/clipboard-image.js.map +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +61 -125
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js +11 -4
- package/dist/utils/version-check.js.map +1 -1
- package/dist/utils/zip.d.ts +7 -0
- package/dist/utils/zip.d.ts.map +1 -0
- package/dist/utils/zip.js +60 -0
- package/dist/utils/zip.js.map +1 -0
- package/docs/compaction.md +39 -13
- package/docs/custom-provider.md +22 -13
- package/docs/development.md +4 -4
- package/docs/docs.json +4 -0
- package/docs/environment-variables.md +1 -0
- package/docs/extensions.md +57 -43
- package/docs/json.md +4 -4
- package/docs/models.md +33 -2
- package/docs/providers.md +2 -2
- package/docs/sdk.md +4 -2
- package/docs/security.md +1 -1
- package/docs/session-format.md +82 -40
- package/docs/sessions.md +27 -0
- package/docs/settings.md +60 -1
- package/docs/termux.md +0 -1
- package/docs/tui.md +2 -2
- package/docs/usage.md +1 -0
- package/examples/extensions/README.md +0 -1
- package/examples/extensions/custom-provider-anthropic/index.ts +18 -12
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +2 -2
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/prompt-customizer.ts +19 -67
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +435 -762
- package/package.json +17 -23
- package/dist/bundle/chunks/anthropic-messages-VWZZOSJQ.js +0 -6
- package/dist/bundle/chunks/azure-openai-responses-BJLAM6CD.js +0 -2
- package/dist/bundle/chunks/chunk-AXIIZGTV.js +0 -2
- package/dist/bundle/chunks/chunk-CLNPYIDP.js +0 -42
- package/dist/bundle/chunks/chunk-GMWCTUPB.js +0 -2
- package/dist/bundle/chunks/chunk-JJ2YFCJF.js +0 -1547
- package/dist/bundle/chunks/chunk-OUXLLA64.js +0 -11
- package/dist/bundle/chunks/chunk-U6ZMQKGD.js +0 -50
- package/dist/bundle/chunks/chunk-UAQELI3K.js +0 -2
- package/dist/bundle/chunks/google-generative-ai-Q2K7FBDI.js +0 -2
- package/dist/bundle/chunks/google-vertex-7UJBF4S7.js +0 -2
- package/dist/bundle/chunks/mistral-conversations-4M6BZBX6.js +0 -5
- package/dist/bundle/chunks/openai-codex-responses-R6VYZTVY.js +0 -10
- package/dist/bundle/chunks/openai-completions-EKZT2IH2.js +0 -7
- package/dist/bundle/chunks/openai-responses-TFDINO6W.js +0 -2
- package/dist/utils/clipboard-native.d.ts +0 -11
- package/dist/utils/clipboard-native.d.ts.map +0 -1
- package/dist/utils/clipboard-native.js +0 -20
- package/dist/utils/clipboard-native.js.map +0 -1
- package/examples/extensions/kimi-deferred-tools.ts +0 -61
package/docs/compaction.md
CHANGED
|
@@ -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
|
|
6
|
-
- [`packages/coding-agent/src/core/compaction/compaction.ts`](https://github.com/earendil-works/pi
|
|
7
|
-
- [`packages/coding-agent/src/core/compaction/branch-summarization.ts`](https://github.com/earendil-works/pi
|
|
8
|
-
- [`packages/coding-agent/src/core/compaction/utils.ts`](https://github.com/earendil-works/pi
|
|
9
|
-
- [`packages/coding-agent/src/core/session-manager.ts`](https://github.com/earendil-works/pi
|
|
10
|
-
- [`packages/coding-agent/src/core/extensions/types.ts`](https://github.com/earendil-works/pi
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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 -
|
|
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.
|
package/docs/custom-provider.md
CHANGED
|
@@ -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
|
|
401
|
-
- [mistral-conversations.ts](https://github.com/earendil-works/pi
|
|
402
|
-
- [openai-completions.ts](https://github.com/earendil-works/pi
|
|
403
|
-
- [openai-responses.ts](https://github.com/earendil-works/pi
|
|
404
|
-
- [google-generative-ai.ts](https://github.com/earendil-works/pi
|
|
405
|
-
- [bedrock-converse-stream.ts](https://github.com/earendil-works/pi
|
|
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:
|
|
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
|
|
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
|
|
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:
|
|
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
|
|
package/docs/development.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# Development
|
|
2
2
|
|
|
3
|
-
See [AGENTS.md](https://github.com/earendil-works/pi
|
|
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
|
|
9
|
-
cd pi
|
|
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
|
|
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
|
@@ -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` |
|
package/docs/extensions.md
CHANGED
|
@@ -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 -
|
|
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
|
-
// .
|
|
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.
|
|
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,
|
|
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
|
|
2105
|
-
- [bash.ts](https://github.com/earendil-works/pi
|
|
2106
|
-
- [powershell.ts](https://github.com/earendil-works/pi
|
|
2107
|
-
- [edit.ts](https://github.com/earendil-works/pi
|
|
2108
|
-
- [write.ts](https://github.com/earendil-works/pi
|
|
2109
|
-
- [grep.ts](https://github.com/earendil-works/pi
|
|
2110
|
-
- [find.ts](https://github.com/earendil-works/pi
|
|
2111
|
-
- [ls.ts](https://github.com/earendil-works/pi
|
|
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
|
|
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
|
|
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(
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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)
|
package/docs/models.md
CHANGED
|
@@ -9,6 +9,7 @@ Add custom providers and models (Ollama, vLLM, LM Studio, proxies) via `~/.pi/ag
|
|
|
9
9
|
- [Supported APIs](#supported-apis)
|
|
10
10
|
- [Provider Configuration](#provider-configuration)
|
|
11
11
|
- [Model Configuration](#model-configuration)
|
|
12
|
+
- [Prompt Cache Lifetimes](#prompt-cache-lifetimes)
|
|
12
13
|
- [Overriding Built-in Providers](#overriding-built-in-providers)
|
|
13
14
|
- [Per-model Overrides](#per-model-overrides)
|
|
14
15
|
- [Anthropic Messages Compatibility](#anthropic-messages-compatibility)
|
|
@@ -208,6 +209,7 @@ If your command is slow, expensive, rate-limited, or should keep using a previou
|
|
|
208
209
|
| `maxTokens` | No | `16384` | Maximum output tokens |
|
|
209
210
|
| `samplingParams` | No | omitted | Sampling parameters merged verbatim into every request body (see below) |
|
|
210
211
|
| `cost` | No | all zeros | Per-million-token rates with optional request-wide input pricing tiers |
|
|
212
|
+
| `promptCache` | No | omitted | Best-effort prompt cache lifetime in seconds per retention tier (see below) |
|
|
211
213
|
| `compat` | No | provider `compat` | Provider compatibility overrides. Merged with provider-level `compat` when both are set. |
|
|
212
214
|
|
|
213
215
|
A cost tier supplies a complete alternate rate set and applies to the full request when total input usage (`input + cacheRead + cacheWrite`) exceeds `inputTokensAbove`. When multiple tiers match, the highest threshold wins.
|
|
@@ -236,6 +238,19 @@ Current behavior:
|
|
|
236
238
|
- `/model`, `--list-models`, and the interactive footer display entries by model `id`.
|
|
237
239
|
- The configured `name` is used for model matching and secondary model detail text. It does not replace the footer/status-bar model id.
|
|
238
240
|
|
|
241
|
+
### Prompt Cache Lifetimes
|
|
242
|
+
|
|
243
|
+
`promptCache` states how long the provider keeps a prompt cache entry alive for each retention tier pi can request (`short` is the default tier; `long` is used when `PI_CACHE_RETENTION=long`). Values are seconds and are estimates: providers publish ranges, so pick the conservative end.
|
|
244
|
+
|
|
245
|
+
```json
|
|
246
|
+
{
|
|
247
|
+
"id": "claude-sonnet-5",
|
|
248
|
+
"promptCache": { "short": 300, "long": 3600 }
|
|
249
|
+
}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
The built-in catalog fills this in for direct Anthropic (5 min / 1 h). Other providers, including direct OpenAI, have no built-in lifetime until their cache-expiry and replay behavior has been validated for warming. A model without a value for the tier a request used is never warmed; custom models and provider overrides can opt in when the backing cache behavior is known. See [Cache Warming](settings.md#cache-warming).
|
|
253
|
+
|
|
239
254
|
### Sampling Parameters
|
|
240
255
|
|
|
241
256
|
`samplingParams` is a free-form object merged verbatim into every request body for the model, after the fields pi sets itself, so its keys win. Use it to send sampling parameters pi does not model — including server-specific ones like llama.cpp's `min_p` or vLLM's `top_k`:
|
|
@@ -359,7 +374,23 @@ Use `modelOverrides` to customize built-in models and matching extension-registe
|
|
|
359
374
|
}
|
|
360
375
|
```
|
|
361
376
|
|
|
362
|
-
`modelOverrides` supports these fields per model: `name`, `reasoning`, `thinkingLevelMap`, `input`, `cost` (partial), `contextWindow`, `maxTokens`, `samplingParams` (merged per key), `headers`, `compat`.
|
|
377
|
+
`modelOverrides` supports these fields per model: `name`, `reasoning`, `thinkingLevelMap`, `input`, `cost` (partial), `promptCache` (merged per tier), `contextWindow`, `maxTokens`, `samplingParams` (merged per key), `headers`, `compat`.
|
|
378
|
+
|
|
379
|
+
Use a `promptCache` override to enable cache warming through a proxy whose backing cache you know, for example OpenRouter routed to Anthropic:
|
|
380
|
+
|
|
381
|
+
```json
|
|
382
|
+
{
|
|
383
|
+
"providers": {
|
|
384
|
+
"openrouter": {
|
|
385
|
+
"modelOverrides": {
|
|
386
|
+
"anthropic/claude-sonnet-4": {
|
|
387
|
+
"promptCache": { "short": 300 }
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
```
|
|
363
394
|
|
|
364
395
|
Direct OpenAI GPT-5.6 Sol, Terra, and Luna default to a `272000` context window so requests remain within OpenAI's short-context pricing tier. To opt into OpenAI's 1.05M context window, increase it for each model you use:
|
|
365
396
|
|
|
@@ -435,6 +466,7 @@ Built-in Anthropic models enable `supportsStrictTools` in their model metadata.
|
|
|
435
466
|
| `supportsMidConvoEffort` | Whether the exact Claude model transport supports per-turn effort system messages and thinking binding controls. Pi persists native effort levels and always sends `drop_block` when enabled. Default: `false`. |
|
|
436
467
|
| `allowEmptySignature` | Whether to replay empty thinking signatures as `signature: ""` instead of converting thinking to text. Default: `false`. |
|
|
437
468
|
| `supportsStrictTools` | Whether the provider accepts strict JSON-schema tool definitions. Default: `false`; built-in Anthropic models enable it in generated metadata. |
|
|
469
|
+
| `allowedFallbackModels` | Up to three server-side fallback models, each with `provider`, `model`, and complete `cost` metadata. An empty array disables fallback. |
|
|
438
470
|
|
|
439
471
|
## OpenAI Compatibility
|
|
440
472
|
|
|
@@ -481,7 +513,6 @@ For providers with partial OpenAI compatibility, use the `compat` field.
|
|
|
481
513
|
| `sessionAffinityFormat` | For `openai-completions` and `openai-responses`, the session-affinity header format: `openai` sends `session_id`/`x-client-request-id` (completions also `x-session-affinity`), `openai-nosession` omits the underscore-containing `session_id` header, `openrouter` sends `x-session-id`. Does not affect the `prompt_cache_key` body param. Default: auto-detected. |
|
|
482
514
|
| `supportsStrictMode` | Whether the provider accepts strict JSON-schema function tool definitions. Defaults depend on the API; built-in OpenAI models carry explicit capability metadata. |
|
|
483
515
|
| `supportsOpenAIGrammarTools` | Whether OpenAI-compatible APIs emit custom Lark/regex grammar tools. When `false`, grammar-constrained tools fall back to normal function tools. Default: `false`; the built-in model catalog enables it for GPT-5+ models on OpenAI, OpenAI Codex, Azure OpenAI, GitHub Copilot, opencode, and Cloudflare AI Gateway. |
|
|
484
|
-
| `deferredToolsMode` | Use provider-specific deferred tool serialization. Currently only `"kimi"` is supported for Kimi's OpenAI-compatible Chat Completions format. |
|
|
485
516
|
| `supportsLongCacheRetention` | Whether the provider accepts long cache retention when cache retention is `long`: `prompt_cache_options.ttl: "30m"` for GPT-5.6+ Responses models, `prompt_cache_retention: "24h"` for earlier OpenAI models, or `cache_control.ttl: "1h"` when `cacheControlFormat` is `anthropic`. Default: `true`. |
|
|
486
517
|
| `openRouterRouting` | OpenRouter provider routing preferences. This object is sent as-is in the `provider` field of the [OpenRouter API request](https://openrouter.ai/docs/guides/routing/provider-selection). |
|
|
487
518
|
| `vercelGatewayRouting` | Vercel AI Gateway routing config for provider selection (`only`, `order`) |
|
package/docs/providers.md
CHANGED
|
@@ -53,7 +53,7 @@ Anthropic subscription auth is active for Claude Pro/Max accounts. Third-party h
|
|
|
53
53
|
|
|
54
54
|
### Radius
|
|
55
55
|
|
|
56
|
-
Radius is a
|
|
56
|
+
Radius is a `pi-messages` gateway. Pi ships the public Radius model catalog for immediate and offline model lookup, then overlays it with the effective gateway catalog after authentication. `/login radius` stores OAuth tokens in `auth.json`; refreshed catalogs are cached in `models-store.json`. Custom Radius gateways can be declared in `models.json` with `"oauth": "radius"` and a gateway `baseUrl`; they do not inherit the public `radius.pi.dev` catalog.
|
|
57
57
|
|
|
58
58
|
## API Keys
|
|
59
59
|
|
|
@@ -104,7 +104,7 @@ pi
|
|
|
104
104
|
| Xiaomi MiMo Token Plan (Amsterdam) | `XIAOMI_TOKEN_PLAN_AMS_API_KEY` | `xiaomi-token-plan-ams` |
|
|
105
105
|
| Xiaomi MiMo Token Plan (Singapore) | `XIAOMI_TOKEN_PLAN_SGP_API_KEY` | `xiaomi-token-plan-sgp` |
|
|
106
106
|
|
|
107
|
-
Reference for environment variables and `auth.json` keys: [`const envMap`](https://github.com/earendil-works/pi
|
|
107
|
+
Reference for environment variables and `auth.json` keys: [`const envMap`](https://github.com/earendil-works/pi/blob/main/packages/ai/src/env-api-keys.ts) in [`packages/ai/src/env-api-keys.ts`](https://github.com/earendil-works/pi/blob/main/packages/ai/src/env-api-keys.ts).
|
|
108
108
|
|
|
109
109
|
#### Auth File
|
|
110
110
|
|
package/docs/sdk.md
CHANGED
|
@@ -111,6 +111,8 @@ interface AgentSession {
|
|
|
111
111
|
}
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
+
`session.navigateTree()` rejects while an agent response, manual or automatic compaction, or another tree navigation is active, even with `summarize: false`. It does not queue navigation or return `{ cancelled: true }` for these conflicts. Wait for the active operation to finish (for example, with `await session.waitForIdle()`) and retry. Rejection leaves the active branch unchanged.
|
|
115
|
+
|
|
114
116
|
Session replacement APIs such as new-session, resume, fork, and import live on `AgentSessionRuntime`, not on `AgentSession`.
|
|
115
117
|
|
|
116
118
|
### createAgentSessionRuntime() and AgentSessionRuntime
|
|
@@ -244,8 +246,8 @@ const state = session.agent.state;
|
|
|
244
246
|
// state.messages: AgentMessage[] - conversation history
|
|
245
247
|
// state.model: Model - current model
|
|
246
248
|
// state.thinkingLevel: ThinkingLevel - current thinking level
|
|
247
|
-
// state.systemPrompt: string - system
|
|
248
|
-
// state.tools: AgentTool[] -
|
|
249
|
+
// state.systemPrompt: string - read-only, replayed from the transcript's system messages
|
|
250
|
+
// state.tools: AgentTool[] - executable tools; changes are declared to the model before the next request
|
|
249
251
|
// state.streamingMessage?: AgentMessage - current partial assistant message
|
|
250
252
|
// state.errorMessage?: string - latest assistant error
|
|
251
253
|
|
package/docs/security.md
CHANGED
|
@@ -54,6 +54,6 @@ If you bind-mount a host workspace read/write, writes from inside the container
|
|
|
54
54
|
|
|
55
55
|
## Reporting Security Issues
|
|
56
56
|
|
|
57
|
-
To report a security issue, follow the repository [Security Policy](https://github.com/earendil-works/pi
|
|
57
|
+
To report a security issue, follow the repository [Security Policy](https://github.com/earendil-works/pi/blob/main/SECURITY.md). Do not open a public issue for security-sensitive reports.
|
|
58
58
|
|
|
59
59
|
Expected local-agent behavior, lack of a built-in sandbox, prompt injection from untrusted content, and behavior of user-installed extensions or skills are generally outside the security boundary unless the report demonstrates a real privilege-boundary bypass or shows how pi grants access that the local user did not already have.
|