Skip to content

feat(serve): add review diff view with word highlights and risk-ordered change lanes (STA-395) - #257

Merged
SutuSebastian merged 6 commits into
mainfrom
agent/sta-395-serve-diff-lanes
Nov 24, 2026
Merged

SutuSebastian merged 6 commits into
mainfrom
agent/sta-395-serve-diff-lanes

Conversation

@SutuSebastian

Copy link
Copy Markdown
Contributor

Summary

Implements STA-395: adds a pure-Go review diff engine (internal/diff), deterministic risk-ordered change lanes, anchored findings, server-computed word-level highlights, and a verdict serve Diff tab (unified + side-by-side) with dark-mode support and static report --html snapshot export.

What changed

  • Pure-Go diff engine (internal/diff, stdlib-only, zero new deps):
    • Unified full.diff parser with active hunk-remainder tracking (content lines beginning with -- , +++ , --- , index , rename, copy never corrupt metadata; \ No newline at end of file handled cleanly).
    • Deterministic histogram line diff with Myers fallback, xdiff cost limit, earliest-position tie-break, and Git's indent heuristic (DiffLines), verified against real git diff --diff-algorithm=histogram hunks.
    • Bounded contiguous-block intraline word spans (PairWordSpans) and collapsed unchanged-line gap tracking (gap_before).
    • Deterministic 9-lane classification (schema, source, config, tests, docs, generated, lockfiles, renamed, whitespace) in risk order with case-insensitive config bases (Makefile/Dockerfile), collapsed-whitespace detection, and Windows \ path normalization.
  • Query layer, verdict serve route, & HTML export (internal/core/query/diff.go, internal/serve/):
    • Added Layer.Diff over root-confined full.diff + findings.json with data.sources[] traceability, partial/errors[] propagation on oversized/unreadable diffs, anchored findings (json.Number line support), and deterministic sorted by_lens counts.
    • Added read-only GET /v1/roots/{root}/bundles/{bundle}/diff (works without --interactive, guarded by s.guard, full HTTP test matrix in internal/serve/diff_test.go) and static export support in internal/serve/export.go.
  • Embedded Web UI (internal/webui/static/):
    • Added Diff tab with Unified / Side-by-Side toggle, lane summary table, word-level highlights, … N unchanged lines collapsed gaps, anchored finding cards, and dark-mode CSS custom properties (48,045 / 98,304 bytes, zero innerHTML/eval/inline code, 28/28 app.test.mjs passing).

Verification

  • S5 independent review (DeepSeek Flash max R1 → Muse Ember Fix R1 → DeepSeek Flash max R2 → Muse Ember Fix R2 → DeepSeek Flash max R3 APPROVE, with independently reproduced mutation proofs for indent sliding, git histogram hunk parity, deterministic anchor tie-break, word spans, gap_before, and by_lens order).
  • 158/158 evals (make evals), full go test -race -shuffle=on -count=1 ./... green, make build, make vet, make deadcode (0 new), make schemas-check, cmd/tsgen & gen-ts-types.mjs --check current, make cross (6/6), make size (all 6 targets ≥8 KB headroom), golangci-lint run ./... (0 issues), bun test (28/28), gofmt -l . empty.

Closes STA-395 (and unblocks STA-493 Tier C --allow-post).

…ane (STA-395)

Pure-Go diff engine in internal/diff (stdlib only): unified full.diff
parser, histogram line diff with Myers fallback and an indent heuristic,
word-level intraline spans, collapsed-gap tracking, and deterministic
9-lane classification in risk order. Query layer Diff composes lanes,
files with word spans, anchored findings, and sources from the confined
bundle; GET /v1/roots/{root}/bundles/{bundle}/diff serves it read-only
and report --html snapshots it. Embedded UI gains a Diff tab with
unified/side-by-side toggle, lane table, word highlights, collapsed gaps,
and anchored findings (all DOM via createElement/textContent).

Size (make size, narrowed ceilings raised to next 10 kB with headroom):
darwin/amd64 20262784 (budget 20280000), darwin/arm64 18381506
(18390000), linux/amd64 19923104 (19940000), linux/arm64 17957024
(17970000), windows/amd64 20351488 (20360000), windows/arm64 18119680
(18130000); deps 0.
- Resolve scripts/size-baseline.txt: taking STA-395 ceilings (max)
- Merges STA-468 azure-post changes, docs/manual.md auto-merges cleanly at separate hunks with zero conflict markers

Byte ceilings in this merge:
- Proceeding to measure sizes; final ratchet updated in follow-up Fix R1 commit.
B1 toInt handles json.Number (UseNumber): added json.Number/float64 cases matching budget.go, sorted by_lens keys deterministically, added query + HTTP tests writing real findings.json and asserting anchored findings (path/line/side) and non-zero findings/by_lens.

B2 parser hunk tracking: added oldRem/newRem from @@ headers; while in hunk lines starting with +,-,space or single-backslash are content never metadata (---/+++/index/rename/copy). Fixed double-backslash raw literal to single-backslash. Fixture tests for -- sql comment, +++ x, --- a/fake inside hunk, index inside hunk, diff-of-a-diff, single-backslash marker, hunk count expiry.

B3 histogramAnchor determinism: scan a in index order with earliest-position tie-break (total then pa then pb) instead of Go map iteration; test runs 64 tied inputs asserting one exact literal edit script EQ[a,b,a,b] DEL[x] INS[y] EQ[a,b].

B4 readDiffText/diff.Parse errors propagate to partial:true and errors[] via errRow; loadDiffFiles now returns ErrRows with diff-too-large/diff-missing/diff-parse-error codes, buildDiffView/diffPayload wire partial and errors. Tests for oversized (11MiB) and missing full.diff assert partial true + non-empty errors.

B5 git histogram parity: TestDiffLinesHistogramMatchesGit now compares deleted/added texts per @@ hunk against real git diff --diff-algorithm=histogram on multi-case corpus (simple, inserts, deletes, replace, dupes, blankSlide); trivial delete-all fails both parity and count minimality, proving real hunk-boundary check. TestIndentationHeuristicSlides now exercises production DiffLines (flipping linesDiff to false fails). TestDiffWordPassMutation proves word pass via anySpans.

B6 lane classification: isConfigBase uses lowercase/EqualFold-style switch so Makefile/Dockerfile/Dockerfile.dev/cmd/Makefile classify as config (pinned literal), stripSpace collapsed to Join(Fields," ") so indentation/multiple/trailing-space edits stay whitespace while msg:=\"a b\"->\"ab\" stays source (pinned both), WhatsApp separators normalized \\->/ for path lanes (pinned).

B7 word spans: PairWordSpans flushes on context lines, pairing only contiguous del run immediately followed by add run inside a block; cross-boundary del/ctx/add gets unpaired all-changed spans, proven by del alpha one / ctx separator / add beta two test asserting single-span unpaired.

B8 HTTP diff_test.go mirrors compare: 200 + serve envelope + lanes order + collapsed gap + anchored finding from real findings.json (json.Number line 1 RIGHT), works with interactive OFF, POST 405, missing token 401, foreign Origin 403, unknown bundle 404.

B9 dark mode: diff backgrounds (#d9f2e2 etc) moved to :root custom properties and @media dark overrides matching --ink #e7edf2 contrast; no hardcoded hex in component rules; TestUIBudget/TestCSPAssets clean.

Also: remove unused DiffView alias; docs/manual.md sources[] wording now view-level + anchored findings/by_lens; size ratchet next-10kB with >=8192 headroom.

Measured binary sizes (release -s -w):
darwin/amd64 20365872 -> budget 20380000 (14128 headroom)
darwin/arm64 18464786 -> budget 18480000 (15214 headroom)
linux/amd64 20025504 -> budget 20040000 (14496 headroom)
linux/arm64 18022560 -> budget 18040000 (17440 headroom)
windows/amd64 20457984 -> budget 20470000 (12016 headroom)
windows/arm64 18209280 -> budget 18220000 (10720 headroom)

UI static total 48045 bytes well under 96KiB (98304).

Mutation proofs:
- indent heuristic: DiffLines equals LinesWithHeuristic(true) and not false (flip fails)
- git histogram: delete-all/insert-all fails hunk parity and count minimality
- word pass: dropping PairWordSpans fails TestDiffWordPassMutation (anySpans false)
# Conflicts:
#	scripts/size-baseline.txt
… determinism pin, manual polish

F1: diffFixtureFiles gains a second hunk (@@ -40) and two anchored
findings on lenses alpha/zeta; TestDiffRoute asserts hunks[1].gap_before
== 37 (40 - (1+2)) exactly and that by_lens keys render alpha before
zeta in the raw envelope body.

F2: TestHistogramDeterminismAnchorSensitive pins the tied pair
a=[a a a a a b] b=[b a b b b b]: histogramAnchor returns "a" (both
totals 6, earliest position breaks the tie) and DiffLines returns the
exact literal INS[b] EQ[a] DEL[a,a,a,a] EQ[b] INS[b,b,b] across 64
runs. Mutation-checked: flipping the tie-break to pick "b" fails the
new test at the anchor assertion, then reverts green.

Polish: manual Review diff now says data.sources[], keeps by_lens
lane-level, and notes line-less findings are excluded from lane
counts and row anchors (per addFinding). No-newline marker comment
reframed as a style/parser pin.

Size re-measure (growth is STA-395 serve layer + merged PRs #251
STA-469 + #254 STA-341; each ceiling raised to the next 10 kB with
>=8192B headroom): darwin/amd64 20525456, darwin/arm64 18617330,
linux/amd64 20181152, linux/arm64 18153632, windows/amd64 20615680,
windows/arm64 18351616, deps 0.
Merge STA-423 fix --recipe (7c13a29) into STA-395 diff view
(4b555e0). docs/manual.md auto-merges with both the diff-view
(by_lens, gap_before) and fix --recipe sections intact; only
scripts/size-baseline.txt conflicts, resolved by taking the higher
ceiling per platform then measuring the merged binary.

Measured sizes (make size, -s -w, version 0.0.0):
- darwin/amd64: 20541936 bytes → ceiling 20560000
- darwin/arm64: 18633970 bytes → ceiling 18650000
- linux/amd64: 20197536 bytes → ceiling 20210000
- linux/arm64: 18153632 bytes → ceiling 18170000 (unchanged, 16368 headroom)
- windows/amd64: 20633088 bytes → ceiling 20650000
- windows/arm64: 18367488 bytes → ceiling 18380000
All ceilings raised only to the next 10 kB boundary leaving >=8192
bytes headroom after merge growth.
@coderabbitai

coderabbitai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 10 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 7c13a29 and effbe3e.

Files selected for processing: 18

  • .changeset/sta-395-serve-diff-lanes.md
  • docs/manual.md
  • internal/core/query/diff.go
  • internal/core/query/diff_test.go
  • internal/diff/diff.go
  • internal/diff/diff_test.go
  • internal/diff/lanes.go
  • internal/diff/lanes_test.go
  • internal/diff/lines.go
  • internal/serve/diff_test.go
  • internal/serve/export.go
  • internal/serve/routes.go
  • internal/serve/serve.go
  • internal/serve/serve_test.go
  • internal/webui/static/app.css
  • internal/webui/static/app.js
  • internal/webui/test/app.test.mjs
  • scripts/size-baseline.txt
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@SutuSebastian
SutuSebastian merged commit 50ee115 into main Nov 24, 2026
21 checks passed
@SutuSebastian
SutuSebastian deleted the agent/sta-395-serve-diff-lanes branch November 24, 2026 09:45
SutuSebastian added a commit that referenced this pull request Nov 24, 2026
Merge commit resolving scripts/size-baseline.txt conflict, taking the
higher (larger) baseline for each platform from both sides:
darwin/amd64 20560000, darwin/arm64 18650000, linux/amd64 20210000,
linux/arm64 18170000, windows/amd64 20650000, windows/arm64 18380000.
docs/manual.md auto-merged cleanly with no conflict markers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant