Tools & Approvals

File Changes

Split review: a file tree on one side, hunks on the other — keep or revert each hunk, then apply the result.

3 variantsMIT

Preview

Installation

Copies the component into components/ui and installs its dependencies and theme tokens.

pnpm dlx shadcn@latest add https://uilab.tmih06.com/r/file-changes.json

Usage

Pass your own data and wire the callbacks to your agent runtime.

import { useState } from "react";
import { FileChanges, type FileChange } from "@/components/ui/file-changes";

export function ReviewEdits({ changes }: { changes: FileChange[] }) {
  const [applying, setApplying] = useState(false);

  return (
    <FileChanges
      data={changes}
      applying={applying}
      onApply={async (selection) => {
        // selection maps each file id to the hunk ids the user kept
        setApplying(true);
        await workspace.applyHunks(selection);
        setApplying(false);
      }}
      onDiscard={() => workspace.revertAll()}
    />
  );
}

// Pass null while the diff is in flight; keep stale data and set loading
// when refetching. The skeleton keeps the tree and hunk layout — it never
// reads as "no changes".
export function ReviewState({ query }: { query: ChangesQuery }) {
  return (
    <FileChanges
      data={query.data ? toFileChanges(query.data) : null}
      loading={query.isRefetching}
      skeleton={{ count: 4 }}
      onApply={(selection) => workspace.applyHunks(selection)}
    />
  );
}

Props

PropTypeDefaultDescription
data*FileChange[] | null—Files the agent edited, each with its diff hunks. Every hunk needs an id. Pass null while they load; an empty array is the explicit no-changes state.
loadingbooleanfalseForce the layout-preserving skeleton while refetching, even when stale data is available.
skeleton{ count?: number }—Shape hints for the loading state; count is the number of file placeholders in the tree or tab row before the real cardinality is known.
view"split" | "stacked""split"Split puts a folder tree beside the hunks; stacked swaps the tree for a row of file tabs for narrow columns.
onApply*(selection: HunkSelection) => void—Called with the hunk ids kept per file. Hunks left out were reverted.
onHunkChange(fileId: string, hunkId: string, keep: boolean) => void—Called whenever a hunk is switched between Keep and Revert.
onDiscard() => void—Shows a Discard all button. Throw away every change here.
applyingbooleanfalsePuts the Apply button in its loading state.
selectedId / onSelectedChangestring / (fileId: string) => void—Control the open file. Leave out to let the component track it.
defaultSelectedIdstring—File open on first render when uncontrolled. Defaults to the first file.
labelsPartial<FileChangesLabels>—Your own UI strings: status names, hunk controls, footer line, buttons and screen-reader text (including `loading`, announced while the skeleton shows), for translating. Right-to-left works under `dir="rtl"`; the diff itself stays left to right.
classNamestring—Extra classes for the root element.
type FileChange = {
  id: string;
  path: string;
  from?: string; // previous path when renamed
  status: "added" | "modified" | "deleted" | "renamed";
  hunks: DiffHunk[];
};

type DiffHunk = {
  id: string;
  oldStart: number;
  newStart: number;
  lines: { type: "add" | "remove" | "context"; text: string }[];
};

type HunkSelection = Record<string, string[]>; // file id → kept hunk ids