Captain UI

Diff review

Review an agent's diff one hunk at a time. Swipe right to accept, left to reject, or press A and R; the hunk follows your finger, tilts as you throw it, and the tally keeps count.

npx shadcn@latest add @captain/diff-review
Pro
1 accepted0 rejected2 leftApplying +1 −1
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
1+export function roundHalfEven(x: number, dp: number) {
2+ const f = 10 ** dp, n = x * f, r = Math.round(n);
3+ return (Math.abs(n % 1) === 0.5 ? 2 * Math.round(n / 2) : r) / f;
4+}
api/routes/invoices.ts GET /invoices/:id+1 −1

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.

Keyboard

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.
  • The tally is a polite live region. Vertical drags scroll the page as usual.