Sitelet https://github.com/earendil-works/pi/commit/25cc5c7bf4cbc76b2e134c729eb8d57d521ed749
Skip to content

Commit 25cc5c7

Browse files
docs(coding-agent): refresh documentation (#9898)
* docs(coding-agent): improve getting started documentation * docs(coding-agent): correct getting started details * docs(coding-agent): clarify SDK entry point * docs(coding-agent): restructure guides and references * docs(coding-agent): improve getting started guides * docs(coding-agent): refresh integration guides * docs(coding-agent): improve terminal and CLI guides * docs(coding-agent): refresh customisation guides * docs(coding-agent): clarify project trust terminology * docs(coding-agent): simplify customisation guidance * docs(coding-agent): improve runtime and reference guidance * Fix settings reference * feat(coding-agent): add Crowdin documentation sync * docs(coding-agent): separate CLI and slash command references * docs(coding-agent): correct compaction reference * docs(coding-agent): streamline package documentation * docs(coding-agent): split RPC reference documentation * Update configuration docs * Shorten config docs * docs(coding-agent): refine configuration references * docs(coding-agent): streamline settings reference * docs(coding-agent): clarify configuration reference * docs(coding-agent): clarify project trust exception * docs(coding-agent): simplify keybindings reference * docs(coding-agent): remove Crowdin integration * docs(coding-agent): turn themes reference into guide * docs(coding-agent): consolidate model and authentication docs * docs(tui): require Component.invalidate() (fixes #9358) * docs(coding-agent): document offline catalog behavior (fixes #8684) * docs(coding-agent): preserve established documentation routes * docs(coding-agent): reorganize documentation navigation * docs(coding-agent): correct audited behavior Clarify provider, session, local-model, Termux, TUI, SDK, debug, and extension behavior. Simplify the documentation audit to report only clear user-visible contradictions. * docs(coding-agent): fix broken documentation links
1 parent d201760 commit 25cc5c7

49 files changed

Lines changed: 4106 additions & 11600 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎AGENTS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- Inline single-line helpers that have only one call site.
2020
- Check node_modules for external API types; don't guess.
2121
- **No inline imports** (`await import()`, `import("pkg").Type`, dynamic type imports). Top-level imports only.
22+
- In `packages/coding-agent`, resolve package assets through helpers in `src/config.ts`. Do not use `__dirname` directly; the helpers account for source checkouts, npm installations, and standalone binaries.
2223
- Never remove or downgrade code to fix type errors from outdated deps; upgrade the dep instead.
2324
- Use only erasable TypeScript syntax (Node strip-only mode) in code checked by the root config (`packages/*/src`, `packages/*/test`, `packages/coding-agent/examples`): no parameter properties, `enum`, `namespace`/`module`, `import =`, `export =`, or other constructs needing JS emit. Use explicit fields with constructor assignments.
2425
- Always ask before removing functionality or code that appears intentional.

‎packages/coding-agent/README.md‎

Lines changed: 25 additions & 711 deletions
Large diffs are not rendered by default.
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

‎packages/coding-agent/docs/cli.md‎

Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

0 commit comments

Comments
 (0)