arena-bridge 0.7.18 → 0.7.20

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.7.20
8
+
9
+ ### Fixed
10
+ - Direct HTTP routes and both execution engines now use one fresh configuration snapshot per request.
11
+ - Changes to roots, protected paths, approval policy and response limits apply consistently without restarting the bridge.
12
+
13
+ ## 0.7.19
14
+
15
+ ### Fixed
16
+ - Approval requests now become `timeout` or `expired` records on disk and cannot be accepted after they are no longer actionable.
17
+ - Stale pending requests expire when listed or decided; failed late approvals cannot open a trust window.
18
+ - Agent recovery hints explain that timed-out requests are closed and require a fresh call or trust window.
19
+ - An explicit Peekaboo path is authoritative rather than silently falling back to another installation.
20
+
7
21
  ## 0.7.18
8
22
 
9
23
  ### Fixed
package/README.md CHANGED
@@ -452,8 +452,10 @@ arena-bridge browser close work # закрыть окно этого пр
452
452
  * **Пути ограничены**: всё вне `roots` — `PROTECTED`. Защищённый список по умолчанию включает
453
453
  `~/.ssh`, `~/.aws`, `~/.arena-bridge`, `~/.npmrc`, профили браузеров, ключи.
454
454
  * **Подтверждения**: `bash`, запись, удаление, управление вашим Chrome и десктопом ждут
455
- `arena-bridge approve <id>`. Ответ `APPROVAL_PENDING` содержит `approval_id` — покажите его
456
- пользователю и повторите вызов один раз.
455
+ `arena-bridge approve <id>`. Подтверждать нужно, пока вызов ожидает решения.
456
+ После `timeout` или `expired` запрос закрыт и его `approval_id` больше не принимается.
457
+ Для продолжения откройте `arena-bridge trust --for 1h` и повторите вызов один раз либо
458
+ согласуйте новый вызов, который пользователь подтвердит во время ожидания.
457
459
  * **Журнал**: `~/.arena-bridge/audit.log` (JSONL) — кто, что и когда вызвал.
458
460
  * **Транспорт**: сервер слушает `127.0.0.1`, наружу — только туннель с HTTPS.
459
461
 
@@ -548,7 +550,7 @@ arena_bridge/ тот же функционал на Python (stdlib only)
548
550
  | `port 8787 is already in use` | остановите старый экземпляр (`Ctrl+C`) или `arena-bridge start --port 8788` |
549
551
  | туннель не поднимается | `cloudflared` по умолчанию использует QUIC и может быть заблокирован — `arena-bridge tunnel --protocol http2` (это поведение по умолчанию) |
550
552
  | агент не видит файлы | проверьте `arena-bridge doctor` и `roots` в `~/.arena-bridge/config.json`; вне `roots` всё равно `PROTECTED` |
551
- | `APPROVAL_PENDING` | покажите пользователю `arena-bridge approve <id>` или откройте `arena-bridge trust --for 1h` |
553
+ | `APPROVAL_PENDING` | при `timeout`/`expired` старый запрос закрыт: согласуйте новый вызов или попросите открыть `arena-bridge trust --for 1h` |
552
554
  | скриншоты не работают | `mac_permissions` — выдайте терминалу Screen Recording и Accessibility |
553
555
  | `peekaboo_not_found` | поставьте Peekaboo или укажите путь: `arena-bridge init` + `peekabooPath` в конфиге |
554
556
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arena-bridge",
3
- "version": "0.7.18",
3
+ "version": "0.7.20",
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": {
@@ -19,9 +19,9 @@
19
19
  "node": ">=18"
20
20
  },
21
21
  "scripts": {
22
- "test": "node test/smoke.mjs && node test/browser.test.mjs && node test/mac.test.mjs && node test/service.test.mjs",
23
- "test:node": "node test/smoke.mjs && node test/browser.test.mjs && node test/mac.test.mjs && node test/service.test.mjs",
24
- "test:python": "python3 test/test_bridge.py && python3 test/test_browser.py && python3 test/test_mac.py && python3 test/test_service.py",
22
+ "test": "node --test test/approvals.test.mjs && node test/smoke.mjs && node test/browser.test.mjs && node test/mac.test.mjs && node test/service.test.mjs",
23
+ "test:node": "node --test test/approvals.test.mjs && node test/smoke.mjs && node test/browser.test.mjs && node test/mac.test.mjs && node test/service.test.mjs",
24
+ "test:python": "python3 test/test_approvals.py && python3 test/test_bridge.py && python3 test/test_browser.py && python3 test/test_mac.py && python3 test/test_service.py",
25
25
  "pack:check": "npm pack --dry-run"
26
26
  },
27
27
  "repository": {
package/src/approvals.mjs CHANGED
@@ -11,6 +11,16 @@ function fileOf(id) {
11
11
  return path.join(APPROVALS_DIR, `${id}.json`);
12
12
  }
13
13
 
14
+ function expireIfNeeded(file, rec, now = Date.now()) {
15
+ if (rec.status === 'pending' && rec.expiresAt && now >= rec.expiresAt) {
16
+ rec.status = 'expired';
17
+ rec.decidedAt = now;
18
+ rec.decidedBy = 'system';
19
+ fs.writeFileSync(file, JSON.stringify(rec, null, 2), { mode: 0o600 });
20
+ }
21
+ return rec;
22
+ }
23
+
14
24
  export function listApprovals() {
15
25
  if (!fs.existsSync(APPROVALS_DIR)) return [];
16
26
  return fs
@@ -18,7 +28,8 @@ export function listApprovals() {
18
28
  .filter((f) => f.endsWith('.json'))
19
29
  .map((f) => {
20
30
  try {
21
- return JSON.parse(fs.readFileSync(path.join(APPROVALS_DIR, f), 'utf8'));
31
+ const file = path.join(APPROVALS_DIR, f);
32
+ return expireIfNeeded(file, JSON.parse(fs.readFileSync(file, 'utf8')));
22
33
  } catch {
23
34
  return null;
24
35
  }
@@ -36,6 +47,7 @@ export function decide(id, decision, by = 'cli') {
36
47
  } catch (e) {
37
48
  return { ok: false, error: e.message };
38
49
  }
50
+ rec = expireIfNeeded(file, rec);
39
51
  if (rec.status !== 'pending') return { ok: false, error: `already ${rec.status}` };
40
52
  rec.status = decision === 'approve' ? 'approved' : 'denied';
41
53
  rec.decidedAt = Date.now();
@@ -117,10 +129,17 @@ export async function requestApproval(tool, args, cfg) {
117
129
  continue;
118
130
  }
119
131
  if (cur.status === 'approved') return { approved: true, rec: cur };
120
- if (cur.status === 'denied') return { approved: false, rec: cur };
121
- if (cur.expiresAt && Date.now() > cur.expiresAt) {
122
- return { approved: false, rec: { ...cur, status: 'expired' } };
132
+ if (cur.status !== 'pending') return { approved: false, rec: cur };
133
+ if (cur.expiresAt && Date.now() >= cur.expiresAt) {
134
+ return { approved: false, rec: expireIfNeeded(fileOf(id), cur) };
123
135
  }
124
136
  }
125
- return { approved: false, rec: { ...rec, status: 'timeout' } };
137
+ const timedOut = expireIfNeeded(fileOf(id), JSON.parse(fs.readFileSync(fileOf(id), 'utf8')));
138
+ if (timedOut.status === 'pending') {
139
+ timedOut.status = 'timeout';
140
+ timedOut.decidedAt = Date.now();
141
+ timedOut.decidedBy = 'system';
142
+ fs.writeFileSync(fileOf(id), JSON.stringify(timedOut, null, 2), { mode: 0o600 });
143
+ }
144
+ return { approved: timedOut.status === 'approved', rec: timedOut };
126
145
  }
package/src/direct.mjs CHANGED
@@ -73,13 +73,15 @@ export function createDirectServer(cfg, engine) {
73
73
  ok: true,
74
74
  mode: 'direct',
75
75
  device: cfg.device,
76
- version: '0.7.18',
76
+ version: '0.7.20',
77
77
  uptime_sec: Math.round(process.uptime()),
78
78
  });
79
79
  }
80
80
 
81
- // re-read the config per request so a rotated token takes effect without a restart
82
- if (!isAuthorized(req, loadConfig())) {
81
+ // Re-read once per request so auth, policy, limits and the response agree.
82
+ const cfgNow = loadConfig();
83
+ mcpCtx.cfg = cfgNow;
84
+ if (!isAuthorized(req, cfgNow)) {
83
85
  res.setHeader('www-authenticate', 'Bearer');
84
86
  return sendJson(res, 401, { ok: false, error: 'unauthorized' });
85
87
  }
@@ -89,23 +91,23 @@ export function createDirectServer(cfg, engine) {
89
91
  }
90
92
 
91
93
  if (req.method === 'GET' && p === '/prompt') {
92
- const text = buildPrompt(cfg, { tool: engine, baseUrl: url.searchParams.get('base') || undefined });
94
+ const text = buildPrompt(cfgNow, { tool: engine, baseUrl: url.searchParams.get('base') || undefined });
93
95
  return sendText(res, 200, text);
94
96
  }
95
97
 
96
98
  if (req.method === 'GET' && p === '/config') {
97
99
  return sendJson(res, 200, {
98
100
  ok: true,
99
- device: cfg.device,
100
- roots: cfg.roots,
101
- protected_count: cfg.protected.length,
102
- requireApproval: cfg.requireApproval,
103
- allowShell: cfg.allowShell,
104
- approvalWaitSec: cfg.approvalWaitSec,
105
- maxOutputBytes: cfg.maxOutputBytes,
101
+ device: cfgNow.device,
102
+ roots: cfgNow.roots,
103
+ protected_count: cfgNow.protected.length,
104
+ requireApproval: cfgNow.requireApproval,
105
+ allowShell: cfgNow.allowShell,
106
+ approvalWaitSec: cfgNow.approvalWaitSec,
107
+ maxOutputBytes: cfgNow.maxOutputBytes,
106
108
  telegram: {
107
- enabled: !!cfg.telegram?.enabled,
108
- chat_ids: cfg.telegram?.chatIds || [],
109
+ enabled: !!cfgNow.telegram?.enabled,
110
+ chat_ids: cfgNow.telegram?.chatIds || [],
109
111
  },
110
112
  });
111
113
  }
@@ -156,7 +158,7 @@ export function createDirectServer(cfg, engine) {
156
158
  }
157
159
 
158
160
  if (req.method === 'POST' && p === '/exec') {
159
- const body = await readJson(req, cfg.maxUploadBytes);
161
+ const body = await readJson(req, cfgNow.maxUploadBytes);
160
162
  const result = await engine.call('bash', {
161
163
  command: body.command,
162
164
  cwd: body.cwd,
@@ -167,7 +169,7 @@ export function createDirectServer(cfg, engine) {
167
169
  }
168
170
 
169
171
  if (req.method === 'POST' && p === '/call') {
170
- const body = await readJson(req, cfg.maxUploadBytes);
172
+ const body = await readJson(req, cfgNow.maxUploadBytes);
171
173
  if (!body.tool) return sendJson(res, 400, { ok: false, error: 'tool is required' });
172
174
  const result = await engine.call(String(body.tool), body.args || {});
173
175
  return sendJson(res, result.ok ? 200 : 400, result);
@@ -176,7 +178,7 @@ export function createDirectServer(cfg, engine) {
176
178
  if (p === '/files') {
177
179
  const target = url.searchParams.get('path');
178
180
  if (!target) return sendJson(res, 400, { ok: false, error: 'path query parameter is required' });
179
- const chk = checkPath(target, cfg, engine.base, { write: req.method !== 'GET' });
181
+ const chk = checkPath(target, cfgNow, engine.base, { write: req.method !== 'GET' });
180
182
  if (!chk.ok) return sendJson(res, 403, { ok: false, error: chk.error, reason: chk.reason });
181
183
  try {
182
184
  if (req.method === 'GET') {
@@ -184,7 +186,7 @@ export function createDirectServer(cfg, engine) {
184
186
  return sendRaw(res, 200, buf);
185
187
  }
186
188
  if (req.method === 'PUT' || req.method === 'POST') {
187
- const buf = await readBody(req, cfg.maxUploadBytes);
189
+ const buf = await readBody(req, cfgNow.maxUploadBytes);
188
190
  await fsp.mkdir(chk.abs.replace(/\/[^/]*$/, ''), { recursive: true });
189
191
  await fsp.writeFile(chk.abs, buf);
190
192
  return sendJson(res, 200, { ok: true, path: chk.abs, bytes: buf.length });
package/src/engine.mjs CHANGED
@@ -635,6 +635,11 @@ export class Engine {
635
635
  }
636
636
 
637
637
  async call(name, args = {}, { requireApproval } = {}) {
638
+ try {
639
+ if (fs.existsSync(CONFIG_PATH)) this.cfg = loadConfig();
640
+ } catch {
641
+ /* keep the last valid snapshot */
642
+ }
638
643
  const tool = this.catalog().find((t) => t.name === name);
639
644
  if (!tool) return { ok: false, error: `unknown tool: ${name}` };
640
645
  const started = Date.now();
@@ -651,13 +656,6 @@ export class Engine {
651
656
  return saved;
652
657
  };
653
658
 
654
- // pick up policy changes (roots, protected, requireApproval) without a restart
655
- try {
656
- if (fs.existsSync(CONFIG_PATH)) this.cfg = loadConfig();
657
- } catch {
658
- /* keep the snapshot */
659
- }
660
-
661
659
  let needApproval = tool.approvalFor ? !!tool.approvalFor(args, this) : !!tool.approval;
662
660
  if (this.cfg.requireApproval === false) needApproval = false;
663
661
  if (requireApproval === true) needApproval = true;
@@ -685,11 +683,11 @@ export class Engine {
685
683
  status,
686
684
  pending,
687
685
  reason: pending
688
- ? `waiting for a local human decision on tool "${tool.name}"`
686
+ ? `approval wait ended (${status}) for tool "${tool.name}"; this request is closed`
689
687
  : `human ${status} tool "${tool.name}"`,
690
688
  approval_id: approval.rec?.id || null,
691
689
  hint: pending
692
- ? 'Tell the user to run: arena-bridge approve <approval_id> - or open a trust window for hands-free work: arena-bridge trust --for 1h. Then retry the call once.'
690
+ ? 'This approval_id is closed and cannot be approved. Ask the user to open a trust window: arena-bridge trust --for 1h. Then retry the call once, or arrange a fresh call for approval while it is waiting.'
693
691
  : 'The user declined this action. Do not retry it; ask what to do instead.',
694
692
  };
695
693
  }
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.18',
93
+ version: '0.7.20',
94
94
  devices: [...devices.keys()],
95
95
  });
96
96
  }
package/src/mac.mjs CHANGED
@@ -18,8 +18,9 @@ const NOT_FOUND_HINT =
18
18
  'peekaboo is not installed on this machine. Install it (macOS: brew install peekaboo, or download the release from https://github.com/openclaw/Peekaboo) and make sure the binary is on PATH.';
19
19
 
20
20
  export function findPeekaboo(cfg = {}) {
21
- const explicit = cfg.peekabooPath || process.env.PEEKABOO_PATH;
22
- if (explicit && fs.existsSync(explicit)) return explicit;
21
+ if (cfg.peekabooPath) return fs.existsSync(cfg.peekabooPath) ? cfg.peekabooPath : null;
22
+ const explicit = process.env.PEEKABOO_PATH;
23
+ if (explicit) return fs.existsSync(explicit) ? explicit : null;
23
24
  for (const c of PEEKABOO_CANDIDATES) if (fs.existsSync(c)) return c;
24
25
  for (const d of (process.env.PATH || '').split(path.delimiter)) {
25
26
  if (!d) continue;
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.18' },
51
+ serverInfo: { name: 'arena-bridge', version: '0.7.20' },
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/prompt.mjs CHANGED
@@ -116,9 +116,10 @@ Use it when a step takes long or when you need a decision: one message is enough
116
116
 
117
117
  ## Approvals
118
118
  ${trustLine}
119
- - When a call answers \`APPROVAL_PENDING\` it carries an \`approval_id\`: tell the user to run
120
- \`arena-bridge approve <approval_id>\` on their machine (or \`arena-bridge trust --for 1h\` to let you
121
- work hands-free until the window closes), then retry the call once. \`GET /approvals\` lists what is waiting.
119
+ - Approve requests while the call is waiting. A returned \`APPROVAL_PENDING\` with status
120
+ \`timeout\` or \`expired\` identifies a closed request: that \`approval_id\` cannot be approved.
121
+ Ask the user to open \`arena-bridge trust --for 1h\` before retrying once, or arrange a fresh
122
+ call that they can approve while it is waiting. \`GET /approvals\` includes historical records; only \`pending\` is actionable.
122
123
  - \`APPROVAL_DENIED\` means the user said no: do not retry, ask what to do instead.
123
124
 
124
125
  ## Rules
@@ -126,8 +127,8 @@ ${trustLine}
126
127
  Reading or writing anything else returns \`PROTECTED\` — do not try to work around it.
127
128
  2. Side-effecting tools (bash, write/edit/delete, process start/kill, actions on the user's own
128
129
  Chrome or on the desktop) may require a local human approval. When the answer contains
129
- \`APPROVAL_PENDING\`, tell the user which approval is pending and stop; they will run
130
- \`arena-bridge approve <approval_id>\` on their machine. Do not retry in a loop.
130
+ \`APPROVAL_PENDING\`, stop and follow the recovery hint; never ask to approve a closed id.
131
+ Do not retry in a loop.
131
132
  3. Work step by step: inspect before you change. Prefer \`read_file\`/\`list_dir\`/\`search_files\`
132
133
  over blind shell commands. \`list_dir\` returns the top level only unless you ask for \`recursive\`.
133
134
  4. Long-running work (dev servers, watchers) belongs in \`start_process\` + \`read_process_output\`,