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
+9 -3
View File
@@ -14,11 +14,16 @@ export class FooterComponent implements Component {
private cachedBranch: string | null | undefined = undefined; // undefined = not checked yet, null = not in git repo, string = branch name
private gitWatcher: FSWatcher | null = null;
private onBranchChange: (() => void) | null = null;
private autoCompactEnabled: boolean = true;
constructor(state: AgentState) {
this.state = state;
}
setAutoCompactEnabled(enabled: boolean): void {
this.autoCompactEnabled = enabled;
}
/**
* Set up a file watcher on .git/HEAD to detect branch changes.
* Call the provided callback when branch changes.
@@ -180,12 +185,13 @@ export class FooterComponent implements Component {
// Colorize context percentage based on usage
let contextPercentStr: string;
const autoIndicator = this.autoCompactEnabled ? " (auto)" : "";
if (contextPercentValue > 90) {
contextPercentStr = theme.fg("error", `${contextPercent}%`);
contextPercentStr = theme.fg("error", `${contextPercent}%${autoIndicator}`);
} else if (contextPercentValue > 70) {
contextPercentStr = theme.fg("warning", `${contextPercent}%`);
contextPercentStr = theme.fg("warning", `${contextPercent}%${autoIndicator}`);
} else {
contextPercentStr = `${contextPercent}%`;
contextPercentStr = `${contextPercent}%${autoIndicator}`;
}
statsParts.push(contextPercentStr);