arena-bridge 0.18.14 → 0.18.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,20 @@ 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.18.16
8
+
9
+ ### Fixed
10
+ - The macOS app no longer refreshes the full interface for every SSE heartbeat; background refreshes are coalesced, spaced out, and publish state only when it changes.
11
+ - Hub devices retry result delivery after transient network failures, and expired queued jobs are removed instead of executing later.
12
+ - Hub job queues are bounded and completed process sessions are pruned after retention.
13
+
14
+ ## 0.18.15
15
+
16
+ ### Fixed
17
+ - Restored the Node handlers for background processes and path deletion after the catalog split.
18
+ - `/health` reports the configured bridge log size again.
19
+ - Oversized HTTP request bodies return a normal `413 PAYLOAD_TOO_LARGE` response instead of resetting the connection.
20
+
7
21
  ## 0.18.14
8
22
 
9
23
  ### Fixed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arena-bridge",
3
- "version": "0.18.14",
3
+ "version": "0.18.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/catalog.mjs CHANGED
@@ -1,13 +1,21 @@
1
1
  import fsp from 'node:fs/promises';
2
+ import { spawn } from 'node:child_process';
2
3
  import os from 'node:os';
3
4
  import fs from 'node:fs';
4
5
  import path from 'node:path';
5
- import { checkPath, resolveTarget } from './policy.mjs';
6
+ import { checkPath, resolveTarget, isInside } from './policy.mjs';
6
7
  import { audit, saveArtifact, tailAudit, readArtifact, auditDir } from './audit.mjs';
7
8
  import { clip, runShell } from './engine_helpers.mjs';
8
9
  import { errorResponse } from './errors.mjs';
9
10
 
10
11
  let lastNoteAt = 0;
12
+ const SESSION_RETENTION_MS = 10 * 60 * 1000;
13
+
14
+ function pruneSessions(sessions, now = Date.now()) {
15
+ for (const [id, session] of sessions) {
16
+ if (session.exited && session.endedAt && now - session.endedAt > SESSION_RETENTION_MS) sessions.delete(id);
17
+ }
18
+ }
11
19
 
12
20
  const S = (o) => ({ type: 'object', properties: o, required: [], additionalProperties: false });
13
21
 
@@ -447,6 +455,7 @@ export function toolCatalog() {
447
455
  handler: async (args, ctx) => {
448
456
  const command = String(args.command ?? '');
449
457
  if (!command.trim()) return { ok: false, error: 'command is required' };
458
+ pruneSessions(ctx.sessions);
450
459
  const base = args.cwd ? resolveTarget(args.cwd, ctx.base) : ctx.base;
451
460
  const chk = checkPath(base, ctx.cfg, ctx.base);
452
461
  if (!chk.ok) return { ok: false, error: chk.error, reason: chk.reason };
@@ -488,6 +497,7 @@ export function toolCatalog() {
488
497
  child.on('close', (code) => {
489
498
  session.exited = true;
490
499
  session.exitCode = code;
500
+ session.endedAt = Date.now();
491
501
  });
492
502
  // R6: limit bash sessions to 20, cleanup oldest
493
503
  if (ctx.sessions.size >= 20) {
@@ -597,4 +607,3 @@ export function toolCatalog() {
597
607
  },
598
608
  ];
599
609
  }
600
-
package/src/device.mjs CHANGED
@@ -4,6 +4,35 @@
4
4
  */
5
5
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
6
6
 
7
+ /** Retry a result while the hub may still be waiting for it. A 404 means the job expired. */
8
+ export async function postResult(base, headers, payload, {
9
+ fetchImpl = fetch,
10
+ sleepImpl = sleep,
11
+ log = () => {},
12
+ maxAttempts = 8,
13
+ } = {}) {
14
+ let delay = 1000;
15
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
16
+ try {
17
+ const res = await fetchImpl(`${base}/device/result`, {
18
+ method: 'POST',
19
+ headers,
20
+ body: JSON.stringify(payload),
21
+ });
22
+ if (res.ok) return true;
23
+ if (res.status === 404) return false;
24
+ log(`[device] result failed: HTTP ${res.status} (attempt ${attempt}/${maxAttempts})`);
25
+ } catch (e) {
26
+ log(`[device] result connection error (attempt ${attempt}/${maxAttempts}): ${e.message}`);
27
+ }
28
+ if (attempt < maxAttempts) {
29
+ await sleepImpl(delay);
30
+ delay = Math.min(delay * 2, 30_000);
31
+ }
32
+ }
33
+ return false;
34
+ }
35
+
7
36
  export async function runDevice(cfg, engine, { log = console.log } = {}) {
8
37
  const base = String(cfg.hub || '').replace(/\/+$/, '');
9
38
  if (!base) throw new Error('cfg.hub is required in hub mode');
@@ -48,11 +77,7 @@ export async function runDevice(cfg, engine, { log = console.log } = {}) {
48
77
  result = { ok: false, error: e.message };
49
78
  }
50
79
 
51
- await fetch(`${base}/device/result`, {
52
- method: 'POST',
53
- headers,
54
- body: JSON.stringify({ id: job.id, result }),
55
- });
80
+ await postResult(base, headers, { id: job.id, result }, { log });
56
81
  } catch (e) {
57
82
  log(`[device] connection error: ${e.message}`);
58
83
  await sleep(backoff);
package/src/direct.mjs CHANGED
@@ -7,7 +7,7 @@ import { handleMcp } from './mcp.mjs';
7
7
  import { buildPrompt } from './prompt.mjs';
8
8
  import { listApprovals, decide, settle } from './approvals.mjs';
9
9
  import { checkPath } from './policy.mjs';
10
- import { loadConfig } from './config.mjs';
10
+ import { loadConfig, CONFIG_DIR } from './config.mjs';
11
11
  import { tailAudit, readArtifact, auditDir, audit, auditPage, findEntry, lean, headCursor, LEVELS, pruneAudit, pruneArtifacts } from './audit.mjs';
12
12
  import { reconcileTrust } from './trust.mjs';
13
13
  import { describeSource, sourceOf, admitUnauthorized } from './source.mjs';
@@ -384,4 +384,4 @@ export function createDirectServer(cfg, engine, runtime = null) {
384
384
  server.on('close', () => { poller?.stop(); clearInterval(maint); clearInterval(sweep); });
385
385
 
386
386
  return server;
387
- }
387
+ }
package/src/http.mjs CHANGED
@@ -39,17 +39,23 @@ export function readBody(req, limit = 16 * 1024 * 1024) {
39
39
  return new Promise((resolve, reject) => {
40
40
  const chunks = [];
41
41
  let len = 0;
42
+ let rejected = false;
42
43
  req.on('data', (c) => {
44
+ if (rejected) return;
43
45
  len += c.length;
44
46
  if (len > limit) {
47
+ rejected = true;
45
48
  reject(new Error('request body too large'));
46
- req.destroy();
47
49
  return;
48
50
  }
49
51
  chunks.push(c);
50
52
  });
51
- req.on('end', () => resolve(Buffer.concat(chunks)));
52
- req.on('error', reject);
53
+ req.on('end', () => {
54
+ if (!rejected) resolve(Buffer.concat(chunks));
55
+ });
56
+ req.on('error', (error) => {
57
+ if (!rejected) reject(error);
58
+ });
53
59
  });
54
60
  }
55
61
 
package/src/hub.mjs CHANGED
@@ -13,6 +13,7 @@ import { audit } from './audit.mjs';
13
13
  import { sourceOf, describeSource, admitUnauthorized } from './source.mjs';
14
14
 
15
15
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
16
+ const MAX_QUEUED_PER_DEVICE = 100;
16
17
 
17
18
  function deviceTokens(cfg) {
18
19
  const list = [];
@@ -34,10 +35,23 @@ export function createHubServer(cfg) {
34
35
  const queues = new Map(); // name -> [{id, tool, args}]
35
36
  const jobs = new Map(); // id -> { resolve, timer }
36
37
 
37
- const dispatch = (device, tool, args, timeoutSec = 120, source = null) =>
38
- new Promise((resolve) => {
38
+ const removeQueued = (device, id) => {
39
+ const q = queues.get(device);
40
+ if (!q) return;
41
+ const remaining = q.filter((job) => job.id !== id);
42
+ if (remaining.length) queues.set(device, remaining);
43
+ else queues.delete(device);
44
+ };
45
+
46
+ const dispatch = (device, tool, args, timeoutSec = 120, source = null) => {
47
+ const q = queues.get(device) || [];
48
+ if (q.length >= MAX_QUEUED_PER_DEVICE) {
49
+ return Promise.resolve({ ok: false, error: 'DEVICE_BUSY', reason: `device "${device}" has too many queued jobs` });
50
+ }
51
+ return new Promise((resolve) => {
39
52
  const id = crypto.randomUUID();
40
53
  const timer = setTimeout(() => {
54
+ removeQueued(device, id);
41
55
  jobs.delete(id);
42
56
  resolve({
43
57
  ok: false,
@@ -46,10 +60,10 @@ export function createHubServer(cfg) {
46
60
  });
47
61
  }, (timeoutSec + 15) * 1000);
48
62
  jobs.set(id, { resolve, timer });
49
- const q = queues.get(device) || [];
50
63
  q.push({ id, tool, args, source });
51
64
  queues.set(device, q);
52
65
  });
66
+ };
53
67
 
54
68
  const callTool = async (tool, args, source = null) => {
55
69
  const device = args?.device || cfg.device;
@@ -259,4 +273,4 @@ export function createHubServer(cfg) {
259
273
  return server;
260
274
  }
261
275
 
262
- export { sleep };
276
+ export { sleep };
package/src/version.mjs CHANGED
@@ -3,7 +3,7 @@ import fs from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import { fileURLToPath } from 'node:url';
5
5
 
6
- export const VERSION = "0.18.14";
6
+ export const VERSION = "0.18.16";
7
7
 
8
8
  export function getVersion() {
9
9
  try {