glidercli 0.3.9 → 0.3.10
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 +34 -11
- package/docs/setup.json +2 -0
- package/lib/domain-resolve.js +72 -0
- package/package.json +1 -1
package/bin/glider.js
CHANGED
|
@@ -57,6 +57,7 @@ if (fs.existsSync(REGISTRY_FILE)) {
|
|
|
57
57
|
|
|
58
58
|
// Direct CDP module
|
|
59
59
|
const { DirectCDP, checkChrome } = require(path.join(LIB_DIR, 'cdp-direct.js'));
|
|
60
|
+
const { resolveDomain } = require(path.join(LIB_DIR, 'domain-resolve.js'));
|
|
60
61
|
|
|
61
62
|
// Domain extensions - load from ~/.glider/config/domains.json
|
|
62
63
|
const DOMAIN_CONFIG_PATHS = [
|
|
@@ -1069,7 +1070,7 @@ async function cmdWindow(args) {
|
|
|
1069
1070
|
}
|
|
1070
1071
|
|
|
1071
1072
|
async function cmdDomains() {
|
|
1072
|
-
const domainKeys = Object.keys(DOMAINS);
|
|
1073
|
+
const domainKeys = Object.keys(DOMAINS).filter((k) => k !== 'meta');
|
|
1073
1074
|
if (domainKeys.length === 0) {
|
|
1074
1075
|
log.warn('No domains configured');
|
|
1075
1076
|
log.info('Add domains to ~/.glider/config/domains.json');
|
|
@@ -1078,12 +1079,28 @@ async function cmdDomains() {
|
|
|
1078
1079
|
console.log(`${GREEN}${domainKeys.length}${NC} domain(s) configured:\n`);
|
|
1079
1080
|
for (const key of domainKeys) {
|
|
1080
1081
|
const d = DOMAINS[key];
|
|
1081
|
-
const
|
|
1082
|
-
const
|
|
1082
|
+
const shortcut = d.shortcut || {};
|
|
1083
|
+
const type = shortcut.type || (d.script ? 'script' : d.url ? 'url' : 'none');
|
|
1084
|
+
const target = shortcut.target || d.script || d.url || '';
|
|
1083
1085
|
console.log(` ${CYAN}${key}${NC} ${DIM}(${type})${NC}`);
|
|
1086
|
+
if (d.host) console.log(` ${DIM}host: ${d.host}${NC}`);
|
|
1087
|
+
if (d.warch) console.log(` ${DIM}warch: ${d.warch}${NC}`);
|
|
1084
1088
|
if (d.description) console.log(` ${d.description}`);
|
|
1085
|
-
console.log(` ${DIM}${target}${NC}`);
|
|
1089
|
+
if (target) console.log(` ${DIM}${target}${NC}`);
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
async function cmdResolve(input, opts = []) {
|
|
1094
|
+
if (!input) {
|
|
1095
|
+
log.fail('Usage: glider resolve <url|host> [--json]');
|
|
1096
|
+
process.exit(1);
|
|
1097
|
+
}
|
|
1098
|
+
const result = resolveDomain(input);
|
|
1099
|
+
if (opts.includes('--json') || jsonOutput) {
|
|
1100
|
+
console.log(JSON.stringify({ ok: true, ...result }));
|
|
1101
|
+
return;
|
|
1086
1102
|
}
|
|
1103
|
+
console.log(JSON.stringify(result, null, 2));
|
|
1087
1104
|
}
|
|
1088
1105
|
|
|
1089
1106
|
async function cmdOpen(url) {
|
|
@@ -1955,6 +1972,8 @@ ${B5}STATUS${NC}
|
|
|
1955
1972
|
${BW}browser${NC} Show browser config ${DIM}(name, path, processName, or use key)${NC}
|
|
1956
1973
|
${BW}use${NC} <key> Set browser by registry key ${DIM}(e.g. arc, brave, chrome)${NC}
|
|
1957
1974
|
${BW}test${NC} Run diagnostics
|
|
1975
|
+
${BW}domains${NC} List ~/.glider domain shortcuts + warch paths
|
|
1976
|
+
${BW}resolve${NC} <url> Resolve host to local warch intel ${DIM}(--json)${NC}
|
|
1958
1977
|
|
|
1959
1978
|
${B5}NAVIGATION${NC}
|
|
1960
1979
|
${BW}goto${NC} <url> Navigate to URL
|
|
@@ -2144,7 +2163,7 @@ async function main() {
|
|
|
2144
2163
|
}
|
|
2145
2164
|
|
|
2146
2165
|
// Ensure server is running for most commands
|
|
2147
|
-
if (!['start', 'stop', 'help', '--help', '-h', 'update', 'version', '-v', '--version'].includes(cmd)) {
|
|
2166
|
+
if (!['start', 'stop', 'help', '--help', '-h', 'update', 'version', '-v', '--version', 'domains', 'resolve'].includes(cmd)) {
|
|
2148
2167
|
if (!await checkServer()) {
|
|
2149
2168
|
log.info('Server not running, starting...');
|
|
2150
2169
|
await cmdStart();
|
|
@@ -2214,6 +2233,9 @@ async function main() {
|
|
|
2214
2233
|
case 'domains':
|
|
2215
2234
|
await cmdDomains();
|
|
2216
2235
|
break;
|
|
2236
|
+
case 'resolve':
|
|
2237
|
+
await cmdResolve(args[1], args.slice(2));
|
|
2238
|
+
break;
|
|
2217
2239
|
case 'goto':
|
|
2218
2240
|
case 'navigate':
|
|
2219
2241
|
await cmdGoto(args[1]);
|
|
@@ -2297,9 +2319,11 @@ async function main() {
|
|
|
2297
2319
|
// Check if it's a domain command from config
|
|
2298
2320
|
if (DOMAINS[cmd]) {
|
|
2299
2321
|
const domain = DOMAINS[cmd];
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2322
|
+
const shortcut = domain.shortcut || {};
|
|
2323
|
+
const scriptPathRaw = shortcut.type === 'script' ? shortcut.target : domain.script;
|
|
2324
|
+
const urlRaw = shortcut.type === 'url' ? shortcut.target : domain.url;
|
|
2325
|
+
if (scriptPathRaw) {
|
|
2326
|
+
const scriptPath = scriptPathRaw.replace(/^~/, os.homedir()).replace(/\$HOME/g, os.homedir());
|
|
2303
2327
|
if (fs.existsSync(scriptPath)) {
|
|
2304
2328
|
const { execSync } = require('child_process');
|
|
2305
2329
|
try {
|
|
@@ -2311,9 +2335,8 @@ async function main() {
|
|
|
2311
2335
|
log.fail(`Domain script not found: ${scriptPath}`);
|
|
2312
2336
|
process.exit(1);
|
|
2313
2337
|
}
|
|
2314
|
-
} else if (
|
|
2315
|
-
|
|
2316
|
-
await cmdGoto(domain.url);
|
|
2338
|
+
} else if (urlRaw) {
|
|
2339
|
+
await cmdGoto(urlRaw);
|
|
2317
2340
|
}
|
|
2318
2341
|
break;
|
|
2319
2342
|
}
|
package/docs/setup.json
CHANGED
|
@@ -33,6 +33,8 @@
|
|
|
33
33
|
},
|
|
34
34
|
"config_paths": {
|
|
35
35
|
"domains": "~/.glider/config/domains.json",
|
|
36
|
+
"domains_template": "$CURREGISTRY/glider/domains.template.json",
|
|
37
|
+
"resolve": "glider resolve <url> --json",
|
|
36
38
|
"browser": "~/.glider/config/browser.json",
|
|
37
39
|
"daemon_log": "~/.glider/daemon.log"
|
|
38
40
|
},
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const { URL } = require('url');
|
|
7
|
+
|
|
8
|
+
const DOMAIN_CONFIG_PATHS = [
|
|
9
|
+
path.join(os.homedir(), '.glider', 'config', 'domains.json'),
|
|
10
|
+
path.join(os.homedir(), '.glider', 'domains.json'),
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
function warchRoot() {
|
|
14
|
+
const base = process.env.CURREGISTRY || path.join(os.homedir(), '.cursor', 'registry');
|
|
15
|
+
return path.join(base, 'warch');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function loadDomainsIndex() {
|
|
19
|
+
for (const cfgPath of DOMAIN_CONFIG_PATHS) {
|
|
20
|
+
if (!fs.existsSync(cfgPath)) continue;
|
|
21
|
+
try {
|
|
22
|
+
return JSON.parse(fs.readFileSync(cfgPath, 'utf8'));
|
|
23
|
+
} catch (_) { /* ignore */ }
|
|
24
|
+
}
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function hostFromUrl(input) {
|
|
29
|
+
if (!input) return null;
|
|
30
|
+
try {
|
|
31
|
+
const u = input.includes('://') ? input : `https://${input}`;
|
|
32
|
+
return new URL(u).hostname || null;
|
|
33
|
+
} catch (_) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function resolveDomain(input) {
|
|
39
|
+
const host = hostFromUrl(input);
|
|
40
|
+
const root = warchRoot();
|
|
41
|
+
const warchPath = host ? path.join(root, host) : null;
|
|
42
|
+
const domains = loadDomainsIndex();
|
|
43
|
+
let indexHit = null;
|
|
44
|
+
for (const [key, val] of Object.entries(domains)) {
|
|
45
|
+
if (key === 'meta' || !val || typeof val !== 'object') continue;
|
|
46
|
+
if (val.host === host || key === host) {
|
|
47
|
+
indexHit = key;
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const gliderJsonPath = warchPath && path.join(warchPath, 'glider.json');
|
|
52
|
+
const gotchasPath = warchPath && path.join(warchPath, 'gotchas.json');
|
|
53
|
+
const gliderJsonExists = !!(gliderJsonPath && fs.existsSync(gliderJsonPath));
|
|
54
|
+
const gotchasExists = !!(gotchasPath && fs.existsSync(gotchasPath));
|
|
55
|
+
let gliderJson = null;
|
|
56
|
+
if (gliderJsonExists) {
|
|
57
|
+
try {
|
|
58
|
+
gliderJson = JSON.parse(fs.readFileSync(gliderJsonPath, 'utf8'));
|
|
59
|
+
} catch (_) { /* ignore */ }
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
host,
|
|
63
|
+
warch_path: warchPath,
|
|
64
|
+
glider_json_exists: gliderJsonExists,
|
|
65
|
+
gotchas_exists: gotchasExists,
|
|
66
|
+
domains_index_hit: indexHit,
|
|
67
|
+
capture_mode: gliderJson?.capture_mode ?? null,
|
|
68
|
+
wait_ms: gliderJson?.wait_ms ?? null,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
module.exports = { resolveDomain, hostFromUrl, warchRoot, loadDomainsIndex };
|
package/package.json
CHANGED