Repository navigation
Write JSON into a model's context as a fenced block, indented one space - #6497
Merged
Merged
Conversation
Max, reading the messages Leaf sends a Claude Code fork, found the working fork's task embedding the thread's delivery as one line of JSON several thousand characters long, and asked for it in a code block with modest pretty-printing, and for that principle wherever Leaf's agent instructions carry structured data. `leaf.json_block` is now the one home for that rendering: `json_block(value)` writes a fenced `json` block with `json.dumps(..., ensure_ascii=False, indent=1)`, and `read_json_block(text)` reads one back with the lines after its closing fence. Every caller moves onto it: - the inline delivery a hook hands the main thread and an agent at a tool boundary (`hook_transport`), after `INLINE_OPENING`; - Codex's hook context (`codex.offer_hook_delivery`), which was compact one-line JSON; - the working and resumed fork's task (`forks.work_prompt`, `resume_prompt`) and the thread the line and summary forks read (`forks.thread_json`, which was indented but unfenced); - the answer schema a model without one is told in its system prompt (`inference.answering`), for Claude Code's Haiku completions and Pi. `hook_transport.inline_delivery` reads the block after the opening line instead of the one line after it, so `harness.claude_code_entered` (which scans transcripts for the opening and parses each attachment), the journey and `leaf-dev logs timeline` keep finding deliveries; the timeline reads the clerk's lines after the closing fence. Tests read hook contexts through `inline_delivery` (`interact_support.inlined`) or `read_json_block` rather than splitting on newlines, and the check that holds pasted eval envelopes to `DELIVERY` reads a pasted block as well as a pasted line. Left as they were: a value inside a sentence (a running call's arguments in the line fork's prompt, a finding's value); the answer templates the clerk and forks spell out inline; Codex's `leaf_delivery` tool output, which is the delivery alone; and every command's output, record and wire message, which programs read. Size: over the 603 deliveries stored in the last three days, the Claude Code hook context grows 13% (4–36% each) and 12 of 574 that fit under 9,990 bytes no longer do and go by pointer; Codex's, from compact JSON, grows 17% (5–48%) and 11 of 575 cross its 10,000. `fits_hook_context` is checked on the rendered text, so nothing else changes there. Evals, on Claude Code (passes out of trials, $10 in all): - line-fork, 9 cases, merge base against this change: 28/28 and 28/28, with the same take or hand_over on every trial of every case. - summary-fork, 2 cases: 6/6 and 6/6. - claude-hook-delivery-needs-no-ack, which pastes a hook's envelope and now pastes it as the hook writes it: one-line 5/5, block 5/5 (both forms run on this change, since the envelope is the case's text). - answer-quotes-what-it-cites, a 3,300-character delivery, the same way: one-line 11/11, block 10/11; the miss linked its own passage, the failure the case was written to catch. Told the title schema as a block, Haiku still answered with bare JSON that `inference.answered` takes on 36/36 title and widget-style requests, as it did with the one-line schema (36/36). Pi's model was not measured. turn-end-check and recovery-leaves-a-forks-answer weren't run: neither prompt changes, so both arms would read the same text.
Ten eval cases pasted a delivery under "Leaf's prompt hook handed you this complete delivery" as one line of JSON, which a hook no longer writes. Each now pastes it as `json_block` renders it. The two pastes in answer-hands-back-the-next-move that stand for Codex's App Server stay on one line, since its `leaf_delivery` tool output is still the compact value. The two cases whose prompts were quoted YAML scalars now hold them as block scalars, with the same text apart from the envelope. Each case run once on Claude Code with the block form: 10/10 passed (about $5).
leaf-agent
approved these changes
Nov 19, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 19, 2026
…Forks topic (#6489) How it works' Forks topic gains "Anatomy of a fork journey". It follows one thread through every message Leaf, Claude Code and the forks exchanged in a recorded run of the Claude Code agent journey (18 Nov, Claude Code 2.1.328). The section has a timeline with a lane for each of the user, Leaf, the line fork, the working fork and the main thread, followed by each message in order. A coloured rule and tint on each message say who wrote it: Claude Code, Leaf, a model or the user. Leaf's own messages are written from the current code with the run's recorded batches (`dev/leaf_dev/fork-journey.json`), so they stay current. The current code reproduces the run's three deliveries and its line prompt exactly. Only the timings, Claude Code's text and the models' answers are as recorded. The line, work and resume prompt slots moved into the section, so each prompt shows once. The take's sequence diagram stays. Two strings gained a function so the docs can render them: `hook_transport.inline_context`, now the one place a hook's inline delivery is composed, and `forks._given_line`. **To weigh:** the recorded paths are the journey's `/private/var/folders/…` scratch page, which the lede says. The timings are one run on your machine. `AGENTS.md`'s rule for `docs/` (#6487) admits a figure from checked-in data, which `fork-journey.json` is, and here the seconds place one run's events rather than state how fast Leaf is. With #6497 merged, the work and resume previews show the delivery as the fenced block the fork reads, and `inline_context` writes it with `json_block`. Max asked for this after reading the same messages on a Leaf page: "a really really useful way to see the messages … can we consider having this as a part of How It Works on the Fork page with 'Anatomy of a Fork Journey'". Reviewed from light, dark and phone captures, which led to fitting the queued-lines box to its text, and by a reviewer who hadn't seen the work. Tests: both `test_product_page.py` files, `tests/model/test_forks.py`, `test_hooks.py`, `test_session_lifecycle.py`. `page check` is clean. > _This was written by Claude Code on behalf of max-sixty_
max-sixty
added a commit
that referenced
this pull request
Nov 19, 2026
… it (#6537) Every fenced block Leaf writes into a model's context now sits under a blank line rather than straight under the sentence that introduces it: the thread or delivery in the line, work, resume and summary forks' prompts, the answer schema in a system prompt, the inline delivery a hook hands a turn, and the pointer blocks of pointer deliveries and reminders. Max asked for it after #6497 fenced the JSON. The text that holds a block writes the blank line, as it does between its other paragraphs, and `json_block` still returns the block alone, since Codex's hook context is the block with nothing before it; `json_block.py`'s header records that. `inline_delivery` now reads the blank line and returns the delivery with the lines after its block, so `leaf-dev logs timeline` reads the clerk's lines through it instead of its own copy of the format. Six eval cases that paste a delivery under a sentence gain the blank line. The shipped Markdown references already had one before every fence. Tests: the model tests for hooks, forks, delivery, the stop guard, the layer contract, titles, activity, clerk, session lifecycle and the Codex adapter, the timeline, journey and How it works prompt tests, and the llm, Pi and Claude Code module process tests. Three snapshots gained the blank line. > _This was written by Claude Code on behalf of max-sixty_
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every JSON value Leaf puts into a model's context as data now goes through one helper,
leaf.json_block. It writes the value as a fencedjsonblock indented one space, andread_json_blockreads it back. The value can be a hook's delivery to the main thread or to a fork at a tool boundary, Codex's hook context, the working and resumed fork's task, the thread the line and summary forks read, or the answer schema in a system prompt. Max asked for this after reading a working fork's task, which held the thread's delivery as one line of several thousand characters, and asked for the same everywhere Leaf's agent instructions carry structured data.Values inside a sentence, Codex's
leaf_deliverytool output (the value alone) and every CLI output, record and wire message stay as they were.inline_delivery,leaf-dev logs timelineand the tests read the block back. Ten eval cases that pasted a hook's delivery as one line now paste the block.To weigh: deliveries grow about 13% on Claude Code and 17% on Codex, which was compact JSON. Over the last three days' 603 deliveries, 12 of 574 that fit inline on Claude Code and 11 of 575 on Codex would now go by pointer, costing a
leaf delivery read. The answer schema is now fenced while the instruction beside it says to answer with no fence. On Haiku that left answers parseable 36/36, the same as before. Pi's model wasn't measured.Evals on Claude Code, merge base against this change: line-fork 28/28 and 28/28, with the same
workjudgment on every trial, and summary-fork 6/6 and 6/6. For cases that paste their envelope, both forms were run on this change: claude-hook-delivery-needs-no-ack 5/5 and 5/5, answer-quotes-what-it-cites 11/11 one-line and 10/11 block. Each converted case was also run once in block form: 10/10. Evals cost about $15 in all.Tests: the model and process tests for hooks, forks, delivery, the Codex adapter, the stop guard, the layer contract, titles, llm and Pi, plus the docs prompt test. Two snapshots changed: the layer-contract walkthrough and the title request's system prompt.