Trace
An AI agent's steps as a list: an icon per kind, a title, status text, duration and expandable tool input and output.
pnpm dlx shadcn@latest add @haze/trace---
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>When to use
- 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
When not to use
- 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.
Installation
Add the Haze registry to components.json once, then install Trace with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/tracenpx shadcn@latest add @haze/traceyarn dlx shadcn@latest add @haze/tracebunx --bun shadcn@latest add @haze/traceFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | 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 | Steps in order. href makes the title a link; detail adds an expandable block. |
| label | string | "Agent steps" | Accessible name of the list. |
| detailLabel | string | "Details" | Summary text of the expandable detail. |
| kindLabels | Record<kind, string> | Tool call, Reasoning, Search, File edit, Message | Screen-reader prefix for each step kind. Translate it. |
| statusLabels | Record<status, string> | Running, Done, Failed, Skipped | Visible status text. Translate it. |
| class | string | – | Extra classes on the list. |
Keyboard interactions
- Tab
- Move through step links, detail toggles and focusable detail blocks.
- EnterSpace
- Open or close a step's detail.
- Arrow keys
- Scroll a focused detail block.
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.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
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": "http://localhost:4329/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: http://localhost:4329/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.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.