arena-bridge 0.7.15 → 0.7.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/CHANGELOG.md CHANGED
@@ -4,6 +4,12 @@ All notable changes to this project are documented here.
4
4
  The format follows [Keep a Changelog](https://keepachangelog.com/) and the project uses
5
5
  [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## 0.7.16
8
+
9
+ ### Fixed
10
+ - The tunnel takes the reserved domain back when an old ngrok process still holds it: only the
11
+ ngrok that serves our domain is stopped, the other tunnels of the user are untouched.
12
+
7
13
  ## 0.7.15
8
14
 
9
15
  ### Fixed
package/README.md CHANGED
@@ -12,7 +12,7 @@
12
12
  <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="license">
13
13
  <img src="https://img.shields.io/badge/node-%3E%3D18-green.svg?style=flat-square" alt="node">
14
14
  <img src="https://img.shields.io/badge/dependencies-0-brightgreen.svg?style=flat-square" alt="dependencies">
15
- <img src="https://img.shields.io/badge/tests-161%20passed-brightgreen.svg?style=flat-square" alt="tests">
15
+ <img src="https://img.shields.io/badge/tests-163%20passed-brightgreen.svg?style=flat-square" alt="tests">
16
16
  </p>
17
17
 
18
18
  <p align="center">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arena-bridge",
3
- "version": "0.7.15",
3
+ "version": "0.7.16",
4
4
  "description": "Give a cloud AI agent (Arena.ai Agent Mode, Claude, Cursor, ...) controlled access to your own machine over HTTP/MCP: files, shell, Chrome and the macOS desktop, with an approval gate, trust windows and an audit log.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/direct.mjs CHANGED
@@ -73,7 +73,7 @@ export function createDirectServer(cfg, engine) {
73
73
  ok: true,
74
74
  mode: 'direct',
75
75
  device: cfg.device,
76
- version: '0.7.15',
76
+ version: '0.7.16',
77
77
  uptime_sec: Math.round(process.uptime()),
78
78
  });
79
79
  }
package/src/hub.mjs CHANGED
@@ -90,7 +90,7 @@ export function createHubServer(cfg) {
90
90
  return sendJson(res, 200, {
91
91
  ok: true,
92
92
  mode: 'hub',
93
- version: '0.7.15',
93
+ version: '0.7.16',
94
94
  devices: [...devices.keys()],
95
95
  });
96
96
  }
package/src/mcp.mjs CHANGED
@@ -48,7 +48,7 @@ export async function handleMcp(req, res, ctx) {
48
48
  mcpResponse(id, {
49
49
  protocolVersion: PROTOCOL_VERSION,
50
50
  capabilities: { tools: { listChanged: false } },
51
- serverInfo: { name: 'arena-bridge', version: '0.7.15' },
51
+ serverInfo: { name: 'arena-bridge', version: '0.7.16' },
52
52
  instructions:
53
53
  'Tools operate the user\'s own machine. Dangerous operations may return ' +
54
54
  'PROTECTED and require a local human approval.',
package/src/tunnel.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { spawn } from 'node:child_process';
1
+ import { spawn, execFileSync } from 'node:child_process';
2
2
  import net from 'node:net';
3
3
 
4
4
  const URL_RE = /https:\/\/[a-z0-9-]+\.trycloudflare\.com/i;
@@ -9,6 +9,40 @@ const NGROK_URL_RE = /https:\/\/[a-z0-9-]+\.ngrok(?:-free)?\.(?:app|io|dev)/i;
9
9
  * cloudflared: QUIC (UDP/7844) is blocked on many networks, so we default to http2 over TCP/443.
10
10
  * ngrok: an authtoken and an optional reserved domain give the same URL on every restart.
11
11
  */
12
+ /**
13
+ * An old ngrok process keeps the reserved domain, and the new one cannot take it. Only the
14
+ * processes that serve our domain are stopped, never the other tunnels of the user.
15
+ */
16
+ export function killStaleNgrok(domain) {
17
+ if (!domain) return [];
18
+ const killed = [];
19
+ let pids = [];
20
+ try {
21
+ pids = execFileSync('pgrep', ['-x', 'ngrok'], { encoding: 'utf8' })
22
+ .split('\n')
23
+ .map((s) => s.trim())
24
+ .filter(Boolean);
25
+ } catch {
26
+ return killed;
27
+ }
28
+ for (const pid of pids) {
29
+ let args = '';
30
+ try {
31
+ args = execFileSync('ps', ['-o', 'args=', '-p', pid], { encoding: 'utf8' });
32
+ } catch {
33
+ continue;
34
+ }
35
+ if (!args.includes(domain)) continue;
36
+ try {
37
+ process.kill(Number(pid), 'SIGTERM');
38
+ killed.push(Number(pid));
39
+ } catch {
40
+ /* already gone */
41
+ }
42
+ }
43
+ return killed;
44
+ }
45
+
12
46
  export function startTunnel(
13
47
  cfg,
14
48
  { port, protocol = 'http2', bin = 'cloudflared', authtoken, domain, restarts = 20, delay = 2000 } = {},
@@ -64,6 +98,11 @@ export function startTunnel(
64
98
  });
65
99
  child.on('exit', (code) => {
66
100
  if (!settled) {
101
+ if (isNgrok && attempt++ < restarts) {
102
+ killStaleNgrok(domain);
103
+ setTimeout(spawnChild, delay);
104
+ return;
105
+ }
67
106
  settled = true;
68
107
  rejectUrl(new Error(`${bin} exited with code ${code} before the tunnel URL appeared`));
69
108
  return;