@claw-link/gateway-host 0.2.10 → 0.2.11

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 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.10",
3
+ "version": "0.2.11",
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": {
@@ -424,7 +424,76 @@ function status() {
424
424
  printAgents(cfg);
425
425
  }
426
426
 
427
+ // `version` — what the CLI is vs what the background service actually runs (these can
428
+ // differ: `npm i -g` updates the CLI; `npx ...@latest` / `clhost update` updates the service).
429
+ function versionCmd() {
430
+ console.log(`@claw-link/gateway-host (clhost) v${VERSION}`);
431
+ console.log(` CLI runs from: ${pkgRoot()}`);
432
+ let svcV = '(service not installed)';
433
+ try { const p = path.join(appDir(), 'package.json'); if (fs.existsSync(p)) svcV = 'v' + require(p).version; } catch { /* */ }
434
+ console.log(` Service runs: ${svcV} ${serviceRunning() ? '● running' : '○ stopped'} (${appDir()})`);
435
+ if (svcV !== '(service not installed)' && svcV !== 'v' + VERSION) {
436
+ console.log(` ⚠ Service is on ${svcV} but this CLI is v${VERSION} — run \`clhost update\` to sync the service.`);
437
+ }
438
+ }
439
+
440
+ // `doctor` — one-shot health check covering every failure we’ve actually hit:
441
+ // config present, service up, each agent’s runtime binary installed, and the bridge
442
+ // reachable + token/machine-binding valid (via a live heartbeat).
443
+ async function doctor() {
444
+ const mark = (b) => (b ? '✓' : '✗');
445
+ console.log('\n ClawLink Host Gateway — doctor\n ──────────────────────────────');
446
+ const cfg = config.load();
447
+ console.log(` ${mark(!!cfg)} config ${cfg ? config.CONFIG_PATH : 'missing — run: clhost setup'}`);
448
+ if (!cfg) return;
449
+ versionCmd();
450
+ console.log(` ${mark(serviceRunning())} service ${serviceRunning() ? 'running' : 'stopped — run: clhost start'}`);
451
+
452
+ const { which, RUNTIME_BINARIES } = require('../src/detect');
453
+ const { Bridge } = require('../src/bridge');
454
+ const agents = cfg.agents || [];
455
+ if (!agents.length) console.log(' ✗ agents none mapped — run: clhost add-agent');
456
+ for (const a of agents) {
457
+ const id = String(a.agent_id || a.host_token || '????').slice(0, 8);
458
+ const bins = RUNTIME_BINARIES[a.runtime] || [];
459
+ const usesLocalGateway = a.runtime === 'openclaw' || !!a.local_gateway_url;
460
+ const binOk = usesLocalGateway || bins.length === 0 || bins.some((b) => which(b));
461
+ let beat = false, msg = '';
462
+ try {
463
+ const r = await new Bridge(cfg.bridge_url, a, cfg.instance_id).heartbeat();
464
+ beat = !!(r && r.ok !== false && !r.error);
465
+ if (!beat) msg = (r && r.error) ? String(r.error) : 'rejected';
466
+ } catch (e) { msg = e && e.message ? e.message : String(e); }
467
+ console.log(` ${mark(binOk && beat)} agent ${id} runtime=${a.runtime}`
468
+ + (binOk ? '' : ` ✗ binary not found (${bins.join('/')})`)
469
+ + (beat ? ' · bridge+token+binding OK' : ` ✗ bridge: ${msg}`));
470
+ }
471
+ console.log('\n Next: `clhost transport-test` (verify the content-addressed relay)\n');
472
+ }
473
+
474
+ // `logs` — tail the background service log.
475
+ function logs() {
476
+ const logPath = path.join(config.HOME_DIR, 'host.log');
477
+ if (!fs.existsSync(logPath)) { console.log(` No log yet at ${logPath} (start the service first).`); return; }
478
+ const n = Number(process.argv[3]) || 60;
479
+ const lines = fs.readFileSync(logPath, 'utf8').split('\n');
480
+ console.log(lines.slice(-n).join('\n'));
481
+ console.log(`\n ── last ${n} lines of ${logPath} ──`);
482
+ }
483
+
484
+ // `update` — refresh the background service to the version of THIS CLI (syncs the stable
485
+ // app dir + restarts). To update the CLI itself: npm i -g @claw-link/gateway-host@latest.
486
+ function update() {
487
+ console.log(` Refreshing the background service to v${VERSION}…`);
488
+ const ok = installService();
489
+ console.log(ok
490
+ ? ` ✓ Service now runs v${VERSION} from ${appDir()}.`
491
+ : ' ⚠ Could not refresh automatically — run: clhost restart');
492
+ console.log(' (To upgrade the `clhost` CLI you type: npm i -g @claw-link/gateway-host@latest)\n');
493
+ }
494
+
427
495
  module.exports = {
428
496
  run, installOnly, addAgentCmd, removeAgentCmd, retokenCmd, listAgents, status,
429
497
  serviceControl, serviceControlCmd, installService, SERVICE_LABEL,
498
+ versionCmd, doctor, logs, update,
430
499
  };