{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "timeline-agent-lanes",
  "title": "Timeline Agent Lanes",
  "description": "Live multi-agent turn tracker: one hairline lane per agent, the lane holding the turn brightened to foreground, handoffs drawn as stepped connectors with mono duration labels.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/core/timeline-agent-lanes/component.tsx",
      "content": "\"use client\";\n\nimport { useEffect, useMemo, useState } from \"react\";\n\n// A live multi-agent turn tracker: one hairline lane per agent, the lane\n// currently holding the turn brightened to --foreground, idle lanes resting\n// at --ns-muted. This shows the PRESENT moment on a rolling `windowMs` window\n// (a \"now\" line pins the right edge) — it is not a post-hoc trace viewer, so\n// there is deliberately no scrub/seek control: adding one would turn this\n// back into exactly the span-tree debugger it's meant to differ from. Past\n// turns stay visible inside the window (dimmer than the live one) only so a\n// handoff connector has two ends to draw between; once a turn's end falls\n// behind the window it silently ages off the left, same as a real monitor.\n//\n// Concurrency (two+ lanes active at once, the normal shape of a parallel\n// fan-out) needs no special case: any number of turns with no `end` can\n// coexist across different agents and each just renders its own bar.\n//\n// A handoff connector (stepped DOM line + a Geist Mono duration chip) is\n// drawn from a finished turn to the next turn on a DIFFERENT agent that\n// starts at or after it ends (small slack for real-world event jitter) —\n// i.e. a genuine baton pass, not two turns that happen to overlap. One\n// finished turn can feed more than one connector (a fan-out reads as one\n// source splitting into two stepped lines). Labels are packed against real\n// collisions, not just parity-staggered: walking left→right, each label\n// drops into the lowest stacking level whose last-placed label sits at\n// least LABEL_MIN_SEP_PCT away in x (even levels above the rail, odd below,\n// each extra pair stepping one row further out), so three or more handoffs\n// close together in x fan into that many legible rows instead of one smear.\n//\n// Beyond MAX_LANES agents the extra rows collapse into one aggregate \"+N\n// more\" lane that brightens with a live count badge when any of them are\n// active, but never participates in handoff connectors (there's no single\n// row to draw a line to) — a stated degrade, not a silent one.\n//\n// Pure DOM: every bar/hairline/connector segment is a plain absolutely\n// positioned div, positioned with independent left:%/top:px so nothing goes\n// through a scaled SVG viewBox (which would stretch mono text). No canvas,\n// no SVG. Zero dependencies.\n\nexport interface RelayLaneAgent {\n  id: string;\n  label: string;\n}\n\nexport interface RelayLaneTurn {\n  /** stable id, unique across the whole run */\n  id: string;\n  agentId: string;\n  /** ms timestamp the turn began */\n  start: number;\n  /** ms timestamp the turn ended — omit while the turn is still live */\n  end?: number;\n}\n\nexport interface RelayLaneProps {\n  /** lane order, top to bottom */\n  agents: RelayLaneAgent[];\n  /** the run so far — append/mutate over time, oldest first is not required */\n  turns: RelayLaneTurn[];\n  /** accessible name for the region */\n  label?: string;\n  /** width of the rolling visible window, in ms */\n  windowMs?: number;\n  /** controlled \"now\" in ms — omit to let the component tick its own clock */\n  now?: number;\n  /** extra classes merged onto the rendered root element */\n  className?: string;\n}\n\nconst MAX_LANES = 12;\nconst ROW_PITCH = 40;\nconst BAR_H = 4;\n// Wide enough for a realistic agent name *plus* its running-duration chip. At\n// 132px (and still at 156px for the longer names) the two together overflowed and truncated the label (\"Orchestra…\") —\n// and only ever on the lane that was currently in flight, i.e. the one lane a\n// reader most needs to identify.\nconst LABEL_W = 176;\nconst MIN_BAR_PCT = 1.2;\nconst HANDOFF_SLACK_MS = 400;\nconst LABEL_MIN_SEP_PCT = 10;\n\nfunction formatDuration(ms: number): string {\n  const total = Math.max(0, Math.round(ms / 1000));\n  const m = Math.floor(total / 60);\n  const s = total % 60;\n  return `${m}:${String(s).padStart(2, \"0\")}`;\n}\n\ninterface Handoff {\n  key: string;\n  x1: number;\n  y1: number;\n  x2: number;\n  y2: number;\n  durationMs: number;\n  band: \"above\" | \"below\";\n  /** how many stagger rows out from the rail this label sits, per its band */\n  tier: number;\n}\n\nexport function RelayLane({\n  agents,\n  turns,\n  label = \"Agent turn tracker\",\n  windowMs = 20000,\n  now: nowProp,\n  className = \"\",\n}: RelayLaneProps) {\n  // uncontrolled clock: seeded to 0 so server/client first paint match, then\n  // set to the real time and ticked once mounted. Fully controlled (nowProp\n  // set) runs no timer at all.\n  const [internalNow, setInternalNow] = useState(0);\n  useEffect(() => {\n    if (nowProp !== undefined) return;\n    setInternalNow(Date.now());\n    const id = window.setInterval(() => setInternalNow(Date.now()), 1000);\n    return () => window.clearInterval(id);\n  }, [nowProp]);\n  const now = nowProp ?? internalNow;\n  const windowStart = now - windowMs;\n\n  const visibleAgents = agents.length > MAX_LANES ? agents.slice(0, MAX_LANES - 1) : agents;\n  const overflowAgents = agents.length > MAX_LANES ? agents.slice(MAX_LANES - 1) : [];\n  const hasOverflow = overflowAgents.length > 0;\n\n  const rowIndex = useMemo(() => {\n    const m = new Map<string, number>();\n    visibleAgents.forEach((a, i) => m.set(a.id, i));\n    return m;\n  }, [visibleAgents]);\n\n  const rowCount = visibleAgents.length + (hasOverflow ? 1 : 0);\n\n  const openTurnByAgent = useMemo(() => {\n    const m = new Map<string, RelayLaneTurn>();\n    for (const t of turns) {\n      if (t.end === undefined) m.set(t.agentId, t);\n    }\n    return m;\n  }, [turns]);\n\n  const overflowActiveCount = overflowAgents.filter((a) =>\n    openTurnByAgent.has(a.id)\n  ).length;\n\n  // handoffs: for every turn, its predecessor is the most-recently-ended\n  // OTHER-agent turn that finished at or before it starts (+ slack)\n  const handoffs = useMemo<Handoff[]>(() => {\n    const finished = turns.filter((t) => t.end !== undefined);\n    const sorted = [...turns].sort((a, b) => a.start - b.start);\n    const raw: { from: RelayLaneTurn; to: RelayLaneTurn; midX: number }[] = [];\n\n    for (const t of sorted) {\n      let best: RelayLaneTurn | undefined;\n      for (const f of finished) {\n        if (f.id === t.id || f.agentId === t.agentId) continue;\n        if (f.end! <= t.start + HANDOFF_SLACK_MS) {\n          if (!best || f.end! > best.end!) best = f;\n        }\n      }\n      if (!best) continue;\n      if (best.end! < windowStart) continue; // aged fully out of view\n      const fromRow = rowIndex.get(best.agentId);\n      const toRow = rowIndex.get(t.agentId);\n      if (fromRow === undefined || toRow === undefined) continue; // overflowed lane\n\n      const x1 = Math.min(100, Math.max(0, ((best.end! - windowStart) / windowMs) * 100));\n      const x2 = Math.min(100, Math.max(0, ((t.start - windowStart) / windowMs) * 100));\n      raw.push({\n        from: best,\n        to: t,\n        midX: (x1 + x2) / 2,\n      });\n    }\n\n    // Real de-overlap, not a parity stagger: three or more handoffs whose\n    // labels land close together in x (a fan-out from one source is exactly\n    // this shape) all overprinted when the only escape was a single above/\n    // below flip. Instead, walk the labels left→right and drop each into the\n    // lowest stacking LEVEL whose most-recently-placed label is at least\n    // LABEL_MIN_SEP_PCT away in x — the classic occupied-range packer. Even\n    // levels ride above the rail, odd below; every additional pair of levels\n    // (its `tier`) steps one row further out, so N coincident labels fan into\n    // N legible rows instead of a single smear.\n    const lastXByLevel: number[] = [];\n    const levelByIndex = new Map<number, number>();\n    [...raw.keys()]\n      .sort((a, b) => raw[a]!.midX - raw[b]!.midX)\n      .forEach((idx) => {\n        let level = 0;\n        while (\n          lastXByLevel[level] !== undefined &&\n          raw[idx]!.midX - lastXByLevel[level]! < LABEL_MIN_SEP_PCT\n        ) {\n          level++;\n        }\n        lastXByLevel[level] = raw[idx]!.midX;\n        levelByIndex.set(idx, level);\n      });\n\n    return raw.map((h, i): Handoff => {\n      const level = levelByIndex.get(i) ?? 0;\n      const band: \"above\" | \"below\" = level % 2 === 0 ? \"above\" : \"below\";\n      const tier = Math.floor(level / 2);\n\n      const fromRow = rowIndex.get(h.from.agentId)!;\n      const toRow = rowIndex.get(h.to.agentId)!;\n      const x1 = Math.min(100, Math.max(0, ((h.from.end! - windowStart) / windowMs) * 100));\n      const x2 = Math.min(100, Math.max(0, ((h.to.start - windowStart) / windowMs) * 100));\n\n      return {\n        key: `${h.from.id}->${h.to.id}`,\n        x1,\n        y1: fromRow * ROW_PITCH + ROW_PITCH / 2,\n        x2,\n        y2: toRow * ROW_PITCH + ROW_PITCH / 2,\n        durationMs: h.from.end! - h.from.start,\n        band,\n        tier,\n      };\n    });\n  }, [turns, rowIndex, windowStart, windowMs]);\n\n  const activeAgents = visibleAgents.filter((a) => openTurnByAgent.has(a.id));\n  const summary =\n    activeAgents.length === 0\n      ? overflowActiveCount > 0\n        ? `${overflowActiveCount} of the overflow agents are active.`\n        : \"No agent currently has the turn.\"\n      : activeAgents.length === 1\n        ? `${activeAgents[0]!.label} has the turn.`\n        : `${activeAgents.map((a) => a.label).join(\", \")} are active concurrently.`;\n\n  return (\n    <div\n      role=\"region\"\n      aria-label={label}\n      className={`rounded-md border border-border bg-surface p-4 ${className}`}\n    >\n      <div\n        aria-hidden=\"true\"\n        className=\"mb-1 flex font-mono text-[9px] uppercase tracking-[0.14em] text-ns-muted\"\n        style={{ paddingLeft: LABEL_W }}\n      >\n        <span className=\"flex-1 text-right\">now</span>\n      </div>\n      <div\n        className=\"grid\"\n        style={{\n          gridTemplateColumns: `${LABEL_W}px 1fr`,\n          gridAutoRows: `${ROW_PITCH}px`,\n        }}\n      >\n        {visibleAgents.map((a, i) => {\n          const open = openTurnByAgent.get(a.id);\n          const elapsed = open ? now - open.start : null;\n          return (\n            <div\n              key={a.id}\n              className=\"flex min-w-0 items-center gap-2 pr-3\"\n              style={{ gridColumn: 1, gridRow: i + 1 }}\n            >\n              <span\n                aria-hidden=\"true\"\n                className={`h-1.5 w-1.5 shrink-0 rounded-full ${\n                  open\n                    ? \"bg-foreground motion-safe:animate-pulse\"\n                    : \"bg-ns-muted\"\n                }`}\n              />\n              <span\n                className={`min-w-0 flex-1 truncate text-sm ${\n                  open ? \"text-foreground\" : \"text-ns-muted\"\n                }`}\n              >\n                {a.label}\n              </span>\n              {elapsed !== null && (\n                <span className=\"shrink-0 font-mono text-[10px] tabular-nums text-ns-muted\">\n                  {formatDuration(elapsed)}\n                </span>\n              )}\n            </div>\n          );\n        })}\n\n        {hasOverflow && (\n          <div\n            className=\"flex min-w-0 items-center gap-2 pr-3\"\n            style={{ gridColumn: 1, gridRow: visibleAgents.length + 1 }}\n          >\n            <span\n              aria-hidden=\"true\"\n              className={`h-1.5 w-1.5 shrink-0 rounded-full ${\n                overflowActiveCount > 0\n                  ? \"bg-foreground motion-safe:animate-pulse\"\n                  : \"bg-ns-muted\"\n              }`}\n            />\n            <span\n              className={`min-w-0 flex-1 truncate text-sm ${\n                overflowActiveCount > 0 ? \"text-foreground\" : \"text-ns-muted\"\n              }`}\n            >\n              +{overflowAgents.length} more\n            </span>\n            {overflowActiveCount > 0 && (\n              <span className=\"shrink-0 font-mono text-[10px] tabular-nums text-ns-muted\">\n                {overflowActiveCount} active\n              </span>\n            )}\n          </div>\n        )}\n\n        {/* track overlay: spans the full lane stack, everything inside is\n            positioned with independent left:%/top:px so no axis distorts\n            the other */}\n        <div\n          className=\"relative overflow-hidden\"\n          style={{\n            gridColumn: 2,\n            gridRow: `1 / span ${rowCount}`,\n          }}\n        >\n          {/* idle baseline: one full-width hairline per lane */}\n          {visibleAgents.map((a, i) => (\n            <div\n              key={a.id}\n              aria-hidden=\"true\"\n              className=\"absolute left-0 h-px w-full bg-ns-muted\"\n              style={{ top: i * ROW_PITCH + ROW_PITCH / 2 }}\n            />\n          ))}\n          {hasOverflow && (\n            <div\n              aria-hidden=\"true\"\n              className=\"absolute left-0 h-px w-full bg-ns-muted\"\n              style={{ top: visibleAgents.length * ROW_PITCH + ROW_PITCH / 2 }}\n            />\n          )}\n\n          {/* turn bars: finished turns dimmer, the live/open turn full\n              brightness with a breathing pulse */}\n          {turns.map((t) => {\n            const row = rowIndex.get(t.agentId);\n            if (row === undefined) return null;\n            const effectiveEnd = t.end ?? now;\n            if (effectiveEnd < windowStart) return null;\n            const clampedStart = Math.max(t.start, windowStart);\n            const clampedEnd = Math.min(effectiveEnd, now);\n            if (clampedEnd <= clampedStart && t.end !== undefined) return null;\n            const leftPct = ((clampedStart - windowStart) / windowMs) * 100;\n            const widthPct = Math.max(\n              ((clampedEnd - clampedStart) / windowMs) * 100,\n              MIN_BAR_PCT\n            );\n            const isOpen = t.end === undefined;\n            return (\n              <div\n                key={t.id}\n                aria-hidden=\"true\"\n                className={`absolute rounded-full transition-[left,width] duration-500 ease-out motion-reduce:transition-none ${\n                  isOpen\n                    ? \"bg-foreground motion-safe:animate-pulse\"\n                    : \"bg-foreground/45\"\n                }`}\n                style={{\n                  left: `${leftPct}%`,\n                  width: `${widthPct}%`,\n                  top: row * ROW_PITCH + ROW_PITCH / 2 - BAR_H / 2,\n                  height: BAR_H,\n                }}\n              />\n            );\n          })}\n\n          {/* handoff connectors: stepped (horizontal/vertical/horizontal)\n              lines built from plain divs, plus a mono duration chip */}\n          {handoffs.map((h) => {\n            const midX = (h.x1 + h.x2) / 2;\n            const yTop = Math.min(h.y1, h.y2);\n            const yBottom = Math.max(h.y1, h.y2);\n            // each extra tier steps the label one 15px row further from the\n            // rail, in its band's direction, so stacked labels never overlap\n            const TIER_STEP = 18;\n            const rawChipTop =\n              h.band === \"above\"\n                ? Math.min(h.y1, h.y2) - 20 - h.tier * TIER_STEP\n                : Math.max(h.y1, h.y2) + 8 + h.tier * TIER_STEP;\n            // clamp inside the (now overflow-hidden) track box so a handoff\n            // touching the first or last lane never clips its own label\n            const chipTop = Math.min(\n              Math.max(rawChipTop, 0),\n              rowCount * ROW_PITCH - 18\n            );\n            return (\n              <div key={h.key} aria-hidden=\"true\">\n                <div\n                  className=\"absolute h-px bg-foreground/25\"\n                  style={{\n                    top: h.y1,\n                    left: `${Math.min(h.x1, midX)}%`,\n                    width: `${Math.abs(midX - h.x1)}%`,\n                  }}\n                />\n                <div\n                  className=\"absolute w-px bg-foreground/25\"\n                  style={{\n                    left: `${midX}%`,\n                    top: yTop,\n                    height: yBottom - yTop,\n                  }}\n                />\n                <div\n                  className=\"absolute h-px bg-foreground/25\"\n                  style={{\n                    top: h.y2,\n                    left: `${Math.min(h.x2, midX)}%`,\n                    width: `${Math.abs(h.x2 - midX)}%`,\n                  }}\n                />\n                <div\n                  className=\"absolute -translate-x-1/2 whitespace-nowrap rounded-sm border border-border bg-background px-1 py-0.5 font-mono text-[10px] tabular-nums text-ns-muted\"\n                  style={{ left: `${midX}%`, top: chipTop }}\n                >\n                  {formatDuration(h.durationMs)}\n                </div>\n              </div>\n            );\n          })}\n\n          {/* now line: the right edge is always the present moment */}\n          <div\n            aria-hidden=\"true\"\n            className=\"absolute right-0 top-0 w-px bg-border\"\n            style={{ height: rowCount * ROW_PITCH }}\n          />\n        </div>\n      </div>\n\n      <div aria-live=\"polite\" aria-atomic=\"true\" className=\"sr-only\">\n        {summary}\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "components/ui/timeline-agent-lanes.tsx"
    }
  ],
  "cssVars": {
    "theme": {
      "color-ns-muted": "var(--ns-muted)",
      "color-surface": "var(--surface)"
    },
    "light": {
      "ns-muted": "#4d4d4d",
      "surface": "#fafafa"
    },
    "dark": {
      "ns-muted": "#8f8f8f",
      "surface": "#171717"
    }
  },
  "meta": {
    "collection": "core",
    "tags": [
      "agent",
      "timeline",
      "orchestration",
      "status",
      "aria-live",
      "concurrency",
      "dashboard",
      "mono"
    ],
    "instruction": "A live multi-agent turn tracker for orchestration UIs — 'who is doing what right now'. Renders one horizontal hairline lane per agent (label column left, track column right, laid out on a CSS grid so both share row geometry with zero manual sync). Idle lanes sit at --ns-muted (dim dot, dim label, thin 1px hairline); the lane whose agent currently holds an open turn brightens its dot and label to --foreground and gets a breathing pulse, with a live font-mono tabular-nums elapsed readout (mm:ss) ticking beside the name. Data model: consumer owns `agents` ({id,label}[], lane order) and `turns` ({id, agentId, start, end?}[]) — a turn with no `end` is the one currently in flight; the component holds no orchestration logic of its own, only layout, a 1s wall clock (skipped entirely when a `now` prop is supplied, making the component fully controlled/deterministic), and announcement text. TIME AXIS: a rolling `windowMs` window (default 20000) with a 'now' line pinned to the right edge — this is the load-bearing design decision: timeline-agent-lanes shows the present moment, not a post-hoc trace, so turns older than the window silently age off the left exactly like a real monitor strip, and there is deliberately NO scrub/seek control — adding one would turn it back into the span-tree debugger this component exists to differ from. Past (finished) turns stay visible inside the window at reduced opacity (foreground/45) only so a handoff connector has two ends to draw between; the live turn's bar is full-opacity foreground with the pulse. CONCURRENCY: any number of turns with no `end` can coexist across different agents with no special-casing — each renders its own bar independently, which is exactly how a parallel fan-out (one planner spawning three subagents at once) reads: three lanes bright at the same x-range. HANDOFFS: a stepped (horizontal/vertical/horizontal) connector plus a Geist Mono tabular-nums duration chip is drawn from a finished turn to the next turn on a DIFFERENT agent that starts at or after it ends (400ms slack for real event-timestamp jitter) — a genuine baton pass, not two turns that happen to overlap; one finished turn can feed multiple connectors, so a fan-out reads as one source splitting into several stepped lines. Connector labels alternate above/below the rail by arrival order and a handoff greedily flips to the other band if the previous same-band label sits within 10% of track width — the answer to two handoffs landing close together in time never drawing label-on-label. LANE COUNT: readable from 2 up to 12 lanes; beyond 12 the extra agents collapse into one aggregate '+N more' row that brightens with a live count badge ('3 active') when any of them hold a turn, but never participates in handoff connectors since there's no single fixed row to draw a line to or from — a stated degrade, not a silent one. ACCESSIBILITY: role=region with an accessible name; a single aria-live=polite aria-atomic visually-hidden region always holds the CURRENT resting summary ('Planner has the turn.' / 'Search agent, Codegen agent are active concurrently.' / 'No agent currently has the turn.') recomputed every render, so the browser's own live-region diffing announces genuine turn changes and a screen reader landing mid-run still hears an accurate state rather than only a diff log. SCOPE: no interactive controls at all (no scrub, no pause, no expand) — a deliberate choice, not an omission for time; it's a passive live status board, so it renders no controls and is exempt from the tabbability rule. REDUCED MOTION: the breathing pulse and bar-position transition both drop out (motion-reduce:animate-none / transition-none equivalents) — the resting brightness contrast between active and idle lanes already carries the full signal without any motion. Pure DOM: every bar, hairline, and connector segment is a plain absolutely positioned div using independent left:%/top:px axes (never a scaled SVG viewBox, which would stretch the mono duration text). No canvas, no SVG. Zero dependencies. Props: agents, turns, label, windowMs, now (controlled clock), className."
  },
  "type": "registry:ui"
}