Captain UI

Diff review

Review an agent's diff one hunk at a time. Drag along a changed line and the old code rewrites into the new, letter by letter under your finger; let go and it rewinds. Fling the hunk right to accept or left to reject, or press A and R.

npx shadcn@latest add @captain/diff-review
Pro
1 accepted0 rejected2 leftApplying +4 −0
billing/invoice.ts totalFor()+1 −1
41 const subtotal = lines.reduce((s, l) => s + l.amount, 0);
42− return Math.round(subtotal * 100) / 100;
42+ return roundHalfEven(subtotal, 2);
billing/rounding.ts roundHalfEven()+4 −0
api/routes/invoices.ts GET /invoices/:id+1 −1
18 const inv = await db.invoice.find(id);
19− res.json({ ...inv, total: inv.total.toFixed(2) });
19+ res.json({ ...inv, total: formatMoney(inv.total, inv.currency) });

Usage

import { DiffReview } from "@/components/ui/diff-review"

<DiffReview hunks={hunks} onValueChange={setVerdicts} />

Props

PropTypeDefaultWhat it does
hunksHunk[]{ id, file, header, lines: { type: add | del | ctx, text, n }[] }.
valueRecord<string, Verdict>Controlled verdicts by hunk id: accepted or rejected.
defaultValueRecord<string, Verdict>Initial verdicts when uncontrolled.
onValueChange(v) => voidCalled on every swipe, key or undo.
thresholdnumber96Swipe distance that decides. A fast flick decides sooner.
hintbooleanfalsePlay the scrub once on the first changed line, to teach the gesture.

Keyboard

← →
Scrub the focused changed line, a letter at a time (Shift for five)
A
Accept the focused hunk
R
Reject it
U
Undo a decided hunk
↑ ↓ or J K
Move between hunks

Accessibility

  • Each hunk is a focusable group labelled with its file, change counts and verdict.
  • Swiping is optional: A, R and U do the same, and focus moves to the next open hunk.
  • A changed line is a slider: arrows rewrite it a letter at a time and its value reads how far the new line has been written.
  • Where a drag starts decides it: on a changed line it scrubs, anywhere else on the hunk it flings. Vertical drags scroll the page as usual.
  • The tally is a polite live region.