{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "swimlane-run-view",
  "title": "Swimlane Run View",
  "description": "See a multi-bot run on one timeline: each bot in its own lane, who waited on whom, a replay you can scrub, and the critical path that set the finish time.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/swimlane-run-view/swimlane-run-view.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type RunSpanKind = \"work\" | \"wait\" | \"error\";\n\nexport interface RunLane {\n  id: string;\n  name: string;\n}\n\nexport interface RunSpan {\n  id: string;\n  lane: string;\n  label: string;\n  /** Seconds from the start of the run. */\n  start: number;\n  end: number;\n  kind?: RunSpanKind;\n  /** Ids of the spans this one had to wait for. */\n  after?: string[];\n}\n\nexport interface SwimlaneRunViewProps extends Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"title\"\n> {\n  theme?: \"dark\" | \"light\";\n  title?: string;\n  subtitle?: string;\n  lanes?: RunLane[];\n  spans?: RunSpan[];\n  /** How long a replay takes, in milliseconds. */\n  replayMs?: number;\n}\n\nconst FONT =\n  '\"Inter Variable\", Inter, \"SF Pro Display\", -apple-system, BlinkMacSystemFont, sans-serif';\nconst ACCENT = \"#5E6AD2\";\nconst RED = \"#EB5757\";\nconst RING = \"outline-none focus-visible:ring-2 focus-visible:ring-[#5E6AD2]\";\nconst AXIS = 26;\nconst LANE = 46;\nconst BAR = 30;\nconst RIGHT = 10;\nconst TICK = 180;\n\nconst PALETTES = {\n  dark: {\n    card: \"#08090A\",\n    border: \"rgba(255,255,255,0.08)\",\n    grid: \"rgba(255,255,255,0.05)\",\n    bar: \"rgba(255,255,255,0.05)\",\n    wire: \"rgba(255,255,255,0.16)\",\n    text: \"#F7F8F8\",\n    soft: \"#D0D6E0\",\n    sub: \"#8A8F98\",\n    faint: \"#62666D\",\n    chip: \"rgba(255,255,255,0.05)\",\n    waitFill: \"rgba(255,255,255,0.1)\",\n  },\n  light: {\n    card: \"#FFFFFF\",\n    border: \"rgba(8,9,10,0.08)\",\n    grid: \"rgba(8,9,10,0.06)\",\n    bar: \"rgba(8,9,10,0.04)\",\n    wire: \"rgba(8,9,10,0.2)\",\n    text: \"#08090A\",\n    soft: \"#3C3F44\",\n    sub: \"#62666D\",\n    faint: \"#8A8F98\",\n    chip: \"rgba(8,9,10,0.04)\",\n    waitFill: \"rgba(8,9,10,0.1)\",\n  },\n};\n\nconst DEFAULT_LANES: RunLane[] = [\n  { id: \"lead\", name: \"Lead\" },\n  { id: \"research\", name: \"Research\" },\n  { id: \"writer\", name: \"Writer\" },\n  { id: \"review\", name: \"Review\" },\n];\n\nconst DEFAULT_SPANS: RunSpan[] = [\n  { id: \"plan\", lane: \"lead\", label: \"Plan\", start: 0, end: 70 },\n  {\n    id: \"merge\",\n    lane: \"lead\",\n    label: \"Merge\",\n    start: 610,\n    end: 700,\n    after: [\"fix\"],\n  },\n  {\n    id: \"sources\",\n    lane: \"research\",\n    label: \"Read sources\",\n    start: 70,\n    end: 300,\n    after: [\"plan\"],\n  },\n  {\n    id: \"retry\",\n    lane: \"research\",\n    label: \"Retry\",\n    start: 300,\n    end: 350,\n    kind: \"error\",\n    after: [\"sources\"],\n  },\n  {\n    id: \"facts\",\n    lane: \"research\",\n    label: \"Check facts\",\n    start: 350,\n    end: 470,\n    after: [\"retry\"],\n  },\n  {\n    id: \"idle\",\n    lane: \"writer\",\n    label: \"Waiting\",\n    start: 70,\n    end: 180,\n    kind: \"wait\",\n  },\n  {\n    id: \"draft\",\n    lane: \"writer\",\n    label: \"Write draft\",\n    start: 180,\n    end: 460,\n    after: [\"plan\"],\n  },\n  {\n    id: \"fix\",\n    lane: \"writer\",\n    label: \"Fix notes\",\n    start: 540,\n    end: 610,\n    after: [\"check\"],\n  },\n  {\n    id: \"hold\",\n    lane: \"review\",\n    label: \"Waiting\",\n    start: 300,\n    end: 470,\n    kind: \"wait\",\n  },\n  {\n    id: \"check\",\n    lane: \"review\",\n    label: \"Review\",\n    start: 470,\n    end: 540,\n    after: [\"draft\", \"facts\"],\n  },\n];\n\nconst stamp = (s: number) => {\n  const m = Math.floor(s / 60);\n  const r = Math.floor(s % 60);\n  return `${String(m).padStart(2, \"0\")}:${String(r).padStart(2, \"0\")}`;\n};\n\nconst round = (n: number) => Math.round(n * 10) / 10;\n\n/** Walks back from the last span, always through whatever finished latest. */\nfunction criticalPath(spans: RunSpan[]) {\n  const byId = new Map(spans.map((s) => [s.id, s]));\n  const path = new Set<string>();\n  let at = [...spans].sort((a, b) => b.end - a.end)[0];\n  while (at) {\n    path.add(at.id);\n    const before = (at.after ?? [])\n      .map((id) => byId.get(id))\n      .filter((s): s is RunSpan => Boolean(s))\n      .sort((a, b) => b.end - a.end)[0];\n    if (!before) break;\n    at = before;\n  }\n  return path;\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\nfunction useWidth<T extends HTMLElement>(fallback: number) {\n  const ref = React.useRef<T>(null);\n  const [width, setWidth] = React.useState(fallback);\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const ro = new ResizeObserver(([entry]) => {\n      setWidth(Math.round(entry.contentRect.width));\n    });\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, []);\n  return [ref, width] as const;\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 SwimlaneRunView({\n  theme = \"dark\",\n  title = \"Launch brief run\",\n  subtitle = \"Four bots working side by side.\",\n  lanes = DEFAULT_LANES,\n  spans = DEFAULT_SPANS,\n  replayMs = 4000,\n  className,\n  style,\n  ...rest\n}: SwimlaneRunViewProps) {\n  const c = PALETTES[theme];\n  const reduce = useReducedMotion();\n  const total = Math.max(...spans.map((s) => s.end), 1);\n  const [time, setTime] = React.useState(total);\n  const [playing, setPlaying] = React.useState(false);\n  const [critical, setCritical] = React.useState(false);\n  const [wrapRef, width] = useWidth<HTMLDivElement>(800);\n  const raf = React.useRef(0);\n  const uid = React.useId();\n\n  const path = React.useMemo(() => criticalPath(spans), [spans]);\n  const left = width < 520 ? 64 : 88;\n  const height = AXIS + lanes.length * LANE;\n  const x = (s: number) => round(left + (s / total) * (width - left - RIGHT));\n  const laneY = (id: string) =>\n    AXIS + lanes.findIndex((l) => l.id === id) * LANE + (LANE - BAR) / 2;\n  const ticks: number[] = [];\n  for (let t = 0; t <= total; t += TICK) ticks.push(t);\n\n  const waited = spans\n    .filter((s) => s.kind === \"wait\")\n    .reduce((sum, s) => sum + s.end - s.start, 0);\n\n  React.useEffect(() => () => cancelAnimationFrame(raf.current), []);\n\n  const stop = () => {\n    cancelAnimationFrame(raf.current);\n    setPlaying(false);\n  };\n\n  const replay = () => {\n    if (playing) {\n      stop();\n      return;\n    }\n    if (reduce) {\n      setTime(total);\n      return;\n    }\n    setPlaying(true);\n    const began = performance.now();\n    const tick = (now: number) => {\n      const p = Math.min(1, (now - began) / replayMs);\n      setTime(Math.round(p * total));\n      if (p < 1) raf.current = requestAnimationFrame(tick);\n      else setPlaying(false);\n    };\n    raf.current = requestAnimationFrame(tick);\n  };\n\n  const timeAt = (clientX: number, el: HTMLElement) => {\n    const box = el.getBoundingClientRect();\n    const ratio = (clientX - box.left - left) / (box.width - left - RIGHT);\n    return Math.round(Math.max(0, Math.min(1, ratio)) * total);\n  };\n\n  const onKeyDown = (e: React.KeyboardEvent) => {\n    const step =\n      e.key === \"ArrowRight\" ? 15 : e.key === \"ArrowLeft\" ? -15 : null;\n    if (step !== null) {\n      e.preventDefault();\n      stop();\n      setTime((t) => Math.max(0, Math.min(total, t + step)));\n    } else if (e.key === \"Home\" || e.key === \"End\") {\n      e.preventDefault();\n      stop();\n      setTime(e.key === \"Home\" ? 0 : total);\n    }\n  };\n\n  const nowIn = (lane: RunLane) => {\n    const own = spans\n      .filter((s) => s.lane === lane.id)\n      .sort((a, b) => a.start - b.start);\n    const active = own.find((s) => time >= s.start && time < s.end);\n    if (active) return active;\n    if (own[0] && time < own[0].start) return \"Not started\";\n    return own.some((s) => s.start > time) ? \"Idle\" : \"Done\";\n  };\n\n  const fillOf = (s: RunSpan) =>\n    s.kind === \"error\" ? RED : s.kind === \"wait\" ? c.waitFill : ACCENT;\n\n  return (\n    <section\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 text-[13px] leading-[20px] tracking-[-0.011em]\"\n              style={{ color: c.sub }}\n            >\n              {subtitle}\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              {stamp(time)}\n            </p>\n            <p\n              className=\"m-0 mt-1.5 text-[13px] leading-[20px] tabular-nums\"\n              style={{ color: c.sub }}\n            >\n              Of {stamp(total)}\n            </p>\n          </div>\n        </div>\n        <div className=\"mt-3 flex flex-wrap items-center gap-1.5\">\n          <button\n            type=\"button\"\n            data-replay=\"\"\n            onClick={replay}\n            className={`flex h-7 w-[84px] cursor-pointer items-center justify-center rounded-full border-0 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] ${RING}`}\n            style={{ background: c.chip, color: c.text }}\n          >\n            {playing ? \"Pause\" : \"Replay\"}\n          </button>\n          <button\n            type=\"button\"\n            data-critical=\"\"\n            aria-pressed={critical}\n            onClick={() => setCritical((v) => !v)}\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: critical ? 1 : 0.6,\n            }}\n          >\n            <Dot size={8} color={ACCENT} />\n            Critical path\n          </button>\n          <span\n            className=\"flex h-7 items-center gap-2 rounded-full px-3 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] tabular-nums\"\n            style={{ color: c.sub }}\n          >\n            <Dot size={8} color={c.faint} />\n            Waiting {stamp(waited)}\n          </span>\n        </div>\n\n        <div\n          ref={wrapRef}\n          role=\"slider\"\n          tabIndex={0}\n          aria-label=\"Time in the run\"\n          aria-valuemin={0}\n          aria-valuemax={total}\n          aria-valuenow={time}\n          aria-valuetext={stamp(time)}\n          onKeyDown={onKeyDown}\n          onPointerDown={(e) => {\n            e.currentTarget.setPointerCapture(e.pointerId);\n            stop();\n            setTime(timeAt(e.clientX, e.currentTarget));\n          }}\n          onPointerMove={(e) => {\n            if (e.currentTarget.hasPointerCapture(e.pointerId)) {\n              setTime(timeAt(e.clientX, e.currentTarget));\n            }\n          }}\n          className={`mt-3 w-full cursor-pointer touch-pan-y rounded-lg select-none ${RING}`}\n          style={{ height }}\n        >\n          {/* Everything here is SVG with explicit coordinates, so it can't fall out of line. */}\n          <svg\n            aria-hidden=\"true\"\n            width={width}\n            height={height}\n            className=\"block\"\n          >\n            <defs>\n              <clipPath id={`${uid}-past`}>\n                <rect x=\"0\" y=\"0\" width={x(time)} height={height} />\n              </clipPath>\n            </defs>\n\n            {ticks.map((t) => (\n              <g key={t}>\n                <line\n                  x1={x(t)}\n                  x2={x(t)}\n                  y1={AXIS - 6}\n                  y2={height}\n                  stroke={c.grid}\n                />\n                <text\n                  x={x(t)}\n                  y={12}\n                  textAnchor={t === 0 ? \"start\" : \"middle\"}\n                  fontSize=\"11\"\n                  fill={c.faint}\n                  style={{ fontVariantNumeric: \"tabular-nums\" }}\n                >\n                  {stamp(t)}\n                </text>\n              </g>\n            ))}\n\n            {lanes.map((lane, i) => (\n              <g key={lane.id}>\n                <text\n                  x={0}\n                  y={AXIS + i * LANE + LANE / 2 + 4}\n                  fontSize=\"12.5\"\n                  fontWeight=\"510\"\n                  fill={c.soft}\n                >\n                  {lane.name}\n                </text>\n                <line\n                  x1={0}\n                  x2={width - RIGHT}\n                  y1={AXIS + (i + 1) * LANE}\n                  y2={AXIS + (i + 1) * LANE}\n                  stroke={c.grid}\n                />\n              </g>\n            ))}\n\n            {spans.flatMap((s) =>\n              (s.after ?? []).map((id) => {\n                const from = spans.find((o) => o.id === id);\n                if (!from) return null;\n                const x1 = x(from.end);\n                const y1 = laneY(from.lane) + BAR / 2;\n                const x2 = x(s.start);\n                const y2 = laneY(s.lane) + BAR / 2;\n                const mid = round(x1 + Math.max(6, (x2 - x1) / 2));\n                const on = path.has(s.id) && path.has(id);\n                return (\n                  <path\n                    key={`${id}-${s.id}`}\n                    d={`M${x1} ${y1} C${mid} ${y1} ${mid} ${y2} ${x2} ${y2}`}\n                    fill=\"none\"\n                    stroke={critical && on ? ACCENT : c.wire}\n                    strokeWidth=\"1.25\"\n                    opacity={critical && !on ? 0.25 : 1}\n                  />\n                );\n              }),\n            )}\n\n            {spans.map((s) => {\n              const bx = x(s.start);\n              const bw = round(x(s.end) - bx);\n              const by = laneY(s.lane);\n              const dim = critical && !path.has(s.id);\n              const fits = bw > s.label.length * 6.3 + 14;\n              const started = time > s.start;\n              return (\n                <g\n                  key={s.id}\n                  opacity={dim ? 0.3 : 1}\n                  className=\"motion-safe:transition-opacity motion-safe:duration-200\"\n                >\n                  <rect\n                    x={bx + 1}\n                    y={by}\n                    width={Math.max(2, bw - 2)}\n                    height={BAR}\n                    rx=\"6\"\n                    fill={c.bar}\n                    stroke={c.border}\n                  />\n                  <rect\n                    x={bx + 1}\n                    y={by}\n                    width={Math.max(2, bw - 2)}\n                    height={BAR}\n                    rx=\"6\"\n                    fill={fillOf(s)}\n                    clipPath={`url(#${uid}-past)`}\n                  />\n                  {fits && (\n                    <text\n                      x={bx + 9}\n                      y={by + BAR / 2 + 4}\n                      fontSize=\"12\"\n                      fontWeight=\"510\"\n                      fill={\n                        started && s.kind !== \"wait\"\n                          ? \"#FFFFFF\"\n                          : s.kind === \"wait\"\n                            ? c.sub\n                            : c.faint\n                      }\n                    >\n                      {s.label}\n                    </text>\n                  )}\n                </g>\n              );\n            })}\n\n            <line\n              x1={x(time)}\n              x2={x(time)}\n              y1={AXIS - 6}\n              y2={height}\n              stroke={c.text}\n              strokeWidth=\"1.25\"\n            />\n          </svg>\n        </div>\n      </div>\n\n      <dl\n        aria-live=\"off\"\n        className=\"m-0 grid grid-cols-2 gap-x-6 gap-y-3 border-t px-5 py-4 @2xl:grid-cols-4 @2xl:px-6\"\n        style={{ borderColor: c.border }}\n      >\n        {lanes.map((lane) => {\n          const now = nowIn(lane);\n          const span = typeof now === \"string\" ? null : now;\n          return (\n            <div key={lane.id} className=\"min-w-0\">\n              <dt\n                className=\"truncate text-[12px] leading-[16px] tracking-[-0.005em]\"\n                style={{ color: c.faint }}\n              >\n                {lane.name}\n              </dt>\n              <dd className=\"m-0 mt-0.5 flex items-center gap-1.5 text-[13.5px] leading-[20px] font-[510] tracking-[-0.011em]\">\n                <Dot\n                  size={6}\n                  color={\n                    span\n                      ? span.kind === \"wait\"\n                        ? c.faint\n                        : fillOf(span)\n                      : c.faint\n                  }\n                />\n                <span\n                  className=\"truncate\"\n                  style={{ color: span ? c.text : c.sub }}\n                >\n                  {span ? span.label : (now as string)}\n                </span>\n              </dd>\n            </div>\n          );\n        })}\n      </dl>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}