glidercli 0.4.14 → 0.4.16
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 +175 -147
- 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 +228 -142
- package/lib/browser-config.js +1 -1
- package/lib/glider-daemon.sh +133 -6
- package/lib/paths.js +5 -7
- package/package.json +2 -2
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(
|
|
@@ -827,7 +877,7 @@ async function requestActiveTabAttach() {
|
|
|
827
877
|
return data;
|
|
828
878
|
}
|
|
829
879
|
|
|
830
|
-
// Auto-connect helper - honors the browser selected by $
|
|
880
|
+
// Auto-connect helper - honors the browser selected by $GLIDER/config/browser.json.
|
|
831
881
|
async function ensureConnected() {
|
|
832
882
|
// Check if already connected
|
|
833
883
|
if (await checkTab()) {
|
|
@@ -999,7 +1049,7 @@ async function cmdStart({ render = true } = {}) {
|
|
|
999
1049
|
throw new Error(`bserve not found at ${RELAY_ENTRY}`);
|
|
1000
1050
|
}
|
|
1001
1051
|
|
|
1002
|
-
fs.mkdirSync(
|
|
1052
|
+
fs.mkdirSync(GLIDER, { recursive: true });
|
|
1003
1053
|
if (render) log.info('Starting glider server...');
|
|
1004
1054
|
const locks = await acquireStandaloneRelayLocks();
|
|
1005
1055
|
|
|
@@ -1011,6 +1061,8 @@ async function cmdStart({ render = true } = {}) {
|
|
|
1011
1061
|
status = await getRelayStatus();
|
|
1012
1062
|
} catch {}
|
|
1013
1063
|
|
|
1064
|
+
if (!status?.pid) reapOrphanedDaemonState();
|
|
1065
|
+
|
|
1014
1066
|
const ownership = inspectDaemonOwnership();
|
|
1015
1067
|
if (status?.pid) {
|
|
1016
1068
|
if (
|
|
@@ -1084,7 +1136,7 @@ async function cmdStart({ render = true } = {}) {
|
|
|
1084
1136
|
}
|
|
1085
1137
|
|
|
1086
1138
|
async function cmdStop({ render = true } = {}) {
|
|
1087
|
-
fs.mkdirSync(
|
|
1139
|
+
fs.mkdirSync(GLIDER, { recursive: true });
|
|
1088
1140
|
const locks = await acquireStandaloneRelayLocks();
|
|
1089
1141
|
try {
|
|
1090
1142
|
assertStandaloneRelayAllowed();
|
|
@@ -1481,7 +1533,7 @@ async function httpGetJson(pathStr) {
|
|
|
1481
1533
|
async function cmdInstallDaemon() {
|
|
1482
1534
|
const home = os.homedir();
|
|
1483
1535
|
const daemonScript = DAEMON_ENTRY;
|
|
1484
|
-
const logDir =
|
|
1536
|
+
const logDir = GLIDER;
|
|
1485
1537
|
const pidFile = DAEMON_PID_FILE;
|
|
1486
1538
|
const legacyPidFile = path.join(logDir, 'daemon.pid');
|
|
1487
1539
|
|
|
@@ -1500,7 +1552,11 @@ async function cmdInstallDaemon() {
|
|
|
1500
1552
|
if (legacy.state === 'stale') {
|
|
1501
1553
|
try { fs.unlinkSync(legacyPidFile); } catch {}
|
|
1502
1554
|
}
|
|
1503
|
-
|
|
1555
|
+
|
|
1556
|
+
let preInstallStatus = null;
|
|
1557
|
+
try { preInstallStatus = await getRelayStatus(); } catch {}
|
|
1558
|
+
if (!preInstallStatus?.pid) reapOrphanedDaemonState();
|
|
1559
|
+
|
|
1504
1560
|
if (fs.existsSync(pidFile)) {
|
|
1505
1561
|
const record = readDaemonPidRecord(pidFile);
|
|
1506
1562
|
const identity = record ? getProcessIdentity(record.pid) : null;
|
|
@@ -1535,6 +1591,7 @@ async function cmdInstallDaemon() {
|
|
|
1535
1591
|
cwd: home,
|
|
1536
1592
|
env: {
|
|
1537
1593
|
...process.env,
|
|
1594
|
+
GLIDER,
|
|
1538
1595
|
GLIDER_PORT: String(PORT),
|
|
1539
1596
|
GLIDER_DAEMON_MANAGEMENT_OWNER_PID: String(managementLock.pid),
|
|
1540
1597
|
GLIDER_DAEMON_MANAGEMENT_OWNER_STARTED: managementLock.started,
|
|
@@ -1582,9 +1639,9 @@ async function cmdInstallDaemon() {
|
|
|
1582
1639
|
}
|
|
1583
1640
|
|
|
1584
1641
|
async function cmdUninstallDaemon() {
|
|
1585
|
-
fs.mkdirSync(
|
|
1642
|
+
fs.mkdirSync(GLIDER, { recursive: true });
|
|
1586
1643
|
const pidFile = DAEMON_PID_FILE;
|
|
1587
|
-
const legacyPidFile = path.join(
|
|
1644
|
+
const legacyPidFile = path.join(GLIDER, 'daemon.pid');
|
|
1588
1645
|
const daemonScript = DAEMON_ENTRY;
|
|
1589
1646
|
const claimDir = DAEMON_CLAIM_DIR;
|
|
1590
1647
|
const managementLock = await acquireDaemonManagementLock();
|
|
@@ -1712,7 +1769,7 @@ async function cmdConnect() {
|
|
|
1712
1769
|
process.exit(1);
|
|
1713
1770
|
}
|
|
1714
1771
|
|
|
1715
|
-
// 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)
|
|
1716
1773
|
try {
|
|
1717
1774
|
const tabUrl = activeBrowserTabUrl(browser);
|
|
1718
1775
|
if (isBrowserInternalUrl(tabUrl)) {
|
|
@@ -1797,54 +1854,97 @@ async function cmdConnect() {
|
|
|
1797
1854
|
process.exit(1);
|
|
1798
1855
|
}
|
|
1799
1856
|
|
|
1800
|
-
function
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
registrySource: b.registrySource,
|
|
1811
|
-
});
|
|
1812
|
-
return;
|
|
1813
|
-
}
|
|
1814
|
-
console.log('Browser config (used by glider connect):');
|
|
1815
|
-
console.log(` name: ${b.name}`);
|
|
1816
|
-
console.log(` path: ${b.path || '(default launch via name)'}`);
|
|
1817
|
-
console.log(` processName: ${b.processName}`);
|
|
1818
|
-
console.log(` bootstrapUrl: ${b.bootstrapUrl}`);
|
|
1819
|
-
if (b.use) {
|
|
1820
|
-
console.log(` use: ${b.use} ${DIM}(from registry)${NC}`);
|
|
1821
|
-
}
|
|
1822
|
-
console.log('');
|
|
1823
|
-
console.log(`Source: ${b.source || path.join(GLIDER_HOME, 'config', 'browser.json')} { "use": "<key>" } or { name, path } -> default "Google Chrome"`);
|
|
1824
|
-
console.log(`Registry: ${b.registrySource || path.join(GLIDER_HOME, 'config', 'browsers-registry.json')}. Keys: ` + (Object.keys(b.registry).join(', ') || '(none loaded)'));
|
|
1825
|
-
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
|
+
});
|
|
1826
1867
|
}
|
|
1827
1868
|
|
|
1828
|
-
function
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
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) {
|
|
1836
1885
|
if (!browser.registry[key]) {
|
|
1837
|
-
console.error(
|
|
1886
|
+
console.error(`Unknown command: config browser ${key}`);
|
|
1887
|
+
printConfigBrowserCommands(browser);
|
|
1838
1888
|
process.exit(1);
|
|
1839
1889
|
}
|
|
1840
|
-
const configDir = path.join(
|
|
1890
|
+
const configDir = path.join(GLIDER, 'config');
|
|
1841
1891
|
const browserPath = path.join(configDir, 'browser.json');
|
|
1842
1892
|
if (!fs.existsSync(configDir)) fs.mkdirSync(configDir, { recursive: true });
|
|
1843
1893
|
fs.writeFileSync(browserPath, JSON.stringify({ use: key }, null, 2) + '\n');
|
|
1844
|
-
console.log(
|
|
1894
|
+
console.log(`glider config browser ${key}`);
|
|
1895
|
+
console.log(browser.registry[key].name);
|
|
1845
1896
|
console.log('Run: glider connect');
|
|
1846
1897
|
}
|
|
1847
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
|
+
|
|
1848
1948
|
async function cmdTest() {
|
|
1849
1949
|
let relay = null;
|
|
1850
1950
|
try {
|
|
@@ -2145,8 +2245,7 @@ async function cmdWindow(args) {
|
|
|
2145
2245
|
const subcmd = args[0] || 'list';
|
|
2146
2246
|
|
|
2147
2247
|
switch (subcmd) {
|
|
2148
|
-
case 'new':
|
|
2149
|
-
case 'create': {
|
|
2248
|
+
case 'new': {
|
|
2150
2249
|
const url = args[1] || 'about:blank';
|
|
2151
2250
|
log.info(`Creating new window: ${url}`);
|
|
2152
2251
|
const result = await wm.createWindow(url);
|
|
@@ -3372,16 +3471,13 @@ async function cmdRun(taskFile) {
|
|
|
3372
3471
|
try {
|
|
3373
3472
|
switch (cmd) {
|
|
3374
3473
|
case 'goto':
|
|
3375
|
-
case 'navigate':
|
|
3376
3474
|
await cmdGoto(arg);
|
|
3377
3475
|
break;
|
|
3378
3476
|
case 'wait':
|
|
3379
|
-
case 'sleep':
|
|
3380
3477
|
await new Promise(r => setTimeout(r, arg * 1000));
|
|
3381
3478
|
log.ok(`Waited ${arg}s`);
|
|
3382
3479
|
break;
|
|
3383
3480
|
case 'eval':
|
|
3384
|
-
case 'js':
|
|
3385
3481
|
await cmdEval(arg);
|
|
3386
3482
|
break;
|
|
3387
3483
|
case 'click':
|
|
@@ -3399,7 +3495,6 @@ async function cmdRun(taskFile) {
|
|
|
3399
3495
|
await cmdText();
|
|
3400
3496
|
break;
|
|
3401
3497
|
case 'log':
|
|
3402
|
-
case 'echo':
|
|
3403
3498
|
console.log(`${BLUE}[LOG]${NC} ${arg}`);
|
|
3404
3499
|
break;
|
|
3405
3500
|
case 'assert':
|
|
@@ -3597,18 +3692,17 @@ ${B5}SETUP${NC}
|
|
|
3597
3692
|
${BW}install${NC} Install detached relay supervisor ${DIM}(current session, auto-restarts)${NC}
|
|
3598
3693
|
${BW}uninstall${NC} Remove daemon
|
|
3599
3694
|
${BW}update${NC} Update to latest version
|
|
3600
|
-
${BW}connect${NC} Connect to browser ${DIM}(uses $
|
|
3695
|
+
${BW}connect${NC} Connect to browser ${DIM}(uses $GLIDER/config/browser.json)${NC}
|
|
3601
3696
|
|
|
3602
3697
|
${B5}STATUS${NC}
|
|
3603
3698
|
${BW}status${NC} Check server, extension, tabs
|
|
3604
|
-
${BW}doctor${NC} Relay + SW + targets
|
|
3605
|
-
${BW}heal${NC}
|
|
3606
|
-
${BW}reload${NC}
|
|
3607
|
-
${BW}browser${NC}
|
|
3608
|
-
${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}
|
|
3609
3703
|
${BW}test${NC} Run diagnostics
|
|
3610
3704
|
${BW}domains${NC} List ~/.glider domain shortcuts + warch paths
|
|
3611
|
-
${BW}resolve${NC} <url> Domain intel under ~/.glider/warch
|
|
3705
|
+
${BW}resolve${NC} <url> Domain intel under ~/.glider/warch
|
|
3612
3706
|
|
|
3613
3707
|
${B5}NAVIGATION${NC}
|
|
3614
3708
|
${BW}goto${NC} <url> Navigate to URL
|
|
@@ -3655,16 +3749,11 @@ ${B5}EXTRACTION PATTERNS${NC} ${DIM}(bulletproof, domain-agnostic)${NC}
|
|
|
3655
3749
|
|
|
3656
3750
|
${B5}AUTOMATION${NC}
|
|
3657
3751
|
${BW}run${NC} <task.yaml> Execute YAML task file
|
|
3658
|
-
${BW}loop${NC} <task>
|
|
3659
|
-
${BW}ralph${NC} <task> ${DIM}Alias for loop${NC}
|
|
3660
|
-
|
|
3661
|
-
${B5}LOOP OPTIONS${NC}
|
|
3662
|
-
-n, --max-iterations N Max iterations ${DIM}(default: 10)${NC}
|
|
3663
|
-
-t, --timeout N Timeout in seconds ${DIM}(default: 3600)${NC}
|
|
3664
|
-
-m, --marker STRING Completion marker ${DIM}(default: LOOP_COMPLETE)${NC}
|
|
3752
|
+
${BW}loop${NC} <task.yaml> Loop until marker
|
|
3665
3753
|
|
|
3666
3754
|
${B5}EXAMPLES${NC}
|
|
3667
3755
|
${DIM}$${NC} glider install ${DIM}# one-time setup${NC}
|
|
3756
|
+
${DIM}$${NC} glider config browser chrome
|
|
3668
3757
|
${DIM}$${NC} glider connect ${DIM}# connect to the configured Chromium browser${NC}
|
|
3669
3758
|
${DIM}$${NC} glider goto "https://x.com" ${DIM}# navigate${NC}
|
|
3670
3759
|
${DIM}$${NC} glider eval "document.title"${DIM}# run JS${NC}
|
|
@@ -3704,7 +3793,7 @@ ${YELLOW}REQUIREMENTS:${NC}
|
|
|
3704
3793
|
- Glider extension from Chrome Web Store connected in a Chromium browser
|
|
3705
3794
|
|
|
3706
3795
|
${YELLOW}DOMAIN EXTENSIONS:${NC}
|
|
3707
|
-
Add custom domain commands via $
|
|
3796
|
+
Add custom domain commands via $GLIDER/config/domains.json:
|
|
3708
3797
|
{
|
|
3709
3798
|
"mysite": { "url": "https://mysite.com/dashboard" },
|
|
3710
3799
|
"mytool": { "script": "~/scripts/mytool.sh" }
|
|
@@ -3740,7 +3829,7 @@ ${YELLOW}DOMAIN EXTENSIONS:${NC}
|
|
|
3740
3829
|
pluginVerbs.push({ verb, def });
|
|
3741
3830
|
}
|
|
3742
3831
|
if (pluginVerbs.length > 0) {
|
|
3743
|
-
console.log(`${YELLOW}PLUGINS:${NC} (from $
|
|
3832
|
+
console.log(`${YELLOW}PLUGINS:${NC} (from $GLIDER/plugins/)`);
|
|
3744
3833
|
for (const { verb, def } of pluginVerbs) {
|
|
3745
3834
|
const desc = (Array.isArray(def.help) ? def.help.find(l => !/^Usage:/i.test(l)) : def.help) || '(no description)';
|
|
3746
3835
|
const shortDesc = String(desc).replace(/^\s+/, '').slice(0, 60);
|
|
@@ -3880,7 +3969,7 @@ const GLIDER_PLUGIN_REGISTRY = new Map(); // verb → plugin def
|
|
|
3880
3969
|
function pluginDirs() {
|
|
3881
3970
|
const dirs = [];
|
|
3882
3971
|
if (process.env.GLIDER_PLUGIN_DIR) dirs.push(process.env.GLIDER_PLUGIN_DIR);
|
|
3883
|
-
dirs.push(path.join(
|
|
3972
|
+
dirs.push(path.join(GLIDER, 'plugins'));
|
|
3884
3973
|
return dirs.filter(d => { try { return fs.statSync(d).isDirectory(); } catch { return false; } });
|
|
3885
3974
|
}
|
|
3886
3975
|
|
|
@@ -4888,9 +4977,9 @@ async function cmdUpload(argv) {
|
|
|
4888
4977
|
// not implemented"). Now delegates to the same code path `explore --har` uses.
|
|
4889
4978
|
async function cmdHar(argv) {
|
|
4890
4979
|
const sub = argv[0];
|
|
4891
|
-
const STATE_PATH = path.join(
|
|
4892
|
-
const BUF_HAR = path.join(
|
|
4893
|
-
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');
|
|
4894
4983
|
const readState = () => { try { return JSON.parse(fs.readFileSync(STATE_PATH, 'utf8')); } catch { return null; } };
|
|
4895
4984
|
const writeState = (st) => { try { fs.mkdirSync(path.dirname(STATE_PATH), { recursive: true }); } catch {} fs.writeFileSync(STATE_PATH, JSON.stringify(st, null, 2)); };
|
|
4896
4985
|
const pidAlive = (pid) => { if (!pid) return false; try { process.kill(pid, 0); return true; } catch { return false; } };
|
|
@@ -5123,25 +5212,6 @@ async function main() {
|
|
|
5123
5212
|
loadPlugins(); // hydrate ~/.glider/plugins/*.plugin.{json,js} - verb-agnostic core
|
|
5124
5213
|
let cmd = args[0];
|
|
5125
5214
|
|
|
5126
|
-
// reload-ext command aliases -
|
|
5127
|
-
// Bare `reload` pins the extension (page refresh stays `history reload`).
|
|
5128
|
-
// Rewrites args in place so downstream switch stays clean.
|
|
5129
|
-
const RELOAD_EXT_ALIASES = new Set(['rex', 'reloadext', 'reloadExt']);
|
|
5130
|
-
if (cmd === 'ext' && args[1] === 'reload') {
|
|
5131
|
-
cmd = 'reload-ext';
|
|
5132
|
-
args.splice(0, 2, 'reload-ext');
|
|
5133
|
-
} else if (cmd === 'reload' && (!args[1] || args[1] === 'ext' || args[1] === 'extension')) {
|
|
5134
|
-
// Bare `reload` = pin extension. Page refresh stays `history reload`.
|
|
5135
|
-
cmd = 'reload-ext';
|
|
5136
|
-
if (args[1]) args.splice(0, 2, 'reload-ext');
|
|
5137
|
-
else args[0] = 'reload-ext';
|
|
5138
|
-
} else if (RELOAD_EXT_ALIASES.has(cmd)) {
|
|
5139
|
-
cmd = 'reload-ext';
|
|
5140
|
-
args[0] = 'reload-ext';
|
|
5141
|
-
}
|
|
5142
|
-
// Typo suggest: if cmd looks like a common command with 1-2 char edit distance, hint it.
|
|
5143
|
-
// (Only checked in unknown-command branch below - this block just normalizes.)
|
|
5144
|
-
|
|
5145
5215
|
if (!cmd || cmd === '--help' || cmd === '-h') {
|
|
5146
5216
|
showHelp();
|
|
5147
5217
|
process.exit(0);
|
|
@@ -5149,7 +5219,7 @@ async function main() {
|
|
|
5149
5219
|
|
|
5150
5220
|
const relayIndependent = new Set([
|
|
5151
5221
|
'help', '--help', '-h', 'update', 'version', '-v', '--version',
|
|
5152
|
-
'
|
|
5222
|
+
'config', 'domains', 'resolve',
|
|
5153
5223
|
]);
|
|
5154
5224
|
if (relayConfigError && !relayIndependent.has(cmd)) {
|
|
5155
5225
|
throw relayConfigError;
|
|
@@ -5165,7 +5235,7 @@ async function main() {
|
|
|
5165
5235
|
// Config, diagnostics, and relay-management commands handle availability themselves.
|
|
5166
5236
|
const noRelayPreflight = new Set([
|
|
5167
5237
|
'start', 'stop', 'restart', 'status', 'test', 'doctor', 'heal', 'connect',
|
|
5168
|
-
'install', 'uninstall', '
|
|
5238
|
+
'install', 'uninstall', 'config',
|
|
5169
5239
|
'help', '--help', '-h', 'update', 'version', '-v', '--version',
|
|
5170
5240
|
'domains', 'resolve',
|
|
5171
5241
|
]);
|
|
@@ -5195,8 +5265,6 @@ async function main() {
|
|
|
5195
5265
|
await cmdRestart();
|
|
5196
5266
|
break;
|
|
5197
5267
|
case 'reload':
|
|
5198
|
-
case 'reload-ext':
|
|
5199
|
-
case 'reload-extension':
|
|
5200
5268
|
await cmdReloadExt();
|
|
5201
5269
|
break;
|
|
5202
5270
|
case 'attach-all':
|
|
@@ -5219,11 +5287,8 @@ async function main() {
|
|
|
5219
5287
|
case 'connect':
|
|
5220
5288
|
await cmdConnect();
|
|
5221
5289
|
break;
|
|
5222
|
-
case '
|
|
5223
|
-
|
|
5224
|
-
break;
|
|
5225
|
-
case 'use':
|
|
5226
|
-
cmdUse(args[1]);
|
|
5290
|
+
case 'config':
|
|
5291
|
+
await cmdConfig(args.slice(1));
|
|
5227
5292
|
break;
|
|
5228
5293
|
case 'test':
|
|
5229
5294
|
await cmdTest();
|
|
@@ -5247,7 +5312,6 @@ async function main() {
|
|
|
5247
5312
|
await cmdSnapshot(args.slice(1));
|
|
5248
5313
|
break;
|
|
5249
5314
|
case 'window':
|
|
5250
|
-
case 'win':
|
|
5251
5315
|
await cmdWindow(args.slice(1));
|
|
5252
5316
|
break;
|
|
5253
5317
|
case 'domains':
|
|
@@ -5257,14 +5321,9 @@ async function main() {
|
|
|
5257
5321
|
await cmdResolve(args[1], args.slice(2));
|
|
5258
5322
|
break;
|
|
5259
5323
|
case 'goto':
|
|
5260
|
-
case 'navigate':
|
|
5261
5324
|
await cmdGoto(args[1]);
|
|
5262
5325
|
break;
|
|
5263
|
-
case 'open':
|
|
5264
|
-
await cmdOpen(args[1]);
|
|
5265
|
-
break;
|
|
5266
5326
|
case 'eval':
|
|
5267
|
-
case 'js':
|
|
5268
5327
|
await cmdEvalV2(args.slice(1));
|
|
5269
5328
|
break;
|
|
5270
5329
|
case 'click':
|
|
@@ -5290,11 +5349,7 @@ async function main() {
|
|
|
5290
5349
|
await cmdBlurVerb(args.slice(1));
|
|
5291
5350
|
break;
|
|
5292
5351
|
case 'scroll':
|
|
5293
|
-
|
|
5294
|
-
case 'scroll-by':
|
|
5295
|
-
case 'scroll-until':
|
|
5296
|
-
if (cmd === 'scroll') await cmdScroll(args.slice(1));
|
|
5297
|
-
else await cmdScroll([cmd.replace('scroll-',''), ...args.slice(1)]);
|
|
5352
|
+
await cmdScroll(args.slice(1));
|
|
5298
5353
|
break;
|
|
5299
5354
|
case 'wait':
|
|
5300
5355
|
await cmdWait(args.slice(1));
|
|
@@ -5382,8 +5437,6 @@ async function main() {
|
|
|
5382
5437
|
await cmdFrozen(args.slice(1));
|
|
5383
5438
|
break;
|
|
5384
5439
|
case 'thaw':
|
|
5385
|
-
case 'unfreeze':
|
|
5386
|
-
case 'wake':
|
|
5387
5440
|
await cmdThaw(args.slice(1));
|
|
5388
5441
|
break;
|
|
5389
5442
|
case 'freeze':
|
|
@@ -5409,13 +5462,10 @@ async function main() {
|
|
|
5409
5462
|
// Use registry pattern - bulletproof method
|
|
5410
5463
|
await cmdRegistry('favicon', args.slice(1));
|
|
5411
5464
|
break;
|
|
5412
|
-
case 'registry':
|
|
5413
5465
|
case 'reg':
|
|
5414
|
-
// Run a registry pattern
|
|
5415
5466
|
await cmdRegistry(args[1], args.slice(2));
|
|
5416
5467
|
break;
|
|
5417
5468
|
case 'loop':
|
|
5418
|
-
case 'ralph': // alias for loop - Ralph Wiggum pattern
|
|
5419
5469
|
// Parse loop options
|
|
5420
5470
|
const loopOpts = {
|
|
5421
5471
|
maxIterations: 10,
|
|
@@ -5464,29 +5514,7 @@ async function main() {
|
|
|
5464
5514
|
}
|
|
5465
5515
|
break;
|
|
5466
5516
|
}
|
|
5467
|
-
|
|
5468
|
-
// v0.3.15: typo suggest (Levenshtein <=2) before dumping full help.
|
|
5469
|
-
const KNOWN_CMDS = ['status','start','stop','restart','reload','reload-ext','attach-all','install','uninstall',
|
|
5470
|
-
'update','version','connect','browser','use','test','doctor','heal','domains','resolve','goto','eval','click','type',
|
|
5471
|
-
'screenshot','snapshot','text','html','title','url','tabs','targets','use-session','fetch','spawn',
|
|
5472
|
-
'extract','explore','favicon','window','reg','run','loop','ralph',
|
|
5473
|
-
'read','hover','focus','blur','scroll','wait','key','right-click','double-click','click-at','drag','select',
|
|
5474
|
-
'frames','frame-eval','upload','har','emulate','storage','history','dialog','console','pdf','mock','a11y','cookies'];
|
|
5475
|
-
function lev(a, b) {
|
|
5476
|
-
if (Math.abs(a.length - b.length) > 2) return 3;
|
|
5477
|
-
const m = Array.from({length: a.length+1}, () => new Array(b.length+1).fill(0));
|
|
5478
|
-
for (let i = 0; i <= a.length; i++) m[i][0] = i;
|
|
5479
|
-
for (let j = 0; j <= b.length; j++) m[0][j] = j;
|
|
5480
|
-
for (let i = 1; i <= a.length; i++) for (let j = 1; j <= b.length; j++) {
|
|
5481
|
-
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]);
|
|
5482
|
-
}
|
|
5483
|
-
return m[a.length][b.length];
|
|
5484
|
-
}
|
|
5485
|
-
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);
|
|
5486
|
-
if (near.length > 0) {
|
|
5487
|
-
log.info(` Did you mean: ${near.map(x => x[0]).join(', ')} ?`);
|
|
5488
|
-
}
|
|
5489
|
-
showHelp();
|
|
5517
|
+
console.error(`Unknown command: ${cmd}`);
|
|
5490
5518
|
process.exit(1);
|
|
5491
5519
|
}
|
|
5492
5520
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"registry": {
|
|
3
|
+
"chrome": {
|
|
4
|
+
"name": "Google Chrome",
|
|
5
|
+
"path": "/Applications/Google Chrome.app",
|
|
6
|
+
"processName": "Google Chrome"
|
|
7
|
+
},
|
|
8
|
+
"edge": {
|
|
9
|
+
"name": "Microsoft Edge",
|
|
10
|
+
"path": "/Applications/Microsoft Edge.app",
|
|
11
|
+
"processName": "Microsoft Edge"
|
|
12
|
+
},
|
|
13
|
+
"brave": {
|
|
14
|
+
"name": "Brave Browser",
|
|
15
|
+
"path": "/Applications/Brave Browser.app",
|
|
16
|
+
"processName": "Brave Browser"
|
|
17
|
+
},
|
|
18
|
+
"opera": {
|
|
19
|
+
"name": "Opera",
|
|
20
|
+
"path": "/Applications/Opera.app",
|
|
21
|
+
"processName": "Opera"
|
|
22
|
+
},
|
|
23
|
+
"vivaldi": {
|
|
24
|
+
"name": "Vivaldi",
|
|
25
|
+
"path": "/Applications/Vivaldi.app",
|
|
26
|
+
"processName": "Vivaldi"
|
|
27
|
+
},
|
|
28
|
+
"helium": {
|
|
29
|
+
"name": "Helium",
|
|
30
|
+
"path": "/Applications/Helium.app",
|
|
31
|
+
"processName": "Helium"
|
|
32
|
+
},
|
|
33
|
+
"arc": {
|
|
34
|
+
"name": "Arc",
|
|
35
|
+
"path": "/Applications/Arc.app",
|
|
36
|
+
"processName": "Arc"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"meta": {
|
|
3
3
|
"schema_version": "2.0",
|
|
4
4
|
"description": "Domain index: host → warch dir under registry base",
|
|
5
|
-
"registry_base": "
|
|
5
|
+
"registry_base": "$GLIDER (~/.glider)",
|
|
6
6
|
"warch_layout": "<registry_base>/warch/<host>/"
|
|
7
7
|
},
|
|
8
8
|
"example_com": {
|