# Diff (/docs/agent-ui/components/diff)

Use a diff when an agent has edited files and the person decides what stays. The edits are already applied: **Keep** leaves an edit as it is, and **Undo** reverts it. With several files, a summary sits above them with **Keep all** and **Undo all**.

<Example caption="Hover a file or a change, or focus it, to show its Keep and Undo. Press Undo all to see it ask first. Each decision shows Keeping… for a moment, then Kept or Undone in the buttons' place.">
  <DiffExample />

  ```tsx tab="React"
  "use client";

  import type { DiffFile } from "@kind-ui/agent-ui";
  import type { DiffTarget } from "@kind-ui/agent-ui/core";
  import { useState } from "react";
  import { Diff } from "@/components/ui/diff";

  const changes: DiffFile[] = [
    {
      path: "src/lib/auth/sign-in.ts",
      before: `export async function signIn(email: string, password: string) {
    const user = await db.users.find({ email });
    if (!user) throw new Error("Not found");
    const ok = compare(password, user.hash);
    return { ok, user };
  }
  `,
      after: `export async function signIn(email: string, password: string) {
    const user = await db.users.find({ email });
    if (!user) return { ok: false, reason: "unknown-user" };
    const ok = await compare(password, user.hash);
    return { ok, user };
  }
  `,
    },
    {
      path: "src/lib/auth/session.ts",
      status: "added",
      before: "",
      after: `export async function create(userId: string) {
    return db.sessions.insert({ id: crypto.randomUUID(), userId });
  }
  `,
    },
    {
      path: "src/lib/auth/password.ts",
      oldPath: "src/lib/crypto/password.ts",
      before: "export const rounds = 10;\n",
      after: 'export const rounds = 10;\nexport const algorithm = "argon2id";\n',
    },
  ];

  const wait = () => new Promise((resolve) => setTimeout(resolve, 600));

  export default function DiffExample() {
    const [files, setFiles] = useState(changes);
    // The edits are already applied: Keep leaves them, Undo reverts them. Report each decision once it's done.
    const decide =
      (decision: "kept" | "undone") =>
      async ({ path, change }: DiffTarget) => {
        await wait();
        setFiles((all) =>
          all.map((file) => {
            if (path !== undefined && file.path !== path) return file;
            if (file.decision) return file;
            if (change === undefined) return { ...file, decision };
            const decided = [...(file.changes ?? [])];
            decided[change] = { decision };
            return { ...file, changes: decided };
          }),
        );
      };
    return (
      <div className="flex w-full max-w-2xl flex-col items-start gap-3">
        <Diff
          className="w-full"
          files={files}
          defaultOpen={changes.slice(0, 1).map((file) => file.path)}
          onKeep={decide("kept")}
          onUndo={decide("undone")}
        />
        <button type="button" data-kind-button="secondary" onClick={() => setFiles(changes)}>
          Start again
        </button>
      </div>
    );
  }
  ```

  ```vue tab="Vue"
  <script setup lang="ts">
  import type { DiffFile } from "@kind-ui/agent-ui";
  import type { DiffTarget } from "@kind-ui/agent-ui/core";
  import { shallowRef } from "vue";
  import { Diff } from "@/components/ui/vue/diff";

  const changes: DiffFile[] = [
    {
      path: "src/lib/auth/sign-in.ts",
      before: `export async function signIn(email: string, password: string) {
    const user = await db.users.find({ email });
    if (!user) throw new Error("Not found");
    const ok = compare(password, user.hash);
    return { ok, user };
  }
  `,
      after: `export async function signIn(email: string, password: string) {
    const user = await db.users.find({ email });
    if (!user) return { ok: false, reason: "unknown-user" };
    const ok = await compare(password, user.hash);
    return { ok, user };
  }
  `,
    },
    {
      path: "src/lib/auth/session.ts",
      status: "added",
      before: "",
      after: `export async function create(userId: string) {
    return db.sessions.insert({ id: crypto.randomUUID(), userId });
  }
  `,
    },
    {
      path: "src/lib/auth/password.ts",
      oldPath: "src/lib/crypto/password.ts",
      before: "export const rounds = 10;\n",
      after: 'export const rounds = 10;\nexport const algorithm = "argon2id";\n',
    },
  ];

  const files = shallowRef(changes);
  const open = changes.slice(0, 1).map((file) => file.path);
  const wait = () => new Promise((resolve) => setTimeout(resolve, 600));

  // The edits are already applied: Keep leaves them, Undo reverts them. Report each decision once it's done.
  const decide =
    (decision: "kept" | "undone") =>
    async ({ path, change }: DiffTarget) => {
      await wait();
      files.value = files.value.map((file) => {
        if (path !== undefined && file.path !== path) return file;
        if (file.decision) return file;
        if (change === undefined) return { ...file, decision };
        const decided = [...(file.changes ?? [])];
        decided[change] = { decision };
        return { ...file, changes: decided };
      });
    };
  const keep = decide("kept");
  const undo = decide("undone");
  </script>

  <template>
    <div class="flex w-full max-w-2xl flex-col items-start gap-3">
      <Diff class="w-full" :files="files" :default-open="open" :on-keep="keep" :on-undo="undo" />
      <button type="button" data-kind-button="secondary" @click="files = changes">Start again</button>
    </div>
  </template>
  ```

  ```svelte tab="Svelte"
  <script lang="ts">
    import type { DiffFile } from "@kind-ui/agent-ui";
    import type { DiffTarget } from "@kind-ui/agent-ui/core";
    import { Diff } from "@/components/ui/svelte/diff/index.js";

    const changes: DiffFile[] = [
      {
        path: "src/lib/auth/sign-in.ts",
        before: `export async function signIn(email: string, password: string) {
    const user = await db.users.find({ email });
    if (!user) throw new Error("Not found");
    const ok = compare(password, user.hash);
    return { ok, user };
  }
  `,
        after: `export async function signIn(email: string, password: string) {
    const user = await db.users.find({ email });
    if (!user) return { ok: false, reason: "unknown-user" };
    const ok = await compare(password, user.hash);
    return { ok, user };
  }
  `,
      },
      {
        path: "src/lib/auth/session.ts",
        status: "added",
        before: "",
        after: `export async function create(userId: string) {
    return db.sessions.insert({ id: crypto.randomUUID(), userId });
  }
  `,
      },
      {
        path: "src/lib/auth/password.ts",
        oldPath: "src/lib/crypto/password.ts",
        before: "export const rounds = 10;\n",
        after: 'export const rounds = 10;\nexport const algorithm = "argon2id";\n',
      },
    ];

    let files = $state.raw(changes);

    const wait = () => new Promise((resolve) => setTimeout(resolve, 600));

    // The edits are already applied: Keep leaves them, Undo reverts them. Report each decision once it's done.
    const decide =
      (decision: "kept" | "undone") =>
      async ({ path, change }: DiffTarget) => {
        await wait();
        files = files.map((file) => {
          if (path !== undefined && file.path !== path) return file;
          if (file.decision) return file;
          if (change === undefined) return { ...file, decision };
          const decided = [...(file.changes ?? [])];
          decided[change] = { decision };
          return { ...file, changes: decided };
        });
      };
  </script>

  <div class="flex w-full max-w-2xl flex-col items-start gap-3">
    <Diff
      class="w-full"
      {files}
      defaultOpen={changes.slice(0, 1).map((file) => file.path)}
      onKeep={decide("kept")}
      onUndo={decide("undone")}
    />
    <button type="button" data-kind-button="secondary" onclick={() => (files = changes)}>Start again</button>
  </div>
  ```

  ```tsx tab="Solid"
  import type { DiffFile } from "@kind-ui/agent-ui";
  import type { DiffTarget } from "@kind-ui/agent-ui/core";
  import { createSignal } from "solid-js";
  import { Diff } from "@/components/ui/solid/diff";

  const changes: DiffFile[] = [
    {
      path: "src/lib/auth/sign-in.ts",
      before: `export async function signIn(email: string, password: string) {
    const user = await db.users.find({ email });
    if (!user) throw new Error("Not found");
    const ok = compare(password, user.hash);
    return { ok, user };
  }
  `,
      after: `export async function signIn(email: string, password: string) {
    const user = await db.users.find({ email });
    if (!user) return { ok: false, reason: "unknown-user" };
    const ok = await compare(password, user.hash);
    return { ok, user };
  }
  `,
    },
    {
      path: "src/lib/auth/session.ts",
      status: "added",
      before: "",
      after: `export async function create(userId: string) {
    return db.sessions.insert({ id: crypto.randomUUID(), userId });
  }
  `,
    },
    {
      path: "src/lib/auth/password.ts",
      oldPath: "src/lib/crypto/password.ts",
      before: "export const rounds = 10;\n",
      after: 'export const rounds = 10;\nexport const algorithm = "argon2id";\n',
    },
  ];

  const wait = () => new Promise((resolve) => setTimeout(resolve, 600));

  export default function DiffExample() {
    const [files, setFiles] = createSignal(changes);
    // The edits are already applied: Keep leaves them, Undo reverts them. Report each decision once it's done.
    const decide =
      (decision: "kept" | "undone") =>
      async ({ path, change }: DiffTarget) => {
        await wait();
        setFiles((all) =>
          all.map((file) => {
            if (path !== undefined && file.path !== path) return file;
            if (file.decision) return file;
            if (change === undefined) return { ...file, decision };
            const decided = [...(file.changes ?? [])];
            decided[change] = { decision };
            return { ...file, changes: decided };
          }),
        );
      };
    return (
      <div class="flex w-full max-w-2xl flex-col items-start gap-3">
        <Diff
          class="w-full"
          files={files()}
          defaultOpen={changes.slice(0, 1).map((file) => file.path)}
          onKeep={decide("kept")}
          onUndo={decide("undone")}
        />
        <button type="button" data-kind-button="secondary" onClick={() => setFiles(changes)}>
          Start again
        </button>
      </div>
    );
  }
  ```
</Example>

## Installation [#installation]

```bash tab="React"
npx shadcn@latest add @kind-ui/diff
```

```bash tab="Web Components"
npx shadcn@latest add @kind-ui/diff-web
```

```bash tab="Vue"
npx shadcn@latest add @kind-ui/diff-vue
```

```bash tab="Svelte"
npx shadcn@latest add @kind-ui/diff-svelte
```

```bash tab="Solid"
npx shadcn@latest add @kind-ui/diff-solid
```

## Composition [#composition]

```text
Diff
├── DiffSummary
│   ├── DiffSummaryTitle
│   ├── DiffSummaryCounts
│   ├── DiffSummaryProgress
│   ├── DiffSummaryOutcome
│   ├── DiffSummaryMark
│   ├── DiffSummaryActions
│   │   ├── DiffUndoAllQuestion
│   │   ├── DiffUndoAll
│   │   ├── DiffKeepAll
│   │   ├── DiffUndoAllCancel
│   │   └── DiffUndoAllConfirm
│   └── DiffSummaryError
└── DiffList
    └── DiffFile
        ├── DiffFileTrigger
        │   ├── DiffFilePath
        │   ├── DiffFileOldPath
        │   ├── DiffFileStatus
        │   ├── DiffFileCounts
        │   └── DiffFileMark
        ├── DiffFileActions
        │   ├── DiffFileError
        │   ├── DiffFileUndo
        │   ├── DiffFileKeep
        │   └── DiffFileOutcome
        └── DiffFileContent
            ├── DiffFileNote
            └── DiffViewport
                ├── DiffTable
                │   ├── DiffHead
                │   │   └── DiffColumn
                │   ├── DiffChange
                │   │   └── DiffChangeTitle
                │   └── DiffLine
                │       ├── DiffOldNumber
                │       ├── DiffNewNumber
                │       ├── DiffSign
                │       └── DiffCode
                │           ├── DiffCollapsed
                │           └── DiffCollapsedText
                └── DiffShowAll
```

`Diff` renders all of these. The root is a region named "Changes", or by the path of a one-file diff. Each file's trigger is a native button that opens its lines, named by the path, its status and its counts, like "src/lib/auth/session.ts Added 38 additions". The lines are a table with column headers for screen readers; added and removed lines are `ins` and `del`, with hidden words before them. Line numbers and signs are drawn from attributes, so copying lines copies only code.

## Usage [#usage]

### Files [#files]

Pass `files`, one `DiffFile` each. Give each a unified `patch`, as `git diff` writes it, or `before` and `after`, which the diff compares itself. A patch's headers fill in the file's `status` and a rename's `oldPath`; you can pass them yourself too. A file row says Added, Deleted or Renamed (a modified file says nothing), and a rename shows "from" its old path. Counts read like `+4 −2`, leaving out a side that's zero. Long paths lose their start, so the file name stays.

Runs of more than 6 unchanged lines keep 3 on each side and fold into **Show N lines**, which opens them in place. Find in page opens them too. A file past 2,000 rows stops there with **Show full diff**. A binary file says "Binary file, not shown", and a rename without changes says "Renamed, no changes".

Pass `highlight`, the same function [Code Block](./code-block.mdx) takes, to color each side; lines show plain until it resolves. Changed words inside a line that reads as an edit of another get a stronger tint.

### One File [#one-file]

With one file there's no summary: the file's row is the header, and it starts open.

<Example caption="One file's change, with the changed words marked.">
  <DiffSingleExample />

  ```tsx tab="React"
  import { Diff } from "@/components/ui/diff";

  const patch = `--- a/package.json
  +++ b/package.json
  @@ -12,3 +12,3 @@
       "test": "vitest run",
  -    "lint": "eslint .",
  +    "lint": "biome check .",
       "build": "tsc -b"
  `;

  export default function DiffSingleExample() {
    return <Diff className="w-full max-w-2xl" files={[{ path: "package.json", patch }]} />;
  }
  ```

  ```vue tab="Vue"
  <script setup lang="ts">
  import { Diff } from "@/components/ui/vue/diff";

  const patch = `--- a/package.json
  +++ b/package.json
  @@ -12,3 +12,3 @@
       "test": "vitest run",
  -    "lint": "eslint .",
  +    "lint": "biome check .",
       "build": "tsc -b"
  `;
  </script>

  <template>
    <Diff class="w-full max-w-2xl" :files="[{ path: 'package.json', patch }]" />
  </template>
  ```

  ```svelte tab="Svelte"
  <script lang="ts">
    import { Diff } from "@/components/ui/svelte/diff/index.js";

    const patch = `--- a/package.json
  +++ b/package.json
  @@ -12,3 +12,3 @@
       "test": "vitest run",
  -    "lint": "eslint .",
  +    "lint": "biome check .",
       "build": "tsc -b"
  `;
  </script>

  <Diff class="w-full max-w-2xl" files={[{ path: "package.json", patch }]} />
  ```

  ```tsx tab="Solid"
  import { Diff } from "@/components/ui/solid/diff";

  const patch = `--- a/package.json
  +++ b/package.json
  @@ -12,3 +12,3 @@
       "test": "vitest run",
  -    "lint": "eslint .",
  +    "lint": "biome check .",
       "build": "tsc -b"
  `;

  export default function DiffSingleExample() {
    return <Diff class="w-full max-w-2xl" files={[{ path: "package.json", patch }]} />;
  }
  ```
</Example>

### Keep and Undo [#keep-and-undo]

Pass `onKeep` and `onUndo` to offer Keep and Undo. Each gets the target and `details`: `{ path, change }` for one change of a file with several, `{ path }` for a file, and `{}` for every undecided file. `details.reason` is `"keep-press"`, `"undo-press"`, `"shortcut"` or `"imperative"`, and `details.source` says who acted.

Return a promise, and the target shows **Keeping…** or **Undoing…** until it settles. Once it resolves, the target stays locked until you report the outcome in `files`: set a file's `decision` to `"kept"` or `"undone"`, or a change's in `changes`, by its index. Replacing the file's patch unlocks it too. If the promise rejects, the row says "Couldn't undo `auth.ts`" and its buttons stay.

A decided file or change shows **Kept** or **Undone** in its buttons' place, taking focus if a pressed button had it. An undone change stays where it is, dimmed. The summary counts the files reviewed, "2 of 4 reviewed", and once every file is decided says "All changes reviewed" with "3 kept, 1 undone"; Keep all and Undo all leave, and focus moves to that line. Outcomes are announced once, like "Kept session.ts".

**Undo all** asks first, in place: "Undo all 4 files? This can't be undone." with **Cancel** and **Undo all**. Cancel takes focus. Pass `perChange={false}` when you can only apply whole files, and `keepLabel` and `undoLabel` to rename the buttons.

With a mouse, a row's Keep and Undo show while you hover or focus it, in space that's always kept, so nothing moves. On touch screens and in a narrow diff they always show, as icon buttons named by the path, like "Keep src/app.ts".

### Streaming [#streaming]

Set a file's `streaming` while its patch arrives and pass the whole patch on each update; only its last change is read again. The summary says "Editing 2 files", the row shows a running mark in place of its counts, and nothing can be kept or undone until every file's patch has arrived. An open file follows its end while it streams.

<Example caption="A new file streams in, then settles with its counts.">
  <DiffStreamingExample />

  ```tsx tab="React"
  "use client";

  import { useEffect, useState } from "react";
  import { Diff } from "@/components/ui/diff";

  const lines = [
    "export async function create(userId: string) {",
    "  const id = crypto.randomUUID();",
    "  await db.sessions.insert({ id, userId });",
    "  return id;",
    "}",
  ];

  const patchOf = (count: number) =>
    `--- /dev/null\n+++ b/src/lib/auth/session.ts\n@@ -0,0 +1,${count} @@\n${lines
      .slice(0, count)
      .map((line) => `+${line}`)
      .join("\n")}\n`;

  export default function DiffStreamingExample() {
    const [count, setCount] = useState(1);
    useEffect(() => {
      const timer = setInterval(() => setCount((n) => (n > lines.length + 4 ? 1 : n + 1)), 500);
      return () => clearInterval(timer);
    }, []);
    const streaming = count <= lines.length;
    return (
      <Diff
        className="w-full max-w-2xl"
        files={[
          {
            path: "src/lib/auth/session.ts",
            status: "added",
            patch: patchOf(Math.min(count, lines.length)),
            streaming,
          },
        ]}
      />
    );
  }
  ```

  ```vue tab="Vue"
  <script setup lang="ts">
  import { computed, onBeforeUnmount, onMounted, ref } from "vue";
  import { Diff } from "@/components/ui/vue/diff";

  const lines = [
    "export async function create(userId: string) {",
    "  const id = crypto.randomUUID();",
    "  await db.sessions.insert({ id, userId });",
    "  return id;",
    "}",
  ];

  const patchOf = (count: number) =>
    `--- /dev/null\n+++ b/src/lib/auth/session.ts\n@@ -0,0 +1,${count} @@\n${lines
      .slice(0, count)
      .map((line) => `+${line}`)
      .join("\n")}\n`;

  const count = ref(1);
  let timer: ReturnType<typeof setInterval> | undefined;
  onMounted(() => {
    timer = setInterval(() => {
      count.value = count.value > lines.length + 4 ? 1 : count.value + 1;
    }, 500);
  });
  onBeforeUnmount(() => clearInterval(timer));

  const files = computed(() => [
    {
      path: "src/lib/auth/session.ts",
      status: "added" as const,
      patch: patchOf(Math.min(count.value, lines.length)),
      streaming: count.value <= lines.length,
    },
  ]);
  </script>

  <template>
    <Diff class="w-full max-w-2xl" :files="files" />
  </template>
  ```

  ```svelte tab="Svelte"
  <script lang="ts">
    import { Diff } from "@/components/ui/svelte/diff/index.js";

    const lines = [
      "export async function create(userId: string) {",
      "  const id = crypto.randomUUID();",
      "  await db.sessions.insert({ id, userId });",
      "  return id;",
      "}",
    ];

    const patchOf = (count: number) =>
      `--- /dev/null\n+++ b/src/lib/auth/session.ts\n@@ -0,0 +1,${count} @@\n${lines
        .slice(0, count)
        .map((line) => `+${line}`)
        .join("\n")}\n`;

    let count = $state(1);

    $effect(() => {
      const timer = setInterval(() => (count = count > lines.length + 4 ? 1 : count + 1), 500);
      return () => clearInterval(timer);
    });

    const streaming = $derived(count <= lines.length);
  </script>

  <Diff
    class="w-full max-w-2xl"
    files={[
      {
        path: "src/lib/auth/session.ts",
        status: "added",
        patch: patchOf(Math.min(count, lines.length)),
        streaming,
      },
    ]}
  />
  ```

  ```tsx tab="Solid"
  import { createSignal, onSettled } from "solid-js";
  import { Diff } from "@/components/ui/solid/diff";

  const lines = [
    "export async function create(userId: string) {",
    "  const id = crypto.randomUUID();",
    "  await db.sessions.insert({ id, userId });",
    "  return id;",
    "}",
  ];

  const patchOf = (count: number) =>
    `--- /dev/null\n+++ b/src/lib/auth/session.ts\n@@ -0,0 +1,${count} @@\n${lines
      .slice(0, count)
      .map((line) => `+${line}`)
      .join("\n")}\n`;

  export default function DiffStreamingExample() {
    const [count, setCount] = createSignal(1);
    onSettled(() => {
      const timer = setInterval(() => setCount((n) => (n > lines.length + 4 ? 1 : n + 1)), 500);
      return () => clearInterval(timer);
    });
    return (
      <Diff
        class="w-full max-w-2xl"
        files={[
          {
            path: "src/lib/auth/session.ts",
            status: "added",
            patch: patchOf(Math.min(count(), lines.length)),
            streaming: count() <= lines.length,
          },
        ]}
      />
    );
  }
  ```
</Example>

### Keyboard [#keyboard]

File rows are one Tab stop: Up and Down arrow keys move between them, Home and End jump to the first and last, and Enter or Space opens and closes one. A row's Undo and Keep follow it in Tab order. On a focused row or change, K keeps and U undoes. Each open file's lines scroll from the keyboard once you Tab to them. Pass `open` with `onOpenChange` to control which files are open.

## API Reference [#api-reference]

### DiffOptions

| Prop            | Type                                                                              | Description                                                                                                                                                                                     |
| --------------- | --------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `files?`        | `DiffFile[] \| undefined`                                                         | One file, or a run's changes. With several, a summary with Keep all and Undo all sits above them.                                                                                               |
| `label?`        | `string \| undefined`                                                             | Names the region. Default: `"Changes", or the path of a one-file Diff`                                                                                                                          |
| `onKeep?`       | `((target: DiffTarget, details: DiffActionDetails) => unknown) \| undefined`      | Offers Keep on each undecided file and change, and Keep all. Return a promise to show "Keeping…" until it settles; the target stays locked until you report its `decision` or replace the file. |
| `onUndo?`       | `((target: DiffTarget, details: DiffActionDetails) => unknown) \| undefined`      | Offers Undo, as `onKeep` offers Keep. Undo all asks first, in place.                                                                                                                            |
| `perChange?`    | `boolean \| undefined`                                                            | Whether each change of a file with several has its own Keep and Undo. Turn it off when you can only apply whole files. Default: `true`                                                          |
| `open?`         | `string[] \| undefined`                                                           | The paths of the open files.                                                                                                                                                                    |
| `defaultOpen?`  | `string[] \| undefined`                                                           | Default: `the only file's path, else none`                                                                                                                                                      |
| `onOpenChange?` | `((open: string[], details: ChangeDetails<DiffOpenReason>) => void) \| undefined` |                                                                                                                                                                                                 |
| `highlight?`    | `Highlight \| undefined`                                                          | Resolves colored tokens for each side of a file, as Code Block's does; lines show plain until it does.                                                                                          |
| `keepLabel?`    | `string \| undefined`                                                             | Default: `"Keep"`                                                                                                                                                                               |
| `undoLabel?`    | `string \| undefined`                                                             | Default: `"Undo"`                                                                                                                                                                               |
| `agentConfirm?` | `boolean \| undefined`                                                            | Whether an agent needs a person to confirm its actions while Undo is offered. UI SDK marks the whole component, so `keep`, `open` and `copy` need one then too. Default: `true`                 |
| `motion?`       | `"auto" \| "none" \| "reduced"`                                                   | How much the open motion and a decided change's dimming animate. `"auto"` follows `prefers-reduced-motion`. Default: `"auto"`                                                                   |

Vue, Svelte and Solid take the same props. Controlled props and callbacks are spelled as each framework expects:

| React                  | Vue                            | Svelte                      | Solid                  |
| ---------------------- | ------------------------------ | --------------------------- | ---------------------- |
| `open`, `onOpenChange` | `v-model:open`, `@open-change` | `bind:open`, `onOpenChange` | `open`, `onOpenChange` |
| `onKeep`               | `@keep`                        | `onKeep`                    | `onKeep`               |
| `onUndo`               | `@undo`                        | `onUndo`                    | `onUndo`               |

### Agent [#agent]

An agent connected with `createAgent` finds the diff by its name and can run these actions; files are listed by path. While `onUndo` is set, every action needs a person to confirm it, unless `agentConfirm` is `false`.

### DiffAgentActions

| Prop        | Type                                                                     | Description                                                                                                      |
| ----------- | ------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------- |
| `keep`      | `((path?: string, change?: number, event?: Event) => void) \| undefined` | Keeps a file, a change, or with no path every undecided file. Offered while `onKeep` is set and nothing streams. |
| `undo`      | `((path?: string, change?: number, event?: Event) => void) \| undefined` | Undoes a file, a change, or with no path every undecided file, without asking. Offered as `keep` is.             |
| `open`      | `((path: string) => boolean) \| undefined`                               | Opens a file. Offered while one is closed.                                                                       |
| `expandAll` | `(() => void) \| undefined`                                              | Shows every collapsed run of unchanged lines and every cut-off file. Offered while there's one.                  |
| `copy`      | `((path: string) => Promise<boolean>) \| undefined`                      | Copies a file's patch, and resolves with whether the clipboard write went through.                               |

<Caption>
  Runs in React, Vue, Svelte, Solid and Web Components. On `<kind-diff>`, `files` is a property; the `can-keep` and `can-undo` attributes offer Keep and Undo, which fire `keep` and `undo` with the target as `detail.value` (call `event.detail.waitUntil(promise)` to show Keeping… until it settles), and `onOpenChange` fires `openchange`.
</Caption>
