{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "agent-plan",
  "title": "Agent plan",
  "description": "Live checklist of an agent's plan: pending, active with a pulsing halo, drawn check, error and skipped states, nested substeps that fold away when done, and a spring progress bar with a step count.",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json",
    "https://goodui.dev/r/locale.json"
  ],
  "files": [
    {
      "path": "registry/components/ai/agent-plan.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\"\nimport { ChevronRight, ListChecks } from \"lucide-react\"\nimport { cn } from \"@/lib/utils\"\nimport { useLabels } from \"@/lib/goodui-locale\"\nimport { GooduiTokens, spring as springs } from \"@/lib/goodui-motion\"\n\n/*\n * An agent's plan as a live checklist: each step shows pending, active (spinner with a pulsing halo), done\n * (drawn check), error or skipped, nested substeps fold under their parent, the rail fills as steps complete\n * and a progress bar with \"3 of 7\" tracks the whole plan.\n */\n\nconst CSS = `\n@keyframes pc-plan-spin{to{transform:rotate(360deg)}}\n.pc-plan-spin{animation:pc-plan-spin .9s linear infinite}\n@keyframes pc-plan-halo{0%{transform:scale(1);opacity:.5}100%{transform:scale(2.2);opacity:0}}\n.pc-plan-halo{animation:pc-plan-halo 1.6s ease-out infinite}\n@media (prefers-reduced-motion:reduce){.pc-plan-spin{animation-duration:2s}.pc-plan-halo{animation:none;display:none}}\n`\n\nexport type PlanStepStatus = \"pending\" | \"active\" | \"done\" | \"error\" | \"skipped\"\nexport type PlanStep = {\n  id: string\n  title: React.ReactNode\n  /** Muted text under the title, e.g. the file touched or the result. */\n  detail?: React.ReactNode\n  status?: PlanStepStatus\n  steps?: PlanStep[]\n}\n\nexport type AgentPlanLabels = {\n  progress: (done: number, total: number) => string\n  pending: string\n  active: string\n  done: string\n  error: string\n  skipped: string\n  toggle: string\n}\nconst DEFAULT_LABELS: AgentPlanLabels = { progress: (d, t) => `${d} of ${t} steps`, pending: \"Pending\", active: \"In progress\", done: \"Done\", error: \"Failed\", skipped: \"Skipped\", toggle: \"Toggle substeps\" }\n\nexport type AgentPlanProps = Omit<React.ComponentProps<\"section\">, \"title\"> & {\n  steps: PlanStep[]\n  title?: React.ReactNode\n  /** Progress bar and count in the header. */\n  showProgress?: boolean\n  /** Substeps fold away once their parent is done (they can be reopened). */\n  autoCollapse?: boolean\n  /** card: bordered; plain: just the list. */\n  variant?: \"card\" | \"plain\"\n  onStepClick?: (step: PlanStep) => void\n  /** Text for built-in controls and screen readers; pass translations here. */\n  labels?: Partial<AgentPlanLabels>\n}\n\nfunction count(steps: PlanStep[]): { done: number; total: number } {\n  let done = 0\n  let total = 0\n  for (const s of steps) {\n    if (s.steps?.length) {\n      const c = count(s.steps)\n      done += c.done\n      total += c.total\n    } else {\n      total++\n      if (s.status === \"done\" || s.status === \"skipped\") done++\n    }\n  }\n  return { done, total }\n}\n\nfunction StatusIcon({ status, reduce }: { status: PlanStepStatus; reduce: boolean }) {\n  const spring = reduce ? { duration: 0 } : springs.play\n  return (\n    <span className=\"relative grid size-5 shrink-0 place-items-center\">\n      <AnimatePresence mode=\"popLayout\" initial={false}>\n        {status === \"pending\" && <motion.span key=\"p\" initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} transition={spring} className=\"size-[14px] rounded-full border-2 border-muted-foreground/40\" />}\n        {status === \"active\" && (\n          <motion.span key=\"a\" initial={{ opacity: 0, scale: 0.6 }} animate={{ opacity: 1, scale: 1 }} exit={{ opacity: 0, scale: 0.6 }} transition={spring} className=\"relative grid size-[14px] place-items-center\">\n            <span className=\"pc-plan-halo absolute inset-0 rounded-full bg-foreground\" aria-hidden=\"true\" />\n            <svg viewBox=\"0 0 24 24\" className=\"pc-plan-spin relative size-[14px] text-foreground\" fill=\"none\" aria-hidden=\"true\">\n              <circle cx=\"12\" cy=\"12\" r=\"9\" stroke=\"currentColor\" strokeOpacity=\".2\" strokeWidth=\"3.5\" />\n              <path d=\"M21 12a9 9 0 0 0-9-9\" stroke=\"currentColor\" strokeWidth=\"3.5\" strokeLinecap=\"round\" />\n            </svg>\n          </motion.span>\n        )}\n        {status === \"done\" && (\n          <motion.svg key=\"d\" viewBox=\"0 0 24 24\" initial={{ opacity: 0, scale: 0.5 }} animate={{ opacity: 1, scale: 1 }} exit={{ opacity: 0, scale: 0.6 }} transition={spring} className=\"size-5 text-emerald-600 dark:text-emerald-400\" fill=\"none\" aria-hidden=\"true\">\n            <circle cx=\"12\" cy=\"12\" r=\"10\" fill=\"currentColor\" />\n            <motion.path d=\"M7.5 12.5l3 3 6-7\" stroke=\"var(--background)\" strokeWidth=\"2.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" initial={{ pathLength: reduce ? 1 : 0 }} animate={{ pathLength: 1 }} transition={reduce ? { duration: 0 } : { duration: 0.28, delay: 0.1, ease: \"easeOut\" }} />\n          </motion.svg>\n        )}\n        {status === \"error\" && (\n          <motion.span key=\"e\" initial={{ opacity: 0, scale: 0.5 }} animate={{ opacity: 1, scale: 1 }} exit={{ opacity: 0, scale: 0.6 }} transition={spring} className=\"grid size-5 place-items-center rounded-full bg-rose-600 text-white dark:bg-rose-500\">\n            <svg viewBox=\"0 0 24 24\" className=\"size-3\" fill=\"none\" aria-hidden=\"true\">\n              <path d=\"M8 8l8 8M16 8l-8 8\" stroke=\"currentColor\" strokeWidth=\"3\" strokeLinecap=\"round\" />\n            </svg>\n          </motion.span>\n        )}\n        {status === \"skipped\" && (\n          <motion.span key=\"s\" initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} transition={spring} className=\"grid size-[14px] place-items-center rounded-full bg-muted-foreground/25\">\n            <span className=\"h-0.5 w-1.5 rounded-full bg-muted-foreground\" />\n          </motion.span>\n        )}\n      </AnimatePresence>\n    </span>\n  )\n}\n\nfunction Step({ step, reduce, l, autoCollapse, onStepClick }: { step: PlanStep; reduce: boolean; l: AgentPlanLabels; autoCollapse: boolean; onStepClick?: (s: PlanStep) => void }) {\n  const uid = React.useId()\n  const status = step.status ?? \"pending\"\n  const children = step.steps ?? []\n  const [manual, setManual] = React.useState<boolean | null>(null)\n  const open = manual ?? !(autoCollapse && status === \"done\")\n  const statusText = l[status]\n  const Title = onStepClick ? \"button\" : \"div\"\n\n  return (\n    <motion.li\n      layout=\"position\"\n      initial={reduce ? { opacity: 0 } : { opacity: 0, y: 6 }}\n      animate={{ opacity: 1, y: 0 }}\n      exit={{ opacity: 0, transition: { duration: 0.12 } }}\n      transition={reduce ? { duration: 0 } : springs.snap}\n      data-status={status}\n      className=\"relative\"\n    >\n      <div className=\"flex items-start gap-2.5 py-1\">\n        <StatusIcon status={status} reduce={reduce} />\n        <span className=\"sr-only\">{statusText}: </span>\n        <Title\n          {...(onStepClick ? { type: \"button\" as const, onClick: () => onStepClick(step) } : {})}\n          className={cn(\n            \"min-w-0 flex-1 text-start leading-5\",\n            onStepClick && \"rounded-md outline-none hover:underline focus-visible:ring-3 focus-visible:ring-ring/50\",\n            status === \"done\" || status === \"skipped\" ? \"text-muted-foreground\" : \"text-foreground\",\n            status === \"skipped\" && \"line-through decoration-muted-foreground/50\",\n          )}\n        >\n          <span className={cn(\"block text-sm\", status === \"active\" && \"font-medium\")}>{step.title}</span>\n          {step.detail && <span className=\"block text-xs leading-5 text-muted-foreground\">{step.detail}</span>}\n        </Title>\n        {children.length > 0 && (\n          <button\n            type=\"button\"\n            aria-expanded={open}\n            aria-controls={`${uid}-sub`}\n            aria-label={l.toggle}\n            onClick={() => setManual(!open)}\n            className=\"pc-press grid size-6 shrink-0 place-items-center rounded-md text-muted-foreground outline-none hover:bg-muted hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50\"\n          >\n            <ChevronRight className={cn(\"size-3.5 transition-transform duration-200 rtl:rotate-180\", open && \"rotate-90 rtl:rotate-90\")} aria-hidden=\"true\" />\n          </button>\n        )}\n      </div>\n      {children.length > 0 && (\n        <AnimatePresence initial={false}>\n          {open && (\n            <motion.ol\n              key=\"sub\"\n              id={`${uid}-sub`}\n              initial={{ height: 0, opacity: 0 }}\n              animate={{ height: \"auto\", opacity: 1 }}\n              exit={{ height: 0, opacity: 0 }}\n              transition={reduce ? { duration: 0 } : springs.ui}\n              className=\"relative ms-[9px] overflow-hidden border-s ps-4\"\n            >\n              {children.map((c) => (\n                <Step key={c.id} step={c} reduce={reduce} l={l} autoCollapse={autoCollapse} onStepClick={onStepClick} />\n              ))}\n            </motion.ol>\n          )}\n        </AnimatePresence>\n      )}\n    </motion.li>\n  )\n}\n\n/** Live checklist of an agent's plan with nested substeps and overall progress. */\nexport function AgentPlan({ steps, title, showProgress = true, autoCollapse = true, variant = \"card\", onStepClick, labels, className, ...props }: AgentPlanProps) {\n  const l = useLabels(\"agent-plan\", DEFAULT_LABELS, labels)\n  const reduce = useReducedMotion() ?? false\n  const { done, total } = count(steps)\n  const pct = total ? done / total : 0\n  const failed = steps.some((s) => s.status === \"error\")\n\n  return (\n    <section aria-label={typeof title === \"string\" ? title : undefined} className={cn(\"pc-plan text-sm\", variant === \"card\" && \"rounded-xl border bg-card p-4 text-card-foreground\", className)} {...props}>\n      <GooduiTokens />\n      <style href=\"pc-agent-plan\" precedence=\"default\">\n        {CSS}\n      </style>\n      {(title || showProgress) && (\n        <header className=\"mb-2\">\n          <div className=\"flex items-center gap-2\">\n            {title && (\n              <h3 className=\"flex items-center gap-1.5 text-sm font-medium\">\n                <ListChecks className=\"size-4 text-muted-foreground\" aria-hidden=\"true\" />\n                {title}\n              </h3>\n            )}\n            {showProgress && <span className=\"ms-auto text-xs text-muted-foreground tabular-nums\">{l.progress(done, total)}</span>}\n          </div>\n          {showProgress && (\n            <div className=\"mt-2 h-1.5 overflow-hidden rounded-full bg-muted\" role=\"progressbar\" aria-label={typeof title === \"string\" ? title : l.progress(done, total)} aria-valuemin={0} aria-valuemax={total} aria-valuenow={done} aria-valuetext={l.progress(done, total)}>\n              <motion.div\n                className={cn(\"h-full origin-left rounded-full rtl:origin-right\", failed ? \"bg-rose-500\" : pct >= 1 ? \"bg-emerald-500\" : \"bg-foreground\")}\n                initial={false}\n                animate={{ scaleX: pct }}\n                transition={reduce ? { duration: 0 } : springs.morph}\n              />\n            </div>\n          )}\n        </header>\n      )}\n      <ol className=\"flex flex-col\">\n        <AnimatePresence initial={false}>\n          {steps.map((s) => (\n            <Step key={s.id} step={s} reduce={reduce} l={l} autoCollapse={autoCollapse} onStepClick={onStepClick} />\n          ))}\n        </AnimatePresence>\n      </ol>\n    </section>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/agent-plan.tsx"
    }
  ],
  "categories": [
    "components",
    "ai"
  ],
  "type": "registry:component"
}