local-commander-agent 0.3.42 → 0.3.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/runtime/JobHost.exe +0 -0
- package/runtime/LocalCommanderAgent.exe +0 -0
- package/runtime/OwnerBridge.exe +0 -0
- package/runtime/agent.mjs +687 -445
package/runtime/agent.mjs
CHANGED
|
@@ -4541,10 +4541,10 @@ function mergeDefs(...defs) {
|
|
|
4541
4541
|
function cloneDef(schema) {
|
|
4542
4542
|
return mergeDefs(schema._zod.def);
|
|
4543
4543
|
}
|
|
4544
|
-
function getElementAtPath(obj,
|
|
4545
|
-
if (!
|
|
4544
|
+
function getElementAtPath(obj, path29) {
|
|
4545
|
+
if (!path29)
|
|
4546
4546
|
return obj;
|
|
4547
|
-
return
|
|
4547
|
+
return path29.reduce((acc, key) => acc?.[key], obj);
|
|
4548
4548
|
}
|
|
4549
4549
|
function promiseAllObject(promisesObj) {
|
|
4550
4550
|
const keys = Object.keys(promisesObj);
|
|
@@ -4884,11 +4884,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
4884
4884
|
}
|
|
4885
4885
|
return false;
|
|
4886
4886
|
}
|
|
4887
|
-
function prefixIssues(
|
|
4887
|
+
function prefixIssues(path29, issues) {
|
|
4888
4888
|
return issues.map((iss) => {
|
|
4889
4889
|
var _a3;
|
|
4890
4890
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
4891
|
-
iss.path.unshift(
|
|
4891
|
+
iss.path.unshift(path29);
|
|
4892
4892
|
return iss;
|
|
4893
4893
|
});
|
|
4894
4894
|
}
|
|
@@ -5338,16 +5338,16 @@ function flattenError(error62, mapper = (issue2) => issue2.message) {
|
|
|
5338
5338
|
}
|
|
5339
5339
|
function formatError(error62, mapper = (issue2) => issue2.message) {
|
|
5340
5340
|
const fieldErrors = { _errors: [] };
|
|
5341
|
-
const processError = (error63,
|
|
5341
|
+
const processError = (error63, path29 = []) => {
|
|
5342
5342
|
for (const issue2 of error63.issues) {
|
|
5343
5343
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
5344
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
5344
|
+
issue2.errors.map((issues) => processError({ issues }, [...path29, ...issue2.path]));
|
|
5345
5345
|
} else if (issue2.code === "invalid_key") {
|
|
5346
|
-
processError({ issues: issue2.issues }, [...
|
|
5346
|
+
processError({ issues: issue2.issues }, [...path29, ...issue2.path]);
|
|
5347
5347
|
} else if (issue2.code === "invalid_element") {
|
|
5348
|
-
processError({ issues: issue2.issues }, [...
|
|
5348
|
+
processError({ issues: issue2.issues }, [...path29, ...issue2.path]);
|
|
5349
5349
|
} else {
|
|
5350
|
-
const fullpath = [...
|
|
5350
|
+
const fullpath = [...path29, ...issue2.path];
|
|
5351
5351
|
if (fullpath.length === 0) {
|
|
5352
5352
|
fieldErrors._errors.push(mapper(issue2));
|
|
5353
5353
|
} else {
|
|
@@ -5386,17 +5386,17 @@ function formatError(error62, mapper = (issue2) => issue2.message) {
|
|
|
5386
5386
|
}
|
|
5387
5387
|
function treeifyError(error62, mapper = (issue2) => issue2.message) {
|
|
5388
5388
|
const result2 = { errors: [] };
|
|
5389
|
-
const processError = (error63,
|
|
5389
|
+
const processError = (error63, path29 = []) => {
|
|
5390
5390
|
var _a3;
|
|
5391
5391
|
for (const issue2 of error63.issues) {
|
|
5392
5392
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
5393
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
5393
|
+
issue2.errors.map((issues) => processError({ issues }, [...path29, ...issue2.path]));
|
|
5394
5394
|
} else if (issue2.code === "invalid_key") {
|
|
5395
|
-
processError({ issues: issue2.issues }, [...
|
|
5395
|
+
processError({ issues: issue2.issues }, [...path29, ...issue2.path]);
|
|
5396
5396
|
} else if (issue2.code === "invalid_element") {
|
|
5397
|
-
processError({ issues: issue2.issues }, [...
|
|
5397
|
+
processError({ issues: issue2.issues }, [...path29, ...issue2.path]);
|
|
5398
5398
|
} else {
|
|
5399
|
-
const fullpath = [...
|
|
5399
|
+
const fullpath = [...path29, ...issue2.path];
|
|
5400
5400
|
if (fullpath.length === 0) {
|
|
5401
5401
|
result2.errors.push(mapper(issue2));
|
|
5402
5402
|
continue;
|
|
@@ -5435,8 +5435,8 @@ function treeifyError(error62, mapper = (issue2) => issue2.message) {
|
|
|
5435
5435
|
}
|
|
5436
5436
|
function toDotPath(_path) {
|
|
5437
5437
|
const segs = [];
|
|
5438
|
-
const
|
|
5439
|
-
for (const seg of
|
|
5438
|
+
const path29 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
5439
|
+
for (const seg of path29) {
|
|
5440
5440
|
if (typeof seg === "number")
|
|
5441
5441
|
segs.push(`[${seg}]`);
|
|
5442
5442
|
else if (typeof seg === "symbol")
|
|
@@ -16905,9 +16905,9 @@ function codePointLengthVar(doc, ctx, accessor, inDoubt) {
|
|
|
16905
16905
|
doc.write(`const ${v} = typeof ${accessor} === "string" && ${inDoubt} ? ${cpLen}(${accessor}) : ${accessor}.length;`);
|
|
16906
16906
|
return v;
|
|
16907
16907
|
}
|
|
16908
|
-
function numericOperand(value,
|
|
16908
|
+
function numericOperand(value, label2) {
|
|
16909
16909
|
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
16910
|
-
throw new ZodCompileUnsupportedError(`${
|
|
16910
|
+
throw new ZodCompileUnsupportedError(`${label2} bound of type ${typeof value}`);
|
|
16911
16911
|
}
|
|
16912
16912
|
return `${value}`;
|
|
16913
16913
|
}
|
|
@@ -22538,13 +22538,13 @@ function resolveRef(ref, ctx) {
|
|
|
22538
22538
|
if (!ref.startsWith("#")) {
|
|
22539
22539
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
22540
22540
|
}
|
|
22541
|
-
const
|
|
22542
|
-
if (
|
|
22541
|
+
const path29 = ref.slice(1).split("/").filter(Boolean);
|
|
22542
|
+
if (path29.length === 0) {
|
|
22543
22543
|
return ctx.rootSchema;
|
|
22544
22544
|
}
|
|
22545
22545
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
22546
|
-
if (
|
|
22547
|
-
const key =
|
|
22546
|
+
if (path29[0] === defsKey) {
|
|
22547
|
+
const key = path29[1] === void 0 ? void 0 : decodeJSONPointerSegment(path29[1]);
|
|
22548
22548
|
if (!key || !ctx.defs[key]) {
|
|
22549
22549
|
throw new Error(`Reference not found: ${ref}`);
|
|
22550
22550
|
}
|
|
@@ -23934,9 +23934,9 @@ function encode4(input2) {
|
|
|
23934
23934
|
}
|
|
23935
23935
|
|
|
23936
23936
|
// ../../node_modules/jose/dist/webapi/lib/validate.js
|
|
23937
|
-
function assertUint8Array(input2,
|
|
23937
|
+
function assertUint8Array(input2, label2) {
|
|
23938
23938
|
if (!(input2 instanceof Uint8Array))
|
|
23939
|
-
throw new TypeError(`${
|
|
23939
|
+
throw new TypeError(`${label2} must be an instance of Uint8Array`);
|
|
23940
23940
|
}
|
|
23941
23941
|
function isObject2(input2) {
|
|
23942
23942
|
if (typeof input2 != "object" || input2 === null || Object.prototype.toString.call(input2) !== "[object Object]")
|
|
@@ -23959,18 +23959,18 @@ function assertNotSet(value, name2) {
|
|
|
23959
23959
|
if (value !== void 0)
|
|
23960
23960
|
throw new TypeError(`${name2} can only be called once`);
|
|
23961
23961
|
}
|
|
23962
|
-
function decodeBase64url(value,
|
|
23962
|
+
function decodeBase64url(value, label2, ErrorClass) {
|
|
23963
23963
|
try {
|
|
23964
23964
|
return decode3(value);
|
|
23965
23965
|
} catch {
|
|
23966
|
-
throw new ErrorClass(`Failed to base64url decode the ${
|
|
23966
|
+
throw new ErrorClass(`Failed to base64url decode the ${label2}`);
|
|
23967
23967
|
}
|
|
23968
23968
|
}
|
|
23969
|
-
function encodeBase64url(value,
|
|
23969
|
+
function encodeBase64url(value, label2, ErrorClass) {
|
|
23970
23970
|
try {
|
|
23971
23971
|
return encode3(value);
|
|
23972
23972
|
} catch {
|
|
23973
|
-
throw new ErrorClass(`The ${
|
|
23973
|
+
throw new ErrorClass(`The ${label2} is not a valid base64url string`);
|
|
23974
23974
|
}
|
|
23975
23975
|
}
|
|
23976
23976
|
function parseJoseHeader(b64, ErrorClass, message2) {
|
|
@@ -24323,9 +24323,9 @@ function secs(str) {
|
|
|
24323
24323
|
const value = parseFloat(matched[2]), numericDate2 = Math.round(value * multipliers[matched[3][0].toLowerCase()]);
|
|
24324
24324
|
return Number.isFinite(numericDate2) || invalidDuration(), matched[1] === "-" || matched[4] === "ago" ? -numericDate2 : numericDate2;
|
|
24325
24325
|
}
|
|
24326
|
-
function validateInput(
|
|
24326
|
+
function validateInput(label2, input2) {
|
|
24327
24327
|
if (!Number.isFinite(input2))
|
|
24328
|
-
throw new TypeError(`Invalid ${
|
|
24328
|
+
throw new TypeError(`Invalid ${label2} input`);
|
|
24329
24329
|
return input2;
|
|
24330
24330
|
}
|
|
24331
24331
|
var normalizeTyp = (value) => {
|
|
@@ -25164,7 +25164,7 @@ async function openNetworkPanel(binaryDirectory, identity) {
|
|
|
25164
25164
|
}
|
|
25165
25165
|
|
|
25166
25166
|
// agent/src/main.ts
|
|
25167
|
-
import
|
|
25167
|
+
import path28 from "node:path";
|
|
25168
25168
|
import os7 from "node:os";
|
|
25169
25169
|
|
|
25170
25170
|
// agent/src/posix-store.ts
|
|
@@ -25583,7 +25583,7 @@ async function acquirePosixJournalGuard(directory, helper) {
|
|
|
25583
25583
|
}
|
|
25584
25584
|
|
|
25585
25585
|
// agent/src/main.ts
|
|
25586
|
-
import { mkdir as mkdir14, open as open13, readFile as
|
|
25586
|
+
import { mkdir as mkdir14, open as open13, readFile as readFile11, realpath as realpath10, rm as rm9 } from "node:fs/promises";
|
|
25587
25587
|
import { fileURLToPath } from "node:url";
|
|
25588
25588
|
|
|
25589
25589
|
// packages/operations/src/crypto.ts
|
|
@@ -25629,8 +25629,129 @@ var SecretBox = class {
|
|
|
25629
25629
|
|
|
25630
25630
|
// agent/src/journal.ts
|
|
25631
25631
|
import { constants as constants2 } from "node:fs";
|
|
25632
|
-
|
|
25633
|
-
|
|
25632
|
+
|
|
25633
|
+
// agent/src/linux-containment.ts
|
|
25634
|
+
import { execFile } from "node:child_process";
|
|
25635
|
+
import { readFile as readFile2, statfs } from "node:fs/promises";
|
|
25636
|
+
import path4 from "node:path";
|
|
25637
|
+
import { promisify } from "node:util";
|
|
25638
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
25639
|
+
var uuid5 = "[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}";
|
|
25640
|
+
var unitName = new RegExp("^lc-command-" + uuid5 + "\\.service$");
|
|
25641
|
+
var bootId = new RegExp("^" + uuid5 + "$");
|
|
25642
|
+
function validLinuxContainment(value) {
|
|
25643
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
25644
|
+
const v = value;
|
|
25645
|
+
return Object.keys(v).length === 5 && Number.isInteger(v.uid) && v.uid > 0 && v.uid <= 4294967295 && typeof v.unit === "string" && unitName.test(v.unit) && typeof v.bootId === "string" && bootId.test(v.bootId) && typeof v.invocationId === "string" && /^[0-9a-f]{32}$/.test(v.invocationId) && !/^0+$/.test(v.invocationId) && typeof v.cgroup === "string" && v.cgroup.length <= 2048 && !v.cgroup.includes("\0") && v.cgroup.startsWith("/user.slice/user-" + v.uid + ".slice/user@" + v.uid + ".service/") && path4.posix.normalize(v.cgroup) === v.cgroup && path4.posix.basename(v.cgroup) === v.unit;
|
|
25646
|
+
}
|
|
25647
|
+
var exec = promisify(execFile);
|
|
25648
|
+
async function linuxSupervisorLiveness(pids, records = []) {
|
|
25649
|
+
if (process.platform !== "linux" || !process.getuid?.() || process.getuid() !== process.geteuid?.()) return null;
|
|
25650
|
+
const remaining = new Set(pids), uid = process.getuid(), deadline = Date.now() + 1e4;
|
|
25651
|
+
const env = buildChildEnvironment(process.env);
|
|
25652
|
+
env.XDG_RUNTIME_DIR = "/run/user/" + uid;
|
|
25653
|
+
env.DBUS_SESSION_BUS_ADDRESS = "unix:path=" + env.XDG_RUNTIME_DIR + "/bus";
|
|
25654
|
+
try {
|
|
25655
|
+
if ((await statfs("/sys/fs/cgroup")).type !== 1667723888) return null;
|
|
25656
|
+
const boot = (await readFile2("/proc/sys/kernel/random/boot_id", "utf8")).trim();
|
|
25657
|
+
const control = (unit, args) => exec(
|
|
25658
|
+
"/usr/bin/systemctl",
|
|
25659
|
+
["--user", "--no-ask-password", ...args, unit],
|
|
25660
|
+
{ env, timeout: Math.max(1, Math.min(2e3, deadline - Date.now())), maxBuffer: 8192, encoding: "utf8", windowsHide: true }
|
|
25661
|
+
);
|
|
25662
|
+
const show = async (unit) => {
|
|
25663
|
+
const properties = ["Id", "LoadState", "ActiveState", "ControlGroup", "InvocationID", "Transient", "Restart", "KillMode"];
|
|
25664
|
+
const result2 = await control(unit, ["show", ...properties.map((p) => "--property=" + p)]).catch((e) => {
|
|
25665
|
+
if (e.code !== 4 || typeof e.stdout !== "string") throw e;
|
|
25666
|
+
return { stdout: e.stdout };
|
|
25667
|
+
});
|
|
25668
|
+
const fields = {};
|
|
25669
|
+
for (const line of result2.stdout.trim().split("\n")) {
|
|
25670
|
+
const at = line.indexOf("="), key = line.slice(0, at);
|
|
25671
|
+
if (at < 1 || !properties.includes(key) || key in fields) throw Error("LINUX_CONTAINMENT_INVALID");
|
|
25672
|
+
fields[key] = line.slice(at + 1);
|
|
25673
|
+
}
|
|
25674
|
+
if (fields.Id !== unit || !fields.LoadState || !fields.ActiveState) throw Error("LINUX_CONTAINMENT_INVALID");
|
|
25675
|
+
return fields;
|
|
25676
|
+
};
|
|
25677
|
+
for (const pid of remaining) {
|
|
25678
|
+
if (Date.now() >= deadline) break;
|
|
25679
|
+
const matches2 = records.filter((r) => r.pid === pid);
|
|
25680
|
+
if (matches2.length !== 1) continue;
|
|
25681
|
+
const proof2 = matches2[0].containment;
|
|
25682
|
+
if (!validLinuxContainment(proof2) || proof2.uid !== uid || proof2.bootId !== boot) continue;
|
|
25683
|
+
try {
|
|
25684
|
+
let stopped2 = false;
|
|
25685
|
+
while (Date.now() < deadline) {
|
|
25686
|
+
const fields = await show(proof2.unit);
|
|
25687
|
+
const absent2 = fields.LoadState === "not-found" && fields.ActiveState === "inactive" && !fields.ControlGroup && !fields.InvocationID;
|
|
25688
|
+
if (!absent2 && (fields.LoadState !== "loaded" || fields.ControlGroup !== proof2.cgroup || fields.InvocationID !== proof2.invocationId || fields.Transient !== "yes" || fields.Restart !== "no" || fields.KillMode !== "control-group")) break;
|
|
25689
|
+
if (absent2 || fields.ActiveState === "inactive" || fields.ActiveState === "failed") {
|
|
25690
|
+
const empty = await readFile2("/sys/fs/cgroup" + proof2.cgroup + "/cgroup.events", "utf8").then((text3) => /(?:^|\n)populated 0(?:\n|$)/.test(text3), (e) => e.code === "ENOENT");
|
|
25691
|
+
if (empty) remaining.delete(pid);
|
|
25692
|
+
break;
|
|
25693
|
+
}
|
|
25694
|
+
if (!stopped2) {
|
|
25695
|
+
await control(proof2.unit, ["stop"]).catch(() => {
|
|
25696
|
+
});
|
|
25697
|
+
stopped2 = true;
|
|
25698
|
+
} else await delay(50);
|
|
25699
|
+
}
|
|
25700
|
+
} catch {
|
|
25701
|
+
}
|
|
25702
|
+
}
|
|
25703
|
+
return remaining;
|
|
25704
|
+
} catch {
|
|
25705
|
+
return null;
|
|
25706
|
+
}
|
|
25707
|
+
}
|
|
25708
|
+
|
|
25709
|
+
// agent/src/darwin-containment.ts
|
|
25710
|
+
import { execFile as execFile2 } from "node:child_process";
|
|
25711
|
+
import { promisify as promisify2 } from "node:util";
|
|
25712
|
+
var label = /^app\.localcmd\.command\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
25713
|
+
var bootSession = /^[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}$/;
|
|
25714
|
+
function validDarwinContainment(value) {
|
|
25715
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
25716
|
+
const v = value;
|
|
25717
|
+
return Object.keys(v).length === 4 && Number.isInteger(v.uid) && v.uid > 0 && v.uid <= 4294967295 && typeof v.label === "string" && label.test(v.label) && typeof v.bootSession === "string" && bootSession.test(v.bootSession) && typeof v.coalition === "string" && /^[1-9][0-9]{0,17}$/.test(v.coalition) && v.coalition !== "1";
|
|
25718
|
+
}
|
|
25719
|
+
var exec2 = promisify2(execFile2);
|
|
25720
|
+
async function darwinSupervisorLiveness(helper, pids, records = []) {
|
|
25721
|
+
if (process.platform !== "darwin" || !process.getuid?.() || process.getuid() !== process.geteuid?.()) return null;
|
|
25722
|
+
const remaining = new Set(pids), uid = process.getuid(), deadline = Date.now() + 1e4, env = buildChildEnvironment(process.env);
|
|
25723
|
+
const run = (file2, args) => exec2(
|
|
25724
|
+
file2,
|
|
25725
|
+
args,
|
|
25726
|
+
{ env, timeout: Math.max(1, Math.min(7e3, deadline - Date.now())), maxBuffer: 8192, encoding: "utf8", windowsHide: true }
|
|
25727
|
+
);
|
|
25728
|
+
try {
|
|
25729
|
+
const boot = (await run("/usr/sbin/sysctl", ["-n", "kern.bootsessionuuid"])).stdout.trim();
|
|
25730
|
+
if (!bootSession.test(boot)) return null;
|
|
25731
|
+
for (const pid of remaining) {
|
|
25732
|
+
if (Date.now() >= deadline) break;
|
|
25733
|
+
const matches2 = records.filter((r) => r.pid === pid);
|
|
25734
|
+
if (matches2.length !== 1) continue;
|
|
25735
|
+
const proof2 = matches2[0].containment;
|
|
25736
|
+
if (!validDarwinContainment(proof2) || proof2.uid !== uid || proof2.bootSession !== boot) continue;
|
|
25737
|
+
try {
|
|
25738
|
+
await run(helper, ["--reap", proof2.coalition]);
|
|
25739
|
+
if ((await run(helper, ["--count", proof2.coalition])).stdout.trim() !== "0") continue;
|
|
25740
|
+
await run("/bin/launchctl", ["bootout", "gui/" + uid + "/" + proof2.label]).catch(() => {
|
|
25741
|
+
});
|
|
25742
|
+
remaining.delete(pid);
|
|
25743
|
+
} catch {
|
|
25744
|
+
}
|
|
25745
|
+
}
|
|
25746
|
+
return remaining;
|
|
25747
|
+
} catch {
|
|
25748
|
+
return null;
|
|
25749
|
+
}
|
|
25750
|
+
}
|
|
25751
|
+
|
|
25752
|
+
// agent/src/journal.ts
|
|
25753
|
+
import { lstat as lstat2, mkdir as mkdir3, open as open3, readdir as readdir2, readFile as readFile3, realpath as realpath2, rename, rm as rm2 } from "node:fs/promises";
|
|
25754
|
+
import path6 from "node:path";
|
|
25634
25755
|
import { createHash as createHash7, randomBytes as randomBytes4, randomUUID as randomUUID4 } from "node:crypto";
|
|
25635
25756
|
|
|
25636
25757
|
// src/output-buffer.ts
|
|
@@ -25864,7 +25985,7 @@ import { createHash as createHash6, createPublicKey as createPublicKey3, KeyObje
|
|
|
25864
25985
|
|
|
25865
25986
|
// packages/contracts/src/agent-policy.ts
|
|
25866
25987
|
var agentPolicyProtocolVersion = 1;
|
|
25867
|
-
var
|
|
25988
|
+
var uuid8 = external_exports.string().uuid().toLowerCase();
|
|
25868
25989
|
var utcDateTime = external_exports.iso.datetime({ offset: false }).refine(
|
|
25869
25990
|
(value) => /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?Z$/.test(value),
|
|
25870
25991
|
"Expected UTC timestamp with seconds"
|
|
@@ -26009,11 +26130,11 @@ var AdapterActionInputSchema = external_exports.object({
|
|
|
26009
26130
|
});
|
|
26010
26131
|
var TrustedActionBindingSchema = external_exports.object({
|
|
26011
26132
|
bindingSource: external_exports.enum(["server", "endpoint-attestation"]),
|
|
26012
|
-
tenantId:
|
|
26013
|
-
accountId:
|
|
26014
|
-
grantId:
|
|
26015
|
-
deviceId:
|
|
26016
|
-
executionSessionId:
|
|
26133
|
+
tenantId: uuid8,
|
|
26134
|
+
accountId: uuid8,
|
|
26135
|
+
grantId: uuid8.optional(),
|
|
26136
|
+
deviceId: uuid8.optional(),
|
|
26137
|
+
executionSessionId: uuid8.optional(),
|
|
26017
26138
|
authenticatedAt: utcDateTime,
|
|
26018
26139
|
expiresAt: utcDateTime
|
|
26019
26140
|
}).strict().refine((value) => Date.parse(value.authenticatedAt) < Date.parse(value.expiresAt), {
|
|
@@ -26022,7 +26143,7 @@ var TrustedActionBindingSchema = external_exports.object({
|
|
|
26022
26143
|
});
|
|
26023
26144
|
var BoundActionRequestSchema = external_exports.object({
|
|
26024
26145
|
protocolVersion: external_exports.literal(agentPolicyProtocolVersion),
|
|
26025
|
-
requestId:
|
|
26146
|
+
requestId: uuid8,
|
|
26026
26147
|
input: AdapterActionInputSchema,
|
|
26027
26148
|
binding: TrustedActionBindingSchema
|
|
26028
26149
|
}).strict().superRefine((value, ctx) => {
|
|
@@ -26056,8 +26177,8 @@ var TransformSpecSchema = external_exports.object({
|
|
|
26056
26177
|
}).strict();
|
|
26057
26178
|
var PolicyDecisionSchema = external_exports.object({
|
|
26058
26179
|
protocolVersion: external_exports.literal(agentPolicyProtocolVersion),
|
|
26059
|
-
decisionId:
|
|
26060
|
-
requestId:
|
|
26180
|
+
decisionId: uuid8,
|
|
26181
|
+
requestId: uuid8,
|
|
26061
26182
|
policyId: slug,
|
|
26062
26183
|
policyVersion: external_exports.string().trim().min(1).max(64),
|
|
26063
26184
|
decidedAt: utcDateTime,
|
|
@@ -26090,15 +26211,15 @@ var ContentEvidenceSchema = external_exports.discriminatedUnion("mode", [
|
|
|
26090
26211
|
external_exports.object({ mode: external_exports.literal("none") }).strict(),
|
|
26091
26212
|
external_exports.object({
|
|
26092
26213
|
mode: external_exports.literal("encrypted-opt-in"),
|
|
26093
|
-
objectId:
|
|
26214
|
+
objectId: uuid8,
|
|
26094
26215
|
keyFingerprint: sha256
|
|
26095
26216
|
}).strict()
|
|
26096
26217
|
]);
|
|
26097
26218
|
var ActionEvidenceSchema = external_exports.object({
|
|
26098
26219
|
protocolVersion: external_exports.literal(agentPolicyProtocolVersion),
|
|
26099
|
-
evidenceId:
|
|
26100
|
-
requestId:
|
|
26101
|
-
decisionId:
|
|
26220
|
+
evidenceId: uuid8,
|
|
26221
|
+
requestId: uuid8,
|
|
26222
|
+
decisionId: uuid8,
|
|
26102
26223
|
occurredAt: utcDateTime,
|
|
26103
26224
|
mediation: external_exports.enum(["mediated", "observed-only", "unknown"]),
|
|
26104
26225
|
phase: external_exports.enum(["request", "decision", "dispatch", "result"]),
|
|
@@ -26122,7 +26243,7 @@ function projectRelativePath(value) {
|
|
|
26122
26243
|
if (normalized.split("/").some((part) => !part || part === "." || part === ".." || /[. ]$/u.test(part) || /^(?:con|prn|aux|nul|clock\$|conin\$|conout\$|com[1-9¹²³]|lpt[1-9¹²³])(?:\.|$)/iu.test(part))) throw new TypeError("Invalid relativePath");
|
|
26123
26244
|
return normalized;
|
|
26124
26245
|
}
|
|
26125
|
-
var
|
|
26246
|
+
var uuid9 = external_exports.string().uuid().toLowerCase();
|
|
26126
26247
|
var hash2 = external_exports.string().regex(/^[a-f0-9]{64}$/);
|
|
26127
26248
|
var ProjectRelativePathSchema = external_exports.string().transform((value, ctx) => {
|
|
26128
26249
|
try {
|
|
@@ -26133,8 +26254,8 @@ var ProjectRelativePathSchema = external_exports.string().transform((value, ctx)
|
|
|
26133
26254
|
}
|
|
26134
26255
|
});
|
|
26135
26256
|
var ProjectTargetBindingSchema = external_exports.object({
|
|
26136
|
-
projectId:
|
|
26137
|
-
targetId:
|
|
26257
|
+
projectId: uuid9,
|
|
26258
|
+
targetId: uuid9,
|
|
26138
26259
|
environment: external_exports.enum(["dev", "staging", "prod"]),
|
|
26139
26260
|
relativePath: ProjectRelativePathSchema,
|
|
26140
26261
|
repositoryFingerprint: hash2,
|
|
@@ -26167,7 +26288,7 @@ function repositoryFingerprint(remote) {
|
|
|
26167
26288
|
var protocolVersion = 1;
|
|
26168
26289
|
var MAX_FILE_WRITE_BYTES = 1024 * 1024;
|
|
26169
26290
|
var MAX_RELAY_FRAME_BYTES = 8 * 1024 * 1024;
|
|
26170
|
-
var
|
|
26291
|
+
var uuid10 = external_exports.string().uuid().toLowerCase();
|
|
26171
26292
|
var nonEmpty = external_exports.string().trim().min(1);
|
|
26172
26293
|
var utcDateTime2 = external_exports.iso.datetime({ offset: false }).refine((value) => /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?Z$/.test(value), "Expected UTC timestamp with seconds");
|
|
26173
26294
|
var units = external_exports.number().int().min(0).max(1e9);
|
|
@@ -26223,27 +26344,27 @@ var ErrorCodeSchema = external_exports.enum([
|
|
|
26223
26344
|
var LedgerEventKindSchema = external_exports.enum(["reserve", "charge", "release", "credit"]);
|
|
26224
26345
|
var TrustedPrincipalSchema = external_exports.object({
|
|
26225
26346
|
protocolVersion: external_exports.literal(protocolVersion),
|
|
26226
|
-
accountId:
|
|
26227
|
-
tenantId:
|
|
26228
|
-
grantId:
|
|
26347
|
+
accountId: uuid10,
|
|
26348
|
+
tenantId: uuid10,
|
|
26349
|
+
grantId: uuid10,
|
|
26229
26350
|
scopes: external_exports.array(PermissionScopeSchema).min(1).max(32),
|
|
26230
26351
|
authenticatedAt: utcDateTime2,
|
|
26231
26352
|
expiresAt: utcDateTime2
|
|
26232
26353
|
}).strict().refine((value) => Date.parse(value.authenticatedAt) < Date.parse(value.expiresAt), { path: ["expiresAt"], message: "Expiry must follow authentication" });
|
|
26233
26354
|
var ExecutionSessionSchema = external_exports.object({
|
|
26234
26355
|
protocolVersion: external_exports.literal(protocolVersion),
|
|
26235
|
-
executionSessionId:
|
|
26236
|
-
tenantId:
|
|
26237
|
-
grantId:
|
|
26238
|
-
deviceId:
|
|
26239
|
-
workspaceGrantId:
|
|
26356
|
+
executionSessionId: uuid10,
|
|
26357
|
+
tenantId: uuid10,
|
|
26358
|
+
grantId: uuid10,
|
|
26359
|
+
deviceId: uuid10,
|
|
26360
|
+
workspaceGrantId: uuid10.optional(),
|
|
26240
26361
|
policyVersion: external_exports.string().trim().min(1).max(64),
|
|
26241
26362
|
openedAt: utcDateTime2,
|
|
26242
26363
|
expiresAt: utcDateTime2,
|
|
26243
26364
|
state: external_exports.enum(["open", "closing", "closed", "expired"])
|
|
26244
26365
|
}).strict().refine((value) => Date.parse(value.openedAt) < Date.parse(value.expiresAt), { path: ["expiresAt"], message: "Expiry must follow session creation" });
|
|
26245
26366
|
var ChildCommandSchema = external_exports.object({
|
|
26246
|
-
childExecutionId:
|
|
26367
|
+
childExecutionId: uuid10,
|
|
26247
26368
|
executable: nonEmpty.max(260),
|
|
26248
26369
|
argv: external_exports.array(external_exports.string().max(8192)).max(128).default([]),
|
|
26249
26370
|
cwd: external_exports.string().trim().min(1).max(2048).optional(),
|
|
@@ -26251,8 +26372,8 @@ var ChildCommandSchema = external_exports.object({
|
|
|
26251
26372
|
}).strict();
|
|
26252
26373
|
var ClientCommandRequestSchema = external_exports.object({
|
|
26253
26374
|
protocolVersion: external_exports.literal(protocolVersion),
|
|
26254
|
-
executionSessionId:
|
|
26255
|
-
operationId:
|
|
26375
|
+
executionSessionId: uuid10,
|
|
26376
|
+
operationId: uuid10,
|
|
26256
26377
|
idempotencyKey: external_exports.string().trim().min(8).max(128),
|
|
26257
26378
|
children: external_exports.array(ChildCommandSchema).min(2).max(32)
|
|
26258
26379
|
}).strict().superRefine((value, ctx) => {
|
|
@@ -26266,25 +26387,25 @@ var ClientCommandRequestSchema = external_exports.object({
|
|
|
26266
26387
|
});
|
|
26267
26388
|
var ControlOperationSchema = external_exports.object({
|
|
26268
26389
|
protocolVersion: external_exports.literal(protocolVersion),
|
|
26269
|
-
executionSessionId:
|
|
26270
|
-
operationId:
|
|
26390
|
+
executionSessionId: uuid10,
|
|
26391
|
+
operationId: uuid10,
|
|
26271
26392
|
kind: external_exports.enum(["status", "output", "cancel"]),
|
|
26272
26393
|
cursor: external_exports.string().trim().min(1).max(512).optional()
|
|
26273
26394
|
}).strict();
|
|
26274
26395
|
var LedgerEventSchema = external_exports.object({
|
|
26275
26396
|
protocolVersion: external_exports.literal(protocolVersion),
|
|
26276
|
-
tenantId:
|
|
26277
|
-
executionId:
|
|
26397
|
+
tenantId: uuid10,
|
|
26398
|
+
executionId: uuid10,
|
|
26278
26399
|
eventKind: LedgerEventKindSchema,
|
|
26279
26400
|
units: external_exports.literal(1),
|
|
26280
26401
|
periodStartUtc: utcDateTime2,
|
|
26281
26402
|
periodEndUtc: utcDateTime2,
|
|
26282
26403
|
occurredAt: utcDateTime2,
|
|
26283
|
-
adjustmentId:
|
|
26404
|
+
adjustmentId: uuid10.optional()
|
|
26284
26405
|
}).strict().refine(validUsagePeriod, { path: ["periodEndUtc"], message: "Expected one UTC calendar month" }).refine((value) => value.eventKind !== "credit" || value.adjustmentId !== void 0, { path: ["adjustmentId"], message: "Credit requires a unique adjustment ID" });
|
|
26285
26406
|
var UsageCountersSchema = external_exports.object({
|
|
26286
26407
|
protocolVersion: external_exports.literal(protocolVersion),
|
|
26287
|
-
tenantId:
|
|
26408
|
+
tenantId: uuid10,
|
|
26288
26409
|
periodStartUtc: utcDateTime2,
|
|
26289
26410
|
periodEndUtc: utcDateTime2,
|
|
26290
26411
|
limitUnits: units,
|
|
@@ -26302,7 +26423,7 @@ var OperationErrorSchema = external_exports.object({
|
|
|
26302
26423
|
}).strict();
|
|
26303
26424
|
|
|
26304
26425
|
// packages/contracts/src/device-protocol.ts
|
|
26305
|
-
var
|
|
26426
|
+
var uuid11 = external_exports.string().uuid().toLowerCase();
|
|
26306
26427
|
var hash3 = external_exports.string().regex(/^[a-f0-9]{64}$/);
|
|
26307
26428
|
var epoch2 = external_exports.string().regex(/^[1-9]\d{0,18}$/).refine((v) => BigInt(v) <= 9223372036854775807n);
|
|
26308
26429
|
var text = external_exports.string().max(32767).refine((v) => !v.includes("\0"));
|
|
@@ -26310,19 +26431,19 @@ var timestamp = external_exports.iso.datetime({ offset: false });
|
|
|
26310
26431
|
var EfficiencyProfileSchema = external_exports.object({
|
|
26311
26432
|
model: external_exports.string().regex(/^[A-Za-z0-9][A-Za-z0-9._:/+-]{0,79}$/)
|
|
26312
26433
|
}).strict();
|
|
26313
|
-
var
|
|
26434
|
+
var path5 = text.min(1);
|
|
26314
26435
|
var ToolCallSchema = external_exports.discriminatedUnion("name", [
|
|
26315
26436
|
external_exports.object({ name: external_exports.literal("project_identity"), args: external_exports.object({ path: ProjectRelativePathSchema }).strict() }).strict(),
|
|
26316
|
-
external_exports.object({ name: external_exports.literal("fs_list"), args: external_exports.object({ path:
|
|
26317
|
-
external_exports.object({ name: external_exports.literal("fs_read"), args: external_exports.object({ path:
|
|
26318
|
-
external_exports.object({ name: external_exports.literal("fs_search"), args: external_exports.object({ path:
|
|
26319
|
-
external_exports.object({ name: external_exports.literal("fs_write"), args: external_exports.object({ path:
|
|
26320
|
-
external_exports.object({ name: external_exports.literal("fs_replace"), args: external_exports.object({ path:
|
|
26321
|
-
external_exports.object({ name: external_exports.literal("git_status"), args: external_exports.object({ path:
|
|
26322
|
-
external_exports.object({ name: external_exports.literal("git_diff"), args: external_exports.object({ path:
|
|
26323
|
-
external_exports.object({ name: external_exports.literal("git_log"), args: external_exports.object({ path:
|
|
26324
|
-
external_exports.object({ name: external_exports.literal("project_snapshot"), args: external_exports.object({ path:
|
|
26325
|
-
external_exports.object({ name: external_exports.literal("command_run"), args: external_exports.object({ command: external_exports.string().min(1).max(260).refine((v) => !/[\r\n\0]/.test(v)), args: external_exports.array(external_exports.string().max(8192).refine((v) => !v.includes("\0"))).max(128).default([]), cwd:
|
|
26437
|
+
external_exports.object({ name: external_exports.literal("fs_list"), args: external_exports.object({ path: path5.optional(), recursive: external_exports.boolean().default(false), maxDepth: external_exports.number().int().min(0).max(8).default(3), maxEntries: external_exports.number().int().min(1).max(1e3).default(200) }).strict() }).strict(),
|
|
26438
|
+
external_exports.object({ name: external_exports.literal("fs_read"), args: external_exports.object({ path: path5, startLine: external_exports.number().int().min(1).max(1e6).optional(), endLine: external_exports.number().int().min(1).max(1e6).optional() }).strict() }).strict(),
|
|
26439
|
+
external_exports.object({ name: external_exports.literal("fs_search"), args: external_exports.object({ path: path5.optional(), query: external_exports.string().min(1).max(1e3), caseSensitive: external_exports.boolean().default(false), maxResults: external_exports.number().int().min(1).max(300).default(100) }).strict() }).strict(),
|
|
26440
|
+
external_exports.object({ name: external_exports.literal("fs_write"), args: external_exports.object({ path: path5, content: external_exports.string().max(MAX_FILE_WRITE_BYTES).refine((value) => Buffer.byteLength(value, "utf8") <= MAX_FILE_WRITE_BYTES, "fs_write content exceeds 1 MiB UTF-8"), overwrite: external_exports.boolean().default(false), expectedSha256: hash3.optional() }).strict() }).strict(),
|
|
26441
|
+
external_exports.object({ name: external_exports.literal("fs_replace"), args: external_exports.object({ path: path5, oldText: external_exports.string().min(1).max(6e4), newText: external_exports.string().max(6e4), replaceAll: external_exports.boolean().default(false), expectedSha256: hash3.optional() }).strict() }).strict(),
|
|
26442
|
+
external_exports.object({ name: external_exports.literal("git_status"), args: external_exports.object({ path: path5.optional() }).strict() }).strict(),
|
|
26443
|
+
external_exports.object({ name: external_exports.literal("git_diff"), args: external_exports.object({ path: path5.optional(), file: path5.optional(), staged: external_exports.boolean().default(false) }).strict() }).strict(),
|
|
26444
|
+
external_exports.object({ name: external_exports.literal("git_log"), args: external_exports.object({ path: path5.optional(), limit: external_exports.number().int().min(1).max(50).default(15) }).strict() }).strict(),
|
|
26445
|
+
external_exports.object({ name: external_exports.literal("project_snapshot"), args: external_exports.object({ path: path5.optional(), startup: external_exports.boolean().optional(), taskId: external_exports.string().regex(/^[A-Za-z0-9_-]{1,100}$/).optional() }).strict() }).strict(),
|
|
26446
|
+
external_exports.object({ name: external_exports.literal("command_run"), args: external_exports.object({ command: external_exports.string().min(1).max(260).refine((v) => !/[\r\n\0]/.test(v)), args: external_exports.array(external_exports.string().max(8192).refine((v) => !v.includes("\0"))).max(128).default([]), cwd: path5.optional(), timeoutMs: external_exports.number().int().min(100).max(864e5).default(6e4) }).strict() }).strict(),
|
|
26326
26447
|
external_exports.object({ name: external_exports.literal("localhost_request"), args: external_exports.object({ url: external_exports.string().url().max(2048), method: external_exports.enum(["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE"]).default("GET"), headers: external_exports.record(external_exports.string().max(128), external_exports.string().max(2048)).optional(), body: external_exports.string().max(6e4).optional() }).strict() }).strict()
|
|
26327
26448
|
]);
|
|
26328
26449
|
function scopeForTool(call) {
|
|
@@ -26330,29 +26451,29 @@ function scopeForTool(call) {
|
|
|
26330
26451
|
if (call.name === "localhost_request") return "localhost:access";
|
|
26331
26452
|
return call.name === "fs_write" || call.name === "fs_replace" ? "files:write" : "files:read";
|
|
26332
26453
|
}
|
|
26333
|
-
var ExecutionBindingSchema = external_exports.object({ tenantId:
|
|
26454
|
+
var ExecutionBindingSchema = external_exports.object({ tenantId: uuid11, accountId: uuid11.optional(), deviceId: uuid11, grantId: uuid11, sessionId: uuid11, operationId: uuid11, executionId: uuid11, connectionEpoch: epoch2, workspaceGrantId: uuid11, policyVersion: external_exports.number().int().min(1).max(2147483647), payloadHash: hash3, deadlineAt: timestamp, projectTarget: ProjectTargetBindingSchema.optional() }).strict();
|
|
26334
26455
|
var EfficiencyNoticeSchema = external_exports.object({ message: external_exports.string().min(1).max(160), estimatedSavedTokens: external_exports.number().int().min(1).max(1e12), savedBytes: external_exports.number().int().min(1).max(1e12), sessionCalls: external_exports.number().int().min(20).max(1e9) }).strict();
|
|
26335
26456
|
var ResultSchema = external_exports.object({ exitCode: external_exports.number().int().min(-2147483648).max(4294967295).nullable(), timedOut: external_exports.boolean(), cancelled: external_exports.boolean(), treeTerminated: external_exports.boolean(), stdout: external_exports.string().max(196608), stderr: external_exports.string().max(196608), stdoutTruncated: external_exports.boolean(), stderrTruncated: external_exports.boolean(), resultCode: external_exports.string().regex(/^[A-Z0-9_]{1,40}$/), efficiencyNotice: EfficiencyNoticeSchema.optional() }).strict();
|
|
26336
26457
|
var ServerFrameSchema = external_exports.discriminatedUnion("type", [
|
|
26337
|
-
external_exports.object({ type: external_exports.literal("hello"), version: external_exports.literal(1), tenantId:
|
|
26458
|
+
external_exports.object({ type: external_exports.literal("hello"), version: external_exports.literal(1), tenantId: uuid11, deviceId: uuid11, connectionEpoch: epoch2, serverTime: timestamp }).strict(),
|
|
26338
26459
|
external_exports.object({ type: external_exports.literal("prepare"), version: external_exports.literal(1), binding: ExecutionBindingSchema, tool: ToolCallSchema }).strict(),
|
|
26339
26460
|
external_exports.object({ type: external_exports.literal("execute"), version: external_exports.literal(1), binding: ExecutionBindingSchema }).strict(),
|
|
26340
|
-
external_exports.object({ type: external_exports.literal("control"), version: external_exports.literal(1), requestId:
|
|
26461
|
+
external_exports.object({ type: external_exports.literal("control"), version: external_exports.literal(1), requestId: uuid11, binding: ExecutionBindingSchema, action: external_exports.enum(["status", "output", "cancel"]) }).strict(),
|
|
26341
26462
|
external_exports.object({ type: external_exports.literal("heartbeat_ack"), version: external_exports.literal(1), connectionEpoch: epoch2, leaseExpiresAt: timestamp }).strict(),
|
|
26342
|
-
external_exports.object({ type: external_exports.literal("workspace_ack"), version: external_exports.literal(1), requestId:
|
|
26463
|
+
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(),
|
|
26343
26464
|
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()
|
|
26344
26465
|
]);
|
|
26345
26466
|
var ClientFrameSchema = external_exports.discriminatedUnion("type", [
|
|
26346
26467
|
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(),
|
|
26347
26468
|
external_exports.object({ type: external_exports.literal("heartbeat"), version: external_exports.literal(1), connectionEpoch: epoch2 }).strict(),
|
|
26348
|
-
external_exports.object({ type: external_exports.literal("workspace_grant"), version: external_exports.literal(1), requestId:
|
|
26349
|
-
external_exports.object({ type: external_exports.literal("workspace_revoke"), version: external_exports.literal(1), requestId:
|
|
26469
|
+
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(),
|
|
26470
|
+
external_exports.object({ type: external_exports.literal("workspace_revoke"), version: external_exports.literal(1), requestId: uuid11, workspaceGrantId: uuid11 }).strict(),
|
|
26350
26471
|
external_exports.object({ type: external_exports.literal("prepared"), version: external_exports.literal(1), binding: ExecutionBindingSchema }).strict(),
|
|
26351
26472
|
external_exports.object({ type: external_exports.literal("accepted"), version: external_exports.literal(1), binding: ExecutionBindingSchema }).strict(),
|
|
26352
26473
|
external_exports.object({ type: external_exports.literal("running"), version: external_exports.literal(1), binding: ExecutionBindingSchema, pid: external_exports.number().int().positive().optional() }).strict(),
|
|
26353
26474
|
external_exports.object({ type: external_exports.literal("result"), version: external_exports.literal(1), binding: ExecutionBindingSchema, result: ResultSchema }).strict(),
|
|
26354
26475
|
external_exports.object({ type: external_exports.literal("not_accepted"), version: external_exports.literal(1), binding: ExecutionBindingSchema, code: external_exports.string().regex(/^[A-Z0-9_]{1,40}$/), provedNotStarted: external_exports.boolean() }).strict(),
|
|
26355
|
-
external_exports.object({ type: external_exports.literal("control_result"), version: external_exports.literal(1), requestId:
|
|
26476
|
+
external_exports.object({ type: external_exports.literal("control_result"), version: external_exports.literal(1), requestId: uuid11, binding: ExecutionBindingSchema, state: external_exports.enum(["prepared", "accepted", "running", "finished", "failed", "cancelled", "rejected", "unknown", "missing"]), result: ResultSchema.optional() }).strict()
|
|
26356
26477
|
]);
|
|
26357
26478
|
var TerminalMetricsSchema = external_exports.object({ stdoutBytes: external_exports.number().int().min(0).max(4194304), stderrBytes: external_exports.number().int().min(0).max(4194304), outputTruncated: external_exports.boolean() }).strict();
|
|
26358
26479
|
var TERMINAL_METRICS_CAPABILITY = "terminalMetrics";
|
|
@@ -26362,8 +26483,8 @@ var NATIVE_CAPACITY_CAPABILITY = "nativeCapacity";
|
|
|
26362
26483
|
var NativeCapacitySchema = external_exports.object({ type: external_exports.literal("nativeCapacity"), protocolVersion: external_exports.literal(1), connectionEpoch: epoch2, safeSlots: external_exports.number().int().min(1).max(32), agentVersion: external_exports.string().regex(/^[A-Za-z0-9._+-]{1,64}$/) }).strict();
|
|
26363
26484
|
var NATIVE_STATUS_CAPABILITY = "nativeStatusV1";
|
|
26364
26485
|
var NativeStatusSchema = NativeCapacitySchema.extend({ type: external_exports.literal("nativeStatus"), active: external_exports.number().int().min(0).max(32), queued: external_exports.number().int().min(0).max(256), paused: external_exports.boolean() }).strict().refine((v) => v.active <= v.safeSlots);
|
|
26365
|
-
var TerminalEventSchema = external_exports.object({ type: external_exports.literal("executionResult"), protocolVersion: external_exports.literal(1), requestId:
|
|
26366
|
-
var TerminalEventAckSchema = external_exports.object({ type: external_exports.literal("executionResultAck"), protocolVersion: external_exports.literal(1), requestId:
|
|
26486
|
+
var TerminalEventSchema = external_exports.object({ type: external_exports.literal("executionResult"), protocolVersion: external_exports.literal(1), requestId: uuid11, tenantId: uuid11, deviceId: uuid11, connectionEpoch: epoch2, binding: ExecutionBindingSchema, state: external_exports.enum(["finished", "failed", "cancelled", "unknown", "rejected"]), resultCode: external_exports.string().regex(/^[A-Z0-9_]{1,40}$/), metrics: TerminalMetricsSchema.optional() }).strict();
|
|
26487
|
+
var TerminalEventAckSchema = external_exports.object({ type: external_exports.literal("executionResultAck"), protocolVersion: external_exports.literal(1), requestId: uuid11, ok: external_exports.boolean() }).strict();
|
|
26367
26488
|
function canonicalJson(value) {
|
|
26368
26489
|
function canonical2(v) {
|
|
26369
26490
|
if (Array.isArray(v)) return v.map(canonical2);
|
|
@@ -26396,16 +26517,16 @@ var guardAdapter = AdapterDescriptorSchema.parse({
|
|
|
26396
26517
|
detectsNativeBypass: false
|
|
26397
26518
|
}
|
|
26398
26519
|
});
|
|
26399
|
-
var
|
|
26520
|
+
var uuid12 = external_exports.string().uuid().toLowerCase();
|
|
26400
26521
|
var GuardSettingsSchema = external_exports.object({
|
|
26401
26522
|
policyId: external_exports.string().regex(/^[a-z][a-z0-9._-]{0,63}$/),
|
|
26402
26523
|
keys: external_exports.array(external_exports.object({ keyId: external_exports.string().regex(/^[a-z][a-z0-9._-]{0,63}$/), publicKeyPem: external_exports.string().max(1024) }).strict()).min(1).max(8),
|
|
26403
26524
|
environment: EnvironmentContextSchema
|
|
26404
26525
|
}).strict();
|
|
26405
26526
|
var GuardConfigurationSchema = GuardSettingsSchema.extend({
|
|
26406
|
-
tenantId:
|
|
26407
|
-
deviceId:
|
|
26408
|
-
ownerAccountId:
|
|
26527
|
+
tenantId: uuid12,
|
|
26528
|
+
deviceId: uuid12,
|
|
26529
|
+
ownerAccountId: uuid12,
|
|
26409
26530
|
ownerSid: external_exports.string().regex(/^S-1-(?:[0-9]+-)+[0-9]+$/).max(184)
|
|
26410
26531
|
}).strict();
|
|
26411
26532
|
function guardHash(value) {
|
|
@@ -26486,14 +26607,14 @@ var GuardEventSchema = external_exports.object({
|
|
|
26486
26607
|
previousHash: hash4,
|
|
26487
26608
|
hash: hash4
|
|
26488
26609
|
}).strict();
|
|
26489
|
-
var
|
|
26610
|
+
var uuid13 = external_exports.string().uuid().toLowerCase();
|
|
26490
26611
|
var GuardEvidenceRecordSchema = external_exports.object({
|
|
26491
|
-
tenantId:
|
|
26492
|
-
deviceId:
|
|
26493
|
-
accountId:
|
|
26494
|
-
sessionId:
|
|
26495
|
-
operationId:
|
|
26496
|
-
executionId:
|
|
26612
|
+
tenantId: uuid13,
|
|
26613
|
+
deviceId: uuid13,
|
|
26614
|
+
accountId: uuid13.optional(),
|
|
26615
|
+
sessionId: uuid13,
|
|
26616
|
+
operationId: uuid13,
|
|
26617
|
+
executionId: uuid13,
|
|
26497
26618
|
state: external_exports.enum(["prepared", "accepted", "running", "finished", "failed", "cancelled", "rejected", "unknown"]),
|
|
26498
26619
|
events: external_exports.array(GuardEventSchema).min(1).max(12)
|
|
26499
26620
|
}).strict();
|
|
@@ -26512,8 +26633,8 @@ function appendGuardEvent(events, input2) {
|
|
|
26512
26633
|
}
|
|
26513
26634
|
var ExportSchema = external_exports.object({
|
|
26514
26635
|
formatVersion: external_exports.literal(1),
|
|
26515
|
-
tenantId:
|
|
26516
|
-
deviceId:
|
|
26636
|
+
tenantId: uuid13,
|
|
26637
|
+
deviceId: uuid13,
|
|
26517
26638
|
records: external_exports.array(GuardEvidenceRecordSchema).max(1e3)
|
|
26518
26639
|
}).strict();
|
|
26519
26640
|
var HeaderSchema = external_exports.object({ alg: external_exports.literal("EdDSA"), typ: external_exports.literal("lc-guard-evidence+jws"), kid: hash4 }).strict();
|
|
@@ -26560,7 +26681,7 @@ var MAX_SUPERVISORS = 8;
|
|
|
26560
26681
|
function validPid(value) {
|
|
26561
26682
|
return Number.isSafeInteger(value) && value > 0 && value <= 4294967295;
|
|
26562
26683
|
}
|
|
26563
|
-
var
|
|
26684
|
+
var uuid14 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
26564
26685
|
var hash5 = /^[0-9a-f]{64}$/;
|
|
26565
26686
|
var bindingKeys = ["executionId", "operationId", "sessionId", "tenantId", "grantId", "deviceId", "connectionEpoch", "payloadHash", "deadlineAt", "workspaceGrantId", "policyVersion", "accountId", "projectTarget"];
|
|
26566
26687
|
var terminal = /* @__PURE__ */ new Set(["finished", "failed", "cancelled", "rejected"]);
|
|
@@ -26580,11 +26701,11 @@ function canonicalTime(value) {
|
|
|
26580
26701
|
}
|
|
26581
26702
|
function validateInput2(value) {
|
|
26582
26703
|
if (!value || typeof value !== "object" || Object.keys(value).some((k) => !bindingKeys.includes(k))) throw failure2("JOURNAL_INPUT_INVALID");
|
|
26583
|
-
for (const name2 of bindingKeys.slice(0, 6)) if (typeof value[name2] !== "string" || !
|
|
26584
|
-
if (value.accountId !== void 0 && !
|
|
26704
|
+
for (const name2 of bindingKeys.slice(0, 6)) if (typeof value[name2] !== "string" || !uuid14.test(value[name2])) throw failure2("JOURNAL_INPUT_INVALID");
|
|
26705
|
+
if (value.accountId !== void 0 && !uuid14.test(value.accountId)) throw failure2("JOURNAL_INPUT_INVALID");
|
|
26585
26706
|
if (value.projectTarget !== void 0 && !ProjectTargetBindingSchema.safeParse(value.projectTarget).success) throw failure2("JOURNAL_INPUT_INVALID");
|
|
26586
26707
|
if (typeof value.connectionEpoch !== "string" || !/^[1-9]\d{0,18}$/.test(value.connectionEpoch) || BigInt(value.connectionEpoch) > 9223372036854775807n || typeof value.payloadHash !== "string" || !hash5.test(value.payloadHash) || !canonicalTime(value.deadlineAt)) throw failure2("JOURNAL_INPUT_INVALID");
|
|
26587
|
-
if (value.workspaceGrantId === void 0 !== (value.policyVersion === void 0) || value.workspaceGrantId !== void 0 && (!
|
|
26708
|
+
if (value.workspaceGrantId === void 0 !== (value.policyVersion === void 0) || value.workspaceGrantId !== void 0 && (!uuid14.test(value.workspaceGrantId) || !Number.isInteger(value.policyVersion) || value.policyVersion < 1 || value.policyVersion > 2147483647)) throw failure2("JOURNAL_INPUT_INVALID");
|
|
26588
26709
|
}
|
|
26589
26710
|
function clone2(value) {
|
|
26590
26711
|
return structuredClone(value);
|
|
@@ -26607,7 +26728,7 @@ function boundedResult(value) {
|
|
|
26607
26728
|
}
|
|
26608
26729
|
}
|
|
26609
26730
|
async function safeDirectory(directory) {
|
|
26610
|
-
const absolute2 =
|
|
26731
|
+
const absolute2 = path6.resolve(directory);
|
|
26611
26732
|
let current2 = absolute2;
|
|
26612
26733
|
for (; ; ) {
|
|
26613
26734
|
try {
|
|
@@ -26615,7 +26736,7 @@ async function safeDirectory(directory) {
|
|
|
26615
26736
|
} catch (e) {
|
|
26616
26737
|
if (e.code !== "ENOENT") throw e;
|
|
26617
26738
|
}
|
|
26618
|
-
const parent =
|
|
26739
|
+
const parent = path6.dirname(current2);
|
|
26619
26740
|
if (parent === current2) break;
|
|
26620
26741
|
current2 = parent;
|
|
26621
26742
|
}
|
|
@@ -26645,7 +26766,7 @@ var NativeJournal = class _NativeJournal {
|
|
|
26645
26766
|
static async open(directory, box, options = {}) {
|
|
26646
26767
|
const maxEntries = options.maxEntries ?? 2e3, maxBytes = options.maxBytes ?? 64 * 1048576, retentionMs = options.retentionMs ?? 864e5;
|
|
26647
26768
|
if (!Number.isInteger(maxEntries) || maxEntries < 1 || maxEntries > 1e4 || !Number.isInteger(maxBytes) || maxBytes < 1024 || maxBytes > 64 * 1048576 || !Number.isInteger(retentionMs) || retentionMs < 0 || retentionMs > 30 * 864e5) throw failure2("JOURNAL_LIMIT_INVALID");
|
|
26648
|
-
const dir = await safeDirectory(directory), lockPath =
|
|
26769
|
+
const dir = await safeDirectory(directory), lockPath = path6.join(dir, "journal.lock"), nonce2 = randomBytes4(16).toString("hex");
|
|
26649
26770
|
const guard = options.lockHelper ? await acquirePosixJournalGuard(dir, options.lockHelper) : void 0;
|
|
26650
26771
|
let file2;
|
|
26651
26772
|
try {
|
|
@@ -26665,7 +26786,7 @@ var NativeJournal = class _NativeJournal {
|
|
|
26665
26786
|
await file2.close().catch(() => {
|
|
26666
26787
|
});
|
|
26667
26788
|
try {
|
|
26668
|
-
const value = JSON.parse(await
|
|
26789
|
+
const value = JSON.parse(await readFile3(lockPath, "utf8"));
|
|
26669
26790
|
if (value.nonce === nonce2) await rm2(lockPath);
|
|
26670
26791
|
} catch {
|
|
26671
26792
|
}
|
|
@@ -26687,10 +26808,10 @@ var NativeJournal = class _NativeJournal {
|
|
|
26687
26808
|
return next;
|
|
26688
26809
|
}
|
|
26689
26810
|
file(id2) {
|
|
26690
|
-
return
|
|
26811
|
+
return path6.join(this.dir, id2 + ".entry");
|
|
26691
26812
|
}
|
|
26692
26813
|
need(id2) {
|
|
26693
|
-
if (!
|
|
26814
|
+
if (!uuid14.test(id2)) throw failure2("JOURNAL_INPUT_INVALID");
|
|
26694
26815
|
const e = this.entries.get(id2);
|
|
26695
26816
|
if (!e) throw failure2("EXECUTION_UNKNOWN");
|
|
26696
26817
|
return clone2(e);
|
|
@@ -26713,7 +26834,7 @@ var NativeJournal = class _NativeJournal {
|
|
|
26713
26834
|
for (const name2 of names) {
|
|
26714
26835
|
if (!name2.endsWith(".entry")) continue;
|
|
26715
26836
|
const id2 = name2.slice(0, -6);
|
|
26716
|
-
if (!
|
|
26837
|
+
if (!uuid14.test(id2)) throw failure2("JOURNAL_CORRUPT");
|
|
26717
26838
|
const envelope = await this.readOwned(id2);
|
|
26718
26839
|
this.totalBytes += envelope.length;
|
|
26719
26840
|
if (this.totalBytes > this.options.maxBytes || this.entries.size >= this.options.maxEntries) throw failure2("JOURNAL_CAPACITY_EXCEEDED");
|
|
@@ -26727,6 +26848,8 @@ var NativeJournal = class _NativeJournal {
|
|
|
26727
26848
|
if (entry.resultCode !== void 0 && (typeof entry.resultCode !== "string" || !/^[A-Z0-9_]{1,40}$/.test(entry.resultCode))) throw Error();
|
|
26728
26849
|
if (entry.reportedAt !== void 0 && (!entry.resultCode || !canonicalTime(entry.reportedAt))) throw Error();
|
|
26729
26850
|
if (entry.supervisors !== void 0 && (!Array.isArray(entry.supervisors) || entry.supervisors.length > MAX_SUPERVISORS || !entry.supervisors.every(validPid))) throw Error();
|
|
26851
|
+
if (entry.linuxSupervisors !== void 0 && (!Array.isArray(entry.linuxSupervisors) || entry.linuxSupervisors.length > MAX_SUPERVISORS || new Set(entry.linuxSupervisors.map((s) => s?.pid)).size !== entry.linuxSupervisors.length || !entry.linuxSupervisors.every((s) => s && Object.keys(s).length === 2 && validPid(s.pid) && entry.supervisors?.includes(s.pid) && validLinuxContainment(s.containment)))) throw Error();
|
|
26852
|
+
if (entry.darwinSupervisors !== void 0 && (!Array.isArray(entry.darwinSupervisors) || entry.darwinSupervisors.length > MAX_SUPERVISORS || new Set(entry.darwinSupervisors.map((s) => s?.pid)).size !== entry.darwinSupervisors.length || !entry.darwinSupervisors.every((s) => s && Object.keys(s).length === 2 && validPid(s.pid) && entry.supervisors?.includes(s.pid) && !entry.linuxSupervisors?.some((l) => l.pid === s.pid) && validDarwinContainment(s.containment)))) throw Error();
|
|
26730
26853
|
if (entry.guardEvents) {
|
|
26731
26854
|
verifyGuardEvidence(entry.guardEvents);
|
|
26732
26855
|
if (entry.guardEvents.some((record2) => record2.event.requestId !== id2)) throw Error();
|
|
@@ -26758,7 +26881,7 @@ var NativeJournal = class _NativeJournal {
|
|
|
26758
26881
|
if (plaintext.length > 262144) throw failure2("JOURNAL_ENTRY_TOO_LARGE");
|
|
26759
26882
|
const envelope = this.box.seal(plaintext, "execution:" + entry.executionId), oldSize = this.sizes.get(entry.executionId) ?? 0;
|
|
26760
26883
|
if (this.totalBytes + envelope.length > this.options.maxBytes) throw failure2("JOURNAL_CAPACITY_EXCEEDED");
|
|
26761
|
-
const temporary =
|
|
26884
|
+
const temporary = path6.join(this.dir, entry.executionId + "." + this.lock.nonce + "." + randomBytes4(8).toString("hex") + ".tmp");
|
|
26762
26885
|
const handle = await open3(temporary, constants2.O_CREAT | constants2.O_EXCL | constants2.O_WRONLY, 384);
|
|
26763
26886
|
try {
|
|
26764
26887
|
await handle.writeFile(envelope);
|
|
@@ -26826,13 +26949,20 @@ var NativeJournal = class _NativeJournal {
|
|
|
26826
26949
|
});
|
|
26827
26950
|
}
|
|
26828
26951
|
/** Durably records a JobHost pid before that JobHost receives its request; a failure must stop the launch. */
|
|
26829
|
-
supervisor(id2, pid) {
|
|
26952
|
+
supervisor(id2, pid, containment) {
|
|
26830
26953
|
return this.enqueue(async () => {
|
|
26831
26954
|
const e = this.need(id2);
|
|
26832
26955
|
if (!validPid(pid)) throw failure2("JOURNAL_INPUT_INVALID");
|
|
26833
26956
|
if (e.state !== "running" || !e.supervisors) throw failure2("JOURNAL_STATE_INVALID");
|
|
26834
|
-
if (
|
|
26835
|
-
|
|
26957
|
+
if (containment !== void 0) {
|
|
26958
|
+
const linux = validLinuxContainment(containment), darwin = !linux && validDarwinContainment(containment);
|
|
26959
|
+
if (!linux && !darwin || !e.supervisors.includes(pid) || e.linuxSupervisors?.some((s) => s.pid === pid) || e.darwinSupervisors?.some((s) => s.pid === pid)) throw failure2("JOURNAL_INPUT_INVALID");
|
|
26960
|
+
if (linux) (e.linuxSupervisors ??= []).push({ pid, containment: clone2(containment) });
|
|
26961
|
+
else (e.darwinSupervisors ??= []).push({ pid, containment: clone2(containment) });
|
|
26962
|
+
} else {
|
|
26963
|
+
if (e.supervisors.length >= MAX_SUPERVISORS) throw failure2("JOURNAL_SUPERVISOR_LIMIT");
|
|
26964
|
+
e.supervisors.push(pid);
|
|
26965
|
+
}
|
|
26836
26966
|
e.updatedAt = this.now().toISOString();
|
|
26837
26967
|
await this.persist(e);
|
|
26838
26968
|
});
|
|
@@ -26875,7 +27005,7 @@ var NativeJournal = class _NativeJournal {
|
|
|
26875
27005
|
}
|
|
26876
27006
|
get(id2) {
|
|
26877
27007
|
return this.enqueue(async () => {
|
|
26878
|
-
if (!
|
|
27008
|
+
if (!uuid14.test(id2)) throw failure2("JOURNAL_INPUT_INVALID");
|
|
26879
27009
|
const e = this.entries.get(id2);
|
|
26880
27010
|
return e ? clone2(e) : null;
|
|
26881
27011
|
});
|
|
@@ -26933,11 +27063,13 @@ var NativeJournal = class _NativeJournal {
|
|
|
26933
27063
|
recoverAfterRestart(liveness) {
|
|
26934
27064
|
return this.enqueue(async () => {
|
|
26935
27065
|
let count3 = 0;
|
|
26936
|
-
const
|
|
27066
|
+
const interrupted = [...this.entries.values()].filter((e) => ["accepted", "running"].includes(e.state));
|
|
27067
|
+
const pids = [...new Set(interrupted.flatMap((e) => e.supervisors ?? []))];
|
|
27068
|
+
const linuxSupervisors = interrupted.flatMap((e) => e.linuxSupervisors ?? []), darwinSupervisors = interrupted.flatMap((e) => e.darwinSupervisors ?? []);
|
|
26937
27069
|
let live = /* @__PURE__ */ new Set();
|
|
26938
27070
|
if (pids.length) {
|
|
26939
27071
|
try {
|
|
26940
|
-
live = liveness ? await liveness(pids) : null;
|
|
27072
|
+
live = liveness ? await liveness(pids, linuxSupervisors, darwinSupervisors) : null;
|
|
26941
27073
|
} catch {
|
|
26942
27074
|
live = null;
|
|
26943
27075
|
}
|
|
@@ -27010,7 +27142,7 @@ var NativeJournal = class _NativeJournal {
|
|
|
27010
27142
|
try {
|
|
27011
27143
|
const st = await lstat2(this.lock.path);
|
|
27012
27144
|
if (!st.isFile() || st.isSymbolicLink() || st.size > 1024) throw failure2("JOURNAL_LOCK_LOST");
|
|
27013
|
-
const value = JSON.parse(await
|
|
27145
|
+
const value = JSON.parse(await readFile3(this.lock.path, "utf8"));
|
|
27014
27146
|
if (value.nonce !== this.lock.nonce) throw failure2("JOURNAL_LOCK_LOST");
|
|
27015
27147
|
await this.lock.file.close();
|
|
27016
27148
|
await rm2(this.lock.path);
|
|
@@ -27031,25 +27163,25 @@ import { constants as constants4 } from "node:fs";
|
|
|
27031
27163
|
import { openSync, closeSync } from "node:fs";
|
|
27032
27164
|
import { isatty, ReadStream, WriteStream } from "node:tty";
|
|
27033
27165
|
import { createInterface } from "node:readline/promises";
|
|
27034
|
-
import
|
|
27166
|
+
import path8 from "node:path";
|
|
27035
27167
|
|
|
27036
27168
|
// agent/src/owner-permissions.ts
|
|
27037
27169
|
import { createHash as createHash8 } from "node:crypto";
|
|
27038
27170
|
import { constants as constants3 } from "node:fs";
|
|
27039
27171
|
import { access, lstat as lstat3, realpath as realpath3 } from "node:fs/promises";
|
|
27040
|
-
import
|
|
27041
|
-
var
|
|
27172
|
+
import path7 from "node:path";
|
|
27173
|
+
var uuid15 = external_exports.string().uuid().toLowerCase();
|
|
27042
27174
|
var name = external_exports.string().regex(/^[a-zA-Z0-9_.-]{1,64}$/).toLowerCase();
|
|
27043
27175
|
var changeSchema = external_exports.discriminatedUnion("kind", [
|
|
27044
|
-
external_exports.object({ workspaceGrantId:
|
|
27045
|
-
external_exports.object({ workspaceGrantId:
|
|
27046
|
-
external_exports.object({ workspaceGrantId:
|
|
27176
|
+
external_exports.object({ workspaceGrantId: uuid15, kind: external_exports.literal("write"), enabled: external_exports.boolean() }).strict(),
|
|
27177
|
+
external_exports.object({ workspaceGrantId: uuid15, kind: external_exports.literal("localhost"), enabled: external_exports.boolean(), port: external_exports.number().int().min(1).max(65535) }).strict(),
|
|
27178
|
+
external_exports.object({ workspaceGrantId: uuid15, kind: external_exports.literal("command"), enabled: external_exports.boolean(), name, executable: external_exports.string().min(1).max(4096).optional() }).strict()
|
|
27047
27179
|
]);
|
|
27048
27180
|
var PERMISSION_HISTORY_LIMIT = 64;
|
|
27049
27181
|
var PermissionHistorySchema = external_exports.array(external_exports.object({
|
|
27050
|
-
id:
|
|
27182
|
+
id: uuid15,
|
|
27051
27183
|
changedAt: external_exports.string().datetime(),
|
|
27052
|
-
workspaceGrantId:
|
|
27184
|
+
workspaceGrantId: uuid15,
|
|
27053
27185
|
kind: external_exports.enum(["write", "command", "localhost"]),
|
|
27054
27186
|
enabled: external_exports.boolean(),
|
|
27055
27187
|
resourceHash: external_exports.string().regex(/^[a-f0-9]{64}$/),
|
|
@@ -27111,10 +27243,10 @@ async function planPermissionChange(current2, programs, input2) {
|
|
|
27111
27243
|
let executableIdentity = null;
|
|
27112
27244
|
if (change.enabled) {
|
|
27113
27245
|
const executable = change.executable;
|
|
27114
|
-
if (!
|
|
27246
|
+
if (!path7.isAbsolute(executable) || process.platform === "win32" && path7.extname(executable).toLowerCase() !== ".exe" || /[\u0000-\u001f\u007f-\u009f\u061c\u200b-\u200f\u2028-\u202e\u2060-\u2069\ufeff]/u.test(executable)) invalid2();
|
|
27115
27247
|
const stat2 = await lstat3(executable).catch(() => invalid2());
|
|
27116
27248
|
const canonical2 = await realpath3(executable).catch(() => invalid2());
|
|
27117
|
-
if (!stat2.isFile() || stat2.isSymbolicLink() || !equalPath(
|
|
27249
|
+
if (!stat2.isFile() || stat2.isSymbolicLink() || !equalPath(path7.resolve(executable), canonical2)) invalid2();
|
|
27118
27250
|
if (process.platform !== "win32") await access(canonical2, constants3.X_OK).catch(() => invalid2());
|
|
27119
27251
|
if (Object.hasOwn(nextPrograms, change.name) && !equalPath(nextPrograms[change.name], canonical2)) invalid2("COMMAND_CONFLICT");
|
|
27120
27252
|
nextPrograms[change.name] = canonical2;
|
|
@@ -27192,17 +27324,17 @@ async function choosePosixFolder() {
|
|
|
27192
27324
|
return terminal2(async (ask) => {
|
|
27193
27325
|
const folder = await ask("Local Commander: enter the absolute folder to allow reading and writing files (empty cancels): ");
|
|
27194
27326
|
if (!folder) return null;
|
|
27195
|
-
if (!
|
|
27327
|
+
if (!path8.isAbsolute(folder) || folder.length > 4096 || /[\u0000-\u001f]/.test(folder)) throw Error("WORKSPACE_INVALID");
|
|
27196
27328
|
return await ask("Read/write folder: " + permissionLabel(folder) + "\nType APPROVE to accept: ") === "APPROVE" ? folder : null;
|
|
27197
27329
|
}, 12e4);
|
|
27198
27330
|
}
|
|
27199
27331
|
async function choosePosixAccess() {
|
|
27200
27332
|
return terminal2(async (ask) => {
|
|
27201
|
-
if (process.platform === "darwin") await ask("This experimental macOS runtime
|
|
27333
|
+
if (process.platform === "darwin") await ask("This experimental macOS runtime runs each command as its own launchd job and stops that job's processes when the command ends; work handed to other services is not stopped. Press Enter to review access: ");
|
|
27202
27334
|
const choice = await ask("Local Commander access\n1. One folder: read and write files\n2. Full Access: account capabilities across this computer, including commands and localhost\nEnter 1 or 2 (empty cancels): ");
|
|
27203
27335
|
if (choice !== "1" && choice !== "2") return null;
|
|
27204
27336
|
const folder = choice === "2" ? "/" : await ask("Absolute folder path: ");
|
|
27205
|
-
if (!
|
|
27337
|
+
if (!path8.isAbsolute(folder) || folder.length > 4096 || /[\u0000-\u001f]/.test(folder)) throw Error("WORKSPACE_INVALID");
|
|
27206
27338
|
const summary = choice === "2" ? "Full Access allows programs to use your account's capabilities across this computer. This is not an OS sandbox." : "Allow reading and writing files in " + permissionLabel(folder) + ".";
|
|
27207
27339
|
if (await ask(summary + "\nThis replaces the previous folder/command/localhost selection and persists until revoked.\nType APPROVE to accept: ") !== "APPROVE") return null;
|
|
27208
27340
|
return { mode: choice === "2" ? "all-drives" : "folders", paths: [folder] };
|
|
@@ -27210,14 +27342,14 @@ async function choosePosixAccess() {
|
|
|
27210
27342
|
}
|
|
27211
27343
|
|
|
27212
27344
|
// agent/src/private-store.ts
|
|
27213
|
-
import { lstat as lstat4, open as open4, readFile as
|
|
27214
|
-
import
|
|
27345
|
+
import { lstat as lstat4, open as open4, readFile as readFile4, readdir as readdir3, realpath as realpath4, rename as rename2, rm as rm3, writeFile as writeFile2 } from "node:fs/promises";
|
|
27346
|
+
import path10 from "node:path";
|
|
27215
27347
|
import os2 from "node:os";
|
|
27216
27348
|
import { createHash as createHash12, createPrivateKey as createPrivateKey2, createPublicKey as createPublicKey4, generateKeyPairSync, randomBytes as randomBytes5, randomUUID as randomUUID6 } from "node:crypto";
|
|
27217
27349
|
import { spawn as spawn3 } from "node:child_process";
|
|
27218
27350
|
|
|
27219
27351
|
// agent/src/access-selection.ts
|
|
27220
|
-
import
|
|
27352
|
+
import path9 from "node:path";
|
|
27221
27353
|
function parseAccessSelection(value, platform = process.platform) {
|
|
27222
27354
|
const fail7 = () => {
|
|
27223
27355
|
throw Error("ACCESS_SELECTION_INVALID");
|
|
@@ -27231,7 +27363,7 @@ function parseAccessSelection(value, platform = process.platform) {
|
|
|
27231
27363
|
}
|
|
27232
27364
|
if (input2.mode !== "folders" && input2.mode !== "all-drives") return fail7();
|
|
27233
27365
|
if (input2.paths.length < 1 || input2.paths.length > (input2.mode === "folders" ? 1 : 26)) return fail7();
|
|
27234
|
-
const paths = platform === "win32" ?
|
|
27366
|
+
const paths = platform === "win32" ? path9.win32 : path9.posix;
|
|
27235
27367
|
const key = (value2) => platform === "win32" ? paths.normalize(value2).toLowerCase() : paths.normalize(value2);
|
|
27236
27368
|
const roots = [];
|
|
27237
27369
|
for (const candidate of input2.paths) {
|
|
@@ -27250,7 +27382,7 @@ import { createHash as createHash10, KeyObject as KeyObject2 } from "node:crypto
|
|
|
27250
27382
|
// packages/policy/src/evaluator.ts
|
|
27251
27383
|
import { createHash as createHash9 } from "node:crypto";
|
|
27252
27384
|
import { isDeepStrictEqual } from "node:util";
|
|
27253
|
-
var
|
|
27385
|
+
var uuid16 = external_exports.string().uuid().toLowerCase();
|
|
27254
27386
|
var slug2 = external_exports.string().regex(/^[a-z][a-z0-9._-]{0,63}$/);
|
|
27255
27387
|
var utc = external_exports.iso.datetime({ offset: false });
|
|
27256
27388
|
var risk = external_exports.enum(["low", "moderate", "high", "critical"]);
|
|
@@ -27275,7 +27407,7 @@ var PolicyRuleSchema = external_exports.object({
|
|
|
27275
27407
|
}
|
|
27276
27408
|
});
|
|
27277
27409
|
var PolicySnapshotSchema = external_exports.object({
|
|
27278
|
-
tenantId:
|
|
27410
|
+
tenantId: uuid16,
|
|
27279
27411
|
policyId: slug2,
|
|
27280
27412
|
policyVersion: external_exports.string().trim().min(1).max(64),
|
|
27281
27413
|
issuedAt: utc,
|
|
@@ -27389,14 +27521,14 @@ async function verifySignedPolicyBundle(candidate, authority, checkpointInput, n
|
|
|
27389
27521
|
|
|
27390
27522
|
// packages/policy/src/approvals.ts
|
|
27391
27523
|
import { createHash as createHash11, randomUUID as randomUUID5 } from "node:crypto";
|
|
27392
|
-
var
|
|
27524
|
+
var uuid17 = TrustedActionBindingSchema.shape.tenantId;
|
|
27393
27525
|
var utc3 = TrustedActionBindingSchema.shape.expiresAt;
|
|
27394
27526
|
var digest3 = ResourceRefSchema.shape.locatorFingerprint;
|
|
27395
27527
|
var requirement = PolicyDecisionSchema.shape.approval.unwrap();
|
|
27396
27528
|
var ApprovalActionSchema = external_exports.object({ request: BoundActionRequestSchema, payloadHash: digest3 }).strict();
|
|
27397
27529
|
var ApprovalAuthoritySchema = external_exports.object({
|
|
27398
|
-
tenantId:
|
|
27399
|
-
accountId:
|
|
27530
|
+
tenantId: uuid17,
|
|
27531
|
+
accountId: uuid17,
|
|
27400
27532
|
approvalClass: requirement.shape.approvalClass,
|
|
27401
27533
|
authenticatedAt: utc3,
|
|
27402
27534
|
expiresAt: utc3
|
|
@@ -27408,11 +27540,11 @@ var ContextSchema = external_exports.object({
|
|
|
27408
27540
|
policyExpiresAt: utc3
|
|
27409
27541
|
}).strict();
|
|
27410
27542
|
var GrantSchema = external_exports.object({
|
|
27411
|
-
approvalId:
|
|
27412
|
-
requestId:
|
|
27413
|
-
decisionId:
|
|
27543
|
+
approvalId: uuid17,
|
|
27544
|
+
requestId: uuid17,
|
|
27545
|
+
decisionId: uuid17,
|
|
27414
27546
|
bindingHash: digest3,
|
|
27415
|
-
approverAccountId:
|
|
27547
|
+
approverAccountId: uuid17,
|
|
27416
27548
|
approvalClass: requirement.shape.approvalClass,
|
|
27417
27549
|
scope: requirement.shape.scope,
|
|
27418
27550
|
issuedAt: utc3,
|
|
@@ -27421,8 +27553,8 @@ var GrantSchema = external_exports.object({
|
|
|
27421
27553
|
uses: external_exports.number().int().min(0).max(Number.MAX_SAFE_INTEGER)
|
|
27422
27554
|
}).strict().refine((value) => Date.parse(value.issuedAt) < Date.parse(value.expiresAt) && (value.scope === "once" ? value.uses === (value.state === "consumed" ? 1 : 0) : value.state !== "consumed"));
|
|
27423
27555
|
var ApprovalLedgerSchema = external_exports.object({
|
|
27424
|
-
tenantId:
|
|
27425
|
-
deviceId:
|
|
27556
|
+
tenantId: uuid17,
|
|
27557
|
+
deviceId: uuid17,
|
|
27426
27558
|
lastChangedAt: utc3,
|
|
27427
27559
|
grants: external_exports.array(GrantSchema).max(128)
|
|
27428
27560
|
}).strict().refine((value) => new Set(value.grants.map((grant) => grant.approvalId)).size === value.grants.length && new Set(value.grants.map((grant) => grant.requestId)).size === value.grants.length && value.grants.every((grant) => Date.parse(grant.issuedAt) <= Date.parse(value.lastChangedAt)));
|
|
@@ -27499,7 +27631,7 @@ function issueApproval(ledgerInput, context, authorityInput, now, expiresAt) {
|
|
|
27499
27631
|
}
|
|
27500
27632
|
function consumeApproval(ledgerInput, context, approvalId, now) {
|
|
27501
27633
|
try {
|
|
27502
|
-
const ledger = current(ledgerInput, now), bound = binding(ledger, context, now), id2 =
|
|
27634
|
+
const ledger = current(ledgerInput, now), bound = binding(ledger, context, now), id2 = uuid17.parse(approvalId);
|
|
27503
27635
|
const grant = ledger.grants.find((candidate) => candidate.approvalId === id2);
|
|
27504
27636
|
if (!grant || grant.state !== "active" || grant.bindingHash !== bound.bindingHash || grant.uses === Number.MAX_SAFE_INTEGER || Date.parse(now) < Date.parse(grant.issuedAt) || grant.scope === "once" && (grant.requestId !== bound.request.requestId || grant.decisionId !== bound.decision.decisionId)) throw Error();
|
|
27505
27637
|
const consumed = { ...grant, uses: grant.uses + 1, state: grant.scope === "once" ? "consumed" : "active" };
|
|
@@ -27510,7 +27642,7 @@ function consumeApproval(ledgerInput, context, approvalId, now) {
|
|
|
27510
27642
|
}
|
|
27511
27643
|
function revokeApproval(ledgerInput, approvalId, now) {
|
|
27512
27644
|
try {
|
|
27513
|
-
const ledger = current(ledgerInput, now), id2 =
|
|
27645
|
+
const ledger = current(ledgerInput, now), id2 = uuid17.parse(approvalId);
|
|
27514
27646
|
return { ...ledger, grants: ledger.grants.map((grant) => grant.approvalId === id2 && grant.state === "active" ? { ...grant, state: "revoked" } : grant) };
|
|
27515
27647
|
} catch {
|
|
27516
27648
|
throw Error("APPROVAL_INVALID");
|
|
@@ -27526,11 +27658,11 @@ function fail2(code) {
|
|
|
27526
27658
|
return Object.assign(new Error(code), { code });
|
|
27527
27659
|
}
|
|
27528
27660
|
function equalPath2(a, b) {
|
|
27529
|
-
return process.platform === "win32" ?
|
|
27661
|
+
return process.platform === "win32" ? path10.resolve(a).toLowerCase() === path10.resolve(b).toLowerCase() : path10.resolve(a) === path10.resolve(b);
|
|
27530
27662
|
}
|
|
27531
27663
|
function under(child, parent) {
|
|
27532
|
-
const rel =
|
|
27533
|
-
return rel !== "" && !rel.startsWith("..") && !
|
|
27664
|
+
const rel = path10.relative(parent, child);
|
|
27665
|
+
return rel !== "" && !rel.startsWith("..") && !path10.isAbsolute(rel);
|
|
27534
27666
|
}
|
|
27535
27667
|
function canonicalPublicKey(value) {
|
|
27536
27668
|
try {
|
|
@@ -27613,8 +27745,8 @@ function validateState(value) {
|
|
|
27613
27745
|
const programs = value.programs ?? {};
|
|
27614
27746
|
const pendingWorkspaceRevokes = value.pendingWorkspaceRevokes ?? [];
|
|
27615
27747
|
if (!Array.isArray(pendingWorkspaceRevokes) || pendingWorkspaceRevokes.length > 32 || pendingWorkspaceRevokes.some((id2) => typeof id2 !== "string" || !UUID.test(id2) || id2 !== id2.toLowerCase()) || new Set(pendingWorkspaceRevokes).size !== pendingWorkspaceRevokes.length) throw fail2("STATE_CORRUPT");
|
|
27616
|
-
if (!programs || typeof programs !== "object" || Array.isArray(programs) || Object.keys(programs).length > 32 || Object.entries(programs).some(([name2, executable]) => !/^[a-z0-9_.-]{1,64}$/.test(name2) || typeof executable !== "string" || !
|
|
27617
|
-
if (!Array.isArray(workspaces) || workspaces.length > 32 || workspaces.some((w) => !w || !UUID.test(w.workspaceGrantId) || typeof w.root !== "string" || !
|
|
27748
|
+
if (!programs || typeof programs !== "object" || Array.isArray(programs) || Object.keys(programs).length > 32 || Object.entries(programs).some(([name2, executable]) => !/^[a-z0-9_.-]{1,64}$/.test(name2) || typeof executable !== "string" || !path10.isAbsolute(executable) || executable.length > 4096 || /[\u0000-\u001f]/.test(executable))) throw fail2("STATE_CORRUPT");
|
|
27749
|
+
if (!Array.isArray(workspaces) || workspaces.length > 32 || workspaces.some((w) => !w || !UUID.test(w.workspaceGrantId) || typeof w.root !== "string" || !path10.isAbsolute(w.root) || w.root.length > 4096 || /[\u0000-\u001f]/.test(w.root) || !/^[a-f0-9]{64}$/.test(w.rootHash) || typeof w.displayName !== "string" || !w.displayName || w.displayName.length > 120 || w.policyVersion !== 1 || !w.permissions || w.permissions.readFiles !== true || typeof w.permissions.writeFiles !== "boolean" || typeof w.permissions.executeCommands !== "boolean" || typeof w.permissions.localhost !== "boolean" || !Array.isArray(w.allowedCommands) || w.allowedCommands.length > 32 || w.allowedCommands.some((name2) => typeof name2 !== "string" || !Object.hasOwn(programs, name2)) || new Set(w.allowedCommands).size !== w.allowedCommands.length || w.permissions.executeCommands !== (w.fullAccess === true || w.allowedCommands.length > 0) || !Array.isArray(w.localhostPorts) || w.localhostPorts.length > 32 || w.localhostPorts.some((port) => !Number.isInteger(port) || port < 1 || port > 65535) || new Set(w.localhostPorts).size !== w.localhostPorts.length || w.permissions.localhost !== (w.fullAccess === true || w.localhostPorts.length > 0))) throw fail2("STATE_CORRUPT");
|
|
27618
27750
|
const audit = value.audit === void 0 ? void 0 : validateAudit(value.audit);
|
|
27619
27751
|
if (new Set(workspaces.map((w) => w.workspaceGrantId)).size !== workspaces.length || new Set(workspaces.map((w) => w.rootHash)).size !== workspaces.length) throw fail2("STATE_CORRUPT");
|
|
27620
27752
|
if (workspaces.some((w) => pendingWorkspaceRevokes.includes(w.workspaceGrantId))) throw fail2("STATE_CORRUPT");
|
|
@@ -27624,9 +27756,9 @@ function validateState(value) {
|
|
|
27624
27756
|
return { version: 1, publicKeyPem: value.publicKeyPem, privateKeyPem: value.privateKeyPem, fingerprint: value.fingerprint, dataKey: value.dataKey, ...enrollment ? { enrollment } : {}, workspaces, programs, pendingWorkspaceRevokes, ...value.permissionHistory ? { permissionHistory: permissionHistory.data } : {}, ...policyBundle ? { policyBundle } : {}, ...approvals?.success ? { approvals: approvals.data } : {}, ...value.guardRequired ? { guardRequired: true } : {}, ...guard ? { guard } : {}, ...audit ? { audit } : {} };
|
|
27625
27757
|
}
|
|
27626
27758
|
async function noSymlinkChain(target) {
|
|
27627
|
-
if (!
|
|
27628
|
-
const absolute2 =
|
|
27629
|
-
if (absolute2 ===
|
|
27759
|
+
if (!path10.isAbsolute(target)) throw fail2("STORE_DIRECTORY_INVALID");
|
|
27760
|
+
const absolute2 = path10.resolve(target);
|
|
27761
|
+
if (absolute2 === path10.parse(absolute2).root) throw fail2("STORE_DIRECTORY_INVALID");
|
|
27630
27762
|
const missing = [];
|
|
27631
27763
|
let cursor = absolute2;
|
|
27632
27764
|
for (; ; ) {
|
|
@@ -27637,7 +27769,7 @@ async function noSymlinkChain(target) {
|
|
|
27637
27769
|
} catch (error62) {
|
|
27638
27770
|
if (error62.code !== "ENOENT") throw error62;
|
|
27639
27771
|
missing.push(cursor);
|
|
27640
|
-
const parent =
|
|
27772
|
+
const parent = path10.dirname(cursor);
|
|
27641
27773
|
if (parent === cursor) throw fail2("STORE_DIRECTORY_INVALID");
|
|
27642
27774
|
cursor = parent;
|
|
27643
27775
|
}
|
|
@@ -27647,15 +27779,15 @@ async function noSymlinkChain(target) {
|
|
|
27647
27779
|
return absolute2;
|
|
27648
27780
|
}
|
|
27649
27781
|
function allowedDirectory(absolute2) {
|
|
27650
|
-
const localAppData = process.env.LOCALAPPDATA ||
|
|
27651
|
-
const appRoot =
|
|
27652
|
-
const tempRoot =
|
|
27782
|
+
const localAppData = process.env.LOCALAPPDATA || path10.join(os2.homedir(), "AppData", "Local");
|
|
27783
|
+
const appRoot = path10.resolve(localAppData, "LocalCommander");
|
|
27784
|
+
const tempRoot = path10.resolve(os2.tmpdir());
|
|
27653
27785
|
if (under(absolute2, appRoot)) return;
|
|
27654
|
-
if (under(absolute2, tempRoot) && /^lc-private-[A-Za-z0-9_.-]+$/i.test(
|
|
27786
|
+
if (under(absolute2, tempRoot) && /^lc-private-[A-Za-z0-9_.-]+$/i.test(path10.basename(absolute2))) return;
|
|
27655
27787
|
throw fail2("STORE_DIRECTORY_POLICY");
|
|
27656
27788
|
}
|
|
27657
27789
|
async function canonicalBridge(value) {
|
|
27658
|
-
if (typeof value !== "string" || !
|
|
27790
|
+
if (typeof value !== "string" || !path10.isAbsolute(value) || path10.extname(value).toLowerCase() !== ".exe") throw fail2("BRIDGE_INVALID");
|
|
27659
27791
|
const stat2 = await lstat4(value).catch(() => {
|
|
27660
27792
|
throw fail2("BRIDGE_INVALID");
|
|
27661
27793
|
});
|
|
@@ -27699,28 +27831,28 @@ var WindowsPrivateStore = class _WindowsPrivateStore {
|
|
|
27699
27831
|
const memoryFile = (name2) => name2 === "host-memory.json" || /^host-memory\.json\.[1-9][0-9]{0,9}\.tmp$/.test(name2);
|
|
27700
27832
|
if (names.some((name2) => !approved.has(name2) && !memoryFile(name2))) throw fail2("STORE_DIRECTORY_UNKNOWN");
|
|
27701
27833
|
for (const name2 of names.filter(memoryFile)) {
|
|
27702
|
-
const stat2 = await lstat4(
|
|
27834
|
+
const stat2 = await lstat4(path10.join(absolute2, name2));
|
|
27703
27835
|
if (!stat2.isFile() || stat2.isSymbolicLink() || stat2.size > 32768) throw fail2("STORE_DIRECTORY_INVALID");
|
|
27704
27836
|
}
|
|
27705
27837
|
for (const name2 of ["agent-process.json", "optimization", ".local-commander"]) {
|
|
27706
27838
|
if (!names.includes(name2)) continue;
|
|
27707
|
-
const filename =
|
|
27839
|
+
const filename = path10.join(absolute2, name2), stat2 = await lstat4(filename);
|
|
27708
27840
|
if (stat2.isSymbolicLink() || (name2 !== "agent-process.json" ? !stat2.isDirectory() : !stat2.isFile() || stat2.size < 1 || stat2.size > 8192)) throw fail2("STORE_DIRECTORY_INVALID");
|
|
27709
27841
|
if (name2 === "agent-process.json") {
|
|
27710
27842
|
let value;
|
|
27711
27843
|
try {
|
|
27712
|
-
value = JSON.parse(await
|
|
27844
|
+
value = JSON.parse(await readFile4(filename, "utf8"));
|
|
27713
27845
|
} catch {
|
|
27714
27846
|
throw fail2("STORE_DIRECTORY_INVALID");
|
|
27715
27847
|
}
|
|
27716
|
-
if (!value || !Number.isSafeInteger(value.pid) || value.pid <= 0 || typeof value.runtimeDir !== "string" || !
|
|
27848
|
+
if (!value || !Number.isSafeInteger(value.pid) || value.pid <= 0 || typeof value.runtimeDir !== "string" || !path10.isAbsolute(value.runtimeDir) || value.runtimeDir.length > 4096 || /[\u0000-\u001f]/.test(value.runtimeDir) || typeof value.version !== "string" || !/^[0-9]+\.[0-9]+\.[0-9]+(?:[-+][A-Za-z0-9.-]+)?$/.test(value.version) || typeof value.startedAt !== "string" || !Number.isFinite(Date.parse(value.startedAt))) throw fail2("STORE_DIRECTORY_INVALID");
|
|
27717
27849
|
}
|
|
27718
27850
|
}
|
|
27719
27851
|
const posix = process.platform !== "win32" ? await PosixProtection.open(absolute2, bridge) : void 0;
|
|
27720
27852
|
if (!posix) await _WindowsPrivateStore.invoke(bridge, "init-directory", { path: absolute2 }, 5e3, false);
|
|
27721
27853
|
const canonical2 = await realpath4(absolute2);
|
|
27722
27854
|
if (!equalPath2(absolute2, canonical2) || (await lstat4(canonical2)).isSymbolicLink()) throw fail2("STORE_DIRECTORY_INVALID");
|
|
27723
|
-
const markerPath =
|
|
27855
|
+
const markerPath = path10.join(canonical2, MARKER);
|
|
27724
27856
|
try {
|
|
27725
27857
|
await writeFile2(markerPath, "LocalCommander private state\n", { flag: "wx", mode: 384 });
|
|
27726
27858
|
} catch (error62) {
|
|
@@ -27738,10 +27870,10 @@ var WindowsPrivateStore = class _WindowsPrivateStore {
|
|
|
27738
27870
|
return result2;
|
|
27739
27871
|
}
|
|
27740
27872
|
statePath() {
|
|
27741
|
-
return
|
|
27873
|
+
return path10.join(this.dir, "owner-state.dat");
|
|
27742
27874
|
}
|
|
27743
27875
|
lockPath() {
|
|
27744
|
-
return
|
|
27876
|
+
return path10.join(this.dir, "owner-state.lock");
|
|
27745
27877
|
}
|
|
27746
27878
|
static invoke(bridge, arg, body, timeoutMs2, interactive, signal) {
|
|
27747
27879
|
return new Promise((resolve, reject) => {
|
|
@@ -27832,7 +27964,7 @@ var WindowsPrivateStore = class _WindowsPrivateStore {
|
|
|
27832
27964
|
await handle.close().catch(() => {
|
|
27833
27965
|
});
|
|
27834
27966
|
try {
|
|
27835
|
-
const current2 = await
|
|
27967
|
+
const current2 = await readFile4(this.lockPath(), "utf8");
|
|
27836
27968
|
if (current2 === nonce2) await rm3(this.lockPath());
|
|
27837
27969
|
} catch {
|
|
27838
27970
|
}
|
|
@@ -27854,7 +27986,7 @@ var WindowsPrivateStore = class _WindowsPrivateStore {
|
|
|
27854
27986
|
try {
|
|
27855
27987
|
const stat2 = await lstat4(this.statePath());
|
|
27856
27988
|
if (!stat2.isFile() || stat2.isSymbolicLink() || stat2.size < 1 || stat2.size > MAX_STATE_BYTES * 4) throw fail2("STATE_CORRUPT");
|
|
27857
|
-
const encrypted = this.posix ? await privateRead(this.statePath(), MAX_STATE_BYTES * 4) : await
|
|
27989
|
+
const encrypted = this.posix ? await privateRead(this.statePath(), MAX_STATE_BYTES * 4) : await readFile4(this.statePath());
|
|
27858
27990
|
const plaintext = await this.unprotect(encrypted);
|
|
27859
27991
|
if (plaintext.length > MAX_STATE_BYTES) throw fail2("STATE_CORRUPT");
|
|
27860
27992
|
return validateState(JSON.parse(plaintext.toString("utf8")));
|
|
@@ -27868,7 +28000,7 @@ var WindowsPrivateStore = class _WindowsPrivateStore {
|
|
|
27868
28000
|
try {
|
|
27869
28001
|
const stat2 = await lstat4(this.statePath());
|
|
27870
28002
|
if (!stat2.isFile() || stat2.isSymbolicLink() || stat2.size > MAX_STATE_BYTES * 4) throw fail2("STATE_CORRUPT");
|
|
27871
|
-
return createHash12("sha256").update(this.posix ? await privateRead(this.statePath(), MAX_STATE_BYTES * 4) : await
|
|
28003
|
+
return createHash12("sha256").update(this.posix ? await privateRead(this.statePath(), MAX_STATE_BYTES * 4) : await readFile4(this.statePath())).digest("hex");
|
|
27872
28004
|
} catch (error62) {
|
|
27873
28005
|
if (error62.code === "ENOENT") return null;
|
|
27874
28006
|
throw error62;
|
|
@@ -27879,7 +28011,7 @@ var WindowsPrivateStore = class _WindowsPrivateStore {
|
|
|
27879
28011
|
const plaintext = Buffer.from(JSON.stringify(validateState(state)), "utf8");
|
|
27880
28012
|
if (plaintext.length > MAX_STATE_BYTES) throw fail2("STATE_TOO_LARGE");
|
|
27881
28013
|
const encrypted = await this.protect(plaintext);
|
|
27882
|
-
const temp =
|
|
28014
|
+
const temp = path10.join(this.dir, "owner-state." + randomBytes5(8).toString("hex") + ".tmp");
|
|
27883
28015
|
const handle = await open4(temp, constants4.O_CREAT | constants4.O_EXCL | constants4.O_WRONLY, 384);
|
|
27884
28016
|
let closed = false;
|
|
27885
28017
|
try {
|
|
@@ -28251,7 +28383,7 @@ var WindowsPrivateStore = class _WindowsPrivateStore {
|
|
|
28251
28383
|
const stat2 = await lstat4(chosen);
|
|
28252
28384
|
if (!stat2.isDirectory() || stat2.isSymbolicLink()) throw fail2("WORKSPACE_INVALID");
|
|
28253
28385
|
const root = await realpath4(chosen);
|
|
28254
|
-
const isDrive = equalPath2(root,
|
|
28386
|
+
const isDrive = equalPath2(root, path10.parse(root).root);
|
|
28255
28387
|
if (!equalPath2(root, chosen) || (selected.mode === "all-drives" ? !isDrive : isDrive) || equalPath2(root, this.dir) || under(root, this.dir) || selected.mode === "folders" && under(this.dir, root)) throw fail2("WORKSPACE_INVALID");
|
|
28256
28388
|
roots.push(root);
|
|
28257
28389
|
}
|
|
@@ -28266,7 +28398,7 @@ var WindowsPrivateStore = class _WindowsPrivateStore {
|
|
|
28266
28398
|
workspaceGrantId: existing?.workspaceGrantId ?? randomUUID6(),
|
|
28267
28399
|
root,
|
|
28268
28400
|
rootHash,
|
|
28269
|
-
displayName: (
|
|
28401
|
+
displayName: (path10.basename(root) || root).slice(0, 120),
|
|
28270
28402
|
policyVersion: 1,
|
|
28271
28403
|
...selected.mode === "all-drives" ? { fullAccess: true } : {},
|
|
28272
28404
|
permissions: { readFiles: true, writeFiles: true, executeCommands: selected.mode === "all-drives", localhost: selected.mode === "all-drives" },
|
|
@@ -28298,7 +28430,7 @@ var WindowsPrivateStore = class _WindowsPrivateStore {
|
|
|
28298
28430
|
const stat2 = await lstat4(chosen);
|
|
28299
28431
|
if (!stat2.isDirectory() || stat2.isSymbolicLink()) throw fail2("WORKSPACE_INVALID");
|
|
28300
28432
|
const root = await realpath4(chosen);
|
|
28301
|
-
if (!equalPath2(root, chosen) || equalPath2(root,
|
|
28433
|
+
if (!equalPath2(root, chosen) || equalPath2(root, path10.parse(root).root) || equalPath2(root, this.dir) || under(this.dir, root)) throw fail2("WORKSPACE_INVALID");
|
|
28302
28434
|
const rootHash = createHash12("sha256").update(process.platform === "win32" ? root.toLowerCase() : root).digest("hex");
|
|
28303
28435
|
return this.run(() => this.withLock(async () => {
|
|
28304
28436
|
const state = await this.readState();
|
|
@@ -28307,7 +28439,7 @@ var WindowsPrivateStore = class _WindowsPrivateStore {
|
|
|
28307
28439
|
if (existing) return existing;
|
|
28308
28440
|
if ((state.workspaces?.length ?? 0) >= 32) throw fail2("WORKSPACE_LIMIT");
|
|
28309
28441
|
const before = await this.rawHash();
|
|
28310
|
-
const workspace2 = { workspaceGrantId: randomUUID6(), root, rootHash, displayName:
|
|
28442
|
+
const workspace2 = { workspaceGrantId: randomUUID6(), root, rootHash, displayName: path10.basename(root).slice(0, 120), policyVersion: 1, permissions: { readFiles: true, writeFiles: true, executeCommands: false, localhost: false }, allowedCommands: [], localhostPorts: [] };
|
|
28311
28443
|
state.workspaces = [...state.workspaces ?? [], workspace2];
|
|
28312
28444
|
await this.writeState(state, before);
|
|
28313
28445
|
return workspace2;
|
|
@@ -28318,7 +28450,7 @@ var WindowsPrivateStore = class _WindowsPrivateStore {
|
|
|
28318
28450
|
return this.run(async () => {
|
|
28319
28451
|
const result2 = await _WindowsPrivateStore.invoke(this.bridge, "choose-folder", {}, 12e4, true);
|
|
28320
28452
|
if (result2.path === null) return null;
|
|
28321
|
-
if (typeof result2.path !== "string" || !
|
|
28453
|
+
if (typeof result2.path !== "string" || !path10.isAbsolute(result2.path) || result2.path.length > 4096 || /[\u0000-\u001f]/.test(result2.path)) throw fail2("BRIDGE_OUTPUT_INVALID");
|
|
28322
28454
|
return result2.path;
|
|
28323
28455
|
});
|
|
28324
28456
|
}
|
|
@@ -28326,10 +28458,10 @@ var WindowsPrivateStore = class _WindowsPrivateStore {
|
|
|
28326
28458
|
|
|
28327
28459
|
// src/host-memory.ts
|
|
28328
28460
|
import os3 from "node:os";
|
|
28329
|
-
import
|
|
28461
|
+
import path12 from "node:path";
|
|
28330
28462
|
import { createHash as createHash13 } from "node:crypto";
|
|
28331
28463
|
import { accessSync, constants as constants5, statSync as statSync2 } from "node:fs";
|
|
28332
|
-
import { lstat as lstat5, readFile as
|
|
28464
|
+
import { lstat as lstat5, readFile as readFile5, mkdir as mkdir5, open as open5, rename as rename3, rm as rm4 } from "node:fs/promises";
|
|
28333
28465
|
|
|
28334
28466
|
// packages/agent-cli/bin/monitor-context.mjs
|
|
28335
28467
|
var AGENT_NAMES = Object.freeze([
|
|
@@ -28513,7 +28645,7 @@ function commandPreview(tool, meta3 = {}) {
|
|
|
28513
28645
|
|
|
28514
28646
|
// src/process.ts
|
|
28515
28647
|
import { statSync } from "node:fs";
|
|
28516
|
-
import
|
|
28648
|
+
import path11 from "node:path";
|
|
28517
28649
|
var WINDOWS_LAUNCH_EXTENSIONS = [".com", ".exe", ".bat", ".cmd"];
|
|
28518
28650
|
function envValue(env, name2) {
|
|
28519
28651
|
const key = Object.keys(env).find((k) => k.toUpperCase() === name2.toUpperCase());
|
|
@@ -28523,9 +28655,9 @@ function resolveWindowsLauncher(commandName, env = process.env) {
|
|
|
28523
28655
|
const extensions = (envValue(env, "PATHEXT") || ".COM;.EXE;.BAT;.CMD").split(";").map((ext) => ext.trim().toLowerCase()).filter((ext) => WINDOWS_LAUNCH_EXTENSIONS.includes(ext));
|
|
28524
28656
|
for (const entry of (envValue(env, "PATH") ?? "").split(";")) {
|
|
28525
28657
|
const dir = entry.trim().replace(/^"(.*)"$/, "$1");
|
|
28526
|
-
if (!
|
|
28658
|
+
if (!path11.win32.isAbsolute(dir)) continue;
|
|
28527
28659
|
for (const ext of extensions) {
|
|
28528
|
-
const file2 =
|
|
28660
|
+
const file2 = path11.win32.join(dir, commandName + ext);
|
|
28529
28661
|
try {
|
|
28530
28662
|
if (statSync(file2).isFile()) return { file: file2, shell: ext === ".bat" || ext === ".cmd" };
|
|
28531
28663
|
} catch {
|
|
@@ -28566,7 +28698,7 @@ var HostMemory = class {
|
|
|
28566
28698
|
try {
|
|
28567
28699
|
const stat2 = await lstat5(this.file);
|
|
28568
28700
|
if (!stat2.isFile() || stat2.isSymbolicLink() || stat2.size > 32768) throw Error("HOST_MEMORY_INVALID");
|
|
28569
|
-
const data = State.parse(JSON.parse(await
|
|
28701
|
+
const data = State.parse(JSON.parse(await readFile5(this.file, "utf8")));
|
|
28570
28702
|
if (data.platform === process.platform) this.entries = data.entries.filter((e) => e.at <= Date.now() && Date.now() - e.at < 30 * 864e5);
|
|
28571
28703
|
} catch (error62) {
|
|
28572
28704
|
if (error62.code !== "ENOENT") this.errors++;
|
|
@@ -28580,16 +28712,16 @@ var HostMemory = class {
|
|
|
28580
28712
|
if (this.programs) {
|
|
28581
28713
|
try {
|
|
28582
28714
|
const executable = this.programs[command];
|
|
28583
|
-
available = !!executable &&
|
|
28715
|
+
available = !!executable && path12.isAbsolute(executable) && statSync2(executable).isFile();
|
|
28584
28716
|
} catch {
|
|
28585
28717
|
available = false;
|
|
28586
28718
|
}
|
|
28587
28719
|
}
|
|
28588
28720
|
if (!this.programs && !available && process.platform === "win32") available = !!resolveWindowsLauncher(command);
|
|
28589
|
-
else if (!this.programs && !available) available = (process.env.PATH ?? "").split(
|
|
28590
|
-
if (!
|
|
28721
|
+
else if (!this.programs && !available) available = (process.env.PATH ?? "").split(path12.delimiter).some((dir) => {
|
|
28722
|
+
if (!path12.isAbsolute(dir)) return false;
|
|
28591
28723
|
try {
|
|
28592
|
-
const file2 =
|
|
28724
|
+
const file2 = path12.join(dir, command);
|
|
28593
28725
|
accessSync(file2, constants5.X_OK);
|
|
28594
28726
|
return statSync2(file2).isFile();
|
|
28595
28727
|
} catch {
|
|
@@ -28647,7 +28779,7 @@ var HostMemory = class {
|
|
|
28647
28779
|
this.entries = this.entries.slice(-32);
|
|
28648
28780
|
const encoded = JSON.stringify({ version: 1, platform: process.platform, entries: this.entries }) + "\n";
|
|
28649
28781
|
this.writing = this.writing.then(async () => {
|
|
28650
|
-
const directory2 =
|
|
28782
|
+
const directory2 = path12.dirname(this.file), temp = this.file + "." + process.pid + ".tmp";
|
|
28651
28783
|
await mkdir5(directory2, { recursive: true, mode: 448 });
|
|
28652
28784
|
const stat2 = await lstat5(directory2);
|
|
28653
28785
|
if (!stat2.isDirectory() || stat2.isSymbolicLink()) throw Error("HOST_MEMORY_DIRECTORY_INVALID");
|
|
@@ -28671,12 +28803,12 @@ var HostMemory = class {
|
|
|
28671
28803
|
// agent/src/tools.ts
|
|
28672
28804
|
import { constants as constants7 } from "node:fs";
|
|
28673
28805
|
import { lstat as lstat7, open as open6, readdir as readdir4, realpath as realpath7, rename as rename4, rm as rm5 } from "node:fs/promises";
|
|
28674
|
-
import
|
|
28806
|
+
import path17 from "node:path";
|
|
28675
28807
|
import { createHash as createHash14, randomUUID as randomUUID7 } from "node:crypto";
|
|
28676
28808
|
|
|
28677
28809
|
// src/guard.ts
|
|
28678
28810
|
import { lstat as lstat6, realpath as realpath5 } from "node:fs/promises";
|
|
28679
|
-
import
|
|
28811
|
+
import path13 from "node:path";
|
|
28680
28812
|
var SENSITIVE_NAMES = /* @__PURE__ */ new Set([
|
|
28681
28813
|
".npmrc",
|
|
28682
28814
|
".pypirc",
|
|
@@ -28713,12 +28845,12 @@ function comparePath(value) {
|
|
|
28713
28845
|
return process.platform === "win32" ? value.toLowerCase() : value;
|
|
28714
28846
|
}
|
|
28715
28847
|
function isInside(root, candidate) {
|
|
28716
|
-
const relative =
|
|
28717
|
-
return relative === "" || !
|
|
28848
|
+
const relative = path13.relative(root, candidate);
|
|
28849
|
+
return relative === "" || !path13.isAbsolute(relative) && relative !== ".." && !relative.startsWith(`..${path13.sep}`);
|
|
28718
28850
|
}
|
|
28719
28851
|
function splitPathSegments(filePath) {
|
|
28720
|
-
const parsed =
|
|
28721
|
-
return
|
|
28852
|
+
const parsed = path13.parse(path13.resolve(filePath));
|
|
28853
|
+
return path13.relative(parsed.root, path13.resolve(filePath)).split(path13.sep).filter((segment) => segment.length > 0);
|
|
28722
28854
|
}
|
|
28723
28855
|
function isProtectedAuditFile(base) {
|
|
28724
28856
|
return base === ".local-commander-audit.jsonl" || base.startsWith(".local-commander-audit.jsonl.");
|
|
@@ -28733,24 +28865,24 @@ function looksProtected(filePath) {
|
|
|
28733
28865
|
return false;
|
|
28734
28866
|
}
|
|
28735
28867
|
function looksSensitive(filePath) {
|
|
28736
|
-
const base =
|
|
28868
|
+
const base = path13.basename(filePath).toLowerCase();
|
|
28737
28869
|
if (base === ".env" || base.startsWith(".env.") && base !== ".env.example") return true;
|
|
28738
28870
|
if (SENSITIVE_NAMES.has(base)) return true;
|
|
28739
|
-
if (SENSITIVE_EXTENSIONS.has(
|
|
28871
|
+
if (SENSITIVE_EXTENSIONS.has(path13.extname(base))) return true;
|
|
28740
28872
|
const segments = splitPathSegments(filePath).map((segment) => segment.toLowerCase());
|
|
28741
28873
|
if (segments.slice(0, -1).some((segment) => SENSITIVE_DIRECTORIES.has(segment))) return true;
|
|
28742
28874
|
const parent = segments.at(-2);
|
|
28743
28875
|
return SENSITIVE_IN_DIRECTORY.some(([directory, name2]) => directory === parent && name2 === base);
|
|
28744
28876
|
}
|
|
28745
28877
|
async function canonicalizePossiblyMissing(inputPath, base) {
|
|
28746
|
-
const absolute2 =
|
|
28747
|
-
const parsed =
|
|
28878
|
+
const absolute2 = path13.isAbsolute(inputPath) ? path13.resolve(inputPath) : path13.resolve(base, inputPath);
|
|
28879
|
+
const parsed = path13.parse(absolute2);
|
|
28748
28880
|
let current2 = absolute2;
|
|
28749
28881
|
const missing = [];
|
|
28750
28882
|
while (current2 !== parsed.root) {
|
|
28751
28883
|
try {
|
|
28752
28884
|
const resolved = await realpath5(current2);
|
|
28753
|
-
return
|
|
28885
|
+
return path13.join(resolved, ...missing.reverse());
|
|
28754
28886
|
} catch (error62) {
|
|
28755
28887
|
if (error62.code !== "ENOENT") throw error62;
|
|
28756
28888
|
let exists = false;
|
|
@@ -28761,12 +28893,12 @@ async function canonicalizePossiblyMissing(inputPath, base) {
|
|
|
28761
28893
|
if (statError.code !== "ENOENT") throw statError;
|
|
28762
28894
|
}
|
|
28763
28895
|
if (exists) throw error62;
|
|
28764
|
-
missing.push(
|
|
28765
|
-
current2 =
|
|
28896
|
+
missing.push(path13.basename(current2));
|
|
28897
|
+
current2 = path13.dirname(current2);
|
|
28766
28898
|
}
|
|
28767
28899
|
}
|
|
28768
28900
|
const root = await realpath5(parsed.root);
|
|
28769
|
-
return
|
|
28901
|
+
return path13.join(root, ...missing.reverse());
|
|
28770
28902
|
}
|
|
28771
28903
|
var PathGuard = class _PathGuard {
|
|
28772
28904
|
constructor(roots, allowSensitiveFiles, protectedPaths) {
|
|
@@ -28782,7 +28914,7 @@ var PathGuard = class _PathGuard {
|
|
|
28782
28914
|
for (const root of roots) {
|
|
28783
28915
|
let resolved;
|
|
28784
28916
|
try {
|
|
28785
|
-
resolved = await realpath5(
|
|
28917
|
+
resolved = await realpath5(path13.resolve(root));
|
|
28786
28918
|
} catch {
|
|
28787
28919
|
throw new Error(`Configured root does not exist: ${root}`);
|
|
28788
28920
|
}
|
|
@@ -28795,8 +28927,8 @@ var PathGuard = class _PathGuard {
|
|
|
28795
28927
|
if (canonical2.length === 0) throw new Error("At least one allowed root is required");
|
|
28796
28928
|
const protectedPaths = [];
|
|
28797
28929
|
for (const protectedPath of options.protectedPaths ?? []) {
|
|
28798
|
-
const base =
|
|
28799
|
-
const absolute2 =
|
|
28930
|
+
const base = path13.isAbsolute(protectedPath) ? path13.parse(path13.resolve(protectedPath)).root : canonical2[0];
|
|
28931
|
+
const absolute2 = path13.resolve(base, protectedPath);
|
|
28800
28932
|
if (!protectedPaths.some((existing) => comparePath(existing) === comparePath(absolute2))) protectedPaths.push(absolute2);
|
|
28801
28933
|
const resolved = await canonicalizePossiblyMissing(protectedPath, base);
|
|
28802
28934
|
if (!protectedPaths.some((existing) => comparePath(existing) === comparePath(resolved))) {
|
|
@@ -28812,7 +28944,7 @@ var PathGuard = class _PathGuard {
|
|
|
28812
28944
|
}
|
|
28813
28945
|
assertNotProtected(candidate) {
|
|
28814
28946
|
if (looksProtected(candidate)) {
|
|
28815
|
-
throw new Error(`Local Commander protected state is blocked: ${
|
|
28947
|
+
throw new Error(`Local Commander protected state is blocked: ${path13.basename(candidate)}`);
|
|
28816
28948
|
}
|
|
28817
28949
|
const normalizedCandidate = comparePath(candidate);
|
|
28818
28950
|
for (const protectedPath of this.protectedPaths) {
|
|
@@ -28825,13 +28957,13 @@ var PathGuard = class _PathGuard {
|
|
|
28825
28957
|
this.assertNotProtected(filePath);
|
|
28826
28958
|
if (!this.allowSensitiveFiles && looksSensitive(filePath)) {
|
|
28827
28959
|
throw new Error(
|
|
28828
|
-
`Sensitive file access is blocked by default: ${
|
|
28960
|
+
`Sensitive file access is blocked by default: ${path13.basename(filePath)}. Enable files.allowSensitiveFiles only if you really need it.`
|
|
28829
28961
|
);
|
|
28830
28962
|
}
|
|
28831
28963
|
}
|
|
28832
28964
|
async resolveExisting(inputPath, cwd) {
|
|
28833
28965
|
const base = cwd ? await this.resolveExisting(cwd) : this.roots[0];
|
|
28834
|
-
const candidate =
|
|
28966
|
+
const candidate = path13.isAbsolute(inputPath) ? path13.resolve(inputPath) : path13.resolve(base, inputPath);
|
|
28835
28967
|
this.assertNotProtected(candidate);
|
|
28836
28968
|
const resolved = await realpath5(candidate);
|
|
28837
28969
|
this.assertWithinRoots(resolved);
|
|
@@ -28846,7 +28978,7 @@ var PathGuard = class _PathGuard {
|
|
|
28846
28978
|
}
|
|
28847
28979
|
async resolveForWrite(inputPath, cwd) {
|
|
28848
28980
|
const base = cwd ? await this.resolveDirectory(cwd) : this.roots[0];
|
|
28849
|
-
const candidate =
|
|
28981
|
+
const candidate = path13.isAbsolute(inputPath) ? path13.resolve(inputPath) : path13.resolve(base, inputPath);
|
|
28850
28982
|
this.assertNotProtected(candidate);
|
|
28851
28983
|
let existing;
|
|
28852
28984
|
try {
|
|
@@ -28868,11 +29000,11 @@ var PathGuard = class _PathGuard {
|
|
|
28868
29000
|
this.assertSafeFile(existing);
|
|
28869
29001
|
return existing;
|
|
28870
29002
|
}
|
|
28871
|
-
const parent = await realpath5(
|
|
29003
|
+
const parent = await realpath5(path13.dirname(candidate));
|
|
28872
29004
|
this.assertWithinRoots(parent);
|
|
28873
29005
|
this.assertNotProtected(parent);
|
|
28874
29006
|
this.assertSafeFile(candidate);
|
|
28875
|
-
const target =
|
|
29007
|
+
const target = path13.join(parent, path13.basename(candidate));
|
|
28876
29008
|
this.assertSafeFile(target);
|
|
28877
29009
|
return target;
|
|
28878
29010
|
}
|
|
@@ -28882,8 +29014,8 @@ var PathGuard = class _PathGuard {
|
|
|
28882
29014
|
};
|
|
28883
29015
|
|
|
28884
29016
|
// src/windows-file-read.ts
|
|
28885
|
-
import { execFile } from "node:child_process";
|
|
28886
|
-
import
|
|
29017
|
+
import { execFile as execFile3 } from "node:child_process";
|
|
29018
|
+
import path14 from "node:path";
|
|
28887
29019
|
function readWindowsFile(bridge, file2, maxBytes, signal) {
|
|
28888
29020
|
return invokeRead(bridge, file2, maxBytes, false, signal);
|
|
28889
29021
|
}
|
|
@@ -28899,13 +29031,52 @@ async function readWindowsFilePrefix(bridge, file2, maxBytes, signal) {
|
|
|
28899
29031
|
throw new Error("FILE_READ_FAILED");
|
|
28900
29032
|
}
|
|
28901
29033
|
}
|
|
29034
|
+
function readWindowsFiles(bridge, files, maxBytes, maxTotalBytes, signal) {
|
|
29035
|
+
const input2 = JSON.stringify({ paths: files });
|
|
29036
|
+
if (process.platform !== "win32" || !path14.isAbsolute(bridge) || files.length < 1 || files.length > 64 || files.some((file2) => !path14.isAbsolute(file2)) || Buffer.byteLength(input2) > 3e5 || !Number.isSafeInteger(maxBytes) || maxBytes < 1 || maxBytes > 1048576 || !Number.isSafeInteger(maxTotalBytes) || maxTotalBytes < 1 || maxTotalBytes > 16777216) {
|
|
29037
|
+
return Promise.reject(new Error("FILE_READ_ARGUMENT_INVALID"));
|
|
29038
|
+
}
|
|
29039
|
+
if (signal?.aborted) return Promise.reject(new Error("CANCELLED"));
|
|
29040
|
+
return new Promise((resolve, reject) => {
|
|
29041
|
+
const child = execFile3(bridge, ["read-files", String(maxBytes), String(maxTotalBytes)], {
|
|
29042
|
+
encoding: "buffer",
|
|
29043
|
+
timeout: 3e4,
|
|
29044
|
+
maxBuffer: Math.ceil(maxTotalBytes / 3) * 4 + files.length * 64 + 512,
|
|
29045
|
+
windowsHide: true,
|
|
29046
|
+
shell: false,
|
|
29047
|
+
env: buildChildEnvironment(process.env, "win32"),
|
|
29048
|
+
signal
|
|
29049
|
+
}, (error62, stdout) => {
|
|
29050
|
+
if (error62) return reject(new Error(signal?.aborted ? "CANCELLED" : "FILE_READ_FAILED"));
|
|
29051
|
+
try {
|
|
29052
|
+
const lines = stdout.toString("utf8").split("\n");
|
|
29053
|
+
if (lines.pop() !== "" || lines.length !== files.length) throw Error();
|
|
29054
|
+
let total = 0;
|
|
29055
|
+
resolve(lines.map((line) => {
|
|
29056
|
+
const value = JSON.parse(line);
|
|
29057
|
+
if (!value || Object.keys(value).length !== 1) throw Error();
|
|
29058
|
+
if (/^(ENOENT|FILE_CHANGED|FILE_UNSUPPORTED_OR_TOO_LARGE|PATH_INVALID|ACCESS_DENIED|IO_FAILED)$/.test(value.error)) return { code: value.error };
|
|
29059
|
+
if (typeof value.data !== "string") throw Error();
|
|
29060
|
+
const data = Buffer.from(value.data, "base64");
|
|
29061
|
+
if (data.toString("base64") !== value.data || data.length > maxBytes || (total += data.length) > maxTotalBytes) throw Error();
|
|
29062
|
+
return { data };
|
|
29063
|
+
}));
|
|
29064
|
+
} catch {
|
|
29065
|
+
reject(new Error("FILE_READ_FAILED"));
|
|
29066
|
+
}
|
|
29067
|
+
});
|
|
29068
|
+
child.stdin.on("error", () => {
|
|
29069
|
+
});
|
|
29070
|
+
child.stdin.end(input2);
|
|
29071
|
+
});
|
|
29072
|
+
}
|
|
28902
29073
|
function invokeRead(bridge, file2, maxBytes, prefix, signal) {
|
|
28903
|
-
if (process.platform !== "win32" || !
|
|
29074
|
+
if (process.platform !== "win32" || !path14.isAbsolute(bridge) || !path14.isAbsolute(file2) || !Number.isSafeInteger(maxBytes) || maxBytes < 1 || maxBytes > (prefix ? 16777216 : 1048576)) {
|
|
28904
29075
|
return Promise.reject(new Error("FILE_READ_ARGUMENT_INVALID"));
|
|
28905
29076
|
}
|
|
28906
29077
|
if (signal?.aborted) return Promise.reject(new Error("CANCELLED"));
|
|
28907
29078
|
return new Promise((resolve, reject) => {
|
|
28908
|
-
const child =
|
|
29079
|
+
const child = execFile3(bridge, prefix ? ["read-prefix", String(maxBytes)] : ["read-file"], {
|
|
28909
29080
|
encoding: "buffer",
|
|
28910
29081
|
timeout: 1e4,
|
|
28911
29082
|
maxBuffer: prefix ? Math.ceil(maxBytes / 3) * 4 + 512 : 1048576,
|
|
@@ -28930,10 +29101,10 @@ function invokeRead(bridge, file2, maxBytes, prefix, signal) {
|
|
|
28930
29101
|
// agent/src/posix-platform.ts
|
|
28931
29102
|
import { constants as constants6 } from "node:fs";
|
|
28932
29103
|
import { access as access2, realpath as realpath6, stat } from "node:fs/promises";
|
|
28933
|
-
import
|
|
29104
|
+
import path15 from "node:path";
|
|
28934
29105
|
async function resolvePosixExecutable(command, searchPath = process.env.PATH ?? "") {
|
|
28935
29106
|
if (!command || /[\u0000-\u001f]/.test(command)) return null;
|
|
28936
|
-
const candidates =
|
|
29107
|
+
const candidates = path15.posix.isAbsolute(command) ? [command] : /^[\w.-]+$/.test(command) ? searchPath.split(":").filter((directory) => path15.posix.isAbsolute(directory)).map((directory) => path15.posix.join(directory, command)) : [];
|
|
28937
29108
|
for (const candidate of candidates) {
|
|
28938
29109
|
try {
|
|
28939
29110
|
const canonical2 = await realpath6(candidate);
|
|
@@ -28949,12 +29120,12 @@ async function resolvePosixExecutable(command, searchPath = process.env.PATH ??
|
|
|
28949
29120
|
|
|
28950
29121
|
// agent/src/job-supervisor.ts
|
|
28951
29122
|
import { spawn as spawn4 } from "node:child_process";
|
|
28952
|
-
import
|
|
29123
|
+
import path16 from "node:path";
|
|
28953
29124
|
function absolute(value) {
|
|
28954
|
-
return typeof value === "string" && value.length > 0 && value.length < 32767 && !value.includes("\0") &&
|
|
29125
|
+
return typeof value === "string" && value.length > 0 && value.length < 32767 && !value.includes("\0") && path16.isAbsolute(value) && path16.resolve(value) === value;
|
|
28955
29126
|
}
|
|
28956
29127
|
async function runSupervised(helper, request, options = {}) {
|
|
28957
|
-
if (process.platform !== "win32" && process.platform !== "linux") throw Error("SUPERVISOR_PLATFORM_UNSUPPORTED");
|
|
29128
|
+
if (process.platform !== "win32" && process.platform !== "linux" && process.platform !== "darwin") throw Error("SUPERVISOR_PLATFORM_UNSUPPORTED");
|
|
28958
29129
|
if (!absolute(helper) || !absolute(request.executable) || !absolute(request.cwd)) throw new TypeError("INVALID_SUPERVISOR_PATH");
|
|
28959
29130
|
const args = request.args ?? [], timeoutMs2 = request.timeoutMs ?? 6e4, maxProcesses = request.maxProcesses ?? 16, maxBytes = options.maxOutputBytes ?? 98304;
|
|
28960
29131
|
if (!Array.isArray(args) || args.length > 128 || args.some((v) => typeof v !== "string" || v.length > 8192 || v.includes("\0"))) throw new TypeError("INVALID_SUPERVISOR_ARGS");
|
|
@@ -28966,8 +29137,9 @@ async function runSupervised(helper, request, options = {}) {
|
|
|
28966
29137
|
const stdout = new Utf8OutputTailBuffer(maxBytes, options.encoding), stderr = new Utf8OutputTailBuffer(maxBytes, options.encoding);
|
|
28967
29138
|
let pid = null, outcome = null;
|
|
28968
29139
|
let buffer = "", failure6 = null, closed = false, cancelSent = false;
|
|
29140
|
+
let containmentReceived = false, containmentSaved = process.platform === "win32";
|
|
28969
29141
|
let killTimer, hardTimer;
|
|
28970
|
-
const child = spawn4(process.platform === "
|
|
29142
|
+
const child = spawn4(process.platform === "win32" ? helper : process.execPath, process.platform === "win32" ? [] : [helper], { cwd: path16.dirname(helper), stdio: ["pipe", "pipe", "pipe"], windowsHide: true, shell: false, env: buildChildEnvironment(process.env) });
|
|
28971
29143
|
const cancel = () => {
|
|
28972
29144
|
if (closed || cancelSent) return;
|
|
28973
29145
|
cancelSent = true;
|
|
@@ -29005,7 +29177,20 @@ async function runSupervised(helper, request, options = {}) {
|
|
|
29005
29177
|
try {
|
|
29006
29178
|
const m = JSON.parse(line);
|
|
29007
29179
|
if (!m || typeof m !== "object" || Array.isArray(m) || outcome) throw Error();
|
|
29008
|
-
if (m.type === "
|
|
29180
|
+
if (m.type === "containment") {
|
|
29181
|
+
const containment = m.containment;
|
|
29182
|
+
const valid = (value) => process.platform === "linux" ? validLinuxContainment(value) : process.platform === "darwin" && validDarwinContainment(value);
|
|
29183
|
+
if (!valid(containment) || containmentReceived || pid !== null || child.pid === void 0 || containment.uid !== process.getuid?.()) throw Error();
|
|
29184
|
+
containmentReceived = true;
|
|
29185
|
+
Promise.resolve().then(() => options.onSupervisor?.(child.pid, containment)).then(() => {
|
|
29186
|
+
if (failure6 || closed || cancelSent) return;
|
|
29187
|
+
containmentSaved = true;
|
|
29188
|
+
child.stdin.write("continue\n", (error62) => {
|
|
29189
|
+
if (error62) fail7("SUPERVISOR_CONTROL_CLOSED");
|
|
29190
|
+
});
|
|
29191
|
+
}, () => fail7("SUPERVISOR_START_FAILED"));
|
|
29192
|
+
} else if (m.type === "started") {
|
|
29193
|
+
if (!containmentSaved) throw Error();
|
|
29009
29194
|
if (pid !== null || !Number.isSafeInteger(m.pid) || m.pid <= 0) throw Error();
|
|
29010
29195
|
pid = m.pid;
|
|
29011
29196
|
options.onStarted?.(pid);
|
|
@@ -29147,24 +29332,33 @@ function encodeText(text3, encoding) {
|
|
|
29147
29332
|
const bytes3 = Buffer.from("\uFEFF" + text3.replace(/[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/g, "\uFFFD"), "utf16le");
|
|
29148
29333
|
return encoding === "utf16be" ? bytes3.swap16() : bytes3;
|
|
29149
29334
|
}
|
|
29150
|
-
var
|
|
29335
|
+
var delay2 = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
29151
29336
|
var NativeTools = class {
|
|
29152
29337
|
constructor(options) {
|
|
29153
29338
|
this.options = options;
|
|
29154
29339
|
this.options = structuredClone(options);
|
|
29155
|
-
this.memory = new HostMemory(
|
|
29340
|
+
this.memory = new HostMemory(path17.join(options.stateDirectory, "host-memory.json"), Object.keys(options.programs), Object.fromEntries(Object.entries(options.programs).map(([name2, program]) => [name2, program.executable])));
|
|
29156
29341
|
}
|
|
29157
29342
|
options;
|
|
29158
29343
|
memory;
|
|
29159
29344
|
async readFile(file2, maxBytes, signal) {
|
|
29160
29345
|
try {
|
|
29161
|
-
return await readBoundedFile(file2, maxBytes, this.options.ownerBridgePath ??
|
|
29346
|
+
return await readBoundedFile(file2, maxBytes, this.options.ownerBridgePath ?? path17.join(path17.dirname(this.options.helperPath), "OwnerBridge.exe"), signal);
|
|
29162
29347
|
} catch (error62) {
|
|
29163
29348
|
if (error62.code === "ENOENT") throw error62;
|
|
29164
29349
|
if (error62 instanceof Error && /^[A-Z_]{1,40}$/.test(error62.message)) fail3(error62.message);
|
|
29165
29350
|
throw error62;
|
|
29166
29351
|
}
|
|
29167
29352
|
}
|
|
29353
|
+
/** Windows only: up to 64 files of at most 1 MiB in one bridge process, each with its own result. */
|
|
29354
|
+
async readFiles(files, maxTotalBytes, signal) {
|
|
29355
|
+
try {
|
|
29356
|
+
return await readWindowsFiles(this.options.ownerBridgePath ?? path17.join(path17.dirname(this.options.helperPath), "OwnerBridge.exe"), files, 1048576, maxTotalBytes, signal);
|
|
29357
|
+
} catch (error62) {
|
|
29358
|
+
if (error62 instanceof Error && /^[A-Z_]{1,40}$/.test(error62.message)) fail3(error62.message);
|
|
29359
|
+
throw error62;
|
|
29360
|
+
}
|
|
29361
|
+
}
|
|
29168
29362
|
async prepare(workspace2, candidate, selection) {
|
|
29169
29363
|
let prepared;
|
|
29170
29364
|
try {
|
|
@@ -29176,14 +29370,14 @@ var NativeTools = class {
|
|
|
29176
29370
|
const proof2 = JSON.parse((await identity.run(AbortSignal.timeout(15e3))).stdout);
|
|
29177
29371
|
if (!proof2.repositoryFingerprint) fail3("PROJECT_IDENTITY_UNKNOWN");
|
|
29178
29372
|
if (proof2.repositoryFingerprint !== target.repositoryFingerprint) fail3("PROJECT_IDENTITY_MISMATCH");
|
|
29179
|
-
projectRoot =
|
|
29373
|
+
projectRoot = path17.resolve(workspace2.root, target.relativePath);
|
|
29180
29374
|
const common = identity.claims.find((claim2) => claim2.namespace === "git")?.path;
|
|
29181
29375
|
if (common) workspace2 = { ...workspace2, gitCommonDir: common };
|
|
29182
29376
|
}
|
|
29183
29377
|
prepared = await this.prepareTool(workspace2, candidate, projectRoot);
|
|
29184
29378
|
} catch (error62) {
|
|
29185
29379
|
const parsed = ToolCallSchema.safeParse(candidate);
|
|
29186
|
-
if (parsed.success && parsed.data.name === "command_run") await this.memory.record({ ...parsed.data.args, cwd:
|
|
29380
|
+
if (parsed.success && parsed.data.name === "command_run") await this.memory.record({ ...parsed.data.args, cwd: path17.resolve(workspace2.root, parsed.data.args.cwd ?? ".") }, void 0, error62).catch(() => {
|
|
29187
29381
|
});
|
|
29188
29382
|
throw error62;
|
|
29189
29383
|
}
|
|
@@ -29203,17 +29397,17 @@ var NativeTools = class {
|
|
|
29203
29397
|
try {
|
|
29204
29398
|
const canonical2 = await realpath7(workspace2.root);
|
|
29205
29399
|
if (!equalPath3(canonical2, workspace2.root) || hash6(process.platform === "win32" ? canonical2.toLowerCase() : canonical2) !== workspace2.rootHash) fail3("WORKSPACE_CHANGED");
|
|
29206
|
-
const runtimeDirectory =
|
|
29400
|
+
const runtimeDirectory = path17.dirname(this.options.helperPath);
|
|
29207
29401
|
const protectedPaths = [
|
|
29208
29402
|
this.options.stateDirectory,
|
|
29209
29403
|
this.options.helperPath,
|
|
29210
|
-
...["agent.mjs", "node.exe", "OwnerBridge.exe", "LocalCommanderAgent.exe", "node", "owner-store", "posix-host", "job-host.mjs", "lifecycle.mjs", "manifest.json"].map((name2) =>
|
|
29404
|
+
...["agent.mjs", "node.exe", "OwnerBridge.exe", "LocalCommanderAgent.exe", "node", "owner-store", "posix-host", "job-host.mjs", "lifecycle.mjs", "manifest.json"].map((name2) => path17.join(runtimeDirectory, name2))
|
|
29211
29405
|
];
|
|
29212
29406
|
if (this.options.ownerBridgePath) protectedPaths.push(this.options.ownerBridgePath);
|
|
29213
|
-
if (process.platform === "win32" && process.env.LOCALAPPDATA &&
|
|
29214
|
-
protectedPaths.push(
|
|
29407
|
+
if (process.platform === "win32" && process.env.LOCALAPPDATA && path17.isAbsolute(process.env.LOCALAPPDATA)) {
|
|
29408
|
+
protectedPaths.push(path17.join(process.env.LOCALAPPDATA, "LocalCommander"));
|
|
29215
29409
|
}
|
|
29216
|
-
if (process.platform !== "win32") protectedPaths.push(
|
|
29410
|
+
if (process.platform !== "win32") protectedPaths.push(path17.join(process.env.LC_AGENT_DATA_DIR || posixDataHome(), "LocalCommander"));
|
|
29217
29411
|
guard = await PathGuard.create([canonical2], false, { protectedPaths });
|
|
29218
29412
|
if (projectRoot) {
|
|
29219
29413
|
const selected = await guard.resolveDirectory(projectRoot);
|
|
@@ -29302,7 +29496,7 @@ var NativeTools = class {
|
|
|
29302
29496
|
}
|
|
29303
29497
|
if (taken === first - 1 && first <= end) fail3("OUTPUT_LIMIT_EXCEEDED");
|
|
29304
29498
|
const remaining = lines.length - (lines.length > 1 && lines.at(-1) === "" ? 1 : 0);
|
|
29305
|
-
return result({ path:
|
|
29499
|
+
return result({ path: path17.relative(workspace2.root, filename), sha256: hash6(bytes3), startLine: first, endLine: Math.min(taken === first - 1 ? last : taken, lines.length), totalLines: lines.length, content: lines.slice(first - 1, taken).join("\n"), truncated: taken < remaining });
|
|
29306
29500
|
} };
|
|
29307
29501
|
}
|
|
29308
29502
|
if (call.name === "fs_write" || call.name === "fs_replace") {
|
|
@@ -29345,7 +29539,7 @@ var NativeTools = class {
|
|
|
29345
29539
|
bytes3 = encodeText(pieces.join(newText), original.encoding);
|
|
29346
29540
|
}
|
|
29347
29541
|
if (bytes3.length > MAX_FILE_WRITE_BYTES) fail3("FILE_WRITE_LIMIT");
|
|
29348
|
-
const temp =
|
|
29542
|
+
const temp = path17.join(path17.dirname(target), ".lc-write-" + randomUUID7() + ".tmp");
|
|
29349
29543
|
const handle = await open6(temp, constants7.O_CREAT | constants7.O_EXCL | constants7.O_WRONLY, 384);
|
|
29350
29544
|
try {
|
|
29351
29545
|
await handle.writeFile(bytes3);
|
|
@@ -29363,7 +29557,7 @@ var NativeTools = class {
|
|
|
29363
29557
|
} catch (error62) {
|
|
29364
29558
|
if (process.platform !== "win32" || !["EPERM", "EBUSY", "EACCES"].includes(error62.code ?? "")) throw error62;
|
|
29365
29559
|
if (attempt === 4) fail3((await lstat7(target)).mode & 128 ? "FILE_IN_USE" : "FILE_READ_ONLY");
|
|
29366
|
-
await
|
|
29560
|
+
await delay2(50 << attempt);
|
|
29367
29561
|
stopped(signal);
|
|
29368
29562
|
}
|
|
29369
29563
|
}
|
|
@@ -29380,11 +29574,11 @@ var NativeTools = class {
|
|
|
29380
29574
|
await rm5(temp);
|
|
29381
29575
|
break;
|
|
29382
29576
|
} catch {
|
|
29383
|
-
await
|
|
29577
|
+
await delay2(100);
|
|
29384
29578
|
}
|
|
29385
29579
|
}
|
|
29386
29580
|
}
|
|
29387
|
-
return result({ path:
|
|
29581
|
+
return result({ path: path17.relative(workspace2.root, target), bytes: bytes3.length, sha256: hash6(bytes3), ...call.name === "fs_replace" ? { replacements } : {} });
|
|
29388
29582
|
} catch (e) {
|
|
29389
29583
|
await handle.close().catch(() => {
|
|
29390
29584
|
});
|
|
@@ -29400,34 +29594,80 @@ var NativeTools = class {
|
|
|
29400
29594
|
const listing = await this.list(guard, base, 8, 1e3, signal), matches2 = [];
|
|
29401
29595
|
const query = call.args.caseSensitive ? call.args.query : call.args.query.toLowerCase();
|
|
29402
29596
|
let scanned = 0, scannedBytes = 0, room = RESULT_ITEMS_BUDGET, incomplete = false;
|
|
29597
|
+
const done = () => matches2.length >= call.args.maxResults || scanned >= 300 || room < 0;
|
|
29598
|
+
const skipped = (error62) => {
|
|
29599
|
+
if (error62 instanceof NativeToolError && ["FILE_READ_FAILED", "CANCELLED"].includes(error62.code)) throw error62;
|
|
29600
|
+
if (error62 instanceof NativeToolError && error62.code === "FILE_UNSUPPORTED_OR_TOO_LARGE") incomplete = true;
|
|
29601
|
+
};
|
|
29602
|
+
const searchFile = (filename, bytes3) => {
|
|
29603
|
+
scannedBytes += bytes3.length;
|
|
29604
|
+
const lines = decodeText(bytes3).text.split(/\r?\n/);
|
|
29605
|
+
scanned++;
|
|
29606
|
+
for (let i = 0; i < lines.length && matches2.length < call.args.maxResults; i++) if ((call.args.caseSensitive ? lines[i] : lines[i].toLowerCase()).includes(query)) {
|
|
29607
|
+
const match = { path: path17.relative(workspace2.root, filename), line: i + 1, text: lines[i].slice(0, 500) };
|
|
29608
|
+
if ((room -= Buffer.byteLength(JSON.stringify(match)) + 1) < 0) {
|
|
29609
|
+
incomplete = true;
|
|
29610
|
+
break;
|
|
29611
|
+
}
|
|
29612
|
+
matches2.push(match);
|
|
29613
|
+
}
|
|
29614
|
+
};
|
|
29615
|
+
const batched = process.platform === "win32", pending = [];
|
|
29616
|
+
let pendingBytes = 0, pendingInput = 0;
|
|
29617
|
+
const flush = async () => {
|
|
29618
|
+
if (!pending.length) return;
|
|
29619
|
+
const files = pending.splice(0);
|
|
29620
|
+
pendingBytes = 0;
|
|
29621
|
+
pendingInput = 0;
|
|
29622
|
+
const results2 = await this.readFiles(files, Math.max(1, 16777216 - scannedBytes), signal);
|
|
29623
|
+
for (let i = 0; i < files.length && !done(); i++) {
|
|
29624
|
+
const read = results2[i];
|
|
29625
|
+
if ("code" in read) {
|
|
29626
|
+
if (read.code === "FILE_UNSUPPORTED_OR_TOO_LARGE") incomplete = true;
|
|
29627
|
+
continue;
|
|
29628
|
+
}
|
|
29629
|
+
try {
|
|
29630
|
+
searchFile(files[i], read.data);
|
|
29631
|
+
} catch (error62) {
|
|
29632
|
+
skipped(error62);
|
|
29633
|
+
}
|
|
29634
|
+
}
|
|
29635
|
+
};
|
|
29403
29636
|
for (const entry of listing.entries) {
|
|
29404
29637
|
if (entry.type !== "file") continue;
|
|
29405
29638
|
stopped(signal);
|
|
29406
|
-
if (
|
|
29407
|
-
|
|
29639
|
+
if (done()) break;
|
|
29640
|
+
const size = entry.size ?? 0;
|
|
29641
|
+
if (pending.length && size <= 1048576 && scannedBytes + pendingBytes + size > 16777216) {
|
|
29642
|
+
await flush();
|
|
29643
|
+
if (done()) break;
|
|
29644
|
+
}
|
|
29645
|
+
if (size > 1048576 || scannedBytes + pendingBytes + size > 16777216) {
|
|
29408
29646
|
incomplete = true;
|
|
29409
29647
|
continue;
|
|
29410
29648
|
}
|
|
29411
29649
|
try {
|
|
29412
|
-
const filename = await guard.resolveExisting(
|
|
29650
|
+
const filename = await guard.resolveExisting(path17.join(base, entry.path));
|
|
29413
29651
|
guard.assertSafeFile(filename);
|
|
29414
|
-
|
|
29415
|
-
|
|
29416
|
-
|
|
29417
|
-
scanned++;
|
|
29418
|
-
for (let i = 0; i < lines.length && matches2.length < call.args.maxResults; i++) if ((call.args.caseSensitive ? lines[i] : lines[i].toLowerCase()).includes(query)) {
|
|
29419
|
-
const match = { path: path16.relative(workspace2.root, filename), line: i + 1, text: lines[i].slice(0, 500) };
|
|
29420
|
-
if ((room -= Buffer.byteLength(JSON.stringify(match)) + 1) < 0) {
|
|
29421
|
-
incomplete = true;
|
|
29422
|
-
break;
|
|
29423
|
-
}
|
|
29424
|
-
matches2.push(match);
|
|
29652
|
+
if (!batched) {
|
|
29653
|
+
searchFile(filename, await this.readFile(filename, 1048576, signal));
|
|
29654
|
+
continue;
|
|
29425
29655
|
}
|
|
29656
|
+
const input2 = Buffer.byteLength(JSON.stringify(filename)) + 1;
|
|
29657
|
+
if (pending.length && pendingInput + input2 > 25e4) await flush();
|
|
29658
|
+
pending.push(filename);
|
|
29659
|
+
pendingBytes += size;
|
|
29660
|
+
pendingInput += input2;
|
|
29426
29661
|
} catch (error62) {
|
|
29427
|
-
|
|
29428
|
-
|
|
29662
|
+
skipped(error62);
|
|
29663
|
+
continue;
|
|
29664
|
+
}
|
|
29665
|
+
if (pending.length >= Math.min(64, 300 - scanned) || pendingBytes >= 4194304) {
|
|
29666
|
+
await flush();
|
|
29667
|
+
if (done()) break;
|
|
29429
29668
|
}
|
|
29430
29669
|
}
|
|
29670
|
+
if (!done()) await flush();
|
|
29431
29671
|
return result({ matches: matches2, scannedFiles: scanned, truncated: listing.truncated || incomplete || matches2.length >= call.args.maxResults || scanned >= 300 });
|
|
29432
29672
|
} };
|
|
29433
29673
|
}
|
|
@@ -29473,7 +29713,7 @@ var NativeTools = class {
|
|
|
29473
29713
|
} };
|
|
29474
29714
|
}
|
|
29475
29715
|
if (call.name === "command_run") {
|
|
29476
|
-
if (
|
|
29716
|
+
if (!["win32", "linux", "darwin"].includes(process.platform)) fail3("COMMAND_NOT_ALLOWED");
|
|
29477
29717
|
const cwd2 = await resolve(call.args.cwd, true), program = await this.resolveProgram(call.args.command, workspace2, call.args.args);
|
|
29478
29718
|
const claims2 = writeClaim(cwd2);
|
|
29479
29719
|
return { call, claims: claims2, execution: { ...program, cwd: cwd2 }, run: async (signal, onStarted, onOutput, onSupervisor) => {
|
|
@@ -29501,9 +29741,9 @@ var NativeTools = class {
|
|
|
29501
29741
|
else if (call.name === "git_diff") {
|
|
29502
29742
|
argv = ["diff", "--no-ext-diff", "--no-textconv", ...call.args.staged ? ["--cached"] : []];
|
|
29503
29743
|
if (call.args.file) {
|
|
29504
|
-
const file2 = await resolve(
|
|
29505
|
-
const relative =
|
|
29506
|
-
if (relative.startsWith(".." +
|
|
29744
|
+
const file2 = await resolve(path17.resolve(cwd, call.args.file));
|
|
29745
|
+
const relative = path17.relative(cwd, file2);
|
|
29746
|
+
if (relative.startsWith(".." + path17.sep) || relative === ".." || path17.isAbsolute(relative)) fail3("PATH_NOT_ALLOWED");
|
|
29507
29747
|
argv.push("--", relative);
|
|
29508
29748
|
} else argv.push("--stat");
|
|
29509
29749
|
} else fail3("TOOL_MISSING");
|
|
@@ -29514,7 +29754,7 @@ var NativeTools = class {
|
|
|
29514
29754
|
const listing = await this.list(guard, cwd, 1, call.args.startup ? 20 : 150, signal);
|
|
29515
29755
|
let packageInfo = null;
|
|
29516
29756
|
try {
|
|
29517
|
-
const name2 = await guard.resolveExisting(
|
|
29757
|
+
const name2 = await guard.resolveExisting(path17.join(cwd, "package.json"));
|
|
29518
29758
|
guard.assertSafeFile(name2);
|
|
29519
29759
|
const value = JSON.parse(utf8(await this.readFile(name2, 64e3, signal)));
|
|
29520
29760
|
packageInfo = { name: typeof value.name === "string" ? value.name : null, version: typeof value.version === "string" ? value.version : null, scripts: value.scripts && typeof value.scripts === "object" ? Object.keys(value.scripts).slice(0, 100) : [] };
|
|
@@ -29534,7 +29774,7 @@ var NativeTools = class {
|
|
|
29534
29774
|
}
|
|
29535
29775
|
const contextFile = async (relative, limit, optional2 = false) => {
|
|
29536
29776
|
try {
|
|
29537
|
-
const file2 = await guard.resolveExisting(
|
|
29777
|
+
const file2 = await guard.resolveExisting(path17.join(primary, relative));
|
|
29538
29778
|
guard.assertSafeFile(file2);
|
|
29539
29779
|
return utf8(await this.readFile(file2, limit, signal));
|
|
29540
29780
|
} catch (error62) {
|
|
@@ -29567,17 +29807,17 @@ var NativeTools = class {
|
|
|
29567
29807
|
} };
|
|
29568
29808
|
}
|
|
29569
29809
|
async resolveProgram(name2, workspace2, args) {
|
|
29570
|
-
const entry = Object.entries(this.options.programs).find(([key, value]) => equalPath3(key, name2) ||
|
|
29810
|
+
const entry = Object.entries(this.options.programs).find(([key, value]) => equalPath3(key, name2) || path17.isAbsolute(name2) && equalPath3(value.executable, path17.resolve(name2)));
|
|
29571
29811
|
if (workspace2.fullAccess) {
|
|
29572
|
-
const commandKey = (value) => process.platform === "win32" ?
|
|
29812
|
+
const commandKey = (value) => process.platform === "win32" ? path17.basename(value).toLowerCase().replace(/\.(exe|com|cmd|bat)$/i, "") : path17.basename(value);
|
|
29573
29813
|
const denied = new Set((workspace2.deniedCommands ?? []).map(commandKey));
|
|
29574
29814
|
if (denied.has(commandKey(name2)) || entry && denied.has(commandKey(entry[0]))) fail3("COMMAND_NOT_ALLOWED");
|
|
29575
|
-
const extension2 =
|
|
29576
|
-
const candidate = entry?.[1].executable ?? (process.platform !== "win32" ? await resolvePosixExecutable(name2) :
|
|
29815
|
+
const extension2 = path17.extname(name2).toLowerCase();
|
|
29816
|
+
const candidate = entry?.[1].executable ?? (process.platform !== "win32" ? await resolvePosixExecutable(name2) : path17.isAbsolute(name2) ? name2 : /^[\w.-]+$/.test(name2) ? resolveWindowsLauncher(
|
|
29577
29817
|
commandKey(name2),
|
|
29578
29818
|
[".exe", ".com", ".cmd", ".bat"].includes(extension2) ? { ...process.env, PATHEXT: extension2 } : process.env
|
|
29579
29819
|
)?.file : void 0);
|
|
29580
|
-
if (!candidate || !
|
|
29820
|
+
if (!candidate || !path17.isAbsolute(candidate)) fail3("COMMAND_NOT_FOUND");
|
|
29581
29821
|
const executable = await realpath7(candidate).catch(() => fail3("COMMAND_NOT_FOUND"));
|
|
29582
29822
|
if (!(await lstat7(executable)).isFile()) fail3("COMMAND_NOT_FOUND");
|
|
29583
29823
|
if (denied.has(commandKey(executable))) fail3("COMMAND_NOT_ALLOWED");
|
|
@@ -29592,7 +29832,7 @@ var NativeTools = class {
|
|
|
29592
29832
|
if (/\.(cmd|bat)$/i.test(executable)) {
|
|
29593
29833
|
if ([executable, ...args].some((value) => /[&|<>^%!"\r\n]/.test(value))) fail3("INVALID_SCRIPT_ARGUMENTS");
|
|
29594
29834
|
const literal2 = (value) => "'" + value.replaceAll("'", "''") + "'";
|
|
29595
|
-
const shell =
|
|
29835
|
+
const shell = path17.join(process.env.SystemRoot ?? "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
|
|
29596
29836
|
if (denied.has("powershell") || denied.has("cmd")) fail3("COMMAND_NOT_ALLOWED");
|
|
29597
29837
|
const script = "& " + literal2(executable) + " @(" + args.map(literal2).join(",") + "); exit $LASTEXITCODE";
|
|
29598
29838
|
return { executable: shell, args: ["-NoProfile", "-NonInteractive", "-EncodedCommand", Buffer.from(script, "utf16le").toString("base64")] };
|
|
@@ -29600,7 +29840,7 @@ var NativeTools = class {
|
|
|
29600
29840
|
if (!/\.(exe|com)$/i.test(executable)) fail3("COMMAND_NOT_ALLOWED");
|
|
29601
29841
|
return { executable, args: [...entry?.[1].prefixArgs ?? [], ...args] };
|
|
29602
29842
|
}
|
|
29603
|
-
if (!entry || !workspace2.allowedCommands.some((v) => equalPath3(v, entry[0])) || !
|
|
29843
|
+
if (!entry || !workspace2.allowedCommands.some((v) => equalPath3(v, entry[0])) || !path17.isAbsolute(entry[1].executable)) fail3("COMMAND_NOT_ALLOWED");
|
|
29604
29844
|
return { executable: entry[1].executable, args: [...entry[1].prefixArgs ?? [], ...args] };
|
|
29605
29845
|
}
|
|
29606
29846
|
async memoryContext(workspace2) {
|
|
@@ -29613,11 +29853,11 @@ var NativeTools = class {
|
|
|
29613
29853
|
})) } };
|
|
29614
29854
|
}
|
|
29615
29855
|
async gitExecution(cwd, args) {
|
|
29616
|
-
if (
|
|
29856
|
+
if (!["win32", "linux", "darwin"].includes(process.platform)) fail3("COMMAND_NOT_ALLOWED");
|
|
29617
29857
|
const configured = this.options.programs.git;
|
|
29618
|
-
const candidates = configured ? [configured.executable] : process.platform === "win32" ? [[process.env.ProgramFiles, "Git"], [process.env["ProgramFiles(x86)"], "Git"], [process.env.LOCALAPPDATA, "Programs/Git"]].filter(([root]) => root &&
|
|
29858
|
+
const candidates = configured ? [configured.executable] : process.platform === "win32" ? [[process.env.ProgramFiles, "Git"], [process.env["ProgramFiles(x86)"], "Git"], [process.env.LOCALAPPDATA, "Programs/Git"]].filter(([root]) => root && path17.isAbsolute(root)).map(([root, suffix]) => path17.join(root, suffix, "cmd", "git.exe")) : ["/usr/bin/git", "/usr/local/bin/git", "/opt/homebrew/bin/git"];
|
|
29619
29859
|
for (const source of candidates) {
|
|
29620
|
-
if (!
|
|
29860
|
+
if (!path17.isAbsolute(source)) continue;
|
|
29621
29861
|
const candidate = process.platform === "win32" ? source : await resolvePosixExecutable(source);
|
|
29622
29862
|
if (!candidate) continue;
|
|
29623
29863
|
try {
|
|
@@ -29651,7 +29891,7 @@ var NativeTools = class {
|
|
|
29651
29891
|
break;
|
|
29652
29892
|
}
|
|
29653
29893
|
if (item.isSymbolicLink() || excluded.has(item.name.toLowerCase())) continue;
|
|
29654
|
-
const candidate =
|
|
29894
|
+
const candidate = path17.join(current2.path, item.name);
|
|
29655
29895
|
let resolved;
|
|
29656
29896
|
try {
|
|
29657
29897
|
resolved = await guard.resolveExisting(candidate);
|
|
@@ -29661,11 +29901,11 @@ var NativeTools = class {
|
|
|
29661
29901
|
}
|
|
29662
29902
|
if (!equalPath3(candidate, resolved)) continue;
|
|
29663
29903
|
if (item.isDirectory()) {
|
|
29664
|
-
entries.push({ path:
|
|
29904
|
+
entries.push({ path: path17.relative(root, resolved), type: "directory" });
|
|
29665
29905
|
if (current2.level < depth) queue.push({ path: resolved, level: current2.level + 1 });
|
|
29666
29906
|
} else if (item.isFile()) {
|
|
29667
29907
|
const stat2 = await lstat7(resolved).catch(() => null);
|
|
29668
|
-
if (stat2) entries.push({ path:
|
|
29908
|
+
if (stat2) entries.push({ path: path17.relative(root, resolved), type: "file", size: stat2.size });
|
|
29669
29909
|
}
|
|
29670
29910
|
}
|
|
29671
29911
|
if (truncated) break;
|
|
@@ -29675,7 +29915,7 @@ var NativeTools = class {
|
|
|
29675
29915
|
async gitCommonDir(cwd, workspace2, guard) {
|
|
29676
29916
|
let directory = cwd;
|
|
29677
29917
|
while (guard.isWithin(directory, workspace2.root)) {
|
|
29678
|
-
const dotGit =
|
|
29918
|
+
const dotGit = path17.join(directory, ".git");
|
|
29679
29919
|
try {
|
|
29680
29920
|
const stat2 = await lstat7(dotGit);
|
|
29681
29921
|
if (stat2.isSymbolicLink()) fail3("GIT_METADATA_CHANGED");
|
|
@@ -29684,14 +29924,14 @@ var NativeTools = class {
|
|
|
29684
29924
|
else {
|
|
29685
29925
|
const content = utf8(await this.readFile(dotGit, 4096)).trim();
|
|
29686
29926
|
if (!content.startsWith("gitdir: ")) fail3("GIT_METADATA_CHANGED");
|
|
29687
|
-
gitDir = await realpath7(
|
|
29927
|
+
gitDir = await realpath7(path17.resolve(directory, content.slice(8)));
|
|
29688
29928
|
}
|
|
29689
29929
|
if (guard.isWithin(gitDir, this.options.stateDirectory) || !guard.isWithin(gitDir, workspace2.root) && (!workspace2.gitCommonDir || !guard.isWithin(gitDir, workspace2.gitCommonDir))) fail3("GIT_COMMON_DIRECTORY_NOT_APPROVED");
|
|
29690
29930
|
let common = gitDir;
|
|
29691
29931
|
try {
|
|
29692
|
-
const content = utf8(await this.readFile(
|
|
29932
|
+
const content = utf8(await this.readFile(path17.join(gitDir, "commondir"), 4096)).trim();
|
|
29693
29933
|
if (!content) fail3("GIT_METADATA_CHANGED");
|
|
29694
|
-
common = await realpath7(
|
|
29934
|
+
common = await realpath7(path17.resolve(gitDir, content));
|
|
29695
29935
|
} catch (e) {
|
|
29696
29936
|
if (e.code !== "ENOENT") throw e;
|
|
29697
29937
|
}
|
|
@@ -29702,22 +29942,22 @@ var NativeTools = class {
|
|
|
29702
29942
|
if (e.code !== "ENOENT") throw e;
|
|
29703
29943
|
}
|
|
29704
29944
|
if (equalPath3(directory, workspace2.root)) break;
|
|
29705
|
-
directory =
|
|
29945
|
+
directory = path17.dirname(directory);
|
|
29706
29946
|
}
|
|
29707
29947
|
return null;
|
|
29708
29948
|
}
|
|
29709
29949
|
};
|
|
29710
29950
|
|
|
29711
29951
|
// agent/src/scheduler.ts
|
|
29712
|
-
import
|
|
29952
|
+
import path18 from "node:path";
|
|
29713
29953
|
import os4 from "node:os";
|
|
29714
29954
|
function canonical(value) {
|
|
29715
|
-
const p =
|
|
29955
|
+
const p = path18.resolve(value);
|
|
29716
29956
|
return process.platform === "win32" ? p.toLowerCase() : p;
|
|
29717
29957
|
}
|
|
29718
29958
|
function ancestor(a, b) {
|
|
29719
|
-
const relative =
|
|
29720
|
-
return relative === "" || !
|
|
29959
|
+
const relative = path18.relative(a, b);
|
|
29960
|
+
return relative === "" || !path18.isAbsolute(relative) && relative !== ".." && !relative.startsWith(".." + path18.sep);
|
|
29721
29961
|
}
|
|
29722
29962
|
function claimsConflict(a, b) {
|
|
29723
29963
|
return a.some((x) => b.some((y) => (x.namespace ?? "filesystem") === (y.namespace ?? "filesystem") && (x.mode === "write" || y.mode === "write") && (ancestor(x.path, y.path) || ancestor(y.path, x.path))));
|
|
@@ -29746,7 +29986,7 @@ var NativeScheduler = class {
|
|
|
29746
29986
|
schedule(id2, claims, deadlineAt, run, signal) {
|
|
29747
29987
|
if (!this.accepting) return Promise.reject(Error("AGENT_PAUSED"));
|
|
29748
29988
|
if (!id2 || id2.length > 100 || this.active.has(id2) || this.waiting.some((j) => j.id === id2)) return Promise.reject(Error("DUPLICATE_SCHEDULED_EXECUTION"));
|
|
29749
|
-
if (!Array.isArray(claims) || !claims.length || claims.length > 32 || claims.some((c) => !c || !
|
|
29989
|
+
if (!Array.isArray(claims) || !claims.length || claims.length > 32 || claims.some((c) => !c || !path18.isAbsolute(c.path) || !["read", "write"].includes(c.mode))) return Promise.reject(Error("INVALID_RESOURCE_CLAIM"));
|
|
29750
29990
|
const deadline = deadlineAt.getTime();
|
|
29751
29991
|
if (!Number.isFinite(deadline) || deadline <= Date.now()) return Promise.reject(Error("ADMISSION_DEADLINE_EXPIRED"));
|
|
29752
29992
|
if (signal?.aborted) return Promise.reject(Error("CANCELLED_BEFORE_ACCEPTANCE"));
|
|
@@ -30253,17 +30493,17 @@ function unshapedResultTelemetry(result2) {
|
|
|
30253
30493
|
|
|
30254
30494
|
// packages/optimization/src/live-telemetry.ts
|
|
30255
30495
|
var LIVE_EFFICIENCY_EVENT_VERSION = 1;
|
|
30256
|
-
var
|
|
30496
|
+
var uuid18 = external_exports.string().uuid().toLowerCase();
|
|
30257
30497
|
var bytes2 = external_exports.number().int().min(0).max(1e9);
|
|
30258
30498
|
var utc4 = external_exports.iso.datetime({ offset: false });
|
|
30259
30499
|
var LiveEfficiencyEventSchema = external_exports.object({
|
|
30260
30500
|
version: external_exports.literal(LIVE_EFFICIENCY_EVENT_VERSION),
|
|
30261
30501
|
occurredAt: utc4,
|
|
30262
|
-
tenantId:
|
|
30263
|
-
accountId:
|
|
30264
|
-
sessionId:
|
|
30265
|
-
operationId:
|
|
30266
|
-
executionId:
|
|
30502
|
+
tenantId: uuid18,
|
|
30503
|
+
accountId: uuid18.nullable(),
|
|
30504
|
+
sessionId: uuid18,
|
|
30505
|
+
operationId: uuid18,
|
|
30506
|
+
executionId: uuid18,
|
|
30267
30507
|
toolName: external_exports.string().trim().min(1).max(120),
|
|
30268
30508
|
outcome: external_exports.enum(["success", "failed", "timed_out", "cancelled", "unknown"]),
|
|
30269
30509
|
parserId: external_exports.string().trim().min(1).max(120).nullable(),
|
|
@@ -30647,7 +30887,7 @@ var NativeRuntime = class {
|
|
|
30647
30887
|
this.send({ type: "running", version: 1, binding: binding2, pid });
|
|
30648
30888
|
}, (stream, bytes3) => {
|
|
30649
30889
|
(stream === "stdout" ? context.stdout : context.stderr).append(bytes3);
|
|
30650
|
-
}, (pid) => this.options.journal.supervisor(binding2.executionId, pid));
|
|
30890
|
+
}, (pid, containment) => this.options.journal.supervisor(binding2.executionId, pid, containment));
|
|
30651
30891
|
const checked = ResultSchema.parse(output2);
|
|
30652
30892
|
const { resultCode, ...journalOutput } = checked;
|
|
30653
30893
|
if (context.guardPermit) await this.options.guard.result(context.guardPermit, checked);
|
|
@@ -30858,9 +31098,9 @@ var NativeRelayBridge = class {
|
|
|
30858
31098
|
|
|
30859
31099
|
// agent/src/local-direct.ts
|
|
30860
31100
|
import net from "node:net";
|
|
30861
|
-
import
|
|
31101
|
+
import path19 from "node:path";
|
|
30862
31102
|
import { createHmac as createHmac2, hkdfSync, randomBytes as randomBytes6, randomUUID as randomUUID8, timingSafeEqual as timingSafeEqual3 } from "node:crypto";
|
|
30863
|
-
import { mkdir as mkdir7, readFile as
|
|
31103
|
+
import { mkdir as mkdir7, readFile as readFile7, rename as rename5, rm as rm6, writeFile as writeFile3 } from "node:fs/promises";
|
|
30864
31104
|
var LocalDirectError = class extends Error {
|
|
30865
31105
|
constructor(code) {
|
|
30866
31106
|
super(code);
|
|
@@ -30878,11 +31118,11 @@ var ADMISSION_MS = 6e4;
|
|
|
30878
31118
|
var MAX_IN_FLIGHT = 16;
|
|
30879
31119
|
var MAX_CONNECTIONS = 32;
|
|
30880
31120
|
function localDirectDirectory(appData) {
|
|
30881
|
-
return
|
|
31121
|
+
return path19.join(appData, "LocalCommander", "LocalMcp");
|
|
30882
31122
|
}
|
|
30883
31123
|
async function localDirectEnabled(directory) {
|
|
30884
31124
|
try {
|
|
30885
|
-
return JSON.parse(await
|
|
31125
|
+
return JSON.parse(await readFile7(path19.join(directory, "settings.json"), "utf8"))?.enabled === true;
|
|
30886
31126
|
} catch {
|
|
30887
31127
|
return false;
|
|
30888
31128
|
}
|
|
@@ -30955,7 +31195,7 @@ var Lines = class {
|
|
|
30955
31195
|
async function readEndpoint(directory) {
|
|
30956
31196
|
let value;
|
|
30957
31197
|
try {
|
|
30958
|
-
value = JSON.parse(await
|
|
31198
|
+
value = JSON.parse(await readFile7(path19.join(directory, "endpoint.json"), "utf8"));
|
|
30959
31199
|
} catch {
|
|
30960
31200
|
fail4("LOCAL_AGENT_NOT_RUNNING");
|
|
30961
31201
|
}
|
|
@@ -30972,7 +31212,7 @@ var LocalDirectServer = class _LocalDirectServer {
|
|
|
30972
31212
|
sockets = /* @__PURE__ */ new Set();
|
|
30973
31213
|
/** Listens only while the owner has enabled direct local access; null otherwise. */
|
|
30974
31214
|
static async start(options) {
|
|
30975
|
-
const endpointFile =
|
|
31215
|
+
const endpointFile = path19.join(options.directory, "endpoint.json");
|
|
30976
31216
|
if (!await localDirectEnabled(options.directory)) {
|
|
30977
31217
|
await rm6(endpointFile, { force: true }).catch(() => {
|
|
30978
31218
|
});
|
|
@@ -31000,7 +31240,7 @@ var LocalDirectServer = class _LocalDirectServer {
|
|
|
31000
31240
|
for (const socket of this.sockets) socket.destroy();
|
|
31001
31241
|
await new Promise((resolve) => this.server.close(() => resolve()));
|
|
31002
31242
|
try {
|
|
31003
|
-
if ((await readEndpoint(this.options.directory)).pid === process.pid) await rm6(
|
|
31243
|
+
if ((await readEndpoint(this.options.directory)).pid === process.pid) await rm6(path19.join(this.options.directory, "endpoint.json"), { force: true });
|
|
31004
31244
|
} catch {
|
|
31005
31245
|
}
|
|
31006
31246
|
}
|
|
@@ -34855,9 +35095,9 @@ var rev2026Codec = {
|
|
|
34855
35095
|
});
|
|
34856
35096
|
const parsed = buildSchemas2026().RequestMetaEnvelopeSchema.safeParse(meta3);
|
|
34857
35097
|
if (!parsed.success) for (const issue2 of parsed.error.issues) {
|
|
34858
|
-
const
|
|
34859
|
-
const key =
|
|
34860
|
-
if (
|
|
35098
|
+
const path29 = issue2.path.map(String);
|
|
35099
|
+
const key = path29.length > 0 ? path29.join(".") : "_meta";
|
|
35100
|
+
if (path29.length === 1 && issues.some((existing) => existing.key === key && existing.problem === "missing")) continue;
|
|
34861
35101
|
issues.push({
|
|
34862
35102
|
key,
|
|
34863
35103
|
problem: issue2.message
|
|
@@ -35159,29 +35399,29 @@ var PERMITTED_X_MCP_HEADER_TYPES = /* @__PURE__ */ new Set([
|
|
|
35159
35399
|
function scanXMcpHeaderDeclarations(inputSchema) {
|
|
35160
35400
|
const declarations = [];
|
|
35161
35401
|
const seenLower = /* @__PURE__ */ new Map();
|
|
35162
|
-
const visit2 = (node2,
|
|
35402
|
+
const visit2 = (node2, path29, reachable) => {
|
|
35163
35403
|
if (node2 === null || typeof node2 !== "object") return void 0;
|
|
35164
35404
|
const schema = node2;
|
|
35165
35405
|
if (X_MCP_HEADER_KEY in schema) {
|
|
35166
|
-
if (!reachable ||
|
|
35406
|
+
if (!reachable || path29.length === 0) return `${pathName(path29)}: x-mcp-header is only permitted on properties statically reachable via a chain of 'properties' keys (not under items, additionalProperties, oneOf/anyOf/allOf/not, if/then/else, or $ref)`;
|
|
35167
35407
|
const raw = schema[X_MCP_HEADER_KEY];
|
|
35168
|
-
if (typeof raw !== "string" || raw.length === 0) return `${pathName(
|
|
35169
|
-
if (!RFC9110_TOKEN.test(raw)) return `${pathName(
|
|
35408
|
+
if (typeof raw !== "string" || raw.length === 0) return `${pathName(path29)}: x-mcp-header MUST be a non-empty string`;
|
|
35409
|
+
if (!RFC9110_TOKEN.test(raw)) return `${pathName(path29)}: x-mcp-header '${raw}' is not a valid RFC 9110 token (no spaces, control characters or HTTP delimiters)`;
|
|
35170
35410
|
const type = typeof schema.type === "string" ? schema.type : void 0;
|
|
35171
|
-
if (type === void 0 || !PERMITTED_X_MCP_HEADER_TYPES.has(type)) return `${pathName(
|
|
35411
|
+
if (type === void 0 || !PERMITTED_X_MCP_HEADER_TYPES.has(type)) return `${pathName(path29)}: x-mcp-header is only permitted on primitive-typed properties (string, integer, boolean); got ${type ?? "<none>"}`;
|
|
35172
35412
|
const lower = raw.toLowerCase();
|
|
35173
35413
|
const prior = seenLower.get(lower);
|
|
35174
35414
|
if (prior !== void 0) return `x-mcp-header '${raw}' is not case-insensitively unique (also declared as '${prior}')`;
|
|
35175
35415
|
seenLower.set(lower, raw);
|
|
35176
35416
|
declarations.push({
|
|
35177
|
-
path:
|
|
35417
|
+
path: path29,
|
|
35178
35418
|
headerName: raw,
|
|
35179
35419
|
type
|
|
35180
35420
|
});
|
|
35181
35421
|
}
|
|
35182
35422
|
const properties = schema.properties;
|
|
35183
35423
|
if (properties !== null && typeof properties === "object") for (const [key, child] of Object.entries(properties)) {
|
|
35184
|
-
const fault$1 = visit2(child, [...
|
|
35424
|
+
const fault$1 = visit2(child, [...path29, key], reachable);
|
|
35185
35425
|
if (fault$1 !== void 0) return fault$1;
|
|
35186
35426
|
}
|
|
35187
35427
|
for (const k of NON_REACHABLE_SUBSCHEMA_KEYWORDS) {
|
|
@@ -35189,7 +35429,7 @@ function scanXMcpHeaderDeclarations(inputSchema) {
|
|
|
35189
35429
|
if (sub === void 0) continue;
|
|
35190
35430
|
const branches = Array.isArray(sub) ? sub : sub !== null && typeof sub === "object" && OBJECT_VALUED_SUBSCHEMA_KEYWORDS.has(k) ? Object.values(sub) : [sub];
|
|
35191
35431
|
for (const branch of branches) {
|
|
35192
|
-
const fault$1 = visit2(branch, [...
|
|
35432
|
+
const fault$1 = visit2(branch, [...path29, `<${k}>`], false);
|
|
35193
35433
|
if (fault$1 !== void 0) return fault$1;
|
|
35194
35434
|
}
|
|
35195
35435
|
}
|
|
@@ -35229,8 +35469,8 @@ var OBJECT_VALUED_SUBSCHEMA_KEYWORDS = /* @__PURE__ */ new Set([
|
|
|
35229
35469
|
"$defs",
|
|
35230
35470
|
"definitions"
|
|
35231
35471
|
]);
|
|
35232
|
-
function pathName(
|
|
35233
|
-
return
|
|
35472
|
+
function pathName(path29) {
|
|
35473
|
+
return path29.length === 0 ? "<root>" : path29.join(".");
|
|
35234
35474
|
}
|
|
35235
35475
|
var HEADER_MISMATCH_ERROR_CODE = -32020;
|
|
35236
35476
|
var INBOUND_VALIDATION_LADDER = [
|
|
@@ -35480,7 +35720,7 @@ var PROPERTY_KEYS_BY_TYPE = {
|
|
|
35480
35720
|
array: shapeKeys([UntitledMultiSelectEnumSchemaSchema, TitledMultiSelectEnumSchemaSchema])
|
|
35481
35721
|
};
|
|
35482
35722
|
var SUPPORTED_STRING_FORMATS = new Set(StringSchemaSchema.shape.format.unwrap().options);
|
|
35483
|
-
function walkProperty(node2,
|
|
35723
|
+
function walkProperty(node2, path29, vendor, unsupported) {
|
|
35484
35724
|
if (!isJsonObject(node2)) return node2;
|
|
35485
35725
|
const allowedKeys = typeof node2.type === "string" && Object.hasOwn(PROPERTY_KEYS_BY_TYPE, node2.type) ? PROPERTY_KEYS_BY_TYPE[node2.type] : void 0;
|
|
35486
35726
|
if (allowedKeys === void 0) return node2;
|
|
@@ -35488,8 +35728,8 @@ function walkProperty(node2, path28, vendor, unsupported) {
|
|
|
35488
35728
|
for (const [key, value] of Object.entries(node2)) if (allowedKeys.has(key) || isAnnotationOnlyJsonSchemaKeyword(key)) pruned[key] = value;
|
|
35489
35729
|
else if (key === "pattern" && node2.type === "string" && typeof node2.format === "string") {
|
|
35490
35730
|
if (!SUPPORTED_STRING_FORMATS.has(node2.format)) pruned[key] = value;
|
|
35491
|
-
else if (typeof value !== "string" || !isLibraryFormatPattern(node2.format, value, vendor)) unsupported.push(`${
|
|
35492
|
-
} else unsupported.push(`${
|
|
35731
|
+
else if (typeof value !== "string" || !isLibraryFormatPattern(node2.format, value, vendor)) unsupported.push(`${path29}.${key}`);
|
|
35732
|
+
} else unsupported.push(`${path29}.${key}`);
|
|
35493
35733
|
return pruned;
|
|
35494
35734
|
}
|
|
35495
35735
|
function walkRequestedSchema(converted, vendor) {
|
|
@@ -35506,11 +35746,11 @@ function describeUnsupportedProperties(pruned, fallback) {
|
|
|
35506
35746
|
const offenders = Object.entries(pruned.properties).filter(([, node2]) => !parseSchema(PrimitiveSchemaDefinitionSchema, node2).success).map(([name2]) => `properties.${name2}`);
|
|
35507
35747
|
return offenders.length > 0 ? offenders.join(", ") : fallback;
|
|
35508
35748
|
}
|
|
35509
|
-
function findDroppedConstraintPaths(original, parsed,
|
|
35510
|
-
if (Array.isArray(original) && Array.isArray(parsed)) return original.flatMap((item, index) => findDroppedConstraintPaths(item, parsed[index], `${
|
|
35749
|
+
function findDroppedConstraintPaths(original, parsed, path29 = "") {
|
|
35750
|
+
if (Array.isArray(original) && Array.isArray(parsed)) return original.flatMap((item, index) => findDroppedConstraintPaths(item, parsed[index], `${path29}[${index}]`));
|
|
35511
35751
|
if (!isJsonObject(original) || !isJsonObject(parsed)) return [];
|
|
35512
35752
|
return Object.entries(original).flatMap(([key, value]) => {
|
|
35513
|
-
const childPath =
|
|
35753
|
+
const childPath = path29 ? `${path29}.${key}` : key;
|
|
35514
35754
|
if (!Object.prototype.hasOwnProperty.call(parsed, key)) return isAnnotationOnlyJsonSchemaKeyword(key) ? [] : [childPath];
|
|
35515
35755
|
return findDroppedConstraintPaths(value, parsed[key], childPath);
|
|
35516
35756
|
});
|
|
@@ -37221,9 +37461,9 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
37221
37461
|
}
|
|
37222
37462
|
};
|
|
37223
37463
|
var Label = class extends Node {
|
|
37224
|
-
constructor(
|
|
37464
|
+
constructor(label2) {
|
|
37225
37465
|
super();
|
|
37226
|
-
this.label =
|
|
37466
|
+
this.label = label2;
|
|
37227
37467
|
this.names = {};
|
|
37228
37468
|
}
|
|
37229
37469
|
render({ _n }) {
|
|
@@ -37231,9 +37471,9 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
37231
37471
|
}
|
|
37232
37472
|
};
|
|
37233
37473
|
var Break = class extends Node {
|
|
37234
|
-
constructor(
|
|
37474
|
+
constructor(label2) {
|
|
37235
37475
|
super();
|
|
37236
|
-
this.label =
|
|
37476
|
+
this.label = label2;
|
|
37237
37477
|
this.names = {};
|
|
37238
37478
|
}
|
|
37239
37479
|
render({ _n }) {
|
|
@@ -37598,11 +37838,11 @@ var require_codegen = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
37598
37838
|
endFor() {
|
|
37599
37839
|
return this._endBlockNode(For);
|
|
37600
37840
|
}
|
|
37601
|
-
label(
|
|
37602
|
-
return this._leafNode(new Label(
|
|
37841
|
+
label(label2) {
|
|
37842
|
+
return this._leafNode(new Label(label2));
|
|
37603
37843
|
}
|
|
37604
|
-
break(
|
|
37605
|
-
return this._leafNode(new Break(
|
|
37844
|
+
break(label2) {
|
|
37845
|
+
return this._leafNode(new Break(label2));
|
|
37606
37846
|
}
|
|
37607
37847
|
return(value) {
|
|
37608
37848
|
const node2 = new Return();
|
|
@@ -39586,8 +39826,8 @@ var require_utils = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
39586
39826
|
for (let i = 0; i < str.length; i++) if (str[i] === token) ind++;
|
|
39587
39827
|
return ind;
|
|
39588
39828
|
}
|
|
39589
|
-
function removeDotSegments(
|
|
39590
|
-
let input2 =
|
|
39829
|
+
function removeDotSegments(path29) {
|
|
39830
|
+
let input2 = path29;
|
|
39591
39831
|
const output2 = [];
|
|
39592
39832
|
let nextSlash = -1;
|
|
39593
39833
|
let len = 0;
|
|
@@ -39740,8 +39980,8 @@ var require_schemes = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
39740
39980
|
wsComponent.secure = void 0;
|
|
39741
39981
|
}
|
|
39742
39982
|
if (wsComponent.resourceName) {
|
|
39743
|
-
const [
|
|
39744
|
-
wsComponent.path =
|
|
39983
|
+
const [path29, query] = wsComponent.resourceName.split("?");
|
|
39984
|
+
wsComponent.path = path29 && path29 !== "/" ? path29 : void 0;
|
|
39745
39985
|
wsComponent.query = query;
|
|
39746
39986
|
wsComponent.resourceName = void 0;
|
|
39747
39987
|
}
|
|
@@ -45382,10 +45622,10 @@ import { createHash as createHash15, createPrivateKey as createPrivateKey3, rand
|
|
|
45382
45622
|
|
|
45383
45623
|
// agent/src/native-incident-producer.ts
|
|
45384
45624
|
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
45385
|
-
var
|
|
45625
|
+
var uuid19 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
45386
45626
|
var results = /* @__PURE__ */ new Set(["accepted", "duplicate", "invalid", "stale", "unconfirmed", "capacity", "retry", "disabled", "busy"]);
|
|
45387
45627
|
function nativeIncidentAck(candidate) {
|
|
45388
|
-
if (candidate.type !== "incidentBatchAck" || candidate.protocolVersion !== 1 || Object.keys(candidate).some((key) => !["type", "protocolVersion", "batchId", "result"].includes(key)) || typeof candidate.result !== "string" || !results.has(candidate.result) || candidate.batchId !== void 0 && (typeof candidate.batchId !== "string" || !
|
|
45628
|
+
if (candidate.type !== "incidentBatchAck" || candidate.protocolVersion !== 1 || Object.keys(candidate).some((key) => !["type", "protocolVersion", "batchId", "result"].includes(key)) || typeof candidate.result !== "string" || !results.has(candidate.result) || candidate.batchId !== void 0 && (typeof candidate.batchId !== "string" || !uuid19.test(candidate.batchId))) return;
|
|
45389
45629
|
return { result: candidate.result, ...candidate.batchId ? { batchId: String(candidate.batchId).toLowerCase() } : {} };
|
|
45390
45630
|
}
|
|
45391
45631
|
var NativeIncidentProducer = class {
|
|
@@ -45451,12 +45691,12 @@ var NativeIncidentProducer = class {
|
|
|
45451
45691
|
classify(event, occurrences) {
|
|
45452
45692
|
const incident = event.incident;
|
|
45453
45693
|
if (!incident) return;
|
|
45454
|
-
const executionId = incident.executionId &&
|
|
45694
|
+
const executionId = incident.executionId && uuid19.test(incident.executionId) ? incident.executionId.toLowerCase() : void 0;
|
|
45455
45695
|
let refs = {};
|
|
45456
45696
|
try {
|
|
45457
45697
|
const confirmed = executionId && this.references?.(executionId);
|
|
45458
|
-
if (confirmed && confirmed.executionId === executionId &&
|
|
45459
|
-
refs = { workerId: confirmed.workerId.toLowerCase(), ...confirmed.taskId &&
|
|
45698
|
+
if (confirmed && confirmed.executionId === executionId && uuid19.test(confirmed.workerId)) {
|
|
45699
|
+
refs = { workerId: confirmed.workerId.toLowerCase(), ...confirmed.taskId && uuid19.test(confirmed.taskId) ? { taskId: confirmed.taskId.toLowerCase() } : {} };
|
|
45460
45700
|
}
|
|
45461
45701
|
} catch {
|
|
45462
45702
|
}
|
|
@@ -45569,7 +45809,7 @@ function relayUrlFromEnrollment(enrollment) {
|
|
|
45569
45809
|
url2.pathname = "/api/agent/relay";
|
|
45570
45810
|
return url2.toString();
|
|
45571
45811
|
}
|
|
45572
|
-
function
|
|
45812
|
+
function uuid20(value, code) {
|
|
45573
45813
|
if (typeof value !== "string" || !UUID2.test(value)) fail5(code);
|
|
45574
45814
|
return value.toLowerCase();
|
|
45575
45815
|
}
|
|
@@ -45699,11 +45939,11 @@ function sendJson(socket, value, maxBytes) {
|
|
|
45699
45939
|
function validateChallenge(frame, expectedProtocol) {
|
|
45700
45940
|
if (frame.type !== "challenge") fail5("RELAY_HANDSHAKE_INVALID");
|
|
45701
45941
|
protocol(frame.protocolVersion, expectedProtocol);
|
|
45702
|
-
|
|
45942
|
+
uuid20(frame.gatewayId, "RELAY_HANDSHAKE_INVALID");
|
|
45703
45943
|
if (typeof frame.nonce !== "string" || frame.nonce.length < 32 || frame.nonce.length > 512 || /[\u0000-\u001f\u007f]/u.test(frame.nonce)) fail5("RELAY_HANDSHAKE_INVALID");
|
|
45704
45944
|
if (typeof frame.expiresAt !== "string" || !Number.isFinite(Date.parse(frame.expiresAt)) || Date.parse(frame.expiresAt) <= Date.now()) fail5("RELAY_HANDSHAKE_INVALID");
|
|
45705
45945
|
return {
|
|
45706
|
-
challengeId:
|
|
45946
|
+
challengeId: uuid20(frame.challengeId, "RELAY_HANDSHAKE_INVALID"),
|
|
45707
45947
|
nonce: frame.nonce,
|
|
45708
45948
|
// Older servers offer no capabilities and verify only the v1 proof.
|
|
45709
45949
|
machineIdentity: Array.isArray(frame.capabilities) && frame.capabilities.includes(MACHINE_IDENTITY_CAPABILITY)
|
|
@@ -45712,27 +45952,27 @@ function validateChallenge(frame, expectedProtocol) {
|
|
|
45712
45952
|
function validateReady(frame, enrollment, expectedProtocol) {
|
|
45713
45953
|
if (frame.type !== "connected") fail5("RELAY_HANDSHAKE_INVALID");
|
|
45714
45954
|
protocol(frame.protocolVersion, expectedProtocol);
|
|
45715
|
-
if (
|
|
45716
|
-
if (
|
|
45955
|
+
if (uuid20(frame.tenantId, "RELAY_HANDSHAKE_INVALID") !== enrollment.tenantId.toLowerCase()) fail5("RELAY_ID_MISMATCH");
|
|
45956
|
+
if (uuid20(frame.deviceId, "RELAY_HANDSHAKE_INVALID") !== enrollment.deviceId.toLowerCase()) fail5("RELAY_ID_MISMATCH");
|
|
45717
45957
|
const terminalMetrics2 = Array.isArray(frame.capabilities) && frame.capabilities.includes(TERMINAL_METRICS_CAPABILITY);
|
|
45718
45958
|
return { connectionEpoch: epoch3(frame.connectionEpoch), terminalMetrics: terminalMetrics2 };
|
|
45719
45959
|
}
|
|
45720
45960
|
function validateRequest(frame, enrollment, expectedProtocol, connectionEpoch) {
|
|
45721
45961
|
if (frame.type !== "relayFrame") fail5("RELAY_REQUEST_INVALID");
|
|
45722
45962
|
protocol(frame.protocolVersion, expectedProtocol);
|
|
45723
|
-
const tenantId =
|
|
45724
|
-
const deviceId =
|
|
45963
|
+
const tenantId = uuid20(frame.tenantId, "RELAY_REQUEST_INVALID");
|
|
45964
|
+
const deviceId = uuid20(frame.deviceId, "RELAY_REQUEST_INVALID");
|
|
45725
45965
|
if (tenantId !== enrollment.tenantId.toLowerCase() || deviceId !== enrollment.deviceId.toLowerCase()) fail5("RELAY_ID_MISMATCH");
|
|
45726
45966
|
if (epoch3(frame.connectionEpoch) !== connectionEpoch) fail5("RELAY_EPOCH_MISMATCH");
|
|
45727
45967
|
const kind = frame.kind;
|
|
45728
45968
|
if (typeof kind !== "string" || !REQUEST_KINDS.has(kind)) fail5("RELAY_REQUEST_INVALID");
|
|
45729
45969
|
return {
|
|
45730
|
-
requestId:
|
|
45970
|
+
requestId: uuid20(frame.requestId, "RELAY_REQUEST_INVALID"),
|
|
45731
45971
|
tenantId,
|
|
45732
45972
|
deviceId,
|
|
45733
45973
|
connectionEpoch,
|
|
45734
|
-
operationId:
|
|
45735
|
-
executionId:
|
|
45974
|
+
operationId: uuid20(frame.operationId, "RELAY_REQUEST_INVALID"),
|
|
45975
|
+
executionId: uuid20(frame.executionId, "RELAY_REQUEST_INVALID"),
|
|
45736
45976
|
kind,
|
|
45737
45977
|
payload: frame.payload,
|
|
45738
45978
|
deadlineAt: isoDate(frame.deadlineAt),
|
|
@@ -45774,8 +46014,8 @@ async function connectOnce(options) {
|
|
|
45774
46014
|
const identity = await options.store.load();
|
|
45775
46015
|
if (!identity || !identity.enrollment) fail5("ENROLLMENT_MISSING");
|
|
45776
46016
|
const enrollment = identity.enrollment;
|
|
45777
|
-
const tenantId =
|
|
45778
|
-
const deviceId =
|
|
46017
|
+
const tenantId = uuid20(enrollment.tenantId, "ENROLLMENT_INVALID");
|
|
46018
|
+
const deviceId = uuid20(enrollment.deviceId, "ENROLLMENT_INVALID");
|
|
45779
46019
|
const url2 = relayUrlFromEnrollment(enrollment);
|
|
45780
46020
|
const socket = new wrapper_default(url2, [], {
|
|
45781
46021
|
followRedirects: false,
|
|
@@ -46074,7 +46314,7 @@ import { createHash as createHash16 } from "node:crypto";
|
|
|
46074
46314
|
import os5 from "node:os";
|
|
46075
46315
|
import { open as open7 } from "node:fs/promises";
|
|
46076
46316
|
import { constants as constants8 } from "node:fs";
|
|
46077
|
-
import
|
|
46317
|
+
import path20 from "node:path";
|
|
46078
46318
|
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;
|
|
46079
46319
|
async function readMachineGuid(timeoutMs2 = 5e3) {
|
|
46080
46320
|
if (process.platform === "linux") {
|
|
@@ -46095,7 +46335,7 @@ async function readMachineGuid(timeoutMs2 = 5e3) {
|
|
|
46095
46335
|
}
|
|
46096
46336
|
}
|
|
46097
46337
|
if (!["win32", "darwin"].includes(process.platform)) return null;
|
|
46098
|
-
const reg = process.platform === "darwin" ? "/usr/sbin/ioreg" :
|
|
46338
|
+
const reg = process.platform === "darwin" ? "/usr/sbin/ioreg" : path20.join(process.env.SystemRoot || "C:\\Windows", "System32", "reg.exe");
|
|
46099
46339
|
const args = process.platform === "darwin" ? ["-rd1", "-c", "IOPlatformExpertDevice"] : ["query", "HKLM\\SOFTWARE\\Microsoft\\Cryptography", "/v", "MachineGuid", "/reg:64"];
|
|
46100
46340
|
const pattern = process.platform === "darwin" ? /"IOPlatformUUID"\s*=\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})"/ : MACHINE_GUID;
|
|
46101
46341
|
return new Promise((resolve) => {
|
|
@@ -46165,10 +46405,10 @@ function canonicalOrigin2(value) {
|
|
|
46165
46405
|
fail6("ORIGIN_INVALID");
|
|
46166
46406
|
}
|
|
46167
46407
|
}
|
|
46168
|
-
function endpoint(origin,
|
|
46169
|
-
return origin +
|
|
46408
|
+
function endpoint(origin, path29) {
|
|
46409
|
+
return origin + path29;
|
|
46170
46410
|
}
|
|
46171
|
-
function
|
|
46411
|
+
function uuid21(value, code) {
|
|
46172
46412
|
if (typeof value !== "string" || !UUID3.test(value)) fail6(code);
|
|
46173
46413
|
return value.toLowerCase();
|
|
46174
46414
|
}
|
|
@@ -46288,7 +46528,7 @@ var PairingClient = class {
|
|
|
46288
46528
|
publicKey: identity.publicKeyPem,
|
|
46289
46529
|
agentVersion: this.version
|
|
46290
46530
|
}));
|
|
46291
|
-
const pairingId =
|
|
46531
|
+
const pairingId = uuid21(response.pairingId, "PAIRING_RESPONSE_INVALID");
|
|
46292
46532
|
const expiresAt = parseDate(response.expiresAt, "PAIRING_RESPONSE_INVALID");
|
|
46293
46533
|
const now = this.nowMs();
|
|
46294
46534
|
if (expiresAt.getTime() <= now || expiresAt.getTime() - now > 30 * 6e4) fail6("PAIRING_RESPONSE_INVALID");
|
|
@@ -46322,7 +46562,7 @@ var PairingClient = class {
|
|
|
46322
46562
|
}
|
|
46323
46563
|
async completeOnce(beginResult, approved, displayNameValue) {
|
|
46324
46564
|
const pairing = this.validateBeginResult(beginResult);
|
|
46325
|
-
const tenantId =
|
|
46565
|
+
const tenantId = uuid21(approved.tenantId, "PAIRING_RESPONSE_INVALID");
|
|
46326
46566
|
const email3 = accountEmail(approved.accountEmail);
|
|
46327
46567
|
const name2 = displayName(displayNameValue);
|
|
46328
46568
|
const identity = await this.currentIdentity();
|
|
@@ -46336,15 +46576,15 @@ var PairingClient = class {
|
|
|
46336
46576
|
displayName: name2,
|
|
46337
46577
|
agentVersion: this.version
|
|
46338
46578
|
}));
|
|
46339
|
-
const completedTenant =
|
|
46579
|
+
const completedTenant = uuid21(response.tenantId, "PAIRING_RESPONSE_INVALID");
|
|
46340
46580
|
if (completedTenant !== tenantId) fail6("PAIRING_RESPONSE_INVALID");
|
|
46341
|
-
const deviceId =
|
|
46581
|
+
const deviceId = uuid21(response.deviceId, "PAIRING_RESPONSE_INVALID");
|
|
46342
46582
|
const enrollment = {
|
|
46343
46583
|
tenantId,
|
|
46344
46584
|
deviceId,
|
|
46345
46585
|
serverOrigin: this.origin,
|
|
46346
46586
|
accountEmail: email3,
|
|
46347
|
-
...response.accountId !== void 0 ? { accountId:
|
|
46587
|
+
...response.accountId !== void 0 ? { accountId: uuid21(response.accountId, "PAIRING_RESPONSE_INVALID") } : {}
|
|
46348
46588
|
};
|
|
46349
46589
|
await this.store.saveEnrollment(enrollment);
|
|
46350
46590
|
return { ...enrollment };
|
|
@@ -46358,7 +46598,7 @@ var PairingClient = class {
|
|
|
46358
46598
|
state: response.state,
|
|
46359
46599
|
expiresAt: parseDate(response.expiresAt, "PAIRING_RESPONSE_INVALID")
|
|
46360
46600
|
};
|
|
46361
|
-
if (response.tenantId !== void 0) result2.tenantId =
|
|
46601
|
+
if (response.tenantId !== void 0) result2.tenantId = uuid21(response.tenantId, "PAIRING_RESPONSE_INVALID");
|
|
46362
46602
|
if (response.accountEmail !== void 0) result2.accountEmail = accountEmail(response.accountEmail);
|
|
46363
46603
|
return result2;
|
|
46364
46604
|
}
|
|
@@ -46370,10 +46610,10 @@ var PairingClient = class {
|
|
|
46370
46610
|
}
|
|
46371
46611
|
validateBeginResult(value) {
|
|
46372
46612
|
return {
|
|
46373
|
-
pairingId:
|
|
46613
|
+
pairingId: uuid21(value.pairingId, "PAIRING_INVALID"),
|
|
46374
46614
|
pairingSecret: pairingSecret(value.pairingSecret),
|
|
46375
46615
|
confirmationCode: confirmationCode(value.confirmationCode),
|
|
46376
|
-
approvalUrl: approvalUrl(value.approvalUrl, this.origin,
|
|
46616
|
+
approvalUrl: approvalUrl(value.approvalUrl, this.origin, uuid21(value.pairingId, "PAIRING_INVALID")),
|
|
46377
46617
|
expiresAt: value.expiresAt instanceof Date ? new Date(value.expiresAt.getTime()) : parseDate(value.expiresAt, "PAIRING_INVALID"),
|
|
46378
46618
|
keyFingerprint: fingerprint2(value.keyFingerprint)
|
|
46379
46619
|
};
|
|
@@ -46668,15 +46908,15 @@ async function deliverGuardEvidence(target, packet, options = {}) {
|
|
|
46668
46908
|
|
|
46669
46909
|
// agent/src/optimization-ledger.ts
|
|
46670
46910
|
import { constants as constants9 } from "node:fs";
|
|
46671
|
-
import { lstat as lstat8, mkdir as mkdir8, open as open8, readFile as
|
|
46672
|
-
import
|
|
46911
|
+
import { lstat as lstat8, mkdir as mkdir8, open as open8, readFile as readFile8, realpath as realpath8 } from "node:fs/promises";
|
|
46912
|
+
import path21 from "node:path";
|
|
46673
46913
|
var MAX_LEDGER_BYTES = 64 * 1024 * 1024;
|
|
46674
46914
|
var MAX_NOTICE_LEDGER_BYTES = 8 * 1024 * 1024;
|
|
46675
46915
|
function failure5(code) {
|
|
46676
46916
|
return Object.assign(new Error(code), { code });
|
|
46677
46917
|
}
|
|
46678
46918
|
async function safeDirectory2(directory) {
|
|
46679
|
-
const absolute2 =
|
|
46919
|
+
const absolute2 = path21.resolve(directory);
|
|
46680
46920
|
let current2 = absolute2;
|
|
46681
46921
|
for (; ; ) {
|
|
46682
46922
|
try {
|
|
@@ -46684,7 +46924,7 @@ async function safeDirectory2(directory) {
|
|
|
46684
46924
|
} catch (error62) {
|
|
46685
46925
|
if (error62.code !== "ENOENT") throw error62;
|
|
46686
46926
|
}
|
|
46687
|
-
const parent =
|
|
46927
|
+
const parent = path21.dirname(current2);
|
|
46688
46928
|
if (parent === current2) break;
|
|
46689
46929
|
current2 = parent;
|
|
46690
46930
|
}
|
|
@@ -46719,15 +46959,15 @@ var OptimizationLedger = class _OptimizationLedger {
|
|
|
46719
46959
|
closed = false;
|
|
46720
46960
|
static async open(directory) {
|
|
46721
46961
|
const dir = await safeDirectory2(directory);
|
|
46722
|
-
const filename =
|
|
46723
|
-
const noticesFilename =
|
|
46962
|
+
const filename = path21.join(dir, "live-efficiency.v1.jsonl");
|
|
46963
|
+
const noticesFilename = path21.join(dir, "live-efficiency-notices.v1.jsonl");
|
|
46724
46964
|
let existing = "";
|
|
46725
46965
|
try {
|
|
46726
46966
|
const stat2 = await lstat8(filename);
|
|
46727
46967
|
if (!stat2.isFile() || stat2.isSymbolicLink() || stat2.size > MAX_LEDGER_BYTES) {
|
|
46728
46968
|
throw failure5("OPTIMIZATION_LEDGER_INVALID");
|
|
46729
46969
|
}
|
|
46730
|
-
existing = await
|
|
46970
|
+
existing = await readFile8(filename, "utf8");
|
|
46731
46971
|
} catch (error62) {
|
|
46732
46972
|
if (error62.code !== "ENOENT") throw error62;
|
|
46733
46973
|
}
|
|
@@ -46741,7 +46981,7 @@ var OptimizationLedger = class _OptimizationLedger {
|
|
|
46741
46981
|
try {
|
|
46742
46982
|
const noticeStat = await lstat8(noticesFilename);
|
|
46743
46983
|
if (!noticeStat.isFile() || noticeStat.isSymbolicLink() || noticeStat.size > MAX_NOTICE_LEDGER_BYTES) throw failure5("OPTIMIZATION_NOTICE_LEDGER_INVALID");
|
|
46744
|
-
const notices = await
|
|
46984
|
+
const notices = await readFile8(noticesFilename, "utf8");
|
|
46745
46985
|
for (const line of notices.split("\n")) {
|
|
46746
46986
|
if (!line) continue;
|
|
46747
46987
|
const parsed = JSON.parse(line);
|
|
@@ -46870,7 +47110,7 @@ var OptimizationLedger = class _OptimizationLedger {
|
|
|
46870
47110
|
// agent/src/monitor.ts
|
|
46871
47111
|
import { createHash as createHash17, randomUUID as randomUUID12 } from "node:crypto";
|
|
46872
47112
|
import { lstat as lstat9, mkdir as mkdir9, open as open9, rename as rename6, rm as rm7 } from "node:fs/promises";
|
|
46873
|
-
import
|
|
47113
|
+
import path22 from "node:path";
|
|
46874
47114
|
import os6 from "node:os";
|
|
46875
47115
|
|
|
46876
47116
|
// packages/agent-cli/bin/monitor-savings.mjs
|
|
@@ -46893,7 +47133,7 @@ function lifetimeSavingsView(raw) {
|
|
|
46893
47133
|
// agent/src/monitor.ts
|
|
46894
47134
|
function commandSummary2(tool) {
|
|
46895
47135
|
if (tool.name !== "command_run") return { name: tool.name, command: tool.name };
|
|
46896
|
-
const candidate =
|
|
47136
|
+
const candidate = path22.win32.basename(tool.args.command).replace(/\.(exe|cmd|bat|com)$/i, "").toLowerCase();
|
|
46897
47137
|
const name2 = ["node", "npm", "npx", "git", "rg", "powershell", "pwsh", "cmd", "tsc", "python", "dotnet"].includes(candidate) ? candidate : "command";
|
|
46898
47138
|
let command = name2;
|
|
46899
47139
|
if (name2 === "node" && tool.args.args.includes("--test") && !tool.args.args.some((arg) => ["-e", "--eval", "-p", "--print"].includes(arg))) command += " --test";
|
|
@@ -46906,9 +47146,9 @@ function commandSummary2(tool) {
|
|
|
46906
47146
|
var ProductionMonitor = class {
|
|
46907
47147
|
constructor(directory, stateDirectory, agentVersion3) {
|
|
46908
47148
|
this.agentVersion = agentVersion3;
|
|
46909
|
-
const key = createHash17("sha256").update(
|
|
46910
|
-
this.file =
|
|
46911
|
-
this.transportFile =
|
|
47149
|
+
const key = createHash17("sha256").update(path22.resolve(stateDirectory).toLowerCase()).digest("hex");
|
|
47150
|
+
this.file = path22.join(directory, key + ".json");
|
|
47151
|
+
this.transportFile = path22.join(directory, key + ".transport");
|
|
46912
47152
|
}
|
|
46913
47153
|
agentVersion;
|
|
46914
47154
|
instanceId = randomUUID12();
|
|
@@ -47100,7 +47340,7 @@ var ProductionMonitor = class {
|
|
|
47100
47340
|
schemaVersion: 1,
|
|
47101
47341
|
instanceId: this.instanceId,
|
|
47102
47342
|
pid: process.pid,
|
|
47103
|
-
savingsSourceId:
|
|
47343
|
+
savingsSourceId: path22.basename(this.file, ".json"),
|
|
47104
47344
|
lifetimeSavings: this.lifetimeSavings && { ...this.lifetimeSavings },
|
|
47105
47345
|
computer: this.computer,
|
|
47106
47346
|
processName: "lc-agent",
|
|
@@ -47134,7 +47374,7 @@ var ProductionMonitor = class {
|
|
|
47134
47374
|
return this.writing;
|
|
47135
47375
|
}
|
|
47136
47376
|
async write(file2, contents) {
|
|
47137
|
-
const directory =
|
|
47377
|
+
const directory = path22.dirname(file2);
|
|
47138
47378
|
await mkdir9(directory, { recursive: true, mode: 448 });
|
|
47139
47379
|
const stat2 = await lstat9(directory);
|
|
47140
47380
|
if (!stat2.isDirectory() || stat2.isSymbolicLink()) throw Error("MONITOR_DIRECTORY_INVALID");
|
|
@@ -47440,7 +47680,7 @@ var NativeEventSupervisor = class {
|
|
|
47440
47680
|
};
|
|
47441
47681
|
|
|
47442
47682
|
// agent/src/native-fabric-observer.ts
|
|
47443
|
-
var
|
|
47683
|
+
var uuid22 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
47444
47684
|
var NativeFabricObserver = class {
|
|
47445
47685
|
constructor(supervisor, source) {
|
|
47446
47686
|
this.supervisor = supervisor;
|
|
@@ -47462,7 +47702,7 @@ var NativeFabricObserver = class {
|
|
|
47462
47702
|
unsubscribe;
|
|
47463
47703
|
connected(authenticatedDeviceId) {
|
|
47464
47704
|
this.disconnected();
|
|
47465
|
-
if (
|
|
47705
|
+
if (uuid22.test(authenticatedDeviceId)) this.deviceId = authenticatedDeviceId.toLowerCase();
|
|
47466
47706
|
this.activity();
|
|
47467
47707
|
}
|
|
47468
47708
|
disconnected() {
|
|
@@ -47497,17 +47737,17 @@ var NativeFabricObserver = class {
|
|
|
47497
47737
|
void Promise.resolve().then(() => this.source.mailbox.snapshot()).then((state) => {
|
|
47498
47738
|
if (this.closed || expired || generation !== this.generation) return;
|
|
47499
47739
|
if (state.workers.length > 64 || state.assignments.length > 256 || state.messages.length > 1024) throw Error("FABRIC_BOUND_INVALID");
|
|
47500
|
-
const workers = new Set(state.workers.filter((w) => w.device?.deviceId.toLowerCase() === deviceId &&
|
|
47740
|
+
const workers = new Set(state.workers.filter((w) => w.device?.deviceId.toLowerCase() === deviceId && uuid22.test(w.workerId)).map((w) => w.workerId));
|
|
47501
47741
|
const assignments = new Map(state.assignments.filter((a) => workers.has(a.workerId)).map((a) => [a.assignmentId, a]));
|
|
47502
47742
|
const refs = /* @__PURE__ */ new Map();
|
|
47503
47743
|
for (const a of assignments.values()) {
|
|
47504
47744
|
const id2 = a.execution?.executionId;
|
|
47505
|
-
if (!id2 || !
|
|
47745
|
+
if (!id2 || !uuid22.test(id2)) continue;
|
|
47506
47746
|
if (refs.has(id2.toLowerCase())) throw Error("FABRIC_EXECUTION_CONFLICT");
|
|
47507
47747
|
refs.set(id2.toLowerCase(), {
|
|
47508
47748
|
executionId: id2.toLowerCase(),
|
|
47509
47749
|
workerId: a.workerId.toLowerCase(),
|
|
47510
|
-
...
|
|
47750
|
+
...uuid22.test(a.taskId) ? { taskId: a.taskId.toLowerCase() } : {}
|
|
47511
47751
|
});
|
|
47512
47752
|
}
|
|
47513
47753
|
this.referencesByExecution.clear();
|
|
@@ -47559,13 +47799,13 @@ var NativeFabricObserver = class {
|
|
|
47559
47799
|
};
|
|
47560
47800
|
|
|
47561
47801
|
// agent/src/native-fabric-startup.ts
|
|
47562
|
-
import { lstat as lstat11, mkdir as mkdir12, open as open11, readFile as
|
|
47563
|
-
import
|
|
47802
|
+
import { lstat as lstat11, mkdir as mkdir12, open as open11, readFile as readFile9 } from "node:fs/promises";
|
|
47803
|
+
import path25 from "node:path";
|
|
47564
47804
|
|
|
47565
47805
|
// src/agent-fabric-service.ts
|
|
47566
47806
|
import { lstat as lstat10, mkdir as mkdir11, realpath as realpath9 } from "node:fs/promises";
|
|
47567
47807
|
import { watch } from "node:fs";
|
|
47568
|
-
import
|
|
47808
|
+
import path24 from "node:path";
|
|
47569
47809
|
|
|
47570
47810
|
// src/agent-runtime-identity.ts
|
|
47571
47811
|
import { createHash as createHash19, randomBytes as randomBytes7, randomUUID as randomUUID14, timingSafeEqual as timingSafeEqual4 } from "node:crypto";
|
|
@@ -47573,13 +47813,13 @@ import { createHash as createHash19, randomBytes as randomBytes7, randomUUID as
|
|
|
47573
47813
|
// src/agent-fabric-state.ts
|
|
47574
47814
|
import { randomUUID as randomUUID13 } from "node:crypto";
|
|
47575
47815
|
import { mkdir as mkdir10, open as open10, rename as rename7, unlink as unlink2 } from "node:fs/promises";
|
|
47576
|
-
import
|
|
47816
|
+
import path23 from "node:path";
|
|
47577
47817
|
var queues = /* @__PURE__ */ new Map();
|
|
47578
47818
|
var FabricStateFile = class {
|
|
47579
47819
|
constructor(file2, maxBytes, parse3) {
|
|
47580
47820
|
this.maxBytes = maxBytes;
|
|
47581
47821
|
this.parse = parse3;
|
|
47582
|
-
this.file =
|
|
47822
|
+
this.file = path23.resolve(file2);
|
|
47583
47823
|
}
|
|
47584
47824
|
maxBytes;
|
|
47585
47825
|
parse;
|
|
@@ -47623,7 +47863,7 @@ var FabricStateFile = class {
|
|
|
47623
47863
|
}
|
|
47624
47864
|
update(fn, create) {
|
|
47625
47865
|
return this.serial(async () => {
|
|
47626
|
-
if (create) await mkdir10(
|
|
47866
|
+
if (create) await mkdir10(path23.dirname(this.file), { recursive: true });
|
|
47627
47867
|
const lockPath = this.file + ".lock";
|
|
47628
47868
|
const token = randomUUID13();
|
|
47629
47869
|
const lock = await open10(lockPath, "wx", 384).catch((error62) => {
|
|
@@ -48267,9 +48507,9 @@ var WorkerRequest = external_exports.discriminatedUnion("operation", [
|
|
|
48267
48507
|
var AgentFabricService = class _AgentFabricService {
|
|
48268
48508
|
constructor(directory, controllerId) {
|
|
48269
48509
|
this.directory = directory;
|
|
48270
|
-
this.identities = new AgentRuntimeIdentityStore(
|
|
48510
|
+
this.identities = new AgentRuntimeIdentityStore(path24.join(directory, "identities.json"));
|
|
48271
48511
|
this.mailbox = new AgentWorkerMailbox(
|
|
48272
|
-
|
|
48512
|
+
path24.join(directory, "mailbox.json"),
|
|
48273
48513
|
controllerId,
|
|
48274
48514
|
this.identities,
|
|
48275
48515
|
void 0,
|
|
@@ -48284,21 +48524,21 @@ var AgentFabricService = class _AgentFabricService {
|
|
|
48284
48524
|
closed = false;
|
|
48285
48525
|
static async open(directory, controllerId, device = null, initialize = true) {
|
|
48286
48526
|
const expected = Binding.parse({ version: 1, controllerId, device, initialized: false });
|
|
48287
|
-
const absolute2 =
|
|
48288
|
-
for (let current2 = absolute2; ; current2 =
|
|
48527
|
+
const absolute2 = path24.resolve(directory);
|
|
48528
|
+
for (let current2 = absolute2; ; current2 = path24.dirname(current2)) {
|
|
48289
48529
|
try {
|
|
48290
48530
|
if ((await lstat10(current2)).isSymbolicLink()) throw Error("FABRIC_DIRECTORY_INVALID");
|
|
48291
48531
|
} catch (error62) {
|
|
48292
48532
|
if (error62.code !== "ENOENT") throw error62;
|
|
48293
48533
|
}
|
|
48294
|
-
if (
|
|
48534
|
+
if (path24.dirname(current2) === current2) break;
|
|
48295
48535
|
}
|
|
48296
48536
|
if (initialize) await mkdir11(absolute2, { recursive: true, mode: 448 });
|
|
48297
48537
|
if (!(await lstat10(absolute2)).isDirectory() || (await realpath9(absolute2)).toLowerCase() !== absolute2.toLowerCase())
|
|
48298
48538
|
throw Error("FABRIC_DIRECTORY_INVALID");
|
|
48299
48539
|
const present = /* @__PURE__ */ new Set();
|
|
48300
48540
|
for (const name2 of ["binding.json", "mailbox.json", "identities.json"]) {
|
|
48301
|
-
const file2 = await lstat10(
|
|
48541
|
+
const file2 = await lstat10(path24.join(absolute2, name2)).catch((error62) => {
|
|
48302
48542
|
if (error62.code === "ENOENT") return null;
|
|
48303
48543
|
throw error62;
|
|
48304
48544
|
});
|
|
@@ -48306,7 +48546,7 @@ var AgentFabricService = class _AgentFabricService {
|
|
|
48306
48546
|
if (file2) present.add(name2);
|
|
48307
48547
|
}
|
|
48308
48548
|
if (!present.has("binding.json") && present.size) throw Error("FABRIC_BINDING_MISSING");
|
|
48309
|
-
const binding2 = new FabricStateFile(
|
|
48549
|
+
const binding2 = new FabricStateFile(path24.join(absolute2, "binding.json"), 2048, (value) => Binding.parse(value));
|
|
48310
48550
|
const service2 = new _AgentFabricService(absolute2, controllerId);
|
|
48311
48551
|
await binding2.update(async (state) => {
|
|
48312
48552
|
if (state.controllerId !== expected.controllerId || JSON.stringify(state.device) !== JSON.stringify(expected.device))
|
|
@@ -48321,7 +48561,7 @@ var AgentFabricService = class _AgentFabricService {
|
|
|
48321
48561
|
state.initialized = true;
|
|
48322
48562
|
}
|
|
48323
48563
|
const snapshot2 = await service2.mailbox.snapshot();
|
|
48324
|
-
if (snapshot2.workers.some((worker) => worker.runtimeId !== null)) await lstat10(
|
|
48564
|
+
if (snapshot2.workers.some((worker) => worker.runtimeId !== null)) await lstat10(path24.join(absolute2, "identities.json"));
|
|
48325
48565
|
}, initialize ? () => expected : void 0);
|
|
48326
48566
|
return service2;
|
|
48327
48567
|
}
|
|
@@ -48408,7 +48648,7 @@ var Delivery = external_exports.strictObject({ capability: external_exports.stri
|
|
|
48408
48648
|
async function openNativeFabric(stateDirectory, enrollment, box, initialize = true) {
|
|
48409
48649
|
const controllerId = "device-" + external_exports.string().uuid().parse(enrollment.deviceId).toLowerCase();
|
|
48410
48650
|
const tenantId = external_exports.string().uuid().parse(enrollment.tenantId).toLowerCase();
|
|
48411
|
-
const parent =
|
|
48651
|
+
const parent = path25.join(stateDirectory, ".local-commander"), marker = path25.join(parent, "fabric-established.json");
|
|
48412
48652
|
try {
|
|
48413
48653
|
await mkdir12(parent, { mode: 448 });
|
|
48414
48654
|
} catch (error62) {
|
|
@@ -48420,7 +48660,7 @@ async function openNativeFabric(stateDirectory, enrollment, box, initialize = tr
|
|
|
48420
48660
|
let fresh = false;
|
|
48421
48661
|
try {
|
|
48422
48662
|
const info = await lstat11(marker);
|
|
48423
|
-
if (!info.isFile() || info.isSymbolicLink() || info.size > 2048 || await
|
|
48663
|
+
if (!info.isFile() || info.isSymbolicLink() || info.size > 2048 || await readFile9(marker, "utf8") !== expected)
|
|
48424
48664
|
throw Error("FABRIC_BINDING_CHANGED");
|
|
48425
48665
|
} catch (error62) {
|
|
48426
48666
|
if (error62.code !== "ENOENT" || !initialize) throw error62;
|
|
@@ -48434,13 +48674,13 @@ async function openNativeFabric(stateDirectory, enrollment, box, initialize = tr
|
|
|
48434
48674
|
fresh = true;
|
|
48435
48675
|
}
|
|
48436
48676
|
const service2 = await AgentFabricService.open(
|
|
48437
|
-
|
|
48677
|
+
path25.join(stateDirectory, ".local-commander", "fabric"),
|
|
48438
48678
|
controllerId,
|
|
48439
48679
|
{ deviceId: enrollment.deviceId.toLowerCase(), enrollmentEvidenceRef: "enrollment-" + tenantId },
|
|
48440
48680
|
fresh
|
|
48441
48681
|
);
|
|
48442
48682
|
const purpose = "native-fabric:" + tenantId + ":" + controllerId;
|
|
48443
|
-
const credentialFile = (workerId) =>
|
|
48683
|
+
const credentialFile = (workerId) => path25.join(service2.directory, external_exports.string().uuid().parse(workerId) + ".capability");
|
|
48444
48684
|
const decode4 = (value) => {
|
|
48445
48685
|
const credential = Credential.parse(JSON.parse(box.open(Buffer.from(value, "base64"), purpose).toString("utf8")));
|
|
48446
48686
|
if (credential.controllerId !== controllerId) throw Error("FABRIC_WORKER_DENIED");
|
|
@@ -48449,7 +48689,7 @@ async function openNativeFabric(stateDirectory, enrollment, box, initialize = tr
|
|
|
48449
48689
|
async function capability(workerId) {
|
|
48450
48690
|
const file2 = credentialFile(workerId), info = await lstat11(file2);
|
|
48451
48691
|
if (!info.isFile() || info.isSymbolicLink() || info.size > 4096) throw Error("FABRIC_CREDENTIAL_UNKNOWN");
|
|
48452
|
-
const encoded = await
|
|
48692
|
+
const encoded = await readFile9(file2, "utf8");
|
|
48453
48693
|
if (decode4(encoded).workerId !== workerId) throw Error("FABRIC_WORKER_DENIED");
|
|
48454
48694
|
return encoded;
|
|
48455
48695
|
}
|
|
@@ -48541,8 +48781,8 @@ async function readFabricRequest(input2 = process.stdin) {
|
|
|
48541
48781
|
|
|
48542
48782
|
// agent/src/supervisor-liveness.ts
|
|
48543
48783
|
import { spawn as spawn6 } from "node:child_process";
|
|
48544
|
-
import
|
|
48545
|
-
import { setTimeout as
|
|
48784
|
+
import path26 from "node:path";
|
|
48785
|
+
import { setTimeout as delay3 } from "node:timers/promises";
|
|
48546
48786
|
var ROW = /^"([^"]+)","(\d{1,10})"/;
|
|
48547
48787
|
function parseTasklist(output2, image) {
|
|
48548
48788
|
const pids = /* @__PURE__ */ new Set();
|
|
@@ -48556,7 +48796,7 @@ function parseTasklist(output2, image) {
|
|
|
48556
48796
|
}
|
|
48557
48797
|
function listProcesses(image, timeoutMs2 = 5e3) {
|
|
48558
48798
|
if (process.platform !== "win32" || !/^[A-Za-z0-9._-]{1,64}\.exe$/i.test(image)) return Promise.resolve(null);
|
|
48559
|
-
const tasklist =
|
|
48799
|
+
const tasklist = path26.join(process.env.SystemRoot || "C:\\Windows", "System32", "tasklist.exe");
|
|
48560
48800
|
return new Promise((resolve) => {
|
|
48561
48801
|
let output2 = "", settled = false;
|
|
48562
48802
|
const finish = (value) => {
|
|
@@ -48584,7 +48824,9 @@ function listProcesses(image, timeoutMs2 = 5e3) {
|
|
|
48584
48824
|
});
|
|
48585
48825
|
}
|
|
48586
48826
|
function supervisorLiveness(helperPath, options = {}) {
|
|
48587
|
-
|
|
48827
|
+
if (process.platform === "linux" && !options.list) return linuxSupervisorLiveness;
|
|
48828
|
+
if (process.platform === "darwin" && !options.list) return (pids, _linux, darwin) => darwinSupervisorLiveness(path26.join(path26.dirname(helperPath), "posix-host"), pids, darwin);
|
|
48829
|
+
const image = path26.basename(helperPath), waitMs = options.waitMs ?? 1e4, pollMs = options.pollMs ?? 500, list = options.list ?? listProcesses;
|
|
48588
48830
|
return async (pids) => {
|
|
48589
48831
|
const deadline = Date.now() + waitMs;
|
|
48590
48832
|
for (; ; ) {
|
|
@@ -48592,24 +48834,24 @@ function supervisorLiveness(helperPath, options = {}) {
|
|
|
48592
48834
|
if (!running) return null;
|
|
48593
48835
|
const live = new Set(pids.filter((pid) => running.has(pid)));
|
|
48594
48836
|
if (!live.size || Date.now() >= deadline) return live;
|
|
48595
|
-
await
|
|
48837
|
+
await delay3(pollMs);
|
|
48596
48838
|
}
|
|
48597
48839
|
};
|
|
48598
48840
|
}
|
|
48599
48841
|
|
|
48600
48842
|
// agent/src/content-audit.ts
|
|
48601
48843
|
import { createReadStream } from "node:fs";
|
|
48602
|
-
import { appendFile, lstat as lstat12, mkdir as mkdir13, open as open12, readdir as readdir5, readFile as
|
|
48603
|
-
import
|
|
48844
|
+
import { appendFile, lstat as lstat12, mkdir as mkdir13, open as open12, readdir as readdir5, readFile as readFile10, rename as rename8, rm as rm8, writeFile as writeFile4 } from "node:fs/promises";
|
|
48845
|
+
import path27 from "node:path";
|
|
48604
48846
|
import { performance as performance3 } from "node:perf_hooks";
|
|
48605
48847
|
import { createInterface as createInterface2 } from "node:readline";
|
|
48606
48848
|
import { randomBytes as randomBytes9 } from "node:crypto";
|
|
48607
48849
|
|
|
48608
48850
|
// src/audit-crypto.ts
|
|
48609
48851
|
import { createCipheriv as createCipheriv3, createDecipheriv as createDecipheriv3, createHash as createHash20, randomBytes as randomBytes8 } from "node:crypto";
|
|
48610
|
-
import { promisify } from "node:util";
|
|
48852
|
+
import { promisify as promisify3 } from "node:util";
|
|
48611
48853
|
import { gunzipSync, gzip, gzipSync } from "node:zlib";
|
|
48612
|
-
var gzipAsync =
|
|
48854
|
+
var gzipAsync = promisify3(gzip);
|
|
48613
48855
|
var AUDIT_ENCRYPTION_ALGORITHM = "A256GCM";
|
|
48614
48856
|
var AUDIT_COMPRESSION = "gzip";
|
|
48615
48857
|
var AUDIT_RECOVERY_KEY_PREFIX = "lca1_";
|
|
@@ -48769,7 +49011,7 @@ var FILE = /^(full|metrics)-(\d{4}-\d{2}-\d{2})\.jsonl$/;
|
|
|
48769
49011
|
var PAUSED_FILE = "paused.json";
|
|
48770
49012
|
var DAY_MS = 864e5;
|
|
48771
49013
|
function contentAuditDirectory(stateDir) {
|
|
48772
|
-
return
|
|
49014
|
+
return path27.join(path27.dirname(path27.resolve(stateDir)), "Audit");
|
|
48773
49015
|
}
|
|
48774
49016
|
async function plainDirectory(dir) {
|
|
48775
49017
|
await mkdir13(dir, { recursive: true, mode: 448 });
|
|
@@ -48788,7 +49030,7 @@ async function auditFiles(dir) {
|
|
|
48788
49030
|
for (const name2 of names) {
|
|
48789
49031
|
const match = FILE.exec(name2);
|
|
48790
49032
|
if (!match) continue;
|
|
48791
|
-
const info = await lstat12(
|
|
49033
|
+
const info = await lstat12(path27.join(dir, name2));
|
|
48792
49034
|
if (info.isFile()) files.push({ name: name2, kind: match[1], day: match[2], bytes: info.size });
|
|
48793
49035
|
}
|
|
48794
49036
|
return files.sort((a, b) => a.name.localeCompare(b.name));
|
|
@@ -48826,7 +49068,7 @@ var ContentAudit = class _ContentAudit {
|
|
|
48826
49068
|
skipped = 0;
|
|
48827
49069
|
closed = false;
|
|
48828
49070
|
static async open(options) {
|
|
48829
|
-
const dir =
|
|
49071
|
+
const dir = path27.resolve(options.directory);
|
|
48830
49072
|
await plainDirectory(dir);
|
|
48831
49073
|
const audit = new _ContentAudit(
|
|
48832
49074
|
dir,
|
|
@@ -48835,7 +49077,7 @@ var ContentAudit = class _ContentAudit {
|
|
|
48835
49077
|
{ retentionDays: options.retentionDays ?? AUDIT_RETENTION_DAYS, maxBytes: options.maxBytes ?? AUDIT_MAX_BYTES },
|
|
48836
49078
|
options.now ?? (() => /* @__PURE__ */ new Date())
|
|
48837
49079
|
);
|
|
48838
|
-
await rm8(
|
|
49080
|
+
await rm8(path27.join(dir, PAUSED_FILE), { force: true });
|
|
48839
49081
|
await audit.rollover(audit.now());
|
|
48840
49082
|
if (audit.usedBytes >= audit.limits.maxBytes) await audit.pause("QUOTA_EXCEEDED");
|
|
48841
49083
|
return audit;
|
|
@@ -48905,8 +49147,8 @@ var ContentAudit = class _ContentAudit {
|
|
|
48905
49147
|
await this.pause("QUOTA_EXCEEDED");
|
|
48906
49148
|
return;
|
|
48907
49149
|
}
|
|
48908
|
-
await appendFile(
|
|
48909
|
-
await appendFile(
|
|
49150
|
+
await appendFile(path27.join(this.dir, `full-${day}.jsonl`), line, { mode: 384 });
|
|
49151
|
+
await appendFile(path27.join(this.dir, `metrics-${day}.jsonl`), metrics, { mode: 384 });
|
|
48910
49152
|
this.usedBytes += bytes3;
|
|
48911
49153
|
}
|
|
48912
49154
|
/** Daily retention runs on the first write of a new day; no timer or background scan. */
|
|
@@ -48915,7 +49157,7 @@ var ContentAudit = class _ContentAudit {
|
|
|
48915
49157
|
const cutoff = new Date(at.getTime() - this.limits.retentionDays * DAY_MS).toISOString().slice(0, 10);
|
|
48916
49158
|
let used = 0;
|
|
48917
49159
|
for (const file2 of await auditFiles(this.dir)) {
|
|
48918
|
-
if (file2.day <= cutoff) await rm8(
|
|
49160
|
+
if (file2.day <= cutoff) await rm8(path27.join(this.dir, file2.name), { force: true });
|
|
48919
49161
|
else used += file2.bytes;
|
|
48920
49162
|
}
|
|
48921
49163
|
this.usedBytes = used;
|
|
@@ -48923,7 +49165,7 @@ var ContentAudit = class _ContentAudit {
|
|
|
48923
49165
|
async pause(reason) {
|
|
48924
49166
|
if (this.paused) return;
|
|
48925
49167
|
this.paused = reason;
|
|
48926
|
-
await writeJsonAtomic(
|
|
49168
|
+
await writeJsonAtomic(path27.join(this.dir, PAUSED_FILE), { reason, at: this.now().toISOString() });
|
|
48927
49169
|
}
|
|
48928
49170
|
};
|
|
48929
49171
|
function percentiles(values) {
|
|
@@ -48945,13 +49187,13 @@ async function* jsonLines(file2) {
|
|
|
48945
49187
|
}
|
|
48946
49188
|
var count2 = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
|
|
48947
49189
|
async function summarizeContentAudit(directory, key) {
|
|
48948
|
-
const dir =
|
|
49190
|
+
const dir = path27.resolve(directory);
|
|
48949
49191
|
const files = await auditFiles(dir);
|
|
48950
49192
|
const days = /* @__PURE__ */ new Map();
|
|
48951
49193
|
const sizes = [];
|
|
48952
49194
|
const timings = [];
|
|
48953
49195
|
for (const file2 of files.filter((f) => f.kind === "metrics")) {
|
|
48954
|
-
for await (const line of jsonLines(
|
|
49196
|
+
for await (const line of jsonLines(path27.join(dir, file2.name))) {
|
|
48955
49197
|
let day = days.get(file2.day);
|
|
48956
49198
|
if (!day) {
|
|
48957
49199
|
day = { day: file2.day, records: 0, failed: 0, rawBytes: 0, sanitizedBytes: 0, compressedBytes: 0, envelopeBytes: 0 };
|
|
@@ -48971,7 +49213,7 @@ async function summarizeContentAudit(directory, key) {
|
|
|
48971
49213
|
}
|
|
48972
49214
|
let paused = null;
|
|
48973
49215
|
try {
|
|
48974
|
-
const value = JSON.parse(await
|
|
49216
|
+
const value = JSON.parse(await readFile10(path27.join(dir, PAUSED_FILE), "utf8"));
|
|
48975
49217
|
if (typeof value.reason === "string" && typeof value.at === "string") paused = { reason: value.reason.slice(0, 40), at: value.at.slice(0, 40) };
|
|
48976
49218
|
} catch {
|
|
48977
49219
|
}
|
|
@@ -48979,7 +49221,7 @@ async function summarizeContentAudit(directory, key) {
|
|
|
48979
49221
|
const newest = files.filter((f) => f.kind === "full").at(-1);
|
|
48980
49222
|
if (key && newest) {
|
|
48981
49223
|
const tail = [];
|
|
48982
|
-
for await (const line of jsonLines(
|
|
49224
|
+
for await (const line of jsonLines(path27.join(dir, newest.name))) {
|
|
48983
49225
|
tail.push(line);
|
|
48984
49226
|
if (tail.length > 5) tail.shift();
|
|
48985
49227
|
}
|
|
@@ -49013,10 +49255,10 @@ async function summarizeContentAudit(directory, key) {
|
|
|
49013
49255
|
};
|
|
49014
49256
|
}
|
|
49015
49257
|
async function restoreContentAudit(input2, output2, key) {
|
|
49016
|
-
const handle = await open12(
|
|
49258
|
+
const handle = await open12(path27.resolve(output2), "wx", 384);
|
|
49017
49259
|
let records = 0, failed = 0;
|
|
49018
49260
|
try {
|
|
49019
|
-
for await (const line of jsonLines(
|
|
49261
|
+
for await (const line of jsonLines(path27.resolve(input2))) {
|
|
49020
49262
|
try {
|
|
49021
49263
|
await handle.appendFile(JSON.stringify(decryptAuditRecord(line, key)) + "\n");
|
|
49022
49264
|
records += 1;
|
|
@@ -49031,7 +49273,7 @@ async function restoreContentAudit(input2, output2, key) {
|
|
|
49031
49273
|
}
|
|
49032
49274
|
|
|
49033
49275
|
// agent/src/main.ts
|
|
49034
|
-
var AGENT_VERSION2 = true ? "0.3.
|
|
49276
|
+
var AGENT_VERSION2 = true ? "0.3.43" : "0.3.2";
|
|
49035
49277
|
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" : "";
|
|
49036
49278
|
var AI_CONNECTION_SHIPPED = false;
|
|
49037
49279
|
function processAlive(pid) {
|
|
@@ -49045,7 +49287,7 @@ function processAlive(pid) {
|
|
|
49045
49287
|
}
|
|
49046
49288
|
async function claimAgentProcess(stateDir, runtimeDir, version2) {
|
|
49047
49289
|
await mkdir14(stateDir, { recursive: true });
|
|
49048
|
-
const file2 =
|
|
49290
|
+
const file2 = path28.join(stateDir, "agent-process.json");
|
|
49049
49291
|
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
49050
49292
|
try {
|
|
49051
49293
|
const handle = await open13(file2, "wx", 384);
|
|
@@ -49056,7 +49298,7 @@ async function claimAgentProcess(stateDir, runtimeDir, version2) {
|
|
|
49056
49298
|
}
|
|
49057
49299
|
return async () => {
|
|
49058
49300
|
try {
|
|
49059
|
-
const current2 = JSON.parse(await
|
|
49301
|
+
const current2 = JSON.parse(await readFile11(file2, "utf8"));
|
|
49060
49302
|
if (current2.pid === process.pid) await rm9(file2, { force: true });
|
|
49061
49303
|
} catch {
|
|
49062
49304
|
}
|
|
@@ -49065,7 +49307,7 @@ async function claimAgentProcess(stateDir, runtimeDir, version2) {
|
|
|
49065
49307
|
if (!error62 || typeof error62 !== "object" || !("code" in error62) || error62.code !== "EEXIST") throw error62;
|
|
49066
49308
|
let stale = true;
|
|
49067
49309
|
try {
|
|
49068
|
-
const current2 = JSON.parse(await
|
|
49310
|
+
const current2 = JSON.parse(await readFile11(file2, "utf8"));
|
|
49069
49311
|
stale = typeof current2.pid !== "number" || !processAlive(current2.pid);
|
|
49070
49312
|
} catch {
|
|
49071
49313
|
}
|
|
@@ -49088,7 +49330,7 @@ function aborted2(signal, ms) {
|
|
|
49088
49330
|
});
|
|
49089
49331
|
}
|
|
49090
49332
|
async function runAgent(options) {
|
|
49091
|
-
const
|
|
49333
|
+
const delay4 = options.reconnectDelayMs ?? 2e3;
|
|
49092
49334
|
const monitor = (update) => {
|
|
49093
49335
|
try {
|
|
49094
49336
|
update();
|
|
@@ -49098,7 +49340,7 @@ async function runAgent(options) {
|
|
|
49098
49340
|
}
|
|
49099
49341
|
};
|
|
49100
49342
|
try {
|
|
49101
|
-
if (!Number.isInteger(
|
|
49343
|
+
if (!Number.isInteger(delay4) || delay4 < 0 || delay4 > 3e4) throw Error("RECONNECT_DELAY_INVALID");
|
|
49102
49344
|
const identity = await options.store.load();
|
|
49103
49345
|
if (!identity?.enrollment) throw Error("ENROLLMENT_MISSING");
|
|
49104
49346
|
const origin = identity.enrollment.serverOrigin;
|
|
@@ -49278,7 +49520,7 @@ async function runAgent(options) {
|
|
|
49278
49520
|
await bridge.disconnected();
|
|
49279
49521
|
connection = null;
|
|
49280
49522
|
}
|
|
49281
|
-
if (!options.signal.aborted) await aborted2(options.signal,
|
|
49523
|
+
if (!options.signal.aborted) await aborted2(options.signal, delay4);
|
|
49282
49524
|
}
|
|
49283
49525
|
} finally {
|
|
49284
49526
|
try {
|
|
@@ -49314,10 +49556,10 @@ async function openContentAudit(store, stateDir) {
|
|
|
49314
49556
|
async function main() {
|
|
49315
49557
|
if (!["win32", "linux", "darwin"].includes(process.platform)) throw Error("PLATFORM_UNSUPPORTED");
|
|
49316
49558
|
const appData = process.env.LC_AGENT_DATA_DIR ?? (process.platform === "win32" ? process.env.LOCALAPPDATA : posixDataHome());
|
|
49317
|
-
if (!appData || !
|
|
49318
|
-
const stateDir = process.env.LC_AGENT_STATE_DIR ??
|
|
49319
|
-
const binaryDir =
|
|
49320
|
-
const ownerBridgePath = process.env.LC_OWNER_BRIDGE ??
|
|
49559
|
+
if (!appData || !path28.isAbsolute(appData)) throw Error("APP_DATA_MISSING");
|
|
49560
|
+
const stateDir = process.env.LC_AGENT_STATE_DIR ?? path28.join(appData, "LocalCommander", "Agent");
|
|
49561
|
+
const binaryDir = path28.dirname(process.platform === "win32" ? process.execPath : await realpath10(process.execPath));
|
|
49562
|
+
const ownerBridgePath = process.env.LC_OWNER_BRIDGE ?? path28.join(binaryDir, process.platform === "win32" ? "OwnerBridge.exe" : "owner-store");
|
|
49321
49563
|
const store = await WindowsPrivateStore.open(stateDir, ownerBridgePath);
|
|
49322
49564
|
const command = process.argv[2] ?? "run";
|
|
49323
49565
|
if (process.platform !== "win32" && (command.startsWith("guard-") || command.startsWith("network-"))) throw Error("FEATURE_PLATFORM_UNSUPPORTED");
|
|
@@ -49412,7 +49654,7 @@ async function main() {
|
|
|
49412
49654
|
}
|
|
49413
49655
|
if (command === "efficiency-report") {
|
|
49414
49656
|
if (args.length) throw Error("AGENT_COMMAND_INVALID");
|
|
49415
|
-
const ledger = await OptimizationLedger.open(
|
|
49657
|
+
const ledger = await OptimizationLedger.open(path28.join(stateDir, "optimization"));
|
|
49416
49658
|
try {
|
|
49417
49659
|
process.stdout.write(JSON.stringify(await ledger.report(), null, 2) + "\n");
|
|
49418
49660
|
} finally {
|
|
@@ -49422,7 +49664,7 @@ async function main() {
|
|
|
49422
49664
|
}
|
|
49423
49665
|
if (command === "guard-configure") {
|
|
49424
49666
|
if (args.length !== 1) throw Error("AGENT_COMMAND_INVALID");
|
|
49425
|
-
const filename = await (await import("node:fs/promises")).realpath(
|
|
49667
|
+
const filename = await (await import("node:fs/promises")).realpath(path28.resolve(args[0]));
|
|
49426
49668
|
const input2 = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(await readWindowsFile(ownerBridgePath, filename, 2e5)));
|
|
49427
49669
|
if (!input2 || typeof input2 !== "object" || Object.keys(input2).sort().join(",") !== "compact,settings") throw Error("GUARD_CONFIGURATION_INVALID");
|
|
49428
49670
|
await store.configureGuard(input2.settings, input2.compact);
|
|
@@ -49441,7 +49683,7 @@ async function main() {
|
|
|
49441
49683
|
}
|
|
49442
49684
|
if (command === "guard-evidence") {
|
|
49443
49685
|
if (args.length) throw Error("AGENT_COMMAND_INVALID");
|
|
49444
|
-
const journal = await NativeJournal.open(
|
|
49686
|
+
const journal = await NativeJournal.open(path28.join(stateDir, "journal"), new SecretBox({ "1": await store.loadDataKey() }));
|
|
49445
49687
|
try {
|
|
49446
49688
|
process.stdout.write(JSON.stringify(await journal.guardEvidence()) + "\n");
|
|
49447
49689
|
} finally {
|
|
@@ -49453,7 +49695,7 @@ async function main() {
|
|
|
49453
49695
|
if (args.length !== (command === "guard-export" ? 0 : 1)) throw Error("AGENT_COMMAND_INVALID");
|
|
49454
49696
|
const identity = await store.load();
|
|
49455
49697
|
if (!identity?.enrollment) throw Error("ENROLLMENT_MISSING");
|
|
49456
|
-
const journal = await NativeJournal.open(
|
|
49698
|
+
const journal = await NativeJournal.open(path28.join(stateDir, "journal"), new SecretBox({ "1": await store.loadDataKey() }));
|
|
49457
49699
|
try {
|
|
49458
49700
|
const { tenantId, deviceId } = identity.enrollment;
|
|
49459
49701
|
const records = (await journal.guardEvidence()).filter((record2) => record2.tenantId === tenantId && record2.deviceId === deviceId);
|
|
@@ -49531,27 +49773,27 @@ async function main() {
|
|
|
49531
49773
|
if (args.length) throw Error("AGENT_COMMAND_INVALID");
|
|
49532
49774
|
if (!(await store.load())?.enrollment) throw Error("ENROLLMENT_MISSING");
|
|
49533
49775
|
const releaseProcess = await claimAgentProcess(stateDir, binaryDir, AGENT_VERSION2);
|
|
49534
|
-
const monitor = new ProductionMonitor(
|
|
49776
|
+
const monitor = new ProductionMonitor(path28.join(appData, "LocalCommander", "Monitor"), stateDir, AGENT_VERSION2);
|
|
49535
49777
|
const publishMonitor = () => monitor.flush().catch(() => {
|
|
49536
49778
|
process.stderr.write("MONITOR_WRITE_FAILED\n");
|
|
49537
49779
|
});
|
|
49538
49780
|
await publishMonitor();
|
|
49539
49781
|
try {
|
|
49540
49782
|
const journal = await NativeJournal.open(
|
|
49541
|
-
|
|
49783
|
+
path28.join(stateDir, "journal"),
|
|
49542
49784
|
new SecretBox({ "1": await store.loadDataKey() }),
|
|
49543
|
-
process.platform === "win32" ? {} : { lockHelper:
|
|
49785
|
+
process.platform === "win32" ? {} : { lockHelper: path28.join(binaryDir, "posix-host") }
|
|
49544
49786
|
);
|
|
49545
49787
|
const ledgerLoss = () => {
|
|
49546
49788
|
process.stderr.write("OPTIMIZATION_TELEMETRY_INCOMPLETE\n");
|
|
49547
49789
|
};
|
|
49548
49790
|
const efficiencyLedger = await new OptionalWork(ledgerLoss, 1e3, 1).run(
|
|
49549
|
-
() => OptimizationLedger.open(
|
|
49791
|
+
() => OptimizationLedger.open(path28.join(stateDir, "optimization")),
|
|
49550
49792
|
void 0,
|
|
49551
49793
|
(ledger) => ledger.close()
|
|
49552
49794
|
);
|
|
49553
49795
|
try {
|
|
49554
|
-
const helperPath = process.env.LC_JOB_HOST ??
|
|
49796
|
+
const helperPath = process.env.LC_JOB_HOST ?? path28.join(binaryDir, process.platform === "win32" ? "JobHost.exe" : "job-host.mjs");
|
|
49555
49797
|
const tools = new NativeTools({ stateDirectory: stateDir, helperPath, ownerBridgePath, programs: await store.loadPrograms() });
|
|
49556
49798
|
const stop = new AbortController();
|
|
49557
49799
|
process.once("SIGINT", () => stop.abort());
|
|
@@ -49622,7 +49864,7 @@ async function main() {
|
|
|
49622
49864
|
await releaseProcess();
|
|
49623
49865
|
}
|
|
49624
49866
|
}
|
|
49625
|
-
var entrypoint = process.argv[1] && (process.platform === "win32" ?
|
|
49867
|
+
var entrypoint = process.argv[1] && (process.platform === "win32" ? path28.resolve(process.argv[1]) : await realpath10(process.argv[1]).catch(() => null));
|
|
49626
49868
|
if (entrypoint === fileURLToPath(import.meta.url)) {
|
|
49627
49869
|
void main().catch((error62) => {
|
|
49628
49870
|
const code = error62 instanceof Error && /^[A-Z0-9_]{1,64}$/.test(error62.message) ? error62.message : "AGENT_START_FAILED";
|