feat(compaction): add proactive context budget and checkpointing

This commit is contained in:
William Valentin
2026-02-16 15:44:00 -08:00
parent 65efda3533
commit 8758ea8f1c
7 changed files with 478 additions and 1 deletions
+25
View File
@@ -15,6 +15,23 @@ export interface CompactionConfig {
summaryMaxTokens: number;
/** Preserve messages at or above this importance score from compaction. */
importanceThreshold: number;
/** Optional proactive context usage thresholds and actions. */
proactive?: ProactiveCompactionConfig;
}
export interface ProactiveCompactionConfig {
/** Enable proactive context warnings/checkpoints before hard compaction cliffs. */
enabled: boolean;
/** Emit warning signals when usage crosses this percentage. */
warnPct: number;
/** Save a checkpoint summary to memory when usage crosses this percentage. */
checkpointPct: number;
/** Auto-run compaction when usage crosses this percentage. */
autoCompactPct: number;
/** Cooldown window between checkpoint writes. */
checkpointCooldownMs: number;
/** Memory namespace base for proactive checkpoints. */
memoryNamespace: string;
}
export interface CompactionResult {
@@ -33,6 +50,14 @@ export const DEFAULT_COMPACTION_CONFIG: CompactionConfig = {
keepTurns: 4,
summaryMaxTokens: 1024,
importanceThreshold: 1,
proactive: {
enabled: false,
warnPct: 75,
checkpointPct: 85,
autoCompactPct: 95,
checkpointCooldownMs: 300_000,
memoryNamespace: 'session/checkpoints',
},
};
export async function compactHistory(opts: {