Repository navigation
Read a rewrite's deleted lines above its added ones in a diff - #3951
Merged
Merged
Conversation
@pierre/diffs 1.6 (bumped from 1.5.2 in #3782 the day before) re-splits a change whose deleted and added line counts differ, so its most similar lines pair (realignChangeContentBySimilarity). That suits a split view; Leaf draws the unified view, where it moved deleted lines into the middle of the added ones. In a fresh Opus 5.5 patch review at 1600x1000 the retry patch's four deleted lines stood between the new function's 11th and 12th lines, with the re-indented lines 12-15 painted as changed words, and the pair judge gave HTML's plain removed-then-added diff "more readable code" twice (.tmp/eval/mix3-c6, patch-review). lf-diff now joins those pieces back after parsing, so each change reads as git wrote it: deletions, then additions. A git patch never sets two changes side by side without context between them, so a one-sided change beside another can only be such a piece. Rows, line numbers and comment coordinates are unchanged. Word highlights pair lines by position again, as on 1.5.2. Test: test_a_rewrite_reads_its_deletions_above_its_additions fails without the join (rows new1..new11, old1..old4, new12..) and passes with it. test_diffs.py -k "comments or selection or refresh or hunk" (8), test_render_anchors.py -k diff (20) and pnpm run test:runtime (540) pass; stills diff-file-threads, diff-long-lines, worktree-diffs, walkthrough-diff-comment and diff-filter are unchanged. Crops: .tmp/overnight/c7/rewrite-diff-{base,after}.png. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
previously approved these changes
Oct 25, 2026
Pierre's parsePatchFiles has run realignChangeContentBySimilarity since @pierre/diffs 1.3.0, and 1.5.2 splits the test's rewrite into the same three pieces as 1.6.1 (0/11, 4/4, 0/4). Leaf pinned 1.4.3 when it first pinned Pierre (#1084), so the rewrite has read this way since then, not since #3782. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty
added a commit
that referenced
this pull request
Oct 25, 2026
…#3957) Leaf dashboards and tuning pages were written as documents. The test was a release-rollout request: "I glance at it every few minutes ... the state has to read at a glance". Fresh Opus 5.5 authors on main followed `page-layout.md`'s "a release dashboard" to a sidebar page set as a document. Each page opened with a 46px title and a three-line lede, then metrics and decision prose. The trend chart, region table and checks fell below a 1600x1000 window, on pages 2229-2692px tall. The plain HTML control fitted status, metrics, chart, regions, checks, decision and log in that one window. On the same run's dashboards, panel headings came out as long all-caps sentences, such as a three-line, 129-character cause. And when the user's final settings were recorded on a configuration page, authors either left the playground authored at today's values under a "Final" heading, or folded it into a `<details>`. This PR makes four changes, one per commit. - **Window guidance** (`page-authoring.md`, "Composing a page"). The bullet for a screen the reader works in now also covers settings tuned against their evidence and a dashboard glanced at between other work. It states the goal: keep the working state in the reader's window, since a glance or a tuning pass doesn't scroll. It keeps the title and premise to a line or two and gives `main` `density-working`. A dashboard is a sidebar page with its regions side by side. `page-layout.md` says what `density-working` does on a column or sidebar `main`. - **Theme** (`browser/styles/theme.css`). On a working-density page, a sidebar page keeps the working title (22px) instead of the wide-page 46px title, and the page starts 28px from the window's top instead of 72px. Only the column and sidebar Layouts read `--page-pad-start`. Among the examples, only `examples/developer/playwright-trace-gallery.html` (a `layout-column density-working` main) changes, by that head room. - **Panel headings** (`page-authoring.md`, "Reading cost"). A `section.panel` heading is set in small capitals, which read as a region's name. So the heading names the region in a few words, and the panel's first line states the finding. - **An applied playground** (`authoring-revisions.md`). An applied playground becomes a record. Each control is authored at the chosen value, so the preview, Reset and the page's account agree. The playground stays open beside its evidence. - **The note.** It adds the campaign's retained and rejected changes, with their numbers, to `notes/agent-usability-evals.md`. ## Known regression: the dashboard at a short window At a 900x600 window, the branch lost the dashboard 2 of 2, one sample per arm. The guidance steers a dashboard to a sidebar page. Main's author wrote a workspace with a compact header and independently scrolling columns, and that did better at that height. The other short-window tasks went to the branch on configuration (2 of 2) and split on the queue (1 of 2), so the branch took 3 of 6 at 900x600, against 17 of 24 at 1600x1000. A likely next step is for the dashboard bullet to prefer a workspace when the reader's window is short. That hasn't been tried. ## Measured effect All authors were fresh Opus 5.5 Claude Code sessions at 1600x1000, with Sol live and pair judges, and base = main. Window guidance and theme: - Dashboard first versions were 2667-3390px tall on main (median about 3020, n=6) and 1704-1947px with the change (median about 1790, n=6). - Across the dashboard runs, all 5 candidate authors put `density-working` on the page and fitted regions, metrics, chart and decision in the first window. Of 4 base authors, none fitted them all. - Pair judgments against main went 7 of 8 for the change. Against HTML, the change took 4 of 4, where the baseline had lost 2 of 2. HTML's decision control didn't record a choice, and the judge still credited HTML's use of space. - Configuration first versions, before the user stated a window, were 1454 and 1944px with all six alerts or three in the window. On main they were 3332 and 2124px with one. Both arms reached a fitting page once the user stated the window, and the later pairs went 1 of 4 for the change, with the judges preferring base's final-record details. - A document control kept its reading column and document type. The live judges passed every candidate sample (9 of 9). Panel headings: - 7 of 7 earlier Leaf dashboards with panels had at least one panel heading over 40 characters, up to 129. - The 2 authors given the line wrote 9 panel headings, the longest 20 characters, each followed by its finding. Applied playground: - Candidate authors authored every control at the chosen value with the tuner open 2 of 2 times, and base 0 of 2. Across every later configuration run, authors with the line did so 7 of 8 times, authors on main 0 of 4. - Pairs went 4 of 4 for the candidate against base. Against the earlier HTML controls, the candidate took 1 of 4, up from 0 of 4; HTML still won on its separate final table and aligned rows. End state: - The campaign branch against main won 17 of 24 judgments, with two samples per task: configuration 4/4, dashboard 4/4, queue 4/4, latency 3/4, document 2/4, patch review 0/4. The patch review losses were on content: which diff the page showed and how it recorded approval. - The live judges passed 10 of 12 samples on each arm. The defects were content. - Codex authors (Sol 6.1) wrote working-density dashboards on both arms, so the guidance changes nothing there. Their configuration and queue pairs went to main 4 of 4, for causes outside these changes: a browser user's wrong click, and an item the author left open. That is n=1 per task. That branch also carried the playground label-choice fix (#3953), the queue summary size (#3955) and the diff fix (#3951). Evidence (local, in the campaign worktree `/Users/maximilian/workspace/leaf.agent-a10f091f355e3a600`): - Dashboard: `.tmp/overnight/c2/` (base-1, base-2, cand-1, cand-2, html). - Dashboard and configuration with the final wording: `.tmp/overnight/c3/`. - Page heights: `.tmp/overnight/c3/heights.tsv`. - Configuration final records: `.tmp/overnight/c4/config-final-{base,cand}-*.png`. - Panel-heading counts: `.tmp/overnight/panelheads.py`. - Cycle log: `.tmp/overnight/page-quality.md`. - Runs: under `.tmp/eval/`. ## Checks These ran on this branch cherry-picked onto current main. - `tests/browser/widgets/test_workspaces_and_bounds.py`, `tests/browser/test_render_gate.py`, `tests/browser/margin/test_rail.py` and `tests/browser/widgets/test_tabs.py` with `-k "workspace or sidebar or wide or release_page or working_prose_density or page_form_decides or title"`: 43 passed, 1 failed. - The failure is `test_a_release_page_is_wide_and_keeps_the_log_on_its_newest_line` (`lp-steps` right edge 1531, expected 1536). It fails the same way on main, so this change doesn't cause it. - `tests/model/test_interact_layer.py` and `tests/model/test_delivery.py` with `-k "skill or reference"`: 4 passed. - `pnpm run test:runtime`: 550 passed. - `pnpm run check:browser` passes (the generated `browser/theme.css` matches its source). - pre-commit passes. No open PR changes the same guidance or theme rules. #3898, #3913 and #3923 also append sections to `notes/agent-usability-evals.md`, so whichever lands second resolves that conflict by keeping both sections. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
approved these changes
Oct 25, 2026
max-sixty
added a commit
that referenced
this pull request
Oct 25, 2026
…3984) An `lf-diff` with its patch inline now first paints at the height its drawing lands at, so nothing below it moves when it upgrades, and the author writes no `data-height` for it. Before, its first paint was the raw patch's height: on a demo page the drawing moved what followed by up to +213 px at 420 px wide and +252 px on a 390 px phone. With this change the shift is 0 px at 420, 700 and 1280 px and on the phone, in Chrome and in Firefox, and an authored `data-height` is no longer needed (several in the examples were stale: `pr-key-hunk` stated 521 and drew 492). **How it sizes itself.** A new `x-initial` renderer (`packages/diff/initial/lf-diff.js`) runs as each diff's markup arrives. It counts what the drawing is made of: the files, whether they open, and the rows from the first `@@` on, less a separator for a first hunk that starts its file. For prose files, which wrap, it adds the greedy wrap of each row at the column the drawing will give it. It writes the counts as custom properties on the host, and the package theme turns them into the reserved height using the drawing's own sizing tokens. Those tokens move to `packages/diff/styles/geometry.css`, which the document theme and the shadow tree both import, and the text scroller's 15 px track becomes `--lf-text-scroll-track` in `reading.css`. The renderer draws nothing and loads no Lit. A `source` diff, a `view="file"` diff and a patch with a hunkless file get no counts and behave as before, and an authored `data-height` still wins. **What it costs, and why it can't wait.** The renderer is inlined into every page that has an `lf-diff`: 3.4 KB, 1.36 KB gzipped. The prototype measured about 5 ms of main-thread time before first paint; I didn't re-measure it on this head. The work can't move later because the height has to be in place before the first paint, and no module has loaded by then. **One wrap rule.** The choice of which files wrap (Markdown and plain text, unless `overflow` is set) moves into `packages/diff/widgets/overflow.js`, and both the widget and the initial renderer import it. The classic script can't read the registry, so the rule names the Markdown extensions itself; `tests/runtime/diff-overflow.test.mjs` checks them against `$languages.paths`. The column geometry the renderer uses (two 1 px frame borders, a gutter of `digits + 3` ch, 2 ch before the text and 8 px after it) stays as numbers in the script. `test_an_inline_patch_first_paints_at_the_height_it_draws_at` holds those numbers to the drawing: it compares first-paint and drawn heights at 1280 px and on a 390 px phone, with code, wrapped prose and folded diffs. It caught a gutter that was off by one column. It can't catch an error smaller than one character width. **Render-check advice.** `page check --render` no longer tells the author to set `data-height` on a box whose own theme already reserved a height from its markup. `firstBoxes` (`render-checks/driver.js`) records whether a stylesheet gave each first-paint box a height of its own: a computed `block-size` other than `auto`, read through `computedStyleMap()`. `unreservedHeights` then advises only where the first paint left the height to the content, or where `data-lf-height` set it. When a counted diff misses its height, the defect is the widget's, and the package author's `keeps-first-box` check reports it. A `data-height` would go stale with the next edit. The rule names no tag. `test_the_render_gate_reports_a_compact_spill_and_unreserved_heights` gains a case where a widget's own theme sized its box, and that case gets no advice. **Pages and instructions.** `data-height` is removed from every inline-patch `lf-diff` in `examples/` and from the registry `x-example`s. `docs/` has none. The source-bound `pr-exact-patch` keeps its `data-height` (2108 corrected to 1697), and `pr-reviewed-request` goes from 959 to 1037, both from the render check's advice. `page-layout.md`, the `lf-diff` `x-instructions` and the diff author guide now say an inline patch reserves its own height and only a `source` diff takes `data-height`. The diff package's `keeps-first-box` entry in `tests/known_widget_findings.py` is gone, since `leaf package check --render packages/diff` now reports nothing. **Known limits.** The prose wrap counts every character as one column, so tabs and wide characters (CJK) in a `.md` or `.txt` row get too few rows. The width is read once, when the diff's markup arrives. That doesn't matter on a served page, whose root always shows its scrollbar (`html[data-lf-live]`), but an export on a platform with classic scrollbars can lose a column when its scrollbar appears. The prototype's survey found Firefox one row over for heavily wrapped prose at 420 px. No diff that is counted lacks the file comment press, so the touch over-reserve I was asked to check (9 px per file) doesn't happen: on a 390 px phone the reserved height matches the drawn one exactly. Diagrams are not covered: `lf-diagram` still takes an authored `data-height`. #3951 also touched lf-diff rows. It merged before this branch's last merge from main, and this head was measured with it in. Checks run: `pnpm run test:runtime`, `pnpm run check`, the touched `lf-diff` browser tests and the render-gate test (`-n0`), `tests/model/interact_contract/test_vocabulary.py`, `test_registry_door.py`, `test_revision_delivery.py`, the diff case of `test_bundled_widgets_meet_the_widget_quality_checks`, and `page check --render` on `worktree-diffs`, `pr-walkthrough` and `diff-thread-gallery`. The only findings left are `unpointable` advice on markup this change doesn't touch. Closes #3174 > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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.
In a patch review at 1600x1000, lf-diff showed a rewrite's four deleted lines between the 11th and 12th of its 19 added lines. That cut the new function in two, and the re-indented lines 12-15 were painted as changed words. Pierre's parser has re-paired such changes since 1.3.0, so the diff has read this way since Leaf first pinned
@pierre/diffs(1.4.3, in #1084), not since the 1.6 bump in #3782: Leaf's vendored parser before that bump splits this PR's test patch exactly as 1.6.1 does.Pierre runs
realignChangeContentBySimilarityon every parse. It splits a change whose deleted and added line counts differ into pieces, so that its most similar lines pair up. That helps a split view. Leaf draws only the unified view, where the step moves deleted lines into the middle of the added ones. In a fresh Opus 5.5 patch review, the pair judge preferred plain HTML's removed-then-added diff both times, for "more readable code".lf-diff now joins the pieces after parsing, restoring git's order: each change reads deletions, then additions. A git patch never puts two changes side by side without context between them, so a one-sided change next to another change can only be one of Pierre's pieces. Rows, line numbers and comment coordinates are unchanged. Word highlights pair a change's lines by position.
The join undoes a step the dependency runs itself. An option in Pierre to skip realignment for the unified view would let this code go; that is reported upstream in pierrecomputer/pierre#1229.
Evidence (local, in the campaign worktree
/Users/maximilian/workspace/leaf.agent-a10f091f355e3a600):.tmp/overnight/c7/rewrite-diff-base.pngand.tmp/overnight/c7/rewrite-diff-after.pngshow the rewrite on main and with the join..tmp/overnight/c7/difftest.htmlreproduces it.Checks, on this branch cherry-picked onto current main:
test_a_rewrite_reads_its_deletions_above_its_additionsfails with main'slf-diff.js, where the rows read new1..new11, old1..old4, new12.., and passes with the join.tests/browser/widgets/test_diffs.py -k "rewrite_reads or comments or selection or refresh or hunk": 9 passed.tests/browser/test_render_anchors.py -k diff: 19 passed.pnpm run test:runtime: 550 passed.parsePatchFilesgives the same three pieces (0/11, 4/4, 0/4 deletions/additions) on 1.3.0, 1.5.2 and 1.6.1, and one change (4/19) on 1.2.0.No open PR touches the same code (searched "pierre", "realign", "diff deleted").