{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "agent-ops-08",
  "title": "Agent board",
  "description": "A run as three lanes: when an agent hands in its work the card travels to Needs review, Approve sends it on to Done, Request changes sends it back with a note, and cards also move by drag or from their menu.",
  "dependencies": [
    "@dnd-kit/core",
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/agent-run.json",
    "https://ui.ndekocode.dev/r/badge.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/dropdown-menu.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/input.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/replay-button.json",
    "https://ui.ndekocode.dev/r/theme.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"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/agent-ops/agent-ops-08/index.tsx",
      "content": "'use client';\n\nimport {\n  DndContext,\n  DragOverlay,\n  MouseSensor,\n  TouchSensor,\n  pointerWithin,\n  useSensor,\n  useSensors,\n  type DragEndEvent,\n  type DragStartEvent,\n} from '@dnd-kit/core';\nimport { LayoutGroup } from 'motion/react';\nimport { useId, useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { useSession } from '@/registry/ndeko/hooks/use-session';\nimport { useTimeouts } from '@/registry/ndeko/hooks/use-timeouts';\nimport { formatCost } from '@/registry/ndeko/lib/agent-run';\nimport { spokenUnless } from '@/registry/ndeko/lib/demonstration';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { ClockGate } from '@/registry/ndeko/ui/live-duration';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { ReplayButton } from '@/registry/ndeko/ui/replay-button';\n\nimport { laneLabelOf, LANES, RUN_TITLE, type LaneId } from './data';\nimport { BoardLane } from './lane';\nimport {\n  INITIAL,\n  LOOP_AFTER_MS,\n  placementOf,\n  reducer,\n  RESTING,\n  REWORK_MS,\n  REWORK_USD,\n  SCRIPT,\n  tasksIn,\n  type BoardState,\n  type LastMove,\n} from './session';\nimport { CARD_SURFACE, TaskCardBody } from './task-card';\n\nconst SESSION = {\n  reducer,\n  initial: INITIAL,\n  resting: RESTING,\n  script: SCRIPT,\n  loopAfter: LOOP_AFTER_MS,\n};\n\nconst MOUSE = { activationConstraint: { distance: 4 } };\n\nconst TOUCH = { activationConstraint: { delay: 180, tolerance: 6 } };\n\nfunction totalCostOf(state: BoardState) {\n  let total = 0;\n  for (const task of state.tasks) {\n    total += task.costUsd;\n  }\n  return total;\n}\n\nfunction tasksWordOf(count: number) {\n  if (count === 1) {\n    return '1 task';\n  }\n  return `${count} tasks`;\n}\n\nfunction moveLineOf(lastMove: LastMove | null) {\n  if (!lastMove) {\n    return '';\n  }\n  return `${lastMove.title} moved to ${laneLabelOf(lastMove.lane)}`;\n}\n\nfunction laneIdOf(value: unknown) {\n  const lane = LANES.find((candidate) => candidate.id === value);\n  return lane?.id ?? null;\n}\n\n/** The drop glides the card to its new place; reduced motion puts it there at once. */\nfunction dropAnimationOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return null;\n  }\n  return undefined;\n}\n\nexport default function AgentOps08() {\n  const {\n    ref,\n    isInView,\n    isAutoplaying,\n    state,\n    act,\n    pressed,\n    isFinished,\n    restart,\n  } = useSession(SESSION);\n  const { schedule } = useTimeouts();\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const groupId = useId();\n  const dndId = useId();\n  const [draggedId, setDraggedId] = useState<string | null>(null);\n  const sensors = useSensors(\n    useSensor(MouseSensor, MOUSE),\n    useSensor(TouchSensor, TOUCH)\n  );\n  const placement = placementOf(state);\n  const draggedTask = state.tasks.find((task) => task.id === draggedId);\n  const totalCost = formatCost(totalCostOf(state));\n  const meta = `${tasksWordOf(state.tasks.length)} · ${totalCost} so far`;\n  const moveLine = moveLineOf(state.lastMove);\n  const message = spokenUnless(isAutoplaying, moveLine);\n  const canReplay = isFinished && !isAutoplaying;\n\n  function focusLater(selector: string) {\n    requestAnimationFrame(() => {\n      const target = ref.current?.querySelector<HTMLElement>(selector);\n      target?.focus();\n    });\n  }\n\n  /** An agent takes a task that came back to Running, reworks it and asks again. */\n  function reworkIfRunning(id: string, lane: LaneId) {\n    if (lane !== 'running') {\n      return;\n    }\n    const resubmit = () => act({ type: 'submitted', id, usd: REWORK_USD });\n    schedule(resubmit, REWORK_MS);\n  }\n\n  function sendBack(id: string, note: string) {\n    act({ type: 'sentBack', id, note });\n    reworkIfRunning(id, 'running');\n  }\n\n  function move(id: string, to: LaneId) {\n    act({ type: 'moved', id, to });\n    reworkIfRunning(id, to);\n    focusLater(`[data-card-menu=\"${id}\"]`);\n  }\n\n  function startDrag({ active }: DragStartEvent) {\n    setDraggedId(String(active.id));\n  }\n\n  function endDrag({ active, over }: DragEndEvent) {\n    setDraggedId(null);\n    const to = laneIdOf(over?.id);\n    if (!to) {\n      return;\n    }\n    const id = String(active.id);\n    act({ type: 'dropped', id, to });\n    reworkIfRunning(id, to);\n  }\n\n  function cancelDrag() {\n    setDraggedId(null);\n  }\n\n  return (\n    <ClockGate isActive={isInView}>\n      <div\n        ref={ref}\n        className='bg-background text-foreground @container min-h-dvh w-full'\n      >\n        <div className='mx-auto flex max-w-5xl flex-col gap-4 p-4 @3xl:gap-5 @3xl:p-8'>\n          <header className='flex flex-wrap items-center gap-x-3 gap-y-2'>\n            <div className='flex min-w-0 flex-1 flex-col gap-0.5'>\n              <h1 className='text-lg font-semibold text-balance'>\n                {RUN_TITLE}\n              </h1>\n              <p className='text-muted-foreground flex flex-wrap items-center gap-x-2 gap-y-1 text-xs tabular-nums'>\n                {meta}\n                <Badge variant='secondary'>Illustrative</Badge>\n              </p>\n            </div>\n            <ReplayButton\n              isShown={canReplay}\n              onReplay={restart}\n              label='Replay the run'\n            />\n          </header>\n\n          <DndContext\n            id={dndId}\n            sensors={sensors}\n            collisionDetection={pointerWithin}\n            onDragStart={startDrag}\n            onDragEnd={endDrag}\n            onDragCancel={cancelDrag}\n          >\n            <LayoutGroup id={groupId}>\n              <div className='grid grid-cols-1 gap-6 @3xl:min-h-[30rem] @3xl:grid-cols-3 @3xl:gap-3'>\n                {LANES.map((lane) => (\n                  <BoardLane\n                    key={lane.id}\n                    lane={lane}\n                    tasks={tasksIn(state, lane.id)}\n                    placement={placement}\n                    pressed={pressed}\n                    onApprove={(id) => act({ type: 'approved', id })}\n                    onSendBack={sendBack}\n                    onMove={move}\n                  />\n                ))}\n              </div>\n            </LayoutGroup>\n            <DragOverlay dropAnimation={dropAnimationOf(shouldReduceMotion)}>\n              {draggedTask && (\n                <div className={cn(CARD_SURFACE, 'cursor-grabbing')}>\n                  <TaskCardBody task={draggedTask} isOverlay />\n                </div>\n              )}\n            </DragOverlay>\n          </DndContext>\n        </div>\n        <LiveRegion message={message} />\n      </div>\n    </ClockGate>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/agent-ops-08/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/agent-ops/agent-ops-08/lane.tsx",
      "content": "'use client';\n\nimport { useDraggable, useDroppable } from '@dnd-kit/core';\nimport { LayoutGroup, motion, type Transition } from 'motion/react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { springOf } from '@/registry/ndeko/lib/motion-presets';\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nimport type { Lane, LaneId } from './data';\nimport type { Task } from './session';\nimport { cardClassOf, TaskCardBody } from './task-card';\n\nconst LANE_DOT: Record<LaneId, string> = {\n  running: 'bg-info',\n  review: 'bg-warning',\n  done: 'bg-success',\n};\n\nfunction tasksWordOf(count: number) {\n  if (count === 1) {\n    return 'task';\n  }\n  return 'tasks';\n}\n\n/** The ring shows the target at every width; the tray only exists side by side. */\nfunction laneToneOf(isTarget: boolean) {\n  if (isTarget) {\n    return 'ring-primary/25 ring-2 @3xl:bg-primary/[0.06]';\n  }\n  return 'ring-0 ring-transparent @3xl:bg-foreground/[0.03]';\n}\n\nfunction slotToneOf(isTarget: boolean) {\n  if (isTarget) {\n    return 'border-primary/40';\n  }\n  return 'border-foreground/20';\n}\n\ntype DraggableCardProps = {\n  task: Task;\n  placement: string;\n  travel: Transition;\n  pressed: string | null;\n  onApprove: (id: string) => void;\n  onSendBack: (id: string, note: string) => void;\n  onMove: (id: string, to: LaneId) => void;\n};\n\n/**\n * A card that changes lane keeps its layout id, so it travels to its new place. A card a person\n * dropped takes a new one: it is already where it was let go.\n */\nfunction DraggableCard({\n  task,\n  placement,\n  travel,\n  pressed,\n  onApprove,\n  onSendBack,\n  onMove,\n}: DraggableCardProps) {\n  const { setNodeRef, listeners, isDragging } = useDraggable({ id: task.id });\n\n  return (\n    <motion.li\n      layout='position'\n      layoutId={`${task.id}:${task.drops}`}\n      layoutDependency={placement}\n      transition={{ layout: travel }}\n      className='relative'\n    >\n      <div\n        ref={setNodeRef}\n        {...listeners}\n        className={cn(\n          'cursor-grab touch-manipulation select-none active:cursor-grabbing',\n          cardClassOf(isDragging)\n        )}\n      >\n        <TaskCardBody\n          task={task}\n          pressed={pressed}\n          onApprove={onApprove}\n          onSendBack={onSendBack}\n          onMove={onMove}\n        />\n      </div>\n    </motion.li>\n  );\n}\n\nexport type BoardLaneProps = {\n  lane: Lane;\n  tasks: Task[];\n  /** Where every task sits: the cards and the lane header measure again when it changes. */\n  placement: string;\n  pressed: string | null;\n  onApprove: (id: string) => void;\n  onSendBack: (id: string, note: string) => void;\n  onMove: (id: string, to: LaneId) => void;\n};\n\n/** A lane takes a drop anywhere, even when it is empty. On a phone the lanes stack and lose their tray. */\nexport function BoardLane({\n  lane,\n  tasks,\n  placement,\n  pressed,\n  onApprove,\n  onSendBack,\n  onMove,\n}: BoardLaneProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const travel = springOf(shouldReduceMotion);\n  const { setNodeRef, isOver } = useDroppable({ id: lane.id });\n  const count = tasks.length;\n  const isEmpty = count === 0;\n\n  return (\n    <section\n      ref={setNodeRef}\n      aria-label={lane.label}\n      className={cn(\n        'flex flex-col gap-2 rounded-xl transition-[background-color,box-shadow] duration-150 @3xl:p-2',\n        laneToneOf(isOver)\n      )}\n    >\n      <motion.header\n        layout='position'\n        layoutDependency={placement}\n        transition={{ layout: travel }}\n        className='flex h-8 items-center gap-2 @3xl:px-1'\n      >\n        <span\n          aria-hidden='true'\n          className={cn('size-2 shrink-0 rounded-full', LANE_DOT[lane.id])}\n        />\n        <h2 className='text-[13px] font-medium'>{lane.label}</h2>\n        <LayoutGroup inherit={false}>\n          <span className='bg-foreground/[0.06] text-muted-foreground inline-flex h-5 min-w-5 items-center justify-center rounded-sm px-1.5 text-xs'>\n            <MotionNumber value={count} />\n            <span className='sr-only'> {tasksWordOf(count)}</span>\n          </span>\n        </LayoutGroup>\n      </motion.header>\n      <ul className='flex flex-col gap-2'>\n        {tasks.map((task) => (\n          <DraggableCard\n            key={task.id}\n            task={task}\n            placement={placement}\n            travel={travel}\n            pressed={pressed}\n            onApprove={onApprove}\n            onSendBack={onSendBack}\n            onMove={onMove}\n          />\n        ))}\n      </ul>\n      {isEmpty && (\n        <p\n          className={cn(\n            'hairline-border text-muted-foreground flex min-h-16 items-center justify-center rounded-lg border-dashed px-3 py-2 text-center text-xs transition-colors duration-150',\n            slotToneOf(isOver)\n          )}\n        >\n          {lane.emptyLine}\n        </p>\n      )}\n    </section>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/agent-ops-08/lane.tsx"
    },
    {
      "path": "registry/ndeko/blocks/agent-ops/agent-ops-08/task-card.tsx",
      "content": "'use client';\n\nimport { useId, useRef, useState } from 'react';\n\nimport { formatCost, seriesColorOf } from '@/registry/ndeko/lib/agent-run';\nimport { pressedSolidOf } from '@/registry/ndeko/lib/demonstration';\nimport { CheckIcon, EllipsisIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Fold } from '@/registry/ndeko/ui/chat-motion';\nimport {\n  DropdownMenu,\n  DropdownMenuContent,\n  DropdownMenuItem,\n  DropdownMenuTrigger,\n} from '@/registry/ndeko/ui/dropdown-menu';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport { LiveDuration } from '@/registry/ndeko/ui/live-duration';\nimport { MeshTile } from '@/registry/ndeko/ui/mesh-tile';\n\nimport { AGENTS, LANES, type AgentId, type LaneId } from './data';\nimport type { Task } from './session';\n\nexport const CARD_SURFACE =\n  'bg-card hairline-ring ring-border rounded-lg shadow-[0_1px_2px_rgb(0_0_0/0.04)] dark:bg-foreground/[0.04]';\n\nfunction sentBackLineOf(note: string | undefined) {\n  const hasText = note !== undefined && note !== '';\n  if (hasText) {\n    return `Sent back by you: ${note}`;\n  }\n  return 'Sent back by you';\n}\n\nfunction AgentChip({ agentId }: { agentId: AgentId }) {\n  const agent = AGENTS[agentId];\n  const color = seriesColorOf(agent.series);\n\n  return (\n    <span className='flex min-w-0 items-center gap-1.5 text-xs font-medium'>\n      <MeshTile seed={agent.name} color={color} />\n      <span className='truncate'>{agent.name}</span>\n    </span>\n  );\n}\n\ntype ApprovalProps = {\n  task: Task;\n  isApprovePressed: boolean;\n  onApprove: (id: string) => void;\n  onSendBack: (id: string, note: string) => void;\n};\n\nfunction Approval({\n  task,\n  isApprovePressed,\n  onApprove,\n  onSendBack,\n}: ApprovalProps) {\n  const noteId = useId();\n  const noteRef = useRef<HTMLInputElement>(null);\n  const [isAsking, setIsAsking] = useState(false);\n  const [note, setNote] = useState('');\n\n  /** The buttons leave when the field unfolds, so the focus goes to the field. */\n  function ask() {\n    setIsAsking(true);\n    requestAnimationFrame(() => noteRef.current?.focus());\n  }\n\n  function sendBack(event: React.FormEvent<HTMLFormElement>) {\n    event.preventDefault();\n    onSendBack(task.id, note.trim());\n  }\n\n  return (\n    <div className='bg-warning/10 flex flex-col gap-2 rounded-md p-2.5 transition-opacity duration-300 starting:opacity-0'>\n      <p className='text-xs leading-5'>{task.request}</p>\n      {!isAsking && (\n        <div className='flex flex-wrap items-center gap-2'>\n          <Button\n            type='button'\n            size='sm'\n            onClick={() => onApprove(task.id)}\n            className={pressedSolidOf(isApprovePressed)}\n          >\n            Approve\n          </Button>\n          <Button type='button' size='sm' variant='outline' onClick={ask}>\n            Request changes\n          </Button>\n        </div>\n      )}\n      <Fold open={isAsking}>\n        <form onSubmit={sendBack} className='flex flex-col gap-2'>\n          <label htmlFor={noteId} className='sr-only'>\n            What should change\n          </label>\n          <Input\n            id={noteId}\n            ref={noteRef}\n            size='sm'\n            autoComplete='off'\n            placeholder='What should change?'\n            value={note}\n            onChange={(event) => setNote(event.target.value)}\n          />\n          <div className='flex items-center gap-2'>\n            <Button type='submit' size='sm'>\n              Send back\n            </Button>\n            <Button\n              type='button'\n              size='sm'\n              variant='ghost'\n              onClick={() => setIsAsking(false)}\n            >\n              Cancel\n            </Button>\n          </div>\n        </form>\n      </Fold>\n    </div>\n  );\n}\n\nexport type TaskCardBodyProps = {\n  task: Task;\n  pressed?: string | null;\n  /** The copy under the pointer shows the task and nothing to press. */\n  isOverlay?: boolean;\n  onApprove?: (id: string) => void;\n  onSendBack?: (id: string, note: string) => void;\n  onMove?: (id: string, to: LaneId) => void;\n};\n\nfunction noop() {}\n\nexport function TaskCardBody({\n  task,\n  pressed = null,\n  isOverlay = false,\n  onApprove = noop,\n  onSendBack = noop,\n  onMove = noop,\n}: TaskCardBodyProps) {\n  const isRunning = task.lane === 'running';\n  const isInReview = task.lane === 'review';\n  const isDone = task.lane === 'done';\n  const showsApproval = isInReview && !isOverlay;\n  const showsApproved = isDone && task.wasApproved;\n  const hasNote = task.note !== undefined;\n  const otherLanes = LANES.filter((lane) => lane.id !== task.lane);\n\n  return (\n    <div className='flex flex-col gap-2 p-2.5'>\n      <div className='flex items-center gap-2'>\n        <AgentChip agentId={task.agentId} />\n        {!isOverlay && (\n          <DropdownMenu>\n            <DropdownMenuTrigger\n              render={\n                <Button\n                  type='button'\n                  variant='ghost'\n                  size='icon-sm'\n                  data-card-menu={task.id}\n                  aria-label={`Move ${task.title}`}\n                  className='text-muted-foreground -my-1 ms-auto -me-1 size-6'\n                />\n              }\n            >\n              <EllipsisIcon />\n            </DropdownMenuTrigger>\n            <DropdownMenuContent align='end' className='min-w-44'>\n              {otherLanes.map((lane) => (\n                <DropdownMenuItem\n                  key={lane.id}\n                  onClick={() => onMove(task.id, lane.id)}\n                >\n                  Move to {lane.label}\n                </DropdownMenuItem>\n              ))}\n            </DropdownMenuContent>\n          </DropdownMenu>\n        )}\n      </div>\n      <p className='text-[13px] leading-5 font-medium text-pretty'>\n        {task.title}\n      </p>\n      {hasNote && (\n        <p className='text-muted-foreground text-xs leading-5'>\n          {sentBackLineOf(task.note)}\n        </p>\n      )}\n      <p className='text-muted-foreground flex items-center gap-2 text-xs'>\n        <LiveDuration item={task} isRunning={isRunning} />\n        <span aria-hidden='true'>·</span>\n        <span className='tabular-nums'>{formatCost(task.costUsd)}</span>\n        {showsApproved && (\n          <span className='ms-auto flex items-center gap-1'>\n            <CheckIcon className='text-success-foreground size-3.5' />\n            Approved by you\n          </span>\n        )}\n      </p>\n      {showsApproval && (\n        <Approval\n          task={task}\n          isApprovePressed={pressed === `approve-${task.id}`}\n          onApprove={onApprove}\n          onSendBack={onSendBack}\n        />\n      )}\n    </div>\n  );\n}\n\nexport function cardClassOf(isDragging: boolean) {\n  return cn(CARD_SURFACE, isDragging && 'opacity-40');\n}\n",
      "type": "registry:component",
      "target": "components/blocks/agent-ops-08/task-card.tsx"
    },
    {
      "path": "registry/ndeko/blocks/agent-ops/agent-ops-08/session.ts",
      "content": "import type { SessionStep } from '@/registry/ndeko/hooks/use-session';\n\nimport { TASKS, type AgentId, type LaneId, type TaskSeed } from './data';\n\nexport type Task = {\n  id: string;\n  agentId: AgentId;\n  title: string;\n  lane: LaneId;\n  costUsd: number;\n  startedAt: number;\n  endedAt?: number;\n  request: string;\n  /** What a person asked for when they sent the task back. */\n  note?: string;\n  wasApproved: boolean;\n  /** Counts the drops: a dropped card lands where it was let go, it does not travel from its lane. */\n  drops: number;\n};\n\nexport type LastMove = {\n  title: string;\n  lane: LaneId;\n};\n\nexport type BoardState = {\n  /** In the order of the lanes: a task that changes lane goes to the end of its new one. */\n  tasks: Task[];\n  lastMove: LastMove | null;\n};\n\nexport type BoardAction =\n  | { type: 'submitted'; id: string; usd: number }\n  | { type: 'spent'; id: string; usd: number }\n  | { type: 'approved'; id: string }\n  | { type: 'sentBack'; id: string; note: string }\n  | { type: 'moved'; id: string; to: LaneId }\n  | { type: 'dropped'; id: string; to: LaneId };\n\ntype Step = SessionStep<BoardState, BoardAction>;\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\nfunction endedAtOf(seed: TaskSeed) {\n  if (seed.endedAgo === undefined) {\n    return undefined;\n  }\n  return since(seed.endedAgo);\n}\n\nfunction taskOf(seed: TaskSeed): Task {\n  return {\n    id: seed.id,\n    agentId: seed.agentId,\n    title: seed.title,\n    lane: seed.lane,\n    costUsd: seed.costUsd,\n    startedAt: since(seed.startedAgo),\n    endedAt: endedAtOf(seed),\n    request: seed.request,\n    wasApproved: seed.lane === 'done',\n    drops: 0,\n  };\n}\n\nexport const INITIAL: BoardState = {\n  tasks: TASKS.map(taskOf),\n  lastMove: null,\n};\n\nexport function tasksIn(state: BoardState, lane: LaneId) {\n  return state.tasks.filter((task) => task.lane === lane);\n}\n\n/** Where every task sits. Cards only measure themselves again when it changes. */\nexport function placementOf(state: BoardState) {\n  const places = state.tasks.map((task) => `${task.id}:${task.lane}`);\n  return places.join(' ');\n}\n\nfunction taskById(state: BoardState, id: string) {\n  return state.tasks.find((task) => task.id === id);\n}\n\n/** Work stops the clock when a task leaves Running and starts it again when it comes back. */\nfunction timedFor(task: Task, lane: LaneId, now: number): Task {\n  if (lane === 'running') {\n    return { ...task, lane, endedAt: undefined };\n  }\n  return { ...task, lane, endedAt: task.endedAt ?? now };\n}\n\nfunction relocated(\n  state: BoardState,\n  id: string,\n  change: (task: Task) => Task\n): BoardState {\n  const task = taskById(state, id);\n  if (!task) {\n    return state;\n  }\n  const next = change(task);\n  const others = state.tasks.filter((candidate) => candidate.id !== id);\n  const lastMove = { title: next.title, lane: next.lane };\n  return { tasks: [...others, next], lastMove };\n}\n\nfunction submitted(\n  state: BoardState,\n  id: string,\n  usd: number,\n  now: number\n): BoardState {\n  const task = taskById(state, id);\n  if (task?.lane !== 'running') {\n    return state;\n  }\n  return relocated(state, id, (current) => ({\n    ...timedFor(current, 'review', now),\n    costUsd: current.costUsd + usd,\n  }));\n}\n\nfunction spent(state: BoardState, id: string, usd: number): BoardState {\n  const tasks = state.tasks.map((task) => {\n    const isWorking = task.id === id && task.lane === 'running';\n    if (isWorking) {\n      return { ...task, costUsd: task.costUsd + usd };\n    }\n    return task;\n  });\n  return { ...state, tasks };\n}\n\nfunction approved(state: BoardState, id: string, now: number): BoardState {\n  const task = taskById(state, id);\n  if (task?.lane !== 'review') {\n    return state;\n  }\n  return relocated(state, id, (current) => ({\n    ...timedFor(current, 'done', now),\n    wasApproved: true,\n    note: undefined,\n  }));\n}\n\nfunction sentBack(\n  state: BoardState,\n  id: string,\n  note: string,\n  now: number\n): BoardState {\n  const task = taskById(state, id);\n  if (task?.lane !== 'review') {\n    return state;\n  }\n  return relocated(state, id, (current) => ({\n    ...timedFor(current, 'running', now),\n    note,\n  }));\n}\n\nfunction moved(\n  state: BoardState,\n  id: string,\n  to: LaneId,\n  now: number,\n  isDrop: boolean\n): BoardState {\n  const task = taskById(state, id);\n  const isSameLane = task?.lane === to;\n  if (!task || isSameLane) {\n    return state;\n  }\n  let drops = task.drops;\n  if (isDrop) {\n    drops += 1;\n  }\n  return relocated(state, id, (current) => ({\n    ...timedFor(current, to, now),\n    wasApproved: to === 'done',\n    drops,\n  }));\n}\n\nexport function applyAt(\n  state: BoardState,\n  action: BoardAction,\n  now: number\n): BoardState {\n  switch (action.type) {\n    case 'submitted':\n      return submitted(state, action.id, action.usd, now);\n    case 'spent':\n      return spent(state, action.id, action.usd);\n    case 'approved':\n      return approved(state, action.id, now);\n    case 'sentBack':\n      return sentBack(state, action.id, action.note, now);\n    case 'moved':\n      return moved(state, action.id, action.to, now, false);\n    case 'dropped':\n      return moved(state, action.id, action.to, now, true);\n  }\n}\n\nexport function reducer(state: BoardState, action: BoardAction) {\n  return applyAt(state, action, Date.now());\n}\n\nfunction hasLeftReview(id: string) {\n  return (state: BoardState) => taskById(state, id)?.lane !== 'review';\n}\n\n/** A request that waits on a person is answered by the demonstration after this long. */\nconst DECIDE_AFTER_MS = 2500;\n\n/** How long an agent takes to rework a task a person sent back. */\nexport const REWORK_MS = 4200;\n\nexport const REWORK_USD = 0.038;\n\nconst FIRST_SUBMIT: Step = {\n  after: 1500,\n  action: { type: 'submitted', id: 'returns-page', usd: 0.026 },\n};\n\nexport const SCRIPT: Step[] = [\n  FIRST_SUBMIT,\n  {\n    after: DECIDE_AFTER_MS,\n    by: 'person',\n    press: 'approve-contract',\n    action: { type: 'approved', id: 'contract' },\n    isAnswered: hasLeftReview('contract'),\n  },\n  { after: 1500, action: { type: 'spent', id: 'tax-rounding', usd: 0.041 } },\n  { after: 1300, action: { type: 'submitted', id: 'couriers', usd: 0.033 } },\n  {\n    after: DECIDE_AFTER_MS,\n    by: 'person',\n    press: 'approve-returns-page',\n    action: { type: 'approved', id: 'returns-page' },\n    isAnswered: hasLeftReview('returns-page'),\n  },\n  {\n    after: 1700,\n    action: { type: 'submitted', id: 'tax-rounding', usd: 0.052 },\n  },\n  {\n    after: DECIDE_AFTER_MS,\n    by: 'person',\n    press: 'approve-couriers',\n    action: { type: 'approved', id: 'couriers' },\n    isAnswered: hasLeftReview('couriers'),\n  },\n];\n\n/** Under reduced motion two tasks wait in Needs review, with their buttons to read. */\nexport const RESTING = applyAt(INITIAL, FIRST_SUBMIT.action, LOADED_AT);\n\nexport const LOOP_AFTER_MS = 3800;\n",
      "type": "registry:component",
      "target": "components/blocks/agent-ops-08/session.ts"
    },
    {
      "path": "registry/ndeko/blocks/agent-ops/agent-ops-08/data.ts",
      "content": "import type { SeriesSlot } from '@/registry/ndeko/lib/agent-run';\n\nexport const RUN_TITLE = 'Autumn catalogue launch';\n\nexport type AgentId =\n  'planner' | 'researcher' | 'writer' | 'reviewer' | 'coder';\n\nexport type Agent = {\n  name: string;\n  series: SeriesSlot;\n};\n\nexport const AGENTS: Record<AgentId, Agent> = {\n  planner: { name: 'Planner', series: 1 },\n  researcher: { name: 'Researcher', series: 2 },\n  writer: { name: 'Writer', series: 3 },\n  reviewer: { name: 'Reviewer', series: 4 },\n  coder: { name: 'Coder', series: 5 },\n};\n\nexport type LaneId = 'running' | 'review' | 'done';\n\nexport type Lane = {\n  id: LaneId;\n  label: string;\n  /** Said in an empty lane, which still takes a drop. */\n  emptyLine: string;\n};\n\nexport const LANES: Lane[] = [\n  {\n    id: 'running',\n    label: 'Running',\n    emptyLine: 'No agent is working. Drop a task here to send it back',\n  },\n  {\n    id: 'review',\n    label: 'Needs review',\n    emptyLine: 'Nothing waits on you',\n  },\n  {\n    id: 'done',\n    label: 'Done',\n    emptyLine: 'Approved tasks land here',\n  },\n];\n\nexport function laneLabelOf(id: LaneId) {\n  const lane = LANES.find((candidate) => candidate.id === id);\n  return lane?.label ?? '';\n}\n\nexport type TaskSeed = {\n  id: string;\n  agentId: AgentId;\n  title: string;\n  lane: LaneId;\n  costUsd: number;\n  /** Minutes before the page loaded. */\n  startedAgo: number;\n  endedAgo?: number;\n  /** What the agent asks a person to approve once its work is ready. */\n  request: string;\n};\n\n/** Invented tasks and costs. The figures are illustrative. */\nexport const TASKS: TaskSeed[] = [\n  {\n    id: 'couriers',\n    agentId: 'researcher',\n    title: 'Compare three couriers for parcels under 2 kg',\n    lane: 'running',\n    costUsd: 0.412,\n    startedAgo: 12,\n    request: 'Share the comparison with the operations team',\n  },\n  {\n    id: 'returns-page',\n    agentId: 'writer',\n    title: 'Draft the returns page',\n    lane: 'running',\n    costUsd: 0.188,\n    startedAgo: 4,\n    request: 'Publish the draft to the help center',\n  },\n  {\n    id: 'tax-rounding',\n    agentId: 'coder',\n    title: 'Fix the rounding in the tax step',\n    lane: 'running',\n    costUsd: 1.204,\n    startedAgo: 21,\n    request: 'Merge the fix into main',\n  },\n  {\n    id: 'contract',\n    agentId: 'reviewer',\n    title: 'Summarise the supplier contract',\n    lane: 'review',\n    costUsd: 0.356,\n    startedAgo: 9,\n    endedAgo: 2,\n    request: 'Send the summary to legal@solwaybooks.example',\n  },\n  {\n    id: 'catalogue-plan',\n    agentId: 'planner',\n    title: 'Plan the catalogue in six steps',\n    lane: 'done',\n    costUsd: 0.884,\n    startedAgo: 31,\n    endedAgo: 14,\n    request: 'Share the plan with the team',\n  },\n];\n",
      "type": "registry:component",
      "target": "components/blocks/agent-ops-08/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "agent-ops"
  ],
  "type": "registry:block"
}