glidercli 0.3.13 → 0.3.15

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/bin/glider.js CHANGED
@@ -502,11 +502,33 @@ async function cmdGoto(url) {
502
502
  method: 'Page.navigate',
503
503
  params: { url }
504
504
  });
505
+ // v0.3.15 FRONTLOG-FIX P0.CLI-goto-false-green + P0.CLI-goto-auto-attach:
506
+ // Prior code printed raw result THEN unconditionally logged '✓ Navigated' —
507
+ // even when result contained {"error":"Session not found"} (stale pinned session after reload-ext).
508
+ // Now: detect embedded error, don't lie about success, then auto-attach the target tab.
509
+ const hasErr = result && (result.error || (typeof result === 'string' && result.includes('error')));
505
510
  if (jsonOutput) {
506
- emitJson(true, { url, navigate: result });
511
+ emitJson(!hasErr, { url, navigate: result }, hasErr ? (result.error?.message || result.error || 'unknown') : null);
512
+ } else if (hasErr) {
513
+ log.fail(`Navigation reported error: ${JSON.stringify(result)}`);
514
+ log.info(' hint: pinned session may be stale (e.g. after reload-ext). Try `glider attach-all` or unset GLIDER_SESSION_ID.');
507
515
  } else {
508
- console.log(JSON.stringify(result));
509
516
  log.ok('Navigated');
517
+ // Auto-attach the tab we just navigated to (best-effort, non-fatal on failure).
518
+ // Uses URL host as substring filter so we don't accidentally re-attach unrelated tabs.
519
+ try {
520
+ const u = new URL(url);
521
+ const host = u.hostname;
522
+ // small delay lets the tab actually load + register in chrome.tabs before attach
523
+ await new Promise(x => setTimeout(x, 800));
524
+ const attach = await postExtension({ method: 'attachAllTabs', params: { urlSubstring: host } });
525
+ const d = attach.result ?? attach;
526
+ if ((d.attached ?? 0) > 0) {
527
+ log.info(` auto-attached ${d.attached} tab(s) matching host="${host}"`);
528
+ }
529
+ } catch (attErr) {
530
+ // silent: nav succeeded, auto-attach is a nice-to-have
531
+ }
510
532
  }
511
533
  } catch (e) {
512
534
  if (jsonOutput) emitJson(false, null, e.message);
@@ -700,6 +722,79 @@ async function cmdRestart() {
700
722
  await cmdStart();
701
723
  }
702
724
 
725
+ // POTEMKIN-PATCH v1: automate the extension reload + tab re-attachment loop
726
+ // so operators don't have to click chrome://extensions after every code change.
727
+ // Bootstrap cost: one manual reload after installing this handler for the first time.
728
+ async function cmdReloadExt() {
729
+ try {
730
+ const r = await postExtension({ method: 'reloadSelf', params: {} });
731
+ // v0.3.15 FRONTLOG-FIX: same unwrap bug as attach-all — r.result was always undefined
732
+ const persisted = (r.result?.persisted ?? r.persisted ?? '?');
733
+ log.ok(`Extension reload triggered (persisted ${persisted} tab URLs).`);
734
+ log.info('Waiting 4s for extension to boot back up + reconnect...');
735
+ await new Promise(x => setTimeout(x, 4000));
736
+ // Extension reboots → autoAttachActiveTab restores from chrome.storage
737
+ // Confirm state
738
+ const st = await httpGetJson('/status');
739
+ log.ok(`relay reconnected: extension=${st.extension} targets=${st.targets}`);
740
+ } catch (e) {
741
+ log.fail(`reload-ext failed: ${e.message}`);
742
+ log.info('First-time bootstrap: open your browser extensions page and reload Glider (one time only).');
743
+ }
744
+ }
745
+
746
+ async function cmdAttachAll(filter) {
747
+ try {
748
+ const r = await postExtension({ method: 'attachAllTabs', params: filter ? { urlSubstring: filter } : {} });
749
+ // v0.3.15 FRONTLOG-FIX P0.CLI-attach-all-observability:
750
+ // relay's sendToExtension unwraps msg.result before HTTP POST responds, so relay body is {attached, skipped, failed, total_connected} bare.
751
+ // Prior code read r.result.attached which was always undefined → literal '?' placeholders on every attach-all.
752
+ const d = r.result ?? r;
753
+ const attached = d.attached ?? 0;
754
+ const skipped = d.skipped ?? 0;
755
+ const failed = d.failed ?? 0;
756
+ const total = d.total_connected ?? 0;
757
+ log.ok(`attach-all: attached=${attached} skipped=${skipped} failed=${failed} total_connected=${total}`);
758
+ if (filter && attached === 0 && total > 0) {
759
+ log.info(` hint: filter "${filter}" matched 0 new tabs. Try 'glider attach-all' with no filter, or check 'glider tabs' for URL substrings that would match.`);
760
+ }
761
+ } catch (e) {
762
+ log.fail(`attach-all failed: ${e.message}`);
763
+ }
764
+ }
765
+
766
+ // Helper: POST to relay's /extension endpoint (already exists in bserve.js)
767
+ async function postExtension(body) {
768
+ return new Promise((resolve, reject) => {
769
+ const data = JSON.stringify(body);
770
+ const req = http.request({
771
+ hostname: '127.0.0.1', port: 19988, path: '/extension', method: 'POST',
772
+ headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(data) }
773
+ }, (res) => {
774
+ let s = '';
775
+ res.on('data', c => s += c);
776
+ res.on('end', () => {
777
+ try {
778
+ const j = JSON.parse(s);
779
+ if (j.error) reject(new Error(j.error.message || j.error));
780
+ else resolve(j);
781
+ } catch(e) { reject(new Error('bad JSON from /extension: ' + s.slice(0,200))); }
782
+ });
783
+ });
784
+ req.on('error', reject);
785
+ req.write(data); req.end();
786
+ });
787
+ }
788
+
789
+ async function httpGetJson(pathStr) {
790
+ return new Promise((resolve, reject) => {
791
+ http.get({ hostname: '127.0.0.1', port: 19988, path: pathStr }, (res) => {
792
+ let s = ''; res.on('data', c => s += c);
793
+ res.on('end', () => { try { resolve(JSON.parse(s)); } catch(e) { reject(e); } });
794
+ }).on('error', reject);
795
+ });
796
+ }
797
+
703
798
  // Daemon management - runs forever, respawns on crash
704
799
  async function cmdInstallDaemon() {
705
800
  const home = os.homedir();
@@ -2150,7 +2245,29 @@ async function cmdUpdate() {
2150
2245
  async function main() {
2151
2246
  const args = parseGlobalFlags(process.argv.slice(2));
2152
2247
  loadPersistedSession();
2153
- const cmd = args[0];
2248
+ let cmd = args[0];
2249
+
2250
+ // v0.3.15 FRONTLOG-FIX P0.CLI-ALIAS-reload-ext:
2251
+ // Accept common natural-language variants + typos for high-frequency commands.
2252
+ // Rewrites args in place so downstream switch stays clean.
2253
+ const RELOAD_EXT_TWO_WORD = new Set([
2254
+ 'ext-reload', 'ext reload',
2255
+ 'reload-extension', 'reload extension',
2256
+ 'reload-ext'
2257
+ ]);
2258
+ const RELOAD_EXT_ALIASES = new Set(['rex', 'reloadext', 'reloadExt']);
2259
+ if (cmd === 'ext' && args[1] === 'reload') {
2260
+ cmd = 'reload-ext';
2261
+ args.splice(0, 2, 'reload-ext');
2262
+ } else if (cmd === 'reload' && (args[1] === 'ext' || args[1] === 'extension')) {
2263
+ cmd = 'reload-ext';
2264
+ args.splice(0, 2, 'reload-ext');
2265
+ } else if (RELOAD_EXT_ALIASES.has(cmd)) {
2266
+ cmd = 'reload-ext';
2267
+ args[0] = 'reload-ext';
2268
+ }
2269
+ // Typo suggest: if cmd looks like a common command with 1-2 char edit distance, hint it.
2270
+ // (Only checked in unknown-command branch below — this block just normalizes.)
2154
2271
 
2155
2272
  if (!cmd || cmd === '--help' || cmd === '-h') {
2156
2273
  showHelp();
@@ -2188,6 +2305,13 @@ async function main() {
2188
2305
  case 'restart':
2189
2306
  await cmdRestart();
2190
2307
  break;
2308
+ case 'reload-ext':
2309
+ case 'reload-extension':
2310
+ await cmdReloadExt();
2311
+ break;
2312
+ case 'attach-all':
2313
+ await cmdAttachAll(args[1]); // optional URL substring filter, e.g. 'microsoft.com'
2314
+ break;
2191
2315
  case 'install':
2192
2316
  await cmdInstallDaemon();
2193
2317
  break;
@@ -2341,6 +2465,25 @@ async function main() {
2341
2465
  break;
2342
2466
  }
2343
2467
  log.fail(`Unknown command: ${cmd}`);
2468
+ // v0.3.15 FRONTLOG-FIX: typo suggest (Levenshtein <=2) before dumping full help.
2469
+ const KNOWN_CMDS = ['status','start','stop','restart','reload-ext','attach-all','install','uninstall',
2470
+ 'update','version','connect','browser','use','test','domains','resolve','goto','eval','click','type',
2471
+ 'screenshot','snapshot','text','html','title','url','tabs','targets','use-session','fetch','spawn',
2472
+ 'extract','explore','favicon','window','reg','run','loop','ralph'];
2473
+ function lev(a, b) {
2474
+ if (Math.abs(a.length - b.length) > 2) return 3;
2475
+ const m = Array.from({length: a.length+1}, () => new Array(b.length+1).fill(0));
2476
+ for (let i = 0; i <= a.length; i++) m[i][0] = i;
2477
+ for (let j = 0; j <= b.length; j++) m[0][j] = j;
2478
+ for (let i = 1; i <= a.length; i++) for (let j = 1; j <= b.length; j++) {
2479
+ m[i][j] = a[i-1] === b[j-1] ? m[i-1][j-1] : 1 + Math.min(m[i-1][j-1], m[i-1][j], m[i][j-1]);
2480
+ }
2481
+ return m[a.length][b.length];
2482
+ }
2483
+ const near = KNOWN_CMDS.map(k => [k, lev(cmd, k)]).filter(x => x[1] <= 2).sort((a,b) => a[1]-b[1]).slice(0, 3);
2484
+ if (near.length > 0) {
2485
+ log.info(` Did you mean: ${near.map(x => x[0]).join(', ')} ?`);
2486
+ }
2344
2487
  showHelp();
2345
2488
  process.exit(1);
2346
2489
  }
package/lib/bserve.js CHANGED
@@ -294,6 +294,14 @@ async function routeCDPCommand({ method, params, sessionId }) {
294
294
  };
295
295
 
296
296
  case 'Target.setAutoAttach':
297
+ // OOPIF-PATCH v1: forward to extension when session-scoped (per-tab autoAttach)
298
+ // so chrome.debugger emits Target.attachedToTarget for OOPIF children.
299
+ // When no sessionId (browser-level call), fall through to the existing
300
+ // "replay attachedToTarget for connectedTargets" branch in the ws handler above.
301
+ if (sessionId) {
302
+ break; // forward to extension
303
+ }
304
+ return {};
297
305
  case 'Target.setDiscoverTargets':
298
306
  return {};
299
307
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glidercli",
3
- "version": "0.3.13",
3
+ "version": "0.3.15",
4
4
  "description": "Browser automation CLI. Control Chrome from terminal via CDP, run YAML task files, autonomous loops until completion.",
5
5
  "main": "index.js",
6
6
  "bin": {