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
-49
View File
@@ -1,49 +0,0 @@
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
export type CondenseDefaultResult = "updated" | "unchanged" | "skipped-invalid";
const CONDENSE_BUNDLE_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,
} as const;
function isObject(value: unknown): value is Record<string, unknown> {
return value !== null && typeof value === "object" && !Array.isArray(value);
}
/** Fill missing pi-condense settings with bundle defaults while preserving every explicit user choice. */
export function ensureCondenseDefaults(agentDir: string): CondenseDefaultResult {
const targetPath = join(agentDir, "settings.json");
let settings: Record<string, unknown> = {};
try {
const parsed: unknown = JSON.parse(readFileSync(targetPath, "utf8"));
if (!isObject(parsed)) return "skipped-invalid";
settings = parsed;
} catch (error) {
if ((error as NodeJS.ErrnoException).code !== "ENOENT") return "skipped-invalid";
}
const existing = settings.contextPrune;
if (existing !== undefined && !isObject(existing)) return "skipped-invalid";
const contextPrune = existing ?? {};
const alreadyComplete = Object.keys(CONDENSE_BUNDLE_DEFAULTS).every((key) => Object.hasOwn(contextPrune, key));
if (alreadyComplete) return "unchanged";
settings.contextPrune = { ...CONDENSE_BUNDLE_DEFAULTS, ...contextPrune };
mkdirSync(dirname(targetPath), { recursive: true });
const temporaryPath = `${targetPath}.my-pi.tmp`;
writeFileSync(temporaryPath, `${JSON.stringify(settings, null, 2)}\n`, "utf8");
renameSync(temporaryPath, targetPath);
return "updated";
}
-12
View File
@@ -1,12 +0,0 @@
import { getAgentDir, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
import { ensureCondenseDefaults } from "./condense-config.ts";
/** Apply the bundle default before pi-condense reads settings on session_start. */
export default async function bundledCondenseExtension(pi: ExtensionAPI): Promise<void> {
const result = ensureCondenseDefaults(getAgentDir());
if (result === "skipped-invalid") {
console.warn("my-pi: skipped the pi-condense default because settings.json or contextPrune is invalid");
}
const { default: condenseExtension } = await import("../node_modules/pi-condense/index.ts");
condenseExtension(pi);
}