@dyyz1993/pi-coding-agent 0.70.5 → 0.74.4
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 +266 -80
- package/README.md +48 -20
- package/dist/bun/cli.d.ts.map +1 -1
- package/dist/bun/cli.js +4 -2
- package/dist/bun/cli.js.map +1 -1
- package/dist/bun/restore-sandbox-env.d.ts +13 -0
- package/dist/bun/restore-sandbox-env.d.ts.map +1 -0
- package/dist/bun/restore-sandbox-env.js +32 -0
- package/dist/bun/restore-sandbox-env.js.map +1 -0
- package/dist/cli/args.d.ts +2 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +34 -22
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js +2 -1
- package/dist/cli/list-models.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +9 -4
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +16 -8
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +238 -66
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +10 -0
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +14 -0
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +2 -1
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +1 -0
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +25 -26
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +1042 -1116
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/agent-types.d.ts +58 -0
- package/dist/core/agent-types.d.ts.map +1 -0
- package/dist/core/agent-types.js +203 -0
- package/dist/core/agent-types.js.map +1 -0
- package/dist/core/auth-guidance.d.ts +5 -0
- package/dist/core/auth-guidance.d.ts.map +1 -0
- package/dist/core/auth-guidance.js +21 -0
- package/dist/core/auth-guidance.js.map +1 -0
- package/dist/core/auth-storage.d.ts +9 -0
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +20 -1
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +9 -6
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +0 -1
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
- package/dist/core/export-html/ansi-to-html.js +1 -1
- package/dist/core/export-html/ansi-to-html.js.map +1 -1
- package/dist/core/export-html/template.css +53 -4
- package/dist/core/export-html/template.js +84 -20
- package/dist/core/export-html/tool-renderer.d.ts +0 -6
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
- package/dist/core/export-html/tool-renderer.js +15 -2
- package/dist/core/export-html/tool-renderer.js.map +1 -1
- package/dist/core/extensions/channel-factory.d.ts +13 -0
- package/dist/core/extensions/channel-factory.d.ts.map +1 -0
- package/dist/core/extensions/channel-factory.js +19 -0
- package/dist/core/extensions/channel-factory.js.map +1 -0
- package/dist/core/extensions/channel-registry.d.ts +28 -0
- package/dist/core/extensions/channel-registry.d.ts.map +1 -0
- package/dist/core/extensions/channel-registry.js +12 -0
- package/dist/core/extensions/channel-registry.js.map +1 -0
- package/dist/core/extensions/index.d.ts +4 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js +1 -0
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts +0 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +49 -137
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +24 -20
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +128 -253
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/server-channel.d.ts +8 -8
- package/dist/core/extensions/server-channel.d.ts.map +1 -1
- package/dist/core/extensions/server-channel.js.map +1 -1
- package/dist/core/extensions/types.d.ts +88 -60
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js +10 -0
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/file-store/file-snapshot-manager.d.ts +95 -0
- package/dist/core/file-store/file-snapshot-manager.d.ts.map +1 -0
- package/dist/core/file-store/file-snapshot-manager.js +508 -0
- package/dist/core/file-store/file-snapshot-manager.js.map +1 -0
- package/dist/core/file-store/index.d.ts +5 -0
- package/dist/core/file-store/index.d.ts.map +1 -0
- package/dist/core/file-store/index.js +3 -0
- package/dist/core/file-store/index.js.map +1 -0
- package/dist/core/messages.d.ts +10 -2
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/messages.js +23 -6
- package/dist/core/messages.js.map +1 -1
- package/dist/core/model-registry.d.ts +19 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +97 -16
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +24 -15
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/package-manager.d.ts +1 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +61 -35
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/provider-display-names.d.ts +2 -0
- package/dist/core/provider-display-names.d.ts.map +1 -0
- package/dist/core/provider-display-names.js +32 -0
- package/dist/core/provider-display-names.js.map +1 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +9 -21
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sdk.d.ts +9 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +39 -18
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts +27 -17
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +133 -47
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +21 -3
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +51 -6
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +3 -8
- package/dist/core/skills.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +4 -3
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/tools/bash.d.ts +0 -2
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +108 -154
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +3 -2
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +4 -3
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +1 -1
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +1 -1
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/output-accumulator.d.ts +50 -0
- package/dist/core/tools/output-accumulator.d.ts.map +1 -0
- package/dist/core/tools/output-accumulator.js +178 -0
- package/dist/core/tools/output-accumulator.js.map +1 -0
- package/dist/core/tools/output-collector.d.ts +35 -0
- package/dist/core/tools/output-collector.d.ts.map +1 -0
- package/dist/core/tools/output-collector.js +79 -0
- package/dist/core/tools/output-collector.js.map +1 -0
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +70 -13
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/spawn-managed.d.ts +18 -0
- package/dist/core/tools/spawn-managed.d.ts.map +1 -0
- package/dist/core/tools/spawn-managed.js +52 -0
- package/dist/core/tools/spawn-managed.js.map +1 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +17 -39
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts +1 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +3 -3
- package/dist/migrations.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +3 -1
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/extension-selector.d.ts +1 -4
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-selector.js +14 -56
- package/dist/modes/interactive/components/extension-selector.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts +5 -1
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +19 -4
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +1 -1
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts +18 -6
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +93 -25
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +3 -7
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +5 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +53 -1
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +20 -4
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +423 -186
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/dark.json +1 -1
- package/dist/modes/interactive/theme/light.json +1 -1
- package/dist/modes/print-mode.d.ts +3 -0
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +62 -19
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +80 -60
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +108 -93
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +106 -0
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +115 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +238 -12
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/utils/child-process.d.ts +1 -0
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/child-process.js +8 -0
- package/dist/utils/child-process.js.map +1 -1
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js +2 -2
- package/dist/utils/clipboard-image.js.map +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +84 -45
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/paths.d.ts +9 -0
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +31 -0
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/pi-user-agent.d.ts +2 -0
- package/dist/utils/pi-user-agent.d.ts.map +1 -0
- package/dist/utils/pi-user-agent.js +5 -0
- package/dist/utils/pi-user-agent.js.map +1 -0
- package/dist/utils/structured-output.d.ts +10 -0
- package/dist/utils/structured-output.d.ts.map +1 -0
- package/dist/utils/structured-output.js +57 -0
- package/dist/utils/structured-output.js.map +1 -0
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +6 -2
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/version-check.d.ts +14 -0
- package/dist/utils/version-check.d.ts.map +1 -0
- package/dist/utils/version-check.js +77 -0
- package/dist/utils/version-check.js.map +1 -0
- package/docs/compaction.md +14 -14
- package/docs/custom-provider.md +40 -31
- package/docs/development.md +1 -1
- package/docs/docs.json +148 -0
- package/docs/extensions.md +116 -56
- package/docs/index.md +70 -0
- package/docs/json.md +4 -4
- package/docs/models.md +150 -3
- package/docs/packages.md +10 -5
- package/docs/providers.md +62 -17
- package/docs/quickstart.md +142 -0
- package/docs/rollback-architecture.md +693 -0
- package/docs/rollback-test-cases.md +412 -0
- package/docs/rpc.md +1 -1
- package/docs/sdk.md +26 -26
- package/docs/{session.md → session-format.md} +6 -6
- package/docs/sessions.md +137 -0
- package/docs/settings.md +52 -9
- package/docs/termux.md +1 -1
- package/docs/themes.md +2 -2
- package/docs/tui.md +20 -20
- package/docs/usage.md +277 -0
- package/examples/extensions/README.md +2 -4
- package/examples/extensions/border-status-editor.ts +150 -0
- package/examples/extensions/commands.ts +2 -2
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/custom-provider-qwen-cli/package.json +1 -1
- package/examples/extensions/dynamic-resources/dynamic.json +1 -1
- package/examples/extensions/git-checkpoint.ts +1 -1
- package/examples/extensions/handoff.ts +49 -11
- package/examples/extensions/plan-mode/index.ts +1 -1
- package/examples/extensions/sandbox/package-lock.json +5 -5
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/subagent/agents.ts +126 -0
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/sdk/README.md +2 -2
- package/package.json +7 -15
- package/docs/tree.md +0 -233
- package/examples/extensions/antigravity-image-gen.ts +0 -418
package/docs/extensions.md
CHANGED
|
@@ -42,6 +42,7 @@ See [examples/extensions/](../examples/extensions/) for working implementations.
|
|
|
42
42
|
- [Resource Events](#resource-events)
|
|
43
43
|
- [Session Events](#session-events)
|
|
44
44
|
- [Agent Events](#agent-events)
|
|
45
|
+
- [Model Events](#model-events)
|
|
45
46
|
- [Tool Events](#tool-events)
|
|
46
47
|
- [UI Interception Events](#ui-interception-events)
|
|
47
48
|
- [ExtensionContext](#extensioncontext)
|
|
@@ -59,7 +60,7 @@ See [examples/extensions/](../examples/extensions/) for working implementations.
|
|
|
59
60
|
Create `~/.pi/agent/extensions/my-extension.ts`:
|
|
60
61
|
|
|
61
62
|
```typescript
|
|
62
|
-
import type { ExtensionAPI } from "@
|
|
63
|
+
import type { ExtensionAPI } from "@dyyz1993/pi-coding-agent";
|
|
63
64
|
import { Type } from "typebox";
|
|
64
65
|
|
|
65
66
|
export default function (pi: ExtensionAPI) {
|
|
@@ -141,14 +142,14 @@ To share extensions via npm or git as pi packages, see [packages.md](packages.md
|
|
|
141
142
|
|
|
142
143
|
| Package | Purpose |
|
|
143
144
|
|---------|---------|
|
|
144
|
-
| `@
|
|
145
|
+
| `@dyyz1993/pi-coding-agent` | Extension types (`ExtensionAPI`, `ExtensionContext`, events) |
|
|
145
146
|
| `typebox` | Schema definitions for tool parameters |
|
|
146
|
-
| `@
|
|
147
|
-
| `@
|
|
147
|
+
| `@dyyz1993/pi-ai` | AI utilities (`StringEnum` for Google-compatible enums) |
|
|
148
|
+
| `@dyyz1993/pi-tui` | TUI components for custom rendering |
|
|
148
149
|
|
|
149
150
|
npm dependencies work too. Add a `package.json` next to your extension (or in a parent directory), run `npm install`, and imports from `node_modules/` are resolved automatically.
|
|
150
151
|
|
|
151
|
-
For distributed pi packages installed with `pi install` (npm or git), runtime deps must be in `dependencies`. Package installation uses production installs (`npm install --omit=dev`), so `devDependencies` are not available at runtime.
|
|
152
|
+
For distributed pi packages installed with `pi install` (npm or git), runtime deps must be in `dependencies`. Package installation uses production installs (`npm install --omit=dev`) by default, so `devDependencies` are not available at runtime; when `npmCommand` is configured, git packages use plain `install` for compatibility with wrappers.
|
|
152
153
|
|
|
153
154
|
Node.js built-ins (`node:fs`, `node:path`, etc.) are also available.
|
|
154
155
|
|
|
@@ -157,7 +158,7 @@ Node.js built-ins (`node:fs`, `node:path`, etc.) are also available.
|
|
|
157
158
|
An extension exports a default factory function that receives `ExtensionAPI`. The factory can be synchronous or asynchronous:
|
|
158
159
|
|
|
159
160
|
```typescript
|
|
160
|
-
import type { ExtensionAPI } from "@
|
|
161
|
+
import type { ExtensionAPI } from "@dyyz1993/pi-coding-agent";
|
|
161
162
|
|
|
162
163
|
export default function (pi: ExtensionAPI) {
|
|
163
164
|
// Subscribe to events
|
|
@@ -186,7 +187,7 @@ If the factory returns a `Promise`, pi awaits it before continuing startup. That
|
|
|
186
187
|
Use an async factory for one-time startup work such as fetching remote configuration or dynamically discovering available models.
|
|
187
188
|
|
|
188
189
|
```typescript
|
|
189
|
-
import type { ExtensionAPI } from "@
|
|
190
|
+
import type { ExtensionAPI } from "@dyyz1993/pi-coding-agent";
|
|
190
191
|
|
|
191
192
|
export default async function (pi: ExtensionAPI) {
|
|
192
193
|
const response = await fetch("http://localhost:1234/v1/models");
|
|
@@ -326,8 +327,12 @@ user sends another prompt ◄─────────────────
|
|
|
326
327
|
└─► session_tree
|
|
327
328
|
|
|
328
329
|
/model or Ctrl+P (model selection/cycling)
|
|
330
|
+
├─► thinking_level_select (if model change changes/clamps thinking level)
|
|
329
331
|
└─► model_select
|
|
330
332
|
|
|
333
|
+
thinking level changes (settings, keybinding, pi.setThinkingLevel())
|
|
334
|
+
└─► thinking_level_select
|
|
335
|
+
|
|
331
336
|
exit (Ctrl+C, Ctrl+D, SIGHUP, SIGTERM)
|
|
332
337
|
└─► session_shutdown
|
|
333
338
|
```
|
|
@@ -353,7 +358,7 @@ pi.on("resources_discover", async (event, _ctx) => {
|
|
|
353
358
|
|
|
354
359
|
### Session Events
|
|
355
360
|
|
|
356
|
-
See [
|
|
361
|
+
See [Session Format](session-format.md) for session storage internals and the SessionManager API.
|
|
357
362
|
|
|
358
363
|
#### session_start
|
|
359
364
|
|
|
@@ -432,7 +437,7 @@ pi.on("session_compact", async (event, ctx) => {
|
|
|
432
437
|
|
|
433
438
|
#### session_before_tree / session_tree
|
|
434
439
|
|
|
435
|
-
Fired on `/tree` navigation. See [
|
|
440
|
+
Fired on `/tree` navigation. See [Sessions](sessions.md) for tree navigation concepts.
|
|
436
441
|
|
|
437
442
|
```typescript
|
|
438
443
|
pi.on("session_before_tree", async (event, ctx) => {
|
|
@@ -542,6 +547,7 @@ Fired for message lifecycle updates.
|
|
|
542
547
|
|
|
543
548
|
- `message_start` and `message_end` fire for user, assistant, and toolResult messages.
|
|
544
549
|
- `message_update` fires for assistant streaming updates.
|
|
550
|
+
- `message_end` handlers can return `{ message }` to replace the finalized message. The replacement must keep the same `role`.
|
|
545
551
|
|
|
546
552
|
```typescript
|
|
547
553
|
pi.on("message_start", async (event, ctx) => {
|
|
@@ -554,7 +560,20 @@ pi.on("message_update", async (event, ctx) => {
|
|
|
554
560
|
});
|
|
555
561
|
|
|
556
562
|
pi.on("message_end", async (event, ctx) => {
|
|
557
|
-
|
|
563
|
+
if (event.message.role !== "assistant") return;
|
|
564
|
+
|
|
565
|
+
return {
|
|
566
|
+
message: {
|
|
567
|
+
...event.message,
|
|
568
|
+
usage: {
|
|
569
|
+
...event.message.usage,
|
|
570
|
+
cost: {
|
|
571
|
+
...event.message.usage.cost,
|
|
572
|
+
total: 0.123,
|
|
573
|
+
},
|
|
574
|
+
},
|
|
575
|
+
},
|
|
576
|
+
};
|
|
558
577
|
});
|
|
559
578
|
```
|
|
560
579
|
|
|
@@ -584,7 +603,7 @@ pi.on("tool_execution_end", async (event, ctx) => {
|
|
|
584
603
|
|
|
585
604
|
#### context
|
|
586
605
|
|
|
587
|
-
Fired before each LLM call. Modify messages non-destructively. See [
|
|
606
|
+
Fired before each LLM call. Modify messages non-destructively. See [Session Format](session-format.md) for message types.
|
|
588
607
|
|
|
589
608
|
```typescript
|
|
590
609
|
pi.on("context", async (event, ctx) => {
|
|
@@ -650,6 +669,21 @@ pi.on("model_select", async (event, ctx) => {
|
|
|
650
669
|
|
|
651
670
|
Use this to update UI elements (status bars, footers) or perform model-specific initialization when the active model changes.
|
|
652
671
|
|
|
672
|
+
#### thinking_level_select
|
|
673
|
+
|
|
674
|
+
Fired when the thinking level changes. This is notification-only; handler return values are ignored.
|
|
675
|
+
|
|
676
|
+
```typescript
|
|
677
|
+
pi.on("thinking_level_select", async (event, ctx) => {
|
|
678
|
+
// event.level - newly selected thinking level
|
|
679
|
+
// event.previousLevel - previous thinking level
|
|
680
|
+
|
|
681
|
+
ctx.ui.setStatus("thinking", `thinking: ${event.level}`);
|
|
682
|
+
});
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
Use this to update extension UI when `pi.setThinkingLevel()`, model changes, or built-in thinking-level controls change the active thinking level.
|
|
686
|
+
|
|
653
687
|
### Tool Events
|
|
654
688
|
|
|
655
689
|
#### tool_call
|
|
@@ -669,7 +703,7 @@ Behavior guarantees:
|
|
|
669
703
|
- Return values from `tool_call` only control blocking via `{ block: true, reason?: string }`
|
|
670
704
|
|
|
671
705
|
```typescript
|
|
672
|
-
import { isToolCallEventType } from "@
|
|
706
|
+
import { isToolCallEventType } from "@dyyz1993/pi-coding-agent";
|
|
673
707
|
|
|
674
708
|
pi.on("tool_call", async (event, ctx) => {
|
|
675
709
|
// event.toolName - "bash", "read", "write", "edit", etc.
|
|
@@ -705,7 +739,7 @@ export type MyToolInput = Static<typeof myToolSchema>;
|
|
|
705
739
|
Use `isToolCallEventType` with explicit type parameters:
|
|
706
740
|
|
|
707
741
|
```typescript
|
|
708
|
-
import { isToolCallEventType } from "@
|
|
742
|
+
import { isToolCallEventType } from "@dyyz1993/pi-coding-agent";
|
|
709
743
|
import type { MyToolInput } from "my-extension";
|
|
710
744
|
|
|
711
745
|
pi.on("tool_call", (event) => {
|
|
@@ -729,7 +763,7 @@ In parallel tool mode, `tool_result` and `tool_execution_end` may interleave in
|
|
|
729
763
|
Use `ctx.signal` for nested async work inside the handler. This lets Esc cancel model calls, `fetch()`, and other abort-aware operations started by the extension.
|
|
730
764
|
|
|
731
765
|
```typescript
|
|
732
|
-
import { isBashToolResult } from "@
|
|
766
|
+
import { isBashToolResult } from "@dyyz1993/pi-coding-agent";
|
|
733
767
|
|
|
734
768
|
pi.on("tool_result", async (event, ctx) => {
|
|
735
769
|
// event.toolName, event.toolCallId, event.input
|
|
@@ -757,7 +791,7 @@ pi.on("tool_result", async (event, ctx) => {
|
|
|
757
791
|
Fired when user executes `!` or `!!` commands. **Can intercept.**
|
|
758
792
|
|
|
759
793
|
```typescript
|
|
760
|
-
import { createLocalBashOperations } from "@
|
|
794
|
+
import { createLocalBashOperations } from "@dyyz1993/pi-coding-agent";
|
|
761
795
|
|
|
762
796
|
pi.on("user_bash", (event, ctx) => {
|
|
763
797
|
// event.command - the bash command
|
|
@@ -937,7 +971,7 @@ Current working directory.
|
|
|
937
971
|
|
|
938
972
|
### ctx.sessionManager
|
|
939
973
|
|
|
940
|
-
Read-only access to session state. See [
|
|
974
|
+
Read-only access to session state. See [Session Format](session-format.md) for the full SessionManager API and entry types.
|
|
941
975
|
|
|
942
976
|
For `tool_call`, this state is synchronized through the current assistant message before handlers run. In parallel tool execution mode it is still not guaranteed to include sibling tool results from the same assistant message.
|
|
943
977
|
|
|
@@ -1164,14 +1198,19 @@ Options:
|
|
|
1164
1198
|
Fork from a specific entry, creating a new session file:
|
|
1165
1199
|
|
|
1166
1200
|
```typescript
|
|
1167
|
-
const result = await ctx.fork("entry-id-123"
|
|
1168
|
-
|
|
1169
|
-
|
|
1201
|
+
const result = await ctx.fork("entry-id-123", {
|
|
1202
|
+
withSession: async (ctx) => {
|
|
1203
|
+
// Use only the replacement-session ctx here.
|
|
1204
|
+
ctx.ui.notify("Now in the forked session", "info");
|
|
1205
|
+
},
|
|
1206
|
+
});
|
|
1207
|
+
if (result.cancelled) {
|
|
1208
|
+
// An extension cancelled the fork
|
|
1170
1209
|
}
|
|
1171
1210
|
|
|
1172
1211
|
const cloneResult = await ctx.fork("entry-id-456", { position: "at" });
|
|
1173
|
-
if (
|
|
1174
|
-
//
|
|
1212
|
+
if (cloneResult.cancelled) {
|
|
1213
|
+
// An extension cancelled the clone
|
|
1175
1214
|
}
|
|
1176
1215
|
```
|
|
1177
1216
|
|
|
@@ -1220,7 +1259,7 @@ Options:
|
|
|
1220
1259
|
To discover available sessions, use the static `SessionManager.list()` or `SessionManager.listAll()` methods:
|
|
1221
1260
|
|
|
1222
1261
|
```typescript
|
|
1223
|
-
import { SessionManager } from "@
|
|
1262
|
+
import { SessionManager } from "@dyyz1993/pi-coding-agent";
|
|
1224
1263
|
|
|
1225
1264
|
pi.registerCommand("switch", {
|
|
1226
1265
|
description: "Switch to another session",
|
|
@@ -1232,7 +1271,11 @@ pi.registerCommand("switch", {
|
|
|
1232
1271
|
sessions.map(s => s.file),
|
|
1233
1272
|
);
|
|
1234
1273
|
if (choice) {
|
|
1235
|
-
await ctx.switchSession(choice
|
|
1274
|
+
await ctx.switchSession(choice, {
|
|
1275
|
+
withSession: async (ctx) => {
|
|
1276
|
+
ctx.ui.notify("Switched session", "info");
|
|
1277
|
+
},
|
|
1278
|
+
});
|
|
1236
1279
|
}
|
|
1237
1280
|
},
|
|
1238
1281
|
});
|
|
@@ -1310,7 +1353,7 @@ Tools run with `ExtensionContext`, so they cannot call `ctx.reload()` directly.
|
|
|
1310
1353
|
Example tool the LLM can call to trigger reload:
|
|
1311
1354
|
|
|
1312
1355
|
```typescript
|
|
1313
|
-
import type { ExtensionAPI } from "@
|
|
1356
|
+
import type { ExtensionAPI } from "@dyyz1993/pi-coding-agent";
|
|
1314
1357
|
import { Type } from "typebox";
|
|
1315
1358
|
|
|
1316
1359
|
export default function (pi: ExtensionAPI) {
|
|
@@ -1359,7 +1402,7 @@ See [dynamic-tools.ts](../examples/extensions/dynamic-tools.ts) for a full examp
|
|
|
1359
1402
|
|
|
1360
1403
|
```typescript
|
|
1361
1404
|
import { Type } from "typebox";
|
|
1362
|
-
import { StringEnum } from "@
|
|
1405
|
+
import { StringEnum } from "@dyyz1993/pi-ai";
|
|
1363
1406
|
|
|
1364
1407
|
pi.registerTool({
|
|
1365
1408
|
name: "my_tool",
|
|
@@ -1549,7 +1592,7 @@ pi.registerCommand("stats", {
|
|
|
1549
1592
|
Optional: add argument auto-completion for `/command ...`:
|
|
1550
1593
|
|
|
1551
1594
|
```typescript
|
|
1552
|
-
import type { AutocompleteItem } from "@
|
|
1595
|
+
import type { AutocompleteItem } from "@dyyz1993/pi-tui";
|
|
1553
1596
|
|
|
1554
1597
|
pi.registerCommand("deploy", {
|
|
1555
1598
|
description: "Deploy to an environment",
|
|
@@ -1627,7 +1670,7 @@ pi.registerFlag("plan", {
|
|
|
1627
1670
|
});
|
|
1628
1671
|
|
|
1629
1672
|
// Check value
|
|
1630
|
-
if (pi.getFlag("
|
|
1673
|
+
if (pi.getFlag("plan")) {
|
|
1631
1674
|
// Plan mode enabled
|
|
1632
1675
|
}
|
|
1633
1676
|
```
|
|
@@ -1683,7 +1726,7 @@ if (model) {
|
|
|
1683
1726
|
|
|
1684
1727
|
### pi.getThinkingLevel() / pi.setThinkingLevel(level)
|
|
1685
1728
|
|
|
1686
|
-
Get or set the thinking level. Level is clamped to model capabilities (non-reasoning models always use "off").
|
|
1729
|
+
Get or set the thinking level. Level is clamped to model capabilities (non-reasoning models always use "off"). Changes emit `thinking_level_select`.
|
|
1687
1730
|
|
|
1688
1731
|
```typescript
|
|
1689
1732
|
const current = pi.getThinkingLevel(); // "off" | "minimal" | "low" | "medium" | "high" | "xhigh"
|
|
@@ -1710,6 +1753,7 @@ If you need to discover models from a remote endpoint, prefer an async extension
|
|
|
1710
1753
|
```typescript
|
|
1711
1754
|
// Register a new provider with custom models
|
|
1712
1755
|
pi.registerProvider("my-proxy", {
|
|
1756
|
+
name: "My Proxy",
|
|
1713
1757
|
baseUrl: "https://proxy.example.com",
|
|
1714
1758
|
apiKey: "PROXY_API_KEY", // env var name or literal
|
|
1715
1759
|
api: "anthropic-messages",
|
|
@@ -1756,12 +1800,13 @@ pi.registerProvider("corporate-ai", {
|
|
|
1756
1800
|
```
|
|
1757
1801
|
|
|
1758
1802
|
**Config options:**
|
|
1803
|
+
- `name` - Display name for the provider in UI such as `/login`.
|
|
1759
1804
|
- `baseUrl` - API endpoint URL. Required when defining models.
|
|
1760
1805
|
- `apiKey` - API key or environment variable name. Required when defining models (unless `oauth` provided).
|
|
1761
1806
|
- `api` - API type: `"anthropic-messages"`, `"openai-completions"`, `"openai-responses"`, etc.
|
|
1762
1807
|
- `headers` - Custom headers to include in requests.
|
|
1763
1808
|
- `authHeader` - If true, adds `Authorization: Bearer` header automatically.
|
|
1764
|
-
- `models` - Array of model definitions. If provided, replaces all existing models for this provider.
|
|
1809
|
+
- `models` - Array of model definitions. If provided, replaces all existing models for this provider. Model definitions can set `baseUrl` to override the provider endpoint for that model.
|
|
1765
1810
|
- `oauth` - OAuth provider config for `/login` support. When provided, the provider appears in the login menu.
|
|
1766
1811
|
- `streamSimple` - Custom streaming implementation for non-standard APIs.
|
|
1767
1812
|
|
|
@@ -1837,7 +1882,7 @@ Pass the real target file path to `withFileMutationQueue()`, not the raw user ar
|
|
|
1837
1882
|
Queue the entire mutation window on that target path. That includes read-modify-write logic, not just the final write.
|
|
1838
1883
|
|
|
1839
1884
|
```typescript
|
|
1840
|
-
import { withFileMutationQueue } from "@
|
|
1885
|
+
import { withFileMutationQueue } from "@dyyz1993/pi-coding-agent";
|
|
1841
1886
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
1842
1887
|
import { dirname, resolve } from "node:path";
|
|
1843
1888
|
|
|
@@ -1862,8 +1907,8 @@ async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
|
1862
1907
|
|
|
1863
1908
|
```typescript
|
|
1864
1909
|
import { Type } from "typebox";
|
|
1865
|
-
import { StringEnum } from "@
|
|
1866
|
-
import { Text } from "@
|
|
1910
|
+
import { StringEnum } from "@dyyz1993/pi-ai";
|
|
1911
|
+
import { Text } from "@dyyz1993/pi-tui";
|
|
1867
1912
|
|
|
1868
1913
|
pi.registerTool({
|
|
1869
1914
|
name: "my_tool",
|
|
@@ -1931,7 +1976,7 @@ async execute(toolCallId, params) {
|
|
|
1931
1976
|
}
|
|
1932
1977
|
```
|
|
1933
1978
|
|
|
1934
|
-
**Important:** Use `StringEnum` from `@
|
|
1979
|
+
**Important:** Use `StringEnum` from `@dyyz1993/pi-ai` for string enums. `Type.Union`/`Type.Literal` doesn't work with Google's API.
|
|
1935
1980
|
|
|
1936
1981
|
**Argument preparation:** `prepareArguments(args)` is optional. If defined, it runs before schema validation and before `execute()`. Use it to mimic an older accepted input shape when pi resumes an older session whose stored tool call arguments no longer match the current schema. Return the object you want validated against `parameters`. Keep the public schema strict. Do not add deprecated compatibility fields to `parameters` just to keep old resumed sessions working.
|
|
1937
1982
|
|
|
@@ -1989,10 +2034,10 @@ Extensions can override built-in tools (`read`, `bash`, `edit`, `write`, `grep`,
|
|
|
1989
2034
|
pi -e ./tool-override.ts
|
|
1990
2035
|
```
|
|
1991
2036
|
|
|
1992
|
-
Alternatively, use `--no-tools` to start without any built-in tools:
|
|
2037
|
+
Alternatively, use `--no-builtin-tools` to start without any built-in tools while keeping extension tools enabled:
|
|
1993
2038
|
```bash
|
|
1994
2039
|
# No built-in tools, only extension tools
|
|
1995
|
-
pi --no-tools -e ./my-extension.ts
|
|
2040
|
+
pi --no-builtin-tools -e ./my-extension.ts
|
|
1996
2041
|
```
|
|
1997
2042
|
|
|
1998
2043
|
See [examples/extensions/tool-override.ts](../examples/extensions/tool-override.ts) for a complete example that overrides `read` with logging and access control.
|
|
@@ -2004,20 +2049,20 @@ See [examples/extensions/tool-override.ts](../examples/extensions/tool-override.
|
|
|
2004
2049
|
**Your implementation must match the exact result shape**, including the `details` type. The UI and session logic depend on these shapes for rendering and state tracking.
|
|
2005
2050
|
|
|
2006
2051
|
Built-in tool implementations:
|
|
2007
|
-
- [read.ts](https://github.com/
|
|
2008
|
-
- [bash.ts](https://github.com/
|
|
2009
|
-
- [edit.ts](https://github.com/
|
|
2010
|
-
- [write.ts](https://github.com/
|
|
2011
|
-
- [grep.ts](https://github.com/
|
|
2012
|
-
- [find.ts](https://github.com/
|
|
2013
|
-
- [ls.ts](https://github.com/
|
|
2052
|
+
- [read.ts](https://github.com/dyyz1993/pi-mono/blob/main/packages/coding-agent/src/core/tools/read.ts) - `ReadToolDetails`
|
|
2053
|
+
- [bash.ts](https://github.com/dyyz1993/pi-mono/blob/main/packages/coding-agent/src/core/tools/bash.ts) - `BashToolDetails`
|
|
2054
|
+
- [edit.ts](https://github.com/dyyz1993/pi-mono/blob/main/packages/coding-agent/src/core/tools/edit.ts)
|
|
2055
|
+
- [write.ts](https://github.com/dyyz1993/pi-mono/blob/main/packages/coding-agent/src/core/tools/write.ts)
|
|
2056
|
+
- [grep.ts](https://github.com/dyyz1993/pi-mono/blob/main/packages/coding-agent/src/core/tools/grep.ts) - `GrepToolDetails`
|
|
2057
|
+
- [find.ts](https://github.com/dyyz1993/pi-mono/blob/main/packages/coding-agent/src/core/tools/find.ts) - `FindToolDetails`
|
|
2058
|
+
- [ls.ts](https://github.com/dyyz1993/pi-mono/blob/main/packages/coding-agent/src/core/tools/ls.ts) - `LsToolDetails`
|
|
2014
2059
|
|
|
2015
2060
|
### Remote Execution
|
|
2016
2061
|
|
|
2017
2062
|
Built-in tools support pluggable operations for delegating to remote systems (SSH, containers, etc.):
|
|
2018
2063
|
|
|
2019
2064
|
```typescript
|
|
2020
|
-
import { createReadTool, createBashTool, type ReadOperations } from "@
|
|
2065
|
+
import { createReadTool, createBashTool, type ReadOperations } from "@dyyz1993/pi-coding-agent";
|
|
2021
2066
|
|
|
2022
2067
|
// Create tool with custom operations
|
|
2023
2068
|
const remoteRead = createReadTool(cwd, {
|
|
@@ -2048,7 +2093,7 @@ For `user_bash`, extensions can reuse pi's local shell backend via `createLocalB
|
|
|
2048
2093
|
The bash tool also supports a spawn hook to adjust the command, cwd, or env before execution:
|
|
2049
2094
|
|
|
2050
2095
|
```typescript
|
|
2051
|
-
import { createBashTool } from "@
|
|
2096
|
+
import { createBashTool } from "@dyyz1993/pi-coding-agent";
|
|
2052
2097
|
|
|
2053
2098
|
const bashTool = createBashTool(cwd, {
|
|
2054
2099
|
spawnHook: ({ command, cwd, env }) => ({
|
|
@@ -2078,7 +2123,7 @@ import {
|
|
|
2078
2123
|
formatSize, // Human-readable size (e.g., "50KB", "1.5MB")
|
|
2079
2124
|
DEFAULT_MAX_BYTES, // 50KB
|
|
2080
2125
|
DEFAULT_MAX_LINES, // 2000
|
|
2081
|
-
} from "@
|
|
2126
|
+
} from "@dyyz1993/pi-coding-agent";
|
|
2082
2127
|
|
|
2083
2128
|
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
2084
2129
|
const output = await runCommand();
|
|
@@ -2133,7 +2178,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
2133
2178
|
|
|
2134
2179
|
### Custom Rendering
|
|
2135
2180
|
|
|
2136
|
-
Tools can provide `renderCall` and `renderResult` for custom TUI display. See [tui.md](tui.md) for the full component API and [tool-execution.ts](https://github.com/
|
|
2181
|
+
Tools can provide `renderCall` and `renderResult` for custom TUI display. See [tui.md](tui.md) for the full component API and [tool-execution.ts](https://github.com/dyyz1993/pi-mono/blob/main/packages/coding-agent/src/modes/interactive/components/tool-execution.ts) for how tool rows are composed.
|
|
2137
2182
|
|
|
2138
2183
|
By default, tool output is wrapped in a `Box` that handles padding and background. A defined `renderCall` or `renderResult` must return a `Component`. If a slot renderer is not defined, `tool-execution.ts` uses fallback rendering for that slot.
|
|
2139
2184
|
|
|
@@ -2169,7 +2214,7 @@ Use `context.state` for cross-slot shared state. Keep slot-local caches on the r
|
|
|
2169
2214
|
Renders the tool call or header:
|
|
2170
2215
|
|
|
2171
2216
|
```typescript
|
|
2172
|
-
import { Text } from "@
|
|
2217
|
+
import { Text } from "@dyyz1993/pi-tui";
|
|
2173
2218
|
|
|
2174
2219
|
renderCall(args, theme, context) {
|
|
2175
2220
|
const text = (context.lastComponent as Text | undefined) ?? new Text("", 0, 0);
|
|
@@ -2214,7 +2259,7 @@ If a slot intentionally has no visible content, return an empty `Component` such
|
|
|
2214
2259
|
Use `keyHint()` to display keybinding hints that respect the active keybinding configuration:
|
|
2215
2260
|
|
|
2216
2261
|
```typescript
|
|
2217
|
-
import { keyHint } from "@
|
|
2262
|
+
import { keyHint } from "@dyyz1993/pi-coding-agent";
|
|
2218
2263
|
|
|
2219
2264
|
renderResult(result, { expanded }, theme, context) {
|
|
2220
2265
|
let text = theme.fg("success", "✓ Done");
|
|
@@ -2265,7 +2310,7 @@ Extensions can interact with users via `ctx.ui` methods and customize how messag
|
|
|
2265
2310
|
- Async operations with cancel (BorderedLoader)
|
|
2266
2311
|
- Settings toggles (SettingsList)
|
|
2267
2312
|
- Status indicators (setStatus)
|
|
2268
|
-
- Working message and indicator during streaming (`setWorkingMessage`, `setWorkingIndicator`)
|
|
2313
|
+
- Working message, visibility, and indicator during streaming (`setWorkingMessage`, `setWorkingVisible`, `setWorkingIndicator`)
|
|
2269
2314
|
- Widgets above/below editor (setWidget)
|
|
2270
2315
|
- Autocomplete providers layered on top of built-in slash/path completion (addAutocompleteProvider)
|
|
2271
2316
|
- Custom footers (setFooter)
|
|
@@ -2347,9 +2392,11 @@ See [examples/extensions/timed-confirm.ts](../examples/extensions/timed-confirm.
|
|
|
2347
2392
|
ctx.ui.setStatus("my-ext", "Processing...");
|
|
2348
2393
|
ctx.ui.setStatus("my-ext", undefined); // Clear
|
|
2349
2394
|
|
|
2350
|
-
// Working
|
|
2395
|
+
// Working loader (shown during streaming)
|
|
2351
2396
|
ctx.ui.setWorkingMessage("Thinking deeply...");
|
|
2352
2397
|
ctx.ui.setWorkingMessage(); // Restore default
|
|
2398
|
+
ctx.ui.setWorkingVisible(false); // Hide the built-in working loader row entirely
|
|
2399
|
+
ctx.ui.setWorkingVisible(true); // Show the built-in working loader row
|
|
2353
2400
|
|
|
2354
2401
|
// Working indicator (shown during streaming)
|
|
2355
2402
|
ctx.ui.setWorkingIndicator({ frames: [ctx.ui.theme.fg("accent", "●")] }); // Static dot
|
|
@@ -2418,6 +2465,10 @@ ctx.ui.setToolsExpanded(wasExpanded);
|
|
|
2418
2465
|
|
|
2419
2466
|
// Custom editor (vim mode, emacs mode, etc.)
|
|
2420
2467
|
ctx.ui.setEditorComponent((tui, theme, keybindings) => new VimEditor(tui, theme, keybindings));
|
|
2468
|
+
const currentEditor = ctx.ui.getEditorComponent();
|
|
2469
|
+
ctx.ui.setEditorComponent((tui, theme, keybindings) =>
|
|
2470
|
+
new WrappedEditor(tui, theme, keybindings, currentEditor?.(tui, theme, keybindings))
|
|
2471
|
+
);
|
|
2421
2472
|
ctx.ui.setEditorComponent(undefined); // Restore default editor
|
|
2422
2473
|
|
|
2423
2474
|
// Theme management (see themes.md for creating themes)
|
|
@@ -2482,7 +2533,7 @@ See [github-issue-autocomplete.ts](../examples/extensions/github-issue-autocompl
|
|
|
2482
2533
|
For complex UI, use `ctx.ui.custom()`. This temporarily replaces the editor with your component until `done()` is called:
|
|
2483
2534
|
|
|
2484
2535
|
```typescript
|
|
2485
|
-
import { Text, Component } from "@
|
|
2536
|
+
import { Text, Component } from "@dyyz1993/pi-tui";
|
|
2486
2537
|
|
|
2487
2538
|
const result = await ctx.ui.custom<boolean>((tui, theme, keybindings, done) => {
|
|
2488
2539
|
const text = new Text("Press Enter to confirm, Escape to cancel", 1, 1);
|
|
@@ -2540,8 +2591,8 @@ See [tui.md](tui.md) for the full `OverlayOptions` API and [overlay-qa-tests.ts]
|
|
|
2540
2591
|
Replace the main input editor with a custom implementation (vim mode, emacs mode, etc.):
|
|
2541
2592
|
|
|
2542
2593
|
```typescript
|
|
2543
|
-
import { CustomEditor, type ExtensionAPI } from "@
|
|
2544
|
-
import { matchesKey } from "@
|
|
2594
|
+
import { CustomEditor, type ExtensionAPI } from "@dyyz1993/pi-coding-agent";
|
|
2595
|
+
import { matchesKey } from "@dyyz1993/pi-tui";
|
|
2545
2596
|
|
|
2546
2597
|
class VimEditor extends CustomEditor {
|
|
2547
2598
|
private mode: "normal" | "insert" = "insert";
|
|
@@ -2572,8 +2623,18 @@ export default function (pi: ExtensionAPI) {
|
|
|
2572
2623
|
- Extend `CustomEditor` (not base `Editor`) to get app keybindings (escape to abort, ctrl+d, model switching)
|
|
2573
2624
|
- Call `super.handleInput(data)` for keys you don't handle
|
|
2574
2625
|
- Factory receives `theme` and `keybindings` from the app
|
|
2626
|
+
- Use `ctx.ui.getEditorComponent()` before `setEditorComponent()` to wrap the previously configured custom editor
|
|
2575
2627
|
- Pass `undefined` to restore default: `ctx.ui.setEditorComponent(undefined)`
|
|
2576
2628
|
|
|
2629
|
+
To compose with another extension that already replaced the editor, capture the previous factory before setting yours:
|
|
2630
|
+
|
|
2631
|
+
```typescript
|
|
2632
|
+
const previous = ctx.ui.getEditorComponent();
|
|
2633
|
+
ctx.ui.setEditorComponent((tui, theme, keybindings) =>
|
|
2634
|
+
new MyEditor(tui, theme, keybindings, { base: previous?.(tui, theme, keybindings) })
|
|
2635
|
+
);
|
|
2636
|
+
```
|
|
2637
|
+
|
|
2577
2638
|
See [tui.md](tui.md) Pattern 7 for a complete example with mode indicator.
|
|
2578
2639
|
|
|
2579
2640
|
### Message Rendering
|
|
@@ -2581,7 +2642,7 @@ See [tui.md](tui.md) Pattern 7 for a complete example with mode indicator.
|
|
|
2581
2642
|
Register a custom renderer for messages with your `customType`:
|
|
2582
2643
|
|
|
2583
2644
|
```typescript
|
|
2584
|
-
import { Text } from "@
|
|
2645
|
+
import { Text } from "@dyyz1993/pi-tui";
|
|
2585
2646
|
|
|
2586
2647
|
pi.registerMessageRenderer("my-extension", (message, options, theme) => {
|
|
2587
2648
|
const { expanded } = options;
|
|
@@ -2630,7 +2691,7 @@ theme.strikethrough(text)
|
|
|
2630
2691
|
For syntax highlighting in custom tool renderers:
|
|
2631
2692
|
|
|
2632
2693
|
```typescript
|
|
2633
|
-
import { highlightCode, getLanguageFromPath } from "@
|
|
2694
|
+
import { highlightCode, getLanguageFromPath } from "@dyyz1993/pi-coding-agent";
|
|
2634
2695
|
|
|
2635
2696
|
// Highlight code with explicit language
|
|
2636
2697
|
const highlighted = highlightCode("const x = 1;", "typescript", theme);
|
|
@@ -2735,7 +2796,6 @@ All examples in [examples/extensions/](../examples/extensions/).
|
|
|
2735
2796
|
| `session-name.ts` | Name sessions for selector | `setSessionName`, `getSessionName` |
|
|
2736
2797
|
| `bookmark.ts` | Bookmark entries for /tree | `setLabel` |
|
|
2737
2798
|
| **Misc** |||
|
|
2738
|
-
| `antigravity-image-gen.ts` | Image generation tool | `registerTool`, Google Antigravity |
|
|
2739
2799
|
| `inline-bash.ts` | Inline bash in tool calls | `on("tool_call")` |
|
|
2740
2800
|
| `bash-spawn-hook.ts` | Adjust bash command, cwd, and env before execution | `createBashTool`, `spawnHook` |
|
|
2741
2801
|
| `with-deps/` | Extension with npm dependencies | Package structure with `package.json` |
|
package/docs/index.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Pi Documentation
|
|
2
|
+
|
|
3
|
+
Pi is a minimal terminal coding harness. It is designed to stay small at the core while being extended through TypeScript extensions, skills, prompt templates, themes, and pi packages.
|
|
4
|
+
|
|
5
|
+
## Quick start
|
|
6
|
+
|
|
7
|
+
On linux or mac you can install Pi with curl:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
curl -fsSL https://pi.dev/install.sh | sh
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or alternatively with npm:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install -g @dyyz1993/pi-coding-agent
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Then run it in a project directory:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pi
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Authenticate with `/login` for subscription providers, or set an API key such as `ANTHROPIC_API_KEY` before starting pi.
|
|
26
|
+
|
|
27
|
+
For the full first-run flow, see [Quickstart](quickstart.md).
|
|
28
|
+
|
|
29
|
+
## Start here
|
|
30
|
+
|
|
31
|
+
- [Quickstart](quickstart.md) - install, authenticate, and run a first session.
|
|
32
|
+
- [Using Pi](usage.md) - interactive mode, slash commands, context files, and CLI reference.
|
|
33
|
+
- [Providers](providers.md) - subscription and API-key setup for built-in providers.
|
|
34
|
+
- [Settings](settings.md) - global and project settings.
|
|
35
|
+
- [Keybindings](keybindings.md) - default shortcuts and custom keybindings.
|
|
36
|
+
- [Sessions](sessions.md) - session management, branching, and tree navigation.
|
|
37
|
+
- [Compaction](compaction.md) - context compaction and branch summarization.
|
|
38
|
+
|
|
39
|
+
## Customization
|
|
40
|
+
|
|
41
|
+
- [Extensions](extensions.md) - TypeScript modules for tools, commands, events, and custom UI.
|
|
42
|
+
- [Skills](skills.md) - Agent Skills for reusable on-demand capabilities.
|
|
43
|
+
- [Prompt templates](prompt-templates.md) - reusable prompts that expand from slash commands.
|
|
44
|
+
- [Themes](themes.md) - built-in and custom terminal themes.
|
|
45
|
+
- [Pi packages](packages.md) - bundle and share extensions, skills, prompts, and themes.
|
|
46
|
+
- [Custom models](models.md) - add model entries for supported provider APIs.
|
|
47
|
+
- [Custom providers](custom-provider.md) - implement custom APIs and OAuth flows.
|
|
48
|
+
|
|
49
|
+
## Programmatic usage
|
|
50
|
+
|
|
51
|
+
- [SDK](sdk.md) - embed pi in Node.js applications.
|
|
52
|
+
- [RPC mode](rpc.md) - integrate over stdin/stdout JSONL.
|
|
53
|
+
- [JSON event stream mode](json.md) - print mode with structured events.
|
|
54
|
+
- [TUI components](tui.md) - build custom terminal UI for extensions.
|
|
55
|
+
|
|
56
|
+
## Reference
|
|
57
|
+
|
|
58
|
+
- [Session format](session-format.md) - JSONL session file format, entry types, and SessionManager API.
|
|
59
|
+
|
|
60
|
+
## Platform setup
|
|
61
|
+
|
|
62
|
+
- [Windows](windows.md)
|
|
63
|
+
- [Termux on Android](termux.md)
|
|
64
|
+
- [tmux](tmux.md)
|
|
65
|
+
- [Terminal setup](terminal-setup.md)
|
|
66
|
+
- [Shell aliases](shell-aliases.md)
|
|
67
|
+
|
|
68
|
+
## Development
|
|
69
|
+
|
|
70
|
+
- [Development](development.md) - local setup, project structure, and debugging.
|
package/docs/json.md
CHANGED
|
@@ -8,7 +8,7 @@ Outputs all session events as JSON lines to stdout. Useful for integrating pi in
|
|
|
8
8
|
|
|
9
9
|
## Event Types
|
|
10
10
|
|
|
11
|
-
Events are defined in [`AgentSessionEvent`](https://github.com/
|
|
11
|
+
Events are defined in [`AgentSessionEvent`](https://github.com/dyyz1993/pi-mono/blob/main/packages/coding-agent/src/core/agent-session.ts#L102):
|
|
12
12
|
|
|
13
13
|
```typescript
|
|
14
14
|
type AgentSessionEvent =
|
|
@@ -22,7 +22,7 @@ type AgentSessionEvent =
|
|
|
22
22
|
|
|
23
23
|
`queue_update` emits the full pending steering and follow-up queues whenever they change. `compaction_start` and `compaction_end` cover both manual and automatic compaction.
|
|
24
24
|
|
|
25
|
-
Base events from [`AgentEvent`](https://github.com/
|
|
25
|
+
Base events from [`AgentEvent`](https://github.com/dyyz1993/pi-mono/blob/main/packages/agent/src/types.ts#L179):
|
|
26
26
|
|
|
27
27
|
```typescript
|
|
28
28
|
type AgentEvent =
|
|
@@ -44,12 +44,12 @@ type AgentEvent =
|
|
|
44
44
|
|
|
45
45
|
## Message Types
|
|
46
46
|
|
|
47
|
-
Base messages from [`packages/ai/src/types.ts`](https://github.com/
|
|
47
|
+
Base messages from [`packages/ai/src/types.ts`](https://github.com/dyyz1993/pi-mono/blob/main/packages/ai/src/types.ts#L134):
|
|
48
48
|
- `UserMessage` (line 134)
|
|
49
49
|
- `AssistantMessage` (line 140)
|
|
50
50
|
- `ToolResultMessage` (line 152)
|
|
51
51
|
|
|
52
|
-
Extended messages from [`packages/coding-agent/src/core/messages.ts`](https://github.com/
|
|
52
|
+
Extended messages from [`packages/coding-agent/src/core/messages.ts`](https://github.com/dyyz1993/pi-mono/blob/main/packages/coding-agent/src/core/messages.ts#L29):
|
|
53
53
|
- `BashExecutionMessage` (line 29)
|
|
54
54
|
- `CustomMessage` (line 46)
|
|
55
55
|
- `BranchSummaryMessage` (line 55)
|