arena-bridge 0.18.8 → 0.18.10
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 +11 -0
- package/package.json +1 -1
- package/src/audit.mjs +6 -2
- package/src/device.mjs +1 -1
- package/src/direct.mjs +21 -13
- package/src/engine.mjs +5 -3
- package/src/gate.mjs +2 -2
- package/src/http.mjs +10 -5
- package/src/hub.mjs +5 -1
- package/src/lifecycle.mjs +2 -2
- package/src/version.mjs +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,17 @@ 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.10
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
- The work log now records only actions attributed to an agent or the user; automatic lifecycle, polling, and system events are omitted.
|
|
11
|
+
- Native-app permission status refreshes use a private local status endpoint and no longer create a tool-call log entry. A deliberate “Check again” remains recorded as a user action.
|
|
12
|
+
|
|
13
|
+
## 0.18.9
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
- Starting the LaunchAgent no longer force-kills the process that `bootstrap` just started via `RunAtLoad`; this avoids launchd's 10-second restart throttle during the Start flow.
|
|
17
|
+
|
|
7
18
|
## 0.18.8
|
|
8
19
|
|
|
9
20
|
### Fixed
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arena-bridge",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.10",
|
|
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/audit.mjs
CHANGED
|
@@ -104,8 +104,12 @@ function argsFor(id, args) {
|
|
|
104
104
|
|
|
105
105
|
export function audit(entry = {}) {
|
|
106
106
|
try {
|
|
107
|
+
// Keep only actions initiated by a human or an agent. Background housekeeping,
|
|
108
|
+
// launchd lifecycle events, and unauthenticated/system probes are not user work.
|
|
109
|
+
const actor = entry.actor || 'system';
|
|
110
|
+
if (actor !== 'agent' && actor !== 'user') return;
|
|
107
111
|
fs.mkdirSync(configDir(), { recursive: true, mode: 0o700 });
|
|
108
|
-
const { id, args, ...fields } = entry;
|
|
112
|
+
const { id, args, ...fields } = { ...entry, actor };
|
|
109
113
|
const recId = String(id || newEntryId(fields.tool));
|
|
110
114
|
const params = argsFor(recId, args);
|
|
111
115
|
const body = clipFields(scrub({ kind: 'call', ...fields }));
|
|
@@ -114,7 +118,7 @@ export function audit(entry = {}) {
|
|
|
114
118
|
ts: new Date().toISOString(),
|
|
115
119
|
...body,
|
|
116
120
|
level: levelFor({ kind: body.kind, status: body.status, level: body.level }),
|
|
117
|
-
actor: body.actor || '
|
|
121
|
+
actor: body.actor || 'system',
|
|
118
122
|
source: body.source ?? null,
|
|
119
123
|
args: params.args,
|
|
120
124
|
args_truncated: params.truncated,
|
package/src/device.mjs
CHANGED
|
@@ -43,7 +43,7 @@ export async function runDevice(cfg, engine, { log = console.log } = {}) {
|
|
|
43
43
|
|
|
44
44
|
let result;
|
|
45
45
|
try {
|
|
46
|
-
result = await engine.call(job.tool, job.args || {}, { source: job.source || { channel: 'hub', ip: null, country: null, host: null, client: null } });
|
|
46
|
+
result = await engine.call(job.tool, job.args || {}, { source: job.source || { channel: 'hub', ip: null, country: null, host: null, client: null }, actor: job.source?.actor || 'agent' });
|
|
47
47
|
} catch (e) {
|
|
48
48
|
result = { ok: false, error: e.message };
|
|
49
49
|
}
|
package/src/direct.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import http from 'node:http';
|
|
|
2
2
|
import { VERSION } from './version.mjs';
|
|
3
3
|
import fsp from 'node:fs/promises';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
-
import { sendJson, sendText, sendRaw, readJson, readBody, isAuthorized, bearer, safeEqual } from './http.mjs';
|
|
5
|
+
import { sendJson, sendText, sendRaw, readJson, readBody, isAuthorized, bearer, safeEqual, actorFor } from './http.mjs';
|
|
6
6
|
import { handleMcp } from './mcp.mjs';
|
|
7
7
|
import { buildPrompt } from './prompt.mjs';
|
|
8
8
|
import { listApprovals, decide, settle } from './approvals.mjs';
|
|
@@ -13,6 +13,7 @@ import { reconcileTrust } from './trust.mjs';
|
|
|
13
13
|
import { describeSource, sourceOf, admitUnauthorized } from './source.mjs';
|
|
14
14
|
import { errorResponse } from './errors.mjs';
|
|
15
15
|
import { startPoller, parseCommand, sendTelegram, answerCallback, editMessageText } from './telegram.mjs';
|
|
16
|
+
import { permissionStatus } from './mac.mjs';
|
|
16
17
|
|
|
17
18
|
export function createDirectServer(cfg, engine) {
|
|
18
19
|
const mcpCtx = {
|
|
@@ -109,11 +110,18 @@ export function createDirectServer(cfg, engine) {
|
|
|
109
110
|
res.setHeader('www-authenticate', 'Bearer');
|
|
110
111
|
return sendJson(res, 401, { ok: false, error: 'unauthorized' });
|
|
111
112
|
}
|
|
113
|
+
const actor = actorFor(req, cfgNow);
|
|
112
114
|
|
|
113
115
|
if (req.method === 'GET' && p === '/tools') {
|
|
114
116
|
return sendJson(res, 200, { ok: true, tools: engine.mcpTools() });
|
|
115
117
|
}
|
|
116
118
|
|
|
119
|
+
// Owner-app background polling only: do not create an audit entry for housekeeping.
|
|
120
|
+
if (req.method === 'GET' && p === '/permissions') {
|
|
121
|
+
if (actor !== 'user') return sendJson(res, 403, { ok: false, error: 'local user token required' });
|
|
122
|
+
return sendJson(res, 200, await permissionStatus(cfgNow));
|
|
123
|
+
}
|
|
124
|
+
|
|
117
125
|
if (req.method === 'GET' && p === '/prompt') {
|
|
118
126
|
const text = buildPrompt(cfgNow, { tool: engine, baseUrl: url.searchParams.get('base') || undefined });
|
|
119
127
|
return sendText(res, 200, text);
|
|
@@ -178,7 +186,7 @@ export function createDirectServer(cfg, engine) {
|
|
|
178
186
|
&& typeof body.message === 'string' && body.message.length <= 500
|
|
179
187
|
&& LEVELS.includes(level) && /^[\w.-]{1,40}$/.test(tool);
|
|
180
188
|
if (!ok) return sendJson(res, 400, { ok: false, error: 'invalid event' });
|
|
181
|
-
audit({ kind: 'step', tool, status: body.status, level, message: body.message, via: 'gui', actor
|
|
189
|
+
audit({ kind: 'step', tool, status: body.status, level, message: body.message, via: 'gui', actor, source: describeSource(req, 'http') });
|
|
182
190
|
return sendJson(res, 200, { ok: true });
|
|
183
191
|
}
|
|
184
192
|
|
|
@@ -217,7 +225,7 @@ export function createDirectServer(cfg, engine) {
|
|
|
217
225
|
const expected = loadConfig().localToken;
|
|
218
226
|
const presented = bearer(req);
|
|
219
227
|
if (!expected || !presented || !safeEqual(presented, expected)) {
|
|
220
|
-
audit({ kind: 'approval', tool: null, status: 'forbidden', error: 'FORBIDDEN', via: 'api', actor
|
|
228
|
+
audit({ kind: 'approval', tool: null, status: 'forbidden', error: 'FORBIDDEN', via: 'api', actor, source: await sourceOf(req, 'http'), args: { approval_id: approveMatch[1] } });
|
|
221
229
|
return sendJson(res, 403, {
|
|
222
230
|
ok: false,
|
|
223
231
|
error: 'forbidden',
|
|
@@ -238,7 +246,7 @@ export function createDirectServer(cfg, engine) {
|
|
|
238
246
|
cwd: body.cwd,
|
|
239
247
|
timeout_sec: body.timeout_sec,
|
|
240
248
|
env: body.env,
|
|
241
|
-
}, { source });
|
|
249
|
+
}, { source, actor });
|
|
242
250
|
const status = result.ok ? 200 : (result.error === 'APPROVAL_PENDING' ? 202 : 400);
|
|
243
251
|
return sendJson(res, status, result);
|
|
244
252
|
}
|
|
@@ -247,10 +255,10 @@ export function createDirectServer(cfg, engine) {
|
|
|
247
255
|
const body = await readJson(req, cfgNow.maxUploadBytes);
|
|
248
256
|
const source = await sourceOf(req, 'http');
|
|
249
257
|
if (!body.tool) {
|
|
250
|
-
audit({ kind: 'call', tool: null, status: 'rejected', error: 'INVALID_ARGS', via: 'direct', source, args: {} });
|
|
258
|
+
audit({ kind: 'call', tool: null, status: 'rejected', error: 'INVALID_ARGS', via: 'direct', actor, source, args: {} });
|
|
251
259
|
return sendJson(res, 400, { ok: false, error: 'tool is required' });
|
|
252
260
|
}
|
|
253
|
-
const result = await engine.call(String(body.tool), body.args || {}, { source });
|
|
261
|
+
const result = await engine.call(String(body.tool), body.args || {}, { source, actor });
|
|
254
262
|
// R5: return 202 for pending approvals, so client can poll GET /approvals/:id
|
|
255
263
|
const status = result.ok ? 200 : (result.error === 'APPROVAL_PENDING' ? 202 : 400);
|
|
256
264
|
return sendJson(res, status, result);
|
|
@@ -263,13 +271,13 @@ export function createDirectServer(cfg, engine) {
|
|
|
263
271
|
if (!target) return sendJson(res, 400, { ok: false, error: 'path query parameter is required' });
|
|
264
272
|
const chk = checkPath(target, cfgNow, engine.base, { write: req.method !== 'GET' });
|
|
265
273
|
if (!chk.ok) {
|
|
266
|
-
audit({ tool: toolName, args: { path: target }, status: 'error', error: chk.error, via: 'files_api', source });
|
|
274
|
+
audit({ tool: toolName, args: { path: target }, status: 'error', error: chk.error, via: 'files_api', actor, source });
|
|
267
275
|
return sendJson(res, 403, { ok: false, error: chk.error, reason: chk.reason });
|
|
268
276
|
}
|
|
269
277
|
// PUT/DELETE must go through the approval gate and audit, like the tools
|
|
270
278
|
if (req.method !== 'GET') {
|
|
271
279
|
const { authorize } = await import('./gate.mjs');
|
|
272
|
-
const resAuth = await authorize(toolName, { path: target }, cfgNow, source);
|
|
280
|
+
const resAuth = await authorize(toolName, { path: target }, cfgNow, source, actor);
|
|
273
281
|
if (!resAuth.ok) {
|
|
274
282
|
const status = resAuth.status || 'denied';
|
|
275
283
|
const pending = resAuth.pending;
|
|
@@ -284,23 +292,23 @@ export function createDirectServer(cfg, engine) {
|
|
|
284
292
|
try {
|
|
285
293
|
if (req.method === 'GET') {
|
|
286
294
|
const buf = await fsp.readFile(chk.abs);
|
|
287
|
-
audit({ tool: 'file_get', args: { path: target }, status: 'ok', via: 'files_api', source, bytes: buf.length });
|
|
295
|
+
audit({ tool: 'file_get', args: { path: target }, status: 'ok', via: 'files_api', actor, source, bytes: buf.length });
|
|
288
296
|
return sendRaw(res, 200, buf);
|
|
289
297
|
}
|
|
290
298
|
if (req.method === 'PUT' || req.method === 'POST') {
|
|
291
299
|
const buf = await readBody(req, cfgNow.maxUploadBytes);
|
|
292
300
|
await fsp.mkdir(path.dirname(chk.abs), { recursive: true });
|
|
293
301
|
await fsp.writeFile(chk.abs, buf);
|
|
294
|
-
audit({ tool: 'file_put', args: { path: target }, status: 'ok', via: 'files_api', source, bytes: buf.length });
|
|
302
|
+
audit({ tool: 'file_put', args: { path: target }, status: 'ok', via: 'files_api', actor, source, bytes: buf.length });
|
|
295
303
|
return sendJson(res, 200, { ok: true, path: chk.abs, bytes: buf.length });
|
|
296
304
|
}
|
|
297
305
|
if (req.method === 'DELETE') {
|
|
298
306
|
await fsp.rm(chk.abs, { recursive: true, force: true });
|
|
299
|
-
audit({ tool: 'delete_path', args: { path: target }, status: 'ok', via: 'files_api', source });
|
|
307
|
+
audit({ tool: 'delete_path', args: { path: target }, status: 'ok', via: 'files_api', actor, source });
|
|
300
308
|
return sendJson(res, 200, { ok: true, path: chk.abs, deleted: true });
|
|
301
309
|
}
|
|
302
310
|
} catch (e) {
|
|
303
|
-
audit({ tool: toolName, args: { path: target }, status: 'error', error: e.message, via: 'files_api', source });
|
|
311
|
+
audit({ tool: toolName, args: { path: target }, status: 'error', error: e.message, via: 'files_api', actor, source });
|
|
304
312
|
return sendJson(res, 400, { ok: false, error: e.message });
|
|
305
313
|
}
|
|
306
314
|
return sendJson(res, 405, { ok: false, error: 'method not allowed' });
|
|
@@ -351,7 +359,7 @@ export function createDirectServer(cfg, engine) {
|
|
|
351
359
|
return sendJson(res, 405, { ok: false, error: 'method not allowed', hint: 'use POST /mcp' });
|
|
352
360
|
}
|
|
353
361
|
const source = await sourceOf(req, 'mcp');
|
|
354
|
-
return handleMcp(req, res, { ...mcpCtx, callTool: (name, args) => engine.call(name, args, { source }) });
|
|
362
|
+
return handleMcp(req, res, { ...mcpCtx, callTool: (name, args) => engine.call(name, args, { source, actor }) });
|
|
355
363
|
}
|
|
356
364
|
|
|
357
365
|
return sendJson(res, 404, { ok: false, error: `no route for ${req.method} ${p}` });
|
package/src/engine.mjs
CHANGED
|
@@ -43,7 +43,7 @@ export class Engine {
|
|
|
43
43
|
return [...toolCatalog(), ...this.browser.tools(), ...macTools(this.cfg), ...telegramTools(this.cfg)];
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
async call(name, args = {}, { requireApproval, cfg, source } = {}) {
|
|
46
|
+
async call(name, args = {}, { requireApproval, cfg, source, actor } = {}) {
|
|
47
47
|
let cfgNow;
|
|
48
48
|
if (cfg) {
|
|
49
49
|
cfgNow = cfg;
|
|
@@ -56,9 +56,11 @@ export class Engine {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
this.cfg = cfgNow;
|
|
59
|
-
const src = source
|
|
59
|
+
const src = source ? { ...source } : { channel: 'local', ip: null, country: null, host: null, client: null };
|
|
60
|
+
const initiator = actor || src.actor || 'agent';
|
|
61
|
+
delete src.actor;
|
|
60
62
|
const record = (fields) => {
|
|
61
|
-
if (this.cfg.audit !== false) audit({ tool: name, args, source: src, kind: name === 'log_note' ? 'note' : 'call', ...fields });
|
|
63
|
+
if (this.cfg.audit !== false) audit({ tool: name, args, source: src, actor: initiator, kind: name === 'log_note' ? 'note' : 'call', ...fields });
|
|
62
64
|
};
|
|
63
65
|
const tool = this.catalog().find((t) => t.name === name);
|
|
64
66
|
if (!tool) {
|
package/src/gate.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { trustState, trustAllows } from './trust.mjs';
|
|
|
2
2
|
import { requestApproval } from './approvals.mjs';
|
|
3
3
|
import { audit } from './audit.mjs';
|
|
4
4
|
|
|
5
|
-
export async function authorize(tool, args, cfg, source = null) {
|
|
5
|
+
export async function authorize(tool, args, cfg, source = null, actor = 'agent') {
|
|
6
6
|
const trust = trustState();
|
|
7
7
|
let needApproval = true;
|
|
8
8
|
if (trustAllows(trust, tool, args, cfg)) needApproval = false;
|
|
@@ -12,7 +12,7 @@ export async function authorize(tool, args, cfg, source = null) {
|
|
|
12
12
|
if (!approval.approved) {
|
|
13
13
|
const status = approval.rec?.status || "denied";
|
|
14
14
|
const pending = status === "pending" || status === "timeout" || status === "expired";
|
|
15
|
-
try { audit({ tool, args, status: "approval_denied", approval_status: status, via: "approval", source, error: pending ? "APPROVAL_PENDING" : "APPROVAL_DENIED" }); } catch {}
|
|
15
|
+
try { audit({ tool, args, status: "approval_denied", approval_status: status, via: "approval", actor, source, error: pending ? "APPROVAL_PENDING" : "APPROVAL_DENIED" }); } catch {}
|
|
16
16
|
return { ok: false, status, approval_id: approval.rec?.id || null, pending };
|
|
17
17
|
}
|
|
18
18
|
return { ok: true };
|
package/src/http.mjs
CHANGED
|
@@ -70,10 +70,15 @@ export function bearer(req) {
|
|
|
70
70
|
return m ? m[1].trim() : null;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
export function
|
|
73
|
+
export function actorFor(req, cfg) {
|
|
74
74
|
const token = bearer(req);
|
|
75
|
-
if (!token) return
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
if (!token) return null;
|
|
76
|
+
// The local token is held by the owner-facing app; the agent token is shared with the agent.
|
|
77
|
+
if (cfg.localToken && safeEqual(token, cfg.localToken)) return 'user';
|
|
78
|
+
if (cfg.token && safeEqual(token, cfg.token)) return 'agent';
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function isAuthorized(req, cfg) {
|
|
83
|
+
return actorFor(req, cfg) !== null;
|
|
79
84
|
}
|
package/src/hub.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import http from 'node:http';
|
|
2
2
|
import { VERSION } from './version.mjs';
|
|
3
3
|
import crypto from 'node:crypto';
|
|
4
|
-
import { sendJson, sendText, readJson, readBody, isAuthorized, bearer, safeEqual } from './http.mjs';
|
|
4
|
+
import { sendJson, sendText, readJson, readBody, isAuthorized, bearer, safeEqual, actorFor } from './http.mjs';
|
|
5
5
|
import { handleMcp } from './mcp.mjs';
|
|
6
6
|
import { buildPrompt } from './prompt.mjs';
|
|
7
7
|
import { toolCatalog } from './engine.mjs';
|
|
@@ -141,6 +141,7 @@ export function createHubServer(cfg) {
|
|
|
141
141
|
res.setHeader('www-authenticate', 'Bearer');
|
|
142
142
|
return sendJson(res, 401, { ok: false, error: 'unauthorized' });
|
|
143
143
|
}
|
|
144
|
+
const actor = actorFor(req, loadConfig());
|
|
144
145
|
|
|
145
146
|
if (req.method === 'GET' && p === '/devices') {
|
|
146
147
|
const list = [...devices.entries()].map(([name, d]) => ({
|
|
@@ -188,6 +189,7 @@ export function createHubServer(cfg) {
|
|
|
188
189
|
if (req.method === 'POST' && p === '/exec') {
|
|
189
190
|
const body = await readJson(req, cfg.maxUploadBytes);
|
|
190
191
|
const source = await sourceOf(req, 'http');
|
|
192
|
+
source.actor = actor;
|
|
191
193
|
const result = await callTool('bash', {
|
|
192
194
|
device: body.device,
|
|
193
195
|
command: body.command,
|
|
@@ -202,6 +204,7 @@ export function createHubServer(cfg) {
|
|
|
202
204
|
const body = await readJson(req, cfg.maxUploadBytes);
|
|
203
205
|
if (!body.tool) return sendJson(res, 400, { ok: false, error: 'tool is required' });
|
|
204
206
|
const source = await sourceOf(req, 'http');
|
|
207
|
+
source.actor = actor;
|
|
205
208
|
const result = await callTool(String(body.tool), body.args || {}, source);
|
|
206
209
|
return sendJson(res, result.ok ? 200 : 400, result);
|
|
207
210
|
}
|
|
@@ -235,6 +238,7 @@ export function createHubServer(cfg) {
|
|
|
235
238
|
|
|
236
239
|
if (req.method === 'POST' && p === '/mcp') {
|
|
237
240
|
const source = await sourceOf(req, 'mcp');
|
|
241
|
+
source.actor = actor;
|
|
238
242
|
return handleMcp(req, res, { ...mcpCtx, callTool: (name, args) => callTool(name, args, source) });
|
|
239
243
|
}
|
|
240
244
|
|
package/src/lifecycle.mjs
CHANGED
|
@@ -5,9 +5,9 @@ import { VERSION } from './version.mjs';
|
|
|
5
5
|
const origin = () => (process.env.XPC_SERVICE_NAME ? 'launchd' : 'cli');
|
|
6
6
|
|
|
7
7
|
export function bridgeEvent(status, { port, reason } = {}) {
|
|
8
|
-
audit({ kind: 'service', tool: 'bridge', status, via: origin(), source: { channel: 'local' }, pid: process.pid, version: VERSION, port, reason });
|
|
8
|
+
audit({ kind: 'service', tool: 'bridge', status, via: origin(), actor: 'system', source: { channel: 'local' }, pid: process.pid, version: VERSION, port, reason });
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export function tunnelEvent(status, extra = {}) {
|
|
12
|
-
audit({ kind: 'tunnel', tool: 'tunnel', status, via: origin(), ...extra });
|
|
12
|
+
audit({ kind: 'tunnel', tool: 'tunnel', status, via: origin(), actor: 'system', ...extra });
|
|
13
13
|
}
|