{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "thought-trail-deploy-demo",
  "type": "registry:block",
  "title": "Thought Trail: Deploy Log",
  "description": "AI Reasoning Steps example, Deploy Log: A CI pipeline with every step listed up front as pending. Logs stream into the running step, pinned to the newest line, and each step keeps its time. Turn on Break a test: the run stops at the tests, which turn red and stay open, and the steps after them never start. 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-deploy-demo",
  "registryDependencies": [
    "https://keyframeui.com/r/thought-trail.json"
  ],
  "files": [
    {
      "path": "components/thought-trail-deploy-demo.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { useInView } from \"motion/react\";\n\nimport { cn } from \"@/lib/utils\";\nimport { ThoughtTrail, ThoughtTrailStep } from \"@/components/ui/thought-trail\";\n\ntype Stage = {\n  id: string;\n  title: string;\n  summary: string;\n  ms: number;\n  log: string[];\n  /** With \"Break a test\" on: the log it stops on, and its summary. */\n  fails?: { log: string[]; summary: string };\n};\n\nconst stages: Stage[] = [\n  {\n    id: \"clone\",\n    title: \"Cloning repository\",\n    summary: \"Cloned 8f3c2a1\",\n    ms: 1400,\n    log: [\n      \"Cloning github.com/acme/storefront (branch: main)\",\n      \"HEAD is now at 8f3c2a1 Fix cart badge overflow\",\n      \"Cloned in 1.1s\",\n    ],\n  },\n  {\n    id: \"install\",\n    title: \"Installing dependencies\",\n    summary: \"Installed 1,284 packages\",\n    ms: 3000,\n    log: [\n      \"$ npm ci\",\n      \"npm warn deprecated inflight@1.0.6\",\n      \"added 1284 packages in 2.7s\",\n      \"214 packages are looking for funding\",\n      \"found 0 vulnerabilities\",\n    ],\n  },\n  {\n    id: \"build\",\n    title: \"Building\",\n    summary: \"Built 42 routes\",\n    ms: 4200,\n    log: [\n      \"$ next build\",\n      \"▲ Next.js 16.4.0\",\n      \"Creating an optimized production build …\",\n      \"✓ Compiled successfully in 2.9s\",\n      \"✓ Linting and checking validity of types\",\n      \"✓ Collecting page data\",\n      \"✓ Generating static pages (42/42)\",\n      \"Route (app)              Size   First Load JS\",\n      \"┌ ○ /                   4.1 kB        118 kB\",\n      \"├ ○ /cart               2.7 kB        116 kB\",\n      \"├ ● /products/[slug]    3.4 kB        117 kB\",\n      \"└ ○ /checkout           5.2 kB        119 kB\",\n    ],\n  },\n  {\n    id: \"test\",\n    title: \"Running tests\",\n    summary: \"212 tests passed\",\n    ms: 2800,\n    log: [\n      \"$ vitest run\",\n      \" ✓ cart/badge.test.ts (12)\",\n      \" ✓ cart/totals.test.ts (31)\",\n      \" ✓ checkout/address.test.ts (24)\",\n      \" ✓ products/search.test.ts (58)\",\n      \" Test Files  38 passed (38)\",\n      \"      Tests  212 passed (212)\",\n    ],\n    fails: {\n      summary: \"1 of 212 tests failed\",\n      log: [\n        \"$ vitest run\",\n        \" ✓ cart/totals.test.ts (31)\",\n        \" ✗ cart/badge.test.ts > caps the count at 99+\",\n        '     Expected: \"99+\"',\n        '     Received: \"100\"',\n        \" Test Files  1 failed | 37 passed (38)\",\n        \"      Tests  1 failed | 211 passed (212)\",\n      ],\n    },\n  },\n  {\n    id: \"deploy\",\n    title: \"Deploying to production\",\n    summary: \"Live at storefront.acme.app\",\n    ms: 2200,\n    log: [\n      \"Uploading build output (18.4 MB)\",\n      \"Promoting to production\",\n      \"Assigning storefront.acme.app\",\n      \"✓ Ready in 2.1s\",\n    ],\n  },\n];\n\nconst LEAD = 700; // ms the pipeline sits queued before the first step\nconst starts = stages.map((_, i) => LEAD + stages.slice(0, i).reduce((sum, s) => sum + s.ms, 0));\nconst END = LEAD + stages.reduce((sum, s) => sum + s.ms, 0);\nconst testIndex = stages.findIndex((s) => s.fails);\nconst FAIL_AT = starts[testIndex] + stages[testIndex].ms; // the broken run stops here\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\nconst seconds = (ms: number) => `${(ms / 1000).toFixed(1)}s`;\n\n// A CI pipeline with every step listed up front. Logs stream into the step\n// that's running and stay pinned to the newest line; each step keeps its\n// time. Turn on \"Break a test\" and the run stops at the tests, with the\n// failure left open.\nexport function ThoughtTrailDeployDemo() {\n  const ref = React.useRef<HTMLDivElement>(null);\n  const playing = useInView(ref, { once: true, amount: 0.4 });\n  const [broken, setBroken] = React.useState(false);\n  const [run, setRun] = React.useState(0);\n  const end = broken ? FAIL_AT : END;\n  const t = usePlayhead(run, playing, end);\n\n  const redeploy = (nextBroken = broken) => {\n    setBroken(nextBroken);\n    setRun((r) => r + 1);\n  };\n\n  return (\n    <div\n      ref={ref}\n      className=\"flex h-[32rem] w-full max-w-2xl 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 flex-wrap items-center gap-x-4 gap-y-3 border-b border-zinc-100 px-5 py-3.5 dark:border-zinc-800/80\">\n        <div className=\"flex min-w-0 flex-1 items-center gap-3\">\n          <span\n            aria-hidden\n            className=\"flex size-8 shrink-0 items-center justify-center rounded-lg bg-zinc-900 text-sm font-semibold text-white dark:bg-zinc-100 dark:text-zinc-900\"\n          >\n            a\n          </span>\n          <div className=\"min-w-0\">\n            <p className=\"truncate text-sm font-medium text-zinc-900 dark:text-zinc-100\">acme/storefront</p>\n            <p className=\"flex min-w-0 items-center gap-1.5 text-xs text-zinc-500 dark:text-zinc-400\">\n              <span className=\"rounded bg-zinc-100 px-1 font-mono text-[11px] text-zinc-600 dark:bg-zinc-800 dark:text-zinc-300\">\n                main\n              </span>\n              <span className=\"truncate\">8f3c2a1 · Fix cart badge overflow</span>\n            </p>\n          </div>\n        </div>\n        <div className=\"flex items-center gap-1\">\n          <label className=\"inline-flex h-8 cursor-pointer items-center gap-2 rounded-lg px-2.5 text-xs font-medium text-zinc-600 select-none hover:bg-zinc-100 dark:text-zinc-400 dark:hover:bg-zinc-800\">\n            <input\n              type=\"checkbox\"\n              checked={broken}\n              onChange={(e) => redeploy(e.target.checked)}\n              className=\"peer sr-only\"\n            />\n            <span\n              aria-hidden\n              className=\"relative h-4 w-7 rounded-full bg-zinc-200 transition-colors duration-200 peer-checked:bg-rose-500 peer-focus-visible:ring-2 peer-focus-visible:ring-zinc-400 dark:bg-zinc-700 dark:peer-checked:bg-rose-500 dark:peer-focus-visible:ring-zinc-600\"\n            >\n              <span\n                className={cn(\n                  \"absolute top-0.5 left-0.5 size-3 rounded-full bg-white shadow-sm transition-transform duration-200\",\n                  broken && \"translate-x-3\",\n                )}\n              />\n            </span>\n            Break a test\n          </label>\n          <button\n            type=\"button\"\n            onClick={() => redeploy()}\n            className=\"inline-flex h-8 items-center 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            Redeploy\n          </button>\n        </div>\n      </div>\n\n      <div className=\"min-h-0 flex-1 overflow-y-auto px-5 py-4\">\n        {playing ? (\n          <ThoughtTrail\n            running={t < end}\n            label=\"Deploying\"\n            collapseOnDone={false}\n            doneLabel={({ seconds, failed }) => `${failed ? \"Failed after\" : \"Deployed in\"} ${seconds ?? 0}s`}\n          >\n            {stages.map((stage, i) => {\n              const start = starts[i];\n              const fails = broken && stage.fails;\n              const ms = stage.ms;\n              // A broken run never reaches the steps after the tests.\n              const skipped = broken && i > testIndex;\n              const status =\n                skipped || t < start ? \"pending\" : t < start + ms ? \"active\" : fails ? \"error\" : \"done\";\n              const log = fails ? stage.fails!.log : stage.log;\n              const shown = Math.ceil(Math.min(1, (t - start) / (ms * 0.9)) * log.length);\n              return (\n                <ThoughtTrailStep\n                  key={stage.id}\n                  status={status}\n                  title={stage.title}\n                  summary={fails ? stage.fails!.summary : stage.summary}\n                  meta={status === \"pending\" ? undefined : seconds(Math.min(t - start, ms))}\n                  contentClassName=\"max-h-32 overflow-y-auto pt-3 [mask-image:linear-gradient(to_bottom,transparent,#000_0.75rem)]\"\n                >\n                  <pre className=\"font-mono text-[11.5px] leading-5 whitespace-pre\">\n                    {log.slice(0, shown).map((line, j) => (\n                      <span\n                        key={j}\n                        className={cn(\n                          \"block\",\n                          line.includes(\"✓\") && \"text-emerald-700 dark:text-emerald-400\",\n                          (line.includes(\"✗\") || line.includes(\"failed\") || line.includes(\"Received\")) &&\n                            \"text-rose-600 dark:text-rose-400\",\n                        )}\n                      >\n                        {line}\n                      </span>\n                    ))}\n                  </pre>\n                </ThoughtTrailStep>\n              );\n            })}\n          </ThoughtTrail>\n        ) : null}\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}