Expand description
Compaction range selection with tool-pair invariant (W4.1).
Maturity: core
A split index must never land inside an assistant tool-call run followed by its tool results. Snapping moves the split past any orphaned tool messages.
Structs§
- Compaction
Range - Plan for compacting
messages[0..split_idx]and keeping the tail.
Functions§
- apply_
range - Apply a range: drop prefix, keep tail; optionally insert a summary as the first post-system message.
- is_
safe_ split - Whether
split_idxis a safe boundary (not mid tool-result run). - select_
compaction_ range - Choose a split that keeps at most
keep_tailmessages from the end, after preserving a leading system message, then snap for tool-pair safety. - snap_
split_ forward - Snap
split_idxforward until the kept prefix no longer ends mid tool-run and the tail does not begin on aToolrole. - tool_
pair_ invariant_ holds - Invariant check for tests / fuzz: no kept Tool without a prior assistant tool-call message still in the list (or system/user only prefix is ok if no tools).