okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
ea2d565e6
main
1/** 2* Finds a browser already installed on this computer (Chrome, then Edge, then Chromium) for the assistant's browser tool, so nothing 3* big has to be downloaded. Returns the program's path and the name the screen shows. 4*/ 5import { existsSync , readdirSync } from 'node:fs' ; 6import { join } from 'node:path' ; 7import { spawnSync } from 'node:child_process' ; 8 9/** @returns { Array<{name: string, path: string}> } candidate programs for a platform, best first */ 10export function browserCandidates ( platform = process . platform , env = process . env ) { 11if ( platform === 'win32' ) { 12const roots = [ env . PROGRAMFILES , env [ 'PROGRAMFILES(X86)' ], env . LOCALAPPDATA ]. filter ( Boolean ); 13const at = rel => roots . map ( r => join ( r , rel )); 14return [ 15 ...at ( 'Google\\Chrome\\Application\\chrome.exe' ). map ( path => ({ name :'Google Chrome' , path})), 16 ...at ( 'Microsoft\\Edge\\Application\\msedge.exe' ). map ( path => ({ name :'Microsoft Edge' , path})), 17 ...at ( 'Chromium\\Application\\chrome.exe' ). map ( path => ({ name :'Chromium' , path})), 18]; 19} 20if ( platform === 'darwin' ) { 21return [ 22{ name :'Google Chrome' , path :'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' }, 23{ name :'Microsoft Edge' , path :'/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge' }, 24{ name :'Chromium' , path :'/Applications/Chromium.app/Contents/MacOS/Chromium' }, 25]; 26} 27return [ 28 ...[ '/usr/bin/google-chrome' , '/usr/bin/google-chrome-stable' , '/opt/google/chrome/chrome' ]. map ( path => ({ name :'Google Chrome' , path})), 29 ...[ '/usr/bin/microsoft-edge' , '/usr/bin/microsoft-edge-stable' , '/opt/microsoft/msedge/msedge' ]. map ( path => ({ name :'Microsoft Edge' , path})), 30 ...[ '/usr/bin/chromium' , '/usr/bin/chromium-browser' , '/snap/bin/chromium' ]. map ( path => ({ name :'Chromium' , path})), 31]; 32} 33 34/** @returns { {found: boolean, name: string|null, path: string|null} } */ 35export function findBrowser ({ platform= process . platform , env= process . env , exists= existsSync } = {}) { 36const hit = browserCandidates ( platform , env ). find ( c => exists ( c . path )); 37if ( hit ) return { found :true , name :hit . name , path :hit . path }; 38if ( platform === 'linux' ) { 39for ( const [ name , bin ] of [[ 'Google Chrome' , 'google-chrome' ], [ 'Microsoft Edge' , 'microsoft-edge' ], [ 'Chromium' , 'chromium' ]]) { 40const r = spawnSync ( 'which' , [ bin ], { encoding :'utf8' }); 41if ( r . status === 0 && r . stdout . trim ()) return { found :true , name, path :r . stdout . trim () }; 42} 43} 44return { found :false , name :null , path :null }; 45} 46 47/** 48* The browser tool server (Playwright's MCP, MIT/Apache) inside the agent component. The installer ships it next to the Harness; a source 49* checkout of the Harness keeps it under node_modules/.pnpm. Returns the file to run with Node, or null. 50*/ 51export function findPlaywrightMcp ( harnessDir , { exists= existsSync , list= readdirSync } = {}) { 52if ( ! harnessDir ) return null ; 53const direct = join ( harnessDir , 'node_modules' , '@playwright' , 'mcp' , 'cli.js' ); 54if ( exists ( direct )) return direct ; 55try { 56const store = join ( harnessDir , 'node_modules' , '.pnpm' ); 57const hit = list ( store ). filter ( n => / ^@playwright\+mcp@ / . test ( n )). sort (). at ( - 1 ); 58const nested = hit ?join ( store , hit , 'node_modules' , '@playwright' , 'mcp' , 'cli.js' ) :null ; 59return nested && exists ( nested ) ?nested :null ; 60} catch { return null ; } 61}