Functions
estimate-tokens
fn (text: Str): Int
Rough token estimate (~4 chars per token). Good enough for budget checks.
fit
fn (items: Vec, opts: Map): Vec
Drop items from the middle of a Vec until total tokens are under budget. Options: max-tokens, field.
fit-with-sample
fn (items: Vec, max-tokens: Int, item-text: Fn, size: Int): Vec
sample
fn (items: Vec, opts: Map): Vec
Sample a Vec down to max-items. Options: max-items (count), strategy (bookend/recent/even). Returns input unchanged if it fits.
sample-bookend
fn (items: Vec, max-items: Int): Vec
sample-even
fn (items: Vec, max-items: Int): Vec
truncate
fn (text: Str, max-chars: Int, suffix: Str?): Str
Truncate text to a character limit. Appends suffix if truncated.