@astralyn/pi 0.82.7 → 0.83.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 +34 -5099
- package/README.md +12 -111
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +9 -2
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/credential-print.d.ts +23 -0
- package/dist/cli/credential-print.d.ts.map +1 -0
- package/dist/cli/credential-print.js +116 -0
- package/dist/cli/credential-print.js.map +1 -0
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +3 -0
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session.d.ts +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +13 -6
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +1 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +7 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +7 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/footer-data-provider.d.ts +10 -0
- package/dist/core/footer-data-provider.d.ts.map +1 -1
- package/dist/core/footer-data-provider.js +1 -1
- package/dist/core/footer-data-provider.js.map +1 -1
- package/dist/core/model-runtime.d.ts +2 -0
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +13 -6
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/resource-loader.d.ts +15 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +70 -9
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +34 -4
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +48 -9
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/extensions/index.d.ts.map +1 -1
- package/dist/extensions/index.js +0 -2
- package/dist/extensions/index.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts.map +1 -1
- package/dist/extensions/llama/provider.js +1 -1
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +43 -0
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/extension-selector.d.ts +1 -1
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-selector.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +4 -1
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/external-editor.d.ts.map +1 -1
- package/dist/modes/interactive/external-editor.js +40 -3
- package/dist/modes/interactive/external-editor.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +20 -6
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +13 -0
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/utils/paths.d.ts +2 -3
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +2 -3
- package/dist/utils/paths.js.map +1 -1
- package/docs/bundled/README.md +13 -16
- package/docs/bundled/themes.md +1 -1
- package/docs/compaction.md +25 -30
- package/docs/custom-provider.md +298 -583
- package/docs/docs.json +0 -8
- package/docs/extensions.md +112 -116
- package/docs/index.md +18 -74
- package/docs/json.md +20 -14
- package/docs/models.md +193 -151
- package/docs/providers.md +2 -1
- package/docs/quickstart.md +3 -3
- package/docs/rpc.md +165 -123
- package/docs/sdk.md +119 -178
- package/docs/security.md +1 -1
- package/docs/session-format.md +139 -119
- package/docs/skills.md +0 -1
- package/docs/themes.md +2 -2
- package/docs/tui.md +411 -549
- package/docs/usage.md +3 -11
- package/examples/README.md +6 -1
- package/examples/extensions/README.md +13 -33
- package/examples/extensions/custom-provider-anthropic/index.ts +9 -3
- package/examples/extensions/dynamic-resources/dynamic.json +1 -1
- package/examples/extensions/truncated-tool.ts +2 -2
- package/examples/sdk/12-full-control.ts +2 -0
- package/npm-shrinkwrap.json +21 -21
- package/package.json +5 -5
- package/dist/extensions/plan/constants.d.ts +0 -68
- package/dist/extensions/plan/constants.d.ts.map +0 -1
- package/dist/extensions/plan/constants.js +0 -100
- package/dist/extensions/plan/constants.js.map +0 -1
- package/dist/extensions/plan/index.d.ts +0 -30
- package/dist/extensions/plan/index.d.ts.map +0 -1
- package/dist/extensions/plan/index.js +0 -429
- package/dist/extensions/plan/index.js.map +0 -1
- package/dist/extensions/plan/schema.d.ts +0 -20
- package/dist/extensions/plan/schema.d.ts.map +0 -1
- package/dist/extensions/plan/schema.js +0 -13
- package/dist/extensions/plan/schema.js.map +0 -1
- package/dist/extensions/plan/state.d.ts +0 -38
- package/dist/extensions/plan/state.d.ts.map +0 -1
- package/dist/extensions/plan/state.js +0 -96
- package/dist/extensions/plan/state.js.map +0 -1
- package/dist/extensions/plan/storage.d.ts +0 -26
- package/dist/extensions/plan/storage.d.ts.map +0 -1
- package/dist/extensions/plan/storage.js +0 -83
- package/dist/extensions/plan/storage.js.map +0 -1
- package/dist/extensions/plan/view.d.ts +0 -44
- package/dist/extensions/plan/view.d.ts.map +0 -1
- package/dist/extensions/plan/view.js +0 -149
- package/dist/extensions/plan/view.js.map +0 -1
- package/docs/bundled/extensions/README.md +0 -19
- package/docs/bundled/extensions/plan.md +0 -34
- package/examples/extensions/plan-mode/README.md +0 -66
- package/examples/extensions/plan-mode/index.ts +0 -390
- package/examples/extensions/plan-mode/utils.ts +0 -168
package/docs/compaction.md
CHANGED
|
@@ -2,14 +2,11 @@
|
|
|
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
|
-
|
|
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
|
|
5
|
+
## Public API
|
|
11
6
|
|
|
12
|
-
|
|
7
|
+
Programmatic compaction helpers are exported by [`@astralyn/pi`](https://www.npmjs.com/package/@astralyn/pi): `compact`, `generateSummary`, `generateSummaryWithUsage`, `collectEntriesForBranchSummary`, `prepareBranchEntries`, `generateBranchSummary`, and `serializeConversation`.
|
|
8
|
+
|
|
9
|
+
`CompactionEntry` and `BranchSummaryEntry` are public types; see [Session Format](session-format.md) for their persisted JSONL representation. For extension lifecycle events, see [compaction events](extensions.md#session_before_compact--session_compact) and [tree events](extensions.md#session_before_tree--session_tree).
|
|
13
10
|
|
|
14
11
|
## Overview
|
|
15
12
|
|
|
@@ -34,7 +31,7 @@ contextTokens > contextWindow - reserveTokens
|
|
|
34
31
|
|
|
35
32
|
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
33
|
|
|
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.
|
|
34
|
+
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. A voluntary `session_before_compact` cancellation at `timing: "midTurn"` lets that run continue and suppresses further mid-turn compaction checks for the rest of the run. An abort, compaction failure, no safe cut point, or retained context that remains above the threshold fails closed before queue polling or another provider request. Cancellations at other timings likewise leave over-threshold context to fail closed before the next request. Because the upstream stateful Agent does not expose its low-level graceful turn-stop hook, a fail-closed path ends with an explicit error/aborted assistant lifecycle; the preceding `compaction_end` event contains the underlying warning or failure.
|
|
38
35
|
|
|
39
36
|
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
37
|
|
|
@@ -124,14 +121,14 @@ Never cut at tool results (they must stay with their tool call).
|
|
|
124
121
|
|
|
125
122
|
### CompactionEntry Structure
|
|
126
123
|
|
|
127
|
-
|
|
124
|
+
The public `CompactionEntry` type is documented in [Session Format](session-format.md):
|
|
128
125
|
|
|
129
126
|
```typescript
|
|
130
127
|
interface CompactionEntry<T = unknown> {
|
|
131
128
|
type: "compaction";
|
|
132
129
|
id: string;
|
|
133
|
-
parentId: string;
|
|
134
|
-
timestamp:
|
|
130
|
+
parentId: string | null;
|
|
131
|
+
timestamp: string;
|
|
135
132
|
summary: string;
|
|
136
133
|
firstKeptEntryId: string;
|
|
137
134
|
tokensBefore: number;
|
|
@@ -140,7 +137,7 @@ interface CompactionEntry<T = unknown> {
|
|
|
140
137
|
details?: T; // implementation-specific data
|
|
141
138
|
}
|
|
142
139
|
|
|
143
|
-
// Default compaction uses this for details
|
|
140
|
+
// Default compaction uses this for details:
|
|
144
141
|
interface CompactionDetails {
|
|
145
142
|
readFiles: string[];
|
|
146
143
|
modifiedFiles: string[];
|
|
@@ -149,7 +146,7 @@ interface CompactionDetails {
|
|
|
149
146
|
|
|
150
147
|
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.
|
|
151
148
|
|
|
152
|
-
|
|
149
|
+
Pi uses an internal preparation step before `compact()`. For direct programmatic summarization, `generateSummary()` returns the summary text and `generateSummaryWithUsage()` returns `{ text, usage }`.
|
|
153
150
|
|
|
154
151
|
## Branch Summarization
|
|
155
152
|
|
|
@@ -177,9 +174,9 @@ Entries to summarize: B, C, D
|
|
|
177
174
|
|
|
178
175
|
After navigation with summary:
|
|
179
176
|
|
|
180
|
-
┌─ B ─ C ─ D
|
|
177
|
+
┌─ B ─ C ─ D (old leaf, abandoned)
|
|
181
178
|
A ───┤
|
|
182
|
-
└─ E ─ F (new leaf)
|
|
179
|
+
└─ E ─ F ─ [summary of B,C,D] (new leaf)
|
|
183
180
|
```
|
|
184
181
|
|
|
185
182
|
### Cumulative File Tracking
|
|
@@ -192,14 +189,14 @@ This means file tracking accumulates across multiple compactions or nested branc
|
|
|
192
189
|
|
|
193
190
|
### BranchSummaryEntry Structure
|
|
194
191
|
|
|
195
|
-
|
|
192
|
+
The public `BranchSummaryEntry` type is documented in [Session Format](session-format.md):
|
|
196
193
|
|
|
197
194
|
```typescript
|
|
198
195
|
interface BranchSummaryEntry<T = unknown> {
|
|
199
196
|
type: "branch_summary";
|
|
200
197
|
id: string;
|
|
201
|
-
parentId: string;
|
|
202
|
-
timestamp:
|
|
198
|
+
parentId: string | null;
|
|
199
|
+
timestamp: string;
|
|
203
200
|
summary: string;
|
|
204
201
|
fromId: string; // Entry we navigated from
|
|
205
202
|
usage?: Usage; // LLM usage that generated the summary
|
|
@@ -207,7 +204,7 @@ interface BranchSummaryEntry<T = unknown> {
|
|
|
207
204
|
details?: T; // implementation-specific data
|
|
208
205
|
}
|
|
209
206
|
|
|
210
|
-
// Default branch summarization uses this for details
|
|
207
|
+
// Default branch summarization uses this for details:
|
|
211
208
|
interface BranchSummaryDetails {
|
|
212
209
|
readFiles: string[];
|
|
213
210
|
modifiedFiles: string[];
|
|
@@ -216,7 +213,7 @@ interface BranchSummaryDetails {
|
|
|
216
213
|
|
|
217
214
|
Same as compaction, extensions can store custom data in `details`.
|
|
218
215
|
|
|
219
|
-
|
|
216
|
+
For programmatic branch summarization, use `collectEntriesForBranchSummary()`, `prepareBranchEntries()`, and `generateBranchSummary()`.
|
|
220
217
|
|
|
221
218
|
## Summary Format
|
|
222
219
|
|
|
@@ -260,7 +257,7 @@ path/to/changed.ts
|
|
|
260
257
|
|
|
261
258
|
### Message Serialization
|
|
262
259
|
|
|
263
|
-
Before summarization,
|
|
260
|
+
Before summarization, the exported `serializeConversation()` function serializes messages to text:
|
|
264
261
|
|
|
265
262
|
```
|
|
266
263
|
[User]: What they said
|
|
@@ -276,11 +273,11 @@ Tool results are truncated to 2000 characters during serialization. Content beyo
|
|
|
276
273
|
|
|
277
274
|
## Custom Summarization via Extensions
|
|
278
275
|
|
|
279
|
-
Extensions can intercept and customize both compaction and branch summarization. See [
|
|
276
|
+
Extensions can intercept and customize both compaction and branch summarization. See [compaction events](extensions.md#session_before_compact--session_compact) and [tree events](extensions.md#session_before_tree--session_tree).
|
|
280
277
|
|
|
281
278
|
### session_before_compact
|
|
282
279
|
|
|
283
|
-
Fired before auto-compaction or `/compact`. Can cancel or provide custom summary. See `SessionBeforeCompactEvent
|
|
280
|
+
Fired before auto-compaction or `/compact`. Can cancel or provide custom summary. See `SessionBeforeCompactEvent`.
|
|
284
281
|
|
|
285
282
|
```typescript
|
|
286
283
|
pi.on("session_before_compact", async (event, ctx) => {
|
|
@@ -300,10 +297,10 @@ pi.on("session_before_compact", async (event, ctx) => {
|
|
|
300
297
|
// willRetry - whether overflow recovery intends to retry if compaction produces a safe retained context
|
|
301
298
|
// signal - AbortSignal (pass to LLM calls)
|
|
302
299
|
|
|
303
|
-
//
|
|
304
|
-
//
|
|
305
|
-
// other timings
|
|
306
|
-
// next provider request.
|
|
300
|
+
// A voluntary cancel at timing "midTurn" continues the current run and skips
|
|
301
|
+
// further mid-turn checks. An abort, failure, no safe cut, or unsafe retained
|
|
302
|
+
// context fails closed; at other timings, over-threshold context also fails
|
|
303
|
+
// closed before the next provider request.
|
|
307
304
|
return { cancel: true };
|
|
308
305
|
|
|
309
306
|
// Custom summary:
|
|
@@ -358,7 +355,7 @@ See [custom-compaction.ts](../examples/extensions/custom-compaction.ts) for a co
|
|
|
358
355
|
|
|
359
356
|
### session_before_tree
|
|
360
357
|
|
|
361
|
-
Fired before `/tree` navigation. Always fires regardless of whether user chose to summarize. Can cancel navigation or provide custom summary.
|
|
358
|
+
Fired before `/tree` navigation. Always fires regardless of whether user chose to summarize. Can cancel navigation or provide custom summary. See `SessionBeforeTreeEvent`.
|
|
362
359
|
|
|
363
360
|
```typescript
|
|
364
361
|
pi.on("session_before_tree", async (event, ctx) => {
|
|
@@ -386,8 +383,6 @@ pi.on("session_before_tree", async (event, ctx) => {
|
|
|
386
383
|
});
|
|
387
384
|
```
|
|
388
385
|
|
|
389
|
-
See `SessionBeforeTreeEvent` and `TreePreparation` in the types file.
|
|
390
|
-
|
|
391
386
|
## Settings
|
|
392
387
|
|
|
393
388
|
Configure compaction in `~/.pi/agent/settings.json` or `<project-dir>/.pi/settings.json`:
|