okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
a1cc285fa
main
1import { useEffect , useState } from 'react' ; 2import { tr } from '../lib/i18n' ; 3import { isForkJob , type ForkLane , type TimeSkipJob , type TimeSkipRun } from '../lib/time-skip' ; 4import { activityWords , phaseFraction } from '../lib/time-skip-activity' ; 5import { stopTimeSkip } from '../lib/store' ; 6import { Btn } from './ui' ; 7 8const 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` ; }; 9 10/** 11* 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 12* 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. 13*/ 14export function TimeSkipWorking ({ run, sessionId} :{ run :TimeSkipRun ; sessionId :string }) { 15const [ now , setNow ] = useState (() => Date . now ()); 16const [ stopping , setStopping ] = useState ( false ); 17useEffect (() => { const t = setInterval (() => setNow ( Date . now ()), 1000 ); return () => clearInterval ( t ); }, []); 18const fraction = phaseFraction ( run . job ?. phase ); 19const fork = isForkJob ( run . job ); 20return < section className = "tsw" aria-label = { tr ( "Time-skip is working" )}> 21< div className = "tsw__stage" aria-hidden = "true" > 22< div className = "tsw__ver" >< span > A · { tr ( "Original" )}</ span >< i style = {{ width :'92%' }}/>< i style = {{ width :'100%' }}/>< i style = {{ width :'78%' }}/>< i style = {{ width :'96%' }}/></ div > 23< div className = "tsw__flow" >< i />< i />< i /></ div > 24< div className = "tsw__ver tsw__ver--b" >< span > B · { tr ( "Revising" )}</ span >< i style = {{ width :'70%' }}/>< i style = {{ width :'88%' }}/>< i style = {{ width :'55%' }}/></ div > 25</ div > 26{ fork ?< ForkProgress job = { run . job ! }/> :null } 27< div className = "tsw__bar" > 28< div className = "tsw__step" role = "status" >< strong >{ activityWords ( run . job )}</ strong >< span className = "small muted" >{ clock ( now - run . startedAt )}</ span > 29{ fork ?null :< div className = "tsw__prog" role = "progressbar" aria-valuemin = { 0 } aria-valuemax = { 100 } aria-valuenow = { Math . round ( fraction * 100 )}>< i style = {{ transform :`scaleX( ${ Math . min ( 1 , Math . max ( 0 , fraction ))} )` }}/></ div >}</ div > 30< Btn size = "sm" icon = "stop" disabled = { stopping || ! run . job ?. id } onClick = {() => { setStopping ( true ); void stopTimeSkip ( sessionId , run . id ). finally (() => setStopping ( false )); }}>{ tr ( "Stop" )}</ Btn > 31</ div > 32</ section >; 33} 34 35const 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 ); 36 37function Lane ({ name, lane, waitingText} :{ name :string ; lane :ForkLane | null | undefined ; waitingText :string }) { 38const pct = Math . round ( laneFraction ( lane ) * 100 ); 39const words = ! lane ?waitingText :lane . waiting ?waitingText :lane . line || ( lane . text ?lane . text :tr ( 'Starting…' )); 40return < div className = "tsf__lane" data-state = { lane ?. state ?? 'waiting' }> 41< span className = "tsf__name" >{ name }</ span > 42< div className = "tsf__prog" role = "progressbar" aria-label = { tr ( 'Progress of {0}' , [ name ])} aria-valuemin = { 0 } aria-valuemax = { 100 } aria-valuenow = { pct }>< i style = {{ transform :`scaleX( ${ Math . min ( 1 , Math . max ( 0 , pct / 100 ))} )` }}/></ div > 43< span className = "tsf__words" >{ words }</ span > 44</ div >; 45} 46 47/** 48* 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 49* why), and the two agents' progress. B starts at that step from A's work so far. 50*/ 51export function ForkProgress ({ job} :{ job :TimeSkipJob }) { 52const steps = job . plan ?. steps ?? [], lever = job . lever ; 53const reachedA = job . a ?. step ?? 0 ; 54const short = ! lever && steps . length > 0 && steps . length < 3 ; 55return < div className = "tsf" > 56{ steps . length ?< ol className = "tsf__plan" aria-label = { tr ( "The plan" )}> 57{ steps . map (( s , i ) => { 58const n = i + 1 , state = job . a && job . a . state === 'done' || n < reachedA ?'done' :n === reachedA ?'running' :'pending' ; 59return < li key = { s . id } data-state = { state } data-lever = { lever ?. step === n || undefined }> 60< span className = "tsf__no" aria-hidden = "true" >{ state === 'done' ?'✓' :n }</ span > 61< span >{ s . text }{ lever ?. step === n ?< small className = "tsf__why" >< strong >{ tr ( "Checking here matters most" )}</ strong >{ lever . why ?' · ' + lever . why :'' }{ lever . defaulted ?' · ' + tr ( 'chosen by default' ) :'' }</ small > :null }</ span > 62</ li >; 63})} 64</ ol > :null } 65{ short ?< p className = "small muted tsf__note" >{ tr ( "This is a short job, so there is one version. Nothing is worth branching." )}</ p > :null } 66< div className = "tsf__lanes" > 67< Lane name = "A" lane = { job . a } waitingText = { tr ( 'Waiting to start' )}/> 68{ short ?null :< Lane name = "B" lane = { job . b } waitingText = { lever ?tr ( 'Starts when A reaches step {0}' , [ lever . step ]) :tr ( 'Waiting for the plan' )}/>} 69</ div > 70</ div >; 71}