@astralyn/pi 0.82.6 → 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 +61 -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/cli/session-picker.d.ts.map +1 -1
- package/dist/cli/session-picker.js +11 -13
- package/dist/cli/session-picker.js.map +1 -1
- 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 +11 -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/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +2 -2
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/tools/bash.d.ts +1 -5
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +16 -41
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +42 -11
- 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 +40 -11
- 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 +17 -8
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +3 -3
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +4 -4
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts +7 -0
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js +11 -0
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +2 -3
- package/dist/core/tools/write.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/deepwiki/render.d.ts.map +1 -1
- package/dist/extensions/deepwiki/render.js +34 -22
- package/dist/extensions/deepwiki/render.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/extensions/question/dialog.d.ts.map +1 -1
- package/dist/extensions/question/dialog.js +29 -10
- package/dist/extensions/question/dialog.js.map +1 -1
- package/dist/extensions/question/index.d.ts.map +1 -1
- package/dist/extensions/question/index.js +7 -2
- package/dist/extensions/question/index.js.map +1 -1
- package/dist/extensions/question/render.d.ts +4 -8
- package/dist/extensions/question/render.d.ts.map +1 -1
- package/dist/extensions/question/render.js +202 -29
- package/dist/extensions/question/render.js.map +1 -1
- package/dist/extensions/question/results.d.ts.map +1 -1
- package/dist/extensions/question/results.js +1 -0
- package/dist/extensions/question/results.js.map +1 -1
- package/dist/extensions/question/schema.d.ts.map +1 -1
- package/dist/extensions/question/schema.js +2 -2
- package/dist/extensions/question/schema.js.map +1 -1
- package/dist/extensions/question/types.d.ts +1 -0
- package/dist/extensions/question/types.d.ts.map +1 -1
- package/dist/extensions/question/types.js +1 -1
- package/dist/extensions/question/types.js.map +1 -1
- package/dist/extensions/router/stream.d.ts +1 -0
- package/dist/extensions/router/stream.d.ts.map +1 -1
- package/dist/extensions/router/stream.js +44 -13
- package/dist/extensions/router/stream.js.map +1 -1
- package/dist/extensions/subagent/constants.d.ts +1 -0
- package/dist/extensions/subagent/constants.d.ts.map +1 -1
- package/dist/extensions/subagent/constants.js +1 -0
- package/dist/extensions/subagent/constants.js.map +1 -1
- package/dist/extensions/subagent/index.d.ts.map +1 -1
- package/dist/extensions/subagent/index.js +2 -0
- package/dist/extensions/subagent/index.js.map +1 -1
- package/dist/extensions/subagent/render.d.ts.map +1 -1
- package/dist/extensions/subagent/render.js +121 -48
- package/dist/extensions/subagent/render.js.map +1 -1
- package/dist/extensions/subagent/retry.d.ts +17 -0
- package/dist/extensions/subagent/retry.d.ts.map +1 -0
- package/dist/extensions/subagent/retry.js +41 -0
- package/dist/extensions/subagent/retry.js.map +1 -0
- package/dist/extensions/subagent/runner.d.ts.map +1 -1
- package/dist/extensions/subagent/runner.js +33 -5
- package/dist/extensions/subagent/runner.js.map +1 -1
- package/dist/extensions/subagent/sdk-runner.d.ts +6 -0
- package/dist/extensions/subagent/sdk-runner.d.ts.map +1 -1
- package/dist/extensions/subagent/sdk-runner.js +46 -24
- package/dist/extensions/subagent/sdk-runner.js.map +1 -1
- package/dist/extensions/subagent/types.d.ts +7 -0
- package/dist/extensions/subagent/types.d.ts.map +1 -1
- package/dist/extensions/subagent/types.js.map +1 -1
- package/dist/extensions/todo/index.d.ts.map +1 -1
- package/dist/extensions/todo/index.js +1 -1
- package/dist/extensions/todo/index.js.map +1 -1
- package/dist/extensions/todo/state.d.ts.map +1 -1
- package/dist/extensions/todo/state.js +10 -2
- package/dist/extensions/todo/state.js.map +1 -1
- package/dist/extensions/todo/view.d.ts +1 -1
- package/dist/extensions/todo/view.d.ts.map +1 -1
- package/dist/extensions/todo/view.js +179 -34
- package/dist/extensions/todo/view.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/migrations.d.ts.map +1 -1
- package/dist/migrations.js +2 -1
- package/dist/migrations.js.map +1 -1
- package/dist/modes/interactive/components/armin.d.ts.map +1 -1
- package/dist/modes/interactive/components/armin.js +5 -0
- package/dist/modes/interactive/components/armin.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts +1 -0
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js +4 -2
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/countdown-timer.d.ts +13 -6
- package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
- package/dist/modes/interactive/components/countdown-timer.js +54 -17
- package/dist/modes/interactive/components/countdown-timer.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 +10 -6
- package/dist/modes/interactive/components/extension-selector.js.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.d.ts +11 -1
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.js +56 -0
- package/dist/modes/interactive/components/keybinding-hints.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/components/session-selector.d.ts +3 -0
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +52 -2
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +10 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +133 -18
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tool-group.d.ts +1 -0
- package/dist/modes/interactive/components/tool-group.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-group.js +5 -0
- package/dist/modes/interactive/components/tool-group.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts +10 -1
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +55 -2
- package/dist/modes/interactive/components/tree-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 +5 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +92 -24
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +3 -2
- package/dist/modes/interactive/theme/theme.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 +5 -0
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +7 -0
- package/dist/utils/paths.js.map +1 -1
- package/docs/bundled/README.md +13 -15
- package/docs/bundled/extensions/deepwiki.md +1 -1
- package/docs/bundled/extensions/question.md +7 -5
- package/docs/bundled/extensions/router.md +3 -4
- package/docs/bundled/extensions/statusline.md +0 -1
- package/docs/bundled/extensions/subagent.md +4 -3
- package/docs/bundled/extensions/todo.md +1 -1
- package/docs/bundled/themes.md +1 -1
- package/docs/bundled/tool-presentation.md +17 -16
- package/docs/compaction.md +25 -30
- package/docs/custom-provider.md +298 -583
- package/docs/docs.json +0 -8
- package/docs/extensions.md +132 -121
- 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 +166 -124
- 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 +25 -25
- package/package.json +5 -5
- package/dist/extensions/plan/constants.d.ts +0 -40
- package/dist/extensions/plan/constants.d.ts.map +0 -1
- package/dist/extensions/plan/constants.js +0 -69
- package/dist/extensions/plan/constants.js.map +0 -1
- package/dist/extensions/plan/index.d.ts +0 -3
- package/dist/extensions/plan/index.d.ts.map +0 -1
- package/dist/extensions/plan/index.js +0 -323
- package/dist/extensions/plan/index.js.map +0 -1
- package/dist/extensions/plan/schema.d.ts +0 -15
- 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 -29
- package/dist/extensions/plan/state.d.ts.map +0 -1
- package/dist/extensions/plan/state.js +0 -74
- package/dist/extensions/plan/state.js.map +0 -1
- package/dist/extensions/plan/storage.d.ts +0 -18
- package/dist/extensions/plan/storage.d.ts.map +0 -1
- package/dist/extensions/plan/storage.js +0 -58
- package/dist/extensions/plan/storage.js.map +0 -1
- package/dist/extensions/plan/view.d.ts +0 -36
- package/dist/extensions/plan/view.d.ts.map +0 -1
- package/dist/extensions/plan/view.js +0 -74
- package/dist/extensions/plan/view.js.map +0 -1
- package/docs/bundled/extensions/README.md +0 -19
- package/docs/bundled/extensions/plan.md +0 -33
- 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
|
@@ -6,17 +6,15 @@ The `@astralyn/pi` package uses Pi's native tool transcript presentation rather
|
|
|
6
6
|
|
|
7
7
|
```text
|
|
8
8
|
● ToolName(args)
|
|
9
|
-
│ result
|
|
9
|
+
│ first result line
|
|
10
|
+
│ second result line
|
|
11
|
+
│
|
|
12
|
+
│ final result line
|
|
10
13
|
```
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
The dim result rail continues through every visual line; an empty output line renders as a bare `│`. Calls keep their status in the leading dot: warning while pending or running, green after success, and red after failure. For default-shell tools that are still running after two seconds, the shell adds a live result row such as `Running… (2.1s)` and removes it when the call settles. Tools with purpose-built progress UI can opt out through `rendersOwnProgress`; tools using `renderShell: "self"` continue to own their entire presentation.
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
● ToolName(args) completed call
|
|
16
|
-
● ToolName Working... pending call
|
|
17
|
-
● ToolName(args) failed call (error color)
|
|
18
|
-
│ result successful or failed output
|
|
19
|
-
```
|
|
17
|
+
Time-driven renderers use `renderRefreshIntervalMs` separately from `rendersOwnProgress`. The former periodically rebuilds call/result components only during the partial lifecycle; the latter only hides the generic `Running…` row. The native shell shares the shortest needed interval, constrains explicit intervals to 250ms–60s, and stops refreshing on final result, abort, disposal, session replacement, chat rebuild, or shutdown. Renderers compute elapsed/countdown values from absolute timestamps or deadlines, so a delayed repaint never changes the underlying wall-clock meaning.
|
|
20
18
|
|
|
21
19
|
## Implementation boundary
|
|
22
20
|
|
|
@@ -31,7 +29,7 @@ The native tool presentation owns:
|
|
|
31
29
|
|
|
32
30
|
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
31
|
|
|
34
|
-
Consecutive tools may opt into a shared collapsed group through `toolGroup`. Built-in `read` and `
|
|
32
|
+
Consecutive tools may opt into a shared collapsed group through `toolGroup`. Built-in `read`, `find`, `grep`, and `ls` calls use the `explore` group, and the bundled `todo` tool uses the `todo` group: their call rows render as one compact run with a single leading gap, while the configured expand-tools key (`Ctrl+O` by default) restores each tool's complete call and result. Collapsed Todo rows are result-aware: successful current snapshots summarize the completed operation, including task IDs and subjects for creation, rather than only its arguments. Failures include a sanitized reason capped at 120 characters; missing or unrecognized result details fall back safely to the call summary.
|
|
35
33
|
|
|
36
34
|
## Renderer inheritance
|
|
37
35
|
|
|
@@ -51,9 +49,10 @@ When no semantic renderer is available:
|
|
|
51
49
|
|
|
52
50
|
- arguments are serialized into a bounded one-line summary;
|
|
53
51
|
- output is collapsed to the most recent ten visual lines;
|
|
54
|
-
-
|
|
52
|
+
- a shared hint above the tail reports the number of hidden earlier lines and the configured expand key;
|
|
53
|
+
- expanding restores the complete output;
|
|
55
54
|
- 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
|
|
55
|
+
- failed calls use the error-colored bullet while result details keep the result rail.
|
|
57
56
|
|
|
58
57
|
The fallback does not change tool schemas, execution logic, or result protocols.
|
|
59
58
|
|
|
@@ -62,15 +61,17 @@ The fallback does not change tool schemas, execution logic, or result protocols.
|
|
|
62
61
|
The native path continues to preserve:
|
|
63
62
|
|
|
64
63
|
- `read`, `bash`, `grep`, `find`, `ls`, `write`, and `edit` semantics;
|
|
65
|
-
- faithful width-aware raw command previews for Bash;
|
|
66
|
-
- running
|
|
67
|
-
-
|
|
64
|
+
- faithful width-aware raw command previews for Bash, with honest multi-line and width truncation markers;
|
|
65
|
+
- shell-wide running duration after the two-second progress threshold, with lifecycle-safe refresh disposal and no permanent completion timer;
|
|
66
|
+
- path links and consistent search flags/limits across built-in renderers;
|
|
67
|
+
- Diff statistics plus a ten-line collapsed Diff preview for `edit`, with the complete Diff restored on expand;
|
|
68
68
|
- syntax highlighting;
|
|
69
69
|
- image output and Kitty conversion;
|
|
70
70
|
- native collapsed/expanded handling;
|
|
71
|
-
- custom UI explicitly using `renderShell: "self"
|
|
71
|
+
- custom UI explicitly using `renderShell: "self"`;
|
|
72
|
+
- independently refreshed custom elapsed time and retry countdowns without a duplicate generic progress row.
|
|
72
73
|
|
|
73
|
-
`edit`
|
|
74
|
+
Built-in result truncation hints share the same `… (N earlier/more lines, … to expand)` language and correct singular/plural forms. `edit` uses the native outer shell while keeping its asynchronous Diff preview and final Diff result.
|
|
74
75
|
|
|
75
76
|
## Deliberately rejected approaches
|
|
76
77
|
|
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`:
|