{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tool-timeline",
  "type": "registry:component",
  "title": "Tool Timeline",
  "description": "Collapsible Working/Worked timeline with thought and tool steps.",
  "registryDependencies": [
    "surfaces",
    "collapsible"
  ],
  "files": [
    {
      "path": "registry/tonic/tool-timeline/tool-timeline.tsx",
      "content": "\"use client\"\n\nimport { useState } from \"react\"\nimport { ChevronDownIcon } from \"lucide-react\"\n\nimport {\n  Collapsible,\n  CollapsibleContent,\n  CollapsibleTrigger,\n} from \"@/registry/tonic/ui/collapsible\"\nimport { cn } from \"@/lib/utils\"\nimport {\n  collapsePanel,\n  ShimmerLabel,\n  stepEnter,\n  SwapLabel,\n  threadDiffAdd,\n  threadDiffRemove,\n  threadMeta,\n  threadText,\n} from \"@/registry/tonic/lib/surfaces\"\n\nexport interface TimelineStep {\n  verb: string\n  chip: string\n  detail?: string\n  filePath?: string\n}\n\nexport interface TimelineStat {\n  file: string\n  added?: number\n  removed?: number\n  filePath?: string\n}\n\nexport interface ToolTimelineProps {\n  steps: readonly TimelineStep[]\n  visibleSteps: number\n  streaming: boolean\n  open: boolean\n  onOpenChange: (open: boolean) => void\n  restingLabel: string\n  activeLabel: string\n  stats: TimelineStat[]\n  onOpenFile?: (path: string) => void\n  elapsed?: string\n  className?: string\n}\n\nconst rowClasses = cn(\n  stepEnter,\n  \"flex min-h-6 items-center gap-1.5 py-0.5\",\n  threadMeta\n)\n\nfunction StepRow({\n  step,\n  index,\n  active,\n  expanded,\n  onToggle,\n  onOpenFile,\n  elapsed,\n}: {\n  step: TimelineStep\n  index: number\n  active: boolean\n  expanded: boolean\n  onToggle: () => void\n  onOpenFile?: (path: string) => void\n  elapsed?: string\n}) {\n  const expandable = typeof step.detail === \"string\" && step.detail.length > 0\n  const verb = active && step.verb === \"Thought\" ? \"Thinking\" : step.verb\n  const showChip = step.chip.length > 0\n\n  const row = (\n    <div\n      key={`step-${index}-${step.verb}-${step.chip}`}\n      className={cn(\n        rowClasses,\n        expandable &&\n          \"cursor-pointer rounded-md outline-none hover:text-foreground/70 focus-visible:text-foreground/70\"\n      )}\n      {...(expandable\n        ? {\n            role: \"button\" as const,\n            tabIndex: 0,\n            \"aria-expanded\": expanded,\n            onClick: onToggle,\n            onKeyDown: (event: React.KeyboardEvent) => {\n              if (event.key === \"Enter\" || event.key === \" \") {\n                event.preventDefault()\n                onToggle()\n              }\n            },\n          }\n        : {})}\n    >\n      <ShimmerLabel\n        active={active}\n        className=\"relative inline-block shrink-0 text-muted-foreground\"\n      >\n        {verb}\n      </ShimmerLabel>\n      {elapsed !== undefined && (\n        <span className=\"tabular-nums opacity-80\">{elapsed}</span>\n      )}\n      {showChip && step.filePath && onOpenFile ? (\n        <button\n          type=\"button\"\n          title={`Open ${step.filePath}`}\n          onClick={(event) => {\n            event.stopPropagation()\n            onOpenFile(step.filePath!)\n          }}\n          className=\"text-muted-foreground hover:text-foreground/80 min-w-0 max-w-full cursor-pointer truncate transition-colors outline-none\"\n        >\n          {step.chip}\n        </button>\n      ) : showChip ? (\n        <span className=\"text-muted-foreground min-w-0 truncate\">\n          {step.chip}\n        </span>\n      ) : null}\n      {expandable && (\n        <ChevronDownIcon\n          className={cn(\n            \"size-3.5 shrink-0 opacity-50 transition-transform duration-200 motion-reduce:transition-none\",\n            expanded && \"rotate-180\"\n          )}\n        />\n      )}\n    </div>\n  )\n\n  if (!expandable) return row\n\n  return (\n    <>\n      {row}\n      {expanded && (\n        <div\n          className={cn(\n            \"text-muted-foreground mt-1 max-h-64 overflow-y-auto whitespace-pre-wrap select-text\",\n            threadText\n          )}\n        >\n          {step.detail}\n        </div>\n      )}\n    </>\n  )\n}\n\nfunction StatLine({\n  stats,\n  onOpenFile,\n}: {\n  stats: TimelineStat[]\n  onOpenFile?: (path: string) => void\n}) {\n  if (stats.length === 0) return null\n\n  const totalAdded = stats.reduce((sum, stat) => sum + (stat.added ?? 0), 0)\n  const totalRemoved = stats.reduce(\n    (sum, stat) => sum + (stat.removed ?? 0),\n    0\n  )\n  const files = stats.length\n  const summary = `Edited ${files} file${files === 1 ? \"\" : \"s\"}`\n\n  return (\n    <div\n      className={cn(\n        \"flex flex-wrap items-center gap-x-1.5 gap-y-0.5 py-0.5\",\n        threadMeta\n      )}\n    >\n      <span className=\"min-w-0 truncate\">{summary}</span>\n      {(totalAdded > 0 || totalRemoved > 0) && (\n        <span className=\"inline-flex items-center gap-1.5 tabular-nums\">\n          {totalAdded > 0 && (\n            <span className={threadDiffAdd}>+{totalAdded}</span>\n          )}\n          {totalRemoved > 0 && (\n            <span className={threadDiffRemove}>-{totalRemoved}</span>\n          )}\n        </span>\n      )}\n      {stats.some((stat) => stat.filePath) && onOpenFile ? (\n        <span className=\"sr-only\">\n          {stats\n            .filter((stat) => stat.filePath)\n            .map((stat) => stat.file)\n            .join(\", \")}\n        </span>\n      ) : null}\n    </div>\n  )\n}\n\nexport function ToolTimeline({\n  steps,\n  visibleSteps,\n  streaming,\n  open,\n  onOpenChange,\n  restingLabel,\n  activeLabel,\n  stats,\n  onOpenFile,\n  elapsed,\n  className,\n}: ToolTimelineProps) {\n  const [expandedSteps, setExpandedSteps] = useState<ReadonlySet<number>>(\n    () => new Set()\n  )\n\n  const toggleStep = (index: number) => {\n    setExpandedSteps((prev) => {\n      const next = new Set(prev)\n      if (next.has(index)) {\n        next.delete(index)\n      } else {\n        next.add(index)\n      }\n      return next\n    })\n  }\n\n  if (steps.length === 1) {\n    const step = steps[0]\n    const stepElapsed = step.verb === \"Thought\" ? elapsed : undefined\n    return (\n      <div data-slot=\"tool-timeline\" className={cn(\"w-full\", className)}>\n        <StepRow\n          step={step}\n          index={0}\n          active={streaming}\n          expanded={expandedSteps.has(0)}\n          onToggle={() => toggleStep(0)}\n          onOpenFile={onOpenFile}\n          elapsed={stepElapsed}\n        />\n        <StatLine stats={stats} onOpenFile={onOpenFile} />\n      </div>\n    )\n  }\n\n  const settledWithDuration =\n    !streaming && elapsed !== undefined && restingLabel.startsWith(\"Worked\")\n\n  return (\n    <Collapsible\n      data-slot=\"tool-timeline\"\n      open={open}\n      onOpenChange={onOpenChange}\n      className={cn(\"w-full\", className)}\n    >\n      <CollapsibleTrigger\n        className={cn(\n          \"group/trigger hover:text-foreground/70 flex items-center gap-1 rounded-md py-0.5 transition-colors outline-none\",\n          threadMeta\n        )}\n      >\n        <SwapLabel active={streaming ? 0 : 1} className=\"text-start\">\n          <ShimmerLabel active={streaming} className=\"relative inline-block\">\n            {elapsed ? `${activeLabel} ${elapsed}` : activeLabel}\n          </ShimmerLabel>\n          <>{restingLabel}</>\n        </SwapLabel>\n        <ChevronDownIcon\n          className={cn(\n            \"size-3.5 shrink-0 opacity-50 transition-transform duration-200 ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:transition-none\",\n            open && \"rotate-180\"\n          )}\n        />\n        {settledWithDuration ? <span className=\"sr-only\">{elapsed}</span> : null}\n      </CollapsibleTrigger>\n      <CollapsibleContent className={cn(collapsePanel, \"outline-none\")}>\n        <div className=\"flex flex-col gap-1 pt-1.5\">\n          {steps\n            .slice(0, Math.max(0, Math.min(visibleSteps, steps.length)))\n            .map((step, index, shown) => (\n              <StepRow\n                key={`step-${index}-${step.verb}-${step.chip}`}\n                step={step}\n                index={index}\n                active={streaming && index === shown.length - 1}\n                expanded={expandedSteps.has(index)}\n                onToggle={() => toggleStep(index)}\n                onOpenFile={onOpenFile}\n              />\n            ))}\n          <StatLine stats={stats} onOpenFile={onOpenFile} />\n        </div>\n      </CollapsibleContent>\n    </Collapsible>\n  )\n}\n",
      "type": "registry:component"
    }
  ]
}