{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "application-12",
  "title": "Coding agent",
  "description": "A Kettlebrook coding agent: a task in the thread, the files it reads with their marks, a failing test whose output streams in the Tests tab, the fix written hunk by hunk in Diff, then the same output turning from failing to passing while the count rolls to 7 of 7, the checkout page before and after in Preview and a pull request that waits for Allow or Deny, over a footer with the branch, the tokens and the cost. Plug your agent into onSend, onApprove and onDeny.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/agent-run.json",
    "https://ui.ndekocode.dev/r/animated-size.json",
    "https://ui.ndekocode.dev/r/badge.json",
    "https://ui.ndekocode.dev/r/brand-logos.json",
    "https://ui.ndekocode.dev/r/brand-tile.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/call-status.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/company-mark.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/inline-sheet.json",
    "https://ui.ndekocode.dev/r/kbd.json",
    "https://ui.ndekocode.dev/r/live-duration.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/mesh-tile.json",
    "https://ui.ndekocode.dev/r/motion-number.json",
    "https://ui.ndekocode.dev/r/motion-presets.json",
    "https://ui.ndekocode.dev/r/motion-word-roll.json",
    "https://ui.ndekocode.dev/r/replay-button.json",
    "https://ui.ndekocode.dev/r/run-session.json",
    "https://ui.ndekocode.dev/r/segments.json",
    "https://ui.ndekocode.dev/r/spinner.json",
    "https://ui.ndekocode.dev/r/streamed-text.json",
    "https://ui.ndekocode.dev/r/tabs.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-follow-bottom.json",
    "https://ui.ndekocode.dev/r/use-is-narrow.json",
    "https://ui.ndekocode.dev/r/use-session.json",
    "https://ui.ndekocode.dev/r/use-timeouts.json",
    "https://ui.ndekocode.dev/r/utils.json",
    "https://ui.ndekocode.dev/r/words.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/templates/agent-workspaces/application-12/index.tsx",
      "content": "'use client';\n\nimport { useIsNarrow } from '@/registry/ndeko/hooks/use-is-narrow';\nimport { useSession } from '@/registry/ndeko/hooks/use-session';\nimport { useTimeouts } from '@/registry/ndeko/hooks/use-timeouts';\nimport { spokenUnless } from '@/registry/ndeko/lib/demonstration';\nimport { InlineSheet } from '@/registry/ndeko/ui/inline-sheet';\nimport { ClockGate } from '@/registry/ndeko/ui/live-duration';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\n\nimport { AppHeader } from './app-header';\nimport { Composer } from './composer';\nimport {\n  DECLINED_LINE,\n  OPENED_LINE,\n  PULL_REQUEST,\n  TEST_COUNT,\n  type PanelTab,\n} from './data';\nimport {\n  INITIAL,\n  isOver,\n  LOOP_AFTER_MS,\n  OPEN_MS,\n  reducer,\n  RESTING,\n  SCRIPT,\n  sendableTextOf,\n  type CodingState,\n  type Decision,\n  type PageVersion,\n  type Stage,\n} from './session';\nimport { StatusFooter } from './status-footer';\nimport { Thread } from './thread';\nimport { WorkPanel } from './work-panel';\n\nconst SESSION = {\n  reducer,\n  initial: INITIAL,\n  resting: RESTING,\n  script: SCRIPT,\n  loopAfter: LOOP_AFTER_MS,\n};\n\n/** The width of the `@3xl` container variant: under it the diff, the tests and the preview live in a sheet. */\nconst SHEET_BELOW_REM = 48;\n\nfunction placeholderOf(stage: Stage) {\n  if (stage === 'idle') {\n    return 'Describe a bug to fix';\n  }\n  if (stage === 'asking') {\n    return 'Allow or deny the request above';\n  }\n  if (isOver(stage)) {\n    return 'Ask for something else';\n  }\n  return 'Coder is working';\n}\n\n/** One line for each change a person cannot see at a glance: the two test results, the request and its outcome. */\nfunction announcementOf(state: CodingState) {\n  if (state.stage === 'asking') {\n    return `Coder asks to open the pull request ${PULL_REQUEST.title}. Allow or deny it`;\n  }\n  if (state.stage === 'opened') {\n    return OPENED_LINE;\n  }\n  if (state.stage === 'declined') {\n    return DECLINED_LINE;\n  }\n  if (state.testRun === 'passed') {\n    return `All ${TEST_COUNT} tests pass`;\n  }\n  if (state.testRun === 'failed') {\n    return `1 of ${TEST_COUNT} tests fails: the bug is reproduced`;\n  }\n  return '';\n}\n\n/** Nothing calls a network. A real agent plugs in here: the task a person sends, and their answer to the pull request. */\nexport type Application12Props = {\n  onSend?: (text: string) => void;\n  onApprove?: () => void;\n  onDeny?: () => void;\n};\n\nexport default function Application12({\n  onSend,\n  onApprove,\n  onDeny,\n}: Application12Props) {\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 isNarrow = useIsNarrow(ref, SHEET_BELOW_REM);\n  const { stage } = state;\n  const sendableText = sendableTextOf(state);\n  const canSend = sendableText !== null;\n  const canReplay = isFinished && !isAutoplaying;\n  const isSheetShown = isNarrow && state.isSheetOpen;\n  const announcement = announcementOf(state);\n  const message = spokenUnless(isAutoplaying, announcement);\n\n  function focusLater(selector: string) {\n    requestAnimationFrame(() => {\n      const target = ref.current?.querySelector<HTMLElement>(selector);\n      target?.focus();\n    });\n  }\n\n  function send() {\n    if (sendableText === null) {\n      return;\n    }\n    act({ type: 'sent' });\n    onSend?.(sendableText);\n  }\n\n  /** The two buttons leave with the request, so the focus goes to what replaces them: the line that says what was decided. */\n  function decide(decision: Decision) {\n    act({ type: 'decided', decision });\n    focusLater('[data-request]');\n    if (decision === 'denied') {\n      onDeny?.();\n      return;\n    }\n    schedule(() => act({ type: 'opened' }), OPEN_MS);\n    onApprove?.();\n  }\n\n  function openSheet() {\n    act({ type: 'sheet', isOpen: true });\n    focusLater('[data-sheet-close=\"work\"]');\n  }\n\n  function closeSheet() {\n    act({ type: 'sheet', isOpen: false });\n    focusLater('[data-work-open]');\n  }\n\n  function pickTab(tab: PanelTab) {\n    act({ type: 'tabPicked', tab });\n  }\n\n  /** A step of the thread points at its tab. On a narrow page that tab is in the sheet, which opens with it. */\n  function showTab(tab: PanelTab) {\n    pickTab(tab);\n    if (isNarrow) {\n      openSheet();\n    }\n  }\n\n  const panel = {\n    tab: state.tab,\n    hunksStarted: state.hunksStarted,\n    hunksDone: state.hunksDone,\n    testRun: state.testRun,\n    pageVersion: state.preview,\n    isActive: isInView,\n    onTabChange: pickTab,\n    onPageVersionChange: (view: PageVersion) =>\n      act({ type: 'previewed', view }),\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='relative flex h-dvh min-h-[40rem] flex-col overflow-hidden'>\n          <div inert={isSheetShown} className='flex min-h-0 flex-1 flex-col'>\n            <AppHeader\n              state={state}\n              canReplay={canReplay}\n              onReplay={restart}\n              onOpenWork={openSheet}\n            />\n            <div className='flex min-h-0 flex-1'>\n              <main className='flex min-w-0 flex-1 flex-col @3xl:w-[24rem] @3xl:flex-none @4xl:w-[27rem]'>\n                <Thread\n                  state={state}\n                  pressed={pressed}\n                  isActive={isInView}\n                  onShow={showTab}\n                  onDecide={decide}\n                />\n                <div className='mx-auto w-full max-w-2xl shrink-0 px-4 pb-4'>\n                  <Composer\n                    draft={state.draft}\n                    placeholder={placeholderOf(stage)}\n                    canSend={canSend}\n                    isSendPressed={pressed === 'send'}\n                    onDraftChange={(text) => act({ type: 'typed', text })}\n                    onSend={send}\n                  />\n                </div>\n              </main>\n              <aside\n                aria-label='Diff, tests and preview'\n                className='hidden min-w-0 flex-1 pe-3 pb-3 @3xl:flex'\n              >\n                <div className='bg-card hairline-ring ring-border dark:bg-foreground/[0.03] flex min-h-0 min-w-0 flex-1 rounded-xl p-4 shadow-[0_1px_2px_rgb(0_0_0/0.04)]'>\n                  {!isNarrow && <WorkPanel {...panel} className='w-full' />}\n                </div>\n              </aside>\n            </div>\n            <StatusFooter tokens={state.tokens} costUsd={state.costUsd} />\n          </div>\n\n          <InlineSheet\n            name='work'\n            label='Work of the agent'\n            closeLabel='Close the work panel'\n            side='bottom'\n            closer='grip'\n            isOpen={isSheetShown}\n            className='@3xl:hidden'\n            panelClassName='h-[80%] px-4 pb-4'\n            onClose={closeSheet}\n          >\n            {isNarrow && <WorkPanel {...panel} className='flex-1' />}\n          </InlineSheet>\n          <LiveRegion message={message} />\n        </div>\n      </div>\n    </ClockGate>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-12/index.tsx"
    },
    {
      "path": "registry/ndeko/templates/agent-workspaces/application-12/app-header.tsx",
      "content": "'use client';\n\nimport { WordRoll } from '@/components/core/word-roll';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { CompanyMark } from '@/registry/ndeko/ui/company-mark';\nimport { ReplayButton } from '@/registry/ndeko/ui/replay-button';\n\nimport { REPOSITORY, type StepId } from './data';\nimport type { CodingState, Stage } from './session';\n\nconst WORKING_WORD: Record<StepId, string> = {\n  read: 'Reading the code',\n  reproduce: 'Reproducing the bug',\n  edit: 'Writing the fix',\n  verify: 'Running the tests',\n  preview: 'Checking the page',\n};\n\nconst STAGE_WORD: Record<Stage, string> = {\n  idle: 'Ready',\n  working: 'Working',\n  answering: 'Answering',\n  asking: 'Waiting on you',\n  opening: 'Opening the pull request',\n  opened: 'Done',\n  declined: 'Done',\n};\n\nconst WORKING_WORDS = Object.values(WORKING_WORD);\n\nconst STAGE_WORDS = Object.values(STAGE_WORD);\n\nconst STATUS_WORDS = [...WORKING_WORDS, ...STAGE_WORDS];\n\nconst STATUS_DOT: Record<Stage, string> = {\n  idle: 'bg-muted-foreground/45',\n  working: 'bg-info',\n  answering: 'bg-info',\n  asking: 'bg-warning',\n  opening: 'bg-info',\n  opened: 'bg-success',\n  declined: 'bg-success',\n};\n\nconst LIVE_STAGES: Stage[] = ['working', 'answering', 'opening'];\n\nfunction statusOf(state: CodingState) {\n  if (state.stage !== 'working') {\n    return STAGE_WORD[state.stage];\n  }\n  const running = state.steps.find((run) => run.status === 'running');\n  if (!running) {\n    return STAGE_WORD.working;\n  }\n  return WORKING_WORD[running.id];\n}\n\nfunction pulseOf(stage: Stage) {\n  if (LIVE_STAGES.includes(stage)) {\n    return 'animate-pulse';\n  }\n  return undefined;\n}\n\ntype AppHeaderProps = {\n  state: CodingState;\n  canReplay: boolean;\n  onReplay: () => void;\n  onOpenWork: () => void;\n};\n\nexport function AppHeader({\n  state,\n  canReplay,\n  onReplay,\n  onOpenWork,\n}: AppHeaderProps) {\n  const { stage } = state;\n\n  return (\n    <header className='flex shrink-0 flex-wrap items-center gap-x-3 gap-y-2 px-4 py-2.5'>\n      <div className='flex min-w-40 flex-1 items-center gap-2.5'>\n        <CompanyMark seed={REPOSITORY.owner} size='lg' />\n        <div className='flex min-w-0 flex-col leading-tight'>\n          <h1 className='truncate text-sm font-medium'>\n            {REPOSITORY.owner}\n            <span className='text-muted-foreground font-normal'>\n              {' '}\n              / {REPOSITORY.name}\n            </span>\n          </h1>\n          <p className='text-muted-foreground flex items-center gap-1.5 text-xs'>\n            <span\n              aria-hidden='true'\n              className={cn(\n                'size-1.5 shrink-0 rounded-full transition-colors duration-200',\n                STATUS_DOT[stage],\n                pulseOf(stage)\n              )}\n            />\n            <WordRoll text={statusOf(state)} labels={STATUS_WORDS} />\n          </p>\n        </div>\n      </div>\n      <div className='flex items-center gap-2'>\n        <ReplayButton isShown={canReplay} onReplay={onReplay} label='Replay' />\n        <Button\n          type='button'\n          variant='outline'\n          size='sm'\n          data-work-open\n          aria-haspopup='dialog'\n          onClick={onOpenWork}\n          className='@3xl:hidden'\n        >\n          Diff and tests\n        </Button>\n      </div>\n    </header>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-12/app-header.tsx"
    },
    {
      "path": "registry/ndeko/templates/agent-workspaces/application-12/thread.tsx",
      "content": "'use client';\n\nimport { useFollowBottom } from '@/registry/ndeko/hooks/use-follow-bottom';\nimport { seriesColorOf } from '@/registry/ndeko/lib/agent-run';\nimport { MeshTile } from '@/registry/ndeko/ui/mesh-tile';\nimport { StreamedText } from '@/registry/ndeko/ui/streamed-text';\n\nimport { ANSWER, CODER, FOLLOW_UP_REPLY, type PanelTab } from './data';\nimport { PullRequest } from './pull-request';\nimport {\n  ANSWER_WORD_MS,\n  hasReached,\n  type CodingState,\n  type Decision,\n} from './session';\nimport { WorkSteps } from './work-steps';\n\nfunction CoderTile() {\n  const color = seriesColorOf(CODER.series);\n\n  return <MeshTile seed={CODER.name} color={color} size='lg' />;\n}\n\nfunction PersonBubble({ text }: { text: string }) {\n  return (\n    <p className='bg-foreground/[0.06] max-w-[85%] self-end rounded-2xl rounded-ee-md px-3.5 py-2 text-sm leading-relaxed'>\n      {text}\n    </p>\n  );\n}\n\nfunction FollowUp({ text }: { text: string }) {\n  return (\n    <>\n      <PersonBubble text={text} />\n      <div className='flex items-start gap-2.5'>\n        <CoderTile />\n        <p className='text-muted-foreground min-w-0 flex-1 pt-1 text-sm leading-relaxed'>\n          {FOLLOW_UP_REPLY}\n        </p>\n      </div>\n    </>\n  );\n}\n\ntype ThreadProps = {\n  state: CodingState;\n  pressed: string | null;\n  isActive: boolean;\n  onShow: (tab: PanelTab) => void;\n  onDecide: (decision: Decision) => void;\n};\n\nexport function Thread({\n  state,\n  pressed,\n  isActive,\n  onShow,\n  onDecide,\n}: ThreadProps) {\n  const { scrollerRef, contentRef, updatePinned } = useFollowBottom();\n  const { stage, task } = state;\n  const hasTask = task !== null;\n  const showsAnswer = hasReached(stage, 'answering');\n  const showsRequest = hasReached(stage, 'asking');\n\n  return (\n    <div\n      ref={scrollerRef}\n      onScroll={updatePinned}\n      className='min-h-0 flex-1 overflow-y-auto'\n    >\n      <div\n        ref={contentRef}\n        className='mx-auto flex min-h-full w-full max-w-2xl flex-col gap-5 px-4 py-5'\n      >\n        {!hasTask && (\n          <p className='text-muted-foreground m-auto max-w-xs text-center text-[13px] leading-relaxed'>\n            Describe a bug. The agent reads the code, proves the bug with a\n            failing test, fixes it and asks before it opens a pull request.\n          </p>\n        )}\n        {task && <PersonBubble text={task} />}\n        {hasTask && (\n          <div className='flex items-start gap-2.5'>\n            <CoderTile />\n            <div className='flex min-w-0 flex-1 flex-col gap-3 pt-1'>\n              <span className='sr-only'>{CODER.name}</span>\n              <WorkSteps\n                steps={state.steps}\n                filesRead={state.filesRead}\n                hunksDone={state.hunksDone}\n                isWorking={stage === 'working'}\n                onShow={onShow}\n              />\n              {showsAnswer && (\n                <p className='text-sm leading-relaxed'>\n                  <StreamedText\n                    text={ANSWER}\n                    isStreaming={stage === 'answering'}\n                    isActive={isActive}\n                    wordMs={ANSWER_WORD_MS}\n                  />\n                </p>\n              )}\n              {showsRequest && (\n                <PullRequest\n                  stage={stage}\n                  pressed={pressed}\n                  onDecide={onDecide}\n                />\n              )}\n            </div>\n          </div>\n        )}\n        {state.followUps.map((text, index) => (\n          <FollowUp key={index} text={text} />\n        ))}\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-12/thread.tsx"
    },
    {
      "path": "registry/ndeko/templates/agent-workspaces/application-12/work-steps.tsx",
      "content": "'use client';\n\nimport { useId, useState } from 'react';\n\nimport {\n  CheckIcon,\n  ChevronDownIcon,\n  FileIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { countOf } from '@/registry/ndeko/lib/words';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { CallStatusMark } from '@/registry/ndeko/ui/call-status';\nimport { Fold, Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { LiveDuration } from '@/registry/ndeko/ui/live-duration';\n\nimport {\n  CAUSE_FILE,\n  FILES,\n  HUNKS,\n  stepOf,\n  type Hunk,\n  type PanelTab,\n  type RepoFile,\n  type WorkStep,\n} from './data';\nimport { ChangeCounts, ModifiedTile } from './diff-view';\nimport type { StepRun } from './session';\n\nconst SHOW_LABEL: Record<PanelTab, string> = {\n  diff: 'Open the diff',\n  tests: 'Open the tests',\n  preview: 'Open the preview',\n};\n\ntype FileMark = 'read' | 'cause' | 'modified';\n\n/** A file wears the strongest thing known about it: changed, then where the bug is, then read. */\nfunction markOf(\n  file: RepoFile,\n  hunks: Hunk[],\n  isCauseKnown: boolean\n): FileMark {\n  if (hunks.length > 0) {\n    return 'modified';\n  }\n  const isCause = file.id === CAUSE_FILE;\n  if (isCause && isCauseKnown) {\n    return 'cause';\n  }\n  return 'read';\n}\n\nfunction pathPartsOf(path: string) {\n  const slash = path.lastIndexOf('/');\n  const nameStart = slash + 1;\n  const folder = path.slice(0, nameStart);\n  const name = path.slice(nameStart);\n  return { folder, name };\n}\n\ntype FileRowProps = {\n  file: RepoFile;\n  hunksDone: number;\n  isCauseKnown: boolean;\n};\n\nfunction FileRow({ file, hunksDone, isCauseKnown }: FileRowProps) {\n  const written = HUNKS.slice(0, hunksDone);\n  const hunks = written.filter((hunk) => hunk.fileId === file.id);\n  const mark = markOf(file, hunks, isCauseKnown);\n  const { folder, name } = pathPartsOf(file.path);\n\n  return (\n    <li className='flex items-start gap-2 py-1 transition-[opacity,translate] duration-300 ease-(--ease-out-strong) starting:translate-y-1 starting:opacity-0'>\n      <FileIcon className='text-muted-foreground mt-0.5 size-3.5 shrink-0' />\n      <span className='flex min-w-0 flex-1 flex-col'>\n        <span className='truncate font-mono text-xs'>\n          <span className='text-muted-foreground'>{folder}</span>\n          {name}\n        </span>\n        <span className='text-muted-foreground text-xs leading-4'>\n          {file.finding}\n        </span>\n      </span>\n      <Swap swapKey={mark} className='h-5 shrink-0'>\n        {mark === 'read' && (\n          <CheckIcon className='text-muted-foreground size-3.5' />\n        )}\n        {mark === 'read' && <span className='sr-only'>Read</span>}\n        {mark === 'cause' && <Badge variant='warning'>Cause</Badge>}\n        {mark === 'modified' && (\n          <span className='flex items-center gap-1.5'>\n            <ChangeCounts hunks={hunks} />\n            <ModifiedTile />\n          </span>\n        )}\n      </Swap>\n    </li>\n  );\n}\n\nfunction chevronTurnOf(isOpen: boolean) {\n  if (isOpen) {\n    return 'rotate-180';\n  }\n  return 'rotate-0';\n}\n\ntype FileListProps = {\n  filesRead: number;\n  hunksDone: number;\n  isCauseKnown: boolean;\n  isWorking: boolean;\n};\n\n/** Open while the agent works, so each mark is seen as it changes, then folded into one line. */\nfunction FileList({\n  filesRead,\n  hunksDone,\n  isCauseKnown,\n  isWorking,\n}: FileListProps) {\n  const [openChoice, setOpenChoice] = useState<boolean | null>(null);\n  const [wasWorking, setWasWorking] = useState(isWorking);\n  const listId = useId();\n  const files = FILES.slice(0, filesRead);\n\n  if (wasWorking !== isWorking) {\n    setWasWorking(isWorking);\n    setOpenChoice(null);\n  }\n\n  const isOpen = openChoice ?? isWorking;\n\n  function toggle() {\n    setOpenChoice(!isOpen);\n  }\n\n  return (\n    <div className='bg-foreground/[0.03] dark:bg-foreground/[0.05] mt-1.5 rounded-lg p-1'>\n      <button\n        type='button'\n        aria-expanded={isOpen}\n        aria-controls={listId}\n        onClick={toggle}\n        className='hover:bg-foreground/[0.04] focus-visible:ring-ring/25 text-muted-foreground flex h-6 w-full cursor-pointer items-center gap-1.5 rounded-md px-1.5 text-start text-xs outline-none focus-visible:ring-[3px]'\n      >\n        <span className='min-w-0 flex-1 truncate tabular-nums'>\n          {countOf(filesRead, 'file')} read\n        </span>\n        <ChevronDownIcon\n          className={cn(\n            'size-3.5 shrink-0 transition-transform duration-200 ease-(--ease-out-strong)',\n            chevronTurnOf(isOpen)\n          )}\n        />\n      </button>\n      <Fold open={isOpen} id={listId}>\n        <ul aria-label='Files read' className='flex flex-col px-1.5 pb-0.5'>\n          {files.map((file) => (\n            <FileRow\n              key={file.id}\n              file={file}\n              hunksDone={hunksDone}\n              isCauseKnown={isCauseKnown}\n            />\n          ))}\n        </ul>\n      </Fold>\n    </div>\n  );\n}\n\nfunction sublineOf(step: WorkStep, run: StepRun) {\n  if (run.status === 'done') {\n    return step.doneSummary;\n  }\n  return step.detail;\n}\n\ntype StepRowProps = FileListProps & {\n  run: StepRun;\n  isLast: boolean;\n  onShow: (tab: PanelTab) => void;\n};\n\nfunction StepRow({ run, isLast, onShow, ...fileList }: StepRowProps) {\n  const step = stepOf(run.id);\n  const isRunning = run.status === 'running';\n  const showsFiles = run.id === 'read' && fileList.filesRead > 0;\n  const shownInTab = step.shownInTab;\n\n  return (\n    <li className='relative flex gap-2.5 pb-3 transition-opacity duration-300 last:pb-0 starting:opacity-0'>\n      {!isLast && (\n        <span\n          aria-hidden='true'\n          className='bg-border absolute start-2 top-6 bottom-1 w-px'\n        />\n      )}\n      <span className='flex h-5 shrink-0 items-center'>\n        <CallStatusMark status={run.status} />\n      </span>\n      <div className='flex min-w-0 flex-1 flex-col'>\n        <p className='flex h-5 items-center gap-2 text-[13px]'>\n          <span className='min-w-0 flex-1 truncate font-medium'>\n            {step.title}\n          </span>\n          <LiveDuration\n            item={run}\n            isRunning={isRunning}\n            className='text-muted-foreground w-10 shrink-0 text-end text-xs'\n          />\n        </p>\n        <div className='flex items-start gap-2'>\n          <p\n            key={run.status}\n            className='text-muted-foreground min-w-0 flex-1 text-xs leading-5 transition-opacity duration-300 starting:opacity-0'\n          >\n            {sublineOf(step, run)}\n          </p>\n          {shownInTab && (\n            <Button\n              type='button'\n              variant='ghost'\n              size='sm'\n              onClick={() => onShow(shownInTab)}\n              className='text-muted-foreground -me-2 h-6 shrink-0 px-2'\n            >\n              {SHOW_LABEL[shownInTab]}\n            </Button>\n          )}\n        </div>\n        {showsFiles && <FileList {...fileList} />}\n      </div>\n    </li>\n  );\n}\n\ntype WorkStepsProps = {\n  steps: StepRun[];\n  filesRead: number;\n  hunksDone: number;\n  isWorking: boolean;\n  onShow: (tab: PanelTab) => void;\n};\n\n/** Steps arrive at the end of the list, where nothing sits under them yet, so a fade is enough. */\nexport function WorkSteps({\n  steps,\n  filesRead,\n  hunksDone,\n  isWorking,\n  onShow,\n}: WorkStepsProps) {\n  const lastIndex = steps.length - 1;\n  const readStep = steps.find((run) => run.id === 'read');\n  const isCauseKnown = readStep?.status === 'done';\n\n  return (\n    <ol aria-label='What the agent did' className='flex flex-col'>\n      {steps.map((run, index) => (\n        <StepRow\n          key={run.id}\n          run={run}\n          isLast={index === lastIndex}\n          filesRead={filesRead}\n          hunksDone={hunksDone}\n          isCauseKnown={isCauseKnown}\n          isWorking={isWorking}\n          onShow={onShow}\n        />\n      ))}\n    </ol>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-12/work-steps.tsx"
    },
    {
      "path": "registry/ndeko/templates/agent-workspaces/application-12/pull-request.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport { useId } from 'react';\n\nimport { pressedSolidOf } from '@/registry/ndeko/lib/demonstration';\nimport {\n  ArrowRightIcon,\n  CircleXIcon,\n  GitBranchIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { fadePresence } from '@/registry/ndeko/lib/motion-presets';\nimport { countOf } from '@/registry/ndeko/lib/words';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { BrandTile } from '@/registry/ndeko/ui/brand-tile';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { DrawnCheck } from '@/registry/ndeko/ui/drawn-check';\nimport { Kbd } from '@/registry/ndeko/ui/kbd';\nimport { Spinner } from '@/registry/ndeko/ui/spinner';\n\nimport {\n  DECLINED_LINE,\n  FILES,\n  HUNKS,\n  OPENED_LINE,\n  PULL_REQUEST,\n  REPOSITORY,\n  type RepoFile,\n} from './data';\nimport { ChangeCounts, ModifiedTile } from './diff-view';\nimport type { Decision, Stage } from './session';\n\nfunction isChanged(file: RepoFile) {\n  return HUNKS.some((hunk) => hunk.fileId === file.id);\n}\n\nconst CHANGED_FILES = FILES.filter(isChanged);\n\nfunction ChangedFile({ file }: { file: RepoFile }) {\n  const hunks = HUNKS.filter((hunk) => hunk.fileId === file.id);\n\n  return (\n    <li className='flex items-center gap-2'>\n      <ModifiedTile />\n      <span className='min-w-0 flex-1 truncate font-mono text-xs'>\n        {file.path}\n      </span>\n      <ChangeCounts hunks={hunks} />\n    </li>\n  );\n}\n\ntype RequestBodyProps = {\n  pressed: string | null;\n  onDecide: (decision: Decision) => void;\n};\n\nfunction RequestBody({ pressed, onDecide }: RequestBodyProps) {\n  const titleId = useId();\n  const keysId = useId();\n\n  function allow() {\n    onDecide('approved');\n  }\n\n  function deny() {\n    onDecide('denied');\n  }\n\n  function decideFromKeys(event: React.KeyboardEvent<HTMLDivElement>) {\n    if (event.key === 'Escape') {\n      event.preventDefault();\n      deny();\n      return;\n    }\n    const isOnCard = event.target === event.currentTarget;\n    const isEnter = event.key === 'Enter';\n    if (isEnter && isOnCard) {\n      event.preventDefault();\n      allow();\n    }\n  }\n\n  return (\n    <div\n      role='group'\n      tabIndex={0}\n      aria-labelledby={titleId}\n      aria-describedby={keysId}\n      onKeyDown={decideFromKeys}\n      className='focus-visible:ring-ring/25 flex flex-col gap-3 rounded-xl p-3 outline-none focus-visible:ring-[3px] focus-visible:ring-inset'\n    >\n      <div className='flex items-center gap-2.5'>\n        <BrandTile brand='github' size='lg' title='GitHub' />\n        <div className='flex min-w-0 flex-1 flex-col leading-tight'>\n          <h2 id={titleId} className='text-sm font-medium'>\n            Open a pull request\n          </h2>\n          <span className='text-muted-foreground truncate text-xs'>\n            {PULL_REQUEST.title}\n          </span>\n        </div>\n        <Badge variant='warning' className='hidden @md:inline-flex'>\n          Waiting on you\n        </Badge>\n      </div>\n      <p className='flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-1 font-mono text-xs'>\n        <GitBranchIcon className='text-muted-foreground size-3.5 shrink-0' />\n        <span className='min-w-0 truncate'>{REPOSITORY.branch}</span>\n        <ArrowRightIcon className='text-muted-foreground size-3 shrink-0' />\n        <span className='sr-only'>into</span>\n        <span>{REPOSITORY.base}</span>\n      </p>\n      <div className='bg-foreground/[0.04] flex flex-col gap-2 rounded-lg p-2.5'>\n        <span className='text-muted-foreground text-xs'>\n          {countOf(CHANGED_FILES.length, 'file')} changed\n        </span>\n        <ul aria-label='Files changed' className='flex flex-col gap-1.5'>\n          {CHANGED_FILES.map((file) => (\n            <ChangedFile key={file.id} file={file} />\n          ))}\n        </ul>\n      </div>\n      <div className='flex flex-wrap items-center gap-2'>\n        <Button\n          type='button'\n          size='sm'\n          onClick={allow}\n          className={pressedSolidOf(pressed === 'allow')}\n        >\n          Allow\n          <Kbd className='ms-0.5'>Enter</Kbd>\n        </Button>\n        <Button type='button' size='sm' variant='outline' onClick={deny}>\n          Deny\n          <Kbd className='ms-0.5'>Esc</Kbd>\n        </Button>\n        <span id={keysId} className='sr-only'>\n          Enter allows, Escape denies\n        </span>\n      </div>\n    </div>\n  );\n}\n\nfunction ResultGlyph({ stage }: { stage: Stage }) {\n  if (stage === 'opening') {\n    return <Spinner aria-hidden='true' />;\n  }\n  if (stage === 'declined') {\n    return <CircleXIcon className='text-muted-foreground size-4 shrink-0' />;\n  }\n  return <DrawnCheck tone='success' entrance='draw' />;\n}\n\nfunction resultLineOf(stage: Stage) {\n  if (stage === 'opening') {\n    return 'Opening the pull request';\n  }\n  if (stage === 'declined') {\n    return DECLINED_LINE;\n  }\n  return OPENED_LINE;\n}\n\nfunction ResultLine({ stage }: { stage: Stage }) {\n  return (\n    <div className='flex min-h-11 items-start gap-2.5 p-3 text-[13px] leading-5'>\n      <Swap swapKey={stage} className='mt-px'>\n        <ResultGlyph stage={stage} />\n      </Swap>\n      <p\n        key={stage}\n        className='min-w-0 transition-opacity duration-300 starting:opacity-0'\n      >\n        {resultLineOf(stage)}\n      </p>\n    </div>\n  );\n}\n\nfunction viewKeyOf(isAsking: boolean) {\n  if (isAsking) {\n    return 'request';\n  }\n  return 'result';\n}\n\ntype PullRequestProps = RequestBodyProps & {\n  stage: Stage;\n};\n\n/** The request resizes into one line that keeps a trace of what the person decided. */\nexport function PullRequest({ stage, pressed, onDecide }: PullRequestProps) {\n  const fade = fadePresence();\n  const isAsking = stage === 'asking';\n\n  return (\n    <section\n      data-request\n      tabIndex={-1}\n      aria-label='Request to open a pull request'\n      className='bg-card hairline-ring ring-border dark:bg-foreground/[0.04] overflow-hidden rounded-xl shadow-[0_1px_2px_rgb(0_0_0/0.04)] transition-opacity duration-300 outline-none starting:opacity-0'\n    >\n      <AnimatedSize>\n        <AnimatePresence initial={false} mode='popLayout'>\n          <motion.div key={viewKeyOf(isAsking)} {...fade}>\n            {isAsking && <RequestBody pressed={pressed} onDecide={onDecide} />}\n            {!isAsking && <ResultLine stage={stage} />}\n          </motion.div>\n        </AnimatePresence>\n      </AnimatedSize>\n    </section>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-12/pull-request.tsx"
    },
    {
      "path": "registry/ndeko/templates/agent-workspaces/application-12/composer.tsx",
      "content": "'use client';\n\nimport { pressedSolidOf } from '@/registry/ndeko/lib/demonstration';\nimport { ArrowUpIcon } from '@/registry/ndeko/lib/icons';\nimport { Button } from '@/registry/ndeko/ui/button';\n\nfunction isSendKey(event: React.KeyboardEvent<HTMLTextAreaElement>) {\n  const isPlainEnter = event.key === 'Enter' && !event.shiftKey;\n  return isPlainEnter && !event.nativeEvent.isComposing;\n}\n\ntype ComposerProps = {\n  draft: string;\n  placeholder: string;\n  canSend: boolean;\n  isSendPressed: boolean;\n  onDraftChange: (text: string) => void;\n  onSend: () => void;\n};\n\nexport function Composer({\n  draft,\n  placeholder,\n  canSend,\n  isSendPressed,\n  onDraftChange,\n  onSend,\n}: ComposerProps) {\n  function handleKeys(event: React.KeyboardEvent<HTMLTextAreaElement>) {\n    if (!isSendKey(event)) {\n      return;\n    }\n    event.preventDefault();\n    if (canSend) {\n      onSend();\n    }\n  }\n\n  return (\n    <div className='bg-card hairline-ring ring-foreground/12 has-[textarea:focus-visible]:ring-ring/25 dark:bg-foreground/[0.04] dark:ring-foreground/15 flex items-end gap-2 rounded-2xl p-2 shadow-[0_1px_2px_rgb(0_0_0/0.05)] transition-[box-shadow] duration-150 has-[textarea:focus-visible]:ring-[3px]'>\n      <textarea\n        value={draft}\n        rows={1}\n        aria-label='Task for the coder'\n        placeholder={placeholder}\n        onChange={(event) => onDraftChange(event.target.value)}\n        onKeyDown={handleKeys}\n        className='placeholder:text-muted-foreground/75 field-sizing-content max-h-[6lh] min-h-8 flex-1 resize-none bg-transparent px-1.5 py-1.5 text-base leading-normal outline-none md:text-[13px]'\n      />\n      <Button\n        type='button'\n        size='icon'\n        aria-label='Send the task'\n        disabled={!canSend}\n        onClick={onSend}\n        className={pressedSolidOf(isSendPressed)}\n      >\n        <ArrowUpIcon />\n      </Button>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-12/composer.tsx"
    },
    {
      "path": "registry/ndeko/templates/agent-workspaces/application-12/work-panel.tsx",
      "content": "'use client';\n\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Tabs, TabsList, TabsPanel, TabsTab } from '@/registry/ndeko/ui/tabs';\n\nimport type { PanelTab } from './data';\nimport { DiffView } from './diff-view';\nimport { PreviewView } from './preview-view';\nimport type { PageVersion, TestRun } from './session';\nimport { TestsView } from './tests-view';\n\nconst TABS: PanelTab[] = ['diff', 'tests', 'preview'];\n\ntype RunMark = 'none' | 'failing' | 'passing';\n\nconst RUN_DOT: Record<RunMark, string> = {\n  none: 'hidden',\n  failing: 'bg-destructive',\n  passing: 'bg-success',\n};\n\nconst RUN_WORD: Record<RunMark, string> = {\n  none: '',\n  failing: ', failing',\n  passing: ', passing',\n};\n\n/** While the second run streams, the tab still says what the first one found. */\nfunction runMarkOf(testRun: TestRun): RunMark {\n  if (testRun === 'passed') {\n    return 'passing';\n  }\n  const hasFailed = testRun === 'failed' || testRun === 'passing';\n  if (hasFailed) {\n    return 'failing';\n  }\n  return 'none';\n}\n\nexport type WorkPanelProps = {\n  tab: PanelTab;\n  hunksStarted: number;\n  hunksDone: number;\n  testRun: TestRun;\n  pageVersion: PageVersion;\n  isActive: boolean;\n  onTabChange: (tab: PanelTab) => void;\n  onPageVersionChange: (version: PageVersion) => void;\n  className?: string;\n};\n\nexport function WorkPanel({\n  tab,\n  hunksStarted,\n  hunksDone,\n  testRun,\n  pageVersion,\n  isActive,\n  onTabChange,\n  onPageVersionChange,\n  className,\n}: WorkPanelProps) {\n  const runMark = runMarkOf(testRun);\n  const hasHunks = hunksStarted > 0;\n\n  function changeTab(next: unknown) {\n    const found = TABS.find((candidate) => candidate === next);\n    if (found) {\n      onTabChange(found);\n    }\n  }\n\n  return (\n    <Tabs\n      value={tab}\n      onValueChange={changeTab}\n      className={cn('min-h-0 gap-3', className)}\n    >\n      <TabsList\n        variant='segmented'\n        aria-label='What the agent produced'\n        className='shrink-0'\n      >\n        <TabsTab value='diff'>\n          Diff\n          {hasHunks && (\n            <span className='text-muted-foreground text-xs tabular-nums'>\n              {hunksStarted}\n              <span className='sr-only'> hunks</span>\n            </span>\n          )}\n        </TabsTab>\n        <TabsTab value='tests'>\n          Tests\n          <span\n            className={cn(\n              'size-1.5 rounded-full transition-colors duration-500',\n              RUN_DOT[runMark]\n            )}\n          >\n            <span className='sr-only'>{RUN_WORD[runMark]}</span>\n          </span>\n        </TabsTab>\n        <TabsTab value='preview'>Preview</TabsTab>\n      </TabsList>\n      <TabsPanel value='diff' className='flex min-h-0 flex-col'>\n        <DiffView\n          hunksStarted={hunksStarted}\n          hunksDone={hunksDone}\n          isActive={isActive}\n        />\n      </TabsPanel>\n      <TabsPanel value='tests' className='flex min-h-0 flex-col'>\n        <TestsView testRun={testRun} isActive={isActive} />\n      </TabsPanel>\n      <TabsPanel value='preview' className='flex min-h-0 flex-col'>\n        <PreviewView\n          version={pageVersion}\n          canCompare={testRun === 'passed'}\n          onVersionChange={onPageVersionChange}\n        />\n      </TabsPanel>\n    </Tabs>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-12/work-panel.tsx"
    },
    {
      "path": "registry/ndeko/templates/agent-workspaces/application-12/diff-view.tsx",
      "content": "'use client';\n\nimport { useFollowBottom } from '@/registry/ndeko/hooks/use-follow-bottom';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport {\n  inkClassOf,\n  shownCountOf,\n  useRevealedCount,\n} from '@/registry/ndeko/ui/streamed-text';\n\nimport {\n  changesOf,\n  fileOf,\n  headerOf,\n  HUNKS,\n  type DiffLine,\n  type Hunk,\n  type LineKind,\n} from './data';\nimport { LINE_MS } from './session';\n\nconst LINE_TONE: Record<LineKind, string> = {\n  same: '',\n  removed: 'bg-destructive/10',\n  added: 'bg-success/10',\n};\n\nconst SIGN: Record<LineKind, string> = {\n  same: ' ',\n  removed: '-',\n  added: '+',\n};\n\nconst SIGN_TONE: Record<LineKind, string> = {\n  same: 'text-muted-foreground',\n  removed: 'text-destructive-ink',\n  added: 'text-success-foreground',\n};\n\nconst SPOKEN_KIND: Record<LineKind, string> = {\n  same: '',\n  removed: 'Removed: ',\n  added: 'Added: ',\n};\n\nexport function ChangeCounts({ hunks }: { hunks: Hunk[] }) {\n  const { additions, deletions } = changesOf(hunks);\n\n  return (\n    <span className='flex shrink-0 gap-1.5 font-mono text-xs tabular-nums'>\n      <span className='text-success-foreground'>+{additions}</span>\n      <span className='text-destructive-ink'>-{deletions}</span>\n    </span>\n  );\n}\n\nexport function ModifiedTile() {\n  return (\n    <span className='chip-3d inline-flex size-5 shrink-0 items-center justify-center rounded-[5px] font-mono text-[11px] font-semibold [--chip:var(--info)]'>\n      <span aria-hidden='true'>M</span>\n      <span className='sr-only'>Modified</span>\n    </span>\n  );\n}\n\ntype CodeLineProps = {\n  line: DiffLine;\n  inkClass: string | undefined;\n};\n\nfunction CodeLine({ line, inkClass }: CodeLineProps) {\n  return (\n    <div\n      className={cn(\n        'flex min-h-5 items-stretch pe-3 font-mono text-xs leading-5',\n        LINE_TONE[line.kind],\n        inkClass\n      )}\n    >\n      <span\n        aria-hidden='true'\n        className={cn(\n          'w-6 shrink-0 text-center select-none',\n          SIGN_TONE[line.kind]\n        )}\n      >\n        {SIGN[line.kind]}\n      </span>\n      <span className='sr-only'>{SPOKEN_KIND[line.kind]}</span>\n      <code className='whitespace-pre'>{line.text}</code>\n    </div>\n  );\n}\n\ntype HunkLinesProps = {\n  hunk: Hunk;\n  isStreaming: boolean;\n  isActive: boolean;\n};\n\n/**\n * Only the lines of the hunk being written re-render. Each line keeps its place before it is\n * written, so a hunk has its final height from its first line.\n */\nfunction HunkLines({ hunk, isStreaming, isActive }: HunkLinesProps) {\n  const total = hunk.lines.length;\n  const isRunning = isStreaming && isActive;\n  const count = useRevealedCount(total, isRunning, LINE_MS);\n  const shown = shownCountOf(isStreaming, count, total);\n\n  return (\n    <div className='flex w-max min-w-full flex-col py-1'>\n      {hunk.lines.map((line, index) => {\n        const isShown = index < shown;\n        return (\n          <CodeLine\n            key={index}\n            line={line}\n            inkClass={inkClassOf(isStreaming, isShown)}\n          />\n        );\n      })}\n    </div>\n  );\n}\n\n/** A hunk rises in while the agent writes it. Coming back to the tab shows the hunks already there, still. */\nfunction arrivalOf(isStreaming: boolean) {\n  if (isStreaming) {\n    return 'transition-[opacity,translate] duration-300 ease-(--ease-out-strong) starting:translate-y-1 starting:opacity-0';\n  }\n  return undefined;\n}\n\nfunction HunkCard({ hunk, isStreaming, isActive }: HunkLinesProps) {\n  const file = fileOf(hunk.fileId);\n\n  return (\n    <li\n      className={cn(\n        'bg-foreground/[0.03] dark:bg-foreground/[0.05] flex flex-col rounded-lg',\n        arrivalOf(isStreaming)\n      )}\n    >\n      <div className='flex min-h-9 flex-wrap items-center gap-x-2 gap-y-0.5 px-2.5 py-1.5'>\n        <ModifiedTile />\n        <span className='min-w-0 flex-1 truncate font-mono text-xs'>\n          {file.path}\n        </span>\n        <ChangeCounts hunks={[hunk]} />\n        <span className='text-muted-foreground w-full font-mono text-[11px]'>\n          {headerOf(hunk)}\n        </span>\n      </div>\n      {/* The scroller is positioned: a hidden word for screen readers would widen the page otherwise. */}\n      <div\n        role='region'\n        aria-label={`Changes to ${file.path}`}\n        tabIndex={0}\n        className='focus-visible:ring-ring/25 relative overflow-x-auto rounded-b-lg outline-none focus-visible:ring-[3px] focus-visible:ring-inset'\n      >\n        <HunkLines hunk={hunk} isStreaming={isStreaming} isActive={isActive} />\n      </div>\n    </li>\n  );\n}\n\ntype DiffViewProps = {\n  hunksStarted: number;\n  hunksDone: number;\n  isActive: boolean;\n};\n\nexport function DiffView({ hunksStarted, hunksDone, isActive }: DiffViewProps) {\n  const { scrollerRef, contentRef, updatePinned } = useFollowBottom();\n  const hunks = HUNKS.slice(0, hunksStarted);\n  const isEmpty = hunksStarted === 0;\n\n  return (\n    <div\n      ref={scrollerRef}\n      onScroll={updatePinned}\n      className='min-h-0 flex-1 overflow-y-auto'\n    >\n      <div ref={contentRef} className='flex flex-col gap-2'>\n        {isEmpty && (\n          <p className='text-muted-foreground text-[13px] leading-relaxed'>\n            No change yet. Each hunk shows here as the agent writes it.\n          </p>\n        )}\n        <ol aria-label='Hunks' className='flex flex-col gap-2'>\n          {hunks.map((hunk, index) => (\n            <HunkCard\n              key={hunk.id}\n              hunk={hunk}\n              isStreaming={index >= hunksDone}\n              isActive={isActive}\n            />\n          ))}\n        </ol>\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-12/diff-view.tsx"
    },
    {
      "path": "registry/ndeko/templates/agent-workspaces/application-12/tests-view.tsx",
      "content": "'use client';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { useFollowBottom } from '@/registry/ndeko/hooks/use-follow-bottom';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { DrawnCheck } from '@/registry/ndeko/ui/drawn-check';\nimport { Spinner } from '@/registry/ndeko/ui/spinner';\nimport {\n  shownCountOf,\n  useRevealedCount,\n} from '@/registry/ndeko/ui/streamed-text';\n\nimport {\n  FAILING_RUN,\n  PASSING_RUN,\n  TEST_COUNT,\n  type LogLine,\n  type LogTone,\n} from './data';\nimport { LOG_MS, type TestRun } from './session';\n\nconst PASSING_BEFORE_THE_FIX = TEST_COUNT - 1;\n\nconst CELLS = Array.from({ length: TEST_COUNT }, (_, index) => index);\n\nconst LOG_TONE: Record<LogTone, string> = {\n  plain: 'text-foreground/85',\n  muted: 'text-muted-foreground',\n  fail: 'text-destructive-ink',\n  pass: 'text-success-foreground',\n};\n\ntype CellTone = 'idle' | 'pass' | 'fail';\n\nconst CELL_TONE: Record<CellTone, string> = {\n  idle: 'bg-foreground/15',\n  pass: 'bg-success',\n  fail: 'bg-destructive',\n};\n\n/** While the second run streams, the result of the first one still stands. */\nfunction passedOf(testRun: TestRun) {\n  if (testRun === 'passed') {\n    return TEST_COUNT;\n  }\n  const hasFailed = testRun === 'failed' || testRun === 'passing';\n  if (hasFailed) {\n    return PASSING_BEFORE_THE_FIX;\n  }\n  return null;\n}\n\nfunction cellToneOf(index: number, passed: number | null): CellTone {\n  if (passed === null) {\n    return 'idle';\n  }\n  if (index < passed) {\n    return 'pass';\n  }\n  return 'fail';\n}\n\nfunction figureToneOf(isAllGreen: boolean) {\n  if (isAllGreen) {\n    return 'text-success-foreground';\n  }\n  return 'text-destructive-ink';\n}\n\nfunction ResultChip({ testRun }: { testRun: TestRun }) {\n  const isRunning = testRun === 'failing' || testRun === 'passing';\n  if (isRunning) {\n    return (\n      <Badge variant='secondary'>\n        <Spinner aria-hidden='true' className='[&_svg]:size-3' />\n        Running\n      </Badge>\n    );\n  }\n  if (testRun === 'failed') {\n    return <Badge variant='destructive'>1 failing</Badge>;\n  }\n  if (testRun === 'passed') {\n    return (\n      <Badge variant='success'>\n        <DrawnCheck\n          tone='success'\n          entrance='draw'\n          className='size-3.5 [&_svg]:size-2.5'\n        />\n        Passing\n      </Badge>\n    );\n  }\n  return null;\n}\n\nfunction lineInOf(isStreaming: boolean) {\n  if (isStreaming) {\n    return 'transition-opacity duration-150 starting:opacity-0';\n  }\n  return undefined;\n}\n\n/** The first run steps back once the second one starts, so the eye goes to the new output. */\nfunction standingOf(isSuperseded: boolean) {\n  if (isSuperseded) {\n    return 'opacity-55';\n  }\n  return 'opacity-100';\n}\n\ntype LogRunProps = {\n  lines: LogLine[];\n  isStreaming: boolean;\n  isActive: boolean;\n  isSuperseded: boolean;\n};\n\n/** Only the run that streams re-renders. Its lines land straight in the log: nothing resizes it line by line. */\nfunction LogRun({ lines, isStreaming, isActive, isSuperseded }: LogRunProps) {\n  const total = lines.length;\n  const isRunning = isStreaming && isActive;\n  const count = useRevealedCount(total, isRunning, LOG_MS);\n  const shown = shownCountOf(isStreaming, count, total);\n  const visible = lines.slice(0, shown);\n\n  return (\n    <div\n      className={cn(\n        'flex flex-col transition-opacity duration-500',\n        standingOf(isSuperseded)\n      )}\n    >\n      {visible.map((line, index) => (\n        <span\n          key={index}\n          className={cn(\n            'block min-h-[1lh] break-words whitespace-pre-wrap',\n            LOG_TONE[line.tone],\n            lineInOf(isStreaming)\n          )}\n        >\n          {line.text}\n        </span>\n      ))}\n    </div>\n  );\n}\n\ntype TestsViewProps = {\n  testRun: TestRun;\n  isActive: boolean;\n};\n\nexport function TestsView({ testRun, isActive }: TestsViewProps) {\n  const { scrollerRef, contentRef, updatePinned } = useFollowBottom();\n  const passed = passedOf(testRun);\n  const hasResult = passed !== null;\n  const isAllGreen = passed === TEST_COUNT;\n  const hasFirstRun = testRun !== 'none';\n  const hasSecondRun = testRun === 'passing' || testRun === 'passed';\n\n  return (\n    <div className='flex min-h-0 flex-1 flex-col gap-3'>\n      <div className='flex flex-col gap-2'>\n        <div className='flex min-h-8 items-center gap-2'>\n          {!hasResult && (\n            <p className='text-muted-foreground text-[13px]'>No result yet</p>\n          )}\n          {hasResult && (\n            <p className='flex items-baseline gap-1.5'>\n              <MotionNumber\n                value={passed}\n                className={cn(\n                  'text-2xl leading-8 font-semibold transition-colors duration-500',\n                  figureToneOf(isAllGreen)\n                )}\n              />\n              <span className='text-muted-foreground text-xs'>\n                of {TEST_COUNT} tests pass\n              </span>\n            </p>\n          )}\n          <Swap swapKey={testRun} className='ms-auto'>\n            <ResultChip testRun={testRun} />\n          </Swap>\n        </div>\n        <div aria-hidden='true' className='flex gap-1'>\n          {CELLS.map((index) => {\n            const tone = cellToneOf(index, passed);\n            return (\n              <span\n                key={index}\n                className={cn(\n                  'h-1.5 flex-1 rounded-full transition-colors duration-500',\n                  CELL_TONE[tone]\n                )}\n              />\n            );\n          })}\n        </div>\n      </div>\n      <div\n        ref={scrollerRef}\n        role='log'\n        aria-label='Test output'\n        aria-live='off'\n        tabIndex={0}\n        onScroll={updatePinned}\n        className='bg-foreground/[0.03] dark:bg-foreground/[0.05] focus-visible:ring-ring/25 min-h-0 flex-1 overflow-y-auto rounded-lg font-mono text-xs leading-5 outline-none focus-visible:ring-[3px] focus-visible:ring-inset'\n      >\n        <div ref={contentRef} className='flex flex-col gap-3 p-3'>\n          {!hasFirstRun && (\n            <p className='text-muted-foreground font-sans'>\n              The output of each run shows here\n            </p>\n          )}\n          {hasFirstRun && (\n            <LogRun\n              lines={FAILING_RUN}\n              isStreaming={testRun === 'failing'}\n              isActive={isActive}\n              isSuperseded={hasSecondRun}\n            />\n          )}\n          {hasSecondRun && (\n            <LogRun\n              lines={PASSING_RUN}\n              isStreaming={testRun === 'passing'}\n              isActive={isActive}\n              isSuperseded={false}\n            />\n          )}\n        </div>\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-12/tests-view.tsx"
    },
    {
      "path": "registry/ndeko/templates/agent-workspaces/application-12/preview-view.tsx",
      "content": "'use client';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { CheckIcon, TriangleAlertIcon } from '@/registry/ndeko/lib/icons';\nimport { Segments, type Segment } from '@/registry/ndeko/ui/segments';\n\nimport { ORDER } from './data';\nimport type { PageVersion } from './session';\n\nconst VERSIONS: Segment<PageVersion>[] = [\n  { value: 'before', label: 'Before' },\n  { value: 'after', label: 'After' },\n];\n\nconst MONEY: Intl.NumberFormatOptions = { style: 'currency', currency: 'USD' };\n\nconst MONEY_FORMAT = new Intl.NumberFormat('en-US', MONEY);\n\nconst SUBTOTAL = MONEY_FORMAT.format(ORDER.subtotal);\n\nconst DISCOUNT = MONEY_FORMAT.format(ORDER.discount);\n\nconst WRONG_TOTAL = MONEY_FORMAT.format(ORDER.totalBefore);\n\nconst RIGHT_TOTAL = MONEY_FORMAT.format(ORDER.totalAfter);\n\nfunction totalOf(version: PageVersion) {\n  if (version === 'after') {\n    return ORDER.totalAfter;\n  }\n  return ORDER.totalBefore;\n}\n\ntype SummaryRowProps = {\n  label: string;\n  value: string;\n};\n\nfunction SummaryRow({ label, value }: SummaryRowProps) {\n  return (\n    <div className='flex items-baseline justify-between gap-3'>\n      <dt className='text-muted-foreground min-w-0 truncate'>{label}</dt>\n      <dd className='shrink-0 tabular-nums'>{value}</dd>\n    </div>\n  );\n}\n\n/** The checkout page of the invented shop, drawn in HTML: nothing in it can be pressed. */\nfunction OrderSummary({ version }: { version: PageVersion }) {\n  return (\n    <div\n      role='group'\n      aria-label='Checkout page, order summary'\n      className='bg-card hairline-ring ring-border dark:bg-foreground/[0.04] flex w-full max-w-sm flex-col gap-3 self-center rounded-xl p-4 shadow-[0_1px_2px_rgb(0_0_0/0.04)]'\n    >\n      <p className='text-sm font-medium'>Order summary</p>\n      <dl className='flex flex-col gap-2 text-[13px]'>\n        <SummaryRow label={ORDER.item} value={SUBTOTAL} />\n        <SummaryRow label={`Code ${ORDER.code}`} value={`-${DISCOUNT}`} />\n        <SummaryRow label='Shipping' value='Free' />\n      </dl>\n      <div className='bg-foreground/[0.04] flex items-baseline justify-between gap-3 rounded-lg px-3 py-2'>\n        <span className='text-[13px] font-medium'>Total</span>\n        <MotionNumber\n          value={totalOf(version)}\n          format={MONEY}\n          className='text-2xl leading-8 font-semibold'\n        />\n      </div>\n      <span\n        aria-hidden='true'\n        className='bg-primary text-primary-foreground pointer-events-none flex h-8 items-center justify-center rounded-full text-[13px] font-medium select-none'\n      >\n        Pay now\n      </span>\n    </div>\n  );\n}\n\nfunction VersionNote({ version }: { version: PageVersion }) {\n  if (version === 'after') {\n    return (\n      <p className='text-success-foreground flex items-start gap-1.5 text-xs leading-5 transition-opacity duration-300 starting:opacity-0'>\n        <CheckIcon className='mt-0.5 size-3.5 shrink-0' />\n        {SUBTOTAL} less {DISCOUNT} is {RIGHT_TOTAL}, and the page says so\n      </p>\n    );\n  }\n  return (\n    <p className='text-warning-foreground flex items-start gap-1.5 text-xs leading-5 transition-opacity duration-300 starting:opacity-0'>\n      <TriangleAlertIcon className='mt-0.5 size-3.5 shrink-0' />\n      {SUBTOTAL} less {DISCOUNT} is {RIGHT_TOTAL}. The page says {WRONG_TOTAL}\n    </p>\n  );\n}\n\ntype PreviewViewProps = {\n  version: PageVersion;\n  canCompare: boolean;\n  onVersionChange: (version: PageVersion) => void;\n};\n\n/** The fixed page exists once the tests pass. Until then there is nothing to compare with, so the switch stays away. */\nexport function PreviewView({\n  version,\n  canCompare,\n  onVersionChange,\n}: PreviewViewProps) {\n  return (\n    <div className='flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto'>\n      <div className='flex min-h-7 flex-wrap items-center gap-x-3 gap-y-2'>\n        {canCompare && (\n          <Segments\n            label='Version of the page'\n            value={version}\n            segments={VERSIONS}\n            onValueChange={onVersionChange}\n          />\n        )}\n        <p className='text-muted-foreground text-xs'>\n          {canCompare && 'Checkout, order summary'}\n          {!canCompare &&\n            'The page as it is today. The fixed one shows once the tests pass'}\n        </p>\n      </div>\n      <OrderSummary version={version} />\n      <VersionNote key={version} version={version} />\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-12/preview-view.tsx"
    },
    {
      "path": "registry/ndeko/templates/agent-workspaces/application-12/status-footer.tsx",
      "content": "'use client';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { formatTokens } from '@/registry/ndeko/lib/agent-run';\nimport { GitBranchIcon } from '@/registry/ndeko/lib/icons';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { BrandTile } from '@/registry/ndeko/ui/brand-tile';\n\nimport { MODEL, REPOSITORY } from './data';\n\n/** Under a dollar a cost keeps three decimals, as in the rest of the kit. */\nconst COST_FORMAT: Intl.NumberFormatOptions = {\n  style: 'currency',\n  currency: 'USD',\n  minimumFractionDigits: 3,\n  maximumFractionDigits: 3,\n};\n\ntype StatusFooterProps = {\n  tokens: number;\n  costUsd: number;\n};\n\n/** The count of tokens is plain text: it changes with each step and has no digit to roll in a figure such as 6.1k. */\nexport function StatusFooter({ tokens, costUsd }: StatusFooterProps) {\n  return (\n    <footer className='bg-foreground/[0.03] text-muted-foreground flex shrink-0 flex-wrap items-center gap-x-4 gap-y-1 px-4 py-2 text-xs'>\n      <span className='flex min-w-0 items-center gap-1.5'>\n        <GitBranchIcon className='size-3.5 shrink-0' />\n        <span className='sr-only'>Branch</span>\n        <span className='text-foreground truncate font-mono'>\n          {REPOSITORY.branch}\n        </span>\n      </span>\n      <span className='tabular-nums'>\n        <span className='text-foreground'>{formatTokens(tokens)}</span> tokens\n      </span>\n      <span className='flex items-center gap-1.5'>\n        <span className='sr-only'>Cost of this run</span>\n        <MotionNumber\n          value={costUsd}\n          format={COST_FORMAT}\n          className='text-foreground'\n        />\n        <Badge variant='secondary'>Illustrative</Badge>\n      </span>\n      <span className='ms-auto flex items-center gap-1.5'>\n        <BrandTile brand={MODEL.brand} />\n        <span className='sr-only @sm:not-sr-only'>{MODEL.name}</span>\n      </span>\n    </footer>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/templates/application-12/status-footer.tsx"
    },
    {
      "path": "registry/ndeko/templates/agent-workspaces/application-12/session.ts",
      "content": "import type { SessionStep } from '@/registry/ndeko/hooks/use-session';\nimport { keyDelayOf, prefixesOf } from '@/registry/ndeko/lib/demonstration';\nimport { restingOf } from '@/registry/ndeko/lib/run-session';\nimport { wordsOf } from '@/registry/ndeko/lib/words';\n\nimport {\n  ANSWER,\n  FAILING_RUN,\n  FILES,\n  HUNKS,\n  PASSING_RUN,\n  stepOf,\n  TASK,\n  type PanelTab,\n  type StepId,\n} from './data';\n\nexport type Stage =\n  | 'idle'\n  | 'working'\n  | 'answering'\n  | 'asking'\n  | 'opening'\n  | 'opened'\n  | 'declined';\n\n/** `failing` and `passing` are the two runs while their output still streams. */\nexport type TestRun = 'none' | 'failing' | 'failed' | 'passing' | 'passed';\n\nexport type PageVersion = 'before' | 'after';\n\nexport type Decision = 'approved' | 'denied';\n\nexport type StepRun = {\n  id: StepId;\n  status: 'running' | 'done';\n  startedAt: number;\n  endedAt?: number;\n};\n\nexport type CodingState = {\n  draft: string;\n  task: string | null;\n  followUps: string[];\n  stage: Stage;\n  steps: StepRun[];\n  filesRead: number;\n  hunksStarted: number;\n  hunksDone: number;\n  testRun: TestRun;\n  preview: PageVersion;\n  tab: PanelTab;\n  isFollowingAgent: boolean;\n  tokens: number;\n  costUsd: number;\n  isSheetOpen: boolean;\n};\n\nexport type CodingAction =\n  | { type: 'typed'; text: string }\n  | { type: 'sent' }\n  | { type: 'stepStarted'; id: StepId }\n  | { type: 'stepDone'; id: StepId }\n  | { type: 'fileRead' }\n  | { type: 'hunkStarted' }\n  | { type: 'hunkDone' }\n  | { type: 'testRun'; run: TestRun }\n  | { type: 'previewed'; view: PageVersion }\n  | { type: 'focused'; tab: PanelTab }\n  | { type: 'tabPicked'; tab: PanelTab }\n  | { type: 'answering' }\n  | { type: 'asked' }\n  | { type: 'decided'; decision: Decision }\n  | { type: 'opened' }\n  | { type: 'sheet'; isOpen: boolean }\n  | { type: 'batch'; actions: CodingAction[] };\n\ntype Step = SessionStep<CodingState, CodingAction>;\n\nexport const INITIAL: CodingState = {\n  draft: '',\n  task: null,\n  followUps: [],\n  stage: 'idle',\n  steps: [],\n  filesRead: 0,\n  hunksStarted: 0,\n  hunksDone: 0,\n  testRun: 'none',\n  preview: 'before',\n  tab: 'diff',\n  isFollowingAgent: true,\n  tokens: 0,\n  costUsd: 0,\n  isSheetOpen: false,\n};\n\nconst STAGE_ORDER: Stage[] = [\n  'idle',\n  'working',\n  'answering',\n  'asking',\n  'opening',\n  'opened',\n  'declined',\n];\n\nexport function hasReached(stage: Stage, target: Stage) {\n  const position = STAGE_ORDER.indexOf(stage);\n  const targetPosition = STAGE_ORDER.indexOf(target);\n  return position >= targetPosition;\n}\n\nexport function isOver(stage: Stage) {\n  return stage === 'opened' || stage === 'declined';\n}\n\n/** A person who takes over while the task is being typed sends the whole task, not the half that was typed. */\nfunction taskOf(draft: string) {\n  const trimmed = draft.trim();\n  const isUnfinishedDemo = TASK.startsWith(trimmed);\n  if (isUnfinishedDemo) {\n    return TASK;\n  }\n  return trimmed;\n}\n\n/** What Send would post now: the task, then follow-ups once the run is over. Null while the agent works. */\nexport function sendableTextOf(state: CodingState) {\n  if (state.task === null) {\n    return taskOf(state.draft);\n  }\n  const text = state.draft.trim();\n  const canFollowUp = isOver(state.stage) && text !== '';\n  if (canFollowUp) {\n    return text;\n  }\n  return null;\n}\n\nfunction sent(state: CodingState): CodingState {\n  const text = sendableTextOf(state);\n  if (text === null) {\n    return state;\n  }\n  if (state.task === null) {\n    return { ...state, draft: '', task: text, stage: 'working' };\n  }\n  return { ...state, draft: '', followUps: [...state.followUps, text] };\n}\n\nfunction stepStarted(state: CodingState, id: StepId, now: number): CodingState {\n  const isKnown = state.steps.some((run) => run.id === id);\n  if (isKnown) {\n    return state;\n  }\n  const run: StepRun = { id, status: 'running', startedAt: now };\n  return { ...state, steps: [...state.steps, run] };\n}\n\nfunction isRunningStep(run: StepRun, id: StepId) {\n  return run.id === id && run.status === 'running';\n}\n\nfunction stepDone(state: CodingState, id: StepId, now: number): CodingState {\n  const wasRunning = state.steps.some((run) => isRunningStep(run, id));\n  if (!wasRunning) {\n    return state;\n  }\n  const steps = state.steps.map((run) => {\n    if (run.id !== id) {\n      return run;\n    }\n    const ended: StepRun = { ...run, status: 'done', endedAt: now };\n    return ended;\n  });\n  const step = stepOf(id);\n  const tokens = state.tokens + step.tokens;\n  const costUsd = state.costUsd + step.usd;\n  return { ...state, steps, tokens, costUsd };\n}\n\nfunction fileRead(state: CodingState): CodingState {\n  const read = state.filesRead + 1;\n  const filesRead = Math.min(FILES.length, read);\n  return { ...state, filesRead };\n}\n\nfunction hunkStarted(state: CodingState): CodingState {\n  const isWriting = state.hunksStarted > state.hunksDone;\n  const isComplete = state.hunksStarted >= HUNKS.length;\n  if (isWriting || isComplete) {\n    return state;\n  }\n  const hunksStarted = state.hunksStarted + 1;\n  return { ...state, hunksStarted };\n}\n\n/** The page after the fix exists once the tests pass, never before. */\nfunction previewed(state: CodingState, view: PageVersion): CodingState {\n  const isTooEarly = view === 'after' && state.testRun !== 'passed';\n  if (isTooEarly) {\n    return state;\n  }\n  return { ...state, preview: view };\n}\n\n/** The panel follows the agent from tab to tab until a person picks one themselves. */\nfunction focused(state: CodingState, tab: PanelTab): CodingState {\n  if (!state.isFollowingAgent) {\n    return state;\n  }\n  return { ...state, tab };\n}\n\nfunction staged(state: CodingState, from: Stage, to: Stage): CodingState {\n  if (state.stage !== from) {\n    return state;\n  }\n  return { ...state, stage: to };\n}\n\nfunction decided(state: CodingState, decision: Decision): CodingState {\n  if (decision === 'approved') {\n    return staged(state, 'asking', 'opening');\n  }\n  return staged(state, 'asking', 'declined');\n}\n\nexport function applyAt(\n  state: CodingState,\n  action: CodingAction,\n  now: number\n): CodingState {\n  switch (action.type) {\n    case 'typed':\n      return { ...state, draft: action.text };\n    case 'sent':\n      return sent(state);\n    case 'stepStarted':\n      return stepStarted(state, action.id, now);\n    case 'stepDone':\n      return stepDone(state, action.id, now);\n    case 'fileRead':\n      return fileRead(state);\n    case 'hunkStarted':\n      return hunkStarted(state);\n    case 'hunkDone':\n      return { ...state, hunksDone: state.hunksStarted };\n    case 'testRun':\n      return { ...state, testRun: action.run };\n    case 'previewed':\n      return previewed(state, action.view);\n    case 'focused':\n      return focused(state, action.tab);\n    case 'tabPicked':\n      return { ...state, tab: action.tab, isFollowingAgent: false };\n    case 'answering':\n      return staged(state, 'working', 'answering');\n    case 'asked':\n      return staged(state, 'answering', 'asking');\n    case 'decided':\n      return decided(state, action.decision);\n    case 'opened':\n      return staged(state, 'opening', 'opened');\n    case 'sheet':\n      return { ...state, isSheetOpen: action.isOpen };\n    case 'batch': {\n      let next = state;\n      for (const inner of action.actions) {\n        next = applyAt(next, inner, now);\n      }\n      return next;\n    }\n  }\n}\n\nexport function reducer(state: CodingState, action: CodingAction) {\n  return applyAt(state, action, Date.now());\n}\n\nfunction hasTask(state: CodingState) {\n  return state.task !== null;\n}\n\nfunction hasDecided(state: CodingState) {\n  return hasReached(state.stage, 'opening');\n}\n\nexport const LINE_MS = 90;\n\nexport const LOG_MS = 110;\n\nexport const ANSWER_WORD_MS = 45;\n\n/** A stream is given a little longer than its lines need, so its last line lands before the next step. */\nconst STREAM_MARGIN_MS = 200;\n\nconst KEY_MS = 34;\n\nconst DEMO_DECIDES_AFTER_MS = 2500;\n\nexport const OPEN_MS = 1000;\n\nfunction hunkMsOf(index: number) {\n  const lineCount = HUNKS[index].lines.length;\n  const streamMs = lineCount * LINE_MS;\n  return streamMs + STREAM_MARGIN_MS;\n}\n\nfunction runMsOf(lineCount: number) {\n  const streamMs = lineCount * LOG_MS;\n  return streamMs + STREAM_MARGIN_MS;\n}\n\nconst FAILING_MS = runMsOf(FAILING_RUN.length);\n\nconst PASSING_MS = runMsOf(PASSING_RUN.length);\n\nconst ANSWER_WORDS = wordsOf(ANSWER);\n\nconst ANSWER_STREAM_MS = ANSWER_WORDS.length * ANSWER_WORD_MS;\n\nconst ANSWER_MS = ANSWER_STREAM_MS + STREAM_MARGIN_MS;\n\nfunction typingSteps(text: string, startAfter: number): Step[] {\n  const prefixes = prefixesOf(text);\n  return prefixes.map((typed, index) => ({\n    after: keyDelayOf(index, startAfter, KEY_MS),\n    by: 'demo',\n    action: { type: 'typed', text: typed },\n  }));\n}\n\nfunction frame(after: number, actions: CodingAction[]): Step {\n  return { after, action: { type: 'batch', actions } };\n}\n\nfunction started(id: StepId): CodingAction {\n  return { type: 'stepStarted', id };\n}\n\nfunction done(id: StepId): CodingAction {\n  return { type: 'stepDone', id };\n}\n\nfunction focus(tab: PanelTab): CodingAction {\n  return { type: 'focused', tab };\n}\n\nfunction run(result: TestRun): CodingAction {\n  return { type: 'testRun', run: result };\n}\n\nconst FILE: CodingAction = { type: 'fileRead' };\n\nconst HUNK_STARTED: CodingAction = { type: 'hunkStarted' };\n\nconst HUNK_DONE: CodingAction = { type: 'hunkDone' };\n\n/** The test is written and seen to fail before a line of the fix: that is what a reviewer wants to see first. */\nconst OPENING: Step[] = [\n  ...typingSteps(TASK, 1000),\n  {\n    after: 500,\n    by: 'person',\n    press: 'send',\n    action: { type: 'sent' },\n    isAnswered: hasTask,\n  },\n  frame(500, [started('read')]),\n  frame(450, [FILE]),\n  frame(400, [FILE]),\n  frame(400, [FILE]),\n  frame(400, [FILE]),\n  frame(600, [done('read'), started('reproduce'), focus('diff'), HUNK_STARTED]),\n  { after: 300, by: 'demo', action: { type: 'sheet', isOpen: true } },\n  frame(hunkMsOf(0), [HUNK_DONE]),\n  frame(400, [focus('tests'), run('failing')]),\n  frame(FAILING_MS, [run('failed'), done('reproduce'), started('edit')]),\n  frame(1100, [focus('diff'), HUNK_STARTED]),\n  frame(hunkMsOf(1), [HUNK_DONE, HUNK_STARTED]),\n  frame(hunkMsOf(2), [HUNK_DONE, done('edit'), started('verify')]),\n  frame(800, [focus('tests'), run('passing')]),\n  frame(PASSING_MS, [run('passed'), done('verify'), started('preview')]),\n  frame(1600, [focus('preview')]),\n  frame(1100, [{ type: 'previewed', view: 'after' }]),\n  frame(1300, [done('preview')]),\n  { after: 600, by: 'demo', action: { type: 'sheet', isOpen: false } },\n  frame(400, [{ type: 'answering' }]),\n  frame(ANSWER_MS, [{ type: 'asked' }]),\n];\n\nconst CLOSING: Step[] = [\n  {\n    after: DEMO_DECIDES_AFTER_MS,\n    by: 'person',\n    press: 'allow',\n    action: { type: 'decided', decision: 'approved' },\n    isAnswered: hasDecided,\n  },\n  { after: OPEN_MS, action: { type: 'opened' } },\n];\n\nexport const SCRIPT: Step[] = [...OPENING, ...CLOSING];\n\nconst ASKED = restingOf(INITIAL, OPENING, applyAt);\n\n/** Under reduced motion the work is done, the tests show green and the pull request waits for an answer. */\nexport const RESTING: CodingState = {\n  ...ASKED,\n  tab: 'tests',\n  isSheetOpen: false,\n};\n\nexport const LOOP_AFTER_MS = 3400;\n",
      "type": "registry:component",
      "target": "components/templates/application-12/session.ts"
    },
    {
      "path": "registry/ndeko/templates/agent-workspaces/application-12/data.ts",
      "content": "import type { SeriesSlot } from '@/registry/ndeko/lib/agent-run';\nimport type { BrandSlug } from '@/registry/ndeko/lib/brand-logos';\n\nexport const REPOSITORY = {\n  owner: 'Kettlebrook',\n  name: 'storefront',\n  branch: 'fix/discount-applied-twice',\n  base: 'main',\n};\n\nexport type Agent = {\n  name: string;\n  series: SeriesSlot;\n};\n\nexport const CODER: Agent = { name: 'Coder', series: 5 };\n\nexport type Model = {\n  name: string;\n  brand: BrandSlug;\n};\n\nexport const MODEL: Model = { name: 'Claude Opus', brand: 'claude' };\n\nexport const TASK =\n  'The discount code is taken twice at checkout. Fix it and open a pull request.';\n\nexport type FileId = 'summary' | 'discount' | 'total' | 'test';\n\nexport type RepoFile = {\n  id: FileId;\n  path: string;\n  finding: string;\n};\n\nexport const FILES: RepoFile[] = [\n  {\n    id: 'summary',\n    path: 'src/checkout/summary.tsx',\n    finding: 'Shows the total it is given',\n  },\n  {\n    id: 'discount',\n    path: 'src/cart/discount.ts',\n    finding: 'Takes a code off an amount',\n  },\n  {\n    id: 'total',\n    path: 'src/cart/total.ts',\n    finding: 'Takes the code off, then calls discount again',\n  },\n  {\n    id: 'test',\n    path: 'src/cart/total.test.ts',\n    finding: 'Six tests, none with a code',\n  },\n];\n\n/** The file where the bug lives: its row is flagged once every file is read. */\nexport const CAUSE_FILE: FileId = 'total';\n\nexport type LineKind = 'same' | 'added' | 'removed';\n\nexport type DiffLine = {\n  kind: LineKind;\n  text: string;\n};\n\nexport type Hunk = {\n  id: string;\n  fileId: FileId;\n  firstLine: number;\n  lines: DiffLine[];\n};\n\n/** In the order the agent writes them: the test that fails first, then the fix in two places. */\nexport const HUNKS: Hunk[] = [\n  {\n    id: 'test',\n    fileId: 'test',\n    firstLine: 41,\n    lines: [\n      { kind: 'same', text: '  });' },\n      { kind: 'added', text: \"  it('applies a discount code once', () => {\" },\n      { kind: 'added', text: \"    const cart = cartOf([line(48)], 'TEN');\" },\n      { kind: 'added', text: '    expect(totalOf(cart)).toBe(43.2);' },\n      { kind: 'added', text: '  });' },\n      { kind: 'same', text: '});' },\n    ],\n  },\n  {\n    id: 'import',\n    fileId: 'total',\n    firstLine: 1,\n    lines: [\n      {\n        kind: 'removed',\n        text: \"import { applyDiscount, discountOf } from './discount';\",\n      },\n      { kind: 'added', text: \"import { applyDiscount } from './discount';\" },\n      { kind: 'same', text: \"import { shippingOf } from './shipping';\" },\n    ],\n  },\n  {\n    id: 'body',\n    fileId: 'total',\n    firstLine: 14,\n    lines: [\n      { kind: 'same', text: 'export function totalOf(cart: Cart) {' },\n      { kind: 'same', text: '  const subtotal = subtotalOf(cart.lines);' },\n      {\n        kind: 'removed',\n        text: '  const discounted = subtotal - discountOf(subtotal, cart.code);',\n      },\n      {\n        kind: 'removed',\n        text: '  return applyDiscount(discounted, cart.code) + shippingOf(discounted);',\n      },\n      {\n        kind: 'added',\n        text: '  const discounted = applyDiscount(subtotal, cart.code);',\n      },\n      { kind: 'added', text: '  return discounted + shippingOf(discounted);' },\n      { kind: 'same', text: '}' },\n    ],\n  },\n];\n\nfunction countOfKind(lines: DiffLine[], kind: LineKind) {\n  const matching = lines.filter((line) => line.kind === kind);\n  return matching.length;\n}\n\nexport function changesOf(hunks: Hunk[]) {\n  let additions = 0;\n  let deletions = 0;\n  for (const hunk of hunks) {\n    additions += countOfKind(hunk.lines, 'added');\n    deletions += countOfKind(hunk.lines, 'removed');\n  }\n  return { additions, deletions };\n}\n\n/** \"@@ -14,5 +14,5 @@\": where the hunk starts and how many lines it covers before and after. */\nexport function headerOf(hunk: Hunk) {\n  const { additions, deletions } = changesOf([hunk]);\n  const unchanged = countOfKind(hunk.lines, 'same');\n  const before = unchanged + deletions;\n  const after = unchanged + additions;\n  return `@@ -${hunk.firstLine},${before} +${hunk.firstLine},${after} @@`;\n}\n\nexport function fileOf(id: FileId) {\n  const file = FILES.find((candidate) => candidate.id === id);\n  return file ?? FILES[0];\n}\n\nexport const TEST_COUNT = 7;\n\nexport type LogTone = 'plain' | 'muted' | 'fail' | 'pass';\n\nexport type LogLine = {\n  text: string;\n  tone: LogTone;\n};\n\nconst COMMAND: LogLine = { text: '$ pnpm test cart', tone: 'muted' };\n\nconst EARLIER_TESTS: LogLine[] = [\n  { text: '  ✓ sums the line items', tone: 'plain' },\n  { text: '  ✓ applies the quantity', tone: 'plain' },\n  { text: '  ✓ rounds to two decimals', tone: 'plain' },\n  { text: '  ✓ ignores an empty cart', tone: 'plain' },\n  { text: '  ✓ adds shipping under the threshold', tone: 'plain' },\n  { text: '  ✓ waives shipping above the threshold', tone: 'plain' },\n];\n\nexport const FAILING_RUN: LogLine[] = [\n  COMMAND,\n  { text: ' FAIL  src/cart/total.test.ts', tone: 'fail' },\n  ...EARLIER_TESTS,\n  { text: '  ✕ applies a discount code once', tone: 'fail' },\n  { text: '      Expected: 43.2', tone: 'plain' },\n  { text: '      Received: 38.88', tone: 'fail' },\n  { text: ' Tests: 1 failed, 6 passed, 7 total', tone: 'fail' },\n];\n\nexport const PASSING_RUN: LogLine[] = [\n  COMMAND,\n  { text: ' PASS  src/cart/total.test.ts', tone: 'pass' },\n  ...EARLIER_TESTS,\n  { text: '  ✓ applies a discount code once', tone: 'pass' },\n  { text: ' Tests: 7 passed, 7 total', tone: 'pass' },\n];\n\nexport const ORDER = {\n  item: 'Stovetop kettle, 1.7 l',\n  subtotal: 48,\n  code: 'TEN',\n  discount: 4.8,\n  totalBefore: 38.88,\n  totalAfter: 43.2,\n};\n\nexport type StepId = 'read' | 'reproduce' | 'edit' | 'verify' | 'preview';\n\nexport type PanelTab = 'diff' | 'tests' | 'preview';\n\nexport type WorkStep = {\n  id: StepId;\n  title: string;\n  detail: string;\n  doneSummary: string;\n  shownInTab?: PanelTab;\n  tokens: number;\n  usd: number;\n};\n\n/** An invented repository, order and costs. The figures are illustrative. */\nexport const STEPS: WorkStep[] = [\n  {\n    id: 'read',\n    title: 'Read the cart and the checkout',\n    detail: 'Four files that touch the total',\n    doneSummary: 'The code is taken off in two places',\n    tokens: 6100,\n    usd: 0.031,\n  },\n  {\n    id: 'reproduce',\n    title: 'Reproduce the bug',\n    detail: 'A test that takes a code once',\n    doneSummary: 'The new test fails: 38.88 where 43.2 is expected',\n    shownInTab: 'tests',\n    tokens: 3900,\n    usd: 0.027,\n  },\n  {\n    id: 'edit',\n    title: 'Fix total.ts',\n    detail: 'One subtraction too many',\n    doneSummary: 'Two hunks in one file',\n    shownInTab: 'diff',\n    tokens: 4800,\n    usd: 0.041,\n  },\n  {\n    id: 'verify',\n    title: 'Run the tests',\n    detail: 'The seven tests of the cart',\n    doneSummary: 'All 7 pass',\n    shownInTab: 'tests',\n    tokens: 1200,\n    usd: 0.008,\n  },\n  {\n    id: 'preview',\n    title: 'Check the page',\n    detail: 'The order summary at checkout',\n    doneSummary: 'The total reads $43.20',\n    shownInTab: 'preview',\n    tokens: 2400,\n    usd: 0.019,\n  },\n];\n\nconst FALLBACK_STEP = STEPS[0];\n\nexport function stepOf(id: StepId) {\n  const step = STEPS.find((candidate) => candidate.id === id);\n  return step ?? FALLBACK_STEP;\n}\n\nexport const ANSWER =\n  'The code was taken off in totalOf and again inside applyDiscount. I removed the first subtraction, added a test for an order with a code, and all 7 tests pass. The checkout now reads $43.20 for this order.';\n\nexport const PULL_REQUEST = {\n  title: 'Take a discount code off once',\n  number: 482,\n};\n\nexport const OPENED_LINE = `Pull request #${PULL_REQUEST.number} opened. It waits for a review on GitHub`;\n\nexport const DECLINED_LINE =\n  'No pull request. The fix stays on its branch until you ask again';\n\nexport const FOLLOW_UP_REPLY =\n  'This demonstration plays one scripted run. Replay it to watch it again.';\n",
      "type": "registry:component",
      "target": "components/templates/application-12/data.ts"
    }
  ],
  "categories": [
    "templates",
    "agent-workspaces"
  ],
  "type": "registry:block"
}