# Trace

> An AI agent's steps as a list: an icon per kind, a title, status text, duration and expandable tool input and output.

- Kind: ui · Category: Data display · Interactivity: native
- Install: `npx shadcn@latest add @haze/trace`
- File: `src/components/haze/ui/trace.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/ui/trace

## Use when
- An assistant works through several steps and the user should see what it searched, read, edited and ran
- A tool call needs its raw input or output available on demand without crowding the list
- A failed or skipped step must be visible next to the steps that worked

## Avoid when
- Events are dated entries in a history, not steps of one run. Use timeline.
- The output is a raw stream of log lines. Use log-viewer.
- Progress through a user-driven flow is shown with numbered stages. Use stepper.

## Alternatives
- [timeline](https://hazeui.com/ui/timeline.md)
- [log-viewer](https://hazeui.com/ui/log-viewer.md)
- [stepper](https://hazeui.com/ui/stepper.md)
- [accordion](https://hazeui.com/ui/accordion.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| steps | `{ kind: "tool" \| "thought" \| "search" \| "edit" \| "message"; title: string; description?: string; status?: "running" \| "done" \| "error" \| "skipped"; duration?: string; href?: string; detail?: string; open?: boolean }[]` | five-step agent run | no | Steps in order. href makes the title a link; detail adds an expandable block. |
| label | `string` | "Agent steps" | no | Accessible name of the list. |
| detailLabel | `string` | "Details" | no | Summary text of the expandable detail. |
| kindLabels | `Record<kind, string>` | Tool call, Reasoning, Search, File edit, Message | no | Screen-reader prefix for each step kind. Translate it. |
| statusLabels | `Record<status, string>` | Running, Done, Failed, Skipped | no | Visible status text. Translate it. |
| class | `string` |  | no | Extra classes on the list. |

## Accessibility
- Steps are an ordered list. Each title starts with its kind for screen readers, because the icon is decorative.
- Status is always text next to its icon, never color alone. The spinning icon of a running step stops under reduced motion and the word Running remains.
- Details use native details and summary. The block scrolls inside itself, is focusable and has its own label so keyboard users can scroll it.
- The thin line joining the steps is decorative and hidden from assistive technology.
- Key Tab: Move through step links, detail toggles and focusable detail blocks.
- Key Enter / Space: Open or close a step's detail.
- Key Arrow keys: Scroll a focused detail block.

## Agent prompts

### Install and use

Install the Haze UI component "Trace" with `npx shadcn@latest add @haze/trace`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import Trace from "@/components/haze/ui/trace.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/ui/trace.md

### Customize with real content

Adapt the Haze trace ui for our product. Replace the demo values of these props with our real content: steps, label, detailLabel, kindLabels, statusLabels, class. Keep the layout, the heading level rules and these accessibility details: Steps are an ordered list. Each title starts with its kind for screen readers, because the icon is decorative. Status is always text next to its icon, never color alone. The spinning icon of a running step stops under reduced motion and the word Running remains. Details use native details and summary. The block scrolls inside itself, is focusable and has its own label so keyboard users can scroll it. The thin line joining the steps is decorative and hidden from assistive technology. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using trace, check it fits: use it when an assistant works through several steps and the user should see what it searched, read, edited and ran; a tool call needs its raw input or output available on demand without crowding the list; a failed or skipped step must be visible next to the steps that worked. Avoid it when events are dated entries in a history, not steps of one run. use timeline.; the output is a raw stream of log lines. use log-viewer.; progress through a user-driven flow is shown with numbered stages. use stepper.. Alternatives: @haze/timeline, @haze/log-viewer, @haze/stepper, @haze/accordion.

## Example requests that should lead here
- Show an AI agent's steps with tool calls, a failed test run and expandable output
- Add a run log for an assistant with search, file edit and reasoning steps and durations

## Source

```astro
---
import { ChevronDown, CircleCheck, CircleMinus, CircleX, FilePenLine, Lightbulb, LoaderCircle, MessageSquare, Search, Wrench } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";

type Kind = "tool" | "thought" | "search" | "edit" | "message";
type Status = "running" | "done" | "error" | "skipped";

interface Step {
  kind: Kind;
  title: string;
  description?: string;
  status?: Status;
  /** Duration as it should read, such as "1.2 s". */
  duration?: string;
  /** Turns the title into a link, for example to a source or a file. */
  href?: string;
  /** Tool input and output or other raw text, shown in a block that scrolls inside itself. */
  detail?: string;
  /** Opens the detail on load. */
  open?: boolean;
}

interface Props {
  steps?: Step[];
  /** Accessible name of the list. */
  label?: string;
  /** Summary text of the expandable detail. */
  detailLabel?: string;
  /** Screen-reader prefix per step kind. */
  kindLabels?: Record<Kind, string>;
  /** Visible text per status. */
  statusLabels?: Record<Status, string>;
  class?: string;
}

const {
  steps = [
    { kind: "search", title: "Searched the docs", description: "Looked for how invoices are rounded.", status: "done", duration: "1.2 s", href: "#docs-rounding" },
    { kind: "tool", title: "Read billing.ts", status: "done", duration: "0.3 s", detail: "read_file({ path: \"src/billing.ts\" })\n\n// 212 lines\nexport function roundLine(amount: number) {\n  return Math.round(amount * 100) / 100;\n}\n// ... totals, tax and discount helpers continue below" },
    { kind: "edit", title: "Edited invoice.ts", description: "Round each line before summing.", status: "done", duration: "2.4 s", detail: "- total += line.amount;\n+ total += roundLine(line.amount);" },
    { kind: "tool", title: "Ran tests", description: "npm test invoice", status: "error", duration: "6.8 s", open: true, detail: "FAIL src/invoice.test.ts\n  adds tax after discount\n    Expected: 108.00\n    Received: 107.99\n\nTests: 1 failed, 11 passed" },
    { kind: "thought", title: "Adjusting the rounding order", description: "Tax has to be added before the total is rounded.", status: "running" },
  ],
  label = "Agent steps",
  detailLabel = "Details",
  kindLabels = { tool: "Tool call", thought: "Reasoning", search: "Search", edit: "File edit", message: "Message" },
  statusLabels = { running: "Running", done: "Done", error: "Failed", skipped: "Skipped" },
  class: className,
} = Astro.props;

const icons = { tool: Wrench, thought: Lightbulb, search: Search, edit: FilePenLine, message: MessageSquare };
const statusIcons = { running: LoaderCircle, done: CircleCheck, error: CircleX, skipped: CircleMinus };
const statusTones = {
  running: "text-muted-foreground",
  done: "text-success",
  error: "text-destructive",
  skipped: "text-muted-foreground",
};

// Where the browser can animate to height:auto, the panel slides open and shut. Elsewhere its content rises in.
const slide =
  "supports-[interpolate-size:allow-keywords]:[interpolate-size:allow-keywords] supports-[interpolate-size:allow-keywords]:details-content:h-0 supports-[interpolate-size:allow-keywords]:details-content:overflow-clip supports-[interpolate-size:allow-keywords]:details-content:transition-[height,content-visibility] supports-[interpolate-size:allow-keywords]:details-content:transition-discrete supports-[interpolate-size:allow-keywords]:details-content:duration-300 supports-[interpolate-size:allow-keywords]:details-content:ease-snappy supports-[interpolate-size:allow-keywords]:open:details-content:h-auto";
---

<ol aria-label={label} class={cn("grid min-w-0", className)}>
  {
    steps.map((step, index) => {
      const Icon = icons[step.kind];
      const StatusIcon = step.status ? statusIcons[step.status] : undefined;
      const last = index === steps.length - 1;
      return (
        <li class={cn("relative flex min-w-0 gap-3", !last && "pb-4")}>
          {!last && <span aria-hidden="true" class="absolute top-7 bottom-0 left-3 w-px -translate-x-1/2 bg-border"></span>}
          <span aria-hidden="true" class="relative inline-grid size-6 shrink-0 place-items-center rounded-lg bg-muted text-muted-foreground">
            <Icon class="size-3.5" />
          </span>
          <div class="min-w-0 flex-1">
            <div class="flex min-h-6 flex-wrap items-center gap-x-2 gap-y-0.5">
              <p class="min-w-0 text-[0.8125rem]/5 font-medium text-foreground wrap-anywhere">
                <span class="sr-only">{kindLabels[step.kind]}: </span>
                {step.href ? (
                  <a href={step.href} class="rounded-sm underline decoration-border-strong underline-offset-2 transition-colors duration-150 ease-snappy hover:decoration-foreground focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring">
                    {step.title}
                  </a>
                ) : (
                  step.title
                )}
              </p>
              {step.status && StatusIcon && (
                <span class={cn("inline-flex items-center gap-1 text-xs/4 font-medium", statusTones[step.status])}>
                  <StatusIcon aria-hidden="true" class={cn("size-3.5", step.status === "running" && "animate-spin motion-reduce:animate-none")} />
                  {statusLabels[step.status]}
                </span>
              )}
              {step.duration && <span class="text-xs/4 text-muted-foreground tabular-nums">{step.duration}</span>}
            </div>
            {step.description && <p class="text-[0.8125rem]/5 text-muted-foreground">{step.description}</p>}
            {step.detail && (
              <details open={step.open} class={cn("mt-1.5", slide)}>
                <summary class="inline-flex min-h-6 cursor-pointer list-none items-center gap-1 rounded-sm text-xs/4 font-medium text-muted-foreground transition-colors duration-150 ease-snappy hover:text-foreground focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring [&::-webkit-details-marker]:hidden">
                  <ChevronDown aria-hidden="true" class="size-3.5 -rotate-90 transition-[rotate] duration-200 ease-spring motion-reduce:transition-none [[open]>summary_&]:rotate-0" />
                  {detailLabel}
                </summary>
                <div class="pt-1.5 not-supports-[interpolate-size:allow-keywords]:animate-rise">
                  <pre
                    tabindex="0"
                    role="group"
                    aria-label={`${detailLabel}: ${step.title}`}
                    class="max-h-40 overflow-auto rounded-lg bg-muted p-3 font-mono text-xs/5 whitespace-pre text-foreground focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring"
                  >{step.detail}</pre>
                </div>
              </details>
            )}
          </div>
        </li>
      );
    })
  }
</ol>
```
