# Metadata diff

The change as files: one tab per file, each named by the thing it is (a field, a layout) as well as its path, with a unified diff that highlights the exact words that changed inside a line.

- Registry name: `metadata-diff` (`@candor/metadata-diff`)
- Tier: Pro. Installing it needs a Pro, Premium or Team licence key: the person runs `npx candor-ui key <key>` themselves; never ask for the key in chat or write it to a file.
- Docs: https://candor.themethodic.com/docs/metadata-diff

## Install

```bash
npx candor-ui add metadata-diff
```

Run `npx candor-ui@latest init` once first (https://candor.themethodic.com/get-started.md). Without the CLI: `npx shadcn@latest add @candor/metadata-diff`.
It brings in: entity-chip, locale, work, utils.
npm packages: lucide-react@^1.67.0, radix-ui@^1.8.1.

## Example

```tsx
"use client"

import type { FileDiff } from "@/lib/work"
import { ChangeDiff } from "@/components/metadata-diff"

const files: FileDiff[] = [
  {
    path: "db/migrations/0142_add_customer_region.sql",
    entity: { kind: "migration", name: "0142_add_customer_region", label: "Add customers.region" },
    change: "create",
    language: "sql",
    hunks: [
      {
        lines: [
          { kind: "add", text: "CREATE TYPE region AS ENUM ('us', 'eu', 'apac', 'other');", newNo: 1 },
          { kind: "add", text: "ALTER TABLE customers ADD COLUMN region region;", newNo: 2 },
          { kind: "add", text: "CREATE INDEX customers_region_idx ON customers (region);", newNo: 3 },
        ],
      },
    ],
  },
  {
    path: "web/src/customers/CustomerHeader.tsx",
    entity: { kind: "component", name: "web/src/customers/CustomerHeader.tsx", label: "CustomerHeader" },
    change: "update",
    language: "tsx",
    hunks: [
      {
        header: "@@ function CustomerHeader @@",
        lines: [
          { kind: "context", text: '      <Fact label="Plan" value={customer.plan} />', oldNo: 43, newNo: 43 },
          { kind: "remove", text: '      <Fact label="Partner tier" value={customer.partnerTierOld} />', oldNo: 44 },
          { kind: "add", text: '      <Fact label="Region" value={regionLabel(customer.region)} />', newNo: 44 },
          { kind: "context", text: "    </dl>", oldNo: 45, newNo: 45 },
        ],
      },
    ],
  },
]

export default function Example() {
  return <ChangeDiff className="max-w-3xl" files={files} />
}
```

## <ChangeDiff>

Props:

- `files: FileDiff[]`: The changed files, one tab each.
- `className?: string | undefined`

## Strings (`metadataDiff`)

The fixed words, English by default. Override any of them under `metadataDiff` in `<LocaleProvider strings={{ metadataDiff: { … } }}>`; the table is exported as `metadataDiffStrings`.

- `label`: Changes
- `files`: { one: "{count} file", other: "{count} files" }
- `fileTabs`: Files
- `create`: New
- `update`: Changed
- `delete`: Deleted
- `added`: Added: 
- `removed`: Removed: 

## Rules for using Candor UI

- Components take plain typed data. Never pass model output as HTML or render it as a link; messages are typed blocks.
- A control that can't be used says why: wrap it in `<Locked reason="…">`, don't just disable it.
- Don't show a value you don't have: leave it out (it renders as —) rather than guess. An estimate is labelled as one.
- Nothing is pre-selected in a decision a person makes, and the agent is named from your app's data, never from model output.
- Your app's words go in `LocaleProvider` (fixed strings) and `TermsProvider` (nouns); entity kinds and agent roles in `EntityKindsProvider` and `AgentRolesProvider`.
