import { Check, Circle, Loader2, MinusCircle } from 'lucide-react' import { useEffect, useState } from 'react' import { STEPS } from '@/lib/content' import { seconds } from '@/lib/format' import type { RunState, StepView } from '@/lib/run' import type { StepDetail } from '@/lib/types' import { cn } from '@/lib/utils' /** The run as it happens: C's graph node by node (with what each found), or A/B's steps * as one call. The running step shows a live timer from when the last event came. */ export function Progress({ run, since }: { run: RunState; since: number }) { const now = useNow(run.phase === 'running') return (
{!run.live && run.steps.length > 0 && (

System {run.system?.toUpperCase()} runs these steps in one call: no progress until the answer.

)}
    {run.steps.map((s) => (
  1. {STEPS[s.name]?.title ?? s.name} {s.status === 'done' ? seconds(s.ms) : s.status === 'running' ? seconds(now - since) : ''} {s.status === 'skipped' ? 'not needed' : ''}

    {STEPS[s.name]?.what}

    {s.status === 'done' && s.detail && }
  2. ))}
) } function StatusIcon({ status }: { status: StepView['status'] }) { const cls = 'mt-0.5 size-4 shrink-0' if (status === 'done') return if (status === 'running') return if (status === 'skipped') return return } /** What a finished step found, in a line or a short list. */ function Detail({ step, detail }: { step: StepView; detail: StepDetail }) { const line = 'mt-1 text-xs' switch (step.name) { case 'retrieve': return

{detail.candidates} candidate passages

case 'judge': case 'judge_new': return (
    {(detail.requirements ?? []).map((r, i) => (
  • {r.found ? 'found' : 'missing'} {r.need}
  • ))}
) case 'research': return (

{(detail.queries ?? []).map((q) => `"${q}"`).join(', ')} → {detail.new_candidates} new passages

) case 'select': return (

{detail.kept} passages kept, {detail.expansions} cited sections added {detail.fallback ? ' (the judge kept none: the top search results are used)' : ''}

) case 'verify': return (

{detail.checked} citations checked {detail.retried ? `, ${detail.failed_first?.length ?? 0} failed the first time: the answer was retried` : ', all passed'} {detail.dropped ? `, ${detail.dropped} still failing and dropped` : ''}

) default: return null } } /** The current time, ticking every 100 ms while `on`. */ function useNow(on: boolean): number { const [now, setNow] = useState(() => Date.now()) useEffect(() => { if (!on) return const timer = setInterval(() => setNow(Date.now()), 100) return () => clearInterval(timer) }, [on]) return now }