Skip to main content

Module shake

Module shake 

Source
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:

  1. Tool result messages whose text payload is at least min_elidable_tokens.
  2. 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§

ShakeConfig
Tunable thresholds for shake.

Enums§

ShakeOutcome
Result of a single shake call.

Functions§

shake
Shake the message log: elide large tool results and code blocks from the older portion of messages, leaving the recent protect_window_tokens intact.