{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "agent-review-05",
  "title": "Agents in a document",
  "description": "Two agents edit a brief like teammates: a named pointer glides to a paragraph and its suggestion types itself in as a tracked change, a margin comment arrives after a typing mark, and a table lists every change.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/agent-run.json",
    "https://ui.ndekocode.dev/r/badge.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/icons.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-presets.json",
    "https://ui.ndekocode.dev/r/motion-word-roll.json",
    "https://ui.ndekocode.dev/r/replay-button.json",
    "https://ui.ndekocode.dev/r/segments.json",
    "https://ui.ndekocode.dev/r/streamed-text.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/use-session.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/agent-review/agent-review-05/index.tsx",
      "content": "'use client';\n\nimport { useLayoutEffect, useRef } from 'react';\n\nimport { WordRoll } from '@/components/core/word-roll';\nimport { useSession } from '@/registry/ndeko/hooks/use-session';\nimport {\n  pressedSolidOf,\n  spokenUnless,\n} from '@/registry/ndeko/lib/demonstration';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { ClockGate } from '@/registry/ndeko/ui/live-duration';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { ReplayButton } from '@/registry/ndeko/ui/replay-button';\nimport { Segments, type Segment } from '@/registry/ndeko/ui/segments';\n\nimport {\n  AGENT_ORDER,\n  AGENTS,\n  CHANGE_ORDER,\n  CHANGES,\n  COMMENT,\n  DOC_TITLE,\n  PARAGRAPHS,\n  type AgentId,\n} from './data';\nimport {\n  AgentPointer,\n  AgentTile,\n  ParagraphRow,\n  POINTER_REACH,\n} from './doc-parts';\nimport {\n  INITIAL,\n  LOOP_AFTER_MS,\n  pendingIdsOf,\n  reducer,\n  RESTING,\n  SCRIPT,\n  type ChangeStatus,\n  type CommentStatus,\n  type DocState,\n  type DocView,\n} from './session';\n\nconst SESSION = {\n  reducer,\n  initial: INITIAL,\n  resting: RESTING,\n  script: SCRIPT,\n  loopAfter: LOOP_AFTER_MS,\n};\n\nconst VIEW_SEGMENTS: Segment<DocView>[] = [\n  { value: 'doc', label: 'Doc' },\n  { value: 'table', label: 'Table' },\n];\n\nconst CHANGE_WORD: Record<ChangeStatus, string> = {\n  hidden: 'Not started',\n  typing: 'Being written',\n  pending: 'Suggested',\n  accepted: 'Accepted',\n  rejected: 'Rejected',\n};\n\nconst CHANGE_VARIANT = {\n  hidden: 'secondary',\n  typing: 'secondary',\n  pending: 'warning',\n  accepted: 'success',\n  rejected: 'secondary',\n} as const;\n\nconst COMMENT_WORD: Record<CommentStatus, string> = {\n  hidden: 'Not started',\n  typing: 'Being written',\n  posted: 'Open',\n  resolved: 'Resolved',\n};\n\nconst COMMENT_VARIANT = {\n  hidden: 'secondary',\n  typing: 'secondary',\n  posted: 'warning',\n  resolved: 'success',\n} as const;\n\nfunction pendingPhraseOf(count: number) {\n  if (count === 0) {\n    return 'No suggestion to decide';\n  }\n  if (count === 1) {\n    return '1 suggestion to decide';\n  }\n  return `${count} suggestions to decide`;\n}\n\nfunction pointersHiddenOf(view: DocView) {\n  if (view === 'table') {\n    return 'hidden';\n  }\n  return undefined;\n}\n\ntype TableRow = {\n  key: string;\n  summary: string;\n  author: AgentId;\n  kind: string;\n  word: string;\n  variant: 'secondary' | 'warning' | 'success';\n};\n\nfunction rowsOf(state: DocState): TableRow[] {\n  const rows: TableRow[] = [];\n  for (const id of CHANGE_ORDER) {\n    const status = state.changes[id];\n    if (status !== 'hidden') {\n      rows.push({\n        key: id,\n        summary: CHANGES[id].summary,\n        author: CHANGES[id].author,\n        kind: 'Edit',\n        word: CHANGE_WORD[status],\n        variant: CHANGE_VARIANT[status],\n      });\n    }\n  }\n  if (state.comment !== 'hidden') {\n    rows.push({\n      key: 'comment',\n      summary: COMMENT.summary,\n      author: COMMENT.author,\n      kind: 'Comment',\n      word: COMMENT_WORD[state.comment],\n      variant: COMMENT_VARIANT[state.comment],\n    });\n  }\n  return rows;\n}\n\nfunction ChangeTable({ rows }: { rows: TableRow[] }) {\n  if (rows.length === 0) {\n    return (\n      <p className='text-muted-foreground py-10 text-center text-[13px]'>\n        No change yet. Suggestions and comments are listed here as the agents\n        make them.\n      </p>\n    );\n  }\n  return (\n    <table className='w-full text-start text-[13px]'>\n      <thead>\n        <tr className='text-muted-foreground text-xs'>\n          <th className='pb-2 text-start font-normal'>Change</th>\n          <th className='pb-2 text-start font-normal'>Author</th>\n          <th className='pb-2 text-end font-normal'>State</th>\n        </tr>\n      </thead>\n      <tbody>\n        {rows.map((row) => (\n          <tr key={row.key} className='hairline-t border-border'>\n            <td className='py-2.5 pe-3'>\n              <span className='flex flex-col leading-snug'>\n                {row.summary}\n                <span className='text-muted-foreground text-xs'>\n                  {row.kind}\n                </span>\n              </span>\n            </td>\n            <td className='py-2.5 pe-3'>\n              <span className='flex items-center gap-2'>\n                <AgentTile agent={AGENTS[row.author]} />\n                <span className='hidden @md:inline'>\n                  {AGENTS[row.author].name}\n                </span>\n                <span className='sr-only @md:hidden'>\n                  {AGENTS[row.author].name}\n                </span>\n              </span>\n            </td>\n            <td className='py-2.5 text-end'>\n              <Badge variant={row.variant}>\n                <Swap swapKey={row.word}>{row.word}</Swap>\n              </Badge>\n            </td>\n          </tr>\n        ))}\n      </tbody>\n    </table>\n  );\n}\n\nexport default function AgentReview05() {\n  const {\n    ref,\n    isInView,\n    isAutoplaying,\n    state,\n    act,\n    pressed,\n    isFinished,\n    restart,\n  } = useSession(SESSION);\n  const pageRef = useRef<HTMLDivElement>(null);\n  const pendingCount = pendingIdsOf(state).length;\n  const pendingPhrase = pendingPhraseOf(pendingCount);\n  const hasPending = pendingCount > 0;\n  const message = spokenUnless(isAutoplaying, pendingPhrase);\n  const canReplay = isFinished && !isAutoplaying;\n  const isDoc = state.view === 'doc';\n  const writerTarget = state.pointers.writer.target;\n  const reviewerTarget = state.pointers.reviewer.target;\n\n  useLayoutEffect(() => {\n    const page = pageRef.current;\n    if (!page) {\n      return;\n    }\n    const targets = { writer: writerTarget, reviewer: reviewerTarget };\n    const place = () => {\n      const bounds = page.getBoundingClientRect();\n      for (const agent of AGENT_ORDER) {\n        const pointer = page.querySelector<HTMLElement>(\n          `[data-pointer='${agent}']`\n        );\n        const paragraph = page.querySelector(\n          `[data-paragraph='${targets[agent]}']`\n        );\n        if (pointer && paragraph) {\n          const box = paragraph.getBoundingClientRect();\n          const x = box.left - bounds.left + box.width * POINTER_REACH[agent];\n          const y = box.top - bounds.top + 18;\n          pointer.style.translate = `${x}px ${y}px`;\n        }\n      }\n    };\n    place();\n    const observer = new ResizeObserver(place);\n    observer.observe(page);\n    return () => observer.disconnect();\n  }, [writerTarget, reviewerTarget, isDoc]);\n\n  return (\n    <ClockGate isActive={isInView}>\n      <div\n        ref={ref}\n        className='bg-background text-foreground @container min-h-dvh w-full p-3 @3xl:p-8'\n      >\n        <div className='mx-auto flex max-w-4xl flex-col gap-3'>\n          <div className='flex flex-wrap items-center gap-x-3 gap-y-2'>\n            <Segments\n              label='View'\n              value={state.view}\n              segments={VIEW_SEGMENTS}\n              onValueChange={(view) => act({ type: 'view', view })}\n            />\n            <span className='text-muted-foreground min-w-40 flex-1 text-xs'>\n              <WordRoll text={pendingPhrase} value={pendingCount} />\n            </span>\n            <ReplayButton\n              isShown={canReplay}\n              onReplay={restart}\n              label='Replay the edits'\n            />\n            <Button\n              type='button'\n              size='sm'\n              disabled={!hasPending}\n              onClick={() => act({ type: 'acceptAll' })}\n              className={pressedSolidOf(pressed === 'accept-all')}\n            >\n              Accept all\n            </Button>\n          </div>\n\n          <article\n            ref={pageRef}\n            aria-label={DOC_TITLE}\n            className='bg-card hairline-ring ring-border dark:bg-foreground/[0.03] relative flex min-h-[26rem] flex-col gap-6 rounded-xl p-5 shadow-[0_1px_2px_rgb(0_0_0/0.04)] @3xl:p-10'\n          >\n            <header className='flex flex-col gap-2'>\n              <h1 className='text-2xl font-semibold text-balance'>\n                {DOC_TITLE}\n              </h1>\n              <ul\n                aria-label='Agents in this document'\n                className='flex flex-wrap items-center gap-x-4 gap-y-1'\n              >\n                {AGENT_ORDER.map((agent) => (\n                  <li\n                    key={agent}\n                    className='text-muted-foreground flex items-center gap-2 text-xs'\n                  >\n                    <AgentTile agent={AGENTS[agent]} />\n                    {AGENTS[agent].name}\n                    <Swap swapKey={state.pointers[agent].action}>\n                      {state.pointers[agent].action}\n                    </Swap>\n                  </li>\n                ))}\n                <li className='text-muted-foreground text-xs'>\n                  Illustrative spend\n                </li>\n              </ul>\n            </header>\n\n            {isDoc &&\n              PARAGRAPHS.map((paragraph) => (\n                <ParagraphRow\n                  key={paragraph.id}\n                  paragraph={paragraph}\n                  statuses={state.changes}\n                  pressed={pressed}\n                  isActive={isInView}\n                  comment={state.comment}\n                  onDecide={(id, decision) =>\n                    act({ type: 'decided', id, decision })\n                  }\n                  onResolveComment={() =>\n                    act({ type: 'comment', status: 'resolved' })\n                  }\n                />\n              ))}\n            {!isDoc && <ChangeTable rows={rowsOf(state)} />}\n\n            <div className={cn(pointersHiddenOf(state.view))}>\n              {AGENT_ORDER.map((agent) => (\n                <AgentPointer\n                  key={agent}\n                  agent={AGENTS[agent]}\n                  pointer={state.pointers[agent]}\n                />\n              ))}\n            </div>\n          </article>\n        </div>\n        <LiveRegion message={message} />\n      </div>\n    </ClockGate>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/agent-review-05/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/agent-review/agent-review-05/doc-parts.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { formatCost, seriesColorOf } from '@/registry/ndeko/lib/agent-run';\nimport { CheckIcon, MousePointerIcon, XIcon } from '@/registry/ndeko/lib/icons';\nimport { rowPresenceOf } from '@/registry/ndeko/lib/motion-presets';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { MeshTile } from '@/registry/ndeko/ui/mesh-tile';\nimport { useRevealedCount } from '@/registry/ndeko/ui/streamed-text';\n\nimport {\n  AGENTS,\n  CHANGES,\n  COMMENT,\n  type AgentId,\n  type ChangeId,\n  type DocAgent,\n  type Paragraph,\n  type Segment,\n} from './data';\nimport {\n  TYPE_TICK_MS,\n  type ChangeStatus,\n  type CommentStatus,\n  type Decision,\n  type Pointer,\n} from './session';\n\nfunction gemStyleOf(agent: DocAgent) {\n  return { '--gem': seriesColorOf(agent.series) } as React.CSSProperties;\n}\n\n/** The inserted words carry the author's colour as a line and a tint; the text itself stays the text colour. */\nfunction insertStyleOf(agent: DocAgent): React.CSSProperties {\n  const color = seriesColorOf(agent.series);\n  return {\n    textDecorationColor: color,\n    backgroundColor: `color-mix(in oklab, ${color} 14%, transparent)`,\n  };\n}\n\nexport function AgentTile({ agent }: { agent: DocAgent }) {\n  const color = seriesColorOf(agent.series);\n\n  return (\n    <MeshTile seed={agent.name} color={color} className='size-6 rounded-md' />\n  );\n}\n\nconst INSERT_CLASS =\n  'rounded-[3px] underline decoration-2 underline-offset-[3px]';\n\n/** Only these words re-render while a suggestion types itself. */\nfunction TypedInsert({\n  text,\n  agent,\n  isActive,\n}: {\n  text: string;\n  agent: DocAgent;\n  isActive: boolean;\n}) {\n  const count = useRevealedCount(text.length, isActive, TYPE_TICK_MS);\n  const typed = text.slice(0, count);\n\n  return (\n    <ins style={insertStyleOf(agent)} className={INSERT_CLASS}>\n      {typed}\n      <span\n        aria-hidden='true'\n        className='bg-foreground/60 ms-px inline-block h-[1em] w-[2px] animate-pulse rounded-full align-[-0.15em]'\n      />\n    </ins>\n  );\n}\n\nfunction pressedOf(isPressed: boolean) {\n  if (isPressed) {\n    return 'scale-90 bg-success/25';\n  }\n  return undefined;\n}\n\ntype ChangeHandlers = {\n  statuses: Record<ChangeId, ChangeStatus>;\n  pressed: string | null;\n  isActive: boolean;\n  onDecide: (id: ChangeId, decision: Decision) => void;\n};\n\nconst DECISION_BUTTON =\n  'focus-visible:ring-ring/40 inline-flex size-5 cursor-pointer items-center justify-center rounded-md outline-none transition-[background-color,scale] duration-150 focus-visible:ring-[3px] active:scale-[0.97]';\n\nfunction TrackedChangeView({\n  id,\n  statuses,\n  pressed,\n  isActive,\n  onDecide,\n}: ChangeHandlers & { id: ChangeId }) {\n  const change = CHANGES[id];\n  const agent = AGENTS[change.author];\n  const status = statuses[id];\n  const hasRemoval = change.removed !== '';\n  const isOriginal = status === 'hidden' || status === 'rejected';\n\n  if (isOriginal) {\n    return <span>{change.removed}</span>;\n  }\n  if (status === 'accepted') {\n    return (\n      <span className='bg-success/0 starting:bg-success/25 rounded-[3px] transition-colors duration-1000 ease-out'>\n        {change.inserted}\n      </span>\n    );\n  }\n  return (\n    <span>\n      {hasRemoval && (\n        <del className='text-muted-foreground decoration-foreground/40'>\n          {change.removed}\n        </del>\n      )}\n      {hasRemoval && ' '}\n      {status === 'typing' && (\n        <TypedInsert text={change.inserted} agent={agent} isActive={isActive} />\n      )}\n      {status === 'pending' && (\n        <>\n          <ins style={insertStyleOf(agent)} className={INSERT_CLASS}>\n            {change.inserted}\n          </ins>\n          <span className='bg-card hairline-ring ring-foreground/15 dark:bg-foreground/[0.08] ms-1.5 inline-flex items-center gap-0.5 rounded-lg p-0.5 align-middle shadow-[0_1px_2px_rgb(0_0_0/0.05)] transition-opacity duration-300 starting:opacity-0'>\n            <button\n              type='button'\n              aria-label={`Accept the suggestion by ${agent.name}: ${change.summary}`}\n              onClick={() => onDecide(id, 'accepted')}\n              className={cn(\n                DECISION_BUTTON,\n                'text-success-foreground hover:bg-success/15',\n                pressedOf(pressed === `accept-${id}`)\n              )}\n            >\n              <CheckIcon className='size-3.5' />\n            </button>\n            <button\n              type='button'\n              aria-label={`Reject the suggestion by ${agent.name}: ${change.summary}`}\n              onClick={() => onDecide(id, 'rejected')}\n              className={cn(\n                DECISION_BUTTON,\n                'text-destructive-ink hover:bg-destructive/10'\n              )}\n            >\n              <XIcon className='size-3.5' />\n            </button>\n          </span>\n        </>\n      )}\n    </span>\n  );\n}\n\nfunction SegmentView({\n  segment,\n  ...handlers\n}: ChangeHandlers & { segment: Segment }) {\n  if ('text' in segment) {\n    return <span>{segment.text}</span>;\n  }\n  return <TrackedChangeView id={segment.change} {...handlers} />;\n}\n\nfunction TypingDots({ name }: { name: string }) {\n  return (\n    <span className='flex h-5 items-center gap-1' role='status'>\n      <span className='sr-only'>{name} is writing a comment</span>\n      <span className='bg-muted-foreground size-1.5 animate-pulse rounded-full' />\n      <span className='bg-muted-foreground size-1.5 animate-pulse rounded-full [animation-delay:160ms]' />\n      <span className='bg-muted-foreground size-1.5 animate-pulse rounded-full [animation-delay:320ms]' />\n    </span>\n  );\n}\n\ntype MarginCommentProps = {\n  status: CommentStatus;\n  onResolve: () => void;\n};\n\nfunction MarginComment({ status, onResolve }: MarginCommentProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const rowPresence = rowPresenceOf(shouldReduceMotion);\n  const agent = AGENTS[COMMENT.author];\n  const isShown = status === 'typing' || status === 'posted';\n\n  return (\n    <AnimatePresence initial={false}>\n      {isShown && (\n        <motion.aside\n          key='comment'\n          aria-label={`Comment by ${agent.name}`}\n          className='overflow-hidden'\n          {...rowPresence}\n        >\n          <div className='bg-foreground/[0.04] mt-2 flex flex-col gap-1.5 rounded-lg p-2.5 @3xl:mt-0'>\n            <div className='flex items-center gap-2'>\n              <AgentTile agent={agent} />\n              <span className='text-xs font-medium'>{agent.name}</span>\n            </div>\n            {status === 'typing' && <TypingDots name={agent.name} />}\n            {status === 'posted' && (\n              <p className='text-[13px] leading-snug transition-opacity duration-300 starting:opacity-0'>\n                {COMMENT.text}\n              </p>\n            )}\n            {status === 'posted' && (\n              <Button\n                type='button'\n                variant='ghost'\n                size='sm'\n                onClick={onResolve}\n                className='text-muted-foreground -ms-1.5 w-fit'\n              >\n                Resolve\n              </Button>\n            )}\n          </div>\n        </motion.aside>\n      )}\n    </AnimatePresence>\n  );\n}\n\ntype ParagraphRowProps = ChangeHandlers & {\n  paragraph: Paragraph;\n  comment: CommentStatus;\n  onResolveComment: () => void;\n};\n\nexport function ParagraphRow({\n  paragraph,\n  comment,\n  onResolveComment,\n  ...handlers\n}: ParagraphRowProps) {\n  const hasComment = COMMENT.paragraph === paragraph.id;\n\n  return (\n    <div className='grid gap-x-6 @3xl:grid-cols-[minmax(0,1fr)_14rem]'>\n      <div className='flex flex-col gap-1'>\n        <h3 className='text-sm font-semibold'>{paragraph.heading}</h3>\n        <p data-paragraph={paragraph.id} className='text-sm leading-7'>\n          {paragraph.segments.map((segment, index) => (\n            <SegmentView key={index} segment={segment} {...handlers} />\n          ))}\n        </p>\n      </div>\n      <div>\n        {hasComment && (\n          <MarginComment status={comment} onResolve={onResolveComment} />\n        )}\n      </div>\n    </div>\n  );\n}\n\nfunction idleToneOf(isIdle: boolean) {\n  if (isIdle) {\n    return 'opacity-0';\n  }\n  return 'opacity-100';\n}\n\ntype AgentPointerProps = {\n  agent: DocAgent;\n  pointer: Pointer;\n};\n\n/** The pointer glides with a transition on its position and fades once its agent has nothing to do. */\nexport function AgentPointer({ agent, pointer }: AgentPointerProps) {\n  const isIdle = pointer.target === null;\n  const iconStyle = { color: seriesColorOf(agent.series) };\n\n  return (\n    <span\n      data-pointer={agent.id}\n      aria-hidden='true'\n      className={cn(\n        'pointer-events-none absolute top-0 left-0 z-10 flex items-start transition-[translate,opacity] duration-700 ease-(--ease-in-out-strong) motion-reduce:transition-none',\n        idleToneOf(isIdle)\n      )}\n    >\n      <MousePointerIcon style={iconStyle} className='size-4 fill-current' />\n      <span\n        style={gemStyleOf(agent)}\n        className='gem-plate mt-3 flex items-center gap-1.5 rounded-full px-2 py-0.5 text-[11px] font-medium whitespace-nowrap'\n      >\n        {agent.name}\n        <span className='opacity-80'>{pointer.action}</span>\n        <span className='tabular-nums'>{formatCost(pointer.spendUsd)}</span>\n      </span>\n    </span>\n  );\n}\n\n/** Where along its paragraph each agent rests, so two pointers on one paragraph do not cover each other. */\nexport const POINTER_REACH: Record<AgentId, number> = {\n  writer: 0.42,\n  reviewer: 0.12,\n};\n",
      "type": "registry:component",
      "target": "components/blocks/agent-review-05/doc-parts.tsx"
    },
    {
      "path": "registry/ndeko/blocks/agent-review/agent-review-05/session.ts",
      "content": "import type { SessionStep } from '@/registry/ndeko/hooks/use-session';\n\nimport {\n  CHANGE_ORDER,\n  type AgentId,\n  type ChangeId,\n  type ParagraphId,\n} from './data';\n\nexport type DocView = 'doc' | 'table';\n\nexport type ChangeStatus =\n  'hidden' | 'typing' | 'pending' | 'accepted' | 'rejected';\n\nexport type CommentStatus = 'hidden' | 'typing' | 'posted' | 'resolved';\n\nexport type Pointer = {\n  /** The paragraph the agent is on, or null while it is idle and its pointer fades. */\n  target: ParagraphId | null;\n  action: string;\n  spendUsd: number;\n};\n\nexport type DocState = {\n  view: DocView;\n  pointers: Record<AgentId, Pointer>;\n  changes: Record<ChangeId, ChangeStatus>;\n  comment: CommentStatus;\n};\n\nexport type Decision = 'accepted' | 'rejected';\n\nexport type DocAction =\n  | { type: 'pointer'; agent: AgentId; pointer: Pointer }\n  | { type: 'change'; id: ChangeId; status: ChangeStatus }\n  | { type: 'comment'; status: CommentStatus }\n  | { type: 'decided'; id: ChangeId; decision: Decision }\n  | { type: 'acceptAll' }\n  | { type: 'view'; view: DocView }\n  | { type: 'batch'; actions: DocAction[] };\n\ntype Step = SessionStep<DocState, DocAction>;\n\nconst IDLE: Pointer = { target: null, action: 'Idle', spendUsd: 0 };\n\nexport const INITIAL: DocState = {\n  view: 'doc',\n  pointers: { writer: IDLE, reviewer: IDLE },\n  changes: { c1: 'hidden', c2: 'hidden' },\n  comment: 'hidden',\n};\n\nexport function pendingIdsOf(state: DocState) {\n  return CHANGE_ORDER.filter((id) => state.changes[id] === 'pending');\n}\n\nfunction decided(state: DocState, id: ChangeId, decision: Decision): DocState {\n  if (state.changes[id] !== 'pending') {\n    return state;\n  }\n  return { ...state, changes: { ...state.changes, [id]: decision } };\n}\n\nfunction acceptAll(state: DocState): DocState {\n  let next = state;\n  for (const id of pendingIdsOf(state)) {\n    next = decided(next, id, 'accepted');\n  }\n  return next;\n}\n\nexport function reducer(state: DocState, action: DocAction): DocState {\n  switch (action.type) {\n    case 'pointer': {\n      const pointers = { ...state.pointers, [action.agent]: action.pointer };\n      return { ...state, pointers };\n    }\n    case 'change': {\n      const changes = { ...state.changes, [action.id]: action.status };\n      return { ...state, changes };\n    }\n    case 'comment':\n      return { ...state, comment: action.status };\n    case 'decided':\n      return decided(state, action.id, action.decision);\n    case 'acceptAll':\n      return acceptAll(state);\n    case 'view':\n      return { ...state, view: action.view };\n    case 'batch': {\n      let next = state;\n      for (const inner of action.actions) {\n        next = reducer(next, inner);\n      }\n      return next;\n    }\n  }\n}\n\nfunction frame(after: number, actions: DocAction[]): Step {\n  return { after, action: { type: 'batch', actions } };\n}\n\nfunction pointing(\n  agent: AgentId,\n  target: ParagraphId | null,\n  action: string,\n  spendUsd: number\n): DocAction {\n  return { type: 'pointer', agent, pointer: { target, action, spendUsd } };\n}\n\nfunction hasDecidedFirst(state: DocState) {\n  return state.changes.c1 !== 'pending';\n}\n\nfunction hasNothingPending(state: DocState) {\n  return pendingIdsOf(state).length === 0;\n}\n\n/** One character every tick while a suggestion types itself. */\nexport const TYPE_TICK_MS = 45;\n\n/** A request that waits on a person is answered by the demonstration after this long. */\nconst DECIDE_AFTER_MS = 2500;\n\nexport const SCRIPT: Step[] = [\n  frame(800, [pointing('writer', 'proposal', 'Reading', 0.004)]),\n  frame(1300, [\n    pointing('writer', 'proposal', 'Suggesting an edit', 0.007),\n    { type: 'change', id: 'c1', status: 'typing' },\n  ]),\n  frame(2100, [\n    { type: 'change', id: 'c1', status: 'pending' },\n    pointing('writer', 'proposal', 'Suggested an edit', 0.011),\n    pointing('reviewer', 'problem', 'Reading', 0.003),\n  ]),\n  frame(1200, [\n    pointing('reviewer', 'problem', 'Commenting', 0.005),\n    { type: 'comment', status: 'typing' },\n  ]),\n  frame(1600, [\n    { type: 'comment', status: 'posted' },\n    pointing('reviewer', null, 'Idle', 0.007),\n    pointing('writer', 'measure', 'Suggesting an edit', 0.013),\n    { type: 'change', id: 'c2', status: 'typing' },\n  ]),\n  frame(1500, [\n    { type: 'change', id: 'c2', status: 'pending' },\n    pointing('writer', null, 'Idle', 0.016),\n  ]),\n  {\n    after: DECIDE_AFTER_MS,\n    by: 'person',\n    press: 'accept-c1',\n    action: { type: 'decided', id: 'c1', decision: 'accepted' },\n    isAnswered: hasDecidedFirst,\n  },\n  { after: 1500, by: 'demo', action: { type: 'view', view: 'table' } },\n  { after: 2300, by: 'demo', action: { type: 'view', view: 'doc' } },\n  {\n    after: 1400,\n    by: 'person',\n    press: 'accept-all',\n    action: { type: 'acceptAll' },\n    isAnswered: hasNothingPending,\n  },\n];\n\nfunction restingOf() {\n  let state = INITIAL;\n  for (const step of SCRIPT) {\n    const isLastStep = step === SCRIPT.at(-1);\n    if (!isLastStep) {\n      state = reducer(state, step.action);\n    }\n  }\n  return reducer(state, { type: 'view', view: 'doc' });\n}\n\n/** Under reduced motion the document rests with one suggestion still to decide, so the tracked change reads. */\nexport const RESTING = restingOf();\n\nexport const LOOP_AFTER_MS = 3400;\n",
      "type": "registry:component",
      "target": "components/blocks/agent-review-05/session.ts"
    },
    {
      "path": "registry/ndeko/blocks/agent-review/agent-review-05/data.ts",
      "content": "import type { SeriesSlot } from '@/registry/ndeko/lib/agent-run';\n\nexport type AgentId = 'writer' | 'reviewer';\n\nexport type DocAgent = {\n  id: AgentId;\n  name: string;\n  series: SeriesSlot;\n};\n\nexport const AGENTS: Record<AgentId, DocAgent> = {\n  writer: { id: 'writer', name: 'Writer', series: 3 },\n  reviewer: { id: 'reviewer', name: 'Reviewer', series: 4 },\n};\n\nexport const AGENT_ORDER: AgentId[] = ['writer', 'reviewer'];\n\nexport const DOC_TITLE = 'Invoice export: product brief';\n\nexport type ChangeId = 'c1' | 'c2';\n\nexport type TrackedChange = {\n  id: ChangeId;\n  author: AgentId;\n  /** What the suggestion strikes out; empty for a pure insertion. */\n  removed: string;\n  inserted: string;\n  /** A short name for the table. */\n  summary: string;\n};\n\nexport const CHANGES: Record<ChangeId, TrackedChange> = {\n  c1: {\n    id: 'c1',\n    author: 'writer',\n    removed: 'a button',\n    inserted: 'an Export button in the invoices table',\n    summary: 'Names where the button lives',\n  },\n  c2: {\n    id: 'c2',\n    author: 'writer',\n    removed: '',\n    inserted: ' within the first month',\n    summary: 'Adds a deadline to the measure',\n  },\n};\n\nexport const CHANGE_ORDER: ChangeId[] = ['c1', 'c2'];\n\nexport type ParagraphId = 'problem' | 'proposal' | 'measure';\n\nexport type Segment = { text: string } | { change: ChangeId };\n\nexport type Paragraph = {\n  id: ParagraphId;\n  heading: string;\n  segments: Segment[];\n};\n\nexport const PARAGRAPHS: Paragraph[] = [\n  {\n    id: 'problem',\n    heading: 'Problem',\n    segments: [\n      {\n        text: 'Finance teams copy invoices into a spreadsheet by hand at the end of every month. It takes hours and the totals drift from what the app shows.',\n      },\n    ],\n  },\n  {\n    id: 'proposal',\n    heading: 'Proposal',\n    segments: [\n      { text: 'Add ' },\n      { change: 'c1' },\n      {\n        text: ' that downloads what the current filters show, with dates in ISO format and amounts in the invoice currency.',\n      },\n    ],\n  },\n  {\n    id: 'measure',\n    heading: 'Success measure',\n    segments: [\n      { text: 'Half of the accounts with a finance seat use the export' },\n      { change: 'c2' },\n      { text: '.' },\n    ],\n  },\n];\n\nexport const COMMENT = {\n  author: 'reviewer' as AgentId,\n  paragraph: 'problem' as ParagraphId,\n  text: 'Which finance teams did we ask? A number here would make the case.',\n  summary: 'Asks for a source on the problem',\n};\n",
      "type": "registry:component",
      "target": "components/blocks/agent-review-05/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "agent-review"
  ],
  "type": "registry:block"
}