@swmansion/argent 0.34.1-next.0 → 0.34.1-next.10

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.
@@ -895,14 +895,6 @@ var init_config_schema = __esm({
895
895
  // drained/reset, not just the file rewritten.
896
896
  manageCommand: "argent telemetry"
897
897
  },
898
- {
899
- key: "allowlist.enabled",
900
- description: "Whether `argent update` re-applies editor auto-approve allowlist rules. Unset (the default) keeps the current behavior: update refreshes the rules for editors that already have argent configured. Set to `false` to keep update from touching editor allowlists. `false` in either scope wins, so a committed project opt-out holds for every teammate.",
901
- scopes: ["project", "global"],
902
- parse: asBoolean,
903
- merge: "prioritize-restrictive",
904
- example: "false"
905
- },
906
898
  {
907
899
  key: "lens.agent",
908
900
  description: "Coding-agent id remembered by `argent lens` to skip the picker.",
@@ -1595,6 +1587,10 @@ var init_failure_codes = __esm({
1595
1587
  AX_DAEMON_READY_TIMEOUT: "AX_DAEMON_READY_TIMEOUT",
1596
1588
  AX_DAEMON_EXITED_BEFORE_READY: "AX_DAEMON_EXITED_BEFORE_READY",
1597
1589
  AX_DAEMON_PROCESS_ERROR: "AX_DAEMON_PROCESS_ERROR",
1590
+ // The daemon died on a fault signal (SIGSEGV, SIGABRT, ...), before or after
1591
+ // it connected. Kept apart from the two codes above so a crash is not read
1592
+ // as an ordinary exit.
1593
+ AX_DAEMON_CRASHED: "AX_DAEMON_CRASHED",
1598
1594
  AX_FACTORY_OPTIONS_MISSING: "AX_FACTORY_OPTIONS_MISSING",
1599
1595
  AX_WRONG_PLATFORM: "AX_WRONG_PLATFORM",
1600
1596
  AX_DEVICE_ID_INVALID: "AX_DEVICE_ID_INVALID",
@@ -79843,10 +79839,10 @@ async function probeAlive(device) {
79843
79839
  async function listExternalDevices(options = {}) {
79844
79840
  const providers = discoverProviders();
79845
79841
  if (providers.length === 0) return [];
79846
- const devices = providers.flatMap((record2) => readProviderDevices2(record2));
79847
- if (options.probe === false) return devices;
79848
- const alive = await Promise.all(devices.map((device) => probeAlive(device).catch(() => false)));
79849
- return devices.filter((_, index) => alive[index]);
79842
+ const devices2 = providers.flatMap((record2) => readProviderDevices2(record2));
79843
+ if (options.probe === false) return devices2;
79844
+ const alive = await Promise.all(devices2.map((device) => probeAlive(device).catch(() => false)));
79845
+ return devices2.filter((_, index) => alive[index]);
79850
79846
  }
79851
79847
  function findExternalDevice(id) {
79852
79848
  const parsed = parseExternalId(id);
@@ -84116,7 +84112,7 @@ async function removeAdbReverse(serial, devicePort) {
84116
84112
  }
84117
84113
  }
84118
84114
  function parseAdbDevices(stdout) {
84119
- const devices = [];
84115
+ const devices2 = [];
84120
84116
  const lines = stdout.split("\n");
84121
84117
  for (const raw of lines) {
84122
84118
  const line = raw.trim();
@@ -84125,9 +84121,9 @@ function parseAdbDevices(stdout) {
84125
84121
  if (!match) continue;
84126
84122
  const state3 = match[2];
84127
84123
  if (!ADB_DEVICE_STATES.has(state3)) continue;
84128
- devices.push({ serial: match[1], state: state3 });
84124
+ devices2.push({ serial: match[1], state: state3 });
84129
84125
  }
84130
- return devices;
84126
+ return devices2;
84131
84127
  }
84132
84128
  function consolePortFromAdbSerial(serial) {
84133
84129
  const emu = serial.match(/^emulator-(\d+)$/);
@@ -100671,7 +100667,8 @@ var ALLOWED = {
100671
100667
  install_mode: INSTALL_MODE
100672
100668
  },
100673
100669
  "installation:allowlist_decision": {
100674
- is_enabled: bool
100670
+ is_enabled: bool,
100671
+ decided_by: oneOf(["flag", "default", "prompt"])
100675
100672
  },
100676
100673
  "installation:stale_config_cleanup": {
100677
100674
  removed_count: COUNT,
@@ -101281,7 +101278,7 @@ var _CI_VENDOR_COUNT_FOR_TEST = vendors_default.length;
101281
101278
  var SESSION_ID = (0, import_node_crypto3.randomUUID)();
101282
101279
  function readCliVersion() {
101283
101280
  if (true) {
101284
- return "0.34.1-next.0";
101281
+ return "0.34.1-next.10";
101285
101282
  }
101286
101283
  return "0.0.0";
101287
101284
  }
@@ -103827,7 +103824,7 @@ async function setContainsUdid(deviceSet, udid) {
103827
103824
  );
103828
103825
  const data = JSON.parse(stdout);
103829
103826
  return Object.values(data.devices ?? {}).some(
103830
- (devices) => devices.some((d) => d.udid === udid)
103827
+ (devices2) => devices2.some((d) => d.udid === udid)
103831
103828
  );
103832
103829
  } catch {
103833
103830
  return false;
@@ -103926,10 +103923,10 @@ async function listDeviceSetSimulators(deviceSet) {
103926
103923
  const data = JSON.parse(stdout);
103927
103924
  const out = [];
103928
103925
  const deviceTypes = [];
103929
- for (const [runtimeId, devices] of Object.entries(data.devices)) {
103926
+ for (const [runtimeId, devices2] of Object.entries(data.devices)) {
103930
103927
  const runtimeKind = simulatorRuntimeKind(runtimeId);
103931
103928
  if (!runtimeKind) continue;
103932
- for (const d of devices) {
103929
+ for (const d of devices2) {
103933
103930
  if (!d.isAvailable) continue;
103934
103931
  out.push({
103935
103932
  udid: d.udid,
@@ -104180,8 +104177,8 @@ async function getRemoteSimulatorRuntimeKind(udid, options) {
104180
104177
  const cached3 = remoteRuntimeKindCache.get(id);
104181
104178
  if (cached3) return cached3;
104182
104179
  try {
104183
- const { devices } = await simctlListDevices(options);
104184
- for (const [runtime, entries] of Object.entries(devices)) {
104180
+ const { devices: devices2 } = await simctlListDevices(options);
104181
+ for (const [runtime, entries] of Object.entries(devices2)) {
104185
104182
  if (!entries.some((d) => d.udid === id)) continue;
104186
104183
  const kind = simulatorRuntimeKind(runtime);
104187
104184
  if (kind) remoteRuntimeKindCache.set(id, kind);
@@ -104695,7 +104692,112 @@ function startListener(endpoint, onConnection) {
104695
104692
  }
104696
104693
  });
104697
104694
  }
104698
- function waitForDaemonConnection(server, proc, timeoutMs) {
104695
+ var DARWIN_SIGNALS = {
104696
+ 1: "SIGHUP",
104697
+ 2: "SIGINT",
104698
+ 3: "SIGQUIT",
104699
+ 4: "SIGILL",
104700
+ 5: "SIGTRAP",
104701
+ 6: "SIGABRT",
104702
+ 7: "SIGEMT",
104703
+ 8: "SIGFPE",
104704
+ 9: "SIGKILL",
104705
+ 10: "SIGBUS",
104706
+ 11: "SIGSEGV",
104707
+ 12: "SIGSYS",
104708
+ 13: "SIGPIPE",
104709
+ 14: "SIGALRM",
104710
+ 15: "SIGTERM"
104711
+ };
104712
+ var FAULT_SIGNALS = /* @__PURE__ */ new Set([
104713
+ "SIGILL",
104714
+ "SIGTRAP",
104715
+ "SIGABRT",
104716
+ "SIGEMT",
104717
+ "SIGFPE",
104718
+ "SIGBUS",
104719
+ "SIGSEGV",
104720
+ "SIGSYS"
104721
+ ]);
104722
+ var SIMCTL_CHILD_SIGNAL = /Child process terminated with signal (\d+)/;
104723
+ var STDERR_DRAIN_MS = 250;
104724
+ var STDERR_TAIL_CHARS = 4e3;
104725
+ var DAEMON_EXIT_GRACE_MS = 1e3;
104726
+ function readAxDaemonExit(code, signal, stderr) {
104727
+ if (signal) return { code, signal };
104728
+ const reported = SIMCTL_CHILD_SIGNAL.exec(stderr);
104729
+ if (!reported) return { code };
104730
+ const number4 = Number(reported[1]);
104731
+ return { code, signal: DARWIN_SIGNALS[number4] ?? `signal ${number4}` };
104732
+ }
104733
+ var AxDaemonCrashError = class extends FailureError {
104734
+ signalName;
104735
+ constructor(message, signal, signalName) {
104736
+ super(message, signal);
104737
+ this.name = "AxDaemonCrashError";
104738
+ this.signalName = signalName;
104739
+ }
104740
+ };
104741
+ function findInCauses(err, pick2) {
104742
+ let current = err;
104743
+ for (let depth = 0; current instanceof Error && depth < 8; depth++) {
104744
+ const found = pick2(current);
104745
+ if (found !== void 0) return found;
104746
+ current = current.cause;
104747
+ }
104748
+ return void 0;
104749
+ }
104750
+ function axDaemonCrashSignal(err) {
104751
+ return findInCauses(
104752
+ err,
104753
+ (error63) => error63 instanceof AxDaemonCrashError ? error63.signalName : void 0
104754
+ );
104755
+ }
104756
+ var startFailureDegraded = /* @__PURE__ */ new WeakMap();
104757
+ function axStartFailureDegraded(err) {
104758
+ return findInCauses(err, (error63) => startFailureDegraded.get(error63));
104759
+ }
104760
+ function axDaemonExitError(exit, phase) {
104761
+ const suffix = phase === "connecting" ? " before connecting" : "";
104762
+ const signal = {
104763
+ error_code: phase === "connecting" ? FAILURE_CODES.AX_DAEMON_EXITED_BEFORE_READY : FAILURE_CODES.AX_DAEMON_PROCESS_ERROR,
104764
+ failure_stage: phase === "connecting" ? "ax_service_spawn_ready" : "ax_service_process_exit",
104765
+ failure_area: "tool_server",
104766
+ error_kind: "subprocess",
104767
+ ...subprocessFailureMetadata(exit, "ax_service")
104768
+ };
104769
+ if (exit.signal === void 0) {
104770
+ return new FailureError(`ax-service exited with code ${exit.code}${suffix}`, signal);
104771
+ }
104772
+ if (!FAULT_SIGNALS.has(exit.signal)) {
104773
+ return new FailureError(`ax-service was killed by ${exit.signal}${suffix}`, signal);
104774
+ }
104775
+ return new AxDaemonCrashError(
104776
+ `ax-service crashed with ${exit.signal}${suffix}`,
104777
+ { ...signal, error_code: FAILURE_CODES.AX_DAEMON_CRASHED },
104778
+ exit.signal
104779
+ );
104780
+ }
104781
+ function watchDaemonExit(proc, onExit) {
104782
+ return new Promise((resolve19) => {
104783
+ let stderrTail = "";
104784
+ proc.stderr?.on("data", (chunk) => {
104785
+ stderrTail = (stderrTail + chunk.toString()).slice(-STDERR_TAIL_CHARS);
104786
+ });
104787
+ proc.once("exit", (code, signal) => {
104788
+ onExit();
104789
+ const settle3 = () => resolve19(readAxDaemonExit(code, signal, stderrTail));
104790
+ const stderr = proc.stderr;
104791
+ if (signal || !stderr || stderr.readableEnded) return settle3();
104792
+ const timer = setTimeout(settle3, STDERR_DRAIN_MS);
104793
+ stderr.once("end", () => {
104794
+ clearTimeout(timer);
104795
+ settle3();
104796
+ });
104797
+ });
104798
+ });
104799
+ }
104800
+ function waitForDaemonConnection(server, proc, exited, timeoutMs) {
104699
104801
  return new Promise((resolve19, reject) => {
104700
104802
  let settled = false;
104701
104803
  const onConnection = (socket) => {
@@ -104704,19 +104806,12 @@ function waitForDaemonConnection(server, proc, timeoutMs) {
104704
104806
  cleanup();
104705
104807
  resolve19(socket);
104706
104808
  };
104707
- const onExit = (code) => {
104809
+ void exited.then((exit) => {
104708
104810
  if (settled) return;
104709
104811
  settled = true;
104710
104812
  cleanup();
104711
- reject(
104712
- new FailureError(`ax-service exited with code ${code} before connecting`, {
104713
- error_code: FAILURE_CODES.AX_DAEMON_EXITED_BEFORE_READY,
104714
- failure_stage: "ax_service_spawn_ready",
104715
- failure_area: "tool_server",
104716
- error_kind: "subprocess"
104717
- })
104718
- );
104719
- };
104813
+ reject(axDaemonExitError(exit, "connecting"));
104814
+ });
104720
104815
  const onError = (err) => {
104721
104816
  if (settled) return;
104722
104817
  settled = true;
@@ -104750,11 +104845,9 @@ function waitForDaemonConnection(server, proc, timeoutMs) {
104750
104845
  const cleanup = () => {
104751
104846
  clearTimeout(timer);
104752
104847
  server.off("connection", onConnection);
104753
- proc.off("exit", onExit);
104754
104848
  proc.off("error", onError);
104755
104849
  };
104756
104850
  server.on("connection", onConnection);
104757
- proc.on("exit", onExit);
104758
104851
  proc.on("error", onError);
104759
104852
  });
104760
104853
  }
@@ -104809,6 +104902,10 @@ var axServiceBlueprint = {
104809
104902
  let nextRpcId = 1;
104810
104903
  let daemonSocket = null;
104811
104904
  let disposed = false;
104905
+ let exitSeen = false;
104906
+ let awaitingVerdict = false;
104907
+ let disconnectTimer;
104908
+ const exitGraceMs = host.kind === "local" ? DAEMON_EXIT_GRACE_MS : 0;
104812
104909
  const failPending = (err) => {
104813
104910
  for (const { reject, timer } of pendingRpc.values()) {
104814
104911
  clearTimeout(timer);
@@ -104816,7 +104913,18 @@ var axServiceBlueprint = {
104816
104913
  }
104817
104914
  pendingRpc.clear();
104818
104915
  };
104916
+ const terminate = (err) => {
104917
+ if (disposed) return;
104918
+ clearTimeout(disconnectTimer);
104919
+ awaitingVerdict = false;
104920
+ failPending(err);
104921
+ events.emit("terminated", err);
104922
+ };
104819
104923
  const { entitlementBypassActive } = await host.bootstrapAx(udid);
104924
+ const startFailed = (err) => {
104925
+ if (err instanceof Error) startFailureDegraded.set(err, !entitlementBypassActive);
104926
+ return err;
104927
+ };
104820
104928
  const server = await startListener(endpoint, (socket) => {
104821
104929
  if (daemonSocket && !daemonSocket.destroyed) {
104822
104930
  daemonSocket.destroy();
@@ -104849,57 +104957,29 @@ var axServiceBlueprint = {
104849
104957
  }
104850
104958
  });
104851
104959
  socket.on("close", () => {
104852
- if (daemonSocket === socket) {
104853
- daemonSocket = null;
104854
- if (!disposed) {
104855
- const err = new FailureError("ax-service daemon disconnected", {
104856
- error_code: FAILURE_CODES.AX_DAEMON_PROCESS_ERROR,
104857
- failure_stage: "ax_service_socket_close",
104858
- failure_area: "tool_server",
104859
- error_kind: "subprocess"
104860
- });
104861
- failPending(err);
104862
- events.emit("terminated", err);
104863
- }
104864
- }
104960
+ if (daemonSocket !== socket) return;
104961
+ daemonSocket = null;
104962
+ if (disposed) return;
104963
+ awaitingVerdict = true;
104964
+ if (exitSeen) return;
104965
+ const disconnected = () => terminate(
104966
+ new FailureError("ax-service daemon disconnected", {
104967
+ error_code: FAILURE_CODES.AX_DAEMON_PROCESS_ERROR,
104968
+ failure_stage: "ax_service_socket_close",
104969
+ failure_area: "tool_server",
104970
+ error_kind: "subprocess"
104971
+ })
104972
+ );
104973
+ if (exitGraceMs === 0) disconnected();
104974
+ else disconnectTimer = setTimeout(disconnected, exitGraceMs);
104865
104975
  });
104866
104976
  socket.on("error", () => {
104867
104977
  });
104978
+ }).catch((err) => {
104979
+ throw startFailed(err);
104868
104980
  });
104869
- if (endpoint.transport === "tcp") {
104870
- await host.startProxy(udid, endpoint.port);
104871
- }
104872
- const proc = host.spawnAxDaemon(udid, endpoint);
104873
- proc.on("exit", (code) => {
104874
- if (disposed) return;
104875
- const err = new FailureError(`ax-service exited with code ${code}`, {
104876
- error_code: FAILURE_CODES.AX_DAEMON_PROCESS_ERROR,
104877
- failure_stage: "ax_service_process_exit",
104878
- failure_area: "tool_server",
104879
- error_kind: "subprocess"
104880
- });
104881
- failPending(err);
104882
- events.emit("terminated", err);
104883
- });
104884
- proc.on("error", (err) => {
104885
- if (disposed) return;
104886
- const error63 = new FailureError(
104887
- err instanceof Error ? err.message : String(err),
104888
- {
104889
- error_code: FAILURE_CODES.AX_DAEMON_PROCESS_ERROR,
104890
- failure_stage: "ax_service_spawn_process",
104891
- failure_area: "tool_server",
104892
- error_kind: "subprocess"
104893
- },
104894
- { cause: err instanceof Error ? err : new Error(String(err)) }
104895
- );
104896
- failPending(error63);
104897
- events.emit("terminated", error63);
104898
- });
104899
- try {
104900
- daemonSocket = await waitForDaemonConnection(server, proc, 1e4);
104901
- } catch (err) {
104902
- if (!proc.killed) proc.kill("SIGTERM");
104981
+ let proxyStarted = false;
104982
+ const abandonStart = async () => {
104903
104983
  server.close();
104904
104984
  if (endpoint.transport === "unix") {
104905
104985
  try {
@@ -104907,14 +104987,51 @@ var axServiceBlueprint = {
104907
104987
  } catch {
104908
104988
  }
104909
104989
  }
104910
- if (endpoint.transport === "tcp") {
104990
+ if (endpoint.transport === "tcp" && proxyStarted) {
104911
104991
  await host.stopProxy(udid, endpoint.port);
104912
104992
  }
104913
- throw err;
104993
+ };
104994
+ let proc;
104995
+ try {
104996
+ if (endpoint.transport === "tcp") {
104997
+ await host.startProxy(udid, endpoint.port);
104998
+ proxyStarted = true;
104999
+ }
105000
+ proc = host.spawnAxDaemon(udid, endpoint);
105001
+ } catch (err) {
105002
+ await abandonStart();
105003
+ throw startFailed(err);
105004
+ }
105005
+ const exited = watchDaemonExit(proc, () => {
105006
+ exitSeen = true;
105007
+ clearTimeout(disconnectTimer);
105008
+ });
105009
+ proc.on("error", (err) => {
105010
+ terminate(
105011
+ new FailureError(
105012
+ err instanceof Error ? err.message : String(err),
105013
+ {
105014
+ error_code: FAILURE_CODES.AX_DAEMON_PROCESS_ERROR,
105015
+ failure_stage: "ax_service_spawn_process",
105016
+ failure_area: "tool_server",
105017
+ error_kind: "subprocess"
105018
+ },
105019
+ { cause: err instanceof Error ? err : new Error(String(err)) }
105020
+ )
105021
+ );
105022
+ });
105023
+ try {
105024
+ daemonSocket = await waitForDaemonConnection(server, proc, exited, 1e4);
105025
+ } catch (err) {
105026
+ if (!proc.killed) proc.kill("SIGTERM");
105027
+ await abandonStart();
105028
+ throw startFailed(err);
104914
105029
  }
105030
+ void exited.then((exit) => terminate(axDaemonExitError(exit, "connected")));
104915
105031
  function query(command, timeoutMs = 5e3, params) {
104916
105032
  return new Promise((resolve19, reject) => {
104917
- if (!daemonSocket || daemonSocket.destroyed) {
105033
+ const socket = daemonSocket && !daemonSocket.destroyed ? daemonSocket : null;
105034
+ if (!socket && !awaitingVerdict) {
104918
105035
  reject(
104919
105036
  new FailureError("ax-service not connected", {
104920
105037
  error_code: FAILURE_CODES.AX_QUERY_FAILED,
@@ -104940,7 +105057,7 @@ var axServiceBlueprint = {
104940
105057
  }
104941
105058
  }, timeoutMs);
104942
105059
  pendingRpc.set(id, { resolve: resolve19, reject, timer });
104943
- daemonSocket.write(
105060
+ socket?.write(
104944
105061
  JSON.stringify(params === void 0 ? { id, command } : { id, command, params }) + "\n"
104945
105062
  );
104946
105063
  });
@@ -105058,6 +105175,8 @@ var axServiceBlueprint = {
105058
105175
  api,
105059
105176
  dispose: async () => {
105060
105177
  disposed = true;
105178
+ clearTimeout(disconnectTimer);
105179
+ awaitingVerdict = false;
105061
105180
  failPending(new Error("ax-service disposed"));
105062
105181
  if (daemonSocket && !daemonSocket.destroyed) {
105063
105182
  daemonSocket.destroy();
@@ -123212,6 +123331,9 @@ function registerCaptureOnDemandSender(deviceId, endpoint, send) {
123212
123331
  if (entry.onDemand) entry.send(false);
123213
123332
  };
123214
123333
  }
123334
+ function simulatorServerDeviceIds() {
123335
+ return [...servers.keys()];
123336
+ }
123215
123337
  function captureOnDemandDropped(deviceId, endpoint) {
123216
123338
  const server = servers.get(deviceId);
123217
123339
  if (server?.endpoint === endpoint) server.onDemand = false;
@@ -124677,8 +124799,8 @@ async function getBootedUdidsInSet(deviceSet, signal) {
124677
124799
  });
124678
124800
  const data = JSON.parse(stdout);
124679
124801
  const udids = /* @__PURE__ */ new Set();
124680
- for (const devices of Object.values(data.devices)) {
124681
- for (const device of devices) {
124802
+ for (const devices2 of Object.values(data.devices)) {
124803
+ for (const device of devices2) {
124682
124804
  if (device.state === "Booted") {
124683
124805
  udids.add(device.udid);
124684
124806
  rememberDeviceSet(device.udid, deviceSet);
@@ -124859,7 +124981,7 @@ var getPaths = () => {
124859
124981
  return { BINARY_PATH, RUN_DIR };
124860
124982
  };
124861
124983
  var READY_TIMEOUT_MS = 3e4;
124862
- var STDERR_DRAIN_MS = 250;
124984
+ var STDERR_DRAIN_MS2 = 250;
124863
124985
  var STDERR_TAIL_LINES = 10;
124864
124986
  var STDERR_MAX_LINE_CHARS = 500;
124865
124987
  var ROUTINE_LOG_LINE = /^\[\S+\s+(?:INFO|DEBUG|TRACE)\s/;
@@ -125055,7 +125177,7 @@ async function spawnSimulatorServerProcess(udid, subcommand) {
125055
125177
  };
125056
125178
  const stderr = proc.stderr;
125057
125179
  if (settled || !stderr || stderr.readableEnded) return fail();
125058
- const drainTimer = setTimeout(fail, STDERR_DRAIN_MS);
125180
+ const drainTimer = setTimeout(fail, STDERR_DRAIN_MS2);
125059
125181
  stderr.once("end", () => {
125060
125182
  clearTimeout(drainTimer);
125061
125183
  fail();
@@ -125778,9 +125900,9 @@ async function listIosPhysicalDevices() {
125778
125900
  return [];
125779
125901
  }
125780
125902
  const payload = json2;
125781
- const devices = payload?.result?.devices ?? [];
125903
+ const devices2 = payload?.result?.devices ?? [];
125782
125904
  const out = [];
125783
- for (const d of devices) {
125905
+ for (const d of devices2) {
125784
125906
  const hardwareProperties = d.hardwareProperties ?? {};
125785
125907
  const udid = hardwareProperties.udid ?? d.identifier;
125786
125908
  if (!udid) {
@@ -128412,7 +128534,7 @@ async function listVvdImages() {
128412
128534
  var VEGA_DISCOVERY_LIST_TIMEOUT_MS = 6e3;
128413
128535
  var VEGA_DISCOVERY_INFO_TIMEOUT_MS = 4e3;
128414
128536
  function parseVegaDeviceList(stdout) {
128415
- const devices = [];
128537
+ const devices2 = [];
128416
128538
  for (const raw of stdout.split("\n")) {
128417
128539
  const line = raw.trim();
128418
128540
  const sep11 = line.indexOf(" : ");
@@ -128423,12 +128545,12 @@ function parseVegaDeviceList(stdout) {
128423
128545
  const parts2 = rhs.split(/\s+-\s+/);
128424
128546
  const serial = parts2[parts2.length - 1]?.trim();
128425
128547
  if (!serial) continue;
128426
- devices.push({ serial, type });
128548
+ devices2.push({ serial, type });
128427
128549
  }
128428
- return devices;
128550
+ return devices2;
128429
128551
  }
128430
- function filterVvdShadowsFromAndroid(androidDevices, vvdAdbSerials) {
128431
- return androidDevices.filter((d) => !vvdAdbSerials.has(d.serial));
128552
+ function filterVvdShadowsFromAndroid(androidDevices2, vvdAdbSerials) {
128553
+ return androidDevices2.filter((d) => !vvdAdbSerials.has(d.serial));
128432
128554
  }
128433
128555
  async function readVegaInfo() {
128434
128556
  try {
@@ -128563,10 +128685,10 @@ async function listRemoteIosSimulators() {
128563
128685
  try {
128564
128686
  const result = await simctlListDevices();
128565
128687
  const out = [];
128566
- for (const [runtime, devices] of Object.entries(result.devices)) {
128688
+ for (const [runtime, devices2] of Object.entries(result.devices)) {
128567
128689
  const runtimeKind = simulatorRuntimeKind(runtime);
128568
128690
  if (!runtimeKind) continue;
128569
- for (const d of devices) {
128691
+ for (const d of devices2) {
128570
128692
  if (d.isAvailable === false) continue;
128571
128693
  out.push({
128572
128694
  platform: "ios-remote",
@@ -128603,12 +128725,12 @@ function sortIosRemote(a, b) {
128603
128725
  const bBooted = b.state === "Booted" ? 0 : 1;
128604
128726
  return aBooted - bBooted;
128605
128727
  }
128606
- async function resolveVvdShadowAdbSerials(androidDevices, vega) {
128728
+ async function resolveVvdShadowAdbSerials(androidDevices2, vega) {
128607
128729
  if (!vega.some((d) => d.kind === "vvd" && d.state === "running")) return /* @__PURE__ */ new Set();
128608
128730
  const vvdPorts = await listRunningVvdConsolePorts();
128609
128731
  if (vvdPorts.size === 0) return /* @__PURE__ */ new Set();
128610
128732
  const shadows = /* @__PURE__ */ new Set();
128611
- for (const d of androidDevices) {
128733
+ for (const d of androidDevices2) {
128612
128734
  const port = consolePortFromAdbSerial(d.serial);
128613
128735
  if (port !== null && vvdPorts.has(port)) shadows.add(d.serial);
128614
128736
  }
@@ -128810,7 +128932,7 @@ Chromium apps are discovered by probing CDP debugging ports (default 9222; exten
128810
128932
  osVersion: h.osVersion
128811
128933
  }))
128812
128934
  ];
128813
- const devices = [
128935
+ const devices2 = [
128814
128936
  ...iosTagged,
128815
128937
  ...iosPhysicalTagged,
128816
128938
  ...iosRemote,
@@ -128821,7 +128943,7 @@ Chromium apps are discovered by probing CDP debugging ports (default 9222; exten
128821
128943
  ...harmonyTagged,
128822
128944
  ...external.map(toListedExternal)
128823
128945
  ];
128824
- devices.sort((a, b) => readinessRank(a) - readinessRank(b));
128946
+ devices2.sort((a, b) => readinessRank(a) - readinessRank(b));
128825
128947
  const avdsTagged = avds.map(
128826
128948
  (a) => foldableAvds.has(a.name) ? { ...a, foldable: true } : a
128827
128949
  );
@@ -128833,7 +128955,7 @@ Chromium apps are discovered by probing CDP debugging ports (default 9222; exten
128833
128955
  ...adbPrefix ? [adbServerHint(adbPrefix)] : []
128834
128956
  ];
128835
128957
  return {
128836
- devices,
128958
+ devices: devices2,
128837
128959
  avds: avdsTagged,
128838
128960
  ...hints.length > 0 ? { hint: hints.join("\n\n") } : {}
128839
128961
  };
@@ -129596,7 +129718,8 @@ var DEGRADED_STANDING_HINT = "This simulator was not booted through argent, so s
129596
129718
  function externalCaveat(deviceId, body) {
129597
129719
  return `${externalSupportHint(deviceId) ?? "This device is supplied by an external provider."} ${body}`;
129598
129720
  }
129599
- var EXTERNAL_BLIND_BODY = "The accessibility read returned no elements, and argent cannot reboot this device to apply the pre-boot accessibility settings. Restart it from that application, or take a screenshot to see the screen.";
129721
+ var EXTERNAL_BLIND_TAIL = ", and argent cannot reboot this device to apply the pre-boot accessibility settings. Restart it from that application, or take a screenshot to see the screen.";
129722
+ var EXTERNAL_BLIND_BODY = `The accessibility read returned no elements${EXTERNAL_BLIND_TAIL}`;
129600
129723
  var EXTERNAL_STANDING_BODY = "System dialogs and native modals may not appear in this tree; everything else reads normally. Argent cannot reboot this device to apply the full accessibility settings \u2014 restart it from that application if something you expect is missing.";
129601
129724
  function isStandingCaveat(hint) {
129602
129725
  return hint === DEGRADED_STANDING_HINT || Boolean(hint?.endsWith(EXTERNAL_STANDING_BODY));
@@ -129604,10 +129727,21 @@ function isStandingCaveat(hint) {
129604
129727
  function isBlindCaveat(hint) {
129605
129728
  return hint === DEGRADED_BLIND_HINT || Boolean(hint?.endsWith(EXTERNAL_BLIND_BODY));
129606
129729
  }
129730
+ function startFailure(err) {
129731
+ return `The accessibility service failed to start (${errMsg(err)})`;
129732
+ }
129733
+ 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.";
129734
+ function axCrashHint(signal) {
129735
+ 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.`;
129736
+ }
129737
+ var NATIVE_FALLBACK_LEAD = "The native fallback has no tree for this read, for a reason of its own, unrelated to the crash:";
129607
129738
  var bootCaveatToldDevices = /* @__PURE__ */ new Set();
129739
+ var readFacts = /* @__PURE__ */ new WeakMap();
129608
129740
  function withBootCaveatOncePerDevice(deviceId, data) {
129609
129741
  if (!isStandingCaveat(data.hint)) {
129610
- if (!isBlindCaveat(data.hint)) bootCaveatToldDevices.delete(deviceId);
129742
+ const facts = readFacts.get(data);
129743
+ const stillDegraded = facts?.daemonGone ? facts.degraded !== false : isBlindCaveat(data.hint);
129744
+ if (!stillDegraded) bootCaveatToldDevices.delete(deviceId);
129611
129745
  return data;
129612
129746
  }
129613
129747
  if (!bootCaveatToldDevices.has(deviceId)) {
@@ -129636,6 +129770,12 @@ function lendsNativeDevtools(deviceId) {
129636
129770
  }
129637
129771
  var iosRequires = ["xcrun"];
129638
129772
  async function describeIos(registry2, device, params, options = {}) {
129773
+ const facts = {};
129774
+ const data = await readIos(registry2, device, params, options, facts);
129775
+ readFacts.set(data, facts);
129776
+ return data;
129777
+ }
129778
+ async function readIos(registry2, device, params, options, facts) {
129639
129779
  const isTvOs = options.isTvOs ?? await isTvOsSimulator(device.id);
129640
129780
  if (isTvOs) {
129641
129781
  return { tree: emptyTree(), source: "ax-service", hint: TVOS_HINT };
@@ -129644,38 +129784,59 @@ async function describeIos(registry2, device, params, options = {}) {
129644
129784
  let degraded;
129645
129785
  let resolverHint;
129646
129786
  let readFailureHint;
129787
+ let startFailureHint;
129788
+ let crashSignal;
129647
129789
  let axApi;
129648
129790
  try {
129649
129791
  const axRef = axServiceRef(device);
129650
129792
  axApi = await registry2.resolveService(axRef.urn, axRef.options);
129651
129793
  degraded = axApi.degraded;
129794
+ facts.degraded = degraded;
129652
129795
  } catch (err) {
129653
129796
  if (isFirstLaunchRefusal(err)) throw err;
129654
129797
  resolverHint = tcpArtifactHint(err);
129655
- degraded = resolverHint === void 0;
129798
+ crashSignal = axDaemonCrashSignal(err);
129799
+ facts.degraded = axStartFailureDegraded(err);
129800
+ const explained = resolverHint !== void 0 || crashSignal !== void 0;
129801
+ degraded = !explained && facts.degraded !== false;
129802
+ if (!explained) {
129803
+ facts.daemonGone = true;
129804
+ startFailureHint = !degraded ? `${startFailure(err)}.` : isExternalId(device.id) ? externalCaveat(device.id, `${startFailure(err)}${EXTERNAL_BLIND_TAIL}`) : `${startFailure(err)}${DEGRADED_START_FAILED_TAIL}`;
129805
+ }
129656
129806
  }
129657
129807
  if (axApi) {
129658
129808
  try {
129659
129809
  tree = adaptAXDescribeToDescribeResult(await axApi.describe());
129660
129810
  } catch (err) {
129661
- readFailureHint = `The accessibility read failed (${errMsg(err)}).`;
129811
+ crashSignal = axDaemonCrashSignal(err);
129812
+ if (crashSignal === void 0) {
129813
+ readFailureHint = `The accessibility read failed (${errMsg(err)}).`;
129814
+ }
129662
129815
  }
129663
129816
  }
129664
- const degradedHint = !degraded ? void 0 : tree.children.length === 0 ? DEGRADED_BLIND_HINT : DEGRADED_STANDING_HINT;
129817
+ const crashHint = crashSignal === void 0 ? void 0 : axCrashHint(crashSignal);
129818
+ if (crashHint !== void 0) facts.daemonGone = true;
129819
+ const degradedHint = !degraded || crashHint !== void 0 || startFailureHint !== void 0 ? void 0 : tree.children.length === 0 ? DEGRADED_BLIND_HINT : DEGRADED_STANDING_HINT;
129665
129820
  const deviceDegradedHint = degradedHint !== void 0 && isExternalId(device.id) ? externalCaveat(
129666
129821
  device.id,
129667
129822
  degradedHint === DEGRADED_BLIND_HINT ? EXTERNAL_BLIND_BODY : EXTERNAL_STANDING_BODY
129668
129823
  ) : degradedHint;
129669
- const hint = resolverHint ?? (readFailureHint ? deviceDegradedHint ? `${deviceDegradedHint}. ${readFailureHint}` : readFailureHint : deviceDegradedHint);
129824
+ const hint = resolverHint ?? crashHint ?? startFailureHint ?? (readFailureHint ? deviceDegradedHint ? `${deviceDegradedHint}. ${readFailureHint}` : readFailureHint : deviceDegradedHint);
129670
129825
  if (tree.children.length > 0) {
129671
129826
  return { tree, source: "ax-service", hint };
129672
129827
  }
129828
+ const daemonGoneHint = crashHint ?? (degraded ? void 0 : startFailureHint);
129673
129829
  if (params.bundleId && !isInjectableBundleId(params.bundleId)) {
129674
- return { tree, source: "ax-service", hint: hint ?? NON_INJECTABLE_HINT };
129830
+ return {
129831
+ tree,
129832
+ source: "ax-service",
129833
+ hint: daemonGoneHint ? `${daemonGoneHint} ${NON_INJECTABLE_HINT}` : hint ?? NON_INJECTABLE_HINT
129834
+ };
129675
129835
  }
129676
129836
  if (isExternalId(device.id) && !lendsNativeDevtools(device.id)) {
129837
+ const provider = externalSupportHint(device.id) ?? "This device is supplied by an external provider.";
129677
129838
  return {
129678
- hint: hint ?? `${externalSupportHint(device.id) ?? "This device is supplied by an external provider."} The native view-hierarchy fallback is unavailable on it, so an empty tree here means the accessibility tree itself was empty. Take a screenshot to see the screen.`,
129839
+ hint: daemonGoneHint ? `${daemonGoneHint} ${provider} The native view-hierarchy fallback is unavailable on it. Take a screenshot to see the screen.` : hint ?? `${provider} The native view-hierarchy fallback is unavailable on it, so an empty tree here means the accessibility tree itself was empty. Take a screenshot to see the screen.`,
129679
129840
  source: "ax-service",
129680
129841
  tree
129681
129842
  };
@@ -129695,7 +129856,7 @@ async function describeIos(registry2, device, params, options = {}) {
129695
129856
  });
129696
129857
  if (state3 !== "connected") {
129697
129858
  const diagnosis = buildAppStateMessage(target.bundleId, state3);
129698
- const merged = hint ? `${hint} ${diagnosis}` : diagnosis;
129859
+ const merged = crashHint ? `${crashHint} ${NATIVE_FALLBACK_LEAD} ${diagnosis}` : hint ? `${hint} ${diagnosis}` : diagnosis;
129699
129860
  return state3 === "unregistered" || state3 === "connecting" ? { tree, source: "ax-service", hint: merged } : { tree, source: "ax-service", should_restart: true, hint: merged };
129700
129861
  }
129701
129862
  const rawResult = await nativeApi.queryViewHierarchy(
@@ -131644,16 +131805,16 @@ function createPreviewRouter(registry2) {
131644
131805
  const KNOWN_DEVICES_TTL_MS = 5e3;
131645
131806
  let knownDevices = null;
131646
131807
  let knownDevicesInFlight = null;
131647
- function deviceIdSet(devices) {
131808
+ function deviceIdSet(devices2) {
131648
131809
  const ids = /* @__PURE__ */ new Set();
131649
- for (const d of devices) {
131810
+ for (const d of devices2) {
131650
131811
  const id = d.platform === "ios" ? d.udid : d.serial;
131651
131812
  if (typeof id === "string") ids.add(id);
131652
131813
  }
131653
131814
  return ids;
131654
131815
  }
131655
- function rememberDevices(devices) {
131656
- knownDevices = { ids: deviceIdSet(devices), at: Date.now() };
131816
+ function rememberDevices(devices2) {
131817
+ knownDevices = { ids: deviceIdSet(devices2), at: Date.now() };
131657
131818
  }
131658
131819
  async function knownDeviceIds() {
131659
131820
  if (knownDevices && Date.now() - knownDevices.at < KNOWN_DEVICES_TTL_MS) {
@@ -133562,6 +133723,159 @@ async function resolveTvApi(registry2, udid) {
133562
133723
  init_adb();
133563
133724
  init_capability();
133564
133725
 
133726
+ // ../tool-server/src/utils/secrets.ts
133727
+ init_src2();
133728
+ init_capability();
133729
+ init_src();
133730
+ var SECRET_PLACEHOLDER_MARKER = "{{secret:";
133731
+ function resolveSecretPlaceholders(text, options = {}) {
133732
+ const secrets = [];
133733
+ let sources;
133734
+ const resolved = text.replace(SECRET_PLACEHOLDER_RE, (_placeholder, rawName) => {
133735
+ sources ??= [
133736
+ ...options.clientSecrets ? [clientSecretSource(options.clientSecrets)] : [],
133737
+ ...secretSources(options)
133738
+ ];
133739
+ const { name, value } = lookupPlaceholderSecret(rawName, sources);
133740
+ if (value === void 0) {
133741
+ const names = secretNames(sources);
133742
+ const where = options.clientSecrets ? `the required secret ${name} was not provided: the argent client forwards its secrets to this tool-server and has no value for it, and no source on the machine running the tool-server defines it either` : `no source on the machine running the tool-server defines ${name}`;
133743
+ throw new InvalidToolInputError(
133744
+ `Unknown secret "${rawName}" \u2014 ${where}. Available secrets: ${names.length ? names.join(", ") : "(none)"}.
133745
+ Sources consulted, first match wins:
133746
+ ${describeSecretSources(sources)}
133747
+ ` + (options.clientSecrets ? clientSecretPlacementAdvice(name) : secretPlacementAdvice(name, options)),
133748
+ {
133749
+ error_code: FAILURE_CODES.SECRET_PLACEHOLDER_UNKNOWN,
133750
+ failure_stage: "secret_placeholder_resolution",
133751
+ error_kind: "validation"
133752
+ }
133753
+ );
133754
+ }
133755
+ if (!secrets.some((s) => s.name === name)) secrets.push({ name, value });
133756
+ return value;
133757
+ });
133758
+ return { text: resolved, secrets };
133759
+ }
133760
+ function scrubSecretValues(text, secrets) {
133761
+ return scrubSecretChunk(text, secrets, true).emit;
133762
+ }
133763
+ function scrubSecretChunk(text, secrets, final) {
133764
+ const ordered = orderedSecrets(secrets);
133765
+ if (ordered.length === 0) return { emit: text, held: 0 };
133766
+ const longestValue = ordered[0].value.length;
133767
+ const names = new Set(ordered.map((secret) => secret.name));
133768
+ const longestName = Math.max(...ordered.map((secret) => secret.name.length));
133769
+ let out = "";
133770
+ let copied = 0;
133771
+ let at = 0;
133772
+ while (at < text.length) {
133773
+ const marker = markerLengthAt(text, at, names, longestName);
133774
+ if (marker > 0 && !valueLeavesMarker(text, at, at + marker, ordered)) {
133775
+ at += marker;
133776
+ continue;
133777
+ }
133778
+ if (!final && text.length - at < longestValue && beginsAValue(text, at, ordered)) break;
133779
+ const hit = ordered.find((secret) => text.startsWith(secret.value, at));
133780
+ if (hit) {
133781
+ out += `${text.slice(copied, at)}${SECRET_PLACEHOLDER_MARKER}${hit.name}}}`;
133782
+ at += hit.value.length;
133783
+ copied = at;
133784
+ continue;
133785
+ }
133786
+ at += 1;
133787
+ }
133788
+ return {
133789
+ emit: copied === 0 ? text.slice(0, at) : out + text.slice(copied, at),
133790
+ held: text.length - at
133791
+ };
133792
+ }
133793
+ function valueLeavesMarker(text, from2, end, ordered) {
133794
+ for (let at = from2; at < end; at++) {
133795
+ for (const { value } of ordered) {
133796
+ if (at + value.length >= end && text.startsWith(value, at)) return true;
133797
+ }
133798
+ }
133799
+ return false;
133800
+ }
133801
+ function beginsAValue(text, at, ordered) {
133802
+ const rest = text.slice(at);
133803
+ return ordered.some(({ value }) => value.length > rest.length && value.startsWith(rest));
133804
+ }
133805
+ function orderedSecrets(secrets) {
133806
+ return secrets.filter(({ value }) => value.length > 0).sort((a, b) => b.value.length - a.value.length);
133807
+ }
133808
+ function markerLengthAt(text, at, names, longestName) {
133809
+ if (!text.startsWith(SECRET_PLACEHOLDER_MARKER, at)) return 0;
133810
+ const from2 = at + SECRET_PLACEHOLDER_MARKER.length;
133811
+ const window2 = text.slice(from2, from2 + longestName + 2);
133812
+ const end = window2.indexOf("}}");
133813
+ return end >= 0 && names.has(window2.slice(0, end)) ? SECRET_PLACEHOLDER_MARKER.length + end + 2 : 0;
133814
+ }
133815
+ function redactSecretsFromError(err, secrets) {
133816
+ const forms = secrets.flatMap((secret) => {
133817
+ const quoted = secret.value.replaceAll("'", "'\\''");
133818
+ return quoted === secret.value ? [secret] : [secret, { name: secret.name, value: quoted }];
133819
+ });
133820
+ const scrub = (s) => scrubSecretValues(s, forms);
133821
+ if (err instanceof Error) {
133822
+ err.message = scrub(err.message);
133823
+ if (err.stack) err.stack = scrub(err.stack);
133824
+ return err;
133825
+ }
133826
+ if (typeof err === "string") return scrub(err);
133827
+ return err;
133828
+ }
133829
+
133830
+ // ../tool-server/src/utils/typed-secrets.ts
133831
+ var MAX_VALUES = 256;
133832
+ var devices = /* @__PURE__ */ new Map();
133833
+ function deviceKey(deviceId) {
133834
+ return deviceId.toLowerCase();
133835
+ }
133836
+ function noteTypedSecrets(deviceId, secrets) {
133837
+ if (secrets.length === 0) return;
133838
+ const key2 = deviceKey(deviceId);
133839
+ const values = devices.get(key2) ?? /* @__PURE__ */ new Map();
133840
+ devices.set(key2, values);
133841
+ for (const { name, value } of secrets) {
133842
+ if (value.length === 0) continue;
133843
+ values.delete(value);
133844
+ values.set(value, `${SECRET_PLACEHOLDER_MARKER}${name}}}`);
133845
+ if (values.size > MAX_VALUES) values.delete(values.keys().next().value);
133846
+ }
133847
+ }
133848
+ function secretTypedOn(deviceId) {
133849
+ return devices.has(deviceKey(deviceId));
133850
+ }
133851
+ var WITHHELD_INPUT_TEXT = "[text withheld: a secret was typed on this device]";
133852
+ function redactTypedSecrets(deviceId, text) {
133853
+ const values = devices.get(deviceKey(deviceId));
133854
+ if (!values || values.size === 0) return text;
133855
+ const longestFirst = [...values].sort((a, b) => b[0].length - a[0].length);
133856
+ let out = "";
133857
+ for (let at = 0; at < text.length; ) {
133858
+ const hit = longestFirst.find(([value]) => text.startsWith(value, at));
133859
+ out += hit ? hit[1] : text[at];
133860
+ at += hit ? hit[0].length : 1;
133861
+ }
133862
+ return out;
133863
+ }
133864
+ function twinOf(tree, quotable, node2) {
133865
+ if (tree === node2) return quotable;
133866
+ for (let i = 0; i < tree.children.length; i++) {
133867
+ const twin = quotable.children[i];
133868
+ const found = twin && twinOf(tree.children[i], twin, node2);
133869
+ if (found) return found;
133870
+ }
133871
+ return void 0;
133872
+ }
133873
+ function quotedText(data, deviceId, node2, read) {
133874
+ if (!data.quotableTree) return redactTypedSecrets(deviceId, read(node2));
133875
+ const twin = twinOf(data.tree, data.quotableTree, node2);
133876
+ return twin ? read(twin) : WITHHELD_INPUT_TEXT;
133877
+ }
133878
+
133565
133879
  // ../tool-server/src/utils/poll-describe-tree.ts
133566
133880
  init_src2();
133567
133881
  async function pollDescribeTree(args) {
@@ -142799,7 +143113,8 @@ function includesWordsCI(haystack, needle) {
142799
143113
  function flattenHoisting(node2, project, out, scrollClip = null) {
142800
143114
  const view = project(node2);
142801
143115
  if (view.skip) return "";
142802
- if (scrollClip && view.rect && rectFullyOutside(view.rect, scrollClip)) return "";
143116
+ if (scrollClip && view.rect && view.rect.w > 0 && view.rect.h > 0 && rectFullyOutside(view.rect, scrollClip))
143117
+ return "";
142803
143118
  const childClip = view.scrolls && view.rect ? intersectClip(view.rect, scrollClip) : scrollClip;
142804
143119
  const childText = [];
142805
143120
  for (const child of view.children) {
@@ -142807,7 +143122,11 @@ function flattenHoisting(node2, project, out, scrollClip = null) {
142807
143122
  if (t) childText.push(t);
142808
143123
  }
142809
143124
  const descendantText2 = childText.join(" ");
142810
- const subtree = view.ownText && !includesWordsCI(descendantText2, view.ownText) ? [view.ownText, descendantText2].filter(Boolean).join(" ") : descendantText2 || view.ownText;
143125
+ const ownParts = view.ownTextParts ?? [view.ownText];
143126
+ const subtree = [
143127
+ ...ownParts.filter((part) => part && !includesWordsCI(descendantText2, part)),
143128
+ descendantText2
143129
+ ].filter(Boolean).join(" ");
142811
143130
  if (view.leaf) {
142812
143131
  if (subtree && subtree !== view.ownText) view.leaf.subtreeText = subtree;
142813
143132
  out.push(view.leaf);
@@ -143392,7 +143711,8 @@ function timeoutNote(params, lastTree, fetchError, lastData) {
143392
143711
  case "text": {
143393
143712
  const first = textCheckTarget(matches2, void 0, isMacos(params));
143394
143713
  const wanted = params.textMatch === "equals" ? "equal" : "contain";
143395
- base = first ? `element matched but its text was "${macFieldText(first, isMacos(params)) ?? assertText(first)}" (wanted to ${wanted} "${params.expectedText}")` : "no element matched the selector before timeout";
143714
+ const shown = first ? redactTypedSecrets(params.udid, macFieldText(first, isMacos(params)) ?? assertText(first)) : void 0;
143715
+ base = shown !== void 0 ? `element matched but its text was "${shown}" (wanted to ${wanted} "${params.expectedText}")` : "no element matched the selector before timeout";
143396
143716
  break;
143397
143717
  }
143398
143718
  case "hidden":
@@ -145449,8 +145769,14 @@ function findAndroidNativeRecord(id) {
145449
145769
  function liveAndroidNetworkCaptures(deviceId) {
145450
145770
  return [...liveInspectors.get(deviceKeyOf(deviceId)) ?? []].filter((handle) => handle.isLive()).map((handle) => handle.packageName).sort();
145451
145771
  }
145772
+ function liveAndroidNetworkCaptureSerials() {
145773
+ return liveCaptureSerials(() => true);
145774
+ }
145452
145775
  function liveAndroidNetworkCaptureDevices(packageName) {
145453
- const serials = allHandles().filter((handle) => handle.packageName === packageName && handle.isLive()).map((handle) => handle.serial);
145776
+ return liveCaptureSerials((handle) => handle.packageName === packageName);
145777
+ }
145778
+ function liveCaptureSerials(matches2) {
145779
+ const serials = allHandles().filter((handle) => matches2(handle) && handle.isLive()).map((handle) => handle.serial);
145454
145780
  return [...new Set(serials)].sort();
145455
145781
  }
145456
145782
  async function attachAndroidNetworkInspectorToLaunch(deviceId, packageName) {
@@ -147621,7 +147947,7 @@ init_external_devices();
147621
147947
  var import_node_crypto13 = require("node:crypto");
147622
147948
  init_src2();
147623
147949
  init_device_info();
147624
- function deviceKey(target) {
147950
+ function deviceKey2(target) {
147625
147951
  const logicalId = target.reactNative?.logicalDeviceId;
147626
147952
  if (logicalId) return logicalId;
147627
147953
  try {
@@ -147650,13 +147976,13 @@ function describeDevice(target) {
147650
147976
  function macosAppTargets(pool, bundleId, port) {
147651
147977
  const own2 = pool.filter((t) => macosAppBundleIdOf(t)?.toLowerCase() === bundleId.toLowerCase());
147652
147978
  if (own2.length) return own2;
147653
- const devices = /* @__PURE__ */ new Map();
147979
+ const devices2 = /* @__PURE__ */ new Map();
147654
147980
  for (const t of pool) {
147655
- const key2 = deviceKey(t);
147656
- if (key2 && !devices.has(key2)) devices.set(key2, describeDevice(t));
147981
+ const key2 = deviceKey2(t);
147982
+ if (key2 && !devices2.has(key2)) devices2.set(key2, describeDevice(t));
147657
147983
  }
147658
147984
  throw new FailureError(
147659
- `No JS runtime of the Mac app ${bundleId} is connected to Metro on port ${port}. Metro lists: ${[...devices.values()].join(", ")}. If the app does not run, start it (launch-app), wait a few seconds for the bundle to load, then retry. Otherwise the app must be a Debug build of react-native-macos 0.76 or later that loads its bundle from this Metro; a Release build has no JS debugger. If the app uses another Metro, pass that port.`,
147985
+ `No JS runtime of the Mac app ${bundleId} is connected to Metro on port ${port}. Metro lists: ${[...devices2.values()].join(", ")}. If the app does not run, start it (launch-app), wait a few seconds for the bundle to load, then retry. Otherwise the app must be a Debug build of react-native-macos 0.76 or later that loads its bundle from this Metro; a Release build has no JS debugger. If the app uses another Metro, pass that port.`,
147660
147986
  {
147661
147987
  error_code: FAILURE_CODES.DEBUGGER_TARGET_DEVICE_MISMATCH,
147662
147988
  failure_stage: "debugger_select_target",
@@ -147684,7 +148010,7 @@ function selectTarget(targets, port, options) {
147684
148010
  } else {
147685
148011
  const distinctDevices = /* @__PURE__ */ new Map();
147686
148012
  for (const t of pool) {
147687
- const key2 = deviceKey(t);
148013
+ const key2 = deviceKey2(t);
147688
148014
  if (key2 && !distinctDevices.has(key2)) distinctDevices.set(key2, describeDevice(t));
147689
148015
  }
147690
148016
  if (distinctDevices.size > 1) {
@@ -150977,8 +151303,8 @@ async function awaitFirstRealFrame(serial, timeoutMs) {
150977
151303
  }
150978
151304
  async function findSerialByAvdName(avdName, deadline) {
150979
151305
  while (Date.now() < deadline) {
150980
- const devices = await listAndroidDevices().catch(() => []);
150981
- const match = devices.find((d) => d.isEmulator && d.avdName === avdName);
151306
+ const devices2 = await listAndroidDevices().catch(() => []);
151307
+ const match = devices2.find((d) => d.isEmulator && d.avdName === avdName);
150982
151308
  if (match) return match.serial;
150983
151309
  await new Promise((r) => setTimeout(r, BOOT_POLL_INTERVALS_MS.serialByAvd));
150984
151310
  }
@@ -151016,8 +151342,8 @@ async function awaitOwnEmulatorSettled(avdName, deadline) {
151016
151342
  while (Date.now() < deadline) {
151017
151343
  if (healthy) return healthy;
151018
151344
  if ((await listEmulatorPidsForAvd(avdName)).length === 0) return null;
151019
- listing ??= listAndroidDevices().then((devices) => {
151020
- if (devices.some((d) => isRunningAvd(d, avdName))) healthy = devices;
151345
+ listing ??= listAndroidDevices().then((devices2) => {
151346
+ if (devices2.some((d) => isRunningAvd(d, avdName))) healthy = devices2;
151021
151347
  }).catch(() => {
151022
151348
  }).finally(() => {
151023
151349
  listing = null;
@@ -151028,9 +151354,9 @@ async function awaitOwnEmulatorSettled(avdName, deadline) {
151028
151354
  }
151029
151355
  return healthy;
151030
151356
  }
151031
- async function dropUnreachableSerials(devices, serialsBefore) {
151357
+ async function dropUnreachableSerials(devices2, serialsBefore) {
151032
151358
  await Promise.all(
151033
- devices.filter((d) => d.isEmulator && !(d.state === "device" && d.avdName !== null)).map(async (d) => {
151359
+ devices2.filter((d) => d.isEmulator && !(d.state === "device" && d.avdName !== null)).map(async (d) => {
151034
151360
  if ((await readEmulatorConsoleAvdName(d.serial)).status === "unreachable") {
151035
151361
  serialsBefore.delete(d.serial);
151036
151362
  }
@@ -151188,8 +151514,8 @@ async function bootIosRemote(id, registry2, force) {
151188
151514
  let simState;
151189
151515
  try {
151190
151516
  const list = await simctlListDevices();
151191
- outer: for (const devices of Object.values(list.devices)) {
151192
- for (const d of devices) {
151517
+ outer: for (const devices2 of Object.values(list.devices)) {
151518
+ for (const d of devices2) {
151193
151519
  if (d.udid === udid) {
151194
151520
  simState = d.state;
151195
151521
  break outer;
@@ -156092,110 +156418,6 @@ init_zod();
156092
156418
  init_src2();
156093
156419
  init_capability();
156094
156420
 
156095
- // ../tool-server/src/utils/secrets.ts
156096
- init_src2();
156097
- init_capability();
156098
- init_src();
156099
- var SECRET_PLACEHOLDER_MARKER = "{{secret:";
156100
- function resolveSecretPlaceholders(text, options = {}) {
156101
- const secrets = [];
156102
- let sources;
156103
- const resolved = text.replace(SECRET_PLACEHOLDER_RE, (_placeholder, rawName) => {
156104
- sources ??= [
156105
- ...options.clientSecrets ? [clientSecretSource(options.clientSecrets)] : [],
156106
- ...secretSources(options)
156107
- ];
156108
- const { name, value } = lookupPlaceholderSecret(rawName, sources);
156109
- if (value === void 0) {
156110
- const names = secretNames(sources);
156111
- const where = options.clientSecrets ? `the required secret ${name} was not provided: the argent client forwards its secrets to this tool-server and has no value for it, and no source on the machine running the tool-server defines it either` : `no source on the machine running the tool-server defines ${name}`;
156112
- throw new InvalidToolInputError(
156113
- `Unknown secret "${rawName}" \u2014 ${where}. Available secrets: ${names.length ? names.join(", ") : "(none)"}.
156114
- Sources consulted, first match wins:
156115
- ${describeSecretSources(sources)}
156116
- ` + (options.clientSecrets ? clientSecretPlacementAdvice(name) : secretPlacementAdvice(name, options)),
156117
- {
156118
- error_code: FAILURE_CODES.SECRET_PLACEHOLDER_UNKNOWN,
156119
- failure_stage: "secret_placeholder_resolution",
156120
- error_kind: "validation"
156121
- }
156122
- );
156123
- }
156124
- if (!secrets.some((s) => s.name === name)) secrets.push({ name, value });
156125
- return value;
156126
- });
156127
- return { text: resolved, secrets };
156128
- }
156129
- function scrubSecretValues(text, secrets) {
156130
- return scrubSecretChunk(text, secrets, true).emit;
156131
- }
156132
- function scrubSecretChunk(text, secrets, final) {
156133
- const ordered = orderedSecrets(secrets);
156134
- if (ordered.length === 0) return { emit: text, held: 0 };
156135
- const longestValue = ordered[0].value.length;
156136
- const names = new Set(ordered.map((secret) => secret.name));
156137
- const longestName = Math.max(...ordered.map((secret) => secret.name.length));
156138
- let out = "";
156139
- let copied = 0;
156140
- let at = 0;
156141
- while (at < text.length) {
156142
- const marker = markerLengthAt(text, at, names, longestName);
156143
- if (marker > 0 && !valueLeavesMarker(text, at, at + marker, ordered)) {
156144
- at += marker;
156145
- continue;
156146
- }
156147
- if (!final && text.length - at < longestValue && beginsAValue(text, at, ordered)) break;
156148
- const hit = ordered.find((secret) => text.startsWith(secret.value, at));
156149
- if (hit) {
156150
- out += `${text.slice(copied, at)}${SECRET_PLACEHOLDER_MARKER}${hit.name}}}`;
156151
- at += hit.value.length;
156152
- copied = at;
156153
- continue;
156154
- }
156155
- at += 1;
156156
- }
156157
- return {
156158
- emit: copied === 0 ? text.slice(0, at) : out + text.slice(copied, at),
156159
- held: text.length - at
156160
- };
156161
- }
156162
- function valueLeavesMarker(text, from2, end, ordered) {
156163
- for (let at = from2; at < end; at++) {
156164
- for (const { value } of ordered) {
156165
- if (at + value.length >= end && text.startsWith(value, at)) return true;
156166
- }
156167
- }
156168
- return false;
156169
- }
156170
- function beginsAValue(text, at, ordered) {
156171
- const rest = text.slice(at);
156172
- return ordered.some(({ value }) => value.length > rest.length && value.startsWith(rest));
156173
- }
156174
- function orderedSecrets(secrets) {
156175
- return secrets.filter(({ value }) => value.length > 0).sort((a, b) => b.value.length - a.value.length);
156176
- }
156177
- function markerLengthAt(text, at, names, longestName) {
156178
- if (!text.startsWith(SECRET_PLACEHOLDER_MARKER, at)) return 0;
156179
- const from2 = at + SECRET_PLACEHOLDER_MARKER.length;
156180
- const window2 = text.slice(from2, from2 + longestName + 2);
156181
- const end = window2.indexOf("}}");
156182
- return end >= 0 && names.has(window2.slice(0, end)) ? SECRET_PLACEHOLDER_MARKER.length + end + 2 : 0;
156183
- }
156184
- function redactSecretsFromError(err, secrets) {
156185
- const forms = secrets.flatMap((secret) => {
156186
- const quoted = secret.value.replaceAll("'", "'\\''");
156187
- return quoted === secret.value ? [secret] : [secret, { name: secret.name, value: quoted }];
156188
- });
156189
- const scrub = (s) => scrubSecretValues(s, forms);
156190
- if (err instanceof Error) {
156191
- err.message = scrub(err.message);
156192
- if (err.stack) err.stack = scrub(err.stack);
156193
- return err;
156194
- }
156195
- if (typeof err === "string") return scrub(err);
156196
- return err;
156197
- }
156198
-
156199
156421
  // ../tool-server/src/tools/keyboard/simulator-server-keys.ts
156200
156422
  init_src2();
156201
156423
 
@@ -156939,6 +157161,7 @@ React Native: after typing, the next tap outside the field may only close the ke
156939
157161
  clientSecrets: options?.clientSecrets
156940
157162
  });
156941
157163
  if (secrets.length === 0) return dispatch(services, params, options);
157164
+ noteTypedSecrets(params.udid, secrets);
156942
157165
  try {
156943
157166
  const result = await dispatch(services, { ...params, text }, options);
156944
157167
  return { ...result, typed: params.text };
@@ -157131,6 +157354,7 @@ Tap the field first so it has focus. Returns { pasted: true }, plus via: "keyboa
157131
157354
  });
157132
157355
  return serializedPerDevice(params.udid, async () => {
157133
157356
  if (secrets.length === 0) return dispatch(services, params, options);
157357
+ noteTypedSecrets(params.udid, secrets);
157134
157358
  try {
157135
157359
  return await dispatch(services, { ...params, text, hasSecrets: true }, options);
157136
157360
  } catch (err) {
@@ -162080,6 +162304,7 @@ Fails with FILL_NO_FOCUSED_FIELD when nothing editable has focus, FILL_NOT_VERIF
162080
162304
  const { text, secrets } = resolveSecretPlaceholders(params.text, {
162081
162305
  clientSecrets: options?.clientSecrets
162082
162306
  });
162307
+ noteTypedSecrets(params.udid, secrets);
162083
162308
  try {
162084
162309
  return await dispatch(services, { udid: params.udid, text }, options);
162085
162310
  } catch (err) {
@@ -162259,7 +162484,12 @@ init_adb();
162259
162484
  var execFileAsync35 = (0, import_node_util35.promisify)(import_node_child_process46.execFile);
162260
162485
  var LOG_READ_TIMEOUT_MS = 5e3;
162261
162486
  var RETRY_DELAY_MS = 300;
162262
- async function findRuntimeDevice(cdp) {
162487
+ var OTHER_TRANSPORTS_GRACE_MS = 500;
162488
+ var NOT_FOUND = { found: [], unresolved: [] };
162489
+ async function findRuntimeDevices(cdp, {
162490
+ awaitSerials = [],
162491
+ waitSerials = []
162492
+ } = {}) {
162263
162493
  const marker = `argent-device-probe:${(0, import_node_crypto15.randomUUID)()}`;
162264
162494
  const logged = await cdp.evaluate(
162265
162495
  `(function () {
@@ -162268,30 +162498,88 @@ async function findRuntimeDevice(cdp) {
162268
162498
  return true;
162269
162499
  })()`
162270
162500
  ).catch(() => false);
162271
- if (logged !== true) return void 0;
162501
+ if (logged !== true) return NOT_FOUND;
162272
162502
  const checks = [
162273
- async () => firstFound((await androidSerials()).map((serial) => () => logcatHolds(serial, marker))),
162274
- async () => firstFound((await bootedSimulators()).map((udid) => () => simulatorLogHolds(udid, marker)))
162503
+ async () => androidDevices(await androidSerials(), marker, awaitSerials, waitSerials),
162504
+ async () => {
162505
+ const udids = await bootedSimulators();
162506
+ const udid = await firstFound(udids.map((udid2) => () => simulatorLogHolds(udid2, marker)));
162507
+ return udid === void 0 ? void 0 : { found: [udid], unresolved: [] };
162508
+ }
162275
162509
  ];
162276
162510
  for (let attempt = 0; attempt < 2; attempt++) {
162277
162511
  if (attempt > 0) await new Promise((r) => setTimeout(r, RETRY_DELAY_MS));
162278
162512
  const found = await firstFound(checks);
162279
162513
  if (found !== void 0) return found;
162280
162514
  }
162281
- return void 0;
162515
+ return NOT_FOUND;
162282
162516
  }
162283
162517
  function firstFound(checks) {
162284
162518
  return new Promise((resolve19) => {
162285
162519
  let left = checks.length;
162286
162520
  if (left === 0) resolve19(void 0);
162287
162521
  for (const check3 of checks) {
162288
- void check3().then((id) => {
162289
- if (id !== void 0) resolve19(id);
162522
+ void check3().then((value) => {
162523
+ if (value !== void 0) resolve19(value);
162290
162524
  else if (--left === 0) resolve19(void 0);
162291
162525
  });
162292
162526
  }
162293
162527
  });
162294
162528
  }
162529
+ async function androidDevices(serials, marker, awaitSerials, waitSerials) {
162530
+ const listed = [...new Set(serials)];
162531
+ const awaited = listed.filter(
162532
+ (serial) => awaitSerials.includes(serial) || waitSerials.includes(serial)
162533
+ );
162534
+ const answers = /* @__PURE__ */ new Map();
162535
+ await new Promise((resolve19) => {
162536
+ let graceOver = false;
162537
+ let grace;
162538
+ const settle3 = () => {
162539
+ const held = heldSerials(answers);
162540
+ const waitingOn = listed.filter(
162541
+ (serial) => !answers.has(serial) && (!graceOver || awaited.includes(serial)) && !held.some((found2) => anotherDevice(serial, found2))
162542
+ );
162543
+ if (waitingOn.length === 0) {
162544
+ clearTimeout(grace);
162545
+ resolve19();
162546
+ }
162547
+ };
162548
+ settle3();
162549
+ for (const serial of listed) {
162550
+ void logcatHolds(serial, marker).then((read) => {
162551
+ answers.set(serial, read);
162552
+ if (read === "held") {
162553
+ grace ??= setTimeout(() => {
162554
+ graceOver = true;
162555
+ settle3();
162556
+ }, OTHER_TRANSPORTS_GRACE_MS);
162557
+ }
162558
+ settle3();
162559
+ });
162560
+ }
162561
+ });
162562
+ const found = heldSerials(answers);
162563
+ if (found.length === 0) return void 0;
162564
+ const unresolved = [...new Set(awaitSerials)].filter(
162565
+ (serial) => (!listed.includes(serial) || answers.get(serial) === "failed") && !found.some((device) => anotherDevice(serial, device))
162566
+ );
162567
+ return { found, unresolved };
162568
+ }
162569
+ function heldSerials(answers) {
162570
+ return [...answers].filter(([, read]) => read === "held").map(([serial]) => serial);
162571
+ }
162572
+ function anotherDevice(a, b) {
162573
+ if (a === b) return false;
162574
+ const portA = consolePortFromAdbSerial(a);
162575
+ const portB = consolePortFromAdbSerial(b);
162576
+ if (portA !== null && portB !== null) return portA !== portB;
162577
+ if (isUsbSerial(a) && isUsbSerial(b)) return true;
162578
+ return portA !== null && isUsbSerial(b) || portB !== null && isUsbSerial(a);
162579
+ }
162580
+ function isUsbSerial(serial) {
162581
+ return !serial.startsWith("emulator-") && !serial.includes(":") && !serial.includes("._");
162582
+ }
162295
162583
  async function androidSerials() {
162296
162584
  try {
162297
162585
  const { stdout } = await runAdb(["devices"], { timeoutMs: ADB_DEVICES_TIMEOUT_MS });
@@ -162310,9 +162598,9 @@ async function logcatHolds(serial, marker) {
162310
162598
  ["-s", serial, "logcat", "-d", "-s", "ReactNativeJS", "-e", marker],
162311
162599
  { timeoutMs: LOG_READ_TIMEOUT_MS }
162312
162600
  );
162313
- return stdout.includes(marker) ? serial : void 0;
162601
+ return stdout.includes(marker) ? "held" : "absent";
162314
162602
  } catch {
162315
- return void 0;
162603
+ return "failed";
162316
162604
  }
162317
162605
  }
162318
162606
  async function simulatorLogHolds(udid, marker) {
@@ -162341,6 +162629,9 @@ async function simulatorLogHolds(udid, marker) {
162341
162629
  }
162342
162630
  }
162343
162631
 
162632
+ // ../tool-server/src/tools/profiler/react/react-profiler-start.ts
162633
+ init_external_devices();
162634
+
162344
162635
  // ../tool-server/src/utils/react-profiler/devtools-bootstrap.ts
162345
162636
  function bootstrapFailureMessage(bootstrap) {
162346
162637
  switch (bootstrap.reason) {
@@ -162362,17 +162653,47 @@ function bootstrapFailureMessage(bootstrap) {
162362
162653
 
162363
162654
  // ../tool-server/src/utils/profiler-shared/network-capture-warning.ts
162364
162655
  var CAPTURE_COST = "It can slow the app, so the timings in this profile can differ from a run without it.";
162365
- function nativeNetworkCaptureWarning(deviceId, runtimeApp) {
162366
- let packages;
162656
+ function nativeNetworkCaptureWarning(deviceId, runtimeApp, runtimeDevices = { found: [], unresolved: [] }) {
162367
162657
  try {
162368
- packages = liveAndroidNetworkCaptures(deviceId);
162658
+ if (runtimeDevices.found.length > 0) {
162659
+ return foundDeviceWarning(runtimeDevices, runtimeApp);
162660
+ }
162661
+ const packages = liveAndroidNetworkCaptures(deviceId);
162369
162662
  if (packages.length === 0) return logicalDeviceWarning(deviceId, runtimeApp);
162663
+ const apps = packages.join(", ");
162664
+ const one = packages.length === 1;
162665
+ return `Native network capture is on for ${apps} on this device: Argent attaches its in-app agent to the processes of ${one ? "that app" : "these apps"}. ${CAPTURE_COST} To profile without it, stop this profile, call native-network-logs with stop: true for ${one ? "that app" : "each of these apps"}, then restart-app and profile again.`;
162370
162666
  } catch {
162371
162667
  return void 0;
162372
162668
  }
162373
- const apps = packages.join(", ");
162374
- const one = packages.length === 1;
162375
- return `Native network capture is on for ${apps} on this device: Argent attaches its in-app agent to the processes of ${one ? "that app" : "these apps"}. ${CAPTURE_COST} To profile without it, stop this profile, call native-network-logs with stop: true for ${one ? "that app" : "each of these apps"}, then restart-app and profile again.`;
162669
+ }
162670
+ function foundDeviceWarning({ found, unresolved }, runtimeApp) {
162671
+ const captures = found.map((device) => ({ device, packages: liveAndroidNetworkCaptures(device) })).filter(({ packages }) => packages.length > 0);
162672
+ const appId = runtimeApp?.platform === "android" ? runtimeApp.appId : void 0;
162673
+ const maybe = appId ? unresolved.filter((serial) => liveAndroidNetworkCaptures(serial).includes(appId)) : [];
162674
+ const first = captures[0];
162675
+ if (!first && (!appId || maybe.length === 0)) return void 0;
162676
+ const sentences = [];
162677
+ if (first) {
162678
+ const apps = [...new Set(captures.flatMap(({ packages }) => packages))].sort();
162679
+ const where = captures.length === 1 ? `${first.device}, the device this profile runs on` : `${captures.map(({ device }) => device).join(" and ")}, adb serials of the device this profile runs on`;
162680
+ sentences.push(
162681
+ `Native network capture is on for ${apps.join(", ")} on ${where}: Argent attaches its in-app agent to the processes of ${apps.length === 1 ? "that app" : "these apps"}.`
162682
+ );
162683
+ }
162684
+ if (appId && maybe.length > 0) {
162685
+ const one = maybe.length === 1;
162686
+ sentences.push(
162687
+ `Native network capture is ${first ? "also " : ""}on for ${appId} on ${maybe.join(", ")}, ${one ? "which" : "each of which"} may also be the device this profile runs on: ${one ? "its logcat" : "their logcats"} could not be read to tell. Argent attaches its in-app agent to the processes of that app there.`
162688
+ );
162689
+ }
162690
+ const stops = [
162691
+ ...captures.flatMap(({ device, packages }) => packages.map((app) => ({ app, device }))),
162692
+ ...appId ? maybe.map((device) => ({ app: appId, device })) : []
162693
+ ];
162694
+ const stop = first && captures.length === 1 && maybe.length === 0 ? `with udid ${first.device} and stop: true for ${first.packages.length === 1 ? "that app" : "each of these apps"}` : `with stop: true for ${stops.map(({ app, device }) => `${app} with udid ${device}`).join(", ")}`;
162695
+ const restart = first?.device ?? found[0];
162696
+ return `${sentences.join(" ")} ${CAPTURE_COST} To profile without it, stop this profile, call native-network-logs ${stop}, then restart-app on ${restart} and profile again.`;
162376
162697
  }
162377
162698
  function logicalDeviceWarning(deviceId, runtimeApp) {
162378
162699
  const appId = runtimeApp?.appId;
@@ -162429,6 +162750,25 @@ function failedTakeoverText({ session_id, reason: reason2 }) {
162429
162750
  const run2 = session_id ? `session ${session_id}` : "a recording with no owner record";
162430
162751
  return `Before it failed, this start stopped ${run2} (reason: ${reason2}), and nothing is recording now.`;
162431
162752
  }
162753
+ function findProfiledDevices(cdp) {
162754
+ return findRuntimeDevices(cdp, {
162755
+ awaitSerials: idsOf(liveAndroidNetworkCaptureSerials),
162756
+ waitSerials: idsOf(simulatorServerDeviceIds).map(externalNativeId)
162757
+ });
162758
+ }
162759
+ function trackedIds(found) {
162760
+ const driven = idsOf(simulatorServerDeviceIds).filter(
162761
+ (id) => found.includes(externalNativeId(id))
162762
+ );
162763
+ return [.../* @__PURE__ */ new Set([...found, ...driven])];
162764
+ }
162765
+ function idsOf(lookup) {
162766
+ try {
162767
+ return lookup();
162768
+ } catch {
162769
+ return [];
162770
+ }
162771
+ }
162432
162772
  function safeGetState(registry2, urn) {
162433
162773
  try {
162434
162774
  return registry2.getServiceState(urn);
@@ -162629,7 +162969,7 @@ Fails if the Hermes runtime is not reachable or the Metro CDP connection cannot
162629
162969
  }
162630
162970
  await cdp.send("Profiler.stop").catch(ignore);
162631
162971
  api.profilingActive = false;
162632
- const runtimeDevice = isLogicalKeyedDevice(api.deviceId) ? await findRuntimeDevice(cdp) : void 0;
162972
+ const runtimeDevices = isLogicalKeyedDevice(api.deviceId) ? await findProfiledDevices(cdp) : { found: [], unresolved: [] };
162633
162973
  const sessionId = crypto6.randomUUID();
162634
162974
  const ownerPayload = {
162635
162975
  sessionId,
@@ -162712,8 +163052,8 @@ Fails if the Hermes runtime is not reachable or the Metro CDP connection cannot
162712
163052
  api.sessionId = sessionId;
162713
163053
  api.ownerToolServerPid = process.pid;
162714
163054
  trackProfilingRun(api.deviceId, api);
162715
- if (runtimeDevice) trackProfilingRun(runtimeDevice, api);
162716
- const warning = nativeNetworkCaptureWarning(deviceId ?? params.device_id, api.runtimeApp);
163055
+ for (const device of trackedIds(runtimeDevices.found)) trackProfilingRun(device, api);
163056
+ const warning = nativeNetworkCaptureWarning(api.deviceId, api.runtimeApp, runtimeDevices);
162717
163057
  return {
162718
163058
  started_at: new Date(startedAtEpochMs).toISOString(),
162719
163059
  startedAtEpochMs,
@@ -162721,7 +163061,7 @@ Fails if the Hermes runtime is not reachable or the Metro CDP connection cannot
162721
163061
  detected_architecture: api.detectedArchitecture,
162722
163062
  ...tookOver ? { took_over: tookOver } : {},
162723
163063
  ...warning ? { warning } : {},
162724
- ...isLogicalKeyedDevice(api.deviceId) && !runtimeDevice ? { [RESULT_NOTE_KEY]: UNKNOWN_DEVICE_NOTE } : {}
163064
+ ...isLogicalKeyedDevice(api.deviceId) && runtimeDevices.found.length === 0 ? { [RESULT_NOTE_KEY]: UNKNOWN_DEVICE_NOTE } : {}
162725
163065
  };
162726
163066
  }
162727
163067
  };
@@ -174755,8 +175095,8 @@ Fails if the input has an unknown key (e.g. \`udids\` instead of \`devices\`); o
174755
175095
  // "all" only holds for the unscoped sweep; a scoped call touches just the
174756
175096
  // ids it was given.
174757
175097
  startedMsg: ({ params }) => {
174758
- const devices = params?.devices;
174759
- return devices ? `Stopping simulator servers for ${devices.length} ${devices.length === 1 ? "device" : "devices"}` : "Stopping all simulator servers";
175098
+ const devices2 = params?.devices;
175099
+ return devices2 ? `Stopping simulator servers for ${devices2.length} ${devices2.length === 1 ? "device" : "devices"}` : "Stopping all simulator servers";
174760
175100
  },
174761
175101
  completedMsg: ({ result }) => {
174762
175102
  const n = result.stopped.length;
@@ -174780,8 +175120,8 @@ Fails if the input has an unknown key (e.g. \`udids\` instead of \`devices\`); o
174780
175120
  },
174781
175121
  services: () => ({}),
174782
175122
  async execute(_services, params, ctx) {
174783
- const devices = params.devices;
174784
- const scoped = devices !== void 0;
175123
+ const devices2 = params.devices;
175124
+ const scoped = devices2 !== void 0;
174785
175125
  const snapshot = registry2.getSnapshot();
174786
175126
  const stopped = [];
174787
175127
  const matchedIds = /* @__PURE__ */ new Set();
@@ -174792,7 +175132,7 @@ Fails if the input has an unknown key (e.g. \`udids\` instead of \`devices\`); o
174792
175132
  aborted2 = true;
174793
175133
  break;
174794
175134
  }
174795
- const matchedId = scoped ? deviceIdOwningUrn(urn, DEVICE_OWNED_NAMESPACES, devices) : void 0;
175135
+ const matchedId = scoped ? deviceIdOwningUrn(urn, DEVICE_OWNED_NAMESPACES, devices2) : void 0;
174796
175136
  const matches2 = scoped ? matchedId !== void 0 : isDeviceServiceUrn(urn, DEVICE_OWNED_NAMESPACES);
174797
175137
  if (matchedId !== void 0) matchedIds.add(matchedId.toLowerCase());
174798
175138
  if (matches2 && entry.state !== "IDLE" /* IDLE */) {
@@ -174806,7 +175146,7 @@ Fails if the input has an unknown key (e.g. \`udids\` instead of \`devices\`); o
174806
175146
  if (aborted2) return { stopped, aborted: true };
174807
175147
  if (!scoped) return { stopped };
174808
175148
  const seen = /* @__PURE__ */ new Set();
174809
- const unmatched = devices.filter((id) => {
175149
+ const unmatched = devices2.filter((id) => {
174810
175150
  const key2 = id.toLowerCase();
174811
175151
  if (matchedIds.has(key2) || seen.has(key2)) return false;
174812
175152
  seen.add(key2);
@@ -177121,7 +177461,7 @@ function serializeFlow(flow) {
177121
177461
  steps: flow.steps.map(toYamlStep)
177122
177462
  };
177123
177463
  if (flow.executionPrerequisite) doc.executionPrerequisite = flow.executionPrerequisite;
177124
- return (0, import_yaml.stringify)(doc, { blockQuote: false });
177464
+ return (0, import_yaml.stringify)(doc, { blockQuote: false, doubleQuotedMinMultiLineLength: Infinity });
177125
177465
  }
177126
177466
  function validateFlow(flow) {
177127
177467
  assertNoOutputReferences(flow.steps);
@@ -177625,14 +177965,14 @@ function isBooted(d, platform) {
177625
177965
  return false;
177626
177966
  }
177627
177967
  }
177628
- function connectedIosDeviceHint(devices, platform) {
177968
+ function connectedIosDeviceHint(devices2, platform) {
177629
177969
  if (platform && platform !== "ios") return "";
177630
- const ids = devices.filter((d) => d.platform === "ios" && d.kind === "device" && d.state === "connected").map((d) => d.udid).filter((id) => Boolean(id));
177970
+ const ids = devices2.filter((d) => d.platform === "ios" && d.kind === "device" && d.state === "connected").map((d) => d.udid).filter((id) => Boolean(id));
177631
177971
  if (ids.length === 0) return "";
177632
177972
  return ` A physical iPhone is connected (${ids.join(", ")}); hardware is never picked automatically, pass device <udid> (--device on the CLI) to run on it.`;
177633
177973
  }
177634
- function macosAppHint(devices, platform) {
177635
- if (platform || !devices.some((d) => d.platform === "macos")) return "";
177974
+ function macosAppHint(devices2, platform) {
177975
+ if (platform || !devices2.some((d) => d.platform === "macos")) return "";
177636
177976
  return " A Mac app is picked only with --platform macos or --device.";
177637
177977
  }
177638
177978
  function macosFlagHint(platform) {
@@ -177719,9 +178059,9 @@ async function assertDeviceMeetsRequires(device, requires, subject2 = "This e2e
177719
178059
  );
177720
178060
  }
177721
178061
  }
177722
- function unknownRuntimeKindError(requires, devices, subject2 = "This e2e test", remedy = "") {
178062
+ function unknownRuntimeKindError(requires, devices2, subject2 = "This e2e test", remedy = "") {
177723
178063
  return requirementsError(
177724
- `${subject2} declares ${describeRequires(requires)}, but the runtime kind of ${devices.join(", ")} could not be determined.${remedy}`,
178064
+ `${subject2} declares ${describeRequires(requires)}, but the runtime kind of ${devices2.join(", ")} could not be determined.${remedy}`,
177725
178065
  FAILURE_CODES.FLOW_DEVICE_RESOLUTION
177726
178066
  );
177727
178067
  }
@@ -177739,8 +178079,8 @@ async function resolveFlowDevice(registry2, ctx, opts) {
177739
178079
  if (macosRefusal) throw deviceResolutionError(`Cannot run on ${device.id}: ${macosRefusal}`);
177740
178080
  return device;
177741
178081
  }
177742
- const { devices } = await invokeSubTool(registry2, ctx, "list-devices", {});
177743
- const booted = devices.filter((d) => isBooted(d, opts.platform));
178082
+ const { devices: devices2 } = await invokeSubTool(registry2, ctx, "list-devices", {});
178083
+ const booted = devices2.filter((d) => isBooted(d, opts.platform));
177744
178084
  const scoped = opts.platform ? booted.filter((d) => d.platform === opts.platform) : booted;
177745
178085
  const requires = opts.requires;
177746
178086
  const candidates = requires ? scoped.filter((d) => platformMeets(d.platform, requires)) : scoped;
@@ -177782,8 +178122,8 @@ async function resolveFlowDevice(registry2, ctx, opts) {
177782
178122
  if (eligible.length === 0) {
177783
178123
  const what = opts.platform ? `No booted ${opts.platform} device found.` : "No booted device found.";
177784
178124
  throw deviceResolutionError(
177785
- `${what} Pass a device id or platform explicitly.${connectedIosDeviceHint(devices, opts.platform)}${macosAppHint(devices, opts.platform)}${macosFlagHint(opts.platform)}`,
177786
- devices
178125
+ `${what} Pass a device id or platform explicitly.${connectedIosDeviceHint(devices2, opts.platform)}${macosAppHint(devices2, opts.platform)}${macosFlagHint(opts.platform)}`,
178126
+ devices2
177787
178127
  );
177788
178128
  }
177789
178129
  throw deviceResolutionError(
@@ -177904,6 +178244,7 @@ function asViewNode(v) {
177904
178244
  className: nonEmptyString(r.className),
177905
178245
  identifier: nonEmptyString(r.identifier),
177906
178246
  label: nonEmptyString(r.label),
178247
+ value: nonEmptyString(r.value),
177907
178248
  frame: asRect2(r.frame),
177908
178249
  windowFrame: asRect2(r.windowFrame),
177909
178250
  screenFrame: asRect2(r.screenFrame),
@@ -177913,10 +178254,11 @@ function asViewNode(v) {
177913
178254
  children
177914
178255
  };
177915
178256
  }
178257
+ var IOS_TEXT_INPUT_ROLE = "AXTextField";
177916
178258
  function roleFromClassName(cn) {
177917
178259
  if (!cn) return "AXGroup";
177918
178260
  if (/Button/i.test(cn)) return "AXButton";
177919
- if (/(TextField|TextView|SearchField)/i.test(cn)) return "AXTextField";
178261
+ if (/(TextField|TextView|SearchField)/i.test(cn)) return IOS_TEXT_INPUT_ROLE;
177920
178262
  if (/(Label|Text)/i.test(cn)) return "AXStaticText";
177921
178263
  if (/Image/i.test(cn)) return "AXImage";
177922
178264
  if (/(Slider|Stepper|Switch|ProgressView)/i.test(cn)) return "AXAdjustable";
@@ -177939,9 +178281,12 @@ function normalizeFrame4(rect, screenW, screenH) {
177939
178281
  height: roundNormalized3(height)
177940
178282
  };
177941
178283
  }
177942
- function projectIosNode(node2, screenW, screenH) {
178284
+ function projectIosNode(node2, screenW, screenH, quotedLabel) {
177943
178285
  const skip = node2.hidden === true || node2.alpha !== void 0 && node2.alpha < 0.01;
177944
178286
  const role = roleFromClassName(node2.className);
178287
+ const held = role === IOS_TEXT_INPUT_ROLE && node2.value !== node2.label ? node2.value : void 0;
178288
+ const value = quotedLabel && held !== void 0 ? WITHHELD_INPUT_TEXT : held;
178289
+ const label = quotedLabel && node2.label !== void 0 ? quotedLabel(node2.label) : node2.label;
177945
178290
  const win = node2.screenFrame ?? node2.windowFrame;
177946
178291
  const rect = win ? { x: win.x, y: win.y, w: win.width, h: win.height } : null;
177947
178292
  let leaf = null;
@@ -177954,27 +178299,34 @@ function projectIosNode(node2, screenW, screenH) {
177954
178299
  role,
177955
178300
  frame: frame2,
177956
178301
  children: [],
177957
- label: node2.label,
178302
+ label,
178303
+ value,
177958
178304
  identifier: node2.identifier,
177959
178305
  focused: node2.firstResponder || void 0
177960
178306
  };
177961
178307
  }
177962
178308
  }
178309
+ const ownTextParts = frame2 ? [label, value].filter((text) => Boolean(text)) : [];
177963
178310
  return {
177964
178311
  skip,
177965
178312
  children: node2.children ?? [],
177966
178313
  // Text hoists only from on-screen nodes (frame is null when the view is
177967
178314
  // scrolled off or zero-area) — otherwise a text assert against an ancestor
177968
178315
  // would pass on content the screen doesn't show. A label makes a node
177969
- // leaf-eligible, so `frame` was computed for any node with text.
177970
- ownText: frame2 ? node2.label ?? "" : "",
178316
+ // leaf-eligible, and so does the text input role a value needs, so `frame`
178317
+ // was computed for any node with text. Mirrors what `nodeText` reads off
178318
+ // the leaf: the label plus a distinct value.
178319
+ ownText: ownTextParts.join(" "),
178320
+ // Apart as well: the view under an empty field that draws its placeholder
178321
+ // repeats the value and not the label, and a floating label the reverse.
178322
+ ownTextParts,
177971
178323
  leaf,
177972
178324
  shield: Boolean(node2.identifier),
177973
178325
  rect,
177974
178326
  scrolls: role === "AXScrollArea"
177975
178327
  };
177976
178328
  }
177977
- function adaptFullHierarchy(raw) {
178329
+ function adaptFullHierarchy(raw, quotedLabel) {
177978
178330
  const payload = typeof raw === "object" && raw !== null ? raw : {};
177979
178331
  const reportedScreen = typeof payload.screen === "object" && payload.screen !== null ? payload.screen : void 0;
177980
178332
  const windows = Array.isArray(payload.windows) ? payload.windows.map(asViewNode).filter((n) => n !== null) : [];
@@ -177996,7 +178348,7 @@ function adaptFullHierarchy(raw) {
177996
178348
  const children = [];
177997
178349
  if (screenW > 0 && screenH > 0) {
177998
178350
  for (const win of windows) {
177999
- flattenHoisting(win, (n) => projectIosNode(n, screenW, screenH), children);
178351
+ flattenHoisting(win, (n) => projectIosNode(n, screenW, screenH, quotedLabel), children);
178000
178352
  }
178001
178353
  }
178002
178354
  const tree = parseDescribeResult({
@@ -178017,6 +178369,9 @@ var FULL_HIERARCHY_FIELDS = [
178017
178369
  "className",
178018
178370
  "identifier",
178019
178371
  "label",
178372
+ // A text input's text; an injected framework that omits it leaves a filled
178373
+ // field reading as empty.
178374
+ "value",
178020
178375
  "frame",
178021
178376
  "windowFrame",
178022
178377
  "screenFrame",
@@ -178179,8 +178534,10 @@ async function queryFullHierarchyTree(registry2, device, target) {
178179
178534
  );
178180
178535
  }
178181
178536
  const { tree, screen, uiOrientation } = adaptFullHierarchy(rawResult);
178537
+ const quotableTree = secretTypedOn(device.id) ? adaptFullHierarchy(rawResult, (label) => redactTypedSecrets(device.id, label)).tree : void 0;
178182
178538
  return {
178183
178539
  tree,
178540
+ ...quotableTree ? { quotableTree } : {},
178184
178541
  source: "native-devtools",
178185
178542
  ...screen ? { screen } : {},
178186
178543
  ...uiOrientation ? { uiOrientation } : {}
@@ -179289,6 +179646,7 @@ async function runType(env, step) {
179289
179646
  async function waitForCondition(env, step, timeoutMs) {
179290
179647
  const deadline = Date.now() + timeoutMs;
179291
179648
  let lastMatches = [];
179649
+ let lastData;
179292
179650
  let fetchError;
179293
179651
  let everMatched = false;
179294
179652
  let lastTrustedReadAt;
@@ -179300,6 +179658,7 @@ async function waitForCondition(env, step, timeoutMs) {
179300
179658
  try {
179301
179659
  const data = await readFlowTree(env);
179302
179660
  lastMatches = flowFindAll(data.tree, step.selector, data.uiOrientation);
179661
+ lastData = data;
179303
179662
  fetchError = void 0;
179304
179663
  everMatched ||= lastMatches.length > 0;
179305
179664
  const blind = isBlindRead(data, everMatched, step.condition);
@@ -179367,7 +179726,10 @@ async function waitForCondition(env, step, timeoutMs) {
179367
179726
  // The read `lastMatches` came from is the last one that answered, and
179368
179727
  // only a read that answers writes the orientation.
179369
179728
  readingOrientation(env),
179370
- env.device.platform === "macos"
179729
+ env.device.platform === "macos",
179730
+ // The text of an element is the only part of a reason that comes off
179731
+ // the screen, where a field shows a typed secret.
179732
+ (node2, read) => lastData ? quotedText(lastData, env.device.id, node2, read) : read(node2)
179371
179733
  ) + blipNote
179372
179734
  };
179373
179735
  }
@@ -179587,7 +179949,7 @@ async function waitForIdle(env, step) {
179587
179949
  warning: `the screen never held still for ${MIN_STILL_INTERVALS} consecutive ${IDLE_POLL_MS}ms intervals${stableFor > 0 ? ` spanning ${stableFor}ms` : ""} within ${timeoutMs}ms, and was moving again on the last one, so this step went ahead without waiting it out. Either something on it never stops (a video, a looping animation, a carousel, live-updating text) or the screen never finished loading. Look at what is moving, and make sure the next action is gated on a stable element rather than on stillness.` + blipNote
179588
179950
  };
179589
179951
  }
179590
- function assertReason(condition, selector, expectedText, textMatch, matches2, orientation, macos) {
179952
+ function assertReason(condition, selector, expectedText, textMatch, matches2, orientation, macos, quoted) {
179591
179953
  const sel = describeSelector(selector);
179592
179954
  switch (condition) {
179593
179955
  case "exists":
@@ -179600,9 +179962,8 @@ function assertReason(condition, selector, expectedText, textMatch, matches2, or
179600
179962
  const first = textCheckTarget(matches2, orientation, macos);
179601
179963
  if (!first) return `no element matched selector ${sel}`;
179602
179964
  const wanted = describeTextExpectation(expectedText, textMatch, "infinitive");
179603
- const field = macFieldText(first, macos);
179604
- const shown = field ?? assertText(first);
179605
- const own2 = field ?? nodeText(first);
179965
+ const shown = quoted(first, (node2) => macFieldText(node2, macos) ?? assertText(node2));
179966
+ const own2 = quoted(first, (node2) => macFieldText(node2, macos) ?? nodeText(node2));
179606
179967
  const ownNote = own2 && own2 !== shown ? ` (own text "${own2}")` : "";
179607
179968
  return `element matched ${sel} but its text was "${shown}"${ownNote} (wanted to ${wanted})`;
179608
179969
  }
@@ -180428,6 +180789,9 @@ function innermostTreeReason(message) {
180428
180789
  const unwrapped = /helper is unavailable:\s*(.+)/s.exec(message)?.[1] ?? message;
180429
180790
  return unwrapped.replace(/^\[[^\]]+\]\s*/, "").trim();
180430
180791
  }
180792
+ function withoutTypedText(node2, { source }) {
180793
+ return source === "native-devtools" && node2.role === IOS_TEXT_INPUT_ROLE ? { ...node2, value: void 0 } : node2;
180794
+ }
180431
180795
  async function captureTapSelector(registry2, session, udid, point) {
180432
180796
  try {
180433
180797
  const device = resolveDevice(udid);
@@ -180440,7 +180804,7 @@ async function captureTapSelector(registry2, session, udid, point) {
180440
180804
  const { tree, uiOrientation } = data;
180441
180805
  const node2 = nodeAtPoint(tree, point);
180442
180806
  if (!node2) return { warning: "no element found under the tap; kept coordinates (brittle)" };
180443
- const selector = deriveSelector(node2);
180807
+ const selector = deriveSelector(withoutTypedText(node2, data));
180444
180808
  if (!selector)
180445
180809
  return { warning: "tapped element has no stable text/id; kept coordinates (brittle)" };
180446
180810
  const resolved = selectorToFrame(tree, selector, uiOrientation);