Context compaction: commands, auto-trigger, RPC support, /branch rework (fixes #92)

- Add compaction settings to Settings interface
- /compact [instructions]: manual compaction with optional focus
- /autocompact: toggle auto-compaction on/off
- Auto-compaction triggers after assistant message_end when threshold exceeded
- Footer shows (auto) when auto-compact is enabled
- RPC mode: {type: 'compact'} command emits CompactionEntry
- /branch now reads from session file to show ALL historical user messages
- createBranchedSessionFromEntries preserves compaction events
This commit is contained in:
Mario Zechner 2025-12-04 00:25:53 +01:00
parent 6c2360af28
commit 79731249eb
5 changed files with 375 additions and 30 deletions

View file

@ -2,6 +2,12 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
import { dirname, join } from "path";
import { getAgentDir } from "./config.js";
export interface CompactionSettings {
enabled?: boolean; // default: true
reserveTokens?: number; // default: 16384
keepRecentTokens?: number; // default: 20000
}
export interface Settings {
lastChangelogVersion?: string;
defaultProvider?: string;
@ -9,6 +15,7 @@ export interface Settings {
defaultThinkingLevel?: "off" | "minimal" | "low" | "medium" | "high";
queueMode?: "all" | "one-at-a-time";
theme?: string;
compaction?: CompactionSettings;
}
export class SettingsManager {
@ -108,4 +115,32 @@ export class SettingsManager {
this.settings.defaultThinkingLevel = level;
this.save();
}
getCompactionEnabled(): boolean {
return this.settings.compaction?.enabled ?? true;
}
setCompactionEnabled(enabled: boolean): void {
if (!this.settings.compaction) {
this.settings.compaction = {};
}
this.settings.compaction.enabled = enabled;
this.save();
}
getCompactionReserveTokens(): number {
return this.settings.compaction?.reserveTokens ?? 16384;
}
getCompactionKeepRecentTokens(): number {
return this.settings.compaction?.keepRecentTokens ?? 20000;
}
getCompactionSettings(): { enabled: boolean; reserveTokens: number; keepRecentTokens: number } {
return {
enabled: this.getCompactionEnabled(),
reserveTokens: this.getCompactionReserveTokens(),
keepRecentTokens: this.getCompactionKeepRecentTokens(),
};
}
}