arena-bridge 0.8.12 → 0.9.0

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.
@@ -0,0 +1,55 @@
1
+ import { spawn } from 'node:child_process';
2
+
3
+ export function clip(buf, cap) {
4
+ if (buf.length <= cap) return { data: buf, truncated: false };
5
+ return { data: buf.subarray(0, cap), truncated: true };
6
+ }
7
+
8
+ export function runShell(command, { cwd, timeout, env, cap }) {
9
+ return new Promise((resolve) => {
10
+ let child;
11
+ try {
12
+ child = spawn('/bin/sh', ['-lc', command], {
13
+ cwd,
14
+ env: { ...process.env, ...(env || {}) },
15
+ stdio: ['ignore', 'pipe', 'pipe'],
16
+ detached: true,
17
+ });
18
+ } catch (e) {
19
+ resolve({ stdout: '', stderr: String(e.message), exit_code: -1, error: e.message });
20
+ return;
21
+ }
22
+ const out = [];
23
+ const err = [];
24
+ let outLen = 0;
25
+ let errLen = 0;
26
+ let truncated = false;
27
+ let timedOut = false;
28
+ const timer = setTimeout(() => {
29
+ timedOut = true;
30
+ try { if (child.pid) process.kill(-child.pid, 'SIGKILL'); } catch { try { child.kill('SIGKILL'); } catch {} }
31
+ }, Math.max(1, timeout) * 1000);
32
+ child.stdout.on('data', (c) => {
33
+ if (outLen >= cap) { truncated = true; return; }
34
+ const room = cap - outLen;
35
+ const part = c.length > room ? c.subarray(0, room) : c;
36
+ out.push(part); outLen += part.length;
37
+ if (part.length < c.length) truncated = true;
38
+ });
39
+ child.stderr.on('data', (c) => {
40
+ if (errLen >= cap) { truncated = true; return; }
41
+ const room = cap - errLen;
42
+ const part = c.length > room ? c.subarray(0, room) : c;
43
+ err.push(part); errLen += part.length;
44
+ if (part.length < c.length) truncated = true;
45
+ });
46
+ child.on('error', (e) => {
47
+ clearTimeout(timer);
48
+ resolve({ stdout: Buffer.concat(out).toString('utf8'), stderr: Buffer.concat(err).toString('utf8') + String(e.message), exit_code: -1, error: e.message, truncated, timed_out: timedOut });
49
+ });
50
+ child.on('close', (code, signal) => {
51
+ clearTimeout(timer);
52
+ resolve({ stdout: Buffer.concat(out).toString('utf8'), stderr: Buffer.concat(err).toString('utf8'), exit_code: code === null ? -1 : code, signal: signal || null, truncated, timed_out: timedOut });
53
+ });
54
+ });
55
+ }
package/src/gate.mjs ADDED
@@ -0,0 +1,19 @@
1
+ import { trustState, trustAllows } from './trust.mjs';
2
+ import { requestApproval } from './approvals.mjs';
3
+ import { audit } from './audit.mjs';
4
+
5
+ export async function authorize(tool, args, cfg) {
6
+ const trust = trustState();
7
+ let needApproval = true;
8
+ if (trustAllows(trust, tool, args, cfg)) needApproval = false;
9
+ else if (cfg.requireApproval === false) needApproval = false;
10
+ if (!needApproval) return { ok: true };
11
+ const approval = await requestApproval(tool, args, cfg);
12
+ if (!approval.approved) {
13
+ const status = approval.rec?.status || "denied";
14
+ try { audit({ tool, args, status: "approval_denied", approval_status: status }); } catch {}
15
+ const pending = status === "pending" || status === "timeout" || status === "expired";
16
+ return { ok: false, status, approval_id: approval.rec?.id || null, pending };
17
+ }
18
+ return { ok: true };
19
+ }
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.8.12";
6
+ export const VERSION = "0.9.0";
7
7
 
8
8
  export function getVersion() {
9
9
  try {