Reasoning

A collapsible "Thinking…" block above an answer, which becomes "Thought for 12 seconds" once done. Host-driven: the server renders the status, the duration and the text so far; a Livewire re-render or wire:stream adds to it. Native details, CSS, no script of its own.

Anatomy

div[data-ds-reasoning="running|done"]
├── span.sr-only[role=status]      empty while running; the done words once done
└── details.group/reasoning        x-data x-ds-keep-toggle, open as below
    ├── summary                    inline, quiet, text-fg-muted
    │   ├── running: spinner (aria-hidden) + ds::shimmer label (+ "4s")
    │   ├── done:    light-bulb + "Thought for 12 seconds"
    │   └── chevron-right, a quarter turn when open
    └── div  border-s-2 border-border ps-3 text-fg-muted
        └── [maxHeight] div[role=region][tabindex=0] — the scroll box
            └── div.space-y-2 — the slot

The body is quieter than the answer: muted text behind a left rule.

Statuses

From the shared set (specs/agent-status.md): pending and running draw the running face; everything else draws the done face. failed and cancelled are still "Thought for…": the thinking happened.

Open or closed

Open on first paint when
runningopenWhileRunning (default true), or open
doneopen, or collapseWhenDone is false and openWhileRunning is true

So by default it is open while it thinks and closed once done, and a host re-render that flips it to done collapses it. x-ds-keep-toggle (an enhancement) then decides what the re-render may change:

  • once the reader has opened or closed it by its summary, that stands: done never collapses one the reader opened by hand;
  • a collapse while focus is inside the body (the scroll box) is refused, so no focus is taken from the reader;
  • it never moves focus itself.

Without the script the details still opens and closes natively, and a re-render sets it to what the server says.

Following the text

With maxHeight (lines, 1.5rem each, as the code block counts them) the body scrolls. While running, the scroll box is a flex-col-reverse column: its scroll origin is the bottom, so text the host appends stays in view, and a reader who has scrolled up keeps their place, the browser's scroll anchoring holding what they are reading. Measured in Chromium: overflow-anchor alone does not do it, because Chromium does not anchor a box scrolled to its top, which is where a box starts. Once done it is a plain column again, so opening it later starts at the beginning.

Accessibility

Rolethe summary is the native disclosure button; the body has no role but the scroll box's region
Namethe summary's words; the scroll box is named by them too
Announcementthe state change only: a visually hidden role="status" outside the details, empty while running, holding the done words once done. Running to done is read once. The body is never a live region, so streamed text is not read as it arrives.
KeyboardTab to the summary; Enter or Space opens and closes it; Tab into the scroll box, arrows scroll it
Focusthe summary and the scroll box draw the system ring
Motionthe shimmer, spinner and chevron are motion-safe:

Do not

  • Do not make the body a live region. A screen reader would read every streamed token.
  • Do not put the answer inside it. The answer goes after the block, at full strength; the block is the working, muted.
  • Do not force it open on every re-render to show progress. The reader closing it is a decision.

From the package repo: edit this page on GitHub.

Was this page helpful?