@oh-my-pi/pi-coding-agent 1.337.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1228 -0
- package/README.md +1041 -0
- package/docs/compaction.md +403 -0
- package/docs/custom-tools.md +541 -0
- package/docs/extension-loading.md +1004 -0
- package/docs/hooks.md +867 -0
- package/docs/rpc.md +1040 -0
- package/docs/sdk.md +994 -0
- package/docs/session-tree-plan.md +441 -0
- package/docs/session.md +240 -0
- package/docs/skills.md +290 -0
- package/docs/theme.md +637 -0
- package/docs/tree.md +197 -0
- package/docs/tui.md +341 -0
- package/examples/README.md +21 -0
- package/examples/custom-tools/README.md +124 -0
- package/examples/custom-tools/hello/index.ts +20 -0
- package/examples/custom-tools/question/index.ts +84 -0
- package/examples/custom-tools/subagent/README.md +172 -0
- package/examples/custom-tools/subagent/agents/planner.md +37 -0
- package/examples/custom-tools/subagent/agents/reviewer.md +35 -0
- package/examples/custom-tools/subagent/agents/scout.md +50 -0
- package/examples/custom-tools/subagent/agents/worker.md +24 -0
- package/examples/custom-tools/subagent/agents.ts +156 -0
- package/examples/custom-tools/subagent/commands/implement-and-review.md +10 -0
- package/examples/custom-tools/subagent/commands/implement.md +10 -0
- package/examples/custom-tools/subagent/commands/scout-and-plan.md +9 -0
- package/examples/custom-tools/subagent/index.ts +1002 -0
- package/examples/custom-tools/todo/index.ts +212 -0
- package/examples/hooks/README.md +56 -0
- package/examples/hooks/auto-commit-on-exit.ts +49 -0
- package/examples/hooks/confirm-destructive.ts +59 -0
- package/examples/hooks/custom-compaction.ts +116 -0
- package/examples/hooks/dirty-repo-guard.ts +52 -0
- package/examples/hooks/file-trigger.ts +41 -0
- package/examples/hooks/git-checkpoint.ts +53 -0
- package/examples/hooks/handoff.ts +150 -0
- package/examples/hooks/permission-gate.ts +34 -0
- package/examples/hooks/protected-paths.ts +30 -0
- package/examples/hooks/qna.ts +119 -0
- package/examples/hooks/snake.ts +343 -0
- package/examples/hooks/status-line.ts +40 -0
- package/examples/sdk/01-minimal.ts +22 -0
- package/examples/sdk/02-custom-model.ts +49 -0
- package/examples/sdk/03-custom-prompt.ts +44 -0
- package/examples/sdk/04-skills.ts +44 -0
- package/examples/sdk/05-tools.ts +90 -0
- package/examples/sdk/06-hooks.ts +61 -0
- package/examples/sdk/07-context-files.ts +36 -0
- package/examples/sdk/08-slash-commands.ts +42 -0
- package/examples/sdk/09-api-keys-and-oauth.ts +55 -0
- package/examples/sdk/10-settings.ts +38 -0
- package/examples/sdk/11-sessions.ts +48 -0
- package/examples/sdk/12-full-control.ts +95 -0
- package/examples/sdk/README.md +154 -0
- package/package.json +81 -0
- package/src/cli/args.ts +246 -0
- package/src/cli/file-processor.ts +72 -0
- package/src/cli/list-models.ts +104 -0
- package/src/cli/plugin-cli.ts +650 -0
- package/src/cli/session-picker.ts +41 -0
- package/src/cli.ts +10 -0
- package/src/commands/init.md +20 -0
- package/src/config.ts +159 -0
- package/src/core/agent-session.ts +1900 -0
- package/src/core/auth-storage.ts +236 -0
- package/src/core/bash-executor.ts +196 -0
- package/src/core/compaction/branch-summarization.ts +343 -0
- package/src/core/compaction/compaction.ts +742 -0
- package/src/core/compaction/index.ts +7 -0
- package/src/core/compaction/utils.ts +154 -0
- package/src/core/custom-tools/index.ts +21 -0
- package/src/core/custom-tools/loader.ts +248 -0
- package/src/core/custom-tools/types.ts +169 -0
- package/src/core/custom-tools/wrapper.ts +28 -0
- package/src/core/exec.ts +129 -0
- package/src/core/export-html/index.ts +211 -0
- package/src/core/export-html/template.css +781 -0
- package/src/core/export-html/template.html +54 -0
- package/src/core/export-html/template.js +1185 -0
- package/src/core/export-html/vendor/highlight.min.js +1213 -0
- package/src/core/export-html/vendor/marked.min.js +6 -0
- package/src/core/hooks/index.ts +16 -0
- package/src/core/hooks/loader.ts +312 -0
- package/src/core/hooks/runner.ts +434 -0
- package/src/core/hooks/tool-wrapper.ts +99 -0
- package/src/core/hooks/types.ts +773 -0
- package/src/core/index.ts +52 -0
- package/src/core/mcp/client.ts +158 -0
- package/src/core/mcp/config.ts +154 -0
- package/src/core/mcp/index.ts +45 -0
- package/src/core/mcp/loader.ts +68 -0
- package/src/core/mcp/manager.ts +181 -0
- package/src/core/mcp/tool-bridge.ts +148 -0
- package/src/core/mcp/transports/http.ts +316 -0
- package/src/core/mcp/transports/index.ts +6 -0
- package/src/core/mcp/transports/stdio.ts +252 -0
- package/src/core/mcp/types.ts +220 -0
- package/src/core/messages.ts +189 -0
- package/src/core/model-registry.ts +317 -0
- package/src/core/model-resolver.ts +393 -0
- package/src/core/plugins/doctor.ts +59 -0
- package/src/core/plugins/index.ts +38 -0
- package/src/core/plugins/installer.ts +189 -0
- package/src/core/plugins/loader.ts +338 -0
- package/src/core/plugins/manager.ts +672 -0
- package/src/core/plugins/parser.ts +105 -0
- package/src/core/plugins/paths.ts +32 -0
- package/src/core/plugins/types.ts +190 -0
- package/src/core/sdk.ts +760 -0
- package/src/core/session-manager.ts +1128 -0
- package/src/core/settings-manager.ts +443 -0
- package/src/core/skills.ts +437 -0
- package/src/core/slash-commands.ts +248 -0
- package/src/core/system-prompt.ts +439 -0
- package/src/core/timings.ts +25 -0
- package/src/core/tools/ask.ts +211 -0
- package/src/core/tools/bash-interceptor.ts +120 -0
- package/src/core/tools/bash.ts +250 -0
- package/src/core/tools/context.ts +32 -0
- package/src/core/tools/edit-diff.ts +475 -0
- package/src/core/tools/edit.ts +208 -0
- package/src/core/tools/exa/company.ts +59 -0
- package/src/core/tools/exa/index.ts +64 -0
- package/src/core/tools/exa/linkedin.ts +59 -0
- package/src/core/tools/exa/logger.ts +56 -0
- package/src/core/tools/exa/mcp-client.ts +368 -0
- package/src/core/tools/exa/render.ts +196 -0
- package/src/core/tools/exa/researcher.ts +90 -0
- package/src/core/tools/exa/search.ts +337 -0
- package/src/core/tools/exa/types.ts +168 -0
- package/src/core/tools/exa/websets.ts +248 -0
- package/src/core/tools/find.ts +261 -0
- package/src/core/tools/grep.ts +555 -0
- package/src/core/tools/index.ts +202 -0
- package/src/core/tools/ls.ts +140 -0
- package/src/core/tools/lsp/client.ts +605 -0
- package/src/core/tools/lsp/config.ts +147 -0
- package/src/core/tools/lsp/edits.ts +101 -0
- package/src/core/tools/lsp/index.ts +804 -0
- package/src/core/tools/lsp/render.ts +447 -0
- package/src/core/tools/lsp/rust-analyzer.ts +145 -0
- package/src/core/tools/lsp/types.ts +463 -0
- package/src/core/tools/lsp/utils.ts +486 -0
- package/src/core/tools/notebook.ts +229 -0
- package/src/core/tools/path-utils.ts +61 -0
- package/src/core/tools/read.ts +240 -0
- package/src/core/tools/renderers.ts +540 -0
- package/src/core/tools/task/agents.ts +153 -0
- package/src/core/tools/task/artifacts.ts +114 -0
- package/src/core/tools/task/bundled-agents/browser.md +71 -0
- package/src/core/tools/task/bundled-agents/explore.md +82 -0
- package/src/core/tools/task/bundled-agents/plan.md +54 -0
- package/src/core/tools/task/bundled-agents/reviewer.md +59 -0
- package/src/core/tools/task/bundled-agents/task.md +53 -0
- package/src/core/tools/task/bundled-commands/architect-plan.md +10 -0
- package/src/core/tools/task/bundled-commands/implement-with-critic.md +11 -0
- package/src/core/tools/task/bundled-commands/implement.md +11 -0
- package/src/core/tools/task/commands.ts +213 -0
- package/src/core/tools/task/discovery.ts +208 -0
- package/src/core/tools/task/executor.ts +367 -0
- package/src/core/tools/task/index.ts +388 -0
- package/src/core/tools/task/model-resolver.ts +115 -0
- package/src/core/tools/task/parallel.ts +38 -0
- package/src/core/tools/task/render.ts +232 -0
- package/src/core/tools/task/types.ts +99 -0
- package/src/core/tools/truncate.ts +265 -0
- package/src/core/tools/web-fetch.ts +2370 -0
- package/src/core/tools/web-search/auth.ts +193 -0
- package/src/core/tools/web-search/index.ts +537 -0
- package/src/core/tools/web-search/providers/anthropic.ts +198 -0
- package/src/core/tools/web-search/providers/exa.ts +302 -0
- package/src/core/tools/web-search/providers/perplexity.ts +195 -0
- package/src/core/tools/web-search/render.ts +182 -0
- package/src/core/tools/web-search/types.ts +180 -0
- package/src/core/tools/write.ts +99 -0
- package/src/index.ts +176 -0
- package/src/main.ts +464 -0
- package/src/migrations.ts +135 -0
- package/src/modes/index.ts +43 -0
- package/src/modes/interactive/components/armin.ts +382 -0
- package/src/modes/interactive/components/assistant-message.ts +86 -0
- package/src/modes/interactive/components/bash-execution.ts +196 -0
- package/src/modes/interactive/components/bordered-loader.ts +41 -0
- package/src/modes/interactive/components/branch-summary-message.ts +42 -0
- package/src/modes/interactive/components/compaction-summary-message.ts +45 -0
- package/src/modes/interactive/components/custom-editor.ts +122 -0
- package/src/modes/interactive/components/diff.ts +147 -0
- package/src/modes/interactive/components/dynamic-border.ts +25 -0
- package/src/modes/interactive/components/footer.ts +381 -0
- package/src/modes/interactive/components/hook-editor.ts +117 -0
- package/src/modes/interactive/components/hook-input.ts +64 -0
- package/src/modes/interactive/components/hook-message.ts +96 -0
- package/src/modes/interactive/components/hook-selector.ts +91 -0
- package/src/modes/interactive/components/model-selector.ts +247 -0
- package/src/modes/interactive/components/oauth-selector.ts +120 -0
- package/src/modes/interactive/components/plugin-settings.ts +479 -0
- package/src/modes/interactive/components/queue-mode-selector.ts +56 -0
- package/src/modes/interactive/components/session-selector.ts +204 -0
- package/src/modes/interactive/components/settings-selector.ts +453 -0
- package/src/modes/interactive/components/show-images-selector.ts +45 -0
- package/src/modes/interactive/components/theme-selector.ts +62 -0
- package/src/modes/interactive/components/thinking-selector.ts +64 -0
- package/src/modes/interactive/components/tool-execution.ts +675 -0
- package/src/modes/interactive/components/tree-selector.ts +866 -0
- package/src/modes/interactive/components/user-message-selector.ts +159 -0
- package/src/modes/interactive/components/user-message.ts +18 -0
- package/src/modes/interactive/components/visual-truncate.ts +50 -0
- package/src/modes/interactive/components/welcome.ts +183 -0
- package/src/modes/interactive/interactive-mode.ts +2516 -0
- package/src/modes/interactive/theme/dark.json +101 -0
- package/src/modes/interactive/theme/light.json +98 -0
- package/src/modes/interactive/theme/theme-schema.json +308 -0
- package/src/modes/interactive/theme/theme.ts +998 -0
- package/src/modes/print-mode.ts +128 -0
- package/src/modes/rpc/rpc-client.ts +527 -0
- package/src/modes/rpc/rpc-mode.ts +483 -0
- package/src/modes/rpc/rpc-types.ts +203 -0
- package/src/utils/changelog.ts +99 -0
- package/src/utils/clipboard.ts +265 -0
- package/src/utils/fuzzy.ts +108 -0
- package/src/utils/mime.ts +30 -0
- package/src/utils/shell.ts +276 -0
- package/src/utils/tools-manager.ts +274 -0
package/README.md
ADDED
|
@@ -0,0 +1,1041 @@
|
|
|
1
|
+
# pi
|
|
2
|
+
|
|
3
|
+
A terminal-based coding agent with multi-model support, mid-session model switching, and a simple CLI for headless coding tasks.
|
|
4
|
+
|
|
5
|
+
Works on Linux, macOS, and Windows (requires bash; see [Windows Setup](#windows-setup)).
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
- [Getting Started](#getting-started)
|
|
10
|
+
- [Installation](#installation)
|
|
11
|
+
- [Windows Setup](#windows-setup)
|
|
12
|
+
- [API Keys & OAuth](#api-keys--oauth)
|
|
13
|
+
- [Quick Start](#quick-start)
|
|
14
|
+
- [Usage](#usage)
|
|
15
|
+
- [Slash Commands](#slash-commands)
|
|
16
|
+
- [Editor Features](#editor-features)
|
|
17
|
+
- [Keyboard Shortcuts](#keyboard-shortcuts)
|
|
18
|
+
- [Bash Mode](#bash-mode)
|
|
19
|
+
- [Image Support](#image-support)
|
|
20
|
+
- [Sessions](#sessions)
|
|
21
|
+
- [Session Management](#session-management)
|
|
22
|
+
- [Context Compaction](#context-compaction)
|
|
23
|
+
- [Branching](#branching)
|
|
24
|
+
- [Configuration](#configuration)
|
|
25
|
+
- [Project Context Files](#project-context-files)
|
|
26
|
+
- [Custom System Prompt](#custom-system-prompt)
|
|
27
|
+
- [Custom Models and Providers](#custom-models-and-providers)
|
|
28
|
+
- [Settings File](#settings-file)
|
|
29
|
+
- [Extensions](#extensions)
|
|
30
|
+
- [Themes](#themes)
|
|
31
|
+
- [Custom Slash Commands](#custom-slash-commands)
|
|
32
|
+
- [Skills](#skills)
|
|
33
|
+
- [Hooks](#hooks)
|
|
34
|
+
- [Custom Tools](#custom-tools)
|
|
35
|
+
- [CLI Reference](#cli-reference)
|
|
36
|
+
- [Tools](#tools)
|
|
37
|
+
- [Programmatic Usage](#programmatic-usage)
|
|
38
|
+
- [SDK](#sdk)
|
|
39
|
+
- [RPC Mode](#rpc-mode)
|
|
40
|
+
- [HTML Export](#html-export)
|
|
41
|
+
- [Philosophy](#philosophy)
|
|
42
|
+
- [Development](#development)
|
|
43
|
+
- [License](#license)
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Getting Started
|
|
48
|
+
|
|
49
|
+
### Installation
|
|
50
|
+
|
|
51
|
+
**npm (recommended):**
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npm install -g @oh-my-pi/pi-coding-agent
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Standalone binary:**
|
|
58
|
+
|
|
59
|
+
Download from [GitHub Releases](https://github.com/badlogic/pi-mono/releases):
|
|
60
|
+
|
|
61
|
+
| Platform | Archive |
|
|
62
|
+
| ------------------- | ------------------------ |
|
|
63
|
+
| macOS Apple Silicon | `pi-darwin-arm64.tar.gz` |
|
|
64
|
+
| macOS Intel | `pi-darwin-x64.tar.gz` |
|
|
65
|
+
| Linux x64 | `pi-linux-x64.tar.gz` |
|
|
66
|
+
| Linux ARM64 | `pi-linux-arm64.tar.gz` |
|
|
67
|
+
| Windows x64 | `pi-windows-x64.zip` |
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# macOS/Linux
|
|
71
|
+
tar -xzf pi-darwin-arm64.tar.gz
|
|
72
|
+
./pi
|
|
73
|
+
|
|
74
|
+
# Windows
|
|
75
|
+
unzip pi-windows-x64.zip
|
|
76
|
+
pi.exe
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**macOS note:** The binary is unsigned. If blocked, run: `xattr -c ./pi`
|
|
80
|
+
|
|
81
|
+
**Build from source** (requires [Bun](https://bun.sh) 1.0+):
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
git clone https://github.com/can1357/oh-my-pi.git
|
|
85
|
+
cd pi-mono && npm install
|
|
86
|
+
cd packages/coding-agent && npm run build:binary
|
|
87
|
+
./dist/pi
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Windows Setup
|
|
91
|
+
|
|
92
|
+
Pi requires a bash shell on Windows. Checked locations (in order):
|
|
93
|
+
|
|
94
|
+
1. Custom path from `~/.pi/agent/settings.json`
|
|
95
|
+
2. Git Bash (`C:\Program Files\Git\bin\bash.exe`)
|
|
96
|
+
3. `bash.exe` on PATH (Cygwin, MSYS2, WSL)
|
|
97
|
+
|
|
98
|
+
For most users, [Git for Windows](https://git-scm.com/download/win) is sufficient.
|
|
99
|
+
|
|
100
|
+
**Custom shell path:**
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
// ~/.pi/agent/settings.json
|
|
104
|
+
{
|
|
105
|
+
"shellPath": "C:\\cygwin64\\bin\\bash.exe"
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### API Keys & OAuth
|
|
110
|
+
|
|
111
|
+
**Option 1: Auth file** (recommended)
|
|
112
|
+
|
|
113
|
+
Add API keys to `~/.pi/agent/auth.json`:
|
|
114
|
+
|
|
115
|
+
```json
|
|
116
|
+
{
|
|
117
|
+
"anthropic": { "type": "api_key", "key": "sk-ant-..." },
|
|
118
|
+
"openai": { "type": "api_key", "key": "sk-..." },
|
|
119
|
+
"google": { "type": "api_key", "key": "..." }
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**Option 2: Environment variables**
|
|
124
|
+
|
|
125
|
+
| Provider | Auth Key | Environment Variable |
|
|
126
|
+
| ---------- | ------------ | -------------------- |
|
|
127
|
+
| Anthropic | `anthropic` | `ANTHROPIC_API_KEY` |
|
|
128
|
+
| OpenAI | `openai` | `OPENAI_API_KEY` |
|
|
129
|
+
| Google | `google` | `GEMINI_API_KEY` |
|
|
130
|
+
| Mistral | `mistral` | `MISTRAL_API_KEY` |
|
|
131
|
+
| Groq | `groq` | `GROQ_API_KEY` |
|
|
132
|
+
| Cerebras | `cerebras` | `CEREBRAS_API_KEY` |
|
|
133
|
+
| xAI | `xai` | `XAI_API_KEY` |
|
|
134
|
+
| OpenRouter | `openrouter` | `OPENROUTER_API_KEY` |
|
|
135
|
+
| ZAI | `zai` | `ZAI_API_KEY` |
|
|
136
|
+
|
|
137
|
+
Auth file keys take priority over environment variables.
|
|
138
|
+
|
|
139
|
+
**OAuth Providers:**
|
|
140
|
+
|
|
141
|
+
Use `/login` to authenticate with subscription-based or free-tier providers:
|
|
142
|
+
|
|
143
|
+
| Provider | Models | Cost |
|
|
144
|
+
| -------------------------- | ----------------------------------------------- | --------------------- |
|
|
145
|
+
| Anthropic (Claude Pro/Max) | Claude models via your subscription | Subscription |
|
|
146
|
+
| GitHub Copilot | GPT-4o, Claude, Gemini via Copilot subscription | Subscription |
|
|
147
|
+
| Google Gemini CLI | Gemini 2.0/2.5 models | Free (Google account) |
|
|
148
|
+
| Google Antigravity | Gemini 3, Claude, GPT-OSS | Free (Google account) |
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
pi
|
|
152
|
+
/login # Select provider, authorize in browser
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**Note:** `/login` replaces any existing API key for that provider with OAuth credentials in `auth.json`.
|
|
156
|
+
|
|
157
|
+
**GitHub Copilot notes:**
|
|
158
|
+
|
|
159
|
+
- Press Enter for github.com, or enter your GitHub Enterprise Server domain
|
|
160
|
+
- If you get "model not supported" error, enable it in VS Code: Copilot Chat → model selector → select model → "Enable"
|
|
161
|
+
|
|
162
|
+
**Google providers notes:**
|
|
163
|
+
|
|
164
|
+
- Gemini CLI uses the production Cloud Code Assist endpoint (standard Gemini models)
|
|
165
|
+
- Antigravity uses a sandbox endpoint with access to Gemini 3, Claude (sonnet/opus thinking), and GPT-OSS models
|
|
166
|
+
- Both are free with any Google account, subject to rate limits
|
|
167
|
+
|
|
168
|
+
Credentials stored in `~/.pi/agent/auth.json`. Use `/logout` to clear.
|
|
169
|
+
|
|
170
|
+
### Quick Start
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
export ANTHROPIC_API_KEY=sk-ant-...
|
|
174
|
+
pi
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Then chat:
|
|
178
|
+
|
|
179
|
+
```
|
|
180
|
+
You: Create a simple Express server in src/server.ts
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
The agent reads, writes, and edits files, and executes commands via bash.
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## Usage
|
|
188
|
+
|
|
189
|
+
### Slash Commands
|
|
190
|
+
|
|
191
|
+
| Command | Description |
|
|
192
|
+
| ------------------------- | --------------------------------------------------------------------------- |
|
|
193
|
+
| `/settings` | Open settings menu (thinking, theme, queue mode, toggles) |
|
|
194
|
+
| `/model` | Switch models mid-session (fuzzy search, arrow keys, Enter to select) |
|
|
195
|
+
| `/export [file]` | Export session to self-contained HTML |
|
|
196
|
+
| `/share` | Upload session as secret GitHub gist, get shareable URL (requires `gh` CLI) |
|
|
197
|
+
| `/session` | Show session info: path, message counts, token usage, cost |
|
|
198
|
+
| `/hotkeys` | Show all keyboard shortcuts |
|
|
199
|
+
| `/changelog` | Display full version history |
|
|
200
|
+
| `/tree` | Navigate session tree in-place (search, filter, label entries) |
|
|
201
|
+
| `/branch` | Create new conversation branch from a previous message |
|
|
202
|
+
| `/resume` | Switch to a different session (interactive selector) |
|
|
203
|
+
| `/login` | OAuth login for subscription-based models |
|
|
204
|
+
| `/logout` | Clear OAuth tokens |
|
|
205
|
+
| `/new` | Start a new session |
|
|
206
|
+
| `/copy` | Copy last agent message to clipboard |
|
|
207
|
+
| `/compact [instructions]` | Manually compact conversation context |
|
|
208
|
+
|
|
209
|
+
### Editor Features
|
|
210
|
+
|
|
211
|
+
**File reference (`@`):** Type `@` to fuzzy-search project files. Respects `.gitignore`.
|
|
212
|
+
|
|
213
|
+
**Path completion (Tab):** Complete relative paths, `../`, `~/`, etc.
|
|
214
|
+
|
|
215
|
+
**Drag & drop:** Drag files from your file manager into the terminal.
|
|
216
|
+
|
|
217
|
+
**Multi-line paste:** Pasted content is collapsed to `[paste #N <lines> lines]` but sent in full.
|
|
218
|
+
|
|
219
|
+
**Message queuing:** Submit messages while the agent is working. They queue and process based on queue mode (configurable via `/settings`). Press Escape to abort and restore queued messages to editor.
|
|
220
|
+
|
|
221
|
+
### Keyboard Shortcuts
|
|
222
|
+
|
|
223
|
+
**Navigation:**
|
|
224
|
+
|
|
225
|
+
| Key | Action |
|
|
226
|
+
| ------------------------ | -------------------------------------------- |
|
|
227
|
+
| Arrow keys | Move cursor / browse history (Up when empty) |
|
|
228
|
+
| Option+Left/Right | Move by word |
|
|
229
|
+
| Ctrl+A / Home / Cmd+Left | Start of line |
|
|
230
|
+
| Ctrl+E / End / Cmd+Right | End of line |
|
|
231
|
+
|
|
232
|
+
**Editing:**
|
|
233
|
+
|
|
234
|
+
| Key | Action |
|
|
235
|
+
| ------------------------- | ---------------------------- |
|
|
236
|
+
| Enter | Send message |
|
|
237
|
+
| Shift+Enter / Alt+Enter | New line (Ctrl+Enter on WSL) |
|
|
238
|
+
| Ctrl+W / Option+Backspace | Delete word backwards |
|
|
239
|
+
| Ctrl+U | Delete to start of line |
|
|
240
|
+
| Ctrl+K | Delete to end of line |
|
|
241
|
+
|
|
242
|
+
**Other:**
|
|
243
|
+
|
|
244
|
+
| Key | Action |
|
|
245
|
+
| --------------------- | -------------------------------------------------------- |
|
|
246
|
+
| Tab | Path completion / accept autocomplete |
|
|
247
|
+
| Escape | Cancel autocomplete / abort streaming |
|
|
248
|
+
| Ctrl+C | Clear editor (first) / exit (second) |
|
|
249
|
+
| Ctrl+D | Exit (when editor is empty) |
|
|
250
|
+
| Ctrl+Z | Suspend to background (use `fg` in shell to resume) |
|
|
251
|
+
| Shift+Tab | Cycle thinking level |
|
|
252
|
+
| Ctrl+P / Shift+Ctrl+P | Cycle models forward/backward (scoped by `--models`) |
|
|
253
|
+
| Ctrl+L | Open model selector |
|
|
254
|
+
| Ctrl+O | Toggle tool output expansion |
|
|
255
|
+
| Ctrl+T | Toggle thinking block visibility |
|
|
256
|
+
| Ctrl+G | Edit message in external editor (`$VISUAL` or `$EDITOR`) |
|
|
257
|
+
|
|
258
|
+
### Bash Mode
|
|
259
|
+
|
|
260
|
+
Prefix commands with `!` to execute them and add output to context:
|
|
261
|
+
|
|
262
|
+
```
|
|
263
|
+
!ls -la
|
|
264
|
+
!git status
|
|
265
|
+
!cat package.json | jq '.dependencies'
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Output streams in real-time. Press Escape to cancel. Large outputs truncate at 2000 lines / 50KB.
|
|
269
|
+
|
|
270
|
+
The output becomes part of your next prompt, formatted as:
|
|
271
|
+
|
|
272
|
+
```
|
|
273
|
+
Ran `ls -la`
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
<output here>
|
|
277
|
+
```
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
Run multiple commands before prompting; all outputs are included together.
|
|
281
|
+
|
|
282
|
+
### Image Support
|
|
283
|
+
|
|
284
|
+
**Attaching images:** Include image paths in your message:
|
|
285
|
+
|
|
286
|
+
```
|
|
287
|
+
You: What's in this screenshot? /path/to/image.png
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
Supported formats: `.jpg`, `.jpeg`, `.png`, `.gif`, `.webp`
|
|
291
|
+
|
|
292
|
+
**Inline rendering:** On terminals that support the Kitty graphics protocol (Kitty, Ghostty, WezTerm) or iTerm2 inline images, images in tool output are rendered inline. On unsupported terminals, a text placeholder is shown instead.
|
|
293
|
+
|
|
294
|
+
Toggle inline images via `/settings` or set `terminal.showImages: false` in settings.
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
## Sessions
|
|
299
|
+
|
|
300
|
+
Sessions are stored as JSONL files with a **tree structure**. Each entry has an `id` and `parentId`, enabling in-place branching: navigate to any previous point with `/tree`, continue from there, and switch between branches while preserving all history in a single file.
|
|
301
|
+
|
|
302
|
+
See [docs/session.md](docs/session.md) for the file format and programmatic API.
|
|
303
|
+
|
|
304
|
+
### Session Management
|
|
305
|
+
|
|
306
|
+
Sessions auto-save to `~/.pi/agent/sessions/` organized by working directory.
|
|
307
|
+
|
|
308
|
+
```bash
|
|
309
|
+
pi --continue # Continue most recent session
|
|
310
|
+
pi -c # Short form
|
|
311
|
+
|
|
312
|
+
pi --resume # Browse and select from past sessions
|
|
313
|
+
pi -r # Short form
|
|
314
|
+
|
|
315
|
+
pi --no-session # Ephemeral mode (don't save)
|
|
316
|
+
|
|
317
|
+
pi --session /path/to/file.jsonl # Use specific session file
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### Context Compaction
|
|
321
|
+
|
|
322
|
+
Long sessions can exhaust context windows. Compaction summarizes older messages while keeping recent ones.
|
|
323
|
+
|
|
324
|
+
**Manual:** `/compact` or `/compact Focus on the API changes`
|
|
325
|
+
|
|
326
|
+
**Automatic:** Enable via `/settings`. When enabled, triggers in two cases:
|
|
327
|
+
|
|
328
|
+
- **Overflow recovery**: LLM returns context overflow error. Compacts and auto-retries.
|
|
329
|
+
- **Threshold maintenance**: Context exceeds `contextWindow - reserveTokens` after a successful turn. Compacts without retry.
|
|
330
|
+
|
|
331
|
+
When disabled, neither case triggers automatic compaction (use `/compact` manually if needed).
|
|
332
|
+
|
|
333
|
+
**Configuration** (`~/.pi/agent/settings.json`):
|
|
334
|
+
|
|
335
|
+
```json
|
|
336
|
+
{
|
|
337
|
+
"compaction": {
|
|
338
|
+
"enabled": true,
|
|
339
|
+
"reserveTokens": 16384,
|
|
340
|
+
"keepRecentTokens": 20000
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
> **Note:** Compaction is lossy. The agent loses full conversation access afterward. Size tasks to avoid context limits when possible. For critical context, ask the agent to write a summary to a file, iterate on it until it covers everything, then start a new session with that file. The full session history is preserved in the JSONL file; use `/tree` to revisit any previous point.
|
|
346
|
+
|
|
347
|
+
See [docs/compaction.md](docs/compaction.md) for how compaction works internally and how to customize it via hooks.
|
|
348
|
+
|
|
349
|
+
### Branching
|
|
350
|
+
|
|
351
|
+
**In-place navigation (`/tree`):** Navigate the session tree without creating new files. Select any previous point, continue from there, and switch between branches while preserving all history.
|
|
352
|
+
|
|
353
|
+
- Search by typing, page with ←/→
|
|
354
|
+
- Filter modes (Ctrl+O): default → no-tools → user-only → labeled-only → all
|
|
355
|
+
- Press `l` to label entries as bookmarks
|
|
356
|
+
- When switching branches, you're prompted whether to generate a summary of the abandoned branch (messages up to the common ancestor)
|
|
357
|
+
|
|
358
|
+
**Create new session (`/branch`):** Branch to a new session file:
|
|
359
|
+
|
|
360
|
+
1. Opens selector showing all your user messages
|
|
361
|
+
2. Select a message to branch from
|
|
362
|
+
3. Creates new session with history up to that point
|
|
363
|
+
4. Selected message placed in editor for modification
|
|
364
|
+
|
|
365
|
+
---
|
|
366
|
+
|
|
367
|
+
## Configuration
|
|
368
|
+
|
|
369
|
+
### Project Context Files
|
|
370
|
+
|
|
371
|
+
Pi loads `AGENTS.md` (or `CLAUDE.md`) files at startup in this order:
|
|
372
|
+
|
|
373
|
+
1. **Global:** `~/.pi/agent/AGENTS.md`
|
|
374
|
+
2. **Parent directories:** Walking up from current directory
|
|
375
|
+
3. **Current directory:** `./AGENTS.md`
|
|
376
|
+
|
|
377
|
+
Use these for:
|
|
378
|
+
|
|
379
|
+
- Project instructions and guidelines
|
|
380
|
+
- Common commands and workflows
|
|
381
|
+
- Architecture documentation
|
|
382
|
+
- Coding conventions
|
|
383
|
+
- Testing instructions
|
|
384
|
+
|
|
385
|
+
```markdown
|
|
386
|
+
# Common Commands
|
|
387
|
+
|
|
388
|
+
- npm run build: Build the project
|
|
389
|
+
- npm test: Run tests
|
|
390
|
+
|
|
391
|
+
# Code Style
|
|
392
|
+
|
|
393
|
+
- Use TypeScript strict mode
|
|
394
|
+
- Prefer async/await over promises
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
### Custom System Prompt
|
|
398
|
+
|
|
399
|
+
Replace the default system prompt entirely by creating a `SYSTEM.md` file:
|
|
400
|
+
|
|
401
|
+
1. **Project-local:** `.pi/SYSTEM.md` (takes precedence)
|
|
402
|
+
2. **Global:** `~/.pi/agent/SYSTEM.md` (fallback)
|
|
403
|
+
|
|
404
|
+
This is useful when using pi as different types of agents across repos (coding assistant, personal assistant, domain-specific agent, etc.).
|
|
405
|
+
|
|
406
|
+
```markdown
|
|
407
|
+
You are a technical writing assistant. Help users write clear documentation.
|
|
408
|
+
|
|
409
|
+
Focus on:
|
|
410
|
+
|
|
411
|
+
- Concise explanations
|
|
412
|
+
- Code examples
|
|
413
|
+
- Proper formatting
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
The `--system-prompt` CLI flag overrides both files. Use `--append-system-prompt` to add to (rather than replace) the prompt.
|
|
417
|
+
|
|
418
|
+
### Custom Models and Providers
|
|
419
|
+
|
|
420
|
+
Add custom models (Ollama, vLLM, LM Studio, etc.) via `~/.pi/agent/models.json`:
|
|
421
|
+
|
|
422
|
+
```json
|
|
423
|
+
{
|
|
424
|
+
"providers": {
|
|
425
|
+
"ollama": {
|
|
426
|
+
"baseUrl": "http://localhost:11434/v1",
|
|
427
|
+
"apiKey": "OLLAMA_API_KEY",
|
|
428
|
+
"api": "openai-completions",
|
|
429
|
+
"models": [
|
|
430
|
+
{
|
|
431
|
+
"id": "llama-3.1-8b",
|
|
432
|
+
"name": "Llama 3.1 8B (Local)",
|
|
433
|
+
"reasoning": false,
|
|
434
|
+
"input": ["text"],
|
|
435
|
+
"cost": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0 },
|
|
436
|
+
"contextWindow": 128000,
|
|
437
|
+
"maxTokens": 32000
|
|
438
|
+
}
|
|
439
|
+
]
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
**Supported APIs:** `openai-completions`, `openai-responses`, `anthropic-messages`, `google-generative-ai`
|
|
446
|
+
|
|
447
|
+
**API key resolution:** The `apiKey` field is checked as environment variable name first, then used as literal value.
|
|
448
|
+
|
|
449
|
+
**API override:** Set `api` at provider level (default for all models) or model level (override per model).
|
|
450
|
+
|
|
451
|
+
**Custom headers:**
|
|
452
|
+
|
|
453
|
+
```json
|
|
454
|
+
{
|
|
455
|
+
"providers": {
|
|
456
|
+
"custom-proxy": {
|
|
457
|
+
"baseUrl": "https://proxy.example.com/v1",
|
|
458
|
+
"apiKey": "YOUR_API_KEY",
|
|
459
|
+
"api": "anthropic-messages",
|
|
460
|
+
"headers": {
|
|
461
|
+
"User-Agent": "Mozilla/5.0 ...",
|
|
462
|
+
"X-Custom-Auth": "token"
|
|
463
|
+
},
|
|
464
|
+
"models": [...]
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
**Authorization header:** Set `authHeader: true` to add `Authorization: Bearer <apiKey>` automatically.
|
|
471
|
+
|
|
472
|
+
**OpenAI compatibility (`compat` field):**
|
|
473
|
+
|
|
474
|
+
| Field | Description |
|
|
475
|
+
| ------------------------- | ------------------------------------------- |
|
|
476
|
+
| `supportsStore` | Whether provider supports `store` field |
|
|
477
|
+
| `supportsDeveloperRole` | Use `developer` vs `system` role |
|
|
478
|
+
| `supportsReasoningEffort` | Support for `reasoning_effort` parameter |
|
|
479
|
+
| `maxTokensField` | Use `max_completion_tokens` or `max_tokens` |
|
|
480
|
+
|
|
481
|
+
**Live reload:** The file reloads each time you open `/model`. Edit during session; no restart needed.
|
|
482
|
+
|
|
483
|
+
**Model selection priority:**
|
|
484
|
+
|
|
485
|
+
1. CLI args (`--provider`, `--model`)
|
|
486
|
+
2. First from `--models` scope (new sessions only)
|
|
487
|
+
3. Restored from session (`--continue`, `--resume`)
|
|
488
|
+
4. Saved default from settings
|
|
489
|
+
5. First available model with valid API key
|
|
490
|
+
|
|
491
|
+
> pi can help you create custom provider and model configurations.
|
|
492
|
+
|
|
493
|
+
### Settings File
|
|
494
|
+
|
|
495
|
+
Settings are loaded from two locations and merged:
|
|
496
|
+
|
|
497
|
+
1. **Global:** `~/.pi/agent/settings.json` - user preferences
|
|
498
|
+
2. **Project:** `<cwd>/.pi/settings.json` - project-specific overrides (version control friendly)
|
|
499
|
+
|
|
500
|
+
Project settings override global settings. For nested objects, individual keys merge. Settings changed via TUI (model, thinking level, etc.) are saved to global preferences only.
|
|
501
|
+
|
|
502
|
+
Global `~/.pi/agent/settings.json` stores persistent preferences:
|
|
503
|
+
|
|
504
|
+
```json
|
|
505
|
+
{
|
|
506
|
+
"theme": "dark",
|
|
507
|
+
"defaultProvider": "anthropic",
|
|
508
|
+
"defaultModel": "claude-sonnet-4-20250514",
|
|
509
|
+
"defaultThinkingLevel": "medium",
|
|
510
|
+
"enabledModels": ["anthropic/*", "*gpt*", "gemini-2.5-pro:high"],
|
|
511
|
+
"queueMode": "one-at-a-time",
|
|
512
|
+
"shellPath": "C:\\path\\to\\bash.exe",
|
|
513
|
+
"hideThinkingBlock": false,
|
|
514
|
+
"collapseChangelog": false,
|
|
515
|
+
"compaction": {
|
|
516
|
+
"enabled": true,
|
|
517
|
+
"reserveTokens": 16384,
|
|
518
|
+
"keepRecentTokens": 20000
|
|
519
|
+
},
|
|
520
|
+
"skills": {
|
|
521
|
+
"enabled": true
|
|
522
|
+
},
|
|
523
|
+
"retry": {
|
|
524
|
+
"enabled": true,
|
|
525
|
+
"maxRetries": 3,
|
|
526
|
+
"baseDelayMs": 2000
|
|
527
|
+
},
|
|
528
|
+
"terminal": {
|
|
529
|
+
"showImages": true
|
|
530
|
+
},
|
|
531
|
+
"hooks": ["/path/to/hook.ts"],
|
|
532
|
+
"customTools": ["/path/to/tool.ts"]
|
|
533
|
+
}
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
| Setting | Description | Default |
|
|
537
|
+
| ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | --------------- |
|
|
538
|
+
| `theme` | Color theme name | auto-detected |
|
|
539
|
+
| `defaultProvider` | Default model provider | - |
|
|
540
|
+
| `defaultModel` | Default model ID | - |
|
|
541
|
+
| `defaultThinkingLevel` | Thinking level: `off`, `minimal`, `low`, `medium`, `high`, `xhigh` | - |
|
|
542
|
+
| `enabledModels` | Model patterns for cycling. Supports glob patterns (`github-copilot/*`, `*sonnet*`) and fuzzy matching. Same as `--models` CLI flag | - |
|
|
543
|
+
| `queueMode` | Message queue mode: `all` or `one-at-a-time` | `one-at-a-time` |
|
|
544
|
+
| `shellPath` | Custom bash path (Windows) | auto-detected |
|
|
545
|
+
| `hideThinkingBlock` | Hide thinking blocks in output (Ctrl+T to toggle) | `false` |
|
|
546
|
+
| `collapseChangelog` | Show condensed changelog after update | `false` |
|
|
547
|
+
| `compaction.enabled` | Enable auto-compaction | `true` |
|
|
548
|
+
| `compaction.reserveTokens` | Tokens to reserve before compaction triggers | `16384` |
|
|
549
|
+
| `compaction.keepRecentTokens` | Recent tokens to keep after compaction | `20000` |
|
|
550
|
+
| `skills.enabled` | Enable skills discovery | `true` |
|
|
551
|
+
| `retry.enabled` | Auto-retry on transient errors | `true` |
|
|
552
|
+
| `retry.maxRetries` | Maximum retry attempts | `3` |
|
|
553
|
+
| `retry.baseDelayMs` | Base delay for exponential backoff | `2000` |
|
|
554
|
+
| `terminal.showImages` | Render images inline (supported terminals) | `true` |
|
|
555
|
+
| `hooks` | Additional hook file paths | `[]` |
|
|
556
|
+
| `customTools` | Additional custom tool file paths | `[]` |
|
|
557
|
+
|
|
558
|
+
---
|
|
559
|
+
|
|
560
|
+
## Extensions
|
|
561
|
+
|
|
562
|
+
### Themes
|
|
563
|
+
|
|
564
|
+
Built-in themes: `dark` (default), `light`. Auto-detected on first run.
|
|
565
|
+
|
|
566
|
+
Select theme via `/settings` or set in `~/.pi/agent/settings.json`.
|
|
567
|
+
|
|
568
|
+
**Custom themes:** Create `~/.pi/agent/themes/*.json`. Custom themes support live reload.
|
|
569
|
+
|
|
570
|
+
```bash
|
|
571
|
+
mkdir -p ~/.pi/agent/themes
|
|
572
|
+
cp $(npm root -g)/@oh-my-pi/pi-coding-agent/dist/theme/dark.json ~/.pi/agent/themes/my-theme.json
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
Select with `/settings`, then edit the file. Changes apply on save.
|
|
576
|
+
|
|
577
|
+
> See [Theme Documentation](docs/theme.md) on how to create custom themes in detail. Pi can help you create a new one.
|
|
578
|
+
|
|
579
|
+
**VS Code terminal fix:** Set `terminal.integrated.minimumContrastRatio` to `1` for accurate colors.
|
|
580
|
+
|
|
581
|
+
### Custom Slash Commands
|
|
582
|
+
|
|
583
|
+
Define reusable prompts as Markdown files:
|
|
584
|
+
|
|
585
|
+
**Locations:**
|
|
586
|
+
|
|
587
|
+
- Global: `~/.pi/agent/commands/*.md`
|
|
588
|
+
- Project: `.pi/commands/*.md`
|
|
589
|
+
|
|
590
|
+
**Format:**
|
|
591
|
+
|
|
592
|
+
```markdown
|
|
593
|
+
---
|
|
594
|
+
description: Review staged git changes
|
|
595
|
+
---
|
|
596
|
+
|
|
597
|
+
Review the staged changes (`git diff --cached`). Focus on:
|
|
598
|
+
|
|
599
|
+
- Bugs and logic errors
|
|
600
|
+
- Security issues
|
|
601
|
+
- Error handling gaps
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
Filename (without `.md`) becomes the command name. Description shown in autocomplete.
|
|
605
|
+
|
|
606
|
+
**Arguments:**
|
|
607
|
+
|
|
608
|
+
```markdown
|
|
609
|
+
---
|
|
610
|
+
description: Create a component
|
|
611
|
+
---
|
|
612
|
+
|
|
613
|
+
Create a React component named $1 with features: $@
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
Usage: `/component Button "onClick handler" "disabled support"`
|
|
617
|
+
|
|
618
|
+
- `$1` = `Button`
|
|
619
|
+
- `$@` = all arguments joined
|
|
620
|
+
|
|
621
|
+
**Namespacing:** Subdirectories create prefixes. `.pi/commands/frontend/component.md` → `/component (project:frontend)`
|
|
622
|
+
|
|
623
|
+
### Skills
|
|
624
|
+
|
|
625
|
+
Skills are self-contained capability packages that the agent loads on-demand. Pi implements the [Agent Skills standard](https://agentskills.io/specification), warning about violations but remaining lenient.
|
|
626
|
+
|
|
627
|
+
A skill provides specialized workflows, setup instructions, helper scripts, and reference documentation for specific tasks. Skills are loaded when the agent decides a task matches the description, or when you explicitly ask to use one.
|
|
628
|
+
|
|
629
|
+
**Example use cases:**
|
|
630
|
+
|
|
631
|
+
- Web search and content extraction (Brave Search API)
|
|
632
|
+
- Browser automation via Chrome DevTools Protocol
|
|
633
|
+
- Google Calendar, Gmail, Drive integration
|
|
634
|
+
- PDF/DOCX processing and creation
|
|
635
|
+
- Speech-to-text transcription
|
|
636
|
+
- YouTube transcript extraction
|
|
637
|
+
|
|
638
|
+
**Skill locations:**
|
|
639
|
+
|
|
640
|
+
- Pi user: `~/.pi/agent/skills/**/SKILL.md` (recursive)
|
|
641
|
+
- Pi project: `.pi/skills/**/SKILL.md` (recursive)
|
|
642
|
+
- Claude Code: `~/.claude/skills/*/SKILL.md` and `.claude/skills/*/SKILL.md`
|
|
643
|
+
- Codex CLI: `~/.codex/skills/**/SKILL.md` (recursive)
|
|
644
|
+
|
|
645
|
+
**Format:**
|
|
646
|
+
|
|
647
|
+
```markdown
|
|
648
|
+
---
|
|
649
|
+
name: brave-search
|
|
650
|
+
description: Web search via Brave Search API. Use for documentation, facts, or web content.
|
|
651
|
+
---
|
|
652
|
+
|
|
653
|
+
# Brave Search
|
|
654
|
+
|
|
655
|
+
## Setup
|
|
656
|
+
|
|
657
|
+
\`\`\`bash
|
|
658
|
+
cd /path/to/brave-search && npm install
|
|
659
|
+
\`\`\`
|
|
660
|
+
|
|
661
|
+
## Usage
|
|
662
|
+
|
|
663
|
+
\`\`\`bash
|
|
664
|
+
./search.js "query" # Basic search
|
|
665
|
+
./search.js "query" --content # Include page content
|
|
666
|
+
\`\`\`
|
|
667
|
+
```
|
|
668
|
+
|
|
669
|
+
- `name`: Required. Must match parent directory name. Lowercase, hyphens, max 64 chars.
|
|
670
|
+
- `description`: Required. Max 1024 chars. Determines when the skill is loaded.
|
|
671
|
+
|
|
672
|
+
**Disable skills:** `pi --no-skills` or set `skills.enabled: false` in settings.
|
|
673
|
+
|
|
674
|
+
> See [docs/skills.md](docs/skills.md) for details, examples, and links to skill repositories. pi can help you create new skills.
|
|
675
|
+
|
|
676
|
+
### Hooks
|
|
677
|
+
|
|
678
|
+
Hooks are TypeScript modules that extend pi's behavior by subscribing to lifecycle events. Use them to:
|
|
679
|
+
|
|
680
|
+
- **Block dangerous commands** (permission gates for `rm -rf`, `sudo`, etc.)
|
|
681
|
+
- **Checkpoint code state** (git stash at each turn, restore on `/branch`)
|
|
682
|
+
- **Protect paths** (block writes to `.env`, `node_modules/`, etc.)
|
|
683
|
+
- **Modify tool output** (filter or transform results before the LLM sees them)
|
|
684
|
+
- **Inject messages from external sources to wake up the agent** (file watchers, webhooks, CI systems)
|
|
685
|
+
|
|
686
|
+
**Hook locations:**
|
|
687
|
+
|
|
688
|
+
- Global: `~/.pi/agent/hooks/*.ts`
|
|
689
|
+
- Project: `.pi/hooks/*.ts`
|
|
690
|
+
- CLI: `--hook <path>` (for debugging)
|
|
691
|
+
|
|
692
|
+
**Quick example** (permission gate):
|
|
693
|
+
|
|
694
|
+
```typescript
|
|
695
|
+
import type { HookAPI } from "@oh-my-pi/pi-coding-agent/hooks";
|
|
696
|
+
|
|
697
|
+
export default function (pi: HookAPI) {
|
|
698
|
+
pi.on("tool_call", async (event, ctx) => {
|
|
699
|
+
if (event.toolName === "bash" && /sudo/.test(event.input.command as string)) {
|
|
700
|
+
const ok = await ctx.ui.confirm("Allow sudo?", event.input.command as string);
|
|
701
|
+
if (!ok) return { block: true, reason: "Blocked by user" };
|
|
702
|
+
}
|
|
703
|
+
return undefined;
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
```
|
|
707
|
+
|
|
708
|
+
**Sending messages from hooks:**
|
|
709
|
+
|
|
710
|
+
Use `pi.sendMessage(message, triggerTurn?)` to inject messages into the session. Messages are persisted as `CustomMessageEntry` and sent to the LLM. If the agent is streaming, the message is queued; otherwise a new agent loop starts if `triggerTurn` is true.
|
|
711
|
+
|
|
712
|
+
```typescript
|
|
713
|
+
import * as fs from "node:fs";
|
|
714
|
+
import type { HookAPI } from "@oh-my-pi/pi-coding-agent/hooks";
|
|
715
|
+
|
|
716
|
+
export default function (pi: HookAPI) {
|
|
717
|
+
pi.on("session_start", async () => {
|
|
718
|
+
fs.watch("/tmp/trigger.txt", () => {
|
|
719
|
+
const content = fs.readFileSync("/tmp/trigger.txt", "utf-8").trim();
|
|
720
|
+
if (content) {
|
|
721
|
+
pi.sendMessage(
|
|
722
|
+
{
|
|
723
|
+
customType: "file-trigger",
|
|
724
|
+
content,
|
|
725
|
+
display: true,
|
|
726
|
+
},
|
|
727
|
+
true
|
|
728
|
+
); // triggerTurn: start agent loop
|
|
729
|
+
}
|
|
730
|
+
});
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
> See [Hooks Documentation](docs/hooks.md) for full API reference. pi can help you create new hooks
|
|
736
|
+
|
|
737
|
+
> See [examples/hooks/](examples/hooks/) for working examples including permission gates, git checkpointing, and path protection.
|
|
738
|
+
|
|
739
|
+
### Custom Tools
|
|
740
|
+
|
|
741
|
+
Custom tools let you extend the built-in toolset (read, write, edit, bash, ...) and are called by the LLM directly. They are TypeScript modules that define tools with optional custom TUI integration for getting user input and custom tool call and result rendering.
|
|
742
|
+
|
|
743
|
+
**Tool locations (auto-discovered):**
|
|
744
|
+
|
|
745
|
+
- Global: `~/.pi/agent/tools/*/index.ts`
|
|
746
|
+
- Project: `.pi/tools/*/index.ts`
|
|
747
|
+
|
|
748
|
+
**Explicit paths:**
|
|
749
|
+
|
|
750
|
+
- CLI: `--tool <path>` (any .ts file)
|
|
751
|
+
- Settings: `customTools` array in `settings.json`
|
|
752
|
+
|
|
753
|
+
**Quick example:**
|
|
754
|
+
|
|
755
|
+
```typescript
|
|
756
|
+
import { Type } from "@sinclair/typebox";
|
|
757
|
+
import type { CustomToolFactory } from "@oh-my-pi/pi-coding-agent";
|
|
758
|
+
|
|
759
|
+
const factory: CustomToolFactory = (pi) => ({
|
|
760
|
+
name: "greet",
|
|
761
|
+
label: "Greeting",
|
|
762
|
+
description: "Generate a greeting",
|
|
763
|
+
parameters: Type.Object({
|
|
764
|
+
name: Type.String({ description: "Name to greet" }),
|
|
765
|
+
}),
|
|
766
|
+
|
|
767
|
+
async execute(toolCallId, params, onUpdate, ctx, signal) {
|
|
768
|
+
const { name } = params as { name: string };
|
|
769
|
+
return {
|
|
770
|
+
content: [{ type: "text", text: `Hello, ${name}!` }],
|
|
771
|
+
details: { greeted: name },
|
|
772
|
+
};
|
|
773
|
+
},
|
|
774
|
+
});
|
|
775
|
+
|
|
776
|
+
export default factory;
|
|
777
|
+
```
|
|
778
|
+
|
|
779
|
+
**Features:**
|
|
780
|
+
|
|
781
|
+
- Access to `pi.cwd`, `pi.exec()`, `pi.ui` (select/confirm/input dialogs)
|
|
782
|
+
- Session lifecycle via `onSession` callback (for state reconstruction)
|
|
783
|
+
- Custom rendering via `renderCall()` and `renderResult()` methods
|
|
784
|
+
- Streaming results via `onUpdate` callback
|
|
785
|
+
- Abort handling via `signal` parameter
|
|
786
|
+
- Multiple tools from one factory (return an array)
|
|
787
|
+
|
|
788
|
+
> See [Custom Tools Documentation](docs/custom-tools.md) for the full API reference, TUI component guide, and examples. pi can help you create custom tools.
|
|
789
|
+
|
|
790
|
+
> See [examples/custom-tools/](examples/custom-tools/) for working examples including a todo list with session state management and a question tool with UI interaction.
|
|
791
|
+
|
|
792
|
+
---
|
|
793
|
+
|
|
794
|
+
## CLI Reference
|
|
795
|
+
|
|
796
|
+
```bash
|
|
797
|
+
pi [options] [@files...] [messages...]
|
|
798
|
+
```
|
|
799
|
+
|
|
800
|
+
### Options
|
|
801
|
+
|
|
802
|
+
| Option | Description |
|
|
803
|
+
| ------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
804
|
+
| `--provider <name>` | Provider: `anthropic`, `openai`, `google`, `mistral`, `xai`, `groq`, `cerebras`, `openrouter`, `zai`, `github-copilot`, `google-gemini-cli`, `google-antigravity`, or custom |
|
|
805
|
+
| `--model <id>` | Model ID |
|
|
806
|
+
| `--api-key <key>` | API key (overrides environment) |
|
|
807
|
+
| `--system-prompt <text\|file>` | Custom system prompt (text or file path) |
|
|
808
|
+
| `--append-system-prompt <text\|file>` | Append to system prompt |
|
|
809
|
+
| `--mode <mode>` | Output mode: `text`, `json`, `rpc` (implies `--print`) |
|
|
810
|
+
| `--print`, `-p` | Non-interactive: process prompt and exit |
|
|
811
|
+
| `--no-session` | Don't save session |
|
|
812
|
+
| `--session <path>` | Use specific session file |
|
|
813
|
+
| `--session-dir <dir>` | Directory for session storage and lookup |
|
|
814
|
+
| `--continue`, `-c` | Continue most recent session |
|
|
815
|
+
| `--resume`, `-r` | Select session to resume |
|
|
816
|
+
| `--models <patterns>` | Comma-separated patterns for Ctrl+P cycling. Supports glob patterns (e.g., `anthropic/*`, `*sonnet*:high`) and fuzzy matching (e.g., `sonnet,haiku:low`) |
|
|
817
|
+
| `--tools <tools>` | Comma-separated tool list (default: `read,bash,edit,write`) |
|
|
818
|
+
| `--thinking <level>` | Thinking level: `off`, `minimal`, `low`, `medium`, `high` |
|
|
819
|
+
| `--hook <path>` | Load a hook file (can be used multiple times) |
|
|
820
|
+
| `--no-skills` | Disable skills discovery and loading |
|
|
821
|
+
| `--skills <patterns>` | Comma-separated glob patterns to filter skills (e.g., `git-*,docker`) |
|
|
822
|
+
| `--export <file> [output]` | Export session to HTML |
|
|
823
|
+
| `--help`, `-h` | Show help |
|
|
824
|
+
| `--version`, `-v` | Show version |
|
|
825
|
+
|
|
826
|
+
### File Arguments
|
|
827
|
+
|
|
828
|
+
Include files with `@` prefix:
|
|
829
|
+
|
|
830
|
+
```bash
|
|
831
|
+
pi @prompt.md "Answer this"
|
|
832
|
+
pi @screenshot.png "What's in this image?"
|
|
833
|
+
pi @requirements.md @design.png "Implement this"
|
|
834
|
+
```
|
|
835
|
+
|
|
836
|
+
Text files wrapped in `<file name="path">content</file>`. Images attached as base64.
|
|
837
|
+
|
|
838
|
+
### Examples
|
|
839
|
+
|
|
840
|
+
```bash
|
|
841
|
+
# Interactive mode
|
|
842
|
+
pi
|
|
843
|
+
|
|
844
|
+
# Interactive with initial prompt
|
|
845
|
+
pi "List all .ts files in src/"
|
|
846
|
+
|
|
847
|
+
# Non-interactive
|
|
848
|
+
pi -p "List all .ts files in src/"
|
|
849
|
+
|
|
850
|
+
# With files
|
|
851
|
+
pi -p @code.ts "Review this code"
|
|
852
|
+
|
|
853
|
+
# JSON event stream
|
|
854
|
+
pi --mode json "List files"
|
|
855
|
+
|
|
856
|
+
# RPC mode (headless)
|
|
857
|
+
pi --mode rpc --no-session
|
|
858
|
+
|
|
859
|
+
# Continue session
|
|
860
|
+
pi -c "What did we discuss?"
|
|
861
|
+
|
|
862
|
+
# Specific model
|
|
863
|
+
pi --provider openai --model gpt-4o "Help me refactor"
|
|
864
|
+
|
|
865
|
+
# Model cycling with thinking levels
|
|
866
|
+
pi --models sonnet:high,haiku:low
|
|
867
|
+
|
|
868
|
+
# Limit to specific provider with glob pattern
|
|
869
|
+
pi --models "github-copilot/*"
|
|
870
|
+
|
|
871
|
+
# Read-only mode
|
|
872
|
+
pi --tools read,grep,find,ls -p "Review the architecture"
|
|
873
|
+
|
|
874
|
+
# Export session
|
|
875
|
+
pi --export session.jsonl output.html
|
|
876
|
+
```
|
|
877
|
+
|
|
878
|
+
---
|
|
879
|
+
|
|
880
|
+
## Tools
|
|
881
|
+
|
|
882
|
+
### Default Tools
|
|
883
|
+
|
|
884
|
+
| Tool | Description |
|
|
885
|
+
| ------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
|
|
886
|
+
| `read` | Read file contents. Images sent as attachments. Text: first 2000 lines, lines truncated at 2000 chars. Use offset/limit for large files. |
|
|
887
|
+
| `write` | Write/overwrite file. Creates parent directories. |
|
|
888
|
+
| `edit` | Replace exact text in file. Must match exactly including whitespace. Fails if text appears multiple times or not found. |
|
|
889
|
+
| `bash` | Execute command. Returns stdout/stderr. Optional `timeout` parameter. |
|
|
890
|
+
|
|
891
|
+
### Read-Only Tools
|
|
892
|
+
|
|
893
|
+
Available via `--tools` flag:
|
|
894
|
+
|
|
895
|
+
| Tool | Description |
|
|
896
|
+
| ------ | --------------------------------------------------------------- |
|
|
897
|
+
| `grep` | Search file contents (regex or literal). Respects `.gitignore`. |
|
|
898
|
+
| `find` | Search for files by glob pattern. Respects `.gitignore`. |
|
|
899
|
+
| `ls` | List directory contents. Includes dotfiles. |
|
|
900
|
+
|
|
901
|
+
Example: `--tools read,grep,find,ls` for code review without modification.
|
|
902
|
+
|
|
903
|
+
For adding new tools, see [Custom Tools](#custom-tools) in the Configuration section.
|
|
904
|
+
|
|
905
|
+
---
|
|
906
|
+
|
|
907
|
+
## Programmatic Usage
|
|
908
|
+
|
|
909
|
+
### SDK
|
|
910
|
+
|
|
911
|
+
For embedding pi in Node.js/TypeScript applications, use the SDK:
|
|
912
|
+
|
|
913
|
+
```typescript
|
|
914
|
+
import { createAgentSession, discoverAuthStorage, discoverModels, SessionManager } from "@oh-my-pi/pi-coding-agent";
|
|
915
|
+
|
|
916
|
+
const authStorage = discoverAuthStorage();
|
|
917
|
+
const modelRegistry = discoverModels(authStorage);
|
|
918
|
+
|
|
919
|
+
const { session } = await createAgentSession({
|
|
920
|
+
sessionManager: SessionManager.inMemory(),
|
|
921
|
+
authStorage,
|
|
922
|
+
modelRegistry,
|
|
923
|
+
});
|
|
924
|
+
|
|
925
|
+
session.subscribe((event) => {
|
|
926
|
+
if (event.type === "message_update" && event.assistantMessageEvent.type === "text_delta") {
|
|
927
|
+
process.stdout.write(event.assistantMessageEvent.delta);
|
|
928
|
+
}
|
|
929
|
+
});
|
|
930
|
+
|
|
931
|
+
await session.prompt("What files are in the current directory?");
|
|
932
|
+
```
|
|
933
|
+
|
|
934
|
+
The SDK provides full control over:
|
|
935
|
+
|
|
936
|
+
- Model selection and thinking level
|
|
937
|
+
- System prompt (replace or modify)
|
|
938
|
+
- Tools (built-in subsets, custom tools)
|
|
939
|
+
- Hooks (inline or discovered)
|
|
940
|
+
- Skills, context files, slash commands
|
|
941
|
+
- Session persistence (`SessionManager`)
|
|
942
|
+
- Settings (`SettingsManager`)
|
|
943
|
+
- API key resolution and OAuth
|
|
944
|
+
|
|
945
|
+
**Philosophy:** "Omit to discover, provide to override." Omit an option and pi discovers from standard locations. Provide an option and your value is used.
|
|
946
|
+
|
|
947
|
+
> See [SDK Documentation](docs/sdk.md) for the full API reference. See [examples/sdk/](examples/sdk/) for working examples from minimal to full control.
|
|
948
|
+
|
|
949
|
+
### RPC Mode
|
|
950
|
+
|
|
951
|
+
For embedding pi from other languages or with process isolation:
|
|
952
|
+
|
|
953
|
+
```bash
|
|
954
|
+
pi --mode rpc --no-session
|
|
955
|
+
```
|
|
956
|
+
|
|
957
|
+
Send JSON commands on stdin:
|
|
958
|
+
|
|
959
|
+
```json
|
|
960
|
+
{"type":"prompt","message":"List all .ts files"}
|
|
961
|
+
{"type":"abort"}
|
|
962
|
+
```
|
|
963
|
+
|
|
964
|
+
> See [RPC Documentation](docs/rpc.md) for the full protocol.
|
|
965
|
+
|
|
966
|
+
### HTML Export
|
|
967
|
+
|
|
968
|
+
```bash
|
|
969
|
+
pi --export session.jsonl # Auto-generated filename
|
|
970
|
+
pi --export session.jsonl output.html # Custom filename
|
|
971
|
+
```
|
|
972
|
+
|
|
973
|
+
Works with both session files and streaming event logs from `--mode json`.
|
|
974
|
+
|
|
975
|
+
---
|
|
976
|
+
|
|
977
|
+
## Philosophy
|
|
978
|
+
|
|
979
|
+
Pi is opinionated about what it won't do. These are intentional design decisions to minimize context bloat and avoid anti-patterns.
|
|
980
|
+
|
|
981
|
+
**No MCP.** Build CLI tools with READMEs (see [Skills](#skills)). The agent reads them on demand. [Would you like to know more?](https://mariozechner.at/posts/2025-11-02-what-if-you-dont-need-mcp/)
|
|
982
|
+
|
|
983
|
+
**No sub-agents.** Spawn pi instances via tmux, or [build your own sub-agent tool](examples/custom-tools/subagent/) with [custom tools](#custom-tools). Full observability and steerability.
|
|
984
|
+
|
|
985
|
+
**No permission popups.** Security theater. Run in a container or build your own with [Hooks](#hooks).
|
|
986
|
+
|
|
987
|
+
**No plan mode.** Gather context in one session, write plans to file, start fresh for implementation.
|
|
988
|
+
|
|
989
|
+
**No built-in to-dos.** They confuse models. Use a TODO.md file, or [build your own](examples/custom-tools/todo/) with [custom tools](#custom-tools).
|
|
990
|
+
|
|
991
|
+
**No background bash.** Use tmux. Full observability, direct interaction.
|
|
992
|
+
|
|
993
|
+
Read the [blog post](https://mariozechner.at/posts/2025-11-30-pi-coding-agent/) for the full rationale.
|
|
994
|
+
|
|
995
|
+
---
|
|
996
|
+
|
|
997
|
+
## Development
|
|
998
|
+
|
|
999
|
+
### Forking / Rebranding
|
|
1000
|
+
|
|
1001
|
+
Configure via `package.json`:
|
|
1002
|
+
|
|
1003
|
+
```json
|
|
1004
|
+
{
|
|
1005
|
+
"piConfig": {
|
|
1006
|
+
"name": "pi",
|
|
1007
|
+
"configDir": ".pi"
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
```
|
|
1011
|
+
|
|
1012
|
+
Change `name`, `configDir`, and `bin` field for your fork. Affects CLI banner, config paths, and environment variable names.
|
|
1013
|
+
|
|
1014
|
+
### Path Resolution
|
|
1015
|
+
|
|
1016
|
+
Three execution modes: npm install, standalone binary, tsx from source.
|
|
1017
|
+
|
|
1018
|
+
**Always use `src/paths.ts`** for package assets:
|
|
1019
|
+
|
|
1020
|
+
```typescript
|
|
1021
|
+
import { getPackageDir, getThemeDir } from "./paths.js";
|
|
1022
|
+
```
|
|
1023
|
+
|
|
1024
|
+
Never use `__dirname` directly for package assets.
|
|
1025
|
+
|
|
1026
|
+
### Debug Command
|
|
1027
|
+
|
|
1028
|
+
`/debug` (hidden) writes rendered lines with ANSI codes to `~/.pi/agent/pi-debug.log` for TUI debugging, as well as the last set of messages that were sent to the LLM.
|
|
1029
|
+
|
|
1030
|
+
For architecture and contribution guidelines, see [DEVELOPMENT.md](./DEVELOPMENT.md).
|
|
1031
|
+
|
|
1032
|
+
---
|
|
1033
|
+
|
|
1034
|
+
## License
|
|
1035
|
+
|
|
1036
|
+
MIT
|
|
1037
|
+
|
|
1038
|
+
## See Also
|
|
1039
|
+
|
|
1040
|
+
- [@oh-my-pi/pi-ai](https://www.npmjs.com/package/@oh-my-pi/pi-ai): Core LLM toolkit
|
|
1041
|
+
- [@oh-my-pi/pi-agent](https://www.npmjs.com/package/@oh-my-pi/pi-agent): Agent framework
|