Skip to main content

Module select

Module select 

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

CompactionRange
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_idx is a safe boundary (not mid tool-result run).
select_compaction_range
Choose a split that keeps at most keep_tail messages from the end, after preserving a leading system message, then snap for tool-pair safety.
snap_split_forward
Snap split_idx forward until the kept prefix no longer ends mid tool-run and the tail does not begin on a Tool role.
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).