@swmansion/argent 0.35.1-next.2 → 0.35.1-next.4

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/dist/cli-cmds.mjs CHANGED
@@ -38575,7 +38575,7 @@ function isCi(env = process.env) {
38575
38575
  var SESSION_ID2 = randomUUID5();
38576
38576
  function readCliVersion() {
38577
38577
  if (true) {
38578
- return "0.35.1-next.2";
38578
+ return "0.35.1-next.4";
38579
38579
  }
38580
38580
  return "0.0.0";
38581
38581
  }
@@ -16998,7 +16998,7 @@ function isCi(env = process.env) {
16998
16998
  var SESSION_ID = randomUUID4();
16999
16999
  function readCliVersion() {
17000
17000
  if (true) {
17001
- return "0.35.1-next.2";
17001
+ return "0.35.1-next.4";
17002
17002
  }
17003
17003
  return "0.0.0";
17004
17004
  }
@@ -95,6 +95,8 @@ export interface ArgentToolArgs {
95
95
  readOnly?: boolean;
96
96
  /** Android only: the emulator's console port, an even number from 5554 to 5584 (`emulator -port`), the range adb finds emulators in; its serial is `emulator-<port>`. Without it the emulator takes the first free port from 5554 up, as Android Studio does. The gRPC server Argent needs for screenshots and gestures goes on the port plus 3000, which must be free too. Given a port, the tool reuses only the emulator on that port and fails if another emulator holds it, or if this AVD runs there writable on a read-only boot and `force` is not set. A read-only emulator started with `-port` belongs to the calls that give that port: a call without `port` never reuses or shuts it down. Where the process list cannot be read (Windows, or a failed `ps`), Argent knows only the pinned emulators it booted itself, so a writable call without `port` can reuse, or with `force` shut down, one that someone else pinned. A writable one is still reused, or with `force` shut down, by a writable call without `port`, since the AVD runs one writable emulator at a time. `force` shuts nothing down when another emulator of the AVD would still block the boot. Ignored on other platforms. */
97
97
  port?: number;
98
+ /** Local iOS simulator only: apply accessibility preferences and leave the simulator shut down for a pool manager to boot. Requires Shutdown state. Cannot be combined with force: true. */
99
+ prepareOnly?: boolean;
98
100
  /** iOS only: boot the simulator core WITHOUT opening its GUI window (Simulator.app, or Device Hub on Xcode 27+). The device still streams via simulator-server. The `ARGENT_SIMULATOR_NO_WINDOW` env var (1/true/yes) forces this host-wide. */
99
101
  headless?: boolean;
100
102
  /** Electron: path to the Electron app to launch. Either a packaged .app bundle / executable, or a project directory whose package.json points the Electron binary at the entry script. */
@@ -72948,7 +72948,7 @@ function isCi(env = process.env) {
72948
72948
  var SESSION_ID = (0, import_node_crypto3.randomUUID)();
72949
72949
  function readCliVersion() {
72950
72950
  if (true) {
72951
- return "0.35.1-next.2";
72951
+ return "0.35.1-next.4";
72952
72952
  }
72953
72953
  return "0.0.0";
72954
72954
  }
@@ -75448,7 +75448,267 @@ function nativeArgs(udid, args) {
75448
75448
  return args.map((argument) => argument === udid ? nativeId : argument);
75449
75449
  }
75450
75450
 
75451
+ // ../tool-server/src/utils/ios-device/usbmux-protocol.ts
75452
+ var USBMUX_HEADER_BYTES = 16;
75453
+ var USBMUX_PROTOCOL_VERSION = 1;
75454
+ var USBMUX_MESSAGE_TYPE_PLIST = 8;
75455
+ var USBMUX_MAX_PACKET_BYTES = 4 * 1024 * 1024;
75456
+ function appendHintToMessage(message, hint) {
75457
+ if (!hint || message.includes(hint)) {
75458
+ return message;
75459
+ }
75460
+ return `${message}${/[.!?]$/.test(message) ? "" : "."} Hint: ${hint}`;
75461
+ }
75462
+ var IosDeviceTransportError = class extends Error {
75463
+ kind;
75464
+ retryable;
75465
+ hint;
75466
+ constructor(kind, message, options = { retryable: false }) {
75467
+ super(
75468
+ appendHintToMessage(message, options.hint),
75469
+ options.cause !== void 0 ? { cause: options.cause } : void 0
75470
+ );
75471
+ this.name = "IosDeviceTransportError";
75472
+ this.kind = kind;
75473
+ this.retryable = options.retryable;
75474
+ if (options.hint !== void 0) {
75475
+ this.hint = options.hint;
75476
+ }
75477
+ }
75478
+ };
75479
+ function isIosDeviceTransportError(error63) {
75480
+ return error63 instanceof IosDeviceTransportError;
75481
+ }
75482
+ function encodeUsbmuxPacket(tag3, payloadXml) {
75483
+ const payload = Buffer.from(payloadXml, "utf8");
75484
+ const packet = Buffer.alloc(USBMUX_HEADER_BYTES + payload.length);
75485
+ packet.writeUInt32LE(packet.length, 0);
75486
+ packet.writeUInt32LE(USBMUX_PROTOCOL_VERSION, 4);
75487
+ packet.writeUInt32LE(USBMUX_MESSAGE_TYPE_PLIST, 8);
75488
+ packet.writeUInt32LE(tag3, 12);
75489
+ payload.copy(packet, USBMUX_HEADER_BYTES);
75490
+ return packet;
75491
+ }
75492
+ function decodeUsbmuxPacket(buffer) {
75493
+ if (buffer.length < USBMUX_HEADER_BYTES) {
75494
+ return null;
75495
+ }
75496
+ const totalLength = buffer.readUInt32LE(0);
75497
+ if (totalLength < USBMUX_HEADER_BYTES || totalLength > USBMUX_MAX_PACKET_BYTES) {
75498
+ throw new IosDeviceTransportError(
75499
+ "protocol",
75500
+ `Invalid usbmuxd packet length ${totalLength} (must be between ${USBMUX_HEADER_BYTES} and ${USBMUX_MAX_PACKET_BYTES} bytes)`,
75501
+ { retryable: false }
75502
+ );
75503
+ }
75504
+ if (buffer.length < totalLength) {
75505
+ return null;
75506
+ }
75507
+ return {
75508
+ version: buffer.readUInt32LE(4),
75509
+ messageType: buffer.readUInt32LE(8),
75510
+ tag: buffer.readUInt32LE(12),
75511
+ payload: buffer.subarray(USBMUX_HEADER_BYTES, totalLength),
75512
+ bytesConsumed: totalLength
75513
+ };
75514
+ }
75515
+ function hostToNetworkPort(port) {
75516
+ if (!Number.isInteger(port) || port < 0 || port > 65535) {
75517
+ throw new IosDeviceTransportError("protocol", `Invalid TCP port ${port}`, {
75518
+ retryable: false
75519
+ });
75520
+ }
75521
+ return (port & 255) << 8 | port >>> 8 & 255;
75522
+ }
75523
+ function escapeXmlText(value) {
75524
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
75525
+ }
75526
+ function buildUsbmuxPlistMessage(messageType, fields = {}) {
75527
+ const entries = [
75528
+ ["BundleID", "com.argent.tool-server"],
75529
+ ["ClientVersionString", "argent"],
75530
+ ["MessageType", messageType],
75531
+ ["ProgName", "argent"],
75532
+ ["kLibUSBMuxVersion", 3],
75533
+ ...Object.entries(fields)
75534
+ ];
75535
+ const body = entries.map(
75536
+ ([key2, value]) => typeof value === "number" ? `<key>${escapeXmlText(key2)}</key><integer>${value}</integer>` : `<key>${escapeXmlText(key2)}</key><string>${escapeXmlText(value)}</string>`
75537
+ ).join("");
75538
+ return `<?xml version="1.0" encoding="UTF-8"?><plist version="1.0"><dict>${body}</dict></plist>`;
75539
+ }
75540
+ function parsePlist(xml) {
75541
+ const elements = parseXmlElements(xml);
75542
+ const plist = elements.find((element) => element.name === "plist");
75543
+ const root = plist ? plist.children[0] : elements[0];
75544
+ if (!root) {
75545
+ throw new IosDeviceTransportError("protocol", "Empty plist document from usbmuxd", {
75546
+ retryable: false
75547
+ });
75548
+ }
75549
+ return convertPlistElement(root);
75550
+ }
75551
+ function readUsbmuxResultCode(xml) {
75552
+ const root = parsePlistOrUndefined(xml);
75553
+ if (!isPlistDict(root)) {
75554
+ return void 0;
75555
+ }
75556
+ const value = root["Number"];
75557
+ return typeof value === "number" && Number.isSafeInteger(value) ? value : void 0;
75558
+ }
75559
+ function readUsbmuxDeviceIdForSerial(xml, serial) {
75560
+ const root = parsePlistOrUndefined(xml);
75561
+ if (!isPlistDict(root)) {
75562
+ return void 0;
75563
+ }
75564
+ const list = root["DeviceList"];
75565
+ if (!Array.isArray(list)) {
75566
+ return void 0;
75567
+ }
75568
+ let fallbackDeviceId;
75569
+ for (const entry of list) {
75570
+ if (!isPlistDict(entry)) {
75571
+ continue;
75572
+ }
75573
+ const properties = entry["Properties"];
75574
+ if (!isPlistDict(properties)) {
75575
+ continue;
75576
+ }
75577
+ if (properties["SerialNumber"] !== serial) {
75578
+ continue;
75579
+ }
75580
+ const deviceId = entry["DeviceID"];
75581
+ if (typeof deviceId !== "number" || !Number.isSafeInteger(deviceId) || deviceId <= 0) {
75582
+ continue;
75583
+ }
75584
+ if (properties["ConnectionType"] === "USB") {
75585
+ return deviceId;
75586
+ }
75587
+ fallbackDeviceId ??= deviceId;
75588
+ }
75589
+ return fallbackDeviceId;
75590
+ }
75591
+ function parsePlistOrUndefined(xml) {
75592
+ try {
75593
+ return parsePlist(xml);
75594
+ } catch {
75595
+ return void 0;
75596
+ }
75597
+ }
75598
+ function isPlistDict(value) {
75599
+ return typeof value === "object" && value !== null && !Array.isArray(value);
75600
+ }
75601
+ function parseXmlElements(xml) {
75602
+ const source = xml.replace(/<\?xml[\s\S]*?\?>/g, "").replace(/<!DOCTYPE[^>]*>/gi, "");
75603
+ const tokenPattern = /<(\/?)([A-Za-z][\w.-]*)((?:\s[^<>]*?)?)(\/?)>|([^<]+)/g;
75604
+ const root = { name: "#root", text: "", children: [] };
75605
+ const stack = [root];
75606
+ let consumed = 0;
75607
+ for (let match = tokenPattern.exec(source); match !== null; match = tokenPattern.exec(source)) {
75608
+ if (match.index !== consumed) {
75609
+ break;
75610
+ }
75611
+ consumed = tokenPattern.lastIndex;
75612
+ const [, closing, name, , selfClosing, textChunk] = match;
75613
+ const top = stack[stack.length - 1];
75614
+ if (textChunk !== void 0) {
75615
+ top.text += decodeXmlEntities(textChunk);
75616
+ continue;
75617
+ }
75618
+ if (closing) {
75619
+ if (stack.length < 2 || top.name !== name) {
75620
+ throw invalidXmlError(`unexpected closing tag </${name}>`);
75621
+ }
75622
+ stack.pop();
75623
+ continue;
75624
+ }
75625
+ const element = { name, text: "", children: [] };
75626
+ top.children.push(element);
75627
+ if (!selfClosing) {
75628
+ stack.push(element);
75629
+ }
75630
+ }
75631
+ if (consumed !== source.length) {
75632
+ throw invalidXmlError("malformed markup");
75633
+ }
75634
+ if (stack.length !== 1) {
75635
+ throw invalidXmlError(`unclosed tag <${stack[stack.length - 1].name}>`);
75636
+ }
75637
+ return root.children;
75638
+ }
75639
+ function convertPlistElement(element) {
75640
+ switch (element.name) {
75641
+ case "dict":
75642
+ return convertPlistDict(element);
75643
+ case "array":
75644
+ return element.children.map(convertPlistElement);
75645
+ case "string":
75646
+ return element.text;
75647
+ case "integer":
75648
+ case "real": {
75649
+ const parsed2 = Number(element.text.trim());
75650
+ if (!Number.isFinite(parsed2)) {
75651
+ throw invalidXmlError(`non-numeric <${element.name}> value "${element.text}"`);
75652
+ }
75653
+ return parsed2;
75654
+ }
75655
+ case "true":
75656
+ return true;
75657
+ case "false":
75658
+ return false;
75659
+ case "data":
75660
+ case "date":
75661
+ return element.text.trim();
75662
+ default:
75663
+ throw invalidXmlError(`unsupported plist node <${element.name}>`);
75664
+ }
75665
+ }
75666
+ function convertPlistDict(element) {
75667
+ const dict = {};
75668
+ for (let index = 0; index < element.children.length - 1; index += 1) {
75669
+ const key2 = element.children[index];
75670
+ if (key2.name !== "key") {
75671
+ continue;
75672
+ }
75673
+ const value = element.children[index + 1];
75674
+ if (value.name === "key") {
75675
+ continue;
75676
+ }
75677
+ dict[key2.text] = convertPlistElement(value);
75678
+ index += 1;
75679
+ }
75680
+ return dict;
75681
+ }
75682
+ function decodeXmlEntities(text) {
75683
+ return text.replace(/&(#x?[0-9a-fA-F]+|[a-z]+);/g, (entity, body) => {
75684
+ if (body.startsWith("#x") || body.startsWith("#X")) {
75685
+ return String.fromCodePoint(Number.parseInt(body.slice(2), 16));
75686
+ }
75687
+ if (body.startsWith("#")) {
75688
+ return String.fromCodePoint(Number.parseInt(body.slice(1), 10));
75689
+ }
75690
+ const named = {
75691
+ amp: "&",
75692
+ lt: "<",
75693
+ gt: ">",
75694
+ quot: '"',
75695
+ apos: "'"
75696
+ };
75697
+ return named[body] ?? entity;
75698
+ });
75699
+ }
75700
+ function invalidXmlError(detail) {
75701
+ return new IosDeviceTransportError("protocol", `Invalid plist XML from usbmuxd: ${detail}`, {
75702
+ retryable: false
75703
+ });
75704
+ }
75705
+
75451
75706
  // ../tool-server/src/utils/ax-prefs.ts
75707
+ var PRE_BOOT_ACCESSIBILITY_KEYS = [
75708
+ "IgnoreAXServerEntitlements",
75709
+ "AccessibilityEnabled",
75710
+ "ApplicationAccessibilityEnabled"
75711
+ ];
75452
75712
  var execFileAsync8 = (0, import_node_util8.promisify)(import_node_child_process11.execFile);
75453
75713
  async function accessibilityDefaults(udid, verb, ...args) {
75454
75714
  const { stdout } = await execFileAsync8(
@@ -75469,16 +75729,15 @@ async function accessibilityDefaults(udid, verb, ...args) {
75469
75729
  async function ensureAutomationEnabled(udid) {
75470
75730
  await accessibilityDefaults(udid, "write", "AutomationEnabled", "-bool", "true");
75471
75731
  }
75472
- async function hasAutomationEnabled(udid) {
75473
- const plist = await accessibilityDefaults(udid, "export", "-");
75732
+ function hasAutomationEnabled(plist) {
75474
75733
  return plist.includes("<key>AutomationEnabled</key>");
75475
75734
  }
75476
- async function clearAutomationEnabled(udid) {
75477
- if (!await hasAutomationEnabled(udid)) return;
75735
+ async function clearAutomationEnabled(udid, plist) {
75736
+ if (!hasAutomationEnabled(plist ?? await accessibilityDefaults(udid, "export", "-"))) return;
75478
75737
  try {
75479
75738
  await accessibilityDefaults(udid, "delete", "AutomationEnabled");
75480
75739
  } catch (err) {
75481
- if (await hasAutomationEnabled(udid)) throw err;
75740
+ if (hasAutomationEnabled(await accessibilityDefaults(udid, "export", "-"))) throw err;
75482
75741
  }
75483
75742
  }
75484
75743
  async function clearAutomationEnabledOrWarn(udid) {
@@ -75489,26 +75748,12 @@ async function clearAutomationEnabledOrWarn(udid) {
75489
75748
  );
75490
75749
  });
75491
75750
  }
75492
- async function isEntitlementBypassActive(udid) {
75751
+ async function prepareLocalAxPrefs(udid) {
75752
+ const plist = await accessibilityDefaults(udid, "export", "-");
75753
+ await clearAutomationEnabled(udid, plist);
75493
75754
  try {
75494
- const { stdout } = await execFileAsync8(
75495
- "xcrun",
75496
- /** Same reasoning as {@linkcode accessibilityDefaults}. */
75497
- await simctlArgsForUdid(
75498
- udid,
75499
- [
75500
- "spawn",
75501
- udid,
75502
- "defaults",
75503
- "read",
75504
- "com.apple.Accessibility",
75505
- "IgnoreAXServerEntitlements"
75506
- ],
75507
- { granted: "ax-service" }
75508
- ),
75509
- { timeout: SIMCTL_SPAWN_TIMEOUT_MS, killSignal: SIMCTL_KILL_SIGNAL }
75510
- );
75511
- return stdout.trim() === "1";
75755
+ const prefs = parsePlist(plist);
75756
+ return typeof prefs === "object" && !Array.isArray(prefs) && PRE_BOOT_ACCESSIBILITY_KEYS.every((key2) => prefs[key2] === true || prefs[key2] === 1);
75512
75757
  } catch {
75513
75758
  return false;
75514
75759
  }
@@ -75524,12 +75769,7 @@ async function setAccessibilityPrefsPreBoot(udid, { isTvOs }) {
75524
75769
  if (!exists3) {
75525
75770
  await execFileAsync8("plutil", ["-create", "binary1", plistPath]);
75526
75771
  }
75527
- const keys = [
75528
- "IgnoreAXServerEntitlements",
75529
- "AccessibilityEnabled",
75530
- "ApplicationAccessibilityEnabled"
75531
- ];
75532
- if (isTvOs) keys.unshift("AutomationEnabled");
75772
+ const keys = isTvOs ? ["AutomationEnabled", ...PRE_BOOT_ACCESSIBILITY_KEYS] : PRE_BOOT_ACCESSIBILITY_KEYS;
75533
75773
  for (const key2 of keys) {
75534
75774
  await execFileAsync8("plutil", ["-replace", key2, "-bool", "true", plistPath]);
75535
75775
  }
@@ -96182,8 +96422,7 @@ var localIosHost = {
96182
96422
  listRunningBundleIds: listRunningUIKitApplicationBundleIds,
96183
96423
  inspectRunningApp: inspectRunningAppLocal,
96184
96424
  async bootstrapAx(udid) {
96185
- await clearAutomationEnabled(udid);
96186
- return { entitlementBypassActive: await isEntitlementBypassActive(udid) };
96425
+ return { accessibilityPrefsEnabled: await prepareLocalAxPrefs(udid) };
96187
96426
  },
96188
96427
  spawnAxDaemon: spawnAxDaemonLocal,
96189
96428
  async startProxy() {
@@ -96225,7 +96464,7 @@ var remoteIosHost = {
96225
96464
  args: ["defaults", "write", "com.apple.Accessibility", flag, "-bool", "true"]
96226
96465
  });
96227
96466
  }
96228
- return { entitlementBypassActive: true };
96467
+ return { accessibilityPrefsEnabled: true };
96229
96468
  },
96230
96469
  spawnAxDaemon: spawnAxDaemonRemote,
96231
96470
  startProxy: proxyStart,
@@ -97811,6 +98050,8 @@ async function initUdid(registry2, udid, trackedServices) {
97811
98050
  }
97812
98051
  }
97813
98052
  function startSimulatorWatcher(registry2) {
98053
+ const configuredUdids = process.env.ARGENT_SIMULATOR_WATCH_UDIDS;
98054
+ const allowedUdids = configuredUdids === void 0 ? void 0 : new Set(configuredUdids.split(",").map((id) => id.trim().toUpperCase()));
97814
98055
  const trackedServices = /* @__PURE__ */ new Map();
97815
98056
  const reportedSkips = /* @__PURE__ */ new Set();
97816
98057
  const stopController = new AbortController();
@@ -97844,6 +98085,7 @@ function startSimulatorWatcher(registry2) {
97844
98085
  const ours = /* @__PURE__ */ new Set();
97845
98086
  const claimed = /* @__PURE__ */ new Set();
97846
98087
  for (const udid of booted) {
98088
+ if (allowedUdids && !allowedUdids.has(udid.toUpperCase())) continue;
97847
98089
  const claim2 = externalClaimForNativeId(udid);
97848
98090
  if (!claim2) {
97849
98091
  reportedSkips.delete(udid);
@@ -98661,263 +98903,6 @@ var path22 = __toESM(require("node:path"));
98661
98903
  var import_node_crypto8 = require("node:crypto");
98662
98904
  var import_node_net = require("node:net");
98663
98905
  init_src2();
98664
-
98665
- // ../tool-server/src/utils/ios-device/usbmux-protocol.ts
98666
- var USBMUX_HEADER_BYTES = 16;
98667
- var USBMUX_PROTOCOL_VERSION = 1;
98668
- var USBMUX_MESSAGE_TYPE_PLIST = 8;
98669
- var USBMUX_MAX_PACKET_BYTES = 4 * 1024 * 1024;
98670
- function appendHintToMessage(message, hint) {
98671
- if (!hint || message.includes(hint)) {
98672
- return message;
98673
- }
98674
- return `${message}${/[.!?]$/.test(message) ? "" : "."} Hint: ${hint}`;
98675
- }
98676
- var IosDeviceTransportError = class extends Error {
98677
- kind;
98678
- retryable;
98679
- hint;
98680
- constructor(kind, message, options = { retryable: false }) {
98681
- super(
98682
- appendHintToMessage(message, options.hint),
98683
- options.cause !== void 0 ? { cause: options.cause } : void 0
98684
- );
98685
- this.name = "IosDeviceTransportError";
98686
- this.kind = kind;
98687
- this.retryable = options.retryable;
98688
- if (options.hint !== void 0) {
98689
- this.hint = options.hint;
98690
- }
98691
- }
98692
- };
98693
- function isIosDeviceTransportError(error63) {
98694
- return error63 instanceof IosDeviceTransportError;
98695
- }
98696
- function encodeUsbmuxPacket(tag3, payloadXml) {
98697
- const payload = Buffer.from(payloadXml, "utf8");
98698
- const packet = Buffer.alloc(USBMUX_HEADER_BYTES + payload.length);
98699
- packet.writeUInt32LE(packet.length, 0);
98700
- packet.writeUInt32LE(USBMUX_PROTOCOL_VERSION, 4);
98701
- packet.writeUInt32LE(USBMUX_MESSAGE_TYPE_PLIST, 8);
98702
- packet.writeUInt32LE(tag3, 12);
98703
- payload.copy(packet, USBMUX_HEADER_BYTES);
98704
- return packet;
98705
- }
98706
- function decodeUsbmuxPacket(buffer) {
98707
- if (buffer.length < USBMUX_HEADER_BYTES) {
98708
- return null;
98709
- }
98710
- const totalLength = buffer.readUInt32LE(0);
98711
- if (totalLength < USBMUX_HEADER_BYTES || totalLength > USBMUX_MAX_PACKET_BYTES) {
98712
- throw new IosDeviceTransportError(
98713
- "protocol",
98714
- `Invalid usbmuxd packet length ${totalLength} (must be between ${USBMUX_HEADER_BYTES} and ${USBMUX_MAX_PACKET_BYTES} bytes)`,
98715
- { retryable: false }
98716
- );
98717
- }
98718
- if (buffer.length < totalLength) {
98719
- return null;
98720
- }
98721
- return {
98722
- version: buffer.readUInt32LE(4),
98723
- messageType: buffer.readUInt32LE(8),
98724
- tag: buffer.readUInt32LE(12),
98725
- payload: buffer.subarray(USBMUX_HEADER_BYTES, totalLength),
98726
- bytesConsumed: totalLength
98727
- };
98728
- }
98729
- function hostToNetworkPort(port) {
98730
- if (!Number.isInteger(port) || port < 0 || port > 65535) {
98731
- throw new IosDeviceTransportError("protocol", `Invalid TCP port ${port}`, {
98732
- retryable: false
98733
- });
98734
- }
98735
- return (port & 255) << 8 | port >>> 8 & 255;
98736
- }
98737
- function escapeXmlText(value) {
98738
- return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
98739
- }
98740
- function buildUsbmuxPlistMessage(messageType, fields = {}) {
98741
- const entries = [
98742
- ["BundleID", "com.argent.tool-server"],
98743
- ["ClientVersionString", "argent"],
98744
- ["MessageType", messageType],
98745
- ["ProgName", "argent"],
98746
- ["kLibUSBMuxVersion", 3],
98747
- ...Object.entries(fields)
98748
- ];
98749
- const body = entries.map(
98750
- ([key2, value]) => typeof value === "number" ? `<key>${escapeXmlText(key2)}</key><integer>${value}</integer>` : `<key>${escapeXmlText(key2)}</key><string>${escapeXmlText(value)}</string>`
98751
- ).join("");
98752
- return `<?xml version="1.0" encoding="UTF-8"?><plist version="1.0"><dict>${body}</dict></plist>`;
98753
- }
98754
- function parsePlist(xml) {
98755
- const elements = parseXmlElements(xml);
98756
- const plist = elements.find((element) => element.name === "plist");
98757
- const root = plist ? plist.children[0] : elements[0];
98758
- if (!root) {
98759
- throw new IosDeviceTransportError("protocol", "Empty plist document from usbmuxd", {
98760
- retryable: false
98761
- });
98762
- }
98763
- return convertPlistElement(root);
98764
- }
98765
- function readUsbmuxResultCode(xml) {
98766
- const root = parsePlistOrUndefined(xml);
98767
- if (!isPlistDict(root)) {
98768
- return void 0;
98769
- }
98770
- const value = root["Number"];
98771
- return typeof value === "number" && Number.isSafeInteger(value) ? value : void 0;
98772
- }
98773
- function readUsbmuxDeviceIdForSerial(xml, serial) {
98774
- const root = parsePlistOrUndefined(xml);
98775
- if (!isPlistDict(root)) {
98776
- return void 0;
98777
- }
98778
- const list = root["DeviceList"];
98779
- if (!Array.isArray(list)) {
98780
- return void 0;
98781
- }
98782
- let fallbackDeviceId;
98783
- for (const entry of list) {
98784
- if (!isPlistDict(entry)) {
98785
- continue;
98786
- }
98787
- const properties = entry["Properties"];
98788
- if (!isPlistDict(properties)) {
98789
- continue;
98790
- }
98791
- if (properties["SerialNumber"] !== serial) {
98792
- continue;
98793
- }
98794
- const deviceId = entry["DeviceID"];
98795
- if (typeof deviceId !== "number" || !Number.isSafeInteger(deviceId) || deviceId <= 0) {
98796
- continue;
98797
- }
98798
- if (properties["ConnectionType"] === "USB") {
98799
- return deviceId;
98800
- }
98801
- fallbackDeviceId ??= deviceId;
98802
- }
98803
- return fallbackDeviceId;
98804
- }
98805
- function parsePlistOrUndefined(xml) {
98806
- try {
98807
- return parsePlist(xml);
98808
- } catch {
98809
- return void 0;
98810
- }
98811
- }
98812
- function isPlistDict(value) {
98813
- return typeof value === "object" && value !== null && !Array.isArray(value);
98814
- }
98815
- function parseXmlElements(xml) {
98816
- const source = xml.replace(/<\?xml[\s\S]*?\?>/g, "").replace(/<!DOCTYPE[^>]*>/gi, "");
98817
- const tokenPattern = /<(\/?)([A-Za-z][\w.-]*)((?:\s[^<>]*?)?)(\/?)>|([^<]+)/g;
98818
- const root = { name: "#root", text: "", children: [] };
98819
- const stack = [root];
98820
- let consumed = 0;
98821
- for (let match = tokenPattern.exec(source); match !== null; match = tokenPattern.exec(source)) {
98822
- if (match.index !== consumed) {
98823
- break;
98824
- }
98825
- consumed = tokenPattern.lastIndex;
98826
- const [, closing, name, , selfClosing, textChunk] = match;
98827
- const top = stack[stack.length - 1];
98828
- if (textChunk !== void 0) {
98829
- top.text += decodeXmlEntities(textChunk);
98830
- continue;
98831
- }
98832
- if (closing) {
98833
- if (stack.length < 2 || top.name !== name) {
98834
- throw invalidXmlError(`unexpected closing tag </${name}>`);
98835
- }
98836
- stack.pop();
98837
- continue;
98838
- }
98839
- const element = { name, text: "", children: [] };
98840
- top.children.push(element);
98841
- if (!selfClosing) {
98842
- stack.push(element);
98843
- }
98844
- }
98845
- if (consumed !== source.length) {
98846
- throw invalidXmlError("malformed markup");
98847
- }
98848
- if (stack.length !== 1) {
98849
- throw invalidXmlError(`unclosed tag <${stack[stack.length - 1].name}>`);
98850
- }
98851
- return root.children;
98852
- }
98853
- function convertPlistElement(element) {
98854
- switch (element.name) {
98855
- case "dict":
98856
- return convertPlistDict(element);
98857
- case "array":
98858
- return element.children.map(convertPlistElement);
98859
- case "string":
98860
- return element.text;
98861
- case "integer":
98862
- case "real": {
98863
- const parsed2 = Number(element.text.trim());
98864
- if (!Number.isFinite(parsed2)) {
98865
- throw invalidXmlError(`non-numeric <${element.name}> value "${element.text}"`);
98866
- }
98867
- return parsed2;
98868
- }
98869
- case "true":
98870
- return true;
98871
- case "false":
98872
- return false;
98873
- case "data":
98874
- case "date":
98875
- return element.text.trim();
98876
- default:
98877
- throw invalidXmlError(`unsupported plist node <${element.name}>`);
98878
- }
98879
- }
98880
- function convertPlistDict(element) {
98881
- const dict = {};
98882
- for (let index = 0; index < element.children.length - 1; index += 1) {
98883
- const key2 = element.children[index];
98884
- if (key2.name !== "key") {
98885
- continue;
98886
- }
98887
- const value = element.children[index + 1];
98888
- if (value.name === "key") {
98889
- continue;
98890
- }
98891
- dict[key2.text] = convertPlistElement(value);
98892
- index += 1;
98893
- }
98894
- return dict;
98895
- }
98896
- function decodeXmlEntities(text) {
98897
- return text.replace(/&(#x?[0-9a-fA-F]+|[a-z]+);/g, (entity, body) => {
98898
- if (body.startsWith("#x") || body.startsWith("#X")) {
98899
- return String.fromCodePoint(Number.parseInt(body.slice(2), 16));
98900
- }
98901
- if (body.startsWith("#")) {
98902
- return String.fromCodePoint(Number.parseInt(body.slice(1), 10));
98903
- }
98904
- const named = {
98905
- amp: "&",
98906
- lt: "<",
98907
- gt: ">",
98908
- quot: '"',
98909
- apos: "'"
98910
- };
98911
- return named[body] ?? entity;
98912
- });
98913
- }
98914
- function invalidXmlError(detail) {
98915
- return new IosDeviceTransportError("protocol", `Invalid plist XML from usbmuxd: ${detail}`, {
98916
- retryable: false
98917
- });
98918
- }
98919
-
98920
- // ../tool-server/src/utils/ios-device/devicectl.ts
98921
98906
  var execFileAsync15 = (0, import_node_util15.promisify)(import_node_child_process20.execFile);
98922
98907
  var DEVICECTL_TIMEOUT_MS2 = 2e4;
98923
98908
  var DEVICECTL_INSTALL_TIMEOUT_MS = 12e4;
@@ -103329,9 +103314,9 @@ var axServiceBlueprint = {
103329
103314
  failPending(err);
103330
103315
  events.emit("terminated", err);
103331
103316
  };
103332
- const { entitlementBypassActive } = await host.bootstrapAx(udid);
103317
+ const { accessibilityPrefsEnabled } = await host.bootstrapAx(udid);
103333
103318
  const startFailed = (err) => {
103334
- if (err instanceof Error) startFailureDegraded.set(err, !entitlementBypassActive);
103319
+ if (err instanceof Error) startFailureDegraded.set(err, !accessibilityPrefsEnabled);
103335
103320
  return err;
103336
103321
  };
103337
103322
  const server = await startListener(endpoint, (socket) => {
@@ -103473,7 +103458,7 @@ var axServiceBlueprint = {
103473
103458
  }
103474
103459
  let lacksOrientationCommand = false;
103475
103460
  const api = {
103476
- degraded: !entitlementBypassActive,
103461
+ degraded: !accessibilityPrefsEnabled,
103477
103462
  async describe() {
103478
103463
  const result = await query("describe", 1e4);
103479
103464
  if (result.error) {
@@ -103877,8 +103862,8 @@ function adaptAXDescribeToDescribeResult(response) {
103877
103862
  }
103878
103863
 
103879
103864
  // ../tool-server/src/tools/describe/platforms/ios/index.ts
103880
- var DEGRADED_BLIND_HINT = "The accessibility read returned no elements, and this simulator was not booted through argent, so the pre-boot accessibility settings were never applied. Unless the screen is genuinely blank, call boot-device with force=true to reboot it with those settings \u2014 this restarts the simulator";
103881
- var DEGRADED_STANDING_HINT = "This simulator was not booted through argent, so system dialogs and native modals may not appear in this tree; everything else reads normally. If something you expect is missing, boot-device with force=true reboots the simulator with the full accessibility settings";
103865
+ var DEGRADED_BLIND_HINT = "The accessibility read returned no elements. Argent could not verify all pre-boot accessibility settings. If you expect elements on this screen, boot-device with force=true restarts the simulator with those settings";
103866
+ var DEGRADED_STANDING_HINT = "Argent could not verify all pre-boot accessibility settings. System dialogs and native modals may be missing. If you need them, boot-device with force=true restarts the simulator with those settings";
103882
103867
  function externalCaveat(deviceId, body) {
103883
103868
  return `${externalSupportHint(deviceId) ?? "This device is supplied by an external provider."} ${body}`;
103884
103869
  }
@@ -103889,12 +103874,12 @@ function isStandingCaveat(hint) {
103889
103874
  return hint === DEGRADED_STANDING_HINT || Boolean(hint?.endsWith(EXTERNAL_STANDING_BODY));
103890
103875
  }
103891
103876
  function isBlindCaveat(hint) {
103892
- return hint === DEGRADED_BLIND_HINT || Boolean(hint?.endsWith(EXTERNAL_BLIND_BODY));
103877
+ return Boolean(hint?.endsWith(DEGRADED_BLIND_HINT) || hint?.endsWith(EXTERNAL_BLIND_BODY));
103893
103878
  }
103894
103879
  function startFailure(err) {
103895
103880
  return `The accessibility service failed to start (${errMsg(err)})`;
103896
103881
  }
103897
- var DEGRADED_START_FAILED_TAIL = ", and this simulator was not booted through argent, so the pre-boot accessibility settings were never applied. Call boot-device with force=true to reboot it with those settings \u2014 this restarts the simulator. If it fails to start again after that reboot, do not reboot again: the boot was not the cause.";
103882
+ var DEGRADED_START_FAILED_TAIL = ". Check the simulator's pre-boot accessibility settings. Call boot-device with force=true to restart the simulator with those settings. If the service fails to start again, do not reboot again: the boot was not the cause.";
103898
103883
  function axCrashHint(signal) {
103899
103884
  return `The accessibility service (ax-service) crashed with ${signal}, so the accessibility tree could not be read. Every describe starts the service again. If this hint repeats, the crash is in the service on this host: rebooting the simulator (boot-device with force=true) or restarting the tool-server will not fix it, because both start the same binary again. While it crashes, system dialogs and SpringBoard chrome cannot be read through describe. describe continues on the app's native view hierarchy where that is available, and \`screenshot\` shows the rest.`;
103900
103885
  }
@@ -104056,7 +104041,13 @@ async function readIos(registry2, device, params, options, facts) {
104056
104041
  }
104057
104042
  const parsed2 = parseNativeDescribeScreenResult(rawResult);
104058
104043
  const nativeTree = adaptNativeDescribeToDescribeResult(parsed2);
104059
- return { tree: nativeTree, source: "native-devtools", hint };
104044
+ const scope = "This app-only tree omits system dialogs, including permission prompts.";
104045
+ return {
104046
+ tree: nativeTree,
104047
+ source: "native-devtools",
104048
+ partial: true,
104049
+ hint: crashHint ?? (hint ? `${scope} ${hint}` : scope)
104050
+ };
104060
104051
  } catch (err) {
104061
104052
  return { tree, source: "ax-service", hint: unexplainedHint(hint, errMsg(err), params) };
104062
104053
  }
@@ -120633,14 +120624,15 @@ function darkTailToleranceMs(pollIntervalMs) {
120633
120624
  // ../tool-server/src/tools/await-ui-element/index.ts
120634
120625
  var WAIT_CANCELLED_NOTE = "wait was cancelled before the condition was met";
120635
120626
  var TREE_FETCH_FAILED_NOTE_PREFIX = "last tree fetch failed: ";
120636
- var HIDDEN_UNREADABLE_NOTE = "could not confirm the element is hidden \u2014 the UI tree was empty or unreadable at timeout";
120627
+ var HIDDEN_UNCONFIRMED = "could not confirm the element is hidden";
120628
+ var HIDDEN_UNREADABLE_NOTE = `${HIDDEN_UNCONFIRMED} \u2014 the UI tree was empty or unreadable at timeout`;
120637
120629
  function unmetUiWaitCause(result) {
120638
120630
  const carried = result?.cause;
120639
120631
  if (carried === "unmet" || carried === "unreadable" || carried === "cancelled") return carried;
120640
120632
  const note = result?.note;
120641
120633
  if (typeof note !== "string") return "unmet";
120642
120634
  if (note === WAIT_CANCELLED_NOTE) return "cancelled";
120643
- if (note.startsWith(TREE_FETCH_FAILED_NOTE_PREFIX) || note.startsWith(HIDDEN_UNREADABLE_NOTE)) {
120635
+ if (note.startsWith(TREE_FETCH_FAILED_NOTE_PREFIX) || note.startsWith(HIDDEN_UNCONFIRMED)) {
120644
120636
  return "unreadable";
120645
120637
  }
120646
120638
  return "unmet";
@@ -120716,7 +120708,13 @@ function timeoutNote(params, lastTree, fetchError, lastData) {
120716
120708
  break;
120717
120709
  }
120718
120710
  case "hidden":
120719
- base = matches2.some(isVisible) ? "an element matching the selector was still visible at timeout" : HIDDEN_UNREADABLE_NOTE;
120711
+ if (matches2.some(isVisible)) {
120712
+ base = "an element matching the selector was still visible at timeout";
120713
+ } else if (lastData?.partial && lastData.source === "native-devtools") {
120714
+ base = HIDDEN_UNCONFIRMED;
120715
+ } else {
120716
+ base = HIDDEN_UNREADABLE_NOTE;
120717
+ }
120720
120718
  break;
120721
120719
  case "visible":
120722
120720
  base = matches2.length > 0 ? "element(s) matched but none was visible (zero-area frame) before timeout" : "no element matched the selector before timeout";
@@ -130550,7 +130548,7 @@ async function bootSimctl(prefix, [sub, udid, ...rest], timeoutMs) {
130550
130548
  );
130551
130549
  }
130552
130550
  }
130553
- async function bootIos(udid, registry2, force, headless) {
130551
+ async function bootIos(udid, registry2, force, headless, prepareOnly) {
130554
130552
  if (process.platform !== "darwin") {
130555
130553
  throw new FailureError(
130556
130554
  `iOS Simulator is unavailable on ${process.platform}: it requires a macOS host. Pass \`avdName\` (Android) instead of \`udid\` (iOS) to boot a device from this host.`,
@@ -130578,6 +130576,15 @@ async function bootIos(udid, registry2, force, headless) {
130578
130576
  }
130579
130577
  const simState = simMatch?.state;
130580
130578
  const isTvOs = simMatch?.runtimeKind === "tv";
130579
+ if (prepareOnly) {
130580
+ if (simState !== "Shutdown") {
130581
+ throw new InvalidToolInputError(
130582
+ `prepareOnly requires a Shutdown simulator. State of ${udid}: ${simState ?? "unknown"}.`
130583
+ );
130584
+ }
130585
+ await setAccessibilityPrefsPreBoot(udid, { isTvOs });
130586
+ return { platform: "ios", udid, booted: false, prepared: true };
130587
+ }
130581
130588
  const deviceSet = await deviceSetForUdid(udid);
130582
130589
  const prefix = simctlPrefix(deviceSet);
130583
130590
  const booting = simState === "Booting";
@@ -131869,6 +131876,9 @@ var zodSchema10 = external_exports.object({
131869
131876
  port: external_exports.number().int().optional().describe(
131870
131877
  "Android only: the emulator's console port, an even number from 5554 to 5584 (`emulator -port`), the range adb finds emulators in; its serial is `emulator-<port>`. Without it the emulator takes the first free port from 5554 up, as Android Studio does. The gRPC server Argent needs for screenshots and gestures goes on the port plus 3000, which must be free too. Given a port, the tool reuses only the emulator on that port and fails if another emulator holds it, or if this AVD runs there writable on a read-only boot and `force` is not set. A read-only emulator started with `-port` belongs to the calls that give that port: a call without `port` never reuses or shuts it down. Where the process list cannot be read (Windows, or a failed `ps`), Argent knows only the pinned emulators it booted itself, so a writable call without `port` can reuse, or with `force` shut down, one that someone else pinned. A writable one is still reused, or with `force` shut down, by a writable call without `port`, since the AVD runs one writable emulator at a time. `force` shuts nothing down when another emulator of the AVD would still block the boot. Ignored on other platforms."
131871
131878
  ),
131879
+ prepareOnly: external_exports.boolean().optional().describe(
131880
+ "Local iOS simulator only: apply accessibility preferences and leave the simulator shut down for a pool manager to boot. Requires Shutdown state. Cannot be combined with force: true."
131881
+ ),
131872
131882
  headless: external_exports.boolean().optional().describe(
131873
131883
  "iOS only: boot the simulator core WITHOUT opening its GUI window (Simulator.app, or Device Hub on Xcode 27+). The device still streams via simulator-server. The `ARGENT_SIMULATOR_NO_WINDOW` env var (1/true/yes) forces this host-wide."
131874
131884
  ),
@@ -131904,9 +131914,9 @@ HarmonyOS hands the instance to DevEco Studio's Emulator manager, then waits for
131904
131914
  alwaysLoad: true,
131905
131915
  searchHint: "boot start launch simulator emulator avd device session ios android vega vvd firetv <flag:harmonyos>harmony harmonyos deveco </flag:harmonyos>cold hot",
131906
131916
  interaction: {
131907
- startedMsg: ({ params }) => `Starting ${bootTarget(params)}`,
131908
- completedMsg: ({ params }) => `Started ${bootTarget(params)}`,
131909
- failedMsg: ({ params, failureSignal: failureSignal2 }) => `Failed to start ${bootTarget(params)}: ${failureSignal2.error_code}`
131917
+ startedMsg: ({ params }) => `${params.prepareOnly ? "Preparing" : "Starting"} ${bootTarget(params)}`,
131918
+ completedMsg: ({ params }) => `${params.prepareOnly ? "Prepared" : "Started"} ${bootTarget(params)}`,
131919
+ failedMsg: ({ params, failureSignal: failureSignal2 }) => `Failed to ${params.prepareOnly ? "prepare" : "start"} ${bootTarget(params)}: ${failureSignal2.error_code}`
131910
131920
  },
131911
131921
  capability: capability2,
131912
131922
  services: () => ({}),
@@ -131932,6 +131942,11 @@ HarmonyOS hands the instance to DevEco Studio's Emulator manager, then waits for
131932
131942
  }
131933
131943
  );
131934
131944
  }
131945
+ if (params.prepareOnly && (!params.udid || classifyDevice(params.udid) !== "ios" || params.force)) {
131946
+ throw new InvalidToolInputError(
131947
+ "prepareOnly requires a local iOS simulator UDID and cannot be combined with force: true."
131948
+ );
131949
+ }
131935
131950
  if (hasMacos || hasUdid && classifyDevice(params.udid) === "macos") {
131936
131951
  return bootMacosApp(registry2, {
131937
131952
  appPath: params.macosAppPath,
@@ -131984,7 +131999,7 @@ HarmonyOS hands the instance to DevEco Studio's Emulator manager, then waits for
131984
131999
  }
131985
132000
  );
131986
132001
  }
131987
- return bootIos(params.udid, registry2, params.force, params.headless);
132002
+ return bootIos(params.udid, registry2, params.force, params.headless, params.prepareOnly);
131988
132003
  }
131989
132004
  if (hasAvd) {
131990
132005
  if (params.port !== void 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swmansion/argent",
3
- "version": "0.35.1-next.2",
3
+ "version": "0.35.1-next.4",
4
4
  "mcpName": "io.github.software-mansion/argent",
5
5
  "description": "MCP server for iOS Simulator, Android Emulator, Chromium app and Mac app control",
6
6
  "license": "Apache-2.0",
@@ -98,5 +98,5 @@
98
98
  "vitest": "^5.0.5",
99
99
  "yaml": "^2.9.1"
100
100
  },
101
- "gitHead": "0f5f4c7e93d51e328f5231c48e5fa4dc1ae64c36"
101
+ "gitHead": "3b96d7b4964cf5938872a30c7dbd78e71af76c17"
102
102
  }