feat: enable adaptive context pruning by default

This commit is contained in:
Peter Steinberger
2026-01-08 22:23:03 +01:00
parent d58cdf7c9f
commit 2c7d64232e
7 changed files with 103 additions and 14 deletions

View File

@@ -269,7 +269,7 @@ describe("config identity defaults", () => {
});
});
it("does not synthesize agent/session when absent", async () => {
it("does not synthesize session when absent", async () => {
await withTempHome(async (home) => {
const configDir = path.join(home, ".clawdbot");
await fs.mkdir(configDir, { recursive: true });
@@ -295,7 +295,7 @@ describe("config identity defaults", () => {
expect(cfg.routing?.groupChat?.mentionPatterns).toEqual([
"\\b@?Samantha\\b",
]);
expect(cfg.agent).toBeUndefined();
expect(cfg.agent?.contextPruning?.mode).toBe("adaptive");
expect(cfg.session).toBeUndefined();
});
});
@@ -327,6 +327,48 @@ describe("config identity defaults", () => {
});
});
describe("config pruning defaults", () => {
it("defaults contextPruning mode to adaptive", async () => {
await withTempHome(async (home) => {
const configDir = path.join(home, ".clawdbot");
await fs.mkdir(configDir, { recursive: true });
await fs.writeFile(
path.join(configDir, "clawdbot.json"),
JSON.stringify({ agent: {} }, null, 2),
"utf-8",
);
vi.resetModules();
const { loadConfig } = await import("./config.js");
const cfg = loadConfig();
expect(cfg.agent?.contextPruning?.mode).toBe("adaptive");
});
});
it("does not override explicit contextPruning mode", async () => {
await withTempHome(async (home) => {
const configDir = path.join(home, ".clawdbot");
await fs.mkdir(configDir, { recursive: true });
await fs.writeFile(
path.join(configDir, "clawdbot.json"),
JSON.stringify(
{ agent: { contextPruning: { mode: "off" } } },
null,
2,
),
"utf-8",
);
vi.resetModules();
const { loadConfig } = await import("./config.js");
const cfg = loadConfig();
expect(cfg.agent?.contextPruning?.mode).toBe("off");
});
});
});
describe("config discord", () => {
let previousHome: string | undefined;

View File

@@ -161,6 +161,25 @@ export function applyLoggingDefaults(cfg: ClawdbotConfig): ClawdbotConfig {
};
}
export function applyContextPruningDefaults(
cfg: ClawdbotConfig,
): ClawdbotConfig {
const agent = cfg.agent;
const contextPruning = agent?.contextPruning;
if (contextPruning?.mode) return cfg;
return {
...cfg,
agent: {
...agent,
contextPruning: {
...contextPruning,
mode: "adaptive",
},
},
};
}
export function resetSessionDefaultsWarningForTests() {
defaultWarnState = { warned: false };
}

View File

@@ -17,6 +17,7 @@ import {
applyLoggingDefaults,
applyMessageDefaults,
applyModelDefaults,
applyContextPruningDefaults,
applySessionDefaults,
applyTalkApiKey,
} from "./defaults.js";
@@ -135,10 +136,12 @@ export function createConfigIO(overrides: ConfigIoDeps = {}) {
return {};
}
const cfg = applyModelDefaults(
applySessionDefaults(
applyLoggingDefaults(
applyMessageDefaults(
applyIdentityDefaults(validated.data as ClawdbotConfig),
applyContextPruningDefaults(
applySessionDefaults(
applyLoggingDefaults(
applyMessageDefaults(
applyIdentityDefaults(validated.data as ClawdbotConfig),
),
),
),
),
@@ -182,7 +185,11 @@ export function createConfigIO(overrides: ConfigIoDeps = {}) {
const exists = deps.fs.existsSync(configPath);
if (!exists) {
const config = applyTalkApiKey(
applyModelDefaults(applySessionDefaults(applyMessageDefaults({}))),
applyModelDefaults(
applyContextPruningDefaults(
applySessionDefaults(applyMessageDefaults({})),
),
),
);
const legacyIssues: LegacyConfigIssue[] = [];
return {