# Command

A command the agent ran: the row reads Ran pnpm test · 4.2 s and folds a well with the command, Copy and what it printed. Running, its output prints in, the clock ticks and Stop ends it; a failure reads red with its exit code.

Tier: pro. Type: component. Category: ai. Tags: agent, run, streaming, keyboard, motion.

## Install

```bash
npx shadcn@latest add @pixilui-pro/command
```

One-time setup: add the registry to `components.json`:

```json
{
  "registries": {
    "@pixilui": "https://pixilui.com/r/{name}.json",
    "@pixilui-pro": {
      "url": "https://pixilui.com/r/pro/{name}.json",
      "headers": { "Authorization": "Bearer ${PIXILUI_TOKEN}" }
    }
  }
}
```

Pro items need a license. Create a token on https://pixilui.com/account and set `PIXILUI_TOKEN` in `.env.local`; the CLI sends it as a bearer header.

Files: `components/pixilui/command.tsx`.

## Preview

Live preview: https://pixilui.com/components/command

Knobs:

- `state`: `done`, `running`, `failed`, `stopped`

Signature: Stripe's CLI prints its signing secret as whsec_••••••••a91c, the webhooks print in line by line, and Stop ends it with ^C.

Styles: `lively` (default), `quiet`, set with `data-style` on <html>. The item reads the style through the foundation; it needs no prop.

## Code

Pro source is available to license holders.

## Usage

When to use:

- A command the agent ran in a terminal, with what it printed: tests, a build, a CLI that streams.
- A long-running command the person may stop.

When not to use:

- A tool call with JSON arguments and a result: use Tool call.
- Code the agent wrote: use Code block.

```tsx
import { useEffect, useRef } from "react";
import { Button } from "@/components/pixilui/button";
import { Command, type CommandHandle } from "@/components/pixilui/command";
import { failedOutput, listenLines, listenReady, testOutput } from "@/components/pixilui/command.examples";

// The first option of each knob is the demo's default; the docs preview starts there.
export const knobs = {
  state: ["done", "running", "failed", "stopped"],
} as const;

const ANSWER = { fontSize: "var(--pixilui-text-answer)", lineHeight: "var(--pixilui-text-answer-leading)", letterSpacing: "var(--pixilui-text-answer-tracking)" };
const SAID = {
  running: "Forwarding Stripe's webhooks to your local server, so you can watch the refund arrive.",
  done: "All 10 refund tests pass with the new limit.",
  failed: "Typecheck found one error: review.ts uses db without importing it. Fixing that next.",
  stopped: "Stopped forwarding webhooks once the refund arrived.",
};

/** A command the agent ran: running, its output prints in and Stop ends it; done, failed with its exit code, or stopped. */
export default function CommandDemo({ state = "done" }: KnobValues<typeof knobs>) {
  const ref = useRef<CommandHandle>(null);
  useEffect(() => {
    if (state === "running") ref.current?.stream(listenLines, 1400);
  }, [state]);
  const props =
    state === "running" ? { cmd: "stripe listen --forward-to localhost:3000/api/webhooks", state, output: listenReady }
    : state === "done" ? { cmd: "pnpm test refunds", state, time: 4.2, output: testOutput }
    : state === "failed" ? { cmd: "pnpm typecheck", state, exit: 2, time: 2.8, output: failedOutput }
    : { cmd: "stripe listen --forward-to localhost:3000/api/webhooks", state, time: 18.6, output: [...listenReady, ...listenLines.slice(0, 4), "^C"] };
  return (
    <div className="grid w-full max-w-xl gap-3 rounded-panel bg-surface p-5 elevation-raised">
      <p className="m-0 text-foreground" style={ANSWER}>
        {SAID[state]}
      </p>
      <Command key={state} ref={ref} {...props} />
      {state === "running" ? (
        <div>
          <Button
            variant="secondary-2"
            size="sm"
            onClick={() => {
              ref.current?.restart();
              ref.current?.stream(listenLines, 1400);
            }}
          >
            Run it again
          </Button>
        </div>
      ) : null}
    </div>
  );
}
```

## Examples

None.

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `cmd` (required) | `string` |  | The command: "pnpm test refunds". The row shows its first two words. |
| `output` | `string[]` | `[]` | The lines it printed. While it runs, lines added here print in. |
| `time` | `number` | `0` | How long it ran, in seconds (running: where its clock starts). |
| `state` | `"done" \| "running" \| "failed" \| "stopped"` | `"done"` | done (the default), running, failed or stopped. |
| `exit` | `number` | `0` | The exit code of a command that failed. |
| `defaultOpen` | `boolean` | `true` | Open (default) or folded, uncontrolled. |
| `open` | `boolean` |  | Open or folded, controlled. |
| `onOpenChange` | `(open: boolean) => void` |  | The row was pressed. |
| `onStop` | `() => void` |  | Stop was pressed (it stops itself; stop the process too). |
| `words` | `Partial<CommandWords>` |  | Every word it says. |
| `icons` | `{ chevron?: ReactNode; stop?: ReactNode; copy?: ReactNode }` | `{}` | The icons it draws (the locked disclosure, stop-run and copy-check). |

Also accepts every native `<section>` attribute except `onToggle`, and a ref to it.

## Keyboard

- `Tab`: Reaches the row, Stop while it runs, Copy, and the output (it scrolls past 14 lines).
- `Enter` + `Space`: Folds or opens the well from its row; stops it; copies the command.

## Accessibility

- The output is a log (aria-live polite while it runs); after Stop focus moves to the row and the status line says how long it ran.
- Copy copies the command itself; a key in the output (sk_live_, whsec_, ghp_) renders masked, named with its last four.
- Failed and Stopped are words, not only color.

## Motion

- A new line writes in from its left edge as it prints; the view follows the end unless you scrolled up to read.
- The clock ticks in tabular figures with no motion of its own; the row's verb and Stop swap with the quiet blur swap.
- Reduced motion: lines appear at once.

## Responsive

- Fills its container; output wraps with a hanging indent, so a wrapped line stays one entry.

## Performance

- One 100ms interval while it runs, cleared when it stops; lines are plain spans.

## Notes for AI

- <Command cmd="pnpm test refunds" time={4.2} output={lines} />; running: state="running" and pass the lines as they arrive in output (they print in), then state="done" with time.
- state is done, running, failed (with exit) or stopped; onStop fires when the person presses Stop (stop the process there).
- A ref has stream(lines, every), stop() and restart() for a replay. Every word is in words (Ran, Running, Failed, Stopped, Stop, exit N).

## Related

- [Tool call](https://pixilui.com/components/tool-call/markdown): One tool call in the agent's answer: its row names the call (the tool's real logo, the function as a code tag, the time) and folds its Arguments and Result. A secret in the arguments renders masked, and Copy copies the mask.
- [Code block](https://pixilui.com/components/code-block/markdown): Code the agent shows you in its answer, in a grey well: the file with its folders quiet, Copy, the syntax in six picked inks and a write-in replay. A well of JSON masks any key as it renders, and Copy copies the mask.
- [Diff](https://pixilui.com/components/diff/markdown): An agent's edit to one file, waiting in its answer: the row reads Edited policy.ts +5 −2 with Undo and Keep, over the path and the line diff. Keep and Undo turn the diff into the file in place, and each change can be kept or undone on its own.
