# Plan

> Show the plan an agent proposes before it acts, stream its steps in, and let the person approve or revise it.

Source: https://www.honestui.com/docs/ai/plan

```tsx
"use client"

import * as React from "react"
import { RotateCcw as RotateCcwIcon } from "honestui/icons"

import { Button } from "@/components/honest-ui/ui/button"
import { Plan, type PlanStatus, type PlanStep } from "@/components/ai/plan"

// A sample plan.
const sampleSteps: PlanStep[] = [
  { id: "read", title: "Read the failed export logs", detail: "Last three nightly runs, from the billing worker." },
  { id: "find", title: "Find the rows that broke the schema", detail: "Compare them with the v4 column contract." },
  { id: "patch", title: "Patch the currency mapper", detail: "Add the missing ISO codes and a test for each." },
  { id: "rerun", title: "Re-run last night's export", detail: "Into a staging bucket, so nothing reaches finance yet." },
]

/** No agent runs here. Approve and Revise set the status your handlers would. */
export function PlanDemo() {
  const [status, setStatus] = React.useState<PlanStatus>("proposed")

  return (
    <div className="flex w-full max-w-lg min-w-0 flex-col items-start gap-[var(--hui-space-4)]">
      <Plan
        title="Fix the nightly billing export"
        summary="The export stops on rows with an unmapped currency. I'll find them, patch the mapper, and re-run into staging."
        steps={sampleSteps}
        status={status}
        onApprove={() => setStatus("approved")}
        onRevise={() => setStatus("revising")}
      />
      {status !== "proposed" && (
        <Button variant="ghost" size="xs" onClick={() => setStatus("proposed")}>
          <RotateCcwIcon aria-hidden="true" />
          Reset
        </Button>
      )}
    </div>
  )
}

```

## Overview [#overview]

Plan shows what an agent intends to do before it does it: a title, a short summary, and the steps in order. The person approves it or asks for a revision.

It shows the plan and status you pass. Once the plan runs, track the work with [Task Rows](/docs/ai/task-rows).

## Anatomy [#anatomy]

<Anatomy title="Plan">
  <AnatomyItem name="Header" description="The title, the step count or status, and the disclosure" />

  <AnatomyItem name="Summary" description="What the plan sets out to do" />

  <AnatomyItem name="Steps" description="Numbered steps, each with an optional detail" />

  <AnatomyItem name="Actions" description="Revise and Approve, while the plan is proposed" />
</Anatomy>

Installing `plan` brings [Button](/docs/components/button), [Collapsible](/docs/components/collapsible), and [Text Shimmer](/docs/animated/text-shimmer) along as registry dependencies.

## Behavior [#behavior]

### Status [#status]

| Status      | Header                                             | Actions            |
| ----------- | -------------------------------------------------- | ------------------ |
| `streaming` | "Planning", with a placeholder under the last step | Hidden             |
| `proposed`  | The step count                                     | Revise and Approve |
| `approved`  | "Approved"                                         | Hidden             |
| `revising`  | "Revising"                                         | Hidden             |

### Streaming [#streaming]

Append steps to the array as they arrive and keep `status` at `streaming`. Steps present on the first render appear at once; later ones fade in. Set `status` to `proposed` when the plan is complete.

### Collapsing [#collapsing]

The header opens and closes the steps. It starts open; pass `defaultOpen={false}`, or control it with `open` and `onOpenChange`, to collapse a decided plan.

### Approve and Revise [#approve-and-revise]

Each button appears only when you pass its handler. Changing `status` after the person answers is your application's work.

## Accessibility [#accessibility]

The plan is a region named by its title. The header is a button that reports whether the steps are expanded. The steps are an ordered list, and each one is read with its number, such as "Step 2: Find the rows that broke the schema". While streaming the region is marked busy, and a status message announces when the plan is ready and when it is decided. With reduced motion, new steps appear without fading.

| Key                                  | Action                                               |
| ------------------------------------ | ---------------------------------------------------- |
| <kbd>Tab</kbd>                       | Move to the header and the actions                   |
| <kbd>Enter</kbd> or <kbd>Space</kbd> | Open or close the steps, or press the focused action |

## Installation [#installation]


  

  
    <CliBlock commands="[&#x22;@honestai/plan&#x22;]" />
  

  
    
      
        Add the components it is built from.
      

      <CliBlock commands="[&#x22;button&#x22;, &#x22;collapsible&#x22;, &#x22;text-shimmer&#x22;]" />

      
        Install the animation library.
      

      ```bash
      npm install motion
      ```

      
        Copy and paste this file into your project.
      

      ### components/ai/plan.tsx

```tsx
"use client"

import * as React from "react"
import { motion, useReducedMotion } from "motion/react"
import {
  Check as CheckIcon,
  ChevronDown as ChevronDownIcon,
  ListOrdered as ListOrderedIcon,
  Pencil as PencilIcon,
} from "honestui/icons"

import { cn } from "@/lib/utils"
import { TextShimmer } from "@/registry/default/animated/text-shimmer"
import { Button } from "@/components/honest-ui/ui/button"
import {
  Collapsible,
  CollapsiblePanel,
  CollapsibleTrigger,
} from "@/components/honest-ui/ui/collapsible"

export type PlanStep = {
  id: string
  title: string
  /** A line or two on how the step will be done. */
  detail?: React.ReactNode
}

/**
 * "streaming" while the agent is still writing the plan, "proposed" once it
 * waits on the person, and "approved" or "revising" after they answer.
 */
export type PlanStatus = "streaming" | "proposed" | "approved" | "revising"

export type PlanLabels = {
  approve: string
  revise: string
  streaming: string
  approved: string
  revising: string
  /** The step count in the header, such as "4 steps". */
  stepCount: (count: number) => string
  /** Names a step for screen readers, such as "Step 2". */
  step: (index: number) => string
}

export const defaultPlanLabels: PlanLabels = {
  approve: "Approve plan",
  revise: "Revise",
  streaming: "Planning",
  approved: "Approved",
  revising: "Revising",
  stepCount: (count) => `${count} ${count === 1 ? "step" : "steps"}`,
  step: (index) => `Step ${index}`,
}

export type PlanProps = Omit<React.ComponentProps<"section">, "title" | "children"> & {
  title: React.ReactNode
  /** What the plan sets out to do, in a sentence or two. */
  summary?: React.ReactNode
  /** The steps, in order. Append to the array as the plan streams in. */
  steps: PlanStep[]
  status?: PlanStatus
  /** Passing it shows Approve while the plan is proposed. */
  onApprove?: () => void
  /** Passing it shows Revise while the plan is proposed. */
  onRevise?: () => void
  /** Whether the steps start open. */
  defaultOpen?: boolean
  open?: boolean
  onOpenChange?: (open: boolean) => void
  labels?: Partial<PlanLabels>
}

const regularText =
  "[font-size:var(--hui-font-size-regular)] [letter-spacing:var(--hui-letter-spacing-regular)] [line-height:var(--hui-line-height-regular)]"

const metaText =
  "[font-size:var(--hui-font-size-small)] [letter-spacing:var(--hui-letter-spacing-small)] [line-height:var(--hui-line-height-small)]"

/**
 * A plan the agent proposes before it acts: a title, a summary, and ordered
 * steps, with Approve and Revise. It shows the plan and status you pass; use
 * Task Rows to track the work once it runs.
 */
function Plan({
  title,
  summary,
  steps,
  status = "proposed",
  onApprove,
  onRevise,
  defaultOpen = true,
  open,
  onOpenChange,
  labels: labelsProp,
  className,
  ...props
}: PlanProps) {
  const labels = { ...defaultPlanLabels, ...labelsProp }
  const titleId = React.useId()
  const reduceMotion = useReducedMotion()
  const isStreaming = status === "streaming"
  const showActions = status === "proposed" && (onApprove || onRevise)

  // Steps present on the first render appear at once; later ones fade in as they stream.
  const [initialIds] = React.useState(() => new Set(steps.map((step) => step.id)))

  const meta = isStreaming
    ? labels.streaming
    : status === "approved"
      ? labels.approved
      : status === "revising"
        ? labels.revising
        : labels.stepCount(steps.length)

  return (
    <section
      aria-labelledby={titleId}
      aria-busy={isStreaming || undefined}
      data-slot="plan"
      data-status={status}
      className={cn(
        "w-full min-w-0 overflow-hidden rounded-[var(--hui-radius-4)] border-[0.5px] border-[var(--hui-color-border-base-primary)] bg-[var(--hui-color-background-base-primary)] text-[var(--hui-color-foreground-base-primary)] shadow-[var(--hui-shadow-feather)]",
        regularText,
        className
      )}
      {...props}
    >
      <Collapsible defaultOpen={defaultOpen} open={open} onOpenChange={onOpenChange}>
        <CollapsibleTrigger
          data-slot="plan-trigger"
          className="group/plan flex min-h-12 w-full min-w-0 items-center gap-[var(--hui-space-4)] rounded-none border-0 bg-transparent px-[var(--hui-space-5)] py-[var(--hui-space-3)] text-left outline-none motion-safe:[transition:var(--hui-transition-interactive)] hover:bg-[var(--hui-color-background-base-primary-hover)] focus-visible:outline-offset-[var(--hui-focus-ring-offset-inset)]"
        >
          <ListOrderedIcon
            aria-hidden="true"
            strokeWidth={1.5}
            className="size-4 shrink-0 text-[var(--hui-color-foreground-base-tertiary)]"
          />
          <span id={titleId} className="min-w-0 flex-1 truncate [font-weight:var(--hui-font-weight-medium)]">
            {title}
          </span>
          <span
            data-slot="plan-meta"
            className={cn("flex shrink-0 items-center gap-[var(--hui-space-2)] text-[var(--hui-color-foreground-base-secondary)]", metaText)}
          >
            {status === "approved" && <CheckIcon aria-hidden="true" className="size-3.5" />}
            {isStreaming ? (
              <TextShimmer duration={1.6}>{meta}</TextShimmer>
            ) : (
              <span className="tabular-nums">{meta}</span>
            )}
          </span>
          <ChevronDownIcon
            aria-hidden="true"
            className="size-3.5 shrink-0 text-[var(--hui-color-foreground-base-tertiary)] motion-safe:transition-transform motion-safe:duration-200 group-data-panel-open/plan:rotate-180"
          />
        </CollapsibleTrigger>

        <CollapsiblePanel>
          <div className="border-t-[0.5px] border-[var(--hui-color-border-base-primary)]">
            {summary && (
              <p
                data-slot="plan-summary"
                className="m-0 px-[var(--hui-space-5)] pt-[var(--hui-space-4)] text-pretty text-[var(--hui-color-foreground-base-secondary)]"
              >
                {summary}
              </p>
            )}
            <ol
              data-slot="plan-steps"
              className="m-0 flex list-none flex-col gap-[var(--hui-space-4)] px-[var(--hui-space-5)] py-[var(--hui-space-5)]"
            >
              {steps.map((step, index) => {
                const isNew = !initialIds.has(step.id) && !reduceMotion
                return (
                  <motion.li
                    key={step.id}
                    data-slot="plan-step"
                    initial={isNew ? { opacity: 0, y: 4 } : false}
                    animate={{ opacity: 1, y: 0 }}
                    transition={{ duration: 0.24, ease: [0.2, 0, 0, 1] }}
                    className="flex min-w-0 gap-[var(--hui-space-4)]"
                  >
                    <span
                      aria-hidden="true"
                      className={cn(
                        "mt-px flex size-[18px] shrink-0 items-center justify-center rounded-full border-[0.5px] border-[var(--hui-color-border-base-secondary)] text-[var(--hui-color-foreground-base-secondary)] tabular-nums [font-size:var(--hui-font-size-micro)] [line-height:1]",
                      )}
                    >
                      {index + 1}
                    </span>
                    <div className="min-w-0 flex-1">
                      <p className="m-0 break-words [font-weight:var(--hui-font-weight-medium)]">
                        <span className="sr-only">{labels.step(index + 1)}: </span>
                        {step.title}
                      </p>
                      {step.detail && (
                        <div className="mt-[var(--hui-space-1)] break-words text-[var(--hui-color-foreground-base-secondary)]">
                          {step.detail}
                        </div>
                      )}
                    </div>
                  </motion.li>
                )
              })}
              {isStreaming && (
                <li aria-hidden="true" data-slot="plan-step-pending" className="flex min-w-0 items-center gap-[var(--hui-space-4)]">
                  <span className="size-[18px] shrink-0 rounded-full border-[0.5px] border-dashed border-[var(--hui-color-border-base-secondary)]" />
                  <span className="h-2 w-40 max-w-[60%] rounded-full bg-[var(--hui-color-background-neutral-secondary)] motion-safe:animate-pulse" />
                </li>
              )}
            </ol>
          </div>
        </CollapsiblePanel>
      </Collapsible>

      {showActions && (
        <div
          data-slot="plan-actions"
          className="flex flex-wrap items-center justify-end gap-[var(--hui-space-3)] border-t-[0.5px] border-[var(--hui-color-border-base-primary)] px-[var(--hui-space-5)] py-[var(--hui-space-4)]"
        >
          {onRevise && (
            <Button variant="ghost" size="sm" onClick={onRevise}>
              <PencilIcon aria-hidden="true" />
              {labels.revise}
            </Button>
          )}
          {onApprove && (
            <Button size="sm" onClick={onApprove}>
              {labels.approve}
            </Button>
          )}
        </div>
      )}

      {/* Announces when the plan finishes streaming and when it is decided. */}
      <span role="status" className="sr-only">
        {isStreaming ? labels.streaming : status === "proposed" ? labels.stepCount(steps.length) : meta}
      </span>
    </section>
  )
}

export { Plan }

```

      
        Update the import paths to match your project setup.
      
    
  


## Usage [#usage]

```tsx
import { Plan } from "@/components/ai/plan"

<Plan
  title={plan.title}
  summary={plan.summary}
  steps={plan.steps}
  status={plan.isStreaming ? "streaming" : plan.decision ?? "proposed"}
  onApprove={() => agent.approvePlan(plan.id)}
  onRevise={() => composer.focus()}
/>
```

## Examples [#examples]

### Streaming [#streaming-1]

Steps arrive one by one, then the actions appear.

```tsx
"use client"

import * as React from "react"
import { RotateCcw as RotateCcwIcon } from "honestui/icons"

import { Button } from "@/components/honest-ui/ui/button"
import { Plan, type PlanStep } from "@/components/ai/plan"

const sampleSteps: PlanStep[] = [
  { id: "audit", title: "List every page that loads the old SDK" },
  { id: "swap", title: "Swap the client for the v2 import", detail: "One pull request per app, behind a flag." },
  { id: "verify", title: "Check sign-in on staging" },
  { id: "remove", title: "Remove the old package" },
]

/** Steps arrive one by one, as an agent would stream them. */
export function PlanStreaming() {
  const [count, setCount] = React.useState(0)
  const [run, setRun] = React.useState(0)

  React.useEffect(() => {
    const timer = window.setInterval(() => {
      setCount((current) => {
        if (current >= sampleSteps.length) {
          window.clearInterval(timer)
          return current
        }
        return current + 1
      })
    }, 700)
    return () => window.clearInterval(timer)
  }, [run])

  const done = count >= sampleSteps.length

  return (
    <div className="flex w-full max-w-lg min-w-0 flex-col items-start gap-[var(--hui-space-4)]">
      <Plan
        key={run}
        title="Migrate to the v2 auth client"
        summary="Four steps, each reversible until the last."
        steps={sampleSteps.slice(0, count)}
        status={done ? "proposed" : "streaming"}
        onApprove={() => {}}
        onRevise={() => {}}
      />
      <Button variant="ghost" size="xs" onClick={() => {
          setCount(0)
          setRun((current) => current + 1)
        }}>
        <RotateCcwIcon aria-hidden="true" />
        Replay
      </Button>
    </div>
  )
}

```

## API reference [#api-reference]

### Plan [#plan]

Accepts native section props beyond those listed.

| Prop           | Type                      | Default      | Description                                                  |
| -------------- | ------------------------- | ------------ | ------------------------------------------------------------ |
| `title`        | `ReactNode`               | Required     | What the plan is for.                                        |
| `summary`      | `ReactNode`               | None         | A sentence or two on the approach.                           |
| `steps`        | `PlanStep[]`              | Required     | The steps, in order.                                         |
| `status`       | `PlanStatus`              | `"proposed"` | Where the plan stands.                                       |
| `onApprove`    | `() => void`              | None         | Passing it shows Approve while proposed.                     |
| `onRevise`     | `() => void`              | None         | Passing it shows Revise while proposed.                      |
| `defaultOpen`  | `boolean`                 | `true`       | Whether the steps start open.                                |
| `open`         | `boolean`                 | None         | Controls whether the steps are open.                         |
| `onOpenChange` | `(open: boolean) => void` | None         | Called when the header is pressed.                           |
| `labels`       | `Partial<PlanLabels>`     | English      | The action names, status words, step count, and step prefix. |

### Types [#types]

| Export       | Shape                                                      |
| ------------ | ---------------------------------------------------------- |
| `PlanStep`   | `id`, `title`, and an optional `detail`                    |
| `PlanStatus` | `"streaming"`, `"proposed"`, `"approved"`, or `"revising"` |
