import { useEffect, useState } from 'react'; import { tr } from '../lib/i18n'; import { isForkJob, type ForkLane, type TimeSkipJob, type TimeSkipRun } from '../lib/time-skip'; import { activityWords, phaseFraction } from '../lib/time-skip-activity'; import { stopTimeSkip } from '../lib/store'; import { Btn } from './ui'; const clock = (ms: number) => { const t = Math.max(0, Math.round(ms / 1000)); return t < 60 ? `${t}s` : `${Math.floor(t / 60)}m ${String(t % 60).padStart(2, '0')}s`; }; /** * While a Time-skip run works, in the chat: the saved version (A) and the one being written (B) with a stream of light between them, what * the assistant is doing right now, how long, and Stop. It is shown from the first moment, so a long run never looks like nothing happening. */ export function TimeSkipWorking({ run, sessionId }: { run: TimeSkipRun; sessionId: string }) { const [now, setNow] = useState(() => Date.now()); const [stopping, setStopping] = useState(false); useEffect(() => { const t = setInterval(() => setNow(Date.now()), 1000); return () => clearInterval(t); }, []); const fraction = phaseFraction(run.job?.phase); const fork = isForkJob(run.job); return
{fork ? : null}
{activityWords(run.job)}{clock(now - run.startedAt)} {fork ? null :
}
{ setStopping(true); void stopTimeSkip(sessionId, run.id).finally(() => setStopping(false)); }}>{tr("Stop")}
; } const laneFraction = (l: ForkLane | null | undefined) => (l && l.total > 0 ? Math.min(1, (l.state === 'done' ? l.total : Math.max(0, l.step - 1)) / l.total) : 0); function Lane({ name, lane, waitingText }: { name: string; lane: ForkLane | null | undefined; waitingText: string }) { const pct = Math.round(laneFraction(lane) * 100); const words = !lane ? waitingText : lane.waiting ? waitingText : lane.line || (lane.text ? lane.text : tr('Starting…')); return
{name}
{words}
; } /** * The fork design (notes-split-agent8.md, item 11): the plan as a list, the one step the assistant chose to check and branch at (with its one-line * why), and the two agents' progress. B starts at that step from A's work so far. */ export function ForkProgress({ job }: { job: TimeSkipJob }) { const steps = job.plan?.steps ?? [], lever = job.lever; const reachedA = job.a?.step ?? 0; const short = !lever && steps.length > 0 && steps.length < 3; return
{steps.length ?
    {steps.map((s, i) => { const n = i + 1, state = job.a && job.a.state === 'done' || n < reachedA ? 'done' : n === reachedA ? 'running' : 'pending'; return
  1. {s.text}{lever?.step === n ? {tr("Checking here matters most")}{lever.why ? ' · ' + lever.why : ''}{lever.defaulted ? ' · ' + tr('chosen by default') : ''} : null}
  2. ; })}
: null} {short ?

{tr("This is a short job, so there is one version. Nothing is worth branching.")}

: null}
{short ? null : }
; }