From cf6101012b712848d2c4d16b8fc8847ad236a103 Mon Sep 17 00:00:00 2001 From: HugoLopes45 Date: Wed, 11 Nov 2026 14:52:28 +0100 Subject: [PATCH 1/2] Shake after handoff only when pruning is not enough turn_end checked Pi's raw token count, not the planned result, before shaking after a handoff. When pruning alone reached the target, the default methodOrder still elided old code blocks and broke the cache once more. The README said old file reads are still replaced with Pi's compaction off. Since edits happen only at the threshold, nothing changes then; the README now says so. Install dependencies without lifecycle scripts in CI and release: the release job can request an npm publish token, and no dependency needs its install script for the checks. --- .github/workflows/ci.yml | 6 +++--- .github/workflows/release.yml | 2 +- README.md | 4 ++-- extensions/index.ts | 2 +- test/extension.test.ts | 37 +++++++++++++++++++++++++++++++++++ 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ad1aae..2ad6080 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,20 +37,20 @@ jobs: with: node-version: ${{ matrix.node }} cache: npm - - run: npm ci + - run: npm ci --ignore-scripts - run: npm run check # Pi's packages depend on each other with caret ranges, so each one is pinned to match a real install. - name: Check oldest supported Pi if: matrix.node == 24 run: | read -ra packages <<< "$PI_PACKAGES" - npm install --no-save --package-lock=false "${packages[@]/%/@1.0.3}" + npm install --ignore-scripts --no-save --package-lock=false "${packages[@]/%/@1.0.3}" npm run check - name: Check latest Pi if: matrix.node == 24 run: | read -ra packages <<< "$PI_PACKAGES" - npm install --no-save --package-lock=false "${packages[@]/%/@latest}" + npm install --ignore-scripts --no-save --package-lock=false "${packages[@]/%/@latest}" npm run check workflow-security: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cd811ae..48ec6d0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -50,7 +50,7 @@ jobs: env: GH_TOKEN: ${{ github.token }} TAG: ${{ github.event.release.tag_name }} - - run: npm ci + - run: npm ci --ignore-scripts - name: Publish to npm run: | npm version "${TAG#v}" --no-git-tag-version --allow-same-version diff --git a/README.md b/README.md index e654c44..57f1d4b 100644 --- a/README.md +++ b/README.md @@ -450,7 +450,7 @@ These settings belong to Pi, not to pi-context-kit. Put them in the `compaction` | Pi setting | Default | Effect on pi-context-kit | | --- | --- | --- | -| `compaction.enabled` | `true` | `false` stops Pi's compaction. Then pi-context-kit only replaces old file reads. | +| `compaction.enabled` | `true` | `false` stops Pi's compaction. Then pi-context-kit changes nothing, because there is no threshold. | | `compaction.reserveTokens` | `16384` | Pi's limit is the context window minus this number. pi-context-kit always starts at this limit or before. | | `compaction.keepRecentTokens` | `20000` | After a handoff note, approximately this number of the newest tokens stays unchanged. | | `compaction.modelOverrides` | none | Changes `reserveTokens` and `keepRecentTokens` for one model. | @@ -506,7 +506,7 @@ To combine recipes, put all the settings in one `contextKit` block: - **Pi still has its own limit.** Pi compacts when the context reaches the context window minus `compaction.reserveTokens` (default 16,384). pi-context-kit can only start earlier, not later. You set Pi's limit with `compaction.reserveTokens` and `compaction.modelOverrides`. - **A threshold is not a guarantee.** At the threshold, pi-context-kit tries to make the context smaller. If one tool output is very large, or the summary request fails, the methods can fail. Then Pi compacts at its own limit. - **Token counts are estimates.** pi-context-kit uses Pi's estimates. The real count of the provider can be different. -- **If Pi's compaction is off** (`compaction.enabled: false`), pi-context-kit only replaces old file reads. +- **If Pi's compaction is off** (`compaction.enabled: false`), pi-context-kit changes nothing. `thresholdTokens` and `thresholdPercent` are ignored, because pi-context-kit edits the context only at a threshold. - **Manual compaction and errors.** When you type `/compact`, when the context is too large for the model, or when Pi compacts before a turn, `shake` cannot run. pi-context-kit uses a ready handoff note, or Pi's summary. - **`methodOrder` stops at `soft`.** The methods after `soft` do not run. - **Subagents** use their own settings. They show no warnings, because they have no screen. diff --git a/extensions/index.ts b/extensions/index.ts index 3b5818f..6eb8593 100644 --- a/extensions/index.ts +++ b/extensions/index.ts @@ -317,7 +317,7 @@ export default function contextKit(pi: ExtensionAPI): void { } } const shakeAfterHandoff = !shakeFirst && before(methods, "shake", "soft"); - if (tokens > limit && shakeAfterHandoff) result = plan(true); + if (result.tokens > limit && shakeAfterHandoff) result = plan(true); const softDue = model && result.tokens > limit && diff --git a/test/extension.test.ts b/test/extension.test.ts index ff924e6..9265a57 100644 --- a/test/extension.test.ts +++ b/test/extension.test.ts @@ -803,6 +803,43 @@ describe("pi-context-kit inside Pi", () => { ).toBe(true); }); + it("does not shake when pruning alone brings the context under the threshold", async () => { + const { session } = await start( + [ + fauxAssistantMessage([ + { + type: "text", + text: ["```ts", "x = 1;".repeat(2_800), "```"].join("\n"), + }, + fauxToolCall("read", { path: "b.ts" }), + ]), + fauxAssistantMessage("done"), + ], + 200_000, + true, + { + thresholdTokens: 8_000, + asyncEnabled: false, + prune: { protectTokens: 0, minSavings: 1, minTokens: 50 }, + shake: { protectTokens: 0, minSavings: 1, blockMinTokens: 10 }, + }, + ); + await session.prompt("Read b.ts"); + const replacements = session.sessionManager + .getBranch() + .flatMap((entry) => + entry.type === "context_edit" + ? [JSON.stringify(entry.replacement)] + : [], + ); + expect(replacements.some((text) => text.includes("Output pruned"))).toBe( + true, + ); + expect(replacements.some((text) => text.includes("Elided block"))).toBe( + false, + ); + }); + it("does not shake before soft when methodOrder puts soft first", async () => { const { session } = await start( [ From 626d211ba90377f4a2bf209d8b77eb7cfa957f10 Mon Sep 17 00:00:00 2001 From: HugoLopes45 Date: Wed, 11 Nov 2026 14:58:50 +0100 Subject: [PATCH 2/2] Say that /compact still writes a handoff note with compaction off --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 57f1d4b..9d0ac3e 100644 --- a/README.md +++ b/README.md @@ -450,7 +450,7 @@ These settings belong to Pi, not to pi-context-kit. Put them in the `compaction` | Pi setting | Default | Effect on pi-context-kit | | --- | --- | --- | -| `compaction.enabled` | `true` | `false` stops Pi's compaction. Then pi-context-kit changes nothing, because there is no threshold. | +| `compaction.enabled` | `true` | `false` stops Pi's automatic compaction. Then pi-context-kit changes the context only on `/compact`, because there is no threshold. | | `compaction.reserveTokens` | `16384` | Pi's limit is the context window minus this number. pi-context-kit always starts at this limit or before. | | `compaction.keepRecentTokens` | `20000` | After a handoff note, approximately this number of the newest tokens stays unchanged. | | `compaction.modelOverrides` | none | Changes `reserveTokens` and `keepRecentTokens` for one model. | @@ -506,7 +506,7 @@ To combine recipes, put all the settings in one `contextKit` block: - **Pi still has its own limit.** Pi compacts when the context reaches the context window minus `compaction.reserveTokens` (default 16,384). pi-context-kit can only start earlier, not later. You set Pi's limit with `compaction.reserveTokens` and `compaction.modelOverrides`. - **A threshold is not a guarantee.** At the threshold, pi-context-kit tries to make the context smaller. If one tool output is very large, or the summary request fails, the methods can fail. Then Pi compacts at its own limit. - **Token counts are estimates.** pi-context-kit uses Pi's estimates. The real count of the provider can be different. -- **If Pi's compaction is off** (`compaction.enabled: false`), pi-context-kit changes nothing. `thresholdTokens` and `thresholdPercent` are ignored, because pi-context-kit edits the context only at a threshold. +- **If Pi's compaction is off** (`compaction.enabled: false`), pi-context-kit changes the context only when you run `/compact`. Then it writes a handoff note, as with compaction on. `thresholdTokens` and `thresholdPercent` are ignored, because pi-context-kit edits the context automatically only at a threshold. - **Manual compaction and errors.** When you type `/compact`, when the context is too large for the model, or when Pi compacts before a turn, `shake` cannot run. pi-context-kit uses a ready handoff note, or Pi's summary. - **`methodOrder` stops at `soft`.** The methods after `soft` do not run. - **Subagents** use their own settings. They show no warnings, because they have no screen.