mu-agent 0.1.4 → 0.1.7

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 (119) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/README.md +7 -3
  3. package/dist/bundle/chunks/anthropic-messages-VMESUHQ7.js +6 -0
  4. package/dist/bundle/chunks/azure-openai-responses-K232MQFF.js +2 -0
  5. package/dist/bundle/chunks/bedrock-converse-stream.js +2 -2
  6. package/dist/bundle/chunks/{chunk-FUXEF6JQ.js → chunk-4O2SCVYF.js} +1 -1
  7. package/dist/bundle/chunks/chunk-AYFRR3OD.js +2 -0
  8. package/dist/bundle/chunks/chunk-FU4XQUSL.js +11 -0
  9. package/dist/bundle/chunks/{chunk-S7SZN6Z3.js → chunk-GNYZK6XN.js} +1 -1
  10. package/dist/bundle/chunks/{chunk-XOBBIK6P.js → chunk-HEMXN7VJ.js} +75 -67
  11. package/dist/bundle/chunks/chunk-MVPXOVOJ.js +2 -0
  12. package/dist/bundle/chunks/chunk-UTB4DTYQ.js +2 -0
  13. package/dist/bundle/chunks/{chunk-WIUZI2CJ.js → chunk-V7IXECST.js} +2 -2
  14. package/dist/bundle/chunks/cloudflare-workers-ai-system-one-NR2TDCXU.js +2 -0
  15. package/dist/bundle/chunks/github-copilot.js +1 -1
  16. package/dist/bundle/chunks/google-generative-ai-C44KRRZ4.js +2 -0
  17. package/dist/bundle/chunks/google-vertex-25DUXPTJ.js +2 -0
  18. package/dist/bundle/chunks/meta.js +2 -0
  19. package/dist/bundle/chunks/mistral-conversations-6IHQOR4R.js +5 -0
  20. package/dist/bundle/chunks/{openai-codex-responses-QDSOTBBO.js → openai-codex-responses-3UAYOSSR.js} +2 -2
  21. package/dist/bundle/chunks/{openai-completions-KQPOPEVM.js → openai-completions-FIEQGWAH.js} +3 -3
  22. package/dist/bundle/chunks/openai-responses-OZJXLHFC.js +2 -0
  23. package/dist/bundle/chunks/{openrouter-images-N4XVVFSD.js → openrouter-images-JVEJN44Q.js} +1 -1
  24. package/dist/bundle/chunks/{pi-messages-GFKBWJHZ.js → pi-messages-TM5SOOIW.js} +2 -2
  25. package/dist/bundle/chunks/typesafe-system-one-VKYX4OGY.js +2 -0
  26. package/dist/bundle/chunks/{virtual-modules-MYFARBUK.js → virtual-modules-V7SXVVLP.js} +1 -1
  27. package/dist/bundle/cli-runtime.js +3 -0
  28. package/dist/bundle/cli.js +4 -2
  29. package/dist/bundle/index.js +1 -1
  30. package/dist/bundle/rpc-entry.js +1 -1
  31. package/dist/core/export-html/template.css +10 -0
  32. package/dist/core/export-html/template.js +56 -18
  33. package/dist/modes/interactive/theme/theme-controller.d.ts +6 -0
  34. package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
  35. package/dist/modes/interactive/theme/theme-controller.js +41 -3
  36. package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
  37. package/dist/modes/interactive/theme/theme-json.d.ts +1 -0
  38. package/dist/modes/interactive/theme/theme-json.d.ts.map +1 -1
  39. package/dist/modes/interactive/theme/theme-json.js +3 -1
  40. package/dist/modes/interactive/theme/theme-json.js.map +1 -1
  41. package/dist/modes/interactive/theme/theme-schema.json +7 -2
  42. package/dist/modes/interactive/theme/theme.d.ts +40 -7
  43. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  44. package/dist/modes/interactive/theme/theme.js +122 -214
  45. package/dist/modes/interactive/theme/theme.js.map +1 -1
  46. package/docs/cli-integration.md +106 -0
  47. package/docs/cli.md +268 -0
  48. package/docs/compaction.md +45 -26
  49. package/docs/configuration.md +45 -0
  50. package/docs/containerization.md +109 -82
  51. package/docs/custom-provider.md +109 -722
  52. package/docs/docs.json +139 -99
  53. package/docs/environment-variables.md +3 -5
  54. package/docs/extensions.md +137 -2953
  55. package/docs/how-pi-works.md +49 -0
  56. package/docs/images/interactive-mode.png +0 -0
  57. package/docs/index.md +24 -69
  58. package/docs/json.md +193 -65
  59. package/docs/keybindings.md +57 -102
  60. package/docs/llama-cpp.md +3 -3
  61. package/docs/message-types.md +261 -0
  62. package/docs/models.md +64 -546
  63. package/docs/packages.md +67 -166
  64. package/docs/prompt-templates.md +31 -68
  65. package/docs/providers.md +102 -232
  66. package/docs/quickstart.md +61 -106
  67. package/docs/rpc-commands.md +854 -0
  68. package/docs/rpc-extension-ui.md +200 -0
  69. package/docs/rpc.md +129 -1556
  70. package/docs/sdk.md +76 -1160
  71. package/docs/security.md +70 -32
  72. package/docs/session-format.md +25 -216
  73. package/docs/sessions.md +35 -141
  74. package/docs/settings.md +109 -387
  75. package/docs/shell-aliases.md +85 -5
  76. package/docs/skills.md +51 -190
  77. package/docs/slash-commands.md +60 -0
  78. package/docs/terminal-setup.md +105 -78
  79. package/docs/termux.md +74 -83
  80. package/docs/themes.md +71 -279
  81. package/docs/tmux.md +31 -39
  82. package/docs/tui.md +74 -910
  83. package/docs/usage.md +54 -272
  84. package/docs/windows.md +43 -17
  85. package/examples/README.md +13 -2
  86. package/examples/extensions/README.md +1 -0
  87. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  88. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  89. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  90. package/examples/extensions/debug-provider.ts +90 -0
  91. package/examples/extensions/gondolin/package-lock.json +2 -2
  92. package/examples/extensions/gondolin/package.json +1 -1
  93. package/examples/extensions/sandbox/package-lock.json +2 -2
  94. package/examples/extensions/sandbox/package.json +1 -1
  95. package/examples/extensions/with-deps/package-lock.json +2 -2
  96. package/examples/extensions/with-deps/package.json +1 -1
  97. package/examples/plugins/pi-example-plugin/src/session.ts +3 -2
  98. package/examples/rpc-client.ts +35 -0
  99. package/examples/rpc-extension-ui.ts +25 -5
  100. package/examples/sdk/README.md +1 -1
  101. package/judge/dist/auth.js +166 -28
  102. package/judge/dist/chrome.js +12 -1
  103. package/judge/dist/kyrn-judge.js +1424 -589
  104. package/judge/dist/setup.js +2051 -0
  105. package/judge/manifest.json +13 -13
  106. package/judge/skills/mu-browser/SKILL.md +1 -0
  107. package/kyrn/bin/kyrn-doctor +107 -18
  108. package/kyrn/bin/mu.mjs +389 -29
  109. package/package.json +4 -4
  110. package/dist/bundle/chunks/anthropic-messages-MYU5ZMRF.js +0 -6
  111. package/dist/bundle/chunks/azure-openai-responses-HUSQ3GP2.js +0 -2
  112. package/dist/bundle/chunks/chunk-6R7UI4IY.js +0 -2
  113. package/dist/bundle/chunks/chunk-CK5Z65DM.js +0 -2
  114. package/dist/bundle/chunks/chunk-RCZIEVGO.js +0 -11
  115. package/dist/bundle/chunks/google-generative-ai-IMS5EK2Y.js +0 -2
  116. package/dist/bundle/chunks/google-vertex-O4YJEQUW.js +0 -2
  117. package/dist/bundle/chunks/mistral-conversations-NOSQHBEY.js +0 -5
  118. package/dist/bundle/chunks/openai-responses-HWEUZ6WZ.js +0 -2
  119. package/docs/development.md +0 -90
package/docs/cli.md ADDED
@@ -0,0 +1,268 @@
1
+ <a id="cli-and-modes-reference"></a>
2
+
3
+ # Command Line
4
+
5
+ This page documents Pi's built-in command-line commands and options. Run `pi --help` or append `--help` to a command for the exact interface in your installed version. The top-level help also includes options registered by loaded extensions.
6
+
7
+ ```sh
8
+ pi [options] [--] [@files...] [messages...]
9
+ pi install <source> [options]
10
+ pi remove <source> [options]
11
+ pi uninstall <source> [options]
12
+ pi update [target] [options]
13
+ pi list
14
+ pi config [options]
15
+ pi auth <check|print-api-key|print-bearer-token> [options]
16
+ ```
17
+
18
+ <a id="modes"></a>
19
+
20
+ ## Invocation and output
21
+
22
+ ```sh
23
+ pi
24
+ pi --print "Summarize this repository"
25
+ git diff | pi --print "Review this change"
26
+ pi --mode json "Inspect this repository" > events.jsonl
27
+ ```
28
+
29
+ With terminal stdin and stdout, Pi opens the terminal UI unless `--print`, `--mode json`, or `--mode rpc` selects another interface. When either stream is redirected and neither JSON nor RPC mode is selected, Pi uses print mode. See [CLI Integration](cli-integration.md) for choosing between interactive, print, JSON, RPC, and SDK integration.
30
+
31
+ | Input | Behavior |
32
+ |---|---|
33
+ | `message` | Provide an initial prompt |
34
+ | `@path` | Include a text file or image in the first prompt |
35
+ | Piped stdin | Prepend its contents to the first prompt |
36
+ | `--` | Stop option parsing so a prompt can begin with `-` |
37
+
38
+ Pi resolves `@path` from the current working directory. The working directory also controls project configuration, resource discovery, and session grouping.
39
+
40
+ `--print` controls whether Pi runs once and exits. `--mode` selects the output interface. `--mode text` does not force one-shot execution when stdin and stdout are terminals; use `--print` for that behavior.
41
+
42
+ | Option | Behavior |
43
+ |---|---|
44
+ | `-p`, `--print` | Run the supplied prompts, write the final assistant text to stdout, then exit |
45
+ | `--mode text` | Select text output; still open the terminal UI when stdin and stdout are terminals |
46
+ | `--mode json` | Run the supplied prompts, write JSONL events to stdout, then exit |
47
+ | `--mode rpc` | Read JSONL commands from stdin and write responses and events to stdout until shutdown |
48
+ | `--export <input> [output]` | Export a session file to HTML and exit; derive the destination when `output` is omitted |
49
+
50
+ RPC mode rejects `@file` arguments. JSON and RPC modes reserve stdout for protocol records. See [JSON Event Stream](json.md) and [RPC Protocol](rpc.md).
51
+
52
+ <a id="model-options"></a>
53
+
54
+ ## Models
55
+
56
+ ```sh
57
+ pi --model sonnet:high
58
+ ```
59
+
60
+ See [Choose a Model](models.md) for model selection and [Provider Authentication](providers.md) for credentials.
61
+
62
+ - `--provider <name>`<br>
63
+ Restricts `--model` lookup to one provider.
64
+ - `--model <pattern>`<br>
65
+ Selects by exact ID or fuzzy ID/name match. It accepts `provider/id` and an optional `:<thinking>` suffix.
66
+ - `--api-key <key>`<br>
67
+ Uses a non-persistent API-key override. It requires a model selected through `--model` or `--models`.
68
+ - `--thinking <level>`<br>
69
+ Sets `off`, `minimal`, `low`, `medium`, `high`, `xhigh`, or `max`. It overrides a `--model` suffix and is clamped to the model's capabilities.
70
+ - `--models <patterns>`<br>
71
+ Sets a comma-separated scope for startup and cycling. It accepts exact IDs, fuzzy matches, case-insensitive globs, and optional `:<thinking>` suffixes.
72
+ - `--list-models [search]`<br>
73
+ Lists available models, optionally filtered by a fuzzy search, then exits.
74
+
75
+ <a id="session-options"></a>
76
+
77
+ ## Sessions
78
+
79
+ ```sh
80
+ pi --continue
81
+ ```
82
+
83
+ See [Sessions and Context](sessions.md) for resuming, forking, naming, and storing sessions.
84
+
85
+ - `-c`, `--continue`<br>
86
+ Continues the most recent session for the current project.
87
+ - `-r`, `--resume`<br>
88
+ Opens the session selector.
89
+ - `--session <path|id>`<br>
90
+ Opens by file path, exact ID, or partial ID. Pi searches the current project first and offers to fork a cross-project match.
91
+ - `--session-id <id>`<br>
92
+ Opens the exact project session ID or creates it if absent. IDs accept letters, numbers, `.`, `_`, and `-`.
93
+ - `--fork <path|id>`<br>
94
+ Forks an existing session into a new session for the current project.
95
+ - `--session-dir <dir>`<br>
96
+ Overrides storage and lookup. It takes precedence over `PI_CODING_AGENT_SESSION_DIR` and the `sessionDir` setting.
97
+ - `--no-session`<br>
98
+ Uses an in-memory session that is not persisted.
99
+ - `-n`, `--name <name>`<br>
100
+ Sets the session display name.
101
+
102
+ Constraints:
103
+
104
+ - Session IDs must start and end with a letter or number.
105
+ - `--fork` cannot be combined with `--session`, `--continue`, `--resume`, or `--no-session`.
106
+ - `--session-id` cannot be combined with `--session`, `--continue`, or `--resume`. Combine it with `--fork` to choose the new ID.
107
+
108
+ <a id="tool-options"></a>
109
+
110
+ ## Tools
111
+
112
+ ```sh
113
+ pi --tools read,grep,find,ls --print "Review this project"
114
+ ```
115
+
116
+ See [Settings](settings.md#tools) for configuring the default tool selection.
117
+
118
+ - `-t`, `--tools <list>`<br>
119
+ Replaces the default selection with a comma-separated allowlist of built-in, extension, or custom tools.
120
+ - `-xt`, `--exclude-tools <list>`<br>
121
+ Disables comma-separated tool names after all other selection options.
122
+ - `-nbt`, `--no-builtin-tools`<br>
123
+ Disables default built-in tools while retaining extension and custom tools.
124
+ - `-nt`, `--no-tools`<br>
125
+ Starts with all built-in, extension, and custom tools disabled.
126
+
127
+ Default enabled tools are `read`, `bash`, `edit`, and `write`, unless `defaultTools` changes them.
128
+
129
+ | Built-in | Purpose |
130
+ |---|---|
131
+ | `read` | Read text files and supported images |
132
+ | `bash` | Run shell commands |
133
+ | `powershell` | Run PowerShell commands on Windows |
134
+ | `edit` | Apply exact text replacements to an existing file |
135
+ | `write` | Create or overwrite a file |
136
+ | `grep` | Search file contents |
137
+ | `find` | Find paths using glob patterns |
138
+ | `ls` | List directory contents |
139
+
140
+ <a id="resource-options"></a>
141
+
142
+ ## Resources
143
+
144
+ ```sh
145
+ pi --extension ./review.ts
146
+ ```
147
+
148
+ See [Configuration](configuration.md) for conventional directories and project trust, [Settings](settings.md#resources) for configured paths, and [Pi Packages](packages.md) for package sources.
149
+
150
+ - `-e`, `--extension <path>`<br>
151
+ Loads an extension file or directory and is repeatable.
152
+ - `-ne`, `--no-extensions`<br>
153
+ Disables discovered and configured extensions. Explicit `-e` paths still load.
154
+ - `--skill <path>`<br>
155
+ Loads a skill file or directory and is repeatable.
156
+ - `-ns`, `--no-skills`<br>
157
+ Disables discovered and configured skills. Explicit `--skill` paths still load.
158
+ - `--prompt-template <path>`<br>
159
+ Loads a prompt-template file or directory and is repeatable.
160
+ - `-np`, `--no-prompt-templates`<br>
161
+ Disables discovered and configured templates. Explicit `--prompt-template` paths still load.
162
+ - `--theme <path>`<br>
163
+ Loads a theme file or directory and is repeatable.
164
+ - `--use-theme <name[/name]>`<br>
165
+ Selects the initial interactive theme for this run.
166
+ - `--no-themes`<br>
167
+ Disables discovered and configured themes. Explicit `--theme` paths still load.
168
+ - `-nc`, `--no-context-files`<br>
169
+ Disables `AGENTS.md` and `CLAUDE.md` discovery.
170
+
171
+ Resource paths apply only to the current process. Relative paths resolve from the current working directory.
172
+
173
+ <a id="prompt-and-display-options"></a>
174
+
175
+ ## Prompts and process
176
+
177
+ ```sh
178
+ pi --append-system-prompt ./instructions.md
179
+ ```
180
+
181
+ See [Configuration](configuration.md) for saved configuration, [Security](security.md#understand-project-trust) for project trust, and [Environment Variables](environment-variables.md) for process controls.
182
+
183
+ - `--system-prompt <text|path>`<br>
184
+ Replaces the default system prompt with text or the contents of an existing file.
185
+ - `--append-system-prompt <text|path>`<br>
186
+ Appends text or an existing file to the system prompt and is repeatable.
187
+ - `--tui-mode <mode>`<br>
188
+ Uses `regular` or `fullscreen` terminal mode.
189
+ - `--verbose`<br>
190
+ Shows verbose interactive startup information, overriding `quietStartup`.
191
+ - `-a`, `--approve`<br>
192
+ Trusts project-local configuration and resources for this process.
193
+ - `-na`, `--no-approve`<br>
194
+ Ignores trust-gated project-local configuration and resources for this process.
195
+ - `--offline`<br>
196
+ Disables automatic network activity, including model catalog refreshes. Equivalent to `PI_OFFLINE=1`.
197
+ - `-h`, `--help`<br>
198
+ Shows help, including flags registered by loaded extensions, then exits.
199
+ - `-v`, `--version`<br>
200
+ Shows the Pi version, then exits.
201
+
202
+ Extensions may register additional long-form options. Unknown short options are rejected.
203
+
204
+ ## Package commands
205
+
206
+ ```sh
207
+ pi install npm:@scope/package
208
+ ```
209
+
210
+ See [Pi Packages](packages.md) for source formats, filtering, installation, and project scope.
211
+
212
+ ### Common tasks
213
+
214
+ | Task | Command |
215
+ |---|---|
216
+ | Install a package | `pi install <source>` |
217
+ | List configured packages | `pi list` |
218
+ | Remove a package and its settings entry | `pi remove <source>` |
219
+ | Configure which package resources load | `pi config` |
220
+
221
+ Add `--local` or `-l` to `install`, `remove`, `uninstall`, or `config` to use project settings instead of global settings.
222
+
223
+ ### Update Pi or packages
224
+
225
+ Running `pi update` without a target updates Pi itself.
226
+
227
+ | Task | Command |
228
+ |---|---|
229
+ | Update Pi | `pi update` |
230
+ | Update all installed packages | `pi update --extensions` |
231
+ | Update one installed package | `pi update <source>` |
232
+ | Refresh model catalogs | `pi update --models` |
233
+ | Update Pi and all installed packages | `pi update --all` |
234
+
235
+ Add `--force` to reinstall Pi when the selected update includes Pi.
236
+
237
+ ### Aliases and command options
238
+
239
+ - `pi uninstall <source>` is an alias for `pi remove <source>`.
240
+ - `pi update --self`, `pi update self`, and `pi update pi` are aliases for `pi update`.
241
+ - `pi update --extension <source>` is an alias for `pi update <source>`.
242
+ - `-a`, `--approve` trusts project-local files for one command. `-na`, `--no-approve` ignores trust-gated project-local files.
243
+ - Append `-h` or `--help` to a command for its exact usage and option constraints.
244
+
245
+ ## Credential commands
246
+
247
+ ```sh
248
+ pi auth check --provider openai --json
249
+ ```
250
+
251
+ Authentication commands require `--provider <provider>` or `--model <model>`. See [Provider Authentication](providers.md) for supported methods.
252
+
253
+ | Command | Description |
254
+ |---|---|
255
+ | `pi auth check` | Print `ready`, `not_ready`, or `invalid`; exit with status `0`, `1`, or `2`, respectively |
256
+ | `pi auth print-api-key` | Print the resolved API key |
257
+ | `pi auth print-bearer-token` | Print a resolved OAuth bearer token |
258
+
259
+ | Option | Applies to | Description |
260
+ |---|---|---|
261
+ | `--provider <provider>` | All | Resolve credentials for a provider |
262
+ | `--model <model>` | All | Resolve credentials from a model; may be combined with `--provider` |
263
+ | `--json` | `auth check` | Write the structured result as JSON |
264
+ | `--credentials` | `auth check` | Emit the resolved credential when ready |
265
+ | `--no-refresh` | `auth check` | Do not refresh expired OAuth credentials; refresh is the default |
266
+ | `--min-expiry <duration>` | `print-bearer-token` | Require remaining token lifetime using `ms`, `s`, `m`, or `h`, such as `30m` |
267
+
268
+ Credential-printing commands write secrets to stdout.
@@ -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.