{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "agent-checklist-demo",
  "title": "Agent Checklist Demo",
  "description": "A worked example of Agent Checklist: A task list whose items change state as work proceeds, announcing what changed instead of re-reading the whole list.",
  "dependencies": [
    "lucide-react@^1.31.0"
  ],
  "registryDependencies": [
    "https://ui.tinkererslabs.com/r/agent-checklist.json"
  ],
  "files": [
    {
      "path": "components/demos/agent-checklist-demo.tsx",
      "content": "\"use client\"\n\nimport { DemoVariants } from \"@/components/demos/demo-variants\"\nimport { RestartButton } from \"@/components/demos/restart-button\"\nimport {\n  useScriptedTimeline,\n  type TimelineStep,\n} from \"@/components/demos/use-scripted-timeline\"\nimport {\n  AgentChecklist,\n  type AgentChecklistItem,\n} from \"@/registry/default/agent-checklist/agent-checklist\"\n\nconst labels = [\n  \"Read the migration\",\n  \"Check the column constraints\",\n  \"Reorder the statements\",\n  \"Run the test suite\",\n]\n\nfunction frame(activeIndex: number): AgentChecklistItem[] {\n  return labels.map((label, index) => ({\n    id: String(index),\n    label,\n    status:\n      index < activeIndex\n        ? \"done\"\n        : index === activeIndex\n          ? \"active\"\n          : \"pending\",\n  }))\n}\n\nconst steps: [\n  TimelineStep<AgentChecklistItem[]>,\n  ...TimelineStep<AgentChecklistItem[]>[],\n] = [\n  { state: frame(0), holdMs: 1600 },\n  { state: frame(1), holdMs: 1600 },\n  { state: frame(2), holdMs: 1600 },\n  { state: frame(3), holdMs: 1600 },\n  { state: frame(4), holdMs: 0 },\n]\n\nfunction LiveRun() {\n  const { state, isFinished, restart, runId } = useScriptedTimeline(steps)\n\n  return (\n    <div className=\"grid gap-4\">\n      <AgentChecklist key={runId} items={state} title=\"Fixing the migration\" />\n      {isFinished ? <RestartButton onClick={restart} /> : null}\n    </div>\n  )\n}\n\nexport function AgentChecklistDemo() {\n  return (\n    <DemoVariants\n      label=\"Checklist state\"\n      variants={[\n        { id: \"live\", label: \"Live run\", render: () => <LiveRun /> },\n        {\n          id: \"failure\",\n          label: \"With a failure\",\n          render: () => (\n            <AgentChecklist\n              title=\"Fixing the migration\"\n              items={[\n                { id: \"0\", label: labels[0], status: \"done\" },\n                { id: \"1\", label: labels[1], status: \"done\" },\n                {\n                  id: \"2\",\n                  label: labels[2],\n                  status: \"error\",\n                  detail: \"Permission denied on migrations/.\",\n                },\n                { id: \"3\", label: labels[3], status: \"skipped\" },\n              ]}\n            />\n          ),\n        },\n      ]}\n    />\n  )\n}\n",
      "type": "registry:example"
    },
    {
      "path": "components/demos/demo-variants.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nexport type DemoVariant = {\n  id: string\n  label: string\n  render: () => React.ReactNode\n}\n\nexport function DemoVariants({\n  variants,\n  label = \"Demo variant\",\n}: {\n  variants: [DemoVariant, ...DemoVariant[]]\n  label?: string\n}) {\n  const [activeId, setActiveId] = React.useState(variants[0].id)\n  const active =\n    variants.find((variant) => variant.id === activeId) ?? variants[0]\n\n  return (\n    <div className=\"grid w-full justify-items-center gap-6\">\n      {/* Centres whatever the variant renders. Without this a demo that caps\n          its own width sits against the left edge while the switch below it\n          is centred, which reads as a mistake. */}\n      <div className=\"flex w-full justify-center\">{active.render()}</div>\n\n      <div\n        role=\"group\"\n        aria-label={label}\n        className=\"border-border bg-background/70 inline-flex flex-wrap justify-center gap-1 rounded-full border p-1\"\n      >\n        {variants.map((variant) => {\n          const isActive = variant.id === active.id\n\n          return (\n            <button\n              key={variant.id}\n              type=\"button\"\n              aria-pressed={isActive}\n              className={\n                isActive\n                  ? \"bg-foreground text-background rounded-full px-3 py-1.5 text-xs font-semibold\"\n                  : \"text-muted-foreground hover:text-foreground rounded-full px-3 py-1.5 text-xs font-semibold\"\n              }\n              onClick={() => setActiveId(variant.id)}\n            >\n              {variant.label}\n            </button>\n          )\n        })}\n      </div>\n    </div>\n  )\n}\n",
      "type": "registry:example"
    },
    {
      "path": "components/demos/restart-button.tsx",
      "content": "\"use client\"\n\nimport { RotateCcw } from \"lucide-react\"\n\nexport function RestartButton({ onClick }: { onClick: () => void }) {\n  return (\n    <button className=\"restore-button\" type=\"button\" onClick={onClick}>\n      <RotateCcw aria-hidden=\"true\" size={15} /> Replay\n    </button>\n  )\n}\n",
      "type": "registry:example"
    },
    {
      "path": "components/demos/use-scripted-timeline.ts",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nconst TICK_MS = 100\n\nexport type TimelineStep<TState> = {\n  state: TState\n  holdMs: number\n}\n\nexport function useScriptedTimeline<TState>(\n  steps: [TimelineStep<TState>, ...TimelineStep<TState>[]]\n) {\n  const [index, setIndex] = React.useState(0)\n  const [elapsedMs, setElapsedMs] = React.useState(0)\n  const [runId, setRunId] = React.useState(0)\n\n  const isFinished = index >= steps.length - 1\n\n  React.useEffect(() => {\n    if (isFinished) return\n\n    const timer = window.setTimeout(\n      () => setIndex((current) => current + 1),\n      (steps[index] ?? steps[0]).holdMs\n    )\n\n    return () => window.clearTimeout(timer)\n  }, [index, isFinished, steps])\n\n  React.useEffect(() => {\n    if (isFinished) return\n\n    const timer = window.setInterval(\n      () => setElapsedMs((current) => current + TICK_MS),\n      TICK_MS\n    )\n\n    return () => window.clearInterval(timer)\n  }, [isFinished])\n\n  const restart = React.useCallback(() => {\n    setIndex(0)\n    setElapsedMs(0)\n    setRunId((current) => current + 1)\n  }, [])\n\n  return {\n    state: (steps[index] ?? steps[0]).state,\n    elapsedMs,\n    isFinished,\n    restart,\n    runId,\n  }\n}\n",
      "type": "registry:example"
    }
  ],
  "type": "registry:example"
}