Expand description
Shake compaction — elide large tool results and code blocks from older context while preserving a recent protect window.
Ported from omp packages/agent/src/compaction/shake.ts.
Shake compaction — mechanical (LLM-free) context compression.
Walks the message log backwards to identify a recent
protect_window_tokens “tail” that
must be preserved verbatim, then elides large token-heavy regions from
everything older:
- Tool result messages whose text payload is at least
min_elidable_tokens. - Fenced code blocks (
```...```) of at least the same size, inside any message text.
Each region is replaced with a compact placeholder. If the total
recovered tokens meet min_savings_tokens,
every region is elided in a single pass and the function reports
ShakeOutcome::Shaken. Otherwise no message is mutated and the
function reports ShakeOutcome::NoChange — callers can poll the same
vector repeatedly without side effects.
Ported from omp packages/agent/src/compaction/shake.ts (mechanical,
regex-free analogue). Token counts use the chars / 4 heuristic that
the rest of the agent loop already uses for cold-start estimation.
Structs§
- Shake
Config - Tunable thresholds for
shake.
Enums§
- Shake
Outcome - Result of a single
shakecall.
Functions§
- shake
- Shake the message log: elide large tool results and code blocks from
the older portion of
messages, leaving the recentprotect_window_tokensintact.