@claw-link/gateway-host 0.2.10 → 0.2.12
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/cli.js +22 -0
- package/package.json +1 -1
- package/scripts/install.js +96 -1
package/bin/cli.js
CHANGED
|
@@ -48,6 +48,24 @@ async function main() {
|
|
|
48
48
|
case 'status':
|
|
49
49
|
return require('../scripts/install').status();
|
|
50
50
|
|
|
51
|
+
case 'version':
|
|
52
|
+
case '--version':
|
|
53
|
+
case '-v':
|
|
54
|
+
return require('../scripts/install').versionCmd();
|
|
55
|
+
|
|
56
|
+
case 'doctor':
|
|
57
|
+
case 'diagnose':
|
|
58
|
+
case 'check':
|
|
59
|
+
return require('../scripts/install').doctor();
|
|
60
|
+
|
|
61
|
+
case 'logs':
|
|
62
|
+
case 'log':
|
|
63
|
+
return require('../scripts/install').logs();
|
|
64
|
+
|
|
65
|
+
case 'update':
|
|
66
|
+
case 'upgrade':
|
|
67
|
+
return require('../scripts/install').update();
|
|
68
|
+
|
|
51
69
|
case 'transport-test':
|
|
52
70
|
case 'transport':
|
|
53
71
|
return require('../scripts/transport-test').run();
|
|
@@ -76,10 +94,14 @@ async function main() {
|
|
|
76
94
|
' retoken Re-enter a new Host Token for an existing agent (clhost retoken <id>)',
|
|
77
95
|
' agents List mapped agents',
|
|
78
96
|
' status Show bridge, service state, and mapped agents',
|
|
97
|
+
' doctor Diagnose config, runtime binaries, bridge + token/machine binding',
|
|
98
|
+
' version Show CLI version + the version the service is running',
|
|
99
|
+
' logs Tail the background service log (clhost logs [N])',
|
|
79
100
|
' transport-test Verify content-addressed Capsule relay (host ⇄ central sync + integrity)',
|
|
80
101
|
' start Start the background service',
|
|
81
102
|
' stop Stop the background service',
|
|
82
103
|
' restart Restart the background service (apply config changes)',
|
|
104
|
+
' update Refresh the background service to this CLI’s version',
|
|
83
105
|
' setup install + add-agent in one flow',
|
|
84
106
|
' rotate How to rotate a Host Token / move to a new machine',
|
|
85
107
|
' uninstall Stop + remove the background service',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@claw-link/gateway-host",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.12",
|
|
4
4
|
"description": "ClawLink Host Gateway — a secure, outbound-only worker that bridges a local agent CLI (OpenClaw, Hermes, Claude, Codex, Cursor) to your ClawLink agents. No inbound ports; authenticated per-agent by a Host Token.",
|
|
5
5
|
"homepage": "https://claw-link.co",
|
|
6
6
|
"bin": {
|
package/scripts/install.js
CHANGED
|
@@ -22,6 +22,29 @@ function ask(rl, q, def) {
|
|
|
22
22
|
}
|
|
23
23
|
function execSafe(cmd) { try { return execSync(cmd, { stdio: ['ignore', 'pipe', 'ignore'] }).toString(); } catch { return null; } }
|
|
24
24
|
|
|
25
|
+
// `npx` runs the package from a cache and NEVER puts the `clhost` bin on PATH — only a
|
|
26
|
+
// global install does. So during setup we make `clhost` available (best-effort, non-fatal):
|
|
27
|
+
// probe PATH, and if it's missing, do a quiet global install of the same version.
|
|
28
|
+
function clhostOnPath() {
|
|
29
|
+
const probe = process.platform === 'win32' ? 'where clhost' : 'command -v clhost';
|
|
30
|
+
return execSafe(probe) != null;
|
|
31
|
+
}
|
|
32
|
+
function ensureGlobalCli() {
|
|
33
|
+
if (clhostOnPath()) return true;
|
|
34
|
+
try { execSync(`npm install -g @claw-link/gateway-host@${VERSION}`, { stdio: 'ignore', timeout: 120000 }); }
|
|
35
|
+
catch { /* no permission / offline — reportCli() prints the manual fallback */ }
|
|
36
|
+
return clhostOnPath();
|
|
37
|
+
}
|
|
38
|
+
function reportCli() {
|
|
39
|
+
if (ensureGlobalCli()) {
|
|
40
|
+
console.log(' ✓ The `clhost` command is ready — try: clhost status');
|
|
41
|
+
} else {
|
|
42
|
+
console.log(' ℹ To get the short `clhost` command, install it once (you may need sudo):');
|
|
43
|
+
console.log(' npm i -g @claw-link/gateway-host');
|
|
44
|
+
console.log(' Until then, run commands as: npx @claw-link/gateway-host <command>');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
25
48
|
// The bridge URL is baked in (config.DEFAULT_BRIDGE_URL / CLAWLINK_BRIDGE_URL env)
|
|
26
49
|
// — operators never type it. We just ensure it's populated.
|
|
27
50
|
function ensureBridgeUrl(cfg) {
|
|
@@ -110,6 +133,7 @@ async function run() {
|
|
|
110
133
|
console.log(installed
|
|
111
134
|
? ' ✓ Service refreshed to the latest version.'
|
|
112
135
|
: ' ⚠ Could not refresh the service automatically — run: clhost restart');
|
|
136
|
+
reportCli();
|
|
113
137
|
console.log('\n Commands: clhost status · clhost agents · clhost add-agent · clhost transport-test\n');
|
|
114
138
|
return;
|
|
115
139
|
}
|
|
@@ -133,6 +157,7 @@ async function run() {
|
|
|
133
157
|
console.log(installed
|
|
134
158
|
? ' ✓ Installed + started the background service.'
|
|
135
159
|
: ' ⚠ Could not install a background service automatically.\n Run it yourself with: clhost run');
|
|
160
|
+
reportCli();
|
|
136
161
|
console.log('\n Check status in ClawLink → Agents → Host Gateway (connection badge).\n');
|
|
137
162
|
}
|
|
138
163
|
|
|
@@ -143,7 +168,8 @@ async function installOnly() {
|
|
|
143
168
|
config.save(cfg);
|
|
144
169
|
const installed = installService();
|
|
145
170
|
console.log(installed ? ' ✓ Service installed.' : ' ⚠ Could not install the service automatically.');
|
|
146
|
-
|
|
171
|
+
reportCli();
|
|
172
|
+
console.log(' Next: clhost add-agent (or npx @claw-link/gateway-host add-agent)\n');
|
|
147
173
|
}
|
|
148
174
|
|
|
149
175
|
// `add-agent` — add one agent by token, then restart the service to pick it up.
|
|
@@ -424,7 +450,76 @@ function status() {
|
|
|
424
450
|
printAgents(cfg);
|
|
425
451
|
}
|
|
426
452
|
|
|
453
|
+
// `version` — what the CLI is vs what the background service actually runs (these can
|
|
454
|
+
// differ: `npm i -g` updates the CLI; `npx ...@latest` / `clhost update` updates the service).
|
|
455
|
+
function versionCmd() {
|
|
456
|
+
console.log(`@claw-link/gateway-host (clhost) v${VERSION}`);
|
|
457
|
+
console.log(` CLI runs from: ${pkgRoot()}`);
|
|
458
|
+
let svcV = '(service not installed)';
|
|
459
|
+
try { const p = path.join(appDir(), 'package.json'); if (fs.existsSync(p)) svcV = 'v' + require(p).version; } catch { /* */ }
|
|
460
|
+
console.log(` Service runs: ${svcV} ${serviceRunning() ? '● running' : '○ stopped'} (${appDir()})`);
|
|
461
|
+
if (svcV !== '(service not installed)' && svcV !== 'v' + VERSION) {
|
|
462
|
+
console.log(` ⚠ Service is on ${svcV} but this CLI is v${VERSION} — run \`clhost update\` to sync the service.`);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// `doctor` — one-shot health check covering every failure we’ve actually hit:
|
|
467
|
+
// config present, service up, each agent’s runtime binary installed, and the bridge
|
|
468
|
+
// reachable + token/machine-binding valid (via a live heartbeat).
|
|
469
|
+
async function doctor() {
|
|
470
|
+
const mark = (b) => (b ? '✓' : '✗');
|
|
471
|
+
console.log('\n ClawLink Host Gateway — doctor\n ──────────────────────────────');
|
|
472
|
+
const cfg = config.load();
|
|
473
|
+
console.log(` ${mark(!!cfg)} config ${cfg ? config.CONFIG_PATH : 'missing — run: clhost setup'}`);
|
|
474
|
+
if (!cfg) return;
|
|
475
|
+
versionCmd();
|
|
476
|
+
console.log(` ${mark(serviceRunning())} service ${serviceRunning() ? 'running' : 'stopped — run: clhost start'}`);
|
|
477
|
+
|
|
478
|
+
const { which, RUNTIME_BINARIES } = require('../src/detect');
|
|
479
|
+
const { Bridge } = require('../src/bridge');
|
|
480
|
+
const agents = cfg.agents || [];
|
|
481
|
+
if (!agents.length) console.log(' ✗ agents none mapped — run: clhost add-agent');
|
|
482
|
+
for (const a of agents) {
|
|
483
|
+
const id = String(a.agent_id || a.host_token || '????').slice(0, 8);
|
|
484
|
+
const bins = RUNTIME_BINARIES[a.runtime] || [];
|
|
485
|
+
const usesLocalGateway = a.runtime === 'openclaw' || !!a.local_gateway_url;
|
|
486
|
+
const binOk = usesLocalGateway || bins.length === 0 || bins.some((b) => which(b));
|
|
487
|
+
let beat = false, msg = '';
|
|
488
|
+
try {
|
|
489
|
+
const r = await new Bridge(cfg.bridge_url, a, cfg.instance_id).heartbeat();
|
|
490
|
+
beat = !!(r && r.ok !== false && !r.error);
|
|
491
|
+
if (!beat) msg = (r && r.error) ? String(r.error) : 'rejected';
|
|
492
|
+
} catch (e) { msg = e && e.message ? e.message : String(e); }
|
|
493
|
+
console.log(` ${mark(binOk && beat)} agent ${id} runtime=${a.runtime}`
|
|
494
|
+
+ (binOk ? '' : ` ✗ binary not found (${bins.join('/')})`)
|
|
495
|
+
+ (beat ? ' · bridge+token+binding OK' : ` ✗ bridge: ${msg}`));
|
|
496
|
+
}
|
|
497
|
+
console.log('\n Next: `clhost transport-test` (verify the content-addressed relay)\n');
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// `logs` — tail the background service log.
|
|
501
|
+
function logs() {
|
|
502
|
+
const logPath = path.join(config.HOME_DIR, 'host.log');
|
|
503
|
+
if (!fs.existsSync(logPath)) { console.log(` No log yet at ${logPath} (start the service first).`); return; }
|
|
504
|
+
const n = Number(process.argv[3]) || 60;
|
|
505
|
+
const lines = fs.readFileSync(logPath, 'utf8').split('\n');
|
|
506
|
+
console.log(lines.slice(-n).join('\n'));
|
|
507
|
+
console.log(`\n ── last ${n} lines of ${logPath} ──`);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// `update` — refresh the background service to the version of THIS CLI (syncs the stable
|
|
511
|
+
// app dir + restarts). To update the CLI itself: npm i -g @claw-link/gateway-host@latest.
|
|
512
|
+
function update() {
|
|
513
|
+
console.log(` Refreshing the background service to v${VERSION}…`);
|
|
514
|
+
const ok = installService();
|
|
515
|
+
console.log(ok
|
|
516
|
+
? ` ✓ Service now runs v${VERSION} from ${appDir()}.`
|
|
517
|
+
: ' ⚠ Could not refresh automatically — run: clhost restart');
|
|
518
|
+
console.log(' (To upgrade the `clhost` CLI you type: npm i -g @claw-link/gateway-host@latest)\n');
|
|
519
|
+
}
|
|
520
|
+
|
|
427
521
|
module.exports = {
|
|
428
522
|
run, installOnly, addAgentCmd, removeAgentCmd, retokenCmd, listAgents, status,
|
|
429
523
|
serviceControl, serviceControlCmd, installService, SERVICE_LABEL,
|
|
524
|
+
versionCmd, doctor, logs, update,
|
|
430
525
|
};
|