{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "thought-trail-demo",
  "type": "registry:block",
  "title": "Thought Trail: Default",
  "description": "AI Reasoning Steps example, Default: A coding agent works through four steps. Each opens while it runs and folds into its summary as the next begins; the edit's diff scrolls inside its step, pinned to the newest line. When the run ends, the trail folds into its header. Click a summary to reopen it. A take on the AI thinking state (reasoning). Fits features and app UI sections.",
  "author": "KeyframeUI <https://keyframeui.com>",
  "categories": [
    "features",
    "app-ui",
    "ai-thinking-state",
    "steps",
    "accordion",
    "ai-chat",
    "ai",
    "status",
    "motion"
  ],
  "docs": "Live preview, examples and props: https://keyframeui.com/components/thought-trail#thought-trail-demo",
  "registryDependencies": [
    "https://keyframeui.com/r/thought-trail.json"
  ],
  "files": [
    {
      "path": "components/thought-trail-demo.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useInView } from \"motion/react\";\n\nimport { cn } from \"@/lib/utils\";\nimport { ThoughtTrail, ThoughtTrailStep } from \"@/components/ui/thought-trail\";\n\ntype Step = {\n  title: string;\n  summary: string;\n  /** How long the step runs, in ms. Its details stream in over the first 85%. */\n  ms: number;\n} & (\n  | { kind: \"files\"; files: string[] }\n  | { kind: \"text\"; text: string }\n  | { kind: \"diff\"; lines: string[] }\n  | { kind: \"log\"; lines: string[] }\n);\n\nconst task = \"Add a dark mode toggle to the settings page\";\n\nconst steps: Step[] = [\n  {\n    title: \"Reading the codebase\",\n    summary: \"Read 6 files\",\n    ms: 2400,\n    kind: \"files\",\n    files: [\n      \"app/settings/page.tsx\",\n      \"components/theme-provider.tsx\",\n      \"app/layout.tsx\",\n      \"components/ui/switch.tsx\",\n      \"lib/storage.ts\",\n      \"app/globals.css\",\n    ],\n  },\n  {\n    title: \"Planning the change\",\n    summary: \"Planned 3 edits\",\n    ms: 3600,\n    kind: \"text\",\n    text: \"ThemeProvider already wraps the app, but nothing ever changes the theme. The settings page has a Preferences section with a Switch for email digests, so a second Switch fits there. It should call setTheme, save the choice through lib/storage.ts, and follow the system setting until someone flips it.\",\n  },\n  {\n    title: \"Editing settings/page.tsx\",\n    summary: \"Edited settings/page.tsx\",\n    ms: 3200,\n    kind: \"diff\",\n    lines: [\n      '+import { useTheme } from \"@/components/theme-provider\";',\n      \" export default function SettingsPage() {\",\n      \"+  const { theme, setTheme } = useTheme();\",\n      '   <Section title=\"Preferences\">',\n      '+    <Row label=\"Dark mode\">',\n      \"+      <Switch\",\n      '+        checked={theme === \"dark\"}',\n      '+        onCheckedChange={(on) => setTheme(on ? \"dark\" : \"light\")}',\n      \"+      />\",\n      \"+    </Row>\",\n    ],\n  },\n  {\n    title: \"Running the type check\",\n    summary: \"Type check passed\",\n    ms: 2000,\n    kind: \"log\",\n    lines: [\"$ tsc --noEmit\", \"Checking 214 files…\", \"✓ No errors\"],\n  },\n];\n\nconst reply =\n  \"Added a Dark mode switch under Preferences. It follows the system setting until you flip it, then remembers the choice.\";\n\nconst LEAD = 600; // ms before the first step, so it arrives rather than just being there\nconst starts = steps.map((_, i) => LEAD + steps.slice(0, i).reduce((sum, s) => sum + s.ms, 0));\nconst END = LEAD + steps.reduce((sum, s) => sum + s.ms, 0);\n\n/** Milliseconds into the current run, from when the demo first scrolls into view. Stops at `end`. */\nfunction usePlayhead(run: number, playing: boolean, end: number) {\n  const [clock, setClock] = React.useState({ run, t: 0 });\n  React.useEffect(() => {\n    if (!playing) return;\n    const start = performance.now();\n    const timer = window.setInterval(() => {\n      const t = Math.min(end, performance.now() - start);\n      setClock({ run, t });\n      if (t >= end) window.clearInterval(timer);\n    }, 50);\n    return () => window.clearInterval(timer);\n  }, [run, playing, end]);\n  return clock.run === run ? clock.t : 0;\n}\n\n// A scripted agent run. Each step opens while it works and shrinks to its\n// summary when the next one starts; when the run ends, the trail folds into\n// its header. Click any summary to open it again.\nexport function ThoughtTrailDemo() {\n  const ref = React.useRef<HTMLDivElement>(null);\n  const playing = useInView(ref, { once: true, amount: 0.4 });\n  const [run, setRun] = React.useState(0);\n  const t = usePlayhead(run, playing, END + 400);\n  const finished = t >= END;\n\n  return (\n    <div\n      ref={ref}\n      className=\"flex h-[30rem] w-full max-w-xl flex-col overflow-hidden rounded-2xl border border-zinc-200 bg-white shadow-sm shadow-zinc-950/5 dark:border-zinc-800 dark:bg-zinc-950 dark:shadow-black/40\"\n    >\n      <div className=\"flex items-center gap-4 border-b border-zinc-100 px-5 py-3.5 dark:border-zinc-800/80\">\n        <div className=\"min-w-0 flex-1\">\n          <p className=\"text-[11px] font-medium tracking-wide text-zinc-400 uppercase dark:text-zinc-500\">Task</p>\n          <p className=\"mt-0.5 truncate text-sm text-zinc-900 dark:text-zinc-100\">{task}</p>\n        </div>\n        <button\n          type=\"button\"\n          onClick={() => setRun((r) => r + 1)}\n          className=\"inline-flex h-8 shrink-0 items-center gap-1.5 rounded-lg px-2.5 text-xs font-medium text-zinc-600 transition-[background-color,color,scale] duration-150 outline-none select-none hover:bg-zinc-100 hover:text-zinc-950 focus-visible:ring-2 focus-visible:ring-zinc-400 active:scale-[0.96] dark:text-zinc-400 dark:hover:bg-zinc-800 dark:hover:text-zinc-50 dark:focus-visible:ring-zinc-600\"\n        >\n          <svg viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden className=\"size-3.5\">\n            <path\n              d=\"M2.75 8a5.25 5.25 0 1 0 1.54-3.71M2.75 2.75v2.5h2.5\"\n              stroke=\"currentColor\"\n              strokeWidth=\"1.5\"\n              strokeLinecap=\"round\"\n              strokeLinejoin=\"round\"\n            />\n          </svg>\n          Replay\n        </button>\n      </div>\n\n      <div className=\"min-h-0 flex-1 overflow-y-auto px-5 py-4\">\n        {playing ? (\n          <ThoughtTrail running={!finished}>\n            {steps.map((step, i) => {\n              if (t < starts[i]) return null;\n              const progress = Math.min(1, (t - starts[i]) / (step.ms * 0.85));\n              const done = t >= starts[i] + step.ms;\n              return (\n                <ThoughtTrailStep\n                  key={step.title}\n                  status={done ? \"done\" : \"active\"}\n                  title={step.title}\n                  summary={step.summary}\n                  meta={step.kind === \"diff\" && done ? <DiffStat lines={step.lines} /> : undefined}\n                  // The diff scrolls inside its step, pinned to the newest line. The top\n                  // padding is the fade zone, so nothing is faded until it scrolls.\n                  contentClassName={\n                    step.kind === \"diff\"\n                      ? \"max-h-40 overflow-y-auto pt-3 [mask-image:linear-gradient(to_bottom,transparent,#000_0.75rem)]\"\n                      : undefined\n                  }\n                >\n                  <StepDetails step={step} progress={progress} />\n                </ThoughtTrailStep>\n              );\n            })}\n          </ThoughtTrail>\n        ) : null}\n\n        <AnimatePresence>\n          {finished ? (\n            <motion.p\n              key={run}\n              initial={{ opacity: 0, y: 6 }}\n              animate={{ opacity: 1, y: 0 }}\n              transition={{ duration: 0.3, ease: \"easeOut\", delay: 0.15 }}\n              className=\"mt-3 text-sm leading-relaxed text-pretty text-zinc-800 dark:text-zinc-200\"\n            >\n              {reply}\n            </motion.p>\n          ) : null}\n        </AnimatePresence>\n      </div>\n    </div>\n  );\n}\n\nfunction StepDetails({ step, progress }: { step: Step; progress: number }) {\n  const upTo = (n: number) => Math.ceil(progress * n);\n\n  if (step.kind === \"files\") {\n    return (\n      <div className=\"flex flex-wrap gap-1.5\">\n        {step.files.slice(0, upTo(step.files.length)).map((file) => (\n          <span\n            key={file}\n            className=\"inline-flex items-center gap-1.5 rounded-md border border-zinc-200 bg-zinc-50 px-1.5 py-0.5 font-mono text-[11.5px] text-zinc-600 dark:border-zinc-800 dark:bg-zinc-900 dark:text-zinc-400\"\n          >\n            <svg viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden className=\"size-3 text-zinc-400 dark:text-zinc-500\">\n              <path\n                d=\"M4 1.75h5L12.25 5v9.25H4z M9 1.75V5h3.25\"\n                stroke=\"currentColor\"\n                strokeWidth=\"1.25\"\n                strokeLinejoin=\"round\"\n              />\n            </svg>\n            {file}\n          </span>\n        ))}\n      </div>\n    );\n  }\n\n  if (step.kind === \"text\") {\n    const words = step.text.split(\" \");\n    return <p className=\"text-pretty\">{words.slice(0, upTo(words.length)).join(\" \")}</p>;\n  }\n\n  return (\n    <pre className=\"font-mono text-[11.5px] leading-5 whitespace-pre-wrap\">\n      {step.lines.slice(0, upTo(step.lines.length)).map((line, i) => (\n        <span\n          key={i}\n          className={cn(\n            \"block\",\n            step.kind === \"diff\" && line.startsWith(\"+\") && \"text-emerald-700 dark:text-emerald-400\",\n            step.kind === \"log\" && line.startsWith(\"✓\") && \"text-emerald-700 dark:text-emerald-400\",\n          )}\n        >\n          {line}\n        </span>\n      ))}\n    </pre>\n  );\n}\n\nfunction DiffStat({ lines }: { lines: string[] }) {\n  const added = lines.filter((line) => line.startsWith(\"+\")).length;\n  return <span className=\"text-emerald-600 dark:text-emerald-400\">+{added}</span>;\n}\n"
    }
  ]
}