{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "agent-01",
  "title": "Agent plan",
  "description": "A plan that waits for Approve plan or an inline edit, then runs: each step checks itself off while the highlight glides to the next one, the agent slides in a step it adds and strikes the one it drops, and a toggle folds it into one line.",
  "dependencies": [
    "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/chip.json",
    "https://ui.ndekocode.dev/r/demonstration.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/progress.json",
    "https://ui.ndekocode.dev/r/replay-button.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-agent-run.json",
    "https://ui.ndekocode.dev/r/use-autoplay.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/utils.json",
    "https://ui.ndekocode.dev/r/words.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/agent/agent-01.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport { useId, useRef, useState } from 'react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport {\n  useRunScript,\n  type RunScriptStep,\n} from '@/registry/ndeko/hooks/use-agent-run';\nimport {\n  useAutoplay,\n  type AutoplayStep,\n} from '@/registry/ndeko/hooks/use-autoplay';\nimport { useKeptHeight } from '@/registry/ndeko/hooks/use-kept-height';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport {\n  emptyRun,\n  formatDuration,\n  seriesColorOf,\n  type ApprovalRequest,\n  type PlanStep,\n  type RunAgent,\n  type RunSnapshot,\n  type RunStatus,\n  type StepStatus,\n} from '@/registry/ndeko/lib/agent-run';\nimport {\n  hold,\n  PRESS_LEAD_MS,\n  pressedSolidOf,\n  spokenUnless,\n  usePress,\n} from '@/registry/ndeko/lib/demonstration';\nimport {\n  ArrowDownIcon,\n  ArrowUpIcon,\n  CheckIcon,\n  ChevronDownIcon,\n  ChevronsUpDownIcon,\n  CircleCheckIcon,\n  CircleIcon,\n  CircleXIcon,\n  ListCollapseIcon,\n  LoaderIcon,\n  MinusIcon,\n  PencilIcon,\n  PlusIcon,\n  XIcon,\n} from '@/registry/ndeko/lib/icons';\nimport {\n  fadePresence,\n  rowPresenceOf,\n  springOf,\n} from '@/registry/ndeko/lib/motion-presets';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { countOf, nounOf } from '@/registry/ndeko/lib/words';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Fold, Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { Chip } from '@/registry/ndeko/ui/chip';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport { ClockGate, LiveDuration } from '@/registry/ndeko/ui/live-duration';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { Progress, ProgressLabel } from '@/registry/ndeko/ui/progress';\nimport { ReplayButton } from '@/registry/ndeko/ui/replay-button';\n\nimport { AgentTile } from './_parts/agent-tile';\nimport { PAGE_ERROR, PLANNER, RUN_TITLE } from './_parts/crew';\nimport { DECIDE_AFTER_MS } from './_parts/demo';\nimport { focusLater } from './_parts/focus-later';\nimport { KeyedHeight } from './_parts/keyed-height';\nimport { RelativeTime } from './_parts/relative-time';\n\nexport type PlanChange = {\n  stepId: string;\n  kind: 'added' | 'skipped';\n};\n\ntype PlanPhase =\n  'waiting' | 'editing' | 'running' | 'revised' | 'done' | 'failed' | 'stopped';\n\ntype BadgeVariant = React.ComponentProps<typeof Badge>['variant'];\n\nconst PHASE_LOOK: Record<PlanPhase, { label: string; variant: BadgeVariant }> =\n  {\n    waiting: { label: 'Needs your approval', variant: 'warning' },\n    editing: { label: 'Editing', variant: 'secondary' },\n    running: { label: 'Running', variant: 'info' },\n    revised: { label: 'Revised', variant: 'info' },\n    done: { label: 'Done', variant: 'success' },\n    failed: { label: 'Failed', variant: 'destructive' },\n    stopped: { label: 'Stopped', variant: 'secondary' },\n  };\n\nconst STEP_STATUS_WORD: Record<StepStatus, string> = {\n  upcoming: 'Upcoming',\n  running: 'Running',\n  done: 'Done',\n  failed: 'Failed',\n  skipped: 'Skipped',\n};\n\nconst CHANGE_WORD: Record<PlanChange['kind'], string> = {\n  added: 'Added',\n  skipped: 'Skipped',\n};\n\nconst NO_CHANGES: PlanChange[] = [];\n\nfunction isPendingApproval(approval: ApprovalRequest | undefined) {\n  return approval?.status === 'pending';\n}\n\nfunction phaseOf(\n  status: RunStatus,\n  approval: ApprovalRequest | undefined,\n  changes: PlanChange[],\n  isEditing: boolean\n): PlanPhase {\n  if (isEditing) {\n    return 'editing';\n  }\n  if (isPendingApproval(approval)) {\n    return 'waiting';\n  }\n  if (status === 'done') {\n    return 'done';\n  }\n  if (status === 'failed') {\n    return 'failed';\n  }\n  if (status === 'cancelled') {\n    return 'stopped';\n  }\n  if (changes.length > 0) {\n    return 'revised';\n  }\n  return 'running';\n}\n\nfunction isCounted(step: PlanStep) {\n  return step.status !== 'skipped';\n}\n\nfunction countedStepsOf(steps: PlanStep[]) {\n  return steps.filter(isCounted);\n}\n\nfunction countWithStatus(steps: PlanStep[], status: StepStatus) {\n  const matching = steps.filter((step) => step.status === status);\n  return matching.length;\n}\n\nfunction shareOf(part: number, total: number) {\n  if (total === 0) {\n    return 0;\n  }\n  const ratio = part / total;\n  return ratio * 100;\n}\n\nfunction firstFound(primary: number, fallback: number) {\n  if (primary >= 0) {\n    return primary;\n  }\n  return fallback;\n}\n\ntype CurrentStep = {\n  step: PlanStep;\n  position: number;\n  total: number;\n};\n\n/** The running step, or between two steps the next one, so the folded line never blinks empty. */\nexport function currentStepOf(steps: PlanStep[]): CurrentStep | null {\n  const counted = countedStepsOf(steps);\n  const runningIndex = counted.findIndex((step) => step.status === 'running');\n  const upcomingIndex = counted.findIndex((step) => step.status === 'upcoming');\n  const index = firstFound(runningIndex, upcomingIndex);\n  if (index < 0) {\n    return null;\n  }\n  return { step: counted[index], position: index + 1, total: counted.length };\n}\n\nfunction changeOf(changes: PlanChange[], stepId: string) {\n  return changes.find((change) => change.stepId === stepId);\n}\n\nfunction chevronTurnOf(isOpen: boolean) {\n  if (isOpen) {\n    return 'rotate-180';\n  }\n  return 'rotate-0';\n}\n\nfunction titleToneOf(status: StepStatus) {\n  if (status === 'skipped') {\n    return 'text-muted-foreground decoration-muted-foreground/70';\n  }\n  if (status === 'upcoming') {\n    return 'text-foreground/70 decoration-transparent';\n  }\n  return 'text-foreground decoration-transparent';\n}\n\nfunction StepGlyph({ status }: { status: StepStatus }) {\n  if (status === 'upcoming') {\n    return <CircleIcon className='text-muted-foreground/60 size-4' />;\n  }\n  if (status === 'running') {\n    return <LoaderIcon className='text-muted-foreground size-4 animate-spin' />;\n  }\n  if (status === 'done') {\n    return <CircleCheckIcon className='text-success-foreground size-4' />;\n  }\n  if (status === 'failed') {\n    return <CircleXIcon className='text-destructive-ink size-4' />;\n  }\n  return <MinusIcon className='text-muted-foreground size-4' />;\n}\n\nfunction StepMark({\n  status,\n  className,\n}: {\n  status: StepStatus;\n  className?: string;\n}) {\n  return (\n    <span className={cn('inline-flex size-4 shrink-0', className)}>\n      <Swap swapKey={status} className='size-4'>\n        <StepGlyph status={status} />\n      </Swap>\n      <span className='sr-only'>{STEP_STATUS_WORD[status]}</span>\n    </span>\n  );\n}\n\n/** A duration that ticks keeps its width, so the title beside it never shifts. */\nfunction StepTime({ step }: { step: PlanStep }) {\n  const isRunning = step.status === 'running';\n  const hasStarted = step.startedAt !== undefined;\n  if (!hasStarted) {\n    return null;\n  }\n  return (\n    <LiveDuration\n      item={step}\n      isRunning={isRunning}\n      className='text-muted-foreground min-w-8 shrink-0 text-end text-xs leading-5'\n    />\n  );\n}\n\nfunction SubstepList({ substeps }: { substeps: PlanStep[] }) {\n  return (\n    <ol className='flex flex-col gap-1 ps-9 pe-2 pt-0.5 pb-2'>\n      {substeps.map((substep) => (\n        <li key={substep.id} className='flex items-start gap-2.5 text-xs'>\n          <StepMark status={substep.status} className='mt-0.5' />\n          <span\n            className={cn(\n              'min-w-0 flex-1 leading-5',\n              titleToneOf(substep.status)\n            )}\n          >\n            {substep.title}\n          </span>\n          <StepTime step={substep} />\n        </li>\n      ))}\n    </ol>\n  );\n}\n\ntype StepContentProps = {\n  step: PlanStep;\n  change: PlanChange | undefined;\n  agent: Pick<RunAgent, 'name' | 'series'>;\n  hasSubsteps: boolean;\n  isOpen: boolean;\n  /** The step the agent is on: the one that runs, or the next one in the breath between two steps. */\n  isCurrent: boolean;\n  highlightId: string;\n};\n\nfunction StepContent({\n  step,\n  change,\n  agent,\n  hasSubsteps,\n  isOpen,\n  isCurrent,\n  highlightId,\n}: StepContentProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const rowPresence = rowPresenceOf(shouldReduceMotion);\n  const spring = springOf(shouldReduceMotion);\n  const isFailed = step.status === 'failed';\n  const failure = step.detail ?? '';\n  const hasFailure = failure !== '';\n  const showsFailure = isFailed && hasFailure;\n  const chipColor = seriesColorOf(agent.series);\n\n  return (\n    <>\n      {isCurrent && (\n        <motion.span\n          layoutId={highlightId}\n          layoutDependency={step.id}\n          transition={spring}\n          aria-hidden='true'\n          className='bg-foreground/[0.04] dark:bg-foreground/[0.06] absolute inset-0 -z-10 rounded-lg'\n        />\n      )}\n      <StepMark status={step.status} className='mt-0.5' />\n      <span className='flex min-w-0 flex-1 flex-col gap-1'>\n        <span className='flex flex-wrap items-center gap-x-2 gap-y-1'>\n          <span\n            className={cn(\n              'text-[13px] leading-5 line-through transition-[color,text-decoration-color] duration-300 ease-(--ease-out-strong)',\n              titleToneOf(step.status)\n            )}\n          >\n            {step.title}\n          </span>\n          <AnimatePresence initial={false}>\n            {change && (\n              <motion.span\n                key={change.kind}\n                className='inline-flex'\n                {...fadePresence()}\n              >\n                <Chip color={chipColor}>\n                  {CHANGE_WORD[change.kind]} by {agent.name}\n                </Chip>\n              </motion.span>\n            )}\n          </AnimatePresence>\n        </span>\n        <AnimatePresence initial={false}>\n          {showsFailure && (\n            <motion.span\n              key='failure'\n              className='text-destructive-ink block overflow-hidden text-xs leading-5'\n              {...rowPresence}\n            >\n              {failure}\n            </motion.span>\n          )}\n        </AnimatePresence>\n      </span>\n      <StepTime step={step} />\n      {hasSubsteps && (\n        <ChevronDownIcon\n          className={cn(\n            'text-muted-foreground mt-0.5 size-4 shrink-0 transition-transform duration-200 ease-(--ease-out-strong)',\n            chevronTurnOf(isOpen)\n          )}\n        />\n      )}\n    </>\n  );\n}\n\nconst ROW =\n  'relative isolate flex w-full items-start gap-3 rounded-lg px-2 py-2';\n\ntype StepRowProps = {\n  step: PlanStep;\n  change: PlanChange | undefined;\n  agent: Pick<RunAgent, 'name' | 'series'>;\n  isOpen: boolean;\n  isCurrent: boolean;\n  onToggle: (stepId: string, isOpen: boolean) => void;\n  highlightId: string;\n};\n\nfunction StepRow({\n  step,\n  change,\n  agent,\n  isOpen,\n  isCurrent,\n  onToggle,\n  highlightId,\n}: StepRowProps) {\n  const panelId = useId();\n  const substeps = step.substeps ?? [];\n  const hasSubsteps = substeps.length > 0;\n\n  function toggle() {\n    onToggle(step.id, !isOpen);\n  }\n\n  const content = (\n    <StepContent\n      step={step}\n      change={change}\n      agent={agent}\n      hasSubsteps={hasSubsteps}\n      isOpen={isOpen}\n      isCurrent={isCurrent}\n      highlightId={highlightId}\n    />\n  );\n\n  return (\n    <div data-status={step.status}>\n      {hasSubsteps && (\n        <button\n          type='button'\n          aria-expanded={isOpen}\n          aria-controls={panelId}\n          onClick={toggle}\n          className={cn(\n            ROW,\n            'hover:bg-foreground/[0.03] focus-visible:ring-ring/25 cursor-pointer text-start outline-none focus-visible:ring-[3px] focus-visible:ring-inset'\n          )}\n        >\n          {content}\n        </button>\n      )}\n      {!hasSubsteps && <div className={ROW}>{content}</div>}\n      {hasSubsteps && (\n        <Fold open={isOpen} id={panelId}>\n          <SubstepList substeps={substeps} />\n        </Fold>\n      )}\n    </div>\n  );\n}\n\ntype StepListProps = {\n  steps: PlanStep[];\n  changes: PlanChange[];\n  agent: Pick<RunAgent, 'name' | 'series'>;\n  currentId: string | null;\n};\n\nfunction StepList({ steps, changes, agent, currentId }: StepListProps) {\n  const [toggled, setToggled] = useState<Record<string, boolean>>({});\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const rowPresence = rowPresenceOf(shouldReduceMotion);\n  const highlightId = useId();\n\n  function isOpenOf(step: PlanStep) {\n    const isRunning = step.status === 'running';\n    return toggled[step.id] ?? isRunning;\n  }\n\n  function setOpen(stepId: string, isOpen: boolean) {\n    setToggled((current) => ({ ...current, [stepId]: isOpen }));\n  }\n\n  return (\n    <ol aria-label='Steps' className='-mx-2 flex flex-col'>\n      <AnimatePresence initial={false}>\n        {steps.map((step) => (\n          <motion.li key={step.id} className='overflow-hidden' {...rowPresence}>\n            <StepRow\n              step={step}\n              change={changeOf(changes, step.id)}\n              agent={agent}\n              isOpen={isOpenOf(step)}\n              isCurrent={step.id === currentId}\n              onToggle={setOpen}\n              highlightId={highlightId}\n            />\n          </motion.li>\n        ))}\n      </AnimatePresence>\n    </ol>\n  );\n}\n\ntype DraftStep = {\n  id: string;\n  title: string;\n  substeps?: PlanStep[];\n};\n\nfunction draftOf(step: PlanStep): DraftStep {\n  return { id: step.id, title: step.title, substeps: step.substeps };\n}\n\nfunction planStepOf(draft: DraftStep): PlanStep {\n  const title = draft.title.trim();\n  if (draft.substeps) {\n    return {\n      id: draft.id,\n      title,\n      status: 'upcoming',\n      substeps: draft.substeps,\n    };\n  }\n  return { id: draft.id, title, status: 'upcoming' };\n}\n\nfunction isBlank(draft: DraftStep) {\n  return draft.title.trim() === '';\n}\n\nfunction describedByOf(isInvalid: boolean, errorId: string) {\n  if (isInvalid) {\n    return errorId;\n  }\n  return undefined;\n}\n\nfunction fieldLabelOf(draft: DraftStep, index: number) {\n  if (isBlank(draft)) {\n    return `step ${index + 1}`;\n  }\n  return draft.title;\n}\n\n/** A row moved to an end loses the button that moved it, so focus lands on the one still enabled. */\nfunction landingButtonOf(target: number, count: number, offset: -1 | 1) {\n  const isAtTop = target === 0;\n  const isAtBottom = target === count - 1;\n  if (isAtTop) {\n    return 'down';\n  }\n  if (isAtBottom) {\n    return 'up';\n  }\n  if (offset < 0) {\n    return 'up';\n  }\n  return 'down';\n}\n\ntype PlanEditorProps = {\n  steps: PlanStep[];\n  onCancel: () => void;\n  onSave: (steps: PlanStep[]) => void;\n};\n\nfunction PlanEditor({ steps, onCancel, onSave }: PlanEditorProps) {\n  const [draft, setDraft] = useState<DraftStep[]>(() => steps.map(draftOf));\n  const [showsErrors, setShowsErrors] = useState(false);\n  const rootRef = useRef<HTMLDivElement>(null);\n  const errorId = useId();\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const rowPresence = rowPresenceOf(shouldReduceMotion);\n  const spring = springOf(shouldReduceMotion);\n  const rowTransition = { ...rowPresence.transition, layout: spring };\n  const draftIds = draft.map((step) => step.id);\n  const orderKey = draftIds.join(' ');\n  const blankStep = draft.find(isBlank);\n  const showsBlankError = showsErrors && blankStep !== undefined;\n  const isLastStep = draft.length === 1;\n\n  function rename(stepId: string, title: string) {\n    setDraft((current) =>\n      current.map((step) => {\n        if (step.id !== stepId) {\n          return step;\n        }\n        return { ...step, title };\n      })\n    );\n  }\n\n  function move(stepId: string, offset: -1 | 1) {\n    const index = draft.findIndex((step) => step.id === stepId);\n    const target = index + offset;\n    const isAboveStart = target < 0;\n    const isPastEnd = target >= draft.length;\n    if (isAboveStart || isPastEnd) {\n      return;\n    }\n    const next = [...draft];\n    const [moved] = next.splice(index, 1);\n    next.splice(target, 0, moved);\n    setDraft(next);\n    const landing = landingButtonOf(target, next.length, offset);\n    focusLater(rootRef, `[data-move=\"${stepId}-${landing}\"]`);\n  }\n\n  function remove(stepId: string) {\n    const index = draft.findIndex((step) => step.id === stepId);\n    const next = draft.filter((step) => step.id !== stepId);\n    setDraft(next);\n    const neighbour = next[index] ?? next[index - 1];\n    if (neighbour) {\n      focusLater(rootRef, `[data-field=\"${neighbour.id}\"]`);\n      return;\n    }\n    focusLater(rootRef, '[data-add-step]');\n  }\n\n  function add() {\n    const id = `added-${Date.now()}`;\n    setDraft((current) => [...current, { id, title: '' }]);\n    focusLater(rootRef, `[data-field=\"${id}\"]`);\n  }\n\n  function save() {\n    if (blankStep) {\n      setShowsErrors(true);\n      focusLater(rootRef, `[data-field=\"${blankStep.id}\"]`);\n      return;\n    }\n    const planSteps = draft.map(planStepOf);\n    onSave(planSteps);\n  }\n\n  function handleKeys(event: React.KeyboardEvent<HTMLDivElement>) {\n    if (event.key === 'Escape') {\n      event.preventDefault();\n      onCancel();\n    }\n  }\n\n  function saveOnEnter(event: React.KeyboardEvent<HTMLInputElement>) {\n    if (event.key === 'Enter') {\n      event.preventDefault();\n      save();\n    }\n  }\n\n  return (\n    <div ref={rootRef} onKeyDown={handleKeys} className='flex flex-col gap-3'>\n      <ol aria-label='Steps to edit' className='-mx-1 flex flex-col'>\n        <AnimatePresence initial={false}>\n          {draft.map((step, index) => {\n            const isFirst = index === 0;\n            const isLast = index === draft.length - 1;\n            const label = fieldLabelOf(step, index);\n            const isInvalid = showsErrors && isBlank(step);\n            const substepCount = step.substeps?.length ?? 0;\n            const hasSubsteps = substepCount > 0;\n\n            return (\n              <motion.li\n                key={step.id}\n                layout='position'\n                layoutDependency={orderKey}\n                className='overflow-hidden'\n                {...rowPresence}\n                transition={rowTransition}\n              >\n                <div className='flex items-start gap-2 px-1 py-1'>\n                  <span className='text-muted-foreground w-4 shrink-0 pt-2 text-end text-xs tabular-nums'>\n                    {index + 1}\n                  </span>\n                  <div className='min-w-0 flex-1'>\n                    <Input\n                      value={step.title}\n                      onChange={(event) => rename(step.id, event.target.value)}\n                      onKeyDown={saveOnEnter}\n                      aria-label={`Step ${index + 1}`}\n                      aria-invalid={isInvalid}\n                      aria-describedby={describedByOf(isInvalid, errorId)}\n                      placeholder='Name the step'\n                      data-field={step.id}\n                      autoFocus={isFirst}\n                    />\n                    {hasSubsteps && (\n                      <p className='text-muted-foreground mt-1 ps-0.5 text-xs'>\n                        Keeps its {countOf(substepCount, 'sub-step')}\n                      </p>\n                    )}\n                  </div>\n                  <div className='flex shrink-0 items-center pt-0.5'>\n                    <Button\n                      type='button'\n                      variant='ghost'\n                      size='icon-sm'\n                      disabled={isFirst}\n                      onClick={() => move(step.id, -1)}\n                      aria-label={`Move ${label} up`}\n                      data-move={`${step.id}-up`}\n                      className='text-muted-foreground'\n                    >\n                      <ArrowUpIcon />\n                    </Button>\n                    <Button\n                      type='button'\n                      variant='ghost'\n                      size='icon-sm'\n                      disabled={isLast}\n                      onClick={() => move(step.id, 1)}\n                      aria-label={`Move ${label} down`}\n                      data-move={`${step.id}-down`}\n                      className='text-muted-foreground'\n                    >\n                      <ArrowDownIcon />\n                    </Button>\n                    <Button\n                      type='button'\n                      variant='ghost'\n                      size='icon-sm'\n                      disabled={isLastStep}\n                      onClick={() => remove(step.id)}\n                      aria-label={`Remove ${label}`}\n                      className='text-muted-foreground'\n                    >\n                      <XIcon />\n                    </Button>\n                  </div>\n                </div>\n              </motion.li>\n            );\n          })}\n        </AnimatePresence>\n      </ol>\n      <button\n        type='button'\n        onClick={add}\n        data-add-step\n        className='hairline-border border-foreground/20 text-muted-foreground hover:text-foreground hover:bg-foreground/[0.03] focus-visible:ring-ring/25 flex h-9 w-full cursor-pointer items-center gap-2 rounded-lg border-dashed px-3 text-[13px] transition-colors outline-none focus-visible:ring-[3px]'\n      >\n        <PlusIcon className='size-4' />\n        Add a step\n      </button>\n      <AnimatePresence initial={false}>\n        {showsBlankError && (\n          <motion.p\n            key='blank'\n            id={errorId}\n            className='text-destructive-ink overflow-hidden text-xs'\n            {...rowPresence}\n          >\n            Name every step, or remove the empty one\n          </motion.p>\n        )}\n      </AnimatePresence>\n      <div className='flex flex-wrap items-center justify-end gap-2'>\n        <Button type='button' variant='ghost' size='sm' onClick={onCancel}>\n          Cancel\n        </Button>\n        <Button type='button' size='sm' onClick={save}>\n          <CheckIcon />\n          Save plan\n        </Button>\n      </div>\n    </div>\n  );\n}\n\nfunction PlanProgress({\n  steps,\n  startedAt,\n  endedAt,\n  isLive,\n}: {\n  steps: PlanStep[];\n  startedAt?: number;\n  endedAt?: number;\n  isLive: boolean;\n}) {\n  const counted = countedStepsOf(steps);\n  const total = counted.length;\n  const doneCount = countWithStatus(counted, 'done');\n  const failedCount = countWithStatus(counted, 'failed');\n  const settledCount = doneCount + failedCount;\n  const value = shareOf(settledCount, total);\n  const hasFailed = failedCount > 0;\n  const hasStarted = startedAt !== undefined;\n\n  return (\n    <Progress value={value}>\n      <div className='flex items-baseline justify-between gap-3'>\n        <ProgressLabel className='text-muted-foreground text-xs font-normal'>\n          <MotionNumber value={doneCount} /> of <MotionNumber value={total} />{' '}\n          {nounOf(total, 'step')}\n          {hasFailed && (\n            <span className='text-destructive-ink'>, {failedCount} failed</span>\n          )}\n        </ProgressLabel>\n        {hasStarted && (\n          <LiveDuration\n            item={{ startedAt, endedAt }}\n            isRunning={isLive}\n            className='text-muted-foreground min-w-8 text-end text-xs'\n          />\n        )}\n      </div>\n    </Progress>\n  );\n}\n\nfunction FoldedLine({\n  phase,\n  steps,\n  startedAt,\n  endedAt,\n}: {\n  phase: PlanPhase;\n  steps: PlanStep[];\n  startedAt?: number;\n  endedAt?: number;\n}) {\n  const counted = countedStepsOf(steps);\n  const stepCount = countOf(counted.length, 'step');\n  const current = currentStepOf(steps);\n  const label = PHASE_LOOK[phase].label;\n\n  if (phase === 'waiting') {\n    return <>Plan of {stepCount} waits for your approval</>;\n  }\n  if (phase === 'done') {\n    const end = endedAt ?? 0;\n    const start = startedAt ?? 0;\n    const elapsed = end - start;\n    return (\n      <>\n        Done: {stepCount} in {formatDuration(elapsed)}\n      </>\n    );\n  }\n  if (!current) {\n    return <>{label}</>;\n  }\n  const isRunning = current.step.status === 'running';\n  return (\n    <>\n      <span className='font-medium'>\n        Step {current.position} of {current.total}:\n      </span>{' '}\n      {current.step.title}\n      {isRunning && (\n        <>\n          ,{' '}\n          <LiveDuration\n            item={current.step}\n            isRunning\n            className='text-muted-foreground'\n          />\n        </>\n      )}\n    </>\n  );\n}\n\nfunction foldedKeyOf(phase: PlanPhase, steps: PlanStep[]) {\n  const current = currentStepOf(steps);\n  const stepKey = current?.step.id ?? 'none';\n  return `${phase}-${stepKey}`;\n}\n\nfunction toggleLabelOf(isFolded: boolean) {\n  if (isFolded) {\n    return 'Unfold the plan';\n  }\n  return 'Fold the plan into one line';\n}\n\nfunction isLiveStatus(status: RunStatus) {\n  const isRunning = status === 'running';\n  const isWaiting = status === 'waiting';\n  return isRunning || isWaiting;\n}\n\n/**\n * The row the agent is on. While the run is live it is the step that runs or, between two steps, the\n * next one: the mark of the step that just ended and the highlight of the one that starts then move\n * in the same instant.\n */\nfunction currentIdOf(steps: PlanStep[], isLive: boolean) {\n  if (isLive) {\n    const current = currentStepOf(steps);\n    return current?.step.id ?? null;\n  }\n  const running = steps.find((step) => step.status === 'running');\n  return running?.id ?? null;\n}\n\nexport type AgentPlanProps = {\n  goal: string;\n  agent: Pick<RunAgent, 'name' | 'series'>;\n  steps: PlanStep[];\n  status: RunStatus;\n  /** The person's go-ahead for the plan: while pending, the plan waits with Approve plan and Edit plan. */\n  approval?: ApprovalRequest;\n  /** Steps the agent added or skipped while it worked. */\n  changes?: PlanChange[];\n  startedAt?: number;\n  endedAt?: number;\n  onApprove?: () => void;\n  onSave?: (steps: PlanStep[]) => void;\n  /** Shows Approve plan held down, for a demonstration that presses it. */\n  isApprovePressed?: boolean;\n  defaultFolded?: boolean;\n  className?: string;\n};\n\nexport function AgentPlan({\n  goal,\n  agent,\n  steps,\n  status,\n  approval,\n  changes = NO_CHANGES,\n  startedAt,\n  endedAt,\n  onApprove,\n  onSave,\n  isApprovePressed = false,\n  defaultFolded = false,\n  className,\n}: AgentPlanProps) {\n  const [isFolded, setIsFolded] = useState(defaultFolded);\n  const [isEditing, setIsEditing] = useState(false);\n  const rootRef = useRef<HTMLElement>(null);\n  const bodyId = useId();\n  const fade = fadePresence();\n  const phase = phaseOf(status, approval, changes, isEditing);\n  const look = PHASE_LOOK[phase];\n  const isWaiting = phase === 'waiting';\n  const wasApproved = approval?.status === 'approved';\n  const resolvedAt = approval?.resolvedAt ?? 0;\n  const showsTrace = wasApproved && !isEditing;\n  const isLive = isLiveStatus(status);\n  const currentId = currentIdOf(steps, isLive);\n  const foldedKey = foldedKeyOf(phase, steps);\n  const toggleLabel = toggleLabelOf(isFolded);\n  const shapeKey = `${isFolded}-${isEditing}`;\n\n  function toggleFolded() {\n    setIsFolded((current) => !current);\n  }\n\n  function approve() {\n    onApprove?.();\n    focusLater(rootRef, '[data-plan-toggle]');\n  }\n\n  function startEditing() {\n    setIsEditing(true);\n  }\n\n  function cancelEditing() {\n    setIsEditing(false);\n    focusLater(rootRef, '[data-plan-action=\"edit\"]');\n  }\n\n  function saveEditing(nextSteps: PlanStep[]) {\n    onSave?.(nextSteps);\n    setIsEditing(false);\n    focusLater(rootRef, '[data-plan-action=\"approve\"]');\n  }\n\n  return (\n    <section\n      ref={rootRef}\n      aria-label={`${agent.name}'s plan: ${goal}`}\n      className={cn(\n        'bg-card hairline-ring ring-border relative rounded-xl shadow-[0_1px_2px_rgb(0_0_0/0.04)]',\n        className\n      )}\n    >\n      {!isEditing && (\n        <Button\n          type='button'\n          variant='ghost'\n          size='icon-sm'\n          aria-expanded={!isFolded}\n          aria-controls={bodyId}\n          aria-label={toggleLabel}\n          onClick={toggleFolded}\n          data-plan-toggle\n          className='text-muted-foreground absolute end-2.5 top-2.5 z-10'\n        >\n          <Swap swapKey={String(isFolded)}>\n            {isFolded && <ChevronsUpDownIcon />}\n            {!isFolded && <ListCollapseIcon />}\n          </Swap>\n        </Button>\n      )}\n      <KeyedHeight changeKey={shapeKey}>\n        <div className='relative'>\n          <AnimatePresence mode='popLayout' initial={false}>\n            {isFolded && (\n              <motion.div\n                key='folded'\n                className='flex min-h-12 items-center gap-2.5 py-2 ps-3 pe-12'\n                {...fade}\n              >\n                <AgentTile name={agent.name} series={agent.series} />\n                <p className='relative min-w-0 flex-1 truncate text-[13px] leading-5'>\n                  <AnimatePresence mode='popLayout' initial={false}>\n                    <motion.span\n                      key={foldedKey}\n                      className='block truncate'\n                      {...fade}\n                    >\n                      <FoldedLine\n                        phase={phase}\n                        steps={steps}\n                        startedAt={startedAt}\n                        endedAt={endedAt}\n                      />\n                    </motion.span>\n                  </AnimatePresence>\n                </p>\n              </motion.div>\n            )}\n            {!isFolded && (\n              <motion.div\n                key='full'\n                id={bodyId}\n                className='flex flex-col gap-4 p-4'\n                {...fade}\n              >\n                <header className='flex items-start gap-3 pe-8'>\n                  <AgentTile\n                    name={agent.name}\n                    series={agent.series}\n                    size='lg'\n                  />\n                  <div className='min-w-0 flex-1'>\n                    <h3 className='truncate text-sm font-medium' title={goal}>\n                      {goal}\n                    </h3>\n                    <div className='mt-1 flex flex-wrap items-center gap-2'>\n                      <span className='text-muted-foreground text-xs'>\n                        {agent.name}&rsquo;s plan\n                      </span>\n                      <Swap swapKey={phase}>\n                        <Badge variant={look.variant}>{look.label}</Badge>\n                      </Swap>\n                    </div>\n                  </div>\n                </header>\n                <PlanProgress\n                  steps={steps}\n                  startedAt={startedAt}\n                  endedAt={endedAt}\n                  isLive={isLive}\n                />\n                <div className='relative'>\n                  <AnimatePresence mode='popLayout' initial={false}>\n                    {isEditing && (\n                      <motion.div key='editor' {...fade}>\n                        <PlanEditor\n                          steps={steps}\n                          onCancel={cancelEditing}\n                          onSave={saveEditing}\n                        />\n                      </motion.div>\n                    )}\n                    {!isEditing && (\n                      <motion.div key='steps' {...fade}>\n                        <StepList\n                          steps={steps}\n                          changes={changes}\n                          agent={agent}\n                          currentId={currentId}\n                        />\n                      </motion.div>\n                    )}\n                  </AnimatePresence>\n                </div>\n                <AnimatePresence mode='popLayout' initial={false}>\n                  {isWaiting && (\n                    <motion.div\n                      key='ask'\n                      className='flex min-h-8 flex-wrap items-center justify-between gap-x-3 gap-y-2'\n                      {...fade}\n                    >\n                      <p className='text-muted-foreground text-xs'>\n                        {agent.name} starts once you approve\n                      </p>\n                      <div className='flex items-center gap-2'>\n                        <Button\n                          type='button'\n                          variant='outline'\n                          size='sm'\n                          onClick={startEditing}\n                          data-plan-action='edit'\n                        >\n                          <PencilIcon />\n                          Edit plan\n                        </Button>\n                        <Button\n                          type='button'\n                          size='sm'\n                          onClick={approve}\n                          data-plan-action='approve'\n                          className={pressedSolidOf(isApprovePressed)}\n                        >\n                          <CheckIcon />\n                          Approve plan\n                        </Button>\n                      </div>\n                    </motion.div>\n                  )}\n                  {showsTrace && (\n                    <motion.p\n                      key='trace'\n                      className='text-muted-foreground flex min-h-8 items-center gap-1.5 text-xs'\n                      {...fade}\n                    >\n                      <CheckIcon className='text-success-foreground size-3.5 shrink-0' />\n                      <span>\n                        You approved this plan, <RelativeTime at={resolvedAt} />\n                      </span>\n                    </motion.p>\n                  )}\n                </AnimatePresence>\n              </motion.div>\n            )}\n          </AnimatePresence>\n        </div>\n      </KeyedHeight>\n    </section>\n  );\n}\n\nconst GOAL = 'Find where Brightmoor overcharged us in Q3 and ask for a credit';\n\nfunction upcoming(id: string, title: string, substeps?: PlanStep[]): PlanStep {\n  if (substeps) {\n    return { id, title, status: 'upcoming', substeps };\n  }\n  return { id, title, status: 'upcoming' };\n}\n\nconst PLAN: PlanStep[] = [\n  upcoming('gather', 'Gather the Q3 invoices from the finance drive', [\n    upcoming('gather-list', 'List the invoice files for July to September'),\n    upcoming('gather-read', 'Read the 117 invoice lines'),\n  ]),\n  upcoming('page', 'Read the Brightmoor pricing page'),\n  upcoming('compare', 'Compare each invoice line with the list price', [\n    upcoming('compare-match', 'Match the items by SKU'),\n    upcoming('compare-flag', 'Flag the lines above the list price'),\n    upcoming('compare-sum', 'Add up what was overpaid'),\n  ]),\n  upcoming('contract', 'Check the bulk discounts in the contract'),\n  upcoming('page-check', 'Confirm the page prices against the contract'),\n  upcoming('draft', 'Draft the credit request to Brightmoor accounts'),\n  upcoming('summary', 'Write a summary for the finance team'),\n];\n\nconst FAILING_STEP_ID = 'page';\n\nconst ADDED_STEP = upcoming(\n  'ask-list',\n  'Ask Brightmoor accounts for their price list'\n);\n\nconst DROPPED_STEP_ID = 'page-check';\n\nconst PLAN_APPROVAL: ApprovalRequest = {\n  id: 'plan',\n  title: 'Run this plan',\n  risk: 'low',\n  status: 'pending',\n  agentId: PLANNER.id,\n};\n\nconst INITIAL_RUN = emptyRun({\n  id: 'brightmoor-plan',\n  title: RUN_TITLE,\n  agents: [PLANNER],\n  plan: PLAN,\n  approvals: [PLAN_APPROVAL],\n});\n\nconst NO_SCRIPT: RunScriptStep[] = [];\n\nconst STEP_GAP_MS = 300;\n\nconst REVISION_PAUSE_MS = 900;\n\nconst DEFAULT_STEP_MS = 1600;\n\nconst STEP_MS: Record<string, number> = {\n  gather: 2000,\n  page: 1300,\n  'ask-list': 1900,\n  compare: 2700,\n  contract: 1500,\n  draft: 2300,\n  summary: 1500,\n};\n\nfunction stepTo(id: string, status: StepStatus): RunScriptStep['event'] {\n  return { type: 'step.updated', id, patch: { status } };\n}\n\nfunction hasStep(plan: PlanStep[], stepId: string) {\n  return plan.some((step) => step.id === stepId);\n}\n\n/** The agent's revision is planned with the rest, out of sight until the step it answers fails. */\nfunction withRevisionSlot(plan: PlanStep[]) {\n  const hasRevision = hasStep(plan, ADDED_STEP.id);\n  const failingIndex = plan.findIndex((step) => step.id === FAILING_STEP_ID);\n  const canFail = failingIndex >= 0;\n  if (hasRevision || !canFail) {\n    return plan;\n  }\n  const revised = [...plan];\n  revised.splice(failingIndex + 1, 0, ADDED_STEP);\n  return revised;\n}\n\nfunction substepEventsOf(substeps: PlanStep[], duration: number) {\n  const exactShare = duration / substeps.length;\n  const share = Math.round(exactShare);\n  const events: RunScriptStep[] = [];\n  for (const substep of substeps) {\n    events.push(\n      { after: 0, event: stepTo(substep.id, 'running') },\n      { after: share, event: stepTo(substep.id, 'done') }\n    );\n  }\n  return events;\n}\n\nfunction failureEventsOf(plan: PlanStep[], duration: number) {\n  const failure: RunScriptStep['event'] = {\n    type: 'step.updated',\n    id: FAILING_STEP_ID,\n    patch: { status: 'failed', detail: PAGE_ERROR },\n  };\n  const events: RunScriptStep[] = [\n    { after: STEP_GAP_MS, event: stepTo(FAILING_STEP_ID, 'running') },\n    { after: duration, event: failure },\n  ];\n  const canDrop = hasStep(plan, DROPPED_STEP_ID);\n  if (canDrop) {\n    events.push({\n      after: REVISION_PAUSE_MS,\n      event: stepTo(DROPPED_STEP_ID, 'skipped'),\n    });\n  }\n  return events;\n}\n\nfunction eventsOfStep(step: PlanStep, plan: PlanStep[]): RunScriptStep[] {\n  const duration = STEP_MS[step.id] ?? DEFAULT_STEP_MS;\n  if (step.id === FAILING_STEP_ID) {\n    return failureEventsOf(plan, duration);\n  }\n  const isDropped = step.id === DROPPED_STEP_ID;\n  const isRevisedPlan = hasStep(plan, ADDED_STEP.id);\n  if (isDropped && isRevisedPlan) {\n    return [];\n  }\n  const start = { after: STEP_GAP_MS, event: stepTo(step.id, 'running') };\n  const substeps = step.substeps ?? [];\n  if (substeps.length === 0) {\n    return [start, { after: duration, event: stepTo(step.id, 'done') }];\n  }\n  const substepEvents = substepEventsOf(substeps, duration);\n  return [\n    start,\n    ...substepEvents,\n    { after: 0, event: stepTo(step.id, 'done') },\n  ];\n}\n\n/** The run follows the plan as approved, edits included: renamed, moved, removed and added steps. */\nfunction scriptOf(plan: PlanStep[]) {\n  const script: RunScriptStep[] = [\n    { after: 400, event: { type: 'run.started' } },\n  ];\n  for (const step of plan) {\n    const events = eventsOfStep(step, plan);\n    script.push(...events);\n  }\n  script.push({ after: 500, event: { type: 'run.finished', status: 'done' } });\n  return script;\n}\n\nfunction isRevisedRun(plan: PlanStep[]) {\n  const failing = plan.find((step) => step.id === FAILING_STEP_ID);\n  return failing?.status === 'failed';\n}\n\nfunction visibleStepsOf(plan: PlanStep[]) {\n  if (isRevisedRun(plan)) {\n    return plan;\n  }\n  return plan.filter((step) => step.id !== ADDED_STEP.id);\n}\n\nfunction changesOf(plan: PlanStep[]) {\n  if (!isRevisedRun(plan)) {\n    return NO_CHANGES;\n  }\n  const changes: PlanChange[] = [];\n  if (hasStep(plan, ADDED_STEP.id)) {\n    changes.push({ stepId: ADDED_STEP.id, kind: 'added' });\n  }\n  const dropped = plan.find((step) => step.id === DROPPED_STEP_ID);\n  if (dropped?.status === 'skipped') {\n    changes.push({ stepId: DROPPED_STEP_ID, kind: 'skipped' });\n  }\n  return changes;\n}\n\nfunction isAddedStep(changes: PlanChange[], stepId: string) {\n  const change = changeOf(changes, stepId);\n  return change?.kind === 'added';\n}\n\nfunction announcementOf(\n  run: RunSnapshot,\n  steps: PlanStep[],\n  changes: PlanChange[]\n) {\n  const [approval] = run.approvals;\n  if (isPendingApproval(approval)) {\n    const stepCount = countOf(steps.length, 'step');\n    return `${PLANNER.name} proposes a plan of ${stepCount} and waits for your approval`;\n  }\n  if (run.status === 'done') {\n    return 'The plan is done';\n  }\n  const current = currentStepOf(steps);\n  if (!current) {\n    return '';\n  }\n  const position = `Step ${current.position} of ${current.total}: ${current.step.title}`;\n  if (isAddedStep(changes, current.step.id)) {\n    return `The pricing page failed, so ${PLANNER.name} revised the plan. ${position}`;\n  }\n  return position;\n}\n\nfunction durationOf(script: RunScriptStep[]) {\n  let total = 0;\n  for (const step of script) {\n    total += step.after;\n  }\n  return total;\n}\n\nconst DEMO_PLAN = withRevisionSlot(PLAN);\n\nconst DEMO_SCRIPT = scriptOf(DEMO_PLAN);\n\nconst LAST_CHECK_MS = 600;\n\n/**\n * The demonstration approves the plan as it was proposed, so it knows how long that run takes: it\n * holds for as long, then a moment more so the last check is seen landing, before the next round.\n */\nconst DEMO_RUN_MS = durationOf(DEMO_SCRIPT) + LAST_CHECK_MS;\n\ntype PressKey = 'approve';\n\n/**\n * The run is built from the plan a person approves, edits included, so its script is not known\n * ahead: it plays into the run store, and the demonstration only presses Approve plan and waits.\n */\nexport default function Agent01() {\n  const [script, setScript] = useState(NO_SCRIPT);\n  const { pressed, press } = usePress<PressKey>();\n  const demoSteps: AutoplayStep[] = [\n    { after: DECIDE_AFTER_MS, run: () => press('approve') },\n    { after: PRESS_LEAD_MS, run: () => approve() },\n    { after: DEMO_RUN_MS, run: hold },\n  ];\n  const {\n    ref,\n    isInView,\n    isAutoplaying,\n    restart: replay,\n  } = useAutoplay(demoSteps, { loopAfter: 3000, onReset: () => resetRun() });\n  const {\n    snapshot,\n    store,\n    restart: restartRun,\n  } = useRunScript(script, { initial: INITIAL_RUN, isActive: isInView });\n  const steps = visibleStepsOf(snapshot.plan);\n  const changes = changesOf(snapshot.plan);\n  const [approval] = snapshot.approvals;\n  const isEnded = snapshot.endedAt !== undefined;\n  const canReplay = isEnded && !isAutoplaying;\n  const announcement = announcementOf(snapshot, steps, changes);\n\n  function approve() {\n    const plan = withRevisionSlot(snapshot.plan);\n    store.dispatch({ type: 'plan.set', steps: plan });\n    store.dispatch({\n      type: 'approval.resolved',\n      id: PLAN_APPROVAL.id,\n      decision: 'approved',\n    });\n    setScript(scriptOf(plan));\n  }\n\n  function save(nextSteps: PlanStep[]) {\n    store.dispatch({ type: 'plan.set', steps: nextSteps });\n  }\n\n  function resetRun() {\n    setScript(NO_SCRIPT);\n    restartRun();\n  }\n\n  useKeptHeight(ref);\n\n  return (\n    <div\n      ref={ref}\n      className='flex min-h-[38.5rem] w-full max-w-[34rem] flex-col gap-2'\n    >\n      <ClockGate isActive={isInView}>\n        <AgentPlan\n          goal={GOAL}\n          agent={PLANNER}\n          steps={steps}\n          status={snapshot.status}\n          approval={approval}\n          changes={changes}\n          startedAt={snapshot.startedAt}\n          endedAt={snapshot.endedAt}\n          onApprove={approve}\n          onSave={save}\n          isApprovePressed={pressed === 'approve'}\n        />\n      </ClockGate>\n      <div className='flex h-7 items-center justify-end'>\n        <ReplayButton\n          isShown={canReplay}\n          onReplay={replay}\n          label='Replay the plan'\n        />\n      </div>\n      <LiveRegion message={spokenUnless(isAutoplaying, announcement)} />\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/agent/agent-01.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/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/relative-time.tsx",
      "content": "'use client';\n\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { useLiveNow } from '@/registry/ndeko/ui/live-duration';\n\nconst MINUTE_MS = 60_000;\n\nconst HOUR_MS = 60 * MINUTE_MS;\n\nconst DAY_MS = 24 * HOUR_MS;\n\nexport function relativeTimeOf(at: number, now: number) {\n  const age = now - at;\n  const elapsed = Math.max(0, age);\n  if (elapsed < MINUTE_MS) {\n    return 'just now';\n  }\n  if (elapsed < HOUR_MS) {\n    const minutes = Math.floor(elapsed / MINUTE_MS);\n    return `${minutes} min ago`;\n  }\n  if (elapsed < DAY_MS) {\n    const hours = Math.floor(elapsed / HOUR_MS);\n    return `${hours} h ago`;\n  }\n  const days = Math.floor(elapsed / DAY_MS);\n  if (days === 1) {\n    return 'yesterday';\n  }\n  return `${days} days ago`;\n}\n\ntype RelativeTimeProps = {\n  at: number;\n  className?: string;\n};\n\nexport function RelativeTime({ at, className }: RelativeTimeProps) {\n  const now = useLiveNow(1000, true);\n  const label = relativeTimeOf(at, now);\n\n  return <span className={cn('tabular-nums', className)}>{label}</span>;\n}\n",
      "type": "registry:component",
      "target": "components/agent/_parts/relative-time.tsx"
    }
  ],
  "categories": [
    "components",
    "agent"
  ],
  "type": "registry:component"
}