okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
f9bfe8bc1
main
1#!/usr/bin/env node 2/** 3* One revision attempt for Time-skip, performed by the app's own assistant. 4* 5* Strata Control runs this as its `--revise-command`, with the candidate folder (an isolated copy of the user's work) as the working 6* directory, the request in STRATA_TIMESKIP_PROMPT and the attempt number in STRATA_TIMESKIP_ATTEMPT. It asks the host (which owns the 7* model and the Harness) for one agent turn inside that folder and returns when the turn ends. Exit 0 means "an attempt was made", not 8* "it helped": whether it helped is decided by the checks and, failing those, by the person. 9* 10* The host answers with a STREAM of one-line JSON messages (`beat`, `activity`, then `result` or `error`) and sends the first one at once. 11* A turn on a slow computer can take many minutes with nothing to say; an answer that sends no byte for five minutes is abandoned by 12* Node's fetch, which is how a Time-skip used to end with "The assistant could not be reached". 13*/ 14const base = process . env . STRATA_HOST_URL ; 15const secret = process . env . STRATA_INTERNAL_SECRET ; 16const prompt = process . env . STRATA_TIMESKIP_PROMPT ?? '' ; 17const attempt = Number ( process . env . STRATA_TIMESKIP_ATTEMPT ?? 1 ); 18 19if ( ! base || ! secret || ! prompt ) { 20console . error ( 'The revision step needs the Strata app to be running.' ); 21process . exit ( 2 ); 22} 23 24try { 25const res = await fetch ( ` ${ base } /api/internal/timeskip-revise` , { 26method :'POST' , 27headers :{ 'content-type' :'application/json' , 'x-strata-internal' :secret }, 28body :JSON . stringify ({ cwd :process . cwd (), prompt, attempt}), 29}); 30if ( ! res . ok || ! res . body ) { 31const body = await res . json (). catch (() => ({})); 32console . error ( body . error ?? `The assistant could not make the change (HTTP ${ res . status } ).` ); 33process . exit ( 1 ); 34} 35const reader = res . body . getReader (); 36const decoder = new TextDecoder (); 37let buffer = '' ; 38let result = null , failure = null ; 39const take = line => { 40if ( ! line . trim ()) return ; 41let message ; 42try { message = JSON . parse ( line ); } catch { return ; } 43if ( message . type === 'result' ) result = String ( message . text ?? '' ). trim (); 44else if ( message . type === 'error' ) failure = String ( message . message ?? 'The assistant could not make the change.' ); 45}; 46for (;;) { 47const { value, done} = await reader . read (); 48if ( value ) { buffer += decoder . decode ( value , { stream :true }); const lines = buffer . split ( '\n' ); buffer = lines . pop () ?? '' ; lines . forEach ( take ); } 49if ( done ) break ; 50} 51take ( buffer ); 52if ( failure ) { console . error ( failure ); process . exit ( 1 ); } 53if ( result === null ) { console . error ( 'The assistant stopped before it finished.' ); process . exit ( 1 ); } 54console . log ( result ); 55} catch ( e ) { 56console . error ( `The assistant could not be reached: ${ e . message } ` ); 57process . exit ( 1 ); 58}