# Tool Chips

An agent run shown as compact rows of tool calls and the files they changed.

An agent run as compact rows: tool calls with inline value chips, then file-diff chips summarizing the edits. The run and every step are collapsibles (inline): hovering, focusing or opening a step swaps its tool glyph for the collapsible's caret, and it expands to show what the tool actually did. Each file chip opens a hover-card with its diff on hover or keyboard focus. Fully controlled: the host owns the steps, the diffs and which rows are open.

Kind: block · Category: Agent · Status: beta · Targets: React, Vue, Svelte

## Add

```bash
npx fndn add tool-chips
```

It writes the folder `tool-chips/` into the project's ui folder (`index.ts`, `tool-chips.tsx`, `ToolChips.vue`, `ToolChips.svelte`, `tool-chips.recipe.ts`), and what it is built from: [Collapsible](/components/collapsible.md), [Hover Card](/components/hover-card.md). First time: [Installation](/installation.md).

## Usage

```tsx
import { ToolChips } from "@/components/ui/tool-chips";
```

```vue
import { ToolChips } from "@/components/ui/tool-chips";
```

```svelte
import { ToolChips } from "$lib/components/ui/tool-chips";
```

## Parts

In the DOM the root carries `data-slot="tool-chips"` and each part `data-slot="tool-chips-<part>"`; in the recipe the root is the `base` slot and each part a slot named after it in camelCase.

| Part | Element | data-slot | Flags | Notes |
| --- | --- | --- | --- | --- |
| `root` | `div` | `tool-chips` |  | max-width 320 |
| `run` | `div` | `tool-chips-run` |  | A collapsible (variant inline, caret start) on the run: its trigger is the header ('4 tool calls'), its region holds the rows and the diff chips. The engine sets aria-expanded, aria-controls and data-state; a closed run stays laid out at 0 rows (invisible, out of the tab order) so the steps do not replay their entrance when it reopens |
| `rows` | `div` | `tool-chips-rows` |  |  |
| `step` | `div` | `tool-chips-step` | repeats | One tool call: a collapsible (variant inline, caret start). --fndn-row-index (set only on steps present at mount) staggers its entrance |
| `icon` | `span` | `tool-chips-icon` |  | The tool glyph, laid over the trigger's caret; they crossfade on hover (gated), focus-visible and open. aria-hidden |
| `label` | `span` | `tool-chips-label` |  | Truncates; full text in title |
| `value` | `span` | `tool-chips-value` |  | Field chip with the tool's argument; data-mono; truncates, full text in title |
| `lines` | `div` | `tool-chips-lines` |  | The step's detail inside its collapsible region; hairline on the inline-start side; data-mono |
| `line` | `span` | `tool-chips-line` | repeats | data-tone=add → green; truncates, full text in title |
| `diffs` | `div` | `tool-chips-diffs` | optional | Hairline top border; enters as one beat after the steps |
| `diff` | `button` | `tool-chips-diff` | repeats | File chip: a hover-card trigger (the hover-card's mono chip) whose card shows the file's diff on hover or keyboard focus; click fires diffClick |
| `add` | `span` | `tool-chips-add` | optional |  |
| `del` | `span` | `tool-chips-del` | optional |  |
| `file` | `span` | `tool-chips-file` | repeats | One changed file: holds its hover-card (no box of its own). The last one also holds the more button, so the two share a line and the chip's file name truncates before the button would wrap alone |
| `more` | `button` | `tool-chips-more` | optional | Shown when labels.more is set |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `steps` | `{ key: string? (defaults to label); icon: 'think' \| 'write' \| 'run' \| 'read' \| 'image' \| 'search' \| icon component; label: string; chip: string; mono?: boolean; detailMono?: boolean; detail: { text: string; tone?: 'add' }[] }[]` |  | Tool calls in order. A step appended later enters without a stagger delay. |
| `diffs` | `{ file: string; add: number; del: number; lines: { text: string; tone?: 'add' \| 'del' \| 'ctx' }[]? (the hover-card preview) }[]` |  | Changed files. Each chip opens a hover-card with the file name, the counts and the preview lines. |
| `open` | `boolean` | `true` | Bindable (React: `defaultOpen` and `onOpenChange`; Vue: `v-model:open`; Svelte: `bind:open`). The run is expanded. |
| `openRows` | `array` |  | Bindable (React: `defaultOpenRows` and `onOpenRowsChange`; Vue: `v-model:openRows`; Svelte: `bind:openRows`). Keys (step.key ?? step.label) of expanded steps; data-state=open on each step's collapsible. |
| `labels` | `object` |  | { header, more }. header defaults to '<n> tool calls' ('1 tool call'); more is hidden unless set. |
| `appear` | `boolean` | `false` | Whether the steps and the diff row present at mount enter, staggered. Off by default: set it on the run your code adds live, never on one rendered from history or with the page (a mount is not an arrival). Steps and diffs added after mount enter either way. |

Other attributes and `class` go to the root; `class` is merged through the recipe.

## Events

| Event | Payload |
| --- | --- |
| `openChange` | (open: boolean) |
| `openRowsChange` | (keys: string[]) (Vue/Svelte through v-model:openRows / bind:openRows) |
| `toggleRow` | (label: string, open: boolean) |
| `diffClick` | (file: string) |
| `moreClick` | () |

## States

`open`, `closed`, `row-hover`, `row-press`, `row-focus-visible`, `row-open`, `chip-hover`, `chip-focus-visible`, `chip-press`

## Keyboard and accessibility

Keyboard:

- Tab reaches the run header, then every step row, then the diff chips; collapsed content is out of the tab order
- Enter / Space on the header expand or collapse the run; focus stays on the header; the change is instant
- Enter / Space on a step row expand or collapse its detail; focus stays on the row; the change is instant
- Focusing a diff chip opens its diff card (hover-card); Escape or moving focus closes it; Enter / Space fire diffClick

Notes:

- The header and every row are collapsible triggers: real buttons with aria-expanded and aria-controls pointing at the region they reveal.
- Icons and the glyph/caret slot are aria-hidden.
- Truncated labels, values, detail lines and file names carry the full text in title.

## Motion

- mount: nothing plays unless appear is set; with appear, steps present at first render fade up over duration.enter (easing.out-strong, fill both), staggered by duration.stagger and capped at motion.stagger-max; the diff row enters as one more beat. A step that arrives later enters with no delay and opens its room as it fades (its row track minmax(0,0fr) → minmax(0,1fr) over duration.reveal, easing.out-strong, from @starting-style; the adapter sets --fndn-row-room: 0fr on an arriving step only, so steps present at first render do not move), so the diffs below slide down instead of jumping
- run and row expand / collapse: the collapsible's reveal recipe; the rows below move with the region; nothing inside enters again; instant from the keyboard
- caret: the collapsible's right caret turns down over duration.move (easing.out-strong); on a step row it crossfades with the tool glyph over duration.fast on hover (gated), focus-visible and open
- press: the header and rows take the collapsible's press (--fndn-hover-2); diff chips (the hover-card trigger) and the more button scale to motion.press-scale over duration.press
- diff card: the hover-card's popup recipe; instant when opened by keyboard focus

## Tokens

`color.ink`, `color.ink-2`, `color.ink-3`, `color.field`, `color.hover`, `color.hover-2`, `color.line`, `color.green`, `color.red`, `shadow.hairline`, `radius.control`, `radius.chip`, `font.mono`, `easing.out-strong`, `duration.fast`, `duration.press`, `duration.move`, `duration.enter`, `duration.stagger`, `motion.stagger-max`, `motion.press-scale`

## Dependencies

- [Collapsible](/components/collapsible.md)
- [Hover Card](/components/hover-card.md)

## Notes

- The diff preview is the hover-card's file-diff example: the card shows the file name, the counts and diffs[].lines.

## Examples

### Agent fixed a failing booking test

React · `default.tsx`

```tsx
import { ToolChips, type ToolDiff, type ToolStep } from "@/components/ui/tool-chips";

const steps: ToolStep[] = [
  {
    icon: "read",
    label: "Read file",
    chip: "src/booking/slots.ts",
    mono: true,
    detail: [{ text: "212 lines · exports buildSlots, mergeSlots" }],
  },
  {
    icon: "write",
    label: "Edit 6 lines",
    chip: "src/booking/slots.ts",
    mono: true,
    detailMono: true,
    detail: [
      { text: "- const end = addMinutes(start, service.length)" },
      {
        text: "+ const end = addMinutes(start, service.length, { tz: location.timeZone })",
        tone: "add",
      },
    ],
  },
  {
    icon: "run",
    label: "Run tests",
    chip: "pnpm test slots",
    mono: true,
    detailMono: true,
    detail: [{ text: "✓ slots.test.ts (19 tests) 1.4s" }, { text: "✓ 19 passed" }],
  },
];

const diffs: ToolDiff[] = [
  {
    file: "slots.ts",
    add: 4,
    del: 2,
    lines: [
      {
        text: "export function buildSlots(start: Date, service: Service) {",
        tone: "ctx",
      },
      { text: "  const end = addMinutes(start, service.length);", tone: "del" },
      { text: "  const end = addMinutes(start, service.length, {", tone: "add" },
      { text: "    tz: location.timeZone,", tone: "add" },
      { text: "  });", tone: "add" },
    ],
  },
  {
    file: "slots.test.ts",
    add: 18,
    del: 0,
    lines: [
      {
        text: 'it("keeps a 9:00 slot at 9:00 across the DST change", () => {',
        tone: "add",
      },
      {
        text: '  const slots = buildSlots(new Date("2026-03-29T09:00"), haircut);',
        tone: "add",
      },
      { text: '  expect(slots[0].start).toBe("09:00");', tone: "add" },
      { text: "});", tone: "add" },
    ],
  },
];

export default function Default() {
  return <ToolChips steps={steps} diffs={diffs} />;
}
```

Vue · `default.vue`

```vue
<script setup lang="ts">
import { ToolChips, type ToolDiff, type ToolStep } from "@/components/ui/tool-chips";

const steps: ToolStep[] = [
  {
    icon: "read",
    label: "Read file",
    chip: "src/booking/slots.ts",
    mono: true,
    detail: [{ text: "212 lines · exports buildSlots, mergeSlots" }],
  },
  {
    icon: "write",
    label: "Edit 6 lines",
    chip: "src/booking/slots.ts",
    mono: true,
    detailMono: true,
    detail: [
      { text: "- const end = addMinutes(start, service.length)" },
      {
        text: "+ const end = addMinutes(start, service.length, { tz: location.timeZone })",
        tone: "add",
      },
    ],
  },
  {
    icon: "run",
    label: "Run tests",
    chip: "pnpm test slots",
    mono: true,
    detailMono: true,
    detail: [{ text: "✓ slots.test.ts (19 tests) 1.4s" }, { text: "✓ 19 passed" }],
  },
];

const diffs: ToolDiff[] = [
  {
    file: "slots.ts",
    add: 4,
    del: 2,
    lines: [
      {
        text: "export function buildSlots(start: Date, service: Service) {",
        tone: "ctx",
      },
      { text: "  const end = addMinutes(start, service.length);", tone: "del" },
      { text: "  const end = addMinutes(start, service.length, {", tone: "add" },
      { text: "    tz: location.timeZone,", tone: "add" },
      { text: "  });", tone: "add" },
    ],
  },
  {
    file: "slots.test.ts",
    add: 18,
    del: 0,
    lines: [
      {
        text: 'it("keeps a 9:00 slot at 9:00 across the DST change", () => {',
        tone: "add",
      },
      {
        text: '  const slots = buildSlots(new Date("2026-03-29T09:00"), haircut);',
        tone: "add",
      },
      { text: '  expect(slots[0].start).toBe("09:00");', tone: "add" },
      { text: "});", tone: "add" },
    ],
  },
];
</script>

<template>
  <ToolChips :steps="steps" :diffs="diffs" />
</template>
```

Svelte · `default.svelte`

```svelte
<script lang="ts">
  import { ToolChips, type ToolDiff, type ToolStep } from "$lib/components/ui/tool-chips";

  const steps: ToolStep[] = [
    {
      icon: "read",
      label: "Read file",
      chip: "src/booking/slots.ts",
      mono: true,
      detail: [{ text: "212 lines · exports buildSlots, mergeSlots" }],
    },
    {
      icon: "write",
      label: "Edit 6 lines",
      chip: "src/booking/slots.ts",
      mono: true,
      detailMono: true,
      detail: [
        { text: "- const end = addMinutes(start, service.length)" },
        {
          text: "+ const end = addMinutes(start, service.length, { tz: location.timeZone })",
          tone: "add",
        },
      ],
    },
    {
      icon: "run",
      label: "Run tests",
      chip: "pnpm test slots",
      mono: true,
      detailMono: true,
      detail: [{ text: "✓ slots.test.ts (19 tests) 1.4s" }, { text: "✓ 19 passed" }],
    },
  ];

  const diffs: ToolDiff[] = [
    {
      file: "slots.ts",
      add: 4,
      del: 2,
      lines: [
        {
          text: "export function buildSlots(start: Date, service: Service) {",
          tone: "ctx",
        },
        { text: "  const end = addMinutes(start, service.length);", tone: "del" },
        { text: "  const end = addMinutes(start, service.length, {", tone: "add" },
        { text: "    tz: location.timeZone,", tone: "add" },
        { text: "  });", tone: "add" },
      ],
    },
    {
      file: "slots.test.ts",
      add: 18,
      del: 0,
      lines: [
        {
          text: 'it("keeps a 9:00 slot at 9:00 across the DST change", () => {',
          tone: "add",
        },
        {
          text: '  const slots = buildSlots(new Date("2026-03-29T09:00"), haircut);',
          tone: "add",
        },
        { text: '  expect(slots[0].start).toBe("09:00");', tone: "add" },
        { text: "});", tone: "add" },
      ],
    },
  ];
</script>

<ToolChips {steps} {diffs} />
```

### Agent still working on a fix

React · `agent-working.tsx`

```tsx
import { useEffect, useState } from "react";
import { ToolChips, type ToolDiff, type ToolStep } from "@/components/ui/tool-chips";

const steps: ToolStep[] = [
  {
    icon: "think",
    label: "Thinking",
    chip: "Finding where reminder emails get their time…",
    detail: [
      {
        text: "Reminders format the slot in UTC, so a 9:00 booking in Lisbon reads 8:00.",
      },
    ],
  },
  {
    icon: "search",
    label: "Search code",
    chip: "formatSlotTime",
    mono: true,
    detail: [
      { text: "3 matches in harbor/api" },
      { text: "src/mail/reminder.ts · src/mail/confirmation.ts · src/sms/reminder.ts" },
    ],
  },
  {
    icon: "read",
    label: "Read file",
    chip: "src/mail/reminder.ts",
    mono: true,
    detail: [{ text: "64 lines · renders the 24-hour reminder" }],
  },
  {
    icon: "write",
    label: "Edit 9 lines",
    chip: "src/mail/format.ts",
    mono: true,
    detailMono: true,
    detail: [
      { text: "+ export const formatSlotTime = (d: Date, tz: string) =>", tone: "add" },
      {
        text: '+   new Intl.DateTimeFormat(locale, { timeStyle: "short", timeZone: tz }).format(d)',
        tone: "add",
      },
    ],
  },
  {
    icon: "run",
    label: "Run tests",
    chip: "pnpm test mail",
    mono: true,
    detailMono: true,
    detail: [{ text: "✓ 27 passed" }],
  },
];

const diffs: ToolDiff[] = [
  {
    file: "format.ts",
    add: 9,
    del: 3,
    lines: [
      {
        text: "export const formatSlotTime = (d: Date) => d.toISOString().slice(11, 16);",
        tone: "del",
      },
      { text: "export const formatSlotTime = (d: Date, tz: string) =>", tone: "add" },
    ],
  },
  {
    file: "reminder.ts",
    add: 2,
    del: 2,
    lines: [
      { text: "  time: formatSlotTime(booking.start),", tone: "del" },
      {
        text: "  time: formatSlotTime(booking.start, booking.location.timeZone),",
        tone: "add",
      },
    ],
  },
];

export default function AgentWorking() {
  /* the agent reports a step about every second; the changed files come with the last one */
  const [shown, setShown] = useState(1);
  useEffect(() => {
    if (shown >= steps.length) return;
    const timer = window.setTimeout(() => setShown(shown + 1), 1100);
    return () => clearTimeout(timer);
  }, [shown]);
  const done = shown === steps.length;
  return <ToolChips steps={steps.slice(0, shown)} diffs={done ? diffs : []} />;
}
```

Vue · `agent-working.vue`

```vue
<script setup lang="ts">
import { computed, onBeforeUnmount, onMounted, ref } from "vue";
import { ToolChips, type ToolDiff, type ToolStep } from "@/components/ui/tool-chips";

const steps: ToolStep[] = [
  {
    icon: "think",
    label: "Thinking",
    chip: "Finding where reminder emails get their time…",
    detail: [
      {
        text: "Reminders format the slot in UTC, so a 9:00 booking in Lisbon reads 8:00.",
      },
    ],
  },
  {
    icon: "search",
    label: "Search code",
    chip: "formatSlotTime",
    mono: true,
    detail: [
      { text: "3 matches in harbor/api" },
      { text: "src/mail/reminder.ts · src/mail/confirmation.ts · src/sms/reminder.ts" },
    ],
  },
  {
    icon: "read",
    label: "Read file",
    chip: "src/mail/reminder.ts",
    mono: true,
    detail: [{ text: "64 lines · renders the 24-hour reminder" }],
  },
  {
    icon: "write",
    label: "Edit 9 lines",
    chip: "src/mail/format.ts",
    mono: true,
    detailMono: true,
    detail: [
      { text: "+ export const formatSlotTime = (d: Date, tz: string) =>", tone: "add" },
      {
        text: '+   new Intl.DateTimeFormat(locale, { timeStyle: "short", timeZone: tz }).format(d)',
        tone: "add",
      },
    ],
  },
  {
    icon: "run",
    label: "Run tests",
    chip: "pnpm test mail",
    mono: true,
    detailMono: true,
    detail: [{ text: "✓ 27 passed" }],
  },
];

const diffs: ToolDiff[] = [
  {
    file: "format.ts",
    add: 9,
    del: 3,
    lines: [
      {
        text: "export const formatSlotTime = (d: Date) => d.toISOString().slice(11, 16);",
        tone: "del",
      },
      { text: "export const formatSlotTime = (d: Date, tz: string) =>", tone: "add" },
    ],
  },
  {
    file: "reminder.ts",
    add: 2,
    del: 2,
    lines: [
      { text: "  time: formatSlotTime(booking.start),", tone: "del" },
      {
        text: "  time: formatSlotTime(booking.start, booking.location.timeZone),",
        tone: "add",
      },
    ],
  },
];

/* the agent reports a step about every second; the changed files come with the last one */
const shown = ref(1);
const done = computed(() => shown.value === steps.length);
let timer = 0;
const tick = () => {
  if (shown.value < steps.length) timer = window.setTimeout(() => { shown.value++; tick(); }, 1100);
};
onMounted(tick);
onBeforeUnmount(() => clearTimeout(timer));
</script>

<template>
  <ToolChips :steps="steps.slice(0, shown)" :diffs="done ? diffs : []" />
</template>
```

Svelte · `agent-working.svelte`

```svelte
<script lang="ts">
  import { onMount } from "svelte";
  import { ToolChips, type ToolDiff, type ToolStep } from "$lib/components/ui/tool-chips";

  const steps: ToolStep[] = [
    {
      icon: "think",
      label: "Thinking",
      chip: "Finding where reminder emails get their time…",
      detail: [
        {
          text: "Reminders format the slot in UTC, so a 9:00 booking in Lisbon reads 8:00.",
        },
      ],
    },
    {
      icon: "search",
      label: "Search code",
      chip: "formatSlotTime",
      mono: true,
      detail: [
        { text: "3 matches in harbor/api" },
        { text: "src/mail/reminder.ts · src/mail/confirmation.ts · src/sms/reminder.ts" },
      ],
    },
    {
      icon: "read",
      label: "Read file",
      chip: "src/mail/reminder.ts",
      mono: true,
      detail: [{ text: "64 lines · renders the 24-hour reminder" }],
    },
    {
      icon: "write",
      label: "Edit 9 lines",
      chip: "src/mail/format.ts",
      mono: true,
      detailMono: true,
      detail: [
        { text: "+ export const formatSlotTime = (d: Date, tz: string) =>", tone: "add" },
        {
          text: '+   new Intl.DateTimeFormat(locale, { timeStyle: "short", timeZone: tz }).format(d)',
          tone: "add",
        },
      ],
    },
    {
      icon: "run",
      label: "Run tests",
      chip: "pnpm test mail",
      mono: true,
      detailMono: true,
      detail: [{ text: "✓ 27 passed" }],
    },
  ];

  const diffs: ToolDiff[] = [
    {
      file: "format.ts",
      add: 9,
      del: 3,
      lines: [
        {
          text: "export const formatSlotTime = (d: Date) => d.toISOString().slice(11, 16);",
          tone: "del",
        },
        { text: "export const formatSlotTime = (d: Date, tz: string) =>", tone: "add" },
      ],
    },
    {
      file: "reminder.ts",
      add: 2,
      del: 2,
      lines: [
        { text: "  time: formatSlotTime(booking.start),", tone: "del" },
        {
          text: "  time: formatSlotTime(booking.start, booking.location.timeZone),",
          tone: "add",
        },
      ],
    },
  ];

  /* the agent reports a step about every second; the changed files come with the last one */
  let shown = $state(1);
  const done = $derived(shown === steps.length);
  onMount(() => {
    let timer = 0;
    const tick = () => {
      if (shown < steps.length) timer = window.setTimeout(() => { shown++; tick(); }, 1100);
    };
    tick();
    return () => clearTimeout(timer);
  });
</script>

<ToolChips steps={steps.slice(0, shown)} diffs={done ? diffs : []} />
```

### Review a finished refactor, step by step

React · `refactor-run.tsx`

```tsx
import { ToolChips, type ToolDiff, type ToolStep } from "@/components/ui/tool-chips";

const steps: ToolStep[] = [
  {
    icon: "think",
    label: "Thinking",
    chip: "Planning the move to the new mailer…",
    detail: [
      { text: "Invoice emails still call the legacy SMTP client in three places." },
      { text: "The new mailer needs a template id per locale; en-US and de-DE exist." },
    ],
  },
  {
    icon: "search",
    label: "Search code",
    chip: "sendInvoiceEmail",
    mono: true,
    detail: [
      { text: "4 matches in 3 files" },
      { text: "src/invoices/send.ts · src/jobs/dunning.ts · src/refunds/notify.ts" },
    ],
  },
  {
    icon: "read",
    label: "Read file",
    chip: "src/mail/client.ts",
    mono: true,
    detail: [{ text: "88 lines · exports createMailer, MailTemplate" }],
  },
  {
    icon: "write",
    label: "Edit 41 lines",
    chip: "src/invoices/send.ts",
    mono: true,
    detailMono: true,
    detail: [
      { text: "- await smtp.sendMail(buildInvoiceMail(invoice))" },
      {
        text: "+ const mailer = createMailer({ region: env.MAIL_REGION })",
        tone: "add",
      },
      {
        text: '+ await mailer.send("invoice.issued", { to, locale, invoice })',
        tone: "add",
      },
    ],
  },
  {
    icon: "run",
    label: "Run tests",
    chip: "pnpm vitest run src/invoices",
    mono: true,
    detailMono: true,
    detail: [{ text: "✓ 42 passed" }, { text: "✓ 3 snapshots updated" }],
  },
  {
    icon: "image",
    label: "Read image",
    chip: "invoice-email-preview.png",
    mono: true,
    detail: [
      { text: "1200 × 1600 · rendered invoice email, en-US" },
      { text: "Totals and the VAT line match the PDF invoice." },
    ],
  },
];

const diffs: ToolDiff[] = [
  {
    file: "send.ts",
    add: 38,
    del: 21,
    lines: [
      {
        text: "export async function sendInvoiceEmail(invoice: Invoice) {",
        tone: "ctx",
      },
      { text: "  await smtp.sendMail(buildInvoiceMail(invoice));", tone: "del" },
      {
        text: "  const mailer = createMailer({ region: env.MAIL_REGION });",
        tone: "add",
      },
      {
        text: '  await mailer.send("invoice.issued", { to, locale, invoice });',
        tone: "add",
      },
      { text: "}", tone: "ctx" },
    ],
  },
  {
    file: "dunning.ts",
    add: 9,
    del: 6,
    lines: [
      { text: "  await sendInvoiceEmail(invoice, { reminder: true });", tone: "ctx" },
      { text: "  attempts: 3,", tone: "del" },
      { text: "  attempts: env.DUNNING_ATTEMPTS,", tone: "add" },
    ],
  },
  {
    file: "notify.ts",
    add: 7,
    del: 4,
    lines: [
      { text: 'import { smtp } from "../legacy/smtp";', tone: "del" },
      { text: 'import { createMailer } from "../mail/client";', tone: "add" },
    ],
  },
  {
    file: "send.test.ts",
    add: 52,
    del: 0,
    lines: [
      {
        text: "it(\"sends invoice.issued in the customer's locale\", async () => {",
        tone: "add",
      },
      {
        text: '  expect(mailer.send).toHaveBeenCalledWith("invoice.issued", expect.anything());',
        tone: "add",
      },
    ],
  },
];

export default function RefactorRun() {
  return (
    <ToolChips
      steps={steps}
      diffs={diffs}
      defaultOpenRows={["Edit 41 lines", "Run tests"]}
      labels={{ header: "6 tool calls, 2 messages", more: "+3 more" }}
    />
  );
}
```

Vue · `refactor-run.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { ToolChips, type ToolDiff, type ToolStep } from "@/components/ui/tool-chips";

const steps: ToolStep[] = [
  {
    icon: "think",
    label: "Thinking",
    chip: "Planning the move to the new mailer…",
    detail: [
      { text: "Invoice emails still call the legacy SMTP client in three places." },
      { text: "The new mailer needs a template id per locale; en-US and de-DE exist." },
    ],
  },
  {
    icon: "search",
    label: "Search code",
    chip: "sendInvoiceEmail",
    mono: true,
    detail: [
      { text: "4 matches in 3 files" },
      { text: "src/invoices/send.ts · src/jobs/dunning.ts · src/refunds/notify.ts" },
    ],
  },
  {
    icon: "read",
    label: "Read file",
    chip: "src/mail/client.ts",
    mono: true,
    detail: [{ text: "88 lines · exports createMailer, MailTemplate" }],
  },
  {
    icon: "write",
    label: "Edit 41 lines",
    chip: "src/invoices/send.ts",
    mono: true,
    detailMono: true,
    detail: [
      { text: "- await smtp.sendMail(buildInvoiceMail(invoice))" },
      {
        text: "+ const mailer = createMailer({ region: env.MAIL_REGION })",
        tone: "add",
      },
      {
        text: '+ await mailer.send("invoice.issued", { to, locale, invoice })',
        tone: "add",
      },
    ],
  },
  {
    icon: "run",
    label: "Run tests",
    chip: "pnpm vitest run src/invoices",
    mono: true,
    detailMono: true,
    detail: [{ text: "✓ 42 passed" }, { text: "✓ 3 snapshots updated" }],
  },
  {
    icon: "image",
    label: "Read image",
    chip: "invoice-email-preview.png",
    mono: true,
    detail: [
      { text: "1200 × 1600 · rendered invoice email, en-US" },
      { text: "Totals and the VAT line match the PDF invoice." },
    ],
  },
];

const diffs: ToolDiff[] = [
  {
    file: "send.ts",
    add: 38,
    del: 21,
    lines: [
      {
        text: "export async function sendInvoiceEmail(invoice: Invoice) {",
        tone: "ctx",
      },
      { text: "  await smtp.sendMail(buildInvoiceMail(invoice));", tone: "del" },
      {
        text: "  const mailer = createMailer({ region: env.MAIL_REGION });",
        tone: "add",
      },
      {
        text: '  await mailer.send("invoice.issued", { to, locale, invoice });',
        tone: "add",
      },
      { text: "}", tone: "ctx" },
    ],
  },
  {
    file: "dunning.ts",
    add: 9,
    del: 6,
    lines: [
      { text: "  await sendInvoiceEmail(invoice, { reminder: true });", tone: "ctx" },
      { text: "  attempts: 3,", tone: "del" },
      { text: "  attempts: env.DUNNING_ATTEMPTS,", tone: "add" },
    ],
  },
  {
    file: "notify.ts",
    add: 7,
    del: 4,
    lines: [
      { text: 'import { smtp } from "../legacy/smtp";', tone: "del" },
      { text: 'import { createMailer } from "../mail/client";', tone: "add" },
    ],
  },
  {
    file: "send.test.ts",
    add: 52,
    del: 0,
    lines: [
      {
        text: "it(\"sends invoice.issued in the customer's locale\", async () => {",
        tone: "add",
      },
      {
        text: '  expect(mailer.send).toHaveBeenCalledWith("invoice.issued", expect.anything());',
        tone: "add",
      },
    ],
  },
];

const openRows = ref(["Edit 41 lines", "Run tests"]);
</script>

<template>
  <ToolChips
    v-model:open-rows="openRows"
    :steps="steps"
    :diffs="diffs"
    :labels="{ header: '6 tool calls, 2 messages', more: '+3 more' }"
  />
</template>
```

Svelte · `refactor-run.svelte`

```svelte
<script lang="ts">
  import { ToolChips, type ToolDiff, type ToolStep } from "$lib/components/ui/tool-chips";

  const steps: ToolStep[] = [
    {
      icon: "think",
      label: "Thinking",
      chip: "Planning the move to the new mailer…",
      detail: [
        { text: "Invoice emails still call the legacy SMTP client in three places." },
        { text: "The new mailer needs a template id per locale; en-US and de-DE exist." },
      ],
    },
    {
      icon: "search",
      label: "Search code",
      chip: "sendInvoiceEmail",
      mono: true,
      detail: [
        { text: "4 matches in 3 files" },
        { text: "src/invoices/send.ts · src/jobs/dunning.ts · src/refunds/notify.ts" },
      ],
    },
    {
      icon: "read",
      label: "Read file",
      chip: "src/mail/client.ts",
      mono: true,
      detail: [{ text: "88 lines · exports createMailer, MailTemplate" }],
    },
    {
      icon: "write",
      label: "Edit 41 lines",
      chip: "src/invoices/send.ts",
      mono: true,
      detailMono: true,
      detail: [
        { text: "- await smtp.sendMail(buildInvoiceMail(invoice))" },
        {
          text: "+ const mailer = createMailer({ region: env.MAIL_REGION })",
          tone: "add",
        },
        {
          text: '+ await mailer.send("invoice.issued", { to, locale, invoice })',
          tone: "add",
        },
      ],
    },
    {
      icon: "run",
      label: "Run tests",
      chip: "pnpm vitest run src/invoices",
      mono: true,
      detailMono: true,
      detail: [{ text: "✓ 42 passed" }, { text: "✓ 3 snapshots updated" }],
    },
    {
      icon: "image",
      label: "Read image",
      chip: "invoice-email-preview.png",
      mono: true,
      detail: [
        { text: "1200 × 1600 · rendered invoice email, en-US" },
        { text: "Totals and the VAT line match the PDF invoice." },
      ],
    },
  ];

  const diffs: ToolDiff[] = [
    {
      file: "send.ts",
      add: 38,
      del: 21,
      lines: [
        {
          text: "export async function sendInvoiceEmail(invoice: Invoice) {",
          tone: "ctx",
        },
        { text: "  await smtp.sendMail(buildInvoiceMail(invoice));", tone: "del" },
        {
          text: "  const mailer = createMailer({ region: env.MAIL_REGION });",
          tone: "add",
        },
        {
          text: '  await mailer.send("invoice.issued", { to, locale, invoice });',
          tone: "add",
        },
        { text: "}", tone: "ctx" },
      ],
    },
    {
      file: "dunning.ts",
      add: 9,
      del: 6,
      lines: [
        { text: "  await sendInvoiceEmail(invoice, { reminder: true });", tone: "ctx" },
        { text: "  attempts: 3,", tone: "del" },
        { text: "  attempts: env.DUNNING_ATTEMPTS,", tone: "add" },
      ],
    },
    {
      file: "notify.ts",
      add: 7,
      del: 4,
      lines: [
        { text: 'import { smtp } from "../legacy/smtp";', tone: "del" },
        { text: 'import { createMailer } from "../mail/client";', tone: "add" },
      ],
    },
    {
      file: "send.test.ts",
      add: 52,
      del: 0,
      lines: [
        {
          text: "it(\"sends invoice.issued in the customer's locale\", async () => {",
          tone: "add",
        },
        {
          text: '  expect(mailer.send).toHaveBeenCalledWith("invoice.issued", expect.anything());',
          tone: "add",
        },
      ],
    },
  ];

  let openRows = $state(["Edit 41 lines", "Run tests"]);
</script>

<ToolChips
  bind:openRows
  {steps}
  {diffs}
  labels={{ header: "6 tool calls, 2 messages", more: "+3 more" }}
/>
```

### Earlier run, folded in the chat

React · `folded.tsx`

```tsx
import { ToolChips, type ToolDiff, type ToolStep } from "@/components/ui/tool-chips";

const steps: ToolStep[] = [
  {
    icon: "search",
    label: "Search logs",
    chip: "booking_conflict last 24h",
    detail: [{ text: "112 events, all from Juniper Health's Denver location" }],
  },
  {
    icon: "read",
    label: "Read file",
    chip: "src/booking/conflicts.ts",
    mono: true,
    detail: [{ text: "140 lines · exports findConflicts" }],
  },
  {
    icon: "write",
    label: "Edit 3 lines",
    chip: "src/booking/conflicts.ts",
    mono: true,
    detailMono: true,
    detail: [{ text: "+ if (a.roomId !== b.roomId) return false;", tone: "add" }],
  },
  {
    icon: "run",
    label: "Run tests",
    chip: "pnpm test conflicts",
    mono: true,
    detailMono: true,
    detail: [{ text: "✓ 31 passed" }],
  },
];

const diffs: ToolDiff[] = [
  {
    file: "conflicts.ts",
    add: 3,
    del: 0,
    lines: [
      { text: "export function overlaps(a: Booking, b: Booking) {", tone: "ctx" },
      { text: "  if (a.roomId !== b.roomId) return false;", tone: "add" },
    ],
  },
];

export default function Folded() {
  return <ToolChips steps={steps} diffs={diffs} defaultOpen={false} />;
}
```

Vue · `folded.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { ToolChips, type ToolDiff, type ToolStep } from "@/components/ui/tool-chips";

const steps: ToolStep[] = [
  {
    icon: "search",
    label: "Search logs",
    chip: "booking_conflict last 24h",
    detail: [{ text: "112 events, all from Juniper Health's Denver location" }],
  },
  {
    icon: "read",
    label: "Read file",
    chip: "src/booking/conflicts.ts",
    mono: true,
    detail: [{ text: "140 lines · exports findConflicts" }],
  },
  {
    icon: "write",
    label: "Edit 3 lines",
    chip: "src/booking/conflicts.ts",
    mono: true,
    detailMono: true,
    detail: [{ text: "+ if (a.roomId !== b.roomId) return false;", tone: "add" }],
  },
  {
    icon: "run",
    label: "Run tests",
    chip: "pnpm test conflicts",
    mono: true,
    detailMono: true,
    detail: [{ text: "✓ 31 passed" }],
  },
];

const diffs: ToolDiff[] = [
  {
    file: "conflicts.ts",
    add: 3,
    del: 0,
    lines: [
      { text: "export function overlaps(a: Booking, b: Booking) {", tone: "ctx" },
      { text: "  if (a.roomId !== b.roomId) return false;", tone: "add" },
    ],
  },
];

const open = ref(false);
</script>

<template>
  <ToolChips v-model:open="open" :steps="steps" :diffs="diffs" />
</template>
```

Svelte · `folded.svelte`

```svelte
<script lang="ts">
  import { ToolChips, type ToolDiff, type ToolStep } from "$lib/components/ui/tool-chips";

  const steps: ToolStep[] = [
    {
      icon: "search",
      label: "Search logs",
      chip: "booking_conflict last 24h",
      detail: [{ text: "112 events, all from Juniper Health's Denver location" }],
    },
    {
      icon: "read",
      label: "Read file",
      chip: "src/booking/conflicts.ts",
      mono: true,
      detail: [{ text: "140 lines · exports findConflicts" }],
    },
    {
      icon: "write",
      label: "Edit 3 lines",
      chip: "src/booking/conflicts.ts",
      mono: true,
      detailMono: true,
      detail: [{ text: "+ if (a.roomId !== b.roomId) return false;", tone: "add" }],
    },
    {
      icon: "run",
      label: "Run tests",
      chip: "pnpm test conflicts",
      mono: true,
      detailMono: true,
      detail: [{ text: "✓ 31 passed" }],
    },
  ];

  const diffs: ToolDiff[] = [
    {
      file: "conflicts.ts",
      add: 3,
      del: 0,
      lines: [
        { text: "export function overlaps(a: Booking, b: Booking) {", tone: "ctx" },
        { text: "  if (a.roomId !== b.roomId) return false;", tone: "add" },
      ],
    },
  ];

  let open = $state(false);
</script>

<ToolChips bind:open {steps} {diffs} />
```

## Recipe

`tool-chips.recipe.ts`:

```ts
import { tv, type VariantProps } from "../lib/tv";

/* tool-chips — an agent run as compact rows: tool calls with inline value chips, then file-diff
 * chips. The run and every step are the real Collapsible (inline, caret first): it owns the
 * triggers' hover, press, caret and the reveal; the run and the steps are marked data-tool-chips="run|step"; this recipe sizes its parts (the trigger through
 * triggerClass, the caret, label and body by name from the collapsible's root). A step's tool glyph
 * sits over its caret and hands over to it on hover, focus or open. Each file chip is the real
 * hover-card trigger (its recipe classes) laid out as a row, previewing the diff.
 * Fully controlled: the host owns the steps, the diffs and which rows are open.
 *
 * Motion (`docs motion`), all here:
 *   mount     a mount is not an arrival: a plain mount shows its steps and diffs at once. With
 *             appear (the host's prop, for a run its code adds live) the steps present at first
 *             render fade up, staggered and capped (--fndn-row-index, set by the adapter only on
 *             those steps), and the diff row follows as one more beat, fading in place.
 *   arrival   a step added after mount always enters, with no delay, and opens its room; a diff
 *             row added after mount always fades in.
 *   run       the collapsible reveals the whole run as one container; nothing inside enters again
 *   row       the collapsible reveals the detail as one container; its lines do not move
 *   caret     the collapsible's caret turns; on a step it crossfades in place with the tool glyph */

export const toolChips = tv({
  slots: {
    base: "w-full max-w-[320px] min-w-0 pb-1",
    /* the run's collapsible root: its caret at 12px; -4px + 6px gives the rows' hover fills and
     * focus rings room inside the region's clip box */
    run: [
      /* its header: the collapsible's inline trigger at this component's size (text-dense, regular weight) */
      "[&>[data-slot=collapsible-trigger]]:gap-1.5 [&>[data-slot=collapsible-trigger]]:text-dense [&>[data-slot=collapsible-trigger]]:font-normal [&>[data-slot=collapsible-trigger]]:tabular-nums",
      "[&>[data-slot=collapsible-trigger]>[data-slot=collapsible-caret]]:text-[12px]",
      "[&>[data-slot=collapsible-content]>[data-slot=collapsible-body]]:-mx-1",
      "[&>[data-slot=collapsible-content]>[data-slot=collapsible-body]]:px-1.5",
      "[&>[data-slot=collapsible-content]>[data-slot=collapsible-body]]:pt-0",
      "[&>[data-slot=collapsible-content]>[data-slot=collapsible-body]]:pb-1",
    ],
    rows: "flex flex-col gap-1 mt-1.5",
    /* a step's collapsible root. Only steps present at first render carry --fndn-row-index; a step
     * that arrives later enters at once. Its label lays the glyph, label and value out in a row
     * (the parts truncate themselves; the value chip's hairline must not be clipped). Its caret is
     * a 16px slot under the glyph, shown on hover, focus or open. */
    /* A step that arrives after the first render makes its room as it fades up, so the diffs below
     * slide down instead of jumping: its first track opens from minmax(0, var(--fndn-row-room)) at
     * @starting-style to minmax(0,1fr) over duration.reveal, out-strong (the collapsible's reveal).
     * The adapter sets --fndn-row-room: 0fr on an arriving step only; a step present at first render
     * starts at 1fr, so nothing moves on first paint. The second track holds the step's own region.
     * Clipped vertically only: the trigger bleeds 3px sideways.
     * fndn-check-ok: grid-template-rows is the sanctioned way to open room; one track, the step's own */
    step: [
      "grid grid-rows-[minmax(0,1fr)_auto] [overflow-y:clip] motion-size-reveal starting:grid-rows-[minmax(0,var(--fndn-row-room,1fr))_auto]",
      "animate-[fndn-fade-up_var(--fndn-duration-enter)_var(--fndn-easing-out-strong)_calc(min(var(--fndn-row-index,0),var(--fndn-motion-stagger-max))*var(--fndn-duration-stagger))_both]",
      /* the trigger stretched to a 28px row. The run's body clips (it is the reveal) and a step is
       * nearly as wide as it: the ring is drawn inside the step. */
      "[&>[data-slot=collapsible-trigger]]:w-[calc(100%+6px)] [&>[data-slot=collapsible-trigger]]:max-w-none [&>[data-slot=collapsible-trigger]]:h-7 [&>[data-slot=collapsible-trigger]]:-mx-[3px] [&>[data-slot=collapsible-trigger]]:px-[3px] [&>[data-slot=collapsible-trigger]]:py-0 [&>[data-slot=collapsible-trigger]]:text-ink",
      "[&>[data-slot=collapsible-trigger]:focus-visible]:outline-offset-[-2px]",
      "[&>[data-slot=collapsible-trigger]>[data-slot=collapsible-label]]:flex",
      "[&>[data-slot=collapsible-trigger]>[data-slot=collapsible-label]]:flex-[1_1_auto]",
      "[&>[data-slot=collapsible-trigger]>[data-slot=collapsible-label]]:items-center",
      "[&>[data-slot=collapsible-trigger]>[data-slot=collapsible-label]]:gap-2",
      "[&>[data-slot=collapsible-trigger]>[data-slot=collapsible-label]]:overflow-visible",
      "[&>[data-slot=collapsible-trigger]>[data-slot=collapsible-caret]]:size-4",
      "[&>[data-slot=collapsible-trigger]>[data-slot=collapsible-caret]]:text-[12px]",
      "[&>[data-slot=collapsible-trigger]>[data-slot=collapsible-caret]]:opacity-0",
      "[&>[data-slot=collapsible-trigger]>[data-slot=collapsible-caret]]:motion-opacity-fast",
      "[&>[data-slot=collapsible-trigger]:is([data-state=open],:focus-visible)>[data-slot=collapsible-caret]]:opacity-100",
      "[@media(hover:hover)_and_(pointer:fine)]:[&>[data-slot=collapsible-trigger]:hover>[data-slot=collapsible-caret]]:opacity-100",
    ],
    /* the tool glyph, over the caret */
    icon: [
      "absolute inset-y-0 start-[3px] grid w-4 place-items-center text-[13px] text-ink-3 motion-opacity-fast",
      "[&>svg[data-slot=icon]]:size-[13px]",
      "[[data-slot=collapsible-trigger]:is([data-state=open],:focus-visible)_&]:opacity-0",
      "[@media(hover:hover)_and_(pointer:fine)]:[[data-slot=collapsible-trigger]:hover_&]:opacity-0",
    ],
    label: "flex-[0_1_auto] min-w-0 max-w-[60%] overflow-hidden text-ellipsis whitespace-nowrap text-dense font-medium text-ink [unicode-bidi:plaintext]",
    /* the value chip takes the row's hover fill, keeping its hairline */
    value: [
      "inline-flex flex-[1_1_0] min-w-0 h-[22px] items-center px-1.5 rounded-chip bg-field shadow-hairline",
      "text-[11.5px] font-normal text-ink-2 whitespace-nowrap motion-colors-fast",
      "[&>span]:min-w-0 [&>span]:overflow-hidden [&>span]:text-ellipsis [&>span]:[unicode-bidi:plaintext]",
      "[@media(hover:hover)_and_(pointer:fine)]:[[data-slot=collapsible-trigger]:hover:not(:active)_&]:bg-hover",
      "[[data-slot=collapsible-trigger]:active_&]:bg-hover-2",
    ],
    /* the step's detail, inside its collapsible region */
    lines: "flex flex-col gap-0.5 min-w-0 mt-0.5 mb-1 ms-2 py-0.5 ps-3.5 border-s border-line",
    line: "min-w-0 overflow-hidden text-ellipsis whitespace-nowrap text-[11.5px] leading-[1.6] text-ink-2 [unicode-bidi:plaintext]",
    /* file-diff chips: the row enters as one beat after the steps. It sits on the run's clipping
     * edge: a rise would show its chips cut at the bottom, so it fades in place (the beat is kept). */
    diffs: [
      "flex flex-wrap gap-1.5 max-w-full mt-2.5 pt-2.5 border-t border-line",
      "animate-[fndn-fade-in_var(--fndn-duration-enter)_ease_calc(min(var(--fndn-row-index,0),var(--fndn-motion-stagger-max))*var(--fndn-duration-stagger))_both]",
    ],
    /* added to the hover-card's chip trigger: laid out so the counts stay whole and the file name
     * truncates */
    diff: [
      "inline-flex min-w-0 items-center gap-2 tabular-nums",
      "[&>span:first-child]:min-w-0 [&>span:first-child]:overflow-hidden [&>span:first-child]:text-ellipsis [&>span:first-child]:[unicode-bidi:plaintext]",
    ],
    /* a count reads "+13" / "−41" on a right-to-left page too */
    add: "shrink-0 text-green [direction:ltr] [unicode-bidi:isolate]",
    del: "shrink-0 text-red [direction:ltr] [unicode-bidi:isolate]",
    /* each file wraps its chip and lays out as if it were not there */
    file: "contents",
    more: [
      "inline-flex shrink-0 h-7 items-center px-1.5 rounded-chip font-mono text-[11.5px] tabular-nums whitespace-nowrap text-ink-2",
      "underline decoration-transparent underline-offset-2 hover:text-ink hover:decoration-current",
      "motion-colors-fast motion-transform-press active:scale-press",
    ],
  },
  variants: {
    /* appear=false (the default): the steps and the diff row present at mount are simply there;
     * what is added later still enters. Set per part by the adapter. */
    appear: { true: {}, false: { step: "animate-none", diffs: "animate-none" } },
    /* a value chip or a step's detail that is code */
    mono: { true: { value: "font-mono", lines: "font-mono" } },
    /* a detail line that was added */
    tone: { add: { line: "text-green" } },
    /* the last file also holds the more button and keeps the two on one line: it counts as 160px
     * when the row wraps, then grows into the room left, so the chip's file name truncates before
     * "+2 more" would go to a line of its own */
    withMore: {
      true: { file: "flex flex-[1_1_160px] min-w-0 max-w-full items-center gap-1.5" },
    },
  },
});

export type ToolChipsRecipeProps = VariantProps<typeof toolChips>;
```
