@foliox/transparent-compact-pi 0.0.0-stage → 0.8.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 +91 -0
- package/LICENSE +21 -0
- package/README.md +173 -2
- package/docs/DESIGN.md +109 -0
- package/extensions/transparent-compact.ts +1440 -0
- package/package.json +59 -4
- package/skills/context-retrieval/SKILL.md +77 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## Unreleased — initial release preparation
|
|
4
|
+
|
|
5
|
+
- Deterministic checkpoints retain user messages and assistant prose, subject to
|
|
6
|
+
a size guard; thinking, full tool outputs, and arguments remain in Pi's session.
|
|
7
|
+
- Tool signatures record per-call `ok`, `error`, or `unknown` outcomes from
|
|
8
|
+
matched tool-result metadata, always marking output as removed. Missing or
|
|
9
|
+
ambiguous outcomes are never inferred, including unlabelled older spans.
|
|
10
|
+
- Read-file entries explicitly mark content as removed; a closing evidence rule
|
|
11
|
+
requires lookup or re-reading before relying on removed outputs or document rules.
|
|
12
|
+
- Flat chronological spans avoid repeatedly summarizing earlier facts.
|
|
13
|
+
- Session-persistent `/compaction-method verbatim|summary` selects manual,
|
|
14
|
+
automatic, and overflow-recovery compaction independently of auto-compaction
|
|
15
|
+
on/off. `/compact` autocomplete reflects the method when supported, without
|
|
16
|
+
replacing the command or footer.
|
|
17
|
+
- Summary-mode warnings appear only on actual switches, not status checks or
|
|
18
|
+
compaction. They clarify that changing the setting alone does not alter context.
|
|
19
|
+
Mixed-context warnings explicitly scope the verbatim guarantee; switching back
|
|
20
|
+
after applying a summary cannot restore earlier model-summarized context to verbatim.
|
|
21
|
+
- Session-backed `context_lookup` searches the full raw active branch across all
|
|
22
|
+
compactions, using an in-memory transcript with authoritative entry attribution.
|
|
23
|
+
- No local transcript dump, temporary file, ownership matching, or pruning.
|
|
24
|
+
- Optional `MECH_COMPACT_LOOKUP_SESSION_FILE` supports full-session recovery from
|
|
25
|
+
pruned harness forks, with explicit failures for invalid overrides.
|
|
26
|
+
- Subagent lookup provides list, grep, and entry-retrieval tools; exhausted lookups
|
|
27
|
+
receive one final tool-free write-up of partial findings. The extension appends
|
|
28
|
+
fallback guidance even when the write-up fails or its findings are truncated.
|
|
29
|
+
- Subagent continuation-only turns no longer spend the substantive search-turn
|
|
30
|
+
budget when they use previously issued, single-use cursors with unchanged
|
|
31
|
+
effective parameters. New searches, mixed batches, invented/replayed cursors,
|
|
32
|
+
and duplicate continuations still count. A separate ceiling allows at most
|
|
33
|
+
3× the configured budget in search-phase model calls (30 by default), plus
|
|
34
|
+
one final tool-free write-up. This is a safety guard, not a measured optimum;
|
|
35
|
+
no telemetry or subagent trace is persisted.
|
|
36
|
+
- Paging guidance now asks for continuation only when omitted evidence matters,
|
|
37
|
+
rather than exhausting every page. Invalid grep `charOffset` errors explain
|
|
38
|
+
the unchanged-parameter requirement and how to restart the match at
|
|
39
|
+
`charOffset=0`.
|
|
40
|
+
- Hybrid recovery is now the default: `context_list_entries`, `context_grep`, and
|
|
41
|
+
`context_show_entry` provide bounded direct search when subagent findings are
|
|
42
|
+
incomplete. The checkpoint, tool descriptions, and bundled skill consistently
|
|
43
|
+
permit these tools while prohibiting raw session-file recovery through
|
|
44
|
+
filesystem tools. This intentionally changes recovery prompting.
|
|
45
|
+
- `MECH_COMPACT_LOOKUP_MAX_CALLS` defaults to 1 consecutive lookup attempt
|
|
46
|
+
(0 = unlimited). User messages, ordinary-work tool results, and bash executions
|
|
47
|
+
reset the limit; narration and thinking do not. The three direct fallback
|
|
48
|
+
tools neither increase nor reset the count, preventing alternating lookup/
|
|
49
|
+
direct-search cycles from repeatedly launching subagents. Branch-based call/result
|
|
50
|
+
accounting also covers pending earlier calls in a batch, preventing parallel
|
|
51
|
+
lookups from bypassing the cap. Lookup requests use sequential execution when
|
|
52
|
+
supported by Pi.
|
|
53
|
+
- Shared subagent/direct search tools now support complete paginated retrieval,
|
|
54
|
+
with continuation cursors and explicit remaining-content notices, including
|
|
55
|
+
oversized individual lines. Listing/grep cursors pin the original last entry
|
|
56
|
+
id, excluding newly appended calls/results without creating a snapshot. Existing grep/entry payload guards remain 12,000/
|
|
57
|
+
24,000 characters; entry listings are now paginated at 12,000 characters.
|
|
58
|
+
`truncateMiddle` was renamed to `truncateHead` to match its actual behavior.
|
|
59
|
+
These are retrieval changes, not new measurements of historical study arms.
|
|
60
|
+
- Lookup model calls no longer force caching off; provider defaults apply, with
|
|
61
|
+
a stable separate session id for each lookup. Cache eligibility remains
|
|
62
|
+
provider-dependent.
|
|
63
|
+
- Session/branch-persistent `/cap-compaction [on|off|warn] [80000c|20000t|25%]`
|
|
64
|
+
controls trimming; the default is `warn 25%` of the current model context window.
|
|
65
|
+
Tokens use a four-characters-per-token estimate (now explicit in budget status),
|
|
66
|
+
percentages follow model changes, and explicit character
|
|
67
|
+
budgets retain the existing scope and algorithm. The environment character
|
|
68
|
+
setting remains an initial-budget override.
|
|
69
|
+
- `MECH_COMPACT_MAX_SUMMARY_PERCENT` configures the initial percentage budget
|
|
70
|
+
(default 25, fractional values supported). Session settings override explicit
|
|
71
|
+
character settings, which override the percentage setting; invalid percentages
|
|
72
|
+
fall back to 25.
|
|
73
|
+
- Trim prompts can apply the cap, persist `off`, change the budget, or cancel.
|
|
74
|
+
Non-interactive mode warns and caps; cancellation never falls through to summary.
|
|
75
|
+
For unattended interactive sessions, use `/cap-compaction on` to avoid waiting
|
|
76
|
+
for trim dialogs. The `warn` default and conversion factor are unchanged.
|
|
77
|
+
- Removed `/dump-context`, `dump_context`, and the `dumpDir` lookup argument;
|
|
78
|
+
old dump-directory and git-ignore warning settings are unused.
|
|
79
|
+
- Bundled `context-retrieval` skill describes session-backed evidence recovery,
|
|
80
|
+
branch scope, historical provenance, and re-verification after compaction.
|
|
81
|
+
- Deterministic tests cover session recovery, overrides, attribution, size guards,
|
|
82
|
+
cap dialogs/modes/budgets, percentage defaults/model changes, cancellation,
|
|
83
|
+
the skill, and Pi's real package loader. Hybrid regressions additionally cover
|
|
84
|
+
narration, same-message/parallel attempts, pagination and oversized lines,
|
|
85
|
+
continuation budget accounting/replay protection, total-call ceilings,
|
|
86
|
+
cursor-error recovery, truncation boundaries, provider caching options, and
|
|
87
|
+
real Pi agent-turn persistence ordering with a stubbed model (no live inference).
|
|
88
|
+
- Preliminary synthetic pilot figures are preserved as historical results from
|
|
89
|
+
the dump-based implementation, not measurements of the current implementation.
|
|
90
|
+
|
|
91
|
+
No version has been published from this staging directory. Full evaluation is pending.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 mech-compact contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,174 @@
|
|
|
1
|
-
#
|
|
1
|
+
# transparent-compact
|
|
2
2
|
|
|
3
|
-
|
|
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 tool outputs are removed
|
|
6
|
+
from the active model context, while user inputs, assistant text, and tool call stubs are retained verbatim.
|
|
7
|
+
Verbatim compaction itself makes no model call. When a missing detail is needed, `context_lookup` runs a subagent over the session's
|
|
8
|
+
full raw branch and returns only relevant findings.
|
|
9
|
+
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.
|
|
10
|
+
|
|
11
|
+
The method is functionally similar to pi-vcc, but is specifically aimed at lighter weight models
|
|
12
|
+
such as **Qwen 3.8 27B** or **GPT-6 Luna**. The design principle is that:
|
|
13
|
+
|
|
14
|
+
- 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.
|
|
15
|
+
- History retrieval should be parsimonious, explicitly clear to the agent, and agnostic to the task and session structure.
|
|
16
|
+
|
|
17
|
+
[This study](https://arxiv.org/abs/2610.20116) demonstrated that a minimal system like
|
|
18
|
+
this outperforms more complicated techniques with lightweight models, and is at least as effective with frontier models too.
|
|
19
|
+
It helps weaker models to avoid confabulating the historical context and to more carefully verify what it does and does not know.
|
|
20
|
+
|
|
21
|
+
The primary intended use case is on a strong local LLM with a reasonably large context window (>128k) : for example, through
|
|
22
|
+
**Qwen 3.8 27B llama.cpp on an RTX 5090**.
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
### Package installation
|
|
27
|
+
|
|
28
|
+
Install from npm:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pi install npm:@foliox/transparent-compact-pi
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
or from github:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pi install git:github.com/felixwoolford/transparent-compact-pi
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
or from a downloaded or cloned checkout:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pi install /absolute/path/to/transparent-compact
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
Pi's compaction uses transparent-compact by default once the extension is loaded.
|
|
50
|
+
To compact manually:
|
|
51
|
+
|
|
52
|
+
```text
|
|
53
|
+
/compact
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Select the compaction method
|
|
57
|
+
|
|
58
|
+
```text
|
|
59
|
+
/compaction-method
|
|
60
|
+
/compaction-method verbatim
|
|
61
|
+
/compaction-method summary
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
`/compaction-method` is available to opt-in to Pi's builtin summary compaction for the current session.
|
|
65
|
+
|
|
66
|
+
The choice applies to manual `/compact`, automatic threshold compaction, and context-overflow recovery.
|
|
67
|
+
With no argument, the command reports the current method.
|
|
68
|
+
|
|
69
|
+
The choice persists in the existing session, follows branch history through
|
|
70
|
+
reload, resume, fork, and tree navigation, and needs no extra configuration file.
|
|
71
|
+
New sessions default to verbatim.
|
|
72
|
+
|
|
73
|
+
### Control the compaction cap
|
|
74
|
+
|
|
75
|
+
Capping of the context eventually applies to strip further elements from the checkpoint.
|
|
76
|
+
See [how cap trimming works](docs/DESIGN.md#how-cap-trimming-works) for the removal order.
|
|
77
|
+
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.
|
|
78
|
+
If you find that in normal usage you frequently work over the compaction cap, other compaction tools are likely to be more suitable.
|
|
79
|
+
|
|
80
|
+
The default is **`warn 25%`**: a conversation-section budget estimated at 25% of
|
|
81
|
+
the current model's context window, using **4 characters per token**, not an
|
|
82
|
+
exact tokenizer. When content would actually be trimmed, choose **Apply trimming**,
|
|
83
|
+
**Disable cap for this session**, **Change budget**, or **Cancel compaction**. Disabling persists as `off`, rather than
|
|
84
|
+
bypassing just once.
|
|
85
|
+
|
|
86
|
+
```text
|
|
87
|
+
/cap-compaction # report mode and budget
|
|
88
|
+
/cap-compaction warn # prompt before trimming (default)
|
|
89
|
+
/cap-compaction on # trim without prompting
|
|
90
|
+
/cap-compaction off # disable cap-based trimming
|
|
91
|
+
/cap-compaction warn 20000t # estimated tokens
|
|
92
|
+
/cap-compaction warn 25% # percentage of model context window
|
|
93
|
+
/cap-compaction on 80000c # the original character guard
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Mode and budget are independent: omitting either preserves it. Budget-only input
|
|
97
|
+
such as `/cap-compaction 40000c` also works. Both settings persist in the session
|
|
98
|
+
and follow branch history through reload, resume, fork, and tree navigation.
|
|
99
|
+
They apply only to verbatim compaction, not summary compaction, and do not change
|
|
100
|
+
Pi's auto-compaction enabled setting.
|
|
101
|
+
|
|
102
|
+
Tokens are estimated with `ceil(chars / 4)`, not an exact tokenizer. For a
|
|
103
|
+
192,000-token window, `25%` gives 48,000 estimated tokens, equivalent to 192,000
|
|
104
|
+
characters.
|
|
105
|
+
|
|
106
|
+
The budget is a size guard, not a guarantee that the whole model context fits.
|
|
107
|
+
Instructions and file lists remain outside it. Disabling the cap
|
|
108
|
+
still removes thinking and tool outputs and abbreviates tool-call signatures.
|
|
109
|
+
It may leave too much context for the model, particularly during overflow recovery.
|
|
110
|
+
|
|
111
|
+
With no interactive UI, `warn` emits a warning and applies the cap. TUI and
|
|
112
|
+
supported RPC clients can answer the dialogs. In interactive sessions, `warn`
|
|
113
|
+
can wait for an answer even during automatic compaction; use `/cap-compaction on`
|
|
114
|
+
for unattended operation. If a percentage cannot be resolved because the model's
|
|
115
|
+
context window is unavailable, compaction is cancelled: choose a character/token
|
|
116
|
+
budget or turn the cap off.
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
## Configuration
|
|
120
|
+
|
|
121
|
+
No separate configuration file is required. Set environment variables before
|
|
122
|
+
starting Pi:
|
|
123
|
+
|
|
124
|
+
| Variable | Default | Meaning |
|
|
125
|
+
|---|---|---|
|
|
126
|
+
| `MECH_COMPACT_MAX_SUMMARY_CHARS` | Unset (uses percentage budget) | Initial conversation-section character budget override; takes precedence over the percentage setting. |
|
|
127
|
+
| `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. |
|
|
128
|
+
| `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. |
|
|
129
|
+
| `MECH_COMPACT_LOOKUP_TURNS` | `10` | Maximum substantive search turns. Valid continuation-only turns are exempt; total search-phase model calls are capped at 3× this budget (30 by default), plus one tool-free write-up on exhaustion. |
|
|
130
|
+
| `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. |
|
|
131
|
+
| `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. |
|
|
132
|
+
|
|
133
|
+
Cap-budget precedence is **session setting → explicit character setting → percentage setting**.
|
|
134
|
+
The initial cap mode remains `warn`.
|
|
135
|
+
|
|
136
|
+
For a different percentage default, with the character override unset:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
MECH_COMPACT_MAX_SUMMARY_PERCENT=30 pi
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Or use a fixed character budget:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
MECH_COMPACT_MAX_SUMMARY_CHARS=40000 pi
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
The lookup model, turn budget, consecutive-call limit, and initial cap settings are read when the extension loads.
|
|
149
|
+
Use `/cap-compaction` to change the session budget or mode without restarting. The
|
|
150
|
+
session-file override is checked at each lookup. Restart Pi after changing its
|
|
151
|
+
launching environment; `/reload` does not change inherited environment variables.
|
|
152
|
+
|
|
153
|
+
Leave the session-file override unset for ordinary use. When configured, lookup
|
|
154
|
+
opens that file with `SessionManager.open()` and renders its branch. Relative,
|
|
155
|
+
missing, empty, or invalid source files fail explicitly rather than silently
|
|
156
|
+
searching the pruned fork. Opening a legacy file may trigger Pi's normal session
|
|
157
|
+
migration. The override is extension configuration, not a tool argument or a
|
|
158
|
+
filesystem search route for the main agent.
|
|
159
|
+
|
|
160
|
+
The character budget is not a token limit or a hard cap on the whole checkpoint.
|
|
161
|
+
Instructions and file lists sit outside the conversation section; an inherited
|
|
162
|
+
base is uncapped and the line budget has a 500-character minimum. Tune it
|
|
163
|
+
alongside the model's context window and Pi's `compaction.keepRecentTokens`.
|
|
164
|
+
|
|
165
|
+
### Local inference engines
|
|
166
|
+
|
|
167
|
+
When lookups use the session model on a local server, they share its KV cache with the main session.
|
|
168
|
+
|
|
169
|
+
- **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.
|
|
170
|
+
- **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.
|
|
171
|
+
|
|
172
|
+
## License
|
|
173
|
+
|
|
174
|
+
[MIT](LICENSE).
|
package/docs/DESIGN.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
|
|
2
|
+
## How it works
|
|
3
|
+
|
|
4
|
+
### Deterministic checkpoint
|
|
5
|
+
|
|
6
|
+
Pi selects the compacted messages and retained boundary. In verbatim mode, the
|
|
7
|
+
extension builds a checkpoint without changing that boundary or calling a model:
|
|
8
|
+
|
|
9
|
+
| Content | Treatment |
|
|
10
|
+
|---|---|
|
|
11
|
+
| User messages | Kept verbatim, subject to the size guard. |
|
|
12
|
+
| Assistant prose | Kept, subject to the size guard. |
|
|
13
|
+
| Tool calls | Short signatures with outcome labels; full arguments and outputs remain recoverable. |
|
|
14
|
+
| Assistant thinking | Removed from the checkpoint; retained in the raw session. |
|
|
15
|
+
| Tool outputs | Removed from the checkpoint; retained in the raw session. |
|
|
16
|
+
| Recent conversation | Pi keeps its normal verbatim tail. |
|
|
17
|
+
| Earlier compacted spans | Re-rendered chronologically, without repeated model summarization. |
|
|
18
|
+
| Read/modified file lists | Carried forward, with file contents marked as removed. |
|
|
19
|
+
|
|
20
|
+
Checkpoints label tool outcomes as `ok`, `error`, or `unknown` and remind the
|
|
21
|
+
agent to recover missing evidence and re-read required documents before relying
|
|
22
|
+
on them. These labels describe tool results, not a guarantee that tests passed.
|
|
23
|
+
|
|
24
|
+
#### How cap trimming works
|
|
25
|
+
|
|
26
|
+
**User messages are prioritized**—capping is not simply an oldest-first cutoff:
|
|
27
|
+
|
|
28
|
+
1. Remove non-user content, oldest first.
|
|
29
|
+
2. If still over budget, shorten long user messages to marked prefix stubs,
|
|
30
|
+
oldest first.
|
|
31
|
+
3. As a last resort, remove the oldest remaining content, including user messages.
|
|
32
|
+
|
|
33
|
+
Trimming stops once the budget is satisfied. Originals remain recoverable from
|
|
34
|
+
the session.
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### Session-backed lookup
|
|
38
|
+
|
|
39
|
+
Pi normally saves append-only JSONL sessions under:
|
|
40
|
+
|
|
41
|
+
```text
|
|
42
|
+
~/.pi/agent/sessions/--<project-path>--/<timestamp>_<session-id>.jsonl
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Compaction adds an entry; it does not delete earlier thinking, tool calls, or
|
|
46
|
+
tool results. At each lookup, the extension obtains the current branch through
|
|
47
|
+
`ctx.sessionManager.getBranch()`, **not** the compacted model-context projection.
|
|
48
|
+
Custom session locations work automatically. In-memory sessions work while the
|
|
49
|
+
process lives, but cannot be resumed after exit.
|
|
50
|
+
|
|
51
|
+
The raw branch is mechanically rendered **in memory** into readable transcript
|
|
52
|
+
lines. Blocks have `ENTRY` headers; assistant sections have `[thinking]`,
|
|
53
|
+
`[text]`, and `[toolCall]` markers. Thinking, tool arguments, and textual tool
|
|
54
|
+
outputs are preserved without truncation in that representation. An authoritative
|
|
55
|
+
entry/section index prevents header-like text inside output from spoofing
|
|
56
|
+
attribution.
|
|
57
|
+
|
|
58
|
+
The subagent uses three internal tools: `list_entries`, `grep`, and `show_entry`.
|
|
59
|
+
These search the rendered lines directly, so no temporary file, second session
|
|
60
|
+
copy, or cleanup is needed. They share the fallback tools' paginated search
|
|
61
|
+
functions. Individual results and the final answer have size limits. Follow
|
|
62
|
+
pages only when omitted content is needed, not to exhaust every match or entry.
|
|
63
|
+
|
|
64
|
+
Valid continuation-only turns do not spend the substantive search budget; new
|
|
65
|
+
queries, changed parameters, or replayed cursors do. A separate ceiling caps all
|
|
66
|
+
search-phase model calls at three times the configured turn budget (30 by default).
|
|
67
|
+
When either budget ends searching, one final tool-free model call writes up
|
|
68
|
+
partial findings; a failed write-up falls back to the latest text, explicitly
|
|
69
|
+
labeled incomplete. Lookup requests use normal provider caching
|
|
70
|
+
defaults rather than forcing caching off; actual cache behavior and savings vary
|
|
71
|
+
by provider.
|
|
72
|
+
|
|
73
|
+
### Recover historical details
|
|
74
|
+
|
|
75
|
+
The extension registers a subagent lookup and three direct-search fallback tools:
|
|
76
|
+
|
|
77
|
+
| Tool | Purpose |
|
|
78
|
+
|---|---|
|
|
79
|
+
| `context_lookup` | Recover specific historical details from the full raw session branch. Accepts only `question`. |
|
|
80
|
+
| `context_list_entries` | Fallback: list entry ids, roles, timestamps, and previews. |
|
|
81
|
+
| `context_grep` | Fallback: regex-search the raw branch with surrounding lines and entry attribution. |
|
|
82
|
+
| `context_show_entry` | Fallback: retrieve an entry by id. |
|
|
83
|
+
|
|
84
|
+
For example, ask the agent to recover the build error observed before compaction.
|
|
85
|
+
It can call `context_lookup` with:
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"question": "What exact build error did we observe for src/auth.ts before compaction? Include the ENTRY id and observed tool output."
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
The subagent searches in its own context and returns findings with entry
|
|
94
|
+
references. Its raw search results stay out of the main conversation. If findings
|
|
95
|
+
are incomplete, the fallback tools run the same searches directly; their results
|
|
96
|
+
enter the main context. Turn-limit write-ups include a note recommending these
|
|
97
|
+
tools for further detail on the same query, even if the write-up fails.
|
|
98
|
+
|
|
99
|
+
By default, only one `context_lookup` attempt is allowed until a user message,
|
|
100
|
+
a bash execution, or a tool result outside these four recovery tools resets the
|
|
101
|
+
limit. Fallback searches, assistant text, and thinking neither increase nor reset
|
|
102
|
+
the count. Pending lookup calls in the same batch also count, preventing parallel
|
|
103
|
+
calls from bypassing the limit. Blocked attempts return a short fallback note
|
|
104
|
+
without launching a subagent; later lookups after other work remain available.
|
|
105
|
+
|
|
106
|
+
After compaction, the checkpoint instructs the agent to re-read required documents,
|
|
107
|
+
even if previously read, re-acquire missing task information, inspect Git state
|
|
108
|
+
when in a Git repository, and re-read files before modifying them.
|
|
109
|
+
|