pickCut
function pickCut(messages, budget): number;Defined in: core/src/context.ts:108
Where to cut so the messages AFTER the cut fit budget, walking backwards
from the newest.
Two invariants the cut must respect, and both are correctness rather than taste:
- Never split a tool call from its result. Every provider rejects a tool result whose call is missing, so a cut landing between them produces a 400 on the very next turn, the failure compaction was called to avoid.
- Never cut into the system prompt. It is not history.
Returns the index the kept tail starts at, or 0 when everything already fits.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
messages |
readonly ChatMessage[] |
budget |
number |
Returns
Section titled “Returns”number