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..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 only replaces old file reads. | +| `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 only replaces old file reads. +- **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. 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( [