@foliox/transparent-compact-pi 0.9.3 → 0.11.1

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 CHANGED
@@ -1,5 +1,80 @@
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
+
17
+ ## 0.10.0
18
+
19
+ - Clarify the context readout: label delta as net, show measured tail inclusion,
20
+ and show combined notice-cost changes after the tail as `+~N scaffolding`,
21
+ without a separate row or breakdown. Keep the last completed readout visible
22
+ during recalculation to avoid loading/color flashes on each selection.
23
+ Remove the `reply/framing` label.
24
+ Replace `cap warn` labels with plain-language size-limit information only when
25
+ the preview was actually shortened. Add small-turn/adjacent-user regressions
26
+ reconciling content savings with generated-notice overhead.
27
+
28
+ - Add a live whole-context size readout to turn selection and review: estimated
29
+ input tokens/window usage, delta from saved context, and reserve-aware headroom.
30
+ Preview the actual capped checkpoint and native expansions with current
31
+ system/tool overhead, without dialogs, writes or model calls. Discard stale
32
+ estimates and label unavailable sizes rather than inventing zero-token counts.
33
+
34
+ - Simplify `/compact-filtered` to ordinary compaction followed by the shared
35
+ `/filter-turns` editor. The checkpoint is committed before selection; cancelling
36
+ the picker leaves that compaction intact. With nothing new to compact, edit the
37
+ existing checkpoint instead. Failed/cancelled compactions never open controls.
38
+ Remove the special interactive compaction-hook path and its request sentinel.
39
+
40
+ - Add whole-turn context modes: `[X] PRUNED`, `[ ] PROSE`, `[○] PROSE+TOOLS`, and
41
+ `[■] FULL`; preserve `[-] LOCKED`. Space retains the prune/restore shortcut;
42
+ `f` cycles modes, including from agent/tool subentries. Preview native content,
43
+ explicit mode transitions and estimated token growth.
44
+ - Reinsert selected original messages at their chronological positions without
45
+ compacted/startup-read duplicates. PROSE+TOOLS retains complete recorded tools
46
+ with thinking markers; FULL retains recorded thinking/signatures and images.
47
+ Persist reversible branch-local choices through reload and later compactions,
48
+ respect explicit context edits, protect native turns from trimming, and reject
49
+ oversized selections rather than silently losing fidelity. Normal provider
50
+ compatibility transformations still apply.
51
+
52
+ - Clarify the filtering TUI with framed selection/review steps, a highlighted
53
+ focused row, numbered turns, semantic action labels and fixed keyboard controls.
54
+ Separate preview instructions from turn content and show a change summary.
55
+
56
+ - Add `/filter-turns` to immediately filter or restore an existing checkpoint,
57
+ without compacting additional history, moving the boundary or starting an agent
58
+ turn. Persist branch-local revisions, refresh reorientation for each revision,
59
+ and carry choices into later verbatim or summary compaction. Recent messages
60
+ remain untouched; pending pre-flags can still be cancelled.
61
+
62
+ - Add `/filter-later <message>` (alias `/fl`) to submit a normal user turn pre-flagged for future
63
+ filtering. Add branch-local `/filter-auto on|off` (default off) to apply eligible
64
+ user pre-flags during verbatim threshold/overflow compaction without a picker.
65
+ - Allow previously filtered turns to be unchecked and restored using `/filter-turns`
66
+ or manual filtered compaction. Preview restorations and pending-flag cancellations; preserve
67
+ canonical startup-read and file-operation metadata for reversible checkpoints.
68
+ Explicit keep/restore decisions prevent automatic re-filtering of the same aside.
69
+
70
+ - Add `/compact-filtered` for optional manual whole-turn filtering in the terminal:
71
+ ordinary compaction followed by tree-like selection and scrollable confirmation.
72
+ Cancelling turn edits leaves the completed compaction and original history intact. Replace excluded groups with `[Turn manually filtered]`, remove their
73
+ retained startup-read copies and exclusive file-list paths, and explain the
74
+ marker conditionally in the checkpoint and reorientation. Exclusions persist
75
+ through later verbatim compactions and follow the active branch; original
76
+ history remains recoverable. Recent-tail turns cannot be partially filtered.
77
+
3
78
  ## 0.9.3
4
79
 
5
80
  - Restore the `706b04b` advertisements for lookup, listing, and grep, including the
package/README.md CHANGED
@@ -1,233 +1,139 @@
1
1
  # transparent-compact
2
2
 
3
- Deterministic context compaction for [Pi](https://pi.dev/), with session-backed
4
- recovery. By default, 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
- The method is functionally similar to pi-vcc, but is specifically aimed at lighter weight models
13
- such as **Qwen 3.8 27B** or **GPT-6 Luna**. The design principle is that:
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.
14
6
 
15
- - All algorithmic or model-based manipulation of prose has the potential to confound the model later, and should be avoided for as long as possible.
16
- - History retrieval should be parsimonious, explicitly clear to the agent, and agnostic to the task and session structure.
7
+ The user can also [selectively manipulate which turns to hold in the current context](#filter-turns) in higher or lower fidelity.
17
8
 
18
- [This study](https://arxiv.org/abs/2610.20116) demonstrated that a minimal system like
19
- this outperforms more complicated techniques with lightweight models, and is at least as effective with frontier models too.
20
- It helps weaker models to avoid confabulating the historical context and to more carefully verify what it does and does not know.
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.
21
12
 
22
- The primary intended use case is on a strong local LLM with a reasonably large context window (>128k) : for example, through
23
- **Qwen 3.8 27B llama.cpp on an RTX 5090**.
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.
24
14
 
25
- ## Install
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.
26
16
 
27
- ### 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.
28
18
 
29
- Install from npm:
19
+ ## Install
30
20
 
31
21
  ```bash
32
22
  pi install npm:@foliox/transparent-compact-pi
33
23
  ```
34
24
 
35
- or from github:
25
+ Alternatively, install from GitHub or a local checkout:
36
26
 
37
27
  ```bash
38
28
  pi install git:github.com/felixwoolford/transparent-compact-pi
39
- ```
40
-
41
-
42
- or from a downloaded or cloned checkout:
43
-
44
- ```bash
45
29
  pi install /absolute/path/to/transparent-compact
46
30
  ```
47
31
 
48
- The extension entry point is `extensions/index.ts`, so Pi's compact extension list
49
- shows `@foliox/transparent-compact-pi` without a filename suffix for npm installs.
50
-
51
- ## Usage
52
-
53
- Pi's compaction uses transparent-compact by default once the extension is loaded.
54
- 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:
55
33
 
56
34
  ```text
57
35
  /compact
58
36
  ```
59
37
 
60
- The checkpoint begins with an explanation and full recovery instructions, and
61
- ends with an evidence-boundary warning. Task-relevant recovery reminders and a
62
- brief recovery recap follow **the retained recent history and any pending new
63
- user input**. They are saved in the session and remain available on later turns.
64
- After another compaction, only the current checklist is presented: older generated
65
- checklists are excluded from compacted spans and the retained tail. This is
66
- instruction delivery, not a guarantee of model compliance.
67
-
68
- Compaction hides earlier details from the model's view; recorded history remains
69
- retrievable. Recovery guidance explicitly names uncertain provenance (where a
70
- finding came from or why a conclusion was reached) and contradictions between
71
- earlier notes and new evidence. Prefer lookup for historical observations or to
72
- avoid repeating costly research; inspect project files for current contents.
73
- Cheap local rereads and recomputations remain reasonable.
74
-
75
- Tool lines use compact signatures and head-only bash previews: the first 160
76
- encoded characters, followed by an ellipsis when truncated. Selected historical
77
- output observations (such as failing-test counts) replace misleading `[ok]` labels;
78
- an unlabelled call is not proof of success. Most output and detailed payloads are
79
- omitted. When you need details hidden by compaction, ask `context_lookup` a specific
80
- historical question. Recovery results supply ENTRY ids for targeted follow-up;
81
- `context_show_entry` can read a specific passage at a known ENTRY id. Start small
82
- and continue only if the detail is missing, incomplete, or needs more context to
83
- resolve ambiguity; stop once the question is answered. Do not expand surrounding
84
- history by default. See [the rendering contract](docs/DESIGN.md#deterministic-checkpoint).
85
-
86
- File lists now distinguish source output retained in the recent tail, partial
87
- reads, and reads followed by tracked changes. Modified paths without retained
88
- read/write evidence are marked `no read-tool output in tail`; these annotations
89
- are checkpoint-time evidence, not guarantees of current filesystem state.
90
- Before replacing an existing file with `write`, the agent is told to reread it
91
- unless current contents are already visible, rather than reconstruct unchanged
92
- sections from memory. Small exact-match edits have no blanket reread requirement.
93
-
94
- ### Automatic startup-read retention
95
-
96
- Successful text reads between the first and second user prompts are retained when
97
- their paths or filenames appear in AGENTS.md / CLAUDE.md instructions. Selection
98
- is purely mechanical: no model call, agent tagging, or extra filesystem reads.
99
- Original output chunks, including paginated reads, survive in a separate checkpoint
100
- section and carry forward across later compactions. Copies still in the recent
101
- tail are not duplicated. If compaction happens before the second prompt, collection
102
- continues until that prompt arrives.
103
-
104
- This is a literal filename-matching heuristic, not an interpretation of required
105
- reading. It does not capture every possible reference or fill in incomplete reads.
106
- The agent is no longer given a required-document reread checklist; recovery is for
107
- missing task-relevant evidence. See [selection details](docs/DESIGN.md#retained-startup-reads).
108
-
109
- ### Select the compaction method
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.
39
+
40
+ ## Filter turns
41
+
42
+ Use these commands while the agent is idle:
110
43
 
111
44
  ```text
112
- /compaction-method
113
- /compaction-method verbatim
114
- /compaction-method summary
45
+ /filter-turns # edit an existing checkpoint
46
+ /compact-filtered # compact first, then open the editor
115
47
  ```
116
48
 
117
- `/compaction-method` is available to opt-in to Pi's builtin summary compaction for the current session.
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.
50
+
51
+ Each selection covers a user message and all following activity up to the next user message:
118
52
 
119
- The choice applies to manual `/compact`, automatic threshold compaction, and context-overflow recovery.
120
- With no argument, the command reports the current method.
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 |
121
60
 
122
- The choice persists in the existing session, follows branch history through
123
- reload, resume, fork, and tree navigation, and needs no extra configuration file.
124
- New sessions default to verbatim.
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.
125
62
 
126
- ### Control the compaction cap
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.
127
64
 
128
- When the checkpoint exceeds its budget, capping first tightens tool presentation:
129
- 160→120→80-character previews, then grouped tool-only prefixes. Only if those stages
130
- cannot make it fit does it remove conversation content. `tools-tightened` marks presentation changes; `trimmed` marks actual
131
- omissions. Earlier structured spans can be tightened in the new checkpoint without
132
- editing their stored originals; disabling the cap restores their normal rendering.
133
- Text-only legacy spans use a conservative fallback.
134
- See [how cap trimming works](docs/DESIGN.md#how-cap-trimming-works) for the full order.
135
- 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.
136
- If you find that in normal usage you frequently work over the compaction cap, other compaction tools are likely to be more suitable.
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.
137
66
 
138
- The default is **`warn 25%`**: a conversation-and-retained-reads budget estimated at 25% of
139
- the current model's context window, using **4 characters per token**, not an
140
- exact tokenizer. When tightening or omission would be needed, choose **Apply trimming**,
141
- **Disable cap for this session**, **Change budget**, or **Cancel compaction**. Disabling persists as `off`, rather than
142
- bypassing just once.
67
+ ### Flag an aside
143
68
 
144
69
  ```text
145
- /cap-compaction # report mode and budget
146
- /cap-compaction warn # prompt before trimming (default)
147
- /cap-compaction on # trim without prompting
148
- /cap-compaction off # disable cap-based trimming
149
- /cap-compaction warn 20000t # estimated tokens
150
- /cap-compaction warn 25% # percentage of model context window
151
- /cap-compaction on 80000c # the original character guard
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
152
75
  ```
153
76
 
154
- Mode and budget are independent: omitting either preserves it. Budget-only input
155
- such as `/cap-compaction 40000c` also works. Both settings persist in the session
156
- and follow branch history through reload, resume, fork, and tree navigation.
157
- They apply only to verbatim compaction, not summary compaction, and do not change
158
- Pi's auto-compaction enabled setting.
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.
159
78
 
160
- Tokens are estimated with `ceil(chars / 4)`, not an exact tokenizer. For a
161
- 192,000-token window, `25%` gives 48,000 estimated tokens, equivalent to 192,000
162
- characters.
79
+ ## Control compaction
163
80
 
164
- The budget is a size guard, not a guarantee that the whole model context fits.
165
- Instructions and file lists remain outside it. Retained startup reads count as
166
- fixed overhead but are never trimmed; if they alone exceed the budget, the
167
- extension warns and keeps them. Disabling the cap still removes thinking and
168
- unselected tool outputs and abbreviates tool-call signatures.
169
- It may leave too much context for the model, particularly during overflow recovery.
81
+ ### Choose the method
170
82
 
171
- With no interactive UI, `warn` emits a warning and applies the cap. TUI and
172
- supported RPC clients can answer the dialogs. In interactive sessions, `warn`
173
- can wait for an answer even during automatic compaction; use `/cap-compaction on`
174
- for unattended operation. If a percentage cannot be resolved because the model's
175
- context window is unavailable, compaction is cancelled: choose a character/token
176
- budget or turn the cap off.
83
+ ```text
84
+ /compaction-method # show current method
85
+ /compaction-method verbatim # extension's compaction (default)
86
+ /compaction-method summary # Pi's built-in summary compaction
87
+ ```
177
88
 
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.
178
90
 
179
- ## Configuration
91
+ ### Set the size cap
180
92
 
181
- No separate configuration file is required. Set environment variables before
182
- starting Pi:
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.
183
95
 
184
- | Variable | Default | Meaning |
185
- |---|---|---|
186
- | `MECH_COMPACT_MAX_SUMMARY_CHARS` | Unset (uses percentage budget) | Initial conversation-and-retained-reads character budget override; takes precedence over the percentage setting. |
187
- | `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. |
188
- | `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. |
189
- | `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. |
190
- | `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. |
191
- | `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. |
192
96
 
193
- Cap-budget precedence is **session setting → explicit character setting → percentage setting**.
194
- The initial cap mode remains `warn`.
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
106
+ ```
195
107
 
196
- For a different percentage default, with the character override unset:
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.
197
109
 
198
- ```bash
199
- MECH_COMPACT_MAX_SUMMARY_PERCENT=30 pi
200
- ```
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.
201
111
 
202
- Or use a fixed character budget:
112
+ ## Configuration
203
113
 
204
- ```bash
205
- MECH_COMPACT_MAX_SUMMARY_CHARS=40000 pi
206
- ```
114
+ No configuration file is needed. Set these environment variables before starting Pi:
207
115
 
208
- The lookup model, turn budget, consecutive-call limit, and initial cap settings are read when the extension loads.
209
- Use `/cap-compaction` to change the session budget or mode without restarting. The
210
- session-file override is checked at each lookup. Restart Pi after changing its
211
- launching environment; `/reload` does not change inherited environment variables.
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. |
212
124
 
213
- Leave the session-file override unset for ordinary use. When configured, lookup
214
- opens that file with `SessionManager.open()` and renders its branch. Relative,
215
- missing, empty, or invalid source files fail explicitly rather than silently
216
- searching the pruned fork. Opening a legacy file may trigger Pi's normal session
217
- migration. The override is extension configuration, not a tool argument or a
218
- filesystem search route for the main agent.
125
+ For example:
219
126
 
220
- The character budget is not a token limit or a hard cap on the whole checkpoint.
221
- Instructions and file lists sit outside the budget; an inherited base and retained
222
- startup reads are uncapped, and the line budget has a 500-character minimum. Tune it
223
- alongside the model's context window and Pi's `compaction.keepRecentTokens`.
127
+ ```bash
128
+ MECH_COMPACT_MAX_SUMMARY_PERCENT=30 pi
129
+ MECH_COMPACT_LOOKUP_MODEL=provider/modelId pi
130
+ ```
224
131
 
225
- ### 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.
226
133
 
227
- When lookups use the session model on a local server, they share its KV cache with the main session.
134
+ ### Local inference
228
135
 
229
- - **llama.cpp**: on a single-slot server (`-np 1`), each lookup call evicts the main session's KV cache. Enable host-memory prompt caching with `--cache-ram <MiB>`, sized to hold at least one full main-session state, so the main session resumes in seconds instead of re-processing its entire context.
230
- - **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.
231
137
 
232
138
  ## License
233
139