Code Diff View

An agent's proposed file changes, with accept or reject on each file.

PROGet Code Diff View and 168 other Pro components with pro lifetime — Get Pro

Category
AI Agent
Access
Pro
Source
473 lines · one file
States
7 drawn

The decision inside it

The decision is per file

A file is the unit people review and the unit an agent can apply or drop cleanly. Each shows its size before it is opened, a decided file can be undone, and nothing is final until your app says so.

When to use it

Use Code Diff View when an agent proposes changes to files and a person approves them: per-file accept or reject, +/− counts, unified or split, unchanged context folded. Keep the decisions in your state and apply only accepted files. For changes to prose (an email, a clause), use Inline Diff.

Installation

How you get it

Paste this into Claude Code, Cursor, Codex or any coding agent. It installs the file and uses it as it is, instead of writing a new one.

Use Liro's Code Diff View for this.
Install it: npx shadcn@latest add @liro/code-diff-view
(the @liro registry is set up in components.json, with LIRO_KEY in .env.local)
Import it from @/components/ui/code-diff-view.
Do not rewrite or restyle it. Pass my data through its props
and keep its built-in states.

For the full brief with every prop and the mistakes assistants usually make, use Copy prompt above. Pro components install through the @liro registry with your CLI token: see the Namespaced tab.

Usage

components/agent-changes.tsx
"use client";

import * as React from "react";
import { CodeDiffView, type DiffDecision, type DiffFile } from "@/components/ui/code-diff-view";

export function AgentChanges({ files, apply }: { files: DiffFile[]; apply: (paths: string[]) => void }) {
  const [decisions, setDecisions] = React.useState<Record<string, DiffDecision>>({});
  const set = (path: string, d: DiffDecision) => setDecisions((s) => ({ ...s, [path]: d }));
  return (
    <CodeDiffView
      files={files}
      decisions={decisions}
      onAccept={(p) => set(p, "accepted")}
      onReject={(p) => set(p, "rejected")}
      onReset={(p) => set(p, "pending")}
      onAcceptAll={() => apply(files.map((f) => f.path))}
    />
  );
}

API reference

“Copy prompt” above puts a full brief on your clipboard, install command, dependencies, props, and the mistakes an assistant usually makes with this component.

Props

Read from the component’s own TypeScript interface when the site is built, so this table cannot drift from the file you install.

TypeNotes
filesDiffFile[] YesThe proposed changes, one entry per file.
view"unified" | "split" NoUnified (one column) or split (old beside new). Split falls back to unified under 560px. Default unified.
variant"default" | "summary" No"summary" shows the file list with counts only. Default "default".
defaultExpandedboolean NoOpen every file at first. Default true for three files or fewer.
decisionsRecord<string, DiffDecision> NoThe decision on each file, by path. Missing means pending.
onAccept(path: string) => void NoCalled when a file is accepted.
onReject(path: string) => void NoCalled when a file is rejected.
onReset(path: string) => void NoCalled to put a decided file back to pending. Without it, a decided file cannot be undone here.
onAcceptAll() => void NoAccept every pending file. Shown in the strip when given.
onRejectAll() => void NoReject every pending file. Shown in the strip when given.
titlestring NoThe heading. Default "Proposed changes".
lookLook NoLayered rests the files in a tray with the totals in the strip below. Flat is one card. Default layered.

Dependencies

npm packages

clsxlucide-reacttailwind-merge

Liro foundations, installed alongside it

liro-theme

States

All of them are drawn by the component. None is left for you to design.

  • Pending
  • Accepted
  • Rejected
  • Split
  • Folded context
  • Binary file
  • Summary

Accessibility

  • Keyboard reachable throughout, in visual order
  • Focus trapped in overlays, Escape closes them
  • Focus returns to whatever opened it
  • Live regions announce what changed, not that something did
  • Honours prefers-reduced-motion

Responsive behavior

  • Sizes to its container, not the viewport
  • Usable from 320px up
  • Pointer-based interaction, so trackpad and touch both work
  • No hover-only affordances