pub fn split_on_budget(transcript: &str, max_chars: usize) -> Vec<&str>Expand description
Splits transcript into chunks that each fit within max_chars.
Packing is line-aware: each chunk is filled with whole lines (a
transcript is one line per turn) up to max_chars, so a chunk only ever
cuts between turns, never mid-turn. A single line longer than
max_chars on its own is hard-split on char boundaries into one or
more chunks — this function is a strict size guarantee, not a hint, so
even a pathologically long line cannot produce an over-budget chunk.
max_chars == 0 has no valid split (every chunk would have to be
empty), so it clamps to a single chunk containing the whole
transcript — the same behavior the crate had before chunking existed.
Debug builds panic via debug_assert_ne! so a misconfigured budget is
caught during development; release builds degrade silently, matching
cap_distilled_memory’s convention of never panicking on
untrusted/misconfigured input.
An empty transcript returns an empty Vec (zero chunks).
This is a pure, zero-copy split: the returned slices borrow from
transcript, and concatenating them in order reproduces transcript
exactly — no data is dropped, added, or copied.