# Trace

A composable sequence of agent steps, tool activity, progress, and expandable details.

Trace presents the work behind an answer as a compact sequence of readable steps. It is useful for
agent reasoning summaries, tool activity, file operations, build progress, and other process history.
Zenos keeps the root and lines semantically neutral so the surrounding product can choose the right
list, status, link, or disclosure semantics.

```tsx
import { CircleNotchIcon, GearIcon, MagnifyingGlassIcon, PulseIcon } from "@phosphor-icons/react";
import { Trace } from "@zentara-co/zenos-ui";

function TraceExample() {
  return (
    <Trace className="w-full max-w-xl">
      <Trace.Line status="running" role="status">
        <Trace.Icon>
          <CircleNotchIcon className="animate-spin motion-reduce:animate-none" />
        </Trace.Icon>
        <Trace.Title>Thinking through the request</Trace.Title>
      </Trace.Line>
      <Trace.Collapsible defaultOpen>
        <Trace.CollapsibleTrigger>
          <Trace.Line>
            <Trace.Icon>
              <MagnifyingGlassIcon />
            </Trace.Icon>
            <Trace.Title>Explored 4 files</Trace.Title>
            <Trace.Description>2.4s</Trace.Description>
          </Trace.Line>
        </Trace.CollapsibleTrigger>
        <Trace.CollapsibleContent>
          package.json, Message.tsx, MessageScroller.tsx, and index.ts
        </Trace.CollapsibleContent>
      </Trace.Collapsible>
      <Trace.Line>
        <Trace.Icon>
          <GearIcon />
        </Trace.Icon>
        <Trace.Title>Updated the conversation layout</Trace.Title>
      </Trace.Line>
      <Trace.Line status="error">
        <Trace.Icon>
          <PulseIcon />
        </Trace.Icon>
        <Trace.Title>Typecheck failed</Trace.Title>
        <Trace.Description>1 error</Trace.Description>
      </Trace.Line>
    </Trace>
  );
}
```

## Import

```tsx
import { Trace } from "@zentara-co/zenos-ui";
```

## Composition

```tsx
<Trace>
  <Trace.Line status="running" role="status">
    <Trace.Icon>
      <SpinnerIcon />
    </Trace.Icon>
    <Trace.Title>Checking dependencies</Trace.Title>
    <Trace.Description>2.4s</Trace.Description>
  </Trace.Line>
</Trace>
```

`Trace.Icon` is decorative and always hidden from assistive technology. Put the meaning of the step
in `Trace.Title`. `Trace.Description` is optional metadata such as elapsed time, a count, or a short
result.

## Status

Omit `status` for completed work. Use `running`, `pending`, or `error` for the remaining visual states.
Status only changes presentation; add `role="status"` when a newly rendered running step should be
announced.

```tsx
import { CircleNotchIcon, GearIcon, PulseIcon } from "@phosphor-icons/react";
import { Trace } from "@zentara-co/zenos-ui";

function TraceStatusesExample() {
  return (
    <Trace className="w-full max-w-xl">
      <Trace.Line>
        <Trace.Icon>
          <GearIcon />
        </Trace.Icon>
        <Trace.Title>Completed workspace scan</Trace.Title>
      </Trace.Line>
      <Trace.Line status="running" role="status">
        <Trace.Icon>
          <CircleNotchIcon className="animate-spin motion-reduce:animate-none" />
        </Trace.Icon>
        <Trace.Title>Checking dependencies</Trace.Title>
      </Trace.Line>
      <Trace.Line status="pending">
        <Trace.Icon>
          <CircleNotchIcon />
        </Trace.Icon>
        <Trace.Title>Generate release notes</Trace.Title>
      </Trace.Line>
      <Trace.Line status="error">
        <Trace.Icon>
          <PulseIcon />
        </Trace.Icon>
        <Trace.Title>Publish preview failed</Trace.Title>
      </Trace.Line>
    </Trace>
  );
}
```

## Expandable details

Use the collapsible parts when a concise step has optional details. They follow the same controlled
and uncontrolled open-state contract as [Collapsible](/components/collapsible/).

```tsx
import { FolderIcon } from "@phosphor-icons/react";
import { Trace } from "@zentara-co/zenos-ui";

function TraceNestedExample() {
  return (
    <Trace className="w-full max-w-xl">
      <Trace.Collapsible defaultOpen>
        <Trace.CollapsibleTrigger>
          <Trace.Line>
            <Trace.Icon>
              <FolderIcon />
            </Trace.Icon>
            <Trace.Title>Read component files</Trace.Title>
            <Trace.Description>3 files</Trace.Description>
          </Trace.Line>
        </Trace.CollapsibleTrigger>
        <Trace.CollapsibleContent>
          <Trace>
            <Trace.Line>
              <Trace.Title>Trace.tsx</Trace.Title>
              <Trace.Description>6.2 kB</Trace.Description>
            </Trace.Line>
            <Trace.Line>
              <Trace.Title>Trace.test.tsx</Trace.Title>
              <Trace.Description>2.1 kB</Trace.Description>
            </Trace.Line>
            <Trace.Line>
              <Trace.Title>index.ts</Trace.Title>
              <Trace.Description>0.5 kB</Trace.Description>
            </Trace.Line>
          </Trace>
        </Trace.CollapsibleContent>
      </Trace.Collapsible>
    </Trace>
  );
}
```

```tsx
<Trace.Collapsible defaultOpen>
  <Trace.CollapsibleTrigger>
    <Trace.Line>
      <Trace.Title>Read component files</Trace.Title>
    </Trace.Line>
  </Trace.CollapsibleTrigger>
  <Trace.CollapsibleContent>Trace.tsx and Trace.test.tsx</Trace.CollapsibleContent>
</Trace.Collapsible>
```

## Links and actions

`Trace.Line` is a non-interactive `span`. Wrap it with a native link, button, dialog trigger, or
another appropriate interactive component rather than adding click behavior to the line itself.

```tsx
import { ArrowRightIcon, ShieldPlusIcon } from "@phosphor-icons/react";
import { Trace } from "@zentara-co/zenos-ui";

function TraceLinkExample() {
  return (
    <Trace className="w-full max-w-xl">
      <a
        href="#accessibility"
        className="rounded-md no-underline outline-none hover:bg-background-neutral-hover focus-visible:ring-2 focus-visible:ring-ring"
      >
        <Trace.Line>
          <Trace.Icon>
            <ShieldPlusIcon />
          </Trace.Icon>
          <Trace.Title>Review accessibility guidance</Trace.Title>
          <ArrowRightIcon className="ms-auto size-4 rtl:rotate-180" aria-hidden="true" />
        </Trace.Line>
      </a>
    </Trace>
  );
}
```

## Custom styling

Every part accepts `className` and `style`. Use these escape hatches to adjust spacing or emphasis
without replacing the component's state and accessibility behavior.

## RTL

Trace uses logical spacing and text alignment. The disclosure indicator follows the current document
direction. Mirror directional application icons with `rtl:rotate-180` when their meaning changes.

## Variants

complete, running, pending, error

## Anatomy

```text
Trace.Root
Trace.Line
Trace.Icon
Trace.Title
Trace.Description
Trace.Collapsible
Trace.CollapsibleTrigger
Trace.CollapsibleContent
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| Line.status | running \| pending \| error | — | Optional visual state. Omit the status for a completed step. |
| Collapsible open / defaultOpen | boolean | false | Controlled or initial visibility of the detail panel. |
| Collapsible onOpenChange | (open: boolean, eventDetails) => void | — | Runs when the trace detail panel opens or closes. |
| CollapsibleContent.keepMounted | boolean | false | Keeps the detail panel mounted while closed. |
| Line / Icon / Title / Description | HTMLAttributes<HTMLSpanElement> | — | Forward native attributes, refs, styles, classes, and data attributes. |
| native props | React.HTMLAttributes<HTMLDivElement> | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

- Keep every step's meaning in `Trace.Title`; icons are decorative.
- Add `role="status"` only to new progress that should be announced, not to static history.
- Wrap interactive lines in native controls with a clear accessible name.
- Do not communicate running, pending, or error state through color alone; write descriptive text
  when the state affects the user's next action.
- The collapsible trigger supplies button semantics, keyboard interaction, and expanded state.

The component is adapted to Zenos conventions from the [shadcn Trace pattern](https://ui.shadcn.com/docs/components/base/trace).

Source: https://zenos-ui.pages.dev/components/trace/