{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "agent-06",
  "title": "Agent fleet",
  "description": "Every main agent at a glance under rolling totals, where the list switches between rows and cards with each agent gliding to its new place, with filters and sub-agents that unfold with Approve and Retry.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/agent-run.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/kbd.json",
    "https://ui.ndekocode.dev/r/live-duration.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/mesh-tile.json",
    "https://ui.ndekocode.dev/r/motion-number.json",
    "https://ui.ndekocode.dev/r/motion-presets.json",
    "https://ui.ndekocode.dev/r/motion-word-roll.json",
    "https://ui.ndekocode.dev/r/replay-button.json",
    "https://ui.ndekocode.dev/r/run-session.json",
    "https://ui.ndekocode.dev/r/segments.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/toggle-group.json",
    "https://ui.ndekocode.dev/r/use-agent-run.json",
    "https://ui.ndekocode.dev/r/use-kept-height.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/use-session.json",
    "https://ui.ndekocode.dev/r/use-timeouts.json",
    "https://ui.ndekocode.dev/r/utils.json",
    "https://ui.ndekocode.dev/r/words.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/agent/agent-06.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport { useContext, useId, useRef, useState } from 'react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { ClockGateContext } from '@/registry/ndeko/hooks/use-agent-run';\nimport { useKeptHeight } from '@/registry/ndeko/hooks/use-kept-height';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport {\n  useSession,\n  type SessionStep,\n} from '@/registry/ndeko/hooks/use-session';\nimport { useTimeouts } from '@/registry/ndeko/hooks/use-timeouts';\nimport {\n  emptyRun,\n  reduceRun,\n  type AgentStatus as AgentState,\n  type ApprovalRequest,\n  type RunAgent,\n  type RunEvent,\n  type RunSnapshot,\n} from '@/registry/ndeko/lib/agent-run';\nimport {\n  pressedQuietOf,\n  spokenUnless,\n} from '@/registry/ndeko/lib/demonstration';\nimport { ChevronDownIcon } from '@/registry/ndeko/lib/icons';\nimport { risePresenceOf, springOf } from '@/registry/ndeko/lib/motion-presets';\nimport { applyBatchAt, restingOf } from '@/registry/ndeko/lib/run-session';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { countOf } from '@/registry/ndeko/lib/words';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Fold } from '@/registry/ndeko/ui/chat-motion';\nimport { ClockGate } from '@/registry/ndeko/ui/live-duration';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { ReplayButton } from '@/registry/ndeko/ui/replay-button';\nimport { Segments, type Segment } from '@/registry/ndeko/ui/segments';\nimport { ToggleGroup, ToggleGroupItem } from '@/registry/ndeko/ui/toggle-group';\n\nimport { AgentActions, pendingApprovalOf } from './_parts/agent-actions';\nimport { AgentClock } from './_parts/agent-clock';\nimport {\n  AGENT_STATUS_WORD,\n  AgentStatus,\n  pulsingIdsOf,\n} from './_parts/agent-status';\nimport { AgentTile } from './_parts/agent-tile';\nimport { CostFigure } from './_parts/cost-figure';\nimport { CODER, PLANNER, RESEARCHER, REVIEWER, WRITER } from './_parts/crew';\nimport { DECIDE_AFTER_MS, pressedIdOf } from './_parts/demo';\nimport { focusLater } from './_parts/focus-later';\nimport { KeyedHeight } from './_parts/keyed-height';\nimport { useAgentAnnouncement } from './_parts/use-agent-announcement';\n\nexport type FleetView = 'rows' | 'cards';\n\nexport type FleetFilter = 'all' | 'needs-you' | 'failed';\n\ntype FleetEntry = {\n  agent: RunAgent;\n  subAgents: RunAgent[];\n  spend: number;\n};\n\nconst VIEWS: Segment<FleetView>[] = [\n  { value: 'rows', label: 'Rows' },\n  { value: 'cards', label: 'Cards' },\n];\n\nconst FILTER_LABEL: Record<FleetFilter, string> = {\n  all: 'All',\n  'needs-you': 'Needs you',\n  failed: 'Failed',\n};\n\nconst FILTERS: FleetFilter[] = ['all', 'needs-you', 'failed'];\n\nconst EMPTY_LINE: Record<FleetFilter, string> = {\n  all: 'No agents are running',\n  'needs-you': 'Nothing waits on you right now',\n  failed: 'No agent has failed',\n};\n\nconst ROW_GRID: React.CSSProperties = {\n  gridTemplateColumns: 'auto minmax(0, 1fr) auto auto',\n  gridTemplateAreas: \"'tile title figures toggle' 'tile meta figures toggle'\",\n};\n\nconst CARD_GRID: React.CSSProperties = {\n  gridTemplateColumns: 'auto minmax(0, 1fr) auto',\n  gridTemplateAreas:\n    \"'tile title toggle' 'meta meta meta' 'figures figures figures'\",\n};\n\nconst LIST_SURFACE: Record<FleetView, string> = {\n  rows: 'm-0 bg-card hairline-ring ring-border rounded-xl shadow-[0_1px_2px_rgb(0_0_0/0.04)]',\n  cards: 'rounded-xl',\n};\n\nconst LIST_LAYOUT: Record<FleetView, string> = {\n  rows: 'flex flex-col gap-0.5 p-0.5',\n  cards: 'grid grid-cols-1 gap-3 @md:grid-cols-2',\n};\n\nconst QUICK_EXIT = { duration: 0.14 };\n\nconst CARD_PRESENCE = {\n  initial: { opacity: 0, scale: 0.98 },\n  animate: { opacity: 1, scale: 1 },\n  exit: { opacity: 0, scale: 0.98, transition: QUICK_EXIT },\n};\n\nconst FADE_ONLY = {\n  initial: { opacity: 0 },\n  animate: { opacity: 1 },\n  exit: { opacity: 0, transition: QUICK_EXIT },\n};\n\nfunction itemPresenceOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_ONLY;\n  }\n  return CARD_PRESENCE;\n}\n\nconst ITEM_CLASS: Record<FleetView, string> = {\n  rows: 'rounded-lg px-2 py-2',\n  cards:\n    'bg-card hairline-ring ring-border rounded-xl p-3 shadow-[0_1px_2px_rgb(0_0_0/0.04)]',\n};\n\nconst FIGURES_CLASS: Record<FleetView, string> = {\n  rows: 'flex flex-col items-end text-end',\n  cards: 'flex items-baseline justify-between gap-3 pt-1',\n};\n\nconst SUB_LIST_CLASS: Record<FleetView, string> = {\n  rows: 'ps-9',\n  cards: 'ps-0',\n};\n\nfunction isMainAgent(agent: RunAgent) {\n  return agent.parentId === undefined;\n}\n\nfunction costOf(agent: RunAgent) {\n  return agent.costUsd ?? 0;\n}\n\nfunction totalCostOf(agents: RunAgent[]) {\n  let total = 0;\n  for (const agent of agents) {\n    total += costOf(agent);\n  }\n  return total;\n}\n\nfunction spendOf(agent: RunAgent, subAgents: RunAgent[]) {\n  const ownCost = costOf(agent);\n  const subAgentCost = totalCostOf(subAgents);\n  return ownCost + subAgentCost;\n}\n\nfunction entriesOf(agents: RunAgent[]): FleetEntry[] {\n  const mainAgents = agents.filter(isMainAgent);\n  return mainAgents.map((agent) => {\n    const subAgents = agents.filter(\n      (candidate) => candidate.parentId === agent.id\n    );\n    const spend = spendOf(agent, subAgents);\n    return { agent, subAgents, spend };\n  });\n}\n\nfunction membersOf(entry: FleetEntry) {\n  return [entry.agent, ...entry.subAgents];\n}\n\nfunction needsPerson(entry: FleetEntry, approvals: ApprovalRequest[]) {\n  const members = membersOf(entry);\n  return members.some((member) => {\n    const pending = pendingApprovalOf(approvals, member.id);\n    return pending !== undefined;\n  });\n}\n\nfunction hasFailure(entry: FleetEntry) {\n  const members = membersOf(entry);\n  return members.some((member) => member.status === 'failed');\n}\n\nfunction matchesFilter(\n  entry: FleetEntry,\n  filter: FleetFilter,\n  approvals: ApprovalRequest[]\n) {\n  if (filter === 'needs-you') {\n    return needsPerson(entry, approvals);\n  }\n  if (filter === 'failed') {\n    return hasFailure(entry);\n  }\n  return true;\n}\n\nfunction countWithStatus(agents: RunAgent[], status: AgentState) {\n  const matching = agents.filter((agent) => agent.status === status);\n  return matching.length;\n}\n\nfunction pendingCountOf(approvals: ApprovalRequest[]) {\n  const pending = approvals.filter((approval) => approval.status === 'pending');\n  return pending.length;\n}\n\nfunction attentionOf(entry: FleetEntry, approvals: ApprovalRequest[]) {\n  const waitingSubAgents = entry.subAgents.filter((subAgent) => {\n    const pending = pendingApprovalOf(approvals, subAgent.id);\n    return pending !== undefined;\n  });\n  const failedCount = countWithStatus(entry.subAgents, 'failed');\n  if (waitingSubAgents.length > 0) {\n    const waitingWord = countOf(waitingSubAgents.length, 'sub-agent');\n    return { tone: 'text-warning-foreground', text: `${waitingWord} waiting` };\n  }\n  if (failedCount > 0) {\n    const failedWord = countOf(failedCount, 'sub-agent');\n    return { tone: 'text-destructive-ink', text: `${failedWord} failed` };\n  }\n  return null;\n}\n\nfunction chevronTurnOf(isOpen: boolean) {\n  if (isOpen) {\n    return 'rotate-180';\n  }\n  return 'rotate-0';\n}\n\nfunction toggleLabelOf(entry: FleetEntry, isOpen: boolean) {\n  const subAgents = countOf(entry.subAgents.length, 'sub-agent');\n  if (isOpen) {\n    return `Hide the ${subAgents} of ${entry.agent.name}`;\n  }\n  return `Show the ${subAgents} of ${entry.agent.name}`;\n}\n\ntype SubAgentListProps = {\n  owner: RunAgent;\n  subAgents: RunAgent[];\n  approvals: ApprovalRequest[];\n  pressedApproveId: string | null;\n  pressedRetryId: string | null;\n  onApprove?: (approvalId: string) => void;\n  onRetry?: (agentId: string) => void;\n};\n\nfunction SubAgentList({\n  owner,\n  subAgents,\n  approvals,\n  pressedApproveId,\n  pressedRetryId,\n  onApprove,\n  onRetry,\n}: SubAgentListProps) {\n  const listRef = useRef<HTMLUListElement>(null);\n\n  function focusRow(agentId: string) {\n    focusLater(listRef, `[data-sub-agent=\"${agentId}\"]`);\n  }\n\n  return (\n    <ul\n      ref={listRef}\n      aria-label={`Sub-agents of ${owner.name}`}\n      className='flex flex-col gap-1 pt-2'\n    >\n      {subAgents.map((subAgent) => (\n        <li\n          key={subAgent.id}\n          tabIndex={-1}\n          data-sub-agent={subAgent.id}\n          className='bg-foreground/[0.025] dark:bg-foreground/[0.04] focus-visible:ring-ring/25 flex items-start gap-2.5 rounded-lg px-2.5 py-2 outline-none focus-visible:ring-[3px]'\n        >\n          <AgentTile\n            name={subAgent.name}\n            series={subAgent.series}\n            size='sm'\n            className='mt-px'\n          />\n          <div className='min-w-0 flex-1'>\n            <p className='flex flex-wrap items-center gap-x-2'>\n              <span className='text-[13px] leading-5 font-medium'>\n                {subAgent.name}\n              </span>\n              <AgentStatus status={subAgent.status} size='sm' isStill />\n            </p>\n            <p className='text-muted-foreground truncate text-xs leading-5'>\n              {subAgent.task}\n            </p>\n            <AgentActions\n              agent={subAgent}\n              approvals={approvals}\n              onApprove={onApprove}\n              onRetry={onRetry}\n              onDecided={focusRow}\n              isApprovePressed={pressedApproveId === subAgent.id}\n              isRetryPressed={pressedRetryId === subAgent.id}\n            />\n          </div>\n          <div className='shrink-0 text-end text-xs leading-5'>\n            <p>\n              <CostFigure usd={costOf(subAgent)} />\n            </p>\n            <p className='text-muted-foreground'>\n              <AgentClock agent={subAgent} />\n            </p>\n          </div>\n        </li>\n      ))}\n    </ul>\n  );\n}\n\ntype FleetItemProps = {\n  entry: FleetEntry;\n  view: FleetView;\n  /** What the places of the items depend on: an item is measured again only when it changes. */\n  layoutKey: string;\n  approvals: ApprovalRequest[];\n  isOpen: boolean;\n  isStill: boolean;\n  isTogglePressed: boolean;\n  pressedApproveId: string | null;\n  pressedRetryId: string | null;\n  onToggle: (agentId: string) => void;\n  onApprove?: (approvalId: string) => void;\n  onRetry?: (agentId: string) => void;\n};\n\nfunction gridOf(view: FleetView) {\n  if (view === 'cards') {\n    return CARD_GRID;\n  }\n  return ROW_GRID;\n}\n\nfunction FleetItem({\n  entry,\n  view,\n  layoutKey,\n  approvals,\n  isOpen,\n  isStill,\n  isTogglePressed,\n  pressedApproveId,\n  pressedRetryId,\n  onToggle,\n  onApprove,\n  onRetry,\n}: FleetItemProps) {\n  const panelId = useId();\n  const isGateOpen = useContext(ClockGateContext);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const spring = springOf(shouldReduceMotion);\n  const presence = itemPresenceOf(shouldReduceMotion);\n  const { agent, subAgents } = entry;\n  const hasSubAgents = subAgents.length > 0;\n  const attention = attentionOf(entry, approvals);\n  // A closed fold keeps its rows in the page, so their clocks hold still until it opens.\n  const areSubClocksLive = isOpen && isGateOpen;\n\n  function toggle() {\n    onToggle(agent.id);\n  }\n\n  return (\n    <motion.li\n      layout\n      layoutDependency={layoutKey}\n      transition={{ layout: spring }}\n      {...presence}\n      className={cn(\n        'transition-[background-color,box-shadow] duration-300 ease-(--ease-out-strong)',\n        ITEM_CLASS[view]\n      )}\n    >\n      <div className='grid items-start gap-x-3 gap-y-1' style={gridOf(view)}>\n        <motion.span\n          layout='position'\n          layoutDependency={view}\n          transition={spring}\n          className='[grid-area:tile]'\n        >\n          <AgentTile name={agent.name} series={agent.series} />\n        </motion.span>\n        <motion.p\n          layout='position'\n          layoutDependency={view}\n          transition={spring}\n          className='flex min-w-0 items-baseline gap-2 [grid-area:title]'\n        >\n          <span className='truncate text-[13px] leading-6 font-medium'>\n            {agent.name}\n          </span>\n          <span className='text-muted-foreground truncate text-xs'>\n            {agent.model}\n          </span>\n        </motion.p>\n        <motion.div\n          layout='position'\n          layoutDependency={view}\n          transition={spring}\n          className='flex min-w-0 flex-col gap-0.5 [grid-area:meta]'\n        >\n          <p className='text-foreground/85 line-clamp-2 text-xs leading-5'>\n            {agent.task}\n          </p>\n          <p className='flex flex-wrap items-center gap-x-3 gap-y-0.5'>\n            <AgentStatus status={agent.status} isStill={isStill} />\n            {attention && (\n              <span className={cn('text-xs', attention.tone)}>\n                {attention.text}\n              </span>\n            )}\n          </p>\n        </motion.div>\n        <motion.div\n          layout='position'\n          layoutDependency={view}\n          transition={spring}\n          className={cn('text-[13px] [grid-area:figures]', FIGURES_CLASS[view])}\n        >\n          <span className='leading-6 font-medium'>\n            <CostFigure usd={entry.spend} />\n          </span>\n          <span className='text-muted-foreground text-xs leading-5'>\n            <AgentClock agent={agent} />\n          </span>\n        </motion.div>\n        <div className='[grid-area:toggle]'>\n          {hasSubAgents && (\n            <Button\n              type='button'\n              variant='ghost'\n              size='icon-sm'\n              aria-expanded={isOpen}\n              aria-controls={panelId}\n              aria-label={toggleLabelOf(entry, isOpen)}\n              onClick={toggle}\n              className={cn(\n                'text-muted-foreground',\n                pressedQuietOf(isTogglePressed)\n              )}\n            >\n              <ChevronDownIcon\n                className={cn(\n                  'transition-transform duration-200 ease-(--ease-out-strong)',\n                  chevronTurnOf(isOpen)\n                )}\n              />\n            </Button>\n          )}\n        </div>\n      </div>\n      {hasSubAgents && (\n        <motion.div\n          layout='position'\n          layoutDependency={view}\n          transition={spring}\n        >\n          <Fold open={isOpen} id={panelId} className={SUB_LIST_CLASS[view]}>\n            <ClockGate isActive={areSubClocksLive}>\n              <SubAgentList\n                owner={agent}\n                subAgents={subAgents}\n                approvals={approvals}\n                pressedApproveId={pressedApproveId}\n                pressedRetryId={pressedRetryId}\n                onApprove={onApprove}\n                onRetry={onRetry}\n              />\n            </ClockGate>\n          </Fold>\n        </motion.div>\n      )}\n    </motion.li>\n  );\n}\n\nfunction FleetTotal({\n  label,\n  children,\n  note,\n}: {\n  label: string;\n  children: React.ReactNode;\n  note?: string;\n}) {\n  return (\n    <div className='bg-foreground/[0.03] dark:bg-foreground/[0.05] flex flex-col gap-0.5 rounded-lg px-3 py-2.5'>\n      <dt className='text-muted-foreground text-xs'>{label}</dt>\n      <dd className='text-lg leading-7 font-medium tabular-nums'>{children}</dd>\n      {note && <dd className='text-muted-foreground text-[11px]'>{note}</dd>}\n    </div>\n  );\n}\n\nfunction changeFilter(\n  values: unknown[],\n  onFilterChange: (filter: FleetFilter) => void\n) {\n  const [next] = values;\n  const filter = FILTERS.find((candidate) => candidate === next);\n  if (filter) {\n    onFilterChange(filter);\n  }\n}\n\nconst NO_APPROVALS: ApprovalRequest[] = [];\n\nconst NO_OPEN_IDS: string[] = [];\n\nfunction withOpen(openIds: string[], agentId: string, isOpen: boolean) {\n  const others = openIds.filter((openId) => openId !== agentId);\n  if (isOpen) {\n    return [...others, agentId];\n  }\n  return others;\n}\n\n/** What decides where each item sits: the layout and which agents show. An item travels only when it changes. */\nfunction layoutKeyOf(view: FleetView, entries: FleetEntry[]) {\n  const ids = entries.map((entry) => entry.agent.id);\n  return `${view}|${ids.join(' ')}`;\n}\n\nexport type AgentFleetProps = {\n  agents: RunAgent[];\n  approvals?: ApprovalRequest[];\n  /** What was spent today before these agents, added to theirs in the total. */\n  earlierSpend?: number;\n  onApprove?: (approvalId: string) => void;\n  onRetry?: (agentId: string) => void;\n  defaultView?: FleetView;\n  /** The layout, when it is held outside: a demonstration or a control beside the fleet switches it. */\n  view?: FleetView;\n  onViewChange?: (view: FleetView) => void;\n  /** The main agents whose sub-agents show, when that is held outside. */\n  openIds?: string[];\n  onOpenChange?: (agentId: string, isOpen: boolean) => void;\n  /** The sub-agent whose Approve a demonstration holds down. */\n  pressedApproveId?: string | null;\n  /** The sub-agent whose Retry a demonstration holds down. */\n  pressedRetryId?: string | null;\n  /** The main agent whose fold a demonstration holds down. */\n  pressedToggleId?: string | null;\n  className?: string;\n};\n\nexport function AgentFleet({\n  agents,\n  approvals = NO_APPROVALS,\n  earlierSpend = 0,\n  onApprove,\n  onRetry,\n  defaultView = 'rows',\n  view,\n  onViewChange,\n  openIds,\n  onOpenChange,\n  pressedApproveId = null,\n  pressedRetryId = null,\n  pressedToggleId = null,\n  className,\n}: AgentFleetProps) {\n  const [ownView, setOwnView] = useState<FleetView>(defaultView);\n  const [filter, setFilter] = useState<FleetFilter>('all');\n  const [ownOpenIds, setOwnOpenIds] = useState(NO_OPEN_IDS);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const risePresence = risePresenceOf(shouldReduceMotion);\n  const shownView = view ?? ownView;\n  const shownOpenIds = openIds ?? ownOpenIds;\n  const entries = entriesOf(agents);\n  const visibleEntries = entries.filter((entry) =>\n    matchesFilter(entry, filter, approvals)\n  );\n  const mainAgents = entries.map((entry) => entry.agent);\n  const pulsingIds = pulsingIdsOf(mainAgents);\n  const layoutKey = layoutKeyOf(shownView, visibleEntries);\n  const isEmpty = visibleEntries.length === 0;\n  const runningCount = countWithStatus(agents, 'running');\n  const waitingCount = pendingCountOf(approvals);\n  const failedCount = countWithStatus(agents, 'failed');\n  const agentSpend = totalCostOf(agents);\n  const spendToday = earlierSpend + agentSpend;\n\n  function countFor(candidate: FleetFilter) {\n    const matching = entries.filter((entry) =>\n      matchesFilter(entry, candidate, approvals)\n    );\n    return matching.length;\n  }\n\n  function changeView(next: FleetView) {\n    setOwnView(next);\n    onViewChange?.(next);\n  }\n\n  function toggle(agentId: string) {\n    const isOpen = !shownOpenIds.includes(agentId);\n    setOwnOpenIds((current) => withOpen(current, agentId, isOpen));\n    onOpenChange?.(agentId, isOpen);\n  }\n\n  function showAll() {\n    setFilter('all');\n  }\n\n  return (\n    <section\n      aria-label='Agent fleet'\n      className={cn('@container flex flex-col gap-3', className)}\n    >\n      <dl className='grid grid-cols-2 gap-2 @md:grid-cols-4'>\n        <FleetTotal label='Running'>\n          <MotionNumber value={runningCount} />\n        </FleetTotal>\n        <FleetTotal label='Waiting on you'>\n          <MotionNumber value={waitingCount} />\n        </FleetTotal>\n        <FleetTotal label='Failed'>\n          <MotionNumber value={failedCount} />\n        </FleetTotal>\n        <FleetTotal label='Spend today' note='Illustrative'>\n          <CostFigure usd={spendToday} />\n        </FleetTotal>\n      </dl>\n      <div className='flex flex-wrap items-center justify-between gap-2'>\n        <ToggleGroup\n          aria-label='Show agents'\n          value={[filter]}\n          onValueChange={(values) => changeFilter(values, setFilter)}\n          travel\n          size='sm'\n          className='gap-1'\n        >\n          {FILTERS.map((candidate) => (\n            <ToggleGroupItem\n              key={candidate}\n              value={candidate}\n              className='rounded-full px-3 text-xs'\n            >\n              {FILTER_LABEL[candidate]}\n              <span className='text-muted-foreground tabular-nums'>\n                <MotionNumber value={countFor(candidate)} />\n              </span>\n            </ToggleGroupItem>\n          ))}\n        </ToggleGroup>\n        <Segments\n          value={shownView}\n          segments={VIEWS}\n          onValueChange={changeView}\n          label='Layout'\n          className='w-32'\n        />\n      </div>\n      <KeyedHeight\n        changeKey={layoutKey}\n        className={cn(\n          'transition-[background-color,box-shadow] duration-300 ease-(--ease-out-strong)',\n          LIST_SURFACE[shownView],\n          isEmpty && 'hidden'\n        )}\n      >\n        <ul\n          aria-label='Main agents'\n          className={cn('relative', LIST_LAYOUT[shownView])}\n        >\n          <AnimatePresence mode='popLayout' initial={false}>\n            {visibleEntries.map((entry) => (\n              <FleetItem\n                key={entry.agent.id}\n                entry={entry}\n                view={shownView}\n                layoutKey={layoutKey}\n                approvals={approvals}\n                isOpen={shownOpenIds.includes(entry.agent.id)}\n                isStill={!pulsingIds.has(entry.agent.id)}\n                isTogglePressed={pressedToggleId === entry.agent.id}\n                pressedApproveId={pressedApproveId}\n                pressedRetryId={pressedRetryId}\n                onToggle={toggle}\n                onApprove={onApprove}\n                onRetry={onRetry}\n              />\n            ))}\n          </AnimatePresence>\n        </ul>\n      </KeyedHeight>\n      <AnimatePresence initial={false}>\n        {isEmpty && (\n          <motion.div\n            key={filter}\n            className='bg-foreground/[0.03] dark:bg-foreground/[0.05] flex flex-col items-center gap-3 rounded-xl px-4 py-8 text-center'\n            {...risePresence}\n          >\n            <p className='text-muted-foreground text-[13px]'>\n              {EMPTY_LINE[filter]}\n            </p>\n            <Button type='button' variant='outline' size='sm' onClick={showAll}>\n              Show all agents\n            </Button>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </section>\n  );\n}\n\nconst MINUTE_MS = 60_000;\n\nconst LOADED_AT = Date.now();\n\nfunction since(minutes: number) {\n  return LOADED_AT - minutes * MINUTE_MS;\n}\n\nconst FLEET: RunAgent[] = [\n  {\n    ...RESEARCHER,\n    parentId: undefined,\n    status: 'running',\n    task: 'Watching competitor prices for the spring catalogue',\n    costUsd: 0.412,\n    startedAt: since(12),\n  },\n  {\n    id: 'price-reader',\n    name: 'Price reader',\n    series: 2,\n    status: 'running',\n    model: 'Claude Haiku',\n    parentId: RESEARCHER.id,\n    task: 'Reading 6 product pages on Larkfield Goods',\n    costUsd: 0.061,\n    startedAt: since(3),\n  },\n  {\n    id: 'feed-reader',\n    name: 'Feed reader',\n    series: 2,\n    status: 'done',\n    model: 'Claude Haiku',\n    parentId: RESEARCHER.id,\n    task: 'Read the Ostrava Supply price feed',\n    costUsd: 0.034,\n    startedAt: since(9),\n    endedAt: since(7),\n  },\n  {\n    ...WRITER,\n    parentId: undefined,\n    status: 'running',\n    task: 'Writing the release notes for version 4.2',\n    costUsd: 0.188,\n    startedAt: since(4),\n  },\n  {\n    ...CODER,\n    parentId: undefined,\n    status: 'running',\n    task: 'Fixing the flaky checkout test',\n    costUsd: 1.204,\n    startedAt: since(21),\n  },\n  {\n    id: 'test-runner',\n    name: 'Test runner',\n    series: 5,\n    status: 'running',\n    model: 'Claude Haiku',\n    parentId: CODER.id,\n    task: 'Running checkout.spec.ts 20 times',\n    costUsd: 0.092,\n    startedAt: since(2),\n  },\n  {\n    id: 'log-reader',\n    name: 'Log reader',\n    series: 5,\n    status: 'done',\n    model: 'Claude Haiku',\n    parentId: CODER.id,\n    task: 'Found the timeout in the payment mock',\n    costUsd: 0.047,\n    startedAt: since(15),\n    endedAt: since(11),\n  },\n  {\n    ...REVIEWER,\n    parentId: undefined,\n    status: 'running',\n    task: 'Checking the Fernhill Foods supply contract',\n    costUsd: 0.356,\n    startedAt: since(7),\n  },\n  {\n    id: 'clause-finder',\n    name: 'Clause finder',\n    series: 4,\n    status: 'running',\n    model: 'Claude Sonnet',\n    parentId: REVIEWER.id,\n    task: 'Listing the renewal and penalty clauses',\n    costUsd: 0.073,\n    startedAt: since(5),\n  },\n  {\n    ...PLANNER,\n    status: 'done',\n    task: 'Drafted the Q4 roadmap in 9 themes',\n    costUsd: 0.884,\n    startedAt: since(26),\n    endedAt: since(2),\n  },\n];\n\nconst SHARE_APPROVAL: ApprovalRequest = {\n  id: 'share-summary',\n  title: 'Share the contract summary with legal@fernhill.example',\n  risk: 'medium',\n  status: 'pending',\n  agentId: 'clause-finder',\n};\n\nconst INITIAL_RUN = emptyRun({ id: 'fleet', agents: FLEET });\n\nconst EARLIER_SPEND = 9.42;\n\nfunction patch(id: string, changes: Partial<RunAgent>): RunEvent {\n  return { type: 'agent.updated', id, patch: changes };\n}\n\nconst TEST_RUNNER_ID = 'test-runner';\n\nconst CLAUSE_FINDER_ID = 'clause-finder';\n\ntype FleetState = {\n  run: RunSnapshot;\n  view: FleetView;\n  openIds: string[];\n  /** The agents a person or the demonstration sent for a second try. */\n  retriedIds: string[];\n};\n\ntype FleetAction =\n  | { type: 'events'; events: RunEvent[] }\n  | { type: 'approve'; approvalId: string }\n  | { type: 'shared' }\n  | { type: 'retry'; agentId: string }\n  | { type: 'retried'; agentId: string }\n  | { type: 'view'; view: FleetView }\n  | { type: 'open'; agentId: string; isOpen: boolean };\n\ntype FleetStep = SessionStep<FleetState, FleetAction>;\n\nconst INITIAL: FleetState = {\n  run: INITIAL_RUN,\n  view: 'rows',\n  openIds: [],\n  retriedIds: [],\n};\n\nfunction agentOf(state: FleetState, agentId: string) {\n  return state.run.agents.find((agent) => agent.id === agentId);\n}\n\nfunction patchedRun(run: RunSnapshot, events: RunEvent[], now: number) {\n  return applyBatchAt(run, { events }, now);\n}\n\nfunction withApproval(state: FleetState, approvalId: string, now: number) {\n  const run = patchedRun(\n    state.run,\n    [\n      { type: 'approval.resolved', id: approvalId, decision: 'approved' },\n      patch(CLAUSE_FINDER_ID, {\n        status: 'running',\n        task: 'Sharing the summary with legal',\n      }),\n      patch(REVIEWER.id, {\n        status: 'running',\n        task: 'Checking the Fernhill Foods supply contract',\n      }),\n    ],\n    now\n  );\n  return { ...state, run };\n}\n\nfunction hasApprovedShare(state: FleetState) {\n  return state.run.approvals.some((approval) => {\n    const isShare = approval.id === SHARE_APPROVAL.id;\n    const isApproved = approval.status === 'approved';\n    return isShare && isApproved;\n  });\n}\n\n/** The script and the hand of a person may both land the same share: only the first one counts. */\nfunction withShareLanded(state: FleetState, now: number) {\n  const finder = agentOf(state, CLAUSE_FINDER_ID);\n  const isRunning = finder?.status === 'running';\n  const isSharing = isRunning && hasApprovedShare(state);\n  if (!isSharing) {\n    return state;\n  }\n  const landed = patch(CLAUSE_FINDER_ID, {\n    status: 'done',\n    task: 'Shared the summary with legal',\n    costUsd: 0.097,\n  });\n  const run = reduceRun(state.run, landed, now);\n  return { ...state, run };\n}\n\nfunction withRetry(state: FleetState, agentId: string, now: number) {\n  const agent = agentOf(state, agentId);\n  const isFailed = agent?.status === 'failed';\n  if (!isFailed) {\n    return state;\n  }\n  const run = patchedRun(\n    state.run,\n    [\n      patch(agentId, {\n        status: 'running',\n        task: 'Second try with a longer payment timeout',\n        startedAt: undefined,\n        endedAt: undefined,\n      }),\n      patch(CODER.id, { task: 'Fixing the flaky checkout test' }),\n    ],\n    now\n  );\n  const retriedIds = [...state.retriedIds, agentId];\n  return { ...state, run, retriedIds };\n}\n\n/** The same for a retry: the script lands it, and so does the timer a person's click starts. */\nfunction withRetryLanded(state: FleetState, agentId: string, now: number) {\n  const agent = agentOf(state, agentId);\n  const isRunning = agent?.status === 'running';\n  const wasRetried = state.retriedIds.includes(agentId);\n  const isRetrying = isRunning && wasRetried;\n  if (!isRetrying) {\n    return state;\n  }\n  const landed = patch(agentId, {\n    status: 'done',\n    task: 'checkout.spec.ts passed 20 times in a row',\n    costUsd: 0.141,\n  });\n  const run = reduceRun(state.run, landed, now);\n  return { ...state, run };\n}\n\nfunction applyAt(\n  state: FleetState,\n  action: FleetAction,\n  now: number\n): FleetState {\n  if (action.type === 'approve') {\n    return withApproval(state, action.approvalId, now);\n  }\n  if (action.type === 'shared') {\n    return withShareLanded(state, now);\n  }\n  if (action.type === 'retry') {\n    return withRetry(state, action.agentId, now);\n  }\n  if (action.type === 'retried') {\n    return withRetryLanded(state, action.agentId, now);\n  }\n  if (action.type === 'view') {\n    return { ...state, view: action.view };\n  }\n  if (action.type === 'open') {\n    const openIds = withOpen(state.openIds, action.agentId, action.isOpen);\n    return { ...state, openIds };\n  }\n  const run = applyBatchAt(state.run, action, now);\n  return { ...state, run };\n}\n\n/** Times are stamped when an action lands, as a backend would stream it. */\nfunction reducer(state: FleetState, action: FleetAction) {\n  return applyAt(state, action, Date.now());\n}\n\n/** The fleet started minutes ago, so its resting state is stamped on the same clock as its agents. */\nfunction applyAfterLoading(\n  state: FleetState,\n  action: FleetAction,\n  sinceStart: number\n) {\n  return applyAt(state, action, LOADED_AT + sinceStart);\n}\n\nfunction landing(after: number, ...events: RunEvent[]): FleetStep {\n  return { after, action: { type: 'events', events } };\n}\n\nconst TOGGLE_PREFIX = 'toggle:';\n\n/** What the demonstration does on its own: a person who takes over finds the same controls, and the fleet goes on. */\nfunction demo(after: number, action: FleetAction, press?: string): FleetStep {\n  return { after, by: 'demo', action, press };\n}\n\nfunction fold(after: number, agentId: string, isOpen: boolean) {\n  const action: FleetAction = { type: 'open', agentId, isOpen };\n  return demo(after, action, `${TOGGLE_PREFIX}${agentId}`);\n}\n\nconst RETRY_MS = 1800;\n\nconst SHARE_MS = 1400;\n\nconst SCRIPT: FleetStep[] = [\n  landing(1600, patch('price-reader', { costUsd: 0.083 })),\n  landing(\n    1400,\n    patch(TEST_RUNNER_ID, {\n      status: 'failed',\n      task: 'Run 7 of 20 timed out on the payment step',\n      costUsd: 0.118,\n    })\n  ),\n  landing(\n    1200,\n    patch(CODER.id, { task: 'Waits for the test runner', costUsd: 1.231 })\n  ),\n  fold(900, CODER.id, true),\n  demo(DECIDE_AFTER_MS, { type: 'retry', agentId: TEST_RUNNER_ID }, 'retry'),\n  landing(\n    1500,\n    patch(WRITER.id, {\n      status: 'done',\n      task: 'Release notes ready: 12 changes, 3 fixes',\n      costUsd: 0.214,\n    })\n  ),\n  { after: 300, action: { type: 'retried', agentId: TEST_RUNNER_ID } },\n  fold(1400, CODER.id, false),\n  landing(\n    900,\n    patch(CLAUSE_FINDER_ID, {\n      status: 'waiting',\n      task: 'Wants to share its summary with legal',\n      costUsd: 0.091,\n    }),\n    { type: 'approval.requested', approval: SHARE_APPROVAL }\n  ),\n  landing(\n    300,\n    patch(REVIEWER.id, {\n      status: 'waiting',\n      task: 'Waits on the clause finder',\n    })\n  ),\n  fold(900, REVIEWER.id, true),\n  demo(\n    DECIDE_AFTER_MS,\n    { type: 'approve', approvalId: SHARE_APPROVAL.id },\n    'approve'\n  ),\n  { after: SHARE_MS, action: { type: 'shared' } },\n  fold(1400, REVIEWER.id, false),\n  demo(1100, { type: 'view', view: 'cards' }),\n  landing(\n    1800,\n    patch('price-reader', {\n      status: 'done',\n      task: 'Read 6 product pages, 2 prices changed',\n      costUsd: 0.104,\n    })\n  ),\n  landing(\n    600,\n    patch(RESEARCHER.id, {\n      status: 'done',\n      task: 'Found 2 price changes on Larkfield Goods',\n      costUsd: 0.437,\n    })\n  ),\n  demo(2000, { type: 'view', view: 'rows' }),\n];\n\nconst SESSION = {\n  reducer,\n  initial: INITIAL,\n  resting: restingOf(INITIAL, SCRIPT, applyAfterLoading),\n  script: SCRIPT,\n  loopAfter: 3000,\n};\n\nfunction pressedToggleOf(pressed: string | null) {\n  const isToggle = pressed?.startsWith(TOGGLE_PREFIX) ?? false;\n  if (!pressed || !isToggle) {\n    return null;\n  }\n  return pressed.slice(TOGGLE_PREFIX.length);\n}\n\nfunction announcementOf(agent: RunAgent) {\n  const word = AGENT_STATUS_WORD[agent.status];\n  return `${agent.name}: ${word}. ${agent.task ?? ''}`;\n}\n\nexport default function Agent06() {\n  const { schedule, clearAll } = useTimeouts();\n  const {\n    ref,\n    isInView,\n    isAutoplaying,\n    state,\n    act,\n    pressed,\n    isFinished,\n    restart,\n  } = useSession(SESSION);\n  const agents = state.run.agents;\n  const message = useAgentAnnouncement(agents, announcementOf);\n  const canReplay = isFinished && !isAutoplaying;\n\n  function approve(approvalId: string) {\n    act({ type: 'approve', approvalId });\n    schedule(() => act({ type: 'shared' }), SHARE_MS);\n  }\n\n  function retry(agentId: string) {\n    act({ type: 'retry', agentId });\n    schedule(() => act({ type: 'retried', agentId }), RETRY_MS);\n  }\n\n  function changeView(view: FleetView) {\n    act({ type: 'view', view });\n  }\n\n  function changeOpen(agentId: string, isOpen: boolean) {\n    act({ type: 'open', agentId, isOpen });\n  }\n\n  function replay() {\n    clearAll();\n    restart();\n  }\n\n  useKeptHeight(ref);\n\n  return (\n    <div\n      ref={ref}\n      className='flex min-h-[48.5rem] w-full max-w-[44rem] flex-col gap-2'\n    >\n      <ClockGate isActive={isInView}>\n        <AgentFleet\n          agents={agents}\n          approvals={state.run.approvals}\n          earlierSpend={EARLIER_SPEND}\n          onApprove={approve}\n          onRetry={retry}\n          view={state.view}\n          onViewChange={changeView}\n          openIds={state.openIds}\n          onOpenChange={changeOpen}\n          pressedApproveId={pressedIdOf(pressed, 'approve', CLAUSE_FINDER_ID)}\n          pressedRetryId={pressedIdOf(pressed, 'retry', TEST_RUNNER_ID)}\n          pressedToggleId={pressedToggleOf(pressed)}\n        />\n      </ClockGate>\n      <div className='flex h-7 items-center justify-end'>\n        <ReplayButton isShown={canReplay} onReplay={replay} />\n      </div>\n      <LiveRegion message={spokenUnless(isAutoplaying, message)} />\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/agent/agent-06.tsx"
    },
    {
      "path": "registry/ndeko/components/agent/_parts/agent-actions.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport type { ApprovalRequest, RunAgent } from '@/registry/ndeko/lib/agent-run';\nimport {\n  pressedQuietOf,\n  pressedSolidOf,\n} from '@/registry/ndeko/lib/demonstration';\nimport { CheckIcon, RotateCcwIcon } from '@/registry/ndeko/lib/icons';\nimport { rowPresenceOf } from '@/registry/ndeko/lib/motion-presets';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Kbd } from '@/registry/ndeko/ui/kbd';\n\nexport function pendingApprovalOf(\n  approvals: ApprovalRequest[],\n  agentId: string\n) {\n  return approvals.find((approval) => {\n    const isForAgent = approval.agentId === agentId;\n    const isPending = approval.status === 'pending';\n    return isForAgent && isPending;\n  });\n}\n\nexport function approvedApprovalOf(\n  approvals: ApprovalRequest[],\n  agentId: string\n) {\n  return approvals.find((approval) => {\n    const isForAgent = approval.agentId === agentId;\n    const isApproved = approval.status === 'approved';\n    return isForAgent && isApproved;\n  });\n}\n\nfunction tabIndexOf(hasKeyHints: boolean) {\n  if (hasKeyHints) {\n    return -1;\n  }\n  return undefined;\n}\n\nconst KEY_HINT = 'ms-0.5 hidden group-focus-visible/row:inline-flex';\n\ntype AgentActionsProps = {\n  agent: RunAgent;\n  approvals: ApprovalRequest[];\n  onApprove?: (approvalId: string) => void;\n  onRetry?: (agentId: string) => void;\n  /**\n   * Inside a tree the row keeps the focus and A or R decide: the buttons leave the tab order and\n   * show their key while the row, marked `group/row`, has visible focus.\n   */\n  hasKeyHints?: boolean;\n  /** Called after Approve or Retry, once the pressed button is about to leave. */\n  onDecided?: (agentId: string) => void;\n  /** Shows Approve held down, for a demonstration that presses it. */\n  isApprovePressed?: boolean;\n  /** Shows Retry held down, for a demonstration that presses it. */\n  isRetryPressed?: boolean;\n};\n\nexport function AgentActions({\n  agent,\n  approvals,\n  onApprove,\n  onRetry,\n  hasKeyHints = false,\n  onDecided,\n  isApprovePressed = false,\n  isRetryPressed = false,\n}: AgentActionsProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const rowPresence = rowPresenceOf(shouldReduceMotion);\n  const pending = pendingApprovalOf(approvals, agent.id);\n  const approved = approvedApprovalOf(approvals, agent.id);\n  const isFailed = agent.status === 'failed';\n  const canRetry = isFailed && onRetry !== undefined;\n  const isNotPending = pending === undefined;\n  const showsTrace = approved !== undefined && isNotPending;\n  const buttonTabIndex = tabIndexOf(hasKeyHints);\n\n  function approve(event: React.MouseEvent) {\n    event.stopPropagation();\n    if (pending) {\n      onApprove?.(pending.id);\n      onDecided?.(agent.id);\n    }\n  }\n\n  function retry(event: React.MouseEvent) {\n    event.stopPropagation();\n    onRetry?.(agent.id);\n    onDecided?.(agent.id);\n  }\n\n  return (\n    <AnimatePresence initial={false}>\n      {pending && (\n        <motion.div key='approve' className='overflow-hidden' {...rowPresence}>\n          <div className='flex flex-wrap items-center gap-x-3 gap-y-1.5 pt-1.5'>\n            <p className='text-foreground/85 min-w-0 text-xs leading-5'>\n              {pending.title}\n            </p>\n            <Button\n              type='button'\n              size='sm'\n              tabIndex={buttonTabIndex}\n              onClick={approve}\n              aria-label={`Approve: ${pending.title}`}\n              className={pressedSolidOf(isApprovePressed)}\n            >\n              <CheckIcon />\n              Approve\n              {hasKeyHints && <Kbd className={KEY_HINT}>A</Kbd>}\n            </Button>\n          </div>\n        </motion.div>\n      )}\n      {canRetry && (\n        <motion.div key='retry' className='overflow-hidden' {...rowPresence}>\n          <div className='pt-1.5'>\n            <Button\n              type='button'\n              variant='outline'\n              size='sm'\n              tabIndex={buttonTabIndex}\n              onClick={retry}\n              aria-label={`Retry ${agent.name}`}\n              className={pressedQuietOf(isRetryPressed)}\n            >\n              <RotateCcwIcon />\n              Retry\n              {hasKeyHints && <Kbd className={KEY_HINT}>R</Kbd>}\n            </Button>\n          </div>\n        </motion.div>\n      )}\n      {showsTrace && (\n        <motion.p\n          key='approved'\n          className='text-muted-foreground overflow-hidden text-xs'\n          {...rowPresence}\n        >\n          <span className='flex items-center gap-1.5 pt-1'>\n            <CheckIcon className='text-success-foreground size-3.5 shrink-0' />\n            Approved by you\n          </span>\n        </motion.p>\n      )}\n    </AnimatePresence>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/agent/_parts/agent-actions.tsx"
    },
    {
      "path": "registry/ndeko/components/agent/_parts/agent-clock.tsx",
      "content": "'use client';\n\nimport type { RunAgent } from '@/registry/ndeko/lib/agent-run';\nimport { LiveDuration } from '@/registry/ndeko/ui/live-duration';\n\nexport function isLiveAgent(agent: RunAgent) {\n  const isRunning = agent.status === 'running';\n  const isWaiting = agent.status === 'waiting';\n  return isRunning || isWaiting;\n}\n\n/** A duration that ticks keeps its width, so nothing beside it shifts ten times a second. */\nexport function AgentClock({ agent }: { agent: RunAgent }) {\n  const hasStarted = agent.startedAt !== undefined;\n  if (!hasStarted) {\n    return <span>Not started</span>;\n  }\n  return (\n    <LiveDuration\n      item={agent}\n      isRunning={isLiveAgent(agent)}\n      className='inline-block min-w-8'\n    />\n  );\n}\n",
      "type": "registry:component",
      "target": "components/agent/_parts/agent-clock.tsx"
    },
    {
      "path": "registry/ndeko/components/agent/_parts/agent-status.tsx",
      "content": "'use client';\n\nimport { WordRoll } from '@/components/core/word-roll';\nimport type {\n  AgentStatus as AgentState,\n  RunAgent,\n} from '@/registry/ndeko/lib/agent-run';\nimport {\n  CircleCheckIcon,\n  CircleXIcon,\n  HandIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\n\nexport const AGENT_STATUS_WORD: Record<AgentState, string> = {\n  idle: 'Idle',\n  running: 'Running',\n  waiting: 'Waiting on you',\n  failed: 'Failed',\n  done: 'Done',\n};\n\nexport const AGENT_STATES: AgentState[] = [\n  'idle',\n  'running',\n  'waiting',\n  'failed',\n  'done',\n];\n\nconst STATUS_WORDS = AGENT_STATES.map((state) => AGENT_STATUS_WORD[state]);\n\nconst DOT_TONE: Record<AgentState, string> = {\n  idle: 'bg-muted-foreground/45',\n  running: 'bg-info',\n  waiting: 'bg-warning',\n  failed: 'bg-destructive',\n  done: 'bg-success',\n};\n\nconst LABEL_TONE: Record<AgentState, string> = {\n  idle: 'text-muted-foreground',\n  running: 'text-foreground',\n  waiting: 'text-warning-foreground',\n  failed: 'text-destructive-ink',\n  done: 'text-muted-foreground',\n};\n\nconst DOT_SIZE = {\n  sm: 'size-1.5',\n  md: 'size-2',\n  lg: 'size-2.5',\n} as const;\n\nconst MARK_SIZE = {\n  sm: 'size-3',\n  md: 'size-3.5',\n  lg: 'size-4',\n} as const;\n\nexport type AgentStatusSize = keyof typeof DOT_SIZE;\n\nconst RING_TIMING: React.CSSProperties = { animationDuration: '2s' };\n\n/** A piece lets this many dots pulse at once. Past it, a running agent is told by its colour and its word. */\nexport const MAX_PULSING = 3;\n\n/** The running agents whose dot may pulse: the first ones, in the order given. */\nexport function pulsingIdsOf(\n  agents: Pick<RunAgent, 'id' | 'status'>[],\n  limit = MAX_PULSING\n) {\n  const running = agents.filter((agent) => agent.status === 'running');\n  const pulsing = running.slice(0, limit);\n  const ids = pulsing.map((agent) => agent.id);\n  return new Set(ids);\n}\n\nfunction reservedLabelsOf(shouldReserve: boolean) {\n  if (shouldReserve) {\n    return STATUS_WORDS;\n  }\n  return undefined;\n}\n\ntype AgentStatusDotProps = {\n  status: AgentState;\n  size?: AgentStatusSize;\n  /** Without a visible word next to it, the dot says its state to screen readers. */\n  isLabelled?: boolean;\n  /** Holds a running dot still: where three others already pulse, or where nothing is really running. */\n  isStill?: boolean;\n  className?: string;\n};\n\n/**\n * A running dot sends a soft ring out: one CSS keyframe on transform and opacity, which the theme\n * stops under reduced motion. Every other state holds still and is told by its colour.\n */\nexport function AgentStatusDot({\n  status,\n  size = 'md',\n  isLabelled = false,\n  isStill = false,\n  className,\n}: AgentStatusDotProps) {\n  const isRunning = status === 'running';\n  const isPulsing = isRunning && !isStill;\n  const word = AGENT_STATUS_WORD[status];\n\n  return (\n    <span\n      data-status={status}\n      className={cn('relative inline-flex shrink-0', DOT_SIZE[size], className)}\n    >\n      {isPulsing && (\n        <span\n          aria-hidden='true'\n          style={RING_TIMING}\n          className='bg-info/40 absolute inset-0 animate-ping rounded-full motion-reduce:hidden'\n        />\n      )}\n      <span\n        aria-hidden='true'\n        className={cn(\n          'relative size-full rounded-full transition-colors duration-200',\n          DOT_TONE[status]\n        )}\n      />\n      {isLabelled && <span className='sr-only'>{word}</span>}\n    </span>\n  );\n}\n\ntype StatusGlyphProps = {\n  status: AgentState;\n  size: AgentStatusSize;\n  isStill: boolean;\n};\n\nfunction StatusGlyph({ status, size, isStill }: StatusGlyphProps) {\n  const box = MARK_SIZE[size];\n  if (status === 'waiting') {\n    return <HandIcon className={cn('text-warning-foreground', box)} />;\n  }\n  if (status === 'failed') {\n    return <CircleXIcon className={cn('text-destructive-ink', box)} />;\n  }\n  if (status === 'done') {\n    return <CircleCheckIcon className={cn('text-success-foreground', box)} />;\n  }\n  return (\n    <span className={cn('flex items-center justify-center', box)}>\n      <AgentStatusDot status={status} size={size} isStill={isStill} />\n    </span>\n  );\n}\n\ntype AgentStatusMarkProps = {\n  status: AgentState;\n  size?: AgentStatusSize;\n  isStill?: boolean;\n  className?: string;\n};\n\n/**\n * The mark of a state, drawn so it reads without its colour: a dot while the agent is idle or runs,\n * a hand while it waits, a cross when it failed, a check when it ended. It swaps when the state changes.\n */\nexport function AgentStatusMark({\n  status,\n  size = 'md',\n  isStill = false,\n  className,\n}: AgentStatusMarkProps) {\n  const box = MARK_SIZE[size];\n\n  return (\n    <span\n      data-status={status}\n      aria-hidden='true'\n      className={cn('inline-flex shrink-0', box, className)}\n    >\n      <Swap swapKey={status} className={box}>\n        <StatusGlyph status={status} size={size} isStill={isStill} />\n      </Swap>\n    </span>\n  );\n}\n\nexport type AgentStatusProps = {\n  status: AgentState;\n  /** Leave the word out where space is short: a dot then carries it for screen readers. */\n  showLabel?: boolean;\n  /** Keeps the width of the longest word, so the row beside it never shifts. */\n  reserveWidth?: boolean;\n  size?: AgentStatusSize;\n  /** Holds a running mark still: a piece lets three pulse at most. */\n  isStill?: boolean;\n  className?: string;\n};\n\nexport function AgentStatus({\n  status,\n  showLabel = true,\n  reserveWidth = false,\n  size = 'md',\n  isStill = false,\n  className,\n}: AgentStatusProps) {\n  const word = AGENT_STATUS_WORD[status];\n  const labels = reservedLabelsOf(reserveWidth);\n\n  if (!showLabel) {\n    return (\n      <AgentStatusDot\n        status={status}\n        size={size}\n        isLabelled\n        isStill={isStill}\n        className={className}\n      />\n    );\n  }\n\n  return (\n    <span\n      className={cn(\n        'inline-flex items-center gap-1 text-xs transition-colors duration-200',\n        LABEL_TONE[status],\n        className\n      )}\n    >\n      <AgentStatusMark status={status} size={size} isStill={isStill} />\n      <WordRoll text={word} labels={labels} />\n    </span>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/agent/_parts/agent-status.tsx"
    },
    {
      "path": "registry/ndeko/components/agent/_parts/agent-tile.tsx",
      "content": "import { seriesColorOf, type SeriesSlot } from '@/registry/ndeko/lib/agent-run';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { MeshTile } from '@/registry/ndeko/ui/mesh-tile';\n\nconst SIZE_CLASS = {\n  sm: 'size-5 rounded-[5px]',\n  md: 'size-6 rounded-md',\n  lg: 'size-8 rounded-lg',\n} as const;\n\nexport type AgentTileSize = keyof typeof SIZE_CLASS;\n\ntype AgentTileProps = {\n  name: string;\n  series: SeriesSlot;\n  size?: AgentTileSize;\n  className?: string;\n};\n\n/** The picture of an agent: a gradient drawn from its name, in its series colour. Its name always sits beside it. */\nexport function AgentTile({\n  name,\n  series,\n  size = 'md',\n  className,\n}: AgentTileProps) {\n  const color = seriesColorOf(series);\n  const sizeClass = SIZE_CLASS[size];\n\n  return (\n    <MeshTile seed={name} color={color} className={cn(sizeClass, className)} />\n  );\n}\n",
      "type": "registry:component",
      "target": "components/agent/_parts/agent-tile.tsx"
    },
    {
      "path": "registry/ndeko/components/agent/_parts/cost-figure.tsx",
      "content": "'use client';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nconst SMALL_COST: Intl.NumberFormatOptions = {\n  style: 'currency',\n  currency: 'USD',\n  minimumFractionDigits: 3,\n  maximumFractionDigits: 3,\n};\n\nconst LARGE_COST: Intl.NumberFormatOptions = {\n  style: 'currency',\n  currency: 'USD',\n  minimumFractionDigits: 2,\n  maximumFractionDigits: 2,\n};\n\n/** Matches `formatCost`: three decimals under a dollar, two above. */\nexport function costFormatOf(usd: number) {\n  if (usd < 1) {\n    return SMALL_COST;\n  }\n  return LARGE_COST;\n}\n\ntype CostFigureProps = {\n  usd: number;\n  className?: string;\n};\n\nexport function CostFigure({ usd, className }: CostFigureProps) {\n  const format = costFormatOf(usd);\n\n  return (\n    <MotionNumber\n      value={usd}\n      format={format}\n      className={cn('tabular-nums', className)}\n    />\n  );\n}\n",
      "type": "registry:component",
      "target": "components/agent/_parts/cost-figure.tsx"
    },
    {
      "path": "registry/ndeko/components/agent/_parts/crew.ts",
      "content": "import type { RunAgent } from '@/registry/ndeko/lib/agent-run';\n\nexport const RUN_TITLE = 'Q3 vendor review for Brightmoor Supply';\n\nexport const PLANNER: RunAgent = {\n  id: 'planner',\n  name: 'Planner',\n  series: 1,\n  status: 'idle',\n  role: 'Lead',\n  model: 'Claude Opus',\n};\n\nexport const RESEARCHER: RunAgent = {\n  id: 'researcher',\n  name: 'Researcher',\n  series: 2,\n  status: 'idle',\n  model: 'Claude Sonnet',\n  parentId: 'planner',\n};\n\nexport const WRITER: RunAgent = {\n  id: 'writer',\n  name: 'Writer',\n  series: 3,\n  status: 'idle',\n  model: 'Claude Haiku',\n  parentId: 'planner',\n};\n\nexport const REVIEWER: RunAgent = {\n  id: 'reviewer',\n  name: 'Reviewer',\n  series: 4,\n  status: 'idle',\n  model: 'Claude Sonnet',\n  parentId: 'planner',\n};\n\nexport const CODER: RunAgent = {\n  id: 'coder',\n  name: 'Coder',\n  series: 5,\n  status: 'idle',\n  model: 'Claude Opus',\n  parentId: 'planner',\n};\n\nexport const CREW: RunAgent[] = [PLANNER, RESEARCHER, WRITER, REVIEWER, CODER];\n\nexport const PAGE_ERROR = 'The pricing page refused the reader (403)';\n",
      "type": "registry:component",
      "target": "components/agent/_parts/crew.ts"
    },
    {
      "path": "registry/ndeko/components/agent/_parts/demo.ts",
      "content": "/** A control that waits on a person is pressed by the demonstration after this long. */\nexport const DECIDE_AFTER_MS = 2500;\n\n/** The row a demonstration presses, when the control it holds down is the one named by `key`. */\nexport function pressedIdOf(pressed: string | null, key: string, id: string) {\n  if (pressed === key) {\n    return id;\n  }\n  return null;\n}\n",
      "type": "registry:component",
      "target": "components/agent/_parts/demo.ts"
    },
    {
      "path": "registry/ndeko/components/agent/_parts/focus-later.ts",
      "content": "/** Moves focus once React has committed the change that moved, replaced or removed the focused control. */\nexport function focusLater(\n  root: React.RefObject<HTMLElement | null>,\n  selector: string\n) {\n  requestAnimationFrame(() => {\n    const target = root.current?.querySelector<HTMLElement>(selector);\n    target?.focus();\n  });\n}\n",
      "type": "registry:component",
      "target": "components/agent/_parts/focus-later.ts"
    },
    {
      "path": "registry/ndeko/components/agent/_parts/keyed-height.tsx",
      "content": "'use client';\n\nimport { useLayoutEffect, useRef } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nconst TRAVEL: KeyframeAnimationOptions = {\n  duration: 300,\n  easing: 'cubic-bezier(0.23, 1, 0.32, 1)',\n};\n\ntype KeyedHeightProps = {\n  /** The frame travels to its new height when this changes, and only then. */\n  changeKey: string;\n  className?: string;\n  children: React.ReactNode;\n};\n\n/**\n * A frame that changes height with a movement only when its key changes: a fold, another view. Any\n * other change of its content (a row that arrives, a panel that opens) is followed at once, since\n * that content already moves by itself and a frame chasing it would animate the same change twice.\n * The padding leaves room for focus rings and the margin takes it back.\n */\nexport function KeyedHeight({\n  changeKey,\n  className,\n  children,\n}: KeyedHeightProps) {\n  const frameRef = useRef<HTMLDivElement>(null);\n  const knownHeight = useRef<number | null>(null);\n  const shouldReduceMotion = usePrefersReducedMotion();\n\n  useLayoutEffect(() => {\n    const frame = frameRef.current;\n    if (!frame) {\n      return;\n    }\n    const observer = new ResizeObserver(() => {\n      knownHeight.current = frame.offsetHeight;\n    });\n    observer.observe(frame);\n    return () => observer.disconnect();\n  }, []);\n\n  useLayoutEffect(() => {\n    const frame = frameRef.current;\n    const from = knownHeight.current;\n    if (!frame || from === null) {\n      return;\n    }\n    if (shouldReduceMotion) {\n      return;\n    }\n    const to = frame.offsetHeight;\n    if (from === to) {\n      return;\n    }\n    const keyframes = [{ height: `${from}px` }, { height: `${to}px` }];\n    const travel = frame.animate(keyframes, TRAVEL);\n    return () => travel.cancel();\n  }, [changeKey, shouldReduceMotion]);\n\n  return (\n    <div\n      ref={frameRef}\n      data-slot='keyed-height'\n      className={cn('-m-1 overflow-hidden', className)}\n    >\n      <div className='p-1'>{children}</div>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/agent/_parts/keyed-height.tsx"
    },
    {
      "path": "registry/ndeko/components/agent/_parts/use-agent-announcement.ts",
      "content": "'use client';\n\nimport { useState } from 'react';\n\nimport type { RunAgent } from '@/registry/ndeko/lib/agent-run';\n\nfunction changedAgentOf(previous: RunAgent[], next: RunAgent[]) {\n  return next.find((agent) => {\n    const before = previous.find((candidate) => candidate.id === agent.id);\n    if (!before) {\n      return true;\n    }\n    return before.status !== agent.status;\n  });\n}\n\nexport function useAgentAnnouncement(\n  agents: RunAgent[],\n  describe: (agent: RunAgent) => string\n) {\n  const [seenAgents, setSeenAgents] = useState(agents);\n  const [message, setMessage] = useState('');\n\n  const hasNewAgents = seenAgents !== agents;\n  if (hasNewAgents) {\n    const changed = changedAgentOf(seenAgents, agents);\n    setSeenAgents(agents);\n    if (changed) {\n      setMessage(describe(changed));\n    }\n  }\n\n  return message;\n}\n",
      "type": "registry:component",
      "target": "components/agent/_parts/use-agent-announcement.ts"
    }
  ],
  "categories": [
    "components",
    "agent"
  ],
  "type": "registry:component"
}