@foliox/transparent-compact-pi 0.10.0 → 0.11.2
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 +14 -0
- package/README.md +75 -242
- package/docs/DESIGN.md +69 -59
- package/extensions/index.ts +36 -195
- package/extensions/lib/checkpoint-cap.ts +28 -27
- package/extensions/lib/tool-stubs/display.mjs +21 -0
- package/extensions/lib/tool-stubs/inputs.mjs +12 -0
- package/extensions/lib/tool-stubs/locations.mjs +42 -0
- package/extensions/lib/tool-stubs/parse.mjs +39 -0
- package/extensions/lib/tool-stubs/parser/LICENSE.Go +27 -0
- package/extensions/lib/tool-stubs/parser/LICENSE.mvdan-sh +27 -0
- package/extensions/lib/tool-stubs/parser/NOTICE.md +13 -0
- package/extensions/lib/tool-stubs/parser/PATENTS.Go +22 -0
- package/extensions/lib/tool-stubs/parser/build.json +12 -0
- package/extensions/lib/tool-stubs/parser/go.mod +5 -0
- package/extensions/lib/tool-stubs/parser/go.sum +2 -0
- package/extensions/lib/tool-stubs/parser/main.go +36 -0
- package/extensions/lib/tool-stubs/parser/shell.wasm +0 -0
- package/extensions/lib/tool-stubs/parser/wasm_exec.js +575 -0
- package/extensions/lib/tool-stubs/renderer.mjs +53 -0
- package/extensions/lib/tool-stubs/shell.mjs +251 -0
- package/package.json +6 -2
- package/skills/context-retrieval/SKILL.md +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.11.0
|
|
4
|
+
|
|
5
|
+
- Use shared location IDs and AST-based skeletons for long bash tool calls.
|
|
6
|
+
Keep short commands literal and unknown tools generic; remove non-payload
|
|
7
|
+
arguments from known tools. Preserve historical outcome observations.
|
|
8
|
+
- Keep the location dictionary near the checkpoint end, with stable branch-local
|
|
9
|
+
IDs across compaction, resume, fork and turn-mode changes. Count dictionary
|
|
10
|
+
cost under the cap and omit unused definitions after filtering or trimming.
|
|
11
|
+
- Bundle the official mvdan/sh parser and typed-JSON encoder as WebAssembly,
|
|
12
|
+
using a small in-package bridge. No third-party npm parser wrapper, runtime
|
|
13
|
+
downloads, Go installation, or external shfmt executable is required.
|
|
14
|
+
- Remove version-comparison harnesses and comparison-only runtime diagnostics;
|
|
15
|
+
test tool rendering directly against production modules.
|
|
16
|
+
|
|
3
17
|
## 0.10.0
|
|
4
18
|
|
|
5
19
|
- Clarify the context readout: label delta as net, show measured tail inclusion,
|
package/README.md
CHANGED
|
@@ -1,306 +1,139 @@
|
|
|
1
1
|
# transparent-compact
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
recovery. Replaces Pi's model-generated compaction summary with a verbatim
|
|
5
|
-
compaction, with a checkpoint built mechanically from conversation text. Thinking and most tool outputs are removed
|
|
6
|
-
from the active model context, while user inputs, assistant text and selected startup reads are retained verbatim.
|
|
7
|
-
Tool calls and custom messages are reduced to short stubs; custom-message bodies remain recoverable from the session.
|
|
8
|
-
Verbatim compaction itself makes no model call. When a missing detail is needed, `context_lookup` runs a subagent over the session's
|
|
9
|
-
full raw branch and returns only relevant findings.
|
|
10
|
-
The goal is to let the agent withstand many (but finite) rounds of compaction without the copy-of-a-copy degradation of model-summary compaction, which is exacerbated in sub-frontier models.
|
|
3
|
+
[Context compaction](#control-compaction) for [Pi](https://pi.dev/) that keeps conversation text verbatim instead of replacing it with a model-generated summary. It removes thinking and most tool output from the active context, while keeping user messages, assistant text, compact tool-call stubs and selected startup reads. The original session history remains available.
|
|
11
4
|
|
|
12
|
-
|
|
5
|
+
When the agent needs a detail that is no longer in context, it can use retrieval tools to search the recorded session with a subagent. Compaction itself does not make a model call.
|
|
13
6
|
|
|
14
|
-
The
|
|
7
|
+
The user can also [selectively manipulate which turns to hold in the current context](#filter-turns) in higher or lower fidelity.
|
|
15
8
|
|
|
16
|
-
|
|
17
|
-
-
|
|
9
|
+
This extension is aimed at addressing two main issues that other compaction techniques face, which are especially exacerbated in agents running on lightweight and local LLMs:
|
|
10
|
+
- Model summaries such as Pi's default method can lead to degradation and confabulation of details that can cause confident blunders.
|
|
11
|
+
- Retrieval-based systems like `pi-vcc` can be effective when the agent knows what to look for, but omitting session structure from the retained context can make retrieval less reliable.
|
|
18
12
|
|
|
19
|
-
[This study](https://arxiv.org/abs/2610.20116)
|
|
20
|
-
this outperforms more complicated techniques with lightweight models, and is at least as effective with frontier models too.
|
|
21
|
-
It helps weaker models to avoid confabulating the historical context and to more carefully verify what it does and does not know.
|
|
13
|
+
`transparent-compact` is also a retrieval-based system, but its design keeps manipulation of conversation text to a minimum and maximises the agent's awareness of its compacted state, with the aim of avoiding confabulation and encouraging accurate retrieval of historical details. [This study](https://arxiv.org/abs/2610.20116) found that a minimal approach outperformed more complex techniques with lightweight models and was at least as effective with frontier models.
|
|
22
14
|
|
|
23
|
-
The
|
|
24
|
-
However it is also very practical for use with stronger models and larger context windows.
|
|
15
|
+
The verbatim compaction system plays particularly nicely with manual pruning of the context. This allows you to decide which parts of the session remain important to the current work, without having to commit to a particular branching point with /tree or decide at the time of the prompt with something like claude's /btw.
|
|
25
16
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
### Package installation
|
|
17
|
+
The extension is particularly suited to capable local models with reasonably large context windows (over 128k tokens), such as Qwen 3.8 27B running on llama.cpp with an RTX 5090, but it is also effective with frontier models and larger context windows.
|
|
29
18
|
|
|
30
|
-
Install
|
|
19
|
+
## Install
|
|
31
20
|
|
|
32
21
|
```bash
|
|
33
22
|
pi install npm:@foliox/transparent-compact-pi
|
|
34
23
|
```
|
|
35
24
|
|
|
36
|
-
|
|
25
|
+
Alternatively, install from GitHub or a local checkout:
|
|
37
26
|
|
|
38
27
|
```bash
|
|
39
28
|
pi install git:github.com/felixwoolford/transparent-compact-pi
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
or from a downloaded or cloned checkout:
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
29
|
pi install /absolute/path/to/transparent-compact
|
|
47
30
|
```
|
|
48
31
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
Pi's compaction uses transparent-compact by default once the extension is loaded.
|
|
52
|
-
To compact manually:
|
|
32
|
+
Once loaded, the extension uses verbatim compaction by default. Pi's automatic compaction continues to work, using the extension's configured method; to compact manually, enter:
|
|
53
33
|
|
|
54
34
|
```text
|
|
55
35
|
/compact
|
|
56
36
|
```
|
|
57
37
|
|
|
58
|
-
The
|
|
59
|
-
ends with an evidence-boundary warning. Task-relevant recovery reminders and a
|
|
60
|
-
brief recovery recap follow **the retained recent history and any pending new
|
|
61
|
-
user input**. This is instruction delivery, not a guarantee of model compliance.
|
|
38
|
+
No additional setup is required. The agent can recover missing details from session history as needed. Successful startup reads referenced by filename in `AGENTS.md` or `CLAUDE.md` are also retained when detected; this is a filename-matching heuristic, so it may not capture every relevant read.
|
|
62
39
|
|
|
63
|
-
|
|
64
|
-
retrievable. Recovery guidance explicitly names uncertain provenance (where a
|
|
65
|
-
finding came from or why a conclusion was reached) and contradictions between
|
|
66
|
-
earlier notes and new evidence.
|
|
40
|
+
## Filter turns
|
|
67
41
|
|
|
68
|
-
|
|
42
|
+
Use these commands while the agent is idle:
|
|
69
43
|
|
|
70
44
|
```text
|
|
71
|
-
/filter-turns # edit
|
|
72
|
-
/compact-filtered #
|
|
45
|
+
/filter-turns # edit an existing checkpoint
|
|
46
|
+
/compact-filtered # compact first, then open the editor
|
|
73
47
|
```
|
|
74
48
|
|
|
75
|
-
`/compact-filtered`
|
|
76
|
-
turn settings, **before** opening the `/filter-turns` editor. Cancelling that editor
|
|
77
|
-
leaves the completed compaction intact. If Pi has nothing new to compact, the command
|
|
78
|
-
opens the existing checkpoint instead. Cancelling compaction itself (including its
|
|
79
|
-
size-cap dialog), or a compaction failure, does not open the editor. No special
|
|
80
|
-
filtering step runs inside the compaction hook.
|
|
81
|
-
|
|
82
|
-
In the interactive terminal, the editor opens a framed checklist of user turns, with
|
|
83
|
-
a highlighted cursor, action labels and a separate fixed controls area. The review
|
|
84
|
-
step summarizes mode changes; a live estimated context readout stays visible on
|
|
85
|
-
both selection and review screens.
|
|
86
|
-
Each choice applies to a user message and everything following it until the next
|
|
87
|
-
user message, including turns spanning multiple compactions.
|
|
88
|
-
|
|
89
|
-
| Symbol | Mode | Active context |
|
|
90
|
-
| --- | --- | --- |
|
|
91
|
-
| `[X]` | **PRUNED** | A positioned filtering marker only |
|
|
92
|
-
| `[ ]` | **PROSE** | Our standard mechanical compaction, including compact tool stubs |
|
|
93
|
-
| `[○]` | **PROSE+TOOLS** | Original conversation text and complete recorded tool arguments/results; thinking markers only |
|
|
94
|
-
| `[■]` | **FULL** | Original conversation content, including all recorded thinking and image attachments |
|
|
95
|
-
| `[-]` | **LOCKED** | Unavailable; not a fifth fidelity mode |
|
|
49
|
+
Use `/compact-filtered` if there is no checkpoint yet. Cancelling its editor does not undo the compaction that just completed. If there is nothing new to compact, it opens the existing checkpoint.
|
|
96
50
|
|
|
97
|
-
|
|
51
|
+
Each selection covers a user message and all following activity up to the next user message:
|
|
98
52
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
53
|
+
| Mode | What stays in context |
|
|
54
|
+
| --- | --- |
|
|
55
|
+
| **PRUNED** `[X]` | A marker in place of the turn |
|
|
56
|
+
| **PROSE** `[ ]` | Conversation text and compact tool stubs |
|
|
57
|
+
| **PROSE+TOOLS** `[○]` | Conversation text and recorded tool arguments and results; thinking markers only |
|
|
58
|
+
| **FULL** `[■]` | All recorded content, including thinking and images |
|
|
59
|
+
| **LOCKED** `[-]` | Not available for editing |
|
|
103
60
|
|
|
104
|
-
|
|
105
|
-
provider tokenization.
|
|
106
|
-
|
|
107
|
-
Use **↑/↓** to navigate and **←/→** to collapse/expand details for the selected
|
|
108
|
-
mode. **Space** prunes any kept mode, or restores a pruned turn as PROSE. **f** cycles
|
|
109
|
-
PRUNED → PROSE → PROSE+TOOLS → FULL → PRUNED. Both keys act on the owning whole turn
|
|
110
|
-
when an agent/tool subentry is focused. **Enter** opens a complete, scrollable
|
|
111
|
-
change preview; **Enter** again confirms, **Esc** goes back or cancels.
|
|
112
|
-
|
|
113
|
-
Filtering requires verbatim mode and an idle agent. Turns overlapping Pi's retained
|
|
114
|
-
recent tail cannot be removed yet: filtering never removes only half a turn or
|
|
115
|
-
changes Pi's retention boundary. Content inside an opaque inherited summary cannot be
|
|
116
|
-
selected individually.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
`/filter-turns` requires an existing verbatim checkpoint
|
|
120
|
-
and works even when there is no new history to compact. It saves a reversible,
|
|
121
|
-
branch-local checkpoint revision without moving the retained boundary or starting
|
|
122
|
-
an agent turn. PROSE restoration uses the canonical spans, startup reads and file
|
|
123
|
-
operations and remains subject to the size cap. PROSE+TOOLS/FULL instead reinsert
|
|
124
|
-
original messages at their chronological positions, replacing their compacted
|
|
125
|
-
copies and any duplicate startup-read copies. Explicit context omissions and
|
|
126
|
-
replacements remain respected. Complete tool-call/result groups are required.
|
|
127
|
-
Before the first checkpoint, use `/compact-filtered`.
|
|
128
|
-
|
|
129
|
-
Full-fidelity choices persist through later verbatim compactions and reload/resume.
|
|
130
|
-
Their content is **never silently shortened by the prose cap**. Estimated native
|
|
131
|
-
message cost is treated as fixed overhead; only PROSE can be trimmed. The extension
|
|
132
|
-
checks the model context budget before saving and on actual requests, reserving
|
|
133
|
-
output/framing headroom. Oversized selections are rejected; if later context growth
|
|
134
|
-
or a model change makes existing choices too large, the request is aborted with
|
|
135
|
-
instructions to downgrade turns through `/filter-turns`. Large full-fidelity turns
|
|
136
|
-
can therefore prevent automatic compaction from freeing enough space. Token counts
|
|
137
|
-
are estimates, not provider tokenization guarantees.
|
|
138
|
-
|
|
139
|
-
FULL means all content actually recorded, not unavailable internal reasoning or
|
|
140
|
-
unrecorded nested-tool outputs. Pi's normal model/provider transformations still
|
|
141
|
-
apply: changing models can convert/drop signed or encrypted thinking, and non-vision
|
|
142
|
-
models cannot receive images. Switching to summary compaction still weakens the
|
|
143
|
-
verbatim guarantee; its summarizer receives the expanded recorded text.
|
|
144
|
-
|
|
145
|
-
Each excluded group becomes `[Turn manually filtered]`. Its retained startup reads
|
|
146
|
-
and file-list paths used only in excluded turns are removed too. The checkpoint
|
|
147
|
-
and post-compaction reorientation explain the marker only when filtering is present.
|
|
148
|
-
Exclusions follow the active branch through later verbatim compactions, reload and
|
|
149
|
-
resume. Original session entries remain unchanged and recoverable; filtering does
|
|
150
|
-
not undo file changes. Ordinary `/compact` never applies new pre-flags or opens the
|
|
151
|
-
picker. Automatic compactions apply new pre-flags only when explicitly enabled below.
|
|
152
|
-
|
|
153
|
-
### Pre-flag an aside and optionally apply flags automatically
|
|
61
|
+
Navigate with **↑/↓**; use **←/→** to collapse or expand details. Press **Space** to prune a turn or restore it to PROSE, or **f** to cycle through all four modes. Press **Enter** to review changes, then **Enter** again to save; **Esc** goes back or cancels. The editor shows an estimated context size as you choose.
|
|
154
62
|
|
|
155
|
-
|
|
156
|
-
/filter-later <message> # normal user turn, pre-checked in either filtering command
|
|
157
|
-
/fl <message> # short alias for /filter-later
|
|
158
|
-
/filter-auto # report current policy (default off)
|
|
159
|
-
/filter-auto on # apply pre-flags during threshold/overflow compaction
|
|
160
|
-
/filter-auto off # stop applying new pre-flags automatically
|
|
161
|
-
```
|
|
63
|
+
You can restore filtered turns later. Choices persist in the current session branch through later verbatim compactions and reloads. Turns overlapping Pi's retained recent history are locked until they can be filtered as a whole; individual content inside an inherited summary cannot be selected.
|
|
162
64
|
|
|
163
|
-
|
|
164
|
-
agent/tool activity remain in normal context until the entire group is eligible
|
|
165
|
-
for filtering. It is not an isolated `/btw` conversation. In `/filter-turns` or
|
|
166
|
-
`/compact-filtered`, you can uncheck the aside before exclusion, or restore it afterward.
|
|
65
|
+
PROSE+TOOLS and FULL can use substantial context. Oversized selections are rejected, and if later context growth or a model change makes them too large, use `/filter-turns` to downgrade them. FULL includes only what was recorded; provider and model limitations can still affect thinking and images.
|
|
167
66
|
|
|
67
|
+
### Flag an aside
|
|
168
68
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
tail are not duplicated. If compaction happens before the second prompt, collection
|
|
177
|
-
continues until that prompt arrives.
|
|
178
|
-
|
|
179
|
-
This is a literal filename-matching heuristic, not an interpretation of required
|
|
180
|
-
reading. It does not capture every possible reference or fill in incomplete reads.
|
|
69
|
+
```text
|
|
70
|
+
/filter-later <message> # send a turn and flag it for filtering
|
|
71
|
+
/fl <message> # short alias
|
|
72
|
+
/filter-auto # show automatic filtering policy
|
|
73
|
+
/filter-auto on # apply flags during automatic compaction
|
|
74
|
+
/filter-auto off # stop automatically applying new flags
|
|
75
|
+
```
|
|
181
76
|
|
|
182
|
-
|
|
77
|
+
A flagged turn remains in context until it is eligible for filtering. It is preselected for pruning in the editor, where you can keep or later restore it. Automatic application of flags is **off** by default. `/fl` is a normal conversation turn, not an isolated aside.
|
|
183
78
|
|
|
184
|
-
|
|
185
|
-
160→120→80-character previews, then grouped tool-only prefixes. Only if those stages
|
|
186
|
-
cannot make it fit does it remove conversation content. `tools-tightened` marks presentation changes; `trimmed` marks actual
|
|
187
|
-
omissions. Earlier structured spans can be tightened in the new checkpoint without
|
|
188
|
-
editing their stored originals; disabling the cap restores their normal rendering.
|
|
189
|
-
Text-only legacy spans use a conservative fallback.
|
|
190
|
-
See [how cap trimming works](docs/DESIGN.md#how-cap-trimming-works) for the full order.
|
|
191
|
-
This is meant as a fallback option for allowing compaction rounds to run far in excess of the intended use case, and should probably be used to allow work to be wrapped up before handing off to a new session.
|
|
192
|
-
If you find that in normal usage you frequently work over the compaction cap, other compaction tools are likely to be more suitable.
|
|
79
|
+
## Control compaction
|
|
193
80
|
|
|
194
|
-
|
|
195
|
-
the current model's context window, using **4 characters per token**, not an
|
|
196
|
-
exact tokenizer. When tightening or omission would be needed, choose **Apply trimming**,
|
|
197
|
-
**Disable cap for this session**, **Change budget**, or **Cancel compaction**. Disabling persists as `off`, rather than
|
|
198
|
-
bypassing just once.
|
|
81
|
+
### Choose the method
|
|
199
82
|
|
|
200
83
|
```text
|
|
201
|
-
/
|
|
202
|
-
/
|
|
203
|
-
/
|
|
204
|
-
/cap-compaction off # disable cap-based trimming
|
|
205
|
-
/cap-compaction warn 20000t # estimated tokens
|
|
206
|
-
/cap-compaction warn 25% # percentage of model context window
|
|
207
|
-
/cap-compaction on 80000c # the original character guard
|
|
84
|
+
/compaction-method # show current method
|
|
85
|
+
/compaction-method verbatim # extension's compaction (default)
|
|
86
|
+
/compaction-method summary # Pi's built-in summary compaction
|
|
208
87
|
```
|
|
209
88
|
|
|
210
|
-
|
|
211
|
-
such as `/cap-compaction 40000c` also works. Both settings persist in the session
|
|
212
|
-
and follow branch history through reload, resume, fork, and tree navigation.
|
|
213
|
-
They apply only to verbatim compaction, not summary compaction, and do not change
|
|
214
|
-
Pi's auto-compaction enabled setting.
|
|
215
|
-
|
|
216
|
-
Tokens are estimated with `ceil(chars / 4)`, not an exact tokenizer. For a
|
|
217
|
-
192,000-token window, `25%` gives 48,000 estimated tokens, equivalent to 192,000
|
|
218
|
-
characters.
|
|
219
|
-
|
|
220
|
-
The budget is a size guard, not a guarantee that the whole model context fits.
|
|
221
|
-
Instructions and file lists remain outside it. Retained startup reads count as
|
|
222
|
-
fixed overhead but are never trimmed; if they alone exceed the budget, the
|
|
223
|
-
extension warns and keeps them. Disabling the cap still removes thinking and
|
|
224
|
-
unselected tool outputs and abbreviates tool-call signatures.
|
|
225
|
-
It may leave too much context for the model, particularly during overflow recovery.
|
|
226
|
-
|
|
227
|
-
With no interactive UI, `warn` emits a warning and applies the cap. TUI and
|
|
228
|
-
supported RPC clients can answer the dialogs. In interactive sessions, `warn`
|
|
229
|
-
can wait for an answer even during automatic compaction; use `/cap-compaction on`
|
|
230
|
-
for unattended operation. If a percentage cannot be resolved because the model's
|
|
231
|
-
context window is unavailable, compaction is cancelled: choose a character/token
|
|
232
|
-
budget or turn the cap off.
|
|
89
|
+
The selection applies to manual and automatic compaction, including overflow recovery, and persists in the session branch. New sessions default to verbatim. Manual filtering requires verbatim mode.
|
|
233
90
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
No separate configuration file is required. Set environment variables before
|
|
237
|
-
starting Pi:
|
|
238
|
-
|
|
239
|
-
| Variable | Default | Meaning |
|
|
240
|
-
|---|---|---|
|
|
241
|
-
| `MECH_COMPACT_MAX_SUMMARY_CHARS` | Unset (uses percentage budget) | Initial conversation-and-retained-reads character budget override; takes precedence over the percentage setting. |
|
|
242
|
-
| `MECH_COMPACT_MAX_SUMMARY_PERCENT` | `25` | Initial percentage of the model's context window, using estimated tokens. Accepts numbers greater than 0 and at most 100, including decimals; invalid values fall back to 25. |
|
|
243
|
-
| `MECH_COMPACT_LOOKUP_MODEL` | Session model | Optional `provider/modelId` for lookups; must support tool calls and be available in Pi. An unresolved model falls back to the session model. |
|
|
244
|
-
| `MECH_COMPACT_LOOKUP_TURNS` | `25` | Maximum substantive search turns. Valid continuation-only turns are exempt; total search-phase model calls are capped at 3× this budget (75 by default), plus one tool-free write-up on exhaustion. |
|
|
245
|
-
| `MECH_COMPACT_LOOKUP_MAX_CALLS` | `1` | Maximum consecutive lookup attempts. `0` means unlimited; see [recovery reset rules](docs/DESIGN.md#recover-historical-details). Invalid values fall back to 1. |
|
|
246
|
-
| `MECH_COMPACT_LOOKUP_SESSION_FILE` | Unset | Optional absolute path to a full session JSONL, replacing the current branch as the lookup source. Intended for harnesses using pruned forks. |
|
|
91
|
+
### Set the size cap
|
|
247
92
|
|
|
248
|
-
|
|
249
|
-
|
|
93
|
+
By default, the extension warns before trimming a checkpoint that exceeds an estimated **25% of the model's context window**. The interactive prompt lets you apply trimming, disable the cap for the session, change the budget, or cancel compaction. Capping works by progressively reducing the size of tool stubs and then as a last resort truncating assistant prose and finally truncating user prose. With normal use, this shouldn't occur until over a dozen compactions.
|
|
94
|
+
If you regularly reach the cap, consider starting a new session or using a different compaction method that is more suited to your workflow.
|
|
250
95
|
|
|
251
|
-
For a different percentage default, with the character override unset:
|
|
252
96
|
|
|
253
|
-
```
|
|
254
|
-
|
|
97
|
+
```text
|
|
98
|
+
/cap-compaction # show mode and budget
|
|
99
|
+
/cap-compaction warn # prompt before trimming (default)
|
|
100
|
+
/cap-compaction on # trim without prompting
|
|
101
|
+
/cap-compaction off # disable cap-based trimming
|
|
102
|
+
/cap-compaction warn 20000t # estimated token budget
|
|
103
|
+
/cap-compaction warn 25% # percentage of model context window
|
|
104
|
+
/cap-compaction on 80000c # character budget
|
|
105
|
+
/cap-compaction 40000c # change budget without changing mode
|
|
255
106
|
```
|
|
256
107
|
|
|
257
|
-
|
|
108
|
+
Mode and budget persist in the session branch; changing one leaves the other unchanged. They apply only to verbatim compaction. The cap estimates tokens at four characters each and is not a limit on the whole model context. Some content, including retained startup reads, is not trimmed. Disabling the cap may leave too much context for the model.
|
|
258
109
|
|
|
259
|
-
|
|
260
|
-
MECH_COMPACT_MAX_SUMMARY_CHARS=40000 pi
|
|
261
|
-
```
|
|
110
|
+
For unattended use, choose `on` to avoid interactive prompts. Without an interactive UI, `warn` emits a warning and applies the cap. If the model's context window is unavailable, use a fixed token or character budget, or turn the cap off.
|
|
262
111
|
|
|
263
|
-
|
|
264
|
-
Use `/cap-compaction` to change the session budget or mode without restarting. The
|
|
265
|
-
session-file override is checked at each lookup. Restart Pi after changing its
|
|
266
|
-
launching environment; `/reload` does not change inherited environment variables.
|
|
112
|
+
## Configuration
|
|
267
113
|
|
|
268
|
-
|
|
269
|
-
opens that file with `SessionManager.open()` and renders its branch. Relative,
|
|
270
|
-
missing, empty, or invalid source files fail explicitly rather than silently
|
|
271
|
-
searching the pruned fork. Opening a legacy file may trigger Pi's normal session
|
|
272
|
-
migration. The override is extension configuration, not a tool argument or a
|
|
273
|
-
filesystem search route for the main agent.
|
|
114
|
+
No configuration file is needed. Set these environment variables before starting Pi:
|
|
274
115
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
116
|
+
| Variable | Default | Purpose |
|
|
117
|
+
| --- | --- | --- |
|
|
118
|
+
| `MECH_COMPACT_MAX_SUMMARY_PERCENT` | `25` | Initial cap as a percentage of the model's context window (greater than 0, up to 100). |
|
|
119
|
+
| `MECH_COMPACT_MAX_SUMMARY_CHARS` | Unset | Initial fixed character budget; overrides the percentage. |
|
|
120
|
+
| `MECH_COMPACT_LOOKUP_MODEL` | Session model | Lookup model as `provider/modelId`; it must be available in Pi and support tool calls. An unresolved model falls back to the session model. |
|
|
121
|
+
| `MECH_COMPACT_LOOKUP_TURNS` | `25` | Maximum substantive search turns per lookup. |
|
|
122
|
+
| `MECH_COMPACT_LOOKUP_MAX_CALLS` | `3` | Maximum consecutive lookup attempts; `0` means unlimited. |
|
|
123
|
+
| `MECH_COMPACT_LOOKUP_SESSION_FILE` | Unset | Absolute path to a full session JSONL to search instead of the current branch, for harnesses using pruned forks. Leave unset for ordinary use. |
|
|
279
124
|
|
|
280
|
-
|
|
125
|
+
For example:
|
|
281
126
|
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
/
|
|
285
|
-
/compaction-method summary
|
|
127
|
+
```bash
|
|
128
|
+
MECH_COMPACT_MAX_SUMMARY_PERCENT=30 pi
|
|
129
|
+
MECH_COMPACT_LOOKUP_MODEL=provider/modelId pi
|
|
286
130
|
```
|
|
287
131
|
|
|
288
|
-
`/compaction
|
|
289
|
-
|
|
290
|
-
The choice applies to manual `/compact`, automatic threshold compaction, and context-overflow recovery.
|
|
291
|
-
With no argument, the command reports the current method.
|
|
292
|
-
|
|
293
|
-
The choice persists in the existing session, follows branch history through
|
|
294
|
-
reload, resume, fork, and tree navigation, and needs no extra configuration file.
|
|
295
|
-
New sessions default to verbatim.
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
### Local inference engines
|
|
132
|
+
A session setting from `/cap-compaction` takes precedence over the environment defaults. Restart Pi after changing its launching environment; `/reload` cannot change inherited environment variables.
|
|
299
133
|
|
|
300
|
-
|
|
134
|
+
### Local inference
|
|
301
135
|
|
|
302
|
-
|
|
303
|
-
- **Other engines**: make sure the main session's prefix survives lookup calls, via prefix caching (on by default in vLLM and SGLang), host-RAM KV offloading where available, or enough parallel capacity to keep both sessions resident. Engines without these will re-prefill the main session after every lookup.
|
|
136
|
+
Lookups using the session model can disrupt the main session's prompt cache. For a single-slot llama.cpp server (`-np 1`), enable `--cache-ram <MiB>` with enough host memory for the main session state. On other engines, use prefix caching, KV offloading, or sufficient parallel capacity to keep both sessions resident.
|
|
304
137
|
|
|
305
138
|
## License
|
|
306
139
|
|
package/docs/DESIGN.md
CHANGED
|
@@ -16,29 +16,75 @@ extension builds a checkpoint without changing that boundary or calling a model:
|
|
|
16
16
|
| Custom messages | Short type stubs marked `content removed`; bodies remain in the raw session. Managed re-orientation messages are regenerated instead. |
|
|
17
17
|
| Recent conversation | Pi keeps its normal verbatim tail. |
|
|
18
18
|
| Earlier compacted spans | Re-rendered chronologically, without repeated model summarization. |
|
|
19
|
-
| Read/modified file lists | Cumulative operation lists with checkpoint-relative retained-evidence annotations. |
|
|
20
19
|
|
|
21
20
|
New tool lines use `[Tools]:` with compact display signatures:
|
|
22
21
|
|
|
23
22
|
```text
|
|
24
|
-
read
|
|
25
|
-
write
|
|
26
|
-
edit
|
|
23
|
+
read @1:12-41
|
|
24
|
+
write @2 (2144 chars)
|
|
25
|
+
edit @1 ×2
|
|
27
26
|
bash "uv run pytest -q 2>&1 | tail -25" → output: "3 failed, 16 passed in 0.21s"
|
|
27
|
+
bash{cd @3 && cargo test >@4 | tail}
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
30
|
+
Known tools use positive input selection: bash retains `command`; read retains
|
|
31
|
+
`path`, `offset` and `limit`; write/edit retain their path and payload-derived
|
|
32
|
+
sizes/counts. Other call arguments are omitted regardless of extension, including
|
|
33
|
+
non-null execution controls. Unknown tools keep bounded agnostic argument previews.
|
|
34
|
+
Read ranges describe requests, not returned coverage or symbol positions.
|
|
35
|
+
|
|
36
|
+
Quoted bash commands of at most 160 encoded characters stay literal, with cwd
|
|
37
|
+
shortening and escaped newlines. Longer commands use a full mvdan/sh AST to retain
|
|
38
|
+
commands, common subcommands, path operands, pipes, sequencing, redirects and
|
|
39
|
+
grouping. Flags and non-location arguments are generally omitted. Inline program
|
|
40
|
+
bodies become explicit `[inline]`/`[body]` markers with bounded lexical path mentions;
|
|
41
|
+
these are not effect analysis. Unsupported, oversized or malformed shell input
|
|
42
|
+
falls back to a head-only literal preview, still without execution metadata.
|
|
43
|
+
|
|
44
|
+
A shared `<locations>` dictionary near the checkpoint end resolves `@N` IDs.
|
|
45
|
+
IDs are append-only and branch-local, persisted in compaction details so resume,
|
|
46
|
+
fork, filtering/restoration and repeated compaction do not renumber old references.
|
|
47
|
+
Definitions are rendered only for surviving structured tool references, never
|
|
48
|
+
discovered by regex-scanning prose. Canonical metadata keeps the
|
|
49
|
+
complete registry so restoring a turn or disabling the cap restores its definitions.
|
|
50
|
+
Raw command/program payloads are not copied into display records.
|
|
51
|
+
|
|
52
|
+
The cap counts dictionary characters, including their removal when a call is
|
|
53
|
+
trimmed. Unused definitions are omitted after pruning, native-turn replacement
|
|
54
|
+
and capping. Skeletons are not
|
|
55
|
+
shortened into partial syntax. Literal previews can tighten to 120 then 80 encoded
|
|
56
|
+
characters before adjacent tool-only prefixes are grouped and destructive trimming
|
|
57
|
+
starts. Calls remain independently removable and ordered.
|
|
58
|
+
|
|
59
|
+
All signatures are display notation, not replayable commands or tool arguments.
|
|
60
|
+
No command diffs or read folding are performed.
|
|
61
|
+
|
|
62
|
+
**Parser dependency and rebuilds.** `extensions/lib/tool-stubs/parser/go.mod`
|
|
63
|
+
pins the official `mvdan.cc/sh/v3` module at `v3.14.1`. Our small Go bridge calls
|
|
64
|
+
`syntax.NewParser` and upstream's `syntax/typedjson.Encode` directly; the renderer
|
|
65
|
+
consumes that upstream JSON format without an intermediate AST schema. It does
|
|
66
|
+
not import an interpreter. The JavaScript loader initializes the bundled WASM
|
|
67
|
+
lazily, once, with Go's globals isolated from Pi. There are no npm parser
|
|
68
|
+
runtime dependencies, external executables, downloads, or target-file reads.
|
|
69
|
+
|
|
70
|
+
Checked-in WASM keeps npm and Git installs self-contained. Rebuild with Go
|
|
71
|
+
1.27.3 available on PATH:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
npm run build:shell-parser
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The build uses pinned module checksums, `-trimpath`, no VCS stamping and no build
|
|
78
|
+
ID. It copies the matching Go support script unmodified. `parser/build.json`
|
|
79
|
+
records source/asset hashes and toolchain/upstream versions; tests detect stale
|
|
80
|
+
sources or assets. The bundled Go and mvdan/sh licenses are in that directory.
|
|
81
|
+
Go is a build-only requirement; users do not need it.
|
|
82
|
+
|
|
83
|
+
**Development experiment — dictionary placement:** keep the shared dictionary at
|
|
84
|
+
the end for now, preserving the checkpoint's start for session-start information.
|
|
85
|
+
Compare dictionary-first versus dictionary-last in independent behavioural tests;
|
|
86
|
+
prompt-order research is suggestive, not a direct evaluation of this format. Do
|
|
87
|
+
not duplicate the dictionary without evidence that the extra context cost helps.
|
|
42
88
|
|
|
43
89
|
`[tool error]` means a safely matched result was flagged as an error; `[unknown]`
|
|
44
90
|
means no safely matched result/status. Plain successes have no status label; this
|
|
@@ -112,16 +158,16 @@ A group includes all activity until the next raw user message, even across multi
|
|
|
112
158
|
compaction spans. Confirmed exclusions are stored as the current `filteredTurnIds`
|
|
113
159
|
snapshot on the compaction entry or its standalone revision, not an append-only
|
|
114
160
|
union. Later verbatim checkpoints apply that branch-local selection to the original canonical spans before size
|
|
115
|
-
trimming, reindexing tool display records without changing stored history.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
also restores its retained-read copies and
|
|
161
|
+
trimming, reindexing tool display records without changing stored history.
|
|
162
|
+
Startup-read snapshots in compaction details remain canonical and unfiltered;
|
|
163
|
+
only the rendered checkpoint masks them. Restoring a turn therefore
|
|
164
|
+
also restores its retained-read copies and location definitions without re-reading
|
|
119
165
|
files or reselecting startup evidence. There is no migration or reconstruction of
|
|
120
166
|
saved spans without turn ownership; opaque content is not individually selectable.
|
|
121
167
|
|
|
122
168
|
One `[Turn manually filtered]` marker replaces each excluded group at its original
|
|
123
169
|
position, even across spans. Markers survive the size cap. Startup-read copies owned
|
|
124
|
-
by the group are excluded;
|
|
170
|
+
by the group are excluded; location definitions used only by excluded turns are removed.
|
|
125
171
|
Filtering does not undo filesystem mutations. The checkpoint introduction and
|
|
126
172
|
persistent reorientation conditionally explain that the user excluded low-value
|
|
127
173
|
context, which remains retrievable from the full raw history. Recovery tools are
|
|
@@ -142,7 +188,7 @@ receive the revision. The checkpoint size guard applies before a revision is sav
|
|
|
142
188
|
Reload/resume and tree navigation select revisions from the raw active branch.
|
|
143
189
|
The next real verbatim compaction inherits their choices and supersedes the old
|
|
144
190
|
revision; model-summary compaction is also given the revised previous summary and
|
|
145
|
-
file
|
|
191
|
+
file-operation metadata rather than stale saved checkpoint content. Cancelling the picker or
|
|
146
192
|
size-cap decision saves no filtering revision. No-op confirmation writes nothing.
|
|
147
193
|
|
|
148
194
|
`/filter-later <message>` (alias `/fl`) submits an ordinary user message through Pi's user-message API.
|
|
@@ -258,42 +304,6 @@ a failed estimate), not on every toggle. Generation checks reject stale results,
|
|
|
258
304
|
closing/disposing the dialog invalidates pending work. No estimated sizes are
|
|
259
305
|
persisted in checkpoint metadata, and no model calls are introduced.
|
|
260
306
|
|
|
261
|
-
### File-list evidence annotations
|
|
262
|
-
|
|
263
|
-
The lists record reads and modifications in compacted history, not an exhaustive
|
|
264
|
-
inventory of current file contents. At every checkpoint, the extension checks
|
|
265
|
-
Pi's model-context projection from `firstKeptEntryId` onward. The turn prefix is
|
|
266
|
-
being compacted and is not treated as retained evidence. Context omissions and
|
|
267
|
-
replacements are respected; replacement read text has unknown completeness.
|
|
268
|
-
No filesystem reads or model calls are made for annotation.
|
|
269
|
-
|
|
270
|
-
Successful, unambiguously paired `read` results receive `(full read in tail)`,
|
|
271
|
-
`(partial read in tail)`, or `(read output in tail)` when completeness is uncertain.
|
|
272
|
-
For Pi's read contract, offset/limit alone does not imply partialness: an offset of
|
|
273
|
-
1 with a limit beyond EOF can still be complete. Truncation metadata and continuation
|
|
274
|
-
notices are checked. Separate partial pages are not combined into a full-file claim.
|
|
275
|
-
A later partial read does not hide an earlier complete snapshot with no intervening
|
|
276
|
-
tracked modification.
|
|
277
|
-
|
|
278
|
-
Successful writes with a visible full payload receive `(write content in tail)`.
|
|
279
|
-
Recorded subsequent edits/writes invalidate earlier snapshots and produce labels
|
|
280
|
-
such as `(read in tail, then edited)`. Mutation metadata can invalidate a snapshot
|
|
281
|
-
even when the mutation's message was omitted, but cannot restore omitted source
|
|
282
|
-
contents. Nested calls can invalidate snapshots, not supply visible file contents.
|
|
283
|
-
Same-path sibling operations may run concurrently, so ambiguous read/write versus
|
|
284
|
-
mutation ordering receives `(read in tail; order uncertain)` or the write equivalent
|
|
285
|
-
instead of treating result order as proof of freshness.
|
|
286
|
-
|
|
287
|
-
Modified paths without retained read/write evidence receive `(no read-tool output
|
|
288
|
-
in tail)`, unless a selected startup read is retained separately. Startup reads
|
|
289
|
-
keep their existing positive annotation. Unmodified paths without established
|
|
290
|
-
retained evidence remain unannotated; the read-list header states the default once:
|
|
291
|
-
"unless annotated, no retained read-tool output identified". A bare path does not
|
|
292
|
-
establish that document contents are still visible. The shared explanation states that labels
|
|
293
|
-
apply as of this checkpoint, not to live filesystem state; shell reads/changes and
|
|
294
|
-
external modifications are not inferred. File contents are never duplicated into
|
|
295
|
-
these lists, and annotations are recomputed rather than persisted as file metadata.
|
|
296
|
-
|
|
297
307
|
### Retained startup reads
|
|
298
308
|
|
|
299
309
|
On the first verbatim compaction, the extension scans successful text-only `read`
|
|
@@ -512,7 +522,7 @@ instructions that must be prominent at the actual point of resumption:
|
|
|
512
522
|
|
|
513
523
|
```text
|
|
514
524
|
Checkpoint introduction: what was removed + full recovery instructions
|
|
515
|
-
All compacted spans (oldest first), then retained startup reads and
|
|
525
|
+
All compacted spans (oldest first), then retained startup reads and location dictionary
|
|
516
526
|
One evidence-boundary warning + start-of-verbatim-tail marker
|
|
517
527
|
Retained verbatim tail
|
|
518
528
|
Any pending new user input
|