@swmansion/argent 0.34.1-next.34 → 0.34.1-next.36

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
@@ -36256,7 +36256,7 @@ function isCi(env = process.env) {
36256
36256
  var SESSION_ID2 = randomUUID5();
36257
36257
  function readCliVersion() {
36258
36258
  if (true) {
36259
- return "0.34.1-next.34";
36259
+ return "0.34.1-next.36";
36260
36260
  }
36261
36261
  return "0.0.0";
36262
36262
  }
@@ -16942,7 +16942,7 @@ function isCi(env = process.env) {
16942
16942
  var SESSION_ID = randomUUID4();
16943
16943
  function readCliVersion() {
16944
16944
  if (true) {
16945
- return "0.34.1-next.34";
16945
+ return "0.34.1-next.36";
16946
16946
  }
16947
16947
  return "0.0.0";
16948
16948
  }
@@ -101440,7 +101440,7 @@ function isCi(env = process.env) {
101440
101440
  var SESSION_ID = (0, import_node_crypto3.randomUUID)();
101441
101441
  function readCliVersion() {
101442
101442
  if (true) {
101443
- return "0.34.1-next.34";
101443
+ return "0.34.1-next.36";
101444
101444
  }
101445
101445
  return "0.0.0";
101446
101446
  }
@@ -127849,6 +127849,59 @@ function bracketed(hostname4) {
127849
127849
  return hostname4.includes(":") && !hostname4.startsWith("[") ? `[${hostname4}]` : hostname4;
127850
127850
  }
127851
127851
 
127852
+ // ../tool-server/src/utils/debugger/scripts/await-promise.ts
127853
+ var WATCH_PROMISE_FUNCTION = `function (slot) {
127854
+ var self = this;
127855
+ var then = self.then;
127856
+ if (typeof then !== "function") return self;
127857
+
127858
+ var box = { settled: false, rejected: false, value: undefined };
127859
+ globalThis[slot] = box;
127860
+
127861
+ new Promise(function (resolve, reject) {
127862
+ then.call(self, resolve, reject);
127863
+ }).then(
127864
+ function (value) {
127865
+ box.settled = true;
127866
+ box.value = value;
127867
+ },
127868
+ function (reason) {
127869
+ box.settled = true;
127870
+ box.rejected = true;
127871
+ box.value = reason;
127872
+ }
127873
+ );
127874
+
127875
+ return slot;
127876
+ }`;
127877
+ function takeSettledScript(slot) {
127878
+ return `(function (slot) {
127879
+ var box = globalThis[slot];
127880
+ if (!box) throw ownError("The JS context reloaded while the Promise was pending.");
127881
+ if (!box.settled) return slot;
127882
+
127883
+ delete globalThis[slot];
127884
+ if (!box.rejected) return box.value;
127885
+ if (box.value instanceof Error) throw box.value;
127886
+ throw ownError("Promise rejected with: " + describe(box.value));
127887
+
127888
+ function ownError(message) {
127889
+ var error = new Error(message);
127890
+ error.stack = "";
127891
+ return error;
127892
+ }
127893
+
127894
+ function describe(reason) {
127895
+ try {
127896
+ var json = JSON.stringify(reason);
127897
+ return json === undefined ? String(reason) : json;
127898
+ } catch (e) {
127899
+ return Object.prototype.toString.call(reason);
127900
+ }
127901
+ }
127902
+ })(${JSON.stringify(slot)})`;
127903
+ }
127904
+
127852
127905
  // ../tool-server/src/utils/debugger/cdp-client.ts
127853
127906
  var BLOCKED_WHILE_PAUSED = /* @__PURE__ */ new Set(["Runtime.evaluate", "Runtime.callFunctionOn"]);
127854
127907
  function trimBundleQuery(url2) {
@@ -127869,7 +127922,16 @@ function formatExceptionDetails(details) {
127869
127922
  return `${description}
127870
127923
  ${frameLines}`;
127871
127924
  }
127925
+ function runtimeException(details) {
127926
+ return new FailureError(formatExceptionDetails(details), {
127927
+ error_code: FAILURE_CODES.DEBUGGER_CDP_RUNTIME_EXCEPTION,
127928
+ failure_stage: "debugger_cdp_evaluate",
127929
+ failure_area: "tool_server",
127930
+ error_kind: "unknown"
127931
+ });
127932
+ }
127872
127933
  var DEFAULT_TIMEOUT_MS2 = 1e4;
127934
+ var PROMISE_POLL_INTERVAL_MS = 100;
127873
127935
  var ORIGIN_SETTLE_MS = 100;
127874
127936
  var acceptedOrigins = /* @__PURE__ */ new Map();
127875
127937
  var CDPClient = class {
@@ -127891,9 +127953,16 @@ var CDPClient = class {
127891
127953
  paused;
127892
127954
  wsUrl;
127893
127955
  sendOrigin;
127956
+ /**
127957
+ * Hermes ignores `awaitPromise`, so {@linkcode evaluateAwaited} waits for a
127958
+ * returned Promise inside the app instead. Set only for Hermes behind the
127959
+ * modern inspector: it relies on `Runtime.callFunctionOn`.
127960
+ */
127961
+ awaitPromisesInApp;
127894
127962
  constructor(wsUrl, options) {
127895
127963
  this.wsUrl = wsUrl;
127896
127964
  this.sendOrigin = options?.sendOrigin !== false;
127965
+ this.awaitPromisesInApp = options?.awaitPromisesInApp === true;
127897
127966
  }
127898
127967
  async connect() {
127899
127968
  if (!this.sendOrigin) {
@@ -128162,20 +128231,68 @@ var CDPClient = class {
128162
128231
  async evaluate(expression, options) {
128163
128232
  const returnByValue = options?.returnByValue ?? true;
128164
128233
  const awaitPromise = options?.awaitPromise ?? true;
128165
- const result = await this.send(
128234
+ const result = await this.runtimeCall(
128166
128235
  "Runtime.evaluate",
128167
128236
  { expression, returnByValue, awaitPromise },
128168
128237
  options?.timeout
128169
128238
  );
128170
- if (result.exceptionDetails) {
128171
- throw new FailureError(formatExceptionDetails(result.exceptionDetails), {
128172
- error_code: FAILURE_CODES.DEBUGGER_CDP_RUNTIME_EXCEPTION,
128173
- failure_stage: "debugger_cdp_evaluate",
128174
- failure_area: "tool_server",
128175
- error_kind: "unknown"
128239
+ return result?.value;
128240
+ }
128241
+ /**
128242
+ * {@linkcode evaluate}, also on runtimes that ignore `awaitPromise`: a
128243
+ * returned Promise yields the value it resolves to, and a rejection throws
128244
+ * like an exception. A Promise still pending after {@linkcode DEFAULT_TIMEOUT_MS}
128245
+ * fails with DEBUGGER_CDP_REQUEST_TIMEOUT.
128246
+ */
128247
+ async evaluateAwaited(expression) {
128248
+ if (!this.awaitPromisesInApp) return this.evaluate(expression);
128249
+ const result = await this.runtimeCall("Runtime.evaluate", { expression, returnByValue: false });
128250
+ const objectId = result?.objectId;
128251
+ if (!objectId || result?.type !== "object" && result?.type !== "function") {
128252
+ return result?.value;
128253
+ }
128254
+ const slot = `__argentPromise_${crypto3.randomUUID().replace(/-/g, "")}`;
128255
+ let watched2;
128256
+ try {
128257
+ const response = await this.runtimeCall("Runtime.callFunctionOn", {
128258
+ objectId,
128259
+ functionDeclaration: WATCH_PROMISE_FUNCTION,
128260
+ arguments: [{ value: slot }],
128261
+ returnByValue: true
128262
+ });
128263
+ watched2 = response?.value;
128264
+ } finally {
128265
+ this.send("Runtime.releaseObject", { objectId }).catch(() => {
128176
128266
  });
128177
128267
  }
128178
- return result.result?.value;
128268
+ if (watched2 !== slot) return watched2;
128269
+ return this.waitForSettled(slot);
128270
+ }
128271
+ async runtimeCall(method, params, timeout) {
128272
+ const response = await this.send(method, params, timeout);
128273
+ if (response.exceptionDetails) throw runtimeException(response.exceptionDetails);
128274
+ return response.result;
128275
+ }
128276
+ async waitForSettled(slot) {
128277
+ const take2 = takeSettledScript(slot);
128278
+ const deadline = Date.now() + DEFAULT_TIMEOUT_MS2;
128279
+ let taken = await this.evaluate(take2);
128280
+ while (taken === slot && Date.now() < deadline) {
128281
+ await sleep(PROMISE_POLL_INTERVAL_MS);
128282
+ taken = await this.evaluate(take2);
128283
+ }
128284
+ if (taken !== slot) return taken;
128285
+ this.evaluate(`delete globalThis[${JSON.stringify(slot)}]`).catch(() => {
128286
+ });
128287
+ throw new FailureError(
128288
+ `The expression returned a Promise that did not settle within ${DEFAULT_TIMEOUT_MS2}ms. The expression ran, and running it again repeats its side effects.`,
128289
+ {
128290
+ error_code: FAILURE_CODES.DEBUGGER_CDP_REQUEST_TIMEOUT,
128291
+ failure_stage: "debugger_cdp_await_promise",
128292
+ failure_area: "tool_server",
128293
+ error_kind: "timeout"
128294
+ }
128295
+ );
128179
128296
  }
128180
128297
  /**
128181
128298
  * With `legacyInspector`, a protocol error leaves the binding unavailable
@@ -151244,6 +151361,7 @@ init_external_devices();
151244
151361
  var import_node_crypto13 = require("node:crypto");
151245
151362
  init_src2();
151246
151363
  init_device_info();
151364
+ init_external_devices();
151247
151365
  init_macos_app_kind();
151248
151366
  function deviceKey2(target) {
151249
151367
  const logicalId = target.reactNative?.logicalDeviceId;
@@ -151275,14 +151393,37 @@ function describeDevice(target) {
151275
151393
  if (macBundleId) return `Mac app ${macBundleId} (${logicalId})`;
151276
151394
  return logicalId ? `${target.deviceName ?? "unknown"} (${logicalId})` : `${target.deviceName ?? "unknown"} (legacy inspector \u2014 no logicalDeviceId)`;
151277
151395
  }
151278
- function macosAppTargets(pool, bundleId, port) {
151279
- const own2 = pool.filter((t) => macosAppBundleIdOf(t)?.toLowerCase() === bundleId.toLowerCase());
151280
- if (own2.length) return own2;
151396
+ function metroDevices(pool) {
151281
151397
  const devices2 = /* @__PURE__ */ new Map();
151282
151398
  for (const t of pool) {
151283
151399
  const key2 = deviceKey2(t);
151284
151400
  if (key2 && !devices2.has(key2)) devices2.set(key2, describeDevice(t));
151285
151401
  }
151402
+ return devices2;
151403
+ }
151404
+ function targetsOfOnlyDeviceNamed(pool, name) {
151405
+ if (name === void 0) return void 0;
151406
+ const named = pool.filter((t) => t.deviceName === name);
151407
+ return new Set(named.map(deviceKey2)).size === 1 ? named : void 0;
151408
+ }
151409
+ function nameMetroLists(simulatorName) {
151410
+ return simulatorName.split("&")[0].replaceAll("+", " ");
151411
+ }
151412
+ async function simulatorNameOnSharedMetro(deviceId, targets) {
151413
+ if (isExternalId(deviceId)) return void 0;
151414
+ const device = resolveDevice(deviceId);
151415
+ if (device.platform !== "ios" || device.kind !== "simulator") return void 0;
151416
+ if (metroDevices(targets).size < 2) return void 0;
151417
+ const simulators = await listIosSimulators().catch(() => []);
151418
+ const booted = simulators.filter((sim) => sim.state === "Booted");
151419
+ const name = booted.find((sim) => sim.udid === deviceId)?.name;
151420
+ if (name === void 0 || nameMetroLists(name) !== name) return void 0;
151421
+ return booted.filter((sim) => nameMetroLists(sim.name) === name).length === 1 ? name : void 0;
151422
+ }
151423
+ function macosAppTargets(pool, bundleId, port) {
151424
+ const own2 = pool.filter((t) => macosAppBundleIdOf(t)?.toLowerCase() === bundleId.toLowerCase());
151425
+ if (own2.length) return own2;
151426
+ const devices2 = metroDevices(pool);
151286
151427
  const catalyst = trackedMacosAppKind(bundleId) === "catalyst";
151287
151428
  const noVendorId = catalyst && !trackedMacosAppVendorId(bundleId) ? `argent does not know the identifierForVendor of the Mac Catalyst app ${bundleId}, which React Native puts in the runtime's id: argent's library reports it when argent starts the app, and the library of this start did not. Run restart-app, then retry; if this message stays, update argent. ` : "";
151288
151429
  throw new FailureError(
@@ -151310,14 +151451,14 @@ function selectTarget(targets, port, options) {
151310
151451
  } else if (typeof options?.deviceId === "string" && options.deviceId) {
151311
151452
  const deviceId = options.deviceId;
151312
151453
  const filtered = candidates.filter((t) => t.reactNative?.logicalDeviceId === deviceId);
151454
+ const simulatorName = typeof options.simulatorName === "string" ? options.simulatorName : void 0;
151455
+ const sameName = targetsOfOnlyDeviceNamed(pool, simulatorName);
151313
151456
  if (filtered.length) {
151314
151457
  candidates = filtered;
151458
+ } else if (sameName) {
151459
+ candidates = sameName;
151315
151460
  } else {
151316
- const distinctDevices = /* @__PURE__ */ new Map();
151317
- for (const t of pool) {
151318
- const key2 = deviceKey2(t);
151319
- if (key2 && !distinctDevices.has(key2)) distinctDevices.set(key2, describeDevice(t));
151320
- }
151461
+ const distinctDevices = metroDevices(pool);
151321
151462
  if (distinctDevices.size > 1) {
151322
151463
  const listed = [...distinctDevices.values()].join(", ");
151323
151464
  throw new FailureError(
@@ -151751,11 +151892,14 @@ var jsRuntimeDebuggerBlueprint = {
151751
151892
  });
151752
151893
  const selected = selectTarget(metro.targets, port, {
151753
151894
  ...options,
151754
- deviceId
151895
+ deviceId,
151896
+ simulatorName: await simulatorNameOnSharedMetro(deviceId, metro.targets)
151755
151897
  });
151756
151898
  const onPublishedBundler = publishedMetroPort(deviceId, port) === void 0;
151757
151899
  const proxied = onPublishedBundler ? externalJsDebuggerUrl(deviceId) : void 0;
151758
- const cdp = new CDPClient(proxied ?? selected.webSocketUrl);
151900
+ const cdp = new CDPClient(proxied ?? selected.webSocketUrl, {
151901
+ awaitPromisesInApp: !selected.legacyInspector
151902
+ });
151759
151903
  await cdp.connect();
151760
151904
  const sourceMaps = new SourceMapsRegistry();
151761
151905
  cdp.events.on("scriptParsed", (script) => {
@@ -162224,7 +162368,7 @@ var zodSchema33 = external_exports.object({
162224
162368
  var debuggerEvaluateTool = {
162225
162369
  id: "debugger-evaluate",
162226
162370
  description: `Execute arbitrary JavaScript in the app's JS runtime via CDP: Hermes on iOS / Android / Vega, V8 on Chromium.
162227
- Returns the result serialized by value as JSON, with deviceName, appName, and logicalDeviceId. Use when you need to read app state, including localStorage and sessionStorage on Chromium, call app functions, or test logic at runtime. Cyclic objects, which many RN runtime values are (fiber nodes, navigation refs, global), fail with a serialization error. Fails if the expression throws or the runtime is not connected. On React Native, a module that fails to load while the expression runs (e.g. a lazy react-native export whose native module the app lacks) fails the call with that module's error instead of opening the app's red box.`,
162371
+ Returns the result serialized by value as JSON, with deviceName, appName, and logicalDeviceId. A returned Promise is awaited and its resolved value returned. Use when you need to read app state, including localStorage and sessionStorage on Chromium, call app functions, or test logic at runtime. Cyclic objects, which many RN runtime values are (fiber nodes, navigation refs, global), fail with a serialization error. Fails if the expression throws or the runtime is not connected. On React Native, a module that fails to load while the expression runs (e.g. a lazy react-native export whose native module the app lacks) fails the call with that module's error instead of opening the app's red box.`,
162228
162372
  zodSchema: zodSchema33,
162229
162373
  searchHint: "javascript js eval expression runtime app state localstorage sessionstorage web storage",
162230
162374
  interaction: {
@@ -162241,7 +162385,7 @@ Returns the result serialized by value as JSON, with deviceName, appName, and lo
162241
162385
  let result;
162242
162386
  try {
162243
162387
  const expression = isChromiumDebuggerTarget(params.device_id) ? params.expression : guardModuleLoadErrors(params.expression);
162244
- result = await api.cdp.evaluate(expression);
162388
+ result = await api.cdp.evaluateAwaited(expression);
162245
162389
  } catch (err) {
162246
162390
  if (err instanceof Error && getFailureSignal(err)?.error_code === FAILURE_CODES.DEBUGGER_CDP_RUNTIME_EXCEPTION) {
162247
162391
  throw new FailureError(
@@ -180507,7 +180651,7 @@ function createStopAllSimulatorServersTool(registry2) {
180507
180651
  id: "stop-all-simulator-servers",
180508
180652
  description: `Stop the services a device owns - simulator-server processes (iOS + Android), native devtools, the iOS accessibility service, TV-control daemons, Chromium CDP sessions, screen recordings, native profiler sessions, Android native network capture (started by native-network-logs), and JS-runtime debugger sessions along with the network inspectors and React profiler sessions that ride on them - freeing their spawned processes, sockets and ports. Call this when the user asks to clean up or ends the session, or when a skill tells you to recycle a device's services mid-flow - not just because a task finished, since the next task reuses these services and would start cold again. To end only the native network capture of one app, call native-network-logs with stop: true instead.
180509
180653
  PASS \`devices\` with the device ids this session used: one tool-server serves every agent, subagent and CLI call using this argent install, and an unscoped call tears down THEIR devices too. Omit \`devices\` only when a machine-wide cleanup is what you actually want. An EMPTY array stops nothing; it does not ask for the machine-wide sweep.
180510
- A JS-runtime debugger session is keyed by the id you called \`debugger-connect\` with. On a Metro serving two or more devices that id is not a udid or serial - connect refuses those and tells you to re-target with the \`logicalDeviceId\` it returns - so a scope built from \`list-devices\` ids cannot reach that session. Pass any such \`logicalDeviceId\` in \`devices\` ALONGSIDE the device id.
180654
+ A JS-runtime debugger session is keyed by the id you called \`debugger-connect\` with. On a Metro serving two or more devices that id can be a \`logicalDeviceId\`: connect refuses a serial, or a simulator udid it cannot match to one Metro device by name, and tells you to re-target with the \`logicalDeviceId\` it returns. A scope built from \`list-devices\` ids cannot reach that session. Pass any such \`logicalDeviceId\` in \`devices\` ALONGSIDE the device id.
180511
180655
  Returns { stopped }: the URNs of the live services that were shut down; empty means nothing was still running. { unmatched }, present only when a supplied id owns no service here, lists those ids, so a typo or a device NAME passed instead of an id does not read as a clean machine. It is NOT proof the id is wrong: a Vega device you only booted and drove with the remote registers no service and lands here, as does any device this session never started anything on. { left_running } lists the URNs of live debugger sessions (and the network inspectors / React profiler sessions riding on them) whose id no device scope can name; re-call with the id after each URN's \`<namespace>:<port>:\` prefix to reap them. { aborted: true } means the request was cancelled part-way: the rest was left untouched and \`unmatched\` / \`left_running\` were not computed.
180512
180656
  Fails if the input has an unknown key (e.g. \`udids\` instead of \`devices\`); otherwise it always succeeds, and reaping nothing is a result, not a failure.`,
180513
180657
  zodSchema: zodSchema66,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swmansion/argent",
3
- "version": "0.34.1-next.34",
3
+ "version": "0.34.1-next.36",
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",
@@ -14,7 +14,7 @@ Physical iPhone: not supported; every `debugger-*` tool rejects `kind: "device"`
14
14
 
15
15
  ## 2. Tools
16
16
 
17
- Pass the same `device_id`, the id from `list-devices`, to every call. With two or more devices on one Metro, `debugger-connect` refuses a udid or serial and returns a `logicalDeviceId`: use that as `device_id` from then on, and include it in `stop-all-simulator-servers`' `devices` at teardown, or the debugger session outlives yours.
17
+ Pass the same `device_id`, the id from `list-devices`, to every call. With two or more devices on one Metro, `debugger-connect` refuses a serial, or a simulator udid it cannot match to one Metro device by name, and returns a `logicalDeviceId`: use that as `device_id` from then on, and include it in `stop-all-simulator-servers`' `devices` at teardown, or the debugger session outlives yours.
18
18
 
19
19
  | Tool | Use for |
20
20
  | ---------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |