pi-tuck 1.3.2 → 1.3.4

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
@@ -3,6 +3,27 @@
3
3
  All notable changes to pi-tuck. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and versions follow
4
4
  [Semantic Versioning](https://semver.org/).
5
5
 
6
+ ## [1.3.4] - 2026-11-20
7
+
8
+ ### Fixed
9
+
10
+ - **A session that already holds a summary from Pi's own `/compact` works with pi-tuck.** Loading pi-tuck into a session whose history
11
+ already contained a summary written by Pi's built-in compaction, not by pi-tuck, made every prompt fail before it was sent ("pi-tuck could
12
+ not plan this request (Cannot resolve custom sources in an unsupported compaction summary)"), so the session could neither continue nor
13
+ reach a cut. Such a summary is now sent as it is, as Pi sends it, and pi-tuck's next cut replaces it. Thanks to basileaw for the detailed
14
+ report and root cause (#1).
15
+
16
+ ## [1.3.3] - 2026-11-20
17
+
18
+ ### Fixed
19
+
20
+ - **A learned server window no longer outlives a larger configured window.** When a server clips replies below the configured window,
21
+ pi-tuck learns the smaller window and keeps it in the session. It now also records the configured window it learned under, and
22
+ drops the learned value once the model's configured window differs, for example after a server and its models.json grew from
23
+ 68,000 to 131,072 tokens. Before, every reopened session stayed capped at the old window and compacted far too often. Learned
24
+ windows saved by earlier versions carry no configured window and are not reused; if the server still clips, the next clipped
25
+ reply learns it again.
26
+
6
27
  ## [1.3.2] - 2026-11-15
7
28
 
8
29
  ### Fixed
package/LICENSE CHANGED
@@ -20,62 +20,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
20
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
21
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  SOFTWARE.
23
-
24
- ---
25
-
26
- Portions derived from pi-blackhole (https://github.com/k0valik/pi-blackhole).
27
- The following notice is retained for those portions:
28
-
29
- MIT License
30
-
31
- Copyright (c) 2026 k0valik
32
-
33
- Permission is hereby granted, free of charge, to any person obtaining a copy
34
- of this software and associated documentation files (the "Software"), to deal
35
- in the Software without restriction, including without limitation the rights
36
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
37
- copies of the Software, and to permit persons to whom the Software is
38
- furnished to do so, subject to the following conditions:
39
-
40
- The above copyright notice and this permission notice shall be included in all
41
- copies or substantial portions of the Software.
42
-
43
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
44
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
45
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
46
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
47
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
48
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
49
- SOFTWARE.
50
-
51
- ---
52
-
53
- Pi-derived inlined message constructors
54
-
55
- The following notice applies to the adapted createCustomMessage and
56
- createBranchSummaryMessage construction branches in src/tuck/cut.ts
57
- and their distributed generated equivalents. Notice source: Pi v1.1.0,
58
- https://github.com/earendil-works/pi/blob/abe508e1b89912adde45528136c3221eb69acdd7/LICENSE
59
- This notice-source pin does not identify the original copy revision.
60
-
61
- MIT License
62
-
63
- Copyright (c) 2025 Mario Zechner
64
-
65
- Permission is hereby granted, free of charge, to any person obtaining a copy
66
- of this software and associated documentation files (the "Software"), to deal
67
- in the Software without restriction, including without limitation the rights
68
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
69
- copies of the Software, and to permit persons to whom the Software is
70
- furnished to do so, subject to the following conditions:
71
-
72
- The above copyright notice and this permission notice shall be included in all
73
- copies or substantial portions of the Software.
74
-
75
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
76
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
77
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
78
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
79
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
80
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
81
- SOFTWARE.
package/NOTICE ADDED
@@ -0,0 +1,63 @@
1
+ # Third-party notices
2
+
3
+ pi-tuck is released under the MIT License in LICENSE. Some portions are derived from the projects below; their notices are retained here
4
+ word for word, as their licenses require.
5
+
6
+ ---
7
+
8
+ Portions derived from pi-blackhole (https://github.com/k0valik/pi-blackhole).
9
+ The following notice is retained for those portions:
10
+
11
+ MIT License
12
+
13
+ Copyright (c) 2026 k0valik
14
+
15
+ Permission is hereby granted, free of charge, to any person obtaining a copy
16
+ of this software and associated documentation files (the "Software"), to deal
17
+ in the Software without restriction, including without limitation the rights
18
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
+ copies of the Software, and to permit persons to whom the Software is
20
+ furnished to do so, subject to the following conditions:
21
+
22
+ The above copyright notice and this permission notice shall be included in all
23
+ copies or substantial portions of the Software.
24
+
25
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
+ SOFTWARE.
32
+
33
+ ---
34
+
35
+ Pi-derived inlined message constructors
36
+
37
+ The following notice applies to the adapted createCustomMessage and
38
+ createBranchSummaryMessage construction branches in src/tuck/cut.ts
39
+ and their distributed generated equivalents. Notice source: Pi v1.1.0,
40
+ https://github.com/earendil-works/pi/blob/abe508e1b89912adde45528136c3221eb69acdd7/LICENSE
41
+ This notice-source pin does not identify the original copy revision.
42
+
43
+ MIT License
44
+
45
+ Copyright (c) 2025 Mario Zechner
46
+
47
+ Permission is hereby granted, free of charge, to any person obtaining a copy
48
+ of this software and associated documentation files (the "Software"), to deal
49
+ in the Software without restriction, including without limitation the rights
50
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
51
+ copies of the Software, and to permit persons to whom the Software is
52
+ furnished to do so, subject to the following conditions:
53
+
54
+ The above copyright notice and this permission notice shall be included in all
55
+ copies or substantial portions of the Software.
56
+
57
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
58
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
59
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
60
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
61
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
62
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
63
+ SOFTWARE.
package/README.md CHANGED
@@ -1,39 +1,59 @@
1
1
  # pi-tuck
2
2
 
3
- **Compaction for [Pi](https://pi.dev) with no model call, and exact recall of earlier history, all on your machine.** In our 128k live run, a cut took a median 0.08 s (pi-tuck 1.0.1). It costs no tokens. The same session always gives the same summary. And nothing is lost: the agent can read back anything earlier, word for word.
3
+ pi-tuck is an extension for [Pi](https://pi.dev). It writes Pi's compaction summary from the session itself, with no model call. In our 128k live run, a cut took a median 0.08 s (pi-tuck 1.0.1). A cut costs no tokens. The same session always gives the same summary. The agent can read back any earlier message or tool result, word for word.
4
4
 
5
5
  ```sh
6
6
  pi install npm:pi-tuck
7
7
  ```
8
8
 
9
- ## pi-tuck against Pi's built-in compaction
9
+ Words used on this page:
10
10
 
11
- Pi's built-in compaction asks a model to write a summary. pi-tuck builds the summary from the session itself. The time, context and task rows compare pi-tuck 1.0.1 with Pi 1.4.0's built-in compaction, where a local model writes the summary. Each measured result in this README names the pi-tuck build or version it was measured on; the release you install may be newer.
11
+ - **Window**: the tokens the model accepts in one request.
12
+ - **Reply reserve**: the tokens Pi keeps free for the reply (`compaction.reserveTokens`, default 16,384).
13
+ - **Room**: the window less the reply reserve.
14
+ - **Cut**: the replacement of older turns with one summary.
15
+ - **Recall**: the agent's way to read back what a cut removed (`tuck_recall`).
12
16
 
13
- | | Pi's built-in (local model writes the summary) | pi-tuck |
17
+ ## How pi-tuck compares with Pi's built-in compaction
18
+
19
+ Pi's built-in compaction asks a model to write the summary. pi-tuck builds it from the session. The 128k rows compare pi-tuck 1.0.1 with Pi 1.4.0's built-in compaction, with a local model writing the built-in summary. The 32k row is a different run, described below.
20
+
21
+ | | Pi's built-in | pi-tuck |
14
22
  |---|---|---|
15
- | Model call per cut | One, to a model you pay for or wait on | None |
16
- | Time per cut | **235 s** (median) | **0.08 s** (median; an upper bound, see below) |
17
- | Context carried after a cut | 27,750 tokens | 26,790 tokens (about the same) |
18
- | Facts cut away, asked back at 128k (mechanical probes) | Answered from the summary alone, with no recall tool | Answered from the summary and pi-tuck's recall tools, cuts 1 to 4 only. Claim line below the table |
19
- | Tasks resolved at 128k (300 SWE-bench Verified tasks per arm, pi-tuck 1.0.1) | 251 of 300 | 258 of 300. The registered claim is only "no loss larger than 0.4 points"; chain s09 matters, see below |
20
- | Same session, same summary | Not guaranteed, since a model writes it | Yes |
21
- | Can the agent get dropped detail back | No recall tool in Pi 1.4.0. The full history stays in the session file, but the agent has no tool made to search it | Yes. `tuck_recall` reads any original exactly |
23
+ | Model call per cut | One | None |
24
+ | Time per cut (median) | 235 s | 0.08 s |
25
+ | Context carried after a cut | 27,750 tokens | 26,790 tokens |
26
+ | Same session, same summary | Not guaranteed | Yes |
22
27
  | Can the summary invent history | It can, since a model writes it | No, it holds only recorded text |
23
- | What the summary leaves out | Whatever the model dropped | Tool output only; the agent reads it back exactly |
24
- | Tasks resolved at a 32k window (150 SWE-bench Verified tasks, one model, pi-tuck 1.0.5) | 94 of 150 | 120 of 150 (+17.3 points, 95% lower bound +10.7). Limits below the table |
28
+ | What the summary leaves out | Whatever the model dropped | Tool output only |
29
+ | Can the agent read back cut detail | No recall tool | Yes, with `tuck_recall` |
30
+ | Facts asked back after a cut, 128k window | From the summary alone | Not more than 3 points below Pi's summary (cuts 1 to 4 only; claim below) |
31
+ | Tasks resolved, 128k window, 300 per arm | 251 | 258 (claim: no loss larger than 0.4 points) |
32
+ | Tasks resolved, 32k window, 150 per arm | 94 | 120 (+17.3 points, 95% lower bound +10.7) |
33
+
34
+ What these numbers cover:
25
35
 
26
- The time and context rows are from the 128k live run: 10 chains of 30 tasks, pi-tuck 1.0.1, medians over 46 pi-tuck cuts and 48 cuts by Pi's compaction. pi-tuck's cut time is an upper bound, read from the session file ([`benchmark/DEVIATIONS.md`](benchmark/DEVIATIONS.md)).
36
+ - **Time, context and 128k tasks.** One live run of pi-tuck 1.0.1: 10 chains of 30 SWE-bench Verified tasks, window 128,000. A local model wrote the built-in summaries. The medians come from 46 pi-tuck cuts and 48 built-in cuts. The pi-tuck time is an upper bound, read from the session file.
37
+ - **Retention.** The claim, as [`benchmark/RESULTS-MAIN.md`](benchmark/RESULTS-MAIN.md) words it: **pi-tuck, answering with its recall tools, retains probed facts at a rate not more than 3 points below that of "Pi's compaction prompts on mac-studio/main:xhigh" (20 recordings) or of "Pi's compaction prompts on GPT-6.1 Terra" (19 of 20 recordings, s09-A missing), each answering from its summary alone, on these probes.** The test compares pi-tuck with its recall tool against Pi's summary alone. It does not compare summary with summary. Every probe was a mechanical fact: files changed, test result, required tag, error class or the session's result-line rule. The numbers cover cuts 1 to 4 only, because 52 of pi-tuck's 95 answer sets in the replay ended in an abort. This README makes no retention claim past cut 4.
38
+ - **128k tasks.** The claim is only "no loss larger than 0.4 points". Chain s09 decides it: Pi's compaction failed 44 times there. Without s09 the lower bound is −0.4 points. With it, the bound is +0.3.
39
+ - **32k tasks.** One model (DeepSeek V4.1 Flash), one window, pi-tuck 1.0.5. Only pi-tuck was held to the 16,384-token room: Pi's built-in compaction sent a request over it in 97 of 150 tasks. Observation masking, a third approach, resolved 117 (pi-tuck +2.0 points, lower bound −2.7: no difference shown). The pi-tuck arm had 1 dead task, so it missed its pre-registered bar of zero by one task.
40
+ - **All results.** They come from SWE-bench-style tasks and may not carry to your work.
27
41
 
28
- The retention row is a paired replay on mechanical probes only: files changed, test-runner summary, required tag, error class and the session's result-line rule. No probe judged how well an agent reasons. The claim line, as [`benchmark/RESULTS-MAIN.md`](benchmark/RESULTS-MAIN.md) words it: **pi-tuck, answering with its recall tools, retains probed facts at a rate not more than 3 points below that of "Pi's compaction prompts on mac-studio/main:xhigh" (20 recordings) or of "Pi's compaction prompts on GPT-6.1 Terra" (19 of 20 recordings, s09-A missing), each answering from its summary alone, on these probes.** This is not summary against summary: it compares pi-tuck's summary together with its recall tools against Pi's compaction without them, and the run has no pi-tuck arm without its recall tools. It says nothing about any other compactor, model or window.
42
+ This README does not say that pi-tuck is as good as or better than any compactor, model, window or kind of task other than those named. It never calls pi-tuck "the best LLM compactor". The plans were written before any result. Every plan and result, including those that did not favour pi-tuck, is in [`benchmark/`](benchmark) (index: [`benchmark/README.md`](benchmark/README.md)).
43
+
44
+ ## Install
29
45
 
30
- In the replay behind pi-tuck's retention numbers, 52 of its 95 answer sets ended in an abort (0 of 95 for Pi's compaction prompts on the same local model), so those numbers cover cuts 1 to 4 only and no retention claim is made past cut 4; see [`benchmark/RESULTS-MAIN.md`](benchmark/RESULTS-MAIN.md).
46
+ Run the command at the top, then start a new Pi session. pi-tuck takes over automatic compaction and `/compact`. You change no setting. pi-tuck downloads nothing.
31
47
 
32
- The 32k row is one model, one window and five chains. Observation masking, a third approach, resolved 117 of the same 150 tasks (pi-tuck +2.0 points, lower bound −2.7: no difference shown). In the 32k run only pi-tuck was held to the 16,384-token room: Pi's built-in compaction sent a request over it in 97 of 150 tasks. Every number comes from a file in this repository. Conditions, sample sizes and the full limits are in [Benchmarks](#benchmarks).
48
+ - Use Pi 1.2.0 or later (tested on 1.2.0 and 1.4.0), on macOS, Linux or Windows. Windows works since 1.2.0 (tested on Windows 10 with Node 24 and Pi 1.5.2).
49
+ - On an older Pi, pi-tuck stays off, Pi's own compaction runs, and pi-tuck says so once.
50
+ - To install from GitHub, run `pi install git:github.com/galyavin/pi-tuck@v1.3.4`.
51
+ - To pin a version, run `pi install npm:pi-tuck@1.3.4`.
52
+ - Restart an open Pi session after an update. It keeps the build it started with.
33
53
 
34
54
  ## Ask your history
35
55
 
36
- A summary cannot hold everything. So pi-tuck lets the agent look things up instead of guess. Say you fixed a login bug two hours ago, and the summary no longer holds the details. You ask:
56
+ A summary cannot hold everything, so pi-tuck lets the agent look things up. Say you fixed a login bug two hours ago, and the summary no longer holds the details. You ask:
37
57
 
38
58
  > "What was the reason we dropped the retry on the token refresh?"
39
59
 
@@ -43,175 +63,92 @@ The agent searches its history by keyword with `tuck_recall`:
43
63
  { "query": "retry token refresh" }
44
64
  ```
45
65
 
46
- It gets back ranked passages with a pointer such as `#212`. It reads the whole message, exactly as it was written:
66
+ It gets ranked passages with a pointer such as `#212`. It reads the whole message, exactly as written:
47
67
 
48
68
  ```json
49
69
  { "index": 212 }
50
70
  ```
51
71
 
52
- The agent answers from the original text, not from a model's memory of it.
53
-
54
- *This example is an illustration. It is not a recorded session.* The call shapes are real. Keyword recall finds a passage only by words it contains, so the question has to use words the original message used.
55
-
56
- ## Install
57
-
58
- ```sh
59
- pi install npm:pi-tuck
60
- ```
61
-
62
- Then start a new Pi session. That is all. pi-tuck takes over Pi's compaction, both automatic and `/compact`. You change no setting.
63
-
64
- - Needs Pi 1.2.0 or later (tested on 1.2.0 and 1.4.0), on macOS, Linux or Windows (Windows since 1.2.0, tested on Windows 10 with Node 24 and Pi 1.5.2). On an older Pi, pi-tuck stays off, Pi's own compaction runs, and pi-tuck says so once.
65
- - Prefer GitHub? `pi install git:github.com/galyavin/pi-tuck@v1.3.1`.
66
- - To pin a version, add it: `pi install npm:pi-tuck@1.3.1`.
67
-
68
- ## Uninstall
69
-
70
- ```sh
71
- pi remove npm:pi-tuck
72
- ```
73
-
74
- Use the same source you installed with. This takes pi-tuck out of Pi's settings. pi-tuck downloads nothing, so there is nothing else to delete, apart from incident records if you turned `/tuck-incident` on: they are in `~/.local/state/pi-tuck-incidents`. Versions before 1.2.0 downloaded about 460 MB of files for a search feature that has been removed. pi-tuck deletes those old files itself, once per machine, the first time 1.2.0 starts, and a notice names the folders it removed. On Windows it leaves them alone, so delete `~/.pi/agent/pi-tuck` yourself if it exists.
72
+ The agent answers from the original text. This example is an illustration, not a recorded session. Keyword recall finds only the words that the original message contains.
75
73
 
76
74
  ## How it works
77
75
 
78
- When context fills up, pi-tuck replaces the older turns with one summary. The summary keeps:
76
+ When the context passes the cut point, pi-tuck replaces the older turns with one summary. The summary keeps:
79
77
 
80
- - **The dialogue and your prompts, ranked.** Since 1.0.18, one ranked list decides what a cut carries, across the summary and the kept tail together: the current prompt, whole; the openings of the first prompt and the newest answered prompts, sized to the room; the newest part of the conversation, kept as it is; the file and action lists below; and the rest of the conversation. Dropped turns and tool results are counted with index ranges that `tuck_recall` reads back. Clipped text says how to read it in full.
81
- - **The files.** Files the agent read, wrote or edited, newest first (up to 60), each with a pointer to read it back.
82
- - **Kept reads** (1.1.0 and later). After the Files list, the summary carries the newest whole read of each file that has no later write or edit, headed `read PATH (as recorded at #N; no write or edit recorded since):`. It keeps at most 4 files, whole outputs only, within 20% of the summary's room and never more than 24,000 characters. Since 1.2.0, a read is also dropped from the summary when a later shell command that is not read-only names the file, or when a git command such as `checkout`, `stash`, `restore` or `reset` ran, and paths are compared after normalising their spelling. When the summary is over its target, these records are dropped first, oldest first. With no such reads the summary is unchanged, and tool outputs are never touched. The header says only that no write or edit was recorded since the read; it does not say the file on disk is unchanged. After a cut, agents often doubted what an earlier read had shown and read the same file again, and this is meant to spare that. It has no effectiveness claim; see Benchmarks.
83
- - **Kept searches** (1.3.0 and later; 1.3.0 never reached npm, so 1.3.1 is the first release with them). A cut's summary also keeps the latest output of a `grep` or `rg` search, per command and at most 4, beside the kept reads, while nothing the search lists has changed since: a later write or edit of a listed file, or a shell command that is not read-only and names one, drops it. Searches with shell syntax pi-tuck cannot classify are never kept. Kept searches share kept reads' space in the summary, so the summary's size target is unchanged. It has no effectiveness claim; see Benchmarks.
84
- - **The action trail.** The agent's other tool calls, such as shell commands, newest first (up to 30). The output is left out. A pointer leads to it.
78
+ - your current prompt, whole;
79
+ - the start of your first prompt and of your recent prompts;
80
+ - the newest turns, as they were;
81
+ - the files the agent read, wrote or edited (up to 60), each with a pointer;
82
+ - **kept reads**: up to 4 whole reads of files that did not change since;
83
+ - **kept searches**: the latest `grep` or `rg` output of each command (up to 4), under the same rules;
84
+ - an action trail: the agent's other tool calls (up to 30), without their output, each with a pointer.
85
85
 
86
- Tool output stays in the session file, not in the summary. Each summary ends with a short instruction to the agent: re-read a file before you edit it, look things up, and treat anything not shown as unknown.
86
+ A later write or edit, a shell command that is not read-only and names the file, or a git `checkout`, `stash`, `restore` or `reset` drops a kept read or search. A search that pi-tuck cannot classify is never kept. The header of a kept read says only that no write or edit was recorded since. It does not prove that the file on disk is unchanged.
87
87
 
88
- The summary is plain text, one line per record, such as `#12 user @2026-10-30T14:00:00Z: text`. The number is the index that `tuck_recall` takes. Summaries from earlier versions are still read.
88
+ Whatever does not fit is counted. `tuck_recall` reads it back by index range. Tool output stays in the session file. Each summary ends with a short instruction to the agent: re-read a file before you edit it, look things up, and treat anything not shown as unknown.
89
89
 
90
- The agent gets one tool to get anything back:
90
+ The summary is plain text, one line per record, such as `#12 user @2026-10-30T14:00:00Z: text`. The number is the index that `tuck_recall` takes.
91
91
 
92
- - **`tuck_recall`** finds earlier text by keyword. It reads any original message or tool result exactly, by the index shown in a summary. It can also write an original out to a file.
93
-
94
- pi-tuck's tool appears only after its first cut. Before that there is nothing out of view to recall, and a request is byte-identical to one without pi-tuck (254 of 254 requests on replay).
92
+ `tuck_recall` finds earlier text by keyword. It reads any original message or tool result by index. It can write an original out to a file. The tool appears only after the first cut. Before that, a request is the same as one without pi-tuck.
95
93
 
96
94
  | Command | Does |
97
95
  |---|---|
98
- | `/tuck` | Says in words what pi-tuck is doing in this session: the version this session loaded (an open session keeps it until Pi restarts), how many cuts and retries pi-tuck made and the last cut's size before and after, whether the cut point adapts or is fixed by `cutAt`, and, since 1.1.1, `standing down:` with the reason when pi-tuck is not acting. It is for you; the model sees nothing new. |
99
- | `/tuck-incident on\|next\|off\|status` | Records this session's compaction decisions to a file you can attach to a bug report. |
100
-
101
- Since 1.1.1, pi-tuck stands down to native Pi when it cannot do its job safely: with an unknown context window (0, missing or not a number), with a Pi virtual model, or with Pi's auto-compaction turned off. It then does exactly what native Pi does, and `/tuck` says `standing down:` with the reason. Refusal, overflow and manual-cut notices also reach stderr when there is no UI (`pi -p`, JSON runs), as the output-limit notice already did.
102
-
103
- `/compact` works as usual. Text after it does not steer the summary, because pi-tuck builds the summary from the session itself: since 1.0.19 it cuts as plain `/compact` does and says the text was not used. Pi's own setting `"compaction": { "enabled": false }` turns compaction off.
104
-
105
- ## What is proven, and what is not
106
-
107
- **Measured so far.** In the 128k live run (pi-tuck 1.0.1), a pi-tuck cut took a median 0.08 s, where Pi's compaction with a local model writing the summary took a median 235 s. A cut calls no model, so it costs no tokens. After a cut, both carried about the same context. On mechanical probes about facts cut away, pi-tuck with its recall tools was not more than 3 points below Pi's compaction prompts on mac-studio/main:xhigh, or below Pi's compaction prompts on GPT-6.1 Terra, each answering from its summary alone (claim line above; cuts 1 to 4 only). Over 300 tasks per arm, pi-tuck resolved 258 and Pi's compaction 251; the registered claim is only that pi-tuck lost no more than 0.4 points. In replay, answers held when pi-tuck cut at 60% of the room instead of 100%. At a 32k window, in one suite of 150 SWE-bench Verified tasks with one model, pi-tuck 1.0.5 resolved 120 tasks and Pi's built-in compaction 94 (+17.3 points, 95% lower bound +10.7). Observation masking resolved 117 (pi-tuck +2.0 points, lower bound −2.7: no difference shown). The limits of each result are in [Benchmarks](#benchmarks).
108
-
109
- **Not claimed.** This README does not say that pi-tuck is as good as or better than any compactor, model, window or kind of task other than those named, and it never calls it "the best LLM compactor". The retention tests compare pi-tuck with its recall tools against Pi's compaction without them. The tests were pre-registered before any result came in. The plans, and every result, including those that did not favour pi-tuck, are in [`benchmark/`](benchmark).
110
-
111
- The pre-registered plan has three parts:
112
-
113
- 1. **A live run** at a 128k window on a local model, with pi-tuck 1.0.1. Ten chains of 30 SWE-bench Verified tasks per arm, with Pi's built-in compaction in one arm and pi-tuck in the other. Official grading.
114
- 2. **A paired replay with probe questions.** The same cuts, made by pi-tuck and by Pi's summarize prompts, then questions about facts that fell before the cut. Pre-registered rule: the claim holds only if pi-tuck is no more than 3 points worse than the better compactor, with a one-sided 95% bound. The comparators are named in [`benchmark/PINS.md`](benchmark/PINS.md) and above.
115
- 3. **A 32k suite**, where tasks are bigger than the room, so cuts must summarise work in progress. Its result is the 32k row above.
116
-
117
- The plan: [`benchmark/PREREG.md`](benchmark/PREREG.md), [`benchmark/PREREG-32K.md`](benchmark/PREREG-32K.md), [`benchmark/PREREG-TERRA.md`](benchmark/PREREG-TERRA.md), and every change after the freeze in [`benchmark/DEVIATIONS.md`](benchmark/DEVIATIONS.md).
118
-
119
- Known limits today:
120
-
121
- - pi-tuck's summary does not explain why things happened. It holds the words that were said, not a model's reading of them. The agent must look things up. Each look-up costs a tool call.
122
- - Small windows: an upstream that spends far more context on tool schemas than others (some OpenRouter upstreams do) can leave a small input room too little space. pi-tuck then refuses to cut rather than overflow. This made 1.0.1 refuse at a 32k window with Pi's default 16,384 reserve. Version 1.0.4 added a notice that says when the provider counts far above pi-tuck's estimate. In 1.0.4, after an oversize tool result or a "Nothing to compact" error from Pi, a session could keep refusing later prompts; 1.0.5 fixed both. Version 1.0.8 clips a fresh tool result that is too large for the room (its head and tail, with a `tuck_recall` locator to the rest) instead of refusing the run. If a small window still refuses, pin a different upstream or use a larger window; see [Small windows](#small-windows).
123
- - Small window, after a stopped run (1.0.8 and 1.0.9 only; fixed in 1.0.10): Pi's default `compaction.keepRecentTokens` (20,000) can exceed pi-tuck's input room, which was the window less the larger of `compaction.reserveTokens` and the model's maximum output (16,384 at a 32k window with the default reserve). After a run that is stopped (Esc, or a time limit) with the context above the room, every later prompt could be refused with "The request needs a cut and Pi has none to make (Nothing to compact (session too small))", and the session stayed stuck. In one check at these defaults (pi-tuck 1.0.8, 32k window, one session of 30 tasks, one local model), 28 tasks were lost, tasks 3 to 30 ([`benchmark/RESULTS-DEFAULTS.md`](benchmark/RESULTS-DEFAULTS.md)). If you are on 1.0.8 or 1.0.9, upgrade to 1.0.10. In 1.0.10 the cut a prompt needs is pi-tuck's own, so `keepRecentTokens` no longer leaves it with nothing to cut. A rerun of the same check on the 1.0.10 candidate had no refusal and no stuck session. It had two caveats: two of its tasks had a first request the local server never answered, and 8 of its 30 tasks began without their prompt, which the refusal counter cannot see (fixed in 1.0.12; see Benchmarks and [`benchmark/RESULTS-DEFAULTS-1010.md`](benchmark/RESULTS-DEFAULTS-1010.md)). Windows of 128k and up were not affected at the defaults.
124
- - A prompt could be lost, with no notice (1.0.10 and 1.0.11; fixed in 1.0.12). When a new prompt arrived over the cut point and pi-tuck's cut kept nothing of the conversation before it, which happens when everything since the last cut is one long turn, the prompt was dropped from the request and from the saved session. The model never saw it and usually went on with the previous task, so work you asked for could be lost, and could look answered. The next prompt ran normally. If you used 1.0.10 or 1.0.11 and a reply ignored what you had just asked, this is the likely cause. Upgrade to 1.0.12 ([`CHANGELOG.md`](CHANGELOG.md) 1.0.12).
125
- - A host that patches a large section into the system prompt could get a refusal that a cut would have fit (1.0.0 to 1.0.16; fixed in 1.0.17). pi-tuck plans a prompt's cut when the prompt arrives, before other extensions change the system prompt. A host engine that adds a section of thousands of tokens for one turn could push that turn's first request over the room, and the final guard refused it. Now the guard plans the cut against the system prompt as finally sent, and refuses only if that cut does not fit either ([`CHANGELOG.md`](CHANGELOG.md) 1.0.17).
126
- - pi-tuck refused requests that fit the window, and could strand a session (1.0.0 to 1.0.21; fixed in 1.0.22). It refused at the room, the window less the full reply reserve, where native Pi still sends. With Pi's defaults and a large setup, a session could be refused at every prompt. The final refusal now sits at the window less a reply floor ([`CHANGELOG.md`](CHANGELOG.md) 1.0.22).
127
- - pi-tuck 1.0.25 failed to load in an installed Pi ("Cannot find module '@earendil-works/pi-ai/utils/estimate'"); fixed in 1.0.26, and 1.0.25 is deprecated. Since 1.0.23, the check of Pi's own reply cap also never ran in an installed Pi, for the same reason: Pi's extension loader resolves only a few pi-ai entry points for an installed package. It loaded only in tests and the eval harness, and the installed package fell back to the same 4,096-token margin without it. Fixed in 1.0.26, which was loaded in a real installed Pi before publishing ([`CHANGELOG.md`](CHANGELOG.md) 1.0.26).
128
- - A request above the room could be admitted and then refused, leaving the session stuck where native Pi would have sent (1.0.22 to 1.0.24; fixed in 1.0.25). pi-tuck checked its line in its own corrected token count, while Pi's reply cap uses Pi's own estimate, which is higher when the provider counts fewer tokens than pi-tuck's raw measure ([`CHANGELOG.md`](CHANGELOG.md) 1.0.25).
129
- - Near the 1.0.22 refusal line, replies were cut to a few hundred tokens (1.0.22; fixed in 1.0.23). 1.0.22 left only its reply floor and did not count Pi's 4,096-token margin on the reply cap ([`CHANGELOG.md`](CHANGELOG.md) 1.0.23).
130
- - Cost of the 1.0.22 change: between the room and the window, the reply reserve no longer cushions a wrong count. At a cold start an undercount can reach the provider. A provider that errors is caught and learned from; a server that truncates silently truncates, as it does for native Pi. With a setup above the room, cuts are forced and frequent, each freeing little, which beats a stranded session ([`CHANGELOG.md`](CHANGELOG.md) 1.0.22).
131
- - Fixed in 1.2.0: kept reads could quote a stale or partial file as if it were whole and current. A cut's summary now keeps only whole reads, and drops a read when a later shell command that is not read-only names the file, or when a git command such as `checkout`, `stash`, `restore` or `reset` ran. In the live gate, kept-read records quoting a partial or stale read were 0 against 141 ([`CHANGELOG.md`](CHANGELOG.md) 1.2.0).
132
- - Fixed in 1.1.3: a steering message after a very large tool round could end the run with a false refusal. When the user or a harness sent a message while the agent was working, right after a round of tool results too large for the window, pi-tuck planned that cut as if a new run were starting. The summary could then leave out the prompt that started the run, and pi-tuck's own prompt check refused with "the request is missing the whole text of the prompt that started this run". The cut now keeps the running task's prompt and the fresh tool round, as a cut at a tool boundary does ([`CHANGELOG.md`](CHANGELOG.md) 1.1.3).
133
- - Fixed in 1.1.1: a resumed session forgot what pi-tuck had learned about the provider's token counts. pi-tuck saved its calibration only inside a cut, so after quitting and resuming Pi before the next cut it counted at 1x again and could send a request the provider truncated or refused, where native Pi succeeded. pi-tuck now saves a small private entry in the session when what a resume would learn changes, not every turn, and reads it back on resume. The entry never reaches the model ([`CHANGELOG.md`](CHANGELOG.md) 1.1.1).
134
- - Fixed in 1.1.1: pi-tuck refused prompts that native Pi would have sent when the context window was unknown, the model was a Pi virtual model, or Pi's auto-compaction was turned off. It now stands down to native in those cases. Also fixed in 1.1.1: refusal, overflow and manual-cut notices were silent without a UI, so a run in `pi -p` or JSON mode could end with no word; and a retry after a reply hit the output limit skipped a check that a pending cut had really been saved in the session ([`CHANGELOG.md`](CHANGELOG.md) 1.1.1).
135
- - Fixed in 1.0.33: a file read's recall number pointed at the read call, not at what the read returned. The summary lists each file the session read with a `tuck_recall` number, and that number brought back the call's arguments instead of the file's contents, so recalling a read cost a turn and showed nothing useful. It now brings back the read's output ([`CHANGELOG.md`](CHANGELOG.md) 1.0.33).
136
- - Fixed in 1.0.31: input that arrived after a tool round had been checked, such as another extension's context or a newly enabled tool, could push the next request past the hard line, and the final check refused a request that pi-tuck could still cut. It now cuts at that check, carries the cut in that request, saves it at the next boundary, and refuses only when no cut can fit ([`CHANGELOG.md`](CHANGELOG.md) 1.0.31).
137
- - Fixed in 1.0.29, when Pi's configured window was larger than the server's: a session could get stuck after one overflow, because pi-tuck mistook a cut Pi had saved for one Pi had failed to save. And a server that silently shrinks the reply to fit its real window went unnoticed, so pi-tuck answered fewer prompts than plain Pi. A reply that stops for length below the reply cap Pi sent is now read as the server's real window: pi-tuck learns it, keeps it for the model in the session, plans with the smaller window, and retries that turn once ([`CHANGELOG.md`](CHANGELOG.md) 1.0.29).
138
- - 1.0.28 moved each piece of state that had several owners to one owner: the pending cut, the run and reply fit. Requests were unchanged. It also fixed a plan made for a prompt that another extension handled, which could still answer Pi's own compaction check before a later run and make a cut deeper than needed ([`CHANGELOG.md`](CHANGELOG.md) 1.0.28).
139
- - A run that a custom message started could lose that message after a cut in the middle of the run (fixed in 1.0.27). pi-tuck protected only a prompt the user typed, so a tool-loop cut in a run an extension started with a custom message kept the message neither whole nor quoted, and later requests lacked the instruction that started the run. Now such a message gets the same protection as a typed prompt: it is kept, or quoted whole in the summary, and the guard checks it. A custom message with no text has nothing to quote and stays unprotected ([`CHANGELOG.md`](CHANGELOG.md) 1.0.27).
140
- - A prompt's cut could reach a run it was not planned for (fixed in 1.0.24). pi-tuck plans a prompt's cut when the prompt arrives. When another extension handled that prompt, no run started, and the plan waited for the next run. A run started by a custom message carried a cut sized for the prompt that never ran, deeper than needed. After a move in the session tree (`/tree`), the plan was applied on the new branch, where its kept entry was not present, so the request lost the custom message that started the run, even on a branch that needed no cut ([`CHANGELOG.md`](CHANGELOG.md) 1.0.24).
141
- - pi-tuck cut earlier than native Pi when a model's reply cap is above Pi's reserve (1.0.0 to 1.0.19; fixed in 1.0.20). It reserved the larger of Pi's `compaction.reserveTokens` and the model's `maxTokens`: with `maxTokens` 32,768 and a reserve of 16,384 on an 81,920 window, its room fell to 49,152 tokens, where native Pi compacts at 65,536 ([`CHANGELOG.md`](CHANGELOG.md) 1.0.20).
142
- - A summary could drop the task a session was working on (1.0.0 to 1.0.17; fixed in 1.0.18). Until 1.0.15 a summary quoted only the session's first user turn, up to 12,000 characters, and the newest one, so in a long session the current task, an older turn followed by short steps, was clipped or dropped while a finished first task stayed whole, and agents acted on a days-old task. 1.0.16 added more quotes. From 1.0.13 to 1.0.17, separate rules decided what a summary quoted and what the kept tail held, and the prompt that set the current task, or the first prompt, could lose its opening after a cut: the stress test found it 40 times in 32 cells on 1.0.16 and 1.0.17. Since 1.0.18 one ranked list fills a cut's room, and the stress test finds no lost opening in 287 cells. Short sessions, and the SWE-bench chains behind our benchmarks, keep each task's prompt in the kept tail and never hit it. Upgrade to 1.0.18 ([`CHANGELOG.md`](CHANGELOG.md) 1.0.18).
143
- - pi-tuck 1.0.16 cost more in live chains than its notes first said. Against 1.0.13 at an 81,920 window, it took 1.48 times the turns on the tasks both resolved (95% interval 1.34 to 1.64), 74% more cuts and 1.66 times the tokens, with 56 of 60 tasks resolved against 55. Replay of single-task sessions cannot show this cost. 1.0.18 replaced its quote rules; in the 1.0.18 gate it took 22.27 turns per task against 29.35 for 1.0.16 and 20.22 for the 1.0.13 arm (different pairs of runs; reported, not claimed) ([`benchmark/RESULTS-V1016.md`](benchmark/RESULTS-V1016.md), [`CHANGELOG.md`](CHANGELOG.md) 1.0.18).
144
- - Since 1.0.18, on replay of 17 recordings, estimated request time against 1.0.13 is 2.2% higher quiet and 4.2% higher loaded at 81,920, and 1.1% and 1.9% lower at 131,072. Billed input moves the same way. At 81,920 each cut carries about 600 more tokens. Sessions that are open keep the build they started with until they are restarted ([`CHANGELOG.md`](CHANGELOG.md) 1.0.18).
145
- - The cut point adapts by itself since 1.0.13; before it, pi-tuck cut too often at small windows or with a large setup (1.0.11 and 1.0.12). The trade, from the changelog: on windows that cut too often, each request now carries more context. Cuts, re-processing and request time fall, and billed tokens rise on paid models. On replay of real sessions at an 81,920 window, cuts went from 22.3 to 9.3 per 100 requests, request time was about 16 to 20% lower, and billed tokens were 16 to 19% higher; at a 65,536 window billed tokens rose by as much as 35%. A very large setup at a small window, such as 40k at 65,536, still leaves too little free room for a good rhythm: cuts stay frequent and free little ([`CHANGELOG.md`](CHANGELOG.md) 1.0.13).
146
- - Still applying (1.0.11 to 1.0.16): a fresh assistant message larger than the free room is refused, and a short next prompt recovers (in an unattended `pi -p` run, a refusal ends the run). A reply that reports more than the window reads to Pi as a silent overflow; when nothing can be cut, pi-tuck refuses the next prompt, and the prompt after that runs. If a provider keeps rejecting requests in a wording Pi does not class as a context overflow, or with a bare HTTP 413, pi-tuck does not recover on its own: the session stays intact, and every prompt can fail until the request shrinks. Try `/compact` ([`CHANGELOG.md`](CHANGELOG.md) 1.0.13).
147
- - Other extensions (1.0.10): a prompt's cut no longer goes through Pi's `session_before_compact`, so another extension's veto there no longer stops it. It never stopped a cut between tool rounds. Pi's own threshold and overflow cuts, and `/compact`, still ask other extensions as before.
148
-
149
- ## Benchmarks
150
-
151
- Each row says what was measured, under which conditions, and where the data is.
152
-
153
- | What | Result | Conditions | Source |
154
- |---|---|---|---|
155
- | Pi's default compaction settings, 32k window, pi-tuck 1.0.10 candidate | Passed as registered: 0 dead tasks and 0 stuck sessions on 30 tasks, on a slow local server (27 of 30 tasks hit the 30-minute wall cap, and 2 had a first request the server never answered). 6 resolved. A counter written later, which counts a task with no token as dead, would count those 2. **The registered counter counts refusals and cannot see a task that began without its prompt**: in 8 of the 30 tasks (4, 8, 9, 10, 13, 14, 17, 21) a cut at the prompt kept no turn, none of the 8 resolved, and 6 ended with an empty patch. So the pass shows no refusal, not that every task began with its prompt. The 1.0.11 candidate on the same test had 7 of 30 such tasks, 1 resolved. Fixed in 1.0.12 | Candidate `a67ec30` of 1.0.10, `mac-studio/main`, window 32,768, output cap 16,384, Pi's default `reserveTokens` 16,384 and `keepRecentTokens` 20,000, one session of chain t06. One mid-run refusal (a round with 9,020 tokens of reasoning against the 16,384-token room). One session per arm, one model. In 12 of the 15 tasks across both arms the model's own first messages show it lacked the prompt; the other 3 are not clear from the records | [`benchmark/RESULTS-DEFAULTS-1010.md`](benchmark/RESULTS-DEFAULTS-1010.md) |
156
- | Pi's default compaction settings, 32k window, pi-tuck 1.0.8 | 28 of 30 tasks lost (tasks 3 to 30, each refused at its prompt); 1 resolved. Fails the pre-registered bar of 0 lost tasks | pi-tuck 1.0.8 (`86935e9`), `mac-studio/main`, window 32,768, output cap 16,384, `reserveTokens` 16,384 and `keepRecentTokens` 20,000 (larger than the room), one session of chain t06. One session, one model, one build: it shows that the failure occurs at these settings, not how often. Not comparable with other rows | [`benchmark/RESULTS-DEFAULTS.md`](benchmark/RESULTS-DEFAULTS.md) |
157
- | Tasks resolved, 32k window | Pi's built-in compaction 94 of 150; pi-tuck 120 of 150 (+17.3 points, 95% lower bound +10.7); observation masking 117 of 150 (pi-tuck +2.0, lower bound −2.7: no difference shown). Turns per task: 9.4 (built-in), 24.0 (pi-tuck), 11.9 (masking). Tokens per session: 6.10 M, 6.39 M, 7.02 M. Spend per arm for the five sessions: $0.87, $0.55, $0.94 | pi-tuck 1.0.5 (commit `aa30824`, the 1.0.5 code; 1.0.6 and 1.0.7 are not measured). DeepSeek V4.1 Flash pinned to one upstream, window 32,768, reserve 16,384, 5 chains of 30 SWE-bench Verified tasks, paired by task, one-sided bootstrap over tasks. **Limits:** only pi-tuck is held to the 16,384-token room (the built-in sent a request over it in 97 of 150 tasks, masking in 73, so the window is nominal for them). The difference by chain is +10.0, −3.3, +50.0, +16.7 and +13.3 points; leaving out chain t03 it is +9.2. The bootstrap resamples tasks, not chains. The pi-tuck arm ran at a different time from the others. One model, one window. pi-tuck refused to cut mid-run in 5 tasks, where one fresh tool result was larger than the room; they count as unresolved. In the same setup pi-tuck 1.0.3 resolved 72 of 150, with 52 dead tasks (tasks refused at their prompt after an earlier failure). In the pi-tuck arm of this row there was 1 dead task (t03 task 24: refused at its prompt with "Nothing to compact"; the next task ran normally), so this build missed the pre-registered acceptance bar of zero dead tasks by one task (the other part of the bar, no loss against 1.0.3 by more than 3 points, was met) | [`benchmark/RESULTS-32K-ACCEPT.md`](benchmark/RESULTS-32K-ACCEPT.md) |
158
- | Kept searches (1.3.0, shipped in 1.3.1): live gate against 1.2.0's line | In a 10-task paired live gate, the agent repeated a search after a cut 0.23 times per cut against 0.45, and resolved 5 tasks the other build missed against 2, with no refusals, lost tasks or error stops | NVIDIA Nemotron, room 16,384, 10 paired tasks, one model, one room, one run per arm. The counts are what the ten tasks showed, and no effectiveness claim is made. 1.3.1 is 1.3.0's code: 1.3.0 never reached npm because a timing check in the test suite stopped its publish on the release runner | [`CHANGELOG.md`](CHANGELOG.md) 1.3.0 and 1.3.1 |
159
- | pi-tuck 1.2.0: live gate against 1.1.2, and replay against 1.1.3 | Live gate, 10 paired tasks at room 16,384: solved wins minus losses +1 (bar: at least −1), turn-cap stops 3 against 4, doubt moments 6 against 9, 0 lost tasks; kept-read records quoting a partial or stale read 0 against 141. Replay against 1.1.3 (byte-identical to 1.1.2): 29 recordings, cuts 1,975 to 1,869 and clips 16 to 8 with the smaller tool list and the stricter kept reads, 0 lost or dead tasks, 0 faults | Ten tasks on NIM Nemotron, one model, one room, one run per arm: no effectiveness claim is made. The gate found one false refusal after a steering message, fixed in 1.1.3 and pinned by tests built from that run. Strict stress: 322 cells, 0 findings. Tests and CI on macOS and Ubuntu; the full suite also passed on Windows | [`CHANGELOG.md`](CHANGELOG.md) 1.2.0 |
160
- | Kept reads (1.1.0): 5-task check against 1.0.31, and replay against 1.0.33 | No breakage in 5 of 5 tasks, and all 5 solved on both builds. Re-checks after a doubt 22 against 45; doubt moments 9 against 24; cuts 22 against 26; turns 305 against 384. One heavy task went worse: 90 turns against 59, 9 cuts against 4, 3 doubts against 1. Replay against 1.0.33: 13,946 requests, 0 lost or dead tasks, clips 17 to 16, cuts 1,946 to 1,971; in every recording that differs, the first difference is the first summary carrying a kept read, and 11 of 29 never differ | Five tasks, before the Tier 1. This is not an effectiveness result and no effectiveness claim is made for kept reads. The Tier 1 against 1.0.33 is still running; if it fails, npm and installs go back to 1.0.33. Strict stress: 0 findings in 313 cells on Pi 1.2.0 and the newest Pi | [`CHANGELOG.md`](CHANGELOG.md) 1.1.0 |
161
- | pi-tuck 1.0.18 against the recorded 1.0.16 arm, 81,920 window | Registered bar (Tier 1) met: both arms resolved the same 56 of 60 tasks (+0.0 points, one-sided 95% lower bound +0.0, against a bar of above −10); 0 lost tasks: dead tasks, mid-run refusals and dropped prompts are 0 in both arms, and the audit listed one candidate task (t06 task 21), which, with the two other candidate tasks that had a cut at a prompt (t06 task 8, t07 task 24), was read by hand and works on its own task. Readouts: turns per task 22.27 against 29.35, cuts 57 against 61, total tokens 40.3 M against 62.1 M. Against the recorded 1.0.13 arm of the adaptive gate, a different pair of runs a day apart, 1.0.18 is at 22.27 turns per task against 20.22 and 40.3 M tokens against 37.4 M | Pre-registered gate. pi-tuck 1.0.18 (`2d1f830`, tag `v1.0.18`), run from the unpacked npm tarball; its `src/` is byte-identical to `1ea1e1e`, the commit replay and the stress test measured, ran alone on chains t06 and t07 (60 tasks) against the recorded 1.0.16 arm; the arms did not run side by side, the base earlier the same day, so seconds are not compared. One model, one window, one run per arm. The resolved result is a bound, not a gain. The turn, cut and token readouts are reported, not claimed | [`benchmark/RESULTS-V1018.md`](benchmark/RESULTS-V1018.md) |
162
- | pi-tuck 1.0.16 against the recorded 1.0.13 arm, 81,920 window | Registered bar (Tier 1) met: resolved 56 of 60 against 55 (+1.7 points, one-sided 95% lower bound +0.0, against a bar of above −10); 0 lost tasks. Readouts: turns per task 29.35 against 20.22 (1.48 times on the 55 tasks both resolved, 95% interval 1.34 to 1.64), cuts 61 against 35, total tokens 62.1 M against 37.4 M | Pre-registered gate. pi-tuck 1.0.16 (`dee0eab`) ran alone on chains t06 and t07 (60 tasks) against the recorded 1.0.13 arm from the adaptive gate; the two arms did not run side by side, the base a day earlier, so seconds are not compared. One model, one window, one run per arm. The resolved result is a bound, not a gain. The cost readouts are reported, not claimed. 1.0.18 replaced this build's quote rules | [`benchmark/RESULTS-V1016.md`](benchmark/RESULTS-V1016.md) |
163
- | The adaptive cut point (1.0.13) against 1.0.12, 81,920 window | Registered bar (Tier 2) met: resolved 131 of 150 in both arms (+0.0 points, one-sided 95% lower bound −1.3, against a bar of above −5); 0 lost tasks in the candidate arm. The 0 counts dead tasks, tasks whose prompt was dropped at a cut, and tasks an audit found started without their prompt; all 11 tasks with a cut at a prompt, in both arms, were also read by hand, and in each the model's first messages work on that task | Pre-registered gate. pi-tuck 1.0.13 (`6f13685`) is the exact code the gate measured (`882f6f6`); only the version and the notes changed. It was measured against pi-tuck 1.0.12, `mac-studio/main` at xhigh, window 81,920, reserve 16,384, `keepRecentTokens` 20,000, 5 chains (t06 to t10) of 30 tasks, 150 paired tasks, one run per arm, one model throughout. The resolved result is a bound, not a gain. Turns, tokens and seconds are in the file and are not claimed here. Nothing about other windows, models or builds | [`benchmark/RESULTS-ADAPTIVE.md`](benchmark/RESULTS-ADAPTIVE.md) |
164
- | The 1.0.10 candidate against 1.0.9, 32k window | 0 dead tasks in both arms; no mid-run refusal. Resolved 50 of 60 (1.0.9) and 49 of 60 (1.0.10 candidate): −1.7 points, 95% lower bound −8.3. **The gate failed as registered, by one task**; 1.0.10 shipped as an exception because of the small-window defect. 6 of the 1.0.10 candidate's 60 tasks began without their prompt (4 of them resolved), against 0 in the 1.0.9 arm; fixed in 1.0.12. Turns per task 25.08 and 29.12; cuts 731 and 884; total tokens 13.07 M and 15.12 M | Pre-registered gate. pi-tuck `a67ec30` against 1.0.9 (`cd4626b`). DeepSeek V4.1 Flash pinned to one upstream, window 32,768, reserve 16,384, `keepRecentTokens` 3,333, chains t01 and t02, 60 paired tasks. One model, one window, one run per arm; 60 tasks cannot separate a one-task difference from run-to-run variation | [`benchmark/RESULTS-V110.md`](benchmark/RESULTS-V110.md) |
165
- | The 1.0.8 candidate against 1.0.7, 32k window | 0 dead tasks in both arms. Resolved 46 of 60 in both (+0.0 points, 95% lower bound −6.7). No mid-run refusal in either arm. Turns per task 25.37 (1.0.7) and 26.10 (1.0.8) | Pre-registered gate, passed as registered. pi-tuck `a2e7d1a` (the tool-result clip and the cut at the end of a run, on 1.0.6) against 1.0.7. Released 1.0.8 is that build merged with 1.0.7's change; its replay requests are reported byte-identical to the gated build on 29 recordings (stated in the source file, not re-run for this README). DeepSeek V4.1 Flash pinned to one upstream, window 32,768, reserve 16,384, chains t01 and t02, 60 paired tasks, both arms run together. One model, one window, one run per arm; 60 tasks cannot show a difference smaller than the bound. The run shows that the change introduced no refusal; no refusal occurred in the 1.0.7 arm for the clip to prevent | [`benchmark/RESULTS-V108.md`](benchmark/RESULTS-V108.md) |
166
- | Cut time, live, 128k | pi-tuck median 0.081 s (46 cuts; 90th percentile 0.279 s). Pi's compaction median 235.3 s (48 cuts; 90th percentile 403.8 s). Context carried after a cut, median: 26,790 tokens (pi-tuck), 27,750 (Pi's compaction) | pi-tuck 1.0.1, Pi 1.4.0, SWE-bench Verified, 10 chains of 30 tasks, window 128,000, reply reserve 32,768, `mac-studio/main:xhigh` writing Pi's summaries. The built-in time depends on that model and on server load. pi-tuck's time is an upper bound, read from the session file: the time between the entry written just before the cut and the compaction entry, so it includes anything between the last message and the cut (pi-tuck's tool-loop cuts emit no compaction events). The 44 failed compaction attempts in chain s09-A have no compaction entry and are not in the counts | [`benchmark/RESULTS-MAIN.md`](benchmark/RESULTS-MAIN.md) test 3 |
167
- | Cut time, paired replay, 128k | pi-tuck median 0.061 s (95 cuts). Pi's compaction prompts on mac-studio/main:xhigh 154.6 s (86 cuts). Pi's compaction prompts on GPT-6.1 Terra 53.2 s (87 cuts, 19 recordings). Context carried after a cut, median: 27,656, 25,790 and 22,784 tokens; median summary 85,561, 23,598 and 11,200 characters | The same recorded sessions cut at the same raw positions. pi-tuck 1.0.1. Terra's cuts ran through Codex, not on the local server | [`benchmark/RESULTS-MAIN.md`](benchmark/RESULTS-MAIN.md) test 3 |
168
- | Retention, 128k, test 1a: pi-tuck with its recall tools against Pi's compaction prompts on mac-studio/main:xhigh | Registered claim: not more than 3 points below, on these probes (cuts 1 to 4 only) (supported). Accuracy on the probes each was asked: 89.7% (783 probes) and 61.8% (1,677). Difference over the 783 shared probes, which come from the 43 of pi-tuck's 95 answer sets that did not abort: +25.7 points, one-sided 95% lower bound +22.0 (+22.3 clustered by chain). By probe type, pi-tuck / comparator: error class 80.2 / 24.7, files changed 84.5 / 78.9, result-line rule 100.0 / 100.0, required tag 100.0 / 99.3, test-runner summary 90.1 / 31.6 | pi-tuck 1.0.1, 20 recordings, mechanical probes only, evidence at least 35,000 raw tokens before the cut. pi-tuck answered with its recall tools (1.0.1 had a second recall tool, since removed) and the comparators with none, from the summary and the kept recent messages. Every one of the 43 asks behind the 783 probes made recall calls (1.25 per probe on average), so no pi-tuck answer lacked the tools; the run cannot show how much of the result comes from the summary and how much from recall. No pi-tuck arm without recall tools exists. The comparators' agents had unrestricted bash, and the logs cannot rule out that one read a recording; nothing shows it. pi-tuck's accuracy does not rise with more calls per probe (87.9%, 90.8%, 90.0% by thirds; post hoc, descriptive). The 783 shared probes are fewer than the 2,969 needed to certify a difference near the margin | [`benchmark/RESULTS-MAIN.md`](benchmark/RESULTS-MAIN.md) test 1a |
169
- | Retention, 128k, test 1b-Terra: pi-tuck with its recall tools against Pi's compaction prompts on GPT-6.1 Terra | Registered claim: not more than 3 points below, on these probes (cuts 1 to 4 only) (supported). Accuracy on the probes each was asked: 89.7% (783) and 57.8% (1,685). Difference over the 728 shared probes, from the same 43 of pi-tuck's 95 answer sets: +33.7 points, one-sided 95% lower bound +30.4 (+30.1 clustered by chain). By probe type, pi-tuck / Terra: error class 80.2 / 14.7, files changed 84.5 / 72.3, result-line rule 100.0 / 100.0, required tag 100.0 / 93.3, test-runner summary 90.1 / 38.1 | As test 1a, on 19 of the 20 recordings: s09-A is missing because its Terra cut job hit a Codex usage limit, and the set was closed at 19 before any Terra result was read. The claim is non-inferiority. The same limits as test 1a apply | [`benchmark/RESULTS-MAIN.md`](benchmark/RESULTS-MAIN.md) test 1b-Terra |
170
- | Tasks resolved, 128k, test 2 | Pi's compaction 251 of 300, pi-tuck 258 of 300. Registered claim: no loss larger than 0.4 points. All 10 chains: +2.3 points, lower bound +0.3. Without chain s09: +1.5 points, lower bound −0.4 | pi-tuck 1.0.1, 10 chains of 30 tasks, paired by task, bootstrap over chains. In s09-A Pi's compaction failed 44 times ("generation hit the token cap") from task 23 on, and no other chain has a failed compaction; that is why the bound changes without s09 | [`benchmark/RESULTS-MAIN.md`](benchmark/RESULTS-MAIN.md) test 2 |
171
- | Tokens per session, input plus output without cache reads, 128k | 241,000 fewer for pi-tuck per session on average, one-sided 95% upper bound −21,000, with all 10 chains. Without chain s09 the mean is −174,000 and the upper bound +43,000 | pi-tuck 1.0.1, paired by chain, bootstrap over sessions. The line holds only with all chains | [`benchmark/RESULTS-MAIN.md`](benchmark/RESULTS-MAIN.md) test 3 |
172
- | Answers after cutting at 60% instead of 100% | No more losses than the limit on all 4 sets. Losses / wins over n questions: 128k shared 3 / 7 of 99; 128k asymmetric 3 / 1 of 67; 32k shared 5 / 3 of 77; 32k asymmetric 9 / 5 of 343. In the 32k asymmetric set the losses lean against 60% (test_result 4 / 2, error_hit 3 / 1); it is the set to watch | Paired replay, same 5 sessions, DeepSeek flash as agent and judge. Limit, set in advance: losses minus wins at most max(2, 5% of n). Asymmetric = evidence the base keeps native and the variant has summarised | [`rnd/replay32/RESULT-lean.md`](rnd/replay32/RESULT-lean.md) |
173
- | 1.0.2 changes (plain-text summary, shrinking dialogue view, time on user turns only) against 1.0.1 | No more losses than the limit on all 4 sets. Losses / wins: 128k 1 / 2 of 128; 128k time questions 0 / 0 of 48; 32k 4 / 2 of 127; 32k asymmetric 0 / 2 of 56 | Paired replay, 5 recorded live sessions, DeepSeek flash as agent and judge. 11 of 146 answer sessions hit a 15-minute wall limit and drop out of the pairing | [`rnd/replay32/RESULT-lean.md`](rnd/replay32/RESULT-lean.md), [`CHANGELOG.md`](CHANGELOG.md) |
174
- | Summary size, plain-text format against the 1.0.1 JSON format | About 30% shorter where the agent writes little, about 14% shorter where it writes a lot | Same dialogue | [`CHANGELOG.md`](CHANGELOG.md) 1.0.2 |
175
- | Small-window fix | A session that writes little prose cut 174 times in 300 tool rounds at 32k with a 16k reserve (1.0.1 code). With the fix, a test pins that no cut frees under a tenth of the room | Real planner on synthetic sessions | [`CHANGELOG.md`](CHANGELOG.md) 1.0.2 (the 174 cuts); [`test/cut-yield.test.ts`](test/cut-yield.test.ts), which pins that every cut frees at least a tenth of the room |
176
- | Stall fix: a long session's cut | A cut at 3,888 entries took 72 s in 1.0.0 and takes 174 ms since 1.0.1. Since 1.0.1 the cost grows linearly with the session | One machine, the same synthetic session for both numbers (little prose, 128k window, reserve 16,384, turn 644) | [`CHANGELOG.md`](CHANGELOG.md) 1.0.1 |
177
-
178
- Notes:
179
-
180
- - The answer replays use one cheap hosted model (DeepSeek flash) as agent and judge. They compare pi-tuck with other pi-tuck settings and versions. They do not compare pi-tuck with an LLM compactor.
181
- - The 128k rows measure pi-tuck 1.0.1. The newer versions are listed in the [changelog](CHANGELOG.md). A cut still calls no model, but the 128k run has not been repeated on them.
182
- - Everything here is from SWE-bench-style tasks on a small set of models. It may not carry to your work.
96
+ | `/tuck` | Shows the loaded version, the cuts so far, the cut point and, if pi-tuck is not acting, why. |
97
+ | `/tuck-incident on\|next\|off\|status` | Records this session's compaction decisions to a file that you can attach to a bug report. |
98
+
99
+ pi-tuck stands down to native Pi when it cannot work safely: the window is unknown, the model is a Pi virtual model, or Pi's auto-compaction is off. Pi then does what it does without pi-tuck, and `/tuck` says `standing down:` with the reason. With no UI (`pi -p`, JSON runs), refusal, overflow and manual-cut notices go to stderr.
100
+
101
+ `/compact` works as usual. Text after it does not steer the summary. pi-tuck cuts as plain `/compact` does and says it did not use the text. Pi's setting `"compaction": { "enabled": false }` turns compaction off.
183
102
 
184
103
  ## Settings
185
104
 
186
- pi-tuck needs none. One is optional. Put them in `pi-tuck.json` in Pi's agent folder (`~/.pi/agent`, or the folder `PI_CODING_AGENT_DIR` names):
105
+ pi-tuck needs no setting. One is optional. Put it in `pi-tuck.json` in Pi's agent folder (`~/.pi/agent`, or the folder that `PI_CODING_AGENT_DIR` names):
187
106
 
188
107
  ```json
189
108
  { "cutAt": 0.8 }
190
109
  ```
191
110
 
192
- - **`cutAt`** (above 0, at most 1; not set by default) is the part of the input room a request may fill before pi-tuck cuts. With no `cutAt`, the cut point adapts to the session since 1.0.13: it follows what the setup and the last cut left, plus half a tail of room to grow, never below 60% of the room and capped just under the room. Setting `cutAt` fixes it as a fraction of the room, and an explicit value keeps the earlier formula, so remove one you set by hand to stop frequent cuts. `{ "cutAt": 1 }` cuts at the full room. A lower value cuts earlier and smaller. The whole room still decides which request pi-tuck refuses.
111
+ - If you do not set `cutAt`, the cut point adapts to the session. It stays between 60% of the room and just under the room.
112
+ - A number above 0 and at most 1 fixes the cut point as a share of the room. `1` cuts at the full room.
113
+ - If the file is bad, pi-tuck says so at session start and uses the defaults.
193
114
 
194
- A bad file is reported at session start, and pi-tuck uses the defaults.
115
+ ## Small windows
195
116
 
196
- ### Small windows
117
+ - pi-tuck keeps the same reply room as native Pi (`reserveTokens`).
118
+ - After a reply that stops for length with thinking only, pi-tuck retries the turn once.
119
+ - When a run ends on a reply cut at the output limit, pi-tuck says so.
120
+ - When a server clips replies below the window, pi-tuck learns the smaller window. It drops that window when the model's window changes.
121
+ - pi-tuck refuses a request only past the window. The refusal names what does not fit.
197
122
 
198
- pi-tuck keeps room for the model's reply. Since 1.0.20 that room is Pi's `compaction.reserveTokens` (default 16,384), the same as native Pi. It rises to the model's `maxTokens` for the rest of the branch only after a reply on that branch did not fit: a reply that stopped for length, or a request refused as a context overflow. A transient error such as a 503 keeps the native room. This is read from the current branch at each decision, so resume, fork and `/tree` follow the branch, and a new session starts at `reserveTokens` again. A host that passes its own reserve keeps its own. Before 1.0.20, pi-tuck always reserved the larger of the two, so with a large `maxTokens` it cut earlier than native Pi.
123
+ If a small window refuses, use a larger window. With OpenRouter, you can also pin one upstream. Add this to `models.json` in Pi's agent folder, and name the upstream:
199
124
 
200
- Since 1.0.22, pi-tuck refuses a request only past a line near the window. Pi sets each request's reply cap to the window less its own estimate of the request less a 4,096-token safety margin, and since 1.0.26 pi-tuck loads Pi's own reply clamp and estimator from the running Pi's install (a host that embeds Pi falls back to the same 4,096-token margin). Since 1.0.25, each point that sends a request above the room checks Pi's own cap on the request it would send. When that leaves less than the reply floor, pi-tuck cuts deeper, with up to three re-plans and then the deepest cut that still carries the whole prompt, and refuses only if that leaves less than the floor too. The floor is the larger of the biggest reply seen on the branch and 3,584 tokens, capped at the model's own reply cap. After a reply that stopped for length or was refused as a context overflow, the floor is the reserve. The line never sits below the room, where 1.0.21 also sends. Before it refuses, pi-tuck cuts to the band, cuts to the room, makes a smaller summary and clips a fresh tool result, in that order. A run's request always carries the whole prompt that started the run: if it cannot fit after every reduction, pi-tuck stops the run with a notice saying to shorten the prompt or use a larger window. Each refusal, and each request sent above the room, leaves one `pi-tuck-capacity` entry in the session; it is never sent to the model, and never appears in summaries or recall.
125
+ ```json
126
+ { "providers": { "openrouter": { "compat": { "openRouterRouting": { "only": ["your-upstream"], "allow_fallbacks": false } } } } }
127
+ ```
201
128
 
202
- Since 1.0.25, after a reply that stops for length with thinking only, pi-tuck retries the turn once, leaving the stopped reply out of the request. It uses the deepest cut that still carries the whole prompt when that gives the reply more room, and otherwise retries uncut. A retried reply that stops again ends the run. When a run ends on a reply cut at the output limit, pi-tuck says so ("the last reply stopped at the model's output limit and may be cut off"): in the interface, or on stderr when there is no UI. The notice never enters the model's context.
129
+ The details are in [`docs/small-windows.md`](docs/small-windows.md).
203
130
 
204
- pi-tuck estimates the request's size, and it scales that estimate by the worst gap it has seen between its count and the provider's. In a small window, an upstream that spends far more context on tool schemas (some OpenRouter upstreams do) can leave too little room. If a small window refuses, use a larger window, or pin one upstream as below.
131
+ ## Known limits
205
132
 
206
- If you reach the model through OpenRouter, you can also pin one upstream, so that every request is served by the same one. Put this in `models.json` in Pi's agent folder, and name the upstream you want:
133
+ - The summary holds the words that were said, not why. The agent must look things up, and each look-up costs a tool call.
134
+ - A very large fixed setup in a small window keeps cuts frequent, and each frees little. Example: 40k of system prompt and tools at a 65,536 window.
135
+ - Between the room and the window, the reply reserve does not cushion a wrong token count. At a cold start, an undercount can reach the provider. A provider that errors is learned from. A server that truncates silently truncates, as it does for native Pi.
136
+ - pi-tuck learns from a provider refusal only when Pi classes it as a context overflow. After a refusal in another wording, or a bare HTTP 413, pi-tuck does not recover. The session stays intact. Every prompt can fail until the request shrinks. Try `/compact`.
137
+ - A custom message with no text has nothing to quote. If a run starts from one, the message stays unprotected after a cut in the middle of the run.
207
138
 
208
- ```json
209
- { "providers": { "openrouter": { "compat": { "openRouterRouting": { "only": ["your-upstream"], "allow_fallbacks": false } } } } }
139
+ Fixed problems are in [`CHANGELOG.md`](CHANGELOG.md).
140
+
141
+ ## Uninstall
142
+
143
+ ```sh
144
+ pi remove npm:pi-tuck
210
145
  ```
211
146
 
147
+ Use the same source that you installed from. If you turned `/tuck-incident` on, its records are in `~/.local/state/pi-tuck-incidents`. Versions before 1.2.0 downloaded about 460 MB for a feature that no longer exists. pi-tuck deletes those files once per machine when it first starts, and shows a notice. On Windows, delete `~/.pi/agent/pi-tuck` yourself.
148
+
212
149
  ## Use from code
213
150
 
214
- The package also exports its parts for hosts that embed Pi through its SDK:
151
+ Hosts that embed Pi through its SDK can use the package:
215
152
 
216
153
  ```ts
217
154
  import { installCompaction } from "pi-tuck";
@@ -219,7 +156,7 @@ import { installCompaction } from "pi-tuck";
219
156
  const handle = await installCompaction(pi);
220
157
  ```
221
158
 
222
- `installCompaction` options (reply reserve, host-injected messages, recall policy, `cutAt` and others) are documented in [src/compaction.ts](src/compaction.ts). `handle.close()` stops the incident recorder; call it before disposing a session.
159
+ [`src/compaction.ts`](src/compaction.ts) documents the options of `installCompaction`: reply reserve, host-injected messages, recall policy, `cutAt` and others. Call `handle.close()` before you dispose a session. It stops the incident recorder.
223
160
 
224
161
  ## Development
225
162
 
@@ -230,11 +167,11 @@ npm test # unit tests (Vitest)
230
167
  npm run build # dist/ for the library export
231
168
  ```
232
169
 
233
- Changes are listed in [CHANGELOG.md](CHANGELOG.md). Releases are published from GitHub Actions by npm trusted publishing, with provenance.
170
+ [`CHANGELOG.md`](CHANGELOG.md) lists the changes. GitHub Actions publishes releases with npm trusted publishing and provenance.
234
171
 
235
172
  ## Credits
236
173
 
237
- pi-tuck grew out of [pi-vcc](https://github.com/sting8k/pi-vcc) by sting8k and includes code from [pi-blackhole](https://github.com/k0valik/pi-blackhole) by k0valik and from [Pi](https://github.com/earendil-works/pi) by Mario Zechner, all MIT; their notices are in [LICENSE](LICENSE).
174
+ pi-tuck grew out of [pi-vcc](https://github.com/sting8k/pi-vcc) by sting8k. It includes code from [pi-blackhole](https://github.com/k0valik/pi-blackhole) by k0valik and from [Pi](https://github.com/earendil-works/pi) by Mario Zechner, all MIT. Their notices are in [NOTICE](NOTICE).
238
175
 
239
176
  ## License
240
177
 
@@ -1 +1 @@
1
- export declare const BUILD_ID = "b6a612ac60abaf5564c6020053627662851d7c7162337cf023ed686c1d598466";
1
+ export declare const BUILD_ID = "6a84733ab75ecf863fe77c6dd6d0a91602a8a0d353a785c3fdb34585f42637a2";
@@ -1 +1 @@
1
- export const BUILD_ID = "b6a612ac60abaf5564c6020053627662851d7c7162337cf023ed686c1d598466";
1
+ export const BUILD_ID = "6a84733ab75ecf863fe77c6dd6d0a91602a8a0d353a785c3fdb34585f42637a2";
@@ -115,6 +115,8 @@ class Calibration {
115
115
  factor = 1;
116
116
  ratios = [];
117
117
  learnedContextWindow;
118
+ /** The configured window the learned window was learned under; the learned window applies only while the model still has it. */
119
+ learnedCatalogue;
118
120
  windowObservation;
119
121
  pending;
120
122
  lastCeiling = null;
@@ -132,6 +134,7 @@ class Calibration {
132
134
  if (reason === 'session') {
133
135
  this.factor = 1;
134
136
  this.learnedContextWindow = undefined;
137
+ this.learnedCatalogue = undefined;
135
138
  this.estimatedTokens = 0;
136
139
  // Keep the old ratios/ceiling until their existing readers replace them, as in 1.1.1.
137
140
  this.seededIdentity = '';
@@ -143,7 +146,8 @@ class Calibration {
143
146
  const branch = ctx.sessionManager.getBranch();
144
147
  this.ratios = seedWindow(branch, this.identity);
145
148
  this.factor = Math.max(1, ...this.ratios);
146
- this.learnedContextWindow = seedContextWindow(branch, this.identity);
149
+ this.learnedCatalogue = ctx.model?.contextWindow;
150
+ this.learnedContextWindow = seedContextWindow(branch, this.identity, this.learnedCatalogue);
147
151
  }
148
152
  learn(value, ctx, append) {
149
153
  this.ratios.push(value);
@@ -192,7 +196,7 @@ export async function installCompaction(pi, options = {}) {
192
196
  }
193
197
  });
194
198
  const captureDraft = (draft, ctx, reserve, reason, tokensBefore, retainCurrentInput, operatorManual, previousSummary, budget) => recorder.measureInline(() => {
195
- const attached = attachReceipt(draft, reason, reserve, contextWindow(ctx), { responseReserveTokens: budget?.response, hostInputTokens: budget?.host, mandatoryInputTokens: budget?.mandatory, target: budget?.target, triggerMarginTokens: budget?.margin, ...(cutAt === 1 ? {} : { cutAt }), calibrationFactor: calibration.factor, calibrationWindow: [...calibration.ratios], calibrationIdentity: calibration.identity, learnedContextWindow: calibration.learnedContextWindow, activeInputCeilingTokens: calibration.lastCeiling });
199
+ const attached = attachReceipt(draft, reason, reserve, contextWindow(ctx), { responseReserveTokens: budget?.response, hostInputTokens: budget?.host, mandatoryInputTokens: budget?.mandatory, target: budget?.target, triggerMarginTokens: budget?.margin, ...(cutAt === 1 ? {} : { cutAt }), calibrationFactor: calibration.factor, calibrationWindow: [...calibration.ratios], calibrationIdentity: calibration.identity, learnedContextWindow: calibration.learnedContextWindow, ...(calibration.learnedContextWindow !== undefined && calibration.learnedCatalogue !== undefined ? { catalogueContextWindow: calibration.learnedCatalogue } : {}), activeInputCeilingTokens: calibration.lastCeiling });
196
200
  proposalId = receiptId(attached);
197
201
  if (recorder.enabled) {
198
202
  try {
@@ -266,7 +270,9 @@ export async function installCompaction(pi, options = {}) {
266
270
  pi.on("model_select", (_event, ctx) => { calibration.select(ctx); });
267
271
  const contextWindow = (ctx) => {
268
272
  identityFor(ctx);
269
- return Math.min(ctx.model?.contextWindow ?? 0, calibration.learnedContextWindow ?? Infinity);
273
+ const model = ctx.model?.contextWindow ?? 0;
274
+ const learned = calibration.learnedCatalogue === ctx.model?.contextWindow ? calibration.learnedContextWindow : undefined;
275
+ return Math.min(model, learned ?? Infinity);
270
276
  };
271
277
  // This is the cap in Pi's built provider payload, including its context clamp and thinking adjustments.
272
278
  // An API with no explicit cap supplies no clipping evidence; never substitute the catalogue maximum.
@@ -339,9 +345,13 @@ export async function installCompaction(pi, options = {}) {
339
345
  if (message.stopReason === "length" && requested !== undefined &&
340
346
  Number.isSafeInteger(output) && output >= 0 && output < requested &&
341
347
  Number.isSafeInteger(bound) && bound > 0 && bound <= ctx.model.contextWindow) {
348
+ // A learned window from another configured window no longer bounds this one.
349
+ if (calibration.learnedCatalogue !== ctx.model.contextWindow)
350
+ calibration.learnedContextWindow = undefined;
351
+ calibration.learnedCatalogue = ctx.model.contextWindow;
342
352
  calibration.learnedContextWindow = Math.min(calibration.learnedContextWindow ?? Infinity, bound);
343
353
  serverClipped.add(message);
344
- calibration.windowObservation = { message, identity: key, window: calibration.learnedContextWindow };
354
+ calibration.windowObservation = { message, identity: key, window: calibration.learnedContextWindow, catalogue: ctx.model.contextWindow };
345
355
  }
346
356
  // A request that was answered cannot have held more than the model's window, so a report above it describes something that never happened.
347
357
  // Learning from one sets the factor for the requests after it: a 60,000-token cache read reported in a 32,768-token window made a
@@ -356,7 +366,7 @@ export async function installCompaction(pi, options = {}) {
356
366
  return;
357
367
  const observation = calibration.windowObservation;
358
368
  calibration.windowObservation = undefined;
359
- pi.appendEntry(WINDOW_RECEIPT, { calibrationIdentity: observation.identity, learnedContextWindow: observation.window,
369
+ pi.appendEntry(WINDOW_RECEIPT, { calibrationIdentity: observation.identity, learnedContextWindow: observation.window, catalogueContextWindow: observation.catalogue,
360
370
  serverClippedReplyId: event.messageEntryId });
361
371
  });
362
372
  // The operator's length-stop notice is decided at settle and is not attempt state: a run reset before then (a tree move inside another
@@ -1,6 +1,6 @@
1
1
  import { type RecallPolicy } from './recall.js';
2
2
  import type { SessionEntry } from '@earendil-works/pi-coding-agent';
3
- export declare const DIAGNOSTIC_BUILD = "b6a612ac60abaf5564c6020053627662851d7c7162337cf023ed686c1d598466";
3
+ export declare const DIAGNOSTIC_BUILD = "6a84733ab75ecf863fe77c6dd6d0a91602a8a0d353a785c3fdb34585f42637a2";
4
4
  export interface Receipt {
5
5
  id: string;
6
6
  build: string;
@@ -20,6 +20,7 @@ export interface Receipt {
20
20
  calibrationWindow?: number[];
21
21
  calibrationIdentity?: string;
22
22
  learnedContextWindow?: number;
23
+ catalogueContextWindow?: number;
23
24
  activeInputCeilingTokens?: number | null;
24
25
  };
25
26
  before: {
@@ -8,10 +8,6 @@ export declare function filterOmittedSummary(summary: string, omitted: ReadonlyS
8
8
  export declare function filterCustomQuotes(summary: string, entries: readonly SessionEntry[], branch: readonly SessionEntry[], policy?: RecallPolicy): string;
9
9
  type ProjectedMessages = ReturnType<ExtensionContext['sessionManager']['buildSessionProjection']>['messages'];
10
10
  export declare function projectedMessages(messages: ProjectedMessages, ctx: ExtensionContext, policy?: RecallPolicy): ProjectedMessages;
11
- /**
12
- * The same as `projectedMessages` for every summary in this compactor's format, and it never throws for any other: a summary of another
13
- * format (a Pi default summary, an empty draft) cannot be filtered and is left as it is. For counting a conversation that a cut is about
14
- * to replace, such as an operator's /compact on a session whose saved summary is foreign. The context hook and the triggers stay strict.
15
- */
11
+ /** The planner's name for the same projection (kept for its callers). */
16
12
  export declare function measurableMessages(messages: ProjectedMessages, ctx: ExtensionContext, policy?: RecallPolicy): ProjectedMessages;
17
13
  export {};
@@ -128,8 +128,10 @@ export function filterCustomQuotes(summary, entries, branch, policy = {}) {
128
128
  });
129
129
  return transcriptHeader(version) + '\n' + retained.join('\n') + closing;
130
130
  }
131
- /** The saved conversation as this compactor delivers it: native omissions and ineligible custom quotes removed from summaries. */
132
- function projectMessages(messages, ctx, policy, allowForeign) {
131
+ /** The saved conversation as this compactor delivers it: native omissions and ineligible custom quotes removed from its own summaries. A
132
+ * summary of another format (Pi's own /compact before pi-tuck was loaded, an empty draft) cannot be filtered and goes out as it is, as
133
+ * native Pi sends it; the next pi-tuck cut replaces it. Failing closed on it left such a session unable to send any prompt (issue #1). */
134
+ function projectMessages(messages, ctx, policy) {
133
135
  const entries = ctx.sessionManager.getEntries(), branch = ctx.sessionManager.getBranch();
134
136
  const omitted = omittedSourceIndices(entries, branch);
135
137
  const lastCut = branch.findLastIndex(entry => entry.type === 'compaction');
@@ -144,17 +146,13 @@ function projectMessages(messages, ctx, policy, allowForeign) {
144
146
  afterCut.add(index);
145
147
  }
146
148
  }
147
- return messages.map(message => message.role === 'compactionSummary' && (!allowForeign || splitSummary(message.summary) !== undefined)
149
+ return messages.map(message => message.role === 'compactionSummary' && splitSummary(message.summary) !== undefined
148
150
  ? { ...message, summary: filterCustomQuotes(filterOmittedSummary(message.summary, omitted, entries, cut?.type === 'compaction' && cut.summary === message.summary ? afterCut : new Set()), entries, branch, policy) } : message);
149
151
  }
150
152
  export function projectedMessages(messages, ctx, policy) {
151
- return projectMessages(messages, ctx, policy, false);
153
+ return projectMessages(messages, ctx, policy);
152
154
  }
153
- /**
154
- * The same as `projectedMessages` for every summary in this compactor's format, and it never throws for any other: a summary of another
155
- * format (a Pi default summary, an empty draft) cannot be filtered and is left as it is. For counting a conversation that a cut is about
156
- * to replace, such as an operator's /compact on a session whose saved summary is foreign. The context hook and the triggers stay strict.
157
- */
155
+ /** The planner's name for the same projection (kept for its callers). */
158
156
  export function measurableMessages(messages, ctx, policy) {
159
- return projectMessages(messages, ctx, policy, true);
157
+ return projectMessages(messages, ctx, policy);
160
158
  }
@@ -23,13 +23,18 @@ export declare const thinkingOnlyLength: (message: AgentMessage) => boolean;
23
23
  /** Thinking-only exhaustion uses the observed largest reply, not the full reserve. Every other failed length/overflow keeps its override. */
24
24
  export declare const needsFullReplyReserve: (message: AgentMessage) => boolean;
25
25
  /** Saved immediately at the reply's turn boundary, even when recovery cannot make a compaction. */
26
+ /** `catalogueContextWindow` is the model's configured window when the server clipped below it. A learned window holds only while the
27
+ * configured window is unchanged: a server or catalogue that grew must not stay capped by an old clip (Nautilus, 2026-11-20). */
26
28
  export interface WindowReceipt {
27
29
  calibrationIdentity: string;
28
30
  learnedContextWindow: number;
31
+ catalogueContextWindow: number;
29
32
  serverClippedReplyId: string;
30
33
  }
31
34
  export declare const WINDOW_RECEIPT = "pi-tuck-window";
32
- export declare function seedContextWindow(branch: readonly SessionEntry[], identity: string): number | undefined;
35
+ /** The newest learned window for `identity`, if it was learned under the model's current configured window. One recorded before 1.3.3
36
+ * carries no configured window and is not trusted: if the server still clips, the next clipped reply learns it again. */
37
+ export declare function seedContextWindow(branch: readonly SessionEntry[], identity: string, catalogue: number | undefined): number | undefined;
33
38
  /** One branch reader for the reserve override and reply floor, including history before cuts. A server-clipping receipt follows its reply. */
34
39
  export declare function replyFit(branch: readonly SessionEntry[]): {
35
40
  failed: boolean;
@@ -72,13 +72,17 @@ function windowSettings(entry) {
72
72
  return entry.details?.diagnosticReceipt?.settings;
73
73
  return undefined;
74
74
  }
75
- export function seedContextWindow(branch, identity) {
75
+ /** The newest learned window for `identity`, if it was learned under the model's current configured window. One recorded before 1.3.3
76
+ * carries no configured window and is not trusted: if the server still clips, the next clipped reply learns it again. */
77
+ export function seedContextWindow(branch, identity, catalogue) {
76
78
  for (let i = branch.length; i--;) {
77
79
  const settings = windowSettings(branch[i]);
78
80
  if (settings?.calibrationIdentity !== identity)
79
81
  continue;
80
82
  const window = settings.learnedContextWindow;
81
- return Number.isSafeInteger(window) && window > 0 ? window : undefined;
83
+ if (!(Number.isSafeInteger(window) && window > 0))
84
+ return undefined;
85
+ return catalogue !== undefined && settings.catalogueContextWindow === catalogue ? window : undefined;
82
86
  }
83
87
  return undefined;
84
88
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-tuck",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "description": "Deterministic compaction for Pi with no model call, plus exact recall of earlier history.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -46,7 +46,8 @@
46
46
  "index.ts",
47
47
  "src",
48
48
  "dist",
49
- "CHANGELOG.md"
49
+ "CHANGELOG.md",
50
+ "NOTICE"
50
51
  ],
51
52
  "scripts": {
52
53
  "check": "tsc -p tsconfig.tests.json",
package/src/build-id.ts CHANGED
@@ -1 +1 @@
1
- export const BUILD_ID = "b6a612ac60abaf5564c6020053627662851d7c7162337cf023ed686c1d598466";
1
+ export const BUILD_ID = "6a84733ab75ecf863fe77c6dd6d0a91602a8a0d353a785c3fdb34585f42637a2";
package/src/compaction.ts CHANGED
@@ -109,7 +109,9 @@ class Calibration {
109
109
  factor = 1;
110
110
  ratios: number[] = [];
111
111
  learnedContextWindow: number | undefined;
112
- windowObservation: { message: AgentMessage; identity: string; window: number } | undefined;
112
+ /** The configured window the learned window was learned under; the learned window applies only while the model still has it. */
113
+ learnedCatalogue: number | undefined;
114
+ windowObservation: { message: AgentMessage; identity: string; window: number; catalogue: number } | undefined;
113
115
  pending: { identity: string; tokens: number; messages: Parameters<typeof convertToLlm>[0]; snapshot: ReturnType<typeof convertToLlm>; requestedMaxTokens?: () => number | undefined } | undefined;
114
116
  lastCeiling: number | null = null;
115
117
  estimatedTokens = 0;
@@ -123,7 +125,7 @@ class Calibration {
123
125
  this.pending = undefined;
124
126
  if (reason !== 'identity') this.windowObservation = undefined;
125
127
  if (reason === 'session') {
126
- this.factor = 1; this.learnedContextWindow = undefined; this.estimatedTokens = 0;
128
+ this.factor = 1; this.learnedContextWindow = undefined; this.learnedCatalogue = undefined; this.estimatedTokens = 0;
127
129
  // Keep the old ratios/ceiling until their existing readers replace them, as in 1.1.1.
128
130
  this.seededIdentity = '';
129
131
  return;
@@ -133,7 +135,8 @@ class Calibration {
133
135
  const branch = ctx.sessionManager.getBranch();
134
136
  this.ratios = seedWindow(branch, this.identity);
135
137
  this.factor = Math.max(1, ...this.ratios);
136
- this.learnedContextWindow = seedContextWindow(branch, this.identity);
138
+ this.learnedCatalogue = ctx.model?.contextWindow;
139
+ this.learnedContextWindow = seedContextWindow(branch, this.identity, this.learnedCatalogue);
137
140
  }
138
141
  learn(value: number, ctx: ExtensionContext, append: (kind: string, data: unknown) => void) {
139
142
  this.ratios.push(value); if (this.ratios.length > CALIBRATION_WINDOW) this.ratios.shift(); this.factor = Math.max(1, ...this.ratios);
@@ -203,7 +206,7 @@ export async function installCompaction(pi: ExtensionAPI, options: CompactionOpt
203
206
  if (found) { recorder.capture("observed-entry", "current-native-branch-memory-not-durable", { entryId: found.id, diagnosticReceiptId: proposalId, details: found.type === "compaction" ? found.details : undefined }); recorder.cut(); proposalId = undefined; }
204
207
  });
205
208
  const captureDraft = (draft: NonNullable<ReturnType<typeof tuckDraft>["compaction"]>, ctx: ExtensionContext, reserve: number, reason: string, tokensBefore: number, retainCurrentInput: boolean, operatorManual: boolean, previousSummary?: string, budget?: { response: number; host: number; mandatory: number; target: Target; margin: number }) => recorder.measureInline(() => {
206
- const attached = attachReceipt(draft, reason, reserve, contextWindow(ctx), { responseReserveTokens: budget?.response, hostInputTokens: budget?.host, mandatoryInputTokens: budget?.mandatory, target: budget?.target, triggerMarginTokens: budget?.margin, ...(cutAt === 1 ? {} : { cutAt }), calibrationFactor: calibration.factor, calibrationWindow: [...calibration.ratios], calibrationIdentity: calibration.identity, learnedContextWindow: calibration.learnedContextWindow, activeInputCeilingTokens: calibration.lastCeiling });
209
+ const attached = attachReceipt(draft, reason, reserve, contextWindow(ctx), { responseReserveTokens: budget?.response, hostInputTokens: budget?.host, mandatoryInputTokens: budget?.mandatory, target: budget?.target, triggerMarginTokens: budget?.margin, ...(cutAt === 1 ? {} : { cutAt }), calibrationFactor: calibration.factor, calibrationWindow: [...calibration.ratios], calibrationIdentity: calibration.identity, learnedContextWindow: calibration.learnedContextWindow, ...(calibration.learnedContextWindow !== undefined && calibration.learnedCatalogue !== undefined ? { catalogueContextWindow: calibration.learnedCatalogue } : {}), activeInputCeilingTokens: calibration.lastCeiling });
207
210
  proposalId = receiptId(attached);
208
211
  if (recorder.enabled) { try {
209
212
  const filtered = permittedEntries(ctx.sessionManager.getEntries(), options.recallPolicy);
@@ -258,7 +261,9 @@ export async function installCompaction(pi: ExtensionAPI, options: CompactionOpt
258
261
  pi.on("model_select", (_event, ctx) => { calibration.select(ctx); });
259
262
  const contextWindow = (ctx: ExtensionContext) => {
260
263
  identityFor(ctx);
261
- return Math.min(ctx.model?.contextWindow ?? 0, calibration.learnedContextWindow ?? Infinity);
264
+ const model = ctx.model?.contextWindow ?? 0;
265
+ const learned = calibration.learnedCatalogue === ctx.model?.contextWindow ? calibration.learnedContextWindow : undefined;
266
+ return Math.min(model, learned ?? Infinity);
262
267
  };
263
268
  // This is the cap in Pi's built provider payload, including its context clamp and thinking adjustments.
264
269
  // An API with no explicit cap supplies no clipping evidence; never substitute the catalogue maximum.
@@ -319,9 +324,12 @@ export async function installCompaction(pi: ExtensionAPI, options: CompactionOpt
319
324
  if (message.stopReason === "length" && requested !== undefined &&
320
325
  Number.isSafeInteger(output) && output >= 0 && output < requested &&
321
326
  Number.isSafeInteger(bound) && bound > 0 && bound <= ctx.model.contextWindow) {
327
+ // A learned window from another configured window no longer bounds this one.
328
+ if (calibration.learnedCatalogue !== ctx.model.contextWindow) calibration.learnedContextWindow = undefined;
329
+ calibration.learnedCatalogue = ctx.model.contextWindow;
322
330
  calibration.learnedContextWindow = Math.min(calibration.learnedContextWindow ?? Infinity, bound);
323
331
  serverClipped.add(message);
324
- calibration.windowObservation = { message, identity: key, window: calibration.learnedContextWindow };
332
+ calibration.windowObservation = { message, identity: key, window: calibration.learnedContextWindow, catalogue: ctx.model.contextWindow };
325
333
  }
326
334
  // A request that was answered cannot have held more than the model's window, so a report above it describes something that never happened.
327
335
  // Learning from one sets the factor for the requests after it: a 60,000-token cache read reported in a 32,768-token window made a
@@ -332,7 +340,7 @@ export async function installCompaction(pi: ExtensionAPI, options: CompactionOpt
332
340
  if (standDown(ctx)) return;
333
341
  if (calibration.windowObservation?.message !== event.message) return;
334
342
  const observation = calibration.windowObservation; calibration.windowObservation = undefined;
335
- pi.appendEntry(WINDOW_RECEIPT, { calibrationIdentity: observation.identity, learnedContextWindow: observation.window,
343
+ pi.appendEntry(WINDOW_RECEIPT, { calibrationIdentity: observation.identity, learnedContextWindow: observation.window, catalogueContextWindow: observation.catalogue,
336
344
  serverClippedReplyId: event.messageEntryId } satisfies WindowReceipt);
337
345
  });
338
346
  // The operator's length-stop notice is decided at settle and is not attempt state: a run reset before then (a tree move inside another
@@ -8,7 +8,7 @@ import { createRecall, type RecallPolicy } from './recall.js';
8
8
  import type { SessionEntry } from '@earendil-works/pi-coding-agent';
9
9
  import { assertWindowsPrivateStorage, createPrivateDirectory, protectWindowsIncidentFile } from './windows-private-storage.js';
10
10
  export const DIAGNOSTIC_BUILD = BUILD_ID;
11
- export interface Receipt { id: string; build: string; reason: string; selectedView: string; boundary: string; settings: { draftReservedTokens: number; contextWindow: number; responseReserveTokens?: number; hostInputTokens?: number; mandatoryInputTokens?: number; target?: 'band' | 'room'; triggerMarginTokens?: number; cutAt?: number; calibrationFactor?: number; calibrationWindow?: number[]; calibrationIdentity?: string; learnedContextWindow?: number; activeInputCeilingTokens?: number | null }; before: { value: number; unit: 'estimated-input-tokens'; scope: 'native-preparation' | 'public-conversation' }; after: { value: number | null; unit: 'estimated-input-tokens'; scope: 'draft-preview' }; }
11
+ export interface Receipt { id: string; build: string; reason: string; selectedView: string; boundary: string; settings: { draftReservedTokens: number; contextWindow: number; responseReserveTokens?: number; hostInputTokens?: number; mandatoryInputTokens?: number; target?: 'band' | 'room'; triggerMarginTokens?: number; cutAt?: number; calibrationFactor?: number; calibrationWindow?: number[]; calibrationIdentity?: string; learnedContextWindow?: number; catalogueContextWindow?: number; activeInputCeilingTokens?: number | null }; before: { value: number; unit: 'estimated-input-tokens'; scope: 'native-preparation' | 'public-conversation' }; after: { value: number | null; unit: 'estimated-input-tokens'; scope: 'draft-preview' }; }
12
12
  export function attachReceipt<T extends { details?: unknown; firstKeptEntryId: string; tokensBefore: number }>(draft: T, reason: string, reserveTokens: number, contextWindow: number, resolved: Partial<Receipt['settings']> = {}): T & { details: Record<string, unknown> & { diagnosticReceipt: Receipt } } {
13
13
  const details = draft.details && typeof draft.details === 'object' ? draft.details as Record<string, unknown> : {};
14
14
  const receipt: Receipt = { id: randomUUID(), build: DIAGNOSTIC_BUILD, reason, selectedView: typeof details.view === 'string' ? details.view : 'deterministic-selected-draft', boundary: draft.firstKeptEntryId, settings: { draftReservedTokens: reserveTokens, contextWindow, ...resolved }, before: { value: draft.tokensBefore, unit: 'estimated-input-tokens', scope: reason === 'tool-loop' || reason === 'run-end' || reason === 'prompt' ? 'public-conversation' : 'native-preparation' }, after: { value: typeof details.tokensAfter === 'number' ? details.tokensAfter : null, unit: 'estimated-input-tokens', scope: 'draft-preview' } };
package/src/omissions.ts CHANGED
@@ -95,8 +95,10 @@ export function filterCustomQuotes(summary: string, entries: readonly SessionEnt
95
95
  return transcriptHeader(version) + '\n' + retained.join('\n') + closing;
96
96
  }
97
97
  type ProjectedMessages = ReturnType<ExtensionContext['sessionManager']['buildSessionProjection']>['messages'];
98
- /** The saved conversation as this compactor delivers it: native omissions and ineligible custom quotes removed from summaries. */
99
- function projectMessages(messages: ProjectedMessages, ctx: ExtensionContext, policy: RecallPolicy | undefined, allowForeign: boolean): ProjectedMessages {
98
+ /** The saved conversation as this compactor delivers it: native omissions and ineligible custom quotes removed from its own summaries. A
99
+ * summary of another format (Pi's own /compact before pi-tuck was loaded, an empty draft) cannot be filtered and goes out as it is, as
100
+ * native Pi sends it; the next pi-tuck cut replaces it. Failing closed on it left such a session unable to send any prompt (issue #1). */
101
+ function projectMessages(messages: ProjectedMessages, ctx: ExtensionContext, policy: RecallPolicy | undefined): ProjectedMessages {
100
102
  const entries = ctx.sessionManager.getEntries(), branch = ctx.sessionManager.getBranch();
101
103
  const omitted = omittedSourceIndices(entries, branch);
102
104
  const lastCut = branch.findLastIndex(entry => entry.type === 'compaction');
@@ -108,18 +110,14 @@ function projectMessages(messages: ProjectedMessages, ctx: ExtensionContext, pol
108
110
  const index = indices.get(entry.targetId); if (index !== undefined) afterCut.add(index);
109
111
  }
110
112
  }
111
- return messages.map(message => message.role === 'compactionSummary' && (!allowForeign || splitSummary(message.summary) !== undefined)
113
+ return messages.map(message => message.role === 'compactionSummary' && splitSummary(message.summary) !== undefined
112
114
  ? { ...message, summary: filterCustomQuotes(filterOmittedSummary(message.summary, omitted, entries,
113
115
  cut?.type === 'compaction' && cut.summary === message.summary ? afterCut : new Set()), entries, branch, policy) } : message);
114
116
  }
115
117
  export function projectedMessages(messages: ProjectedMessages, ctx: ExtensionContext, policy?: RecallPolicy): ProjectedMessages {
116
- return projectMessages(messages, ctx, policy, false);
118
+ return projectMessages(messages, ctx, policy);
117
119
  }
118
- /**
119
- * The same as `projectedMessages` for every summary in this compactor's format, and it never throws for any other: a summary of another
120
- * format (a Pi default summary, an empty draft) cannot be filtered and is left as it is. For counting a conversation that a cut is about
121
- * to replace, such as an operator's /compact on a session whose saved summary is foreign. The context hook and the triggers stay strict.
122
- */
120
+ /** The planner's name for the same projection (kept for its callers). */
123
121
  export function measurableMessages(messages: ProjectedMessages, ctx: ExtensionContext, policy?: RecallPolicy): ProjectedMessages {
124
- return projectMessages(messages, ctx, policy, true);
122
+ return projectMessages(messages, ctx, policy);
125
123
  }
@@ -63,19 +63,24 @@ export const needsFullReplyReserve = (message: AgentMessage): boolean => message
63
63
  (message.stopReason === 'length' && !thinkingOnlyLength(message) || message.stopReason === 'error' && isContextOverflow(message));
64
64
 
65
65
  /** Saved immediately at the reply's turn boundary, even when recovery cannot make a compaction. */
66
- export interface WindowReceipt { calibrationIdentity: string; learnedContextWindow: number; serverClippedReplyId: string }
66
+ /** `catalogueContextWindow` is the model's configured window when the server clipped below it. A learned window holds only while the
67
+ * configured window is unchanged: a server or catalogue that grew must not stay capped by an old clip (Nautilus, 2026-11-20). */
68
+ export interface WindowReceipt { calibrationIdentity: string; learnedContextWindow: number; catalogueContextWindow: number; serverClippedReplyId: string }
67
69
  export const WINDOW_RECEIPT = 'pi-tuck-window';
68
70
  function windowSettings(entry: SessionEntry): Partial<WindowReceipt> | undefined {
69
71
  if (entry.type === 'custom' && entry.customType === WINDOW_RECEIPT) return entry.data as Partial<WindowReceipt> | undefined;
70
72
  if (entry.type === 'compaction') return (entry.details as { diagnosticReceipt?: { settings?: Partial<WindowReceipt> } } | undefined)?.diagnosticReceipt?.settings;
71
73
  return undefined;
72
74
  }
73
- export function seedContextWindow(branch: readonly SessionEntry[], identity: string): number | undefined {
75
+ /** The newest learned window for `identity`, if it was learned under the model's current configured window. One recorded before 1.3.3
76
+ * carries no configured window and is not trusted: if the server still clips, the next clipped reply learns it again. */
77
+ export function seedContextWindow(branch: readonly SessionEntry[], identity: string, catalogue: number | undefined): number | undefined {
74
78
  for (let i = branch.length; i--;) {
75
79
  const settings = windowSettings(branch[i]!);
76
80
  if (settings?.calibrationIdentity !== identity) continue;
77
81
  const window = settings.learnedContextWindow;
78
- return Number.isSafeInteger(window) && window! > 0 ? window : undefined;
82
+ if (!(Number.isSafeInteger(window) && window! > 0)) return undefined;
83
+ return catalogue !== undefined && settings.catalogueContextWindow === catalogue ? window : undefined;
79
84
  }
80
85
  return undefined;
81
86
  }