# Changed Files

> The files an agent's turn changed, as a card with each file's stat and Review.

Page: https://uicontext.com/docs/components/changed-files

Group: Agents.

## When to use

The files an agent's turn changed, as a card with each file's stat and Review. Use [Diff](https://uicontext.com/docs/components/diff.md) instead when people read the change line by line.

## Usage

```ts
import { type ChangedFileStat, ChangeSummary } from "./ui/uicontext/components/ChangeSummary.ts"

const Message = UiSchema.TaggedEnum({ ReviewedTurn: {}, OpenedTurnFile: { path: Schema.String } })

// at the end of a turn: Review opens the whole change, a file opens its own diff
export const TurnChanges = (h: Html.H<typeof Message.Type>, turn: string, files: ReadonlyArray<ChangedFileStat>) =>
	ChangeSummary(h, {
		key: turn,
		props: { id: turn, files },
		onEmit: { RequestedReview: () => Message.ReviewedTurn(), RequestedOpen: ({ path }) => Message.OpenedTurnFile({ path }) },
	})
```

## Examples

Each example is a complete file. Its imports point where the CLI installs the source.

### What a turn changed

The most-changed files first, the rest behind +N more. Press a file or Review; the line under the card says what was asked for.

```ts title="src/demo.ts" source="www/src/examples/changed-files/demo.ts"
import { UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Schema } from "effect"
import { type ChangedFileStat, ChangeSummary } from "./ui/uicontext/components/ChangeSummary.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { color, font, space } from "./ui/uicontext/components/tokens.stylex.ts"

const files: ReadonlyArray<ChangedFileStat> = [
	{ path: "app/src/api/reports.ts", additions: 126, deletions: 43 },
	{ path: "app/src/pages/reports/index.tsx", additions: 184, deletions: 76, unseen: true },
	{ path: "app/src/pages/reports/EmptyState.tsx", additions: 38, deletions: 0, status: "added" },
	{ path: "app/src/hooks/useReport.ts", additions: 22, deletions: 9 },
	{ path: "app/src/pages/reports/Chart.tsx", additions: 11, deletions: 14 },
	{ path: "app/src/legacy/reportsV1.ts", additions: 0, deletions: 141, status: "removed" },
]

const Message = UiSchema.TaggedEnum({ ReviewedChanges: {}, OpenedChangesFile: { path: Schema.String } })

const styles = stylex.create({
	frame: { display: "grid", gap: space.md, inlineSize: "min(100%, 34rem)" },
	said: { margin: 0, fontSize: font.sm, color: color.muted },
})

export const TurnChanges = Html.component({
	name: "TurnChanges",
	model: Schema.Struct({ said: Schema.String }),
	message: Message,
}).make({
	init: () => ({ said: "Nothing opened yet." }),
	update: {
		ReviewedChanges: ($) => $.evolve({ said: "Opened the whole change for review." }),
		OpenedChangesFile: ($, { path }) => $.evolve({ said: `Opened ${path}.` }),
	},
	view: (h, model) => h.div.attrs(sx(styles.frame)).children(
		ChangeSummary(h, {
			props: { id: "turn-4", files },
			onEmit: { RequestedReview: () => Message.ReviewedChanges(), RequestedOpen: ({ path }) => Message.OpenedChangesFile({ path }) },
		}),
		h.p.attrs({ role: "status", ...sx(styles.said) }).children(model.said),
	),
})
```

## API reference

**Props**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `id` (required) | `string` | — | — |
| `files` (required) | `ChangedFileStat[]` | — | — |
| `limit` | `number` | `3` | Files shown before "+N more"; 3 by default |
| `reviewLabel` | `string` | `"Review"` | "Review" by default; leave `can` without "review" for no button |
| `can` | `("review" \| "open")[]` | — | "review" shows the button; "open" makes each file a button |
| `agentId` | `string` | — | — |
| `locale` | `string` | — | — |

**Events**

| Event | Payload | Description |
| --- | --- | --- |
| `RequestedReview` | `{ id: string }` | Review the whole change |
| `RequestedOpen` | `{ id: string; path: string }` | Open one file's change |

**Agent actions**

| Action | Description |
| --- | --- |
| `ClickedReview` | Review the whole change |
| `ClickedFile` | Open one file's change, by its path |

## Keyboard and accessibility

- The card is a section named by its heading, "Edited 6 files"; Review and each file are real buttons.
- +N more is a button with `aria-expanded`. A new or deleted file says so in words.

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/changed-files
```

With npm: `npx shadcn@latest add checkfu/uicontext/changed-files`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/changed-files`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/changed-files`.

It writes these files:

- `src/ui/uicontext/components/Button.ts`
- `src/ui/uicontext/components/ChangeSummary.ts`
- `src/ui/uicontext/components/Diff.ts`
- `src/ui/uicontext/components/DiffStat.ts`
- `src/ui/uicontext/components/IconStroke.ts`
- `src/ui/uicontext/components/InlineNotice.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/agent/Agent.ts`
- `src/ui/uicontext/components/button.stylex.ts`
- `src/ui/uicontext/components/domain/Format.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`
- `src/ui/uicontext/components/touch.stylex.ts`
- `src/ui/uicontext/components/variants.ts`

And installs the npm packages `@stylexjs/stylex`, `effect`.

## Source

- [src/ChangeSummary.ts](https://github.com/checkfu/uicontext/blob/main/src/ChangeSummary.ts)

## Used in

- [Agent studio](https://uicontext.com/blocks/agent-studio.md)

## Related

- [Agent Tools](https://uicontext.com/docs/components/agent-tools.md) (`agent-tools`): Lets agents in the browser read the page and act through the same controls people use.
- [Tool Confirmation](https://uicontext.com/docs/components/tool-confirmation.md) (`tool-confirmation`): Asks a person to confirm before an agent's action changes anything.
- [Prompt Template](https://uicontext.com/docs/components/prompt-template.md) (`prompt-template`): Write a prompt with {{variables}} the app fills in: they stand out, unknown ones are flagged, and a preview shows it with samples.
- [Agent Settings](https://uicontext.com/docs/components/agent-settings.md) (`agent-settings`): Edit an agent's name, instructions, tools and model.
- [Computer](https://uicontext.com/docs/components/computer.md) (`computer`): The machine an agent works on: a live view of its screen, full size or as a thumbnail with Take over, and its browser with tabs and an address bar.
- [Persona Avatar](https://uicontext.com/docs/components/persona-avatar.md) (`persona-avatar`): An agent's face: a shape and a color with eyes that move with what it's doing.
