pub fn render_tool_output(v: &Value) -> StringExpand description
A tool result’s output as a model should read it: outcome fields first
(truncated, error, ok, status, exit_code, timed_out), one line
each; then other scalars as key: value lines; then each long or
multi-line string (a file’s content, a command’s output) as a raw block
headed key (N bytes):, and each array of records as key (N records):
with one line per record. A cut at the budget loses the tail of the bulk,
never the verdict.
Journals, receipts and events keep the JSON; only the model’s copy changes.
The model used to be handed the JSON too — so a file arrived as one line of
\n, \t and \" escapes. On claude-haiku-4-5, 23% of native edit_file
calls (42 of 182) missed with “old_text not found”, against 1 of 60 for
Claude Code’s Edit on the same model and tasks; the misses carried escapes
copied out of the JSON (\"\"\" for a docstring’s """). Claude Code’s
Read returns plain numbered lines; this is that shape.
The text reads back exactly with parse_rendered_output, apart from the
outcome fields (shown on one line) and a record list (read back as text):
blocks carry their length, so no content line can be mistaken for a field,
and a string that would read back as another JSON type ("123", "null")
is written quoted.