gm-oc 2.0.214 → 2.0.215
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/hooks/pre-tool-use-hook.js +31 -3
- package/package.json +1 -1
|
@@ -368,6 +368,23 @@ const run = () => {
|
|
|
368
368
|
const AB_CMDS = new Set(['open','goto','navigate','close','quit','exit','back','forward','reload','click','dblclick','type','fill','press','check','uncheck','select','drag','upload','hover','focus','scroll','scrollintoview','wait','screenshot','pdf','snapshot','get','is','find','eval','connect','tab','frame','dialog','state','session','network','cookies','storage','set','trace','profiler','record','console','errors','highlight','inspect','diff','keyboard','mouse','install','upgrade','confirm','deny','auth','device','window']);
|
|
369
369
|
const AB_GLOBAL_FLAGS = new Set(['--cdp','--headed','--headless','--session','--session-name','--auto-connect','--profile','--allow-file-access','--color-scheme','-p','--platform','--device']);
|
|
370
370
|
const AB_GLOBAL_FLAGS_WITH_VALUE = new Set(['--cdp','--session','--session-name','--profile','--color-scheme','-p','--platform','--device']);
|
|
371
|
+
function loadAbProfile(dir) {
|
|
372
|
+
if (!dir) return [];
|
|
373
|
+
try {
|
|
374
|
+
const cfg = JSON.parse(fs.readFileSync(path.join(dir, '.agent-browser.json'), 'utf8'));
|
|
375
|
+
const flags = [];
|
|
376
|
+
if (cfg.headed) flags.push('--headed');
|
|
377
|
+
if (cfg.headless) flags.push('--headless');
|
|
378
|
+
if (cfg.profile) flags.push('--profile', cfg.profile);
|
|
379
|
+
if (cfg.cdp) flags.push('--cdp', String(cfg.cdp));
|
|
380
|
+
if (cfg.platform || cfg.p) flags.push('-p', cfg.platform || cfg.p);
|
|
381
|
+
if (cfg.device) flags.push('--device', cfg.device);
|
|
382
|
+
if (cfg['allow-file-access']) flags.push('--allow-file-access');
|
|
383
|
+
if (cfg['color-scheme']) flags.push('--color-scheme', cfg['color-scheme']);
|
|
384
|
+
return flags;
|
|
385
|
+
} catch { return []; }
|
|
386
|
+
}
|
|
387
|
+
const abProfileFlags = loadAbProfile(projectDir || cwd || process.cwd());
|
|
371
388
|
const AB_SESSION_STATE = path.join(os.tmpdir(), 'gm-ab-sessions.json');
|
|
372
389
|
function readAbSessions() { try { return JSON.parse(fs.readFileSync(AB_SESSION_STATE, 'utf8')); } catch { return {}; } }
|
|
373
390
|
function writeAbSessions(s) { try { fs.writeFileSync(AB_SESSION_STATE, JSON.stringify(s)); } catch {} }
|
|
@@ -396,11 +413,21 @@ const run = () => {
|
|
|
396
413
|
if (isClose) delete sessions[sessionName];
|
|
397
414
|
writeAbSessions(sessions);
|
|
398
415
|
const openSessions = Object.entries(sessions);
|
|
416
|
+
function mergeProfileFlags(userGlobalArgs) {
|
|
417
|
+
const userFlagSet = new Set(userGlobalArgs.filter(f => f.startsWith('-')));
|
|
418
|
+
const filtered = [];
|
|
419
|
+
for (let i = 0; i < abProfileFlags.length; i++) {
|
|
420
|
+
const f = abProfileFlags[i];
|
|
421
|
+
if (f.startsWith('-') && userFlagSet.has(f)) { if (AB_GLOBAL_FLAGS_WITH_VALUE.has(f)) i++; continue; }
|
|
422
|
+
filtered.push(f);
|
|
423
|
+
}
|
|
424
|
+
return [...filtered, ...userGlobalArgs];
|
|
425
|
+
}
|
|
399
426
|
if (AB_CMDS.has(firstWord)) {
|
|
400
427
|
const lines = safeCode.split('\n').map(l => l.trim()).filter(Boolean);
|
|
401
428
|
if (lines.length === 1) {
|
|
402
429
|
const { globalArgs, rest } = parseAbLine(lines[0]);
|
|
403
|
-
result = spawnDirect(abBin, [...globalArgs, ...rest]);
|
|
430
|
+
result = spawnDirect(abBin, [...mergeProfileFlags(globalArgs), ...rest]);
|
|
404
431
|
} else {
|
|
405
432
|
const hasClose = lines.some(l => { const w = (parseAbLine(l).rest[0]||'').toLowerCase(); return ['close','quit','exit'].includes(w); });
|
|
406
433
|
const cmds = lines.map(l => {
|
|
@@ -408,14 +435,15 @@ const run = () => {
|
|
|
408
435
|
const w = (rest[0]||'').toLowerCase();
|
|
409
436
|
if (['open','goto','navigate'].includes(w)) sessions[sessionName] = { url: rest[1]||'?', ts: Date.now() };
|
|
410
437
|
if (['close','quit','exit'].includes(w)) delete sessions[sessionName];
|
|
411
|
-
return [...globalArgs,
|
|
438
|
+
if (!AB_CMDS.has(w)) return [...mergeProfileFlags(globalArgs), 'eval', l.trim()];
|
|
439
|
+
return [...mergeProfileFlags(globalArgs), ...rest];
|
|
412
440
|
});
|
|
413
441
|
writeAbSessions(sessions);
|
|
414
442
|
result = spawnDirect(abBin, ['batch'], JSON.stringify(cmds));
|
|
415
443
|
if (!hasClose && openSessions.length > 0) result += `\n\n[tab] Browser session "${sessionName}" still open. Close when done:\n exec:agent-browser\n close`;
|
|
416
444
|
}
|
|
417
445
|
} else {
|
|
418
|
-
result = spawnDirect(abBin, ['eval', '--stdin'], safeCode);
|
|
446
|
+
result = spawnDirect(abBin, [...abProfileFlags, 'eval', '--stdin'], safeCode);
|
|
419
447
|
}
|
|
420
448
|
if (openSessions.length > 1) {
|
|
421
449
|
const stale = openSessions.filter(([n]) => n !== sessionName).map(([n,v]) => ` "${n}" → ${v.url} (${Math.round((Date.now()-v.ts)/60000)}min ago)`).join('\n');
|