Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion extensions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
37 changes: 37 additions & 0 deletions test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
Expand Down
Loading