@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
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type KeyObject } from 'node:crypto';
|
|
2
|
+
import { BrowserProfileRunnerRpc } from './terminal-browser-profile-sync.ts';
|
|
3
|
+
import { LegacyBrowserProfileImporter } from './terminal-browser-profile-import.ts';
|
|
4
|
+
import { type BrowserProfileImportRequest, type BrowserProfileImportReply } from './terminal-browser-profile-import.protocol.ts';
|
|
5
|
+
type Options = {
|
|
6
|
+
connectionId: string;
|
|
7
|
+
instanceId: string;
|
|
8
|
+
terminalId: string;
|
|
9
|
+
keyId: string;
|
|
10
|
+
privateKey: KeyObject;
|
|
11
|
+
baseUrl: string;
|
|
12
|
+
importer: LegacyBrowserProfileImporter;
|
|
13
|
+
rpc: BrowserProfileRunnerRpc;
|
|
14
|
+
authorized(frame: BrowserProfileImportRequest): boolean;
|
|
15
|
+
send(reply: BrowserProfileImportReply): void;
|
|
16
|
+
};
|
|
17
|
+
/** Runs outside the ordinary command queue, so private renewal/readback replies cannot deadlock import. */
|
|
18
|
+
export declare class BrowserProfileImportRunner {
|
|
19
|
+
private readonly options;
|
|
20
|
+
private readonly entries;
|
|
21
|
+
private closed;
|
|
22
|
+
constructor(options: Options);
|
|
23
|
+
accept(value: unknown): void;
|
|
24
|
+
private run;
|
|
25
|
+
private send;
|
|
26
|
+
acceptAck(value: unknown): void;
|
|
27
|
+
revokeProfile(profileId: string): void;
|
|
28
|
+
private finish;
|
|
29
|
+
dispose(): void;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { CentralBrowserProfileLease } from "./terminal-browser-central-profile.js";
|
|
4
|
+
import { browserProfileImportError, validBrowserProfileImportRequest } from "./terminal-browser-profile-import.protocol.js";
|
|
5
|
+
/** Runs outside the ordinary command queue, so private renewal/readback replies cannot deadlock import. */
|
|
6
|
+
export class BrowserProfileImportRunner {
|
|
7
|
+
options;
|
|
8
|
+
entries = new Map();
|
|
9
|
+
closed = false;
|
|
10
|
+
constructor(options) { this.options = options; }
|
|
11
|
+
accept(value) {
|
|
12
|
+
if (this.closed || !validBrowserProfileImportRequest(value))
|
|
13
|
+
return;
|
|
14
|
+
const frame = value;
|
|
15
|
+
if (frame.connectionId !== this.options.connectionId || frame.instanceId !== this.options.instanceId
|
|
16
|
+
|| frame.scope.agentTerminalId !== this.options.terminalId || frame.scope.keyId !== this.options.keyId)
|
|
17
|
+
return;
|
|
18
|
+
const signature = createHash('sha256').update(JSON.stringify(frame)).digest('hex');
|
|
19
|
+
const existing = this.entries.get(frame.requestId);
|
|
20
|
+
if (existing) {
|
|
21
|
+
if (existing.signature === signature && existing.reply)
|
|
22
|
+
this.send(existing.reply, existing);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
for (const [id, entry] of this.entries)
|
|
26
|
+
if (entry.reply && !entry.lease && Date.now() - entry.createdAt > 600_000)
|
|
27
|
+
this.entries.delete(id);
|
|
28
|
+
if (this.entries.size >= 64) {
|
|
29
|
+
try {
|
|
30
|
+
this.options.send({ type: 'browser_profile_import_result', requestId: frame.requestId,
|
|
31
|
+
connectionId: this.options.connectionId, ok: false, error: 'browser_profile_import_busy' });
|
|
32
|
+
}
|
|
33
|
+
catch { /* Socket teardown owns cleanup. */ }
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const entry = { signature, createdAt: Date.now(), controller: new AbortController(), profileId: frame.grant?.profile.id };
|
|
37
|
+
this.entries.set(frame.requestId, entry);
|
|
38
|
+
void this.run(frame, entry);
|
|
39
|
+
}
|
|
40
|
+
async run(frame, entry) {
|
|
41
|
+
const signal = AbortSignal.any([entry.controller.signal, AbortSignal.timeout(frame.remainingMs)]);
|
|
42
|
+
const allowed = () => !this.closed && !signal.aborted && this.options.authorized(frame);
|
|
43
|
+
const assertAllowed = () => { if (!allowed())
|
|
44
|
+
throw new Error('browser_profile_access_denied'); };
|
|
45
|
+
try {
|
|
46
|
+
assertAllowed();
|
|
47
|
+
const workspace = fs.realpathSync(frame.workspace);
|
|
48
|
+
if (workspace !== frame.workspace)
|
|
49
|
+
throw new Error('browser_profile_access_denied');
|
|
50
|
+
const owner = { baseUrl: this.options.baseUrl, instanceId: this.options.instanceId,
|
|
51
|
+
actorUserId: frame.scope.actorUserId, terminalId: this.options.terminalId, workspace };
|
|
52
|
+
if (frame.operation === 'catalog') {
|
|
53
|
+
const profiles = await this.options.importer.catalog(owner);
|
|
54
|
+
assertAllowed();
|
|
55
|
+
entry.reply = { type: 'browser_profile_import_result', requestId: frame.requestId,
|
|
56
|
+
connectionId: this.options.connectionId, ok: true, profiles };
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const grant = frame.grant;
|
|
60
|
+
entry.lease = await CentralBrowserProfileLease.open(grant, this.options.privateKey, this.options.rpc.transport(grant), () => entry.controller.abort());
|
|
61
|
+
const result = await this.options.importer.importProfile(owner, frame.localProfileId, entry.lease, { signal, isAuthorized: allowed, removeLocalCopy: frame.removeLocalCopy === true });
|
|
62
|
+
assertAllowed();
|
|
63
|
+
entry.reply = { type: 'browser_profile_import_result', requestId: frame.requestId,
|
|
64
|
+
connectionId: this.options.connectionId, ok: true, result };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
await entry.lease?.release();
|
|
69
|
+
entry.lease = undefined;
|
|
70
|
+
entry.reply = { type: 'browser_profile_import_result', requestId: frame.requestId,
|
|
71
|
+
connectionId: this.options.connectionId, ok: false, error: browserProfileImportError(error) };
|
|
72
|
+
}
|
|
73
|
+
if (!this.closed)
|
|
74
|
+
this.send(entry.reply, entry);
|
|
75
|
+
}
|
|
76
|
+
send(reply, entry) {
|
|
77
|
+
try {
|
|
78
|
+
this.options.send(reply);
|
|
79
|
+
if (!entry.ackTimeout) {
|
|
80
|
+
entry.ackTimeout = setTimeout(() => this.finish(entry), 10_000);
|
|
81
|
+
entry.ackTimeout.unref();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
this.finish(entry);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
acceptAck(value) {
|
|
89
|
+
const frame = value;
|
|
90
|
+
if (!frame || frame.type !== 'browser_profile_import_ack' || frame.connectionId !== this.options.connectionId
|
|
91
|
+
|| typeof frame.ok !== 'boolean' || typeof frame.requestId !== 'string')
|
|
92
|
+
return;
|
|
93
|
+
const entry = this.entries.get(frame.requestId);
|
|
94
|
+
if (entry?.reply)
|
|
95
|
+
this.finish(entry);
|
|
96
|
+
}
|
|
97
|
+
revokeProfile(profileId) {
|
|
98
|
+
for (const entry of this.entries.values())
|
|
99
|
+
if (entry.profileId === profileId)
|
|
100
|
+
this.finish(entry);
|
|
101
|
+
}
|
|
102
|
+
finish(entry) {
|
|
103
|
+
if (entry.ackTimeout)
|
|
104
|
+
clearTimeout(entry.ackTimeout);
|
|
105
|
+
entry.ackTimeout = undefined;
|
|
106
|
+
entry.controller.abort();
|
|
107
|
+
void entry.lease?.release();
|
|
108
|
+
entry.lease = undefined;
|
|
109
|
+
}
|
|
110
|
+
dispose() { this.closed = true; for (const entry of this.entries.values())
|
|
111
|
+
this.finish(entry); }
|
|
112
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CentralBrowserProfileLease } from './terminal-browser-central-profile.ts';
|
|
2
|
+
import { BrowserAuthProfileStore, type BrowserProfileState } from './terminal-browser-profile.ts';
|
|
3
|
+
import { type BrowserProfileOwner } from './terminal-browser-profile-preferences.ts';
|
|
4
|
+
import { type BrowserProfileImportResult } from './terminal-browser-profile-import.protocol.ts';
|
|
5
|
+
type Restore = (state: BrowserProfileState, signal: AbortSignal) => Promise<BrowserProfileState>;
|
|
6
|
+
type ImportOptions = {
|
|
7
|
+
removeLocalCopy: boolean;
|
|
8
|
+
signal: AbortSignal;
|
|
9
|
+
isAuthorized(): boolean;
|
|
10
|
+
};
|
|
11
|
+
/** Local legacy keys are touched only after a human migration request, never during connect. */
|
|
12
|
+
export declare class LegacyBrowserProfileImporter {
|
|
13
|
+
private store?;
|
|
14
|
+
private importing;
|
|
15
|
+
private readonly available;
|
|
16
|
+
private readonly createStore;
|
|
17
|
+
private readonly restore;
|
|
18
|
+
constructor(available: boolean, createStore: () => BrowserAuthProfileStore, restore?: Restore);
|
|
19
|
+
private localStore;
|
|
20
|
+
catalog(owner: BrowserProfileOwner): Promise<Array<{
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
}>>;
|
|
24
|
+
importProfile(owner: BrowserProfileOwner, localProfileId: string, target: CentralBrowserProfileLease, options: ImportOptions): Promise<BrowserProfileImportResult>;
|
|
25
|
+
}
|
|
26
|
+
/** Reconstruct only browser state. Origin navigations are intercepted; no website receives imported cookies. */
|
|
27
|
+
export declare function restoreBrowserProfileForImport(state: BrowserProfileState, signal: AbortSignal): Promise<BrowserProfileState>;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { BrowserProfilePreferences } from "./terminal-browser-profile-preferences.js";
|
|
2
|
+
import { browserProfileImportError } from "./terminal-browser-profile-import.protocol.js";
|
|
3
|
+
/** Local legacy keys are touched only after a human migration request, never during connect. */
|
|
4
|
+
export class LegacyBrowserProfileImporter {
|
|
5
|
+
store;
|
|
6
|
+
importing = false;
|
|
7
|
+
available;
|
|
8
|
+
createStore;
|
|
9
|
+
restore;
|
|
10
|
+
constructor(available, createStore, restore = restoreBrowserProfileForImport) {
|
|
11
|
+
this.available = available;
|
|
12
|
+
this.createStore = createStore;
|
|
13
|
+
this.restore = restore;
|
|
14
|
+
}
|
|
15
|
+
localStore() {
|
|
16
|
+
if (!this.available)
|
|
17
|
+
throw new Error('browser_profile_import_unavailable');
|
|
18
|
+
return this.store ??= this.createStore();
|
|
19
|
+
}
|
|
20
|
+
async catalog(owner) {
|
|
21
|
+
const store = this.localStore();
|
|
22
|
+
return (await new BrowserProfilePreferences(store).allChoicesAsync(owner))
|
|
23
|
+
.filter(choice => choice.persistent && store.has({ ...owner, name: choice.name }))
|
|
24
|
+
.map(({ id, name }) => ({ id, name }));
|
|
25
|
+
}
|
|
26
|
+
async importProfile(owner, localProfileId, target, options) {
|
|
27
|
+
if (this.importing)
|
|
28
|
+
throw new Error('browser_profile_import_busy');
|
|
29
|
+
this.importing = true;
|
|
30
|
+
const authorized = () => {
|
|
31
|
+
if (options.signal.aborted || !options.isAuthorized())
|
|
32
|
+
throw new Error('browser_profile_access_denied');
|
|
33
|
+
};
|
|
34
|
+
try {
|
|
35
|
+
authorized();
|
|
36
|
+
if (!/^[a-f\d]{64}$/u.test(localProfileId) || target.currentRevision !== 0 || target.state !== undefined)
|
|
37
|
+
throw new Error('browser_profile_import_target_changed');
|
|
38
|
+
const selected = (await this.catalog(owner)).find(choice => choice.id === localProfileId);
|
|
39
|
+
if (!selected)
|
|
40
|
+
throw new Error('browser_profile_import_source_unavailable');
|
|
41
|
+
authorized();
|
|
42
|
+
const store = this.localStore();
|
|
43
|
+
const source = await store.openAsync({ ...owner, name: selected.name });
|
|
44
|
+
try {
|
|
45
|
+
authorized();
|
|
46
|
+
if (!source.state)
|
|
47
|
+
throw new Error('browser_profile_import_source_unavailable');
|
|
48
|
+
const portable = await this.restore(source.state, options.signal);
|
|
49
|
+
authorized();
|
|
50
|
+
await target.save(portable);
|
|
51
|
+
const cloud = await target.verifySavedState();
|
|
52
|
+
authorized();
|
|
53
|
+
const restored = await this.restore(cloud, options.signal);
|
|
54
|
+
authorized();
|
|
55
|
+
if (canonicalState(restored) !== canonicalState(portable))
|
|
56
|
+
throw new Error('browser_profile_import_restore_failed');
|
|
57
|
+
let localCopy = 'retained';
|
|
58
|
+
if (options.removeLocalCopy) {
|
|
59
|
+
try {
|
|
60
|
+
await source.forget();
|
|
61
|
+
await new BrowserProfilePreferences(store).removeAsync(owner, selected.name);
|
|
62
|
+
localCopy = 'removed';
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
localCopy = 'cleanup_unconfirmed';
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return { revision: target.currentRevision, localCopy };
|
|
69
|
+
}
|
|
70
|
+
finally {
|
|
71
|
+
source.release();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
throw new Error(browserProfileImportError(error));
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
this.importing = false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** Reconstruct only browser state. Origin navigations are intercepted; no website receives imported cookies. */
|
|
83
|
+
export async function restoreBrowserProfileForImport(state, signal) {
|
|
84
|
+
const bounded = AbortSignal.any([signal, AbortSignal.timeout(15_000)]);
|
|
85
|
+
bounded.throwIfAborted();
|
|
86
|
+
const { chromium } = await import('playwright-core');
|
|
87
|
+
const browser = await chromium.launch({ channel: 'chromium', headless: true, timeout: 15_000,
|
|
88
|
+
args: ['--disable-background-networking'] });
|
|
89
|
+
const abort = () => { void browser.close(); };
|
|
90
|
+
bounded.addEventListener('abort', abort, { once: true });
|
|
91
|
+
let context;
|
|
92
|
+
try {
|
|
93
|
+
bounded.throwIfAborted();
|
|
94
|
+
context = await browser.newContext({ acceptDownloads: false, serviceWorkers: 'block' });
|
|
95
|
+
await context.route('**/*', route => route.abort('blockedbyclient'));
|
|
96
|
+
await context.setStorageState(state);
|
|
97
|
+
const restored = await context.storageState({ indexedDB: true });
|
|
98
|
+
bounded.throwIfAborted();
|
|
99
|
+
return restored;
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
bounded.removeEventListener('abort', abort);
|
|
103
|
+
await browser.close();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Sort semantic collections while preserving order inside IndexedDB record values and key paths.
|
|
107
|
+
function canonicalState(state) {
|
|
108
|
+
const collections = {
|
|
109
|
+
state: { cookies: 'plain', origins: 'origin' }, origin: { localStorage: 'plain', indexedDB: 'database' },
|
|
110
|
+
database: { stores: 'store' }, store: { indexes: 'plain', records: 'plain' },
|
|
111
|
+
};
|
|
112
|
+
const normalize = (value, kind = 'plain') => {
|
|
113
|
+
if (Array.isArray(value))
|
|
114
|
+
return value.map(item => normalize(item));
|
|
115
|
+
if (!value || typeof value !== 'object')
|
|
116
|
+
return value;
|
|
117
|
+
return Object.fromEntries(Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([key, item]) => {
|
|
118
|
+
const child = collections[kind]?.[key];
|
|
119
|
+
return [key, child && Array.isArray(item)
|
|
120
|
+
? item.map(entry => normalize(entry, child)).sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)))
|
|
121
|
+
: normalize(item)];
|
|
122
|
+
}));
|
|
123
|
+
};
|
|
124
|
+
return JSON.stringify(normalize(state, 'state'));
|
|
125
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { BrowserProfileRunnerGrant } from './terminal-browser-profile-sync.protocol.ts';
|
|
2
|
+
export type BrowserProfileImportScope = {
|
|
3
|
+
actorUserId: string;
|
|
4
|
+
assistantThreadId: string;
|
|
5
|
+
agentTerminalId: string;
|
|
6
|
+
agentTerminalWorkspaceId: string;
|
|
7
|
+
connectionId: string;
|
|
8
|
+
keyId: string;
|
|
9
|
+
};
|
|
10
|
+
export type LegacyBrowserProfileMetadata = {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
};
|
|
14
|
+
export type BrowserProfileImportResult = {
|
|
15
|
+
revision: number;
|
|
16
|
+
localCopy: 'retained' | 'removed' | 'cleanup_unconfirmed';
|
|
17
|
+
};
|
|
18
|
+
export type BrowserProfileImportRequest = {
|
|
19
|
+
type: 'browser_profile_import';
|
|
20
|
+
requestId: string;
|
|
21
|
+
connectionId: string;
|
|
22
|
+
instanceId: string;
|
|
23
|
+
operation: 'catalog' | 'import';
|
|
24
|
+
scope: BrowserProfileImportScope;
|
|
25
|
+
workspace: string;
|
|
26
|
+
grantRevision: number;
|
|
27
|
+
remainingMs: number;
|
|
28
|
+
localProfileId?: string;
|
|
29
|
+
removeLocalCopy?: boolean;
|
|
30
|
+
grant?: BrowserProfileRunnerGrant;
|
|
31
|
+
};
|
|
32
|
+
export type BrowserProfileImportReply = {
|
|
33
|
+
type: 'browser_profile_import_result';
|
|
34
|
+
requestId: string;
|
|
35
|
+
connectionId: string;
|
|
36
|
+
ok: boolean;
|
|
37
|
+
error?: string;
|
|
38
|
+
profiles?: LegacyBrowserProfileMetadata[];
|
|
39
|
+
result?: BrowserProfileImportResult;
|
|
40
|
+
};
|
|
41
|
+
export type BrowserProfileImportAck = {
|
|
42
|
+
type: 'browser_profile_import_ack';
|
|
43
|
+
requestId: string;
|
|
44
|
+
connectionId: string;
|
|
45
|
+
ok: boolean;
|
|
46
|
+
};
|
|
47
|
+
export declare const BROWSER_PROFILE_IMPORT_ERRORS: Set<string>;
|
|
48
|
+
export declare function browserProfileImportError(error: unknown): string;
|
|
49
|
+
export declare function validBrowserProfileImportRequest(value: unknown): value is BrowserProfileImportRequest;
|
|
50
|
+
export declare function validBrowserProfileImportReply(value: unknown): value is BrowserProfileImportReply;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export const BROWSER_PROFILE_IMPORT_ERRORS = new Set(['browser_profile_import_failed', 'browser_profile_import_unavailable',
|
|
2
|
+
'browser_profile_import_busy', 'browser_profile_import_source_unavailable', 'browser_profile_import_target_changed',
|
|
3
|
+
'browser_profile_import_restore_failed', 'browser_profile_access_denied', 'browser_profile_busy',
|
|
4
|
+
'browser_profile_session_limit', 'browser_profile_corrupt', 'browser_profile_keystore_unavailable',
|
|
5
|
+
'browser_profile_readback_failed', 'browser_profile_save_failed', 'browser_profile_lease_expired',
|
|
6
|
+
'browser_profile_sync_unavailable', 'browser_profile_state_unavailable']);
|
|
7
|
+
export function browserProfileImportError(error) {
|
|
8
|
+
const code = error instanceof Error ? error.message : typeof error === 'string' ? error : '';
|
|
9
|
+
return BROWSER_PROFILE_IMPORT_ERRORS.has(code) ? code : 'browser_profile_import_failed';
|
|
10
|
+
}
|
|
11
|
+
const UUID = /^[a-f\d]{8}-(?:[a-f\d]{4}-){3}[a-f\d]{12}$/iu;
|
|
12
|
+
const HEX = /^[a-f\d]{64}$/u;
|
|
13
|
+
const keys = (value, allowed) => Object.keys(value).every(key => allowed.includes(key));
|
|
14
|
+
export function validBrowserProfileImportRequest(value) {
|
|
15
|
+
const v = value;
|
|
16
|
+
if (!v || v.type !== 'browser_profile_import' || !UUID.test(v.requestId) || !UUID.test(v.connectionId)
|
|
17
|
+
|| !['catalog', 'import'].includes(v.operation) || typeof v.instanceId !== 'string' || !v.instanceId || v.instanceId.length > 256
|
|
18
|
+
|| !Number.isSafeInteger(v.grantRevision) || v.grantRevision < 0 || !Number.isSafeInteger(v.remainingMs) || v.remainingMs < 1 || v.remainingMs > 180_000
|
|
19
|
+
|| typeof v.workspace !== 'string' || !v.workspace.startsWith('/') || v.workspace.length > 8192 || /[\u0000-\u001f]/u.test(v.workspace))
|
|
20
|
+
return false;
|
|
21
|
+
const s = v.scope;
|
|
22
|
+
if (!s || ![s.actorUserId, s.assistantThreadId, s.agentTerminalId, s.agentTerminalWorkspaceId, s.connectionId].every(id => UUID.test(id))
|
|
23
|
+
|| !HEX.test(s.keyId) || s.connectionId !== v.connectionId
|
|
24
|
+
|| !keys(s, ['actorUserId', 'assistantThreadId', 'agentTerminalId', 'agentTerminalWorkspaceId', 'connectionId', 'keyId']))
|
|
25
|
+
return false;
|
|
26
|
+
const common = ['type', 'requestId', 'connectionId', 'instanceId', 'operation', 'scope', 'workspace', 'grantRevision', 'remainingMs'];
|
|
27
|
+
if (v.operation === 'catalog')
|
|
28
|
+
return keys(v, common);
|
|
29
|
+
const grant = v.grant;
|
|
30
|
+
return keys(v, [...common, 'localProfileId', 'removeLocalCopy', 'grant']) && HEX.test(v.localProfileId)
|
|
31
|
+
&& typeof v.removeLocalCopy === 'boolean' && !!grant && UUID.test(grant.profile?.id)
|
|
32
|
+
&& grant.scope?.instanceId === v.instanceId && grant.scope.browserProfileId === grant.profile.id
|
|
33
|
+
&& HEX.test(grant.scope.browserSessionId) && grant.revision === 0 && grant.download === null
|
|
34
|
+
&& Object.entries(s).every(([key, entry]) => grant.scope[key] === entry);
|
|
35
|
+
}
|
|
36
|
+
export function validBrowserProfileImportReply(value) {
|
|
37
|
+
const v = value;
|
|
38
|
+
if (!v || v.type !== 'browser_profile_import_result' || !UUID.test(v.requestId) || !UUID.test(v.connectionId)
|
|
39
|
+
|| typeof v.ok !== 'boolean')
|
|
40
|
+
return false;
|
|
41
|
+
const common = ['type', 'requestId', 'connectionId', 'ok'];
|
|
42
|
+
if (!v.ok)
|
|
43
|
+
return keys(v, [...common, 'error']) && BROWSER_PROFILE_IMPORT_ERRORS.has(v.error);
|
|
44
|
+
if (v.profiles)
|
|
45
|
+
return keys(v, [...common, 'profiles']) && Array.isArray(v.profiles) && v.profiles.length <= 128
|
|
46
|
+
&& new Set(v.profiles.map(profile => profile?.id)).size === v.profiles.length
|
|
47
|
+
&& v.profiles.every(profile => !!profile && keys(profile, ['id', 'name']) && HEX.test(profile.id)
|
|
48
|
+
&& typeof profile.name === 'string' && /^[a-z0-9][a-z0-9 ._-]{0,63}$/iu.test(profile.name));
|
|
49
|
+
return keys(v, [...common, 'result']) && !!v.result && keys(v.result, ['revision', 'localCopy'])
|
|
50
|
+
&& Number.isSafeInteger(v.result.revision) && v.result.revision > 0 && v.result.revision < 2147483647
|
|
51
|
+
&& ['retained', 'removed', 'cleanup_unconfirmed'].includes(v.result.localCopy);
|
|
52
|
+
}
|
|
@@ -18,6 +18,7 @@ export declare class BrowserProfilePreferences {
|
|
|
18
18
|
private read;
|
|
19
19
|
private readAsync;
|
|
20
20
|
remove(owner: BrowserProfileOwner, name: string): void;
|
|
21
|
+
removeAsync(owner: BrowserProfileOwner, name: string): Promise<void>;
|
|
21
22
|
validName(name: string): string;
|
|
22
23
|
private resolved;
|
|
23
24
|
resolve(owner: BrowserProfileOwner, explicit?: string): ReturnType<BrowserProfilePreferences['resolved']>;
|
|
@@ -54,6 +54,22 @@ export class BrowserProfilePreferences {
|
|
|
54
54
|
lease.release();
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
+
async removeAsync(owner, name) {
|
|
58
|
+
this.validName(name);
|
|
59
|
+
if (!this.store.has(this.scope(owner)))
|
|
60
|
+
return;
|
|
61
|
+
const lease = await this.store.openAsync(this.scope(owner));
|
|
62
|
+
try {
|
|
63
|
+
const previous = this.parse(lease);
|
|
64
|
+
const profileCatalog = { names: previous.names.filter(value => value !== name),
|
|
65
|
+
...(previous.defaultName && previous.defaultName !== name ? { defaultName: previous.defaultName } : {}) };
|
|
66
|
+
const state = { cookies: [], origins: [], profileCatalog };
|
|
67
|
+
lease.save(state);
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
lease.release();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
57
73
|
validName(name) {
|
|
58
74
|
if (name === INDEX_NAME)
|
|
59
75
|
throw new Error('browser_profile_name_invalid');
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { BrowserProfileRunnerGrant, BrowserProfileSyncRequest } from './terminal-browser-profile-sync.protocol.ts';
|
|
2
|
+
import type { CentralBrowserProfileTransport } from './terminal-browser-central-profile.ts';
|
|
3
|
+
/** Responses are consumed before the command queue, so a snapshot save cannot deadlock its own reply. */
|
|
4
|
+
export declare class BrowserProfileRunnerRpc {
|
|
5
|
+
private readonly connectionId;
|
|
6
|
+
private readonly send;
|
|
7
|
+
private readonly pending;
|
|
8
|
+
private closed;
|
|
9
|
+
constructor(connectionId: string, send: (request: BrowserProfileSyncRequest) => void);
|
|
10
|
+
accept(value: unknown): void;
|
|
11
|
+
private request;
|
|
12
|
+
transport(grant: BrowserProfileRunnerGrant): CentralBrowserProfileTransport;
|
|
13
|
+
dispose(): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { BROWSER_PROFILE_STATE_MAX_BYTES } from "./terminal-browser-profile-crypto.js";
|
|
3
|
+
const UUID = /^[a-f\d]{8}-(?:[a-f\d]{4}-){3}[a-f\d]{12}$/iu;
|
|
4
|
+
const errors = new Set(['browser_profile_access_denied', 'browser_profile_busy', 'browser_profile_session_limit',
|
|
5
|
+
'browser_profile_lease_expired', 'browser_profile_revision_conflict', 'browser_profile_upload_incomplete',
|
|
6
|
+
'browser_profile_state_unavailable', 'browser_profile_sync_busy']);
|
|
7
|
+
/** Responses are consumed before the command queue, so a snapshot save cannot deadlock its own reply. */
|
|
8
|
+
export class BrowserProfileRunnerRpc {
|
|
9
|
+
connectionId;
|
|
10
|
+
send;
|
|
11
|
+
pending = new Map();
|
|
12
|
+
closed = false;
|
|
13
|
+
constructor(connectionId, send) {
|
|
14
|
+
if (!UUID.test(connectionId))
|
|
15
|
+
throw new Error('browser_profile_sync_invalid');
|
|
16
|
+
this.connectionId = connectionId;
|
|
17
|
+
this.send = send;
|
|
18
|
+
}
|
|
19
|
+
accept(value) {
|
|
20
|
+
const frame = value;
|
|
21
|
+
if (!frame || frame.type !== 'browser_profile_sync_result' || frame.connectionId !== this.connectionId
|
|
22
|
+
|| typeof frame.requestId !== 'string' || typeof frame.ok !== 'boolean')
|
|
23
|
+
return;
|
|
24
|
+
const pending = this.pending.get(frame.requestId);
|
|
25
|
+
if (!pending)
|
|
26
|
+
return;
|
|
27
|
+
clearTimeout(pending.timer);
|
|
28
|
+
this.pending.delete(frame.requestId);
|
|
29
|
+
if (frame.ok)
|
|
30
|
+
pending.resolve(frame);
|
|
31
|
+
else
|
|
32
|
+
pending.reject(new Error(errors.has(frame.error || '') ? frame.error : 'browser_profile_sync_unavailable'));
|
|
33
|
+
}
|
|
34
|
+
request(browserSessionId, operation, body = {}) {
|
|
35
|
+
if (this.closed)
|
|
36
|
+
return Promise.reject(new Error('browser_profile_lease_expired'));
|
|
37
|
+
if (this.pending.size >= 32)
|
|
38
|
+
return Promise.reject(new Error('browser_profile_sync_busy'));
|
|
39
|
+
const request = { ...body, type: 'browser_profile_sync', connectionId: this.connectionId,
|
|
40
|
+
requestId: body.requestId || randomUUID(), browserSessionId, operation };
|
|
41
|
+
if (this.pending.has(request.requestId))
|
|
42
|
+
return Promise.reject(new Error('browser_profile_sync_busy'));
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
const timer = setTimeout(() => { this.pending.delete(request.requestId); reject(new Error('browser_profile_sync_timeout')); }, 10_000);
|
|
45
|
+
timer.unref();
|
|
46
|
+
this.pending.set(request.requestId, { resolve, reject, timer });
|
|
47
|
+
try {
|
|
48
|
+
this.send(request);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
this.pending.delete(request.requestId);
|
|
53
|
+
reject(new Error('browser_profile_sync_unavailable'));
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
transport(grant) {
|
|
58
|
+
if (grant.scope.connectionId !== this.connectionId)
|
|
59
|
+
throw new Error('browser_profile_lease_expired');
|
|
60
|
+
const browserSessionId = grant.scope.browserSessionId;
|
|
61
|
+
return {
|
|
62
|
+
read: async () => grant.download ? downloadProfile(grant.download) : null,
|
|
63
|
+
readback: async (expectedRevision) => {
|
|
64
|
+
const result = await this.request(browserSessionId, 'readback', { expectedRevision });
|
|
65
|
+
if (result.revision !== expectedRevision || result.keyVersion !== grant.scope.keyVersion || !result.download)
|
|
66
|
+
throw new Error('browser_profile_revision_conflict');
|
|
67
|
+
const ciphertext = await downloadProfile(result.download);
|
|
68
|
+
return { revision: expectedRevision, keyVersion: result.keyVersion, ciphertext, digest: result.download.digest };
|
|
69
|
+
},
|
|
70
|
+
save: async (input) => {
|
|
71
|
+
const provisioned = await this.request(browserSessionId, 'upload', { requestId: input.operationId,
|
|
72
|
+
expectedRevision: input.expectedRevision, size: input.ciphertext.length, digest: input.digest });
|
|
73
|
+
const target = provisioned.upload;
|
|
74
|
+
if (!target || !UUID.test(target.uploadId) || !['PUT', 'POST'].includes(target.method))
|
|
75
|
+
throw new Error('browser_profile_sync_invalid');
|
|
76
|
+
await uploadProfile(target, input.ciphertext);
|
|
77
|
+
const result = await this.request(browserSessionId, 'commit', { uploadId: target.uploadId });
|
|
78
|
+
if (!Number.isSafeInteger(result.revision) || result.revision !== input.expectedRevision + 1)
|
|
79
|
+
throw new Error('browser_profile_revision_conflict');
|
|
80
|
+
return { revision: result.revision };
|
|
81
|
+
},
|
|
82
|
+
renew: async () => {
|
|
83
|
+
const result = await this.request(browserSessionId, 'renew');
|
|
84
|
+
if (!Number.isSafeInteger(result.leaseRemainingMs) || result.leaseRemainingMs < 1 || result.leaseRemainingMs > 45_000)
|
|
85
|
+
throw new Error('browser_profile_sync_invalid');
|
|
86
|
+
return { leaseRemainingMs: result.leaseRemainingMs };
|
|
87
|
+
},
|
|
88
|
+
release: async () => { await this.request(browserSessionId, 'release'); },
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
dispose() {
|
|
92
|
+
this.closed = true;
|
|
93
|
+
for (const pending of this.pending.values()) {
|
|
94
|
+
clearTimeout(pending.timer);
|
|
95
|
+
pending.reject(new Error('browser_profile_lease_expired'));
|
|
96
|
+
}
|
|
97
|
+
this.pending.clear();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function transferUrl(value) {
|
|
101
|
+
try {
|
|
102
|
+
const url = new URL(value);
|
|
103
|
+
if (url.protocol !== 'https:' || url.hostname !== 'storage.googleapis.com' || url.port || url.username || url.password || url.hash)
|
|
104
|
+
throw new Error();
|
|
105
|
+
return url.toString();
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
throw new Error('browser_profile_transfer_invalid');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** Direct bounded ciphertext transfer intentionally bypasses the CLI API/HTTP trace and its auth headers. */
|
|
112
|
+
async function downloadProfile(source) {
|
|
113
|
+
if (!Number.isSafeInteger(source.size) || source.size < 28 || source.size > BROWSER_PROFILE_STATE_MAX_BYTES + 28)
|
|
114
|
+
throw new Error('browser_profile_transfer_invalid');
|
|
115
|
+
try {
|
|
116
|
+
const response = await fetch(transferUrl(source.url), { method: 'GET', credentials: 'omit', redirect: 'error', cache: 'no-store',
|
|
117
|
+
referrerPolicy: 'no-referrer', signal: AbortSignal.timeout(15_000) });
|
|
118
|
+
if (!response.ok || !response.body)
|
|
119
|
+
throw new Error();
|
|
120
|
+
const length = response.headers.get('content-length');
|
|
121
|
+
if (length !== null && Number(length) !== source.size) {
|
|
122
|
+
await response.body.cancel();
|
|
123
|
+
throw new Error();
|
|
124
|
+
}
|
|
125
|
+
const reader = response.body.getReader();
|
|
126
|
+
const chunks = [];
|
|
127
|
+
let size = 0;
|
|
128
|
+
try {
|
|
129
|
+
while (true) {
|
|
130
|
+
const part = await reader.read();
|
|
131
|
+
if (part.done)
|
|
132
|
+
break;
|
|
133
|
+
size += part.value.length;
|
|
134
|
+
if (size > source.size)
|
|
135
|
+
throw new Error();
|
|
136
|
+
chunks.push(Buffer.from(part.value));
|
|
137
|
+
}
|
|
138
|
+
if (size !== source.size)
|
|
139
|
+
throw new Error();
|
|
140
|
+
return Buffer.concat(chunks, size);
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
await reader.cancel().catch(() => undefined);
|
|
144
|
+
reader.releaseLock();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
throw new Error('browser_profile_transfer_failed');
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async function uploadProfile(target, ciphertext) {
|
|
152
|
+
if (ciphertext.length < 28 || ciphertext.length > BROWSER_PROFILE_STATE_MAX_BYTES + 28)
|
|
153
|
+
throw new Error('browser_profile_transfer_invalid');
|
|
154
|
+
const headers = { 'Content-Type': 'application/octet-stream' };
|
|
155
|
+
for (const [key, value] of Object.entries(target.headers || {})) {
|
|
156
|
+
if (key.toLowerCase() !== 'content-type' || value !== 'application/octet-stream')
|
|
157
|
+
throw new Error('browser_profile_transfer_invalid');
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
const response = await fetch(transferUrl(target.url), { method: target.method, headers, body: new Uint8Array(ciphertext),
|
|
161
|
+
credentials: 'omit', redirect: 'error', cache: 'no-store', referrerPolicy: 'no-referrer', signal: AbortSignal.timeout(30_000) });
|
|
162
|
+
await response.body?.cancel();
|
|
163
|
+
if (!response.ok)
|
|
164
|
+
throw new Error();
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
throw new Error('browser_profile_transfer_failed');
|
|
168
|
+
}
|
|
169
|
+
}
|