Default complete-turn retention limit. Prefer passing the config-driven
value via run_tool_call_loop; this constant is only used when callers omit
the parameter. The name is retained for config compatibility.
Canonical breadcrumb text used for trim markers. This is the English
string that has been stable across all locales; it is the locale-
independent anchor for legacy migration. Injected breadcrumbs are always
produced via get_required_cli_string("history-trim-breadcrumb"), which
currently resolves to this same English text in every locale. Checking
the canonical value makes restore independent of the current process
locale.
Fixed per-image charge in the history estimate, applied to the images
preparation dispatches: the markers it lifts from user messages and the
attachments a tool-result carrier declares. Approximates the
standard-tier Anthropic maximum (1,568 tokens for an image
at the 1568px downscale). High-resolution tiers and some models bill more
(Anthropic high-res up to 4,784; GPT-4o-mini base 2,833; Qwen-VL ~4k per
A4 page): this is a heuristic for trimming, not a ceiling, and
provider-reported usage corrects it after the first successful response.
Estimate token count for a message history using the ~4 chars/token
heuristic plus ~4 framing tokens per message. Images are charged per
image only where preparation dispatches them: the markers lifted from
user turns and the attachments declared by the tool-result carriers of
the current user turn. Stale tool-result carriers are priced as their
bytes, and system or assistant content is priced
as text. Trim
probes estimate history suffixes that always retain the newest turn, so
the current turn’s tool-result carriers carry the same disposition in
every probe as in the full history.
Estimate the token cost of native tool definitions serialized into the
provider request, using the same ~4 chars/token heuristic as messages.
The OpenAI and compatible adapters serialize these schemas into the chat
request, so providers that include them in input_tokens report a
population of messages plus tool schemas, not messages alone.
Load interactive history plus the persisted breadcrumb provenance. Legacy
files without the flag are migrated by inspecting the restored history:
if the first non-system message equals the breadcrumb string, the flag is
recovered as true. v2 records carry an explicit
history_has_trim_breadcrumb (true or false) so a genuine user message
that collides with the breadcrumb text keeps its real turn-boundary role.
Legacy v1 migration is locale-independent: it checks the canonical
English breadcrumb plus the current-locale string, covering both the
stable historical value and any future translated variant. A v1 file whose
first user turn genuinely equals the breadcrumb text cannot be
distinguished from a synthetic marker on its one-time migration; after the
next persist the file becomes v2 with the (mis)classified flag, which is
the documented one-time limitation for unmarked legacy state.
Truncate a tool message’s content, preserving JSON structure when the
message stores tool_call_id alongside content (native tool-call
format). Without this, truncate_tool_result destroys the JSON envelope
and downstream model_providers receive a nullcall_id.