@swmansion/argent 0.34.1-next.82 → 0.34.1-next.83

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
@@ -36295,7 +36295,7 @@ function isCi(env = process.env) {
36295
36295
  var SESSION_ID2 = randomUUID5();
36296
36296
  function readCliVersion() {
36297
36297
  if (true) {
36298
- return "0.34.1-next.81";
36298
+ return "0.34.1-next.82";
36299
36299
  }
36300
36300
  return "0.0.0";
36301
36301
  }
@@ -16995,7 +16995,7 @@ function isCi(env = process.env) {
16995
16995
  var SESSION_ID = randomUUID4();
16996
16996
  function readCliVersion() {
16997
16997
  if (true) {
16998
- return "0.34.1-next.81";
16998
+ return "0.34.1-next.82";
16999
16999
  }
17000
17000
  return "0.0.0";
17001
17001
  }
@@ -72947,7 +72947,7 @@ function isCi(env = process.env) {
72947
72947
  var SESSION_ID = (0, import_node_crypto3.randomUUID)();
72948
72948
  function readCliVersion() {
72949
72949
  if (true) {
72950
- return "0.34.1-next.81";
72950
+ return "0.34.1-next.82";
72951
72951
  }
72952
72952
  return "0.0.0";
72953
72953
  }
@@ -124795,6 +124795,10 @@ function forgetNativeUnavailableOf(devices2) {
124795
124795
  if (!covered || covered.has(key2.slice(0, key2.lastIndexOf(":")))) nativeUnavailable.delete(key2);
124796
124796
  }
124797
124797
  }
124798
+ function captureSweepUnderWay(udid) {
124799
+ const device = lockDevice(udid);
124800
+ return [...captureSweeps].some((sweep) => !sweep.devices || sweep.devices.has(device));
124801
+ }
124798
124802
  function withCaptureLock(udid, bundleId, fn) {
124799
124803
  const device = lockDevice(udid);
124800
124804
  const sweeps = [...captureSweeps].filter((sweep) => !sweep.devices || sweep.devices.has(device)).map((sweep) => sweep.done);
@@ -127644,7 +127648,8 @@ function makeNetworkWaitReadScript(mark, metroPort2) {
127644
127648
  url: e.request ? e.request.url : undefined,
127645
127649
  status: e.response ? e.response.status : undefined,
127646
127650
  durationMs: e.durationMs,
127647
- errorText: e.errorText
127651
+ errorText: e.errorText,
127652
+ timestamp: e.timestamp
127648
127653
  });
127649
127654
  }
127650
127655
  return JSON.stringify({
@@ -137108,7 +137113,7 @@ var ALLOWED_TOOLS = /* @__PURE__ */ new Set([
137108
137113
  "fold",
137109
137114
  "tv-remote",
137110
137115
  AWAIT_UI_ELEMENT_TOOL_ID,
137111
- // Returns its match, never an image: after network-capture-start, an
137116
+ // Returns its match or near misses, never an image: after network-capture-start, an
137112
137117
  // action and its wait run as one sequence, and an unmet wait stops it.
137113
137118
  AWAIT_NETWORK_REQUEST_TOOL_ID
137114
137119
  ]);
@@ -139850,7 +139855,7 @@ function createNetworkCaptureStartTool(registry2) {
139850
139855
  id: "network-capture-start",
139851
139856
  description: `Start network capture on iOS simulators and Android<flag:macos-apps> (also on Mac apps)</flag:macos-apps>. Use when you need to inspect traffic from an upcoming action or check a request with await-network-request. A new start keeps the log and begins a new window for the wait. Capture can slow the app.
139852
139857
  On Chromium, Argent connects if needed and marks the start of the wait window. The log records while connected.
139853
- The JavaScript layer needs an app connected to Metro. Start again after its JavaScript loads, including after a reload or relaunch. Android native capture needs a debuggable build.<flag:macos-apps> For a supported React Native app launched from Xcode, use layer js and form udid as macos-app-<bundle id>. Native capture needs a supported build launched through Argent.</flag:macos-apps>
139858
+ The JavaScript layer needs an app connected to Metro. After a reload or relaunch, start capture again once JavaScript loads and before triggering the request. Android native capture needs a debuggable build.<flag:macos-apps> For a supported React Native app launched from Xcode, use layer js and form udid as macos-app-<bundle id>. Native capture needs a supported build launched through Argent.</flag:macos-apps>
139854
139859
  Returns { status, layers }: check armed and reason for each requested layer. A pending native layer can become ready when Argent launches or reconnects to the app. On a device whose devtools agent Argent attached to, start native capture again after a relaunch.
139855
139860
  When every requested layer is unavailable, the call fails with NETWORK_CAPTURE_UNAVAILABLE or TOOL_DEPENDENCY_MISSING.`,
139856
139861
  zodSchema: captureSchema,
@@ -141927,6 +141932,8 @@ init_capability();
141927
141932
 
141928
141933
  // ../tool-server/src/tools/await-network-request/layers.ts
141929
141934
  var CAPTURE_ENDED = "its capture ended after the start (stop-all-simulator-servers, a stop of the device's services, or a tool-server restart); call network-capture-start again";
141935
+ var SWEEP_UNDER_WAY = "stop-all-simulator-servers or the tool-server's exit is ending the app's capture";
141936
+ var CAPTURE_CHANGED = "the app's capture changed during the read (a network-capture-start or -stop, or a teardown of the device), so the read left the app's JS runtime as it was";
141930
141937
  async function liveService(registry2, ref) {
141931
141938
  return isLiveService(registry2, ref.urn) ? registry2.resolveService(ref.urn, ref.options) : void 0;
141932
141939
  }
@@ -141954,7 +141961,9 @@ function fromNative(record2) {
141954
141961
  ...record2.response ? { status: record2.response.status } : {},
141955
141962
  state: lost ? "lost" : record2.state,
141956
141963
  ...record2.timing.durationMs !== void 0 ? { durationMs: Math.round(record2.timing.durationMs) } : {},
141957
- ...record2.errorText ? { errorText: record2.errorText } : {}
141964
+ ...record2.errorText ? { errorText: record2.errorText } : {},
141965
+ // From the agent's wallTime, on the app's clock, as the start of a JS request.
141966
+ startedAt: record2.timing.startedAt
141958
141967
  };
141959
141968
  }
141960
141969
  function nativeAfter(records, floor) {
@@ -142109,7 +142118,8 @@ function fromJs(entry) {
142109
142118
  ...typeof entry.status === "number" ? { status: entry.status } : {},
142110
142119
  state: state3,
142111
142120
  ...typeof entry.durationMs === "number" ? { durationMs: Math.round(entry.durationMs) } : {},
142112
- ...entry.errorText ? { errorText: entry.errorText } : {}
142121
+ ...entry.errorText ? { errorText: entry.errorText } : {},
142122
+ ...typeof entry.timestamp === "number" ? { startedAt: entry.timestamp * 1e3 } : {}
142113
142123
  };
142114
142124
  }
142115
142125
  function jsLayer(registry2, device, bundleId, startWindow) {
@@ -142124,22 +142134,33 @@ function jsLayer(registry2, device, bundleId, startWindow) {
142124
142134
  if (!found2 || !mark) return unreadable("js", CAPTURE_ENDED);
142125
142135
  const { payload, port, capture } = found2;
142126
142136
  let stopped = capture.intent === "stopped";
142127
- if (!isLiveService(registry2, `${JS_RUNTIME_DEBUGGER_NAMESPACE}:${payload}`)) {
142137
+ const physical = capture.physicalDeviceId ?? device.id;
142138
+ if (captureSweepUnderWay(physical)) return unreadable("js", SWEEP_UNDER_WAY, stopped);
142139
+ const urn = `${JS_RUNTIME_DEBUGGER_NAMESPACE}:${payload}`;
142140
+ const live = isLiveService(registry2, urn);
142141
+ if (stopped && !live) {
142128
142142
  return unreadable(
142129
142143
  "js",
142130
- stopped ? "the app's JS runtime is not connected, and a stopped capture does not reconnect to it" : "argent's connection to the app's JS runtime ended (a relaunch, a Metro restart or a stop of the device's services); call network-capture-start again",
142131
- stopped
142144
+ "the app's JS runtime is not connected, and a stopped capture does not reconnect to it",
142145
+ true
142132
142146
  );
142133
142147
  }
142134
- const physical = capture.physicalDeviceId ?? device.id;
142148
+ const whileStarted = (change) => withCaptureLock(physical, bundleId, async () => {
142149
+ if (captureSweepUnderWay(physical)) return { note: SWEEP_UNDER_WAY };
142150
+ const now = findJsCaptureOfDevice(device.id, bundleId);
142151
+ if (!now?.capture.mark) return { note: CAPTURE_ENDED };
142152
+ if (now.capture !== capture || capture.intent !== "started") {
142153
+ return { note: CAPTURE_CHANGED };
142154
+ }
142155
+ return { value: await change() };
142156
+ });
142135
142157
  const target = payload.slice(payload.indexOf(":") + 1);
142136
142158
  try {
142137
- const dbg = await resolveJsRuntime(
142138
- registry2,
142139
- physical,
142140
- target !== physical ? target : void 0,
142141
- port
142159
+ const opened = live ? { value: await registry2.resolveService(urn) } : await whileStarted(
142160
+ () => resolveJsRuntime(registry2, physical, target !== physical ? target : void 0, port)
142142
142161
  );
142162
+ if ("note" in opened) return unreadable("js", opened.note);
142163
+ const dbg = opened.value;
142143
142164
  const appId = dbg.runtimeApp?.appId;
142144
142165
  if (appId !== void 0 && appId !== bundleId) {
142145
142166
  return unreadable(
@@ -142157,6 +142178,10 @@ function jsLayer(registry2, device, bundleId, startWindow) {
142157
142178
  );
142158
142179
  const pauseMissed = stopped && answer.installed && answer.paused === false;
142159
142180
  if (pauseMissed) stopped = false;
142181
+ const resume = !stopped && !pauseMissed && (!answer.installed || answer.paused === true);
142182
+ if (resume && answer.xhr !== true) {
142183
+ return unreadable("js", "the app's JavaScript has not loaded yet", stopped);
142184
+ }
142160
142185
  if (!answer.installed) {
142161
142186
  if (stopped) {
142162
142187
  return {
@@ -142168,29 +142193,45 @@ function jsLayer(registry2, device, bundleId, startWindow) {
142168
142193
  note: "the app's JS runtime reloaded since the stop, which cleared its requests"
142169
142194
  };
142170
142195
  }
142196
+ const installed = await whileStarted(
142197
+ () => installNetworkInterceptor(dbg.cdp, payload, dbg.runtimeApp)
142198
+ );
142199
+ if ("note" in installed) return unreadable("js", installed.note);
142200
+ const install = installed.value;
142171
142201
  return unreadable(
142172
142202
  "js",
142173
- answer.xhr === true ? "the app's JS runtime has no interceptor, as after a reload; call network-capture-start again" : "the app's JavaScript has not loaded yet; call network-capture-start once it has"
142203
+ install.installed ? "the app's JS runtime had no interceptor (it reloaded, or its JavaScript had not loaded at the start), so the wait installed it: requests from now on are recorded, earlier ones in that runtime are missing" : `the interceptor did not install: ${install.reason}`
142174
142204
  );
142175
142205
  }
142176
- const records = (answer.entries ?? []).map(fromJs);
142177
- if (!stopped && answer.paused === true) {
142178
- return {
142179
- layer: "js",
142180
- readable: true,
142181
- armed: false,
142182
- stopped,
142183
- records,
142184
- note: "a stop's pause is still in the app's JS runtime, so it records nothing; call network-capture-start again"
142185
- };
142206
+ let note;
142207
+ if (resume) {
142208
+ const resumed = await whileStarted(
142209
+ () => installNetworkInterceptor(dbg.cdp, payload, dbg.runtimeApp)
142210
+ );
142211
+ if ("note" in resumed) return unreadable("js", resumed.note);
142212
+ const install = resumed.value;
142213
+ note = install.installed ? "a stop's pause was still in the app's JS runtime, so the wait resumed the capture: requests sent while it was paused are missing" : `a stop's pause is still in the app's JS runtime, and the wait could not resume it: ${install.reason}`;
142214
+ if (!install.installed) {
142215
+ return {
142216
+ layer: "js",
142217
+ readable: true,
142218
+ armed: false,
142219
+ stopped,
142220
+ records: (answer.entries ?? []).map(fromJs),
142221
+ note
142222
+ };
142223
+ }
142224
+ } else if (mark.install !== null && answer.token !== mark.install) {
142225
+ note = "the app's JS runtime reloaded after the start, so its requests between the reload and the interceptor's reinstall are missing";
142226
+ } else if (pauseMissed) {
142227
+ note = "the stop's pause did not reach the app's JS runtime, which still records: requests after the stop count";
142186
142228
  }
142187
- const note = mark.install !== null && answer.token !== mark.install ? "the app's JS runtime reloaded after the start, so its requests between the reload and the interceptor's reinstall are missing" : pauseMissed ? "the stop's pause did not reach the app's JS runtime, which still records: requests after the stop count" : void 0;
142188
142229
  return {
142189
142230
  layer: "js",
142190
142231
  readable: true,
142191
142232
  armed: true,
142192
142233
  stopped,
142193
- records,
142234
+ records: (answer.entries ?? []).map(fromJs),
142194
142235
  ...note ? { note } : {}
142195
142236
  };
142196
142237
  } catch (err) {
@@ -142206,6 +142247,9 @@ function jsLayer(registry2, device, bundleId, startWindow) {
142206
142247
  }
142207
142248
 
142208
142249
  // ../tool-server/src/tools/await-network-request/match.ts
142250
+ function withoutStart({ startedAt: _, ...record2 }) {
142251
+ return record2;
142252
+ }
142209
142253
  var STATUS_CLASSES = ["1xx", "2xx", "3xx", "4xx", "5xx"];
142210
142254
  function urlMatches(criteria, url2) {
142211
142255
  switch (criteria.urlMatch) {
@@ -142240,7 +142284,28 @@ function mismatches(criteria, record2) {
142240
142284
  return failed3;
142241
142285
  }
142242
142286
  function firstMatch(criteria, records) {
142243
- return records.find((record2) => mismatches(criteria, record2).length === 0);
142287
+ const found = records.find((record2) => mismatches(criteria, record2).length === 0);
142288
+ return found && withoutStart(found);
142289
+ }
142290
+ var MAX_NEAR_MISSES = 3;
142291
+ var SAME_REQUEST_MS = 1e3;
142292
+ function sameRequest(a, b) {
142293
+ return a.layer !== b.layer && a.method.toLowerCase() === b.method.toLowerCase() && a.url === b.url && a.status === b.status && a.state === b.state && // A retry with the same fields starts later.
142294
+ (a.startedAt === void 0 || b.startedAt === void 0 || Math.abs(a.startedAt - b.startedAt) <= SAME_REQUEST_MS);
142295
+ }
142296
+ function nearMisses(criteria, records) {
142297
+ const ranked = records.map((record2, index) => ({ record: record2, mismatch: mismatches(criteria, record2), index })).sort(
142298
+ (a, b) => Number(a.mismatch.includes("url")) - Number(b.mismatch.includes("url")) || a.mismatch.length - b.mismatch.length || // A record without a start counts as the oldest; NaN, when neither has one, falls through.
142299
+ (b.record.startedAt ?? -Infinity) - (a.record.startedAt ?? -Infinity) || b.index - a.index
142300
+ );
142301
+ const listed = [];
142302
+ for (const { record: record2, mismatch: mismatch2 } of ranked) {
142303
+ if (listed.length === MAX_NEAR_MISSES) break;
142304
+ const of = listed.find((entry) => !entry.twin && sameRequest(entry.record, record2));
142305
+ if (of) of.twin = true;
142306
+ else listed.push({ record: record2, mismatch: mismatch2, twin: false });
142307
+ }
142308
+ return listed.map(({ record: record2, mismatch: mismatch2 }) => ({ ...withoutStart(record2), mismatch: mismatch2 }));
142244
142309
  }
142245
142310
  var NOTE_URL_CHARS = 120;
142246
142311
  function shortUrl(url2) {
@@ -142255,6 +142320,17 @@ function describeCriteria(criteria) {
142255
142320
  criteria.outcome === "any" ? "complete or failed" : criteria.outcome
142256
142321
  ].filter(Boolean).join(", ");
142257
142322
  }
142323
+ function describeRecord(record2) {
142324
+ const parts2 = [
142325
+ `${record2.method || "?"} ${shortUrl(record2.url)}`,
142326
+ record2.status !== void 0 ? String(record2.status) : void 0,
142327
+ record2.state,
142328
+ record2.errorText ? `"${shortUrl(record2.errorText)}"` : void 0,
142329
+ `[${record2.layer} ${record2.id}]`
142330
+ ];
142331
+ const mismatch2 = "mismatch" in record2 ? ` (mismatch: ${record2.mismatch.join(", ")})` : "";
142332
+ return `${parts2.filter(Boolean).join(" ")}${mismatch2}`;
142333
+ }
142258
142334
 
142259
142335
  // ../tool-server/src/tools/await-network-request/index.ts
142260
142336
  var DEFAULT_TIMEOUT_MS4 = 1e4;
@@ -142336,8 +142412,8 @@ function createAwaitNetworkRequestTool(registry2) {
142336
142412
  // A literal, so scripts/extract-tools.mjs finds the description it scores.
142337
142413
  id: "await-network-request",
142338
142414
  description: `Check whether a matching request finished. Use when an action should send a specific request. Call network-capture-start before the action, then call this tool. It searches requests started since the latest capture start and waits until a match finishes or the timeout expires. On Chromium, match the final URL, method and status after redirects.
142339
- Returns the matching request. Pass match.id as requestId to view-network-request-details for headers and bodies. Requests whose outcome capture missed cannot match. When success is false, check cause. For unmet, check the action and criteria. For unreadable, use the layer notes to restore capture. For cancelled, retry if needed. A false result fails an e2e step and stops a run-sequence.
142340
- If capture has no start for the target, the tool raises NETWORK_CAPTURE_NOT_STARTED. Start capture and repeat the action. After a JavaScript reload, start capture again once the runtime is ready.`,
142415
+ Pass match.id as requestId to view-network-request-details for headers and bodies. A request can match only if Argent saw its outcome. When success is false, check cause. For unmet or unreadable, nearMisses can show which criteria captured requests missed. For unreadable, follow the layer notes to restore capture and repeat the action. For cancelled, retry if needed. A false result fails an e2e step and stops a run-sequence.
142416
+ If the tool raises NETWORK_CAPTURE_NOT_STARTED, start capture and repeat the action. While the JavaScript capture window is active, the wait can reconnect to the runtime and restore recording. Requests sent before recording resumes may be missing.`,
142341
142417
  zodSchema: zodSchema44,
142342
142418
  searchHint: "wait await network request http api call fetch xhr response status url match after capture start e2e assert",
142343
142419
  readOnly: true,
@@ -142473,17 +142549,25 @@ If capture has no start for the target, the tool raises NETWORK_CAPTURE_NOT_STAR
142473
142549
  ...last?.note ? { note: last.note } : {}
142474
142550
  };
142475
142551
  });
142552
+ const seen = [...latestReadable.values()].flatMap((read) => read.records);
142553
+ const misses = nearMisses(criteria, seen);
142476
142554
  const counts = summaries.map(
142477
142555
  (s) => `${s.layer} ${s.readable ? s.requests : "not read"}${s.armed ? "" : " (not armed)"}`
142478
142556
  ).join(", ");
142479
142557
  const head = allStopped ? `No request matched (wanted: ${describeCriteria(criteria)}): capture is stopped on every marked layer, so only the requests captured between network-capture-start and network-capture-stop were searched.` : `No request since network-capture-start matched within this ${timeoutMs} ms wait (wanted: ${describeCriteria(criteria)}).`;
142480
142558
  const notes = summaries.filter((s) => s.note).map((s) => `${s.layer}: ${s.note}`).join("; ");
142481
- const note = [head, `Requests since the start: ${counts}.`, notes ? `${notes}.` : void 0].filter(Boolean).join(" ");
142559
+ const note = [
142560
+ head,
142561
+ `Requests since the start: ${counts}.`,
142562
+ notes ? `${notes}.` : void 0,
142563
+ misses.length > 0 ? `Nearest: ${misses.map(describeRecord).join("; ")}.` : void 0
142564
+ ].filter(Boolean).join(" ");
142482
142565
  return {
142483
142566
  success: false,
142484
142567
  elapsed: elapsed(),
142485
142568
  cause,
142486
142569
  note,
142570
+ nearMisses: misses,
142487
142571
  layers: summaries
142488
142572
  };
142489
142573
  }
@@ -163132,7 +163216,7 @@ function unmetWaitWarningFor(cause) {
163132
163216
  if (cause === "cancelled") return CANCELLED_WAIT_WARNING;
163133
163217
  return UNMET_WAIT_WARNING;
163134
163218
  }
163135
- var UNMET_NETWORK_WAIT_WARNING = "recorded, but the wait never held: `await-network-request` returned success:false, and at replay an unmet wait FAILS the step. `toolResult.note` counts the requests since the start per layer: fix the matcher, or record the action that sends the request, then record the wait again. Delete the failed step after `e2e-finish-recording`, not mid-recording";
163219
+ var UNMET_NETWORK_WAIT_WARNING = "recorded, but the wait never held: `await-network-request` returned success:false, and at replay an unmet wait FAILS the step. `toolResult.nearMisses` lists the closest requests and the criteria each missed: fix the matcher, or record the action that sends the request, then record the wait again. Delete the failed step after `e2e-finish-recording`, not mid-recording";
163136
163220
  var UNREADABLE_NETWORK_WAIT_WARNING = "recorded, but no armed capture layer was read near the deadline, so the request was never judged and whether it is sent is UNKNOWN: `toolResult.layers` says why. Get the layer back (for example call network-capture-start again once the app's JavaScript has loaded) and record the wait again. Do not delete the step on this warning alone";
163137
163221
  var CANCELLED_NETWORK_WAIT_WARNING = "recorded, but this wait was cancelled before its deadline, so whether the request is sent is UNKNOWN: record the step again to find out";
163138
163222
  function unmetNetworkWaitWarningFor(cause) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swmansion/argent",
3
- "version": "0.34.1-next.82",
3
+ "version": "0.34.1-next.83",
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": "8eb9229560692d827bdd12df1ce9605d45995fd8"
101
+ "gitHead": "e7971422599e364b63aedc5648004cce59a4d074"
102
102
  }
@@ -163,7 +163,7 @@ Keep the wait as a `tool:` step in YAML. Match on a part of the URL that contain
163
163
 
164
164
  On Android, capture can slow the app. Start just before the triggering action and stop immediately after the wait, before checking the UI. For many related requests, keep capture running through the group and stop after the last wait. If a replay fails before the stop, stop capture before retrying.
165
165
 
166
- If the recorder reports `NETWORK_CAPTURE_NOT_STARTED`, record the start and repeat the action. If it records a wait with `success: false`, read the warning. For `unmet`, inspect the request counts in `toolResult.note` and check the action and matcher. For `unreadable`, fix the layer named in the result before repeating the action. For `cancelled`, record the wait again. Remove superseded steps after `e2e-finish-recording`.
166
+ If the recorder reports `NETWORK_CAPTURE_NOT_STARTED`, record the start and repeat the action. If it records a wait with `success: false`, read the warning. For `unmet`, use `toolResult.nearMisses` and the request counts in `toolResult.note` to check the matcher and the recorded action. For `unreadable`, fix the layer named in the result before repeating the action. For `cancelled`, record the wait again. Remove superseded steps after `e2e-finish-recording`.
167
167
 
168
168
  ### Wrong turns
169
169