{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "mid-run-nudge-bar",
  "title": "Mid-run Nudge Bar",
  "description": "Steer an AI agent while it works: watch each step arrive, send a quick nudge or your own note, and pause or stop without losing what's done.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/mid-run-nudge-bar/mid-run-nudge-bar.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface NudgeSuggestion {\n  label: string;\n  /** What the bot answers. */\n  reply: string;\n}\n\nexport interface MidRunNudgeBarProps extends Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"title\"\n> {\n  theme?: \"dark\" | \"light\";\n  title?: string;\n  bot?: string;\n  /** The steps the bot works through, in order. */\n  steps?: string[];\n  suggestions?: NudgeSuggestion[];\n  /** Milliseconds per step. */\n  stepMs?: number;\n  /** Starts again at the end. Handy for demos. */\n  loop?: boolean;\n  onNudge?: (text: string) => void;\n  onPauseChange?: (paused: boolean) => void;\n  onStop?: () => void;\n}\n\ntype FeedKind = \"step\" | \"you\" | \"bot\";\n\ninterface FeedItem {\n  key: number;\n  kind: FeedKind;\n  text: string;\n}\n\nconst FONT =\n  '\"Inter Variable\", Inter, \"SF Pro Display\", -apple-system, BlinkMacSystemFont, sans-serif';\nconst ACCENT = \"#5E6AD2\";\nconst GREEN = \"#27A644\";\nconst ORANGE = \"#FC7840\";\nconst RED = \"#EB5757\";\nconst RING = \"outline-none focus-visible:ring-2 focus-visible:ring-[#5E6AD2]\";\nconst ROW = 36;\nconst ROWS = 6;\nconst START = 5;\n\nconst PALETTES = {\n  dark: {\n    card: \"#08090A\",\n    bar: \"#161718\",\n    border: \"rgba(255,255,255,0.08)\",\n    track: \"rgba(255,255,255,0.1)\",\n    text: \"#F7F8F8\",\n    soft: \"#D0D6E0\",\n    sub: \"#8A8F98\",\n    faint: \"#62666D\",\n    chip: \"rgba(255,255,255,0.05)\",\n    btn: \"#E5E5E6\",\n    btnText: \"#08090A\",\n  },\n  light: {\n    card: \"#FFFFFF\",\n    bar: \"#F7F8F8\",\n    border: \"rgba(8,9,10,0.08)\",\n    track: \"rgba(8,9,10,0.1)\",\n    text: \"#08090A\",\n    soft: \"#3C3F44\",\n    sub: \"#62666D\",\n    faint: \"#8A8F98\",\n    chip: \"rgba(8,9,10,0.05)\",\n    btn: \"#08090A\",\n    btnText: \"#F7F8F8\",\n  },\n};\n\nconst DEFAULT_STEPS = [\n  \"Read the old billing code\",\n  \"Listed every call to the invoice API\",\n  \"Updated the database schema\",\n  \"Moved invoice creation to the new API\",\n  \"Copied the old invoice records\",\n  \"Rewrote the refund totals\",\n  \"Ran the billing tests\",\n  \"Fixed two failing tests\",\n  \"Opened the pull request\",\n];\n\nconst DEFAULT_SUGGESTIONS: NudgeSuggestion[] = [\n  {\n    label: \"Use the test database\",\n    reply: \"Okay, switching to the test database.\",\n  },\n  { label: \"Skip the docs\", reply: \"Got it, leaving the docs alone.\" },\n  { label: \"Keep the old tables\", reply: \"Will do, the old tables stay.\" },\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\n        cx={r}\n        cy={r}\n        r={r}\n        className=\"motion-safe:transition-[fill] motion-safe:duration-200\"\n        style={{ fill: color }}\n      />\n    </svg>\n  );\n}\n\n/** Fades itself in when it arrives, without touching the row's own transform. */\nfunction Appear({\n  still,\n  children,\n}: {\n  still: boolean;\n  children: React.ReactNode;\n}) {\n  const ref = React.useRef<HTMLSpanElement>(null);\n  React.useEffect(() => {\n    if (still) return;\n    ref.current?.animate([{ opacity: 0 }, { opacity: 1 }], {\n      duration: 240,\n      easing: \"ease-out\",\n    });\n    // Only on arrival.\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, []);\n  return (\n    <span ref={ref} className=\"flex min-w-0 flex-1 items-center gap-2.5\">\n      {children}\n    </span>\n  );\n}\n\nexport function MidRunNudgeBar({\n  theme = \"dark\",\n  title = \"Move invoices to the new billing API\",\n  bot = \"Patch\",\n  steps = DEFAULT_STEPS,\n  suggestions = DEFAULT_SUGGESTIONS,\n  stepMs = 1400,\n  loop = false,\n  onNudge,\n  onPauseChange,\n  onStop,\n  className,\n  style,\n  ...rest\n}: MidRunNudgeBarProps) {\n  const c = PALETTES[theme];\n  const reduce = useReducedMotion();\n  const rootRef = React.useRef<HTMLElement>(null);\n  const [visible, setVisible] = React.useState(false);\n  const [done, setDone] = React.useState(START);\n  const [feed, setFeed] = React.useState<FeedItem[]>(() =>\n    steps.slice(0, START).map((text, i) => ({ key: i, kind: \"step\", text })),\n  );\n  const [paused, setPaused] = React.useState(false);\n  const [stopped, setStopped] = React.useState(false);\n  const [draft, setDraft] = React.useState(\"\");\n  const [sent, setSent] = React.useState<string[]>([]);\n  const nextKey = React.useRef(steps.length);\n  const timers = React.useRef<number[]>([]);\n\n  const finished = done >= steps.length;\n  const running = !paused && !stopped && !finished;\n\n  const push = React.useCallback((kind: FeedKind, text: string) => {\n    nextKey.current += 1;\n    const key = nextKey.current;\n    setFeed((prev) => [...prev, { key, kind, text }].slice(-(ROWS + 1)));\n  }, []);\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    const pending = timers.current;\n    return () => pending.forEach((t) => window.clearTimeout(t));\n  }, []);\n\n  // The bot takes one step at a time, and only while the card can be seen.\n  React.useEffect(() => {\n    if (!visible || reduce || stopped || paused) return;\n    if (finished && !loop) return;\n    const id = window.setTimeout(\n      () => {\n        if (finished) {\n          setDone(START);\n          setSent([]);\n          setFeed(\n            steps.slice(0, START).map((text) => {\n              nextKey.current += 1;\n              return { key: nextKey.current, kind: \"step\", text } as FeedItem;\n            }),\n          );\n          return;\n        }\n        push(\"step\", steps[done]);\n        setDone(done + 1);\n      },\n      finished ? stepMs * 2 : stepMs,\n    );\n    return () => window.clearTimeout(id);\n  }, [\n    done,\n    finished,\n    loop,\n    paused,\n    push,\n    reduce,\n    stepMs,\n    steps,\n    stopped,\n    visible,\n  ]);\n\n  const nudge = (text: string, reply?: string) => {\n    const body = text.trim();\n    if (!body || stopped) return;\n    push(\"you\", body);\n    setSent((prev) => [...prev, body]);\n    setDraft(\"\");\n    onNudge?.(body);\n    timers.current.push(\n      window.setTimeout(\n        () => push(\"bot\", reply ?? \"Got it, changing the plan.\"),\n        600,\n      ),\n    );\n  };\n\n  const togglePause = () => {\n    setPaused(!paused);\n    onPauseChange?.(!paused);\n  };\n\n  const stop = () => {\n    setStopped(true);\n    push(\"bot\", \"Stopped. Everything so far is saved.\");\n    onStop?.();\n  };\n\n  const resume = () => {\n    setStopped(false);\n    setPaused(false);\n  };\n\n  const status = stopped\n    ? { label: \"Stopped\", color: RED }\n    : finished\n      ? { label: \"Finished\", color: GREEN }\n      : paused\n        ? { label: \"Paused\", color: ORANGE }\n        : { label: `${bot} is working`, color: GREEN };\n\n  const live = feed.slice(-ROWS);\n  const offset = ROWS - live.length;\n  const open = suggestions.filter((s) => !sent.includes(s.label));\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 @xl:p-6 @xl: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              aria-live=\"polite\"\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={status.color} />\n              {status.label}\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              {done} of {steps.length}\n            </p>\n            <p\n              className=\"m-0 mt-1.5 text-[13px] leading-[20px]\"\n              style={{ color: c.sub }}\n            >\n              Steps done\n            </p>\n          </div>\n        </div>\n      </div>\n\n      <ol\n        aria-label=\"Run log\"\n        className=\"relative m-0 list-none overflow-hidden p-0\"\n        style={{ height: ROWS * ROW }}\n      >\n        {live.map((item, i) => {\n          const y = (i + offset) * ROW;\n          const color =\n            item.kind === \"step\"\n              ? c.sub\n              : item.kind === \"you\"\n                ? c.text\n                : c.soft;\n          return (\n            <li\n              key={item.key}\n              className=\"flex items-center px-5 motion-safe:transition-transform motion-safe:duration-300 @xl:px-6\"\n              style={{\n                position: \"absolute\",\n                top: 0,\n                left: 0,\n                right: 0,\n                height: ROW,\n                transform: `translateY(${y}px)`,\n              }}\n            >\n              <Appear still={reduce}>\n                <Dot\n                  size={6}\n                  color={\n                    item.kind === \"you\"\n                      ? ACCENT\n                      : item.kind === \"bot\"\n                        ? c.soft\n                        : c.faint\n                  }\n                />\n                <span\n                  className=\"min-w-0 truncate text-[13.5px] leading-[20px] tracking-[-0.011em]\"\n                  style={{\n                    color,\n                    fontWeight: item.kind === \"you\" ? 510 : 400,\n                  }}\n                >\n                  {item.kind === \"you\" ? `You: ${item.text}` : item.text}\n                </span>\n              </Appear>\n            </li>\n          );\n        })}\n      </ol>\n\n      <div className=\"p-3 @xl:p-4\">\n        <div\n          className=\"overflow-hidden rounded-xl border\"\n          style={{ background: c.bar, borderColor: c.border }}\n        >\n          <div aria-hidden=\"true\" style={{ height: 2, background: c.track }}>\n            <div\n              className=\"h-full origin-left motion-safe:transition-transform motion-safe:duration-300\"\n              style={{\n                background: ACCENT,\n                transform: `scaleX(${steps.length ? done / steps.length : 0})`,\n              }}\n            />\n          </div>\n          <div className=\"p-3\">\n            <div\n              className=\"flex items-center gap-1.5 overflow-x-auto\"\n              style={{ height: 28, scrollbarWidth: \"none\" }}\n            >\n              {open.map((s, i) => (\n                <button\n                  key={s.label}\n                  type=\"button\"\n                  data-suggest={i}\n                  disabled={stopped}\n                  onClick={() => nudge(s.label, s.reply)}\n                  className={`h-7 shrink-0 cursor-pointer rounded-full border-0 px-3 text-[12.5px] leading-[18px] font-[510] tracking-[-0.008em] whitespace-nowrap disabled:cursor-default ${RING}`}\n                  style={{\n                    background: c.chip,\n                    color: stopped ? c.faint : c.soft,\n                  }}\n                >\n                  {s.label}\n                </button>\n              ))}\n            </div>\n            <form\n              className=\"mt-2 flex items-center gap-1.5\"\n              onSubmit={(e) => {\n                e.preventDefault();\n                nudge(draft);\n              }}\n            >\n              <input\n                value={draft}\n                disabled={stopped}\n                onChange={(e) => setDraft(e.target.value)}\n                aria-label={`Tell ${bot} what to change`}\n                placeholder=\"Send a note\"\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] @xl:text-[13px]\"\n                style={{ borderColor: c.border, color: c.text }}\n              />\n              {stopped ? (\n                <button\n                  type=\"button\"\n                  data-resume=\"\"\n                  onClick={resume}\n                  className={`h-9 shrink-0 cursor-pointer rounded-full border-0 px-4 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] ${RING}`}\n                  style={{ background: c.btn, color: c.btnText }}\n                >\n                  Carry on\n                </button>\n              ) : (\n                <>\n                  <button\n                    type=\"button\"\n                    data-pause=\"\"\n                    aria-pressed={paused}\n                    onClick={togglePause}\n                    disabled={finished}\n                    className={`h-9 shrink-0 cursor-pointer rounded-full border-0 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] disabled:cursor-default ${RING}`}\n                    style={{\n                      width: 72,\n                      background: c.chip,\n                      color: finished ? c.faint : c.soft,\n                    }}\n                  >\n                    {paused ? \"Resume\" : \"Pause\"}\n                  </button>\n                  <button\n                    type=\"button\"\n                    data-stop=\"\"\n                    onClick={stop}\n                    disabled={finished}\n                    className={`h-9 shrink-0 cursor-pointer rounded-full border-0 px-3.5 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] disabled:cursor-default ${RING}`}\n                    style={{\n                      background: c.chip,\n                      color: finished ? c.faint : RED,\n                    }}\n                  >\n                    Stop\n                  </button>\n                </>\n              )}\n            </form>\n          </div>\n        </div>\n        <span className=\"sr-only\" aria-live=\"polite\">\n          {running ? \"\" : status.label}\n        </span>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}