gm-cc 2.0.212 → 2.0.213

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.
@@ -4,7 +4,7 @@
4
4
  "name": "AnEntrypoint"
5
5
  },
6
6
  "description": "State machine agent with hooks, skills, and automated git enforcement",
7
- "version": "2.0.212",
7
+ "version": "2.0.213",
8
8
  "metadata": {
9
9
  "description": "State machine agent with hooks, skills, and automated git enforcement"
10
10
  },
@@ -241,7 +241,7 @@ const run = () => {
241
241
  const rawLang = (execMatch[1] || '').toLowerCase();
242
242
  const code = execMatch[2];
243
243
  if (/^\s*agent-browser\s/.test(code)) {
244
- return deny(`Do not call agent-browser via exec:bash. Use exec:agent-browser instead:\n\nexec:agent-browser\n<plain JS here>\n\nThe code is piped directly to the browser eval. No base64, no flags, no shell wrapping.`);
244
+ return deny(`Do not call agent-browser via exec:bash. Use exec:agent-browser instead:\n\nexec:agent-browser\nopen http://example.com\n\nMultiple commands in one block:\n\nexec:agent-browser\nopen http://localhost:3001\nwait 2000\nsnapshot -i\n\nFor JS eval (DOM inspection, custom logic):\n\nexec:agent-browser\ndocument.title\n\nCLI commands (open, click, screenshot, snapshot, wait, console, tab, etc.) run directly.\nAnything that is not a CLI command goes through eval --stdin.\nClose tabs when done: exec:agent-browser\\nclose`);
245
245
  }
246
246
  const cwd = tool_input?.cwd;
247
247
 
@@ -364,11 +364,62 @@ const run = () => {
364
364
  const wrapped = `const __result = await (async () => {\n${safeCode}\n})();\nif (__result !== undefined) { if (typeof __result === 'object') { console.log(JSON.stringify(__result, null, 2)); } else { console.log(__result); } }`;
365
365
  result = runWithFile(lang || 'nodejs', wrapped);
366
366
  } else if (lang === 'agent-browser') {
367
- const abBin = localBin('agent-browser');
368
- if (fs.existsSync(abBin)) {
369
- result = spawnDirect(abBin, ['eval', '--stdin'], safeCode);
367
+ const abBin = fs.existsSync(localBin('agent-browser')) ? localBin('agent-browser') : 'agent-browser';
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
+ const AB_GLOBAL_FLAGS = new Set(['--cdp','--headed','--headless','--session','--session-name','--auto-connect','--profile','--allow-file-access','--color-scheme','-p','--platform','--device']);
370
+ const AB_GLOBAL_FLAGS_WITH_VALUE = new Set(['--cdp','--session','--session-name','--profile','--color-scheme','-p','--platform','--device']);
371
+ const AB_SESSION_STATE = path.join(os.tmpdir(), 'gm-ab-sessions.json');
372
+ function readAbSessions() { try { return JSON.parse(fs.readFileSync(AB_SESSION_STATE, 'utf8')); } catch { return {}; } }
373
+ function writeAbSessions(s) { try { fs.writeFileSync(AB_SESSION_STATE, JSON.stringify(s)); } catch {} }
374
+ function parseAbLine(line) {
375
+ const tokens = line.match(/(?:[^\s"']+|"[^"]*"|'[^']*')+/g) || [];
376
+ const globalArgs = [], rest = [];
377
+ let i = 0;
378
+ while (i < tokens.length) {
379
+ if (AB_GLOBAL_FLAGS.has(tokens[i])) {
380
+ globalArgs.push(tokens[i]);
381
+ if (AB_GLOBAL_FLAGS_WITH_VALUE.has(tokens[i]) && i + 1 < tokens.length && !tokens[i+1].startsWith('--')) {
382
+ globalArgs.push(tokens[++i]);
383
+ }
384
+ i++;
385
+ } else { rest.push(...tokens.slice(i)); break; }
386
+ }
387
+ return { globalArgs, rest };
388
+ }
389
+ const firstLineParsed = parseAbLine(safeCode.trim().split('\n')[0].trim());
390
+ const firstWord = (firstLineParsed.rest[0] || '').toLowerCase();
391
+ const sessionName = (() => { const si = firstLineParsed.globalArgs.indexOf('--session'); return si >= 0 ? firstLineParsed.globalArgs[si+1] : 'default'; })();
392
+ const isOpen = ['open','goto','navigate'].includes(firstWord);
393
+ const isClose = ['close','quit','exit'].includes(firstWord);
394
+ const sessions = readAbSessions();
395
+ if (isOpen) sessions[sessionName] = { url: (firstLineParsed.rest[1] || '?'), ts: Date.now() };
396
+ if (isClose) delete sessions[sessionName];
397
+ writeAbSessions(sessions);
398
+ const openSessions = Object.entries(sessions);
399
+ if (AB_CMDS.has(firstWord)) {
400
+ const lines = safeCode.split('\n').map(l => l.trim()).filter(Boolean);
401
+ if (lines.length === 1) {
402
+ const { globalArgs, rest } = parseAbLine(lines[0]);
403
+ result = spawnDirect(abBin, [...globalArgs, ...rest]);
404
+ } else {
405
+ const hasClose = lines.some(l => { const w = (parseAbLine(l).rest[0]||'').toLowerCase(); return ['close','quit','exit'].includes(w); });
406
+ const cmds = lines.map(l => {
407
+ const { globalArgs, rest } = parseAbLine(l);
408
+ const w = (rest[0]||'').toLowerCase();
409
+ if (['open','goto','navigate'].includes(w)) sessions[sessionName] = { url: rest[1]||'?', ts: Date.now() };
410
+ if (['close','quit','exit'].includes(w)) delete sessions[sessionName];
411
+ return [...globalArgs, ...rest];
412
+ });
413
+ writeAbSessions(sessions);
414
+ result = spawnDirect(abBin, ['batch'], JSON.stringify(cmds));
415
+ if (!hasClose && openSessions.length > 0) result += `\n\n[tab] Browser session "${sessionName}" still open. Close when done:\n exec:agent-browser\n close`;
416
+ }
370
417
  } else {
371
- result = spawnDirect('agent-browser', ['eval', '--stdin'], safeCode);
418
+ result = spawnDirect(abBin, ['eval', '--stdin'], safeCode);
419
+ }
420
+ if (openSessions.length > 1) {
421
+ const stale = openSessions.filter(([n]) => n !== sessionName).map(([n,v]) => ` "${n}" → ${v.url} (${Math.round((Date.now()-v.ts)/60000)}min ago)`).join('\n');
422
+ result = (result || '') + `\n\n[tab] ${openSessions.length - 1} other session(s) still open:\n${stale}\n Close with: exec:agent-browser\\nclose (or --session <name> close)`;
372
423
  }
373
424
  } else {
374
425
  result = runWithFile(lang, safeCode);
@@ -384,7 +435,7 @@ const run = () => {
384
435
  try { helpText = '\n\n' + execSync(`"${localBin('gm-exec')}" --help`, { timeout: 10000, windowsHide: true }).toString().trim(); } catch (e) {
385
436
  try { helpText = '\n\n' + execSync('bun x gm-exec --help', { timeout: 10000, windowsHide: true }).toString().trim(); } catch {}
386
437
  }
387
- return deny(`Bash is restricted to exec:<lang> and git.\n\nexec:<lang> syntax (lang auto-detected if omitted):\n exec:nodejs / exec:python / exec:bash / exec:typescript\n exec:go / exec:rust / exec:java / exec:c / exec:cpp\n exec:cmd ← runs cmd.exe /c on Windows\n exec:agent-browser ← plain JS piped to browser eval (NO base64)\n exec ← auto-detects language\n\nTask management shortcuts (body = args):\n exec:status\n <task_id>\n\n exec:sleep\n <task_id> [seconds] [--next-output]\n\n exec:type\n <task_id>\n <input to send to stdin>\n\n exec:close\n <task_id>\n\n exec:runner\n start|stop|status\n\nCode search shortcut:\n exec:codesearch\n <natural language query>\n\nNEVER encode agent-browser code as base64 — pass plain JS directly.\n\nbun x gm-exec${helpText}\n\nAll other Bash commands are blocked.`);
438
+ return deny(`Bash is restricted to exec:<lang> and git.\n\nexec:<lang> syntax (lang auto-detected if omitted):\n exec:nodejs / exec:python / exec:bash / exec:typescript\n exec:go / exec:rust / exec:java / exec:c / exec:cpp\n exec:cmd ← runs cmd.exe /c on Windows\n exec:agent-browser ← browser CLI (open, click, snapshot, wait, tab, console...)\n OR JS eval when body is not a CLI command\n exec ← auto-detects language\n\nexec:agent-browser examples:\n open http://localhost:3001 ← navigate\n snapshot -i ← get element refs\n wait 2000 ← wait ms\n console ← read browser console\n close ← ALWAYS close when done\n document.title ← JS eval (not a CLI command)\n\nMultiple CLI commands in one block run as batch:\n exec:agent-browser\n open http://localhost:3001\n wait 2000\n snapshot -i\n\nTask management shortcuts (body = args):\n exec:status\n <task_id>\n\n exec:sleep\n <task_id> [seconds] [--next-output]\n\n exec:type\n <task_id>\n <input to send to stdin>\n\n exec:close\n <task_id>\n\n exec:runner\n start|stop|status\n\nCode search shortcut:\n exec:codesearch\n <natural language query>\n\nbun x gm-exec${helpText}\n\nAll other Bash commands are blocked.`);
388
439
  }
389
440
  }
390
441
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm-cc",
3
- "version": "2.0.212",
3
+ "version": "2.0.213",
4
4
  "description": "State machine agent with hooks, skills, and automated git enforcement",
5
5
  "author": "AnEntrypoint",
6
6
  "license": "MIT",
package/plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm",
3
- "version": "2.0.212",
3
+ "version": "2.0.213",
4
4
  "description": "State machine agent with hooks, skills, and automated git enforcement",
5
5
  "author": {
6
6
  "name": "AnEntrypoint",
@@ -8,11 +8,23 @@ allowed-tools: agent-browser, Bash(exec:agent-browser*)
8
8
 
9
9
  ## Two Pathways
10
10
 
11
- **Ordinary browser control** — call the `agent-browser` tool directly. This covers all standard browser tasks: navigating, clicking, filling forms, taking screenshots, extracting text. The tool accepts CLI-style commands as its input.
11
+ **`exec:agent-browser` (primary)** — run browser CLI commands or JavaScript eval via Bash. Each line in the body is a CLI command. Lines that are not recognized CLI commands are automatically routed through `eval --stdin`. Supports multi-command batches in a single block.
12
12
 
13
- **JavaScript eval** — use `exec:agent-browser` via Bash when you need to run arbitrary JavaScript in the page context. The code body is piped directly to `agent-browser eval --stdin`. Use this for DOM inspection, custom extraction logic, or anything the CLI commands don't cover.
13
+ ```
14
+ exec:agent-browser
15
+ open http://localhost:3001
16
+ wait 2000
17
+ snapshot -i
18
+ ```
19
+
20
+ ```
21
+ exec:agent-browser
22
+ document.title
23
+ ```
24
+
25
+ **`agent-browser` tool (alternative)** — call the MCP tool directly with a single CLI command at a time. Use when you only need one command and don't need batching.
14
26
 
15
- Use the ordinary pathway by default. Switch to eval only when you need JavaScript access to the page.
27
+ **Always close tabs when done**: every `open` is tracked. Use `exec:agent-browser\nclose` (or `--session <name> close`) when finished. Leaving sessions open accumulates stale tabs — the hook will warn you when other sessions are still open.
16
28
 
17
29
  ## Core Workflow
18
30