@swmansion/argent 0.33.1-next.9 → 0.34.1-next.0

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.
Files changed (39) hide show
  1. package/assets/Argent.tracetemplate +0 -0
  2. package/bin/argent-android-devtools-0.4.0.apk +0 -0
  3. package/bin/darwin/argent-macos-helper +0 -0
  4. package/bin/darwin/ax-service +0 -0
  5. package/bin/darwin/tvos-ax-service +0 -0
  6. package/bin/darwin/tvos-hid-daemon +0 -0
  7. package/bin/network-inspector/network-inspector.jar +0 -0
  8. package/bin/tcp/ax-service +0 -0
  9. package/dist/cli-cmds.mjs +380 -123
  10. package/dist/client.js +256 -56
  11. package/dist/flow-script-runner.mjs +148 -5
  12. package/dist/installer.mjs +40 -24
  13. package/dist/ios-device-runner/ArgentRunner/ArgentRunnerUITests/ArgentRunnerSession+Snapshot.swift +110 -4
  14. package/dist/mcp-server.mjs +330 -68
  15. package/dist/tool-args.generated.d.ts +22 -20
  16. package/dist/tool-server.cjs +3763 -2146
  17. package/dylibs/libArgentInjectionBootstrap.dylib +0 -0
  18. package/dylibs/libKeyboardPatch.dylib +0 -0
  19. package/dylibs/libNativeDevtoolsIos.dylib +0 -0
  20. package/dylibs/macos/libArgentInjectionBootstrap.dylib +0 -0
  21. package/dylibs/macos/libNativeDevtoolsMacos.dylib +0 -0
  22. package/dylibs/tcp/libArgentInjectionBootstrap.dylib +0 -0
  23. package/dylibs/tcp/libKeyboardPatch.dylib +0 -0
  24. package/dylibs/tcp/libNativeDevtoolsIos.dylib +0 -0
  25. package/dylibs/tvos/libArgentInjectionBootstrap.dylib +0 -0
  26. package/dylibs/tvos/libKeyboardPatch.dylib +0 -0
  27. package/dylibs/tvos/libNativeDevtoolsIos.dylib +0 -0
  28. package/package.json +2 -3
  29. package/rules/argent.md +1 -1
  30. package/skills/argent-create-e2e/references/e2e-yaml.md +11 -1
  31. package/skills/argent-create-e2e/references/reliability-and-recovery.md +1 -1
  32. package/skills/argent-device-interact/SKILL.md +2 -2
  33. package/skills/argent-device-interact/references/harmonyos.md +1 -1
  34. package/skills/argent-macos-app-interact/SKILL.md +5 -1
  35. package/skills/argent-native-profiler/SKILL.md +14 -5
  36. package/skills/argent-react-native-profiler/SKILL.md +7 -0
  37. package/skills/argent-test-ui-flow/SKILL.md +1 -1
  38. package/assets/trace-processor/SHA256SUMS +0 -4
  39. package/assets/trace-processor/engine.mjs +0 -42423
@@ -17450,7 +17450,7 @@ function handleIntersectionResults(result, left, right) {
17450
17450
  const unrecKeys = /* @__PURE__ */ new Map();
17451
17451
  let unrecIssue;
17452
17452
  const keyIssues = /* @__PURE__ */ new Map();
17453
- const collect = (iss, side) => {
17453
+ const collect2 = (iss, side) => {
17454
17454
  let keys;
17455
17455
  if (iss.code === "unrecognized_keys" && !iss.path?.length) {
17456
17456
  unrecIssue ?? (unrecIssue = iss);
@@ -17471,11 +17471,11 @@ function handleIntersectionResults(result, left, right) {
17471
17471
  return true;
17472
17472
  };
17473
17473
  for (const iss of left.issues) {
17474
- if (!collect(iss, "l"))
17474
+ if (!collect2(iss, "l"))
17475
17475
  result.issues.push(iss);
17476
17476
  }
17477
17477
  for (const iss of right.issues) {
17478
- if (!collect(iss, "r"))
17478
+ if (!collect2(iss, "r"))
17479
17479
  result.issues.push(iss);
17480
17480
  }
17481
17481
  const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
@@ -24574,7 +24574,7 @@ function spawnToolsServer(paths, port, options = {}) {
24574
24574
  "error",
24575
24575
  (err) => reject(
24576
24576
  new Error(
24577
- err.code === "ENOENT" && nodeBin === "node" ? "Could not start the argent tool-server: `node` was not found on PATH. Install Node.js 20+ or add it to PATH." : `Could not start the argent tool-server: ${err.message}`
24577
+ 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}`
24578
24578
  )
24579
24579
  )
24580
24580
  );
@@ -25490,7 +25490,10 @@ import { basename, extname } from "node:path";
25490
25490
  var FLOW_NAME_CHARSET = "[A-Za-z0-9_-]+";
25491
25491
  var FLOW_NAME_PATTERN = new RegExp(`^${FLOW_NAME_CHARSET}$`);
25492
25492
  var FLOW_FILE_NAME_PATTERN = new RegExp(`^${FLOW_NAME_CHARSET}\\.yaml$`);
25493
- var SCRIPT_FILE_NAME_PATTERN = new RegExp(`^${FLOW_NAME_CHARSET}\\.mjs$`);
25493
+ var SCRIPT_FILE_EXTENSIONS = [".mjs", ".mts", ".js", ".ts"];
25494
+ var SCRIPT_FILE_NAME_PATTERN = new RegExp(
25495
+ `^${FLOW_NAME_CHARSET}(?:${SCRIPT_FILE_EXTENSIONS.map((ext) => `\\${ext}`).join("|")})$`
25496
+ );
25494
25497
  function interpolateFileInputPath(template, args) {
25495
25498
  let missing = false;
25496
25499
  const out = template.replace(/\$\{([A-Za-z0-9_]+)\}/g, (_m, name) => {
@@ -25981,6 +25984,9 @@ var FAILURE_CODES = {
25981
25984
  NATIVE_PROFILER_SESSION_TORN_DOWN: "NATIVE_PROFILER_SESSION_TORN_DOWN",
25982
25985
  NATIVE_PROFILER_APP_PROCESS_NOT_FOUND: "NATIVE_PROFILER_APP_PROCESS_NOT_FOUND",
25983
25986
  NATIVE_PROFILER_NO_EXPORTED_TRACE: "NATIVE_PROFILER_NO_EXPORTED_TRACE",
25987
+ NATIVE_PROFILER_APP_NOT_DEBUGGABLE: "NATIVE_PROFILER_APP_NOT_DEBUGGABLE",
25988
+ NATIVE_PROFILER_APP_HAS_WEBKIT_HEAP: "NATIVE_PROFILER_APP_HAS_WEBKIT_HEAP",
25989
+ NATIVE_PROFILER_APP_HEAP_CHECK_FAILED: "NATIVE_PROFILER_APP_HEAP_CHECK_FAILED",
25984
25990
  // Android perfetto start failures, mirroring the iOS xctrace set above.
25985
25991
  NATIVE_PROFILER_PERFETTO_PROCESS_ERROR: "NATIVE_PROFILER_PERFETTO_PROCESS_ERROR",
25986
25992
  NATIVE_PROFILER_PERFETTO_READY_TIMEOUT: "NATIVE_PROFILER_PERFETTO_READY_TIMEOUT",
@@ -26010,6 +26016,8 @@ var FAILURE_CODES = {
26010
26016
  FLOW_DEVICE_RESOLUTION: "FLOW_DEVICE_RESOLUTION",
26011
26017
  // The target does not satisfy the test's `requires:` block; a directory run skips it.
26012
26018
  FLOW_REQUIREMENTS_UNMET: "FLOW_REQUIREMENTS_UNMET",
26019
+ // The tool-server's Node.js cannot run a TypeScript `script:` step the test holds.
26020
+ FLOW_SCRIPT_TYPESCRIPT_UNSUPPORTED: "FLOW_SCRIPT_TYPESCRIPT_UNSUPPORTED",
26013
26021
  PROFILER_QUERY_MODE_INVALID: "PROFILER_QUERY_MODE_INVALID",
26014
26022
  PROFILER_QUERY_REQUIRED_PARAM_MISSING: "PROFILER_QUERY_REQUIRED_PARAM_MISSING",
26015
26023
  PROFILER_DATA_NOT_LOADED: "PROFILER_DATA_NOT_LOADED",
@@ -26270,7 +26278,7 @@ async function getResolvedToolsUrl() {
26270
26278
 
26271
26279
  // ../argent-tools-client/src/file-inputs.ts
26272
26280
  import { createHash as createHash2, randomUUID as randomUUID4 } from "node:crypto";
26273
- import { createReadStream, rmSync as rmSync2 } from "node:fs";
26281
+ import { createReadStream as createReadStream2, rmSync as rmSync2 } from "node:fs";
26274
26282
  import {
26275
26283
  chmod as chmod3,
26276
26284
  lstat,
@@ -26286,50 +26294,234 @@ import { constants, tmpdir } from "node:os";
26286
26294
  import * as path10 from "node:path";
26287
26295
 
26288
26296
  // ../archive/src/index.ts
26289
- import { execFile } from "node:child_process";
26290
- import { rm, readdir as readdir3 } from "node:fs/promises";
26291
- import { basename as basename4, dirname as dirname5, join as join9, posix as posix2, resolve as resolve6, sep as sep2 } from "node:path";
26292
- import { promisify } from "node:util";
26293
- var execFileAsync = promisify(execFile);
26297
+ import { spawn as spawn2 } from "node:child_process";
26298
+ import { once } from "node:events";
26299
+ import { createReadStream, createWriteStream } from "node:fs";
26300
+ import { open as open2, rm, readdir as readdir3 } from "node:fs/promises";
26301
+ import { basename as basename4, dirname as dirname5, join as join9, resolve as resolve6, sep as sep2 } from "node:path";
26302
+ import { Writable } from "node:stream";
26303
+ import { pipeline } from "node:stream/promises";
26304
+ import zlib from "node:zlib";
26294
26305
  var ArchiveError = class extends Error {
26295
26306
  };
26296
- function createTarGzArgs(sourcePath, target) {
26297
- return ["-czf", target, "-C", dirname5(sourcePath), basename4(sourcePath)];
26307
+ var ARCHIVE_FORMATS = typeof zlib.createZstdCompress === "function" ? ["zstd", "gzip"] : ["gzip"];
26308
+ var ARCHIVE_CONTENT_TYPES = {
26309
+ zstd: "application/zstd",
26310
+ gzip: "application/gzip"
26311
+ };
26312
+ function pickArchiveFormat(peerFormats) {
26313
+ return ARCHIVE_FORMATS.find((f) => peerFormats?.includes(f)) ?? "gzip";
26314
+ }
26315
+ var CHUNK_BYTES = 1 << 20;
26316
+ function createCompressor(format) {
26317
+ return format === "zstd" ? zlib.createZstdCompress({
26318
+ chunkSize: CHUNK_BYTES,
26319
+ // Lets the decoder detect corruption.
26320
+ params: { [zlib.constants.ZSTD_c_checksumFlag]: 1 }
26321
+ }) : zlib.createGzip({ chunkSize: CHUNK_BYTES });
26322
+ }
26323
+ function createTarArgs(sourcePath) {
26324
+ const name = basename4(sourcePath);
26325
+ return ["-cf", "-", "-C", dirname5(sourcePath), /^[-@]/.test(name) ? `./${name}` : name];
26326
+ }
26327
+ var MAX_LISTING_BYTES = 32 << 20;
26328
+ var MAX_LISTING_LINES = 1 << 18;
26329
+ var MAX_STDERR_BYTES = 16 << 10;
26330
+ var MAX_UNREAD_BYTES = 16 << 20;
26331
+ function collect(stream, maxBytes, { maxLines = Infinity, onOverflow } = {}) {
26332
+ const chunks = [];
26333
+ let bytes = 0;
26334
+ let lines = 0;
26335
+ let overflowed = false;
26336
+ stream?.on("data", (chunk) => {
26337
+ if (overflowed) return;
26338
+ chunks.push(chunk.subarray(0, maxBytes - bytes));
26339
+ bytes += chunk.length;
26340
+ for (let i = chunk.indexOf(10); i !== -1 && lines <= maxLines; i = chunk.indexOf(10, i + 1)) {
26341
+ lines++;
26342
+ }
26343
+ if (bytes > maxBytes || lines > maxLines) {
26344
+ overflowed = true;
26345
+ onOverflow?.();
26346
+ }
26347
+ });
26348
+ return {
26349
+ overflowed: () => overflowed,
26350
+ text: () => Buffer.concat(chunks).toString("utf8") + (overflowed ? "\u2026" : "")
26351
+ };
26298
26352
  }
26299
- async function createTarGzFile(sourcePath, tarPath) {
26353
+ async function createArchiveFile(sourcePath, archivePath, format, signal) {
26354
+ const out = createWriteStream(archivePath);
26355
+ await once(out, "ready");
26300
26356
  try {
26301
- await execFileAsync("tar", createTarGzArgs(sourcePath, tarPath));
26357
+ await archiveInto(out, sourcePath, format, signal);
26302
26358
  } catch (err) {
26303
- await rm(tarPath, { force: true }).catch(() => {
26359
+ out.destroy();
26360
+ await rm(archivePath, { force: true }).catch(() => {
26304
26361
  });
26362
+ signal?.throwIfAborted();
26305
26363
  throw err;
26306
26364
  }
26307
26365
  }
26366
+ async function archiveInto(out, sourcePath, format, signal) {
26367
+ const child = spawn2("tar", createTarArgs(sourcePath), {
26368
+ stdio: ["ignore", "pipe", "pipe"],
26369
+ signal
26370
+ });
26371
+ const exited = new Promise((res, rej) => {
26372
+ child.on("error", rej);
26373
+ child.on("close", res);
26374
+ });
26375
+ const stderr = collect(child.stderr, MAX_STDERR_BYTES);
26376
+ const [written, closed] = await Promise.allSettled([
26377
+ pipeline(child.stdout, createCompressor(format), out),
26378
+ exited
26379
+ ]);
26380
+ if (closed.status === "rejected") throw closed.reason;
26381
+ if (written.status === "rejected") throw written.reason;
26382
+ if (closed.value !== 0) {
26383
+ throw new Error(`tar exited with code ${closed.value}: ${stderr.text().trim()}`);
26384
+ }
26385
+ }
26386
+ async function sniffFormat(archivePath) {
26387
+ const fh = await open2(archivePath, "r");
26388
+ try {
26389
+ const { buffer, bytesRead } = await fh.read(Buffer.alloc(4), 0, 4, 0);
26390
+ const magic = buffer.subarray(0, bytesRead).toString("hex");
26391
+ if (magic.startsWith("1f8b")) return "gzip";
26392
+ if (magic === "28b52ffd" && ARCHIVE_FORMATS.includes("zstd")) return "zstd";
26393
+ throw new ArchiveError("unrecognized compression");
26394
+ } finally {
26395
+ await fh.close();
26396
+ }
26397
+ }
26398
+ var ZSTD_FRAME_MAGIC = 4247762216;
26399
+ async function assertSingleCompleteZstdFrame(archivePath) {
26400
+ const fh = await open2(archivePath, "r");
26401
+ try {
26402
+ const { size } = await fh.stat();
26403
+ const window = Buffer.alloc(4096);
26404
+ let windowStart = 0;
26405
+ let windowEnd = 0;
26406
+ let pos = 0;
26407
+ const read = async (n) => {
26408
+ if (pos < windowStart || pos + n > windowEnd) {
26409
+ const { bytesRead } = await fh.read(window, 0, window.length, pos);
26410
+ windowStart = pos;
26411
+ windowEnd = pos + bytesRead;
26412
+ if (bytesRead < n) throw new ArchiveError("truncated zstd frame");
26413
+ }
26414
+ return window.subarray(pos - windowStart, pos - windowStart + n);
26415
+ };
26416
+ for (let frame = 0; pos < size; frame++) {
26417
+ const header = await read(5);
26418
+ if (header.readUInt32LE(0) !== ZSTD_FRAME_MAGIC) throw new ArchiveError("bad zstd frame");
26419
+ const descriptor = header[4];
26420
+ const singleSegment = descriptor >> 5 & 1;
26421
+ pos += 5 + (singleSegment ? 0 : 1) + // window descriptor
26422
+ [0, 1, 2, 4][descriptor & 3] + // dictionary id
26423
+ [singleSegment, 2, 4, 8][descriptor >> 6];
26424
+ let hasData = false;
26425
+ for (let last = 0; !last; ) {
26426
+ const block = (await read(3)).readUIntLE(0, 3);
26427
+ last = block & 1;
26428
+ const type = block >> 1 & 3;
26429
+ const blockSize = block >> 3;
26430
+ if (blockSize > 0) hasData = true;
26431
+ pos += 3 + (type === 1 ? 1 : blockSize);
26432
+ }
26433
+ if (descriptor >> 2 & 1) pos += 4;
26434
+ if (hasData && frame > 0) throw new ArchiveError("multi-frame zstd");
26435
+ }
26436
+ if (pos !== size) throw new ArchiveError("truncated zstd frame");
26437
+ } finally {
26438
+ await fh.close();
26439
+ }
26440
+ }
26441
+ var TAR_LOCALE = process.platform === "darwin" ? "en_US.UTF-8" : "C.UTF-8";
26442
+ function tarEnv(env) {
26443
+ const characterType = env.LC_ALL || env.LC_CTYPE || env.LANG || "";
26444
+ return /utf-?8/i.test(characterType) ? env : { ...env, LC_ALL: TAR_LOCALE };
26445
+ }
26446
+ async function runTar(archive, args) {
26447
+ const child = spawn2("tar", [...args, "-f", "-"], {
26448
+ env: tarEnv(process.env)
26449
+ });
26450
+ const exited = new Promise((res, rej) => {
26451
+ child.on("error", rej);
26452
+ child.on("close", res);
26453
+ });
26454
+ const stdout = collect(child.stdout, MAX_LISTING_BYTES, {
26455
+ maxLines: MAX_LISTING_LINES,
26456
+ onOverflow: () => child.kill()
26457
+ });
26458
+ const stderr = collect(child.stderr, MAX_STDERR_BYTES);
26459
+ child.stdin?.on("error", () => {
26460
+ });
26461
+ const unreadLimit = new Error("unread limit");
26462
+ let unread = 0;
26463
+ const fed = pipeline(
26464
+ createReadStream(archive.path, { highWaterMark: CHUNK_BYTES }),
26465
+ archive.format === "zstd" ? zlib.createZstdDecompress({ chunkSize: CHUNK_BYTES }) : zlib.createGunzip({ chunkSize: CHUNK_BYTES }),
26466
+ new Writable({
26467
+ write(chunk, _encoding, done) {
26468
+ if (child.stdin?.writable) return void child.stdin.write(chunk, () => done());
26469
+ unread += chunk.length;
26470
+ done(unread > MAX_UNREAD_BYTES ? unreadLimit : null);
26471
+ },
26472
+ final(done) {
26473
+ child.stdin?.end();
26474
+ done();
26475
+ },
26476
+ destroy(err, done) {
26477
+ if (err) child.stdin?.destroy();
26478
+ done(err);
26479
+ }
26480
+ })
26481
+ ).then(
26482
+ () => null,
26483
+ (err) => err
26484
+ );
26485
+ const [code, feedError] = await Promise.all([exited, fed]);
26486
+ if (stdout.overflowed()) {
26487
+ throw new Error(
26488
+ `tar ${args.join(" ")} listed more than ${MAX_LISTING_LINES} members or ${MAX_LISTING_BYTES >> 20} MiB`
26489
+ );
26490
+ }
26491
+ if (feedError && feedError !== unreadLimit) throw feedError;
26492
+ if (code !== 0)
26493
+ throw new Error(`tar ${args.join(" ")} exited with code ${code}: ${stderr.text().trim()}`);
26494
+ return stdout.text();
26495
+ }
26308
26496
  function normalizeTarMemberPath(memberPath) {
26309
26497
  return memberPath.replace(/^\.\//, "").replace(/\\/g, "/");
26310
26498
  }
26499
+ function isContainedPath(path17, windows = process.platform === "win32") {
26500
+ const slashed = path17.replace(/\\/g, "/");
26501
+ const drive = windows ? /^[A-Za-z]:/ : /^[A-Za-z]:\//;
26502
+ return !slashed.startsWith("/") && !drive.test(slashed) && !slashed.split("/").includes("..");
26503
+ }
26311
26504
  function isSafeTarMember(memberPath, destDir) {
26312
26505
  const normalized = normalizeTarMemberPath(memberPath);
26313
- if (!normalized || normalized === "." || normalized === "./") return false;
26314
- if (normalized.startsWith("/") || /^[A-Za-z]:[\\/]/.test(normalized)) return false;
26315
- const relative2 = posix2.normalize(normalized);
26316
- if (relative2 === ".." || relative2.startsWith("../") || relative2.split("/").includes("..")) {
26317
- return false;
26318
- }
26506
+ if (!isContainedPath(normalized)) return false;
26319
26507
  const root = resolve6(destDir);
26320
- const resolved = resolve6(destDir, relative2);
26321
- return resolved === root || resolved.startsWith(root + sep2);
26508
+ return resolve6(destDir, normalized).startsWith(root + sep2);
26322
26509
  }
26323
- async function listTarMembers(tarPath) {
26324
- const { stdout } = await execFileAsync("tar", ["-tzf", tarPath]);
26325
- return stdout.split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
26510
+ async function readListing(archive, args) {
26511
+ try {
26512
+ return await runTar(archive, args);
26513
+ } catch (err) {
26514
+ throw new ArchiveError(
26515
+ `Could not read archive: ${err instanceof Error ? err.message : String(err)}`
26516
+ );
26517
+ }
26326
26518
  }
26327
- function isEscapingLinkTarget(target) {
26328
- if (target.startsWith("/") || /^[A-Za-z]:[\\/]/.test(target)) return true;
26329
- return posix2.normalize(target.replace(/\\/g, "/")).split("/").includes("..");
26519
+ async function listTarMembers(archive) {
26520
+ const stdout = await readListing(archive, ["-t"]);
26521
+ return stdout.split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
26330
26522
  }
26331
- async function assertSafeMemberTypes(tarPath) {
26332
- const { stdout } = await execFileAsync("tar", ["-tzvf", tarPath]);
26523
+ async function assertSafeMemberTypes(archive) {
26524
+ const stdout = await readListing(archive, ["-tv"]);
26333
26525
  for (const line of stdout.split("\n")) {
26334
26526
  if (!line.trim()) continue;
26335
26527
  const type = line[0];
@@ -26337,7 +26529,7 @@ async function assertSafeMemberTypes(tarPath) {
26337
26529
  if (type === "l") {
26338
26530
  const parts = line.split(" -> ");
26339
26531
  const target = parts.length === 2 ? parts[1].trim() : "";
26340
- if (parts.length !== 2 || !target || isEscapingLinkTarget(target)) {
26532
+ if (parts.length !== 2 || !target || !isContainedPath(target)) {
26341
26533
  throw new ArchiveError(
26342
26534
  `Archive contains a symlink whose target could not be confirmed safe: "${line.trim()}".`
26343
26535
  );
@@ -26349,15 +26541,8 @@ async function assertSafeMemberTypes(tarPath) {
26349
26541
  );
26350
26542
  }
26351
26543
  }
26352
- async function assertSafeArchive(tarPath, destDir) {
26353
- let members2;
26354
- try {
26355
- members2 = await listTarMembers(tarPath);
26356
- } catch (err) {
26357
- throw new ArchiveError(
26358
- `Could not read archive: ${err instanceof Error ? err.message : String(err)}`
26359
- );
26360
- }
26544
+ async function assertSafeArchive(archive, destDir) {
26545
+ const members2 = await listTarMembers(archive);
26361
26546
  if (members2.length === 0) {
26362
26547
  throw new ArchiveError("Archive is empty.");
26363
26548
  }
@@ -26366,7 +26551,7 @@ async function assertSafeArchive(tarPath, destDir) {
26366
26551
  throw new ArchiveError(`Archive contains an unsafe path "${member}" \u2014 refusing extraction.`);
26367
26552
  }
26368
26553
  }
26369
- await assertSafeMemberTypes(tarPath);
26554
+ await assertSafeMemberTypes(archive);
26370
26555
  }
26371
26556
  async function resolveMember(destDir, expectedName) {
26372
26557
  const entries = await readdir3(destDir);
@@ -26381,9 +26566,18 @@ async function resolveMember(destDir, expectedName) {
26381
26566
  }
26382
26567
  return join9(destDir, real[0]);
26383
26568
  }
26384
- async function safeExtractTarGz(tarPath, destDir, expectedName) {
26385
- await assertSafeArchive(tarPath, destDir);
26386
- await execFileAsync("tar", ["-xzf", tarPath, "-C", destDir]);
26569
+ async function safeExtractArchive(archivePath, destDir, expectedName) {
26570
+ let archive;
26571
+ try {
26572
+ archive = { path: archivePath, format: await sniffFormat(archivePath) };
26573
+ if (archive.format === "zstd") await assertSingleCompleteZstdFrame(archivePath);
26574
+ } catch (err) {
26575
+ throw new ArchiveError(
26576
+ `Could not read archive: ${err instanceof Error ? err.message : String(err)}`
26577
+ );
26578
+ }
26579
+ await assertSafeArchive(archive, destDir);
26580
+ await runTar(archive, ["-x", "-C", destDir]);
26387
26581
  return resolveMember(destDir, expectedName);
26388
26582
  }
26389
26583
 
@@ -26464,7 +26658,7 @@ function untrackArchive(archive) {
26464
26658
  function sha256File(filePath) {
26465
26659
  return new Promise((resolve10, reject) => {
26466
26660
  const hash = createHash2("sha256");
26467
- createReadStream(filePath).on("data", (chunk) => hash.update(chunk)).on("end", () => resolve10(hash.digest("hex"))).on("error", reject);
26661
+ createReadStream2(filePath).on("data", (chunk) => hash.update(chunk)).on("end", () => resolve10(hash.digest("hex"))).on("error", reject);
26468
26662
  });
26469
26663
  }
26470
26664
  function toolServerError(text) {
@@ -26490,15 +26684,15 @@ function uploadFailure(url, res, text, bytes) {
26490
26684
  errorKind: "validation"
26491
26685
  });
26492
26686
  }
26493
- async function uploadTar(tarPath, endpoint, signal) {
26687
+ async function uploadTar(tarPath, format, endpoint, signal) {
26494
26688
  const { size } = await stat3(tarPath);
26495
26689
  const init = {
26496
26690
  method: "POST",
26497
26691
  headers: {
26498
- "content-type": "application/gzip",
26692
+ "content-type": ARCHIVE_CONTENT_TYPES[format],
26499
26693
  ...endpoint.token ? { Authorization: `Bearer ${endpoint.token}` } : {}
26500
26694
  },
26501
- body: createReadStream(tarPath),
26695
+ body: createReadStream2(tarPath),
26502
26696
  duplex: "half",
26503
26697
  signal
26504
26698
  };
@@ -26515,12 +26709,13 @@ async function uploadTar(tarPath, endpoint, signal) {
26515
26709
  return json.uploadId;
26516
26710
  }
26517
26711
  async function uploadFile(sourcePath, endpoint, signal) {
26712
+ const format = pickArchiveFormat(endpoint.formats);
26518
26713
  const tarPath = path10.join(tmpdir(), `argent-upload-${randomUUID4()}.tar.gz`);
26519
26714
  trackArchive(tarPath);
26520
26715
  try {
26521
- await createTarGzFile(await realpath2(sourcePath), tarPath);
26716
+ await createArchiveFile(await realpath2(sourcePath), tarPath, format, signal);
26522
26717
  const contentHash = await sha256File(tarPath);
26523
- return { uploadId: await uploadTar(tarPath, endpoint, signal), contentHash };
26718
+ return { uploadId: await uploadTar(tarPath, format, endpoint, signal), contentHash };
26524
26719
  } finally {
26525
26720
  untrackArchive(tarPath);
26526
26721
  await rm2(tarPath, { force: true }).catch(() => {
@@ -27375,7 +27570,7 @@ function createToolsClient(options = {}) {
27375
27570
  const { url, token } = await route();
27376
27571
  return { url, token };
27377
27572
  }
27378
- async function fetchTools(opts) {
27573
+ async function fetchToolList(opts) {
27379
27574
  opts?.signal?.throwIfAborted();
27380
27575
  const { url, token } = await baseUrl();
27381
27576
  const res = await doFetch(
@@ -27384,8 +27579,10 @@ function createToolsClient(options = {}) {
27384
27579
  { longRunning: false, carriesUpload: false }
27385
27580
  );
27386
27581
  if (!res.ok) throw new Error(`GET /tools failed: ${res.status} ${res.statusText}`);
27387
- const json = await res.json();
27388
- return json.tools;
27582
+ return await res.json();
27583
+ }
27584
+ async function fetchTools(opts) {
27585
+ return (await fetchToolList(opts)).tools;
27389
27586
  }
27390
27587
  async function fetchTool(name, opts) {
27391
27588
  return findTool(await fetchTools(opts), name);
@@ -27394,7 +27591,7 @@ function createToolsClient(options = {}) {
27394
27591
  opts?.signal?.throwIfAborted();
27395
27592
  const { url, token, remote } = await route();
27396
27593
  let finalArgs = canonicalToolArgs(name, args);
27397
- const tools = await fetchTools({ signal: opts?.signal });
27594
+ const { tools, uploadFormats } = await fetchToolList({ signal: opts?.signal });
27398
27595
  const meta2 = findTool(tools, name);
27399
27596
  const olderServer = meta2 !== null && !tools.some((t) => t.name === canonicalToolId(meta2.name));
27400
27597
  if (meta2) {
@@ -27411,7 +27608,7 @@ function createToolsClient(options = {}) {
27411
27608
  if (remote) assertRequiredPresent(meta2, finalArgs);
27412
27609
  finalArgs = await prepareFileInputs(meta2.fileInputs, finalArgs ?? {}, {
27413
27610
  includeContent: remote,
27414
- uploadEndpoint: remote ? { url, token } : void 0,
27611
+ uploadEndpoint: remote ? { url, token, formats: uploadFormats } : void 0,
27415
27612
  log: diagnose,
27416
27613
  baselineDirs,
27417
27614
  collectMembers: collectFlowMembers,
@@ -27708,7 +27905,7 @@ async function downloadAndExtractArchive(handle, data, dir) {
27708
27905
  const tarball = join13(dir, `${sanitizeSegment(handle.filename)}.tar.gz`);
27709
27906
  try {
27710
27907
  await writeFile4(tarball, data);
27711
- return await safeExtractTarGz(tarball, dir, handle.filename);
27908
+ return await safeExtractArchive(tarball, dir, handle.filename);
27712
27909
  } catch {
27713
27910
  return null;
27714
27911
  } finally {
@@ -27787,7 +27984,10 @@ async function materializeArtifacts(result, ctx) {
27787
27984
  }
27788
27985
  try {
27789
27986
  const res = await fetchFn(`${ctx.toolsUrl}/artifacts/${value.id}`, {
27790
- headers: authHeaders3,
27987
+ headers: value.archive ? {
27988
+ ...authHeaders3,
27989
+ Accept: ARCHIVE_FORMATS.map((f) => ARCHIVE_CONTENT_TYPES[f]).join(", ")
27990
+ } : authHeaders3,
27791
27991
  signal: ctx.signal
27792
27992
  });
27793
27993
  if (!res.ok) return null;
@@ -28536,7 +28736,7 @@ import * as fs8 from "node:fs";
28536
28736
  import * as path14 from "node:path";
28537
28737
 
28538
28738
  // ../telemetry/src/fingerprint.ts
28539
- import { execFileSync as execFileSync2, spawn as spawn2 } from "node:child_process";
28739
+ import { execFileSync as execFileSync2, spawn as spawn3 } from "node:child_process";
28540
28740
 
28541
28741
  // ../native-devtools-ios/src/index.ts
28542
28742
  import * as path15 from "node:path";
@@ -29006,6 +29206,53 @@ function getAutoScreenshotDelayMs(toolName) {
29006
29206
  return base;
29007
29207
  }
29008
29208
 
29209
+ // ../argent-mcp/src/unchanged-tree.ts
29210
+ import { randomInt } from "node:crypto";
29211
+ var MAX_UNCHANGED_IN_A_ROW = 3;
29212
+ var UNCHANGED_MAX_AGE_MS = 5 * 6e4;
29213
+ function treeIdLine(id) {
29214
+ return `Tree id: ${id}`;
29215
+ }
29216
+ function unchangedTreeNote(id, tool) {
29217
+ return `Identical to element tree \`${id}\`, which an earlier \`${tool}\` result returned, so it is not repeated here: take elements and frames from that tree. The action can still have had an effect that the tree does not show, such as text typed in a field. Call \`describe\` if you do not have tree \`${id}\`.`;
29218
+ }
29219
+ function randomTag() {
29220
+ return randomInt(36 ** 3).toString(36).padStart(3, "0");
29221
+ }
29222
+ function createTreeMemory(now = Date.now, tag = randomTag()) {
29223
+ const lastSent = /* @__PURE__ */ new Map();
29224
+ let count = 0;
29225
+ const sent = (udid, tree, toolName) => {
29226
+ const id = `${tag}-${++count}`;
29227
+ lastSent.set(udid, { id, tree, tool: normalizeToolName(toolName), sentAt: now(), notes: 0 });
29228
+ return id;
29229
+ };
29230
+ return {
29231
+ sent,
29232
+ afterAction(udid, tree, toolName) {
29233
+ const last = lastSent.get(udid);
29234
+ const identical = last !== void 0 && last.tree === tree;
29235
+ if (last !== void 0 && identical && last.notes < MAX_UNCHANGED_IN_A_ROW && now() - last.sentAt <= UNCHANGED_MAX_AGE_MS) {
29236
+ last.notes += 1;
29237
+ return { text: unchangedTreeNote(last.id, last.tool), identical, note: true };
29238
+ }
29239
+ const id = sent(udid, tree, toolName);
29240
+ return { text: `${treeIdLine(id)}
29241
+ ${tree}`, identical, note: false };
29242
+ },
29243
+ forget(udid) {
29244
+ lastSent.delete(udid);
29245
+ }
29246
+ };
29247
+ }
29248
+ function describedTree(result) {
29249
+ const { description, hint } = result ?? {};
29250
+ if (typeof description !== "string" || description.length === 0) return void 0;
29251
+ const hintLine = typeof hint === "string" && hint && !description.includes(hint) ? `Hint: ${hint}
29252
+ ` : "";
29253
+ return `${hintLine}${description}`;
29254
+ }
29255
+
29009
29256
  // ../argent-mcp/src/keyword-facts.ts
29010
29257
  var SHOWS_KEYWORDS = [
29011
29258
  /^claude-code\b/,
@@ -29244,7 +29491,7 @@ ${stopped.join("\n")}`;
29244
29491
  }
29245
29492
 
29246
29493
  // ../argent-mcp/src/instructions.ts
29247
- var SERVER_INSTRUCTIONS = "Argent \u2014 iOS Simulator, Android Emulator, and Chromium app control for interacting, testing, profiling and debugging mobile and Chromium applications. Interaction tools return the screen after the action: a screenshot plus the accessibility element tree with normalized tap frames. Take coordinates from that tree; call describe only when no fresh tree is available \u2014 never guess coordinates from pixels. Do not stop simulator servers when a task finishes: the next task reuses them. Call stop-all-simulator-servers when the user asks to clean up or ends the session, or when a skill tells you to recycle a device's services, always with devices: [...] naming the devices this session used. Never stop a Metro the user started unless they ask. One tool-server is shared by every agent using this argent install, so an unscoped call tears down their devices too \u2014 reserve it for a deliberate machine-wide cleanup.";
29494
+ var SERVER_INSTRUCTIONS = "Argent \u2014 iOS Simulator, Android Emulator, and Chromium app control for interacting, testing, profiling and debugging mobile and Chromium applications. Interaction tools return the screen after the action: a screenshot plus the accessibility element tree with normalized tap frames. Take coordinates from that tree; call describe only when no fresh tree is available \u2014 never guess coordinates from pixels. A result names an identical earlier tree by its tree id in place of repeating it. Do not stop simulator servers when a task finishes: the next task reuses them. Call stop-all-simulator-servers when the user asks to clean up or ends the session, or when a skill tells you to recycle a device's services, always with devices: [...] naming the devices this session used. Never stop a Metro the user started unless they ask. One tool-server is shared by every agent using this argent install, so an unscoped call tears down their devices too \u2014 reserve it for a deliberate machine-wide cleanup.";
29248
29495
 
29249
29496
  // ../argent-mcp/src/installed-version.ts
29250
29497
  import * as fs11 from "node:fs";
@@ -29379,6 +29626,7 @@ async function startMcpServer(options) {
29379
29626
  const autoScreenshotOn = autoScreenshotEnabled();
29380
29627
  const autoDescribeOn = autoDescribeEnabled();
29381
29628
  const captureTimeoutMs = options.captureTimeoutMs ?? CAPTURE_TIMEOUT_MS;
29629
+ const trees = createTreeMemory();
29382
29630
  let TOOLS_URL;
29383
29631
  let AUTH_TOKEN;
29384
29632
  const resolved = await getResolvedToolsUrl();
@@ -29480,19 +29728,21 @@ async function startMcpServer(options) {
29480
29728
  const t1 = Date.now();
29481
29729
  try {
29482
29730
  const d = await callTool("describe", { udid }, { signal });
29483
- const { description: desc, hint } = d.result ?? {};
29731
+ const tree = describedTree(d.result);
29732
+ const shown = tree === void 0 ? void 0 : trees.afterAction(udid, tree, toolName);
29484
29733
  await spyLog({
29485
29734
  ts: (/* @__PURE__ */ new Date()).toISOString(),
29486
29735
  event: "auto_describe",
29487
29736
  name: toolName,
29488
29737
  durationMs: Date.now() - t1,
29489
- chars: typeof desc === "string" ? desc.length : 0
29738
+ chars: tree?.length ?? 0,
29739
+ // `identical` is the repeat rate; `note` is what the agent was spared.
29740
+ identical: shown?.identical ?? false,
29741
+ note: shown?.note ?? false
29490
29742
  });
29491
- if (typeof desc !== "string" || desc.length === 0) return [];
29492
- const hintLine = typeof hint === "string" && hint && !desc.includes(hint) ? `Hint: ${hint}
29493
- ` : "";
29743
+ if (shown === void 0) return [];
29494
29744
  return [{ type: "text", text: `${AUTO_DESCRIBE_HEADER}
29495
- ${hintLine}${desc}` }];
29745
+ ${shown.text}` }];
29496
29746
  } catch (e) {
29497
29747
  await spyLog({
29498
29748
  ts: (/* @__PURE__ */ new Date()).toISOString(),
@@ -29530,8 +29780,9 @@ ${hintLine}${desc}` }];
29530
29780
  return { tools: [] };
29531
29781
  }
29532
29782
  });
29533
- server.setRequestHandler(CallToolRequestSchema, async ({ params }) => {
29783
+ server.setRequestHandler(CallToolRequestSchema, async ({ params }, { signal: cancelled }) => {
29534
29784
  const t0 = Date.now();
29785
+ let treeUdid;
29535
29786
  await spyLog({
29536
29787
  ts: (/* @__PURE__ */ new Date()).toISOString(),
29537
29788
  event: "tool_called",
@@ -29565,6 +29816,14 @@ ${hintLine}${desc}` }];
29565
29816
  content = await toMcpContent(result, outputHint, ctx, params.arguments);
29566
29817
  }
29567
29818
  const udid = getUdidFromArgs(params.arguments);
29819
+ if (udid && autoDescribeOn && canonicalToolId(params.name) === "describe") {
29820
+ const tree = describedTree(result);
29821
+ if (tree !== void 0) {
29822
+ treeUdid = udid;
29823
+ const id = trees.sent(udid, tree, "describe");
29824
+ content = [...content, { type: "text", text: treeIdLine(id) }];
29825
+ }
29826
+ }
29568
29827
  const wantScreenshot = autoScreenshotOn && shouldAutoScreenshot(params.name, params.arguments);
29569
29828
  const wantTree = autoDescribeOn && shouldAutoDescribe(params.name, params.arguments);
29570
29829
  if (udid && (wantScreenshot || wantTree) && containsSecretPlaceholder(params.arguments)) {
@@ -29585,14 +29844,17 @@ ${hintLine}${desc}` }];
29585
29844
  const signal = AbortSignal.timeout(captureTimeoutMs);
29586
29845
  const screenshot = wantScreenshot ? captureScreenshotBlocks(udid, signal) : Promise.resolve([]);
29587
29846
  if (!screenSettled) await screenshot;
29847
+ if (wantTree) treeUdid = udid;
29588
29848
  const tree = wantTree ? captureTreeBlocks(udid, params.name, signal) : Promise.resolve([]);
29589
29849
  content = [...content, ...await screenshot, ...await tree];
29590
29850
  }
29591
29851
  if (note) {
29592
29852
  content = [{ type: "text", text: note }, ...content];
29593
29853
  }
29854
+ if (treeUdid !== void 0 && cancelled.aborted) trees.forget(treeUdid);
29594
29855
  return { content };
29595
29856
  } catch (err) {
29857
+ if (treeUdid !== void 0) trees.forget(treeUdid);
29596
29858
  await spyLog({
29597
29859
  ts: (/* @__PURE__ */ new Date()).toISOString(),
29598
29860
  event: "tool_result",