okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221merge f-split-agent2 c7b65c7f7 (/loop, /goal, /time-skip, keyless search, system-browser tool, Settings Tools, Plan refuses connected tools) into f-split-intea2d565e6

main
3.3 KiB61 linesraw
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) {
11  if (platform === 'win32') {
12    const roots = [env.PROGRAMFILES, env['PROGRAMFILES(X86)'], env.LOCALAPPDATA].filter(Boolean);
13    const at = rel => roots.map(r => join(r, rel));
14    return [
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  }
20  if (platform === 'darwin') {
21    return [
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  }
27  return [
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 } = {}) {
36  const hit = browserCandidates(platform, env).find(c => exists(c.path));
37  if (hit) return { found: true, name: hit.name, path: hit.path };
38  if (platform === 'linux') {
39    for (const [name, bin] of [['Google Chrome', 'google-chrome'], ['Microsoft Edge', 'microsoft-edge'], ['Chromium', 'chromium']]) {
40      const r = spawnSync('which', [bin], { encoding: 'utf8' });
41      if (r.status === 0 && r.stdout.trim()) return { found: true, name, path: r.stdout.trim() };
42    }
43  }
44  return { 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 } = {}) {
52  if (!harnessDir) return null;
53  const direct = join(harnessDir, 'node_modules', '@playwright', 'mcp', 'cli.js');
54  if (exists(direct)) return direct;
55  try {
56    const store = join(harnessDir, 'node_modules', '.pnpm');
57    const hit = list(store).filter(n => /^@playwright\+mcp@/.test(n)).sort().at(-1);
58    const nested = hit ? join(store, hit, 'node_modules', '@playwright', 'mcp', 'cli.js') : null;
59    return nested && exists(nested) ? nested : null;
60  } catch { return null; }
61}