@claw-link/gateway-host 0.2.2 → 0.2.4

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 CHANGED
@@ -61,6 +61,17 @@ Change the Claude model by editing `.claude/settings.json` (e.g. `"model": "opus
61
61
  For Codex/Cursor, set the model via their CLI (`args_template` in the config, or the
62
62
  tool's own settings).
63
63
 
64
+ **Permissions by scope** — each job carries a scope, and the Claude adapter runs with
65
+ matching permissions automatically:
66
+
67
+ | Trigger | Scope | Claude permissions |
68
+ |---------|-------|--------------------|
69
+ | Admin **Setup via Chat** / apply skill | `configure` | `--permission-mode acceptEdits` — may write workspace files (GUARDRAILS/SOUL/BOOTSTRAP/TOOLS/AGENTS) |
70
+ | Customer chat + discovery | `customer` | `--disallowedTools "Write Edit MultiEdit NotebookEdit Bash"` — **read-only**, cannot edit config or run shell |
71
+
72
+ So an agent's files are editable from the admin panel but never from customer/discovery
73
+ chat. (Operator `args_template` overrides this for advanced setups.)
74
+
64
75
  ## Commands
65
76
 
66
77
  After install the `clhost` command is available (aliases: `gateway-host`, `claw-host`):
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claw-link/gateway-host",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
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": {
@@ -16,4 +16,11 @@ module.exports = makeCliAdapter({
16
16
  '--verbose',
17
17
  ...(resumeId ? ['--resume', resumeId] : []),
18
18
  ],
19
+ // Admin "configure" turns may write workspace files (auto-accept edits, no shell
20
+ // prompt); customer/discovery turns are strictly read-only (no Write/Edit/Bash) so
21
+ // they can never modify the agent's config or hang on a permission prompt.
22
+ permissions: (scope) =>
23
+ (scope === 'configure' || scope === 'sub_configure')
24
+ ? ['--permission-mode', 'acceptEdits']
25
+ : ['--disallowedTools', 'Write Edit MultiEdit NotebookEdit Bash'],
19
26
  });
@@ -76,9 +76,14 @@ function makeCliAdapter(cfg) {
76
76
  // spawn never fails with ENOENT (coding workspaces are validated at setup).
77
77
  try { fs.mkdirSync(agent.work_dir, { recursive: true }); } catch { /* ignore */ }
78
78
 
79
+ // Scope-based permissions: admin "configure" turns may write workspace files
80
+ // (GUARDRAILS/SOUL/etc.); customer/discovery turns are read-only and cannot
81
+ // edit or run shell. Operator args_template overrides take full control.
82
+ const scope = job.scope || 'customer';
83
+ const permArgs = (!Array.isArray(agent.args_template) && cfg.permissions) ? cfg.permissions(scope) : [];
79
84
  const argvFor = (rid) => Array.isArray(agent.args_template)
80
85
  ? buildArgv(agent.args_template, { prompt: fullPrompt, sessionId: rid || '', systemPrompt })
81
- : cfg.defaultArgs(fullPrompt, rid, cfg.promptViaStdin);
86
+ : [...cfg.defaultArgs(fullPrompt, rid, cfg.promptViaStdin), ...permArgs];
82
87
 
83
88
  let emittedAny = false;
84
89
  const runOnce = async function* (rid) {
package/src/machine.js CHANGED
@@ -1,29 +1,58 @@
1
1
  'use strict';
2
- // Stable machine fingerprint for host binding. Derived from the host's physical
3
- // MAC address(es) + hostname, then hashed we send only the HASH to ClawLink, so
4
- // raw MACs never leave the machine. Supabase binds this on first connect; after
5
- // that, only this machine may act for the agent (a stolen token from elsewhere
6
- // fails the binding check).
2
+ // Stable machine fingerprint for host binding. We bind an agent's token to ONE
3
+ // machine so a stolen token can't be used elsewhere. The fingerprint MUST be
4
+ // stable across reboots and network changes earlier versions hashed MAC
5
+ // addresses, which rotate (Tailscale/Docker/VPN/private-WiFi) and caused false
6
+ // "host binding mismatch" errors. We now use the OS hardware machine id, with a
7
+ // persisted random id as a fallback, and send only the HASH.
7
8
 
8
9
  const os = require('os');
10
+ const fs = require('fs');
11
+ const path = require('path');
9
12
  const crypto = require('crypto');
13
+ const { execSync } = require('child_process');
14
+ const { enrichedEnv } = require('./paths');
10
15
 
11
- function macAddresses() {
12
- const macs = [];
13
- const ifaces = os.networkInterfaces();
14
- for (const name of Object.keys(ifaces)) {
15
- for (const ni of ifaces[name] || []) {
16
- if (ni.internal) continue;
17
- if (!ni.mac || ni.mac === '00:00:00:00:00:00') continue;
18
- macs.push(ni.mac.toLowerCase());
16
+ const HOME_DIR = path.join(os.homedir(), '.clawlink-host');
17
+
18
+ function execSafe(cmd) {
19
+ try { return execSync(cmd, { stdio: ['ignore', 'pipe', 'ignore'], timeout: 4000, env: enrichedEnv() }).toString(); }
20
+ catch { return ''; }
21
+ }
22
+
23
+ // Stable, hardware-tied id where available.
24
+ function hardwareId() {
25
+ try {
26
+ if (process.platform === 'darwin') {
27
+ const m = execSafe('ioreg -rd1 -c IOPlatformExpertDevice').match(/IOPlatformUUID"\s*=\s*"([^"]+)"/);
28
+ if (m) return 'hw:' + m[1];
29
+ } else if (process.platform === 'linux') {
30
+ for (const p of ['/etc/machine-id', '/var/lib/dbus/machine-id']) {
31
+ try { const id = fs.readFileSync(p, 'utf8').trim(); if (id) return 'hw:' + id; } catch { /* next */ }
32
+ }
33
+ } else if (process.platform === 'win32') {
34
+ const m = execSafe('reg query "HKLM\\SOFTWARE\\Microsoft\\Cryptography" /v MachineGuid').match(/MachineGuid\s+REG_SZ\s+([\w-]+)/i);
35
+ if (m) return 'hw:' + m[1];
19
36
  }
20
- }
21
- return [...new Set(macs)].sort();
37
+ } catch { /* fall through */ }
38
+ return null;
39
+ }
40
+
41
+ // Stable random id persisted under the home dir (fallback when no hardware id).
42
+ function persistedId() {
43
+ const idPath = path.join(HOME_DIR, 'machine-id');
44
+ try { const id = fs.readFileSync(idPath, 'utf8').trim(); if (id) return 'id:' + id; } catch { /* create below */ }
45
+ try {
46
+ fs.mkdirSync(HOME_DIR, { recursive: true });
47
+ const id = crypto.randomBytes(32).toString('hex');
48
+ fs.writeFileSync(idPath, id, { mode: 0o600 });
49
+ try { fs.chmodSync(idPath, 0o600); } catch { /* best effort */ }
50
+ return 'id:' + id;
51
+ } catch { return null; }
22
52
  }
23
53
 
24
54
  function machineId() {
25
- const macs = macAddresses();
26
- const basis = (macs.length ? macs.join(',') : 'no-mac') + '|' + os.hostname();
55
+ const basis = hardwareId() || persistedId() || ('host:' + os.hostname());
27
56
  return crypto.createHash('sha256').update(basis).digest('hex');
28
57
  }
29
58