rnxsim 0.1.365 → 0.1.367

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.
Files changed (240) hide show
  1. package/README.md +14 -0
  2. package/cli/bin.ts +18 -0
  3. package/cli/bridge-flow-runner.ts +16 -153
  4. package/cli/commands/assert.ts +1 -1
  5. package/cli/commands/box/checkout-plane.ts +126 -0
  6. package/cli/commands/box/rnx-command.ts +68 -0
  7. package/cli/commands/box.ts +200 -0
  8. package/cli/commands/control.ts +15 -76
  9. package/cli/commands/detox.ts +18 -1
  10. package/cli/commands/do-chain.ts +412 -0
  11. package/cli/commands/flow.ts +2 -11
  12. package/cli/commands/inspect/core.ts +302 -725
  13. package/cli/commands/inspect/describe.ts +3 -76
  14. package/cli/commands/inspect/find.ts +3 -6
  15. package/cli/commands/inspect/get-layout.ts +14 -1
  16. package/cli/commands/inspect/resolve-target.ts +41 -47
  17. package/cli/commands/inspect/shared.ts +28 -123
  18. package/cli/commands/inspect/tree.ts +6 -15
  19. package/cli/commands/inspect/wait-ready.ts +2 -2
  20. package/cli/commands/inspect/wait-selector.ts +4 -8
  21. package/cli/commands/inspect.ts +23 -17
  22. package/cli/commands/install-desktop.ts +44 -7
  23. package/cli/commands/maestro-generate.ts +0 -2
  24. package/cli/commands/platform.ts +68 -0
  25. package/cli/commands/state.ts +5 -2
  26. package/cli/outbound-endpoints.ts +6 -1
  27. package/cli/parse-args.ts +13 -2
  28. package/cli/ws-bridge.ts +30 -2
  29. package/detox/index.ts +37 -18
  30. package/dist-cli/bin.js +5 -5
  31. package/dist-cli/chunks/{agent-BVMNQFKF.js → agent-EKKIAKP5.js} +2 -2
  32. package/dist-cli/chunks/{agent-wrapper-B6YFXGC3.js → agent-wrapper-MHLQUGA6.js} +2 -2
  33. package/dist-cli/chunks/{app-fonts-MEI6R6XR.js → app-fonts-HN6ADRTQ.js} +2 -2
  34. package/dist-cli/chunks/{assert-JGHI53HV.js → assert-IMR6QCN6.js} +3 -3
  35. package/dist-cli/chunks/{auth-STEOXUS7.js → auth-27LPMQNH.js} +2 -2
  36. package/dist-cli/chunks/{beta-HT3FLS5T.js → beta-6RXBB5AI.js} +2 -2
  37. package/dist-cli/chunks/box-DORLF3GP.js +1709 -0
  38. package/dist-cli/chunks/{camera-ZCLFSLON.js → camera-2G7JZ5DL.js} +2 -2
  39. package/dist-cli/chunks/{chunk-RI3NS77J.js → chunk-3QZJLNYY.js} +1 -1
  40. package/dist-cli/chunks/{chunk-FHWZPUGC.js → chunk-3VBVEDDA.js} +1 -1
  41. package/dist-cli/chunks/{chunk-EAFKG5R3.js → chunk-4BWGLTKU.js} +2 -2
  42. package/dist-cli/chunks/chunk-4XSNO374.js +423 -0
  43. package/dist-cli/chunks/{chunk-GZEUDDAW.js → chunk-5DGMFUZG.js} +2 -2
  44. package/dist-cli/chunks/{chunk-TKCGP3DD.js → chunk-6DBS5EGX.js} +2 -2
  45. package/dist-cli/chunks/{chunk-HIDS3PYC.js → chunk-6SO6I3D5.js} +2 -2
  46. package/dist-cli/chunks/chunk-75EFOPXE.js +32 -0
  47. package/dist-cli/chunks/{chunk-FIXRGPUT.js → chunk-A5AJFVOF.js} +1 -1
  48. package/dist-cli/chunks/{chunk-2SFMW5K6.js → chunk-AM2ODYAN.js} +1 -1
  49. package/dist-cli/chunks/{chunk-BGRGP3QR.js → chunk-AVOROGA3.js} +1 -1
  50. package/dist-cli/chunks/chunk-AXMMLO7D.js +130 -0
  51. package/dist-cli/chunks/{chunk-XXNPISER.js → chunk-BSEXEYNX.js} +2 -2
  52. package/dist-cli/chunks/{chunk-67ATAITF.js → chunk-CM6ZKZW7.js} +2 -2
  53. package/dist-cli/chunks/{chunk-MR3YPNUI.js → chunk-DNVABCEC.js} +2 -2
  54. package/dist-cli/chunks/{chunk-5AS7S6HY.js → chunk-E33A4AIR.js} +2 -2
  55. package/dist-cli/chunks/{chunk-DBJZUCFP.js → chunk-EFMOXYDD.js} +2 -2
  56. package/dist-cli/chunks/{chunk-ZTWUNK45.js → chunk-EV4P5UBP.js} +2 -2
  57. package/dist-cli/chunks/{chunk-EVBQDQVY.js → chunk-G5IUIGGC.js} +1 -1
  58. package/dist-cli/chunks/chunk-GMLOCV3E.js +312 -0
  59. package/dist-cli/chunks/{chunk-DQFOHIRF.js → chunk-GRN2FHVW.js} +1 -1
  60. package/dist-cli/chunks/{chunk-CYIE65QN.js → chunk-HFFXPUEP.js} +1 -1
  61. package/dist-cli/chunks/chunk-HG6T4OOR.js +4 -0
  62. package/dist-cli/chunks/{chunk-GK7PGYFH.js → chunk-HNT2OXPZ.js} +1 -1
  63. package/dist-cli/chunks/chunk-IPEURNLI.js +24 -0
  64. package/dist-cli/chunks/chunk-IR44SFBA.js +5 -0
  65. package/dist-cli/chunks/chunk-JMSLXZFW.js +4 -0
  66. package/dist-cli/chunks/{chunk-WGNDJARS.js → chunk-JPXQKLNH.js} +1 -1
  67. package/dist-cli/chunks/chunk-K3EC6JDE.js +4 -0
  68. package/dist-cli/chunks/chunk-KHX65HAU.js +4 -0
  69. package/dist-cli/chunks/{chunk-MACI34ST.js → chunk-LWOVKHRC.js} +2 -2
  70. package/dist-cli/chunks/{chunk-QIQL7Y5V.js → chunk-MQN5DWTI.js} +2 -2
  71. package/dist-cli/chunks/{chunk-5VHWQGGF.js → chunk-N3BXQEUF.js} +1 -1
  72. package/dist-cli/chunks/{chunk-O2ORLK6W.js → chunk-N5OSV26B.js} +2 -2
  73. package/dist-cli/chunks/chunk-PHNURIH3.js +4 -0
  74. package/dist-cli/chunks/{chunk-JRPU5TFI.js → chunk-PP2KNVXP.js} +3 -3
  75. package/dist-cli/chunks/{chunk-UR345KM3.js → chunk-PROKNJVY.js} +2 -2
  76. package/dist-cli/chunks/chunk-QXLLY4IM.js +7 -0
  77. package/dist-cli/chunks/{chunk-2CXHDTQ5.js → chunk-RNQTOGM7.js} +1 -1
  78. package/dist-cli/chunks/{chunk-M5KJCLUW.js → chunk-RPNKKVBN.js} +27 -27
  79. package/dist-cli/chunks/{chunk-EFXNSJ55.js → chunk-RSNLI2NH.js} +2 -2
  80. package/dist-cli/chunks/{chunk-25BTVHK2.js → chunk-RZGHV2WI.js} +2 -2
  81. package/dist-cli/chunks/chunk-SGGL3AFV.js +497 -0
  82. package/dist-cli/chunks/chunk-SH5ETJKG.js +4 -0
  83. package/dist-cli/chunks/{chunk-MRNW4GVL.js → chunk-T6J4YP56.js} +2 -2
  84. package/dist-cli/chunks/{chunk-R4FQZXJC.js → chunk-TWUE7WF5.js} +2 -2
  85. package/dist-cli/chunks/{chunk-X5ZOZVHC.js → chunk-U44VEQRN.js} +1 -1
  86. package/dist-cli/chunks/{chunk-XRO5WQXP.js → chunk-URLVQHC3.js} +1 -1
  87. package/dist-cli/chunks/{chunk-JAFF4RAU.js → chunk-VANZFTUE.js} +1 -1
  88. package/dist-cli/chunks/{chunk-6BAF6GFS.js → chunk-VB2YBH46.js} +1 -1
  89. package/dist-cli/chunks/{chunk-O6P4N2JD.js → chunk-VFU2SJ7M.js} +2 -2
  90. package/dist-cli/chunks/{chunk-XPOTXF5Q.js → chunk-VUBJ6FXU.js} +15 -15
  91. package/dist-cli/chunks/{chunk-XR4KID25.js → chunk-W5PATILQ.js} +2 -2
  92. package/dist-cli/chunks/chunk-WI5V4TYG.js +38 -0
  93. package/dist-cli/chunks/{chunk-NEH4T67X.js → chunk-XTRHQAOV.js} +2 -2
  94. package/dist-cli/chunks/chunk-XWUTJLBM.js +27 -0
  95. package/dist-cli/chunks/{chunk-TULWPOAY.js → chunk-XYRUQQUR.js} +2 -2
  96. package/dist-cli/chunks/chunk-YBFB3RM7.js +4 -0
  97. package/dist-cli/chunks/chunk-YGQVQ2VG.js +4 -0
  98. package/dist-cli/chunks/{chunk-J66US2OZ.js → chunk-YINACV32.js} +1 -1
  99. package/dist-cli/chunks/chunk-YV7ERO2V.js +5 -0
  100. package/dist-cli/chunks/{cleanup-G4TEYVKY.js → cleanup-GVFHQ3KH.js} +2 -2
  101. package/dist-cli/chunks/cli-version-DPX5MA2M.js +4 -0
  102. package/dist-cli/chunks/{compat-EZ5NP32J.js → compat-AYRTXYAM.js} +2 -2
  103. package/dist-cli/chunks/{config-27M2DGCS.js → config-K7LOOV62.js} +2 -2
  104. package/dist-cli/chunks/connect-H3CNY4IO.js +4 -0
  105. package/dist-cli/chunks/control-SMHZ2CF5.js +4 -0
  106. package/dist-cli/chunks/daemon-TEZUNI73.js +4 -0
  107. package/dist-cli/chunks/{debug-EXU3D7PC.js → debug-ELGHG57T.js} +3 -3
  108. package/dist-cli/chunks/{desktop-SHHPZAWQ.js → desktop-4G7FK3MP.js} +3 -3
  109. package/dist-cli/chunks/detox-JKXGEJIZ.js +52 -0
  110. package/dist-cli/chunks/{device-4NI26HG6.js → device-IV3AR6KG.js} +2 -2
  111. package/dist-cli/chunks/{diagnose-P4SFXH6J.js → diagnose-3ERGF7EW.js} +2 -2
  112. package/dist-cli/chunks/{disk-cleanup-BUAKWYMY.js → disk-cleanup-ALFEVZ4B.js} +2 -2
  113. package/dist-cli/chunks/do-chain-K2B4OHM7.js +5 -0
  114. package/dist-cli/chunks/drivers-KJYXA3M3.js +4 -0
  115. package/dist-cli/chunks/env-2KF6IYZE.js +4 -0
  116. package/dist-cli/chunks/{film-Y2BAQINB.js → film-UQXJFAD5.js} +3 -3
  117. package/dist-cli/chunks/flow-ASTUH56E.js +4 -0
  118. package/dist-cli/chunks/help-SNNYFELA.js +4 -0
  119. package/dist-cli/chunks/{hidden-runtime-alias-U2MAY2XV.js → hidden-runtime-alias-VJCWCFVO.js} +2 -2
  120. package/dist-cli/chunks/{home-paths-PAJMZCOS.js → home-paths-EGUZZ6J6.js} +2 -2
  121. package/dist-cli/chunks/inspect-XANAADQT.js +4 -0
  122. package/dist-cli/chunks/install-desktop-JKQA7UY6.js +4 -0
  123. package/dist-cli/chunks/{login-D53XKBEO.js → login-6KQGD7HK.js} +2 -2
  124. package/dist-cli/chunks/{logout-HZQKLNUJ.js → logout-2FCOVLBC.js} +2 -2
  125. package/dist-cli/chunks/{maestro-XSS2KX6L.js → maestro-HPSSEVJD.js} +3 -3
  126. package/dist-cli/chunks/{maestro-generate-DNDQX3JQ.js → maestro-generate-KQQ6JHMR.js} +5 -5
  127. package/dist-cli/chunks/{mode-LEVGOKI3.js → mode-SH7KRZET.js} +2 -2
  128. package/dist-cli/chunks/{optional-demo-registry-2XZIJNDG.js → optional-demo-registry-NAMCAVFX.js} +2 -2
  129. package/dist-cli/chunks/{perf-OKMAXDLB.js → perf-LWKAHXUL.js} +2 -2
  130. package/dist-cli/chunks/{permissions-VG5TBUTN.js → permissions-EZTKWTXV.js} +2 -2
  131. package/dist-cli/chunks/platform-KSOJIVN5.js +6 -0
  132. package/dist-cli/chunks/privacy-EJULWP7L.js +4 -0
  133. package/dist-cli/chunks/{record-BQYGZOMV.js → record-2IC7BAQN.js} +3 -3
  134. package/dist-cli/chunks/{report-issue-HCPZESWE.js → report-issue-MMX6HOQO.js} +2 -2
  135. package/dist-cli/chunks/reset-PKFZA4NC.js +4 -0
  136. package/dist-cli/chunks/resolve-target-AFKU3BRE.js +4 -0
  137. package/dist-cli/chunks/runtime-XHWWPOIN.js +4 -0
  138. package/dist-cli/chunks/{screenshot-command-DWEYPJE7.js → screenshot-command-JYUXDVSA.js} +3 -3
  139. package/dist-cli/chunks/{screenshot-layers-5GMBXLO7.js → screenshot-layers-OGRY6AA3.js} +2 -2
  140. package/dist-cli/chunks/{screenshots-capture-5KCI7IZD.js → screenshots-capture-QHDN65XS.js} +2 -2
  141. package/dist-cli/chunks/{serve-QNKTA2HR.js → serve-W4BKAG4J.js} +3 -3
  142. package/dist-cli/chunks/setup-WJPMPSAC.js +4 -0
  143. package/dist-cli/chunks/sim-client-UOQGFBPO.js +4 -0
  144. package/dist-cli/chunks/{skills-DOEALD3X.js → skills-OPPXOD63.js} +2 -2
  145. package/dist-cli/chunks/state-TDAN7BOM.js +14 -0
  146. package/dist-cli/chunks/{storage-E7WUWN3E.js → storage-CFB2YGLY.js} +2 -2
  147. package/dist-cli/chunks/store-4TEED4ZU.js +4 -0
  148. package/dist-cli/chunks/telemetry-S6N7CV6G.js +4 -0
  149. package/dist-cli/chunks/{timeline-IKNUGQ2A.js → timeline-ASOOVP4C.js} +2 -2
  150. package/dist-cli/chunks/{upgrade-VS3OKXE2.js → upgrade-6MVJISHG.js} +2 -2
  151. package/dist-cli/chunks/upload-CBNIRFEW.js +4 -0
  152. package/dist-cli/chunks/{version-F4XHNTBZ.js → version-5GS7CWRL.js} +2 -2
  153. package/dist-cli/chunks/{web-F72724QL.js → web-QRRMYMV4.js} +2 -2
  154. package/dist-cli/chunks/welcome-33FXMAMB.js +5 -0
  155. package/dist-cli/chunks/{what-happened-APK7YKOV.js → what-happened-GAZJGKXX.js} +2 -2
  156. package/dist-cli/chunks/ws-bridge-DIXUAPLQ.js +4 -0
  157. package/dist-lib/agent-daemon-client.cjs +1 -1
  158. package/dist-lib/agent-events.cjs +1 -1
  159. package/dist-lib/agent-identity.cjs +1 -1
  160. package/dist-lib/agent-sessions.cjs +1 -1
  161. package/dist-lib/attached-projects.cjs +1 -1
  162. package/dist-lib/auth/shared-session.cjs +1 -1
  163. package/dist-lib/backend-origin.cjs +1 -1
  164. package/dist-lib/beta.cjs +1 -1
  165. package/dist-lib/beta.mjs +1 -1
  166. package/dist-lib/bridge-constants.cjs +1 -1
  167. package/dist-lib/bridge-contract-input.cjs +336 -0
  168. package/dist-lib/bridge-contract-input.mjs +303 -0
  169. package/dist-lib/bridge-contract.cjs +29 -1
  170. package/dist-lib/bridge-contract.mjs +19 -0
  171. package/dist-lib/cli-constants.cjs +1 -1
  172. package/dist-lib/config.cjs +1 -1
  173. package/dist-lib/detox/index.cjs +35 -19
  174. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  175. package/dist-lib/home-paths.cjs +1 -1
  176. package/dist-lib/host/bridge-host.cjs +5 -1
  177. package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
  178. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  179. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  180. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  181. package/dist-lib/host/websocket-proxy.cjs +1 -1
  182. package/dist-lib/index.cjs +244 -594
  183. package/dist-lib/jump-to-source-babel.cjs +1 -1
  184. package/dist-lib/menu.cjs +1 -1
  185. package/dist-lib/menu.mjs +1 -1
  186. package/dist-lib/metro-production-bundle.cjs +1 -1
  187. package/dist-lib/metro-production-bundle.mjs +1 -1
  188. package/dist-lib/metro.cjs +1 -1
  189. package/dist-lib/profiles.cjs +1 -1
  190. package/dist-lib/public-brand.cjs +1 -1
  191. package/dist-lib/react-native-host-modules.cjs +1 -1
  192. package/dist-lib/react-native-host-modules.mjs +1 -1
  193. package/dist-lib/render-mode.cjs +1 -1
  194. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  195. package/dist-lib/sdk.cjs +303 -657
  196. package/dist-lib/sdk.mjs +301 -652
  197. package/dist-lib/skills.cjs +256 -339
  198. package/dist-lib/vite.cjs +1 -1
  199. package/package.json +10 -1
  200. package/skills/contrast/SKILL.md +3 -0
  201. package/skills/rnx-debug/SKILL.md +8 -0
  202. package/skills/rnx-test/SKILL.md +21 -0
  203. package/src/app-url.ts +40 -0
  204. package/src/bridge-contract-input.ts +359 -0
  205. package/src/bridge-contract.ts +121 -1
  206. package/src/host/bridge-host.ts +7 -12
  207. package/src/index.ts +7 -0
  208. package/src/sim-client.ts +24 -9
  209. package/dist-cli/chunks/chunk-2JFZ5Z7Q.js +0 -4
  210. package/dist-cli/chunks/chunk-4WFN4DFR.js +0 -5
  211. package/dist-cli/chunks/chunk-52ES4API.js +0 -38
  212. package/dist-cli/chunks/chunk-622E4JET.js +0 -767
  213. package/dist-cli/chunks/chunk-EFL2ASZO.js +0 -124
  214. package/dist-cli/chunks/chunk-IWPS3EKJ.js +0 -15
  215. package/dist-cli/chunks/chunk-MCHKBFUL.js +0 -4
  216. package/dist-cli/chunks/chunk-OSZ5HZSI.js +0 -24
  217. package/dist-cli/chunks/chunk-W3UIDI3W.js +0 -5
  218. package/dist-cli/chunks/chunk-XKRUNS7A.js +0 -32
  219. package/dist-cli/chunks/chunk-YE3M3YD4.js +0 -944
  220. package/dist-cli/chunks/chunk-ZCP4CRP6.js +0 -4
  221. package/dist-cli/chunks/chunk-ZGD7GZRI.js +0 -4
  222. package/dist-cli/chunks/chunk-ZGH5U4AJ.js +0 -27
  223. package/dist-cli/chunks/cli-version-ZM3PVKQ5.js +0 -4
  224. package/dist-cli/chunks/control-4QR43FXV.js +0 -4
  225. package/dist-cli/chunks/daemon-2U4CJ6AT.js +0 -4
  226. package/dist-cli/chunks/detox-RQ6FFSBS.js +0 -52
  227. package/dist-cli/chunks/drivers-OVCUPQTM.js +0 -4
  228. package/dist-cli/chunks/flow-ELTLKKZ3.js +0 -4
  229. package/dist-cli/chunks/help-CDEZAG2L.js +0 -4
  230. package/dist-cli/chunks/inspect-VVQRPJLS.js +0 -4
  231. package/dist-cli/chunks/install-desktop-YXSRKR35.js +0 -4
  232. package/dist-cli/chunks/privacy-MNRHREME.js +0 -4
  233. package/dist-cli/chunks/reset-R4E4W4YI.js +0 -4
  234. package/dist-cli/chunks/runtime-XRQZ7W34.js +0 -4
  235. package/dist-cli/chunks/setup-RNMM5GO5.js +0 -4
  236. package/dist-cli/chunks/state-3HH2IHIF.js +0 -14
  237. package/dist-cli/chunks/store-HUPZUCFG.js +0 -4
  238. package/dist-cli/chunks/telemetry-IJ53XR2Y.js +0 -4
  239. package/dist-cli/chunks/upload-A57NAAHF.js +0 -4
  240. package/dist-cli/chunks/welcome-B72RRMBW.js +0 -5
@@ -0,0 +1,412 @@
1
+ import { BridgeInputError } from '../../src/bridge-contract-input'
2
+ import type { SimPerformStep } from '../../src/sim-client'
3
+
4
+ interface TargetedDoubleTapAction {
5
+ type: 'targetedDoubleTap'
6
+ id: string
7
+ gapMs: number
8
+ }
9
+
10
+ interface TargetedLongPressAction {
11
+ type: 'targetedLongPress'
12
+ id: string
13
+ durationMs: number
14
+ }
15
+
16
+ export type DoChainAction =
17
+ | SimPerformStep
18
+ | TargetedDoubleTapAction
19
+ | TargetedLongPressAction
20
+
21
+ const DO_CHAIN_ACTIONS = new Set([
22
+ 'tap',
23
+ 'tap-id',
24
+ 'tap-text',
25
+ 'double-tap',
26
+ 'long-press',
27
+ 'type',
28
+ 'type-into',
29
+ 'key',
30
+ 'key-sequence',
31
+ 'dismiss',
32
+ 'scroll',
33
+ 'drag',
34
+ 'swipe',
35
+ 'pinch',
36
+ 'touch',
37
+ 'sleep',
38
+ ])
39
+
40
+ export function hasDoChain(args: string[]): boolean {
41
+ return args.includes('--then')
42
+ }
43
+
44
+ function invalidAction(index: number, usage: string): never {
45
+ throw new BridgeInputError(
46
+ `do chain action ${index + 1} has invalid arguments; usage: rnx do ${usage}`,
47
+ )
48
+ }
49
+
50
+ function finiteNumber(value: string | undefined, index: number, usage: string): number {
51
+ const parsed = Number(value)
52
+ if (value === undefined || !Number.isFinite(parsed)) invalidAction(index, usage)
53
+ return parsed
54
+ }
55
+
56
+ export function parseDoChainActions(args: string[]): DoChainAction[] {
57
+ const segments: string[][] = [[]]
58
+ for (const argument of args) {
59
+ if (argument !== '--then') {
60
+ segments[segments.length - 1].push(argument)
61
+ continue
62
+ }
63
+ if (segments[segments.length - 1].length === 0) {
64
+ throw new BridgeInputError('do chain contains an empty action')
65
+ }
66
+ segments.push([])
67
+ }
68
+ if (segments.length < 2) {
69
+ throw new BridgeInputError('do chain needs at least two actions separated by --then')
70
+ }
71
+ if (segments[segments.length - 1].length === 0) {
72
+ throw new BridgeInputError('do chain cannot end with --then')
73
+ }
74
+
75
+ return segments.flatMap((segment, index): DoChainAction[] => {
76
+ const [action, ...values] = segment
77
+ if (!action) throw new BridgeInputError('do chain contains an empty action')
78
+ if (!DO_CHAIN_ACTIONS.has(action)) {
79
+ throw new BridgeInputError(
80
+ `do chain action ${index + 1} cannot batch ${JSON.stringify(action)}; run it as a separate rnx do command`,
81
+ )
82
+ }
83
+
84
+ switch (action) {
85
+ case 'tap': {
86
+ if (values.length === 1 && !Number.isFinite(Number(values[0]))) {
87
+ return [{ type: 'tapId', id: values[0] }]
88
+ }
89
+ if (values.length !== 2) invalidAction(index, 'tap <testid> | <x> <y>')
90
+ return [
91
+ {
92
+ type: 'tap',
93
+ x: finiteNumber(values[0], index, 'tap <testid> | <x> <y>'),
94
+ y: finiteNumber(values[1], index, 'tap <testid> | <x> <y>'),
95
+ },
96
+ ]
97
+ }
98
+
99
+ case 'tap-id':
100
+ if (values.length !== 1) invalidAction(index, 'tap-id <id>')
101
+ return [{ type: 'tapId', id: values[0] }]
102
+
103
+ case 'tap-text': {
104
+ const text = values.join(' ')
105
+ if (!text) invalidAction(index, 'tap-text <text>')
106
+ return [{ type: 'tapText', text }]
107
+ }
108
+
109
+ case 'double-tap': {
110
+ const usage = 'double-tap <testid> [gapMs] | <x> <y> [gapMs]'
111
+ if (values.length > 0 && !Number.isFinite(Number(values[0]))) {
112
+ if (values.length > 2) invalidAction(index, usage)
113
+ return [
114
+ {
115
+ type: 'targetedDoubleTap',
116
+ id: values[0],
117
+ gapMs:
118
+ values.length === 2
119
+ ? Math.max(0, Math.round(finiteNumber(values[1], index, usage)))
120
+ : 80,
121
+ },
122
+ ]
123
+ }
124
+ if (values.length < 2 || values.length > 3) invalidAction(index, usage)
125
+ return [
126
+ {
127
+ type: 'doubleTap',
128
+ x: finiteNumber(values[0], index, usage),
129
+ y: finiteNumber(values[1], index, usage),
130
+ gapMs:
131
+ values.length === 3
132
+ ? Math.max(0, Math.round(finiteNumber(values[2], index, usage)))
133
+ : 80,
134
+ },
135
+ ]
136
+ }
137
+
138
+ case 'long-press': {
139
+ const usage = 'long-press <testid> [durationMs] | <x> <y> [durationMs]'
140
+ if (values.length > 0 && !Number.isFinite(Number(values[0]))) {
141
+ if (values.length > 2) invalidAction(index, usage)
142
+ return [
143
+ {
144
+ type: 'targetedLongPress',
145
+ id: values[0],
146
+ durationMs:
147
+ values.length === 2
148
+ ? Math.max(0, Math.round(finiteNumber(values[1], index, usage)))
149
+ : 600,
150
+ },
151
+ ]
152
+ }
153
+ if (values.length < 2 || values.length > 3) invalidAction(index, usage)
154
+ return [
155
+ {
156
+ type: 'longPress',
157
+ x: finiteNumber(values[0], index, usage),
158
+ y: finiteNumber(values[1], index, usage),
159
+ durationMs:
160
+ values.length === 3
161
+ ? Math.max(0, Math.round(finiteNumber(values[2], index, usage)))
162
+ : 600,
163
+ },
164
+ ]
165
+ }
166
+
167
+ case 'type': {
168
+ const text = values.join(' ')
169
+ if (!text) invalidAction(index, 'type <text>')
170
+ return [{ type: 'type', text }]
171
+ }
172
+
173
+ case 'type-into': {
174
+ const text = values.slice(1).join(' ')
175
+ if (!values[0] || !text) invalidAction(index, 'type-into <id> <text>')
176
+ return [
177
+ { type: 'tapId', id: values[0] },
178
+ { type: 'type', text },
179
+ ]
180
+ }
181
+
182
+ case 'key':
183
+ if (values.length !== 1) invalidAction(index, 'key <name>')
184
+ return [{ type: 'key', key: values[0] }]
185
+
186
+ case 'key-sequence':
187
+ if (values.length === 0) invalidAction(index, 'key-sequence <key> [<key> ...]')
188
+ return values.map((key) => ({ type: 'key', key }))
189
+
190
+ case 'dismiss':
191
+ if (values.length !== 0) invalidAction(index, 'dismiss')
192
+ return [{ type: 'dismissKeyboard' }]
193
+
194
+ case 'scroll': {
195
+ const usage = 'scroll <id> <x> <y>'
196
+ if (values.length !== 3) invalidAction(index, usage)
197
+ return [
198
+ {
199
+ type: 'scroll',
200
+ id: values[0],
201
+ x: finiteNumber(values[1], index, usage),
202
+ y: finiteNumber(values[2], index, usage),
203
+ animated: false,
204
+ },
205
+ ]
206
+ }
207
+
208
+ case 'drag':
209
+ case 'swipe': {
210
+ const usage = `${action} <x1> <y1> <x2> <y2> [steps] [stepMs]`
211
+ if (values.length < 4 || values.length > 6) invalidAction(index, usage)
212
+ const defaultSteps = action === 'swipe' ? 10 : 12
213
+ const defaultStepMs = action === 'swipe' ? 8 : 16
214
+ return [
215
+ {
216
+ type: 'drag',
217
+ fromX: finiteNumber(values[0], index, usage),
218
+ fromY: finiteNumber(values[1], index, usage),
219
+ toX: finiteNumber(values[2], index, usage),
220
+ toY: finiteNumber(values[3], index, usage),
221
+ steps:
222
+ values.length >= 5
223
+ ? Math.max(1, Math.round(finiteNumber(values[4], index, usage)))
224
+ : defaultSteps,
225
+ stepMs:
226
+ values.length === 6
227
+ ? Math.max(0, Math.round(finiteNumber(values[5], index, usage)))
228
+ : defaultStepMs,
229
+ },
230
+ ]
231
+ }
232
+
233
+ case 'pinch': {
234
+ const usage = "pinch <x1> <y1> <x2> <y2> <x1'> <y1'> <x2'> <y2'> [steps] [stepMs]"
235
+ if (values.length < 8 || values.length > 10) invalidAction(index, usage)
236
+ return [
237
+ {
238
+ type: 'pinch',
239
+ fromX1: finiteNumber(values[0], index, usage),
240
+ fromY1: finiteNumber(values[1], index, usage),
241
+ fromX2: finiteNumber(values[2], index, usage),
242
+ fromY2: finiteNumber(values[3], index, usage),
243
+ toX1: finiteNumber(values[4], index, usage),
244
+ toY1: finiteNumber(values[5], index, usage),
245
+ toX2: finiteNumber(values[6], index, usage),
246
+ toY2: finiteNumber(values[7], index, usage),
247
+ steps:
248
+ values.length >= 9
249
+ ? Math.max(1, Math.round(finiteNumber(values[8], index, usage)))
250
+ : 12,
251
+ stepMs:
252
+ values.length === 10
253
+ ? Math.max(0, Math.round(finiteNumber(values[9], index, usage)))
254
+ : 16,
255
+ },
256
+ ]
257
+ }
258
+
259
+ case 'touch': {
260
+ const usage = 'touch <down|move|up|cancel> <x> <y> [pointerId]'
261
+ if (values.length < 3 || values.length > 4) invalidAction(index, usage)
262
+ const phase = values[0]
263
+ if (
264
+ phase !== 'down' &&
265
+ phase !== 'move' &&
266
+ phase !== 'up' &&
267
+ phase !== 'cancel'
268
+ ) {
269
+ invalidAction(index, usage)
270
+ }
271
+ const pointerId =
272
+ values.length === 4
273
+ ? Math.max(1, Math.round(finiteNumber(values[3], index, usage)))
274
+ : 999
275
+ if (phase === 'cancel') return [{ type: 'touchCancel', pointerId }]
276
+ return [
277
+ {
278
+ type:
279
+ phase === 'down' ? 'touchDown' : phase === 'move' ? 'touchMove' : 'touchUp',
280
+ x: finiteNumber(values[1], index, usage),
281
+ y: finiteNumber(values[2], index, usage),
282
+ pointerId,
283
+ },
284
+ ]
285
+ }
286
+
287
+ case 'sleep': {
288
+ const usage = 'sleep [seconds]'
289
+ if (values.length > 1) invalidAction(index, usage)
290
+ const seconds = values.length === 1 ? finiteNumber(values[0], index, usage) : 0.5
291
+ if (seconds < 0) invalidAction(index, usage)
292
+ return [{ type: 'wait', ms: Math.round(seconds * 1000) }]
293
+ }
294
+
295
+ default:
296
+ throw new BridgeInputError(
297
+ `do chain action ${index + 1} cannot batch ${JSON.stringify(action)}`,
298
+ )
299
+ }
300
+ })
301
+ }
302
+
303
+ export async function runDoChain(
304
+ args: string[],
305
+ opts: { port?: number } = {},
306
+ ): Promise<number> {
307
+ const [connectModule, simClientModule, bridgeModule, envModule, targetModule] =
308
+ await Promise.all([
309
+ import('../../src/connect'),
310
+ import('../../src/sim-client'),
311
+ import('../ws-bridge'),
312
+ import('./inspect/env'),
313
+ import('./inspect/resolve-target'),
314
+ ])
315
+ const { connect } = connectModule
316
+ const { SimPerformError } = simClientModule
317
+ const { checkSimHealth, parseBridgeCliArgs } = bridgeModule
318
+ const { isAgentEnv } = envModule
319
+ const { resolveTargetCoords } = targetModule
320
+ const wantsJson = args.includes('--json')
321
+ const skipSettle =
322
+ args.includes('--no-wait') || process.env.SOOTSIM_NO_AUTO_WAIT === '1'
323
+ const parsed = parseBridgeCliArgs(args, {
324
+ port: opts.port,
325
+ commandTimeoutMs: 30_000,
326
+ stripBooleanFlags: ['--json', '--no-wait'],
327
+ })
328
+ if (!Number.isFinite(parsed.commandTimeoutMs) || parsed.commandTimeoutMs <= 0) {
329
+ console.error(' do chain: --timeout must be a positive number')
330
+ return 1
331
+ }
332
+
333
+ let actions: DoChainAction[]
334
+ try {
335
+ actions = parseDoChainActions(parsed.positional)
336
+ } catch (error) {
337
+ console.error(` do chain: ${error instanceof Error ? error.message : error}`)
338
+ return 1
339
+ }
340
+
341
+ let sim: Awaited<ReturnType<typeof connect>> | null = null
342
+ try {
343
+ sim = await connect({
344
+ port: parsed.wsPort,
345
+ sim: parsed.simId,
346
+ timeoutMs: parsed.commandTimeoutMs,
347
+ })
348
+ await checkSimHealth(sim)
349
+
350
+ const steps: SimPerformStep[] = []
351
+ for (const action of actions) {
352
+ if (action.type !== 'targetedDoubleTap' && action.type !== 'targetedLongPress') {
353
+ steps.push(action)
354
+ continue
355
+ }
356
+ const target = await resolveTargetCoords(sim, { mode: 'testid', value: action.id })
357
+ if (!target) {
358
+ throw new BridgeInputError(
359
+ `do chain could not find testID ${JSON.stringify(action.id)}`,
360
+ )
361
+ }
362
+ steps.push(
363
+ action.type === 'targetedDoubleTap'
364
+ ? {
365
+ type: 'doubleTap',
366
+ x: target.x,
367
+ y: target.y,
368
+ gapMs: action.gapMs,
369
+ }
370
+ : {
371
+ type: 'longPress',
372
+ x: target.x,
373
+ y: target.y,
374
+ durationMs: action.durationMs,
375
+ },
376
+ )
377
+ }
378
+
379
+ const result = await sim.perform(steps, { timeoutMs: parsed.commandTimeoutMs })
380
+ if (!skipSettle) {
381
+ try {
382
+ const budgetMs = isAgentEnv() ? 400 : 200
383
+ const settled = await sim.settle({ maxMs: budgetMs })
384
+ if (!settled.settled) {
385
+ process.stderr.write(
386
+ ` ⚠ auto-wait timed out after ${settled.elapsed ?? budgetMs}ms. next command may see mid-animation state. use \`rnx do settle\` for a longer wait.\n`,
387
+ )
388
+ }
389
+ } catch {}
390
+ }
391
+
392
+ if (wantsJson) {
393
+ console.log(JSON.stringify(result))
394
+ } else {
395
+ console.log(
396
+ ` completed ${result.completed} batched ${result.completed === 1 ? 'step' : 'steps'} in ${result.durationMs}ms`,
397
+ )
398
+ }
399
+ return 0
400
+ } catch (error) {
401
+ if (error instanceof SimPerformError && wantsJson) {
402
+ console.log(JSON.stringify(error.result))
403
+ } else {
404
+ console.error(
405
+ ` do chain failed: ${error instanceof Error ? error.message : error}`,
406
+ )
407
+ }
408
+ return 1
409
+ } finally {
410
+ sim?.close()
411
+ }
412
+ }
@@ -456,16 +456,6 @@ flow extension:
456
456
  })
457
457
  }
458
458
  if (!targetDevice) return false
459
- const currentUrl = await bridge.send({
460
- type: 'evaluate',
461
- simId: driver.simId,
462
- code: 'window.location.href',
463
- })
464
- if (typeof currentUrl === 'string' && currentUrl.length > 0) {
465
- const nextUrl = new URL(currentUrl)
466
- nextUrl.searchParams.set('device', targetDevice)
467
- driver.setSimRouteHint(nextUrl.toString())
468
- }
469
459
  return Boolean(
470
460
  await bridge.send({
471
461
  type: 'call',
@@ -494,7 +484,8 @@ flow extension:
494
484
  requireRecordingEntitlement: preview,
495
485
  // re-arm the event recorder after every launchApp-with-reload. the
496
486
  // recorder lives in-page state and gets wiped by window.location.reload.
497
- onAfterLaunch: async () => {
487
+ onAfterLaunch: async (simId) => {
488
+ if (simId) saveCurrentSimId(simId)
498
489
  const deviceChanged = await applyFlowFrontmatter()
499
490
  if (deviceChanged) await driver.waitForTree(120000)
500
491
  if (!preview) return