feat(pi-condense): vendor source and add summarizer retries

This commit is contained in:
云服务部-叶林立
2026-08-31 15:13:41 +08:00
parent 8002d7c213
commit e80959cc3f
94 changed files with 21327 additions and 185 deletions
-98
View File
@@ -1,98 +0,0 @@
import assert from "node:assert/strict";
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
import { ensureCondenseDefaults } from "../extensions/condense-config.ts";
const EXPECTED_DEFAULTS = {
enabled: true,
pruneOn: "agent-message",
batchingMode: "turn",
autoBudgetThreshold: 0.735,
budgetTurnDelta: 0.04,
summarizerModel: "default",
summarizerThinking: "default",
summarizerIdleTimeoutMs: 90_000,
summarizerMaxTimeoutMs: 300_000,
quietOversizedSkips: false,
};
async function withAgentDir(run: (agentDir: string) => Promise<void>): Promise<void> {
const agentDir = await mkdtemp(join(tmpdir(), "my-pi-condense-"));
try {
await run(agentDir);
} finally {
await rm(agentDir, { recursive: true, force: true });
}
}
test("pi-condense writes the complete bundle defaults when contextPrune is absent", async () => {
await withAgentDir(async (agentDir) => {
assert.equal(ensureCondenseDefaults(agentDir), "updated");
assert.deepEqual(JSON.parse(await readFile(join(agentDir, "settings.json"), "utf8")), {
contextPrune: EXPECTED_DEFAULTS,
});
});
});
test("pi-condense fills only missing defaults and preserves unrelated settings", async () => {
await withAgentDir(async (agentDir) => {
const path = join(agentDir, "settings.json");
await writeFile(
path,
JSON.stringify({ theme: "dark", contextPrune: { minBatchChars: 4000, budgetTurnDelta: 0.03 } }),
"utf8",
);
assert.equal(ensureCondenseDefaults(agentDir), "updated");
assert.deepEqual(JSON.parse(await readFile(path, "utf8")), {
theme: "dark",
contextPrune: { ...EXPECTED_DEFAULTS, minBatchChars: 4000, budgetTurnDelta: 0.03 },
});
});
});
test("pi-condense preserves an explicit disabled choice while filling other defaults", async () => {
await withAgentDir(async (agentDir) => {
const path = join(agentDir, "settings.json");
await writeFile(path, JSON.stringify({ contextPrune: { enabled: false } }), "utf8");
assert.equal(ensureCondenseDefaults(agentDir), "updated");
assert.deepEqual(JSON.parse(await readFile(path, "utf8")), {
contextPrune: { ...EXPECTED_DEFAULTS, enabled: false },
});
});
});
test("pi-condense does not rewrite a complete explicit configuration", async () => {
await withAgentDir(async (agentDir) => {
const path = join(agentDir, "settings.json");
const original = `${JSON.stringify(
{ contextPrune: { ...EXPECTED_DEFAULTS, enabled: false, quietOversizedSkips: true } },
null,
2,
)}\n`;
await writeFile(path, original, "utf8");
assert.equal(ensureCondenseDefaults(agentDir), "unchanged");
assert.equal(await readFile(path, "utf8"), original);
});
});
test("pi-condense defaults do not overwrite malformed settings", async () => {
await withAgentDir(async (agentDir) => {
const path = join(agentDir, "settings.json");
await writeFile(path, "{not-json", "utf8");
assert.equal(ensureCondenseDefaults(agentDir), "skipped-invalid");
assert.equal(await readFile(path, "utf8"), "{not-json");
});
});
test("pi-condense defaults reject a non-object contextPrune value", async () => {
await withAgentDir(async (agentDir) => {
const path = join(agentDir, "settings.json");
const original = `${JSON.stringify({ contextPrune: false }, null, 2)}\n`;
await writeFile(path, original, "utf8");
assert.equal(ensureCondenseDefaults(agentDir), "skipped-invalid");
assert.equal(await readFile(path, "utf8"), original);
});
});
+11
View File
@@ -46,6 +46,17 @@ test("all package extensions load together without global registration conflicts
packageJson.pi.extensions.includes("./pi-extension-codex-fast-mode/index.ts"),
"the bundle must load the locally maintained Codex Fast mode extension",
);
assert.equal(packageJson.dependencies["pi-condense"], "file:./pi-condense");
assert.ok(packageJson.files.includes("pi-condense"), "the packed bundle must include maintained pi-condense source");
assert.ok(
packageJson.pi.extensions.includes("./pi-condense/index.ts"),
"the bundle must load maintained pi-condense directly",
);
assert.equal(
packageJson.pi.extensions.includes("./extensions/condense.ts"),
false,
"the removed config-injection wrapper must not be loaded in parallel",
);
assert.ok(packageJson.pi.extensions.includes("./pi-ssh/index.ts"), "the bundle must load the locally maintained SSH extension");
assert.equal(packageJson.dependencies["pi-ssh"], "file:./pi-ssh");
assert.equal(packageJson.dependencies.ssh2, "1.17.0", "the packed bundle must install pi-ssh's runtime transport");