@swmansion/argent 0.35.1-next.74 → 0.35.1-next.75

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
@@ -41591,6 +41591,8 @@ ${renderSummary(report, { withDevice: true })}`);
41591
41591
  // ../argent-cli/src/run-device-env.ts
41592
41592
  var DEVICE_ENV_VAR = "ARGENT_UDID";
41593
41593
  var DEVICE_FIELDS = ["udid", "device_id"];
41594
+ var DEVICE_FLAG_SPELLINGS = /* @__PURE__ */ new Set(["udid", "deviceid", "device", "serial", "id", "uuid"]);
41595
+ var LEADING_DASH = /^[-\u2013\u2014]/;
41594
41596
  function requiredDeviceField(schema) {
41595
41597
  const properties = schema?.properties ?? {};
41596
41598
  const required2 = schema?.required ?? [];
@@ -41598,11 +41600,28 @@ function requiredDeviceField(schema) {
41598
41600
  (name) => required2.includes(name) && properties[name] && !isRetiredField(properties[name])
41599
41601
  );
41600
41602
  }
41601
- function applyDeviceFromEnv(payload, schema, env = process.env) {
41603
+ function isDeviceFlagSpelling(name) {
41604
+ return DEVICE_FLAG_SPELLINGS.has(name.toLowerCase().replace(/[^a-z]/g, ""));
41605
+ }
41606
+ function findMistypedDeviceFlag(payload, positional, schema) {
41607
+ const properties = schema?.properties ?? {};
41608
+ const mistypedKey = Object.keys(payload).find(
41609
+ (key) => !Object.hasOwn(properties, key) && isDeviceFlagSpelling(key)
41610
+ );
41611
+ if (mistypedKey) return `--${mistypedKey}`;
41612
+ return positional.find(
41613
+ (token) => LEADING_DASH.test(token) && isDeviceFlagSpelling(token.split("=")[0])
41614
+ );
41615
+ }
41616
+ function applyDeviceFromEnv(payload, schema, positional, env = process.env) {
41602
41617
  const deviceId = env[DEVICE_ENV_VAR]?.trim();
41603
- if (!deviceId) return;
41618
+ if (!deviceId) return void 0;
41604
41619
  const field = requiredDeviceField(schema);
41605
- if (field && !Object.hasOwn(payload, field)) payload[field] = deviceId;
41620
+ if (!field || Object.hasOwn(payload, field)) return void 0;
41621
+ const mistyped = findMistypedDeviceFlag(payload, positional, schema);
41622
+ if (mistyped) return mistyped;
41623
+ payload[field] = deviceId;
41624
+ return void 0;
41606
41625
  }
41607
41626
 
41608
41627
  // ../argent-cli/src/run.ts
@@ -41661,6 +41680,9 @@ ${description}
41661
41680
  console.log(" --json Print the raw JSON result");
41662
41681
  console.log(" --out <path> For image results, save to <path> instead of fetching URL");
41663
41682
  console.log(" --help, -h Show this help");
41683
+ const deviceField = requiredDeviceField(schema);
41684
+ if (deviceField) console.log(`
41685
+ ARGENT_UDID sets --${deviceField} when the call leaves it out.`);
41664
41686
  }
41665
41687
  async function fetchImageToFile(result, outPath) {
41666
41688
  const url2 = result.url;
@@ -41762,6 +41784,7 @@ settled=false or debugger-status's not_connected.
41762
41784
  process.exit(1);
41763
41785
  }
41764
41786
  const schema = meta3.inputSchema;
41787
+ const deviceField = requiredDeviceField(schema);
41765
41788
  const failInvocation = async (summary, report, failure3) => {
41766
41789
  if (json2) {
41767
41790
  console.error(
@@ -41787,7 +41810,7 @@ settled=false or debugger-status's not_connected.
41787
41810
  });
41788
41811
  process.exit(2);
41789
41812
  };
41790
- const failValidation = (report, stage) => failInvocation(formatValidationError(report, schema), report, {
41813
+ const failValidation = (report, stage, hint = "") => failInvocation(formatValidationError(report, schema) + hint, report, {
41791
41814
  error_code: FAILURE_CODES.CLI_RUN_INPUT_VALIDATION_FAILED,
41792
41815
  failure_stage: stage
41793
41816
  });
@@ -41807,11 +41830,6 @@ settled=false or debugger-status's not_connected.
41807
41830
  printToolHelp(meta3);
41808
41831
  return;
41809
41832
  }
41810
- if (parsed.positional.length > 0) {
41811
- console.error(
41812
- `Note: ignoring unused argument(s): ${parsed.positional.join(", ")}. Pass values as --flag <value> or --flag=<value>.`
41813
- );
41814
- }
41815
41833
  let payload = {};
41816
41834
  if (parsed.rawArgs !== null) {
41817
41835
  let rawJson = parsed.rawArgs;
@@ -41845,10 +41863,30 @@ settled=false or debugger-status's not_connected.
41845
41863
  for (const [k, v] of Object.entries(parsed.args)) {
41846
41864
  payload[k] = v;
41847
41865
  }
41848
- applyDeviceFromEnv(payload, schema);
41866
+ const mistypedDeviceFlag = applyDeviceFromEnv(payload, schema, parsed.positional);
41867
+ if (mistypedDeviceFlag) {
41868
+ await failInvocation(
41869
+ `unknown flag ${mistypedDeviceFlag} (did you mean --${deviceField}?)`,
41870
+ null,
41871
+ {
41872
+ error_code: FAILURE_CODES.CLI_RUN_FLAG_PARSE_FAILED,
41873
+ failure_stage: "cli_run_device_env"
41874
+ }
41875
+ );
41876
+ }
41877
+ if (parsed.positional.length > 0) {
41878
+ console.error(
41879
+ `Note: ignoring unused argument(s): ${parsed.positional.join(", ")}. Pass values as --flag <value> or --flag=<value>.`
41880
+ );
41881
+ }
41849
41882
  const missing = findMissingRequired(payload, schema);
41850
41883
  if (missing.length > 0) {
41851
- await failValidation({ missing, invalid: [], rawIssues: null }, "cli_run_required_flags");
41884
+ const envHint = deviceField && missing.includes(deviceField) ? ` (--${deviceField} can come from ARGENT_UDID)` : "";
41885
+ await failValidation(
41886
+ { missing, invalid: [], rawIssues: null },
41887
+ "cli_run_required_flags",
41888
+ envHint
41889
+ );
41852
41890
  }
41853
41891
  let result;
41854
41892
  let note2;
@@ -22853,6 +22853,11 @@ function terminatingSignalCause(message) {
22853
22853
  error_kind: "unknown"
22854
22854
  });
22855
22855
  }
22856
+ function serviceTerminatingError(urn) {
22857
+ return new ServiceInitializationError(urn, "Service is currently terminating", {
22858
+ cause: terminatingSignalCause("Service is currently terminating")
22859
+ });
22860
+ }
22856
22861
  function valueAtPath(root, path78) {
22857
22862
  let current = root;
22858
22863
  for (const key2 of path78) {
@@ -22936,6 +22941,14 @@ var init_registry = __esm({
22936
22941
  services = /* @__PURE__ */ new Map();
22937
22942
  blueprints = /* @__PURE__ */ new Map();
22938
22943
  tools = /* @__PURE__ */ new Map();
22944
+ /**
22945
+ * Teardowns of services that ended themselves without a fault, for example
22946
+ * after an idle window. A resolve that arrives during one waits for it and starts the
22947
+ * service again, unless `dispose` or `disposeService` is running.
22948
+ */
22949
+ selfReleases = /* @__PURE__ */ new Map();
22950
+ disposeCalls = 0;
22951
+ disposingUrns = /* @__PURE__ */ new Set();
22939
22952
  /** Alias → the id of the tool that declares it in `aliases`. */
22940
22953
  toolAliases = /* @__PURE__ */ new Map();
22941
22954
  /**
@@ -23142,13 +23155,28 @@ var init_registry = __esm({
23142
23155
  async disposeService(urn) {
23143
23156
  const node2 = this.services.get(urn);
23144
23157
  if (!node2) throw new ServiceNotFoundError(urn);
23145
- await this._teardown(urn);
23158
+ const selfRelease = this.selfReleases.get(urn);
23159
+ if (!selfRelease) return this._teardown(urn);
23160
+ this.disposingUrns.add(urn);
23161
+ try {
23162
+ await selfRelease;
23163
+ await this._teardown(urn);
23164
+ } finally {
23165
+ this.disposingUrns.delete(urn);
23166
+ }
23146
23167
  }
23147
23168
  async dispose() {
23148
- for (const [urn, node2] of this.services) {
23149
- if (node2.state === "RUNNING" /* RUNNING */ || node2.state === "STARTING" /* STARTING */) {
23150
- await this._teardown(urn);
23169
+ this.disposeCalls++;
23170
+ try {
23171
+ for (const [urn, node2] of this.services) {
23172
+ const selfRelease = this.selfReleases.get(urn);
23173
+ if (selfRelease) await selfRelease;
23174
+ if (node2.state === "RUNNING" /* RUNNING */ || node2.state === "STARTING" /* STARTING */) {
23175
+ await this._teardown(urn);
23176
+ }
23151
23177
  }
23178
+ } finally {
23179
+ this.disposeCalls--;
23152
23180
  }
23153
23181
  }
23154
23182
  _resolve(urn, resolutionPath, options) {
@@ -23182,12 +23210,13 @@ var init_registry = __esm({
23182
23210
  )
23183
23211
  );
23184
23212
  }
23213
+ const selfRelease = this.selfReleases.get(urn);
23214
+ if (selfRelease) {
23215
+ if (this._disposing(urn)) return Promise.reject(serviceTerminatingError(urn));
23216
+ return selfRelease.then(() => this._resolveAfterSelfRelease(urn, resolutionPath, options));
23217
+ }
23185
23218
  if (node2.state === "TERMINATING" /* TERMINATING */) {
23186
- return Promise.reject(
23187
- new ServiceInitializationError(urn, "Service is currently terminating", {
23188
- cause: terminatingSignalCause("Service is currently terminating")
23189
- })
23190
- );
23219
+ return Promise.reject(serviceTerminatingError(urn));
23191
23220
  }
23192
23221
  if (node2.state === "RUNNING" /* RUNNING */ && node2.instance) {
23193
23222
  return Promise.resolve(node2.instance.api);
@@ -23225,7 +23254,9 @@ var init_registry = __esm({
23225
23254
  this._transition(node2, "RUNNING" /* RUNNING */);
23226
23255
  node2.instance = instance;
23227
23256
  instance.events.on("terminated", (error63) => {
23228
- void this._teardown(urn, error63);
23257
+ const selfRelease = !error63 && node2.state === "RUNNING" /* RUNNING */;
23258
+ const teardown = this._teardown(urn, error63);
23259
+ if (selfRelease) this._trackSelfRelease(urn, teardown);
23229
23260
  });
23230
23261
  return instance.api;
23231
23262
  } catch (error63) {
@@ -23238,6 +23269,18 @@ var init_registry = __esm({
23238
23269
  throw new ServiceInitializationError(urn, cause.message, { cause });
23239
23270
  }
23240
23271
  }
23272
+ _resolveAfterSelfRelease(urn, resolutionPath, options) {
23273
+ if (this._disposing(urn)) return Promise.reject(serviceTerminatingError(urn));
23274
+ return this._resolve(urn, resolutionPath, options);
23275
+ }
23276
+ _disposing(urn) {
23277
+ return this.disposeCalls > 0 || this.disposingUrns.has(urn);
23278
+ }
23279
+ _trackSelfRelease(urn, teardown) {
23280
+ this.selfReleases.set(urn, teardown);
23281
+ const forget2 = () => this.selfReleases.delete(urn);
23282
+ void teardown.then(forget2, forget2);
23283
+ }
23241
23284
  _transition(node2, to, cause) {
23242
23285
  const from2 = node2.state;
23243
23286
  node2.state = to;
@@ -100982,6 +101025,16 @@ function transportError(cmd, apiUrl, detail) {
100982
101025
  COMMAND_TRANSPORT_FAILURE
100983
101026
  );
100984
101027
  }
101028
+ function connectionRefusedError(cmd, api) {
101029
+ const next = api.external ? `Check that the provider's simulator-server at ${api.apiUrl} is running.` : "The next call connects to a new simulator-server.";
101030
+ return new FailureError(
101031
+ `simulator-server did not accept the '${cmd}' command: the connection was refused. The command was NOT delivered to the device. ${next}`,
101032
+ { ...COMMAND_TRANSPORT_FAILURE, failure_stage: "simulator_command_connection_refused" }
101033
+ );
101034
+ }
101035
+ function isConnectionRefused(err) {
101036
+ return err.code === "ECONNREFUSED";
101037
+ }
100985
101038
  function remoteTransportError(cmd, cause) {
100986
101039
  const detail = cause instanceof Error ? cause.message : String(cause);
100987
101040
  return wrapFailure(
@@ -100994,11 +101047,12 @@ function getOrCreateConnection(api) {
100994
101047
  const key2 = api.apiUrl;
100995
101048
  const existing = connections.get(key2);
100996
101049
  if (existing && (existing.ws.readyState === wrapper_default.OPEN || existing.ws.readyState === wrapper_default.CONNECTING)) {
101050
+ existing.apis.add(api);
100997
101051
  return existing;
100998
101052
  }
100999
101053
  const { host } = new URL(api.apiUrl);
101000
101054
  const ws = new wrapper_default(`ws://${host}/ws`);
101001
- const conn = { ws, pending: /* @__PURE__ */ new Map(), heldKeys: [] };
101055
+ const conn = { ws, pending: /* @__PURE__ */ new Map(), heldKeys: [], apis: /* @__PURE__ */ new Set([api]) };
101002
101056
  ws.on("message", (data) => {
101003
101057
  const text = Buffer.isBuffer(data) ? data.toString() : Array.isArray(data) ? Buffer.concat(data).toString() : Buffer.from(data).toString();
101004
101058
  let ack;
@@ -101033,6 +101087,11 @@ function getOrCreateConnection(api) {
101033
101087
  });
101034
101088
  ws.on("error", (err) => {
101035
101089
  connections.delete(key2);
101090
+ if (isConnectionRefused(err)) {
101091
+ failAllPending(conn, (cmd) => connectionRefusedError(cmd, api));
101092
+ for (const user of conn.apis) user.onConnectionRefused?.();
101093
+ return;
101094
+ }
101036
101095
  failAllPending(conn, (cmd) => transportError(cmd, key2, err.message));
101037
101096
  });
101038
101097
  ws.on("close", () => {
@@ -101063,8 +101122,8 @@ async function sendCommandUnlocked(api, cmd, options) {
101063
101122
  await sendViaTransport(api.transport, native, cmdName);
101064
101123
  return turnWarning !== void 0 ? { warning: turnWarning } : {};
101065
101124
  }
101066
- const conn = getOrCreateConnection(api);
101067
101125
  const { cmd: targeted, warning: screenWarning } = await withActiveScreen(api, native);
101126
+ const conn = getOrCreateConnection(api);
101068
101127
  const warning = turnWarning !== void 0 && screenWarning !== void 0 ? `${screenWarning} ${turnWarning}` : screenWarning ?? turnWarning;
101069
101128
  const id = String(++cmdId);
101070
101129
  const payload = JSON.stringify({ id, ...targeted });
@@ -104512,10 +104571,12 @@ async function buildAttachedInstance(device, externalDevice) {
104512
104571
  `${externalDevice.provider.name} did not publish a simulator-server endpoint for this device`
104513
104572
  );
104514
104573
  }
104574
+ const events = new TypedEventEmitter();
104515
104575
  const api = {
104516
104576
  apiUrl: externalDevice.simulatorServer.apiUrl,
104517
104577
  deviceId: device.id,
104518
104578
  external: true,
104579
+ onConnectionRefused: () => events.emit("terminated", connectionRefusedTermination()),
104519
104580
  pressKey: async (direction, code) => {
104520
104581
  await sendCommand(api, { cmd: "key", code, direction }, { ackTimeoutMs: KEY_ACK_TIMEOUT_MS });
104521
104582
  },
@@ -104527,9 +104588,18 @@ async function buildAttachedInstance(device, externalDevice) {
104527
104588
  api,
104528
104589
  dispose: async () => {
104529
104590
  },
104530
- events: new TypedEventEmitter()
104591
+ events
104531
104592
  };
104532
104593
  }
104594
+ function connectionRefusedTermination() {
104595
+ return new FailureError("simulator-server refused the command connection", {
104596
+ error_code: FAILURE_CODES.SIMULATOR_SERVER_TERMINATED,
104597
+ failure_stage: "simulator_server_connection_refused",
104598
+ failure_area: "tool_server",
104599
+ error_kind: "network",
104600
+ network_failure: "connection_refused"
104601
+ });
104602
+ }
104533
104603
  var SAFE_SIMULATOR_DEVICE_ID = /^[A-Za-z0-9][A-Za-z0-9._:-]*$/;
104534
104604
  function subcommandForDevice(device) {
104535
104605
  if (device.platform === "ios") {
@@ -104821,6 +104891,7 @@ var simulatorServerBlueprint = {
104821
104891
  apiUrl,
104822
104892
  streamUrl,
104823
104893
  deviceId: device.id,
104894
+ onConnectionRefused: () => events.emit("terminated", connectionRefusedTermination()),
104824
104895
  /**
104825
104896
  * Over the WebSocket, not stdin: simulator-server never replies on
104826
104897
  * stdin, so a stdin write resolved at once and a stalled server let keys
@@ -111670,6 +111741,7 @@ var READY_TIMEOUT_MS2 = 3e4;
111670
111741
  var EXIT_GRACE_MS2 = 200;
111671
111742
  var HELPER_EXIT_TIMEOUT_MS = 3e3;
111672
111743
  var DISPOSE_FORCE_STOP_WAIT_MS = 2e3;
111744
+ var HELPER_IDLE_RELEASE_MS = 18e4;
111673
111745
  var HELPER_PORT_MARKER = /^INSTRUMENTATION_STATUS:\s*port=(\d+)/;
111674
111746
  var ADB_FORWARD_PORT_MARKER = /^(\d+)\s*$/;
111675
111747
  var HELPER_STATUS_MARKER = /^INSTRUMENTATION_STATUS:\s*Error=/;
@@ -112047,7 +112119,50 @@ var androidDevtoolsBlueprint = {
112047
112119
  throw err;
112048
112120
  }
112049
112121
  };
112050
- const request4 = async (method, params) => send(await connected(), method, params);
112122
+ let idleTimer;
112123
+ const armIdleRelease = () => {
112124
+ clearTimeout(idleTimer);
112125
+ idleTimer = setTimeout(() => events.emit("terminated"), HELPER_IDLE_RELEASE_MS);
112126
+ idleTimer.unref();
112127
+ };
112128
+ const tracked = (call) => {
112129
+ clearTimeout(idleTimer);
112130
+ return call().finally(() => {
112131
+ if (!disposed) armIdleRelease();
112132
+ });
112133
+ };
112134
+ armIdleRelease();
112135
+ const request4 = (method, params) => tracked(async () => send(await connected(), method, params));
112136
+ const sendSetText = async (text, setOpts) => {
112137
+ const current = await connected();
112138
+ let result;
112139
+ try {
112140
+ result = await send(current, "setText", {
112141
+ text,
112142
+ ...setOpts.check ? { check: true } : {}
112143
+ });
112144
+ } catch (err) {
112145
+ if (err instanceof Error && err.message.includes("Unknown method: setText")) {
112146
+ throw new FailureError("The devtools helper predates `setText`; update argent", {
112147
+ error_code: FAILURE_CODES.ANDROID_DEVTOOLS_RPC_ERROR,
112148
+ failure_stage: "android_devtools_set_text",
112149
+ failure_area: "tool_server",
112150
+ error_kind: "unknown"
112151
+ });
112152
+ }
112153
+ if (getFailureSignal(err)?.error_code === FAILURE_CODES.ANDROID_DEVTOOLS_RPC_TIMEOUT || err instanceof Error && err.message.includes("Helper worker timed out")) {
112154
+ return { focused: true, verified: false, timedOut: true };
112155
+ }
112156
+ throw err;
112157
+ }
112158
+ return {
112159
+ focused: result.focused === true,
112160
+ verified: result.verified === true,
112161
+ ...typeof result.performed === "boolean" ? { performed: result.performed } : {},
112162
+ ...typeof result.password === "boolean" ? { password: result.password } : {},
112163
+ ...result.singleLine === true ? { singleLine: true } : {}
112164
+ };
112165
+ };
112051
112166
  const api = {
112052
112167
  isReady: () => ready2 && !disposed,
112053
112168
  getHierarchy(getOpts = {}) {
@@ -112064,35 +112179,8 @@ var androidDevtoolsBlueprint = {
112064
112179
  ping() {
112065
112180
  return request4("ping");
112066
112181
  },
112067
- async setText(text, setOpts = {}) {
112068
- const current = await connected();
112069
- let result;
112070
- try {
112071
- result = await send(current, "setText", {
112072
- text,
112073
- ...setOpts.check ? { check: true } : {}
112074
- });
112075
- } catch (err) {
112076
- if (err instanceof Error && err.message.includes("Unknown method: setText")) {
112077
- throw new FailureError("The devtools helper predates `setText`; update argent", {
112078
- error_code: FAILURE_CODES.ANDROID_DEVTOOLS_RPC_ERROR,
112079
- failure_stage: "android_devtools_set_text",
112080
- failure_area: "tool_server",
112081
- error_kind: "unknown"
112082
- });
112083
- }
112084
- if (getFailureSignal(err)?.error_code === FAILURE_CODES.ANDROID_DEVTOOLS_RPC_TIMEOUT || err instanceof Error && err.message.includes("Helper worker timed out")) {
112085
- return { focused: true, verified: false, timedOut: true };
112086
- }
112087
- throw err;
112088
- }
112089
- return {
112090
- focused: result.focused === true,
112091
- verified: result.verified === true,
112092
- ...typeof result.performed === "boolean" ? { performed: result.performed } : {},
112093
- ...typeof result.password === "boolean" ? { password: result.password } : {},
112094
- ...result.singleLine === true ? { singleLine: true } : {}
112095
- };
112182
+ setText(text, setOpts = {}) {
112183
+ return tracked(() => sendSetText(text, setOpts));
112096
112184
  }
112097
112185
  };
112098
112186
  const instance = {
@@ -112100,6 +112188,7 @@ var androidDevtoolsBlueprint = {
112100
112188
  dispose: async () => {
112101
112189
  disposed = true;
112102
112190
  ready2 = false;
112191
+ clearTimeout(idleTimer);
112103
112192
  let opening;
112104
112193
  let acknowledged = false;
112105
112194
  if (!procExited) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swmansion/argent",
3
- "version": "0.35.1-next.74",
3
+ "version": "0.35.1-next.75",
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": "8909a5d03b40301a5ee5fb9692830725f62cfa0a"
101
+ "gitHead": "0517476863d35302ed47ccd10a383b7563b1eb20"
102
102
  }