gm-gc 2.0.215 → 2.0.216
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/gemini-extension.json +1 -1
- package/hooks/pre-tool-use-hook.js +41 -20
- package/package.json +1 -1
package/gemini-extension.json
CHANGED
|
@@ -279,7 +279,8 @@ const run = () => {
|
|
|
279
279
|
const langExts = { nodejs: 'mjs', typescript: 'ts', deno: 'ts', python: 'py', bash: 'sh', powershell: 'ps1', go: 'go', rust: 'rs', c: 'c', cpp: 'cpp', java: 'java' };
|
|
280
280
|
|
|
281
281
|
const spawnDirect = (bin, args, stdin) => {
|
|
282
|
-
const
|
|
282
|
+
const spawnCwd = cwd || (lang === 'agent-browser' ? process.cwd() : undefined);
|
|
283
|
+
const opts = { encoding: 'utf-8', timeout: 60000, windowsHide: true, ...(spawnCwd && { cwd: spawnCwd }), ...(stdin !== undefined && { input: stdin }) };
|
|
283
284
|
const r = spawnSync(bin, args, opts);
|
|
284
285
|
if (!r.stdout && !r.stderr && r.error) return `[spawn error: ${r.error.message}]`;
|
|
285
286
|
const out = (r.stdout || '').trimEnd(), err = stripFooter(r.stderr || '').trimEnd();
|
|
@@ -369,22 +370,42 @@ const run = () => {
|
|
|
369
370
|
const AB_GLOBAL_FLAGS = new Set(['--cdp','--headed','--headless','--session','--session-name','--auto-connect','--profile','--allow-file-access','--color-scheme','-p','--platform','--device']);
|
|
370
371
|
const AB_GLOBAL_FLAGS_WITH_VALUE = new Set(['--cdp','--session','--session-name','--profile','--color-scheme','-p','--platform','--device']);
|
|
371
372
|
function loadAbProfile(dir) {
|
|
372
|
-
if (!dir) return [];
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
373
|
+
if (!dir) return { flags: [], env: {} };
|
|
374
|
+
const candidates = ['agent-browser.json', '.agent-browser.json'];
|
|
375
|
+
for (const name of candidates) {
|
|
376
|
+
try {
|
|
377
|
+
const cfg = JSON.parse(fs.readFileSync(path.join(dir, name), 'utf8'));
|
|
378
|
+
const flags = [], env = {};
|
|
379
|
+
if (cfg.headed) { flags.push('--headed'); env.AGENT_BROWSER_HEADED = '1'; }
|
|
380
|
+
if (cfg.headless) flags.push('--headless');
|
|
381
|
+
if (cfg.profile) { flags.push('--profile', cfg.profile); env.AGENT_BROWSER_PROFILE = cfg.profile; }
|
|
382
|
+
if (cfg.cdp) flags.push('--cdp', String(cfg.cdp));
|
|
383
|
+
if (cfg.platform || cfg.p) flags.push('-p', cfg.platform || cfg.p);
|
|
384
|
+
if (cfg.device) flags.push('--device', cfg.device);
|
|
385
|
+
if (cfg['allow-file-access']) flags.push('--allow-file-access');
|
|
386
|
+
if (cfg['color-scheme']) { flags.push('--color-scheme', cfg['color-scheme']); env.AGENT_BROWSER_COLOR_SCHEME = cfg['color-scheme']; }
|
|
387
|
+
return { flags, env };
|
|
388
|
+
} catch {}
|
|
389
|
+
}
|
|
390
|
+
return { flags: [], env: {} };
|
|
391
|
+
}
|
|
392
|
+
const { flags: abProfileFlags, env: abProfileEnv } = loadAbProfile(process.cwd());
|
|
393
|
+
// If profile config exists and no daemon is running, pre-start the daemon with correct cwd
|
|
394
|
+
if (abProfileFlags.length > 0) {
|
|
395
|
+
const portFile = path.join(os.tmpdir(), 'agent-shell.port');
|
|
396
|
+
const daemonRunning = fs.existsSync(portFile);
|
|
397
|
+
if (!daemonRunning) {
|
|
398
|
+
// Start daemon in background from correct cwd so it picks up agent-browser.json
|
|
399
|
+
require('child_process').spawn(abBin, ['open', 'about:blank'], {
|
|
400
|
+
detached: true, stdio: 'ignore',
|
|
401
|
+
cwd: process.cwd(),
|
|
402
|
+
env: { ...process.env, ...abProfileEnv },
|
|
403
|
+
windowsHide: true
|
|
404
|
+
}).unref();
|
|
405
|
+
// Wait for daemon to bind
|
|
406
|
+
spawnSync('cmd.exe', ['/c', 'ping -n 3 127.0.0.1 > nul'], { windowsHide: true, timeout: 5000 });
|
|
407
|
+
}
|
|
386
408
|
}
|
|
387
|
-
const abProfileFlags = loadAbProfile(projectDir || cwd || process.cwd());
|
|
388
409
|
const AB_SESSION_STATE = path.join(os.tmpdir(), 'gm-ab-sessions.json');
|
|
389
410
|
function readAbSessions() { try { return JSON.parse(fs.readFileSync(AB_SESSION_STATE, 'utf8')); } catch { return {}; } }
|
|
390
411
|
function writeAbSessions(s) { try { fs.writeFileSync(AB_SESSION_STATE, JSON.stringify(s)); } catch {} }
|
|
@@ -427,7 +448,7 @@ const run = () => {
|
|
|
427
448
|
const lines = safeCode.split('\n').map(l => l.trim()).filter(Boolean);
|
|
428
449
|
if (lines.length === 1) {
|
|
429
450
|
const { globalArgs, rest } = parseAbLine(lines[0]);
|
|
430
|
-
result = spawnDirect(abBin, [...
|
|
451
|
+
result = spawnDirect(abBin, [...globalArgs, ...rest]);
|
|
431
452
|
} else {
|
|
432
453
|
const hasClose = lines.some(l => { const w = (parseAbLine(l).rest[0]||'').toLowerCase(); return ['close','quit','exit'].includes(w); });
|
|
433
454
|
const cmds = lines.map(l => {
|
|
@@ -435,15 +456,15 @@ const run = () => {
|
|
|
435
456
|
const w = (rest[0]||'').toLowerCase();
|
|
436
457
|
if (['open','goto','navigate'].includes(w)) sessions[sessionName] = { url: rest[1]||'?', ts: Date.now() };
|
|
437
458
|
if (['close','quit','exit'].includes(w)) delete sessions[sessionName];
|
|
438
|
-
if (!AB_CMDS.has(w)) return [...
|
|
439
|
-
return [...
|
|
459
|
+
if (!AB_CMDS.has(w)) return [...globalArgs, 'eval', l.trim()];
|
|
460
|
+
return [...globalArgs, ...rest];
|
|
440
461
|
});
|
|
441
462
|
writeAbSessions(sessions);
|
|
442
463
|
result = spawnDirect(abBin, ['batch'], JSON.stringify(cmds));
|
|
443
464
|
if (!hasClose && openSessions.length > 0) result += `\n\n[tab] Browser session "${sessionName}" still open. Close when done:\n exec:agent-browser\n close`;
|
|
444
465
|
}
|
|
445
466
|
} else {
|
|
446
|
-
result = spawnDirect(abBin, [
|
|
467
|
+
result = spawnDirect(abBin, ['eval', '--stdin'], safeCode);
|
|
447
468
|
}
|
|
448
469
|
if (openSessions.length > 1) {
|
|
449
470
|
const stale = openSessions.filter(([n]) => n !== sessionName).map(([n,v]) => ` "${n}" → ${v.url} (${Math.round((Date.now()-v.ts)/60000)}min ago)`).join('\n');
|