{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "review-08",
  "title": "Branch conflicts",
  "description": "A file by agent grid of live edits where a conflict opens both approaches side by side, Use or Combine settles it, and Merge waits until none is open.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/agent-run.json",
    "https://ui.ndekocode.dev/r/animated-size.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/mesh-tile.json",
    "https://ui.ndekocode.dev/r/morph-button.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/theme.json",
    "https://ui.ndekocode.dev/r/use-agent-run.json",
    "https://ui.ndekocode.dev/r/use-demo-run.json",
    "https://ui.ndekocode.dev/r/use-kept-height.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/use-timeouts.json",
    "https://ui.ndekocode.dev/r/utils.json",
    "https://ui.ndekocode.dev/r/words.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/review/review-08.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport { useId, useState } from 'react';\n\nimport { WordRoll } from '@/components/core/word-roll';\nimport type { RunScriptStep } from '@/registry/ndeko/hooks/use-agent-run';\nimport { useDemoRun } from '@/registry/ndeko/hooks/use-demo-run';\nimport { useKeptHeight } from '@/registry/ndeko/hooks/use-kept-height';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { useTimeouts } from '@/registry/ndeko/hooks/use-timeouts';\nimport {\n  emptyRun,\n  seriesColorOf,\n  type RunEvent,\n  type RunSnapshot,\n  type SeriesSlot,\n} from '@/registry/ndeko/lib/agent-run';\nimport {\n  CheckIcon,\n  ChevronDownIcon,\n  GitMergeIcon,\n  TriangleAlertIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { risePresenceOf } from '@/registry/ndeko/lib/motion-presets';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { countOf } from '@/registry/ndeko/lib/words';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Fold, Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { MeshTile } from '@/registry/ndeko/ui/mesh-tile';\nimport { MorphButton, type MorphState } from '@/registry/ndeko/ui/morph-button';\nimport { ReplayButton } from '@/registry/ndeko/ui/replay-button';\n\nimport { pathPartsOf } from './_parts/path-parts';\n\nexport type MatrixAgent = {\n  id: string;\n  name: string;\n  series: SeriesSlot;\n};\n\nexport type MatrixFile = {\n  id: string;\n  path: string;\n};\n\nexport type EditState = 'untouched' | 'writing' | 'changed';\n\nexport type Approach = {\n  summary: string;\n  lines: string[];\n};\n\nexport type Conflict = {\n  fileId: string;\n  /** Where the two edits overlap: \"lines 16 to 19\". */\n  where: string;\n  agents: [string, string];\n  approaches: Record<string, Approach>;\n  combined: Approach;\n};\n\nexport type Settlement = {\n  /** The agent whose approach was kept, or \"combined\". */\n  choice: string;\n};\n\nconst CELL_WORD: Record<EditState, string> = {\n  untouched: 'untouched',\n  writing: 'writing',\n  changed: 'changed',\n};\n\nfunction callIdOf(agentId: string, fileId: string) {\n  return `${agentId}:${fileId}`;\n}\n\nexport function editStateOf(\n  run: RunSnapshot,\n  agentId: string,\n  fileId: string\n): EditState {\n  const callId = callIdOf(agentId, fileId);\n  const call = run.calls.find((candidate) => candidate.id === callId);\n  if (!call) {\n    return 'untouched';\n  }\n  if (call.status === 'done') {\n    return 'changed';\n  }\n  return 'writing';\n}\n\nfunction hasChanged(run: RunSnapshot, agentId: string, fileId: string) {\n  const state = editStateOf(run, agentId, fileId);\n  return state === 'changed';\n}\n\n/** Two agents changed the same lines once both of their edits have landed. */\nfunction isConflictVisible(conflict: Conflict, run: RunSnapshot) {\n  const [first, second] = conflict.agents;\n  const isFirstDone = hasChanged(run, first, conflict.fileId);\n  const isSecondDone = hasChanged(run, second, conflict.fileId);\n  return isFirstDone && isSecondDone;\n}\n\nfunction isConflictOpen(\n  conflict: Conflict,\n  run: RunSnapshot,\n  settlements: Record<string, Settlement>\n) {\n  const isVisible = isConflictVisible(conflict, run);\n  const isSettled = settlements[conflict.fileId] !== undefined;\n  return isVisible && !isSettled;\n}\n\nfunction KeptMark({ color }: { color: string }) {\n  const style = { '--gem': color } as React.CSSProperties;\n\n  return (\n    <span\n      aria-hidden='true'\n      style={style}\n      className='gem-plate inline-flex size-3.5 items-center justify-center rounded-[4px]'\n    >\n      <CheckIcon className='size-2.5' strokeWidth={3} />\n    </span>\n  );\n}\n\nfunction EditCell({\n  state,\n  agent,\n  isKept,\n}: {\n  state: EditState;\n  agent: MatrixAgent;\n  isKept: boolean;\n}) {\n  const color = seriesColorOf(agent.series);\n  const style = { backgroundColor: color } as React.CSSProperties;\n  const markKey = cellKeyOf(state, isKept);\n\n  return (\n    <span className='flex h-9 items-center justify-center'>\n      <Swap swapKey={markKey} className='size-3.5 justify-center'>\n        {isKept && <KeptMark color={color} />}\n        {!isKept && <CellMark state={state} style={style} />}\n      </Swap>\n      <span className='sr-only'>\n        {agent.name}: {CELL_WORD[state]}\n        {isKept && ', kept'}\n      </span>\n    </span>\n  );\n}\n\nfunction cellKeyOf(state: EditState, isKept: boolean) {\n  if (isKept) {\n    return 'kept';\n  }\n  return state;\n}\n\nfunction CellMark({\n  state,\n  style,\n}: {\n  state: EditState;\n  style: React.CSSProperties;\n}) {\n  if (state === 'writing') {\n    return (\n      <span\n        aria-hidden='true'\n        style={style}\n        className='size-2.5 animate-pulse rounded-full'\n      />\n    );\n  }\n  if (state === 'changed') {\n    return (\n      <span\n        aria-hidden='true'\n        style={style}\n        className='size-2.5 rounded-[3px]'\n      />\n    );\n  }\n  return (\n    <span\n      aria-hidden='true'\n      className='bg-foreground/15 size-1.5 rounded-full'\n    />\n  );\n}\n\ntype ApproachCardProps = {\n  agent: MatrixAgent;\n  approach: Approach;\n  where: string;\n  onUse: () => void;\n};\n\nfunction ApproachCard({ agent, approach, where, onUse }: ApproachCardProps) {\n  return (\n    <div className='bg-foreground/[0.03] dark:bg-foreground/[0.05] flex min-w-0 flex-col gap-2 rounded-lg p-3'>\n      <div className='flex items-center gap-2'>\n        <MeshTile seed={agent.name} color={seriesColorOf(agent.series)} />\n        <span className='min-w-0 flex-1 truncate text-[13px] font-medium'>\n          {agent.name}&rsquo;s approach\n        </span>\n        <span className='text-muted-foreground shrink-0 text-xs'>{where}</span>\n      </div>\n      <p className='text-muted-foreground text-xs leading-5'>\n        {approach.summary}\n      </p>\n      <pre className='bg-card hairline-ring ring-border overflow-x-auto rounded-md p-2 font-mono text-xs leading-5'>\n        <code>{approach.lines.join('\\n')}</code>\n      </pre>\n      <Button\n        type='button'\n        variant='outline'\n        size='sm'\n        onClick={onUse}\n        className='self-start'\n      >\n        Use {agent.name}&rsquo;s\n      </Button>\n    </div>\n  );\n}\n\ntype ConflictPanelProps = {\n  conflict: Conflict;\n  agents: MatrixAgent[];\n  onSettle: (choice: string) => void;\n};\n\ntype Side = {\n  agent: MatrixAgent;\n  approach: Approach;\n};\n\nfunction sidesOf(conflict: Conflict, agents: MatrixAgent[]) {\n  const sides: Side[] = [];\n  for (const agentId of conflict.agents) {\n    const agent = agents.find((candidate) => candidate.id === agentId);\n    const approach = conflict.approaches[agentId];\n    if (!agent) {\n      continue;\n    }\n    if (!approach) {\n      continue;\n    }\n    sides.push({ agent, approach });\n  }\n  return sides;\n}\n\nfunction ConflictPanel({ conflict, agents, onSettle }: ConflictPanelProps) {\n  const [isCombining, setIsCombining] = useState(false);\n  const sides = sidesOf(conflict, agents);\n\n  return (\n    <AnimatedSize>\n      <div className='flex flex-col gap-3 px-1 pt-1 pb-3'>\n        {!isCombining && (\n          <>\n            <div className='grid grid-cols-1 gap-2 @xl:grid-cols-2'>\n              {sides.map((side) => (\n                <ApproachCard\n                  key={side.agent.id}\n                  agent={side.agent}\n                  approach={side.approach}\n                  where={conflict.where}\n                  onUse={() => onSettle(side.agent.id)}\n                />\n              ))}\n            </div>\n            <Button\n              type='button'\n              variant='ghost'\n              size='sm'\n              onClick={() => setIsCombining(true)}\n              className='self-start'\n            >\n              <GitMergeIcon />\n              Combine\n            </Button>\n          </>\n        )}\n        {isCombining && (\n          <div className='bg-foreground/[0.03] dark:bg-foreground/[0.05] flex flex-col gap-2 rounded-lg p-3 transition-opacity duration-200 starting:opacity-0'>\n            <span className='text-[13px] font-medium'>Combined</span>\n            <p className='text-muted-foreground text-xs leading-5'>\n              {conflict.combined.summary}\n            </p>\n            <pre className='bg-card hairline-ring ring-border overflow-x-auto rounded-md p-2 font-mono text-xs leading-5'>\n              <code>{conflict.combined.lines.join('\\n')}</code>\n            </pre>\n            <span className='flex flex-wrap items-center gap-2'>\n              <Button\n                type='button'\n                size='sm'\n                onClick={() => onSettle('combined')}\n              >\n                Keep combined\n              </Button>\n              <Button\n                type='button'\n                variant='ghost'\n                size='sm'\n                onClick={() => setIsCombining(false)}\n              >\n                Back to both\n              </Button>\n            </span>\n          </div>\n        )}\n      </div>\n    </AnimatedSize>\n  );\n}\n\nfunction keptWordsOf(settlement: Settlement, agents: MatrixAgent[]) {\n  if (settlement.choice === 'combined') {\n    return 'Combined';\n  }\n  const agent = agents.find((candidate) => candidate.id === settlement.choice);\n  const name = agent?.name ?? 'One';\n  return `${name}’s kept`;\n}\n\nfunction chevronTurnOf(isOpen: boolean) {\n  if (isOpen) {\n    return 'rotate-180';\n  }\n  return 'rotate-0';\n}\n\ntype FileCellProps = {\n  file: MatrixFile;\n  conflict: Conflict | undefined;\n  isConflictShown: boolean;\n  settlement: Settlement | undefined;\n  agents: MatrixAgent[];\n  isOpen: boolean;\n  panelId: string;\n  onToggle: () => void;\n};\n\nfunction FileCell({\n  file,\n  conflict,\n  isConflictShown,\n  settlement,\n  agents,\n  isOpen,\n  panelId,\n  onToggle,\n}: FileCellProps) {\n  const { folder, name } = pathPartsOf(file.path);\n  const isSelectable = conflict !== undefined && isConflictShown;\n  const isOpenConflict = isSelectable && settlement === undefined;\n  const path = (\n    <span className='min-w-0 truncate font-mono text-xs'>\n      <span className='text-muted-foreground hidden @md:inline'>{folder}</span>\n      {name}\n    </span>\n  );\n\n  if (!isSelectable) {\n    return <span className='flex h-9 min-w-0 items-center px-2'>{path}</span>;\n  }\n\n  return (\n    <button\n      type='button'\n      aria-expanded={isOpen}\n      aria-controls={panelId}\n      onClick={onToggle}\n      className='hover:bg-foreground/[0.04] focus-visible:ring-ring/25 flex h-9 w-full min-w-0 cursor-pointer items-center gap-1.5 rounded-md px-2 text-start outline-none focus-visible:ring-[3px]'\n    >\n      <Swap swapKey={String(isOpenConflict)} className='size-3.5 shrink-0'>\n        {isOpenConflict && (\n          <TriangleAlertIcon className='text-warning-foreground size-3.5' />\n        )}\n        {!isOpenConflict && (\n          <CheckIcon className='text-success-foreground size-3.5' />\n        )}\n      </Swap>\n      {path}\n      <span className='text-muted-foreground ms-auto hidden shrink-0 text-[11px] @sm:inline'>\n        {settlement && keptWordsOf(settlement, agents)}\n        {!settlement && 'Conflict'}\n      </span>\n      <ChevronDownIcon\n        className={cn(\n          'text-muted-foreground size-3.5 shrink-0 transition-transform duration-200 ease-(--ease-out-strong)',\n          chevronTurnOf(isOpen)\n        )}\n      />\n    </button>\n  );\n}\n\nfunction mergeLabelsOf(\n  writingCount: number,\n  openCount: number,\n  branchCount: number\n): Record<MorphState, string> {\n  const idle = idleMergeLabelOf(writingCount, openCount, branchCount);\n  return { idle, busy: 'Merging', done: 'Merged' };\n}\n\nfunction idleMergeLabelOf(\n  writingCount: number,\n  openCount: number,\n  branchCount: number\n) {\n  if (writingCount > 0) {\n    return 'Merge when the agents finish';\n  }\n  if (openCount > 0) {\n    const conflicts = countOf(openCount, 'conflict');\n    return `Merge, ${conflicts} open`;\n  }\n  const branches = countOf(branchCount, 'branch', 'branches');\n  return `Merge ${branches}`;\n}\n\nfunction mergeVariantOf(canMerge: boolean) {\n  if (canMerge) {\n    return 'default';\n  }\n  return 'outline';\n}\n\nfunction writingCountOf(run: RunSnapshot) {\n  const writing = run.calls.filter((call) => call.status === 'running');\n  return writing.length;\n}\n\nfunction activityWordsOf(writingCount: number, openCount: number) {\n  if (writingCount > 0) {\n    const agents = countOf(writingCount, 'agent');\n    return `${agents} writing`;\n  }\n  if (openCount > 0) {\n    return 'Agents done, conflicts to settle';\n  }\n  return 'Every change settled';\n}\n\nexport type ConflictMatrixProps = {\n  agents: MatrixAgent[];\n  files: MatrixFile[];\n  conflicts: Conflict[];\n  run: RunSnapshot;\n  settlements: Record<string, Settlement>;\n  onSettle: (fileId: string, choice: string) => void;\n};\n\nexport function ConflictMatrix({\n  agents,\n  files,\n  conflicts,\n  run,\n  settlements,\n  onSettle,\n}: ConflictMatrixProps) {\n  const [openFileId, setOpenFileId] = useState<string | null>(null);\n  const baseId = useId();\n\n  function toggle(fileId: string) {\n    setOpenFileId((current) => {\n      if (current === fileId) {\n        return null;\n      }\n      return fileId;\n    });\n  }\n\n  function settle(fileId: string, choice: string) {\n    onSettle(fileId, choice);\n    setOpenFileId(null);\n  }\n\n  return (\n    <table className='w-full table-fixed border-separate border-spacing-0'>\n      <caption className='sr-only'>\n        Files each agent is editing, with conflicts between them\n      </caption>\n      <colgroup>\n        <col />\n        {agents.map((agent) => (\n          <col key={agent.id} className='w-11 @md:w-20' />\n        ))}\n      </colgroup>\n      <thead>\n        <tr className='text-muted-foreground text-xs'>\n          <th scope='col' className='h-8 px-2 text-start font-normal'>\n            File\n          </th>\n          {agents.map((agent) => (\n            <th key={agent.id} scope='col' className='h-8 font-normal'>\n              <span className='flex items-center justify-center gap-1.5'>\n                <MeshTile\n                  seed={agent.name}\n                  color={seriesColorOf(agent.series)}\n                />\n                <span className='hidden truncate @md:inline'>{agent.name}</span>\n                <span className='sr-only @md:hidden'>{agent.name}</span>\n              </span>\n            </th>\n          ))}\n        </tr>\n      </thead>\n      <tbody>\n        {files.map((file) => {\n          const conflict = conflicts.find((entry) => entry.fileId === file.id);\n          const isShown = conflictShownOf(conflict, run);\n          const settlement = settlements[file.id];\n          const isOpen = openFileId === file.id;\n          const panelId = `${baseId}-${file.id}`;\n          return (\n            <FileRows\n              key={file.id}\n              file={file}\n              agents={agents}\n              conflict={conflict}\n              isConflictShown={isShown}\n              settlement={settlement}\n              isOpen={isOpen}\n              panelId={panelId}\n              run={run}\n              onToggle={() => toggle(file.id)}\n              onSettle={(choice) => settle(file.id, choice)}\n            />\n          );\n        })}\n      </tbody>\n    </table>\n  );\n}\n\nfunction conflictShownOf(conflict: Conflict | undefined, run: RunSnapshot) {\n  if (!conflict) {\n    return false;\n  }\n  return isConflictVisible(conflict, run);\n}\n\nfunction rowToneOf(isOpenConflict: boolean) {\n  if (isOpenConflict) {\n    return 'bg-warning/[0.07]';\n  }\n  return '';\n}\n\ntype FileRowsProps = {\n  file: MatrixFile;\n  agents: MatrixAgent[];\n  conflict: Conflict | undefined;\n  isConflictShown: boolean;\n  settlement: Settlement | undefined;\n  isOpen: boolean;\n  panelId: string;\n  run: RunSnapshot;\n  onToggle: () => void;\n  onSettle: (choice: string) => void;\n};\n\nfunction FileRows({\n  file,\n  agents,\n  conflict,\n  isConflictShown,\n  settlement,\n  isOpen,\n  panelId,\n  run,\n  onToggle,\n  onSettle,\n}: FileRowsProps) {\n  const isOpenConflict = isConflictShown && settlement === undefined;\n  const panelConflict = panelConflictOf(conflict, isConflictShown);\n  const columnCount = agents.length + 1;\n\n  return (\n    <>\n      <tr\n        className={cn(\n          'transition-colors duration-200',\n          rowToneOf(isOpenConflict)\n        )}\n      >\n        <th scope='row' className='p-0 text-start font-normal'>\n          <FileCell\n            file={file}\n            conflict={conflict}\n            isConflictShown={isConflictShown}\n            settlement={settlement}\n            agents={agents}\n            isOpen={isOpen}\n            panelId={panelId}\n            onToggle={onToggle}\n          />\n        </th>\n        {agents.map((agent) => {\n          const state = editStateOf(run, agent.id, file.id);\n          const isKept = isKeptBy(settlement, agent.id);\n          return (\n            <td key={agent.id} className='p-0'>\n              <EditCell state={state} agent={agent} isKept={isKept} />\n            </td>\n          );\n        })}\n      </tr>\n      {panelConflict && (\n        <tr>\n          <td colSpan={columnCount} className='p-0'>\n            <Fold open={isOpen} id={panelId}>\n              <ConflictPanel\n                conflict={panelConflict}\n                agents={agents}\n                onSettle={onSettle}\n              />\n            </Fold>\n          </td>\n        </tr>\n      )}\n    </>\n  );\n}\n\nfunction panelConflictOf(conflict: Conflict | undefined, isShown: boolean) {\n  if (!isShown) {\n    return undefined;\n  }\n  return conflict;\n}\n\nfunction isKeptBy(settlement: Settlement | undefined, agentId: string) {\n  if (!settlement) {\n    return false;\n  }\n  const isChosen = settlement.choice === agentId;\n  const isCombined = settlement.choice === 'combined';\n  return isChosen || isCombined;\n}\n\nconst AGENTS: MatrixAgent[] = [\n  { id: 'coder', name: 'Coder', series: 5 },\n  { id: 'reviewer', name: 'Reviewer', series: 4 },\n  { id: 'writer', name: 'Writer', series: 3 },\n];\n\nconst FILES: MatrixFile[] = [\n  { id: 'fee', path: 'src/billing/pallet-fee.ts' },\n  { id: 'tiers', path: 'src/billing/pallet-tiers.ts' },\n  { id: 'checkout', path: 'src/orders/checkout.ts' },\n  { id: 'test', path: 'src/billing/pallet-fee.test.ts' },\n  { id: 'docs', path: 'docs/pricing.md' },\n];\n\nconst CONFLICTS: Conflict[] = [\n  {\n    fileId: 'fee',\n    where: 'lines 16 to 18',\n    agents: ['coder', 'reviewer'],\n    approaches: {\n      coder: {\n        summary: 'Checks the pallet count where the fee is billed.',\n        lines: [\n          'if (order.pallets >= FLAT_FROM_PALLETS) {',\n          '  return money(order.pallets * FLAT_FEE_EUR);',\n          '}',\n        ],\n      },\n      reviewer: {\n        summary:\n          'Moves the check into isFlatOrder, which also looks at the start date.',\n        lines: [\n          'if (isFlatOrder(order)) {',\n          '  return money(order.pallets * FLAT_FEE_EUR);',\n          '}',\n        ],\n      },\n    },\n    combined: {\n      summary:\n        'Keeps the helper from Reviewer and names the result as Coder did.',\n      lines: [\n        'const isFlat = isFlatOrder(order);',\n        'if (isFlat) {',\n        '  return money(order.pallets * FLAT_FEE_EUR);',\n        '}',\n      ],\n    },\n  },\n  {\n    fileId: 'docs',\n    where: 'line 3',\n    agents: ['writer', 'reviewer'],\n    approaches: {\n      writer: {\n        summary: 'Leads with the date the change starts.',\n        lines: [\n          'From 1 October, orders of 40 pallets or more pay a flat 18.40 EUR per pallet.',\n        ],\n      },\n      reviewer: {\n        summary: 'Adds the year so the page still reads right next autumn.',\n        lines: [\n          'Orders of 40 pallets or more pay 18.40 EUR per pallet from 1 October 2026.',\n        ],\n      },\n    },\n    combined: {\n      summary: 'The order of Writer with the year of Reviewer.',\n      lines: [\n        'From 1 October 2026, orders of 40 pallets or more pay a flat 18.40 EUR per pallet.',\n      ],\n    },\n  },\n];\n\nfunction startEdit(agentId: string, fileId: string): RunEvent {\n  return {\n    type: 'call.started',\n    call: {\n      id: callIdOf(agentId, fileId),\n      tool: 'edit_file',\n      label: fileId,\n      agentId,\n      status: 'running',\n    },\n  };\n}\n\nfunction finishEdit(agentId: string, fileId: string): RunEvent {\n  return {\n    type: 'call.updated',\n    id: callIdOf(agentId, fileId),\n    patch: { status: 'done' },\n  };\n}\n\nconst SCRIPT: RunScriptStep[] = [\n  { after: 400, event: { type: 'run.started' } },\n  { after: 0, event: startEdit('coder', 'fee') },\n  { after: 150, event: startEdit('reviewer', 'checkout') },\n  { after: 150, event: startEdit('writer', 'docs') },\n  { after: 900, event: finishEdit('coder', 'fee') },\n  { after: 0, event: startEdit('coder', 'tiers') },\n  { after: 500, event: finishEdit('reviewer', 'checkout') },\n  { after: 0, event: startEdit('reviewer', 'fee') },\n  { after: 600, event: finishEdit('writer', 'docs') },\n  { after: 0, event: finishEdit('coder', 'tiers') },\n  { after: 0, event: startEdit('coder', 'test') },\n  { after: 700, event: finishEdit('reviewer', 'fee') },\n  { after: 200, event: startEdit('reviewer', 'docs') },\n  { after: 700, event: finishEdit('coder', 'test') },\n  { after: 500, event: finishEdit('reviewer', 'docs') },\n  { after: 0, event: { type: 'run.finished', status: 'done' } },\n];\n\nconst INITIAL_RUN = emptyRun({ id: 'conflicts', title: 'Flat fee branches' });\n\nconst MERGING_MS = 900;\n\nfunction openCountOf(\n  run: RunSnapshot,\n  settlements: Record<string, Settlement>\n) {\n  const open = CONFLICTS.filter((conflict) =>\n    isConflictOpen(conflict, run, settlements)\n  );\n  return open.length;\n}\n\nfunction settleNoticeOf(fileId: string, choice: string) {\n  const file = FILES.find((candidate) => candidate.id === fileId);\n  const { name } = pathPartsOf(file?.path ?? fileId);\n  if (choice === 'combined') {\n    return `Kept the combined change in ${name}`;\n  }\n  const agent = AGENTS.find((candidate) => candidate.id === choice);\n  return `Kept the change from ${agent?.name ?? 'one agent'} in ${name}`;\n}\n\nexport default function Review08() {\n  const [settlements, setSettlements] = useState<Record<string, Settlement>>(\n    {}\n  );\n  const [mergeState, setMergeState] = useState<MorphState>('idle');\n  const [notice, setNotice] = useState('');\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const risePresence = risePresenceOf(shouldReduceMotion);\n  const { schedule, clearAll } = useTimeouts();\n  const { ref, snapshot, restart } = useDemoRun(SCRIPT, {\n    initial: INITIAL_RUN,\n  });\n  const writingCount = writingCountOf(snapshot);\n  const openCount = openCountOf(snapshot, settlements);\n  const isQuiet = writingCount === 0;\n  const hasNoConflict = openCount === 0;\n  const isRunDone = snapshot.status === 'done';\n  const isReady = isQuiet && hasNoConflict;\n  const canMerge = isReady && isRunDone;\n  const isMerged = mergeState === 'done';\n  const activity = activityWordsOf(writingCount, openCount);\n  const branchCount = AGENTS.length;\n  const labels = mergeLabelsOf(writingCount, openCount, branchCount);\n\n  function settle(fileId: string, choice: string) {\n    setSettlements((current) => ({ ...current, [fileId]: { choice } }));\n    setNotice(settleNoticeOf(fileId, choice));\n  }\n\n  function merge() {\n    if (!canMerge) {\n      return;\n    }\n    setMergeState('busy');\n    schedule(() => {\n      setMergeState('done');\n      const branches = countOf(branchCount, 'branch', 'branches');\n      setNotice(`Merged ${branches} into main`);\n    }, MERGING_MS);\n  }\n\n  function replay() {\n    clearAll();\n    setSettlements({});\n    setMergeState('idle');\n    setNotice('');\n    restart();\n  }\n\n  useKeptHeight(ref);\n\n  return (\n    <div\n      ref={ref}\n      className='bg-card hairline-ring ring-border @container flex w-full max-w-[44rem] flex-col gap-3 rounded-xl p-3 shadow-[0_1px_2px_rgb(0_0_0/0.04)]'\n    >\n      <header className='flex flex-wrap items-center justify-between gap-x-3 gap-y-1 px-1'>\n        <span className='text-[13px] font-medium'>\n          Flat fee, three branches\n        </span>\n        <span className='text-muted-foreground text-xs'>\n          <WordRoll text={activity} />\n        </span>\n      </header>\n      <ConflictMatrix\n        agents={AGENTS}\n        files={FILES}\n        conflicts={CONFLICTS}\n        run={snapshot}\n        settlements={settlements}\n        onSettle={settle}\n      />\n      <footer className='flex flex-wrap items-center justify-end gap-2 px-1'>\n        <AnimatePresence initial={false}>\n          {isMerged && (\n            <motion.p\n              key='merged'\n              className='text-muted-foreground me-auto text-xs'\n              {...risePresence}\n            >\n              main now holds every kept change\n            </motion.p>\n          )}\n        </AnimatePresence>\n        <ReplayButton isShown={isMerged} onReplay={replay} label='Run again' />\n        <MorphButton\n          type='button'\n          size='sm'\n          variant={mergeVariantOf(canMerge)}\n          state={mergeState}\n          labels={labels}\n          disabled={!canMerge}\n          idleIcon={<GitMergeIcon />}\n          onClick={merge}\n        />\n      </footer>\n      <LiveRegion message={notice} />\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/review/review-08.tsx"
    },
    {
      "path": "registry/ndeko/components/review/_parts/path-parts.ts",
      "content": "export function pathPartsOf(path: string) {\n  const slash = path.lastIndexOf('/');\n  if (slash < 0) {\n    return { folder: '', name: path };\n  }\n  const nameStart = slash + 1;\n  const folder = path.slice(0, nameStart);\n  const name = path.slice(nameStart);\n  return { folder, name };\n}\n",
      "type": "registry:component",
      "target": "components/review/_parts/path-parts.ts"
    }
  ],
  "categories": [
    "components",
    "review"
  ],
  "type": "registry:component"
}