local-commander-agent 0.3.46 → 0.3.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/bin/localcommander.mjs +17 -0
- package/bin/posix.mjs +18 -0
- package/package.json +4 -4
- package/runtime/JobHost.exe +0 -0
- package/runtime/LocalCommanderAgent.exe +0 -0
- package/runtime/OwnerBridge.exe +0 -0
- package/runtime/agent.mjs +1321 -121
package/runtime/agent.mjs
CHANGED
|
@@ -2125,7 +2125,7 @@ var require_extension = __commonJS({
|
|
|
2125
2125
|
if (dest[name2] === void 0) dest[name2] = [elem];
|
|
2126
2126
|
else dest[name2].push(elem);
|
|
2127
2127
|
}
|
|
2128
|
-
function
|
|
2128
|
+
function parse4(header) {
|
|
2129
2129
|
const offers = /* @__PURE__ */ Object.create(null);
|
|
2130
2130
|
let params = /* @__PURE__ */ Object.create(null);
|
|
2131
2131
|
let mustUnescape = false;
|
|
@@ -2265,7 +2265,7 @@ var require_extension = __commonJS({
|
|
|
2265
2265
|
}).join(", ");
|
|
2266
2266
|
}).join(", ");
|
|
2267
2267
|
}
|
|
2268
|
-
module.exports = { format, parse:
|
|
2268
|
+
module.exports = { format, parse: parse4 };
|
|
2269
2269
|
}
|
|
2270
2270
|
});
|
|
2271
2271
|
|
|
@@ -2276,9 +2276,9 @@ var require_websocket = __commonJS({
|
|
|
2276
2276
|
var EventEmitter = __require("events");
|
|
2277
2277
|
var https2 = __require("https");
|
|
2278
2278
|
var http2 = __require("http");
|
|
2279
|
-
var
|
|
2279
|
+
var net3 = __require("net");
|
|
2280
2280
|
var tls2 = __require("tls");
|
|
2281
|
-
var { randomBytes:
|
|
2281
|
+
var { randomBytes: randomBytes11, createHash: createHash21 } = __require("crypto");
|
|
2282
2282
|
var { Duplex, Readable } = __require("stream");
|
|
2283
2283
|
var { URL: URL2 } = __require("url");
|
|
2284
2284
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
@@ -2299,7 +2299,7 @@ var require_websocket = __commonJS({
|
|
|
2299
2299
|
var {
|
|
2300
2300
|
EventTarget: { addEventListener, removeEventListener }
|
|
2301
2301
|
} = require_event_target();
|
|
2302
|
-
var { format, parse:
|
|
2302
|
+
var { format, parse: parse4 } = require_extension();
|
|
2303
2303
|
var { toBuffer } = require_buffer_util();
|
|
2304
2304
|
var kAborted = /* @__PURE__ */ Symbol("kAborted");
|
|
2305
2305
|
var protocolVersions = [8, 13];
|
|
@@ -2829,7 +2829,7 @@ var require_websocket = __commonJS({
|
|
|
2829
2829
|
}
|
|
2830
2830
|
}
|
|
2831
2831
|
const defaultPort = isSecure ? 443 : 80;
|
|
2832
|
-
const key =
|
|
2832
|
+
const key = randomBytes11(16).toString("base64");
|
|
2833
2833
|
const request = isSecure ? https2.request : http2.request;
|
|
2834
2834
|
const protocolSet = /* @__PURE__ */ new Set();
|
|
2835
2835
|
let perMessageDeflate;
|
|
@@ -2989,7 +2989,7 @@ var require_websocket = __commonJS({
|
|
|
2989
2989
|
}
|
|
2990
2990
|
let extensions;
|
|
2991
2991
|
try {
|
|
2992
|
-
extensions =
|
|
2992
|
+
extensions = parse4(secWebSocketExtensions);
|
|
2993
2993
|
} catch (err) {
|
|
2994
2994
|
const message2 = "Invalid Sec-WebSocket-Extensions header";
|
|
2995
2995
|
abortHandshake(websocket, socket, message2);
|
|
@@ -3033,12 +3033,12 @@ var require_websocket = __commonJS({
|
|
|
3033
3033
|
}
|
|
3034
3034
|
function netConnect2(options) {
|
|
3035
3035
|
options.path = options.socketPath;
|
|
3036
|
-
return
|
|
3036
|
+
return net3.connect(options);
|
|
3037
3037
|
}
|
|
3038
3038
|
function tlsConnect(options) {
|
|
3039
3039
|
options.path = void 0;
|
|
3040
3040
|
if (!options.servername && options.servername !== "") {
|
|
3041
|
-
options.servername =
|
|
3041
|
+
options.servername = net3.isIP(options.host) ? "" : options.host;
|
|
3042
3042
|
}
|
|
3043
3043
|
return tls2.connect(options);
|
|
3044
3044
|
}
|
|
@@ -3281,7 +3281,7 @@ var require_subprotocol = __commonJS({
|
|
|
3281
3281
|
"../../node_modules/ws/lib/subprotocol.js"(exports, module) {
|
|
3282
3282
|
"use strict";
|
|
3283
3283
|
var { tokenChars } = require_validation();
|
|
3284
|
-
function
|
|
3284
|
+
function parse4(header) {
|
|
3285
3285
|
const protocols = /* @__PURE__ */ new Set();
|
|
3286
3286
|
let start = -1;
|
|
3287
3287
|
let end = -1;
|
|
@@ -3317,7 +3317,7 @@ var require_subprotocol = __commonJS({
|
|
|
3317
3317
|
protocols.add(protocol2);
|
|
3318
3318
|
return protocols;
|
|
3319
3319
|
}
|
|
3320
|
-
module.exports = { parse:
|
|
3320
|
+
module.exports = { parse: parse4 };
|
|
3321
3321
|
}
|
|
3322
3322
|
});
|
|
3323
3323
|
|
|
@@ -5570,18 +5570,18 @@ var validateAsync = async (schema, value, _ctx) => {
|
|
|
5570
5570
|
return result2.issues.length === 0;
|
|
5571
5571
|
};
|
|
5572
5572
|
var _encode = (_Err) => {
|
|
5573
|
-
const
|
|
5573
|
+
const parse4 = _parse(_Err);
|
|
5574
5574
|
const fn = (schema, value, _ctx, _params) => {
|
|
5575
5575
|
const ctx = _ctx ? { ..._ctx, direction: "backward" } : { direction: "backward" };
|
|
5576
|
-
return
|
|
5576
|
+
return parse4(schema, value, ctx, finalizeParams(fn, _params));
|
|
5577
5577
|
};
|
|
5578
5578
|
return fn;
|
|
5579
5579
|
};
|
|
5580
5580
|
var encode = /* @__PURE__ */ _encode($ZodRealError);
|
|
5581
5581
|
var _decode = (_Err) => {
|
|
5582
|
-
const
|
|
5582
|
+
const parse4 = _parse(_Err);
|
|
5583
5583
|
const fn = (schema, value, _ctx, _params) => {
|
|
5584
|
-
return
|
|
5584
|
+
return parse4(schema, value, _ctx, finalizeParams(fn, _params));
|
|
5585
5585
|
};
|
|
5586
5586
|
return fn;
|
|
5587
5587
|
};
|
|
@@ -26466,10 +26466,12 @@ var ServerFrameSchema = external_exports.discriminatedUnion("type", [
|
|
|
26466
26466
|
external_exports.object({ type: external_exports.literal("workspace_ack"), version: external_exports.literal(1), requestId: uuid11, workspaceGrantId: uuid11, accepted: external_exports.boolean(), code: external_exports.string().max(64).optional() }).strict(),
|
|
26467
26467
|
external_exports.object({ type: external_exports.literal("revoke"), version: external_exports.literal(1), reason: external_exports.enum(["device_revoked", "account_revoked", "server_shutdown", "connection_replaced"]) }).strict()
|
|
26468
26468
|
]);
|
|
26469
|
+
var WORKSPACE_ACCESS_MODE_CAPABILITY = "workspaceAccessModeV1";
|
|
26470
|
+
var WorkspaceAccessModeSchema = external_exports.enum(["full", "scoped"]);
|
|
26469
26471
|
var ClientFrameSchema = external_exports.discriminatedUnion("type", [
|
|
26470
26472
|
external_exports.object({ type: external_exports.literal("ready"), version: external_exports.literal(1), safeSlots: external_exports.number().int().min(1).max(128), platform: external_exports.literal("win32"), agentVersion: external_exports.string().regex(/^[A-Za-z0-9._+-]{1,64}$/), supervisor: external_exports.boolean() }).strict(),
|
|
26471
26473
|
external_exports.object({ type: external_exports.literal("heartbeat"), version: external_exports.literal(1), connectionEpoch: epoch2 }).strict(),
|
|
26472
|
-
external_exports.object({ type: external_exports.literal("workspace_grant"), version: external_exports.literal(1), requestId: uuid11, workspaceGrantId: uuid11, rootHash: hash3, displayName: external_exports.string().min(1).max(120), policyVersion: external_exports.number().int().min(1).max(2147483647) }).strict(),
|
|
26474
|
+
external_exports.object({ type: external_exports.literal("workspace_grant"), version: external_exports.literal(1), requestId: uuid11, workspaceGrantId: uuid11, rootHash: hash3, displayName: external_exports.string().min(1).max(120), policyVersion: external_exports.number().int().min(1).max(2147483647), accessMode: WorkspaceAccessModeSchema.optional() }).strict(),
|
|
26473
26475
|
external_exports.object({ type: external_exports.literal("workspace_revoke"), version: external_exports.literal(1), requestId: uuid11, workspaceGrantId: uuid11 }).strict(),
|
|
26474
26476
|
external_exports.object({ type: external_exports.literal("prepared"), version: external_exports.literal(1), binding: ExecutionBindingSchema }).strict(),
|
|
26475
26477
|
external_exports.object({ type: external_exports.literal("accepted"), version: external_exports.literal(1), binding: ExecutionBindingSchema }).strict(),
|
|
@@ -27030,9 +27032,9 @@ var NativeJournal = class _NativeJournal {
|
|
|
27030
27032
|
if (!validPid(pid)) throw failure2("JOURNAL_INPUT_INVALID");
|
|
27031
27033
|
if (e.state !== "running" || !e.supervisors) throw failure2("JOURNAL_STATE_INVALID");
|
|
27032
27034
|
if (containment !== void 0) {
|
|
27033
|
-
const
|
|
27034
|
-
if (!
|
|
27035
|
-
if (
|
|
27035
|
+
const linux2 = validLinuxContainment(containment), darwin = !linux2 && validDarwinContainment(containment);
|
|
27036
|
+
if (!linux2 && !darwin || !e.supervisors.includes(pid) || e.linuxSupervisors?.some((s) => s.pid === pid) || e.darwinSupervisors?.some((s) => s.pid === pid)) throw failure2("JOURNAL_INPUT_INVALID");
|
|
27037
|
+
if (linux2) (e.linuxSupervisors ??= []).push({ pid, containment: clone2(containment) });
|
|
27036
27038
|
else (e.darwinSupervisors ??= []).push({ pid, containment: clone2(containment) });
|
|
27037
27039
|
} else {
|
|
27038
27040
|
if (e.supervisors.length >= MAX_SUPERVISORS) throw failure2("JOURNAL_SUPERVISOR_LIMIT");
|
|
@@ -27930,11 +27932,16 @@ var WindowsPrivateStore = class _WindowsPrivateStore {
|
|
|
27930
27932
|
if (process.platform !== "win32") for (const name2 of ["owner-key.json", "owner-key.dat", "owner-key.lock"]) approved.add(name2);
|
|
27931
27933
|
if (names.length && !names.includes(MARKER)) throw fail2("STORE_DIRECTORY_UNKNOWN");
|
|
27932
27934
|
const memoryFile = (name2) => name2 === "host-memory.json" || /^host-memory\.json\.[1-9][0-9]{0,9}\.tmp$/.test(name2);
|
|
27933
|
-
|
|
27935
|
+
const switchFile = (name2) => name2 === "screenshot-acceptance-enabled" || name2 === "screenshot-disabled-by-owner";
|
|
27936
|
+
if (names.some((name2) => !approved.has(name2) && !memoryFile(name2) && !switchFile(name2))) throw fail2("STORE_DIRECTORY_UNKNOWN");
|
|
27934
27937
|
for (const name2 of names.filter(memoryFile)) {
|
|
27935
27938
|
const stat2 = await lstat4(path10.join(absolute2, name2));
|
|
27936
27939
|
if (!stat2.isFile() || stat2.isSymbolicLink() || stat2.size > 32768) throw fail2("STORE_DIRECTORY_INVALID");
|
|
27937
27940
|
}
|
|
27941
|
+
for (const name2 of names.filter(switchFile)) {
|
|
27942
|
+
const stat2 = await lstat4(path10.join(absolute2, name2));
|
|
27943
|
+
if (!stat2.isFile() || stat2.isSymbolicLink() || stat2.size > 4096) throw fail2("STORE_DIRECTORY_INVALID");
|
|
27944
|
+
}
|
|
27938
27945
|
for (const name2 of ["agent-process.json", "optimization", ".local-commander"]) {
|
|
27939
27946
|
if (!names.includes(name2)) continue;
|
|
27940
27947
|
const filename = path10.join(absolute2, name2), stat2 = await lstat4(filename);
|
|
@@ -28905,8 +28912,8 @@ var HostMemory = class {
|
|
|
28905
28912
|
};
|
|
28906
28913
|
|
|
28907
28914
|
// agent/src/tools.ts
|
|
28908
|
-
import { constants as
|
|
28909
|
-
import { lstat as
|
|
28915
|
+
import { constants as constants8 } from "node:fs";
|
|
28916
|
+
import { lstat as lstat8, open as open6, readdir as readdir5, realpath as realpath7, rename as rename4, rm as rm6 } from "node:fs/promises";
|
|
28910
28917
|
import path18 from "node:path";
|
|
28911
28918
|
import { createHash as createHash14, randomUUID as randomUUID7 } from "node:crypto";
|
|
28912
28919
|
|
|
@@ -29353,22 +29360,1025 @@ async function runSupervised(helper, request, options = {}) {
|
|
|
29353
29360
|
|
|
29354
29361
|
// agent/src/screen-capture.ts
|
|
29355
29362
|
import { execFile as execFile4 } from "node:child_process";
|
|
29356
|
-
import {
|
|
29363
|
+
import { randomBytes as randomBytes6 } from "node:crypto";
|
|
29364
|
+
import { constants as constants7 } from "node:fs";
|
|
29365
|
+
import { access as access3, lstat as lstat7, mkdtemp, readFile as readFile6, readdir as readdir4, rm as rm5, unlink as unlink2 } from "node:fs/promises";
|
|
29357
29366
|
import os4 from "node:os";
|
|
29358
29367
|
import path17 from "node:path";
|
|
29368
|
+
|
|
29369
|
+
// agent/src/dbus-portal.ts
|
|
29370
|
+
import net from "node:net";
|
|
29371
|
+
function sessionBusSocket(address) {
|
|
29372
|
+
for (const entry of (address ?? "").split(";")) {
|
|
29373
|
+
if (!entry.startsWith("unix:")) continue;
|
|
29374
|
+
for (const part of entry.slice(5).split(",")) {
|
|
29375
|
+
const at = part.indexOf("="), key = part.slice(0, at), value = decodeURIComponent(part.slice(at + 1));
|
|
29376
|
+
if (at > 0 && value && key === "path") return value;
|
|
29377
|
+
if (at > 0 && value && key === "abstract") return "\0" + value;
|
|
29378
|
+
}
|
|
29379
|
+
}
|
|
29380
|
+
return null;
|
|
29381
|
+
}
|
|
29382
|
+
var Writer = class {
|
|
29383
|
+
bytes = [];
|
|
29384
|
+
align(n) {
|
|
29385
|
+
while (this.bytes.length % n) this.bytes.push(0);
|
|
29386
|
+
}
|
|
29387
|
+
byte(v) {
|
|
29388
|
+
this.bytes.push(v & 255);
|
|
29389
|
+
}
|
|
29390
|
+
u32(v) {
|
|
29391
|
+
this.align(4);
|
|
29392
|
+
this.bytes.push(v & 255, v >>> 8 & 255, v >>> 16 & 255, v >>> 24 & 255);
|
|
29393
|
+
}
|
|
29394
|
+
str(v) {
|
|
29395
|
+
const b = Buffer.from(v, "utf8");
|
|
29396
|
+
this.u32(b.length);
|
|
29397
|
+
this.bytes.push(...b, 0);
|
|
29398
|
+
}
|
|
29399
|
+
sig(v) {
|
|
29400
|
+
this.byte(v.length);
|
|
29401
|
+
this.bytes.push(...Buffer.from(v, "ascii"), 0);
|
|
29402
|
+
}
|
|
29403
|
+
/** Basic value or variant: `s`, `o`, `g`, `u`, `b`, `v` ([signature, value]). */
|
|
29404
|
+
put(type, value) {
|
|
29405
|
+
if (type === "s" || type === "o") this.str(String(value));
|
|
29406
|
+
else if (type === "g") this.sig(String(value));
|
|
29407
|
+
else if (type === "u") this.u32(Number(value));
|
|
29408
|
+
else if (type === "b") this.u32(value ? 1 : 0);
|
|
29409
|
+
else if (type === "v") {
|
|
29410
|
+
const [inner, v] = value;
|
|
29411
|
+
this.sig(inner);
|
|
29412
|
+
this.put(inner, v);
|
|
29413
|
+
} else throw Error("type " + type);
|
|
29414
|
+
}
|
|
29415
|
+
/** a{sv} */
|
|
29416
|
+
dict(entries) {
|
|
29417
|
+
this.u32(0);
|
|
29418
|
+
const lengthAt = this.bytes.length - 4;
|
|
29419
|
+
this.align(8);
|
|
29420
|
+
const start = this.bytes.length;
|
|
29421
|
+
for (const [key, value] of entries) {
|
|
29422
|
+
this.align(8);
|
|
29423
|
+
this.str(key);
|
|
29424
|
+
this.put("v", value);
|
|
29425
|
+
}
|
|
29426
|
+
const length = this.bytes.length - start;
|
|
29427
|
+
this.bytes.splice(lengthAt, 4, length & 255, length >>> 8 & 255, length >>> 16 & 255, length >>> 24 & 255);
|
|
29428
|
+
}
|
|
29429
|
+
};
|
|
29430
|
+
var Reader = class {
|
|
29431
|
+
constructor(data, at, le) {
|
|
29432
|
+
this.data = data;
|
|
29433
|
+
this.at = at;
|
|
29434
|
+
this.le = le;
|
|
29435
|
+
}
|
|
29436
|
+
data;
|
|
29437
|
+
at;
|
|
29438
|
+
le;
|
|
29439
|
+
align(n) {
|
|
29440
|
+
this.at = Math.ceil(this.at / n) * n;
|
|
29441
|
+
}
|
|
29442
|
+
u32() {
|
|
29443
|
+
this.align(4);
|
|
29444
|
+
const v = this.le ? this.data.readUInt32LE(this.at) : this.data.readUInt32BE(this.at);
|
|
29445
|
+
this.at += 4;
|
|
29446
|
+
return v;
|
|
29447
|
+
}
|
|
29448
|
+
/** Reads one complete type from `sig` starting at `i`; returns the value and the index after the type. */
|
|
29449
|
+
read(sig2, i) {
|
|
29450
|
+
const c = sig2[i];
|
|
29451
|
+
const fixed = { y: 1, n: 2, q: 2, b: 4, i: 4, u: 4, h: 4, x: 8, t: 8, d: 8 };
|
|
29452
|
+
if (c in fixed) {
|
|
29453
|
+
const size = fixed[c];
|
|
29454
|
+
this.align(size);
|
|
29455
|
+
const v = size === 1 ? this.data[this.at] : size === 2 ? this.le ? this.data.readUInt16LE(this.at) : this.data.readUInt16BE(this.at) : size === 4 ? this.le ? this.data.readUInt32LE(this.at) : this.data.readUInt32BE(this.at) : null;
|
|
29456
|
+
this.at += size;
|
|
29457
|
+
return [c === "b" ? v === 1 : v, i + 1];
|
|
29458
|
+
}
|
|
29459
|
+
if (c === "s" || c === "o") {
|
|
29460
|
+
const n = this.u32(), v = this.data.toString("utf8", this.at, this.at + n);
|
|
29461
|
+
this.at += n + 1;
|
|
29462
|
+
return [v, i + 1];
|
|
29463
|
+
}
|
|
29464
|
+
if (c === "g") {
|
|
29465
|
+
const n = this.data[this.at], v = this.data.toString("ascii", this.at + 1, this.at + 1 + n);
|
|
29466
|
+
this.at += n + 2;
|
|
29467
|
+
return [v, i + 1];
|
|
29468
|
+
}
|
|
29469
|
+
if (c === "v") {
|
|
29470
|
+
const [inner] = this.read("g", 0);
|
|
29471
|
+
return [this.read(inner, 0)[0], i + 1];
|
|
29472
|
+
}
|
|
29473
|
+
if (c === "(" || c === "{") {
|
|
29474
|
+
this.align(8);
|
|
29475
|
+
const close = c === "(" ? ")" : "}", values = [];
|
|
29476
|
+
let j = i + 1;
|
|
29477
|
+
while (sig2[j] !== close) {
|
|
29478
|
+
const [v, next] = this.read(sig2, j);
|
|
29479
|
+
values.push(v);
|
|
29480
|
+
j = next;
|
|
29481
|
+
}
|
|
29482
|
+
return [values, j + 1];
|
|
29483
|
+
}
|
|
29484
|
+
if (c === "a") {
|
|
29485
|
+
const n = this.u32(), element = sig2[i + 1];
|
|
29486
|
+
this.align("xtd({".includes(element) ? 8 : element === "n" || element === "q" ? 2 : element === "y" || element === "g" || element === "v" ? 1 : 4);
|
|
29487
|
+
const end = this.at + n, values = [];
|
|
29488
|
+
let next = skip(sig2, i + 1);
|
|
29489
|
+
while (this.at < end) {
|
|
29490
|
+
const [v, j] = this.read(sig2, i + 1);
|
|
29491
|
+
values.push(v);
|
|
29492
|
+
next = j;
|
|
29493
|
+
}
|
|
29494
|
+
return [values, next];
|
|
29495
|
+
}
|
|
29496
|
+
throw Error("signature " + sig2);
|
|
29497
|
+
}
|
|
29498
|
+
};
|
|
29499
|
+
function skip(sig2, i) {
|
|
29500
|
+
const c = sig2[i];
|
|
29501
|
+
if (c === "a") return skip(sig2, i + 1);
|
|
29502
|
+
if (c === "(" || c === "{") {
|
|
29503
|
+
let j = i + 1;
|
|
29504
|
+
while (sig2[j] !== (c === "(" ? ")" : "}")) j = skip(sig2, j);
|
|
29505
|
+
return j + 1;
|
|
29506
|
+
}
|
|
29507
|
+
return i + 1;
|
|
29508
|
+
}
|
|
29509
|
+
function parse3(data) {
|
|
29510
|
+
const le = data[0] === 108, r = new Reader(data, 4, le), bodyLength = r.u32(), serial = r.u32();
|
|
29511
|
+
const [fields] = r.read("a(yv)", 0);
|
|
29512
|
+
const message2 = { type: data[1], serial, signature: "", body: [] };
|
|
29513
|
+
for (const [code, value] of fields) {
|
|
29514
|
+
if (code === 1) message2.path = String(value);
|
|
29515
|
+
else if (code === 2) message2.interface = String(value);
|
|
29516
|
+
else if (code === 3) message2.member = String(value);
|
|
29517
|
+
else if (code === 4) message2.errorName = String(value);
|
|
29518
|
+
else if (code === 5) message2.replySerial = Number(value);
|
|
29519
|
+
else if (code === 8) message2.signature = String(value);
|
|
29520
|
+
}
|
|
29521
|
+
r.align(8);
|
|
29522
|
+
const end = r.at + bodyLength;
|
|
29523
|
+
for (let i = 0; i < message2.signature.length && r.at < end; ) {
|
|
29524
|
+
const [v, next] = r.read(message2.signature, i);
|
|
29525
|
+
message2.body.push(v);
|
|
29526
|
+
i = next;
|
|
29527
|
+
}
|
|
29528
|
+
return message2;
|
|
29529
|
+
}
|
|
29530
|
+
function frameLength(data) {
|
|
29531
|
+
if (data.length < 16) return 0;
|
|
29532
|
+
const le = data[0] === 108, u = (at) => le ? data.readUInt32LE(at) : data.readUInt32BE(at);
|
|
29533
|
+
const length = Math.ceil((16 + u(12)) / 8) * 8 + u(4);
|
|
29534
|
+
return data.length >= length ? length : 0;
|
|
29535
|
+
}
|
|
29536
|
+
async function portalScreenshot(socket, uid, token, signal) {
|
|
29537
|
+
const connection = net.createConnection({ path: socket });
|
|
29538
|
+
try {
|
|
29539
|
+
return await new Promise((resolve, reject) => {
|
|
29540
|
+
let serial = 0, buffer = Buffer.alloc(0), authenticated = false, requestPath = "";
|
|
29541
|
+
const pending = /* @__PURE__ */ new Map();
|
|
29542
|
+
const fail7 = (error62) => reject(error62 instanceof Error ? error62 : Error(String(error62)));
|
|
29543
|
+
const abort = () => fail7(Error("ABORTED"));
|
|
29544
|
+
if (signal.aborted) return abort();
|
|
29545
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
29546
|
+
connection.on("error", fail7);
|
|
29547
|
+
connection.on("close", () => fail7(Error("CLOSED")));
|
|
29548
|
+
const call = (destination, path30, iface, member, signature = "", body = () => {
|
|
29549
|
+
}) => new Promise((done, failed) => {
|
|
29550
|
+
const payload2 = new Writer();
|
|
29551
|
+
body(payload2);
|
|
29552
|
+
const header = new Writer(), fields = [[1, "o", path30], [2, "s", iface], [3, "s", member], [6, "s", destination]];
|
|
29553
|
+
if (signature) fields.push([8, "g", signature]);
|
|
29554
|
+
header.byte(108);
|
|
29555
|
+
header.byte(1);
|
|
29556
|
+
header.byte(0);
|
|
29557
|
+
header.byte(1);
|
|
29558
|
+
header.u32(payload2.bytes.length);
|
|
29559
|
+
header.u32(++serial);
|
|
29560
|
+
header.u32(0);
|
|
29561
|
+
const lengthAt = header.bytes.length - 4;
|
|
29562
|
+
header.align(8);
|
|
29563
|
+
const start = header.bytes.length;
|
|
29564
|
+
for (const [code, type, value] of fields) {
|
|
29565
|
+
header.align(8);
|
|
29566
|
+
header.byte(code);
|
|
29567
|
+
header.sig(type);
|
|
29568
|
+
header.put(type, value);
|
|
29569
|
+
}
|
|
29570
|
+
const length = header.bytes.length - start;
|
|
29571
|
+
header.bytes.splice(lengthAt, 4, length & 255, length >>> 8 & 255, length >>> 16 & 255, length >>> 24 & 255);
|
|
29572
|
+
header.align(8);
|
|
29573
|
+
pending.set(serial, (reply) => reply.type === 3 ? failed(Error(reply.errorName ?? "DBUS_ERROR")) : done(reply));
|
|
29574
|
+
connection.write(Buffer.from([...header.bytes, ...payload2.bytes]));
|
|
29575
|
+
});
|
|
29576
|
+
const bus = (member, signature, body) => call("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", member, signature, body);
|
|
29577
|
+
connection.on("data", (chunk) => {
|
|
29578
|
+
try {
|
|
29579
|
+
receive(chunk);
|
|
29580
|
+
} catch (error62) {
|
|
29581
|
+
fail7(error62);
|
|
29582
|
+
}
|
|
29583
|
+
});
|
|
29584
|
+
const receive = (chunk) => {
|
|
29585
|
+
buffer = Buffer.concat([buffer, chunk]);
|
|
29586
|
+
if (buffer.length > 1048576) return fail7(Error("OVERSIZED"));
|
|
29587
|
+
if (!authenticated) {
|
|
29588
|
+
const end = buffer.indexOf("\r\n");
|
|
29589
|
+
if (end < 0) return;
|
|
29590
|
+
const line = buffer.toString("ascii", 0, end);
|
|
29591
|
+
buffer = buffer.subarray(end + 2);
|
|
29592
|
+
if (!line.startsWith("OK ")) return fail7(Error("AUTH"));
|
|
29593
|
+
authenticated = true;
|
|
29594
|
+
connection.write("BEGIN\r\n");
|
|
29595
|
+
void (async () => {
|
|
29596
|
+
const unique = String((await bus("Hello")).body[0]);
|
|
29597
|
+
requestPath = "/org/freedesktop/portal/desktop/request/" + unique.slice(1).replace(/\./g, "_") + "/" + token;
|
|
29598
|
+
await bus("AddMatch", "s", (w) => w.put("s", "type='signal',interface='org.freedesktop.portal.Request',member='Response',path='" + requestPath + "'"));
|
|
29599
|
+
const handle = await call(
|
|
29600
|
+
"org.freedesktop.portal.Desktop",
|
|
29601
|
+
"/org/freedesktop/portal/desktop",
|
|
29602
|
+
"org.freedesktop.portal.Screenshot",
|
|
29603
|
+
"Screenshot",
|
|
29604
|
+
"sa{sv}",
|
|
29605
|
+
(w) => {
|
|
29606
|
+
w.put("s", "");
|
|
29607
|
+
w.dict([["handle_token", ["s", token]], ["interactive", ["b", false]]]);
|
|
29608
|
+
}
|
|
29609
|
+
);
|
|
29610
|
+
if (handle.body[0] !== requestPath) {
|
|
29611
|
+
requestPath = String(handle.body[0]);
|
|
29612
|
+
await bus("AddMatch", "s", (w) => w.put("s", "type='signal',interface='org.freedesktop.portal.Request',member='Response',path='" + requestPath + "'"));
|
|
29613
|
+
}
|
|
29614
|
+
})().catch(fail7);
|
|
29615
|
+
}
|
|
29616
|
+
for (let length = frameLength(buffer); authenticated && length; length = frameLength(buffer)) {
|
|
29617
|
+
const message2 = parse3(buffer.subarray(0, length));
|
|
29618
|
+
buffer = buffer.subarray(length);
|
|
29619
|
+
if ((message2.type === 2 || message2.type === 3) && message2.replySerial !== void 0) {
|
|
29620
|
+
pending.get(message2.replySerial)?.(message2);
|
|
29621
|
+
pending.delete(message2.replySerial);
|
|
29622
|
+
} else if (message2.type === 4 && message2.member === "Response" && message2.path === requestPath && message2.signature === "ua{sv}") {
|
|
29623
|
+
const results2 = message2.body[1], uri = results2.find(([key]) => key === "uri")?.[1];
|
|
29624
|
+
resolve({ code: Number(message2.body[0]), uri: typeof uri === "string" ? uri : void 0 });
|
|
29625
|
+
}
|
|
29626
|
+
}
|
|
29627
|
+
};
|
|
29628
|
+
connection.on("connect", () => connection.write("\0AUTH EXTERNAL " + Buffer.from(String(uid), "ascii").toString("hex") + "\r\n"));
|
|
29629
|
+
});
|
|
29630
|
+
} finally {
|
|
29631
|
+
connection.destroy();
|
|
29632
|
+
}
|
|
29633
|
+
}
|
|
29634
|
+
|
|
29635
|
+
// agent/src/screen-image.ts
|
|
29636
|
+
import { inflateSync } from "node:zlib";
|
|
29637
|
+
var MAX_EDGE = 16384;
|
|
29638
|
+
var MAX_PIXELS = 67108864;
|
|
29639
|
+
function sizeOk(width, height) {
|
|
29640
|
+
return Number.isSafeInteger(width) && Number.isSafeInteger(height) && width > 0 && height > 0 && width <= MAX_EDGE && height <= MAX_EDGE && width * height <= MAX_PIXELS;
|
|
29641
|
+
}
|
|
29642
|
+
function decodePng(data) {
|
|
29643
|
+
if (data.length < 33 || data.readUInt32BE(0) !== 2303741511 || data.readUInt32BE(4) !== 218765834) return null;
|
|
29644
|
+
let width = 0, height = 0, channels = 0;
|
|
29645
|
+
const idat = [];
|
|
29646
|
+
for (let at = 8; at + 12 <= data.length; ) {
|
|
29647
|
+
const length = data.readUInt32BE(at), type = data.toString("latin1", at + 4, at + 8), body = at + 8;
|
|
29648
|
+
if (body + length + 4 > data.length) return null;
|
|
29649
|
+
if (type === "IHDR") {
|
|
29650
|
+
if (length !== 13) return null;
|
|
29651
|
+
width = data.readUInt32BE(body);
|
|
29652
|
+
height = data.readUInt32BE(body + 4);
|
|
29653
|
+
const depth = data[body + 8], color = data[body + 9], interlace = data[body + 12];
|
|
29654
|
+
channels = color === 0 ? 1 : color === 2 ? 3 : color === 4 ? 2 : color === 6 ? 4 : 0;
|
|
29655
|
+
if (depth !== 8 || !channels || interlace !== 0 || data[body + 10] !== 0 || data[body + 11] !== 0 || !sizeOk(width, height)) return null;
|
|
29656
|
+
} else if (type === "IDAT") idat.push(data.subarray(body, body + length));
|
|
29657
|
+
else if (type === "IEND") break;
|
|
29658
|
+
at = body + length + 4;
|
|
29659
|
+
}
|
|
29660
|
+
if (!channels || !idat.length) return null;
|
|
29661
|
+
const stride = width * channels, expected = (stride + 1) * height;
|
|
29662
|
+
let raw;
|
|
29663
|
+
try {
|
|
29664
|
+
raw = inflateSync(Buffer.concat(idat), { maxOutputLength: expected });
|
|
29665
|
+
} catch {
|
|
29666
|
+
return null;
|
|
29667
|
+
}
|
|
29668
|
+
if (raw.length !== expected) return null;
|
|
29669
|
+
const rgb = Buffer.alloc(width * height * 3);
|
|
29670
|
+
let previous = Buffer.alloc(stride), current2 = Buffer.alloc(stride);
|
|
29671
|
+
for (let y = 0; y < height; y++) {
|
|
29672
|
+
const filter = raw[y * (stride + 1)], line = raw.subarray(y * (stride + 1) + 1, (y + 1) * (stride + 1));
|
|
29673
|
+
for (let x = 0; x < stride; x++) {
|
|
29674
|
+
const a = x >= channels ? current2[x - channels] : 0, b = previous[x], c = x >= channels ? previous[x - channels] : 0;
|
|
29675
|
+
let value = line[x];
|
|
29676
|
+
if (filter === 1) value += a;
|
|
29677
|
+
else if (filter === 2) value += b;
|
|
29678
|
+
else if (filter === 3) value += a + b >> 1;
|
|
29679
|
+
else if (filter === 4) {
|
|
29680
|
+
const p = a + b - c, pa = Math.abs(p - a), pb = Math.abs(p - b), pc = Math.abs(p - c);
|
|
29681
|
+
value += pa <= pb && pa <= pc ? a : pb <= pc ? b : c;
|
|
29682
|
+
} else if (filter !== 0) return null;
|
|
29683
|
+
current2[x] = value & 255;
|
|
29684
|
+
}
|
|
29685
|
+
for (let x = 0, o = y * width * 3; x < width; x++, o += 3) {
|
|
29686
|
+
const i = x * channels;
|
|
29687
|
+
if (channels <= 2) rgb[o] = rgb[o + 1] = rgb[o + 2] = current2[i];
|
|
29688
|
+
else {
|
|
29689
|
+
rgb[o] = current2[i];
|
|
29690
|
+
rgb[o + 1] = current2[i + 1];
|
|
29691
|
+
rgb[o + 2] = current2[i + 2];
|
|
29692
|
+
}
|
|
29693
|
+
}
|
|
29694
|
+
[previous, current2] = [current2, previous];
|
|
29695
|
+
}
|
|
29696
|
+
return { width, height, rgb };
|
|
29697
|
+
}
|
|
29698
|
+
function decodeXwd(data) {
|
|
29699
|
+
if (data.length < 100) return null;
|
|
29700
|
+
const field = (index) => data.readUInt32BE(index * 4);
|
|
29701
|
+
const headerSize = field(0), version2 = field(1), format = field(2), width = field(4), height = field(5), byteOrder = field(7);
|
|
29702
|
+
const bitsPerPixel = field(11), bytesPerLine = field(12), visualClass = field(13), masks = [field(14), field(15), field(16)], colors = field(19);
|
|
29703
|
+
if (version2 !== 7 || format !== 2 || headerSize < 100 || ![4, 5].includes(visualClass) || ![24, 32].includes(bitsPerPixel) || !sizeOk(width, height) || colors > 65536) return null;
|
|
29704
|
+
const pixelBytes = bitsPerPixel / 8, start = headerSize + colors * 12;
|
|
29705
|
+
if (bytesPerLine < width * pixelBytes || start + bytesPerLine * height > data.length || masks.some((mask) => !mask)) return null;
|
|
29706
|
+
const shifts = masks.map((mask) => {
|
|
29707
|
+
let shift = 0;
|
|
29708
|
+
while (!(mask >>> shift & 1)) shift++;
|
|
29709
|
+
return shift;
|
|
29710
|
+
});
|
|
29711
|
+
const scales = masks.map((mask, i) => 255 / (mask >>> shifts[i]));
|
|
29712
|
+
const rgb = Buffer.alloc(width * height * 3);
|
|
29713
|
+
for (let y = 0; y < height; y++) for (let x = 0, at = start + y * bytesPerLine, o = y * width * 3; x < width; x++, at += pixelBytes, o += 3) {
|
|
29714
|
+
const pixel = pixelBytes === 4 ? byteOrder === 0 ? data.readUInt32LE(at) : data.readUInt32BE(at) : byteOrder === 0 ? data[at] | data[at + 1] << 8 | data[at + 2] << 16 : data[at] << 16 | data[at + 1] << 8 | data[at + 2];
|
|
29715
|
+
for (let c = 0; c < 3; c++) rgb[o + c] = Math.round(((pixel & masks[c]) >>> 0 >>> shifts[c]) * scales[c]);
|
|
29716
|
+
}
|
|
29717
|
+
return { width, height, rgb };
|
|
29718
|
+
}
|
|
29719
|
+
function downscale(image, edge) {
|
|
29720
|
+
const scale = Math.min(1, edge / Math.max(image.width, image.height));
|
|
29721
|
+
if (scale >= 1) return image;
|
|
29722
|
+
const width = Math.max(1, Math.round(image.width * scale)), height = Math.max(1, Math.round(image.height * scale));
|
|
29723
|
+
const xs = Array.from({ length: width + 1 }, (_, x) => Math.min(image.width, Math.floor(x * image.width / width)));
|
|
29724
|
+
const ys = Array.from({ length: height + 1 }, (_, y) => Math.min(image.height, Math.floor(y * image.height / height)));
|
|
29725
|
+
const rgb = Buffer.alloc(width * height * 3), sums = new Float64Array(width * 3);
|
|
29726
|
+
for (let y = 0; y < height; y++) {
|
|
29727
|
+
sums.fill(0);
|
|
29728
|
+
for (let sy = ys[y]; sy < ys[y + 1]; sy++) for (let x = 0; x < width; x++) for (let sx = xs[x]; sx < xs[x + 1]; sx++) {
|
|
29729
|
+
const i = (sy * image.width + sx) * 3;
|
|
29730
|
+
sums[x * 3] = sums[x * 3] + image.rgb[i];
|
|
29731
|
+
sums[x * 3 + 1] = sums[x * 3 + 1] + image.rgb[i + 1];
|
|
29732
|
+
sums[x * 3 + 2] = sums[x * 3 + 2] + image.rgb[i + 2];
|
|
29733
|
+
}
|
|
29734
|
+
for (let x = 0; x < width; x++) {
|
|
29735
|
+
const count3 = (ys[y + 1] - ys[y]) * (xs[x + 1] - xs[x]);
|
|
29736
|
+
for (let c = 0; c < 3; c++) rgb[(y * width + x) * 3 + c] = Math.round(sums[x * 3 + c] / count3);
|
|
29737
|
+
}
|
|
29738
|
+
}
|
|
29739
|
+
return { width, height, rgb };
|
|
29740
|
+
}
|
|
29741
|
+
var ZIGZAG = [
|
|
29742
|
+
0,
|
|
29743
|
+
1,
|
|
29744
|
+
5,
|
|
29745
|
+
6,
|
|
29746
|
+
14,
|
|
29747
|
+
15,
|
|
29748
|
+
27,
|
|
29749
|
+
28,
|
|
29750
|
+
2,
|
|
29751
|
+
4,
|
|
29752
|
+
7,
|
|
29753
|
+
13,
|
|
29754
|
+
16,
|
|
29755
|
+
26,
|
|
29756
|
+
29,
|
|
29757
|
+
42,
|
|
29758
|
+
3,
|
|
29759
|
+
8,
|
|
29760
|
+
12,
|
|
29761
|
+
17,
|
|
29762
|
+
25,
|
|
29763
|
+
30,
|
|
29764
|
+
41,
|
|
29765
|
+
43,
|
|
29766
|
+
9,
|
|
29767
|
+
11,
|
|
29768
|
+
18,
|
|
29769
|
+
24,
|
|
29770
|
+
31,
|
|
29771
|
+
40,
|
|
29772
|
+
44,
|
|
29773
|
+
53,
|
|
29774
|
+
10,
|
|
29775
|
+
19,
|
|
29776
|
+
23,
|
|
29777
|
+
32,
|
|
29778
|
+
39,
|
|
29779
|
+
45,
|
|
29780
|
+
52,
|
|
29781
|
+
54,
|
|
29782
|
+
20,
|
|
29783
|
+
22,
|
|
29784
|
+
33,
|
|
29785
|
+
38,
|
|
29786
|
+
46,
|
|
29787
|
+
51,
|
|
29788
|
+
55,
|
|
29789
|
+
60,
|
|
29790
|
+
21,
|
|
29791
|
+
34,
|
|
29792
|
+
37,
|
|
29793
|
+
47,
|
|
29794
|
+
50,
|
|
29795
|
+
56,
|
|
29796
|
+
59,
|
|
29797
|
+
61,
|
|
29798
|
+
35,
|
|
29799
|
+
36,
|
|
29800
|
+
48,
|
|
29801
|
+
49,
|
|
29802
|
+
57,
|
|
29803
|
+
58,
|
|
29804
|
+
62,
|
|
29805
|
+
63
|
|
29806
|
+
];
|
|
29807
|
+
var LUMA_QUANT = [
|
|
29808
|
+
16,
|
|
29809
|
+
11,
|
|
29810
|
+
10,
|
|
29811
|
+
16,
|
|
29812
|
+
24,
|
|
29813
|
+
40,
|
|
29814
|
+
51,
|
|
29815
|
+
61,
|
|
29816
|
+
12,
|
|
29817
|
+
12,
|
|
29818
|
+
14,
|
|
29819
|
+
19,
|
|
29820
|
+
26,
|
|
29821
|
+
58,
|
|
29822
|
+
60,
|
|
29823
|
+
55,
|
|
29824
|
+
14,
|
|
29825
|
+
13,
|
|
29826
|
+
16,
|
|
29827
|
+
24,
|
|
29828
|
+
40,
|
|
29829
|
+
57,
|
|
29830
|
+
69,
|
|
29831
|
+
56,
|
|
29832
|
+
14,
|
|
29833
|
+
17,
|
|
29834
|
+
22,
|
|
29835
|
+
29,
|
|
29836
|
+
51,
|
|
29837
|
+
87,
|
|
29838
|
+
80,
|
|
29839
|
+
62,
|
|
29840
|
+
18,
|
|
29841
|
+
22,
|
|
29842
|
+
37,
|
|
29843
|
+
56,
|
|
29844
|
+
68,
|
|
29845
|
+
109,
|
|
29846
|
+
103,
|
|
29847
|
+
77,
|
|
29848
|
+
24,
|
|
29849
|
+
35,
|
|
29850
|
+
55,
|
|
29851
|
+
64,
|
|
29852
|
+
81,
|
|
29853
|
+
104,
|
|
29854
|
+
113,
|
|
29855
|
+
92,
|
|
29856
|
+
49,
|
|
29857
|
+
64,
|
|
29858
|
+
78,
|
|
29859
|
+
87,
|
|
29860
|
+
103,
|
|
29861
|
+
121,
|
|
29862
|
+
120,
|
|
29863
|
+
101,
|
|
29864
|
+
72,
|
|
29865
|
+
92,
|
|
29866
|
+
95,
|
|
29867
|
+
98,
|
|
29868
|
+
112,
|
|
29869
|
+
100,
|
|
29870
|
+
103,
|
|
29871
|
+
99
|
|
29872
|
+
];
|
|
29873
|
+
var CHROMA_QUANT = [17, 18, 24, 47, 99, 99, 99, 99, 18, 21, 26, 66, 99, 99, 99, 99, 24, 26, 56, 99, 99, 99, 99, 99, 47, 66, ...Array(38).fill(99)];
|
|
29874
|
+
var AC_LUMA_VALUES = [
|
|
29875
|
+
1,
|
|
29876
|
+
2,
|
|
29877
|
+
3,
|
|
29878
|
+
0,
|
|
29879
|
+
4,
|
|
29880
|
+
17,
|
|
29881
|
+
5,
|
|
29882
|
+
18,
|
|
29883
|
+
33,
|
|
29884
|
+
49,
|
|
29885
|
+
65,
|
|
29886
|
+
6,
|
|
29887
|
+
19,
|
|
29888
|
+
81,
|
|
29889
|
+
97,
|
|
29890
|
+
7,
|
|
29891
|
+
34,
|
|
29892
|
+
113,
|
|
29893
|
+
20,
|
|
29894
|
+
50,
|
|
29895
|
+
129,
|
|
29896
|
+
145,
|
|
29897
|
+
161,
|
|
29898
|
+
8,
|
|
29899
|
+
35,
|
|
29900
|
+
66,
|
|
29901
|
+
177,
|
|
29902
|
+
193,
|
|
29903
|
+
21,
|
|
29904
|
+
82,
|
|
29905
|
+
209,
|
|
29906
|
+
240,
|
|
29907
|
+
36,
|
|
29908
|
+
51,
|
|
29909
|
+
98,
|
|
29910
|
+
114,
|
|
29911
|
+
130,
|
|
29912
|
+
9,
|
|
29913
|
+
10,
|
|
29914
|
+
22,
|
|
29915
|
+
23,
|
|
29916
|
+
24,
|
|
29917
|
+
25,
|
|
29918
|
+
26,
|
|
29919
|
+
37,
|
|
29920
|
+
38,
|
|
29921
|
+
39,
|
|
29922
|
+
40,
|
|
29923
|
+
41,
|
|
29924
|
+
42,
|
|
29925
|
+
52,
|
|
29926
|
+
53,
|
|
29927
|
+
54,
|
|
29928
|
+
55,
|
|
29929
|
+
56,
|
|
29930
|
+
57,
|
|
29931
|
+
58,
|
|
29932
|
+
67,
|
|
29933
|
+
68,
|
|
29934
|
+
69,
|
|
29935
|
+
70,
|
|
29936
|
+
71,
|
|
29937
|
+
72,
|
|
29938
|
+
73,
|
|
29939
|
+
74,
|
|
29940
|
+
83,
|
|
29941
|
+
84,
|
|
29942
|
+
85,
|
|
29943
|
+
86,
|
|
29944
|
+
87,
|
|
29945
|
+
88,
|
|
29946
|
+
89,
|
|
29947
|
+
90,
|
|
29948
|
+
99,
|
|
29949
|
+
100,
|
|
29950
|
+
101,
|
|
29951
|
+
102,
|
|
29952
|
+
103,
|
|
29953
|
+
104,
|
|
29954
|
+
105,
|
|
29955
|
+
106,
|
|
29956
|
+
115,
|
|
29957
|
+
116,
|
|
29958
|
+
117,
|
|
29959
|
+
118,
|
|
29960
|
+
119,
|
|
29961
|
+
120,
|
|
29962
|
+
121,
|
|
29963
|
+
122,
|
|
29964
|
+
131,
|
|
29965
|
+
132,
|
|
29966
|
+
133,
|
|
29967
|
+
134,
|
|
29968
|
+
135,
|
|
29969
|
+
136,
|
|
29970
|
+
137,
|
|
29971
|
+
138,
|
|
29972
|
+
146,
|
|
29973
|
+
147,
|
|
29974
|
+
148,
|
|
29975
|
+
149,
|
|
29976
|
+
150,
|
|
29977
|
+
151,
|
|
29978
|
+
152,
|
|
29979
|
+
153,
|
|
29980
|
+
154,
|
|
29981
|
+
162,
|
|
29982
|
+
163,
|
|
29983
|
+
164,
|
|
29984
|
+
165,
|
|
29985
|
+
166,
|
|
29986
|
+
167,
|
|
29987
|
+
168,
|
|
29988
|
+
169,
|
|
29989
|
+
170,
|
|
29990
|
+
178,
|
|
29991
|
+
179,
|
|
29992
|
+
180,
|
|
29993
|
+
181,
|
|
29994
|
+
182,
|
|
29995
|
+
183,
|
|
29996
|
+
184,
|
|
29997
|
+
185,
|
|
29998
|
+
186,
|
|
29999
|
+
194,
|
|
30000
|
+
195,
|
|
30001
|
+
196,
|
|
30002
|
+
197,
|
|
30003
|
+
198,
|
|
30004
|
+
199,
|
|
30005
|
+
200,
|
|
30006
|
+
201,
|
|
30007
|
+
202,
|
|
30008
|
+
210,
|
|
30009
|
+
211,
|
|
30010
|
+
212,
|
|
30011
|
+
213,
|
|
30012
|
+
214,
|
|
30013
|
+
215,
|
|
30014
|
+
216,
|
|
30015
|
+
217,
|
|
30016
|
+
218,
|
|
30017
|
+
225,
|
|
30018
|
+
226,
|
|
30019
|
+
227,
|
|
30020
|
+
228,
|
|
30021
|
+
229,
|
|
30022
|
+
230,
|
|
30023
|
+
231,
|
|
30024
|
+
232,
|
|
30025
|
+
233,
|
|
30026
|
+
234,
|
|
30027
|
+
241,
|
|
30028
|
+
242,
|
|
30029
|
+
243,
|
|
30030
|
+
244,
|
|
30031
|
+
245,
|
|
30032
|
+
246,
|
|
30033
|
+
247,
|
|
30034
|
+
248,
|
|
30035
|
+
249,
|
|
30036
|
+
250
|
|
30037
|
+
];
|
|
30038
|
+
var AC_CHROMA_VALUES = [
|
|
30039
|
+
0,
|
|
30040
|
+
1,
|
|
30041
|
+
2,
|
|
30042
|
+
3,
|
|
30043
|
+
17,
|
|
30044
|
+
4,
|
|
30045
|
+
5,
|
|
30046
|
+
33,
|
|
30047
|
+
49,
|
|
30048
|
+
6,
|
|
30049
|
+
18,
|
|
30050
|
+
65,
|
|
30051
|
+
81,
|
|
30052
|
+
7,
|
|
30053
|
+
97,
|
|
30054
|
+
113,
|
|
30055
|
+
19,
|
|
30056
|
+
34,
|
|
30057
|
+
50,
|
|
30058
|
+
129,
|
|
30059
|
+
8,
|
|
30060
|
+
20,
|
|
30061
|
+
66,
|
|
30062
|
+
145,
|
|
30063
|
+
161,
|
|
30064
|
+
177,
|
|
30065
|
+
193,
|
|
30066
|
+
9,
|
|
30067
|
+
35,
|
|
30068
|
+
51,
|
|
30069
|
+
82,
|
|
30070
|
+
240,
|
|
30071
|
+
21,
|
|
30072
|
+
98,
|
|
30073
|
+
114,
|
|
30074
|
+
209,
|
|
30075
|
+
10,
|
|
30076
|
+
22,
|
|
30077
|
+
36,
|
|
30078
|
+
52,
|
|
30079
|
+
225,
|
|
30080
|
+
37,
|
|
30081
|
+
241,
|
|
30082
|
+
23,
|
|
30083
|
+
24,
|
|
30084
|
+
25,
|
|
30085
|
+
26,
|
|
30086
|
+
38,
|
|
30087
|
+
39,
|
|
30088
|
+
40,
|
|
30089
|
+
41,
|
|
30090
|
+
42,
|
|
30091
|
+
53,
|
|
30092
|
+
54,
|
|
30093
|
+
55,
|
|
30094
|
+
56,
|
|
30095
|
+
57,
|
|
30096
|
+
58,
|
|
30097
|
+
67,
|
|
30098
|
+
68,
|
|
30099
|
+
69,
|
|
30100
|
+
70,
|
|
30101
|
+
71,
|
|
30102
|
+
72,
|
|
30103
|
+
73,
|
|
30104
|
+
74,
|
|
30105
|
+
83,
|
|
30106
|
+
84,
|
|
30107
|
+
85,
|
|
30108
|
+
86,
|
|
30109
|
+
87,
|
|
30110
|
+
88,
|
|
30111
|
+
89,
|
|
30112
|
+
90,
|
|
30113
|
+
99,
|
|
30114
|
+
100,
|
|
30115
|
+
101,
|
|
30116
|
+
102,
|
|
30117
|
+
103,
|
|
30118
|
+
104,
|
|
30119
|
+
105,
|
|
30120
|
+
106,
|
|
30121
|
+
115,
|
|
30122
|
+
116,
|
|
30123
|
+
117,
|
|
30124
|
+
118,
|
|
30125
|
+
119,
|
|
30126
|
+
120,
|
|
30127
|
+
121,
|
|
30128
|
+
122,
|
|
30129
|
+
130,
|
|
30130
|
+
131,
|
|
30131
|
+
132,
|
|
30132
|
+
133,
|
|
30133
|
+
134,
|
|
30134
|
+
135,
|
|
30135
|
+
136,
|
|
30136
|
+
137,
|
|
30137
|
+
138,
|
|
30138
|
+
146,
|
|
30139
|
+
147,
|
|
30140
|
+
148,
|
|
30141
|
+
149,
|
|
30142
|
+
150,
|
|
30143
|
+
151,
|
|
30144
|
+
152,
|
|
30145
|
+
153,
|
|
30146
|
+
154,
|
|
30147
|
+
162,
|
|
30148
|
+
163,
|
|
30149
|
+
164,
|
|
30150
|
+
165,
|
|
30151
|
+
166,
|
|
30152
|
+
167,
|
|
30153
|
+
168,
|
|
30154
|
+
169,
|
|
30155
|
+
170,
|
|
30156
|
+
178,
|
|
30157
|
+
179,
|
|
30158
|
+
180,
|
|
30159
|
+
181,
|
|
30160
|
+
182,
|
|
30161
|
+
183,
|
|
30162
|
+
184,
|
|
30163
|
+
185,
|
|
30164
|
+
186,
|
|
30165
|
+
194,
|
|
30166
|
+
195,
|
|
30167
|
+
196,
|
|
30168
|
+
197,
|
|
30169
|
+
198,
|
|
30170
|
+
199,
|
|
30171
|
+
200,
|
|
30172
|
+
201,
|
|
30173
|
+
202,
|
|
30174
|
+
210,
|
|
30175
|
+
211,
|
|
30176
|
+
212,
|
|
30177
|
+
213,
|
|
30178
|
+
214,
|
|
30179
|
+
215,
|
|
30180
|
+
216,
|
|
30181
|
+
217,
|
|
30182
|
+
218,
|
|
30183
|
+
226,
|
|
30184
|
+
227,
|
|
30185
|
+
228,
|
|
30186
|
+
229,
|
|
30187
|
+
230,
|
|
30188
|
+
231,
|
|
30189
|
+
232,
|
|
30190
|
+
233,
|
|
30191
|
+
234,
|
|
30192
|
+
242,
|
|
30193
|
+
243,
|
|
30194
|
+
244,
|
|
30195
|
+
245,
|
|
30196
|
+
246,
|
|
30197
|
+
247,
|
|
30198
|
+
248,
|
|
30199
|
+
249,
|
|
30200
|
+
250
|
|
30201
|
+
];
|
|
30202
|
+
var DC_VALUES = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
|
|
30203
|
+
var HUFFMAN = [
|
|
30204
|
+
[0, [0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0], DC_VALUES],
|
|
30205
|
+
[16, [0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125], AC_LUMA_VALUES],
|
|
30206
|
+
[1, [0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0], DC_VALUES],
|
|
30207
|
+
[17, [0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 119], AC_CHROMA_VALUES]
|
|
30208
|
+
];
|
|
30209
|
+
var CODES = HUFFMAN.map(([, counts, values]) => {
|
|
30210
|
+
const table2 = [];
|
|
30211
|
+
let code = 0, at = 0;
|
|
30212
|
+
counts.forEach((count3, index) => {
|
|
30213
|
+
for (let i = 0; i < count3; i++) table2[values[at++]] = [code++, index + 1];
|
|
30214
|
+
code <<= 1;
|
|
30215
|
+
});
|
|
30216
|
+
return table2;
|
|
30217
|
+
});
|
|
30218
|
+
var AAN = [1, 1.387039845, 1.306562965, 1.175875602, 1, 0.785694958, 0.5411961, 0.275899379];
|
|
30219
|
+
function quantTables(quality) {
|
|
30220
|
+
const factor = quality < 50 ? 5e3 / quality : 200 - quality * 2;
|
|
30221
|
+
const scaled = (base) => base.map((value) => Math.min(255, Math.max(1, Math.floor((value * factor + 50) / 100))));
|
|
30222
|
+
const divisors = (table2) => Float64Array.from(table2, (value, k) => 1 / (value * AAN[k >> 3] * AAN[k & 7] * 8));
|
|
30223
|
+
const luma = scaled(LUMA_QUANT), chroma = scaled(CHROMA_QUANT);
|
|
30224
|
+
return { luma, chroma, lumaDivisors: divisors(luma), chromaDivisors: divisors(chroma) };
|
|
30225
|
+
}
|
|
30226
|
+
var BitWriter = class {
|
|
30227
|
+
buffer = Buffer.alloc(65536);
|
|
30228
|
+
length = 0;
|
|
30229
|
+
bits = 0;
|
|
30230
|
+
count = 0;
|
|
30231
|
+
byte(value) {
|
|
30232
|
+
if (this.length === this.buffer.length) {
|
|
30233
|
+
const next = Buffer.alloc(this.buffer.length * 2);
|
|
30234
|
+
this.buffer.copy(next);
|
|
30235
|
+
this.buffer = next;
|
|
30236
|
+
}
|
|
30237
|
+
this.buffer[this.length++] = value;
|
|
30238
|
+
}
|
|
30239
|
+
bytes(values) {
|
|
30240
|
+
for (const value of values) this.byte(value);
|
|
30241
|
+
}
|
|
30242
|
+
write(code, length) {
|
|
30243
|
+
this.bits = (this.bits << length | code) >>> 0;
|
|
30244
|
+
this.count += length;
|
|
30245
|
+
while (this.count >= 8) {
|
|
30246
|
+
const value = this.bits >>> this.count - 8 & 255;
|
|
30247
|
+
this.byte(value);
|
|
30248
|
+
if (value === 255) this.byte(0);
|
|
30249
|
+
this.count -= 8;
|
|
30250
|
+
this.bits &= (1 << this.count) - 1;
|
|
30251
|
+
}
|
|
30252
|
+
}
|
|
30253
|
+
flush() {
|
|
30254
|
+
if (this.count > 0) this.write((1 << 8 - this.count) - 1, 8 - this.count);
|
|
30255
|
+
}
|
|
30256
|
+
result() {
|
|
30257
|
+
return Buffer.from(this.buffer.subarray(0, this.length));
|
|
30258
|
+
}
|
|
30259
|
+
};
|
|
30260
|
+
function transform2(block, divisors, out) {
|
|
30261
|
+
for (let pass = 0; pass < 2; pass++) for (let i = 0; i < 8; i++) {
|
|
30262
|
+
const step = pass ? 8 : 1, base = pass ? i : i * 8, at = (k) => base + k * step;
|
|
30263
|
+
const d0 = block[at(0)], d1 = block[at(1)], d2 = block[at(2)], d3 = block[at(3)], d4 = block[at(4)], d5 = block[at(5)], d6 = block[at(6)], d7 = block[at(7)];
|
|
30264
|
+
const t0 = d0 + d7, t7 = d0 - d7, t1 = d1 + d6, t6 = d1 - d6, t2 = d2 + d5, t5 = d2 - d5, t3 = d3 + d4, t4 = d3 - d4;
|
|
30265
|
+
const t10 = t0 + t3, t13 = t0 - t3, t11 = t1 + t2, t12 = t1 - t2;
|
|
30266
|
+
block[at(0)] = t10 + t11;
|
|
30267
|
+
block[at(4)] = t10 - t11;
|
|
30268
|
+
const z1 = (t12 + t13) * 0.707106781;
|
|
30269
|
+
block[at(2)] = t13 + z1;
|
|
30270
|
+
block[at(6)] = t13 - z1;
|
|
30271
|
+
const o10 = t4 + t5, o11 = t5 + t6, o12 = t6 + t7;
|
|
30272
|
+
const z5 = (o10 - o12) * 0.382683433, z2 = 0.5411961 * o10 + z5, z4 = 1.306562965 * o12 + z5, z3 = o11 * 0.707106781;
|
|
30273
|
+
const z11 = t7 + z3, z13 = t7 - z3;
|
|
30274
|
+
block[at(5)] = z13 + z2;
|
|
30275
|
+
block[at(3)] = z13 - z2;
|
|
30276
|
+
block[at(1)] = z11 + z4;
|
|
30277
|
+
block[at(7)] = z11 - z4;
|
|
30278
|
+
}
|
|
30279
|
+
for (let k = 0; k < 64; k++) out[ZIGZAG[k]] = Math.round(block[k] * divisors[k]);
|
|
30280
|
+
}
|
|
30281
|
+
function magnitude(value) {
|
|
30282
|
+
const absolute2 = Math.abs(value);
|
|
30283
|
+
let length = 0;
|
|
30284
|
+
while (absolute2 >> length) length++;
|
|
30285
|
+
return [value < 0 ? value + (1 << length) - 1 : value, length];
|
|
30286
|
+
}
|
|
30287
|
+
function encodeJpeg(image, quality) {
|
|
30288
|
+
const { width, height, rgb } = image, tables = quantTables(Math.min(100, Math.max(1, Math.round(quality))));
|
|
30289
|
+
const out = new BitWriter(), word = (value) => [value >> 8, value & 255];
|
|
30290
|
+
out.bytes([255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0]);
|
|
30291
|
+
out.bytes([255, 219, 0, 132]);
|
|
30292
|
+
for (const [id2, table2] of [[0, tables.luma], [1, tables.chroma]]) {
|
|
30293
|
+
const zig = new Array(64);
|
|
30294
|
+
table2.forEach((value, k) => {
|
|
30295
|
+
zig[ZIGZAG[k]] = value;
|
|
30296
|
+
});
|
|
30297
|
+
out.bytes([id2, ...zig]);
|
|
30298
|
+
}
|
|
30299
|
+
out.bytes([255, 192, 0, 17, 8, ...word(height), ...word(width), 3, 1, 34, 0, 2, 17, 1, 3, 17, 1]);
|
|
30300
|
+
out.bytes([255, 196, ...word(2 + HUFFMAN.reduce((sum, [, , values]) => sum + 17 + values.length, 0))]);
|
|
30301
|
+
for (const [id2, counts, values] of HUFFMAN) out.bytes([id2, ...counts, ...values]);
|
|
30302
|
+
out.bytes([255, 218, 0, 12, 3, 1, 0, 2, 17, 3, 17, 0, 63, 0]);
|
|
30303
|
+
const block = new Float64Array(64), coefficients = new Int32Array(64), dc = [0, 0, 0];
|
|
30304
|
+
const Y = new Float64Array(256), Cb = new Float64Array(256), Cr = new Float64Array(256);
|
|
30305
|
+
const encode5 = (component, divisors) => {
|
|
30306
|
+
transform2(block, divisors, coefficients);
|
|
30307
|
+
const dcCodes = CODES[component ? 2 : 0], acCodes = CODES[component ? 3 : 1];
|
|
30308
|
+
const diff = coefficients[0] - dc[component];
|
|
30309
|
+
dc[component] = coefficients[0];
|
|
30310
|
+
const [bits, size] = magnitude(diff);
|
|
30311
|
+
out.write(...dcCodes[size]);
|
|
30312
|
+
if (size) out.write(bits, size);
|
|
30313
|
+
let last = 63;
|
|
30314
|
+
while (last > 0 && coefficients[last] === 0) last--;
|
|
30315
|
+
for (let k = 1, zeros = 0; k <= last; k++) {
|
|
30316
|
+
if (coefficients[k] === 0) {
|
|
30317
|
+
zeros++;
|
|
30318
|
+
continue;
|
|
30319
|
+
}
|
|
30320
|
+
while (zeros >= 16) {
|
|
30321
|
+
out.write(...acCodes[240]);
|
|
30322
|
+
zeros -= 16;
|
|
30323
|
+
}
|
|
30324
|
+
const [value, length] = magnitude(coefficients[k]);
|
|
30325
|
+
out.write(...acCodes[(zeros << 4) + length]);
|
|
30326
|
+
out.write(value, length);
|
|
30327
|
+
zeros = 0;
|
|
30328
|
+
}
|
|
30329
|
+
if (last < 63) out.write(...acCodes[0]);
|
|
30330
|
+
};
|
|
30331
|
+
for (let my = 0; my < height; my += 16) for (let mx = 0; mx < width; mx += 16) {
|
|
30332
|
+
for (let y = 0; y < 16; y++) for (let x = 0; x < 16; x++) {
|
|
30333
|
+
const i = (Math.min(height - 1, my + y) * width + Math.min(width - 1, mx + x)) * 3, r = rgb[i], g = rgb[i + 1], b = rgb[i + 2];
|
|
30334
|
+
Y[y * 16 + x] = 0.299 * r + 0.587 * g + 0.114 * b - 128;
|
|
30335
|
+
Cb[y * 16 + x] = -0.168736 * r - 0.331264 * g + 0.5 * b;
|
|
30336
|
+
Cr[y * 16 + x] = 0.5 * r - 0.418688 * g - 0.081312 * b;
|
|
30337
|
+
}
|
|
30338
|
+
for (const [ox, oy] of [[0, 0], [8, 0], [0, 8], [8, 8]]) {
|
|
30339
|
+
for (let y = 0; y < 8; y++) for (let x = 0; x < 8; x++) block[y * 8 + x] = Y[(oy + y) * 16 + ox + x];
|
|
30340
|
+
encode5(0, tables.lumaDivisors);
|
|
30341
|
+
}
|
|
30342
|
+
for (const [component, plane] of [[1, Cb], [2, Cr]]) {
|
|
30343
|
+
for (let y = 0; y < 8; y++) for (let x = 0; x < 8; x++) {
|
|
30344
|
+
const at = y * 32 + x * 2;
|
|
30345
|
+
block[y * 8 + x] = (plane[at] + plane[at + 1] + plane[at + 16] + plane[at + 17]) / 4;
|
|
30346
|
+
}
|
|
30347
|
+
encode5(component, tables.chromaDivisors);
|
|
30348
|
+
}
|
|
30349
|
+
}
|
|
30350
|
+
out.flush();
|
|
30351
|
+
out.bytes([255, 217]);
|
|
30352
|
+
return out.result();
|
|
30353
|
+
}
|
|
30354
|
+
function fitJpeg(image, maxEdge, maxBytes) {
|
|
30355
|
+
for (const edge of [maxEdge, 1280, 1024, 800, 640]) {
|
|
30356
|
+
const scaled = downscale(image, edge);
|
|
30357
|
+
for (const quality of [75, 60, 45, 35]) {
|
|
30358
|
+
const data = encodeJpeg(scaled, quality);
|
|
30359
|
+
if (data.length <= maxBytes) return { data, width: scaled.width, height: scaled.height };
|
|
30360
|
+
}
|
|
30361
|
+
}
|
|
30362
|
+
return null;
|
|
30363
|
+
}
|
|
30364
|
+
|
|
30365
|
+
// agent/src/screen-capture.ts
|
|
29359
30366
|
var SCREENSHOT_MAX_JPEG_BYTES = 131072;
|
|
29360
30367
|
var SCREENSHOT_MAX_EDGE = 1568;
|
|
29361
30368
|
function screenshotEnabled(env = process.env) {
|
|
29362
30369
|
return env.LC_SCREENSHOT_ENABLED === "true";
|
|
29363
30370
|
}
|
|
29364
30371
|
var SCREENSHOT_ACCEPTANCE_FILE = "screenshot-acceptance-enabled";
|
|
30372
|
+
var SCREENSHOT_OWNER_OFF_FILE = "screenshot-disabled-by-owner";
|
|
29365
30373
|
var ScreenCaptureError = class extends Error {
|
|
29366
|
-
constructor(code) {
|
|
30374
|
+
constructor(code, detail) {
|
|
29367
30375
|
super(code);
|
|
29368
30376
|
this.code = code;
|
|
30377
|
+
this.detail = detail;
|
|
29369
30378
|
this.name = "ScreenCaptureError";
|
|
29370
30379
|
}
|
|
29371
30380
|
code;
|
|
30381
|
+
detail;
|
|
29372
30382
|
};
|
|
29373
30383
|
var KNOWN = /^(SCREEN_UNAVAILABLE|SCREEN_LOCKED|SCREEN_ENCODER_UNAVAILABLE|SCREENSHOT_TOO_LARGE|ARGUMENT_INVALID)$/;
|
|
29374
30384
|
function jpegSize(data) {
|
|
@@ -29384,12 +30394,12 @@ function jpegSize(data) {
|
|
|
29384
30394
|
}
|
|
29385
30395
|
return null;
|
|
29386
30396
|
}
|
|
29387
|
-
function run(file2, args, signal, maxBuffer = 65536) {
|
|
30397
|
+
function run(file2, args, signal, maxBuffer = 65536, env = buildChildEnvironment(process.env, process.platform)) {
|
|
29388
30398
|
return new Promise((resolve, reject) => {
|
|
29389
30399
|
execFile4(
|
|
29390
30400
|
file2,
|
|
29391
30401
|
args,
|
|
29392
|
-
{ encoding: "buffer", timeout: 15e3, maxBuffer, windowsHide: true, shell: false, env
|
|
30402
|
+
{ encoding: "buffer", timeout: 15e3, maxBuffer, windowsHide: true, shell: false, env, signal },
|
|
29393
30403
|
(error62, stdout, stderr) => error62 ? reject(Object.assign(error62, { stdout, stderr })) : resolve({ stdout, stderr })
|
|
29394
30404
|
);
|
|
29395
30405
|
});
|
|
@@ -29454,11 +30464,141 @@ async function mac3(signal) {
|
|
|
29454
30464
|
});
|
|
29455
30465
|
}
|
|
29456
30466
|
}
|
|
30467
|
+
var SESSION_KEYS = ["DISPLAY", "WAYLAND_DISPLAY", "XAUTHORITY", "XDG_RUNTIME_DIR", "DBUS_SESSION_BUS_ADDRESS", "XDG_SESSION_TYPE", "XDG_CURRENT_DESKTOP"];
|
|
30468
|
+
var SESSION_VALUE = /^[A-Za-z0-9_.:,;=@+/-]{1,256}$/;
|
|
30469
|
+
var LINUX_SOURCE_BYTES = 150994944;
|
|
30470
|
+
async function linuxTool(name2) {
|
|
30471
|
+
for (const directory of ["/usr/bin", "/bin", "/usr/local/bin"]) {
|
|
30472
|
+
const file2 = path17.posix.join(directory, name2);
|
|
30473
|
+
try {
|
|
30474
|
+
await access3(file2, constants7.X_OK);
|
|
30475
|
+
return file2;
|
|
30476
|
+
} catch {
|
|
30477
|
+
}
|
|
30478
|
+
}
|
|
30479
|
+
return null;
|
|
30480
|
+
}
|
|
30481
|
+
async function linuxSession(signal) {
|
|
30482
|
+
const session = {}, uid = process.getuid?.();
|
|
30483
|
+
const take = (key, value) => {
|
|
30484
|
+
if (value && !session[key] && SESSION_VALUE.test(value)) session[key] = value;
|
|
30485
|
+
};
|
|
30486
|
+
const base = buildChildEnvironment(process.env, "linux");
|
|
30487
|
+
for (const key of SESSION_KEYS) take(key, process.env[key]);
|
|
30488
|
+
if (!session.DISPLAY && !session.WAYLAND_DISPLAY) {
|
|
30489
|
+
const systemctl = await linuxTool("systemctl");
|
|
30490
|
+
if (systemctl) try {
|
|
30491
|
+
const { stdout } = await run(systemctl, ["--user", "show-environment"], signal, 262144, base);
|
|
30492
|
+
for (const line of stdout.toString("utf8").split("\n")) {
|
|
30493
|
+
const at = line.indexOf("=");
|
|
30494
|
+
if (at > 0 && SESSION_KEYS.includes(line.slice(0, at))) take(line.slice(0, at), line.slice(at + 1));
|
|
30495
|
+
}
|
|
30496
|
+
} catch {
|
|
30497
|
+
if (signal.aborted) throw new ScreenCaptureError("CANCELLED");
|
|
30498
|
+
}
|
|
30499
|
+
}
|
|
30500
|
+
if (uid !== void 0) take("XDG_RUNTIME_DIR", "/run/user/" + uid);
|
|
30501
|
+
if (!session.DISPLAY && !session.WAYLAND_DISPLAY) {
|
|
30502
|
+
if (session.XDG_RUNTIME_DIR) for (const name2 of ["wayland-0", "wayland-1"]) {
|
|
30503
|
+
const socket = await lstat7(path17.posix.join(session.XDG_RUNTIME_DIR, name2)).catch(() => null);
|
|
30504
|
+
if (socket?.isSocket() && socket.uid === uid) {
|
|
30505
|
+
session.WAYLAND_DISPLAY = name2;
|
|
30506
|
+
break;
|
|
30507
|
+
}
|
|
30508
|
+
}
|
|
30509
|
+
if (!session.WAYLAND_DISPLAY) {
|
|
30510
|
+
const servers = [];
|
|
30511
|
+
for (const name2 of await readdir4("/tmp/.X11-unix").catch(() => [])) {
|
|
30512
|
+
const n = /^X(\d{1,4})$/.exec(name2)?.[1], socket = n ? await lstat7("/tmp/.X11-unix/" + name2).catch(() => null) : null;
|
|
30513
|
+
if (n && socket?.isSocket()) servers.push({ n: Number(n), own: socket.uid === uid });
|
|
30514
|
+
}
|
|
30515
|
+
const server = servers.sort((a, b) => Number(b.own) - Number(a.own) || a.n - b.n)[0];
|
|
30516
|
+
if (server) session.DISPLAY = ":" + server.n;
|
|
30517
|
+
}
|
|
30518
|
+
}
|
|
30519
|
+
if (session.DISPLAY && !session.XAUTHORITY) {
|
|
30520
|
+
const file2 = path17.posix.join(os4.homedir(), ".Xauthority");
|
|
30521
|
+
if ((await lstat7(file2).catch(() => null))?.isFile()) take("XAUTHORITY", file2);
|
|
30522
|
+
}
|
|
30523
|
+
if (session.XDG_RUNTIME_DIR) take("DBUS_SESSION_BUS_ADDRESS", "unix:path=" + session.XDG_RUNTIME_DIR + "/bus");
|
|
30524
|
+
const wayland = !!session.WAYLAND_DISPLAY || session.XDG_SESSION_TYPE === "wayland";
|
|
30525
|
+
return { env: { ...base, ...session }, wayland, x11: !wayland && !!session.DISPLAY };
|
|
30526
|
+
}
|
|
30527
|
+
async function busSocket(env) {
|
|
30528
|
+
const socket = sessionBusSocket(env.DBUS_SESSION_BUS_ADDRESS);
|
|
30529
|
+
if (!socket || socket.startsWith("\0")) return socket;
|
|
30530
|
+
return (await lstat7(socket).catch(() => null))?.isSocket() ? socket : null;
|
|
30531
|
+
}
|
|
30532
|
+
async function portalCapture(socket, signal) {
|
|
30533
|
+
const token = "lc" + randomBytes6(8).toString("hex"), started = Date.now(), uid = process.getuid?.();
|
|
30534
|
+
if (uid === void 0) throw new ScreenCaptureError("SCREEN_UNAVAILABLE");
|
|
30535
|
+
let answer;
|
|
30536
|
+
try {
|
|
30537
|
+
answer = await portalScreenshot(socket, uid, token, AbortSignal.any([signal, AbortSignal.timeout(3e4)]));
|
|
30538
|
+
} catch {
|
|
30539
|
+
throw new ScreenCaptureError(signal.aborted ? "CANCELLED" : "SCREEN_UNAVAILABLE");
|
|
30540
|
+
}
|
|
30541
|
+
const { code, uri } = answer;
|
|
30542
|
+
if (code === 1) throw new ScreenCaptureError("SCREEN_RECORDING_PERMISSION_REQUIRED");
|
|
30543
|
+
if (code !== 0 || !uri?.startsWith("file://")) throw new ScreenCaptureError("SCREEN_UNAVAILABLE");
|
|
30544
|
+
const file2 = decodeURIComponent(new URL(uri).pathname), info = await lstat7(file2);
|
|
30545
|
+
const fresh = info.isFile() && info.uid === uid && info.mtimeMs >= started - 5e3;
|
|
30546
|
+
try {
|
|
30547
|
+
if (!fresh || info.size > LINUX_SOURCE_BYTES) throw new ScreenCaptureError("SCREEN_UNAVAILABLE");
|
|
30548
|
+
return await readFile6(file2);
|
|
30549
|
+
} finally {
|
|
30550
|
+
if (fresh) await unlink2(file2).catch(() => {
|
|
30551
|
+
});
|
|
30552
|
+
}
|
|
30553
|
+
}
|
|
30554
|
+
async function linux(signal) {
|
|
30555
|
+
const session = await linuxSession(signal);
|
|
30556
|
+
if (!session.wayland && !session.x11) throw new ScreenCaptureError("SCREENSHOT_UNSUPPORTED", { reason: "NO_DISPLAY" });
|
|
30557
|
+
const output2 = (args) => async (tool) => (await run(tool, args, signal, LINUX_SOURCE_BYTES, session.env)).stdout;
|
|
30558
|
+
const portal = (socket) => portalCapture(socket, signal);
|
|
30559
|
+
const methods = session.wayland ? [["grim", "grim", output2(["-t", "png", "-"])], ["portal", "", portal]] : [
|
|
30560
|
+
["xwd", "xwd", output2(["-root", "-silent"])],
|
|
30561
|
+
["import", "import", output2(["-silent", "-window", "root", "png:-"])],
|
|
30562
|
+
["maim", "maim", output2(["-f", "png"])],
|
|
30563
|
+
["portal", "", portal]
|
|
30564
|
+
];
|
|
30565
|
+
const tried = [];
|
|
30566
|
+
for (const [name2, program, capture2] of methods) {
|
|
30567
|
+
const tool = program ? await linuxTool(program) : await busSocket(session.env);
|
|
30568
|
+
if (!tool) {
|
|
30569
|
+
tried.push(name2 + ":missing");
|
|
30570
|
+
continue;
|
|
30571
|
+
}
|
|
30572
|
+
let image;
|
|
30573
|
+
try {
|
|
30574
|
+
const source = await capture2(tool);
|
|
30575
|
+
image = decodePng(source) ?? decodeXwd(source);
|
|
30576
|
+
} catch (error62) {
|
|
30577
|
+
if (signal.aborted) throw new ScreenCaptureError("CANCELLED");
|
|
30578
|
+
if (error62 instanceof ScreenCaptureError && error62.code === "SCREEN_RECORDING_PERMISSION_REQUIRED") throw error62;
|
|
30579
|
+
tried.push(name2 + ":failed");
|
|
30580
|
+
continue;
|
|
30581
|
+
}
|
|
30582
|
+
if (!image) {
|
|
30583
|
+
tried.push(name2 + ":unreadable");
|
|
30584
|
+
continue;
|
|
30585
|
+
}
|
|
30586
|
+
const fitted = fitJpeg(image, SCREENSHOT_MAX_EDGE, SCREENSHOT_MAX_JPEG_BYTES);
|
|
30587
|
+
if (!fitted) throw new ScreenCaptureError("SCREENSHOT_TOO_LARGE");
|
|
30588
|
+
return { ...fitted, sourceWidth: image.width, sourceHeight: image.height };
|
|
30589
|
+
}
|
|
30590
|
+
throw new ScreenCaptureError("SCREENSHOT_UNSUPPORTED", {
|
|
30591
|
+
reason: tried.every((entry) => entry.endsWith(":missing")) ? "NO_CAPTURE_TOOL" : "CAPTURE_FAILED",
|
|
30592
|
+
session: session.wayland ? "wayland" : "x11",
|
|
30593
|
+
tried
|
|
30594
|
+
});
|
|
30595
|
+
}
|
|
29457
30596
|
async function captureScreen(options) {
|
|
29458
30597
|
if (options.signal.aborted) throw new ScreenCaptureError("CANCELLED");
|
|
29459
30598
|
if (process.platform === "win32") return windows(options.ownerBridgePath, options.signal);
|
|
29460
30599
|
if (process.platform === "darwin") return mac3(options.signal);
|
|
29461
|
-
|
|
30600
|
+
if (process.platform === "linux") return linux(options.signal);
|
|
30601
|
+
throw new ScreenCaptureError("SCREENSHOT_UNSUPPORTED", { reason: "PLATFORM_UNSUPPORTED" });
|
|
29462
30602
|
}
|
|
29463
30603
|
|
|
29464
30604
|
// agent/src/tools.ts
|
|
@@ -29491,7 +30631,7 @@ function stopped(signal) {
|
|
|
29491
30631
|
if (signal.aborted) fail3("CANCELLED");
|
|
29492
30632
|
}
|
|
29493
30633
|
async function readBoundedFile(file2, maxBytes, bridge, signal) {
|
|
29494
|
-
const stat2 = await
|
|
30634
|
+
const stat2 = await lstat8(file2);
|
|
29495
30635
|
if (!stat2.isFile() || stat2.isSymbolicLink() || stat2.size > maxBytes) fail3("FILE_UNSUPPORTED_OR_TOO_LARGE");
|
|
29496
30636
|
if (process.platform === "win32") {
|
|
29497
30637
|
if (maxBytes <= 1048576 || stat2.size <= 1048576) return readWindowsFile(bridge, file2, Math.min(maxBytes, 1048576), signal);
|
|
@@ -29499,7 +30639,7 @@ async function readBoundedFile(file2, maxBytes, bridge, signal) {
|
|
|
29499
30639
|
if (read.truncated) fail3("FILE_UNSUPPORTED_OR_TOO_LARGE");
|
|
29500
30640
|
return read.data;
|
|
29501
30641
|
}
|
|
29502
|
-
const handle = await open6(file2,
|
|
30642
|
+
const handle = await open6(file2, constants8.O_RDONLY | (constants8.O_NOFOLLOW ?? 0));
|
|
29503
30643
|
try {
|
|
29504
30644
|
const current2 = await handle.stat();
|
|
29505
30645
|
if (!current2.isFile() || current2.size > maxBytes) fail3("FILE_UNSUPPORTED_OR_TOO_LARGE");
|
|
@@ -29754,7 +30894,7 @@ var NativeTools = class {
|
|
|
29754
30894
|
}
|
|
29755
30895
|
if (bytes3.length > MAX_FILE_WRITE_BYTES) fail3("FILE_WRITE_LIMIT");
|
|
29756
30896
|
const temp = path18.join(path18.dirname(target), ".lc-write-" + randomUUID7() + ".tmp");
|
|
29757
|
-
const handle = await open6(temp,
|
|
30897
|
+
const handle = await open6(temp, constants8.O_CREAT | constants8.O_EXCL | constants8.O_WRONLY, 384);
|
|
29758
30898
|
try {
|
|
29759
30899
|
await handle.writeFile(bytes3);
|
|
29760
30900
|
await handle.sync();
|
|
@@ -29770,7 +30910,7 @@ var NativeTools = class {
|
|
|
29770
30910
|
break;
|
|
29771
30911
|
} catch (error62) {
|
|
29772
30912
|
if (process.platform !== "win32" || !["EPERM", "EBUSY", "EACCES"].includes(error62.code ?? "")) throw error62;
|
|
29773
|
-
if (attempt === 4) fail3((await
|
|
30913
|
+
if (attempt === 4) fail3((await lstat8(target)).mode & 128 ? "FILE_IN_USE" : "FILE_READ_ONLY");
|
|
29774
30914
|
await delay2(50 << attempt);
|
|
29775
30915
|
stopped(signal);
|
|
29776
30916
|
}
|
|
@@ -29886,14 +31026,26 @@ var NativeTools = class {
|
|
|
29886
31026
|
} };
|
|
29887
31027
|
}
|
|
29888
31028
|
if (call.name === "take_screenshot") {
|
|
29889
|
-
if (!screenshotEnabled() && !await
|
|
31029
|
+
if (!screenshotEnabled() && !await lstat8(path18.join(this.options.stateDirectory, SCREENSHOT_ACCEPTANCE_FILE)).then((s) => s.isFile(), () => false)) fail3("SCREENSHOT_DISABLED");
|
|
29890
31030
|
if (!workspace2.fullAccess) fail3("FULL_ACCESS_REQUIRED");
|
|
31031
|
+
if (await lstat8(path18.join(this.options.stateDirectory, SCREENSHOT_OWNER_OFF_FILE)).then(() => true, (error62) => error62.code !== "ENOENT")) fail3("SCREENSHOT_DISABLED_BY_OWNER");
|
|
29891
31032
|
const bridge = this.options.ownerBridgePath ?? path18.join(path18.dirname(this.options.helperPath), "OwnerBridge.exe");
|
|
29892
31033
|
return { call, claims: [{ path: path18.join(this.options.stateDirectory, "screen-capture"), mode: "read" }], run: async (signal) => {
|
|
29893
31034
|
let shot;
|
|
29894
31035
|
try {
|
|
29895
31036
|
shot = await captureScreen({ ownerBridgePath: bridge, signal });
|
|
29896
31037
|
} catch (error62) {
|
|
31038
|
+
if (error62 instanceof ScreenCaptureError && error62.detail) return {
|
|
31039
|
+
exitCode: 1,
|
|
31040
|
+
timedOut: false,
|
|
31041
|
+
cancelled: false,
|
|
31042
|
+
treeTerminated: true,
|
|
31043
|
+
stdout: JSON.stringify({ type: "screenshot_error", resultCode: error62.code, ...error62.detail }),
|
|
31044
|
+
stderr: "",
|
|
31045
|
+
stdoutTruncated: false,
|
|
31046
|
+
stderrTruncated: false,
|
|
31047
|
+
resultCode: error62.code
|
|
31048
|
+
};
|
|
29897
31049
|
fail3(error62 instanceof Error && /^[A-Z_]{1,40}$/.test(error62.message) ? error62.message : "SCREEN_UNAVAILABLE");
|
|
29898
31050
|
}
|
|
29899
31051
|
return result({
|
|
@@ -30057,7 +31209,7 @@ var NativeTools = class {
|
|
|
30057
31209
|
)?.file : void 0);
|
|
30058
31210
|
if (!candidate || !path18.isAbsolute(candidate)) fail3("COMMAND_NOT_FOUND");
|
|
30059
31211
|
const executable = await realpath7(candidate).catch(() => fail3("COMMAND_NOT_FOUND"));
|
|
30060
|
-
if (!(await
|
|
31212
|
+
if (!(await lstat8(executable)).isFile()) fail3("COMMAND_NOT_FOUND");
|
|
30061
31213
|
if (denied.has(commandKey(executable))) fail3("COMMAND_NOT_ALLOWED");
|
|
30062
31214
|
for (const key of workspace2.deniedCommands ?? []) {
|
|
30063
31215
|
const configured = this.options.programs[key]?.executable;
|
|
@@ -30099,7 +31251,7 @@ var NativeTools = class {
|
|
|
30099
31251
|
const candidate = process.platform === "win32" ? source : await resolvePosixExecutable(source);
|
|
30100
31252
|
if (!candidate) continue;
|
|
30101
31253
|
try {
|
|
30102
|
-
const stat2 = await
|
|
31254
|
+
const stat2 = await lstat8(candidate);
|
|
30103
31255
|
if (!stat2.isFile() || stat2.isSymbolicLink() || !equalPath3(candidate, await realpath7(candidate))) continue;
|
|
30104
31256
|
} catch {
|
|
30105
31257
|
continue;
|
|
@@ -30117,7 +31269,7 @@ var NativeTools = class {
|
|
|
30117
31269
|
const current2 = queue.shift();
|
|
30118
31270
|
let names;
|
|
30119
31271
|
try {
|
|
30120
|
-
names = await
|
|
31272
|
+
names = await readdir5(current2.path, { withFileTypes: true });
|
|
30121
31273
|
} catch (error62) {
|
|
30122
31274
|
if (current2.level === 0) throw error62;
|
|
30123
31275
|
continue;
|
|
@@ -30142,7 +31294,7 @@ var NativeTools = class {
|
|
|
30142
31294
|
entries.push({ path: path18.relative(root, resolved), type: "directory" });
|
|
30143
31295
|
if (current2.level < depth) queue.push({ path: resolved, level: current2.level + 1 });
|
|
30144
31296
|
} else if (item.isFile()) {
|
|
30145
|
-
const stat2 = await
|
|
31297
|
+
const stat2 = await lstat8(resolved).catch(() => null);
|
|
30146
31298
|
if (stat2) entries.push({ path: path18.relative(root, resolved), type: "file", size: stat2.size });
|
|
30147
31299
|
}
|
|
30148
31300
|
}
|
|
@@ -30155,7 +31307,7 @@ var NativeTools = class {
|
|
|
30155
31307
|
while (guard.isWithin(directory, workspace2.root)) {
|
|
30156
31308
|
const dotGit = path18.join(directory, ".git");
|
|
30157
31309
|
try {
|
|
30158
|
-
const stat2 = await
|
|
31310
|
+
const stat2 = await lstat8(dotGit);
|
|
30159
31311
|
if (stat2.isSymbolicLink()) fail3("GIT_METADATA_CHANGED");
|
|
30160
31312
|
let gitDir;
|
|
30161
31313
|
if (stat2.isDirectory()) gitDir = await realpath7(dotGit);
|
|
@@ -30173,7 +31325,7 @@ var NativeTools = class {
|
|
|
30173
31325
|
} catch (e) {
|
|
30174
31326
|
if (e.code !== "ENOENT") throw e;
|
|
30175
31327
|
}
|
|
30176
|
-
if (!(await
|
|
31328
|
+
if (!(await lstat8(common)).isDirectory() || guard.isWithin(common, this.options.stateDirectory)) fail3("GIT_METADATA_CHANGED");
|
|
30177
31329
|
if (!guard.isWithin(common, workspace2.root) && (!workspace2.gitCommonDir || !equalPath3(common, workspace2.gitCommonDir))) fail3("GIT_COMMON_DIRECTORY_NOT_APPROVED");
|
|
30178
31330
|
return common;
|
|
30179
31331
|
} catch (e) {
|
|
@@ -30929,7 +32081,45 @@ function journalBinding(entry, binding2) {
|
|
|
30929
32081
|
function journalResult(value, code) {
|
|
30930
32082
|
return { ...value, resultCode: code ?? (value.treeTerminated ? value.cancelled ? "CANCELLED" : value.timedOut ? "TIMEOUT" : value.exitCode === 0 ? "SUCCESS" : "USER_PROGRAM_FAILED" : "EXECUTION_UNKNOWN") };
|
|
30931
32083
|
}
|
|
30932
|
-
var knownCodes = /* @__PURE__ */ new Set([
|
|
32084
|
+
var knownCodes = /* @__PURE__ */ new Set([
|
|
32085
|
+
"PROJECT_IDENTITY_UNKNOWN",
|
|
32086
|
+
"PROJECT_IDENTITY_MISMATCH",
|
|
32087
|
+
"INVALID_TOOL_ARGUMENTS",
|
|
32088
|
+
"LOCAL_PERMISSION_REQUIRED",
|
|
32089
|
+
"PATH_NOT_ALLOWED",
|
|
32090
|
+
"FILE_CHANGED",
|
|
32091
|
+
"FILE_NOT_FOUND",
|
|
32092
|
+
"FILE_ALREADY_EXISTS",
|
|
32093
|
+
"REPLACEMENT_NOT_UNIQUE",
|
|
32094
|
+
"OUTPUT_LIMIT_EXCEEDED",
|
|
32095
|
+
"BINARY_FILE_NOT_SUPPORTED",
|
|
32096
|
+
"FILE_UNSUPPORTED_OR_TOO_LARGE",
|
|
32097
|
+
"INVALID_LINE_RANGE",
|
|
32098
|
+
"FILE_IN_USE",
|
|
32099
|
+
"FILE_READ_ONLY",
|
|
32100
|
+
"FILE_WRITE_LIMIT",
|
|
32101
|
+
"GIT_METADATA_CHANGED",
|
|
32102
|
+
"GIT_COMMON_DIRECTORY_NOT_APPROVED",
|
|
32103
|
+
"GIT_NOT_INSTALLED",
|
|
32104
|
+
"LOCALHOST_NOT_ALLOWED",
|
|
32105
|
+
"COMMAND_NOT_ALLOWED",
|
|
32106
|
+
"WORKSPACE_CHANGED",
|
|
32107
|
+
"WORKSPACE_UNAVAILABLE",
|
|
32108
|
+
"RESOURCE_BUSY",
|
|
32109
|
+
"AGENT_PAUSED",
|
|
32110
|
+
"CANCELLED_BEFORE_ACCEPTANCE",
|
|
32111
|
+
"ADMISSION_DEADLINE_EXPIRED",
|
|
32112
|
+
// take_screenshot refusals (#434, #486): without these the client sees TOOL_FAILED.
|
|
32113
|
+
"FULL_ACCESS_REQUIRED",
|
|
32114
|
+
"SCREENSHOT_DISABLED",
|
|
32115
|
+
"SCREENSHOT_DISABLED_BY_OWNER",
|
|
32116
|
+
"SCREENSHOT_UNSUPPORTED",
|
|
32117
|
+
"SCREENSHOT_TOO_LARGE",
|
|
32118
|
+
"SCREEN_UNAVAILABLE",
|
|
32119
|
+
"SCREEN_LOCKED",
|
|
32120
|
+
"SCREEN_ENCODER_UNAVAILABLE",
|
|
32121
|
+
"SCREEN_RECORDING_PERMISSION_REQUIRED"
|
|
32122
|
+
]);
|
|
30933
32123
|
function safeCode(error62) {
|
|
30934
32124
|
const code = error62 instanceof NativeToolError ? error62.code : error62 instanceof Error ? error62.message : "";
|
|
30935
32125
|
return knownCodes.has(code) || /^GUARD_[A-Z_]{1,30}$/.test(code) ? code : "TOOL_FAILED";
|
|
@@ -31362,9 +32552,9 @@ var NativeRelayBridge = class {
|
|
|
31362
32552
|
};
|
|
31363
32553
|
|
|
31364
32554
|
// agent/src/local-direct.ts
|
|
31365
|
-
import
|
|
32555
|
+
import net2 from "node:net";
|
|
31366
32556
|
import path20 from "node:path";
|
|
31367
|
-
import { createHmac as createHmac2, hkdfSync, randomBytes as
|
|
32557
|
+
import { createHmac as createHmac2, hkdfSync, randomBytes as randomBytes7, randomUUID as randomUUID8, timingSafeEqual as timingSafeEqual3 } from "node:crypto";
|
|
31368
32558
|
import { mkdir as mkdir7, readFile as readFile8, rename as rename5, rm as rm7, writeFile as writeFile3 } from "node:fs/promises";
|
|
31369
32559
|
var LocalDirectError = class extends Error {
|
|
31370
32560
|
constructor(code) {
|
|
@@ -31401,7 +32591,7 @@ function sameProof(candidate, expected) {
|
|
|
31401
32591
|
const a = Buffer.from(candidate), b = Buffer.from(expected);
|
|
31402
32592
|
return a.length === b.length && timingSafeEqual3(a, b);
|
|
31403
32593
|
}
|
|
31404
|
-
var nonce = () =>
|
|
32594
|
+
var nonce = () => randomBytes7(32).toString("base64url");
|
|
31405
32595
|
var NONCE = /^[A-Za-z0-9_-]{43}$/;
|
|
31406
32596
|
function codeOf(error62) {
|
|
31407
32597
|
const code = error62 instanceof NativeToolError || error62 instanceof LocalDirectError ? error62.code : error62 instanceof Error ? error62.message : "";
|
|
@@ -31483,7 +32673,7 @@ var LocalDirectServer = class _LocalDirectServer {
|
|
|
31483
32673
|
});
|
|
31484
32674
|
return null;
|
|
31485
32675
|
}
|
|
31486
|
-
const server =
|
|
32676
|
+
const server = net2.createServer(), self = new _LocalDirectServer(server, options);
|
|
31487
32677
|
server.on("connection", (socket) => self.accept(socket));
|
|
31488
32678
|
await new Promise((resolve, reject) => {
|
|
31489
32679
|
server.once("error", reject);
|
|
@@ -31640,7 +32830,7 @@ var LocalDirectClient = class _LocalDirectClient {
|
|
|
31640
32830
|
static async connect(options) {
|
|
31641
32831
|
if (!await localDirectEnabled(options.directory)) fail4("LOCAL_ACCESS_DISABLED");
|
|
31642
32832
|
const endpoint2 = await readEndpoint(options.directory);
|
|
31643
|
-
const socket =
|
|
32833
|
+
const socket = net2.createConnection({ host: "127.0.0.1", port: endpoint2.port });
|
|
31644
32834
|
let handler = () => {
|
|
31645
32835
|
};
|
|
31646
32836
|
const lines = new Lines(socket, (frame) => handler(frame));
|
|
@@ -37163,8 +38353,8 @@ var require_content_type = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
37163
38353
|
var PARAM_REGEXP = /; *([!#$%&'*+.^_`|~0-9A-Za-z-]+) *= *("(?:[\u000b\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u000b\u0020-\u00ff])*"|[!#$%&'*+.^_`|~0-9A-Za-z-]+) */g;
|
|
37164
38354
|
var QESC_REGEXP = /\\([\u000b\u0020-\u00ff])/g;
|
|
37165
38355
|
var TYPE_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
37166
|
-
exports.parse =
|
|
37167
|
-
function
|
|
38356
|
+
exports.parse = parse4;
|
|
38357
|
+
function parse4(string4) {
|
|
37168
38358
|
if (!string4) throw new TypeError("argument string is required");
|
|
37169
38359
|
var header = typeof string4 === "object" ? getcontenttype(string4) : string4;
|
|
37170
38360
|
if (typeof header !== "string") throw new TypeError("argument string is required to be a string");
|
|
@@ -37688,9 +38878,9 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
37688
38878
|
const rhs = this.rhs === void 0 ? "" : ` = ${this.rhs}`;
|
|
37689
38879
|
return `${varKind} ${this.name}${rhs};` + _n;
|
|
37690
38880
|
}
|
|
37691
|
-
optimizeNames(names,
|
|
38881
|
+
optimizeNames(names, constants11) {
|
|
37692
38882
|
if (!names[this.name.str]) return;
|
|
37693
|
-
if (this.rhs) this.rhs = optimizeExpr(this.rhs, names,
|
|
38883
|
+
if (this.rhs) this.rhs = optimizeExpr(this.rhs, names, constants11);
|
|
37694
38884
|
return this;
|
|
37695
38885
|
}
|
|
37696
38886
|
get names() {
|
|
@@ -37707,9 +38897,9 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
37707
38897
|
render({ _n }) {
|
|
37708
38898
|
return `${this.lhs} = ${this.rhs};` + _n;
|
|
37709
38899
|
}
|
|
37710
|
-
optimizeNames(names,
|
|
38900
|
+
optimizeNames(names, constants11) {
|
|
37711
38901
|
if (this.lhs instanceof code_1.Name && !names[this.lhs.str] && !this.sideEffects) return;
|
|
37712
|
-
this.rhs = optimizeExpr(this.rhs, names,
|
|
38902
|
+
this.rhs = optimizeExpr(this.rhs, names, constants11);
|
|
37713
38903
|
return this;
|
|
37714
38904
|
}
|
|
37715
38905
|
get names() {
|
|
@@ -37768,8 +38958,8 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
37768
38958
|
optimizeNodes() {
|
|
37769
38959
|
return `${this.code}` ? this : void 0;
|
|
37770
38960
|
}
|
|
37771
|
-
optimizeNames(names,
|
|
37772
|
-
this.code = optimizeExpr(this.code, names,
|
|
38961
|
+
optimizeNames(names, constants11) {
|
|
38962
|
+
this.code = optimizeExpr(this.code, names, constants11);
|
|
37773
38963
|
return this;
|
|
37774
38964
|
}
|
|
37775
38965
|
get names() {
|
|
@@ -37795,12 +38985,12 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
37795
38985
|
}
|
|
37796
38986
|
return nodes.length > 0 ? this : void 0;
|
|
37797
38987
|
}
|
|
37798
|
-
optimizeNames(names,
|
|
38988
|
+
optimizeNames(names, constants11) {
|
|
37799
38989
|
const { nodes } = this;
|
|
37800
38990
|
let i = nodes.length;
|
|
37801
38991
|
while (i--) {
|
|
37802
38992
|
const n = nodes[i];
|
|
37803
|
-
if (n.optimizeNames(names,
|
|
38993
|
+
if (n.optimizeNames(names, constants11)) continue;
|
|
37804
38994
|
subtractNames(names, n.names);
|
|
37805
38995
|
nodes.splice(i, 1);
|
|
37806
38996
|
}
|
|
@@ -37847,11 +39037,11 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
37847
39037
|
if (cond === false || !this.nodes.length) return void 0;
|
|
37848
39038
|
return this;
|
|
37849
39039
|
}
|
|
37850
|
-
optimizeNames(names,
|
|
39040
|
+
optimizeNames(names, constants11) {
|
|
37851
39041
|
var _a3;
|
|
37852
|
-
this.else = (_a3 = this.else) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names,
|
|
37853
|
-
if (!(super.optimizeNames(names,
|
|
37854
|
-
this.condition = optimizeExpr(this.condition, names,
|
|
39042
|
+
this.else = (_a3 = this.else) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names, constants11);
|
|
39043
|
+
if (!(super.optimizeNames(names, constants11) || this.else)) return;
|
|
39044
|
+
this.condition = optimizeExpr(this.condition, names, constants11);
|
|
37855
39045
|
return this;
|
|
37856
39046
|
}
|
|
37857
39047
|
get names() {
|
|
@@ -37873,9 +39063,9 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
37873
39063
|
render(opts) {
|
|
37874
39064
|
return `for(${this.iteration})` + super.render(opts);
|
|
37875
39065
|
}
|
|
37876
|
-
optimizeNames(names,
|
|
37877
|
-
if (!super.optimizeNames(names,
|
|
37878
|
-
this.iteration = optimizeExpr(this.iteration, names,
|
|
39066
|
+
optimizeNames(names, constants11) {
|
|
39067
|
+
if (!super.optimizeNames(names, constants11)) return;
|
|
39068
|
+
this.iteration = optimizeExpr(this.iteration, names, constants11);
|
|
37879
39069
|
return this;
|
|
37880
39070
|
}
|
|
37881
39071
|
get names() {
|
|
@@ -37910,9 +39100,9 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
37910
39100
|
render(opts) {
|
|
37911
39101
|
return `for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})` + super.render(opts);
|
|
37912
39102
|
}
|
|
37913
|
-
optimizeNames(names,
|
|
37914
|
-
if (!super.optimizeNames(names,
|
|
37915
|
-
this.iterable = optimizeExpr(this.iterable, names,
|
|
39103
|
+
optimizeNames(names, constants11) {
|
|
39104
|
+
if (!super.optimizeNames(names, constants11)) return;
|
|
39105
|
+
this.iterable = optimizeExpr(this.iterable, names, constants11);
|
|
37916
39106
|
return this;
|
|
37917
39107
|
}
|
|
37918
39108
|
get names() {
|
|
@@ -37951,11 +39141,11 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
37951
39141
|
(_b = this.finally) === null || _b === void 0 || _b.optimizeNodes();
|
|
37952
39142
|
return this;
|
|
37953
39143
|
}
|
|
37954
|
-
optimizeNames(names,
|
|
39144
|
+
optimizeNames(names, constants11) {
|
|
37955
39145
|
var _a3, _b;
|
|
37956
|
-
super.optimizeNames(names,
|
|
37957
|
-
(_a3 = this.catch) === null || _a3 === void 0 || _a3.optimizeNames(names,
|
|
37958
|
-
(_b = this.finally) === null || _b === void 0 || _b.optimizeNames(names,
|
|
39146
|
+
super.optimizeNames(names, constants11);
|
|
39147
|
+
(_a3 = this.catch) === null || _a3 === void 0 || _a3.optimizeNames(names, constants11);
|
|
39148
|
+
(_b = this.finally) === null || _b === void 0 || _b.optimizeNames(names, constants11);
|
|
37959
39149
|
return this;
|
|
37960
39150
|
}
|
|
37961
39151
|
get names() {
|
|
@@ -38204,7 +39394,7 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
38204
39394
|
function addExprNames(names, from) {
|
|
38205
39395
|
return from instanceof code_1._CodeOrName ? addNames(names, from.names) : names;
|
|
38206
39396
|
}
|
|
38207
|
-
function optimizeExpr(expr, names,
|
|
39397
|
+
function optimizeExpr(expr, names, constants11) {
|
|
38208
39398
|
if (expr instanceof code_1.Name) return replaceName(expr);
|
|
38209
39399
|
if (!canOptimize(expr)) return expr;
|
|
38210
39400
|
return new code_1._Code(expr._items.reduce((items, c) => {
|
|
@@ -38214,13 +39404,13 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
38214
39404
|
return items;
|
|
38215
39405
|
}, []));
|
|
38216
39406
|
function replaceName(n) {
|
|
38217
|
-
const c =
|
|
39407
|
+
const c = constants11[n.str];
|
|
38218
39408
|
if (c === void 0 || names[n.str] !== 1) return n;
|
|
38219
39409
|
delete names[n.str];
|
|
38220
39410
|
return c;
|
|
38221
39411
|
}
|
|
38222
39412
|
function canOptimize(e) {
|
|
38223
|
-
return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 &&
|
|
39413
|
+
return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 && constants11[c.str] !== void 0);
|
|
38224
39414
|
}
|
|
38225
39415
|
}
|
|
38226
39416
|
function subtractNames(names, from) {
|
|
@@ -40352,21 +41542,21 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
40352
41542
|
const { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizeComponentEncoding, isIPv4, nonSimpleDomain } = require_utils();
|
|
40353
41543
|
const { SCHEMES, getSchemeHandler } = require_schemes();
|
|
40354
41544
|
function normalize(uri, options) {
|
|
40355
|
-
if (typeof uri === "string") uri = serialize(
|
|
40356
|
-
else if (typeof uri === "object") uri =
|
|
41545
|
+
if (typeof uri === "string") uri = serialize(parse4(uri, options), options);
|
|
41546
|
+
else if (typeof uri === "object") uri = parse4(serialize(uri, options), options);
|
|
40357
41547
|
return uri;
|
|
40358
41548
|
}
|
|
40359
41549
|
function resolve(baseURI, relativeURI, options) {
|
|
40360
41550
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
40361
|
-
const resolved = resolveComponent(
|
|
41551
|
+
const resolved = resolveComponent(parse4(baseURI, schemelessOptions), parse4(relativeURI, schemelessOptions), schemelessOptions, true);
|
|
40362
41552
|
schemelessOptions.skipEscape = true;
|
|
40363
41553
|
return serialize(resolved, schemelessOptions);
|
|
40364
41554
|
}
|
|
40365
41555
|
function resolveComponent(base, relative, options, skipNormalization) {
|
|
40366
41556
|
const target = {};
|
|
40367
41557
|
if (!skipNormalization) {
|
|
40368
|
-
base =
|
|
40369
|
-
relative =
|
|
41558
|
+
base = parse4(serialize(base, options), options);
|
|
41559
|
+
relative = parse4(serialize(relative, options), options);
|
|
40370
41560
|
}
|
|
40371
41561
|
options = options || {};
|
|
40372
41562
|
if (!options.tolerant && relative.scheme) {
|
|
@@ -40410,7 +41600,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
40410
41600
|
function equal(uriA, uriB, options) {
|
|
40411
41601
|
if (typeof uriA === "string") {
|
|
40412
41602
|
uriA = unescape(uriA);
|
|
40413
|
-
uriA = serialize(normalizeComponentEncoding(
|
|
41603
|
+
uriA = serialize(normalizeComponentEncoding(parse4(uriA, options), true), {
|
|
40414
41604
|
...options,
|
|
40415
41605
|
skipEscape: true
|
|
40416
41606
|
});
|
|
@@ -40420,7 +41610,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
40420
41610
|
});
|
|
40421
41611
|
if (typeof uriB === "string") {
|
|
40422
41612
|
uriB = unescape(uriB);
|
|
40423
|
-
uriB = serialize(normalizeComponentEncoding(
|
|
41613
|
+
uriB = serialize(normalizeComponentEncoding(parse4(uriB, options), true), {
|
|
40424
41614
|
...options,
|
|
40425
41615
|
skipEscape: true
|
|
40426
41616
|
});
|
|
@@ -40473,7 +41663,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
40473
41663
|
return uriTokens.join("");
|
|
40474
41664
|
}
|
|
40475
41665
|
const URI_PARSE = /^(?:([^#/:?]+):)?(?:\/\/((?:([^#/?@]*)@)?(\[[^#/?\]]+\]|[^#/:?]*)(?::(\d*))?))?([^#?]*)(?:\?([^#]*))?(?:#((?:.|[\n\r])*))?/u;
|
|
40476
|
-
function
|
|
41666
|
+
function parse4(uri, opts) {
|
|
40477
41667
|
const options = Object.assign({}, opts);
|
|
40478
41668
|
const parsed = {
|
|
40479
41669
|
scheme: void 0,
|
|
@@ -40534,7 +41724,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
40534
41724
|
resolveComponent,
|
|
40535
41725
|
equal,
|
|
40536
41726
|
serialize,
|
|
40537
|
-
parse:
|
|
41727
|
+
parse: parse4
|
|
40538
41728
|
};
|
|
40539
41729
|
module.exports = fastUri;
|
|
40540
41730
|
module.exports.default = fastUri;
|
|
@@ -45814,7 +47004,7 @@ var DESCRIPTIONS = {
|
|
|
45814
47004
|
git_log: ["Recent Git commits of the repository at a workspace-relative path.", { readOnlyHint: true, openWorldHint: false }],
|
|
45815
47005
|
project_snapshot: ["Compact project overview: Git state and, with startup, AGENTS.md policy and task continuation.", { readOnlyHint: true, openWorldHint: false }],
|
|
45816
47006
|
command_run: ["Run one executable with an argument array (no shell parsing), hidden, with captured output. Uses this user account's rights within the owner's grant.", { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true }],
|
|
45817
|
-
take_screenshot: ["Take a still image of this computer's primary screen, returned as a JPEG image. Needs a Full Access workspace; the lock screen is never captured.", { readOnlyHint: true, openWorldHint: false }],
|
|
47007
|
+
take_screenshot: ["Take a still image of this computer's primary screen, returned as a JPEG image. It contains everything visible on the screen, including any open passwords, keys or private messages. Needs a Full Access workspace; the lock screen is never captured.", { readOnlyHint: true, openWorldHint: false }],
|
|
45818
47008
|
localhost_request: ["HTTP request to a service on this computer (localhost only).", { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false }]
|
|
45819
47009
|
};
|
|
45820
47010
|
var workspace = external_exports.string().min(1).max(4096).optional().describe("Workspace grant id, root path (for example D:\\) or display name from workspace_list. Optional when only one workspace is approved.");
|
|
@@ -46336,6 +47526,7 @@ async function connectOnce(options) {
|
|
|
46336
47526
|
const incidents = Array.isArray(readyFrame.capabilities) && readyFrame.capabilities.includes("incidentBatchV1");
|
|
46337
47527
|
const monitorHeartbeat = Array.isArray(readyFrame.capabilities) && readyFrame.capabilities.includes("monitorHeartbeatV1") && typeof readyFrame.heartbeatMs === "number" && Number.isInteger(readyFrame.heartbeatMs) && readyFrame.heartbeatMs >= 1e3 && readyFrame.heartbeatMs <= 6e4 ? readyFrame.heartbeatMs : void 0;
|
|
46338
47528
|
const nativeStatus = Array.isArray(readyFrame.capabilities) && readyFrame.capabilities.includes(NATIVE_STATUS_CAPABILITY) && options.status;
|
|
47529
|
+
const accessModes = Array.isArray(readyFrame.capabilities) && readyFrame.capabilities.includes(WORKSPACE_ACCESS_MODE_CAPABILITY);
|
|
46339
47530
|
const reportStatus = () => {
|
|
46340
47531
|
if (!nativeStatus) return;
|
|
46341
47532
|
const { safeSlots, active, queued, paused } = nativeStatus();
|
|
@@ -46562,7 +47753,16 @@ async function connectOnce(options) {
|
|
|
46562
47753
|
registerWorkspace: (workspace2) => {
|
|
46563
47754
|
if (pendingWorkspace.size >= 32) return Promise.reject(new RelayClientError("RELAY_PENDING_LIMIT"));
|
|
46564
47755
|
const requestId = randomUUID10();
|
|
46565
|
-
const event = {
|
|
47756
|
+
const event = {
|
|
47757
|
+
type: "workspace_grant",
|
|
47758
|
+
version: 1,
|
|
47759
|
+
requestId,
|
|
47760
|
+
workspaceGrantId: workspace2.workspaceGrantId,
|
|
47761
|
+
rootHash: workspace2.rootHash,
|
|
47762
|
+
displayName: workspace2.displayName,
|
|
47763
|
+
policyVersion: workspace2.policyVersion,
|
|
47764
|
+
...accessModes ? { accessMode: workspace2.fullAccess === true ? "full" : "scoped" } : {}
|
|
47765
|
+
};
|
|
46566
47766
|
return new Promise((resolve, reject) => {
|
|
46567
47767
|
const timer = setTimeout(() => {
|
|
46568
47768
|
pendingWorkspace.delete(requestId);
|
|
@@ -46611,14 +47811,14 @@ import { spawn as spawn5 } from "node:child_process";
|
|
|
46611
47811
|
import { createHash as createHash16 } from "node:crypto";
|
|
46612
47812
|
import os6 from "node:os";
|
|
46613
47813
|
import { open as open7 } from "node:fs/promises";
|
|
46614
|
-
import { constants as
|
|
47814
|
+
import { constants as constants9 } from "node:fs";
|
|
46615
47815
|
import path21 from "node:path";
|
|
46616
47816
|
var MACHINE_GUID = /^\s*MachineGuid\s+REG_SZ\s+([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})\s*$/m;
|
|
46617
47817
|
async function readMachineGuid(timeoutMs2 = 5e3) {
|
|
46618
47818
|
if (process.platform === "linux") {
|
|
46619
47819
|
let handle;
|
|
46620
47820
|
try {
|
|
46621
|
-
handle = await open7("/etc/machine-id",
|
|
47821
|
+
handle = await open7("/etc/machine-id", constants9.O_RDONLY | constants9.O_NOFOLLOW);
|
|
46622
47822
|
const stat2 = await handle.stat();
|
|
46623
47823
|
if (!stat2.isFile() || stat2.size > 128) return null;
|
|
46624
47824
|
const data = Buffer.alloc(129);
|
|
@@ -46667,7 +47867,7 @@ async function readComputerName(timeoutMs2 = 5e3) {
|
|
|
46667
47867
|
if (process.platform === "linux") {
|
|
46668
47868
|
let handle;
|
|
46669
47869
|
try {
|
|
46670
|
-
handle = await open7("/etc/hostname",
|
|
47870
|
+
handle = await open7("/etc/hostname", constants9.O_RDONLY | constants9.O_NOFOLLOW);
|
|
46671
47871
|
const data = Buffer.alloc(257), { bytesRead } = await handle.read(data, 0, data.length, 0);
|
|
46672
47872
|
const name2 = data.subarray(0, bytesRead).toString("utf8").trim();
|
|
46673
47873
|
if (bytesRead <= 256 && valid(name2)) return name2;
|
|
@@ -47250,8 +48450,8 @@ async function deliverGuardEvidence(target, packet, options = {}) {
|
|
|
47250
48450
|
}
|
|
47251
48451
|
|
|
47252
48452
|
// agent/src/optimization-ledger.ts
|
|
47253
|
-
import { constants as
|
|
47254
|
-
import { lstat as
|
|
48453
|
+
import { constants as constants10 } from "node:fs";
|
|
48454
|
+
import { lstat as lstat9, mkdir as mkdir8, open as open8, readFile as readFile9, realpath as realpath8 } from "node:fs/promises";
|
|
47255
48455
|
import path22 from "node:path";
|
|
47256
48456
|
var MAX_LEDGER_BYTES = 64 * 1024 * 1024;
|
|
47257
48457
|
var MAX_NOTICE_LEDGER_BYTES = 8 * 1024 * 1024;
|
|
@@ -47263,7 +48463,7 @@ async function safeDirectory2(directory) {
|
|
|
47263
48463
|
let current2 = absolute2;
|
|
47264
48464
|
for (; ; ) {
|
|
47265
48465
|
try {
|
|
47266
|
-
if ((await
|
|
48466
|
+
if ((await lstat9(current2)).isSymbolicLink()) throw failure5("OPTIMIZATION_LEDGER_DIRECTORY_INVALID");
|
|
47267
48467
|
} catch (error62) {
|
|
47268
48468
|
if (error62.code !== "ENOENT") throw error62;
|
|
47269
48469
|
}
|
|
@@ -47272,7 +48472,7 @@ async function safeDirectory2(directory) {
|
|
|
47272
48472
|
current2 = parent;
|
|
47273
48473
|
}
|
|
47274
48474
|
await mkdir8(absolute2, { recursive: true, mode: 448 });
|
|
47275
|
-
const stat2 = await
|
|
48475
|
+
const stat2 = await lstat9(absolute2);
|
|
47276
48476
|
if (!stat2.isDirectory() || stat2.isSymbolicLink()) throw failure5("OPTIMIZATION_LEDGER_DIRECTORY_INVALID");
|
|
47277
48477
|
return realpath8(absolute2);
|
|
47278
48478
|
}
|
|
@@ -47306,7 +48506,7 @@ var OptimizationLedger = class _OptimizationLedger {
|
|
|
47306
48506
|
const noticesFilename = path22.join(dir, "live-efficiency-notices.v1.jsonl");
|
|
47307
48507
|
let existing = "";
|
|
47308
48508
|
try {
|
|
47309
|
-
const stat2 = await
|
|
48509
|
+
const stat2 = await lstat9(filename);
|
|
47310
48510
|
if (!stat2.isFile() || stat2.isSymbolicLink() || stat2.size > MAX_LEDGER_BYTES) {
|
|
47311
48511
|
throw failure5("OPTIMIZATION_LEDGER_INVALID");
|
|
47312
48512
|
}
|
|
@@ -47316,13 +48516,13 @@ var OptimizationLedger = class _OptimizationLedger {
|
|
|
47316
48516
|
}
|
|
47317
48517
|
const handle = await open8(
|
|
47318
48518
|
filename,
|
|
47319
|
-
|
|
48519
|
+
constants10.O_CREAT | constants10.O_APPEND | constants10.O_WRONLY | (constants10.O_NOFOLLOW ?? 0),
|
|
47320
48520
|
384
|
|
47321
48521
|
);
|
|
47322
48522
|
const ledger = new _OptimizationLedger(filename, handle, noticesFilename);
|
|
47323
48523
|
try {
|
|
47324
48524
|
try {
|
|
47325
|
-
const noticeStat = await
|
|
48525
|
+
const noticeStat = await lstat9(noticesFilename);
|
|
47326
48526
|
if (!noticeStat.isFile() || noticeStat.isSymbolicLink() || noticeStat.size > MAX_NOTICE_LEDGER_BYTES) throw failure5("OPTIMIZATION_NOTICE_LEDGER_INVALID");
|
|
47327
48527
|
const notices = await readFile9(noticesFilename, "utf8");
|
|
47328
48528
|
for (const line of notices.split("\n")) {
|
|
@@ -47404,7 +48604,7 @@ var OptimizationLedger = class _OptimizationLedger {
|
|
|
47404
48604
|
const marker = JSON.stringify({ sessionId: event.sessionId, checkpointCalls, deliveredAt: (/* @__PURE__ */ new Date()).toISOString() }) + "\n";
|
|
47405
48605
|
let currentBytes = 0;
|
|
47406
48606
|
try {
|
|
47407
|
-
const stat2 = await
|
|
48607
|
+
const stat2 = await lstat9(this.noticesFilename);
|
|
47408
48608
|
if (!stat2.isFile() || stat2.isSymbolicLink()) throw failure5("OPTIMIZATION_NOTICE_LEDGER_INVALID");
|
|
47409
48609
|
currentBytes = stat2.size;
|
|
47410
48610
|
} catch (error62) {
|
|
@@ -47413,7 +48613,7 @@ var OptimizationLedger = class _OptimizationLedger {
|
|
|
47413
48613
|
if (currentBytes + Buffer.byteLength(marker, "utf8") > MAX_NOTICE_LEDGER_BYTES) throw failure5("OPTIMIZATION_NOTICE_LEDGER_CAPACITY_EXCEEDED");
|
|
47414
48614
|
const markerHandle = await open8(
|
|
47415
48615
|
this.noticesFilename,
|
|
47416
|
-
|
|
48616
|
+
constants10.O_CREAT | constants10.O_APPEND | constants10.O_WRONLY | (constants10.O_NOFOLLOW ?? 0),
|
|
47417
48617
|
384
|
|
47418
48618
|
);
|
|
47419
48619
|
try {
|
|
@@ -47452,7 +48652,7 @@ var OptimizationLedger = class _OptimizationLedger {
|
|
|
47452
48652
|
|
|
47453
48653
|
// agent/src/monitor.ts
|
|
47454
48654
|
import { createHash as createHash17, randomUUID as randomUUID12 } from "node:crypto";
|
|
47455
|
-
import { lstat as
|
|
48655
|
+
import { lstat as lstat10, mkdir as mkdir9, open as open9, rename as rename6, rm as rm8 } from "node:fs/promises";
|
|
47456
48656
|
import path23 from "node:path";
|
|
47457
48657
|
import os7 from "node:os";
|
|
47458
48658
|
|
|
@@ -47719,7 +48919,7 @@ var ProductionMonitor = class {
|
|
|
47719
48919
|
async write(file2, contents) {
|
|
47720
48920
|
const directory = path23.dirname(file2);
|
|
47721
48921
|
await mkdir9(directory, { recursive: true, mode: 448 });
|
|
47722
|
-
const stat2 = await
|
|
48922
|
+
const stat2 = await lstat10(directory);
|
|
47723
48923
|
if (!stat2.isDirectory() || stat2.isSymbolicLink()) throw Error("MONITOR_DIRECTORY_INVALID");
|
|
47724
48924
|
const temporary = file2 + "." + this.instanceId + ".tmp";
|
|
47725
48925
|
const handle = await open9(temporary, "wx", 384);
|
|
@@ -48142,26 +49342,26 @@ var NativeFabricObserver = class {
|
|
|
48142
49342
|
};
|
|
48143
49343
|
|
|
48144
49344
|
// agent/src/native-fabric-startup.ts
|
|
48145
|
-
import { lstat as
|
|
49345
|
+
import { lstat as lstat12, mkdir as mkdir12, open as open11, readFile as readFile10 } from "node:fs/promises";
|
|
48146
49346
|
import path26 from "node:path";
|
|
48147
49347
|
|
|
48148
49348
|
// src/agent-fabric-service.ts
|
|
48149
|
-
import { lstat as
|
|
49349
|
+
import { lstat as lstat11, mkdir as mkdir11, realpath as realpath9 } from "node:fs/promises";
|
|
48150
49350
|
import { watch } from "node:fs";
|
|
48151
49351
|
import path25 from "node:path";
|
|
48152
49352
|
|
|
48153
49353
|
// src/agent-runtime-identity.ts
|
|
48154
|
-
import { createHash as createHash19, randomBytes as
|
|
49354
|
+
import { createHash as createHash19, randomBytes as randomBytes8, randomUUID as randomUUID14, timingSafeEqual as timingSafeEqual4 } from "node:crypto";
|
|
48155
49355
|
|
|
48156
49356
|
// src/agent-fabric-state.ts
|
|
48157
49357
|
import { randomUUID as randomUUID13 } from "node:crypto";
|
|
48158
|
-
import { mkdir as mkdir10, open as open10, rename as rename7, unlink as
|
|
49358
|
+
import { mkdir as mkdir10, open as open10, rename as rename7, unlink as unlink3 } from "node:fs/promises";
|
|
48159
49359
|
import path24 from "node:path";
|
|
48160
49360
|
var queues = /* @__PURE__ */ new Map();
|
|
48161
49361
|
var FabricStateFile = class {
|
|
48162
|
-
constructor(file2, maxBytes,
|
|
49362
|
+
constructor(file2, maxBytes, parse4) {
|
|
48163
49363
|
this.maxBytes = maxBytes;
|
|
48164
|
-
this.parse =
|
|
49364
|
+
this.parse = parse4;
|
|
48165
49365
|
this.file = path24.resolve(file2);
|
|
48166
49366
|
}
|
|
48167
49367
|
maxBytes;
|
|
@@ -48237,7 +49437,7 @@ var FabricStateFile = class {
|
|
|
48237
49437
|
}
|
|
48238
49438
|
await rename7(temporary, this.file);
|
|
48239
49439
|
} finally {
|
|
48240
|
-
await
|
|
49440
|
+
await unlink3(temporary).catch((error62) => {
|
|
48241
49441
|
if (error62.code !== "ENOENT") throw error62;
|
|
48242
49442
|
});
|
|
48243
49443
|
}
|
|
@@ -48251,7 +49451,7 @@ var FabricStateFile = class {
|
|
|
48251
49451
|
} finally {
|
|
48252
49452
|
await current2.close();
|
|
48253
49453
|
}
|
|
48254
|
-
await
|
|
49454
|
+
await unlink3(lockPath);
|
|
48255
49455
|
}
|
|
48256
49456
|
});
|
|
48257
49457
|
}
|
|
@@ -48305,7 +49505,7 @@ var AgentRuntimeIdentityStore = class {
|
|
|
48305
49505
|
return this.serial((state) => {
|
|
48306
49506
|
if (state.bindings.length >= MAX_BINDINGS) throw Error("RUNTIME_IDENTITY_LIMIT");
|
|
48307
49507
|
const runtimeId = "rt-" + randomUUID14();
|
|
48308
|
-
const runtimeKey =
|
|
49508
|
+
const runtimeKey = randomBytes8(32).toString("base64url");
|
|
48309
49509
|
const now = this.now();
|
|
48310
49510
|
state.bindings.push({ runtimeId, keyHash: encodedDigest(runtimeKey), createdAt: now, lastUsedAt: now, revoked: false });
|
|
48311
49511
|
return { runtimeId, runtimeKey };
|
|
@@ -48870,18 +50070,18 @@ var AgentFabricService = class _AgentFabricService {
|
|
|
48870
50070
|
const absolute2 = path25.resolve(directory);
|
|
48871
50071
|
for (let current2 = absolute2; ; current2 = path25.dirname(current2)) {
|
|
48872
50072
|
try {
|
|
48873
|
-
if ((await
|
|
50073
|
+
if ((await lstat11(current2)).isSymbolicLink()) throw Error("FABRIC_DIRECTORY_INVALID");
|
|
48874
50074
|
} catch (error62) {
|
|
48875
50075
|
if (error62.code !== "ENOENT") throw error62;
|
|
48876
50076
|
}
|
|
48877
50077
|
if (path25.dirname(current2) === current2) break;
|
|
48878
50078
|
}
|
|
48879
50079
|
if (initialize) await mkdir11(absolute2, { recursive: true, mode: 448 });
|
|
48880
|
-
if (!(await
|
|
50080
|
+
if (!(await lstat11(absolute2)).isDirectory() || (await realpath9(absolute2)).toLowerCase() !== absolute2.toLowerCase())
|
|
48881
50081
|
throw Error("FABRIC_DIRECTORY_INVALID");
|
|
48882
50082
|
const present = /* @__PURE__ */ new Set();
|
|
48883
50083
|
for (const name2 of ["binding.json", "mailbox.json", "identities.json"]) {
|
|
48884
|
-
const file2 = await
|
|
50084
|
+
const file2 = await lstat11(path25.join(absolute2, name2)).catch((error62) => {
|
|
48885
50085
|
if (error62.code === "ENOENT") return null;
|
|
48886
50086
|
throw error62;
|
|
48887
50087
|
});
|
|
@@ -48904,7 +50104,7 @@ var AgentFabricService = class _AgentFabricService {
|
|
|
48904
50104
|
state.initialized = true;
|
|
48905
50105
|
}
|
|
48906
50106
|
const snapshot2 = await service2.mailbox.snapshot();
|
|
48907
|
-
if (snapshot2.workers.some((worker) => worker.runtimeId !== null)) await
|
|
50107
|
+
if (snapshot2.workers.some((worker) => worker.runtimeId !== null)) await lstat11(path25.join(absolute2, "identities.json"));
|
|
48908
50108
|
}, initialize ? () => expected : void 0);
|
|
48909
50109
|
return service2;
|
|
48910
50110
|
}
|
|
@@ -48997,12 +50197,12 @@ async function openNativeFabric(stateDirectory, enrollment, box, initialize = tr
|
|
|
48997
50197
|
} catch (error62) {
|
|
48998
50198
|
if (error62.code !== "EEXIST") throw error62;
|
|
48999
50199
|
}
|
|
49000
|
-
const parentInfo = await
|
|
50200
|
+
const parentInfo = await lstat12(parent);
|
|
49001
50201
|
if (!parentInfo.isDirectory() || parentInfo.isSymbolicLink()) throw Error("FABRIC_DIRECTORY_INVALID");
|
|
49002
50202
|
const expected = JSON.stringify({ version: 1, controllerId, tenantId });
|
|
49003
50203
|
let fresh = false;
|
|
49004
50204
|
try {
|
|
49005
|
-
const info = await
|
|
50205
|
+
const info = await lstat12(marker);
|
|
49006
50206
|
if (!info.isFile() || info.isSymbolicLink() || info.size > 2048 || await readFile10(marker, "utf8") !== expected)
|
|
49007
50207
|
throw Error("FABRIC_BINDING_CHANGED");
|
|
49008
50208
|
} catch (error62) {
|
|
@@ -49030,7 +50230,7 @@ async function openNativeFabric(stateDirectory, enrollment, box, initialize = tr
|
|
|
49030
50230
|
return credential;
|
|
49031
50231
|
};
|
|
49032
50232
|
async function capability(workerId) {
|
|
49033
|
-
const file2 = credentialFile(workerId), info = await
|
|
50233
|
+
const file2 = credentialFile(workerId), info = await lstat12(file2);
|
|
49034
50234
|
if (!info.isFile() || info.isSymbolicLink() || info.size > 4096) throw Error("FABRIC_CREDENTIAL_UNKNOWN");
|
|
49035
50235
|
const encoded = await readFile10(file2, "utf8");
|
|
49036
50236
|
if (decode4(encoded).workerId !== workerId) throw Error("FABRIC_WORKER_DENIED");
|
|
@@ -49184,14 +50384,14 @@ function supervisorLiveness(helperPath, options = {}) {
|
|
|
49184
50384
|
|
|
49185
50385
|
// agent/src/content-audit.ts
|
|
49186
50386
|
import { createReadStream } from "node:fs";
|
|
49187
|
-
import { appendFile, lstat as
|
|
50387
|
+
import { appendFile, lstat as lstat13, mkdir as mkdir13, open as open12, readdir as readdir6, readFile as readFile11, rename as rename8, rm as rm9, writeFile as writeFile4 } from "node:fs/promises";
|
|
49188
50388
|
import path28 from "node:path";
|
|
49189
50389
|
import { performance as performance3 } from "node:perf_hooks";
|
|
49190
50390
|
import { createInterface as createInterface2 } from "node:readline";
|
|
49191
|
-
import { randomBytes as
|
|
50391
|
+
import { randomBytes as randomBytes10 } from "node:crypto";
|
|
49192
50392
|
|
|
49193
50393
|
// src/audit-crypto.ts
|
|
49194
|
-
import { createCipheriv as createCipheriv3, createDecipheriv as createDecipheriv3, createHash as createHash20, randomBytes as
|
|
50394
|
+
import { createCipheriv as createCipheriv3, createDecipheriv as createDecipheriv3, createHash as createHash20, randomBytes as randomBytes9 } from "node:crypto";
|
|
49195
50395
|
import { promisify as promisify3 } from "node:util";
|
|
49196
50396
|
import { gunzipSync, gzip, gzipSync } from "node:zlib";
|
|
49197
50397
|
var gzipAsync = promisify3(gzip);
|
|
@@ -49243,7 +50443,7 @@ async function encryptAuditRecordAsync(record2, keyInput, keyId2) {
|
|
|
49243
50443
|
function sealCompressed(compressed, keyInput, keyId2) {
|
|
49244
50444
|
const key = parseAuditRecoveryKey(keyInput);
|
|
49245
50445
|
const kid = keyId2?.trim() || auditRecoveryKeyId(key);
|
|
49246
|
-
const iv =
|
|
50446
|
+
const iv = randomBytes9(IV_BYTES);
|
|
49247
50447
|
try {
|
|
49248
50448
|
const cipher = createCipheriv3("aes-256-gcm", key, iv, { authTagLength: TAG_BYTES });
|
|
49249
50449
|
cipher.setAAD(additionalData(kid));
|
|
@@ -49358,13 +50558,13 @@ function contentAuditDirectory(stateDir) {
|
|
|
49358
50558
|
}
|
|
49359
50559
|
async function plainDirectory(dir) {
|
|
49360
50560
|
await mkdir13(dir, { recursive: true, mode: 448 });
|
|
49361
|
-
const info = await
|
|
50561
|
+
const info = await lstat13(dir);
|
|
49362
50562
|
if (info.isSymbolicLink() || !info.isDirectory()) throw Error("AUDIT_DIRECTORY_INVALID");
|
|
49363
50563
|
}
|
|
49364
50564
|
async function auditFiles(dir) {
|
|
49365
50565
|
let names;
|
|
49366
50566
|
try {
|
|
49367
|
-
names = await
|
|
50567
|
+
names = await readdir6(dir);
|
|
49368
50568
|
} catch (error62) {
|
|
49369
50569
|
if (error62.code === "ENOENT") return [];
|
|
49370
50570
|
throw error62;
|
|
@@ -49373,13 +50573,13 @@ async function auditFiles(dir) {
|
|
|
49373
50573
|
for (const name2 of names) {
|
|
49374
50574
|
const match = FILE.exec(name2);
|
|
49375
50575
|
if (!match) continue;
|
|
49376
|
-
const info = await
|
|
50576
|
+
const info = await lstat13(path28.join(dir, name2));
|
|
49377
50577
|
if (info.isFile()) files.push({ name: name2, kind: match[1], day: match[2], bytes: info.size });
|
|
49378
50578
|
}
|
|
49379
50579
|
return files.sort((a, b) => a.name.localeCompare(b.name));
|
|
49380
50580
|
}
|
|
49381
50581
|
async function writeJsonAtomic(file2, value) {
|
|
49382
|
-
const temp = `${file2}.${
|
|
50582
|
+
const temp = `${file2}.${randomBytes10(6).toString("hex")}.tmp`;
|
|
49383
50583
|
try {
|
|
49384
50584
|
await writeFile4(temp, JSON.stringify(value) + "\n", { flag: "wx", mode: 384 });
|
|
49385
50585
|
await rename8(temp, file2);
|
|
@@ -49616,7 +50816,7 @@ async function restoreContentAudit(input2, output2, key) {
|
|
|
49616
50816
|
}
|
|
49617
50817
|
|
|
49618
50818
|
// agent/src/main.ts
|
|
49619
|
-
var AGENT_VERSION2 = true ? "0.3.
|
|
50819
|
+
var AGENT_VERSION2 = true ? "0.3.48" : "0.3.2";
|
|
49620
50820
|
var NETWORK_PUBLIC_KEY = true ? "-----BEGIN PUBLIC KEY-----\nMIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAvmu+81vWtJBQDZNHcAIW\nzCSxpG+R9RBsum2df5mP2cOW+wyUDTpnYquFge1qgI5YYTF96j0xCyXL8B9FeNWs\n939opWNmv53j+CQlS4cEIQhBbZSCu0eC4icsVEzBhvf68MB+E668SOtZBcVTEnyh\n96PTcupxS10rQJBWDinbKBXRC2gvGYeu01rWa/nsrndy4vAYP5t3yQtdOC8e8mr0\n+2Mg2Qhiq+KiTCtDd+L9oXvoLqqJYbzUIveNGha25AWxF1Weblp0gOM87hell5gV\nK7q4ZLUq/wBRGYNmQRdLyV7/WRE1FFPSW21/SBZQ/5aU4UqJU/MjMcrJUrnRKngz\nYKmo0czkxS3N7Q2KVxomgR1AQSuQFKMrboZYKjShADp9RIYUxzs7cYg51Of5PnHh\n6Ax+VevDGfzjMD+yHuyxYZqCtX4OwgolJxz63UQbzKlris+8xb5lLYTbIuz90Pss\nn6HK/F5May25c6oMmS3nh/NsiZopL1OvdtWKTt1L4WlRAgMBAAE=\n-----END PUBLIC KEY-----\n" : "";
|
|
49621
50821
|
var AI_CONNECTION_SHIPPED = false;
|
|
49622
50822
|
function processAlive(pid) {
|