Components
DiffReview
Accept or reject an agent’s edits hunk by hunk, across files, and get the patched files back.
Example
Review changes
4 files · 4 hunks · +21 −1
Comment On line 7
Read the window from an env var, so staging can use a longer one.
2/6 reviewed · 0 of 4 files viewed · 1 comment · unreviewed hunks are skipped
Keyboard: J or K to move between hunks, Shift J or Shift K between files, A to accept, R to reject, U to reset, Alt A or Alt R for the whole file, Shift A or Shift R for every hunk, Shift with the up or down arrow to select lines, C to comment on them or on the hunk, E to show more unchanged lines, V to mark the file viewed, Ctrl Enter to apply.
Interactive, and the same on the components page. Try the keyboard below on it.
Installation
npm i signoff-ui aiimport { DiffReview, reviewToolOutput } from 'signoff-ui';
// Once per app (with Tailwind v4: @import 'signoff-ui/tailwind.css'; in your CSS)
import 'signoff-ui/styles.css';npx shadcn@latest add https://signoff-ui.vercel.app/r/diff-review.jsonimport { DiffReview } from '@/components/signoff-ui/diff-review';The styles are once per app; Getting started has the Tailwind v4 and plain CSS options.
Usage
<DiffReview
files={[{ path: 'app/api/chat/route.ts', oldContent, newContent }]}
// The agent gets each file as applied, the rejected hunks and every comment.
onSubmit={(result) =>
addToolOutput({ tool: 'review_changes', toolCallId, output: reviewToolOutput(result) })
}
/>How it works
Unified or split review of agent edits across files, with word-level highlights. Give it the old and new contents of each file, or a unified patch when you only have the diff, and it computes the hunks. The reviewer accepts or rejects each hunk or a whole file, comments on lines or hunks, marks files viewed and applies, and the agent gets back what it needs to act on.
What the agent gets back
onSubmit(result, { toPatch }) receives:
files: each file'sdecision(accepted,rejected,partial,pendingorunchanged), whether it was markedviewed, and itscontentwith only the accepted hunks applied, unreviewed ones left out. Each file also carries the ids of the hunks accepted, rejected or left pending.rejectedHunks: each rejected hunk with its lines, so the agent knows what not to do again.comments: each with its file, its line range (side,startLine,endLine, andoldStartLineandoldEndLinefor removed lines among lines of the proposed file), its text and the lines it is on (excerpt).toPatch(): the accepted changes as a git-style unified diff, whichgit applyreads.
reviewToolOutput(result) shapes that for the model. It gives a one-sentence summary, each file's decision with its applied contents, the rejected hunks, the comments and decisions, each decided hunk by id. A file the reviewer marked viewed has viewed: true, and the others have no viewed key, so the output stays small. Pass { contents: false, patch: toPatch() } to send a patch instead of contents. It is plain JSON, so it is an AI SDK tool output as it is: addToolOutput({ tool: 'review_changes', toolCallId, output: reviewToolOutput(result) }). For an AG-UI agent paused on an interrupt, reviewResumeEntry(interrupt.id, result) is the resume entry, with the same payload: pass it to useAgUiAgent's resolve.
To show a review again from its saved output, after a reload say, render it read-only with the same files and decisions={decisionsFromToolOutput(output)}: each hunk shows as it was decided. ReviewToolUI does this for assistant-ui. Only the decisions are shown again: the output's viewed marks and comments are there for the agent, and the review shown again has none. An output saved by an earlier version has no decisions, and shows every hunk undecided.
The review is sent once per state of the review. A double click or a repeated ⌘ or Ctrl + Enter sends one review, until a decision, a comment, a viewed mark or the files change. Files compare by content, so an inline files array does not count as a change. When onSubmit returns a promise, the review announces "Review sent" once it resolves and nothing if it rejects, so say what failed yourself; Apply works again once it settles.
Decisions are keyed by a hunk's position in its file, so when the agent revises a file under the same review, the review of that file starts over. Its decisions, viewed mark, fold and comments are dropped, with any lines selected or a comment being written on it, because they were about the old edit. Other files keep theirs. If you control decisions, viewed or comments, the review reads them without that file's entries and calls onDecisionsChange, onViewedChange and onCommentsChange once without them. It leaves them out for as long as you pass the same entries for that file, whether you keep the value in state, build it on every render (decisions={{ ...decisions }}) or copy it in the update that brings the new files. Entries for that file that change in the same render as the new files are taken as meant for the new edit, such as the decisions saved with another review, and are kept. To start the whole review over, give it a new key, such as the revision's id.
Comments
Select lines from a hunk with Shift and the up or down arrow: down starts at its first changed line, up at its last. Or click a line number and Shift-click another. C comments on the selected lines, or on the whole hunk when none are selected, and the hunk's comment button does the same. ⌘ or Ctrl + Enter saves the comment and Escape cancels it. Lines are numbered in the proposed file, or in the original when only removed lines are selected (side: 'old'), and the comment's field, buttons and announcement name them so: "Comment on line 21 of the original". Removed lines selected with lines of the proposed file are numbered in the original too (oldStartLine, oldEndLine), so they stay in the comment and in its excerpt. Control comments with comments and onCommentsChange, or start from defaultComments.
Files
A review of several files lists them first. The list is one tab stop: the arrow keys move between files and Enter goes to one. Any file can be accepted or rejected whole, with its buttons or with Alt + A and Alt + R. A file can be marked viewed with its checkbox, or with V, which also moves to the next file. A viewed file folds away (collapseViewed={false} keeps it open), and viewed and onViewedChange control the marks. A renamed file shows its old path, from oldPath or from a git rename patch (rename from, which git diff writes by default). A binary file reads "Binary file, not shown": it is detected from a NUL character in its contents or from a binary patch, or set with binary. A file the review can't read shows the same way, so the other files stay reviewable: a patch whose hunk counts don't match its lines or with a line that doesn't start with +, - or a space, as models write them, or contents that aren't strings. Binary and unreadable files, renames without changes, and files created or deleted empty are each decided as a whole, under the id `${path}:file`. Put a review of a model's tool input inside an error boundary all the same: files that is not an array of objects still fails the render.
Context
Unchanged lines between hunks can be shown, 20 at a time or all at once, from the bar between hunks or with E around the focused hunk. That needs both contents: a patch alone has no lines outside its hunks.
Large files
Large files stay responsive. A file that needs more than a few hundred edits is diffed in a worker and reads "Comparing changes…" until it is done; Apply waits for it. Webpack 5, Next.js and Vite emit the package's worker without configuration. diffWorker takes a function that starts your own worker, or false to diff on the main thread after the first paint. A file changed in more places than maxEditLength (2,000 lines added plus removed) is reviewed as one hunk that replaces the changed region, and the review says so. A long review renders only the rows near the screen, and so do unchanged lines shown between hunks, past their first 100. The rest keep their height and their text for screen readers, and every hunk stays in place for focus and for J and K: past the first 100, hunks render 100 at a time, and the one J or K moves to renders at once. A line over 2,000 characters shows as plain text, without syntax colors. Performance and limits has the numbers.
Your own buttons
actions puts your controls in the header, next to the layout toggle: actions={<button onClick={copyPatch}>Copy as a patch</. They are your content, in a data-signoff-slot element, so styles.css leaves them to your CSS. Keys pressed on them, or in a menu they open, are theirs: J, K, A, R, ⌘ or Ctrl + Enter and the review's other shortcuts don't act from there. Pass nothing, null or false and the header stays as it was.
Your own markup
useDiffReview is all of this without the markup. It gives the files, decisions, comments, selection, viewed marks and shown context, and the keyboard. It also gives getters for items, buttons, the comment editor and a file navigator.
On the server
parseFileChange, applyHunks, computeReviewResult, toPatch, reviewToolOutput, decisionsFromToolOutput and reviewResumeEntry are in signoff-ui/core, with no React. A server render diffs the files a render may diff, and shows the rest as being compared, so hydration matches. Long changed lines skip word-level highlights rather than stall.
API reference
Generated from the types the package ships, so it matches the version you install.
DiffReview
Review agent file edits hunk by hunk, in unified or split view, with word-level highlights, and send back what was accepted, what was rejected and what the reviewer said about it.
Keyboard: J/K or the arrows move between hunks and Shift+J/K between files; A accepts, R rejects, U resets, Alt+A / Alt+R decide the file and Shift+A / Shift+R everything; Shift+arrows select lines and C comments on them (or on the hunk); E shows more context; V marks the file viewed; ⌘/Ctrl+Enter applies.
Large files stay responsive: a big diff is computed in a worker while the file shows
"Comparing…", one past maxEditLength becomes a single replacing hunk, and long reviews
render only the rows near the screen. For your own markup, useDiffReview is this component's
state and keyboard without it.
Props
filesrequiredreadonly FileChange[]The edits to review, one per file, with full contents (
oldContentandnewContent) or a unifiedpatch. Compared by content: a new array of the same edits, such as one written inline, is not diffed again. A file whose contents change starts its review over: its decisions, viewed mark and comments are dropped, and controlled ones are reported without them.titleReactNodeDefault'Review changes'Heading. Without one, the review uses
labels.diffReview.title.actionsReactNodeYour own controls in the header, next to the layout toggle, e.g. a "Copy as a patch" button. Your content, like
AgentMessage'srenderTool: it sits in adata-signoff-slotelement, and keys pressed in it are yours, not the review's shortcuts.viewDiffViewModeThe layout, controlled:
unified, one column, orsplit, the original and the proposed file side by side. PassonViewChangewith it to follow the layout toggle.defaultViewDiffViewModeDefault'unified''unified' | 'split'The layout to start with, when the review keeps its own.
onViewChange(view: DiffViewMode) => voidCalled with the layout the reviewer picks with the layout toggle.
submitLabelstringThe apply button's text. Default "Apply 2 of 5", or "Apply changes" before any is accepted (
labels.diffReview.apply).readOnlybooleanDefaultfalseHide review controls, e.g. once the review has been submitted.
contextnumberDefault3Lines of context around each change.
maxEditLengthnumberDefault2000Past this many lines added plus lines removed in one file, its changed region (from the first changed line to the last) is shown as one hunk that replaces it, and the review says so. Diffing costs about the square of this number.
autoAdvancebooleanDefaulttrueAfter accepting or rejecting with the keyboard, move to the next undecided hunk.
collapseViewedbooleanDefaulttrueFold a file away once it is marked viewed.
headingLevelHeadingLevelDefault3Heading level for the title, to fit your document outline.
onSubmit(result: DiffReviewResult, review: { toPatch: () => string; }) => void | PromiseLike<void>Called with the reviewed result, and a
toPatchthat gives the accepted changes as a unified diff. Pending hunks are not applied. Fires once per review state, so a double click or a repeated ⌘/Ctrl+Enter sends one review: submitting again needs a changed decision, comment or viewed mark, changedfiles, the returned promise to settle, or the handler to throw. Files compare by content and the rest by value: an equal new array or object does not count as a change.decisionsReadonly<Record<string, HunkDecision>>Controlled decisions keyed by item id: a hunk's
${path}:${index}, or${path}:filefor a file with no hunks (binary, renamed or empty). A repeated path gets${path}#2,#3and so on, skipping a suffix another file's path already has.defaultDecisionsReadonly<Record<string, HunkDecision>>The decisions to start with, keyed like
decisions, when the review keeps its own: to restore a review in progress, say. Read on the first render only.onDecisionsChange(decisions: Record<string, HunkDecision>) => voidCalled with every decision, keyed like
decisions, whenever one changes: an item accepted, rejected or reset, or a whole file or the whole review decided at once.commentsreadonly DiffReviewComment[]Controlled comments.
defaultCommentsreadonly DiffReviewComment[]The comments to start with, when the review keeps its own. Read on the first render only.
onCommentsChange(comments: DiffReviewComment[]) => voidCalled with every comment whenever one is added, edited or removed.
viewedReadonly<Record<string, boolean>>Controlled "Viewed" marks, by file id (the path, or
path#2… for a repeated path).defaultViewedReadonly<Record<string, boolean>>The "Viewed" marks to start with, by file id, when the review keeps its own. Read on the first render only.
onViewedChange(viewed: Record<string, boolean>) => voidCalled with every "Viewed" mark, by file id, whenever one is set or cleared.
diffWorkerDiffWorkerFactory | falseWhere files too large to diff while rendering are diffed: by default in the package's own worker, which bundlers with worker support emit (webpack 5 and Next.js, Vite, Parcel). Pass a function that starts your own
Workerrunningsignoff-ui's diff worker, orfalseto diff them on the main thread after the first paint. Without a working worker the latter is the fallback.labelsSignoffLabelsInputWords to use instead of the English defaults, for what the hook announces and names: see
SignoffLabelsProvider.
Other props go to the root <section>: className (merged with tailwind-merge), id, aria-*, data-* and event handlers.
FileChange
A file edit proposed by an agent. Provide either full contents or a unified patch.
pathrequiredstringThe file's path, e.g.
app/api/chat/route.ts: the review shows it and the result returns it. Its extension picks the highlighting, unlesslanguageis given.oldPathstringPrevious path, for renames. Read from a git rename
patchwhen omitted.oldContentstringOriginal file contents. Omit (or pass '') for new files.
newContentstringProposed file contents. Omit (or pass '') for deletions.
patchstringA unified diff for this file, used when contents are not available.
languagestringLanguage id for highlighting, inferred from the extension when omitted.
binarybooleanA binary file: shown as "Binary file, not shown" and decided as a whole. Detected when omitted: contents with a NUL character in their first 8,000, or a patch that says
Binary files … differ.
DiffReviewResult
What onSubmit gets: each file as reviewed, the decisions counted, the rejected hunks and the
comments. reviewToolOutput shapes it for the agent.
filesrequiredDiffReviewFileResult[]Each file in the review, in the order of
files: its decision, its contents as applied and its item ids.acceptedrequirednumberHow many items were accepted, across the review: hunks, and files with no hunks (decided as a whole).
rejectedrequirednumberHow many items were rejected, counted like
accepted.pendingrequirednumberHow many items were left undecided, counted like
accepted.rejectedHunksrequiredDiffReviewRejectedHunk[]Each hunk the reviewer rejected, with its lines, so the agent knows what not to do, including every hunk of a file or a review rejected at once (Alt+R rejects each hunk of the file). A file with no hunks (binary, a rename, an empty file) is decided as a whole and appears only in its file's
rejected.commentsrequiredDiffReviewResultComment[]Every comment, with the lines it is on (
excerpt) when they are in the review.
DiffReviewFileResult
One file of a DiffReviewResult: how it came out of the review.
pathrequiredstringThe file's path, as in its
FileChange.statusrequiredFileStatus'added' | 'deleted' | 'modified' | 'renamed'What the edit does to the file:
added,deleted,modifiedorrenamed.decisionrequiredFileDecision'accepted' | 'rejected' | 'partial' | 'pending' | 'unchanged'acceptedwhen every change was accepted,rejectedwhen every one was,partialfor some of each or some left undecided,pendingwhen none was decided,unchangedwith nothing to decide.viewedrequiredbooleanMarked "Viewed" by the reviewer.
contentrequiredstringFile contents with only accepted hunks applied.
undefinedfor patch-only input.acceptedrequiredstring[]The ids of its accepted items: hunk ids, or
${fileId}:filefor a file with no hunks, decided as a whole.rejectedrequiredstring[]The ids of its rejected items, like
accepted.pendingrequiredstring[]The ids of its undecided items, like
accepted. They are not applied tocontent.oldPathstringThe path before, for a renamed file.
binarytruetruefor a binary file, which is decided as a whole; absent otherwise.
DiffReviewRejectedHunk
A hunk the reviewer turned down, with its lines, so the agent knows exactly what not to do.
idrequiredstringThe hunk's id,
${fileId}:${index}, as in the decisions.pathrequiredstringThe file's path.
headerrequiredstringThe hunk's header line in a unified diff, with where it starts and how many lines it spans in each file.
diffrequiredstringThe hunk as unified diff lines:
unchanged,-removed,+added.
DiffReviewComment
A reviewer's comment for the agent, on lines of a hunk, a whole hunk or a whole file.
idrequiredstringUnique within the review.
fileIdrequiredstringThe file's id in the review: its path, or
path#2… for a path that repeats.pathrequiredstringThe file's path, as in its
FileChange.targetrequired'lines' | 'hunk' | 'file'What it is on.
textrequiredstringWhat the reviewer wrote.
hunkIdstringThe hunk the lines are in, for
linesandhunk.sideCommentSideWhich file the line numbers count in: the proposed one (
new), or for removed lines only, the original (old). Absent for a comment on a whole file.startLinenumberThe first line it is on, numbered in the
sidefile. Absent for a comment on a whole file.endLinenumberThe last line it is on, numbered like
startLine.oldStartLinenumberWith
side: 'new', when removed lines are among the lines it is on: the first of them all that is in the original, numbered there. Removed lines have no number in the proposed file.oldEndLinenumberThe last line it is on that is in the original, numbered like
oldStartLine.
DiffReviewResultComment
A comment as the result carries it: with the lines it is on, when the review has them.
idrequiredstringUnique within the review.
fileIdrequiredstringThe file's id in the review: its path, or
path#2… for a path that repeats.pathrequiredstringThe file's path, as in its
FileChange.targetrequired'lines' | 'hunk' | 'file'What it is on.
textrequiredstringWhat the reviewer wrote.
excerptstringThe lines commented on, as unified diff lines, when they are in the review.
hunkIdstringThe hunk the lines are in, for
linesandhunk.sideCommentSideWhich file the line numbers count in: the proposed one (
new), or for removed lines only, the original (old). Absent for a comment on a whole file.startLinenumberThe first line it is on, numbered in the
sidefile. Absent for a comment on a whole file.endLinenumberThe last line it is on, numbered like
startLine.oldStartLinenumberWith
side: 'new', when removed lines are among the lines it is on: the first of them all that is in the original, numbered there. Removed lines have no number in the proposed file.oldEndLinenumberThe last line it is on that is in the original, numbered like
oldStartLine.
Extends DiffReviewComment.
FileDecision
How a file came out of the review. partial: some of its changes were accepted, not all.
type FileDecision = 'accepted' | 'rejected' | 'partial' | 'pending' | 'unchanged';HunkDecision
type HunkDecision = 'accepted' | 'rejected' | 'pending';DiffViewMode
type DiffViewMode = 'unified' | 'split';Accessibility
| Keys | Action |
|---|---|
| JK | Next or previous hunk (↓ and ↑ too, from a hunk) |
| ⇧J⇧K | First hunk of the next or previous file |
| A | Accept the hunk, and move to the next undecided one |
| R | Reject the hunk, and move on (X works too) |
| U | Reset the hunk |
| ⌥A⌥R | Accept or reject every hunk in the file (Alt on Windows and Linux) |
| ⇧A⇧R | Accept or reject every hunk |
| ⇧↓⇧↑ | Select lines in the hunk, from its first or last changed line |
| ↓↑ | With lines selected, move the selection by a line |
| Esc | Clear the selection, or cancel the comment being written |
| C | Comment on the selected lines, or on the hunk |
| ⌘/Ctrl↵ | In a comment, save it; elsewhere, apply the review |
| E | Show 20 more unchanged lines above and below the hunk |
| V | Mark the file viewed, fold it and go to the next file |
- A
<section>named by its title. Hunks use a roving tabindex, so the whole review is one tab stop that J, K and the arrows move through. - Each hunk is a group named like "Hunk 2 of 4, app/api/chat/route.ts, lines 12 to 20, accepted"; a file decided as a whole, like "Change 5 of 6, logo.png, binary file, not reviewed".
- Every shortcut is also a button: "Accept hunk 2", "Reject hunk 2", "Reset hunk 2" with
aria-pressed, "Comment on hunk 2", "Accept file app/route.ts", the "Viewed app/route.ts" checkbox, the layout toggle and Apply. Shortcuts only work while focus is inside the review, and not on your own controls inactions. - Selected lines are announced as they change, line by line: "Added: const ip = … Lines 15 to 17 selected." The comment editor is a labeled text area ("Comment on lines 15 to 17, for the agent") that takes focus, and focus returns to the hunk when it closes.
- The file list is a navigation landmark ("Files in this review") with one tab stop: the arrow keys, Home and End move through it, and each entry reads its path, how many changes are decided and whether it is viewed. A folded file has an expand button with
aria-expanded. - Line numbers and the buttons that show unchanged lines are clickable but out of the tab order (Shift and the arrows select lines, E shows context); the numbers are hidden from screen readers, which read the lines themselves.
- Progress, decisions, comments, viewed marks and shown context are announced: "Hunk 2 of 4 accepted. 2 remaining."
- Changed lines keep their + and − glyphs and are read as "Added:" or "Removed:", so cyan and magenta never carry the meaning alone.
- A long review renders only the rows near the screen. The rest keep their place as visually hidden text, read in the same order with the same "Added:" and "Removed:", and every hunk stays rendered, so its name, focus and J and K never depend on scrolling.
- A file still being diffed reads "Comparing changes…" and is
aria-busy; the review itself is not, so its announcements go out meanwhile. A file pastmaxEditLengthsays it is shown as one replacing hunk.
Theming
Every color, radius and font is a CSS variable, so the overrides in Theming apply, on :root or scoped to any element. These hooks are read from the component's markup.
- Slots (data-slot)
- signoff-diff-hunksignoff-diff-reviewsignoff-diff-submitsignoff-diff-filessignoff-diff-filesignoff-diff-fallbacksignoff-diff-commentsignoff-diff-comment-editorsignoff-diff-chunksignoff-diff-gap
- State attributes
- data-fallbackon
signoff-diff-file'replace', for a file past maxEditLengthdata-viewedonsignoff-diff-fileset on a file marked vieweddata-decisiononsignoff-diff-fileHunkDecision, on hunks; FileDecision, on filesdata-line-indexdata-renderedonsignoff-diff-chunkset while the rows are rendered, near the screendata-linedata-selectedset on a selected line - Tokens it uses
- --signoff-accent--signoff-accent-fg--signoff-add-bg--signoff-add-strong--signoff-bg--signoff-border--signoff-border-strong--signoff-del-bg--signoff-del-strong--signoff-fg--signoff-fg-muted--signoff-fg-subtle--signoff-font-mono--signoff-font-sans--signoff-hot--signoff-hot-fg--signoff-on-accent--signoff-radius--signoff-ring--signoff-surface--signoff-surface-2--signoff-warn--signoff-warn-fg
/* Only this component, and only inside .settings-panel */
.settings-panel [data-slot='signoff-diff-hunk'] {
--signoff-radius: 4px;
}
[data-slot='signoff-diff-file'][data-fallback='replace'] {
outline: 1px solid var(--signoff-accent);
}