@revoengine/cli 1.0.12 → 1.0.14

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.
Files changed (31) hide show
  1. package/README.md +16 -2
  2. package/dist/src/cli.js +4 -0
  3. package/dist/src/client.d.ts +5 -0
  4. package/dist/src/client.js +41 -42
  5. package/dist/src/commands/component.js +26 -25
  6. package/dist/src/commands/migrate.js +10 -0
  7. package/dist/src/commands/terminal-browser.d.ts +40 -6
  8. package/dist/src/commands/terminal-browser.js +480 -19
  9. package/dist/src/commands/terminal-image.js +59 -1
  10. package/dist/src/commands/terminal-operational-log.d.ts +18 -0
  11. package/dist/src/commands/terminal-operational-log.js +119 -0
  12. package/dist/src/commands/terminal-policy.d.ts +23 -0
  13. package/dist/src/commands/terminal-policy.js +48 -0
  14. package/dist/src/commands/terminal-pty.d.ts +4 -0
  15. package/dist/src/commands/terminal-pty.js +39 -0
  16. package/dist/src/commands/terminal-reconnect-grace.d.ts +11 -0
  17. package/dist/src/commands/terminal-reconnect-grace.js +29 -0
  18. package/dist/src/commands/terminal-sandbox.d.ts +5 -1
  19. package/dist/src/commands/terminal-sandbox.js +19 -5
  20. package/dist/src/commands/terminal-secure-browser.d.ts +25 -0
  21. package/dist/src/commands/terminal-secure-browser.js +58 -0
  22. package/dist/src/commands/terminal.d.ts +5 -2
  23. package/dist/src/commands/terminal.js +259 -44
  24. package/dist/src/migration.js +10 -10
  25. package/dist/src/request-queue.d.ts +20 -0
  26. package/dist/src/request-queue.js +80 -0
  27. package/dist/src/resource-inventory.js +9 -10
  28. package/dist/src/resource-syncs/endpoint-sync.js +12 -46
  29. package/dist/src/types.d.ts +2 -0
  30. package/package.json +4 -3
  31. package/scripts/ensure-pty-helper.mjs +9 -0
@@ -0,0 +1,119 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { randomUUID } from 'node:crypto';
4
+ import { gunzipSync, gzipSync } from 'node:zlib';
5
+ const ARCHIVE_RETENTION_MS = 30 * 24 * 60 * 60 * 1_000;
6
+ const SAFE_ATOM = /^[A-Za-z0-9_.:-]{1,120}$/u;
7
+ const DETAIL_KEYS = new Set(['operation', 'sandbox', 'reason', 'errorCode', 'browserAction',
8
+ 'exitCode', 'images', 'screenshot', 'executed', 'timedOut', 'truncated', 'activeExecutions',
9
+ 'resumedExecutions', 'bytes', 'close', 'code', 'policyViolation', 'milliseconds']);
10
+ function atom(value) {
11
+ return typeof value === 'string' && SAFE_ATOM.test(value) ? value : '-';
12
+ }
13
+ function dateOf(value) {
14
+ return value.toISOString().slice(0, 10);
15
+ }
16
+ export class TerminalOperationalLog {
17
+ prepared = false;
18
+ failed = false;
19
+ currentDate = '';
20
+ directory;
21
+ now;
22
+ constructor(directory, now = () => new Date()) {
23
+ this.directory = directory;
24
+ this.now = now;
25
+ }
26
+ write(severity, trace, event, details = {}) {
27
+ if (this.failed)
28
+ return;
29
+ try {
30
+ const time = this.now();
31
+ this.prepare(time);
32
+ const fields = Object.entries(details)
33
+ .filter(([key]) => DETAIL_KEYS.has(key))
34
+ .map(([key, value]) => `${key}=${typeof value === 'number' && Number.isFinite(value) ? value
35
+ : typeof value === 'boolean' ? value : atom(value)}`);
36
+ if (trace.executionId)
37
+ fields.unshift(`executionId=${atom(trace.executionId)}`);
38
+ const line = `[${time.toISOString()}][${severity}][${atom(trace.assistantThreadId)}]`
39
+ + `[${atom(trace.assistantMessageId)}] ${atom(event)}${fields.length ? ` ${fields.join(' ')}` : ''}\n`;
40
+ const file = path.join(this.directory, 'debug.log');
41
+ const descriptor = fs.openSync(file, fs.constants.O_WRONLY | fs.constants.O_APPEND
42
+ | fs.constants.O_CREAT | (fs.constants.O_NOFOLLOW || 0), 0o600);
43
+ try {
44
+ fs.fchmodSync(descriptor, 0o600);
45
+ fs.writeSync(descriptor, line);
46
+ }
47
+ finally {
48
+ fs.closeSync(descriptor);
49
+ }
50
+ }
51
+ catch {
52
+ // Operational diagnostics must never terminate a command or print sensitive data.
53
+ this.failed = true;
54
+ process.stderr.write('Revo terminal operational log unavailable.\n');
55
+ }
56
+ }
57
+ prepare(time) {
58
+ const currentDate = dateOf(time);
59
+ if (this.prepared && this.currentDate === currentDate)
60
+ return;
61
+ if (!this.prepared) {
62
+ fs.mkdirSync(this.directory, { recursive: true, mode: 0o700 });
63
+ fs.chmodSync(this.directory, 0o700);
64
+ this.prepared = true;
65
+ }
66
+ this.rotate(time);
67
+ this.prune(time);
68
+ this.currentDate = currentDate;
69
+ }
70
+ rotate(time) {
71
+ const active = path.join(this.directory, 'debug.log');
72
+ let stats;
73
+ try {
74
+ stats = fs.lstatSync(active);
75
+ }
76
+ catch (error) {
77
+ if (error.code === 'ENOENT')
78
+ return;
79
+ throw error;
80
+ }
81
+ if (!stats.isFile() || stats.isSymbolicLink())
82
+ throw new Error('invalid_operational_log');
83
+ const sourceDate = dateOf(stats.mtime);
84
+ if (sourceDate === dateOf(time))
85
+ return;
86
+ const archive = path.join(this.directory, `${sourceDate}-debug.log.gz`);
87
+ const archived = fs.existsSync(archive) ? fs.lstatSync(archive) : null;
88
+ if (archived && (!archived.isFile() || archived.isSymbolicLink()))
89
+ throw new Error('invalid_operational_archive');
90
+ const prior = archived ? gunzipSync(fs.readFileSync(archive)) : Buffer.alloc(0);
91
+ const compressed = gzipSync(Buffer.concat([prior, fs.readFileSync(active)]));
92
+ const temporary = `${archive}.${randomUUID()}.tmp`;
93
+ try {
94
+ fs.writeFileSync(temporary, compressed, { flag: 'wx', mode: 0o600 });
95
+ fs.renameSync(temporary, archive);
96
+ fs.chmodSync(archive, 0o600);
97
+ fs.unlinkSync(active);
98
+ }
99
+ finally {
100
+ try {
101
+ fs.unlinkSync(temporary);
102
+ }
103
+ catch (error) {
104
+ if (error.code !== 'ENOENT')
105
+ throw error;
106
+ }
107
+ }
108
+ }
109
+ prune(time) {
110
+ for (const name of fs.readdirSync(this.directory)) {
111
+ const match = /^(\d{4}-\d{2}-\d{2})-debug\.log\.gz$/u.exec(name);
112
+ if (!match)
113
+ continue;
114
+ const date = new Date(`${match[1]}T00:00:00.000Z`);
115
+ if (Number.isFinite(date.getTime()) && time.getTime() - date.getTime() > ARCHIVE_RETENTION_MS)
116
+ fs.unlinkSync(path.join(this.directory, name));
117
+ }
118
+ }
119
+ }
@@ -0,0 +1,23 @@
1
+ import type { TerminalNetworkAccess, TerminalSandbox } from './terminal-sandbox.ts';
2
+ export type TerminalCommandAccess = 'workspace' | 'host';
3
+ export type TerminalExecutePolicy = {
4
+ policyVersion: 2;
5
+ commandAccess: TerminalCommandAccess;
6
+ networkAccess: TerminalNetworkAccess;
7
+ commandAccessExpiresAt: number | null;
8
+ networkAccessExpiresAt: number | null;
9
+ networkAccessOnce?: boolean;
10
+ policyGrantRevision: number;
11
+ };
12
+ type PolicyFrame = Partial<TerminalExecutePolicy> & {
13
+ operation?: 'shell' | 'apply_patch' | 'browser' | 'save_image';
14
+ sandbox?: TerminalSandbox;
15
+ browserLocalOnly?: boolean;
16
+ };
17
+ /** The connected Realtime process must send a complete, current policy for every execution. */
18
+ export declare function validateExecutePolicy(frame: PolicyFrame, now?: number): string | null;
19
+ export declare function executionPolicyDeadline(frame: TerminalExecutePolicy & {
20
+ operation?: 'shell' | 'apply_patch' | 'browser' | 'save_image';
21
+ sandbox?: TerminalSandbox;
22
+ }): number | null;
23
+ export {};
@@ -0,0 +1,48 @@
1
+ function validDeadline(value) {
2
+ return value === null || Number.isSafeInteger(value) && Number(value) > 0;
3
+ }
4
+ /** The connected Realtime process must send a complete, current policy for every execution. */
5
+ export function validateExecutePolicy(frame, now = Date.now()) {
6
+ if (frame.policyVersion !== 2 || !['workspace', 'host'].includes(frame.commandAccess || '')
7
+ || !['none', 'local', 'full'].includes(frame.networkAccess || '')
8
+ || !validDeadline(frame.commandAccessExpiresAt)
9
+ || !validDeadline(frame.networkAccessExpiresAt)
10
+ || !Number.isSafeInteger(frame.policyGrantRevision) || frame.policyGrantRevision < 0)
11
+ return 'terminal_policy_v2_required';
12
+ if (frame.commandAccessExpiresAt !== null && frame.commandAccessExpiresAt <= now
13
+ || frame.networkAccessExpiresAt !== null && frame.networkAccessExpiresAt <= now)
14
+ return 'terminal_policy_expired';
15
+ if (frame.sandbox === 'unrestricted' && frame.commandAccess !== 'host')
16
+ return 'terminal_command_access_denied';
17
+ if (frame.sandbox === 'workspace-network' && frame.operation === 'shell'
18
+ && frame.networkAccess !== 'full')
19
+ return 'terminal_network_disabled';
20
+ if (frame.sandbox === 'workspace' && frame.operation === 'shell'
21
+ && frame.networkAccess === 'full')
22
+ return 'terminal_policy_invalid';
23
+ if (frame.operation === 'apply_patch' && frame.networkAccess !== 'none')
24
+ return 'terminal_policy_invalid';
25
+ if (frame.operation === 'browser') {
26
+ if (frame.networkAccess === 'none')
27
+ return 'terminal_network_disabled';
28
+ if (frame.browserLocalOnly !== (frame.networkAccess === 'local'))
29
+ return 'terminal_policy_invalid';
30
+ }
31
+ if (frame.networkAccessOnce !== undefined && typeof frame.networkAccessOnce !== 'boolean'
32
+ || frame.networkAccessOnce === true && (frame.operation !== 'browser'
33
+ || frame.networkAccessExpiresAt === null))
34
+ return 'terminal_policy_invalid';
35
+ if (frame.operation === 'save_image' && frame.networkAccess !== 'full')
36
+ return 'terminal_network_disabled';
37
+ return null;
38
+ }
39
+ export function executionPolicyDeadline(frame) {
40
+ const deadlines = [
41
+ ...(frame.sandbox === 'unrestricted' && frame.commandAccessExpiresAt !== null
42
+ ? [frame.commandAccessExpiresAt] : []),
43
+ ...(frame.networkAccess !== 'none' && frame.networkAccessExpiresAt !== null
44
+ && (frame.sandbox === 'unrestricted' || frame.sandbox === 'workspace-network'
45
+ || frame.operation === 'browser') ? [frame.networkAccessExpiresAt] : []),
46
+ ];
47
+ return deadlines.length ? Math.min(...deadlines) : null;
48
+ }
@@ -0,0 +1,4 @@
1
+ /** node-pty's macOS prebuild launches this helper with posix_spawn. */
2
+ export declare function ensurePtyHelperExecutable(packageRoot?: string, platform?: NodeJS.Platform, arch?: NodeJS.Architecture): void;
3
+ /** These failures happen before node-pty starts the requested process. */
4
+ export declare function normalizePtyStartError(error: unknown): Error;
@@ -0,0 +1,39 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { createRequire } from 'node:module';
4
+ const require = createRequire(import.meta.url);
5
+ /** node-pty's macOS prebuild launches this helper with posix_spawn. */
6
+ export function ensurePtyHelperExecutable(packageRoot = path.dirname(require.resolve('node-pty/package.json')), platform = process.platform, arch = process.arch) {
7
+ if (platform !== 'darwin')
8
+ return;
9
+ const candidates = [path.join(packageRoot, 'prebuilds', `darwin-${arch}`, 'spawn-helper'),
10
+ path.join(packageRoot, 'build', 'Release', 'spawn-helper')];
11
+ let found = false;
12
+ for (const helper of candidates) {
13
+ if (!fs.existsSync(helper))
14
+ continue;
15
+ found = true;
16
+ const stat = fs.lstatSync(helper);
17
+ if (!stat.isFile())
18
+ throw new Error('pty_helper_invalid');
19
+ try {
20
+ // Keep the package file executable without inheriting world/group write
21
+ // or special permission bits from a damaged installation.
22
+ const safeMode = ((stat.mode & 0o777) & ~0o022) | 0o111;
23
+ if ((stat.mode & 0o7777) !== safeMode)
24
+ fs.chmodSync(helper, safeMode);
25
+ fs.accessSync(helper, fs.constants.X_OK);
26
+ }
27
+ catch {
28
+ throw new Error('pty_helper_not_executable');
29
+ }
30
+ }
31
+ if (!found)
32
+ throw new Error('pty_helper_missing');
33
+ }
34
+ /** These failures happen before node-pty starts the requested process. */
35
+ export function normalizePtyStartError(error) {
36
+ const message = error instanceof Error ? error.message : String(error);
37
+ return message === 'posix_spawnp failed.' || /^pty_helper_(?:invalid|missing|not_executable)$/u.test(message)
38
+ ? new Error('pty_unavailable') : error instanceof Error ? error : new Error(message);
39
+ }
@@ -0,0 +1,11 @@
1
+ /** One grace period from the first lost runner socket; failed reconnects do not renew it. */
2
+ export declare class TerminalReconnectGrace {
3
+ private timer?;
4
+ private readonly onExpire;
5
+ private readonly delayMs;
6
+ private readonly scheduleTimer;
7
+ private readonly clearTimer;
8
+ constructor(onExpire: () => void, delayMs?: number, scheduleTimer?: typeof setTimeout, clearTimer?: typeof clearTimeout);
9
+ start(hasRunningWork: boolean): void;
10
+ clear(): void;
11
+ }
@@ -0,0 +1,29 @@
1
+ /** One grace period from the first lost runner socket; failed reconnects do not renew it. */
2
+ export class TerminalReconnectGrace {
3
+ timer;
4
+ onExpire;
5
+ delayMs;
6
+ scheduleTimer;
7
+ clearTimer;
8
+ constructor(onExpire, delayMs = 120_000, scheduleTimer = setTimeout, clearTimer = clearTimeout) {
9
+ this.onExpire = onExpire;
10
+ this.delayMs = delayMs;
11
+ this.scheduleTimer = scheduleTimer;
12
+ this.clearTimer = clearTimer;
13
+ }
14
+ start(hasRunningWork) {
15
+ if (!hasRunningWork || this.timer)
16
+ return;
17
+ this.timer = this.scheduleTimer(() => {
18
+ this.timer = undefined;
19
+ this.onExpire();
20
+ }, this.delayMs);
21
+ this.timer.unref?.();
22
+ }
23
+ clear() {
24
+ if (!this.timer)
25
+ return;
26
+ this.clearTimer(this.timer);
27
+ this.timer = undefined;
28
+ }
29
+ }
@@ -1,6 +1,10 @@
1
1
  export type TerminalSandbox = 'workspace' | 'workspace-network' | 'unrestricted';
2
+ export type TerminalNetworkAccess = 'none' | 'local' | 'full';
3
+ export declare function isTerminalSandbox(value: unknown): value is TerminalSandbox;
4
+ /** Keep macOS private TMPDIR short enough for Nx and other Unix-domain sockets. */
5
+ export declare function createSandboxScratchDirectory(platform?: NodeJS.Platform): string;
2
6
  export declare function shellQuote(value: string): string;
3
- export declare function sandboxCommand(workspace: string, workdir: string, command: string, sandbox: TerminalSandbox, platform?: NodeJS.Platform, scratchDir?: string, readPaths?: string[], networkAllowed?: boolean): {
7
+ export declare function sandboxCommand(workspace: string, workdir: string, command: string, sandbox: TerminalSandbox, platform?: NodeJS.Platform, scratchDir?: string, readPaths?: string[], networkAccess?: TerminalNetworkAccess): {
4
8
  file: string;
5
9
  args: string[];
6
10
  };
@@ -1,22 +1,34 @@
1
1
  import fs from 'node:fs';
2
2
  import os from 'node:os';
3
3
  import path from 'node:path';
4
+ export function isTerminalSandbox(value) {
5
+ return value === 'workspace' || value === 'workspace-network' || value === 'unrestricted';
6
+ }
7
+ /** Keep macOS private TMPDIR short enough for Nx and other Unix-domain sockets. */
8
+ export function createSandboxScratchDirectory(platform = process.platform) {
9
+ const base = platform === 'darwin' ? fs.realpathSync('/tmp') : os.tmpdir();
10
+ return fs.mkdtempSync(path.join(base, 'revo-terminal-'));
11
+ }
4
12
  export function shellQuote(value) { return `'${value.replace(/'/g, `'\\''`)}'`; }
5
13
  function seatbeltLiteral(value) {
6
14
  return `"${value.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
7
15
  }
8
- export function sandboxCommand(workspace, workdir, command, sandbox, platform = process.platform, scratchDir, readPaths = [], networkAllowed = true) {
16
+ export function sandboxCommand(workspace, workdir, command, sandbox, platform = process.platform, scratchDir, readPaths = [], networkAccess = 'none') {
9
17
  const shell = platform === 'darwin' ? '/bin/zsh' : '/bin/sh';
10
- if (sandbox === 'unrestricted' && networkAllowed)
18
+ if (sandbox === 'unrestricted' && networkAccess === 'full')
11
19
  return { file: shell, args: ['-lc', command] };
12
20
  if (sandbox === 'unrestricted') {
13
21
  if (platform === 'darwin') {
14
22
  if (!fs.existsSync('/usr/bin/sandbox-exec'))
15
23
  throw new Error('network_sandbox_unavailable');
16
24
  return { file: '/usr/bin/sandbox-exec',
17
- args: ['-p', '(version 1)\n(allow default)\n(deny network*)', shell, '-c', command] };
25
+ args: ['-p', ['(version 1)', '(allow default)', '(deny network*)',
26
+ ...(networkAccess === 'local' ? ['(allow network-outbound (remote ip "localhost:*"))',
27
+ '(allow network-inbound (local ip "localhost:*"))'] : [])].join('\n'), shell, '-c', command] };
18
28
  }
19
29
  if (platform === 'linux') {
30
+ if (networkAccess === 'local')
31
+ throw new Error('local_network_sandbox_unavailable');
20
32
  return { file: 'bwrap', args: ['--die-with-parent', '--unshare-net', '--bind', '/', '/',
21
33
  '--dev-bind', '/dev', '/dev', '--proc', '/proc', '--chdir', fs.realpathSync(workdir), shell, '-c', command] };
22
34
  }
@@ -24,7 +36,7 @@ export function sandboxCommand(workspace, workdir, command, sandbox, platform =
24
36
  }
25
37
  if (sandbox !== 'workspace' && sandbox !== 'workspace-network')
26
38
  throw new Error('Invalid terminal sandbox.');
27
- if (sandbox === 'workspace-network' && !networkAllowed)
39
+ if (sandbox === 'workspace-network' && networkAccess !== 'full')
28
40
  throw new Error('terminal_network_disabled');
29
41
  const root = fs.realpathSync(workspace);
30
42
  const cwd = fs.realpathSync(workdir);
@@ -55,7 +67,7 @@ export function sandboxCommand(workspace, workdir, command, sandbox, platform =
55
67
  const profile = [
56
68
  '(version 1)', '(allow default)',
57
69
  ...(sandbox === 'workspace' ? ['(deny network*)',
58
- ...(networkAllowed ? ['(allow network-outbound (remote ip "localhost:*"))',
70
+ ...(networkAccess !== 'none' ? ['(allow network-outbound (remote ip "localhost:*"))',
59
71
  '(allow network-inbound (local ip "localhost:*"))'] : [])] : []),
60
72
  '(deny file-write*)',
61
73
  `(allow file-write* (subpath ${seatbeltLiteral(root)}))`,
@@ -74,6 +86,8 @@ export function sandboxCommand(workspace, workdir, command, sandbox, platform =
74
86
  if (platform === 'linux') {
75
87
  if (root === '/')
76
88
  throw new Error('Workspace root cannot be the filesystem root.');
89
+ if (sandbox === 'workspace' && networkAccess === 'local')
90
+ throw new Error('local_network_sandbox_unavailable');
77
91
  return { file: 'bwrap', args: ['--die-with-parent',
78
92
  ...(sandbox === 'workspace' ? ['--unshare-net'] : []), '--ro-bind', '/', '/',
79
93
  '--dev-bind', '/dev', '/dev', '--proc', '/proc', '--tmpfs', '/tmp',
@@ -0,0 +1,25 @@
1
+ import { type KeyObject } from 'node:crypto';
2
+ export type SecureBrowserInputEnvelope = {
3
+ type: 'secure_browser_input';
4
+ requestId: string;
5
+ threadId: string;
6
+ agentTerminalId: string;
7
+ browserSessionId: string;
8
+ origin: string;
9
+ selector: string;
10
+ connectionId: string;
11
+ keyId: string;
12
+ expiresAt: number;
13
+ ephemeralPublicKey: string;
14
+ iv: string;
15
+ ciphertext: string;
16
+ tag: string;
17
+ };
18
+ export type SecureBrowserIdentity = {
19
+ publicKey: string;
20
+ keyId: string;
21
+ privateKey: KeyObject;
22
+ };
23
+ export declare function createSecureBrowserIdentity(): SecureBrowserIdentity;
24
+ export declare function secureBrowserInputAad(frame: SecureBrowserInputEnvelope): Buffer;
25
+ export declare function decryptSecureBrowserInput(frame: SecureBrowserInputEnvelope, identity: SecureBrowserIdentity): string;
@@ -0,0 +1,58 @@
1
+ import { createDecipheriv, createHash, createPublicKey, diffieHellman, generateKeyPairSync, hkdfSync } from 'node:crypto';
2
+ const INFO = Buffer.from('revo-browser-credential-v1', 'utf8');
3
+ const BASE64 = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u;
4
+ function bytes(value, min, max) {
5
+ if (typeof value !== 'string' || !BASE64.test(value))
6
+ throw new Error('secure_input_invalid');
7
+ const decoded = Buffer.from(value, 'base64');
8
+ if (decoded.length < min || decoded.length > max || decoded.toString('base64') !== value)
9
+ throw new Error('secure_input_invalid');
10
+ return decoded;
11
+ }
12
+ export function createSecureBrowserIdentity() {
13
+ const pair = generateKeyPairSync('x25519');
14
+ const publicKey = pair.publicKey.export({ type: 'spki', format: 'der' });
15
+ return { publicKey: publicKey.toString('base64'),
16
+ keyId: createHash('sha256').update(publicKey).digest('hex'), privateKey: pair.privateKey };
17
+ }
18
+ export function secureBrowserInputAad(frame) {
19
+ return Buffer.from(JSON.stringify([frame.requestId, frame.threadId, frame.agentTerminalId,
20
+ frame.browserSessionId, frame.origin, frame.selector, frame.connectionId,
21
+ frame.keyId, frame.expiresAt]), 'utf8');
22
+ }
23
+ export function decryptSecureBrowserInput(frame, identity) {
24
+ if (frame.keyId !== identity.keyId || !Number.isSafeInteger(frame.expiresAt)
25
+ || frame.expiresAt < Date.now() || frame.expiresAt > Date.now() + 120_000
26
+ || !/^[a-f0-9-]{36}$/iu.test(frame.requestId)
27
+ || !/^[a-f0-9]{64}$/u.test(frame.browserSessionId)
28
+ || typeof frame.selector !== 'string' || !frame.selector.trim() || frame.selector.length > 500
29
+ || typeof frame.origin !== 'string' || frame.origin.length > 2_048
30
+ || typeof frame.threadId !== 'string' || frame.threadId.length > 128
31
+ || typeof frame.agentTerminalId !== 'string' || frame.agentTerminalId.length > 128
32
+ || typeof frame.connectionId !== 'string' || frame.connectionId.length > 128)
33
+ throw new Error('secure_input_invalid');
34
+ const publicBytes = bytes(frame.ephemeralPublicKey, 44, 128);
35
+ const publicKey = createPublicKey({ key: publicBytes, format: 'der', type: 'spki' });
36
+ if (publicKey.asymmetricKeyType !== 'x25519')
37
+ throw new Error('secure_input_invalid');
38
+ const shared = diffieHellman({ privateKey: identity.privateKey, publicKey });
39
+ const key = Buffer.from(hkdfSync('sha256', shared, Buffer.from(frame.requestId, 'utf8'), INFO, 32));
40
+ shared.fill(0);
41
+ const decipher = createDecipheriv('aes-256-gcm', key, bytes(frame.iv, 12, 12));
42
+ decipher.setAAD(secureBrowserInputAad(frame));
43
+ decipher.setAuthTag(bytes(frame.tag, 16, 16));
44
+ try {
45
+ const plaintext = Buffer.concat([decipher.update(bytes(frame.ciphertext, 1, 8_192)), decipher.final()]);
46
+ if (plaintext.length > 4_096)
47
+ throw new Error('secure_input_invalid');
48
+ const value = plaintext.toString('utf8');
49
+ plaintext.fill(0);
50
+ return value;
51
+ }
52
+ catch {
53
+ throw new Error('secure_input_invalid');
54
+ }
55
+ finally {
56
+ key.fill(0);
57
+ }
58
+ }
@@ -1,5 +1,5 @@
1
1
  import { type ChildProcess } from 'node:child_process';
2
- import { type TerminalSandbox } from './terminal-sandbox.ts';
2
+ import { type TerminalNetworkAccess, type TerminalSandbox } from './terminal-sandbox.ts';
3
3
  export declare const MAX_TERMINAL_PROCESS_MS: number;
4
4
  type CommandResult = {
5
5
  executed: boolean;
@@ -10,6 +10,7 @@ type CommandResult = {
10
10
  truncated: boolean;
11
11
  logTruncated: boolean;
12
12
  logPath: string;
13
+ policyExpired?: boolean;
13
14
  };
14
15
  export type RunningProcess = {
15
16
  pid: number | undefined;
@@ -27,7 +28,8 @@ export declare function runCommand(input: {
27
28
  workspace: string;
28
29
  timeoutMs: number;
29
30
  sandbox?: TerminalSandbox;
30
- networkAllowed?: boolean;
31
+ networkAccess?: TerminalNetworkAccess;
32
+ policyDeadlineMs?: number | null;
31
33
  tty?: boolean;
32
34
  cols?: number;
33
35
  rows?: number;
@@ -38,6 +40,7 @@ export declare function runWorkspacePatch(input: {
38
40
  patch: string;
39
41
  workspace: string;
40
42
  allowDelete: boolean;
43
+ policyDeadlineMs?: number | null;
41
44
  }, onDone: (result: {
42
45
  executed: boolean;
43
46
  exitCode: number | null;