@kingingwang/pi-windows-arm64 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.
- package/bin/CHANGELOG.md +62 -0
- package/bin/README.md +25 -675
- package/bin/docs/cli-integration.md +106 -0
- package/bin/docs/cli.md +268 -0
- package/bin/docs/compaction.md +45 -26
- package/bin/docs/configuration.md +45 -0
- package/bin/docs/containerization.md +109 -82
- package/bin/docs/custom-provider.md +132 -784
- package/bin/docs/docs.json +139 -99
- package/bin/docs/environment-variables.md +3 -5
- package/bin/docs/extensions.md +134 -2956
- package/bin/docs/how-pi-works.md +49 -0
- package/bin/docs/images/interactive-mode.png +0 -0
- package/bin/docs/index.md +24 -69
- package/bin/docs/json.md +193 -65
- package/bin/docs/keybindings.md +57 -102
- package/bin/docs/llama-cpp.md +3 -3
- package/bin/docs/message-types.md +261 -0
- package/bin/docs/models.md +64 -546
- package/bin/docs/packages.md +66 -167
- package/bin/docs/prompt-templates.md +31 -68
- package/bin/docs/providers.md +102 -240
- package/bin/docs/quickstart.md +61 -106
- package/bin/docs/rpc-commands.md +854 -0
- package/bin/docs/rpc-extension-ui.md +200 -0
- package/bin/docs/rpc.md +129 -1556
- package/bin/docs/sdk.md +76 -1160
- package/bin/docs/security.md +70 -32
- package/bin/docs/session-format.md +25 -216
- package/bin/docs/sessions.md +35 -141
- package/bin/docs/settings.md +109 -386
- package/bin/docs/shell-aliases.md +85 -5
- package/bin/docs/skills.md +51 -190
- package/bin/docs/slash-commands.md +60 -0
- package/bin/docs/terminal-setup.md +105 -78
- package/bin/docs/termux.md +74 -83
- package/bin/docs/themes.md +68 -280
- package/bin/docs/tmux.md +31 -39
- package/bin/docs/tui.md +69 -923
- package/bin/docs/usage.md +54 -272
- package/bin/docs/windows.md +43 -17
- package/bin/examples/README.md +13 -2
- package/bin/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/bin/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/bin/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/bin/examples/extensions/gondolin/package-lock.json +2 -2
- package/bin/examples/extensions/gondolin/package.json +1 -1
- package/bin/examples/extensions/sandbox/package-lock.json +2 -2
- package/bin/examples/extensions/sandbox/package.json +1 -1
- package/bin/examples/extensions/with-deps/package-lock.json +2 -2
- package/bin/examples/extensions/with-deps/package.json +1 -1
- package/bin/examples/plugins/pi-example-plugin/src/session.ts +3 -2
- package/bin/examples/rpc-client.ts +35 -0
- package/bin/examples/rpc-extension-ui.ts +25 -5
- package/bin/examples/sdk/README.md +1 -1
- package/bin/export-html/template.js +6 -1
- package/bin/package.json +8 -8
- package/bin/pi.exe +2 -2
- package/package.json +1 -1
- package/bin/docs/development.md +0 -90
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# CLI Integration
|
|
2
|
+
|
|
3
|
+
By default, running `pi` opens the interactive terminal interface. When input or output is piped or redirected, Pi uses print mode instead. You can also select print, JSON, or RPC mode explicitly for scripts and applications.
|
|
4
|
+
|
|
5
|
+
All four modes use the same agent, sessions, resources, and tools. The mode determines how input enters Pi, how output is exposed, and whether the process remains available for more commands.
|
|
6
|
+
|
|
7
|
+
The SDK is not a CLI mode. It embeds the agent directly in a Node.js or Bun process. See the [SDK](sdk.md) when direct TypeScript access is preferable to a process boundary.
|
|
8
|
+
|
|
9
|
+
## Choose a mode
|
|
10
|
+
|
|
11
|
+
| Mode | Interface | Lifetime | Use it when |
|
|
12
|
+
|---|---|---|---|
|
|
13
|
+
| Interactive | Terminal UI | Until the user exits | A person is working with Pi directly |
|
|
14
|
+
| Print | Final text on stdout | One invocation | A script needs the final assistant response |
|
|
15
|
+
| JSON | JSONL events on stdout | One invocation | A process needs structured progress from a run |
|
|
16
|
+
| RPC | JSONL commands, responses, and events | Long-lived | A process needs bidirectional control |
|
|
17
|
+
|
|
18
|
+
CLI options still select the working directory, model, tools, resources, and session persistence independently of the mode. See [Command Line](cli.md) for the complete startup options.
|
|
19
|
+
|
|
20
|
+
## Print to stdout
|
|
21
|
+
|
|
22
|
+
Print mode runs the supplied prompts, writes the final assistant text to stdout, and exits:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pi --print "Summarize the changes in this repository"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Use print mode when only the final text is needed, including command substitution, pipelines, and one-shot jobs. Intermediate events are not exposed.
|
|
29
|
+
|
|
30
|
+
Print mode writes errors to stderr. A final assistant response with an `error` or `aborted` stop reason produces a nonzero exit status.
|
|
31
|
+
|
|
32
|
+
When no mode is selected explicitly, non-TTY stdin or stdout also selects print mode. This allows piped input and output without adding `--print`.
|
|
33
|
+
|
|
34
|
+
## Stream JSON events
|
|
35
|
+
|
|
36
|
+
JSON mode writes a session header followed by agent and session events as newline-delimited JSON:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pi --mode json "Review this repository" > events.jsonl
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
This is structured event output, not a single JSON result or a constraint on the format of the model’s response.
|
|
43
|
+
|
|
44
|
+
All prompts are supplied when the process starts. The process streams events for that run and then exits; it does not accept later commands.
|
|
45
|
+
|
|
46
|
+
A failed or aborted assistant response appears in the event stream but does not by itself produce a nonzero exit status. Inspect the events when success or failure matters. Pi still exits nonzero if the invocation throws an error.
|
|
47
|
+
|
|
48
|
+
Streaming `message_update` records contain deltas rather than a growing message snapshot. Assemble live output from the delta events, then replace it with the authoritative message from `message_end`.
|
|
49
|
+
|
|
50
|
+
`agent_end` can be followed by automatic recovery or queued work. `agent_settled` marks the end of automatic work for the current run.
|
|
51
|
+
|
|
52
|
+
Stdout is reserved for JSONL. Diagnostics and application logging are written to stderr. See [JSON Event Stream](json.md) for framing, event shapes, and reconstruction rules.
|
|
53
|
+
|
|
54
|
+
## Control Pi with RPC
|
|
55
|
+
|
|
56
|
+
RPC mode keeps Pi running while another process sends commands and receives responses and events:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pi --mode rpc --no-session
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Commands are JSON objects written to stdin. Responses and events are JSON objects written to stdout. Every record occupies one line.
|
|
63
|
+
|
|
64
|
+
Add an `id` to commands that need correlation. The matching response repeats that ID. Events generally have no command ID because they describe session activity rather than one request.
|
|
65
|
+
|
|
66
|
+
A successful `prompt` response means the prompt was accepted, queued, or handled. It does not mean the run completed. Continue consuming events through `agent_settled` when completion matters.
|
|
67
|
+
|
|
68
|
+
RPC commands can change models, inspect state, manage sessions, run shell commands, and answer extension UI requests.
|
|
69
|
+
|
|
70
|
+
Extension dialogs form a request-response subprotocol. Other extension UI updates are notifications that a client may display or ignore. TUI-only extension capabilities are unavailable or degraded outside interactive mode.
|
|
71
|
+
|
|
72
|
+
For Node.js or TypeScript integrations, prefer `RpcClient` from `@earendil-works/pi-coding-agent`. It starts a Pi RPC child process, correlates requests, exposes typed command methods, and delivers session events to listeners.
|
|
73
|
+
|
|
74
|
+
The [RPC client example](../examples/rpc-client.ts) sends one prompt, streams text and tool activity, waits for `agent_settled`, and shuts down the child process. It is included in the repository’s TypeScript checks.
|
|
75
|
+
|
|
76
|
+
`RpcClient.promptAndWait()` installs its event listener before sending the prompt, avoiding a race with fast completions. For separate operations, subscribe before calling `prompt()` and call `waitForIdle()` only while a run is active.
|
|
77
|
+
|
|
78
|
+
The client requires a path to a runnable Pi CLI. The repository example points at `dist/cli.js`, so the package must be built before that example runs from a checkout.
|
|
79
|
+
|
|
80
|
+
If you are building a client without `RpcClient`, start with [RPC Protocol](rpc.md), then use [RPC Commands](rpc-commands.md) and [JSON Event Stream](json.md) as the wire references.
|
|
81
|
+
|
|
82
|
+
## Fork and rebrand Pi
|
|
83
|
+
|
|
84
|
+
A source fork can change the CLI name and configuration directory through `package.json`:
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
{
|
|
88
|
+
"piConfig": {
|
|
89
|
+
"name": "my-agent",
|
|
90
|
+
"configDir": ".my-agent"
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Change the top-level `bin` field to set the executable name. These settings affect the CLI banner, configuration paths, and derived environment variable names.
|
|
96
|
+
|
|
97
|
+
## Examples and references
|
|
98
|
+
|
|
99
|
+
- [RPC client](../examples/rpc-client.ts): typed Node.js integration
|
|
100
|
+
- [RPC extension UI](../examples/rpc-extension-ui.ts): custom terminal client with extension dialogs
|
|
101
|
+
- [Command Line](cli.md): startup options and mode selection
|
|
102
|
+
- [JSON Event Stream](json.md): JSON event reference
|
|
103
|
+
- [RPC Protocol](rpc.md): RPC lifecycle, framing, errors, and shutdown
|
|
104
|
+
- [RPC Commands](rpc-commands.md): command and response reference
|
|
105
|
+
- [RPC Extension UI](rpc-extension-ui.md): extension interaction subprotocol
|
|
106
|
+
- [SDK examples](../examples/sdk/): in-process TypeScript integrations
|
package/bin/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.
|
package/bin/docs/compaction.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# Compaction
|
|
1
|
+
# Compaction Reference
|
|
2
2
|
|
|
3
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
100
|
+
### Split user-message spans
|
|
84
101
|
|
|
85
|
-
A
|
|
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
|
|
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
|
|
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
|
|
120
|
+
messagesToSummarize = [] (no earlier user-message spans)
|
|
104
121
|
turnPrefixMessages = [usr, ass, tool, ass, tool, tool]
|
|
105
122
|
```
|
|
106
123
|
|
|
107
|
-
For split
|
|
124
|
+
For split user-message spans, Pi generates two summaries and merges them:
|
|
108
125
|
1. **History summary**: Previous context (if any)
|
|
109
|
-
2. **
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
|
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 -
|
|
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
|
|
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 [
|
|
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.
|