Repository navigation
Render diffs with Pierre - #72
Conversation
leaf-agent
left a comment
There was a problem hiding this comment.
Two of these I checked by running the vendored bundle under node and reading the HTML it actually returns, so they're not guesses about Pierre's output — the details are in each inline comment. Together they mean the diff currently renders in Pierre's own palette and font rather than Leaf's, which is the half of the cutover the PR description calls "brighter line and word fills". Holding off on approving for that reason; the shape of the change itself reads well, and the parse/selection/export work all holds up.
The third is behavioural: a diff with file headers and no @@ line parses to a file with zero hunks and stages an empty <details> — no error, no lines, +0 −0. That is the "incomplete evidence" case strict parsing was adopted to prevent, and it's the one shape the old parser deliberately handled ("a hand-written diff carrying no @@ headers still shows its changes"). .lf-error is gated by rendering.py, so a genuine parse failure is caught by version check; this one isn't caught by anything.
How I verified the two CSS findings
preloadDiffHTML with the widget's exact OPTIONS returns, in order: <style data-core-css>, <style data-theme-css>, then <pre data-diff data-diff-type data-overflow data-disable-line-numbers data-background data-indicators data-dehydrated>. No element carries a data-theme attribute — the string data-theme occurs exactly once in the whole bundle, as data-theme-css.
Pierre's core sheet declares its variables on :host inside @layer base, e.g. --diffs-bg: light-dark(var(--diffs-light-bg, #fff), var(--diffs-dark-bg, #000)) and font-family: var(--diffs-font-family, var(--diffs-font-fallback)) where the fallback is "SF Mono", Monaco, Consolas, …. The dropped data-theme-css sheet is what supplies --diffs-light-bg, --diffs-dark-bg, --diffs-*-addition-color, and --diffs-scrollbar-gutter-measured, so with both faults standing the background resolves to a literal #fff/#000.
An unlayered :host(.lf-rendered) rule outranks Pierre's @layer base regardless of specificity, so moving the block onto the host is enough — no !important, no layer of its own.
One thing outside the diff, for whenever it's convenient: .claude/skills/running-tend/SKILL.md has a weekly step that reads HLJS_VERSION and MARKED_VERSION out of the two vendor scripts and compares them against npm, precisely because Dependabot can't see a version held in a shell variable. PIERRE_VERSION (and SHIKI_VERSION) are now a third and fourth of exactly that kind and will drift the same way silently.
leaf-agent
left a comment
There was a problem hiding this comment.
One finding, on the authoring contract this push added rather than on the code it fixes — the previous round's five all check out, and I re-verified the two CSS ones the same way I found them (the shadow tree now carries one data-core-css and one data-theme-css sheet, and :host(.lf-rendered) is unlayered so it outranks Pierre's @layer base).
The registry entry now tells authors to write   for a context line with nothing after the space. That works everywhere except the last line of the body, where the widget's own \n\s*$ strip eats it — and strict parsing then rejects the whole diff with hunk line count mismatch, which points at the counts rather than at the line that was removed. It's the same normalization as before the cutover, but before the cutover a dropped trailing context line was silently tolerated; now it's fatal, and the instruction the author just followed is what puts them there. Inline suggestion on the strip.
How I verified it, and why the narrower strip is safe
dataBody is el.querySelector(":scope > pre").textContent, so   is already a plain space by the time it reaches the strip, and \s covers it. Feeding the vendored bundle the textContent a column-0 <pre> produces for a diff whose last line is that context line:
/\n\s*$/ -> THROWS: parsePatchContent: hunk line count mismatch
/\n$/ -> ok, 1 hunk, 2 context lines
The leading half is already safe — ^\n+ matches newlines only, so a   first line survives.
Every authored lf-diff body in examples/ and tests/ ends with exactly one \n (the </pre> sits at column 0, which the entry's own "at column 0" already requires) or with no trailing newline at all, so the narrower strip is a no-op across the corpus.
The alternative is to leave the strip alone and say in the entry that the   line can't be last — but that reads as an arbitrary exception, and the widget can just stop eating it.
|
One more on the strict-hunk guard, which arrived after the approval above rather than before it: |
leaf-agent
left a comment
There was a problem hiding this comment.
Two findings on this push, both about the hunkless taxonomy it introduces rather than about the guard it fixes — the rename-pure branch itself checks out (I ran the vendored parser under node: a pure rename really does come back type: "rename-pure" with prevName set and zero hunks, and shadowStage always injects the theme's shadow slice, so a rename-only diff is still styled).
The new row stands in no example and in no render case. .lf-diff-rename is a box the reader sees — its own border, background, and padding, outside any <details>, with no <pre> under it — and the only page that composes it is the Playwright fixture in test_render_anchors.py, which asserts DOM properties rather than layout. So none of the eight nightly sweeps read it in either palette, through axe, in print, or through export, and TRAPPED_MARGINS, COVERED_WORDS, and MISPLACED_BOXES never get a reading on it. examples/CLAUDE.md names this exact trap: "a widget that stands in no example is a widget the sweeps have never seen inside a whole page. That gap is easy to miss, because the widget's own tests are green — the missing coverage reads as coverage," and, under Standing here is not the same as having been looked at, "Where an attribute or a content shape changes what a reader sees, a page here shows that shape." A rename entry in pr-walkthrough.html's existing lf-diff, or a case beside SHADOWED_DIFF in tests/render_cases_layout.py, would close it. Happy to push either if you'd like.
The second is inline on the registry description: two hunkless shapes it doesn't name reach the reader wrong rather than being refused with a message that fits them.
What the vendored parser returns for each hunkless shape
parsePatchFiles(source, undefined, true) on the bundle at this head, one entry per case:
purerename [{"type":"rename-pure","name":"new-name.js","prevName":"old-name.js","hunks":0}]
renamechanged [{"type":"rename-changed","name":"new.js","prevName":"old.js","hunks":1}]
copy [{"type":"rename-pure","name":"b.js","prevName":"a.js","hunks":0}]
emptynewfile [{"type":"new","name":"empty.txt","hunks":0}]
deletedempty [{"type":"deleted","name":"gone.txt","hunks":0}]
modeonly [{"type":"change","name":"run.sh","hunks":0}]
binary [{"type":"change","name":"logo.png","hunks":0}]
Empty added and deleted files. git add on a touched-but-empty file gives exactly diff --git + new file mode 100644 + index 0000000..e69de29, with no hunk because there are no lines to carry one. That hits the throw, and the message it gets — "binary and mode-only entries belong in prose; changed files need textual @@ hunks" — names neither the shape the author has nor an instruction they can follow: there is no @@ header to add for a file with nothing in it. The entry's own list is the other half; it names binary and mode-only and stops, so an author who reads it and then hits the error has nowhere to go.
Copies. git diff -C (or diff.renames = copies) emits copy from a.js / copy to b.js, and Pierre parses that into an object byte-identical to the rename above — same type, same name, same prevName, so the widget cannot separate them from file alone. The row then reads a.js → b.js renamed about a file that is still there, which is the page stating something the source does not. Refusing them in the entry is the cheap answer; separating them would mean reading copy from off the raw body, which isn't worth it.
rename-changed is the smaller third: it renders through renderFile and its summary shows only file.name, so a rename that also changed lines drops the old path the source carries. That's how it behaved before this PR too — it's only that the entry now promises renames "appear as one old → new row," which holds for the pure case alone.
|
Confirmed resolved at One thing worth recording for whoever touches the copy guard next, not a request. A copy with edits — Parser probe at
|
leaf-agent
left a comment
There was a problem hiding this comment.
Moving the rename into ship-review.html as part of that page's own story is a better home for it than the walkthrough was, and it holds together end to end: the tree entry, the new sentence, and the diff all say the same thing now, and test_gallery_is_generated_from_the_examples and test_examples_pass_check both pass on it here. It also clears the new guard on its merits rather than being grandfathered past it — the vendored parser returns client/offline/merge.ts with one hunk and client/offline/document-store.ts as a hunkless rename-pure with no mode or blob fields. I checked the guard's other side against real git diff output too: git mv alone emits no index line at 100% similarity, and git mv plus a chmod +x emits exactly the old mode/new mode pair the new test case pins, so the shape the guard exists to catch is the shape git actually produces.
One finding, inline, on the second of the two markers renameNode now writes.
Separately, and not about this push: the copy guard is broader than the row it protects, and this is the first round it has stood without comment. A copy from/copy to block with textual hunks comes back from Pierre as rename-changed, and renderFile labels that with file.name alone — no arrow, no "renamed" — so it stated nothing false and rendered fine at ed711be. Only the hunkless copy arrives as rename-pure, which renameNode draws as a.js → b.js renamed about a file that is still there. /^copy (?:from|to) /m can't separate them, so a real git diff -C whose copy destination was edited now fails the whole widget. Refusing both is the simpler rule and the registry's way out does work — I ran it — so this is a fair call to have made; what it costs is that the body stops being the diff verbatim for that one shape, and the fix if you ever want it is to collect copy to paths off the source and refuse only the ones that come back rename-pure.
Probes against the vendored bundle at 8be7ca0
parsePatchFiles(source, undefined, true) flattened over patch.files, plus the widget's own pathOnlyRename test applied to each result:
ship-review off-merge-diff merge.ts type=change hunks=1
document-store.ts type=rename-pure hunks=0 pathOnly=true
pure rename type=rename-pure hunks=0 pathOnly=true
pure rename + index line type=rename-pure mode=100644 prevObjectId/newObjectId set pathOnly=false
rename + chmod type=rename-pure mode=100755 prevMode=100644 pathOnly=false
pure copy type=rename-pure prevName=source.js hunks=0 guard=true
edited copy type=rename-changed prevName=source.js hunks=1 guard=true
copy lines dropped type=rename-changed hunks=1 guard=false
copy + similarity dropped type=change hunks=1 guard=false
The last two rows are the registry's documented remedy for a copy, and it lands where it says: dropping the similarity index line as well is what gets a plain change; keeping it leaves a rename-changed, harmless because the summary shows only the destination path.
Real git diff for the rename shapes, from a scratch repo:
git mv old.js new.js -> diff --git / similarity index 100% / rename from / rename to (no index line)
git mv old.js new.js; chmod +x -> ... plus old mode 100644 / new mode 100755
I also grepped examples/, tests/, and plugins/ for a column-0 copy from/copy to and found none, so the pre-parse test has nothing to false-positive on in the corpus — every content line in a unified diff carries its prefix.
Not run here: the browser suite. This runner has no Playwright browser (Executable doesn't exist at …/chrome-headless-shell), so test_render_anchors.py is unverified from my side and I read the rename markers rather than measuring them; ci / test on this commit is the reading that counts.
leaf-agent
left a comment
There was a problem hiding this comment.
The source cross-check holds up where I could test it. I built the two-sided quoting case in a scratch repo rather than reasoning about it: git C-quotes each path independently on both the header and the rename lines, so a rename where only one side needs quoting (readme.md → léame.md, which core.quotepath quotes by default) comes out as diff --git a/readme.md "b/l\303\251ame.md" with an unquoted rename from, and headerPath reconstructs exactly that. Both corpus blocks — gallery.html and ship-review.html — are the canonical four lines with the rename last in the body, so the \n+$ strip leaves them at four and the new guard doesn't touch them.
One finding, inline: the mode/object-id clauses the guard was built around are now unreachable behind it.
What I ran
git init; commit readme.md; git mv readme.md léame.md
git show --format= -M HEAD | cat -A
diff --git a/readme.md "b/l\303\251ame.md"$
similarity index 100%$
rename from readme.md$
rename to "l\303\251ame.md"$
That was the case I expected to break it — quote_two quoting both header paths whenever either needs it would have made headerPath("a", "readme.md") produce a/readme.md against a quoted "a/readme.md". It doesn't; each side is quoted on its own, in the header and in the rename line alike, so the reconstruction is faithful.
Corpus check, both examples:
examples/gallery.html:189-192 diff --git / similarity index 100% / rename from / rename to
examples/ship-review.html:183-186 same four lines, </pre> at column 0 on the next line
Not run here: the browser suite — this runner has no Playwright browser, so test_render_anchors.py is unverified from my side and ci / test on this commit is the reading that counts. lint was green on the previous head; test was still running there when this head landed.
The render gate used to reach /api/state behind a networkidle navigation, which waited out the page's first poll and the append that rode on it. The news stream leaves the network never idle, so the gate now navigates on load and can reach /api/state while the page's first read is still in flight — whereupon it counts an empty log, waits for nothing, and reads a page 120px mid-move. That is what CI reported at run 33053132232. The window this test constructs is now stated on both sides: the action still goes in behind the page's first read, and the gate's own read is held until it has. A 0.4s delay on the page's read reproduces the CI failure exactly on the old test and passes on the new one at 2s, so the ordering is an arrangement rather than a margin. The premise assertion moves ahead of the gate's verdict, since a window that never opened makes that verdict say nothing.
# Conflicts: # tests/test_render_projection.py
leaf-agent
left a comment
There was a problem hiding this comment.
Nothing new on the Pierre work itself — every file this PR owns is byte-identical to the tree approved at 3a3b549. The whole increment is #73 and #74 merged in, plus #75, which is now on main as 44d1ac7. So this approval is about the merge rather than about new code.
The merge is a faithful union. I compared each of #73's and #74's files against their own three-dot diffs from the shared base a3dbce1: every file matches its source PR exactly except leaf.js, registry.json, and test_interact_product.py, which more than one branch touches — and those three carry every side's hunks. movedWords leaves the widget API alongside #74's threadMarkupAwaiting wiring; this PR's $languages description sits beside #74's awaits comment schema; the bundles_carry rename sits beside #73's dropped-id assertion and #74's new reply test, and the line counts close exactly (1474 base, +2 from #73, +51 from #74, −1 here, 1526 at this head). No symbol collision either: movedWords has no consumer left outside lf-suggestion.js, which is what the cutover set out to do, and threadMarkupAwaiting is wired end to end through asks/model.js and reconcile.js.
Worth stating since the description doesn't: merging this lands #73 and #74 with it. Both are approved at trees equivalent to what's here, so nothing goes in unreviewed — they'd just need closing out afterwards rather than merging on their own.
ci / lint is green on this head. test was still running when I wrote this, and it is the reading that counts for the combined tree — I'll dismiss this approval if it goes red.
# Conflicts: # plugins/leaf/skills/leaf/assets/leaf.js # plugins/leaf/skills/leaf/assets/runtime/widget-api.js # plugins/leaf/skills/leaf/scripts/leaf/render_checks.py
leaf-agent
left a comment
There was a problem hiding this comment.
Nothing new in the Pierre work — the whole increment since 68abfdc is main catching up, and the merge is faithful in both directions. This head differs from ad353ff in exactly the 28 files the PR owns, and each of those diffs is only this PR's own hunks sitting on main's current content, so nothing of the refactor was dropped and nothing extra came along.
Two pieces of it were real re-work rather than a clean replay, and both check out. The scroller tab-stop grant in bake() moved from render_checks.py's BAKE string into render-checks.js unchanged apart from indentation — same predicate, same roots it now iterates, and roots is the array bake() builds at its top by pushing every open shadowRoot it walks into, so nested roots are covered and the array is fully populated well before this loop reads it. The export sweep in test_render_export.py already gates it: every example's copy goes through axe at 420px, and a shadowed code[data-code] with no way in is a serious violation there. And movedWords came out of runtime/passages.js, its shim, and runtime/widget-api.js in one piece, with the private copy in lf-suggestion.js identical bar the shared field only lf-diff wanted — nothing else in the tree names it, and alignText is still published for the drafts test that imports it.
One correction to my last approval, since the thread would otherwise read wrong: merging this no longer lands #73 and #74 with it. Both are on main now, as is #75, so what's here is the Pierre cutover alone.
The PIERRE_VERSION/SHIKI_VERSION drift point from an earlier round is closed — the weekly step names both and scripts/CLAUDE.md carries the script. ESBUILD_VERSION is a third pin in that file and isn't named, but it builds the bundle rather than shipping in it, which is the same bargain the other vendor scripts already make.
ci / lint is green on this head; test was still running as I wrote this, and it is the reading that counts for the merged tree — I'll dismiss this approval if it goes red.
…ding it (#2580) Item 72 of the Lit follow-up review. That review numbers its own items, so #72 is not a GitHub issue. ## Item 72: a comment being written stays in hand when its outlet's content goes **What changed.** A comment being written on a diff line now keeps focus, with no blur, when a change removes the line without a redraw that would keep its outlet. There are four such changes: a new patch that drops the line's file, the file's next deferred patch failing to load, the source being cleared, and a patch the widget refuses (`failSoft`). Before, each of them removed the thread outlet holding core's composer before the thread placement committed. A dropped file lost focus altogether, and the user was left on the page. In the other three the box blurred once and `restoreFab`'s hold put the user back. The same cause affected `lf-visual-review`: a new run that dropped the case being commented on left the user on the next case's title, and a cleared source blurred the box once. Both now keep the user typing too. **How.** #2570 gave the placement an `onCommit` hook, so a widget removes unused outlets only once core has moved the composer. Its hook didn't cover a removal outside the placement, and the runtime had nothing a widget could call first. - `releaseOutlets(node)` (`thread/surfaces.js`, exported from `widget-api`) moves core's composer out of every registered outlet under `node` immediately, to where the next commit would put it. On every path this covers, the composer's datum is gone, so the next commit puts it in the same place and doesn't move it again. The move goes through `move()`, which keeps focus. The released box is in the viewport. - `lf-diff` calls it before dropping a file, before a file's error box replaces its lines, before a cleared source empties its stage, and before `failSoft`. - `lf-visual-review` calls it for the cases a new run drops, at the top of `#show`, and before `failSoft`. - `failSoft` doesn't call it itself. The dependency gate forbids `widget-upgrade.js` from importing the thread layer, because that import closes a cycle through `markdown.js` and `projection/authored.js`. These two are the only widgets that place threads. - A release has to come before any `holdFocus` around the removal. Otherwise that hold reads the user as having left and hands them to Retry or to the case title. `module-authoring.md` ("Widget-local Thread placement") states this next to `onCommit`. **Not done here.** I didn't add a removal hook in `dom-children.js`. `lf-visual-review` removes cases through Lit `repeat` rather than `setChildren`, so the hook wouldn't reach it. A release made during removal would also come after the widget's own focus hold. While the floating bar is still being placed at home, that hold would not count it as drawn. A revision that removes the whole widget while the user is composing is deferred (`midComposition` in `version.js`). I checked this: the revision was not applied within 120 s. **Lines.** Hand-written source: +31 / −1 (surfaces.js +11, widget-api.js +1, lf-diff.js +12/−1, lf-visual-review.js +7). Tests: +102 / −6. **Tests.** - `test_a_comment_being_written_on_a_diff_line_stays_in_hand_across_a_new_patch` runs four new cases: `file-dropped`, `file-refused`, `source-cleared` and `patch-refused`. It now also checks that the box is in the viewport. Each new case fails on `main`. `file-dropped` loses focus, and the other three blur once. `patch-refused` was checked by disabling the release before `failSoft`. - `test_a_comment_being_written_on_a_visual_case_stays_in_hand_as_the_case_goes` has two cases, `case-dropped` and `source-cleared`. Both fail without the release in `#show`. ## Checks These pass: `npm run test:runtime`; the diff, visual-review and failure selections of `test_render_threads.py`, `test_render_diff_controls.py`, `test_render_anchors.py`, `test_render_widgets.py`, `test_render_read_state.py`, `test_render_drafts.py`, `test_thread_response_continuity.py`, `test_response_pointer.py` and `test_render_visual_review_journey.py`; the widget-api export test; and pre-commit. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Leaf's hand-written diff renderer duplicated patch parsing, language tokenization, line pairing, and paint. Its word marks were hard to read, visible change indicators entered copied text, and file headers inherited code-block styles.
This changes
lf-diffto Pierre's vendored static renderer. Pierre now owns strict patch parsing, line pairing, brighter line and word fills, and visible+/-indicators rendered as unselectable pseudo-elements. Leaf keeps exact source in its passage model, removes hidden line-number nodes, maps token colors onto Leaf syntax roles, and preserves the rendered shadow tree in standalone exports.The cutover also removes obsolete diff-only helpers, keeps suggestion comparison local to
lf-suggestion, adds a reproducible vendoring script and license notices, and makes exported shadow scrollports keyboard-accessible.Path-only renames render as compact old-to-new rows. Other hunkless shapes—copies, empty additions or deletions, binary entries, and mode changes—fail visibly with guidance to state them in prose; malformed textual hunks fail rather than dropping evidence. Generated rename summaries remain in the page's visible reading without being mistaken for authored diff text.