22. Compact Subsystem
Why Compacting Is a Whole Subsystem
The files under services/compact/ show that context shrinking is not one function call. There are separate pieces for microcompact,
auto-compact thresholds, prompt templates, warning state, cleanup, grouping, and session-memory-aware compacting.
What microCompact.ts Reveals
Microcompact is selective. It targets specific tool outputs, estimates token pressure, manages cache edits, and keeps compacting state consistent with prompt-cache behavior. That means the goal is not only to save tokens, but to do so without wrecking cache efficiency or losing critical context.
What autoCompact.ts Reveals
Auto-compact is guarded by context-window math, feature interactions, recursion guards, and circuit-breaker logic. The system explicitly avoids compacting inside compact-related flows and certain specialized modes. This is context management as operational control flow.
Main Lesson
Source Navigation
Recommended Source Files
source/services/compact/compact.tssource/services/compact/autoCompact.tssource/services/compact/microCompact.tssource/services/compact/prompt.tssource/services/compact/sessionMemoryCompact.ts
Next Files to Read
source/services/compact/postCompactCleanup.tssource/services/api/promptCacheBreakDetection.tssource/services/SessionMemory/sessionMemory.ts