@revoengine/cli 1.0.29 → 1.0.31
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/README.md +156 -3
- package/dist/src/automation-contract.generated.d.ts +742 -0
- package/dist/src/automation-contract.generated.js +1021 -0
- package/dist/src/cli.js +9 -1
- package/dist/src/client.d.ts +24 -0
- package/dist/src/client.js +60 -0
- package/dist/src/commands/component.js +56 -23
- package/dist/src/commands/env.js +1 -1
- package/dist/src/commands/index.d.ts +2 -0
- package/dist/src/commands/index.js +2 -0
- package/dist/src/commands/studio.d.ts +3 -0
- package/dist/src/commands/studio.js +114 -0
- package/dist/src/commands/terminal-browser-human-input.d.ts +11 -0
- package/dist/src/commands/terminal-browser-human-input.js +44 -0
- package/dist/src/commands/terminal-browser-interaction.d.ts +25 -0
- package/dist/src/commands/terminal-browser-interaction.js +56 -0
- package/dist/src/commands/terminal-browser-live-protocol.d.ts +151 -0
- package/dist/src/commands/terminal-browser-live-protocol.js +177 -0
- package/dist/src/commands/terminal-browser-live-transport.d.ts +41 -0
- package/dist/src/commands/terminal-browser-live-transport.js +206 -0
- package/dist/src/commands/terminal-browser-live.d.ts +114 -0
- package/dist/src/commands/terminal-browser-live.js +455 -0
- package/dist/src/commands/terminal-browser-observation.d.ts +10 -0
- package/dist/src/commands/terminal-browser-observation.js +27 -0
- package/dist/src/commands/terminal-browser-page-input.d.ts +8 -0
- package/dist/src/commands/terminal-browser-page-input.js +94 -0
- package/dist/src/commands/terminal-browser-profile-preferences.d.ts +37 -0
- package/dist/src/commands/terminal-browser-profile-preferences.js +136 -0
- package/dist/src/commands/terminal-browser-profile.d.ts +52 -0
- package/dist/src/commands/terminal-browser-profile.js +447 -0
- package/dist/src/commands/terminal-browser.d.ts +28 -1
- package/dist/src/commands/terminal-browser.js +401 -55
- package/dist/src/commands/terminal-policy.js +2 -0
- package/dist/src/commands/terminal-public-web-proxy.d.ts +14 -0
- package/dist/src/commands/terminal-public-web-proxy.js +141 -0
- package/dist/src/commands/terminal-public-web.d.ts +11 -0
- package/dist/src/commands/terminal-public-web.js +99 -0
- package/dist/src/commands/terminal.d.ts +1 -0
- package/dist/src/commands/terminal.js +92 -9
- package/dist/src/commands/tests.d.ts +3 -0
- package/dist/src/commands/tests.js +236 -0
- package/dist/src/component-element-validation.d.ts +8 -0
- package/dist/src/component-element-validation.js +79 -0
- package/dist/src/component-lifecycle.d.ts +3 -0
- package/dist/src/component-lifecycle.js +17 -0
- package/dist/src/component-lock.d.ts +17 -12
- package/dist/src/component-lock.js +57 -6
- package/dist/src/component-manifests.js +3 -0
- package/dist/src/component-source-validation.d.ts +5 -0
- package/dist/src/component-source-validation.js +27 -0
- package/dist/src/env-sync.js +67 -9
- package/dist/src/native-tests.d.ts +61 -0
- package/dist/src/native-tests.js +20 -0
- package/dist/src/request-contract.d.ts +39 -0
- package/dist/src/request-contract.js +138 -0
- package/dist/src/resource-syncs/agent-sync.js +47 -7
- package/dist/src/resource-syncs/database-table-sync.js +8 -8
- package/dist/src/resource-syncs/endpoint-sync.js +20 -14
- package/dist/src/resource-syncs/group-sync.js +8 -3
- package/dist/src/resource-syncs/job-template-sync.js +75 -28
- package/dist/src/resource-syncs/role-group-sync.js +8 -0
- package/dist/src/resource-syncs/runtime-definition-validation.d.ts +14 -0
- package/dist/src/resource-syncs/runtime-definition-validation.js +153 -0
- package/dist/src/test-workspace.d.ts +33 -0
- package/dist/src/test-workspace.js +156 -0
- package/dist/src/types.d.ts +1 -0
- package/dist/src/ui.js +12 -0
- package/dist/src/update-notifier.d.ts +1 -1
- package/package.json +5 -3
|
@@ -48,6 +48,8 @@ export function validateExecutePolicy(frame, now = Date.now()) {
|
|
|
48
48
|
if (frame.operation === 'apply_patch' && frame.networkAccess !== 'none')
|
|
49
49
|
return 'terminal_policy_invalid';
|
|
50
50
|
if (frame.operation === 'browser') {
|
|
51
|
+
if (frame.browserAction === 'read_public' && frame.networkAccess !== 'full')
|
|
52
|
+
return 'terminal_network_disabled';
|
|
51
53
|
if (frame.networkAccess === 'none' && !['tabs', 'close', 'close_tab'].includes(frame.browserAction || ''))
|
|
52
54
|
return 'terminal_network_disabled';
|
|
53
55
|
if (frame.browserLocalOnly !== (frame.networkAccess === 'local'))
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { lookup } from 'node:dns/promises';
|
|
2
|
+
/** Public reads never reach LAN, metadata, translated IPv4, multicast or reserved addresses. */
|
|
3
|
+
export declare function publicWebAddress(address: string): boolean;
|
|
4
|
+
export declare function publicWebUrl(value: string): URL;
|
|
5
|
+
export declare function resolvePublicWebAddress(hostname: string, resolve?: typeof lookup): Promise<{
|
|
6
|
+
address: string;
|
|
7
|
+
family: number;
|
|
8
|
+
}>;
|
|
9
|
+
/** Connect to the validated numeric address, so Chromium cannot re-resolve a rebinding host.
|
|
10
|
+
* Every HTTP request and HTTPS tunnel (including redirects/subresources) uses this boundary. */
|
|
11
|
+
export declare function createPublicWebProxy(signal: AbortSignal): Promise<{
|
|
12
|
+
server: string;
|
|
13
|
+
close(): Promise<void>;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import http from 'node:http';
|
|
2
|
+
import net from 'node:net';
|
|
3
|
+
import { lookup } from 'node:dns/promises';
|
|
4
|
+
const BLOCKED = new Set(['localhost', 'localhost.localdomain', 'host.docker.internal',
|
|
5
|
+
'gateway.docker.internal', 'metadata', 'metadata.google.internal', 'kubernetes',
|
|
6
|
+
'kubernetes.default', 'kubernetes.default.svc']);
|
|
7
|
+
const IPV4_RANGES = [['0.0.0.0', 8], ['10.0.0.0', 8],
|
|
8
|
+
['100.64.0.0', 10], ['127.0.0.0', 8], ['169.254.0.0', 16], ['172.16.0.0', 12],
|
|
9
|
+
['192.0.0.0', 24], ['192.0.2.0', 24], ['192.168.0.0', 16], ['198.18.0.0', 15],
|
|
10
|
+
['198.51.100.0', 24], ['203.0.113.0', 24], ['224.0.0.0', 4], ['240.0.0.0', 4]];
|
|
11
|
+
const ipv4Number = (value) => value.split('.').reduce((total, part) => (total << 8) + Number(part), 0) >>> 0;
|
|
12
|
+
/** Public reads never reach LAN, metadata, translated IPv4, multicast or reserved addresses. */
|
|
13
|
+
export function publicWebAddress(address) {
|
|
14
|
+
if (net.isIP(address) === 4)
|
|
15
|
+
return !IPV4_RANGES.some(([base, prefix]) => ipv4Number(address) >>> (32 - prefix) === ipv4Number(base) >>> (32 - prefix));
|
|
16
|
+
if (net.isIP(address) !== 6 || address.includes('%'))
|
|
17
|
+
return false;
|
|
18
|
+
// Restrict IPv6 to global unicast, excluding transition/special-purpose ranges.
|
|
19
|
+
const first = parseInt(address.split(':')[0], 16);
|
|
20
|
+
return first >= 0x2000 && first <= 0x3fff && first !== 0x2002
|
|
21
|
+
&& !(first === 0x2001 && parseInt(address.split(':')[1] || '0', 16) < 0x200)
|
|
22
|
+
&& !(first === 0x2001 && parseInt(address.split(':')[1] || '0', 16) === 0xdb8);
|
|
23
|
+
}
|
|
24
|
+
export function publicWebUrl(value) {
|
|
25
|
+
const url = new URL(value);
|
|
26
|
+
const hostname = url.hostname.toLowerCase().replace(/^\[|\]$/gu, '').replace(/\.$/u, '');
|
|
27
|
+
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password
|
|
28
|
+
|| value.length > 2048 || BLOCKED.has(hostname)
|
|
29
|
+
|| ['.localhost', '.local', '.internal', '.home.arpa', '.cluster.local'].some(suffix => hostname.endsWith(suffix))
|
|
30
|
+
|| net.isIP(hostname) && !publicWebAddress(hostname))
|
|
31
|
+
throw new Error('public_web_destination_blocked');
|
|
32
|
+
return url;
|
|
33
|
+
}
|
|
34
|
+
export async function resolvePublicWebAddress(hostname, resolve = lookup) {
|
|
35
|
+
const host = hostname.replace(/^\[|\]$/gu, '');
|
|
36
|
+
const addresses = net.isIP(host) ? [{ address: host, family: net.isIP(host) }]
|
|
37
|
+
: await resolve(host, { all: true, verbatim: true });
|
|
38
|
+
if (!addresses.length || addresses.some(entry => !publicWebAddress(entry.address)))
|
|
39
|
+
throw new Error('public_web_destination_blocked');
|
|
40
|
+
return addresses[0];
|
|
41
|
+
}
|
|
42
|
+
/** Connect to the validated numeric address, so Chromium cannot re-resolve a rebinding host.
|
|
43
|
+
* Every HTTP request and HTTPS tunnel (including redirects/subresources) uses this boundary. */
|
|
44
|
+
export async function createPublicWebProxy(signal) {
|
|
45
|
+
const sockets = new Set();
|
|
46
|
+
let closed = false;
|
|
47
|
+
let transferredBytes = 0;
|
|
48
|
+
const track = (socket) => {
|
|
49
|
+
sockets.add(socket);
|
|
50
|
+
socket.on('data', chunk => {
|
|
51
|
+
transferredBytes += chunk.length;
|
|
52
|
+
if (transferredBytes > 8 * 1024 * 1024) {
|
|
53
|
+
closed = true;
|
|
54
|
+
for (const peer of sockets)
|
|
55
|
+
peer.destroy();
|
|
56
|
+
server.close();
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
socket.on('error', () => socket.destroy());
|
|
60
|
+
socket.once('close', () => sockets.delete(socket));
|
|
61
|
+
return socket;
|
|
62
|
+
};
|
|
63
|
+
const server = http.createServer((incoming, outgoing) => {
|
|
64
|
+
void (async () => {
|
|
65
|
+
const url = publicWebUrl(incoming.url || '');
|
|
66
|
+
if (url.protocol !== 'http:' || !['GET', 'HEAD'].includes(incoming.method || ''))
|
|
67
|
+
throw new Error('blocked');
|
|
68
|
+
const pinned = await resolvePublicWebAddress(url.hostname);
|
|
69
|
+
if (closed || signal.aborted)
|
|
70
|
+
throw new Error('closed');
|
|
71
|
+
const headers = { ...incoming.headers, host: url.host };
|
|
72
|
+
delete headers['proxy-authorization'];
|
|
73
|
+
delete headers['proxy-connection'];
|
|
74
|
+
delete headers.authorization;
|
|
75
|
+
delete headers.cookie;
|
|
76
|
+
const upstream = http.request({ hostname: pinned.address, family: pinned.family,
|
|
77
|
+
port: url.port || 80, path: url.pathname + url.search, method: incoming.method,
|
|
78
|
+
headers, signal, timeout: 8000 }, response => {
|
|
79
|
+
outgoing.writeHead(response.statusCode || 502, response.headers);
|
|
80
|
+
response.pipe(outgoing);
|
|
81
|
+
});
|
|
82
|
+
upstream.on('socket', track);
|
|
83
|
+
upstream.on('timeout', () => upstream.destroy());
|
|
84
|
+
upstream.on('error', () => { if (!outgoing.headersSent)
|
|
85
|
+
outgoing.writeHead(502); outgoing.end(); });
|
|
86
|
+
incoming.pipe(upstream);
|
|
87
|
+
})().catch(() => { if (!outgoing.headersSent)
|
|
88
|
+
outgoing.writeHead(403); outgoing.end(); });
|
|
89
|
+
});
|
|
90
|
+
server.on('connection', track);
|
|
91
|
+
server.on('clientError', (_error, socket) => socket.destroy());
|
|
92
|
+
server.on('connect', (request, socket, head) => {
|
|
93
|
+
void (async () => {
|
|
94
|
+
const url = publicWebUrl('https://' + request.url);
|
|
95
|
+
if (url.pathname !== '/' || url.search || url.hash)
|
|
96
|
+
throw new Error('blocked');
|
|
97
|
+
const pinned = await resolvePublicWebAddress(url.hostname);
|
|
98
|
+
if (closed || signal.aborted || socket.destroyed)
|
|
99
|
+
throw new Error('closed');
|
|
100
|
+
const upstream = net.connect({ host: pinned.address, family: pinned.family, port: Number(url.port || 443) });
|
|
101
|
+
track(upstream);
|
|
102
|
+
upstream.setTimeout(8000, () => upstream.destroy());
|
|
103
|
+
upstream.once('connect', () => {
|
|
104
|
+
if (closed || socket.destroyed) {
|
|
105
|
+
upstream.destroy();
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
socket.write('HTTP/1.1 200 Connection Established\r\n\r\n');
|
|
109
|
+
if (head.length)
|
|
110
|
+
upstream.write(head);
|
|
111
|
+
socket.pipe(upstream);
|
|
112
|
+
upstream.pipe(socket);
|
|
113
|
+
});
|
|
114
|
+
upstream.once('close', () => socket.destroy());
|
|
115
|
+
socket.once('close', () => upstream.destroy());
|
|
116
|
+
})().catch(() => socket.destroy());
|
|
117
|
+
});
|
|
118
|
+
const stop = () => { closed = true; for (const socket of sockets)
|
|
119
|
+
socket.destroy(); server.close(); };
|
|
120
|
+
signal.addEventListener('abort', stop, { once: true });
|
|
121
|
+
try {
|
|
122
|
+
if (signal.aborted)
|
|
123
|
+
throw new Error('browser_cancelled');
|
|
124
|
+
await new Promise((resolve, reject) => {
|
|
125
|
+
server.once('error', reject);
|
|
126
|
+
server.listen(0, '127.0.0.1', () => { server.removeListener('error', reject); resolve(); });
|
|
127
|
+
});
|
|
128
|
+
if (signal.aborted)
|
|
129
|
+
throw new Error('browser_cancelled');
|
|
130
|
+
const address = server.address();
|
|
131
|
+
return { server: `http://127.0.0.1:${address.port}`, close: async () => {
|
|
132
|
+
signal.removeEventListener('abort', stop);
|
|
133
|
+
stop();
|
|
134
|
+
} };
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
signal.removeEventListener('abort', stop);
|
|
138
|
+
stop();
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { BrowserType } from 'playwright-core';
|
|
2
|
+
import { createPublicWebProxy } from './terminal-public-web-proxy.ts';
|
|
3
|
+
export declare function readPublicWebPage(input: {
|
|
4
|
+
url: string;
|
|
5
|
+
timeoutMs?: number;
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
onActionAttempt?: () => void;
|
|
8
|
+
}, dependencies?: {
|
|
9
|
+
chromium?: Pick<BrowserType, 'launch'>;
|
|
10
|
+
proxy?: typeof createPublicWebProxy;
|
|
11
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { createPublicWebProxy, publicWebUrl } from "./terminal-public-web-proxy.js";
|
|
2
|
+
// Independent of interactive contexts/profile leases. Bound across all chats on this runner.
|
|
3
|
+
let activeReads = 0;
|
|
4
|
+
export async function readPublicWebPage(input, dependencies = {}) {
|
|
5
|
+
publicWebUrl(input.url);
|
|
6
|
+
const timeout = input.timeoutMs ?? 6000;
|
|
7
|
+
if (!Number.isInteger(timeout) || timeout < 1 || timeout > 8000)
|
|
8
|
+
throw new Error('invalid_browser_timeout');
|
|
9
|
+
if (input.signal?.aborted)
|
|
10
|
+
throw new Error('browser_cancelled');
|
|
11
|
+
if (activeReads >= 3)
|
|
12
|
+
throw new Error('browser_public_read_limit');
|
|
13
|
+
activeReads++;
|
|
14
|
+
const controller = new AbortController();
|
|
15
|
+
const abort = () => controller.abort();
|
|
16
|
+
input.signal?.addEventListener('abort', abort, { once: true });
|
|
17
|
+
const deadline = Date.now() + timeout;
|
|
18
|
+
const timer = setTimeout(abort, timeout);
|
|
19
|
+
let browser;
|
|
20
|
+
let proxy;
|
|
21
|
+
const closeBrowser = () => { void browser?.close().catch(() => undefined); };
|
|
22
|
+
controller.signal.addEventListener('abort', closeBrowser, { once: true });
|
|
23
|
+
try {
|
|
24
|
+
proxy = await (dependencies.proxy || createPublicWebProxy)(controller.signal);
|
|
25
|
+
const chromium = dependencies.chromium || (await import('playwright-core')).chromium;
|
|
26
|
+
browser = await chromium.launch({ headless: true, timeout: Math.max(1, deadline - Date.now()),
|
|
27
|
+
proxy: { server: proxy.server, bypass: '<-loopback>' },
|
|
28
|
+
args: ['--disable-background-networking', '--disable-quic',
|
|
29
|
+
'--force-webrtc-ip-handling-policy=disable_non_proxied_udp'] });
|
|
30
|
+
if (controller.signal.aborted)
|
|
31
|
+
throw new Error('browser_cancelled');
|
|
32
|
+
const context = await browser.newContext({ acceptDownloads: false, serviceWorkers: 'block' });
|
|
33
|
+
await context.addInitScript(() => {
|
|
34
|
+
for (const name of ['RTCPeerConnection', 'webkitRTCPeerConnection', 'WebTransport', 'Worker', 'SharedWorker'])
|
|
35
|
+
Object.defineProperty(globalThis, name, { value: undefined, writable: false, configurable: false });
|
|
36
|
+
});
|
|
37
|
+
await context.route('**/*', route => {
|
|
38
|
+
try {
|
|
39
|
+
publicWebUrl(route.request().url());
|
|
40
|
+
if (!['GET', 'HEAD'].includes(route.request().method()))
|
|
41
|
+
return route.abort();
|
|
42
|
+
const headers = { ...route.request().headers() };
|
|
43
|
+
delete headers.authorization;
|
|
44
|
+
delete headers.cookie;
|
|
45
|
+
return route.continue({ headers });
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return route.abort();
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
await context.routeWebSocket('**/*', socket => socket.close());
|
|
52
|
+
context.on('page', page => { if (context.pages().length > 1)
|
|
53
|
+
void page.close(); });
|
|
54
|
+
const page = await context.newPage();
|
|
55
|
+
input.onActionAttempt?.();
|
|
56
|
+
const response = await page.goto(input.url, { waitUntil: 'domcontentloaded', timeout: Math.max(1, deadline - Date.now()) });
|
|
57
|
+
if (!response || response.status() < 200 || response.status() >= 300)
|
|
58
|
+
throw new Error('public_web_http_failed');
|
|
59
|
+
const contentType = response.headers()['content-type'] || 'text/html';
|
|
60
|
+
if (!/^(text\/(html|plain)|application\/xhtml\+xml)\b/iu.test(contentType))
|
|
61
|
+
throw new Error('public_web_content_type');
|
|
62
|
+
// Wait for hydration, without waiting indefinitely for analytics/network-idle.
|
|
63
|
+
await page.waitForFunction(() => (document.querySelector('main, article') || document.body)?.innerText?.trim().length >= 80, undefined, { timeout: Math.max(1, deadline - Date.now()) });
|
|
64
|
+
const snapshot = await page.evaluate(() => {
|
|
65
|
+
const escape = (text) => text.replace(/&/gu, '&').replace(/</gu, '<').replace(/>/gu, '>').replace(/"/gu, '"');
|
|
66
|
+
const root = (document.querySelector('main, article') || document.body).cloneNode(true);
|
|
67
|
+
root.querySelectorAll('script,style,noscript,iframe,canvas,svg,nav,footer,header,form,aside,template,input,textarea').forEach(node => node.remove());
|
|
68
|
+
const headings = Array.from(root.querySelectorAll('h1,h2,h3')).slice(0, 24)
|
|
69
|
+
.map(node => '<h2>' + escape((node.textContent || '').slice(0, 200)) + '</h2>').join('');
|
|
70
|
+
const links = Array.from(document.querySelectorAll('a[href]')).slice(0, 40)
|
|
71
|
+
.map(node => '<a href="' + escape(node.href.slice(0, 512)) + '"></a>').join('');
|
|
72
|
+
return { url: window.location.href, html: '<html><head><title>' + escape(document.title.slice(0, 512)) + '</title></head><body><main><p>'
|
|
73
|
+
+ escape((root.textContent || '').slice(0, 8000)) + '</p>' + headings + '</main>' + links + '</body></html>' };
|
|
74
|
+
});
|
|
75
|
+
const result = { url: publicWebUrl(snapshot.url).toString(), statusCode: response.status(), contentType, html: snapshot.html };
|
|
76
|
+
while (JSON.stringify(result).length > 15_000)
|
|
77
|
+
result.html = result.html.slice(0, Math.max(0, result.html.length - 1000));
|
|
78
|
+
return JSON.stringify(result);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
if (controller.signal.aborted)
|
|
82
|
+
throw new Error('public_web_timeout');
|
|
83
|
+
if (error instanceof Error && error.message.includes("Executable doesn't exist at"))
|
|
84
|
+
throw new Error('browser_binary_unavailable');
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
clearTimeout(timer);
|
|
89
|
+
input.signal?.removeEventListener('abort', abort);
|
|
90
|
+
controller.signal.removeEventListener('abort', closeBrowser);
|
|
91
|
+
await browser?.close().catch(() => undefined);
|
|
92
|
+
try {
|
|
93
|
+
await proxy?.close();
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
activeReads--;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -47,6 +47,7 @@ export type RunningProcess = {
|
|
|
47
47
|
export declare function childEnvironment(source: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
48
48
|
export declare function acquireRunnerLock(agentTerminalId: string): () => void;
|
|
49
49
|
export declare function resolveWorkspaceDirectory(root: string, requested: string): string;
|
|
50
|
+
export declare function selectedBrowserProfile(argv: string[]): string | undefined;
|
|
50
51
|
export declare function boundResultFrame(frame: Record<string, unknown>): Record<string, unknown>;
|
|
51
52
|
export declare function runCommand(input: {
|
|
52
53
|
cmd: string;
|
|
@@ -18,6 +18,9 @@ import { TerminalReconnectGrace, TerminalTransportRecovery, isRunnerTransportHea
|
|
|
18
18
|
import { TerminalOutputBuffer } from "./terminal-output-buffer.js";
|
|
19
19
|
import { TerminalOperationalLog } from "./terminal-operational-log.js";
|
|
20
20
|
import { createSecureBrowserIdentity, decryptSecureBrowserInput } from "./terminal-secure-browser.js";
|
|
21
|
+
import { BrowserAuthProfileStore, macOSBrowserProfileKeyStore, validateBrowserProfileName } from "./terminal-browser-profile.js";
|
|
22
|
+
import { BrowserProfilePreferences } from "./terminal-browser-profile-preferences.js";
|
|
23
|
+
import { TerminalBrowserLiveTransport } from "./terminal-browser-live-transport.js";
|
|
21
24
|
class TerminalRunnerFatalError extends Error {
|
|
22
25
|
}
|
|
23
26
|
class TerminalApiTransientError extends Error {
|
|
@@ -72,6 +75,10 @@ const OPERATIONAL_ERROR_CODES = new Set([
|
|
|
72
75
|
'browser_secret_input_requires_secure_reference', 'browser_full_page_too_large',
|
|
73
76
|
'browser_element_too_large', 'browser_screenshot_too_large', 'browser_output_outside_workspace',
|
|
74
77
|
'browser_image_upload_unavailable', 'destructive_command_requires_approval',
|
|
78
|
+
'browser_profile_busy', 'browser_profile_changed', 'browser_profile_closed',
|
|
79
|
+
'browser_profile_corrupt', 'browser_profile_scope_invalid', 'browser_profile_scope_changed',
|
|
80
|
+
'browser_profile_keystore_unavailable', 'browser_profile_keystore_unsupported',
|
|
81
|
+
'browser_profile_directory_invalid', 'browser_profile_too_large',
|
|
75
82
|
'pty_unavailable', 'sandbox_unavailable',
|
|
76
83
|
]);
|
|
77
84
|
const CHILD_ENV_KEYS = ['HOME', 'PATH', 'USER', 'LOGNAME', 'SHELL', 'TMPDIR', 'LANG', 'LC_ALL', 'LC_CTYPE', 'TERM'];
|
|
@@ -257,6 +264,19 @@ function option(argv, name) {
|
|
|
257
264
|
return argv[index + 1];
|
|
258
265
|
return argv.find(value => value.startsWith(`--${name}=`))?.slice(name.length + 3);
|
|
259
266
|
}
|
|
267
|
+
export function selectedBrowserProfile(argv) {
|
|
268
|
+
const supplied = argv.some(value => value === '--browser-profile' || value.startsWith('--browser-profile='));
|
|
269
|
+
if (!supplied)
|
|
270
|
+
return undefined;
|
|
271
|
+
const name = option(argv, 'browser-profile');
|
|
272
|
+
if (!name || name.startsWith('--'))
|
|
273
|
+
throw new Error('browser_profile_name_invalid');
|
|
274
|
+
if (argv[0] === 'service' || argv.includes('--service-runner'))
|
|
275
|
+
throw new Error('browser_profile_service_unsupported');
|
|
276
|
+
if (!['connect', 'browser-profile'].includes(argv[0]))
|
|
277
|
+
throw new Error('browser_profile_option_invalid');
|
|
278
|
+
return validateBrowserProfileName(name);
|
|
279
|
+
}
|
|
260
280
|
function selectedProject(argv) {
|
|
261
281
|
const project = option(argv, 'project');
|
|
262
282
|
const legacy = option(argv, 'env');
|
|
@@ -648,7 +668,7 @@ export function runWorkspacePatch(input, onDone) {
|
|
|
648
668
|
child.on('error', error => finish(null, error));
|
|
649
669
|
return Object.assign(child, { updatePolicyDeadline });
|
|
650
670
|
}
|
|
651
|
-
async function connect(profile, device) {
|
|
671
|
+
async function connect(profile, device, authProfile) {
|
|
652
672
|
const logDeviceId = /^[A-Za-z0-9_-]{1,128}$/u.test(device.agentTerminalId)
|
|
653
673
|
? device.agentTerminalId : createHash('sha256').update(device.agentTerminalId).digest('hex');
|
|
654
674
|
const operationalLog = new TerminalOperationalLog(path.join(configDir(), 'logs', 'terminal', logDeviceId));
|
|
@@ -668,6 +688,9 @@ async function connect(profile, device) {
|
|
|
668
688
|
const completed = new Map();
|
|
669
689
|
const traces = new Map();
|
|
670
690
|
const secureRequests = new Map();
|
|
691
|
+
const profilePreferences = process.platform === 'darwin' && !process.argv.includes('--service-runner')
|
|
692
|
+
? new BrowserProfilePreferences(authProfile?.store || new BrowserAuthProfileStore(path.join(configDir(), 'browser-profiles'), macOSBrowserProfileKeyStore())) : undefined;
|
|
693
|
+
const browserScopes = new Map();
|
|
671
694
|
const resumed = new Set();
|
|
672
695
|
const reconnectGrace = new TerminalReconnectGrace(() => {
|
|
673
696
|
for (const child of children.values())
|
|
@@ -733,6 +756,28 @@ async function connect(profile, device) {
|
|
|
733
756
|
try {
|
|
734
757
|
await new Promise((resolve, reject) => {
|
|
735
758
|
const secureIdentity = createSecureBrowserIdentity();
|
|
759
|
+
const liveAuthorized = (frame) => {
|
|
760
|
+
const scope = browserScopes.get(frame.browserSessionId);
|
|
761
|
+
return !stopping && !policyRevisionUnavailable && activeConnectionId === frame.connectionId
|
|
762
|
+
&& frame.agentTerminalId === device.agentTerminalId && scope?.revision === minimumPolicyGrantRevision && scope.owner.actorUserId === frame.actorUserId
|
|
763
|
+
&& scope.threadId === frame.threadId && scope.workspaceId === frame.agentTerminalWorkspaceId
|
|
764
|
+
&& (scope.expiresAt === null || scope.expiresAt > Date.now());
|
|
765
|
+
};
|
|
766
|
+
const live = new TerminalBrowserLiveTransport({ runnerUrl: device.realtimeUrl,
|
|
767
|
+
headers: { Authorization: `Bearer ${profile.token}`, ...(profile.instance ? { instance: profile.instance } : {}) },
|
|
768
|
+
authorized: liveAuthorized,
|
|
769
|
+
options: frame => {
|
|
770
|
+
const scope = browserScopes.get(frame.browserSessionId);
|
|
771
|
+
if (!scope || !liveAuthorized(frame))
|
|
772
|
+
throw new Error('browser_live_scope_invalid');
|
|
773
|
+
return { browserSessionId: frame.browserSessionId, liveSessionId: frame.liveSessionId,
|
|
774
|
+
actorUserId: frame.actorUserId, threadId: frame.threadId,
|
|
775
|
+
agentTerminalWorkspaceId: frame.agentTerminalWorkspaceId, connectionId: frame.connectionId,
|
|
776
|
+
identity: secureIdentity, profilePreferences, profileOwner: scope.owner,
|
|
777
|
+
initialControl: { controlEpoch: frame.controlEpoch, mode: frame.mode, private: frame.private },
|
|
778
|
+
recordingDirectory: path.join(fs.realpathSync(configDir()), 'browser-recordings', device.agentTerminalId),
|
|
779
|
+
isAuthorized: () => liveAuthorized(frame) };
|
|
780
|
+
} });
|
|
736
781
|
const socket = new WebSocket(device.realtimeUrl, {
|
|
737
782
|
headers: { Authorization: `Bearer ${profile.token}`,
|
|
738
783
|
...(profile.instance ? { instance: profile.instance } : {}) },
|
|
@@ -750,11 +795,12 @@ async function connect(profile, device) {
|
|
|
750
795
|
reconnectGrace.clear();
|
|
751
796
|
});
|
|
752
797
|
socket.on('open', () => send(socket, { type: 'hello', protocol: 1, agentTerminalId: device.agentTerminalId,
|
|
753
|
-
secret: device.secret, capabilities: ['terminal_resume_durable_v1', 'grant_refresh_v1', 'workspace_sandbox_v1', 'workspace_network_v1', 'network_policy_v1',
|
|
798
|
+
secret: device.secret, browserSessionIds: browserSessionIds(), capabilities: ['terminal_resume_durable_v1', 'grant_refresh_v1', 'workspace_sandbox_v1', 'workspace_network_v1', 'network_policy_v1',
|
|
754
799
|
'terminal_policy_v2', 'terminal_policy_selective_v1', 'background_shell_v1', 'terminal_thread_scope_v1',
|
|
755
800
|
'apply_patch_v1', 'stdin_v1', 'pty_v1', 'browser_v1', 'browser_session_v1', 'browser_forms_v1',
|
|
756
801
|
'browser_local_v1', 'browser_once_v1', 'browser_secure_input_v1', 'browser_tabs_v1', 'save_image_v1',
|
|
757
|
-
'browser_timeout_v1', 'terminal_workspaces_v1', 'file_transfer_v1', 'browser_control_v1',
|
|
802
|
+
'browser_timeout_v1', 'browser_public_read_v1', 'terminal_workspaces_v1', 'file_transfer_v1', 'browser_control_v1', 'browser_live_v1', 'browser_interaction_v1', 'browser_recording_v1',
|
|
803
|
+
...(profilePreferences ? ['browser_profiles_v1'] : []),
|
|
758
804
|
...(process.platform === 'darwin' ? ['localhost_shell_v1'] : [])],
|
|
759
805
|
secureBrowserPublicKey: secureIdentity.publicKey, secureBrowserKeyId: secureIdentity.keyId }));
|
|
760
806
|
socket.on('message', raw => {
|
|
@@ -820,6 +866,10 @@ async function connect(profile, device) {
|
|
|
820
866
|
}
|
|
821
867
|
return;
|
|
822
868
|
}
|
|
869
|
+
if (frame.type === 'browser_live_attach') {
|
|
870
|
+
live.connect(frame);
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
823
873
|
if (frame.type === 'policy_updated') {
|
|
824
874
|
const update = frame;
|
|
825
875
|
if (update.connectionId !== connectionId)
|
|
@@ -833,10 +883,12 @@ async function connect(profile, device) {
|
|
|
833
883
|
await closeBrowserSessions();
|
|
834
884
|
return;
|
|
835
885
|
}
|
|
886
|
+
live.disconnectAll();
|
|
836
887
|
await updateGrantPolicy(update.policyGrantRevision, { mode: update.grantMode, networkMode: update.networkMode });
|
|
837
888
|
return;
|
|
838
889
|
}
|
|
839
890
|
if (frame.type === 'policy_revoked') {
|
|
891
|
+
live.disconnectAll();
|
|
840
892
|
if (frame.connectionId !== connectionId)
|
|
841
893
|
return;
|
|
842
894
|
securePolicyEpoch++;
|
|
@@ -996,7 +1048,7 @@ async function connect(profile, device) {
|
|
|
996
1048
|
&& typeof frame.browserSessionId === 'string' && frame.browserAction) {
|
|
997
1049
|
try {
|
|
998
1050
|
validateBrowserActionInput({ url: frame.url, action: frame.browserAction,
|
|
999
|
-
workspace, browserSessionId: frame.browserSessionId, tabId: frame.tabId, selector: frame.selector,
|
|
1051
|
+
workspace, browserSessionId: frame.browserSessionId, tabId: frame.tabId, interaction: frame.browserInteraction, selector: frame.selector,
|
|
1000
1052
|
width: frame.width, height: frame.height, value: frame.value, checked: frame.checked,
|
|
1001
1053
|
key: frame.key, deltaY: frame.deltaY, state: frame.state,
|
|
1002
1054
|
waitTimeoutMs: frame.waitTimeoutMs, capture: frame.capture, clip: frame.clip,
|
|
@@ -1107,7 +1159,7 @@ async function connect(profile, device) {
|
|
|
1107
1159
|
void runBrowserAction({ url: frame.url, action: frame.browserAction, workspace, agentTerminalWorkspaceId: frame.agentTerminalWorkspaceId,
|
|
1108
1160
|
browserSessionId: frame.browserSessionId, tabId: frame.tabId,
|
|
1109
1161
|
onActionAttempt: () => { actionAttempted = true; },
|
|
1110
|
-
selector: frame.selector, width: frame.width, height: frame.height,
|
|
1162
|
+
interaction: frame.browserInteraction, selector: frame.selector, width: frame.width, height: frame.height,
|
|
1111
1163
|
value: frame.value, checked: frame.checked, key: frame.key, deltaY: frame.deltaY,
|
|
1112
1164
|
state: frame.state, waitTimeoutMs: frame.waitTimeoutMs,
|
|
1113
1165
|
actionTimeoutMs: frame.actionTimeoutMs,
|
|
@@ -1117,8 +1169,17 @@ async function connect(profile, device) {
|
|
|
1117
1169
|
networkAccessOnce: frame.networkAccessOnce,
|
|
1118
1170
|
networkAccessForThread: frame.networkAccessForThread, actorUserId: frame.actorUserId,
|
|
1119
1171
|
threadId: frame.browserTargetThreadId || frame.assistantThreadId, policyGrantRevision: frame.policyGrantRevision,
|
|
1172
|
+
...(profilePreferences && frame.actorUserId ? { resolveAuthProfile: () => profilePreferences.resolveAsync({
|
|
1173
|
+
baseUrl: device.baseUrl, instanceId: device.instance, actorUserId: frame.actorUserId,
|
|
1174
|
+
terminalId: device.agentTerminalId, workspace
|
|
1175
|
+
}, authProfile?.name) } : {}),
|
|
1120
1176
|
signal: controller.signal })
|
|
1121
1177
|
.then(async (browserResult) => {
|
|
1178
|
+
if (frame.browserAction !== 'read_public')
|
|
1179
|
+
browserScopes.set(browserResult.browserSessionId, { workspace, workspaceId: frame.agentTerminalWorkspaceId || device.agentTerminalId,
|
|
1180
|
+
owner: { baseUrl: device.baseUrl, instanceId: device.instance, actorUserId: frame.actorUserId || '', terminalId: device.agentTerminalId, workspace },
|
|
1181
|
+
threadId: frame.browserTargetThreadId || frame.assistantThreadId || '', revision: frame.policyGrantRevision,
|
|
1182
|
+
expiresAt: frame.networkAccessExpiresAt ?? null });
|
|
1122
1183
|
if (frame.browserAction === 'screenshot') {
|
|
1123
1184
|
if (!browserResult.screenshotPath || frame.files?.length !== 1)
|
|
1124
1185
|
throw new Error('browser_image_upload_unavailable');
|
|
@@ -1132,8 +1193,10 @@ async function connect(profile, device) {
|
|
|
1132
1193
|
completed.set(frame.executionId, { executed: true, exitCode: 0,
|
|
1133
1194
|
stdout: browserResult.dom, stderr: '', screenshotPath: browserResult.screenshotPath || null,
|
|
1134
1195
|
pageUrl: browserResult.pageUrl,
|
|
1135
|
-
browserSessionId: browserResult.browserSessionId, activeTabId: browserResult.activeTabId,
|
|
1136
|
-
|
|
1196
|
+
...(frame.browserAction !== 'read_public' ? { browserSessionId: browserResult.browserSessionId, activeTabId: browserResult.activeTabId,
|
|
1197
|
+
tabs: browserResult.tabs, sessionCreated: browserResult.sessionCreated,
|
|
1198
|
+
browserObservation: browserResult.browserObservation, screenshotTransform: browserResult.screenshotTransform,
|
|
1199
|
+
browserProfileName: browserResult.browserProfile?.name, browserProfile: browserResult.browserProfile } : {}),
|
|
1137
1200
|
cancelled: cancelledExecutions.delete(frame.executionId) });
|
|
1138
1201
|
operationalLog.write('INFO', trace, 'execution.completed', { operation,
|
|
1139
1202
|
browserAction: frame.browserAction, exitCode: 0, screenshot: frame.browserAction === 'screenshot' });
|
|
@@ -1230,6 +1293,7 @@ async function connect(profile, device) {
|
|
|
1230
1293
|
}).catch(() => socket.terminate());
|
|
1231
1294
|
});
|
|
1232
1295
|
socket.on('close', (code, reason) => {
|
|
1296
|
+
live.disconnectAll();
|
|
1233
1297
|
securePolicyEpoch++;
|
|
1234
1298
|
operationalLog.write(code === 1000 ? 'INFO' : 'WARN', {}, 'socket.closed', { code, activeExecutions: children.size, policyViolation: code === 1008 });
|
|
1235
1299
|
if (heartbeat)
|
|
@@ -1296,8 +1360,9 @@ async function connect(profile, device) {
|
|
|
1296
1360
|
}
|
|
1297
1361
|
async function runTerminalCommand(argv, signal) {
|
|
1298
1362
|
const command = argv[0] || 'help';
|
|
1363
|
+
const browserProfileName = selectedBrowserProfile(argv);
|
|
1299
1364
|
if (command === 'help' || argv.includes('--help')) {
|
|
1300
|
-
console.log('revo terminal connect|status|disconnect [--project NAME] [--workspace PATH] [--name NAME|--terminal-id UUID] [--url URL] [--realtime-url URL]\nrevo terminal service install|uninstall --workspace PATH [--project NAME] [--name NAME|--terminal-id UUID]');
|
|
1365
|
+
console.log('revo terminal connect|status|disconnect [--project NAME] [--workspace PATH] [--name NAME|--terminal-id UUID] [--url URL] [--realtime-url URL]\nrevo terminal connect [--browser-profile NAME] (macOS foreground only)\nrevo terminal browser-profile forget --browser-profile NAME --workspace PATH --terminal-id UUID [--project NAME]\nrevo terminal service install|uninstall --workspace PATH [--project NAME] [--name NAME|--terminal-id UUID]');
|
|
1301
1366
|
return;
|
|
1302
1367
|
}
|
|
1303
1368
|
if (command === 'service') {
|
|
@@ -1372,6 +1437,8 @@ async function runTerminalCommand(argv, signal) {
|
|
|
1372
1437
|
return;
|
|
1373
1438
|
}
|
|
1374
1439
|
const profile = { ...resolveProfile(argv), retryReads: command === 'connect', signal };
|
|
1440
|
+
const authProfile = browserProfileName ? { name: browserProfileName,
|
|
1441
|
+
store: new BrowserAuthProfileStore(path.join(configDir(), 'browser-profiles'), macOSBrowserProfileKeyStore()) } : undefined;
|
|
1375
1442
|
let me;
|
|
1376
1443
|
if (!profile.instance) {
|
|
1377
1444
|
const currentUser = await api(profile, 'GET', '/me');
|
|
@@ -1388,6 +1455,20 @@ async function runTerminalCommand(argv, signal) {
|
|
|
1388
1455
|
const profileDevices = store.devices.filter(item => (command === 'connect' || item.workspace === workspace || item.workspaces?.includes(workspace))
|
|
1389
1456
|
&& item.baseUrl === profile.baseUrl && item.instance === profile.instance);
|
|
1390
1457
|
let matchingDevices = profileDevices.filter(item => terminalId ? item.agentTerminalId === terminalId : item.name === name);
|
|
1458
|
+
if (command === 'browser-profile') {
|
|
1459
|
+
if (argv[1] !== 'forget' || !authProfile)
|
|
1460
|
+
throw new Error('Use terminal browser-profile forget --browser-profile NAME.');
|
|
1461
|
+
const currentUser = me || await api(profile, 'GET', '/me');
|
|
1462
|
+
const selectedId = terminalId || (matchingDevices.length === 1 ? matchingDevices[0].agentTerminalId : undefined);
|
|
1463
|
+
if (!selectedId)
|
|
1464
|
+
throw new Error('Select the profile terminal with --terminal-id.');
|
|
1465
|
+
authProfile.store.forget({ name: authProfile.name, baseUrl: profile.baseUrl, instanceId: profile.instance,
|
|
1466
|
+
actorUserId: currentUser.userId || '', terminalId: selectedId, workspace });
|
|
1467
|
+
new BrowserProfilePreferences(authProfile.store).remove({ baseUrl: profile.baseUrl, instanceId: profile.instance,
|
|
1468
|
+
actorUserId: currentUser.userId || '', terminalId: selectedId, workspace }, authProfile.name);
|
|
1469
|
+
console.log('Browser profile forgotten. Website sessions must be revoked separately when required.');
|
|
1470
|
+
return;
|
|
1471
|
+
}
|
|
1391
1472
|
if (command === 'connect' && !terminalId && option(argv, 'name') === undefined
|
|
1392
1473
|
&& !matchingDevices.length
|
|
1393
1474
|
&& terminalServiceInstalled(workspace, selectedProject(argv) || getActiveEnvironmentName())) {
|
|
@@ -1504,13 +1585,15 @@ async function runTerminalCommand(argv, signal) {
|
|
|
1504
1585
|
}
|
|
1505
1586
|
catch (error) {
|
|
1506
1587
|
if (error instanceof Error && error.message.includes('already connected')) {
|
|
1588
|
+
if (authProfile)
|
|
1589
|
+
throw new Error('Stop the existing terminal runner before selecting --browser-profile.');
|
|
1507
1590
|
console.log(`Terminal ${device.agentTerminalId} already has a local runner; its workspace contract will refresh automatically.`);
|
|
1508
1591
|
return;
|
|
1509
1592
|
}
|
|
1510
1593
|
throw error;
|
|
1511
1594
|
}
|
|
1512
1595
|
try {
|
|
1513
|
-
await connect(profile, device);
|
|
1596
|
+
await connect(profile, device, authProfile);
|
|
1514
1597
|
}
|
|
1515
1598
|
finally {
|
|
1516
1599
|
releaseRunnerLock();
|