Artifacts Associated With Ticket e16ad1d395752c1eb2ced0b324e096ffee618218
Ticket change [ff7ec3266c] (rid 654) by dmestas on 2026-08-17 19:35:29:
- comment initialized to:
Diffs are the page a forge lives or dies by, and ours is the weakest thing we render. The whole renderer is `classifyDiff` (internal/web/web.go:1217): twenty lines that prefix-match each line of a unified diff and tag it `add`/`del`/`hunk`/`head`/`ctx`. Nothing else happens. ## What that costs, concretely From `/r/pikchr/checkin/a7f1c35bc044.../diff`: - /* Remove leading and trailing whitespace from each argument. + /* Remove leading and trailing whitespace from each argument (including Only `(including` was added. The reader gets two fully-coloured lines and has to diff it by eye. Same hunk, a few lines down, a `while` condition gains one set of parentheses and reads as a wholesale replacement. The specific gaps: - **No syntax highlighting.** chroma is vendored and already highlights the file page (internal/api/register.go:1837). The diff page never calls it, so every diff is monochrome regardless of language. - **No intra-line diff** at word or character granularity — the case above. - **No line numbers.** You cannot say "look at 5223". - **`+`/`-` are in the text, not a gutter**, so copying a hunk copies the markers. - **Raw unified-diff chrome** (`--- a/pikchr.y`, `+++ b/pikchr.y`) instead of a file header. - **No context expansion**, no per-file navigation for a multi-file changeset, no unified/split choice. ## This is an API problem, not only a template problem `checkin.diff` (internal/api/register.go:1754) returns: type diffGetOut struct { From, To string Files []zitcli.DiffEntry Unified string // <- the entire diff, as one opaque blob Note string } Principle 5 says a feature is not done until its full capability is in the API, and that the HTML and the API share one query layer. A structured diff has to land in the **op**, or we build a good page on top of a string and the API stays screen-scrape-only. `Unified` should remain (it is what a script wants) but stop being the only shape. ## Proposed model Build it in Go. The factoring below is adapted from @pierre/diffs' public types (Apache-2.0) — worth borrowing because it survived a second, wildly different renderer (see references), which is the real evidence that the model is separable from the markup: type FileDiff struct { Path, PrevPath string Change ChangeKind // change | new | deleted | rename-pure | rename-changed Binary bool Hunks []Hunk } type Hunk struct { OldStart, OldLines, NewStart, NewLines int Header string // the text after @@ … @@ Lines []Line } type Line struct { Kind LineKind // context | addition | deletion | expanded | metadata OldNum, NewNum int // 0 when the side has no number Tokens []Token // syntax tokens, positional Spans []Span // intra-line changed ranges, in byte offsets } type Token struct { Col int; Class string; Text string } Two details carried over deliberately: 1. **A token is positional — `(column, class, text)` — not nested markup.** This is what makes the whole thing tractable, and it is the one idea worth taking above all others. 2. **Rename is split into `rename-pure` and `rename-changed`.** A pure rename should not render a diff body at all. ## The hard part Syntax highlighting and intra-line diff both want to emit spans over the same text, and they do not nest: a changed range routinely starts and ends mid-token. Pierre resolves this by keeping highlight output positional and splicing at render time; that is why hunk can drive the same model into a terminal grid. We can do the same directly, because chroma hands us tokens rather than only HTML (internal/highlight/highlight.go:41): it, err := lexer.Tokenise(nil, string(code)) That iterator yields `chroma.Token{Type, Value}`. The pipeline: 1. Parse the unified diff into files/hunks/lines (replacing `classifyDiff`). 2. Pair each deletion run with its addition run; compute a word-level diff over each pair to get changed byte ranges. 3. Tokenise each line with chroma, tracking byte offsets. 4. Split tokens at diff-range boundaries so every emitted span carries exactly one syntax class and one change state. 5. Render through the existing sanitizer gate, as `highlight.Code` already does. Step 2 needs a word-level diff. Either a small dependency or a Myers pass over word tokens — decide when we get there, not now. ## Scope In: - structured diff in the op, `Unified` retained - syntax highlighting via chroma, reusing the existing class-based stylesheet - word-level intra-line marking - line numbers, and `+`/`-` moved to a gutter so selection copies clean code - proper file headers with the change kind, and per-file navigation - context expansion Out, deliberately: - **Line-anchored review comments.** 0002 §1 makes this an explicit divergence: conversations anchor to artifacts, and the UI says "discuss this check-in", not "review". Pierre models annotations; we are not taking them. - **Merge-conflict rendering.** Pierre models conflict marker rows. Not a forge-display concern for us. - **Structural/AST diffing.** hunk's own comparison notes only difftastic does this. Out of scope, and worth a separate ticket if ever wanted. - **Adopting @pierre/diffs or hunkdiff as dependencies.** Measured: @pierre/diffs has no dependency-free entry point — even `./ssr` is 115 files / 492 KB and needs Shiki, a WASM-Oniguruma highlighter with TextMate grammars. That means Node in the build plus a second highlighter, to get what we can build on the one already in the binary. hunkdiff is 19.6 MB and targets a terminal via OpenTUI. ## References - @pierre/diffs — Apache-2.0, v1.3.5, https://diffs.com/ — the reference implementation and the source of the model factoring above. Reading its `dist/types.d.ts` is the fastest way into the design. - hunk / hunkdiff — MIT, v0.19.0, https://hunk.dev/, https://github.com/modem-dev/hunk — a terminal diff viewer that pins `@pierre/[email protected]` and renders it via OpenTUI. Useful as proof the model is render-target-agnostic, and its feature list (split/stack responsive layout, multi-file review stream, sidebar navigation) is a good requirements checklist. Licensing note: both are permissive and compatible. If we adapt anything concrete from either — type factoring, CSS metrics, layout values — it needs a `third_party/PROVENANCE.md` row, the way fossil's `default.css` metrics already carry one. No code should cross; this is the same [MAP]-not-[COPY] relationship 0002 §1 defines. - status initialized to: "Open"
- title initialized to:
Rebuild diff rendering: structured model, syntax highlighting, word-level marking
- comment initialized to:
Ticket change [264e97a683] (rid 858) by dmestas on 2026-08-18 18:40:05:
- Untracked field cmimetype: "text/x-markdown"
Ticket change [99620115d3] (rid 1077) by dmestas on 2026-08-19 11:04:35:
- priority changed to: "Medium"
- severity changed to: "Important"
- type changed to: "Feature_Request"
Ticket change [3e6f39a837] (rid 1127) by dmestas on 2026-08-19 12:10:50:
- subsystem changed to: "web"
Ticket change [1c92435560] (rid 1272) by dmestas on 2026-08-19 21:57:37:
- icomment:
Built (cc6091b1), on the model this ticket specified. **internal/diff** — the Pierre-factored model in Go: FileDiff (change kind: change/new/deleted, /dev/null recognised), Hunk (starts + header), Line (kind + old/new numbers), and POSITIONAL tokens — one syntax class and one change state per span, the one idea worth taking above all others. Intra-line marking is an LCS over word tokens (letters/digits vs punctuation split separately, so a paren edit marks the paren, not the word beside it), with the rewrite guard: lines sharing under a third of their words mark NOTHING — a fully-marked pair says less than plain colour. The chroma splice tracks byte offsets and splits tokens at mark boundaries; a reassembly test pins that the splice never loses or duplicates a byte. **The op** — checkin.diff gains `structured` (files/hunks/lines/ tokens); `unified` remains for scripts. Principle 5 held: the page renders the same shape the API serves. **The page** — per-file sections with change-kind headers and the file list doubling as anchor navigation; hunk headers with the @@ context; line numbers and the +/- marker in user-select:none gutters so copying a hunk copies clean code; syntax classes riding the chroma stylesheet already on every page; marks as tinted ranges inside add/del rows. **Verified on the ticket's own case** — pikchr a7f1c35b: `(including` is a marked span, everything else on that line is not; 13 marked ranges across the changeset; gutters number from 5220. A Go diff carries full syntax (1.4k identifier spans, keywords, strings). pikchr.y itself gets structure and marks but plain tokens — chroma has no yacc lexer; degrade-to-plain is the designed behavior. **Remainders, honestly:** context expansion (needs a new op serving file lines at a revision plus an expand affordance) and a unified/ split toggle — both listed in the original gaps, neither in this pass. Line-level chroma also cannot see multi-line constructs (a string spanning lines tokenises per-line); the price of not fetching whole files, degrades to plain.
- mimetype: "text/x-markdown"
- status changed to: "Review"
- icomment:
Ticket change [b5d4596dde] (rid 1744) by ai-local on 2026-08-22 02:11:46:
- priority changed to: "Low"
Ticket change [e229874727] (rid 1745) by ai-local on 2026-08-22 02:12:40:
- priority changed to: "Medium"
Ticket change [e7222d5032] (rid 2106) by ai-local on 2026-08-23 10:22:02:
- icomment:
Shipped. The diff is a structured model now: per-line number, mark and code cells, chroma syntax highlighting, and word-level marking inside a changed line. Verified live on /r/pikchr/checkin/a7f1c35bc044/diff.
- mimetype: "text/x-markdown"
- resolution changed to: "Fixed"
- status changed to: "Closed"
- icomment:
Ticket change [cf6d04b1a8] (rid 12445) by zeitgeist on 2026-09-24 00:52:42:
- Untracked field number: "10"