Repository navigation
Read the HTML in an agent's message by CommonMark's rules, with no exceptions - #6247
Conversation
An agent's message is Markdown with HTML whichever path posts it: a `leaf thread` command, a Codex turn's final message or opening, a fork's working line, a failure receipt or the turn-end check. #6208 read HTML only in the first and last, and logged `html: true` to mark them. Readers now derive it from the text (`thread_context.logged_fragment`), and the server serves it on each thread message, so the browser is unchanged. Behavior that changes: - A Codex final message with a stray tag is refused, and the correction delivery asks the agent to answer again; HTML in it now draws. - Progress lines may carry formatting HTML and still refuse a widget. - The turn-end check hands any ask Leaf refuses (HTML, or a picture the page hasn't got) to the agent as an owed line instead of posting it with its HTML as raw text, or dropping the whole answer for a missing picture. - The edit rules for HTML move from `leaf thread edit` to the append door. Protocol 47: a Leaf at 46 would draw these messages' HTML as text.
…e body #6225 put each test's widget into its message text and passed html=True, the parameter this branch removes; every agent message now reads its HTML.
…ceptions
An agent's thread message is Markdown whose raw HTML draws, and both runtimes read
it (passages.py to check it, markdown.js to draw it). They now read its HTML exactly
as CommonMark does, as GitHub reads a comment. Three departures go:
- A line opening a custom element no longer runs raw to its closing tag across blank
lines, nor interrupts a paragraph. A block of HTML now starts on a line holding its
opening tag alone and ends at the next blank line; a `<pre>` opening its own line
still runs to its closing tag.
- A `<code>` element's words are Markdown again, so a formula's `\{` needs `\\{`.
- The gate no longer refuses a widget inside a paragraph (`widget-in-paragraph`). A
widget written whole on one line, as most agents write a choice, draws inside the
paragraph Markdown puts around it. Where the HTML parser closes that paragraph
early, as an `lf-ask`'s heading or a data widget's `<pre>` does, the structure
checks refuse it (`unclosed`, `stray-members`, `data-body`). Of 50 widget messages
agents sent in real sessions, 46 draw as before and 4, one-line `lf-ask`s, would
be refused.
One failure no check reported: a blank line inside a `<pre>` within a widget or a
`<details>` ends the outer block, and Markdown reads the rest as paragraphs, so the
code keeps its words but loses its blank lines, indents and asterisks, in HTML that
stays well formed. The custom-element rule used to hide this for widgets. The message
gate now refuses a `<pre>` holding a `<p>` (`split-pre`), which HTML's content model
forbids and only that split draws, and threads.md says to put such text in a fence or
in a `<pre>` opening its own line after a blank line.
A refusal of a message's HTML now prints the lines of the HTML its Markdown drew that
the findings name, with one either side, since every finding counts lines of that
drawing and the drawing is often the cause.
markdown-it-py starts a block on a line indented four spaces once its `code` rule is
off, where the browser's markdown-it never does, so Python's message reading now
keeps that rule active and matching nothing. This replaces the indent guard the custom
element rule carried and also fixes indented headings, lists and fences, which
Python read as blocks and the browser drew as words.
threads.md says how a block of HTML starts and ends, and how a formula inside a
sentence escapes Markdown's punctuation. Tests whose messages wrote an `lf-ask` or a
data widget on one line now start it on a line of its own.
Scored thread-choice-takes-a-press and answer-quotes-what-it-cites on Claude Code,
3 runs per arm, on the first wording of the guidance: 12 of 12 pass, and each of the
six choices the runs wrote passes this gate.
leaf-agent
left a comment
There was a problem hiding this comment.
split-pre misses a split whenever Markdown reads the lines after the blank line as some other block than a paragraph. The docstring claims "no other check reports it" for that silent loss, and the same reasoning covers these cases. I ran this head's message_markup and split_preformatted on an <lf-code> whose <pre> holds YAML with a blank line (a: 1, blank, - b, - c). It draws <pre>a: 1\n<ul><li>b</li>…</pre> with no finding. A diff log after a blank line (+ added, - removed) does the same, and so does a numbered list. A shell comment (# comment) only gets caught because a <p> happens to follow its <h1>. A bounded log or diff is exactly what threads.md tells agents to put in a <pre>, so this is the main path for the new check, not an edge case.
None of those elements can be valid content of <pre>, which holds phrasing content only. So testing for any block element Markdown emits, not just p, closes the gap with no new false positive (suggestion below). The finding's words in findings.py ("holds a paragraph", "read the lines after it as paragraphs") would then say "Markdown blocks" instead.
…paragraph After a blank line splits a block of HTML, Markdown can read the lines after it as a list, heading or quote as well as a paragraph: a YAML list or a diff's +/- lines inside an lf-code's <pre> became a <ul> with no finding. split-pre now refuses any HTML element outside phrasing content inside a <pre>, which HTML's content model forbids there, and names it.
# Conflicts: # src/leaf/validation/admission.py # tests/browser/navigation/test_obligation_walk.py # tests/browser/navigation/test_reading_place.py # tests/browser/startup/test_modules.py # tests/browser/test_render_application_boundary.py # tests/browser/test_render_floating_panel.py # tests/browser/test_render_options_settled.py # tests/browser/test_render_read_state.py # tests/browser/threads/test_agent_replies.py # tests/browser/threads/test_panel_list.py # tests/browser/threads/test_summaries.py # tests/browser/threads/test_targets.py # tests/browser/widgets/test_threads.py # tests/journeys/test_interact_anchors.py # tests/journeys/test_interact_contract.py # tests/journeys/test_render_read_state.py # tests/message_html_cases.json # tests/model/interact_contract/test_revendoring.py # tests/model/interact_contract/test_thread_resolution.py # tests/model/test_delivery.py # tests/model/test_interact_anchors.py # tests/model/test_interact_document.py # tests/model/test_interact_product.py # tests/process/test_interact_server.py # tests/process/test_read_state.py # tests/process/website_server/test_turn_answers.py # tests/render_cases_interaction.py # tests/render_harness.py
# Conflicts: # browser/runtime/kernel-registry.json # examples/developer/feature-gallery.html # examples/ship-review.jsonl # src/leaf/events.md # tests/browser/test_render_application_boundary.py # tests/journeys/test_interact_contract.py # tests/model/interact_contract/_regtest_outputs/test_layer_contract.test_each_route_hands_the_agent_what_the_snapshot_shows__0/snapshot.yaml # tests/model/interact_contract/test_admission.py # tests/model/test_clerk.py # tests/model/test_delivery.py # tests/model/test_forks.py # tests/model/test_interact_document.py # tests/model/test_obligations.py # tests/model/test_stop_guard.py # tests/model/test_workflows.py # tests/process/website_server/_regtest_outputs/test_app_server.test_hosted_agent_receives_the_response_instructions_and_delivery__0/snapshot.yaml # tests/process/website_server/test_turn_answers.py
# Conflicts: # src/leaf/clerk.py
The live-sample history in `_sample_containment_page` still gave its agent reply `"html":true`, which the reply record no longer allows, so the sample's history was refused and the journey couldn't start its child. Its `\n\n` also reached the JSON as raw newlines, which the sample-json check refuses on main too; the literal now escapes them.
…ark-message-html # Conflicts: # browser/runtime/markdown.js # dev/tests/browser/test_draw_failures.py # tests/browser/projection/test_thread_replies.py # tests/browser/test_render_application_boundary.py # tests/browser/test_render_outbox.py # tests/journeys/test_interact_contract.py # tests/model/interact_contract/test_authored_markup.py # tests/model/test_interact_anchors.py # tests/model/test_interact_document.py # tests/model/test_interact_product.py # tests/process/test_interact_server.py # tests/process/website_server/test_turn_answers.py
# Conflicts: # browser/runtime/markdown.js # dev/tests/browser/test_draw_failures.py # tests/browser/projection/test_thread_replies.py # tests/browser/test_render_application_boundary.py # tests/browser/test_render_outbox.py # tests/journeys/test_interact_contract.py # tests/model/interact_contract/test_authored_markup.py # tests/model/test_interact_anchors.py # tests/model/test_interact_document.py # tests/model/test_interact_product.py # tests/model/test_responses.py # tests/process/test_interact_server.py # tests/process/website_server/test_turn_answers.py
A reply that moves or detaches its thread checks the page against the log plus a stand-in for the move, built from the reply's event. Since every agent message's text reads as HTML (#6218), the stand-in's copy of the text put the reply's widget ids into the log's message ids, so a reply whose id clashed with the page was refused as "cannot reply while index.html is invalid" rather than by the reply's own check, which names the clash. The stand-in now carries no text.
…its line (#6293) #6247 reads an agent message's HTML by CommonMark's rules, under which a block of HTML starts only from an opening tag alone on its line (`skills/leaf/references/threads.md`). The two failing tests seed replies whose widget opens `<lf-chart id=…><pre>` and `<lf-diff id=…><pre>` on one line. Markdown now wraps that in a `<p>`, the browser's parser closes the paragraph at `<pre>` and moves the `<pre>` out of the widget, so the chart throws `<lf-chart> has no data body` and the diff never renders. The fixtures are seeded with `append_carried_log_record`, past admission, so nothing reported the shape. The fixtures now put `<pre>` on its own line, as #6247 did for its own fixtures (`test_draw_failures.py`, `test_draft_editing.py`). This keeps #6247's intent and moves no interface: the tests still check that a chart in a closed thread draws at its visible width once opened, and that a diff in a panel reply takes the keyboard. Verified locally: both tests fail on `main` (the chart with the "no data body" error the issue quotes, the diff with the wait timeout) and pass with this change: - `tests/browser/widgets/test_charts.py::test_a_chart_in_a_closed_thread_draws_at_its_visible_width_when_opened` - `tests/browser/controls/test_focus.py::test_a_scroll_box_in_a_panel_reply_takes_the_keyboard` `passages.message_markup` on the new fixtures now draws each widget as its own block with the `<pre>` whole inside it. Closes #6291 — automated triage Co-authored-by: leaf-agent <[email protected]>
… drawing it (#6312) An agent's message whose widget opens on the same line as its content, such as `<lf-code id="x"><pre>…</pre></lf-code>`, is refused for what CommonMark does to it, and only that. CommonMark reads a custom tag sharing its line as inline HTML, so Markdown draws a paragraph around it and the `<pre>` closes that paragraph along with the widget. Before, the agent got a browser stack trace (`<lf-code> has no data body`) from the draw check, which runs before the markup gate. Now the draw check leaves markup the HTML parser repairs to the gate, and the gate's fragment stage reports a repair's findings alone, as its later stages already do. The refusal reads: ``` the HTML in the comment doesn't validate. Its Markdown draws this HTML, where the findings count lines: 1 <p>Here:</p> 2 <p><lf-code id="snippet"><pre><code class="language-python">print(1)</code></pre></lf-code></p> Findings: - unclosed tags: <lf-code> (line 2) ``` Max asked what the standard handling is for widgets written on one line (open item #8 from #6247). It's what Leaf's readers already do: a parser can't tell whether a custom element is block or inline, so CommonMark starts a block of HTML at one only when its tag is alone on its line (jgm in commonmark/commonmark-spec#758 and commonmark/commonmark-spec#239; commonmark/commonmark-spec#770, which would make hyphenated tags block-level, is still open). GitHub and markdown-it follow that. VitePress departs from it by treating every tag missing from a list of inline tags as block-level. Since #6256 a question is a `<section role="group">` or `<fieldset>`, which CommonMark reads as a block even on one line, so this rule now matters only for a data widget written on one line. Ran the model and process tests around message markup, and the journey test for a widget that fails to draw. > _This was written by Claude Code on behalf of max-sixty_
An agent's thread message now reads its HTML exactly as CommonMark does, as GitHub reads a comment. Max asked whether messages could hold HTML following Markdown's standards, with no special exceptions; this drops the three #6208 added (a custom element running to its closing tag across blank lines, a literal
<code>, and thewidget-in-paragraphrefusal).What changes for an agent writing a message:
lf-askor data widget whole on one line<pre>closes that paragraph early<details><pre>is refused (split-pre)<code class="language-math">\{x\}</code>\\{x\\}Worth weighing:
split-preis the one new check. A blank line inside a nested<pre>leaves well-formed HTML whose code silently lost its blank lines and indents, which nothing else reports; it refuses a<pre>holding any block, such as the<p>or<ul>Markdown draws there. A refusal also now prints the drawn HTML lines its findings name. Of 50 widget messages agents sent on local pages, 46 draw as before and 4 (one-linelf-asks) would be refused. Python's message reading also stops starting blocks on lines indented four spaces, matching the browser. It also fixes a regression from #6218: a reply that moves its thread checked the page against a stand-in event carrying the reply's text, so a widget id clashing with the page was refused as an invalid page rather than by the reply's own check.Scored
thread-choice-takes-a-pressandanswer-quotes-what-it-citeson Claude Code (12/12, base and head), reviewed by a fresh subagent, whose findings are fixed here. Ran model and process tests,pnpm run test:runtime,pnpm run check, and the 22 browser and journey tests holding edited messages.