Repository navigation
Ask a message's text for the media it names, as the markup door does - #324
Conversation
`media_errors` reads a picture out of an attribute, which is where markup names one. A message names its picture in Markdown, so `leaf comment --text ""` reached the log through the one door that never asked — and the log is append-only, so a reference the page directory cannot answer is a broken image for as long as the page exists. `read_text_arg` is where every agent-authored body arrives, so the reading sits there: text, markup, or both, a `/media/…` name has to be a file. The reference is read by the layer's own content-addressed naming rather than by scanning for the word, so `/media/` standing in a sentence is prose.
leaf-agent
left a comment
There was a problem hiding this comment.
text_media_errors scans the raw body, so it reads a mention as a reference — which is the one reading this repo has already written down twice as wrong.
test_check_names_a_media_reference_the_directory_cannot_answer states it for the markup door: "A mention is not a reference: a page explaining leaf writes one of these paths in its prose, and reading the markup rather than the attributes would send its author hunting for a screenshot the page never asks for." _inline_assets in exporting.py states it again next to the incident — "a text scan crashed the export on a documented path no file answers" — and takes references from the parsed reading for exactly that reason. The browser has a name for the same reading: runtime/media.js exposes isCanonicalMediaUrl, and runtime/markdown.js calls it on a link or image token's href, never on the surrounding words.
The digest requirement narrows the scan but does not make it that reading. Checked against the compiled pattern:
| body | matched |
|---|---|
Write it as `/media/deadbeefdeadbeef.png` in the message. |
yes |
```prints /media/deadbeefdeadbeef.png``` |
yes |
the panel now:  |
yes |
put the shot under /media/ as usual |
no |
So leaf comment <page> --text 'Write it as /media/deadbeefdeadbeef.png' now exits 1 with "isn't in the page directory; leaf page media puts it there", on a message that names no picture and renders as literal text — while the same sentence authored into the page passes version check. Two doors, one page, opposite answers about what a mention is; the PR's own reference text says "in text as in markup".
The new test's prose case (put the shot under /media/ as usual) is the digest-free shape, which the pattern was never going to match, so it doesn't reach the case the existing markup test records. Worth extending it to a digest-bearing mention once the reading changes.
The inline suggestion reads a Markdown link or image destination instead, which is what the runtime resolves. Verified against the same table: the two mentions above stop matching, and , [text](…), a title (), and an angle-bracket destination (](</media/….png>)) all still match, with findall returning the captured path so text_media_errors needs no change. check_markup's and read_text_arg's docstrings would want a word about destinations rather than names. The residual is a fenced block quoting a whole image construct — the same residual _inline_assets already names and accepts.
The text door scanned the raw body for /media/<digest>.<ext>, so a path quoted in a sentence or a fence read as a reference the page directory had to answer. Authored markup has never read a mention that way, and the runtime resolves /media/ only off a link or image token's href. Match the Markdown destination instead, and extend the test's accepted case from a digest-free sentence to the digest-bearing mention the markup door keeps.
leaf-agent
left a comment
There was a problem hiding this comment.
The destination reading landed, and the two mentions in the earlier table now pass. One shape of destination is still missed, and it is the one the door exists for: a Markdown link reference definition. marked resolves ![shot][ref] plus [ref]: /media/….png into an image token whose href is that path, so the runtime renders it exactly as it renders the inline form — but \]\( never sees it, and the body is accepted into an append-only log.
Checked against the vendored parser and the merged tree's own code, not from memory:
| body | marked token |
text_media_errors |
|---|---|---|
 |
image href |
refused |
[a](</media/deadbeefdeadbeef.png> "t") |
link href |
refused |
write it as `/media/deadbeefdeadbeef.png` |
none | accepted |
![shot][r] + [r]: /media/deadbeefdeadbeef.png |
image href |
accepted |
[the panel][r] + [r]: /media/deadbeefdeadbeef.png "cap" |
link href |
accepted |
So leaf comment <page> --text $'![shot][r]\n\n[r]: /media/deadbeefdeadbeef.png' freezes a broken image for the page's lifetime — the harm test_the_reply_door_refuses_a_picture_the_page_directory_has_not_got was written against, through the door this PR opens. It is the reading the docstring already claims, not a wider one: a definition is a destination, and the sentence-quoted path stays prose either way. The reference prose says the same thing in conversation-threads.md ("It reads the link and image destinations the runtime resolves") and events.md, so both hold once the pattern does.
The inline suggestion adds the definition branch. Verified: the five refusals and acceptances above all come out right, and uv run pytest tests/test_interact_contract.py is green with it (264 passed). The residual it adds is a definition nothing references, which renders nothing and would now be refused — narrower than the fenced-image-construct residual the docstring already names, and it errs toward the door rather than through it. The test's accepted case would be worth a refused reference-style sibling beside the angle-bracket one.
How this was checked
marked tokens, against the vendored bundle the runtime imports (skills/leaf/assets/vendor/marked.esm.js), with the renderer overrides from runtime/markdown.js:
"![shot][ref]\n\n[ref]: /media/deadbeefdeadbeef.png" => [["image","/media/deadbeefdeadbeef.png"]]
"[the panel][ref]\n\n[ref]: /media/deadbeefdeadbeef.png \"cap\"" => [["link","/media/deadbeefdeadbeef.png"]]
"write it as `/media/deadbeefdeadbeef.png` here" => []
text_media_errors on the same bodies, imported from the merged tree:
inline : ["/media/deadbeefdeadbeef.png isn't in the page directory; `leaf page media` puts it there"]
refstyle : []
A reference-style `![shot][ref]` keeps its destination in the definition line, and marked resolves it to the same href the inline form produces — so the text door accepted a broken image the runtime renders. MEDIA_REFERENCE now reads that line too, and the test refuses one.
leaf-agent
left a comment
There was a problem hiding this comment.
The reference-definition destination landed, and the five shapes in the last table now come out right. One gap in the same seam is left, and it is the one the PR's own sentence claims closed: the text door reads only a digest-named destination, while the markup door refuses any /media/… at all. _StructParser harvests v for v in attrs_d.values() if v.startswith("/media/") — no name shape — so the two doors ask different questions, and the narrower one is the door this PR opens.
Checked against the merged tree and the vendored parser, not from memory:
| body | rendered | text door | markup door (same ref in src=) |
|---|---|---|---|
 |
<button><img …> |
refused | refused |
 |
<img src="/media/screenshot.png" alt="shot"> |
accepted | refused |
![shot][r] + [r]: /media/screenshot.png |
<img src="/media/screenshot.png" alt="shot"> |
accepted | refused |
isCanonicalMediaUrl returns false for the non-digest href, so markdown.js's image renderer returns false and marked falls through to its default one — which emits a plain <img> pointing at a path SERVED_PATH.fullmatch will never answer. So leaf comment <page> --text 'look: ' exits 0 today and freezes a broken image in the append-only log: the exact harm test_the_reply_door_refuses_a_picture_the_page_directory_has_not_got names, arriving through the door that was supposed to start asking.
The digest requirement was load-bearing when the reading was a scan of the words — it was what kept a sentence from being read as a reference. Once the reading is a destination, ]( and the definition line do that work on their own, and the digest constraint only narrows which broken destinations get caught. Dropping it makes the two doors one predicate: any /media/… destination, which is all the directory can hold anyway.
The inline suggestions do that. Verified: every case in this table and in the previous two comes out right, the sentence-quoted path and `…` mention still pass, [the guide](/docs/media/thing.png) still passes, and uv run pytest tests is green with them applied (883 passed, 6 skipped). The two go together — _DIR_FILES has no other reader in this module, so the pattern change alone leaves an unused import for lint. The test's refused cases would want a non-digest sibling, and conversation-threads.md's "in text as in markup" becomes true rather than nearly true.
How this was checked
Both doors, against the merged tree:
TEXT DOOR  -> exit 0, comment appended
MARKUP DOOR <img src="/media/screenshot.png"> -> exit 1, "/media/screenshot.png isn't in the page directory"
marked from the vendored bundle (skills/leaf/assets/vendor/marked.esm.js) with runtime/markdown.js's renderer overrides:
"look:\n\n" => "<p>look:</p>\n<p><img src=\"/media/screenshot.png\" alt=\"shot\"></p>\n"
"look:\n\n" => "<p>look:</p>\n<p><button><img src=\"/media/deadbeefdeadbeef.png\" alt=\"shot\"></button></p>\n"
"![shot][r]\n\n[r]: /media/screenshot.png" => "<p><img src=\"/media/screenshot.png\" alt=\"shot\"></p>\n"
MEDIA_REFERENCE as compiled, before and after the suggestion:
"" old=['/media/deadbeefdeadbeef.png'] new=['/media/deadbeefdeadbeef.png']
'[a](</media/deadbeefdeadbeef.png> "t")' old=['/media/deadbeefdeadbeef.png'] new=['/media/deadbeefdeadbeef.png']
"write it as `/media/deadbeefdeadbeef.png`" old=[] new=[]
"the file /media/screenshot.png is there" old=[] new=[]
"see [the guide](/docs/media/thing.png)" old=[] new=[]
"" old=[] new=['/media/screenshot.png']
"![shot][r]\n\n[r]: /media/screenshot.png" old=[] new=['/media/screenshot.png']
"![shot][r]\n\n[r]:\n /media/…png" old=['/media/deadbeefdeadbeef.png'] new=['/media/deadbeefdeadbeef.png']
The markup door harvests every attribute value under `/media/`, no name shape, because the directory holds digest-named files and nothing else — so any other path under that root is one it can never answer. The text door asked only about a digest-named destination, which the widened reading no longer needs: `](` and the definition line are what keep a mention a mention, and the digest only narrowed which broken destinations were caught. `` renders as a plain <img> — `isCanonicalMediaUrl` is false, so `markdown.js` falls through to marked's default renderer — and froze a broken image in the append-only log. Both doors now ask one question.
Problem
media_errorsasks both markup doors whether a/media/…reference names a file the page directory has, because a reply carrying pictures is the shape an agent sends and the log is append-only. It reads those references out of parsed attributes, which is where markup writes one. A message writes its picture in Markdown instead, andcheck_markupruns onlyif markup, so this was accepted and frozen:That is the same harm
test_the_reply_door_refuses_a_picture_the_page_directory_has_not_gotwas written against — a broken image for as long as the page exists, which no later check mentions — arriving through the door that never asked. #320 is where the corpus first names media that way, andauthoring-evidence.mdalready tells the agent to write the printed/media/…path into a message.Solution
text_media_errorsreads a body for the Markdown destinations the runtime resolves — inline after](, angle brackets and a title included, and the definition a reference-style![shot][ref]resolves through — and hands the hits to the same file checkmedia_errorsuses. It asks about any/media/…destination, which is the predicate the markup door's attribute harvest already keeps:_StructParsertakes every attribute value under/media/with no name shape, because the directory holds digest-named files and nothing else, so— whichisCanonicalMediaUrlrejects, leavingmarked's default renderer to emit a plain<img>at a path nothing serves — is a broken image at either door. The reading sits inread_text_arg, which is where every agent-authored body arrives — comment, reply, edit, receipt, and a stamp note — so text and markup are asked the same thing at one door.Reading destinations rather than the words is what keeps a mention a mention:
runtime/markdown.jscallsisCanonicalMediaUrlon a link or image token'shrefand nowhere else,version checkhas always let a path written into prose through, andinline_assetstakes its references from the parsed reading after a text scan crashed an export on a documented path. A page explaining leaf can quote/media/deadbeefdeadbeef.pngin a sentence and both doors agree it is words. The residual is a fence quoting a whole image construct, which is the residualinline_assetsnames and accepts too, plus a definition nothing references — it renders nothing, but it reads as a destination and errs toward the door.The browser door is unchanged. A pasted image is stored before its reference enters a draft, so a reader's reference exists by construction.
Testing
test_the_text_door_refuses_a_picture_the_page_directory_has_not_gotposts the image reference, the same path quoted in a sentence, a link destination with angle brackets and a title, a reference-style image whose definition carries the path, a destination under/media/the directory can never hold, and the image reference again with the file laid in.Local runs
The nightly browser modules are left to CI.