local-commander-agent-linux-arm64 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/package.json +1 -1
- package/runtime/agent.mjs +1321 -121
- package/runtime/manifest.json +4 -4
- package/runtime/node +0 -0
- package/runtime/posix-host +0 -0
package/runtime/agent.mjs
CHANGED
|
@@ -2138,7 +2138,7 @@ var require_extension = __commonJS({
|
|
|
2138
2138
|
if (dest[name2] === void 0) dest[name2] = [elem];
|
|
2139
2139
|
else dest[name2].push(elem);
|
|
2140
2140
|
}
|
|
2141
|
-
function
|
|
2141
|
+
function parse4(header) {
|
|
2142
2142
|
const offers = /* @__PURE__ */ Object.create(null);
|
|
2143
2143
|
let params = /* @__PURE__ */ Object.create(null);
|
|
2144
2144
|
let mustUnescape = false;
|
|
@@ -2278,7 +2278,7 @@ var require_extension = __commonJS({
|
|
|
2278
2278
|
}).join(", ");
|
|
2279
2279
|
}).join(", ");
|
|
2280
2280
|
}
|
|
2281
|
-
module.exports = { format, parse:
|
|
2281
|
+
module.exports = { format, parse: parse4 };
|
|
2282
2282
|
}
|
|
2283
2283
|
});
|
|
2284
2284
|
|
|
@@ -2289,9 +2289,9 @@ var require_websocket = __commonJS({
|
|
|
2289
2289
|
var EventEmitter = __require("events");
|
|
2290
2290
|
var https2 = __require("https");
|
|
2291
2291
|
var http2 = __require("http");
|
|
2292
|
-
var
|
|
2292
|
+
var net3 = __require("net");
|
|
2293
2293
|
var tls2 = __require("tls");
|
|
2294
|
-
var { randomBytes:
|
|
2294
|
+
var { randomBytes: randomBytes11, createHash: createHash21 } = __require("crypto");
|
|
2295
2295
|
var { Duplex, Readable } = __require("stream");
|
|
2296
2296
|
var { URL: URL2 } = __require("url");
|
|
2297
2297
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
@@ -2312,7 +2312,7 @@ var require_websocket = __commonJS({
|
|
|
2312
2312
|
var {
|
|
2313
2313
|
EventTarget: { addEventListener, removeEventListener }
|
|
2314
2314
|
} = require_event_target();
|
|
2315
|
-
var { format, parse:
|
|
2315
|
+
var { format, parse: parse4 } = require_extension();
|
|
2316
2316
|
var { toBuffer } = require_buffer_util();
|
|
2317
2317
|
var kAborted = /* @__PURE__ */ Symbol("kAborted");
|
|
2318
2318
|
var protocolVersions = [8, 13];
|
|
@@ -2842,7 +2842,7 @@ var require_websocket = __commonJS({
|
|
|
2842
2842
|
}
|
|
2843
2843
|
}
|
|
2844
2844
|
const defaultPort = isSecure ? 443 : 80;
|
|
2845
|
-
const key =
|
|
2845
|
+
const key = randomBytes11(16).toString("base64");
|
|
2846
2846
|
const request = isSecure ? https2.request : http2.request;
|
|
2847
2847
|
const protocolSet = /* @__PURE__ */ new Set();
|
|
2848
2848
|
let perMessageDeflate;
|
|
@@ -3002,7 +3002,7 @@ var require_websocket = __commonJS({
|
|
|
3002
3002
|
}
|
|
3003
3003
|
let extensions;
|
|
3004
3004
|
try {
|
|
3005
|
-
extensions =
|
|
3005
|
+
extensions = parse4(secWebSocketExtensions);
|
|
3006
3006
|
} catch (err) {
|
|
3007
3007
|
const message2 = "Invalid Sec-WebSocket-Extensions header";
|
|
3008
3008
|
abortHandshake(websocket, socket, message2);
|
|
@@ -3046,12 +3046,12 @@ var require_websocket = __commonJS({
|
|
|
3046
3046
|
}
|
|
3047
3047
|
function netConnect2(options) {
|
|
3048
3048
|
options.path = options.socketPath;
|
|
3049
|
-
return
|
|
3049
|
+
return net3.connect(options);
|
|
3050
3050
|
}
|
|
3051
3051
|
function tlsConnect(options) {
|
|
3052
3052
|
options.path = void 0;
|
|
3053
3053
|
if (!options.servername && options.servername !== "") {
|
|
3054
|
-
options.servername =
|
|
3054
|
+
options.servername = net3.isIP(options.host) ? "" : options.host;
|
|
3055
3055
|
}
|
|
3056
3056
|
return tls2.connect(options);
|
|
3057
3057
|
}
|
|
@@ -3294,7 +3294,7 @@ var require_subprotocol = __commonJS({
|
|
|
3294
3294
|
"node_modules/ws/lib/subprotocol.js"(exports, module) {
|
|
3295
3295
|
"use strict";
|
|
3296
3296
|
var { tokenChars } = require_validation();
|
|
3297
|
-
function
|
|
3297
|
+
function parse4(header) {
|
|
3298
3298
|
const protocols = /* @__PURE__ */ new Set();
|
|
3299
3299
|
let start = -1;
|
|
3300
3300
|
let end = -1;
|
|
@@ -3330,7 +3330,7 @@ var require_subprotocol = __commonJS({
|
|
|
3330
3330
|
protocols.add(protocol2);
|
|
3331
3331
|
return protocols;
|
|
3332
3332
|
}
|
|
3333
|
-
module.exports = { parse:
|
|
3333
|
+
module.exports = { parse: parse4 };
|
|
3334
3334
|
}
|
|
3335
3335
|
});
|
|
3336
3336
|
|
|
@@ -5583,18 +5583,18 @@ var validateAsync = async (schema, value, _ctx) => {
|
|
|
5583
5583
|
return result2.issues.length === 0;
|
|
5584
5584
|
};
|
|
5585
5585
|
var _encode = (_Err) => {
|
|
5586
|
-
const
|
|
5586
|
+
const parse4 = _parse(_Err);
|
|
5587
5587
|
const fn = (schema, value, _ctx, _params) => {
|
|
5588
5588
|
const ctx = _ctx ? { ..._ctx, direction: "backward" } : { direction: "backward" };
|
|
5589
|
-
return
|
|
5589
|
+
return parse4(schema, value, ctx, finalizeParams(fn, _params));
|
|
5590
5590
|
};
|
|
5591
5591
|
return fn;
|
|
5592
5592
|
};
|
|
5593
5593
|
var encode = /* @__PURE__ */ _encode($ZodRealError);
|
|
5594
5594
|
var _decode = (_Err) => {
|
|
5595
|
-
const
|
|
5595
|
+
const parse4 = _parse(_Err);
|
|
5596
5596
|
const fn = (schema, value, _ctx, _params) => {
|
|
5597
|
-
return
|
|
5597
|
+
return parse4(schema, value, _ctx, finalizeParams(fn, _params));
|
|
5598
5598
|
};
|
|
5599
5599
|
return fn;
|
|
5600
5600
|
};
|
|
@@ -26479,10 +26479,12 @@ var ServerFrameSchema = external_exports.discriminatedUnion("type", [
|
|
|
26479
26479
|
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(),
|
|
26480
26480
|
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()
|
|
26481
26481
|
]);
|
|
26482
|
+
var WORKSPACE_ACCESS_MODE_CAPABILITY = "workspaceAccessModeV1";
|
|
26483
|
+
var WorkspaceAccessModeSchema = external_exports.enum(["full", "scoped"]);
|
|
26482
26484
|
var ClientFrameSchema = external_exports.discriminatedUnion("type", [
|
|
26483
26485
|
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(),
|
|
26484
26486
|
external_exports.object({ type: external_exports.literal("heartbeat"), version: external_exports.literal(1), connectionEpoch: epoch2 }).strict(),
|
|
26485
|
-
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(),
|
|
26487
|
+
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(),
|
|
26486
26488
|
external_exports.object({ type: external_exports.literal("workspace_revoke"), version: external_exports.literal(1), requestId: uuid11, workspaceGrantId: uuid11 }).strict(),
|
|
26487
26489
|
external_exports.object({ type: external_exports.literal("prepared"), version: external_exports.literal(1), binding: ExecutionBindingSchema }).strict(),
|
|
26488
26490
|
external_exports.object({ type: external_exports.literal("accepted"), version: external_exports.literal(1), binding: ExecutionBindingSchema }).strict(),
|
|
@@ -27043,9 +27045,9 @@ var NativeJournal = class _NativeJournal {
|
|
|
27043
27045
|
if (!validPid(pid)) throw failure2("JOURNAL_INPUT_INVALID");
|
|
27044
27046
|
if (e.state !== "running" || !e.supervisors) throw failure2("JOURNAL_STATE_INVALID");
|
|
27045
27047
|
if (containment !== void 0) {
|
|
27046
|
-
const
|
|
27047
|
-
if (!
|
|
27048
|
-
if (
|
|
27048
|
+
const linux2 = validLinuxContainment(containment), darwin = !linux2 && validDarwinContainment(containment);
|
|
27049
|
+
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");
|
|
27050
|
+
if (linux2) (e.linuxSupervisors ??= []).push({ pid, containment: clone2(containment) });
|
|
27049
27051
|
else (e.darwinSupervisors ??= []).push({ pid, containment: clone2(containment) });
|
|
27050
27052
|
} else {
|
|
27051
27053
|
if (e.supervisors.length >= MAX_SUPERVISORS) throw failure2("JOURNAL_SUPERVISOR_LIMIT");
|
|
@@ -27943,11 +27945,16 @@ var WindowsPrivateStore = class _WindowsPrivateStore {
|
|
|
27943
27945
|
if (process.platform !== "win32") for (const name2 of ["owner-key.json", "owner-key.dat", "owner-key.lock"]) approved.add(name2);
|
|
27944
27946
|
if (names.length && !names.includes(MARKER)) throw fail2("STORE_DIRECTORY_UNKNOWN");
|
|
27945
27947
|
const memoryFile = (name2) => name2 === "host-memory.json" || /^host-memory\.json\.[1-9][0-9]{0,9}\.tmp$/.test(name2);
|
|
27946
|
-
|
|
27948
|
+
const switchFile = (name2) => name2 === "screenshot-acceptance-enabled" || name2 === "screenshot-disabled-by-owner";
|
|
27949
|
+
if (names.some((name2) => !approved.has(name2) && !memoryFile(name2) && !switchFile(name2))) throw fail2("STORE_DIRECTORY_UNKNOWN");
|
|
27947
27950
|
for (const name2 of names.filter(memoryFile)) {
|
|
27948
27951
|
const stat2 = await lstat4(path10.join(absolute2, name2));
|
|
27949
27952
|
if (!stat2.isFile() || stat2.isSymbolicLink() || stat2.size > 32768) throw fail2("STORE_DIRECTORY_INVALID");
|
|
27950
27953
|
}
|
|
27954
|
+
for (const name2 of names.filter(switchFile)) {
|
|
27955
|
+
const stat2 = await lstat4(path10.join(absolute2, name2));
|
|
27956
|
+
if (!stat2.isFile() || stat2.isSymbolicLink() || stat2.size > 4096) throw fail2("STORE_DIRECTORY_INVALID");
|
|
27957
|
+
}
|
|
27951
27958
|
for (const name2 of ["agent-process.json", "optimization", ".local-commander"]) {
|
|
27952
27959
|
if (!names.includes(name2)) continue;
|
|
27953
27960
|
const filename = path10.join(absolute2, name2), stat2 = await lstat4(filename);
|
|
@@ -28918,8 +28925,8 @@ var HostMemory = class {
|
|
|
28918
28925
|
};
|
|
28919
28926
|
|
|
28920
28927
|
// agent/src/tools.ts
|
|
28921
|
-
import { constants as
|
|
28922
|
-
import { lstat as
|
|
28928
|
+
import { constants as constants8 } from "node:fs";
|
|
28929
|
+
import { lstat as lstat8, open as open6, readdir as readdir5, realpath as realpath7, rename as rename4, rm as rm6 } from "node:fs/promises";
|
|
28923
28930
|
import path18 from "node:path";
|
|
28924
28931
|
import { createHash as createHash14, randomUUID as randomUUID7 } from "node:crypto";
|
|
28925
28932
|
|
|
@@ -29366,22 +29373,1025 @@ async function runSupervised(helper, request, options = {}) {
|
|
|
29366
29373
|
|
|
29367
29374
|
// agent/src/screen-capture.ts
|
|
29368
29375
|
import { execFile as execFile4 } from "node:child_process";
|
|
29369
|
-
import {
|
|
29376
|
+
import { randomBytes as randomBytes6 } from "node:crypto";
|
|
29377
|
+
import { constants as constants7 } from "node:fs";
|
|
29378
|
+
import { access as access3, lstat as lstat7, mkdtemp, readFile as readFile6, readdir as readdir4, rm as rm5, unlink as unlink2 } from "node:fs/promises";
|
|
29370
29379
|
import os4 from "node:os";
|
|
29371
29380
|
import path17 from "node:path";
|
|
29381
|
+
|
|
29382
|
+
// agent/src/dbus-portal.ts
|
|
29383
|
+
import net from "node:net";
|
|
29384
|
+
function sessionBusSocket(address) {
|
|
29385
|
+
for (const entry of (address ?? "").split(";")) {
|
|
29386
|
+
if (!entry.startsWith("unix:")) continue;
|
|
29387
|
+
for (const part of entry.slice(5).split(",")) {
|
|
29388
|
+
const at = part.indexOf("="), key = part.slice(0, at), value = decodeURIComponent(part.slice(at + 1));
|
|
29389
|
+
if (at > 0 && value && key === "path") return value;
|
|
29390
|
+
if (at > 0 && value && key === "abstract") return "\0" + value;
|
|
29391
|
+
}
|
|
29392
|
+
}
|
|
29393
|
+
return null;
|
|
29394
|
+
}
|
|
29395
|
+
var Writer = class {
|
|
29396
|
+
bytes = [];
|
|
29397
|
+
align(n) {
|
|
29398
|
+
while (this.bytes.length % n) this.bytes.push(0);
|
|
29399
|
+
}
|
|
29400
|
+
byte(v) {
|
|
29401
|
+
this.bytes.push(v & 255);
|
|
29402
|
+
}
|
|
29403
|
+
u32(v) {
|
|
29404
|
+
this.align(4);
|
|
29405
|
+
this.bytes.push(v & 255, v >>> 8 & 255, v >>> 16 & 255, v >>> 24 & 255);
|
|
29406
|
+
}
|
|
29407
|
+
str(v) {
|
|
29408
|
+
const b = Buffer.from(v, "utf8");
|
|
29409
|
+
this.u32(b.length);
|
|
29410
|
+
this.bytes.push(...b, 0);
|
|
29411
|
+
}
|
|
29412
|
+
sig(v) {
|
|
29413
|
+
this.byte(v.length);
|
|
29414
|
+
this.bytes.push(...Buffer.from(v, "ascii"), 0);
|
|
29415
|
+
}
|
|
29416
|
+
/** Basic value or variant: `s`, `o`, `g`, `u`, `b`, `v` ([signature, value]). */
|
|
29417
|
+
put(type, value) {
|
|
29418
|
+
if (type === "s" || type === "o") this.str(String(value));
|
|
29419
|
+
else if (type === "g") this.sig(String(value));
|
|
29420
|
+
else if (type === "u") this.u32(Number(value));
|
|
29421
|
+
else if (type === "b") this.u32(value ? 1 : 0);
|
|
29422
|
+
else if (type === "v") {
|
|
29423
|
+
const [inner, v] = value;
|
|
29424
|
+
this.sig(inner);
|
|
29425
|
+
this.put(inner, v);
|
|
29426
|
+
} else throw Error("type " + type);
|
|
29427
|
+
}
|
|
29428
|
+
/** a{sv} */
|
|
29429
|
+
dict(entries) {
|
|
29430
|
+
this.u32(0);
|
|
29431
|
+
const lengthAt = this.bytes.length - 4;
|
|
29432
|
+
this.align(8);
|
|
29433
|
+
const start = this.bytes.length;
|
|
29434
|
+
for (const [key, value] of entries) {
|
|
29435
|
+
this.align(8);
|
|
29436
|
+
this.str(key);
|
|
29437
|
+
this.put("v", value);
|
|
29438
|
+
}
|
|
29439
|
+
const length = this.bytes.length - start;
|
|
29440
|
+
this.bytes.splice(lengthAt, 4, length & 255, length >>> 8 & 255, length >>> 16 & 255, length >>> 24 & 255);
|
|
29441
|
+
}
|
|
29442
|
+
};
|
|
29443
|
+
var Reader = class {
|
|
29444
|
+
constructor(data, at, le) {
|
|
29445
|
+
this.data = data;
|
|
29446
|
+
this.at = at;
|
|
29447
|
+
this.le = le;
|
|
29448
|
+
}
|
|
29449
|
+
data;
|
|
29450
|
+
at;
|
|
29451
|
+
le;
|
|
29452
|
+
align(n) {
|
|
29453
|
+
this.at = Math.ceil(this.at / n) * n;
|
|
29454
|
+
}
|
|
29455
|
+
u32() {
|
|
29456
|
+
this.align(4);
|
|
29457
|
+
const v = this.le ? this.data.readUInt32LE(this.at) : this.data.readUInt32BE(this.at);
|
|
29458
|
+
this.at += 4;
|
|
29459
|
+
return v;
|
|
29460
|
+
}
|
|
29461
|
+
/** Reads one complete type from `sig` starting at `i`; returns the value and the index after the type. */
|
|
29462
|
+
read(sig2, i) {
|
|
29463
|
+
const c = sig2[i];
|
|
29464
|
+
const fixed = { y: 1, n: 2, q: 2, b: 4, i: 4, u: 4, h: 4, x: 8, t: 8, d: 8 };
|
|
29465
|
+
if (c in fixed) {
|
|
29466
|
+
const size = fixed[c];
|
|
29467
|
+
this.align(size);
|
|
29468
|
+
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;
|
|
29469
|
+
this.at += size;
|
|
29470
|
+
return [c === "b" ? v === 1 : v, i + 1];
|
|
29471
|
+
}
|
|
29472
|
+
if (c === "s" || c === "o") {
|
|
29473
|
+
const n = this.u32(), v = this.data.toString("utf8", this.at, this.at + n);
|
|
29474
|
+
this.at += n + 1;
|
|
29475
|
+
return [v, i + 1];
|
|
29476
|
+
}
|
|
29477
|
+
if (c === "g") {
|
|
29478
|
+
const n = this.data[this.at], v = this.data.toString("ascii", this.at + 1, this.at + 1 + n);
|
|
29479
|
+
this.at += n + 2;
|
|
29480
|
+
return [v, i + 1];
|
|
29481
|
+
}
|
|
29482
|
+
if (c === "v") {
|
|
29483
|
+
const [inner] = this.read("g", 0);
|
|
29484
|
+
return [this.read(inner, 0)[0], i + 1];
|
|
29485
|
+
}
|
|
29486
|
+
if (c === "(" || c === "{") {
|
|
29487
|
+
this.align(8);
|
|
29488
|
+
const close = c === "(" ? ")" : "}", values = [];
|
|
29489
|
+
let j = i + 1;
|
|
29490
|
+
while (sig2[j] !== close) {
|
|
29491
|
+
const [v, next] = this.read(sig2, j);
|
|
29492
|
+
values.push(v);
|
|
29493
|
+
j = next;
|
|
29494
|
+
}
|
|
29495
|
+
return [values, j + 1];
|
|
29496
|
+
}
|
|
29497
|
+
if (c === "a") {
|
|
29498
|
+
const n = this.u32(), element = sig2[i + 1];
|
|
29499
|
+
this.align("xtd({".includes(element) ? 8 : element === "n" || element === "q" ? 2 : element === "y" || element === "g" || element === "v" ? 1 : 4);
|
|
29500
|
+
const end = this.at + n, values = [];
|
|
29501
|
+
let next = skip(sig2, i + 1);
|
|
29502
|
+
while (this.at < end) {
|
|
29503
|
+
const [v, j] = this.read(sig2, i + 1);
|
|
29504
|
+
values.push(v);
|
|
29505
|
+
next = j;
|
|
29506
|
+
}
|
|
29507
|
+
return [values, next];
|
|
29508
|
+
}
|
|
29509
|
+
throw Error("signature " + sig2);
|
|
29510
|
+
}
|
|
29511
|
+
};
|
|
29512
|
+
function skip(sig2, i) {
|
|
29513
|
+
const c = sig2[i];
|
|
29514
|
+
if (c === "a") return skip(sig2, i + 1);
|
|
29515
|
+
if (c === "(" || c === "{") {
|
|
29516
|
+
let j = i + 1;
|
|
29517
|
+
while (sig2[j] !== (c === "(" ? ")" : "}")) j = skip(sig2, j);
|
|
29518
|
+
return j + 1;
|
|
29519
|
+
}
|
|
29520
|
+
return i + 1;
|
|
29521
|
+
}
|
|
29522
|
+
function parse3(data) {
|
|
29523
|
+
const le = data[0] === 108, r = new Reader(data, 4, le), bodyLength = r.u32(), serial = r.u32();
|
|
29524
|
+
const [fields] = r.read("a(yv)", 0);
|
|
29525
|
+
const message2 = { type: data[1], serial, signature: "", body: [] };
|
|
29526
|
+
for (const [code, value] of fields) {
|
|
29527
|
+
if (code === 1) message2.path = String(value);
|
|
29528
|
+
else if (code === 2) message2.interface = String(value);
|
|
29529
|
+
else if (code === 3) message2.member = String(value);
|
|
29530
|
+
else if (code === 4) message2.errorName = String(value);
|
|
29531
|
+
else if (code === 5) message2.replySerial = Number(value);
|
|
29532
|
+
else if (code === 8) message2.signature = String(value);
|
|
29533
|
+
}
|
|
29534
|
+
r.align(8);
|
|
29535
|
+
const end = r.at + bodyLength;
|
|
29536
|
+
for (let i = 0; i < message2.signature.length && r.at < end; ) {
|
|
29537
|
+
const [v, next] = r.read(message2.signature, i);
|
|
29538
|
+
message2.body.push(v);
|
|
29539
|
+
i = next;
|
|
29540
|
+
}
|
|
29541
|
+
return message2;
|
|
29542
|
+
}
|
|
29543
|
+
function frameLength(data) {
|
|
29544
|
+
if (data.length < 16) return 0;
|
|
29545
|
+
const le = data[0] === 108, u = (at) => le ? data.readUInt32LE(at) : data.readUInt32BE(at);
|
|
29546
|
+
const length = Math.ceil((16 + u(12)) / 8) * 8 + u(4);
|
|
29547
|
+
return data.length >= length ? length : 0;
|
|
29548
|
+
}
|
|
29549
|
+
async function portalScreenshot(socket, uid, token, signal) {
|
|
29550
|
+
const connection = net.createConnection({ path: socket });
|
|
29551
|
+
try {
|
|
29552
|
+
return await new Promise((resolve, reject) => {
|
|
29553
|
+
let serial = 0, buffer = Buffer.alloc(0), authenticated = false, requestPath = "";
|
|
29554
|
+
const pending = /* @__PURE__ */ new Map();
|
|
29555
|
+
const fail7 = (error62) => reject(error62 instanceof Error ? error62 : Error(String(error62)));
|
|
29556
|
+
const abort = () => fail7(Error("ABORTED"));
|
|
29557
|
+
if (signal.aborted) return abort();
|
|
29558
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
29559
|
+
connection.on("error", fail7);
|
|
29560
|
+
connection.on("close", () => fail7(Error("CLOSED")));
|
|
29561
|
+
const call = (destination, path30, iface, member, signature = "", body = () => {
|
|
29562
|
+
}) => new Promise((done, failed) => {
|
|
29563
|
+
const payload2 = new Writer();
|
|
29564
|
+
body(payload2);
|
|
29565
|
+
const header = new Writer(), fields = [[1, "o", path30], [2, "s", iface], [3, "s", member], [6, "s", destination]];
|
|
29566
|
+
if (signature) fields.push([8, "g", signature]);
|
|
29567
|
+
header.byte(108);
|
|
29568
|
+
header.byte(1);
|
|
29569
|
+
header.byte(0);
|
|
29570
|
+
header.byte(1);
|
|
29571
|
+
header.u32(payload2.bytes.length);
|
|
29572
|
+
header.u32(++serial);
|
|
29573
|
+
header.u32(0);
|
|
29574
|
+
const lengthAt = header.bytes.length - 4;
|
|
29575
|
+
header.align(8);
|
|
29576
|
+
const start = header.bytes.length;
|
|
29577
|
+
for (const [code, type, value] of fields) {
|
|
29578
|
+
header.align(8);
|
|
29579
|
+
header.byte(code);
|
|
29580
|
+
header.sig(type);
|
|
29581
|
+
header.put(type, value);
|
|
29582
|
+
}
|
|
29583
|
+
const length = header.bytes.length - start;
|
|
29584
|
+
header.bytes.splice(lengthAt, 4, length & 255, length >>> 8 & 255, length >>> 16 & 255, length >>> 24 & 255);
|
|
29585
|
+
header.align(8);
|
|
29586
|
+
pending.set(serial, (reply) => reply.type === 3 ? failed(Error(reply.errorName ?? "DBUS_ERROR")) : done(reply));
|
|
29587
|
+
connection.write(Buffer.from([...header.bytes, ...payload2.bytes]));
|
|
29588
|
+
});
|
|
29589
|
+
const bus = (member, signature, body) => call("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", member, signature, body);
|
|
29590
|
+
connection.on("data", (chunk) => {
|
|
29591
|
+
try {
|
|
29592
|
+
receive(chunk);
|
|
29593
|
+
} catch (error62) {
|
|
29594
|
+
fail7(error62);
|
|
29595
|
+
}
|
|
29596
|
+
});
|
|
29597
|
+
const receive = (chunk) => {
|
|
29598
|
+
buffer = Buffer.concat([buffer, chunk]);
|
|
29599
|
+
if (buffer.length > 1048576) return fail7(Error("OVERSIZED"));
|
|
29600
|
+
if (!authenticated) {
|
|
29601
|
+
const end = buffer.indexOf("\r\n");
|
|
29602
|
+
if (end < 0) return;
|
|
29603
|
+
const line = buffer.toString("ascii", 0, end);
|
|
29604
|
+
buffer = buffer.subarray(end + 2);
|
|
29605
|
+
if (!line.startsWith("OK ")) return fail7(Error("AUTH"));
|
|
29606
|
+
authenticated = true;
|
|
29607
|
+
connection.write("BEGIN\r\n");
|
|
29608
|
+
void (async () => {
|
|
29609
|
+
const unique = String((await bus("Hello")).body[0]);
|
|
29610
|
+
requestPath = "/org/freedesktop/portal/desktop/request/" + unique.slice(1).replace(/\./g, "_") + "/" + token;
|
|
29611
|
+
await bus("AddMatch", "s", (w) => w.put("s", "type='signal',interface='org.freedesktop.portal.Request',member='Response',path='" + requestPath + "'"));
|
|
29612
|
+
const handle = await call(
|
|
29613
|
+
"org.freedesktop.portal.Desktop",
|
|
29614
|
+
"/org/freedesktop/portal/desktop",
|
|
29615
|
+
"org.freedesktop.portal.Screenshot",
|
|
29616
|
+
"Screenshot",
|
|
29617
|
+
"sa{sv}",
|
|
29618
|
+
(w) => {
|
|
29619
|
+
w.put("s", "");
|
|
29620
|
+
w.dict([["handle_token", ["s", token]], ["interactive", ["b", false]]]);
|
|
29621
|
+
}
|
|
29622
|
+
);
|
|
29623
|
+
if (handle.body[0] !== requestPath) {
|
|
29624
|
+
requestPath = String(handle.body[0]);
|
|
29625
|
+
await bus("AddMatch", "s", (w) => w.put("s", "type='signal',interface='org.freedesktop.portal.Request',member='Response',path='" + requestPath + "'"));
|
|
29626
|
+
}
|
|
29627
|
+
})().catch(fail7);
|
|
29628
|
+
}
|
|
29629
|
+
for (let length = frameLength(buffer); authenticated && length; length = frameLength(buffer)) {
|
|
29630
|
+
const message2 = parse3(buffer.subarray(0, length));
|
|
29631
|
+
buffer = buffer.subarray(length);
|
|
29632
|
+
if ((message2.type === 2 || message2.type === 3) && message2.replySerial !== void 0) {
|
|
29633
|
+
pending.get(message2.replySerial)?.(message2);
|
|
29634
|
+
pending.delete(message2.replySerial);
|
|
29635
|
+
} else if (message2.type === 4 && message2.member === "Response" && message2.path === requestPath && message2.signature === "ua{sv}") {
|
|
29636
|
+
const results2 = message2.body[1], uri = results2.find(([key]) => key === "uri")?.[1];
|
|
29637
|
+
resolve({ code: Number(message2.body[0]), uri: typeof uri === "string" ? uri : void 0 });
|
|
29638
|
+
}
|
|
29639
|
+
}
|
|
29640
|
+
};
|
|
29641
|
+
connection.on("connect", () => connection.write("\0AUTH EXTERNAL " + Buffer.from(String(uid), "ascii").toString("hex") + "\r\n"));
|
|
29642
|
+
});
|
|
29643
|
+
} finally {
|
|
29644
|
+
connection.destroy();
|
|
29645
|
+
}
|
|
29646
|
+
}
|
|
29647
|
+
|
|
29648
|
+
// agent/src/screen-image.ts
|
|
29649
|
+
import { inflateSync } from "node:zlib";
|
|
29650
|
+
var MAX_EDGE = 16384;
|
|
29651
|
+
var MAX_PIXELS = 67108864;
|
|
29652
|
+
function sizeOk(width, height) {
|
|
29653
|
+
return Number.isSafeInteger(width) && Number.isSafeInteger(height) && width > 0 && height > 0 && width <= MAX_EDGE && height <= MAX_EDGE && width * height <= MAX_PIXELS;
|
|
29654
|
+
}
|
|
29655
|
+
function decodePng(data) {
|
|
29656
|
+
if (data.length < 33 || data.readUInt32BE(0) !== 2303741511 || data.readUInt32BE(4) !== 218765834) return null;
|
|
29657
|
+
let width = 0, height = 0, channels = 0;
|
|
29658
|
+
const idat = [];
|
|
29659
|
+
for (let at = 8; at + 12 <= data.length; ) {
|
|
29660
|
+
const length = data.readUInt32BE(at), type = data.toString("latin1", at + 4, at + 8), body = at + 8;
|
|
29661
|
+
if (body + length + 4 > data.length) return null;
|
|
29662
|
+
if (type === "IHDR") {
|
|
29663
|
+
if (length !== 13) return null;
|
|
29664
|
+
width = data.readUInt32BE(body);
|
|
29665
|
+
height = data.readUInt32BE(body + 4);
|
|
29666
|
+
const depth = data[body + 8], color = data[body + 9], interlace = data[body + 12];
|
|
29667
|
+
channels = color === 0 ? 1 : color === 2 ? 3 : color === 4 ? 2 : color === 6 ? 4 : 0;
|
|
29668
|
+
if (depth !== 8 || !channels || interlace !== 0 || data[body + 10] !== 0 || data[body + 11] !== 0 || !sizeOk(width, height)) return null;
|
|
29669
|
+
} else if (type === "IDAT") idat.push(data.subarray(body, body + length));
|
|
29670
|
+
else if (type === "IEND") break;
|
|
29671
|
+
at = body + length + 4;
|
|
29672
|
+
}
|
|
29673
|
+
if (!channels || !idat.length) return null;
|
|
29674
|
+
const stride = width * channels, expected = (stride + 1) * height;
|
|
29675
|
+
let raw;
|
|
29676
|
+
try {
|
|
29677
|
+
raw = inflateSync(Buffer.concat(idat), { maxOutputLength: expected });
|
|
29678
|
+
} catch {
|
|
29679
|
+
return null;
|
|
29680
|
+
}
|
|
29681
|
+
if (raw.length !== expected) return null;
|
|
29682
|
+
const rgb = Buffer.alloc(width * height * 3);
|
|
29683
|
+
let previous = Buffer.alloc(stride), current2 = Buffer.alloc(stride);
|
|
29684
|
+
for (let y = 0; y < height; y++) {
|
|
29685
|
+
const filter = raw[y * (stride + 1)], line = raw.subarray(y * (stride + 1) + 1, (y + 1) * (stride + 1));
|
|
29686
|
+
for (let x = 0; x < stride; x++) {
|
|
29687
|
+
const a = x >= channels ? current2[x - channels] : 0, b = previous[x], c = x >= channels ? previous[x - channels] : 0;
|
|
29688
|
+
let value = line[x];
|
|
29689
|
+
if (filter === 1) value += a;
|
|
29690
|
+
else if (filter === 2) value += b;
|
|
29691
|
+
else if (filter === 3) value += a + b >> 1;
|
|
29692
|
+
else if (filter === 4) {
|
|
29693
|
+
const p = a + b - c, pa = Math.abs(p - a), pb = Math.abs(p - b), pc = Math.abs(p - c);
|
|
29694
|
+
value += pa <= pb && pa <= pc ? a : pb <= pc ? b : c;
|
|
29695
|
+
} else if (filter !== 0) return null;
|
|
29696
|
+
current2[x] = value & 255;
|
|
29697
|
+
}
|
|
29698
|
+
for (let x = 0, o = y * width * 3; x < width; x++, o += 3) {
|
|
29699
|
+
const i = x * channels;
|
|
29700
|
+
if (channels <= 2) rgb[o] = rgb[o + 1] = rgb[o + 2] = current2[i];
|
|
29701
|
+
else {
|
|
29702
|
+
rgb[o] = current2[i];
|
|
29703
|
+
rgb[o + 1] = current2[i + 1];
|
|
29704
|
+
rgb[o + 2] = current2[i + 2];
|
|
29705
|
+
}
|
|
29706
|
+
}
|
|
29707
|
+
[previous, current2] = [current2, previous];
|
|
29708
|
+
}
|
|
29709
|
+
return { width, height, rgb };
|
|
29710
|
+
}
|
|
29711
|
+
function decodeXwd(data) {
|
|
29712
|
+
if (data.length < 100) return null;
|
|
29713
|
+
const field = (index) => data.readUInt32BE(index * 4);
|
|
29714
|
+
const headerSize = field(0), version2 = field(1), format = field(2), width = field(4), height = field(5), byteOrder = field(7);
|
|
29715
|
+
const bitsPerPixel = field(11), bytesPerLine = field(12), visualClass = field(13), masks = [field(14), field(15), field(16)], colors = field(19);
|
|
29716
|
+
if (version2 !== 7 || format !== 2 || headerSize < 100 || ![4, 5].includes(visualClass) || ![24, 32].includes(bitsPerPixel) || !sizeOk(width, height) || colors > 65536) return null;
|
|
29717
|
+
const pixelBytes = bitsPerPixel / 8, start = headerSize + colors * 12;
|
|
29718
|
+
if (bytesPerLine < width * pixelBytes || start + bytesPerLine * height > data.length || masks.some((mask) => !mask)) return null;
|
|
29719
|
+
const shifts = masks.map((mask) => {
|
|
29720
|
+
let shift = 0;
|
|
29721
|
+
while (!(mask >>> shift & 1)) shift++;
|
|
29722
|
+
return shift;
|
|
29723
|
+
});
|
|
29724
|
+
const scales = masks.map((mask, i) => 255 / (mask >>> shifts[i]));
|
|
29725
|
+
const rgb = Buffer.alloc(width * height * 3);
|
|
29726
|
+
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) {
|
|
29727
|
+
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];
|
|
29728
|
+
for (let c = 0; c < 3; c++) rgb[o + c] = Math.round(((pixel & masks[c]) >>> 0 >>> shifts[c]) * scales[c]);
|
|
29729
|
+
}
|
|
29730
|
+
return { width, height, rgb };
|
|
29731
|
+
}
|
|
29732
|
+
function downscale(image, edge) {
|
|
29733
|
+
const scale = Math.min(1, edge / Math.max(image.width, image.height));
|
|
29734
|
+
if (scale >= 1) return image;
|
|
29735
|
+
const width = Math.max(1, Math.round(image.width * scale)), height = Math.max(1, Math.round(image.height * scale));
|
|
29736
|
+
const xs = Array.from({ length: width + 1 }, (_, x) => Math.min(image.width, Math.floor(x * image.width / width)));
|
|
29737
|
+
const ys = Array.from({ length: height + 1 }, (_, y) => Math.min(image.height, Math.floor(y * image.height / height)));
|
|
29738
|
+
const rgb = Buffer.alloc(width * height * 3), sums = new Float64Array(width * 3);
|
|
29739
|
+
for (let y = 0; y < height; y++) {
|
|
29740
|
+
sums.fill(0);
|
|
29741
|
+
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++) {
|
|
29742
|
+
const i = (sy * image.width + sx) * 3;
|
|
29743
|
+
sums[x * 3] = sums[x * 3] + image.rgb[i];
|
|
29744
|
+
sums[x * 3 + 1] = sums[x * 3 + 1] + image.rgb[i + 1];
|
|
29745
|
+
sums[x * 3 + 2] = sums[x * 3 + 2] + image.rgb[i + 2];
|
|
29746
|
+
}
|
|
29747
|
+
for (let x = 0; x < width; x++) {
|
|
29748
|
+
const count3 = (ys[y + 1] - ys[y]) * (xs[x + 1] - xs[x]);
|
|
29749
|
+
for (let c = 0; c < 3; c++) rgb[(y * width + x) * 3 + c] = Math.round(sums[x * 3 + c] / count3);
|
|
29750
|
+
}
|
|
29751
|
+
}
|
|
29752
|
+
return { width, height, rgb };
|
|
29753
|
+
}
|
|
29754
|
+
var ZIGZAG = [
|
|
29755
|
+
0,
|
|
29756
|
+
1,
|
|
29757
|
+
5,
|
|
29758
|
+
6,
|
|
29759
|
+
14,
|
|
29760
|
+
15,
|
|
29761
|
+
27,
|
|
29762
|
+
28,
|
|
29763
|
+
2,
|
|
29764
|
+
4,
|
|
29765
|
+
7,
|
|
29766
|
+
13,
|
|
29767
|
+
16,
|
|
29768
|
+
26,
|
|
29769
|
+
29,
|
|
29770
|
+
42,
|
|
29771
|
+
3,
|
|
29772
|
+
8,
|
|
29773
|
+
12,
|
|
29774
|
+
17,
|
|
29775
|
+
25,
|
|
29776
|
+
30,
|
|
29777
|
+
41,
|
|
29778
|
+
43,
|
|
29779
|
+
9,
|
|
29780
|
+
11,
|
|
29781
|
+
18,
|
|
29782
|
+
24,
|
|
29783
|
+
31,
|
|
29784
|
+
40,
|
|
29785
|
+
44,
|
|
29786
|
+
53,
|
|
29787
|
+
10,
|
|
29788
|
+
19,
|
|
29789
|
+
23,
|
|
29790
|
+
32,
|
|
29791
|
+
39,
|
|
29792
|
+
45,
|
|
29793
|
+
52,
|
|
29794
|
+
54,
|
|
29795
|
+
20,
|
|
29796
|
+
22,
|
|
29797
|
+
33,
|
|
29798
|
+
38,
|
|
29799
|
+
46,
|
|
29800
|
+
51,
|
|
29801
|
+
55,
|
|
29802
|
+
60,
|
|
29803
|
+
21,
|
|
29804
|
+
34,
|
|
29805
|
+
37,
|
|
29806
|
+
47,
|
|
29807
|
+
50,
|
|
29808
|
+
56,
|
|
29809
|
+
59,
|
|
29810
|
+
61,
|
|
29811
|
+
35,
|
|
29812
|
+
36,
|
|
29813
|
+
48,
|
|
29814
|
+
49,
|
|
29815
|
+
57,
|
|
29816
|
+
58,
|
|
29817
|
+
62,
|
|
29818
|
+
63
|
|
29819
|
+
];
|
|
29820
|
+
var LUMA_QUANT = [
|
|
29821
|
+
16,
|
|
29822
|
+
11,
|
|
29823
|
+
10,
|
|
29824
|
+
16,
|
|
29825
|
+
24,
|
|
29826
|
+
40,
|
|
29827
|
+
51,
|
|
29828
|
+
61,
|
|
29829
|
+
12,
|
|
29830
|
+
12,
|
|
29831
|
+
14,
|
|
29832
|
+
19,
|
|
29833
|
+
26,
|
|
29834
|
+
58,
|
|
29835
|
+
60,
|
|
29836
|
+
55,
|
|
29837
|
+
14,
|
|
29838
|
+
13,
|
|
29839
|
+
16,
|
|
29840
|
+
24,
|
|
29841
|
+
40,
|
|
29842
|
+
57,
|
|
29843
|
+
69,
|
|
29844
|
+
56,
|
|
29845
|
+
14,
|
|
29846
|
+
17,
|
|
29847
|
+
22,
|
|
29848
|
+
29,
|
|
29849
|
+
51,
|
|
29850
|
+
87,
|
|
29851
|
+
80,
|
|
29852
|
+
62,
|
|
29853
|
+
18,
|
|
29854
|
+
22,
|
|
29855
|
+
37,
|
|
29856
|
+
56,
|
|
29857
|
+
68,
|
|
29858
|
+
109,
|
|
29859
|
+
103,
|
|
29860
|
+
77,
|
|
29861
|
+
24,
|
|
29862
|
+
35,
|
|
29863
|
+
55,
|
|
29864
|
+
64,
|
|
29865
|
+
81,
|
|
29866
|
+
104,
|
|
29867
|
+
113,
|
|
29868
|
+
92,
|
|
29869
|
+
49,
|
|
29870
|
+
64,
|
|
29871
|
+
78,
|
|
29872
|
+
87,
|
|
29873
|
+
103,
|
|
29874
|
+
121,
|
|
29875
|
+
120,
|
|
29876
|
+
101,
|
|
29877
|
+
72,
|
|
29878
|
+
92,
|
|
29879
|
+
95,
|
|
29880
|
+
98,
|
|
29881
|
+
112,
|
|
29882
|
+
100,
|
|
29883
|
+
103,
|
|
29884
|
+
99
|
|
29885
|
+
];
|
|
29886
|
+
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)];
|
|
29887
|
+
var AC_LUMA_VALUES = [
|
|
29888
|
+
1,
|
|
29889
|
+
2,
|
|
29890
|
+
3,
|
|
29891
|
+
0,
|
|
29892
|
+
4,
|
|
29893
|
+
17,
|
|
29894
|
+
5,
|
|
29895
|
+
18,
|
|
29896
|
+
33,
|
|
29897
|
+
49,
|
|
29898
|
+
65,
|
|
29899
|
+
6,
|
|
29900
|
+
19,
|
|
29901
|
+
81,
|
|
29902
|
+
97,
|
|
29903
|
+
7,
|
|
29904
|
+
34,
|
|
29905
|
+
113,
|
|
29906
|
+
20,
|
|
29907
|
+
50,
|
|
29908
|
+
129,
|
|
29909
|
+
145,
|
|
29910
|
+
161,
|
|
29911
|
+
8,
|
|
29912
|
+
35,
|
|
29913
|
+
66,
|
|
29914
|
+
177,
|
|
29915
|
+
193,
|
|
29916
|
+
21,
|
|
29917
|
+
82,
|
|
29918
|
+
209,
|
|
29919
|
+
240,
|
|
29920
|
+
36,
|
|
29921
|
+
51,
|
|
29922
|
+
98,
|
|
29923
|
+
114,
|
|
29924
|
+
130,
|
|
29925
|
+
9,
|
|
29926
|
+
10,
|
|
29927
|
+
22,
|
|
29928
|
+
23,
|
|
29929
|
+
24,
|
|
29930
|
+
25,
|
|
29931
|
+
26,
|
|
29932
|
+
37,
|
|
29933
|
+
38,
|
|
29934
|
+
39,
|
|
29935
|
+
40,
|
|
29936
|
+
41,
|
|
29937
|
+
42,
|
|
29938
|
+
52,
|
|
29939
|
+
53,
|
|
29940
|
+
54,
|
|
29941
|
+
55,
|
|
29942
|
+
56,
|
|
29943
|
+
57,
|
|
29944
|
+
58,
|
|
29945
|
+
67,
|
|
29946
|
+
68,
|
|
29947
|
+
69,
|
|
29948
|
+
70,
|
|
29949
|
+
71,
|
|
29950
|
+
72,
|
|
29951
|
+
73,
|
|
29952
|
+
74,
|
|
29953
|
+
83,
|
|
29954
|
+
84,
|
|
29955
|
+
85,
|
|
29956
|
+
86,
|
|
29957
|
+
87,
|
|
29958
|
+
88,
|
|
29959
|
+
89,
|
|
29960
|
+
90,
|
|
29961
|
+
99,
|
|
29962
|
+
100,
|
|
29963
|
+
101,
|
|
29964
|
+
102,
|
|
29965
|
+
103,
|
|
29966
|
+
104,
|
|
29967
|
+
105,
|
|
29968
|
+
106,
|
|
29969
|
+
115,
|
|
29970
|
+
116,
|
|
29971
|
+
117,
|
|
29972
|
+
118,
|
|
29973
|
+
119,
|
|
29974
|
+
120,
|
|
29975
|
+
121,
|
|
29976
|
+
122,
|
|
29977
|
+
131,
|
|
29978
|
+
132,
|
|
29979
|
+
133,
|
|
29980
|
+
134,
|
|
29981
|
+
135,
|
|
29982
|
+
136,
|
|
29983
|
+
137,
|
|
29984
|
+
138,
|
|
29985
|
+
146,
|
|
29986
|
+
147,
|
|
29987
|
+
148,
|
|
29988
|
+
149,
|
|
29989
|
+
150,
|
|
29990
|
+
151,
|
|
29991
|
+
152,
|
|
29992
|
+
153,
|
|
29993
|
+
154,
|
|
29994
|
+
162,
|
|
29995
|
+
163,
|
|
29996
|
+
164,
|
|
29997
|
+
165,
|
|
29998
|
+
166,
|
|
29999
|
+
167,
|
|
30000
|
+
168,
|
|
30001
|
+
169,
|
|
30002
|
+
170,
|
|
30003
|
+
178,
|
|
30004
|
+
179,
|
|
30005
|
+
180,
|
|
30006
|
+
181,
|
|
30007
|
+
182,
|
|
30008
|
+
183,
|
|
30009
|
+
184,
|
|
30010
|
+
185,
|
|
30011
|
+
186,
|
|
30012
|
+
194,
|
|
30013
|
+
195,
|
|
30014
|
+
196,
|
|
30015
|
+
197,
|
|
30016
|
+
198,
|
|
30017
|
+
199,
|
|
30018
|
+
200,
|
|
30019
|
+
201,
|
|
30020
|
+
202,
|
|
30021
|
+
210,
|
|
30022
|
+
211,
|
|
30023
|
+
212,
|
|
30024
|
+
213,
|
|
30025
|
+
214,
|
|
30026
|
+
215,
|
|
30027
|
+
216,
|
|
30028
|
+
217,
|
|
30029
|
+
218,
|
|
30030
|
+
225,
|
|
30031
|
+
226,
|
|
30032
|
+
227,
|
|
30033
|
+
228,
|
|
30034
|
+
229,
|
|
30035
|
+
230,
|
|
30036
|
+
231,
|
|
30037
|
+
232,
|
|
30038
|
+
233,
|
|
30039
|
+
234,
|
|
30040
|
+
241,
|
|
30041
|
+
242,
|
|
30042
|
+
243,
|
|
30043
|
+
244,
|
|
30044
|
+
245,
|
|
30045
|
+
246,
|
|
30046
|
+
247,
|
|
30047
|
+
248,
|
|
30048
|
+
249,
|
|
30049
|
+
250
|
|
30050
|
+
];
|
|
30051
|
+
var AC_CHROMA_VALUES = [
|
|
30052
|
+
0,
|
|
30053
|
+
1,
|
|
30054
|
+
2,
|
|
30055
|
+
3,
|
|
30056
|
+
17,
|
|
30057
|
+
4,
|
|
30058
|
+
5,
|
|
30059
|
+
33,
|
|
30060
|
+
49,
|
|
30061
|
+
6,
|
|
30062
|
+
18,
|
|
30063
|
+
65,
|
|
30064
|
+
81,
|
|
30065
|
+
7,
|
|
30066
|
+
97,
|
|
30067
|
+
113,
|
|
30068
|
+
19,
|
|
30069
|
+
34,
|
|
30070
|
+
50,
|
|
30071
|
+
129,
|
|
30072
|
+
8,
|
|
30073
|
+
20,
|
|
30074
|
+
66,
|
|
30075
|
+
145,
|
|
30076
|
+
161,
|
|
30077
|
+
177,
|
|
30078
|
+
193,
|
|
30079
|
+
9,
|
|
30080
|
+
35,
|
|
30081
|
+
51,
|
|
30082
|
+
82,
|
|
30083
|
+
240,
|
|
30084
|
+
21,
|
|
30085
|
+
98,
|
|
30086
|
+
114,
|
|
30087
|
+
209,
|
|
30088
|
+
10,
|
|
30089
|
+
22,
|
|
30090
|
+
36,
|
|
30091
|
+
52,
|
|
30092
|
+
225,
|
|
30093
|
+
37,
|
|
30094
|
+
241,
|
|
30095
|
+
23,
|
|
30096
|
+
24,
|
|
30097
|
+
25,
|
|
30098
|
+
26,
|
|
30099
|
+
38,
|
|
30100
|
+
39,
|
|
30101
|
+
40,
|
|
30102
|
+
41,
|
|
30103
|
+
42,
|
|
30104
|
+
53,
|
|
30105
|
+
54,
|
|
30106
|
+
55,
|
|
30107
|
+
56,
|
|
30108
|
+
57,
|
|
30109
|
+
58,
|
|
30110
|
+
67,
|
|
30111
|
+
68,
|
|
30112
|
+
69,
|
|
30113
|
+
70,
|
|
30114
|
+
71,
|
|
30115
|
+
72,
|
|
30116
|
+
73,
|
|
30117
|
+
74,
|
|
30118
|
+
83,
|
|
30119
|
+
84,
|
|
30120
|
+
85,
|
|
30121
|
+
86,
|
|
30122
|
+
87,
|
|
30123
|
+
88,
|
|
30124
|
+
89,
|
|
30125
|
+
90,
|
|
30126
|
+
99,
|
|
30127
|
+
100,
|
|
30128
|
+
101,
|
|
30129
|
+
102,
|
|
30130
|
+
103,
|
|
30131
|
+
104,
|
|
30132
|
+
105,
|
|
30133
|
+
106,
|
|
30134
|
+
115,
|
|
30135
|
+
116,
|
|
30136
|
+
117,
|
|
30137
|
+
118,
|
|
30138
|
+
119,
|
|
30139
|
+
120,
|
|
30140
|
+
121,
|
|
30141
|
+
122,
|
|
30142
|
+
130,
|
|
30143
|
+
131,
|
|
30144
|
+
132,
|
|
30145
|
+
133,
|
|
30146
|
+
134,
|
|
30147
|
+
135,
|
|
30148
|
+
136,
|
|
30149
|
+
137,
|
|
30150
|
+
138,
|
|
30151
|
+
146,
|
|
30152
|
+
147,
|
|
30153
|
+
148,
|
|
30154
|
+
149,
|
|
30155
|
+
150,
|
|
30156
|
+
151,
|
|
30157
|
+
152,
|
|
30158
|
+
153,
|
|
30159
|
+
154,
|
|
30160
|
+
162,
|
|
30161
|
+
163,
|
|
30162
|
+
164,
|
|
30163
|
+
165,
|
|
30164
|
+
166,
|
|
30165
|
+
167,
|
|
30166
|
+
168,
|
|
30167
|
+
169,
|
|
30168
|
+
170,
|
|
30169
|
+
178,
|
|
30170
|
+
179,
|
|
30171
|
+
180,
|
|
30172
|
+
181,
|
|
30173
|
+
182,
|
|
30174
|
+
183,
|
|
30175
|
+
184,
|
|
30176
|
+
185,
|
|
30177
|
+
186,
|
|
30178
|
+
194,
|
|
30179
|
+
195,
|
|
30180
|
+
196,
|
|
30181
|
+
197,
|
|
30182
|
+
198,
|
|
30183
|
+
199,
|
|
30184
|
+
200,
|
|
30185
|
+
201,
|
|
30186
|
+
202,
|
|
30187
|
+
210,
|
|
30188
|
+
211,
|
|
30189
|
+
212,
|
|
30190
|
+
213,
|
|
30191
|
+
214,
|
|
30192
|
+
215,
|
|
30193
|
+
216,
|
|
30194
|
+
217,
|
|
30195
|
+
218,
|
|
30196
|
+
226,
|
|
30197
|
+
227,
|
|
30198
|
+
228,
|
|
30199
|
+
229,
|
|
30200
|
+
230,
|
|
30201
|
+
231,
|
|
30202
|
+
232,
|
|
30203
|
+
233,
|
|
30204
|
+
234,
|
|
30205
|
+
242,
|
|
30206
|
+
243,
|
|
30207
|
+
244,
|
|
30208
|
+
245,
|
|
30209
|
+
246,
|
|
30210
|
+
247,
|
|
30211
|
+
248,
|
|
30212
|
+
249,
|
|
30213
|
+
250
|
|
30214
|
+
];
|
|
30215
|
+
var DC_VALUES = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
|
|
30216
|
+
var HUFFMAN = [
|
|
30217
|
+
[0, [0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0], DC_VALUES],
|
|
30218
|
+
[16, [0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125], AC_LUMA_VALUES],
|
|
30219
|
+
[1, [0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0], DC_VALUES],
|
|
30220
|
+
[17, [0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 119], AC_CHROMA_VALUES]
|
|
30221
|
+
];
|
|
30222
|
+
var CODES = HUFFMAN.map(([, counts, values]) => {
|
|
30223
|
+
const table2 = [];
|
|
30224
|
+
let code = 0, at = 0;
|
|
30225
|
+
counts.forEach((count3, index) => {
|
|
30226
|
+
for (let i = 0; i < count3; i++) table2[values[at++]] = [code++, index + 1];
|
|
30227
|
+
code <<= 1;
|
|
30228
|
+
});
|
|
30229
|
+
return table2;
|
|
30230
|
+
});
|
|
30231
|
+
var AAN = [1, 1.387039845, 1.306562965, 1.175875602, 1, 0.785694958, 0.5411961, 0.275899379];
|
|
30232
|
+
function quantTables(quality) {
|
|
30233
|
+
const factor = quality < 50 ? 5e3 / quality : 200 - quality * 2;
|
|
30234
|
+
const scaled = (base) => base.map((value) => Math.min(255, Math.max(1, Math.floor((value * factor + 50) / 100))));
|
|
30235
|
+
const divisors = (table2) => Float64Array.from(table2, (value, k) => 1 / (value * AAN[k >> 3] * AAN[k & 7] * 8));
|
|
30236
|
+
const luma = scaled(LUMA_QUANT), chroma = scaled(CHROMA_QUANT);
|
|
30237
|
+
return { luma, chroma, lumaDivisors: divisors(luma), chromaDivisors: divisors(chroma) };
|
|
30238
|
+
}
|
|
30239
|
+
var BitWriter = class {
|
|
30240
|
+
buffer = Buffer.alloc(65536);
|
|
30241
|
+
length = 0;
|
|
30242
|
+
bits = 0;
|
|
30243
|
+
count = 0;
|
|
30244
|
+
byte(value) {
|
|
30245
|
+
if (this.length === this.buffer.length) {
|
|
30246
|
+
const next = Buffer.alloc(this.buffer.length * 2);
|
|
30247
|
+
this.buffer.copy(next);
|
|
30248
|
+
this.buffer = next;
|
|
30249
|
+
}
|
|
30250
|
+
this.buffer[this.length++] = value;
|
|
30251
|
+
}
|
|
30252
|
+
bytes(values) {
|
|
30253
|
+
for (const value of values) this.byte(value);
|
|
30254
|
+
}
|
|
30255
|
+
write(code, length) {
|
|
30256
|
+
this.bits = (this.bits << length | code) >>> 0;
|
|
30257
|
+
this.count += length;
|
|
30258
|
+
while (this.count >= 8) {
|
|
30259
|
+
const value = this.bits >>> this.count - 8 & 255;
|
|
30260
|
+
this.byte(value);
|
|
30261
|
+
if (value === 255) this.byte(0);
|
|
30262
|
+
this.count -= 8;
|
|
30263
|
+
this.bits &= (1 << this.count) - 1;
|
|
30264
|
+
}
|
|
30265
|
+
}
|
|
30266
|
+
flush() {
|
|
30267
|
+
if (this.count > 0) this.write((1 << 8 - this.count) - 1, 8 - this.count);
|
|
30268
|
+
}
|
|
30269
|
+
result() {
|
|
30270
|
+
return Buffer.from(this.buffer.subarray(0, this.length));
|
|
30271
|
+
}
|
|
30272
|
+
};
|
|
30273
|
+
function transform2(block, divisors, out) {
|
|
30274
|
+
for (let pass = 0; pass < 2; pass++) for (let i = 0; i < 8; i++) {
|
|
30275
|
+
const step = pass ? 8 : 1, base = pass ? i : i * 8, at = (k) => base + k * step;
|
|
30276
|
+
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)];
|
|
30277
|
+
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;
|
|
30278
|
+
const t10 = t0 + t3, t13 = t0 - t3, t11 = t1 + t2, t12 = t1 - t2;
|
|
30279
|
+
block[at(0)] = t10 + t11;
|
|
30280
|
+
block[at(4)] = t10 - t11;
|
|
30281
|
+
const z1 = (t12 + t13) * 0.707106781;
|
|
30282
|
+
block[at(2)] = t13 + z1;
|
|
30283
|
+
block[at(6)] = t13 - z1;
|
|
30284
|
+
const o10 = t4 + t5, o11 = t5 + t6, o12 = t6 + t7;
|
|
30285
|
+
const z5 = (o10 - o12) * 0.382683433, z2 = 0.5411961 * o10 + z5, z4 = 1.306562965 * o12 + z5, z3 = o11 * 0.707106781;
|
|
30286
|
+
const z11 = t7 + z3, z13 = t7 - z3;
|
|
30287
|
+
block[at(5)] = z13 + z2;
|
|
30288
|
+
block[at(3)] = z13 - z2;
|
|
30289
|
+
block[at(1)] = z11 + z4;
|
|
30290
|
+
block[at(7)] = z11 - z4;
|
|
30291
|
+
}
|
|
30292
|
+
for (let k = 0; k < 64; k++) out[ZIGZAG[k]] = Math.round(block[k] * divisors[k]);
|
|
30293
|
+
}
|
|
30294
|
+
function magnitude(value) {
|
|
30295
|
+
const absolute2 = Math.abs(value);
|
|
30296
|
+
let length = 0;
|
|
30297
|
+
while (absolute2 >> length) length++;
|
|
30298
|
+
return [value < 0 ? value + (1 << length) - 1 : value, length];
|
|
30299
|
+
}
|
|
30300
|
+
function encodeJpeg(image, quality) {
|
|
30301
|
+
const { width, height, rgb } = image, tables = quantTables(Math.min(100, Math.max(1, Math.round(quality))));
|
|
30302
|
+
const out = new BitWriter(), word = (value) => [value >> 8, value & 255];
|
|
30303
|
+
out.bytes([255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0]);
|
|
30304
|
+
out.bytes([255, 219, 0, 132]);
|
|
30305
|
+
for (const [id2, table2] of [[0, tables.luma], [1, tables.chroma]]) {
|
|
30306
|
+
const zig = new Array(64);
|
|
30307
|
+
table2.forEach((value, k) => {
|
|
30308
|
+
zig[ZIGZAG[k]] = value;
|
|
30309
|
+
});
|
|
30310
|
+
out.bytes([id2, ...zig]);
|
|
30311
|
+
}
|
|
30312
|
+
out.bytes([255, 192, 0, 17, 8, ...word(height), ...word(width), 3, 1, 34, 0, 2, 17, 1, 3, 17, 1]);
|
|
30313
|
+
out.bytes([255, 196, ...word(2 + HUFFMAN.reduce((sum, [, , values]) => sum + 17 + values.length, 0))]);
|
|
30314
|
+
for (const [id2, counts, values] of HUFFMAN) out.bytes([id2, ...counts, ...values]);
|
|
30315
|
+
out.bytes([255, 218, 0, 12, 3, 1, 0, 2, 17, 3, 17, 0, 63, 0]);
|
|
30316
|
+
const block = new Float64Array(64), coefficients = new Int32Array(64), dc = [0, 0, 0];
|
|
30317
|
+
const Y = new Float64Array(256), Cb = new Float64Array(256), Cr = new Float64Array(256);
|
|
30318
|
+
const encode5 = (component, divisors) => {
|
|
30319
|
+
transform2(block, divisors, coefficients);
|
|
30320
|
+
const dcCodes = CODES[component ? 2 : 0], acCodes = CODES[component ? 3 : 1];
|
|
30321
|
+
const diff = coefficients[0] - dc[component];
|
|
30322
|
+
dc[component] = coefficients[0];
|
|
30323
|
+
const [bits, size] = magnitude(diff);
|
|
30324
|
+
out.write(...dcCodes[size]);
|
|
30325
|
+
if (size) out.write(bits, size);
|
|
30326
|
+
let last = 63;
|
|
30327
|
+
while (last > 0 && coefficients[last] === 0) last--;
|
|
30328
|
+
for (let k = 1, zeros = 0; k <= last; k++) {
|
|
30329
|
+
if (coefficients[k] === 0) {
|
|
30330
|
+
zeros++;
|
|
30331
|
+
continue;
|
|
30332
|
+
}
|
|
30333
|
+
while (zeros >= 16) {
|
|
30334
|
+
out.write(...acCodes[240]);
|
|
30335
|
+
zeros -= 16;
|
|
30336
|
+
}
|
|
30337
|
+
const [value, length] = magnitude(coefficients[k]);
|
|
30338
|
+
out.write(...acCodes[(zeros << 4) + length]);
|
|
30339
|
+
out.write(value, length);
|
|
30340
|
+
zeros = 0;
|
|
30341
|
+
}
|
|
30342
|
+
if (last < 63) out.write(...acCodes[0]);
|
|
30343
|
+
};
|
|
30344
|
+
for (let my = 0; my < height; my += 16) for (let mx = 0; mx < width; mx += 16) {
|
|
30345
|
+
for (let y = 0; y < 16; y++) for (let x = 0; x < 16; x++) {
|
|
30346
|
+
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];
|
|
30347
|
+
Y[y * 16 + x] = 0.299 * r + 0.587 * g + 0.114 * b - 128;
|
|
30348
|
+
Cb[y * 16 + x] = -0.168736 * r - 0.331264 * g + 0.5 * b;
|
|
30349
|
+
Cr[y * 16 + x] = 0.5 * r - 0.418688 * g - 0.081312 * b;
|
|
30350
|
+
}
|
|
30351
|
+
for (const [ox, oy] of [[0, 0], [8, 0], [0, 8], [8, 8]]) {
|
|
30352
|
+
for (let y = 0; y < 8; y++) for (let x = 0; x < 8; x++) block[y * 8 + x] = Y[(oy + y) * 16 + ox + x];
|
|
30353
|
+
encode5(0, tables.lumaDivisors);
|
|
30354
|
+
}
|
|
30355
|
+
for (const [component, plane] of [[1, Cb], [2, Cr]]) {
|
|
30356
|
+
for (let y = 0; y < 8; y++) for (let x = 0; x < 8; x++) {
|
|
30357
|
+
const at = y * 32 + x * 2;
|
|
30358
|
+
block[y * 8 + x] = (plane[at] + plane[at + 1] + plane[at + 16] + plane[at + 17]) / 4;
|
|
30359
|
+
}
|
|
30360
|
+
encode5(component, tables.chromaDivisors);
|
|
30361
|
+
}
|
|
30362
|
+
}
|
|
30363
|
+
out.flush();
|
|
30364
|
+
out.bytes([255, 217]);
|
|
30365
|
+
return out.result();
|
|
30366
|
+
}
|
|
30367
|
+
function fitJpeg(image, maxEdge, maxBytes) {
|
|
30368
|
+
for (const edge of [maxEdge, 1280, 1024, 800, 640]) {
|
|
30369
|
+
const scaled = downscale(image, edge);
|
|
30370
|
+
for (const quality of [75, 60, 45, 35]) {
|
|
30371
|
+
const data = encodeJpeg(scaled, quality);
|
|
30372
|
+
if (data.length <= maxBytes) return { data, width: scaled.width, height: scaled.height };
|
|
30373
|
+
}
|
|
30374
|
+
}
|
|
30375
|
+
return null;
|
|
30376
|
+
}
|
|
30377
|
+
|
|
30378
|
+
// agent/src/screen-capture.ts
|
|
29372
30379
|
var SCREENSHOT_MAX_JPEG_BYTES = 131072;
|
|
29373
30380
|
var SCREENSHOT_MAX_EDGE = 1568;
|
|
29374
30381
|
function screenshotEnabled(env = process.env) {
|
|
29375
30382
|
return env.LC_SCREENSHOT_ENABLED === "true";
|
|
29376
30383
|
}
|
|
29377
30384
|
var SCREENSHOT_ACCEPTANCE_FILE = "screenshot-acceptance-enabled";
|
|
30385
|
+
var SCREENSHOT_OWNER_OFF_FILE = "screenshot-disabled-by-owner";
|
|
29378
30386
|
var ScreenCaptureError = class extends Error {
|
|
29379
|
-
constructor(code) {
|
|
30387
|
+
constructor(code, detail) {
|
|
29380
30388
|
super(code);
|
|
29381
30389
|
this.code = code;
|
|
30390
|
+
this.detail = detail;
|
|
29382
30391
|
this.name = "ScreenCaptureError";
|
|
29383
30392
|
}
|
|
29384
30393
|
code;
|
|
30394
|
+
detail;
|
|
29385
30395
|
};
|
|
29386
30396
|
var KNOWN = /^(SCREEN_UNAVAILABLE|SCREEN_LOCKED|SCREEN_ENCODER_UNAVAILABLE|SCREENSHOT_TOO_LARGE|ARGUMENT_INVALID)$/;
|
|
29387
30397
|
function jpegSize(data) {
|
|
@@ -29397,12 +30407,12 @@ function jpegSize(data) {
|
|
|
29397
30407
|
}
|
|
29398
30408
|
return null;
|
|
29399
30409
|
}
|
|
29400
|
-
function run(file2, args, signal, maxBuffer = 65536) {
|
|
30410
|
+
function run(file2, args, signal, maxBuffer = 65536, env = buildChildEnvironment(process.env, process.platform)) {
|
|
29401
30411
|
return new Promise((resolve, reject) => {
|
|
29402
30412
|
execFile4(
|
|
29403
30413
|
file2,
|
|
29404
30414
|
args,
|
|
29405
|
-
{ encoding: "buffer", timeout: 15e3, maxBuffer, windowsHide: true, shell: false, env
|
|
30415
|
+
{ encoding: "buffer", timeout: 15e3, maxBuffer, windowsHide: true, shell: false, env, signal },
|
|
29406
30416
|
(error62, stdout, stderr) => error62 ? reject(Object.assign(error62, { stdout, stderr })) : resolve({ stdout, stderr })
|
|
29407
30417
|
);
|
|
29408
30418
|
});
|
|
@@ -29467,11 +30477,141 @@ async function mac3(signal) {
|
|
|
29467
30477
|
});
|
|
29468
30478
|
}
|
|
29469
30479
|
}
|
|
30480
|
+
var SESSION_KEYS = ["DISPLAY", "WAYLAND_DISPLAY", "XAUTHORITY", "XDG_RUNTIME_DIR", "DBUS_SESSION_BUS_ADDRESS", "XDG_SESSION_TYPE", "XDG_CURRENT_DESKTOP"];
|
|
30481
|
+
var SESSION_VALUE = /^[A-Za-z0-9_.:,;=@+/-]{1,256}$/;
|
|
30482
|
+
var LINUX_SOURCE_BYTES = 150994944;
|
|
30483
|
+
async function linuxTool(name2) {
|
|
30484
|
+
for (const directory of ["/usr/bin", "/bin", "/usr/local/bin"]) {
|
|
30485
|
+
const file2 = path17.posix.join(directory, name2);
|
|
30486
|
+
try {
|
|
30487
|
+
await access3(file2, constants7.X_OK);
|
|
30488
|
+
return file2;
|
|
30489
|
+
} catch {
|
|
30490
|
+
}
|
|
30491
|
+
}
|
|
30492
|
+
return null;
|
|
30493
|
+
}
|
|
30494
|
+
async function linuxSession(signal) {
|
|
30495
|
+
const session = {}, uid = process.getuid?.();
|
|
30496
|
+
const take = (key, value) => {
|
|
30497
|
+
if (value && !session[key] && SESSION_VALUE.test(value)) session[key] = value;
|
|
30498
|
+
};
|
|
30499
|
+
const base = buildChildEnvironment(process.env, "linux");
|
|
30500
|
+
for (const key of SESSION_KEYS) take(key, process.env[key]);
|
|
30501
|
+
if (!session.DISPLAY && !session.WAYLAND_DISPLAY) {
|
|
30502
|
+
const systemctl = await linuxTool("systemctl");
|
|
30503
|
+
if (systemctl) try {
|
|
30504
|
+
const { stdout } = await run(systemctl, ["--user", "show-environment"], signal, 262144, base);
|
|
30505
|
+
for (const line of stdout.toString("utf8").split("\n")) {
|
|
30506
|
+
const at = line.indexOf("=");
|
|
30507
|
+
if (at > 0 && SESSION_KEYS.includes(line.slice(0, at))) take(line.slice(0, at), line.slice(at + 1));
|
|
30508
|
+
}
|
|
30509
|
+
} catch {
|
|
30510
|
+
if (signal.aborted) throw new ScreenCaptureError("CANCELLED");
|
|
30511
|
+
}
|
|
30512
|
+
}
|
|
30513
|
+
if (uid !== void 0) take("XDG_RUNTIME_DIR", "/run/user/" + uid);
|
|
30514
|
+
if (!session.DISPLAY && !session.WAYLAND_DISPLAY) {
|
|
30515
|
+
if (session.XDG_RUNTIME_DIR) for (const name2 of ["wayland-0", "wayland-1"]) {
|
|
30516
|
+
const socket = await lstat7(path17.posix.join(session.XDG_RUNTIME_DIR, name2)).catch(() => null);
|
|
30517
|
+
if (socket?.isSocket() && socket.uid === uid) {
|
|
30518
|
+
session.WAYLAND_DISPLAY = name2;
|
|
30519
|
+
break;
|
|
30520
|
+
}
|
|
30521
|
+
}
|
|
30522
|
+
if (!session.WAYLAND_DISPLAY) {
|
|
30523
|
+
const servers = [];
|
|
30524
|
+
for (const name2 of await readdir4("/tmp/.X11-unix").catch(() => [])) {
|
|
30525
|
+
const n = /^X(\d{1,4})$/.exec(name2)?.[1], socket = n ? await lstat7("/tmp/.X11-unix/" + name2).catch(() => null) : null;
|
|
30526
|
+
if (n && socket?.isSocket()) servers.push({ n: Number(n), own: socket.uid === uid });
|
|
30527
|
+
}
|
|
30528
|
+
const server = servers.sort((a, b) => Number(b.own) - Number(a.own) || a.n - b.n)[0];
|
|
30529
|
+
if (server) session.DISPLAY = ":" + server.n;
|
|
30530
|
+
}
|
|
30531
|
+
}
|
|
30532
|
+
if (session.DISPLAY && !session.XAUTHORITY) {
|
|
30533
|
+
const file2 = path17.posix.join(os4.homedir(), ".Xauthority");
|
|
30534
|
+
if ((await lstat7(file2).catch(() => null))?.isFile()) take("XAUTHORITY", file2);
|
|
30535
|
+
}
|
|
30536
|
+
if (session.XDG_RUNTIME_DIR) take("DBUS_SESSION_BUS_ADDRESS", "unix:path=" + session.XDG_RUNTIME_DIR + "/bus");
|
|
30537
|
+
const wayland = !!session.WAYLAND_DISPLAY || session.XDG_SESSION_TYPE === "wayland";
|
|
30538
|
+
return { env: { ...base, ...session }, wayland, x11: !wayland && !!session.DISPLAY };
|
|
30539
|
+
}
|
|
30540
|
+
async function busSocket(env) {
|
|
30541
|
+
const socket = sessionBusSocket(env.DBUS_SESSION_BUS_ADDRESS);
|
|
30542
|
+
if (!socket || socket.startsWith("\0")) return socket;
|
|
30543
|
+
return (await lstat7(socket).catch(() => null))?.isSocket() ? socket : null;
|
|
30544
|
+
}
|
|
30545
|
+
async function portalCapture(socket, signal) {
|
|
30546
|
+
const token = "lc" + randomBytes6(8).toString("hex"), started = Date.now(), uid = process.getuid?.();
|
|
30547
|
+
if (uid === void 0) throw new ScreenCaptureError("SCREEN_UNAVAILABLE");
|
|
30548
|
+
let answer;
|
|
30549
|
+
try {
|
|
30550
|
+
answer = await portalScreenshot(socket, uid, token, AbortSignal.any([signal, AbortSignal.timeout(3e4)]));
|
|
30551
|
+
} catch {
|
|
30552
|
+
throw new ScreenCaptureError(signal.aborted ? "CANCELLED" : "SCREEN_UNAVAILABLE");
|
|
30553
|
+
}
|
|
30554
|
+
const { code, uri } = answer;
|
|
30555
|
+
if (code === 1) throw new ScreenCaptureError("SCREEN_RECORDING_PERMISSION_REQUIRED");
|
|
30556
|
+
if (code !== 0 || !uri?.startsWith("file://")) throw new ScreenCaptureError("SCREEN_UNAVAILABLE");
|
|
30557
|
+
const file2 = decodeURIComponent(new URL(uri).pathname), info = await lstat7(file2);
|
|
30558
|
+
const fresh = info.isFile() && info.uid === uid && info.mtimeMs >= started - 5e3;
|
|
30559
|
+
try {
|
|
30560
|
+
if (!fresh || info.size > LINUX_SOURCE_BYTES) throw new ScreenCaptureError("SCREEN_UNAVAILABLE");
|
|
30561
|
+
return await readFile6(file2);
|
|
30562
|
+
} finally {
|
|
30563
|
+
if (fresh) await unlink2(file2).catch(() => {
|
|
30564
|
+
});
|
|
30565
|
+
}
|
|
30566
|
+
}
|
|
30567
|
+
async function linux(signal) {
|
|
30568
|
+
const session = await linuxSession(signal);
|
|
30569
|
+
if (!session.wayland && !session.x11) throw new ScreenCaptureError("SCREENSHOT_UNSUPPORTED", { reason: "NO_DISPLAY" });
|
|
30570
|
+
const output2 = (args) => async (tool) => (await run(tool, args, signal, LINUX_SOURCE_BYTES, session.env)).stdout;
|
|
30571
|
+
const portal = (socket) => portalCapture(socket, signal);
|
|
30572
|
+
const methods = session.wayland ? [["grim", "grim", output2(["-t", "png", "-"])], ["portal", "", portal]] : [
|
|
30573
|
+
["xwd", "xwd", output2(["-root", "-silent"])],
|
|
30574
|
+
["import", "import", output2(["-silent", "-window", "root", "png:-"])],
|
|
30575
|
+
["maim", "maim", output2(["-f", "png"])],
|
|
30576
|
+
["portal", "", portal]
|
|
30577
|
+
];
|
|
30578
|
+
const tried = [];
|
|
30579
|
+
for (const [name2, program, capture2] of methods) {
|
|
30580
|
+
const tool = program ? await linuxTool(program) : await busSocket(session.env);
|
|
30581
|
+
if (!tool) {
|
|
30582
|
+
tried.push(name2 + ":missing");
|
|
30583
|
+
continue;
|
|
30584
|
+
}
|
|
30585
|
+
let image;
|
|
30586
|
+
try {
|
|
30587
|
+
const source = await capture2(tool);
|
|
30588
|
+
image = decodePng(source) ?? decodeXwd(source);
|
|
30589
|
+
} catch (error62) {
|
|
30590
|
+
if (signal.aborted) throw new ScreenCaptureError("CANCELLED");
|
|
30591
|
+
if (error62 instanceof ScreenCaptureError && error62.code === "SCREEN_RECORDING_PERMISSION_REQUIRED") throw error62;
|
|
30592
|
+
tried.push(name2 + ":failed");
|
|
30593
|
+
continue;
|
|
30594
|
+
}
|
|
30595
|
+
if (!image) {
|
|
30596
|
+
tried.push(name2 + ":unreadable");
|
|
30597
|
+
continue;
|
|
30598
|
+
}
|
|
30599
|
+
const fitted = fitJpeg(image, SCREENSHOT_MAX_EDGE, SCREENSHOT_MAX_JPEG_BYTES);
|
|
30600
|
+
if (!fitted) throw new ScreenCaptureError("SCREENSHOT_TOO_LARGE");
|
|
30601
|
+
return { ...fitted, sourceWidth: image.width, sourceHeight: image.height };
|
|
30602
|
+
}
|
|
30603
|
+
throw new ScreenCaptureError("SCREENSHOT_UNSUPPORTED", {
|
|
30604
|
+
reason: tried.every((entry) => entry.endsWith(":missing")) ? "NO_CAPTURE_TOOL" : "CAPTURE_FAILED",
|
|
30605
|
+
session: session.wayland ? "wayland" : "x11",
|
|
30606
|
+
tried
|
|
30607
|
+
});
|
|
30608
|
+
}
|
|
29470
30609
|
async function captureScreen(options) {
|
|
29471
30610
|
if (options.signal.aborted) throw new ScreenCaptureError("CANCELLED");
|
|
29472
30611
|
if (process.platform === "win32") return windows(options.ownerBridgePath, options.signal);
|
|
29473
30612
|
if (process.platform === "darwin") return mac3(options.signal);
|
|
29474
|
-
|
|
30613
|
+
if (process.platform === "linux") return linux(options.signal);
|
|
30614
|
+
throw new ScreenCaptureError("SCREENSHOT_UNSUPPORTED", { reason: "PLATFORM_UNSUPPORTED" });
|
|
29475
30615
|
}
|
|
29476
30616
|
|
|
29477
30617
|
// agent/src/tools.ts
|
|
@@ -29504,7 +30644,7 @@ function stopped(signal) {
|
|
|
29504
30644
|
if (signal.aborted) fail3("CANCELLED");
|
|
29505
30645
|
}
|
|
29506
30646
|
async function readBoundedFile(file2, maxBytes, bridge, signal) {
|
|
29507
|
-
const stat2 = await
|
|
30647
|
+
const stat2 = await lstat8(file2);
|
|
29508
30648
|
if (!stat2.isFile() || stat2.isSymbolicLink() || stat2.size > maxBytes) fail3("FILE_UNSUPPORTED_OR_TOO_LARGE");
|
|
29509
30649
|
if (process.platform === "win32") {
|
|
29510
30650
|
if (maxBytes <= 1048576 || stat2.size <= 1048576) return readWindowsFile(bridge, file2, Math.min(maxBytes, 1048576), signal);
|
|
@@ -29512,7 +30652,7 @@ async function readBoundedFile(file2, maxBytes, bridge, signal) {
|
|
|
29512
30652
|
if (read.truncated) fail3("FILE_UNSUPPORTED_OR_TOO_LARGE");
|
|
29513
30653
|
return read.data;
|
|
29514
30654
|
}
|
|
29515
|
-
const handle = await open6(file2,
|
|
30655
|
+
const handle = await open6(file2, constants8.O_RDONLY | (constants8.O_NOFOLLOW ?? 0));
|
|
29516
30656
|
try {
|
|
29517
30657
|
const current2 = await handle.stat();
|
|
29518
30658
|
if (!current2.isFile() || current2.size > maxBytes) fail3("FILE_UNSUPPORTED_OR_TOO_LARGE");
|
|
@@ -29767,7 +30907,7 @@ var NativeTools = class {
|
|
|
29767
30907
|
}
|
|
29768
30908
|
if (bytes3.length > MAX_FILE_WRITE_BYTES) fail3("FILE_WRITE_LIMIT");
|
|
29769
30909
|
const temp = path18.join(path18.dirname(target), ".lc-write-" + randomUUID7() + ".tmp");
|
|
29770
|
-
const handle = await open6(temp,
|
|
30910
|
+
const handle = await open6(temp, constants8.O_CREAT | constants8.O_EXCL | constants8.O_WRONLY, 384);
|
|
29771
30911
|
try {
|
|
29772
30912
|
await handle.writeFile(bytes3);
|
|
29773
30913
|
await handle.sync();
|
|
@@ -29783,7 +30923,7 @@ var NativeTools = class {
|
|
|
29783
30923
|
break;
|
|
29784
30924
|
} catch (error62) {
|
|
29785
30925
|
if (process.platform !== "win32" || !["EPERM", "EBUSY", "EACCES"].includes(error62.code ?? "")) throw error62;
|
|
29786
|
-
if (attempt === 4) fail3((await
|
|
30926
|
+
if (attempt === 4) fail3((await lstat8(target)).mode & 128 ? "FILE_IN_USE" : "FILE_READ_ONLY");
|
|
29787
30927
|
await delay2(50 << attempt);
|
|
29788
30928
|
stopped(signal);
|
|
29789
30929
|
}
|
|
@@ -29899,14 +31039,26 @@ var NativeTools = class {
|
|
|
29899
31039
|
} };
|
|
29900
31040
|
}
|
|
29901
31041
|
if (call.name === "take_screenshot") {
|
|
29902
|
-
if (!screenshotEnabled() && !await
|
|
31042
|
+
if (!screenshotEnabled() && !await lstat8(path18.join(this.options.stateDirectory, SCREENSHOT_ACCEPTANCE_FILE)).then((s) => s.isFile(), () => false)) fail3("SCREENSHOT_DISABLED");
|
|
29903
31043
|
if (!workspace2.fullAccess) fail3("FULL_ACCESS_REQUIRED");
|
|
31044
|
+
if (await lstat8(path18.join(this.options.stateDirectory, SCREENSHOT_OWNER_OFF_FILE)).then(() => true, (error62) => error62.code !== "ENOENT")) fail3("SCREENSHOT_DISABLED_BY_OWNER");
|
|
29904
31045
|
const bridge = this.options.ownerBridgePath ?? path18.join(path18.dirname(this.options.helperPath), "OwnerBridge.exe");
|
|
29905
31046
|
return { call, claims: [{ path: path18.join(this.options.stateDirectory, "screen-capture"), mode: "read" }], run: async (signal) => {
|
|
29906
31047
|
let shot;
|
|
29907
31048
|
try {
|
|
29908
31049
|
shot = await captureScreen({ ownerBridgePath: bridge, signal });
|
|
29909
31050
|
} catch (error62) {
|
|
31051
|
+
if (error62 instanceof ScreenCaptureError && error62.detail) return {
|
|
31052
|
+
exitCode: 1,
|
|
31053
|
+
timedOut: false,
|
|
31054
|
+
cancelled: false,
|
|
31055
|
+
treeTerminated: true,
|
|
31056
|
+
stdout: JSON.stringify({ type: "screenshot_error", resultCode: error62.code, ...error62.detail }),
|
|
31057
|
+
stderr: "",
|
|
31058
|
+
stdoutTruncated: false,
|
|
31059
|
+
stderrTruncated: false,
|
|
31060
|
+
resultCode: error62.code
|
|
31061
|
+
};
|
|
29910
31062
|
fail3(error62 instanceof Error && /^[A-Z_]{1,40}$/.test(error62.message) ? error62.message : "SCREEN_UNAVAILABLE");
|
|
29911
31063
|
}
|
|
29912
31064
|
return result({
|
|
@@ -30070,7 +31222,7 @@ var NativeTools = class {
|
|
|
30070
31222
|
)?.file : void 0);
|
|
30071
31223
|
if (!candidate || !path18.isAbsolute(candidate)) fail3("COMMAND_NOT_FOUND");
|
|
30072
31224
|
const executable = await realpath7(candidate).catch(() => fail3("COMMAND_NOT_FOUND"));
|
|
30073
|
-
if (!(await
|
|
31225
|
+
if (!(await lstat8(executable)).isFile()) fail3("COMMAND_NOT_FOUND");
|
|
30074
31226
|
if (denied.has(commandKey(executable))) fail3("COMMAND_NOT_ALLOWED");
|
|
30075
31227
|
for (const key of workspace2.deniedCommands ?? []) {
|
|
30076
31228
|
const configured = this.options.programs[key]?.executable;
|
|
@@ -30112,7 +31264,7 @@ var NativeTools = class {
|
|
|
30112
31264
|
const candidate = process.platform === "win32" ? source : await resolvePosixExecutable(source);
|
|
30113
31265
|
if (!candidate) continue;
|
|
30114
31266
|
try {
|
|
30115
|
-
const stat2 = await
|
|
31267
|
+
const stat2 = await lstat8(candidate);
|
|
30116
31268
|
if (!stat2.isFile() || stat2.isSymbolicLink() || !equalPath3(candidate, await realpath7(candidate))) continue;
|
|
30117
31269
|
} catch {
|
|
30118
31270
|
continue;
|
|
@@ -30130,7 +31282,7 @@ var NativeTools = class {
|
|
|
30130
31282
|
const current2 = queue.shift();
|
|
30131
31283
|
let names;
|
|
30132
31284
|
try {
|
|
30133
|
-
names = await
|
|
31285
|
+
names = await readdir5(current2.path, { withFileTypes: true });
|
|
30134
31286
|
} catch (error62) {
|
|
30135
31287
|
if (current2.level === 0) throw error62;
|
|
30136
31288
|
continue;
|
|
@@ -30155,7 +31307,7 @@ var NativeTools = class {
|
|
|
30155
31307
|
entries.push({ path: path18.relative(root, resolved), type: "directory" });
|
|
30156
31308
|
if (current2.level < depth) queue.push({ path: resolved, level: current2.level + 1 });
|
|
30157
31309
|
} else if (item.isFile()) {
|
|
30158
|
-
const stat2 = await
|
|
31310
|
+
const stat2 = await lstat8(resolved).catch(() => null);
|
|
30159
31311
|
if (stat2) entries.push({ path: path18.relative(root, resolved), type: "file", size: stat2.size });
|
|
30160
31312
|
}
|
|
30161
31313
|
}
|
|
@@ -30168,7 +31320,7 @@ var NativeTools = class {
|
|
|
30168
31320
|
while (guard.isWithin(directory, workspace2.root)) {
|
|
30169
31321
|
const dotGit = path18.join(directory, ".git");
|
|
30170
31322
|
try {
|
|
30171
|
-
const stat2 = await
|
|
31323
|
+
const stat2 = await lstat8(dotGit);
|
|
30172
31324
|
if (stat2.isSymbolicLink()) fail3("GIT_METADATA_CHANGED");
|
|
30173
31325
|
let gitDir;
|
|
30174
31326
|
if (stat2.isDirectory()) gitDir = await realpath7(dotGit);
|
|
@@ -30186,7 +31338,7 @@ var NativeTools = class {
|
|
|
30186
31338
|
} catch (e) {
|
|
30187
31339
|
if (e.code !== "ENOENT") throw e;
|
|
30188
31340
|
}
|
|
30189
|
-
if (!(await
|
|
31341
|
+
if (!(await lstat8(common)).isDirectory() || guard.isWithin(common, this.options.stateDirectory)) fail3("GIT_METADATA_CHANGED");
|
|
30190
31342
|
if (!guard.isWithin(common, workspace2.root) && (!workspace2.gitCommonDir || !equalPath3(common, workspace2.gitCommonDir))) fail3("GIT_COMMON_DIRECTORY_NOT_APPROVED");
|
|
30191
31343
|
return common;
|
|
30192
31344
|
} catch (e) {
|
|
@@ -30942,7 +32094,45 @@ function journalBinding(entry, binding2) {
|
|
|
30942
32094
|
function journalResult(value, code) {
|
|
30943
32095
|
return { ...value, resultCode: code ?? (value.treeTerminated ? value.cancelled ? "CANCELLED" : value.timedOut ? "TIMEOUT" : value.exitCode === 0 ? "SUCCESS" : "USER_PROGRAM_FAILED" : "EXECUTION_UNKNOWN") };
|
|
30944
32096
|
}
|
|
30945
|
-
var knownCodes = /* @__PURE__ */ new Set([
|
|
32097
|
+
var knownCodes = /* @__PURE__ */ new Set([
|
|
32098
|
+
"PROJECT_IDENTITY_UNKNOWN",
|
|
32099
|
+
"PROJECT_IDENTITY_MISMATCH",
|
|
32100
|
+
"INVALID_TOOL_ARGUMENTS",
|
|
32101
|
+
"LOCAL_PERMISSION_REQUIRED",
|
|
32102
|
+
"PATH_NOT_ALLOWED",
|
|
32103
|
+
"FILE_CHANGED",
|
|
32104
|
+
"FILE_NOT_FOUND",
|
|
32105
|
+
"FILE_ALREADY_EXISTS",
|
|
32106
|
+
"REPLACEMENT_NOT_UNIQUE",
|
|
32107
|
+
"OUTPUT_LIMIT_EXCEEDED",
|
|
32108
|
+
"BINARY_FILE_NOT_SUPPORTED",
|
|
32109
|
+
"FILE_UNSUPPORTED_OR_TOO_LARGE",
|
|
32110
|
+
"INVALID_LINE_RANGE",
|
|
32111
|
+
"FILE_IN_USE",
|
|
32112
|
+
"FILE_READ_ONLY",
|
|
32113
|
+
"FILE_WRITE_LIMIT",
|
|
32114
|
+
"GIT_METADATA_CHANGED",
|
|
32115
|
+
"GIT_COMMON_DIRECTORY_NOT_APPROVED",
|
|
32116
|
+
"GIT_NOT_INSTALLED",
|
|
32117
|
+
"LOCALHOST_NOT_ALLOWED",
|
|
32118
|
+
"COMMAND_NOT_ALLOWED",
|
|
32119
|
+
"WORKSPACE_CHANGED",
|
|
32120
|
+
"WORKSPACE_UNAVAILABLE",
|
|
32121
|
+
"RESOURCE_BUSY",
|
|
32122
|
+
"AGENT_PAUSED",
|
|
32123
|
+
"CANCELLED_BEFORE_ACCEPTANCE",
|
|
32124
|
+
"ADMISSION_DEADLINE_EXPIRED",
|
|
32125
|
+
// take_screenshot refusals (#434, #486): without these the client sees TOOL_FAILED.
|
|
32126
|
+
"FULL_ACCESS_REQUIRED",
|
|
32127
|
+
"SCREENSHOT_DISABLED",
|
|
32128
|
+
"SCREENSHOT_DISABLED_BY_OWNER",
|
|
32129
|
+
"SCREENSHOT_UNSUPPORTED",
|
|
32130
|
+
"SCREENSHOT_TOO_LARGE",
|
|
32131
|
+
"SCREEN_UNAVAILABLE",
|
|
32132
|
+
"SCREEN_LOCKED",
|
|
32133
|
+
"SCREEN_ENCODER_UNAVAILABLE",
|
|
32134
|
+
"SCREEN_RECORDING_PERMISSION_REQUIRED"
|
|
32135
|
+
]);
|
|
30946
32136
|
function safeCode(error62) {
|
|
30947
32137
|
const code = error62 instanceof NativeToolError ? error62.code : error62 instanceof Error ? error62.message : "";
|
|
30948
32138
|
return knownCodes.has(code) || /^GUARD_[A-Z_]{1,30}$/.test(code) ? code : "TOOL_FAILED";
|
|
@@ -31375,9 +32565,9 @@ var NativeRelayBridge = class {
|
|
|
31375
32565
|
};
|
|
31376
32566
|
|
|
31377
32567
|
// agent/src/local-direct.ts
|
|
31378
|
-
import
|
|
32568
|
+
import net2 from "node:net";
|
|
31379
32569
|
import path20 from "node:path";
|
|
31380
|
-
import { createHmac as createHmac2, hkdfSync, randomBytes as
|
|
32570
|
+
import { createHmac as createHmac2, hkdfSync, randomBytes as randomBytes7, randomUUID as randomUUID8, timingSafeEqual as timingSafeEqual3 } from "node:crypto";
|
|
31381
32571
|
import { mkdir as mkdir7, readFile as readFile8, rename as rename5, rm as rm7, writeFile as writeFile3 } from "node:fs/promises";
|
|
31382
32572
|
var LocalDirectError = class extends Error {
|
|
31383
32573
|
constructor(code) {
|
|
@@ -31414,7 +32604,7 @@ function sameProof(candidate, expected) {
|
|
|
31414
32604
|
const a = Buffer.from(candidate), b = Buffer.from(expected);
|
|
31415
32605
|
return a.length === b.length && timingSafeEqual3(a, b);
|
|
31416
32606
|
}
|
|
31417
|
-
var nonce = () =>
|
|
32607
|
+
var nonce = () => randomBytes7(32).toString("base64url");
|
|
31418
32608
|
var NONCE = /^[A-Za-z0-9_-]{43}$/;
|
|
31419
32609
|
function codeOf(error62) {
|
|
31420
32610
|
const code = error62 instanceof NativeToolError || error62 instanceof LocalDirectError ? error62.code : error62 instanceof Error ? error62.message : "";
|
|
@@ -31496,7 +32686,7 @@ var LocalDirectServer = class _LocalDirectServer {
|
|
|
31496
32686
|
});
|
|
31497
32687
|
return null;
|
|
31498
32688
|
}
|
|
31499
|
-
const server =
|
|
32689
|
+
const server = net2.createServer(), self = new _LocalDirectServer(server, options);
|
|
31500
32690
|
server.on("connection", (socket) => self.accept(socket));
|
|
31501
32691
|
await new Promise((resolve, reject) => {
|
|
31502
32692
|
server.once("error", reject);
|
|
@@ -31653,7 +32843,7 @@ var LocalDirectClient = class _LocalDirectClient {
|
|
|
31653
32843
|
static async connect(options) {
|
|
31654
32844
|
if (!await localDirectEnabled(options.directory)) fail4("LOCAL_ACCESS_DISABLED");
|
|
31655
32845
|
const endpoint2 = await readEndpoint(options.directory);
|
|
31656
|
-
const socket =
|
|
32846
|
+
const socket = net2.createConnection({ host: "127.0.0.1", port: endpoint2.port });
|
|
31657
32847
|
let handler = () => {
|
|
31658
32848
|
};
|
|
31659
32849
|
const lines = new Lines(socket, (frame) => handler(frame));
|
|
@@ -37176,8 +38366,8 @@ var require_content_type = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
37176
38366
|
var PARAM_REGEXP = /; *([!#$%&'*+.^_`|~0-9A-Za-z-]+) *= *("(?:[\u000b\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u000b\u0020-\u00ff])*"|[!#$%&'*+.^_`|~0-9A-Za-z-]+) */g;
|
|
37177
38367
|
var QESC_REGEXP = /\\([\u000b\u0020-\u00ff])/g;
|
|
37178
38368
|
var TYPE_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
37179
|
-
exports.parse =
|
|
37180
|
-
function
|
|
38369
|
+
exports.parse = parse4;
|
|
38370
|
+
function parse4(string4) {
|
|
37181
38371
|
if (!string4) throw new TypeError("argument string is required");
|
|
37182
38372
|
var header = typeof string4 === "object" ? getcontenttype(string4) : string4;
|
|
37183
38373
|
if (typeof header !== "string") throw new TypeError("argument string is required to be a string");
|
|
@@ -37701,9 +38891,9 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
37701
38891
|
const rhs = this.rhs === void 0 ? "" : ` = ${this.rhs}`;
|
|
37702
38892
|
return `${varKind} ${this.name}${rhs};` + _n;
|
|
37703
38893
|
}
|
|
37704
|
-
optimizeNames(names,
|
|
38894
|
+
optimizeNames(names, constants11) {
|
|
37705
38895
|
if (!names[this.name.str]) return;
|
|
37706
|
-
if (this.rhs) this.rhs = optimizeExpr(this.rhs, names,
|
|
38896
|
+
if (this.rhs) this.rhs = optimizeExpr(this.rhs, names, constants11);
|
|
37707
38897
|
return this;
|
|
37708
38898
|
}
|
|
37709
38899
|
get names() {
|
|
@@ -37720,9 +38910,9 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
37720
38910
|
render({ _n }) {
|
|
37721
38911
|
return `${this.lhs} = ${this.rhs};` + _n;
|
|
37722
38912
|
}
|
|
37723
|
-
optimizeNames(names,
|
|
38913
|
+
optimizeNames(names, constants11) {
|
|
37724
38914
|
if (this.lhs instanceof code_1.Name && !names[this.lhs.str] && !this.sideEffects) return;
|
|
37725
|
-
this.rhs = optimizeExpr(this.rhs, names,
|
|
38915
|
+
this.rhs = optimizeExpr(this.rhs, names, constants11);
|
|
37726
38916
|
return this;
|
|
37727
38917
|
}
|
|
37728
38918
|
get names() {
|
|
@@ -37781,8 +38971,8 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
37781
38971
|
optimizeNodes() {
|
|
37782
38972
|
return `${this.code}` ? this : void 0;
|
|
37783
38973
|
}
|
|
37784
|
-
optimizeNames(names,
|
|
37785
|
-
this.code = optimizeExpr(this.code, names,
|
|
38974
|
+
optimizeNames(names, constants11) {
|
|
38975
|
+
this.code = optimizeExpr(this.code, names, constants11);
|
|
37786
38976
|
return this;
|
|
37787
38977
|
}
|
|
37788
38978
|
get names() {
|
|
@@ -37808,12 +38998,12 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
37808
38998
|
}
|
|
37809
38999
|
return nodes.length > 0 ? this : void 0;
|
|
37810
39000
|
}
|
|
37811
|
-
optimizeNames(names,
|
|
39001
|
+
optimizeNames(names, constants11) {
|
|
37812
39002
|
const { nodes } = this;
|
|
37813
39003
|
let i = nodes.length;
|
|
37814
39004
|
while (i--) {
|
|
37815
39005
|
const n = nodes[i];
|
|
37816
|
-
if (n.optimizeNames(names,
|
|
39006
|
+
if (n.optimizeNames(names, constants11)) continue;
|
|
37817
39007
|
subtractNames(names, n.names);
|
|
37818
39008
|
nodes.splice(i, 1);
|
|
37819
39009
|
}
|
|
@@ -37860,11 +39050,11 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
37860
39050
|
if (cond === false || !this.nodes.length) return void 0;
|
|
37861
39051
|
return this;
|
|
37862
39052
|
}
|
|
37863
|
-
optimizeNames(names,
|
|
39053
|
+
optimizeNames(names, constants11) {
|
|
37864
39054
|
var _a3;
|
|
37865
|
-
this.else = (_a3 = this.else) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names,
|
|
37866
|
-
if (!(super.optimizeNames(names,
|
|
37867
|
-
this.condition = optimizeExpr(this.condition, names,
|
|
39055
|
+
this.else = (_a3 = this.else) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names, constants11);
|
|
39056
|
+
if (!(super.optimizeNames(names, constants11) || this.else)) return;
|
|
39057
|
+
this.condition = optimizeExpr(this.condition, names, constants11);
|
|
37868
39058
|
return this;
|
|
37869
39059
|
}
|
|
37870
39060
|
get names() {
|
|
@@ -37886,9 +39076,9 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
37886
39076
|
render(opts) {
|
|
37887
39077
|
return `for(${this.iteration})` + super.render(opts);
|
|
37888
39078
|
}
|
|
37889
|
-
optimizeNames(names,
|
|
37890
|
-
if (!super.optimizeNames(names,
|
|
37891
|
-
this.iteration = optimizeExpr(this.iteration, names,
|
|
39079
|
+
optimizeNames(names, constants11) {
|
|
39080
|
+
if (!super.optimizeNames(names, constants11)) return;
|
|
39081
|
+
this.iteration = optimizeExpr(this.iteration, names, constants11);
|
|
37892
39082
|
return this;
|
|
37893
39083
|
}
|
|
37894
39084
|
get names() {
|
|
@@ -37923,9 +39113,9 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
37923
39113
|
render(opts) {
|
|
37924
39114
|
return `for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})` + super.render(opts);
|
|
37925
39115
|
}
|
|
37926
|
-
optimizeNames(names,
|
|
37927
|
-
if (!super.optimizeNames(names,
|
|
37928
|
-
this.iterable = optimizeExpr(this.iterable, names,
|
|
39116
|
+
optimizeNames(names, constants11) {
|
|
39117
|
+
if (!super.optimizeNames(names, constants11)) return;
|
|
39118
|
+
this.iterable = optimizeExpr(this.iterable, names, constants11);
|
|
37929
39119
|
return this;
|
|
37930
39120
|
}
|
|
37931
39121
|
get names() {
|
|
@@ -37964,11 +39154,11 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
37964
39154
|
(_b = this.finally) === null || _b === void 0 || _b.optimizeNodes();
|
|
37965
39155
|
return this;
|
|
37966
39156
|
}
|
|
37967
|
-
optimizeNames(names,
|
|
39157
|
+
optimizeNames(names, constants11) {
|
|
37968
39158
|
var _a3, _b;
|
|
37969
|
-
super.optimizeNames(names,
|
|
37970
|
-
(_a3 = this.catch) === null || _a3 === void 0 || _a3.optimizeNames(names,
|
|
37971
|
-
(_b = this.finally) === null || _b === void 0 || _b.optimizeNames(names,
|
|
39159
|
+
super.optimizeNames(names, constants11);
|
|
39160
|
+
(_a3 = this.catch) === null || _a3 === void 0 || _a3.optimizeNames(names, constants11);
|
|
39161
|
+
(_b = this.finally) === null || _b === void 0 || _b.optimizeNames(names, constants11);
|
|
37972
39162
|
return this;
|
|
37973
39163
|
}
|
|
37974
39164
|
get names() {
|
|
@@ -38217,7 +39407,7 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
38217
39407
|
function addExprNames(names, from) {
|
|
38218
39408
|
return from instanceof code_1._CodeOrName ? addNames(names, from.names) : names;
|
|
38219
39409
|
}
|
|
38220
|
-
function optimizeExpr(expr, names,
|
|
39410
|
+
function optimizeExpr(expr, names, constants11) {
|
|
38221
39411
|
if (expr instanceof code_1.Name) return replaceName(expr);
|
|
38222
39412
|
if (!canOptimize(expr)) return expr;
|
|
38223
39413
|
return new code_1._Code(expr._items.reduce((items, c) => {
|
|
@@ -38227,13 +39417,13 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
38227
39417
|
return items;
|
|
38228
39418
|
}, []));
|
|
38229
39419
|
function replaceName(n) {
|
|
38230
|
-
const c =
|
|
39420
|
+
const c = constants11[n.str];
|
|
38231
39421
|
if (c === void 0 || names[n.str] !== 1) return n;
|
|
38232
39422
|
delete names[n.str];
|
|
38233
39423
|
return c;
|
|
38234
39424
|
}
|
|
38235
39425
|
function canOptimize(e) {
|
|
38236
|
-
return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 &&
|
|
39426
|
+
return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 && constants11[c.str] !== void 0);
|
|
38237
39427
|
}
|
|
38238
39428
|
}
|
|
38239
39429
|
function subtractNames(names, from) {
|
|
@@ -40365,21 +41555,21 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
40365
41555
|
const { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizeComponentEncoding, isIPv4, nonSimpleDomain } = require_utils();
|
|
40366
41556
|
const { SCHEMES, getSchemeHandler } = require_schemes();
|
|
40367
41557
|
function normalize(uri, options) {
|
|
40368
|
-
if (typeof uri === "string") uri = serialize(
|
|
40369
|
-
else if (typeof uri === "object") uri =
|
|
41558
|
+
if (typeof uri === "string") uri = serialize(parse4(uri, options), options);
|
|
41559
|
+
else if (typeof uri === "object") uri = parse4(serialize(uri, options), options);
|
|
40370
41560
|
return uri;
|
|
40371
41561
|
}
|
|
40372
41562
|
function resolve(baseURI, relativeURI, options) {
|
|
40373
41563
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
40374
|
-
const resolved = resolveComponent(
|
|
41564
|
+
const resolved = resolveComponent(parse4(baseURI, schemelessOptions), parse4(relativeURI, schemelessOptions), schemelessOptions, true);
|
|
40375
41565
|
schemelessOptions.skipEscape = true;
|
|
40376
41566
|
return serialize(resolved, schemelessOptions);
|
|
40377
41567
|
}
|
|
40378
41568
|
function resolveComponent(base, relative, options, skipNormalization) {
|
|
40379
41569
|
const target = {};
|
|
40380
41570
|
if (!skipNormalization) {
|
|
40381
|
-
base =
|
|
40382
|
-
relative =
|
|
41571
|
+
base = parse4(serialize(base, options), options);
|
|
41572
|
+
relative = parse4(serialize(relative, options), options);
|
|
40383
41573
|
}
|
|
40384
41574
|
options = options || {};
|
|
40385
41575
|
if (!options.tolerant && relative.scheme) {
|
|
@@ -40423,7 +41613,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
40423
41613
|
function equal(uriA, uriB, options) {
|
|
40424
41614
|
if (typeof uriA === "string") {
|
|
40425
41615
|
uriA = unescape(uriA);
|
|
40426
|
-
uriA = serialize(normalizeComponentEncoding(
|
|
41616
|
+
uriA = serialize(normalizeComponentEncoding(parse4(uriA, options), true), {
|
|
40427
41617
|
...options,
|
|
40428
41618
|
skipEscape: true
|
|
40429
41619
|
});
|
|
@@ -40433,7 +41623,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
40433
41623
|
});
|
|
40434
41624
|
if (typeof uriB === "string") {
|
|
40435
41625
|
uriB = unescape(uriB);
|
|
40436
|
-
uriB = serialize(normalizeComponentEncoding(
|
|
41626
|
+
uriB = serialize(normalizeComponentEncoding(parse4(uriB, options), true), {
|
|
40437
41627
|
...options,
|
|
40438
41628
|
skipEscape: true
|
|
40439
41629
|
});
|
|
@@ -40486,7 +41676,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
40486
41676
|
return uriTokens.join("");
|
|
40487
41677
|
}
|
|
40488
41678
|
const URI_PARSE = /^(?:([^#/:?]+):)?(?:\/\/((?:([^#/?@]*)@)?(\[[^#/?\]]+\]|[^#/:?]*)(?::(\d*))?))?([^#?]*)(?:\?([^#]*))?(?:#((?:.|[\n\r])*))?/u;
|
|
40489
|
-
function
|
|
41679
|
+
function parse4(uri, opts) {
|
|
40490
41680
|
const options = Object.assign({}, opts);
|
|
40491
41681
|
const parsed = {
|
|
40492
41682
|
scheme: void 0,
|
|
@@ -40547,7 +41737,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
40547
41737
|
resolveComponent,
|
|
40548
41738
|
equal,
|
|
40549
41739
|
serialize,
|
|
40550
|
-
parse:
|
|
41740
|
+
parse: parse4
|
|
40551
41741
|
};
|
|
40552
41742
|
module.exports = fastUri;
|
|
40553
41743
|
module.exports.default = fastUri;
|
|
@@ -45827,7 +47017,7 @@ var DESCRIPTIONS = {
|
|
|
45827
47017
|
git_log: ["Recent Git commits of the repository at a workspace-relative path.", { readOnlyHint: true, openWorldHint: false }],
|
|
45828
47018
|
project_snapshot: ["Compact project overview: Git state and, with startup, AGENTS.md policy and task continuation.", { readOnlyHint: true, openWorldHint: false }],
|
|
45829
47019
|
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 }],
|
|
45830
|
-
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 }],
|
|
47020
|
+
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 }],
|
|
45831
47021
|
localhost_request: ["HTTP request to a service on this computer (localhost only).", { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false }]
|
|
45832
47022
|
};
|
|
45833
47023
|
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.");
|
|
@@ -46349,6 +47539,7 @@ async function connectOnce(options) {
|
|
|
46349
47539
|
const incidents = Array.isArray(readyFrame.capabilities) && readyFrame.capabilities.includes("incidentBatchV1");
|
|
46350
47540
|
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;
|
|
46351
47541
|
const nativeStatus = Array.isArray(readyFrame.capabilities) && readyFrame.capabilities.includes(NATIVE_STATUS_CAPABILITY) && options.status;
|
|
47542
|
+
const accessModes = Array.isArray(readyFrame.capabilities) && readyFrame.capabilities.includes(WORKSPACE_ACCESS_MODE_CAPABILITY);
|
|
46352
47543
|
const reportStatus = () => {
|
|
46353
47544
|
if (!nativeStatus) return;
|
|
46354
47545
|
const { safeSlots, active, queued, paused } = nativeStatus();
|
|
@@ -46575,7 +47766,16 @@ async function connectOnce(options) {
|
|
|
46575
47766
|
registerWorkspace: (workspace2) => {
|
|
46576
47767
|
if (pendingWorkspace.size >= 32) return Promise.reject(new RelayClientError("RELAY_PENDING_LIMIT"));
|
|
46577
47768
|
const requestId = randomUUID10();
|
|
46578
|
-
const event = {
|
|
47769
|
+
const event = {
|
|
47770
|
+
type: "workspace_grant",
|
|
47771
|
+
version: 1,
|
|
47772
|
+
requestId,
|
|
47773
|
+
workspaceGrantId: workspace2.workspaceGrantId,
|
|
47774
|
+
rootHash: workspace2.rootHash,
|
|
47775
|
+
displayName: workspace2.displayName,
|
|
47776
|
+
policyVersion: workspace2.policyVersion,
|
|
47777
|
+
...accessModes ? { accessMode: workspace2.fullAccess === true ? "full" : "scoped" } : {}
|
|
47778
|
+
};
|
|
46579
47779
|
return new Promise((resolve, reject) => {
|
|
46580
47780
|
const timer = setTimeout(() => {
|
|
46581
47781
|
pendingWorkspace.delete(requestId);
|
|
@@ -46624,14 +47824,14 @@ import { spawn as spawn5 } from "node:child_process";
|
|
|
46624
47824
|
import { createHash as createHash16 } from "node:crypto";
|
|
46625
47825
|
import os6 from "node:os";
|
|
46626
47826
|
import { open as open7 } from "node:fs/promises";
|
|
46627
|
-
import { constants as
|
|
47827
|
+
import { constants as constants9 } from "node:fs";
|
|
46628
47828
|
import path21 from "node:path";
|
|
46629
47829
|
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;
|
|
46630
47830
|
async function readMachineGuid(timeoutMs2 = 5e3) {
|
|
46631
47831
|
if (process.platform === "linux") {
|
|
46632
47832
|
let handle;
|
|
46633
47833
|
try {
|
|
46634
|
-
handle = await open7("/etc/machine-id",
|
|
47834
|
+
handle = await open7("/etc/machine-id", constants9.O_RDONLY | constants9.O_NOFOLLOW);
|
|
46635
47835
|
const stat2 = await handle.stat();
|
|
46636
47836
|
if (!stat2.isFile() || stat2.size > 128) return null;
|
|
46637
47837
|
const data = Buffer.alloc(129);
|
|
@@ -46680,7 +47880,7 @@ async function readComputerName(timeoutMs2 = 5e3) {
|
|
|
46680
47880
|
if (process.platform === "linux") {
|
|
46681
47881
|
let handle;
|
|
46682
47882
|
try {
|
|
46683
|
-
handle = await open7("/etc/hostname",
|
|
47883
|
+
handle = await open7("/etc/hostname", constants9.O_RDONLY | constants9.O_NOFOLLOW);
|
|
46684
47884
|
const data = Buffer.alloc(257), { bytesRead } = await handle.read(data, 0, data.length, 0);
|
|
46685
47885
|
const name2 = data.subarray(0, bytesRead).toString("utf8").trim();
|
|
46686
47886
|
if (bytesRead <= 256 && valid(name2)) return name2;
|
|
@@ -47263,8 +48463,8 @@ async function deliverGuardEvidence(target, packet, options = {}) {
|
|
|
47263
48463
|
}
|
|
47264
48464
|
|
|
47265
48465
|
// agent/src/optimization-ledger.ts
|
|
47266
|
-
import { constants as
|
|
47267
|
-
import { lstat as
|
|
48466
|
+
import { constants as constants10 } from "node:fs";
|
|
48467
|
+
import { lstat as lstat9, mkdir as mkdir8, open as open8, readFile as readFile9, realpath as realpath8 } from "node:fs/promises";
|
|
47268
48468
|
import path22 from "node:path";
|
|
47269
48469
|
var MAX_LEDGER_BYTES = 64 * 1024 * 1024;
|
|
47270
48470
|
var MAX_NOTICE_LEDGER_BYTES = 8 * 1024 * 1024;
|
|
@@ -47276,7 +48476,7 @@ async function safeDirectory2(directory) {
|
|
|
47276
48476
|
let current2 = absolute2;
|
|
47277
48477
|
for (; ; ) {
|
|
47278
48478
|
try {
|
|
47279
|
-
if ((await
|
|
48479
|
+
if ((await lstat9(current2)).isSymbolicLink()) throw failure5("OPTIMIZATION_LEDGER_DIRECTORY_INVALID");
|
|
47280
48480
|
} catch (error62) {
|
|
47281
48481
|
if (error62.code !== "ENOENT") throw error62;
|
|
47282
48482
|
}
|
|
@@ -47285,7 +48485,7 @@ async function safeDirectory2(directory) {
|
|
|
47285
48485
|
current2 = parent;
|
|
47286
48486
|
}
|
|
47287
48487
|
await mkdir8(absolute2, { recursive: true, mode: 448 });
|
|
47288
|
-
const stat2 = await
|
|
48488
|
+
const stat2 = await lstat9(absolute2);
|
|
47289
48489
|
if (!stat2.isDirectory() || stat2.isSymbolicLink()) throw failure5("OPTIMIZATION_LEDGER_DIRECTORY_INVALID");
|
|
47290
48490
|
return realpath8(absolute2);
|
|
47291
48491
|
}
|
|
@@ -47319,7 +48519,7 @@ var OptimizationLedger = class _OptimizationLedger {
|
|
|
47319
48519
|
const noticesFilename = path22.join(dir, "live-efficiency-notices.v1.jsonl");
|
|
47320
48520
|
let existing = "";
|
|
47321
48521
|
try {
|
|
47322
|
-
const stat2 = await
|
|
48522
|
+
const stat2 = await lstat9(filename);
|
|
47323
48523
|
if (!stat2.isFile() || stat2.isSymbolicLink() || stat2.size > MAX_LEDGER_BYTES) {
|
|
47324
48524
|
throw failure5("OPTIMIZATION_LEDGER_INVALID");
|
|
47325
48525
|
}
|
|
@@ -47329,13 +48529,13 @@ var OptimizationLedger = class _OptimizationLedger {
|
|
|
47329
48529
|
}
|
|
47330
48530
|
const handle = await open8(
|
|
47331
48531
|
filename,
|
|
47332
|
-
|
|
48532
|
+
constants10.O_CREAT | constants10.O_APPEND | constants10.O_WRONLY | (constants10.O_NOFOLLOW ?? 0),
|
|
47333
48533
|
384
|
|
47334
48534
|
);
|
|
47335
48535
|
const ledger = new _OptimizationLedger(filename, handle, noticesFilename);
|
|
47336
48536
|
try {
|
|
47337
48537
|
try {
|
|
47338
|
-
const noticeStat = await
|
|
48538
|
+
const noticeStat = await lstat9(noticesFilename);
|
|
47339
48539
|
if (!noticeStat.isFile() || noticeStat.isSymbolicLink() || noticeStat.size > MAX_NOTICE_LEDGER_BYTES) throw failure5("OPTIMIZATION_NOTICE_LEDGER_INVALID");
|
|
47340
48540
|
const notices = await readFile9(noticesFilename, "utf8");
|
|
47341
48541
|
for (const line of notices.split("\n")) {
|
|
@@ -47417,7 +48617,7 @@ var OptimizationLedger = class _OptimizationLedger {
|
|
|
47417
48617
|
const marker = JSON.stringify({ sessionId: event.sessionId, checkpointCalls, deliveredAt: (/* @__PURE__ */ new Date()).toISOString() }) + "\n";
|
|
47418
48618
|
let currentBytes = 0;
|
|
47419
48619
|
try {
|
|
47420
|
-
const stat2 = await
|
|
48620
|
+
const stat2 = await lstat9(this.noticesFilename);
|
|
47421
48621
|
if (!stat2.isFile() || stat2.isSymbolicLink()) throw failure5("OPTIMIZATION_NOTICE_LEDGER_INVALID");
|
|
47422
48622
|
currentBytes = stat2.size;
|
|
47423
48623
|
} catch (error62) {
|
|
@@ -47426,7 +48626,7 @@ var OptimizationLedger = class _OptimizationLedger {
|
|
|
47426
48626
|
if (currentBytes + Buffer.byteLength(marker, "utf8") > MAX_NOTICE_LEDGER_BYTES) throw failure5("OPTIMIZATION_NOTICE_LEDGER_CAPACITY_EXCEEDED");
|
|
47427
48627
|
const markerHandle = await open8(
|
|
47428
48628
|
this.noticesFilename,
|
|
47429
|
-
|
|
48629
|
+
constants10.O_CREAT | constants10.O_APPEND | constants10.O_WRONLY | (constants10.O_NOFOLLOW ?? 0),
|
|
47430
48630
|
384
|
|
47431
48631
|
);
|
|
47432
48632
|
try {
|
|
@@ -47465,7 +48665,7 @@ var OptimizationLedger = class _OptimizationLedger {
|
|
|
47465
48665
|
|
|
47466
48666
|
// agent/src/monitor.ts
|
|
47467
48667
|
import { createHash as createHash17, randomUUID as randomUUID12 } from "node:crypto";
|
|
47468
|
-
import { lstat as
|
|
48668
|
+
import { lstat as lstat10, mkdir as mkdir9, open as open9, rename as rename6, rm as rm8 } from "node:fs/promises";
|
|
47469
48669
|
import path23 from "node:path";
|
|
47470
48670
|
import os7 from "node:os";
|
|
47471
48671
|
|
|
@@ -47732,7 +48932,7 @@ var ProductionMonitor = class {
|
|
|
47732
48932
|
async write(file2, contents) {
|
|
47733
48933
|
const directory = path23.dirname(file2);
|
|
47734
48934
|
await mkdir9(directory, { recursive: true, mode: 448 });
|
|
47735
|
-
const stat2 = await
|
|
48935
|
+
const stat2 = await lstat10(directory);
|
|
47736
48936
|
if (!stat2.isDirectory() || stat2.isSymbolicLink()) throw Error("MONITOR_DIRECTORY_INVALID");
|
|
47737
48937
|
const temporary = file2 + "." + this.instanceId + ".tmp";
|
|
47738
48938
|
const handle = await open9(temporary, "wx", 384);
|
|
@@ -48155,26 +49355,26 @@ var NativeFabricObserver = class {
|
|
|
48155
49355
|
};
|
|
48156
49356
|
|
|
48157
49357
|
// agent/src/native-fabric-startup.ts
|
|
48158
|
-
import { lstat as
|
|
49358
|
+
import { lstat as lstat12, mkdir as mkdir12, open as open11, readFile as readFile10 } from "node:fs/promises";
|
|
48159
49359
|
import path26 from "node:path";
|
|
48160
49360
|
|
|
48161
49361
|
// src/agent-fabric-service.ts
|
|
48162
|
-
import { lstat as
|
|
49362
|
+
import { lstat as lstat11, mkdir as mkdir11, realpath as realpath9 } from "node:fs/promises";
|
|
48163
49363
|
import { watch } from "node:fs";
|
|
48164
49364
|
import path25 from "node:path";
|
|
48165
49365
|
|
|
48166
49366
|
// src/agent-runtime-identity.ts
|
|
48167
|
-
import { createHash as createHash19, randomBytes as
|
|
49367
|
+
import { createHash as createHash19, randomBytes as randomBytes8, randomUUID as randomUUID14, timingSafeEqual as timingSafeEqual4 } from "node:crypto";
|
|
48168
49368
|
|
|
48169
49369
|
// src/agent-fabric-state.ts
|
|
48170
49370
|
import { randomUUID as randomUUID13 } from "node:crypto";
|
|
48171
|
-
import { mkdir as mkdir10, open as open10, rename as rename7, unlink as
|
|
49371
|
+
import { mkdir as mkdir10, open as open10, rename as rename7, unlink as unlink3 } from "node:fs/promises";
|
|
48172
49372
|
import path24 from "node:path";
|
|
48173
49373
|
var queues = /* @__PURE__ */ new Map();
|
|
48174
49374
|
var FabricStateFile = class {
|
|
48175
|
-
constructor(file2, maxBytes,
|
|
49375
|
+
constructor(file2, maxBytes, parse4) {
|
|
48176
49376
|
this.maxBytes = maxBytes;
|
|
48177
|
-
this.parse =
|
|
49377
|
+
this.parse = parse4;
|
|
48178
49378
|
this.file = path24.resolve(file2);
|
|
48179
49379
|
}
|
|
48180
49380
|
maxBytes;
|
|
@@ -48250,7 +49450,7 @@ var FabricStateFile = class {
|
|
|
48250
49450
|
}
|
|
48251
49451
|
await rename7(temporary, this.file);
|
|
48252
49452
|
} finally {
|
|
48253
|
-
await
|
|
49453
|
+
await unlink3(temporary).catch((error62) => {
|
|
48254
49454
|
if (error62.code !== "ENOENT") throw error62;
|
|
48255
49455
|
});
|
|
48256
49456
|
}
|
|
@@ -48264,7 +49464,7 @@ var FabricStateFile = class {
|
|
|
48264
49464
|
} finally {
|
|
48265
49465
|
await current2.close();
|
|
48266
49466
|
}
|
|
48267
|
-
await
|
|
49467
|
+
await unlink3(lockPath);
|
|
48268
49468
|
}
|
|
48269
49469
|
});
|
|
48270
49470
|
}
|
|
@@ -48318,7 +49518,7 @@ var AgentRuntimeIdentityStore = class {
|
|
|
48318
49518
|
return this.serial((state) => {
|
|
48319
49519
|
if (state.bindings.length >= MAX_BINDINGS) throw Error("RUNTIME_IDENTITY_LIMIT");
|
|
48320
49520
|
const runtimeId = "rt-" + randomUUID14();
|
|
48321
|
-
const runtimeKey =
|
|
49521
|
+
const runtimeKey = randomBytes8(32).toString("base64url");
|
|
48322
49522
|
const now = this.now();
|
|
48323
49523
|
state.bindings.push({ runtimeId, keyHash: encodedDigest(runtimeKey), createdAt: now, lastUsedAt: now, revoked: false });
|
|
48324
49524
|
return { runtimeId, runtimeKey };
|
|
@@ -48883,18 +50083,18 @@ var AgentFabricService = class _AgentFabricService {
|
|
|
48883
50083
|
const absolute2 = path25.resolve(directory);
|
|
48884
50084
|
for (let current2 = absolute2; ; current2 = path25.dirname(current2)) {
|
|
48885
50085
|
try {
|
|
48886
|
-
if ((await
|
|
50086
|
+
if ((await lstat11(current2)).isSymbolicLink()) throw Error("FABRIC_DIRECTORY_INVALID");
|
|
48887
50087
|
} catch (error62) {
|
|
48888
50088
|
if (error62.code !== "ENOENT") throw error62;
|
|
48889
50089
|
}
|
|
48890
50090
|
if (path25.dirname(current2) === current2) break;
|
|
48891
50091
|
}
|
|
48892
50092
|
if (initialize) await mkdir11(absolute2, { recursive: true, mode: 448 });
|
|
48893
|
-
if (!(await
|
|
50093
|
+
if (!(await lstat11(absolute2)).isDirectory() || (await realpath9(absolute2)).toLowerCase() !== absolute2.toLowerCase())
|
|
48894
50094
|
throw Error("FABRIC_DIRECTORY_INVALID");
|
|
48895
50095
|
const present = /* @__PURE__ */ new Set();
|
|
48896
50096
|
for (const name2 of ["binding.json", "mailbox.json", "identities.json"]) {
|
|
48897
|
-
const file2 = await
|
|
50097
|
+
const file2 = await lstat11(path25.join(absolute2, name2)).catch((error62) => {
|
|
48898
50098
|
if (error62.code === "ENOENT") return null;
|
|
48899
50099
|
throw error62;
|
|
48900
50100
|
});
|
|
@@ -48917,7 +50117,7 @@ var AgentFabricService = class _AgentFabricService {
|
|
|
48917
50117
|
state.initialized = true;
|
|
48918
50118
|
}
|
|
48919
50119
|
const snapshot2 = await service2.mailbox.snapshot();
|
|
48920
|
-
if (snapshot2.workers.some((worker) => worker.runtimeId !== null)) await
|
|
50120
|
+
if (snapshot2.workers.some((worker) => worker.runtimeId !== null)) await lstat11(path25.join(absolute2, "identities.json"));
|
|
48921
50121
|
}, initialize ? () => expected : void 0);
|
|
48922
50122
|
return service2;
|
|
48923
50123
|
}
|
|
@@ -49010,12 +50210,12 @@ async function openNativeFabric(stateDirectory, enrollment, box, initialize = tr
|
|
|
49010
50210
|
} catch (error62) {
|
|
49011
50211
|
if (error62.code !== "EEXIST") throw error62;
|
|
49012
50212
|
}
|
|
49013
|
-
const parentInfo = await
|
|
50213
|
+
const parentInfo = await lstat12(parent);
|
|
49014
50214
|
if (!parentInfo.isDirectory() || parentInfo.isSymbolicLink()) throw Error("FABRIC_DIRECTORY_INVALID");
|
|
49015
50215
|
const expected = JSON.stringify({ version: 1, controllerId, tenantId });
|
|
49016
50216
|
let fresh = false;
|
|
49017
50217
|
try {
|
|
49018
|
-
const info = await
|
|
50218
|
+
const info = await lstat12(marker);
|
|
49019
50219
|
if (!info.isFile() || info.isSymbolicLink() || info.size > 2048 || await readFile10(marker, "utf8") !== expected)
|
|
49020
50220
|
throw Error("FABRIC_BINDING_CHANGED");
|
|
49021
50221
|
} catch (error62) {
|
|
@@ -49043,7 +50243,7 @@ async function openNativeFabric(stateDirectory, enrollment, box, initialize = tr
|
|
|
49043
50243
|
return credential;
|
|
49044
50244
|
};
|
|
49045
50245
|
async function capability(workerId) {
|
|
49046
|
-
const file2 = credentialFile(workerId), info = await
|
|
50246
|
+
const file2 = credentialFile(workerId), info = await lstat12(file2);
|
|
49047
50247
|
if (!info.isFile() || info.isSymbolicLink() || info.size > 4096) throw Error("FABRIC_CREDENTIAL_UNKNOWN");
|
|
49048
50248
|
const encoded = await readFile10(file2, "utf8");
|
|
49049
50249
|
if (decode4(encoded).workerId !== workerId) throw Error("FABRIC_WORKER_DENIED");
|
|
@@ -49197,14 +50397,14 @@ function supervisorLiveness(helperPath, options = {}) {
|
|
|
49197
50397
|
|
|
49198
50398
|
// agent/src/content-audit.ts
|
|
49199
50399
|
import { createReadStream } from "node:fs";
|
|
49200
|
-
import { appendFile, lstat as
|
|
50400
|
+
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";
|
|
49201
50401
|
import path28 from "node:path";
|
|
49202
50402
|
import { performance as performance3 } from "node:perf_hooks";
|
|
49203
50403
|
import { createInterface as createInterface2 } from "node:readline";
|
|
49204
|
-
import { randomBytes as
|
|
50404
|
+
import { randomBytes as randomBytes10 } from "node:crypto";
|
|
49205
50405
|
|
|
49206
50406
|
// src/audit-crypto.ts
|
|
49207
|
-
import { createCipheriv as createCipheriv3, createDecipheriv as createDecipheriv3, createHash as createHash20, randomBytes as
|
|
50407
|
+
import { createCipheriv as createCipheriv3, createDecipheriv as createDecipheriv3, createHash as createHash20, randomBytes as randomBytes9 } from "node:crypto";
|
|
49208
50408
|
import { promisify as promisify3 } from "node:util";
|
|
49209
50409
|
import { gunzipSync, gzip, gzipSync } from "node:zlib";
|
|
49210
50410
|
var gzipAsync = promisify3(gzip);
|
|
@@ -49256,7 +50456,7 @@ async function encryptAuditRecordAsync(record2, keyInput, keyId2) {
|
|
|
49256
50456
|
function sealCompressed(compressed, keyInput, keyId2) {
|
|
49257
50457
|
const key = parseAuditRecoveryKey(keyInput);
|
|
49258
50458
|
const kid = keyId2?.trim() || auditRecoveryKeyId(key);
|
|
49259
|
-
const iv =
|
|
50459
|
+
const iv = randomBytes9(IV_BYTES);
|
|
49260
50460
|
try {
|
|
49261
50461
|
const cipher = createCipheriv3("aes-256-gcm", key, iv, { authTagLength: TAG_BYTES });
|
|
49262
50462
|
cipher.setAAD(additionalData(kid));
|
|
@@ -49371,13 +50571,13 @@ function contentAuditDirectory(stateDir) {
|
|
|
49371
50571
|
}
|
|
49372
50572
|
async function plainDirectory(dir) {
|
|
49373
50573
|
await mkdir13(dir, { recursive: true, mode: 448 });
|
|
49374
|
-
const info = await
|
|
50574
|
+
const info = await lstat13(dir);
|
|
49375
50575
|
if (info.isSymbolicLink() || !info.isDirectory()) throw Error("AUDIT_DIRECTORY_INVALID");
|
|
49376
50576
|
}
|
|
49377
50577
|
async function auditFiles(dir) {
|
|
49378
50578
|
let names;
|
|
49379
50579
|
try {
|
|
49380
|
-
names = await
|
|
50580
|
+
names = await readdir6(dir);
|
|
49381
50581
|
} catch (error62) {
|
|
49382
50582
|
if (error62.code === "ENOENT") return [];
|
|
49383
50583
|
throw error62;
|
|
@@ -49386,13 +50586,13 @@ async function auditFiles(dir) {
|
|
|
49386
50586
|
for (const name2 of names) {
|
|
49387
50587
|
const match = FILE.exec(name2);
|
|
49388
50588
|
if (!match) continue;
|
|
49389
|
-
const info = await
|
|
50589
|
+
const info = await lstat13(path28.join(dir, name2));
|
|
49390
50590
|
if (info.isFile()) files.push({ name: name2, kind: match[1], day: match[2], bytes: info.size });
|
|
49391
50591
|
}
|
|
49392
50592
|
return files.sort((a, b) => a.name.localeCompare(b.name));
|
|
49393
50593
|
}
|
|
49394
50594
|
async function writeJsonAtomic(file2, value) {
|
|
49395
|
-
const temp = `${file2}.${
|
|
50595
|
+
const temp = `${file2}.${randomBytes10(6).toString("hex")}.tmp`;
|
|
49396
50596
|
try {
|
|
49397
50597
|
await writeFile4(temp, JSON.stringify(value) + "\n", { flag: "wx", mode: 384 });
|
|
49398
50598
|
await rename8(temp, file2);
|
|
@@ -49629,7 +50829,7 @@ async function restoreContentAudit(input2, output2, key) {
|
|
|
49629
50829
|
}
|
|
49630
50830
|
|
|
49631
50831
|
// agent/src/main.ts
|
|
49632
|
-
var AGENT_VERSION2 = true ? "0.3.
|
|
50832
|
+
var AGENT_VERSION2 = true ? "0.3.48" : "0.3.2";
|
|
49633
50833
|
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" : "";
|
|
49634
50834
|
var AI_CONNECTION_SHIPPED = false;
|
|
49635
50835
|
function processAlive(pid) {
|