fn compact_counters(frames: &mut Vec<Value>)Expand description
Fold each run of consecutive thinking-token counters in a turn into the one frame it draws as.
The fold reads a counter for two things only, its growth and its stamp,
and draws no row for it - so a turn that thinks for an hour is thousands of
frames that all say the same running figure. One frame per run carries it
exactly: the summed estimated_tokens_delta, the newest frame’s own id and
stamp, and the stamps the run covers (folded_from through its own
timestamp) with folded_frames saying how many the one stands for. The
live stream already serves a flush’s run this way (batch::merge); this
is that shape at the page’s own cut.
The range is what a landing reads, not a single instant. A page can open on a turn’s SUFFIX - the held window’s front cuts inside a running turn when no turn opener sits above the line - so a client holding the counters above the page’s first one must keep them, and a run that recorded only where it ends would drop them.
A run that may start mid-turn is never folded. When a turn’s first carried frame is itself a counter, the window’s front cut inside that running turn, and the run’s true start is not in the page - so its leading counters are served as themselves. Every fold a page carries therefore starts at the first counter after a frame that is no counter, which is a boundary any earlier page of the same run shares; a later page’s fold then nests inside or around an earlier one instead of crossing it.
A run is one dispatch’s, and the dispatch lives in the frame’s extras
rather than in its typed fields. No captured baseline carries
parent_tool_use_id on a counter, so the grouping is a guard rather than a
live path: if the CLI ever stamps one, a sub-agent’s counters are the
subagents surface’s and the chat fold skips them whole, and folding them
into the parent’s run would move its figure and its clock. A folded run
is stamped throughout: a frame with no stamp breaks the run rather than
being folded under a bound it cannot be placed by.
It runs after the page is cut, so the budget still counts the bytes a page used to carry and keeps the same turns it always did.