ai diff review.md

AI Diff Review

A coding agent's edits streaming in file by file, then reviewed per file with accept, reject and undo.

Installation

npx shadcn@latest add @kokonutui/ai-diff-review

Props

Prop Type Default Description
files? FileChange[] The agent's edits. When omitted, a demo edit streams in, file by file, then waits for review.
onDecision? (path: string, decision: FileDecision) => void Called when a file is accepted, rejected or put back to pending.
className? string Extra classes for the root element.

FileChange

Field Type Description
path string
hunks DiffHunk[]
created? boolean True for a file the agent created.

FileDecision

type FileDecision = "pending" | "accepted" | "rejected";

DiffHunk

Field Type Description
start number First line number of the hunk in the new file.
lines DiffLine[]

DiffLine

Field Type Description
type "add" | "remove" | "context"
text string

Source

"use client";

/**
 * @author: @kokonutui
 * @description: AI Diff Review
 * @version: 1.1.0
 * @date: 2026-10-21
 * @license: MIT
 * @website: https://kokonutui.com
 * @github: https://github.com/kokonut-labs/kokonutui
 */

import { Check, ChevronRight, Undo2, X } from "lucide-react";
import {
  AnimatePresence,
  MotionConfig,
  motion,
  useReducedMotion,
} from "motion/react";
import { type ReactNode, useEffect, useId, useRef, useState } from "react";
import { cn } from "@/lib/utils";

export interface DiffLine {
  type: "add" | "remove" | "context";
  text: string;
}

export interface DiffHunk {
  /** First line number of the hunk in the new file. */
  start: number;
  lines: DiffLine[];
}

export type FileDecision = "pending" | "accepted" | "rejected";

export interface FileChange {
  path: string;
  hunks: DiffHunk[];
  /** True for a file the agent created. */
  created?: boolean;
}

interface AIDiffReviewProps {
  /**
   * The agent's edits. When omitted, a demo edit streams in, file by file,
   * then waits for review.
   */
  files?: FileChange[];
  /** Called when a file is accepted, rejected or put back to pending. */
  onDecision?: (path: string, decision: FileDecision) => void;
  className?: string;
}

const DEMO_FILES: FileChange[] = [
  {
    path: "lib/validate.ts",
    created: true,
    hunks: [
      {
        start: 1,
        lines: [
          {
            type: "add",
            text: "const POSTCODE = /^[A-Z]{1,2}\\d[A-Z\\d]? ?\\d[A-Z]{2}$/i;",
          },
          { type: "add", text: "" },
          { type: "add", text: "export function isPostcode(value: string) {" },
          { type: "add", text: "  return POSTCODE.test(value.trim());" },
          { type: "add", text: "}" },
        ],
      },
    ],
  },
  {
    path: "app/checkout/form.tsx",
    hunks: [
      {
        start: 18,
        lines: [
          { type: "context", text: "  const onSubmit = (data: Address) => {" },
          { type: "remove", text: "    if (!data.postcode) {" },
          { type: "remove", text: '      return setError(