@revoengine/cli 1.0.31 → 1.0.34
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 +25 -0
- package/README.md +152 -24
- package/dist/src/argument-contract.d.ts +17 -0
- package/dist/src/argument-contract.js +359 -0
- package/dist/src/automation-contract.generated.d.ts +56 -22
- package/dist/src/automation-contract.generated.js +68 -26
- package/dist/src/cli.js +15 -13
- package/dist/src/client.d.ts +34 -2
- package/dist/src/client.js +76 -13
- package/dist/src/commands/agents.js +5 -1
- package/dist/src/commands/auth.js +2 -0
- package/dist/src/commands/component.js +34 -17
- package/dist/src/commands/database-tables.js +15 -4
- package/dist/src/commands/database-views.js +5 -1
- package/dist/src/commands/endpoints.js +5 -1
- package/dist/src/commands/env.js +5 -1
- package/dist/src/commands/events.js +5 -1
- package/dist/src/commands/groups.js +5 -1
- package/dist/src/commands/info.js +2 -0
- package/dist/src/commands/job-templates.js +5 -1
- package/dist/src/commands/metadata.js +2 -0
- package/dist/src/commands/migrate.d.ts +2 -2
- package/dist/src/commands/migrate.js +33 -7
- package/dist/src/commands/project.js +19 -14
- package/dist/src/commands/request.js +2 -0
- package/dist/src/commands/role-groups.js +5 -1
- package/dist/src/commands/schedules.js +5 -1
- package/dist/src/commands/search.js +2 -0
- package/dist/src/commands/service-accounts.js +5 -1
- package/dist/src/commands/studio.js +2 -0
- package/dist/src/commands/terminal-browser-central-profile.d.ts +65 -0
- package/dist/src/commands/terminal-browser-central-profile.js +203 -0
- package/dist/src/commands/terminal-browser-human-input.d.ts +3 -1
- package/dist/src/commands/terminal-browser-human-input.js +3 -1
- package/dist/src/commands/terminal-browser-interaction.js +1 -1
- package/dist/src/commands/terminal-browser-live-protocol.d.ts +34 -2
- package/dist/src/commands/terminal-browser-live-protocol.js +28 -12
- package/dist/src/commands/terminal-browser-live-transport.d.ts +1 -0
- package/dist/src/commands/terminal-browser-live-transport.js +9 -5
- package/dist/src/commands/terminal-browser-live.d.ts +24 -3
- package/dist/src/commands/terminal-browser-live.js +199 -30
- package/dist/src/commands/terminal-browser-page-input.d.ts +4 -1
- package/dist/src/commands/terminal-browser-page-input.js +46 -1
- package/dist/src/commands/terminal-browser-profile-crypto.d.ts +30 -0
- package/dist/src/commands/terminal-browser-profile-crypto.js +101 -0
- package/dist/src/commands/terminal-browser-profile-import-runner.d.ts +31 -0
- package/dist/src/commands/terminal-browser-profile-import-runner.js +112 -0
- package/dist/src/commands/terminal-browser-profile-import.d.ts +28 -0
- package/dist/src/commands/terminal-browser-profile-import.js +125 -0
- package/dist/src/commands/terminal-browser-profile-import.protocol.d.ts +50 -0
- package/dist/src/commands/terminal-browser-profile-import.protocol.js +52 -0
- package/dist/src/commands/terminal-browser-profile-preferences.d.ts +1 -0
- package/dist/src/commands/terminal-browser-profile-preferences.js +16 -0
- package/dist/src/commands/terminal-browser-profile-sync.d.ts +14 -0
- package/dist/src/commands/terminal-browser-profile-sync.js +169 -0
- package/dist/src/commands/terminal-browser-profile-sync.protocol.d.ts +50 -0
- package/dist/src/commands/terminal-browser-profile-sync.protocol.js +19 -0
- package/dist/src/commands/terminal-browser-profile.d.ts +10 -1
- package/dist/src/commands/terminal-browser-profile.js +30 -4
- package/dist/src/commands/terminal-browser-recording.d.ts +39 -0
- package/dist/src/commands/terminal-browser-recording.js +74 -0
- package/dist/src/commands/terminal-browser-recording.protocol.d.ts +49 -0
- package/dist/src/commands/terminal-browser-recording.protocol.js +16 -0
- package/dist/src/commands/terminal-browser.d.ts +14 -1
- package/dist/src/commands/terminal-browser.js +98 -33
- package/dist/src/commands/terminal-file-descriptor.d.ts +9 -0
- package/dist/src/commands/terminal-file-descriptor.js +39 -0
- package/dist/src/commands/terminal-file.js +41 -6
- package/dist/src/commands/terminal-image.js +3 -31
- package/dist/src/commands/terminal-output-buffer.d.ts +18 -1
- package/dist/src/commands/terminal-output-buffer.js +95 -8
- package/dist/src/commands/terminal-process-group.d.ts +25 -0
- package/dist/src/commands/terminal-process-group.js +144 -0
- package/dist/src/commands/terminal.d.ts +3 -1
- package/dist/src/commands/terminal.js +366 -80
- package/dist/src/commands/tests.js +2 -0
- package/dist/src/component-lock.d.ts +15 -1
- package/dist/src/component-lock.js +96 -10
- package/dist/src/env-sync.js +12 -6
- package/dist/src/migration.d.ts +7 -0
- package/dist/src/migration.js +39 -21
- package/dist/src/planning-snapshot.d.ts +3 -0
- package/dist/src/planning-snapshot.js +60 -2
- package/dist/src/project.d.ts +1 -0
- package/dist/src/project.js +7 -8
- package/dist/src/resource-syncs/agent-sync.js +76 -24
- package/dist/src/resource-syncs/database-table-sync.d.ts +8 -1
- package/dist/src/resource-syncs/database-table-sync.js +66 -32
- package/dist/src/resource-syncs/database-view-sync.js +41 -28
- package/dist/src/resource-syncs/endpoint-sync.js +90 -18
- package/dist/src/resource-syncs/event-sync.js +33 -14
- package/dist/src/resource-syncs/group-sync.js +21 -11
- package/dist/src/resource-syncs/job-template-sync.js +98 -37
- package/dist/src/resource-syncs/role-group-sync.js +22 -11
- package/dist/src/resource-syncs/schedule-sync.js +26 -11
- package/dist/src/resource-syncs/service-account-sync.js +22 -11
- package/dist/src/reviewed-plan.js +3 -0
- package/dist/src/runtime-view.js +2 -18
- package/dist/src/sync-omit-command.d.ts +6 -0
- package/dist/src/sync-omit-command.js +49 -0
- package/dist/src/sync-omit-write-fence.d.ts +10 -0
- package/dist/src/sync-omit-write-fence.js +134 -0
- package/dist/src/sync-omit.d.ts +59 -0
- package/dist/src/sync-omit.js +469 -0
- package/dist/src/sync-output.d.ts +3 -3
- package/dist/src/ui.js +11 -5
- package/dist/src/update-notifier.d.ts +1 -1
- package/dist/src/update-notifier.js +2 -1
- package/dist/src/utils.js +46 -17
- package/dist/src/workspace-prune.js +11 -3
- package/dist/src/workspace-write-lock.d.ts +7 -0
- package/dist/src/workspace-write-lock.js +144 -0
- package/package.json +6 -5
|
@@ -6,7 +6,7 @@ import { browserProfileScopeId } from "./terminal-browser-profile.js";
|
|
|
6
6
|
import { validBrowserInteraction } from "./terminal-browser-interaction.js";
|
|
7
7
|
import { BrowserObservations } from "./terminal-browser-observation.js";
|
|
8
8
|
import { BrowserLiveHandle, browserAuthPage } from "./terminal-browser-live.js";
|
|
9
|
-
import { applyPageInteraction, clearSecretInputs, releasePageInput, pageHasSecretFocus, secretControlAttributes } from "./terminal-browser-page-input.js";
|
|
9
|
+
import { applyPageInteraction, clearSecretInputs, releasePageInput, describeFocusedField, pageHasSecretFocus, secretControlAttributes } from "./terminal-browser-page-input.js";
|
|
10
10
|
const MAX_BROWSER_SESSIONS = 4;
|
|
11
11
|
const BROWSER_SESSION_IDLE_MS = 60 * 60_000;
|
|
12
12
|
const MAX_BROWSER_TABS = 16;
|
|
@@ -130,19 +130,21 @@ export function validateBrowserActionInput(input) {
|
|
|
130
130
|
|| input.clip.x + input.clip.width > width || input.clip.y + input.clip.height > height))
|
|
131
131
|
throw new Error('invalid_browser_capture');
|
|
132
132
|
}
|
|
133
|
-
async function closeSession(id) {
|
|
133
|
+
async function closeSession(id, options = {}) {
|
|
134
134
|
const session = browserSessions.get(id);
|
|
135
135
|
if (!session)
|
|
136
136
|
return;
|
|
137
137
|
browserSessions.delete(id);
|
|
138
|
-
session.live?.
|
|
138
|
+
session.live?.close();
|
|
139
|
+
await session.live?.settled();
|
|
139
140
|
if (session.networkLeaseTimer)
|
|
140
141
|
clearTimeout(session.networkLeaseTimer);
|
|
141
142
|
try {
|
|
142
143
|
await session.browser.close().catch(() => undefined);
|
|
143
144
|
}
|
|
144
145
|
finally {
|
|
145
|
-
|
|
146
|
+
if (!options.retainProfileLease)
|
|
147
|
+
await session.authProfile?.release();
|
|
146
148
|
}
|
|
147
149
|
}
|
|
148
150
|
async function checkpointProfile(session) {
|
|
@@ -150,7 +152,7 @@ async function checkpointProfile(session) {
|
|
|
150
152
|
return;
|
|
151
153
|
session.snapshotting = true;
|
|
152
154
|
try {
|
|
153
|
-
session.authProfile.save(await session.context.storageState({ indexedDB: true }));
|
|
155
|
+
await session.authProfile.save(await session.context.storageState({ indexedDB: true }));
|
|
154
156
|
}
|
|
155
157
|
finally {
|
|
156
158
|
session.snapshotting = false;
|
|
@@ -240,39 +242,44 @@ export async function closeThreadBrowserSession(browserSessionId) {
|
|
|
240
242
|
}
|
|
241
243
|
export function browserSessionIds() { return [...browserSessions.keys()]; }
|
|
242
244
|
export function hasBrowserSessions() { return browserSessions.size > 0; }
|
|
243
|
-
|
|
245
|
+
/** Revocation closes only this central context and never checkpoints its authentication. */
|
|
246
|
+
export async function revokeBrowserProfileSession(browserSessionId, profileId) {
|
|
247
|
+
if (browserSessions.get(browserSessionId)?.centralProfile?.id === profileId)
|
|
248
|
+
await closeSession(browserSessionId);
|
|
249
|
+
}
|
|
250
|
+
async function createSession(id, url, localOnly, width, height, signal, onNavigationAttempt, actionTimeoutMs, authProfile, centralProfile, recording) {
|
|
244
251
|
await pruneIdleSessions();
|
|
245
252
|
if (browserSessions.size + creatingSessions.size >= MAX_BROWSER_SESSIONS)
|
|
246
253
|
throw new Error('browser_session_limit');
|
|
247
254
|
creatingSessions.add(id);
|
|
248
255
|
let profileLease;
|
|
249
256
|
try {
|
|
250
|
-
profileLease = authProfile ? await authProfile.store.openAsync(authProfile.scope) : undefined;
|
|
257
|
+
profileLease = centralProfile?.lease ?? (authProfile ? await authProfile.store.openAsync(authProfile.scope) : undefined);
|
|
251
258
|
}
|
|
252
259
|
catch (error) {
|
|
253
260
|
creatingSessions.delete(id);
|
|
254
261
|
throw error;
|
|
255
262
|
}
|
|
256
263
|
const epoch = sessionEpoch;
|
|
257
|
-
const { chromium } = await import('playwright-core').catch(error => {
|
|
258
|
-
profileLease?.release();
|
|
264
|
+
const { chromium } = await import('playwright-core').catch(async (error) => {
|
|
265
|
+
await profileLease?.release();
|
|
259
266
|
creatingSessions.delete(id);
|
|
260
267
|
throw error;
|
|
261
268
|
});
|
|
262
|
-
const browser = await chromium.launch({ headless: true,
|
|
269
|
+
const browser = await chromium.launch({ channel: 'chromium', headless: true, ignoreDefaultArgs: ['--hide-scrollbars'],
|
|
263
270
|
args: localOnly ? ['--disable-background-networking',
|
|
264
271
|
'--host-resolver-rules=MAP localhost 127.0.0.1'] : [] }).catch(error => {
|
|
265
272
|
if (error instanceof Error && error.message.includes("Executable doesn't exist at"))
|
|
266
273
|
throw new Error('browser_binary_unavailable');
|
|
267
274
|
throw error;
|
|
268
|
-
}).catch(error => { profileLease?.release(); creatingSessions.delete(id); throw error; });
|
|
275
|
+
}).catch(async (error) => { await profileLease?.release(); creatingSessions.delete(id); throw error; });
|
|
269
276
|
const onAbort = () => { void browser.close(); };
|
|
270
277
|
signal?.addEventListener('abort', onAbort, { once: true });
|
|
271
278
|
try {
|
|
272
279
|
if (signal?.aborted)
|
|
273
280
|
throw new Error('browser_cancelled');
|
|
274
281
|
const context = await browser.newContext({ viewport: { width, height }, acceptDownloads: false,
|
|
275
|
-
serviceWorkers: 'block' });
|
|
282
|
+
serviceWorkers: localOnly ? 'block' : 'allow' });
|
|
276
283
|
const geometryBinding = 'revoGeometry_' + randomUUID().replaceAll('-', '');
|
|
277
284
|
await context.exposeBinding(geometryBinding, ({ page }) => {
|
|
278
285
|
const session = browserSessions.get(id);
|
|
@@ -295,9 +302,14 @@ async function createSession(id, url, localOnly, width, height, signal, onNaviga
|
|
|
295
302
|
});
|
|
296
303
|
}
|
|
297
304
|
});
|
|
298
|
-
await context.route('**/*', route => {
|
|
305
|
+
await context.route('**/*', async (route) => {
|
|
299
306
|
try {
|
|
300
307
|
(localOnly ? localBrowserUrl : browserUrl)(route.request().url());
|
|
308
|
+
const live = browserSessions.get(id)?.live;
|
|
309
|
+
// Do not evaluate the page while holding a navigation route: evaluation can
|
|
310
|
+
// wait for that very navigation. Fence capture, then let the request continue.
|
|
311
|
+
if (route.request().isNavigationRequest() && browserAuthPage(route.request().url()) && live && !live.private)
|
|
312
|
+
await live.pauseRecording(false);
|
|
301
313
|
return route.continue();
|
|
302
314
|
}
|
|
303
315
|
catch {
|
|
@@ -326,8 +338,17 @@ async function createSession(id, url, localOnly, width, height, signal, onNaviga
|
|
|
326
338
|
throw new Error('browser_local_network_guard_unavailable');
|
|
327
339
|
const session = { browser, context, page, localOnly, tabs: new Map(),
|
|
328
340
|
observations: new BrowserObservations(), control: { epoch: 0, mode: 'observe', private: false, connected: false },
|
|
329
|
-
...(profileLease ? { authProfile: profileLease, profileScopeId: browserProfileScopeId(authProfile.scope),
|
|
341
|
+
...(profileLease ? { authProfile: profileLease, profileScopeId: centralProfile?.id ?? browserProfileScopeId(authProfile.scope),
|
|
342
|
+
...(centralProfile ? { centralProfile: { id: centralProfile.id, name: centralProfile.name } } : { profileScope: authProfile.scope }) } : {}),
|
|
330
343
|
lastUsedAt: Date.now(), active: false, networkAccessExpiresAt: null };
|
|
344
|
+
if (recording) {
|
|
345
|
+
session.owner = { actorUserId: recording.options.actorUserId, threadId: recording.options.threadId,
|
|
346
|
+
workspaceId: recording.options.agentTerminalWorkspaceId, workspace: fs.realpathSync(recording.options.profileOwner.workspace) };
|
|
347
|
+
session.workspace = session.owner.workspace;
|
|
348
|
+
session.policyGrantRevision = recording.policyGrantRevision;
|
|
349
|
+
setNetworkLease(id, session, recording.networkAccessExpiresAt);
|
|
350
|
+
browserSessions.set(id, session);
|
|
351
|
+
}
|
|
331
352
|
registerTab(session, page);
|
|
332
353
|
context.on('page', opened => {
|
|
333
354
|
if (session.snapshotting)
|
|
@@ -340,6 +361,10 @@ async function createSession(id, url, localOnly, width, height, signal, onNaviga
|
|
|
340
361
|
session.page = opened;
|
|
341
362
|
await opened.waitForLoadState('domcontentloaded', { timeout: 5_000 }).catch(() => undefined);
|
|
342
363
|
}).catch(() => undefined);
|
|
364
|
+
if (recording)
|
|
365
|
+
await attachBrowserLive({ ...recording.options, sessionOwned: true });
|
|
366
|
+
if (browserAuthPage(url))
|
|
367
|
+
await session.live?.pauseRecording();
|
|
343
368
|
onNavigationAttempt?.();
|
|
344
369
|
await page.goto(url, { waitUntil: 'domcontentloaded', timeout: actionTimeoutMs ?? 30_000 });
|
|
345
370
|
(localOnly ? localBrowserUrl : browserUrl)(page.url());
|
|
@@ -351,13 +376,20 @@ async function createSession(id, url, localOnly, width, height, signal, onNaviga
|
|
|
351
376
|
}
|
|
352
377
|
if (epoch !== sessionEpoch)
|
|
353
378
|
throw new Error('browser_session_closed');
|
|
379
|
+
// Reading the lease also checks expiry after slow navigation/context construction.
|
|
380
|
+
if (centralProfile)
|
|
381
|
+
void profileLease.state;
|
|
354
382
|
browserSessions.set(id, session);
|
|
355
383
|
startIdleCleanup();
|
|
356
384
|
return session;
|
|
357
385
|
}
|
|
358
386
|
catch (error) {
|
|
359
|
-
|
|
360
|
-
|
|
387
|
+
if (browserSessions.get(id)?.browser === browser)
|
|
388
|
+
await closeSession(id);
|
|
389
|
+
else {
|
|
390
|
+
await browser.close().catch(() => undefined);
|
|
391
|
+
await profileLease?.release();
|
|
392
|
+
}
|
|
361
393
|
throw error;
|
|
362
394
|
}
|
|
363
395
|
finally {
|
|
@@ -377,7 +409,7 @@ function registerTab(session, page) {
|
|
|
377
409
|
page.on('framenavigated', frame => {
|
|
378
410
|
session.observations.invalidate();
|
|
379
411
|
if (frame === page.mainFrame() && browserAuthPage(page.url()))
|
|
380
|
-
void session.live?.pauseRecording();
|
|
412
|
+
void session.live?.pauseRecording().catch(() => session.live?.block());
|
|
381
413
|
});
|
|
382
414
|
session.observations.invalidate();
|
|
383
415
|
page.on('close', () => {
|
|
@@ -398,13 +430,14 @@ async function describeSession(id, session, sessionCreated) {
|
|
|
398
430
|
continue;
|
|
399
431
|
const rawUrl = page.url();
|
|
400
432
|
tabs.push({ id: tabId, title: (await page.title().catch(() => '')).slice(0, 200),
|
|
401
|
-
url: rawUrl === 'about:blank' ? rawUrl : safePageUrl(rawUrl), active: session?.page === page });
|
|
433
|
+
url: rawUrl === 'about:blank' ? rawUrl : safePageUrl(rawUrl), popup: !!await page.opener(), active: session?.page === page });
|
|
402
434
|
}
|
|
403
435
|
const active = tabs.find(tab => tab.active);
|
|
404
436
|
return { browserSessionId: id, activeTabId: active?.id || null,
|
|
405
437
|
tabs, pageUrl: active?.url || '', sessionCreated,
|
|
406
438
|
...(active && session ? { browserObservation: session.observations.fresh(activePage(session), active.id) } : {}),
|
|
407
|
-
...(session?.
|
|
439
|
+
...(session?.centralProfile ? { browserProfile: { ...session.centralProfile, persistent: true, default: false } }
|
|
440
|
+
: session?.profileScope ? { browserProfile: { id: session.profileScopeId, name: session.profileScope.name, persistent: true, default: false } } : {}) };
|
|
408
441
|
}
|
|
409
442
|
function activePage(session) {
|
|
410
443
|
if (!session.page.isClosed())
|
|
@@ -508,11 +541,26 @@ async function runForSession(input) {
|
|
|
508
541
|
throw new Error('browser_cancelled');
|
|
509
542
|
validateBrowserActionInput(input);
|
|
510
543
|
const url = input.localOnly && !['tabs', 'close', 'close_tab'].includes(input.action) ? localBrowserUrl(input.url) : browserUrl(input.url);
|
|
511
|
-
|
|
512
|
-
|
|
544
|
+
let width = input.width ?? existing?.page.viewportSize()?.width ?? input.recording?.options.browserSettings?.width ?? 1440;
|
|
545
|
+
let height = input.height ?? existing?.page.viewportSize()?.height ?? input.recording?.options.browserSettings?.height ?? 900;
|
|
513
546
|
let session = browserSessions.get(input.browserSessionId);
|
|
514
|
-
if (
|
|
547
|
+
if (input.centralProfile && (input.authProfile || input.resolveAuthProfile))
|
|
515
548
|
throw new Error('browser_profile_scope_changed');
|
|
549
|
+
if (session && !input.resolveAuthProfile && session.profileScopeId !== (input.centralProfile?.id ?? (input.authProfile ? browserProfileScopeId(input.authProfile.scope) : undefined)))
|
|
550
|
+
throw new Error('browser_profile_scope_changed');
|
|
551
|
+
if (session?.centralProfile && !['tabs', 'close', 'close_tab'].includes(input.action)
|
|
552
|
+
&& session.localOnly !== (input.localOnly === true)) {
|
|
553
|
+
// A new network boundary requires fresh navigation, never a replayed click/form action.
|
|
554
|
+
if (input.action !== 'navigate' || input.tabId)
|
|
555
|
+
throw new Error('browser_profile_navigation_required');
|
|
556
|
+
await checkpointSession(input.browserSessionId, session);
|
|
557
|
+
const viewport = session.page.viewportSize();
|
|
558
|
+
width = input.width ?? viewport?.width ?? width;
|
|
559
|
+
height = input.height ?? viewport?.height ?? height;
|
|
560
|
+
// The authorized central writer stays fenced to this session while Chromium is replaced.
|
|
561
|
+
await closeSession(input.browserSessionId, { retainProfileLease: true });
|
|
562
|
+
session = undefined;
|
|
563
|
+
}
|
|
516
564
|
if (session && (!['tabs', 'close', 'close_tab'].includes(input.action) && session.localOnly !== (input.localOnly === true) || !session.browser.isConnected()
|
|
517
565
|
|| session.context.pages().every(page => page.isClosed())
|
|
518
566
|
|| Date.now() - session.lastUsedAt >= BROWSER_SESSION_IDLE_MS)) {
|
|
@@ -534,7 +582,7 @@ async function runForSession(input) {
|
|
|
534
582
|
throw new Error('browser_session_missing');
|
|
535
583
|
const created = !session;
|
|
536
584
|
if (!session)
|
|
537
|
-
session = await createSession(input.browserSessionId, url, input.localOnly === true, width, height, input.signal, input.onActionAttempt, input.actionTimeoutMs, input.resolveAuthProfile ? await input.resolveAuthProfile() : input.authProfile);
|
|
585
|
+
session = await createSession(input.browserSessionId, url, input.localOnly === true, width, height, input.signal, input.onActionAttempt, input.actionTimeoutMs, input.resolveAuthProfile ? await input.resolveAuthProfile() : input.authProfile, input.centralProfile, input.recording);
|
|
538
586
|
if (input.actorUserId && input.threadId) {
|
|
539
587
|
const owner = { actorUserId: input.actorUserId, threadId: input.threadId,
|
|
540
588
|
workspaceId: input.agentTerminalWorkspaceId, workspace: fs.realpathSync(input.workspace) };
|
|
@@ -560,6 +608,8 @@ async function runForSession(input) {
|
|
|
560
608
|
await closeSession(input.browserSessionId);
|
|
561
609
|
throw new Error('browser_cancelled');
|
|
562
610
|
}
|
|
611
|
+
if (input.recording && session.live?.sessionOwned)
|
|
612
|
+
session.live.refreshRecordingAuthority(input.recording.options);
|
|
563
613
|
const onAbort = () => { void closeSession(input.browserSessionId); };
|
|
564
614
|
input.signal?.addEventListener('abort', onAbort, { once: true });
|
|
565
615
|
session.active = true;
|
|
@@ -702,6 +752,7 @@ async function runForSession(input) {
|
|
|
702
752
|
const bodyText = (await domTarget.innerText({ timeout: input.actionTimeoutMs ?? 10_000 })).slice(0, 25_000);
|
|
703
753
|
const dom = (bodyText + await semanticControls(page)).slice(0, 40_000);
|
|
704
754
|
const pageUrl = safePageUrl(page.url());
|
|
755
|
+
await session.live?.resumeRecordingIfPublic();
|
|
705
756
|
const inventory = await describeSession(input.browserSessionId, session, created);
|
|
706
757
|
if (session.control.mode !== 'observe')
|
|
707
758
|
throw new Error('browser_human_control_active');
|
|
@@ -780,7 +831,9 @@ export async function runBrowserAction(input) {
|
|
|
780
831
|
const task = previous.catch(() => undefined).then(() => runForSession(input));
|
|
781
832
|
sessionQueues.set(input.browserSessionId, task);
|
|
782
833
|
try {
|
|
783
|
-
|
|
834
|
+
const result = await task;
|
|
835
|
+
return input.networkAccessOnce ? { ...result, tabs: [], activeTabId: null, sessionCreated: false,
|
|
836
|
+
browserObservation: undefined, screenshotTransform: undefined } : result;
|
|
784
837
|
}
|
|
785
838
|
finally {
|
|
786
839
|
if (sessionQueues.get(input.browserSessionId) === task)
|
|
@@ -872,9 +925,6 @@ export async function attachBrowserLive(options) {
|
|
|
872
925
|
|| !options.isAuthorized() || !session.browser.isConnected())
|
|
873
926
|
throw new Error('browser_live_scope_invalid');
|
|
874
927
|
const previous = session.live;
|
|
875
|
-
previous?.disconnect();
|
|
876
|
-
if (previous)
|
|
877
|
-
await previous.settled();
|
|
878
928
|
if (options.initialControl && options.initialControl.controlEpoch >= session.control.epoch) {
|
|
879
929
|
session.control.epoch = options.initialControl.controlEpoch;
|
|
880
930
|
if (options.initialControl.mode !== 'observe') {
|
|
@@ -883,6 +933,16 @@ export async function attachBrowserLive(options) {
|
|
|
883
933
|
}
|
|
884
934
|
// A reconnect never auto-releases an existing local human/blocked fence.
|
|
885
935
|
}
|
|
936
|
+
if (previous?.sessionOwned) {
|
|
937
|
+
previous.attachViewer(options);
|
|
938
|
+
if (options.initialControl?.mode && options.initialControl.mode !== 'observe')
|
|
939
|
+
await previous.pauseRecording();
|
|
940
|
+
await previous.start();
|
|
941
|
+
return previous;
|
|
942
|
+
}
|
|
943
|
+
previous?.disconnect();
|
|
944
|
+
if (previous)
|
|
945
|
+
await previous.settled();
|
|
886
946
|
const authorized = () => browserSessions.get(options.browserSessionId) === session && session.browser.isConnected()
|
|
887
947
|
&& (session.networkAccessExpiresAt === null || session.networkAccessExpiresAt > Date.now());
|
|
888
948
|
const handle = new BrowserLiveHandle(options, {
|
|
@@ -919,7 +979,10 @@ export async function attachBrowserLive(options) {
|
|
|
919
979
|
sessionQueues.delete(options.browserSessionId);
|
|
920
980
|
}
|
|
921
981
|
},
|
|
922
|
-
state: async () =>
|
|
982
|
+
state: async () => {
|
|
983
|
+
const focusId = await describeFocusedField(activePage(session));
|
|
984
|
+
return { ...await describeSession(options.browserSessionId, session, false), focusEditable: !!focusId, focusId };
|
|
985
|
+
},
|
|
923
986
|
selectTab: async (tabId) => {
|
|
924
987
|
const page = session.tabs.get(tabId);
|
|
925
988
|
if (!page || page.isClosed())
|
|
@@ -938,6 +1001,8 @@ export async function attachBrowserLive(options) {
|
|
|
938
1001
|
await checkpointSession(options.browserSessionId, session);
|
|
939
1002
|
},
|
|
940
1003
|
profile: async (choice, liveOptions) => {
|
|
1004
|
+
if (session.centralProfile)
|
|
1005
|
+
throw new Error('browser_profile_new_session_required');
|
|
941
1006
|
const preferences = liveOptions.profilePreferences;
|
|
942
1007
|
const owner = liveOptions.profileOwner;
|
|
943
1008
|
if (!preferences || !owner || owner.actorUserId !== session.owner.actorUserId
|
|
@@ -961,12 +1026,12 @@ export async function attachBrowserLive(options) {
|
|
|
961
1026
|
let next = same ? session.authProfile : (resolved ? await resolved.store.openAsync(resolved.scope) : undefined);
|
|
962
1027
|
if (!authorized() || !options.isAuthorized()) {
|
|
963
1028
|
if (next && next !== session.authProfile)
|
|
964
|
-
next.release();
|
|
1029
|
+
await next.release();
|
|
965
1030
|
throw new Error('browser_live_scope_expired');
|
|
966
1031
|
}
|
|
967
1032
|
if (choice.reset && resolved) {
|
|
968
1033
|
if (same) {
|
|
969
|
-
session.authProfile?.release();
|
|
1034
|
+
await session.authProfile?.release();
|
|
970
1035
|
session.authProfile = undefined;
|
|
971
1036
|
}
|
|
972
1037
|
else
|
|
@@ -985,7 +1050,7 @@ export async function attachBrowserLive(options) {
|
|
|
985
1050
|
if (saveCurrent) {
|
|
986
1051
|
session.snapshotting = true;
|
|
987
1052
|
try {
|
|
988
|
-
next.save(await session.context.storageState({ indexedDB: true }));
|
|
1053
|
+
await next.save(await session.context.storageState({ indexedDB: true }));
|
|
989
1054
|
}
|
|
990
1055
|
finally {
|
|
991
1056
|
session.snapshotting = false;
|
|
@@ -997,7 +1062,7 @@ export async function attachBrowserLive(options) {
|
|
|
997
1062
|
else
|
|
998
1063
|
await session.context.setStorageState(next?.state || { cookies: [], origins: [] });
|
|
999
1064
|
if (!same || choice.reset) {
|
|
1000
|
-
session.authProfile?.release();
|
|
1065
|
+
await session.authProfile?.release();
|
|
1001
1066
|
session.authProfile = next;
|
|
1002
1067
|
session.profileScope = resolved?.scope;
|
|
1003
1068
|
session.profileScopeId = resolved ? browserProfileScopeId(resolved.scope) : undefined;
|
|
@@ -1011,7 +1076,7 @@ export async function attachBrowserLive(options) {
|
|
|
1011
1076
|
}
|
|
1012
1077
|
catch (error) {
|
|
1013
1078
|
if (next && next !== session.authProfile)
|
|
1014
|
-
next.release();
|
|
1079
|
+
await next.release();
|
|
1015
1080
|
throw error;
|
|
1016
1081
|
}
|
|
1017
1082
|
},
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
type DescriptorErrors = {
|
|
3
|
+
unverifiable: string;
|
|
4
|
+
outside: string;
|
|
5
|
+
notRegular: string;
|
|
6
|
+
};
|
|
7
|
+
/** canonicalWorkspaceRoot is captured before open; do not re-resolve a mutable workspace path here. */
|
|
8
|
+
export declare function verifyWorkspaceFileDescriptor(canonicalWorkspaceRoot: string, fd: number, errors: DescriptorErrors): fs.Stats;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
|
+
/** Resolve the opened inode, never a path that can be substituted after validation. */
|
|
5
|
+
function openedFilePath(fd, unverifiable) {
|
|
6
|
+
if (process.platform === 'linux') {
|
|
7
|
+
try {
|
|
8
|
+
return fs.readlinkSync(`/proc/self/fd/${fd}`);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
throw new Error(unverifiable);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
if (process.platform === 'darwin') {
|
|
15
|
+
const result = spawnSync('/usr/sbin/lsof', ['-a', '-p', String(process.pid), '-d', String(fd), '-F0n'], { encoding: 'utf8', timeout: 5_000, maxBuffer: 64_000 });
|
|
16
|
+
if (result.error || result.status !== 0 || typeof result.stdout !== 'string')
|
|
17
|
+
throw new Error(unverifiable);
|
|
18
|
+
const fields = result.stdout.split('\0').map(field => field.replace(/^\n/u, ''));
|
|
19
|
+
if (!fields.includes(`p${process.pid}`) || !fields.includes(`f${fd}`))
|
|
20
|
+
throw new Error(unverifiable);
|
|
21
|
+
const names = fields.filter(field => field.startsWith('n')).map(field => field.slice(1));
|
|
22
|
+
if (names.length !== 1)
|
|
23
|
+
throw new Error(unverifiable);
|
|
24
|
+
return names[0];
|
|
25
|
+
}
|
|
26
|
+
throw new Error(unverifiable);
|
|
27
|
+
}
|
|
28
|
+
/** canonicalWorkspaceRoot is captured before open; do not re-resolve a mutable workspace path here. */
|
|
29
|
+
export function verifyWorkspaceFileDescriptor(canonicalWorkspaceRoot, fd, errors) {
|
|
30
|
+
const stat = fs.fstatSync(fd);
|
|
31
|
+
const openedPath = openedFilePath(fd, errors.unverifiable);
|
|
32
|
+
const relative = path.relative(canonicalWorkspaceRoot, openedPath);
|
|
33
|
+
if (!path.isAbsolute(openedPath) || !relative || relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
|
|
34
|
+
throw new Error(errors.outside);
|
|
35
|
+
}
|
|
36
|
+
if (!stat.isFile())
|
|
37
|
+
throw new Error(errors.notRegular);
|
|
38
|
+
return stat;
|
|
39
|
+
}
|
|
@@ -3,6 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
import https from 'node:https';
|
|
4
4
|
import { randomUUID } from 'node:crypto';
|
|
5
5
|
import { pipeline } from 'node:stream/promises';
|
|
6
|
+
import { verifyWorkspaceFileDescriptor } from "./terminal-file-descriptor.js";
|
|
6
7
|
const HEADERS = new Set(['content-type', 'content-length', 'content-range', 'range', 'if-match', 'if-none-match',
|
|
7
8
|
'x-goog-if-generation-match', 'x-goog-if-metageneration-match']);
|
|
8
9
|
/** URLs and headers are credentials. Never include them in errors or operational logs. */
|
|
@@ -69,8 +70,9 @@ export async function transferWorkspaceFile(workspace, operation, transfer, sign
|
|
|
69
70
|
if (operation === 'upload_file') {
|
|
70
71
|
const file = await fs.promises.open(target, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW);
|
|
71
72
|
try {
|
|
72
|
-
const stat =
|
|
73
|
-
|
|
73
|
+
const stat = verifyWorkspaceFileDescriptor(root, file.fd, { unverifiable: 'file_transfer_path_unverifiable',
|
|
74
|
+
outside: 'file_transfer_outside_workspace', notRegular: 'file_transfer_not_regular' });
|
|
75
|
+
if (!Number.isSafeInteger(stat.size))
|
|
74
76
|
throw new Error('file_transfer_not_regular');
|
|
75
77
|
const resumable = new URL(transfer.url).searchParams.has('upload_id');
|
|
76
78
|
let offset = transfer.offset ?? 0;
|
|
@@ -126,6 +128,18 @@ export async function transferWorkspaceFile(workspace, operation, transfer, sign
|
|
|
126
128
|
if (transfer.offset !== null || transfer.length !== null || headers.range)
|
|
127
129
|
throw new Error('file_download_range_not_supported');
|
|
128
130
|
const temporary = path.join(parent, `.revo-transfer-${randomUUID()}.part`);
|
|
131
|
+
const parentIdentity = await fs.promises.stat(parent);
|
|
132
|
+
let file;
|
|
133
|
+
let temporaryIdentity;
|
|
134
|
+
const unchangedParent = () => {
|
|
135
|
+
try {
|
|
136
|
+
const current = fs.lstatSync(parent);
|
|
137
|
+
return current.isDirectory() && current.dev === parentIdentity.dev && current.ino === parentIdentity.ino;
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
129
143
|
try {
|
|
130
144
|
const existing = await fs.promises.lstat(target).catch(error => {
|
|
131
145
|
if (error.code === 'ENOENT')
|
|
@@ -134,16 +148,27 @@ export async function transferWorkspaceFile(workspace, operation, transfer, sign
|
|
|
134
148
|
});
|
|
135
149
|
if (existing && (!transfer.overwrite || !existing.isFile() || existing.isSymbolicLink()))
|
|
136
150
|
throw new Error('file_transfer_target_exists');
|
|
151
|
+
file = await fs.promises.open(temporary, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_NOFOLLOW, 0o600);
|
|
152
|
+
temporaryIdentity = verifyWorkspaceFileDescriptor(root, file.fd, { unverifiable: 'file_transfer_path_unverifiable',
|
|
153
|
+
outside: 'file_transfer_outside_workspace', notRegular: 'file_transfer_not_regular' });
|
|
154
|
+
if (!unchangedParent())
|
|
155
|
+
throw new Error('file_transfer_outside_workspace');
|
|
137
156
|
const response = await request(transfer.url, 'GET', headers, signal);
|
|
138
157
|
if (response.statusCode !== 200) {
|
|
139
158
|
drain(response);
|
|
140
159
|
throw transferError(response.statusCode);
|
|
141
160
|
}
|
|
142
|
-
await pipeline(response, fs.createWriteStream(temporary, {
|
|
143
|
-
const stat = await
|
|
161
|
+
await pipeline(response, fs.createWriteStream(temporary, { fd: file.fd, autoClose: false, emitClose: false }), { signal });
|
|
162
|
+
const stat = await file.stat();
|
|
144
163
|
if (response.headers['content-length'] !== undefined && Number(response.headers['content-length']) !== stat.size)
|
|
145
164
|
throw new Error('file_transfer_incomplete');
|
|
146
|
-
|
|
165
|
+
verifyWorkspaceFileDescriptor(root, file.fd, { unverifiable: 'file_transfer_path_unverifiable',
|
|
166
|
+
outside: 'file_transfer_outside_workspace', notRegular: 'file_transfer_not_regular' });
|
|
167
|
+
if (!unchangedParent())
|
|
168
|
+
throw new Error('file_transfer_outside_workspace');
|
|
169
|
+
const temporaryPathIdentity = await fs.promises.lstat(temporary).catch(() => { throw new Error('file_transfer_outside_workspace'); });
|
|
170
|
+
if (!unchangedParent() || !temporaryPathIdentity.isFile()
|
|
171
|
+
|| temporaryPathIdentity.dev !== stat.dev || temporaryPathIdentity.ino !== stat.ino)
|
|
147
172
|
throw new Error('file_transfer_outside_workspace');
|
|
148
173
|
if (transfer.overwrite)
|
|
149
174
|
await fs.promises.rename(temporary, target);
|
|
@@ -155,6 +180,16 @@ export async function transferWorkspaceFile(workspace, operation, transfer, sign
|
|
|
155
180
|
...(typeof response.headers.etag === 'string' ? { etag: response.headers.etag } : {}) };
|
|
156
181
|
}
|
|
157
182
|
finally {
|
|
158
|
-
|
|
183
|
+
// A substituted directory must never turn cleanup into deletion of a
|
|
184
|
+
// different file. A displaced temporary is retained rather than guessed.
|
|
185
|
+
if (temporaryIdentity && unchangedParent()) {
|
|
186
|
+
try {
|
|
187
|
+
const current = fs.lstatSync(temporary);
|
|
188
|
+
if (current.isFile() && current.dev === temporaryIdentity.dev && current.ino === temporaryIdentity.ino)
|
|
189
|
+
fs.unlinkSync(temporary);
|
|
190
|
+
}
|
|
191
|
+
catch { /* already committed or namespace changed */ }
|
|
192
|
+
}
|
|
193
|
+
await file?.close();
|
|
159
194
|
}
|
|
160
195
|
}
|
|
@@ -1,42 +1,14 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { verifyWorkspaceFileDescriptor } from "./terminal-file-descriptor.js";
|
|
4
4
|
const MAX_IMAGE_BYTES = 30 * 1024 * 1024;
|
|
5
5
|
const MAX_IMAGE_BATCH_BYTES = 240 * 1024 * 1024;
|
|
6
|
-
/** Resolve the file actually held by an open descriptor, never the mutable input path. */
|
|
7
|
-
function openedFilePath(fd) {
|
|
8
|
-
if (process.platform === 'linux') {
|
|
9
|
-
try {
|
|
10
|
-
return fs.readlinkSync(`/proc/self/fd/${fd}`);
|
|
11
|
-
}
|
|
12
|
-
catch {
|
|
13
|
-
throw new Error('image_path_unverifiable');
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
if (process.platform === 'darwin') {
|
|
17
|
-
const result = spawnSync('/usr/sbin/lsof', ['-a', '-p', String(process.pid), '-d', String(fd), '-F0n'], { encoding: 'utf8', timeout: 5_000, maxBuffer: 64_000 });
|
|
18
|
-
if (result.error || result.status !== 0 || typeof result.stdout !== 'string')
|
|
19
|
-
throw new Error('image_path_unverifiable');
|
|
20
|
-
const fields = result.stdout.split('\0').map(field => field.replace(/^\n/u, ''));
|
|
21
|
-
if (!fields.includes(`p${process.pid}`) || !fields.includes(`f${fd}`))
|
|
22
|
-
throw new Error('image_path_unverifiable');
|
|
23
|
-
const names = fields.filter(field => field.startsWith('n')).map(field => field.slice(1));
|
|
24
|
-
if (names.length !== 1)
|
|
25
|
-
throw new Error('image_path_unverifiable');
|
|
26
|
-
return names[0];
|
|
27
|
-
}
|
|
28
|
-
throw new Error('image_path_unverifiable');
|
|
29
|
-
}
|
|
30
6
|
function readWorkspaceImage(workspace, file) {
|
|
31
7
|
const root = fs.realpathSync(workspace);
|
|
32
8
|
const fd = fs.openSync(file, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW);
|
|
33
9
|
try {
|
|
34
|
-
const stat =
|
|
35
|
-
|
|
36
|
-
const relative = path.relative(root, openedPath);
|
|
37
|
-
if (!path.isAbsolute(openedPath) || !relative || relative.startsWith('..')
|
|
38
|
-
|| path.isAbsolute(relative) || !stat.isFile())
|
|
39
|
-
throw new Error('image_outside_workspace');
|
|
10
|
+
const stat = verifyWorkspaceFileDescriptor(root, fd, { unverifiable: 'image_path_unverifiable',
|
|
11
|
+
outside: 'image_outside_workspace', notRegular: 'image_outside_workspace' });
|
|
40
12
|
if (stat.size < 1 || stat.size > MAX_IMAGE_BYTES)
|
|
41
13
|
throw new Error('image_size_invalid');
|
|
42
14
|
const data = Buffer.allocUnsafe(stat.size);
|
|
@@ -3,14 +3,31 @@ export type TerminalOutputChunk = {
|
|
|
3
3
|
stream: 'stdout' | 'stderr';
|
|
4
4
|
text: string;
|
|
5
5
|
};
|
|
6
|
-
|
|
6
|
+
export declare const TERMINAL_CAPTURE_MAX_BYTES = 1000000000;
|
|
7
|
+
export declare const TERMINAL_CAPTURE_MAX_CHUNKS = 1000000;
|
|
8
|
+
/** Private, process-local replay spool. Only a committed server ACK prunes its index. */
|
|
7
9
|
export declare class TerminalOutputBuffer {
|
|
8
10
|
private readonly chunks;
|
|
9
11
|
private sequence;
|
|
10
12
|
private acknowledged;
|
|
13
|
+
private sentThrough;
|
|
14
|
+
private inFlightBytes;
|
|
15
|
+
private bytes;
|
|
16
|
+
private directory?;
|
|
17
|
+
private fd?;
|
|
18
|
+
private disposed;
|
|
19
|
+
private readonly options;
|
|
20
|
+
constructor(options?: {
|
|
21
|
+
spool?: boolean;
|
|
22
|
+
});
|
|
11
23
|
get lastSequence(): number;
|
|
12
24
|
get lastAcknowledged(): number;
|
|
13
25
|
append(stream: TerminalOutputChunk['stream'], text: string): TerminalOutputChunk;
|
|
14
26
|
acknowledge(sequence: unknown): boolean;
|
|
27
|
+
private read;
|
|
15
28
|
pending(): readonly TerminalOutputChunk[];
|
|
29
|
+
private page;
|
|
30
|
+
takeUnsent(): readonly TerminalOutputChunk[];
|
|
31
|
+
resetTransport(): void;
|
|
32
|
+
dispose(): void;
|
|
16
33
|
}
|