okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
ea2d565e6
main
1/** 2* The three slash commands through the real app on a real model, with screenshots (playwright-core + installed Chrome). 3* 4* STRATA_URL=http://127.0.0.1:8899 SHOTS=./shots WORKDIR=<the host's workspace> MODEL='Qwen test' node scripts/agent2-flow.mjs 5* 6* Steps (each prints ok/FAIL): 7* 1. typing "/" lists /time-skip, /goal and /loop with plain descriptions; 8* 2. /loop 1m <message>: the first answer arrives, the loop repeats it a minute later, /loop shows it, /loop stop ends it; 9* 3. /goal <objective>: the assistant works until the goal is complete (Manual mode: Approve cards are clicked), /goal shows it; 10* 4. /time-skip <request>: a job runs on a copy, the sidebar lists the changed file, Keep the update changes the file in WORKDIR, 11* Put the original back restores it. 12* Environment: STRATA_URL (required), SHOTS, WORKDIR, MODEL (picker text), CHROME, SKIP (comma list of steps to skip: menu,loop,goal,timeskip), 13* LOOP_WAIT_MS (how long to wait for the second loop run, default 150000). 14*/ 15import { chromium } from 'playwright-core' ; 16import { existsSync , mkdirSync , readFileSync , writeFileSync } from 'node:fs' ; 17import { join , resolve } from 'node:path' ; 18 19const BASE = process . env . STRATA_URL ; 20if ( ! BASE ) { console . error ( 'STRATA_URL is required' ); process . exit ( 2 ); } 21const SHOTS = resolve ( process . env . SHOTS ?? 'agent2-shots' ); 22mkdirSync ( SHOTS , { recursive :true }); 23const WORKDIR = process . env . WORKDIR ; 24const MODEL = process . env . MODEL ?? 'Qwen test' ; 25const SKIP = new Set (( process . env . SKIP ?? '' ). split ( ',' ). filter ( Boolean )); 26const CHROME = process . env . CHROME ?? [ 'C:/Program Files/Google/Chrome/Application/chrome.exe' , '/usr/bin/google-chrome' ]. find ( existsSync ); 27 28let failed = false ; 29const check = ( ok , label ) => { console . log ( ` ${ ok ? 'ok ' : 'FAIL' } ${ label } ` ); if ( ! ok ) failed = true ; }; 30const browser = await chromium . launch ({ executablePath :CHROME , headless :true }); 31const page = await browser . newPage ({ viewport :{ width :1512 , height :1000 } }); 32const problems = []; 33page . on ( 'pageerror' , e => problems . push ( `pageerror: ${ e . message } ` )); 34page . on ( 'console' , m => { if ( m . type () === 'error' ) problems . push ( `console: ${ m . text (). slice ( 0 , 200 )} ` ); }); 35const shot = async name => { await page . waitForTimeout ( 400 ); await page . screenshot ({ path :join ( SHOTS , ` ${ name } .png` ) }); console . log ( `shot ${ name } .png` ); }; 36const send = async text => { await page . locator ( 'textarea' ). first (). fill ( text ); await page . getByRole ( 'button' , { name :'Send' }). click (); }; 37const idle = async ( ms = 900000 ) => page . waitForFunction (() => document . documentElement . dataset . streaming !== 'true' , null , { timeout :ms }); 38const started = async () => page . waitForFunction (() => document . documentElement . dataset . streaming === 'true' , null , { timeout :30000 }); 39const text = () => page . evaluate (() => document . querySelector ( '.chat' )?. innerText ?? document . body . innerText ); 40 41/** Approve every card that asks until the turn is over. */ 42async function approveUntilIdle ( label ) { 43let asked = 0 ; const seen = new Set (); 44for (;;) { 45const streaming = await page . evaluate (() => document . documentElement . dataset . streaming === 'true' ); 46const cards = page . locator ( '.toolcard[data-state="proposed"]' ); 47const n = await cards . count (); 48for ( let i = 0 ; i < n ; i ++ ) { 49const card = cards . nth ( i ); 50const key = ( await card . innerText ()). slice ( 0 , 200 ); 51if ( ! seen . has ( key )) { seen . add ( key ); asked ++ ; await shot ( ` ${ label } -approve- ${ asked } ` ); } 52await card . getByRole ( 'button' , { name :'Approve' }). click (). catch (() => {}); 53} 54if ( ! streaming && n === 0 ) break ; 55await page . waitForTimeout ( 400 ); 56} 57return asked ; 58} 59 60try { 61await page . goto ( ` ${ BASE } /#/chat` ); 62await page . waitForTimeout ( 2000 ); 63const skip = page . getByText ( 'Go straight to the app' ); 64if ( await skip . count ()) { await skip . click (); await page . waitForTimeout ( 600 ); } 65await page . getByRole ( 'button' , { name :'New chat' }). first (). click (); 66await page . waitForTimeout ( 600 ); 67await page . getByRole ( 'button' , { name :/ Choose model / }). first (). click (); 68await page . waitForTimeout ( 300 ); 69await page . getByRole ( 'menuitemradio' , { name :new RegExp ( MODEL ) }). first (). click (); 70await page . waitForTimeout ( 300 ); 71 72// 1. the menu 73if ( ! SKIP . has ( 'menu' )) { 74await page . locator ( 'textarea' ). first (). fill ( '/' ); 75await page . waitForSelector ( '.slashmenu' , { timeout :5000 }); 76const menu = await page . locator ( '.slashmenu' ). innerText (); 77await shot ( '01-slash-menu' ); 78check ( / \/time-skip / . test ( menu ) && / Try a change on a copy / . test ( menu ), '/time-skip is listed with its plain description' ); 79check ( / \/goal / . test ( menu ) && / keep working until it is done / . test ( menu ), '/goal is listed with its plain description' ); 80check ( / \/loop / . test ( menu ) && / every few minutes / . test ( menu ), '/loop is listed with its plain description' ); 81await page . locator ( 'textarea' ). first (). fill ( '/lo' ); 82await shot ( '01b-slash-menu-filtered' ); 83await page . locator ( 'textarea' ). first (). fill ( '' ); 84} 85 86// 2. /loop 87if ( ! SKIP . has ( 'loop' )) { 88await send ( '/loop 1m Reply with exactly three words about the sea.' ); 89await page . waitForTimeout ( 1500 ); 90await shot ( '02a-loop-started' ); 91let body = await text (); 92check ( / Loop started: .Reply with exactly three words about the sea\.. every minute / . test ( body ), 'a note says the loop started and how often' ); 93await started (). catch (() => {}); 94await idle (); 95await shot ( '02b-loop-first-answer' ); 96const firstCount = ( await text ()). split ( 'Reply with exactly three words about the sea.' ). length - 1 ; 97const t0 = Date . now (); 98const wait = Number ( process . env . LOOP_WAIT_MS ?? 150000 ); 99await page . waitForFunction ( n => ( document . querySelector ( '.chat' )?. innerText ?? '' ). split ( 'Reply with exactly three words about the sea.' ). length - 1 > n , firstCount , { timeout :wait }). catch (() => {}); 100await idle (); 101await shot ( '02c-loop-second-run' ); 102const secondCount = ( await text ()). split ( 'Reply with exactly three words about the sea.' ). length - 1 ; 103check ( secondCount > firstCount , `the loop sent the message again on its own ( ${ Math . round (( Date . now () - t0 ) / 1000 )} s after the first answer)` ); 104await send ( '/loop' ); 105await page . waitForTimeout ( 800 ); 106check ( / A loop is running in this chat / . test ( await text ()), '/loop says a loop is running' ); 107await send ( '/loop stop' ); 108await page . waitForTimeout ( 800 ); 109await shot ( '02d-loop-stopped' ); 110check ( / The loop is stopped / . test ( await text ()), '/loop stop says it is stopped' ); 111const afterStop = ( await text ()). split ( 'Reply with exactly three words about the sea.' ). length - 1 ; 112await page . waitForTimeout ( 75000 ); 113await idle (); 114check (( await text ()). split ( 'Reply with exactly three words about the sea.' ). length - 1 === afterStop , 'nothing more was sent after stopping' ); 115} 116 117// 3. /goal 118if ( ! SKIP . has ( 'goal' )) { 119await page . getByRole ( 'button' , { name :'New chat' }). first (). click (); 120await page . waitForTimeout ( 600 ); 121await page . getByRole ( 'button' , { name :/ Choose model / }). first (). click (); 122await page . waitForTimeout ( 300 ); 123await page . getByRole ( 'menuitemradio' , { name :new RegExp ( MODEL ) }). first (). click (); 124await page . waitForTimeout ( 300 ); 125await send ( '/goal Create a file called goal-done.txt in the current folder that contains the single word done, then confirm it exists.' ); 126await started (). catch (() => {}); 127const asked = await approveUntilIdle ( '03' ); 128await idle (); 129await shot ( '03a-goal-finished' ); 130const body = await text (); 131check ( !! WORKDIR && existsSync ( join ( WORKDIR , 'goal-done.txt' )), 'the goal produced goal-done.txt' ); 132check ( / goal is complete | goal-done\.txt / i . test ( body ), 'the chat says the goal is complete or names the file' ); 133console . log ( `approval cards: ${ asked } ` ); 134await send ( '/goal' ); 135await page . waitForTimeout ( 1500 ); 136await shot ( '03b-goal-status' ); 137} 138 139// 4. /time-skip 140if ( ! SKIP . has ( 'timeskip' )) { 141await page . getByRole ( 'button' , { name :'New chat' }). first (). click (); 142await page . waitForTimeout ( 600 ); 143await page . getByRole ( 'button' , { name :/ Choose model / }). first (). click (); 144await page . waitForTimeout ( 300 ); 145await page . getByRole ( 'menuitemradio' , { name :new RegExp ( MODEL ) }). first (). click (); 146await page . waitForTimeout ( 300 ); 147const notes = WORKDIR ?join ( WORKDIR , 'notes.md' ) :null ; 148const before = notes && existsSync ( notes ) ?readFileSync ( notes , 'utf8' ) :null ; 149await send ( '/time-skip Add a second line to notes.md that says: second line added.' ); 150await page . waitForTimeout ( 2500 ); 151await shot ( '04a-timeskip-working' ); 152await page . waitForFunction (() => / Ready to compare | Update kept | Saved version kept | could not be completed | stopped | interrupted / i . test ( document . querySelector ( '#time-skip-content .ts-heading' )?. innerText ?? '' ), null , { timeout :1200000 }). catch (() => {}); 153await shot ( '04b-timeskip-ready' ); 154const panel = await page . locator ( '#time-skip-content' ). innerText (). catch (() => '' ); 155check ( / Ready to compare / . test ( panel ), 'the sidebar says the result is ready to compare' ); 156check ( / notes\.md / . test ( panel ), 'the sidebar names the changed file' ); 157check ( ! notes || readFileSync ( notes , 'utf8' ) === before , 'your file is untouched until you choose' ); 158await page . getByRole ( 'button' , { name :'Compare' }). first (). click (). catch (() => {}); 159await page . waitForTimeout ( 800 ); 160await shot ( '04c-timeskip-compare' ); 161await page . getByRole ( 'button' , { name :/ Back to chat | Done comparing / }). first (). click (). catch (() => {}); 162await page . getByRole ( 'button' , { name :'Keep the update' }). first (). click (); 163await page . waitForTimeout ( 4000 ); 164await shot ( '04d-timeskip-kept' ); 165check ( ! notes || / second line added / i . test ( readFileSync ( notes , 'utf8' )), 'Keep the update put the revision in your file' ); 166await page . getByRole ( 'button' , { name :'Put the original back' }). first (). click (); 167await page . waitForTimeout ( 4000 ); 168await shot ( '04e-timeskip-restored' ); 169check ( ! notes || readFileSync ( notes , 'utf8' ) === before , 'Put the original back restored your file' ); 170} 171} catch ( e ) { 172console . log ( 'ERROR' , e . message ); 173await shot ( 'zz-error' ). catch (() => {}); 174failed = true ; 175} finally { 176const text = problems . filter ( p => ! /Failed to load resource | ERR_ | favicon / . test ( p )); 177console . log ( `page problems: ${ text . length } ` ); text . slice ( 0 , 8 ). forEach ( p => console . log ( ' ' + p )); 178await browser . close (); 179} 180process . exit ( failed ?1 :0 );