{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "features-04",
  "title": "Live features",
  "description": "Five tiles of one agent run, each the working control: a prompt with a status tray, a plan that ticks, an approval that waits for you, a context ring that fills and a cost that rolls.",
  "dependencies": [],
  "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/drawn-check.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/motion-number.json",
    "https://ui.ndekocode.dev/r/replay-button.json",
    "https://ui.ndekocode.dev/r/textarea.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-kept-height.json",
    "https://ui.ndekocode.dev/r/use-session.json",
    "https://ui.ndekocode.dev/r/utils.json",
    "https://ui.ndekocode.dev/r/wash.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/features/features-04/index.tsx",
      "content": "'use client';\n\nimport { useEffect } from 'react';\n\nimport { useKeptHeight } from '@/registry/ndeko/hooks/use-kept-height';\nimport { useSession } from '@/registry/ndeko/hooks/use-session';\nimport { spokenUnless } from '@/registry/ndeko/lib/demonstration';\nimport { ListChecksIcon } from '@/registry/ndeko/lib/icons';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { ReplayButton } from '@/registry/ndeko/ui/replay-button';\n\nimport { ApprovalTile } from './approval-tile';\nimport { ContextTile } from './context-tile';\nimport { CostTile } from './cost-tile';\nimport { APPROVAL, SECTION } from './data';\nimport { PlanTile } from './plan-tile';\nimport { PromptTile } from './prompt-tile';\nimport {\n  doneCountOf,\n  INITIAL,\n  LOOP_AFTER_MS,\n  reducer,\n  RESTING,\n  SCRIPT,\n  TRAY_READ_MS,\n  type RunState,\n} from './session';\n\nconst SESSION = {\n  reducer,\n  initial: INITIAL,\n  resting: RESTING,\n  script: SCRIPT,\n  loopAfter: LOOP_AFTER_MS,\n};\n\nfunction spokenLineOf(state: RunState) {\n  if (state.approval === 'waiting') {\n    return `Ledgerfinch asks: ${APPROVAL.title}. Approve or decline.`;\n  }\n  if (state.approval === 'approved') {\n    return 'Approved, the matches are posted';\n  }\n  if (state.approval === 'declined') {\n    return 'Declined, the step was skipped';\n  }\n  return '';\n}\n\nexport default function Features04() {\n  const { ref, isAutoplaying, state, act, pressed, isFinished, restart } =\n    useSession(SESSION);\n  const isReading = state.tray === 'reading';\n  const isSentByPerson = isReading && !isAutoplaying;\n  const doneCount = doneCountOf(state);\n  const message = spokenUnless(isAutoplaying, spokenLineOf(state));\n  const canReplay = isFinished && !isAutoplaying;\n\n  useKeptHeight(ref);\n\n  useEffect(() => {\n    if (!isSentByPerson) {\n      return;\n    }\n    const timer = setTimeout(() => act({ type: 'planned' }), TRAY_READ_MS);\n    return () => clearTimeout(timer);\n  }, [isSentByPerson, act]);\n\n  return (\n    <div ref={ref} className='@container min-h-[60rem]'>\n      <section className='px-4 py-16 @2xl:px-6 @2xl:py-24 @5xl:px-8'>\n        <div className='mx-auto flex max-w-6xl flex-col gap-10'>\n          <header className='flex flex-wrap items-end justify-between gap-x-6 gap-y-4'>\n            <div className='flex max-w-2xl flex-col gap-3'>\n              <p className='text-primary-ink flex items-center gap-1.5 text-[13px] font-medium'>\n                <ListChecksIcon className='size-4' />\n                {SECTION.label}\n              </p>\n              <h2 className='text-2xl font-semibold text-balance @2xl:text-3xl'>\n                {SECTION.title}\n              </h2>\n              <p className='text-muted-foreground text-base text-pretty'>\n                {SECTION.lead}\n              </p>\n            </div>\n            <div className='flex flex-wrap items-center gap-2'>\n              <ReplayButton\n                isShown={canReplay}\n                onReplay={restart}\n                label='Replay'\n              />\n              <Badge variant='secondary'>{SECTION.figures}</Badge>\n            </div>\n          </header>\n          <ul className='grid gap-3 @4xl:grid-cols-6'>\n            <li className='flex @4xl:col-span-3'>\n              <PromptTile\n                prompt={state.prompt}\n                tray={state.tray}\n                isSendPressed={pressed === 'send'}\n                onType={(value) => act({ type: 'typed', value })}\n                onSend={() => act({ type: 'sent' })}\n              />\n            </li>\n            <li className='flex @4xl:col-span-3'>\n              <PlanTile steps={state.steps} doneCount={doneCount} />\n            </li>\n            <li className='flex @4xl:col-span-2'>\n              <ApprovalTile\n                approval={state.approval}\n                isApprovePressed={pressed === 'approve'}\n                onApprove={() => act({ type: 'approved' })}\n                onDecline={() => act({ type: 'declined' })}\n              />\n            </li>\n            <li className='flex @4xl:col-span-2'>\n              <ContextTile percent={state.context} />\n            </li>\n            <li className='flex @4xl:col-span-2'>\n              <CostTile cost={state.cost} />\n            </li>\n          </ul>\n        </div>\n      </section>\n      <LiveRegion message={message} />\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/features-04/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/features/features-04/approval-tile.tsx",
      "content": "'use client';\n\nimport { pressedSolidOf } from '@/registry/ndeko/lib/demonstration';\nimport { CircleDashedIcon, XIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { DrawnCheck } from '@/registry/ndeko/ui/drawn-check';\nimport { Wash } from '@/registry/ndeko/ui/wash';\n\nimport { APPROVAL, TILES } from './data';\nimport type { Approval } from './session';\nimport { Tile } from './tile';\n\nfunction layerClassOf(isActive: boolean) {\n  if (isActive) {\n    return 'opacity-100 transition-opacity delay-100 duration-200 ease-(--ease-out-strong)';\n  }\n  return 'pointer-events-none opacity-0 transition-opacity duration-150';\n}\n\ntype ApprovalTileProps = {\n  approval: Approval;\n  isApprovePressed: boolean;\n  onApprove: () => void;\n  onDecline: () => void;\n};\n\nexport function ApprovalTile({\n  approval,\n  isApprovePressed,\n  onApprove,\n  onDecline,\n}: ApprovalTileProps) {\n  const isNone = approval === 'none';\n  const isWaiting = approval === 'waiting';\n  const isApproved = approval === 'approved';\n  const isDeclined = approval === 'declined';\n\n  return (\n    <Tile copy={TILES.approval}>\n      <Wash color='var(--warning)' isShown={isWaiting} />\n      <div className='grid *:col-start-1 *:row-start-1'>\n        <p\n          inert={!isNone}\n          aria-hidden={!isNone}\n          className={cn(\n            'text-muted-foreground flex items-center gap-2 text-[13px]',\n            layerClassOf(isNone)\n          )}\n        >\n          <CircleDashedIcon className='size-4 shrink-0' />\n          Nothing is waiting for you\n        </p>\n        <div\n          inert={!isWaiting}\n          aria-hidden={!isWaiting}\n          className={cn(\n            'bg-card dark:bg-foreground/[0.06] flex flex-col gap-3 rounded-xl p-3 shadow-[0_1px_2px_rgb(0_0_0/0.04)]',\n            layerClassOf(isWaiting)\n          )}\n        >\n          <div className='flex flex-col gap-1'>\n            <p className='text-[13px] font-medium'>{APPROVAL.title}</p>\n            <p className='text-muted-foreground text-xs text-pretty'>\n              {APPROVAL.detail}\n            </p>\n          </div>\n          <div className='flex flex-wrap gap-2'>\n            <Button\n              size='sm'\n              onClick={onApprove}\n              className={pressedSolidOf(isApprovePressed)}\n            >\n              Approve\n            </Button>\n            <Button size='sm' variant='outline' onClick={onDecline}>\n              Decline\n            </Button>\n          </div>\n        </div>\n        <p\n          inert={!isApproved}\n          aria-hidden={!isApproved}\n          className={cn(\n            'flex items-center gap-2 text-[13px]',\n            layerClassOf(isApproved)\n          )}\n        >\n          {isApproved && <DrawnCheck tone='success' entrance='draw' />}\n          Approved, 38 matches posted\n        </p>\n        <p\n          inert={!isDeclined}\n          aria-hidden={!isDeclined}\n          className={cn(\n            'text-muted-foreground flex items-center gap-2 text-[13px]',\n            layerClassOf(isDeclined)\n          )}\n        >\n          <XIcon className='size-4 shrink-0' />\n          Declined, the step was skipped\n        </p>\n      </div>\n    </Tile>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/features-04/approval-tile.tsx"
    },
    {
      "path": "registry/ndeko/blocks/features/features-04/context-tile.tsx",
      "content": "'use client';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { formatTokens } from '@/registry/ndeko/lib/agent-run';\n\nimport { CONTEXT_LIMIT_TOKENS, TILES } from './data';\nimport { Tile } from './tile';\n\nconst RING_LENGTH = 100;\n\ntype ContextTileProps = {\n  percent: number;\n};\n\nexport function ContextTile({ percent }: ContextTileProps) {\n  const offset = RING_LENGTH - percent;\n  const usedTokens = (percent / 100) * CONTEXT_LIMIT_TOKENS;\n  const used = formatTokens(usedTokens);\n  const limit = formatTokens(CONTEXT_LIMIT_TOKENS);\n\n  return (\n    <Tile copy={TILES.context} stageClassName='items-center gap-3'>\n      <div\n        role='img'\n        aria-label={`Context window ${Math.round(percent)} percent full`}\n        className='relative size-28'\n      >\n        <svg viewBox='0 0 100 100' aria-hidden='true' className='size-full'>\n          <circle\n            cx='50'\n            cy='50'\n            r='44'\n            fill='none'\n            strokeWidth='8'\n            className='stroke-foreground/10'\n          />\n          <circle\n            cx='50'\n            cy='50'\n            r='44'\n            fill='none'\n            strokeWidth='8'\n            strokeLinecap='round'\n            pathLength={RING_LENGTH}\n            strokeDasharray={RING_LENGTH}\n            strokeDashoffset={offset}\n            transform='rotate(-90 50 50)'\n            className='stroke-primary transition-[stroke-dashoffset] duration-700 ease-(--ease-out-strong) motion-reduce:transition-none'\n          />\n        </svg>\n        <span\n          aria-hidden='true'\n          className='absolute inset-0 flex items-center justify-center text-2xl font-semibold'\n        >\n          <MotionNumber value={Math.round(percent)} suffix='%' />\n        </span>\n      </div>\n      <p className='text-muted-foreground text-xs tabular-nums'>\n        {used} of {limit} tokens\n      </p>\n    </Tile>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/features-04/context-tile.tsx"
    },
    {
      "path": "registry/ndeko/blocks/features/features-04/cost-tile.tsx",
      "content": "'use client';\n\nimport { MotionNumber } from '@/components/core/motion-number';\n\nimport { BUDGET_USD, TILES } from './data';\nimport { Tile } from './tile';\n\nconst MONEY = { minimumFractionDigits: 3, maximumFractionDigits: 3 };\n\ntype CostTileProps = {\n  cost: number;\n};\n\nexport function CostTile({ cost }: CostTileProps) {\n  const share = Math.min(cost / BUDGET_USD, 1);\n  const barStyle = { transform: `scaleX(${share})` };\n  const budget = BUDGET_USD.toFixed(2);\n\n  return (\n    <Tile copy={TILES.cost} stageClassName='gap-4'>\n      <div className='flex flex-col gap-1'>\n        <span className='text-muted-foreground text-xs'>Spent this run</span>\n        <MotionNumber\n          value={cost}\n          prefix='$'\n          format={MONEY}\n          className='text-4xl font-semibold'\n        />\n      </div>\n      <div className='flex flex-col gap-1.5'>\n        <div\n          role='progressbar'\n          aria-label='Share of the budget spent'\n          aria-valuemin={0}\n          aria-valuemax={100}\n          aria-valuenow={Math.round(share * 100)}\n          className='bg-foreground/10 h-1.5 overflow-hidden rounded-full'\n        >\n          <div\n            style={barStyle}\n            className='bg-primary h-full w-full origin-left rounded-full transition-transform duration-500 ease-(--ease-out-strong) motion-reduce:transition-none'\n          />\n        </div>\n        <span className='text-muted-foreground text-xs tabular-nums'>\n          Budget ${budget}\n        </span>\n      </div>\n    </Tile>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/features-04/cost-tile.tsx"
    },
    {
      "path": "registry/ndeko/blocks/features/features-04/plan-tile.tsx",
      "content": "'use client';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport {\n  HourglassIcon,\n  LoaderIcon,\n  MinusIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { DrawnCheck } from '@/registry/ndeko/ui/drawn-check';\n\nimport { PLAN_STEPS, TILES } from './data';\nimport type { PlanStatus } from './session';\nimport { Tile } from './tile';\n\nconst STATUS_WORD: Record<PlanStatus, string> = {\n  upcoming: 'Upcoming',\n  running: 'Running',\n  waiting: 'Waiting for you',\n  done: 'Done',\n  skipped: 'Skipped',\n};\n\nfunction StepGlyph({ status }: { status: PlanStatus }) {\n  if (status === 'done') {\n    return <DrawnCheck tone='success' entrance='draw' />;\n  }\n  if (status === 'running') {\n    return <LoaderIcon className='text-muted-foreground size-4 animate-spin' />;\n  }\n  if (status === 'waiting') {\n    return <HourglassIcon className='text-warning-foreground size-4' />;\n  }\n  if (status === 'skipped') {\n    return <MinusIcon className='text-muted-foreground size-4' />;\n  }\n  return (\n    <span className='hairline-ring ring-foreground/25 size-3.5 rounded-full' />\n  );\n}\n\nfunction liftedOf(status: PlanStatus) {\n  const isActive = status === 'running' || status === 'waiting';\n  if (isActive) {\n    return 'bg-card shadow-[0_1px_2px_rgb(0_0_0/0.04)] dark:bg-foreground/[0.06]';\n  }\n  return undefined;\n}\n\nfunction mutedOf(status: PlanStatus) {\n  const isQuiet = status === 'upcoming' || status === 'skipped';\n  if (isQuiet) {\n    return 'text-muted-foreground';\n  }\n  return undefined;\n}\n\ntype PlanTileProps = {\n  steps: PlanStatus[];\n  doneCount: number;\n};\n\nexport function PlanTile({ steps, doneCount }: PlanTileProps) {\n  return (\n    <Tile copy={TILES.plan}>\n      <div className='flex flex-col gap-2'>\n        <p className='text-muted-foreground flex items-baseline gap-1 px-2 text-xs tabular-nums'>\n          <MotionNumber value={doneCount} />\n          <span>of {PLAN_STEPS.length} done</span>\n        </p>\n        <ol aria-label='Plan' className='flex flex-col gap-0.5'>\n          {PLAN_STEPS.map((title, index) => {\n            const status = steps[index];\n\n            return (\n              <li\n                key={title}\n                className={cn(\n                  'flex h-8 items-center gap-2.5 rounded-lg px-2 text-[13px] transition-[background-color,box-shadow] duration-200',\n                  liftedOf(status)\n                )}\n              >\n                <span className='flex size-[18px] shrink-0 items-center justify-center'>\n                  <Swap swapKey={status}>\n                    <StepGlyph status={status} />\n                  </Swap>\n                </span>\n                <span\n                  className={cn(\n                    'min-w-0 flex-1 truncate transition-colors duration-200',\n                    mutedOf(status)\n                  )}\n                >\n                  <span className='sr-only'>{STATUS_WORD[status]}: </span>\n                  {title}\n                </span>\n              </li>\n            );\n          })}\n        </ol>\n      </div>\n    </Tile>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/features-04/plan-tile.tsx"
    },
    {
      "path": "registry/ndeko/blocks/features/features-04/prompt-tile.tsx",
      "content": "'use client';\n\nimport { pressedSolidOf } from '@/registry/ndeko/lib/demonstration';\nimport {\n  ArrowUpIcon,\n  CircleDashedIcon,\n  LoaderIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { DrawnCheck } from '@/registry/ndeko/ui/drawn-check';\nimport { Textarea } from '@/registry/ndeko/ui/textarea';\n\nimport { PLAN_STEPS, PROMPT, TILES } from './data';\nimport type { TrayStatus } from './session';\nimport { Tile } from './tile';\n\nconst TRAY_LINE: Record<TrayStatus, string> = {\n  idle: 'Ready for a prompt',\n  reading: 'Reading 3 files',\n  planned: `Plan ready, ${PLAN_STEPS.length} steps`,\n};\n\nfunction TrayGlyph({ tray }: { tray: TrayStatus }) {\n  if (tray === 'planned') {\n    return <DrawnCheck tone='success' entrance='draw' />;\n  }\n  if (tray === 'reading') {\n    return <LoaderIcon className='text-info-foreground size-4 animate-spin' />;\n  }\n  return <CircleDashedIcon className='size-4' />;\n}\n\ntype PromptTileProps = {\n  prompt: string;\n  tray: TrayStatus;\n  isSendPressed: boolean;\n  onType: (value: string) => void;\n  onSend: () => void;\n};\n\nexport function PromptTile({\n  prompt,\n  tray,\n  isSendPressed,\n  onType,\n  onSend,\n}: PromptTileProps) {\n  const isEmpty = prompt.trim() === '';\n  const line = TRAY_LINE[tray];\n\n  function sendOnEnter(event: React.KeyboardEvent<HTMLTextAreaElement>) {\n    const isEnter = event.key === 'Enter';\n    const isPlain = !event.shiftKey;\n    const hasText = !isEmpty;\n    if (isEnter && isPlain && hasText) {\n      event.preventDefault();\n      onSend();\n    }\n  }\n\n  return (\n    <Tile copy={TILES.prompt}>\n      <div className='flex flex-col gap-2'>\n        <div className='relative'>\n          <Textarea\n            rows={3}\n            value={prompt}\n            placeholder={PROMPT.placeholder}\n            aria-label={PROMPT.label}\n            onChange={(event) => onType(event.target.value)}\n            onKeyDown={sendOnEnter}\n            className='min-h-24 pe-12 text-[13px]'\n          />\n          <Button\n            type='button'\n            size='icon-sm'\n            aria-label='Send the prompt'\n            disabled={isEmpty}\n            onClick={onSend}\n            className={cn(\n              'absolute end-2 bottom-2',\n              pressedSolidOf(isSendPressed)\n            )}\n          >\n            <ArrowUpIcon />\n          </Button>\n        </div>\n        <p\n          aria-label='Status'\n          className='text-muted-foreground flex h-6 items-center px-1 text-xs'\n        >\n          <Swap swapKey={tray}>\n            <span className='flex items-center gap-1.5'>\n              <TrayGlyph tray={tray} />\n              <span>{line}</span>\n            </span>\n          </Swap>\n        </p>\n      </div>\n    </Tile>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/features-04/prompt-tile.tsx"
    },
    {
      "path": "registry/ndeko/blocks/features/features-04/tile.tsx",
      "content": "import { cn } from '@/registry/ndeko/lib/utils';\n\nimport type { TileCopy } from './data';\n\ntype TileProps = {\n  copy: TileCopy;\n  stageClassName?: string;\n  children: React.ReactNode;\n};\n\n/** The stage radius is the tile radius minus the padding between them, so the curves run parallel. */\nexport function Tile({ copy, stageClassName, children }: TileProps) {\n  return (\n    <article className='bg-card hairline-ring ring-border dark:bg-foreground/[0.03] flex min-w-0 flex-1 flex-col gap-4 rounded-2xl p-2 shadow-[0_1px_2px_rgb(0_0_0/0.04)]'>\n      <div\n        className={cn(\n          'bg-foreground/[0.04] relative isolate flex min-h-52 flex-1 flex-col justify-center rounded-[calc(var(--radius-2xl)-0.5rem)] p-4',\n          stageClassName\n        )}\n      >\n        {children}\n      </div>\n      <div className='flex flex-col gap-1 px-2 pb-2'>\n        <h3 className='text-sm font-medium'>{copy.title}</h3>\n        <p className='text-muted-foreground text-[13px] text-pretty'>\n          {copy.text}\n        </p>\n      </div>\n    </article>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/features-04/tile.tsx"
    },
    {
      "path": "registry/ndeko/blocks/features/features-04/session.ts",
      "content": "import type { SessionStep } from '@/registry/ndeko/hooks/use-session';\nimport { keyDelayOf, prefixesOf } from '@/registry/ndeko/lib/demonstration';\n\nimport { PLAN_STEPS, PROMPT_TEXT } from './data';\n\nexport type PlanStatus =\n  'upcoming' | 'running' | 'waiting' | 'done' | 'skipped';\n\nexport type TrayStatus = 'idle' | 'reading' | 'planned';\n\nexport type Approval = 'none' | 'waiting' | 'approved' | 'declined';\n\nexport type RunState = {\n  prompt: string;\n  tray: TrayStatus;\n  steps: PlanStatus[];\n  context: number;\n  cost: number;\n  approval: Approval;\n};\n\nexport type RunAction =\n  | { type: 'typed'; value: string }\n  | { type: 'sent' }\n  | { type: 'read' }\n  | { type: 'planned' }\n  | { type: 'advanced'; step: number; context: number; cost: number }\n  | { type: 'asked' }\n  | { type: 'approved' }\n  | { type: 'declined' };\n\ntype Step = SessionStep<RunState, RunAction>;\n\nconst LAST_STEP = PLAN_STEPS.length - 1;\n\nconst APPROVED_COST_USD = 0.014;\n\nconst APPROVED_CONTEXT_PERCENT = 8;\n\nfunction stepsOf(status: PlanStatus): PlanStatus[] {\n  return PLAN_STEPS.map(() => status);\n}\n\nexport const INITIAL: RunState = {\n  prompt: '',\n  tray: 'idle',\n  steps: stepsOf('upcoming'),\n  context: 0,\n  cost: 0,\n  approval: 'none',\n};\n\nfunction withStep(\n  steps: PlanStatus[],\n  index: number,\n  status: PlanStatus\n): PlanStatus[] {\n  return steps.map((current, position) => {\n    if (position === index) {\n      return status;\n    }\n    return current;\n  });\n}\n\nfunction planned(state: RunState): RunState {\n  const isNotStarted = state.steps[0] === 'upcoming';\n  if (!isNotStarted) {\n    return { ...state, tray: 'planned' };\n  }\n  const steps = withStep(state.steps, 0, 'running');\n  return { ...state, tray: 'planned', steps };\n}\n\nfunction advanced(\n  state: RunState,\n  step: number,\n  context: number,\n  cost: number\n): RunState {\n  let steps = withStep(state.steps, step, 'done');\n  const next = step + 1;\n  const isAutomatic = next < LAST_STEP;\n  const isUpcoming = state.steps[next] === 'upcoming';\n  if (isAutomatic && isUpcoming) {\n    steps = withStep(steps, next, 'running');\n  }\n  return { ...state, steps, context, cost };\n}\n\nfunction asked(state: RunState): RunState {\n  if (state.approval !== 'none') {\n    return state;\n  }\n  const steps = withStep(state.steps, LAST_STEP, 'waiting');\n  return { ...state, steps, approval: 'waiting' };\n}\n\nfunction approved(state: RunState): RunState {\n  if (state.approval !== 'waiting') {\n    return state;\n  }\n  const steps = withStep(state.steps, LAST_STEP, 'done');\n  return {\n    ...state,\n    steps,\n    approval: 'approved',\n    cost: state.cost + APPROVED_COST_USD,\n    context: state.context + APPROVED_CONTEXT_PERCENT,\n  };\n}\n\nfunction declined(state: RunState): RunState {\n  if (state.approval !== 'waiting') {\n    return state;\n  }\n  const steps = withStep(state.steps, LAST_STEP, 'skipped');\n  return { ...state, steps, approval: 'declined' };\n}\n\nexport function reducer(state: RunState, action: RunAction): RunState {\n  switch (action.type) {\n    case 'typed':\n      return { ...state, prompt: action.value };\n    case 'sent':\n      return { ...state, tray: 'reading' };\n    case 'read':\n      return { ...state, context: 18, cost: 0.012 };\n    case 'planned':\n      return planned(state);\n    case 'advanced':\n      return advanced(state, action.step, action.context, action.cost);\n    case 'asked':\n      return asked(state);\n    case 'approved':\n      return approved(state);\n    case 'declined':\n      return declined(state);\n  }\n}\n\nexport function doneCountOf(state: RunState) {\n  const done = state.steps.filter((status) => status === 'done');\n  return done.length;\n}\n\nconst KEY_MS = 38;\n\n/** How long the tray reads for a person who sends a prompt themselves. */\nexport const TRAY_READ_MS = 1400;\n\nfunction typing(text: string, startAfter: number): Step[] {\n  const prefixes = prefixesOf(text);\n  return prefixes.map((value, index) => ({\n    after: keyDelayOf(index, startAfter, KEY_MS),\n    by: 'demo',\n    action: { type: 'typed', value },\n  }));\n}\n\nfunction hasAnswered(state: RunState) {\n  return state.approval !== 'waiting';\n}\n\n/**\n * The agent works on its own clock: it reads, plans and ticks its steps. The prompt is typed and\n * the approval is answered by the demonstration until a person takes over, and the run waits for\n * them from then on.\n */\nexport const SCRIPT: Step[] = [\n  ...typing(PROMPT_TEXT, 700),\n  { after: 600, by: 'demo', press: 'send', action: { type: 'sent' } },\n  { after: 1100, action: { type: 'read' } },\n  { after: 900, action: { type: 'planned' } },\n  {\n    after: 1100,\n    action: { type: 'advanced', step: 0, context: 34, cost: 0.027 },\n  },\n  {\n    after: 1200,\n    action: { type: 'advanced', step: 1, context: 52, cost: 0.041 },\n  },\n  {\n    after: 1200,\n    action: { type: 'advanced', step: 2, context: 63, cost: 0.052 },\n  },\n  { after: 700, action: { type: 'asked' } },\n  {\n    after: 2600,\n    by: 'person',\n    press: 'approve',\n    action: { type: 'approved' },\n    isAnswered: hasAnswered,\n  },\n];\n\n/** Under reduced motion the run rests where it waits on a person. */\nexport const RESTING: RunState = {\n  prompt: PROMPT_TEXT,\n  tray: 'planned',\n  steps: ['done', 'done', 'done', 'waiting'],\n  context: 63,\n  cost: 0.052,\n  approval: 'waiting',\n};\n\nexport const LOOP_AFTER_MS = 4200;\n",
      "type": "registry:component",
      "target": "components/blocks/features-04/session.ts"
    },
    {
      "path": "registry/ndeko/blocks/features/features-04/data.ts",
      "content": "export const SECTION = {\n  label: 'What a run looks like',\n  title: 'Five parts of one agent run, working',\n  lead: 'Each tile is the control itself, following the same run: the prompt, the plan, the decision, the context and the cost.',\n  figures: 'Illustrative figures',\n};\n\nexport const PROMPT_TEXT = 'Reconcile March invoices against the bank export';\n\nexport const PROMPT = {\n  label: 'Ask Ledgerfinch',\n  placeholder: 'Describe the job in plain words',\n};\n\nexport const PLAN_STEPS: string[] = [\n  'Read the bank export',\n  'Match invoices to payments',\n  'Flag what does not match',\n  'Post the matches to the ledger',\n];\n\nexport const APPROVAL = {\n  title: 'Post 38 matches to the ledger',\n  detail: 'Writes to the March ledger. Nothing is posted until you answer.',\n};\n\nexport const CONTEXT_LIMIT_TOKENS = 32_000;\n\nexport const BUDGET_USD = 0.25;\n\nexport type TileCopy = {\n  title: string;\n  text: string;\n};\n\nexport const TILES = {\n  prompt: {\n    title: 'Ask in plain words',\n    text: 'The tray under the prompt says what the agent is reading before it plans.',\n  },\n  plan: {\n    title: 'See the plan tick',\n    text: 'Each step marks itself done, so you know where the run is without opening a log.',\n  },\n  approval: {\n    title: 'Decide before it writes',\n    text: 'Anything that changes your books waits for an answer first.',\n  },\n  context: {\n    title: 'Watch the context fill',\n    text: 'The ring shows how much the agent holds, so a long run holds no surprise.',\n  },\n  cost: {\n    title: 'Follow the cost',\n    text: 'The figure rolls with every call and stays under the budget you set.',\n  },\n} satisfies Record<string, TileCopy>;\n",
      "type": "registry:component",
      "target": "components/blocks/features-04/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "features"
  ],
  "type": "registry:block"
}