<!-- generated by scripts/gen-docs.mjs from docs/system/trace.md. Edit the source and rerun. -->
# Trace

## Description
Shows what an agent did to reach its answer, step by step, so a person can check where an answer came from or see where it went wrong, folded away until they want it.

`import { Trace, TraceStep } from "@/components/cobalt/ui/trace"`, source `registry/cobalt/ui/trace.tsx`, status `ready-with-gaps`.
Foundation: `Base UI Collapsible`. Traps checked: `trap/color-only-status`, `trap/loader-small-dots`, `trap/reduced-motion-ignored`, `trap/numbers-shift`, `trap/button-icon-name`, `trap/loading-layout-shift`.

`trap/color-only-status` is answered by each status's own mark, a check, a turning quarter, a dashed circle and a cross, and by its word read before each title, "Done", "Running", "Queued" or "Failed" (States, ARIA). `trap/loader-small-dots` by the running mark being the full 16px circle the other marks are, with "Running" read for it. `trap/reduced-motion-ignored` by the collapsible's height motion, which stops under reduced motion, and the running mark, which holds still. `trap/numbers-shift` by tabular figures on every duration, right-aligned in their own column. `trap/button-icon-name` by every trigger carrying its words, the chevron only beside them. `trap/loading-layout-shift` by every line being 32px in every status, so a step that starts or ends moves nothing under it.

### Foundation
| Given by the foundation | Added by the team |
|---|---|
| Base UI `Collapsible` through the system `Collapsible`: the summary and each step with detail open their panel, with `aria-expanded` | A three-column grid every line shares through `subgrid`: a 16px mark, the words, and the step durations right-aligned as a table's figures; one drawn circle per status at one radius, so the marks stand on one axis; a 1px rail joining the marks 4px clear of each; the summary as one line, "Searched 3 sources, 4.2 s"; a failed step's reason in words under its title; a step's detail indented to its title. Tag has no trace; the pattern is the tool-call parts of agent chat kits, kept to these four statuses |

## Examples
A finished trace of three steps, opened, one of them opened to what it sent.

Real uses, 0 call sites (`rg -n "<Trace\b" app registry --glob '!registry/cobalt/ui/*'`): the message and thread examples render it in an assistant's reply, `docs/system/examples/message/agent.tsx` and `docs/system/examples/thread/in-assistant.tsx`.

### Example files
| File | Covers | Caption |
|---|---|---|
| `docs/system/examples/trace/default.tsx` | default | How a research assistant reached its answer: one line that says what it did and how long it took, opened to the steps, and a step opened to what it sent and got back |
| `docs/system/examples/trace/in-card.tsx` | composition:Card | A nightly import beside its result, its trace closed, with the one step that failed and what the import did without it |
| `docs/system/examples/trace/state-statuses.tsx` | state:running | Every status on one axis: done with a check, failed with a cross and why under it, running turning, queued dashed. The times line up as figures in a table |

Example: How a research assistant reached its answer: one line that says what it did and how long it took, opened to the steps, and a step opened to what it sent and got back (`docs/system/examples/trace/default.tsx`)

```tsx
import { Trace, TraceStep } from "@/components/cobalt/ui/trace";

export default function Example() {
  return (
    <div className="w-full max-w-xl">
      <Trace summary="Searched 3 sources" duration="4.2 s" defaultOpen>
        <TraceStep status="done" title="Searched EDGAR for Harbour Street Master Fund" duration="0.8 s">
          {'search_filings({ filer: "Harbour Street Master Fund LP", forms: ["13F-HR"] })\n→ 3 filings, latest 2026-08-14'}
        </TraceStep>
        <TraceStep status="done" title="Read the Q3 13F-HR" duration="2.1 s" />
        <TraceStep status="done" title="Compared holdings with Q2" duration="1.3 s" />
      </Trace>
    </div>
  );
}
```

Example: A nightly import beside its result, its trace closed, with the one step that failed and what the import did without it (`docs/system/examples/trace/in-card.tsx`)

```tsx
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/cobalt/ui/card";
import { Trace, TraceStep } from "@/components/cobalt/ui/trace";

export default function Example() {
  return (
    <Card className="w-full max-w-md">
      <CardHeader>
        <CardTitle render={<h3 />}>13F filings, Oct 17</CardTitle>
        <CardDescription>412 filers, 61,208 positions. 3 filers left out.</CardDescription>
      </CardHeader>
      <CardContent>
        <Trace summary="Imported in 4 steps" duration="6 min 12 s">
          <TraceStep status="done" title="Fetched the EDGAR daily index" duration="8 s" />
          <TraceStep status="done" title="Downloaded 415 filings" duration="3 min 40 s" />
          <TraceStep
            status="failed"
            title="Parsed 3 information tables"
            duration="12 s"
            error="Their XML did not match the 13F schema. The 3 filers are left out until they amend."
          />
          <TraceStep status="done" title="Matched 61,208 positions to securities" duration="2 min 12 s" />
        </Trace>
      </CardContent>
    </Card>
  );
}
```

## Variants
Not applicable: a trace has one look; a step's status is its state.

## States
| State | Trigger | What the user can do | Shown by, besides color | Checked by |
|---|---|---|---|---|
| closed | default | open it | the summary, a comma and the total time, and a chevron pointing down | test |
| open | the summary pressed | read the steps, close it | the steps under it on the rail, the chevron turned over | screenshot |
| queued | `status="queued"` | read what will run | a dashed circle, the title in the muted grey, no time, "Queued" read first | test |
| running | `status="running"` | wait | a quarter of the circle turning, no time yet, "Running" read first; on the summary, `status="running"` turns its mark | test |
| done | `status="done"` | open its detail | a circle with a check and its time | test |
| failed | `status="failed"` | open its detail, read why | a circle with a cross in red, `error` in words under the title, its time, "Failed" read first | test |
| detail open | a step's line pressed | read what it sent and got back | the detail in a grey mono block, indented to the title | screenshot |

Example: Every status on one axis: done with a check, failed with a cross and why under it, running turning, queued dashed. The times line up as figures in a table (`docs/system/examples/trace/state-statuses.tsx`)

```tsx
import { Trace, TraceStep } from "@/components/cobalt/ui/trace";

export default function Example() {
  return (
    <div className="w-full max-w-xl">
      <Trace summary="Reading 3 filings" duration="6.4 s" status="running" defaultOpen>
        <TraceStep status="done" title="Searched EDGAR for Harbour Street" duration="0.8 s" />
        <TraceStep status="done" title="Read the Q3 13F-HR" duration="2.1 s">
          {"read_filing(0001104659-26-112233)\n→ 192 positions, $48.2B"}
        </TraceStep>
        <TraceStep
          status="failed"
          title="Read the Q2 amendment"
          duration="12.0 s"
          error="EDGAR timed out. The answer uses the original Q2 filing."
        />
        <TraceStep status="running" title="Reading the Q2 13F-HR" />
        <TraceStep status="queued" title="Compare the two quarters" />
      </Trace>
    </div>
  );
}
```

### State precedence
- Queued, running, done and failed: Not applicable: a step has one status.
- Running and closed: both show. The summary's mark turns and its words name the step under way while the steps are folded.
- Failed and detail open: both show. The reason stays under the title above the detail.

### Motion
| Trigger | Kind | Preset | Properties | Reduced motion |
|---|---|---|---|---|
| open or close the trace or a step | announce | the `Collapsible` panel, `--t-settle` open and `--t-leave` closed | height, opacity | no animation |
| the chevron turns | announce | `--t-settle`, `--t-leave` | transform rotate | no animation |
| the summary's rail shows as the steps open | announce | `--t-settle` | opacity | the same fade |
| the summary's colour under the pointer | input | `--t-press` | color | the same |
| running | announce | `animate-spin` on the mark | rotate | the mark holds still |

## Props

<!-- Props generated from registry/cobalt/ui/trace.tsx with TypeScript by scripts/props-table.mjs -->
### Trace

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `children` | `ReactNode` |  | `TraceStep`s, in the order they ran. |
| `summary` | `ReactNode` |  | What was done, in a few words: "Searched 3 sources". |
| `className?` | `string` |  |  |
| `defaultOpen?` | `boolean` | `false` |  |
| `duration?` | `ReactNode` |  | How long it took in all, such as "4.2 s". |
| `labels?` | `Partial<Record<TraceStatus, string>>` |  | Each status in words, read before each step's title by a screen reader. |
| `status?` | `"failed" \| "done" \| "running"` | `"done"` | Where the work as a whole is. |

### TraceStep

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `status` | `TraceStatus` |  |  |
| `title` | `ReactNode` |  | What it did, in the past tense once done: "Read the Q3 13F-HR". |
| `children?` | `ReactNode` |  | What it sent and got back, shown when opened. |
| `duration?` | `ReactNode` |  | How long it took, once it is done or failed. |
| `error?` | `ReactNode` |  | Why it failed, and what the answer did without it. |

`Trace` takes `summary`, `duration` (the total), `status` (`running`, `done` or `failed`, for the summary's mark), `defaultOpen`, `labels` (each status's word) and the steps as children. `TraceStep` takes `status`, `title`, `duration`, `error` and its detail as children.

## Usage

### When to use
- An agent's reply that read, searched or ran something a person may want to check.
- A long job's steps beside its result, such as an import.

### When not to use
- A record's history of changes. Use Timeline instead.
- A long job a person waits on with a share done. Use Progress instead.

### Rules
- `rule/trace-closed-by-default`: When an agent's answer is shown, keep its `Trace` closed above it, because the answer is what was asked for and the steps are there to check it. Evidence: principle heuristic: aesthetic and minimalist design, the answer leads. Check: review of every `Trace` with `defaultOpen` in a message.
  - Don't: `<Trace summary="Read 3 filings" defaultOpen>` above an answer
  - Do: `<Trace summary="Read 3 filings" duration="4.2 s">`
- `rule/trace-failure-in-words`: When a step fails, pass `error` with what failed and what the answer did without it, because a red cross says something went wrong but not what or whether the answer still holds. Evidence: principle heuristic: help users recognize, diagnose and recover from errors. Check: review of every failed `TraceStep`.
  - Don't: `<TraceStep status="failed" title="Read the Q2 13F-HR" />`
  - Do: `<TraceStep status="failed" title="Read the Q2 13F-HR" error="EDGAR timed out. The answer uses the original Q2 filing." />`

### Content
- Follows `rule/writing-status-verb-ing`.
- `rule/trace-step-titles`: When titling a step, say what it did to what in the past tense once done, such as "Read the Q3 13F-HR", and what it is doing while it runs, "Reading the Q3 13F-HR", in at most 8 words, instead of a tool's name, because people read actions, not function names. Evidence: principle heuristic: match between the system and the real world. Check: review.
  - Don't: `title="read_filing"`
  - Do: `title="Read the Q3 13F-HR"`

### Anti-slop
- `rule/trace-no-new-shapes`: When showing steps, use `TraceStep`, whose marks already say done, under way, still to come and failed, instead of status icons, badges or progress bars per step, because a second set of shapes breaks the one axis the marks stand on. Evidence: person D13; measured every mark's centre on one x within 0.5px at 390 and 1440, `.design-system/evidence/trace/alignment.json`. Check: review.
  - Don't: `<Badge>Completed</Badge>` on each step
  - Do: `<TraceStep status="done" title="Read the Q3 13F-HR" duration="2.1 s" />`

### Limits
- `rule/trace-steps`: When a trace has more than 12 steps, group them into fewer steps with a summary of each, because at 12 steps of 32px the open list is over 400px, taller than most answers it explains. Evidence: measured 32px for every one-line step, `.design-system/evidence/trace/alignment.json`, from docs/system/stress/trace.tsx. Check: probe in docs/system/stress/trace.tsx.
  - Don't: 40 `TraceStep`s, one per page read
  - Do: `<TraceStep status="done" title="Read 40 pages of the prospectus" duration="12 s" />`

## Accessibility
Rests on Base UI `Collapsible` and an ordered list of steps.

### Keyboard
| Key | Where focus is | Effect | Focus after | Checked by |
|---|---|---|---|---|
| Tab | before the trace | moves to the summary, then each step with detail when open | the next trigger | by hand |
| Enter or Space | the summary | opens or closes the steps | stays on the summary | by hand |
| Enter or Space | a step's line | opens or closes its detail | stays on the line | by hand |

### ARIA
| Part | Role | Accessible name from | States and properties | Announced | Checked by |
|---|---|---|---|---|---|
| summary | button | its status word, its words and the total | `aria-expanded`, `aria-controls` | "Done, Searched 3 sources, 4.2 s, button, collapsed" | test |
| steps | list | none | ordered | "list, 3 items" | test |
| step with detail | button | its status word, title and time | `aria-expanded` | "Done, Read the Q3 13F-HR, 2.1 s, button, collapsed" | test |
| step without detail | none | its status word, title and time | none | "Failed, Read the Q2 amendment, 12.0 s" | test |
| marks | none | none | `aria-hidden` | nothing; the words carry the status | test |

## Tokens
| Part | State | Token |
|---|---|---|
| summary | all | `--muted-foreground`, `--foreground` on hover, `--t-press` |
| marks | done, queued | `--muted-foreground` |
| marks | running | `--foreground` |
| marks | failed | `--destructive` |
| rail | all | `--border` |
| reason | failed | `--muted-foreground` |
| detail | open | `--muted`, `--r-lg`, `--mono` |
| panel | open, closed | `--t-settle`, `--t-leave`, `--curve` |

## Related
- Message: the assistant's reply a trace sits in.
- Timeline: a record's history of changes.
- Collapsible: the fold a trace opens with.
