glidercli 0.4.13 → 0.4.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/README.md +78 -95
- package/bin/glider.js +197 -150
- package/config/browser.json.example +1 -3
- package/config/browsers-registry.json.example +39 -0
- package/config/domains.template.json +1 -1
- package/docs/setup.json +7 -7
- package/lib/bexplore.js +507 -217
- package/lib/browser-config.js +1 -1
- package/lib/glider-daemon.sh +133 -6
- package/lib/paths.js +5 -7
- package/lib/pin-machine.js +1 -1
- package/package.json +3 -3
package/bin/glider.js
CHANGED
|
@@ -26,6 +26,7 @@ const path = require('path');
|
|
|
26
26
|
const fs = require('fs');
|
|
27
27
|
const os = require('os');
|
|
28
28
|
const http = require('http');
|
|
29
|
+
const readline = require('readline');
|
|
29
30
|
const WebSocket = require('ws');
|
|
30
31
|
const YAML = require('yaml');
|
|
31
32
|
|
|
@@ -43,9 +44,9 @@ let jsonOutput = false;
|
|
|
43
44
|
let allowedDomainList = null;
|
|
44
45
|
const { configPath, gliderHome } = require(path.join(LIB_DIR, 'paths.js'));
|
|
45
46
|
const { isBrowserInternalUrl, loadBrowserConfig } = require(path.join(LIB_DIR, 'browser-config.js'));
|
|
46
|
-
const
|
|
47
|
-
const LOG_FILE = path.join(
|
|
48
|
-
const SESSION_STORE = path.join(
|
|
47
|
+
const GLIDER = gliderHome();
|
|
48
|
+
const LOG_FILE = path.join(GLIDER, 'relay.log');
|
|
49
|
+
const SESSION_STORE = path.join(GLIDER, 'config', 'active-session.json');
|
|
49
50
|
const { resolveAllowedDomains, assertUrlAllowed, urlAllowed } = require(path.join(LIB_DIR, 'guard.js'));
|
|
50
51
|
const { buildSnapshotExpression, formatSnapshotText } = require(path.join(LIB_DIR, 'bsnapshot.js'));
|
|
51
52
|
let PORT = null;
|
|
@@ -58,12 +59,12 @@ try {
|
|
|
58
59
|
relayConfigError = error;
|
|
59
60
|
}
|
|
60
61
|
const RELAY_ENTRY = path.join(LIB_DIR, 'bserve.js');
|
|
61
|
-
const RELAY_PID_FILE = PORT === null ? null : path.join(
|
|
62
|
-
const RELAY_START_LOCK = PORT === null ? null : path.join(
|
|
62
|
+
const RELAY_PID_FILE = PORT === null ? null : path.join(GLIDER, `relay-${PORT}.pid`);
|
|
63
|
+
const RELAY_START_LOCK = PORT === null ? null : path.join(GLIDER, `relay-${PORT}.lifecycle.lock`);
|
|
63
64
|
const DAEMON_ENTRY = path.join(LIB_DIR, 'glider-daemon.sh');
|
|
64
|
-
const DAEMON_PID_FILE = PORT === null ? null : path.join(
|
|
65
|
-
const DAEMON_CLAIM_DIR = PORT === null ? null : path.join(
|
|
66
|
-
const DAEMON_MANAGEMENT_LOCK = PORT === null ? null : path.join(
|
|
65
|
+
const DAEMON_PID_FILE = PORT === null ? null : path.join(GLIDER, `daemon-${PORT}.pid`);
|
|
66
|
+
const DAEMON_CLAIM_DIR = PORT === null ? null : path.join(GLIDER, `daemon-${PORT}.claim`);
|
|
67
|
+
const DAEMON_MANAGEMENT_LOCK = PORT === null ? null : path.join(GLIDER, `daemon-${PORT}.management.lock`);
|
|
67
68
|
|
|
68
69
|
// Load pattern registry
|
|
69
70
|
let REGISTRY = {};
|
|
@@ -91,7 +92,7 @@ for (const cfgPath of DOMAIN_CONFIG_PATHS) {
|
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
function getBrowserConfig() {
|
|
94
|
-
return loadBrowserConfig({ home:
|
|
95
|
+
return loadBrowserConfig({ home: GLIDER });
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
// Colors - matching the deep blue gradient logo
|
|
@@ -374,6 +375,55 @@ function inspectDaemonOwnership() {
|
|
|
374
375
|
return { state: 'unverified', record };
|
|
375
376
|
}
|
|
376
377
|
|
|
378
|
+
const CLAIM_ORPHAN_GRACE_MS = 5000;
|
|
379
|
+
|
|
380
|
+
function readClaimOwnerPid(claimDir) {
|
|
381
|
+
try {
|
|
382
|
+
const raw = fs.readFileSync(path.join(claimDir, 'owner'), 'utf8').trim();
|
|
383
|
+
const pid = Number.parseInt(raw.split('-')[0], 10);
|
|
384
|
+
return Number.isInteger(pid) && pid > 0 ? pid : null;
|
|
385
|
+
} catch {
|
|
386
|
+
return null;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function claimIsTombstone(claimDir) {
|
|
391
|
+
const ownerPid = readClaimOwnerPid(claimDir);
|
|
392
|
+
if (ownerPid !== null) return !getProcessIdentity(ownerPid);
|
|
393
|
+
// Unreadable owner: a supervisor may be between mkdir and writing its token.
|
|
394
|
+
try {
|
|
395
|
+
return Date.now() - fs.statSync(claimDir).mtimeMs >= CLAIM_ORPHAN_GRACE_MS;
|
|
396
|
+
} catch {
|
|
397
|
+
return false;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// Clear daemon lifecycle state left by a supervisor that died without cleanup
|
|
402
|
+
// (crash, SIGKILL, power loss). Callers must first confirm no relay answers on
|
|
403
|
+
// the port. Nothing is removed while the recorded supervisor or the claim owner
|
|
404
|
+
// is alive. Returns true when state was reaped.
|
|
405
|
+
function reapOrphanedDaemonState() {
|
|
406
|
+
const claimExists = fs.existsSync(DAEMON_CLAIM_DIR);
|
|
407
|
+
const recordExists = fs.existsSync(DAEMON_PID_FILE);
|
|
408
|
+
if (!claimExists && !recordExists) return false;
|
|
409
|
+
|
|
410
|
+
const record = recordExists ? readDaemonPidRecord(DAEMON_PID_FILE) : null;
|
|
411
|
+
const identity = record ? getProcessIdentity(record.pid) : null;
|
|
412
|
+
if (daemonSupervisorMatches(record, identity, DAEMON_ENTRY)) return false;
|
|
413
|
+
if (claimExists && !claimIsTombstone(DAEMON_CLAIM_DIR)) return false;
|
|
414
|
+
|
|
415
|
+
let reaped = false;
|
|
416
|
+
if (claimExists) {
|
|
417
|
+
try { fs.rmSync(DAEMON_CLAIM_DIR, { recursive: true, force: true }); reaped = true; } catch {}
|
|
418
|
+
}
|
|
419
|
+
if (record) {
|
|
420
|
+
try { removeDaemonPidRecordIfOwned(DAEMON_PID_FILE, record); reaped = true; } catch {}
|
|
421
|
+
} else if (recordExists) {
|
|
422
|
+
try { fs.unlinkSync(DAEMON_PID_FILE); reaped = true; } catch {}
|
|
423
|
+
}
|
|
424
|
+
return reaped;
|
|
425
|
+
}
|
|
426
|
+
|
|
377
427
|
function assertStandaloneRelayAllowed(ownership = inspectDaemonOwnership()) {
|
|
378
428
|
if (ownership.state === 'owned') {
|
|
379
429
|
throw new Error(
|
|
@@ -648,8 +698,24 @@ async function pickLiveSessionId() {
|
|
|
648
698
|
targetId: want.targetId || '',
|
|
649
699
|
sessionId: '',
|
|
650
700
|
});
|
|
651
|
-
if (resolved.pin)
|
|
652
|
-
|
|
701
|
+
if (resolved.pin) {
|
|
702
|
+
persistPin(resolved.pin);
|
|
703
|
+
return resolved.pin.sessionId;
|
|
704
|
+
}
|
|
705
|
+
const part = pinMachine.partition(targets);
|
|
706
|
+
if (part.pages.length === 1) {
|
|
707
|
+
const page = part.pages[0];
|
|
708
|
+
persistPin({
|
|
709
|
+
sessionId: page.sessionId,
|
|
710
|
+
targetId: page.targetId,
|
|
711
|
+
type: pinMachine.PAGE,
|
|
712
|
+
url: page.url,
|
|
713
|
+
host: pinMachine.hostFromUrl(page.url),
|
|
714
|
+
reason: 'heal_only_page',
|
|
715
|
+
});
|
|
716
|
+
return page.sessionId;
|
|
717
|
+
}
|
|
718
|
+
return null;
|
|
653
719
|
}
|
|
654
720
|
|
|
655
721
|
async function httpPost(urlPath, body) {
|
|
@@ -811,7 +877,7 @@ async function requestActiveTabAttach() {
|
|
|
811
877
|
return data;
|
|
812
878
|
}
|
|
813
879
|
|
|
814
|
-
// Auto-connect helper - honors the browser selected by $
|
|
880
|
+
// Auto-connect helper - honors the browser selected by $GLIDER/config/browser.json.
|
|
815
881
|
async function ensureConnected() {
|
|
816
882
|
// Check if already connected
|
|
817
883
|
if (await checkTab()) {
|
|
@@ -983,7 +1049,7 @@ async function cmdStart({ render = true } = {}) {
|
|
|
983
1049
|
throw new Error(`bserve not found at ${RELAY_ENTRY}`);
|
|
984
1050
|
}
|
|
985
1051
|
|
|
986
|
-
fs.mkdirSync(
|
|
1052
|
+
fs.mkdirSync(GLIDER, { recursive: true });
|
|
987
1053
|
if (render) log.info('Starting glider server...');
|
|
988
1054
|
const locks = await acquireStandaloneRelayLocks();
|
|
989
1055
|
|
|
@@ -995,6 +1061,8 @@ async function cmdStart({ render = true } = {}) {
|
|
|
995
1061
|
status = await getRelayStatus();
|
|
996
1062
|
} catch {}
|
|
997
1063
|
|
|
1064
|
+
if (!status?.pid) reapOrphanedDaemonState();
|
|
1065
|
+
|
|
998
1066
|
const ownership = inspectDaemonOwnership();
|
|
999
1067
|
if (status?.pid) {
|
|
1000
1068
|
if (
|
|
@@ -1068,7 +1136,7 @@ async function cmdStart({ render = true } = {}) {
|
|
|
1068
1136
|
}
|
|
1069
1137
|
|
|
1070
1138
|
async function cmdStop({ render = true } = {}) {
|
|
1071
|
-
fs.mkdirSync(
|
|
1139
|
+
fs.mkdirSync(GLIDER, { recursive: true });
|
|
1072
1140
|
const locks = await acquireStandaloneRelayLocks();
|
|
1073
1141
|
try {
|
|
1074
1142
|
assertStandaloneRelayAllowed();
|
|
@@ -1465,7 +1533,7 @@ async function httpGetJson(pathStr) {
|
|
|
1465
1533
|
async function cmdInstallDaemon() {
|
|
1466
1534
|
const home = os.homedir();
|
|
1467
1535
|
const daemonScript = DAEMON_ENTRY;
|
|
1468
|
-
const logDir =
|
|
1536
|
+
const logDir = GLIDER;
|
|
1469
1537
|
const pidFile = DAEMON_PID_FILE;
|
|
1470
1538
|
const legacyPidFile = path.join(logDir, 'daemon.pid');
|
|
1471
1539
|
|
|
@@ -1484,7 +1552,11 @@ async function cmdInstallDaemon() {
|
|
|
1484
1552
|
if (legacy.state === 'stale') {
|
|
1485
1553
|
try { fs.unlinkSync(legacyPidFile); } catch {}
|
|
1486
1554
|
}
|
|
1487
|
-
|
|
1555
|
+
|
|
1556
|
+
let preInstallStatus = null;
|
|
1557
|
+
try { preInstallStatus = await getRelayStatus(); } catch {}
|
|
1558
|
+
if (!preInstallStatus?.pid) reapOrphanedDaemonState();
|
|
1559
|
+
|
|
1488
1560
|
if (fs.existsSync(pidFile)) {
|
|
1489
1561
|
const record = readDaemonPidRecord(pidFile);
|
|
1490
1562
|
const identity = record ? getProcessIdentity(record.pid) : null;
|
|
@@ -1519,6 +1591,7 @@ async function cmdInstallDaemon() {
|
|
|
1519
1591
|
cwd: home,
|
|
1520
1592
|
env: {
|
|
1521
1593
|
...process.env,
|
|
1594
|
+
GLIDER,
|
|
1522
1595
|
GLIDER_PORT: String(PORT),
|
|
1523
1596
|
GLIDER_DAEMON_MANAGEMENT_OWNER_PID: String(managementLock.pid),
|
|
1524
1597
|
GLIDER_DAEMON_MANAGEMENT_OWNER_STARTED: managementLock.started,
|
|
@@ -1566,9 +1639,9 @@ async function cmdInstallDaemon() {
|
|
|
1566
1639
|
}
|
|
1567
1640
|
|
|
1568
1641
|
async function cmdUninstallDaemon() {
|
|
1569
|
-
fs.mkdirSync(
|
|
1642
|
+
fs.mkdirSync(GLIDER, { recursive: true });
|
|
1570
1643
|
const pidFile = DAEMON_PID_FILE;
|
|
1571
|
-
const legacyPidFile = path.join(
|
|
1644
|
+
const legacyPidFile = path.join(GLIDER, 'daemon.pid');
|
|
1572
1645
|
const daemonScript = DAEMON_ENTRY;
|
|
1573
1646
|
const claimDir = DAEMON_CLAIM_DIR;
|
|
1574
1647
|
const managementLock = await acquireDaemonManagementLock();
|
|
@@ -1696,7 +1769,7 @@ async function cmdConnect() {
|
|
|
1696
1769
|
process.exit(1);
|
|
1697
1770
|
}
|
|
1698
1771
|
|
|
1699
|
-
// 6. Opt-in UI path: ensure we have a real tab (not chrome:// or
|
|
1772
|
+
// 6. Opt-in UI path: ensure we have a real tab (not chrome:// or other internal pages)
|
|
1700
1773
|
try {
|
|
1701
1774
|
const tabUrl = activeBrowserTabUrl(browser);
|
|
1702
1775
|
if (isBrowserInternalUrl(tabUrl)) {
|
|
@@ -1781,54 +1854,97 @@ async function cmdConnect() {
|
|
|
1781
1854
|
process.exit(1);
|
|
1782
1855
|
}
|
|
1783
1856
|
|
|
1784
|
-
function
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
registrySource: b.registrySource,
|
|
1795
|
-
});
|
|
1796
|
-
return;
|
|
1797
|
-
}
|
|
1798
|
-
console.log('Browser config (used by glider connect):');
|
|
1799
|
-
console.log(` name: ${b.name}`);
|
|
1800
|
-
console.log(` path: ${b.path || '(default launch via name)'}`);
|
|
1801
|
-
console.log(` processName: ${b.processName}`);
|
|
1802
|
-
console.log(` bootstrapUrl: ${b.bootstrapUrl}`);
|
|
1803
|
-
if (b.use) {
|
|
1804
|
-
console.log(` use: ${b.use} ${DIM}(from registry)${NC}`);
|
|
1805
|
-
}
|
|
1806
|
-
console.log('');
|
|
1807
|
-
console.log(`Source: ${b.source || path.join(GLIDER_HOME, 'config', 'browser.json')} { "use": "<key>" } or { name, path } -> default "Google Chrome"`);
|
|
1808
|
-
console.log(`Registry: ${b.registrySource || path.join(GLIDER_HOME, 'config', 'browsers-registry.json')}. Keys: ` + (Object.keys(b.registry).join(', ') || '(none loaded)'));
|
|
1809
|
-
console.log('See README.md#browsers for compatibility and examples.');
|
|
1857
|
+
function emitBrowserJson(b) {
|
|
1858
|
+
emitJson(true, {
|
|
1859
|
+
name: b.name,
|
|
1860
|
+
path: b.path,
|
|
1861
|
+
processName: b.processName,
|
|
1862
|
+
bootstrapUrl: b.bootstrapUrl,
|
|
1863
|
+
use: b.use,
|
|
1864
|
+
source: b.source,
|
|
1865
|
+
registrySource: b.registrySource,
|
|
1866
|
+
});
|
|
1810
1867
|
}
|
|
1811
1868
|
|
|
1812
|
-
function
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1869
|
+
function configHelpFlag(s) {
|
|
1870
|
+
return s === '-h' || s === '--help';
|
|
1871
|
+
}
|
|
1872
|
+
|
|
1873
|
+
function defaultBrowserNames() {
|
|
1874
|
+
return ['chrome', 'edge', 'brave', 'opera', 'vivaldi', 'helium', 'arc'];
|
|
1875
|
+
}
|
|
1876
|
+
|
|
1877
|
+
function printConfigBrowserCommands(browser) {
|
|
1878
|
+
const keys = Object.keys((browser && browser.registry) || {});
|
|
1879
|
+
const list = keys.length ? keys : defaultBrowserNames();
|
|
1880
|
+
for (const k of list) console.log(`glider config browser ${k}`);
|
|
1881
|
+
if (browser && browser.use) console.log(`current: ${browser.use}`);
|
|
1882
|
+
}
|
|
1883
|
+
|
|
1884
|
+
function writeBrowserUse(key, browser) {
|
|
1820
1885
|
if (!browser.registry[key]) {
|
|
1821
|
-
console.error(
|
|
1886
|
+
console.error(`Unknown command: config browser ${key}`);
|
|
1887
|
+
printConfigBrowserCommands(browser);
|
|
1822
1888
|
process.exit(1);
|
|
1823
1889
|
}
|
|
1824
|
-
const configDir = path.join(
|
|
1890
|
+
const configDir = path.join(GLIDER, 'config');
|
|
1825
1891
|
const browserPath = path.join(configDir, 'browser.json');
|
|
1826
1892
|
if (!fs.existsSync(configDir)) fs.mkdirSync(configDir, { recursive: true });
|
|
1827
1893
|
fs.writeFileSync(browserPath, JSON.stringify({ use: key }, null, 2) + '\n');
|
|
1828
|
-
console.log(
|
|
1894
|
+
console.log(`glider config browser ${key}`);
|
|
1895
|
+
console.log(browser.registry[key].name);
|
|
1829
1896
|
console.log('Run: glider connect');
|
|
1830
1897
|
}
|
|
1831
1898
|
|
|
1899
|
+
async function pickBrowser(browser) {
|
|
1900
|
+
const keys = Object.keys(browser.registry || {});
|
|
1901
|
+
const list = keys.length ? keys : defaultBrowserNames();
|
|
1902
|
+
list.forEach((k, i) => console.log(`${i + 1}. glider config browser ${k}`));
|
|
1903
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
1904
|
+
const answer = await new Promise((resolve) => rl.question('> ', resolve));
|
|
1905
|
+
rl.close();
|
|
1906
|
+
const t = String(answer || '').trim();
|
|
1907
|
+
if (/^\d+$/.test(t)) {
|
|
1908
|
+
const picked = list[Number(t) - 1];
|
|
1909
|
+
if (picked) return picked;
|
|
1910
|
+
}
|
|
1911
|
+
if (list.includes(t)) return t;
|
|
1912
|
+
const m = t.match(/(?:config\s+browser\s+)?(\S+)$/);
|
|
1913
|
+
if (m && list.includes(m[1])) return m[1];
|
|
1914
|
+
console.error(`Unknown command: config browser ${t}`);
|
|
1915
|
+
process.exit(1);
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1918
|
+
async function cmdConfig(argv) {
|
|
1919
|
+
const a = (argv || []).filter((x) => x !== undefined);
|
|
1920
|
+
const browser = getBrowserConfig();
|
|
1921
|
+
if (!a.length || configHelpFlag(a[0])) {
|
|
1922
|
+
if (jsonOutput) return emitBrowserJson(browser);
|
|
1923
|
+
printConfigBrowserCommands(browser);
|
|
1924
|
+
return;
|
|
1925
|
+
}
|
|
1926
|
+
if (a[0] !== 'browser') {
|
|
1927
|
+
console.error(`Unknown command: config ${a[0]}`);
|
|
1928
|
+
process.exit(1);
|
|
1929
|
+
}
|
|
1930
|
+
const rest = a.slice(1);
|
|
1931
|
+
if (rest.length && configHelpFlag(rest[0])) {
|
|
1932
|
+
if (jsonOutput) return emitBrowserJson(browser);
|
|
1933
|
+
printConfigBrowserCommands(browser);
|
|
1934
|
+
return;
|
|
1935
|
+
}
|
|
1936
|
+
if (!rest.length) {
|
|
1937
|
+
if (jsonOutput) return emitBrowserJson(browser);
|
|
1938
|
+
if (process.stdin.isTTY && !process.env.CI) {
|
|
1939
|
+
writeBrowserUse(await pickBrowser(browser), browser);
|
|
1940
|
+
return;
|
|
1941
|
+
}
|
|
1942
|
+
printConfigBrowserCommands(browser);
|
|
1943
|
+
return;
|
|
1944
|
+
}
|
|
1945
|
+
writeBrowserUse(rest[0], browser);
|
|
1946
|
+
}
|
|
1947
|
+
|
|
1832
1948
|
async function cmdTest() {
|
|
1833
1949
|
let relay = null;
|
|
1834
1950
|
try {
|
|
@@ -2129,8 +2245,7 @@ async function cmdWindow(args) {
|
|
|
2129
2245
|
const subcmd = args[0] || 'list';
|
|
2130
2246
|
|
|
2131
2247
|
switch (subcmd) {
|
|
2132
|
-
case 'new':
|
|
2133
|
-
case 'create': {
|
|
2248
|
+
case 'new': {
|
|
2134
2249
|
const url = args[1] || 'about:blank';
|
|
2135
2250
|
log.info(`Creating new window: ${url}`);
|
|
2136
2251
|
const result = await wm.createWindow(url);
|
|
@@ -3206,7 +3321,7 @@ async function cmdRegistry(patternName, opts = []) {
|
|
|
3206
3321
|
// Explore site (clicks around, captures network)
|
|
3207
3322
|
async function cmdExplore(url, opts = []) {
|
|
3208
3323
|
if (!url) {
|
|
3209
|
-
log.fail('Usage: glider explore <url> [--depth N] [--output dir] [--har file] [--session-id id]');
|
|
3324
|
+
log.fail('Usage: glider explore <url> [--depth N] [--output dir] [--har file] [--session-id id] [--workers N]');
|
|
3210
3325
|
process.exit(1);
|
|
3211
3326
|
}
|
|
3212
3327
|
|
|
@@ -3216,6 +3331,7 @@ async function cmdExplore(url, opts = []) {
|
|
|
3216
3331
|
let sessionId = null;
|
|
3217
3332
|
let freshTab = false;
|
|
3218
3333
|
let closeOnDone = false;
|
|
3334
|
+
let workers = 1;
|
|
3219
3335
|
|
|
3220
3336
|
for (let i = 0; i < opts.length; i++) {
|
|
3221
3337
|
if (opts[i] === '--depth' || opts[i] === '-d') {
|
|
@@ -3227,6 +3343,7 @@ async function cmdExplore(url, opts = []) {
|
|
|
3227
3343
|
else if (opts[i] === '--session-id' || opts[i] === '--session') sessionId = opts[++i];
|
|
3228
3344
|
else if (opts[i] === '--fresh-tab') freshTab = true;
|
|
3229
3345
|
else if (opts[i] === '--close-on-done') closeOnDone = true;
|
|
3346
|
+
else if (opts[i] === '--workers') workers = Math.min(4, Math.max(1, parseInt(opts[++i], 10) || 1));
|
|
3230
3347
|
}
|
|
3231
3348
|
if (!sessionId && !freshTab && activeSessionId) sessionId = activeSessionId;
|
|
3232
3349
|
|
|
@@ -3271,6 +3388,7 @@ async function cmdExplore(url, opts = []) {
|
|
|
3271
3388
|
if (depth === 0) spawnArgs.push('--depth', '0');
|
|
3272
3389
|
if (harFile) spawnArgs.push('--har', harFile);
|
|
3273
3390
|
if (sessionId) spawnArgs.push('--session-id', sessionId);
|
|
3391
|
+
spawnArgs.push('--workers', String(workers));
|
|
3274
3392
|
|
|
3275
3393
|
const child = spawn('node', spawnArgs, {
|
|
3276
3394
|
stdio: 'inherit'
|
|
@@ -3353,16 +3471,13 @@ async function cmdRun(taskFile) {
|
|
|
3353
3471
|
try {
|
|
3354
3472
|
switch (cmd) {
|
|
3355
3473
|
case 'goto':
|
|
3356
|
-
case 'navigate':
|
|
3357
3474
|
await cmdGoto(arg);
|
|
3358
3475
|
break;
|
|
3359
3476
|
case 'wait':
|
|
3360
|
-
case 'sleep':
|
|
3361
3477
|
await new Promise(r => setTimeout(r, arg * 1000));
|
|
3362
3478
|
log.ok(`Waited ${arg}s`);
|
|
3363
3479
|
break;
|
|
3364
3480
|
case 'eval':
|
|
3365
|
-
case 'js':
|
|
3366
3481
|
await cmdEval(arg);
|
|
3367
3482
|
break;
|
|
3368
3483
|
case 'click':
|
|
@@ -3380,7 +3495,6 @@ async function cmdRun(taskFile) {
|
|
|
3380
3495
|
await cmdText();
|
|
3381
3496
|
break;
|
|
3382
3497
|
case 'log':
|
|
3383
|
-
case 'echo':
|
|
3384
3498
|
console.log(`${BLUE}[LOG]${NC} ${arg}`);
|
|
3385
3499
|
break;
|
|
3386
3500
|
case 'assert':
|
|
@@ -3578,18 +3692,17 @@ ${B5}SETUP${NC}
|
|
|
3578
3692
|
${BW}install${NC} Install detached relay supervisor ${DIM}(current session, auto-restarts)${NC}
|
|
3579
3693
|
${BW}uninstall${NC} Remove daemon
|
|
3580
3694
|
${BW}update${NC} Update to latest version
|
|
3581
|
-
${BW}connect${NC} Connect to browser ${DIM}(uses $
|
|
3695
|
+
${BW}connect${NC} Connect to browser ${DIM}(uses $GLIDER/config/browser.json)${NC}
|
|
3582
3696
|
|
|
3583
3697
|
${B5}STATUS${NC}
|
|
3584
3698
|
${BW}status${NC} Check server, extension, tabs
|
|
3585
|
-
${BW}doctor${NC} Relay + SW + targets
|
|
3586
|
-
${BW}heal${NC}
|
|
3587
|
-
${BW}reload${NC}
|
|
3588
|
-
${BW}browser${NC}
|
|
3589
|
-
${BW}use${NC} <key> Set browser by registry key ${DIM}(e.g. arc, brave, chrome)${NC}
|
|
3699
|
+
${BW}doctor${NC} Relay + SW + targets
|
|
3700
|
+
${BW}heal${NC} Ensure relay, wake SW, reattach
|
|
3701
|
+
${BW}reload${NC} Pin Glider extension
|
|
3702
|
+
${BW}config browser chrome${NC} ${DIM}also: edge, brave, opera, vivaldi, helium, arc${NC}
|
|
3590
3703
|
${BW}test${NC} Run diagnostics
|
|
3591
3704
|
${BW}domains${NC} List ~/.glider domain shortcuts + warch paths
|
|
3592
|
-
${BW}resolve${NC} <url> Domain intel under ~/.glider/warch
|
|
3705
|
+
${BW}resolve${NC} <url> Domain intel under ~/.glider/warch
|
|
3593
3706
|
|
|
3594
3707
|
${B5}NAVIGATION${NC}
|
|
3595
3708
|
${BW}goto${NC} <url> Navigate to URL
|
|
@@ -3636,16 +3749,11 @@ ${B5}EXTRACTION PATTERNS${NC} ${DIM}(bulletproof, domain-agnostic)${NC}
|
|
|
3636
3749
|
|
|
3637
3750
|
${B5}AUTOMATION${NC}
|
|
3638
3751
|
${BW}run${NC} <task.yaml> Execute YAML task file
|
|
3639
|
-
${BW}loop${NC} <task>
|
|
3640
|
-
${BW}ralph${NC} <task> ${DIM}Alias for loop${NC}
|
|
3641
|
-
|
|
3642
|
-
${B5}LOOP OPTIONS${NC}
|
|
3643
|
-
-n, --max-iterations N Max iterations ${DIM}(default: 10)${NC}
|
|
3644
|
-
-t, --timeout N Timeout in seconds ${DIM}(default: 3600)${NC}
|
|
3645
|
-
-m, --marker STRING Completion marker ${DIM}(default: LOOP_COMPLETE)${NC}
|
|
3752
|
+
${BW}loop${NC} <task.yaml> Loop until marker
|
|
3646
3753
|
|
|
3647
3754
|
${B5}EXAMPLES${NC}
|
|
3648
3755
|
${DIM}$${NC} glider install ${DIM}# one-time setup${NC}
|
|
3756
|
+
${DIM}$${NC} glider config browser chrome
|
|
3649
3757
|
${DIM}$${NC} glider connect ${DIM}# connect to the configured Chromium browser${NC}
|
|
3650
3758
|
${DIM}$${NC} glider goto "https://x.com" ${DIM}# navigate${NC}
|
|
3651
3759
|
${DIM}$${NC} glider eval "document.title"${DIM}# run JS${NC}
|
|
@@ -3685,7 +3793,7 @@ ${YELLOW}REQUIREMENTS:${NC}
|
|
|
3685
3793
|
- Glider extension from Chrome Web Store connected in a Chromium browser
|
|
3686
3794
|
|
|
3687
3795
|
${YELLOW}DOMAIN EXTENSIONS:${NC}
|
|
3688
|
-
Add custom domain commands via $
|
|
3796
|
+
Add custom domain commands via $GLIDER/config/domains.json:
|
|
3689
3797
|
{
|
|
3690
3798
|
"mysite": { "url": "https://mysite.com/dashboard" },
|
|
3691
3799
|
"mytool": { "script": "~/scripts/mytool.sh" }
|
|
@@ -3721,7 +3829,7 @@ ${YELLOW}DOMAIN EXTENSIONS:${NC}
|
|
|
3721
3829
|
pluginVerbs.push({ verb, def });
|
|
3722
3830
|
}
|
|
3723
3831
|
if (pluginVerbs.length > 0) {
|
|
3724
|
-
console.log(`${YELLOW}PLUGINS:${NC} (from $
|
|
3832
|
+
console.log(`${YELLOW}PLUGINS:${NC} (from $GLIDER/plugins/)`);
|
|
3725
3833
|
for (const { verb, def } of pluginVerbs) {
|
|
3726
3834
|
const desc = (Array.isArray(def.help) ? def.help.find(l => !/^Usage:/i.test(l)) : def.help) || '(no description)';
|
|
3727
3835
|
const shortDesc = String(desc).replace(/^\s+/, '').slice(0, 60);
|
|
@@ -3861,7 +3969,7 @@ const GLIDER_PLUGIN_REGISTRY = new Map(); // verb → plugin def
|
|
|
3861
3969
|
function pluginDirs() {
|
|
3862
3970
|
const dirs = [];
|
|
3863
3971
|
if (process.env.GLIDER_PLUGIN_DIR) dirs.push(process.env.GLIDER_PLUGIN_DIR);
|
|
3864
|
-
dirs.push(path.join(
|
|
3972
|
+
dirs.push(path.join(GLIDER, 'plugins'));
|
|
3865
3973
|
return dirs.filter(d => { try { return fs.statSync(d).isDirectory(); } catch { return false; } });
|
|
3866
3974
|
}
|
|
3867
3975
|
|
|
@@ -4869,9 +4977,9 @@ async function cmdUpload(argv) {
|
|
|
4869
4977
|
// not implemented"). Now delegates to the same code path `explore --har` uses.
|
|
4870
4978
|
async function cmdHar(argv) {
|
|
4871
4979
|
const sub = argv[0];
|
|
4872
|
-
const STATE_PATH = path.join(
|
|
4873
|
-
const BUF_HAR = path.join(
|
|
4874
|
-
const BUF_OUT = path.join(
|
|
4980
|
+
const STATE_PATH = path.join(GLIDER, 'har-state.json');
|
|
4981
|
+
const BUF_HAR = path.join(GLIDER, 'har-buffer.har');
|
|
4982
|
+
const BUF_OUT = path.join(GLIDER, 'har-buffer-out');
|
|
4875
4983
|
const readState = () => { try { return JSON.parse(fs.readFileSync(STATE_PATH, 'utf8')); } catch { return null; } };
|
|
4876
4984
|
const writeState = (st) => { try { fs.mkdirSync(path.dirname(STATE_PATH), { recursive: true }); } catch {} fs.writeFileSync(STATE_PATH, JSON.stringify(st, null, 2)); };
|
|
4877
4985
|
const pidAlive = (pid) => { if (!pid) return false; try { process.kill(pid, 0); return true; } catch { return false; } };
|
|
@@ -5104,25 +5212,6 @@ async function main() {
|
|
|
5104
5212
|
loadPlugins(); // hydrate ~/.glider/plugins/*.plugin.{json,js} - verb-agnostic core
|
|
5105
5213
|
let cmd = args[0];
|
|
5106
5214
|
|
|
5107
|
-
// reload-ext command aliases -
|
|
5108
|
-
// Bare `reload` pins the extension (page refresh stays `history reload`).
|
|
5109
|
-
// Rewrites args in place so downstream switch stays clean.
|
|
5110
|
-
const RELOAD_EXT_ALIASES = new Set(['rex', 'reloadext', 'reloadExt']);
|
|
5111
|
-
if (cmd === 'ext' && args[1] === 'reload') {
|
|
5112
|
-
cmd = 'reload-ext';
|
|
5113
|
-
args.splice(0, 2, 'reload-ext');
|
|
5114
|
-
} else if (cmd === 'reload' && (!args[1] || args[1] === 'ext' || args[1] === 'extension')) {
|
|
5115
|
-
// Bare `reload` = pin extension. Page refresh stays `history reload`.
|
|
5116
|
-
cmd = 'reload-ext';
|
|
5117
|
-
if (args[1]) args.splice(0, 2, 'reload-ext');
|
|
5118
|
-
else args[0] = 'reload-ext';
|
|
5119
|
-
} else if (RELOAD_EXT_ALIASES.has(cmd)) {
|
|
5120
|
-
cmd = 'reload-ext';
|
|
5121
|
-
args[0] = 'reload-ext';
|
|
5122
|
-
}
|
|
5123
|
-
// Typo suggest: if cmd looks like a common command with 1-2 char edit distance, hint it.
|
|
5124
|
-
// (Only checked in unknown-command branch below - this block just normalizes.)
|
|
5125
|
-
|
|
5126
5215
|
if (!cmd || cmd === '--help' || cmd === '-h') {
|
|
5127
5216
|
showHelp();
|
|
5128
5217
|
process.exit(0);
|
|
@@ -5130,7 +5219,7 @@ async function main() {
|
|
|
5130
5219
|
|
|
5131
5220
|
const relayIndependent = new Set([
|
|
5132
5221
|
'help', '--help', '-h', 'update', 'version', '-v', '--version',
|
|
5133
|
-
'
|
|
5222
|
+
'config', 'domains', 'resolve',
|
|
5134
5223
|
]);
|
|
5135
5224
|
if (relayConfigError && !relayIndependent.has(cmd)) {
|
|
5136
5225
|
throw relayConfigError;
|
|
@@ -5146,7 +5235,7 @@ async function main() {
|
|
|
5146
5235
|
// Config, diagnostics, and relay-management commands handle availability themselves.
|
|
5147
5236
|
const noRelayPreflight = new Set([
|
|
5148
5237
|
'start', 'stop', 'restart', 'status', 'test', 'doctor', 'heal', 'connect',
|
|
5149
|
-
'install', 'uninstall', '
|
|
5238
|
+
'install', 'uninstall', 'config',
|
|
5150
5239
|
'help', '--help', '-h', 'update', 'version', '-v', '--version',
|
|
5151
5240
|
'domains', 'resolve',
|
|
5152
5241
|
]);
|
|
@@ -5176,8 +5265,6 @@ async function main() {
|
|
|
5176
5265
|
await cmdRestart();
|
|
5177
5266
|
break;
|
|
5178
5267
|
case 'reload':
|
|
5179
|
-
case 'reload-ext':
|
|
5180
|
-
case 'reload-extension':
|
|
5181
5268
|
await cmdReloadExt();
|
|
5182
5269
|
break;
|
|
5183
5270
|
case 'attach-all':
|
|
@@ -5200,11 +5287,8 @@ async function main() {
|
|
|
5200
5287
|
case 'connect':
|
|
5201
5288
|
await cmdConnect();
|
|
5202
5289
|
break;
|
|
5203
|
-
case '
|
|
5204
|
-
|
|
5205
|
-
break;
|
|
5206
|
-
case 'use':
|
|
5207
|
-
cmdUse(args[1]);
|
|
5290
|
+
case 'config':
|
|
5291
|
+
await cmdConfig(args.slice(1));
|
|
5208
5292
|
break;
|
|
5209
5293
|
case 'test':
|
|
5210
5294
|
await cmdTest();
|
|
@@ -5228,7 +5312,6 @@ async function main() {
|
|
|
5228
5312
|
await cmdSnapshot(args.slice(1));
|
|
5229
5313
|
break;
|
|
5230
5314
|
case 'window':
|
|
5231
|
-
case 'win':
|
|
5232
5315
|
await cmdWindow(args.slice(1));
|
|
5233
5316
|
break;
|
|
5234
5317
|
case 'domains':
|
|
@@ -5238,14 +5321,9 @@ async function main() {
|
|
|
5238
5321
|
await cmdResolve(args[1], args.slice(2));
|
|
5239
5322
|
break;
|
|
5240
5323
|
case 'goto':
|
|
5241
|
-
case 'navigate':
|
|
5242
5324
|
await cmdGoto(args[1]);
|
|
5243
5325
|
break;
|
|
5244
|
-
case 'open':
|
|
5245
|
-
await cmdOpen(args[1]);
|
|
5246
|
-
break;
|
|
5247
5326
|
case 'eval':
|
|
5248
|
-
case 'js':
|
|
5249
5327
|
await cmdEvalV2(args.slice(1));
|
|
5250
5328
|
break;
|
|
5251
5329
|
case 'click':
|
|
@@ -5271,11 +5349,7 @@ async function main() {
|
|
|
5271
5349
|
await cmdBlurVerb(args.slice(1));
|
|
5272
5350
|
break;
|
|
5273
5351
|
case 'scroll':
|
|
5274
|
-
|
|
5275
|
-
case 'scroll-by':
|
|
5276
|
-
case 'scroll-until':
|
|
5277
|
-
if (cmd === 'scroll') await cmdScroll(args.slice(1));
|
|
5278
|
-
else await cmdScroll([cmd.replace('scroll-',''), ...args.slice(1)]);
|
|
5352
|
+
await cmdScroll(args.slice(1));
|
|
5279
5353
|
break;
|
|
5280
5354
|
case 'wait':
|
|
5281
5355
|
await cmdWait(args.slice(1));
|
|
@@ -5363,8 +5437,6 @@ async function main() {
|
|
|
5363
5437
|
await cmdFrozen(args.slice(1));
|
|
5364
5438
|
break;
|
|
5365
5439
|
case 'thaw':
|
|
5366
|
-
case 'unfreeze':
|
|
5367
|
-
case 'wake':
|
|
5368
5440
|
await cmdThaw(args.slice(1));
|
|
5369
5441
|
break;
|
|
5370
5442
|
case 'freeze':
|
|
@@ -5390,13 +5462,10 @@ async function main() {
|
|
|
5390
5462
|
// Use registry pattern - bulletproof method
|
|
5391
5463
|
await cmdRegistry('favicon', args.slice(1));
|
|
5392
5464
|
break;
|
|
5393
|
-
case 'registry':
|
|
5394
5465
|
case 'reg':
|
|
5395
|
-
// Run a registry pattern
|
|
5396
5466
|
await cmdRegistry(args[1], args.slice(2));
|
|
5397
5467
|
break;
|
|
5398
5468
|
case 'loop':
|
|
5399
|
-
case 'ralph': // alias for loop - Ralph Wiggum pattern
|
|
5400
5469
|
// Parse loop options
|
|
5401
5470
|
const loopOpts = {
|
|
5402
5471
|
maxIterations: 10,
|
|
@@ -5445,29 +5514,7 @@ async function main() {
|
|
|
5445
5514
|
}
|
|
5446
5515
|
break;
|
|
5447
5516
|
}
|
|
5448
|
-
|
|
5449
|
-
// v0.3.15: typo suggest (Levenshtein <=2) before dumping full help.
|
|
5450
|
-
const KNOWN_CMDS = ['status','start','stop','restart','reload','reload-ext','attach-all','install','uninstall',
|
|
5451
|
-
'update','version','connect','browser','use','test','doctor','heal','domains','resolve','goto','eval','click','type',
|
|
5452
|
-
'screenshot','snapshot','text','html','title','url','tabs','targets','use-session','fetch','spawn',
|
|
5453
|
-
'extract','explore','favicon','window','reg','run','loop','ralph',
|
|
5454
|
-
'read','hover','focus','blur','scroll','wait','key','right-click','double-click','click-at','drag','select',
|
|
5455
|
-
'frames','frame-eval','upload','har','emulate','storage','history','dialog','console','pdf','mock','a11y','cookies'];
|
|
5456
|
-
function lev(a, b) {
|
|
5457
|
-
if (Math.abs(a.length - b.length) > 2) return 3;
|
|
5458
|
-
const m = Array.from({length: a.length+1}, () => new Array(b.length+1).fill(0));
|
|
5459
|
-
for (let i = 0; i <= a.length; i++) m[i][0] = i;
|
|
5460
|
-
for (let j = 0; j <= b.length; j++) m[0][j] = j;
|
|
5461
|
-
for (let i = 1; i <= a.length; i++) for (let j = 1; j <= b.length; j++) {
|
|
5462
|
-
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]);
|
|
5463
|
-
}
|
|
5464
|
-
return m[a.length][b.length];
|
|
5465
|
-
}
|
|
5466
|
-
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);
|
|
5467
|
-
if (near.length > 0) {
|
|
5468
|
-
log.info(` Did you mean: ${near.map(x => x[0]).join(', ')} ?`);
|
|
5469
|
-
}
|
|
5470
|
-
showHelp();
|
|
5517
|
+
console.error(`Unknown command: ${cmd}`);
|
|
5471
5518
|
process.exit(1);
|
|
5472
5519
|
}
|
|
5473
5520
|
}
|