@astralyn/pi 0.82.1 → 0.82.3
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 +27 -0
- package/LICENSE +21 -0
- package/README.md +71 -624
- package/dist/core/agent-session.d.ts +4 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +193 -43
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +6 -13
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/types.d.ts +2 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/model-resolver.d.ts +1 -0
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +13 -3
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +19 -1
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +3 -0
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts +7 -2
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts.map +1 -1
- package/dist/extensions/llama/provider.js +6 -0
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts +3 -1
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-message.js +10 -2
- package/dist/modes/interactive/components/custom-message.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 +22 -13
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +53 -28
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/docs/bundled/README.md +38 -0
- package/docs/bundled/extensions/README.md +18 -0
- package/docs/bundled/extensions/deepwiki.md +62 -0
- package/docs/bundled/extensions/question.md +48 -0
- package/docs/bundled/extensions/rewind.md +75 -0
- package/docs/bundled/extensions/router.md +126 -0
- package/docs/bundled/extensions/statusline.md +109 -0
- package/docs/bundled/extensions/subagent.md +95 -0
- package/docs/bundled/extensions/todo.md +28 -0
- package/docs/bundled/themes.md +51 -0
- package/docs/bundled/tool-presentation.md +85 -0
- package/docs/compaction.md +20 -14
- package/docs/containerization.md +1 -1
- package/docs/custom-provider.md +8 -8
- package/docs/docs.json +57 -9
- package/docs/extensions.md +14 -13
- package/docs/index.md +12 -7
- package/docs/json.md +4 -4
- package/docs/providers.md +1 -1
- package/docs/rpc.md +3 -9
- package/docs/session-format.md +5 -5
- package/docs/skills.md +1 -1
- package/docs/themes.md +4 -8
- package/docs/tui.md +1 -1
- package/examples/extensions/README.md +0 -1
- package/examples/extensions/custom-provider-anthropic/index.ts +4 -4
- package/examples/extensions/custom-provider-anthropic/package-lock.json +3 -3
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +2 -2
- package/examples/extensions/custom-provider-gitlab-duo/test.ts +1 -1
- package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
- package/examples/extensions/doom-overlay/doom/build.sh +0 -0
- package/examples/extensions/dynamic-resources/dynamic.json +1 -1
- package/examples/extensions/gondolin/index.ts +4 -6
- package/examples/extensions/message-renderer.ts +2 -2
- package/examples/extensions/overlay-qa-tests.ts +2 -2
- package/examples/extensions/project-trust.ts +2 -2
- package/examples/extensions/sandbox/package-lock.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/sdk/README.md +38 -44
- package/npm-shrinkwrap.json +3465 -624
- package/package.json +34 -18
- package/docs/development.md +0 -71
- package/examples/extensions/subagent/README.md +0 -175
- package/examples/extensions/subagent/agents/planner.md +0 -37
- package/examples/extensions/subagent/agents/reviewer.md +0 -35
- package/examples/extensions/subagent/agents/scout.md +0 -50
- package/examples/extensions/subagent/agents/worker.md +0 -24
- package/examples/extensions/subagent/agents.ts +0 -126
- package/examples/extensions/subagent/index.ts +0 -1009
- package/examples/extensions/subagent/prompts/implement-and-review.md +0 -10
- package/examples/extensions/subagent/prompts/implement.md +0 -10
- package/examples/extensions/subagent/prompts/scout-and-plan.md +0 -9
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Native tool presentation
|
|
2
|
+
|
|
3
|
+
The `@astralyn/pi` package uses Pi's native tool transcript presentation rather than replacing it with a separate `tools-view` extension.
|
|
4
|
+
|
|
5
|
+
## Visual language
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
● ToolName(args)
|
|
9
|
+
│ result
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
States use the same shell:
|
|
13
|
+
|
|
14
|
+
```text
|
|
15
|
+
● ToolName(args) completed call
|
|
16
|
+
● ToolName Working... pending call
|
|
17
|
+
● ToolName(args) failed call (error color)
|
|
18
|
+
│ result successful or failed output
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Implementation boundary
|
|
22
|
+
|
|
23
|
+
The native tool presentation owns:
|
|
24
|
+
|
|
25
|
+
- the default call/result shell;
|
|
26
|
+
- pending, success, and error states;
|
|
27
|
+
- call titles and generic argument summaries;
|
|
28
|
+
- collapsed and expanded result behavior;
|
|
29
|
+
- generic fallback rendering;
|
|
30
|
+
- image placement and conversion.
|
|
31
|
+
|
|
32
|
+
Built-in renderers remain responsible for semantic content such as file paths, syntax highlighting, search results, Diff previews, and command output. The outer shell is native so built-in tools, bundled extensions, and compatible third-party tools share the same presentation.
|
|
33
|
+
|
|
34
|
+
Consecutive tools may opt into a shared collapsed group through `toolGroup`. Built-in `read` and `find` calls use the `explore` group: their call rows render as one compact run with a single leading gap, while `Ctrl+O` restores each tool's complete call and result.
|
|
35
|
+
|
|
36
|
+
## Renderer inheritance
|
|
37
|
+
|
|
38
|
+
| Tool definition | Behavior |
|
|
39
|
+
|---|---|
|
|
40
|
+
| No `renderCall`/`renderResult` | Uses the package's native call and result fallback. |
|
|
41
|
+
| Custom renderer with the default shell | Uses the native shell around the custom content. |
|
|
42
|
+
| `renderShell: "self"` | Keeps complete ownership of the tool's layout. |
|
|
43
|
+
|
|
44
|
+
Built-in tool definitions are also used when an extension overrides only one renderer slot. A custom call renderer can inherit the built-in result renderer, and vice versa.
|
|
45
|
+
|
|
46
|
+
Renderer failures fall back to native generic output rather than breaking the transcript.
|
|
47
|
+
|
|
48
|
+
## Generic fallback
|
|
49
|
+
|
|
50
|
+
When no semantic renderer is available:
|
|
51
|
+
|
|
52
|
+
- arguments are serialized into a bounded one-line summary;
|
|
53
|
+
- output is collapsed to the most recent ten visual lines;
|
|
54
|
+
- `Ctrl+O` expands the complete output;
|
|
55
|
+
- historical tools that are no longer registered still receive the same shell;
|
|
56
|
+
- failed calls use the error-colored bullet while result details keep the result bar.
|
|
57
|
+
|
|
58
|
+
The fallback does not change tool schemas, execution logic, or result protocols.
|
|
59
|
+
|
|
60
|
+
## Built-in behavior preserved
|
|
61
|
+
|
|
62
|
+
The native path continues to preserve:
|
|
63
|
+
|
|
64
|
+
- `read`, `bash`, `grep`, `find`, `ls`, `write`, and `edit` semantics;
|
|
65
|
+
- faithful width-aware raw command previews for Bash;
|
|
66
|
+
- running Bash duration after the two-second progress threshold, without a permanent completion timer;
|
|
67
|
+
- Diff previews and first-change-line metadata for `edit`;
|
|
68
|
+
- syntax highlighting;
|
|
69
|
+
- image output and Kitty conversion;
|
|
70
|
+
- native collapsed/expanded handling;
|
|
71
|
+
- custom UI explicitly using `renderShell: "self"`.
|
|
72
|
+
|
|
73
|
+
`edit` now uses the native outer shell while keeping its asynchronous Diff preview and final Diff result.
|
|
74
|
+
|
|
75
|
+
## Deliberately rejected approaches
|
|
76
|
+
|
|
77
|
+
The package does not use:
|
|
78
|
+
|
|
79
|
+
- prototype patching of `ToolExecutionComponent` from an extension;
|
|
80
|
+
- same-name re-registration to replace built-in tools;
|
|
81
|
+
- a global renderer registry exposed through Extension API;
|
|
82
|
+
- a restored `tools-view` extension;
|
|
83
|
+
- forced decoration of third-party tools that explicitly own their shell.
|
|
84
|
+
|
|
85
|
+
Those approaches either depend on private runtime internals, change execution ownership, or cannot reliably cover independently loaded extensions.
|
package/docs/compaction.md
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
LLMs have limited context windows. When conversations grow too long, pi uses compaction to summarize older content while preserving recent work. This page covers both auto-compaction and branch summarization.
|
|
4
4
|
|
|
5
|
-
**Source files** ([pi
|
|
6
|
-
- [`
|
|
7
|
-
- [`
|
|
8
|
-
- [`
|
|
9
|
-
- [`
|
|
10
|
-
- [`
|
|
5
|
+
**Source files** ([ming-kang/pi](https://github.com/ming-kang/pi)):
|
|
6
|
+
- [`src/core/compaction/compaction.ts`](https://github.com/ming-kang/pi/blob/main/src/core/compaction/compaction.ts) - Auto-compaction logic
|
|
7
|
+
- [`src/core/compaction/branch-summarization.ts`](https://github.com/ming-kang/pi/blob/main/src/core/compaction/branch-summarization.ts) - Branch summarization
|
|
8
|
+
- [`src/core/compaction/utils.ts`](https://github.com/ming-kang/pi/blob/main/src/core/compaction/utils.ts) - Shared utilities (file tracking, serialization)
|
|
9
|
+
- [`src/core/session-manager.ts`](https://github.com/ming-kang/pi/blob/main/src/core/session-manager.ts) - Entry types (`CompactionEntry`, `BranchSummaryEntry`)
|
|
10
|
+
- [`src/core/extensions/types.ts`](https://github.com/ming-kang/pi/blob/main/src/core/extensions/types.ts) - Extension event types
|
|
11
11
|
|
|
12
12
|
For TypeScript definitions in your project, inspect `node_modules/@astralyn/pi/dist/`.
|
|
13
13
|
|
|
@@ -34,6 +34,12 @@ contextTokens > contextWindow - reserveTokens
|
|
|
34
34
|
|
|
35
35
|
By default, `reserveTokens` is 16384 tokens (configurable in `~/.pi/agent/settings.json` or `<project-dir>/.pi/settings.json`). This leaves room for the LLM's response.
|
|
36
36
|
|
|
37
|
+
During an active tool-calling run, Pi evaluates this threshold after each complete tool batch, including the newly appended tool results, and before another provider request. If compaction succeeds, Pi rebuilds the context and continues the same agent run without inserting a continuation prompt. If compaction is cancelled, fails, has no safe cut point, or leaves the estimated retained context above the threshold, Pi fails closed before queue polling or another provider request. Because the upstream stateful Agent does not expose its low-level graceful turn-stop hook, this exceptional path ends with an explicit error/aborted assistant lifecycle; the preceding `compaction_end` event contains the underlying warning or failure.
|
|
38
|
+
|
|
39
|
+
This between-tool-batch trigger is separate from **split-turn compaction** below: the trigger determines *when* compaction runs, while split-turn support determines *where* a very long turn can be cut.
|
|
40
|
+
|
|
41
|
+
Before a new user prompt, Pi also refuses to send an existing context whose estimate remains above the threshold after compaction. This check happens before adding the new prompt itself. Reduce `keepRecentTokens`, remove unusually large retained content, or switch to a model with a larger context window before continuing.
|
|
42
|
+
|
|
37
43
|
You can also trigger manually with `/compact [instructions]`, where optional instructions focus the summary.
|
|
38
44
|
|
|
39
45
|
### How It Works
|
|
@@ -42,7 +48,7 @@ You can also trigger manually with `/compact [instructions]`, where optional ins
|
|
|
42
48
|
2. **Extract messages**: Collect messages from the previous kept boundary (or session start) up to the cut point
|
|
43
49
|
3. **Generate summary**: Call LLM to summarize with structured format, passing the previous summary as iterative context when present
|
|
44
50
|
4. **Append entry**: Save `CompactionEntry` with summary and `firstKeptEntryId`
|
|
45
|
-
5. **Reload**:
|
|
51
|
+
5. **Reload and verify**: Rebuild context using the summary plus messages from `firstKeptEntryId` onwards, then verify the estimated retained context is below the auto-compaction threshold before continuing automatically
|
|
46
52
|
|
|
47
53
|
```
|
|
48
54
|
Before compaction:
|
|
@@ -118,7 +124,7 @@ Never cut at tool results (they must stay with their tool call).
|
|
|
118
124
|
|
|
119
125
|
### CompactionEntry Structure
|
|
120
126
|
|
|
121
|
-
Defined in [`session-manager.ts`](https://github.com/
|
|
127
|
+
Defined in [`session-manager.ts`](https://github.com/ming-kang/pi/blob/main/src/core/session-manager.ts):
|
|
122
128
|
|
|
123
129
|
```typescript
|
|
124
130
|
interface CompactionEntry<T = unknown> {
|
|
@@ -143,7 +149,7 @@ interface CompactionDetails {
|
|
|
143
149
|
|
|
144
150
|
Extensions can store any JSON-serializable data in `details`. The default compaction tracks file operations, but custom extension implementations can use their own structure. Generated and extension-provided summaries store their LLM `usage` when available so session totals include summarization work.
|
|
145
151
|
|
|
146
|
-
See [`prepareCompaction()`](https://github.com/
|
|
152
|
+
See [`prepareCompaction()`](https://github.com/ming-kang/pi/blob/main/src/core/compaction/compaction.ts) and [`compact()`](https://github.com/ming-kang/pi/blob/main/src/core/compaction/compaction.ts) for the implementation. For direct programmatic summarization, `generateSummary()` returns the summary text and `generateSummaryWithUsage()` returns `{ text, usage }`.
|
|
147
153
|
|
|
148
154
|
## Branch Summarization
|
|
149
155
|
|
|
@@ -186,7 +192,7 @@ This means file tracking accumulates across multiple compactions or nested branc
|
|
|
186
192
|
|
|
187
193
|
### BranchSummaryEntry Structure
|
|
188
194
|
|
|
189
|
-
Defined in [`session-manager.ts`](https://github.com/
|
|
195
|
+
Defined in [`session-manager.ts`](https://github.com/ming-kang/pi/blob/main/src/core/session-manager.ts):
|
|
190
196
|
|
|
191
197
|
```typescript
|
|
192
198
|
interface BranchSummaryEntry<T = unknown> {
|
|
@@ -210,7 +216,7 @@ interface BranchSummaryDetails {
|
|
|
210
216
|
|
|
211
217
|
Same as compaction, extensions can store custom data in `details`.
|
|
212
218
|
|
|
213
|
-
See [`collectEntriesForBranchSummary()`](https://github.com/
|
|
219
|
+
See [`collectEntriesForBranchSummary()`](https://github.com/ming-kang/pi/blob/main/src/core/compaction/branch-summarization.ts), [`prepareBranchEntries()`](https://github.com/ming-kang/pi/blob/main/src/core/compaction/branch-summarization.ts), and [`generateBranchSummary()`](https://github.com/ming-kang/pi/blob/main/src/core/compaction/branch-summarization.ts) for the implementation.
|
|
214
220
|
|
|
215
221
|
## Summary Format
|
|
216
222
|
|
|
@@ -254,7 +260,7 @@ path/to/changed.ts
|
|
|
254
260
|
|
|
255
261
|
### Message Serialization
|
|
256
262
|
|
|
257
|
-
Before summarization, messages are serialized to text via [`serializeConversation()`](https://github.com/
|
|
263
|
+
Before summarization, messages are serialized to text via [`serializeConversation()`](https://github.com/ming-kang/pi/blob/main/src/core/compaction/utils.ts):
|
|
258
264
|
|
|
259
265
|
```
|
|
260
266
|
[User]: What they said
|
|
@@ -270,7 +276,7 @@ Tool results are truncated to 2000 characters during serialization. Content beyo
|
|
|
270
276
|
|
|
271
277
|
## Custom Summarization via Extensions
|
|
272
278
|
|
|
273
|
-
Extensions can intercept and customize both compaction and branch summarization. See [`extensions/types.ts`](https://github.com/
|
|
279
|
+
Extensions can intercept and customize both compaction and branch summarization. See [`extensions/types.ts`](https://github.com/ming-kang/pi/blob/main/src/core/extensions/types.ts) for event type definitions.
|
|
274
280
|
|
|
275
281
|
### session_before_compact
|
|
276
282
|
|
|
@@ -290,7 +296,7 @@ pi.on("session_before_compact", async (event, ctx) => {
|
|
|
290
296
|
|
|
291
297
|
// branchEntries - all entries on current branch (for custom state)
|
|
292
298
|
// reason - "manual" (/compact), "threshold", or "overflow"
|
|
293
|
-
// willRetry - whether
|
|
299
|
+
// willRetry - whether overflow recovery intends to retry if compaction produces a safe retained context
|
|
294
300
|
// signal - AbortSignal (pass to LLM calls)
|
|
295
301
|
|
|
296
302
|
// Cancel:
|
package/docs/containerization.md
CHANGED
|
@@ -24,7 +24,7 @@ Use the [example extension](../examples/extensions/gondolin) when you want `pi`
|
|
|
24
24
|
Setup:
|
|
25
25
|
|
|
26
26
|
```bash
|
|
27
|
-
cp -R
|
|
27
|
+
cp -R examples/extensions/gondolin ~/.pi/agent/extensions/gondolin
|
|
28
28
|
cd ~/.pi/agent/extensions/gondolin
|
|
29
29
|
npm install --ignore-scripts
|
|
30
30
|
```
|
package/docs/custom-provider.md
CHANGED
|
@@ -397,12 +397,12 @@ interface OAuthCredentials {
|
|
|
397
397
|
For providers with non-standard APIs, implement `streamSimple`. Study the existing provider implementations before writing your own:
|
|
398
398
|
|
|
399
399
|
**Reference implementations:**
|
|
400
|
-
- [anthropic.ts](https://github.com/earendil-works/pi
|
|
401
|
-
- [mistral.ts](https://github.com/earendil-works/pi
|
|
402
|
-
- [openai-completions.ts](https://github.com/earendil-works/pi
|
|
403
|
-
- [openai-responses.ts](https://github.com/earendil-works/pi
|
|
404
|
-
- [google.ts](https://github.com/earendil-works/pi
|
|
405
|
-
- [amazon-bedrock.ts](https://github.com/earendil-works/pi
|
|
400
|
+
- [anthropic.ts](https://github.com/earendil-works/pi/blob/v0.82.1/packages/ai/src/providers/anthropic.ts) - Anthropic Messages API
|
|
401
|
+
- [mistral.ts](https://github.com/earendil-works/pi/blob/v0.82.1/packages/ai/src/providers/mistral.ts) - Mistral Conversations API
|
|
402
|
+
- [openai-completions.ts](https://github.com/earendil-works/pi/blob/v0.82.1/packages/ai/src/providers/openai-completions.ts) - OpenAI Chat Completions
|
|
403
|
+
- [openai-responses.ts](https://github.com/earendil-works/pi/blob/v0.82.1/packages/ai/src/providers/openai-responses.ts) - OpenAI Responses API
|
|
404
|
+
- [google.ts](https://github.com/earendil-works/pi/blob/v0.82.1/packages/ai/src/providers/google.ts) - Google Generative AI
|
|
405
|
+
- [amazon-bedrock.ts](https://github.com/earendil-works/pi/blob/v0.82.1/packages/ai/src/providers/amazon-bedrock.ts) - AWS Bedrock
|
|
406
406
|
|
|
407
407
|
### Stream Pattern
|
|
408
408
|
|
|
@@ -565,7 +565,7 @@ When a request exceeds the model's context window, pi can recover automatically
|
|
|
565
565
|
Detection runs on the finalized assistant message:
|
|
566
566
|
|
|
567
567
|
- `stopReason === "error"`
|
|
568
|
-
- `errorMessage` matches one of pi's known overflow patterns (see [`packages/ai/src/utils/overflow.ts`](https://github.com/earendil-works/pi
|
|
568
|
+
- `errorMessage` matches one of pi's known overflow patterns (see [`packages/ai/src/utils/overflow.ts`](https://github.com/earendil-works/pi/blob/v0.82.1/packages/ai/src/utils/overflow.ts))
|
|
569
569
|
|
|
570
570
|
If your provider returns overflow errors with a message pi does not recognize, normalize the error from the same extension that registers the provider. Use a `message_end` handler to rewrite the assistant message so its `errorMessage` starts with a phrase pi recognizes. The generic fallback `context_length_exceeded` is the safest choice.
|
|
571
571
|
|
|
@@ -628,7 +628,7 @@ pi.registerProvider("my-provider", {
|
|
|
628
628
|
|
|
629
629
|
## Testing Your Implementation
|
|
630
630
|
|
|
631
|
-
Test your provider against the same test suites used by built-in providers. Copy and adapt these test files from [packages/ai/test/](https://github.com/earendil-works/pi
|
|
631
|
+
Test your provider against the same test suites used by built-in providers. Copy and adapt these test files from [packages/ai/test/](https://github.com/earendil-works/pi/tree/v0.82.1/packages/ai/test):
|
|
632
632
|
|
|
633
633
|
| Test | Purpose |
|
|
634
634
|
|------|---------|
|
package/docs/docs.json
CHANGED
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
"title": "Providers",
|
|
20
20
|
"path": "providers.md"
|
|
21
21
|
},
|
|
22
|
+
{
|
|
23
|
+
"title": "llama.cpp",
|
|
24
|
+
"path": "llama-cpp.md"
|
|
25
|
+
},
|
|
22
26
|
{
|
|
23
27
|
"title": "Security",
|
|
24
28
|
"path": "security.md"
|
|
@@ -45,6 +49,55 @@
|
|
|
45
49
|
}
|
|
46
50
|
]
|
|
47
51
|
},
|
|
52
|
+
{
|
|
53
|
+
"title": "Bundled features",
|
|
54
|
+
"items": [
|
|
55
|
+
{
|
|
56
|
+
"title": "Overview",
|
|
57
|
+
"path": "bundled/README.md"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"title": "Extension catalog",
|
|
61
|
+
"path": "bundled/extensions/README.md"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"title": "DeepWiki",
|
|
65
|
+
"path": "bundled/extensions/deepwiki.md"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"title": "Question",
|
|
69
|
+
"path": "bundled/extensions/question.md"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"title": "Rewind",
|
|
73
|
+
"path": "bundled/extensions/rewind.md"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"title": "Router",
|
|
77
|
+
"path": "bundled/extensions/router.md"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"title": "Statusline",
|
|
81
|
+
"path": "bundled/extensions/statusline.md"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"title": "Subagent",
|
|
85
|
+
"path": "bundled/extensions/subagent.md"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"title": "Todo",
|
|
89
|
+
"path": "bundled/extensions/todo.md"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"title": "Bundled themes",
|
|
93
|
+
"path": "bundled/themes.md"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"title": "Native tool presentation",
|
|
97
|
+
"path": "bundled/tool-presentation.md"
|
|
98
|
+
}
|
|
99
|
+
]
|
|
100
|
+
},
|
|
48
101
|
{
|
|
49
102
|
"title": "Customization",
|
|
50
103
|
"items": [
|
|
@@ -81,6 +134,10 @@
|
|
|
81
134
|
{
|
|
82
135
|
"title": "Reference",
|
|
83
136
|
"items": [
|
|
137
|
+
{
|
|
138
|
+
"title": "Environment Variables",
|
|
139
|
+
"path": "environment-variables.md"
|
|
140
|
+
},
|
|
84
141
|
{
|
|
85
142
|
"title": "Session Format",
|
|
86
143
|
"path": "session-format.md"
|
|
@@ -132,15 +189,6 @@
|
|
|
132
189
|
"path": "shell-aliases.md"
|
|
133
190
|
}
|
|
134
191
|
]
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
"title": "Development",
|
|
138
|
-
"items": [
|
|
139
|
-
{
|
|
140
|
-
"title": "Development",
|
|
141
|
-
"path": "development.md"
|
|
142
|
-
}
|
|
143
|
-
]
|
|
144
192
|
}
|
|
145
193
|
],
|
|
146
194
|
"redirects": [
|
package/docs/extensions.md
CHANGED
|
@@ -457,7 +457,7 @@ pi.on("session_before_compact", async (event, ctx) => {
|
|
|
457
457
|
const { preparation, branchEntries, customInstructions, reason, willRetry, signal } = event;
|
|
458
458
|
|
|
459
459
|
// reason - "manual" (/compact), "threshold", or "overflow"
|
|
460
|
-
// willRetry - whether
|
|
460
|
+
// willRetry - whether overflow recovery intends to retry if compaction produces a safe retained context
|
|
461
461
|
|
|
462
462
|
// Cancel:
|
|
463
463
|
return { cancel: true };
|
|
@@ -477,7 +477,7 @@ pi.on("session_compact", async (event, ctx) => {
|
|
|
477
477
|
// event.compactionEntry - the saved compaction
|
|
478
478
|
// event.fromExtension - whether extension provided it
|
|
479
479
|
// event.reason - "manual" (/compact), "threshold", or "overflow"
|
|
480
|
-
// event.willRetry - whether
|
|
480
|
+
// event.willRetry - whether overflow recovery will actually retry after retained-context verification
|
|
481
481
|
});
|
|
482
482
|
```
|
|
483
483
|
|
|
@@ -585,6 +585,8 @@ pi.on("turn_end", async (event, ctx) => {
|
|
|
585
585
|
});
|
|
586
586
|
```
|
|
587
587
|
|
|
588
|
+
Between-tool auto-compaction runs after the completed tool turn's `turn_end`. If it cannot produce a safe next context, Pi stops before queue polling or another provider request. The upstream stateful Agent represents that package-local stop as an additional assistant error/aborted message lifecycle and `turn_end`, followed by `agent_end`; SDK, JSON, and RPC consumers can use the preceding `compaction_end` event for the detailed compaction failure or retained-context warning.
|
|
589
|
+
|
|
588
590
|
#### message_start / message_update / message_end
|
|
589
591
|
|
|
590
592
|
Fired for message lifecycle updates.
|
|
@@ -2041,13 +2043,13 @@ See [examples/extensions/tool-override.ts](../examples/extensions/tool-override.
|
|
|
2041
2043
|
**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.
|
|
2042
2044
|
|
|
2043
2045
|
Built-in tool implementations:
|
|
2044
|
-
- [read.ts](https://github.com/
|
|
2045
|
-
- [bash.ts](https://github.com/
|
|
2046
|
-
- [edit.ts](https://github.com/
|
|
2047
|
-
- [write.ts](https://github.com/
|
|
2048
|
-
- [grep.ts](https://github.com/
|
|
2049
|
-
- [find.ts](https://github.com/
|
|
2050
|
-
- [ls.ts](https://github.com/
|
|
2046
|
+
- [read.ts](https://github.com/ming-kang/pi/blob/main/src/core/tools/read.ts) - `ReadToolDetails`
|
|
2047
|
+
- [bash.ts](https://github.com/ming-kang/pi/blob/main/src/core/tools/bash.ts) - `BashToolDetails`
|
|
2048
|
+
- [edit.ts](https://github.com/ming-kang/pi/blob/main/src/core/tools/edit.ts)
|
|
2049
|
+
- [write.ts](https://github.com/ming-kang/pi/blob/main/src/core/tools/write.ts)
|
|
2050
|
+
- [grep.ts](https://github.com/ming-kang/pi/blob/main/src/core/tools/grep.ts) - `GrepToolDetails`
|
|
2051
|
+
- [find.ts](https://github.com/ming-kang/pi/blob/main/src/core/tools/find.ts) - `FindToolDetails`
|
|
2052
|
+
- [ls.ts](https://github.com/ming-kang/pi/blob/main/src/core/tools/ls.ts) - `LsToolDetails`
|
|
2051
2053
|
|
|
2052
2054
|
### Remote Execution
|
|
2053
2055
|
|
|
@@ -2178,7 +2180,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
2178
2180
|
|
|
2179
2181
|
### Custom Rendering
|
|
2180
2182
|
|
|
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/
|
|
2183
|
+
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/ming-kang/pi/blob/main/src/modes/interactive/components/tool-execution.ts) for how tool rows are composed.
|
|
2182
2184
|
|
|
2183
2185
|
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.
|
|
2184
2186
|
|
|
@@ -2791,7 +2793,7 @@ Register a custom renderer for messages with your `customType`. Use message rend
|
|
|
2791
2793
|
import { Text } from "@earendil-works/pi-tui";
|
|
2792
2794
|
|
|
2793
2795
|
pi.registerMessageRenderer("my-extension", (message, options, theme) => {
|
|
2794
|
-
const { expanded } = options;
|
|
2796
|
+
const { expanded, outputPad } = options;
|
|
2795
2797
|
let text = theme.fg("accent", `[${message.customType}] `);
|
|
2796
2798
|
text += message.content;
|
|
2797
2799
|
|
|
@@ -2799,7 +2801,7 @@ pi.registerMessageRenderer("my-extension", (message, options, theme) => {
|
|
|
2799
2801
|
text += "\n" + theme.fg("dim", JSON.stringify(message.details, null, 2));
|
|
2800
2802
|
}
|
|
2801
2803
|
|
|
2802
|
-
return new Text(text,
|
|
2804
|
+
return new Text(text, outputPad, 0);
|
|
2803
2805
|
});
|
|
2804
2806
|
```
|
|
2805
2807
|
|
|
@@ -2940,7 +2942,6 @@ All examples in [examples/extensions/](../examples/extensions/).
|
|
|
2940
2942
|
| `interactive-shell.ts` | Persistent shell session | `on("user_bash")` |
|
|
2941
2943
|
| `sandbox/` | Sandboxed tool execution | Tool operations |
|
|
2942
2944
|
| `gondolin/` | Route built-in tools and `!` commands into a Gondolin micro-VM | Tool operations, built-in tool overrides, `on("user_bash")` |
|
|
2943
|
-
| `subagent/` | Spawn sub-agents | `registerTool`, `exec` |
|
|
2944
2945
|
| **Games** |||
|
|
2945
2946
|
| `snake.ts` | Snake game | `registerCommand`, `ui.custom`, keyboard handling |
|
|
2946
2947
|
| `space-invaders.ts` | Space Invaders game | `registerCommand`, `ui.custom` |
|
package/docs/index.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @astralyn/pi user and API documentation
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
@astralyn/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
4
|
|
|
5
|
-
This documentation
|
|
5
|
+
This documentation is owned by @astralyn/pi and describes the behavior of the installed npm package, including its bundled features and public APIs. Upstream Pi documentation and release tags are used only as synchronization input; they are not the user-facing source for these docs.
|
|
6
6
|
|
|
7
7
|
## Quick start
|
|
8
8
|
|
|
@@ -45,6 +45,15 @@ For the full first-run flow, see [Quickstart](quickstart.md).
|
|
|
45
45
|
- [Sessions](sessions.md) - session management, branching, and tree navigation.
|
|
46
46
|
- [Compaction](compaction.md) - context compaction and branch summarization.
|
|
47
47
|
|
|
48
|
+
## Bundled features
|
|
49
|
+
|
|
50
|
+
The installed package includes built-in extensions, themes, and native tool presentation:
|
|
51
|
+
|
|
52
|
+
- [Bundled overview](bundled/README.md) - package features and how they fit together.
|
|
53
|
+
- [Bundled extensions](bundled/extensions/README.md) - catalog and links to every bundled extension.
|
|
54
|
+
- [Bundled themes](bundled/themes.md) - the ice-cream themes included with the package.
|
|
55
|
+
- [Native tool presentation](bundled/tool-presentation.md) - the shared tool-call and result layout.
|
|
56
|
+
|
|
48
57
|
## Customization
|
|
49
58
|
|
|
50
59
|
- [Extensions](extensions.md) - TypeScript modules for tools, commands, events, and custom UI.
|
|
@@ -74,7 +83,3 @@ For the full first-run flow, see [Quickstart](quickstart.md).
|
|
|
74
83
|
- [tmux](tmux.md)
|
|
75
84
|
- [Terminal setup](terminal-setup.md)
|
|
76
85
|
- [Shell aliases](shell-aliases.md)
|
|
77
|
-
|
|
78
|
-
## Development
|
|
79
|
-
|
|
80
|
-
- [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/ming-kang/pi/blob/main/src/core/agent-session.ts#L102):
|
|
12
12
|
|
|
13
13
|
```typescript
|
|
14
14
|
type AgentSessionEvent =
|
|
@@ -26,7 +26,7 @@ type AgentSessionEvent =
|
|
|
26
26
|
|
|
27
27
|
`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.
|
|
28
28
|
|
|
29
|
-
Base events from [`AgentEvent`](https://github.com/earendil-works/pi
|
|
29
|
+
Base events from [`AgentEvent`](https://github.com/earendil-works/pi/blob/v0.82.1/packages/agent/src/types.ts#L179):
|
|
30
30
|
|
|
31
31
|
```typescript
|
|
32
32
|
type AgentEvent =
|
|
@@ -48,12 +48,12 @@ type AgentEvent =
|
|
|
48
48
|
|
|
49
49
|
## Message Types
|
|
50
50
|
|
|
51
|
-
Base messages from [`packages/ai/src/types.ts`](https://github.com/earendil-works/pi
|
|
51
|
+
Base messages from [`packages/ai/src/types.ts`](https://github.com/earendil-works/pi/blob/v0.82.1/packages/ai/src/types.ts#L134):
|
|
52
52
|
- `UserMessage` (line 134)
|
|
53
53
|
- `AssistantMessage` (line 140)
|
|
54
54
|
- `ToolResultMessage` (line 152)
|
|
55
55
|
|
|
56
|
-
Extended messages from [`
|
|
56
|
+
Extended messages from [`src/core/messages.ts`](https://github.com/ming-kang/pi/blob/main/src/core/messages.ts#L29):
|
|
57
57
|
- `BashExecutionMessage` (line 29)
|
|
58
58
|
- `CustomMessage` (line 46)
|
|
59
59
|
- `BranchSummaryMessage` (line 55)
|
package/docs/providers.md
CHANGED
|
@@ -101,7 +101,7 @@ pi
|
|
|
101
101
|
| Xiaomi MiMo Token Plan (Amsterdam) | `XIAOMI_TOKEN_PLAN_AMS_API_KEY` | `xiaomi-token-plan-ams` |
|
|
102
102
|
| Xiaomi MiMo Token Plan (Singapore) | `XIAOMI_TOKEN_PLAN_SGP_API_KEY` | `xiaomi-token-plan-sgp` |
|
|
103
103
|
|
|
104
|
-
Reference for environment variables and `auth.json` keys: [`const envMap`](https://github.com/earendil-works/pi
|
|
104
|
+
Reference for environment variables and `auth.json` keys: [`const envMap`](https://github.com/earendil-works/pi/blob/v0.82.1/packages/ai/src/env-api-keys.ts) in [`packages/ai/src/env-api-keys.ts`](https://github.com/earendil-works/pi/blob/v0.82.1/packages/ai/src/env-api-keys.ts).
|
|
105
105
|
|
|
106
106
|
#### Auth File
|
|
107
107
|
|
package/docs/rpc.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
RPC mode enables headless operation of the coding agent via a JSON protocol over stdin/stdout. This is useful for embedding the agent in other applications, IDEs, or custom UIs.
|
|
4
4
|
|
|
5
|
-
**Note for Node.js/TypeScript users**: If you're building a Node.js application, consider using `AgentSession` directly from `@astralyn/pi` instead of spawning a subprocess
|
|
5
|
+
**Note for Node.js/TypeScript users**: If you're building a Node.js application, consider using `AgentSession` directly from `@astralyn/pi` instead of spawning a subprocess; see the [public SDK API](sdk.md). For a subprocess-based client, use the RPC protocol described below. The published [RPC extension UI example](../examples/rpc-extension-ui.ts) pairs with the published [RPC demo extension](../examples/extensions/rpc-demo.ts).
|
|
6
6
|
|
|
7
7
|
## Starting RPC Mode
|
|
8
8
|
|
|
@@ -1358,11 +1358,7 @@ Parse errors:
|
|
|
1358
1358
|
|
|
1359
1359
|
## Types
|
|
1360
1360
|
|
|
1361
|
-
|
|
1362
|
-
- [`packages/ai/src/types.ts`](../../ai/src/types.ts) - `Model`, `UserMessage`, `AssistantMessage`, `ToolResultMessage`
|
|
1363
|
-
- [`packages/agent/src/types.ts`](../../agent/src/types.ts) - `AgentMessage`, `AgentEvent`
|
|
1364
|
-
- [`src/core/messages.ts`](../src/core/messages.ts) - `BashExecutionMessage`
|
|
1365
|
-
- [`src/modes/rpc/rpc-types.ts`](../src/modes/rpc/rpc-types.ts) - RPC command/response types, extension UI request/response types
|
|
1361
|
+
RPC messages use the public SDK and protocol types documented by this package. The model and agent message shapes are summarized below; applications embedding Pi should import the public API from `@astralyn/pi` rather than relying on package source files.
|
|
1366
1362
|
|
|
1367
1363
|
### Model
|
|
1368
1364
|
|
|
@@ -1519,9 +1515,7 @@ for event in read_events():
|
|
|
1519
1515
|
|
|
1520
1516
|
## Example: Interactive Client (Node.js)
|
|
1521
1517
|
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
For a complete example of handling the extension UI protocol, see [`examples/rpc-extension-ui.ts`](../examples/rpc-extension-ui.ts) which pairs with the [`examples/extensions/rpc-demo.ts`](../examples/extensions/rpc-demo.ts) extension.
|
|
1518
|
+
For a complete interactive example, see the published [RPC extension UI example](../examples/rpc-extension-ui.ts), which pairs with the published [RPC demo extension](../examples/extensions/rpc-demo.ts). For embedded Node.js or TypeScript clients, use the [public SDK API](sdk.md).
|
|
1525
1519
|
|
|
1526
1520
|
```javascript
|
|
1527
1521
|
const { spawn } = require("child_process");
|
package/docs/session-format.md
CHANGED
|
@@ -28,11 +28,11 @@ Existing sessions are automatically migrated to the current version (v3) when lo
|
|
|
28
28
|
|
|
29
29
|
## Source Files
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
- [`
|
|
33
|
-
- [`
|
|
34
|
-
- [`packages/ai/src/types.ts`](https://github.com/earendil-works/pi
|
|
35
|
-
- [`packages/agent/src/types.ts`](https://github.com/earendil-works/pi
|
|
31
|
+
Distribution source on GitHub ([ming-kang/pi](https://github.com/ming-kang/pi)):
|
|
32
|
+
- [`src/core/session-manager.ts`](https://github.com/ming-kang/pi/blob/main/src/core/session-manager.ts) - Session entry types and SessionManager
|
|
33
|
+
- [`src/core/messages.ts`](https://github.com/ming-kang/pi/blob/main/src/core/messages.ts) - Extended message types (BashExecutionMessage, CustomMessage, etc.)
|
|
34
|
+
- [`packages/ai/src/types.ts`](https://github.com/earendil-works/pi/blob/v0.82.1/packages/ai/src/types.ts) - Base message types (UserMessage, AssistantMessage, ToolResultMessage)
|
|
35
|
+
- [`packages/agent/src/types.ts`](https://github.com/earendil-works/pi/blob/v0.82.1/packages/agent/src/types.ts) - AgentMessage union type
|
|
36
36
|
|
|
37
37
|
For TypeScript definitions in your project, inspect `node_modules/@astralyn/pi/dist/` and `node_modules/@earendil-works/pi-ai/dist/`.
|
|
38
38
|
|
package/docs/skills.md
CHANGED
|
@@ -131,7 +131,7 @@ cd /path/to/skill && npm install
|
|
|
131
131
|
Use relative paths from the skill directory:
|
|
132
132
|
|
|
133
133
|
```markdown
|
|
134
|
-
See
|
|
134
|
+
See the reference guide at `references/REFERENCE.md` for details.
|
|
135
135
|
```
|
|
136
136
|
|
|
137
137
|
## Frontmatter
|
package/docs/themes.md
CHANGED
|
@@ -52,7 +52,7 @@ vim ~/.pi/agent/themes/my-theme.json
|
|
|
52
52
|
|
|
53
53
|
```json
|
|
54
54
|
{
|
|
55
|
-
"$schema": "https://raw.githubusercontent.com/
|
|
55
|
+
"$schema": "https://raw.githubusercontent.com/ming-kang/pi/main/src/modes/interactive/theme/theme-schema.json",
|
|
56
56
|
"name": "my-theme",
|
|
57
57
|
"vars": {
|
|
58
58
|
"primary": "#00aaff",
|
|
@@ -123,7 +123,7 @@ vim ~/.pi/agent/themes/my-theme.json
|
|
|
123
123
|
|
|
124
124
|
```json
|
|
125
125
|
{
|
|
126
|
-
"$schema": "https://raw.githubusercontent.com/
|
|
126
|
+
"$schema": "https://raw.githubusercontent.com/ming-kang/pi/main/src/modes/interactive/theme/theme-schema.json",
|
|
127
127
|
"name": "my-theme",
|
|
128
128
|
"vars": {
|
|
129
129
|
"blue": "#0066cc",
|
|
@@ -292,10 +292,6 @@ echo $COLORTERM # Should output "truecolor" or "24bit"
|
|
|
292
292
|
|
|
293
293
|
## Examples
|
|
294
294
|
|
|
295
|
-
|
|
296
|
-
- [dark.json](../src/modes/interactive/theme/dark.json)
|
|
297
|
-
- [light.json](../src/modes/interactive/theme/light.json)
|
|
298
|
-
- [ice-cream-dark.json](../src/modes/interactive/theme/ice-cream-dark.json)
|
|
299
|
-
- [ice-cream-light.json](../src/modes/interactive/theme/ice-cream-light.json)
|
|
295
|
+
The built-in themes are selected by name: `dark`, `light`, `ice-cream-dark`, and `ice-cream-light`. When inspecting an installed package, their JSON assets are under `node_modules/@astralyn/pi/dist/modes/interactive/theme/` (the global-install equivalent is under Pi's npm package directory).
|
|
300
296
|
|
|
301
|
-
The ice-cream palette and
|
|
297
|
+
The ice-cream palette and bundled design notes are documented in [Bundled themes](bundled/themes.md).
|
package/docs/tui.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
Extensions and custom tools can render custom TUI components for interactive user interfaces. This page covers the component system and available building blocks.
|
|
6
6
|
|
|
7
|
-
**Source:** [`@earendil-works/pi-tui`](https://github.com/earendil-works/pi
|
|
7
|
+
**Source:** [`@earendil-works/pi-tui@0.82.1`](https://github.com/earendil-works/pi/tree/v0.82.1/packages/tui)
|
|
8
8
|
|
|
9
9
|
## Component Interface
|
|
10
10
|
|
|
@@ -42,7 +42,6 @@ cp permission-gate.ts ~/.pi/agent/extensions/
|
|
|
42
42
|
| `minimal-mode.ts` | Override built-in tool rendering for minimal display (only tool calls, no output in collapsed mode) |
|
|
43
43
|
| `truncated-tool.ts` | Wraps ripgrep with proper output truncation (50KB/2000 lines) |
|
|
44
44
|
| `ssh.ts` | Delegate all tools to a remote machine via SSH using pluggable operations |
|
|
45
|
-
| `subagent/` | Delegate tasks to specialized subagents with isolated context windows |
|
|
46
45
|
|
|
47
46
|
### Commands & UI
|
|
48
47
|
|