@earendil-works/pi-coding-agent 0.86.1 → 0.87.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/README.md +25 -675
  3. package/dist/bundle/chunks/{anthropic-messages-MYU5ZMRF.js → anthropic-messages-J5WXPPPC.js} +1 -1
  4. package/dist/bundle/chunks/chunk-65HAU2C5.js +2 -0
  5. package/dist/bundle/chunks/{chunk-CMRUVXTE.js → chunk-OJP47DM6.js} +48 -42
  6. package/dist/bundle/chunks/github-copilot.js +1 -1
  7. package/dist/bundle/chunks/{openai-completions-CYGM3XXP.js → openai-completions-OBX42CLD.js} +2 -2
  8. package/dist/bundle/chunks/{virtual-modules-MGTKWDID.js → virtual-modules-VHMJYYWQ.js} +1 -1
  9. package/dist/bundle/cli-runtime.js +1 -1
  10. package/dist/bundle/index.js +1 -1
  11. package/dist/bundle/rpc-entry.js +1 -1
  12. package/dist/cli/args.d.ts.map +1 -1
  13. package/dist/cli/args.js +14 -4
  14. package/dist/cli/args.js.map +1 -1
  15. package/dist/cli/file-processor.d.ts +1 -1
  16. package/dist/cli/file-processor.d.ts.map +1 -1
  17. package/dist/cli/file-processor.js.map +1 -1
  18. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  19. package/dist/core/agent-session-runtime.js +1 -1
  20. package/dist/core/agent-session-runtime.js.map +1 -1
  21. package/dist/core/agent-session.d.ts +27 -3
  22. package/dist/core/agent-session.d.ts.map +1 -1
  23. package/dist/core/agent-session.js +389 -119
  24. package/dist/core/agent-session.js.map +1 -1
  25. package/dist/core/cache-warmer.d.ts +1 -0
  26. package/dist/core/cache-warmer.d.ts.map +1 -1
  27. package/dist/core/cache-warmer.js +15 -1
  28. package/dist/core/cache-warmer.js.map +1 -1
  29. package/dist/core/compaction/compaction.d.ts +3 -1
  30. package/dist/core/compaction/compaction.d.ts.map +1 -1
  31. package/dist/core/compaction/compaction.js +155 -57
  32. package/dist/core/compaction/compaction.js.map +1 -1
  33. package/dist/core/crash-log.d.ts +5 -0
  34. package/dist/core/crash-log.d.ts.map +1 -1
  35. package/dist/core/crash-log.js +68 -0
  36. package/dist/core/crash-log.js.map +1 -1
  37. package/dist/core/export-html/template.js +6 -1
  38. package/dist/core/extensions/index.d.ts +1 -1
  39. package/dist/core/extensions/index.d.ts.map +1 -1
  40. package/dist/core/extensions/index.js.map +1 -1
  41. package/dist/core/extensions/runner.d.ts +16 -3
  42. package/dist/core/extensions/runner.d.ts.map +1 -1
  43. package/dist/core/extensions/runner.js +110 -5
  44. package/dist/core/extensions/runner.js.map +1 -1
  45. package/dist/core/extensions/types.d.ts +77 -6
  46. package/dist/core/extensions/types.d.ts.map +1 -1
  47. package/dist/core/extensions/types.js.map +1 -1
  48. package/dist/core/index.d.ts +1 -1
  49. package/dist/core/index.d.ts.map +1 -1
  50. package/dist/core/index.js.map +1 -1
  51. package/dist/core/model-config.d.ts +52 -0
  52. package/dist/core/model-config.d.ts.map +1 -1
  53. package/dist/core/model-config.js +16 -0
  54. package/dist/core/model-config.js.map +1 -1
  55. package/dist/core/model-resolver.d.ts.map +1 -1
  56. package/dist/core/model-resolver.js +1 -1
  57. package/dist/core/model-resolver.js.map +1 -1
  58. package/dist/core/prompt-templates.d.ts +6 -1
  59. package/dist/core/prompt-templates.d.ts.map +1 -1
  60. package/dist/core/prompt-templates.js +61 -35
  61. package/dist/core/prompt-templates.js.map +1 -1
  62. package/dist/core/provider-composer.d.ts +1 -0
  63. package/dist/core/provider-composer.d.ts.map +1 -1
  64. package/dist/core/provider-composer.js +19 -0
  65. package/dist/core/provider-composer.js.map +1 -1
  66. package/dist/core/resource-loader.d.ts.map +1 -1
  67. package/dist/core/resource-loader.js +6 -2
  68. package/dist/core/resource-loader.js.map +1 -1
  69. package/dist/core/sdk.d.ts.map +1 -1
  70. package/dist/core/sdk.js +3 -4
  71. package/dist/core/sdk.js.map +1 -1
  72. package/dist/core/session-manager.d.ts +36 -9
  73. package/dist/core/session-manager.d.ts.map +1 -1
  74. package/dist/core/session-manager.js +97 -7
  75. package/dist/core/session-manager.js.map +1 -1
  76. package/dist/core/tools/read.d.ts +4 -1
  77. package/dist/core/tools/read.d.ts.map +1 -1
  78. package/dist/core/tools/read.js +5 -1
  79. package/dist/core/tools/read.js.map +1 -1
  80. package/dist/index.d.ts +2 -2
  81. package/dist/index.d.ts.map +1 -1
  82. package/dist/index.js +1 -1
  83. package/dist/index.js.map +1 -1
  84. package/dist/main.d.ts.map +1 -1
  85. package/dist/main.js +4 -3
  86. package/dist/main.js.map +1 -1
  87. package/dist/modes/interactive/bug-report.d.ts.map +1 -1
  88. package/dist/modes/interactive/bug-report.js +4 -0
  89. package/dist/modes/interactive/bug-report.js.map +1 -1
  90. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  91. package/dist/modes/interactive/components/tree-selector.js +7 -0
  92. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  93. package/dist/modes/interactive/interactive-mode.d.ts +3 -0
  94. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  95. package/dist/modes/interactive/interactive-mode.js +64 -2
  96. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  97. package/dist/utils/mime.d.ts.map +1 -1
  98. package/dist/utils/mime.js +1 -1
  99. package/dist/utils/mime.js.map +1 -1
  100. package/dist/utils/tool-result-images.d.ts +3 -1
  101. package/dist/utils/tool-result-images.d.ts.map +1 -1
  102. package/dist/utils/tool-result-images.js +4 -1
  103. package/dist/utils/tool-result-images.js.map +1 -1
  104. package/docs/cli-integration.md +106 -0
  105. package/docs/cli.md +268 -0
  106. package/docs/compaction.md +45 -26
  107. package/docs/configuration.md +45 -0
  108. package/docs/containerization.md +109 -82
  109. package/docs/custom-provider.md +132 -784
  110. package/docs/docs.json +139 -99
  111. package/docs/environment-variables.md +3 -5
  112. package/docs/extensions.md +134 -2956
  113. package/docs/how-pi-works.md +49 -0
  114. package/docs/images/interactive-mode.png +0 -0
  115. package/docs/index.md +24 -69
  116. package/docs/json.md +193 -65
  117. package/docs/keybindings.md +57 -102
  118. package/docs/llama-cpp.md +3 -3
  119. package/docs/message-types.md +261 -0
  120. package/docs/models.md +64 -546
  121. package/docs/packages.md +66 -167
  122. package/docs/prompt-templates.md +31 -68
  123. package/docs/providers.md +102 -240
  124. package/docs/quickstart.md +61 -106
  125. package/docs/rpc-commands.md +854 -0
  126. package/docs/rpc-extension-ui.md +200 -0
  127. package/docs/rpc.md +129 -1556
  128. package/docs/sdk.md +76 -1160
  129. package/docs/security.md +70 -32
  130. package/docs/session-format.md +25 -216
  131. package/docs/sessions.md +35 -141
  132. package/docs/settings.md +109 -387
  133. package/docs/shell-aliases.md +85 -5
  134. package/docs/skills.md +51 -190
  135. package/docs/slash-commands.md +60 -0
  136. package/docs/terminal-setup.md +105 -78
  137. package/docs/termux.md +74 -83
  138. package/docs/themes.md +68 -280
  139. package/docs/tmux.md +31 -39
  140. package/docs/tui.md +69 -923
  141. package/docs/usage.md +54 -272
  142. package/docs/windows.md +43 -17
  143. package/examples/README.md +13 -2
  144. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  145. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  146. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  147. package/examples/extensions/gondolin/package-lock.json +2 -2
  148. package/examples/extensions/gondolin/package.json +1 -1
  149. package/examples/extensions/sandbox/package-lock.json +2 -2
  150. package/examples/extensions/sandbox/package.json +1 -1
  151. package/examples/extensions/with-deps/package-lock.json +2 -2
  152. package/examples/extensions/with-deps/package.json +1 -1
  153. package/examples/plugins/pi-example-plugin/src/session.ts +3 -2
  154. package/examples/rpc-client.ts +35 -0
  155. package/examples/rpc-extension-ui.ts +25 -5
  156. package/examples/sdk/README.md +1 -1
  157. package/npm-shrinkwrap.json +20 -20
  158. package/package.json +8 -8
  159. package/dist/bundle/chunks/chunk-HTEQD2HM.js +0 -2
  160. package/docs/development.md +0 -90
@@ -1,6 +1,6 @@
1
- # Compaction & Branch Summarization
1
+ # Compaction Reference
2
2
 
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.
3
+ This reference describes automatic compaction, branch summarization, persisted entries, and extension hooks. For the user workflow, see [Sessions and Context](sessions.md#manage-conversation-context).
4
4
 
5
5
  **Source files** ([pi](https://github.com/earendil-works/pi)):
6
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
@@ -20,7 +20,7 @@ Pi has two summarization mechanisms:
20
20
  | Compaction | Context exceeds threshold, or `/compact` | Summarize old messages to free up context |
21
21
  | Branch summarization | `/tree` navigation | Preserve context when switching branches |
22
22
 
23
- Both use the same structured summary format and track file operations cumulatively. Compaction and branch-summary requests use fresh routing session IDs and, where supported by the provider, disable prompt-cache writes because these one-off prompts are unlikely to be reused.
23
+ Both use closely related structured formats and track file operations cumulatively. Summarization requests disable prompt-cache writes because these one-off prompts are unlikely to be reused.
24
24
 
25
25
  ## Compaction
26
26
 
@@ -34,14 +34,16 @@ contextTokens > contextWindow - reserveTokens
34
34
 
35
35
  By default, `reserveTokens` is 16384 tokens (configurable in `~/.pi/agent/settings.json` or `<project-dir>/.pi/settings.json`). This leaves room for the LLM's response.
36
36
 
37
- During a multi-turn agent run, Pi checks this threshold after tools finish and their results are appended, before starting the next assistant response. If the threshold is crossed, Pi compacts inside the same agent run and resumes with the summary and retained messages. It skips this between-turn check when the completed tool batch terminates the run and no queued message requires another response. Pi also checks the threshold before a new user prompt and after a low-level agent run ends.
37
+ During a multi-turn agent run, Pi checks the canonical projected context after tools finish and their results are appended, before starting the next assistant response. If the threshold is crossed, Pi compacts during `prepareNextTurn`, then performs the existing catch-up steering poll before `turn_start`. It skips this between-turn check when the completed tool batch terminates the run and no queued message requires another response. Pi also checks before a new user prompt and performs final-attempt overflow recovery after the low-level run ends.
38
+
39
+ A provider context-overflow error or an early final `stopReason: "length"` can select one compact-and-retry recovery attempt. Length responses with tool calls retain their synthetic failed tool results and follow the ordinary tool/queue scheduler rather than forcing the run to end.
38
40
 
39
41
  You can also trigger manually with `/compact [instructions]`, where optional instructions focus the summary.
40
42
 
41
43
  ### How It Works
42
44
 
43
- 1. **Find cut point**: Walk backwards from newest message, accumulating token estimates until `keepRecentTokens` (default 20k, configurable in `~/.pi/agent/settings.json` or `<project-dir>/.pi/settings.json`) is reached
44
- 2. **Extract messages**: Collect messages from the previous kept boundary (or session start) up to the cut point
45
+ 1. **Find cut point**: Walk backwards through the finalized session projection, accumulating token estimates until `keepRecentTokens` (default 20k, configurable in `~/.pi/agent/settings.json` or `<project-dir>/.pi/settings.json`) is reached
46
+ 2. **Extract messages**: Collect projected messages from the previous kept boundary (or session start) up to the cut point
45
47
  3. **Generate summary**: Call LLM to summarize with structured format, passing the previous summary as iterative context when present
46
48
  4. **Append entry**: Save `CompactionEntry` with summary and `firstKeptEntryId`
47
49
  5. **Rebuilds context**: Session rebuilds the context for the next request, using summary + messages from `firstKeptEntryId` onwards
@@ -78,16 +80,31 @@ What the LLM sees:
78
80
  prompt from cmp messages from firstKeptEntryId
79
81
  ```
80
82
 
81
- On repeated compactions, the summarized span starts at the previous compaction's kept boundary (`firstKeptEntryId`), not at the compaction entry itself, falling back to the entry after the previous compaction if that kept entry cannot be found in the path. This preserves messages that survived the earlier compaction by including them in the next summarization pass as well. Pi also recalculates `tokensBefore` from the rebuilt session context before writing the new `CompactionEntry`, so the token count reflects the actual pre-compaction context being replaced.
83
+ On repeated compactions, the summarized span starts at the previous compaction's kept boundary (`firstKeptEntryId`), not at the compaction entry itself, falling back to the entry after the previous compaction if that kept entry cannot be found in the path. A retain-none compaction records its own ID as `firstKeptEntryId`; repeated compaction starts after that entry. This preserves messages that survived the earlier compaction by including them in the next summarization pass as well. Pi also recalculates `tokensBefore` from the rebuilt, context-edited session projection before writing the new `CompactionEntry`, so the token count reflects the actual pre-compaction context being replaced. Omitted raw entries remain stored but do not affect cut selection, summaries, checkpoints, or token estimates.
84
+
85
+ ### Overflow and Length Recovery Ordering
86
+
87
+ Recovery preserves the existing lifecycle and queue order. The completed attempt remains visible to `turn_end` and `agent_end`; post-run recovery then repairs persisted model context before a fresh retry:
88
+
89
+ ```text
90
+ persist final assistant response
91
+ → extension/public turn_end
92
+ → extension/public agent_end
93
+ → append context_edit omissions for the selected attempt
94
+ → for overflow/length: run session_before_compact and append compaction on success
95
+ → start the retry as a fresh run
96
+ ```
97
+
98
+ If recovery compaction fails or is cancelled, Pi keeps the omission edits, appends no compaction, and schedules no internal retry. Existing queued work remains governed by ordinary steering and follow-up rules. `agent_before_settle` sees the repaired projection after recovery processing. Raw transcript history, exports, billing totals, and history-search extensions can still inspect the omitted attempt.
82
99
 
83
- ### Split Turns
100
+ ### Split user-message spans
84
101
 
85
- A "turn" starts with a user message and includes all assistant responses and tool calls until the next user message. Normally, compaction cuts at turn boundaries.
102
+ A user-message span starts with a user message and includes all turns until the next user message. Normally, compaction cuts at user-message boundaries.
86
103
 
87
- When a single turn exceeds `keepRecentTokens`, the cut point lands mid-turn at an assistant message. This is a "split turn":
104
+ When one user-message span exceeds `keepRecentTokens`, the cut point lands within that span at an assistant message. This is a split user-message span:
88
105
 
89
106
  ```
90
- Split turn (one huge turn exceeds budget):
107
+ Split user-message span (one span exceeds budget):
91
108
 
92
109
  entry: 0 1 2 3 4 5 6 7 8
93
110
  ┌─────┬─────┬─────┬──────┬─────┬──────┬──────┬─────┬──────┐
@@ -100,13 +117,13 @@ Split turn (one huge turn exceeds budget):
100
117
  └── kept (7-8)
101
118
 
102
119
  isSplitTurn = true
103
- messagesToSummarize = [] (no complete turns before)
120
+ messagesToSummarize = [] (no earlier user-message spans)
104
121
  turnPrefixMessages = [usr, ass, tool, ass, tool, tool]
105
122
  ```
106
123
 
107
- For split turns, Pi generates two summaries and merges them:
124
+ For split user-message spans, Pi generates two summaries and merges them:
108
125
  1. **History summary**: Previous context (if any)
109
- 2. **Turn prefix summary**: The early part of the split turn
126
+ 2. **User-message-span prefix summary**: The early part of the split user-message span
110
127
 
111
128
  ### Cut Point Rules
112
129
 
@@ -118,6 +135,8 @@ Valid cut points are:
118
135
 
119
136
  Never cut at tool results (they must stay with their tool call).
120
137
 
138
+ Preparation advances the kept boundary into a context-invisible suffix only when that suffix contains an omitted assistant attempt and no unomitted context-producing entries. Recovery `context_edit` omissions satisfy this rule; intrinsically context-invisible metadata may coexist with them. Metadata alone and newly appended custom messages do not move the cut. A replacement edit affecting the candidate input or summarized prefix also blocks advancement because the omitted assistant answered the pre-edit input; replacements of suffix entries that are ultimately omitted remain safe. This allows an over-budget recovered input to be summarized while retaining the edits that keep the abandoned attempt omitted, without making bookkeeping change whether new model input is preserved verbatim.
139
+
121
140
  ### CompactionEntry Structure
122
141
 
123
142
  Defined in [`session-manager.ts`](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/src/core/session-manager.ts):
@@ -126,8 +145,8 @@ Defined in [`session-manager.ts`](https://github.com/earendil-works/pi/blob/main
126
145
  interface CompactionEntry<T = unknown> {
127
146
  type: "compaction";
128
147
  id: string;
129
- parentId: string;
130
- timestamp: number;
148
+ parentId: string | null;
149
+ timestamp: string;
131
150
  summary: string;
132
151
  firstKeptEntryId: string;
133
152
  tokensBefore: number;
@@ -180,11 +199,9 @@ After navigation with summary:
180
199
 
181
200
  ### Cumulative File Tracking
182
201
 
183
- Both compaction and branch summarization track files cumulatively. When generating a summary, pi extracts file operations from:
184
- - Tool calls in the messages being summarized
185
- - Previous compaction or branch summary `details` (if any)
202
+ Default compaction and branch summarization track files cumulatively. Both extract file operations from tool calls in the messages being summarized. Compaction also carries file lists from the previous Pi-generated compaction. Branch summarization carries file lists from Pi-generated branch summaries in the entries it summarizes.
186
203
 
187
- This means file tracking accumulates across multiple compactions or nested branch summaries, preserving the full history of read and modified files.
204
+ File tracking therefore accumulates across default compactions and nested default branch summaries. Pi does not automatically carry file lists from extension-generated summaries whose `fromHook` field is `true`; extensions manage their own `details` format.
188
205
 
189
206
  ### BranchSummaryEntry Structure
190
207
 
@@ -194,8 +211,8 @@ Defined in [`session-manager.ts`](https://github.com/earendil-works/pi/blob/main
194
211
  interface BranchSummaryEntry<T = unknown> {
195
212
  type: "branch_summary";
196
213
  id: string;
197
- parentId: string;
198
- timestamp: number;
214
+ parentId: string | null;
215
+ timestamp: string;
199
216
  summary: string;
200
217
  fromId: string; // Entry we navigated from
201
218
  usage?: Usage; // LLM usage that generated the summary
@@ -216,7 +233,9 @@ See [`collectEntriesForBranchSummary()`](https://github.com/earendil-works/pi/bl
216
233
 
217
234
  ## Summary Format
218
235
 
219
- Both compaction and branch summarization use the same structured format:
236
+ Both formats include Goal, Constraints & Preferences, Progress, Key Decisions, and Next Steps. Compaction summaries also include Critical Context. Branch summaries stop after Next Steps. Pi appends file lists to either format when relevant.
237
+
238
+ Compaction summaries use this format:
220
239
 
221
240
  ```markdown
222
241
  ## Goal
@@ -283,7 +302,7 @@ pi.on("session_before_compact", async (event, ctx) => {
283
302
  const { preparation, branchEntries, customInstructions, reason, willRetry, signal } = event;
284
303
 
285
304
  // preparation.messagesToSummarize - messages to summarize
286
- // preparation.turnPrefixMessages - split turn prefix (if isSplitTurn)
305
+ // preparation.turnPrefixMessages - user-message-span prefix (if isSplitTurn)
287
306
  // preparation.previousSummary - previous compaction summary
288
307
  // preparation.fileOps - extracted file operations
289
308
  // preparation.tokensBefore - context tokens before compaction
@@ -357,7 +376,7 @@ pi.on("session_compact_failed", async (event, ctx) => {
357
376
  const { reason, errorMessage, aborted, willRetry, fromExtension } = event;
358
377
  // reason - "manual" (/compact), "threshold", or "overflow"
359
378
  // errorMessage - present for non-abort failures
360
- // aborted - true for cancelled/aborted compactions
379
+ // aborted - true for canceled/aborted compactions
361
380
  // willRetry - whether the aborted turn would have retried after compaction
362
381
  // fromExtension - whether extension-provided compaction content was being used
363
382
  });
@@ -441,4 +460,4 @@ Keys are exact, case-sensitive `provider/modelId` values, including any slashes
441
460
 
442
461
  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
462
 
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.
463
+ 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](settings.md#per-model-compaction-overrides) for details.
@@ -0,0 +1,45 @@
1
+ # Configuration
2
+
3
+ Pi supports user-level and project configuration. User-level configuration lives in the agent directory, which defaults to `~/.pi/agent`. Project configuration lives in `.pi` under the working directory and loads after [project trust](security.md#understand-project-trust) is granted. The only exception is `sessionDir`, which Pi reads before resolving trust so it can locate sessions.
4
+
5
+ In interactive mode, use `/settings` to change common preferences. For other options, ask Pi to update the configuration or edit the relevant files directly. Run `/reload` after manually changing settings, keybindings, instructions, or resources.
6
+
7
+ ## Agent directory
8
+
9
+ The agent directory is shown as `<agent-dir>` below. Set its location with the `PI_CODING_AGENT_DIR` environment variable or the SDK's [`agentDir`](sdk.md) option.
10
+
11
+ | Path | Responsibility |
12
+ |---|---|
13
+ | `<agent-dir>/settings.json` | User-level [settings](settings.md), including preferences, defaults, resource paths, and Pi package declarations. |
14
+ | `<agent-dir>/keybindings.json` | Custom terminal UI and application [keybindings](keybindings.md). |
15
+ | `<agent-dir>/models.json` | [Compatible endpoints, models, and model overrides](models.md#configure-a-compatible-endpoint). |
16
+ | `<agent-dir>/auth.json` | Saved API keys and OAuth credentials. |
17
+ | `<agent-dir>/AGENTS.override.md`, `AGENTS.md`, `AGENTS.MD`, `CLAUDE.md`, or `CLAUDE.MD` | User instructions applied across working directories. |
18
+ | `<agent-dir>/SYSTEM.md` | Replaces Pi’s default system prompt. |
19
+ | `<agent-dir>/APPEND_SYSTEM.md` | Adds instructions to Pi’s system prompt. |
20
+ | `<agent-dir>/extensions/` | User [extensions](extensions.md). |
21
+ | `<agent-dir>/skills/` | User [skills](skills.md) and supporting files. |
22
+ | `<agent-dir>/prompts/` | User [prompt templates](prompt-templates.md) exposed as slash commands. |
23
+ | `<agent-dir>/themes/` | User [theme](themes.md) files. |
24
+
25
+ ## Project `.pi` directory
26
+
27
+ | Path | Responsibility |
28
+ |---|---|
29
+ | `.pi/settings.json` | Project-level [settings](settings.md), resource paths, and Pi package declarations. |
30
+ | `.pi/SYSTEM.md` | Replaces the system prompt for the project. |
31
+ | `.pi/APPEND_SYSTEM.md` | Adds project-specific instructions to the system prompt. |
32
+ | `.pi/extensions/` | Project extensions. |
33
+ | `.pi/skills/` | Project skills and supporting files. |
34
+ | `.pi/prompts/` | Project prompt templates exposed as slash commands. |
35
+ | `.pi/themes/` | Project theme files. |
36
+
37
+ For `SYSTEM.md` and `APPEND_SYSTEM.md`, the trusted project file takes precedence over the corresponding agent-directory file. Files with the same name are not combined.
38
+
39
+ ## Context files
40
+
41
+ Context files are separate from project `.pi` configuration. Pi loads them from the agent directory, the working directory, and its parent directories. A context file applies whenever Pi runs in its directory or anywhere below it.
42
+
43
+ An `AGENTS.override.md` replaces `AGENTS.md` or `CLAUDE.md` only in the same directory. It does not suppress context files from the agent directory or other directories.
44
+
45
+ Context-file discovery does not require project trust.
@@ -1,53 +1,39 @@
1
- # Containerization
1
+ # Run Pi in an isolated environment
2
2
 
3
- Pi runs with all permissions by default, but in some cases, you will want to have more control over what directories Pi can write to and which accesses it has.
3
+ Use an isolated environment to limit the files, credentials, processes, and network services that generated commands can access or affect.
4
4
 
5
- There are two general options. You can either
6
- 1. run the whole `pi` process inside an isolated environment, or
7
- 2. run `pi` on the host and route tool execution into an isolated environment.
5
+ You can isolate the complete Pi process or keep Pi on the host and route selected tools into an isolated environment.
8
6
 
9
- ## Choose a pattern
7
+ ## Choose an isolation method
10
8
 
11
- | Pattern | What is isolated | Best for | Notes |
12
- | --- | --- | --- | --- |
13
- | Gondolin extension | Built-in tools and `!` commands | Local micro-VM isolation while keeping auth on host | See [`examples/extensions/gondolin/`](../examples/extensions/gondolin/). |
14
- | Plain Docker | Whole `pi` process in a local container | Simple local isolation | Provider API keys enter the container. |
15
- | OpenShell | Whole `pi` process in a policy-controlled sandbox | Local or remote managed sandbox | Requires an OpenShell gateway |
16
- | Docker Sandboxes | Whole `pi` process in a managed sandbox | Local isolation with provider keys kept on the host | Requires Docker Sandboxes (`sbx`). |
9
+ | Method | Where Pi runs | What is isolated | Credential handling | Best for |
10
+ |---|---|---|---|---|
11
+ | Plain Docker | Container | Pi, built-in tools, `!` commands, and extensions | Credentials passed into the container | A straightforward local container boundary |
12
+ | Docker Sandboxes | Managed sandbox | Pi, built-in tools, `!` commands, and extensions | Provider credentials remain on the host and are substituted by the proxy | Managed local isolation without exposing the real provider key |
13
+ | OpenShell | Local or remote sandbox | Pi, built-in tools, `!` commands, and extensions | Policy-controlled credentials and inference routing | Filesystem, process, network, and credential policies |
14
+ | Gondolin extension | Host | Built-in tools and `!` commands | Stored Pi credentials remain on the host, but commands inherit host environment variables | A local micro-VM for tool execution while retaining the host interface |
17
15
 
18
- Extensions run wherever the `pi` process runs. If you run host `pi` with a tool-routing extension, other custom extension tools still run on the host unless they also delegate their operations.
16
+ The method changes where extensions run. When the complete Pi process runs inside an isolated environment, its extensions run there too. When host Pi delegates built-in tools through Gondolin, other extension tools still run on the host unless they also delegate their work.
19
17
 
20
- ## Gondolin
18
+ ## Decide what Pi can access
21
19
 
22
- [Gondolin](https://github.com/earendil-works/gondolin) is a local Linux micro-VM.
23
- Use the [example extension](../examples/extensions/gondolin) when you want `pi` on the host but all built-in tools routed into the VM.
20
+ An isolated process can still affect resources you expose to it:
24
21
 
25
- Setup:
22
+ - A read-write host mount lets Pi modify those host files.
23
+ - Mounting `~/.pi/agent` exposes your Pi credentials, settings, extensions, and sessions.
24
+ - Environment variables passed into a container are available to processes inside it.
25
+ - Network access may allow code or tool output to leave the environment.
26
+ - Tool-only isolation does not constrain the host Pi process or extension tools that do not use the isolated backend.
26
27
 
27
- ```bash
28
- cp -R packages/coding-agent/examples/extensions/gondolin ~/.pi/agent/extensions/gondolin
29
- cd ~/.pi/agent/extensions/gondolin
30
- npm install --ignore-scripts
31
- ```
32
-
33
- Run from the project you want mounted:
34
-
35
- ```bash
36
- cd /path/to/project
37
- pi -e ~/.pi/agent/extensions/gondolin
38
- ```
28
+ Expose only the working folder, credentials, and network destinations needed for the task. Use read-only mounts or copy files into and out of the environment when you do not want writes to affect the host.
39
29
 
40
- The extension mounts the host cwd at `/workspace` in the VM and overrides `read`, `write`, `edit`, `bash`, `grep`, `find`, and `ls`.
41
- User `!` commands are routed into the VM, as well.
42
- File changes under `/workspace` write through to the host.
30
+ ## Run Pi in plain Docker
43
31
 
44
- Requirements: Node.js >= 23.6.0 for `@earendil-works/gondolin`, plus QEMU (requires installation through your package manager).
32
+ Plain Docker provides the simplest whole-process container boundary.
45
33
 
46
- ## Plain Docker
34
+ ### Build the image
47
35
 
48
- Run the whole `pi` process in Docker when you want the simplest local container boundary.
49
-
50
- `Dockerfile.pi`:
36
+ Create `Dockerfile.pi`:
51
37
 
52
38
  ```dockerfile
53
39
  FROM node:24-bookworm-slim
@@ -61,11 +47,17 @@ WORKDIR /workspace
61
47
  ENTRYPOINT ["pi"]
62
48
  ```
63
49
 
64
- Build and run:
50
+ Build it from the directory containing the file:
65
51
 
66
52
  ```bash
67
53
  docker build -t pi-sandbox -f Dockerfile.pi .
54
+ ```
68
55
 
56
+ ### Start Pi
57
+
58
+ From the working folder you want Pi to access, run:
59
+
60
+ ```bash
69
61
  docker run --rm -it \
70
62
  -e ANTHROPIC_API_KEY \
71
63
  -v "$PWD:/workspace" \
@@ -73,84 +65,119 @@ docker run --rm -it \
73
65
  pi-sandbox
74
66
  ```
75
67
 
76
- The `-v "$PWD:/workspace"` mounts your current directory into the container at /workspace such that reads and writes in `/workspace` inside Docker directly affect your host files, like in the Gondolin example.
68
+ Replace `ANTHROPIC_API_KEY` with the credential required by your provider. The named `pi-agent-home` volume keeps container-local settings, credentials, and sessions between runs.
69
+
70
+ Do not mount the host's `~/.pi/agent` unless the container should have access to your host Pi configuration and credentials.
71
+
72
+ ### Verify the workspace
73
+
74
+ Inside Pi, run:
75
+
76
+ ```text
77
+ !pwd
78
+ ```
79
+
80
+ The command should report `/workspace`. Changes under `/workspace` write through to the mounted host folder. Remove the bind mount or use a read-only mount when that is not acceptable.
81
+
82
+ ## Run Pi with Docker Sandboxes
77
83
 
78
- Use a named volume for `/root/.pi/agent` if you want container-local settings and sessions. Mounting your host `~/.pi/agent` exposes host auth and session files to the container.
84
+ [Docker Sandboxes](https://docs.docker.com/ai/sandboxes/) runs the complete Pi process inside a managed sandbox. Its proxy can keep the real provider credential on the host and substitute it when requests leave the sandbox.
79
85
 
80
- ## OpenShell
86
+ Configure credentials before creating the sandbox. Do not run `/login` inside the sandbox because that writes a real credential into it.
81
87
 
82
- Use [NVIDIA OpenShell](https://docs.nvidia.com/openshell/about/overview) when you want a policy-controlled sandbox with filesystem, process, network, credential, and inference controls.
83
- OpenShell can run sandboxes through a local gateway backed by Docker, Podman, or a VM runtime, or through a remote Kubernetes gateway.
88
+ ### Use a Claude Pro or Max token
84
89
 
85
- Every sandbox requires an active gateway.
86
- Register and select one before creating a sandbox:
90
+ Generate the token with `claude setup-token` on a machine with Claude Code. If an `anthropic` secret is already configured, remove it first so the proxy does not add an API-key header alongside the bearer token:
87
91
 
88
92
  ```bash
89
- openshell gateway add <gateway-url> --name <name>
90
- openshell gateway select <name>
93
+ sbx secret rm anthropic
94
+
95
+ sbx secret set-custom \
96
+ --host api.anthropic.com \
97
+ --env ANTHROPIC_OAUTH_TOKEN \
98
+ --placeholder 'sk-ant-oat01-{rand}'
91
99
  ```
92
100
 
93
- Launch `pi` inside an OpenShell sandbox:
101
+ `sbx secret set-custom` reads the real token from standard input. The sandbox receives an OAuth-shaped placeholder, which the proxy replaces only for requests to the configured host.
102
+
103
+ For an Anthropic API key, use `sbx secret set anthropic` instead.
104
+
105
+ ### Start Pi
106
+
107
+ Run this from the working folder you want mounted:
94
108
 
95
109
  ```bash
96
- openshell sandbox create --name pi-sandbox --from pi -- pi
110
+ sbx run --kit "docker.io/sbx/pi-kit:latest" pi
97
111
  ```
98
112
 
99
- In this pattern, the whole `pi` process runs inside the sandbox.
100
- Built-in tools, `!` commands, and extension tools execute inside the OpenShell boundary.
101
-
102
- If the gateway is remote, project files are not bind-mounted from the host, meaning writes in the sandbox are not reflected on your machine.
103
- Clone the repository inside the sandbox or use OpenShell file transfer commands:
113
+ For an existing sandbox, run Pi non-interactively with:
104
114
 
105
115
  ```bash
106
- openshell sandbox upload pi-sandbox ./repo /workspace
107
- openshell sandbox download pi-sandbox /workspace/repo ./repo-out
116
+ sbx exec <sandbox-name> -- pi -p "list the failing tests"
108
117
  ```
109
118
 
110
- OpenShell providers can keep raw model API keys outside the sandbox.
111
- When inference routing is configured, code inside the sandbox can call `https://inference.local`, and the gateway injects the configured provider credentials upstream.
112
- Configure Pi to use the corresponding OpenAI-compatible or Anthropic-compatible endpoint if you want model traffic to use this route.
119
+ See the [Pi kit documentation](https://github.com/docker/sbx-kits-contrib/tree/main/pi) for other providers, troubleshooting, and image pinning.
113
120
 
114
- ## Docker Sandboxes
121
+ ## Run Pi with OpenShell
115
122
 
116
- [Docker Sandboxes](https://docs.docker.com/ai/sandboxes/) is a managed sandbox runtime from Docker that runs the whole `pi` process inside a sandbox.
117
- It is one of the container boundaries [No Built-in Sandbox](security.md#no-built-in-sandbox) points to.
123
+ [NVIDIA OpenShell](https://docs.nvidia.com/openshell/about/overview) provides local or remote sandboxes with filesystem, process, network, credential, and inference policies.
118
124
 
119
- Unlike the Plain Docker pattern above, the provider credential is not passed into the container.
120
- The sandbox receives a sentinel value instead, and the `sbx` proxy substitutes the real credential on egress to `api.anthropic.com`.
121
- Credentials are wired at creation time, so store yours on the host before you create the sandbox.
125
+ ### Select a gateway
122
126
 
123
- For a Claude Pro/Max subscription, run `claude setup-token` on a machine with Claude Code, then store the result on the host.
124
- If an `anthropic` secret is already bound, remove it first: otherwise the proxy adds an `x-api-key` header alongside the Bearer token and Anthropic rejects the request.
125
- `sbx secret set-custom` reads the token from stdin, so it stays out of shell history.
127
+ Every sandbox requires an active gateway:
126
128
 
127
129
  ```bash
128
- sbx secret rm anthropic
130
+ openshell gateway add <gateway-url> --name <name>
131
+ openshell gateway select <name>
132
+ ```
129
133
 
130
- sbx secret set-custom \
131
- --host api.anthropic.com \
132
- --env ANTHROPIC_OAUTH_TOKEN \
133
- --placeholder 'sk-ant-oat01-{rand}'
134
+ ### Create the sandbox
135
+
136
+ ```bash
137
+ openshell sandbox create --name pi-sandbox --from pi -- pi
134
138
  ```
135
139
 
136
- The sandbox gets an OAuth-shaped placeholder, not the real token, and the proxy swaps it on egress to that host; `ANTHROPIC_OAUTH_TOKEN` is a variable pi already reads and prefers over an API key, so no extra pi configuration is needed.
140
+ Pi, its built-in tools, `!` commands, and extension tools run inside the OpenShell boundary.
137
141
 
138
- For an API key, store it with `sbx secret set anthropic` instead. The kit wires it the same way, as a sentinel the proxy substitutes on egress.
142
+ ### Transfer files to a remote sandbox
139
143
 
140
- With the credential stored, launch `pi` from the project you want mounted:
144
+ A remote gateway does not bind-mount your host working folder. Clone the repository inside the sandbox or transfer files explicitly:
141
145
 
142
146
  ```bash
143
- sbx run --kit "docker.io/sbx/pi-kit:latest" pi
147
+ openshell sandbox upload pi-sandbox ./working-folder /workspace
148
+ openshell sandbox download pi-sandbox /workspace/working-folder ./working-folder-out
144
149
  ```
145
150
 
146
- The kit pre-bakes `pi` into its image, so the sandbox starts without installing anything, and the current directory is the sandbox workspace.
151
+ OpenShell inference routing can keep raw model credentials outside the sandbox. When configured, point Pi at the corresponding OpenAI-compatible or Anthropic-compatible endpoint exposed by the gateway.
152
+
153
+ ## Route tools through Gondolin
154
+
155
+ [Gondolin](https://github.com/earendil-works/gondolin) is a local Linux micro-VM. Its example extension keeps the Pi process and file-based provider credentials on the host while routing the built-in tools and user `!` commands into the VM.
156
+
157
+ Commands inside the VM inherit the host process environment. Provider keys supplied through environment variables can therefore be visible inside the VM. Do not use this pattern as a credential boundary unless you remove sensitive variables or change the extension's environment handling.
147
158
 
148
- Do not authenticate from inside the sandbox: `/login` there writes a real token into the container and defeats the proxy model.
159
+ Gondolin requires Node.js 23.6 or newer and QEMU installed through your operating-system package manager.
149
160
 
150
- Scripted use works the same way:
161
+ ### Install the extension
162
+
163
+ From a Pi source checkout:
151
164
 
152
165
  ```bash
153
- sbx exec <sandbox-name> -- pi -p "list the failing tests"
166
+ mkdir -p ~/.pi/agent/extensions
167
+ cp -R packages/coding-agent/examples/extensions/gondolin ~/.pi/agent/extensions/gondolin
168
+ cd ~/.pi/agent/extensions/gondolin
169
+ npm install --ignore-scripts
170
+ ```
171
+
172
+ ### Start Pi
173
+
174
+ Run Pi from the working folder you want mounted:
175
+
176
+ ```bash
177
+ cd /path/to/working-folder
178
+ pi -e ~/.pi/agent/extensions/gondolin
154
179
  ```
155
180
 
156
- See the [kit documentation](https://github.com/docker/sbx-kits-contrib/tree/main/pi) for the full credential matrix, troubleshooting, and pinning.
181
+ The extension mounts the host working folder at `/workspace` in the VM and overrides `read`, `write`, `edit`, `bash`, `grep`, `find`, and `ls`. File changes under `/workspace` write through to the host.
182
+
183
+ Other extension tools still run on the host unless they explicitly delegate their operations. Review the [Gondolin example](../examples/extensions/gondolin/) before adding tools that could bypass the VM boundary.