agent-device 0.20.10 → 0.21.1

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 (510) hide show
  1. package/README.md +2 -2
  2. package/android/ime-helper/dist/{agent-device-android-ime-helper-0.20.10.apk → agent-device-android-ime-helper-0.21.1.apk} +0 -0
  3. package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.1.apk.sha256 +1 -0
  4. package/android/ime-helper/dist/{agent-device-android-ime-helper-0.20.10.manifest.json → agent-device-android-ime-helper-0.21.1.manifest.json} +4 -4
  5. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.1.apk +0 -0
  6. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.1.apk.sha256 +1 -0
  7. package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.20.10.manifest.json → agent-device-android-snapshot-helper-0.21.1.manifest.json} +6 -6
  8. package/apple/macos-helper/Sources/AgentDeviceMacOSHelper/AudioProbe.swift +35 -33
  9. package/apple/macos-helper/Sources/AgentDeviceMacOSHelper/main.swift +6 -1
  10. package/apple/snapshot-bridge/LICENSE.idb +23 -0
  11. package/apple/snapshot-bridge/README.md +106 -0
  12. package/apple/snapshot-bridge/SnapshotBridge.m +286 -0
  13. package/apple/snapshot-bridge/SnapshotBridgeCapture.h +25 -0
  14. package/apple/snapshot-bridge/SnapshotBridgeCapture.m +138 -0
  15. package/apple/snapshot-bridge/SnapshotBridgeRuntime.h +34 -0
  16. package/apple/snapshot-bridge/SnapshotBridgeRuntime.m +411 -0
  17. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerApp.m +58 -0
  18. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunner.xcodeproj/project.pbxproj +19 -0
  19. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAXSnapshotBridge.h +12 -0
  20. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAXSnapshotBridge.m +20 -0
  21. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAlertVerification.swift +36 -0
  22. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSelectorMatchPolicy.swift +15 -15
  23. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerStringNormalization.swift +8 -0
  24. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.h +12 -1
  25. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.m +100 -6
  26. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSystemSurfaceHostPolicy.swift +72 -0
  27. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTapPointPolicy.swift +63 -14
  28. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AXSnapshotFallback.swift +677 -83
  29. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Alert.swift +35 -92
  30. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AlertObservation.swift +124 -0
  31. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+BlockingSystemModalResolution.swift +39 -4
  32. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +1058 -213
  33. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandJournal.swift +296 -14
  34. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Environment.swift +1 -1
  35. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Exceptions.swift +10 -10
  36. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +309 -149
  37. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Keyboard.swift +101 -42
  38. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Lifecycle.swift +24 -17
  39. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +124 -199
  40. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Navigation.swift +71 -4
  41. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+PrivateAXElementTypes.swift +12 -0
  42. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+PrivateAXPresentation.swift +211 -78
  43. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScreenRecorder.swift +30 -10
  44. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScrollGesture.swift +254 -24
  45. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SequenceExecution.swift +206 -22
  46. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift +465 -494
  47. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotBackendCapabilities.swift +168 -0
  48. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotCapturePlan.swift +802 -247
  49. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotPresentationInvariant.swift +19 -0
  50. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotTiming.swift +185 -0
  51. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedCommitDeadline.swift +206 -0
  52. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedGesturePolicy.swift +83 -5
  53. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedTextEntry.swift +156 -34
  54. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SystemModal.swift +5 -4
  55. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntry.swift +35 -318
  56. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryFocus.swift +206 -0
  57. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryReadiness.swift +158 -0
  58. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextInputCandidatePolicy.swift +28 -0
  59. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextInputProbe.swift +101 -0
  60. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextTyping.swift +56 -23
  61. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Transport.swift +56 -27
  62. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TvRemote.swift +30 -24
  63. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +126 -80
  64. package/dist/apple/runner/AgentDeviceRunner/RecordingScripts/RecordingExportSupport.swift +111 -0
  65. package/dist/apple/runner/AgentDeviceRunner/RecordingScripts/recording-overlay.swift +47 -86
  66. package/dist/apple/runner/AgentDeviceRunner/RecordingScripts/recording-trim.swift +32 -79
  67. package/dist/apple/snapshot-presentation/Package.swift +21 -0
  68. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotGeometry.swift +56 -0
  69. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotModels.swift +259 -0
  70. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotPresentation.swift +153 -0
  71. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotPresentationFailure.swift +27 -0
  72. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotPresentationInvariant.swift +91 -0
  73. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotPresentationProjection.swift +161 -0
  74. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotScopePolicy.swift +53 -0
  75. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotVisibilityFold.swift +242 -0
  76. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotVisibilityFoldProjection.swift +97 -0
  77. package/dist/src/adapter.js +1 -0
  78. package/dist/src/adb-executor.js +2 -0
  79. package/dist/src/adb-failure.js +1 -0
  80. package/dist/src/adb-host.js +1 -0
  81. package/dist/src/adb.js +1 -0
  82. package/dist/src/agent-browser-lifecycle.js +1 -0
  83. package/dist/src/agent-browser-process-record.js +1 -0
  84. package/dist/src/agent-browser-provider.js +1 -0
  85. package/dist/src/agent-browser-tool.js +1 -1
  86. package/dist/src/agent-device-client.js +2 -2
  87. package/dist/src/ai-sdk.d.ts +2 -2
  88. package/dist/src/ai-sdk.js +1 -1
  89. package/dist/src/alert-contract.js +1 -0
  90. package/dist/src/alert-runtime.js +1 -0
  91. package/dist/src/android-adb.d.ts +27 -19
  92. package/dist/src/android-adb.js +1 -1
  93. package/dist/src/android-input-ownership.js +1 -0
  94. package/dist/src/android-system-chrome.js +1 -0
  95. package/dist/src/android.js +1 -1
  96. package/dist/src/api.js +11 -0
  97. package/dist/src/app-catalog.js +1 -0
  98. package/dist/src/app-deployment-resolution.js +2 -0
  99. package/dist/src/app-helpers.js +1 -1
  100. package/dist/src/app-inventory-contract.js +1 -0
  101. package/dist/src/app-inventory.js +1 -0
  102. package/dist/src/app-launch.js +2 -0
  103. package/dist/src/app-lifecycle-facade.js +1 -0
  104. package/dist/src/app-lifecycle.js +3 -6
  105. package/dist/src/app-lifecycle2.js +2 -2
  106. package/dist/src/app-lifecycle3.js +1 -0
  107. package/dist/src/app-log-files.js +1 -1
  108. package/dist/src/app-log-reconnect.js +1 -1
  109. package/dist/src/app-log-runtime.js +1 -4
  110. package/dist/src/app-log-runtime2.js +4 -0
  111. package/dist/src/app-parsers.js +4 -0
  112. package/dist/src/app-resolution-cache.js +1 -0
  113. package/dist/src/app-resolution-facade.js +1 -0
  114. package/dist/src/app-resolution.js +2 -2
  115. package/dist/src/app-state.js +1 -2
  116. package/dist/src/apple-runner-platform.js +1 -0
  117. package/dist/src/application-lifecycle-interaction.js +1 -0
  118. package/dist/src/application-lifecycle-runtime.js +1 -0
  119. package/dist/src/apps-simctl.js +1 -0
  120. package/dist/src/archive.js +4 -0
  121. package/dist/src/artifact-download.js +1 -0
  122. package/dist/src/artifacts.d.ts +6 -2
  123. package/dist/src/artifacts.js +1 -1
  124. package/dist/src/async-lifecycle.js +1 -0
  125. package/dist/src/audio-probe-result.js +1 -0
  126. package/dist/src/audio-probe-runtime.js +1 -0
  127. package/dist/src/audio-probe-support.js +1 -0
  128. package/dist/src/auth-session.js +1 -1
  129. package/dist/src/auth.js +1 -1
  130. package/dist/src/backend-snapshot-options.js +1 -1
  131. package/dist/src/{url.js → base-url.js} +1 -1
  132. package/dist/src/boot-diagnostics.js +2 -2
  133. package/dist/src/byte-limit-stream.js +1 -1
  134. package/dist/src/capabilities.js +1 -0
  135. package/dist/src/capture.js +1 -0
  136. package/dist/src/catalog.js +1 -0
  137. package/dist/src/cli-command-aliases.js +1 -0
  138. package/dist/src/cli-config.js +1 -1
  139. package/dist/src/cli-help.js +74 -51
  140. package/dist/src/cli-output.js +1 -1
  141. package/dist/src/cli-runner.js +1 -1
  142. package/dist/src/cli.js +4 -6
  143. package/dist/src/click-button.js +1 -0
  144. package/dist/src/client-metro-companion.js +1 -0
  145. package/dist/src/client-metro.js +1 -1
  146. package/dist/src/client-types.d.ts +280 -242
  147. package/dist/src/clipboard.js +1 -0
  148. package/dist/src/code-signature-cache.js +1 -0
  149. package/dist/src/code-signature.js +1 -0
  150. package/dist/src/color.js +1 -0
  151. package/dist/src/command-metadata.js +1 -1
  152. package/dist/src/command-schema.js +3 -3
  153. package/dist/src/command-surface.js +1 -1
  154. package/dist/src/command-tools.js +2 -2
  155. package/dist/src/command.js +1 -0
  156. package/dist/src/compatibility-policy.js +1 -0
  157. package/dist/src/config.js +1 -1
  158. package/dist/src/config2.js +1 -0
  159. package/dist/src/connection-runtime.js +1 -1
  160. package/dist/src/connection.js +5 -5
  161. package/dist/src/contracts.d.ts +1 -1
  162. package/dist/src/contracts.js +1 -1
  163. package/dist/src/daemon-client-lifecycle.js +1 -0
  164. package/dist/src/daemon-process.js +1 -0
  165. package/dist/src/daemon-registration.js +1 -0
  166. package/dist/src/daemon-shutdown-report.js +1 -1
  167. package/dist/src/daemon.js +2 -2
  168. package/dist/src/debug-symbols-facade.js +5 -0
  169. package/dist/src/deploy-result-target.js +1 -0
  170. package/dist/src/device-claim-inspection.js +1 -1
  171. package/dist/src/device-claim-rule.js +1 -0
  172. package/dist/src/device-input-state.d.ts +190 -3
  173. package/dist/src/device-inventory-context.js +1 -0
  174. package/dist/src/device-isolation.js +1 -0
  175. package/dist/src/device-release.js +1 -0
  176. package/dist/src/device-rotation.js +1 -0
  177. package/dist/src/device-selection-resolver.js +1 -0
  178. package/dist/src/device-session.js +1 -0
  179. package/dist/src/device.js +1 -1
  180. package/dist/src/device2.js +3 -2
  181. package/dist/src/diagnostics.js +3 -0
  182. package/dist/src/diagnostics2.js +1 -0
  183. package/dist/src/dispatch-resolve.js +1 -0
  184. package/dist/src/doctor-facade.js +1 -0
  185. package/dist/src/doctor-output.js +1 -0
  186. package/dist/src/doctor.js +1 -0
  187. package/dist/src/doctor2.js +1 -0
  188. package/dist/src/doctor3.js +1 -0
  189. package/dist/src/durable-resource.js +1 -0
  190. package/dist/src/entities.js +1 -1
  191. package/dist/src/error.js +2 -0
  192. package/dist/src/exec.js +1 -0
  193. package/dist/src/file.js +1 -0
  194. package/dist/src/find.js +1 -1
  195. package/dist/src/finders.js +1 -1
  196. package/dist/src/generic-settle.js +1 -1
  197. package/dist/src/generic.js +1 -1
  198. package/dist/src/gesture-admission.js +1 -0
  199. package/dist/src/gesture-plan-types.js +1 -0
  200. package/dist/src/gesture-plan.js +1 -0
  201. package/dist/src/gesture-runtime.js +1 -0
  202. package/dist/src/harmonyos.js +1 -1
  203. package/dist/src/hdc.js +1 -1
  204. package/dist/src/helper.js +2 -2
  205. package/dist/src/host-file.js +1 -0
  206. package/dist/src/human-control-contract.js +1 -0
  207. package/dist/src/human-control.js +1 -0
  208. package/dist/src/index.d.ts +1 -1
  209. package/dist/src/index.js +1 -1
  210. package/dist/src/input-actions.js +1 -4
  211. package/dist/src/input-actions2.js +2 -1
  212. package/dist/src/install-artifact-facade.js +1 -0
  213. package/dist/src/install-source-network-transport.js +1 -0
  214. package/dist/src/install-source.d.ts +3 -10
  215. package/dist/src/install-source2.js +1 -1
  216. package/dist/src/interaction-positionals.js +1 -0
  217. package/dist/src/interaction-ref-policy.js +1 -0
  218. package/dist/src/interaction.js +1 -1
  219. package/dist/src/interaction2.js +1 -1
  220. package/dist/src/interactor-operation-catalog.js +1 -0
  221. package/dist/src/interactor-types.js +1 -0
  222. package/dist/src/interactor.js +6 -2
  223. package/dist/src/interactor2.js +1 -1
  224. package/dist/src/interactors.js +1 -1
  225. package/dist/src/internal/bin.d.ts +1 -1
  226. package/dist/src/internal/bin.js +1 -2
  227. package/dist/src/internal/companion-tunnel.d.ts +1 -1
  228. package/dist/src/internal/companion-tunnel.js +1 -1
  229. package/dist/src/internal/daemon.d.ts +1 -1
  230. package/dist/src/internal/daemon.js +2 -4
  231. package/dist/src/internal/png-worker.d.ts +4 -4
  232. package/dist/src/internal/png-worker.js +1 -1
  233. package/dist/src/internal/run-script-http-child.d.ts +4 -0
  234. package/dist/src/internal/run-script-http-child.js +1 -0
  235. package/dist/src/internal/update-check-entry.d.ts +1 -1
  236. package/dist/src/inventory.js +4 -4
  237. package/dist/src/inventory2.js +1 -1
  238. package/dist/src/inventory3.js +1 -1
  239. package/dist/src/inventory5.js +1 -1
  240. package/dist/src/inventory6.js +1 -1
  241. package/dist/src/ios-client.js +16 -0
  242. package/dist/src/ios-snapshot-acquisition.js +1 -0
  243. package/dist/src/ios-snapshot-adapter.js +1 -0
  244. package/dist/src/ios-snapshot-planning.js +1 -0
  245. package/dist/src/ios-snapshot-runtime.js +1 -0
  246. package/dist/src/ios-system-surface.js +1 -0
  247. package/dist/src/json.js +1 -0
  248. package/dist/src/keyboard-actions.js +1 -0
  249. package/dist/src/launch-console.js +1 -0
  250. package/dist/src/lease-context.js +1 -1
  251. package/dist/src/lease-scope.js +1 -0
  252. package/dist/src/lease.js +1 -1
  253. package/dist/src/limrun-runtime-dependencies.js +1 -1
  254. package/dist/src/limrun.d.ts +1610 -7
  255. package/dist/src/limrun.js +1 -1
  256. package/dist/src/linux.js +1 -1
  257. package/dist/src/local-interactor-operation-set.js +1 -0
  258. package/dist/src/location-coordinates.js +1 -1
  259. package/dist/src/logcat.js +1 -1
  260. package/dist/src/macos-facade.js +1 -0
  261. package/dist/src/managed-device-scope.js +1 -0
  262. package/dist/src/mechanics.js +19 -0
  263. package/dist/src/metro.d.ts +4 -2
  264. package/dist/src/metro.js +1 -1
  265. package/dist/src/metro2.js +1 -1
  266. package/dist/src/mobile-snapshot-semantics.js +1 -1
  267. package/dist/src/multitouch-support.js +1 -0
  268. package/dist/src/numeric.js +1 -0
  269. package/dist/src/observability.js +1 -1
  270. package/dist/src/observation.js +2 -0
  271. package/dist/src/open-target-resolution.js +1 -0
  272. package/dist/src/output-path.js +1 -1
  273. package/dist/src/owner-identity.js +3 -1
  274. package/dist/src/parameterized-recorded-fill.js +1 -0
  275. package/dist/src/parser.js +1 -1
  276. package/dist/src/perf-facade.js +2 -0
  277. package/dist/src/perf-process-identity.js +1 -0
  278. package/dist/src/perf-runtime-operation-builder.js +1 -0
  279. package/dist/src/perf-runtime-plan.js +1 -0
  280. package/dist/src/perf-runtime.js +1 -0
  281. package/dist/src/perf.js +1 -4
  282. package/dist/src/physical-device-control.js +1 -1
  283. package/dist/src/physical-device-facade.js +1 -0
  284. package/dist/src/platform-request-scope.js +1 -0
  285. package/dist/src/platform-runtime-android-adb-host.js +1 -0
  286. package/dist/src/platform-runtime-android-mechanics.js +1 -0
  287. package/dist/src/platform-runtime-app-log-android-transport.js +1 -1
  288. package/dist/src/platform-runtime-app-log-process.js +1 -1
  289. package/dist/src/platform-runtime-host.js +1 -1
  290. package/dist/src/platform-runtime-managed-owner.js +1 -0
  291. package/dist/src/platform-runtime-network-web-transport.js +1 -1
  292. package/dist/src/platform-runtime-open-target.js +1 -1
  293. package/dist/src/platform-runtime-operation-host.js +4 -4
  294. package/dist/src/platform-runtime-runtime-hints.js +2 -2
  295. package/dist/src/platform-runtime-screen-recording-android-host.js +1 -1
  296. package/dist/src/platform-runtime-screen-recording-apple-runner-host.js +1 -1
  297. package/dist/src/platform-runtime-screen-recording-apple-runner-transport.js +1 -1
  298. package/dist/src/platform-runtime-screen-recording-apple-simulator-host.js +1 -1
  299. package/dist/src/platform-runtime-screen-recording-apple-transport.js +1 -1
  300. package/dist/src/platform-runtime-screen-recording-finalizer-host.js +1 -1
  301. package/dist/src/platform-runtime-screen-recording-harmony-host.js +1 -1
  302. package/dist/src/platform-runtime-screen-recording-process-host.js +1 -0
  303. package/dist/src/platform-runtime-screen-recording-web-host.js +1 -1
  304. package/dist/src/platform-runtime-unavailable.js +1 -0
  305. package/dist/src/platform-runtime.js +1 -1
  306. package/dist/src/platform-runtime2.js +1 -1
  307. package/dist/src/plist.js +1 -1
  308. package/dist/src/png-worker-contract.js +1 -1
  309. package/dist/src/prepare-kind.js +1 -0
  310. package/dist/src/process-exit.js +1 -1
  311. package/dist/src/process.js +1 -0
  312. package/dist/src/provider-device-runtime.js +1 -0
  313. package/dist/src/provider-session-ownership.js +2 -0
  314. package/dist/src/provider-webdriver.js +1 -1
  315. package/dist/src/provider.js +1 -1
  316. package/dist/src/providers.js +1 -0
  317. package/dist/src/proxy.js +2 -2
  318. package/dist/src/react-native-overlay.js +1 -0
  319. package/dist/src/react-native.js +1 -1
  320. package/dist/src/record-runtime.js +1 -1
  321. package/dist/src/record-trace.js +1 -1
  322. package/dist/src/rect-center.js +1 -0
  323. package/dist/src/register-builtins.js +1 -0
  324. package/dist/src/registry.js +40 -28
  325. package/dist/src/remote-config2.js +1 -1
  326. package/dist/src/replay-divergence.js +2 -0
  327. package/dist/src/replay.js +2 -2
  328. package/dist/src/reporting.js +8 -7
  329. package/dist/src/request-admission.js +1 -0
  330. package/dist/src/request-cancel.js +1 -0
  331. package/dist/src/request-cancellation.js +1 -0
  332. package/dist/src/request-progress-protocol.js +1 -0
  333. package/dist/src/request-providers.js +1 -0
  334. package/dist/src/request-runtime-binding.js +1 -0
  335. package/dist/src/request.js +1 -0
  336. package/dist/src/result-serialization.js +1 -0
  337. package/dist/src/retry.js +1 -0
  338. package/dist/src/rolldown-runtime.js +1 -1
  339. package/dist/src/runner-cache-metadata.js +2 -0
  340. package/dist/src/runner-client.js +1 -1
  341. package/dist/src/runner-disposal.js +1 -1
  342. package/dist/src/runner-operations-facade.js +1 -0
  343. package/dist/src/runner-owner-facade.js +1 -0
  344. package/dist/src/runner-owner-state.js +1 -0
  345. package/dist/src/runner-presentation.js +1 -0
  346. package/dist/src/runner.js +1 -0
  347. package/dist/src/{runtime-transport.js → runtime-transport-hints.js} +1 -1
  348. package/dist/src/runtime.js +3 -3
  349. package/dist/src/runtime2.js +4 -4
  350. package/dist/src/runtime3.js +1 -1
  351. package/dist/src/runtime4.js +5 -3
  352. package/dist/src/runtime5.js +1 -1
  353. package/dist/src/runtime6.js +1 -1
  354. package/dist/src/runtime7.js +1 -1
  355. package/dist/src/runtime8.js +1 -1
  356. package/dist/src/runtime9.js +1 -1
  357. package/dist/src/scoped-provider.js +1 -1
  358. package/dist/src/screen-recording-completion.js +1 -0
  359. package/dist/src/screen-recording-live-handle.js +1 -0
  360. package/dist/src/screen-recording-options.js +1 -0
  361. package/dist/src/screen-recording-resource-recovery.js +1 -0
  362. package/dist/src/screen-recording-runtime.js +1 -0
  363. package/dist/src/screenshot-density.js +1 -1
  364. package/dist/src/screenshot-result.js +1 -6
  365. package/dist/src/screenshot-runtime.js +1 -0
  366. package/dist/src/screenshot.js +1 -1
  367. package/dist/src/screenshot2.js +1 -0
  368. package/dist/src/screenshot3.js +5 -0
  369. package/dist/src/script.js +1 -0
  370. package/dist/src/scroll-command.js +1 -0
  371. package/dist/src/scroll-gesture.js +1 -0
  372. package/dist/src/scroll-indicator.js +1 -0
  373. package/dist/src/sdk-batch-runner.d.ts +23 -6
  374. package/dist/src/sdk-batch-runner.js +2 -3
  375. package/dist/src/sdk-batch.js +2 -0
  376. package/dist/src/sdk-contracts.d.ts +170 -41
  377. package/dist/src/sdk-contracts.js +2 -2
  378. package/dist/src/sdk-device.js +1 -1
  379. package/dist/src/sdk-finders.d.ts +1 -1
  380. package/dist/src/sdk-finders.js +1 -1
  381. package/dist/src/sdk-io.js +1 -1
  382. package/dist/src/sdk-remote-config.d.ts +1 -1
  383. package/dist/src/sdk-remote-config.js +1 -1
  384. package/dist/src/sdk-selectors.d.ts +524 -140
  385. package/dist/src/sdk-selectors.js +1 -1
  386. package/dist/src/selection.js +1 -0
  387. package/dist/src/selector-runtime.js +1 -1
  388. package/dist/src/selectors.js +1 -1
  389. package/dist/src/semantic-index.js +1 -0
  390. package/dist/src/server.js +4 -4
  391. package/dist/src/session-allocation.js +1 -0
  392. package/dist/src/session-artifact-paths.js +1 -0
  393. package/dist/src/session-observation.js +1 -0
  394. package/dist/src/session-paths.js +1 -0
  395. package/dist/src/session-repair-tombstone.js +1 -0
  396. package/dist/src/session-routing.js +1 -0
  397. package/dist/src/session-runtime-admission.js +1 -0
  398. package/dist/src/session-snapshot.js +1 -0
  399. package/dist/src/session-store.js +4 -0
  400. package/dist/src/session-target-evidence.js +1 -1
  401. package/dist/src/session2.js +5 -27
  402. package/dist/src/settings.js +1 -0
  403. package/dist/src/shared.js +2 -2
  404. package/dist/src/simctl-facade.js +1 -0
  405. package/dist/src/simctl.js +1 -1
  406. package/dist/src/simulator-facade.js +1 -0
  407. package/dist/src/simulator.js +1 -1
  408. package/dist/src/snapshot-capture-annotations.js +1 -0
  409. package/dist/src/snapshot-desktop-projection.js +1 -0
  410. package/dist/src/snapshot-diagnostics.js +1 -0
  411. package/dist/src/snapshot-process.js +1 -0
  412. package/dist/src/snapshot-quality-backend-capabilities.js +1 -0
  413. package/dist/src/snapshot-quality-verdict.js +1 -0
  414. package/dist/src/snapshot-runtime-binding.js +1 -0
  415. package/dist/src/snapshot-runtime.js +1 -1
  416. package/dist/src/snapshot-scope.js +1 -1
  417. package/dist/src/snapshot-state.js +1 -0
  418. package/dist/src/snapshot.js +1 -8
  419. package/dist/src/snapshot2.js +1 -1
  420. package/dist/src/snapshot3.js +1 -1
  421. package/dist/src/snapshot4.js +1 -0
  422. package/dist/src/src.js +1 -1
  423. package/dist/src/src2.js +1 -1
  424. package/dist/src/src3.js +1 -2
  425. package/dist/src/src4.js +1 -1
  426. package/dist/src/src5.js +1 -0
  427. package/dist/src/src6.js +1 -0
  428. package/dist/src/src7.js +2 -0
  429. package/dist/src/src8.js +115 -0
  430. package/dist/src/startup-recovery-fence.js +1 -0
  431. package/dist/src/status-markers.js +1 -0
  432. package/dist/src/string-enum.js +1 -1
  433. package/dist/src/success-text.js +1 -0
  434. package/dist/src/surface-snapshot.js +1 -0
  435. package/dist/src/surface-snapshot2.js +1 -0
  436. package/dist/src/takeover.js +5 -0
  437. package/dist/src/tool-provider-facade.js +1 -0
  438. package/dist/src/tool-provider.js +4 -3
  439. package/dist/src/tool-provider2.js +1 -1
  440. package/dist/src/tool-provider3.js +1 -1
  441. package/dist/src/toolchain-probe.js +2 -0
  442. package/dist/src/touch-reference-frame.js +1 -0
  443. package/dist/src/touch-runtime.js +1 -0
  444. package/dist/src/transport.js +3 -0
  445. package/dist/src/tree.js +1 -0
  446. package/dist/src/ttl-memo.js +1 -0
  447. package/dist/src/tv-remote.js +1 -0
  448. package/dist/src/type-text-runtime.js +1 -0
  449. package/dist/src/undici.js +99 -0
  450. package/dist/src/update-check.js +1 -1
  451. package/dist/src/verified-file.js +1 -1
  452. package/dist/src/version.js +1 -1
  453. package/dist/src/video.js +2 -2
  454. package/dist/src/web.js +2 -1
  455. package/dist/src/web2.js +1 -0
  456. package/dist/src/webdriver-ios-snapshot.js +1 -0
  457. package/dist/src/webdriver-source.js +1 -0
  458. package/dist/src/window-state.js +1 -0
  459. package/linux/atspi-dump.py +54 -9
  460. package/package.json +58 -35
  461. package/server.json +9 -3
  462. package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.10.apk.sha256 +0 -1
  463. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.10.apk +0 -0
  464. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.10.apk.sha256 +0 -1
  465. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CoordinateTextEntryTests.swift +0 -4
  466. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+FlatSnapshotFiltering.swift +0 -168
  467. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+LifecycleCacheTests.swift +0 -6
  468. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+RecordingTests.swift +0 -4
  469. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SelectorMatchPolicyTests.swift +0 -4
  470. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotPresentation.swift +0 -183
  471. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotPresentationTests.swift +0 -0
  472. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotTraversalIdentityTests.swift +0 -4
  473. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryPolicyTests.swift +0 -4
  474. package/dist/src/appearance.js +0 -1
  475. package/dist/src/apps.js +0 -5
  476. package/dist/src/audio-probe.js +0 -1
  477. package/dist/src/cli-grammar.js +0 -1
  478. package/dist/src/command-catalog.js +0 -1
  479. package/dist/src/debug-symbols.js +0 -5
  480. package/dist/src/device-input-state.js +0 -2
  481. package/dist/src/device-ready.js +0 -1
  482. package/dist/src/dispatch.js +0 -1
  483. package/dist/src/handler-utils.js +0 -1
  484. package/dist/src/helper-package-install.js +0 -1
  485. package/dist/src/host-process.js +0 -3
  486. package/dist/src/ime-lifecycle.js +0 -2
  487. package/dist/src/ime-recovery-marker.js +0 -1
  488. package/dist/src/input-actions3.js +0 -1
  489. package/dist/src/install-artifact.js +0 -1
  490. package/dist/src/install-artifact2.js +0 -1
  491. package/dist/src/interaction-common.js +0 -1
  492. package/dist/src/interaction-runtime.js +0 -1
  493. package/dist/src/interaction-snapshot.js +0 -1
  494. package/dist/src/manifest.js +0 -1
  495. package/dist/src/method-scope.js +0 -1
  496. package/dist/src/png-resize.js +0 -1
  497. package/dist/src/process-lock.js +0 -1
  498. package/dist/src/runner-lease.js +0 -1
  499. package/dist/src/runner-sequence.js +0 -1
  500. package/dist/src/script-source-bundle.js +0 -16
  501. package/dist/src/sdk-android-adb.d.ts +0 -245
  502. package/dist/src/sdk-android-adb.js +0 -4
  503. package/dist/src/sdk.js +0 -1
  504. package/dist/src/setting-state.js +0 -1
  505. package/dist/src/shell-quote.js +0 -1
  506. package/dist/src/snapshot-session.js +0 -1
  507. package/dist/src/timing-safe-equal.js +0 -1
  508. package/dist/src/unsupported-interactor.js +0 -1
  509. package/dist/src/verdict.js +0 -1
  510. /package/dist/src/{recording-telemetry.js → telemetry.js} +0 -0
@@ -1 +1 @@
1
- import{pn as e}from"./sdk-batch-runner.js";function t(t,n,r){return e(typeof t==`string`?t:t.raw,n,r)}export{t};
1
+ import{yn as e}from"./sdk-batch.js";function t(t,n,r){return e(typeof t==`string`?t:t.raw,n,r)}export{t};
@@ -0,0 +1 @@
1
+ import{Fr as e,Tr as t,xr as n}from"./sdk-batch.js";import{r}from"./mobile-snapshot-semantics.js";function i(e,t,n={}){let i=a(e);if(i.length===0)return{canScroll:!1,emptySnapshot:!0};let s=r(i),c=o(i,s,t,n);return c?{canScroll:d(c,s.get(c.index),t),emptySnapshot:!1,scope:f(c,i)}:{canScroll:!1,emptySnapshot:!1}}function a(e){return e.map((e,t)=>({...e,ref:`ref`in e&&e.ref?e.ref:`e${t+1}`}))}function o(t,r,i,a){let o=n(t),d=t.filter(t=>e(t)&&v(t.rect));if(d.length===0)return null;let f=u(a.nodeIndex,o.nodeByIndex);if(f)return f;let p=a.point;if(p)return c(d,r,i,p)||s(d,r,i,o);let m=l(t);if(m){let e=c(d,r,i,m);if(e)return e}return s(d,r,i,o)}function s(e,t,n,r){let i=e.filter(e=>d(e,t.get(e.index),n)).sort((e,t)=>h(t,e));return i.length>0?i[0]??null:e.filter(r.isVisibleInEffectiveViewport).sort((e,t)=>h(t,e))[0]??e.sort((e,t)=>h(t,e))[0]??null}function c(e,t,n,r){let i=e.filter(e=>e.rect&&_(e.rect,r)).sort(h);return i.find(e=>d(e,t.get(e.index),n))??i[0]??null}function l(e){let n=e.filter(e=>t(e)&&v(e.rect)).sort((e,t)=>h(t,e))[0]?.rect;if(n)return{x:n.x+n.width/2,y:n.y+n.height/2}}function u(t,n){if(t===void 0)return null;let r=n.get(t);for(;r;){if(e(r)&&v(r.rect))return r;r=r.parentIndex===void 0?void 0:n.get(r.parentIndex)}return null}function d(e,t,n){return n===`bottom`?e.hiddenContentBelow===!0||t?.hiddenContentBelow===!0:e.hiddenContentAbove===!0||t?.hiddenContentAbove===!0}function f(e,t){return[e.identifier,e.label].filter(e=>typeof e==`string`).map(e=>e.trim()).find(n=>m(n)&&p(n,e,t))}function p(e,t,n){let r=e.toLowerCase(),i=n.filter(e=>[e.identifier,e.label,e.value].some(e=>typeof e==`string`&&e.trim().toLowerCase().includes(r)));return i.length===1&&i[0]?.index===t.index}function m(e){return e.length>0&&e.length<=80&&!/^(true|false)$/i.test(e)&&!/^\d+$/.test(e)&&!/^\d+%$/.test(e)}function h(e,t){return g(e.rect)-g(t.rect)}function g(e){return e?e.width*e.height:0}function _(e,t){return t.x>=e.x&&t.x<=e.x+e.width&&t.y>=e.y&&t.y<=e.y+e.height}function v(e){return!!(e&&e.width>0&&e.height>0)}export{i as analyzeScrollEdgeState};
@@ -1 +1 @@
1
- import{E as e,_ as t,h as n,l as r,m as i,s as a,v as o}from"./sdk-contracts.js";import{$n as s,Bt as c,Cr as l,Qn as u,Sn as d,Xn as f,Zn as p,Zt as m,bn as ee,nn as te,tr as ne}from"./sdk-batch-runner.js";import{_ as re,c as h,l as ie,s as ae}from"./sdk-device.js";import{Dt as oe,G as se,Ot as ce,m as g,ot as le}from"./script-source-bundle.js";import{t as ue}from"./interaction.js";import{N as de,Q as _}from"./screenshot-result.js";import{i as fe}from"./session-target-evidence.js";import{t as pe}from"./verdict.js";import{a as me,t as he}from"./runtime.js";import{A as ge}from"./sdk-android-adb.js";import{r as _e}from"./app-lifecycle.js";import{a as v}from"./snapshot.js";import{j as ve}from"./runner-disposal.js";import{o as y}from"./interactors.js";import{a as b,o as ye,p as be,s as x,t as xe}from"./dispatch.js";import{n as S}from"./runner-client.js";import{Mt as C,Ot as w,ft as Se,gt as T,ht as E,jt as Ce,mt as we,wt as D}from"./internal/daemon.js";import{a as Te,i as Ee,r as De}from"./snapshot-session.js";import{t as Oe}from"./device-ready.js";import{t as ke}from"./backend-snapshot-options.js";const Ae=[[`snapshotDepth`,`--depth`],[`snapshotScope`,`--scope`],[`snapshotRaw`,`--raw`]];function O(e,t){let n=je(t);return n.length===0?null:b(`INVALID_ARGS`,`${e} @ref does not support ${n.join(`, `)}.`)}function je(e){if(!e)return[];let t=[];for(let[n,r]of Ae)e[n]!==void 0&&t.push(r);return t}function Me(e,t){if(!t||t.settle===!0)return null;let n=[];return t.settleQuietMs!==void 0&&n.push(`--settle-quiet`),n.length===0?null:b(`INVALID_ARGS`,`${e}: ${n.join(`, `)} require${n.length===1?`s`:``} --settle.`)}function Ne(e){if(e?.settle===!0)return{...e.settleQuietMs===void 0?{}:{quietMs:e.settleQuietMs},...e.timeoutMs===void 0?{}:{timeoutMs:e.timeoutMs}}}function k(e){if(e.length<2)return null;let t=Number(e[0]),n=Number(e[1]);return!Number.isFinite(t)||!Number.isFinite(n)?null:{x:t,y:n}}function A(e){let t=n(e);return t?{ok:!0,ref:t.base,generation:t.generation}:{ok:!1,response:b(`INVALID_ARGS`,`Invalid ref "${e}" — malformed generation suffix.`,{hint:a})}}function j(e,t){let n=k(e);if(n)return{ok:!0,target:{kind:`point`,x:n.x,y:n.y}};let r=e[0]??``;if(r.startsWith(`@`)){let t=A(r);return t.ok?{ok:!0,target:{kind:`ref`,ref:t.ref,fallbackLabel:e.slice(1).join(` `).trim()},refGeneration:t.generation}:{ok:!1,response:t.response}}let i=e.join(` `).trim();return i?{ok:!0,target:{kind:`selector`,selector:i}}:{ok:!1,response:b(`INVALID_ARGS`,`${t} requires @ref, selector expression, or x y coordinates`)}}function Pe(e){let t=k(e);if(t)return{ok:!0,target:{kind:`point`,x:t.x,y:t.y},...Ve(e[2])};let n=Be(e),r=j(n.targetPositionals,`longpress`);return r.ok?{ok:!0,target:r.target,refGeneration:r.refGeneration,...n.duration}:r}function Fe(e){let t=e[0]??``;if(t.startsWith(`@`)){let n=A(t);if(!n.ok)return{ok:!1,response:n.response};let r=g(e).text;return r?{ok:!0,target:{kind:`ref`,ref:n.ref,fallbackLabel:ze(e)},refGeneration:n.generation,text:r}:{ok:!1,response:b(`INVALID_ARGS`,`fill requires text after ref`)}}let n=k(e);if(n){let t=e.slice(2).join(` `);return t?{ok:!0,target:{kind:`point`,x:n.x,y:n.y},text:t}:{ok:!1,response:b(`INVALID_ARGS`,`fill requires text after coordinates`)}}let r=Ie(e);return!r||r.kind!==`selector`?{ok:!1,response:b(`INVALID_ARGS`,`fill requires x y text, @ref text, or selector text`)}:r.text.trim()?{ok:!0,target:{kind:`selector`,selector:r.target.selector},text:r.text}:{ok:!1,response:b(`INVALID_ARGS`,`fill requires text after selector`)}}function Ie(e){try{return g(e)}catch{return null}}function Le(e){let t=`evidence`in e?e.evidence:void 0,n=e.settle;return e.kind===`ref`?{ref:M(e.target?.kind===`ref`?e.target.ref:void 0),refLabel:e.refLabel,selectorChain:e.selectorChain,targetHittable:e.targetHittable,hint:e.hint,evidence:t,settle:n,resolution:e.resolution}:e.kind===`selector`?{selector:e.target?.kind===`selector`?e.target.selector:void 0,selectorChain:e.selectorChain,refLabel:e.refLabel,targetHittable:e.targetHittable,hint:e.hint,evidence:t,settle:n,resolution:e.resolution}:{evidence:t,settle:n}}function Re(e,t){return e.kind===`point`?`coordinate tap`:t.kind===`ref`&&t.target?.kind===`ref`?t.target.ref:t.kind===`selector`&&t.target?.kind===`selector`?t.target.selector:`target`}function M(e){return e?.startsWith(`@`)?e.slice(1):e}function ze(e){return e.length>=3&&e[1]?.trim()||``}function Be(e){let t=e.at(-1);return e.length>1&&He(t)?{targetPositionals:e.slice(0,-1),duration:{durationMs:Number(t)}}:{targetPositionals:e,duration:{}}}function Ve(e){return e===void 0?{}:{durationMs:Number(e)}}function He(e){return e===void 0||e.trim()===``?!1:Number.isFinite(Number(e))}function N(e){let{req:t,logPath:n,traceLogPath:r}=e;return{verbose:t.flags?.verbose,logPath:n,traceLogPath:r,requestId:t.meta?.requestId,iosXctestrunFile:t.flags?.iosXctestrunFile,iosXctestDerivedDataPath:t.flags?.iosXctestDerivedDataPath,iosXctestEnvDir:t.flags?.iosXctestEnvDir}}function P(e,t){return!(!e||!h(e.device)||y(e.device)||t.skipPendingPostGestureStabilization&&w(e))}function F(e){let{session:t,selectorExpression:n}=e;return P(t,{skipPendingPostGestureStabilization:!0})?te(n):null}function Ue(e){let t=e.identifier?.trim();if(t)return{key:`id`,value:t};let n=e.label?.trim();return n?{key:`label`,value:n}:null}function I(e,t={}){let n=o(e);if(n.code===`ELEMENT_NOT_FOUND`)return t.delegateSemanticFailures===!0||t.allowElementNotFound===!0;if(n.code===`AMBIGUOUS_MATCH`)return t.delegateSemanticFailures===!0;if(n.code===`ELEMENT_OFFSCREEN`)return t.delegateSemanticFailures!==!1;if(n.code!==`COMMAND_FAILED`)return!1;let r=n.message.toLowerCase();return r.includes(`fetch failed`)||r.includes(`timed out`)||r.includes(`timeout`)||r.includes(`runner did not accept connection`)||r.includes(`invalid runner response`)}async function We(e,n){let r=await L(e);if(r){if(v(r.foregroundPackage))return`press ${n} opened an Android permission dialog (${r.foregroundPackage}) over ${r.expectedPackage}. ${r.hint}`;throw new t(`COMMAND_FAILED`,`press ${n} left ${e.appBundleId} and foregrounded ${r.foregroundPackage}. The tap likely escaped the app.`,r)}}async function L(e){if(e.device.platform!==`android`||!e.appBundleId)return null;let t=await _e(e.device),n=t.package?.trim();return!n||n===e.appBundleId||!Je(n)?null:{expectedPackage:e.appBundleId,foregroundPackage:n,activity:t.activity,hint:qe(n)}}function Ge(e){return v(e.foregroundPackage)?`Android permission dialog is blocking ${e.expectedPackage}`:`${e.foregroundPackage} is foreground instead of ${e.expectedPackage}`}function Ke(e){return e.code===`COMMAND_FAILED`&&typeof e.details?.expectedPackage==`string`&&typeof e.details?.foregroundPackage==`string`}function qe(e){return v(e)?`Use "alert get" to inspect it, then "alert accept" or "alert dismiss" to respond.`:`Use screenshot as visual truth, then take a fresh snapshot -i before retrying.`}function Je(e){return e===`com.android.settings`||e===`com.android.systemui`||v(e)||e.includes(`launcher`)}function Ye(e,t){if(t===`exists`)return{found:!0};if(t===`wait`)return{found:!0,waitedMs:e.waitedMs};if(t===`list`)return{action:`list`,matches:Array.isArray(e.matches)?e.matches.length:0};let n=typeof e.ref==`string`?e.ref:void 0;return t===`get_attrs`?{ref:n,action:`get attrs`}:{ref:n,action:`get text`,text:typeof e.text==`string`?e.text:``}}function Xe(e){return e.kind===`found`?{found:!0,...typeof e.waitedMs==`number`?{waitedMs:e.waitedMs}:{}}:e.kind===`list`?{matches:e.matches.map(e=>({ref:e.ref,node:c(e.node)}))}:{ref:e.ref,...e.kind===`text`?{text:e.text}:{},node:c(e.node)}}function Ze(e,t){let n=Array.isArray(e.selectorChain)?e.selectorChain:void 0,r=et(e),i=r?.kind===`ref`?H(r.ref):void 0,a=r?.kind===`selector`?r.selector:void 0,o={...i?{ref:i}:{},...a?{selector:a}:{},...n?{selectorChain:n}:{}};if(t===`attrs`)return o;let s=typeof e.text==`string`?e.text:``;return{...o,text:s,refLabel:$e(s)}}function R(e){let{target:t}=e;return{...t.kind===`ref`?{ref:H(t.ref)}:{},...t.kind===`selector`?{selector:t.selector}:{},...typeof e.text==`string`?{text:e.text}:{},node:c(e.node)}}function z(e){let{node:t,preActionNodes:n,...r}=e;return r}function Qe(e){return{waitedMs:e.waitedMs,...typeof e.text==`string`?{text:e.text}:{},...typeof e.selector==`string`?{selector:e.selector}:{},...typeof e.captures==`number`?{captures:e.captures}:{},...typeof e.nodeCount==`number`?{nodeCount:e.nodeCount}:{},...typeof e.hint==`string`?{hint:e.hint}:{}}}function B(e){let{selectorChain:t,...n}=e;return n}function V(e,t,n,r,i,a){let o=e.get(t);if(!o)return;let s=_(o)&&i?fe(i,{mode:a}):void 0;e.recordAction(o,{command:n.command,positionals:n.positionals??[],flags:n.flags??{},result:r,interactiveObservation:de(n),...s?{targetEvidence:s}:{}})}function $e(e){let t=e.trim();if(!(!t||t.length>80||/[\r\n]/.test(t)))return t}function et(e){let t=e.target;if(!t||typeof t!=`object`)return;let n=t;if(n.kind===`ref`&&typeof n.ref==`string`)return{kind:`ref`,ref:n.ref};if(n.kind===`selector`&&typeof n.selector==`string`)return{kind:`selector`,selector:n.selector}}function H(e){return e.startsWith(`@`)?e.slice(1):e}const tt=[`application`,`window`,`tabbar`,`scrollbar`,`image`],nt=new Set([`tab bar`]);async function U(e,t){if(t.ok||!rt(t.error.details?.reason)||t.error.details?.captureStalled===!0||t.error.details?.captureTruncated===!0)return t;let n=await it(e).catch(()=>null);return n?b(t.error.code,`${t.error.message}. Current surface: ${n.summary}.`,{...t.error.details??{},currentSurface:n.details}):t}function rt(e){return e===ue.targetAbsent||e===ue.stableTimeout}async function it(e){let t=[...(await D({device:e.device,session:e.session,flags:{...e.req.flags,snapshotInteractiveOnly:!0},logPath:e.logPath??``})).snapshot.nodes].sort(at),n=W(t,6,{includeIdentifiers:!0});if(n.length===0)return null;let r=W(t.filter(e=>!lt(e)),4,{includeIdentifiers:!1}),i=W(t.filter(ut),4,{includeIdentifiers:!0});return{summary:(r.length>0?r:n.slice(0,4)).join(`, `),details:{labels:n,...i.length>0?{buttons:i}:{}}}}function W(e,t,n){let r=new Set,i=[];for(let a of e){let e=ct(a,n);if(!(!e||r.has(e))&&(r.add(e),i.push(e),i.length>=t))break}return i}function at(e,t){return ot(e)-ot(t)||st(e,t)}function ot(e){let t=!!ct(e,{includeIdentifiers:!1});return(lt(e)?2:0)+ +!t}function st(e,t){return e.rect&&t.rect?e.rect.y-t.rect.y||e.rect.x-t.rect.x:e.rect?-1:t.rect?1:(e.depth??0)-(t.depth??0)||e.index-t.index}function ct(e,t){let n=(t.includeIdentifiers?[e.label,e.value,e.identifier]:[e.label,e.value]).map(e=>typeof e==`string`?e.trim():``).find(e=>e.length>0);return n?n.replace(/\s+/g,` `).slice(0,80):``}function lt(e){let t=l(`${e.type??``} ${e.role??``} ${e.subrole??``}`),n=`${e.label??``} ${e.value??``}`.trim().toLowerCase();return tt.some(e=>t.includes(e))||nt.has(n)||n.endsWith(`.fill`)}function ut(e){return l(`${e.type??``} ${e.role??``} ${e.subrole??``}`).includes(`button`)}function G(e,t){let n=me(t);if(!n)return e;if(e.ok){let t=dt(e.data?.warning,n);return{...e,data:{...e.data,warning:t}}}let r=e.error.details??{};return{...e,error:{...e.error,details:{...r,hint:dt(r.hint,n)}}}}function dt(e,t){return typeof e==`string`&&e.trim()!==``?`${e}\n${t}`:t}async function ft(e){let{device:t,node:n,flags:r,appBundleId:i,traceOutPath:a,surface:o,contextFromFlags:s}=e,c=oe(n),l=le(n.rect);if(!l||h(t)&&c&&!ce(n.type??``))return c;try{let e=await xe(t,`read`,[String(l.x),String(l.y)],void 0,{...s(r,i,a),surface:o}),u=e&&typeof e==`object`?e:void 0,d=typeof u?.text==`string`?u.text:``;return d.trim()?d:(ge({level:`warn`,phase:`interaction_read_fallback`,data:{reason:`empty_backend_text`,nodeRef:n.ref,surface:o,platform:t.platform}}),c)}catch(e){return ge({level:`warn`,phase:`interaction_read_fallback`,data:{reason:`backend_read_failed`,nodeRef:n.ref,surface:o,platform:t.platform,error:e instanceof Error?e.message:String(e)}}),c}}function K(e){let{session:t,sessionStore:n,sessionName:r}=e,i=0,a,o,s=t=>(e.consumedSnapshot&&(e.consumedSnapshot.state=t.snapshot),t);return{capture:async c=>{let l=Date.now(),u=St(c,e.req.flags?.out),d=gt({timestamp:l,lastSnapshotAt:i,lastSnapshotResult:a,lastSnapshotCacheKey:o,session:t,request:c,cacheKey:u});if(d)return s(d);let f=_t({session:t,timestamp:l,request:c});if(f)return i=f.createdAt,a={snapshot:f},o=u,s(a);let p=await pt({params:e,request:c});c.signal?.throwIfAborted();let m={snapshot:p};return wt({session:t,sessionStore:n,sessionName:r,snapshot:p}),i=l,a=m,o=u,s(m)}}}async function pt(e){let{params:t,request:n}=e,r=await q(t,n,n.snapshotScope);return n.recovery?.legacyIosSparse&&Tt(r)?await mt({runtimeParams:t,request:n,policy:n.recovery.legacyIosSparse}):n.recovery?.sparseVerdictQueryScope?.shouldScope&&pe(r.snapshotQuality)?await ht({runtimeParams:t,request:n,policy:n.recovery.sparseVerdictQueryScope,snapshot:r}):r}async function mt(e){let{runtimeParams:t,request:n,policy:r}=e;try{return await q(t,n,void 0,!1)}catch(e){if(!r.shouldScope)throw e;return await q(t,n,r.query,!1)}}async function ht(e){let{runtimeParams:t,request:n,policy:r,snapshot:i}=e;try{return await q(t,n,r.query,!1)}catch{return i}}async function q(e,t,n,r=t.flags?.snapshotInteractiveOnly){return(await D({device:e.device,session:e.session,flags:{...t.flags,snapshotInteractiveOnly:r},outPath:t.outPath??e.req.flags?.out,logPath:e.logPath??``,snapshotScope:n,includeRects:t.includeRects,signal:t.signal})).snapshot}function gt(e){let{timestamp:t,lastSnapshotAt:n,lastSnapshotResult:r,lastSnapshotCacheKey:i,session:a,request:o,cacheKey:s}=e;if(o.cache?.forceFresh!==!0&&r&&i===s&&!(t-n>=750)&&!C(a)&&!bt(a,o))return r}function _t(e){let{session:t,timestamp:n,request:r}=e,i=t?.snapshot;if(i&&vt(t,r)&&yt(i,n)&&i.presentationKey===xt(r))return i}function vt(e,t){return!(t.cache?.forceFresh===!0||t.cache?.useSessionSnapshot!==!0||C(e)||bt(e,t))}function yt(e,t){return t-e.createdAt<750}function bt(e,t){return t.cache?.bypassForPostGestureStabilization===!0&&w(e)}function xt(e){return r(i(Ct(e)))}function St(e,t){return JSON.stringify({presentationKey:xt(e),includeRects:e.includeRects===!0,outPath:e.outPath??t??null})}function Ct(e){return e.snapshotScope===void 0?e.flags:{...e.flags,snapshotScope:e.snapshotScope}}function wt(e){let{session:t,sessionStore:n,sessionName:r,snapshot:i}=e;!t||pe(i.snapshotQuality)||(T(t,i),n.set(r,t))}function Tt(e){return e.snapshotQuality||e.backend!==`xctest`||e.nodes.length!==1?!1:e.nodes[0]?.type===`Application`}function Et(e){return he({backend:Dt(e),...Te(`selector commands`,{plural:!0}),sessions:Se({sessionName:e.sessionName,getSession:()=>e.session,recordOptions:{includeSnapshot:!0},setRecord:t=>{!e.session||!t.snapshot||(T(e.session,t.snapshot),e.sessionStore.set(e.sessionName,e.session))}}),signal:e.signal??ve(e.req.meta?.requestId)})}async function J(e,t){e.consumedSnapshot??={};let n=e.sessionStore.get(e.sessionName);if(!n&&t.requireSession)return{ok:!1,response:ye()};let r=n?.device??await be(e.req.flags??{});n||await Oe(r);let i=x(t.capability,r);return i?{ok:!1,response:i}:{ok:!0,runtime:Et({...e,session:n,device:r})}}function Dt(e){let{req:t,session:n,device:r,logPath:i,sessionName:a,sessionStore:o}=e,s=K({device:r,session:n,sessionStore:o,sessionName:a,req:t,consumedSnapshot:e.consumedSnapshot,logPath:i});return{platform:re(r),captureSnapshot:async(e,n)=>{let i={...t.flags,...ke(n)},a=n?.includeRects===!0,o=n?.scope??t.flags?.snapshotScope,c=t.command===`wait`||t.command===`find`||a&&r.platform===`web`;return await s.capture({flags:i,signal:e.signal,snapshotScope:o,includeRects:a,cache:{forceFresh:c,useSessionSnapshot:!0,bypassForPostGestureStabilization:!0}})},readText:async(a,o)=>({text:await ft({device:r,node:o,flags:t.flags,appBundleId:n?.appBundleId,traceOutPath:n?.trace?.outPath,surface:n?.surface,contextFromFlags:e.contextFromFlags??((e,t,n)=>Ce(i??``,e,t,n))})}),findText:async(t,n)=>({found:await Ot(e,n,t.signal)})}}async function Ot(e,t,n){let r=await kt(e,t,n);return r===null?await At(e,t,n)===!0?!0:await Nt(e,t,n):r}async function kt(e,t,n){return!ie(e.device)||!e.session?.surface||e.session.surface===`app`?null:await Nt(e,t,n)}async function At(e,t,n){let r=jt(e);return r?(await S(r.device,{command:`findText`,text:t,appBundleId:r.appBundleId},{...Mt(e,r),signal:n}))?.found===!0:null}function jt(e){return!ae(e.device.platform)||y(e.device)||!e.session?.appBundleId?null:{device:e.device,appBundleId:e.session.appBundleId,traceLogPath:e.session.trace?.outPath}}function Mt(e,t){return N({req:e.req,logPath:e.logPath,traceLogPath:t.traceLogPath})}async function Nt(e,t,n){return!!se((await Pt(e,n)).nodes,t)}async function Pt(e,t){let{snapshot:n}=await K({device:e.device,session:e.session,sessionStore:e.sessionStore,sessionName:e.sessionName,req:e.req,logPath:e.logPath,consumedSnapshot:e.consumedSnapshot}).capture({flags:{...e.req.flags,snapshotInteractiveOnly:!1,snapshotIncludeHiddenContentHints:!1},signal:t,cache:{forceFresh:!0,bypassForPostGestureStabilization:!0}});return n}async function Ft(e){let{req:t}=e;if(t.command!==`find`)return null;let n=ee(t.positionals??[],t.flags);if(!n.ok)return b(n.code,n.message);let r=n.parsed,i=r.action;if(!d(i))return null;let a=await J(e,{requireSession:!1,capability:`find`});return a.ok?G(await Q(async()=>{let n=await a.runtime.selectors.find({session:e.sessionName,requestId:t.meta?.requestId,locator:r.locator,query:r.query,action:i,timeoutMs:r.timeoutMs});V(e.sessionStore,e.sessionName,t,Ye(n,i));let o=Xe(n),s=typeof o.ref==`string`?[o.ref]:Array.isArray(o.matches)?o.matches.map(e=>e.ref).filter(e=>typeof e==`string`):[];if(s.length>0){let t=e.sessionStore.get(e.sessionName);if(t&&(we(t,s),e.sessionStore.set(e.sessionName,t),t.snapshotGeneration!==void 0))return{...o,refsGeneration:t.snapshotGeneration}}return o}),Y(e)):a.response}function Y(e){return e.consumedSnapshot?.state??e.sessionStore.get(e.sessionName)?.snapshot}async function It(e){let{req:t}=e;if(t.command!==`get`)return null;let n=p(t.positionals?.[0]);if(!n.ok)return b(n.code,n.message);let r=n.format,i=Yt(t);if(!i.ok)return i.response;if(i.target.kind===`ref`){let e=O(`get`,t.flags);if(e)return e}let a=t.internal?.replayTargetGuard;if(i.target.kind===`selector`&&!a){let t=await Vt(e,r,i.target.selector);if(t)return t}let o=await J(e,{requireSession:!0,capability:`get`});if(!o.ok)return o.response;let s=i.target.kind===`ref`?E({session:e.sessionStore.get(e.sessionName),ref:i.target.ref,mintedGeneration:i.refGeneration}):void 0;return G(await Q(async()=>{let n=await o.runtime.selectors.get({session:e.sessionName,requestId:t.meta?.requestId,property:r,target:i.target,expectedResolvedTarget:a});V(e.sessionStore,e.sessionName,t,Ze(n,r),{node:n.node,preActionNodes:n.preActionNodes});let c=R(n);return s?{...c,warning:s}:c}),Y(e))}async function Lt(e){let{req:t}=e;if(t.command!==`is`)return null;let n=u(t.positionals??[]);if(!n.ok)return b(n.code,n.message,n.hint?{hint:n.hint}:void 0);let{predicate:r,expectedText:i}=n,a={selectorExpression:n.selectorExpression},o=t.internal?.replayTargetGuard,s=_(e.sessionStore.get(e.sessionName));if(!o&&!s){let t=await Ht(e,r,a.selectorExpression,i);if(t)return t}let c=await J(e,{requireSession:!0,capability:`is`});return c.ok?G(await $(e,await Q(async()=>{let n=await c.runtime.selectors.is({session:e.sessionName,requestId:t.meta?.requestId,predicate:r,selector:a.selectorExpression,expectedText:i,expectedResolvedTarget:o}),s=zt(n),l=z(n);return V(e.sessionStore,e.sessionName,t,l,s),B(l)}),`is ${r}`),Y(e)):c.response}async function Rt(e){let{req:t,sessionName:n,sessionStore:r}=e,i=m(t.positionals??[]);if(!i)return b(`INVALID_ARGS`,`wait requires a duration or text`);if(i.kind===`invalid`)return b(`INVALID_ARGS`,i.message);let{session:a,device:o}=await De(r,n,t.flags);if(i.kind!==`sleep`){let e=x(`wait`,o);if(e)return e}let s=t.internal?.replayLandmarkGuard;if(i.kind===`selector`&&!s&&!_(a)){let t=await Ut({...e,session:a,device:o,selectorExpression:i.selectorExpression,timeoutMs:i.timeoutMs});if(t)return t}let c=i,l;if(i.kind===`ref`){let e=A(i.rawRef);if(!e.ok)return e.response;c={...i,rawRef:e.ref},l=E({session:a,ref:e.ref,mintedGeneration:e.generation})}e.consumedSnapshot??={};let u=async()=>{let i=Et({...e,session:a,device:o}),u=await Q(async()=>{let e=await i.selectors.wait({session:n,requestId:t.meta?.requestId,target:Xt(c,a,s)}),o=zt(e);V(r,n,t,z(e),o,`landmark`);let u=Qe(e);return l?{...u,warning:l}:u});return await $(e,await U({req:t,logPath:e.logPath,session:a,device:o},u),`wait`)};return i.kind===`sleep`?await u():G(await Ee(a,o,u),Y(e))}function zt(e){let t=e.node,n=e.preActionNodes;if(!(!t||typeof t!=`object`||!Array.isArray(n)))return{node:t,preActionNodes:n}}function Bt(e,t,n){if(!e||_(e))return null;let r=F({session:e,selectorExpression:n});return t===`text`&&r?.key!==`id`?null:r}async function Vt(e,t,n){let r=e.sessionStore.get(e.sessionName),i=Bt(r,t,n);if(!r||!i)return null;let a=await X(e,r,i);if(Z(a))return a.response;if(!a)return null;let o=Kt(t,i.raw,a);return o?(V(e.sessionStore,e.sessionName,e.req,Ze(o,t)),{ok:!0,data:R(o)}):null}async function Ht(e,t,n,r){if(t===`hidden`)return null;let i=await Wt(e,n);if(Z(i))return i.response;if(!i?.result.found||!i.result.node)return null;let a=t===`exists`?{predicate:t,pass:!0,selector:i.selector.raw,matches:1,selectorChain:[i.selector.raw]}:qt(t,r,i.selector.raw,i.session,i.result.node);return a?(V(e.sessionStore,e.sessionName,e.req,a),{ok:!0,data:B(a)}):null}async function Ut(e){let t=F({session:e.session,selectorExpression:e.selectorExpression});if(!e.session||!t)return null;let n=Date.now(),r=await X(e,e.session,t);if(Z(r))return r.response;if(!r?.found)return null;let i={kind:`selector`,selector:t.raw,waitedMs:Date.now()-n,selectorChain:[t.raw]};V(e.sessionStore,e.sessionName,e.req,i);let a={ok:!0,data:B(i)};return await U({req:e.req,logPath:e.logPath,session:e.session,device:e.device},a)}async function Wt(e,t){let n=e.sessionStore.get(e.sessionName),r=F({session:n,selectorExpression:t});if(!n||!r)return null;let i=await X(e,n,r);return Z(i)?i:i?{session:n,selector:r,result:i}:null}async function Gt(e,t,n){let r=await S(e.device,{command:`querySelector`,selectorKey:t.key,selectorValue:t.value,appBundleId:e.appBundleId},n),i=r.found===!0,a=Jt(r);return{found:i,...typeof r.text==`string`?{text:r.text}:{},...a?{node:a}:{}}}async function X(t,n,r){try{return await Gt(n,r,N({req:t.req,logPath:t.logPath,traceLogPath:n.trace?.outPath}))}catch(t){return I(t,{allowElementNotFound:!0})?null:{kind:`error`,response:{ok:!1,error:e(t)}}}}function Z(e){return e!==null&&`kind`in e&&e.kind===`error`}function Kt(e,t,n){if(!n.found||!n.node)return null;let r={target:{kind:`selector`,selector:t},node:n.node,selectorChain:[t]};return e===`attrs`?{kind:`attrs`,...r}:typeof n.text==`string`?{kind:`text`,...r,text:n.text}:null}function qt(e,t,n,r,i){let a=ne({predicate:e,node:i,nodes:[i],expectedText:t,platform:r.device.platform});return{predicate:e,pass:a.pass,selector:n,...e===`text`?{text:a.actualText}:{},selectorChain:[n]}}function Jt(e){let t=e.nodes;if(!Array.isArray(t))return;let n=t[0];if(!(!n||typeof n!=`object`))return n}function Yt(e){let t=e.positionals?.[1]??``;if(t.startsWith(`@`)){let n=A(t);return n.ok?{ok:!0,target:{kind:`ref`,ref:n.ref,fallbackLabel:e.positionals.length>2?e.positionals.slice(2).join(` `).trim():``},refGeneration:n.generation}:{ok:!1,response:n.response}}let n=f(e.positionals?.slice(1)??[]);return n.ok?{ok:!0,target:{kind:`selector`,selector:`selector`in n?n.selector:``}}:{ok:!1,response:b(n.code,n.message)}}function Xt(e,n,r){if(e.kind===`sleep`)return{kind:`sleep`,durationMs:e.durationMs};if(e.kind===`selector`)return{kind:`selector`,selector:e.selectorExpression,timeoutMs:e.timeoutMs,...r?{recordedLandmark:r}:{}};if(e.kind===`ref`){if(!n?.snapshot)throw new t(`INVALID_ARGS`,`Ref wait requires an existing snapshot in session.`);return{kind:`ref`,ref:e.rawRef,timeoutMs:e.timeoutMs}}if(e.kind===`stable`)return{kind:`stable`,quietMs:e.quietMs,timeoutMs:e.timeoutMs};let i=s(e.text);if(!i.ok)throw new t(i.code,i.message);return{kind:`text`,text:i.text,timeoutMs:e.timeoutMs}}async function Q(e){try{return{ok:!0,data:await e()}}catch(e){let t=o(e);return b(t.code,t.message,t.details)}}async function $(e,t,n){if(t.ok)return t;let r=e.sessionStore.get(e.sessionName);if(!r)return t;let i;try{i=await L(r)}catch{return t}return i?b(t.error.code,`${n} failed because ${Ge(i)}.`,{...t.error.details??{},...i,blockedBy:`android_foreground_surface`,originalMessage:t.error.message}):t}export{Me as C,O as S,Fe as _,Gt as a,M as b,We as c,I as d,P as f,Le as g,Re as h,Rt as i,Ke as l,N as m,It as n,K as o,F as p,Lt as r,G as s,Ft as t,Ue as u,Pe as v,Ne as x,j as y};
1
+ import{C as e,c as t,f as n,w as r,x as i,y as a}from"./sdk-contracts.js";import{l as o,v as s}from"./sdk-device.js";import{Dn as c,Pt as l,ar as u,kn as d,or as f,sr as p}from"./sdk-batch.js";import{s as m}from"./session-store.js";import{i as ee,s as te}from"./session-target-evidence.js";import{f as h}from"./parameterized-recorded-fill.js";import{_ as ne,t as re}from"./runtime.js";import{a as ie,m as ae,p as oe,s as se,t as ce}from"./app-inventory-contract.js";import{r as le}from"./diagnostics.js";import"./diagnostics2.js";import{i as ue}from"./rect-center.js";import{a as g}from"./android-system-chrome.js";import{r as de}from"./request-cancel.js";import"./request.js";import{r as _}from"./provider-device-runtime.js";import{n as v}from"./dispatch-resolve.js";import{a as fe,i as y}from"./request-runtime-binding.js";import{C as b,S as pe,f as x,i as S,n as me,o as he,p as ge,r as _e,s as ve,y as C}from"./session-snapshot.js";import{t as w}from"./snapshot-quality-verdict.js";import{t as T}from"./ios-system-surface.js";import{t as E}from"./backend-snapshot-options.js";import{t as D}from"./snapshot-runtime-binding.js";function O(e){let n=i(e);return n?{ok:!0,ref:n.base,generation:n.generation}:{ok:!1,response:y(`INVALID_ARGS`,`Invalid ref "${e}" — malformed generation suffix.`,{hint:t})}}function k(e,t){if(t===`exists`)return{found:!0};if(t===`wait`)return{found:!0,waitedMs:e.waitedMs};if(t===`list`)return{action:`list`,matches:Array.isArray(e.matches)?e.matches.length:0};let n=typeof e.ref==`string`?e.ref:void 0;return t===`get_attrs`?{ref:n,action:`get attrs`}:{ref:n,action:`get text`,text:typeof e.text==`string`?e.text:``}}function A(e){return e.kind===`found`?{found:!0,...typeof e.waitedMs==`number`?{waitedMs:e.waitedMs}:{}}:e.kind===`list`?{matches:e.matches.map(e=>({ref:e.ref,node:g(e.node)}))}:{ref:e.ref,...e.kind===`text`?{text:e.text}:{},node:g(e.node)}}function j(e,t){let n=Array.isArray(e.selectorChain)?e.selectorChain:void 0,r=be(e),i=r?.kind===`ref`?L(r.ref):void 0,a=r?.kind===`selector`?r.selector:void 0,o={...i?{ref:i}:{},...a?{selector:a}:{},...n?{selectorChain:n}:{}};if(t===`attrs`)return o;let s=typeof e.text==`string`?e.text:``;return{...o,text:s,refLabel:ye(s)}}function M(e){let{target:t}=e;return{...t.kind===`ref`?{ref:L(t.ref)}:{},...t.kind===`selector`?{selector:t.selector}:{},...typeof e.text==`string`?{text:e.text}:{},node:g(e.node)}}function N(e){let{node:t,preActionNodes:n,...r}=e;return r}function P(e){return{waitedMs:e.waitedMs,...typeof e.text==`string`?{text:e.text}:{},...typeof e.selector==`string`?{selector:e.selector}:{},...typeof e.captures==`number`?{captures:e.captures}:{},...typeof e.nodeCount==`number`?{nodeCount:e.nodeCount}:{},...typeof e.hint==`string`?{hint:e.hint}:{}}}function F(e){let{selectorChain:t,...n}=e;return n}function I(e,t,n,r,i,a){let o=e.get(t);if(!o)return;let s=h(o)&&i?ee(i,{mode:a}):void 0;e.recordAction(o,{command:n.command,positionals:n.positionals??[],flags:n.flags??{},result:r,interactiveObservation:m(n),...s?{targetEvidence:s,targetEvidenceMode:a??`action`}:{}})}function ye(e){let t=e.trim();if(!(!t||t.length>80||/[\r\n]/.test(t)))return t}function be(e){let t=e.target;if(!t||typeof t!=`object`)return;let n=t;if(n.kind===`ref`&&typeof n.ref==`string`)return{kind:`ref`,ref:n.ref};if(n.kind===`selector`&&typeof n.selector==`string`)return{kind:`selector`,selector:n.selector}}function L(e){return e.startsWith(`@`)?e.slice(1):e}async function R(e){let t=await D({...e,plan:l({hasActiveApp:e.session?.appBundleId!==void 0,intent:xe(e.command)}),...e.session?{}:{readiness:{}}});return t.ok?{ok:!0,operations:{capture:t.capture,...t.readTextAtPoint?{readText:t.readTextAtPoint}:{},...t.findText?{findText:t.findText}:{}}}:t}function xe(e){switch(e){case`is`:return`capture-only`;case`find`:case`get`:return`element-text`;case`wait`:return`wait-observation`}}const Se=[[`snapshotDepth`,`--depth`],[`snapshotScope`,`--scope`],[`snapshotRaw`,`--raw`]];function z(e,t){let n=Se.filter(([e])=>t?.[e]!==void 0).map(([,e])=>e);return n.length===0?null:y(`INVALID_ARGS`,`${e} @ref does not support ${n.join(`, `)}.`)}async function B(t,n){if(t.device.platform!==`android`||!t.appBundleId||t.lease?.leaseProvider||_(t.device))return null;if(!n)throw new e(`INTERNAL_ERROR`,`Android observation was not supplied by root runtime composition`);let r=await n.readAppState(t.device),i=r.package?.trim();if(!i||i===t.appBundleId)return null;let a=await n.isPermissionPackage(i);return!we(i)&&!a?null:{expectedPackage:t.appBundleId,foregroundPackage:i,activity:r.activity,hint:Ce(a),...a?{permissionDialog:!0}:{}}}function V(e){return e.permissionDialog?`Android permission dialog is blocking ${e.expectedPackage}`:`${e.foregroundPackage} is foreground instead of ${e.expectedPackage}`}function Ce(e){return e?`Use "alert get" to inspect it, then "alert accept" or "alert dismiss" to respond.`:`Use screenshot as visual truth, then take a fresh snapshot -i before retrying.`}function we(e){return e===`com.android.settings`||e===`com.android.systemui`||e.includes(`launcher`)}function H(e,t){let n=t?.iosSystemSurfaceBundleId?T:ne(t);if(!n)return e;if(e.ok){let t=U(e.data?.warning,n);return{...e,data:{...e.data,warning:t}}}let r=e.error.details??{};return{...e,error:{...e.error,details:{...r,hint:U(r.hint,n)}}}}function U(e,t){return typeof e==`string`&&e.trim()!==``?`${e}\n${t}`:t}async function Te(e){let{device:t,node:n,flags:r,appBundleId:i,traceOutPath:a,surface:s,contextFromFlags:c}=e,l=oe(n),u=e.readTextAtPoint;if(!u)return l;let d=ue(n.rect);if(!d||o(t)&&l&&!ae(n.type??``))return l;let f=c(r,i,a),p=await u({point:d,options:{appBundleId:i,surface:s},execution:ge(f)});return p.status===`read`?p.text:(le({level:`warn`,phase:`interaction_read_fallback`,data:{reason:Ee(p.reason),nodeRef:n.ref,surface:s,platform:t.platform}}),l)}function Ee(e){switch(e){case`no-text-at-point`:return`no_text_at_point`;default:return e}}function W(e){let{session:t,sessionStore:n,sessionName:r}=e,i=0,a,o,s=t=>(e.consumedSnapshot&&(e.consumedSnapshot.state=t.snapshot),t);return{capture:async c=>{let l=Date.now(),u=Pe(c,e.req.flags?.out),d=Ae({timestamp:l,lastSnapshotAt:i,lastSnapshotResult:a,lastSnapshotCacheKey:o,session:t,request:c,cacheKey:u});if(d)return s(d);let f=je({session:t,timestamp:l,request:c});if(f)return i=f.createdAt,a={snapshot:f},o=u,s(a);let p=await De({params:e,request:c});c.signal?.throwIfAborted();let m={snapshot:p};return Ie({session:t,sessionStore:n,sessionName:r,snapshot:p}),i=l,a=m,o=u,s(m)}}}async function De(e){let{params:t,request:n}=e,r=await G(t,n,n.snapshotScope);return n.recovery?.legacyIosSparse&&se(r)?await Oe({runtimeParams:t,request:n,policy:n.recovery.legacyIosSparse}):n.recovery?.sparseVerdictQueryScope?.shouldScope&&w(r.snapshotQuality)?await ke({runtimeParams:t,request:n,policy:n.recovery.sparseVerdictQueryScope,snapshot:r}):r}async function Oe(e){let{runtimeParams:t,request:n,policy:r}=e;try{return await G(t,n,void 0,!1)}catch(e){if(!r.shouldScope)throw e;return await G(t,n,r.query,!1)}}async function ke(e){let{runtimeParams:t,request:n,policy:r,snapshot:i}=e;try{return await G(t,n,r.query,!1)}catch{return i}}async function G(e,t,n,r=t.flags?.snapshotInteractiveOnly){let i={...t.flags,snapshotInteractiveOnly:r},a=e.capture;return(await ve({device:e.device,session:e.session,flags:i,outPath:t.outPath??e.req.flags?.out,logPath:e.logPath??``,snapshotScope:n,includeRects:t.includeRects,signal:t.signal,captureData:async()=>await a(x({flags:i,logPath:e.logPath??``,meta:e.req.meta,session:e.session,snapshotScope:n,includeRects:t.includeRects,signal:t.signal}))})).snapshot}function Ae(e){let{timestamp:t,lastSnapshotAt:n,lastSnapshotResult:r,lastSnapshotCacheKey:i,session:a,request:o,cacheKey:s}=e;if(o.cache?.forceFresh!==!0&&r&&i===s&&!(t-n>=750)&&!b(a)&&!K(a,o))return r}function je(e){let{session:t,timestamp:n,request:r}=e,i=t?.snapshot;if(i&&Me(t,r)&&Ne(i,n)&&i.presentationKey===q(r))return i}function Me(e,t){return!(t.cache?.forceFresh===!0||t.cache?.useSessionSnapshot!==!0||b(e)||K(e,t))}function Ne(e,t){return t-e.createdAt<750}function K(e,t){return t.cache?.bypassForPostGestureStabilization===!0&&C(e)}function q(e){return n(a(Fe(e)))}function Pe(e,t){return JSON.stringify({presentationKey:q(e),includeRects:e.includeRects===!0,outPath:e.outPath??t??null})}function Fe(e){return e.snapshotScope===void 0?e.flags:{...e.flags,snapshotScope:e.snapshotScope}}function Ie(e){let{session:t,sessionStore:n,sessionName:r,snapshot:i}=e;!t||w(i.snapshotQuality)||(S(t,i),n.set(r,t))}function J(e){return re({backend:Re(e),...te(`selector commands`,{plural:!0}),sessions:he({sessionName:e.sessionName,getSession:()=>e.session,recordOptions:{includeSnapshot:!0},setRecord:t=>{!e.session||!t.snapshot||(S(e.session,t.snapshot),e.sessionStore.set(e.sessionName,e.session))}}),signal:e.signal??de(e.req.meta?.requestId)})}async function Le(e,t){e.consumedSnapshot??={};let n=e.sessionStore.get(e.sessionName);return!n&&t?{ok:!1,response:fe()}:{ok:!0,session:n,device:n?.device??await v(e.req.flags??{})}}async function Y(e,t){let n=await Le(e,t.requireSession);if(!n.ok)return n;let r=await R({command:t.command,device:n.device,session:n.session,inspectFacts:e.inspectFacts,bindDevice:e.bindDevice});return r.ok?{ok:!0,runtime:J({...e,session:n.session,device:n.device,bound:r.operations})}:{ok:!1,response:r.response}}function Re(e){let{req:t,session:n,device:r,logPath:i,sessionName:a,sessionStore:o}=e,c=e.contextFromFlags??((e,t,n)=>pe(i??``,e,t,n)),l=e.bound?.readText,u=e.bound?.findText,d=x({flags:t.flags,logPath:i??``,meta:t.meta,session:n,snapshotScope:void 0}).execution,f=e.bound,p=f===void 0?void 0:W({device:r,session:n,sessionStore:o,sessionName:a,req:t,consumedSnapshot:e.consumedSnapshot,logPath:i,capture:f.capture});return{platform:s(r),captureSnapshot:p&&(async(e,n)=>{let i={...t.flags,...E(n)},a=n?.includeRects===!0,o=n?.scope??t.flags?.snapshotScope,s=t.command===`wait`||t.command===`find`||ze(t)||a&&r.platform===`web`;return await p.capture({flags:i,signal:e.signal,snapshotScope:o,includeRects:a,cache:{forceFresh:s,useSessionSnapshot:!0,bypassForPostGestureStabilization:!0}})}),readText:async(e,i)=>({text:await Te({readTextAtPoint:l,device:r,node:i,flags:t.flags,appBundleId:n?.appBundleId,traceOutPath:n?.trace?.outPath,surface:n?.surface,contextFromFlags:c})}),...u?{findText:async(e,t)=>({found:(await u({text:t,options:{appBundleId:n?.appBundleId,surface:n?.surface},execution:d,...e.signal?{signal:e.signal}:{}})).found})}:{}}}function ze(e){if(e.command!==`is`)return!1;let t=p(e.positionals??[]);return t.ok&&t.predicate===`absent`}async function Be(e){let{req:t}=e;if(t.command!==`find`)return null;let n=t.positionals??[],r=c(n,t.flags);if(!r.ok)return y(r.code,r.message);let i=r.parsed,a=i.action;if(!d(a))return null;let o=await Y(e,{requireSession:!1,command:`find`});return o.ok?H(await Q(async()=>{let n=await o.runtime.selectors.find({session:e.sessionName,requestId:t.meta?.requestId,locator:i.locator,query:i.query,action:a,timeoutMs:i.timeoutMs});I(e.sessionStore,e.sessionName,t,k(n,a));let r=A(n),s=typeof r.ref==`string`?[r.ref]:Array.isArray(r.matches)?r.matches.map(e=>e.ref).filter(e=>typeof e==`string`):[];if(s.length>0){let t=e.sessionStore.get(e.sessionName);if(t&&(me(t,s),e.sessionStore.set(e.sessionName,t),t.snapshotGeneration!==void 0))return{...r,refsGeneration:t.snapshotGeneration}}return r}),X(e)):o.response}function X(e){return e.consumedSnapshot?.state??e.sessionStore.get(e.sessionName)?.snapshot}async function Ve(e){let{req:t}=e;if(t.command!==`get`)return null;let n=f(t.positionals?.[0]);if(!n.ok)return y(n.code,n.message);let r=n.format,i=Ue(t);if(!i.ok)return i.response;if(i.target.kind===`ref`){let e=z(`get`,t.flags);if(e)return e}let a=t.internal?.replayTargetGuard,o=await Y(e,{requireSession:!0,command:`get`});if(!o.ok)return o.response;let s=o.runtime,c=i.target.kind===`ref`?_e({session:e.sessionStore.get(e.sessionName),ref:i.target.ref,mintedGeneration:i.refGeneration}):void 0;return H(await Q(async()=>{let n=await s.selectors.get({session:e.sessionName,requestId:t.meta?.requestId,property:r,target:i.target,expectedResolvedTarget:a});I(e.sessionStore,e.sessionName,t,j(n,r),{node:n.node,preActionNodes:n.preActionNodes});let o=M(n);return c?{...o,warning:c}:o}),X(e))}async function He(e){let{req:t}=e;if(t.command!==`is`)return null;let n=p(t.positionals??[]);if(!n.ok)return y(n.code,n.message,n.hint?{hint:n.hint}:void 0);let{predicate:r,selectorExpression:i,expectedText:a}=n;if(r===`absent`){let e=ie({depth:t.flags?.snapshotDepth,scope:t.flags?.snapshotScope});if(e){let t=ce(e);return y(t.code,t.message,t.details)}}let o=t.internal?.replayTargetGuard,s=await Y(e,{requireSession:!0,command:`is`});return s.ok?H(await $(e,await Q(async()=>{let n=await s.runtime.selectors.is({session:e.sessionName,requestId:t.meta?.requestId,predicate:r,selector:i,expectedText:a,expectedResolvedTarget:o}),c=Z(n),l=N(n);return I(e.sessionStore,e.sessionName,t,l,c),F(l)}),`is ${r}`),X(e)):s.response}function Z(e){let t=e.node,n=e.preActionNodes;if(!(!t||typeof t!=`object`||!Array.isArray(n)))return{node:t,preActionNodes:n}}function Ue(e){let t=e.positionals?.[1]??``;if(t.startsWith(`@`)){let n=O(t);return n.ok?{ok:!0,target:{kind:`ref`,ref:n.ref,fallbackLabel:e.positionals.length>2?e.positionals.slice(2).join(` `).trim():``},refGeneration:n.generation}:{ok:!1,response:n.response}}let n=u(e.positionals?.slice(1)??[]);return n.ok?{ok:!0,target:{kind:`selector`,selector:`selector`in n?n.selector:``}}:{ok:!1,response:y(n.code,n.message)}}async function Q(e){try{return{ok:!0,data:await e()}}catch(e){let t=r(e);return y(t.code,t.message,t.details)}}async function $(e,t,n){if(t.ok)return t;let r=e.sessionStore.get(e.sessionName);if(!r)return t;let i;try{if(!e.androidObservation)return t;i=await B(r,e.androidObservation)}catch{return t}return i?y(t.error.code,`${n} failed because ${V(i)}.`,{...t.error.details??{},...i,blockedBy:`android_foreground_surface`,originalMessage:t.error.message}):t}export{O as _,$ as a,J as c,B as d,z as f,P as g,N as h,He as i,W as l,I as m,Be as n,Z as o,R as p,Ve as r,Q as s,X as t,H as u};
@@ -1 +1 @@
1
- import{dr as e,fn as t,hn as n,lr as r,or as i,sr as a,ur as o}from"./sdk-batch-runner.js";import{t as s}from"./sdk-selectors.js";export{t as findSelectorChainMatch,s as formatSelectorFailure,o as isNodeEditable,e as isNodeVisible,i as isSelectorToken,a as parseSelectorChain,n as resolveSelectorChain,r as tryParseSelectorChain};
1
+ import{br as e,gr as t,hr as n,vn as r,vr as i,xn as a,yr as o}from"./sdk-batch.js";import{t as s}from"./sdk-selectors.js";export{r as findSelectorChainMatch,s as formatSelectorFailure,o as isNodeEditable,e as isNodeVisible,n as isSelectorToken,t as parseSelectorChain,a as resolveSelectorChain,i as tryParseSelectorChain};
@@ -0,0 +1 @@
1
+ import{Dr as e,Hr as t,Rr as n,Vr as r,jr as i,zr as a}from"./sdk-batch.js";import{n as o,t as s}from"./scroll-indicator.js";import{a as c,i as l,o as ee,r as u}from"./react-native-overlay.js";import{t as d}from"./rect-center.js";import{a as f,c as te,d as p,f as m,g as ne,h,i as g,l as re,m as _,n as v,o as y,p as b,r as x,s as S,t as C,u as ie}from"./tree.js";function ae(e,t){let n=g(t.sourceNodesByIndex.values());for(let r of e)oe(r,t.sourceNodesByIndex,n)&&b(t.replacements,r,{type:`Cell`})}function oe(e,t,n){return!(i(e.type??``)!==`other`||e.enabled===!1||!e.rect||!le(e.label)||!f(e,t,ce)||!se(e)||re(e.rect,n))}function se(e){return e.rect?e.rect.height>=44&&e.rect.height<=160&&e.rect.width>=120:!1}function ce(e){let t=i(e.type??``);return t===`scrollview`||t===`scrollarea`}function le(e){let t=e?.trim();return!(!t||/^(toolbar|window|application)$/i.test(t)||t.startsWith(`!,`)||/debugger|fast refresh/i.test(t))}function ue(e,t){let n=new Set;for(let r of e)de(t.replacements.get(r.index)??r)&&fe(r,t.sourceNodesByIndex,t,n);pe(e,t,n)}function de(e){let t=e.label?.trim();return!!(t&&o(t))}function fe(e,t,n,r){let i=!p(e.type)||n.isSuppressed(e),a=s(e.label?.trim()??``,e.value),o=a?y(e,t,{includeSelf:!0}):void 0;i&&n.suppressNode(e,o?[o]:[]),o&&a&&j(n,o,e,a)&&r.add(o.index)}function pe(e,t,n){let r=new Map;for(let i of e){let e=r.get(i.parentIndex??-1),a=e?.clip,o=t.replacements.get(i.index)??i,s=k(o.rect,a),c=me(o,a,s),l=w(e,c,o);T(t,i,o,a,s,c,l),r.set(i.index,E(i,o,a,s,l,n))}}function me(e,t,r){return!!(t&&n(e.rect)&&!n(r))}function w(e,t,n){return!!(e?.projectedOut||t&&O(n))}function T(e,t,n,r,i,a,o){o||a?e.suppressNode(t,[]):r&&i&&!A(n.rect,i)&&b(e.replacements,t,{rect:i})}function E(e,t,n,r,i,a){return{projectedOut:i,...D(e,t,n,r,a)?{clip:r}:n?{clip:n}:{}}}function D(e,t,r,i,a){return!!(n(i)&&(a.has(e.index)||r!==void 0&&p(t.type)))}function O(e){return e.type?.trim().toLowerCase()===`cell`||p(e.type)}function k(e,t){if(!e||!t)return e;let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),i=Math.min(e.x+e.width,t.x+t.width),a=Math.min(e.y+e.height,t.y+t.height);return{x:n,y:r,width:Math.max(0,i-n),height:Math.max(0,a-r)}}function A(e,t){return!!(e&&e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height)}function j(e,t,n,r){let i=N((e.replacements.get(t.index)??t).rect,n.rect);return ne(e.replacements,t,e=>({rect:i??e.rect,hiddenContentAbove:M(e.hiddenContentAbove,r.above),hiddenContentBelow:M(e.hiddenContentBelow,r.below)})),!!i}function M(e,t){return e===!0||t?!0:void 0}function N(e,t){if(!(!e||!t)&&!(t.height<=0||t.height>=e.height)&&!(t.y<e.y||t.y>e.y+e.height))return{...e,y:t.y,height:Math.min(t.height,e.y+e.height-t.y)}}function P(e,t){for(let n=0;n<e.length;n+=1){let r=e[n],a=r?.label?.trim();r&&a&&i(r.type??``)===`other`&&t(r,a,n)}}function F(e,t){P(e,(n,r,i)=>{if(!c(r)||!n.rect)return;let a=x(e,i,e=>!!e.rect&&ee(e.label?.trim()??``));if(!a?.rect)return;let o=L(n.rect,a.rect);if(!o)return;let s=I(e,i,o);b(t,n,{rect:s}),S(e,i,e=>{c(e.label?.trim()??``)&&b(t,e,{rect:s})})})}function I(e,n,i){let a=i;return S(e,n,e=>{let n=e.label?.trim()??``;!e.rect||!c(n)||t(i,e.rect)&&r(e.rect)<r(a)&&(a=e.rect)}),a}function L(e,t){let n=e.x+e.width,r=t.x+t.width,i={x:t.x,y:e.y,width:n-t.x,height:e.height};if(t.x>e.x&&d(t,i))return{...e,width:t.x-e.x};let a={x:e.x,y:e.y,width:r-e.x,height:e.height};if(r<n&&d(t,a))return{...e,x:r,width:n-r}}function R(e,t){P(e,(n,r,i)=>{u(n)&&l(n,z(e,i))&&t.suppressNode(n,z(e,i))})}function z(e,t){let n=[];return S(e,t,e=>{n.push(e)}),n}function he(e,t){let n=g(e),r=n?n.y+n.height:null;if(r!==null)for(let n=0;n<e.length;n+=1){let i=e[n];!i||!ge(i,r)||(t.suppressNode(i,[]),_e(i,t,r),S(e,n,e=>{t.suppressNode(e,[])}))}}function ge(e,t){return!e.rect||i(e.type??``)!==`keyboard`?!1:e.rect.y>=t}function _e(e,t,n){let r=typeof e.parentIndex==`number`?t.sourceNodesByIndex.get(e.parentIndex):void 0;for(;r?.rect&&r.rect.y>=n;)t.suppressNode(r,[]),r=typeof r.parentIndex==`number`?t.sourceNodesByIndex.get(r.parentIndex):void 0}function ve(e,t){for(let n=0;n<e.length;n+=1){let r=e[n];if(!r)continue;if(ye(r)){B(e,n,r,t);continue}if(!be(r))continue;let a=x(e,n,e=>i(e.type??``)===`searchfield`&&e.label===`Search`);a&&(t.suppressNode(r,[a]),xe(r,a,t),B(e,n,a,t))}}function ye(e){return i(e.type??``)===`searchfield`&&e.label===`Search`}function be(e){let t=i(e.type??``);return e.label===`Toolbar`&&(t===`toolbar`||t===`searchfield`)}function B(e,t,n,r){S(e,t,e=>{e.index!==n.index&&Se(e)&&r.suppressNode(e,[n])})}function xe(e,t,n){let r=e;for(;typeof r.parentIndex==`number`;){let e=n.sourceNodesByIndex.get(r.parentIndex);if(!e||e.label!==`Toolbar`)return;n.suppressNode(e,[t]),r=e}}function Se(e){let t=i(e.type??``);return t===`button`?!1:t===`image`||e.label===`Search`}function Ce(e,t){for(let n=0;n<e.length;n+=1){let r=e[n],i=r?.label?.trim();!r||t.isSuppressed(r)||!i||we(e,n,r,i,t)}}function we(e,t,n,r,a){let o=i(n.type??``);if(o===`statictext`||o===`link`){V(e,t,r,n,a);return}if(o!==`other`)return;let s=Te(e,t,r);if(s){a.suppressNode(n,[s]);return}V(e,t,r,n,a)}function Te(e,t,n){return x(e,t,e=>{let t=i(e.type??``);return(t===`link`||t===`searchfield`||p(e.type))&&e.label?.trim()===n})}function V(e,t,n,r,i){S(e,t,e=>{!i.semanticRepresentativeIndexes.has(e.index)&&ie(e,n)&&i.suppressNode(e,[r])})}function Ee(e,t){P(e,(n,r,i)=>{let a=x(e,i,e=>m(e)&&e.label?.trim()===r&&(d(e.rect,n.rect)||De(n,e)));a&&t.suppressNode(n,[a])})}function De(e,t){if(t.label?.trim()!==e.label?.trim())return!1;let n=i(t.type??``);return Oe(e,n)||n===`textfield`||ke(e,n,t)}function Oe(e,t){let n=e.label?.trim();return t===`button`&&(n===`Dismiss`||n===`Back`)}function ke(e,t,n){return t!==`button`||!e.rect||!n.rect?!1:e.rect.x===0&&e.rect.y===0&&e.rect.width>=300&&e.rect.height>=600&&n.rect.width<e.rect.width}function Ae(e,t){let n=C(e);for(let r of e)i(r.type??``)===`other`&&(r.hittable===!0||r.label?.trim()||r.value?.trim()||r.identifier?.trim()&&t.suppressNode(r,je(r,n)))}function je(e,t){let n=[],r=new Set([e.index]),i=[...t.get(e.index)??[]];for(;i.length>0;){let e=i.pop();if(!e||r.has(e.index))continue;r.add(e.index),n.push(e);let a=t.get(e.index);a&&i.push(...a)}return n}function Me(e,t){he(e,t),Ae(e,t),ue(e,t),ve(e,t),Ee(e,t),F(e,t.replacements),R(e,t),Ce(e,t)}function Ne(e,t){for(let n=0;n<e.length;n+=1){let r=e[n],i=r?Pe(e,n,r,t):void 0;!r?.rect||!i||Le(e,n,r,i,t)}}function Pe(e,t,n,r){let a=n.label?.trim();if(i(n.type??``)!==`cell`||a&&!Fe(a,n.identifier)&&!o(a))return a;let s=v(e,t).find(Ie),c=s?.label?.trim();return!s||!c?a:(b(r.replacements,n,{label:c}),r.suppressNode(s,[n]),c)}function Fe(e,t){return t?.trim()===e&&/^[A-Z_$][A-Za-z0-9_$]*Cell$/.test(e)}function Ie(e){if(!e.label?.trim())return!1;let t=i(e.type??``);return t===`statictext`||t===`text`||t===`textview`}function Le(e,t,n,r,a){let o=i(n.type??``);if(o===`button`){H(v(e,t),r,a,n);return}if(o!==`cell`)return;let s=v(e,t);Re(s,n,r,a)||ze(s,n,r,a)}function Re(e,t,n,r){let i=e.find(e=>Ve(e,t,n));if(!i)return!1;let a=e.find(e=>U(e,t,n)),o=i.identifier?void 0:a?.identifier??t.identifier;return o&&b(r.replacements,i,{identifier:o}),r.suppressNode(t,[i]),Be(e,t,n,i,r),!0}function ze(e,t,n,r){let i=e.find(e=>U(e,t,n));if(!i){e.some(te)&&H(e,n,r,t);return}!t.identifier&&i.identifier&&b(r.replacements,t,{identifier:i.identifier}),r.suppressNode(i,[t]),H(e.filter(e=>e.index!==i.index),n,r,t)}function Be(e,t,n,r,i){for(let a of e)a.index!==r.index&&(U(a,t,n)||W(a,t)||He(a,r)||h(a,n))&&i.suppressNode(a,[r])}function H(e,t,n,r){for(let i of e)(h(i,t)||r&&W(i,r))&&n.suppressNode(i,r?[r]:[])}function U(e,t,n){if(i(e.type??``)!==`button`)return!1;let r=t.identifier?.trim(),a=e.identifier?.trim();return r&&a&&r===a?!0:e.label?.trim()===n&&d(e.rect,t.rect)}function W(e,t){return i(e.type??``)===`button`&&!e.label?.trim()&&!e.value?.trim()&&d(e.rect,t.rect)}function Ve(e,t,n){if(i(e.type??``)!==`switch`)return!1;let r=t.identifier?.trim(),a=e.identifier?.trim();return r&&a&&r===a?!0:e.label?.trim()===n}function He(e,t){if(i(e.type??``)!==`switch`||e.index===t.index)return!1;let n=e.label?.trim();return n===t.value?.trim()||n===`0`||n===`1`}const G=1.15;function Ue(e,t,n){let r=new Map(e.map((e,t)=>[e.index,t]));for(let[i,o]of e.entries()){let s=We(e,r,t,o,n);if(!s)continue;q(e,i,n);let c=J(s.shelfRect,2);for(let t of s.intermediateSiblings){if($e(t)||!t.rect||!a(t.rect,c))continue;let i=r.get(t.index);i!==void 0&&q(e,i,n)}}}function We(e,t,n,r,i){let a=Ge(r,n,i.sourceNodesByIndex);if(!a)return;let o=Je(e,t,a.siblings,a.position,a.parent);if(!(o<0))return{shelfRect:a.rect,intermediateSiblings:a.siblings.slice(a.position+1,o)}}function Ge(e,t,n){let r=Ye(e,K(t,e.index));if(!r)return;let i=qe(e,n);if(!i||!i.rect)return;let a=K(t,i.index),o=a.findIndex(t=>t.index===e.index);if(Ke(a,o,e,r))return{rect:r.rect,parent:i,siblings:a,position:o}}function K(e,t){return e.get(t)??[]}function Ke(e,t,n,r){if(t<1)return!1;let i=Xe(e,t,n);return i?!r.childActionsPresented||!Ze(i,r.actionButtons):!1}function qe(e,t){return typeof e.parentIndex==`number`?t.get(e.parentIndex):void 0}function Je(e,t,n,r,i){return n.findIndex((n,a)=>a>r&&Qe(e,t.get(n.index),n,i))}function Ye(e,n){if(!p(e.type)||!e.rect)return;let r=e.rect,a=n.filter(e=>i(e.type??``)===`button`&&e.rect);if(a.length===0&&e.hiddenContentBelow===!0)return{rect:r,childActionsPresented:!1,actionButtons:a};if(a.length<3)return;let o=a.map(e=>e.rect.x+e.rect.width/2);if(o.every((e,t)=>t===0||e>o[t-1]))return{rect:r,childActionsPresented:a.some(e=>t(r,e.rect)),actionButtons:a}}function Xe(e,t,n){if(!(!n.rect||t<1))for(let r=t-1;r>=0;--r){let t=e[r];if(!(!t.rect||!m(t))&&t.rect.x+t.rect.width/2<n.rect.x&&et(t.rect,J(n.rect,2)))return t}}function Ze(e,t){if(!e.rect||t.length===0)return!1;let n=Math.max(...t.map(e=>e.rect?.width??0)),r=Math.max(...t.map(e=>e.rect?.height??0));return e.rect.width>n*G||e.rect.height>r*G}function Qe(e,t,n,r){return t!==void 0&&i(n.type??``)===`other`&&d(n.rect,r.rect)&&!!x(e,t,m)}function q(e,t,n){let r=e[t];if(r){n.suppressNode(r,[]);for(let r of v(e,t))n.suppressNode(r,[])}}function $e(e){let t=i(e.type??``);return t===`textfield`||t===`securetextfield`||t===`searchfield`||t===`textview`}function J(e,t){return{x:e.x-t,y:e.y-t,width:e.width+t*2,height:e.height+t*2}}function et(e,t){return Math.max(e.y,t.y)<=Math.min(e.y+e.height,t.y+t.height)}function tt(e,t){let n=C(e);Ue(e,n,t),nt(e,n,t)}function nt(e,t,n){for(let r of e){if(i(r.type??``)!==`navigationbar`||!r.rect)continue;let e=t.get(r.index)??[],a=e.flatMap(t=>rt(t,e,r.rect));if(a.length!==1)continue;let{field:o,title:s,image:c,label:l}=a[0];b(n.replacements,o,{type:`Button`,label:l,enabled:!0,rect:st([c.rect,o.rect,s.rect])}),n.semanticRepresentativeIndexes.add(o.index),n.suppressNode(s,[o]),n.suppressNode(c,[o])}}function rt(t,n,r){let i=e(t);if(!it(t,i))return[];let a=X(n,e=>at(e,i)),o=X(n,Y);return a?.rect&&o?.rect&&ot(o.rect,t.rect,a.rect,r)?[{field:t,title:a,image:o,label:i}]:[]}function it(e,t){return i(e.type??``)===`textfield`&&e.enabled===!1&&!!e.rect&&!!t&&e.value?.trim()===t}function at(e,t){return i(e.type??``)===`statictext`&&e.label?.trim()===t&&!!e.rect}function Y(e){return i(e.type??``)===`image`&&!!e.identifier?.trim()&&!!e.rect}function X(e,t){let n=e.filter(t);return n.length===1?n[0]:void 0}function ot(e,n,r,i){let a=n.x-(e.x+e.width),o=r.x-(n.x+n.width);return t(i,e)&&t(i,n)&&t(i,r)&&a>=0&&a<=12&&o>=0&&o<=12&&Z(e,n)&&Z(n,r)}function Z(e,t){return Math.max(e.y,t.y)<=Math.min(e.y+e.height,t.y+t.height)}function st(e){let t=Math.min(...e.map(e=>e.x)),n=Math.min(...e.map(e=>e.y)),r=Math.max(...e.map(e=>e.x+e.width)),i=Math.max(...e.map(e=>e.y+e.height));return{x:t,y:n,width:r-t,height:i-n}}function ct(e,t){let n=C(e);for(let r of e){if(i(r.type??``)===`element(58)`){b(t.replacements,r,{type:`WebView`});continue}let e=lt(r,t.sourceNodesByIndex,n);if(e?.kind===`suppress`){t.suppressNode(r,[]);continue}e&&(b(t.replacements,r,{type:e.type,...e.type===`Heading`?{value:void 0}:{}}),t.semanticRepresentativeIndexes.add(r.index))}}function lt(e,t,n){if(i(e.type??``)!==`other`)return null;let r=f(e,t,ft),a=e.label?.trim();return!r||!a?null:dt(e,r,a)?{kind:`suppress`}:ut(e,a,n)?{kind:`semantic`,type:Q(e.value)?`Heading`:`StaticText`}:null}function ut(e,t,n){let r=n.get(e.index);if(r?.length!==1)return!1;let a=r[0];return i(a.type??``)===`statictext`&&a.label?.trim()===t&&!n.has(a.index)}function dt(e,t,n){return e.parentIndex===t.index&&t.label?.trim()===n&&!Q(e.value)}function ft(e){let t=i(e.type??``);return t===`webview`||t===`element(58)`}function Q(e){return/^[1-6]$/.test(e?.trim()??``)}const pt=[ct,tt,ae,Ne,Me];function mt(e){if(e.length===0)return{nodes:e,presentedIndexesBySourceIndex:new Map};let t=new Map,n=new Map,r=new Set,i=new Map(e.map(e=>[e.index,e])),a=new Set,o={replacements:t,semanticRepresentativeIndexes:r,sourceNodesByIndex:i,isSuppressed:e=>a.has(e.index),suppressNode(e,t){if(a.add(e.index),t.length===0)return;let r=n.get(e.index)??new Set;for(let e of t)r.add(e.index);n.set(e.index,r)}};for(let t of pt)t(e,o);if(a.size===0&&t.size===0)return{nodes:e,presentedIndexesBySourceIndex:new Map(e.map(e=>[e.index,[e.index]]))};let s=e.filter(e=>!a.has(e.index)).map(e=>t.get(e.index)??e),c=_(s,a,e),l=new Map(s.map((e,t)=>[e.index,c[t].index]));return{nodes:c,presentedIndexesBySourceIndex:new Map(e.map(e=>[e.index,$(e.index,l,n)]))}}function $(e,t,n,r=new Set){let i=t.get(e);if(i!==void 0)return[i];if(r.has(e))return[];r.add(e);let a=new Set;for(let i of n.get(e)??[])for(let e of $(i,t,n,r))a.add(e);return[...a].sort((e,t)=>e-t)}export{mt as t};
@@ -1,10 +1,10 @@
1
- import{_ as e,o as t}from"./sdk-contracts.js";import{_ as n}from"./sdk-batch-runner.js";import{i as r}from"./command-catalog.js";import{n as i}from"./version.js";import{a,i as o,r as s,t as ee}from"./command-tools.js";import{n as c}from"./internal/bin.js";import{i as l,n as u,t as d}from"./cli-help.js";const f=`agent-device drives iOS, Android, tvOS, Android TV, macOS, Linux, and web apps. Tools mirror CLI commands of the same name; CLI flags are camelCase properties (--settle -> settle: true).
1
+ import{C as e,s as t}from"./sdk-contracts.js";import{g as n}from"./sdk-batch.js";import{i as r}from"./catalog.js";import{r as i}from"./version.js";import{a,i as ee,r as o,t as te}from"./command-tools.js";import{i as s,r as c,t as l}from"./cli-help.js";const u=`agent-device drives iOS, Android, tvOS, Android TV, macOS, Linux, and web apps. Tools mirror CLI commands of the same name; CLI flags are camelCase properties (--settle -> settle: true).
2
2
 
3
3
  Start: known app -> call open {app, foreground: true} at once; do not probe with devices, apps, appstate, snapshot, or screenshot first. open returns the initial interactive snapshot with @refs. Unknown app id: devices, then apps, then open the discovered id; never invent ids. Existing session: continue from its state, do not reopen.
4
4
 
5
- Loop: press/click/fill/longpress/hover/scroll/back with settle: true; the response is the settled UI diff, continue from it. snapshot {interactiveOnly: true} only when the diff lacks the next target or did not settle. Verify with wait {kind: "text", text}, wait {selector}, is, get, or find; a bare screenshot is not verification. End with close.
5
+ Loop: press/click/fill/longpress/hover/scroll/back with settle: true; the response is the settled UI diff, continue from it. To reach an off-screen target, scroll {direction, until: "<selector>"} scrolls until it is on screen in one call, and direction "bottom" runs to the end of the content; repeated bare scrolls are the slow way to find something. snapshot {interactiveOnly: true} only when the diff lacks the next target or did not settle. Verify with wait {kind: "text", text}, wait {selector}, wait {absent: selector}, is, get, or find; a bare screenshot is not verification. End with close.
6
6
 
7
7
  Targets: copy refs byte-for-byte (@e12, @e12~s4; keep @ and any ~sN). Refs go stale after mutations. Prefer refs, then id/label/role selectors; coordinates last. On a sparse/AX-unavailable warning its refs and selectors are invalid: screenshot, read the image, press {x, y}, then snapshot the changed screen.
8
8
 
9
- Errors carry hints; follow them instead of re-planning. Call help only for specialized work (gestures, scripting, TV, macOS, web, remote, debugging) or an unclear command shape, never at startup.`;function p(){let e=new Set(n());return r().filter(t=>!e.has(t))}const m={name:`help`,description:`Usage guides. No topic: the full workflow card. topic = one of ${l().join(`, `)} for that guide, or a tool name for its complete flag reference. For specialized work or an unclear command shape only; not a startup step, not needed after an error that carries a hint.`,inputSchema:{type:`object`,properties:{topic:{type:`string`,description:`Guide topic or tool name; omit for the card.`}},additionalProperties:!1}},h=`CLI syntax over MCP: \`agent-device <command> <positionals> --flag\` = tool <command>; positionals are named properties (target, text, direction), flags camelCase (--settle -> settle: true, -i -> interactiveOnly: true). Terminal-only (no MCP tool; run in a shell): ${p().join(`, `)}.\n\n`;function te(e){let t=e.topic;if(t!==void 0&&typeof t!=`string`)return g(`Expected topic to be a string.`,!0);let n=t?d(c(t)):u();return n===null?g(`Unknown help topic: ${t}. ${m.description}`,!0):g(h+n)}function g(e,t=!1){return{isError:t,content:[{type:`text`,text:e}]}}const _=`2026-07-28`,v=[_],y=[`2025-11-25`,`2025-06-18`],b=[...v,...y],x=`server/discover`,S=new Set([`initialize`,`ping`]),C=`io.modelcontextprotocol/protocolVersion`,w=`io.modelcontextprotocol/clientCapabilities`,T=`io.modelcontextprotocol/clientInfo`,E=36e5;var D=class extends Error{requested;constructor(e){super(`Unsupported MCP protocol version: ${e}. Supported: ${b.join(`, `)}.`),this.requested=e}get data(){return{supported:b,requested:this.requested}}};function O(t,n){let r=R(R(n)._meta),i=z(r,C);if(i===void 0){if(t===x)throw new e(`INVALID_ARGS`,`Expected _meta["${C}"] on ${x}.`);return`legacy`}if(!b.includes(i))throw new D(i);if(!M(r[w]))throw new e(`INVALID_ARGS`,`Expected _meta["${w}"] to be an object.`);let a=r[T];if(a!==void 0&&!N(a))throw new e(`INVALID_ARGS`,`Expected _meta["${T}"] to be a valid Implementation.`);if(!v.includes(i)){if(t===x)throw new D(i);return`legacy`}return`modern`}function ne(e){let t=z(R(e),`protocolVersion`);return t!==void 0&&y.includes(t)?t:`2025-11-25`}function re(e,t){return t===`modern`&&S.has(e)}function k(){return{name:`agent-device`,version:i()}}function A(e,t){return t===`legacy`||typeof e!=`object`||!e?e:{resultType:`complete`,...e,_meta:{...e._meta,"io.modelcontextprotocol/serverInfo":k()}}}function j(e,t){return e===`modern`?{ttlMs:t,cacheScope:`public`}:void 0}function M(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function N(e){return!M(e)||!I(e.name)||!I(e.version)?!1:F(e.title,I)&&F(e.description,I)&&F(e.websiteUrl,I)&&F(e.icons,e=>Array.isArray(e)&&e.every(P))}function P(e){return!M(e)||!I(e.src)?!1:F(e.mimeType,I)&&F(e.sizes,L)&&F(e.theme,e=>e===`light`||e===`dark`)}function F(e,t){return e===void 0||t(e)}function I(e){return typeof e==`string`}function L(e){return Array.isArray(e)&&e.every(I)}function R(e){return M(e)?e:{}}function z(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:void 0}async function B(e){if(e.jsonrpc!==`2.0`||typeof e.method!=`string`)return G(e.id??null,-32600,`Invalid JSON-RPC request.`);if(e.id===void 0)return null;try{let t=O(e.method,e.params),n=await V(e.method,e.params,t);return W(e.id,A(n,t))}catch(t){return t instanceof D?G(e.id,-32022,t.message,t.data):t instanceof Y?G(e.id,-32601,t.message):G(e.id,-32602,t instanceof Error?t.message:String(t))}}async function V(e,t,n){if(re(e,n))throw new Y(`${e} was removed in MCP ${_}.`);switch(e){case`server/discover`:return{supportedVersions:b,capabilities:{tools:{}},instructions:f,ttlMs:E,cacheScope:`public`};case`initialize`:return{protocolVersion:ne(t),capabilities:{tools:{}},serverInfo:k(),instructions:f};case`ping`:return{};case`tools/list`:return{tools:[...s(),m],...j(n,E)};case`tools/call`:return await H(t);default:throw new Y(`Unsupported MCP method: ${e}`)}}async function H(e){let t=K(e),n=J(t,`name`);try{return n===`help`?te(q(t.arguments)):await ee.execute(n,q(t.arguments))}catch(e){return U(o(a(e)),!0)}}function U(e,t=!1){return{isError:t,content:[{type:`text`,text:e}]}}function W(e,t){return{jsonrpc:`2.0`,id:e,result:t}}function G(e,t,n,r){return{jsonrpc:`2.0`,id:e,error:{code:t,message:n,...r?{data:r}:{}}}}function K(t){if(!t||typeof t!=`object`||Array.isArray(t))throw new e(`INVALID_ARGS`,`Expected object parameters.`);return t}function q(e){return e===void 0?{}:K(e)}function J(t,n){let r=t[n];if(typeof r!=`string`||r.length===0)throw new e(`INVALID_ARGS`,`Expected ${n} to be a non-empty string.`);return r}var Y=class extends Error{};async function ie(){let e=ae(),t=new le(t=>{e.push(t)});process.stdin.setEncoding(`utf8`),process.stdin.on(`data`,e=>{try{t.push(e)}catch(e){$({jsonrpc:`2.0`,id:null,error:{code:-32700,message:e instanceof Error?e.message:String(e)}})}}),await new Promise(e=>{process.stdin.on(`end`,e),process.stdin.on(`close`,e),process.stdin.resume()}),await e.idle()}function ae(e={}){let t=e.handlePayload??oe,n=e.write??$,r=Promise.resolve();return{push:e=>{let i=ce(e);r=r.then(async()=>{let r=await t(e);r&&n(r)}).catch(e=>{n({jsonrpc:`2.0`,id:i,error:{code:-32603,message:e instanceof Error?e.message:String(e)}})})},idle:async()=>{await r}}}function oe(e){return Array.isArray(e)?X(e):Z(e)}async function X(e){let t=[];for(let n of e)t.push(...ue(await Z(n)));return t.length>0?t:null}async function Z(e){let n;try{n=t.parse(e)}catch{return se(Q(e))}return B(n)}function se(e){return{jsonrpc:`2.0`,id:e,error:{code:-32600,message:`Invalid JSON-RPC request.`}}}function ce(e){return Array.isArray(e)?e.length===1?Q(e[0]):null:Q(e)}function Q(e){if(e&&typeof e==`object`&&!Array.isArray(e)){let t=e.id;if(typeof t==`string`||typeof t==`number`||t===null)return t}return null}var le=class{buffer=``;sink;constructor(e){this.sink=e}push(e){for(this.buffer+=e;;){let e=this.tryReadLineMessage();if(e!==void 0){this.emit(e);continue}break}}tryReadLineMessage(){let e=this.buffer.indexOf(`
10
- `);if(e===-1)return;let t=this.buffer.slice(0,e).trim();return this.buffer=this.buffer.slice(e+1),t.length>0?t:void 0}emit(e){this.sink(JSON.parse(e))}};function ue(e){return e?[e]:[]}function $(e){process.stdout.write(`${JSON.stringify(e)}\n`)}export{ie as runAgentDeviceMcpServer};
9
+ Errors carry hints; follow them instead of re-planning. Call help only for specialized work (gestures, scripting, TV, macOS, web, remote, debugging) or an unclear command shape, never at startup.`;function d(){let e=new Set(n());return r().filter(t=>!e.has(t))}const f={name:`help`,description:`Usage guides. No topic: the full workflow card. topic = one of ${c().join(`, `)} for that guide, or a tool name for its complete flag reference. For specialized work or an unclear command shape only; not a startup step, not needed after an error that carries a hint.`,inputSchema:{type:`object`,properties:{topic:{type:`string`,description:`Guide topic or tool name; omit for the card.`}},additionalProperties:!1}},p=`CLI syntax over MCP: \`agent-device <command> <positionals> --flag\` = tool <command>; positionals are named properties (target, text, direction), flags camelCase (--settle -> settle: true, -i -> interactiveOnly: true). Terminal-only (no MCP tool; run in a shell): ${d().join(`, `)}.\n\n`;function ne(e){let t=e.topic;if(t!==void 0&&typeof t!=`string`)return m(`Expected topic to be a string.`,!0);let n=t?s(t):l();return n===null?m(`Unknown help topic: ${t}. ${f.description}`,!0):m(p+n)}function m(e,t=!1){return{isError:t,content:[{type:`text`,text:e}]}}const h=`2026-07-28`,g=[h],_=[`2025-11-25`,`2025-06-18`],v=[...g,..._],y=`server/discover`,b=new Set([`initialize`,`ping`]),x=`io.modelcontextprotocol/protocolVersion`,S=`io.modelcontextprotocol/clientCapabilities`,C=`io.modelcontextprotocol/clientInfo`,w=36e5;var T=class extends Error{requested;constructor(e){super(`Unsupported MCP protocol version: ${e}. Supported: ${v.join(`, `)}.`),this.requested=e}get data(){return{supported:v,requested:this.requested}}};function E(t,n){let r=I(I(n)._meta),i=L(r,x);if(i===void 0){if(t===y)throw new e(`INVALID_ARGS`,`Expected _meta["${x}"] on ${y}.`);return`legacy`}if(!v.includes(i))throw new T(i);if(!A(r[S]))throw new e(`INVALID_ARGS`,`Expected _meta["${S}"] to be an object.`);let a=r[C];if(a!==void 0&&!j(a))throw new e(`INVALID_ARGS`,`Expected _meta["${C}"] to be a valid Implementation.`);if(!g.includes(i)){if(t===y)throw new T(i);return`legacy`}return`modern`}function D(e){let t=L(I(e),`protocolVersion`);return t!==void 0&&_.includes(t)?t:`2025-11-25`}function O(e,t){return t===`modern`&&b.has(e)}function k(){return{name:`agent-device`,version:i()}}function re(e,t){return t===`legacy`||typeof e!=`object`||!e?e:{resultType:`complete`,...e,_meta:{...e._meta,"io.modelcontextprotocol/serverInfo":k()}}}function ie(e,t){return e===`modern`?{ttlMs:t,cacheScope:`public`}:void 0}function A(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function j(e){return!A(e)||!P(e.name)||!P(e.version)?!1:N(e.title,P)&&N(e.description,P)&&N(e.websiteUrl,P)&&N(e.icons,e=>Array.isArray(e)&&e.every(M))}function M(e){return!A(e)||!P(e.src)?!1:N(e.mimeType,P)&&N(e.sizes,F)&&N(e.theme,e=>e===`light`||e===`dark`)}function N(e,t){return e===void 0||t(e)}function P(e){return typeof e==`string`}function F(e){return Array.isArray(e)&&e.every(P)}function I(e){return A(e)?e:{}}function L(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:void 0}async function R(e){if(e.jsonrpc!==`2.0`||typeof e.method!=`string`)return U(e.id??null,-32600,`Invalid JSON-RPC request.`);if(e.id===void 0)return null;try{let t=E(e.method,e.params),n=await z(e.method,e.params,t);return H(e.id,re(n,t))}catch(t){return t instanceof T?U(e.id,-32022,t.message,t.data):t instanceof q?U(e.id,-32601,t.message):U(e.id,-32602,t instanceof Error?t.message:String(t))}}async function z(e,t,n){if(O(e,n))throw new q(`${e} was removed in MCP ${h}.`);switch(e){case`server/discover`:return{supportedVersions:v,capabilities:{tools:{}},instructions:u,ttlMs:w,cacheScope:`public`};case`initialize`:return{protocolVersion:D(t),capabilities:{tools:{}},serverInfo:k(),instructions:u};case`ping`:return{};case`tools/list`:return{tools:[...o(),f],...ie(n,w)};case`tools/call`:return await B(t);default:throw new q(`Unsupported MCP method: ${e}`)}}async function B(e){let t=W(e),n=K(t,`name`);try{return n===`help`?ne(G(t.arguments)):await te.execute(n,G(t.arguments))}catch(e){return V(ee(a(e)),!0)}}function V(e,t=!1){return{isError:t,content:[{type:`text`,text:e}]}}function H(e,t){return{jsonrpc:`2.0`,id:e,result:t}}function U(e,t,n,r){return{jsonrpc:`2.0`,id:e,error:{code:t,message:n,...r?{data:r}:{}}}}function W(t){if(!t||typeof t!=`object`||Array.isArray(t))throw new e(`INVALID_ARGS`,`Expected object parameters.`);return t}function G(e){return e===void 0?{}:W(e)}function K(t,n){let r=t[n];if(typeof r!=`string`||r.length===0)throw new e(`INVALID_ARGS`,`Expected ${n} to be a non-empty string.`);return r}var q=class extends Error{};async function J(){let e=Y(),t=new ce(t=>{e.push(t)});process.stdin.setEncoding(`utf8`),process.stdin.on(`data`,e=>{try{t.push(e)}catch(e){$({jsonrpc:`2.0`,id:null,error:{code:-32700,message:e instanceof Error?e.message:String(e)}})}}),await new Promise(e=>{process.stdin.on(`end`,e),process.stdin.on(`close`,e),process.stdin.resume()}),await e.idle()}function Y(e={}){let t=e.handlePayload??X,n=e.write??$,r=Promise.resolve();return{push:e=>{let i=se(e);r=r.then(async()=>{let r=await t(e);r&&n(r)}).catch(e=>{n({jsonrpc:`2.0`,id:i,error:{code:-32603,message:e instanceof Error?e.message:String(e)}})})},idle:async()=>{await r}}}function X(e){return Array.isArray(e)?ae(e):Z(e)}async function ae(e){let t=[];for(let n of e)t.push(...le(await Z(n)));return t.length>0?t:null}async function Z(e){let n;try{n=t.parse(e)}catch{return oe(Q(e))}return R(n)}function oe(e){return{jsonrpc:`2.0`,id:e,error:{code:-32600,message:`Invalid JSON-RPC request.`}}}function se(e){return Array.isArray(e)?e.length===1?Q(e[0]):null:Q(e)}function Q(e){if(e&&typeof e==`object`&&!Array.isArray(e)){let t=e.id;if(typeof t==`string`||typeof t==`number`||t===null)return t}return null}var ce=class{buffer=``;sink;constructor(e){this.sink=e}push(e){for(this.buffer+=e;;){let e=this.tryReadLineMessage();if(e!==void 0){this.emit(e);continue}break}}tryReadLineMessage(){let e=this.buffer.indexOf(`
10
+ `);if(e===-1)return;let t=this.buffer.slice(0,e).trim();return this.buffer=this.buffer.slice(e+1),t.length>0?t:void 0}emit(e){this.sink(JSON.parse(e))}};function le(e){return e?[e]:[]}function $(e){process.stdout.write(`${JSON.stringify(e)}\n`)}export{Y as createMcpPayloadQueue,X as handleMcpPayload,J as runAgentDeviceMcpServer};
@@ -0,0 +1 @@
1
+ import{C as e}from"./sdk-contracts.js";import{a as t}from"./request-cancellation.js";import{c as n,r,t as i}from"./device-session.js";import{assertLimrunUploadedAppAccess as a,resolveInstalledAppIdForAsset as o,resolveLimrunAppAsset as s}from"./app-catalog.js";async function c(e,t,n){let r=n?.initialApp,i=typeof r==`string`?r.trim():``;if(i)return a(n?.publicNetworkOnly),await s(e,t,i,n?.signal)}async function l(t,n){let r=await i(t).listApps(`user-installed`),a=o(n.name,r);if(a)return a;throw new e(`COMMAND_FAILED`,`Limrun installed ${n.name}, but its application identifier could not be resolved unambiguously.`,{asset:n.name,installedApps:r.map(e=>e.id)})}async function u(n){let i=await n.limrun.iosInstances.create({wait:!0,metadata:n.metadata,spec:{...n.region?{region:n.region}:{},...n.app?{initialAssets:[{kind:`App`,source:`AssetID`,assetId:n.app.id,launchMode:`RelaunchIfRunning`}]}:{}}});try{if(!i.status.apiUrl)throw new e(`COMMAND_FAILED`,`Limrun iOS instance did not expose apiUrl`);return await r({lease:n.lease,instanceId:i.metadata.id,device:t(`ios`,n.lease,i.metadata.id),apiUrl:i.status.apiUrl,token:i.status.token},n.dependencies)}catch(e){throw await n.limrun.iosInstances.delete(i.metadata.id).catch(()=>{}),e}}async function d(r){let i=await r.limrun.androidInstances.create({wait:!0,metadata:r.metadata,spec:{...r.region?{region:r.region}:{},...r.app?{initialAssets:[{kind:`App`,source:`AssetIDs`,assetIds:[r.app.id]}]}:{}}});try{if(!i.status.apiUrl||!i.status.adbWebSocketUrl)throw new e(`COMMAND_FAILED`,`Limrun Android instance did not expose API and ADB websocket endpoints`);return await n({lease:r.lease,instanceId:i.metadata.id,device:t(`android`,r.lease,i.metadata.id),apiUrl:i.status.apiUrl,token:i.status.token,adbUrl:i.status.adbWebSocketUrl},r.dependencies)}catch(e){throw await r.limrun.androidInstances.delete(i.metadata.id).catch(()=>{}),e}}export{d as allocateLimrunAndroidSession,u as allocateLimrunIosSession,l as resolvePreinstalledAppId,c as resolveRequestedLimrunAppAsset};
@@ -0,0 +1 @@
1
+ import{r as e}from"./session-paths.js";import t from"node:path";function n(e){return t.join(e,`runner.log`)}function r(n,r){let i=e(r&&r.length>0?r:`unknown`);return t.join(n,`requests`,`${i}.ndjson`)}function i(e){return{path:r(e.sessionDir,e.requestId),ref:{session:e.session,requestId:e.requestId&&e.requestId.length>0?e.requestId:`unknown`}}}function a(n,i){return r(t.join(n,`remote-diagnostics`,e(i.session)),i.requestId)}export{n as i,i as n,r,a as t};
@@ -0,0 +1 @@
1
+ function e(e){return Object.freeze({async observeRunnerSession(e){let{getRunnerSessionSnapshot:t}=await import(`./runner-client.js`).then(e=>e.h),n=await t(e);return n?{alive:n.alive,sessionId:n.sessionId}:void 0},async resolveSoleForegroundApp(t={}){try{let n=await e.listLocalDevices({platform:`ios`,iosSimulatorSetPath:t.simulatorSetPath,kind:`simulator`,booted:!0});if(n.length!==1)return;let[r]=n;if(!r)return;let{detectSoleRunningIosSimulatorApp:i}=await import(`./app-resolution.js`).then(e=>e.t),a=await i(r);return a?{device:r,app:{bundleId:a.bundleId}}:void 0}catch(t){if(e.shouldPropagateProbeError(t))throw t;return}}})}export{e as createAppleSessionObservation};
@@ -0,0 +1 @@
1
+ import{n as e}from"./path-resolution.js";import"./file.js";function t(e){return e.replaceAll(/[^a-zA-Z0-9._-]/g,`_`)}function n(e){let n=t(e);return n.length>0&&n!==`.`&&n!==`..`}function r(t,n){return e(t,{cwd:n})}export{n,t as r,r as t};
@@ -0,0 +1 @@
1
+ import e from"node:path";import t from"node:fs";function n(t){return e.join(t,`repair-tombstone.json`)}function r(e){let n;try{n=t.readFileSync(e,`utf8`)}catch{return}let r;try{r=JSON.parse(n)}catch{return}if(!(typeof r?.expiresAt!=`number`||r.expiresAt<=Date.now()))return r}function i(i){let a;try{a=t.readdirSync(i,{withFileTypes:!0})}catch{return}for(let t of a){if(!t.isDirectory())continue;let a=r(n(e.join(i,t.name)));if(a?.commitFailure)return{sessionName:t.name,tombstone:{...a,commitFailure:a.commitFailure}}}}export{r as n,n as r,i as t};
@@ -0,0 +1 @@
1
+ import{C as e}from"./sdk-contracts.js";import"./session-store.js";import t from"node:path";import n from"node:fs";import r from"node:crypto";const i=`default`;function a(e,t){let n=e.session||i;if(d(e))return n;let r=c(e);return r.kind===`cwd`?f(r.id,n):n}function o(e){return e.session||i}function s(e){let t=c(e);return t.kind===`cwd`?t:void 0}function c(t){if(t.meta?.sessionIsolation===`tenant`||t.flags?.sessionIsolation===`tenant`){let n=t.meta?.tenantId;if(!n)throw new e(`INTERNAL_ERROR`,`Tenant-scoped request reached session routing without an admitted tenant id`);return{kind:`tenant`,id:n}}if(d(t)||(t.session||i)!==i)return{kind:`named-local`};let n=m(t.meta?.cwd);return n?{kind:`cwd`,id:p(n)}:{kind:`global-default`}}function l(e,t){let n=e.sessionScope;return n?t.kind===`tenant`?n.kind===`tenant`&&n.id===t.id:n.kind===`tenant`?!1:t.kind!==`cwd`||n.kind===`named-local`||n.kind===`cwd`&&n.id===t.id:!1}function u(e,t){let n=s(e);return!n||t.sessionScope?.kind!==`cwd`?!1:t.sessionScope.id!==n.id}function d(e){if(e.meta?.sessionExplicit===!0)return!0;let t=e.flags?.session;return typeof t==`string`&&t.trim().length>0}function f(e,t){return`cwd:${e}:${t}`}function p(e){return r.createHash(`sha256`).update(e).digest(`hex`).slice(0,16)}function m(e){if(!e||e.trim().length===0)return;let t=h(e);return g(t)??t}function h(e){let r=t.resolve(e);try{return n.realpathSync.native(r)}catch{return r}}function g(e){let r=e;for(;;){if(n.existsSync(t.join(r,`.git`)))return r;let e=t.dirname(r);if(e===r)return;r=e}}export{c as a,o as i,u as n,l as o,a as r,d as t};
@@ -0,0 +1 @@
1
+ import{C as e}from"./sdk-contracts.js";import{i as t}from"./request-runtime-binding.js";function n(e,n){if(!n.available)return t(`UNSUPPORTED_OPERATION`,`${e} is not supported on this device`,{reason:n.reason},n.hint?{hint:n.hint}:void 0)}function r(t){if(t)return t;throw new e(`COMMAND_FAILED`,`Device runtime facts inspection is unavailable.`)}const i=new WeakMap;let a;(class e{static{a=(t,n)=>{let r=new e;return i.set(r,{device:Object.freeze({...t}),plan:n}),Object.freeze(r),r}}#e;constructor(){this.#e=void 0}get admitted(){return this.#e,!0}});function o(t){let n=i.get(t);if(n===void 0)throw new e(`COMMAND_FAILED`,`Runtime plan admission is not one minted by admitRuntimePlan; refusing to bind.`);return n}async function s(e){let t=await r(e.inspectFacts)(e.device);for(let n of e.plan.use.required){let e=t.operations[n];if(!e.available)return{admitted:!1,operation:n,fact:e}}return a(e.device,e.plan)}function c(t){if(t)return t;throw new e(`COMMAND_FAILED`,`Device runtime binding is unavailable.`)}export{o as a,n as i,c as n,r,s as t};
@@ -0,0 +1 @@
1
+ import{C as e,g as t,l as n,m as r,v as i}from"./sdk-contracts.js";import{l as a}from"./capture.js";import{r as o}from"./snapshot-capture-annotations.js";import{r as s}from"./snapshot-diagnostics.js";import{f as c}from"./android-input-ownership.js";import{c as l,d as u,v as d}from"./sdk-device.js";import{It as f,St as ee,Tr as te,ct as ne,lt as re,ot as ie,pt as ae,st as oe,vt as se,zt as ce}from"./sdk-batch.js";import{b as le,c as ue,x as de}from"./runtime.js";import{n as p}from"./success-text.js";import{i as m}from"./click-button.js";import{a as fe,r as h}from"./diagnostics.js";import{t as g}from"./timeouts.js";import"./diagnostics2.js";import"./retry.js";import{t as pe}from"./snapshot-state.js";import{i as me}from"./lease-context.js";import{i as _,n as he}from"./request-runtime-binding.js";import{t as ge}from"./interactor-types.js";import{randomInt as _e}from"node:crypto";var v=class e{#e;constructor(e){this.#e=e}get state(){return this.#e.state}get scope(){return this.#e.scope}get tree(){return this.#e.tree}get generation(){return this.#e.generation}static expire(t){return t.#e.state===`expired`?t:new e({...t.#e,state:`expired`})}};const ve=new v({state:`active`,scope:`all`,tree:void 0,generation:void 0});function ye(e){return new v({state:`active`,...e})}function be(e){return v.expire(e)}const xe=new WeakMap;function y(e){return e.refFrame??ve}function b(e){return y(e).generation??e.snapshotGeneration}function Se(e){return y(e).tree}function Ce(e){we(e),e.refFrame=be(y(e)),e.snapshotScopeSource=void 0}function we(e){let t=Te(e)+1;return xe.set(e,t),t}function Te(e){return xe.get(e)??0}function Ee(e){x(e,`all`)}function De(e,t){x(e,t)}function x(e,t){e.refFrame=ye({scope:t,tree:e.snapshot,generation:e.snapshotGeneration})}function S(e){return y(e).state}function C(e){return y(e).scope}function Oe(e){let t=e.ref.startsWith(`@`)?e.ref.slice(1):e.ref;return{admission:ke({session:e.session,refBody:t,mintedGeneration:e.mintedGeneration}),scope:C(e.session),currentGeneration:b(e.session)}}function ke(e){let{session:t,refBody:n,mintedGeneration:r}=e;if(S(t)===`expired`)return{admitted:!1,reason:`ref_frame_expired`};if(r!==void 0&&r!==b(t))return{admitted:!1,reason:`ref_generation_mismatch`};let i=C(t);if(i!==`all`){if(r===void 0)return{admitted:!1,reason:`plain_ref_requires_complete_frame`};if(!i.has(n))return{admitted:!1,reason:`ref_not_issued`}}return{admitted:!0}}const Ae=[250,400,600];function w(e){return e===`press`||e===`click`||e===`back`||e===`open`}function je(e){return e.map(e=>[e.depth??0,e.type??``,e.label??``,e.value??``,e.identifier??``,e.enabled===!1?`disabled`:`enabled`,e.hittable===!0?`hittable`:`not-hittable`].join(`|`))}function Me(e,t){return e<12?!1:t<=Math.floor(e*.2)}function Ne(e,t,n){return n.interactiveOnly&&e.snapshot.nodes.length===0&&e.rawNodeCount!==void 0&&e.rawNodeCount>=12?`empty-interactive`:n.mode===`ref-refresh`?null:Me(t.baselineCount,e.snapshot.nodes.length)?Pe(e.snapshot)?null:`sharp-drop`:t.routeComparable&&w(t.action)&&Fe(t.baselineSignatures,e.snapshot.nodes)?`stuck-route`:null}function Pe(e){return e.nodes.some(e=>e.hittable===!0||!!e.label?.trim()||!!e.value?.trim()||!!e.identifier?.trim())}function Fe(e,t){if(!e||e.length===0)return!1;let n=Math.max(e.length,t.length);if(n<12)return!1;let r=je(t),i=Math.min(e.length,r.length),a=0;for(let t=0;t<i;t+=1)e[t]===r[t]&&(a+=1);let o=Math.max(0,r.length-e.length),s=Math.max(0,e.length-r.length),c=Math.max(3,Math.floor(n*.15));return a>=Math.floor(n*.9)&&o<=c&&s<=c}async function Ie(e){let t=e.window.markedAt+e.retry.retryBudgetMs,n=await e.capture(),r=e.classify(n),i=0;for(let a of e.retry.delaysMs){if(!r)break;let o=t-Date.now();if(o<=0)break;await g(Math.min(a,o)),n=await e.capture(),i+=1,r=e.classify(n)}r||e.onTrustworthyCapture?.();let a=i>0||r?{action:e.window.action,retryCount:i,staleAfterRetries:!!r,reason:r??void 0}:void 0;return{...n,annotations:{...n.annotations,...o({freshness:a})}}}function Le(e,t,n=e.snapshot){if(e.device.platform!==`android`)return;let r=Re(e,n),i=r?.comparisonSafe===!0;e.androidSnapshotFreshness={action:t,markedAt:Date.now(),baselineCount:(r??n)?.nodes.length??0,baselineSignatures:i?je(r?.nodes??[]):void 0,routeComparable:i}}function Re(e,t){if(t?.comparisonSafe===!0)return t;let n=e.lastComparisonSafeSnapshot;return!n||n.comparisonSafe!==!0?t:Date.now()-n.createdAt<=5e3?n:t}function T(e){if(!e||e.device.platform!==`android`)return;let t=e.androidSnapshotFreshness;if(t){if(Date.now()-t.markedAt>2500){delete e.androidSnapshotFreshness;return}return t}}function E(e){!e||e.device.platform!==`android`||delete e.androidSnapshotFreshness}async function ze(e,t){return Ie({capture:e.capture,classify:n=>Ne({snapshot:n.snapshot,rawNodeCount:n.annotations.analysis?.rawNodeCount},t,{interactiveOnly:e.interactiveOnly,mode:e.androidFreshnessMode}),window:t,retry:{retryBudgetMs:1500,delaysMs:Ae},onTrustworthyCapture:()=>E(e.session)})}function Be(e,t){return`${[e,...t].join(` `).trim()} produced no visible change: the tree still matches its pre-gesture state. Either the container is already at its edge, or it ignores synthesized scrolls — a raw drag moves such lists: swipe x1 y1 x2 y2 (start inside the list).`}function Ve(e,t){return t?{...e,warnings:[...e.warnings??[],Be(t.action,t.positionals)]}:e}const He=`activity.launchConsole.launchArgs.clearAppState.verbose.iosXctestrunFile.iosXctestDerivedDataPath.iosXctestEnvDir.snapshotInteractiveOnly.snapshotPreferredBackend.snapshotDepth.snapshotScope.snapshotRaw.snapshotCustomActions.snapshotIncludeHiddenContentHints.count.intervalMs.delayMs.durationMs.holdMs.jitterPx.pixels.until.doubleTap.backMode.pauseMs.pattern`.split(`.`);function Ue(e){return Object.fromEntries(He.map(t=>[t,e?.[t]]))}function D(e,t,n,r,i,o){return{requestId:i??fe().requestId,appBundleId:n,runnerLeaseContext:me({meta:o}),logPath:e,traceLogPath:r,...Ue(t),screenshotCaptureBackend:t?.maestro?.screenshotCaptureBackend,...a(t),clickButton:m(t)}}function We(e){return e?.interactionOutcome?.retryOnNoChange===!0}function Ge(e){let{session:t,command:n,positionals:r,flags:i,preSnapshot:a}=e;if(!We(i)||!L(t))return;let o=$e(n);if(!o||!it(r))return;let s=M(a?.nodes??[]);s.length!==0&&(t.pendingInteractionOutcome={action:n,command:o,positionals:r,flags:j(i),markedAt:Date.now(),attemptsRemaining:2,preSignature:s})}function Ke(e){let t=e?.pendingInteractionOutcome;if(!(!e||!t)){if(!L(e)){O(e);return}if(Date.now()-t.markedAt>3e4){O(e);return}return t}}function O(e){e?.pendingInteractionOutcome&&(e.pendingInteractionOutcome=void 0)}async function k(e){let{pending:t,snapshot:n}=e,r=N(t.preSignature,M(n.nodes));if(r!==`unchanged`||t.attemptsRemaining<=0)return{retried:!1,change:r};let i=e.retryTap,a=i?R(t.positionals):void 0;if(!i||!a)return A(t,i?`unreadable-retry-point`:`device-runtime-unavailable`),{retried:!1,change:r};let o=Date.now();return--t.attemptsRemaining,await qe(i,e)?(h({level:`info`,phase:`interaction_no_change_retry`,data:{action:t.action,attemptsRemaining:t.attemptsRemaining,durationMs:Date.now()-o}}),{retried:!0,change:r}):(A(t,`retry-tap-unavailable`),{retried:!1,change:r})}async function qe(e,t){let{session:n,pending:r}=t,i=R(r.positionals);if(!i)return!1;try{return await e({device:n.device,point:i,context:{...D(t.logPath,r.flags,n.appBundleId,n.trace?.outPath),surface:n.surface}})}catch{return!1}}function A(e,t){h({level:`info`,phase:`interaction_no_change_retry_skipped`,data:{action:e.action,attemptsRemaining:e.attemptsRemaining,reason:t}})}function Je(e){h({level:e.attempts>0?`info`:`debug`,phase:`interaction_settled`,data:{action:e.pending.action,change:e.change,attempts:e.attempts,durationMs:Date.now()-e.startedAt}})}function Ye(e){h({level:`warn`,phase:`interaction_settle_timeout`,data:{action:e.pending.action,attempts:e.attempts,durationMs:Date.now()-e.startedAt}})}function j(e){if(!e?.interactionOutcome&&!e?.postGestureStabilization)return e;let{interactionOutcome:t,postGestureStabilization:n,...r}=e;return r}function M(e){let t=new Map,n=[],r=de(e);for(let i of e){let e=et(i,t,r);e&&n.push(e)}return n}function N(e,t){return e.length===0||t.length===0?`ambiguous`:F(e,t)?`unchanged`:`changed`}function P(e,t){return Math.abs(e.x-t.x)<=1&&Math.abs(e.y-t.y)<=1&&Math.abs(e.width-t.width)<=1&&Math.abs(e.height-t.height)<=1}function F(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){let r=e[n],i=t[n];if(!r||!i||r.key!==i.key||!P(r,i))return!1}return!0}function Xe(e,t){let n=I(e),r=I(t);if(n.size===0||r.size===0)return`ambiguous`;let i=0,a=!1;for(let[e,t]of n){let n=r.get(e);if(!n){a=!0;continue}if(i+=1,!P(t,n))return`changed`}if(i===0)return`ambiguous`;let o=r.size>i;return a&&o?`changed`:`unchanged`}function I(e){let t=new Map;for(let n of e)!n.identity||!n.discriminating||t.has(n.identity)||t.set(n.identity,n);return t}function Ze(e,t){let n=e.filter(e=>e.discriminating),r=t.filter(e=>e.discriminating);if(n.length===0||n.length!==r.length)return!1;let i=new Map(r.map(e=>[e.key,e]));for(let e of n){let t=i.get(e.key);if(!t||!P(e,t))return!1}return!0}function Qe(e,t){let n=new Map(t.filter(e=>e.discriminating).map(e=>[e.key,e])),r=0,i=0,a=0;for(let t of e){if(!t.discriminating)continue;let e=n.get(t.key);if(!e){r+=1;continue}n.delete(t.key),a+=1,P(t,e)||(i+=1)}return{onlyInBaseline:r,onlyInCurrent:n.size,rectMismatched:i,shared:a}}function L(e){return u(e.device)}function R(e){let t=Number(e[0]),n=Number(e[1]);return Number.isFinite(t)&&Number.isFinite(n)?{x:t,y:n}:void 0}function $e(e){if(e===`click`||e===`press`)return`press`}function et(e,t,n){if(!e.rect||!at(e.rect)||ot(e))return;let r=rt(e);if(!r)return;let i=t.get(r)??0;t.set(r,i+1);let a=tt(e);return{key:`${r}|#${i}`,...a?{identity:a}:{},x:Math.round(e.rect.x),y:Math.round(e.rect.y),width:Math.round(e.rect.width),height:Math.round(e.rect.height),discriminating:!nt(e,n)}}function tt(e){let t=[e.identifier,e.label,e.value].map(e=>typeof e==`string`?e.trim():``).join(`|`);if(t.replaceAll(`|`,``))return`${t}|${e.type??``}`}function nt(e,t){return te(e)||e.ref!==void 0&&t.has(e.ref)}function rt(e){let t=[e.identifier,e.label,e.value,e.type,e.role,e.enabled===!1?`disabled`:`enabled`,e.selected===!0?`selected`:`unselected`,e.hittable===!0?`hittable`:`not-hittable`].map(e=>typeof e==`string`?e.trim():``).join(`|`);return t.replaceAll(`|`,``)?t:void 0}function it(e){return e.length===2&&e.every(e=>Number.isFinite(Number(e)))}function at(e){return[e.x,e.y,e.width,e.height].every(e=>Number.isFinite(e))&&e.width>0&&e.height>0}function ot(e){return`${e.label??``} ${e.identifier??``}`.toLowerCase().includes(`scroll bar`)}const z=3500;function st(e){let{needsBaselineDistrust:t,baselineSignature:n,quietSignature:r,elapsedMs:i,distrustCapMs:a}=e;return!t||!n?.length||e.classifyBaselineEvidence(n,r)!==`unchanged`?`trust`:i<a?`distrust`:`accept-stale`}async function ct(e){let{pending:t,needsBaselineDistrust:n,hooks:r}=e,i=Date.now(),a=1,o=await B(r,e.initial),s=t.baselineSignature,c=t.baselineBackend,l=!1,u=1500;for(;a<2||Date.now()-i<u;){await g(200),a+=1;let e=await B(r);if(r.signaturesStable(o.signature,e.signature)){let d=Date.now()-i;if(s&&c!==e.backend){h({level:`debug`,phase:`post_gesture_snapshot_baseline_rebased`,data:{action:t.action,from:c,to:e.backend,attempts:a}}),s=e.signature,c=e.backend,l=!0,o=e;continue}let f=st({needsBaselineDistrust:n,baselineSignature:s,quietSignature:e.signature,elapsedMs:d,distrustCapMs:z,classifyBaselineEvidence:r.classifyBaselineEvidence});if(f===`distrust`){u=z,o=e;continue}return lt(f,t.action,a,d),ut(f,t,e,r,l)}o=e}return h({level:`warn`,phase:`post_gesture_snapshot_stabilization_timeout`,data:{action:t.action,attempts:a,durationMs:Date.now()-i}}),{value:o.value}}async function B(e,t){let n=t??await e.capture();return{value:n,...e.readSurface(n)}}function lt(e,t,n,r){if(e===`accept-stale`){h({level:`warn`,phase:`post_gesture_snapshot_stale_accept`,data:{action:t,attempts:n,durationMs:r,matchedPreGestureBaseline:!0}});return}h({level:n>2?`info`:`debug`,phase:`post_gesture_snapshot_stabilized`,data:{action:t,attempts:n,durationMs:r}})}function ut(e,t,n,r,i){if(e!==`accept-stale`)return{value:n.value};let a=t.baselineSignature;return a!==void 0&&r.surfacesIdentical(a,n.signature)?{value:n.value,gestureNoEffect:{action:t.action,positionals:t.positionals}}:(h({level:`info`,phase:`post_gesture_no_effect_vetoed`,data:{action:t.action,backend:n.backend,...i?{reason:`baseline_rebased`}:{reason:`surface_divergence`,...a===void 0?{}:r.summarizeDivergence(a,n.signature)}}}),{value:n.value})}function dt(e){let{session:t,command:n,action:r=n,positionals:i,flags:a,scheduleOutcomeRetry:o=!1,androidFreshnessBaseline:s}=e;o&&Ge({session:t,command:n,positionals:i,flags:a,preSnapshot:t.snapshot}),w(r)&&Le(t,r,s??t.snapshot),ft(t,r,i,a)}function ft(e,t,n=[],r){if(!G(e.device)||!vt(t,n,r))return;let i=K(e.device)?M(e.snapshot?.nodes??[]):void 0;e.postGestureStabilization={action:t,positionals:n,markedAt:Date.now(),...i?.length?{baselineSignature:i,baselineBackend:W(e.snapshot)}:{}}}function pt(e){e?.postGestureStabilization&&(e.postGestureStabilization=void 0)}function V(e){return!!e?.postGestureStabilization}async function mt(e){let t=Ke(e.session);if(t&&e.session)return await ht({...e,session:e.session},t);if(u(e.device)&&e.session&&V(e.session))return await gt({...e,session:e.session});let n=T(e.session);if(n&&e.device.platform===`android`){let t=await ze(e,n);return{snapshot:t.snapshot,...t.annotations}}}async function ht(e,t){let n=e.session,r=Date.now(),i=0,a=await H(e,t,await U(e)),o=await k({session:n,pending:t,logPath:e.logPath,snapshot:a.snapshot,retryTap:e.retryTap});for(;o.retried;)i+=1,a=await H(e,t,await U(e)),o=await k({session:n,pending:t,logPath:e.logPath,snapshot:a.snapshot,retryTap:e.retryTap});O(n);let s=await _t({session:n,initial:a,capture:async()=>await U(e),readSnapshot:e=>e.snapshot});return a=s.value,o.change!==`ambiguous`&&a.annotations.freshness?.staleAfterRetries!==!0&&E(n),o.change===`unchanged`?Ye({pending:t,attempts:i,startedAt:r}):Je({pending:t,change:o.change,attempts:i,startedAt:r}),{snapshot:a.snapshot,...Ve(a.annotations,s.gestureNoEffect)}}async function H(e,t,n){let r=n;return N(t.preSignature,M(r.snapshot.nodes))===`unchanged`?(await g(500),r=await U(e),r):r}async function gt(e){let t=await _t({session:e.session,capture:async()=>await U(e),readSnapshot:e=>e.snapshot}),n=t.value;return{snapshot:n.snapshot,...Ve(n.annotations,t.gestureNoEffect)}}async function U(e){let t=T(e.session);return t&&e.device.platform===`android`?await ze(e,t):await e.capture()}async function _t(e){let{session:t,capture:n,readSnapshot:r}=e,i=t?.postGestureStabilization;if(!t||!G(t.device)||!i)return{value:e.initial??await n()};let a=await ct({pending:{action:i.action,positionals:i.positionals??[],baselineSignature:i.baselineSignature,baselineBackend:i.baselineBackend},needsBaselineDistrust:K(t.device),initial:e.initial,hooks:{capture:n,readSurface:e=>{let t=r(e);return{signature:M(t.nodes),backend:W(t)}},signaturesStable:F,classifyBaselineEvidence:Xe,surfacesIdentical:Ze,summarizeDivergence:Qe}});return pt(t),a}function W(e){return e?.comparisonKey??e?.snapshotQuality?.backend}function vt(e,t,n){return n?.postGestureStabilization===!1?!1:n?.postGestureStabilization===!0||e===`swipe`||e===`scroll`||e===`gesture`&&t[0]===`swipe`}function G(e){return u(e)}function K(e){return l(e.platform)}let q;async function J(){if(q)return q;let{createAppleSessionObservation:e}=await import(`./session-observation.js`),{listLocalDeviceInventory:t,shouldPropagateDeviceInventoryProbeError:n}=await import(`./device-inventory-context.js`).then(e=>e.t);return q??=e({listLocalDevices:t,shouldPropagateProbeError:n}),q}const yt=Object.freeze({async observeRunnerSession(e){return(await J()).observeRunnerSession(e)},async resolveSoleForegroundApp(e){return(await J()).resolveSoleForegroundApp(e)}});async function bt(e,t,n,r){let{queryAppleRunnerSelector:i}=await import(`./runner-operations-facade.js`);return await i(e,t,n,r)}async function Y(e){let t=await Ct(e.inspectFacts)(e.device);for(let n of e.required){let r=t.operations[n];if(!r.available)return{type:`response`,response:e.unavailableResponse?e.unavailableResponse(r):_(`UNSUPPORTED_OPERATION`,`${e.command} is not supported on this device`,void 0,r.hint?{hint:r.hint}:void 0)}}return{type:`admitted`,bind:wt(e.bindDevice)}}async function xt(e){let t=await Y({...e,required:e.use.required});if(t.type===`response`)return t;let n=await t.bind(e.device,e.use);return e.readiness!==void 0&&await he(n,e.readiness),{type:`runtime`,runtime:n}}async function St(e,t){let n=await xt(e);if(n.type===`response`)return{ok:!1,response:n.response};let r=n.runtime;return{ok:!0,execute:async({dispatchContext:e})=>await t(r,e)}}function Ct(t){if(t)return t;throw new e(`COMMAND_FAILED`,`Device runtime facts inspection is unavailable.`,{reason:`runtime-gateway-missing`})}function wt(t){if(t)return t;throw new e(`COMMAND_FAILED`,`Device runtime binding is unavailable.`,{reason:`runtime-gateway-missing`})}function Tt(e){let{flags:t,logPath:r,meta:a,session:o,snapshotScope:s}=e,{appBundleId:c,trace:l,surface:u}=o??{},d=e.context??D(r??``,t,c,l?.outPath,a?.requestId,a);return{options:{appBundleId:c,...i(t,n),scope:s,includeRects:e.includeRects,surface:u},execution:X(d),...e.signal===void 0?{}:{signal:e.signal}}}function X(e){return{requestId:e.requestId,verbose:e.verbose,logPath:e.logPath,traceLogPath:e.traceLogPath,iosXctestrunFile:e.iosXctestrunFile,iosXctestDerivedDataPath:e.iosXctestDerivedDataPath,iosXctestEnvDir:e.iosXctestEnvDir,runnerLeaseContext:e.runnerLeaseContext}}async function Et(e){let{getInteractor:t}=await import(`./interactors.js`),n=await(await t(e.device,e.runnerContext)).snapshot(e.options);if(!(`stage`in n))return n;let{presentIosSnapshotAcquisition:r}=await import(`./ios-snapshot-runtime.js`);return await r(n,e.options)}function Dt(e){let t=e?e.textEntryReadiness:void 0,n=Mt(t)?{textEntryReadiness:t}:{},r=Ot(e);return r?{...n,...r}:n}function Ot(e){if(!kt(e))return null;let t=At(e.target);return t?{verification:`unconfirmed`,requested:e.requested,before:e.before,after:e.after,target:t}:null}function kt(e){return!!(e&&e.verification===`unconfirmed`&&typeof e.requested==`string`&&Z(e.before)&&Z(e.after))}function At(e){if(!Q(e)||!jt(e))return null;let t=Nt(e.rect);return t?{resourceId:e.resourceId,className:e.className,packageName:e.packageName,rect:t}:null}function jt(e){return Z(e.resourceId)&&Z(e.className)&&Z(e.packageName)}function Mt(e){return typeof e==`string`&&ge.includes(e)}function Z(e){return e===null||typeof e==`string`}function Nt(e){return!Q(e)||![e.x,e.y,e.width,e.height].every(e=>typeof e==`number`)?null:e}function Q(e){return!!e&&typeof e==`object`}async function Pt(e){let t={device:e.device,inspectFacts:e.inspectFacts,bindDevice:e.bindDevice},n=f(e.command,e.requiresCapture),r=await Y({command:e.command,required:n.use.required,...e.unavailableResponse?{unavailableResponse:e.unavailableResponse}:{},...t});if(r.type===`response`)return{ok:!1,response:r.response};let i=r.bind;switch(n.kind){case`tap-point`:return{ok:!0,runtime:{kind:`tap`,captured:!1,runtime:await i(e.device,ce)}};case`captured-tap`:return{ok:!0,runtime:{kind:`tap`,captured:!0,runtime:await i(e.device,re)}};case`long-press-point`:return{ok:!0,runtime:{kind:`long-press`,captured:!1,runtime:await i(e.device,ee)}};case`captured-long-press`:return{ok:!0,runtime:{kind:`long-press`,captured:!0,runtime:await i(e.device,ne)}};case`hover-point`:return{ok:!0,runtime:{kind:`hover`,captured:!1,runtime:await i(e.device,se)}};case`captured-hover`:return{ok:!0,runtime:{kind:`hover`,captured:!0,runtime:await i(e.device,oe)}};case`fill-point`:return{ok:!0,runtime:{kind:`fill`,captured:!1,runtime:await i(e.device,ae)}};case`captured-fill`:return{ok:!0,runtime:{kind:`fill`,captured:!0,runtime:await i(e.device,ie)}}}}function Ft(e,t){let n={execution:X(t),appBundleId:t.appBundleId},r=e.captured?Vt(e.runtime):void 0;switch(e.kind){case`tap`:return It(e,t,n,r);case`long-press`:return Lt(e,n,r);case`hover`:return Rt(e,n,r);case`fill`:return zt(e,t,n,r)}}function It(e,t,n,r){let i=e.captured?e.runtime.operations.tapRef:void 0,a=e.captured?e.runtime.operations.tapElementSelector:void 0;return Object.freeze({captureSnapshot:r,tapPoint:async(r,i={})=>{let a=Ht(i,t),o=await e.runtime.operations.tapPoint({point:r,options:a,...n});return{x:r.x,y:r.y,count:a.count,intervalMs:a.intervalMs,holdMs:a.holdMs,jitterPx:a.jitterPx,doubleTap:a.doubleTap,...a.button===`primary`?{}:{button:a.button},...o??{},...p(Gt(r,a.button))}},tapRef:i?async e=>await i({ref:e,...n}):void 0,tapElementSelector:e.captured&&a?async t=>{let r=await e.runtime.operations.tapElementSelector?.({selector:t,...n}),i=r?.maestroNonHittableCoordinateFallbackUsed===!0;return{selector:t.raw,...r??{},...p(i?`tapped via non-hittable coordinate fallback`:`Tapped ${t.raw}`)}}:void 0})}function Lt(e,t,n){return Object.freeze({captureSnapshot:n,longPressPoint:async(n,r)=>{let i=await e.runtime.operations.longPressPoint({point:n,durationMs:r,...t});return{x:n.x,y:n.y,durationMs:r,...i??{},...p(`Long pressed (${n.x}, ${n.y})`)}}})}function Rt(e,t,n){let r=e.captured?e.runtime.operations.hoverRef:void 0;return Object.freeze({captureSnapshot:n,hoverPoint:async n=>{let r=await e.runtime.operations.hoverPoint({point:n,...t});return{x:n.x,y:n.y,...r??{},...p(`Hovered (${n.x}, ${n.y})`)}},hoverRef:r?async e=>await r({ref:e,...t}):void 0})}function zt(e,t,n,r){let i=e.captured?e.runtime.operations.fillRef:void 0,a=e=>le(e??t.delayMs??0,`delay-ms`,0,1e4);return Object.freeze({captureSnapshot:r,fillPoint:async(t,r,i={})=>{let o=a(i.delayMs),s=await e.runtime.operations.fillPoint({point:t,text:r,delayMs:o,allowNonHittableCoordinateFallback:i.allowNonHittableCoordinateFallback===!0,...n});return{x:t.x,y:t.y,text:r,delayMs:o,...Bt(s)?{maestroNonHittableCoordinateFallbackUsed:!0}:{},...Dt(s),...p(`Filled ${Array.from(r).length} chars`)}},fillRef:i?async(e,t,r={})=>await i({ref:e,text:t,delayMs:a(r.delayMs),...n}):void 0})}function Bt(e){return typeof e==`object`&&!!e&&`maestroNonHittableCoordinateFallbackUsed`in e&&e.maestroNonHittableCoordinateFallbackUsed===!0}function Vt(e){return async t=>await e.operations.captureSnapshot(t)}function Ht(e,t){let n=Ut(e,t);return Wt(n),{button:e.button??m(t),...n,surface:e.surface??t.surface}}function Ut(e,t){return{count:$(e.count,t.count,1,`count`,1,200),intervalMs:$(e.intervalMs,t.intervalMs,0,`interval-ms`,0,1e4),holdMs:$(e.holdMs,t.holdMs,0,`hold-ms`,0,1e4),jitterPx:$(e.jitterPx,t.jitterPx,0,`jitter-px`,0,100),doubleTap:e.doubleTap??t.doubleTap??!1}}function $(e,t,n,r,i,a){return le(e??t??n,r,i,a)}function Wt(t){if(t.doubleTap&&t.holdMs>0)throw new e(`INVALID_ARGS`,`double-tap cannot be combined with hold-ms`);if(t.doubleTap&&t.jitterPx>0)throw new e(`INVALID_ARGS`,`double-tap cannot be combined with jitter-px`)}function Gt(e,t){return t===`primary`?`Pressed (${e.x}, ${e.y})`:`${t===`secondary`?`Right`:`Middle`} clicked (${e.x}, ${e.y})`}function Kt(e){let{inspectFacts:t,bindDevice:n}=e;if(!t||!n)return;let r=new Map;return async({device:e,point:i,context:a})=>{let o=r.get(e.id);o||(o=Pt({device:e,command:`press`,requiresCapture:!1,inspectFacts:t,bindDevice:n}),r.set(e.id,o));let s=await o;if(!s.ok)return!1;let c=Ft(s.runtime,a);return c.tapPoint?(await c.tapPoint(i),!0):!1}}async function qt(e){let t=await mt({session:e.session,device:e.device,logPath:e.logPath,interactiveOnly:e.flags?.snapshotInteractiveOnly===!0,androidFreshnessMode:e.androidFreshnessMode,capture:()=>Yt(e),retryTap:Kt(e)});if(t)return t;let n=await Yt(e);return E(e.session),{snapshot:n.snapshot,...n.annotations}}async function Jt(e){if(e.captureData)return await e.captureData();let{device:t,session:r,logPath:a}=e,o=D(a,Xt(e),r?.appBundleId,r?.trace?.outPath);return await Et({device:t,runnerContext:{requestId:o.requestId,signal:e.signal,appBundleId:o.appBundleId,verbose:o.verbose,logPath:o.logPath,traceLogPath:o.traceLogPath,iosXctestrunFile:o.iosXctestrunFile,iosXctestDerivedDataPath:o.iosXctestDerivedDataPath,iosXctestEnvDir:o.iosXctestEnvDir,runnerLeaseContext:o.runnerLeaseContext},options:{appBundleId:o.appBundleId,signal:e.signal,...i(o,n),includeRects:e.includeRects,surface:r?.surface}})}async function Yt(e){let t=Date.now(),n=await Jt(e);s(e.session,{durationMs:Date.now()-t,backend:n.backend,platform:d(e.device)});let r=o(n),i=c(n,pe(n,Xt(e)));return r.androidSnapshot?.systemSurfaceOnly===!0&&(i.systemSurfaceOnly=!0),{data:n,snapshot:i,annotations:r}}function Xt(e){return e.snapshotScope===void 0?e.flags:{...e.flags,snapshotScope:e.snapshotScope}}function Zt(e,n){if(!e||!e.trim().startsWith(`@`))return{ok:!0,scope:e};if(!n?.snapshot)return _(`INVALID_ARGS`,`Ref scope requires an existing snapshot in session.`);let i=t(e.trim());if(!i)return _(`INVALID_ARGS`,`Invalid ref scope: ${e}`);let a=[n.snapshot,...n.snapshotScopeSource?[n.snapshotScopeSource]:[]],o;for(let e of a){let t=r(e.nodes,i);if(o=t?ue(t,e.nodes):void 0,o)break}return o?{ok:!0,scope:o}:_(`COMMAND_FAILED`,`Ref ${e} not found or has no label`)}function Qt(e,t,n={}){if(!e)return;let r=Se(e);return{name:t,appBundleId:e.appBundleId,appName:e.appName,...n.includeSnapshot===!0?{snapshot:e.snapshot,...r&&n.omitRefFrameSnapshot!==!0?{refFrameSnapshot:r}:{}}:{},metadata:{surface:e.surface,...n.metadata??{}}}}function $t(e){return{get:t=>t===e.sessionName?Qt(e.getSession(),e.sessionName,e.recordOptions):void 0,set:t=>{if(t.name!==e.sessionName){h({level:`warn`,phase:`runtime_session_write_skipped`,data:{expected:e.sessionName,received:t.name}});return}e.setRecord(t)}}}function en(e,t){e.snapshot!==t&&(e.snapshotGeneration=nn(e.snapshotGeneration)),e.snapshot=t,e.snapshotScopeSource=void 0,t.comparisonSafe===!0&&(e.lastComparisonSafeSnapshot=t)}function tn(e,t){e.snapshotScopeSource=t.scopeSource,e.snapshotGeneration=t.keptCurrentSnapshot?t.previousGeneration:nn(t.previousGeneration)}function nn(e){return e===void 0?_e(1e5,1e6):e+1}function rn(e){let t=e.startsWith(`@`)?e.slice(1):e,n=t.indexOf(`~`);return n===-1?t:t.slice(0,n)}function an(e,t){let n=new Set;for(let e of t){let t=rn(e);t.length>0&&n.add(t)}n.size!==0&&De(e,n)}function on(e,t){if(t?.diff)return an(e,sn(t)),e.snapshotGeneration}function sn(e){let t=[];for(let n of e.diff?.lines??[])n.ref&&t.push(n.ref);for(let n of e.refs??[])t.push(n.ref);for(let n of e.tail??[])t.push(n.ref);return t}function cn(e){return`Ref @${e.ref.startsWith(`@`)?e.ref.slice(1):e.ref} was minted from snapshot s${e.mintedGeneration} but the session's ref frame is now s${e.currentFrameEpoch} — re-run snapshot -i.`}function ln(e){let{session:t,ref:n,mintedGeneration:r}=e;if(t&&S(t)===`expired`)return`The UI may have changed since these refs were issued, so they no longer represent current device state. Take a new snapshot before relying on or interacting with them.`;if(r!==void 0){let e=t?b(t)??0:0;if(r!==e)return cn({ref:n,mintedGeneration:r,currentFrameEpoch:e})}}export{T as C,Te as D,Oe as E,y as O,D as S,Ce as T,yt as _,tn as a,dt as b,Jt as c,Pt as d,Tt as f,St as g,xt as h,en as i,Zt as l,Y as m,an as n,$t as o,X as p,ln as r,qt as s,on as t,Ft as u,bt as v,Ee as w,j as x,V as y};
@@ -0,0 +1,4 @@
1
+ import{C as e,z as t}from"./sdk-contracts.js";import{g as n}from"./sdk-batch-runner.js";import{A as r,V as i,s as a}from"./registry.js";import{i as o,r as s,t as c,v as l}from"./sdk-device.js";import{Jn as ee,b as te,f as ne,qn as re,rn as u,tn as ie}from"./sdk-batch.js";import{i as ae}from"./scroll-gesture.js";import{_ as d,c as oe,d as se,g as ce,h as le,i as ue,l as de,m as fe,o as pe,p as f,s as me,u as p,y as he}from"./script.js";import{A as ge,C as _e,D as ve,E as ye,M as be,N as xe,O as Se,S as Ce,T as we,_ as m,a as Te,b as Ee,c as De,i as Oe,n as ke,o as Ae,r as je,t as Me,u as Ne,v as Pe,w as Fe,x as Ie,y as Le}from"./parameterized-recorded-fill.js";import{n as h,t as g}from"./catalog.js";import{t as Re}from"./session.js";import{n as ze}from"./success-text.js";import{t as Be}from"./click-button.js";import"./device.js";import{t as _}from"./device-rotation.js";import{a as v,r as y}from"./diagnostics.js";import{D as Ve}from"./owner-identity.js";import"./file.js";import{t as He}from"./tv-remote.js";import"./diagnostics2.js";import{n as Ue,r as We}from"./session-repair-tombstone.js";import{n as Ge,r as b,t as x}from"./session-paths.js";import"./command-schema.js";import{t as Ke}from"./keyboard-actions.js";import S from"node:path";import C from"node:fs";import{createHash as qe}from"node:crypto";import{StringDecoder as Je}from"node:string_decoder";function Ye(e,t={}){let n=[e.command];return e.command===`snapshot`?se(n,e):e.command===`open`?ue(n,e):e.command===`runtime`?oe(n,e,{includeAllPositionals:t.runtimeIncludeAllPositionals}):e.command===`record`?me(n,e):e.command===`screenshot`?de(n,e):pe(n,e),n.join(` `)}function Xe(e){return e.targetEvidences?[re(e.targetEvidences)]:e.targetEvidence?[ee(e.targetEvidence)]:[]}function w(e){return e?.scriptPublication??m}function Ze(e,t){let n=w(e),r=typeof t.saveScript==`string`?x(t.saveScript):n.kind===`repair`?void 0:t.healedSiblingPath;e.scriptPublication=Le(n,{requested:{path:r,force:t.force===!0},boundary:t.firstArm?e.actions.length:0,sourcePath:t.sourcePath})}function Qe(e){e.scriptPublication=Ie(w(e))}function $e(e){e.scriptPublication=we(w(e))}function et(e,t){e.scriptPublication=ye(w(e),t)}function tt(e){e.scriptPublication=Pe(w(e))}function nt(e,t){let n=w(e);return n.kind===`repair`&&n.closeReceipt===t}function rt(e){return w(e).kind===`repair`}function it(e){return Fe(w(e))}function T(e){return ve(w(e))}function at(e){return Se(w(e))}function ot(e,t){if(t.flags?.noRecord||gt(e,t))return;t.flags&&De(e,t.flags);let n=ct(t),r=dt(e,lt(t,n));n&&ut(e,n);let i={ts:Date.now(),command:r.command,positionals:r.positionals,runtime:r.runtime,flags:vt(r.flags),result:r.result,...r.targetEvidence?{targetEvidence:r.targetEvidence}:{},...r.targetEvidences?{targetEvidences:r.targetEvidences}:{}};return e.actions.push(i),y({level:`debug`,phase:`record_action`,data:{command:t.command,session:e.name}}),i}function st(e,t,n,r,i,a){t&&e.recordAction(t,{command:r,positionals:a?.positionals??n.positionals??[],flags:a?.flags??n.flags??{},result:i??{}})}function ct(e){if(e.command!==`fill`||typeof e.flags.recordAs!=`string`)return;let t=xe(e.flags.recordAs),n=be(t);return{literal:Ae({ts:0,command:e.command,positionals:e.positionals,flags:e.flags}),placeholder:n}}function lt(e,t){if(!t)return e;let{literal:n,placeholder:r}=t;return{...e,positionals:pt(e.positionals,r),result:Me(e.result,n,r),targetEvidence:ke(e.targetEvidence,n,r)}}function ut(e,t){t.literal.trim()&&(e.recordedFillLiterals??=new Map,!e.recordedFillLiterals.has(t.literal)&&e.recordedFillLiterals.set(t.literal,t.placeholder))}function dt(e,t){let n=e.recordedFillLiterals;if(!n||n.size===0)return t;let r=je(t.result,n),i=(t.targetEvidenceMode??`action`)===`landmark`?ft(t.targetEvidence,n):E(t.targetEvidence,n),a=t.targetEvidences?{source:E(t.targetEvidences.source,n),destination:E(t.targetEvidences.destination,n)}:t.targetEvidences;return{...t,result:r,targetEvidence:i,targetEvidences:a}}function ft(e,t){return e&&(Te(e,t)?void 0:e)}function E(e,t){return!e||!Te(e,t)?e:{...Oe(e,t),verification:`unverifiable`}}function pt(e,t){let n=e[0];return n?.startsWith(`@`)?e.length>=3?[n,e[1],t]:[n,t]:e.length>=3&&Number.isFinite(Number(e[0]))&&Number.isFinite(Number(e[1]))?[e[0],e[1],t]:n===void 0?[t]:[n,t]}const mt=new Set([`snapshot`,`get`,`is`,`find`]);function ht(e){return e.internal?.replayPlanStep!==!0&&mt.has(e.command)}function gt(e,t){return!t.interactiveObservation||T(e)===void 0?!1:t.flags?.record!==!0}const _t=r();function vt(e){if(!e)return{};let t={};for(let n of _t){let r=e[n];r!==void 0&&(t[n]=r)}return t}function yt(t){let n=t.flatMap((e,t)=>e.command===`open`?[t]:[]);if(n.length!==1||n[0]!==0)throw new e(`COMMAND_FAILED`,`Cannot publish this session: an open-to-destination script requires exactly one initial recorded open.`,{retriable:!1,hint:`Close this session and start a fresh one with open <app> --save-script[=<path>].`});if(t.some(e=>e.command===`close`))throw new e(`COMMAND_FAILED`,`Cannot publish an active-session script containing close.`,{retriable:!1,hint:`Close this session and record the journey again from a fresh open --save-script session.`});let r=-1;for(let[e,n]of t.entries())te({command:n.command,positionals:n.positionals,flags:n.flags})===`mutates-app`&&(r=e);if(!t.slice(r+1).some(Tt))throw new e(`COMMAND_FAILED`,`Cannot publish this session without a portable destination guard after the final mutating action.`,{retriable:!0,hint:`Record a selector-targeted wait on a labeled or id-bearing landmark, for example wait 'role="heading" label="Screen X"', so its recorded identity is captured, then retry session save-script.`})}function bt(t){for(let n of t){if(xt(n)){St(n);continue}let t=Et(n),r=t??(n.command===`wait`?n.positionals[0]:void 0);if(r?.startsWith(`@`))throw new e(`COMMAND_FAILED`,`Cannot publish recorded step "${n.command} ${r}": the session-local ref was not converted to a portable selector.`,{retriable:!1,hint:`Close this session and record the journey again using selectors or resolvable refs.`});if(n.command===`find`&&te(n)===`mutates-app`)throw new e(`COMMAND_FAILED`,`Cannot publish a recorded mutating find step because its target identity is not replay-verifiable.`,{retriable:!1,hint:`Close this session and record the journey again with an explicit selector-targeted click, press, fill, or focus action.`});let i=t;if(!(!i||!u(i)||n.targetEvidence))throw new e(`COMMAND_FAILED`,`Cannot publish recorded step "${n.command} ${i}": recording-time target identity evidence is missing.`,{retriable:!1,hint:`Close this session and record the journey again from open --save-script so target-v1 evidence is captured before each interaction.`})}}function xt(e){return Ct(e)!==void 0}function St(t){let n=Ct(t);if(!n)return;let r=[n.source,n.destination];for(let n of r){if(n?.startsWith(`@`))throw new e(`COMMAND_FAILED`,`Cannot publish recorded drag endpoint "${n}": the session-local ref was not converted to a portable selector.`,{retriable:!1});if(!(!n||!u(n))&&!t.targetEvidences)throw new e(`COMMAND_FAILED`,`Cannot publish recorded drag endpoint "${n}": recording-time target identity evidence is missing.`,{retriable:!1,hint:`Close this session and record the journey again so targets-v1 evidence is captured for both drag endpoints.`})}}function Ct(e){return e.command===`gesture`?he(e.positionals):void 0}function wt(t,n){if(t instanceof e){if(t.details?.reason===`script_target_exists`)return new e(t.code,`A file already exists at ${String(t.details.path)}.`,{...t.details,retriable:!0,hint:`Retry session save-script with another path, or pass --force to replace the existing file. The session remains armed.`});let n=t.details?.retriable===!0;return new e(t.code,t.message,{...t.details,retriable:n,hint:t.details?.hint??(n?`Fix the recorded journey or target, then retry session save-script. The session remains armed.`:`Close this session and start a fresh one with open <app> --save-script[=<path>].`)})}let r=t instanceof Error?t.message:String(t);return new e(`COMMAND_FAILED`,`Failed to publish the active session script${n?` to ${n}`:``}: ${r}`,{retriable:!0,hint:`Check the target path and permissions, then retry session save-script. The session remains armed.`})}function Tt(e){if(e.command!==`wait`)return!1;let t=ie(e.positionals);return t?.kind!==`selector`||!u(t.selectorExpression)?!1:e.targetEvidence?.verification===`verified`}function Et(e){if(e.command===`get`)return e.positionals[1];if(ce(e.command)||e.command===`fill`){let[t,n]=e.positionals;return t!==void 0&&n!==void 0&&Dt(t)&&Dt(n)?void 0:t}}function Dt(e){return e.trim().length>0&&Number.isFinite(Number(e))}function Ot(e){let t=e.scriptPublication??m;return t.kind===`repair`?t.status===`committed`||!_e(t):!1}function kt(e){return!Ce(e.scriptPublication??m)||Ot(e)}var At=class{sessionsDir;constructor(e){this.sessionsDir=e}write(e,t){let n=rt(e),r=t?.publication===`active`,i;try{if(kt(e))return{written:!1};let a=jt(e,{appendCompleteSentinel:n,activePublication:r});i=this.resolveScriptPath(e);let o=S.dirname(i);return C.existsSync(o)||C.mkdirSync(o,{recursive:!0}),Pt({scriptPath:i,script:a.script,force:t?.force}),n&&(e.scriptPublication=Ee(e.scriptPublication??m)),{written:!0,path:i,actionCount:a.actionCount}}catch(t){return Mt({session:e,error:t,scriptPath:i,repairArmed:n,activePublication:r})}}resolveScriptPath(e){let t=ge(e.scriptPublication??m);if(t)return x(t);let n=b(e.name),r=new Date(e.createdAt).toISOString().replaceAll(/[:.]/g,`-`);return S.join(this.sessionsDir,`${n}-${r}.ad`)}};function jt(e,t){let n=Ft(e,{strictPortableRefs:t.activePublication});return t.activePublication&&yt(n),{script:Gt(e,n,t.appendCompleteSentinel),actionCount:n.length}}function Mt(t){let{session:n,error:r,scriptPath:i,repairArmed:a,activePublication:o}=t;if(y({level:`warn`,phase:`session_script_write_failed`,data:{session:n.name,path:i,error:r instanceof Error?r.message:String(r)}}),a)return{written:!1,error:Nt(r,i)};if(o)return{written:!1,error:wt(r,i)};if(r instanceof e)throw r;return{written:!1}}function Nt(t,n){if(t instanceof e)return t;let r=t instanceof Error?t.message:String(t);return new e(`COMMAND_FAILED`,`Failed to write the healed script${n?` to ${n}`:``}: ${r}`,{hint:`The repair transaction completed but the healed .ad could not be published; check the target path and permissions, then retry close --save-script.`})}function Pt(t){let{scriptPath:n,script:r,force:i}=t;try{Ve({destination:n,contents:r,publish:i?`replace`:`link-exclusive`})}catch(t){throw t.code===`EEXIST`?new e(`COMMAND_FAILED`,`A file already exists at ${n}; remove it, pass replay --save-script=<other-path>, or pass --force/--overwrite to replace it.`,{reason:`script_target_exists`,path:n}):t}}function Ft(e,t={}){let n=T(e),r=n!==void 0,i=e.actions.slice(n??0),a=[];for(let n of i){if(n.command===`snapshot`)continue;let i=Rt(n);if(i){a.push(i);continue}(r||t.strictPortableRefs)&&It(n);let o=Wt(e,n);o&&a.push(o),a.push(n)}return t.strictPortableRefs&&bt(a),a}function It(t){let n=t.command===`gesture`?he(t.positionals??[]):void 0;if(n){Lt(n);return}if(!D(t.command))return;let r=t.command===`get`?t.positionals?.[1]:t.positionals?.[0];if(r?.startsWith(`@`))throw new e(`COMMAND_FAILED`,`Cannot write recorded step "${t.command} ${r}" to a script: it never resolved to a selector, so the ref would not resolve in a fresh replay session.`)}function Lt(t){let n=[t.source,t.destination].find(e=>e.startsWith(`@`));if(n)throw new e(`COMMAND_FAILED`,`Cannot write recorded drag endpoint "${n}" to a script: it never resolved to a selector, so the ref would not resolve in a fresh replay session.`)}function Rt(e){let t=zt(e);if(!(!t||!D(e.command)))return le(e.command)||e.command===`hover`?{...e,positionals:[t]}:e.command===`longpress`?Vt(e,t):e.command===`fill`?Bt(e,t):Ht(e,t)}function zt(e){let t=Array.isArray(e.result?.selectorChain)&&e.result.selectorChain.every(e=>typeof e==`string`)?e.result.selectorChain:[];return t.length>0?t.join(` || `):void 0}function D(e){return ce(e)||e===`fill`||e===`get`}function Bt(e,t){let n=Ae(e);return n.length>0?{...e,positionals:[t,n]}:void 0}function Vt(e,t){let n=typeof e.result?.durationMs==`number`?String(e.result.durationMs):Ut(e.positionals??[]);return{...e,positionals:n?[t,n]:[t]}}function Ht(e,t){let n=e.positionals?.[0];return n===`text`||n===`attrs`?{...e,positionals:[n,t]}:void 0}function Ut(e){let t=e.at(-1);if(!(e.length<=1||t===void 0||t.trim()===``))return Number.isFinite(Number(t))?t:void 0}function Wt(e,t){if(!D(t.command))return;let n=t.result?.refLabel;if(typeof n!=`string`||n.trim().length===0)return;let r=n.trim();return{ts:t.ts,command:`snapshot`,positionals:[],flags:{platform:e.device.platform,snapshotInteractiveOnly:!0,snapshotScope:r},result:{scope:r}}}function Gt(e,t,n){let r=[],i=e.device.kind?` kind=${e.device.kind}`:``;r.push(`context platform=${l(e.device)} device=${fe(e.device.name)}${i} theme=unknown`);for(let e of t)e.flags?.noRecord||(r.push(...Xe(e)),r.push(Kt(e)));return n&&r.push(`# agent-device:heal-complete`),`${r.join(`
2
+ `)}\n`}function Kt(e){return qt([e.command],e)||Ye(e)}function qt(e,t){if(le(t.command))return Jt(e,t);if(t.command===`fill`)return Yt(e,t);if(t.command===`get`)return Xt(e,t)}function Jt(e,t){let n=t.positionals?.[0];if(n){if(n.startsWith(`@`))return e.push(f(d(n))),O(e,t),p(e,t),e.join(` `);if(t.positionals.length===1)return e.push(f(n)),p(e,t),e.join(` `)}}function Yt(e,t){let n=t.positionals?.[0];if(!n?.startsWith(`@`))return;e.push(f(d(n))),O(e,t);let r=t.positionals.slice(1).join(` `);return t.positionals.length>1&&e.push(f(r)),p(e,t),e.join(` `)}function Xt(e,t){let n=t.positionals?.[0],r=t.positionals?.[1];if(!(!n||!r))return e.push(f(n)),e.push(f(d(r))),r.startsWith(`@`)&&O(e,t),e.join(` `)}function O(e,t){let n=t.result?.refLabel;typeof n==`string`&&n.trim().length>0&&e.push(f(n))}const Zt=[`id`,`deviceId`,`device_id`,`serial`,`udid`,`device_udid`,`identifier`],Qt={ios:`iOS`,ipados:`iPadOS`,tvos:`tvOS`,watchos:`watchOS`,visionos:`visionOS`,macos:`macOS`,apple:`Apple`,android:`Android`,linux:`Linux`,web:`Web`};function $t(e,t){let n=t??{};switch(e.command){case h.devices:return en(n.devices);case h.apps:return tn(n.apps,e.flags?.appsFilter);case h.boot:return nn(`Booted`,n,!0);case h.shutdown:return nn(`Shut down`,n,!1);case h.install:return k(`Installed`,n);case h.reinstall:return k(`Reinstalled`,n);case h.screenshot:return rn(e,n);default:return{}}}function en(e){if(!Array.isArray(e))return{};let t=e.flatMap(e=>{let t=on(e);return t?[t]:[]}),n=t.slice(0,5),r=Math.max(0,t.length-n.length),i=t.slice(0,3);return{summary:hn(`Found ${t.length} ${gn(`device`,t.length)}`,i.map(e=>pn(e,!0)),Math.max(0,t.length-i.length)),details:{deviceCount:t.length,devices:n,...r>0?{omittedDeviceCount:r}:{}}}}function tn(e,t){if(!Array.isArray(e))return{};let n=e.flatMap(e=>{let t=M(e);return t?[t]:[]}),r=n.slice(0,5),i=Math.max(0,n.length-r.length),a=n.slice(0,3);return{summary:hn(`Found ${n.length} ${gn(`app`,n.length)}`,a,Math.max(0,n.length-a.length)),details:{appCount:n.length,apps:r,...i>0?{omittedAppCount:i}:{},...t===`all`||t===`user-installed`?{filter:t}:{}}}}function nn(e,t,n){let r=sn(t);if(!r)return{};let i={device:r,...fn(t),booted:n};return{summary:`${e} ${pn(i,!1)}`,details:i}}function k(e,t){let n=M(t.appName),r=M(t.bundleId),i=A(t,[`packageName`,`package`]),a=M(t.platform),o=M(t.launchTarget),s=A(t,[`bundleId`,`packageName`,`package`,`appId`,`launchTarget`]),c=mn(n,s);if(!c)return{};let l={};return j(l,`appName`,n),j(l,`bundleId`,r),j(l,`packageName`,i),j(l,`platform`,a),o!==s&&j(l,`launchTarget`,o),{summary:`${e} ${c}`,details:l}}function rn(e,t){let n=an(e,t);return n?{details:{requestedFileName:n}}:{}}function an(e,t){let n=R(e.meta?.clientArtifactPaths?.path)??R(t.path);if(n)return L(n)}function on(e){if(!n(e))return;let t=sn(e);if(t)return{name:t,...fn(e)}}function sn(e){let t=A(e,[`name`,`deviceName`,`device`]);return!t||!cn(e,t)?t:un(e)}function cn(e,t){let n=ln(t);return Zt.some(t=>{let r=M(e[t]);return r!==void 0&&ln(r)===n})}function ln(e){return e.toLowerCase()}function un(e){let t=M(e.appleOs),n=M(e.platform),r=M(e.kind),i=dn(t,n);return i&&(r===`simulator`||r===`emulator`)?`${i} ${r}`:i?`${i} device`:r===`simulator`?`Simulator`:r===`emulator`?`Emulator`:`Unnamed device`}function dn(e,t){let n=e??t;if(!(!n||!Object.hasOwn(Qt,n)))return Qt[n]}function fn(e){let t=M(e.platform),n=M(e.appleOs),r=M(e.kind),i=M(e.target);return{...t?{platform:t}:{},...n?{appleOs:n}:{},...r?{kind:r}:{},...i?{target:i}:{},...typeof e.booted==`boolean`?{booted:e.booted}:{}}}function pn(e,t){let n=M(e.name)??M(e.device)??`device`,r=M(e.platform),i=M(e.appleOs),a=[r,i===r?void 0:i,M(e.kind),M(e.target),t&&typeof e.booted==`boolean`?e.booted?`booted`:`stopped`:void 0].filter(e=>!!e);return a.length>0?`${n} (${a.join(`, `)})`:n}function mn(e,t){return e&&t&&e!==t?`${e} (${t})`:e??t}function A(e,t){for(let n of t){let t=M(e[n]);if(t)return t}}function j(e,t,n){n&&(e[t]=n)}function hn(e,t,n){let r=[...t,...n>0?[`+${n} more`]:[]];return r.length>0?`${e}: ${r.join(`, `)}`:e}function gn(e,t){return t===1?e:`${e}s`}function M(e){let t=R(e);if(!t)return;let n=t.trim(),r=Array.from(n);return r.length<=120?n:`${r.slice(0,119).join(``)}…`}function N(e){return M(e)}function P(e){return typeof e==`boolean`?e:void 0}function F(e,t){let n=N(e);return n&&t.includes(n)?n:void 0}function I(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0))}function L(e){let t=R(e);return t?M(t.split(/[\\/]/).at(-1)):void 0}function R(e){if(typeof e==`string`)return e.trim().length>0?e:void 0}function z(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}const _n=[`up`,`down`,`left`,`right`],vn=[`top`,`bottom`];function yn(e){return`${e.command===h.reinstall?`Reinstalled`:`Installed`} ${Cn(e.result??{})??`app`}`}function bn(e){let t=e.result??{};switch(e.command){case h.scroll:return Tn(t);case h.screenshot:return On(t);case h.home:return`Went home`;case h.back:return An(t);case h.appSwitcher:return`Opened app switcher`;case h.orientation:return jn(t);case h.viewport:return Mn(t);case h.clipboard:return Nn(t);case h.keyboard:return Pn(t);case h.tvRemote:return Ln(t);case h.gesture:return Rn(t);case h.swipe:return zn(t);case h.trace:return Vn(`trace`,e);case h.record:return Vn(`recording`,e);default:return}}function xn(e){let t=e.result??{};switch(e.command){case h.scroll:return I({direction:F(t.direction,_n),edge:F(t.edge,vn),passes:z(t.passes),amount:z(t.amount),pixels:z(t.pixels),durationMs:z(t.durationMs),x1:z(t.x1),y1:z(t.y1),x2:z(t.x2),y2:z(t.y2)});case h.screenshot:return I({requestedFileName:kn(t)});case h.back:return I({mode:F(t.mode,a)});case h.orientation:return I({orientation:F(t.orientation,_)});case h.viewport:return I({width:z(t.width),height:z(t.height)});case h.clipboard:return I({action:F(t.action,[`read`,`write`])});case h.keyboard:return In(t);case h.tvRemote:return I({button:F(t.button,He),durationMs:z(t.durationMs)});case h.gesture:case h.swipe:return Bn(t);case h.trace:case h.record:return I({action:F(t.action,[`start`,`stop`]),fileName:Un(e),showTouches:P(t.showTouches)});default:return{}}}function Sn(e,t){if(e.command!==h.screenshot)return t;let n=an(e,t);return n?{...t,requestedFileName:n}:t}function Cn(e){let t=N(e.appName),n=Wn(e,[`bundleId`,`packageName`,`appBundleId`,`launchTarget`]);return t&&n&&t!==n?`${t} (${n})`:t??n??wn(e)}function wn(e){let t=N(e.app);return t&&!t.includes(`/`)&&!t.includes(`\\`)?t:void 0}function Tn(e){let t=F(e.direction,_n),n=F(e.edge,vn),r=z(e.passes);return n?En(n,r):t?Dn(t,e):`Scrolled`}function En(e,t){return t===0?`Already at ${e}`:t===void 0?`Scrolled to ${e}`:`Scrolled to ${e} in ${t} ${t===1?`pass`:`passes`}`}function Dn(e,t){let n=z(t.pixels);if(n!==void 0)return`Scrolled ${e} by ${n}px`;let r=z(t.amount);return r===void 0?`Scrolled ${e}`:`Scrolled ${e} by ${r}`}function On(e){let t=kn(e);return t?`Captured screenshot ${t}`:`Captured screenshot`}function kn(e){return L(e.requestedFileName)??L(e.path)}function An(e){return F(e.mode,a)===`system`?`Went back using system navigation`:`Went back`}function jn(e){let t=F(e.orientation,_);return t?P(e.confirmed)===!1?`Requested ${t} (unconfirmed)`:`Rotated to ${t}`:`Changed orientation`}function Mn(e){let t=z(e.width),n=z(e.height);return t!==void 0&&n!==void 0?`Set viewport to ${t}×${n}`:`Changed viewport`}function Nn(e){let t=F(e.action,[`read`,`write`]);return t===`read`?`Read clipboard`:t===`write`?`Updated clipboard`:`Used clipboard`}function Pn(e){let t=R(e.action);if(!t||!Ke(t))return`Used keyboard`;if(t===`dismiss`)return Fn(e);if(t===`enter`||t===`return`)return`Pressed keyboard return`;let n=P(e.visible);return n===void 0?`Inspected keyboard`:n?`Keyboard is visible`:`Keyboard is hidden`}function Fn(e){return P(e.dismissed)===!1?`Keyboard was already hidden`:`Dismissed keyboard`}function In(e){let t=R(e.action);return I({action:t&&Ke(t)?t:void 0,platform:F(e.platform,[`ios`,`android`]),visible:P(e.visible),wasVisible:P(e.wasVisible),dismissed:P(e.dismissed),attempts:z(e.attempts),mechanism:F(e.mechanism,[`dismissKey`])})}function Ln(e){let t=F(e.button,He);return t?`Pressed TV remote ${t}`:`Used TV remote`}function Rn(e){let t=F(e.kind,[`fling`,`pan`,`pinch`,`rotate`,`transform`]);return t?`Ran ${t} gesture`:`Ran gesture`}function zn(e){let t=z(e.count);return t!==void 0&&t>1?`Swiped ${t} times`:`Swiped`}function Bn(e){return I({kind:F(e.kind,[`fling`,`pan`,`pinch`,`rotate`,`transform`]),durationMs:z(e.durationMs),pointerCount:z(e.pointerCount),x1:z(e.x1),y1:z(e.y1),x2:z(e.x2),y2:z(e.y2),count:z(e.count),pauseMs:z(e.pauseMs),pattern:F(e.pattern,[`one-way`,`ping-pong`]),scale:z(e.scale)})}function Vn(e,t){let n=Hn(e,F(t.result?.action,[`start`,`stop`])),r=Un(t);return r?`${n} ${r}`:n}function Hn(e,t){return t===`start`?e===`trace`?`Started trace`:`Started recording`:t===`stop`?e===`trace`?`Stopped trace`:`Stopped recording`:e===`trace`?`Updated trace`:`Updated recording`}function Un(e){let t=e.result??{};return L(t.requestedFileName)??L(t.outPath)??L(t.path)??L(e.positionals[1])}function Wn(e,t){for(let n of t){let t=N(e[n]);if(t)return t}}function Gn(e){switch(e.command){case h.open:return`Opened ${B(e)??`session`}`;case h.close:return`Closed ${N(e.result?.session)??`session`}`;case h.click:case h.press:return`Tapped ${B(e)??`target`}`;case h.longPress:return`Long pressed ${B(e)??`target`}`;case h.hover:return`Hovered ${B(e)??`target`}`;case h.fill:return`Filled ${B(e)??`target`}`;case h.type:return`Typed text`;case h.install:case h.reinstall:case g.installSource:return yn(e);default:return bn(e)??`Ran ${e.command}`}}function Kn(e){return I({command:e.command,positionals:tr(e),flags:pr(e),...qn(e),...Jn(e),...Yn(e),...xn(e)})}function qn(e){if(!Xn(e.command))return{};let t=e.result??{};return I({ref:G(t),targetLabel:B(e),selectorChainLength:lr(t.selectorChain)?.length,x:z(t.x),y:z(t.y),x2:z(t.x2),y2:z(t.y2),durationMs:z(t.durationMs)})}function Jn(e){if(!Zn(e.command))return{};let t=e.result??{};return I({platform:F(t.platform,o),target:F(t.target,c),appName:N(t.appName),appBundleId:N(t.appBundleId),bundleId:N(t.bundleId),packageName:N(t.packageName),launchTarget:N(t.launchTarget)})}function Yn(e){let t=e.result??{};return e.command===h.snapshot?Array.isArray(t.nodes)?{nodeCount:t.nodes.length}:{}:e.command!==h.wait&&e.command!==h.find&&e.command!==h.get&&e.command!==h.is?{}:I({waitedMs:z(t.waitedMs),found:P(t.found)})}function Xn(e){return e===h.click||e===h.press||e===h.longPress||e===h.hover||e===h.focus||e===h.fill}function Zn(e){return e===h.open||e===h.install||e===h.reinstall||e===g.installSource}function B(e){let t=e.result??{};return Qn(t)??$n(t)??er(t)??sr(e.positionals[0])}function Qn(e){let t=G(e);if(t)return t.startsWith(`@`)?t:`@${t}`}function $n(e){let t=z(e.x),n=z(e.y);if(t!==void 0&&n!==void 0)return`(${t}, ${n})`}function er(e){return N(e.appName)??N(e.appBundleId)??N(e.bundleId)??N(e.packageName)}function tr(e){if(e.positionals.length!==0)return e.command===h.type?[H(`text`)]:e.command===h.fill?nr(e):e.command===h.find?rr(e):e.command===h.clipboard?ir(e):e.command===h.push?ar(e,`app`,`payload`):e.command===h.triggerAppEvent?ar(e,`event`,`payload`):e.positionals.map(V)}function nr(e){let t=H(`text`),n=e.result??{},r=G(n);if(r)return[`@${r}`,t];if(N(n.selector))return[H(`target`),t];let i=z(n.x),a=z(n.y);return i!==void 0&&a!==void 0?[String(i),String(a),t]:[t]}function rr(e){let t=+!!cr(e.positionals[0]);if(e.positionals[t]===void 0)return;let n=t+1,r=[...t===1?[String(e.positionals[0])]:[],H(`query`)],i=e.positionals[n];return i?i===`fill`||i===`type`?[...r,i,H(`text`)]:[...r,...e.positionals.slice(n).map(or)]:r}function ir(e){let t=e.positionals[0]?.toLowerCase();return t===`read`?[`read`]:t===`write`?[`write`,H(`text`)]:e.positionals.map(V)}function ar(e,t,n){let[r,i,...a]=e.positionals;return[...r?[H(t)]:[],...i?[H(n)]:[],...a.map(V)]}function or(e){return e===`click`||e===`focus`||e===`exists`||e===`get`||e===`text`||e===`attrs`||e===`wait`?e:V(e)}function V(e){return sr(e)??H(`arg`)}function sr(e){if(!e)return;let t=e.trim();if(/^@[a-zA-Z0-9:_-]+$/.test(t))return t}function H(e){return`<${e}>`}function cr(e){return e===`text`||e===`label`||e===`value`||e===`role`||e===`id`}function lr(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)?e:void 0}const ur={enums:[{source:`platform`,values:s},{source:`target`,values:c}]},dr={booleans:[{source:`settle`}],numbers:[{source:`settleQuietMs`}]},fr={[h.open]:{booleans:[{source:`relaunch`},{source:`testIme`}],enums:[{source:`surface`,values:Re}]},[h.click]:U(),[h.press]:U(),[h.longPress]:U(),[h.hover]:U(),[h.fill]:hr(),[h.type]:hr(),[h.scroll]:{numbers:[{source:`pixels`},{source:`durationMs`}]},[h.gesture]:gr(),[h.swipe]:gr(),[h.screenshot]:{booleans:[{source:`overlayRefs`},{source:`screenshotFullscreen`,output:`fullscreen`},{source:`screenshotNoStabilize`,output:`noStabilize`},{source:`screenshotNormalizeStatusBar`,output:`normalizeStatusBar`}],numbers:[{source:`screenshotPixelDensity`,output:`pixelDensity`},{source:`screenshotScale`,output:`scale`}]},[h.snapshot]:{booleans:[{source:`snapshotInteractiveOnly`,output:`interactiveOnly`},{source:`snapshotDiff`,output:`diff`},{source:`snapshotRaw`,output:`raw`},{source:`snapshotCustomActions`,output:`actions`},{source:`snapshotForceFull`,output:`forceFull`}],numbers:[{source:`snapshotDepth`,output:`depth`}]},[h.back]:{enums:[{source:`backMode`,output:`mode`,values:a}]},[h.record]:{booleans:[{source:`hideTouches`}],numbers:[{source:`fps`}],enums:[{source:`recordingScope`,output:`scope`,values:i}]},[h.apps]:{enums:[{source:`appsFilter`,output:`filter`,values:[`user-installed`,`all`]}]},[h.boot]:{booleans:[{source:`headless`}]},[h.close]:{booleans:[{source:`shutdown`}]}};function pr(e){let t=e.flags??{},n={},r=Object.hasOwn(fr,e.command)?fr[e.command]:void 0;return W(n,t,ur),W(n,t,r),W(n,t,mr(e.command)),Object.keys(n).length>0?n:void 0}function mr(e){return ne(e)?dr:void 0}function U(){return{booleans:[{source:`doubleTap`}],numbers:[{source:`count`},{source:`intervalMs`},{source:`holdMs`},{source:`jitterPx`}],enums:[{source:`clickButton`,values:Be}]}}function hr(){return{numbers:[{source:`delayMs`}]}}function gr(){return{numbers:[{source:`pointerCount`},{source:`count`},{source:`pauseMs`}],enums:[{source:`pattern`,values:ae}]}}function W(e,t,n){n&&(_r(e,t,n.booleans??[]),vr(e,t,n.numbers??[]),yr(e,t,n.enums??[]))}function _r(e,t,n){for(let r of n)br(e,r.output??r.source,t[r.source])}function vr(e,t,n){for(let r of n)xr(e,r.output??r.source,t[r.source])}function yr(e,t,n){for(let r of n)Sr(e,r.output??r.source,t[r.source],r.values)}function G(e){let t=N(e.ref);if(!t)return;let n=t.startsWith(`@`)?t.slice(1):t;return/^[a-zA-Z0-9:_-]+$/.test(n)?n:void 0}function br(e,t,n){typeof n==`boolean`&&(e[t]=n)}function xr(e,t,n){let r=z(n);r!==void 0&&(e[t]=r)}function Sr(e,t,n,r){let i=F(n,r);i!==void 0&&(e[t]=i)}const Cr=65536;function wr(e){return qe(`sha256`).update(e,`utf8`).digest(`hex`).slice(0,32)}function K(e,t){let n=Or(e);if(n===void 0)return!1;try{let e=Er(t),r=Buffer.allocUnsafe(Cr),i=0;do if(i=C.readSync(n,r,0,r.length,null),!e.push(r.subarray(0,i)))return!0;while(i>0);return e.end(),!0}finally{C.closeSync(n)}}async function Tr(e){let t=await kr(e);if(t===void 0)return{lineCount:0,firstLineDigest:void 0};let n={lineCount:0,firstLineDigest:void 0};try{let e=Er(e=>{n.lineCount===0&&(n.firstLineDigest=wr(e)),n.lineCount+=1}),r=Buffer.allocUnsafe(Cr);for(;;){let{bytesRead:n}=await t.read(r,0,r.length,null);if(e.push(r.subarray(0,n)),n===0)break}return e.end(),n}finally{await t.close()}}function q(e){let t;return K(e,e=>(t=wr(e),!1)),t}function Er(e){let t=new Je(`utf8`),n=``,r=!1;return{push(i){if(r)return!1;let a=`${n}${t.write(i)}`,o=0;for(let t=a.indexOf(`
3
+ `);t!==-1;t=a.indexOf(`
4
+ `,o)){if(Dr(a.slice(o,t),e)===!1)return r=!0,!1;o=t+1}return n=a.slice(o),!0},end(){r||Dr(`${n}${t.end()}`,e)}}}function Dr(e,t){let n=e.endsWith(`\r`)?e.slice(0,-1):e;if(n.trim().length!==0)return t(n)}function Or(e){try{return C.openSync(e,`r`)}catch(e){if(e.code===`ENOENT`)return;throw e}}async function kr(e){try{return await C.promises.open(e,`r`)}catch(e){if(e.code===`ENOENT`)return;throw e}}const Ar=5242880;function jr(e=process.env){let t=e.AGENT_DEVICE_EVENT_LOG_MAX_BYTES?.trim();if(t===void 0||!/^\d+$/.test(t))return Ar;let n=Number(t);return Number.isSafeInteger(n)&&n>0?n:Ar}function J(e){return`${e}.1`}function Y(e){return`${e}.window.json`}function Mr(e){let t;for(let n=0;n<3;n+=1){let n=Z(e);try{let t=Nr(e);if(Z(e)===n)return t}catch(r){if(t=r,Z(e)===n)throw r}}throw t??X(e,`the window did not settle while reading`)}function Nr(e){let t=J(e),n=Br(e);if(n===`unverifiable`)throw X(e,`window file is invalid`);if(n===void 0)return Pr(e,t);let r=n.at(-1);if(!r)throw X(e,`window file records no generation`);let i=Ur(e),a=Fr(e,r),o=[],s=Ir({eventLogPath:e,rotatedPath:t,sidecar:n,activeStart:a,activeExists:i});return s!==void 0&&o.push({path:t,firstLineIndex:s}),i&&o.push({path:e,firstLineIndex:a}),{files:o,earliestCursor:o[0]?.firstLineIndex??a}}function Pr(e,t){if(q(t)!==void 0)throw X(e,`a rotated event log exists with no window record`);return{files:Ur(e)?[{path:e,firstLineIndex:0}]:[],earliestCursor:0}}function Fr(e,t){let n=q(e);return n!==void 0&&n===t.firstLineDigest?t.firstLineIndex:t.firstLineIndex+t.lineCount}function Ir(e){let{eventLogPath:t,rotatedPath:n,sidecar:r,activeStart:i,activeExists:a}=e,o=q(n);if(o===void 0)return;let s=r.find(e=>e.firstLineDigest===o);if(!s)throw X(t,`the rotated event log matches no window record`);let c=zr(n);if(c!==s.lineCount)throw X(t,`the rotated event log holds ${c} lines, the window recorded ${s.lineCount}`);if(a&&s.firstLineIndex+s.lineCount!==i)throw X(t,`retained event log generations are not contiguous`);return s.firstLineIndex}async function Lr(e,t){let n=Wr(e);if(!n||n.size<t)return!1;let r=Br(e);if(r===`unverifiable`)return await C.promises.rename(e,J(e)),!0;let i=await Tr(e);if(i.firstLineDigest!==void 0){let t=r??[],n=t.at(-1),a=n&&n.firstLineDigest===i.firstLineDigest?n:{firstLineIndex:n?n.firstLineIndex+n.lineCount:0,lineCount:i.lineCount,firstLineDigest:i.firstLineDigest};await Hr(e,(a===n?t:[...t,a]).slice(-2))}return await C.promises.rename(e,J(e)),!0}function Rr(t,n){if(!(t>=n))throw new e(`COMMAND_FAILED`,`events cursor ${t} precedes the retained event log window; events before cursor ${n} were rotated out.`,{reason:`EVENT_LOG_CURSOR_EXPIRED`,cursor:t,earliestCursor:n,hint:`Resume with cursor ${n}, the oldest retained event; earlier events are no longer available.`})}function X(t,n){return new e(`COMMAND_FAILED`,`Session event log window cannot be verified: ${n}.`,{reason:`EVENT_LOG_WINDOW_UNVERIFIED`,path:t,hint:`Cursor positions for this session cannot be resolved. Delete ${t}, ${J(t)}, and ${Y(t)} to restart the timeline, or read the files directly.`})}function zr(e){let t=0;return K(e,()=>{t+=1}),t}function Z(e){return[Q(Y(e)),Q(e),Q(J(e))].join(`|`)}function Q(e){try{let t=C.lstatSync(e);return`${t.ino}:${t.size}:${t.mtimeMs}`}catch{return`absent`}}function Br(e){let t;try{t=C.readFileSync(Y(e),`utf8`)}catch(e){return e.code===`ENOENT`?void 0:`unverifiable`}try{let e=JSON.parse(t);if(!n(e)||e.version!==2)return`unverifiable`;let{generations:r}=e;if(!Array.isArray(r)||r.length===0)return`unverifiable`;let i=r.map(Vr);return i.every(e=>e!==void 0)?i:`unverifiable`}catch{return`unverifiable`}}function Vr(e){if(!n(e))return;let{firstLineIndex:t,lineCount:r,firstLineDigest:i}=e;if(!(!Number.isSafeInteger(t)||t<0)&&!(!Number.isSafeInteger(r)||r<0)&&typeof i==`string`&&i.length!==0)return{firstLineIndex:t,lineCount:r,firstLineDigest:i}}async function Hr(e,t){let n=Y(e),r=`${n}.${process.pid}.tmp`;await C.promises.writeFile(r,JSON.stringify({version:2,generations:t}),`utf8`),await C.promises.rename(r,n)}function Ur(e){return Wr(e)!==void 0}function Wr(t){try{let n=C.lstatSync(t);if(n.isSymbolicLink())throw new e(`COMMAND_FAILED`,`Session event log must not be a symbolic link: ${t}`);return n}catch(e){if(e.code===`ENOENT`)return;throw e}}const $=new Map,Gr=new Set;function Kr(e){return S.join(e,`events.ndjson`)}function qr(e){return e.command!==h.events}function Jr(e,n,r){let i=t({version:1,ts:r.ts??new Date().toISOString(),session:n,...r});Xr(e,`${JSON.stringify(i)}\n`)}async function Yr(e){await(e?$.get(e):Promise.all($.values()))}function Xr(e,t){let n=($.get(e)??Promise.resolve()).catch(()=>void 0).then(async()=>{await Zr(e),await Lr(e,jr()),await C.promises.appendFile(e,t,`utf8`)}).catch(t=>{y({level:`warn`,phase:`session_event_log_write_failed`,data:{path:e,error:t instanceof Error?t.message:String(t)}})}).finally(()=>{$.get(e)===n&&$.delete(e)});$.set(e,n)}async function Zr(e){let t=S.dirname(e);if(!Gr.has(t))try{await C.promises.mkdir(t,{recursive:!0}),Gr.add(t)}catch(t){throw y({level:`warn`,phase:`session_event_log_dir_failed`,data:{path:e,error:t instanceof Error?t.message:String(t)}}),t}}function Qr(e,t,n){Jr(e,t,{kind:`action.recorded`,requestId:v().requestId,command:n.command,summary:Gn(n),details:Kn(n)})}function $r(e){let{req:t}=e;return{kind:`request.started`,requestId:t.meta?.requestId??v().requestId,command:t.command,summary:`Started ${t.command}`}}function ei(e){let{req:t,response:n,durationMs:r}=e;if(n.ok){let e=$t(t,n.data);return{kind:`request.finished`,requestId:t.meta?.requestId??v().requestId,command:t.command,status:`ok`,summary:e.summary??`Finished ${t.command}`,details:{durationMs:r,...e.details}}}return{kind:`request.finished`,requestId:t.meta?.requestId??v().requestId,command:t.command,status:`error`,summary:`Failed ${t.command}: ${n.error.code}`,details:{durationMs:r,code:n.error.code,diagnosticId:n.error.diagnosticId}}}function ti(e,t={}){let n=ri(t.cursor),r=ii(t.limit),i=Mr(e);Rr(n,i.earliestCursor);let a=ni(i.files,n,r),o=a.lines.flatMap(e=>{let t=ai(e);return t?[t]:[]});return{path:e,cursor:String(n),limit:r,events:o,...a.nextCursor===void 0?{}:{nextCursor:String(a.nextCursor)}}}function ni(e,t,n){let r=[],i;for(let a of e){let e=a.firstLineIndex;if(K(a.path,a=>{if(e>=t+n)return i=t+n,!1;e>=t&&r.push(a),e+=1}),i!==void 0)break}return{lines:r,...i===void 0?{}:{nextCursor:i}}}function ri(t){if(t===void 0||t.trim()===``)return 0;let n=Number(t);if(Number.isInteger(n)&&n>=0)return n;throw new e(`INVALID_ARGS`,`events cursor must be a non-negative integer string.`)}function ii(t){if(t===void 0||typeof t==`string`&&t.trim()===``)return 100;let n=typeof t==`string`?Number(t):t;if(Number.isInteger(n)&&n>=1&&n<=500)return n;throw new e(`INVALID_ARGS`,`events limit must be between 1 and 500.`)}function ai(e){try{let t=oi(JSON.parse(e));return t?si(t):void 0}catch{return}}function oi(e){if(n(e)&&e.version===1&&typeof e.ts==`string`&&typeof e.session==`string`&&ci(e.kind))return e}function si(e){let t=n(e.details)?e.details:void 0;return{version:1,ts:e.ts,session:e.session,kind:e.kind,...typeof e.requestId==`string`?{requestId:e.requestId}:{},...typeof e.command==`string`?{command:e.command}:{},...li(e.status)?{status:e.status}:{},...typeof e.summary==`string`?{summary:e.summary}:{},...t?{details:t}:{}}}function ci(e){return e===`request.started`||e===`request.finished`||e===`action.recorded`}function li(e){return e===`ok`||e===`error`}const ui=36e5;var di=class{sessions=new Map;runtimeHints=new Map;sessionsDir;scriptWriter;constructor(e){this.sessionsDir=e,this.scriptWriter=new At(e)}get(e){return this.sessions.get(e)}set(e,t){this.sessions.set(e,t)}delete(e){return this.runtimeHints.delete(e),this.sessions.delete(e)}values(){return this.sessions.values()}toArray(){return Array.from(this.sessions.values())}lookup(e){let t=this.sessions.get(e);return t?{address:e,session:t}:void 0}findByDevice(e){for(let[t,n]of this.sessions)if(n.device.id===e)return{address:t,session:n}}listRefs(){return Array.from(this.sessions,([e,t])=>({address:e,session:t}))}getRuntimeHints(e){return this.runtimeHints.get(e)}setRuntimeHints(e,t){this.runtimeHints.set(e,t)}clearRuntimeHints(e){return this.runtimeHints.delete(e)}recordAction(e,t){let n=ot(e,t);if(n){let t=this.resolveStoredSessionName(e);Qr(this.resolveEventLogPath(t),t,n)}}recordEvent(e,t){Jr(this.resolveEventLogPath(e),e,t)}readEvents(e,t={}){return ti(this.resolveEventLogPath(e),t)}async flushEvents(e){await Yr(e?this.resolveEventLogPath(e):void 0)}writeSessionLog(e,t){let n=this.scriptWriter.write(e,t);return n.written&&y({level:`info`,phase:`session_script_written`,data:{session:e.name,path:n.path}}),n}finalizeRepairTeardown(e){this.recordRepairFinalizeCloseIfCommitting(e);let t=this.writeSessionLog(e,{force:Ne(e,void 0)});it(e)&&(!t.written&&t.error?this.writeRepairTombstone(e,ui,{code:String(t.error.code),message:t.error.message}):this.writeRepairTombstone(e))}recordRepairFinalizeCloseIfCommitting(e){let t=e.scriptPublication??m;_e(t)&&this.recordAction(e,{command:`close`,positionals:[],flags:{},result:{session:e.name,...ze(`Closed: ${e.name}`)}})}writeRepairTombstone(e,t=ui,n){try{let r=this.resolveSessionDir(e.name);C.mkdirSync(r,{recursive:!0});let i={owner:e.name,reapedAt:Date.now(),expiresAt:Date.now()+t,...at(e)?{sourcePath:at(e)}:{},...n?{commitFailure:n}:{}};C.writeFileSync(this.repairTombstonePath(e.name),`${JSON.stringify(i)}\n`)}catch(t){y({level:`warn`,phase:`repair_tombstone_write_failed`,data:{session:e.name,error:t instanceof Error?t.message:String(t)}})}}readRepairTombstone(e){return Ue(this.repairTombstonePath(e))}clearRepairTombstone(e){try{C.rmSync(this.repairTombstonePath(e),{force:!0})}catch{}}repairTombstonePath(e){return We(this.resolveSessionDir(e))}defaultTracePath(e){let t=b(e.name),n=new Date().toISOString().replaceAll(/[:.]/g,`-`);return S.join(this.sessionsDir,`${t}-${n}.trace.log`)}resolveSessionDir(t){if(!Ge(t))throw new e(`INVALID_ARGS`,`Invalid session name ${JSON.stringify(t)}: a session name cannot be empty, ".", or "..".`);return S.join(this.sessionsDir,b(t))}resolveDaemonStateDir(){return S.dirname(this.sessionsDir)}ensureSessionDir(e){let t=this.resolveSessionDir(e);return C.mkdirSync(t,{recursive:!0}),t}resolveAppLogPath(e){return S.join(this.resolveSessionDir(e),`app.log`)}resolveAppLogPidPath(e){return S.join(this.resolveSessionDir(e),`app-log.pid`)}resolveEventLogPath(e){return Kr(this.resolveSessionDir(e))}static expandHome(e,t){return x(e,t)}resolveStoredSessionName(e){for(let[t,n]of this.sessions)if(n===e)return t;return e.name}};export{Qe as _,tr as a,st as c,nt as d,rt as f,T as g,et as h,qr as i,tt as l,$e as m,ei as n,Sn as o,it as p,$r as r,ht as s,di as t,Ze as u};
@@ -1 +1 @@
1
- import{Fn as e,Gn as t,Ln as n,Pn as r,Wn as i,kn as a,zn as o}from"./sdk-batch-runner.js";import{J as s,K as c,ot as l,q as u}from"./script-source-bundle.js";import{Dt as d}from"./internal/daemon.js";function f(e){return e.matchedRefs.length===0?{path:2,outcome:`unverifiable`,reason:`selector-miss`}:e.identitySetRefs.length===0?{path:3,outcome:`unverifiable`,reason:`identity-set-empty`}:e.identitySetRefs.length===1?e.identitySetRefs[0]===e.winnerRef?{path:4,outcome:`verified`}:{path:5,outcome:`unverifiable`,reason:`unique-but-wrong`}:e.siblingMatchRefs.length===1?e.siblingMatchRefs[0]===e.winnerRef?{path:6,outcome:`verified`}:{path:6,outcome:`unverifiable`,reason:`signal-isolated-wrong`}:e.regionMemberRefs!==void 0&&e.regionMemberRefs.length>0&&e.viewportCandidateRef!==void 0?e.viewportCandidateRef===e.winnerRef?{path:6,outcome:`verified`}:{path:6,outcome:`unverifiable`,reason:`signal-isolated-wrong`}:{path:6,outcome:`unverifiable`,reason:`no-signal-isolation`}}function p(e,t={}){let n=t.mode??`action`,{node:r,preActionNodes:i}=e;if(typeof r.index!=`number`)return;let o=u(i),s=a(_(r),i);if(n===`landmark`&&s.id===void 0&&s.label===void 0)return;let l=c(r,o,8),d=l.chain,f=v(i,r),p=y(r,o),b=x(r),C=+(d.length>0),w=e=>{let t=d.slice(0,e),n=S({nodes:i,byIndex:o,node:r,identity:s,ancestry:t,sibling:f,scrollRegion:p});return{candidate:{...s,ancestry:t,sibling:f,viewportOrder:n.viewportOrder,...p?{scrollRegion:p}:{},...b?{rect:b}:{},verification:`verified`},domain:n}};for(let e=d.length;e>=C;--e){let{candidate:t,domain:i}=w(e);if(h(t))return t.verification=m({node:r,domain:i,mode:n,brokenWalk:l.broken}),t;if(e===C)return g(t)}}function m(e){return e.brokenWalk?`unverifiable`:e.mode===`landmark`?`verified`:w({node:e.node,domain:e.domain})}function h(e){return t(i({...e,verification:`unverifiable`}))<=o}function g(e){return e.verification=`unverifiable`,t(i(e))>4096&&delete e.rect,e}const _=e;function v(e,t){return n(e,t)}function y(e,t){let n=d(e,t);if(!n)return;let r=_(n);return{role:r.role,...r.id===void 0?r.label===void 0?{}:{label:r.label}:{id:r.id}}}function b(e,t){return!e&&!t?!0:!e||!t?!1:r(e,t)}function x(e){let t=e.rect;if(t)return{x:t.x,y:t.y,width:t.width,height:t.height}}function S(e){let{nodes:t,byIndex:n,node:r,identity:i,ancestry:a,sibling:o,scrollRegion:c}=e,l=s(t,n,i,a),u=l.filter(e=>v(t,e)===o),d=l.length>0?l.filter(e=>b(y(e,n),c)):void 0,f=d?C(d):[];return{identitySet:l,siblingMatches:u,regionMembers:d,orderedRegion:f,viewportOrder:Math.max(f.findIndex(e=>e.index===r.index),0)}}function C(e){return e.map((e,t)=>({node:e,documentOrder:t,center:l(e.rect)})).sort((e,t)=>!e.center&&!t.center?e.documentOrder-t.documentOrder:e.center?t.center?e.center.y===t.center.y?e.center.x===t.center.x?e.documentOrder-t.documentOrder:e.center.x-t.center.x:e.center.y-t.center.y:-1:1).map(e=>e.node)}function w(e){let{node:t,domain:n}=e,r=t.ref,i=n.identitySet.map(e=>e.ref);return f({winnerRef:r,matchedRefs:i,identitySetRefs:i,siblingMatchRefs:n.siblingMatches.map(e=>e.ref),regionMemberRefs:n.regionMembers?.map(e=>e.ref),viewportCandidateRef:n.orderedRegion[n.viewportOrder]?.ref}).outcome}export{C as a,p as i,y as n,b as o,v as r,f as s,_ as t};
1
+ import{C as e}from"./sdk-contracts.js";import{$n as t,Hn as n,In as r,Kn as i,Vn as a,Wn as o,Zn as s}from"./sdk-batch.js";import{E as c,T as l,n as u,w as d}from"./runtime.js";import{i as f}from"./rect-center.js";import{o as p}from"./tree.js";function m(e){return e.matchedRefs.length===0?{path:2,outcome:`unverifiable`,reason:`selector-miss`}:e.identitySetRefs.length===0?{path:3,outcome:`unverifiable`,reason:`identity-set-empty`}:e.identitySetRefs.length===1?e.identitySetRefs[0]===e.winnerRef?{path:4,outcome:`verified`}:{path:5,outcome:`unverifiable`,reason:`unique-but-wrong`}:e.siblingMatchRefs.length===1?e.siblingMatchRefs[0]===e.winnerRef?{path:6,outcome:`verified`}:{path:6,outcome:`unverifiable`,reason:`signal-isolated-wrong`}:e.regionMemberRefs!==void 0&&e.regionMemberRefs.length>0&&e.viewportCandidateRef!==void 0?e.viewportCandidateRef===e.winnerRef?{path:6,outcome:`verified`}:{path:6,outcome:`unverifiable`,reason:`signal-isolated-wrong`}:{path:6,outcome:`unverifiable`,reason:`no-signal-isolation`}}function h(t,n={}){let r=n.plural===!0?`do`:`does`;return{resolveInput:async()=>{throw new e(`UNSUPPORTED_OPERATION`,`${t} ${r} not resolve input artifacts`)},reserveOutput:async()=>{throw new e(`UNSUPPORTED_OPERATION`,`${t} ${r} not reserve output artifacts`)},createTempFile:async()=>{throw new e(`UNSUPPORTED_OPERATION`,`${t} ${r} not create temporary files`)}}}function g(e,t={}){return{artifacts:h(e,t),policy:u()}}function _(e,t={}){let n=t.mode??`action`,{node:i,preActionNodes:a}=e;if(typeof i.index!=`number`)return;let o=l(a),s=r(x(i),a);if(n===`landmark`&&s.id===void 0&&s.label===void 0)return;let c=d(i,o,8),u=c.chain,f=S(a,i),p=C(i,o),m=T(i),h=+(u.length>0),g=e=>{let t=u.slice(0,e),n=E({nodes:a,byIndex:o,node:i,identity:s,ancestry:t,sibling:f,scrollRegion:p});return{candidate:{...s,ancestry:t,sibling:f,viewportOrder:n.viewportOrder,...p?{scrollRegion:p}:{},...m?{rect:m}:{},verification:`verified`},domain:n}};for(let e=u.length;e>=h;--e){let{candidate:t,domain:r}=g(e);if(y(t))return t.verification=v({node:i,domain:r,mode:n,brokenWalk:c.broken}),t;if(e===h)return b(t)}}function v(e){return e.brokenWalk?`unverifiable`:e.mode===`landmark`?`verified`:O({node:e.node,domain:e.domain})}function y(e){return t(s({...e,verification:`unverifiable`}))<=i}function b(e){return e.verification=`unverifiable`,t(s(e))>4096&&delete e.rect,e}const x=n;function S(e,t){return o(e,t)}function C(e,t){let n=p(e,t);if(!n)return;let r=x(n);return{role:r.role,...r.id===void 0?r.label===void 0?{}:{label:r.label}:{id:r.id}}}function w(e,t){return!e&&!t?!0:!e||!t?!1:a(e,t)}function T(e){let t=e.rect;if(t)return{x:t.x,y:t.y,width:t.width,height:t.height}}function E(e){let{nodes:t,byIndex:n,node:r,identity:i,ancestry:a,sibling:o,scrollRegion:s}=e,l=c(t,n,i,a),u=l.filter(e=>S(t,e)===o),d=l.length>0?l.filter(e=>w(C(e,n),s)):void 0,f=d?D(d):[];return{identitySet:l,siblingMatches:u,regionMembers:d,orderedRegion:f,viewportOrder:Math.max(f.findIndex(e=>e.index===r.index),0)}}function D(e){return e.map((e,t)=>({node:e,documentOrder:t,center:f(e.rect)})).sort((e,t)=>!e.center&&!t.center?e.documentOrder-t.documentOrder:e.center?t.center?e.center.y===t.center.y?e.center.x===t.center.x?e.documentOrder-t.documentOrder:e.center.x-t.center.x:e.center.y-t.center.y:-1:1).map(e=>e.node)}function O(e){let{node:t,domain:n}=e,r=t.ref,i=n.identitySet.map(e=>e.ref);return m({winnerRef:r,matchedRefs:i,identitySetRefs:i,siblingMatchRefs:n.siblingMatches.map(e=>e.ref),regionMemberRefs:n.regionMembers?.map(e=>e.ref),viewportCandidateRef:n.orderedRegion[n.viewportOrder]?.ref}).outcome}export{D as a,m as c,_ as i,C as n,w as o,S as r,g as s,x as t};