agent-device 0.21.19 → 0.21.21

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 (369) hide show
  1. package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.19.apk → agent-device-android-ime-helper-0.21.21.apk} +0 -0
  2. package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.21.apk.sha256 +1 -0
  3. package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.19.manifest.json → agent-device-android-ime-helper-0.21.21.manifest.json} +4 -4
  4. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.21.apk +0 -0
  5. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.21.apk.sha256 +1 -0
  6. package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.19.manifest.json → agent-device-android-snapshot-helper-0.21.21.manifest.json} +6 -6
  7. package/apple/macos-helper/Sources/AgentDeviceMacOSHelper/AppWindowScreenshot.swift +73 -0
  8. package/apple/macos-helper/Sources/AgentDeviceMacOSHelper/BackgroundInteraction.swift +557 -0
  9. package/apple/macos-helper/Sources/AgentDeviceMacOSHelper/GhostCursor.swift +141 -0
  10. package/apple/macos-helper/Sources/AgentDeviceMacOSHelper/SnapshotTraversal.swift +107 -3
  11. package/apple/macos-helper/Sources/AgentDeviceMacOSHelper/main.swift +136 -22
  12. package/apple/macos-helper/Tests/AgentDeviceMacOSHelperTests/BackgroundInteractionTests.swift +88 -0
  13. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerApp.m +133 -4
  14. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.h +10 -2
  15. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.m +36 -9
  16. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Alert.swift +28 -0
  17. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandJournal.swift +1 -14
  18. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +14 -16
  19. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +67 -14
  20. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedCommitDeadline.swift +6 -1
  21. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedGesturePolicy.swift +7 -2
  22. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedInteraction.swift +21 -7
  23. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedTextEntry.swift +121 -17
  24. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntry.swift +179 -6
  25. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryConfirmation.swift +119 -0
  26. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryFocus.swift +8 -1
  27. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryReadiness.swift +23 -11
  28. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextInputProbe.swift +59 -6
  29. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextTyping.swift +112 -23
  30. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TypeExecution.swift +25 -12
  31. package/dist/apple/runner/AgentDeviceRunner/RecordingScripts/RecordingExportSupport.swift +6 -1
  32. package/dist/apple/runner/AgentDeviceRunner/RecordingScripts/recording-overlay.swift +43 -13
  33. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotModels.swift +20 -5
  34. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotPresentationProjection.swift +2 -15
  35. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotVisibilityFold.swift +10 -25
  36. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotVisibilityFoldProjection.swift +1 -18
  37. package/dist/src/adapter.js +1 -1
  38. package/dist/src/adb-executor.js +2 -2
  39. package/dist/src/adb-failure.js +1 -1
  40. package/dist/src/adb-transport.js +1 -1
  41. package/dist/src/agent-browser-lifecycle.js +1 -1
  42. package/dist/src/agent-browser-process-record.js +1 -1
  43. package/dist/src/agent-browser-provider.js +1 -1
  44. package/dist/src/agent-browser-tool.js +1 -1
  45. package/dist/src/agent-device-client.js +2 -2
  46. package/dist/src/ai-sdk.js +1 -1
  47. package/dist/src/alert-runtime.js +1 -1
  48. package/dist/src/alert.js +1 -0
  49. package/dist/src/android-adb.d.ts +12 -0
  50. package/dist/src/android-input-ownership.js +1 -1
  51. package/dist/src/app-backend.js +1 -0
  52. package/dist/src/app-catalog.js +1 -1
  53. package/dist/src/app-deployment-resolution.js +1 -1
  54. package/dist/src/app-inventory.js +1 -1
  55. package/dist/src/app-launch.js +2 -2
  56. package/dist/src/app-lifecycle.js +2 -2
  57. package/dist/src/app-lifecycle2.js +1 -1
  58. package/dist/src/app-log-files.js +1 -1
  59. package/dist/src/app-log-reconnect.js +1 -1
  60. package/dist/src/app-log-runtime2.js +3 -3
  61. package/dist/src/app-log-session-resource.js +1 -0
  62. package/dist/src/app-resolution.js +2 -2
  63. package/dist/src/apple-runner-platform.js +1 -1
  64. package/dist/src/application-lifecycle-interaction.js +1 -1
  65. package/dist/src/archive.js +2 -2
  66. package/dist/src/artifact-download.js +1 -1
  67. package/dist/src/auth-session.js +1 -1
  68. package/dist/src/auth.js +1 -1
  69. package/dist/src/back-mode.js +1 -1
  70. package/dist/src/backend-snapshot-options.js +1 -1
  71. package/dist/src/boot-diagnostics.js +1 -1
  72. package/dist/src/browser-launch.js +1 -1
  73. package/dist/src/cache.js +1 -1
  74. package/dist/src/capabilities.js +1 -1
  75. package/dist/src/capture.js +1 -1
  76. package/dist/src/cli-config.js +1 -1
  77. package/dist/src/cli-help.js +317 -323
  78. package/dist/src/cli-runner.js +1 -1
  79. package/dist/src/cli.js +4 -4
  80. package/dist/src/click-button.js +1 -1
  81. package/dist/src/client-metro-companion.js +1 -1
  82. package/dist/src/client-metro.js +1 -1
  83. package/dist/src/client-options.js +3 -0
  84. package/dist/src/client-types.d.ts +101 -6
  85. package/dist/src/clipboard-shell-response.js +1 -1
  86. package/dist/src/{scroll-command.d.ts → cloud-artifacts.d.ts} +249 -240
  87. package/dist/src/code-signature-cache.js +1 -1
  88. package/dist/src/code-signature.js +1 -1
  89. package/dist/src/command-schema.js +3 -3
  90. package/dist/src/command-tools.js +2 -2
  91. package/dist/src/command.js +1 -1
  92. package/dist/src/config.js +1 -1
  93. package/dist/src/connection-runtime.js +1 -1
  94. package/dist/src/connection.js +5 -5
  95. package/dist/src/contracts.d.ts +1 -1
  96. package/dist/src/contracts.js +1 -1
  97. package/dist/src/daemon-artifacts.js +1 -0
  98. package/dist/src/daemon-client-lease-beat.js +1 -1
  99. package/dist/src/daemon-client-lifecycle.js +1 -1
  100. package/dist/src/daemon-client-liveness-probe.js +1 -0
  101. package/dist/src/daemon-client-transport.js +1 -1
  102. package/dist/src/daemon-http.js +1 -0
  103. package/dist/src/daemon-policy-file.js +1 -1
  104. package/dist/src/daemon-registration-owner.js +1 -0
  105. package/dist/src/daemon-registration.js +1 -1
  106. package/dist/src/daemon-resolution.js +1 -1
  107. package/dist/src/daemon-shutdown-report.js +1 -1
  108. package/dist/src/daemon.js +2 -2
  109. package/dist/src/debug-symbols-facade.js +3 -3
  110. package/dist/src/device-claim-inspection.js +1 -1
  111. package/dist/src/device-claim-rule.js +1 -1
  112. package/dist/src/device-inventory-context.js +1 -1
  113. package/dist/src/device-readiness-runtime.js +1 -1
  114. package/dist/src/device-release.js +1 -1
  115. package/dist/src/device-rotation.js +1 -1
  116. package/dist/src/device-selection-resolver.js +1 -1
  117. package/dist/src/device-session.js +1 -1
  118. package/dist/src/device-shell.js +1 -1
  119. package/dist/src/device.js +1 -1
  120. package/dist/src/device2.js +1 -3
  121. package/dist/src/device3.js +3 -0
  122. package/dist/src/devicectl.js +1 -1
  123. package/dist/src/diagnostics.js +3 -3
  124. package/dist/src/dispatch-resolve.js +4 -1
  125. package/dist/src/display-inventory.js +1 -1
  126. package/dist/src/doctor-facade.js +1 -1
  127. package/dist/src/doctor2.js +1 -1
  128. package/dist/src/durable-capture-resource.js +1 -0
  129. package/dist/src/engine-eval-script.js +1 -1
  130. package/dist/src/error.js +1 -1
  131. package/dist/src/exec.js +1 -1
  132. package/dist/src/file.js +1 -1
  133. package/dist/src/find.js +1 -1
  134. package/dist/src/generic-settle.js +1 -1
  135. package/dist/src/generic.js +1 -1
  136. package/dist/src/gesture-admission.js +1 -1
  137. package/dist/src/gesture-plan.js +1 -1
  138. package/dist/src/gesture-runtime.js +1 -1
  139. package/dist/src/harmonyos.js +1 -1
  140. package/dist/src/hdc.js +1 -1
  141. package/dist/src/helper.js +2 -2
  142. package/dist/src/host-file.js +1 -1
  143. package/dist/src/host.js +1 -1
  144. package/dist/src/human-control-contract.js +1 -1
  145. package/dist/src/human-control.js +1 -1
  146. package/dist/src/index.d.ts +2 -2
  147. package/dist/src/index.js +1 -1
  148. package/dist/src/input-actions.js +1 -1
  149. package/dist/src/input-actions2.js +2 -2
  150. package/dist/src/install-artifact-facade.js +1 -1
  151. package/dist/src/install-source-network-transport.js +1 -1
  152. package/dist/src/install-source.d.ts +5 -0
  153. package/dist/src/install-source2.js +1 -1
  154. package/dist/src/instance-client.js +1 -0
  155. package/dist/src/interaction-positionals.js +1 -1
  156. package/dist/src/interaction-ref-policy.js +1 -1
  157. package/dist/src/interaction.js +1 -1
  158. package/dist/src/interaction2.js +1 -1
  159. package/dist/src/interactor-operation-binding.js +1 -1
  160. package/dist/src/interactor.js +5 -5
  161. package/dist/src/interactor2.js +1 -1
  162. package/dist/src/interactors.js +1 -1
  163. package/dist/src/internal/bin.js +1 -1
  164. package/dist/src/internal/daemon.js +1 -2
  165. package/dist/src/internal/png-worker.js +1 -1
  166. package/dist/src/internal/run-script-http-child.js +1 -1
  167. package/dist/src/inventory.js +4 -4
  168. package/dist/src/inventory2.js +1 -1
  169. package/dist/src/inventory3.js +1 -1
  170. package/dist/src/inventory5.js +1 -1
  171. package/dist/src/ios-client.js +4 -30
  172. package/dist/src/ios-settings.js +1 -0
  173. package/dist/src/ios-snapshot-engine.js +1 -1
  174. package/dist/src/ios-snapshot-runtime.js +1 -1
  175. package/dist/src/launch-confirmation.js +1 -0
  176. package/dist/src/lease-context.js +1 -1
  177. package/dist/src/lease-registry-scope.js +1 -0
  178. package/dist/src/lease-scope.js +1 -1
  179. package/dist/src/lease.js +1 -1
  180. package/dist/src/legacy-xctest-device-set.js +1 -1
  181. package/dist/src/limrun-download-file.js +1 -1
  182. package/dist/src/limrun-runtime-dependencies.js +1 -1
  183. package/dist/src/limrun.d.ts +78 -44
  184. package/dist/src/limrun.js +1 -1
  185. package/dist/src/linux.js +1 -1
  186. package/dist/src/load.js +1 -0
  187. package/dist/src/location-coordinates.js +1 -1
  188. package/dist/src/macos-facade.js +1 -1
  189. package/dist/src/managed-device-scope.js +1 -1
  190. package/dist/src/mechanics.js +16 -16
  191. package/dist/src/observation.js +1 -1
  192. package/dist/src/observe-until.js +1 -1
  193. package/dist/src/overlay.js +2 -2
  194. package/dist/src/owner-identity.js +3 -3
  195. package/dist/src/path-resolution.js +1 -1
  196. package/dist/src/perf-facade.js +1 -1
  197. package/dist/src/perf-runtime-operation-builder.js +1 -1
  198. package/dist/src/perf-runtime-plan.js +1 -1
  199. package/dist/src/perf-target.js +1 -1
  200. package/dist/src/perf.js +1 -1
  201. package/dist/src/physical-device-control.js +1 -1
  202. package/dist/src/platform-request-scope.js +1 -1
  203. package/dist/src/platform-runtime-android-adb-host.js +1 -1
  204. package/dist/src/platform-runtime-app-log-process.js +1 -1
  205. package/dist/src/platform-runtime-host.js +1 -1
  206. package/dist/src/platform-runtime-managed-owner.js +1 -1
  207. package/dist/src/platform-runtime-open-target.js +1 -1
  208. package/dist/src/platform-runtime-operation-host.js +2 -2
  209. package/dist/src/platform-runtime-runtime-hints.js +2 -2
  210. package/dist/src/platform-runtime-screen-recording-android-host.js +1 -1
  211. package/dist/src/platform-runtime-screen-recording-apple-runner-transport.js +1 -1
  212. package/dist/src/platform-runtime-screen-recording-apple-simulator-host.js +1 -1
  213. package/dist/src/platform-runtime-screen-recording-finalizer-host.js +1 -1
  214. package/dist/src/platform-runtime-screen-recording-output-host.js +1 -1
  215. package/dist/src/platform-runtime-screen-recording-process-host.js +1 -1
  216. package/dist/src/platform-runtime-unavailable.js +1 -1
  217. package/dist/src/platform-runtime.js +1 -1
  218. package/dist/src/platform-runtime2.js +1 -1
  219. package/dist/src/plugins.d.ts +9 -0
  220. package/dist/src/plugins.js +1 -0
  221. package/dist/src/plugins2.js +2 -0
  222. package/dist/src/png-crop-bytes.js +1 -1
  223. package/dist/src/png-size.js +1 -1
  224. package/dist/src/png-worker-client.js +1 -1
  225. package/dist/src/png.js +1 -1
  226. package/dist/src/prepare-kind.js +1 -1
  227. package/dist/src/process.js +1 -1
  228. package/dist/src/project-runtime.js +1 -1
  229. package/dist/src/provider-credential-fingerprint.js +1 -0
  230. package/dist/src/provider-device-admission.js +1 -1
  231. package/dist/src/provider-device-runtimes.js +1 -0
  232. package/dist/src/provider-limrun-credentials.js +1 -0
  233. package/dist/src/provider-profile-fields.js +1 -0
  234. package/dist/src/provider-session-ownership.js +2 -2
  235. package/dist/src/provider-webdriver.js +2 -1
  236. package/dist/src/providers.js +1 -1
  237. package/dist/src/proxy.js +1 -1
  238. package/dist/src/quality-warnings.js +1 -1
  239. package/dist/src/react-native.js +1 -1
  240. package/dist/src/record-runtime.js +1 -1
  241. package/dist/src/record-trace.js +1 -1
  242. package/dist/src/recording.js +1 -1
  243. package/dist/src/rect-center.js +1 -1
  244. package/dist/src/register-builtins.js +1 -1
  245. package/dist/src/registry.js +52 -36
  246. package/dist/src/remote-config2.js +1 -1
  247. package/dist/src/replay-divergence.js +1 -1
  248. package/dist/src/replay.js +2 -2
  249. package/dist/src/reporting.js +5 -5
  250. package/dist/src/request-admission.js +1 -1
  251. package/dist/src/request-cancel.js +1 -1
  252. package/dist/src/request-cancellation.js +1 -1
  253. package/dist/src/request-runtime-binding.js +1 -1
  254. package/dist/src/result-serialization.js +1 -1
  255. package/dist/src/retry.js +1 -1
  256. package/dist/src/runner-artifact-manifest.js +1 -1
  257. package/dist/src/runner-cache-metadata.js +3 -3
  258. package/dist/src/runner-client.js +1 -1
  259. package/dist/src/runner-dev-tools-security.js +1 -1
  260. package/dist/src/runner-device-readiness.js +1 -1
  261. package/dist/src/runner-disposal.js +1 -1
  262. package/dist/src/runner-error-classification.js +2 -2
  263. package/dist/src/runner-exchange.js +1 -1
  264. package/dist/src/runner-operations-facade.js +1 -1
  265. package/dist/src/runner-session-types.js +1 -1
  266. package/dist/src/runner-start-budget.js +1 -1
  267. package/dist/src/runner.js +1 -1
  268. package/dist/src/runtime-admission.js +1 -1
  269. package/dist/src/runtime-transport-hints.js +1 -1
  270. package/dist/src/runtime.js +1 -1
  271. package/dist/src/runtime10.js +2 -2
  272. package/dist/src/runtime2.js +3 -3
  273. package/dist/src/runtime3.js +1 -1
  274. package/dist/src/runtime4.js +5 -5
  275. package/dist/src/runtime5.js +1 -1
  276. package/dist/src/runtime6.js +1 -1
  277. package/dist/src/runtime7.js +1 -1
  278. package/dist/src/runtime8.js +1 -1
  279. package/dist/src/runtime9.js +1 -1
  280. package/dist/src/screen-recording-admission-ledger.js +1 -1
  281. package/dist/src/screen-recording-completion.js +1 -1
  282. package/dist/src/screen-recording-options.js +1 -1
  283. package/dist/src/screen-recording-resource-recovery.js +1 -1
  284. package/dist/src/screen-recording-transport.js +1 -1
  285. package/dist/src/screenshot-density.js +1 -1
  286. package/dist/src/screenshot-image.js +1 -1
  287. package/dist/src/screenshot-result.js +1 -1
  288. package/dist/src/screenshot-runtime.js +1 -1
  289. package/dist/src/screenshot.js +1 -1
  290. package/dist/src/screenshot3.js +1 -1
  291. package/dist/src/script.js +1 -1
  292. package/dist/src/scroll-command.js +1 -1
  293. package/dist/src/scroll-gesture.js +1 -1
  294. package/dist/src/sdk-batch-runner.js +2 -2
  295. package/dist/src/sdk-batch.js +2 -2
  296. package/dist/src/sdk-contracts.d.ts +47 -2
  297. package/dist/src/sdk-contracts.js +2 -2
  298. package/dist/src/sdk-device.js +1 -1
  299. package/dist/src/sdk-io.js +1 -1
  300. package/dist/src/sdk-remote-config.js +1 -1
  301. package/dist/src/sdk-selectors.d.ts +37 -8
  302. package/dist/src/selection.js +0 -0
  303. package/dist/src/selector-runtime.js +1 -1
  304. package/dist/src/selectors.d.ts +2 -2
  305. package/dist/src/selectors.js +1 -1
  306. package/dist/src/server.js +1 -1
  307. package/dist/src/session-allocation.js +1 -1
  308. package/dist/src/session-artifact-paths.js +1 -1
  309. package/dist/src/session-repair-tombstone.js +1 -1
  310. package/dist/src/session-routing.js +1 -1
  311. package/dist/src/session-runtime-admission.js +1 -1
  312. package/dist/src/session-snapshot.js +1 -1
  313. package/dist/src/session-stream.js +27 -0
  314. package/dist/src/session.js +1 -1
  315. package/dist/src/session2.js +5 -5
  316. package/dist/src/settings.js +1 -1
  317. package/dist/src/settings2.js +1 -1
  318. package/dist/src/simctl-settings-facade.js +1 -0
  319. package/dist/src/simctl-settings.js +1 -0
  320. package/dist/src/simctl.js +1 -1
  321. package/dist/src/simulator-boot.js +1 -1
  322. package/dist/src/simulator.js +1 -1
  323. package/dist/src/snapshot-diagnostics.js +1 -1
  324. package/dist/src/snapshot-runtime-binding.js +1 -1
  325. package/dist/src/snapshot-runtime.js +1 -1
  326. package/dist/src/snapshot-state.js +1 -1
  327. package/dist/src/snapshot2.js +1 -1
  328. package/dist/src/snapshot3.js +1 -1
  329. package/dist/src/snapshot4.js +1 -1
  330. package/dist/src/src.js +1 -1
  331. package/dist/src/src7.js +1 -1
  332. package/dist/src/src8.js +2 -2
  333. package/dist/src/store.js +1 -0
  334. package/dist/src/string-enum.js +1 -1
  335. package/dist/src/surface-snapshot.js +1 -1
  336. package/dist/src/takeover.js +1 -1
  337. package/dist/src/target-evidence.js +1 -1
  338. package/dist/src/telemetry.js +1 -1
  339. package/dist/src/text-entry-focus.js +1 -1
  340. package/dist/src/tool-provider.js +3 -3
  341. package/dist/src/tool-provider2.js +1 -1
  342. package/dist/src/tool-provider3.js +1 -1
  343. package/dist/src/toolchain-probe.js +2 -2
  344. package/dist/src/touch-runtime.js +1 -1
  345. package/dist/src/touch-runtime2.js +1 -1
  346. package/dist/src/transport.js +2 -2
  347. package/dist/src/tv-remote.js +1 -1
  348. package/dist/src/type-text-runtime.js +1 -1
  349. package/dist/src/update-check.js +1 -1
  350. package/dist/src/vars.js +1 -1
  351. package/dist/src/verified-file.js +1 -1
  352. package/dist/src/version.js +1 -1
  353. package/dist/src/video.js +1 -1
  354. package/dist/src/viewport.js +1 -1
  355. package/dist/src/web.js +1 -1
  356. package/dist/src/web2.js +1 -1
  357. package/dist/src/webdriver-source.js +1 -1
  358. package/package.json +5 -1
  359. package/server.json +2 -2
  360. package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.19.apk.sha256 +0 -1
  361. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.19.apk +0 -0
  362. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.19.apk.sha256 +0 -1
  363. package/dist/src/api.js +0 -3
  364. package/dist/src/daemon-process.js +0 -1
  365. package/dist/src/multitouch-support.js +0 -1
  366. package/dist/src/parameterized-recorded-fill.js +0 -1
  367. package/dist/src/runner-startup-transport.js +0 -1
  368. package/dist/src/runner-xctestrun.js +0 -1
  369. package/dist/src/session-store.js +0 -4
@@ -1,5 +1,5 @@
1
- import{F as e,G as t,N as n,P as r}from"./sdk-contracts.js";import{_ as i,i as a}from"./sdk-batch-runner.js";import{A as o,D as s,c,d as l,f as u,m as d,p as f,y as p}from"./sdk-device.js";import{Xt as m,nn as h,rn as ee,tn as te}from"./sdk-batch.js";import{r as ne}from"./session.js";import"./device.js";import{a as re,l as g}from"./device-rotation.js";import{c as ie,r as ae}from"./diagnostics.js";import{a as oe,n as _}from"./exec.js";import"./diagnostics2.js";import"./command.js";import{r as se}from"./version.js";import{n as ce}from"./scoped-provider.js";import{i as le,n as ue,r as de}from"./ios-snapshot-planning.js";import{t as fe}from"./request.js";import{n as pe,r as me,t as he}from"./application-lifecycle-runtime.js";import{A as ge,B as _e,C as ve,D as ye,E as be,G as xe,H as Se,I as Ce,J as we,K as Te,L as Ee,N as De,O as Oe,P as ke,V as Ae,W as je,d as Me,h as Ne,j as Pe,n as Fe,o as Ie,s as Le,v as Re,w as ze,x as Be,z as Ve}from"./alert-runtime.js";import{n as He}from"./audio-probe-runtime.js";import{n as Ue}from"./perf-runtime.js";import{i as We,t as Ge}from"./touch-runtime.js";import{a as Ke,n as qe}from"./durable-resource.js";import{n as Je,t as Ye}from"./async-lifecycle.js";import{a as Xe,c as Ze,d as Qe,f as $e,l as et,n as tt,o as nt,s as rt,t as it,u as at}from"./src7.js";import{n as ot,t as st}from"./screen-recording-completion.js";import{a as ct,c as lt,i as ut,n as dt,o as ft,r as pt,s as mt,t as ht}from"./device-readiness-runtime.js";import{n as gt}from"./screen-recording-runtime.js";import{t as _t}from"./ios-system-surface.js";import{i as vt,r as yt}from"./gesture-admission.js";import{t as bt}from"./interactor-operation-catalog.js";import{a as xt,i as St,n as Ct,r as wt,t as Tt}from"./perf-runtime-operation-builder.js";import{t as Et}from"./app-log-runtime.js";import{n as Dt}from"./artifact-paths.js";import{i as Ot,r as kt}from"./managed-device-scope.js";import{a as At,n as jt,o as Mt}from"./application-lifecycle-interaction.js";import{f as Nt}from"./host-file.js";import{a as Pt,o as Ft,s as It}from"./config.js";import{a as Lt,o as Rt}from"./tool-provider.js";import{o as zt}from"./devicectl.js";import{t as Bt}from"./physical-device-apps.js";import{t as Vt}from"./apple-runner-platform.js";import{a as Ht,i as Ut,l as Wt,n as Gt,o as v,s as Kt}from"./simctl.js";import{a as qt,r as Jt}from"./simulator.js";import{r as Yt}from"./display-inventory.js";import{t as Xt}from"./multitouch-support.js";import{t as Zt}from"./simulator-state.js";import{a as Qt,c as $t,d as en,i as tn,l as nn,n as rn,o as an,r as on,t as sn,u as cn}from"./cache.js";import y from"node:path";import{randomUUID as ln}from"node:crypto";function un(e){let t=Ot();return Object.freeze(t?{...ce({...e},e=>qt(t,e))}:e)}function dn(e,t){return Object.freeze({appState:async n=>{if(t.signal.throwIfAborted(),!await e.appleApplications.hasLiveRunnerSession(t.device,{}))return{};let r=await t.resolveInteractor(t.device,{appBundleId:n?.appBundleId,signal:t.signal});if(typeof r.appState!=`function`)throw ee(`Runtime owner advertised appState without an interactor implementation`);return await r.appState()}})}function fn(e){return ft(e)?Object.freeze({available:!0}):d(e)||f(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 pn(e){let{resolveHost:t,device:n,owner:r}=e;return Object.freeze({...Tt({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 St(t().sampleFrames(n,e)):Ct(`Apple`,`bundle ID`),sampling:await t().frameSampling(n)}),perfMemorySample:async({appId:e})=>({metric:e?await St(t().sampleMemory(n,e)):Ct(`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 xt(`Apple`,o,s,`Use perf memory snapshot --kind memgraph for supported Apple app sessions.`);if(!e)throw wt();let c=i??y.join(a,`memory-memgraph-${mn()}.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 mn(){return new Date().toISOString().replaceAll(/[:.]/g,`-`)}const b=Object.freeze({available:!0}),x=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),S=vn(`Gestures are supported only for Apple simulators and devices.`),hn=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:yt}),gn=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:vt}),_n=vn(`scroll is supported only for Apple simulators and devices.`);function vn(e){return Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:e})}function yn(e){return{...Ce({unsupported:bn(e),plan:xn(e),directionalFling:xn(e),multiTouch:Sn(e),targetAuthoredDrag:Cn(e),viewport:wn(e)}),...De({scroll:Tn(e)})}}function bn(e){return e.appleOs===`watchos`||e.appleOs===`visionos`?x:S}function xn(e){return e.appleOs===`watchos`||e.appleOs===`visionos`?x:C(e)?b:S}function Sn(e){if(e.appleOs===`watchos`)return x;if(!C(e))return S;let t=s(e);if(t!==`ios`&&t!==`ipados`){let e=Xt[t];return Object.freeze({available:!1,reason:`unsupported-platform-leaf`,...e===void 0?{}:{hint:e}})}return e.kind===`simulator`?b:hn}function Cn(e){return C(e)?(e.appleOs===void 0?e.target!==`desktop`&&e.target!==`tv`:e.appleOs===`ios`||e.appleOs===`ipados`)?b:gn:S}function wn(e){return e.appleOs===`watchos`?x:C(e)?b:S}function Tn(e){return C(e)?b:_n}function C(e){return e.kind===`simulator`||e.kind===`device`}const w=`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`;function T(e){return d(e)?`macos`:e.kind===`device`?`ios-device`:`ios-simulator`}const En=Object.freeze({resourceKind:Et,version:1,encode:e=>({...e}),decode:e=>!On(e.transport)||!kn(e.backend)||!Nn(e.outputPath)||!jn(e.pidPath)||!An(e.transport,e.backend)?Dn():{status:`decoded`,descriptor:Object.freeze({transport:e.transport,backend:e.backend,outputPath:e.outputPath,...e.pidPath===void 0?{}:{pidPath:e.pidPath}})}});function Dn(){return{status:`invalid`,message:`Invalid Apple app-log descriptor`}}function On(e){return e===`apple-log-stream`||e===`coredevice-console`}function kn(e){return e===`ios-simulator`||e===`ios-device`||e===`macos`}function An(e,t){return e===`coredevice-console`?t===`ios-device`:t!==`ios-device`}function jn(e){return e===void 0||Nn(e)}function Mn(e){if(!e.device.appleOs)throw TypeError(`Apple app-log persistence requires an explicit appleOs identity`);return qe({resourceKind:Et,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:Ke(En,e.descriptor)})}function Nn(e){return typeof e==`string`&&e.trim().length>0}const Pn={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.`},Fn={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 In(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 Ln(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(d(t))i.logAvailable=!!await e.commands.which(`log`);else if(t.kind===`simulator`)i.simctlAvailable=await lt(async()=>mt(await e.appleTools.run({tool:`simctl`,args:Kt(),allowFailure:!0},r)),r);else if(t.iosPhysicalDeviceBackend===`xctest`)i.devicectlAvailable=!1,i.devicectlConsoleCapture=!1,a.push(w);else{i.devicectlAvailable=await lt(async()=>mt(await e.appleTools.run({tool:`devicectl`,args:[`--version`],allowFailure:!0},r)),r);let t=await In(e,r);if(i.devicectlConsoleCapture=t.supported,!t.supported){let e=t.reason===`unsupported`?Pn:Fn;a.push(`${e.message} ${e.hint}`)}}return{backend:T(t),checks:i,notes:a}}function Rn(e,t){let n=Vn(e),r=[`subsystem == "${n}"`,`subsystem CONTAINS "${n}"`,`processImagePath ENDSWITH[c] "/${n}"`,`senderImagePath ENDSWITH[c] "/${n}"`];if(t){let e=Vn(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 zn(e,t){return Gt(e,[`spawn`,e.id,`log`,`stream`,`--style`,`compact`,`--level`,`info`,`--predicate`,Rn(t.appBundleId,t.executableName)])}function Bn(e,t){return[`devicectl`,`device`,`process`,`launch`,`--device`,e,`--console`,`--terminate-existing`,t]}function Vn(e){return e.replaceAll(`\\`,String.raw`\\`).replaceAll(`"`,String.raw`\"`)}async function Hn(e,t,n,r,i){Un(t),nt(e,n);let a=T(t),o=await Gn(e,t,n.appBundleId,i),s=new Ye,c=!1;try{let l=await e.outputs.openAppend(n.outputPath);s.defer(async()=>{c||await l[Symbol.asyncDispose]()}),i?.throwIfAborted();let u=await Wn(e,t,o,l,n.pidPath,i);s.defer(async()=>{c||await u[Symbol.asyncDispose]()});let d=qn(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=$e(d,Mn({sessionId:n.sessionId,device:t,owner:r,fence:n.fence,descriptor:f}));return c=!0,p}finally{await s[Symbol.asyncDispose]()}}function Un(e){if(e.appleOs===`watchos`)throw new n(`UNSUPPORTED_PLATFORM`,`watchOS app logs are not supported`);if(f(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`)throw new n(`UNSUPPORTED_OPERATION`,w,{hint:w})}async function Wn(e,t,r,i,a,o){if(f(t)&&t.kind===`device`){let t=await In(e,o);if(!t.supported){let e=t.reason===`unsupported`?Pn:Fn;throw new n(t.reason===`unsupported`?`UNSUPPORTED_OPERATION`:`COMMAND_FAILED`,e.message,{backend:`ios-device`,hint:e.hint,stderr:t.stderr})}}return o?.throwIfAborted(),await e.processes.start({command:{kind:`host`,request:r},output:i,...a?{markerPath:a}:{}})}async function Gn(e,t,n,r){return d(t)?{executable:`log`,args:[`stream`,`--style`,`compact`,`--predicate`,Rn(n)],allowFailure:!0}:t.kind===`device`?{executable:`xcrun`,args:Bn(t.id,n),allowFailure:!0}:{executable:`xcrun`,args:zn(t,{appBundleId:n,executableName:await Kn(e,t,n,r)}),allowFailure:!0}}async function Kn(e,t,n,r){let i=await e.appleTools.run({tool:`simctl`,args:v(t,[`get_app_container`,t.id,n,`app`]),allowFailure:!0,timeoutMs:4e3},r),a=i.exitCode===0?i.stdout.trim():``;if(!a)return;let o=await e.commands.run({executable:`plutil`,args:[`-extract`,`CFBundleExecutable`,`raw`,`-o`,`-`,y.join(a,`Info.plist`)],allowFailure:!0,timeoutMs:4e3},r);return o.exitCode===0&&o.stdout.trim()||void 0}function qn(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 at({inspect:()=>({backend:r,state:o,startedAt:a}),finish:async()=>s??=(async()=>(await Jn([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 Jn(e){let t=[];for(let n of e)try{await n()}catch(e){t.push(e)}return t}const E=m(`apple`),D=Object.freeze({available:!0});function Yn(e){return Object.freeze({owner:E,ownsDevice:e=>e.platform===`apple`,inspectFacts:async e=>Zn(e),bind:async t=>{if(t.intent.kind===`exact-owner`&&!te(t.intent.owner,E))throw new n(`UNSUPPORTED_OPERATION`,`Apple app-log owner identity does not match`);return Xn(e,t.device,t.scope.signal)},shutdown:async()=>void 0})}function Xn(e,t,r){if(t.platform!==`apple`)throw new n(`UNSUPPORTED_PLATFORM`,`Apple app-log owner cannot bind ${t.platform}`);let i=Qe({codec:En,reattach:async(n,r)=>n.backend!==T(t)||!Xe(e,r.sessionId,n)?{status:`unreattachable`,reason:`descriptor-invalid`,message:`Apple app-log descriptor does not match the bound device or owning session`}:await Ze(e,n.pidPath),cleanup:async(n,r)=>n.backend===T(t)&&Xe(e,r.sessionId,n)?await rt(e,n.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:T(t)}),appLogDoctor:async({appBundleId:n})=>await Ln(e,t,n,r),appLogStart:async n=>await Hn(e,t,n,E,r),...i});return Object.freeze({device:t,owner:E,facts:Zn(t),operations:a,[Symbol.asyncDispose]:async()=>void 0})}function Zn(e){if(e.appleOs===`watchos`)return Qn(e);let t=f(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?{available:!1,reason:`unsupported-device-backend`,hint:w}:D;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:D,appLogCleanup:D}})}function Qn(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 $n(e,t,n,r){let i=T(t),a=await e.appLogs.readRecent(n.sessionId,n.maxScanLines),o=tt(a.text,{...n,path:a.path,exists:a.exists,lineNumberOffset:a.skippedLines,backend:i}),s=[];if(tr(t,n,o.dump)){let i=await nr(e,t,n,a.path,r);i&&(o=er(s,o,i,n.maxEntries))}return ar(s,t,n),ir(s,o.dump),o.dump.entries.length===0&&s.push(or(t)),Object.freeze({source:`app-log`,backend:i,dump:o.dump,notes:Object.freeze(s)})}function er(e,t,n,r){let i=n.scan.dump.entries.length;return i===0&&(n.scan.dump.unnamedRequests??0)===0?(n.lineCount>0&&e.push(`Recovered ${n.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.`),t):(i>0&&e.push(`Recovered ${i} iOS simulator HTTP entr${i===1?`y`:`ies`} from simctl log show (${n.lineCount} app log lines scanned).`),it(n.scan,t,r))}function tr(e,t,n){return f(e)&&e.kind===`simulator`&&!!t.appBundleId&&n.entries.length===0}async function nr(e,t,n,r,i){let a=n.appLogSnapshot?.startedAt,o=v(t,[`spawn`,t.id,`log`,`show`,`--style`,`compact`,`--info`,`--predicate`,rr(n.appBundleId),...typeof a==`number`&&Number.isFinite(a)&&a>0?[`--start`,`@${Math.floor(a/1e3)}`]:[`--last`,`5m`]]),s=await e.appleTools.run({tool:`simctl`,args:o,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{scan:tt(`${c.join(`
3
- `)}\n`,{...n,path:`${r} (simctl log show recovery)`,exists:!0,backend:`ios-simulator`}),lineCount:c.length}}function rr(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 ir(e,t){let n=t.entries.filter(e=>e.pathUnavailable).length,r=t.unnamedRequests??0,i=n+r;if(i===0)return;let a=[`${i} request${i===1?``:`s`} reused a keep-alive connection, so CFNetwork logged no request URL.`];n>0&&a.push(`${n} listed against the origin the connection was opened for, without a path.`),r>0&&a.push(`${r} opened before this scan window and are missing from the entries entirely; scan more lines, or run logs clear --restart before the repro.`),a.push(`Absence of an endpoint in this dump does not prove it was not called.`),e.push(a.join(` `))}function ar(e,t,n){n.appLogSnapshot?n.appLogSnapshot.state!==`active`&&e.length===0&&e.push(f(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 or(e){return f(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.`:f(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 sr(e){let{host:t,snapshot:n,targetLabel:i,recorderWarning:a,nativePathDisposition:o}=e,s=n.invalidatedReason?{recorder:`lost`,why:`owner-session-lost`}:e.stopObservation;if(n.invalidatedReason&&!n.showTouches)throw Error(`recording invalidated: ${n.invalidatedReason}`);let c;try{c=await t.screenRecording.finalize.complete({outputPath:n.outPath,showTouches:!n.invalidatedReason&&n.showTouches,gestureEvents:n.gestureEvents,exportQuality:n.exportQuality??`medium`,targetLabel:i})}catch(e){throw r(e,`COMMAND_FAILED`)}let l=[...c.warning?[c.warning]:[],...a?[a]:[]];return st(n,{...c,...l.length>0?{warning:l.join(` `)}:{},...n.invalidatedReason?{overlayWarning:`overlay unavailable: ${n.invalidatedReason}`}:{}},{stopObservation:s,...o===void 0?{}:{nativePathDisposition:o}})}async function cr(e){let{host:t,snapshot:n,targetLabel:r,collectedPath:i,exportPath:a,nativePath:o}=e;if(n.invalidatedReason&&!n.showTouches)throw Error(`recording invalidated: ${n.invalidatedReason}`);let s=e.overlayUnavailable??n.invalidatedReason,c;try{await t.screenRecording.outputs.copy({from:i,to:a}),c=await lr(()=>t.screenRecording.finalize.complete({outputPath:a,showTouches:s===void 0&&n.showTouches,gestureEvents:n.gestureEvents,exportQuality:n.exportQuality??`medium`,targetLabel:r}))}catch(e){throw await t.screenRecording.outputs.remove(a),e}return{...c,...s===void 0?{}:{overlayWarning:`overlay unavailable: ${s}`},nativePathDisposition:await t.screenRecording.outputs.remove(o)===`removed`?`retired`:`retirable`}}async function lr(e){try{return await e()}catch(e){throw r(e,`COMMAND_FAILED`)}}const ur=[`outPath`,`startedAt`,`clientOutPath`,...ut],O=Object.freeze({resourceKind:gt,version:1,encode:e=>e.backend===`simctl`?{backend:e.backend,outputPath:e.outputPath,processes:e.processes.map(e=>({...e})),...e.recording===void 0?{}:{recording:{...e.recording}}}:{backend:e.backend,outputPath:e.outputPath,appBundleId:e.appBundleId,runnerSessionId:e.runnerSessionId,runnerAuthority:e.runnerAuthority,...e.remotePath===void 0?{}:{remotePath:e.remotePath}},decode:e=>Sr(e)});function dr(e){let{device:t,owner:n,input:r,descriptor:i}=e;return qe({resourceKind:gt,sessionId:r.sessionId,device:o(t),owner:n,fence:r.fence,lifecycle:`open`,descriptor:Ke(O,i)})}function fr(e){let t={};for(let n of ur)e[n]!==void 0&&Object.assign(t,{[n]:e[n]});return t}async function pr(e,t,n,r){let i=O.decode(n);return i.status!==`decoded`||!Mr(t,i.descriptor)?{status:`cleanup-pending`,reason:`manual-recovery-required`}:i.descriptor.backend===`simctl`?await mr(e,i.descriptor.processes,r):await gr(e,t,i.descriptor)}async function mr(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(hr(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(hr(n)),i.every(e=>e===`already-missing`)?{status:`already-missing`}:{status:`cleaned`})}function hr(e){return{kind:`session`,sessionId:e}}async function gr(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 _r(e){let{host:t,device:n,envelope:r}=e,i=O.decode(r.descriptor.body);return i.status===`decoded`?Mr(n,i.descriptor)?i.descriptor.backend===`simctl`?await vr(e,i.descriptor):await br(t,n,i.descriptor):k(`descriptor-invalid`,`Apple screen-recording descriptor does not match the bound device.`):k(`descriptor-invalid`,i.message)}async function vr(e,t){let n=await Promise.all(t.processes.map(async t=>await e.host.screenRecording.apple.inspectProcess(t)));if(!n.every(e=>e===`missing`))return k(`transport-not-reattachable`,n.includes(`ownership-lost`)?`Apple recording ownership no longer matches the durable descriptor.`:`Apple screen recordings require exact cleanup after daemon restart.`);let{recording:r}=t,i=yr(pt(e.envelope.metadata),t.outputPath);return r===void 0||i!==void 0&&!await xr(e.host,i)?{status:`missing`}:{status:`restore-export`,recording:r,nativePath:t.outputPath,cleanup:async()=>await mr(e.host,t.processes,e.envelope.sessionId)}}function yr(e,t){if(e.finalization===void 0)return e.collectedPath??t}async function br(e,t,n){let r=await e.screenRecording.apple.inspectRunner(t,n.runnerSessionId,n.runnerAuthority);return r===`missing`?{status:`missing`}:k(`transport-not-reattachable`,r===`ownership-lost`?`Apple recording ownership no longer matches the durable descriptor.`:`Apple screen recordings require exact cleanup after daemon restart.`)}async function xr(e,t){try{return await e.screenRecording.finalize.sniff({outputPath:t}),!0}catch{return!1}}function k(e,t){return{status:`unreattachable`,reason:e,message:t}}function Sr(e){return typeof e.outputPath!=`string`||e.outputPath.length===0?j():e.backend===`simctl`?Cr(e,e.outputPath):e.backend===`runner`?Er(e,e.outputPath):j()}function Cr(e,t){let n=Nr(e.processes),r=wr(e.recording);return!n||r===`invalid`?j():{status:`decoded`,descriptor:Object.freeze({backend:`simctl`,outputPath:t,processes:n,...r===void 0?{}:{recording:r}})}}function wr(e){if(e!==void 0)return i(e)&&Tr(e)?Object.freeze(e):`invalid`}function Tr(e){return A(e.outPath)&&Or(e.startedAt)&&Dr(e.clientOutPath)&&ct(e)}function Er(e,t){return!A(e.appBundleId)||!A(e.runnerSessionId)||!kr(e.runnerAuthority)||!Ar(e.remotePath)?j():{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 A(e){return typeof e==`string`&&e.length>0}function Dr(e){return e===void 0||A(e)}function Or(e){return typeof e==`number`&&Number.isFinite(e)}function kr(e){return e===`local-lease`||e===`scoped-provider`}function Ar(e){return e===void 0||jr(e)}function jr(e){return typeof e==`string`&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(e)}function Mr(e,t){return e.kind===`simulator`?t.backend===`simctl`:t.backend===`runner`?e.appleOs===`macos`?t.remotePath===void 0:f(e)?t.remotePath!==void 0&&jr(t.remotePath):t.remotePath===void 0:!1}function Nr(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 j(){return{status:`invalid`,message:`Invalid Apple screen-recording descriptor`}}async function Pr(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.`)}const Fr=`iOS recording`,Ir=`simctl recordVideo`;function Lr(e){return e.appleOs===`watchos`?Zr(`unsupported-platform-leaf`,`watchOS recording is not supported.`):f(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?Zr(`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 Rr(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await zr({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async e=>{let r=await _r({host:t,device:n,envelope:e.envelope});return r.status===`restore-export`?{status:`active`,handle:Vr({host:t,restored:r})}:r},screenRecordingCleanup:async e=>await pr(t,n,e.envelope.descriptor.body,e.envelope.sessionId)})}async function zr(e){return e.signal.throwIfAborted(),e.device.kind===`simulator`?await Br(e):await Ur(e)}async function Br(e){let{host:t,device:n,owner:r,input:i,signal:a}=e;await Pr(n,i,t.screenRecording.apple.isRunnerBundleId);let o=i.activeSessionApp?await t.screenRecording.apple.captureClockAnchor(n,i.activeSessionApp.bundleId,a):void 0,s=Dt(i.outputPath);await t.screenRecording.outputs.prepare(s);let c=await t.screenRecording.apple.startSimulator(n,s,a),l=c.markers;if(!l||l.length===0)throw await M(c).catch(()=>{}),Error(`simctl recordVideo did not expose durable process identity`);try{a.throwIfAborted(),t.screenRecording.ownedProcesses.replace({kind:`session`,sessionId:i.sessionId},l.map(e=>({...e,purpose:`simctl-screen-recording`})))}catch(e){try{t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId})}catch{}throw await M(c).catch(()=>{}),e}let u,d,f=async()=>{await c.terminate();let e=await c.wait;return d=e,u=Gr(e),t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId}),{observation:{recorder:`confirmed`},...u===void 0?{}:{warning:`${u} before record stop; the video covers only what the recorder wrote before it stopped.`}}},p=Xr(i,Ir,{},o);return Yr({device:n,owner:r,input:i,descriptor:{backend:`simctl`,outputPath:s,processes:l,recording:fr(p)},snapshot:p,finish:(e,n)=>dt({snapshot:e,progress:n,steps:{stop:f,collect:async e=>{try{await Hr(t,s,e)}catch(e){throw Kr(e,u,d)}},finalize:async({collectedPath:n,exportPath:r})=>{try{return await cr({host:t,snapshot:e,targetLabel:Fr,collectedPath:n,exportPath:r,nativePath:s})}catch(e){throw Kr(e,u,d)}},discard:async e=>{await t.screenRecording.outputs.remove(e)}}}),cleanup:async()=>{let e=await Jr(c);return(e.status===`cleaned`||e.status===`already-missing`)&&t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId}),e}})}function Vr(e){let{host:t,restored:{recording:n,nativePath:r,cleanup:i}}=e,a=Object.freeze({...n,backend:Ir,gestureEvents:[]});return ot(a,{finish:(e,i)=>dt({snapshot:e,progress:i,steps:{stop:async()=>({observation:{recorder:`confirmed`},warning:`simctl recordVideo had already ended when record stop reattached to it; the video covers only what the recorder wrote before it stopped.`}),collect:async e=>{await Hr(t,r,e)},finalize:async({collectedPath:i,exportPath:a})=>await cr({host:t,snapshot:e,targetLabel:Fr,collectedPath:i,exportPath:a,nativePath:r,...n.showTouches?{overlayUnavailable:`the daemon that held the touch events ended before record stop`}:{}}),discard:async e=>{await t.screenRecording.outputs.remove(e)}}}),forceCleanup:async()=>await i()})}async function Hr(e,t,n){await e.screenRecording.outputs.copy({from:t,to:n}),await e.screenRecording.finalize.sniff({outputPath:n})}async function Ur(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??=Wr(()=>t.screenRecording.apple.runRunner(n,{kind:`stop`,appBundleId:o,...c}).then(()=>void 0)).catch(e=>{throw l=void 0,e}),l);if(!qr(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 Yr({device:n,owner:r,input:i,descriptor:{backend:`runner`,outputPath:i.outputPath,appBundleId:o,...c,...s.remotePath===void 0?{}:{remotePath:s.remotePath}},snapshot:Xr(i,`runner AVAssetWriter`,s),finish:async e=>(await u(),s.remotePath!==void 0&&await t.screenRecording.apple.retrieveRunnerRecording(n,s.remotePath,e.outPath),await sr({host:t,snapshot:e,targetLabel:n.appleOs===`macos`?`macOS recording`:`iOS recording`,stopObservation:{recorder:`confirmed`},...s.remotePath===void 0?{}:{nativePathDisposition:`retirable`}})),cleanup:async()=>(await u(),{status:`cleaned`})})}async function Wr(e){try{return await e()}catch(e){throw r(e,`COMMAND_FAILED`)}}function Gr(e){if(e.exitCode!==0)return e.signal?`simctl recordVideo was killed by ${e.signal}`:`simctl recordVideo exited with code ${e.exitCode}`}function Kr(e,t,i){let a=r(e,`COMMAND_FAILED`);return t===void 0||i===void 0||a.details?.reason!==`recording-output-unplayable`?e:new n(a.code,`${a.message}; ${t}`,_(i,{...a.details??{},...i.signal===void 0?{}:{signal:i.signal},retriable:!1,hint:`The recorder exited before record stop, so the next record stop reads the same file. Close this session to release the device, then record again.`}))}function qr(e,t){return e.appleOs===`macos`||!f(e)?t===void 0:t!==void 0&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(t)}async function M(e){return await e.terminate(),await e.wait}async function Jr(e){try{return await M(e),{status:`cleaned`}}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`Apple simulator cleanup failed`}}}function Yr(e){let{device:t,owner:n,input:r,descriptor:i,snapshot:a,finish:o,cleanup:s}=e,c=ot(a,{finish:o,forceCleanup:s});return Object.freeze({pendingHandle:new Je(c),envelope:dr({device:t,owner:n,input:r,descriptor:i})})}function Xr(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.runnerSessionId===void 0?{}:{runnerSessionId:n.runnerSessionId}})}function Zr(e,t){return Object.freeze({available:!1,reason:e,hint:t})}const Qr=15e3;async function N(e,t,n,r={}){return n.throwIfAborted(),await kt(t)||d(t)?{...t,booted:!0}:t.kind===`device`?(await e.deviceReadiness.applePhysical.ensureConnected(t,n),{...t,booted:!0}):t.kind===`simulator`?((await $r(e,t)?`Booted`:await ii(e,t,n))!==`Booted`&&(r.onColdBootStart?.(),e.deviceReadiness.appleAutomation.keepHot(t),await ei(e,t,n,r.deadlineAtMs),await ai(e,n)),e.deviceReadiness.appleAutomation.keepHot(t),e.deviceReadiness.appleAutomation.markBooted(t),{...t,booted:!0}):{...t,booted:!0}}async function $r(e,t){try{return await e.deviceReadiness.appleAutomation.wasRecentlyObservedBooted(t)}catch{return!1}}async function ei(e,t,n,r=Date.now()+12e4){let i=!1;try{i=await ti(e,t,n,r),await ni(e,t,n,r)}catch(a){throw i&&n.aborted&&oi(e,t),n.throwIfAborted(),Date.now()>=r?ri(t,a):a}}async function ti(e,t,r,i){let a=await e.appleTools.run({tool:`simctl`,args:v(t,[`boot`,t.id]),allowFailure:!0,timeoutMs:P(i,t)},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 n(`COMMAND_FAILED`,`simctl boot failed`,{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode});return!s}async function ni(e,t,r,i){fe({type:`command`,status:`progress`,message:`Waiting for the Simulator to finish booting...`});let a=await e.appleTools.run({tool:`simctl`,args:v(t,[`bootstatus`,t.id,`-b`]),allowFailure:!0,timeoutMs:P(i,t)},r);if(a.exitCode!==0)throw new n(`COMMAND_FAILED`,`simctl bootstatus failed`,{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode});if(await Zt(e.appleTools,t,r,Math.min(Qr,P(i,t)))!==`Booted`)throw new n(`COMMAND_FAILED`,`Simulator is still booting`,{deviceId:t.id});if(Date.now()>=i)throw ri(t)}function P(e,t){let n=e-Date.now();if(n<=0)throw ri(t);return n}function ri(e,t){return new n(`COMMAND_FAILED`,`Simulator did not finish booting within the startup budget`,{reason:ht,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.`},t instanceof Error?t:void 0)}async function ii(e,t,n){return await Zt(e.appleTools,t,n,Qr)}async function ai(e,t){await e.commands.run({executable:`open`,args:[`-a`,`Simulator`],allowFailure:!0,timeoutMs:1e4},t)}function oi(e,t){e.appleTools.run({tool:`simctl`,args:v(t,[`shutdown`,t.id]),allowFailure:!0}).catch(()=>{})}const si=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:`runner`,setSetting:`simulator`,readSetting:`simulator`,setFoldPose:`simulator`,captureSnapshot:`simulator`,captureSnapshotWithoutActiveApp:`simulator`,captureSnapshotWithCustomActions:`runner`,captureScreenshot:`simulator`,findText:`runner`,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`,actionButton:`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 ci(e){return e===void 0?`possible`:e.some(e=>si[e]===`runner`)?`required`:`none`}const li=3e3,ui=`simulator-target-discovery-pending`;function di(){let e=new Map,t=new Map,n=cn({waitMs:1500});return async(r,i,a,o)=>{a.throwIfAborted();let s=`${r.id}:${i}`,c=e.get(s);if(c&&o!==`refresh`){let e=await nn(c.pid,{signal:a,timeoutMs:li});if(a.throwIfAborted(),e===c.processStartTime)return c}return e.delete(s),await n.value(s,{start:async()=>{let n=await mi(r,i,t);return e.set(s,n),n},wait:(e,t)=>en({waitMs:e,signal:a,stop:t,cancelled:()=>fi(a)}),pending:()=>F(ui,r,i)})}}function fi(t){return e({readinessPhase:`target-discovery`},t.reason)}function pi(e){return e instanceof n&&e.details?.reason===ui}async function mi(e,t,n){let r=Date.now()+15e3,[i,a]=await Promise.allSettled([Ht(e,[`spawn`,e.id,`launchctl`,`list`],{allowFailure:!0,timeoutMs:_i(r)}),hi(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 F(`simulator-target-probe-failed`,e,t);let c=gi(o.stdout,t);if(!c)throw F(`simulator-target-unavailable`,e,t);let l=await nn(c.pid,{timeoutMs:Math.min(li,_i(r))});if(!l)throw F(`simulator-target-identity-unavailable`,e,t);return Object.freeze({simulator:Wt(e),runtime:s,pid:c.pid,generation:`${c.pid}:${c.label}:${l}`,targetId:`${e.id}:${t}`,processStartTime:l})}async function hi(e,t,n){let r=t.get(e.id);if(r)return await r;let i=Ht(e,[`list`,`devices`,`-j`],{allowFailure:!0,timeoutMs:_i(n)}).then(t=>{if(t.exitCode!==0)throw F(`simulator-runtime-probe-failed`,e,``);let n=Object.entries(Ut(t.stdout)).find(([,t])=>t.some(t=>t.udid===e.id))?.[0];if(!n)throw F(`simulator-runtime-unavailable`,e,``);return n});t.set(e.id,i);try{return await i}catch(n){throw t.delete(e.id),n}}function gi(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 _i(e){return Math.max(1,e-Date.now())}function F(e,t,r){return new n(`COMMAND_FAILED`,`Unable to resolve the running iOS Simulator app (${e}).`,{reason:e,deviceId:t.id,appBundleId:r})}const vi=new Map([[`application-element-missing`,5e3],[`application-server-unavailable`,5e3],[`foreground-owner-unverified`,1e3],[`foreground-owner-changed`,1e3]]);function I(e){return e.platform===`apple`&&e.appleOs===`ios`&&e.kind===`simulator`}function yi(e){let t=le(de({depth:1,interactiveOnly:!0}));return Object.freeze({awaitObservable:async(n,r,i)=>{if(!I(n))return`not-eligible`;let a;for(;;){let o=await bi(e.resolveTarget,n,r,i);if(!o)return`unobservable`;if(e.isBridgeDisabled(o))return ae({level:`debug`,phase:`ios_launch_observation_skipped`,data:{reason:`circuit-disabled`,deviceId:n.id,generation:o.generation}}),`unobservable`;let s=await e.source.acquire({target:o,hint:t,signal:i});if(s.stage!==`failed`)return`observable`;i.throwIfAborted();let c=vi.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)}}})}async function bi(e,t,n,r){for(;;)try{return await e(t,n,r)}catch(e){if(r.throwIfAborted(),!pi(e))return}}function xi(e,t,n){let r=n&&I(e),i=r?ci(t.execution.plannedOperations):void 0,a=f(e)&&t.surface===`app`&&t.positionals.length>0&&!!t.appBundleId&&i!==`none`;return{...i?{runnerDemand:i}:{},shouldPrewarmRunner:a,awaitPrewarmAfterOpen:t.relaunch&&!r}}function Si(e,t,n,r){r.runnerDemand===`none`&&e.appleApplications.releaseSpeculativeRunner(t.device,n.execution).catch(()=>{})}async function Ci(e,t,n,r,i,a){let o=Date.now();r&&I(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 wi(e){let t=jt({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 N(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 Ti(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 Fi(e.host,t,n),finalizeApplicationClose:async t=>await Ii(e.host,e.device,e.signal,t),prepareAppleRunner:async t=>await Li(e.host,e.device,e.signal,t),configureProviderPortReverse:Hi})}async function Ti(e,t,n,r){let i={},a=L(t.device),o=Ri(e,t,n,i),s=xi(t.device,n,a);s.runnerDemand&&(i.runnerDemand=s.runnerDemand),Si(e,t,n,s);let{shouldPrewarmRunner:c}=s,l=Pi(t.device,n,a);a&&c&&!n.prewarmRunnerBeforeOpen&&o.schedule();try{await Ei(e,t,n,a,l,i),await Di(n,i),await Oi(o,c,n.prewarmRunnerBeforeOpen);let u=o.wasAwaited();return await ki(t,n,a,i),await ji(o,c,s.awaitPrewarmAfterOpen),await Mi(e,t,n,a,u,l),await Ci(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 Ei(e,t,n,r,i,a){if(!Ni(n,r)||!n.target)return;let o=Date.now();l(t.device.platform)&&!r&&!i&&await e.appleApplications.stopRunnerSession(t.device.id),await At({device:t.device,interactor:await t.resolveInteractor(n.execution,n.appBundleId),positionals:[n.appBundleId??n.target]}),r&&await e.clock.sleep(300,t.signal),a.relaunchCloseDurationMs=R(o)}async function Di(e,t){if(!me(e.runtimeHints))return;if(!e.applyRuntimeHints)throw new n(`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}),t.runtimeHintsDurationMs=R(r)}async function Oi(e,t,n){!t||!n||(e.schedule(!0),await e.wait())}async function ki(e,t,n,r){let i=Bi(t,n),a=Date.now();await Mt({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=R(a),await Ai(e,t,i.followUpUrl,r)}async function Ai(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 Mt({device:e.device,interactor:await e.resolveInteractor(i,t.appBundleId),positionals:[n],appBundleId:t.appBundleId,execution:i}),r.launchUrlDurationMs=R(a)}async function ji(e,t,n){t&&!e.wasScheduled()&&e.schedule(),n?await e.wait():e.recordUnawaited()}async function Mi(e,t,n,r,i,a){!f(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 Ni(e,t){return!!(e.relaunch&&e.target)&&!(t&&!e.execution.clearAppState)}function Pi(e,t,n){return e.kind===`device`&&e.appleOs===`ios`&&Ni(t,n)}async function Fi(e,t,n){n.ensureReady&&await N(e,t.device,t.signal),l(t.device.platform)&&!L(t.device)&&await e.appleApplications.stopRunnerSession(t.device.id),await At({device:t.device,interactor:await t.resolveInteractor(n.execution,n.appBundleId),positionals:n.positionals}),L(t.device)&&await e.clock.sleep(300,t.signal)}async function Ii(e,t,n,r){r.daemonShutdown||await e.appleApplications.releaseRunnerOnClose(t.id,{retain:r.retainRunner}),await e.appleApplications.dismissCloseAlerts(t,r).catch(()=>{});let i=r.shutdownTarget&&L(t)?await e.deviceShutdown.apple.shutdownTarget(t,n):void 0;return i===void 0?{}:{shutdown:i}}async function Li(e,t,n,r){let i=Date.now()+r.timeoutMs;await N(e,t,n,{deadlineAtMs:i});let a=Math.max(1,i-Date.now());return await e.appleApplications.prepareRunner(t,{...r,timeoutMs:a},n)}function Ri(e,t,n,r){let i,a=!1,o=zi(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=R(e)},wasAwaited:()=>a,wasScheduled:()=>i!==void 0,recordUnawaited:()=>{i&&!a&&(r.runnerPrewarmWaited=!1)}}}function zi(e,t){return e.kind===`device`&&e.appleOs===`ios`&&!t.hasExistingSession&&!t.relaunch&&!t.prewarmRunnerBeforeOpen}function Bi(e,t){let n=e.runtimeLaunchUrl?.trim(),r=e.positionals.length===1?e.positionals[0]?.trim():void 0;return!n||!r||a(r)?{positionals:e.positionals}:t&&!Vi(e)?{positionals:[r,n]}:{positionals:e.positionals,followUpUrl:n}}function Vi(e){return e.execution.clearAppState===!0||!!e.execution.launchConsole?.trim()||!!e.execution.launchArgs?.length}function L(e){return f(e)&&e.kind===`simulator`}function R(e){return Math.max(0,Date.now()-e)}async function Hi(){throw new n(`UNSUPPORTED_OPERATION`,`This lifecycle operation is unavailable for Apple.`)}const Ui=Object.freeze({available:!0}),Wi=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.`}),Gi=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Push notifications are supported on Apple simulators only.`}),Ki=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),qi=Object.freeze({available:!1,reason:`unsupported-device-kind`});function Ji(e){let t=na(e);return Object.freeze({deployApp:t,materializeAppSource:t,deployMaterializedApp:t,sendPushNotification:ra(e)})}function Yi(e){let{host:t,device:n,signal:r}=e,i=Ji(n);return Object.freeze({...i.deployApp.available?{deployApp:async e=>await Xi(t,n,e,r),materializeAppSource:async e=>await t.appleDeployment.prepareArtifact(e,{signal:r}),deployMaterializedApp:async e=>await Zi(t,n,e,r)}:{},...i.sendPushNotification.available?{sendPushNotification:async e=>(await ea(t,n,e,r),{})}:{}})}async function Xi(e,t,n,r){if(n.replaceExisting)return await e.appleDeployment.withInvalidatedAppResolutionCache(t,async()=>{let i=await e.appleDeployment.resolveAppBundleId(t,n.app);await $i(e,t,i,r);let a=await e.appleDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{appIdentifierHint:n.app,signal:r});try{return await Qi(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 Zi(e,t,{artifact:i},r)}finally{await i.cleanup()}}async function Zi(e,t,n,r){return await Qi(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 Qi(e,t,n,r){await N(e,t,r),await ta(e,t.kind===`simulator`?{tool:`simctl`,args:v(t,[`install`,t.id,n])}:{tool:`devicectl`,args:[`device`,`install`,`app`,`--device`,t.id,n],timeoutMs:Pt},r,`Apple app install failed`)}async function $i(e,t,n,r){await N(e,t,r),await ta(e,t.kind===`simulator`?{tool:`simctl`,args:v(t,[`uninstall`,t.id,n])}:{tool:`devicectl`,args:[`device`,`uninstall`,`app`,`--device`,t.id,n]},r,`Apple app uninstall failed for ${n}`,{tolerate:e=>Bt(`${e.stdout}\n${e.stderr}`.toLowerCase())})}async function ea(e,t,r,i){if(t.kind!==`simulator`)throw new n(`UNSUPPORTED_OPERATION`,`Apple push notifications require a simulator`);await N(e,t,i);let a=await e.temporaryFiles.create({prefix:`agent-device-ios-push-`,suffix:`.apns`});try{await a.writeText(`${JSON.stringify(r.payload)}\n`),await ta(e,{tool:`simctl`,args:v(t,[`push`,t.id,r.appId,a.path])},i,`Apple push notification failed`)}finally{await a[Symbol.asyncDispose]()}}async function ta(e,t,n,r,i){let a=await e.appleTools.run({...t,allowFailure:!0},n);return i?.tolerate?.(a)?a:oe(a,r,e=>({cmd:`xcrun`,args:[t.tool,...t.args],...t.tool===`devicectl`?{hint:zt(e.stdout,e.stderr)??`Ensure the iOS device is unlocked, trusted, and available in Xcode > Devices, then retry.`}:{}}))}function na(e){return ia(e)?e.kind!==`simulator`&&e.kind!==`device`?qi:e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?Wi:Ui:Ki}function ra(e){return ia(e)?e.kind===`simulator`?Ui:Gi:Ki}function ia(e){return f(e)&&e.appleOs!==`watchos`}const z=Object.freeze({available:!0}),aa=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`back is supported on Apple simulators and physical devices.`}),oa=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function sa(e){return e.kind!==`simulator`&&e.kind!==`device`?aa:s(e)===`watchos`?oa:z}const ca=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`home is supported on Apple simulators and physical devices.`}),la=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),ua=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`app-switcher is supported on Apple simulators and physical devices.`});function da(e,t){if(e.kind!==`simulator`&&e.kind!==`device`)return t;let n=s(e);return n===`macos`||n===`watchos`?la:z}function B(e){if(e.kind!==`simulator`&&e.kind!==`device`)return!1;let t=s(e);return t!==`tvos`&&t!==`macos`&&t!==`watchos`}const fa=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`orientation is supported on Apple simulators and physical devices.`}),pa=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function ma(e){return e.kind!==`simulator`&&e.kind!==`device`?fa:B(e)?z:pa}const ha=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`tv-remote is supported only on tvOS devices.`});function ga(e){return(e.kind===`simulator`||e.kind===`device`)&&p(e)?z:ha}const V=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),_a=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 va(e){return B(e)?_a:V}function ya(e){return B(e)?z:V}function ba(e){return B(e)?z:V}const xa=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`No Apple leaf carries this system button.`}),Sa=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`action-button is supported on iPhone and iPad simulators and physical devices.`}),Ca=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`The Action Button is iPhone and iPad hardware; tvOS, macOS, watchOS and visionOS have no such control.`});function wa(e){return e.kind!==`simulator`&&e.kind!==`device`?Sa:c(e)?z:Ca}function Ta(e){return Object.freeze({...ze({back:sa(e)}),...Me({unsupported:xa,home:da(e,ca),appSwitcher:da(e,ua),actionButton:wa(e)}),...ve({orientation:ma(e)}),...Be({tvRemote:ga(e)}),...Re({unsupported:V,status:va(e),dismiss:ya(e),enter:ba(e)})})}function Ea(e){let{host:t,device:n,signal:r}=e;return bt({device:n,signal:r,resolveInteractor:t.localInteractors.resolve,facts:Ta(n)})}const H=Object.freeze({available:!0}),Da=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`clipboard is supported on Apple simulators and the macOS host.`}),Oa=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`settings is supported on Apple simulators and the macOS host.`}),ka=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.`}),Aa=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:"Apple targets answer a settings read only on iPhone and iPad simulators, where `simctl ui` reports the value the device holds."}),ja=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.`}),U=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function Ma(e,t,n){if(e.kind!==`simulator`&&e.kind!==`device`)return t;let r=s(e);return r===`watchos`?U:e.kind===`simulator`||r===`macos`?H:n}function Na(e){return Ma(e,Da,ja)}const Pa=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`trigger-app-event is supported on Apple simulators and physical devices.`}),Fa=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`alert is supported on Apple simulators and physical devices.`}),Ia=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`alert is supported on Apple simulators, the macOS host, and physical iOS devices.`});function La(e){if(e.kind!==`simulator`&&e.kind!==`device`)return Fa;let t=s(e);return t===`watchos`?U:e.kind===`simulator`||t===`ios`||t===`macos`?H:Ia}function Ra(e){return e.kind!==`simulator`&&e.kind!==`device`?Pa:s(e)===`watchos`?U:H}function za(e){let t=Na(e);return t.available?ja:t}function Ba(e){return e.kind!==`simulator`&&e.kind!==`device`?Oa:s(e)===`watchos`?U:u(e)?H:Aa}function Va(e){let t=Na(e),n=La(e);return Object.freeze({...Ne({unsupported:za(e),read:t,write:t}),...Fe({read:n,wait:n,accept:n,dismiss:n}),...Le({triggerAppEvent:Ra(e)}),...Ie({setSetting:Ma(e,Oa,ka),readSetting:Ba(e)})})}function Ha(e){let{host:t,device:n,signal:r}=e;return bt({device:n,signal:r,resolveInteractor:t.localInteractors.resolve,facts:Va(n)})}function Ua(e){return Object.freeze({setFoldPose:e.fold})}const Wa=/Angle:\s*(-?\d+(?:[.,]\d+)?)\s*°/g;async function Ga(e,t={}){let r=[`devicectl`,`device`,`motion`,`hinge-angle`,`--device`,e.id,`--session-timeout`,`1`,`--timeout`,`5`],i=await Rt(r,{allowFailure:!0,signal:t.signal,timeoutMs:It}),a=Ka(i.stdout)??Ka(i.stderr);if(a!==void 0)return a;throw new n(`COMMAND_FAILED`,`CoreDevice reported no hinge angle sample`,_(i,{cmd:`xcrun`,args:r,stdout:i.stdout,stderr:i.stderr,deviceId:e.id,hint:`This Xcode/CoreDevice toolchain does not stream 'devicectl device motion hinge-angle' for this device. Foldable poses can be verified only through that stream; update Xcode to a version that ships it.`}))}function Ka(e){let t;for(let n of e.matchAll(Wa)){let e=Number.parseFloat(n[1].replace(`,`,`.`));Number.isFinite(e)&&(t=e)}return t}const qa=`Fold.m`,Ja=3e4,Ya=Vt+Ja;async function Xa(e={}){let t=e.host??Za(),n=an(Ya,e.signal);try{let r=e.sourceRoot??y.join(se(),`apple`,`fold-helper`),i=await on(t,r,[qa],n),a=await tn(t,n),o=e.cacheRoot??y.join(Nt(),`.agent-device`,`fold-helper`);return await sn({host:t,deadline:n,lockDescription:`iOS Simulator fold helper cache`,cacheRoot:o,binaryFilename:`fold-helper`,keyInputs:{schemaVersion:1,sourceHash:i,toolchain:a,compileArgv:Qa({sourceRoot:``,outputPath:``})},build:e=>$a(t,n,r,e)})}catch(e){throw eo(e)}}function Za(){return Qt(Lt)}function Qa(e){return[`--sdk`,`iphonesimulator`,`clang`,`-mios-simulator-version-min=15.0`,`-fobjc-arc`,`-Wall`,`-Wextra`,`-framework`,`Foundation`,`-framework`,`IOKit`,y.join(e.sourceRoot,qa),`-o`,e.outputPath]}async function $a(e,t,n,r){let i=await rn({host:e,deadline:t,argv:Qa({sourceRoot:n,outputPath:r}),budgetMs:Ja,label:`fold helper`});if(i.exitCode!==0||!e.exists(r))throw to(_(i))}function eo(e){return!(e instanceof $t)||e.buildFailureKind===`cancelled`?e:to({...e.buildDetails,cause:e.buildFailureCode},e)}function to(e,t){return new n(`COMMAND_FAILED`,`Unable to build the simulator fold helper`,{hint:`Select an Xcode with the iOS simulator SDK and foldable HID support using DEVELOPER_DIR.`,...e,reason:`fold-helper-build-failed`},t)}async function no(e,t,r){r?.throwIfAborted();let i=await Xa({signal:r});r?.throwIfAborted();let a=typeof t==`string`?0:t.at(-1).atMs,o=typeof t==`string`?t:JSON.stringify(t),s=await Ht(e,[`spawn`,e.id,i.path,o],{signal:r,timeoutMs:a+1e4,kill:{signal:`SIGTERM`,graceMs:1e3},allowFailure:!0});if(s.exitCode!==0)throw new n(`COMMAND_FAILED`,`Unable to send the simulator hinge pose`,_(s,{reason:`fold-hid-dispatch-failed`,deviceId:e.id}))}async function ro(e,t,n={}){n.signal?.throwIfAborted(),Jt(e,`fold`);let r=t,i=r.keyframes?.at(-1)?.angle,a=r.pose??g(i);io(e,await Yt(e,{signal:n.signal})),await no(e,r.keyframes??a,n.signal),ae({level:`info`,phase:`apple_fold_pose_dispatched`,data:{deviceId:e.id,pose:a}});let o=await ao(e,a,n.signal,i),s=await ho(e,n.signal);return{pose:g(o),hingeAngleDegrees:o,...s?{screen:go(s)}:{}}}function io(e,t){if(t.unresolved)throw new n(`COMMAND_FAILED`,`CoreDevice reported no display table for this simulator`,{deviceId:e.id,hint:`fold needs 'devicectl device info displays' to tell a foldable from a single-panel simulator; update Xcode to a version that ships the display-information feature.`});if(!t.multiScreen)throw new n(`UNSUPPORTED_OPERATION`,`${e.name} is not a foldable simulator: fold requires more than one integrated panel`,{deviceId:e.id,reason:`single-panel-device`,hint:`fold sets the hinge angle of a foldable simulator such as iPhone Duo; this simulator reports one integrated panel, so it has no hinge to pose.`})}async function ao(e,t,n,r){let i,a;for(let o=1;o<=4;o+=1)if(n?.throwIfAborted(),a=i,i=await Ga(e,{signal:n}),oo(i,a,t,r))return i;throw lo(e,t,i,a,r)}function oo(e,t,n,r){return r===void 0?g(e)===n?n!==`half-open`||t!==void 0&&uo(e,t):!1:so(e,t,r)}function so(e,t,n){return co(e,n)?n===0||n===180||t!==void 0&&co(t,n)&&Math.abs(e-t)<=.5:!1}function co(e,t){return t===void 0||e!==void 0&&Math.abs(e-t)<=.5}function lo(e,t,r,i,a){return co(r,a)?a!==void 0&&r!==void 0?mo(e,g(r),r,i):r!==void 0&&t===`half-open`&&g(r)===t?mo(e,t,r,i):po(e,t,r):new n(`COMMAND_FAILED`,`The hinge did not reach the final keyframe angle`,{reason:`fold-angle-unverified`,targetAngleDegrees:a,hingeAngleDegrees:r,deviceId:e.id})}function uo(e,t){return g(e)===`half-open`&&g(t)===`half-open`&&Math.abs(e-t)<=.5}function fo(e,t,n){return{deviceId:e.id,requestedPose:t,observedPose:n===void 0?void 0:g(n),hingeAngleDegrees:n}}function po(e,t,r){return new n(`COMMAND_FAILED`,`${e.name} did not reach the ${t} pose: CoreDevice still reports a hinge angle of ${r}°`,{...fo(e,t,r),reason:`fold-pose-unverified`,hint:`The simulator HID command completed, but the hinge did not follow. Verify that the selected Xcode and simulator runtime support foldable HID control, then retry.`})}function mo(e,t,r,i){return new n(`COMMAND_FAILED`,`${e.name} was observed ${t} at ${r}° but did not settle: 4 hinge reads never held two consecutive angles within ${Ft}° of each other`,{...fo(e,t,r),reason:`fold-pose-unsettled`,...i===void 0?{}:{previousHingeAngleDegrees:i},hint:`The hinge reached the requested pose and was still moving when the read budget ended. Retry the fold, then read the angle directly with xcrun devicectl device motion hinge-angle --device <udid> --session-timeout 1 --timeout 5 to see whether the simulator holds the pose.`})}async function ho(e,t){let n=await Yt(e,{signal:t});if(!(n.unresolved||n.ambiguous))return n.activeDisplay}function go(e){return{display:e.name,coordinateSpace:re,widthPt:Math.round(e.widthPx/e.pointScale),heightPt:Math.round(e.heightPx/e.pointScale)}}const _o=Object.freeze({available:!0}),vo=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`fold is supported on foldable iPhone simulators controlled through simulator HID; a physical device is folded by hand.`}),yo=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`fold poses the hinge of a foldable iPhone; tvOS, macOS, watchOS and visionOS simulators have no hinge.`});function bo(e){return{available:!1,reason:`unsupported-device-scope`,hint:`fold cannot resolve a simulator scoped to the set at "${e}": CoreDevice's display inventory and hinge-angle readback need a simulator in the default set, so the pose could not be verified. Run fold without --ios-simulator-device-set.`}}function xo(e){if(e.kind!==`simulator`)return vo;let t=s(e);return t!==`ios`&&t!==`ipados`?yo:e.simulatorSetPath?bo(e.simulatorSetPath):_o}function So(e){return Ua({fold:xo(e)})}function Co(e){let{device:t,signal:n}=e;return h(So(t).setFoldPose,()=>({setFoldPose:async e=>(n.throwIfAborted(),await ro(t,e,{signal:n}))}))}function wo(e,t,n){let r=Se({device:t.device,signal:t.signal,resolveInteractor:e.localInteractors.resolve}),i=async i=>{if(d(t.device)&&ne(i.options?.surface)===`macos-helper`)return await e.snapshot.captureSurface(t.device,i.options,je(t.signal,i));if(!n)return await r.captureSnapshot(i);let a=je(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 To(e,t){return Object.freeze({findText:async n=>{let r=await Eo(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}}})}async function Eo(e,t,n){let r=n.options?.appBundleId;if(r===void 0||d(t.device)&&ne(n.options?.surface)===`macos-helper`)return;let i=n.signal?AbortSignal.any([t.signal,n.signal]):t.signal;if(i.throwIfAborted(),await Do(e,t.device,n.execution))return{appBundleId:r,signal:i}}async function Do(e,t,n){return!I(t)||await e.appleApplications.hasLiveRunnerSession(t,n??{})}function Oo(){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()}}}function ko(e=Date.now){let t=new Map;return async(n,r)=>{if(n.kind!==`simulator`)return`absent`;let i=t.get(n.id);if(i!==void 0&&e()-i.at<1e3)return{kind:`present`,host:i.host};t.delete(n.id);let a=await Ao(n,r);return a!==`absent`&&a!==`unknown`&&t.set(n.id,{at:e(),host:a.host}),a}}async function Ao(e,t){let n=!1;for(let r of _t){let i=await jo(r.processExecutable,t);if(i===`unknown`){n=!0;continue}for(let a of i){let i=await Mo(a,e.id,t);if(i===`unknown`)n=!0;else if(i)return{kind:`present`,host:r}}}return n?`unknown`:`absent`}async function jo(e,t){let n=await No(`pgrep`,[`-f`,e],t);return n===`unknown`?`unknown`:n.exitCode===1?[]:n.exitCode===0?n.stdout.split(`
5
- `).map(e=>Number.parseInt(e.trim(),10)).filter(e=>Number.isSafeInteger(e)&&e>0):`unknown`}async function Mo(e,t,n){let r=await No(`ps`,[`eww`,`-p`,String(e),`-o`,`command=`],n);return r===`unknown`||r.exitCode!==0?`unknown`:r.stdout.includes(`SIMULATOR_UDID=${t}`)?!0:!r.stdout.includes(`SIMULATOR_UDID=`)&&`unknown`}async function No(e,t,n){try{let r=await Lt(e,t,{allowFailure:!0,timeoutMs:3e3,...n?{signal:n}:{}});return{exitCode:r.exitCode,stdout:r.stdout}}catch{return`unknown`}}const Po=`system-surface-presented`,Fo=`system-surface-host-lingering`,Io=`window-coordinate-space-unresolved`;function Lo(e,t={}){let r=t.source??Oo(),i=t.resolveTarget??di(),a=t.systemSurfacePresent??ko(),o=new Set,s=new Map,c=e=>(Xo(e,s,o),o.has(Zo(e))),l=yi({source:r,resolveTarget:i,clock:e.clock,isBridgeDisabled:c});return Object.freeze({awaitObservable:l.awaitObservable,shutdown:async()=>await r.close(),capture:async(t,s,l,u)=>{if(!Bo(t,s))return await Wo(t,s,u);let d=await a(t,l);if(d===`unknown`)return await W(t.id,s,u,G(t.id,s),q(s),`system-surface-probe-unavailable`,[K()]);if(d!==`absent`)return await Uo(t,s,u,d.host.bundleId);let f;try{f=await Ro(e,i,t,s,l)}catch(e){return zo(l,e),J(`target-resolution-failed`,t,void 0,e),await W(t.id,s,u,G(t.id,s),q(s),`target-resolution-failed`,[K()])}if(c(f))return J(`circuit-disabled`,t,f.generation),await W(t.id,s,u,f,q(s),`circuit-disabled`);let p=q(s),m=await r.acquire({target:f,hint:le(p),signal:l});if(m.stage===`failed`){if(m.failure.kind===`cancelled`)throw l.throwIfAborted(),new n(`COMMAND_FAILED`,`Simulator AX snapshot acquisition was cancelled.`,{reason:m.failure.code,...m.failure.details});let e=await Yo(m.failure,f,t,s.options.appBundleId,l,i);return await Vo(s,u,f,e,p,m.failure,o)}try{return await ie(`ios.snapshot-source.present`,async()=>await e.snapshot.presentIosAcquisition(m,s.options),{producer:`simulator-ax-bridge`})}catch(e){return await Vo(s,u,f,{lineage:f,residue:[]},p,{kind:`malformed-tree`,code:`presentation-invariant`},o,e)}}})}async function Ro(e,t,n,r,i){let a=r.options.appBundleId;for(;;)try{return await t(n,a,i)}catch(t){if(!pi(t))throw t;let i={requestId:r.execution?.requestId};if(await e.appleApplications.hasLiveRunnerSession(n,i))throw t}}function zo(e,n){if(e.aborted)throw t(n)?n:e.reason}function Bo(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 Vo(e,t,n,r,i,a,o,s){return Ho(a)&&o.add(Zo(n)),J(a.code,{id:n.simulator.udid},n.generation,s,a.details),await W(n.simulator.udid,e,t,r.lineage,i,a.code,r.residue)}function Ho(e){return e.kind!==`preparing`&&e.code!==Io}async function W(e,t,n,r,i,a,o=[]){return Go(e,await n(t),r,i,a,o)}async function Uo(e,t,n,r){let i=await n(t),a=i.systemSurface?Po:Fo;return i.systemSurface||J(a,e,void 0,void 0,{detectedHost:r}),Go(e.id,i,G(e.id,t),q(t),a)}async function Wo(e,t,n){let r=await n(t),i=r.systemSurface;return i?{...r,comparisonIdentity:qo(Ko(e.id,i.bundleId),q(t),[])}:r}function Go(e,t,n,r,i,a=[]){let o=t.systemSurface;return{...t,comparisonIdentity:qo(o?Ko(e,o.bundleId):n,r,[...o?[]:a,{kind:`fallback-source`,producer:`apple-runner`}]),warnings:[...t.warnings??[],Jo(i,n,o!==void 0)]}}function G(e,t){return{targetId:`${e}:${t.options.appBundleId}`}}function Ko(e,t){return{targetId:`${e}:${t}`}}function qo(e,t,n){return Object.freeze({producer:`apple-runner`,intent:t.acquisitionIntent,lineage:Object.freeze({...e.targetId?{targetId:e.targetId}:{},...e.generation?{generation:e.generation}:{}}),presentationKey:ue(t),residue:Object.freeze([...n])})}function Jo(e,t,n){return e===Po?`Simulator AX snapshot inapplicable (${e}); used XCTest to read the system surface presented over the app.`:e===Fo?`Simulator AX snapshot inapplicable (${e}); used XCTest, which read app content: the system surface host process was still running but no longer presenting.`:n?`Simulator AX snapshot unavailable (${e}); used XCTest, which read the system surface presented over the app.`:e===`bridge-preparation-pending`?`Simulator AX snapshot unavailable (${e}); used XCTest for this capture while the bridge is still being prepared.`:e===Io?`Simulator AX snapshot unavailable (${e}); used XCTest for this capture, which reports captured geometry in the app's own orientation space.`:`Simulator AX snapshot unavailable (${e}); used XCTest for ${t.generation?`this app generation`:`an unverified app generation`}.`}async function Yo(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(),J(`fallback-target-resolution-failed`,n,void 0,e),{lineage:{targetId:t.targetId},residue:[K()]}}}function K(){return{kind:`unknown-generation`,captureId:ln()}}function q(e){return de({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 Xo(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 Zo(e){return`${e.targetId}:${e.generation}`}function J(e,t,n,r,i){ae({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 Y=m(`apple`),X=Object.freeze({available:!0}),Z=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Qo=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.`}),$o=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.`}),es=Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`perf requires an Apple simulator, macOS device, or CoreDevice-backed physical Apple device.`}),ts=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`focus is supported on Apple simulators and physical devices.`}),ns=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple appstate is unavailable here: the runner reads the session app's XCUIApplication state on iOS-family simulators and physical devices only, and the Apple target answers no sessionless foreground probe. The per-command answer is the targetActivation disclosure, which a capture carries when its command had to re-activate the session app (#2682).`});function rs(e){return!f(e)||e.appleOs===`watchos`?ns:e.kind===`simulator`||e.kind===`device`?X:ns}const is=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Headless boot is supported only for local Android emulators.`}),as=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS has no XCUITest-driveable UI, so element text comes from the captured tree only.`}),os=Object.freeze({available:!1,reason:`unsupported-device-kind`}),ss=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS open is not supported because XCUITest cannot drive watchOS UI.`}),cs=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS runner preparation is not supported because XCUITest cannot drive watchOS UI.`}),ls=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS close is not supported because XCUITest cannot drive watchOS UI.`}),us=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Runtime hints are supported only for local iOS-family simulators and Android devices.`}),ds=Q(`open is supported only for Apple simulators and devices.`),fs=Q(`prepare is supported only for Apple simulators and devices.`),ps=Q(`close is supported only for Apple simulators and devices.`),ms=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`}),hs=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`shutdown is supported only for Apple simulators and Android emulators.`}),gs=Q(`snapshot is supported only for Apple simulators and devices.`),_s=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Re-run without --actions, or target an iOS simulator.`}),vs=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`screenshot is not supported on watchOS because XCUITest cannot drive watchOS UI.`}),ys=Q(`screenshot is supported only for Apple simulators and devices.`),bs=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`Open the app under test before capturing its snapshot.`});function Q(e){return Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:e})}function xs(e){return!f(e)||e.appleOs===`watchos`?Z:e.kind===`simulator`?X:hs}function Ss(e){let t=Cs(e),n=ws(e),r=Ts(e),i=Es(e);return he({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:i,clearRuntimeHints:i,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:n,configureProviderPortReverse:ms})}function Cs(e){return s(e)===`watchos`?ss:e.kind===`simulator`||e.kind===`device`?X:ds}function ws(e){return s(e)===`watchos`?cs:e.kind===`simulator`||e.kind===`device`?X:fs}function Ts(e){return s(e)===`watchos`?ls:e.kind===`simulator`||e.kind===`device`?X:ps}function Es(e){return s(e)!==`watchos`&&f(e)&&e.kind===`simulator`?X:us}function Ds(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.`}):X}function $(e){return e.kind===`simulator`||e.kind===`device`?X:ts}function Os(e){let t=Yn(e),n=Lo(e),r=async n=>{let r=await t.inspectFacts(n),i=Ji(n),a=Lr(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`?Z:X,l=d(n)||n.appleOs===`watchos`?Z:X,u=Ds(n);return Object.freeze({device:r.device,operations:{...r.operations,...i,appState:rs(n),networkDump:X,screenRecordingStart:s,screenRecordingReattach:s,screenRecordingCleanup:s,...Ns(n),...we({capture:Ms(n)}),...Ae({findText:js(n)}),..._e({setViewport:Qo}),...Ve({focus:$(n)}),...yn(n),...ge({type:$(n)}),...We({unsupported:Z,tap:$(n),longPress:$(n),fill:$(n),...f(n)?{tapElementSelector:$(n)}:{}}),...ye({readTextAtPoint:As(n)}),...Ta(n),...So(n),...Va(n),...He({capture:fn(n),query:$o}),...Ue(ks(n)),ensureReady:c,bootTarget:l,bootTargetHeadless:is,listApps:u,...Ss(n),shutdownTarget:xs(n)}})};return Object.freeze({owner:Y,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={...h(o.operations.appState,()=>dn(e,{device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...a.operations,...Yi({host:e,device:i.device,signal:i.scope.signal}),networkDump:async t=>await $n(e,i.device,t,i.scope.signal),...h(s,()=>Rr({host:e,device:i.device,owner:Y,signal:i.scope.signal})),...h(o.operations.audioProbeStart,()=>et({host:e.audioProbe.hostCapture,device:i.device,owner:Y})),...h(o.operations.perfFrames,()=>pn({resolveHost:()=>e.perf.apple,device:i.device,owner:Y})),...h(o.operations.captureSnapshot,()=>wo(e,{device:i.device,signal:i.scope.signal},n)),...h(o.operations.captureScreenshot,()=>Te({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...h(o.operations.focusPoint,()=>Ee({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...ke({device:i.device,signal:i.scope.signal,facts:o.operations,resolveInteractor:e.localInteractors.resolve}),...h(o.operations.scrollDirection,()=>Pe({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...h(o.operations.typeText,()=>Oe({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...h(o.operations.tapPoint,()=>Ge({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)})),...h(o.operations.readTextAtPoint,()=>be({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...h(o.operations.findText,()=>To(e,{device:i.device,signal:i.scope.signal})),...Ea({host:e,device:i.device,signal:i.scope.signal}),...Ha({host:e,device:i.device,signal:i.scope.signal}),...Co({device:i.device,signal:i.scope.signal}),...h(o.operations.ensureReady,()=>({ensureReady:async()=>await N(e,i.device,i.scope.signal)})),...h(o.operations.bootTarget,()=>({bootTarget:async t=>await N(e,i.device,i.scope.signal,{deadlineAtMs:t.deadlineAtMs})})),...h(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}))}})),...pe(wi({host:e,device:i.device,signal:i.scope.signal,observation:n}),o.operations),...h(o.operations.shutdownTarget,()=>({shutdownTarget:async()=>await e.deviceShutdown.apple.shutdownTarget(i.device,i.scope.signal)}))};return Object.freeze({device:a.device,owner:Y,facts:o,operations:un(c),[Symbol.asyncDispose]:async()=>await a[Symbol.asyncDispose]()})},shutdown:async()=>{await Promise.all([t.shutdown(),n.shutdown()])}})}function ks(e){let t=e.iosPhysicalDeviceBackend!==`xctest`&&s(e)!==`watchos`?X:es;return{frames:t,memorySample:t,memorySnapshot:t,nativeCapture:t,profileReport:t}}function As(e){return s(e)===`watchos`?as:e.kind===`simulator`||e.kind===`device`?X:os}function js(e){return s(e)===`watchos`?gs:e.kind===`simulator`||e.kind===`device`?X:gs}function Ms(e){return s(e)===`watchos`?vs:e.kind===`simulator`||e.kind===`device`?X:ys}function Ns(e){let t=js(e);return xe({capture:t,customActions:t.available&&f(e)&&e.kind===`simulator`?X:_s,withoutActiveApp:f(e)?bs:t})}export{Os as createApplePlatformRuntime};
1
+ import{F as e,I as t,J as n,K as r,P as i}from"./sdk-contracts.js";import{a,i as o,v as s}from"./sdk-batch-runner.js";import{c,r as l}from"./diagnostics.js";import"./diagnostics2.js";import{O as u,c as d,d as f,f as p,j as m,m as h,p as g,y as ee}from"./sdk-device.js";import{Xt as te,nn as _,rn as ne,tn as re}from"./sdk-batch.js";import{n as ie,r as ae}from"./session.js";import"./device.js";import{a as oe,u as v}from"./device-rotation.js";import{o as se,r as y}from"./exec.js";import"./command.js";import{r as ce}from"./version.js";import{n as le}from"./scoped-provider.js";import{i as ue,n as de,r as fe}from"./ios-snapshot-planning.js";import{t as pe}from"./request.js";import{n as me,r as he,t as ge}from"./application-lifecycle-runtime.js";import{A as _e,B as ve,C as ye,D as be,E as xe,G as Se,H as Ce,I as we,J as Te,K as Ee,L as De,N as Oe,O as ke,P as Ae,V as je,W as Me,d as Ne,h as Pe,j as Fe,n as Ie,o as Le,s as Re,v as ze,w as Be,x as Ve,z as He}from"./alert-runtime.js";import{n as Ue}from"./audio-probe-runtime.js";import{n as We}from"./perf-runtime.js";import{i as Ge,t as Ke}from"./touch-runtime.js";import{a as qe,n as Je}from"./durable-resource.js";import{n as Ye,t as Xe}from"./async-lifecycle.js";import{a as Ze,c as Qe,d as $e,f as et,l as tt,n as nt,o as rt,s as it,t as at,u as ot}from"./src7.js";import{n as st,t as ct}from"./screen-recording-completion.js";import{a as lt,c as ut,i as dt,n as ft,o as pt,r as mt,s as ht,t as gt}from"./device-readiness-runtime.js";import{n as _t}from"./screen-recording-runtime.js";import{t as vt}from"./ios-system-surface.js";import{i as yt,r as bt}from"./gesture-admission.js";import{t as xt}from"./interactor-operation-catalog.js";import{a as St,i as Ct,n as wt,r as Tt,t as Et}from"./perf-runtime-operation-builder.js";import{t as Dt}from"./app-log-runtime.js";import{n as Ot}from"./artifact-paths.js";import{i as kt,r as At}from"./managed-device-scope.js";import{a as jt,n as Mt,o as Nt}from"./application-lifecycle-interaction.js";import{f as Pt}from"./host-file.js";import{a as Ft,o as It,s as Lt}from"./config.js";import{a as Rt,o as zt}from"./tool-provider.js";import{o as Bt}from"./devicectl.js";import{t as Vt}from"./physical-device-apps.js";import{t as Ht}from"./apple-runner-platform.js";import{a as b,i as Ut,l as Wt,n as Gt,o as x,s as Kt}from"./simctl.js";import{a as qt,r as Jt}from"./simulator.js";import{r as Yt}from"./display-inventory.js";import{n as Xt,t as Zt}from"./app-backend.js";import{t as Qt}from"./simulator-state.js";import{a as $t,c as en,d as tn,i as nn,l as rn,n as an,o as on,r as sn,t as cn,u as ln}from"./cache.js";import{randomUUID as un}from"node:crypto";import S from"node:path";function dn(e){let t=kt();return Object.freeze(t?{...le({...e},e=>qt(t,e))}:e)}function fn(e,t){return Object.freeze({appState:async n=>{if(t.signal.throwIfAborted(),!await e.appleApplications.hasLiveRunnerSession(t.device,{}))return{};let r=await t.resolveInteractor(t.device,{appBundleId:n?.appBundleId,signal:t.signal});if(typeof r.appState!=`function`)throw ne(`Runtime owner advertised appState without an interactor implementation`);return await r.appState()}})}function pn(e){return pt(e)?Object.freeze({available:!0}):h(e)||g(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 mn(e){let{resolveHost:t,device:n,owner:r}=e;return Object.freeze({...Et({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)):wt(`Apple`,`bundle ID`),sampling:await t().frameSampling(n)}),perfMemorySample:async({appId:e})=>({metric:e?await Ct(t().sampleMemory(n,e)):wt(`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 Tt();let c=i??S.join(a,`memory-memgraph-${hn()}.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 hn(){return new Date().toISOString().replaceAll(/[:.]/g,`-`)}const C=Object.freeze({available:!0}),w=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),T=yn(`Gestures are supported only for Apple simulators and devices.`),gn=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:bt}),_n=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:yt}),vn=yn(`scroll is supported only for Apple simulators and devices.`);function yn(e){return Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:e})}function bn(e){return{...we({unsupported:xn(e),plan:Sn(e),directionalFling:Sn(e),multiTouch:Cn(e),targetAuthoredDrag:wn(e),viewport:Tn(e)}),...Oe({scroll:En(e)})}}function xn(e){return e.appleOs===`watchos`||e.appleOs===`visionos`?w:T}function Sn(e){return e.appleOs===`watchos`||e.appleOs===`visionos`?w:E(e)?C:T}function Cn(e){if(e.appleOs===`watchos`)return w;if(!E(e))return T;let t=u(e);if(t!==`ios`&&t!==`ipados`){let e=Xt[t];return Object.freeze({available:!1,reason:`unsupported-platform-leaf`,...e===void 0?{}:{hint:e}})}return e.kind===`simulator`?C:gn}function wn(e){return E(e)?(e.appleOs===void 0?e.target!==`desktop`&&e.target!==`tv`:e.appleOs===`ios`||e.appleOs===`ipados`)?C:_n:T}function Tn(e){return e.appleOs===`watchos`?w:E(e)?C:T}function En(e){return E(e)?C:vn}function E(e){return e.kind===`simulator`||e.kind===`device`}const D=`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`;function O(e){return h(e)?`macos`:e.kind===`device`?`ios-device`:`ios-simulator`}const Dn=Object.freeze({resourceKind:Dt,version:1,encode:e=>({...e}),decode:e=>!kn(e.transport)||!An(e.backend)||!Pn(e.outputPath)||!Mn(e.pidPath)||!jn(e.transport,e.backend)?On():{status:`decoded`,descriptor:Object.freeze({transport:e.transport,backend:e.backend,outputPath:e.outputPath,...e.pidPath===void 0?{}:{pidPath:e.pidPath}})}});function On(){return{status:`invalid`,message:`Invalid Apple app-log descriptor`}}function kn(e){return e===`apple-log-stream`||e===`coredevice-console`}function An(e){return e===`ios-simulator`||e===`ios-device`||e===`macos`}function jn(e,t){return e===`coredevice-console`?t===`ios-device`:t!==`ios-device`}function Mn(e){return e===void 0||Pn(e)}function Nn(e){if(!e.device.appleOs)throw TypeError(`Apple app-log persistence requires an explicit appleOs identity`);return Je({resourceKind:Dt,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:qe(Dn,e.descriptor)})}function Pn(e){return typeof e==`string`&&e.trim().length>0}const Fn={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.`},In={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 Ln(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 Rn(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 ut(async()=>ht(await e.appleTools.run({tool:`simctl`,args:Kt(),allowFailure:!0},r)),r);else if(t.iosPhysicalDeviceBackend===`xctest`)i.devicectlAvailable=!1,i.devicectlConsoleCapture=!1,a.push(D);else{i.devicectlAvailable=await ut(async()=>ht(await e.appleTools.run({tool:`devicectl`,args:[`--version`],allowFailure:!0},r)),r);let t=await Ln(e,r);if(i.devicectlConsoleCapture=t.supported,!t.supported){let e=t.reason===`unsupported`?Fn:In;a.push(`${e.message} ${e.hint}`)}}return{backend:O(t),checks:i,notes:a}}function zn(e,t){let n=Hn(e),r=[`subsystem == "${n}"`,`subsystem CONTAINS "${n}"`,`processImagePath ENDSWITH[c] "/${n}"`,`senderImagePath ENDSWITH[c] "/${n}"`];if(t){let e=Hn(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 Bn(e,t){return Gt(e,[`spawn`,e.id,`log`,`stream`,`--style`,`compact`,`--level`,`info`,`--predicate`,zn(t.appBundleId,t.executableName)])}function Vn(e,t){return[`devicectl`,`device`,`process`,`launch`,`--device`,e,`--console`,`--terminate-existing`,t]}function Hn(e){return e.replaceAll(`\\`,String.raw`\\`).replaceAll(`"`,String.raw`\"`)}async function Un(e,t,n,r,i){Wn(t),rt(e,n);let a=O(t),o=await Kn(e,t,n.appBundleId,i),s=new Xe,c=!1;try{let l=await e.outputs.openAppend(n.outputPath);s.defer(async()=>{c||await l[Symbol.asyncDispose]()}),i?.throwIfAborted();let u=await Gn(e,t,o,l,n.pidPath,i);s.defer(async()=>{c||await u[Symbol.asyncDispose]()});let d=Jn(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=et(d,Nn({sessionId:n.sessionId,device:t,owner:r,fence:n.fence,descriptor:f}));return c=!0,p}finally{await s[Symbol.asyncDispose]()}}function Wn(e){if(e.appleOs===`watchos`)throw new i(`UNSUPPORTED_PLATFORM`,`watchOS app logs are not supported`);if(g(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`)throw new i(`UNSUPPORTED_OPERATION`,D,{hint:D})}async function Gn(e,t,n,r,a,o){if(g(t)&&t.kind===`device`){let t=await Ln(e,o);if(!t.supported){let e=t.reason===`unsupported`?Fn:In;throw new i(t.reason===`unsupported`?`UNSUPPORTED_OPERATION`:`COMMAND_FAILED`,e.message,{backend:`ios-device`,hint:e.hint,stderr:t.stderr})}}return o?.throwIfAborted(),await e.processes.start({command:{kind:`host`,request:n},output:r,...a?{markerPath:a}:{}})}async function Kn(e,t,n,r){return h(t)?{executable:`log`,args:[`stream`,`--style`,`compact`,`--predicate`,zn(n)],allowFailure:!0}:t.kind===`device`?{executable:`xcrun`,args:Vn(t.id,n),allowFailure:!0}:{executable:`xcrun`,args:Bn(t,{appBundleId:n,executableName:await qn(e,t,n,r)}),allowFailure:!0}}async function qn(e,t,n,r){let i=await e.appleTools.run({tool:`simctl`,args:x(t,[`get_app_container`,t.id,n,`app`]),allowFailure:!0,timeoutMs:4e3},r),a=i.exitCode===0?i.stdout.trim():``;if(!a)return;let o=await e.commands.run({executable:`plutil`,args:[`-extract`,`CFBundleExecutable`,`raw`,`-o`,`-`,S.join(a,`Info.plist`)],allowFailure:!0,timeoutMs:4e3},r);return o.exitCode===0&&o.stdout.trim()||void 0}function Jn(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 ot({inspect:()=>({backend:r,state:o,startedAt:a}),finish:async()=>s??=(async()=>(await Yn([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 Yn(e){let t=[];for(let n of e)try{await n()}catch(e){t.push(e)}return t}const k=te(`apple`),A=Object.freeze({available:!0});function Xn(e){return Object.freeze({owner:k,ownsDevice:e=>e.platform===`apple`,inspectFacts:async e=>Qn(e),bind:async t=>{if(t.intent.kind===`exact-owner`&&!re(t.intent.owner,k))throw new i(`UNSUPPORTED_OPERATION`,`Apple app-log owner identity does not match`);return Zn(e,t.device,t.scope.signal)},shutdown:async()=>void 0})}function Zn(e,t,n){if(t.platform!==`apple`)throw new i(`UNSUPPORTED_PLATFORM`,`Apple app-log owner cannot bind ${t.platform}`);let r=$e({codec:Dn,reattach:async(n,r)=>n.backend!==O(t)||!Ze(e,r.sessionId,n)?{status:`unreattachable`,reason:`descriptor-invalid`,message:`Apple app-log descriptor does not match the bound device or owning session`}:await Qe(e,n.pidPath),cleanup:async(n,r)=>n.backend===O(t)&&Ze(e,r.sessionId,n)?await it(e,n.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:O(t)}),appLogDoctor:async({appBundleId:r})=>await Rn(e,t,r,n),appLogStart:async r=>await Un(e,t,r,k,n),...r});return Object.freeze({device:t,owner:k,facts:Qn(t),operations:a,[Symbol.asyncDispose]:async()=>void 0})}function Qn(e){if(e.appleOs===`watchos`)return $n(e);let t=g(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?{available:!1,reason:`unsupported-device-backend`,hint:D}: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 $n(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 er(e,t,n,r){let i=O(t),a=await e.appLogs.readRecent(n.sessionId,n.maxScanLines),o=nt(a.text,{...n,path:a.path,exists:a.exists,lineNumberOffset:a.skippedLines,backend:i}),s=[];if(nr(t,n,o.dump)){let i=await rr(e,t,n,a.path,r);i&&(o=tr(s,o,i,n.maxEntries))}return or(s,t,n),ar(s,o.dump),o.dump.entries.length===0&&s.push(sr(t)),Object.freeze({source:`app-log`,backend:i,dump:o.dump,notes:Object.freeze(s)})}function tr(e,t,n,r){let i=n.scan.dump.entries.length;return i===0&&(n.scan.dump.unnamedRequests??0)===0?(n.lineCount>0&&e.push(`Recovered ${n.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.`),t):(i>0&&e.push(`Recovered ${i} iOS simulator HTTP entr${i===1?`y`:`ies`} from simctl log show (${n.lineCount} app log lines scanned).`),at(n.scan,t,r))}function nr(e,t,n){return g(e)&&e.kind===`simulator`&&!!t.appBundleId&&n.entries.length===0}async function rr(e,t,n,r,i){let a=n.appLogSnapshot?.startedAt,o=x(t,[`spawn`,t.id,`log`,`show`,`--style`,`compact`,`--info`,`--predicate`,ir(n.appBundleId),...typeof a==`number`&&Number.isFinite(a)&&a>0?[`--start`,`@${Math.floor(a/1e3)}`]:[`--last`,`5m`]]),s=await e.appleTools.run({tool:`simctl`,args:o,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{scan:nt(`${c.join(`
3
+ `)}\n`,{...n,path:`${r} (simctl log show recovery)`,exists:!0,backend:`ios-simulator`}),lineCount:c.length}}function ir(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 ar(e,t){let n=t.entries.filter(e=>e.pathUnavailable).length,r=t.unnamedRequests??0,i=n+r;if(i===0)return;let a=[`${i} request${i===1?``:`s`} reused a keep-alive connection, so CFNetwork logged no request URL.`];n>0&&a.push(`${n} listed against the origin the connection was opened for, without a path.`),r>0&&a.push(`${r} opened before this scan window and are missing from the entries entirely; scan more lines, or run logs clear --restart before the repro.`),a.push(`Absence of an endpoint in this dump does not prove it was not called.`),e.push(a.join(` `))}function or(e,t,n){n.appLogSnapshot?n.appLogSnapshot.state!==`active`&&e.length===0&&e.push(g(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 sr(e){return g(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.`:g(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 cr(t){let{host:n,snapshot:r,targetLabel:i,recorderWarning:a,nativePathDisposition:o}=t,s=r.invalidatedReason?{recorder:`lost`,why:`owner-session-lost`}:t.stopObservation;if(r.invalidatedReason&&!r.showTouches)throw Error(`recording invalidated: ${r.invalidatedReason}`);let c;try{c=await n.screenRecording.finalize.complete({outputPath:r.outPath,showTouches:!r.invalidatedReason&&r.showTouches,gestureEvents:r.gestureEvents,exportQuality:r.exportQuality??`medium`,...r.fps===void 0?{}:{fps:r.fps},targetLabel:i})}catch(t){throw e(t,`COMMAND_FAILED`)}let l=[...c.warning?[c.warning]:[],...a?[a]:[]];return ct(r,{...c,...l.length>0?{warning:l.join(` `)}:{},...r.invalidatedReason?{overlayWarning:`overlay unavailable: ${r.invalidatedReason}`}:{}},{stopObservation:s,...o===void 0?{}:{nativePathDisposition:o}})}async function lr(e){let{host:t,snapshot:n,targetLabel:r,collectedPath:i,exportPath:a,nativePath:o}=e;if(n.invalidatedReason&&!n.showTouches)throw Error(`recording invalidated: ${n.invalidatedReason}`);let s=e.overlayUnavailable??n.invalidatedReason,c;try{await t.screenRecording.outputs.copy({from:i,to:a}),c=await ur(()=>t.screenRecording.finalize.complete({outputPath:a,showTouches:s===void 0&&n.showTouches,gestureEvents:n.gestureEvents,exportQuality:n.exportQuality??`medium`,...n.fps===void 0?{}:{fps:n.fps},targetLabel:r}))}catch(e){throw await t.screenRecording.outputs.remove(a),e}return{...c,...s===void 0?{}:{overlayWarning:`overlay unavailable: ${s}`},nativePathDisposition:await t.screenRecording.outputs.remove(o)===`removed`?`retired`:`retirable`}}async function ur(t){try{return await t()}catch(t){throw e(t,`COMMAND_FAILED`)}}const dr=[`outPath`,`startedAt`,`clientOutPath`,...dt],j=Object.freeze({resourceKind:_t,version:1,encode:e=>e.backend===`simctl`?{backend:e.backend,outputPath:e.outputPath,processes:e.processes.map(e=>({...e})),...e.recording===void 0?{}:{recording:{...e.recording}}}:{backend:e.backend,outputPath:e.outputPath,appBundleId:e.appBundleId,runnerSessionId:e.runnerSessionId,runnerAuthority:e.runnerAuthority,...e.remotePath===void 0?{}:{remotePath:e.remotePath}},decode:e=>Cr(e)});function fr(e){let{device:t,owner:n,input:r,descriptor:i}=e;return Je({resourceKind:_t,sessionId:r.sessionId,device:m(t),owner:n,fence:r.fence,lifecycle:`open`,descriptor:qe(j,i)})}function pr(e){let t={};for(let n of dr)e[n]!==void 0&&Object.assign(t,{[n]:e[n]});return t}async function mr(e,t,n,r){let i=j.decode(n);return i.status!==`decoded`||!Nr(t,i.descriptor)?{status:`cleanup-pending`,reason:`manual-recovery-required`}:i.descriptor.backend===`simctl`?await hr(e,i.descriptor.processes,r):await _r(e,t,i.descriptor)}async function hr(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(gr(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(gr(n)),i.every(e=>e===`already-missing`)?{status:`already-missing`}:{status:`cleaned`})}function gr(e){return{kind:`session`,sessionId:e}}async function _r(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 vr(e){let{host:t,device:n,envelope:r}=e,i=j.decode(r.descriptor.body);return i.status===`decoded`?Nr(n,i.descriptor)?i.descriptor.backend===`simctl`?await yr(e,i.descriptor):await xr(t,n,i.descriptor):M(`descriptor-invalid`,`Apple screen-recording descriptor does not match the bound device.`):M(`descriptor-invalid`,i.message)}async function yr(e,t){let n=await Promise.all(t.processes.map(async t=>await e.host.screenRecording.apple.inspectProcess(t)));if(!n.every(e=>e===`missing`))return M(`transport-not-reattachable`,n.includes(`ownership-lost`)?`Apple recording ownership no longer matches the durable descriptor.`:`Apple screen recordings require exact cleanup after daemon restart.`);let{recording:r}=t,i=br(mt(e.envelope.metadata),t.outputPath);return r===void 0||i!==void 0&&!await Sr(e.host,i)?{status:`missing`}:{status:`restore-export`,recording:r,nativePath:t.outputPath,cleanup:async()=>await hr(e.host,t.processes,e.envelope.sessionId)}}function br(e,t){if(e.finalization===void 0)return e.collectedPath??t}async function xr(e,t,n){let r=await e.screenRecording.apple.inspectRunner(t,n.runnerSessionId,n.runnerAuthority);return r===`missing`?{status:`missing`}:M(`transport-not-reattachable`,r===`ownership-lost`?`Apple recording ownership no longer matches the durable descriptor.`:`Apple screen recordings require exact cleanup after daemon restart.`)}async function Sr(e,t){try{return await e.screenRecording.finalize.sniff({outputPath:t}),!0}catch{return!1}}function M(e,t){return{status:`unreattachable`,reason:e,message:t}}function Cr(e){return typeof e.outputPath!=`string`||e.outputPath.length===0?P():e.backend===`simctl`?wr(e,e.outputPath):e.backend===`runner`?Dr(e,e.outputPath):P()}function wr(e,t){let n=Pr(e.processes),r=Tr(e.recording);return!n||r===`invalid`?P():{status:`decoded`,descriptor:Object.freeze({backend:`simctl`,outputPath:t,processes:n,...r===void 0?{}:{recording:r}})}}function Tr(e){if(e!==void 0)return s(e)&&Er(e)?Object.freeze(e):`invalid`}function Er(e){return N(e.outPath)&&kr(e.startedAt)&&Or(e.clientOutPath)&&lt(e)}function Dr(e,t){return!N(e.appBundleId)||!N(e.runnerSessionId)||!Ar(e.runnerAuthority)||!jr(e.remotePath)?P():{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 N(e){return typeof e==`string`&&e.length>0}function Or(e){return e===void 0||N(e)}function kr(e){return typeof e==`number`&&Number.isFinite(e)}function Ar(e){return e===`local-lease`||e===`scoped-provider`}function jr(e){return e===void 0||Mr(e)}function Mr(e){return typeof e==`string`&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(e)}function Nr(e,t){return e.kind===`simulator`?t.backend===`simctl`:t.backend===`runner`?e.appleOs===`macos`?t.remotePath===void 0:g(e)?t.remotePath!==void 0&&Mr(t.remotePath):t.remotePath===void 0:!1}function Pr(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 P(){return{status:`invalid`,message:`Invalid Apple screen-recording descriptor`}}async function Fr(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.`)}const Ir=`iOS recording`,Lr=`simctl recordVideo`;function Rr(e){return e.appleOs===`watchos`?$r(`unsupported-platform-leaf`,`watchOS recording is not supported.`):g(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?$r(`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 zr(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await Br({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async e=>{let r=await vr({host:t,device:n,envelope:e.envelope});return r.status===`restore-export`?{status:`active`,handle:Hr({host:t,restored:r})}:r},screenRecordingCleanup:async e=>await mr(t,n,e.envelope.descriptor.body,e.envelope.sessionId)})}async function Br(e){return e.signal.throwIfAborted(),e.device.kind===`simulator`?await Vr(e):await Wr(e)}async function Vr(e){let{host:t,device:n,owner:r,input:i,signal:a}=e;await Fr(n,i,t.screenRecording.apple.isRunnerBundleId);let o=i.activeSessionApp?await t.screenRecording.apple.captureClockAnchor(n,i.activeSessionApp.bundleId,a):void 0,s=Ot(i.outputPath);await t.screenRecording.outputs.prepare(s);let c=await t.screenRecording.apple.startSimulator(n,s,a),l=c.markers;if(!l||l.length===0)throw await Yr(c).catch(()=>{}),Error(`simctl recordVideo did not expose durable process identity`);try{a.throwIfAborted(),t.screenRecording.ownedProcesses.replace({kind:`session`,sessionId:i.sessionId},l.map(e=>({...e,purpose:`simctl-screen-recording`})))}catch(e){try{t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId})}catch{}throw await Yr(c).catch(()=>{}),e}let u,d,f=async()=>{await c.terminate();let e=await c.wait;return d=e,u=Kr(e),t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId}),{observation:{recorder:`confirmed`},...u===void 0?{}:{warning:`${u} before record stop; the video covers only what the recorder wrote before it stopped.`}}},p=Qr(i,Lr,{},o);return Zr({device:n,owner:r,input:i,descriptor:{backend:`simctl`,outputPath:s,processes:l,recording:pr(p)},snapshot:p,finish:(e,n)=>ft({snapshot:e,progress:n,steps:{stop:f,collect:async e=>{try{await Ur(t,s,e)}catch(e){throw qr(e,u,d)}},finalize:async({collectedPath:n,exportPath:r})=>{try{return await lr({host:t,snapshot:e,targetLabel:Ir,collectedPath:n,exportPath:r,nativePath:s})}catch(e){throw qr(e,u,d)}},discard:async e=>{await t.screenRecording.outputs.remove(e)}}}),cleanup:async()=>{let e=await Xr(c);return(e.status===`cleaned`||e.status===`already-missing`)&&t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId}),e}})}function Hr(e){let{host:t,restored:{recording:n,nativePath:r,cleanup:i}}=e,a=Object.freeze({...n,backend:Lr,gestureEvents:[]});return st(a,{finish:(e,i)=>ft({snapshot:e,progress:i,steps:{stop:async()=>({observation:{recorder:`confirmed`},warning:`simctl recordVideo had already ended when record stop reattached to it; the video covers only what the recorder wrote before it stopped.`}),collect:async e=>{await Ur(t,r,e)},finalize:async({collectedPath:i,exportPath:a})=>await lr({host:t,snapshot:e,targetLabel:Ir,collectedPath:i,exportPath:a,nativePath:r,...n.showTouches?{overlayUnavailable:`the daemon that held the touch events ended before record stop`}:{}}),discard:async e=>{await t.screenRecording.outputs.remove(e)}}}),forceCleanup:async()=>await i()})}async function Ur(e,t,n){await e.screenRecording.outputs.copy({from:t,to:n}),await e.screenRecording.finalize.sniff({outputPath:n})}async function Wr(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??=Gr(()=>t.screenRecording.apple.runRunner(n,{kind:`stop`,appBundleId:o,...c}).then(()=>void 0)).catch(e=>{throw l=void 0,e}),l);if(!Jr(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 Zr({device:n,owner:r,input:i,descriptor:{backend:`runner`,outputPath:i.outputPath,appBundleId:o,...c,...s.remotePath===void 0?{}:{remotePath:s.remotePath}},snapshot:Qr(i,`runner AVAssetWriter`,s),finish:async e=>(await u(),s.remotePath!==void 0&&await t.screenRecording.apple.retrieveRunnerRecording(n,s.remotePath,e.outPath),await cr({host:t,snapshot:e,targetLabel:n.appleOs===`macos`?`macOS recording`:`iOS recording`,stopObservation:{recorder:`confirmed`},...s.remotePath===void 0?{}:{nativePathDisposition:`retirable`}})),cleanup:async()=>(await u(),{status:`cleaned`})})}async function Gr(t){try{return await t()}catch(t){throw e(t,`COMMAND_FAILED`)}}function Kr(e){if(e.exitCode!==0)return e.signal?`simctl recordVideo was killed by ${e.signal}`:`simctl recordVideo exited with code ${e.exitCode}`}function qr(t,n,r){let a=e(t,`COMMAND_FAILED`);return n===void 0||r===void 0||a.details?.reason!==`recording-output-unplayable`?t:new i(a.code,`${a.message}; ${n}`,y(r,{...a.details??{},...r.signal===void 0?{}:{signal:r.signal},retriable:!1,hint:`The recorder exited before record stop, so the next record stop reads the same file. Close this session to release the device, then record again.`}))}function Jr(e,t){return e.appleOs===`macos`||!g(e)?t===void 0:t!==void 0&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(t)}async function Yr(e){return await e.terminate(),await e.wait}async function Xr(e){try{return await Yr(e),{status:`cleaned`}}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`Apple simulator cleanup failed`}}}function Zr(e){let{device:t,owner:n,input:r,descriptor:i,snapshot:a,finish:o,cleanup:s}=e,c=st(a,{finish:o,forceCleanup:s});return Object.freeze({pendingHandle:new Ye(c),envelope:fr({device:t,owner:n,input:r,descriptor:i})})}function Qr(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},...e.fps===void 0?{}:{fps:e.fps},gestureEvents:[],...r===void 0?{}:{gestureClockOriginAtMs:r.wallClockAtMs,gestureClockOriginUptimeMs:r.uptimeMs},...n.recorderStartUptimeMs===void 0?{}:{gestureClockOriginAtMs:i,gestureClockOriginUptimeMs:n.recorderStartUptimeMs,runnerStartedAtUptimeMs:n.recorderStartUptimeMs},...n.runnerSessionId===void 0?{}:{runnerSessionId:n.runnerSessionId}})}function $r(e,t){return Object.freeze({available:!1,reason:e,hint:t})}const ei=15e3;async function F(e,t,n,r={}){return n.throwIfAborted(),await At(t)||h(t)?{...t,booted:!0}:t.kind===`device`?(await e.deviceReadiness.applePhysical.ensureConnected(t,n),{...t,booted:!0}):t.kind===`simulator`?((await ti(e,t)?`Booted`:await si(e,t,n))!==`Booted`&&(r.onColdBootStart?.(),e.deviceReadiness.appleAutomation.keepHot(t),await ni(e,t,n,r.deadlineAtMs),await ci(e,n)),e.deviceReadiness.appleAutomation.keepHot(t),e.deviceReadiness.appleAutomation.markBooted(t),{...t,booted:!0}):{...t,booted:!0}}async function ti(e,t){try{return await e.deviceReadiness.appleAutomation.wasRecentlyObservedBooted(t)}catch{return!1}}async function ni(e,t,n,r=Date.now()+12e4){let i=!1;try{i=await ri(e,t,n,r),await ii(e,t,n,r)}catch(a){throw i&&n.aborted&&li(e,t),n.throwIfAborted(),Date.now()>=r?oi(t,a):a}}async function ri(e,t,n,r){let a=await e.appleTools.run({tool:`simctl`,args:x(t,[`boot`,t.id]),allowFailure:!0,timeoutMs:ai(r,t)},n),o=`${a.stdout}\n${a.stderr}`.toLowerCase(),s=o.includes(`already booted`)||o.includes(`current state: booted`);if(a.exitCode!==0&&!s)throw new i(`COMMAND_FAILED`,`simctl boot failed`,{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode});return!s}async function ii(e,t,n,r){pe({type:`command`,status:`progress`,message:`Waiting for the Simulator to finish booting...`});let a=await e.appleTools.run({tool:`simctl`,args:x(t,[`bootstatus`,t.id,`-b`]),allowFailure:!0,timeoutMs:ai(r,t)},n);if(a.exitCode!==0)throw new i(`COMMAND_FAILED`,`simctl bootstatus failed`,{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode});if(await Qt(e.appleTools,t,n,Math.min(ei,ai(r,t)))!==`Booted`)throw new i(`COMMAND_FAILED`,`Simulator is still booting`,{deviceId:t.id});if(Date.now()>=r)throw oi(t)}function ai(e,t){let n=e-Date.now();if(n<=0)throw oi(t);return n}function oi(e,t){return new i(`COMMAND_FAILED`,`Simulator did not finish booting within the startup budget`,{reason:gt,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.`},t instanceof Error?t:void 0)}async function si(e,t,n){return await Qt(e.appleTools,t,n,ei)}async function ci(e,t){await e.commands.run({executable:`open`,args:[`-a`,`Simulator`],allowFailure:!0,timeoutMs:1e4},t)}function li(e,t){e.appleTools.run({tool:`simctl`,args:x(t,[`shutdown`,t.id]),allowFailure:!0}).catch(()=>{})}const ui=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:`runner`,setSetting:`simulator`,readSetting:`simulator`,setFoldPose:`simulator`,captureSnapshot:`simulator`,captureSnapshotWithoutActiveApp:`simulator`,captureSnapshotWithCustomActions:`runner`,captureScreenshot:`simulator`,findText:`runner`,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`,actionButton:`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 di(e){return e===void 0?`possible`:e.some(e=>ui[e]===`runner`)?`required`:`none`}const fi=3e3,pi=`simulator-target-discovery-pending`,mi=`simulator-target-unavailable`;function hi(){let e=new Map,t=new Map,n=ln({waitMs:1500});return async(r,i,a,o)=>{a.throwIfAborted();let s=`${r.id}:${i}`,c=e.get(s);if(c&&o!==`refresh`){let e=await rn(c.pid,{signal:a,timeoutMs:fi});if(a.throwIfAborted(),e===c.processStartTime)return c}return e.delete(s),await n.value(s,{start:async()=>{let n=await yi(r,i,t);return e.set(s,n),n},wait:(e,t)=>tn({waitMs:e,signal:a,stop:t,cancelled:()=>gi(a)}),pending:()=>I(pi,r,i)})}}function gi(e){return t({readinessPhase:`target-discovery`},e.reason)}function _i(e){return e instanceof i&&e.details?.reason===pi}function vi(e){return e instanceof i&&e.details?.reason===mi}async function yi(e,t,n){let r=Date.now()+15e3,[i,a]=await Promise.allSettled([b(e,[`spawn`,e.id,`launchctl`,`list`],{allowFailure:!0,timeoutMs:Si(r)}),bi(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 I(`simulator-target-probe-failed`,e,t);let c=xi(o.stdout,t);if(!c)throw I(mi,e,t);let l=await rn(c.pid,{timeoutMs:Math.min(fi,Si(r))});if(!l)throw I(`simulator-target-identity-unavailable`,e,t);return Object.freeze({simulator:Wt(e),runtime:s,pid:c.pid,generation:`${c.pid}:${c.label}:${l}`,targetId:`${e.id}:${t}`,processStartTime:l})}async function bi(e,t,n){let r=t.get(e.id);if(r)return await r;let i=b(e,[`list`,`devices`,`-j`],{allowFailure:!0,timeoutMs:Si(n)}).then(t=>{if(t.exitCode!==0)throw I(`simulator-runtime-probe-failed`,e,``);let n=Object.entries(Ut(t.stdout)).find(([,t])=>t.some(t=>t.udid===e.id))?.[0];if(!n)throw I(`simulator-runtime-unavailable`,e,``);return n});t.set(e.id,i);try{return await i}catch(n){throw t.delete(e.id),n}}function xi(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 Si(e){return Math.max(1,e-Date.now())}function I(e,t,n){return new i(`COMMAND_FAILED`,`Unable to resolve the running iOS Simulator app (${e}).`,{reason:e,deviceId:t.id,appBundleId:n})}function Ci(e){return e?.observation===`unobservable`&&e.proof===`no-running-process`}const wi=new Map([[`application-element-missing`,5e3],[`application-server-unavailable`,5e3],[`foreground-owner-unverified`,1e3],[`foreground-owner-changed`,1e3]]);function L(e){return e.platform===`apple`&&e.appleOs===`ios`&&e.kind===`simulator`}function Ti(e){let t=ue(fe({depth:1,interactiveOnly:!0}));return Object.freeze({awaitObservable:async(n,r,i)=>{if(!L(n))return{observation:`not-eligible`};let a;for(;;){let o=await Di(e.resolveTarget,n,r,i);if(`verdict`in o)return o.verdict;let{target:s}=o;if(e.isBridgeDisabled(s))return l({level:`debug`,phase:`ios_launch_observation_skipped`,data:{reason:`circuit-disabled`,deviceId:n.id,generation:s.generation}}),Ei({source:`circuit`});let c=await e.source.acquire({target:s,hint:t,signal:i});if(c.stage!==`failed`)return{observation:`observable`};i.throwIfAborted();let{kind:u,code:d}=c.failure,f=wi.get(d);if(f===void 0)return Ei({source:`bridge`,kind:u,code:d});let p=e.clock.now();if(a=Math.min(a??1/0,p+f),p>=a)return{observation:`unobservable`,proof:`launch-transition`};await e.clock.sleep(Math.min(150,a-p),i)}}})}function Ei(e){return{observation:`probe-failed`,failure:e}}async function Di(e,t,r,i){for(;;)try{return{target:await e(t,r,i)}}catch(e){if(i.throwIfAborted(),_i(e))continue;if(vi(e))return{verdict:{observation:`unobservable`,proof:`no-running-process`}};let{code:t,details:r}=n(e),a=r?.reason;return{verdict:Ei(typeof a==`string`?{source:`target`,code:t,reason:a}:{source:`target`,code:t})}}}function Oi(e,t,n){let r=n&&L(e),i=r?di(t.execution.plannedOperations):void 0,a=g(e)&&t.surface===`app`&&t.positionals.length>0&&!!t.appBundleId&&i!==`none`;return{...i?{runnerDemand:i}:{},shouldPrewarmRunner:a,awaitPrewarmAfterOpen:t.relaunch&&!r}}function ki(e,t,n,r){r.runnerDemand===`none`&&e.appleApplications.releaseSpeculativeRunner(t.device,n.execution).catch(()=>{})}async function Ai(e,t,n,r,a,o){let s=Date.now(),c=async()=>await Fi(t,n,r,a.observation),l=await c(),u,d=a.answerConfirmation,f=d&&l?.observation!==`observable`?await ji(d,a.redispatchLaunchUrl,c,l):void 0;if(f&&(o.runnerDemand=`required`,u=f.launchConfirmation,l=f.observed,f.unanswered))throw new i(`COMMAND_FAILED`,`The Simulator has not completed the launch URL for ${n.appBundleId}.`,{reason:`launch_confirmation_unanswered`,appBundleId:n.appBundleId,hint:`iOS may still be holding an "Open in" prompt, or the answer died with the runner session that raised it. Inspect the current alert before deciding on another action.`});return r&&l?.observation!==`observable`&&await e.clock.sleep(300,t.signal),l&&(o.postOpenObservation=l.observation,l.observation===`probe-failed`&&(o.postOpenObservationFailure=l.failure)),o.postOpenSettleDurationMs=Math.max(0,Date.now()-s),u}async function ji(e,t,n,r){let i={observed:r,acceptAttempted:!1,confirmationStillPresent:!1};for(let r=0;r<2;r+=1){i=await Mi(e,n,i);let a=r===1;if(i.confirmationStillPresent||a||!Ni(i)||!t)break;await t()}return{observed:i.observed,launchConfirmation:i.launchConfirmation,unanswered:Ni(i)||i.confirmationStillPresent}}async function Mi(e,t,n){let r=await e(),i=r.outcome===`unanswered`&&r.reason===`alert-still-present`,a=n.acceptAttempted||Pi(r),o=r.outcome===`accepted`?`accepted`:n.launchConfirmation;return a?{observed:await t(),launchConfirmation:o,acceptAttempted:a,confirmationStillPresent:i}:{observed:n.observed,launchConfirmation:o,acceptAttempted:a,confirmationStillPresent:i}}function Ni(e){return e.acceptAttempted&&Ci(e.observed)}function Pi(e){return e.outcome===`accepted`||e.outcome===`unanswered`&&e.reason===`alert-still-present`||e.outcome===`unreadable`&&e.step===`alert-accept`}async function Fi(e,t,n,r){if(!(!n||!L(e.device))&&!(!r||!t.appBundleId))return await r.awaitObservable(e.device,t.appBundleId,e.signal)}let Ii;const Li=()=>Ii??=import(`./launch-confirmation.js`);function Ri(e){let t=Mt({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 F(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 zi(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 Qi(e.host,t,n),finalizeApplicationClose:async t=>await $i(e.host,e.device,e.signal,t),prepareAppleRunner:async t=>await ea(e.host,e.device,e.signal,t),configureProviderPortReverse:oa})}async function zi(e,t,n,r){let i={},a=R(t.device),o=ra(t.device,n,a),s=ta(e,t,n,i),c=Oi(t.device,n,a);c.runnerDemand&&(i.runnerDemand=c.runnerDemand),ki(e,t,n,c);let{shouldPrewarmRunner:l}=c,u=Zi(t.device,n,a);a&&l&&!n.prewarmRunnerBeforeOpen&&s.schedule();try{await Bi(e,t,n,a,u,i),await Vi(n,i),await Hi(s,l,n.prewarmRunnerBeforeOpen);let d=s.wasAwaited();await Ui(t,n,o,a,i),await Ji(s,l,c.awaitPrewarmAfterOpen),await Yi(e,t,n,a,d,u);let f=await Ai(e,t,n,a,{observation:r,answerConfirmation:Ki(t,n,o),redispatchLaunchUrl:qi(t,n,o)},i);return{appBundleId:n.appBundleId,timing:i,...f?{launchConfirmation:f}:{}}}catch(n){throw u&&await e.appleApplications.stopRunnerSession(t.device.id).catch(()=>{}),n}}async function Bi(e,t,n,r,i,a){if(!Xi(n,r)||!n.target)return;let o=Date.now();f(t.device.platform)&&!r&&!i&&await e.appleApplications.stopRunnerSession(t.device.id),await jt({device:t.device,interactor:await t.resolveInteractor(n.execution,n.appBundleId),positionals:[n.appBundleId??n.target]}),r&&await e.clock.sleep(300,t.signal),a.relaunchCloseDurationMs=z(o)}async function Vi(e,t){if(!he(e.runtimeHints))return;if(!e.applyRuntimeHints)throw new i(`COMMAND_FAILED`,`Runtime hint operation was not admitted for this open.`,{reason:`runtime-hints-operation-missing`});let n=Date.now();await e.applyRuntimeHints({appId:e.appBundleId,values:e.runtimeHints}),t.runtimeHintsDurationMs=z(n)}async function Hi(e,t,n){!t||!n||(e.schedule(!0),await e.wait())}async function Ui(e,t,n,r,i){let a=Date.now();await Nt({device:e.device,interactor:await e.resolveInteractor(t.execution,t.appBundleId),positionals:n.positionals,appBundleId:t.appBundleId,execution:t.execution,...r&&t.relaunch&&!t.execution.clearAppState?{terminateRunningApp:!0}:{}}),i.openDispatchDurationMs=z(a),await Wi(e,t,n.followUpUrl,i)}async function Wi(e,t,n,r){if(!n){r.launchUrlDurationMs=0;return}let i=Date.now();await Gi(e,t,n),r.launchUrlDurationMs=z(i)}async function Gi(e,t,n){let r={...t.execution,clearAppState:void 0,launchConsole:void 0,launchArgs:void 0};await Nt({device:e.device,interactor:await e.resolveInteractor(r,t.appBundleId),positionals:[n],appBundleId:t.appBundleId,execution:r})}function Ki(e,t,{confirmation:n}){if(n)return async()=>{let{answerSimulatorLaunchConfirmation:r}=await Li();return await r(e.device,n,e.resolveInteractor(t.execution,n.appBundleId),e.signal)}}function qi(e,t,{confirmation:n}){if(n)return async()=>{await Gi(e,t,n.url)}}async function Ji(e,t,n){t&&!e.wasScheduled()&&e.schedule(),n?await e.wait():e.recordUnawaited()}async function Yi(e,t,n,r,i,a){!g(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 Xi(e,t){return!!(e.relaunch&&e.target)&&!(t&&!e.execution.clearAppState)}function Zi(e,t,n){return e.kind===`device`&&e.appleOs===`ios`&&Xi(t,n)}async function Qi(e,t,n){n.ensureReady&&await F(e,t.device,t.signal),f(t.device.platform)&&!R(t.device)&&await e.appleApplications.stopRunnerSession(t.device.id),await jt({device:t.device,interactor:await t.resolveInteractor(n.execution,n.appBundleId),positionals:n.positionals}),R(t.device)&&await e.clock.sleep(300,t.signal)}async function $i(e,t,n,r){r.daemonShutdown||await e.appleApplications.releaseRunnerOnClose(t.id,{retain:r.retainRunner}),await e.appleApplications.dismissCloseAlerts(t,r).catch(()=>{});let i=r.shutdownTarget&&R(t)?await e.deviceShutdown.apple.shutdownTarget(t,n):void 0;return i===void 0?{}:{shutdown:i}}async function ea(e,t,n,r){let i=Date.now()+r.timeoutMs;await F(e,t,n,{deadlineAtMs:i});let a=Math.max(1,i-Date.now());return await e.appleApplications.prepareRunner(t,{...r,timeoutMs:a},n)}function ta(e,t,n,r){let i,a=!1,o=na(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=z(e)},wasAwaited:()=>a,wasScheduled:()=>i!==void 0,recordUnawaited:()=>{i&&!a&&(r.runnerPrewarmWaited=!1)}}}function na(e,t){return e.kind===`device`&&e.appleOs===`ios`&&!t.hasExistingSession&&!t.relaunch&&!t.prewarmRunnerBeforeOpen}function ra(e,t,n){let r=t.runtimeLaunchUrl?.trim(),i=t.positionals.length===1?t.positionals[0]?.trim():void 0;if(!r||!i||o(i))return{positionals:t.positionals};let a=ia(e,t.appBundleId,r),s=a?{confirmation:a}:{};return n&&!aa(t)?{positionals:[i,r],...s}:{positionals:t.positionals,followUpUrl:r,...s}}function ia(e,t,n){if(e.appleOs===`ios`&&e.kind===`simulator`&&!(t===void 0||a(n)))return{url:n,appBundleId:t}}function aa(e){return e.execution.clearAppState===!0||!!e.execution.launchConsole?.trim()||!!e.execution.launchArgs?.length}function R(e){return g(e)&&e.kind===`simulator`}function z(e){return Math.max(0,Date.now()-e)}async function oa(){throw new i(`UNSUPPORTED_OPERATION`,`This lifecycle operation is unavailable for Apple.`)}const sa=Object.freeze({available:!0}),ca=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.`}),la=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Push notifications are supported on Apple simulators only.`}),ua=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),da=Object.freeze({available:!1,reason:`unsupported-device-kind`});function fa(e){let t=ba(e);return Object.freeze({deployApp:t,materializeAppSource:t,deployMaterializedApp:t,sendPushNotification:xa(e)})}function pa(e){let{host:t,device:n,signal:r}=e,i=fa(n);return Object.freeze({...i.deployApp.available?{deployApp:async e=>await ma(t,n,e,r),materializeAppSource:async e=>await t.appleDeployment.prepareArtifact(e,{signal:r}),deployMaterializedApp:async e=>await ha(t,n,e,r)}:{},...i.sendPushNotification.available?{sendPushNotification:async e=>(await va(t,n,e,r),{})}:{}})}async function ma(e,t,n,r){if(n.replaceExisting)return await e.appleDeployment.withInvalidatedAppResolutionCache(t,async()=>{let i=await e.appleDeployment.resolveAppBundleId(t,n.app);await _a(e,t,i,r);let a=await e.appleDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{appIdentifierHint:n.app,signal:r});try{return await ga(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 ha(e,t,{artifact:i},r)}finally{await i.cleanup()}}async function ha(e,t,n,r){return await ga(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 ga(e,t,n,r){await F(e,t,r),await ya(e,t.kind===`simulator`?{tool:`simctl`,args:x(t,[`install`,t.id,n])}:{tool:`devicectl`,args:[`device`,`install`,`app`,`--device`,t.id,n],timeoutMs:Ft},r,`Apple app install failed`)}async function _a(e,t,n,r){await F(e,t,r),await ya(e,t.kind===`simulator`?{tool:`simctl`,args:x(t,[`uninstall`,t.id,n])}:{tool:`devicectl`,args:[`device`,`uninstall`,`app`,`--device`,t.id,n]},r,`Apple app uninstall failed for ${n}`,{tolerate:e=>Vt(`${e.stdout}\n${e.stderr}`.toLowerCase())})}async function va(e,t,n,r){if(t.kind!==`simulator`)throw new i(`UNSUPPORTED_OPERATION`,`Apple push notifications require a simulator`);await F(e,t,r);let a=await e.temporaryFiles.create({prefix:`agent-device-ios-push-`,suffix:`.apns`});try{await a.writeText(`${JSON.stringify(n.payload)}\n`),await ya(e,{tool:`simctl`,args:x(t,[`push`,t.id,n.appId,a.path])},r,`Apple push notification failed`)}finally{await a[Symbol.asyncDispose]()}}async function ya(e,t,n,r,i){let a=await e.appleTools.run({...t,allowFailure:!0},n);return i?.tolerate?.(a)?a:se(a,r,e=>({cmd:`xcrun`,args:[t.tool,...t.args],...t.tool===`devicectl`?{hint:Bt(e.stdout,e.stderr)??`Ensure the iOS device is unlocked, trusted, and available in Xcode > Devices, then retry.`}:{}}))}function ba(e){return Sa(e)?e.kind!==`simulator`&&e.kind!==`device`?da:e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?ca:sa:ua}function xa(e){return Sa(e)?e.kind===`simulator`?sa:la:ua}function Sa(e){return g(e)&&e.appleOs!==`watchos`}const B=Object.freeze({available:!0}),Ca=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`back is supported on Apple simulators and physical devices.`}),wa=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function Ta(e){return e.kind!==`simulator`&&e.kind!==`device`?Ca:u(e)===`watchos`?wa:B}const Ea=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`home is supported on Apple simulators and physical devices.`}),Da=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Oa=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`app-switcher is supported on Apple simulators and physical devices.`});function ka(e,t){if(e.kind!==`simulator`&&e.kind!==`device`)return t;let n=u(e);return n===`macos`||n===`watchos`?Da:B}function V(e){if(e.kind!==`simulator`&&e.kind!==`device`)return!1;let t=u(e);return t!==`tvos`&&t!==`macos`&&t!==`watchos`}const Aa=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`orientation is supported on Apple simulators and physical devices.`}),ja=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function Ma(e){return e.kind!==`simulator`&&e.kind!==`device`?Aa:V(e)?B:ja}const Na=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`tv-remote is supported only on tvOS devices.`});function Pa(e){return(e.kind===`simulator`||e.kind===`device`)&&ee(e)?B:Na}const H=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Fa=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 Ia(e){return V(e)?Fa:H}function La(e){return V(e)?B:H}function Ra(e){return V(e)?B:H}const za=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`No Apple leaf carries this system button.`}),Ba=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`action-button is supported on iPhone and iPad simulators and physical devices.`}),Va=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`The Action Button is iPhone and iPad hardware; tvOS, macOS, watchOS and visionOS have no such control.`});function Ha(e){return e.kind!==`simulator`&&e.kind!==`device`?Ba:d(e)?B:Va}function Ua(e){return Object.freeze({...Be({back:Ta(e)}),...Ne({unsupported:za,home:ka(e,Ea),appSwitcher:ka(e,Oa),actionButton:Ha(e)}),...ye({orientation:Ma(e)}),...Ve({tvRemote:Pa(e)}),...ze({unsupported:H,status:Ia(e),dismiss:La(e),enter:Ra(e)})})}function Wa(e){let{host:t,device:n,signal:r,admitted:i}=e,a=Object.keys(Ua(n));return xt({device:n,signal:r,resolveInteractor:t.localInteractors.resolve,facts:Object.fromEntries(a.map(e=>[e,i[e]]))})}const U=Object.freeze({available:!0}),Ga=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`clipboard is supported on Apple simulators and the macOS host.`}),Ka=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`settings is supported on Apple simulators and the macOS host.`}),qa=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.`}),Ja=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:"Apple targets answer a settings read only on iPhone and iPad simulators, where `simctl ui` reports the value the device holds."}),Ya=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.`}),W=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function Xa(e,t,n){if(e.kind!==`simulator`&&e.kind!==`device`)return t;let r=u(e);return r===`watchos`?W:e.kind===`simulator`||r===`macos`?U:n}function Za(e){return Xa(e,Ga,Ya)}const Qa=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`trigger-app-event is supported on Apple simulators and physical devices.`}),$a=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`alert is supported on Apple simulators and physical devices.`}),eo=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`alert is supported on Apple simulators, the macOS host, and physical iOS devices.`});function to(e){if(e.kind!==`simulator`&&e.kind!==`device`)return $a;let t=u(e);return t===`watchos`?W:e.kind===`simulator`||t===`ios`||t===`macos`?U:eo}function no(e){return e.kind!==`simulator`&&e.kind!==`device`?Qa:u(e)===`watchos`?W:U}function ro(e){let t=Za(e);return t.available?Ya:t}function io(e){return e.kind!==`simulator`&&e.kind!==`device`?Ka:u(e)===`watchos`?W:p(e)?U:Ja}function ao(e){let t=Za(e),n=to(e);return Object.freeze({...Pe({unsupported:ro(e),read:t,write:t}),...Ie({read:n,wait:n,accept:n,dismiss:n}),...Re({triggerAppEvent:no(e)}),...Le({setSetting:Xa(e,Ka,qa),readSetting:io(e)})})}function oo(e){let{host:t,device:n,signal:r}=e;return xt({device:n,signal:r,resolveInteractor:t.localInteractors.resolve,facts:ao(n)})}function so(e){return Object.freeze({setFoldPose:e.fold})}const co=/Angle:\s*(-?\d+(?:[.,]\d+)?)\s*°/g;async function lo(e,t={}){let n=[`devicectl`,`device`,`motion`,`hinge-angle`,`--device`,e.id,`--session-timeout`,`1`,`--timeout`,`5`],r=await zt(n,{allowFailure:!0,signal:t.signal,timeoutMs:Lt}),a=uo(r.stdout)??uo(r.stderr);if(a!==void 0)return a;throw new i(`COMMAND_FAILED`,`CoreDevice reported no hinge angle sample`,y(r,{cmd:`xcrun`,args:n,stdout:r.stdout,stderr:r.stderr,deviceId:e.id,hint:`This Xcode/CoreDevice toolchain does not stream 'devicectl device motion hinge-angle' for this device. Foldable poses can be verified only through that stream; update Xcode to a version that ships it.`}))}function uo(e){let t;for(let n of e.matchAll(co)){let e=Number.parseFloat(n[1].replace(`,`,`.`));Number.isFinite(e)&&(t=e)}return t}const fo=`Fold.m`,po=3e4,mo=Ht+po;async function ho(e={}){let t=e.host??go(),n=on(mo,e.signal);try{let r=e.sourceRoot??S.join(ce(),`apple`,`fold-helper`),i=await sn(t,r,[fo],n),a=await nn(t,n),o=e.cacheRoot??S.join(Pt(),`.agent-device`,`fold-helper`);return await cn({host:t,deadline:n,lockDescription:`iOS Simulator fold helper cache`,cacheRoot:o,binaryFilename:`fold-helper`,keyInputs:{schemaVersion:1,sourceHash:i,toolchain:a,compileArgv:_o({sourceRoot:``,outputPath:``})},build:e=>vo(t,n,r,e)})}catch(e){throw yo(e)}}function go(){return $t(Rt)}function _o(e){return[`--sdk`,`iphonesimulator`,`clang`,`-mios-simulator-version-min=15.0`,`-fobjc-arc`,`-Wall`,`-Wextra`,`-framework`,`Foundation`,`-framework`,`IOKit`,S.join(e.sourceRoot,fo),`-o`,e.outputPath]}async function vo(e,t,n,r){let i=await an({host:e,deadline:t,argv:_o({sourceRoot:n,outputPath:r}),budgetMs:po,label:`fold helper`});if(i.exitCode!==0||!e.exists(r))throw bo(y(i))}function yo(e){return!(e instanceof en)||e.buildFailureKind===`cancelled`?e:bo({...e.buildDetails,cause:e.buildFailureCode},e)}function bo(e,t){return new i(`COMMAND_FAILED`,`Unable to build the simulator fold helper`,{hint:`Select an Xcode with the iOS simulator SDK and foldable HID support using DEVELOPER_DIR.`,...e,reason:`fold-helper-build-failed`},t)}async function xo(e,t,n){n?.throwIfAborted();let r=await ho({signal:n});n?.throwIfAborted();let a=typeof t==`string`?0:t.at(-1).atMs,o=typeof t==`string`?t:JSON.stringify(t),s=await b(e,[`spawn`,e.id,r.path,o],{signal:n,timeoutMs:a+1e4,kill:{signal:`SIGTERM`,graceMs:1e3},allowFailure:!0});if(s.exitCode!==0)throw new i(`COMMAND_FAILED`,`Unable to send the simulator hinge pose`,y(s,{reason:`fold-hid-dispatch-failed`,deviceId:e.id}))}async function So(e,t,n={}){n.signal?.throwIfAborted(),Jt(e,`fold`);let r=t,i=r.keyframes?.at(-1)?.angle,a=r.pose??v(i);Co(e,await Yt(e,{signal:n.signal})),await xo(e,r.keyframes??a,n.signal),l({level:`info`,phase:`apple_fold_pose_dispatched`,data:{deviceId:e.id,pose:a}});let o=await wo(e,a,n.signal,i),s=await No(e,n.signal);return{pose:v(o),hingeAngleDegrees:o,...s?{screen:Po(s)}:{}}}function Co(e,t){if(t.unresolved)throw new i(`COMMAND_FAILED`,`CoreDevice reported no display table for this simulator`,{deviceId:e.id,hint:`fold needs 'devicectl device info displays' to tell a foldable from a single-panel simulator; update Xcode to a version that ships the display-information feature.`});if(!t.multiScreen)throw new i(`UNSUPPORTED_OPERATION`,`${e.name} is not a foldable simulator: fold requires more than one integrated panel`,{deviceId:e.id,reason:`single-panel-device`,hint:`fold sets the hinge angle of a foldable simulator such as iPhone Duo; this simulator reports one integrated panel, so it has no hinge to pose.`})}async function wo(e,t,n,r){let i,a;for(let o=1;o<=4;o+=1)if(n?.throwIfAborted(),a=i,i=await lo(e,{signal:n}),To(i,a,t,r))return i;throw Oo(e,t,i,a,r)}function To(e,t,n,r){return r===void 0?v(e)===n?n!==`half-open`||t!==void 0&&ko(e,t):!1:Eo(e,t,r)}function Eo(e,t,n){return Do(e,n)?n===0||n===180||t!==void 0&&Do(t,n)&&Math.abs(e-t)<=.5:!1}function Do(e,t){return t===void 0||e!==void 0&&Math.abs(e-t)<=.5}function Oo(e,t,n,r,a){return Do(n,a)?a!==void 0&&n!==void 0?Mo(e,v(n),n,r):n!==void 0&&t===`half-open`&&v(n)===t?Mo(e,t,n,r):jo(e,t,n):new i(`COMMAND_FAILED`,`The hinge did not reach the final keyframe angle`,{reason:`fold-angle-unverified`,targetAngleDegrees:a,hingeAngleDegrees:n,deviceId:e.id})}function ko(e,t){return v(e)===`half-open`&&v(t)===`half-open`&&Math.abs(e-t)<=.5}function Ao(e,t,n){return{deviceId:e.id,requestedPose:t,observedPose:n===void 0?void 0:v(n),hingeAngleDegrees:n}}function jo(e,t,n){return new i(`COMMAND_FAILED`,`${e.name} did not reach the ${t} pose: CoreDevice still reports a hinge angle of ${n}°`,{...Ao(e,t,n),reason:`fold-pose-unverified`,hint:`The simulator HID command completed, but the hinge did not follow. Verify that the selected Xcode and simulator runtime support foldable HID control, then retry.`})}function Mo(e,t,n,r){return new i(`COMMAND_FAILED`,`${e.name} was observed ${t} at ${n}° but did not settle: 4 hinge reads never held two consecutive angles within ${It}° of each other`,{...Ao(e,t,n),reason:`fold-pose-unsettled`,...r===void 0?{}:{previousHingeAngleDegrees:r},hint:`The hinge reached the requested pose and was still moving when the read budget ended. Retry the fold, then read the angle directly with xcrun devicectl device motion hinge-angle --device <udid> --session-timeout 1 --timeout 5 to see whether the simulator holds the pose.`})}async function No(e,t){let n=await Yt(e,{signal:t});if(!(n.unresolved||n.ambiguous))return n.activeDisplay}function Po(e){return{display:e.name,coordinateSpace:oe,widthPt:Math.round(e.widthPx/e.pointScale),heightPt:Math.round(e.heightPx/e.pointScale)}}const Fo=Object.freeze({available:!0}),Io=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`fold is supported on foldable iPhone simulators controlled through simulator HID; a physical device is folded by hand.`}),Lo=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`fold poses the hinge of a foldable iPhone; tvOS, macOS, watchOS and visionOS simulators have no hinge.`});function Ro(e){return{available:!1,reason:`unsupported-device-scope`,hint:`fold cannot resolve a simulator scoped to the set at "${e}": CoreDevice's display inventory and hinge-angle readback need a simulator in the default set, so the pose could not be verified. Run fold without --ios-simulator-device-set.`}}function zo(e){if(e.kind!==`simulator`)return Io;let t=u(e);return t!==`ios`&&t!==`ipados`?Lo:e.simulatorSetPath?Ro(e.simulatorSetPath):Fo}function Bo(e){return so({fold:zo(e)})}function Vo(e){let{device:t,signal:n}=e;return _(Bo(t).setFoldPose,()=>({setFoldPose:async e=>(n.throwIfAborted(),await So(t,e,{signal:n}))}))}function Ho(e,t,n){let r=Ce({device:t.device,signal:t.signal,resolveInteractor:e.localInteractors.resolve}),i=async i=>{let a=h(t.device)?ie(i.options?.surface,t.appBackend):void 0;if(a)return await e.snapshot.captureSurface(t.device,{...i.options,surface:a},Me(t.signal,i));if(!n)return await r.captureSnapshot(i);let o=Me(t.signal,i);return await n.capture(t.device,i,o,async e=>await r.captureSnapshot(e))};return Object.freeze({captureSnapshot:i,captureSnapshotWithCustomActions:i,captureSnapshotWithoutActiveApp:i})}function Uo(e,t){return Object.freeze({findText:async n=>{let r=await Wo(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}}})}async function Wo(e,t,n){let r=n.options?.appBundleId;if(r===void 0||h(t.device)&&ae(n.options?.surface,t.appBackend)===`macos-helper`)return;let i=n.signal?AbortSignal.any([t.signal,n.signal]):t.signal;if(i.throwIfAborted(),await Go(e,t.device,n.execution))return{appBundleId:r,signal:i}}async function Go(e,t,n){return!L(t)||await e.appleApplications.hasLiveRunnerSession(t,n??{})}const G=Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`The native macOS app backend never starts the XCTest runner, which this command needs. Unset AGENT_DEVICE_MACOS_APP_BACKEND to use XCTest.`});function Ko(e,t){return!h(e)||t!==`native`?{}:Object.freeze({screenRecordingStart:G,screenRecordingReattach:G,prepareAppleRunner:G,longPressPoint:G,...Be({back:G}),...we({unsupported:G})})}function qo(){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()}}}function Jo(e=Date.now){let t=new Map;return async(n,r)=>{if(n.kind!==`simulator`)return`absent`;let i=t.get(n.id);if(i!==void 0&&e()-i.at<1e3)return{kind:`present`,host:i.host};t.delete(n.id);let a=await Yo(n,r);return a!==`absent`&&a!==`unknown`&&t.set(n.id,{at:e(),host:a.host}),a}}async function Yo(e,t){let n=!1;for(let r of vt){let i=await Xo(r.processExecutable,t);if(i===`unknown`){n=!0;continue}for(let a of i){let i=await Zo(a,e.id,t);if(i===`unknown`)n=!0;else if(i)return{kind:`present`,host:r}}}return n?`unknown`:`absent`}async function Xo(e,t){let n=await Qo(`pgrep`,[`-f`,e],t);return n===`unknown`?`unknown`:n.exitCode===1?[]:n.exitCode===0?n.stdout.split(`
5
+ `).map(e=>Number.parseInt(e.trim(),10)).filter(e=>Number.isSafeInteger(e)&&e>0):`unknown`}async function Zo(e,t,n){let r=await Qo(`ps`,[`eww`,`-p`,String(e),`-o`,`command=`],n);return r===`unknown`||r.exitCode!==0?`unknown`:r.stdout.includes(`SIMULATOR_UDID=${t}`)?!0:!r.stdout.includes(`SIMULATOR_UDID=`)&&`unknown`}async function Qo(e,t,n){try{let r=await Rt(e,t,{allowFailure:!0,timeoutMs:3e3,...n?{signal:n}:{}});return{exitCode:r.exitCode,stdout:r.stdout}}catch{return`unknown`}}const $o=`system-surface-presented`,es=`system-surface-host-lingering`,ts=`window-coordinate-space-unresolved`;function ns(e,t={}){let n=t.source??qo(),r=t.resolveTarget??hi(),a=t.systemSurfacePresent??Jo(),o=new Set,s=new Map,l=e=>(_s(e,s,o),o.has(vs(e))),u=Ti({source:n,resolveTarget:r,clock:e.clock,isBridgeDisabled:l});return Object.freeze({awaitObservable:u.awaitObservable,shutdown:async()=>await n.close(),capture:async(t,s,u,d)=>{if(!as(t,s))return await ls(t,s,d);let f=await a(t,u);if(f===`unknown`)return await K(t.id,s,d,ds(t.id,s),q(s),`system-surface-probe-unavailable`,[gs()]);if(f!==`absent`)return await cs(t,s,d,f.host.bundleId);let p;try{p=await rs(e,r,t,s,u)}catch(e){return is(u,e),J(`target-resolution-failed`,t,void 0,e),await K(t.id,s,d,ds(t.id,s),q(s),`target-resolution-failed`,[gs()])}if(l(p))return J(`circuit-disabled`,t,p.generation),await K(t.id,s,d,p,q(s),`circuit-disabled`);let m=q(s),h=await n.acquire({target:p,hint:ue(m),signal:u});if(h.stage===`failed`){if(h.failure.kind===`cancelled`)throw u.throwIfAborted(),new i(`COMMAND_FAILED`,`Simulator AX snapshot acquisition was cancelled.`,{reason:h.failure.code,...h.failure.details});let e=await hs(h.failure,p,t,s.options.appBundleId,u,r);return await os(s,d,p,e,m,h.failure,o)}try{return await c(`ios.snapshot-source.present`,async()=>await e.snapshot.presentIosAcquisition(h,s.options),{producer:`simulator-ax-bridge`})}catch(e){return await os(s,d,p,{lineage:p,residue:[]},m,{kind:`malformed-tree`,code:`presentation-invariant`},o,e)}}})}async function rs(e,t,n,r,i){let a=r.options.appBundleId;for(;;)try{return await t(n,a,i)}catch(t){if(!_i(t))throw t;let i={requestId:r.execution?.requestId};if(await e.appleApplications.hasLiveRunnerSession(n,i))throw t}}function is(e,t){if(e.aborted)throw r(t)?t:e.reason}function as(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 os(e,t,n,r,i,a,o,s){return ss(a)&&o.add(vs(n)),J(a.code,{id:n.simulator.udid},n.generation,s,a.details),await K(n.simulator.udid,e,t,r.lineage,i,a.code,r.residue)}function ss(e){return e.kind!==`preparing`&&e.code!==ts}async function K(e,t,n,r,i,a,o=[]){return us(e,await n(t),r,i,a,o)}async function cs(e,t,n,r){let i=await n(t),a=i.systemSurface?$o:es;return i.systemSurface||J(a,e,void 0,void 0,{detectedHost:r}),us(e.id,i,ds(e.id,t),q(t),a)}async function ls(e,t,n){let r=await n(t),i=r.systemSurface;return i?{...r,comparisonIdentity:ps(fs(e.id,i.bundleId),q(t),[])}:r}function us(e,t,n,r,i,a=[]){let o=t.systemSurface;return{...t,comparisonIdentity:ps(o?fs(e,o.bundleId):n,r,[...o?[]:a,{kind:`fallback-source`,producer:`apple-runner`}]),warnings:[...t.warnings??[],ms(i,n,o!==void 0)]}}function ds(e,t){return{targetId:`${e}:${t.options.appBundleId}`}}function fs(e,t){return{targetId:`${e}:${t}`}}function ps(e,t,n){return Object.freeze({producer:`apple-runner`,intent:t.acquisitionIntent,lineage:Object.freeze({...e.targetId?{targetId:e.targetId}:{},...e.generation?{generation:e.generation}:{}}),presentationKey:de(t),residue:Object.freeze([...n])})}function ms(e,t,n){return e===$o?`Simulator AX snapshot inapplicable (${e}); used XCTest to read the system surface presented over the app.`:e===es?`Simulator AX snapshot inapplicable (${e}); used XCTest, which read app content: the system surface host process was still running but no longer presenting.`:n?`Simulator AX snapshot unavailable (${e}); used XCTest, which read the system surface presented over the app.`:e===`bridge-preparation-pending`?`Simulator AX snapshot unavailable (${e}); used XCTest for this capture while the bridge is still being prepared.`:e===ts?`Simulator AX snapshot unavailable (${e}); used XCTest for this capture, which reports captured geometry in the app's own orientation space.`:`Simulator AX snapshot unavailable (${e}); used XCTest for ${t.generation?`this app generation`:`an unverified app generation`}.`}async function hs(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(),J(`fallback-target-resolution-failed`,n,void 0,e),{lineage:{targetId:t.targetId},residue:[gs()]}}}function gs(){return{kind:`unknown-generation`,captureId:un()}}function q(e){return fe({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 _s(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 vs(e){return`${e.targetId}:${e.generation}`}function J(e,t,n,r,i){l({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 Y=te(`apple`),X=Object.freeze({available:!0}),Z=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),ys=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.`}),bs=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.`}),xs=Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`perf requires an Apple simulator, macOS device, or CoreDevice-backed physical Apple device.`}),Ss=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`focus is supported on Apple simulators and physical devices.`}),Cs=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple appstate is unavailable here: the runner reads the session app's XCUIApplication state on iOS-family simulators and physical devices only, and the Apple target answers no sessionless foreground probe. The per-command answer is the targetActivation disclosure, which a capture carries when its command had to re-activate the session app (#2682).`});function ws(e){return!g(e)||e.appleOs===`watchos`?Cs:e.kind===`simulator`||e.kind===`device`?X:Cs}const Ts=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Headless boot is supported only for local Android emulators.`}),Es=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS has no XCUITest-driveable UI, so element text comes from the captured tree only.`}),Ds=Object.freeze({available:!1,reason:`unsupported-device-kind`}),Os=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS open is not supported because XCUITest cannot drive watchOS UI.`}),ks=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS runner preparation is not supported because XCUITest cannot drive watchOS UI.`}),As=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS close is not supported because XCUITest cannot drive watchOS UI.`}),js=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Runtime hints are supported only for local iOS-family simulators and Android devices.`}),Ms=Q(`open is supported only for Apple simulators and devices.`),Ns=Q(`prepare is supported only for Apple simulators and devices.`),Ps=Q(`close is supported only for Apple simulators and devices.`),Fs=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`}),Is=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`shutdown is supported only for Apple simulators and Android emulators.`}),Ls=Q(`snapshot is supported only for Apple simulators and devices.`),Rs=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Re-run without --actions, or target an iOS simulator.`}),zs=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`screenshot is not supported on watchOS because XCUITest cannot drive watchOS UI.`}),Bs=Q(`screenshot is supported only for Apple simulators and devices.`),Vs=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`Open the app under test before capturing its snapshot.`});function Q(e){return Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:e})}function Hs(e){return!g(e)||e.appleOs===`watchos`?Z:e.kind===`simulator`?X:Is}function Us(e){let t=Ws(e),n=Gs(e),r=Ks(e),i=qs(e);return ge({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:i,clearRuntimeHints:i,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:n,configureProviderPortReverse:Fs})}function Ws(e){return u(e)===`watchos`?Os:e.kind===`simulator`||e.kind===`device`?X:Ms}function Gs(e){return u(e)===`watchos`?ks:e.kind===`simulator`||e.kind===`device`?X:Ns}function Ks(e){return u(e)===`watchos`?As:e.kind===`simulator`||e.kind===`device`?X:Ps}function qs(e){return u(e)!==`watchos`&&g(e)&&e.kind===`simulator`?X:js}function Js(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.`}):X}function $(e){return e.kind===`simulator`||e.kind===`device`?X:Ss}function Ys(e){let t=Xn(e),n=ns(e),r,i=e=>h(e)?r??=Zt():`xctest`,a=async n=>{let r=await t.inspectFacts(n),a=fa(n),o=Rr(n),s=o.available?await e.screenRecording.apple.availability(n):void 0,c=o.available&&s?.available===!1?Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:s.hint}):o,l=n.appleOs===`watchos`?Z:X,u=h(n)||n.appleOs===`watchos`?Z:X,d=Js(n);return Object.freeze({device:r.device,operations:{...r.operations,...a,appState:ws(n),networkDump:X,screenRecordingStart:c,screenRecordingReattach:c,screenRecordingCleanup:c,...ec(n),...Te({capture:$s(n)}),...je({findText:Qs(n)}),...ve({setViewport:ys}),...He({focus:$(n)}),...bn(n),..._e({type:$(n)}),...Ge({unsupported:Z,tap:$(n),longPress:$(n),fill:$(n),...g(n)?{tapElementSelector:$(n)}:{}}),...be({readTextAtPoint:Zs(n)}),...Ua(n),...Bo(n),...ao(n),...Ue({capture:pn(n),query:bs}),...We(Xs(n)),ensureReady:l,bootTarget:u,bootTargetHeadless:Ts,listApps:d,...Us(n),shutdownTarget:Hs(n),...Ko(n,i(n))}})};return Object.freeze({owner:Y,ownsDevice:e=>e.platform===`apple`,inspectFacts:a,bind:async r=>{let o=await t.bind(r),s=await a(r.device),c=s.operations.screenRecordingStart,l={..._(s.operations.appState,()=>fn(e,{device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...o.operations,...pa({host:e,device:r.device,signal:r.scope.signal}),networkDump:async t=>await er(e,r.device,t,r.scope.signal),..._(c,()=>zr({host:e,device:r.device,owner:Y,signal:r.scope.signal})),..._(s.operations.audioProbeStart,()=>tt({host:e.audioProbe.hostCapture,device:r.device,owner:Y})),..._(s.operations.perfFrames,()=>mn({resolveHost:()=>e.perf.apple,device:r.device,owner:Y})),..._(s.operations.captureSnapshot,()=>Ho(e,{device:r.device,signal:r.scope.signal,appBackend:i(r.device)},n)),..._(s.operations.captureScreenshot,()=>Ee({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),..._(s.operations.focusPoint,()=>De({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...Ae({device:r.device,signal:r.scope.signal,facts:s.operations,resolveInteractor:e.localInteractors.resolve}),..._(s.operations.scrollDirection,()=>Fe({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),..._(s.operations.typeText,()=>ke({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),..._(s.operations.tapPoint,()=>Ke({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:s.operations,pause:async t=>await e.clock.sleep(t,r.scope.signal)})),..._(s.operations.readTextAtPoint,()=>xe({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),..._(s.operations.findText,()=>Uo(e,{device:r.device,signal:r.scope.signal,appBackend:i(r.device)})),...Wa({host:e,device:r.device,signal:r.scope.signal,admitted:s.operations}),...oo({host:e,device:r.device,signal:r.scope.signal}),...Vo({device:r.device,signal:r.scope.signal}),..._(s.operations.ensureReady,()=>({ensureReady:async()=>await F(e,r.device,r.scope.signal)})),..._(s.operations.bootTarget,()=>({bootTarget:async t=>await F(e,r.device,r.scope.signal,{deadlineAtMs:t.deadlineAtMs})})),..._(s.operations.listApps,()=>({listApps:async e=>{r.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}))}})),...me(Ri({host:e,device:r.device,signal:r.scope.signal,observation:n}),s.operations),..._(s.operations.shutdownTarget,()=>({shutdownTarget:async()=>await e.deviceShutdown.apple.shutdownTarget(r.device,r.scope.signal)}))};return Object.freeze({device:o.device,owner:Y,facts:s,operations:dn(l),[Symbol.asyncDispose]:async()=>await o[Symbol.asyncDispose]()})},shutdown:async()=>{await Promise.all([t.shutdown(),n.shutdown()])}})}function Xs(e){let t=e.iosPhysicalDeviceBackend!==`xctest`&&u(e)!==`watchos`?X:xs;return{frames:t,memorySample:t,memorySnapshot:t,nativeCapture:t,profileReport:t}}function Zs(e){return u(e)===`watchos`?Es:e.kind===`simulator`||e.kind===`device`?X:Ds}function Qs(e){return u(e)===`watchos`?Ls:e.kind===`simulator`||e.kind===`device`?X:Ls}function $s(e){return u(e)===`watchos`?zs:e.kind===`simulator`||e.kind===`device`?X:Bs}function ec(e){let t=Qs(e);return Se({capture:t,customActions:t.available&&g(e)&&e.kind===`simulator`?X:Rs,withoutActiveApp:g(e)?Vs:t})}export{Ys as createApplePlatformRuntime};
@@ -1 +1 @@
1
- import{q as e}from"./sdk-contracts.js";import{p as t}from"./sdk-device.js";import{o as n}from"./simctl.js";import{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
+ import{J as e}from"./sdk-contracts.js";import{p as t}from"./sdk-device.js";import{o as n}from"./simctl.js";import{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{N as e}from"./sdk-contracts.js";import{A as t}from"./sdk-device.js";import{Xt as n,nn as r}from"./sdk-batch.js";import{n as i}from"./device-shell.js";import{n as a,t as o}from"./application-lifecycle-runtime.js";import{A as s,B as c,C as l,D as u,G as d,H as f,I as p,J as ee,K as te,L as ne,N as re,O as ie,P as ae,V as oe,d as se,h as ce,j as le,n as ue,o as de,s as fe,v as m,w as h,x as g,z as pe}from"./alert-runtime.js";import{n as me}from"./audio-probe-runtime.js";import{n as he}from"./perf-runtime.js";import{i as ge,t as _e}from"./touch-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{n as xe,t as y}from"./screen-recording-completion.js";import{t as b}from"./screen-recording-options.js";import{n as x}from"./screen-recording-runtime.js";import{i as S}from"./gesture-admission.js";import{t as C}from"./interactor-operation-catalog.js";import{i as w,n as T}from"./perf-runtime-operation-builder.js";import{t as E}from"./app-log-runtime.js";import{n as D,t as O}from"./application-lifecycle-interaction.js";import{randomUUID as k}from"node:crypto";import{setTimeout as A}from"node:timers/promises";const j=Object.freeze({resourceKind:E,version:1,encode:e=>({...e}),decode:e=>e.transport!==`harmony-hilog`||!N(e.outputPath)||!N(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 M(e){return v({resourceKind:E,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:_(j,e.descriptor)})}function N(e){return typeof e==`string`&&e.trim().length>0}function Se(e){return be(e,{family:`harmonyos`,backend:`harmonyos`,label:`HarmonyOS`,codec:j,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 a=await Ce(e,r);return{resolvePid:async r=>await ye(e,{executable:a,args:i(`hdc`,`shell`,[`pidof`,n.appBundleId],[`-t`,t.id]),allowFailure:!0,timeoutMs:5e3},r),command:e=>({kind:`host`,request:{executable:a,args:i(`hdc`,`shell`,[`hilog`,`-P`,e],[`-t`,t.id]),allowFailure:!0}})}},descriptor:({artifacts:e})=>({transport:`harmony-hilog`,...e}),envelope:({input:e,device:t,owner:n,descriptor:r})=>M({sessionId:e.sessionId,device:t,owner:n,fence:e.fence,descriptor:r})})}async function Ce(t,n){n.throwIfAborted(),await P(async()=>await t.toolchains.prepare(`harmonyos`),n),n.throwIfAborted();let r=await P(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 P(e,t){try{return await e()}catch(e){throw t.throwIfAborted(),e}}function we(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 w(t().sampleMemory(n,e)):T(`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 F=Object.freeze({resourceKind:x,version:1,encode:e=>({...e}),decode:e=>e.backend===`harmony-screen-recorder`&&typeof e.fileName==`string`&&De(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 Te(e){let{device:n,owner:r,input:i,descriptor:a}=e;return v({resourceKind:x,sessionId:i.sessionId,device:t(n),owner:r,fence:i.fence,lifecycle:`open`,descriptor:_(F,a)})}function Ee(e){return F.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 De(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 Oe(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 ke(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await Ae({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=>Ee(e.envelope.descriptor.body)})}async function Ae(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`);b(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-${k()}.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=je(a),d=!1,f=async()=>{d||=(B(await n.screenRecording.harmony.stop(r),`stop`),!0)},p=xe(u,{finish:async e=>await Me(n,r,e,c,f),forceCleanup:async()=>await R(n,r,c,f)});return Object.freeze({pendingHandle:new ve(p),envelope:Te({device:r,owner:i,input:a,descriptor:c})})}function je(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 Me(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 Ne(e,t,r,a);return y(n,{...i,...L(i.warning,o)},{stopObservation:{recorder:`confirmed`},nativePathDisposition:o===void 0?`retired`:`retirable`,showTouches:!1})}catch(n){throw await e.screenRecording.harmony.remove(t,r.remotePath).catch(()=>{}),n}}async function Ne(e,t,n,r){let i=[];return await I(()=>e.screenRecording.harmony.remove(t,n.remotePath))||i.push(`staging artifact`),await I(()=>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 I(e){try{return await e()}catch{return!1}}function L(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{runHarmonyShell:r}=await import(`./hdc.js`),i=await r(t,[`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 O({owner:`HarmonyOS`,openTargetIdentity:`bundle-id`,binding:D({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 Ke(t,n,[`install`,`-r`,r.appPath],i,18e4),r.replaceExisting&&(await A(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,[`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,[`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 Ke(e,t,n,r,i=15e3){return await e.run({executable:`hdc`,args:[`-t`,t.id,...n],timeoutMs:i},r)}async function U(e,t,n,r,a=15e3){return await e.run({executable:`hdc`,args:i(`hdc`,`shell`,n,[`-t`,t.id]),timeoutMs:a},r)}const W=n(`harmonyos`),qe=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`HarmonyOS reads element text from the captured tree only.`}),Je=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`}),Ye=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`HarmonyOS appstate is supported only for HarmonyOS emulators and devices.`}),Xe=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple runner preparation is supported only for Apple targets.`}),q=Object.freeze({available:!0}),Ze=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`open is supported only for HarmonyOS emulators and devices.`}),Qe=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`close is supported only for HarmonyOS emulators and devices.`}),$e=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.`}),et=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`screenshot is supported only for HarmonyOS emulators and devices.`}),tt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Re-run without --actions, or target an iOS simulator.`}),nt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`viewport resizes web targets only (--platform web).`});function rt(e){let t=it(e),n=at(e);return o({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:K,clearRuntimeHints:K,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:Xe,configureProviderPortReverse:$e})}function it(e){return e.kind===`emulator`||e.kind===`device`?q:Ze}function at(e){return e.kind===`emulator`||e.kind===`device`?q:Qe}const Y=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Gestures are supported on HarmonyOS emulators and physical devices.`}),ot=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),st=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:S});function X(e){return e.kind===`emulator`||e.kind===`device`?G:Y}function Z(e){return e.kind===`emulator`||e.kind===`device`?G:Je}const Q=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),ct=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 lt(e){let t=Se(e),n=async e=>{let n=await t.inspectFacts(e),r=H(e),i=Oe(e);return Object.freeze({device:n.device,operations:{...n.operations,...r,appState:e.kind===`simulator`?Ye:G,networkDump:K,screenRecordingStart:i,screenRecordingReattach:i,screenRecordingCleanup:i,...d({capture:e.kind===`emulator`||e.kind===`device`?G:J,customActions:tt,withoutActiveApp:e.kind===`emulator`||e.kind===`device`?G:J}),...ee({capture:e.kind===`emulator`||e.kind===`device`?G:et}),...oe({findText:J}),...c({setViewport:nt}),...pe({focus:Z(e)}),...p({unsupported:Y,plan:X(e),directionalFling:X(e),multiTouch:ot,targetAuthoredDrag:st,viewport:X(e)}),...re({scroll:X(e)}),...s({type:Z(e)}),...ge({unsupported:K,tap:Z(e),longPress:Z(e),fill:Z(e)}),...u({readTextAtPoint:qe}),...h({back:Z(e)}),...se({unsupported:Q,home:Z(e),appSwitcher:Z(e)}),setFoldPose:Q,...fe({triggerAppEvent:Q}),...de({setSetting:Z(e),readSetting:Q}),...ue({read:Q,wait:Q,accept:Q,dismiss:Q}),...l({orientation:Q}),...g({tvRemote:Q}),...m({unsupported:Q,status:ct,dismiss:Z(e),enter:Z(e)}),...ce({unsupported:Q}),...me({capture:$,query:$}),...he({frames:Z(e),memorySample:Z(e),memorySnapshot:Z(e),nativeCapture:Q,profileReport:Q}),ensureReady:G,bootTarget:K,bootTargetHeadless:K,listApps:G,...rt(e),shutdownTarget:K}})};return Object.freeze({owner:W,ownsDevice:e=>e.platform===`harmonyos`,inspectFacts:n,bind:async i=>{let o=await t.bind(i),s=await n(i.device),c=s.operations.screenRecordingStart;return Object.freeze({device:o.device,owner:W,facts:s,operations:Object.freeze({...o.operations,...Ve({commands:e.commands,device:i.device,signal:i.scope.signal}),...s.operations.appState.available?{appState:async()=>await Ie(i.device,i.scope.signal)}:{},ensureReady:async()=>({...i.device,booted:!0}),...c.available?ke({host:e,device:i.device,owner:W,signal:i.scope.signal}):{},...s.operations.captureSnapshot.available?f({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...s.operations.captureScreenshot.available?te({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...s.operations.focusPoint.available?ne({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...s.operations.typeText.available?ie({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...ae({device:i.device,signal:i.scope.signal,facts:s.operations,resolveInteractor:e.localInteractors.resolve}),...s.operations.scrollDirection.available?le({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...C({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:s.operations}),...r(s.operations.perfFrames,()=>we({resolveHost:()=>e.perf.harmony,device:i.device})),...r(s.operations.tapPoint,()=>_e({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:s.operations,pause:async t=>await e.clock.sleep(t,i.scope.signal)})),listApps:async e=>{i.scope.signal.throwIfAborted();let{listHarmonyApps:t}=await import(`./app-lifecycle2.js`);return(await t(e.device,e.filter,{signal:i.scope.signal})).map(e=>({id:e.package,name:e.name}))},...a(Re({host:e.localInteractors,device:i.device,signal:i.scope.signal}),s.operations)}),[Symbol.asyncDispose]:async()=>await o[Symbol.asyncDispose]()})},shutdown:async()=>await t.shutdown()})}export{lt as createHarmonyPlatformRuntime};
1
+ import{P as e}from"./sdk-contracts.js";import{j as t}from"./sdk-device.js";import{Xt as n,nn as r}from"./sdk-batch.js";import{n as i}from"./device-shell.js";import{n as a,t as o}from"./application-lifecycle-runtime.js";import{A as s,B as c,C as l,D as u,G as d,H as f,I as p,J as ee,K as te,L as ne,N as re,O as ie,P as ae,V as oe,d as se,h as ce,j as le,n as ue,o as de,s as fe,v as m,w as h,x as g,z as pe}from"./alert-runtime.js";import{n as me}from"./audio-probe-runtime.js";import{n as he}from"./perf-runtime.js";import{i as ge,t as _e}from"./touch-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{n as xe,t as y}from"./screen-recording-completion.js";import{t as b}from"./screen-recording-options.js";import{n as x}from"./screen-recording-runtime.js";import{i as S}from"./gesture-admission.js";import{t as C}from"./interactor-operation-catalog.js";import{i as w,n as T}from"./perf-runtime-operation-builder.js";import{t as E}from"./app-log-runtime.js";import{n as D,t as O}from"./application-lifecycle-interaction.js";import{randomUUID as k}from"node:crypto";import{setTimeout as A}from"node:timers/promises";const j=Object.freeze({resourceKind:E,version:1,encode:e=>({...e}),decode:e=>e.transport!==`harmony-hilog`||!N(e.outputPath)||!N(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 M(e){return v({resourceKind:E,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:_(j,e.descriptor)})}function N(e){return typeof e==`string`&&e.trim().length>0}function Se(e){return be(e,{family:`harmonyos`,backend:`harmonyos`,label:`HarmonyOS`,codec:j,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 a=await Ce(e,r);return{resolvePid:async r=>await ye(e,{executable:a,args:i(`hdc`,`shell`,[`pidof`,n.appBundleId],[`-t`,t.id]),allowFailure:!0,timeoutMs:5e3},r),command:e=>({kind:`host`,request:{executable:a,args:i(`hdc`,`shell`,[`hilog`,`-P`,e],[`-t`,t.id]),allowFailure:!0}})}},descriptor:({artifacts:e})=>({transport:`harmony-hilog`,...e}),envelope:({input:e,device:t,owner:n,descriptor:r})=>M({sessionId:e.sessionId,device:t,owner:n,fence:e.fence,descriptor:r})})}async function Ce(t,n){n.throwIfAborted(),await P(async()=>await t.toolchains.prepare(`harmonyos`),n),n.throwIfAborted();let r=await P(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 P(e,t){try{return await e()}catch(e){throw t.throwIfAborted(),e}}function we(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 w(t().sampleMemory(n,e)):T(`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 F=Object.freeze({resourceKind:x,version:1,encode:e=>({...e}),decode:e=>e.backend===`harmony-screen-recorder`&&typeof e.fileName==`string`&&De(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 Te(e){let{device:n,owner:r,input:i,descriptor:a}=e;return v({resourceKind:x,sessionId:i.sessionId,device:t(n),owner:r,fence:i.fence,lifecycle:`open`,descriptor:_(F,a)})}function Ee(e){return F.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 De(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 Oe(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 ke(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await Ae({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=>Ee(e.envelope.descriptor.body)})}async function Ae(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`);b(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-${k()}.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=je(a),d=!1,f=async()=>{d||=(B(await n.screenRecording.harmony.stop(r),`stop`),!0)},p=xe(u,{finish:async e=>await Me(n,r,e,c,f),forceCleanup:async()=>await R(n,r,c,f)});return Object.freeze({pendingHandle:new ve(p),envelope:Te({device:r,owner:i,input:a,descriptor:c})})}function je(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 Me(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 Ne(e,t,r,a);return y(n,{...i,...L(i.warning,o)},{stopObservation:{recorder:`confirmed`},nativePathDisposition:o===void 0?`retired`:`retirable`,showTouches:!1})}catch(n){throw await e.screenRecording.harmony.remove(t,r.remotePath).catch(()=>{}),n}}async function Ne(e,t,n,r){let i=[];return await I(()=>e.screenRecording.harmony.remove(t,n.remotePath))||i.push(`staging artifact`),await I(()=>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 I(e){try{return await e()}catch{return!1}}function L(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{runHarmonyShell:r}=await import(`./hdc.js`),i=await r(t,[`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 O({owner:`HarmonyOS`,openTargetIdentity:`bundle-id`,binding:D({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 Ke(t,n,[`install`,`-r`,r.appPath],i,18e4),r.replaceExisting&&(await A(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,[`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,[`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 Ke(e,t,n,r,i=15e3){return await e.run({executable:`hdc`,args:[`-t`,t.id,...n],timeoutMs:i},r)}async function U(e,t,n,r,a=15e3){return await e.run({executable:`hdc`,args:i(`hdc`,`shell`,n,[`-t`,t.id]),timeoutMs:a},r)}const W=n(`harmonyos`),qe=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`HarmonyOS reads element text from the captured tree only.`}),Je=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`}),Ye=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`HarmonyOS appstate is supported only for HarmonyOS emulators and devices.`}),Xe=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple runner preparation is supported only for Apple targets.`}),q=Object.freeze({available:!0}),Ze=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`open is supported only for HarmonyOS emulators and devices.`}),Qe=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`close is supported only for HarmonyOS emulators and devices.`}),$e=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.`}),et=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`screenshot is supported only for HarmonyOS emulators and devices.`}),tt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Re-run without --actions, or target an iOS simulator.`}),nt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`viewport resizes web targets only (--platform web).`});function rt(e){let t=it(e),n=at(e);return o({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:K,clearRuntimeHints:K,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:Xe,configureProviderPortReverse:$e})}function it(e){return e.kind===`emulator`||e.kind===`device`?q:Ze}function at(e){return e.kind===`emulator`||e.kind===`device`?q:Qe}const Y=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Gestures are supported on HarmonyOS emulators and physical devices.`}),ot=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),st=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:S});function X(e){return e.kind===`emulator`||e.kind===`device`?G:Y}function Z(e){return e.kind===`emulator`||e.kind===`device`?G:Je}const Q=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),ct=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 lt(e){let t=Se(e),n=async e=>{let n=await t.inspectFacts(e),r=H(e),i=Oe(e);return Object.freeze({device:n.device,operations:{...n.operations,...r,appState:e.kind===`simulator`?Ye:G,networkDump:K,screenRecordingStart:i,screenRecordingReattach:i,screenRecordingCleanup:i,...d({capture:e.kind===`emulator`||e.kind===`device`?G:J,customActions:tt,withoutActiveApp:e.kind===`emulator`||e.kind===`device`?G:J}),...ee({capture:e.kind===`emulator`||e.kind===`device`?G:et}),...oe({findText:J}),...c({setViewport:nt}),...pe({focus:Z(e)}),...p({unsupported:Y,plan:X(e),directionalFling:X(e),multiTouch:ot,targetAuthoredDrag:st,viewport:X(e)}),...re({scroll:X(e)}),...s({type:Z(e)}),...ge({unsupported:K,tap:Z(e),longPress:Z(e),fill:Z(e)}),...u({readTextAtPoint:qe}),...h({back:Z(e)}),...se({unsupported:Q,home:Z(e),appSwitcher:Z(e)}),setFoldPose:Q,...fe({triggerAppEvent:Q}),...de({setSetting:Z(e),readSetting:Q}),...ue({read:Q,wait:Q,accept:Q,dismiss:Q}),...l({orientation:Q}),...g({tvRemote:Q}),...m({unsupported:Q,status:ct,dismiss:Z(e),enter:Z(e)}),...ce({unsupported:Q}),...me({capture:$,query:$}),...he({frames:Z(e),memorySample:Z(e),memorySnapshot:Z(e),nativeCapture:Q,profileReport:Q}),ensureReady:G,bootTarget:K,bootTargetHeadless:K,listApps:G,...rt(e),shutdownTarget:K}})};return Object.freeze({owner:W,ownsDevice:e=>e.platform===`harmonyos`,inspectFacts:n,bind:async i=>{let o=await t.bind(i),s=await n(i.device),c=s.operations.screenRecordingStart;return Object.freeze({device:o.device,owner:W,facts:s,operations:Object.freeze({...o.operations,...Ve({commands:e.commands,device:i.device,signal:i.scope.signal}),...s.operations.appState.available?{appState:async()=>await Ie(i.device,i.scope.signal)}:{},ensureReady:async()=>({...i.device,booted:!0}),...c.available?ke({host:e,device:i.device,owner:W,signal:i.scope.signal}):{},...s.operations.captureSnapshot.available?f({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...s.operations.captureScreenshot.available?te({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...s.operations.focusPoint.available?ne({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...s.operations.typeText.available?ie({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...ae({device:i.device,signal:i.scope.signal,facts:s.operations,resolveInteractor:e.localInteractors.resolve}),...s.operations.scrollDirection.available?le({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...C({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:s.operations}),...r(s.operations.perfFrames,()=>we({resolveHost:()=>e.perf.harmony,device:i.device})),...r(s.operations.tapPoint,()=>_e({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:s.operations,pause:async t=>await e.clock.sleep(t,i.scope.signal)})),listApps:async e=>{i.scope.signal.throwIfAborted();let{listHarmonyApps:t}=await import(`./app-lifecycle2.js`);return(await t(e.device,e.filter,{signal:i.scope.signal})).map(e=>({id:e.package,name:e.name}))},...a(Re({host:e.localInteractors,device:i.device,signal:i.scope.signal}),s.operations)}),[Symbol.asyncDispose]:async()=>await o[Symbol.asyncDispose]()})},shutdown:async()=>await t.shutdown()})}export{lt as createHarmonyPlatformRuntime};
@@ -1 +1 @@
1
- import{N as e}from"./sdk-contracts.js";import{Xt as t,tn as n}from"./sdk-batch.js";import{n as r,t as i}from"./application-lifecycle-runtime.js";import{A as a,D as o,G as s,I as c,J as ee,N as l,W as u,d,h as f,w as p,z as m}from"./alert-runtime.js";import{i as h}from"./touch-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,orientation:G,tvRemote:G,clipboard:W,systemButton:G,fold:G,triggerAppEvent:G,settings:G,readAlert:G,awaitAlert:G,acceptAlert:G,dismissAlert:G,keyboard: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,...s({capture:X(e,z),customActions:V,withoutActiveApp:X(e,z)}),...ee({capture:X(e,B)}),...m({focus:X(e,E)}),...c({unsupported:O,plan:X(e,O),directionalFling:A,multiTouch:j,targetAuthoredDrag:M,viewport:N}),...l({scroll:X(e,k)}),...a({type:X(e,D)}),...Z(e),...o({readTextAtPoint:X(e,T)}),...p({back:X(e,H)}),...d({unsupported:G,home:X(e,U)}),...f({unsupported:W,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 h({unsupported:w,tap:t,longPress:t,fill:t})}function Q(e,t){let n=async n=>await e.snapshot.captureSurface(t.device,n.options,u(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};
1
+ import{P as e}from"./sdk-contracts.js";import{Xt as t,tn as n}from"./sdk-batch.js";import{n as r,t as i}from"./application-lifecycle-runtime.js";import{A as a,D as o,G as s,I as c,J as ee,N as l,W as u,d,h as f,w as p,z as m}from"./alert-runtime.js";import{i as h}from"./touch-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,orientation:G,tvRemote:G,clipboard:W,systemButton:G,fold:G,triggerAppEvent:G,settings:G,readAlert:G,awaitAlert:G,acceptAlert:G,dismissAlert:G,keyboard: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,...s({capture:X(e,z),customActions:V,withoutActiveApp:X(e,z)}),...ee({capture:X(e,B)}),...m({focus:X(e,E)}),...c({unsupported:O,plan:X(e,O),directionalFling:A,multiTouch:j,targetAuthoredDrag:M,viewport:N}),...l({scroll:X(e,k)}),...a({type:X(e,D)}),...Z(e),...o({readTextAtPoint:X(e,T)}),...p({back:X(e,H)}),...d({unsupported:G,home:X(e,U)}),...f({unsupported:W,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 h({unsupported:w,tap:t,longPress:t,fill:t})}function Q(e,t){let n=async n=>await e.snapshot.captureSurface(t.device,n.options,u(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};
@@ -1 +1 @@
1
- import{N as e}from"./sdk-contracts.js";import{Xt as t,tn as n}from"./sdk-batch.js";import{n as r,t as i}from"./application-lifecycle-runtime.js";import{I as a,d as o,w as s,x as c}from"./alert-runtime.js";import{r as l}from"./platform-runtime-unavailable.js";import{i as u}from"./gesture-admission.js";import{t as d}from"./interactor-operation-catalog.js";import{n as f,t as p}from"./application-lifecycle-interaction.js";function m(e){return p({owner:`Vega`,openTargetIdentity:`app-name`,binding:f({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const h=t(`vega`),g=Object.freeze({available:!0}),_=W(`unsupported-platform-leaf`),v=W(`unsupported-platform-leaf`,`Runtime hints are supported only for local iOS-family simulators and Android devices.`),y=W(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),b=W(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),x=W(`unsupported-device-kind`,`open currently supports only Vega Virtual Devices.`),S=W(`unsupported-device-kind`,`close currently supports only Vega Virtual Devices.`);function C(t){return Object.freeze({owner:h,ownsDevice:e=>e.platform===`vega`,inspectFacts:async e=>U(e),bind:async i=>{if(i.intent.kind===`exact-owner`&&!n(i.intent.owner,h))throw new e(`UNSUPPORTED_OPERATION`,`Vega runtime owner identity does not match`);if(i.device.platform!==`vega`)throw new e(`UNSUPPORTED_PLATFORM`,`Vega runtime cannot bind this device`);let a=U(i.device),o=m({host:t.localInteractors,device:i.device,signal:i.scope.signal});return Object.freeze({device:i.device,owner:h,facts:a,operations:Object.freeze({...r(o,a.operations),...d({device:i.device,signal:i.scope.signal,resolveInteractor:t.localInteractors.resolve,facts:a.operations})}),[Symbol.asyncDispose]:async()=>void 0})},shutdown:async()=>void 0})}const w=W(`unsupported-platform-leaf`,`screenshot is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),T=W(`unsupported-platform-leaf`,`focus is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),E=W(`unsupported-platform-leaf`,`type is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),D=W(`unsupported-platform-leaf`,`Gestures are not supported on Vega OS: the Vega runtime exposes remote navigation only.`),O=W(`unsupported-platform-leaf`,`scroll is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),k=W(`unsupported-platform-leaf`),A=W(`unsupported-platform-leaf`,u),j=W(`unsupported-platform-leaf`,`orientation is not supported on Vega OS.`),M=W(`unsupported-platform-leaf`,`keyboard is not supported on Vega OS.`),N=W(`unsupported-platform-leaf`,`alert is not supported on Vega OS.`),P=W(`unsupported-platform-leaf`,`settings is not supported on Vega OS.`),F=W(`unsupported-platform-leaf`,`trigger-app-event is not supported on Vega OS.`),I=W(`unsupported-platform-leaf`,`System buttons other than home are not supported on Vega OS.`),L=W(`unsupported-platform-leaf`,`fold is not supported on Vega OS.`),R=W(`unsupported-platform-leaf`,`clipboard is not supported on Vega OS.`),z=W(`unsupported-device-kind`,`back currently supports only Vega Virtual Devices.`),B=W(`unsupported-device-kind`,`home currently supports only Vega Virtual Devices.`),V=W(`unsupported-device-kind`,`tv-remote currently supports only Vega Virtual Devices.`),H=W(`unsupported-platform-leaf`,`audio is supported for web browser sessions, macOS sessions, iOS simulators, and Android emulators on macOS hosts`);function U(e){let t=e.kind===`emulator`&&e.target===`tv`,n=t?g:x,r=t?g:S,u=l(e,h,{appLog:_,network:_,screenshot:w,snapshot:_,viewport:_,focus:T,gesture:D,scroll:O,typeText:E,touch:_,elementText:_,back:z,orientation:j,tvRemote:V,clipboard:R,systemButton:I,fold:L,triggerAppEvent:F,settings:P,readAlert:N,awaitAlert:N,acceptAlert:N,dismissAlert:N,keyboard:M,audioProbeCapture:H,audioProbeQuery:H,perf:_,readiness:_,lifecycle:i({resolveOpenTarget:n,prepareApplicationOpen:n,openApplication:n,applyRuntimeHints:v,clearRuntimeHints:v,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:y,configureProviderPortReverse:b})});return Object.freeze({device:u.device,operations:{...u.operations,...s({back:t?g:z}),...o({unsupported:I,home:t?g:B}),...c({tvRemote:t?g:V}),...a({unsupported:D,multiTouch:k,targetAuthoredDrag:A})}})}function W(e,t){let n={available:!1,reason:e,...t===void 0?{}:{hint:t}};return Object.freeze(n)}export{C as createVegaPlatformRuntime};
1
+ import{P as e}from"./sdk-contracts.js";import{Xt as t,tn as n}from"./sdk-batch.js";import{n as r,t as i}from"./application-lifecycle-runtime.js";import{I as a,d as o,w as s,x as c}from"./alert-runtime.js";import{r as l}from"./platform-runtime-unavailable.js";import{i as u}from"./gesture-admission.js";import{t as d}from"./interactor-operation-catalog.js";import{n as f,t as p}from"./application-lifecycle-interaction.js";function m(e){return p({owner:`Vega`,openTargetIdentity:`app-name`,binding:f({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const h=t(`vega`),g=Object.freeze({available:!0}),_=W(`unsupported-platform-leaf`),v=W(`unsupported-platform-leaf`,`Runtime hints are supported only for local iOS-family simulators and Android devices.`),y=W(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),b=W(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),x=W(`unsupported-device-kind`,`open currently supports only Vega Virtual Devices.`),S=W(`unsupported-device-kind`,`close currently supports only Vega Virtual Devices.`);function C(t){return Object.freeze({owner:h,ownsDevice:e=>e.platform===`vega`,inspectFacts:async e=>U(e),bind:async i=>{if(i.intent.kind===`exact-owner`&&!n(i.intent.owner,h))throw new e(`UNSUPPORTED_OPERATION`,`Vega runtime owner identity does not match`);if(i.device.platform!==`vega`)throw new e(`UNSUPPORTED_PLATFORM`,`Vega runtime cannot bind this device`);let a=U(i.device),o=m({host:t.localInteractors,device:i.device,signal:i.scope.signal});return Object.freeze({device:i.device,owner:h,facts:a,operations:Object.freeze({...r(o,a.operations),...d({device:i.device,signal:i.scope.signal,resolveInteractor:t.localInteractors.resolve,facts:a.operations})}),[Symbol.asyncDispose]:async()=>void 0})},shutdown:async()=>void 0})}const w=W(`unsupported-platform-leaf`,`screenshot is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),T=W(`unsupported-platform-leaf`,`focus is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),E=W(`unsupported-platform-leaf`,`type is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),D=W(`unsupported-platform-leaf`,`Gestures are not supported on Vega OS: the Vega runtime exposes remote navigation only.`),O=W(`unsupported-platform-leaf`,`scroll is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),k=W(`unsupported-platform-leaf`),A=W(`unsupported-platform-leaf`,u),j=W(`unsupported-platform-leaf`,`orientation is not supported on Vega OS.`),M=W(`unsupported-platform-leaf`,`keyboard is not supported on Vega OS.`),N=W(`unsupported-platform-leaf`,`alert is not supported on Vega OS.`),P=W(`unsupported-platform-leaf`,`settings is not supported on Vega OS.`),F=W(`unsupported-platform-leaf`,`trigger-app-event is not supported on Vega OS.`),I=W(`unsupported-platform-leaf`,`System buttons other than home are not supported on Vega OS.`),L=W(`unsupported-platform-leaf`,`fold is not supported on Vega OS.`),R=W(`unsupported-platform-leaf`,`clipboard is not supported on Vega OS.`),z=W(`unsupported-device-kind`,`back currently supports only Vega Virtual Devices.`),B=W(`unsupported-device-kind`,`home currently supports only Vega Virtual Devices.`),V=W(`unsupported-device-kind`,`tv-remote currently supports only Vega Virtual Devices.`),H=W(`unsupported-platform-leaf`,`audio is supported for web browser sessions, macOS sessions, iOS simulators, and Android emulators on macOS hosts`);function U(e){let t=e.kind===`emulator`&&e.target===`tv`,n=t?g:x,r=t?g:S,u=l(e,h,{appLog:_,network:_,screenshot:w,snapshot:_,viewport:_,focus:T,gesture:D,scroll:O,typeText:E,touch:_,elementText:_,back:z,orientation:j,tvRemote:V,clipboard:R,systemButton:I,fold:L,triggerAppEvent:F,settings:P,readAlert:N,awaitAlert:N,acceptAlert:N,dismissAlert:N,keyboard:M,audioProbeCapture:H,audioProbeQuery:H,perf:_,readiness:_,lifecycle:i({resolveOpenTarget:n,prepareApplicationOpen:n,openApplication:n,applyRuntimeHints:v,clearRuntimeHints:v,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:y,configureProviderPortReverse:b})});return Object.freeze({device:u.device,operations:{...u.operations,...s({back:t?g:z}),...o({unsupported:I,home:t?g:B}),...c({tvRemote:t?g:V}),...a({unsupported:D,multiTouch:k,targetAuthoredDrag:A})}})}function W(e,t){let n={available:!1,reason:e,...t===void 0?{}:{hint:t}};return Object.freeze(n)}export{C as createVegaPlatformRuntime};
@@ -1 +1 @@
1
- import{N as e}from"./sdk-contracts.js";import{Xt as t,nn as n,tn as r}from"./sdk-batch.js";import{n as i,t as a}from"./application-lifecycle-runtime.js";import{A as o,B as s,C as c,D as l,G as u,H as d,I as ee,J as f,K as te,L as ne,N as p,O as m,V as h,d as re,h as g,j as _,n as v,o as ie,s as y,v as b,w as x,x as S,z as C}from"./alert-runtime.js";import{n as w}from"./audio-probe-runtime.js";import{n as T}from"./perf-runtime.js";import{i as E,t as D}from"./touch-runtime.js";import{i as O}from"./gesture-admission.js";import{n as k,t as A}from"./application-lifecycle-interaction.js";import{n as j,r as M,t as N}from"./screen-recording-transport.js";async function P(e){let{host:t,device:n,owner:r,signal:i}=e,a=await t.screenRecording.web.resolve(n);return a?{available:!0,operations:{screenRecordingStart:async e=>(F(e),await N({host:t,device:n,owner:r,input:e,signal:i,transport:{backend:`agent-browser`,targetLabel:`web recording`,start:async t=>await a.start(e.outputPath,t),stop:async()=>await a.stop()},support:{scopes:[`app`],fps:!1,exportQuality:!1,hideTouches:!1},unsupported:e=>`web recordings do not support ${e.join(`, `)}; agent-browser records WebM directly`})),screenRecordingReattach:async()=>M(`Web recordings cannot be reattached after daemon restart.`),screenRecordingCleanup:async()=>j(`Web recordings cannot be cleaned after daemon restart.`)}}:{available:!1,operations:{}}}function F(t){if(t.recordOnlySession)throw new e(`INVALID_ARGS`,`record on web requires an active browser session; run open <url> --platform web first`);if(!t.outputPath.toLowerCase().endsWith(`.webm`))throw new e(`INVALID_ARGS`,`web recordings require a .webm output path; agent-browser records WebM directly`)}function I(e){return A({owner:`web`,openTargetIdentity:`app-name`,binding:k({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const L=t(`web`),R=Object.freeze({available:!0}),z=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Web targets read element text from the captured tree only.`}),B=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),V=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`record is not supported by this web provider`}),H=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Re-run without --actions, or target an iOS simulator.`}),U=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),W=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`apps is not supported on web targets.`}),G=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),K=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),q=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple runner preparation is supported only for Apple targets.`}),J=Object.freeze({available:!1,reason:`owner-capability-missing`}),Y=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`A web click is one immediate pointer press; the browser backend has no timed hold.`}),ae=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`audio on web sessions is the stateless page probe; host capture is a macOS-host operation.`});function X(e,t){return typeof e==`function`?t:J}function Z(e,t){return e?R:t}const oe=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),se=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:O}),Q=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`open is supported only for web browser devices.`}),ce=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`close is supported only for web browser 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),n=fe(e);return a({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:U,clearRuntimeHints:U,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:q,configureProviderPortReverse:le})}function de(e){return e.kind===`device`?R:Q}function fe(e){return e.kind===`device`?R:ce}function pe(t){return Object.freeze({owner:L,ownsDevice:e=>e.platform===`web`,inspectFacts:async e=>{let n=await t.networkTransports.resolve(e),r=await P({host:t,device:e,owner:L,signal:new AbortController().signal}),i=e.kind===`device`?await t.localInteractors.resolve(e,{}):void 0;return $(e,n,r.available,i)},bind:async n=>{if(n.intent.kind===`exact-owner`&&!r(n.intent.owner,L))throw new e(`UNSUPPORTED_OPERATION`,`Web runtime owner identity does not match`);if(n.device.platform!==`web`)throw new e(`UNSUPPORTED_PLATFORM`,`Web runtime owner cannot bind ${n.device.platform}`);let i=await t.networkTransports.resolve(n.device),a=await P({host:t,device:n.device,owner:L,signal:n.scope.signal}),o=n.device.kind===`device`?await t.localInteractors.resolve(n.device,{signal:n.scope.signal}):void 0;return me(t,n.device,n.scope.signal,i,a,$(n.device,i,a.available,o))},shutdown:async()=>void 0})}function me(t,r,a,o,s,c){let l=o.dump,u={...l?{networkDump:async e=>{let t=await l({maxEntries:e.maxEntries,include:e.include},a);return Object.freeze({source:`provider`,...t})}}:{},...s.operations,...c.operations.captureSnapshot.available?d({device:r,signal:a,resolveInteractor:t.localInteractors.resolve}):{},...c.operations.captureScreenshot.available?te({device:r,signal:a,resolveInteractor:t.localInteractors.resolve}):{},...c.operations.focusPoint.available?ne({device:r,signal:a,resolveInteractor:t.localInteractors.resolve}):{},...c.operations.typeText.available?m({device:r,signal:a,resolveInteractor:t.localInteractors.resolve}):{},...n(c.operations.tapPoint,()=>D({device:r,signal:a,resolveInteractor:t.localInteractors.resolve,facts:c.operations,pause:async e=>await t.clock.sleep(e,a)})),...c.operations.scrollDirection.available?_({device:r,signal:a,resolveInteractor:t.localInteractors.resolve}):{},...c.operations.setViewport.available?{setViewport:async n=>{a.throwIfAborted();let i=await t.localInteractors.resolve(r,{signal:a});if(!i.setViewport)throw new e(`UNSUPPORTED_OPERATION`,`viewport is not supported by the bound web interactor`);await i.setViewport(n.width,n.height),a.throwIfAborted()}}:{},...n(c.operations.audioProbeQuery,()=>({audioProbeQuery:async n=>{let i=await t.audioProbe.web.resolve(r);if(i===void 0)throw new e(`UNSUPPORTED_OPERATION`,`audio is not supported by this web provider`);return await i.probe(n)}})),...i(I({host:t.localInteractors,device:r,signal:a}),c.operations)};return Object.freeze({device:r,owner:L,facts:c,operations:Object.freeze(u),[Symbol.asyncDispose]:async()=>void 0})}function $(e,t,n,r){let i=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`network is not supported by this web provider`}),a=Z(e.kind===`device`,Q);return Object.freeze({device:{family:`web`,kind:e.kind,...e.target===void 0?{}:{target:e.target},providerMode:t.mode},operations:{appLogInspect:B,appLogDoctor:B,appLogStart:B,appLogReattach:B,appLogCleanup:B,appState:G,networkDump:Z(!!t.dump,i),screenRecordingStart:Z(n,V),screenRecordingReattach:Z(n,V),screenRecordingCleanup:Z(n,V),...u({capture:a,customActions:H,withoutActiveApp:a}),...h({findText:Q}),...f({capture:a}),...C({focus:a}),...o({type:a}),...E({unsupported:U,tap:a,tapRef:X(r?.tapRef,a),longPress:Y,hover:X(r?.hover,a),hoverRef:X(r?.hoverRef,a),fill:a,fillRef:X(r?.fillRef,a)}),...p({scroll:a}),...ee({unsupported:oe,targetAuthoredDrag:se}),...s({setViewport:a}),...l({readTextAtPoint:z}),...x({back:K}),...c({orientation:K}),...S({tvRemote:K}),...b({unsupported:K}),...g({unsupported:K}),...w({capture:ae,query:R}),...T({frames:K,memorySample:K,memorySnapshot:K,nativeCapture:K,profileReport:K}),...re({unsupported:K}),setFoldPose:K,...y({triggerAppEvent:K}),...ie({setSetting:K,readSetting:K}),...v({read:K,wait:K,accept:K,dismiss:K}),ensureReady:U,bootTarget:U,bootTargetHeadless:U,listApps:W,deployApp:U,materializeAppSource:U,deployMaterializedApp:U,sendPushNotification:U,shutdownTarget:U,...ue(e)}})}export{pe as createWebPlatformRuntime};
1
+ import{P as e}from"./sdk-contracts.js";import{Xt as t,nn as n,tn as r}from"./sdk-batch.js";import{n as i,t as a}from"./application-lifecycle-runtime.js";import{A as o,B as s,C as c,D as l,G as u,H as d,I as ee,J as f,K as te,L as ne,N as p,O as m,V as h,d as re,h as g,j as _,n as v,o as ie,s as y,v as b,w as x,x as S,z as C}from"./alert-runtime.js";import{n as w}from"./audio-probe-runtime.js";import{n as T}from"./perf-runtime.js";import{i as E,t as D}from"./touch-runtime.js";import{i as O}from"./gesture-admission.js";import{n as k,t as A}from"./application-lifecycle-interaction.js";import{n as j,r as M,t as N}from"./screen-recording-transport.js";async function P(e){let{host:t,device:n,owner:r,signal:i}=e,a=await t.screenRecording.web.resolve(n);return a?{available:!0,operations:{screenRecordingStart:async e=>(F(e),await N({host:t,device:n,owner:r,input:e,signal:i,transport:{backend:`agent-browser`,targetLabel:`web recording`,start:async t=>await a.start(e.outputPath,t),stop:async()=>await a.stop()},support:{scopes:[`app`],fps:!1,exportQuality:!1,hideTouches:!1},unsupported:e=>`web recordings do not support ${e.join(`, `)}; agent-browser records WebM directly`})),screenRecordingReattach:async()=>M(`Web recordings cannot be reattached after daemon restart.`),screenRecordingCleanup:async()=>j(`Web recordings cannot be cleaned after daemon restart.`)}}:{available:!1,operations:{}}}function F(t){if(t.recordOnlySession)throw new e(`INVALID_ARGS`,`record on web requires an active browser session; run open <url> --platform web first`);if(!t.outputPath.toLowerCase().endsWith(`.webm`))throw new e(`INVALID_ARGS`,`web recordings require a .webm output path; agent-browser records WebM directly`)}function I(e){return A({owner:`web`,openTargetIdentity:`app-name`,binding:k({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const L=t(`web`),R=Object.freeze({available:!0}),z=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Web targets read element text from the captured tree only.`}),B=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),V=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`record is not supported by this web provider`}),H=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Re-run without --actions, or target an iOS simulator.`}),U=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),W=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`apps is not supported on web targets.`}),G=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),K=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),q=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple runner preparation is supported only for Apple targets.`}),J=Object.freeze({available:!1,reason:`owner-capability-missing`}),Y=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`A web click is one immediate pointer press; the browser backend has no timed hold.`}),ae=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`audio on web sessions is the stateless page probe; host capture is a macOS-host operation.`});function X(e,t){return typeof e==`function`?t:J}function Z(e,t){return e?R:t}const oe=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),se=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:O}),Q=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`open is supported only for web browser devices.`}),ce=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`close is supported only for web browser 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),n=fe(e);return a({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:U,clearRuntimeHints:U,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:q,configureProviderPortReverse:le})}function de(e){return e.kind===`device`?R:Q}function fe(e){return e.kind===`device`?R:ce}function pe(t){return Object.freeze({owner:L,ownsDevice:e=>e.platform===`web`,inspectFacts:async e=>{let n=await t.networkTransports.resolve(e),r=await P({host:t,device:e,owner:L,signal:new AbortController().signal}),i=e.kind===`device`?await t.localInteractors.resolve(e,{}):void 0;return $(e,n,r.available,i)},bind:async n=>{if(n.intent.kind===`exact-owner`&&!r(n.intent.owner,L))throw new e(`UNSUPPORTED_OPERATION`,`Web runtime owner identity does not match`);if(n.device.platform!==`web`)throw new e(`UNSUPPORTED_PLATFORM`,`Web runtime owner cannot bind ${n.device.platform}`);let i=await t.networkTransports.resolve(n.device),a=await P({host:t,device:n.device,owner:L,signal:n.scope.signal}),o=n.device.kind===`device`?await t.localInteractors.resolve(n.device,{signal:n.scope.signal}):void 0;return me(t,n.device,n.scope.signal,i,a,$(n.device,i,a.available,o))},shutdown:async()=>void 0})}function me(t,r,a,o,s,c){let l=o.dump,u={...l?{networkDump:async e=>{let t=await l({maxEntries:e.maxEntries,include:e.include},a);return Object.freeze({source:`provider`,...t})}}:{},...s.operations,...c.operations.captureSnapshot.available?d({device:r,signal:a,resolveInteractor:t.localInteractors.resolve}):{},...c.operations.captureScreenshot.available?te({device:r,signal:a,resolveInteractor:t.localInteractors.resolve}):{},...c.operations.focusPoint.available?ne({device:r,signal:a,resolveInteractor:t.localInteractors.resolve}):{},...c.operations.typeText.available?m({device:r,signal:a,resolveInteractor:t.localInteractors.resolve}):{},...n(c.operations.tapPoint,()=>D({device:r,signal:a,resolveInteractor:t.localInteractors.resolve,facts:c.operations,pause:async e=>await t.clock.sleep(e,a)})),...c.operations.scrollDirection.available?_({device:r,signal:a,resolveInteractor:t.localInteractors.resolve}):{},...c.operations.setViewport.available?{setViewport:async n=>{a.throwIfAborted();let i=await t.localInteractors.resolve(r,{signal:a});if(!i.setViewport)throw new e(`UNSUPPORTED_OPERATION`,`viewport is not supported by the bound web interactor`);await i.setViewport(n.width,n.height),a.throwIfAborted()}}:{},...n(c.operations.audioProbeQuery,()=>({audioProbeQuery:async n=>{let i=await t.audioProbe.web.resolve(r);if(i===void 0)throw new e(`UNSUPPORTED_OPERATION`,`audio is not supported by this web provider`);return await i.probe(n)}})),...i(I({host:t.localInteractors,device:r,signal:a}),c.operations)};return Object.freeze({device:r,owner:L,facts:c,operations:Object.freeze(u),[Symbol.asyncDispose]:async()=>void 0})}function $(e,t,n,r){let i=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`network is not supported by this web provider`}),a=Z(e.kind===`device`,Q);return Object.freeze({device:{family:`web`,kind:e.kind,...e.target===void 0?{}:{target:e.target},providerMode:t.mode},operations:{appLogInspect:B,appLogDoctor:B,appLogStart:B,appLogReattach:B,appLogCleanup:B,appState:G,networkDump:Z(!!t.dump,i),screenRecordingStart:Z(n,V),screenRecordingReattach:Z(n,V),screenRecordingCleanup:Z(n,V),...u({capture:a,customActions:H,withoutActiveApp:a}),...h({findText:Q}),...f({capture:a}),...C({focus:a}),...o({type:a}),...E({unsupported:U,tap:a,tapRef:X(r?.tapRef,a),longPress:Y,hover:X(r?.hover,a),hoverRef:X(r?.hoverRef,a),fill:a,fillRef:X(r?.fillRef,a)}),...p({scroll:a}),...ee({unsupported:oe,targetAuthoredDrag:se}),...s({setViewport:a}),...l({readTextAtPoint:z}),...x({back:K}),...c({orientation:K}),...S({tvRemote:K}),...b({unsupported:K}),...g({unsupported:K}),...w({capture:ae,query:R}),...T({frames:K,memorySample:K,memorySnapshot:K,nativeCapture:K,profileReport:K}),...re({unsupported:K}),setFoldPose:K,...y({triggerAppEvent:K}),...ie({setSetting:K,readSetting:K}),...v({read:K,wait:K,accept:K,dismiss:K}),ensureReady:U,bootTarget:U,bootTargetHeadless:U,listApps:W,deployApp:U,materializeAppSource:U,deployMaterializedApp:U,sendPushNotification:U,shutdownTarget:U,...ue(e)}})}export{pe as createWebPlatformRuntime};