@swmansion/argent 0.33.1-next.2 → 0.33.1-next.20
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/bin/argent-android-devtools-0.4.0.apk +0 -0
- package/bin/darwin/argent-macos-helper +0 -0
- package/bin/darwin/ax-service +0 -0
- package/bin/darwin/tvos-ax-service +0 -0
- package/bin/darwin/tvos-hid-daemon +0 -0
- package/bin/network-inspector/network-inspector.jar +0 -0
- package/bin/tcp/ax-service +0 -0
- package/dist/cli-cmds.mjs +267 -70
- package/dist/client.js +253 -56
- package/dist/flow-script-runner.mjs +148 -5
- package/dist/installer.mjs +52 -26
- package/dist/ios-device-runner/ArgentRunner/ArgentRunnerUITests/ArgentRunnerSession+Snapshot.swift +110 -4
- package/dist/mcp-server.mjs +257 -60
- package/dist/tool-args.generated.d.ts +3 -1
- package/dist/tool-server.cjs +1366 -697
- package/dylibs/libArgentInjectionBootstrap.dylib +0 -0
- package/dylibs/libKeyboardPatch.dylib +0 -0
- package/dylibs/libNativeDevtoolsIos.dylib +0 -0
- package/dylibs/macos/libArgentInjectionBootstrap.dylib +0 -0
- package/dylibs/macos/libNativeDevtoolsMacos.dylib +0 -0
- package/dylibs/tcp/libArgentInjectionBootstrap.dylib +0 -0
- package/dylibs/tcp/libKeyboardPatch.dylib +0 -0
- package/dylibs/tcp/libNativeDevtoolsIos.dylib +0 -0
- package/dylibs/tvos/libArgentInjectionBootstrap.dylib +0 -0
- package/dylibs/tvos/libKeyboardPatch.dylib +0 -0
- package/dylibs/tvos/libNativeDevtoolsIos.dylib +0 -0
- package/package.json +2 -3
- package/skills/argent-create-e2e/references/e2e-yaml.md +11 -1
- package/skills/argent-create-e2e/references/reliability-and-recovery.md +1 -1
- package/skills/argent-device-interact/SKILL.md +1 -1
- package/skills/argent-device-interact/references/harmonyos.md +1 -1
- package/skills/argent-react-native-app-workflow/SKILL.md +1 -1
- package/skills/argent-test-ui-flow/SKILL.md +6 -8
- package/assets/trace-processor/SHA256SUMS +0 -4
- package/assets/trace-processor/engine.mjs +0 -42423
package/dist/client.js
CHANGED
|
@@ -8432,7 +8432,7 @@ function spawnToolsServer(paths, port, options = {}) {
|
|
|
8432
8432
|
"error",
|
|
8433
8433
|
(err) => reject(
|
|
8434
8434
|
new Error(
|
|
8435
|
-
err.code === "ENOENT" && nodeBin === "node" ? "Could not start the argent tool-server: `node` was not found on PATH. Install Node.js
|
|
8435
|
+
err.code === "ENOENT" && nodeBin === "node" ? "Could not start the argent tool-server: `node` was not found on PATH. Install Node.js 22.18+ or add it to PATH." : `Could not start the argent tool-server: ${err.message}`
|
|
8436
8436
|
)
|
|
8437
8437
|
)
|
|
8438
8438
|
);
|
|
@@ -8780,7 +8780,10 @@ import { basename, extname } from "node:path";
|
|
|
8780
8780
|
var FLOW_NAME_CHARSET = "[A-Za-z0-9_-]+";
|
|
8781
8781
|
var FLOW_NAME_PATTERN = new RegExp(`^${FLOW_NAME_CHARSET}$`);
|
|
8782
8782
|
var FLOW_FILE_NAME_PATTERN = new RegExp(`^${FLOW_NAME_CHARSET}\\.yaml$`);
|
|
8783
|
-
var
|
|
8783
|
+
var SCRIPT_FILE_EXTENSIONS = [".mjs", ".mts", ".js", ".ts"];
|
|
8784
|
+
var SCRIPT_FILE_NAME_PATTERN = new RegExp(
|
|
8785
|
+
`^${FLOW_NAME_CHARSET}(?:${SCRIPT_FILE_EXTENSIONS.map((ext) => `\\${ext}`).join("|")})$`
|
|
8786
|
+
);
|
|
8784
8787
|
function interpolateFileInputPath(template, args) {
|
|
8785
8788
|
let missing = false;
|
|
8786
8789
|
const out = template.replace(/\$\{([A-Za-z0-9_]+)\}/g, (_m, name) => {
|
|
@@ -9300,6 +9303,8 @@ var FAILURE_CODES = {
|
|
|
9300
9303
|
FLOW_DEVICE_RESOLUTION: "FLOW_DEVICE_RESOLUTION",
|
|
9301
9304
|
// The target does not satisfy the test's `requires:` block; a directory run skips it.
|
|
9302
9305
|
FLOW_REQUIREMENTS_UNMET: "FLOW_REQUIREMENTS_UNMET",
|
|
9306
|
+
// The tool-server's Node.js cannot run a TypeScript `script:` step the test holds.
|
|
9307
|
+
FLOW_SCRIPT_TYPESCRIPT_UNSUPPORTED: "FLOW_SCRIPT_TYPESCRIPT_UNSUPPORTED",
|
|
9303
9308
|
PROFILER_QUERY_MODE_INVALID: "PROFILER_QUERY_MODE_INVALID",
|
|
9304
9309
|
PROFILER_QUERY_REQUIRED_PARAM_MISSING: "PROFILER_QUERY_REQUIRED_PARAM_MISSING",
|
|
9305
9310
|
PROFILER_DATA_NOT_LOADED: "PROFILER_DATA_NOT_LOADED",
|
|
@@ -9516,7 +9521,7 @@ async function getResolvedToolsUrl() {
|
|
|
9516
9521
|
|
|
9517
9522
|
// ../argent-tools-client/src/file-inputs.ts
|
|
9518
9523
|
import { createHash as createHash2, randomUUID as randomUUID4 } from "node:crypto";
|
|
9519
|
-
import { createReadStream, rmSync as rmSync2 } from "node:fs";
|
|
9524
|
+
import { createReadStream as createReadStream2, rmSync as rmSync2 } from "node:fs";
|
|
9520
9525
|
import {
|
|
9521
9526
|
chmod as chmod3,
|
|
9522
9527
|
lstat,
|
|
@@ -9532,50 +9537,234 @@ import { constants, tmpdir } from "node:os";
|
|
|
9532
9537
|
import * as path10 from "node:path";
|
|
9533
9538
|
|
|
9534
9539
|
// ../archive/src/index.ts
|
|
9535
|
-
import {
|
|
9536
|
-
import {
|
|
9537
|
-
import {
|
|
9538
|
-
import {
|
|
9539
|
-
|
|
9540
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
9541
|
+
import { once } from "node:events";
|
|
9542
|
+
import { createReadStream, createWriteStream } from "node:fs";
|
|
9543
|
+
import { open, rm, readdir as readdir3 } from "node:fs/promises";
|
|
9544
|
+
import { basename as basename4, dirname as dirname5, join as join9, resolve as resolve6, sep as sep2 } from "node:path";
|
|
9545
|
+
import { Writable } from "node:stream";
|
|
9546
|
+
import { pipeline } from "node:stream/promises";
|
|
9547
|
+
import zlib from "node:zlib";
|
|
9540
9548
|
var ArchiveError = class extends Error {
|
|
9541
9549
|
};
|
|
9542
|
-
function
|
|
9543
|
-
|
|
9550
|
+
var ARCHIVE_FORMATS = typeof zlib.createZstdCompress === "function" ? ["zstd", "gzip"] : ["gzip"];
|
|
9551
|
+
var ARCHIVE_CONTENT_TYPES = {
|
|
9552
|
+
zstd: "application/zstd",
|
|
9553
|
+
gzip: "application/gzip"
|
|
9554
|
+
};
|
|
9555
|
+
function pickArchiveFormat(peerFormats) {
|
|
9556
|
+
return ARCHIVE_FORMATS.find((f) => peerFormats?.includes(f)) ?? "gzip";
|
|
9557
|
+
}
|
|
9558
|
+
var CHUNK_BYTES = 1 << 20;
|
|
9559
|
+
function createCompressor(format) {
|
|
9560
|
+
return format === "zstd" ? zlib.createZstdCompress({
|
|
9561
|
+
chunkSize: CHUNK_BYTES,
|
|
9562
|
+
// Lets the decoder detect corruption.
|
|
9563
|
+
params: { [zlib.constants.ZSTD_c_checksumFlag]: 1 }
|
|
9564
|
+
}) : zlib.createGzip({ chunkSize: CHUNK_BYTES });
|
|
9565
|
+
}
|
|
9566
|
+
function createTarArgs(sourcePath) {
|
|
9567
|
+
const name = basename4(sourcePath);
|
|
9568
|
+
return ["-cf", "-", "-C", dirname5(sourcePath), /^[-@]/.test(name) ? `./${name}` : name];
|
|
9569
|
+
}
|
|
9570
|
+
var MAX_LISTING_BYTES = 32 << 20;
|
|
9571
|
+
var MAX_LISTING_LINES = 1 << 18;
|
|
9572
|
+
var MAX_STDERR_BYTES = 16 << 10;
|
|
9573
|
+
var MAX_UNREAD_BYTES = 16 << 20;
|
|
9574
|
+
function collect(stream, maxBytes, { maxLines = Infinity, onOverflow } = {}) {
|
|
9575
|
+
const chunks = [];
|
|
9576
|
+
let bytes = 0;
|
|
9577
|
+
let lines = 0;
|
|
9578
|
+
let overflowed = false;
|
|
9579
|
+
stream?.on("data", (chunk) => {
|
|
9580
|
+
if (overflowed) return;
|
|
9581
|
+
chunks.push(chunk.subarray(0, maxBytes - bytes));
|
|
9582
|
+
bytes += chunk.length;
|
|
9583
|
+
for (let i = chunk.indexOf(10); i !== -1 && lines <= maxLines; i = chunk.indexOf(10, i + 1)) {
|
|
9584
|
+
lines++;
|
|
9585
|
+
}
|
|
9586
|
+
if (bytes > maxBytes || lines > maxLines) {
|
|
9587
|
+
overflowed = true;
|
|
9588
|
+
onOverflow?.();
|
|
9589
|
+
}
|
|
9590
|
+
});
|
|
9591
|
+
return {
|
|
9592
|
+
overflowed: () => overflowed,
|
|
9593
|
+
text: () => Buffer.concat(chunks).toString("utf8") + (overflowed ? "\u2026" : "")
|
|
9594
|
+
};
|
|
9544
9595
|
}
|
|
9545
|
-
async function
|
|
9596
|
+
async function createArchiveFile(sourcePath, archivePath, format, signal) {
|
|
9597
|
+
const out = createWriteStream(archivePath);
|
|
9598
|
+
await once(out, "ready");
|
|
9546
9599
|
try {
|
|
9547
|
-
await
|
|
9600
|
+
await archiveInto(out, sourcePath, format, signal);
|
|
9548
9601
|
} catch (err) {
|
|
9549
|
-
|
|
9602
|
+
out.destroy();
|
|
9603
|
+
await rm(archivePath, { force: true }).catch(() => {
|
|
9550
9604
|
});
|
|
9605
|
+
signal?.throwIfAborted();
|
|
9551
9606
|
throw err;
|
|
9552
9607
|
}
|
|
9553
9608
|
}
|
|
9609
|
+
async function archiveInto(out, sourcePath, format, signal) {
|
|
9610
|
+
const child = spawn2("tar", createTarArgs(sourcePath), {
|
|
9611
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
9612
|
+
signal
|
|
9613
|
+
});
|
|
9614
|
+
const exited = new Promise((res, rej) => {
|
|
9615
|
+
child.on("error", rej);
|
|
9616
|
+
child.on("close", res);
|
|
9617
|
+
});
|
|
9618
|
+
const stderr = collect(child.stderr, MAX_STDERR_BYTES);
|
|
9619
|
+
const [written, closed] = await Promise.allSettled([
|
|
9620
|
+
pipeline(child.stdout, createCompressor(format), out),
|
|
9621
|
+
exited
|
|
9622
|
+
]);
|
|
9623
|
+
if (closed.status === "rejected") throw closed.reason;
|
|
9624
|
+
if (written.status === "rejected") throw written.reason;
|
|
9625
|
+
if (closed.value !== 0) {
|
|
9626
|
+
throw new Error(`tar exited with code ${closed.value}: ${stderr.text().trim()}`);
|
|
9627
|
+
}
|
|
9628
|
+
}
|
|
9629
|
+
async function sniffFormat(archivePath) {
|
|
9630
|
+
const fh = await open(archivePath, "r");
|
|
9631
|
+
try {
|
|
9632
|
+
const { buffer, bytesRead } = await fh.read(Buffer.alloc(4), 0, 4, 0);
|
|
9633
|
+
const magic = buffer.subarray(0, bytesRead).toString("hex");
|
|
9634
|
+
if (magic.startsWith("1f8b")) return "gzip";
|
|
9635
|
+
if (magic === "28b52ffd" && ARCHIVE_FORMATS.includes("zstd")) return "zstd";
|
|
9636
|
+
throw new ArchiveError("unrecognized compression");
|
|
9637
|
+
} finally {
|
|
9638
|
+
await fh.close();
|
|
9639
|
+
}
|
|
9640
|
+
}
|
|
9641
|
+
var ZSTD_FRAME_MAGIC = 4247762216;
|
|
9642
|
+
async function assertSingleCompleteZstdFrame(archivePath) {
|
|
9643
|
+
const fh = await open(archivePath, "r");
|
|
9644
|
+
try {
|
|
9645
|
+
const { size } = await fh.stat();
|
|
9646
|
+
const window = Buffer.alloc(4096);
|
|
9647
|
+
let windowStart = 0;
|
|
9648
|
+
let windowEnd = 0;
|
|
9649
|
+
let pos = 0;
|
|
9650
|
+
const read = async (n) => {
|
|
9651
|
+
if (pos < windowStart || pos + n > windowEnd) {
|
|
9652
|
+
const { bytesRead } = await fh.read(window, 0, window.length, pos);
|
|
9653
|
+
windowStart = pos;
|
|
9654
|
+
windowEnd = pos + bytesRead;
|
|
9655
|
+
if (bytesRead < n) throw new ArchiveError("truncated zstd frame");
|
|
9656
|
+
}
|
|
9657
|
+
return window.subarray(pos - windowStart, pos - windowStart + n);
|
|
9658
|
+
};
|
|
9659
|
+
for (let frame = 0; pos < size; frame++) {
|
|
9660
|
+
const header = await read(5);
|
|
9661
|
+
if (header.readUInt32LE(0) !== ZSTD_FRAME_MAGIC) throw new ArchiveError("bad zstd frame");
|
|
9662
|
+
const descriptor = header[4];
|
|
9663
|
+
const singleSegment = descriptor >> 5 & 1;
|
|
9664
|
+
pos += 5 + (singleSegment ? 0 : 1) + // window descriptor
|
|
9665
|
+
[0, 1, 2, 4][descriptor & 3] + // dictionary id
|
|
9666
|
+
[singleSegment, 2, 4, 8][descriptor >> 6];
|
|
9667
|
+
let hasData = false;
|
|
9668
|
+
for (let last = 0; !last; ) {
|
|
9669
|
+
const block = (await read(3)).readUIntLE(0, 3);
|
|
9670
|
+
last = block & 1;
|
|
9671
|
+
const type = block >> 1 & 3;
|
|
9672
|
+
const blockSize = block >> 3;
|
|
9673
|
+
if (blockSize > 0) hasData = true;
|
|
9674
|
+
pos += 3 + (type === 1 ? 1 : blockSize);
|
|
9675
|
+
}
|
|
9676
|
+
if (descriptor >> 2 & 1) pos += 4;
|
|
9677
|
+
if (hasData && frame > 0) throw new ArchiveError("multi-frame zstd");
|
|
9678
|
+
}
|
|
9679
|
+
if (pos !== size) throw new ArchiveError("truncated zstd frame");
|
|
9680
|
+
} finally {
|
|
9681
|
+
await fh.close();
|
|
9682
|
+
}
|
|
9683
|
+
}
|
|
9684
|
+
var TAR_LOCALE = process.platform === "darwin" ? "en_US.UTF-8" : "C.UTF-8";
|
|
9685
|
+
function tarEnv(env) {
|
|
9686
|
+
const characterType = env.LC_ALL || env.LC_CTYPE || env.LANG || "";
|
|
9687
|
+
return /utf-?8/i.test(characterType) ? env : { ...env, LC_ALL: TAR_LOCALE };
|
|
9688
|
+
}
|
|
9689
|
+
async function runTar(archive, args) {
|
|
9690
|
+
const child = spawn2("tar", [...args, "-f", "-"], {
|
|
9691
|
+
env: tarEnv(process.env)
|
|
9692
|
+
});
|
|
9693
|
+
const exited = new Promise((res, rej) => {
|
|
9694
|
+
child.on("error", rej);
|
|
9695
|
+
child.on("close", res);
|
|
9696
|
+
});
|
|
9697
|
+
const stdout = collect(child.stdout, MAX_LISTING_BYTES, {
|
|
9698
|
+
maxLines: MAX_LISTING_LINES,
|
|
9699
|
+
onOverflow: () => child.kill()
|
|
9700
|
+
});
|
|
9701
|
+
const stderr = collect(child.stderr, MAX_STDERR_BYTES);
|
|
9702
|
+
child.stdin?.on("error", () => {
|
|
9703
|
+
});
|
|
9704
|
+
const unreadLimit = new Error("unread limit");
|
|
9705
|
+
let unread = 0;
|
|
9706
|
+
const fed = pipeline(
|
|
9707
|
+
createReadStream(archive.path, { highWaterMark: CHUNK_BYTES }),
|
|
9708
|
+
archive.format === "zstd" ? zlib.createZstdDecompress({ chunkSize: CHUNK_BYTES }) : zlib.createGunzip({ chunkSize: CHUNK_BYTES }),
|
|
9709
|
+
new Writable({
|
|
9710
|
+
write(chunk, _encoding, done) {
|
|
9711
|
+
if (child.stdin?.writable) return void child.stdin.write(chunk, () => done());
|
|
9712
|
+
unread += chunk.length;
|
|
9713
|
+
done(unread > MAX_UNREAD_BYTES ? unreadLimit : null);
|
|
9714
|
+
},
|
|
9715
|
+
final(done) {
|
|
9716
|
+
child.stdin?.end();
|
|
9717
|
+
done();
|
|
9718
|
+
},
|
|
9719
|
+
destroy(err, done) {
|
|
9720
|
+
if (err) child.stdin?.destroy();
|
|
9721
|
+
done(err);
|
|
9722
|
+
}
|
|
9723
|
+
})
|
|
9724
|
+
).then(
|
|
9725
|
+
() => null,
|
|
9726
|
+
(err) => err
|
|
9727
|
+
);
|
|
9728
|
+
const [code, feedError] = await Promise.all([exited, fed]);
|
|
9729
|
+
if (stdout.overflowed()) {
|
|
9730
|
+
throw new Error(
|
|
9731
|
+
`tar ${args.join(" ")} listed more than ${MAX_LISTING_LINES} members or ${MAX_LISTING_BYTES >> 20} MiB`
|
|
9732
|
+
);
|
|
9733
|
+
}
|
|
9734
|
+
if (feedError && feedError !== unreadLimit) throw feedError;
|
|
9735
|
+
if (code !== 0)
|
|
9736
|
+
throw new Error(`tar ${args.join(" ")} exited with code ${code}: ${stderr.text().trim()}`);
|
|
9737
|
+
return stdout.text();
|
|
9738
|
+
}
|
|
9554
9739
|
function normalizeTarMemberPath(memberPath) {
|
|
9555
9740
|
return memberPath.replace(/^\.\//, "").replace(/\\/g, "/");
|
|
9556
9741
|
}
|
|
9742
|
+
function isContainedPath(path14, windows = process.platform === "win32") {
|
|
9743
|
+
const slashed = path14.replace(/\\/g, "/");
|
|
9744
|
+
const drive = windows ? /^[A-Za-z]:/ : /^[A-Za-z]:\//;
|
|
9745
|
+
return !slashed.startsWith("/") && !drive.test(slashed) && !slashed.split("/").includes("..");
|
|
9746
|
+
}
|
|
9557
9747
|
function isSafeTarMember(memberPath, destDir) {
|
|
9558
9748
|
const normalized = normalizeTarMemberPath(memberPath);
|
|
9559
|
-
if (!normalized
|
|
9560
|
-
if (normalized.startsWith("/") || /^[A-Za-z]:[\\/]/.test(normalized)) return false;
|
|
9561
|
-
const relative2 = posix2.normalize(normalized);
|
|
9562
|
-
if (relative2 === ".." || relative2.startsWith("../") || relative2.split("/").includes("..")) {
|
|
9563
|
-
return false;
|
|
9564
|
-
}
|
|
9749
|
+
if (!isContainedPath(normalized)) return false;
|
|
9565
9750
|
const root = resolve6(destDir);
|
|
9566
|
-
|
|
9567
|
-
return resolved === root || resolved.startsWith(root + sep2);
|
|
9751
|
+
return resolve6(destDir, normalized).startsWith(root + sep2);
|
|
9568
9752
|
}
|
|
9569
|
-
async function
|
|
9570
|
-
|
|
9571
|
-
|
|
9753
|
+
async function readListing(archive, args) {
|
|
9754
|
+
try {
|
|
9755
|
+
return await runTar(archive, args);
|
|
9756
|
+
} catch (err) {
|
|
9757
|
+
throw new ArchiveError(
|
|
9758
|
+
`Could not read archive: ${err instanceof Error ? err.message : String(err)}`
|
|
9759
|
+
);
|
|
9760
|
+
}
|
|
9572
9761
|
}
|
|
9573
|
-
function
|
|
9574
|
-
|
|
9575
|
-
return
|
|
9762
|
+
async function listTarMembers(archive) {
|
|
9763
|
+
const stdout = await readListing(archive, ["-t"]);
|
|
9764
|
+
return stdout.split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
|
|
9576
9765
|
}
|
|
9577
|
-
async function assertSafeMemberTypes(
|
|
9578
|
-
const
|
|
9766
|
+
async function assertSafeMemberTypes(archive) {
|
|
9767
|
+
const stdout = await readListing(archive, ["-tv"]);
|
|
9579
9768
|
for (const line of stdout.split("\n")) {
|
|
9580
9769
|
if (!line.trim()) continue;
|
|
9581
9770
|
const type = line[0];
|
|
@@ -9583,7 +9772,7 @@ async function assertSafeMemberTypes(tarPath) {
|
|
|
9583
9772
|
if (type === "l") {
|
|
9584
9773
|
const parts = line.split(" -> ");
|
|
9585
9774
|
const target = parts.length === 2 ? parts[1].trim() : "";
|
|
9586
|
-
if (parts.length !== 2 || !target ||
|
|
9775
|
+
if (parts.length !== 2 || !target || !isContainedPath(target)) {
|
|
9587
9776
|
throw new ArchiveError(
|
|
9588
9777
|
`Archive contains a symlink whose target could not be confirmed safe: "${line.trim()}".`
|
|
9589
9778
|
);
|
|
@@ -9595,15 +9784,8 @@ async function assertSafeMemberTypes(tarPath) {
|
|
|
9595
9784
|
);
|
|
9596
9785
|
}
|
|
9597
9786
|
}
|
|
9598
|
-
async function assertSafeArchive(
|
|
9599
|
-
|
|
9600
|
-
try {
|
|
9601
|
-
members = await listTarMembers(tarPath);
|
|
9602
|
-
} catch (err) {
|
|
9603
|
-
throw new ArchiveError(
|
|
9604
|
-
`Could not read archive: ${err instanceof Error ? err.message : String(err)}`
|
|
9605
|
-
);
|
|
9606
|
-
}
|
|
9787
|
+
async function assertSafeArchive(archive, destDir) {
|
|
9788
|
+
const members = await listTarMembers(archive);
|
|
9607
9789
|
if (members.length === 0) {
|
|
9608
9790
|
throw new ArchiveError("Archive is empty.");
|
|
9609
9791
|
}
|
|
@@ -9612,7 +9794,7 @@ async function assertSafeArchive(tarPath, destDir) {
|
|
|
9612
9794
|
throw new ArchiveError(`Archive contains an unsafe path "${member}" \u2014 refusing extraction.`);
|
|
9613
9795
|
}
|
|
9614
9796
|
}
|
|
9615
|
-
await assertSafeMemberTypes(
|
|
9797
|
+
await assertSafeMemberTypes(archive);
|
|
9616
9798
|
}
|
|
9617
9799
|
async function resolveMember(destDir, expectedName) {
|
|
9618
9800
|
const entries = await readdir3(destDir);
|
|
@@ -9627,9 +9809,18 @@ async function resolveMember(destDir, expectedName) {
|
|
|
9627
9809
|
}
|
|
9628
9810
|
return join9(destDir, real[0]);
|
|
9629
9811
|
}
|
|
9630
|
-
async function
|
|
9631
|
-
|
|
9632
|
-
|
|
9812
|
+
async function safeExtractArchive(archivePath, destDir, expectedName) {
|
|
9813
|
+
let archive;
|
|
9814
|
+
try {
|
|
9815
|
+
archive = { path: archivePath, format: await sniffFormat(archivePath) };
|
|
9816
|
+
if (archive.format === "zstd") await assertSingleCompleteZstdFrame(archivePath);
|
|
9817
|
+
} catch (err) {
|
|
9818
|
+
throw new ArchiveError(
|
|
9819
|
+
`Could not read archive: ${err instanceof Error ? err.message : String(err)}`
|
|
9820
|
+
);
|
|
9821
|
+
}
|
|
9822
|
+
await assertSafeArchive(archive, destDir);
|
|
9823
|
+
await runTar(archive, ["-x", "-C", destDir]);
|
|
9633
9824
|
return resolveMember(destDir, expectedName);
|
|
9634
9825
|
}
|
|
9635
9826
|
|
|
@@ -9710,7 +9901,7 @@ function untrackArchive(archive) {
|
|
|
9710
9901
|
function sha256File(filePath) {
|
|
9711
9902
|
return new Promise((resolve9, reject) => {
|
|
9712
9903
|
const hash = createHash2("sha256");
|
|
9713
|
-
|
|
9904
|
+
createReadStream2(filePath).on("data", (chunk) => hash.update(chunk)).on("end", () => resolve9(hash.digest("hex"))).on("error", reject);
|
|
9714
9905
|
});
|
|
9715
9906
|
}
|
|
9716
9907
|
function toolServerError(text) {
|
|
@@ -9736,15 +9927,15 @@ function uploadFailure(url, res, text, bytes) {
|
|
|
9736
9927
|
errorKind: "validation"
|
|
9737
9928
|
});
|
|
9738
9929
|
}
|
|
9739
|
-
async function uploadTar(tarPath, endpoint, signal) {
|
|
9930
|
+
async function uploadTar(tarPath, format, endpoint, signal) {
|
|
9740
9931
|
const { size } = await stat3(tarPath);
|
|
9741
9932
|
const init = {
|
|
9742
9933
|
method: "POST",
|
|
9743
9934
|
headers: {
|
|
9744
|
-
"content-type":
|
|
9935
|
+
"content-type": ARCHIVE_CONTENT_TYPES[format],
|
|
9745
9936
|
...endpoint.token ? { Authorization: `Bearer ${endpoint.token}` } : {}
|
|
9746
9937
|
},
|
|
9747
|
-
body:
|
|
9938
|
+
body: createReadStream2(tarPath),
|
|
9748
9939
|
duplex: "half",
|
|
9749
9940
|
signal
|
|
9750
9941
|
};
|
|
@@ -9761,12 +9952,13 @@ async function uploadTar(tarPath, endpoint, signal) {
|
|
|
9761
9952
|
return json.uploadId;
|
|
9762
9953
|
}
|
|
9763
9954
|
async function uploadFile(sourcePath, endpoint, signal) {
|
|
9955
|
+
const format = pickArchiveFormat(endpoint.formats);
|
|
9764
9956
|
const tarPath = path10.join(tmpdir(), `argent-upload-${randomUUID4()}.tar.gz`);
|
|
9765
9957
|
trackArchive(tarPath);
|
|
9766
9958
|
try {
|
|
9767
|
-
await
|
|
9959
|
+
await createArchiveFile(await realpath2(sourcePath), tarPath, format, signal);
|
|
9768
9960
|
const contentHash = await sha256File(tarPath);
|
|
9769
|
-
return { uploadId: await uploadTar(tarPath, endpoint, signal), contentHash };
|
|
9961
|
+
return { uploadId: await uploadTar(tarPath, format, endpoint, signal), contentHash };
|
|
9770
9962
|
} finally {
|
|
9771
9963
|
untrackArchive(tarPath);
|
|
9772
9964
|
await rm2(tarPath, { force: true }).catch(() => {
|
|
@@ -10621,7 +10813,7 @@ function createToolsClient(options = {}) {
|
|
|
10621
10813
|
const { url, token } = await route();
|
|
10622
10814
|
return { url, token };
|
|
10623
10815
|
}
|
|
10624
|
-
async function
|
|
10816
|
+
async function fetchToolList(opts) {
|
|
10625
10817
|
opts?.signal?.throwIfAborted();
|
|
10626
10818
|
const { url, token } = await baseUrl();
|
|
10627
10819
|
const res = await doFetch(
|
|
@@ -10630,8 +10822,10 @@ function createToolsClient(options = {}) {
|
|
|
10630
10822
|
{ longRunning: false, carriesUpload: false }
|
|
10631
10823
|
);
|
|
10632
10824
|
if (!res.ok) throw new Error(`GET /tools failed: ${res.status} ${res.statusText}`);
|
|
10633
|
-
|
|
10634
|
-
|
|
10825
|
+
return await res.json();
|
|
10826
|
+
}
|
|
10827
|
+
async function fetchTools(opts) {
|
|
10828
|
+
return (await fetchToolList(opts)).tools;
|
|
10635
10829
|
}
|
|
10636
10830
|
async function fetchTool(name, opts) {
|
|
10637
10831
|
return findTool(await fetchTools(opts), name);
|
|
@@ -10640,7 +10834,7 @@ function createToolsClient(options = {}) {
|
|
|
10640
10834
|
opts?.signal?.throwIfAborted();
|
|
10641
10835
|
const { url, token, remote } = await route();
|
|
10642
10836
|
let finalArgs = canonicalToolArgs(name, args);
|
|
10643
|
-
const tools = await
|
|
10837
|
+
const { tools, uploadFormats } = await fetchToolList({ signal: opts?.signal });
|
|
10644
10838
|
const meta = findTool(tools, name);
|
|
10645
10839
|
const olderServer = meta !== null && !tools.some((t) => t.name === canonicalToolId(meta.name));
|
|
10646
10840
|
if (meta) {
|
|
@@ -10657,7 +10851,7 @@ function createToolsClient(options = {}) {
|
|
|
10657
10851
|
if (remote) assertRequiredPresent(meta, finalArgs);
|
|
10658
10852
|
finalArgs = await prepareFileInputs(meta.fileInputs, finalArgs ?? {}, {
|
|
10659
10853
|
includeContent: remote,
|
|
10660
|
-
uploadEndpoint: remote ? { url, token } : void 0,
|
|
10854
|
+
uploadEndpoint: remote ? { url, token, formats: uploadFormats } : void 0,
|
|
10661
10855
|
log: diagnose,
|
|
10662
10856
|
baselineDirs,
|
|
10663
10857
|
collectMembers: collectFlowMembers,
|
|
@@ -10954,7 +11148,7 @@ async function downloadAndExtractArchive(handle, data, dir) {
|
|
|
10954
11148
|
const tarball = join13(dir, `${sanitizeSegment(handle.filename)}.tar.gz`);
|
|
10955
11149
|
try {
|
|
10956
11150
|
await writeFile4(tarball, data);
|
|
10957
|
-
return await
|
|
11151
|
+
return await safeExtractArchive(tarball, dir, handle.filename);
|
|
10958
11152
|
} catch {
|
|
10959
11153
|
return null;
|
|
10960
11154
|
} finally {
|
|
@@ -11033,7 +11227,10 @@ async function materializeArtifacts(result, ctx) {
|
|
|
11033
11227
|
}
|
|
11034
11228
|
try {
|
|
11035
11229
|
const res = await fetchFn(`${ctx.toolsUrl}/artifacts/${value.id}`, {
|
|
11036
|
-
headers:
|
|
11230
|
+
headers: value.archive ? {
|
|
11231
|
+
...authHeaders3,
|
|
11232
|
+
Accept: ARCHIVE_FORMATS.map((f) => ARCHIVE_CONTENT_TYPES[f]).join(", ")
|
|
11233
|
+
} : authHeaders3,
|
|
11037
11234
|
signal: ctx.signal
|
|
11038
11235
|
});
|
|
11039
11236
|
if (!res.ok) return null;
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
// next to the compiled executor and resolves its watchdogs against its own URL.
|
|
3
3
|
|
|
4
4
|
import fs from "node:fs";
|
|
5
|
+
import { Module } from "node:module";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
5
8
|
import { isMainThread, Worker } from "node:worker_threads";
|
|
6
9
|
|
|
7
10
|
const LIFELINE_WATCHDOG = "flow-script-watchdog-lifeline.mjs";
|
|
@@ -20,6 +23,7 @@ let finished = false;
|
|
|
20
23
|
let maxOutputBytes = 0;
|
|
21
24
|
|
|
22
25
|
let probing = false;
|
|
26
|
+
let entryThrew = false;
|
|
23
27
|
|
|
24
28
|
let idleResources = [];
|
|
25
29
|
|
|
@@ -65,10 +69,12 @@ const decodeJson = JSON.parse;
|
|
|
65
69
|
|
|
66
70
|
const runnerListeners = [];
|
|
67
71
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
/**
|
|
73
|
+
* The CommonJS loader's entry point, which is how plain `node` starts a main
|
|
74
|
+
* module. Node's types do not carry it, and a Node without it leaves the entry
|
|
75
|
+
* to Node. See `loadEntryAsPlainNodeDoes`.
|
|
76
|
+
*/
|
|
77
|
+
const commonJsLoad = /** @type {{ _load?: unknown }} */ (/** @type {unknown} */ (Module))._load;
|
|
72
78
|
|
|
73
79
|
async function prepare() {
|
|
74
80
|
const raw = await nextRequest();
|
|
@@ -129,6 +135,8 @@ async function prepare() {
|
|
|
129
135
|
});
|
|
130
136
|
|
|
131
137
|
closeChannelToScript();
|
|
138
|
+
const commonJsLoaderEntry = entryForCommonJsLoader(request.scriptUrl);
|
|
139
|
+
if (commonJsLoaderEntry === undefined) claimMainModuleIdentity(request.scriptUrl);
|
|
132
140
|
|
|
133
141
|
// Registered here rather than at module scope: Node references the IPC
|
|
134
142
|
// channel while a `message` or `disconnect` listener exists, and in the
|
|
@@ -151,6 +159,8 @@ async function prepare() {
|
|
|
151
159
|
// Read last, so it is the loop as the script inherits it. Node awaits this
|
|
152
160
|
// module before it loads the entry, so there is no later point that holds.
|
|
153
161
|
idleResources = process.getActiveResourcesInfo();
|
|
162
|
+
|
|
163
|
+
if (commonJsLoaderEntry !== undefined) return loadEntryAsPlainNodeDoes(commonJsLoaderEntry);
|
|
154
164
|
}
|
|
155
165
|
|
|
156
166
|
/**
|
|
@@ -209,7 +219,133 @@ function reportWhenEntrySettled(scriptUrl) {
|
|
|
209
219
|
: { type: "result", outputJson: encoded.json }
|
|
210
220
|
);
|
|
211
221
|
};
|
|
212
|
-
|
|
222
|
+
// An entry that threw in `loadEntryAsPlainNodeDoes` left no module behind, so
|
|
223
|
+
// an import here would run the script a second time.
|
|
224
|
+
(entryThrew ? Promise.resolve() : import(scriptUrl)).then(report, report);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* The path of a `.ts` entry that Node may run as CommonJS, which this preload
|
|
229
|
+
* then loads itself (see {@link loadEntryAsPlainNodeDoes}); undefined for every
|
|
230
|
+
* other entry.
|
|
231
|
+
*
|
|
232
|
+
* `.mts` cannot be CommonJS, and neither can a `.ts` file under
|
|
233
|
+
* `"type": "module"`. A `.js` entry stays with Node: its `require` is whole
|
|
234
|
+
* either way, and `claimMainModuleIdentity` covers what differs.
|
|
235
|
+
*/
|
|
236
|
+
function entryForCommonJsLoader(scriptUrl) {
|
|
237
|
+
if (typeof commonJsLoad !== "function") return undefined;
|
|
238
|
+
let entryPath;
|
|
239
|
+
try {
|
|
240
|
+
entryPath = fileURLToPath(scriptUrl);
|
|
241
|
+
} catch {
|
|
242
|
+
return undefined;
|
|
243
|
+
}
|
|
244
|
+
if (!entryPath.endsWith(".ts")) return undefined;
|
|
245
|
+
return nearestPackageType(entryPath) === "module" ? undefined : entryPath;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* The `type` of the `package.json` nearest to `file`, as Node looks it up: the
|
|
250
|
+
* first one found going up, and never past a `node_modules` directory. A file
|
|
251
|
+
* that will not read or parse counts as no answer: Node then decides, and
|
|
252
|
+
* reports that file itself.
|
|
253
|
+
*/
|
|
254
|
+
function nearestPackageType(file) {
|
|
255
|
+
let dir = path.dirname(file);
|
|
256
|
+
for (;;) {
|
|
257
|
+
if (path.basename(dir) === "node_modules") return undefined;
|
|
258
|
+
try {
|
|
259
|
+
return decodeJson(fs.readFileSync(path.join(dir, "package.json"), "utf8"))?.type;
|
|
260
|
+
} catch (err) {
|
|
261
|
+
if (err?.code !== "ENOENT") return undefined;
|
|
262
|
+
}
|
|
263
|
+
const parent = path.dirname(dir);
|
|
264
|
+
if (parent === dir) return undefined;
|
|
265
|
+
dir = parent;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Loads the entry through the CommonJS loader, which is where plain `node`
|
|
271
|
+
* starts a `.ts` file outside `"type": "module"`. Node decides the module type
|
|
272
|
+
* there as it does with no preload: a file with ES module syntax goes on to
|
|
273
|
+
* the ESM loader, and anything else runs as CommonJS, as the main module.
|
|
274
|
+
*
|
|
275
|
+
* Left to Node, the `--import` that carries this preload sends the entry
|
|
276
|
+
* through the ESM loader instead, and on Node 22, 24.0 to 24.17 and 25 that
|
|
277
|
+
* loader gives a CommonJS TypeScript file a reduced `require`: no
|
|
278
|
+
* `require.cache`, no `require.extensions`, and an undefined `module.parent`
|
|
279
|
+
* in every module the script loads. Node still imports the entry after this
|
|
280
|
+
* preload, and finds the module this call left in its cache, so the script
|
|
281
|
+
* runs once.
|
|
282
|
+
*
|
|
283
|
+
* A script that throws leaves no module in that cache, and Node would run it
|
|
284
|
+
* again. So the preload never settles, which keeps Node from the entry, and
|
|
285
|
+
* the error goes where plain `node` sends it: to `uncaughtException`.
|
|
286
|
+
*/
|
|
287
|
+
function loadEntryAsPlainNodeDoes(entryPath) {
|
|
288
|
+
try {
|
|
289
|
+
/** @type {Function} */ (commonJsLoad).call(Module, entryPath, null, true);
|
|
290
|
+
} catch (err) {
|
|
291
|
+
entryThrew = true;
|
|
292
|
+
queueMicrotask(() => {
|
|
293
|
+
throw err;
|
|
294
|
+
});
|
|
295
|
+
return never();
|
|
296
|
+
}
|
|
297
|
+
return undefined;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Under plain `node` a CommonJS entry is the main module three ways:
|
|
302
|
+
* `require.main === module`, `module.id === "."` and `module.parent === null`.
|
|
303
|
+
* This preload rides in on `--import`, which sends the entry through the ESM
|
|
304
|
+
* loader, and there Node sets only the first: `id` is the file's path and
|
|
305
|
+
* `parent` is `undefined`. A script that guards its body with either of the
|
|
306
|
+
* other two would skip it, and the step would pass having done nothing.
|
|
307
|
+
*
|
|
308
|
+
* Node builds the entry's module object and runs the script with no hook in
|
|
309
|
+
* between, so the values go in from inside the constructor: its first statement
|
|
310
|
+
* is `this.id = id`, which a setter on the prototype receives. `parent` is an
|
|
311
|
+
* accessor on that same prototype, so an own property answers for it.
|
|
312
|
+
*
|
|
313
|
+
* The setter is spent on the first module built, whichever it is. For a
|
|
314
|
+
* CommonJS entry that is the entry. An ES module entry never builds one for
|
|
315
|
+
* itself, so the first is some dependency's and comes out as Node made it —
|
|
316
|
+
* unless the script calls `createRequire` on its own path first, whose hidden
|
|
317
|
+
* parent module then carries the entry's identity, which is what it stands for.
|
|
318
|
+
*
|
|
319
|
+
* `.mjs` and `.mts` are skipped: neither can be CommonJS. A `.ts` entry that
|
|
320
|
+
* may be CommonJS does not come here at all: `loadEntryAsPlainNodeDoes` makes
|
|
321
|
+
* it the main module the way Node does.
|
|
322
|
+
*/
|
|
323
|
+
function claimMainModuleIdentity(scriptUrl) {
|
|
324
|
+
let entryPath;
|
|
325
|
+
try {
|
|
326
|
+
entryPath = fileURLToPath(scriptUrl);
|
|
327
|
+
} catch {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
if (/\.m[jt]s$/.test(entryPath)) return;
|
|
331
|
+
const own = (target, key, value, enumerable) =>
|
|
332
|
+
Object.defineProperty(target, key, { value, writable: true, enumerable, configurable: true });
|
|
333
|
+
Object.defineProperty(Module.prototype, "id", {
|
|
334
|
+
configurable: true,
|
|
335
|
+
enumerable: false,
|
|
336
|
+
get() {
|
|
337
|
+
return undefined;
|
|
338
|
+
},
|
|
339
|
+
set(value) {
|
|
340
|
+
delete Module.prototype.id;
|
|
341
|
+
if (value !== entryPath) {
|
|
342
|
+
this.id = value;
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
own(this, "id", ".", true);
|
|
346
|
+
own(this, "parent", null, false);
|
|
347
|
+
},
|
|
348
|
+
});
|
|
213
349
|
}
|
|
214
350
|
|
|
215
351
|
function keepListener(event, handler) {
|
|
@@ -794,3 +930,10 @@ function sendToParent(message, callback) {
|
|
|
794
930
|
runnerIsSending = false;
|
|
795
931
|
}
|
|
796
932
|
}
|
|
933
|
+
|
|
934
|
+
// Last in the file: `prepare` may never settle, and a handler that runs while
|
|
935
|
+
// this module is parked there reads the constants declared above.
|
|
936
|
+
if (isMainThread && process.env[ACTIVATION_ENV] === "1") {
|
|
937
|
+
delete process.env[ACTIVATION_ENV];
|
|
938
|
+
await prepare();
|
|
939
|
+
}
|