{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "live-run-console",
  "title": "Live Run Console",
  "description": "Watch an AI agent's log as it happens: lines stream in, level pills and a filter cut the noise, and scrolling up to read stops it jumping away.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/live-run-console/live-run-console.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type LogLevel = \"info\" | \"tool\" | \"warn\" | \"error\";\n\nexport interface LogLine {\n  level: LogLevel;\n  text: string;\n}\n\nexport interface LiveRunConsoleProps extends Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"title\"\n> {\n  theme?: \"dark\" | \"light\";\n  title?: string;\n  subtitle?: string;\n  /** Written out one at a time, then repeated. */\n  lines?: LogLine[];\n  /** Milliseconds between lines. */\n  lineMs?: number;\n  /** Seconds past midnight for the first line. */\n  startAt?: number;\n  /** How many lines to keep. */\n  maxLines?: number;\n}\n\ninterface Entry extends LogLine {\n  key: number;\n  time: string;\n}\n\nconst FONT =\n  '\"Inter Variable\", Inter, \"SF Pro Display\", -apple-system, BlinkMacSystemFont, sans-serif';\nconst MONO =\n  'ui-monospace, \"SF Mono\", SFMono-Regular, Menlo, Consolas, monospace';\nconst RING = \"outline-none focus-visible:ring-2 focus-visible:ring-[#5E6AD2]\";\nconst LOG_H = 300;\nconst FIRST = 7;\n\nconst LEVELS: { id: LogLevel; label: string; color: string }[] = [\n  { id: \"info\", label: \"Info\", color: \"#8A8F98\" },\n  { id: \"tool\", label: \"Tools\", color: \"#4EA7FC\" },\n  { id: \"warn\", label: \"Warnings\", color: \"#FC7840\" },\n  { id: \"error\", label: \"Errors\", color: \"#EB5757\" },\n];\n\nconst PALETTES = {\n  dark: {\n    card: \"#08090A\",\n    log: \"#0F1011\",\n    border: \"rgba(255,255,255,0.08)\",\n    text: \"#F7F8F8\",\n    soft: \"#D0D6E0\",\n    sub: \"#8A8F98\",\n    faint: \"#62666D\",\n    chip: \"rgba(255,255,255,0.05)\",\n  },\n  light: {\n    card: \"#FFFFFF\",\n    log: \"#F7F8F8\",\n    border: \"rgba(8,9,10,0.08)\",\n    text: \"#08090A\",\n    soft: \"#3C3F44\",\n    sub: \"#62666D\",\n    faint: \"#8A8F98\",\n    chip: \"rgba(8,9,10,0.04)\",\n  },\n};\n\nconst DEFAULT_LINES: LogLine[] = [\n  { level: \"info\", text: \"Starting run 482\" },\n  { level: \"tool\", text: 'search_tickets query=\"refund\" limit=40' },\n  { level: \"info\", text: \"Found 40 tickets in 214 ms\" },\n  { level: \"tool\", text: \"read_order id=5120\" },\n  { level: \"tool\", text: \"read_order id=5121\" },\n  { level: \"warn\", text: \"Rate limit at 80%, slowing down\" },\n  { level: \"info\", text: \"Grouped tickets into 5 reasons\" },\n  { level: \"tool\", text: \"draft_reply ticket=8841\" },\n  { level: \"error\", text: \"draft_reply failed: template not found\" },\n  { level: \"info\", text: \"Retrying with the default template\" },\n  { level: \"tool\", text: \"draft_reply ticket=8841 template=default\" },\n  { level: \"info\", text: \"Saved 12 drafts for review\" },\n];\n\nconst stamp = (seconds: number) => {\n  const h = Math.floor(seconds / 3600) % 24;\n  const m = Math.floor(seconds / 60) % 60;\n  const s = seconds % 60;\n  return [h, m, s].map((n) => String(n).padStart(2, \"0\")).join(\":\");\n};\n\nfunction seed(lines: LogLine[], startAt: number): Entry[] {\n  return lines.slice(0, FIRST).map((line, i) => ({\n    ...line,\n    key: i,\n    time: stamp(startAt + i * 2),\n  }));\n}\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\n/** Drawn as SVG, because a tiny border-radius circle turns lumpy on 1x screens. */\nfunction Dot({ size, color }: { size: number; color: string }) {\n  const r = size / 2;\n  return (\n    <svg\n      aria-hidden=\"true\"\n      width={size}\n      height={size}\n      viewBox={`0 0 ${size} ${size}`}\n      className=\"block shrink-0\"\n    >\n      <circle cx={r} cy={r} r={r} style={{ fill: color }} />\n    </svg>\n  );\n}\n\nexport function LiveRunConsole({\n  theme = \"dark\",\n  title = \"Run 482\",\n  subtitle = \"Sift, sorting refund tickets\",\n  lines = DEFAULT_LINES,\n  lineMs = 900,\n  startAt = 50531,\n  maxLines = 200,\n  className,\n  style,\n  ...rest\n}: LiveRunConsoleProps) {\n  const c = PALETTES[theme];\n  const reduce = useReducedMotion();\n  const rootRef = React.useRef<HTMLElement>(null);\n  const logRef = React.useRef<HTMLDivElement>(null);\n  const [visible, setVisible] = React.useState(false);\n  const [entries, setEntries] = React.useState(() => seed(lines, startAt));\n  const [paused, setPaused] = React.useState(false);\n  const [follow, setFollow] = React.useState(true);\n  const [hidden, setHidden] = React.useState<LogLevel[]>([]);\n  const [query, setQuery] = React.useState(\"\");\n  const count = React.useRef(FIRST);\n\n  React.useEffect(() => {\n    const el = rootRef.current;\n    if (!el) return;\n    const io = new IntersectionObserver(\n      ([entry]) => setVisible(entry.isIntersecting),\n      { threshold: 0.2 },\n    );\n    io.observe(el);\n    return () => io.disconnect();\n  }, []);\n\n  React.useEffect(() => {\n    if (!visible || paused || reduce || !lines.length) return;\n    const id = window.setInterval(() => {\n      const i = count.current;\n      count.current += 1;\n      const line = lines[i % lines.length];\n      setEntries((prev) =>\n        [...prev, { ...line, key: i, time: stamp(startAt + i * 2) }].slice(\n          -maxLines,\n        ),\n      );\n    }, lineMs);\n    return () => window.clearInterval(id);\n  }, [lineMs, lines, maxLines, paused, reduce, startAt, visible]);\n\n  const needle = query.trim().toLowerCase();\n  const shown = entries.filter(\n    (e) =>\n      !hidden.includes(e.level) &&\n      (!needle || e.text.toLowerCase().includes(needle)),\n  );\n  const errors = entries.filter((e) => e.level === \"error\").length;\n\n  // Stays pinned to the newest line unless someone has scrolled up to read.\n  React.useEffect(() => {\n    const el = logRef.current;\n    if (el && follow) el.scrollTop = el.scrollHeight;\n  }, [follow, shown.length]);\n\n  const onScroll = (e: React.UIEvent<HTMLDivElement>) => {\n    const el = e.currentTarget;\n    const atEnd = el.scrollHeight - el.scrollTop - el.clientHeight < 8;\n    if (atEnd !== follow) setFollow(atEnd);\n  };\n\n  const countOf = (id: LogLevel) =>\n    entries.filter((e) => e.level === id).length;\n\n  return (\n    <section\n      ref={rootRef}\n      aria-label={title}\n      className={`@container w-full rounded-2xl border ${className ?? \"\"}`}\n      style={{\n        background: c.card,\n        borderColor: c.border,\n        color: c.text,\n        fontFamily: FONT,\n        ...style,\n      }}\n      {...rest}\n    >\n      <div className=\"p-5 pb-3 @2xl:p-6 @2xl:pb-3\">\n        <div className=\"flex items-start justify-between gap-4\">\n          <header className=\"min-w-0\">\n            <h3 className=\"m-0 text-[20px] leading-[26px] font-[590] tracking-[-0.012em]\">\n              {title}\n            </h3>\n            <p\n              className=\"m-0 mt-1 flex items-center gap-2 text-[13px] leading-[20px] tracking-[-0.011em]\"\n              style={{ color: c.sub }}\n            >\n              <Dot size={8} color={paused ? \"#FC7840\" : \"#27A644\"} />\n              <span className=\"truncate\">{paused ? \"Paused\" : subtitle}</span>\n            </p>\n          </header>\n          <div className=\"shrink-0 text-right\">\n            <p className=\"m-0 text-[32px] leading-[32px] font-[510] tracking-[-0.022em] tabular-nums\">\n              {entries.length}\n            </p>\n            <p\n              className=\"m-0 mt-1.5 text-[13px] leading-[20px] tabular-nums\"\n              style={{ color: c.sub }}\n            >\n              Lines, {errors} {errors === 1 ? \"error\" : \"errors\"}\n            </p>\n          </div>\n        </div>\n        <div className=\"mt-3 flex flex-wrap gap-1.5\">\n          {LEVELS.map((l) => {\n            const off = hidden.includes(l.id);\n            return (\n              <button\n                key={l.id}\n                type=\"button\"\n                data-level={l.id}\n                aria-pressed={!off}\n                onClick={() =>\n                  setHidden((h) =>\n                    off ? h.filter((x) => x !== l.id) : [...h, l.id],\n                  )\n                }\n                className={`flex h-7 cursor-pointer items-center gap-2 rounded-full border-0 px-3 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] motion-safe:transition-opacity motion-safe:duration-150 ${RING}`}\n                style={{\n                  background: c.chip,\n                  color: c.text,\n                  opacity: off ? 0.45 : 1,\n                }}\n              >\n                <Dot size={8} color={l.color} />\n                {l.label}\n                <span className=\"tabular-nums\" style={{ color: c.sub }}>\n                  {countOf(l.id)}\n                </span>\n              </button>\n            );\n          })}\n        </div>\n      </div>\n\n      <div className=\"px-3 @2xl:px-4\">\n        <div\n          ref={logRef}\n          role=\"log\"\n          aria-label=\"Run log\"\n          tabIndex={0}\n          onScroll={onScroll}\n          className={`overflow-y-auto rounded-xl py-2 ${RING}`}\n          style={{\n            height: LOG_H,\n            background: c.log,\n            fontFamily: MONO,\n            overscrollBehavior: \"contain\",\n          }}\n        >\n          {shown.map((e) => {\n            const color =\n              e.level === \"error\"\n                ? \"#EB5757\"\n                : e.level === \"warn\"\n                  ? \"#FC7840\"\n                  : e.level === \"tool\"\n                    ? \"#4EA7FC\"\n                    : c.soft;\n            return (\n              <p\n                key={e.key}\n                className=\"m-0 flex gap-3 px-3.5 text-[12.5px] leading-[22px]\"\n              >\n                <span\n                  className=\"hidden shrink-0 tabular-nums @md:inline\"\n                  style={{ color: c.faint }}\n                >\n                  {e.time}\n                </span>\n                <span className=\"min-w-0 break-words\" style={{ color }}>\n                  {e.text}\n                </span>\n              </p>\n            );\n          })}\n          {!shown.length && (\n            <p\n              className=\"m-0 px-3.5 text-[12.5px] leading-[22px]\"\n              style={{ color: c.faint }}\n            >\n              No lines match.\n            </p>\n          )}\n        </div>\n      </div>\n\n      <footer className=\"flex items-center gap-2 p-3 @2xl:px-4\">\n        <input\n          value={query}\n          onChange={(e) => setQuery(e.target.value)}\n          aria-label=\"Filter the log\"\n          placeholder=\"Filter\"\n          className=\"h-9 min-w-0 flex-1 rounded-full border bg-transparent px-3.5 text-[16px] tracking-[-0.011em] outline-none focus:border-[#5E6AD2] @2xl:text-[13px]\"\n          style={{ borderColor: c.border, color: c.text }}\n        />\n        <button\n          type=\"button\"\n          data-follow=\"\"\n          aria-pressed={follow}\n          onClick={() => setFollow(!follow)}\n          className={`h-9 shrink-0 cursor-pointer rounded-full border-0 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] ${RING}`}\n          style={{\n            width: 72,\n            background: c.chip,\n            color: follow ? c.text : c.sub,\n          }}\n        >\n          Follow\n        </button>\n        <button\n          type=\"button\"\n          data-pause=\"\"\n          aria-pressed={paused}\n          onClick={() => setPaused(!paused)}\n          className={`h-9 shrink-0 cursor-pointer rounded-full border-0 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] ${RING}`}\n          style={{ width: 72, background: c.chip, color: c.soft }}\n        >\n          {paused ? \"Resume\" : \"Pause\"}\n        </button>\n      </footer>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}