agent-device 0.20.9 → 0.21.0

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 (492) hide show
  1. package/README.md +2 -2
  2. package/android/ime-helper/dist/{agent-device-android-ime-helper-0.20.9.apk → agent-device-android-ime-helper-0.21.0.apk} +0 -0
  3. package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.0.apk.sha256 +1 -0
  4. package/android/ime-helper/dist/{agent-device-android-ime-helper-0.20.9.manifest.json → agent-device-android-ime-helper-0.21.0.manifest.json} +4 -4
  5. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.0.apk +0 -0
  6. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.0.apk.sha256 +1 -0
  7. package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.20.9.manifest.json → agent-device-android-snapshot-helper-0.21.0.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 +49 -0
  12. package/apple/snapshot-bridge/SnapshotBridge.m +280 -0
  13. package/apple/snapshot-bridge/SnapshotBridgeRuntime.h +33 -0
  14. package/apple/snapshot-bridge/SnapshotBridgeRuntime.m +382 -0
  15. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerApp.m +58 -0
  16. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunner.xcodeproj/project.pbxproj +19 -0
  17. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAlertVerification.swift +36 -0
  18. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerStringNormalization.swift +8 -0
  19. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.h +12 -1
  20. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.m +100 -6
  21. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTapPointPolicy.swift +2 -2
  22. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AXSnapshotFallback.swift +21 -12
  23. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Alert.swift +21 -88
  24. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AlertObservation.swift +124 -0
  25. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +110 -107
  26. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandJournal.swift +6 -14
  27. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +85 -114
  28. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Lifecycle.swift +13 -6
  29. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +72 -175
  30. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Navigation.swift +10 -11
  31. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+PrivateAXElementTypes.swift +12 -0
  32. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+PrivateAXPresentation.swift +78 -64
  33. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScreenRecorder.swift +17 -9
  34. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScrollGesture.swift +47 -13
  35. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift +232 -438
  36. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotBackendCapabilities.swift +98 -0
  37. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotCapturePlan.swift +229 -168
  38. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotPresentationInvariant.swift +19 -0
  39. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotTiming.swift +110 -0
  40. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedCommitDeadline.swift +206 -0
  41. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedTextEntry.swift +147 -25
  42. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SystemModal.swift +21 -18
  43. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntry.swift +24 -307
  44. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryFocus.swift +206 -0
  45. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryReadiness.swift +158 -0
  46. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextInputCandidatePolicy.swift +19 -0
  47. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextTyping.swift +49 -16
  48. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Transport.swift +2 -11
  49. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TvRemote.swift +4 -19
  50. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +16 -20
  51. package/dist/apple/runner/AgentDeviceRunner/RecordingScripts/RecordingExportSupport.swift +111 -0
  52. package/dist/apple/runner/AgentDeviceRunner/RecordingScripts/recording-overlay.swift +42 -81
  53. package/dist/apple/runner/AgentDeviceRunner/RecordingScripts/recording-trim.swift +35 -82
  54. package/dist/apple/snapshot-presentation/Package.swift +21 -0
  55. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotGeometry.swift +56 -0
  56. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotModels.swift +259 -0
  57. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotPresentation.swift +153 -0
  58. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotPresentationFailure.swift +27 -0
  59. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotPresentationInvariant.swift +91 -0
  60. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotPresentationProjection.swift +161 -0
  61. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotScopePolicy.swift +53 -0
  62. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotVisibilityFold.swift +242 -0
  63. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotVisibilityFoldProjection.swift +97 -0
  64. package/dist/src/adapter.js +1 -0
  65. package/dist/src/adb-executor.js +2 -0
  66. package/dist/src/adb-failure.js +1 -0
  67. package/dist/src/adb-host.js +1 -0
  68. package/dist/src/adb.js +1 -0
  69. package/dist/src/agent-browser-lifecycle.js +1 -0
  70. package/dist/src/agent-browser-process-record.js +1 -0
  71. package/dist/src/agent-browser-provider.js +1 -0
  72. package/dist/src/agent-browser-tool.js +1 -1
  73. package/dist/src/agent-device-client.js +2 -2
  74. package/dist/src/ai-sdk.d.ts +61 -0
  75. package/dist/src/ai-sdk.js +1 -0
  76. package/dist/src/alert-contract.js +1 -0
  77. package/dist/src/alert-runtime.js +1 -0
  78. package/dist/src/android-adb.d.ts +27 -19
  79. package/dist/src/android-adb.js +1 -1
  80. package/dist/src/android-input-ownership.js +1 -0
  81. package/dist/src/android-system-chrome.js +1 -0
  82. package/dist/src/android.js +1 -1
  83. package/dist/src/api.js +11 -0
  84. package/dist/src/app-catalog.js +1 -0
  85. package/dist/src/app-deployment-resolution.js +2 -0
  86. package/dist/src/app-helpers.js +1 -1
  87. package/dist/src/app-inventory-contract.js +1 -0
  88. package/dist/src/app-inventory.js +1 -0
  89. package/dist/src/app-launch.js +2 -0
  90. package/dist/src/app-lifecycle-facade.js +1 -0
  91. package/dist/src/app-lifecycle.js +3 -6
  92. package/dist/src/app-lifecycle2.js +2 -2
  93. package/dist/src/app-lifecycle3.js +1 -0
  94. package/dist/src/app-log-files.js +1 -1
  95. package/dist/src/app-log-reconnect.js +1 -1
  96. package/dist/src/app-log-runtime.js +1 -4
  97. package/dist/src/app-log-runtime2.js +4 -0
  98. package/dist/src/app-parsers.js +4 -0
  99. package/dist/src/app-resolution-cache.js +1 -0
  100. package/dist/src/app-resolution-facade.js +1 -0
  101. package/dist/src/app-resolution.js +2 -2
  102. package/dist/src/app-state.js +1 -2
  103. package/dist/src/application-lifecycle-interaction.js +1 -0
  104. package/dist/src/application-lifecycle-runtime.js +1 -0
  105. package/dist/src/apps-simctl.js +1 -0
  106. package/dist/src/archive.js +4 -0
  107. package/dist/src/artifact-download.js +1 -0
  108. package/dist/src/artifacts.d.ts +6 -2
  109. package/dist/src/artifacts.js +1 -1
  110. package/dist/src/async-lifecycle.js +1 -0
  111. package/dist/src/audio-probe-result.js +1 -0
  112. package/dist/src/audio-probe-runtime.js +1 -0
  113. package/dist/src/audio-probe-support.js +1 -0
  114. package/dist/src/auth-session.js +1 -1
  115. package/dist/src/auth.js +1 -1
  116. package/dist/src/back-mode.js +1 -0
  117. package/dist/src/{url.js → base-url.js} +1 -1
  118. package/dist/src/boot-diagnostics.js +2 -2
  119. package/dist/src/byte-limit-stream.js +1 -1
  120. package/dist/src/capabilities.js +1 -0
  121. package/dist/src/capture.js +1 -0
  122. package/dist/src/catalog.js +1 -0
  123. package/dist/src/cli-command-aliases.js +1 -0
  124. package/dist/src/cli-config.js +1 -1
  125. package/dist/src/cli-help.js +77 -51
  126. package/dist/src/cli-output.js +1 -1
  127. package/dist/src/cli-runner.js +1 -1
  128. package/dist/src/cli.js +5 -7
  129. package/dist/src/click-button.js +1 -0
  130. package/dist/src/client-metro-companion.js +1 -0
  131. package/dist/src/client-metro.js +1 -1
  132. package/dist/src/client-types.d.ts +1606 -0
  133. package/dist/src/clipboard.js +1 -0
  134. package/dist/src/code-signature-cache.js +1 -0
  135. package/dist/src/code-signature.js +1 -0
  136. package/dist/src/color.js +1 -0
  137. package/dist/src/command-metadata.js +1 -1
  138. package/dist/src/command-schema.js +3 -3
  139. package/dist/src/command-surface.js +1 -1
  140. package/dist/src/command-tools.js +2 -0
  141. package/dist/src/command.js +1 -0
  142. package/dist/src/{selector-vocabulary.js → compatibility-policy.js} +1 -1
  143. package/dist/src/config.js +1 -1
  144. package/dist/src/config2.js +1 -0
  145. package/dist/src/connection-runtime.js +1 -1
  146. package/dist/src/connection.js +5 -5
  147. package/dist/src/contracts.d.ts +1 -1
  148. package/dist/src/contracts.js +1 -1
  149. package/dist/src/daemon-client-lifecycle.js +1 -0
  150. package/dist/src/daemon-process.js +1 -0
  151. package/dist/src/daemon-registration.js +1 -0
  152. package/dist/src/daemon-shutdown-report.js +1 -1
  153. package/dist/src/daemon.js +2 -2
  154. package/dist/src/debug-symbols-facade.js +5 -0
  155. package/dist/src/deploy-result-target.js +1 -0
  156. package/dist/src/device-claim-inspection.js +1 -1
  157. package/dist/src/device-claim-rule.js +1 -0
  158. package/dist/src/device-input-state.d.ts +190 -3
  159. package/dist/src/device-inventory-context.js +1 -0
  160. package/dist/src/device-isolation.js +1 -0
  161. package/dist/src/device-release.js +1 -0
  162. package/dist/src/device-rotation.js +1 -0
  163. package/dist/src/device-selection-resolver.js +1 -0
  164. package/dist/src/device-session.js +1 -0
  165. package/dist/src/device.js +1 -1
  166. package/dist/src/device2.js +3 -2
  167. package/dist/src/diagnostics.js +3 -0
  168. package/dist/src/diagnostics2.js +1 -0
  169. package/dist/src/dispatch-resolve.js +1 -0
  170. package/dist/src/doctor-facade.js +1 -0
  171. package/dist/src/doctor-output.js +1 -0
  172. package/dist/src/doctor.js +1 -0
  173. package/dist/src/doctor2.js +1 -0
  174. package/dist/src/doctor3.js +1 -0
  175. package/dist/src/durable-resource.js +1 -0
  176. package/dist/src/entities.js +1 -1
  177. package/dist/src/error.js +2 -0
  178. package/dist/src/exec.js +1 -0
  179. package/dist/src/file.js +1 -0
  180. package/dist/src/find.js +1 -1
  181. package/dist/src/finders.js +1 -1
  182. package/dist/src/format.js +2 -0
  183. package/dist/src/generic-settle.js +1 -1
  184. package/dist/src/generic.js +1 -1
  185. package/dist/src/gesture-admission.js +1 -0
  186. package/dist/src/gesture-plan-types.js +1 -0
  187. package/dist/src/gesture-plan.js +1 -0
  188. package/dist/src/gesture-runtime.js +1 -0
  189. package/dist/src/harmonyos.js +1 -1
  190. package/dist/src/hdc.js +1 -1
  191. package/dist/src/helper.js +2 -2
  192. package/dist/src/host-file.js +1 -0
  193. package/dist/src/human-control-contract.js +1 -0
  194. package/dist/src/human-control.js +1 -0
  195. package/dist/src/index.d.ts +2 -1578
  196. package/dist/src/index.js +1 -1
  197. package/dist/src/input-actions.js +1 -4
  198. package/dist/src/input-actions2.js +2 -1
  199. package/dist/src/install-artifact-facade.js +1 -0
  200. package/dist/src/install-source-network-transport.js +1 -0
  201. package/dist/src/install-source.d.ts +3 -10
  202. package/dist/src/install-source2.js +1 -1
  203. package/dist/src/interaction-positionals.js +1 -0
  204. package/dist/src/interaction-ref-policy.js +1 -0
  205. package/dist/src/interaction.js +1 -1
  206. package/dist/src/interaction2.js +1 -1
  207. package/dist/src/interactor-operation-catalog.js +1 -0
  208. package/dist/src/interactor-types.js +1 -0
  209. package/dist/src/interactor.js +6 -2
  210. package/dist/src/interactor2.js +1 -1
  211. package/dist/src/interactors.js +1 -1
  212. package/dist/src/internal/bin.d.ts +1 -1
  213. package/dist/src/internal/bin.js +1 -2
  214. package/dist/src/internal/companion-tunnel.d.ts +1 -1
  215. package/dist/src/internal/companion-tunnel.js +1 -1
  216. package/dist/src/internal/daemon.d.ts +1 -1
  217. package/dist/src/internal/daemon.js +2 -4
  218. package/dist/src/internal/png-worker.d.ts +4 -4
  219. package/dist/src/internal/png-worker.js +1 -1
  220. package/dist/src/internal/run-script-http-child.d.ts +4 -0
  221. package/dist/src/internal/run-script-http-child.js +1 -0
  222. package/dist/src/internal/update-check-entry.d.ts +1 -1
  223. package/dist/src/inventory.js +4 -4
  224. package/dist/src/inventory2.js +1 -1
  225. package/dist/src/inventory3.js +1 -1
  226. package/dist/src/inventory5.js +1 -1
  227. package/dist/src/inventory6.js +1 -1
  228. package/dist/src/ios-client.js +16 -0
  229. package/dist/src/ios-snapshot-acquisition.js +1 -0
  230. package/dist/src/ios-snapshot-adapter.js +1 -0
  231. package/dist/src/ios-snapshot-planning.js +1 -0
  232. package/dist/src/ios-snapshot-runtime.js +1 -0
  233. package/dist/src/json.js +1 -0
  234. package/dist/src/keyboard-actions.js +1 -0
  235. package/dist/src/launch-console.js +1 -0
  236. package/dist/src/lease-context.js +1 -1
  237. package/dist/src/lease-scope.js +1 -0
  238. package/dist/src/lease.js +1 -1
  239. package/dist/src/limrun-runtime-dependencies.js +1 -1
  240. package/dist/src/limrun.d.ts +1618 -7
  241. package/dist/src/limrun.js +1 -1
  242. package/dist/src/linux.js +1 -1
  243. package/dist/src/local-interactor-operation-set.js +1 -0
  244. package/dist/src/location-coordinates.js +1 -1
  245. package/dist/src/logcat.js +1 -1
  246. package/dist/src/macos-facade.js +1 -0
  247. package/dist/src/managed-device-scope.js +1 -0
  248. package/dist/src/mechanics.js +19 -0
  249. package/dist/src/metro.d.ts +4 -2
  250. package/dist/src/metro.js +1 -1
  251. package/dist/src/metro2.js +1 -1
  252. package/dist/src/mobile-snapshot-semantics.js +1 -0
  253. package/dist/src/multitouch-support.js +1 -0
  254. package/dist/src/numeric.js +1 -0
  255. package/dist/src/observability.js +1 -1
  256. package/dist/src/observation.js +2 -0
  257. package/dist/src/output-path.js +1 -1
  258. package/dist/src/owner-identity.js +3 -1
  259. package/dist/src/parameterized-recorded-fill.js +1 -0
  260. package/dist/src/parser.js +1 -1
  261. package/dist/src/perf-facade.js +2 -0
  262. package/dist/src/perf-runtime-operation-builder.js +1 -0
  263. package/dist/src/perf-runtime-plan.js +1 -0
  264. package/dist/src/perf-runtime.js +1 -0
  265. package/dist/src/perf.js +1 -4
  266. package/dist/src/physical-device-control.js +1 -1
  267. package/dist/src/physical-device-facade.js +1 -0
  268. package/dist/src/platform-request-scope.js +1 -0
  269. package/dist/src/platform-runtime-android-adb-host.js +1 -0
  270. package/dist/src/platform-runtime-android-mechanics.js +1 -0
  271. package/dist/src/platform-runtime-app-log-android-transport.js +1 -1
  272. package/dist/src/platform-runtime-app-log-process.js +1 -1
  273. package/dist/src/platform-runtime-apple-resources.js +1 -0
  274. package/dist/src/platform-runtime-host.js +1 -1
  275. package/dist/src/platform-runtime-managed-owner.js +1 -0
  276. package/dist/src/platform-runtime-network-web-transport.js +1 -1
  277. package/dist/src/platform-runtime-open-target.js +1 -1
  278. package/dist/src/platform-runtime-operation-host.js +4 -4
  279. package/dist/src/platform-runtime-runtime-hints.js +2 -2
  280. package/dist/src/platform-runtime-screen-recording-android-host.js +1 -1
  281. package/dist/src/platform-runtime-screen-recording-apple-runner-host.js +1 -1
  282. package/dist/src/platform-runtime-screen-recording-apple-runner-transport.js +1 -1
  283. package/dist/src/platform-runtime-screen-recording-apple-simulator-host.js +1 -1
  284. package/dist/src/platform-runtime-screen-recording-apple-transport.js +1 -1
  285. package/dist/src/platform-runtime-screen-recording-finalizer-host.js +1 -1
  286. package/dist/src/platform-runtime-screen-recording-harmony-host.js +1 -1
  287. package/dist/src/platform-runtime-screen-recording-process-host.js +1 -0
  288. package/dist/src/platform-runtime-screen-recording-web-host.js +1 -1
  289. package/dist/src/platform-runtime-unavailable.js +1 -0
  290. package/dist/src/platform-runtime.js +1 -1
  291. package/dist/src/platform-runtime2.js +1 -1
  292. package/dist/src/plist.js +1 -1
  293. package/dist/src/png-worker-contract.js +1 -1
  294. package/dist/src/prepare-kind.js +1 -15
  295. package/dist/src/process-exit.js +1 -1
  296. package/dist/src/process.js +1 -0
  297. package/dist/src/provider-device-runtime.js +1 -0
  298. package/dist/src/provider-session-ownership.js +2 -0
  299. package/dist/src/provider-webdriver.js +1 -1
  300. package/dist/src/provider.js +1 -1
  301. package/dist/src/providers.js +1 -0
  302. package/dist/src/proxy.js +2 -2
  303. package/dist/src/react-native-overlay.js +1 -0
  304. package/dist/src/react-native.js +1 -1
  305. package/dist/src/record-runtime.js +1 -1
  306. package/dist/src/record-trace.js +1 -1
  307. package/dist/src/rect-center.js +1 -0
  308. package/dist/src/register-builtins.js +1 -0
  309. package/dist/src/registry.js +39 -28
  310. package/dist/src/remote-config2.js +1 -1
  311. package/dist/src/replay-divergence.js +2 -0
  312. package/dist/src/replay.js +2 -2
  313. package/dist/src/reporting.js +8 -8
  314. package/dist/src/request-admission.js +1 -0
  315. package/dist/src/request-cancel.js +1 -0
  316. package/dist/src/request-cancellation.js +1 -0
  317. package/dist/src/request-progress-protocol.js +1 -0
  318. package/dist/src/request-providers.js +1 -0
  319. package/dist/src/request-runtime-binding.js +1 -0
  320. package/dist/src/request.js +1 -0
  321. package/dist/src/result-serialization.js +1 -0
  322. package/dist/src/retry.js +1 -0
  323. package/dist/src/rolldown-runtime.js +1 -1
  324. package/dist/src/runner-cache-metadata.js +2 -0
  325. package/dist/src/runner-client.js +1 -1
  326. package/dist/src/runner-disposal.js +1 -1
  327. package/dist/src/runner-operations-facade.js +1 -0
  328. package/dist/src/runner-owner-facade.js +1 -0
  329. package/dist/src/runner-owner-state.js +1 -0
  330. package/dist/src/runner-presentation.js +1 -0
  331. package/dist/src/runner-selector-query.js +1 -0
  332. package/dist/src/runner.js +1 -0
  333. package/dist/src/{runtime-transport.js → runtime-transport-hints.js} +1 -1
  334. package/dist/src/runtime.js +3 -3
  335. package/dist/src/runtime2.js +4 -4
  336. package/dist/src/runtime3.js +1 -1
  337. package/dist/src/runtime4.js +4 -3
  338. package/dist/src/runtime5.js +1 -1
  339. package/dist/src/runtime6.js +1 -1
  340. package/dist/src/runtime7.js +1 -1
  341. package/dist/src/runtime8.js +1 -1
  342. package/dist/src/runtime9.js +1 -1
  343. package/dist/src/scoped-provider.js +1 -1
  344. package/dist/src/screen-recording-completion.js +1 -0
  345. package/dist/src/screen-recording-live-handle.js +1 -0
  346. package/dist/src/screen-recording-options.js +1 -0
  347. package/dist/src/screen-recording-resource-recovery.js +1 -0
  348. package/dist/src/screen-recording-runtime.js +1 -0
  349. package/dist/src/screenshot-density.js +1 -1
  350. package/dist/src/screenshot-result.js +1 -6
  351. package/dist/src/screenshot-runtime.js +1 -0
  352. package/dist/src/screenshot.js +1 -1
  353. package/dist/src/screenshot2.js +1 -0
  354. package/dist/src/screenshot3.js +5 -0
  355. package/dist/src/script.js +1 -0
  356. package/dist/src/scroll-command.js +1 -0
  357. package/dist/src/scroll-gesture.js +1 -0
  358. package/dist/src/scroll-indicator.js +1 -0
  359. package/dist/src/sdk-batch-runner.d.ts +23 -6
  360. package/dist/src/sdk-batch-runner.js +2 -3
  361. package/dist/src/sdk-batch.js +2 -0
  362. package/dist/src/sdk-contracts.d.ts +222 -99
  363. package/dist/src/sdk-contracts.js +2 -2
  364. package/dist/src/sdk-device.js +1 -1
  365. package/dist/src/sdk-finders.d.ts +1 -1
  366. package/dist/src/sdk-finders.js +1 -1
  367. package/dist/src/sdk-io.js +1 -1
  368. package/dist/src/sdk-remote-config.d.ts +1 -1
  369. package/dist/src/sdk-remote-config.js +1 -1
  370. package/dist/src/sdk-selectors.d.ts +539 -199
  371. package/dist/src/sdk-selectors.js +1 -1
  372. package/dist/src/selection.js +1 -0
  373. package/dist/src/selector-runtime.js +1 -1
  374. package/dist/src/selectors.js +1 -1
  375. package/dist/src/semantic-index.js +1 -0
  376. package/dist/src/server.js +10 -3
  377. package/dist/src/session-allocation.js +1 -0
  378. package/dist/src/session-artifact-paths.js +1 -0
  379. package/dist/src/session-paths.js +1 -0
  380. package/dist/src/session-repair-tombstone.js +1 -0
  381. package/dist/src/session-routing.js +1 -0
  382. package/dist/src/session-runtime-admission.js +1 -0
  383. package/dist/src/session-snapshot.js +1 -0
  384. package/dist/src/session-store.js +4 -0
  385. package/dist/src/session-target-evidence.js +1 -1
  386. package/dist/src/session2.js +5 -28
  387. package/dist/src/settings.js +1 -0
  388. package/dist/src/shared.js +2 -2
  389. package/dist/src/simctl-facade.js +1 -0
  390. package/dist/src/simctl.js +1 -1
  391. package/dist/src/simulator-facade.js +1 -0
  392. package/dist/src/simulator.js +1 -1
  393. package/dist/src/snapshot-capture-annotations.js +1 -0
  394. package/dist/src/snapshot-desktop-projection.js +1 -0
  395. package/dist/src/snapshot-diagnostics.js +1 -0
  396. package/dist/src/snapshot-process.js +1 -0
  397. package/dist/src/snapshot-quality-backend-capabilities.js +1 -0
  398. package/dist/src/snapshot-quality-verdict.js +1 -0
  399. package/dist/src/snapshot-runtime-binding.js +1 -0
  400. package/dist/src/snapshot-runtime.js +1 -1
  401. package/dist/src/snapshot-scope.js +1 -0
  402. package/dist/src/snapshot-state.js +1 -0
  403. package/dist/src/snapshot.js +1 -8
  404. package/dist/src/snapshot2.js +1 -1
  405. package/dist/src/snapshot3.js +1 -1
  406. package/dist/src/snapshot4.js +1 -0
  407. package/dist/src/src.js +1 -1
  408. package/dist/src/src2.js +1 -1
  409. package/dist/src/src3.js +1 -2
  410. package/dist/src/src4.js +1 -0
  411. package/dist/src/src5.js +1 -0
  412. package/dist/src/src6.js +1 -0
  413. package/dist/src/src7.js +2 -0
  414. package/dist/src/src8.js +115 -0
  415. package/dist/src/startup-recovery-fence.js +1 -0
  416. package/dist/src/status-markers.js +1 -0
  417. package/dist/src/string-enum.js +1 -1
  418. package/dist/src/success-text.js +1 -0
  419. package/dist/src/surface-snapshot.js +1 -0
  420. package/dist/src/surface-snapshot2.js +1 -0
  421. package/dist/src/takeover.js +5 -0
  422. package/dist/src/tool-provider-facade.js +1 -0
  423. package/dist/src/tool-provider.js +4 -3
  424. package/dist/src/tool-provider2.js +1 -1
  425. package/dist/src/tool-provider3.js +1 -0
  426. package/dist/src/toolchain-probe.js +2 -0
  427. package/dist/src/touch-runtime.js +1 -0
  428. package/dist/src/transport.js +3 -0
  429. package/dist/src/tree.js +1 -0
  430. package/dist/src/ttl-memo.js +1 -0
  431. package/dist/src/tv-remote.js +1 -0
  432. package/dist/src/type-text-runtime.js +1 -0
  433. package/dist/src/undici.js +99 -0
  434. package/dist/src/update-check.js +1 -1
  435. package/dist/src/verified-file.js +1 -1
  436. package/dist/src/version.js +1 -1
  437. package/dist/src/video.js +2 -2
  438. package/dist/src/web.js +2 -1
  439. package/dist/src/web2.js +1 -0
  440. package/dist/src/webdriver-ios-snapshot.js +1 -0
  441. package/dist/src/webdriver-source.js +1 -0
  442. package/linux/atspi-dump.py +54 -9
  443. package/package.json +73 -38
  444. package/server.json +9 -3
  445. package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.9.apk.sha256 +0 -1
  446. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.9.apk +0 -0
  447. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.9.apk.sha256 +0 -1
  448. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CoordinateTextEntryTests.swift +0 -4
  449. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+FlatSnapshotFiltering.swift +0 -75
  450. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+LifecycleCacheTests.swift +0 -6
  451. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+RecordingTests.swift +0 -4
  452. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SelectorMatchPolicyTests.swift +0 -4
  453. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotTraversalIdentityTests.swift +0 -4
  454. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryPolicyTests.swift +0 -4
  455. package/dist/src/appearance.js +0 -1
  456. package/dist/src/apps.js +0 -5
  457. package/dist/src/audio-probe.js +0 -1
  458. package/dist/src/cancel.js +0 -1
  459. package/dist/src/cli-grammar.js +0 -1
  460. package/dist/src/command-catalog.js +0 -1
  461. package/dist/src/debug-symbols.js +0 -5
  462. package/dist/src/device-input-state.js +0 -2
  463. package/dist/src/device-ready.js +0 -1
  464. package/dist/src/dispatch.js +0 -1
  465. package/dist/src/handler-utils.js +0 -1
  466. package/dist/src/helper-package-install.js +0 -1
  467. package/dist/src/host-process.js +0 -3
  468. package/dist/src/ime-lifecycle.js +0 -2
  469. package/dist/src/ime-recovery-marker.js +0 -1
  470. package/dist/src/input-actions3.js +0 -1
  471. package/dist/src/install-artifact.js +0 -1
  472. package/dist/src/install-artifact2.js +0 -1
  473. package/dist/src/interaction-common.js +0 -1
  474. package/dist/src/interaction-runtime.js +0 -1
  475. package/dist/src/interaction-snapshot.js +0 -1
  476. package/dist/src/manifest.js +0 -1
  477. package/dist/src/method-scope.js +0 -1
  478. package/dist/src/png-resize.js +0 -1
  479. package/dist/src/process-lock.js +0 -1
  480. package/dist/src/runner-lease.js +0 -1
  481. package/dist/src/runner-sequence.js +0 -1
  482. package/dist/src/screenshot-geometry.js +0 -1
  483. package/dist/src/sdk-android-adb.d.ts +0 -245
  484. package/dist/src/sdk-android-adb.js +0 -4
  485. package/dist/src/sdk.js +0 -1
  486. package/dist/src/setting-state.js +0 -1
  487. package/dist/src/shell-quote.js +0 -1
  488. package/dist/src/snapshot-session.js +0 -1
  489. package/dist/src/timing-safe-equal.js +0 -1
  490. package/dist/src/unsupported-interactor.js +0 -1
  491. package/dist/src/verdict.js +0 -1
  492. /package/dist/src/{recording-telemetry.js → telemetry.js} +0 -0
@@ -1,5 +1,5 @@
1
- import{_ as e}from"./sdk-contracts.js";import{H as t,U as n,V as r,at as i,bt as a,dt as o,et as s,ot as c,st as l,tt as u,z as d}from"./sdk-batch-runner.js";import{C as ee}from"./sdk-device.js";import{a as f,i as p,n as m,o as h,p as g,r as _,t as v,v as te,x as y}from"./src3.js";import{readAndroidAppState as b}from"./app-state.js";import x from"node:path";function S(t){if(!/^[a-zA-Z0-9._:-]+$/.test(t))throw new e(`INVALID_ARGS`,`Invalid Android package name for logs: ${t}`)}const C=Object.freeze({resourceKind:u,version:1,encode:e=>({...e}),decode:e=>e.transport!==`android-logcat-local`&&e.transport!==`android-logcat-transport-composed`||!re(e.outputPath)||!re(e.pidPath)?{status:`invalid`,message:`Invalid Android app-log descriptor`}:{status:`decoded`,descriptor:Object.freeze({transport:e.transport,outputPath:e.outputPath,pidPath:e.pidPath})}});function ne(e){let t=C.decode(e.descriptor);if(t.status!==`decoded`)throw TypeError(t.message);return te({resourceKind:u,sessionId:e.sessionId,device:{id:e.device.id,family:`android`,kind:e.device.kind,...e.device.target===void 0?{}:{target:e.device.target}},owner:e.owner,fence:e.fence,lifecycle:`open`,descriptor:y(C,t.descriptor)})}function re(e){return typeof e==`string`&&e.trim().length>0}function ie(e){return f(e,{family:`android`,backend:`android`,label:`Android`,codec:C,startUnavailableHint:`The selected Android transport cannot start a background adb logcat stream.`,cleanupFailureMessage:`Android app-log cleanup did not settle every owned resource`,doctor:async({host:e,device:t,signal:n},r)=>await ae(e,t.id,r,n),validateStart:({input:e})=>S(e.appBundleId),process:async({host:e,device:t,input:n})=>({resolvePid:async r=>await h(e,oe(t.id,n.appBundleId),r),command:e=>({kind:`android-adb`,serial:t.id,args:[`logcat`,`-v`,`time`,`--pid`,e],options:{allowFailure:!0}})}),descriptor:({artifacts:e,transport:t})=>({transport:t.mode===`transport-composed`?`android-logcat-transport-composed`:`android-logcat-local`,...e}),envelope:({input:e,device:t,owner:n,descriptor:r})=>ne({sessionId:e.sessionId,device:t,owner:n,fence:e.fence,descriptor:r})})}async function ae(e,t,n,r){let i={};return i.adbAvailable=await p(async()=>_(await e.commands.run({executable:`adb`,args:[`-s`,t,`shell`,`echo`,`ok`],allowFailure:!0,timeoutMs:1e3},r)),r),n&&(i.androidPidVisible=await p(async()=>!!await h(e,oe(t,n),r),r)),{backend:`android`,checks:i,notes:n?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`]}}function oe(e,t){return{executable:`adb`,args:[`-s`,e,`shell`,`pidof`,t],allowFailure:!0,timeoutMs:5e3}}async function se(e,t,n,r){let i=await e.appLogs.readRecent(n.sessionId,n.maxScanLines),a=m(i.text,{...n,path:i.path,exists:i.exists,lineNumberOffset:i.skippedLines,backend:`android`}),o=[],s=await le(e,t,n,r);if(s&&n.appBundleId){S(n.appBundleId);let c=await de(e,t,n.appBundleId,r);if(c){let e=m(c.text,{...n,path:`${i.path} (adb logcat recovery)`,exists:!0,backend:`android`});e.entries.length>0&&(a=v(e,a,n.maxEntries),o.push(s.reason===`stale-active`?`Session app log stream was still bound to prior Android PID ${s.trackedPid}. Recovered recent Android HTTP entries from adb logcat for PID set ${c.pids.join(`, `)}.`:`Session app log stream was inactive. Recovered recent Android HTTP entries from adb logcat for PID set ${c.pids.join(`, `)}.`))}}return n.appLogSnapshot?n.appLogSnapshot.state!==`active`&&o.length===0&&o.push(`Session app log stream is inactive. Run logs clear --restart, reproduce the request window again, then rerun network dump.`):o.push(`Capture uses the session app log file. For fresh traffic, run logs clear --restart before reproducing requests.`),a.entries.length===0&&o.push(`No HTTP(s) entries were found in recent session app logs.`),Object.freeze({source:`app-log`,backend:`android`,dump:a,notes:Object.freeze(o)})}async function ce(e,t,n){n.throwIfAborted();try{let r=await e.commands.run(t,n);return n.throwIfAborted(),r}catch{n.throwIfAborted();return}}async function le(e,t,n,r){if(!n.appBundleId||n.appLogSnapshot?.state===void 0)return;if(n.appLogSnapshot.state!==`active`)return{reason:`inactive`};let i=ue(await e.appLogs.readProcessMarker(n.sessionId));if(!i)return;let a=await fe(e,t.id,n.appBundleId,r);if(!(!a||a===i))return{reason:`stale-active`,trackedPid:i}}function ue(e){if(e.status===`decoded`)return/(?:^|\s)--pid\s+(\d+)(?:\s|$)/.exec(e.marker.command)?.[1]}async function de(e,t,n,r){let i=await fe(e,t.id,n,r),a=await ce(e,{executable:`adb`,args:[`-s`,t.id,`logcat`,`-d`,`-v`,`time`,`-t`,`4000`],allowFailure:!0,timeoutMs:3e3},r);if(!a||a.exitCode!==0||!a.stdout.trim())return;let o=pe(a.stdout,n,i);if(o.length===0)return;let s=new Set(o),c=a.stdout.split(`
1
+ import{y as e}from"./sdk-contracts.js";import{w as t}from"./sdk-device.js";import{Wt as n,Xt as r}from"./sdk-batch.js";import{n as i,r as a,t as o}from"./application-lifecycle-runtime.js";import{i as s}from"./touch-runtime.js";import{A as c,D as l,G as u,H as d,I as f,L as p,N as m,R as h,a as g,b as ee,d as _,g as te,i as ne,m as re,s as ie,t as ae,v as oe,w as se,x as ce,z as le}from"./alert-runtime.js";import{n as ue}from"./audio-probe-runtime.js";import{n as de}from"./perf-runtime.js";import{a as fe,n as pe}from"./durable-resource.js";import{n as me}from"./async-lifecycle.js";import{i as he,l as ge,n as v,r as _e,t as ve}from"./src7.js";import{t as ye}from"./screen-recording-live-handle.js";import{n as be,r as xe,t as Se}from"./audio-probe-support.js";import{t as Ce}from"./screen-recording-runtime.js";import{readAndroidAppStateWithExecutor as we}from"./app-state.js";import{i as Te,t as Ee}from"./gesture-admission.js";import{t as De}from"./local-interactor-operation-set.js";import{a as Oe,i as ke,n as Ae,r as je,t as Me}from"./perf-runtime-operation-builder.js";import{t as Ne}from"./app-log-runtime.js";import{n as y,r as Pe}from"./managed-device-scope.js";import{a as Fe,i as Ie,n as Le,o as Re}from"./application-lifecycle-interaction.js";import b from"node:path";function ze(e){return Se(e)?Object.freeze({available:!0}):e.kind===`emulator`?Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`audio probe capture requires a macOS host.`}):Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`audio probe capture is supported for Android emulators on macOS hosts.`})}function Be(e){let{resolveHost:t,device:n,owner:r}=e;return Object.freeze({...Me({platform:`Android`,expectedProfileKind:`simpleperf`,start:async e=>await t().start(n,r,e),reattach:async e=>await t().reattach(n,e),cleanup:async e=>await t().cleanup(n,e),writeProfileReport:async e=>await t().writeProfileReport(n,e)}),perfFrames:async({appId:e})=>({metric:e?await ke(t().sampleFrames(n,e)):Ae(`Android`,`package`),sampling:{method:`adb-shell-dumpsys-gfxinfo-framestats`,description:`Rendered-frame health from the current adb shell dumpsys gfxinfo <package> framestats window. Dropped frames use Android gfxinfo janky-frame/frame-deadline data when available; this is not video recording FPS.`,unit:`percent`,primaryField:`droppedFramePercent`,window:`since previous Android gfxinfo reset or app process start`,resetsAfterRead:!0,relatedActionsLimit:12}}),perfMemorySample:async({appId:e})=>({metric:e?await ke(t().sampleMemory(n,e)):Ae(`Android`,`package`),sampling:{method:`adb-shell-dumpsys-meminfo`,description:`Memory snapshot from adb shell dumpsys meminfo <package>. Values are reported in kilobytes.`,unit:`kB`,topConsumerLimit:5}}),perfMemorySnapshot:async({appId:e,kind:r,outPath:i,artifactsDir:a})=>{let o=r??`android-hprof`,s=Ve();if(o!==`android-hprof`)return Oe(`Android`,o,s,`Use perf memory snapshot --kind android-hprof for Android Java heap artifacts.`);if(!e)throw je();let c=i??b.join(a,`memory-android-hprof-${He()}.hprof`);return{artifact:await t().captureMemorySnapshot(n,e,c),support:s,sampling:{method:`adb-shell-am-dumpheap`,description:`Java heap dump captured with adb shell am dumpheap, pulled to a local artifact path.`,defaultKind:`android-hprof`,artifactOnly:!0}}}})}function Ve(){return{platform:`android`,defaultKind:`android-hprof`,androidHprof:!0,memgraph:!1,heapprofd:!1,heapprofdDecision:`Deferred until Android Perfetto/heapprofd plumbing is available in the perf trace slice.`}}function He(){return new Date().toISOString().replaceAll(/[:.]/g,`-`)}function Ue(t){if(!/^[a-zA-Z0-9._:-]+$/.test(t))throw new e(`INVALID_ARGS`,`Invalid Android package name for logs: ${t}`)}const x=Object.freeze({resourceKind:Ne,version:1,encode:e=>({...e}),decode:e=>e.transport!==`android-logcat-local`&&e.transport!==`android-logcat-transport-composed`||!Ge(e.outputPath)||!Ge(e.pidPath)?{status:`invalid`,message:`Invalid Android app-log descriptor`}:{status:`decoded`,descriptor:Object.freeze({transport:e.transport,outputPath:e.outputPath,pidPath:e.pidPath})}});function We(e){let t=x.decode(e.descriptor);if(t.status!==`decoded`)throw TypeError(t.message);return pe({resourceKind:Ne,sessionId:e.sessionId,device:{id:e.device.id,family:`android`,kind:e.device.kind,...e.device.target===void 0?{}:{target:e.device.target}},owner:e.owner,fence:e.fence,lifecycle:`open`,descriptor:fe(x,t.descriptor)})}function Ge(e){return typeof e==`string`&&e.trim().length>0}function Ke(e){return _e(e,{family:`android`,backend:`android`,label:`Android`,codec:x,startUnavailableHint:`The selected Android transport cannot start a background adb logcat stream.`,cleanupFailureMessage:`Android app-log cleanup did not settle every owned resource`,doctor:async({host:e,device:t,signal:n},r)=>await qe(e,t.id,r,n),validateStart:({input:e})=>Ue(e.appBundleId),process:async({host:e,device:t,input:n})=>({resolvePid:async r=>await he(e,Je(t.id,n.appBundleId),r),command:e=>({kind:`android-adb`,serial:t.id,args:[`logcat`,`-v`,`time`,`--pid`,e],options:{allowFailure:!0}})}),descriptor:({artifacts:e,transport:t})=>({transport:t.mode===`transport-composed`?`android-logcat-transport-composed`:`android-logcat-local`,...e}),envelope:({input:e,device:t,owner:n,descriptor:r})=>We({sessionId:e.sessionId,device:t,owner:n,fence:e.fence,descriptor:r})})}async function qe(e,t,n,r){let i={};return i.adbAvailable=await xe(async()=>be(await e.commands.run({executable:`adb`,args:[`-s`,t,`shell`,`echo`,`ok`],allowFailure:!0,timeoutMs:1e3},r)),r),n&&(i.androidPidVisible=await xe(async()=>!!await he(e,Je(t,n),r),r)),{backend:`android`,checks:i,notes:n?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`]}}function Je(e,t){return{executable:`adb`,args:[`-s`,e,`shell`,`pidof`,t],allowFailure:!0,timeoutMs:5e3}}async function Ye(e,t,n,r){let i=await e.appLogs.readRecent(n.sessionId,n.maxScanLines),a=v(i.text,{...n,path:i.path,exists:i.exists,lineNumberOffset:i.skippedLines,backend:`android`}),o=[],s=await Ze(e,t,n,r);if(s&&n.appBundleId){Ue(n.appBundleId);let c=await $e(e,t,n.appBundleId,r);if(c){let e=v(c.text,{...n,path:`${i.path} (adb logcat recovery)`,exists:!0,backend:`android`});e.entries.length>0&&(a=ve(e,a,n.maxEntries),o.push(s.reason===`stale-active`?`Session app log stream was still bound to prior Android PID ${s.trackedPid}. Recovered recent Android HTTP entries from adb logcat for PID set ${c.pids.join(`, `)}.`:`Session app log stream was inactive. Recovered recent Android HTTP entries from adb logcat for PID set ${c.pids.join(`, `)}.`))}}return n.appLogSnapshot?n.appLogSnapshot.state!==`active`&&o.length===0&&o.push(`Session app log stream is inactive. Run logs clear --restart, reproduce the request window again, then rerun network dump.`):o.push(`Capture uses the session app log file. For fresh traffic, run logs clear --restart before reproducing requests.`),a.entries.length===0&&o.push(`No HTTP(s) entries were found in recent session app logs.`),Object.freeze({source:`app-log`,backend:`android`,dump:a,notes:Object.freeze(o)})}async function Xe(e,t,n){n.throwIfAborted();try{let r=await e.commands.run(t,n);return n.throwIfAborted(),r}catch{n.throwIfAborted();return}}async function Ze(e,t,n,r){if(!n.appBundleId||n.appLogSnapshot?.state===void 0)return;if(n.appLogSnapshot.state!==`active`)return{reason:`inactive`};let i=Qe(await e.appLogs.readProcessMarker(n.sessionId));if(!i)return;let a=await et(e,t.id,n.appBundleId,r);if(!(!a||a===i))return{reason:`stale-active`,trackedPid:i}}function Qe(e){if(e.status===`decoded`)return/(?:^|\s)--pid\s+(\d+)(?:\s|$)/.exec(e.marker.command)?.[1]}async function $e(e,t,n,r){let i=await et(e,t.id,n,r),a=await Xe(e,{executable:`adb`,args:[`-s`,t.id,`logcat`,`-d`,`-v`,`time`,`-t`,`4000`],allowFailure:!0,timeoutMs:3e3},r);if(!a||a.exitCode!==0||!a.stdout.trim())return;let o=tt(a.stdout,n,i);if(o.length===0)return;let s=new Set(o),c=a.stdout.split(`
2
2
  `).filter(e=>{if(!e.trim())return!1;if(e.includes(n))return!0;let t=/\(\s*(\d+)\)\s*:/.exec(e)?.[1];return!!(t&&s.has(t))}).join(`
3
- `);return c.trim()?{text:c,pids:o}:void 0}async function fe(e,t,n,r){let i=await ce(e,{executable:`adb`,args:[`-s`,t,`shell`,`pidof`,n],allowFailure:!0},r);if(!i)return;let a=i.stdout.trim().split(/\s+/)[0];return a&&/^\d+$/.test(a)?a:void 0}function pe(e,t,n){let r=new Set(n?[n]:[]),i=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),a=[RegExp(`\\bStart proc\\s+(\\d+):${i}(?:\\b|/)`,`i`),RegExp(`\\b(\\d+):${i}(?:\\b|/)`,`i`),RegExp(`${i}.*?\\bpid\\s*[=:]?\\s*(\\d+)\\b`,`i`),RegExp(`\\bpid\\s*[=:]?\\s*(\\d+)\\b.*${i}`,`i`)];for(let n of e.split(`
4
- `))if(n.includes(t))for(let e of a){let t=e.exec(n)?.[1];t&&/^\d+$/.test(t)&&r.add(t)}return Object.freeze([...r])}const me=/^(?:\/sdcard|\/data\/local\/tmp)\/agent-device-recording-\d{1,20}\.mp4$/,he=/^(?:\/sdcard|\/data\/local\/tmp)\/agent-device-recording-active\.json$/;function ge(e){return ye(e)&&be(e)&&xe(e)}function _e(e){if(!w(e))return!1;let t=e;return Se(t)&&Ce(t)&&we(t)&&Te(t)&&(t.completion===void 0||je(t))}function ve(e,t){return Me(e,t)&&Ne(e,t.outputPath,t.clientOutputPath)}function ye(e){return e.backend===`adb-screenrecord`&&typeof e.manifestPath==`string`&&he.test(e.manifestPath)&&typeof e.outputPath==`string`}function be(e){return(e.clientOutputPath===void 0||typeof e.clientOutputPath==`string`)&&T(e.scope)&&typeof e.showTouches==`boolean`&&typeof e.recordOnlySession==`boolean`}function xe(e){return E(e.transportMode)&&Pe(e.exportQuality)&&D(e.activeSessionApp)}function Se(e){return e.version===1&&e.resourceKind===`screen-recording`&&typeof e.fenceToken==`string`&&Number.isInteger(e.fenceGeneration)&&typeof e.sessionId==`string`&&typeof e.deviceId==`string`&&Number.isFinite(e.startedAt)}function Ce(e){return typeof e.outputPath==`string`&&(e.clientOutputPath===void 0||typeof e.clientOutputPath==`string`)&&T(e.scope)&&typeof e.showTouches==`boolean`&&typeof e.recordOnlySession==`boolean`}function we(e){return D(e.activeSessionApp)&&Pe(e.exportQuality)&&E(e.transportMode)&&(e.pendingRemotePath===void 0||Fe(e.pendingRemotePath))}function Te(e){return Array.isArray(e.chunks)&&e.chunks.every(Ee)&&(e.chunks.length>0||e.pendingRemotePath!==void 0)&&(e.completion===void 0||De(e.completion))}function Ee(e,t){if(!w(e))return!1;let n=e;return n.index===t+1&&Fe(n.remotePath)&&O(n.remotePid)&&O(n.remoteStartTime)}function De(e){if(!w(e))return!1;let t=e;return Oe(t)&&ke(t)&&(t.chunks===void 0||t.chunks.every(Ae))}function Oe(e){return typeof e.backend==`string`&&typeof e.outPath==`string`&&(e.clientOutPath===void 0||typeof e.clientOutPath==`string`)&&Number.isFinite(e.startedAt)&&Number.isFinite(e.completedAt)}function ke(e){return T(e.scope)&&typeof e.showTouches==`boolean`&&typeof e.recordOnlySession==`boolean`&&D(e.activeSessionApp)}function Ae(e,t){return e.index===t+1&&typeof e.path==`string`&&(e.clientOutPath===void 0||typeof e.clientOutPath==`string`)}function je(e){let t=e.completion;return t!==void 0&&Me(t,e)&&t.startedAt===e.startedAt&&Ne(t,e.outputPath,e.clientOutputPath,e.chunks.length)}function Me(e,t){return e.backend===`adb screenrecord`&&e.outPath===t.outputPath&&e.clientOutPath===t.clientOutputPath&&e.scope===t.scope&&e.showTouches===t.showTouches&&e.recordOnlySession===t.recordOnlySession&&Ie(e.activeSessionApp,t.activeSessionApp)}function Ne(e,t,n,r=e.chunks===void 0?1:e.chunks.length){return r===1?e.chunks===void 0:e.chunks?.length===r&&e.chunks.every((e,r)=>e.path===k(t,r+1)&&e.clientOutPath===(n===void 0?void 0:k(n,r+1)))}function w(e){return typeof e==`object`&&!!e}function T(e){return e===`app`||e===`device`||e===`system`}function E(e){return e===`local`||e===`transport-composed`}function Pe(e){return e===void 0||e===`medium`||e===`high`}function D(e){return e===void 0||w(e)&&typeof e.bundleId==`string`&&(e.name===void 0||typeof e.name==`string`)}function Fe(e){return typeof e==`string`&&me.test(e)}function O(e){return typeof e==`string`&&/^\d+$/.test(e)}function Ie(e,t){return JSON.stringify(e)===JSON.stringify(t)}function k(e,t){if(t===1)return e;let n=e.lastIndexOf(`.`),r=n>e.lastIndexOf(`/`)?e.slice(0,n):e,i=n>e.lastIndexOf(`/`)?e.slice(n):`.mp4`;return`${r}.part-${String(t).padStart(3,`0`)}${i}`}const A=Object.freeze({resourceKind:s,version:1,encode:e=>({...e}),decode:e=>ge(e)?{status:`decoded`,descriptor:Object.freeze({backend:`adb-screenrecord`,manifestPath:e.manifestPath,outputPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutputPath:e.clientOutputPath},scope:e.scope,showTouches:e.showTouches,recordOnlySession:e.recordOnlySession,transportMode:e.transportMode,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},...e.exportQuality===void 0?{}:{exportQuality:e.exportQuality}})}:{status:`invalid`,message:`Invalid Android screen-recording descriptor`}});function j(e,t,n,r,i,a=`local`){return Object.freeze({version:1,resourceKind:`screen-recording`,fenceToken:t.fence.token,fenceGeneration:t.fence.generation,sessionId:t.sessionId,deviceId:e.id,startedAt:n,outputPath:t.outputPath,...t.clientOutputPath===void 0?{}:{clientOutputPath:t.clientOutputPath},scope:t.scope,showTouches:t.showTouches,recordOnlySession:t.recordOnlySession,...t.activeSessionApp===void 0?{}:{activeSessionApp:t.activeSessionApp},...t.exportQuality===void 0?{}:{exportQuality:t.exportQuality},chunks:r,...i===void 0?{}:{pendingRemotePath:i},transportMode:a})}function Le(e,t){return Object.freeze({...e,completion:t})}function M(e){try{let t=e&&JSON.parse(e);return _e(t)?t:void 0}catch{return}}function Re(e,t,n){return e.deviceId===t.id&&e.deviceId===n.device.id&&e.fenceToken===n.fence.token&&e.fenceGeneration===n.fence.generation&&e.sessionId===n.sessionId}function ze(e,t){return e.outputPath===t.outputPath&&e.clientOutputPath===t.clientOutputPath&&e.scope===t.scope&&e.showTouches===t.showTouches&&e.recordOnlySession===t.recordOnlySession&&JSON.stringify(e.activeSessionApp)===JSON.stringify(t.activeSessionApp)&&e.exportQuality===t.exportQuality&&e.transportMode===t.transportMode&&(e.completion===void 0||ve(e.completion,t))}const Be=1e4,Ve=1e3;var N=class extends Error{constructor(e){super(`Android screenrecord launch rollback could not be confirmed`,{cause:e})}};function P(e,t=Date.now()){return[...new Set(e?[e,`/sdcard`,`/data/local/tmp`]:[`/sdcard`,`/data/local/tmp`])].map(e=>`${e}/agent-device-recording-${t}.mp4`)}async function He(e,t,n,r){let i;try{if(i=(await e.start({remotePath:t,quality:n.exportQuality??`medium`},r)).process,!/^\d+$/.test(i.pid)||!/^\d+$/.test(i.startTime)||i.remotePath!==t)throw Error(`Android screenrecord returned an invalid process identity`);if(!await Ke(e,t,i,r))throw Error(`Android screenrecord did not begin producing frames`);return{index:1,remotePath:t,remotePid:i.pid,remoteStartTime:i.startTime}}catch(t){throw i&&Ue(i)&&!await qe(e,i)?new N(t):r?.aborted?r.reason:t}}function Ue(e){return/^\d+$/.test(e.pid)&&/^\d+$/.test(e.startTime)&&e.remotePath.length>0}async function F(e,t){let n=!1,r;for(let i of[...t].reverse())try{n=await R(e,i)||n}catch(e){r??=e}if(r)throw r;return n}async function We(e,t){for(let n of t){let t;for(let r=0;r<3;r+=1){let i=await e.size(n.remotePath);if(typeof i==`number`&&i>0&&i===t)break;if(t=typeof i==`number`&&i>0?i:void 0,r===2)throw Error(`Android recording artifact is not stable: ${n.remotePath}`);await new Promise(e=>setTimeout(e,250))}}}async function Ge(e,t,n,r){let i=[];for(let[a,o]of t.entries()){let t=a===0?n:B(n,a+1);await Je(e,o.remotePath,t);let s=a===0||r===void 0?r:B(r,a+1);i.push({index:a+1,path:t,...s===void 0?{}:{clientOutPath:s}})}return Object.freeze(i)}async function I(e,t){let n;for(let r of t)try{if(!await e.remove(r.remotePath))throw Error(`failed to remove Android recording artifact: ${r.remotePath}`)}catch(e){n??=e}if(n)throw n}async function L(e,t){try{await F(e,t)}finally{await I(e,t)}}async function Ke(e,t,n,r){for(let i=0;i<3;i+=1){if(r?.throwIfAborted(),await e.exists(t,r)===!0)return!0;if(await e.inspect(n,r)!==`owned-alive`)return!1;i<2&&await new Promise(e=>setTimeout(e,250))}return!0}async function qe(e,t){try{let n=await e.stop(t,{force:!0});return(n===`stopped`||n===`already-missing`)&&await e.remove(t.remotePath)}catch{return!1}}async function R(e,t){if(!t)return!1;let n={pid:t.remotePid,remotePath:t.remotePath,startTime:t.remoteStartTime},r=await e.stop(n);if(r===`already-missing`)return!0;if(r===`ownership-lost`)throw Error(`Android screenrecord ownership could not be confirmed for pid ${t.remotePid}`);if(await Ye(e,n))return!1;let i=await e.stop(n,{force:!0});if(i===`stopped`||i===`already-missing`)return!1;throw Error(`failed to stop Android screenrecord pid ${t.remotePid}`)}async function Je(e,t,n){for(let r=0;r<3;r+=1){let i=await e.pullPlayable({remotePath:t,outputPath:n});if(i.exitCode===0&&i.playable)return;r+1<3&&await z(1e3)}throw Error(`failed to retrieve playable Android recording`)}async function Ye(e,t){for(let n=0;n<=Be;n+=Ve){let r=await e.inspect(t);if(r===`missing`)return!0;if(r===`ownership-lost`)throw Error(`Android screenrecord ownership could not be confirmed for pid ${t.pid}`);n<Be&&await z(Ve)}return!1}function z(e){return new Promise(t=>setTimeout(t,e))}function B(e,t){let n=x.parse(e);return x.join(n.dir,`${n.name}.part-${String(t).padStart(3,`0`)}${n.ext||`.mp4`}`)}async function Xe(e){let{transport:t,device:n,input:r,startedAt:i,signal:a,prepareOutput:o}=e;await $e(t,n),await o();let s;for(let e of P(void 0)){let o=t.manifestPathFor(e);await H(t,o,j(n,r,i,[],e,t.mode),a);let c;try{c=await He(t,e,r,a)}catch(e){if(a.aborted)throw await Ze(t,o,e),a.reason;await ot(t,o,e),s=e;continue}try{await H(t,o,j(n,r,i,[c],void 0,t.mode),a)}catch(e){throw await Qe(t,o,c),e}return{chunk:c,manifestPath:o}}throw s??Error(`Android screenrecord did not begin producing frames`)}async function Ze(e,t,n){n instanceof N||await U(e,t).catch(()=>{})}async function Qe(e,t,n){try{await L(e,[n])}catch{return}await U(e,t).catch(()=>{})}async function $e(e,t){let n=(await et(e)).flatMap(n=>tt(n,t,e.mode));for(let t of n)await at(e,t.evidence,t.manifestPath)}async function et(e){return await Promise.all(P(void 0).map(async t=>{let n=e.manifestPathFor(t);return{manifestPath:n,read:await e.readManifest(n)}}))}function tt(e,t,n){if(e.read.status===`missing`)return[];if(e.read.status!==`read`)throw rt();let r=M(e.read.contents);if(!nt(r,t,n))throw it();return[{manifestPath:e.manifestPath,evidence:r}]}function nt(e,t,n){return e!==void 0&&e.completion!==void 0&&e.pendingRemotePath===void 0&&e.deviceId===t.id&&e.transportMode===n}function rt(){return Error(`Android screenrecord native recovery evidence is unavailable`)}function it(){return Error(`Android screenrecord native recovery evidence already exists`)}async function at(e,t,n){for(let n of t.chunks)if(await e.inspect({pid:n.remotePid,remotePath:n.remotePath,startTime:n.remoteStartTime})!==`missing`)throw Error(`Android screenrecord completed evidence cannot be safely retired`);if(await I(e,t.chunks),await U(e,n),(await e.readManifest(n)).status!==`missing`)throw Error(`Android screenrecord completed evidence removal could not be confirmed`)}async function V(e){let{transport:t,device:n,input:r,startedAt:i,chunks:a,manifestPath:o,preferredDir:s}=e,c;for(let e of P(s)){await H(t,o,j(n,r,i,a,e,t.mode));try{return await He(t,e,r)}catch(e){if(e instanceof N)throw e;try{await H(t,o,j(n,r,i,a,void 0,t.mode))}catch{throw new N(e)}c=e}}throw c??Error(`failed to start next Android recording chunk`)}async function ot(e,t,n){if(n instanceof N)throw n;try{await U(e,t)}catch{throw new N(n)}}async function H(e,t,n,r){await e.writeManifest({manifestPath:t,contents:JSON.stringify(n)},r)}async function U(e,t){if(!await e.removeManifest(t))throw Error(`failed to remove Android recording manifest: ${t}`)}function st(e,t){return Object.freeze({backend:`adb screenrecord`,outPath:e.outputPath,...e.clientOutputPath?{clientOutPath:e.clientOutputPath}:{},startedAt:t,scope:e.scope,showTouches:e.showTouches,recordOnlySession:e.recordOnlySession,...e.activeSessionApp?{activeSessionApp:e.activeSessionApp}:{},...e.exportQuality?{exportQuality:e.exportQuality}:{},gestureEvents:[]})}async function ct(e,t,n,r,i=!1){let a=n.length>1,o=await e.screenRecording.finalize.complete({outputPath:t.outPath,showTouches:a?!1:t.showTouches,gestureEvents:t.gestureEvents,exportQuality:t.exportQuality??`medium`,targetLabel:r}),s=[...i?[`Android adb screenrecord stopped before record stop, likely after reaching the 180s platform limit. The MP4 may be truncated; final interactions after the limit are not in the video.`]:[],...a?[`Android adb screenrecord is capped at 180s, so this recording was split into multiple MP4 chunks.`]:[]];return{status:`completed`,result:{backend:t.backend,outPath:t.outPath,...t.clientOutPath?{clientOutPath:t.clientOutPath}:{},startedAt:t.startedAt,completedAt:Date.now(),scope:t.scope,showTouches:t.showTouches,recordOnlySession:t.recordOnlySession,...t.activeSessionApp?{activeSessionApp:t.activeSessionApp}:{},...a?{chunks:n}:{},...s.length?{warning:s.join(` `)}:{},...o,...a&&t.showTouches&&t.gestureEvents.length>0?{overlayWarning:`touch overlay burn-in is skipped for chunked Android recordings; returning raw chunks plus gesture telemetry`}:{}}}}function lt(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:String(e)}}async function ut(e){let t=await F(e.transport,e.evidence.chunks)||e.reachedLimit===!0;await We(e.transport,e.evidence.chunks);let n=await Ge(e.transport,e.evidence.chunks,e.recording.outPath,e.recording.clientOutPath),r=await ct(e.host,e.recording,n,`Android recording`,t);return await H(e.transport,e.manifestPath,Le(e.evidence,r.result)),await I(e.transport,e.evidence.chunks),r}async function dt(e,t,n){try{let r=t.pendingRemotePath,i=r===void 0?[]:(await e.findRunning(r)).map(e=>({index:t.chunks.length+1,remotePath:r,remotePid:e.pid,remoteStartTime:e.startTime}));if(await F(e,[...t.chunks,...i]),await I(e,t.chunks),r!==void 0&&!await e.remove(r))throw Error(`failed to remove Android recording artifact: ${r}`);return await U(e,n),{status:`cleaned`}}catch(e){return lt(e)}}async function ft(e){let{transport:t,device:n,envelope:r,descriptor:i}=e;if(i.transportMode!==t.mode)return{status:`transport-unavailable`};let a=await t.readManifest(i.manifestPath);if(a.status===`unavailable`)return{status:`transport-unavailable`};let o=a.status===`read`?M(a.contents):void 0;return o&&Re(o,n,r)&&ze(o,i)?{status:`matched`,evidence:o}:{status:`ownership-lost`}}async function pt(e){let t=await e.transport.readManifest(e.manifestPath);if(t.status!==`read`)return;let n=M(t.contents);return n&&mt(n,e)?n:void 0}function mt(e,t){return e.deviceId===t.deviceId&&e.sessionId===t.sessionId&&e.fenceToken===t.fence.token&&e.fenceGeneration===t.fence.generation}async function ht(e){let{host:t,transport:n,device:r,input:i}=e,a=A.decode(i.envelope.descriptor.body);if(a.status!==`decoded`)return W(`descriptor-invalid`);let o=await ft({transport:n,device:r,envelope:i.envelope,descriptor:a.descriptor});return o.status===`matched`?await _t({host:t,transport:n,device:r,input:i,descriptor:a.descriptor,evidence:o.evidence}):W(o.status===`transport-unavailable`?`transport-not-reattachable`:`ownership-fence-lost`)}async function gt(e){let t=A.decode(e.input.envelope.descriptor.body);if(t.status!==`decoded`)return{status:`cleanup-pending`,reason:`manual-recovery-required`};let n=await ft({transport:e.transport,device:e.device,envelope:e.input.envelope,descriptor:t.descriptor});return n.status===`matched`?await dt(e.transport,n.evidence,t.descriptor.manifestPath):n.status===`transport-unavailable`?{status:`cleanup-pending`,reason:`owner-unavailable`}:{status:`cleanup-pending`,reason:`ownership-fence-lost`}}async function _t(e){let{host:t,transport:n,device:r,input:i,descriptor:a,evidence:o}=e;if(o.completion!==void 0&&await vt(n,o))return{status:`completed`,result:o.completion};if(o.completion!==void 0)return W(`ownership-fence-lost`,`Android recording completed evidence still names a live or unverifiable recorder.`);if(o.pendingRemotePath!==void 0)return W(`transport-not-reattachable`,`Android recording launch was interrupted before its process identity was committed.`);let s=o.chunks.at(-1);if(!s)return{status:`missing`};let c=await n.inspect({pid:s.remotePid,remotePath:s.remotePath,startTime:s.remoteStartTime});if(c!==`owned-alive`&&await n.exists(s.remotePath)!==!0)return W(`transport-not-reattachable`,`Android recording process ended before its artifact could be recovered.`);let l=yt(i.envelope.sessionId,i.envelope.fence,a),u=!1;return{status:`active`,handle:g(st(l,o.startedAt),{finish:async e=>{let r=await ut({host:t,transport:n,evidence:o,manifestPath:a.manifestPath,recording:e,reachedLimit:c===`missing`});return u=!0,r},forceCleanup:async()=>u?{status:`cleaned`}:await gt({transport:n,device:r,input:i})})}}async function vt(e,t){try{for(let n of t.chunks)if(await e.inspect({pid:n.remotePid,remotePath:n.remotePath,startTime:n.remoteStartTime})!==`missing`)return!1;return!0}catch{return!1}}function yt(e,t,n){return{sessionId:e,outputPath:n.outputPath,...n.clientOutputPath===void 0?{}:{clientOutputPath:n.clientOutputPath},scope:n.scope,showTouches:n.showTouches,hideTouchesRequested:!1,recordOnlySession:n.recordOnlySession,...n.activeSessionApp===void 0?{}:{activeSessionApp:n.activeSessionApp},...n.exportQuality===void 0?{}:{exportQuality:n.exportQuality},fence:t}}function W(e,t){return{status:`unreattachable`,reason:e,...t===void 0?{}:{message:t}}}async function bt(e){let{host:t,device:n,owner:r,signal:i}=e,a=await t.screenRecording.android.resolve(n);return Object.freeze({screenRecordingStart:async e=>await xt({host:t,transport:a,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async e=>await ht({host:t,transport:a,device:n,input:e}),screenRecordingCleanup:async e=>await gt({transport:a,device:n,input:e})})}async function xt(e){let{host:t,transport:n,device:r,owner:i,input:a,signal:c}=e;c.throwIfAborted();let l=Date.now(),u=await Xe({transport:n,device:r,input:a,startedAt:l,signal:c,prepareOutput:async()=>await t.screenRecording.outputs.prepare(a.outputPath)}),d=u.manifestPath,f=[u.chunk],p,m,h,_=!1,v=()=>{p=setTimeout(()=>{m=b().catch(e=>{h=e})},17e4),p.unref?.()},b=async()=>{let e=f.at(-1);if(!e)throw Error(`Android recording has no active chunk`);let t=!1,i;try{i=await V({transport:n,device:r,input:a,startedAt:l,chunks:f,manifestPath:d,preferredDir:x.posix.dirname(e.remotePath)})}catch(o){await R(n,e),t=!0;try{i=await V({transport:n,device:r,input:a,startedAt:l,chunks:f,manifestPath:d,preferredDir:x.posix.dirname(e.remotePath)})}catch(e){throw e instanceof Error?e:o}}let o=[...f,{...i,index:f.length+1}];try{await H(n,d,j(r,a,l,o,void 0,n.mode))}catch(o){if(await L(n,[i]).catch(()=>{}),t)await H(n,d,j(r,a,l,f,i.remotePath,n.mode)).catch(()=>{});else try{await H(n,d,j(r,a,l,f,void 0,n.mode))}catch{await R(n,e).catch(()=>{}),await H(n,d,j(r,a,l,f,i.remotePath,n.mode)).catch(()=>{})}throw o}f=o,t||await R(n,e),v()};v();let S=g(st(a,l),{finish:async e=>{if(p&&clearTimeout(p),await m,h)throw h;let i=await ut({host:t,transport:n,evidence:j(r,a,l,f,void 0,n.mode),manifestPath:d,recording:e});return _=!0,i},forceCleanup:async()=>{if(p&&clearTimeout(p),_)return{status:`cleaned`};try{await m}catch(e){h=e}let e=await pt({transport:n,deviceId:r.id,sessionId:a.sessionId,fence:a.fence,manifestPath:d});return e?await dt(n,e,d):{status:`cleanup-pending`,reason:`ownership-fence-lost`}}});return Object.freeze({pendingHandle:new o(S),envelope:te({resourceKind:s,sessionId:a.sessionId,device:ee(r),owner:i,fence:a.fence,lifecycle:`open`,descriptor:y(A,{backend:`adb-screenrecord`,manifestPath:d,outputPath:a.outputPath,...a.clientOutputPath===void 0?{}:{clientOutputPath:a.clientOutputPath},scope:a.scope,showTouches:a.showTouches,recordOnlySession:a.recordOnlySession,...a.activeSessionApp===void 0?{}:{activeSessionApp:a.activeSessionApp},...a.exportQuality===void 0?{}:{exportQuality:a.exportQuality},transportMode:n.mode})})})}const G=12e4,St=1e3;async function K(e,t,n,r){return r.throwIfAborted(),t.kind===`emulator`&&(t.booted!==!0||!q(t))?await Ct(e,t,n,r):(t.booted!==!0&&await Dt(e,t.id,G,r),{...t,booted:!0})}async function Ct(e,t,n,r){await wt(e);let i=Ot(n),a=Tt(await e.deviceReadiness.androidEmulator.discover(i,r),t.name,n.serial),o=q(a)?a:void 0,s=o?void 0:e.deviceReadiness.androidEmulator.launch(a.name,n.headless);try{let t=o??await Et(e,a.name,i,n.serial,r);return await Dt(e,t.id,G,r),{...(await e.deviceReadiness.androidEmulator.discover(i,r)).find(e=>e.id===t.id)??t,name:a.name,booted:!0}}catch(t){throw s!==void 0&&r.aborted&&await e.deviceReadiness.androidEmulator.terminate(s),r.throwIfAborted(),t}}async function wt(t){if(await t.toolchains.prepare(`android`),!await t.commands.which(`adb`))throw new e(`TOOL_MISSING`,`adb not found in PATH`);if(!await t.commands.which(`emulator`))throw new e(`TOOL_MISSING`,`emulator not found in PATH`)}function Tt(t,n,r){let i=kt(t,n,r);if(i)return i;throw new e(`DEVICE_NOT_FOUND`,`No Android emulator AVD named ${n}`,{requestedAvdName:n,availableAvds:t.map(e=>e.name),hint:"Run `emulator -list-avds` and pass an existing AVD name to --device."})}async function Et(t,n,r,i,a){let o=t.clock.now()+G;for(;t.clock.now()<o;){let e=kt(await t.deviceReadiness.androidEmulator.discover(r,a),n,i);if(e&&q(e))return e;await t.clock.sleep(St,a)}throw new e(`COMMAND_FAILED`,`Android emulator did not appear in time`,{avdName:n,serial:i,timeoutMs:G})}async function Dt(t,n,r,i){let a=t.clock.now()+r;for(;t.clock.now()<a;){if((await t.commands.run({executable:`adb`,args:[`-s`,n,`shell`,`getprop`,`sys.boot_completed`],allowFailure:!0,timeoutMs:Math.min(1e4,Math.max(1e3,a-t.clock.now()))},i)).stdout.trim()===`1`)return;await t.clock.sleep(St,i)}throw new e(`COMMAND_FAILED`,`Android device failed to finish booting`,{serial:n,timeoutMs:r,reason:`ANDROID_BOOT_TIMEOUT`})}function Ot(e){return{platform:`android`,kind:`emulator`,...e.serial?{serial:e.serial}:{},...e.androidSerialAllowlist?{androidSerialAllowlist:[...e.androidSerialAllowlist]}:{}}}function kt(e,t,n){let r=At(t);return e.find(e=>e.platform===`android`&&e.kind===`emulator`&&At(e.name)===r&&(!n||!q(e)||e.id===n))}function q(e){return e.id.startsWith(`emulator-`)}function At(e){return e.toLowerCase().replace(/_/g,` `).replace(/\s+/g,` `).trim()}function jt(e){let{host:n,device:r,signal:i}=e,a=d({device:r,signal:i,resolveInteractor:n.localInteractors.resolve});return Object.freeze({resolveOpenTarget:async e=>await n.androidApplications.resolveOpenTarget(r,e),prepareApplicationOpen:async e=>{await K(n,r,{headless:!1},i)},openApplication:async e=>await Mt(n,a,e),applyRuntimeHints:async e=>await n.androidApplications.applyRuntimeHints(r,e),clearRuntimeHints:async e=>await n.androidApplications.clearRuntimeHints(r,e),closeApplication:async e=>{e.ensureReady&&await K(n,r,{headless:!1},i),await t({device:r,interactor:await a.resolveInteractor(e.execution,e.appBundleId),positionals:e.positionals})},finalizeApplicationClose:async e=>{await n.androidApplications.restoreTestIme(r,{stateDir:e.stateDir});let t=e.shutdownTarget&&r.kind===`emulator`?await n.deviceShutdown.android.shutdownTarget(r,i):void 0;return t===void 0?{}:{shutdown:t}},prepareAppleRunner:Nt,configureProviderPortReverse:Nt})}async function Mt(i,a,o){let s={};if(o.relaunch&&o.target){let e=Date.now();await t({device:a.device,interactor:await a.resolveInteractor(o.execution,o.appBundleId),positionals:[o.appBundleId??o.target]}),s.relaunchCloseDurationMs=J(e)}if(l(o.runtimeHints)){if(!o.applyRuntimeHints)throw new e(`COMMAND_FAILED`,`Runtime hint operation was not admitted for this open.`,{reason:`runtime-hints-operation-missing`});let t=Date.now();await o.applyRuntimeHints({appId:o.appBundleId,values:o.runtimeHints}),s.runtimeHintsDurationMs=J(t)}let c=Date.now();await n({device:a.device,interactor:await a.resolveInteractor(o.execution,o.appBundleId),positionals:o.positionals,appBundleId:o.appBundleId,execution:o.execution}),s.openDispatchDurationMs=J(c),o.enableTestIme&&await i.androidApplications.activateTestIme(a.device,{stateDir:o.stateDir});let u=r(o);if(u){let e=Date.now();await n({device:a.device,interactor:await a.resolveInteractor({...o.execution,clearAppState:void 0,launchConsole:void 0,launchArgs:void 0},o.appBundleId),positionals:[u],appBundleId:o.appBundleId,execution:{...o.execution,clearAppState:void 0,launchConsole:void 0,launchArgs:void 0}}),s.launchUrlDurationMs=J(e)}else s.launchUrlDurationMs=0;let d=await i.androidApplications.inferOpenedAppBundleId(a.device,o.target,o.appBundleId);return d&&await i.androidApplications.resetFramePerfStats(a.device,d),s.postOpenSettleDurationMs=0,{appBundleId:d,timing:s}}function J(e){return Math.max(0,Date.now()-e)}async function Nt(){throw new e(`UNSUPPORTED_OPERATION`,`This lifecycle operation is unavailable for Android.`)}async function Y(e,t,n,r,i){let a=r?void 0:await Rt(e,t,i);if(x.extname(n).toLowerCase()===`.aab`?await Lt(e,t,n,i):Z(await e.androidTools.installPackage(t,n,{replace:!0},i),`adb install failed`),r)return r;let o=[...await Rt(e,t,i)].filter(e=>!a?.has(e));return o.length===1?o[0]:void 0}async function Pt(e,t,n,r){let i=await X(e,t,[`uninstall`,n],r);if(i.exitCode===0)return;let a=`${i.stdout}\n${i.stderr}`.toLowerCase();a.includes(`unknown package`)||a.includes(`not installed`)||Z(i,`adb uninstall failed for ${n}`)}async function Ft(t,n,r,i){let a=r.payload,o=typeof a.action==`string`&&a.action.trim()?a.action.trim():`${r.appId}.TEST_PUSH`,s=[`shell`,`am`,`broadcast`,`-a`,o,`-p`,r.appId];typeof a.receiver==`string`&&a.receiver.trim()&&s.push(`-n`,a.receiver.trim());let c=a.extras??{};if(typeof c!=`object`||!c||Array.isArray(c))throw new e(`INVALID_ARGS`,`Android push payload extras must be an object`);let l=0;for(let[e,t]of Object.entries(c))e&&(zt(s,e,t),l+=1);return Z(await X(t,n,s,i),`adb push broadcast failed`),{action:o,extrasCount:l}}function It(e){let t=new Set([`com`,`android`,`google`,`app`,`apps`,`service`,`services`,`mobile`,`client`]),n=e.split(/[._-]+/).map(e=>e.trim().toLowerCase()).filter(Boolean),r=[...n].reverse().find(e=>!t.has(e))??n.at(-1)??e;return r.charAt(0).toUpperCase()+r.slice(1)}async function Lt(t,n,r,i){if(await t.androidTools.installBundle(n,r,`universal`,i))return;let a=await t.commands.which(`bundletool`),o=t.androidDeployment.bundletoolJar;if(!a&&!o)throw new e(`TOOL_MISSING`,`bundletool not found in PATH. Install bundletool or set AGENT_DEVICE_BUNDLETOOL_JAR.`);let s=a?`bundletool`:`java`,c=a?[]:[`-jar`,o],l=await t.temporaryFiles.create({prefix:`agent-device-aab-`,suffix:`.apks`}),u=l.path;try{Z(await t.commands.run({executable:s,args:[...c,`build-apks`,`--bundle`,r,`--output`,u,`--mode`,`universal`]},i),`bundletool build-apks failed`),Z(await t.commands.run({executable:s,args:[...c,`install-apks`,`--apks`,u,`--device-id`,n.id]},i),`bundletool install-apks failed`)}finally{await l[Symbol.asyncDispose]()}}async function Rt(e,t,n){let r=await X(e,t,[`shell`,`pm`,`list`,`packages`],n);return Z(r,`adb package inventory failed`),new Set(r.stdout.split(`
5
- `).map(e=>e.replace(`package:`,``).trim()).filter(Boolean))}function zt(t,n,r){if(typeof r==`string`)t.push(`--es`,n,r);else if(typeof r==`boolean`)t.push(`--ez`,n,String(r));else if(typeof r==`number`&&Number.isFinite(r))t.push(Number.isInteger(r)?`--ei`:`--ef`,n,String(r));else throw new e(`INVALID_ARGS`,`Unsupported Android broadcast extra type for "${n}". Use string, boolean, or number.`)}async function X(e,t,n,r,i=15e3){return await e.androidTools.runAdb(t,n,{timeoutMs:i,allowFailure:!0},r)}function Z(t,n){if(t.exitCode!==0)throw new e(`COMMAND_FAILED`,n,{stdout:t.stdout,stderr:t.stderr,exitCode:t.exitCode})}const Bt=Object.freeze({available:!0});function Vt(e){let t=Gt(e);return Object.freeze({deployApp:t,materializeAppSource:t,deployMaterializedApp:t,sendPushNotification:t})}function Ht(e){let{host:t,device:n,signal:r}=e;return Vt(n).deployApp.available?Object.freeze({deployApp:async e=>await Ut(t,n,e,r),materializeAppSource:async e=>await t.androidDeployment.prepareArtifact(e,{signal:r}),deployMaterializedApp:async e=>await Wt(t,n,e,r),sendPushNotification:async e=>await Ft(t,n,e,r)}):Object.freeze({})}async function Ut(e,t,n,r){if(n.replaceExisting)return await e.androidDeployment.withInvalidatedAppResolutionCache(t,async()=>{t.booted!==!0&&await K(e,t,{headless:!1},r);let i=await e.androidDeployment.resolveAppPackage(t,n.app);await Pt(e,t,i,r);let a=await e.androidDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{resolveIdentity:!1,signal:r});try{return await Y(e,t,a.installablePath,void 0,r),{packageName:i,launchTarget:i}}finally{await a.cleanup()}});t.booted!==!0&&await K(e,t,{headless:!1},r);let i=await e.androidDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{resolveIdentity:!0,signal:r});try{let n=await Y(e,t,i.installablePath,i.packageName,r);return n?{packageName:n,appName:It(n),launchTarget:n}:{}}finally{await i.cleanup()}}async function Wt(t,n,r,i){let a=await Y(t,n,r.artifact.installablePath,r.artifact.packageName,i);if(!a)throw new e(`COMMAND_FAILED`,`Installed Android app identity could not be resolved from the artifact or device state`);return{packageName:a,appName:It(a),launchTarget:a}}function Gt(e){return e.kind===`emulator`||e.kind===`device`?Bt:Object.freeze({available:!1,reason:`unsupported-device-kind`})}const Q=a(`android`),$=Object.freeze({available:!0}),Kt=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Headless boot is supported only for Android emulators.`}),qt=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Android appstate is supported only for Android emulators and devices.`}),Jt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple runner preparation is supported only for Apple targets.`}),Yt=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`open is supported only for Android emulators and devices.`}),Xt=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`close is supported only for Android emulators and devices.`}),Zt=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Runtime hints are supported only for Android emulators and devices.`}),Qt=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`}),$t=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`shutdown is supported only for Apple simulators and Android emulators.`});function en(e){let t=tn(e),n=nn(e),r=rn(e);return i({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:r,clearRuntimeHints:r,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:Jt,configureProviderPortReverse:Qt})}function tn(e){return e.kind===`emulator`||e.kind===`device`?$:Yt}function nn(e){return e.kind===`emulator`||e.kind===`device`?$:Xt}function rn(e){return e.kind===`emulator`||e.kind===`device`?$:Zt}function an(e){let t=ie(e),n=async e=>{let n=await t.inspectFacts(e),r=Vt(e);return Object.freeze({device:n.device,operations:{...n.operations,...r,appState:e.kind===`simulator`?qt:$,networkDump:$,screenRecordingStart:$,screenRecordingReattach:$,screenRecordingCleanup:$,ensureReady:$,bootTarget:$,bootTargetHeadless:e.kind===`emulator`?$:Kt,listApps:$,...en(e),shutdownTarget:e.kind===`emulator`?$:$t}})};return Object.freeze({owner:Q,ownsDevice:e=>e.platform===`android`,inspectFacts:n,bind:async r=>{let i=await t.bind(r),a=await n(r.device),o=await bt({host:e,device:r.device,owner:Q,signal:r.scope.signal});return Object.freeze({device:i.device,owner:Q,facts:a,operations:Object.freeze({...i.operations,...Ht({host:e,device:r.device,signal:r.scope.signal}),...a.operations.appState.available?{appState:async()=>await b(e.appState.android,r.device,r.scope.signal)}:{},networkDump:async t=>await se(e,r.device,t,r.scope.signal),...o,ensureReady:async t=>await K(e,r.device,{...t,headless:!1},r.scope.signal),bootTarget:async t=>await K(e,r.device,{...t,headless:!1},r.scope.signal),...a.operations.bootTargetHeadless.available?{bootTargetHeadless:async t=>await K(e,r.device,{...t,headless:!0},r.scope.signal)}:{},listApps:async t=>await e.appInventory.android.listApps(t.device,t.filter,r.scope.signal),...c(jt({host:e,device:r.device,signal:r.scope.signal}),a.operations),...a.operations.shutdownTarget.available?{shutdownTarget:async()=>await e.deviceShutdown.android.shutdownTarget(r.device,r.scope.signal)}:{}}),[Symbol.asyncDispose]:async()=>await i[Symbol.asyncDispose]()})},shutdown:async()=>await t.shutdown()})}export{an as createAndroidPlatformRuntime};
3
+ `);return c.trim()?{text:c,pids:o}:void 0}async function et(e,t,n,r){let i=await Xe(e,{executable:`adb`,args:[`-s`,t,`shell`,`pidof`,n],allowFailure:!0},r);if(!i)return;let a=i.stdout.trim().split(/\s+/)[0];return a&&/^\d+$/.test(a)?a:void 0}function tt(e,t,n){let r=new Set(n?[n]:[]),i=t.replaceAll(/[.*+?^${}()|[\]\\]/g,String.raw`\$&`),a=[RegExp(`\\bStart proc\\s+(\\d+):${i}(?:\\b|/)`,`i`),RegExp(`\\b(\\d+):${i}(?:\\b|/)`,`i`),RegExp(`${i}.*?\\bpid\\s*[=:]?\\s*(\\d+)\\b`,`i`),RegExp(`\\bpid\\s*[=:]?\\s*(\\d+)\\b.*${i}`,`i`)];for(let n of e.split(`
4
+ `))if(n.includes(t))for(let e of a){let t=e.exec(n)?.[1];t&&/^\d+$/.test(t)&&r.add(t)}return Object.freeze([...r])}const nt=/^(?:\/sdcard|\/data\/local\/tmp)\/agent-device-recording-\d{1,20}\.mp4$/,rt=/^(?:\/sdcard|\/data\/local\/tmp)\/agent-device-recording-active\.json$/;function it(e){return st(e)&&ct(e)&&lt(e)}function at(e){if(!S(e))return!1;let t=e;return ut(t)&&dt(t)&&ft(t)&&pt(t)&&(t.completion===void 0||yt(t))}function ot(e,t){return bt(e,t)&&xt(e,t.outputPath,t.clientOutputPath)}function st(e){return e.backend===`adb-screenrecord`&&typeof e.manifestPath==`string`&&rt.test(e.manifestPath)&&typeof e.outputPath==`string`}function ct(e){return(e.clientOutputPath===void 0||typeof e.clientOutputPath==`string`)&&C(e.scope)&&typeof e.showTouches==`boolean`&&typeof e.recordOnlySession==`boolean`}function lt(e){return w(e.transportMode)&&T(e.exportQuality)&&E(e.activeSessionApp)}function ut(e){return e.version===1&&e.resourceKind===`screen-recording`&&typeof e.fenceToken==`string`&&Number.isInteger(e.fenceGeneration)&&typeof e.sessionId==`string`&&typeof e.deviceId==`string`&&Number.isFinite(e.startedAt)}function dt(e){return typeof e.outputPath==`string`&&(e.clientOutputPath===void 0||typeof e.clientOutputPath==`string`)&&C(e.scope)&&typeof e.showTouches==`boolean`&&typeof e.recordOnlySession==`boolean`}function ft(e){return E(e.activeSessionApp)&&T(e.exportQuality)&&w(e.transportMode)&&(e.pendingRemotePath===void 0||St(e.pendingRemotePath))}function pt(e){return Array.isArray(e.chunks)&&e.chunks.every(mt)&&(e.chunks.length>0||e.pendingRemotePath!==void 0)&&(e.completion===void 0||ht(e.completion))}function mt(e,t){if(!S(e))return!1;let n=e;return n.index===t+1&&St(n.remotePath)&&Ct(n.remotePid)&&Ct(n.remoteStartTime)}function ht(e){if(!S(e))return!1;let t=e;return gt(t)&&_t(t)&&(t.chunks===void 0||t.chunks.every(vt))}function gt(e){return typeof e.backend==`string`&&typeof e.outPath==`string`&&(e.clientOutPath===void 0||typeof e.clientOutPath==`string`)&&Number.isFinite(e.startedAt)&&Number.isFinite(e.completedAt)}function _t(e){return C(e.scope)&&typeof e.showTouches==`boolean`&&typeof e.recordOnlySession==`boolean`&&E(e.activeSessionApp)}function vt(e,t){return e.index===t+1&&typeof e.path==`string`&&(e.clientOutPath===void 0||typeof e.clientOutPath==`string`)}function yt(e){let t=e.completion;return t!==void 0&&bt(t,e)&&t.startedAt===e.startedAt&&xt(t,e.outputPath,e.clientOutputPath,e.chunks.length)}function bt(e,t){return e.backend===`adb screenrecord`&&e.outPath===t.outputPath&&e.clientOutPath===t.clientOutputPath&&e.scope===t.scope&&e.showTouches===t.showTouches&&e.recordOnlySession===t.recordOnlySession&&wt(e.activeSessionApp,t.activeSessionApp)}function xt(e,t,n,r=e.chunks===void 0?1:e.chunks.length){return r===1?e.chunks===void 0:e.chunks?.length===r&&e.chunks.every((e,r)=>e.path===Tt(t,r+1)&&e.clientOutPath===(n===void 0?void 0:Tt(n,r+1)))}function S(e){return typeof e==`object`&&!!e}function C(e){return e===`app`||e===`device`||e===`system`}function w(e){return e===`local`||e===`transport-composed`}function T(e){return e===void 0||e===`medium`||e===`high`}function E(e){return e===void 0||S(e)&&typeof e.bundleId==`string`&&(e.name===void 0||typeof e.name==`string`)}function St(e){return typeof e==`string`&&nt.test(e)}function Ct(e){return typeof e==`string`&&/^\d+$/.test(e)}function wt(e,t){return JSON.stringify(e)===JSON.stringify(t)}function Tt(e,t){if(t===1)return e;let n=e.lastIndexOf(`.`),r=n>e.lastIndexOf(`/`)?e.slice(0,n):e,i=n>e.lastIndexOf(`/`)?e.slice(n):`.mp4`;return`${r}.part-${String(t).padStart(3,`0`)}${i}`}const D=Object.freeze({resourceKind:Ce,version:1,encode:e=>({...e}),decode:e=>it(e)?{status:`decoded`,descriptor:Object.freeze({backend:`adb-screenrecord`,manifestPath:e.manifestPath,outputPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutputPath:e.clientOutputPath},scope:e.scope,showTouches:e.showTouches,recordOnlySession:e.recordOnlySession,transportMode:e.transportMode,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},...e.exportQuality===void 0?{}:{exportQuality:e.exportQuality}})}:{status:`invalid`,message:`Invalid Android screen-recording descriptor`}});function O(e,t,n,r,i,a=`local`){return Object.freeze({version:1,resourceKind:`screen-recording`,fenceToken:t.fence.token,fenceGeneration:t.fence.generation,sessionId:t.sessionId,deviceId:e.id,startedAt:n,outputPath:t.outputPath,...t.clientOutputPath===void 0?{}:{clientOutputPath:t.clientOutputPath},scope:t.scope,showTouches:t.showTouches,recordOnlySession:t.recordOnlySession,...t.activeSessionApp===void 0?{}:{activeSessionApp:t.activeSessionApp},...t.exportQuality===void 0?{}:{exportQuality:t.exportQuality},chunks:r,...i===void 0?{}:{pendingRemotePath:i},transportMode:a})}function Et(e,t){return Object.freeze({...e,completion:t})}function k(e){try{let t=e&&JSON.parse(e);return at(t)?t:void 0}catch{return}}function Dt(e,t,n){return e.deviceId===t.id&&e.deviceId===n.device.id&&e.fenceToken===n.fence.token&&e.fenceGeneration===n.fence.generation&&e.sessionId===n.sessionId}function Ot(e,t){return e.outputPath===t.outputPath&&e.clientOutputPath===t.clientOutputPath&&e.scope===t.scope&&e.showTouches===t.showTouches&&e.recordOnlySession===t.recordOnlySession&&JSON.stringify(e.activeSessionApp)===JSON.stringify(t.activeSessionApp)&&e.exportQuality===t.exportQuality&&e.transportMode===t.transportMode&&(e.completion===void 0||ot(e.completion,t))}const A=1e4,j=1e3;var M=class extends Error{constructor(e){super(`Android screenrecord launch rollback could not be confirmed`,{cause:e})}};function N(e,t=Date.now()){return[...new Set(e?[e,`/sdcard`,`/data/local/tmp`]:[`/sdcard`,`/data/local/tmp`])].map(e=>`${e}/agent-device-recording-${t}.mp4`)}async function kt(e,t,n,r){let i;try{if(i=(await e.start({remotePath:t,quality:n.exportQuality??`medium`},r)).process,!/^\d+$/.test(i.pid)||!/^\d+$/.test(i.startTime)||i.remotePath!==t)throw Error(`Android screenrecord returned an invalid process identity`);if(!await Pt(e,t,i,r))throw Error(`Android screenrecord did not begin producing frames`);return{index:1,remotePath:t,remotePid:i.pid,remoteStartTime:i.startTime}}catch(t){throw i&&At(i)&&!await Ft(e,i)?new M(t):r?.aborted?r.reason:t}}function At(e){return/^\d+$/.test(e.pid)&&/^\d+$/.test(e.startTime)&&e.remotePath.length>0}async function P(e,t){let n=!1,r;for(let i of[...t].reverse())try{n=await I(e,i)||n}catch(e){r??=e}if(r)throw r;return n}async function jt(e,t){for(let n of t){let t;for(let r=0;r<3;r+=1){let i=await e.size(n.remotePath);if(typeof i==`number`&&i>0&&i===t)break;if(t=typeof i==`number`&&i>0?i:void 0,r===2)throw Error(`Android recording artifact is not stable: ${n.remotePath}`);await new Promise(e=>setTimeout(e,250))}}}async function Mt(e,t,n,r){let i=[];for(let[a,o]of t.entries()){let t=a===0?n:zt(n,a+1);await It(e,o.remotePath,t);let s=a===0||r===void 0?r:zt(r,a+1);i.push({index:a+1,path:t,...s===void 0?{}:{clientOutPath:s}})}return Object.freeze(i)}async function F(e,t){let n;for(let r of t)try{if(!await e.remove(r.remotePath))throw Error(`failed to remove Android recording artifact: ${r.remotePath}`)}catch(e){n??=e}if(n)throw n}async function Nt(e,t){try{await P(e,t)}finally{await F(e,t)}}async function Pt(e,t,n,r){for(let i=0;i<3;i+=1){if(r?.throwIfAborted(),await e.exists(t,r)===!0)return!0;if(await e.inspect(n,r)!==`owned-alive`)return!1;i<2&&await new Promise(e=>setTimeout(e,250))}return!0}async function Ft(e,t){try{let n=await e.stop(t,{force:!0});return(n===`stopped`||n===`already-missing`)&&await e.remove(t.remotePath)}catch{return!1}}async function I(e,t){if(!t)return!1;let n={pid:t.remotePid,remotePath:t.remotePath,startTime:t.remoteStartTime},r=await e.stop(n);if(r===`already-missing`)return!0;if(r===`ownership-lost`)throw Error(`Android screenrecord ownership could not be confirmed for pid ${t.remotePid}`);if(await Lt(e,n))return!1;let i=await e.stop(n,{force:!0});if(i===`stopped`||i===`already-missing`)return!1;throw Error(`failed to stop Android screenrecord pid ${t.remotePid}`)}async function It(e,t,n){for(let r=0;r<3;r+=1){let i=await e.pullPlayable({remotePath:t,outputPath:n});if(i.exitCode===0&&i.playable)return;r+1<3&&await Rt(1e3)}throw Error(`failed to retrieve playable Android recording`)}async function Lt(e,t){for(let n=0;n<=A;n+=j){let r=await e.inspect(t);if(r===`missing`)return!0;if(r===`ownership-lost`)throw Error(`Android screenrecord ownership could not be confirmed for pid ${t.pid}`);n<A&&await Rt(j)}return!1}function Rt(e){return new Promise(t=>setTimeout(t,e))}function zt(e,t){let n=b.parse(e);return b.join(n.dir,`${n.name}.part-${String(t).padStart(3,`0`)}${n.ext||`.mp4`}`)}async function Bt(e){let{transport:t,device:n,input:r,startedAt:i,signal:a,prepareOutput:o}=e;await Ut(t,n),await o();let s;for(let e of N(void 0)){let o=t.manifestPathFor(e);await L(t,o,O(n,r,i,[],e,t.mode),a);let c;try{c=await kt(t,e,r,a)}catch(e){if(a.aborted)throw await Vt(t,o,e),a.reason;await Zt(t,o,e),s=e;continue}try{await L(t,o,O(n,r,i,[c],void 0,t.mode),a)}catch(e){throw await Ht(t,o,c),e}return{chunk:c,manifestPath:o}}throw s??Error(`Android screenrecord did not begin producing frames`)}async function Vt(e,t,n){n instanceof M||await R(e,t).catch(()=>{})}async function Ht(e,t,n){try{await Nt(e,[n])}catch{return}await R(e,t).catch(()=>{})}async function Ut(e,t){let n=(await Wt(e)).flatMap(n=>Gt(n,t,e.mode));for(let t of n)await Yt(e,t.evidence,t.manifestPath)}async function Wt(e){return await Promise.all(N(void 0).map(async t=>{let n=e.manifestPathFor(t);return{manifestPath:n,read:await e.readManifest(n)}}))}function Gt(e,t,n){if(e.read.status===`missing`)return[];if(e.read.status!==`read`)throw qt();let r=k(e.read.contents);if(!Kt(r,t,n))throw Jt();return[{manifestPath:e.manifestPath,evidence:r}]}function Kt(e,t,n){return e!==void 0&&e.completion!==void 0&&e.pendingRemotePath===void 0&&e.deviceId===t.id&&e.transportMode===n}function qt(){return Error(`Android screenrecord native recovery evidence is unavailable`)}function Jt(){return Error(`Android screenrecord native recovery evidence already exists`)}async function Yt(e,t,n){for(let n of t.chunks)if(await e.inspect({pid:n.remotePid,remotePath:n.remotePath,startTime:n.remoteStartTime})!==`missing`)throw Error(`Android screenrecord completed evidence cannot be safely retired`);if(await F(e,t.chunks),await R(e,n),(await e.readManifest(n)).status!==`missing`)throw Error(`Android screenrecord completed evidence removal could not be confirmed`)}async function Xt(e){let{transport:t,device:n,input:r,startedAt:i,chunks:a,manifestPath:o,preferredDir:s}=e,c;for(let e of N(s)){await L(t,o,O(n,r,i,a,e,t.mode));try{return await kt(t,e,r)}catch(e){if(e instanceof M)throw e;try{await L(t,o,O(n,r,i,a,void 0,t.mode))}catch{throw new M(e)}c=e}}throw c??Error(`failed to start next Android recording chunk`)}async function Zt(e,t,n){if(n instanceof M)throw n;try{await R(e,t)}catch{throw new M(n)}}async function L(e,t,n,r){await e.writeManifest({manifestPath:t,contents:JSON.stringify(n)},r)}async function R(e,t){if(!await e.removeManifest(t))throw Error(`failed to remove Android recording manifest: ${t}`)}function Qt(e,t){return Object.freeze({backend:`adb screenrecord`,outPath:e.outputPath,...e.clientOutputPath?{clientOutPath:e.clientOutputPath}:{},startedAt:t,scope:e.scope,showTouches:e.showTouches,recordOnlySession:e.recordOnlySession,...e.activeSessionApp?{activeSessionApp:e.activeSessionApp}:{},...e.exportQuality?{exportQuality:e.exportQuality}:{},gestureEvents:[]})}async function $t(e,t,n,r,i=!1){let a=n.length>1,o=await e.screenRecording.finalize.complete({outputPath:t.outPath,showTouches:!a&&t.showTouches,gestureEvents:t.gestureEvents,exportQuality:t.exportQuality??`medium`,targetLabel:r}),s=[...i?[`Android adb screenrecord stopped before record stop, likely after reaching the 180s platform limit. The MP4 may be truncated; final interactions after the limit are not in the video.`]:[],...a?[`Android adb screenrecord is capped at 180s, so this recording was split into multiple MP4 chunks.`]:[]];return{status:`completed`,result:{backend:t.backend,outPath:t.outPath,...t.clientOutPath?{clientOutPath:t.clientOutPath}:{},startedAt:t.startedAt,completedAt:Date.now(),scope:t.scope,showTouches:t.showTouches,recordOnlySession:t.recordOnlySession,...t.activeSessionApp?{activeSessionApp:t.activeSessionApp}:{},...a?{chunks:n}:{},...s.length?{warning:s.join(` `)}:{},...o,...a&&t.showTouches&&t.gestureEvents.length>0?{overlayWarning:`touch overlay burn-in is skipped for chunked Android recordings; returning raw chunks plus gesture telemetry`}:{}}}}function en(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:String(e)}}async function tn(e){let t=await P(e.transport,e.evidence.chunks)||e.reachedLimit===!0;await jt(e.transport,e.evidence.chunks);let n=await Mt(e.transport,e.evidence.chunks,e.recording.outPath,e.recording.clientOutPath),r=await $t(e.host,e.recording,n,`Android recording`,t);return await L(e.transport,e.manifestPath,Et(e.evidence,r.result)),await F(e.transport,e.evidence.chunks),r}async function nn(e,t,n){try{let r=t.pendingRemotePath,i=r===void 0?[]:(await e.findRunning(r)).map(e=>({index:t.chunks.length+1,remotePath:r,remotePid:e.pid,remoteStartTime:e.startTime}));if(await P(e,[...t.chunks,...i]),await F(e,t.chunks),r!==void 0&&!await e.remove(r))throw Error(`failed to remove Android recording artifact: ${r}`);return await R(e,n),{status:`cleaned`}}catch(e){return en(e)}}async function rn(e){let{transport:t,device:n,envelope:r,descriptor:i}=e;if(i.transportMode!==t.mode)return{status:`transport-unavailable`};let a=await t.readManifest(i.manifestPath);if(a.status===`unavailable`)return{status:`transport-unavailable`};let o=a.status===`read`?k(a.contents):void 0;return o&&Dt(o,n,r)&&Ot(o,i)?{status:`matched`,evidence:o}:{status:`ownership-lost`}}async function an(e){let t=await e.transport.readManifest(e.manifestPath);if(t.status!==`read`)return;let n=k(t.contents);return n&&on(n,e)?n:void 0}function on(e,t){return e.deviceId===t.deviceId&&e.sessionId===t.sessionId&&e.fenceToken===t.fence.token&&e.fenceGeneration===t.fence.generation}async function sn(e){let{host:t,transport:n,device:r,input:i}=e,a=D.decode(i.envelope.descriptor.body);if(a.status!==`decoded`)return z(`descriptor-invalid`);let o=await rn({transport:n,device:r,envelope:i.envelope,descriptor:a.descriptor});return o.status===`matched`?await ln({host:t,transport:n,device:r,input:i,descriptor:a.descriptor,evidence:o.evidence}):z(o.status===`transport-unavailable`?`transport-not-reattachable`:`ownership-fence-lost`)}async function cn(e){let t=D.decode(e.input.envelope.descriptor.body);if(t.status!==`decoded`)return{status:`cleanup-pending`,reason:`manual-recovery-required`};let n=await rn({transport:e.transport,device:e.device,envelope:e.input.envelope,descriptor:t.descriptor});return n.status===`matched`?await nn(e.transport,n.evidence,t.descriptor.manifestPath):n.status===`transport-unavailable`?{status:`cleanup-pending`,reason:`owner-unavailable`}:{status:`cleanup-pending`,reason:`ownership-fence-lost`}}async function ln(e){let{host:t,transport:n,device:r,input:i,descriptor:a,evidence:o}=e;if(o.completion!==void 0&&await un(n,o))return{status:`completed`,result:o.completion};if(o.completion!==void 0)return z(`ownership-fence-lost`,`Android recording completed evidence still names a live or unverifiable recorder.`);if(o.pendingRemotePath!==void 0)return z(`transport-not-reattachable`,`Android recording launch was interrupted before its process identity was committed.`);let s=o.chunks.at(-1);if(!s)return{status:`missing`};let c=await n.inspect({pid:s.remotePid,remotePath:s.remotePath,startTime:s.remoteStartTime});if(c!==`owned-alive`&&await n.exists(s.remotePath)!==!0)return z(`transport-not-reattachable`,`Android recording process ended before its artifact could be recovered.`);let l=dn(i.envelope.sessionId,i.envelope.fence,a),u=!1;return{status:`active`,handle:ye(Qt(l,o.startedAt),{finish:async e=>{let r=await tn({host:t,transport:n,evidence:o,manifestPath:a.manifestPath,recording:e,reachedLimit:c===`missing`});return u=!0,r},forceCleanup:async()=>u?{status:`cleaned`}:await cn({transport:n,device:r,input:i})})}}async function un(e,t){try{for(let n of t.chunks)if(await e.inspect({pid:n.remotePid,remotePath:n.remotePath,startTime:n.remoteStartTime})!==`missing`)return!1;return!0}catch{return!1}}function dn(e,t,n){return{sessionId:e,outputPath:n.outputPath,...n.clientOutputPath===void 0?{}:{clientOutputPath:n.clientOutputPath},scope:n.scope,showTouches:n.showTouches,hideTouchesRequested:!1,recordOnlySession:n.recordOnlySession,...n.activeSessionApp===void 0?{}:{activeSessionApp:n.activeSessionApp},...n.exportQuality===void 0?{}:{exportQuality:n.exportQuality},fence:t}}function z(e,t){return{status:`unreattachable`,reason:e,...t===void 0?{}:{message:t}}}async function fn(e){let{host:t,device:n,owner:r,signal:i}=e,a=await t.screenRecording.android.resolve(n);return Object.freeze({screenRecordingStart:async e=>await pn({host:t,transport:a,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async e=>await sn({host:t,transport:a,device:n,input:e}),screenRecordingCleanup:async e=>await cn({transport:a,device:n,input:e})})}async function pn(e){let{host:n,transport:r,device:i,owner:a,input:o,signal:s}=e;s.throwIfAborted();let c=Date.now(),l=await Bt({transport:r,device:i,input:o,startedAt:c,signal:s,prepareOutput:async()=>await n.screenRecording.outputs.prepare(o.outputPath)}),u=l.manifestPath,d=[l.chunk],f,p,m,h=!1,g=()=>{f=setTimeout(()=>{p=ee().catch(e=>{m=e})},17e4),f.unref?.()},ee=async()=>{let e=d.at(-1);if(!e)throw Error(`Android recording has no active chunk`);let t=!1,n;try{n=await Xt({transport:r,device:i,input:o,startedAt:c,chunks:d,manifestPath:u,preferredDir:b.posix.dirname(e.remotePath)})}catch(a){await I(r,e),t=!0;try{n=await Xt({transport:r,device:i,input:o,startedAt:c,chunks:d,manifestPath:u,preferredDir:b.posix.dirname(e.remotePath)})}catch(e){throw e instanceof Error?e:a}}let a=[...d,{...n,index:d.length+1}];try{await L(r,u,O(i,o,c,a,void 0,r.mode))}catch(a){if(await Nt(r,[n]).catch(()=>{}),t)await L(r,u,O(i,o,c,d,n.remotePath,r.mode)).catch(()=>{});else try{await L(r,u,O(i,o,c,d,void 0,r.mode))}catch{await I(r,e).catch(()=>{}),await L(r,u,O(i,o,c,d,n.remotePath,r.mode)).catch(()=>{})}throw a}d=a,t||await I(r,e),g()};g();let _=ye(Qt(o,c),{finish:async e=>{if(f&&clearTimeout(f),await p,m)throw m;let t=await tn({host:n,transport:r,evidence:O(i,o,c,d,void 0,r.mode),manifestPath:u,recording:e});return h=!0,t},forceCleanup:async()=>{if(f&&clearTimeout(f),h)return{status:`cleaned`};try{await p}catch(e){m=e}let e=await an({transport:r,deviceId:i.id,sessionId:o.sessionId,fence:o.fence,manifestPath:u});return e?await nn(r,e,u):{status:`cleanup-pending`,reason:`ownership-fence-lost`}}});return Object.freeze({pendingHandle:new me(_),envelope:pe({resourceKind:Ce,sessionId:o.sessionId,device:t(i),owner:a,fence:o.fence,lifecycle:`open`,descriptor:fe(D,{backend:`adb-screenrecord`,manifestPath:u,outputPath:o.outputPath,...o.clientOutputPath===void 0?{}:{clientOutputPath:o.clientOutputPath},scope:o.scope,showTouches:o.showTouches,recordOnlySession:o.recordOnlySession,...o.activeSessionApp===void 0?{}:{activeSessionApp:o.activeSessionApp},...o.exportQuality===void 0?{}:{exportQuality:o.exportQuality},transportMode:r.mode})})})}const B=12e4,mn=1e3;async function V(e,t,n,r){return r.throwIfAborted(),await Pe(t)?{...t,booted:!0}:t.kind===`emulator`&&(t.booted!==!0||!H(t))?await hn(e,t,n,r):(t.booted!==!0&&await yn(e,t.id,B,r),{...t,booted:!0})}async function hn(e,t,n,r){await gn(e);let i=bn(n),a=_n(await e.deviceReadiness.androidEmulator.discover(i,r),t.name,n.serial),o=H(a)?a:void 0,s=o?void 0:e.deviceReadiness.androidEmulator.launch(a.name,n.headless);try{let t=o??await vn(e,a.name,i,n.serial,r);return await yn(e,t.id,B,r),{...(await e.deviceReadiness.androidEmulator.discover(i,r)).find(e=>e.id===t.id)??t,name:a.name,booted:!0}}catch(t){throw s!==void 0&&r.aborted&&await e.deviceReadiness.androidEmulator.terminate(s),r.throwIfAborted(),t}}async function gn(t){if(await t.toolchains.prepare(`android`),!await t.commands.which(`adb`))throw new e(`TOOL_MISSING`,`adb not found in PATH`);if(!await t.commands.which(`emulator`))throw new e(`TOOL_MISSING`,`emulator not found in PATH`)}function _n(t,n,r){let i=xn(t,n,r);if(i)return i;throw new e(`DEVICE_NOT_FOUND`,`No Android emulator AVD named ${n}`,{requestedAvdName:n,availableAvds:t.map(e=>e.name),hint:"Run `emulator -list-avds` and pass an existing AVD name to --device."})}async function vn(t,n,r,i,a){let o=t.clock.now()+B;for(;t.clock.now()<o;){let e=xn(await t.deviceReadiness.androidEmulator.discover(r,a),n,i);if(e&&H(e))return e;await t.clock.sleep(mn,a)}throw new e(`COMMAND_FAILED`,`Android emulator did not appear in time`,{avdName:n,serial:i,timeoutMs:B})}async function yn(t,n,r,i){let a=t.clock.now()+r;for(;t.clock.now()<a;){if((await t.commands.run({executable:`adb`,args:[`-s`,n,`shell`,`getprop`,`sys.boot_completed`],allowFailure:!0,timeoutMs:Math.min(1e4,Math.max(1e3,a-t.clock.now()))},i)).stdout.trim()===`1`)return;await t.clock.sleep(mn,i)}throw new e(`COMMAND_FAILED`,`Android device failed to finish booting`,{serial:n,timeoutMs:r,reason:`ANDROID_BOOT_TIMEOUT`})}function bn(e){return{platform:`android`,kind:`emulator`,...e.serial?{serial:e.serial}:{},...e.androidSerialAllowlist?{androidSerialAllowlist:[...e.androidSerialAllowlist]}:{}}}function xn(e,t,n){let r=Sn(t);return e.find(e=>e.platform===`android`&&e.kind===`emulator`&&Sn(e.name)===r&&(!n||!H(e)||e.id===n))}function H(e){return e.id.startsWith(`emulator-`)}function Sn(e){return e.toLowerCase().replaceAll(`_`,` `).replaceAll(/\s+/g,` `).trim()}function Cn(e){let{host:t,device:n,signal:r}=e,i=Le({device:n,signal:r,resolveInteractor:t.localInteractors.resolve});return Object.freeze({resolveOpenTarget:async e=>await t.androidApplications.resolveOpenTarget(n,e),prepareApplicationOpen:async e=>{await V(t,n,{headless:!1},r)},openApplication:async e=>await wn(t,i,e),applyRuntimeHints:async e=>await t.androidApplications.applyRuntimeHints(n,e),clearRuntimeHints:async e=>await t.androidApplications.clearRuntimeHints(n,e),closeApplication:async e=>{e.ensureReady&&await V(t,n,{headless:!1},r),await Fe({device:n,interactor:await i.resolveInteractor(e.execution,e.appBundleId),positionals:e.positionals})},finalizeApplicationClose:async e=>{await t.androidApplications.restoreTestIme(n,{stateDir:e.stateDir});let i=e.shutdownTarget&&n.kind===`emulator`?await t.deviceShutdown.android.shutdownTarget(n,r):void 0;return i===void 0?{}:{shutdown:i}},prepareAppleRunner:Tn,configureProviderPortReverse:Tn})}async function wn(t,n,r){let i={};if(r.relaunch&&r.target){let e=Date.now();await Fe({device:n.device,interactor:await n.resolveInteractor(r.execution,r.appBundleId),positionals:[r.appBundleId??r.target]}),i.relaunchCloseDurationMs=U(e)}if(a(r.runtimeHints)){if(!r.applyRuntimeHints)throw new e(`COMMAND_FAILED`,`Runtime hint operation was not admitted for this open.`,{reason:`runtime-hints-operation-missing`});let t=Date.now();await r.applyRuntimeHints({appId:r.appBundleId,values:r.runtimeHints}),i.runtimeHintsDurationMs=U(t)}let o=Date.now();await Re({device:n.device,interactor:await n.resolveInteractor(r.execution,r.appBundleId),positionals:r.positionals,appBundleId:r.appBundleId,execution:r.execution}),i.openDispatchDurationMs=U(o),r.enableTestIme&&await t.androidApplications.activateTestIme(n.device,{stateDir:r.stateDir});let s=Ie(r);if(s){let e=Date.now();await Re({device:n.device,interactor:await n.resolveInteractor({...r.execution,clearAppState:void 0,launchConsole:void 0,launchArgs:void 0},r.appBundleId),positionals:[s],appBundleId:r.appBundleId,execution:{...r.execution,clearAppState:void 0,launchConsole:void 0,launchArgs:void 0}}),i.launchUrlDurationMs=U(e)}else i.launchUrlDurationMs=0;let c=await t.androidApplications.inferOpenedAppBundleId(n.device,r.target,r.appBundleId);return c&&await t.androidApplications.resetFramePerfStats(n.device,c),i.postOpenSettleDurationMs=0,{appBundleId:c,timing:i}}function U(e){return Math.max(0,Date.now()-e)}async function Tn(){throw new e(`UNSUPPORTED_OPERATION`,`This lifecycle operation is unavailable for Android.`)}async function W(e,t,n,r,i){G(n);let a=r?void 0:await An(e,t,i);if(b.extname(n).toLowerCase()===`.aab`?await kn(e,t,n,i):q(await e.androidTools.installPackage(t,n,{replace:!0},i),`adb install failed`),r)return r;let o=[...await An(e,t,i)].filter(e=>!a?.has(e));return o.length===1?o[0]:void 0}function G(t){if(y()&&b.extname(t).toLowerCase()===`.aab`)throw new e(`UNSUPPORTED_OPERATION`,`Managed Android deployment does not support app bundles.`,{reason:`managed-bundle-install-unavailable`,hint:`Install an APK on this managed device.`})}async function En(e,t,n,r){let i=await K(e,t,[`uninstall`,n],r);if(i.exitCode===0)return;let a=`${i.stdout}\n${i.stderr}`.toLowerCase();a.includes(`unknown package`)||a.includes(`not installed`)||q(i,`adb uninstall failed for ${n}`)}async function Dn(t,n,r,i){let a=r.payload,o=typeof a.action==`string`&&a.action.trim()?a.action.trim():`${r.appId}.TEST_PUSH`,s=[`shell`,`am`,`broadcast`,`-a`,o,`-p`,r.appId];typeof a.receiver==`string`&&a.receiver.trim()&&s.push(`-n`,a.receiver.trim());let c=a.extras??{};if(typeof c!=`object`||!c||Array.isArray(c))throw new e(`INVALID_ARGS`,`Android push payload extras must be an object`);let l=0;for(let[e,t]of Object.entries(c))e&&(jn(s,e,t),l+=1);return q(await K(t,n,s,i),`adb push broadcast failed`),{action:o,extrasCount:l}}function On(e){let t=new Set([`com`,`android`,`google`,`app`,`apps`,`service`,`services`,`mobile`,`client`]),n=e.split(/[._-]+/).map(e=>e.trim().toLowerCase()).filter(Boolean),r=[...n].reverse().find(e=>!t.has(e))??n.at(-1)??e;return r.charAt(0).toUpperCase()+r.slice(1)}async function kn(t,n,r,i){if(await t.androidTools.installBundle(n,r,`universal`,i))return;let a=await t.commands.which(`bundletool`),o=t.androidDeployment.bundletoolJar;if(!a&&!o)throw new e(`TOOL_MISSING`,`bundletool not found in PATH. Install bundletool or set AGENT_DEVICE_BUNDLETOOL_JAR.`);let s=a?`bundletool`:`java`,c=a?[]:[`-jar`,o],l=await t.temporaryFiles.create({prefix:`agent-device-aab-`,suffix:`.apks`}),u=l.path;try{q(await t.commands.run({executable:s,args:[...c,`build-apks`,`--bundle`,r,`--output`,u,`--mode`,`universal`]},i),`bundletool build-apks failed`),q(await t.commands.run({executable:s,args:[...c,`install-apks`,`--apks`,u,`--device-id`,n.id]},i),`bundletool install-apks failed`)}finally{await l[Symbol.asyncDispose]()}}async function An(e,t,n){let r=await K(e,t,[`shell`,`pm`,`list`,`packages`],n);return q(r,`adb package inventory failed`),new Set(r.stdout.split(`
5
+ `).map(e=>e.replace(`package:`,``).trim()).filter(Boolean))}function jn(t,n,r){if(typeof r==`string`)t.push(`--es`,n,r);else if(typeof r==`boolean`)t.push(`--ez`,n,String(r));else if(typeof r==`number`&&Number.isFinite(r))t.push(Number.isInteger(r)?`--ei`:`--ef`,n,String(r));else throw new e(`INVALID_ARGS`,`Unsupported Android broadcast extra type for "${n}". Use string, boolean, or number.`)}async function K(e,t,n,r,i=15e3){return await e.androidTools.runAdb(t,n,{timeoutMs:i,allowFailure:!0},r)}function q(t,n){if(t.exitCode===0)return;let r={stdout:t.stdout,stderr:t.stderr,exitCode:t.exitCode};throw new e(`COMMAND_FAILED`,n,r)}const Mn=Object.freeze({available:!0});function Nn(e){let t=Ln(e);return Object.freeze({deployApp:t,materializeAppSource:t,deployMaterializedApp:t,sendPushNotification:t})}function Pn(e){let{host:t,device:n,signal:r}=e;return Nn(n).deployApp.available?Object.freeze({deployApp:async e=>await Fn(t,n,e,r),materializeAppSource:async e=>await t.androidDeployment.prepareArtifact(e,{signal:r}),deployMaterializedApp:async e=>await In(t,n,e,r),sendPushNotification:async e=>await Dn(t,n,e,r)}):Object.freeze({})}async function Fn(e,t,n,r){if(n.replaceExisting)return await e.androidDeployment.withInvalidatedAppResolutionCache(t,async()=>{let i;try{y()&&(i=await e.androidDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{resolveIdentity:!1,signal:r}),G(i.installablePath)),t.booted!==!0&&await V(e,t,{headless:!1},r);let a=await e.androidDeployment.resolveAppPackage(t,n.app);return await En(e,t,a,r),i??=await e.androidDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{resolveIdentity:!1,signal:r}),await W(e,t,i.installablePath,void 0,r),{packageName:a,launchTarget:a}}finally{await i?.cleanup()}});let i;try{y()&&(i=await e.androidDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{resolveIdentity:!0,signal:r}),G(i.installablePath)),t.booted!==!0&&await V(e,t,{headless:!1},r),i??=await e.androidDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{resolveIdentity:!0,signal:r});let a=await W(e,t,i.installablePath,i.packageName,r);return a?{packageName:a,appName:On(a),launchTarget:a}:{}}finally{await i?.cleanup()}}async function In(t,n,r,i){let a=await W(t,n,r.artifact.installablePath,r.artifact.packageName,i);if(!a)throw new e(`COMMAND_FAILED`,`Installed Android app identity could not be resolved from the artifact or device state`);return{packageName:a,appName:On(a),launchTarget:a}}function Ln(e){return e.kind===`emulator`||e.kind===`device`?Mn:Object.freeze({available:!1,reason:`unsupported-device-kind`})}const J=n(`android`),Y=Object.freeze({available:!0}),Rn=Object.freeze({available:!1,reason:`unsupported-device-kind`}),X=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`focus is supported on Android emulators and physical devices.`}),zn=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Bn=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Headless boot is supported only for Android emulators.`}),Vn=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Android appstate is supported only for Android emulators and devices.`}),Hn=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple runner preparation is supported only for Apple targets.`}),Un=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`open is supported only for Android emulators and devices.`}),Wn=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`close is supported only for Android emulators and devices.`}),Gn=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Runtime hints are supported only for Android emulators and devices.`}),Kn=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`}),qn=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`shutdown is supported only for Apple simulators and Android emulators.`}),Jn=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`screenshot is supported only for Android emulators and devices.`}),Z=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`snapshot is supported only for Android emulators and devices.`}),Yn=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Re-run without --actions, or target an iOS simulator.`}),Xn=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`viewport resizes web targets only (--platform web).`}),Zn=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`the stateless audio page probe is a web-session operation; Android targets use the host capture.`});function Qn(e){let t=$n(e),n=er(e),r=tr(e);return o({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:r,clearRuntimeHints:r,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:Hn,configureProviderPortReverse:Kn})}function $n(e){return e.kind===`emulator`||e.kind===`device`?Y:Un}function er(e){return e.kind===`emulator`||e.kind===`device`?Y:Wn}function tr(e){return e.kind===`emulator`||e.kind===`device`?Y:Gn}const nr=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Gestures are supported on Android emulators and physical devices.`}),rr=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:Ee}),ir=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:Te});function ar(e,t){return e.kind===`simulator`?nr:e.target===`tv`?t:Y}function Q(e){return e.kind===`simulator`?nr:Y}function $(e){return e.kind===`simulator`?X:Y}const or=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`This Android build ships no shell implementation for the clipboard service, so adb cannot read or write the clipboard on it.`}),sr=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`Could not determine whether this Android build supports a shell clipboard: the adb probe did not complete. Retry once the device is reachable.`});async function cr(e,t){let n=e.androidTools?.probeClipboardShellSupport;return n?await n.call(e.androidTools,t):`probe-failed`}const lr=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`tv-remote is supported only on Android TV targets.`});function ur(e){return e.kind!==`simulator`&&e.target===`tv`?Y:lr}function dr(e){let t=Ke(e),n=new Map,a=async t=>{if(t.kind===`simulator`)return or;let r=n.get(t.id)??await cr(e,t);return r!==`probe-failed`&&n.set(t.id,r),r===`supported`?Y:r===`unsupported`?or:sr},o=async e=>{let n=await t.inspectFacts(e),r=Nn(e),i=await a(e);return Object.freeze({device:n.device,operations:{...n.operations,...r,appState:e.kind===`simulator`?Vn:Y,networkDump:Y,screenRecordingStart:Y,screenRecordingReattach:Y,screenRecordingCleanup:Y,...d({capture:e.kind===`simulator`?Z:Y,customActions:Yn,withoutActiveApp:e.kind===`simulator`?Z:Y}),...u({capture:e.kind===`simulator`?Jn:Y}),...h({findText:Z,findSelector:Z}),...p({setViewport:Xn}),...f({focus:$(e)}),...m({plan:Q(e),directionalFling:Q(e),multiTouch:ar(e,rr),targetAuthoredDrag:ar(e,ir),viewport:Q(e)}),...c({scroll:Q(e)}),...l({type:$(e)}),...s({tap:$(e),tapRef:X,longPress:$(e),hover:zn,hoverRef:X,fill:$(e),fillRef:X,tapElementSelector:X}),...se({readTextAtPoint:e.kind===`simulator`?Rn:Y}),...ce({back:$(e)}),...ee({home:$(e)}),...ie({appSwitcher:$(e)}),...g({triggerAppEvent:$(e)}),...ne({setSetting:$(e)}),...ae({read:$(e),wait:$(e),accept:$(e),dismiss:$(e)}),...oe({orientation:$(e)}),...te({tvRemote:ur(e)}),...re({status:$(e),dismiss:$(e),enter:$(e)}),..._({read:i,write:i}),...ue({capture:ze(e),query:Zn}),...de({frames:$(e),memorySample:$(e),memorySnapshot:$(e),nativeCapture:$(e),profileReport:$(e)}),ensureReady:Y,bootTarget:Y,bootTargetHeadless:e.kind===`emulator`?Y:Bn,listApps:Y,...Qn(e),shutdownTarget:e.kind===`emulator`?Y:qn}})};return Object.freeze({owner:J,ownsDevice:e=>e.platform===`android`,inspectFacts:o,bind:async n=>{let a=await t.bind(n),s=await o(n.device),c=await fn({host:e,device:n.device,owner:J,signal:n.scope.signal});return Object.freeze({device:a.device,owner:J,facts:s,operations:Object.freeze({...a.operations,...Pn({host:e,device:n.device,signal:n.scope.signal}),...s.operations.appState.available?{appState:async()=>{n.scope.signal.throwIfAborted();let{runAndroidAdb:e}=await import(`./adb.js`).then(e=>e.t);return await we(async(t,r)=>await e(n.device,t,{...r,signal:n.scope.signal}),n.scope.signal)}}:{},networkDump:async t=>await Ye(e,n.device,t,n.scope.signal),...c,...r(s.operations.audioProbeStart,()=>ge({host:e.audioProbe.hostCapture,device:n.device,owner:J})),...r(s.operations.perfFrames,()=>Be({resolveHost:()=>e.perf.android,device:n.device,owner:J})),...fr(e,n,s),ensureReady:async t=>await V(e,n.device,{...t,headless:!1},n.scope.signal),bootTarget:async t=>await V(e,n.device,{...t,headless:!1},n.scope.signal),...s.operations.bootTargetHeadless.available?{bootTargetHeadless:async t=>await V(e,n.device,{...t,headless:!0},n.scope.signal)}:{},listApps:async e=>{n.scope.signal.throwIfAborted();let{listAndroidApps:t}=await import(`./app-lifecycle.js`).then(e=>e.t);return(await t(e.device,e.filter)).map(e=>({id:e.package,name:e.name}))},...i(Cn({host:e,device:n.device,signal:n.scope.signal}),s.operations),...s.operations.shutdownTarget.available?{shutdownTarget:async()=>await e.deviceShutdown.android.shutdownTarget(n.device,n.scope.signal)}:{}}),[Symbol.asyncDispose]:async()=>await a[Symbol.asyncDispose]()})},shutdown:async()=>await t.shutdown()})}function fr(e,t,n){let r={device:t.device,signal:t.scope.signal,resolveInteractor:e.localInteractors.resolve};return{...n.operations.captureSnapshot.available?le(r):{},...De({...r,facts:n.operations,pause:async n=>await e.clock.sleep(n,t.scope.signal)})}}export{dr as createAndroidPlatformRuntime};
@@ -1 +1 @@
1
- import{C as e}from"./sdk-contracts.js";function t(e){return Object.freeze({canShutdownTarget:n,shutdownTarget:async(t,n)=>await r(e.commands,t,n)})}function n(e){return e.platform===`android`&&e.kind===`emulator`}async function r(t,n,r){if(n.booted===!1)return i();r.throwIfAborted();try{let e=await t.run({executable:`adb`,args:[`-s`,n.id,`emu`,`kill`],allowFailure:!0,timeoutMs:15e3},r);r.throwIfAborted();let i=e.exitCode??-1;return{success:i===0,exitCode:i,stdout:e.stdout,stderr:e.stderr}}catch(t){r.throwIfAborted();let n=e(t);return{success:!1,exitCode:-1,stdout:``,stderr:n.message,error:n}}}function i(){return{success:!0,exitCode:0,stdout:``,stderr:``}}export{t as createAndroidShutdownRuntime};
1
+ import{O as e}from"./sdk-contracts.js";function t(e){return Object.freeze({canShutdownTarget:n,shutdownTarget:async(t,n)=>await r(e.commands,t,n)})}function n(e){return e.platform===`android`&&e.kind===`emulator`}async function r(t,n,r){if(n.booted===!1)return i();r.throwIfAborted();try{let e=await t.run({executable:`adb`,args:[`-s`,n.id,`emu`,`kill`],allowFailure:!0,timeoutMs:15e3},r);r.throwIfAborted();let i=e.exitCode??-1;return{success:i===0,exitCode:i,stdout:e.stdout,stderr:e.stderr}}catch(t){r.throwIfAborted();let n=e(t);return{success:!1,exitCode:-1,stdout:``,stderr:n.message,error:n}}}function i(){return{success:!0,exitCode:0,stdout:``,stderr:``}}export{t as createAndroidShutdownRuntime};
@@ -1,3 +1,4 @@
1
- import{_ as e,v as t}from"./sdk-contracts.js";import{H as n,K as r,U as i,at as a,bt as o,dt as s,et as c,ot as l,st as u,tt as d,ut as f,wt as p,z as ee}from"./sdk-batch-runner.js";import{C as te,c as m,l as h,s as g,x as _}from"./sdk-device.js";import{c as ne,f as re,g as ie,h as ae,i as oe,l as se,m as ce,n as le,p as ue,r as v,s as y,t as de,u as fe,v as b,x}from"./src3.js";import{n as S,t as pe}from"./simulator-state.js";import me from"node:path";const C=`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`;function w(e){return h(e)?`macos`:e.kind===`device`?`ios-device`:`ios-simulator`}const T=Object.freeze({resourceKind:d,version:1,encode:e=>({...e}),decode:e=>!ge(e.transport)||!_e(e.backend)||!E(e.outputPath)||!ye(e.pidPath)||!ve(e.transport,e.backend)?he():{status:`decoded`,descriptor:Object.freeze({transport:e.transport,backend:e.backend,outputPath:e.outputPath,...e.pidPath===void 0?{}:{pidPath:e.pidPath}})}});function he(){return{status:`invalid`,message:`Invalid Apple app-log descriptor`}}function ge(e){return e===`apple-log-stream`||e===`coredevice-console`}function _e(e){return e===`ios-simulator`||e===`ios-device`||e===`macos`}function ve(e,t){return e===`coredevice-console`?t===`ios-device`:t!==`ios-device`}function ye(e){return e===void 0||E(e)}function be(e){if(!e.device.appleOs)throw TypeError(`Apple app-log persistence requires an explicit appleOs identity`);return b({resourceKind:d,sessionId:e.sessionId,device:{id:e.device.id,family:`apple`,appleOs:e.device.appleOs,kind:e.device.kind,...e.device.target===void 0?{}:{target:e.device.target},...e.device.iosPhysicalDeviceBackend===void 0?{}:{iosPhysicalDeviceBackend:e.device.iosPhysicalDeviceBackend}},owner:e.owner,fence:e.fence,lifecycle:`open`,descriptor:x(T,e.descriptor)})}function E(e){return typeof e==`string`&&e.trim().length>0}const D={message:`iOS physical-device app console capture is not supported by the installed devicectl.`,hint:`This devicectl does not expose process launch --console. Markers can still be written to app.log, but app output is not being captured. Use an iOS simulator for agent-device app logs or inspect physical-device logs in Console.app/Xcode until this Xcode toolchain exposes scriptable console capture.`},xe={message:`Could not verify iOS physical-device app console capture support.`,hint:`Retry logs clear --restart. If the probe keeps failing, run logs doctor and inspect the request diagnostics for the devicectl help command.`};async function Se(e,t){try{let n=await e.appleTools.run({tool:`devicectl`,args:[`device`,`process`,`launch`,`--help`],allowFailure:!0,timeoutMs:5e3},t),r=n.stderr.trim()||void 0;if(n.exitCode!==0)return{supported:!1,reason:`probe-failed`,stderr:r};let i=`${n.stdout}\n${n.stderr}`;return/\bUSAGE:\s+devicectl device process launch\b/i.test(i)&&/--console\b/.test(i)&&/--terminate-existing\b/.test(i)?{supported:!0,...r?{stderr:r}:{}}:{supported:!1,reason:`unsupported`,...r?{stderr:r}:{}}}catch(e){if(t?.aborted)throw t.reason;return{supported:!1,reason:`probe-failed`,...e instanceof Error?{stderr:e.message}:{}}}}async function Ce(e,t,n,r){let i={},a=n?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`];if(h(t))i.logAvailable=!!await e.commands.which(`log`);else if(t.kind===`simulator`)i.simctlAvailable=await oe(async()=>v(await e.appleTools.run({tool:`simctl`,args:[`help`],allowFailure:!0},r)),r);else if(t.iosPhysicalDeviceBackend===`xctest`)i.devicectlAvailable=!1,i.devicectlConsoleCapture=!1,a.push(C);else{i.devicectlAvailable=await oe(async()=>v(await e.appleTools.run({tool:`devicectl`,args:[`--version`],allowFailure:!0},r)),r);let t=await Se(e,r);if(i.devicectlConsoleCapture=t.supported,!t.supported){let e=t.reason===`unsupported`?D:xe;a.push(`${e.message} ${e.hint}`)}}return{backend:w(t),checks:i,notes:a}}function we(e,t){let n=O(e),r=[`subsystem == "${n}"`,`subsystem CONTAINS "${n}"`,`processImagePath ENDSWITH[c] "/${n}"`,`senderImagePath ENDSWITH[c] "/${n}"`];if(t){let e=O(t);r.push(`process == "${e}"`,`processImagePath ENDSWITH[c] "/${e}"`,`senderImagePath ENDSWITH[c] "/${e}"`,`processImagePath CONTAINS[c] "/${e}.app/"`,`senderImagePath CONTAINS[c] "/${e}.app/"`)}return r.join(` OR `)}function Te(e){return[...e.simulatorSetPath?[`simctl`,`--set`,e.simulatorSetPath]:[`simctl`],`spawn`,e.deviceId,`log`,`stream`,`--style`,`compact`,`--level`,`info`,`--predicate`,we(e.appBundleId,e.executableName)]}function Ee(e,t){return[`devicectl`,`device`,`process`,`launch`,`--device`,e,`--console`,`--terminate-existing`,t]}function O(e){return e.replaceAll(`\\`,`\\\\`).replaceAll(`"`,`\\"`)}async function De(e,t,n,r,i){Oe(t),ne(e,n);let a=w(t),o=await Ae(e,t,n.appBundleId,i),s=new f,c=!1;try{let l=await e.outputs.openAppend(n.outputPath);s.defer(async()=>{c||await l[Symbol.asyncDispose]()}),i?.throwIfAborted();let u=await ke(e,t,o,l,n.pidPath,i);s.defer(async()=>{c||await u[Symbol.asyncDispose]()});let d=Me(e,u,l,a,n.outputPath),f={transport:a===`ios-device`?`coredevice-console`:`apple-log-stream`,backend:a,outputPath:n.outputPath,...n.pidPath===void 0?{}:{pidPath:n.pidPath}},p=ie(d,be({sessionId:n.sessionId,device:t,owner:r,fence:n.fence,descriptor:f}));return c=!0,p}finally{await s[Symbol.asyncDispose]()}}function Oe(t){if(t.appleOs===`watchos`)throw new e(`UNSUPPORTED_PLATFORM`,`watchOS app logs are not supported`);if(m(t)&&t.kind===`device`&&t.iosPhysicalDeviceBackend===`xctest`)throw new e(`UNSUPPORTED_OPERATION`,C,{hint:C})}async function ke(t,n,r,i,a,o){if(m(n)&&n.kind===`device`){let n=await Se(t,o);if(!n.supported){let t=n.reason===`unsupported`?D:xe;throw new e(n.reason===`unsupported`?`UNSUPPORTED_OPERATION`:`COMMAND_FAILED`,t.message,{backend:`ios-device`,hint:t.hint,stderr:n.stderr})}}return o?.throwIfAborted(),await t.processes.start({command:{kind:`host`,request:r},output:i,...a?{markerPath:a}:{}})}async function Ae(e,t,n,r){if(h(t))return{executable:`log`,args:[`stream`,`--style`,`compact`,`--predicate`,we(n)],allowFailure:!0};if(t.kind===`device`)return{executable:`xcrun`,args:Ee(t.id,n),allowFailure:!0};let i=await je(e,t,n,r);return{executable:`xcrun`,args:Te({deviceId:t.id,appBundleId:n,executableName:i,simulatorSetPath:t.simulatorSetPath}),allowFailure:!0}}async function je(e,t,n,r){let i=t.simulatorSetPath?[`--set`,t.simulatorSetPath]:[],a=await e.appleTools.run({tool:`simctl`,args:[...i,`get_app_container`,t.id,n,`app`],allowFailure:!0,timeoutMs:4e3},r),o=a.exitCode===0?a.stdout.trim():``;if(!o)return;let s=await e.commands.run({executable:`plutil`,args:[`-extract`,`CFBundleExecutable`,`raw`,`-o`,`-`,me.join(o,`Info.plist`)],allowFailure:!0,timeoutMs:4e3},r);return s.exitCode===0&&s.stdout.trim()||void 0}function Me(e,t,n,r,i){let a=e.clock.now(),o=`active`;t.wait.then(e=>{o=e.exitCode===0?`ended`:`failed`},()=>{o=`failed`});let s;return ce({inspect:()=>({backend:r,state:o,startedAt:a}),finish:async()=>s??=(async()=>(await Ne([async()=>await t.terminate(),async()=>await t.wait.then(()=>void 0),async()=>await t[Symbol.asyncDispose](),async()=>await n[Symbol.asyncDispose]()])).length>0?(o=`failed`,{status:`cleanup-pending`,reason:`transport-failed`,message:`Apple app-log cleanup did not settle every owned resource`}):(o=`ended`,{status:`completed`,result:{backend:r,outputPath:i,completedAt:e.clock.now()}}))()})}async function Ne(e){let t=[];for(let n of e)try{await n()}catch(e){t.push(e)}return t}const k=o(`apple`),A=Object.freeze({available:!0});function Pe(t){return Object.freeze({owner:k,ownsDevice:e=>e.platform===`apple`,inspectFacts:async e=>j(e),bind:async n=>{if(n.intent.kind===`exact-owner`&&!p(n.intent.owner,k))throw new e(`UNSUPPORTED_OPERATION`,`Apple app-log owner identity does not match`);return Fe(t,n.device,n.scope.signal)},shutdown:async()=>void 0})}function Fe(t,n,r){if(n.platform!==`apple`)throw new e(`UNSUPPORTED_PLATFORM`,`Apple app-log owner cannot bind ${n.platform}`);let i=ae({codec:T,reattach:async(e,r)=>e.backend!==w(n)||!y(t,r.sessionId,e)?{status:`unreattachable`,reason:`descriptor-invalid`,message:`Apple app-log descriptor does not match the bound device or owning session`}:await fe(t,e.pidPath),cleanup:async(e,r)=>e.backend===w(n)&&y(t,r.sessionId,e)?await se(t,e.pidPath):{status:`cleanup-pending`,reason:`ownership-fence-lost`,message:`Apple app-log descriptor does not match the bound device or owning session`}}),a=Object.freeze({appLogInspect:async()=>({backend:w(n)}),appLogDoctor:async({appBundleId:e})=>await Ce(t,n,e,r),appLogStart:async e=>await De(t,n,e,k,r),...i});return Object.freeze({device:n,owner:k,facts:j(n),operations:a,[Symbol.asyncDispose]:async()=>void 0})}function j(e){if(e.appleOs===`watchos`)return Ie(e);let t=m(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?{available:!1,reason:`unsupported-device-backend`,hint:C}:A;return Object.freeze({device:{family:`apple`,appleOs:e.appleOs,kind:e.kind,...e.target===void 0?{}:{target:e.target},...e.iosPhysicalDeviceBackend===void 0?{}:{iosPhysicalDeviceBackend:e.iosPhysicalDeviceBackend},providerMode:`local`},operations:{appLogInspect:t,appLogDoctor:t,appLogStart:t,appLogReattach:A,appLogCleanup:A}})}function Ie(e){let t=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS app logs are not supported.`});return Object.freeze({device:{family:`apple`,appleOs:`watchos`,kind:e.kind,...e.target===void 0?{}:{target:e.target},providerMode:`local`},operations:{appLogInspect:t,appLogDoctor:t,appLogStart:t,appLogReattach:t,appLogCleanup:t}})}async function Le(e,t,n,r){let i=w(t),a=await e.appLogs.readRecent(n.sessionId,n.maxScanLines),o=le(a.text,{...n,path:a.path,exists:a.exists,lineNumberOffset:a.skippedLines,backend:i}),s=[];if(Re(t,n,o)){let i=await ze(e,t,n,a.path,r);i&&(i.dump.entries.length>0?(o=de(i.dump,o,n.maxEntries),s.push(`Recovered ${i.dump.entries.length} iOS simulator HTTP entr${i.dump.entries.length===1?`y`:`ies`} from simctl log show (${i.lineCount} app log lines scanned).`)):i.lineCount>0&&s.push(`Recovered ${i.lineCount} recent iOS simulator app log lines from simctl log show, but none looked like HTTP traffic. This app may not emit request URLs, status, or timing into Unified Logging for this repro window.`))}return Ve(s,t,n),o.entries.length===0&&s.push(He(t)),Object.freeze({source:`app-log`,backend:i,dump:o,notes:Object.freeze(s)})}function Re(e,t,n){return m(e)&&e.kind===`simulator`&&!!t.appBundleId&&n.entries.length===0}async function ze(e,t,n,r,i){let a=[...t.simulatorSetPath?[`--set`,t.simulatorSetPath]:[],`spawn`,t.id,`log`,`show`,`--style`,`compact`,`--info`,`--predicate`,Be(n.appBundleId)],o=n.appLogSnapshot?.startedAt;a.push(...typeof o==`number`&&Number.isFinite(o)&&o>0?[`--start`,`@${Math.floor(o/1e3)}`]:[`--last`,`5m`]);let s=await e.appleTools.run({tool:`simctl`,args:a,allowFailure:!0,timeoutMs:4e3},i);if(s.exitCode!==0||!s.stdout.trim())return;let c=s.stdout.split(`
2
- `).map(e=>e.trimEnd()).filter(e=>e.trim()&&!e.trim().startsWith(`Timestamp Ty Process[PID:TID]`));if(c.length!==0)return{dump:le(`${c.join(`
3
- `)}\n`,{...n,path:`${r} (simctl log show recovery)`,exists:!0,backend:`ios-simulator`}),lineCount:c.length}}function Be(e){let t=e.replaceAll(`\\`,`\\\\`).replaceAll(`"`,`\\"`);return[`subsystem == "${t}"`,`subsystem CONTAINS "${t}"`,`processImagePath ENDSWITH[c] "/${t}"`,`senderImagePath ENDSWITH[c] "/${t}"`].join(` OR `)}function Ve(e,t,n){n.appLogSnapshot?n.appLogSnapshot.state!==`active`&&e.length===0&&e.push(m(t)&&t.kind===`simulator`?`Session app log stream is inactive. The iOS simulator recovery path scanned recent simctl log history, but a fresh logs clear --restart window is still the most reliable repro loop.`:`Session app log stream is inactive. Run logs clear --restart, reproduce the request window again, then rerun network dump.`):e.push(`Capture uses the session app log file. For fresh traffic, run logs clear --restart before reproducing requests.`)}function He(e){return m(e)&&e.kind===`simulator`?`No HTTP(s) entries were found in recent iOS simulator app logs. If the app only emits non-HTTP diagnostics, inspect logs path or add app-side URLSession/network logging for per-request timing and payload details.`:m(e)?`No HTTP(s) entries were found in recent iOS device app logs. iOS network dump only sees what the app emits into Unified Logging for this process.`:`No HTTP(s) entries were found in recent session app logs.`}async function M(e,n,r){if(n.invalidatedReason&&!n.showTouches)throw Error(`recording invalidated: ${n.invalidatedReason}`);let i;try{i=await e.screenRecording.finalize.complete({outputPath:n.outPath,showTouches:n.invalidatedReason?!1:n.showTouches,gestureEvents:n.gestureEvents,exportQuality:n.exportQuality??`medium`,...n.runnerStartedAtUptimeMs!==void 0&&n.targetAppReadyUptimeMs!==void 0?{trimStartMs:Math.max(0,n.targetAppReadyUptimeMs-n.runnerStartedAtUptimeMs)}:{},targetLabel:r})}catch(e){throw t(e,`COMMAND_FAILED`)}return re(n,{...i,...n.invalidatedReason?{overlayWarning:`overlay unavailable: ${n.invalidatedReason}`}:{}})}const N=Object.freeze({resourceKind:c,version:1,encode:e=>e.backend===`simctl`?{backend:e.backend,outputPath:e.outputPath,processes:e.processes.map(e=>({...e}))}:{backend:e.backend,outputPath:e.outputPath,appBundleId:e.appBundleId,runnerSessionId:e.runnerSessionId,runnerAuthority:e.runnerAuthority,...e.remotePath===void 0?{}:{remotePath:e.remotePath}},decode:e=>Je(e)});function Ue(e){let{device:t,owner:n,input:r,descriptor:i}=e;return b({resourceKind:c,sessionId:r.sessionId,device:te(t),owner:n,fence:r.fence,lifecycle:`open`,descriptor:x(N,i)})}async function We(e,t,n){let r=N.decode(n);return r.status!==`decoded`||!I(t,r.descriptor)?{status:`cleanup-pending`,reason:`manual-recovery-required`}:r.descriptor.backend===`simctl`?await Ge(e,r.descriptor.processes):await Ke(e,t,r.descriptor)}async function Ge(e,t){let n=await Promise.all(t.map(async t=>await e.screenRecording.apple.inspectProcess(t)));if(n.includes(`ownership-lost`))return{status:`cleanup-pending`,reason:`ownership-fence-lost`};if(n.every(e=>e===`missing`))return{status:`already-missing`};let r=await Promise.all(t.flatMap((t,r)=>n[r]===`owned-alive`?[e.screenRecording.apple.terminateProcess(t)]:[]));return r.includes(`ownership-lost`)?{status:`cleanup-pending`,reason:`ownership-fence-lost`}:r.every(e=>e===`already-missing`)?{status:`already-missing`}:{status:`cleaned`}}async function Ke(e,t,n){try{let r=await e.screenRecording.apple.inspectRunner(t,n.runnerSessionId,n.runnerAuthority);return r===`missing`?{status:`already-missing`}:r===`ownership-lost`?{status:`cleanup-pending`,reason:`ownership-fence-lost`}:(await e.screenRecording.apple.runRunner(t,{kind:`stop`,appBundleId:n.appBundleId,runnerSessionId:n.runnerSessionId,runnerAuthority:n.runnerAuthority}),{status:`cleaned`})}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`Apple recording cleanup failed`}}}async function qe(e,t,n){let r=N.decode(n);if(r.status!==`decoded`)return{status:`unreattachable`,reason:`descriptor-invalid`,message:r.message};if(!I(t,r.descriptor))return{status:`unreattachable`,reason:`descriptor-invalid`,message:`Apple screen-recording descriptor does not match the bound device.`};let i=r.descriptor.backend===`simctl`?await Promise.all(r.descriptor.processes.map(async t=>await e.screenRecording.apple.inspectProcess(t))):[await e.screenRecording.apple.inspectRunner(t,r.descriptor.runnerSessionId,r.descriptor.runnerAuthority)];return i.every(e=>e===`missing`)?{status:`missing`}:{status:`unreattachable`,reason:`transport-not-reattachable`,message:i.includes(`ownership-lost`)?`Apple recording ownership no longer matches the durable descriptor.`:`Apple screen recordings require exact cleanup after daemon restart.`}}function Je(e){return typeof e.outputPath!=`string`||e.outputPath.length===0?L():e.backend===`simctl`?Ye(e,e.outputPath):e.backend===`runner`?Xe(e,e.outputPath):L()}function Ye(e,t){let n=$e(e.processes);return n?{status:`decoded`,descriptor:Object.freeze({backend:`simctl`,outputPath:t,processes:n})}:L()}function Xe(e,t){return!P(e.appBundleId)||!P(e.runnerSessionId)||!Ze(e.runnerAuthority)||!Qe(e.remotePath)?L():{status:`decoded`,descriptor:Object.freeze({backend:`runner`,outputPath:t,appBundleId:e.appBundleId,runnerSessionId:e.runnerSessionId,runnerAuthority:e.runnerAuthority,...e.remotePath===void 0?{}:{remotePath:e.remotePath}})}}function P(e){return typeof e==`string`&&e.length>0}function Ze(e){return e===`local-lease`||e===`scoped-provider`}function Qe(e){return e===void 0||F(e)}function F(e){return typeof e==`string`&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(e)}function I(e,t){return e.kind===`simulator`?t.backend===`simctl`:t.backend===`runner`?e.appleOs===`macos`?t.remotePath===void 0:m(e)?t.remotePath!==void 0&&F(t.remotePath):t.remotePath===void 0:!1}function $e(e){if(!Array.isArray(e)||e.length===0)return;let t=e.filter(e=>typeof e==`object`&&!!e&&Number.isInteger(e.pid)&&(e.pid??0)>0&&typeof e.startTime==`string`&&e.startTime.length>0&&typeof e.command==`string`&&e.command.length>0);return t.length===e.length?Object.freeze([...t]):void 0}function L(){return{status:`invalid`,message:`Invalid Apple screen-recording descriptor`}}async function et(e,t,n){if(e.kind!==`simulator`||t.scope!==`app`)return;let r=t.activeSessionApp?.bundleId;if(!r)throw TypeError(`App-scoped recording requires an active app session; open the app under test before recording.`);if(await n(r))throw TypeError(`App-scoped recording requires a real application session; open the app under test before recording.`)}function tt(e){return e.appleOs===`watchos`?V(`unsupported-platform-leaf`,`watchOS recording is not supported.`):m(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?V(`unsupported-device-backend`,`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`):Object.freeze({available:!0})}function nt(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await rt({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async e=>await qe(t,n,e.envelope.descriptor.body),screenRecordingCleanup:async e=>await We(t,n,e.envelope.descriptor.body)})}async function rt(e){return e.signal.throwIfAborted(),e.device.kind===`simulator`?await it(e):await at(e)}async function it(e){let{host:t,device:n,owner:r,input:i,signal:a}=e;await et(n,i,t.screenRecording.apple.isRunnerBundleId);let o=i.activeSessionApp?await t.screenRecording.apple.captureClockAnchor(n,i.activeSessionApp.bundleId,a):void 0;await t.screenRecording.outputs.prepare(i.outputPath);let s=await t.screenRecording.apple.startSimulator(n,i.outputPath,a),c=s.markers;if(!c||c.length===0)throw await R(s).catch(()=>{}),Error(`simctl recordVideo did not expose durable process identity`);try{a.throwIfAborted()}catch(e){throw await R(s).catch(()=>{}),e}return z({device:n,owner:r,input:i,descriptor:{backend:`simctl`,outputPath:i.outputPath,processes:c},snapshot:B(i,`simctl recordVideo`,{},o),finish:async e=>{await s.terminate();let n=await s.wait;if(n.exitCode!==0)throw Error(`simctl recordVideo exited with code ${n.exitCode}`);return await M(t,e,`iOS recording`)},cleanup:async()=>await ct(s)})}async function at(e){let{host:t,device:n,owner:r,input:i,signal:a}=e,o=i.activeSessionApp?.bundleId;if(!o)throw TypeError(`Apple runner recording requires an active app session identity`);await t.screenRecording.outputs.prepare(i.outputPath);let s=await t.screenRecording.apple.runRunner(n,{kind:`start`,appBundleId:o,outputPath:i.outputPath,...i.fps===void 0?{}:{fps:i.fps}},a);if(!s.runnerSessionId||!s.runnerAuthority)throw Error(`Apple runner recording did not expose durable session ownership`);let c={runnerSessionId:s.runnerSessionId,runnerAuthority:s.runnerAuthority},l,u=()=>l??=ot(()=>t.screenRecording.apple.runRunner(n,{kind:`stop`,appBundleId:o,...c}).then(()=>void 0));if(!st(n,s.remotePath))throw await u().catch(()=>{}),Error(`Apple runner recording did not expose coherent durable media ownership`);try{a.throwIfAborted()}catch(e){throw await u().catch(()=>{}),e}return z({device:n,owner:r,input:i,descriptor:{backend:`runner`,outputPath:i.outputPath,appBundleId:o,...c,...s.remotePath===void 0?{}:{remotePath:s.remotePath}},snapshot:B(i,`runner AVAssetWriter`,s),finish:async e=>(await u(),s.remotePath!==void 0&&await t.screenRecording.apple.retrieveRunnerRecording(n,s.remotePath,e.outPath),await M(t,e,n.appleOs===`macos`?`macOS recording`:`iOS recording`)),cleanup:async()=>(await u(),{status:`cleaned`})})}async function ot(e){try{return await e()}catch(e){throw t(e,`COMMAND_FAILED`)}}function st(e,t){return e.appleOs===`macos`||!m(e)?t===void 0:t!==void 0&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(t)}async function R(e){return await e.terminate(),await e.wait}async function ct(e){try{return await R(e),{status:`cleaned`}}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`Apple simulator cleanup failed`}}}function z(e){let{device:t,owner:n,input:r,descriptor:i,snapshot:a,finish:o,cleanup:c}=e,l=ue(a,{finish:o,forceCleanup:c});return Object.freeze({pendingHandle:new s(l),envelope:Ue({device:t,owner:n,input:r,descriptor:i})})}function B(e,t,n={},r){let i=Date.now();return Object.freeze({backend:t,outPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutPath:e.clientOutputPath},startedAt:i,scope:e.scope,showTouches:e.showTouches,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},...e.exportQuality===void 0?{}:{exportQuality:e.exportQuality},gestureEvents:[],...r===void 0?{}:{gestureClockOriginAtMs:r.wallClockAtMs,gestureClockOriginUptimeMs:r.uptimeMs},...n.recorderStartUptimeMs===void 0?{}:{gestureClockOriginAtMs:i,gestureClockOriginUptimeMs:n.recorderStartUptimeMs,runnerStartedAtUptimeMs:n.recorderStartUptimeMs},...n.targetAppReadyUptimeMs===void 0?{}:{targetAppReadyUptimeMs:n.targetAppReadyUptimeMs},...n.runnerSessionId===void 0?{}:{runnerSessionId:n.runnerSessionId}})}function V(e,t){return Object.freeze({available:!1,reason:e,hint:t})}const H=12e4;async function U(e,t,n,r={}){return n.throwIfAborted(),h(t)?{...t,booted:!0}:t.kind===`device`?(await e.deviceReadiness.applePhysical.ensureConnected(t,n),{...t,booted:!0}):t.kind===`simulator`?(await W(e,t,n)!==`Booted`&&(r.onColdBootStart?.(),e.deviceReadiness.appleAutomation.keepHot(t),await lt(e,t,n),await ut(e,n)),e.deviceReadiness.appleAutomation.keepHot(t),e.deviceReadiness.appleAutomation.markBooted(t),{...t,booted:!0}):{...t,booted:!0}}async function lt(t,n,r){let i=!1;try{let a=await t.appleTools.run({tool:`simctl`,args:S(n,[`boot`,n.id]),allowFailure:!0,timeoutMs:H},r),o=`${a.stdout}\n${a.stderr}`.toLowerCase(),s=o.includes(`already booted`)||o.includes(`current state: booted`);if(a.exitCode!==0&&!s)throw new e(`COMMAND_FAILED`,`simctl boot failed`,{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode});i=!s;let c=await t.appleTools.run({tool:`simctl`,args:S(n,[`bootstatus`,n.id,`-b`]),allowFailure:!0,timeoutMs:H},r);if(c.exitCode!==0)throw new e(`COMMAND_FAILED`,`simctl bootstatus failed`,{stdout:c.stdout,stderr:c.stderr,exitCode:c.exitCode});if(await W(t,n,r)!==`Booted`)throw new e(`COMMAND_FAILED`,`Simulator is still booting`,{deviceId:n.id})}catch(e){throw i&&r.aborted&&dt(t,n),r.throwIfAborted(),e}}async function W(e,t,n){return await pe(e.appleTools,t,n,15e3)}async function ut(e,t){await e.commands.run({executable:`open`,args:[`-a`,`Simulator`],allowFailure:!0,timeoutMs:1e4},t)}function dt(e,t){e.appleTools.run({tool:`simctl`,args:S(t,[`shutdown`,t.id]),allowFailure:!0}).catch(()=>{})}function ft(e){let t=ee({device:e.device,signal:e.signal,resolveInteractor:e.host.localInteractors.resolve});return Object.freeze({resolveOpenTarget:async t=>await e.host.appleApplications.resolveOpenTarget(e.device,t),prepareApplicationOpen:async t=>{await U(e.host,e.device,e.signal,{onColdBootStart:t.prewarmRunnerOnColdBoot?()=>{e.host.appleApplications.prewarmRunnerCache(e.device,t.execution,e.signal).catch(()=>{})}:void 0})},openApplication:async n=>await pt(e.host,t,n),applyRuntimeHints:async t=>await e.host.appleApplications.applyRuntimeHints(e.device,t),clearRuntimeHints:async t=>await e.host.appleApplications.clearRuntimeHints(e.device,t),closeApplication:async n=>await Ct(e.host,t,n),finalizeApplicationClose:async t=>await wt(e.host,e.device,e.signal,t),prepareAppleRunner:async t=>await Tt(e.host,e.device,e.signal,t),configureProviderPortReverse:kt})}async function pt(e,t,n){let r={},i=G(t.device),a=Et(e,t,n,r),o=m(t.device)&&n.surface===`app`&&n.positionals.length>0&&!!n.appBundleId;i&&o&&!n.prewarmRunnerBeforeOpen&&a.schedule(),await mt(e,t,n,i,r),await ht(n,r),await gt(a,o,n.prewarmRunnerBeforeOpen);let s=a.wasAwaited();return await _t(t,n,i,r),await yt(a,o,n.relaunch),await bt(e,t,n,i,s),await xt(e,t,i,r),{appBundleId:n.appBundleId,timing:r}}async function mt(e,t,r,i,a){if(!St(r,i)||!r.target)return;let o=Date.now();g(t.device.platform)&&!i&&await e.appleApplications.stopRunnerSession(t.device.id),await n({device:t.device,interactor:await t.resolveInteractor(r.execution,r.appBundleId),positionals:[r.appBundleId??r.target]}),i&&await e.clock.sleep(300,t.signal),a.relaunchCloseDurationMs=K(o)}async function ht(t,n){if(!u(t.runtimeHints))return;if(!t.applyRuntimeHints)throw new e(`COMMAND_FAILED`,`Runtime hint operation was not admitted for this open.`,{reason:`runtime-hints-operation-missing`});let r=Date.now();await t.applyRuntimeHints({appId:t.appBundleId,values:t.runtimeHints}),n.runtimeHintsDurationMs=K(r)}async function gt(e,t,n){!t||!n||(e.schedule(!0),await e.wait())}async function _t(e,t,n,r){let a=Dt(t,n),o=Date.now();await i({device:e.device,interactor:await e.resolveInteractor(t.execution,t.appBundleId),positionals:a.positionals,appBundleId:t.appBundleId,execution:t.execution,...n&&t.relaunch&&!t.execution.clearAppState?{terminateRunningApp:!0}:{}}),r.openDispatchDurationMs=K(o),await vt(e,t,a.followUpUrl,r)}async function vt(e,t,n,r){if(!n){r.launchUrlDurationMs=0;return}let a={...t.execution,clearAppState:void 0,launchConsole:void 0,launchArgs:void 0},o=Date.now();await i({device:e.device,interactor:await e.resolveInteractor(a,t.appBundleId),positionals:[n],appBundleId:t.appBundleId,execution:a}),r.launchUrlDurationMs=K(o)}async function yt(e,t,n){t&&!e.wasScheduled()&&e.schedule(),n?await e.wait():e.recordUnawaited()}async function bt(e,t,n,r,i){!r||!n.relaunch&&!i||await e.appleApplications.notifyRunnerAppRelaunched(t.device,n.execution,t.signal)}async function xt(e,t,n,r){let i=Date.now();n&&await e.clock.sleep(300,t.signal),r.postOpenSettleDurationMs=K(i)}function St(e,t){return!!(e.relaunch&&e.target)&&!(t&&!e.execution.clearAppState)}async function Ct(e,t,r){r.ensureReady&&await U(e,t.device,t.signal),g(t.device.platform)&&!G(t.device)&&await e.appleApplications.stopRunnerSession(t.device.id),await n({device:t.device,interactor:await t.resolveInteractor(r.execution,r.appBundleId),positionals:r.positionals}),G(t.device)&&await e.clock.sleep(300,t.signal)}async function wt(e,t,n,r){r.daemonShutdown?await e.appleApplications.dismissCloseAlerts(t,r).catch(()=>{}):r.retainRunner?(e.appleApplications.scheduleRunnerIdleStop(t.id),await e.appleApplications.dismissCloseAlerts(t,r).catch(()=>{})):(await e.appleApplications.stopRunnerSession(t.id),await e.appleApplications.dismissCloseAlerts(t,r).catch(()=>{}));let i=r.shutdownTarget&&G(t)?await e.deviceShutdown.apple.shutdownTarget(t,n):void 0;return i===void 0?{}:{shutdown:i}}async function Tt(e,t,n,r){return await U(e,t,n),await e.appleApplications.prepareRunner(t,r,n)}function Et(e,t,n,r){let i,a=!1;return{schedule:(a=!1)=>{i||=(r.runnerPrewarmKind=`session`,r.runnerPrewarmScheduled=!0,e.appleApplications.prewarmRunnerSession(t.device,n.execution,t.signal,a))},wait:async()=>{if(!i||a)return;a=!0;let e=Date.now();await i,r.runnerPrewarmWaited=!0,r.runnerPrewarmDurationMs=K(e)},wasAwaited:()=>a,wasScheduled:()=>i!==void 0,recordUnawaited:()=>{i&&!a&&(r.runnerPrewarmWaited=!1)}}}function Dt(e,t){let n=e.runtimeLaunchUrl?.trim(),i=e.positionals.length===1?e.positionals[0]?.trim():void 0;return!n||!i||r(i)?{positionals:e.positionals}:t&&!Ot(e)?{positionals:[i,n]}:{positionals:e.positionals,followUpUrl:n}}function Ot(e){return e.execution.clearAppState===!0||!!e.execution.launchConsole?.trim()||!!e.execution.launchArgs?.length}function G(e){return m(e)&&e.kind===`simulator`}function K(e){return Math.max(0,Date.now()-e)}async function kt(){throw new e(`UNSUPPORTED_OPERATION`,`This lifecycle operation is unavailable for Apple.`)}const q=Object.freeze({available:!0}),At=Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`}),jt=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Push notifications are supported on Apple simulators only.`}),J=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Mt=Object.freeze({available:!1,reason:`unsupported-device-kind`});function Y(e){let t=Bt(e);return Object.freeze({deployApp:t,materializeAppSource:t,deployMaterializedApp:t,sendPushNotification:Vt(e)})}function Nt(e){let{host:t,device:n,signal:r}=e,i=Y(n);return Object.freeze({...i.deployApp.available?{deployApp:async e=>await Pt(t,n,e,r),materializeAppSource:async e=>await t.appleDeployment.prepareArtifact(e,{signal:r}),deployMaterializedApp:async e=>await Ft(t,n,e,r)}:{},...i.sendPushNotification.available?{sendPushNotification:async e=>(await Rt(t,n,e,r),{})}:{}})}async function Pt(e,t,n,r){if(n.replaceExisting)return await e.appleDeployment.withInvalidatedAppResolutionCache(t,async()=>{let i=await e.appleDeployment.resolveAppBundleId(t,n.app);await Lt(e,t,i,r);let a=await e.appleDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{appIdentifierHint:n.app,signal:r});try{return await It(e,t,a.installablePath,r),{bundleId:i,launchTarget:i}}finally{await a.cleanup()}});let i=await e.appleDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{appIdentifierHint:n.app,signal:r});try{return await Ft(e,t,{artifact:i},r)}finally{await i.cleanup()}}async function Ft(e,t,n,r){return await It(e,t,n.artifact.installablePath,r),{...n.artifact.bundleId?{bundleId:n.artifact.bundleId}:{},...n.artifact.appName?{appName:n.artifact.appName}:{},...n.artifact.bundleId?{launchTarget:n.artifact.bundleId}:{}}}async function It(e,t,n,r){await U(e,t,r),X(await e.appleTools.run(t.kind===`simulator`?{tool:`simctl`,args:S(t,[`install`,t.id,n])}:{tool:`devicectl`,args:[`device`,`install`,`app`,`--device`,t.id,n],timeoutMs:12e4},r),`Apple app install failed`)}async function Lt(e,t,n,r){await U(e,t,r);let i=await e.appleTools.run(t.kind===`simulator`?{tool:`simctl`,args:S(t,[`uninstall`,t.id,n]),allowFailure:!0}:{tool:`devicectl`,args:[`device`,`uninstall`,`app`,`--device`,t.id,n],allowFailure:!0},r);i.exitCode===0||zt(`${i.stdout}\n${i.stderr}`)||X(i,`Apple app uninstall failed for ${n}`)}async function Rt(t,n,r,i){if(n.kind!==`simulator`)throw new e(`UNSUPPORTED_OPERATION`,`Apple push notifications require a simulator`);await U(t,n,i);let a=await t.temporaryFiles.create({prefix:`agent-device-ios-push-`,suffix:`.apns`});try{await a.writeText(`${JSON.stringify(r.payload)}\n`),X(await t.appleTools.run({tool:`simctl`,args:S(n,[`push`,n.id,r.appId,a.path])},i),`Apple push notification failed`)}finally{await a[Symbol.asyncDispose]()}}function zt(e){let t=e.toLowerCase();return t.includes(`not installed`)||t.includes(`not found`)||t.includes(`no such file`)}function X(t,n){if(t.exitCode!==0)throw new e(`COMMAND_FAILED`,n,{stdout:t.stdout,stderr:t.stderr,exitCode:t.exitCode})}function Bt(e){return Ht(e)?e.kind!==`simulator`&&e.kind!==`device`?Mt:e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?At:q:J}function Vt(e){return Ht(e)?e.kind===`simulator`?q:jt:J}function Ht(e){return m(e)&&e.appleOs!==`watchos`}const Z=o(`apple`),Q=Object.freeze({available:!0}),$=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Ut=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple appstate reads the active session state; a sessionless runtime foreground probe is unavailable.`}),Wt=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Headless boot is supported only for local Android emulators.`}),Gt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS open is not supported because XCUITest cannot drive watchOS UI.`}),Kt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS runner preparation is not supported because XCUITest cannot drive watchOS UI.`}),qt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS close is not supported because XCUITest cannot drive watchOS UI.`}),Jt=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Runtime hints are supported only for local iOS-family simulators and Android devices.`}),Yt=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`open is supported only for Apple simulators and devices.`}),Xt=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`prepare is supported only for Apple simulators and devices.`}),Zt=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`close is supported only for Apple simulators and devices.`}),Qt=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`}),$t=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`shutdown is supported only for Apple simulators and Android emulators.`});function en(e){return!m(e)||e.appleOs===`watchos`?$:e.kind===`simulator`?Q:$t}function tn(e){let t=nn(e),n=rn(e),r=an(e),i=on(e);return a({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:i,clearRuntimeHints:i,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:n,configureProviderPortReverse:Qt})}function nn(e){return _(e)===`watchos`?Gt:e.kind===`simulator`||e.kind===`device`?Q:Yt}function rn(e){return _(e)===`watchos`?Kt:e.kind===`simulator`||e.kind===`device`?Q:Xt}function an(e){return _(e)===`watchos`?qt:e.kind===`simulator`||e.kind===`device`?Q:Zt}function on(e){return _(e)!==`watchos`&&m(e)&&e.kind===`simulator`?Q:Jt}function sn(e){return e.appleOs===`watchos`?Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS app inventory is not supported.`}):e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`App inventory is available only on CoreDevice-backed physical iOS devices.`}):Q}function cn(e){let t=Pe(e),n=async n=>{let r=await t.inspectFacts(n),i=Y(n),a=tt(n),o=a.available?await e.screenRecording.apple.availability(n):void 0,s=a.available&&o?.available===!1?Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:o.hint}):a,c=n.appleOs===`watchos`?$:Q,l=h(n)||n.appleOs===`watchos`?$:Q,u=sn(n);return Object.freeze({device:r.device,operations:{...r.operations,...i,appState:Ut,networkDump:Q,screenRecordingStart:s,screenRecordingReattach:s,screenRecordingCleanup:s,ensureReady:c,bootTarget:l,bootTargetHeadless:Wt,listApps:u,...tn(n),shutdownTarget:en(n)}})};return Object.freeze({owner:Z,ownsDevice:e=>e.platform===`apple`,inspectFacts:n,bind:async r=>{let i=await t.bind(r),a=await n(r.device),o=a.operations.screenRecordingStart;return Object.freeze({device:i.device,owner:Z,facts:a,operations:Object.freeze({...i.operations,...Nt({host:e,device:r.device,signal:r.scope.signal}),networkDump:async t=>await Le(e,r.device,t,r.scope.signal),...o.available?nt({host:e,device:r.device,owner:Z,signal:r.scope.signal}):{},...a.operations.ensureReady.available?{ensureReady:async()=>await U(e,r.device,r.scope.signal)}:{},...a.operations.bootTarget.available?{bootTarget:async()=>await U(e,r.device,r.scope.signal)}:{},...a.operations.listApps.available?{listApps:async t=>await e.appInventory.apple.listApps(t.device,t.filter,r.scope.signal)}:{},...l(ft({host:e,device:r.device,signal:r.scope.signal}),a.operations),...a.operations.shutdownTarget.available?{shutdownTarget:async()=>await e.deviceShutdown.apple.shutdownTarget(r.device,r.scope.signal)}:{}}),[Symbol.asyncDispose]:async()=>await i[Symbol.asyncDispose]()})},shutdown:async()=>await t.shutdown()})}export{cn as createApplePlatformRuntime};
1
+ import{b as e,y as t}from"./sdk-contracts.js";import{r as n}from"./sdk-batch-runner.js";import{S as r,c as i,h as a,l as o,u as s,w as c}from"./sdk-device.js";import{Wt as l,Xt as u,Yt as d}from"./sdk-batch.js";import{c as f,r as p}from"./diagnostics.js";import"./diagnostics2.js";import{n as m}from"./scoped-provider.js";import{i as ee,n as te,r as ne}from"./ios-snapshot-planning.js";import{t as re}from"./request.js";import{n as ie,r as ae,t as oe}from"./application-lifecycle-runtime.js";import{i as se,t as ce}from"./touch-runtime.js";import{A as le,C as ue,D as de,G as fe,H as pe,I as me,L as he,N as ge,O as _e,P as ve,R as ye,T as be,U as xe,V as Se,a as Ce,b as we,d as Te,g as Ee,i as De,j as Oe,m as ke,s as Ae,t as je,v as Me,w as Ne,x as Pe,z as Fe}from"./alert-runtime.js";import{n as Ie}from"./audio-probe-runtime.js";import{n as Le}from"./perf-runtime.js";import{a as Re,n as ze}from"./durable-resource.js";import{n as Be,t as Ve}from"./async-lifecycle.js";import{a as He,c as Ue,d as We,f as Ge,l as Ke,n as qe,o as Je,s as Ye,t as Xe,u as Ze}from"./src7.js";import{t as Qe}from"./screen-recording-live-handle.js";import{t as $e}from"./screen-recording-completion.js";import{n as et,r as tt,t as nt}from"./audio-probe-support.js";import{t as rt}from"./screen-recording-runtime.js";import{i as it,r as at}from"./gesture-admission.js";import{t as ot}from"./interactor-operation-catalog.js";import{a as st,i as ct,n as lt,r as ut,t as dt}from"./perf-runtime-operation-builder.js";import{t as ft}from"./app-log-runtime.js";import{i as pt,r as mt}from"./managed-device-scope.js";import{a as ht,n as gt,o as _t}from"./application-lifecycle-interaction.js";import{n as vt}from"./apps-simctl.js";import{a as yt}from"./simulator.js";import{t as bt}from"./multitouch-support.js";import{n as h,t as xt}from"./simulator-state.js";import{t as St}from"./snapshot-process.js";import Ct from"node:path";import{randomUUID as wt}from"node:crypto";function Tt(e){let t=pt();return Object.freeze(t?{...m({...e},e=>yt(t,e))}:e)}function Et(e){return nt(e)?Object.freeze({available:!0}):s(e)||o(e)&&e.kind===`simulator`?Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`audio probe capture requires a macOS host.`}):Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`audio is supported for macOS sessions and iOS simulators on macOS hosts; physical iOS devices expose no host audio tap.`})}function Dt(e){let{resolveHost:t,device:n,owner:r}=e;return Object.freeze({...dt({platform:`Apple`,expectedProfileKind:`xctrace`,start:async e=>await t().start(n,r,e),reattach:async e=>await t().reattach(n,e),cleanup:async e=>await t().cleanup(n,e),writeProfileReport:async e=>await t().writeProfileReport(e)}),perfFrames:async({appId:e})=>({metric:e?await ct(t().sampleFrames(n,e)):lt(`Apple`,`bundle ID`),sampling:await t().frameSampling(n)}),perfMemorySample:async({appId:e})=>({metric:e?await ct(t().sampleMemory(n,e)):lt(`Apple`,`bundle ID`),sampling:await t().memorySampling(n)}),perfMemorySnapshot:async({appId:e,kind:r,outPath:i,artifactsDir:a})=>{let o=r??`memgraph`,s={...await t().memorySnapshotSupport(n),androidHprof:!1,heapprofd:!1};if(o!==`memgraph`)return st(`Apple`,o,s,`Use perf memory snapshot --kind memgraph for supported Apple app sessions.`);if(!e)throw ut();let c=i??Ct.join(a,`memory-memgraph-${Ot()}.memgraph`);return{artifact:await t().captureMemorySnapshot(n,e,c),support:s,sampling:{method:`xcrun memgraph`,description:`Native Apple memory graph captured for offline inspection.`,defaultKind:`memgraph`,artifactOnly:!0}}}})}function Ot(){return new Date().toISOString().replaceAll(/[:.]/g,`-`)}const g=Object.freeze({available:!0}),_=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),v=y(`Gestures are supported only for Apple simulators and devices.`),kt=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:at}),At=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:it}),jt=y(`scroll is supported only for Apple simulators and devices.`);function y(e){return Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:e})}function Mt(e){return{...ge({plan:Nt(e),directionalFling:Nt(e),multiTouch:Pt(e),targetAuthoredDrag:Ft(e),viewport:It(e)}),...le({scroll:Lt(e)})}}function Nt(e){return e.appleOs===`watchos`||e.appleOs===`visionos`?_:b(e)?g:v}function Pt(e){if(e.appleOs===`watchos`)return _;if(!b(e))return v;let t=r(e);if(t!==`ios`&&t!==`ipados`){let e=bt[t];return Object.freeze({available:!1,reason:`unsupported-platform-leaf`,...e===void 0?{}:{hint:e}})}return e.kind===`simulator`?g:kt}function Ft(e){return b(e)?(e.appleOs===void 0?e.target!==`desktop`&&e.target!==`tv`:e.appleOs===`ios`||e.appleOs===`ipados`)?g:At:v}function It(e){return e.appleOs===`watchos`?_:b(e)?g:v}function Lt(e){return b(e)?g:jt}function b(e){return e.kind===`simulator`||e.kind===`device`}const x=`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`;function S(e){return s(e)?`macos`:e.kind===`device`?`ios-device`:`ios-simulator`}const Rt=Object.freeze({resourceKind:ft,version:1,encode:e=>({...e}),decode:e=>!Bt(e.transport)||!Vt(e.backend)||!Gt(e.outputPath)||!Ut(e.pidPath)||!Ht(e.transport,e.backend)?zt():{status:`decoded`,descriptor:Object.freeze({transport:e.transport,backend:e.backend,outputPath:e.outputPath,...e.pidPath===void 0?{}:{pidPath:e.pidPath}})}});function zt(){return{status:`invalid`,message:`Invalid Apple app-log descriptor`}}function Bt(e){return e===`apple-log-stream`||e===`coredevice-console`}function Vt(e){return e===`ios-simulator`||e===`ios-device`||e===`macos`}function Ht(e,t){return e===`coredevice-console`?t===`ios-device`:t!==`ios-device`}function Ut(e){return e===void 0||Gt(e)}function Wt(e){if(!e.device.appleOs)throw TypeError(`Apple app-log persistence requires an explicit appleOs identity`);return ze({resourceKind:ft,sessionId:e.sessionId,device:{id:e.device.id,family:`apple`,appleOs:e.device.appleOs,kind:e.device.kind,...e.device.target===void 0?{}:{target:e.device.target},...e.device.iosPhysicalDeviceBackend===void 0?{}:{iosPhysicalDeviceBackend:e.device.iosPhysicalDeviceBackend}},owner:e.owner,fence:e.fence,lifecycle:`open`,descriptor:Re(Rt,e.descriptor)})}function Gt(e){return typeof e==`string`&&e.trim().length>0}const Kt={message:`iOS physical-device app console capture is not supported by the installed devicectl.`,hint:`This devicectl does not expose process launch --console. Markers can still be written to app.log, but app output is not being captured. Use an iOS simulator for agent-device app logs or inspect physical-device logs in Console.app/Xcode until this Xcode toolchain exposes scriptable console capture.`},qt={message:`Could not verify iOS physical-device app console capture support.`,hint:`Retry logs clear --restart. If the probe keeps failing, run logs doctor and inspect the request diagnostics for the devicectl help command.`};async function Jt(e,t){try{let n=await e.appleTools.run({tool:`devicectl`,args:[`device`,`process`,`launch`,`--help`],allowFailure:!0,timeoutMs:5e3},t),r=n.stderr.trim()||void 0;if(n.exitCode!==0)return{supported:!1,reason:`probe-failed`,stderr:r};let i=`${n.stdout}\n${n.stderr}`;return/\bUSAGE:\s+devicectl device process launch\b/i.test(i)&&/--console\b/.test(i)&&/--terminate-existing\b/.test(i)?{supported:!0,...r?{stderr:r}:{}}:{supported:!1,reason:`unsupported`,...r?{stderr:r}:{}}}catch(e){if(t?.aborted)throw t.reason;return{supported:!1,reason:`probe-failed`,...e instanceof Error?{stderr:e.message}:{}}}}async function Yt(e,t,n,r){let i={},a=n?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`];if(s(t))i.logAvailable=!!await e.commands.which(`log`);else if(t.kind===`simulator`)i.simctlAvailable=await tt(async()=>et(await e.appleTools.run({tool:`simctl`,args:[`help`],allowFailure:!0},r)),r);else if(t.iosPhysicalDeviceBackend===`xctest`)i.devicectlAvailable=!1,i.devicectlConsoleCapture=!1,a.push(x);else{i.devicectlAvailable=await tt(async()=>et(await e.appleTools.run({tool:`devicectl`,args:[`--version`],allowFailure:!0},r)),r);let t=await Jt(e,r);if(i.devicectlConsoleCapture=t.supported,!t.supported){let e=t.reason===`unsupported`?Kt:qt;a.push(`${e.message} ${e.hint}`)}}return{backend:S(t),checks:i,notes:a}}function Xt(e,t){let n=$t(e),r=[`subsystem == "${n}"`,`subsystem CONTAINS "${n}"`,`processImagePath ENDSWITH[c] "/${n}"`,`senderImagePath ENDSWITH[c] "/${n}"`];if(t){let e=$t(t);r.push(`process == "${e}"`,`processImagePath ENDSWITH[c] "/${e}"`,`senderImagePath ENDSWITH[c] "/${e}"`,`processImagePath CONTAINS[c] "/${e}.app/"`,`senderImagePath CONTAINS[c] "/${e}.app/"`)}return r.join(` OR `)}function Zt(e){return[...e.simulatorSetPath?[`simctl`,`--set`,e.simulatorSetPath]:[`simctl`],`spawn`,e.deviceId,`log`,`stream`,`--style`,`compact`,`--level`,`info`,`--predicate`,Xt(e.appBundleId,e.executableName)]}function Qt(e,t){return[`devicectl`,`device`,`process`,`launch`,`--device`,e,`--console`,`--terminate-existing`,t]}function $t(e){return e.replaceAll(`\\`,String.raw`\\`).replaceAll(`"`,String.raw`\"`)}async function en(e,t,n,r,i){tn(t),Je(e,n);let a=S(t),o=await rn(e,t,n.appBundleId,i),s=new Ve,c=!1;try{let l=await e.outputs.openAppend(n.outputPath);s.defer(async()=>{c||await l[Symbol.asyncDispose]()}),i?.throwIfAborted();let u=await nn(e,t,o,l,n.pidPath,i);s.defer(async()=>{c||await u[Symbol.asyncDispose]()});let d=on(e,u,l,a,n.outputPath),f={transport:a===`ios-device`?`coredevice-console`:`apple-log-stream`,backend:a,outputPath:n.outputPath,...n.pidPath===void 0?{}:{pidPath:n.pidPath}},p=Ge(d,Wt({sessionId:n.sessionId,device:t,owner:r,fence:n.fence,descriptor:f}));return c=!0,p}finally{await s[Symbol.asyncDispose]()}}function tn(e){if(e.appleOs===`watchos`)throw new t(`UNSUPPORTED_PLATFORM`,`watchOS app logs are not supported`);if(o(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`)throw new t(`UNSUPPORTED_OPERATION`,x,{hint:x})}async function nn(e,n,r,i,a,s){if(o(n)&&n.kind===`device`){let n=await Jt(e,s);if(!n.supported){let e=n.reason===`unsupported`?Kt:qt;throw new t(n.reason===`unsupported`?`UNSUPPORTED_OPERATION`:`COMMAND_FAILED`,e.message,{backend:`ios-device`,hint:e.hint,stderr:n.stderr})}}return s?.throwIfAborted(),await e.processes.start({command:{kind:`host`,request:r},output:i,...a?{markerPath:a}:{}})}async function rn(e,t,n,r){if(s(t))return{executable:`log`,args:[`stream`,`--style`,`compact`,`--predicate`,Xt(n)],allowFailure:!0};if(t.kind===`device`)return{executable:`xcrun`,args:Qt(t.id,n),allowFailure:!0};let i=await an(e,t,n,r);return{executable:`xcrun`,args:Zt({deviceId:t.id,appBundleId:n,executableName:i,simulatorSetPath:t.simulatorSetPath}),allowFailure:!0}}async function an(e,t,n,r){let i=t.simulatorSetPath?[`--set`,t.simulatorSetPath]:[],a=await e.appleTools.run({tool:`simctl`,args:[...i,`get_app_container`,t.id,n,`app`],allowFailure:!0,timeoutMs:4e3},r),o=a.exitCode===0?a.stdout.trim():``;if(!o)return;let s=await e.commands.run({executable:`plutil`,args:[`-extract`,`CFBundleExecutable`,`raw`,`-o`,`-`,Ct.join(o,`Info.plist`)],allowFailure:!0,timeoutMs:4e3},r);return s.exitCode===0&&s.stdout.trim()||void 0}function on(e,t,n,r,i){let a=e.clock.now(),o=`active`;t.wait.then(e=>{o=e.exitCode===0?`ended`:`failed`},()=>{o=`failed`});let s;return Ze({inspect:()=>({backend:r,state:o,startedAt:a}),finish:async()=>s??=(async()=>(await sn([async()=>await t.terminate(),async()=>await t.wait.then(()=>void 0),async()=>await t[Symbol.asyncDispose](),async()=>await n[Symbol.asyncDispose]()])).length>0?(o=`failed`,{status:`cleanup-pending`,reason:`transport-failed`,message:`Apple app-log cleanup did not settle every owned resource`}):(o=`ended`,{status:`completed`,result:{backend:r,outputPath:i,completedAt:e.clock.now()}}))()})}async function sn(e){let t=[];for(let n of e)try{await n()}catch(e){t.push(e)}return t}const C=l(`apple`),w=Object.freeze({available:!0});function cn(e){return Object.freeze({owner:C,ownsDevice:e=>e.platform===`apple`,inspectFacts:async e=>T(e),bind:async n=>{if(n.intent.kind===`exact-owner`&&!d(n.intent.owner,C))throw new t(`UNSUPPORTED_OPERATION`,`Apple app-log owner identity does not match`);return ln(e,n.device,n.scope.signal)},shutdown:async()=>void 0})}function ln(e,n,r){if(n.platform!==`apple`)throw new t(`UNSUPPORTED_PLATFORM`,`Apple app-log owner cannot bind ${n.platform}`);let i=We({codec:Rt,reattach:async(t,r)=>t.backend!==S(n)||!He(e,r.sessionId,t)?{status:`unreattachable`,reason:`descriptor-invalid`,message:`Apple app-log descriptor does not match the bound device or owning session`}:await Ue(e,t.pidPath),cleanup:async(t,r)=>t.backend===S(n)&&He(e,r.sessionId,t)?await Ye(e,t.pidPath):{status:`cleanup-pending`,reason:`ownership-fence-lost`,message:`Apple app-log descriptor does not match the bound device or owning session`}}),a=Object.freeze({appLogInspect:async()=>({backend:S(n)}),appLogDoctor:async({appBundleId:t})=>await Yt(e,n,t,r),appLogStart:async t=>await en(e,n,t,C,r),...i});return Object.freeze({device:n,owner:C,facts:T(n),operations:a,[Symbol.asyncDispose]:async()=>void 0})}function T(e){if(e.appleOs===`watchos`)return un(e);let t=o(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?{available:!1,reason:`unsupported-device-backend`,hint:x}:w;return Object.freeze({device:{family:`apple`,appleOs:e.appleOs,kind:e.kind,...e.target===void 0?{}:{target:e.target},...e.iosPhysicalDeviceBackend===void 0?{}:{iosPhysicalDeviceBackend:e.iosPhysicalDeviceBackend},providerMode:`local`},operations:{appLogInspect:t,appLogDoctor:t,appLogStart:t,appLogReattach:w,appLogCleanup:w}})}function un(e){let t=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS app logs are not supported.`});return Object.freeze({device:{family:`apple`,appleOs:`watchos`,kind:e.kind,...e.target===void 0?{}:{target:e.target},providerMode:`local`},operations:{appLogInspect:t,appLogDoctor:t,appLogStart:t,appLogReattach:t,appLogCleanup:t}})}async function dn(e,t,n,r){let i=S(t),a=await e.appLogs.readRecent(n.sessionId,n.maxScanLines),o=qe(a.text,{...n,path:a.path,exists:a.exists,lineNumberOffset:a.skippedLines,backend:i}),s=[];if(fn(t,n,o)){let i=await pn(e,t,n,a.path,r);i&&(i.dump.entries.length>0?(o=Xe(i.dump,o,n.maxEntries),s.push(`Recovered ${i.dump.entries.length} iOS simulator HTTP entr${i.dump.entries.length===1?`y`:`ies`} from simctl log show (${i.lineCount} app log lines scanned).`)):i.lineCount>0&&s.push(`Recovered ${i.lineCount} recent iOS simulator app log lines from simctl log show, but none looked like HTTP traffic. This app may not emit request URLs, status, or timing into Unified Logging for this repro window.`))}return hn(s,t,n),o.entries.length===0&&s.push(gn(t)),Object.freeze({source:`app-log`,backend:i,dump:o,notes:Object.freeze(s)})}function fn(e,t,n){return o(e)&&e.kind===`simulator`&&!!t.appBundleId&&n.entries.length===0}async function pn(e,t,n,r,i){let a=[...t.simulatorSetPath?[`--set`,t.simulatorSetPath]:[],`spawn`,t.id,`log`,`show`,`--style`,`compact`,`--info`,`--predicate`,mn(n.appBundleId)],o=n.appLogSnapshot?.startedAt;a.push(...typeof o==`number`&&Number.isFinite(o)&&o>0?[`--start`,`@${Math.floor(o/1e3)}`]:[`--last`,`5m`]);let s=await e.appleTools.run({tool:`simctl`,args:a,allowFailure:!0,timeoutMs:4e3},i);if(s.exitCode!==0||!s.stdout.trim())return;let c=s.stdout.split(`
2
+ `).map(e=>e.trimEnd()).filter(e=>e.trim()&&!e.trim().startsWith(`Timestamp Ty Process[PID:TID]`));if(c.length!==0)return{dump:qe(`${c.join(`
3
+ `)}\n`,{...n,path:`${r} (simctl log show recovery)`,exists:!0,backend:`ios-simulator`}),lineCount:c.length}}function mn(e){let t=e.replaceAll(`\\`,String.raw`\\`).replaceAll(`"`,String.raw`\"`);return[`subsystem == "${t}"`,`subsystem CONTAINS "${t}"`,`processImagePath ENDSWITH[c] "/${t}"`,`senderImagePath ENDSWITH[c] "/${t}"`].join(` OR `)}function hn(e,t,n){n.appLogSnapshot?n.appLogSnapshot.state!==`active`&&e.length===0&&e.push(o(t)&&t.kind===`simulator`?`Session app log stream is inactive. The iOS simulator recovery path scanned recent simctl log history, but a fresh logs clear --restart window is still the most reliable repro loop.`:`Session app log stream is inactive. Run logs clear --restart, reproduce the request window again, then rerun network dump.`):e.push(`Capture uses the session app log file. For fresh traffic, run logs clear --restart before reproducing requests.`)}function gn(e){return o(e)&&e.kind===`simulator`?`No HTTP(s) entries were found in recent iOS simulator app logs. If the app only emits non-HTTP diagnostics, inspect logs path or add app-side URLSession/network logging for per-request timing and payload details.`:o(e)?`No HTTP(s) entries were found in recent iOS device app logs. iOS network dump only sees what the app emits into Unified Logging for this process.`:`No HTTP(s) entries were found in recent session app logs.`}async function E(t,n,r){if(n.invalidatedReason&&!n.showTouches)throw Error(`recording invalidated: ${n.invalidatedReason}`);let i;try{i=await t.screenRecording.finalize.complete({outputPath:n.outPath,showTouches:!n.invalidatedReason&&n.showTouches,gestureEvents:n.gestureEvents,exportQuality:n.exportQuality??`medium`,...n.runnerStartedAtUptimeMs!==void 0&&n.targetAppReadyUptimeMs!==void 0?{trimStartMs:Math.max(0,n.targetAppReadyUptimeMs-n.runnerStartedAtUptimeMs)}:{},targetLabel:r})}catch(t){throw e(t,`COMMAND_FAILED`)}return $e(n,{...i,...n.invalidatedReason?{overlayWarning:`overlay unavailable: ${n.invalidatedReason}`}:{}})}const D=Object.freeze({resourceKind:rt,version:1,encode:e=>e.backend===`simctl`?{backend:e.backend,outputPath:e.outputPath,processes:e.processes.map(e=>({...e}))}:{backend:e.backend,outputPath:e.outputPath,appBundleId:e.appBundleId,runnerSessionId:e.runnerSessionId,runnerAuthority:e.runnerAuthority,...e.remotePath===void 0?{}:{remotePath:e.remotePath}},decode:e=>Cn(e)});function _n(e){let{device:t,owner:n,input:r,descriptor:i}=e;return ze({resourceKind:rt,sessionId:r.sessionId,device:c(t),owner:n,fence:r.fence,lifecycle:`open`,descriptor:Re(D,i)})}async function vn(e,t,n,r){let i=D.decode(n);return i.status!==`decoded`||!An(t,i.descriptor)?{status:`cleanup-pending`,reason:`manual-recovery-required`}:i.descriptor.backend===`simctl`?await yn(e,i.descriptor.processes,r):await xn(e,t,i.descriptor)}async function yn(e,t,n){let r=await Promise.all(t.map(async t=>await e.screenRecording.apple.inspectProcess(t)));if(r.includes(`ownership-lost`))return{status:`cleanup-pending`,reason:`ownership-fence-lost`};if(r.every(e=>e===`missing`))return n!==void 0&&e.screenRecording.ownedProcesses.clear(bn(n)),{status:`already-missing`};let i=await Promise.all(t.flatMap((t,n)=>r[n]===`owned-alive`?[e.screenRecording.apple.terminateProcess(t)]:[]));return i.includes(`ownership-lost`)?{status:`cleanup-pending`,reason:`ownership-fence-lost`}:(n!==void 0&&e.screenRecording.ownedProcesses.clear(bn(n)),i.every(e=>e===`already-missing`)?{status:`already-missing`}:{status:`cleaned`})}function bn(e){return{kind:`session`,sessionId:e}}async function xn(e,t,n){try{let r=await e.screenRecording.apple.inspectRunner(t,n.runnerSessionId,n.runnerAuthority);return r===`missing`?{status:`already-missing`}:r===`ownership-lost`?{status:`cleanup-pending`,reason:`ownership-fence-lost`}:(await e.screenRecording.apple.runRunner(t,{kind:`stop`,appBundleId:n.appBundleId,runnerSessionId:n.runnerSessionId,runnerAuthority:n.runnerAuthority}),{status:`cleaned`})}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`Apple recording cleanup failed`}}}async function Sn(e,t,n){let r=D.decode(n);if(r.status!==`decoded`)return{status:`unreattachable`,reason:`descriptor-invalid`,message:r.message};if(!An(t,r.descriptor))return{status:`unreattachable`,reason:`descriptor-invalid`,message:`Apple screen-recording descriptor does not match the bound device.`};let i=r.descriptor.backend===`simctl`?await Promise.all(r.descriptor.processes.map(async t=>await e.screenRecording.apple.inspectProcess(t))):[await e.screenRecording.apple.inspectRunner(t,r.descriptor.runnerSessionId,r.descriptor.runnerAuthority)];return i.every(e=>e===`missing`)?{status:`missing`}:{status:`unreattachable`,reason:`transport-not-reattachable`,message:i.includes(`ownership-lost`)?`Apple recording ownership no longer matches the durable descriptor.`:`Apple screen recordings require exact cleanup after daemon restart.`}}function Cn(e){return typeof e.outputPath!=`string`||e.outputPath.length===0?O():e.backend===`simctl`?wn(e,e.outputPath):e.backend===`runner`?Tn(e,e.outputPath):O()}function wn(e,t){let n=jn(e.processes);return n?{status:`decoded`,descriptor:Object.freeze({backend:`simctl`,outputPath:t,processes:n})}:O()}function Tn(e,t){return!En(e.appBundleId)||!En(e.runnerSessionId)||!Dn(e.runnerAuthority)||!On(e.remotePath)?O():{status:`decoded`,descriptor:Object.freeze({backend:`runner`,outputPath:t,appBundleId:e.appBundleId,runnerSessionId:e.runnerSessionId,runnerAuthority:e.runnerAuthority,...e.remotePath===void 0?{}:{remotePath:e.remotePath}})}}function En(e){return typeof e==`string`&&e.length>0}function Dn(e){return e===`local-lease`||e===`scoped-provider`}function On(e){return e===void 0||kn(e)}function kn(e){return typeof e==`string`&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(e)}function An(e,t){return e.kind===`simulator`?t.backend===`simctl`:t.backend===`runner`?e.appleOs===`macos`?t.remotePath===void 0:o(e)?t.remotePath!==void 0&&kn(t.remotePath):t.remotePath===void 0:!1}function jn(e){if(!Array.isArray(e)||e.length===0)return;let t=e.filter(e=>typeof e==`object`&&!!e&&Number.isInteger(e.pid)&&(e.pid??0)>0&&typeof e.startTime==`string`&&e.startTime.length>0&&typeof e.command==`string`&&e.command.length>0);return t.length===e.length?Object.freeze([...t]):void 0}function O(){return{status:`invalid`,message:`Invalid Apple screen-recording descriptor`}}async function Mn(e,t,n){if(e.kind!==`simulator`||t.scope!==`app`)return;let r=t.activeSessionApp?.bundleId;if(!r)throw TypeError(`App-scoped recording requires an active app session; open the app under test before recording.`);if(await n(r))throw TypeError(`App-scoped recording requires a real application session; open the app under test before recording.`)}function Nn(e){return e.appleOs===`watchos`?Un(`unsupported-platform-leaf`,`watchOS recording is not supported.`):o(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?Un(`unsupported-device-backend`,`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`):Object.freeze({available:!0})}function Pn(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await Fn({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async e=>await Sn(t,n,e.envelope.descriptor.body),screenRecordingCleanup:async e=>await vn(t,n,e.envelope.descriptor.body,e.envelope.sessionId)})}async function Fn(e){return e.signal.throwIfAborted(),e.device.kind===`simulator`?await In(e):await Ln(e)}async function In(e){let{host:t,device:n,owner:r,input:i,signal:a}=e;await Mn(n,i,t.screenRecording.apple.isRunnerBundleId);let o=i.activeSessionApp?await t.screenRecording.apple.captureClockAnchor(n,i.activeSessionApp.bundleId,a):void 0;await t.screenRecording.outputs.prepare(i.outputPath);let s=await t.screenRecording.apple.startSimulator(n,i.outputPath,a),c=s.markers;if(!c||c.length===0)throw await k(s).catch(()=>{}),Error(`simctl recordVideo did not expose durable process identity`);try{a.throwIfAborted(),t.screenRecording.ownedProcesses.replace({kind:`session`,sessionId:i.sessionId},c.map(e=>({...e,purpose:`simctl-screen-recording`})))}catch(e){try{t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId})}catch{}throw await k(s).catch(()=>{}),e}return Vn({device:n,owner:r,input:i,descriptor:{backend:`simctl`,outputPath:i.outputPath,processes:c},snapshot:Hn(i,`simctl recordVideo`,{},o),finish:async e=>{await s.terminate();let n=await s.wait;if(t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId}),n.exitCode!==0)throw Error(`simctl recordVideo exited with code ${n.exitCode}`);return await E(t,e,`iOS recording`)},cleanup:async()=>{let e=await Bn(s);return(e.status===`cleaned`||e.status===`already-missing`)&&t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId}),e}})}async function Ln(e){let{host:t,device:n,owner:r,input:i,signal:a}=e,o=i.activeSessionApp?.bundleId;if(!o)throw TypeError(`Apple runner recording requires an active app session identity`);await t.screenRecording.outputs.prepare(i.outputPath);let s=await t.screenRecording.apple.runRunner(n,{kind:`start`,appBundleId:o,outputPath:i.outputPath,...i.fps===void 0?{}:{fps:i.fps}},a);if(!s.runnerSessionId||!s.runnerAuthority)throw Error(`Apple runner recording did not expose durable session ownership`);let c={runnerSessionId:s.runnerSessionId,runnerAuthority:s.runnerAuthority},l,u=()=>l??=Rn(()=>t.screenRecording.apple.runRunner(n,{kind:`stop`,appBundleId:o,...c}).then(()=>void 0));if(!zn(n,s.remotePath))throw await u().catch(()=>{}),Error(`Apple runner recording did not expose coherent durable media ownership`);try{a.throwIfAborted()}catch(e){throw await u().catch(()=>{}),e}return Vn({device:n,owner:r,input:i,descriptor:{backend:`runner`,outputPath:i.outputPath,appBundleId:o,...c,...s.remotePath===void 0?{}:{remotePath:s.remotePath}},snapshot:Hn(i,`runner AVAssetWriter`,s),finish:async e=>(await u(),s.remotePath!==void 0&&await t.screenRecording.apple.retrieveRunnerRecording(n,s.remotePath,e.outPath),await E(t,e,n.appleOs===`macos`?`macOS recording`:`iOS recording`)),cleanup:async()=>(await u(),{status:`cleaned`})})}async function Rn(t){try{return await t()}catch(t){throw e(t,`COMMAND_FAILED`)}}function zn(e,t){return e.appleOs===`macos`||!o(e)?t===void 0:t!==void 0&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(t)}async function k(e){return await e.terminate(),await e.wait}async function Bn(e){try{return await k(e),{status:`cleaned`}}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`Apple simulator cleanup failed`}}}function Vn(e){let{device:t,owner:n,input:r,descriptor:i,snapshot:a,finish:o,cleanup:s}=e,c=Qe(a,{finish:o,forceCleanup:s});return Object.freeze({pendingHandle:new Be(c),envelope:_n({device:t,owner:n,input:r,descriptor:i})})}function Hn(e,t,n={},r){let i=Date.now();return Object.freeze({backend:t,outPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutPath:e.clientOutputPath},startedAt:i,scope:e.scope,showTouches:e.showTouches,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},...e.exportQuality===void 0?{}:{exportQuality:e.exportQuality},gestureEvents:[],...r===void 0?{}:{gestureClockOriginAtMs:r.wallClockAtMs,gestureClockOriginUptimeMs:r.uptimeMs},...n.recorderStartUptimeMs===void 0?{}:{gestureClockOriginAtMs:i,gestureClockOriginUptimeMs:n.recorderStartUptimeMs,runnerStartedAtUptimeMs:n.recorderStartUptimeMs},...n.targetAppReadyUptimeMs===void 0?{}:{targetAppReadyUptimeMs:n.targetAppReadyUptimeMs},...n.runnerSessionId===void 0?{}:{runnerSessionId:n.runnerSessionId}})}function Un(e,t){return Object.freeze({available:!1,reason:e,hint:t})}const Wn=15e3;async function A(e,t,n,r={}){return n.throwIfAborted(),await mt(t)||s(t)?{...t,booted:!0}:t.kind===`device`?(await e.deviceReadiness.applePhysical.ensureConnected(t,n),{...t,booted:!0}):t.kind===`simulator`?((await Gn(e,t)?`Booted`:await Yn(e,t,n))!==`Booted`&&(r.onColdBootStart?.(),e.deviceReadiness.appleAutomation.keepHot(t),await Kn(e,t,n,r.deadlineAtMs),await Xn(e,n)),e.deviceReadiness.appleAutomation.keepHot(t),e.deviceReadiness.appleAutomation.markBooted(t),{...t,booted:!0}):{...t,booted:!0}}async function Gn(e,t){try{return await e.deviceReadiness.appleAutomation.wasRecentlyObservedBooted(t)}catch{return!1}}async function Kn(e,t,n,r=Date.now()+12e4){let i=!1;try{i=await qn(e,t,n,r),await Jn(e,t,n,r)}catch(a){throw i&&n.aborted&&Zn(e,t),n.throwIfAborted(),Date.now()>=r?M(t,a):a}}async function qn(e,n,r,i){let a=await e.appleTools.run({tool:`simctl`,args:h(n,[`boot`,n.id]),allowFailure:!0,timeoutMs:j(i,n)},r),o=`${a.stdout}\n${a.stderr}`.toLowerCase(),s=o.includes(`already booted`)||o.includes(`current state: booted`);if(a.exitCode!==0&&!s)throw new t(`COMMAND_FAILED`,`simctl boot failed`,{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode});return!s}async function Jn(e,n,r,i){re({type:`command`,status:`progress`,message:`Waiting for the Simulator to finish booting...`});let a=await e.appleTools.run({tool:`simctl`,args:h(n,[`bootstatus`,n.id,`-b`]),allowFailure:!0,timeoutMs:j(i,n)},r);if(a.exitCode!==0)throw new t(`COMMAND_FAILED`,`simctl bootstatus failed`,{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode});if(await xt(e.appleTools,n,r,Math.min(Wn,j(i,n)))!==`Booted`)throw new t(`COMMAND_FAILED`,`Simulator is still booting`,{deviceId:n.id});if(Date.now()>=i)throw M(n)}function j(e,t){let n=e-Date.now();if(n<=0)throw M(t);return n}function M(e,n){return new t(`COMMAND_FAILED`,`Simulator did not finish booting within the startup budget`,{reason:`boot_timeout`,deviceId:e.id,hint:`The Simulator keeps booting in the background; a first boot can take several minutes. Retry once it is up, or pass a larger --timeout.`},n instanceof Error?n:void 0)}async function Yn(e,t,n){return await xt(e.appleTools,t,n,Wn)}async function Xn(e,t){await e.commands.run({executable:`open`,args:[`-a`,`Simulator`],allowFailure:!0,timeoutMs:1e4},t)}function Zn(e,t){e.appleTools.run({tool:`simctl`,args:h(t,[`shutdown`,t.id]),allowFailure:!0}).catch(()=>{})}const Qn=Object.freeze({resolveOpenTarget:`simulator`,prepareApplicationOpen:`simulator`,openApplication:`simulator`,applyRuntimeHints:`simulator`,clearRuntimeHints:`simulator`,closeApplication:`simulator`,finalizeApplicationClose:`simulator`,prepareAppleRunner:`runner`,configureProviderPortReverse:`simulator`,ensureReady:`simulator`,bootTarget:`simulator`,bootTargetHeadless:`simulator`,shutdownTarget:`simulator`,listApps:`simulator`,deployApp:`simulator`,materializeAppSource:`simulator`,deployMaterializedApp:`simulator`,sendPushNotification:`simulator`,appState:`simulator`,appLogStart:`simulator`,appLogInspect:`simulator`,appLogDoctor:`simulator`,appLogReattach:`simulator`,appLogCleanup:`simulator`,networkDump:`simulator`,audioProbeStart:`simulator`,audioProbeQuery:`simulator`,audioProbeReattach:`simulator`,audioProbeCleanup:`simulator`,readClipboard:`simulator`,writeClipboard:`simulator`,setSetting:`simulator`,captureSnapshot:`simulator`,captureSnapshotWithoutActiveApp:`simulator`,captureSnapshotWithCustomActions:`runner`,captureScreenshot:`simulator`,findText:`simulator`,findSelector:`simulator`,readTextAtPoint:`runner`,tapPoint:`runner`,tapRef:`runner`,tapElementSelector:`runner`,fillPoint:`runner`,fillRef:`runner`,longPressPoint:`runner`,hoverPoint:`runner`,hoverRef:`runner`,focusPoint:`runner`,typeText:`runner`,scrollDirection:`runner`,performGesturePlan:`runner`,performMultiTouchGesturePlan:`runner`,performTargetAuthoredDrag:`runner`,performDirectionalFlingPlan:`runner`,gestureViewport:`runner`,setViewport:`runner`,back:`runner`,home:`runner`,setOrientation:`runner`,appSwitcher:`runner`,tvRemote:`runner`,keyboardDismiss:`runner`,keyboardEnter:`runner`,keyboardStatus:`runner`,triggerAppEvent:`runner`,readAlert:`runner`,awaitAlert:`runner`,acceptAlert:`runner`,dismissAlert:`runner`,perfFrames:`runner`,perfMemorySample:`runner`,perfMemorySnapshot:`runner`,perfNativeCaptureStart:`runner`,perfNativeCaptureReattach:`runner`,perfNativeCaptureCleanup:`runner`,perfProfileReport:`runner`,screenRecordingStart:`runner`,screenRecordingReattach:`runner`,screenRecordingCleanup:`runner`});function $n(e){return e===void 0?`possible`:e.some(e=>Qn[e]===`runner`)?`required`:`none`}const er=new Map([[`application-element-missing`,5e3],[`application-server-unavailable`,5e3],[`foreground-owner-unverified`,1e3],[`foreground-owner-changed`,1e3]]);function N(e){return e.platform===`apple`&&e.appleOs===`ios`&&e.kind===`simulator`}function tr(e){let t=ee(ne({depth:1,interactiveOnly:!0}));return Object.freeze({awaitObservable:async(n,r,i)=>{if(!N(n))return`not-eligible`;let a;for(;;){let o=await e.resolveTarget(n,r,i).catch(()=>void 0);if(i.throwIfAborted(),!o)return`unobservable`;let s=await e.source.acquire({target:o,hint:t,signal:i});if(s.stage!==`failed`)return`observable`;i.throwIfAborted();let c=er.get(s.failure.code);if(c===void 0)return`unobservable`;let l=e.clock.now();if(a=Math.min(a??1/0,l+c),l>=a)return`unobservable`;await e.clock.sleep(Math.min(150,a-l),i)}}})}function nr(e,t,n){let r=n&&N(e),i=r?$n(t.execution.plannedOperations):void 0,a=o(e)&&t.surface===`app`&&t.positionals.length>0&&!!t.appBundleId&&i!==`none`;return{...i?{runnerDemand:i}:{},shouldPrewarmRunner:a,awaitPrewarmAfterOpen:t.relaunch&&!r}}function rr(e,t,n,r){r.runnerDemand===`none`&&e.appleApplications.releaseSpeculativeRunner(t.device,n.execution).catch(()=>{})}async function ir(e,t,n,r,i,a){let o=Date.now();r&&N(t.device)&&i&&n.appBundleId&&(a.postOpenObservation=await i.awaitObservable(t.device,n.appBundleId,t.signal)),r&&a.postOpenObservation!==`observable`&&await e.clock.sleep(300,t.signal),a.postOpenSettleDurationMs=Math.max(0,Date.now()-o)}function ar(e){let t=gt({device:e.device,signal:e.signal,resolveInteractor:e.host.localInteractors.resolve});return Object.freeze({resolveOpenTarget:async t=>await e.host.appleApplications.resolveOpenTarget(e.device,t),prepareApplicationOpen:async t=>{await A(e.host,e.device,e.signal,{deadlineAtMs:t.execution.startupDeadlineAtMs,onColdBootStart:t.prewarmRunnerOnColdBoot?()=>{e.host.appleApplications.prewarmRunnerCache(e.device,t.execution,e.signal).catch(()=>{})}:void 0})},openApplication:async n=>await or(e.host,t,n,e.observation),applyRuntimeHints:async t=>await e.host.appleApplications.applyRuntimeHints(e.device,t),clearRuntimeHints:async t=>await e.host.appleApplications.clearRuntimeHints(e.device,t),closeApplication:async n=>await gr(e.host,t,n),finalizeApplicationClose:async t=>await _r(e.host,e.device,e.signal,t),prepareAppleRunner:async t=>await vr(e.host,e.device,e.signal,t),configureProviderPortReverse:Cr})}async function or(e,t,n,r){let i={},a=P(t.device),o=yr(e,t,n,i),s=nr(t.device,n,a);s.runnerDemand&&(i.runnerDemand=s.runnerDemand),rr(e,t,n,s);let{shouldPrewarmRunner:c}=s,l=hr(t.device,n,a);a&&c&&!n.prewarmRunnerBeforeOpen&&o.schedule();try{await sr(e,t,n,a,l,i),await cr(n,i),await lr(o,c,n.prewarmRunnerBeforeOpen);let u=o.wasAwaited();return await ur(t,n,a,i),await fr(o,c,s.awaitPrewarmAfterOpen),await pr(e,t,n,a,u,l),await ir(e,t,n,a,r,i),{appBundleId:n.appBundleId,timing:i}}catch(n){throw l&&await e.appleApplications.stopRunnerSession(t.device.id).catch(()=>{}),n}}async function sr(e,t,n,r,a,o){if(!mr(n,r)||!n.target)return;let s=Date.now();i(t.device.platform)&&!r&&!a&&await e.appleApplications.stopRunnerSession(t.device.id),await ht({device:t.device,interactor:await t.resolveInteractor(n.execution,n.appBundleId),positionals:[n.appBundleId??n.target]}),r&&await e.clock.sleep(300,t.signal),o.relaunchCloseDurationMs=F(s)}async function cr(e,n){if(!ae(e.runtimeHints))return;if(!e.applyRuntimeHints)throw new t(`COMMAND_FAILED`,`Runtime hint operation was not admitted for this open.`,{reason:`runtime-hints-operation-missing`});let r=Date.now();await e.applyRuntimeHints({appId:e.appBundleId,values:e.runtimeHints}),n.runtimeHintsDurationMs=F(r)}async function lr(e,t,n){!t||!n||(e.schedule(!0),await e.wait())}async function ur(e,t,n,r){let i=xr(t,n),a=Date.now();await _t({device:e.device,interactor:await e.resolveInteractor(t.execution,t.appBundleId),positionals:i.positionals,appBundleId:t.appBundleId,execution:t.execution,...n&&t.relaunch&&!t.execution.clearAppState?{terminateRunningApp:!0}:{}}),r.openDispatchDurationMs=F(a),await dr(e,t,i.followUpUrl,r)}async function dr(e,t,n,r){if(!n){r.launchUrlDurationMs=0;return}let i={...t.execution,clearAppState:void 0,launchConsole:void 0,launchArgs:void 0},a=Date.now();await _t({device:e.device,interactor:await e.resolveInteractor(i,t.appBundleId),positionals:[n],appBundleId:t.appBundleId,execution:i}),r.launchUrlDurationMs=F(a)}async function fr(e,t,n){t&&!e.wasScheduled()&&e.schedule(),n?await e.wait():e.recordUnawaited()}async function pr(e,t,n,r,i,a){!o(t.device)||!r&&!a||!n.relaunch&&!i||r&&!i&&!await e.appleApplications.hasLiveRunnerSession(t.device,n.execution)||await e.appleApplications.notifyRunnerAppRelaunched(t.device,n.execution,t.signal)}function mr(e,t){return!!(e.relaunch&&e.target)&&!(t&&!e.execution.clearAppState)}function hr(e,t,n){return e.kind===`device`&&e.appleOs===`ios`&&mr(t,n)}async function gr(e,t,n){n.ensureReady&&await A(e,t.device,t.signal),i(t.device.platform)&&!P(t.device)&&await e.appleApplications.stopRunnerSession(t.device.id),await ht({device:t.device,interactor:await t.resolveInteractor(n.execution,n.appBundleId),positionals:n.positionals}),P(t.device)&&await e.clock.sleep(300,t.signal)}async function _r(e,t,n,r){r.daemonShutdown?await e.appleApplications.dismissCloseAlerts(t,r).catch(()=>{}):r.retainRunner?(e.appleApplications.scheduleRunnerIdleStop(t.id),await e.appleApplications.dismissCloseAlerts(t,r).catch(()=>{})):(await e.appleApplications.stopRunnerSession(t.id),await e.appleApplications.dismissCloseAlerts(t,r).catch(()=>{}));let i=r.shutdownTarget&&P(t)?await e.deviceShutdown.apple.shutdownTarget(t,n):void 0;return i===void 0?{}:{shutdown:i}}async function vr(e,t,n,r){let i=Date.now()+r.timeoutMs;await A(e,t,n,{deadlineAtMs:i});let a=Math.max(1,i-Date.now());return await e.appleApplications.prepareRunner(t,{...r,timeoutMs:a},n)}function yr(e,t,n,r){let i,a=!1,o=br(t.device,n)?{healthCheck:!1}:void 0;return{schedule:(a=!1)=>{i||=(r.runnerPrewarmKind=`session`,r.runnerPrewarmScheduled=!0,o?e.appleApplications.prewarmRunnerSession(t.device,n.execution,t.signal,a,o):e.appleApplications.prewarmRunnerSession(t.device,n.execution,t.signal,a))},wait:async()=>{if(!i||a)return;a=!0;let e=Date.now();await i,r.runnerPrewarmWaited=!0,r.runnerPrewarmDurationMs=F(e)},wasAwaited:()=>a,wasScheduled:()=>i!==void 0,recordUnawaited:()=>{i&&!a&&(r.runnerPrewarmWaited=!1)}}}function br(e,t){return e.kind===`device`&&e.appleOs===`ios`&&!t.hasExistingSession&&!t.relaunch&&!t.prewarmRunnerBeforeOpen}function xr(e,t){let r=e.runtimeLaunchUrl?.trim(),i=e.positionals.length===1?e.positionals[0]?.trim():void 0;return!r||!i||n(i)?{positionals:e.positionals}:t&&!Sr(e)?{positionals:[i,r]}:{positionals:e.positionals,followUpUrl:r}}function Sr(e){return e.execution.clearAppState===!0||!!e.execution.launchConsole?.trim()||!!e.execution.launchArgs?.length}function P(e){return o(e)&&e.kind===`simulator`}function F(e){return Math.max(0,Date.now()-e)}async function Cr(){throw new t(`UNSUPPORTED_OPERATION`,`This lifecycle operation is unavailable for Apple.`)}const wr=Object.freeze({available:!0}),Tr=Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`}),Er=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Push notifications are supported on Apple simulators only.`}),I=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Dr=Object.freeze({available:!1,reason:`unsupported-device-kind`});function Or(e){let t=Ir(e);return Object.freeze({deployApp:t,materializeAppSource:t,deployMaterializedApp:t,sendPushNotification:Lr(e)})}function kr(e){let{host:t,device:n,signal:r}=e,i=Or(n);return Object.freeze({...i.deployApp.available?{deployApp:async e=>await Ar(t,n,e,r),materializeAppSource:async e=>await t.appleDeployment.prepareArtifact(e,{signal:r}),deployMaterializedApp:async e=>await jr(t,n,e,r)}:{},...i.sendPushNotification.available?{sendPushNotification:async e=>(await Pr(t,n,e,r),{})}:{}})}async function Ar(e,t,n,r){if(n.replaceExisting)return await e.appleDeployment.withInvalidatedAppResolutionCache(t,async()=>{let i=await e.appleDeployment.resolveAppBundleId(t,n.app);await Nr(e,t,i,r);let a=await e.appleDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{appIdentifierHint:n.app,signal:r});try{return await Mr(e,t,a.installablePath,r),{bundleId:i,launchTarget:i}}finally{await a.cleanup()}});let i=await e.appleDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{appIdentifierHint:n.app,signal:r});try{return await jr(e,t,{artifact:i},r)}finally{await i.cleanup()}}async function jr(e,t,n,r){return await Mr(e,t,n.artifact.installablePath,r),{...n.artifact.bundleId?{bundleId:n.artifact.bundleId}:{},...n.artifact.appName?{appName:n.artifact.appName}:{},...n.artifact.bundleId?{launchTarget:n.artifact.bundleId}:{}}}async function Mr(e,t,n,r){await A(e,t,r),L(await e.appleTools.run(t.kind===`simulator`?{tool:`simctl`,args:h(t,[`install`,t.id,n])}:{tool:`devicectl`,args:[`device`,`install`,`app`,`--device`,t.id,n],timeoutMs:12e4},r),`Apple app install failed`)}async function Nr(e,t,n,r){await A(e,t,r);let i=await e.appleTools.run(t.kind===`simulator`?{tool:`simctl`,args:h(t,[`uninstall`,t.id,n]),allowFailure:!0}:{tool:`devicectl`,args:[`device`,`uninstall`,`app`,`--device`,t.id,n],allowFailure:!0},r);i.exitCode===0||Fr(`${i.stdout}\n${i.stderr}`)||L(i,`Apple app uninstall failed for ${n}`)}async function Pr(e,n,r,i){if(n.kind!==`simulator`)throw new t(`UNSUPPORTED_OPERATION`,`Apple push notifications require a simulator`);await A(e,n,i);let a=await e.temporaryFiles.create({prefix:`agent-device-ios-push-`,suffix:`.apns`});try{await a.writeText(`${JSON.stringify(r.payload)}\n`),L(await e.appleTools.run({tool:`simctl`,args:h(n,[`push`,n.id,r.appId,a.path])},i),`Apple push notification failed`)}finally{await a[Symbol.asyncDispose]()}}function Fr(e){let t=e.toLowerCase();return t.includes(`not installed`)||t.includes(`not found`)||t.includes(`no such file`)}function L(e,n){if(e.exitCode!==0)throw new t(`COMMAND_FAILED`,n,{stdout:e.stdout,stderr:e.stderr,exitCode:e.exitCode})}function Ir(e){return Rr(e)?e.kind!==`simulator`&&e.kind!==`device`?Dr:e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?Tr:wr:I}function Lr(e){return Rr(e)?e.kind===`simulator`?wr:Er:I}function Rr(e){return o(e)&&e.appleOs!==`watchos`}const R=Object.freeze({available:!0}),zr=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`back is supported on Apple simulators and physical devices.`}),Br=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function Vr(e){return e.kind!==`simulator`&&e.kind!==`device`?zr:r(e)===`watchos`?Br:R}const Hr=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`home is supported on Apple simulators and physical devices.`}),Ur=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Wr=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`app-switcher is supported on Apple simulators and physical devices.`});function Gr(e,t){if(e.kind!==`simulator`&&e.kind!==`device`)return t;let n=r(e);return n===`macos`||n===`watchos`?Ur:R}function z(e){if(e.kind!==`simulator`&&e.kind!==`device`)return!1;let t=r(e);return t!==`tvos`&&t!==`macos`&&t!==`watchos`}const Kr=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`orientation is supported on Apple simulators and physical devices.`}),qr=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function Jr(e){return e.kind!==`simulator`&&e.kind!==`device`?Kr:z(e)?R:qr}const Yr=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`tv-remote is supported only on tvOS devices.`});function Xr(e){return(e.kind===`simulator`||e.kind===`device`)&&a(e)?R:Yr}const B=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Zr=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`keyboard status/get is currently supported only on Android; use keyboard dismiss or enter on iOS`});function Qr(e){return z(e)?Zr:B}function $r(e){return z(e)?R:B}function ei(e){return z(e)?R:B}function ti(e){return Object.freeze({...Pe({back:Vr(e)}),...we({home:Gr(e,Hr)}),...Ae({appSwitcher:Gr(e,Wr)}),...Me({orientation:Jr(e)}),...Ee({tvRemote:Xr(e)}),...ke({status:Qr(e),dismiss:$r(e),enter:ei(e)})})}function ni(e){let{host:t,device:n,signal:r}=e;return ot({device:n,signal:r,resolveInteractor:t.localInteractors.resolve,facts:ti(n)})}const V=Object.freeze({available:!0}),ri=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`clipboard is supported on Apple simulators and the macOS host.`}),ii=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`settings is supported on Apple simulators and the macOS host.`}),ai=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`settings is supported on Apple simulators and the macOS host, not on physical devices of this OS.`}),oi=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`clipboard is supported on Apple simulators and the macOS host, not on physical devices of this OS.`}),H=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function si(e,t,n){if(e.kind!==`simulator`&&e.kind!==`device`)return t;let i=r(e);return i===`watchos`?H:e.kind===`simulator`||i===`macos`?V:n}function ci(e){return si(e,ri,oi)}const li=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`trigger-app-event is supported on Apple simulators and physical devices.`}),ui=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`alert is supported on Apple simulators and physical devices.`}),di=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`alert is supported on Apple simulators, the macOS host, and physical iOS devices.`});function fi(e){if(e.kind!==`simulator`&&e.kind!==`device`)return ui;let t=r(e);return t===`watchos`?H:e.kind===`simulator`||t===`ios`||t===`macos`?V:di}function pi(e){return e.kind!==`simulator`&&e.kind!==`device`?li:r(e)===`watchos`?H:V}function mi(e){let t=ci(e),n=fi(e);return Object.freeze({...Te({read:t,write:t}),...je({read:n,wait:n,accept:n,dismiss:n}),...Ce({triggerAppEvent:pi(e)}),...De({setSetting:si(e,ii,ai)})})}function hi(e){let{host:t,device:n,signal:r}=e;return ot({device:n,signal:r,resolveInteractor:t.localInteractors.resolve,facts:mi(n)})}function gi(e,t,n){let r=Fe({device:t.device,signal:t.signal,resolveInteractor:e.localInteractors.resolve}),i=async i=>{if(s(t.device)&&i.options?.surface!==void 0&&i.options.surface!==`app`)return await e.snapshot.captureSurface(t.device,i.options,Se(t.signal,i));if(!n)return await r.captureSnapshot(i);let a=Se(t.signal,i);return await n.capture(t.device,i,a,async e=>await r.captureSnapshot(e))};return Object.freeze({captureSnapshot:i,captureSnapshotWithCustomActions:i,captureSnapshotWithoutActiveApp:i})}function _i(e,t){return Object.freeze({findText:async n=>{let r=await yi(e,t,n);if(!r)return{found:!1};let i=await e.localInteractors.resolve(t.device,{...n.execution,...r});return i.findText?await i.findText(n.text,r):{found:!1}}})}function vi(e,t){return Object.freeze({findSelector:async n=>{let r=await yi(e,t,n);if(!r)return{found:!1};let i=await e.localInteractors.resolve(t.device,{...n.execution,...r});return i.findSelector?await i.findSelector(n.selector,r):{found:!1}}})}async function yi(e,t,n){let r=n.options?.appBundleId;if(r===void 0)return;let i=n.options?.surface;if(s(t.device)&&i!==void 0&&i!==`app`)return;let a=n.signal?AbortSignal.any([t.signal,n.signal]):t.signal;if(a.throwIfAborted(),await bi(e,t.device,n.execution))return{appBundleId:r,signal:a}}async function bi(e,t,n){return!N(t)||await e.appleApplications.hasLiveRunnerSession(t,n??{})}function xi(){let e,t=!1,n=async()=>(e??=import(`./adapter.js`).then(({createSimulatorSnapshotSource:e})=>e()),await e);return{acquire:async e=>t?{stage:`failed`,failure:{kind:`unsupported`,code:`source-closed`}}:await(await n()).acquire(e),close:async()=>{t=!0,e&&await(await e).close()}}}const Si=3e3;function Ci(){let e=new Map,t=new Map,n=new Map;return async(r,i,a,o)=>{a.throwIfAborted();let s=`${r.id}:${i}`,c=e.get(s);if(c&&o!==`refresh`&&await St(c.pid,{signal:a,timeoutMs:Si})===c.processStartTime)return c;e.delete(s);let l=t.get(s);return l||(l=Ti(r,i,n).then(t=>(e.set(s,t),t)).finally(()=>t.delete(s)),l.catch(()=>void 0),t.set(s,l)),await wi(l,a,r,i)}}async function wi(e,t,n,r){let i,a,o=new Promise((e,o)=>{i=setTimeout(()=>o(W(`simulator-target-discovery-pending`,n,r)),1500),a=()=>o(t.reason),t.addEventListener(`abort`,a,{once:!0})});try{return await Promise.race([e,o])}finally{clearTimeout(i),a&&t.removeEventListener(`abort`,a)}}async function Ti(e,t,n){let r=Date.now()+15e3,[i,a]=await Promise.allSettled([vt(e,[`spawn`,e.id,`launchctl`,`list`],{allowFailure:!0,timeoutMs:U(r)}),Ei(e,n,r)]);if(i.status===`rejected`)throw i.reason;if(a.status===`rejected`)throw a.reason;let o=i.value,s=a.value;if(o.exitCode!==0)throw W(`simulator-target-probe-failed`,e,t);let c=Di(o.stdout,t);if(!c)throw W(`simulator-target-unavailable`,e,t);let l=await St(c.pid,{timeoutMs:Math.min(Si,U(r))});if(!l)throw W(`simulator-target-identity-unavailable`,e,t);return Object.freeze({udid:e.id,runtime:s,pid:c.pid,generation:`${c.pid}:${c.label}:${l}`,targetId:`${e.id}:${t}`,processStartTime:l})}async function Ei(e,t,n){let r=t.get(e.id);if(r)return await r;let i=vt(e,[`list`,`devices`,`-j`],{allowFailure:!0,timeoutMs:U(n)}).then(t=>{if(t.exitCode!==0)throw W(`simulator-runtime-probe-failed`,e,``);let n=JSON.parse(t.stdout),r=Object.entries(n.devices??{}).find(([,t])=>t.some(t=>t.udid===e.id))?.[0];if(!r)throw W(`simulator-runtime-unavailable`,e,``);return r});t.set(e.id,i);try{return await i}catch(n){throw t.delete(e.id),n}}function Di(e,t){for(let n of e.split(`
4
+ `)){let[e,,r]=n.trim().split(/\s+/);if(!e||!r||!r.startsWith(`UIKitApplication:${t}[`))continue;let i=Number(e);if(Number.isSafeInteger(i)&&i>0)return{pid:i,label:r}}}function U(e){return Math.max(1,e-Date.now())}function W(e,n,r){return new t(`COMMAND_FAILED`,`Unable to resolve the running iOS Simulator app (${e}).`,{reason:e,deviceId:n.id,appBundleId:r})}function Oi(e,n={}){let r=n.source??xi(),i=n.resolveTarget??Ci(),a=new Set,o=new Map,s=tr({source:r,resolveTarget:i,clock:e.clock});return Object.freeze({awaitObservable:s.awaitObservable,shutdown:async()=>await r.close(),capture:async(n,s,c,l)=>{if(!ji(n,s))return await l(s);let u;try{u=await ki(e,i,n,s,c)}catch(e){return c.throwIfAborted(),q(`target-resolution-failed`,n,void 0,e),await G(s,l,{targetId:`${n.id}:${s.options.appBundleId}`},K(s),`target-resolution-failed`,[Pi()])}Fi(u,o,a);let d=Ii(u);if(a.has(d))return await G(s,l,u,K(s),`circuit-disabled`);let p=K(s),m=await r.acquire({target:u,hint:ee(p),signal:c});if(m.stage===`failed`){if(m.failure.kind===`cancelled`)throw c.throwIfAborted(),new t(`COMMAND_FAILED`,`Simulator AX snapshot acquisition was cancelled.`,{reason:m.failure.code,...m.failure.details});let e=await Ni(m.failure,u,n,s.options.appBundleId,c,i);return await Mi(s,l,u,e,p,m.failure,a)}try{return await f(`ios.snapshot-source.present`,async()=>await e.snapshot.presentIosAcquisition(m,s.options),{producer:`simulator-ax-bridge`})}catch(e){return await Mi(s,l,u,{lineage:u,residue:[]},p,{kind:`malformed-tree`,code:`presentation-invariant`},a,e)}}})}async function ki(e,t,n,r,i){let a=r.options.appBundleId;for(;;)try{return await t(n,a,i)}catch(t){if(!Ai(t))throw t;let i={requestId:r.execution?.requestId};if(await e.appleApplications.hasLiveRunnerSession(n,i))throw t}}function Ai(e){return e instanceof t&&e.details?.reason===`simulator-target-discovery-pending`}function ji(e,t){return e.platform===`apple`&&e.appleOs===`ios`&&e.kind===`simulator`&&!!t.options?.appBundleId&&t.options?.customActions!==!0&&t.options?.preferredBackend===void 0}async function Mi(e,t,n,r,i,a,o,s){return o.add(Ii(n)),q(a.code,{id:n.udid},n.generation,s,a.details),await G(e,t,r.lineage,i,a.code,r.residue)}async function G(e,t,n,r,i,a=[]){let o=await t(e),s=Object.freeze({producer:`apple-runner`,intent:r.acquisitionIntent,lineage:Object.freeze({...n.targetId?{targetId:n.targetId}:{},...n.generation?{generation:n.generation}:{}}),presentationKey:te(r),residue:Object.freeze([...a,{kind:`fallback-source`,producer:`apple-runner`}])}),c=`Simulator AX snapshot unavailable (${i}); used XCTest for ${n.generation?`this app generation`:`an unverified app generation`}.`;return{...o,comparisonIdentity:s,warnings:[...o.warnings??[],c]}}async function Ni(e,t,n,r,i,a){if(e.kind!==`stale-target`)return{lineage:t,residue:[]};try{return{lineage:await a(n,r,i,`refresh`),residue:[]}}catch(e){return i.throwIfAborted(),q(`fallback-target-resolution-failed`,n,void 0,e),{lineage:{targetId:t.targetId},residue:[Pi()]}}}function Pi(){return{kind:`unknown-generation`,captureId:wt()}}function K(e){return ne({raw:e.options?.raw,interactiveOnly:e.options?.interactiveOnly,depth:e.options?.depth,scope:e.options?.scope,customActions:e.options?.customActions,acquisitionIntent:e.options?.acquisitionIntent})}function Fi(e,t,n){let r=t.get(e.targetId);r&&r!==e.generation&&n.delete(`${e.targetId}:${r}`),t.set(e.targetId,e.generation)}function Ii(e){return`${e.targetId}:${e.generation}`}function q(e,t,n,r,i){p({level:`debug`,phase:`ios_snapshot_route_fallback`,data:{reason:e,deviceId:t.id,...n?{generation:n}:{},...r?{error:r instanceof Error?r.message:String(r)}:{},...i?{details:i}:{}}})}const J=l(`apple`),Y=Object.freeze({available:!0}),X=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Li=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`viewport resizes web targets only (--platform web). Apple screen geometry is fixed by the selected simulator or device type — open a different simulator to test another screen size.`}),Ri=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`the stateless audio page probe is a web-session operation; Apple targets use the host capture.`}),zi=Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`perf requires an Apple simulator, macOS device, or CoreDevice-backed physical Apple device.`}),Bi=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`focus is supported on Apple simulators and physical devices.`}),Vi=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple appstate reads the active session state; a sessionless runtime foreground probe is unavailable.`}),Hi=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Headless boot is supported only for local Android emulators.`}),Ui=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS has no XCUITest-driveable UI, so element text comes from the captured tree only.`}),Wi=Object.freeze({available:!1,reason:`unsupported-device-kind`}),Gi=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS open is not supported because XCUITest cannot drive watchOS UI.`}),Ki=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS runner preparation is not supported because XCUITest cannot drive watchOS UI.`}),qi=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS close is not supported because XCUITest cannot drive watchOS UI.`}),Ji=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Runtime hints are supported only for local iOS-family simulators and Android devices.`}),Yi=Z(`open is supported only for Apple simulators and devices.`),Xi=Z(`prepare is supported only for Apple simulators and devices.`),Zi=Z(`close is supported only for Apple simulators and devices.`),Qi=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`}),$i=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`shutdown is supported only for Apple simulators and Android emulators.`}),ea=Z(`snapshot is supported only for Apple simulators and devices.`),ta=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Re-run without --actions, or target an iOS simulator.`}),na=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`screenshot is not supported on watchOS because XCUITest cannot drive watchOS UI.`}),ra=Z(`screenshot is supported only for Apple simulators and devices.`),ia=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`Open the app under test before capturing its snapshot.`}),aa=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Native selector observation is available only on the Apple touch family.`});function Z(e){return Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:e})}function oa(e){return!o(e)||e.appleOs===`watchos`?X:e.kind===`simulator`?Y:$i}function sa(e){let t=ca(e),n=la(e),r=ua(e),i=da(e);return oe({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:i,clearRuntimeHints:i,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:n,configureProviderPortReverse:Qi})}function ca(e){return r(e)===`watchos`?Gi:e.kind===`simulator`||e.kind===`device`?Y:Yi}function la(e){return r(e)===`watchos`?Ki:e.kind===`simulator`||e.kind===`device`?Y:Xi}function ua(e){return r(e)===`watchos`?qi:e.kind===`simulator`||e.kind===`device`?Y:Zi}function da(e){return r(e)!==`watchos`&&o(e)&&e.kind===`simulator`?Y:Ji}function fa(e){return e.appleOs===`watchos`?Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS app inventory is not supported.`}):e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`App inventory is available only on CoreDevice-backed physical iOS devices.`}):Y}function Q(e){return e.kind===`simulator`||e.kind===`device`?Y:Bi}function pa(e){let t=cn(e),n=Oi(e),r=async n=>{let r=await t.inspectFacts(n),i=Or(n),a=Nn(n),c=a.available?await e.screenRecording.apple.availability(n):void 0,l=a.available&&c?.available===!1?Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:c.hint}):a,u=n.appleOs===`watchos`?X:Y,d=s(n)||n.appleOs===`watchos`?X:Y,f=fa(n);return Object.freeze({device:r.device,operations:{...r.operations,...i,appState:Vi,networkDump:Y,screenRecordingStart:l,screenRecordingReattach:l,screenRecordingCleanup:l,...va(n),...fe({capture:_a(n)}),...ye({findText:$(n),findSelector:ga(n)}),...he({setViewport:Li}),...me({focus:Q(n)}),...Mt(n),...de({type:Q(n)}),...se({tap:Q(n),tapRef:X,longPress:Q(n),hover:X,hoverRef:X,fill:Q(n),fillRef:X,tapElementSelector:o(n)?Q(n):X}),...Ne({readTextAtPoint:ha(n)}),...ti(n),...mi(n),...Ie({capture:Et(n),query:Ri}),...Le(ma(n)),ensureReady:u,bootTarget:d,bootTargetHeadless:Hi,listApps:f,...sa(n),shutdownTarget:oa(n)}})};return Object.freeze({owner:J,ownsDevice:e=>e.platform===`apple`,inspectFacts:r,bind:async i=>{let a=await t.bind(i),o=await r(i.device),s=o.operations.screenRecordingStart,c={...a.operations,...kr({host:e,device:i.device,signal:i.scope.signal}),networkDump:async t=>await dn(e,i.device,t,i.scope.signal),...u(s,()=>Pn({host:e,device:i.device,owner:J,signal:i.scope.signal})),...u(o.operations.audioProbeStart,()=>Ke({host:e.audioProbe.hostCapture,device:i.device,owner:J})),...u(o.operations.perfFrames,()=>Dt({resolveHost:()=>e.perf.apple,device:i.device,owner:J})),...u(o.operations.captureSnapshot,()=>gi(e,{device:i.device,signal:i.scope.signal},n)),...u(o.operations.captureScreenshot,()=>xe({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...u(o.operations.focusPoint,()=>ve({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...Oe({device:i.device,signal:i.scope.signal,facts:o.operations,resolveInteractor:e.localInteractors.resolve}),...u(o.operations.scrollDirection,()=>_e({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...u(o.operations.typeText,()=>be({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...u(o.operations.tapPoint,()=>ce({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:o.operations,pause:async t=>await e.clock.sleep(t,i.scope.signal)})),...u(o.operations.readTextAtPoint,()=>ue({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...u(o.operations.findText,()=>_i(e,{device:i.device,signal:i.scope.signal})),...u(o.operations.findSelector,()=>vi(e,{device:i.device,signal:i.scope.signal})),...ni({host:e,device:i.device,signal:i.scope.signal}),...hi({host:e,device:i.device,signal:i.scope.signal}),...u(o.operations.ensureReady,()=>({ensureReady:async()=>await A(e,i.device,i.scope.signal)})),...u(o.operations.bootTarget,()=>({bootTarget:async()=>await A(e,i.device,i.scope.signal)})),...u(o.operations.listApps,()=>({listApps:async e=>{i.scope.signal.throwIfAborted();let{listIosApps:t}=await import(`./app-resolution.js`).then(e=>e.t);return(await t(e.device,e.filter)).map(e=>({id:e.bundleId,name:e.name}))}})),...ie(ar({host:e,device:i.device,signal:i.scope.signal,observation:n}),o.operations),...u(o.operations.shutdownTarget,()=>({shutdownTarget:async()=>await e.deviceShutdown.apple.shutdownTarget(i.device,i.scope.signal)}))};return Object.freeze({device:a.device,owner:J,facts:o,operations:Tt(c),[Symbol.asyncDispose]:async()=>await a[Symbol.asyncDispose]()})},shutdown:async()=>{await Promise.all([t.shutdown(),n.shutdown()])}})}function ma(e){let t=e.iosPhysicalDeviceBackend!==`xctest`&&r(e)!==`watchos`?Y:zi;return{frames:t,memorySample:t,memorySnapshot:t,nativeCapture:t,profileReport:t}}function ha(e){return r(e)===`watchos`?Ui:e.kind===`simulator`||e.kind===`device`?Y:Wi}function $(e){return r(e)===`watchos`?ea:e.kind===`simulator`||e.kind===`device`?Y:ea}function ga(e){return o(e)?$(e):aa}function _a(e){return r(e)===`watchos`?na:e.kind===`simulator`||e.kind===`device`?Y:ra}function va(e){let t=$(e);return pe({capture:t,customActions:t.available&&o(e)&&e.kind===`simulator`?Y:ta,withoutActiveApp:o(e)?ia:t})}export{pa as createApplePlatformRuntime};
@@ -1 +1 @@
1
- import{C as e}from"./sdk-contracts.js";import{c as t}from"./sdk-device.js";import{n,t as r}from"./simulator-state.js";const i=15e3;function a(e){return Object.freeze({canShutdownTarget:o,shutdownTarget:async(t,n)=>await s(e.appleTools,t,n)})}function o(e){return t(e)&&e.appleOs!==`watchos`&&e.kind===`simulator`}async function s(t,r,a){if(r.booted===!1)return u();a.throwIfAborted();try{let e=await t.run({tool:`simctl`,args:n(r,[`shutdown`,r.id]),allowFailure:!0,timeoutMs:i},a);a.throwIfAborted();let o=l(e);return o.success?o:await c(t,r,a)===`Shutdown`?{...o,success:!0,exitCode:0}:o}catch(t){a.throwIfAborted();let n=e(t);return{success:!1,exitCode:-1,stdout:``,stderr:n.message,error:n}}}async function c(e,t,n){try{return await r(e,t,n,i)}catch{return n.throwIfAborted(),null}}function l(e){let t=e.exitCode??-1;return{success:t===0,exitCode:t,stdout:e.stdout,stderr:e.stderr}}function u(){return{success:!0,exitCode:0,stdout:``,stderr:``}}export{a as createAppleShutdownRuntime};
1
+ import{O as e}from"./sdk-contracts.js";import{l as t}from"./sdk-device.js";import{n,t as r}from"./simulator-state.js";const i=15e3;function a(e){return Object.freeze({canShutdownTarget:o,shutdownTarget:async(t,n)=>await s(e.appleTools,t,n)})}function o(e){return t(e)&&e.appleOs!==`watchos`&&e.kind===`simulator`}async function s(t,r,a){a.throwIfAborted();try{let e=await t.run({tool:`simctl`,args:n(r,[`shutdown`,r.id]),allowFailure:!0,timeoutMs:i},a);a.throwIfAborted();let o=l(e);return o.success?o:await c(t,r,a)===`Shutdown`?{...o,success:!0,exitCode:0}:o}catch(t){a.throwIfAborted();let n=e(t);return{success:!1,exitCode:-1,stdout:``,stderr:n.message,error:n}}}async function c(e,t,n){try{return await r(e,t,n,i)}catch{return n.throwIfAborted(),null}}function l(e){let t=e.exitCode??-1;return{success:t===0,exitCode:t,stdout:e.stdout,stderr:e.stderr}}export{a as createAppleShutdownRuntime};
@@ -1 +1 @@
1
- import{_ as e}from"./sdk-contracts.js";import{R as t,at as n,bt as r,dt as i,et as a,ot as o,tt as s,z as c}from"./sdk-batch-runner.js";import{C as l}from"./sdk-device.js";import{a as u,d,f,o as p,p as m,v as h,x as g}from"./src3.js";import{randomUUID as _}from"node:crypto";import{setTimeout as ee}from"node:timers/promises";const v=Object.freeze({resourceKind:s,version:1,encode:e=>({...e}),decode:e=>e.transport!==`harmony-hilog`||!y(e.outputPath)||!y(e.pidPath)?{status:`invalid`,message:`Invalid HarmonyOS app-log descriptor`}:{status:`decoded`,descriptor:Object.freeze({transport:`harmony-hilog`,outputPath:e.outputPath,pidPath:e.pidPath})}});function te(e){return h({resourceKind:s,sessionId:e.sessionId,device:{id:e.device.id,family:`harmonyos`,kind:e.device.kind,...e.device.target===void 0?{}:{target:e.device.target}},owner:e.owner,fence:e.fence,lifecycle:`open`,descriptor:g(v,e.descriptor)})}function y(e){return typeof e==`string`&&e.trim().length>0}function b(e){return u(e,{family:`harmonyos`,backend:`harmonyos`,label:`HarmonyOS`,codec:v,startUnavailableHint:`The selected HarmonyOS transport cannot start a background hilog stream.`,cleanupFailureMessage:`HarmonyOS app-log cleanup did not settle every owned resource`,doctor:async(e,t)=>({backend:`harmonyos`,checks:{},notes:t?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`]}),process:async({host:e,device:t,input:n,signal:r})=>{let i=await x(e,r);return{resolvePid:async r=>await p(e,{executable:i,args:[`-t`,t.id,`shell`,`pidof`,n.appBundleId],allowFailure:!0,timeoutMs:5e3},r),command:e=>({kind:`host`,request:{executable:i,args:[`-t`,t.id,`shell`,`hilog`,`-P`,e],allowFailure:!0}})}},descriptor:({artifacts:e})=>({transport:`harmony-hilog`,...e}),envelope:({input:e,device:t,owner:n,descriptor:r})=>te({sessionId:e.sessionId,device:t,owner:n,fence:e.fence,descriptor:r})})}async function x(t,n){n.throwIfAborted(),await S(async()=>await t.toolchains.prepare(`harmonyos`),n),n.throwIfAborted();let r=await S(async()=>await t.commands.which(`hdc`),n);if(n.throwIfAborted(),!r)throw new e(`TOOL_MISSING`,`hdc not found in PATH`,{hint:`Install HarmonyOS Command Line Tools, then add its sdk/default/openharmony/toolchains directory to PATH.`});return r}async function S(e,t){try{return await e()}catch(e){throw t.throwIfAborted(),e}}const C=Object.freeze({resourceKind:a,version:1,encode:e=>({...e}),decode:e=>e.backend===`harmony-screen-recorder`&&typeof e.fileName==`string`&&ne(e.fileName)&&e.remotePath===`/data/local/tmp/${e.fileName}`?{status:`decoded`,descriptor:Object.freeze({backend:`harmony-screen-recorder`,fileName:e.fileName,remotePath:e.remotePath})}:{status:`invalid`,message:`Invalid HarmonyOS screen-recording descriptor`}});function w(e){let{device:t,owner:n,input:r,descriptor:i}=e;return h({resourceKind:a,sessionId:r.sessionId,device:l(t),owner:n,fence:r.fence,lifecycle:`open`,descriptor:g(C,i)})}function T(e){return C.decode(e).status===`decoded`?{status:`cleanup-pending`,reason:`manual-recovery-required`,message:`HarmonyOS recorder ownership cannot be proven after daemon restart; no recorder was stopped.`}:{status:`cleanup-pending`,reason:`manual-recovery-required`}}function ne(e){return/^agent-device-recording-[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\.mp4$/i.test(e)}function E(e){return e.kind===`device`?Object.freeze({available:!0}):Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`HarmonyOS recording is supported on physical devices only.`})}function re(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await ie({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async()=>({status:`unreattachable`,reason:`transport-not-reattachable`,message:`HarmonyOS recordings cannot be reattached after daemon restart.`}),screenRecordingCleanup:async e=>T(e.envelope.descriptor.body)})}async function ie(t){let{host:n,device:r,owner:a,input:o,signal:s}=t;if(o.scope===`app`)throw new e(`INVALID_ARGS`,`HarmonyOS recording captures the whole physical-device screen; use --scope device or --scope system`);d(o,{scopes:[`device`,`system`],fps:!1,exportQuality:!1,hideTouches:!1},e=>`HarmonyOS recordings do not support ${e.join(`, `)}`),s.throwIfAborted(),await n.screenRecording.outputs.prepare(o.outputPath);let c=`agent-device-recording-${_()}.mp4`,l={backend:`harmony-screen-recorder`,fileName:c,remotePath:`/data/local/tmp/${c}`},u;try{u=await n.screenRecording.harmony.start(r,c,s),s.throwIfAborted()}catch(e){throw s.aborted?(await N(n,r,l).catch(()=>{}),s.reason):e}I(u,`start`);try{s.throwIfAborted()}catch(e){throw await N(n,r,l).catch(()=>{}),e}let f=D(o),p=!1,h=async()=>{p||=(I(await n.screenRecording.harmony.stop(r),`stop`),!0)},g=m(f,{finish:async e=>await O(n,r,e,l,h),forceCleanup:async()=>await N(n,r,l,h)});return Object.freeze({pendingHandle:new i(g),envelope:w({device:r,owner:a,input:o,descriptor:l})})}function D(e){return Object.freeze({backend:`HarmonyOS ScreenRecorder`,outPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutPath:e.clientOutputPath},startedAt:Date.now(),scope:e.scope,showTouches:!1,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},gestureEvents:[]})}async function O(e,t,n,r,i){await i();let a=await e.screenRecording.harmony.findMedia(t,r.fileName);if(!a)throw Error(`failed to find finalized HarmonyOS recording '${r.fileName}'`);if(!await M(e,t,r,a))throw Error(`failed to finalize HarmonyOS recording: ${r.fileName} did not produce a non-empty media file`);try{if((await e.screenRecording.harmony.pull(t,{remotePath:r.remotePath,outputPath:n.outPath})).exitCode!==0)throw Error(`failed to retrieve HarmonyOS recording`);let i=await e.screenRecording.finalize.complete({outputPath:n.outPath,showTouches:!1,gestureEvents:n.gestureEvents,targetLabel:`HarmonyOS recording`}),o=await k(e,t,r,a);return f(n,{...i,...j(i.warning,o)},!1)}catch(n){throw await e.screenRecording.harmony.remove(t,r.remotePath).catch(()=>{}),n}}async function k(e,t,n,r){let i=[];return await A(()=>e.screenRecording.harmony.remove(t,n.remotePath))||i.push(`staging artifact`),await A(()=>e.screenRecording.harmony.removeMedia(t,r))||i.push(`media-library artifact`),i.length===0?void 0:`HarmonyOS recording completed, but cleanup was not confirmed for the ${i.join(` and `)}.`}async function A(e){try{return await e()}catch{return!1}}function j(e,t){let n=[e,t].filter(e=>e!==void 0).join(` `);return n.length===0?{}:{warning:n}}async function M(e,t,n,r){let i;for(let a=0;a<40;a+=1){if(await e.screenRecording.harmony.remove(t,n.remotePath).catch(()=>{}),await e.screenRecording.harmony.stageMedia(t,{mediaUri:r,remotePath:n.remotePath})){let r=await e.screenRecording.harmony.stagedFileSize(t,n.remotePath);if(r!==void 0&&r>0&&r===i)return!0;i=r!==void 0&&r>0?r:void 0}else i=void 0;a<39&&await e.clock.sleep(250)}return!1}async function N(e,t,n,r=async()=>{I(await e.screenRecording.harmony.stop(t),`stop`)}){let i=[await F(r),await F(async()=>{if(!await e.screenRecording.harmony.remove(t,n.remotePath))throw Error(`HarmonyOS recording staging artifact removal was not confirmed`)}),await F(async()=>await P(e,t,n.fileName))].find(e=>e!==void 0);return i===void 0?{status:`cleaned`}:{status:`cleanup-pending`,reason:`transport-failed`,message:i instanceof Error?i.message:`HarmonyOS recording cleanup failed`}}async function P(e,t,n){let r=await e.screenRecording.harmony.findMedia(t,n);if(r&&!await e.screenRecording.harmony.removeMedia(t,r))throw Error(`HarmonyOS recording media removal was not confirmed`)}async function F(e){try{await e();return}catch(e){return e}}function I(e,t){if(e.exitCode===0&&e.stdout.includes(`start ability successfully`))return;let n=e.stdout.trim()||e.stderr.trim()||`hdc exit ${e.exitCode}`;throw Error(`failed to ${t} HarmonyOS screen recording: ${n}`)}async function L(t,n,r){r.throwIfAborted();let i=await t.run(n,{args:[`shell`,`aa`,`dump`,`-l`],timeoutMs:15e3},r);r.throwIfAborted();let a=R(i.stdout);if(!a)throw new e(`COMMAND_FAILED`,`Could not determine the foreground HarmonyOS app`,{hint:`Open an app on the target, then retry appstate.`});return a}function R(e){let t=e.split(/(?=^\s*Mission ID #)/m);for(let e of t){if(!/\bstate #FOREGROUND\b/.test(e))continue;let t=e.match(/mission name #\[#([^:]+):[^:]*:([^\]]+)]/);if(!t)continue;let[,n,r]=t;if(!(!n||!r))return{package:n,activity:r}}}function z(e){return t({owner:`HarmonyOS`,openTargetIdentity:`bundle-id`,binding:c({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const B=Object.freeze({available:!0}),V=Object.freeze({available:!1,reason:`unsupported-device-kind`}),H=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function U(e){let t=e.kind===`emulator`||e.kind===`device`?B:V;return Object.freeze({deployApp:t,materializeAppSource:H,deployMaterializedApp:H,sendPushNotification:H})}function W(e){return U(e.device).deployApp.available?Object.freeze({deployApp:async t=>await G(e.commands,e.device,t,e.signal)}):Object.freeze({})}async function G(t,n,r,i){let a=await K(t,r.appPath,i)??r.app.trim();if(!a)throw new e(`INVALID_ARGS`,`Could not determine the bundle name from the HAP archive`,{hint:`Pass the HarmonyOS bundle name before the HAP path, or provide a valid HAP containing module.json.`});return await Y(t,n,[`install`,`-r`,r.appPath],i,18e4),r.replaceExisting&&(await ee(1e3,void 0,{signal:i}),await q(t,n,a,i)),{packageName:a,launchTarget:a}}async function K(e,t,n){let r=await e.run({executable:`unzip`,args:[`-p`,t,`module.json`],allowFailure:!0,timeoutMs:15e3},n);if(!(r.exitCode!==0||r.stdout.trim().length===0))try{return JSON.parse(r.stdout).app?.bundleName?.trim()||void 0}catch{return}}async function q(t,n,r,i){let a=J((await Y(t,n,[`shell`,`bm`,`dump`,`-n`,r],i)).stdout);if(!a)throw new e(`COMMAND_FAILED`,`Could not determine a launchable ability for ${r}`,{hint:`Check that the HarmonyOS bundle exposes a main ability.`});await Y(t,n,[`shell`,`aa`,`start`,`-b`,r,...a.module?[`-m`,a.module]:[],`-a`,a.ability],i)}function J(e){let t=e.indexOf(`{`);if(t!==-1)try{let n=JSON.parse(e.slice(t)).hapModuleInfos?.find(e=>e.mainElementName);return n?.mainElementName?{ability:n.mainElementName,...n.moduleName?{module:n.moduleName}:{}}:void 0}catch{return}}async function Y(e,t,n,r,i=15e3){return await e.run({executable:`hdc`,args:[`-t`,t.id,...n],timeoutMs:i},r)}const X=r(`harmonyos`),Z=Object.freeze({available:!0}),Q=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),ae=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`HarmonyOS appstate is supported only for HarmonyOS emulators and devices.`}),oe=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple runner preparation is supported only for Apple targets.`}),$=Object.freeze({available:!0}),se=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`open is supported only for HarmonyOS emulators and devices.`}),ce=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`close is supported only for HarmonyOS emulators and devices.`}),le=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`});function ue(e){let t=de(e),r=fe(e);return n({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:Q,clearRuntimeHints:Q,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:oe,configureProviderPortReverse:le})}function de(e){return e.kind===`emulator`||e.kind===`device`?$:se}function fe(e){return e.kind===`emulator`||e.kind===`device`?$:ce}function pe(e){let t=b(e),n=async e=>{let n=await t.inspectFacts(e),r=U(e),i=E(e);return Object.freeze({device:n.device,operations:{...n.operations,...r,appState:e.kind===`simulator`?ae:Z,networkDump:Q,screenRecordingStart:i,screenRecordingReattach:i,screenRecordingCleanup:i,ensureReady:Z,bootTarget:Q,bootTargetHeadless:Q,listApps:Z,...ue(e),shutdownTarget:Q}})};return Object.freeze({owner:X,ownsDevice:e=>e.platform===`harmonyos`,inspectFacts:n,bind:async r=>{let i=await t.bind(r),a=await n(r.device),s=a.operations.screenRecordingStart;return Object.freeze({device:i.device,owner:X,facts:a,operations:Object.freeze({...i.operations,...W({commands:e.commands,device:r.device,signal:r.scope.signal}),...a.operations.appState.available?{appState:async()=>await L(e.appState.harmonyos,r.device,r.scope.signal)}:{},ensureReady:async()=>({...r.device,booted:!0}),...s.available?re({host:e,device:r.device,owner:X,signal:r.scope.signal}):{},listApps:async t=>await e.appInventory.harmonyos.listApps(t.device,t.filter,r.scope.signal),...o(z({host:e.localInteractors,device:r.device,signal:r.scope.signal}),a.operations)}),[Symbol.asyncDispose]:async()=>await i[Symbol.asyncDispose]()})},shutdown:async()=>await t.shutdown()})}export{pe as createHarmonyPlatformRuntime};
1
+ import{y as e}from"./sdk-contracts.js";import{w as t}from"./sdk-device.js";import{Wt as n,Xt as r}from"./sdk-batch.js";import{n as i,t as a}from"./application-lifecycle-runtime.js";import{i as o,t as s}from"./touch-runtime.js";import{A as c,D as l,G as u,H as d,I as f,L as p,N as ee,O as te,P as m,R as h,T as g,U as ne,a as re,b as ie,d as ae,g as oe,i as se,j as ce,m as le,s as ue,t as de,v as fe,w as pe,x as me,z as he}from"./alert-runtime.js";import{n as ge}from"./audio-probe-runtime.js";import{n as _e}from"./perf-runtime.js";import{a as _,n as v}from"./durable-resource.js";import{n as ve}from"./async-lifecycle.js";import{i as ye,r as be}from"./src7.js";import{t as y}from"./screen-recording-live-handle.js";import{t as b}from"./screen-recording-completion.js";import{t as x}from"./screen-recording-options.js";import{t as S}from"./screen-recording-runtime.js";import{i as C}from"./gesture-admission.js";import{t as w}from"./interactor-operation-catalog.js";import{i as T,n as E}from"./perf-runtime-operation-builder.js";import{t as D}from"./app-log-runtime.js";import{n as O,t as k}from"./application-lifecycle-interaction.js";import{randomUUID as A}from"node:crypto";import{setTimeout as j}from"node:timers/promises";const M=Object.freeze({resourceKind:D,version:1,encode:e=>({...e}),decode:e=>e.transport!==`harmony-hilog`||!P(e.outputPath)||!P(e.pidPath)?{status:`invalid`,message:`Invalid HarmonyOS app-log descriptor`}:{status:`decoded`,descriptor:Object.freeze({transport:`harmony-hilog`,outputPath:e.outputPath,pidPath:e.pidPath})}});function N(e){return v({resourceKind:D,sessionId:e.sessionId,device:{id:e.device.id,family:`harmonyos`,kind:e.device.kind,...e.device.target===void 0?{}:{target:e.device.target}},owner:e.owner,fence:e.fence,lifecycle:`open`,descriptor:_(M,e.descriptor)})}function P(e){return typeof e==`string`&&e.trim().length>0}function xe(e){return be(e,{family:`harmonyos`,backend:`harmonyos`,label:`HarmonyOS`,codec:M,startUnavailableHint:`The selected HarmonyOS transport cannot start a background hilog stream.`,cleanupFailureMessage:`HarmonyOS app-log cleanup did not settle every owned resource`,doctor:async(e,t)=>({backend:`harmonyos`,checks:{},notes:t?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`]}),process:async({host:e,device:t,input:n,signal:r})=>{let i=await Se(e,r);return{resolvePid:async r=>await ye(e,{executable:i,args:[`-t`,t.id,`shell`,`pidof`,n.appBundleId],allowFailure:!0,timeoutMs:5e3},r),command:e=>({kind:`host`,request:{executable:i,args:[`-t`,t.id,`shell`,`hilog`,`-P`,e],allowFailure:!0}})}},descriptor:({artifacts:e})=>({transport:`harmony-hilog`,...e}),envelope:({input:e,device:t,owner:n,descriptor:r})=>N({sessionId:e.sessionId,device:t,owner:n,fence:e.fence,descriptor:r})})}async function Se(t,n){n.throwIfAborted(),await F(async()=>await t.toolchains.prepare(`harmonyos`),n),n.throwIfAborted();let r=await F(async()=>await t.commands.which(`hdc`),n);if(n.throwIfAborted(),!r)throw new e(`TOOL_MISSING`,`hdc not found in PATH`,{hint:`Install HarmonyOS Command Line Tools, then add its sdk/default/openharmony/toolchains directory to PATH.`});return r}async function F(e,t){try{return await e()}catch(e){throw t.throwIfAborted(),e}}function Ce(e){let{resolveHost:t,device:n}=e,r={available:!1,reason:`Dropped-frame sampling is currently available only on Android app sessions and connected iOS device app sessions.`};return Object.freeze({perfFrames:async()=>({metric:r,sampling:r}),perfMemorySample:async({appId:e})=>({metric:e?await T(t().sampleMemory(n,e)):E(`HarmonyOS`,`bundle`),sampling:{method:`hdc-shell-proc-status`,description:`Resident memory snapshot from HarmonyOS /proc/<pid>/status. Values are reported in kilobytes.`,unit:`kB`,topConsumerLimit:1}}),perfMemorySnapshot:async({kind:e})=>({artifact:{available:!1,kind:e??`memgraph`,reason:`Memory snapshot artifacts are not supported on harmonyos.`,hint:`Use perf memory sample where supported, or run the snapshot against Android, iOS simulator, or macOS.`,support:{platform:`harmonyos`,defaultKind:`memgraph`,androidHprof:!1,memgraph:!1,heapprofd:!1}},sampling:{method:`unsupported`,description:`HarmonyOS memory snapshot capture is not available through HDC.`,artifactOnly:!0}})})}const I=Object.freeze({resourceKind:S,version:1,encode:e=>({...e}),decode:e=>e.backend===`harmony-screen-recorder`&&typeof e.fileName==`string`&&Ee(e.fileName)&&e.remotePath===`/data/local/tmp/${e.fileName}`?{status:`decoded`,descriptor:Object.freeze({backend:`harmony-screen-recorder`,fileName:e.fileName,remotePath:e.remotePath})}:{status:`invalid`,message:`Invalid HarmonyOS screen-recording descriptor`}});function we(e){let{device:n,owner:r,input:i,descriptor:a}=e;return v({resourceKind:S,sessionId:i.sessionId,device:t(n),owner:r,fence:i.fence,lifecycle:`open`,descriptor:_(I,a)})}function Te(e){return I.decode(e).status===`decoded`?{status:`cleanup-pending`,reason:`manual-recovery-required`,message:`HarmonyOS recorder ownership cannot be proven after daemon restart; no recorder was stopped.`}:{status:`cleanup-pending`,reason:`manual-recovery-required`}}function Ee(e){return/^agent-device-recording-[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\.mp4$/i.test(e)}function De(e){return e.kind===`device`?Object.freeze({available:!0}):Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`HarmonyOS recording is supported on physical devices only.`})}function Oe(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await ke({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async()=>({status:`unreattachable`,reason:`transport-not-reattachable`,message:`HarmonyOS recordings cannot be reattached after daemon restart.`}),screenRecordingCleanup:async e=>Te(e.envelope.descriptor.body)})}async function ke(t){let{host:n,device:r,owner:i,input:a,signal:o}=t;if(a.scope===`app`)throw new e(`INVALID_ARGS`,`HarmonyOS recording captures the whole physical-device screen; use --scope device or --scope system`);x(a,{scopes:[`device`,`system`],fps:!1,exportQuality:!1,hideTouches:!1},e=>`HarmonyOS recordings do not support ${e.join(`, `)}`),o.throwIfAborted(),await n.screenRecording.outputs.prepare(a.outputPath);let s=`agent-device-recording-${A()}.mp4`,c={backend:`harmony-screen-recorder`,fileName:s,remotePath:`/data/local/tmp/${s}`},l;try{l=await n.screenRecording.harmony.start(r,s,o),o.throwIfAborted()}catch(e){throw o.aborted?(await R(n,r,c).catch(()=>{}),o.reason):e}B(l,`start`);try{o.throwIfAborted()}catch(e){throw await R(n,r,c).catch(()=>{}),e}let u=Ae(a),d=!1,f=async()=>{d||=(B(await n.screenRecording.harmony.stop(r),`stop`),!0)},p=y(u,{finish:async e=>await je(n,r,e,c,f),forceCleanup:async()=>await R(n,r,c,f)});return Object.freeze({pendingHandle:new ve(p),envelope:we({device:r,owner:i,input:a,descriptor:c})})}function Ae(e){return Object.freeze({backend:`HarmonyOS ScreenRecorder`,outPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutPath:e.clientOutputPath},startedAt:Date.now(),scope:e.scope,showTouches:!1,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},gestureEvents:[]})}async function je(e,t,n,r,i){await i();let a=await e.screenRecording.harmony.findMedia(t,r.fileName);if(!a)throw Error(`failed to find finalized HarmonyOS recording '${r.fileName}'`);if(!await Pe(e,t,r,a))throw Error(`failed to finalize HarmonyOS recording: ${r.fileName} did not produce a non-empty media file`);try{if((await e.screenRecording.harmony.pull(t,{remotePath:r.remotePath,outputPath:n.outPath})).exitCode!==0)throw Error(`failed to retrieve HarmonyOS recording`);let i=await e.screenRecording.finalize.complete({outputPath:n.outPath,showTouches:!1,gestureEvents:n.gestureEvents,targetLabel:`HarmonyOS recording`}),o=await Me(e,t,r,a);return b(n,{...i,...Ne(i.warning,o)},!1)}catch(n){throw await e.screenRecording.harmony.remove(t,r.remotePath).catch(()=>{}),n}}async function Me(e,t,n,r){let i=[];return await L(()=>e.screenRecording.harmony.remove(t,n.remotePath))||i.push(`staging artifact`),await L(()=>e.screenRecording.harmony.removeMedia(t,r))||i.push(`media-library artifact`),i.length===0?void 0:`HarmonyOS recording completed, but cleanup was not confirmed for the ${i.join(` and `)}.`}async function L(e){try{return await e()}catch{return!1}}function Ne(e,t){let n=[e,t].filter(e=>e!==void 0).join(` `);return n.length===0?{}:{warning:n}}async function Pe(e,t,n,r){let i;for(let a=0;a<40;a+=1){if(await e.screenRecording.harmony.remove(t,n.remotePath).catch(()=>{}),await e.screenRecording.harmony.stageMedia(t,{mediaUri:r,remotePath:n.remotePath})){let r=await e.screenRecording.harmony.stagedFileSize(t,n.remotePath);if(r!==void 0&&r>0&&r===i)return!0;i=r!==void 0&&r>0?r:void 0}else i=void 0;a<39&&await e.clock.sleep(250)}return!1}async function R(e,t,n,r=async()=>{B(await e.screenRecording.harmony.stop(t),`stop`)}){let i=[await z(r),await z(async()=>{if(!await e.screenRecording.harmony.remove(t,n.remotePath))throw Error(`HarmonyOS recording staging artifact removal was not confirmed`)}),await z(async()=>await Fe(e,t,n.fileName))].find(e=>e!==void 0);return i===void 0?{status:`cleaned`}:{status:`cleanup-pending`,reason:`transport-failed`,message:i instanceof Error?i.message:`HarmonyOS recording cleanup failed`}}async function Fe(e,t,n){let r=await e.screenRecording.harmony.findMedia(t,n);if(r&&!await e.screenRecording.harmony.removeMedia(t,r))throw Error(`HarmonyOS recording media removal was not confirmed`)}async function z(e){try{await e();return}catch(e){return e}}function B(e,t){if(e.exitCode===0&&e.stdout.includes(`start ability successfully`))return;let n=e.stdout.trim()||e.stderr.trim()||`hdc exit ${e.exitCode}`;throw Error(`failed to ${t} HarmonyOS screen recording: ${n}`)}async function Ie(t,n){n.throwIfAborted();let{runHarmonyHdc:r}=await import(`./hdc.js`),i=await r(t,[`shell`,`aa`,`dump`,`-l`],{timeoutMs:15e3,signal:n});n.throwIfAborted();let a=Le(i.stdout);if(!a)throw new e(`COMMAND_FAILED`,`Could not determine the foreground HarmonyOS app`,{hint:`Open an app on the target, then retry appstate.`});return a}function Le(e){let t=e.split(/(?=^\s*Mission ID #)/m);for(let e of t){if(!/\bstate #FOREGROUND\b/.test(e))continue;let t=e.match(/mission name #\[#([^:]+):[^:]*:([^\]]+)]/);if(!t)continue;let[,n,r]=t;if(!(!n||!r))return{package:n,activity:r}}}function Re(e){return k({owner:`HarmonyOS`,openTargetIdentity:`bundle-id`,binding:O({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const ze=Object.freeze({available:!0}),Be=Object.freeze({available:!1,reason:`unsupported-device-kind`}),V=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function H(e){let t=e.kind===`emulator`||e.kind===`device`?ze:Be;return Object.freeze({deployApp:t,materializeAppSource:V,deployMaterializedApp:V,sendPushNotification:V})}function Ve(e){return H(e.device).deployApp.available?Object.freeze({deployApp:async t=>await He(e.commands,e.device,t,e.signal)}):Object.freeze({})}async function He(t,n,r,i){let a=await Ue(t,r.appPath,i)??r.app.trim();if(!a)throw new e(`INVALID_ARGS`,`Could not determine the bundle name from the HAP archive`,{hint:`Pass the HarmonyOS bundle name before the HAP path, or provide a valid HAP containing module.json.`});return await U(t,n,[`install`,`-r`,r.appPath],i,18e4),r.replaceExisting&&(await j(1e3,void 0,{signal:i}),await We(t,n,a,i)),{packageName:a,launchTarget:a}}async function Ue(e,t,n){let r=await e.run({executable:`unzip`,args:[`-p`,t,`module.json`],allowFailure:!0,timeoutMs:15e3},n);if(r.exitCode===0&&r.stdout.trim().length!==0)try{return JSON.parse(r.stdout).app?.bundleName?.trim()||void 0}catch{return}}async function We(t,n,r,i){let a=Ge((await U(t,n,[`shell`,`bm`,`dump`,`-n`,r],i)).stdout);if(!a)throw new e(`COMMAND_FAILED`,`Could not determine a launchable ability for ${r}`,{hint:`Check that the HarmonyOS bundle exposes a main ability.`});await U(t,n,[`shell`,`aa`,`start`,`-b`,r,...a.module?[`-m`,a.module]:[],`-a`,a.ability],i)}function Ge(e){let t=e.indexOf(`{`);if(t!==-1)try{let n=JSON.parse(e.slice(t)).hapModuleInfos?.find(e=>e.mainElementName);return n?.mainElementName?{ability:n.mainElementName,...n.moduleName?{module:n.moduleName}:{}}:void 0}catch{return}}async function U(e,t,n,r,i=15e3){return await e.run({executable:`hdc`,args:[`-t`,t.id,...n],timeoutMs:i},r)}const W=n(`harmonyos`),Ke=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`HarmonyOS reads element text from the captured tree only.`}),qe=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`focus is supported on HarmonyOS emulators and physical devices.`}),G=Object.freeze({available:!0}),K=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Je=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`HarmonyOS appstate is supported only for HarmonyOS emulators and devices.`}),Ye=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple runner preparation is supported only for Apple targets.`}),q=Object.freeze({available:!0}),Xe=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`open is supported only for HarmonyOS emulators and devices.`}),Ze=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`close is supported only for HarmonyOS emulators and devices.`}),Qe=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`}),J=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`snapshot is supported only for HarmonyOS emulators and devices.`}),Y=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`screenshot is supported only for HarmonyOS emulators and devices.`}),$e=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Re-run without --actions, or target an iOS simulator.`}),et=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`viewport resizes web targets only (--platform web).`});function tt(e){let t=nt(e),n=rt(e);return a({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:K,clearRuntimeHints:K,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:Ye,configureProviderPortReverse:Qe})}function nt(e){return e.kind===`emulator`||e.kind===`device`?q:Xe}function rt(e){return e.kind===`emulator`||e.kind===`device`?q:Ze}const it=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Gestures are supported on HarmonyOS emulators and physical devices.`}),at=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),ot=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:C});function X(e){return e.kind===`emulator`||e.kind===`device`?G:it}function Z(e){return e.kind===`emulator`||e.kind===`device`?G:qe}const Q=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),st=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`keyboard status/get is not available through the public HarmonyOS HDC API; use keyboard dismiss or enter`}),$=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`audio is supported for web browser sessions, macOS sessions, iOS simulators, and Android emulators on macOS hosts`});function ct(e){let t=xe(e),n=async e=>{let n=await t.inspectFacts(e),r=H(e),i=De(e);return Object.freeze({device:n.device,operations:{...n.operations,...r,appState:e.kind===`simulator`?Je:G,networkDump:K,screenRecordingStart:i,screenRecordingReattach:i,screenRecordingCleanup:i,...d({capture:e.kind===`emulator`||e.kind===`device`?G:J,customActions:$e,withoutActiveApp:e.kind===`emulator`||e.kind===`device`?G:J}),...u({capture:e.kind===`emulator`||e.kind===`device`?G:Y}),...h({findText:J,findSelector:J}),...p({setViewport:et}),...f({focus:Z(e)}),...ee({plan:X(e),directionalFling:X(e),multiTouch:at,targetAuthoredDrag:ot,viewport:X(e)}),...c({scroll:X(e)}),...l({type:Z(e)}),...o({tap:Z(e),tapRef:K,longPress:Z(e),hover:K,hoverRef:K,fill:Z(e),fillRef:K,tapElementSelector:K}),...pe({readTextAtPoint:Ke}),...me({back:Z(e)}),...ie({home:Z(e)}),...ue({appSwitcher:Z(e)}),...re({triggerAppEvent:Q}),...se({setSetting:Z(e)}),...de({read:Q,wait:Q,accept:Q,dismiss:Q}),...fe({orientation:Q}),...oe({tvRemote:Q}),...le({status:st,dismiss:Z(e),enter:Z(e)}),...ae({read:Q,write:Q}),...ge({capture:$,query:$}),..._e({frames:Z(e),memorySample:Z(e),memorySnapshot:Z(e),nativeCapture:Q,profileReport:Q}),ensureReady:G,bootTarget:K,bootTargetHeadless:K,listApps:G,...tt(e),shutdownTarget:K}})};return Object.freeze({owner:W,ownsDevice:e=>e.platform===`harmonyos`,inspectFacts:n,bind:async a=>{let o=await t.bind(a),c=await n(a.device),l=c.operations.screenRecordingStart;return Object.freeze({device:o.device,owner:W,facts:c,operations:Object.freeze({...o.operations,...Ve({commands:e.commands,device:a.device,signal:a.scope.signal}),...c.operations.appState.available?{appState:async()=>await Ie(a.device,a.scope.signal)}:{},ensureReady:async()=>({...a.device,booted:!0}),...l.available?Oe({host:e,device:a.device,owner:W,signal:a.scope.signal}):{},...c.operations.captureSnapshot.available?he({device:a.device,signal:a.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...c.operations.captureScreenshot.available?ne({device:a.device,signal:a.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...c.operations.focusPoint.available?m({device:a.device,signal:a.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...c.operations.typeText.available?g({device:a.device,signal:a.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...ce({device:a.device,signal:a.scope.signal,facts:c.operations,resolveInteractor:e.localInteractors.resolve}),...c.operations.scrollDirection.available?te({device:a.device,signal:a.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...w({device:a.device,signal:a.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:c.operations}),...r(c.operations.perfFrames,()=>Ce({resolveHost:()=>e.perf.harmony,device:a.device})),...r(c.operations.tapPoint,()=>s({device:a.device,signal:a.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:c.operations,pause:async t=>await e.clock.sleep(t,a.scope.signal)})),listApps:async e=>{a.scope.signal.throwIfAborted();let{listHarmonyApps:t}=await import(`./app-lifecycle2.js`);return(await t(e.device,e.filter,{signal:a.scope.signal})).map(e=>({id:e.package,name:e.name}))},...i(Re({host:e.localInteractors,device:a.device,signal:a.scope.signal}),c.operations)}),[Symbol.asyncDispose]:async()=>await o[Symbol.asyncDispose]()})},shutdown:async()=>await t.shutdown()})}export{ct as createHarmonyPlatformRuntime};
@@ -1 +1 @@
1
- import{_ as e}from"./sdk-contracts.js";import{R as t,at as n,bt as r,it as i,ot as a,wt as o,z as s}from"./sdk-batch-runner.js";function c(e){return t({owner:`Linux`,openTargetIdentity:`app-name`,binding:s({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const l=Object.freeze({available:!0}),u=r(`linux`),d=y(`unsupported-platform-leaf`),f=y(`unsupported-platform-leaf`,`Runtime hints are supported only for local iOS-family simulators and Android devices.`),p=y(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),m=y(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),h=y(`unsupported-device-kind`,`open is supported only for the Linux desktop device.`),g=y(`unsupported-device-kind`,`close is supported only for the Linux desktop device.`);function _(t){return Object.freeze({owner:u,ownsDevice:e=>e.platform===`linux`,inspectFacts:async e=>v(e),bind:async n=>{if(n.intent.kind===`exact-owner`&&!o(n.intent.owner,u))throw new e(`UNSUPPORTED_OPERATION`,`Linux runtime owner identity does not match`);if(n.device.platform!==`linux`)throw new e(`UNSUPPORTED_PLATFORM`,`Linux runtime cannot bind this device`);let r=v(n.device),i=c({host:t.localInteractors,device:n.device,signal:n.scope.signal});return Object.freeze({device:n.device,owner:u,facts:r,operations:Object.freeze(a(i,r.operations)),[Symbol.asyncDispose]:async()=>void 0})},shutdown:async()=>void 0})}function v(e){let t=e.kind===`device`?l:h,r=e.kind===`device`?l:g;return i(e,u,{appLog:d,network:d,readiness:d,lifecycle:n({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:f,clearRuntimeHints:f,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:p,configureProviderPortReverse:m})})}function y(e,t){return Object.freeze(t===void 0?{available:!1,reason:e}:{available:!1,reason:e,hint:t})}export{_ as createLinuxPlatformRuntime};
1
+ import{y as e}from"./sdk-contracts.js";import{Wt as t,Yt as n}from"./sdk-batch.js";import{n as r,t as i}from"./application-lifecycle-runtime.js";import{i as a}from"./touch-runtime.js";import{A as o,D as s,G as c,H as ee,I as l,N as u,V as d,b as f,d as p,w as m,x as h}from"./alert-runtime.js";import{r as g}from"./platform-runtime-unavailable.js";import{i as _}from"./gesture-admission.js";import{t as v}from"./local-interactor-operation-set.js";import{n as y,t as b}from"./application-lifecycle-interaction.js";function x(e){return b({owner:`Linux`,openTargetIdentity:`app-name`,binding:y({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const S=Object.freeze({available:!0}),C=t(`linux`),w=$(`unsupported-platform-leaf`),T=$(`unsupported-device-kind`),E=$(`unsupported-device-kind`,`focus is supported only for the Linux desktop device.`),D=$(`unsupported-device-kind`,`type is supported only for the Linux desktop device.`),O=$(`unsupported-device-kind`,`Gestures are supported only for the Linux desktop device.`),k=$(`unsupported-device-kind`,`scroll is supported only for the Linux desktop device.`),A=$(`unsupported-platform-leaf`),j=$(`unsupported-platform-leaf`),M=$(`unsupported-platform-leaf`,_),N=$(`unsupported-platform-leaf`),P=$(`unsupported-platform-leaf`,`Runtime hints are supported only for local iOS-family simulators and Android devices.`),F=$(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),I=$(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),L=$(`unsupported-device-kind`,`open is supported only for the Linux desktop device.`),R=$(`unsupported-device-kind`,`close is supported only for the Linux desktop device.`),z=$(`unsupported-device-kind`,`snapshot is supported only for the Linux desktop device.`),B=$(`unsupported-device-kind`,`screenshot is supported only for the Linux desktop device.`),V=$(`unsupported-platform-leaf`,`Re-run without --actions, or target an iOS simulator.`),H=$(`unsupported-device-kind`,`back is supported only for the Linux desktop device.`),U=$(`unsupported-device-kind`,`home is supported only for the Linux desktop device.`),W=$(`unsupported-device-kind`,`clipboard is supported only for the Linux desktop device.`),G=w,K=$(`unsupported-platform-leaf`,`audio is supported for web browser sessions, macOS sessions, iOS simulators, and Android emulators on macOS hosts`);function q(t){return Object.freeze({owner:C,ownsDevice:e=>e.platform===`linux`,inspectFacts:async e=>Y(e),bind:async i=>{if(i.intent.kind===`exact-owner`&&!n(i.intent.owner,C))throw new e(`UNSUPPORTED_OPERATION`,`Linux runtime owner identity does not match`);if(i.device.platform!==`linux`)throw new e(`UNSUPPORTED_PLATFORM`,`Linux runtime cannot bind this device`);let a=Y(i.device),o=x({host:t.localInteractors,device:i.device,signal:i.scope.signal});return Object.freeze({device:i.device,owner:C,facts:a,operations:Object.freeze({...r(o,a.operations),...a.operations.captureSnapshot.available?Q(t,i):{},...J(t,i,a)}),[Symbol.asyncDispose]:async()=>void 0})},shutdown:async()=>void 0})}function J(e,t,n){let r={device:t.device,signal:t.scope.signal,resolveInteractor:e.localInteractors.resolve};return v({...r,facts:n.operations,pause:async n=>await e.clock.sleep(n,t.scope.signal)})}function Y(e){let t=e.kind===`device`?S:L,n=e.kind===`device`?S:R,r=g(e,C,{appLog:w,network:w,screenshot:B,snapshot:z,viewport:w,focus:E,gesture:O,scroll:k,typeText:D,touch:E,elementText:T,back:H,home:U,orientation:G,tvRemote:G,readClipboard:W,writeClipboard:W,appSwitcher:G,triggerAppEvent:G,setSetting:G,readAlert:G,awaitAlert:G,acceptAlert:G,dismissAlert:G,keyboardStatus:G,keyboardDismiss:G,keyboardEnter:G,audioProbeCapture:K,audioProbeQuery:K,perf:G,readiness:w,lifecycle:i({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:P,clearRuntimeHints:P,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:F,configureProviderPortReverse:I})});return Object.freeze({device:r.device,operations:{...r.operations,...ee({capture:X(e,z),customActions:V,withoutActiveApp:X(e,z)}),...c({capture:X(e,B)}),...l({focus:X(e,E)}),...u({plan:X(e,O),directionalFling:A,multiTouch:j,targetAuthoredDrag:M,viewport:N}),...o({scroll:X(e,k)}),...s({type:X(e,D)}),...Z(e),...m({readTextAtPoint:X(e,T)}),...h({back:X(e,H)}),...f({home:X(e,U)}),...p({read:X(e,W),write:X(e,W)})}})}function X(e,t){return e.kind===`device`?S:t}function Z(e){let t=e.kind===`device`?S:E;return a({tap:t,tapRef:w,longPress:t,hover:w,hoverRef:w,fill:t,fillRef:w,tapElementSelector:w})}function Q(e,t){let n=async n=>await e.snapshot.captureSurface(t.device,n.options,d(t.scope.signal,n));return Object.freeze({captureSnapshot:n,captureSnapshotWithCustomActions:n,captureSnapshotWithoutActiveApp:n})}function $(e,t){return Object.freeze(t===void 0?{available:!1,reason:e}:{available:!1,reason:e,hint:t})}export{q as createLinuxPlatformRuntime};