mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-08-28 08:35:57 +00:00
feat(condense): tune default pruning policy
This commit is contained in:
@@ -3,12 +3,25 @@ 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);
|
||||
}
|
||||
|
||||
/** Enable pi-condense only when the user has not already chosen an enabled state. */
|
||||
export function ensureCondenseEnabledDefault(agentDir: string): CondenseDefaultResult {
|
||||
/** 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> = {};
|
||||
|
||||
@@ -22,9 +35,12 @@ export function ensureCondenseEnabledDefault(agentDir: string): CondenseDefaultR
|
||||
|
||||
const existing = settings.contextPrune;
|
||||
if (existing !== undefined && !isObject(existing)) return "skipped-invalid";
|
||||
if (isObject(existing) && Object.hasOwn(existing, "enabled")) return "unchanged";
|
||||
|
||||
settings.contextPrune = { ...(existing ?? {}), enabled: true };
|
||||
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");
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { getAgentDir, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
||||
import { ensureCondenseEnabledDefault } from "./condense-config.ts";
|
||||
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 = ensureCondenseEnabledDefault(getAgentDir());
|
||||
const result = ensureCondenseDefaults(getAgentDir());
|
||||
if (result === "skipped-invalid") {
|
||||
console.warn("my-pi: skipped the pi-condense default because settings.json or contextPrune is invalid");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user