# Step Group (/docs/agent-ui/components/step-group)

Use a step group when one turn runs many steps, like tool calls, commands or agents. Its line names the work: the step that's running while it runs, like "Running `npm test`" with "1 of 3", and what was done once it's finished, like "Read `sign-in.ts`, `session.ts` and ran `npm test`". It opens to your own rows.

<Example caption="Press Finish a step to move the turn along. When the last step finishes, the group folds a second later and names the work.">
  <StepGroupExample />

  ```tsx tab="React"
  "use client";

  import type { StepGroupItem, ToolCall } from "@kind-ui/agent-ui";
  import { useState } from "react";
  import { StepGroup } from "@/components/ui/step-group";
  import { Tool } from "@/components/ui/tool";

  // How each kind of step reads, live and done.
  const kinds = {
    read: { live: "Reading", done: "Read", one: "file", many: "files" },
    run: { live: "Running", done: "Ran", one: "command", many: "commands" },
  };

  const steps = [
    { id: "a", kind: "read", target: "sign-in.ts", name: "read_file" },
    { id: "b", kind: "read", target: "session.ts", name: "read_file" },
    { id: "c", kind: "run", target: "npm test", name: "run_command" },
  ] as const;

  export default function StepGroupExample() {
    const [done, setDone] = useState(1);
    const items: StepGroupItem[] = steps.map((step, index) => ({
      ...step,
      status: index < done ? "complete" : index === done ? "running" : "pending",
    }));
    return (
      <div className="flex flex-col items-start gap-3">
        <StepGroup items={items} kinds={kinds} durationSeconds={done === steps.length ? 41 : undefined}>
          {items.map((item, index) => {
            const kind = kinds[steps[index].kind];
            const call: ToolCall = {
              toolCallId: item.id,
              name: steps[index].name,
              title: `${item.status === "complete" ? kind.done : kind.live} \`${item.target}\``,
              dynamic: false,
              input: { state: "ready", value: { target: item.target } },
              ...(item.status === "complete" && { output: { state: "available", value: "Done" } }),
            };
            return item.status === "pending" ? null : (
              <Tool key={item.id} call={call} status={item.status} autoOpen="never" />
            );
          })}
        </StepGroup>
        <button
          type="button"
          data-kind-button="secondary"
          onClick={() => setDone((n) => (n === steps.length ? 1 : n + 1))}
        >
          {done === steps.length ? "Start again" : "Finish a step"}
        </button>
      </div>
    );
  }
  ```

  ```vue tab="Vue"
  <script setup lang="ts">
  import type { StepGroupItem, ToolCall } from "@kind-ui/agent-ui";
  import { computed, ref } from "vue";
  import { StepGroup } from "@/components/ui/vue/step-group";
  import { Tool } from "@/components/ui/vue/tool";

  // How each kind of step reads, live and done.
  const kinds = {
    read: { live: "Reading", done: "Read", one: "file", many: "files" },
    run: { live: "Running", done: "Ran", one: "command", many: "commands" },
  };

  const steps = [
    { id: "a", kind: "read", target: "sign-in.ts", name: "read_file" },
    { id: "b", kind: "read", target: "session.ts", name: "read_file" },
    { id: "c", kind: "run", target: "npm test", name: "run_command" },
  ] as const;

  const done = ref(1);

  type Item = StepGroupItem & (typeof steps)[number];

  const items = computed(() =>
    steps.map(
      (step, index): Item => ({
        ...step,
        status: index < done.value ? "complete" : index === done.value ? "running" : "pending",
      }),
    ),
  );

  const callOf = (item: Item): ToolCall => {
    const kind = kinds[item.kind];
    return {
      toolCallId: item.id,
      name: item.name,
      title: `${item.status === "complete" ? kind.done : kind.live} \`${item.target}\``,
      dynamic: false,
      input: { state: "ready", value: { target: item.target } },
      ...(item.status === "complete" && { output: { state: "available", value: "Done" } }),
    };
  };

  const next = () => {
    done.value = done.value === steps.length ? 1 : done.value + 1;
  };
  </script>

  <template>
    <div class="flex flex-col items-start gap-3">
      <StepGroup :items="items" :kinds="kinds" :duration-seconds="done === steps.length ? 41 : undefined">
        <template v-for="item in items" :key="item.id">
          <Tool v-if="item.status !== 'pending'" :call="callOf(item)" :status="item.status" auto-open="never" />
        </template>
      </StepGroup>
      <button type="button" data-kind-button="secondary" @click="next">
        {{ done === steps.length ? "Start again" : "Finish a step" }}
      </button>
    </div>
  </template>
  ```

  ```svelte tab="Svelte"
  <script lang="ts">
    import type { StepGroupItem, ToolCall } from "@kind-ui/agent-ui";
    import { StepGroup } from "@/components/ui/svelte/step-group/index.js";
    import { Tool } from "@/components/ui/svelte/tool/index.js";

    // How each kind of step reads, live and done.
    const kinds = {
      read: { live: "Reading", done: "Read", one: "file", many: "files" },
      run: { live: "Running", done: "Ran", one: "command", many: "commands" },
    };

    const steps = [
      { id: "a", kind: "read", target: "sign-in.ts", name: "read_file" },
      { id: "b", kind: "read", target: "session.ts", name: "read_file" },
      { id: "c", kind: "run", target: "npm test", name: "run_command" },
    ] as const;

    let done = $state(1);
    const statusOf = (index: number) => (index < done ? "complete" : index === done ? "running" : "pending");
    const items: StepGroupItem[] = $derived(steps.map((step, index) => ({ ...step, status: statusOf(index) })));

    const callOf = (step: (typeof steps)[number], status: string): ToolCall => {
      const kind = kinds[step.kind];
      return {
        toolCallId: step.id,
        name: step.name,
        title: `${status === "complete" ? kind.done : kind.live} \`${step.target}\``,
        dynamic: false,
        input: { state: "ready", value: { target: step.target } },
        ...(status === "complete" && { output: { state: "available", value: "Done" } }),
      };
    };
  </script>

  <div class="flex flex-col items-start gap-3">
    <StepGroup {items} {kinds} durationSeconds={done === steps.length ? 41 : undefined}>
      {#each steps as step, index (step.id)}
        {@const status = statusOf(index)}
        {#if status !== "pending"}
          <Tool call={callOf(step, status)} {status} autoOpen="never" />
        {/if}
      {/each}
    </StepGroup>
    <button
      type="button"
      data-kind-button="secondary"
      onclick={() => (done = done === steps.length ? 1 : done + 1)}
    >
      {done === steps.length ? "Start again" : "Finish a step"}
    </button>
  </div>
  ```

  ```tsx tab="Solid"
  import type { StepStatus, ToolCall } from "@kind-ui/agent-ui";
  import { createMemo, createSignal, For, Show } from "solid-js";
  import { StepGroup } from "@/components/ui/solid/step-group";
  import { Tool } from "@/components/ui/solid/tool";

  // How each kind of step reads, live and done.
  const kinds = {
    read: { live: "Reading", done: "Read", one: "file", many: "files" },
    run: { live: "Running", done: "Ran", one: "command", many: "commands" },
  };

  const steps = [
    { id: "a", kind: "read", target: "sign-in.ts", name: "read_file" },
    { id: "b", kind: "read", target: "session.ts", name: "read_file" },
    { id: "c", kind: "run", target: "npm test", name: "run_command" },
  ] as const;

  export default function StepGroupExample() {
    const [done, setDone] = createSignal(1);
    const items = createMemo(() =>
      steps.map((step, index) => {
        const status: StepStatus = index < done() ? "complete" : index === done() ? "running" : "pending";
        return { ...step, status };
      }),
    );
    return (
      <div class="flex flex-col items-start gap-3">
        <StepGroup items={items()} kinds={kinds} durationSeconds={done() === steps.length ? 41 : undefined}>
          <For each={items()} keyed={(item) => item.id}>
            {(item) => {
              const call = (): ToolCall => {
                const kind = kinds[item().kind];
                return {
                  toolCallId: item().id,
                  name: item().name,
                  title: `${item().status === "complete" ? kind.done : kind.live} \`${item().target}\``,
                  dynamic: false,
                  input: { state: "ready", value: { target: item().target } },
                  ...(item().status === "complete" && { output: { state: "available", value: "Done" } }),
                };
              };
              return (
                <Show when={item().status !== "pending"}>
                  <Tool call={call()} status={item().status} autoOpen="never" />
                </Show>
              );
            }}
          </For>
        </StepGroup>
        <button
          type="button"
          data-kind-button="secondary"
          onClick={() => setDone((n) => (n === steps.length ? 1 : n + 1))}
        >
          {done() === steps.length ? "Start again" : "Finish a step"}
        </button>
      </div>
    );
  }
  ```
</Example>

## Installation [#installation]

```bash tab="React"
npx shadcn@latest add @kind-ui/step-group
```

```bash tab="Web Components"
npx shadcn@latest add @kind-ui/step-group-web
```

```bash tab="Vue"
npx shadcn@latest add @kind-ui/step-group-vue
```

```bash tab="Svelte"
npx shadcn@latest add @kind-ui/step-group-svelte
```

```bash tab="Solid"
npx shadcn@latest add @kind-ui/step-group-solid
```

## Composition [#composition]

```text
StepGroup
├── StepGroupTrigger
│   ├── StepGroupIcon
│   ├── StepGroupTitle
│   └── StepGroupMeta
└── StepGroupContent
    └── StepGroupChildren
```

`StepGroup` renders these parts and puts its children, your rows, in `StepGroupChildren`. The trigger is a native button named by the title and the meta, like "Read auth.ts and ran npm test, 1 failed, 41 sec". `StepGroupIcon` is the group's status mark. To arrange the parts yourself, render them inside `StepGroupRoot`.

## Usage [#usage]

### Items and Kinds [#items-and-kinds]

The group can't read your rows, so pass what they are as `items`: each step's `id`, `status`, and optionally its `kind` and `target`. Pass `kinds` to say how each kind reads, live and done, with its noun: `{ read: { live: "Reading", done: "Read", one: "file", many: "files" } }`. The title joins kinds in the order they were first used and names up to two targets each, so "Read `sign-in.ts`, `session.ts` and ran `npm test`"; past `maxClauses` kinds (2 by default) it counts instead, like "Read 6 files, edited 2 files and 3 other steps". Without `kinds`, it reads "12 steps". Pass `current` to word the running step yourself, or `label` to replace the title.

Each row says its own status, so a row is a [Tool](./tool.mdx), [Terminal](./terminal.mdx) or [Subagent](./subagent.mdx), titled in words. Wrap them in a [StepList](./step.mdx) to make them one Tab stop. Complete rows are quiet: their mark is a dot, not a check, and only running, waiting, failed and stopped rows are marked.

### Status [#status]

The group takes its most urgent step's status: waiting, then failed, then running, then not started, then stopped, then complete. Pass `status` to set it yourself, like `error` when the turn itself failed. The meta says it in words:

| While | Meta |
| --- | --- |
| Running | "3 of 5" |
| Waiting, open | "1 waiting" |
| Waiting, folded | "Waiting for approval" |
| Done | the duration, like "41 sec", from `durationSeconds` |
| Done with a failure | "1 failed · 41 sec" |
| Stopped | "Stopped after 41 sec" |
| Failed | "Failed after 12 sec" |

### Parallel Agents [#parallel-agents]

When several steps of one kind have no target, like agents, the group counts them: "Running 3 agents" with "1 of 3", then "Ran 3 agents". Agents that finish together are announced together, like "3 agents finished, 1 failed".

<Example caption="Three agents at work. The group counts them; the running one is marked, and the one that finished is a quiet dot.">
  <StepGroupAgentsExample />

  ```tsx tab="React"
  import type { StepGroupItem } from "@kind-ui/agent-ui";
  import { StepGroup } from "@/components/ui/step-group";
  import { Subagent } from "@/components/ui/subagent";

  const kinds = { agent: { live: "Running", done: "Ran", one: "agent", many: "agents" } };

  const agents = [
    { id: "reviewer", name: "Code reviewer", status: "complete" },
    { id: "writer", name: "Test writer", status: "running" },
    { id: "docs", name: "Docs updater", status: "pending" },
  ] as const;

  const items: StepGroupItem[] = agents.map(({ id, status }) => ({ id, status, kind: "agent" }));

  export default function StepGroupAgentsExample() {
    return (
      <StepGroup items={items} kinds={kinds}>
        {agents.map((agent) => (
          <Subagent key={agent.id} agentName={agent.name} status={agent.status} autoOpen="never" />
        ))}
      </StepGroup>
    );
  }
  ```

  ```vue tab="Vue"
  <script setup lang="ts">
  import type { StepGroupItem } from "@kind-ui/agent-ui";
  import { StepGroup } from "@/components/ui/vue/step-group";
  import { Subagent } from "@/components/ui/vue/subagent";

  const kinds = { agent: { live: "Running", done: "Ran", one: "agent", many: "agents" } };

  const agents = [
    { id: "reviewer", name: "Code reviewer", status: "complete" },
    { id: "writer", name: "Test writer", status: "running" },
    { id: "docs", name: "Docs updater", status: "pending" },
  ] as const;

  const items: StepGroupItem[] = agents.map(({ id, status }) => ({ id, status, kind: "agent" }));
  </script>

  <template>
    <StepGroup :items="items" :kinds="kinds">
      <Subagent
        v-for="agent in agents"
        :key="agent.id"
        :agent-name="agent.name"
        :status="agent.status"
        auto-open="never"
      />
    </StepGroup>
  </template>
  ```

  ```svelte tab="Svelte"
  <script lang="ts">
    import type { StepGroupItem } from "@kind-ui/agent-ui";
    import { StepGroup } from "@/components/ui/svelte/step-group/index.js";
    import { Subagent } from "@/components/ui/svelte/subagent/index.js";

    const kinds = { agent: { live: "Running", done: "Ran", one: "agent", many: "agents" } };

    const agents = [
      { id: "reviewer", name: "Code reviewer", status: "complete" },
      { id: "writer", name: "Test writer", status: "running" },
      { id: "docs", name: "Docs updater", status: "pending" },
    ] as const;

    const items: StepGroupItem[] = agents.map(({ id, status }) => ({ id, status, kind: "agent" }));
  </script>

  <StepGroup {items} {kinds}>
    {#each agents as agent (agent.id)}
      <Subagent agentName={agent.name} status={agent.status} autoOpen="never" />
    {/each}
  </StepGroup>
  ```

  ```tsx tab="Solid"
  import type { StepGroupItem } from "@kind-ui/agent-ui";
  import { For } from "solid-js";
  import { StepGroup } from "@/components/ui/solid/step-group";
  import { Subagent } from "@/components/ui/solid/subagent";

  const kinds = { agent: { live: "Running", done: "Ran", one: "agent", many: "agents" } };

  const agents = [
    { id: "reviewer", name: "Code reviewer", status: "complete" },
    { id: "writer", name: "Test writer", status: "running" },
    { id: "docs", name: "Docs updater", status: "pending" },
  ] as const;

  const items: StepGroupItem[] = agents.map(({ id, status }) => ({ id, status, kind: "agent" }));

  export default function StepGroupAgentsExample() {
    return (
      <StepGroup items={items} kinds={kinds}>
        <For each={agents}>
          {(agent) => <Subagent agentName={agent.name} status={agent.status} autoOpen="never" />}
        </For>
      </StepGroup>
    );
  }
  ```
</Example>

### Opening and Closing [#opening-and-closing]

A group opens while it runs, and by itself whenever a step waits for a person, even after someone closed it, so it never hides an approval. About a second after it finishes it folds, once, unless someone opened or closed it, and never while focus or a text selection is inside it. Find in page opens it too. Pass `open` with `onOpenChange` to control it.

With fewer than `minItems` items (3 by default), there's no group line: the rows show flat, since grouping two rows hides more than it saves.

### Motion [#motion]

The group opens and closes like a [Step](./step.mdx), and a row that arrives while it's open rises in once; nothing plays when it opens. Under `prefers-reduced-motion`, or with `motion="reduced"`, the content fades over 120 ms instead, and with `motion="none"` everything changes at once.

## API Reference [#api-reference]

### StepGroupOptions

| Prop               | Type                                                                                   | Description                                                                                                                                                                                    |
| ------------------ | -------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `lastActivityAt?`  | `string \| undefined`                                                                  | When the last update arrived, as an ISO 8601 date-time. With it, a running state reads "No update for 2 min".                                                                                  |
| `stalledAfter?`    | `number \| undefined`                                                                  | Seconds without an update before a running state counts as stalled. Default: `120`                                                                                                             |
| `status?`          | `"awaiting-input" \| "cancelled" \| "complete" \| "error" \| "pending" \| "running"`   | What the step is doing. The icon shows it. Default: `"pending"`                                                                                                                                |
| `kind?`            | `string \| undefined`                                                                  | Written as `data-kind`, for styling by step type.                                                                                                                                              |
| `label?`           | `string \| undefined`                                                                  | Names the step in announcements. Defaults to the title part's text.                                                                                                                            |
| `open?`            | `boolean \| undefined`                                                                 | Whether the content shows. Passing it controls it: change it in `onOpenChange`.                                                                                                                |
| `defaultOpen?`     | `boolean \| undefined`                                                                 | Whether the content shows at first, when `open` isn't passed. Defaults to open while `status` is `running` or `awaiting-input`, unless `autoOpen` is `"never"`.                                |
| `onOpenChange?`    | `((open: boolean, details: ChangeDetails<StepOpenChangeReason>) => void) \| undefined` | Called when the step opens or closes, with what caused it.                                                                                                                                     |
| `autoOpen?`        | `"never" \| "running"`                                                                 | With `"running"`, the step opens while running or awaiting input and closes on completion, until someone toggles it. With `"never"`, only a person or your code opens it. Default: `"running"` |
| `durationSeconds?` | `number \| undefined`                                                                  | Written as `--kind-step-duration`.                                                                                                                                                             |
| `motion?`          | `"auto" \| "none" \| "reduced"`                                                        | `"auto"` follows `prefers-reduced-motion`. Default: `"auto"`                                                                                                                                   |
| `items?`           | `StepGroupItem[] \| undefined`                                                         | The steps inside, in order, since core can't read the host's rows. Their statuses give the group's status.                                                                                     |
| `kinds?`           | `StepGroupKinds \| undefined`                                                          | How each kind of step reads, keyed by an item's `kind`: `{ read: { live: "Reading", done: "Read", one: "file", many: "files" } }`.                                                             |
| `maxClauses?`      | `number \| undefined`                                                                  | How many kinds the title names before "and N other steps". Default: `2`                                                                                                                        |
| `minItems?`        | `number \| undefined`                                                                  | With fewer items, the steps show flat, without the group's row. Default: `3`                                                                                                                   |
| `current?`         | `string \| undefined`                                                                  | The live step's words while steps run, like "Running `npm test`". Defaults to the running item's kind and target.                                                                              |

Vue, Svelte and Solid take the same props. Controlled props and callbacks are spelled as each framework expects:

| React                  | Vue                            | Svelte                      | Solid                  |
| ---------------------- | ------------------------------ | --------------------------- | ---------------------- |
| `open`, `onOpenChange` | `v-model:open`, `@open-change` | `bind:open`, `onOpenChange` | `open`, `onOpenChange` |

### Agent [#agent]

An agent connected with `createAgent` finds the group by its title and reads its `open` and `status`. It can run these actions, and press the trigger like a person would.

### StepGroupAgentActions

| Prop       | Type            | Description                                               |
| ---------- | --------------- | --------------------------------------------------------- |
| `expand`   | `() => boolean` | Opens the step. Returns whether the change was accepted.  |
| `collapse` | `() => boolean` | Closes the step. Returns whether the change was accepted. |

<Caption>
  Runs in React, Vue, Svelte, Solid and Web Components. On `<kind-step-group>`, `items` and `kinds` are properties, and `onOpenChange` fires `openchange`. Write the rows inside a `<kind-step-group-content>` holding a `<kind-step-group-children>`: the element adds its trigger before it, unless you wrote one.
</Caption>
