@agentconnect.md/computer 2.12.0-rc.13 → 2.12.0-rc.15
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/dist/agentconnect-computer.mjs +2183 -2099
- package/package.json +1 -1
|
@@ -67280,2131 +67280,2157 @@ var StdioServerTransport = class {
|
|
|
67280
67280
|
}
|
|
67281
67281
|
};
|
|
67282
67282
|
|
|
67283
|
-
// src/
|
|
67284
|
-
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
67285
|
-
import { spawn } from "node:child_process";
|
|
67286
|
-
import { createInterface } from "node:readline";
|
|
67287
|
-
var ANSWER_TIMEOUT_MS = 1e4;
|
|
67288
|
-
var RESTART_MS = 5e3;
|
|
67289
|
-
var str = (value) => typeof value === "string" && value !== "" ? value : void 0;
|
|
67290
|
-
var AdminPromptHelper = class _AdminPromptHelper {
|
|
67291
|
-
constructor(path, options) {
|
|
67292
|
-
this.path = path;
|
|
67293
|
-
this.options = options;
|
|
67294
|
-
}
|
|
67295
|
-
path;
|
|
67296
|
-
options;
|
|
67297
|
-
problem;
|
|
67298
|
-
current;
|
|
67299
|
-
child;
|
|
67300
|
-
closed = false;
|
|
67301
|
-
waiting = /* @__PURE__ */ new Map();
|
|
67302
|
-
static start(path, options) {
|
|
67303
|
-
const helper = new _AdminPromptHelper(path, options);
|
|
67304
|
-
helper.spawn();
|
|
67305
|
-
return helper;
|
|
67306
|
-
}
|
|
67307
|
-
pending() {
|
|
67308
|
-
return this.current;
|
|
67309
|
-
}
|
|
67310
|
-
answer(id, answer) {
|
|
67311
|
-
const child2 = this.child;
|
|
67312
|
-
if (!child2?.stdin || this.problem)
|
|
67313
|
-
return Promise.reject(new Error(this.problem ?? "the prompt helper is not running"));
|
|
67314
|
-
return new Promise((resolve5, reject) => {
|
|
67315
|
-
const timer = setTimeout(() => {
|
|
67316
|
-
this.waiting.delete(id);
|
|
67317
|
-
reject(new Error("the prompt helper did not answer in time"));
|
|
67318
|
-
}, ANSWER_TIMEOUT_MS);
|
|
67319
|
-
timer.unref();
|
|
67320
|
-
this.waiting.set(id, {
|
|
67321
|
-
resolve: () => (clearTimeout(timer), resolve5()),
|
|
67322
|
-
reject: (error63) => (clearTimeout(timer), reject(error63))
|
|
67323
|
-
});
|
|
67324
|
-
child2.stdin.write(`${JSON.stringify({ id, answer })}
|
|
67325
|
-
`);
|
|
67326
|
-
});
|
|
67327
|
-
}
|
|
67328
|
-
close() {
|
|
67329
|
-
this.closed = true;
|
|
67330
|
-
this.child?.stdin?.end();
|
|
67331
|
-
}
|
|
67332
|
-
spawn() {
|
|
67333
|
-
const child2 = (this.options.spawnHelper ?? ((file2) => spawn(file2, [], { stdio: ["pipe", "pipe", "inherit"], windowsHide: true })))(this.path);
|
|
67334
|
-
this.child = child2;
|
|
67335
|
-
child2.stdin?.on("error", () => void 0);
|
|
67336
|
-
child2.on("error", (error63) => this.gone(`cannot start the administrator prompt helper: ${error63.message}`));
|
|
67337
|
-
child2.on(
|
|
67338
|
-
"exit",
|
|
67339
|
-
(code, signal) => this.gone(`the administrator prompt helper exited (${signal ?? `code ${code}`})`)
|
|
67340
|
-
);
|
|
67341
|
-
if (child2.stdout) createInterface({ input: child2.stdout }).on("line", (line) => this.received(line));
|
|
67342
|
-
}
|
|
67343
|
-
received(line) {
|
|
67344
|
-
let message;
|
|
67345
|
-
try {
|
|
67346
|
-
message = JSON.parse(line);
|
|
67347
|
-
} catch {
|
|
67348
|
-
return;
|
|
67349
|
-
}
|
|
67350
|
-
const id = str(message.id);
|
|
67351
|
-
switch (message.event) {
|
|
67352
|
-
case "prompt": {
|
|
67353
|
-
if (!id) return;
|
|
67354
|
-
this.current = {
|
|
67355
|
-
id,
|
|
67356
|
-
kind: message.kind === "credentials" ? "credentials" : "consent",
|
|
67357
|
-
...str(message.app) ? { app: str(message.app) } : {},
|
|
67358
|
-
...str(message.publisher) ? { publisher: str(message.publisher) } : {},
|
|
67359
|
-
...str(message.command) ? { command: str(message.command) } : {},
|
|
67360
|
-
lines: Array.isArray(message.lines) ? message.lines.filter((l) => typeof l === "string") : []
|
|
67361
|
-
};
|
|
67362
|
-
this.options.log(`administrator prompt: ${this.current.app ?? "an app"} asks to run as administrator`);
|
|
67363
|
-
return this.options.onChange();
|
|
67364
|
-
}
|
|
67365
|
-
case "gone":
|
|
67366
|
-
if (id && this.current?.id === id) {
|
|
67367
|
-
this.current = void 0;
|
|
67368
|
-
this.options.onChange();
|
|
67369
|
-
}
|
|
67370
|
-
return;
|
|
67371
|
-
case "answered": {
|
|
67372
|
-
const waiter = id ? this.waiting.get(id) : void 0;
|
|
67373
|
-
if (!waiter || !id) return;
|
|
67374
|
-
this.waiting.delete(id);
|
|
67375
|
-
if (message.ok === true) waiter.resolve();
|
|
67376
|
-
else waiter.reject(new Error(str(message.error) ?? "the prompt could not be answered"));
|
|
67377
|
-
return;
|
|
67378
|
-
}
|
|
67379
|
-
case "problem": {
|
|
67380
|
-
const problem = str(message.message);
|
|
67381
|
-
if (problem === this.problem) return;
|
|
67382
|
-
this.problem = problem;
|
|
67383
|
-
if (problem) this.options.log(`administrator prompts: ${problem}`);
|
|
67384
|
-
return this.options.onChange();
|
|
67385
|
-
}
|
|
67386
|
-
}
|
|
67387
|
-
}
|
|
67388
|
-
gone(problem) {
|
|
67389
|
-
if (this.closed) return;
|
|
67390
|
-
this.problem = problem;
|
|
67391
|
-
this.current = void 0;
|
|
67392
|
-
for (const waiter of this.waiting.values()) waiter.reject(new Error(problem));
|
|
67393
|
-
this.waiting.clear();
|
|
67394
|
-
this.options.log(`administrator prompts: ${problem}; starting it again`);
|
|
67395
|
-
this.options.onChange();
|
|
67396
|
-
const child2 = this.child;
|
|
67397
|
-
this.child = void 0;
|
|
67398
|
-
if (child2)
|
|
67399
|
-
setTimeout(() => {
|
|
67400
|
-
if (this.closed) return;
|
|
67401
|
-
this.problem = void 0;
|
|
67402
|
-
this.spawn();
|
|
67403
|
-
}, this.options.restartMs ?? RESTART_MS).unref();
|
|
67404
|
-
}
|
|
67405
|
-
};
|
|
67406
|
-
|
|
67407
|
-
// src/audit.ts
|
|
67283
|
+
// ../protocol/src/frames/computer.ts
|
|
67408
67284
|
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
67409
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
67410
|
-
import { appendFileSync, mkdirSync } from "node:fs";
|
|
67411
|
-
import { dirname } from "node:path";
|
|
67412
|
-
var callContext = new AsyncLocalStorage();
|
|
67413
|
-
var withCallContext = (context, fn) => callContext.run(context, fn);
|
|
67414
|
-
var currentCallContext = () => callContext.getStore() ?? {};
|
|
67415
|
-
function auditSinks(...sinks) {
|
|
67416
|
-
return (record2) => {
|
|
67417
|
-
const full = { ...callContext.getStore(), ...record2 };
|
|
67418
|
-
for (const sink of sinks) sink(full);
|
|
67419
|
-
};
|
|
67420
|
-
}
|
|
67421
|
-
function redactArgs(args) {
|
|
67422
|
-
const out = {};
|
|
67423
|
-
for (const [key, value] of Object.entries(args)) {
|
|
67424
|
-
out[key] = (key === "text" || key === "value" || key === "content") && typeof value === "string" ? `<${value.length} chars>` : value;
|
|
67425
|
-
}
|
|
67426
|
-
return out;
|
|
67427
|
-
}
|
|
67428
|
-
function fileAuditSink(path) {
|
|
67429
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
67430
|
-
return (record2) => {
|
|
67431
|
-
const line = JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), ...record2, args: redactArgs(record2.args) });
|
|
67432
|
-
try {
|
|
67433
|
-
appendFileSync(path, `${line}
|
|
67434
|
-
`);
|
|
67435
|
-
} catch (error63) {
|
|
67436
|
-
console.error(`audit write failed: ${error63.message}`);
|
|
67437
|
-
}
|
|
67438
|
-
};
|
|
67439
|
-
}
|
|
67440
67285
|
|
|
67441
|
-
//
|
|
67286
|
+
// ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/index.js
|
|
67442
67287
|
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
67443
67288
|
|
|
67444
|
-
// src/
|
|
67289
|
+
// ../protocol/src/envelope.ts
|
|
67445
67290
|
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
67291
|
+
var Envelope = external_exports.object({
|
|
67292
|
+
v: external_exports.literal(1),
|
|
67293
|
+
// protocol major; bump = breaking
|
|
67294
|
+
id: external_exports.string().uuid(),
|
|
67295
|
+
// unique per frame (sender-generated)
|
|
67296
|
+
ts: external_exports.string().datetime(),
|
|
67297
|
+
// RFC3339, sender clock (advisory only)
|
|
67298
|
+
type: external_exports.string(),
|
|
67299
|
+
// frame discriminator, e.g. "register"
|
|
67300
|
+
corr: external_exports.string().uuid().optional(),
|
|
67301
|
+
// correlation: set on a reply to the request's `id`
|
|
67302
|
+
orgId: external_exports.string().min(1).max(64).optional(),
|
|
67303
|
+
// tenant context on an install-wide daemon connection
|
|
67304
|
+
payload: external_exports.unknown()
|
|
67305
|
+
// validated by the per-type schema
|
|
67306
|
+
});
|
|
67307
|
+
var ControlExt = external_exports.object({
|
|
67308
|
+
epoch: external_exports.number().int(),
|
|
67309
|
+
// sessionEpoch this frame was issued under (§3.1 fencing)
|
|
67310
|
+
agentId: external_exports.string().uuid().optional(),
|
|
67311
|
+
// present on agent-scoped frames
|
|
67312
|
+
launchId: external_exports.string().uuid().optional()
|
|
67313
|
+
// per-launch fence, §4.4
|
|
67314
|
+
});
|
|
67315
|
+
var NIL_UUID = "00000000-0000-0000-0000-000000000000";
|
|
67316
|
+
function frameSchema(type, payload) {
|
|
67317
|
+
return external_exports.object({
|
|
67318
|
+
v: external_exports.literal(1),
|
|
67319
|
+
id: external_exports.string().uuid(),
|
|
67320
|
+
ts: external_exports.string().datetime(),
|
|
67321
|
+
type: external_exports.literal(type),
|
|
67322
|
+
corr: external_exports.string().uuid().optional(),
|
|
67323
|
+
orgId: external_exports.string().min(1).max(64).optional(),
|
|
67324
|
+
payload
|
|
67325
|
+
});
|
|
67326
|
+
}
|
|
67446
67327
|
|
|
67447
|
-
// src/
|
|
67328
|
+
// ../protocol/src/tolerant.ts
|
|
67448
67329
|
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
67449
|
-
|
|
67450
|
-
|
|
67451
|
-
|
|
67452
|
-
|
|
67453
|
-
|
|
67454
|
-
|
|
67455
|
-
|
|
67456
|
-
const host = match[1] ?? "";
|
|
67457
|
-
const number4 = Number(match[2]);
|
|
67458
|
-
if (host === "" || host === "unix") return { path: `/tmp/.X11-unix/X${number4}`, number: number4 };
|
|
67459
|
-
return { host, port: 6e3 + number4, number: number4 };
|
|
67330
|
+
var memo3 = /* @__PURE__ */ new WeakMap();
|
|
67331
|
+
function tolerantReader(schema) {
|
|
67332
|
+
const hit = memo3.get(schema);
|
|
67333
|
+
if (hit) return hit;
|
|
67334
|
+
const built = rebuild(schema);
|
|
67335
|
+
memo3.set(schema, built);
|
|
67336
|
+
return built;
|
|
67460
67337
|
}
|
|
67461
|
-
|
|
67462
|
-
|
|
67463
|
-
var COOKIE = "MIT-MAGIC-COOKIE-1";
|
|
67464
|
-
function xauthCookie(file2, number4, host = hostname3()) {
|
|
67465
|
-
let offset = 0;
|
|
67466
|
-
let fallback;
|
|
67467
|
-
const field = () => {
|
|
67468
|
-
const length = file2.readUInt16BE(offset);
|
|
67469
|
-
const value = file2.subarray(offset + 2, offset + 2 + length);
|
|
67470
|
-
offset += 2 + length;
|
|
67471
|
-
return value;
|
|
67472
|
-
};
|
|
67473
|
-
try {
|
|
67474
|
-
while (offset < file2.length) {
|
|
67475
|
-
const family = file2.readUInt16BE(offset);
|
|
67476
|
-
offset += 2;
|
|
67477
|
-
const address = field().toString("latin1");
|
|
67478
|
-
const display = field().toString("latin1");
|
|
67479
|
-
const name = field().toString("latin1");
|
|
67480
|
-
const data = field();
|
|
67481
|
-
if (name !== COOKIE || display !== "" && display !== String(number4)) continue;
|
|
67482
|
-
if (family === FAMILY_WILD || family === FAMILY_LOCAL && address === host) return Buffer.from(data);
|
|
67483
|
-
fallback ??= Buffer.from(data);
|
|
67484
|
-
}
|
|
67485
|
-
} catch {
|
|
67486
|
-
}
|
|
67487
|
-
return fallback;
|
|
67338
|
+
function tolerantSchemas(schemas) {
|
|
67339
|
+
return Object.fromEntries(Object.entries(schemas).map(([type, schema]) => [type, tolerantReader(schema)]));
|
|
67488
67340
|
}
|
|
67489
|
-
|
|
67490
|
-
|
|
67491
|
-
|
|
67492
|
-
|
|
67493
|
-
|
|
67494
|
-
|
|
67495
|
-
|
|
67496
|
-
|
|
67497
|
-
|
|
67498
|
-
|
|
67499
|
-
|
|
67500
|
-
|
|
67501
|
-
|
|
67502
|
-
|
|
67503
|
-
|
|
67504
|
-
|
|
67505
|
-
|
|
67506
|
-
|
|
67507
|
-
|
|
67508
|
-
|
|
67509
|
-
|
|
67510
|
-
buffer = Buffer.alloc(0);
|
|
67511
|
-
sequence = 0;
|
|
67512
|
-
pending = /* @__PURE__ */ new Map();
|
|
67513
|
-
errors = /* @__PURE__ */ new Map();
|
|
67514
|
-
closed = false;
|
|
67515
|
-
onEvent = () => void 0;
|
|
67516
|
-
onClose = () => void 0;
|
|
67517
|
-
static async connect(options = {}) {
|
|
67518
|
-
const address = parseDisplay(options.display ?? process.env.DISPLAY);
|
|
67519
|
-
if (!address) throw new Error("DISPLAY is not set to an X11 display");
|
|
67520
|
-
const authFile = options.xauthority ?? process.env.XAUTHORITY ?? join(homedir(), ".Xauthority");
|
|
67521
|
-
let cookie;
|
|
67522
|
-
try {
|
|
67523
|
-
cookie = xauthCookie(readFileSync(authFile), address.number);
|
|
67524
|
-
} catch {
|
|
67341
|
+
function isSchema(value) {
|
|
67342
|
+
return typeof value === "object" && value !== null && "_zod" in value;
|
|
67343
|
+
}
|
|
67344
|
+
function defOf(schema) {
|
|
67345
|
+
return schema._zod.def;
|
|
67346
|
+
}
|
|
67347
|
+
function child(value) {
|
|
67348
|
+
return tolerantReader(value);
|
|
67349
|
+
}
|
|
67350
|
+
function withDef(schema, def) {
|
|
67351
|
+
return external_exports.clone(schema, def);
|
|
67352
|
+
}
|
|
67353
|
+
function rebuild(schema) {
|
|
67354
|
+
const def = defOf(schema);
|
|
67355
|
+
switch (def.type) {
|
|
67356
|
+
case "object": {
|
|
67357
|
+
const shape = Object.fromEntries(
|
|
67358
|
+
Object.entries(def.shape).map(([key, value]) => [key, child(value)])
|
|
67359
|
+
);
|
|
67360
|
+
const catchall = isNeverSchema(def.catchall) ? void 0 : def.catchall ? child(def.catchall) : void 0;
|
|
67361
|
+
return withDef(schema, { ...def, shape, catchall });
|
|
67525
67362
|
}
|
|
67526
|
-
|
|
67527
|
-
|
|
67528
|
-
|
|
67529
|
-
|
|
67530
|
-
|
|
67531
|
-
|
|
67532
|
-
|
|
67533
|
-
|
|
67534
|
-
|
|
67535
|
-
|
|
67536
|
-
|
|
67537
|
-
|
|
67538
|
-
|
|
67539
|
-
|
|
67540
|
-
|
|
67541
|
-
|
|
67542
|
-
|
|
67543
|
-
|
|
67544
|
-
|
|
67545
|
-
|
|
67546
|
-
|
|
67547
|
-
|
|
67548
|
-
|
|
67549
|
-
|
|
67550
|
-
|
|
67551
|
-
|
|
67552
|
-
|
|
67553
|
-
|
|
67554
|
-
|
|
67555
|
-
|
|
67556
|
-
|
|
67557
|
-
|
|
67558
|
-
|
|
67559
|
-
socket.write(setupRequest(cookie));
|
|
67560
|
-
});
|
|
67561
|
-
const connection = new _X11Connection(socket, setup2.setup);
|
|
67562
|
-
if (setup2.rest.length) connection.receive(setup2.rest);
|
|
67563
|
-
return connection;
|
|
67564
|
-
}
|
|
67565
|
-
listen(listener) {
|
|
67566
|
-
this.onEvent = listener;
|
|
67567
|
-
}
|
|
67568
|
-
whenClosed(listener) {
|
|
67569
|
-
this.onClose = listener;
|
|
67570
|
-
}
|
|
67571
|
-
/** Sends a request that has a reply and resolves with the whole reply. */
|
|
67572
|
-
request(body) {
|
|
67573
|
-
if (this.closed) return Promise.reject(new Error("X11 connection closed"));
|
|
67574
|
-
const sequence = this.send(body);
|
|
67575
|
-
return new Promise((resolve5, reject) => this.pending.set(sequence, { resolve: resolve5, reject }));
|
|
67363
|
+
case "array":
|
|
67364
|
+
return withDef(schema, { ...def, element: child(def.element) });
|
|
67365
|
+
// Both plain and discriminated unions; the discriminator rides along in the spread def.
|
|
67366
|
+
case "union":
|
|
67367
|
+
return withDef(schema, { ...def, options: def.options.map(child) });
|
|
67368
|
+
case "intersection":
|
|
67369
|
+
return withDef(schema, { ...def, left: child(def.left), right: child(def.right) });
|
|
67370
|
+
case "tuple":
|
|
67371
|
+
return withDef(schema, {
|
|
67372
|
+
...def,
|
|
67373
|
+
items: def.items.map(child),
|
|
67374
|
+
...isSchema(def.rest) ? { rest: child(def.rest) } : {}
|
|
67375
|
+
});
|
|
67376
|
+
case "record":
|
|
67377
|
+
case "map":
|
|
67378
|
+
return withDef(schema, { ...def, keyType: child(def.keyType), valueType: child(def.valueType) });
|
|
67379
|
+
case "set":
|
|
67380
|
+
return withDef(schema, { ...def, valueType: child(def.valueType) });
|
|
67381
|
+
case "optional":
|
|
67382
|
+
case "nullable":
|
|
67383
|
+
case "nonoptional":
|
|
67384
|
+
case "default":
|
|
67385
|
+
case "prefault":
|
|
67386
|
+
case "catch":
|
|
67387
|
+
case "readonly":
|
|
67388
|
+
case "promise":
|
|
67389
|
+
return withDef(schema, { ...def, innerType: child(def.innerType) });
|
|
67390
|
+
case "pipe":
|
|
67391
|
+
return withDef(schema, { ...def, in: child(def.in), out: child(def.out) });
|
|
67392
|
+
case "lazy":
|
|
67393
|
+
return external_exports.lazy(() => child(def.getter()));
|
|
67394
|
+
default:
|
|
67395
|
+
return schema;
|
|
67576
67396
|
}
|
|
67577
|
-
|
|
67578
|
-
|
|
67579
|
-
|
|
67580
|
-
|
|
67581
|
-
|
|
67582
|
-
|
|
67583
|
-
|
|
67397
|
+
}
|
|
67398
|
+
function isNeverSchema(value) {
|
|
67399
|
+
return isSchema(value) && defOf(value).type === "never";
|
|
67400
|
+
}
|
|
67401
|
+
|
|
67402
|
+
// ../protocol/src/wire.ts
|
|
67403
|
+
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
67404
|
+
import { randomUUID } from "node:crypto";
|
|
67405
|
+
var MAX_FRAME_BYTES = 256 * 1024;
|
|
67406
|
+
var REPLY_BUDGET = MAX_FRAME_BYTES - 4096;
|
|
67407
|
+
var textEncoder = new TextEncoder();
|
|
67408
|
+
function byteLength(text) {
|
|
67409
|
+
return textEncoder.encode(text).length;
|
|
67410
|
+
}
|
|
67411
|
+
function extractControlExt(json5) {
|
|
67412
|
+
if (typeof json5 !== "object" || json5 === null) return void 0;
|
|
67413
|
+
const o = json5;
|
|
67414
|
+
const ext = {};
|
|
67415
|
+
if (typeof o.epoch === "number") ext.epoch = o.epoch;
|
|
67416
|
+
if (typeof o.agentId === "string") ext.agentId = o.agentId;
|
|
67417
|
+
if (typeof o.launchId === "string") ext.launchId = o.launchId;
|
|
67418
|
+
return Object.keys(ext).length > 0 ? ext : void 0;
|
|
67419
|
+
}
|
|
67420
|
+
function decodeEnvelopeWith(schemas, text, opts = {}) {
|
|
67421
|
+
if (byteLength(text) > (opts.maxBytes ?? MAX_FRAME_BYTES)) {
|
|
67422
|
+
return { ok: false, id: NIL_UUID, msg: "FRAME_TOO_LARGE" };
|
|
67584
67423
|
}
|
|
67585
|
-
|
|
67586
|
-
|
|
67587
|
-
|
|
67588
|
-
|
|
67589
|
-
|
|
67590
|
-
this.pending.clear();
|
|
67591
|
-
this.onClose(error63);
|
|
67424
|
+
let json5;
|
|
67425
|
+
try {
|
|
67426
|
+
json5 = JSON.parse(text);
|
|
67427
|
+
} catch {
|
|
67428
|
+
return { ok: false, id: NIL_UUID, msg: "invalid json" };
|
|
67592
67429
|
}
|
|
67593
|
-
|
|
67594
|
-
|
|
67595
|
-
|
|
67596
|
-
return
|
|
67430
|
+
const env = Envelope.safeParse(json5);
|
|
67431
|
+
if (!env.success) {
|
|
67432
|
+
const id = typeof json5 === "object" && json5 !== null && typeof json5.id === "string" ? json5.id : NIL_UUID;
|
|
67433
|
+
return { ok: false, id, msg: env.error.message };
|
|
67597
67434
|
}
|
|
67598
|
-
|
|
67599
|
-
|
|
67600
|
-
|
|
67601
|
-
|
|
67602
|
-
|
|
67603
|
-
|
|
67604
|
-
|
|
67605
|
-
|
|
67606
|
-
this.dispatch(kind, message);
|
|
67607
|
-
}
|
|
67435
|
+
const schema = Object.hasOwn(schemas, env.data.type) ? schemas[env.data.type] : void 0;
|
|
67436
|
+
if (!schema) {
|
|
67437
|
+
return {
|
|
67438
|
+
ok: false,
|
|
67439
|
+
id: env.data.id,
|
|
67440
|
+
msg: "UNKNOWN_FRAME",
|
|
67441
|
+
...env.data.corr ? { corr: env.data.corr } : {}
|
|
67442
|
+
};
|
|
67608
67443
|
}
|
|
67609
|
-
|
|
67610
|
-
|
|
67611
|
-
|
|
67612
|
-
|
|
67613
|
-
|
|
67614
|
-
|
|
67615
|
-
|
|
67616
|
-
|
|
67617
|
-
return;
|
|
67618
|
-
}
|
|
67619
|
-
if (kind === 0) {
|
|
67620
|
-
this.errors.set(sequence, new X11Error(message[1], sequence));
|
|
67621
|
-
if (this.errors.size > 64) this.errors.delete(this.errors.keys().next().value);
|
|
67622
|
-
}
|
|
67623
|
-
return;
|
|
67624
|
-
}
|
|
67625
|
-
this.onEvent(Buffer.from(message));
|
|
67444
|
+
const payload = schema.safeParse(env.data.payload);
|
|
67445
|
+
if (!payload.success) {
|
|
67446
|
+
return {
|
|
67447
|
+
ok: false,
|
|
67448
|
+
id: env.data.id,
|
|
67449
|
+
msg: payload.error.message,
|
|
67450
|
+
...env.data.corr ? { corr: env.data.corr } : {}
|
|
67451
|
+
};
|
|
67626
67452
|
}
|
|
67627
|
-
|
|
67628
|
-
|
|
67629
|
-
|
|
67630
|
-
|
|
67631
|
-
|
|
67632
|
-
|
|
67633
|
-
out.writeUInt16LE(11, 2);
|
|
67634
|
-
out.writeUInt16LE(0, 4);
|
|
67635
|
-
out.writeUInt16LE(name.length, 6);
|
|
67636
|
-
out.writeUInt16LE(data.length, 8);
|
|
67637
|
-
name.copy(out, 12);
|
|
67638
|
-
data.copy(out, 12 + name.length + pad4(name.length));
|
|
67639
|
-
return out;
|
|
67640
|
-
}
|
|
67641
|
-
function parseSetup(reply2) {
|
|
67642
|
-
const vendorLength = reply2.readUInt16LE(24);
|
|
67643
|
-
const formats = reply2[29];
|
|
67644
|
-
const minKeycode = reply2[34];
|
|
67645
|
-
const maxKeycode = reply2[35];
|
|
67646
|
-
const screens = 40 + vendorLength + pad4(vendorLength) + formats * 8;
|
|
67647
|
-
if (reply2.length < screens + 4) throw new Error("X11 setup reply has no screen");
|
|
67648
|
-
return { root: reply2.readUInt32LE(screens), minKeycode, maxKeycode };
|
|
67453
|
+
const ext = extractControlExt(json5);
|
|
67454
|
+
return {
|
|
67455
|
+
ok: true,
|
|
67456
|
+
frame: { ...env.data, payload: payload.data },
|
|
67457
|
+
...ext ? { ext } : {}
|
|
67458
|
+
};
|
|
67649
67459
|
}
|
|
67650
|
-
function
|
|
67651
|
-
|
|
67652
|
-
|
|
67653
|
-
|
|
67654
|
-
|
|
67655
|
-
|
|
67656
|
-
|
|
67657
|
-
}
|
|
67658
|
-
|
|
67659
|
-
|
|
67660
|
-
|
|
67661
|
-
var OP_GET_KEYBOARD_MAPPING = 101;
|
|
67662
|
-
var OP_GET_MODIFIER_MAPPING = 119;
|
|
67663
|
-
async function queryExtension(x, name) {
|
|
67664
|
-
const bytes = Buffer.from(name, "latin1");
|
|
67665
|
-
const body = Buffer.alloc(4 + bytes.length);
|
|
67666
|
-
body.writeUInt16LE(bytes.length, 0);
|
|
67667
|
-
bytes.copy(body, 4);
|
|
67668
|
-
const reply2 = await x.request(request(OP_QUERY_EXTENSION, 0, body));
|
|
67669
|
-
return reply2[8] ? reply2[9] : void 0;
|
|
67460
|
+
function buildEnvelopeRaw(type, payload, opts = {}) {
|
|
67461
|
+
return {
|
|
67462
|
+
v: 1,
|
|
67463
|
+
id: opts.id ?? randomUUID(),
|
|
67464
|
+
ts: opts.ts ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
67465
|
+
type,
|
|
67466
|
+
payload,
|
|
67467
|
+
...opts.corr ? { corr: opts.corr } : {},
|
|
67468
|
+
...opts.orgId ? { orgId: opts.orgId } : {},
|
|
67469
|
+
...opts.ext ?? {}
|
|
67470
|
+
};
|
|
67670
67471
|
}
|
|
67671
67472
|
|
|
67672
|
-
// src/
|
|
67473
|
+
// ../protocol/src/frames/error.ts
|
|
67673
67474
|
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
67674
|
-
|
|
67675
|
-
|
|
67676
|
-
|
|
67677
|
-
|
|
67678
|
-
|
|
67679
|
-
|
|
67680
|
-
|
|
67681
|
-
|
|
67682
|
-
|
|
67683
|
-
|
|
67684
|
-
|
|
67685
|
-
|
|
67686
|
-
|
|
67687
|
-
|
|
67688
|
-
|
|
67689
|
-
|
|
67475
|
+
var ErrorCode = external_exports.enum([
|
|
67476
|
+
// protocol / framing
|
|
67477
|
+
"UNKNOWN_FRAME",
|
|
67478
|
+
"FRAME_TOO_LARGE",
|
|
67479
|
+
"PROTOCOL_STATE",
|
|
67480
|
+
"BAD_PAYLOAD",
|
|
67481
|
+
// auth / identity
|
|
67482
|
+
"AUTH_FAILED",
|
|
67483
|
+
"ATTESTATION_INVALID",
|
|
67484
|
+
// fencing / ordering
|
|
67485
|
+
"STALE_EPOCH",
|
|
67486
|
+
"STALE_LAUNCH",
|
|
67487
|
+
// delivery
|
|
67488
|
+
"NO_SESSION",
|
|
67489
|
+
"SCOPE_DENIED",
|
|
67490
|
+
// delegated MCP authority / invocation binding
|
|
67491
|
+
"DELEGATION_DENIED",
|
|
67492
|
+
"INVOCATION_CONFLICT",
|
|
67493
|
+
// secrets
|
|
67494
|
+
"LEASE_EXPIRED",
|
|
67495
|
+
"LEASE_DENIED",
|
|
67496
|
+
// generic
|
|
67497
|
+
"RATE_LIMITED",
|
|
67498
|
+
"CONFLICT",
|
|
67499
|
+
"INTERNAL"
|
|
67500
|
+
]);
|
|
67501
|
+
var ErrorFrame = external_exports.object({
|
|
67502
|
+
code: ErrorCode,
|
|
67503
|
+
message: external_exports.string(),
|
|
67504
|
+
// human-readable, redacted of secrets
|
|
67505
|
+
retryable: external_exports.boolean(),
|
|
67506
|
+
details: external_exports.record(external_exports.string(), external_exports.unknown()).optional()
|
|
67507
|
+
});
|
|
67690
67508
|
|
|
67691
|
-
// src/
|
|
67509
|
+
// ../protocol/src/frames/computer-lease.ts
|
|
67692
67510
|
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
67693
|
-
|
|
67694
|
-
|
|
67695
|
-
|
|
67696
|
-
|
|
67697
|
-
|
|
67698
|
-
|
|
67699
|
-
|
|
67700
|
-
|
|
67701
|
-
|
|
67702
|
-
|
|
67703
|
-
|
|
67704
|
-
|
|
67705
|
-
|
|
67511
|
+
var ComputerDesktopId = external_exports.string().regex(/^[A-Za-z0-9_-]{1,32}$/);
|
|
67512
|
+
var COMPUTER_LEASE_AGENT_NAME_MAX = 200;
|
|
67513
|
+
var ComputerLeaseHolder = external_exports.object({
|
|
67514
|
+
sessionId: external_exports.string().min(1).max(256),
|
|
67515
|
+
agentId: external_exports.string().uuid(),
|
|
67516
|
+
agentName: external_exports.string().min(1).max(COMPUTER_LEASE_AGENT_NAME_MAX).optional()
|
|
67517
|
+
});
|
|
67518
|
+
var computerLeaseHolderName = (holder) => `${holder.agentId}/${holder.sessionId}`;
|
|
67519
|
+
var ComputerControlLease = external_exports.object({
|
|
67520
|
+
leaseId: external_exports.string().uuid(),
|
|
67521
|
+
computerId: external_exports.string().uuid(),
|
|
67522
|
+
holder: ComputerLeaseHolder,
|
|
67523
|
+
acquiredAt: external_exports.string().datetime(),
|
|
67524
|
+
expiresAt: external_exports.string().datetime(),
|
|
67525
|
+
// Behind `computer-desktops-v1`: the agent desktop it covers, keyed by that agent's id; absent, the main desktop.
|
|
67526
|
+
desktop: external_exports.string().uuid().optional()
|
|
67527
|
+
});
|
|
67528
|
+
var COMPUTER_LEASE_REFUSALS = ["computer_busy", "human_in_control", "unavailable", "denied"];
|
|
67529
|
+
var COMPUTER_LEASE_POLL_MAX_MS = 1e4;
|
|
67530
|
+
var COMPUTER_LEASE_WAIT_MAX_SECONDS = 600;
|
|
67531
|
+
var ComputerLeaseAcquire = external_exports.object({
|
|
67532
|
+
computerId: external_exports.string().uuid(),
|
|
67533
|
+
agentId: external_exports.string().uuid(),
|
|
67534
|
+
sessionId: external_exports.string().min(1).max(256),
|
|
67535
|
+
// The daemon-clock time of the request, compared with the `event/session` turn end on the same clock.
|
|
67536
|
+
requestedAt: external_exports.string().datetime(),
|
|
67537
|
+
// Behind COMPUTER_LEASE_QUEUE_FEATURE: wait in the Computer's FIFO queue, holding the reply up to this long.
|
|
67538
|
+
waitMs: external_exports.number().int().min(0).max(COMPUTER_LEASE_POLL_MAX_MS).optional()
|
|
67539
|
+
});
|
|
67540
|
+
var ComputerLeaseQueued = external_exports.object({
|
|
67541
|
+
position: external_exports.number().int().min(1),
|
|
67542
|
+
waitedMs: external_exports.number().int().min(0),
|
|
67543
|
+
// Time left before the wait ends in `computer_busy`.
|
|
67544
|
+
leftMs: external_exports.number().int().min(0)
|
|
67545
|
+
});
|
|
67546
|
+
var ComputerLeaseAcquireResult = external_exports.discriminatedUnion("granted", [
|
|
67547
|
+
external_exports.object({ granted: external_exports.literal(true), lease: ComputerControlLease }),
|
|
67548
|
+
external_exports.object({
|
|
67549
|
+
granted: external_exports.literal(false),
|
|
67550
|
+
code: external_exports.enum(COMPUTER_LEASE_REFUSALS),
|
|
67551
|
+
message: external_exports.string().max(500),
|
|
67552
|
+
holder: ComputerLeaseHolder.optional(),
|
|
67553
|
+
queued: ComputerLeaseQueued.optional()
|
|
67554
|
+
})
|
|
67555
|
+
]);
|
|
67556
|
+
var ComputerLeaseRelease = external_exports.object({
|
|
67557
|
+
computerId: external_exports.string().uuid(),
|
|
67558
|
+
agentId: external_exports.string().uuid(),
|
|
67559
|
+
sessionId: external_exports.string().min(1).max(256)
|
|
67560
|
+
});
|
|
67706
67561
|
|
|
67707
|
-
// src/
|
|
67562
|
+
// ../protocol/src/frames/computer-channel.ts
|
|
67708
67563
|
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
67709
|
-
|
|
67710
|
-
|
|
67711
|
-
|
|
67712
|
-
|
|
67713
|
-
|
|
67714
|
-
|
|
67715
|
-
|
|
67716
|
-
var
|
|
67717
|
-
var
|
|
67718
|
-
var
|
|
67719
|
-
var
|
|
67720
|
-
|
|
67721
|
-
|
|
67722
|
-
|
|
67723
|
-
|
|
67724
|
-
|
|
67725
|
-
|
|
67726
|
-
|
|
67727
|
-
|
|
67728
|
-
|
|
67729
|
-
})()
|
|
67730
|
-
|
|
67731
|
-
|
|
67732
|
-
|
|
67733
|
-
|
|
67564
|
+
|
|
67565
|
+
// ../protocol/src/computer-channel-token.ts
|
|
67566
|
+
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
67567
|
+
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
67568
|
+
|
|
67569
|
+
// ../protocol/src/computer-viewer.ts
|
|
67570
|
+
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
67571
|
+
var COMPUTER_VIEWER_API_PREFIX = "/view/api/";
|
|
67572
|
+
var COMPUTER_VIEWER_MAX_REQUEST_BYTES = 64 * 1024;
|
|
67573
|
+
var COMPUTER_VIEWER_TRANSPORTS = ["direct", "stun", "turn"];
|
|
67574
|
+
var ComputerIceServer = external_exports.object({
|
|
67575
|
+
urls: external_exports.array(
|
|
67576
|
+
external_exports.string().regex(/^turns?:/).max(256)
|
|
67577
|
+
).min(1).max(4),
|
|
67578
|
+
username: external_exports.string().min(1).max(256),
|
|
67579
|
+
credential: external_exports.string().min(1).max(256)
|
|
67580
|
+
}).strict();
|
|
67581
|
+
var COMPUTER_ICE_SERVERS_MAX = 2;
|
|
67582
|
+
var ComputerStunUrl = external_exports.string().max(256).regex(/^stun:(\[[0-9a-fA-F:.]+\]|[A-Za-z0-9.-]+)(:\d{1,5})?$/, "expected stun:<host>[:<port>]");
|
|
67583
|
+
var ComputerTurnUrl = external_exports.string().max(256).regex(
|
|
67584
|
+
/^turns?:(\[[0-9a-fA-F:.]+\]|[A-Za-z0-9.-]+)(:\d{1,5})?(\?transport=(udp|tcp))?$/,
|
|
67585
|
+
"expected turn:<host>[:<port>][?transport=udp|tcp] or turns:"
|
|
67586
|
+
);
|
|
67587
|
+
var COMPUTER_STUN_URLS_MAX = 2;
|
|
67588
|
+
var ComputerViewerCandidate = external_exports.object({
|
|
67589
|
+
id: external_exports.string().min(1).max(64),
|
|
67590
|
+
candidate: external_exports.object({
|
|
67591
|
+
candidate: external_exports.string().max(1024),
|
|
67592
|
+
sdpMid: external_exports.string().max(64).nullish(),
|
|
67593
|
+
sdpMLineIndex: external_exports.number().int().min(0).max(64).nullish()
|
|
67594
|
+
}).nullable()
|
|
67595
|
+
});
|
|
67596
|
+
var ComputerViewerCandidatesRequest = external_exports.object({
|
|
67597
|
+
id: external_exports.string().min(1).max(64),
|
|
67598
|
+
after: external_exports.number().int().min(0).max(1e3).default(0)
|
|
67599
|
+
});
|
|
67600
|
+
var ComputerViewerOfferRequest = external_exports.object({ transport: external_exports.enum(COMPUTER_VIEWER_TRANSPORTS).optional() });
|
|
67601
|
+
var ComputerViewerRenewal = external_exports.object({ type: external_exports.literal("auth"), token: external_exports.string().min(1).max(4096) });
|
|
67602
|
+
|
|
67603
|
+
// ../protocol/src/computer-command-line.ts
|
|
67604
|
+
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
67605
|
+
var COMPUTER_SHELL_MODES = ["off", "ask", "on"];
|
|
67606
|
+
var COMPUTER_FILES_MODES = ["off", "read", "read-write"];
|
|
67607
|
+
var COMPUTER_FILE_ROOTS_MAX = 32;
|
|
67608
|
+
var ComputerFileRoot = external_exports.string().trim().min(1).max(1024).refine((p) => /^(\/|~(\/|$)|[A-Za-z]:[\\/])/.test(p) && !p.includes("\0"), "expected an absolute path");
|
|
67609
|
+
var COMPUTER_EXEC_TIMEOUT_DEFAULT_MS = 3e4;
|
|
67610
|
+
var COMPUTER_EXEC_TIMEOUT_MAX_MS = 9e4;
|
|
67611
|
+
var COMPUTER_EXEC_COMMAND_MAX_CHARS = 16384;
|
|
67612
|
+
var COMPUTER_EXEC_OUTPUT_TAIL_BYTES = 32 * 1024;
|
|
67613
|
+
var COMPUTER_EXEC_PER_SESSION_MAX = 4;
|
|
67614
|
+
var COMPUTER_EXEC_TOTAL_MAX = 8;
|
|
67615
|
+
var COMPUTER_READ_TEXT_MAX_BYTES = 256 * 1024;
|
|
67616
|
+
var COMPUTER_READ_IMAGE_MAX_BYTES = 5 * 1024 * 1024;
|
|
67617
|
+
var COMPUTER_WRITE_MAX_BYTES = 1024 * 1024;
|
|
67618
|
+
var COMPUTER_LIST_DIR_MAX = 1e3;
|
|
67619
|
+
var SHELL_RANK = { off: 0, ask: 1, on: 2 };
|
|
67620
|
+
var FILES_RANK = { off: 0, read: 1, "read-write": 2 };
|
|
67621
|
+
var narrowerShell = (a, b) => SHELL_RANK[a] <= SHELL_RANK[b] ? a : b;
|
|
67622
|
+
var narrowerFiles = (a, b) => FILES_RANK[a] <= FILES_RANK[b] ? a : b;
|
|
67623
|
+
|
|
67624
|
+
// ../protocol/src/computer-channel-token.ts
|
|
67625
|
+
var COMPUTER_CHANNEL_TOKEN_PREFIX = "actk1";
|
|
67626
|
+
var COMPUTER_CHANNEL_TOKEN_AUDIENCES = ["mcp", "relay", "view"];
|
|
67627
|
+
var COMPUTER_CHANNEL_TOKEN_MAX_TTL_MS = 5 * 6e4;
|
|
67628
|
+
var COMPUTER_AGENT_MODES = ["view", "control"];
|
|
67629
|
+
var ComputerChannelTokenClaims = external_exports.object({
|
|
67630
|
+
aud: external_exports.enum(COMPUTER_CHANNEL_TOKEN_AUDIENCES),
|
|
67631
|
+
// The Computer the token is for, and the id of the channel key that signed it.
|
|
67632
|
+
cmp: external_exports.string().uuid(),
|
|
67633
|
+
kid: external_exports.string().min(1).max(64),
|
|
67634
|
+
// Issue and expiry times, epoch milliseconds on the issuer's clock.
|
|
67635
|
+
iat: external_exports.number().int().nonnegative(),
|
|
67636
|
+
exp: external_exports.number().int().positive(),
|
|
67637
|
+
// `mcp` only: the agent session the calls belong to, its agent and daemon, and what the policy lets it do.
|
|
67638
|
+
ses: external_exports.string().min(1).max(256).optional(),
|
|
67639
|
+
agt: external_exports.string().uuid().optional(),
|
|
67640
|
+
dmn: external_exports.string().uuid().optional(),
|
|
67641
|
+
mode: external_exports.enum(COMPUTER_AGENT_MODES).optional(),
|
|
67642
|
+
// `mcp` only: the command-line tier the policy allows (§5.7); absent, as from an older CP, means none.
|
|
67643
|
+
sh: external_exports.enum(COMPUTER_SHELL_MODES).optional(),
|
|
67644
|
+
fs: external_exports.enum(COMPUTER_FILES_MODES).optional(),
|
|
67645
|
+
// `view` only: the member watching, the TURN servers the desktop may relay media through, and the STUN servers it may punch with.
|
|
67646
|
+
usr: external_exports.string().min(1).max(128).optional(),
|
|
67647
|
+
ice: external_exports.array(ComputerIceServer).max(COMPUTER_ICE_SERVERS_MAX).optional(),
|
|
67648
|
+
stun: external_exports.array(ComputerStunUrl).max(COMPUTER_STUN_URLS_MAX).optional(),
|
|
67649
|
+
// `view` only, behind `computer-desktops-v1`: the one desktop it may watch (§3.9); absent, the main desktop.
|
|
67650
|
+
dsk: ComputerDesktopId.optional()
|
|
67651
|
+
}).strip().refine((c) => c.aud !== "mcp" || c.ses !== void 0 && c.agt !== void 0 && c.mode !== void 0, {
|
|
67652
|
+
message: "an mcp token names its session, agent and mode"
|
|
67653
|
+
}).refine((c) => c.aud !== "view" || c.usr !== void 0 && c.mode !== void 0, {
|
|
67654
|
+
message: "a view token names its member and mode"
|
|
67655
|
+
}).refine((c) => c.exp > c.iat && c.exp - c.iat <= COMPUTER_CHANNEL_TOKEN_MAX_TTL_MS, {
|
|
67656
|
+
message: "token lifetime out of range"
|
|
67657
|
+
});
|
|
67658
|
+
var MAC_DOMAIN = "agentconnect/computer-channel-token/v1\n";
|
|
67659
|
+
var MAX_TOKEN_CHARS = 4096;
|
|
67660
|
+
function mac3(key, signed) {
|
|
67661
|
+
return createHmac("sha256", key).update(MAC_DOMAIN + signed).digest();
|
|
67734
67662
|
}
|
|
67735
|
-
function
|
|
67736
|
-
|
|
67663
|
+
function signComputerChannelToken(claims, key) {
|
|
67664
|
+
const parsed = ComputerChannelTokenClaims.parse(claims);
|
|
67665
|
+
const signed = `${COMPUTER_CHANNEL_TOKEN_PREFIX}.${Buffer.from(JSON.stringify(parsed)).toString("base64url")}`;
|
|
67666
|
+
return `${signed}.${mac3(key, signed).toString("base64url")}`;
|
|
67737
67667
|
}
|
|
67738
|
-
|
|
67739
|
-
|
|
67740
|
-
|
|
67741
|
-
|
|
67742
|
-
|
|
67743
|
-
|
|
67744
|
-
|
|
67745
|
-
|
|
67746
|
-
return
|
|
67747
|
-
}
|
|
67748
|
-
varint() {
|
|
67749
|
-
let result = 0;
|
|
67750
|
-
let shift = 0;
|
|
67751
|
-
for (; ; ) {
|
|
67752
|
-
if (this.pos >= this.buf.length) throw new Error("leveldb: truncated varint");
|
|
67753
|
-
const byte = this.buf[this.pos++];
|
|
67754
|
-
result += (byte & 127) * 2 ** shift;
|
|
67755
|
-
if (!(byte & 128)) return result;
|
|
67756
|
-
shift += 7;
|
|
67757
|
-
if (shift > 63) throw new Error("leveldb: varint too long");
|
|
67758
|
-
}
|
|
67759
|
-
}
|
|
67760
|
-
bytes(length) {
|
|
67761
|
-
if (this.pos + length > this.buf.length) throw new Error("leveldb: truncated slice");
|
|
67762
|
-
const out = this.buf.subarray(this.pos, this.pos + length);
|
|
67763
|
-
this.pos += length;
|
|
67764
|
-
return out;
|
|
67765
|
-
}
|
|
67766
|
-
slice() {
|
|
67767
|
-
return this.bytes(this.varint());
|
|
67768
|
-
}
|
|
67769
|
-
};
|
|
67770
|
-
function varint(value) {
|
|
67771
|
-
const out = [];
|
|
67772
|
-
let v = value;
|
|
67773
|
-
while (v >= 128) {
|
|
67774
|
-
out.push(v % 128 | 128);
|
|
67775
|
-
v = Math.floor(v / 128);
|
|
67668
|
+
function readComputerChannelToken(token) {
|
|
67669
|
+
if (token.length > MAX_TOKEN_CHARS) return null;
|
|
67670
|
+
const parts = token.split(".");
|
|
67671
|
+
if (parts.length !== 3 || parts[0] !== COMPUTER_CHANNEL_TOKEN_PREFIX) return null;
|
|
67672
|
+
try {
|
|
67673
|
+
const parsed = ComputerChannelTokenClaims.safeParse(JSON.parse(Buffer.from(parts[1], "base64url").toString()));
|
|
67674
|
+
return parsed.success ? parsed.data : null;
|
|
67675
|
+
} catch {
|
|
67676
|
+
return null;
|
|
67776
67677
|
}
|
|
67777
|
-
out.push(v);
|
|
67778
|
-
return Buffer.from(out);
|
|
67779
67678
|
}
|
|
67780
|
-
function
|
|
67781
|
-
|
|
67679
|
+
function verifyComputerChannelToken(token, opts) {
|
|
67680
|
+
const claims = readComputerChannelToken(token);
|
|
67681
|
+
if (!claims || claims.aud !== opts.aud || claims.cmp !== opts.computerId) return null;
|
|
67682
|
+
if (!(claims.exp > opts.now)) return null;
|
|
67683
|
+
const key = opts.key(claims.kid);
|
|
67684
|
+
if (!key) return null;
|
|
67685
|
+
const at = token.lastIndexOf(".");
|
|
67686
|
+
const presented = Buffer.from(token.slice(at + 1), "base64url");
|
|
67687
|
+
const expected = mac3(key, token.slice(0, at));
|
|
67688
|
+
if (presented.length !== expected.length || !timingSafeEqual(presented, expected)) return null;
|
|
67689
|
+
return claims;
|
|
67782
67690
|
}
|
|
67783
|
-
|
|
67784
|
-
|
|
67785
|
-
|
|
67786
|
-
|
|
67787
|
-
|
|
67788
|
-
|
|
67789
|
-
|
|
67790
|
-
|
|
67791
|
-
|
|
67792
|
-
|
|
67793
|
-
|
|
67794
|
-
|
|
67795
|
-
|
|
67796
|
-
|
|
67797
|
-
|
|
67798
|
-
|
|
67799
|
-
|
|
67800
|
-
|
|
67801
|
-
|
|
67802
|
-
|
|
67803
|
-
|
|
67804
|
-
|
|
67805
|
-
|
|
67806
|
-
|
|
67807
|
-
|
|
67808
|
-
|
|
67809
|
-
|
|
67810
|
-
|
|
67811
|
-
|
|
67812
|
-
|
|
67813
|
-
|
|
67814
|
-
|
|
67815
|
-
|
|
67816
|
-
|
|
67817
|
-
|
|
67818
|
-
|
|
67819
|
-
|
|
67820
|
-
|
|
67821
|
-
|
|
67691
|
+
|
|
67692
|
+
// ../protocol/src/frames/computer-channel.ts
|
|
67693
|
+
var ComputerRelayEntry = external_exports.object({
|
|
67694
|
+
relayId: external_exports.string().uuid(),
|
|
67695
|
+
url: external_exports.string().min(1).max(2048)
|
|
67696
|
+
});
|
|
67697
|
+
var COMPUTER_RELAYS_MAX = 64;
|
|
67698
|
+
var COMPUTER_ADMIN_PROMPT_MODES = ["agent", "people", "approve", "deny"];
|
|
67699
|
+
var DEFAULT_COMPUTER_ADMIN_PROMPT_MODE = "people";
|
|
67700
|
+
var ComputerApprovalsSchema = external_exports.object({
|
|
67701
|
+
// Ask before a session's first click, drag, type, key or launch; an allow covers the rest of the session.
|
|
67702
|
+
firstInputPerSession: external_exports.boolean().default(true),
|
|
67703
|
+
// Windows only; absent means the default, so policies stored before it keep their meaning.
|
|
67704
|
+
adminPrompts: external_exports.enum(COMPUTER_ADMIN_PROMPT_MODES).optional()
|
|
67705
|
+
});
|
|
67706
|
+
var ComputerGrantApprovalsSchema = ComputerApprovalsSchema.extend({
|
|
67707
|
+
launchApp: external_exports.enum(["always", "session", "never-ask"]).optional(),
|
|
67708
|
+
submitLikeKeys: external_exports.boolean().optional()
|
|
67709
|
+
});
|
|
67710
|
+
var COMPUTER_CHANNEL_REFUSALS = ["denied", "unavailable"];
|
|
67711
|
+
var ComputerChannelGrantRequest = external_exports.object({
|
|
67712
|
+
computerId: external_exports.string().uuid(),
|
|
67713
|
+
agentId: external_exports.string().uuid(),
|
|
67714
|
+
sessionId: external_exports.string().min(1).max(256)
|
|
67715
|
+
});
|
|
67716
|
+
var ComputerChannelGrantResult = external_exports.discriminatedUnion("granted", [
|
|
67717
|
+
external_exports.object({
|
|
67718
|
+
granted: external_exports.literal(true),
|
|
67719
|
+
token: external_exports.string().min(1).max(2048),
|
|
67720
|
+
expiresAt: external_exports.string().datetime(),
|
|
67721
|
+
mode: external_exports.enum(COMPUTER_AGENT_MODES),
|
|
67722
|
+
relays: external_exports.array(ComputerRelayEntry).max(COMPUTER_RELAYS_MAX),
|
|
67723
|
+
// What the approval cards name and whom they also reach (§4.2); an older CP sends none, and every approval is asked.
|
|
67724
|
+
name: external_exports.string().min(1).max(200).optional(),
|
|
67725
|
+
ownerUserId: external_exports.string().min(1).max(128).optional(),
|
|
67726
|
+
approvals: ComputerGrantApprovalsSchema.optional(),
|
|
67727
|
+
// The console users who may answer its approvals: the Computer's allowed members; an older CP sends none.
|
|
67728
|
+
approvers: external_exports.array(external_exports.string().min(1).max(128)).max(500).optional(),
|
|
67729
|
+
// The command-line tier the token allows (§5.7); an older CP sends none, which allows none.
|
|
67730
|
+
shell: external_exports.enum(COMPUTER_SHELL_MODES).optional(),
|
|
67731
|
+
files: external_exports.enum(COMPUTER_FILES_MODES).optional()
|
|
67732
|
+
}),
|
|
67733
|
+
external_exports.object({
|
|
67734
|
+
granted: external_exports.literal(false),
|
|
67735
|
+
code: external_exports.enum(COMPUTER_CHANNEL_REFUSALS),
|
|
67736
|
+
message: external_exports.string().max(500)
|
|
67737
|
+
})
|
|
67738
|
+
]);
|
|
67739
|
+
|
|
67740
|
+
// ../protocol/src/frames/computer-audit.ts
|
|
67741
|
+
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
67742
|
+
var COMPUTER_AUDIT_FEATURE = "computer-audit-v1";
|
|
67743
|
+
var COMPUTER_APPROVAL_META_KEY = "md.agentconnect/approval";
|
|
67744
|
+
var COMPUTER_APPROVAL_RESULTS = ["not_required", "allowed", "allowed_session"];
|
|
67745
|
+
var COMPUTER_AUDIT_BATCH_MAX = 100;
|
|
67746
|
+
var COMPUTER_AUDIT_BATCH_BYTES = REPLY_BUDGET;
|
|
67747
|
+
var COMPUTER_AUDIT_ARGS_MAX_CHARS = 2048;
|
|
67748
|
+
var AUDIT_STRING_MAX = 256;
|
|
67749
|
+
var AUDIT_COMMAND_MAX = 1536;
|
|
67750
|
+
var AUDIT_DEPTH_MAX = 6;
|
|
67751
|
+
var TEXT_KEYS = /* @__PURE__ */ new Set(["text", "value", "content"]);
|
|
67752
|
+
var CONTROL_CHARS = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g;
|
|
67753
|
+
var LONE_SURROGATE = /[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/g;
|
|
67754
|
+
function computerAuditText(value) {
|
|
67755
|
+
return value.replace(CONTROL_CHARS, "").replace(LONE_SURROGATE, "\uFFFD");
|
|
67756
|
+
}
|
|
67757
|
+
function auditValue(value, depth) {
|
|
67758
|
+
if (typeof value === "string") return computerAuditText(value.slice(0, AUDIT_STRING_MAX));
|
|
67759
|
+
if (value === null || typeof value !== "object") return value;
|
|
67760
|
+
if (depth >= AUDIT_DEPTH_MAX) return "[nested]";
|
|
67761
|
+
if (Array.isArray(value)) return value.map((item) => auditValue(item, depth + 1));
|
|
67762
|
+
const out = {};
|
|
67763
|
+
for (const [key, item] of Object.entries(value))
|
|
67764
|
+
out[computerAuditText(key.slice(0, 64))] = auditValue(item, depth + 1);
|
|
67822
67765
|
return out;
|
|
67823
67766
|
}
|
|
67824
|
-
function
|
|
67825
|
-
|
|
67826
|
-
|
|
67827
|
-
|
|
67828
|
-
|
|
67829
|
-
|
|
67830
|
-
if (left < HEADER_SIZE) {
|
|
67831
|
-
pos += left;
|
|
67832
|
-
continue;
|
|
67833
|
-
}
|
|
67834
|
-
if (pos + HEADER_SIZE > data.length) break;
|
|
67835
|
-
const length = data.readUInt16LE(pos + 4);
|
|
67836
|
-
const type = data[pos + 6];
|
|
67837
|
-
if (type === 0 && length === 0) {
|
|
67838
|
-
pos += left;
|
|
67767
|
+
function computerAuditArgs(args) {
|
|
67768
|
+
let textLength;
|
|
67769
|
+
const out = {};
|
|
67770
|
+
for (const [key, value] of Object.entries(args)) {
|
|
67771
|
+
if (TEXT_KEYS.has(key) && typeof value === "string") {
|
|
67772
|
+
textLength = (textLength ?? 0) + [...value].length;
|
|
67839
67773
|
continue;
|
|
67840
67774
|
}
|
|
67841
|
-
|
|
67842
|
-
const payload = data.subarray(pos + HEADER_SIZE, pos + HEADER_SIZE + length);
|
|
67843
|
-
pos += HEADER_SIZE + length;
|
|
67844
|
-
if (type === FULL) {
|
|
67845
|
-
records.push(Buffer.from(payload));
|
|
67846
|
-
pending = void 0;
|
|
67847
|
-
} else if (type === FIRST) pending = [payload];
|
|
67848
|
-
else if (type === MIDDLE && pending) pending.push(payload);
|
|
67849
|
-
else if (type === LAST && pending) {
|
|
67850
|
-
pending.push(payload);
|
|
67851
|
-
records.push(Buffer.concat(pending));
|
|
67852
|
-
pending = void 0;
|
|
67853
|
-
}
|
|
67854
|
-
}
|
|
67855
|
-
return records;
|
|
67856
|
-
}
|
|
67857
|
-
function writeLogRecords(records) {
|
|
67858
|
-
const chunks = [];
|
|
67859
|
-
let offset = 0;
|
|
67860
|
-
const emit = (type, payload) => {
|
|
67861
|
-
const header = Buffer.alloc(HEADER_SIZE);
|
|
67862
|
-
header.writeUInt32LE(maskCrc(crc32c(payload, crc32c(Buffer.from([type])))), 0);
|
|
67863
|
-
header.writeUInt16LE(payload.length, 4);
|
|
67864
|
-
header[6] = type;
|
|
67865
|
-
chunks.push(header, payload);
|
|
67866
|
-
offset += HEADER_SIZE + payload.length;
|
|
67867
|
-
};
|
|
67868
|
-
for (const record2 of records) {
|
|
67869
|
-
let pos = 0;
|
|
67870
|
-
let first = true;
|
|
67871
|
-
do {
|
|
67872
|
-
let left = BLOCK_SIZE - offset % BLOCK_SIZE;
|
|
67873
|
-
if (left < HEADER_SIZE) {
|
|
67874
|
-
chunks.push(Buffer.alloc(left));
|
|
67875
|
-
offset += left;
|
|
67876
|
-
left = BLOCK_SIZE;
|
|
67877
|
-
}
|
|
67878
|
-
const take = Math.min(left - HEADER_SIZE, record2.length - pos);
|
|
67879
|
-
const end = pos + take === record2.length;
|
|
67880
|
-
emit(first && end ? FULL : first ? FIRST : end ? LAST : MIDDLE, record2.subarray(pos, pos + take));
|
|
67881
|
-
pos += take;
|
|
67882
|
-
first = false;
|
|
67883
|
-
} while (pos < record2.length);
|
|
67775
|
+
out[computerAuditText(key.slice(0, 64))] = key === "command" && typeof value === "string" ? computerAuditText(value.slice(0, AUDIT_COMMAND_MAX)) : auditValue(value, 1);
|
|
67884
67776
|
}
|
|
67885
|
-
|
|
67777
|
+
const bounded = JSON.stringify(out).length <= COMPUTER_AUDIT_ARGS_MAX_CHARS ? out : { truncated: true };
|
|
67778
|
+
return { args: bounded, ...textLength !== void 0 ? { textLength } : {} };
|
|
67886
67779
|
}
|
|
67887
|
-
|
|
67888
|
-
|
|
67889
|
-
|
|
67890
|
-
|
|
67891
|
-
|
|
67892
|
-
|
|
67893
|
-
|
|
67894
|
-
|
|
67895
|
-
|
|
67896
|
-
|
|
67897
|
-
|
|
67898
|
-
|
|
67899
|
-
|
|
67900
|
-
|
|
67901
|
-
|
|
67902
|
-
|
|
67903
|
-
|
|
67904
|
-
|
|
67780
|
+
var ComputerAuditEntry = external_exports.object({
|
|
67781
|
+
// Idempotency: a batch resent after a lost ack does not duplicate rows.
|
|
67782
|
+
id: external_exports.string().uuid(),
|
|
67783
|
+
at: external_exports.string().datetime(),
|
|
67784
|
+
tool: external_exports.string().min(1).max(128),
|
|
67785
|
+
// The lease holder name: `agentId/sessionId` for an agent session, else a local client or viewer name.
|
|
67786
|
+
client: external_exports.string().min(1).max(512),
|
|
67787
|
+
agentId: external_exports.string().uuid().optional(),
|
|
67788
|
+
sessionId: external_exports.string().min(1).max(256).optional(),
|
|
67789
|
+
outcome: external_exports.enum(["ok", "error"]),
|
|
67790
|
+
code: external_exports.string().min(1).max(64).optional(),
|
|
67791
|
+
approval: external_exports.enum(COMPUTER_APPROVAL_RESULTS).optional(),
|
|
67792
|
+
args: external_exports.record(external_exports.string().max(64), external_exports.unknown()).refine((args) => JSON.stringify(args).length <= COMPUTER_AUDIT_ARGS_MAX_CHARS, "audit args too large").optional(),
|
|
67793
|
+
textLength: external_exports.number().int().min(0).max(1e6).optional(),
|
|
67794
|
+
ms: external_exports.number().int().min(0),
|
|
67795
|
+
// The stored screenshot this call returned (§9), as `sha256:<hex>`.
|
|
67796
|
+
screenshotRef: external_exports.string().min(1).max(1024).optional(),
|
|
67797
|
+
// Behind `computer-desktops-v1`: the agent desktop that served it (§3.9); absent, the main desktop.
|
|
67798
|
+
desktop: ComputerDesktopId.optional()
|
|
67799
|
+
}).strict();
|
|
67800
|
+
var ComputerAuditReport = external_exports.object({
|
|
67801
|
+
entries: external_exports.array(ComputerAuditEntry).min(1).max(COMPUTER_AUDIT_BATCH_MAX)
|
|
67802
|
+
});
|
|
67803
|
+
var ComputerAuditAck = external_exports.object({ stored: external_exports.number().int().min(0) });
|
|
67804
|
+
|
|
67805
|
+
// ../protocol/src/frames/computer-screenshot.ts
|
|
67806
|
+
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
67807
|
+
var COMPUTER_SCREENSHOT_FEATURE = "computer-screenshot-v1";
|
|
67808
|
+
var COMPUTER_SCREENSHOT_RETENTION_MAX_DAYS = 3650;
|
|
67809
|
+
var COMPUTER_SCREENSHOT_MAX_BYTES = 32 * 1024 * 1024;
|
|
67810
|
+
var COMPUTER_SCREENSHOT_CONTENT_TYPES = ["image/png", "image/jpeg", "image/webp"];
|
|
67811
|
+
var REF_PREFIX = "sha256:";
|
|
67812
|
+
var SHA256_HEX_RE = /^[0-9a-f]{64}$/;
|
|
67813
|
+
var ComputerScreenshotSha256 = external_exports.string().regex(SHA256_HEX_RE, "expected a lower-case hex SHA-256");
|
|
67814
|
+
function computerScreenshotRef(sha2563) {
|
|
67815
|
+
return `${REF_PREFIX}${sha2563}`;
|
|
67905
67816
|
}
|
|
67906
|
-
|
|
67907
|
-
|
|
67908
|
-
|
|
67909
|
-
|
|
67910
|
-
|
|
67911
|
-
|
|
67912
|
-
|
|
67913
|
-
|
|
67914
|
-
|
|
67915
|
-
|
|
67916
|
-
|
|
67917
|
-
|
|
67918
|
-
|
|
67919
|
-
|
|
67817
|
+
var ComputerScreenshotPut = external_exports.object({
|
|
67818
|
+
sessionId: external_exports.string().min(1).max(256),
|
|
67819
|
+
agentId: external_exports.string().uuid(),
|
|
67820
|
+
sha256: ComputerScreenshotSha256,
|
|
67821
|
+
bytes: external_exports.number().int().positive().max(COMPUTER_SCREENSHOT_MAX_BYTES),
|
|
67822
|
+
contentType: external_exports.enum(COMPUTER_SCREENSHOT_CONTENT_TYPES),
|
|
67823
|
+
takenAt: external_exports.string().datetime()
|
|
67824
|
+
}).strict();
|
|
67825
|
+
var ComputerScreenshotPutOk = external_exports.object({
|
|
67826
|
+
status: external_exports.enum(["upload", "stored", "skipped"]),
|
|
67827
|
+
url: external_exports.string().url().optional(),
|
|
67828
|
+
headers: external_exports.record(external_exports.string(), external_exports.string()).optional(),
|
|
67829
|
+
expiresAt: external_exports.string().datetime().optional(),
|
|
67830
|
+
reason: external_exports.string().max(200).optional()
|
|
67831
|
+
});
|
|
67832
|
+
var ComputerScreenshotCommit = external_exports.object({ sessionId: external_exports.string().min(1).max(256), sha256: ComputerScreenshotSha256 }).strict();
|
|
67833
|
+
var ComputerScreenshotCommitOk = external_exports.object({ stored: external_exports.boolean() });
|
|
67834
|
+
|
|
67835
|
+
// ../protocol/src/frames/relay-computer.ts
|
|
67836
|
+
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
67837
|
+
var RELAY_COMPUTER_SUBPROTOCOL = "agentconnect.cr.v1";
|
|
67838
|
+
var RELAY_COMPUTER_WS_PATH = "/cr/ws";
|
|
67839
|
+
var RELAY_COMPUTER_MAX_BODY_BYTES = 8 * 1024 * 1024;
|
|
67840
|
+
var RELAY_COMPUTER_MAX_FRAME_BYTES = 12 * 1024 * 1024;
|
|
67841
|
+
var RELAY_DAEMON_PATH_SUFFIX = "/rd/ws";
|
|
67842
|
+
function relayUrlAt(relayUrl, path, scheme) {
|
|
67843
|
+
const url2 = new URL(relayUrl);
|
|
67844
|
+
const prefix = url2.pathname.endsWith(RELAY_DAEMON_PATH_SUFFIX) ? url2.pathname.slice(0, -RELAY_DAEMON_PATH_SUFFIX.length) : url2.pathname.replace(/\/+$/, "");
|
|
67845
|
+
for (const { from, to } of scheme) if (url2.protocol === from) url2.protocol = to;
|
|
67846
|
+
url2.pathname = `${prefix}${path}`;
|
|
67847
|
+
url2.search = "";
|
|
67848
|
+
url2.hash = "";
|
|
67849
|
+
return url2.toString();
|
|
67920
67850
|
}
|
|
67921
|
-
function
|
|
67922
|
-
|
|
67923
|
-
|
|
67924
|
-
|
|
67925
|
-
|
|
67926
|
-
if (compression === 0) return contents;
|
|
67927
|
-
if (compression === 1) return snappyDecompress(contents);
|
|
67928
|
-
throw new Error(`leveldb: unsupported block compression ${compression}`);
|
|
67851
|
+
function relayComputerWsUrl(relayUrl) {
|
|
67852
|
+
return relayUrlAt(relayUrl, RELAY_COMPUTER_WS_PATH, [
|
|
67853
|
+
{ from: "http:", to: "ws:" },
|
|
67854
|
+
{ from: "https:", to: "wss:" }
|
|
67855
|
+
]);
|
|
67929
67856
|
}
|
|
67930
|
-
|
|
67931
|
-
|
|
67932
|
-
|
|
67933
|
-
|
|
67934
|
-
|
|
67935
|
-
|
|
67936
|
-
|
|
67937
|
-
|
|
67938
|
-
|
|
67939
|
-
|
|
67940
|
-
|
|
67941
|
-
|
|
67942
|
-
|
|
67857
|
+
var Base64 = external_exports.string().regex(/^[A-Za-z0-9+/]*={0,2}$/);
|
|
67858
|
+
var Headers2 = external_exports.record(external_exports.string().min(1).max(256), external_exports.string().max(8192));
|
|
67859
|
+
var CrHello = external_exports.object({
|
|
67860
|
+
computerId: external_exports.string().uuid(),
|
|
67861
|
+
token: external_exports.string().min(1).max(2048),
|
|
67862
|
+
desktopDaemonVersion: external_exports.string().trim().min(1).max(64)
|
|
67863
|
+
}).strict();
|
|
67864
|
+
var CrHelloOk = external_exports.object({ relayId: external_exports.string().min(1).max(64) });
|
|
67865
|
+
var CrHttpRequest = external_exports.object({
|
|
67866
|
+
method: external_exports.enum(["GET", "POST", "DELETE"]),
|
|
67867
|
+
path: external_exports.string().min(1).max(2048),
|
|
67868
|
+
headers: Headers2,
|
|
67869
|
+
body: Base64.optional()
|
|
67870
|
+
});
|
|
67871
|
+
var CrHttpResponse = external_exports.object({
|
|
67872
|
+
status: external_exports.number().int().min(100).max(599),
|
|
67873
|
+
headers: Headers2,
|
|
67874
|
+
body: Base64.optional()
|
|
67875
|
+
});
|
|
67876
|
+
var RELAY_COMPUTER_SCHEMAS = {
|
|
67877
|
+
"cr/hello": CrHello,
|
|
67878
|
+
"cr/hello/ok": CrHelloOk,
|
|
67879
|
+
"cr/http": CrHttpRequest,
|
|
67880
|
+
"cr/http/result": CrHttpResponse,
|
|
67881
|
+
error: ErrorFrame
|
|
67882
|
+
};
|
|
67883
|
+
var RelayComputerFrame = external_exports.discriminatedUnion("type", [
|
|
67884
|
+
frameSchema("cr/hello", RELAY_COMPUTER_SCHEMAS["cr/hello"]),
|
|
67885
|
+
frameSchema("cr/hello/ok", RELAY_COMPUTER_SCHEMAS["cr/hello/ok"]),
|
|
67886
|
+
frameSchema("cr/http", RELAY_COMPUTER_SCHEMAS["cr/http"]),
|
|
67887
|
+
frameSchema("cr/http/result", RELAY_COMPUTER_SCHEMAS["cr/http/result"]),
|
|
67888
|
+
frameSchema("error", RELAY_COMPUTER_SCHEMAS["error"])
|
|
67889
|
+
]);
|
|
67890
|
+
function decodeRelayComputerFrame(text) {
|
|
67891
|
+
return decodeEnvelopeWith(RELAY_COMPUTER_SCHEMAS, text, {
|
|
67892
|
+
maxBytes: RELAY_COMPUTER_MAX_FRAME_BYTES
|
|
67943
67893
|
});
|
|
67944
67894
|
}
|
|
67945
|
-
function
|
|
67946
|
-
|
|
67947
|
-
for (const record2 of readLogRecords(data)) {
|
|
67948
|
-
const reader = new Reader(record2);
|
|
67949
|
-
while (!reader.done) {
|
|
67950
|
-
const tag = reader.varint();
|
|
67951
|
-
if (tag === 1) reader.slice();
|
|
67952
|
-
else if (tag === 2) manifest.logNumber = reader.varint();
|
|
67953
|
-
else if (tag === 3) reader.varint();
|
|
67954
|
-
else if (tag === 4) reader.varint();
|
|
67955
|
-
else if (tag === 5) {
|
|
67956
|
-
reader.varint();
|
|
67957
|
-
reader.slice();
|
|
67958
|
-
} else if (tag === 6) {
|
|
67959
|
-
reader.varint();
|
|
67960
|
-
manifest.tables.delete(reader.varint());
|
|
67961
|
-
} else if (tag === 7) {
|
|
67962
|
-
reader.varint();
|
|
67963
|
-
manifest.tables.add(reader.varint());
|
|
67964
|
-
reader.varint();
|
|
67965
|
-
reader.slice();
|
|
67966
|
-
reader.slice();
|
|
67967
|
-
} else if (tag === 9) manifest.prevLogNumber = reader.varint();
|
|
67968
|
-
else throw new Error(`leveldb: unknown manifest tag ${tag}`);
|
|
67969
|
-
}
|
|
67970
|
-
}
|
|
67971
|
-
return manifest;
|
|
67895
|
+
function buildRelayComputerFrame(type, payload, opts = {}) {
|
|
67896
|
+
return buildEnvelopeRaw(type, payload, opts);
|
|
67972
67897
|
}
|
|
67973
|
-
|
|
67974
|
-
|
|
67975
|
-
|
|
67976
|
-
|
|
67977
|
-
|
|
67978
|
-
|
|
67979
|
-
|
|
67980
|
-
|
|
67981
|
-
|
|
67982
|
-
|
|
67983
|
-
|
|
67984
|
-
|
|
67985
|
-
|
|
67986
|
-
|
|
67987
|
-
|
|
67988
|
-
|
|
67989
|
-
|
|
67990
|
-
|
|
67991
|
-
|
|
67898
|
+
|
|
67899
|
+
// ../protocol/src/frames/computer-keys.ts
|
|
67900
|
+
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
67901
|
+
var COMPUTER_KEY_ALIASES = {
|
|
67902
|
+
enter: "return",
|
|
67903
|
+
esc: "escape",
|
|
67904
|
+
control: "ctrl",
|
|
67905
|
+
option: "alt"
|
|
67906
|
+
};
|
|
67907
|
+
function normalizeComputerKey(key) {
|
|
67908
|
+
const lowered = key.trim().toLowerCase();
|
|
67909
|
+
return COMPUTER_KEY_ALIASES[lowered] ?? lowered;
|
|
67910
|
+
}
|
|
67911
|
+
|
|
67912
|
+
// ../protocol/src/frames/computer.ts
|
|
67913
|
+
var COMPUTER_CP_SUBPROTOCOL = "agentconnect.computer.v1";
|
|
67914
|
+
var COMPUTER_WS_PUBLIC_PATH = "/v1/computers/ws";
|
|
67915
|
+
var COMPUTER_REGISTER_PUBLIC_PATH = "/v1/computers/register";
|
|
67916
|
+
var COMPUTER_SESSIONS = ["aqua", "console", "rdp", "x11", "xvfb", "wayland-gnome"];
|
|
67917
|
+
var COMPUTER_LIVE_STATUSES = ["online", "locked", "paused", "human_in_control", "busy"];
|
|
67918
|
+
var HHMM = "(?:[01]\\d|2[0-3]):[0-5]\\d";
|
|
67919
|
+
var QUIET_RANGE_RE = new RegExp(`^${HHMM}-${HHMM}$`);
|
|
67920
|
+
function isTimeZone(tz) {
|
|
67921
|
+
try {
|
|
67922
|
+
new Intl.DateTimeFormat("en-US", { timeZone: tz });
|
|
67923
|
+
return true;
|
|
67924
|
+
} catch {
|
|
67925
|
+
return false;
|
|
67992
67926
|
}
|
|
67993
|
-
const out = /* @__PURE__ */ new Map();
|
|
67994
|
-
for (const [key, entry] of entries2) if (!entry.deleted) out.set(key, entry.value);
|
|
67995
|
-
return out;
|
|
67996
67927
|
}
|
|
67997
|
-
|
|
67998
|
-
|
|
67999
|
-
|
|
68000
|
-
|
|
68001
|
-
|
|
68002
|
-
|
|
68003
|
-
|
|
68004
|
-
|
|
68005
|
-
|
|
68006
|
-
|
|
68007
|
-
|
|
68008
|
-
|
|
68009
|
-
|
|
68010
|
-
|
|
68011
|
-
|
|
68012
|
-
|
|
68013
|
-
|
|
68014
|
-
|
|
68015
|
-
|
|
68016
|
-
|
|
68017
|
-
|
|
68018
|
-
|
|
68019
|
-
|
|
68020
|
-
|
|
68021
|
-
|
|
68022
|
-
|
|
67928
|
+
var AppId = external_exports.string().trim().min(1).max(256);
|
|
67929
|
+
var COMPUTER_ACCESS_AGENTS_MAX = 200;
|
|
67930
|
+
var COMPUTER_AGENT_ACCESS_MODES = ["none", "selected", "all"];
|
|
67931
|
+
var ComputerAgentAccess = external_exports.object({
|
|
67932
|
+
mode: external_exports.enum(COMPUTER_AGENT_ACCESS_MODES),
|
|
67933
|
+
agents: external_exports.array(external_exports.uuid()).max(COMPUTER_ACCESS_AGENTS_MAX).default([])
|
|
67934
|
+
});
|
|
67935
|
+
var ComputerPolicySchema = external_exports.object({
|
|
67936
|
+
allowedMembers: external_exports.array(external_exports.string().min(1).max(128)).max(500).default([]),
|
|
67937
|
+
agentMode: external_exports.enum(["view", "control"]).default("control"),
|
|
67938
|
+
approvals: ComputerApprovalsSchema.default({ firstInputPerSession: true }),
|
|
67939
|
+
appAllowlist: external_exports.array(AppId).max(200).optional(),
|
|
67940
|
+
redactApps: external_exports.array(AppId).max(200).default([]),
|
|
67941
|
+
exposeDriverTools: external_exports.boolean().default(false),
|
|
67942
|
+
quietHours: external_exports.object({
|
|
67943
|
+
tz: external_exports.string().min(1).max(64).refine(isTimeZone, "unknown IANA time zone"),
|
|
67944
|
+
ranges: external_exports.array(external_exports.string().regex(QUIET_RANGE_RE, "expected HH:MM-HH:MM")).min(1).max(24)
|
|
67945
|
+
}).optional(),
|
|
67946
|
+
leaseIdleSeconds: external_exports.number().int().min(10).max(3600).default(120),
|
|
67947
|
+
leaseMaxSeconds: external_exports.number().int().min(60).max(86400).default(1800),
|
|
67948
|
+
// Seconds an acquire waits in the FIFO lease queue before `computer_busy` (§4.4); 0 never waits.
|
|
67949
|
+
leaseWaitSeconds: external_exports.number().int().min(0).max(COMPUTER_LEASE_WAIT_MAX_SECONDS).default(45),
|
|
67950
|
+
// Days stored screenshots are kept (§9); 0 means never written, absent means the deployment's default.
|
|
67951
|
+
screenshotRetentionDays: external_exports.number().int().min(0).max(COMPUTER_SCREENSHOT_RETENTION_MAX_DAYS).optional(),
|
|
67952
|
+
// Whether viewers may hole-punch peer to peer, which shows them the desktop's public IP (§7.2); absent means on only for owner-only viewing.
|
|
67953
|
+
viewerPeerToPeer: external_exports.boolean().optional(),
|
|
67954
|
+
// The command-line tier (§5.7); absent means the Computer's default, on for a managed one and off otherwise.
|
|
67955
|
+
shell: external_exports.enum(COMPUTER_SHELL_MODES).optional(),
|
|
67956
|
+
files: external_exports.enum(COMPUTER_FILES_MODES).optional(),
|
|
67957
|
+
// Prefixes the file tools may touch; absent means the user's home directory.
|
|
67958
|
+
fileRoots: external_exports.array(ComputerFileRoot).max(COMPUTER_FILE_ROOTS_MAX).optional(),
|
|
67959
|
+
// Per-agent desktops fork and merge the registrant's browser logins (§3.9); absent means on.
|
|
67960
|
+
shareBrowserLogins: external_exports.boolean().optional()
|
|
67961
|
+
}).refine((p) => p.leaseIdleSeconds <= p.leaseMaxSeconds, {
|
|
67962
|
+
message: "leaseIdleSeconds must not exceed leaseMaxSeconds",
|
|
67963
|
+
path: ["leaseIdleSeconds"]
|
|
67964
|
+
}).refine((p) => p.agentMode === "control" || p.shell === void 0 || p.shell === "off", {
|
|
67965
|
+
message: "a shell needs agentMode control",
|
|
67966
|
+
path: ["shell"]
|
|
67967
|
+
});
|
|
67968
|
+
var ComputerCapabilitiesSchema = external_exports.object({
|
|
67969
|
+
screenshot: external_exports.boolean().default(false),
|
|
67970
|
+
input: external_exports.boolean().default(false),
|
|
67971
|
+
textInput: external_exports.enum(["full", "keymap-only"]).default("full"),
|
|
67972
|
+
// Which human input pauses agents (§6); absent reads as pointer only, what older desktops detect.
|
|
67973
|
+
humanActivity: external_exports.enum(["pointer", "pointer+keyboard"]).optional(),
|
|
67974
|
+
backgroundInput: external_exports.boolean().default(false),
|
|
67975
|
+
accessibilityTree: external_exports.boolean().default(false),
|
|
67976
|
+
viewer: external_exports.boolean().default(false),
|
|
67977
|
+
// The viewer accepts a view token's `stun` claim; desktops before relay STUN refuse such a token.
|
|
67978
|
+
viewerStun: external_exports.boolean().optional(),
|
|
67979
|
+
// The browser's traffic leaves through the desktop's egress forwarder, which applies `computer/egress` (§15.4).
|
|
67980
|
+
egress: external_exports.boolean().optional(),
|
|
67981
|
+
// The command-line tier can run here (§5.7): computer_exec, and the file tools.
|
|
67982
|
+
exec: external_exports.boolean().optional(),
|
|
67983
|
+
files: external_exports.boolean().optional(),
|
|
67984
|
+
displays: external_exports.array(
|
|
67985
|
+
external_exports.object({
|
|
67986
|
+
id: external_exports.string().min(1).max(128),
|
|
67987
|
+
width: external_exports.number().int().positive().max(1e5),
|
|
67988
|
+
height: external_exports.number().int().positive().max(1e5),
|
|
67989
|
+
scale: external_exports.number().positive().max(16)
|
|
67990
|
+
})
|
|
67991
|
+
).max(16).default([]),
|
|
67992
|
+
permissions: external_exports.object({
|
|
67993
|
+
accessibility: external_exports.boolean().optional(),
|
|
67994
|
+
screenRecording: external_exports.boolean().optional(),
|
|
67995
|
+
portal: external_exports.boolean().optional(),
|
|
67996
|
+
firewall: external_exports.boolean().optional()
|
|
67997
|
+
}).default({})
|
|
67998
|
+
});
|
|
67999
|
+
var ComputerDoctorCheck = external_exports.object({
|
|
68000
|
+
name: external_exports.string().min(1).max(64),
|
|
68001
|
+
status: external_exports.enum(["ok", "info", "warn", "fail"]),
|
|
68002
|
+
detail: external_exports.string().max(1e3),
|
|
68003
|
+
fix: external_exports.string().max(1e3).optional()
|
|
68004
|
+
});
|
|
68005
|
+
var ComputerDoctorReport = external_exports.object({
|
|
68006
|
+
checkedAt: external_exports.string().datetime(),
|
|
68007
|
+
checks: external_exports.array(ComputerDoctorCheck).max(64)
|
|
68008
|
+
});
|
|
68009
|
+
var ComputerChannelCredential = external_exports.object({
|
|
68010
|
+
keyId: external_exports.string().min(1).max(64),
|
|
68011
|
+
// 32 random-looking bytes, base64url without padding; secret material, never logged.
|
|
68012
|
+
key: external_exports.string().regex(/^[A-Za-z0-9_-]{43}$/),
|
|
68013
|
+
issuedAt: external_exports.string().datetime(),
|
|
68014
|
+
expiresAt: external_exports.string().datetime()
|
|
68015
|
+
});
|
|
68016
|
+
var ComputerEgressProxyUrl = external_exports.string().max(512).refine((raw) => {
|
|
68017
|
+
try {
|
|
68018
|
+
const u = new URL(raw);
|
|
68019
|
+
return (u.protocol === "http:" || u.protocol === "https:") && u.hostname !== "" && u.username === "" && u.password === "" && (u.pathname === "" || u.pathname === "/") && u.search === "" && u.hash === "";
|
|
68020
|
+
} catch {
|
|
68021
|
+
return false;
|
|
68023
68022
|
}
|
|
68024
|
-
|
|
68025
|
-
|
|
68026
|
-
|
|
68027
|
-
|
|
68028
|
-
|
|
68029
|
-
|
|
68030
|
-
|
|
68031
|
-
|
|
68032
|
-
|
|
68033
|
-
|
|
68034
|
-
|
|
68035
|
-
|
|
68036
|
-
|
|
68037
|
-
|
|
68023
|
+
}, "expected http://host:port or https://host:port without credentials or a path");
|
|
68024
|
+
var ComputerEgress = external_exports.discriminatedUnion("mode", [
|
|
68025
|
+
external_exports.object({ mode: external_exports.literal("direct") }),
|
|
68026
|
+
external_exports.object({
|
|
68027
|
+
mode: external_exports.literal("proxy"),
|
|
68028
|
+
url: ComputerEgressProxyUrl,
|
|
68029
|
+
username: external_exports.string().min(1).max(256).optional(),
|
|
68030
|
+
password: external_exports.string().min(1).max(512).optional()
|
|
68031
|
+
})
|
|
68032
|
+
]);
|
|
68033
|
+
var COMPUTER_EGRESS_FEATURE = "computer-egress-v1";
|
|
68034
|
+
var ComputerAuth = external_exports.object({
|
|
68035
|
+
apiKey: external_exports.string().min(1).max(256),
|
|
68036
|
+
desktopDaemonVersion: external_exports.string().trim().min(1).max(64)
|
|
68037
|
+
}).strict();
|
|
68038
|
+
var ComputerAuthOk = external_exports.object({
|
|
68039
|
+
computerId: external_exports.string().uuid(),
|
|
68040
|
+
orgId: external_exports.string().min(1).max(64),
|
|
68041
|
+
name: external_exports.string().min(1).max(200),
|
|
68042
|
+
heartbeatSec: external_exports.number().int().positive(),
|
|
68043
|
+
serverTime: external_exports.string().datetime(),
|
|
68044
|
+
credential: ComputerChannelCredential,
|
|
68045
|
+
policy: ComputerPolicySchema,
|
|
68046
|
+
// What this CP accepts on the channel beyond the base frames, such as `computer-audit-v1`.
|
|
68047
|
+
features: external_exports.array(external_exports.string().min(1).max(64)).max(32).optional(),
|
|
68048
|
+
// The retention in effect for this Computer's screenshots (§9); 0 or absent means none are stored.
|
|
68049
|
+
screenshotRetentionDays: external_exports.number().int().min(0).max(COMPUTER_SCREENSHOT_RETENTION_MAX_DAYS).optional(),
|
|
68050
|
+
// A managed desktop's egress (§15.4); absent means direct unless `computer-egress-v1` is advertised. Secret, never logged.
|
|
68051
|
+
egress: ComputerEgress.optional()
|
|
68052
|
+
});
|
|
68053
|
+
var COMPUTER_DESKTOPS_FEATURE = "computer-desktops-v1";
|
|
68054
|
+
var COMPUTER_DESKTOPS_MAX = 64;
|
|
68055
|
+
var ComputerDesktopReport = external_exports.object({
|
|
68056
|
+
id: ComputerDesktopId,
|
|
68057
|
+
agentId: external_exports.string().uuid(),
|
|
68058
|
+
status: external_exports.enum(COMPUTER_LIVE_STATUSES),
|
|
68059
|
+
lease: external_exports.object({
|
|
68060
|
+
holder: external_exports.string().min(1).max(512),
|
|
68061
|
+
idleMs: external_exports.number().int().min(0),
|
|
68062
|
+
heldMs: external_exports.number().int().min(0).optional()
|
|
68063
|
+
}).strict().optional()
|
|
68064
|
+
}).strict();
|
|
68065
|
+
var ComputerHeartbeat = external_exports.object({
|
|
68066
|
+
status: external_exports.enum(COMPUTER_LIVE_STATUSES),
|
|
68067
|
+
osVersion: external_exports.string().trim().min(1).max(120).optional(),
|
|
68068
|
+
session: external_exports.enum(COMPUTER_SESSIONS).optional(),
|
|
68069
|
+
desktopDaemonVersion: external_exports.string().trim().min(1).max(64).optional(),
|
|
68070
|
+
driverVersion: external_exports.string().trim().min(1).max(64).optional(),
|
|
68071
|
+
capabilities: ComputerCapabilitiesSchema.optional(),
|
|
68072
|
+
doctor: ComputerDoctorReport.optional(),
|
|
68073
|
+
// The local lease, how long since its last input, and how long it has been held without idling out.
|
|
68074
|
+
lease: external_exports.object({
|
|
68075
|
+
holder: external_exports.string().min(1).max(512),
|
|
68076
|
+
idleMs: external_exports.number().int().min(0),
|
|
68077
|
+
heldMs: external_exports.number().int().min(0).optional()
|
|
68078
|
+
}).strict().optional(),
|
|
68079
|
+
// Behind `computer-desktops-v1`: present (even empty) while each agent gets a desktop of its own; `status` is the main one's.
|
|
68080
|
+
desktops: external_exports.array(ComputerDesktopReport).max(COMPUTER_DESKTOPS_MAX).optional()
|
|
68081
|
+
}).strict();
|
|
68082
|
+
var ComputerCredentialRenewal = external_exports.object({ credential: ComputerChannelCredential });
|
|
68083
|
+
var ComputerPolicyPush = external_exports.object({
|
|
68084
|
+
policy: ComputerPolicySchema,
|
|
68085
|
+
screenshotRetentionDays: external_exports.number().int().min(0).max(COMPUTER_SCREENSHOT_RETENTION_MAX_DAYS).optional()
|
|
68086
|
+
});
|
|
68087
|
+
var ComputerRevoke = external_exports.object({
|
|
68088
|
+
reason: external_exports.enum(["revoked", "deleted", "owner_removed"]),
|
|
68089
|
+
message: external_exports.string().max(500).optional()
|
|
68090
|
+
});
|
|
68091
|
+
var ComputerLeasePush = external_exports.object({
|
|
68092
|
+
lease: ComputerControlLease.nullable(),
|
|
68093
|
+
desktops: external_exports.array(ComputerControlLease).max(COMPUTER_DESKTOPS_MAX).optional()
|
|
68094
|
+
});
|
|
68095
|
+
var ComputerRelaysPush = external_exports.object({ relays: external_exports.array(ComputerRelayEntry).max(COMPUTER_RELAYS_MAX) });
|
|
68096
|
+
var ComputerStopPush = external_exports.object({ stop: external_exports.object({ at: external_exports.string().datetime() }).nullable() });
|
|
68097
|
+
var ComputerEgressPush = external_exports.object({ egress: ComputerEgress });
|
|
68098
|
+
var COMPUTER_ADMIN_PROMPTS_FEATURE = "computer-admin-prompts-v1";
|
|
68099
|
+
var ComputerAdminPromptsSet = external_exports.object({ mode: external_exports.enum(COMPUTER_ADMIN_PROMPT_MODES) }).strict();
|
|
68100
|
+
var ComputerAdminPromptsSetOk = external_exports.object({ mode: external_exports.enum(COMPUTER_ADMIN_PROMPT_MODES) });
|
|
68101
|
+
var COMPUTER_CP_SCHEMAS = {
|
|
68102
|
+
"computer/auth": ComputerAuth,
|
|
68103
|
+
"computer/auth/ok": ComputerAuthOk,
|
|
68104
|
+
"computer/heartbeat": ComputerHeartbeat,
|
|
68105
|
+
"computer/credential": ComputerCredentialRenewal,
|
|
68106
|
+
"computer/policy": ComputerPolicyPush,
|
|
68107
|
+
"computer/revoke": ComputerRevoke,
|
|
68108
|
+
"computer/lease": ComputerLeasePush,
|
|
68109
|
+
"computer/relays": ComputerRelaysPush,
|
|
68110
|
+
"computer/stop": ComputerStopPush,
|
|
68111
|
+
"computer/egress": ComputerEgressPush,
|
|
68112
|
+
"computer/admin-prompts": ComputerAdminPromptsSet,
|
|
68113
|
+
"computer/admin-prompts/ok": ComputerAdminPromptsSetOk,
|
|
68114
|
+
"computer/audit": ComputerAuditReport,
|
|
68115
|
+
"computer/audit/ok": ComputerAuditAck,
|
|
68116
|
+
"computer/screenshot/put": ComputerScreenshotPut,
|
|
68117
|
+
"computer/screenshot/put/ok": ComputerScreenshotPutOk,
|
|
68118
|
+
"computer/screenshot/commit": ComputerScreenshotCommit,
|
|
68119
|
+
"computer/screenshot/commit/ok": ComputerScreenshotCommitOk,
|
|
68120
|
+
error: ErrorFrame
|
|
68121
|
+
};
|
|
68122
|
+
var COMPUTER_CP_FRAME_TYPES = Object.keys(COMPUTER_CP_SCHEMAS);
|
|
68123
|
+
var ComputerCpFrame = external_exports.discriminatedUnion("type", [
|
|
68124
|
+
frameSchema("computer/auth", COMPUTER_CP_SCHEMAS["computer/auth"]),
|
|
68125
|
+
frameSchema("computer/auth/ok", COMPUTER_CP_SCHEMAS["computer/auth/ok"]),
|
|
68126
|
+
frameSchema("computer/heartbeat", COMPUTER_CP_SCHEMAS["computer/heartbeat"]),
|
|
68127
|
+
frameSchema("computer/credential", COMPUTER_CP_SCHEMAS["computer/credential"]),
|
|
68128
|
+
frameSchema("computer/policy", COMPUTER_CP_SCHEMAS["computer/policy"]),
|
|
68129
|
+
frameSchema("computer/revoke", COMPUTER_CP_SCHEMAS["computer/revoke"]),
|
|
68130
|
+
frameSchema("computer/lease", COMPUTER_CP_SCHEMAS["computer/lease"]),
|
|
68131
|
+
frameSchema("computer/relays", COMPUTER_CP_SCHEMAS["computer/relays"]),
|
|
68132
|
+
frameSchema("computer/stop", COMPUTER_CP_SCHEMAS["computer/stop"]),
|
|
68133
|
+
frameSchema("computer/egress", COMPUTER_CP_SCHEMAS["computer/egress"]),
|
|
68134
|
+
frameSchema("computer/admin-prompts", COMPUTER_CP_SCHEMAS["computer/admin-prompts"]),
|
|
68135
|
+
frameSchema("computer/admin-prompts/ok", COMPUTER_CP_SCHEMAS["computer/admin-prompts/ok"]),
|
|
68136
|
+
frameSchema("computer/audit", COMPUTER_CP_SCHEMAS["computer/audit"]),
|
|
68137
|
+
frameSchema("computer/audit/ok", COMPUTER_CP_SCHEMAS["computer/audit/ok"]),
|
|
68138
|
+
frameSchema("computer/screenshot/put", COMPUTER_CP_SCHEMAS["computer/screenshot/put"]),
|
|
68139
|
+
frameSchema("computer/screenshot/put/ok", COMPUTER_CP_SCHEMAS["computer/screenshot/put/ok"]),
|
|
68140
|
+
frameSchema("computer/screenshot/commit", COMPUTER_CP_SCHEMAS["computer/screenshot/commit"]),
|
|
68141
|
+
frameSchema("computer/screenshot/commit/ok", COMPUTER_CP_SCHEMAS["computer/screenshot/commit/ok"]),
|
|
68142
|
+
frameSchema("error", COMPUTER_CP_SCHEMAS["error"])
|
|
68143
|
+
]);
|
|
68144
|
+
var TOLERANT_COMPUTER_CP_SCHEMAS = tolerantSchemas(COMPUTER_CP_SCHEMAS);
|
|
68145
|
+
function decodeComputerCpFrameTolerant(text) {
|
|
68146
|
+
return decodeEnvelopeWith(TOLERANT_COMPUTER_CP_SCHEMAS, text);
|
|
68038
68147
|
}
|
|
68039
|
-
|
|
68040
|
-
|
|
68041
|
-
var BASELINE_FILE = "ac-fork-baseline.json";
|
|
68042
|
-
var CHROME_EPOCH_OFFSET_US = 11644473600000000n;
|
|
68043
|
-
var SNAPSHOT_TRIES = 6;
|
|
68044
|
-
var SNAPSHOT_RETRY_MS = 300;
|
|
68045
|
-
function cookiesPath(profile) {
|
|
68046
|
-
const network = join3(profile, "Default", "Network", "Cookies");
|
|
68047
|
-
return existsSync2(network) ? network : join3(profile, "Default", "Cookies");
|
|
68148
|
+
function buildComputerCpFrame(type, payload, opts = {}) {
|
|
68149
|
+
return buildEnvelopeRaw(type, payload, opts);
|
|
68048
68150
|
}
|
|
68049
|
-
|
|
68050
|
-
|
|
68051
|
-
|
|
68052
|
-
|
|
68053
|
-
|
|
68054
|
-
|
|
68151
|
+
|
|
68152
|
+
// src/admin-prompts.ts
|
|
68153
|
+
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
68154
|
+
import { spawn } from "node:child_process";
|
|
68155
|
+
import { createInterface } from "node:readline";
|
|
68156
|
+
var ANSWER_TIMEOUT_MS = 1e4;
|
|
68157
|
+
var RESTART_MS = 5e3;
|
|
68158
|
+
var str = (value) => typeof value === "string" && value !== "" ? value : void 0;
|
|
68159
|
+
var AdminPromptHelper = class _AdminPromptHelper {
|
|
68160
|
+
constructor(path, options) {
|
|
68161
|
+
this.path = path;
|
|
68162
|
+
this.options = options;
|
|
68163
|
+
}
|
|
68164
|
+
path;
|
|
68165
|
+
options;
|
|
68166
|
+
problem;
|
|
68167
|
+
current;
|
|
68168
|
+
child;
|
|
68169
|
+
closed = false;
|
|
68170
|
+
waiting = /* @__PURE__ */ new Map();
|
|
68171
|
+
static start(path, options) {
|
|
68172
|
+
const helper = new _AdminPromptHelper(path, options);
|
|
68173
|
+
helper.spawn();
|
|
68174
|
+
return helper;
|
|
68175
|
+
}
|
|
68176
|
+
pending() {
|
|
68177
|
+
return this.current;
|
|
68178
|
+
}
|
|
68179
|
+
answer(id, answer) {
|
|
68180
|
+
const child2 = this.child;
|
|
68181
|
+
if (!child2?.stdin || this.problem)
|
|
68182
|
+
return Promise.reject(new Error(this.problem ?? "the prompt helper is not running"));
|
|
68183
|
+
return new Promise((resolve5, reject) => {
|
|
68184
|
+
const timer = setTimeout(() => {
|
|
68185
|
+
this.waiting.delete(id);
|
|
68186
|
+
reject(new Error("the prompt helper did not answer in time"));
|
|
68187
|
+
}, ANSWER_TIMEOUT_MS);
|
|
68188
|
+
timer.unref();
|
|
68189
|
+
this.waiting.set(id, {
|
|
68190
|
+
resolve: () => (clearTimeout(timer), resolve5()),
|
|
68191
|
+
reject: (error63) => (clearTimeout(timer), reject(error63))
|
|
68192
|
+
});
|
|
68193
|
+
child2.stdin.write(`${JSON.stringify({ id, answer })}
|
|
68194
|
+
`);
|
|
68055
68195
|
});
|
|
68056
|
-
try {
|
|
68057
|
-
sqlite = process.getBuiltinModule("node:sqlite");
|
|
68058
|
-
} finally {
|
|
68059
|
-
process.emitWarning = emit;
|
|
68060
|
-
}
|
|
68061
68196
|
}
|
|
68062
|
-
|
|
68063
|
-
|
|
68064
|
-
|
|
68065
|
-
|
|
68066
|
-
|
|
68067
|
-
|
|
68068
|
-
|
|
68069
|
-
|
|
68070
|
-
|
|
68071
|
-
|
|
68072
|
-
|
|
68073
|
-
|
|
68074
|
-
|
|
68075
|
-
|
|
68197
|
+
close() {
|
|
68198
|
+
this.closed = true;
|
|
68199
|
+
this.child?.stdin?.end();
|
|
68200
|
+
}
|
|
68201
|
+
spawn() {
|
|
68202
|
+
const child2 = (this.options.spawnHelper ?? ((file2) => spawn(file2, [], { stdio: ["pipe", "pipe", "inherit"], windowsHide: true })))(this.path);
|
|
68203
|
+
this.child = child2;
|
|
68204
|
+
child2.stdin?.on("error", () => void 0);
|
|
68205
|
+
child2.on("error", (error63) => this.gone(`cannot start the administrator prompt helper: ${error63.message}`));
|
|
68206
|
+
child2.on(
|
|
68207
|
+
"exit",
|
|
68208
|
+
(code, signal) => this.gone(`the administrator prompt helper exited (${signal ?? `code ${code}`})`)
|
|
68209
|
+
);
|
|
68210
|
+
if (child2.stdout) createInterface({ input: child2.stdout }).on("line", (line) => this.received(line));
|
|
68211
|
+
}
|
|
68212
|
+
received(line) {
|
|
68213
|
+
let message;
|
|
68076
68214
|
try {
|
|
68077
|
-
|
|
68078
|
-
|
|
68079
|
-
|
|
68080
|
-
|
|
68081
|
-
|
|
68082
|
-
|
|
68083
|
-
|
|
68084
|
-
|
|
68085
|
-
|
|
68086
|
-
|
|
68087
|
-
|
|
68215
|
+
message = JSON.parse(line);
|
|
68216
|
+
} catch {
|
|
68217
|
+
return;
|
|
68218
|
+
}
|
|
68219
|
+
const id = str(message.id);
|
|
68220
|
+
switch (message.event) {
|
|
68221
|
+
case "prompt": {
|
|
68222
|
+
if (!id) return;
|
|
68223
|
+
this.current = {
|
|
68224
|
+
id,
|
|
68225
|
+
kind: message.kind === "credentials" ? "credentials" : "consent",
|
|
68226
|
+
...str(message.app) ? { app: str(message.app) } : {},
|
|
68227
|
+
...str(message.publisher) ? { publisher: str(message.publisher) } : {},
|
|
68228
|
+
...str(message.command) ? { command: str(message.command) } : {},
|
|
68229
|
+
lines: Array.isArray(message.lines) ? message.lines.filter((l) => typeof l === "string") : []
|
|
68230
|
+
};
|
|
68231
|
+
this.options.log(`administrator prompt: ${this.current.app ?? "an app"} asks to run as administrator`);
|
|
68232
|
+
return this.options.onChange();
|
|
68088
68233
|
}
|
|
68089
|
-
|
|
68090
|
-
|
|
68091
|
-
|
|
68092
|
-
|
|
68093
|
-
|
|
68094
|
-
|
|
68095
|
-
|
|
68096
|
-
|
|
68097
|
-
|
|
68234
|
+
case "gone":
|
|
68235
|
+
if (id && this.current?.id === id) {
|
|
68236
|
+
this.current = void 0;
|
|
68237
|
+
this.options.onChange();
|
|
68238
|
+
}
|
|
68239
|
+
return;
|
|
68240
|
+
case "answered": {
|
|
68241
|
+
const waiter = id ? this.waiting.get(id) : void 0;
|
|
68242
|
+
if (!waiter || !id) return;
|
|
68243
|
+
this.waiting.delete(id);
|
|
68244
|
+
if (message.ok === true) waiter.resolve();
|
|
68245
|
+
else waiter.reject(new Error(str(message.error) ?? "the prompt could not be answered"));
|
|
68246
|
+
return;
|
|
68247
|
+
}
|
|
68248
|
+
case "problem": {
|
|
68249
|
+
const problem = str(message.message);
|
|
68250
|
+
if (problem === this.problem) return;
|
|
68251
|
+
this.problem = problem;
|
|
68252
|
+
if (problem) this.options.log(`administrator prompts: ${problem}`);
|
|
68253
|
+
return this.options.onChange();
|
|
68098
68254
|
}
|
|
68099
|
-
baselines.sources[key] = next;
|
|
68100
|
-
reports.push(report);
|
|
68101
|
-
} finally {
|
|
68102
|
-
rmSync2(work, { recursive: true, force: true });
|
|
68103
68255
|
}
|
|
68104
68256
|
}
|
|
68105
|
-
|
|
68106
|
-
|
|
68107
|
-
|
|
68108
|
-
|
|
68109
|
-
|
|
68110
|
-
|
|
68111
|
-
|
|
68112
|
-
|
|
68257
|
+
gone(problem) {
|
|
68258
|
+
if (this.closed) return;
|
|
68259
|
+
this.problem = problem;
|
|
68260
|
+
this.current = void 0;
|
|
68261
|
+
for (const waiter of this.waiting.values()) waiter.reject(new Error(problem));
|
|
68262
|
+
this.waiting.clear();
|
|
68263
|
+
this.options.log(`administrator prompts: ${problem}; starting it again`);
|
|
68264
|
+
this.options.onChange();
|
|
68265
|
+
const child2 = this.child;
|
|
68266
|
+
this.child = void 0;
|
|
68267
|
+
if (child2)
|
|
68268
|
+
setTimeout(() => {
|
|
68269
|
+
if (this.closed) return;
|
|
68270
|
+
this.problem = void 0;
|
|
68271
|
+
this.spawn();
|
|
68272
|
+
}, this.options.restartMs ?? RESTART_MS).unref();
|
|
68113
68273
|
}
|
|
68114
|
-
|
|
68274
|
+
};
|
|
68275
|
+
|
|
68276
|
+
// src/audit.ts
|
|
68277
|
+
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
68278
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
68279
|
+
import { appendFileSync, mkdirSync } from "node:fs";
|
|
68280
|
+
import { dirname } from "node:path";
|
|
68281
|
+
var callContext = new AsyncLocalStorage();
|
|
68282
|
+
var withCallContext = (context, fn) => callContext.run(context, fn);
|
|
68283
|
+
var currentCallContext = () => callContext.getStore() ?? {};
|
|
68284
|
+
function auditSinks(...sinks) {
|
|
68285
|
+
return (record2) => {
|
|
68286
|
+
const full = { ...callContext.getStore(), ...record2 };
|
|
68287
|
+
for (const sink of sinks) sink(full);
|
|
68288
|
+
};
|
|
68115
68289
|
}
|
|
68116
|
-
|
|
68117
|
-
const
|
|
68118
|
-
const
|
|
68119
|
-
|
|
68120
|
-
snapshot.cookies = join3(work, "Cookies");
|
|
68121
|
-
cpSync(cookies, snapshot.cookies);
|
|
68122
|
-
for (const suffix of ["-journal", "-wal"]) {
|
|
68123
|
-
if (existsSync2(cookies + suffix)) cpSync(cookies + suffix, snapshot.cookies + suffix);
|
|
68124
|
-
}
|
|
68125
|
-
}
|
|
68126
|
-
const localStorage2 = localStoragePath(source);
|
|
68127
|
-
if (existsSync2(localStorage2)) {
|
|
68128
|
-
snapshot.localStorage = await retried(sleep3, () => {
|
|
68129
|
-
const copy = join3(work, "ls");
|
|
68130
|
-
rmSync2(copy, { recursive: true, force: true });
|
|
68131
|
-
cpSync(localStorage2, copy, { recursive: true, filter: (path) => basename(path) !== "LOCK" });
|
|
68132
|
-
return readLevelDb(copy);
|
|
68133
|
-
});
|
|
68134
|
-
}
|
|
68135
|
-
const indexedDb = indexedDbPath(source);
|
|
68136
|
-
if (existsSync2(indexedDb)) {
|
|
68137
|
-
snapshot.indexedDb = join3(work, "idb");
|
|
68138
|
-
await retried(sleep3, () => {
|
|
68139
|
-
rmSync2(snapshot.indexedDb, { recursive: true, force: true });
|
|
68140
|
-
cpSync(indexedDb, snapshot.indexedDb, {
|
|
68141
|
-
recursive: true,
|
|
68142
|
-
preserveTimestamps: true,
|
|
68143
|
-
filter: (path) => basename(path) !== "LOCK"
|
|
68144
|
-
});
|
|
68145
|
-
});
|
|
68290
|
+
function redactArgs(args) {
|
|
68291
|
+
const out = {};
|
|
68292
|
+
for (const [key, value] of Object.entries(args)) {
|
|
68293
|
+
out[key] = (key === "text" || key === "value" || key === "content") && typeof value === "string" ? `<${value.length} chars>` : value;
|
|
68146
68294
|
}
|
|
68147
|
-
return
|
|
68295
|
+
return out;
|
|
68148
68296
|
}
|
|
68149
|
-
|
|
68150
|
-
|
|
68151
|
-
|
|
68297
|
+
function fileAuditSink(path) {
|
|
68298
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
68299
|
+
return (record2) => {
|
|
68300
|
+
const line = JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), ...record2, args: redactArgs(record2.args) });
|
|
68152
68301
|
try {
|
|
68153
|
-
|
|
68302
|
+
appendFileSync(path, `${line}
|
|
68303
|
+
`);
|
|
68154
68304
|
} catch (error63) {
|
|
68155
|
-
|
|
68156
|
-
await sleep3(SNAPSHOT_RETRY_MS);
|
|
68305
|
+
console.error(`audit write failed: ${error63.message}`);
|
|
68157
68306
|
}
|
|
68158
|
-
}
|
|
68159
|
-
throw new Error(`could not snapshot a running profile: ${last.message}`);
|
|
68307
|
+
};
|
|
68160
68308
|
}
|
|
68161
|
-
|
|
68162
|
-
|
|
68163
|
-
|
|
68164
|
-
|
|
68165
|
-
|
|
68166
|
-
|
|
68167
|
-
|
|
68168
|
-
|
|
68169
|
-
|
|
68309
|
+
|
|
68310
|
+
// src/browser/command.ts
|
|
68311
|
+
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
68312
|
+
|
|
68313
|
+
// src/browser/close.ts
|
|
68314
|
+
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
68315
|
+
|
|
68316
|
+
// src/linux/x11.ts
|
|
68317
|
+
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
68318
|
+
import { readFileSync } from "node:fs";
|
|
68319
|
+
import { createConnection } from "node:net";
|
|
68320
|
+
import { homedir, hostname as hostname3 } from "node:os";
|
|
68321
|
+
import { join } from "node:path";
|
|
68322
|
+
function parseDisplay(display) {
|
|
68323
|
+
const match = /^([^:]*):(\d+)(?:\.\d+)?$/.exec(display ?? "");
|
|
68324
|
+
if (!match) return void 0;
|
|
68325
|
+
const host = match[1] ?? "";
|
|
68326
|
+
const number4 = Number(match[2]);
|
|
68327
|
+
if (host === "" || host === "unix") return { path: `/tmp/.X11-unix/X${number4}`, number: number4 };
|
|
68328
|
+
return { host, port: 6e3 + number4, number: number4 };
|
|
68170
68329
|
}
|
|
68171
|
-
|
|
68172
|
-
|
|
68173
|
-
|
|
68174
|
-
|
|
68330
|
+
var FAMILY_LOCAL = 256;
|
|
68331
|
+
var FAMILY_WILD = 65535;
|
|
68332
|
+
var COOKIE = "MIT-MAGIC-COOKIE-1";
|
|
68333
|
+
function xauthCookie(file2, number4, host = hostname3()) {
|
|
68334
|
+
let offset = 0;
|
|
68335
|
+
let fallback;
|
|
68336
|
+
const field = () => {
|
|
68337
|
+
const length = file2.readUInt16BE(offset);
|
|
68338
|
+
const value = file2.subarray(offset + 2, offset + 2 + length);
|
|
68339
|
+
offset += 2 + length;
|
|
68340
|
+
return value;
|
|
68341
|
+
};
|
|
68175
68342
|
try {
|
|
68176
|
-
|
|
68177
|
-
|
|
68178
|
-
|
|
68179
|
-
|
|
68180
|
-
|
|
68181
|
-
|
|
68182
|
-
|
|
68183
|
-
|
|
68184
|
-
|
|
68185
|
-
|
|
68186
|
-
statement.setReadBigInts(true);
|
|
68187
|
-
return statement.all();
|
|
68188
|
-
};
|
|
68189
|
-
const quoted = columns.map((column) => `"${column}"`).join(",");
|
|
68190
|
-
const mine = /* @__PURE__ */ new Map();
|
|
68191
|
-
for (const row of list2(db, `SELECT rowid AS ac_rowid, ${quoted} FROM cookies`)) {
|
|
68192
|
-
mine.set(keyOf2(row), { rowid: row.ac_rowid, stamp: row[stamp] });
|
|
68343
|
+
while (offset < file2.length) {
|
|
68344
|
+
const family = file2.readUInt16BE(offset);
|
|
68345
|
+
offset += 2;
|
|
68346
|
+
const address = field().toString("latin1");
|
|
68347
|
+
const display = field().toString("latin1");
|
|
68348
|
+
const name = field().toString("latin1");
|
|
68349
|
+
const data = field();
|
|
68350
|
+
if (name !== COOKIE || display !== "" && display !== String(number4)) continue;
|
|
68351
|
+
if (family === FAMILY_WILD || family === FAMILY_LOCAL && address === host) return Buffer.from(data);
|
|
68352
|
+
fallback ??= Buffer.from(data);
|
|
68193
68353
|
}
|
|
68194
|
-
|
|
68195
|
-
|
|
68196
|
-
|
|
68197
|
-
|
|
68354
|
+
} catch {
|
|
68355
|
+
}
|
|
68356
|
+
return fallback;
|
|
68357
|
+
}
|
|
68358
|
+
var pad4 = (n) => (4 - n % 4) % 4;
|
|
68359
|
+
var X11Error = class extends Error {
|
|
68360
|
+
constructor(code, sequence) {
|
|
68361
|
+
super(`X11 error ${code} (request ${sequence})`);
|
|
68362
|
+
this.code = code;
|
|
68363
|
+
this.sequence = sequence;
|
|
68364
|
+
this.name = "X11Error";
|
|
68365
|
+
}
|
|
68366
|
+
code;
|
|
68367
|
+
sequence;
|
|
68368
|
+
};
|
|
68369
|
+
var X11Connection = class _X11Connection {
|
|
68370
|
+
constructor(socket, setup2) {
|
|
68371
|
+
this.socket = socket;
|
|
68372
|
+
this.setup = setup2;
|
|
68373
|
+
socket.on("data", (chunk) => this.receive(chunk));
|
|
68374
|
+
socket.on("error", (error63) => this.close(error63));
|
|
68375
|
+
socket.on("close", () => this.close());
|
|
68376
|
+
}
|
|
68377
|
+
socket;
|
|
68378
|
+
setup;
|
|
68379
|
+
buffer = Buffer.alloc(0);
|
|
68380
|
+
sequence = 0;
|
|
68381
|
+
pending = /* @__PURE__ */ new Map();
|
|
68382
|
+
errors = /* @__PURE__ */ new Map();
|
|
68383
|
+
closed = false;
|
|
68384
|
+
onEvent = () => void 0;
|
|
68385
|
+
onClose = () => void 0;
|
|
68386
|
+
static async connect(options = {}) {
|
|
68387
|
+
const address = parseDisplay(options.display ?? process.env.DISPLAY);
|
|
68388
|
+
if (!address) throw new Error("DISPLAY is not set to an X11 display");
|
|
68389
|
+
const authFile = options.xauthority ?? process.env.XAUTHORITY ?? join(homedir(), ".Xauthority");
|
|
68390
|
+
let cookie;
|
|
68198
68391
|
try {
|
|
68199
|
-
|
|
68200
|
-
|
|
68201
|
-
|
|
68202
|
-
|
|
68203
|
-
|
|
68204
|
-
|
|
68205
|
-
|
|
68206
|
-
|
|
68392
|
+
cookie = xauthCookie(readFileSync(authFile), address.number);
|
|
68393
|
+
} catch {
|
|
68394
|
+
}
|
|
68395
|
+
const socket = options.socketPath ? createConnection(options.socketPath) : "path" in address ? createConnection(address.path) : createConnection(address.port, address.host);
|
|
68396
|
+
socket.setNoDelay(true);
|
|
68397
|
+
const timeoutMs = options.timeoutMs ?? 5e3;
|
|
68398
|
+
const setup2 = await new Promise((resolve5, reject) => {
|
|
68399
|
+
let data = Buffer.alloc(0);
|
|
68400
|
+
const timer = setTimeout(() => fail(new Error("X11 connection setup timed out")), timeoutMs);
|
|
68401
|
+
const fail = (error63) => {
|
|
68402
|
+
clearTimeout(timer);
|
|
68403
|
+
socket.off("data", onData);
|
|
68404
|
+
socket.destroy();
|
|
68405
|
+
reject(error63);
|
|
68406
|
+
};
|
|
68407
|
+
const onData = (chunk) => {
|
|
68408
|
+
data = Buffer.concat([data, chunk]);
|
|
68409
|
+
if (data.length < 8) return;
|
|
68410
|
+
const total = 8 + data.readUInt16LE(6) * 4;
|
|
68411
|
+
if (data.length < total) return;
|
|
68412
|
+
clearTimeout(timer);
|
|
68413
|
+
socket.off("data", onData);
|
|
68414
|
+
socket.off("error", fail);
|
|
68415
|
+
if (data[0] !== 1) {
|
|
68416
|
+
const reason = data.subarray(8, 8 + (data[1] ?? 0)).toString("latin1");
|
|
68417
|
+
socket.destroy();
|
|
68418
|
+
return reject(new Error(`X11 server refused the connection: ${reason || "authorization required"}`));
|
|
68207
68419
|
}
|
|
68208
|
-
|
|
68209
|
-
|
|
68210
|
-
|
|
68211
|
-
|
|
68212
|
-
continue;
|
|
68420
|
+
try {
|
|
68421
|
+
resolve5({ setup: parseSetup(data.subarray(0, total)), rest: data.subarray(total) });
|
|
68422
|
+
} catch (error63) {
|
|
68423
|
+
fail(error63);
|
|
68213
68424
|
}
|
|
68214
|
-
|
|
68215
|
-
|
|
68425
|
+
};
|
|
68426
|
+
socket.once("error", fail);
|
|
68427
|
+
socket.on("data", onData);
|
|
68428
|
+
socket.write(setupRequest(cookie));
|
|
68429
|
+
});
|
|
68430
|
+
const connection = new _X11Connection(socket, setup2.setup);
|
|
68431
|
+
if (setup2.rest.length) connection.receive(setup2.rest);
|
|
68432
|
+
return connection;
|
|
68433
|
+
}
|
|
68434
|
+
listen(listener) {
|
|
68435
|
+
this.onEvent = listener;
|
|
68436
|
+
}
|
|
68437
|
+
whenClosed(listener) {
|
|
68438
|
+
this.onClose = listener;
|
|
68439
|
+
}
|
|
68440
|
+
/** Sends a request that has a reply and resolves with the whole reply. */
|
|
68441
|
+
request(body) {
|
|
68442
|
+
if (this.closed) return Promise.reject(new Error("X11 connection closed"));
|
|
68443
|
+
const sequence = this.send(body);
|
|
68444
|
+
return new Promise((resolve5, reject) => this.pending.set(sequence, { resolve: resolve5, reject }));
|
|
68445
|
+
}
|
|
68446
|
+
/** Sends a request without a reply; resolves once the server processed it, rejecting with its error. */
|
|
68447
|
+
async checked(body) {
|
|
68448
|
+
const sequence = this.send(body);
|
|
68449
|
+
await this.request(request(43, 0, Buffer.alloc(0)));
|
|
68450
|
+
const error63 = this.errors.get(sequence);
|
|
68451
|
+
this.errors.delete(sequence);
|
|
68452
|
+
if (error63) throw error63;
|
|
68453
|
+
}
|
|
68454
|
+
close(error63) {
|
|
68455
|
+
if (this.closed) return;
|
|
68456
|
+
this.closed = true;
|
|
68457
|
+
this.socket.destroy();
|
|
68458
|
+
for (const pending of this.pending.values()) pending.reject(error63 ?? new Error("X11 connection closed"));
|
|
68459
|
+
this.pending.clear();
|
|
68460
|
+
this.onClose(error63);
|
|
68461
|
+
}
|
|
68462
|
+
send(body) {
|
|
68463
|
+
this.sequence = this.sequence + 1 & 65535;
|
|
68464
|
+
this.socket.write(body);
|
|
68465
|
+
return this.sequence;
|
|
68466
|
+
}
|
|
68467
|
+
receive(chunk) {
|
|
68468
|
+
this.buffer = this.buffer.length ? Buffer.concat([this.buffer, chunk]) : chunk;
|
|
68469
|
+
while (this.buffer.length >= 32) {
|
|
68470
|
+
const kind = this.buffer[0] & 127;
|
|
68471
|
+
const total = kind === 1 || kind === 35 ? 32 + this.buffer.readUInt32LE(4) * 4 : 32;
|
|
68472
|
+
if (this.buffer.length < total) return;
|
|
68473
|
+
const message = this.buffer.subarray(0, total);
|
|
68474
|
+
this.buffer = this.buffer.subarray(total);
|
|
68475
|
+
this.dispatch(kind, message);
|
|
68476
|
+
}
|
|
68477
|
+
}
|
|
68478
|
+
dispatch(kind, message) {
|
|
68479
|
+
const sequence = message.readUInt16LE(2);
|
|
68480
|
+
if (kind === 1 || kind === 0) {
|
|
68481
|
+
const pending = this.pending.get(sequence);
|
|
68482
|
+
if (pending) {
|
|
68483
|
+
this.pending.delete(sequence);
|
|
68484
|
+
if (kind === 1) pending.resolve(Buffer.from(message));
|
|
68485
|
+
else pending.reject(new X11Error(message[1], sequence));
|
|
68486
|
+
return;
|
|
68216
68487
|
}
|
|
68217
|
-
if (
|
|
68218
|
-
|
|
68219
|
-
|
|
68220
|
-
const current = mine.get(id);
|
|
68221
|
-
if (current) {
|
|
68222
|
-
remove.run(current.rowid);
|
|
68223
|
-
counts.deleted++;
|
|
68224
|
-
}
|
|
68225
|
-
}
|
|
68488
|
+
if (kind === 0) {
|
|
68489
|
+
this.errors.set(sequence, new X11Error(message[1], sequence));
|
|
68490
|
+
if (this.errors.size > 64) this.errors.delete(this.errors.keys().next().value);
|
|
68226
68491
|
}
|
|
68227
|
-
|
|
68228
|
-
} catch (error63) {
|
|
68229
|
-
db.exec("ROLLBACK");
|
|
68230
|
-
throw error63;
|
|
68492
|
+
return;
|
|
68231
68493
|
}
|
|
68232
|
-
|
|
68233
|
-
source.close();
|
|
68234
|
-
db.close();
|
|
68494
|
+
this.onEvent(Buffer.from(message));
|
|
68235
68495
|
}
|
|
68496
|
+
};
|
|
68497
|
+
function setupRequest(cookie) {
|
|
68498
|
+
const name = cookie ? Buffer.from(COOKIE, "latin1") : Buffer.alloc(0);
|
|
68499
|
+
const data = cookie ?? Buffer.alloc(0);
|
|
68500
|
+
const out = Buffer.alloc(12 + name.length + pad4(name.length) + data.length + pad4(data.length));
|
|
68501
|
+
out.write("l", 0, "latin1");
|
|
68502
|
+
out.writeUInt16LE(11, 2);
|
|
68503
|
+
out.writeUInt16LE(0, 4);
|
|
68504
|
+
out.writeUInt16LE(name.length, 6);
|
|
68505
|
+
out.writeUInt16LE(data.length, 8);
|
|
68506
|
+
name.copy(out, 12);
|
|
68507
|
+
data.copy(out, 12 + name.length + pad4(name.length));
|
|
68508
|
+
return out;
|
|
68236
68509
|
}
|
|
68237
|
-
function
|
|
68238
|
-
|
|
68239
|
-
|
|
68240
|
-
|
|
68241
|
-
|
|
68242
|
-
|
|
68243
|
-
|
|
68244
|
-
|
|
68245
|
-
if (byte === void 0) return value.toString();
|
|
68246
|
-
value |= BigInt(byte & 127) << shift;
|
|
68247
|
-
shift += 7n;
|
|
68248
|
-
if (!(byte & 128)) break;
|
|
68249
|
-
}
|
|
68250
|
-
if (tag === 8) return value.toString();
|
|
68251
|
-
}
|
|
68252
|
-
return "0";
|
|
68510
|
+
function parseSetup(reply2) {
|
|
68511
|
+
const vendorLength = reply2.readUInt16LE(24);
|
|
68512
|
+
const formats = reply2[29];
|
|
68513
|
+
const minKeycode = reply2[34];
|
|
68514
|
+
const maxKeycode = reply2[35];
|
|
68515
|
+
const screens = 40 + vendorLength + pad4(vendorLength) + formats * 8;
|
|
68516
|
+
if (reply2.length < screens + 4) throw new Error("X11 setup reply has no screen");
|
|
68517
|
+
return { root: reply2.readUInt32LE(screens), minKeycode, maxKeycode };
|
|
68253
68518
|
}
|
|
68254
|
-
function
|
|
68255
|
-
const
|
|
68256
|
-
|
|
68257
|
-
|
|
68258
|
-
|
|
68259
|
-
|
|
68260
|
-
|
|
68261
|
-
|
|
68262
|
-
|
|
68263
|
-
|
|
68264
|
-
|
|
68265
|
-
|
|
68266
|
-
|
|
68267
|
-
|
|
68268
|
-
|
|
68269
|
-
|
|
68270
|
-
|
|
68271
|
-
|
|
68272
|
-
|
|
68273
|
-
|
|
68274
|
-
|
|
68275
|
-
|
|
68276
|
-
|
|
68277
|
-
|
|
68278
|
-
|
|
68519
|
+
function request(opcode, minor, body) {
|
|
68520
|
+
const out = Buffer.alloc(4 + body.length + pad4(body.length));
|
|
68521
|
+
out[0] = opcode;
|
|
68522
|
+
out[1] = minor;
|
|
68523
|
+
out.writeUInt16LE(out.length / 4, 2);
|
|
68524
|
+
body.copy(out, 4);
|
|
68525
|
+
return out;
|
|
68526
|
+
}
|
|
68527
|
+
var OP_GRAB_KEY = 33;
|
|
68528
|
+
var OP_UNGRAB_KEY = 34;
|
|
68529
|
+
var OP_QUERY_EXTENSION = 98;
|
|
68530
|
+
var OP_GET_KEYBOARD_MAPPING = 101;
|
|
68531
|
+
var OP_GET_MODIFIER_MAPPING = 119;
|
|
68532
|
+
async function queryExtension(x, name) {
|
|
68533
|
+
const bytes = Buffer.from(name, "latin1");
|
|
68534
|
+
const body = Buffer.alloc(4 + bytes.length);
|
|
68535
|
+
body.writeUInt16LE(bytes.length, 0);
|
|
68536
|
+
bytes.copy(body, 4);
|
|
68537
|
+
const reply2 = await x.request(request(OP_QUERY_EXTENSION, 0, body));
|
|
68538
|
+
return reply2[8] ? reply2[9] : void 0;
|
|
68539
|
+
}
|
|
68540
|
+
|
|
68541
|
+
// src/browser/launcher.ts
|
|
68542
|
+
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
68543
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
68544
|
+
import {
|
|
68545
|
+
accessSync,
|
|
68546
|
+
closeSync,
|
|
68547
|
+
constants,
|
|
68548
|
+
cpSync as cpSync2,
|
|
68549
|
+
existsSync as existsSync3,
|
|
68550
|
+
mkdirSync as mkdirSync3,
|
|
68551
|
+
openSync,
|
|
68552
|
+
readlinkSync,
|
|
68553
|
+
realpathSync as realpathSync2,
|
|
68554
|
+
rmSync as rmSync3,
|
|
68555
|
+
statSync as statSync2
|
|
68556
|
+
} from "node:fs";
|
|
68557
|
+
import { hostname as hostname4 } from "node:os";
|
|
68558
|
+
import { basename as basename2, delimiter, dirname as dirname2, join as join4, resolve } from "node:path";
|
|
68559
|
+
|
|
68560
|
+
// src/browser/profile-merge.ts
|
|
68561
|
+
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
68562
|
+
import {
|
|
68563
|
+
cpSync,
|
|
68564
|
+
existsSync as existsSync2,
|
|
68565
|
+
mkdtempSync,
|
|
68566
|
+
readFileSync as readFileSync3,
|
|
68567
|
+
readdirSync as readdirSync2,
|
|
68568
|
+
realpathSync,
|
|
68569
|
+
rmSync as rmSync2,
|
|
68570
|
+
statSync,
|
|
68571
|
+
writeFileSync as writeFileSync2
|
|
68572
|
+
} from "node:fs";
|
|
68573
|
+
import { tmpdir } from "node:os";
|
|
68574
|
+
import { basename, join as join3 } from "node:path";
|
|
68575
|
+
|
|
68576
|
+
// src/browser/leveldb.ts
|
|
68577
|
+
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
68578
|
+
import { existsSync, mkdirSync as mkdirSync2, readdirSync, readFileSync as readFileSync2, rmSync, writeFileSync } from "node:fs";
|
|
68579
|
+
import { join as join2 } from "node:path";
|
|
68580
|
+
var BLOCK_SIZE = 32 * 1024;
|
|
68581
|
+
var HEADER_SIZE = 7;
|
|
68582
|
+
var FULL = 1;
|
|
68583
|
+
var FIRST = 2;
|
|
68584
|
+
var MIDDLE = 3;
|
|
68585
|
+
var LAST = 4;
|
|
68586
|
+
var TYPE_DELETION = 0;
|
|
68587
|
+
var TYPE_VALUE = 1;
|
|
68588
|
+
var TABLE_MAGIC = 0xdb4775248b80fb57n;
|
|
68589
|
+
var BATCH_LIMIT_BYTES = 1024 * 1024;
|
|
68590
|
+
var CRC_TABLE = (() => {
|
|
68591
|
+
const table = new Uint32Array(256);
|
|
68592
|
+
for (let n = 0; n < 256; n++) {
|
|
68593
|
+
let c = n;
|
|
68594
|
+
for (let k = 0; k < 8; k++) c = c & 1 ? 2197175160 ^ c >>> 1 : c >>> 1;
|
|
68595
|
+
table[n] = c >>> 0;
|
|
68279
68596
|
}
|
|
68280
|
-
|
|
68597
|
+
return table;
|
|
68598
|
+
})();
|
|
68599
|
+
function crc32c(data, initial = 0) {
|
|
68600
|
+
let crc = ~initial >>> 0;
|
|
68601
|
+
for (const byte of data) crc = CRC_TABLE[(crc ^ byte) & 255] ^ crc >>> 8;
|
|
68602
|
+
return ~crc >>> 0;
|
|
68281
68603
|
}
|
|
68282
|
-
function
|
|
68283
|
-
|
|
68284
|
-
for (const entry of readdirSync2(dir, { withFileTypes: true, recursive: true })) {
|
|
68285
|
-
if (entry.isFile()) newest = Math.max(newest, statSync(join3(entry.parentPath, entry.name)).mtimeMs);
|
|
68286
|
-
}
|
|
68287
|
-
return newest;
|
|
68604
|
+
function maskCrc(crc) {
|
|
68605
|
+
return (crc >>> 15 | crc << 17) + 2726488792 >>> 0;
|
|
68288
68606
|
}
|
|
68289
|
-
|
|
68290
|
-
|
|
68291
|
-
|
|
68292
|
-
|
|
68293
|
-
|
|
68294
|
-
|
|
68295
|
-
|
|
68296
|
-
|
|
68297
|
-
|
|
68298
|
-
|
|
68299
|
-
|
|
68300
|
-
|
|
68301
|
-
|
|
68302
|
-
|
|
68303
|
-
|
|
68304
|
-
|
|
68607
|
+
var Reader = class {
|
|
68608
|
+
constructor(buf, pos = 0) {
|
|
68609
|
+
this.buf = buf;
|
|
68610
|
+
this.pos = pos;
|
|
68611
|
+
}
|
|
68612
|
+
buf;
|
|
68613
|
+
pos;
|
|
68614
|
+
get done() {
|
|
68615
|
+
return this.pos >= this.buf.length;
|
|
68616
|
+
}
|
|
68617
|
+
varint() {
|
|
68618
|
+
let result = 0;
|
|
68619
|
+
let shift = 0;
|
|
68620
|
+
for (; ; ) {
|
|
68621
|
+
if (this.pos >= this.buf.length) throw new Error("leveldb: truncated varint");
|
|
68622
|
+
const byte = this.buf[this.pos++];
|
|
68623
|
+
result += (byte & 127) * 2 ** shift;
|
|
68624
|
+
if (!(byte & 128)) return result;
|
|
68625
|
+
shift += 7;
|
|
68626
|
+
if (shift > 63) throw new Error("leveldb: varint too long");
|
|
68305
68627
|
}
|
|
68306
|
-
report.taken.push(origin);
|
|
68307
68628
|
}
|
|
68308
|
-
|
|
68309
|
-
|
|
68310
|
-
|
|
68311
|
-
|
|
68312
|
-
|
|
68313
|
-
var LOCK_STALE_MS = 6e4;
|
|
68314
|
-
var LOCK_WAIT_MS = 3e4;
|
|
68315
|
-
var OWN_WAIT_MS = 2e4;
|
|
68316
|
-
function profileOwner(profile, host = hostname4()) {
|
|
68317
|
-
let target;
|
|
68318
|
-
try {
|
|
68319
|
-
target = readlinkSync(join4(profile, "SingletonLock"));
|
|
68320
|
-
} catch {
|
|
68321
|
-
return void 0;
|
|
68629
|
+
bytes(length) {
|
|
68630
|
+
if (this.pos + length > this.buf.length) throw new Error("leveldb: truncated slice");
|
|
68631
|
+
const out = this.buf.subarray(this.pos, this.pos + length);
|
|
68632
|
+
this.pos += length;
|
|
68633
|
+
return out;
|
|
68322
68634
|
}
|
|
68323
|
-
|
|
68324
|
-
|
|
68325
|
-
const pid = Number(match[2]);
|
|
68326
|
-
try {
|
|
68327
|
-
process.kill(pid, 0);
|
|
68328
|
-
return pid;
|
|
68329
|
-
} catch (error63) {
|
|
68330
|
-
return error63.code === "EPERM" ? pid : void 0;
|
|
68635
|
+
slice() {
|
|
68636
|
+
return this.bytes(this.varint());
|
|
68331
68637
|
}
|
|
68638
|
+
};
|
|
68639
|
+
function varint(value) {
|
|
68640
|
+
const out = [];
|
|
68641
|
+
let v = value;
|
|
68642
|
+
while (v >= 128) {
|
|
68643
|
+
out.push(v % 128 | 128);
|
|
68644
|
+
v = Math.floor(v / 128);
|
|
68645
|
+
}
|
|
68646
|
+
out.push(v);
|
|
68647
|
+
return Buffer.from(out);
|
|
68332
68648
|
}
|
|
68333
|
-
function
|
|
68334
|
-
|
|
68335
|
-
return !(name.startsWith("Singleton") || /cache$/i.test(name) || name === "Crash Reports" || name === "Sessions" || name === "Session Storage" || name === BASELINE_FILE);
|
|
68336
|
-
}
|
|
68337
|
-
function seedProfile(master, profile) {
|
|
68338
|
-
mkdirSync3(dirname2(profile), { recursive: true });
|
|
68339
|
-
cpSync2(master, profile, { recursive: true, preserveTimestamps: true, filter: seedable });
|
|
68649
|
+
function lengthPrefixed(data) {
|
|
68650
|
+
return Buffer.concat([varint(data.length), data]);
|
|
68340
68651
|
}
|
|
68341
|
-
function
|
|
68342
|
-
const
|
|
68343
|
-
|
|
68344
|
-
|
|
68345
|
-
|
|
68346
|
-
|
|
68347
|
-
|
|
68348
|
-
|
|
68349
|
-
|
|
68350
|
-
|
|
68652
|
+
function snappyDecompress(input2) {
|
|
68653
|
+
const reader = new Reader(input2);
|
|
68654
|
+
const length = reader.varint();
|
|
68655
|
+
const out = Buffer.alloc(length);
|
|
68656
|
+
let o = 0;
|
|
68657
|
+
while (!reader.done) {
|
|
68658
|
+
const tag = input2[reader.pos++];
|
|
68659
|
+
const kind = tag & 3;
|
|
68660
|
+
if (kind === 0) {
|
|
68661
|
+
let len2 = tag >>> 2;
|
|
68662
|
+
if (len2 >= 60) {
|
|
68663
|
+
const extra = len2 - 59;
|
|
68664
|
+
len2 = input2.readUIntLE(reader.pos, extra);
|
|
68665
|
+
reader.pos += extra;
|
|
68351
68666
|
}
|
|
68667
|
+
len2 += 1;
|
|
68668
|
+
input2.copy(out, o, reader.pos, reader.pos + len2);
|
|
68669
|
+
reader.pos += len2;
|
|
68670
|
+
o += len2;
|
|
68671
|
+
continue;
|
|
68352
68672
|
}
|
|
68353
|
-
|
|
68354
|
-
|
|
68355
|
-
|
|
68356
|
-
|
|
68357
|
-
|
|
68358
|
-
|
|
68359
|
-
|
|
68360
|
-
|
|
68361
|
-
|
|
68362
|
-
|
|
68363
|
-
|
|
68364
|
-
|
|
68365
|
-
|
|
68366
|
-
seedProfile(options.master, options.profile);
|
|
68367
|
-
log40(`browser profile ${options.profile} created from ${options.master}`);
|
|
68368
|
-
} else mkdirSync3(options.profile, { recursive: true });
|
|
68369
|
-
}
|
|
68370
|
-
for (const name of ["SingletonLock", "SingletonCookie", "SingletonSocket"]) {
|
|
68371
|
-
rmSync3(join4(options.profile, name), { force: true });
|
|
68673
|
+
let len;
|
|
68674
|
+
let offset;
|
|
68675
|
+
if (kind === 1) {
|
|
68676
|
+
len = (tag >>> 2 & 7) + 4;
|
|
68677
|
+
offset = tag >>> 5 << 8 | input2[reader.pos++];
|
|
68678
|
+
} else if (kind === 2) {
|
|
68679
|
+
len = (tag >>> 2) + 1;
|
|
68680
|
+
offset = input2.readUInt16LE(reader.pos);
|
|
68681
|
+
reader.pos += 2;
|
|
68682
|
+
} else {
|
|
68683
|
+
len = (tag >>> 2) + 1;
|
|
68684
|
+
offset = input2.readUInt32LE(reader.pos);
|
|
68685
|
+
reader.pos += 4;
|
|
68372
68686
|
}
|
|
68373
|
-
|
|
68374
|
-
|
|
68375
|
-
(source) => existsSync3(join4(source, "Default")) && realpathSync2(source) !== self2
|
|
68376
|
-
);
|
|
68377
|
-
const reports = await forkMerge(options.profile, sources);
|
|
68378
|
-
for (const report of reports) log40(`browser fork-merge from ${report.source}: ${summarize(report)}`);
|
|
68379
|
-
const child2 = start(options);
|
|
68380
|
-
if (!await owned(options.profile, child2)) log40(`browser for ${options.profile} did not take its profile`);
|
|
68381
|
-
return { handedOff: false, reports, ...child2.pid !== void 0 ? { pid: child2.pid } : {} };
|
|
68382
|
-
} finally {
|
|
68383
|
-
release3();
|
|
68687
|
+
if (offset === 0 || offset > o) throw new Error("leveldb: bad snappy offset");
|
|
68688
|
+
for (let i = 0; i < len; i++, o++) out[o] = out[o - offset];
|
|
68384
68689
|
}
|
|
68690
|
+
if (o !== length) throw new Error("leveldb: snappy length mismatch");
|
|
68691
|
+
return out;
|
|
68385
68692
|
}
|
|
68386
|
-
function
|
|
68387
|
-
const
|
|
68388
|
-
|
|
68389
|
-
|
|
68390
|
-
|
|
68391
|
-
|
|
68392
|
-
|
|
68393
|
-
|
|
68394
|
-
|
|
68395
|
-
async function owned(profile, child2) {
|
|
68396
|
-
let ended = false;
|
|
68397
|
-
const end = () => void (ended = true);
|
|
68398
|
-
child2.once("error", end).once("exit", end);
|
|
68399
|
-
try {
|
|
68400
|
-
const deadline = Date.now() + OWN_WAIT_MS;
|
|
68401
|
-
for (; ; ) {
|
|
68402
|
-
if (profileOwner(profile) !== void 0) return true;
|
|
68403
|
-
if (ended || Date.now() > deadline) return false;
|
|
68404
|
-
await new Promise((resolveWait) => setTimeout(resolveWait, 100));
|
|
68693
|
+
function readLogRecords(data) {
|
|
68694
|
+
const records = [];
|
|
68695
|
+
let pending;
|
|
68696
|
+
let pos = 0;
|
|
68697
|
+
while (pos < data.length) {
|
|
68698
|
+
const left = BLOCK_SIZE - pos % BLOCK_SIZE;
|
|
68699
|
+
if (left < HEADER_SIZE) {
|
|
68700
|
+
pos += left;
|
|
68701
|
+
continue;
|
|
68405
68702
|
}
|
|
68406
|
-
|
|
68407
|
-
|
|
68408
|
-
|
|
68409
|
-
|
|
68410
|
-
|
|
68411
|
-
|
|
68412
|
-
const c = report.cookies;
|
|
68413
|
-
return [
|
|
68414
|
-
report.firstFork ? "first fork" : "since last fork",
|
|
68415
|
-
`cookies +${c.inserted} ~${c.updated} -${c.deleted} (kept ${c.kept}, expired ${c.expired})`,
|
|
68416
|
-
`localStorage ${report.localStorage.taken.length} origin(s)`,
|
|
68417
|
-
`IndexedDB ${report.indexedDb.taken.length} origin(s)`
|
|
68418
|
-
].join(", ");
|
|
68419
|
-
}
|
|
68420
|
-
async function lockProfile(profile) {
|
|
68421
|
-
const path = `${profile}.launch-lock`;
|
|
68422
|
-
mkdirSync3(dirname2(path), { recursive: true });
|
|
68423
|
-
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
68424
|
-
for (; ; ) {
|
|
68425
|
-
try {
|
|
68426
|
-
closeSync(openSync(path, "wx"));
|
|
68427
|
-
return () => rmSync3(path, { force: true });
|
|
68428
|
-
} catch (error63) {
|
|
68429
|
-
if (error63.code !== "EEXIST") throw error63;
|
|
68430
|
-
try {
|
|
68431
|
-
if (Date.now() - statSync2(path).mtimeMs > LOCK_STALE_MS) rmSync3(path, { force: true });
|
|
68432
|
-
} catch {
|
|
68433
|
-
}
|
|
68434
|
-
if (Date.now() > deadline) throw new Error(`another browser launch for ${profile} is still running`);
|
|
68435
|
-
await new Promise((resolveWait) => setTimeout(resolveWait, 200));
|
|
68703
|
+
if (pos + HEADER_SIZE > data.length) break;
|
|
68704
|
+
const length = data.readUInt16LE(pos + 4);
|
|
68705
|
+
const type = data[pos + 6];
|
|
68706
|
+
if (type === 0 && length === 0) {
|
|
68707
|
+
pos += left;
|
|
68708
|
+
continue;
|
|
68436
68709
|
}
|
|
68437
|
-
|
|
68438
|
-
|
|
68439
|
-
|
|
68440
|
-
|
|
68441
|
-
|
|
68442
|
-
|
|
68443
|
-
|
|
68444
|
-
|
|
68445
|
-
|
|
68446
|
-
|
|
68447
|
-
|
|
68448
|
-
|
|
68449
|
-
if (pid === void 0) return "not-running";
|
|
68450
|
-
try {
|
|
68451
|
-
const x = await X11Connection.connect({
|
|
68452
|
-
display: options.display,
|
|
68453
|
-
...options.xauthority ? { xauthority: options.xauthority } : {}
|
|
68454
|
-
});
|
|
68455
|
-
try {
|
|
68456
|
-
const windows = await windowsOf(x, pid);
|
|
68457
|
-
const protocols = await internAtom(x, "WM_PROTOCOLS");
|
|
68458
|
-
const remove = await internAtom(x, "WM_DELETE_WINDOW");
|
|
68459
|
-
for (const window2 of windows) await sendClientMessage(x, window2, protocols, [remove, 0, 0, 0, 0]);
|
|
68460
|
-
log40(`asked ${windows.length} browser window(s) of ${options.profile} to close`);
|
|
68461
|
-
} finally {
|
|
68462
|
-
x.close();
|
|
68710
|
+
if (pos + HEADER_SIZE + length > data.length) break;
|
|
68711
|
+
const payload = data.subarray(pos + HEADER_SIZE, pos + HEADER_SIZE + length);
|
|
68712
|
+
pos += HEADER_SIZE + length;
|
|
68713
|
+
if (type === FULL) {
|
|
68714
|
+
records.push(Buffer.from(payload));
|
|
68715
|
+
pending = void 0;
|
|
68716
|
+
} else if (type === FIRST) pending = [payload];
|
|
68717
|
+
else if (type === MIDDLE && pending) pending.push(payload);
|
|
68718
|
+
else if (type === LAST && pending) {
|
|
68719
|
+
pending.push(payload);
|
|
68720
|
+
records.push(Buffer.concat(pending));
|
|
68721
|
+
pending = void 0;
|
|
68463
68722
|
}
|
|
68464
|
-
} catch (error63) {
|
|
68465
|
-
log40(`could not ask the browser of ${options.profile} to close: ${error63.message}`);
|
|
68466
68723
|
}
|
|
68467
|
-
|
|
68468
|
-
log40(`browser ${pid} did not exit after its windows closed; sending SIGTERM (unflushed cookies may be lost)`);
|
|
68469
|
-
process.kill(pid, "SIGTERM");
|
|
68470
|
-
if (await exited(pid, 5e3)) return "terminated";
|
|
68471
|
-
process.kill(pid, "SIGKILL");
|
|
68472
|
-
return "killed";
|
|
68724
|
+
return records;
|
|
68473
68725
|
}
|
|
68474
|
-
|
|
68475
|
-
const
|
|
68476
|
-
|
|
68477
|
-
|
|
68478
|
-
|
|
68479
|
-
|
|
68480
|
-
|
|
68481
|
-
|
|
68482
|
-
|
|
68483
|
-
|
|
68726
|
+
function writeLogRecords(records) {
|
|
68727
|
+
const chunks = [];
|
|
68728
|
+
let offset = 0;
|
|
68729
|
+
const emit = (type, payload) => {
|
|
68730
|
+
const header = Buffer.alloc(HEADER_SIZE);
|
|
68731
|
+
header.writeUInt32LE(maskCrc(crc32c(payload, crc32c(Buffer.from([type])))), 0);
|
|
68732
|
+
header.writeUInt16LE(payload.length, 4);
|
|
68733
|
+
header[6] = type;
|
|
68734
|
+
chunks.push(header, payload);
|
|
68735
|
+
offset += HEADER_SIZE + payload.length;
|
|
68736
|
+
};
|
|
68737
|
+
for (const record2 of records) {
|
|
68738
|
+
let pos = 0;
|
|
68739
|
+
let first = true;
|
|
68740
|
+
do {
|
|
68741
|
+
let left = BLOCK_SIZE - offset % BLOCK_SIZE;
|
|
68742
|
+
if (left < HEADER_SIZE) {
|
|
68743
|
+
chunks.push(Buffer.alloc(left));
|
|
68744
|
+
offset += left;
|
|
68745
|
+
left = BLOCK_SIZE;
|
|
68484
68746
|
}
|
|
68485
|
-
|
|
68486
|
-
|
|
68487
|
-
|
|
68747
|
+
const take = Math.min(left - HEADER_SIZE, record2.length - pos);
|
|
68748
|
+
const end = pos + take === record2.length;
|
|
68749
|
+
emit(first && end ? FULL : first ? FIRST : end ? LAST : MIDDLE, record2.subarray(pos, pos + take));
|
|
68750
|
+
pos += take;
|
|
68751
|
+
first = false;
|
|
68752
|
+
} while (pos < record2.length);
|
|
68488
68753
|
}
|
|
68489
|
-
return
|
|
68754
|
+
return Buffer.concat(chunks);
|
|
68490
68755
|
}
|
|
68491
|
-
|
|
68492
|
-
const
|
|
68493
|
-
|
|
68494
|
-
|
|
68495
|
-
process.kill(pid, 0);
|
|
68496
|
-
} catch {
|
|
68497
|
-
return true;
|
|
68498
|
-
}
|
|
68499
|
-
if (Date.now() > deadline) return false;
|
|
68500
|
-
await new Promise((resolve5) => setTimeout(resolve5, 200));
|
|
68501
|
-
}
|
|
68756
|
+
function apply(entries2, key, sequence, deleted, value) {
|
|
68757
|
+
const id = key.toString("latin1");
|
|
68758
|
+
const current = entries2.get(id);
|
|
68759
|
+
if (!current || current.sequence < sequence) entries2.set(id, { sequence, deleted, value: Buffer.from(value) });
|
|
68502
68760
|
}
|
|
68503
|
-
|
|
68504
|
-
|
|
68505
|
-
|
|
68506
|
-
|
|
68507
|
-
|
|
68508
|
-
|
|
68509
|
-
|
|
68510
|
-
|
|
68761
|
+
function applyBatch(entries2, batch) {
|
|
68762
|
+
if (batch.length < 12) return;
|
|
68763
|
+
let sequence = batch.readBigUInt64LE(0);
|
|
68764
|
+
const count = batch.readUInt32LE(8);
|
|
68765
|
+
const reader = new Reader(batch, 12);
|
|
68766
|
+
for (let i = 0; i < count; i++, sequence++) {
|
|
68767
|
+
const type = batch[reader.pos++];
|
|
68768
|
+
if (type === TYPE_VALUE) {
|
|
68769
|
+
const key = reader.slice();
|
|
68770
|
+
apply(entries2, key, sequence, false, reader.slice());
|
|
68771
|
+
} else if (type === TYPE_DELETION) apply(entries2, reader.slice(), sequence, true, Buffer.alloc(0));
|
|
68772
|
+
else throw new Error("leveldb: unknown write batch record");
|
|
68511
68773
|
}
|
|
68512
|
-
return found;
|
|
68513
|
-
}
|
|
68514
|
-
async function internAtom(x, name) {
|
|
68515
|
-
const bytes = Buffer.from(name, "latin1");
|
|
68516
|
-
const body = Buffer.alloc(4 + bytes.length);
|
|
68517
|
-
body.writeUInt16LE(bytes.length, 0);
|
|
68518
|
-
bytes.copy(body, 4);
|
|
68519
|
-
return (await x.request(request(OP_INTERN_ATOM, 0, body))).readUInt32LE(8);
|
|
68520
|
-
}
|
|
68521
|
-
async function queryTree(x, window2) {
|
|
68522
|
-
const body = Buffer.alloc(4);
|
|
68523
|
-
body.writeUInt32LE(window2, 0);
|
|
68524
|
-
const reply2 = await x.request(request(OP_QUERY_TREE, 0, body)).catch(() => void 0);
|
|
68525
|
-
if (!reply2) return [];
|
|
68526
|
-
const count = reply2.readUInt16LE(16);
|
|
68527
|
-
return Array.from({ length: count }, (_, i) => reply2.readUInt32LE(32 + i * 4));
|
|
68528
68774
|
}
|
|
68529
|
-
|
|
68530
|
-
|
|
68531
|
-
|
|
68532
|
-
|
|
68533
|
-
|
|
68534
|
-
|
|
68535
|
-
|
|
68536
|
-
|
|
68537
|
-
|
|
68538
|
-
|
|
68775
|
+
function blockEntries(block, each) {
|
|
68776
|
+
if (block.length < 4) return;
|
|
68777
|
+
const restarts = block.readUInt32LE(block.length - 4);
|
|
68778
|
+
const end = block.length - 4 - restarts * 4;
|
|
68779
|
+
const reader = new Reader(block.subarray(0, end));
|
|
68780
|
+
let last = Buffer.alloc(0);
|
|
68781
|
+
while (!reader.done) {
|
|
68782
|
+
const shared = reader.varint();
|
|
68783
|
+
const unshared = reader.varint();
|
|
68784
|
+
const valueLength = reader.varint();
|
|
68785
|
+
const key = Buffer.concat([last.subarray(0, shared), reader.bytes(unshared)]);
|
|
68786
|
+
each(key, reader.bytes(valueLength));
|
|
68787
|
+
last = key;
|
|
68788
|
+
}
|
|
68539
68789
|
}
|
|
68540
|
-
|
|
68541
|
-
const
|
|
68542
|
-
|
|
68543
|
-
|
|
68544
|
-
|
|
68545
|
-
|
|
68546
|
-
|
|
68547
|
-
|
|
68548
|
-
body.writeUInt32LE(window2, 0);
|
|
68549
|
-
body.writeUInt32LE(0, 4);
|
|
68550
|
-
event.copy(body, 8);
|
|
68551
|
-
await x.checked(request(OP_SEND_EVENT, 0, body));
|
|
68790
|
+
function readBlock(file2, handle) {
|
|
68791
|
+
const offset = handle.varint();
|
|
68792
|
+
const size = handle.varint();
|
|
68793
|
+
const contents = file2.subarray(offset, offset + size);
|
|
68794
|
+
const compression = file2[offset + size];
|
|
68795
|
+
if (compression === 0) return contents;
|
|
68796
|
+
if (compression === 1) return snappyDecompress(contents);
|
|
68797
|
+
throw new Error(`leveldb: unsupported block compression ${compression}`);
|
|
68552
68798
|
}
|
|
68553
|
-
|
|
68554
|
-
|
|
68555
|
-
|
|
68556
|
-
|
|
68557
|
-
|
|
68558
|
-
|
|
68559
|
-
|
|
68560
|
-
|
|
68561
|
-
|
|
68562
|
-
|
|
68563
|
-
|
|
68564
|
-
|
|
68565
|
-
|
|
68566
|
-
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
68567
|
-
|
|
68568
|
-
// ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/index.js
|
|
68569
|
-
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
68570
|
-
|
|
68571
|
-
// ../protocol/src/envelope.ts
|
|
68572
|
-
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
68573
|
-
var Envelope = external_exports.object({
|
|
68574
|
-
v: external_exports.literal(1),
|
|
68575
|
-
// protocol major; bump = breaking
|
|
68576
|
-
id: external_exports.string().uuid(),
|
|
68577
|
-
// unique per frame (sender-generated)
|
|
68578
|
-
ts: external_exports.string().datetime(),
|
|
68579
|
-
// RFC3339, sender clock (advisory only)
|
|
68580
|
-
type: external_exports.string(),
|
|
68581
|
-
// frame discriminator, e.g. "register"
|
|
68582
|
-
corr: external_exports.string().uuid().optional(),
|
|
68583
|
-
// correlation: set on a reply to the request's `id`
|
|
68584
|
-
orgId: external_exports.string().min(1).max(64).optional(),
|
|
68585
|
-
// tenant context on an install-wide daemon connection
|
|
68586
|
-
payload: external_exports.unknown()
|
|
68587
|
-
// validated by the per-type schema
|
|
68588
|
-
});
|
|
68589
|
-
var ControlExt = external_exports.object({
|
|
68590
|
-
epoch: external_exports.number().int(),
|
|
68591
|
-
// sessionEpoch this frame was issued under (§3.1 fencing)
|
|
68592
|
-
agentId: external_exports.string().uuid().optional(),
|
|
68593
|
-
// present on agent-scoped frames
|
|
68594
|
-
launchId: external_exports.string().uuid().optional()
|
|
68595
|
-
// per-launch fence, §4.4
|
|
68596
|
-
});
|
|
68597
|
-
var NIL_UUID = "00000000-0000-0000-0000-000000000000";
|
|
68598
|
-
function frameSchema(type, payload) {
|
|
68599
|
-
return external_exports.object({
|
|
68600
|
-
v: external_exports.literal(1),
|
|
68601
|
-
id: external_exports.string().uuid(),
|
|
68602
|
-
ts: external_exports.string().datetime(),
|
|
68603
|
-
type: external_exports.literal(type),
|
|
68604
|
-
corr: external_exports.string().uuid().optional(),
|
|
68605
|
-
orgId: external_exports.string().min(1).max(64).optional(),
|
|
68606
|
-
payload
|
|
68799
|
+
function readTable(file2, entries2) {
|
|
68800
|
+
if (file2.length < 48) throw new Error("leveldb: table too short");
|
|
68801
|
+
const footer = file2.subarray(file2.length - 48);
|
|
68802
|
+
if (footer.readBigUInt64LE(40) !== TABLE_MAGIC) throw new Error("leveldb: bad table magic");
|
|
68803
|
+
const handles = new Reader(footer);
|
|
68804
|
+
handles.varint();
|
|
68805
|
+
handles.varint();
|
|
68806
|
+
const index = readBlock(file2, handles);
|
|
68807
|
+
blockEntries(index, (_key, handle) => {
|
|
68808
|
+
blockEntries(readBlock(file2, new Reader(handle)), (internal, value) => {
|
|
68809
|
+
const tag = internal.readBigUInt64LE(internal.length - 8);
|
|
68810
|
+
apply(entries2, internal.subarray(0, internal.length - 8), tag >> 8n, Number(tag & 0xffn) === TYPE_DELETION, value);
|
|
68811
|
+
});
|
|
68607
68812
|
});
|
|
68608
68813
|
}
|
|
68609
|
-
|
|
68610
|
-
|
|
68611
|
-
|
|
68612
|
-
|
|
68613
|
-
|
|
68614
|
-
|
|
68615
|
-
|
|
68616
|
-
|
|
68617
|
-
|
|
68618
|
-
|
|
68619
|
-
|
|
68620
|
-
|
|
68621
|
-
|
|
68814
|
+
function readManifest(data) {
|
|
68815
|
+
const manifest = { logNumber: 0, prevLogNumber: 0, tables: /* @__PURE__ */ new Set() };
|
|
68816
|
+
for (const record2 of readLogRecords(data)) {
|
|
68817
|
+
const reader = new Reader(record2);
|
|
68818
|
+
while (!reader.done) {
|
|
68819
|
+
const tag = reader.varint();
|
|
68820
|
+
if (tag === 1) reader.slice();
|
|
68821
|
+
else if (tag === 2) manifest.logNumber = reader.varint();
|
|
68822
|
+
else if (tag === 3) reader.varint();
|
|
68823
|
+
else if (tag === 4) reader.varint();
|
|
68824
|
+
else if (tag === 5) {
|
|
68825
|
+
reader.varint();
|
|
68826
|
+
reader.slice();
|
|
68827
|
+
} else if (tag === 6) {
|
|
68828
|
+
reader.varint();
|
|
68829
|
+
manifest.tables.delete(reader.varint());
|
|
68830
|
+
} else if (tag === 7) {
|
|
68831
|
+
reader.varint();
|
|
68832
|
+
manifest.tables.add(reader.varint());
|
|
68833
|
+
reader.varint();
|
|
68834
|
+
reader.slice();
|
|
68835
|
+
reader.slice();
|
|
68836
|
+
} else if (tag === 9) manifest.prevLogNumber = reader.varint();
|
|
68837
|
+
else throw new Error(`leveldb: unknown manifest tag ${tag}`);
|
|
68838
|
+
}
|
|
68839
|
+
}
|
|
68840
|
+
return manifest;
|
|
68622
68841
|
}
|
|
68623
|
-
function
|
|
68624
|
-
|
|
68842
|
+
function readLevelDb(dir) {
|
|
68843
|
+
const entries2 = /* @__PURE__ */ new Map();
|
|
68844
|
+
if (!existsSync(join2(dir, "CURRENT"))) return /* @__PURE__ */ new Map();
|
|
68845
|
+
const current = readFileSync2(join2(dir, "CURRENT"), "latin1").trim();
|
|
68846
|
+
const manifest = readManifest(readFileSync2(join2(dir, current)));
|
|
68847
|
+
const files = readdirSync(dir);
|
|
68848
|
+
for (const number4 of manifest.tables) {
|
|
68849
|
+
const name = [`${String(number4).padStart(6, "0")}.ldb`, `${String(number4).padStart(6, "0")}.sst`].find(
|
|
68850
|
+
(n) => files.includes(n)
|
|
68851
|
+
);
|
|
68852
|
+
if (!name) throw new Error(`leveldb: table ${number4} is missing`);
|
|
68853
|
+
readTable(readFileSync2(join2(dir, name)), entries2);
|
|
68854
|
+
}
|
|
68855
|
+
for (const name of files) {
|
|
68856
|
+
const match = /^(\d+)\.log$/.exec(name);
|
|
68857
|
+
if (!match) continue;
|
|
68858
|
+
const number4 = Number(match[1]);
|
|
68859
|
+
if (number4 < manifest.logNumber && number4 !== manifest.prevLogNumber) continue;
|
|
68860
|
+
for (const batch of readLogRecords(readFileSync2(join2(dir, name)))) applyBatch(entries2, batch);
|
|
68861
|
+
}
|
|
68862
|
+
const out = /* @__PURE__ */ new Map();
|
|
68863
|
+
for (const [key, entry] of entries2) if (!entry.deleted) out.set(key, entry.value);
|
|
68864
|
+
return out;
|
|
68625
68865
|
}
|
|
68626
|
-
function
|
|
68627
|
-
|
|
68866
|
+
function writeLevelDb(dir, data) {
|
|
68867
|
+
rmSync(dir, { recursive: true, force: true });
|
|
68868
|
+
mkdirSync2(dir, { recursive: true });
|
|
68869
|
+
const batches = [];
|
|
68870
|
+
let sequence = 1n;
|
|
68871
|
+
let records = [];
|
|
68872
|
+
let bytes = 0;
|
|
68873
|
+
const flush = () => {
|
|
68874
|
+
if (!records.length) return;
|
|
68875
|
+
const head = Buffer.alloc(12);
|
|
68876
|
+
head.writeBigUInt64LE(sequence, 0);
|
|
68877
|
+
head.writeUInt32LE(records.length, 8);
|
|
68878
|
+
batches.push(Buffer.concat([head, ...records]));
|
|
68879
|
+
sequence += BigInt(records.length);
|
|
68880
|
+
records = [];
|
|
68881
|
+
bytes = 0;
|
|
68882
|
+
};
|
|
68883
|
+
for (const [key, value] of data) {
|
|
68884
|
+
const record2 = Buffer.concat([
|
|
68885
|
+
Buffer.from([TYPE_VALUE]),
|
|
68886
|
+
lengthPrefixed(Buffer.from(key, "latin1")),
|
|
68887
|
+
lengthPrefixed(value)
|
|
68888
|
+
]);
|
|
68889
|
+
records.push(record2);
|
|
68890
|
+
bytes += record2.length;
|
|
68891
|
+
if (bytes >= BATCH_LIMIT_BYTES) flush();
|
|
68892
|
+
}
|
|
68893
|
+
flush();
|
|
68894
|
+
const edit = Buffer.concat([
|
|
68895
|
+
varint(1),
|
|
68896
|
+
lengthPrefixed(Buffer.from("leveldb.BytewiseComparator", "latin1")),
|
|
68897
|
+
varint(2),
|
|
68898
|
+
varint(3),
|
|
68899
|
+
varint(3),
|
|
68900
|
+
varint(4),
|
|
68901
|
+
varint(4),
|
|
68902
|
+
varint(0)
|
|
68903
|
+
]);
|
|
68904
|
+
writeFileSync(join2(dir, "000003.log"), writeLogRecords(batches));
|
|
68905
|
+
writeFileSync(join2(dir, "MANIFEST-000002"), writeLogRecords([edit]));
|
|
68906
|
+
writeFileSync(join2(dir, "CURRENT"), "MANIFEST-000002\n");
|
|
68628
68907
|
}
|
|
68629
|
-
|
|
68630
|
-
|
|
68908
|
+
|
|
68909
|
+
// src/browser/profile-merge.ts
|
|
68910
|
+
var BASELINE_FILE = "ac-fork-baseline.json";
|
|
68911
|
+
var CHROME_EPOCH_OFFSET_US = 11644473600000000n;
|
|
68912
|
+
var SNAPSHOT_TRIES = 6;
|
|
68913
|
+
var SNAPSHOT_RETRY_MS = 300;
|
|
68914
|
+
function cookiesPath(profile) {
|
|
68915
|
+
const network = join3(profile, "Default", "Network", "Cookies");
|
|
68916
|
+
return existsSync2(network) ? network : join3(profile, "Default", "Cookies");
|
|
68631
68917
|
}
|
|
68632
|
-
|
|
68633
|
-
|
|
68918
|
+
var sqlite;
|
|
68919
|
+
function openDb(path) {
|
|
68920
|
+
if (!sqlite) {
|
|
68921
|
+
const emit = process.emitWarning;
|
|
68922
|
+
process.emitWarning = ((warning, ...rest) => {
|
|
68923
|
+
if (!String(warning).includes("SQLite")) emit.call(process, warning, ...rest);
|
|
68924
|
+
});
|
|
68925
|
+
try {
|
|
68926
|
+
sqlite = process.getBuiltinModule("node:sqlite");
|
|
68927
|
+
} finally {
|
|
68928
|
+
process.emitWarning = emit;
|
|
68929
|
+
}
|
|
68930
|
+
}
|
|
68931
|
+
return new sqlite.DatabaseSync(path);
|
|
68634
68932
|
}
|
|
68635
|
-
|
|
68636
|
-
|
|
68637
|
-
|
|
68638
|
-
|
|
68639
|
-
|
|
68640
|
-
|
|
68933
|
+
var localStoragePath = (profile) => join3(profile, "Default", "Local Storage", "leveldb");
|
|
68934
|
+
var indexedDbPath = (profile) => join3(profile, "Default", "IndexedDB");
|
|
68935
|
+
async function forkMerge(target, sources, options = {}) {
|
|
68936
|
+
const now = options.now ?? Date.now;
|
|
68937
|
+
const sleep3 = options.sleep ?? ((ms) => new Promise((resolve5) => setTimeout(resolve5, ms)));
|
|
68938
|
+
const baselinePath = join3(target, BASELINE_FILE);
|
|
68939
|
+
const baselines = loadBaselines(baselinePath);
|
|
68940
|
+
const reports = [];
|
|
68941
|
+
for (const source of sources) {
|
|
68942
|
+
const key = realpathSync(source);
|
|
68943
|
+
const previous = baselines.sources[key];
|
|
68944
|
+
const work = mkdtempSync(join3(tmpdir(), "ac-fork-"));
|
|
68945
|
+
try {
|
|
68946
|
+
const snapshot = await takeSnapshot(source, work, sleep3);
|
|
68947
|
+
const next = { cookies: {}, localStorage: {}, indexedDb: {} };
|
|
68948
|
+
const report = {
|
|
68949
|
+
source,
|
|
68950
|
+
firstFork: previous === void 0,
|
|
68951
|
+
cookies: { inserted: 0, updated: 0, kept: 0, expired: 0, deleted: 0 },
|
|
68952
|
+
localStorage: { taken: [], kept: 0 },
|
|
68953
|
+
indexedDb: { taken: [], kept: 0 }
|
|
68954
|
+
};
|
|
68955
|
+
if (snapshot.cookies) {
|
|
68956
|
+
mergeCookies(snapshot.cookies, cookiesPath(target), previous?.cookies, next.cookies, report.cookies, now);
|
|
68957
|
+
}
|
|
68958
|
+
mergeLocalStorage(
|
|
68959
|
+
snapshot.localStorage,
|
|
68960
|
+
localStoragePath(target),
|
|
68961
|
+
previous?.localStorage,
|
|
68962
|
+
next.localStorage,
|
|
68963
|
+
report.localStorage
|
|
68641
68964
|
);
|
|
68642
|
-
|
|
68643
|
-
|
|
68965
|
+
if (snapshot.indexedDb) {
|
|
68966
|
+
mergeIndexedDb(snapshot.indexedDb, indexedDbPath(target), previous?.indexedDb, next.indexedDb, report.indexedDb);
|
|
68967
|
+
}
|
|
68968
|
+
baselines.sources[key] = next;
|
|
68969
|
+
reports.push(report);
|
|
68970
|
+
} finally {
|
|
68971
|
+
rmSync2(work, { recursive: true, force: true });
|
|
68644
68972
|
}
|
|
68645
|
-
case "array":
|
|
68646
|
-
return withDef(schema, { ...def, element: child(def.element) });
|
|
68647
|
-
// Both plain and discriminated unions; the discriminator rides along in the spread def.
|
|
68648
|
-
case "union":
|
|
68649
|
-
return withDef(schema, { ...def, options: def.options.map(child) });
|
|
68650
|
-
case "intersection":
|
|
68651
|
-
return withDef(schema, { ...def, left: child(def.left), right: child(def.right) });
|
|
68652
|
-
case "tuple":
|
|
68653
|
-
return withDef(schema, {
|
|
68654
|
-
...def,
|
|
68655
|
-
items: def.items.map(child),
|
|
68656
|
-
...isSchema(def.rest) ? { rest: child(def.rest) } : {}
|
|
68657
|
-
});
|
|
68658
|
-
case "record":
|
|
68659
|
-
case "map":
|
|
68660
|
-
return withDef(schema, { ...def, keyType: child(def.keyType), valueType: child(def.valueType) });
|
|
68661
|
-
case "set":
|
|
68662
|
-
return withDef(schema, { ...def, valueType: child(def.valueType) });
|
|
68663
|
-
case "optional":
|
|
68664
|
-
case "nullable":
|
|
68665
|
-
case "nonoptional":
|
|
68666
|
-
case "default":
|
|
68667
|
-
case "prefault":
|
|
68668
|
-
case "catch":
|
|
68669
|
-
case "readonly":
|
|
68670
|
-
case "promise":
|
|
68671
|
-
return withDef(schema, { ...def, innerType: child(def.innerType) });
|
|
68672
|
-
case "pipe":
|
|
68673
|
-
return withDef(schema, { ...def, in: child(def.in), out: child(def.out) });
|
|
68674
|
-
case "lazy":
|
|
68675
|
-
return external_exports.lazy(() => child(def.getter()));
|
|
68676
|
-
default:
|
|
68677
|
-
return schema;
|
|
68678
68973
|
}
|
|
68974
|
+
writeFileSync2(baselinePath, JSON.stringify(baselines));
|
|
68975
|
+
return reports;
|
|
68679
68976
|
}
|
|
68680
|
-
function
|
|
68681
|
-
return isSchema(value) && defOf(value).type === "never";
|
|
68682
|
-
}
|
|
68683
|
-
|
|
68684
|
-
// ../protocol/src/wire.ts
|
|
68685
|
-
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
68686
|
-
import { randomUUID } from "node:crypto";
|
|
68687
|
-
var MAX_FRAME_BYTES = 256 * 1024;
|
|
68688
|
-
var REPLY_BUDGET = MAX_FRAME_BYTES - 4096;
|
|
68689
|
-
var textEncoder = new TextEncoder();
|
|
68690
|
-
function byteLength(text) {
|
|
68691
|
-
return textEncoder.encode(text).length;
|
|
68692
|
-
}
|
|
68693
|
-
function extractControlExt(json5) {
|
|
68694
|
-
if (typeof json5 !== "object" || json5 === null) return void 0;
|
|
68695
|
-
const o = json5;
|
|
68696
|
-
const ext = {};
|
|
68697
|
-
if (typeof o.epoch === "number") ext.epoch = o.epoch;
|
|
68698
|
-
if (typeof o.agentId === "string") ext.agentId = o.agentId;
|
|
68699
|
-
if (typeof o.launchId === "string") ext.launchId = o.launchId;
|
|
68700
|
-
return Object.keys(ext).length > 0 ? ext : void 0;
|
|
68701
|
-
}
|
|
68702
|
-
function decodeEnvelopeWith(schemas, text, opts = {}) {
|
|
68703
|
-
if (byteLength(text) > (opts.maxBytes ?? MAX_FRAME_BYTES)) {
|
|
68704
|
-
return { ok: false, id: NIL_UUID, msg: "FRAME_TOO_LARGE" };
|
|
68705
|
-
}
|
|
68706
|
-
let json5;
|
|
68977
|
+
function loadBaselines(path) {
|
|
68707
68978
|
try {
|
|
68708
|
-
|
|
68979
|
+
const parsed = JSON.parse(readFileSync3(path, "utf8"));
|
|
68980
|
+
if (parsed.version === 1 && parsed.sources && typeof parsed.sources === "object") return parsed;
|
|
68709
68981
|
} catch {
|
|
68710
|
-
return { ok: false, id: NIL_UUID, msg: "invalid json" };
|
|
68711
68982
|
}
|
|
68712
|
-
|
|
68713
|
-
|
|
68714
|
-
|
|
68715
|
-
|
|
68983
|
+
return { version: 1, sources: {} };
|
|
68984
|
+
}
|
|
68985
|
+
async function takeSnapshot(source, work, sleep3) {
|
|
68986
|
+
const snapshot = { localStorage: /* @__PURE__ */ new Map() };
|
|
68987
|
+
const cookies = cookiesPath(source);
|
|
68988
|
+
if (existsSync2(cookies)) {
|
|
68989
|
+
snapshot.cookies = join3(work, "Cookies");
|
|
68990
|
+
cpSync(cookies, snapshot.cookies);
|
|
68991
|
+
for (const suffix of ["-journal", "-wal"]) {
|
|
68992
|
+
if (existsSync2(cookies + suffix)) cpSync(cookies + suffix, snapshot.cookies + suffix);
|
|
68993
|
+
}
|
|
68716
68994
|
}
|
|
68717
|
-
const
|
|
68718
|
-
if (
|
|
68719
|
-
|
|
68720
|
-
|
|
68721
|
-
|
|
68722
|
-
|
|
68723
|
-
|
|
68724
|
-
};
|
|
68995
|
+
const localStorage2 = localStoragePath(source);
|
|
68996
|
+
if (existsSync2(localStorage2)) {
|
|
68997
|
+
snapshot.localStorage = await retried(sleep3, () => {
|
|
68998
|
+
const copy = join3(work, "ls");
|
|
68999
|
+
rmSync2(copy, { recursive: true, force: true });
|
|
69000
|
+
cpSync(localStorage2, copy, { recursive: true, filter: (path) => basename(path) !== "LOCK" });
|
|
69001
|
+
return readLevelDb(copy);
|
|
69002
|
+
});
|
|
68725
69003
|
}
|
|
68726
|
-
const
|
|
68727
|
-
if (
|
|
68728
|
-
|
|
68729
|
-
|
|
68730
|
-
|
|
68731
|
-
|
|
68732
|
-
|
|
68733
|
-
|
|
69004
|
+
const indexedDb = indexedDbPath(source);
|
|
69005
|
+
if (existsSync2(indexedDb)) {
|
|
69006
|
+
snapshot.indexedDb = join3(work, "idb");
|
|
69007
|
+
await retried(sleep3, () => {
|
|
69008
|
+
rmSync2(snapshot.indexedDb, { recursive: true, force: true });
|
|
69009
|
+
cpSync(indexedDb, snapshot.indexedDb, {
|
|
69010
|
+
recursive: true,
|
|
69011
|
+
preserveTimestamps: true,
|
|
69012
|
+
filter: (path) => basename(path) !== "LOCK"
|
|
69013
|
+
});
|
|
69014
|
+
});
|
|
68734
69015
|
}
|
|
68735
|
-
|
|
68736
|
-
return {
|
|
68737
|
-
ok: true,
|
|
68738
|
-
frame: { ...env.data, payload: payload.data },
|
|
68739
|
-
...ext ? { ext } : {}
|
|
68740
|
-
};
|
|
68741
|
-
}
|
|
68742
|
-
function buildEnvelopeRaw(type, payload, opts = {}) {
|
|
68743
|
-
return {
|
|
68744
|
-
v: 1,
|
|
68745
|
-
id: opts.id ?? randomUUID(),
|
|
68746
|
-
ts: opts.ts ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
68747
|
-
type,
|
|
68748
|
-
payload,
|
|
68749
|
-
...opts.corr ? { corr: opts.corr } : {},
|
|
68750
|
-
...opts.orgId ? { orgId: opts.orgId } : {},
|
|
68751
|
-
...opts.ext ?? {}
|
|
68752
|
-
};
|
|
69016
|
+
return snapshot;
|
|
68753
69017
|
}
|
|
68754
|
-
|
|
68755
|
-
|
|
68756
|
-
|
|
68757
|
-
|
|
68758
|
-
|
|
68759
|
-
|
|
68760
|
-
|
|
68761
|
-
|
|
68762
|
-
|
|
68763
|
-
|
|
68764
|
-
|
|
68765
|
-
"ATTESTATION_INVALID",
|
|
68766
|
-
// fencing / ordering
|
|
68767
|
-
"STALE_EPOCH",
|
|
68768
|
-
"STALE_LAUNCH",
|
|
68769
|
-
// delivery
|
|
68770
|
-
"NO_SESSION",
|
|
68771
|
-
"SCOPE_DENIED",
|
|
68772
|
-
// delegated MCP authority / invocation binding
|
|
68773
|
-
"DELEGATION_DENIED",
|
|
68774
|
-
"INVOCATION_CONFLICT",
|
|
68775
|
-
// secrets
|
|
68776
|
-
"LEASE_EXPIRED",
|
|
68777
|
-
"LEASE_DENIED",
|
|
68778
|
-
// generic
|
|
68779
|
-
"RATE_LIMITED",
|
|
68780
|
-
"CONFLICT",
|
|
68781
|
-
"INTERNAL"
|
|
68782
|
-
]);
|
|
68783
|
-
var ErrorFrame = external_exports.object({
|
|
68784
|
-
code: ErrorCode,
|
|
68785
|
-
message: external_exports.string(),
|
|
68786
|
-
// human-readable, redacted of secrets
|
|
68787
|
-
retryable: external_exports.boolean(),
|
|
68788
|
-
details: external_exports.record(external_exports.string(), external_exports.unknown()).optional()
|
|
68789
|
-
});
|
|
68790
|
-
|
|
68791
|
-
// ../protocol/src/frames/computer-lease.ts
|
|
68792
|
-
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
68793
|
-
var COMPUTER_LEASE_AGENT_NAME_MAX = 200;
|
|
68794
|
-
var ComputerLeaseHolder = external_exports.object({
|
|
68795
|
-
sessionId: external_exports.string().min(1).max(256),
|
|
68796
|
-
agentId: external_exports.string().uuid(),
|
|
68797
|
-
agentName: external_exports.string().min(1).max(COMPUTER_LEASE_AGENT_NAME_MAX).optional()
|
|
68798
|
-
});
|
|
68799
|
-
var computerLeaseHolderName = (holder) => `${holder.agentId}/${holder.sessionId}`;
|
|
68800
|
-
var ComputerControlLease = external_exports.object({
|
|
68801
|
-
leaseId: external_exports.string().uuid(),
|
|
68802
|
-
computerId: external_exports.string().uuid(),
|
|
68803
|
-
holder: ComputerLeaseHolder,
|
|
68804
|
-
acquiredAt: external_exports.string().datetime(),
|
|
68805
|
-
expiresAt: external_exports.string().datetime()
|
|
68806
|
-
});
|
|
68807
|
-
var COMPUTER_LEASE_REFUSALS = ["computer_busy", "human_in_control", "unavailable", "denied"];
|
|
68808
|
-
var COMPUTER_LEASE_POLL_MAX_MS = 1e4;
|
|
68809
|
-
var COMPUTER_LEASE_WAIT_MAX_SECONDS = 600;
|
|
68810
|
-
var ComputerLeaseAcquire = external_exports.object({
|
|
68811
|
-
computerId: external_exports.string().uuid(),
|
|
68812
|
-
agentId: external_exports.string().uuid(),
|
|
68813
|
-
sessionId: external_exports.string().min(1).max(256),
|
|
68814
|
-
// The daemon-clock time of the request, compared with the `event/session` turn end on the same clock.
|
|
68815
|
-
requestedAt: external_exports.string().datetime(),
|
|
68816
|
-
// Behind COMPUTER_LEASE_QUEUE_FEATURE: wait in the Computer's FIFO queue, holding the reply up to this long.
|
|
68817
|
-
waitMs: external_exports.number().int().min(0).max(COMPUTER_LEASE_POLL_MAX_MS).optional()
|
|
68818
|
-
});
|
|
68819
|
-
var ComputerLeaseQueued = external_exports.object({
|
|
68820
|
-
position: external_exports.number().int().min(1),
|
|
68821
|
-
waitedMs: external_exports.number().int().min(0),
|
|
68822
|
-
// Time left before the wait ends in `computer_busy`.
|
|
68823
|
-
leftMs: external_exports.number().int().min(0)
|
|
68824
|
-
});
|
|
68825
|
-
var ComputerLeaseAcquireResult = external_exports.discriminatedUnion("granted", [
|
|
68826
|
-
external_exports.object({ granted: external_exports.literal(true), lease: ComputerControlLease }),
|
|
68827
|
-
external_exports.object({
|
|
68828
|
-
granted: external_exports.literal(false),
|
|
68829
|
-
code: external_exports.enum(COMPUTER_LEASE_REFUSALS),
|
|
68830
|
-
message: external_exports.string().max(500),
|
|
68831
|
-
holder: ComputerLeaseHolder.optional(),
|
|
68832
|
-
queued: ComputerLeaseQueued.optional()
|
|
68833
|
-
})
|
|
68834
|
-
]);
|
|
68835
|
-
var ComputerLeaseRelease = external_exports.object({
|
|
68836
|
-
computerId: external_exports.string().uuid(),
|
|
68837
|
-
agentId: external_exports.string().uuid(),
|
|
68838
|
-
sessionId: external_exports.string().min(1).max(256)
|
|
68839
|
-
});
|
|
68840
|
-
|
|
68841
|
-
// ../protocol/src/frames/computer-channel.ts
|
|
68842
|
-
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
68843
|
-
|
|
68844
|
-
// ../protocol/src/computer-channel-token.ts
|
|
68845
|
-
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
68846
|
-
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
68847
|
-
|
|
68848
|
-
// ../protocol/src/computer-viewer.ts
|
|
68849
|
-
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
68850
|
-
var COMPUTER_VIEWER_API_PREFIX = "/view/api/";
|
|
68851
|
-
var COMPUTER_VIEWER_MAX_REQUEST_BYTES = 64 * 1024;
|
|
68852
|
-
var COMPUTER_VIEWER_TRANSPORTS = ["direct", "stun", "turn"];
|
|
68853
|
-
var ComputerIceServer = external_exports.object({
|
|
68854
|
-
urls: external_exports.array(
|
|
68855
|
-
external_exports.string().regex(/^turns?:/).max(256)
|
|
68856
|
-
).min(1).max(4),
|
|
68857
|
-
username: external_exports.string().min(1).max(256),
|
|
68858
|
-
credential: external_exports.string().min(1).max(256)
|
|
68859
|
-
}).strict();
|
|
68860
|
-
var COMPUTER_ICE_SERVERS_MAX = 2;
|
|
68861
|
-
var ComputerStunUrl = external_exports.string().max(256).regex(/^stun:(\[[0-9a-fA-F:.]+\]|[A-Za-z0-9.-]+)(:\d{1,5})?$/, "expected stun:<host>[:<port>]");
|
|
68862
|
-
var ComputerTurnUrl = external_exports.string().max(256).regex(
|
|
68863
|
-
/^turns?:(\[[0-9a-fA-F:.]+\]|[A-Za-z0-9.-]+)(:\d{1,5})?(\?transport=(udp|tcp))?$/,
|
|
68864
|
-
"expected turn:<host>[:<port>][?transport=udp|tcp] or turns:"
|
|
68865
|
-
);
|
|
68866
|
-
var COMPUTER_STUN_URLS_MAX = 2;
|
|
68867
|
-
var ComputerViewerCandidate = external_exports.object({
|
|
68868
|
-
id: external_exports.string().min(1).max(64),
|
|
68869
|
-
candidate: external_exports.object({
|
|
68870
|
-
candidate: external_exports.string().max(1024),
|
|
68871
|
-
sdpMid: external_exports.string().max(64).nullish(),
|
|
68872
|
-
sdpMLineIndex: external_exports.number().int().min(0).max(64).nullish()
|
|
68873
|
-
}).nullable()
|
|
68874
|
-
});
|
|
68875
|
-
var ComputerViewerCandidatesRequest = external_exports.object({
|
|
68876
|
-
id: external_exports.string().min(1).max(64),
|
|
68877
|
-
after: external_exports.number().int().min(0).max(1e3).default(0)
|
|
68878
|
-
});
|
|
68879
|
-
var ComputerViewerOfferRequest = external_exports.object({ transport: external_exports.enum(COMPUTER_VIEWER_TRANSPORTS).optional() });
|
|
68880
|
-
var ComputerViewerRenewal = external_exports.object({ type: external_exports.literal("auth"), token: external_exports.string().min(1).max(4096) });
|
|
68881
|
-
|
|
68882
|
-
// ../protocol/src/computer-command-line.ts
|
|
68883
|
-
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
68884
|
-
var COMPUTER_SHELL_MODES = ["off", "ask", "on"];
|
|
68885
|
-
var COMPUTER_FILES_MODES = ["off", "read", "read-write"];
|
|
68886
|
-
var COMPUTER_FILE_ROOTS_MAX = 32;
|
|
68887
|
-
var ComputerFileRoot = external_exports.string().trim().min(1).max(1024).refine((p) => /^(\/|~(\/|$)|[A-Za-z]:[\\/])/.test(p) && !p.includes("\0"), "expected an absolute path");
|
|
68888
|
-
var COMPUTER_EXEC_TIMEOUT_DEFAULT_MS = 3e4;
|
|
68889
|
-
var COMPUTER_EXEC_TIMEOUT_MAX_MS = 9e4;
|
|
68890
|
-
var COMPUTER_EXEC_COMMAND_MAX_CHARS = 16384;
|
|
68891
|
-
var COMPUTER_EXEC_OUTPUT_TAIL_BYTES = 32 * 1024;
|
|
68892
|
-
var COMPUTER_EXEC_PER_SESSION_MAX = 4;
|
|
68893
|
-
var COMPUTER_EXEC_TOTAL_MAX = 8;
|
|
68894
|
-
var COMPUTER_READ_TEXT_MAX_BYTES = 256 * 1024;
|
|
68895
|
-
var COMPUTER_READ_IMAGE_MAX_BYTES = 5 * 1024 * 1024;
|
|
68896
|
-
var COMPUTER_WRITE_MAX_BYTES = 1024 * 1024;
|
|
68897
|
-
var COMPUTER_LIST_DIR_MAX = 1e3;
|
|
68898
|
-
var SHELL_RANK = { off: 0, ask: 1, on: 2 };
|
|
68899
|
-
var FILES_RANK = { off: 0, read: 1, "read-write": 2 };
|
|
68900
|
-
var narrowerShell = (a, b) => SHELL_RANK[a] <= SHELL_RANK[b] ? a : b;
|
|
68901
|
-
var narrowerFiles = (a, b) => FILES_RANK[a] <= FILES_RANK[b] ? a : b;
|
|
68902
|
-
|
|
68903
|
-
// ../protocol/src/computer-channel-token.ts
|
|
68904
|
-
var COMPUTER_CHANNEL_TOKEN_PREFIX = "actk1";
|
|
68905
|
-
var COMPUTER_CHANNEL_TOKEN_AUDIENCES = ["mcp", "relay", "view"];
|
|
68906
|
-
var COMPUTER_CHANNEL_TOKEN_MAX_TTL_MS = 5 * 6e4;
|
|
68907
|
-
var COMPUTER_AGENT_MODES = ["view", "control"];
|
|
68908
|
-
var ComputerChannelTokenClaims = external_exports.object({
|
|
68909
|
-
aud: external_exports.enum(COMPUTER_CHANNEL_TOKEN_AUDIENCES),
|
|
68910
|
-
// The Computer the token is for, and the id of the channel key that signed it.
|
|
68911
|
-
cmp: external_exports.string().uuid(),
|
|
68912
|
-
kid: external_exports.string().min(1).max(64),
|
|
68913
|
-
// Issue and expiry times, epoch milliseconds on the issuer's clock.
|
|
68914
|
-
iat: external_exports.number().int().nonnegative(),
|
|
68915
|
-
exp: external_exports.number().int().positive(),
|
|
68916
|
-
// `mcp` only: the agent session the calls belong to, its agent and daemon, and what the policy lets it do.
|
|
68917
|
-
ses: external_exports.string().min(1).max(256).optional(),
|
|
68918
|
-
agt: external_exports.string().uuid().optional(),
|
|
68919
|
-
dmn: external_exports.string().uuid().optional(),
|
|
68920
|
-
mode: external_exports.enum(COMPUTER_AGENT_MODES).optional(),
|
|
68921
|
-
// `mcp` only: the command-line tier the policy allows (§5.7); absent, as from an older CP, means none.
|
|
68922
|
-
sh: external_exports.enum(COMPUTER_SHELL_MODES).optional(),
|
|
68923
|
-
fs: external_exports.enum(COMPUTER_FILES_MODES).optional(),
|
|
68924
|
-
// `view` only: the member watching, the TURN servers the desktop may relay media through, and the STUN servers it may punch with.
|
|
68925
|
-
usr: external_exports.string().min(1).max(128).optional(),
|
|
68926
|
-
ice: external_exports.array(ComputerIceServer).max(COMPUTER_ICE_SERVERS_MAX).optional(),
|
|
68927
|
-
stun: external_exports.array(ComputerStunUrl).max(COMPUTER_STUN_URLS_MAX).optional()
|
|
68928
|
-
}).strip().refine((c) => c.aud !== "mcp" || c.ses !== void 0 && c.agt !== void 0 && c.mode !== void 0, {
|
|
68929
|
-
message: "an mcp token names its session, agent and mode"
|
|
68930
|
-
}).refine((c) => c.aud !== "view" || c.usr !== void 0 && c.mode !== void 0, {
|
|
68931
|
-
message: "a view token names its member and mode"
|
|
68932
|
-
}).refine((c) => c.exp > c.iat && c.exp - c.iat <= COMPUTER_CHANNEL_TOKEN_MAX_TTL_MS, {
|
|
68933
|
-
message: "token lifetime out of range"
|
|
68934
|
-
});
|
|
68935
|
-
var MAC_DOMAIN = "agentconnect/computer-channel-token/v1\n";
|
|
68936
|
-
var MAX_TOKEN_CHARS = 4096;
|
|
68937
|
-
function mac3(key, signed) {
|
|
68938
|
-
return createHmac("sha256", key).update(MAC_DOMAIN + signed).digest();
|
|
69018
|
+
async function retried(sleep3, attempt) {
|
|
69019
|
+
let last;
|
|
69020
|
+
for (let i = 0; i < SNAPSHOT_TRIES; i++) {
|
|
69021
|
+
try {
|
|
69022
|
+
return attempt();
|
|
69023
|
+
} catch (error63) {
|
|
69024
|
+
last = error63;
|
|
69025
|
+
await sleep3(SNAPSHOT_RETRY_MS);
|
|
69026
|
+
}
|
|
69027
|
+
}
|
|
69028
|
+
throw new Error(`could not snapshot a running profile: ${last.message}`);
|
|
68939
69029
|
}
|
|
68940
|
-
|
|
68941
|
-
|
|
68942
|
-
|
|
68943
|
-
|
|
69030
|
+
var scalar = (value) => typeof value === "bigint" ? value.toString() : value;
|
|
69031
|
+
var bindable = (value) => value instanceof Uint8Array ? Buffer.from(value) : value;
|
|
69032
|
+
function uniqueKey(db) {
|
|
69033
|
+
for (const index of db.prepare("PRAGMA index_list(cookies)").all()) {
|
|
69034
|
+
if (Number(index.unique) !== 1) continue;
|
|
69035
|
+
const name = String(index.name).replaceAll("'", "''");
|
|
69036
|
+
return db.prepare(`PRAGMA index_info('${name}')`).all().map((column) => String(column.name));
|
|
69037
|
+
}
|
|
69038
|
+
throw new Error("the cookies table has no unique index");
|
|
68944
69039
|
}
|
|
68945
|
-
function
|
|
68946
|
-
if (
|
|
68947
|
-
const
|
|
68948
|
-
|
|
69040
|
+
function mergeCookies(snapshot, target, previous, next, counts, now) {
|
|
69041
|
+
if (!existsSync2(target)) cpSync(snapshot, target);
|
|
69042
|
+
const source = openDb(snapshot);
|
|
69043
|
+
const db = openDb(target);
|
|
68949
69044
|
try {
|
|
68950
|
-
const
|
|
68951
|
-
|
|
68952
|
-
|
|
68953
|
-
|
|
69045
|
+
const columns = db.prepare("PRAGMA table_info(cookies)").all().map((column) => String(column.name));
|
|
69046
|
+
const sourceColumns = source.prepare("PRAGMA table_info(cookies)").all().map(
|
|
69047
|
+
(column) => String(column.name)
|
|
69048
|
+
);
|
|
69049
|
+
if (columns.join() !== sourceColumns.join()) throw new Error("the cookie databases have different schemas");
|
|
69050
|
+
const key = uniqueKey(db);
|
|
69051
|
+
const stamp = columns.includes("last_update_utc") ? "last_update_utc" : "creation_utc";
|
|
69052
|
+
const keyOf2 = (row) => JSON.stringify(key.map((column) => scalar(row[column])));
|
|
69053
|
+
const list2 = (database, sql) => {
|
|
69054
|
+
const statement = database.prepare(sql);
|
|
69055
|
+
statement.setReadBigInts(true);
|
|
69056
|
+
return statement.all();
|
|
69057
|
+
};
|
|
69058
|
+
const quoted = columns.map((column) => `"${column}"`).join(",");
|
|
69059
|
+
const mine = /* @__PURE__ */ new Map();
|
|
69060
|
+
for (const row of list2(db, `SELECT rowid AS ac_rowid, ${quoted} FROM cookies`)) {
|
|
69061
|
+
mine.set(keyOf2(row), { rowid: row.ac_rowid, stamp: row[stamp] });
|
|
69062
|
+
}
|
|
69063
|
+
const insert = db.prepare(`INSERT OR REPLACE INTO cookies (${quoted}) VALUES (${columns.map(() => "?").join(",")})`);
|
|
69064
|
+
const remove = db.prepare("DELETE FROM cookies WHERE rowid = ?");
|
|
69065
|
+
const nowUs = BigInt(now()) * 1000n + CHROME_EPOCH_OFFSET_US;
|
|
69066
|
+
db.exec("BEGIN");
|
|
69067
|
+
try {
|
|
69068
|
+
for (const row of list2(source, `SELECT ${quoted} FROM cookies`)) {
|
|
69069
|
+
const id = keyOf2(row);
|
|
69070
|
+
const updated = row[stamp];
|
|
69071
|
+
next[id] = updated.toString();
|
|
69072
|
+
const expires = row.expires_utc;
|
|
69073
|
+
if (Number(row.is_persistent) === 1 && expires > 0n && expires < nowUs) {
|
|
69074
|
+
counts.expired++;
|
|
69075
|
+
continue;
|
|
69076
|
+
}
|
|
69077
|
+
const current = mine.get(id);
|
|
69078
|
+
const changed = previous === void 0 || previous[id] !== updated.toString();
|
|
69079
|
+
if (!changed || current?.stamp === updated) {
|
|
69080
|
+
counts.kept++;
|
|
69081
|
+
continue;
|
|
69082
|
+
}
|
|
69083
|
+
insert.run(...columns.map((column) => bindable(row[column])));
|
|
69084
|
+
counts[current ? "updated" : "inserted"]++;
|
|
69085
|
+
}
|
|
69086
|
+
if (previous) {
|
|
69087
|
+
for (const id of Object.keys(previous)) {
|
|
69088
|
+
if (id in next) continue;
|
|
69089
|
+
const current = mine.get(id);
|
|
69090
|
+
if (current) {
|
|
69091
|
+
remove.run(current.rowid);
|
|
69092
|
+
counts.deleted++;
|
|
69093
|
+
}
|
|
69094
|
+
}
|
|
69095
|
+
}
|
|
69096
|
+
db.exec("COMMIT");
|
|
69097
|
+
} catch (error63) {
|
|
69098
|
+
db.exec("ROLLBACK");
|
|
69099
|
+
throw error63;
|
|
69100
|
+
}
|
|
69101
|
+
} finally {
|
|
69102
|
+
source.close();
|
|
69103
|
+
db.close();
|
|
68954
69104
|
}
|
|
68955
69105
|
}
|
|
68956
|
-
function
|
|
68957
|
-
|
|
68958
|
-
|
|
68959
|
-
|
|
68960
|
-
|
|
68961
|
-
|
|
68962
|
-
|
|
68963
|
-
|
|
68964
|
-
|
|
68965
|
-
|
|
68966
|
-
|
|
69106
|
+
function lastModified(meta3) {
|
|
69107
|
+
let pos = 0;
|
|
69108
|
+
while (pos < meta3.length) {
|
|
69109
|
+
const tag = meta3[pos++];
|
|
69110
|
+
let value = 0n;
|
|
69111
|
+
let shift = 0n;
|
|
69112
|
+
for (; ; ) {
|
|
69113
|
+
const byte = meta3[pos++];
|
|
69114
|
+
if (byte === void 0) return value.toString();
|
|
69115
|
+
value |= BigInt(byte & 127) << shift;
|
|
69116
|
+
shift += 7n;
|
|
69117
|
+
if (!(byte & 128)) break;
|
|
69118
|
+
}
|
|
69119
|
+
if (tag === 8) return value.toString();
|
|
69120
|
+
}
|
|
69121
|
+
return "0";
|
|
68967
69122
|
}
|
|
68968
|
-
|
|
68969
|
-
|
|
68970
|
-
|
|
68971
|
-
|
|
68972
|
-
|
|
68973
|
-
|
|
68974
|
-
|
|
68975
|
-
|
|
68976
|
-
|
|
68977
|
-
|
|
68978
|
-
|
|
68979
|
-
|
|
68980
|
-
|
|
68981
|
-
|
|
68982
|
-
|
|
68983
|
-
|
|
68984
|
-
|
|
68985
|
-
|
|
68986
|
-
|
|
68987
|
-
|
|
68988
|
-
|
|
68989
|
-
|
|
68990
|
-
|
|
68991
|
-
|
|
68992
|
-
|
|
68993
|
-
|
|
68994
|
-
|
|
68995
|
-
granted: external_exports.literal(true),
|
|
68996
|
-
token: external_exports.string().min(1).max(2048),
|
|
68997
|
-
expiresAt: external_exports.string().datetime(),
|
|
68998
|
-
mode: external_exports.enum(COMPUTER_AGENT_MODES),
|
|
68999
|
-
relays: external_exports.array(ComputerRelayEntry).max(COMPUTER_RELAYS_MAX),
|
|
69000
|
-
// What the approval cards name and whom they also reach (§4.2); an older CP sends none, and every approval is asked.
|
|
69001
|
-
name: external_exports.string().min(1).max(200).optional(),
|
|
69002
|
-
ownerUserId: external_exports.string().min(1).max(128).optional(),
|
|
69003
|
-
approvals: ComputerGrantApprovalsSchema.optional(),
|
|
69004
|
-
// The console users who may answer its approvals: the Computer's allowed members; an older CP sends none.
|
|
69005
|
-
approvers: external_exports.array(external_exports.string().min(1).max(128)).max(500).optional(),
|
|
69006
|
-
// The command-line tier the token allows (§5.7); an older CP sends none, which allows none.
|
|
69007
|
-
shell: external_exports.enum(COMPUTER_SHELL_MODES).optional(),
|
|
69008
|
-
files: external_exports.enum(COMPUTER_FILES_MODES).optional()
|
|
69009
|
-
}),
|
|
69010
|
-
external_exports.object({
|
|
69011
|
-
granted: external_exports.literal(false),
|
|
69012
|
-
code: external_exports.enum(COMPUTER_CHANNEL_REFUSALS),
|
|
69013
|
-
message: external_exports.string().max(500)
|
|
69014
|
-
})
|
|
69015
|
-
]);
|
|
69016
|
-
|
|
69017
|
-
// ../protocol/src/frames/computer-audit.ts
|
|
69018
|
-
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
69019
|
-
var COMPUTER_AUDIT_FEATURE = "computer-audit-v1";
|
|
69020
|
-
var COMPUTER_APPROVAL_META_KEY = "md.agentconnect/approval";
|
|
69021
|
-
var COMPUTER_APPROVAL_RESULTS = ["not_required", "allowed", "allowed_session"];
|
|
69022
|
-
var COMPUTER_AUDIT_BATCH_MAX = 100;
|
|
69023
|
-
var COMPUTER_AUDIT_BATCH_BYTES = REPLY_BUDGET;
|
|
69024
|
-
var COMPUTER_AUDIT_ARGS_MAX_CHARS = 2048;
|
|
69025
|
-
var AUDIT_STRING_MAX = 256;
|
|
69026
|
-
var AUDIT_COMMAND_MAX = 1536;
|
|
69027
|
-
var AUDIT_DEPTH_MAX = 6;
|
|
69028
|
-
var TEXT_KEYS = /* @__PURE__ */ new Set(["text", "value", "content"]);
|
|
69029
|
-
var CONTROL_CHARS = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g;
|
|
69030
|
-
var LONE_SURROGATE = /[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/g;
|
|
69031
|
-
function computerAuditText(value) {
|
|
69032
|
-
return value.replace(CONTROL_CHARS, "").replace(LONE_SURROGATE, "\uFFFD");
|
|
69123
|
+
function mergeLocalStorage(source, target, previous, next, report) {
|
|
69124
|
+
const merged = readLevelDb(target);
|
|
69125
|
+
let changed = false;
|
|
69126
|
+
if (!merged.has("VERSION") && source.has("VERSION")) {
|
|
69127
|
+
merged.set("VERSION", source.get("VERSION"));
|
|
69128
|
+
changed = true;
|
|
69129
|
+
}
|
|
69130
|
+
for (const [key, meta3] of source) {
|
|
69131
|
+
if (!key.startsWith("META:")) continue;
|
|
69132
|
+
const origin = key.slice("META:".length);
|
|
69133
|
+
const modified = lastModified(meta3);
|
|
69134
|
+
next[origin] = modified;
|
|
69135
|
+
const mine = merged.get(key);
|
|
69136
|
+
if (previous !== void 0 && previous[origin] === modified || mine && mine.equals(meta3)) {
|
|
69137
|
+
report.kept++;
|
|
69138
|
+
continue;
|
|
69139
|
+
}
|
|
69140
|
+
const prefix = `_${origin}\0`;
|
|
69141
|
+
for (const existing of [...merged.keys()]) if (existing.startsWith(prefix)) merged.delete(existing);
|
|
69142
|
+
for (const [entry, value] of source) if (entry.startsWith(prefix)) merged.set(entry, value);
|
|
69143
|
+
merged.set(key, meta3);
|
|
69144
|
+
const access = source.get(`METAACCESS:${origin}`);
|
|
69145
|
+
if (access) merged.set(`METAACCESS:${origin}`, access);
|
|
69146
|
+
report.taken.push(origin);
|
|
69147
|
+
changed = true;
|
|
69148
|
+
}
|
|
69149
|
+
if (changed) writeLevelDb(target, merged);
|
|
69033
69150
|
}
|
|
69034
|
-
function
|
|
69035
|
-
|
|
69036
|
-
|
|
69037
|
-
|
|
69038
|
-
|
|
69039
|
-
|
|
69040
|
-
for (const [key, item] of Object.entries(value))
|
|
69041
|
-
out[computerAuditText(key.slice(0, 64))] = auditValue(item, depth + 1);
|
|
69042
|
-
return out;
|
|
69151
|
+
function newestMtime(dir) {
|
|
69152
|
+
let newest = 0;
|
|
69153
|
+
for (const entry of readdirSync2(dir, { withFileTypes: true, recursive: true })) {
|
|
69154
|
+
if (entry.isFile()) newest = Math.max(newest, statSync(join3(entry.parentPath, entry.name)).mtimeMs);
|
|
69155
|
+
}
|
|
69156
|
+
return newest;
|
|
69043
69157
|
}
|
|
69044
|
-
function
|
|
69045
|
-
|
|
69046
|
-
|
|
69047
|
-
|
|
69048
|
-
|
|
69049
|
-
|
|
69158
|
+
function mergeIndexedDb(snapshot, target, previous, next, report) {
|
|
69159
|
+
for (const name of readdirSync2(snapshot)) {
|
|
69160
|
+
if (!name.endsWith(".indexeddb.leveldb")) continue;
|
|
69161
|
+
const origin = name.slice(0, -".indexeddb.leveldb".length);
|
|
69162
|
+
const modified = newestMtime(join3(snapshot, name));
|
|
69163
|
+
next[origin] = modified;
|
|
69164
|
+
const mine = join3(target, name);
|
|
69165
|
+
if (previous !== void 0 && previous[origin] === modified || existsSync2(mine) && newestMtime(mine) === modified) {
|
|
69166
|
+
report.kept++;
|
|
69050
69167
|
continue;
|
|
69051
69168
|
}
|
|
69052
|
-
|
|
69169
|
+
for (const suffix of [".indexeddb.leveldb", ".indexeddb.blob"]) {
|
|
69170
|
+
const to = join3(target, origin + suffix);
|
|
69171
|
+
rmSync2(to, { recursive: true, force: true });
|
|
69172
|
+
const from = join3(snapshot, origin + suffix);
|
|
69173
|
+
if (existsSync2(from)) cpSync(from, to, { recursive: true, preserveTimestamps: true });
|
|
69174
|
+
}
|
|
69175
|
+
report.taken.push(origin);
|
|
69053
69176
|
}
|
|
69054
|
-
const bounded = JSON.stringify(out).length <= COMPUTER_AUDIT_ARGS_MAX_CHARS ? out : { truncated: true };
|
|
69055
|
-
return { args: bounded, ...textLength !== void 0 ? { textLength } : {} };
|
|
69056
69177
|
}
|
|
69057
|
-
var ComputerAuditEntry = external_exports.object({
|
|
69058
|
-
// Idempotency: a batch resent after a lost ack does not duplicate rows.
|
|
69059
|
-
id: external_exports.string().uuid(),
|
|
69060
|
-
at: external_exports.string().datetime(),
|
|
69061
|
-
tool: external_exports.string().min(1).max(128),
|
|
69062
|
-
// The lease holder name: `agentId/sessionId` for an agent session, else a local client or viewer name.
|
|
69063
|
-
client: external_exports.string().min(1).max(512),
|
|
69064
|
-
agentId: external_exports.string().uuid().optional(),
|
|
69065
|
-
sessionId: external_exports.string().min(1).max(256).optional(),
|
|
69066
|
-
outcome: external_exports.enum(["ok", "error"]),
|
|
69067
|
-
code: external_exports.string().min(1).max(64).optional(),
|
|
69068
|
-
approval: external_exports.enum(COMPUTER_APPROVAL_RESULTS).optional(),
|
|
69069
|
-
args: external_exports.record(external_exports.string().max(64), external_exports.unknown()).refine((args) => JSON.stringify(args).length <= COMPUTER_AUDIT_ARGS_MAX_CHARS, "audit args too large").optional(),
|
|
69070
|
-
textLength: external_exports.number().int().min(0).max(1e6).optional(),
|
|
69071
|
-
ms: external_exports.number().int().min(0),
|
|
69072
|
-
// The stored screenshot this call returned (§9), as `sha256:<hex>`.
|
|
69073
|
-
screenshotRef: external_exports.string().min(1).max(1024).optional()
|
|
69074
|
-
}).strict();
|
|
69075
|
-
var ComputerAuditReport = external_exports.object({
|
|
69076
|
-
entries: external_exports.array(ComputerAuditEntry).min(1).max(COMPUTER_AUDIT_BATCH_MAX)
|
|
69077
|
-
});
|
|
69078
|
-
var ComputerAuditAck = external_exports.object({ stored: external_exports.number().int().min(0) });
|
|
69079
69178
|
|
|
69080
|
-
//
|
|
69081
|
-
|
|
69082
|
-
var
|
|
69083
|
-
var
|
|
69084
|
-
var
|
|
69085
|
-
var
|
|
69086
|
-
|
|
69087
|
-
|
|
69088
|
-
|
|
69089
|
-
|
|
69090
|
-
|
|
69179
|
+
// src/browser/launcher.ts
|
|
69180
|
+
var BROWSER_NAMES = ["chromium", "chromium-browser", "google-chrome-stable", "google-chrome"];
|
|
69181
|
+
var BASE_FLAGS = ["--no-first-run", "--no-default-browser-check", "--hide-crash-restore-bubble"];
|
|
69182
|
+
var LOCK_STALE_MS = 6e4;
|
|
69183
|
+
var LOCK_WAIT_MS = 3e4;
|
|
69184
|
+
var OWN_WAIT_MS = 2e4;
|
|
69185
|
+
function profileOwner(profile, host = hostname4()) {
|
|
69186
|
+
let target;
|
|
69187
|
+
try {
|
|
69188
|
+
target = readlinkSync(join4(profile, "SingletonLock"));
|
|
69189
|
+
} catch {
|
|
69190
|
+
return void 0;
|
|
69191
|
+
}
|
|
69192
|
+
const match = /^(.*)-(\d+)$/.exec(target);
|
|
69193
|
+
if (!match || match[1] !== host) return void 0;
|
|
69194
|
+
const pid = Number(match[2]);
|
|
69195
|
+
try {
|
|
69196
|
+
process.kill(pid, 0);
|
|
69197
|
+
return pid;
|
|
69198
|
+
} catch (error63) {
|
|
69199
|
+
return error63.code === "EPERM" ? pid : void 0;
|
|
69200
|
+
}
|
|
69091
69201
|
}
|
|
69092
|
-
|
|
69093
|
-
|
|
69094
|
-
|
|
69095
|
-
sha256: ComputerScreenshotSha256,
|
|
69096
|
-
bytes: external_exports.number().int().positive().max(COMPUTER_SCREENSHOT_MAX_BYTES),
|
|
69097
|
-
contentType: external_exports.enum(COMPUTER_SCREENSHOT_CONTENT_TYPES),
|
|
69098
|
-
takenAt: external_exports.string().datetime()
|
|
69099
|
-
}).strict();
|
|
69100
|
-
var ComputerScreenshotPutOk = external_exports.object({
|
|
69101
|
-
status: external_exports.enum(["upload", "stored", "skipped"]),
|
|
69102
|
-
url: external_exports.string().url().optional(),
|
|
69103
|
-
headers: external_exports.record(external_exports.string(), external_exports.string()).optional(),
|
|
69104
|
-
expiresAt: external_exports.string().datetime().optional(),
|
|
69105
|
-
reason: external_exports.string().max(200).optional()
|
|
69106
|
-
});
|
|
69107
|
-
var ComputerScreenshotCommit = external_exports.object({ sessionId: external_exports.string().min(1).max(256), sha256: ComputerScreenshotSha256 }).strict();
|
|
69108
|
-
var ComputerScreenshotCommitOk = external_exports.object({ stored: external_exports.boolean() });
|
|
69109
|
-
|
|
69110
|
-
// ../protocol/src/frames/relay-computer.ts
|
|
69111
|
-
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
69112
|
-
var RELAY_COMPUTER_SUBPROTOCOL = "agentconnect.cr.v1";
|
|
69113
|
-
var RELAY_COMPUTER_WS_PATH = "/cr/ws";
|
|
69114
|
-
var RELAY_COMPUTER_MAX_BODY_BYTES = 8 * 1024 * 1024;
|
|
69115
|
-
var RELAY_COMPUTER_MAX_FRAME_BYTES = 12 * 1024 * 1024;
|
|
69116
|
-
var RELAY_DAEMON_PATH_SUFFIX = "/rd/ws";
|
|
69117
|
-
function relayUrlAt(relayUrl, path, scheme) {
|
|
69118
|
-
const url2 = new URL(relayUrl);
|
|
69119
|
-
const prefix = url2.pathname.endsWith(RELAY_DAEMON_PATH_SUFFIX) ? url2.pathname.slice(0, -RELAY_DAEMON_PATH_SUFFIX.length) : url2.pathname.replace(/\/+$/, "");
|
|
69120
|
-
for (const { from, to } of scheme) if (url2.protocol === from) url2.protocol = to;
|
|
69121
|
-
url2.pathname = `${prefix}${path}`;
|
|
69122
|
-
url2.search = "";
|
|
69123
|
-
url2.hash = "";
|
|
69124
|
-
return url2.toString();
|
|
69202
|
+
function seedable(path) {
|
|
69203
|
+
const name = basename2(path);
|
|
69204
|
+
return !(name.startsWith("Singleton") || /cache$/i.test(name) || name === "Crash Reports" || name === "Sessions" || name === "Session Storage" || name === BASELINE_FILE);
|
|
69125
69205
|
}
|
|
69126
|
-
function
|
|
69127
|
-
|
|
69128
|
-
|
|
69129
|
-
{ from: "https:", to: "wss:" }
|
|
69130
|
-
]);
|
|
69206
|
+
function seedProfile(master, profile) {
|
|
69207
|
+
mkdirSync3(dirname2(profile), { recursive: true });
|
|
69208
|
+
cpSync2(master, profile, { recursive: true, preserveTimestamps: true, filter: seedable });
|
|
69131
69209
|
}
|
|
69132
|
-
|
|
69133
|
-
|
|
69134
|
-
|
|
69135
|
-
|
|
69136
|
-
|
|
69137
|
-
|
|
69138
|
-
|
|
69139
|
-
|
|
69140
|
-
|
|
69141
|
-
|
|
69142
|
-
|
|
69143
|
-
|
|
69144
|
-
|
|
69145
|
-
|
|
69146
|
-
|
|
69147
|
-
|
|
69148
|
-
|
|
69149
|
-
|
|
69150
|
-
|
|
69151
|
-
|
|
69152
|
-
|
|
69153
|
-
|
|
69154
|
-
|
|
69155
|
-
|
|
69156
|
-
|
|
69157
|
-
|
|
69158
|
-
|
|
69159
|
-
|
|
69160
|
-
|
|
69161
|
-
|
|
69162
|
-
|
|
69163
|
-
|
|
69164
|
-
|
|
69165
|
-
|
|
69166
|
-
|
|
69167
|
-
|
|
69210
|
+
function findBrowser(path = process.env.PATH ?? "", skip = []) {
|
|
69211
|
+
const skipped = new Set(skip.map((dir) => resolve(dir)));
|
|
69212
|
+
for (const name of BROWSER_NAMES) {
|
|
69213
|
+
for (const dir of path.split(delimiter)) {
|
|
69214
|
+
if (!dir || skipped.has(resolve(dir))) continue;
|
|
69215
|
+
const candidate = join4(dir, name);
|
|
69216
|
+
try {
|
|
69217
|
+
accessSync(candidate, constants.X_OK);
|
|
69218
|
+
if (statSync2(candidate).isFile()) return candidate;
|
|
69219
|
+
} catch {
|
|
69220
|
+
}
|
|
69221
|
+
}
|
|
69222
|
+
}
|
|
69223
|
+
return void 0;
|
|
69224
|
+
}
|
|
69225
|
+
async function launchBrowser(options) {
|
|
69226
|
+
const log40 = options.log ?? (() => void 0);
|
|
69227
|
+
const release3 = await lockProfile(options.profile);
|
|
69228
|
+
try {
|
|
69229
|
+
if (profileOwner(options.profile) !== void 0) {
|
|
69230
|
+
start(options).unref();
|
|
69231
|
+
return { handedOff: true, reports: [] };
|
|
69232
|
+
}
|
|
69233
|
+
if (!existsSync3(options.profile)) {
|
|
69234
|
+
if (options.master && existsSync3(options.master)) {
|
|
69235
|
+
seedProfile(options.master, options.profile);
|
|
69236
|
+
log40(`browser profile ${options.profile} created from ${options.master}`);
|
|
69237
|
+
} else mkdirSync3(options.profile, { recursive: true });
|
|
69238
|
+
}
|
|
69239
|
+
for (const name of ["SingletonLock", "SingletonCookie", "SingletonSocket"]) {
|
|
69240
|
+
rmSync3(join4(options.profile, name), { force: true });
|
|
69241
|
+
}
|
|
69242
|
+
const self2 = realpathSync2(options.profile);
|
|
69243
|
+
const sources = options.sources.filter(
|
|
69244
|
+
(source) => existsSync3(join4(source, "Default")) && realpathSync2(source) !== self2
|
|
69245
|
+
);
|
|
69246
|
+
const reports = await forkMerge(options.profile, sources);
|
|
69247
|
+
for (const report of reports) log40(`browser fork-merge from ${report.source}: ${summarize(report)}`);
|
|
69248
|
+
const child2 = start(options);
|
|
69249
|
+
if (!await owned(options.profile, child2)) log40(`browser for ${options.profile} did not take its profile`);
|
|
69250
|
+
return { handedOff: false, reports, ...child2.pid !== void 0 ? { pid: child2.pid } : {} };
|
|
69251
|
+
} finally {
|
|
69252
|
+
release3();
|
|
69253
|
+
}
|
|
69254
|
+
}
|
|
69255
|
+
function start(options) {
|
|
69256
|
+
const child2 = spawn2(options.browser, [`--user-data-dir=${options.profile}`, ...BASE_FLAGS, ...options.args ?? []], {
|
|
69257
|
+
detached: true,
|
|
69258
|
+
stdio: "ignore",
|
|
69259
|
+
env: options.env ?? process.env
|
|
69168
69260
|
});
|
|
69261
|
+
child2.on("error", () => void 0);
|
|
69262
|
+
return child2;
|
|
69169
69263
|
}
|
|
69170
|
-
function
|
|
69171
|
-
|
|
69264
|
+
async function owned(profile, child2) {
|
|
69265
|
+
let ended = false;
|
|
69266
|
+
const end = () => void (ended = true);
|
|
69267
|
+
child2.once("error", end).once("exit", end);
|
|
69268
|
+
try {
|
|
69269
|
+
const deadline = Date.now() + OWN_WAIT_MS;
|
|
69270
|
+
for (; ; ) {
|
|
69271
|
+
if (profileOwner(profile) !== void 0) return true;
|
|
69272
|
+
if (ended || Date.now() > deadline) return false;
|
|
69273
|
+
await new Promise((resolveWait) => setTimeout(resolveWait, 100));
|
|
69274
|
+
}
|
|
69275
|
+
} finally {
|
|
69276
|
+
child2.off("error", end).off("exit", end);
|
|
69277
|
+
child2.unref();
|
|
69278
|
+
}
|
|
69279
|
+
}
|
|
69280
|
+
function summarize(report) {
|
|
69281
|
+
const c = report.cookies;
|
|
69282
|
+
return [
|
|
69283
|
+
report.firstFork ? "first fork" : "since last fork",
|
|
69284
|
+
`cookies +${c.inserted} ~${c.updated} -${c.deleted} (kept ${c.kept}, expired ${c.expired})`,
|
|
69285
|
+
`localStorage ${report.localStorage.taken.length} origin(s)`,
|
|
69286
|
+
`IndexedDB ${report.indexedDb.taken.length} origin(s)`
|
|
69287
|
+
].join(", ");
|
|
69288
|
+
}
|
|
69289
|
+
async function lockProfile(profile) {
|
|
69290
|
+
const path = `${profile}.launch-lock`;
|
|
69291
|
+
mkdirSync3(dirname2(path), { recursive: true });
|
|
69292
|
+
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
69293
|
+
for (; ; ) {
|
|
69294
|
+
try {
|
|
69295
|
+
closeSync(openSync(path, "wx"));
|
|
69296
|
+
return () => rmSync3(path, { force: true });
|
|
69297
|
+
} catch (error63) {
|
|
69298
|
+
if (error63.code !== "EEXIST") throw error63;
|
|
69299
|
+
try {
|
|
69300
|
+
if (Date.now() - statSync2(path).mtimeMs > LOCK_STALE_MS) rmSync3(path, { force: true });
|
|
69301
|
+
} catch {
|
|
69302
|
+
}
|
|
69303
|
+
if (Date.now() > deadline) throw new Error(`another browser launch for ${profile} is still running`);
|
|
69304
|
+
await new Promise((resolveWait) => setTimeout(resolveWait, 200));
|
|
69305
|
+
}
|
|
69306
|
+
}
|
|
69172
69307
|
}
|
|
69173
69308
|
|
|
69174
|
-
//
|
|
69175
|
-
|
|
69176
|
-
var
|
|
69177
|
-
|
|
69178
|
-
|
|
69179
|
-
|
|
69180
|
-
|
|
69181
|
-
|
|
69182
|
-
|
|
69183
|
-
|
|
69184
|
-
|
|
69309
|
+
// src/browser/close.ts
|
|
69310
|
+
var OP_QUERY_TREE = 15;
|
|
69311
|
+
var OP_INTERN_ATOM = 16;
|
|
69312
|
+
var OP_GET_PROPERTY = 20;
|
|
69313
|
+
var OP_SEND_EVENT = 25;
|
|
69314
|
+
var CLIENT_MESSAGE = 33;
|
|
69315
|
+
async function closeBrowser(options) {
|
|
69316
|
+
const log40 = options.log ?? (() => void 0);
|
|
69317
|
+
const pid = profileOwner(options.profile);
|
|
69318
|
+
if (pid === void 0) return "not-running";
|
|
69319
|
+
try {
|
|
69320
|
+
const x = await X11Connection.connect({
|
|
69321
|
+
display: options.display,
|
|
69322
|
+
...options.xauthority ? { xauthority: options.xauthority } : {}
|
|
69323
|
+
});
|
|
69324
|
+
try {
|
|
69325
|
+
const windows = await windowsOf(x, pid);
|
|
69326
|
+
const protocols = await internAtom(x, "WM_PROTOCOLS");
|
|
69327
|
+
const remove = await internAtom(x, "WM_DELETE_WINDOW");
|
|
69328
|
+
for (const window2 of windows) await sendClientMessage(x, window2, protocols, [remove, 0, 0, 0, 0]);
|
|
69329
|
+
log40(`asked ${windows.length} browser window(s) of ${options.profile} to close`);
|
|
69330
|
+
} finally {
|
|
69331
|
+
x.close();
|
|
69332
|
+
}
|
|
69333
|
+
} catch (error63) {
|
|
69334
|
+
log40(`could not ask the browser of ${options.profile} to close: ${error63.message}`);
|
|
69335
|
+
}
|
|
69336
|
+
if (await exited(pid, options.timeoutMs ?? 15e3)) return "closed";
|
|
69337
|
+
log40(`browser ${pid} did not exit after its windows closed; sending SIGTERM (unflushed cookies may be lost)`);
|
|
69338
|
+
process.kill(pid, "SIGTERM");
|
|
69339
|
+
if (await exited(pid, 5e3)) return "terminated";
|
|
69340
|
+
process.kill(pid, "SIGKILL");
|
|
69341
|
+
return "killed";
|
|
69342
|
+
}
|
|
69343
|
+
async function waitForWindowManager(display, timeoutMs) {
|
|
69344
|
+
const deadline = Date.now() + timeoutMs;
|
|
69345
|
+
while (Date.now() < deadline) {
|
|
69346
|
+
try {
|
|
69347
|
+
const x = await X11Connection.connect({ display });
|
|
69348
|
+
try {
|
|
69349
|
+
const check2 = await internAtom(x, "_NET_SUPPORTING_WM_CHECK");
|
|
69350
|
+
if (await cardinal(x, x.setup.root, check2, 33) !== void 0) return true;
|
|
69351
|
+
} finally {
|
|
69352
|
+
x.close();
|
|
69353
|
+
}
|
|
69354
|
+
} catch {
|
|
69355
|
+
}
|
|
69356
|
+
await new Promise((resolve5) => setTimeout(resolve5, 200));
|
|
69357
|
+
}
|
|
69358
|
+
return false;
|
|
69185
69359
|
}
|
|
69186
|
-
|
|
69187
|
-
|
|
69188
|
-
|
|
69189
|
-
|
|
69190
|
-
|
|
69191
|
-
|
|
69192
|
-
|
|
69193
|
-
|
|
69194
|
-
|
|
69195
|
-
|
|
69196
|
-
try {
|
|
69197
|
-
new Intl.DateTimeFormat("en-US", { timeZone: tz });
|
|
69198
|
-
return true;
|
|
69199
|
-
} catch {
|
|
69200
|
-
return false;
|
|
69360
|
+
async function exited(pid, timeoutMs) {
|
|
69361
|
+
const deadline = Date.now() + timeoutMs;
|
|
69362
|
+
for (; ; ) {
|
|
69363
|
+
try {
|
|
69364
|
+
process.kill(pid, 0);
|
|
69365
|
+
} catch {
|
|
69366
|
+
return true;
|
|
69367
|
+
}
|
|
69368
|
+
if (Date.now() > deadline) return false;
|
|
69369
|
+
await new Promise((resolve5) => setTimeout(resolve5, 200));
|
|
69201
69370
|
}
|
|
69202
69371
|
}
|
|
69203
|
-
|
|
69204
|
-
|
|
69205
|
-
|
|
69206
|
-
|
|
69207
|
-
|
|
69208
|
-
|
|
69209
|
-
|
|
69210
|
-
|
|
69211
|
-
allowedMembers: external_exports.array(external_exports.string().min(1).max(128)).max(500).default([]),
|
|
69212
|
-
agentMode: external_exports.enum(["view", "control"]).default("control"),
|
|
69213
|
-
approvals: ComputerApprovalsSchema.default({ firstInputPerSession: true }),
|
|
69214
|
-
appAllowlist: external_exports.array(AppId).max(200).optional(),
|
|
69215
|
-
redactApps: external_exports.array(AppId).max(200).default([]),
|
|
69216
|
-
exposeDriverTools: external_exports.boolean().default(false),
|
|
69217
|
-
quietHours: external_exports.object({
|
|
69218
|
-
tz: external_exports.string().min(1).max(64).refine(isTimeZone, "unknown IANA time zone"),
|
|
69219
|
-
ranges: external_exports.array(external_exports.string().regex(QUIET_RANGE_RE, "expected HH:MM-HH:MM")).min(1).max(24)
|
|
69220
|
-
}).optional(),
|
|
69221
|
-
leaseIdleSeconds: external_exports.number().int().min(10).max(3600).default(120),
|
|
69222
|
-
leaseMaxSeconds: external_exports.number().int().min(60).max(86400).default(1800),
|
|
69223
|
-
// Seconds an acquire waits in the FIFO lease queue before `computer_busy` (§4.4); 0 never waits.
|
|
69224
|
-
leaseWaitSeconds: external_exports.number().int().min(0).max(COMPUTER_LEASE_WAIT_MAX_SECONDS).default(45),
|
|
69225
|
-
// Days stored screenshots are kept (§9); 0 means never written, absent means the deployment's default.
|
|
69226
|
-
screenshotRetentionDays: external_exports.number().int().min(0).max(COMPUTER_SCREENSHOT_RETENTION_MAX_DAYS).optional(),
|
|
69227
|
-
// Whether viewers may hole-punch peer to peer, which shows them the desktop's public IP (§7.2); absent means on only for owner-only viewing.
|
|
69228
|
-
viewerPeerToPeer: external_exports.boolean().optional(),
|
|
69229
|
-
// The command-line tier (§5.7); absent means the Computer's default, on for a managed one and off otherwise.
|
|
69230
|
-
shell: external_exports.enum(COMPUTER_SHELL_MODES).optional(),
|
|
69231
|
-
files: external_exports.enum(COMPUTER_FILES_MODES).optional(),
|
|
69232
|
-
// Prefixes the file tools may touch; absent means the user's home directory.
|
|
69233
|
-
fileRoots: external_exports.array(ComputerFileRoot).max(COMPUTER_FILE_ROOTS_MAX).optional()
|
|
69234
|
-
}).refine((p) => p.leaseIdleSeconds <= p.leaseMaxSeconds, {
|
|
69235
|
-
message: "leaseIdleSeconds must not exceed leaseMaxSeconds",
|
|
69236
|
-
path: ["leaseIdleSeconds"]
|
|
69237
|
-
}).refine((p) => p.agentMode === "control" || p.shell === void 0 || p.shell === "off", {
|
|
69238
|
-
message: "a shell needs agentMode control",
|
|
69239
|
-
path: ["shell"]
|
|
69240
|
-
});
|
|
69241
|
-
var ComputerCapabilitiesSchema = external_exports.object({
|
|
69242
|
-
screenshot: external_exports.boolean().default(false),
|
|
69243
|
-
input: external_exports.boolean().default(false),
|
|
69244
|
-
textInput: external_exports.enum(["full", "keymap-only"]).default("full"),
|
|
69245
|
-
// Which human input pauses agents (§6); absent reads as pointer only, what older desktops detect.
|
|
69246
|
-
humanActivity: external_exports.enum(["pointer", "pointer+keyboard"]).optional(),
|
|
69247
|
-
backgroundInput: external_exports.boolean().default(false),
|
|
69248
|
-
accessibilityTree: external_exports.boolean().default(false),
|
|
69249
|
-
viewer: external_exports.boolean().default(false),
|
|
69250
|
-
// The viewer accepts a view token's `stun` claim; desktops before relay STUN refuse such a token.
|
|
69251
|
-
viewerStun: external_exports.boolean().optional(),
|
|
69252
|
-
// The browser's traffic leaves through the desktop's egress forwarder, which applies `computer/egress` (§15.4).
|
|
69253
|
-
egress: external_exports.boolean().optional(),
|
|
69254
|
-
// The command-line tier can run here (§5.7): computer_exec, and the file tools.
|
|
69255
|
-
exec: external_exports.boolean().optional(),
|
|
69256
|
-
files: external_exports.boolean().optional(),
|
|
69257
|
-
displays: external_exports.array(
|
|
69258
|
-
external_exports.object({
|
|
69259
|
-
id: external_exports.string().min(1).max(128),
|
|
69260
|
-
width: external_exports.number().int().positive().max(1e5),
|
|
69261
|
-
height: external_exports.number().int().positive().max(1e5),
|
|
69262
|
-
scale: external_exports.number().positive().max(16)
|
|
69263
|
-
})
|
|
69264
|
-
).max(16).default([]),
|
|
69265
|
-
permissions: external_exports.object({
|
|
69266
|
-
accessibility: external_exports.boolean().optional(),
|
|
69267
|
-
screenRecording: external_exports.boolean().optional(),
|
|
69268
|
-
portal: external_exports.boolean().optional(),
|
|
69269
|
-
firewall: external_exports.boolean().optional()
|
|
69270
|
-
}).default({})
|
|
69271
|
-
});
|
|
69272
|
-
var ComputerDoctorCheck = external_exports.object({
|
|
69273
|
-
name: external_exports.string().min(1).max(64),
|
|
69274
|
-
status: external_exports.enum(["ok", "info", "warn", "fail"]),
|
|
69275
|
-
detail: external_exports.string().max(1e3),
|
|
69276
|
-
fix: external_exports.string().max(1e3).optional()
|
|
69277
|
-
});
|
|
69278
|
-
var ComputerDoctorReport = external_exports.object({
|
|
69279
|
-
checkedAt: external_exports.string().datetime(),
|
|
69280
|
-
checks: external_exports.array(ComputerDoctorCheck).max(64)
|
|
69281
|
-
});
|
|
69282
|
-
var ComputerChannelCredential = external_exports.object({
|
|
69283
|
-
keyId: external_exports.string().min(1).max(64),
|
|
69284
|
-
// 32 random-looking bytes, base64url without padding; secret material, never logged.
|
|
69285
|
-
key: external_exports.string().regex(/^[A-Za-z0-9_-]{43}$/),
|
|
69286
|
-
issuedAt: external_exports.string().datetime(),
|
|
69287
|
-
expiresAt: external_exports.string().datetime()
|
|
69288
|
-
});
|
|
69289
|
-
var ComputerEgressProxyUrl = external_exports.string().max(512).refine((raw) => {
|
|
69290
|
-
try {
|
|
69291
|
-
const u = new URL(raw);
|
|
69292
|
-
return (u.protocol === "http:" || u.protocol === "https:") && u.hostname !== "" && u.username === "" && u.password === "" && (u.pathname === "" || u.pathname === "/") && u.search === "" && u.hash === "";
|
|
69293
|
-
} catch {
|
|
69294
|
-
return false;
|
|
69372
|
+
async function windowsOf(x, pid) {
|
|
69373
|
+
const pidAtom = await internAtom(x, "_NET_WM_PID");
|
|
69374
|
+
const found = [];
|
|
69375
|
+
for (const frame of await queryTree(x, x.setup.root)) {
|
|
69376
|
+
for (const window2 of [frame, ...await queryTree(x, frame)]) {
|
|
69377
|
+
const value = await cardinal(x, window2, pidAtom);
|
|
69378
|
+
if (value === pid) found.push(window2);
|
|
69379
|
+
}
|
|
69295
69380
|
}
|
|
69296
|
-
|
|
69297
|
-
var ComputerEgress = external_exports.discriminatedUnion("mode", [
|
|
69298
|
-
external_exports.object({ mode: external_exports.literal("direct") }),
|
|
69299
|
-
external_exports.object({
|
|
69300
|
-
mode: external_exports.literal("proxy"),
|
|
69301
|
-
url: ComputerEgressProxyUrl,
|
|
69302
|
-
username: external_exports.string().min(1).max(256).optional(),
|
|
69303
|
-
password: external_exports.string().min(1).max(512).optional()
|
|
69304
|
-
})
|
|
69305
|
-
]);
|
|
69306
|
-
var COMPUTER_EGRESS_FEATURE = "computer-egress-v1";
|
|
69307
|
-
var ComputerAuth = external_exports.object({
|
|
69308
|
-
apiKey: external_exports.string().min(1).max(256),
|
|
69309
|
-
desktopDaemonVersion: external_exports.string().trim().min(1).max(64)
|
|
69310
|
-
}).strict();
|
|
69311
|
-
var ComputerAuthOk = external_exports.object({
|
|
69312
|
-
computerId: external_exports.string().uuid(),
|
|
69313
|
-
orgId: external_exports.string().min(1).max(64),
|
|
69314
|
-
name: external_exports.string().min(1).max(200),
|
|
69315
|
-
heartbeatSec: external_exports.number().int().positive(),
|
|
69316
|
-
serverTime: external_exports.string().datetime(),
|
|
69317
|
-
credential: ComputerChannelCredential,
|
|
69318
|
-
policy: ComputerPolicySchema,
|
|
69319
|
-
// What this CP accepts on the channel beyond the base frames, such as `computer-audit-v1`.
|
|
69320
|
-
features: external_exports.array(external_exports.string().min(1).max(64)).max(32).optional(),
|
|
69321
|
-
// The retention in effect for this Computer's screenshots (§9); 0 or absent means none are stored.
|
|
69322
|
-
screenshotRetentionDays: external_exports.number().int().min(0).max(COMPUTER_SCREENSHOT_RETENTION_MAX_DAYS).optional(),
|
|
69323
|
-
// A managed desktop's egress (§15.4); absent means direct unless `computer-egress-v1` is advertised. Secret, never logged.
|
|
69324
|
-
egress: ComputerEgress.optional()
|
|
69325
|
-
});
|
|
69326
|
-
var ComputerHeartbeat = external_exports.object({
|
|
69327
|
-
status: external_exports.enum(COMPUTER_LIVE_STATUSES),
|
|
69328
|
-
osVersion: external_exports.string().trim().min(1).max(120).optional(),
|
|
69329
|
-
session: external_exports.enum(COMPUTER_SESSIONS).optional(),
|
|
69330
|
-
desktopDaemonVersion: external_exports.string().trim().min(1).max(64).optional(),
|
|
69331
|
-
driverVersion: external_exports.string().trim().min(1).max(64).optional(),
|
|
69332
|
-
capabilities: ComputerCapabilitiesSchema.optional(),
|
|
69333
|
-
doctor: ComputerDoctorReport.optional(),
|
|
69334
|
-
// The local lease, how long since its last input, and how long it has been held without idling out.
|
|
69335
|
-
lease: external_exports.object({
|
|
69336
|
-
holder: external_exports.string().min(1).max(512),
|
|
69337
|
-
idleMs: external_exports.number().int().min(0),
|
|
69338
|
-
heldMs: external_exports.number().int().min(0).optional()
|
|
69339
|
-
}).strict().optional()
|
|
69340
|
-
}).strict();
|
|
69341
|
-
var ComputerCredentialRenewal = external_exports.object({ credential: ComputerChannelCredential });
|
|
69342
|
-
var ComputerPolicyPush = external_exports.object({
|
|
69343
|
-
policy: ComputerPolicySchema,
|
|
69344
|
-
screenshotRetentionDays: external_exports.number().int().min(0).max(COMPUTER_SCREENSHOT_RETENTION_MAX_DAYS).optional()
|
|
69345
|
-
});
|
|
69346
|
-
var ComputerRevoke = external_exports.object({
|
|
69347
|
-
reason: external_exports.enum(["revoked", "deleted", "owner_removed"]),
|
|
69348
|
-
message: external_exports.string().max(500).optional()
|
|
69349
|
-
});
|
|
69350
|
-
var ComputerLeasePush = external_exports.object({ lease: ComputerControlLease.nullable() });
|
|
69351
|
-
var ComputerRelaysPush = external_exports.object({ relays: external_exports.array(ComputerRelayEntry).max(COMPUTER_RELAYS_MAX) });
|
|
69352
|
-
var ComputerStopPush = external_exports.object({ stop: external_exports.object({ at: external_exports.string().datetime() }).nullable() });
|
|
69353
|
-
var ComputerEgressPush = external_exports.object({ egress: ComputerEgress });
|
|
69354
|
-
var COMPUTER_ADMIN_PROMPTS_FEATURE = "computer-admin-prompts-v1";
|
|
69355
|
-
var ComputerAdminPromptsSet = external_exports.object({ mode: external_exports.enum(COMPUTER_ADMIN_PROMPT_MODES) }).strict();
|
|
69356
|
-
var ComputerAdminPromptsSetOk = external_exports.object({ mode: external_exports.enum(COMPUTER_ADMIN_PROMPT_MODES) });
|
|
69357
|
-
var COMPUTER_CP_SCHEMAS = {
|
|
69358
|
-
"computer/auth": ComputerAuth,
|
|
69359
|
-
"computer/auth/ok": ComputerAuthOk,
|
|
69360
|
-
"computer/heartbeat": ComputerHeartbeat,
|
|
69361
|
-
"computer/credential": ComputerCredentialRenewal,
|
|
69362
|
-
"computer/policy": ComputerPolicyPush,
|
|
69363
|
-
"computer/revoke": ComputerRevoke,
|
|
69364
|
-
"computer/lease": ComputerLeasePush,
|
|
69365
|
-
"computer/relays": ComputerRelaysPush,
|
|
69366
|
-
"computer/stop": ComputerStopPush,
|
|
69367
|
-
"computer/egress": ComputerEgressPush,
|
|
69368
|
-
"computer/admin-prompts": ComputerAdminPromptsSet,
|
|
69369
|
-
"computer/admin-prompts/ok": ComputerAdminPromptsSetOk,
|
|
69370
|
-
"computer/audit": ComputerAuditReport,
|
|
69371
|
-
"computer/audit/ok": ComputerAuditAck,
|
|
69372
|
-
"computer/screenshot/put": ComputerScreenshotPut,
|
|
69373
|
-
"computer/screenshot/put/ok": ComputerScreenshotPutOk,
|
|
69374
|
-
"computer/screenshot/commit": ComputerScreenshotCommit,
|
|
69375
|
-
"computer/screenshot/commit/ok": ComputerScreenshotCommitOk,
|
|
69376
|
-
error: ErrorFrame
|
|
69377
|
-
};
|
|
69378
|
-
var COMPUTER_CP_FRAME_TYPES = Object.keys(COMPUTER_CP_SCHEMAS);
|
|
69379
|
-
var ComputerCpFrame = external_exports.discriminatedUnion("type", [
|
|
69380
|
-
frameSchema("computer/auth", COMPUTER_CP_SCHEMAS["computer/auth"]),
|
|
69381
|
-
frameSchema("computer/auth/ok", COMPUTER_CP_SCHEMAS["computer/auth/ok"]),
|
|
69382
|
-
frameSchema("computer/heartbeat", COMPUTER_CP_SCHEMAS["computer/heartbeat"]),
|
|
69383
|
-
frameSchema("computer/credential", COMPUTER_CP_SCHEMAS["computer/credential"]),
|
|
69384
|
-
frameSchema("computer/policy", COMPUTER_CP_SCHEMAS["computer/policy"]),
|
|
69385
|
-
frameSchema("computer/revoke", COMPUTER_CP_SCHEMAS["computer/revoke"]),
|
|
69386
|
-
frameSchema("computer/lease", COMPUTER_CP_SCHEMAS["computer/lease"]),
|
|
69387
|
-
frameSchema("computer/relays", COMPUTER_CP_SCHEMAS["computer/relays"]),
|
|
69388
|
-
frameSchema("computer/stop", COMPUTER_CP_SCHEMAS["computer/stop"]),
|
|
69389
|
-
frameSchema("computer/egress", COMPUTER_CP_SCHEMAS["computer/egress"]),
|
|
69390
|
-
frameSchema("computer/admin-prompts", COMPUTER_CP_SCHEMAS["computer/admin-prompts"]),
|
|
69391
|
-
frameSchema("computer/admin-prompts/ok", COMPUTER_CP_SCHEMAS["computer/admin-prompts/ok"]),
|
|
69392
|
-
frameSchema("computer/audit", COMPUTER_CP_SCHEMAS["computer/audit"]),
|
|
69393
|
-
frameSchema("computer/audit/ok", COMPUTER_CP_SCHEMAS["computer/audit/ok"]),
|
|
69394
|
-
frameSchema("computer/screenshot/put", COMPUTER_CP_SCHEMAS["computer/screenshot/put"]),
|
|
69395
|
-
frameSchema("computer/screenshot/put/ok", COMPUTER_CP_SCHEMAS["computer/screenshot/put/ok"]),
|
|
69396
|
-
frameSchema("computer/screenshot/commit", COMPUTER_CP_SCHEMAS["computer/screenshot/commit"]),
|
|
69397
|
-
frameSchema("computer/screenshot/commit/ok", COMPUTER_CP_SCHEMAS["computer/screenshot/commit/ok"]),
|
|
69398
|
-
frameSchema("error", COMPUTER_CP_SCHEMAS["error"])
|
|
69399
|
-
]);
|
|
69400
|
-
var TOLERANT_COMPUTER_CP_SCHEMAS = tolerantSchemas(COMPUTER_CP_SCHEMAS);
|
|
69401
|
-
function decodeComputerCpFrameTolerant(text) {
|
|
69402
|
-
return decodeEnvelopeWith(TOLERANT_COMPUTER_CP_SCHEMAS, text);
|
|
69381
|
+
return found;
|
|
69403
69382
|
}
|
|
69404
|
-
function
|
|
69405
|
-
|
|
69383
|
+
async function internAtom(x, name) {
|
|
69384
|
+
const bytes = Buffer.from(name, "latin1");
|
|
69385
|
+
const body = Buffer.alloc(4 + bytes.length);
|
|
69386
|
+
body.writeUInt16LE(bytes.length, 0);
|
|
69387
|
+
bytes.copy(body, 4);
|
|
69388
|
+
return (await x.request(request(OP_INTERN_ATOM, 0, body))).readUInt32LE(8);
|
|
69389
|
+
}
|
|
69390
|
+
async function queryTree(x, window2) {
|
|
69391
|
+
const body = Buffer.alloc(4);
|
|
69392
|
+
body.writeUInt32LE(window2, 0);
|
|
69393
|
+
const reply2 = await x.request(request(OP_QUERY_TREE, 0, body)).catch(() => void 0);
|
|
69394
|
+
if (!reply2) return [];
|
|
69395
|
+
const count = reply2.readUInt16LE(16);
|
|
69396
|
+
return Array.from({ length: count }, (_, i) => reply2.readUInt32LE(32 + i * 4));
|
|
69397
|
+
}
|
|
69398
|
+
async function cardinal(x, window2, property, type = 0) {
|
|
69399
|
+
const body = Buffer.alloc(20);
|
|
69400
|
+
body.writeUInt32LE(window2, 0);
|
|
69401
|
+
body.writeUInt32LE(property, 4);
|
|
69402
|
+
body.writeUInt32LE(type, 8);
|
|
69403
|
+
body.writeUInt32LE(0, 12);
|
|
69404
|
+
body.writeUInt32LE(1, 16);
|
|
69405
|
+
const reply2 = await x.request(request(OP_GET_PROPERTY, 0, body)).catch(() => void 0);
|
|
69406
|
+
if (!reply2 || reply2[1] !== 32 || reply2.readUInt32LE(16) < 1) return void 0;
|
|
69407
|
+
return reply2.readUInt32LE(32);
|
|
69408
|
+
}
|
|
69409
|
+
async function sendClientMessage(x, window2, type, data) {
|
|
69410
|
+
const event = Buffer.alloc(32);
|
|
69411
|
+
event[0] = CLIENT_MESSAGE;
|
|
69412
|
+
event[1] = 32;
|
|
69413
|
+
event.writeUInt32LE(window2, 4);
|
|
69414
|
+
event.writeUInt32LE(type, 8);
|
|
69415
|
+
data.forEach((value, i) => event.writeUInt32LE(value >>> 0, 12 + i * 4));
|
|
69416
|
+
const body = Buffer.alloc(40);
|
|
69417
|
+
body.writeUInt32LE(window2, 0);
|
|
69418
|
+
body.writeUInt32LE(0, 4);
|
|
69419
|
+
event.copy(body, 8);
|
|
69420
|
+
await x.checked(request(OP_SEND_EVENT, 0, body));
|
|
69406
69421
|
}
|
|
69407
69422
|
|
|
69423
|
+
// src/linux/desktops.ts
|
|
69424
|
+
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
69425
|
+
import { spawn as spawn5, spawnSync } from "node:child_process";
|
|
69426
|
+
import { chmodSync, existsSync as existsSync4, mkdirSync as mkdirSync4, readFileSync as readFileSync4, writeFileSync as writeFileSync3 } from "node:fs";
|
|
69427
|
+
import { homedir as homedir2 } from "node:os";
|
|
69428
|
+
import { join as join6 } from "node:path";
|
|
69429
|
+
|
|
69430
|
+
// src/computer.ts
|
|
69431
|
+
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
69432
|
+
import { hostname as hostname5, release } from "node:os";
|
|
69433
|
+
|
|
69408
69434
|
// src/driver/client.ts
|
|
69409
69435
|
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
69410
69436
|
|
|
@@ -85390,10 +85416,11 @@ function desktopBrowserPlan(dataDir2, id) {
|
|
|
85390
85416
|
const state = loadDesktopState(dataDir2);
|
|
85391
85417
|
const ids = Object.values(state.desktops).map((record2) => record2.id);
|
|
85392
85418
|
if (!ids.includes(id)) throw new Error(`no desktop ${id}`);
|
|
85419
|
+
const share = state.shareBrowserLogins !== false;
|
|
85393
85420
|
return {
|
|
85394
85421
|
profile: desktopProfile(dataDir2, id),
|
|
85395
|
-
master: state.master,
|
|
85396
|
-
sources: [state.master, ...ids.filter((other) => other !== id).map((other) => desktopProfile(dataDir2, other))],
|
|
85422
|
+
...share ? { master: state.master } : {},
|
|
85423
|
+
sources: share ? [state.master, ...ids.filter((other) => other !== id).map((other) => desktopProfile(dataDir2, other))] : [],
|
|
85397
85424
|
skip: ids.map((other) => wrapperDir(dataDir2, other)),
|
|
85398
85425
|
...state.mainBus ? { mainBus: state.mainBus } : {}
|
|
85399
85426
|
};
|
|
@@ -85451,6 +85478,13 @@ var DesktopManager = class {
|
|
|
85451
85478
|
closed = false;
|
|
85452
85479
|
// The owner's pause, applied to every desktop, including ones started while it stands.
|
|
85453
85480
|
paused;
|
|
85481
|
+
/** The registrant's `shareBrowserLogins` (§3.9), kept with the state the browser wrappers read. */
|
|
85482
|
+
setShareBrowserLogins(on) {
|
|
85483
|
+
if (this.state.shareBrowserLogins !== false === on) return;
|
|
85484
|
+
this.state.shareBrowserLogins = on;
|
|
85485
|
+
saveDesktopState(this.deps.dataDir, this.state);
|
|
85486
|
+
this.deps.log(`per-agent desktops: browser logins ${on ? "shared between desktops" : "kept apart per desktop"}`);
|
|
85487
|
+
}
|
|
85454
85488
|
/** On when the owner's switch is on and the machine supports it. */
|
|
85455
85489
|
enabled() {
|
|
85456
85490
|
return this.deps.config.perAgentDesktops && this.deps.support().supported;
|
|
@@ -85577,6 +85611,7 @@ var DesktopManager = class {
|
|
|
85577
85611
|
XFCE_SHELL.forEach(run4);
|
|
85578
85612
|
const { driver, computer } = this.deps.build({
|
|
85579
85613
|
id: record2.id,
|
|
85614
|
+
key: record2.key,
|
|
85580
85615
|
label: record2.label,
|
|
85581
85616
|
env,
|
|
85582
85617
|
launchBrowser: (app) => isBrowserName(app) ? async () => {
|
|
@@ -85749,7 +85784,7 @@ async function desktopBrowser(id, args, log40, dataDir2) {
|
|
|
85749
85784
|
if (plan.mainBus) env.DBUS_SESSION_BUS_ADDRESS = plan.mainBus;
|
|
85750
85785
|
const result = await launchBrowser({
|
|
85751
85786
|
profile: plan.profile,
|
|
85752
|
-
master: plan.master,
|
|
85787
|
+
...plan.master ? { master: plan.master } : {},
|
|
85753
85788
|
sources: plan.sources,
|
|
85754
85789
|
browser,
|
|
85755
85790
|
// The desktop's tabs come back after its browser was closed for idleness (computer-use.md §3.10).
|
|
@@ -86264,7 +86299,8 @@ function auditEntry(record2, at, id = randomUUID2()) {
|
|
|
86264
86299
|
args: summary.args,
|
|
86265
86300
|
...summary.textLength !== void 0 ? { textLength: summary.textLength } : {},
|
|
86266
86301
|
ms: Math.max(0, Math.round(record2.ms)),
|
|
86267
|
-
...record2.screenshotRef ? { screenshotRef: record2.screenshotRef } : {}
|
|
86302
|
+
...record2.screenshotRef ? { screenshotRef: record2.screenshotRef } : {},
|
|
86303
|
+
...record2.desktop ? { desktop: record2.desktop } : {}
|
|
86268
86304
|
};
|
|
86269
86305
|
}
|
|
86270
86306
|
var AuditReporter = class {
|
|
@@ -90295,7 +90331,7 @@ var serviceEntry = () => managedEntry() ?? resolve3(process.argv[1]);
|
|
|
90295
90331
|
|
|
90296
90332
|
// src/version.ts
|
|
90297
90333
|
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
90298
|
-
var COMPUTER_DAEMON_VERSION = true ? "2.12.0-rc.
|
|
90334
|
+
var COMPUTER_DAEMON_VERSION = true ? "2.12.0-rc.15" : JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
90299
90335
|
|
|
90300
90336
|
// src/http-server.ts
|
|
90301
90337
|
var CONTROL_HEADER = "x-agentconnect-computer";
|
|
@@ -114380,6 +114416,112 @@ function createViewer(options) {
|
|
|
114380
114416
|
|
|
114381
114417
|
// src/viewer-router.ts
|
|
114382
114418
|
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
114419
|
+
|
|
114420
|
+
// src/mcp-access.ts
|
|
114421
|
+
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
114422
|
+
var bearer = (authorization) => /^Bearer\s+(\S+)$/i.exec(authorization ?? "")?.[1];
|
|
114423
|
+
function channelPrincipal(authorization, authority, computerId) {
|
|
114424
|
+
const token = bearer(authorization);
|
|
114425
|
+
const id = computerId();
|
|
114426
|
+
if (!token?.startsWith(`${COMPUTER_CHANNEL_TOKEN_PREFIX}.`) || !id) return void 0;
|
|
114427
|
+
const claims = authority.verify(token, "mcp", id);
|
|
114428
|
+
if (!claims?.ses || !claims.agt) return void 0;
|
|
114429
|
+
return {
|
|
114430
|
+
client: computerLeaseHolderName({ agentId: claims.agt, sessionId: claims.ses }),
|
|
114431
|
+
viewOnly: claims.mode === "view",
|
|
114432
|
+
agent: { agentId: claims.agt, sessionId: claims.ses },
|
|
114433
|
+
...claims.sh || claims.fs ? { commandLineGrant: { shell: claims.sh ?? "off", files: claims.fs ?? "off" } } : {}
|
|
114434
|
+
};
|
|
114435
|
+
}
|
|
114436
|
+
var RESPONSE_HEADERS = ["allow", "content-type", "mcp-protocol-version", "mcp-session-id", "www-authenticate"];
|
|
114437
|
+
function reply(status, body, headers = {}) {
|
|
114438
|
+
return {
|
|
114439
|
+
status,
|
|
114440
|
+
headers: { "content-type": "application/json", ...headers },
|
|
114441
|
+
body: Buffer.from(JSON.stringify(body)).toString("base64")
|
|
114442
|
+
};
|
|
114443
|
+
}
|
|
114444
|
+
function viewerPrincipal(authorization, authority, computerId) {
|
|
114445
|
+
const token = bearer(authorization);
|
|
114446
|
+
const id = computerId();
|
|
114447
|
+
if (!token?.startsWith(`${COMPUTER_CHANNEL_TOKEN_PREFIX}.`) || !id) return void 0;
|
|
114448
|
+
const claims = authority.verify(token, "view", id);
|
|
114449
|
+
if (!claims?.usr) return void 0;
|
|
114450
|
+
return {
|
|
114451
|
+
client: `console:${claims.usr}`,
|
|
114452
|
+
control: claims.mode === "control",
|
|
114453
|
+
iceServers: claims.ice ?? [],
|
|
114454
|
+
stunUrls: claims.stun ?? [],
|
|
114455
|
+
desktop: claims.dsk ?? "main",
|
|
114456
|
+
valid: () => authority.verify(token, "view", id) !== void 0
|
|
114457
|
+
};
|
|
114458
|
+
}
|
|
114459
|
+
var mayWatch = (principal, desktop) => desktop === null || principal.desktop === void 0 || principal.desktop === desktop;
|
|
114460
|
+
function viewerAuthenticator(member, localClient, desktop = "main") {
|
|
114461
|
+
return (authorization, via) => {
|
|
114462
|
+
const principal = member(authorization);
|
|
114463
|
+
if (principal) return mayWatch(principal, desktop) ? principal : void 0;
|
|
114464
|
+
if (via !== "local") return void 0;
|
|
114465
|
+
const client = localClient(authorization);
|
|
114466
|
+
return client ? { client, control: true } : void 0;
|
|
114467
|
+
};
|
|
114468
|
+
}
|
|
114469
|
+
function createRelayedMcpHandler(deps) {
|
|
114470
|
+
return async (request2) => {
|
|
114471
|
+
const pathname = new URL(request2.path, "http://desktop.invalid").pathname;
|
|
114472
|
+
if (deps.viewer && pathname.startsWith(COMPUTER_VIEWER_API_PREFIX)) {
|
|
114473
|
+
const out = await deps.viewer({
|
|
114474
|
+
method: request2.method,
|
|
114475
|
+
path: pathname,
|
|
114476
|
+
authorization: request2.headers.authorization,
|
|
114477
|
+
via: "relay",
|
|
114478
|
+
...request2.body ? { body: Buffer.from(request2.body, "base64") } : {}
|
|
114479
|
+
});
|
|
114480
|
+
if (out.body.length > RELAY_COMPUTER_MAX_BODY_BYTES) return reply(500, { error: "response too large" });
|
|
114481
|
+
return {
|
|
114482
|
+
status: out.status,
|
|
114483
|
+
headers: out.headers,
|
|
114484
|
+
...out.body.length > 0 ? { body: out.body.toString("base64") } : {}
|
|
114485
|
+
};
|
|
114486
|
+
}
|
|
114487
|
+
if (pathname !== "/mcp") return reply(404, { error: "not found" });
|
|
114488
|
+
const principal = deps.authenticate(request2.headers.authorization);
|
|
114489
|
+
if (!principal) return reply(401, { error: "unauthorized" }, { "www-authenticate": "Bearer" });
|
|
114490
|
+
if (request2.method !== "POST" && request2.method !== "DELETE") {
|
|
114491
|
+
return reply(405, { error: "method not allowed" }, { allow: "POST, DELETE" });
|
|
114492
|
+
}
|
|
114493
|
+
const mcp = deps.createMcpServer(principal);
|
|
114494
|
+
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
114495
|
+
sessionIdGenerator: void 0,
|
|
114496
|
+
enableJsonResponse: true
|
|
114497
|
+
});
|
|
114498
|
+
try {
|
|
114499
|
+
await mcp.connect(transport);
|
|
114500
|
+
const response = await transport.handleRequest(
|
|
114501
|
+
new Request("http://desktop.invalid/mcp", {
|
|
114502
|
+
method: request2.method,
|
|
114503
|
+
headers: request2.headers,
|
|
114504
|
+
...request2.body ? { body: Buffer.from(request2.body, "base64") } : {}
|
|
114505
|
+
})
|
|
114506
|
+
);
|
|
114507
|
+
const body = Buffer.from(await response.arrayBuffer());
|
|
114508
|
+
if (body.length > RELAY_COMPUTER_MAX_BODY_BYTES) return reply(500, { error: "response too large" });
|
|
114509
|
+
const headers = {};
|
|
114510
|
+
for (const name of RESPONSE_HEADERS) {
|
|
114511
|
+
const value = response.headers.get(name);
|
|
114512
|
+
if (value !== null) headers[name] = value;
|
|
114513
|
+
}
|
|
114514
|
+
return { status: response.status, headers, ...body.length > 0 ? { body: body.toString("base64") } : {} };
|
|
114515
|
+
} catch (error63) {
|
|
114516
|
+
deps.log(`relayed request failed: ${error63.message}`);
|
|
114517
|
+
return reply(500, { error: "failed" });
|
|
114518
|
+
} finally {
|
|
114519
|
+
void mcp.close().catch(() => void 0);
|
|
114520
|
+
}
|
|
114521
|
+
};
|
|
114522
|
+
}
|
|
114523
|
+
|
|
114524
|
+
// src/viewer-router.ts
|
|
114383
114525
|
var DESKTOP_PATH = /^\/view\/api\/d\/([A-Za-z0-9_-]{1,32})(\/.*)$/;
|
|
114384
114526
|
var MAX_BODY_BYTES2 = 64 * 1024;
|
|
114385
114527
|
var json4 = (status, body) => ({
|
|
@@ -114425,10 +114567,11 @@ function createViewerRouter(options) {
|
|
|
114425
114567
|
if (!match || match[1] === "main") {
|
|
114426
114568
|
return options.main.api(match ? { ...request2, path: `/view/api${match[2]}` } : request2);
|
|
114427
114569
|
}
|
|
114428
|
-
|
|
114570
|
+
const id = match[1];
|
|
114571
|
+
const principal = options.authenticate(request2.authorization, request2.via);
|
|
114572
|
+
if (!principal || !mayWatch(principal, id)) return json4(401, { error: "unauthorized" });
|
|
114429
114573
|
const manager = options.desktops();
|
|
114430
114574
|
if (!manager?.enabled()) return json4(404, { error: "not_found", message: "per-agent desktops are off" });
|
|
114431
|
-
const id = match[1];
|
|
114432
114575
|
let desktop;
|
|
114433
114576
|
try {
|
|
114434
114577
|
desktop = await manager.byId(id);
|
|
@@ -115047,6 +115190,7 @@ var ComputerCpClient = class {
|
|
|
115047
115190
|
const payload = {
|
|
115048
115191
|
status: report.status,
|
|
115049
115192
|
...report.lease ? { lease: report.lease } : {},
|
|
115193
|
+
...report.desktops && this.features.has(COMPUTER_DESKTOPS_FEATURE) ? { desktops: report.desktops } : {},
|
|
115050
115194
|
...fresh ? report.facts : {}
|
|
115051
115195
|
};
|
|
115052
115196
|
try {
|
|
@@ -115060,9 +115204,10 @@ var ComputerCpClient = class {
|
|
|
115060
115204
|
async reportAudit(entries2) {
|
|
115061
115205
|
const transport = this.transport;
|
|
115062
115206
|
if (this.state !== "READY" || !transport || !this.features.has(COMPUTER_AUDIT_FEATURE)) return "retry";
|
|
115207
|
+
const sent = this.features.has(COMPUTER_DESKTOPS_FEATURE) ? entries2 : entries2.map(({ desktop: _desktop, ...entry }) => entry);
|
|
115063
115208
|
try {
|
|
115064
115209
|
const reply2 = await this.correlator.request(
|
|
115065
|
-
buildComputerCpFrame("computer/audit", { entries:
|
|
115210
|
+
buildComputerCpFrame("computer/audit", { entries: sent }),
|
|
115066
115211
|
(encoded2) => transport.send(encoded2)
|
|
115067
115212
|
);
|
|
115068
115213
|
return reply2.type === "computer/audit/ok" ? "stored" : "retry";
|
|
@@ -115071,6 +115216,10 @@ var ComputerCpClient = class {
|
|
|
115071
115216
|
return error63 instanceof WireError && !error63.retryable ? "rejected" : "retry";
|
|
115072
115217
|
}
|
|
115073
115218
|
}
|
|
115219
|
+
/** Whether the CP keys leases, status and audit per agent desktop (computer-use.md §3.9). */
|
|
115220
|
+
desktopsSupported() {
|
|
115221
|
+
return this.state === "READY" && this.features.has(COMPUTER_DESKTOPS_FEATURE);
|
|
115222
|
+
}
|
|
115074
115223
|
/** Whether the CP stores the administrator-prompt mode the menu sets (computer-use.md §4.2.1). */
|
|
115075
115224
|
servesAdminPrompts() {
|
|
115076
115225
|
return this.state === "READY" && this.features.has(COMPUTER_ADMIN_PROMPTS_FEATURE);
|
|
@@ -115197,7 +115346,7 @@ var ComputerCpClient = class {
|
|
|
115197
115346
|
this.deps.onPolicy?.(frame.payload.policy);
|
|
115198
115347
|
return;
|
|
115199
115348
|
case "computer/lease":
|
|
115200
|
-
this.deps.onLease?.(frame.payload.lease);
|
|
115349
|
+
this.deps.onLease?.(frame.payload.lease, frame.payload.desktops);
|
|
115201
115350
|
return;
|
|
115202
115351
|
case "computer/relays":
|
|
115203
115352
|
this.deps.onRelays?.(frame.payload.relays);
|
|
@@ -116743,108 +116892,6 @@ var RelayLinks = class {
|
|
|
116743
116892
|
}
|
|
116744
116893
|
};
|
|
116745
116894
|
|
|
116746
|
-
// src/mcp-access.ts
|
|
116747
|
-
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
116748
|
-
var bearer = (authorization) => /^Bearer\s+(\S+)$/i.exec(authorization ?? "")?.[1];
|
|
116749
|
-
function channelPrincipal(authorization, authority, computerId) {
|
|
116750
|
-
const token = bearer(authorization);
|
|
116751
|
-
const id = computerId();
|
|
116752
|
-
if (!token?.startsWith(`${COMPUTER_CHANNEL_TOKEN_PREFIX}.`) || !id) return void 0;
|
|
116753
|
-
const claims = authority.verify(token, "mcp", id);
|
|
116754
|
-
if (!claims?.ses || !claims.agt) return void 0;
|
|
116755
|
-
return {
|
|
116756
|
-
client: computerLeaseHolderName({ agentId: claims.agt, sessionId: claims.ses }),
|
|
116757
|
-
viewOnly: claims.mode === "view",
|
|
116758
|
-
agent: { agentId: claims.agt, sessionId: claims.ses },
|
|
116759
|
-
...claims.sh || claims.fs ? { commandLineGrant: { shell: claims.sh ?? "off", files: claims.fs ?? "off" } } : {}
|
|
116760
|
-
};
|
|
116761
|
-
}
|
|
116762
|
-
var RESPONSE_HEADERS = ["allow", "content-type", "mcp-protocol-version", "mcp-session-id", "www-authenticate"];
|
|
116763
|
-
function reply(status, body, headers = {}) {
|
|
116764
|
-
return {
|
|
116765
|
-
status,
|
|
116766
|
-
headers: { "content-type": "application/json", ...headers },
|
|
116767
|
-
body: Buffer.from(JSON.stringify(body)).toString("base64")
|
|
116768
|
-
};
|
|
116769
|
-
}
|
|
116770
|
-
function viewerPrincipal(authorization, authority, computerId) {
|
|
116771
|
-
const token = bearer(authorization);
|
|
116772
|
-
const id = computerId();
|
|
116773
|
-
if (!token?.startsWith(`${COMPUTER_CHANNEL_TOKEN_PREFIX}.`) || !id) return void 0;
|
|
116774
|
-
const claims = authority.verify(token, "view", id);
|
|
116775
|
-
if (!claims?.usr) return void 0;
|
|
116776
|
-
return {
|
|
116777
|
-
client: `console:${claims.usr}`,
|
|
116778
|
-
control: claims.mode === "control",
|
|
116779
|
-
iceServers: claims.ice ?? [],
|
|
116780
|
-
stunUrls: claims.stun ?? [],
|
|
116781
|
-
valid: () => authority.verify(token, "view", id) !== void 0
|
|
116782
|
-
};
|
|
116783
|
-
}
|
|
116784
|
-
function viewerAuthenticator(member, localClient) {
|
|
116785
|
-
return (authorization, via) => {
|
|
116786
|
-
const principal = member(authorization);
|
|
116787
|
-
if (principal) return principal;
|
|
116788
|
-
if (via !== "local") return void 0;
|
|
116789
|
-
const client = localClient(authorization);
|
|
116790
|
-
return client ? { client, control: true } : void 0;
|
|
116791
|
-
};
|
|
116792
|
-
}
|
|
116793
|
-
function createRelayedMcpHandler(deps) {
|
|
116794
|
-
return async (request2) => {
|
|
116795
|
-
const pathname = new URL(request2.path, "http://desktop.invalid").pathname;
|
|
116796
|
-
if (deps.viewer && pathname.startsWith(COMPUTER_VIEWER_API_PREFIX)) {
|
|
116797
|
-
const out = await deps.viewer({
|
|
116798
|
-
method: request2.method,
|
|
116799
|
-
path: pathname,
|
|
116800
|
-
authorization: request2.headers.authorization,
|
|
116801
|
-
via: "relay",
|
|
116802
|
-
...request2.body ? { body: Buffer.from(request2.body, "base64") } : {}
|
|
116803
|
-
});
|
|
116804
|
-
if (out.body.length > RELAY_COMPUTER_MAX_BODY_BYTES) return reply(500, { error: "response too large" });
|
|
116805
|
-
return {
|
|
116806
|
-
status: out.status,
|
|
116807
|
-
headers: out.headers,
|
|
116808
|
-
...out.body.length > 0 ? { body: out.body.toString("base64") } : {}
|
|
116809
|
-
};
|
|
116810
|
-
}
|
|
116811
|
-
if (pathname !== "/mcp") return reply(404, { error: "not found" });
|
|
116812
|
-
const principal = deps.authenticate(request2.headers.authorization);
|
|
116813
|
-
if (!principal) return reply(401, { error: "unauthorized" }, { "www-authenticate": "Bearer" });
|
|
116814
|
-
if (request2.method !== "POST" && request2.method !== "DELETE") {
|
|
116815
|
-
return reply(405, { error: "method not allowed" }, { allow: "POST, DELETE" });
|
|
116816
|
-
}
|
|
116817
|
-
const mcp = deps.createMcpServer(principal);
|
|
116818
|
-
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
116819
|
-
sessionIdGenerator: void 0,
|
|
116820
|
-
enableJsonResponse: true
|
|
116821
|
-
});
|
|
116822
|
-
try {
|
|
116823
|
-
await mcp.connect(transport);
|
|
116824
|
-
const response = await transport.handleRequest(
|
|
116825
|
-
new Request("http://desktop.invalid/mcp", {
|
|
116826
|
-
method: request2.method,
|
|
116827
|
-
headers: request2.headers,
|
|
116828
|
-
...request2.body ? { body: Buffer.from(request2.body, "base64") } : {}
|
|
116829
|
-
})
|
|
116830
|
-
);
|
|
116831
|
-
const body = Buffer.from(await response.arrayBuffer());
|
|
116832
|
-
if (body.length > RELAY_COMPUTER_MAX_BODY_BYTES) return reply(500, { error: "response too large" });
|
|
116833
|
-
const headers = {};
|
|
116834
|
-
for (const name of RESPONSE_HEADERS) {
|
|
116835
|
-
const value = response.headers.get(name);
|
|
116836
|
-
if (value !== null) headers[name] = value;
|
|
116837
|
-
}
|
|
116838
|
-
return { status: response.status, headers, ...body.length > 0 ? { body: body.toString("base64") } : {} };
|
|
116839
|
-
} catch (error63) {
|
|
116840
|
-
deps.log(`relayed request failed: ${error63.message}`);
|
|
116841
|
-
return reply(500, { error: "failed" });
|
|
116842
|
-
} finally {
|
|
116843
|
-
void mcp.close().catch(() => void 0);
|
|
116844
|
-
}
|
|
116845
|
-
};
|
|
116846
|
-
}
|
|
116847
|
-
|
|
116848
116895
|
// src/cp/report.ts
|
|
116849
116896
|
init_define_AGENTCONNECT_COMPUTER_WINDOWS_SOURCES();
|
|
116850
116897
|
import { spawnSync as spawnSync11 } from "node:child_process";
|
|
@@ -117851,6 +117898,19 @@ async function registerComputer(dir, token, cpUrl, name) {
|
|
|
117851
117898
|
return registration;
|
|
117852
117899
|
}
|
|
117853
117900
|
var DOCTOR_INTERVAL_MS = 30 * 6e4;
|
|
117901
|
+
function desktopReports(manager) {
|
|
117902
|
+
if (!manager?.enabled()) return void 0;
|
|
117903
|
+
return manager.runningDesktops().filter((desktop) => UUID.test(desktop.record.key)).slice(0, COMPUTER_DESKTOPS_MAX).map((desktop) => {
|
|
117904
|
+
const lease = desktop.computer.leaseActivity();
|
|
117905
|
+
return {
|
|
117906
|
+
id: desktop.record.id,
|
|
117907
|
+
agentId: desktop.record.key,
|
|
117908
|
+
status: desktop.computer.liveStatus(),
|
|
117909
|
+
...lease ? { lease } : {}
|
|
117910
|
+
};
|
|
117911
|
+
});
|
|
117912
|
+
}
|
|
117913
|
+
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
117854
117914
|
function startCpChannel(options) {
|
|
117855
117915
|
const { dir, config: config2, registration, authority, computer, driver, screenSize } = options;
|
|
117856
117916
|
const num = (value) => typeof value === "number" && Number.isFinite(value) ? value : 0;
|
|
@@ -117887,9 +117947,11 @@ function startCpChannel(options) {
|
|
|
117887
117947
|
const display = computer.info().display;
|
|
117888
117948
|
const lease = computer.leaseActivity();
|
|
117889
117949
|
const local = options.local();
|
|
117950
|
+
const desktops = desktopReports(options.desktops?.());
|
|
117890
117951
|
return {
|
|
117891
117952
|
status: computer.liveStatus(),
|
|
117892
117953
|
...lease ? { lease } : {},
|
|
117954
|
+
...desktops ? { desktops } : {},
|
|
117893
117955
|
facts: {
|
|
117894
117956
|
...profile,
|
|
117895
117957
|
driverVersion: driver.version ?? CUA_DRIVER_VERSION,
|
|
@@ -117912,7 +117974,10 @@ function startCpChannel(options) {
|
|
|
117912
117974
|
config2.leaseMaxSeconds = policy.leaseMaxSeconds;
|
|
117913
117975
|
options.onPolicy?.(policy);
|
|
117914
117976
|
},
|
|
117915
|
-
onLease: (lease) =>
|
|
117977
|
+
onLease: (lease, desktops) => {
|
|
117978
|
+
computer.applyControlLease(lease);
|
|
117979
|
+
options.onDesktopLeases?.(desktops ?? []);
|
|
117980
|
+
},
|
|
117916
117981
|
onReady: (ok) => computer.rename(ok.name),
|
|
117917
117982
|
onRelays: (relays) => relayLinks.converge(relays),
|
|
117918
117983
|
onStop: (stop) => applyConsoleStop(stop),
|
|
@@ -117949,7 +118014,7 @@ function startCpChannel(options) {
|
|
|
117949
118014
|
}
|
|
117950
118015
|
};
|
|
117951
118016
|
}
|
|
117952
|
-
function buildViewer(dir, config2, computer, refusal, consoleViewer, advertiseAddress, onFfmpegInstalled, display) {
|
|
118017
|
+
function buildViewer(dir, config2, computer, refusal, consoleViewer, advertiseAddress, onFfmpegInstalled, display, desktopId = "main") {
|
|
117953
118018
|
const ffmpeg = () => resolveFfmpegPath(dir, config2.ffmpegPath);
|
|
117954
118019
|
let ffmpegState = "missing";
|
|
117955
118020
|
if (config2.webrtc) {
|
|
@@ -117981,7 +118046,10 @@ function buildViewer(dir, config2, computer, refusal, consoleViewer, advertiseAd
|
|
|
117981
118046
|
stream,
|
|
117982
118047
|
log: log39,
|
|
117983
118048
|
onMessage: (principal, message) => viewer.channelMessage(principal, message),
|
|
117984
|
-
reauthorize: (token) =>
|
|
118049
|
+
reauthorize: (token) => {
|
|
118050
|
+
const principal = consoleViewer?.(`Bearer ${token}`);
|
|
118051
|
+
return principal && mayWatch(principal, desktopId) ? principal : void 0;
|
|
118052
|
+
},
|
|
117985
118053
|
...advertiseAddress ? { advertiseAddress } : {},
|
|
117986
118054
|
...config2.rtcPortRange ? { portRange: config2.rtcPortRange } : {}
|
|
117987
118055
|
}) : void 0;
|
|
@@ -117989,7 +118057,8 @@ function buildViewer(dir, config2, computer, refusal, consoleViewer, advertiseAd
|
|
|
117989
118057
|
computer,
|
|
117990
118058
|
authenticate: viewerAuthenticator(
|
|
117991
118059
|
(header) => consoleViewer?.(header),
|
|
117992
|
-
(header) => authenticate(config2, header)
|
|
118060
|
+
(header) => authenticate(config2, header),
|
|
118061
|
+
desktopId
|
|
117993
118062
|
),
|
|
117994
118063
|
log: log39,
|
|
117995
118064
|
...rtc ? { rtc } : {},
|
|
@@ -118137,7 +118206,11 @@ async function run3(dir, initial, clientName) {
|
|
|
118137
118206
|
config: config2,
|
|
118138
118207
|
support: () => desktopSupport.current,
|
|
118139
118208
|
self: [process.execPath, resolve4(process.argv[1])],
|
|
118140
|
-
build: ({ id, label, env, launchBrowser: launchBrowser2 }) => {
|
|
118209
|
+
build: ({ id, key, label, env, launchBrowser: launchBrowser2 }) => {
|
|
118210
|
+
const desktopAudit = auditSinks(
|
|
118211
|
+
fileAuditSink(join21(dir, "audit.log")),
|
|
118212
|
+
...auditReport ? [auditReport.sink] : []
|
|
118213
|
+
);
|
|
118141
118214
|
const prefixed = (line) => log39(`desktop ${id}: ${line}`);
|
|
118142
118215
|
const desktopDriver = new CuaDriver({
|
|
118143
118216
|
command: resolveDriverPath(dir, config2.driverPath),
|
|
@@ -118148,7 +118221,8 @@ async function run3(dir, initial, clientName) {
|
|
|
118148
118221
|
const desktop = new Computer({
|
|
118149
118222
|
driver: desktopDriver,
|
|
118150
118223
|
config: config2,
|
|
118151
|
-
|
|
118224
|
+
// Each entry names the desktop that served it (§3.9).
|
|
118225
|
+
audit: (record2) => desktopAudit({ ...record2, desktop: id }),
|
|
118152
118226
|
log: prefixed,
|
|
118153
118227
|
onStatus: () => live2.local?.update(),
|
|
118154
118228
|
refusal: () => authority.refusal(),
|
|
@@ -118161,6 +118235,7 @@ async function run3(dir, initial, clientName) {
|
|
|
118161
118235
|
isolation: isolationKind()
|
|
118162
118236
|
}
|
|
118163
118237
|
});
|
|
118238
|
+
desktop.applyControlLease(live2.desktopLeases?.get(key) ?? null);
|
|
118164
118239
|
return { driver: desktopDriver, computer: desktop };
|
|
118165
118240
|
},
|
|
118166
118241
|
log: log39,
|
|
@@ -118220,11 +118295,13 @@ async function run3(dir, initial, clientName) {
|
|
|
118220
118295
|
consoleViewer,
|
|
118221
118296
|
advertiseAddress,
|
|
118222
118297
|
void 0,
|
|
118223
|
-
desktop.display
|
|
118298
|
+
desktop.display,
|
|
118299
|
+
desktop.record.id
|
|
118224
118300
|
),
|
|
118225
118301
|
authenticate: viewerAuthenticator(
|
|
118226
118302
|
(header) => consoleViewer?.(header),
|
|
118227
|
-
(header) => authenticate(config2, header)
|
|
118303
|
+
(header) => authenticate(config2, header),
|
|
118304
|
+
null
|
|
118228
118305
|
),
|
|
118229
118306
|
mainInfo: () => ({
|
|
118230
118307
|
name: String(computer.info().name),
|
|
@@ -118405,6 +118482,13 @@ async function run3(dir, initial, clientName) {
|
|
|
118405
118482
|
onPolicy: (policy) => {
|
|
118406
118483
|
live2.policy = policy;
|
|
118407
118484
|
keepAdminPrompts(policy.approvals.adminPrompts);
|
|
118485
|
+
live2.desktops?.setShareBrowserLogins(policy.shareBrowserLogins !== false);
|
|
118486
|
+
},
|
|
118487
|
+
desktops: () => live2.desktops,
|
|
118488
|
+
onDesktopLeases: (leases) => {
|
|
118489
|
+
live2.desktopLeases = new Map(leases.flatMap((lease) => lease.desktop ? [[lease.desktop, lease]] : []));
|
|
118490
|
+
for (const desktop of live2.desktops?.runningDesktops() ?? [])
|
|
118491
|
+
desktop.computer.applyControlLease(live2.desktopLeases.get(desktop.record.key) ?? null);
|
|
118408
118492
|
}
|
|
118409
118493
|
});
|
|
118410
118494
|
const publicBase = publicBaseUrl(config2);
|