agent-device 0.21.23 → 0.21.25

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 (435) hide show
  1. package/README.md +6 -6
  2. package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.23.apk → agent-device-android-ime-helper-0.21.25.apk} +0 -0
  3. package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.25.apk.sha256 +1 -0
  4. package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.23.manifest.json → agent-device-android-ime-helper-0.21.25.manifest.json} +4 -4
  5. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.25.apk +0 -0
  6. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.25.apk.sha256 +1 -0
  7. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.25.manifest.json +16 -0
  8. package/apple/macos-helper/Sources/AgentDeviceMacOSHelper/SnapshotTraversal.swift +12 -6
  9. package/apple/macos-helper/Tests/AgentDeviceMacOSHelperTests/RectResponseTests.swift +21 -0
  10. package/apple/snapshot-bridge/README.md +9 -7
  11. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerApp.m +159 -4
  12. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerHttpRequestFraming.swift +139 -0
  13. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerListenerPeer.swift +41 -0
  14. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerListenerToken.swift +25 -0
  15. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandDispatch.swift +56 -0
  16. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +14 -5
  17. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Environment.swift +18 -11
  18. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Lifecycle.swift +8 -0
  19. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +12 -0
  20. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Navigation.swift +25 -1
  21. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotCaptureTarget.swift +1 -1
  22. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotExecution.swift +29 -5
  23. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedTextEntry.swift +0 -3
  24. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntry.swift +35 -13
  25. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryConfirmation.swift +59 -26
  26. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryFocus.swift +19 -5
  27. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextTyping.swift +50 -106
  28. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Transport.swift +142 -54
  29. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TypeExecution.swift +4 -1
  30. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +21 -19
  31. package/dist/src/absence-observation-errors.js +1 -0
  32. package/dist/src/adapter.js +1 -1
  33. package/dist/src/adb-executor.js +2 -2
  34. package/dist/src/adb-failure.js +2 -2
  35. package/dist/src/adb.js +1 -1
  36. package/dist/src/agent-browser-lifecycle.js +1 -1
  37. package/dist/src/agent-browser-process-record.js +1 -1
  38. package/dist/src/agent-browser-provider.js +1 -1
  39. package/dist/src/agent-browser-tool.js +1 -1
  40. package/dist/src/agent-device-client.js +2 -2
  41. package/dist/src/alert.js +1 -1
  42. package/dist/src/android-adb.d.ts +3 -2
  43. package/dist/src/android-adb.js +1 -1
  44. package/dist/src/android-input-ownership.js +1 -1
  45. package/dist/src/android-system-surface-disclosure.js +1 -0
  46. package/dist/src/android-text-entry.js +1 -0
  47. package/dist/src/android.js +1 -1
  48. package/dist/src/app-backend.js +1 -1
  49. package/dist/src/app-helpers.js +1 -1
  50. package/dist/src/app-inventory.d.ts +4 -0
  51. package/dist/src/app-launch.js +1 -1
  52. package/dist/src/app-lifecycle.js +4 -3
  53. package/dist/src/app-lifecycle2.js +2 -2
  54. package/dist/src/app-log-files.js +1 -1
  55. package/dist/src/app-log-reconnect.js +1 -1
  56. package/dist/src/app-log-runtime2.js +3 -3
  57. package/dist/src/app-resolution-facade.js +1 -1
  58. package/dist/src/app-resolution.js +2 -2
  59. package/dist/src/app-state-runtime.d.ts +15 -0
  60. package/dist/src/apple-runner-platform.js +1 -1
  61. package/dist/src/application-lifecycle-interaction.js +1 -1
  62. package/dist/src/artifact-download.js +1 -1
  63. package/dist/src/auth.js +1 -1
  64. package/dist/src/aws-device-farm-connection.js +1 -0
  65. package/dist/src/back-mode.js +1 -1
  66. package/dist/src/backend-snapshot-options.js +1 -1
  67. package/dist/src/boot-diagnostics.js +1 -1
  68. package/dist/src/browserstack-connection.js +1 -0
  69. package/dist/src/capture-disclosure.js +1 -0
  70. package/dist/src/cli-config.js +1 -1
  71. package/dist/src/cli-help.js +36 -17
  72. package/dist/src/cli-output.js +1 -1
  73. package/dist/src/cli-runner.js +3 -1
  74. package/dist/src/cli.js +3 -4
  75. package/dist/src/client-companion-tunnel.js +1 -0
  76. package/dist/src/client-metro.js +1 -1
  77. package/dist/src/client-types.d.ts +15 -7
  78. package/dist/src/cloud-artifacts.d.ts +3 -2
  79. package/dist/src/code-signature-cache.js +1 -1
  80. package/dist/src/code-signature.js +1 -1
  81. package/dist/src/command-metadata.js +73 -1
  82. package/dist/src/command-policy.js +1 -0
  83. package/dist/src/command-schema.js +3 -3
  84. package/dist/src/command-surface.js +1 -1
  85. package/dist/src/command-tools.js +2 -2
  86. package/dist/src/connection-runtime.js +1 -1
  87. package/dist/src/connection-verification.js +1 -0
  88. package/dist/src/connection.js +5 -5
  89. package/dist/src/contracts.d.ts +1 -1
  90. package/dist/src/contracts.js +1 -1
  91. package/dist/src/daemon-client-lease-beat.js +1 -1
  92. package/dist/src/daemon-client-lifecycle.js +1 -1
  93. package/dist/src/daemon-client-liveness-probe.js +1 -1
  94. package/dist/src/daemon-policy-file.js +1 -1
  95. package/dist/src/daemon-registration-owner.js +1 -1
  96. package/dist/src/daemon-registration.js +1 -1
  97. package/dist/src/daemon-resolution.js +3 -1
  98. package/dist/src/debug-symbols-facade.js +1 -1
  99. package/dist/src/device-claim-inspection.js +1 -1
  100. package/dist/src/device-input-state.d.ts +6 -17
  101. package/dist/src/device-inventory-context.js +1 -1
  102. package/dist/src/device-readiness-runtime.js +1 -1
  103. package/dist/src/device-release.js +1 -1
  104. package/dist/src/device-selection-resolver.js +1 -1
  105. package/dist/src/device-shell.js +1 -1
  106. package/dist/src/device.js +3 -1
  107. package/dist/src/devicectl.js +1 -1
  108. package/dist/src/diagnostics.js +1 -1
  109. package/dist/src/doctor-facade.js +1 -1
  110. package/dist/src/durable-capture-resource.js +1 -1
  111. package/dist/src/durable-resource.js +1 -1
  112. package/dist/src/engine-eval-script.js +1 -1
  113. package/dist/src/error.js +1 -1
  114. package/dist/src/exec.js +1 -1
  115. package/dist/src/expo-dev-client-launch.js +1 -0
  116. package/dist/src/file.js +3 -1
  117. package/dist/src/find.js +1 -1
  118. package/dist/src/finders.js +1 -1
  119. package/dist/src/generic-settle.js +1 -1
  120. package/dist/src/generic.js +1 -1
  121. package/dist/src/gesture-admission.js +1 -1
  122. package/dist/src/gesture-plan-types.d.ts +2 -5
  123. package/dist/src/gesture-plan.js +1 -1
  124. package/dist/src/gesture-runtime.js +1 -1
  125. package/dist/src/harmonyos.js +1 -1
  126. package/dist/src/hdc.js +1 -1
  127. package/dist/src/helper.js +2 -2
  128. package/dist/src/human-control.js +1 -1
  129. package/dist/src/ime-rebind.js +1 -1
  130. package/dist/src/ime-state.js +1 -1
  131. package/dist/src/index.d.ts +4 -4
  132. package/dist/src/index.js +1 -1
  133. package/dist/src/input-actions.js +1 -1
  134. package/dist/src/input-actions2.js +2 -2
  135. package/dist/src/install-source-network-transport.js +1 -1
  136. package/dist/src/install-source2.js +1 -1
  137. package/dist/src/interaction-error.js +1 -0
  138. package/dist/src/interaction-positionals.js +1 -1
  139. package/dist/src/interaction.js +1 -1
  140. package/dist/src/interaction2.js +1 -1
  141. package/dist/src/interactor-operation-catalog.js +1 -1
  142. package/dist/src/interactor.js +5 -5
  143. package/dist/src/interactor2.js +1 -1
  144. package/dist/src/interactors.js +1 -1
  145. package/dist/src/internal/bin.js +1 -1
  146. package/dist/src/internal/daemon.js +5 -1
  147. package/dist/src/internal/png-worker.js +1 -1
  148. package/dist/src/inventory.js +2 -2
  149. package/dist/src/inventory2.js +1 -1
  150. package/dist/src/inventory6.js +1 -1
  151. package/dist/src/io.d.ts +2 -2
  152. package/dist/src/ios-client.js +1 -1
  153. package/dist/src/ios-settings.js +1 -1
  154. package/dist/src/ios-snapshot-acquisition.js +1 -1
  155. package/dist/src/ios-snapshot-adapter.js +1 -1
  156. package/dist/src/ios-snapshot-engine.js +1 -1
  157. package/dist/src/ios-snapshot-runtime.js +1 -1
  158. package/dist/src/keyed-lock.js +1 -1
  159. package/dist/src/launch-confirmation.js +1 -1
  160. package/dist/src/lease.js +1 -1
  161. package/dist/src/limrun-runtime-dependencies.js +1 -1
  162. package/dist/src/limrun.d.ts +5 -564
  163. package/dist/src/limrun.js +1 -1
  164. package/dist/src/linux.js +1 -1
  165. package/dist/src/load.js +1 -1
  166. package/dist/src/local-interactor-operation-set.js +1 -1
  167. package/dist/src/log-stream.js +9 -9
  168. package/dist/src/mechanics.js +16 -16
  169. package/dist/src/metro.js +1 -1
  170. package/dist/src/metro2.js +1 -1
  171. package/dist/src/mobile-snapshot-semantics.js +1 -1
  172. package/dist/src/observability.js +1 -1
  173. package/dist/src/observation.js +1 -2
  174. package/dist/src/open-target-resolution.js +1 -1
  175. package/dist/src/output-path.js +1 -1
  176. package/dist/src/overlay.js +1 -3
  177. package/dist/src/perf-facade.js +1 -1
  178. package/dist/src/perf-runtime-operation-builder.js +1 -1
  179. package/dist/src/perf-runtime.js +1 -1
  180. package/dist/src/perf-target.js +1 -1
  181. package/dist/src/physical-device-control.js +1 -1
  182. package/dist/src/platform-request-scope.js +1 -1
  183. package/dist/src/platform-runtime-android-adb-host.js +1 -1
  184. package/dist/src/platform-runtime-app-log-android-transport.js +1 -1
  185. package/dist/src/platform-runtime-apple-resources.js +1 -0
  186. package/dist/src/platform-runtime-claim-recovery.js +1 -0
  187. package/dist/src/platform-runtime-daemon-services.js +1 -0
  188. package/dist/src/platform-runtime-host.js +1 -1
  189. package/dist/src/platform-runtime-network-web-transport.js +1 -1
  190. package/dist/src/platform-runtime-open-target.js +1 -1
  191. package/dist/src/platform-runtime-operation-host.js +4 -4
  192. package/dist/src/platform-runtime-runtime-hints.js +2 -2
  193. package/dist/src/platform-runtime-screen-recording-android-host.js +1 -1
  194. package/dist/src/platform-runtime-screen-recording-apple-runner-transport.js +1 -1
  195. package/dist/src/platform-runtime-screen-recording-apple-simulator-host.js +1 -1
  196. package/dist/src/platform-runtime-screen-recording-finalizer-host.js +1 -1
  197. package/dist/src/platform-runtime-screen-recording-harmony-host.js +1 -1
  198. package/dist/src/platform-runtime-screen-recording-web-host.js +1 -1
  199. package/dist/src/platform-runtime-unavailable.js +1 -1
  200. package/dist/src/platform-runtime.js +1 -1
  201. package/dist/src/platform-runtime2.js +1 -1
  202. package/dist/src/plugin.js +1 -0
  203. package/dist/src/plugins/webdriver.d.ts +111 -0
  204. package/dist/src/plugins/webdriver.js +1 -0
  205. package/dist/src/plugins.d.ts +2 -1
  206. package/dist/src/plugins2.js +1 -1
  207. package/dist/src/png-crop-bytes.js +1 -1
  208. package/dist/src/png-resize.js +1 -0
  209. package/dist/src/png-worker-client.js +1 -1
  210. package/dist/src/png-worker-contract.js +1 -1
  211. package/dist/src/process-entry.js +1 -1
  212. package/dist/src/process-exit.js +1 -1
  213. package/dist/src/process.js +1 -1
  214. package/dist/src/provider-credential-fingerprint.js +1 -1
  215. package/dist/src/provider-device-admission.js +1 -1
  216. package/dist/src/provider-device-runtime.d.ts +556 -0
  217. package/dist/src/provider-policy.js +1 -0
  218. package/dist/src/provider-profile-fields.js +1 -1
  219. package/dist/src/provider-webdriver.js +1 -2
  220. package/dist/src/proxy.js +2 -2
  221. package/dist/src/quality-warnings.js +1 -1
  222. package/dist/src/react-devtools.js +2 -0
  223. package/dist/src/react-native-overlay2.js +3 -0
  224. package/dist/src/react-native.js +1 -1
  225. package/dist/src/record-runtime.js +1 -1
  226. package/dist/src/record-trace.js +1 -1
  227. package/dist/src/recording.js +2 -2
  228. package/dist/src/register-builtins.js +1 -1
  229. package/dist/src/remote-bridge.js +1 -0
  230. package/dist/src/remote-config-core.js +1 -0
  231. package/dist/src/remote-config.js +1 -1
  232. package/dist/src/remote-config2.js +1 -1
  233. package/dist/src/replay-backend-registry.js +1 -0
  234. package/dist/src/replay-divergence.js +1 -1
  235. package/dist/src/replay-maestro-backend.js +117 -0
  236. package/dist/src/replay-script-selection.js +1 -0
  237. package/dist/src/replay.js +1 -3
  238. package/dist/src/replay2.js +1 -0
  239. package/dist/src/reporting.js +3 -3
  240. package/dist/src/request-cancel.js +1 -1
  241. package/dist/src/request-providers.js +1 -1
  242. package/dist/src/request-runtime-binding.js +1 -1
  243. package/dist/src/result-serialization.js +1 -1
  244. package/dist/src/retry.js +1 -1
  245. package/dist/src/retry2.js +1 -0
  246. package/dist/src/runner-artifact-manifest.js +1 -1
  247. package/dist/src/runner-cache-retention.js +1 -0
  248. package/dist/src/runner-cache-trim.js +1 -0
  249. package/dist/src/runner-client.js +1 -1
  250. package/dist/src/runner-dev-tools-security.js +1 -1
  251. package/dist/src/runner-device-readiness.js +1 -1
  252. package/dist/src/runner-device-set.js +1 -0
  253. package/dist/src/runner-error-classification.js +3 -3
  254. package/dist/src/runner-exchange.js +1 -1
  255. package/dist/src/runner-lease.js +1 -0
  256. package/dist/src/runner-operations-facade.js +1 -1
  257. package/dist/src/runner-retention.js +1 -0
  258. package/dist/src/runner-start-budget.js +1 -1
  259. package/dist/src/runner-startup-transport.js +1 -0
  260. package/dist/src/runner-toolchain-probe.js +2 -0
  261. package/dist/src/runner.js +2 -1
  262. package/dist/src/runtime-command-surface.js +1 -0
  263. package/dist/src/runtime-deployment.js +1 -0
  264. package/dist/src/runtime-factory.js +1 -0
  265. package/dist/src/runtime-session.js +1 -0
  266. package/dist/src/runtime-transport-hints.js +1 -1
  267. package/dist/src/runtime.js +2 -1
  268. package/dist/src/runtime10.js +2 -2
  269. package/dist/src/runtime2.js +4 -4
  270. package/dist/src/runtime3.js +1 -1
  271. package/dist/src/runtime4.js +5 -5
  272. package/dist/src/runtime5.js +1 -1
  273. package/dist/src/runtime6.js +1 -1
  274. package/dist/src/runtime7.js +1 -1
  275. package/dist/src/runtime8.js +1 -1
  276. package/dist/src/runtime9.js +1 -1
  277. package/dist/src/screen-recording-transport.js +1 -1
  278. package/dist/src/screenshot-density.js +1 -1
  279. package/dist/src/screenshot-image.js +1 -1
  280. package/dist/src/screenshot-runtime.js +1 -1
  281. package/dist/src/screenshot3.js +5 -5
  282. package/dist/src/sdk-batch-runner.js +2 -2
  283. package/dist/src/sdk-batch.js +2 -2
  284. package/dist/src/sdk-contracts.d.ts +20 -29
  285. package/dist/src/sdk-contracts.js +2 -2
  286. package/dist/src/sdk-device.js +1 -1
  287. package/dist/src/sdk-finders.d.ts +1 -1
  288. package/dist/src/sdk-finders.js +1 -1
  289. package/dist/src/sdk-io.d.ts +4 -2
  290. package/dist/src/sdk-remote-config.d.ts +4 -0
  291. package/dist/src/sdk-remote-config.js +1 -1
  292. package/dist/src/sdk-selectors.d.ts +5 -6
  293. package/dist/src/sdk-selectors.js +1 -1
  294. package/dist/src/selection.js +0 -0
  295. package/dist/src/selector-pipeline-policy.js +1 -1
  296. package/dist/src/selector-runtime.js +1 -1
  297. package/dist/src/selectors.js +1 -1
  298. package/dist/src/server.js +2 -2
  299. package/dist/src/session-allocation.js +1 -1
  300. package/dist/src/session-replay-runtime-failure-response.js +1 -0
  301. package/dist/src/session-runtime-admission.js +1 -1
  302. package/dist/src/session.js +1 -1
  303. package/dist/src/session2.js +5 -5
  304. package/dist/src/settings.js +1 -1
  305. package/dist/src/settings2.js +1 -1
  306. package/dist/src/simctl-settings.js +1 -1
  307. package/dist/src/simctl.js +1 -1
  308. package/dist/src/simulator-boot.js +1 -1
  309. package/dist/src/simulator-state.js +1 -1
  310. package/dist/src/simulator.js +1 -1
  311. package/dist/src/snapshot-capture-annotations.js +1 -1
  312. package/dist/src/snapshot-chrome.js +1 -0
  313. package/dist/src/snapshot-desktop-projection.js +1 -1
  314. package/dist/src/snapshot-evidence.js +1 -0
  315. package/dist/src/snapshot-node-lookup.js +1 -0
  316. package/dist/src/snapshot-occlusion.js +1 -0
  317. package/dist/src/snapshot-quality-verdict.js +1 -0
  318. package/dist/src/snapshot-runtime-binding.js +1 -1
  319. package/dist/src/snapshot-runtime.js +1 -1
  320. package/dist/src/snapshot-state.js +1 -1
  321. package/dist/src/snapshot.js +1 -1
  322. package/dist/src/snapshot2.js +1 -1
  323. package/dist/src/snapshot3.js +1 -1
  324. package/dist/src/src.js +5 -1
  325. package/dist/src/src2.js +1 -1
  326. package/dist/src/src3.js +2 -1
  327. package/dist/src/store.js +1 -1
  328. package/dist/src/surface-snapshot2.js +1 -1
  329. package/dist/src/target-evidence-tree.js +1 -0
  330. package/dist/src/target-evidence.js +1 -1
  331. package/dist/src/text-entry-focus.js +1 -1
  332. package/dist/src/tool-provider2.js +1 -1
  333. package/dist/src/touch-runtime.js +1 -1
  334. package/dist/src/touch-runtime2.js +1 -1
  335. package/dist/src/tree.js +1 -1
  336. package/dist/src/tv-remote.js +1 -1
  337. package/dist/src/type-text-runtime.js +1 -1
  338. package/dist/src/undici.js +8 -8
  339. package/dist/src/update-check.js +1 -1
  340. package/dist/src/vars.js +1 -1
  341. package/dist/src/version.js +1 -1
  342. package/dist/src/video.js +2 -2
  343. package/dist/src/wait.js +1 -0
  344. package/dist/src/web.js +1 -1
  345. package/dist/src/web2.js +1 -1
  346. package/package.json +22 -19
  347. package/server.json +2 -2
  348. package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.23.apk.sha256 +0 -1
  349. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.23.apk +0 -0
  350. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.23.apk.sha256 +0 -1
  351. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.23.manifest.json +0 -16
  352. package/dist/src/adb-transport.js +0 -1
  353. package/dist/src/alert-runtime.js +0 -1
  354. package/dist/src/app-deployment-resolution.js +0 -2
  355. package/dist/src/app-inventory-contract.js +0 -1
  356. package/dist/src/app-log-session-resource.js +0 -1
  357. package/dist/src/application-lifecycle-runtime.js +0 -1
  358. package/dist/src/auth-session.js +0 -1
  359. package/dist/src/cache.js +0 -1
  360. package/dist/src/capabilities.js +0 -1
  361. package/dist/src/capture.js +0 -1
  362. package/dist/src/catalog.js +0 -1
  363. package/dist/src/click-button.js +0 -1
  364. package/dist/src/client-metro-companion.js +0 -1
  365. package/dist/src/client-options.js +0 -3
  366. package/dist/src/compatibility-policy.js +0 -1
  367. package/dist/src/daemon-artifacts.js +0 -1
  368. package/dist/src/daemon-client-transport.js +0 -1
  369. package/dist/src/daemon-http.js +0 -1
  370. package/dist/src/device-claim-rule.js +0 -1
  371. package/dist/src/device-rotation.js +0 -1
  372. package/dist/src/device-session.js +0 -3
  373. package/dist/src/device2.js +0 -1
  374. package/dist/src/device3.js +0 -3
  375. package/dist/src/dispatch-resolve.js +0 -4
  376. package/dist/src/format.js +0 -1
  377. package/dist/src/gesture-plan-types.js +0 -1
  378. package/dist/src/host.js +0 -1
  379. package/dist/src/human-control-contract.js +0 -1
  380. package/dist/src/interaction-ref-policy.js +0 -1
  381. package/dist/src/interactor-operation-binding.js +0 -1
  382. package/dist/src/keyboard-actions.js +0 -1
  383. package/dist/src/lease-context.js +0 -1
  384. package/dist/src/lease-registry-scope.js +0 -1
  385. package/dist/src/lease-scope.js +0 -1
  386. package/dist/src/managed-device-scope.js +0 -1
  387. package/dist/src/observe-until.js +0 -1
  388. package/dist/src/output-common.js +0 -5
  389. package/dist/src/owner-identity.js +0 -3
  390. package/dist/src/path-resolution.js +0 -1
  391. package/dist/src/perf-runtime-plan.js +0 -1
  392. package/dist/src/platform-runtime-app-log-process.js +0 -1
  393. package/dist/src/platform-runtime-managed-owner.js +0 -1
  394. package/dist/src/platform-runtime-screen-recording-process-host.js +0 -1
  395. package/dist/src/png.js +0 -1
  396. package/dist/src/prepare-kind.js +0 -1
  397. package/dist/src/provider-device-runtimes.js +0 -1
  398. package/dist/src/provider-session-ownership.js +0 -2
  399. package/dist/src/providers.js +0 -1
  400. package/dist/src/registry.js +0 -68
  401. package/dist/src/request-admission.js +0 -1
  402. package/dist/src/request-cancellation.js +0 -1
  403. package/dist/src/request-progress-protocol.js +0 -1
  404. package/dist/src/runner-cache-metadata.js +0 -3
  405. package/dist/src/runner-disposal.js +0 -1
  406. package/dist/src/runner-session-types.js +0 -1
  407. package/dist/src/runtime-admission.js +0 -1
  408. package/dist/src/screen-recording-admission-ledger.js +0 -1
  409. package/dist/src/screen-recording-resource-recovery.js +0 -1
  410. package/dist/src/screenshot-result.js +0 -1
  411. package/dist/src/script.js +0 -1
  412. package/dist/src/scroll-command.js +0 -1
  413. package/dist/src/scroll-gesture.js +0 -1
  414. package/dist/src/scroll-indicator.js +0 -1
  415. package/dist/src/session-artifact-paths.js +0 -1
  416. package/dist/src/session-paths.js +0 -1
  417. package/dist/src/session-repair-tombstone.js +0 -1
  418. package/dist/src/session-routing.js +0 -1
  419. package/dist/src/session-snapshot.js +0 -1
  420. package/dist/src/snapshot4.js +0 -1
  421. package/dist/src/src4.js +0 -1
  422. package/dist/src/src5.js +0 -1
  423. package/dist/src/src6.js +0 -1
  424. package/dist/src/src7.js +0 -2
  425. package/dist/src/src8.js +0 -115
  426. package/dist/src/string-enum.js +0 -1
  427. package/dist/src/success-text.js +0 -1
  428. package/dist/src/timeouts.js +0 -1
  429. package/dist/src/touch-reference-frame.js +0 -1
  430. package/dist/src/transport.js +0 -3
  431. package/dist/src/ttl-memo.js +0 -1
  432. package/dist/src/verified-file.js +0 -1
  433. package/dist/src/viewport.js +0 -1
  434. package/dist/src/window-state.js +0 -1
  435. /package/dist/src/{doctor-output.js → doctor-lines.js} +0 -0
package/dist/src/alert.js CHANGED
@@ -1 +1 @@
1
- import{P as e}from"./sdk-contracts.js";import{m as t,p as n}from"./sdk-device.js";import{a as r,n as i}from"./alert-contract.js";import{t as a}from"./timeouts.js";import"./retry.js";import{c as o}from"./runner-client.js";import{a as s}from"./helper.js";function c(e,n,r){if(t(e)){let e=r?.surface===`frontmost-app`?{surface:r.surface}:{bundleId:r?.appBundleId,surface:r?.surface};return async t=>await s(t,e)}return async(t,i)=>await o(e,{command:`alert`,action:t,appBundleId:r?.appBundleId,timeoutMs:i},n)}async function l(e){try{return await e}catch(e){if(h(e))return;throw e}}async function u(e,t,n){return await c(e,t,n)(`get`,r)}async function d(t,n,r){let i=c(t,n,r),o=r?.timeoutMs??1e4,s=Date.now(),l=!0;for(;Date.now()-s<o;){try{let e=l?o:p(s,o);return l=!1,await i(`get`,e)}catch(e){if(!h(e))throw e}await a(300)}throw new e(`COMMAND_FAILED`,`alert wait timed out`)}async function f(e,t,o,s){let l=c(e,t,s),u=n(e)?r:i,d=Date.now(),f,g=!0;for(;Date.now()-d<i;){try{let e=g?u:p(d,i);return g=!1,await l(o,e)}catch(e){if(f=e,!h(e))break}await a(300)}throw m(f)}function p(e,t){return Math.max(1,t-(Date.now()-e))}function m(t){return!(t instanceof e)||!h(t)?t:new e(t.code,t.message,{...t.details??{},hint:`If the permission sheet is visible in snapshot or screenshot but alert reports no alert, take a scoped snapshot around the visible button label and use press @ref.`})}function h(t){if(!(t instanceof e))return!1;let n=t.details??{};return n.runnerErrorCode===`ALERT_NOT_FOUND`||n.reason===`alert-not-found`}export{u as i,l as n,d as r,f as t};
1
+ import{P as e}from"./sdk-contracts.js";import{g as t,h as n}from"./sdk-device.js";import{a as r,n as i}from"./alert-contract.js";import{i as a}from"./retry.js";import"./retry2.js";import{c as o}from"./runner-client.js";import{a as s}from"./helper.js";function c(e,n,r){if(t(e)){let e=r?.surface===`frontmost-app`?{surface:r.surface}:{bundleId:r?.appBundleId,surface:r?.surface};return async t=>await s(t,e)}return async(t,i)=>await o(e,{command:`alert`,action:t,appBundleId:r?.appBundleId,timeoutMs:i},n)}async function l(e){try{return await e}catch(e){if(h(e))return;throw e}}async function u(e,t,n){return await c(e,t,n)(`get`,r)}async function d(t,n,r){let i=c(t,n,r),o=r?.timeoutMs??1e4,s=Date.now(),l=!0;for(;Date.now()-s<o;){try{let e=l?o:p(s,o);return l=!1,await i(`get`,e)}catch(e){if(!h(e))throw e}await a(300)}throw new e(`COMMAND_FAILED`,`alert wait timed out`)}async function f(e,t,o,s){let l=c(e,t,s),u=n(e)?r:i,d=Date.now(),f,g=!0;for(;Date.now()-d<i;){try{let e=g?u:p(d,i);return g=!1,await l(o,e)}catch(e){if(f=e,!h(e))break}await a(300)}throw m(f)}function p(e,t){return Math.max(1,t-(Date.now()-e))}function m(t){return!(t instanceof e)||!h(t)?t:new e(t.code,t.message,{...t.details??{},hint:`If the permission sheet is visible in snapshot or screenshot but alert reports no alert, take a scoped snapshot around the visible button label and use press @ref.`})}function h(t){if(!(t instanceof e))return!1;let n=t.details??{};return n.runnerErrorCode===`ALERT_NOT_FOUND`||n.reason===`alert-not-found`}export{u as i,l as n,d as r,f as t};
@@ -1,6 +1,7 @@
1
1
  import { b as DeviceInfo } from "./sdk-contracts.js";
2
- import { s as AppsFilter } from "./gesture-plan-types.js";
3
- import { a as readAndroidClipboardWithAdb, c as AndroidAdbExecutor, d as AndroidAdbProvider, f as AndroidPortReverseEndpoint, i as getAndroidKeyboardStatusWithAdb, l as AndroidAdbExecutorOptions, m as AppStateRuntimeResult, n as AndroidKeyboardState, o as writeAndroidClipboardWithAdb, p as AndroidPortReverseProvider, r as dismissAndroidKeyboardWithAdb, t as AndroidKeyboardDismissResult, u as AndroidAdbExecutorResult } from "./device-input-state.js";
2
+ import { t as AppsFilter } from "./app-inventory.js";
3
+ import { t as AppStateRuntimeResult } from "./app-state-runtime.js";
4
+ import { a as readAndroidClipboardWithAdb, c as AndroidAdbExecutor, d as AndroidAdbProvider, f as AndroidPortReverseEndpoint, i as getAndroidKeyboardStatusWithAdb, l as AndroidAdbExecutorOptions, n as AndroidKeyboardState, o as writeAndroidClipboardWithAdb, p as AndroidPortReverseProvider, r as dismissAndroidKeyboardWithAdb, t as AndroidKeyboardDismissResult, u as AndroidAdbExecutorResult } from "./device-input-state.js";
4
5
  //#region packages/platform-android/src/adb-port-reverse.d.ts
5
6
  type AndroidExecPortReverseOptions = Readonly<{
6
7
  /**
@@ -1 +1 @@
1
- import{d as e,p as t,u as n}from"./adb-executor.js";import{b as r,f as i,g as a,m as o,n as s,t as c,v as l,y as u}from"./mechanics.js";import{a as d,o as f}from"./adb.js";import"./platform-runtime-android-adb-host.js";async function p(e,t){let{getAndroidAppStateWithAdb:n}=await import(`./platform-runtime.js`).then(e=>e.a);return await n(e,t)}export{c as captureAndroidLogcatWithAdb,t as createAndroidPortReverseManager,i as dismissAndroidKeyboardWithAdb,u as forceStopAndroidAppWithAdb,p as getAndroidAppStateWithAdb,o as getAndroidKeyboardStatusWithAdb,s as listAndroidAppsWithAdb,r as openAndroidAppWithAdb,a as readAndroidClipboardWithAdb,n as runAdbExecOut,e as runAdbShell,d as runAndroidExecOut,f as runAndroidShell,l as writeAndroidClipboardWithAdb};
1
+ import{d as e,p as t,u as n}from"./adb-executor.js";import{C as r,S as i,_ as a,h as o,n as s,t as c,x as l,y as u}from"./mechanics.js";import{a as d,o as f}from"./adb.js";import"./platform-runtime-android-adb-host.js";async function p(e,t){let{getAndroidAppStateWithAdb:n}=await import(`./platform-runtime.js`).then(e=>e.a);return await n(e,t)}export{c as captureAndroidLogcatWithAdb,t as createAndroidPortReverseManager,o as dismissAndroidKeyboardWithAdb,i as forceStopAndroidAppWithAdb,p as getAndroidAppStateWithAdb,a as getAndroidKeyboardStatusWithAdb,s as listAndroidAppsWithAdb,r as openAndroidAppWithAdb,u as readAndroidClipboardWithAdb,n as runAdbExecOut,e as runAdbShell,d as runAndroidExecOut,f as runAndroidShell,l as writeAndroidClipboardWithAdb};
@@ -1 +1 @@
1
- import{b as e}from"./sdk-contracts.js";import{Gr as t,Lr as n,ei as r,jr as i,qr as a}from"./sdk-batch.js";import{n as o,t as s}from"./rect-center.js";const c=new WeakMap;function l(e,t){return c.set(e,{...c.get(e),...t}),e}function u(e,t){return l(e,{clickability:t})}function d(e){return e?c.get(e)?.clickability:void 0}function f(e,t){let n=d(e);return n?u(t,n):t}function p(e,t){return l(e,{occlusionContext:t})}function m(e){return e?c.get(e)?.occlusionContext:void 0}const h=[`tabbar`,`toolbar`,`navigationbar`,`bottomnavigation`,`bottomnavigationview`,`sheet`,`dialog`,`alert`,`popover`,`menu`],g=[`tabbar`,`toolbar`,`navigationbar`],_=[`toolbar`],v=[`scrollbar`,`scrollindicator`],y=[`button`,`link`,`menuitem`,`tabitem`,`textfield`,`searchfield`,`edittext`,`checkbox`,`radio`,`switch`,`cell`];function b(e){let t=new Map,n=new Map;for(let r of e){if(t.set(r.index,r),typeof r.parentIndex!=`number`)continue;let e=n.get(r.parentIndex);e?e.push(r):n.set(r.parentIndex,[r])}return{byIndex:t,childrenByParent:n}}function x(e,t={}){if(e.length<2)return e;let n=b(e),r={nodes:e,byIndex:n.byIndex,neighbourhood:n,overlayPositions:e.flatMap((e,r)=>A(e,n,t)?[r]:[]),coverCache:new Map},i=[];for(let[n,a]of e.entries())k(a)&&T(r,n,a,t)&&i.push(n);return C(e,i)}function S(e,t){let n=[];for(let[r,i]of e.entries())k(i)&&t(i)&&n.push(r);return C(e,n)}function C(e,t){if(t.length===0)return e;let n=[...e];for(let r of t){let t=e[r];n[r]={...t,hittable:!1,interactionBlocked:`covered`,presentationHints:G(t.presentationHints)}}return n}function w(e){return e.interactionBlocked!==void 0}function T(t,n,r,i){let a=t.coverCache.get(n);if(a!==void 0)return a;t.coverCache.set(n,null);let o=W(r.rect);if(!o)return E(t,n,null);let s=e(o),c=i.isAdditionalOverlayNode?.(r)===!0;for(let e of t.overlayPositions){if(!ee(t,e,n,c,i))continue;let a=t.nodes[e];if(D(t,e,r,o,s,i))return E(t,n,a)}return E(t,n,null)}function ee(e,t,n,r,i){let a=e.nodes[t];return a?t>n?!0:t===n||r?!1:i.isAdditionalOverlayNode?.(a)===!0:!1}function E(e,t,n){return e.coverCache.set(t,n),n}function D(e,t,n,r,i,o){if(!e.nodes[t])return!1;let s=O(e,t,n,r,o);return!!(s&&a(s,i.x,i.y))}function O(e,t,n,r,i){let a=e.nodes[t];if(!a||!A(a,e.neighbourhood,i)||H(n,a,e.byIndex))return null;let o=W(a.rect);return!o||s(r,o)||T(e,t,a,i)?null:o}function k(e){return W(e.rect)?e.hittable===!0||z(e)?!0:!!(e.label?.trim()||e.value?.trim()||e.identifier?.trim()):!1}function A(e,t,n){return!W(e.rect)||i(e)||F(e,t.byIndex)||j(e,t)||M(e,t)?!1:B(e,h)||I(e,t.byIndex,n)}function j(e,t){if(!B(e,g)||typeof e.parentIndex!=`number`)return!1;let n=W(e.rect);return n?(t.childrenByParent.get(e.parentIndex)??[]).some(t=>t.index!==e.index&&s(n,t.rect)):!1}function M(e,t){if(!B(e,_)||typeof e.parentIndex!=`number`)return!1;let n=W(e.rect);if(!n)return!1;let r=t.childrenByParent.get(e.parentIndex),i=r.findIndex(t=>t.index===e.index),a=N(r,i),o=!1;for(let[e,t]of r.entries())if(!(e===i||!P(n,t))){if(e<a||e>i)return!1;o=!0}return o}function N(e,t){for(let n=t-1;n>=0;n--)if(B(e[n],_))return n+1;return 0}function P(e,n){let i=B(n,g)||t(n)&&!B(n,v),a=W(n.rect);return!!(i&&a&&r(e,a))}function F(e,t){if(!B(e,g))return!1;let n=W(e.rect);if(!n)return!1;let r=typeof e.parentIndex==`number`?t.get(e.parentIndex):void 0,a=new Set;for(;r&&!a.has(r.index);){if(i(r)){let e=W(r.rect);return!!(e&&s(n,e))}a.add(r.index),r=typeof r.parentIndex==`number`?t.get(r.parentIndex):void 0}return!1}function I(e,t,n){return n.isAdditionalOverlayNode?.(e)===!0&&!L(e,t,n)}function L(e,t,n){let r=typeof e.parentIndex==`number`?t.get(e.parentIndex):void 0,i=new Set;for(;r&&!i.has(r.index);){if(R(r,n))return!0;i.add(r.index),r=typeof r.parentIndex==`number`?t.get(r.parentIndex):void 0}return!1}function R(e,t){return t.isAdditionalOverlayNode?.(e)===!0&&W(e.rect)!==null&&!i(e)}function z(e){return B(e,y)}function B(e,t){let n=V(e);return t.some(e=>n.includes(e))}function V(e){return[e.type,e.role,e.subrole].map(e=>n(e??``)).join(` `)}function H(e,t,n){return U(e,t,n)||U(t,e,n)}function U(e,t,n){let r=typeof t.parentIndex==`number`?n.get(t.parentIndex):void 0,i=new Set;for(;r&&!i.has(r.index);){if(r.index===e.index)return!0;i.add(r.index),r=typeof r.parentIndex==`number`?n.get(r.parentIndex):void 0}return!1}function W(e){let t=o(e);return t&&t.width>0&&t.height>0?t:null}function G(e){return Array.from(new Set([...e??[],`covered`]))}const K=new Set([`com.google.android.inputmethod.latin`,`com.samsung.android.honeyboard`,`com.touchtype.swiftkey`,`com.microsoft.swiftkey`]);function q(e){let t=$(e.packageName),n=(e.resourceId??``).toLowerCase(),r=$(e.activeInputMethodPackage);if(t&&r&&t===r)return{inputMethodOwned:!0,source:`active-input-method`};if(r&&n.startsWith(`${r}:id/`))return{inputMethodOwned:!0,source:`active-input-method-resource`};if(t&&K.has(t))return{inputMethodOwned:!0,source:`known-ime-package`};for(let e of K)if(n.startsWith(`${e}:id/`))return{inputMethodOwned:!0,source:`known-ime-resource`};return{inputMethodOwned:!1,source:`app`}}function J(e,t,n){return q({packageName:e,resourceId:t,activeInputMethodPackage:n}).inputMethodOwned}function Y(e){return q(e).inputMethodOwned}function X(e){return Y({packageName:e.bundleId,resourceId:e.identifier})}function Z(e){let t=$(e);return!!(t&&K.has(t))}function Q(e){let t=(e??``).toLowerCase();for(let e of K)if(t.startsWith(`${e}:id/`))return!0;return!1}function te(e,t,n){return!e&&!t?`unknown`:J(e,t,n)?`ime`:`app`}function ne(e){for(let t of[/\bmCurMethodId=([^\s]+)/i,/\bmCurId=([^\s]+)/i,/\bmCurrentInputMethodId=([^\s]+)/i,/\bcurMethodId=([^\s]+)/i]){let n=re(e.match(t)?.[1]);if(n)return n}}function re(e){let t=(e??``).trim();if(t)return $((t.split(`/`)[0]??``).match(/[a-zA-Z0-9_.]+/)?.[0])}function $(e){return(e??``).trim().toLowerCase()||void 0}export{Q as a,S as c,p as d,f,Z as i,w as l,m,X as n,ne as o,d as p,Y as r,x as s,te as t,u};
1
+ const e=new WeakMap;function t(t,n){return e.set(t,{...e.get(t),...n}),t}function n(e,n){return t(e,{clickability:n})}function r(t){return t?e.get(t)?.clickability:void 0}function i(e,t){let i=r(e);return i?n(t,i):t}function a(e,n){return t(e,{occlusionContext:n})}function o(t){return t?e.get(t)?.occlusionContext:void 0}const s=new Set([`com.google.android.inputmethod.latin`,`com.samsung.android.honeyboard`,`com.touchtype.swiftkey`,`com.microsoft.swiftkey`]);function c(e){let t=_(e.packageName),n=(e.resourceId??``).toLowerCase(),r=_(e.activeInputMethodPackage);if(t&&r&&t===r)return{inputMethodOwned:!0,source:`active-input-method`};if(r&&n.startsWith(`${r}:id/`))return{inputMethodOwned:!0,source:`active-input-method-resource`};if(t&&s.has(t))return{inputMethodOwned:!0,source:`known-ime-package`};for(let e of s)if(n.startsWith(`${e}:id/`))return{inputMethodOwned:!0,source:`known-ime-resource`};return{inputMethodOwned:!1,source:`app`}}function l(e,t,n){return c({packageName:e,resourceId:t,activeInputMethodPackage:n}).inputMethodOwned}function u(e){return c(e).inputMethodOwned}function d(e){return u({packageName:e.bundleId,resourceId:e.identifier})}function f(e){let t=_(e);return!!(t&&s.has(t))}function p(e){let t=(e??``).toLowerCase();for(let e of s)if(t.startsWith(`${e}:id/`))return!0;return!1}function m(e,t,n){return!e&&!t?`unknown`:l(e,t,n)?`ime`:`app`}function h(e){for(let t of[/\bmCurMethodId=([^\s]+)/i,/\bmCurId=([^\s]+)/i,/\bmCurrentInputMethodId=([^\s]+)/i,/\bcurMethodId=([^\s]+)/i]){let n=g(e.match(t)?.[1]);if(n)return n}}function g(e){let t=(e??``).trim();if(t)return _((t.split(`/`)[0]??``).match(/[a-zA-Z0-9_.]+/)?.[0])}function _(e){return(e??``).trim().toLowerCase()||void 0}export{p as a,a as c,o as d,f as i,i as l,d as n,h as o,u as r,n as s,m as t,r as u};
@@ -0,0 +1 @@
1
+ const e=`A system surface (notification shade, quick settings, or another system overlay) covers the app, so this snapshot shows that surface. Interact with it or dismiss it (press back or swipe up) to reach app content.`;function t(t){return t?.systemSurfaceOnly===!0?e:void 0}export{t as n,e as t};
@@ -0,0 +1 @@
1
+ function e(e){return async t=>{if(t.action!==`fill`){await e.setText(t.target,t.text);return}t.target&&await e.tap(t.target),await e.pressKey(`a`,[`ctrl`]),await e.pressKey(`del`),t.text.length>0&&await e.setText(void 0,t.text)}}export{e as createLimrunAndroidTextInjector};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime.js";import{c as t}from"./diagnostics.js";import"./diagnostics2.js";import{f as n}from"./adb-executor.js";import{A as r,C as i,D as a,E as o,M as s,N as c,O as l,P as u,S as d,T as f,_ as p,a as m,c as h,d as g,h as _,i as v,j as y,k as b,l as x,o as S,p as C,s as w,u as T,w as E,x as D}from"./mechanics.js";import{a as O,i as k,n as A}from"./app-lifecycle.js";import"./platform-runtime-android-adb-host.js";import{n as j}from"./scoped-provider.js";import{t as M}from"./snapshot-state.js";var N=e({createAndroidInteractor:()=>F});function P(e){return e?`daemon-session`:`command`}function F(e,N,F){let I=P(F?.appBundleId),L=t=>({...t===void 0?{}:{timeoutMs:t},captureNodes:async()=>{let t=await x(e,{includeHiddenContentHints:!1});return M(T(t),void 0).nodes}}),R={open:(t,n)=>k(e,t,{activity:n?.activity,appBundleId:n?.appBundleId,launchArgs:n?.launchArgs,url:n?.url}),openDevice:()=>O(e),close:t=>A(e,t),tap:(t,n)=>l(e,t,n),doubleTap:(t,n)=>E(e,t,n),longPress:(t,n,r)=>a(e,t,n,r),focus:(t,n)=>f(e,t,n),type:(t,n)=>m(e,t,n),fill:(t,n,r,i)=>v(e,t,n,r,i,{helperSessionScope:I}),scroll:(t,n)=>y(e,t,{...n,helperSessionScope:I}),performGesture:t=>c(e,t),gestureViewport:()=>u(e,{helperSessionScope:I}),screenshot:(t,n)=>S(e,t,n),readTextAtPoint:async(t,n)=>{let{readAndroidTextAtPoint:r}=await import(`./mechanics.js`).then(e=>e.r);return await r(e,t.x,t.y,{helperSessionScope:P(n?.appBundleId)})??void 0},snapshot:async n=>{let r=n??{},i=await t(`snapshot_capture`,async()=>await x(e,{appBundleId:r.appBundleId,signal:r.signal??F?.signal,interactiveOnly:r.interactiveOnly,depth:r.depth,scope:r.scope,raw:r.raw,includeHiddenContentHints:r.includeHiddenContentHints,helperSessionScope:P(r.appBundleId),transient:r.transient}),{backend:`android`});return T(i)},back:t=>i(e),home:()=>o(e),setOrientation:t=>s(e,t),appSwitcher:()=>d(e),tvRemote:(t,n)=>r(e,t,n),keyboardStatus:async()=>({kind:`ime-probe`,...await C(e)}),keyboardDismiss:async()=>({kind:`ime-probe`,...await g(e)}),keyboardEnter:async()=>(await b(e),{kind:`android-acknowledged`}),readClipboard:()=>_(e),writeClipboard:t=>p(e,t),setSetting:(t,n,r,i)=>h(e,t,n,r,i),readSetting:t=>w(e,t),readAlert:async()=>await D(e,`get`,L()),awaitAlert:async t=>await D(e,`wait`,L(t?.timeoutMs)),acceptAlert:async()=>await D(e,`accept`,L()),dismissAlert:async()=>await D(e,`dismiss`,L())};return N?j(R,t=>n(N,{serial:e.id},t)):R}export{F as n,N as t};
1
+ import{r as e}from"./rolldown-runtime.js";import{c as t}from"./diagnostics.js";import"./diagnostics2.js";import{f as n}from"./adb-executor.js";import{A as r,D as i,E as a,F as o,I as s,L as c,M as l,N as u,O as d,P as f,T as p,a as m,b as h,c as g,g as _,i as v,j as y,k as b,l as x,m as S,o as C,s as w,u as T,v as E,w as D}from"./mechanics.js";import{a as O,o as k,r as A}from"./app-lifecycle.js";import"./platform-runtime-android-adb-host.js";import{n as j}from"./scoped-provider.js";import{t as M}from"./snapshot-state.js";var N=e({createAndroidInteractor:()=>F});function P(e){return e?`daemon-session`:`command`}function F(e,N,F){let I=P(F?.appBundleId),L=t=>({...t===void 0?{}:{timeoutMs:t},captureNodes:async()=>{let t=await x(e,{includeHiddenContentHints:!1});return M(T(t),void 0).nodes}}),R={open:(t,n)=>O(e,t,{activity:n?.activity,appBundleId:n?.appBundleId,launchArgs:n?.launchArgs,url:n?.url}),openDevice:()=>k(e),close:t=>A(e,t),tap:(t,n)=>y(e,t,n),doubleTap:(t,n)=>i(e,t,n),longPress:(t,n,i)=>r(e,t,n,i),focus:(t,n)=>d(e,t,n),type:(t,n)=>m(e,t,n),fill:(t,n,r,i)=>v(e,t,n,r,i,{helperSessionScope:I}),scroll:(t,n)=>f(e,t,{...n,helperSessionScope:I}),performGesture:t=>s(e,t),gestureViewport:()=>c(e,{helperSessionScope:I}),screenshot:(t,n)=>C(e,t,n),readTextAtPoint:async(t,n)=>{let{readAndroidTextAtPoint:r}=await import(`./mechanics.js`).then(e=>e.r);return await r(e,t.x,t.y,{helperSessionScope:P(n?.appBundleId)})??void 0},snapshot:async n=>{let r=n??{},i=await t(`snapshot_capture`,async()=>await x(e,{appBundleId:r.appBundleId,signal:r.signal??F?.signal,interactiveOnly:r.interactiveOnly,depth:r.depth,scope:r.scope,raw:r.raw,includeHiddenContentHints:r.includeHiddenContentHints,helperSessionScope:P(r.appBundleId),transient:r.transient}),{backend:`android`});return T(i)},back:t=>a(e),home:()=>b(e),setOrientation:t=>o(e,t),appSwitcher:()=>p(e),tvRemote:(t,n)=>u(e,t,n),keyboardStatus:async()=>({kind:`ime-probe`,...await _(e)}),keyboardDismiss:async()=>({kind:`ime-probe`,...await S(e)}),keyboardEnter:async()=>(await l(e),{kind:`android-acknowledged`}),readClipboard:()=>E(e),writeClipboard:t=>h(e,t),setSetting:(t,n,r,i)=>g(e,t,n,r,i),readSetting:t=>w(e,t),readAlert:async()=>await D(e,`get`,L()),awaitAlert:async t=>await D(e,`wait`,L(t?.timeoutMs)),acceptAlert:async()=>await D(e,`accept`,L()),dismissAlert:async()=>await D(e,`dismiss`,L())};return N?j(R,t=>n(N,{serial:e.id},t)):R}export{F as n,N as t};
@@ -1 +1 @@
1
- import{P as e}from"./sdk-contracts.js";import{O as t,d as n}from"./sdk-device.js";import{a as r}from"./session.js";import{b as i}from"./owner-identity.js";import"./process.js";import{n as a}from"./gesture-admission.js";const o={visionos:`visionOS uses spatial input and does not support two-finger touch synthesis.`,tvos:`tvOS has no touch input — this gesture is supported on Android and the iOS simulator only.`,macos:`macOS automation has no multi-touch input — this gesture is supported on Android and the iOS simulator only.`};function s(r,i){if(!n(r.platform))throw c(i,r.platform);let s=t(r);if(s!==`ios`&&s!==`ipados`||r.kind!==`simulator`)throw s===`ios`||s===`ipados`?new e(`UNSUPPORTED_OPERATION`,`gesture ${i} is not supported on physical iOS devices`,{hint:`Two-finger gesture synthesis is iOS-simulator only — not available on physical iOS devices.`}):c(i,a[s],o[s])}function c(t,n,r){return new e(`UNSUPPORTED_OPERATION`,`gesture ${t} is not supported on ${n}`,r===void 0?void 0:{hint:r})}function l(){return r(i)}export{o as n,s as r,l as t};
1
+ import{P as e}from"./sdk-contracts.js";import{A as t,f as n}from"./sdk-device.js";import{a as r}from"./session.js";import{T as i}from"./file.js";import"./process.js";import{n as a}from"./gesture-admission.js";const o={visionos:`visionOS uses spatial input and does not support two-finger touch synthesis.`,tvos:`tvOS has no touch input — this gesture is supported on Android and the iOS simulator only.`,macos:`macOS automation has no multi-touch input — this gesture is supported on Android and the iOS simulator only.`};function s(r,i){if(!n(r.platform))throw c(i,r.platform);let s=t(r);if(s!==`ios`&&s!==`ipados`||r.kind!==`simulator`)throw s===`ios`||s===`ipados`?new e(`UNSUPPORTED_OPERATION`,`gesture ${i} is not supported on physical iOS devices`,{hint:`Two-finger gesture synthesis is iOS-simulator only — not available on physical iOS devices.`}):c(i,a[s],o[s])}function c(t,n,r){return new e(`UNSUPPORTED_OPERATION`,`gesture ${t} is not supported on ${n}`,r===void 0?void 0:{hint:r})}function l(){return r(i)}export{o as n,s as r,l as t};
@@ -1 +1 @@
1
- import{n as e}from"./app-inventory.js";import"./device.js";import{d as t}from"./adb-executor.js";import{n}from"./adb-failure.js";import{n as r}from"./app-deployment-resolution.js";import{a as i,i as a}from"./app-parsers.js";const o=`android.intent.category.LAUNCHER`,s=`android.intent.category.LEANBACK_LAUNCHER`;async function c(t,n={}){let i=await l(t,n.target??`auto`);return(e(n.filter)===`user-installed`?(await p(t)).filter(e=>i.has(e)):Array.from(i)).map(e=>({package:e,name:r(e)})).sort((e,t)=>e.package.localeCompare(t.package))}async function l(e,n){let r=(await Promise.all(u(n).map(async n=>{let r=await t(e,d(n),{allowFailure:!0});return r.exitCode===0?f(r.stdout):[]}))).flat();return new Set(r)}function u(e){switch(e){case`mobile`:return[o];case`tv`:return[s];default:return[o,s]}}function d(e){return[`cmd`,`package`,`query-activities`,`--brief`,`-a`,`android.intent.action.MAIN`,`-c`,e]}function f(e){return e.trim().length===0?[]:a(e)}async function p(e){let r=await t(e,[`pm`,`list`,`packages`,`-3`],{allowFailure:!0});if(r.exitCode!==0)throw n(`Failed to list Android user-installed apps`,r);return i(r.stdout)}export{c as listAndroidAppsWithAdb};
1
+ import"./tv-remote.js";import{n as e}from"./app-inventory.js";import{d as t}from"./adb-executor.js";import{n}from"./adb-failure.js";import{p as r}from"./app-lifecycle.js";import{a as i,i as a}from"./app-parsers.js";const o=`android.intent.category.LAUNCHER`,s=`android.intent.category.LEANBACK_LAUNCHER`;async function c(t,n={}){let i=await l(t,n.target??`auto`);return(e(n.filter)===`user-installed`?(await p(t)).filter(e=>i.has(e)):Array.from(i)).map(e=>({package:e,name:r(e)})).sort((e,t)=>e.package.localeCompare(t.package))}async function l(e,n){let r=(await Promise.all(u(n).map(async n=>{let r=await t(e,d(n),{allowFailure:!0});return r.exitCode===0?f(r.stdout):[]}))).flat();return new Set(r)}function u(e){switch(e){case`mobile`:return[o];case`tv`:return[s];default:return[o,s]}}function d(e){return[`cmd`,`package`,`query-activities`,`--brief`,`-a`,`android.intent.action.MAIN`,`-c`,e]}function f(e){return e.trim().length===0?[]:a(e)}async function p(e){let r=await t(e,[`pm`,`list`,`packages`,`-3`],{allowFailure:!0});if(r.exitCode!==0)throw n(`Failed to list Android user-installed apps`,r);return i(r.stdout)}export{c as listAndroidAppsWithAdb};
@@ -0,0 +1,4 @@
1
+ //#region packages/contracts/src/app-inventory.d.ts
2
+ type AppsFilter = 'user-installed' | 'all';
3
+ //#endregion
4
+ export { AppsFilter as t };
@@ -1,2 +1,2 @@
1
- import{P as e}from"./sdk-contracts.js";import{a as t,i as n,o as r}from"./sdk-batch-runner.js";import{r as i}from"./diagnostics.js";import"./diagnostics2.js";import{m as a,p as o}from"./sdk-device.js";import{n as s,t as c}from"./launch-console.js";import"./observability.js";import{i as l,r as u}from"./exec.js";import"./command.js";import{i as d,n as f}from"./retry.js";import{D as p,o as m}from"./host-file.js";import{d as h,g,n as _}from"./config.js";import{a as v,o as y}from"./tool-provider.js";import{t as b}from"./physical-device-control.js";import{n as x}from"./simctl.js";import{c as S}from"./runner-client.js";import{t as C}from"./simulator.js";import{a as w,l as T,u as E}from"./app-resolution.js";import D from"node:path";function O(t){if(!(t instanceof e)||t.code!==`COMMAND_FAILED`)return!1;let n=t.details??{};if(n.exitCode!==4)return!1;let r=String(n.stderr??``).toLowerCase();return r.includes(`fbsopenapplicationserviceerrordomain`)&&r.includes(`the request to open`)}async function k(e,t){let n=await y(x(e,[`get_app_container`,e.id,t]),{allowFailure:!0});if(n.exitCode!==0)return{installed:!1};let r=n.stdout.trim();if(!r)return{installed:!1};let i=await v(`plutil`,[`-extract`,`CFBundleExecutable`,`raw`,`-o`,`-`,`${r}/Info.plist`],{allowFailure:!0});if(i.exitCode!==0||!i.stdout.trim())return{installed:!0};let a=`${r}/${i.stdout.trim()}`,o=await v(`otool`,[`-l`,a],{allowFailure:!0});if(o.exitCode!==0)return{installed:!0};let s=o.stdout.toLowerCase();return{installed:!0,simulatorCompatible:s.includes(`iossimulator`)||s.includes(`platform 7`)}}function A(e){return e.installed?e.simulatorCompatible===!1?`ARCH_MISMATCH`:`PERSISTENT_LAUNCH_FAIL`:`APP_NOT_INSTALLED`}function j(e){switch(e){case`ARCH_MISMATCH`:return`The app binary was not built for the simulator platform. Rebuild with a simulator destination or use a physical device.`;case`APP_NOT_INSTALLED`:return`The app bundle is not installed on this simulator. Run install before open.`;case`PERSISTENT_LAUNCH_FAIL`:return`The simulator repeatedly refused to launch the app. Inspect crash logs in Console.app or ~/Library/Logs/DiagnosticReports/ and consider reinstalling the app.`;default:return`The simulator failed to launch the app. Retry with --debug and inspect diagnostics log for details.`}}const M=25e3;async function N(i,l,u){let d=u?.launchConsole?.trim(),f=u?.launchArgs;if(d&&(!o(i)||i.kind!==`simulator`))throw new e(`UNSUPPORTED_OPERATION`,s);if(a(i)){if(f&&f.length>0)throw new e(`UNSUPPORTED_OPERATION`,`--launch-args is not supported on macOS; launch arguments are currently iOS-only.`);await E(i,l,u);return}let p=u?.url?.trim();if(p){if(d)throw new e(`INVALID_ARGS`,c);if(!n(p))throw new e(`INVALID_ARGS`,`open <app> <url> requires a valid URL target`);if(i.kind===`simulator`){let e=!!f||t(p);if(u?.terminateRunningApp||e){let t=u?.appBundleId??await w(i,l);e?await z(i,t,{...f?{launchArgs:f}:{},...u?.terminateRunningApp?{terminateRunningApp:!0}:{}}):await R(i,t)}await P(i,p,void 0,u?.runnerOptions);return}let a=u?.appBundleId??await w(i,l),o=r(a,p);if(!o)throw new e(`INVALID_ARGS`,`Deep link open on iOS devices requires an active app bundle ID. Open the app first, then open the URL.`);await W(i,o,{payloadUrl:p,launchArgs:f,runnerOptions:u?.runnerOptions});return}let m=l.trim();if(n(m)){if(d)throw new e(`INVALID_ARGS`,c);if(i.kind===`simulator`){await P(i,m,f,u?.runnerOptions);return}let t=r(u?.appBundleId,m);if(!t)throw new e(`INVALID_ARGS`,`Deep link open on iOS devices requires an active app bundle ID. Open the app first, then open the URL.`);await W(i,t,{payloadUrl:m,launchArgs:f,runnerOptions:u?.runnerOptions});return}let h=u?.appBundleId??await w(i,l);if(i.kind===`simulator`){await z(i,h,{...d?{launchConsole:d}:{},...f?{launchArgs:f}:{},...u?.terminateRunningApp?{terminateRunningApp:!0}:{}});return}await W(i,h,{launchArgs:f,runnerOptions:u?.runnerOptions})}async function P(t,n,r,i){if(r&&r.length>0)throw new e(`INVALID_ARGS`,`--launch-args is not supported with iOS simulator URL opens (simctl openurl ignores launch args). Launch the app first with --launch-args, then issue the URL open in a separate call.`);await C(t);let a=x(t,[`openurl`,t.id,n]);try{await y(a,{timeoutMs:h,...i?.signal?{signal:i.signal}:{}})}catch(n){throw l(n)?new e(`COMMAND_FAILED`,`xcrun simctl openurl did not answer within ${h}ms.`,{...n.details,reason:`ios-simulator-openurl-timeout`,timeoutMs:h,deviceId:t.id,hint:`The Simulator may still have received the URL; CoreSimulator is slow to answer. Retry the open, or answer any "Open in" prompt with alert accept.`}):n}}async function F(e){a(e)||e.kind===`simulator`&&await C(e)}async function I(e,t,n){if(a(e)){await T(e,t);return}let r=await w(e,t);if(e.kind===`simulator`){await R(e,r);return}await L(r),await b(e).terminateApp(e,r,{runnerOptions:n,runRunnerCommand:S})}async function L(t){let{iosSystemSurfaceHost:n,iosSystemSurfaceOpenRefusal:r}=await import(`./ios-system-surface.js`).then(e=>e.a);if(n(t))throw new e(`UNSUPPORTED_OPERATION`,r(t),{reason:`system-surface-host-not-openable`,appBundleId:t})}async function R(t,n){await L(n),await C(t);let r=x(t,[`terminate`,t.id,n]),i=await y(r,{allowFailure:!0,timeoutMs:g});if(i.exitCode!==0&&!i.stderr.toLowerCase().includes(`found nothing to terminate`))throw new e(`COMMAND_FAILED`,`xcrun exited with code ${i.exitCode}`,u(i,{cmd:`xcrun`,args:r}))}async function z(t,n,r){await L(n),await C(t);let i=0,a=f.fromTimeoutMs(_);try{await d(async({deadline:i})=>{if(i?.isExpired())throw new e(`COMMAND_FAILED`,`App launch deadline exceeded`,{timeoutMs:_});let a=x(t,B(t.id,n,r)),o=r?.launchConsole?await V(a,r.launchConsole):await y(a,{allowFailure:!0});if(o.exitCode!==0)throw new e(`COMMAND_FAILED`,`xcrun exited with code ${o.exitCode}`,u(o,{cmd:`xcrun`,args:a}))},{maxAttempts:10,baseDelayMs:1e3,maxDelayMs:5e3,jitter:.2,shouldRetry(e){return O(e)?(i+=1,i<3):!1}},{deadline:a})}catch(e){if(O(e)){let r=e,i=A(await k(t,n));r.details={...r.details,hint:j(i)}}throw e}}function B(e,t,n){let r=[`launch`];return n?.launchConsole&&r.push(`--console-pty`),n?.terminateRunningApp&&r.push(`--terminate-running-process`),r.push(e,t),n?.launchArgs&&n.launchArgs.length>0&&r.push(...n.launchArgs),r}async function V(t,n){await m(D.dirname(n));try{let e=await y(t,{allowFailure:!0,timeoutMs:M});return await H(n,e.stdout,e.stderr),e}catch(t){let r=(t instanceof e?t:void 0)?.details;if(r?.timeoutMs===M){let e=typeof r.stdout==`string`?r.stdout:``,t=typeof r.stderr==`string`?r.stderr:``;return await H(n,e,t),i({level:`warn`,phase:`ios_simulator_launch_console_capture_timeout`,data:{timeoutMs:M,logPath:n,stdoutBytes:Buffer.byteLength(e),stderrBytes:Buffer.byteLength(t)}}),{stdout:e,stderr:t,exitCode:0}}throw t}}async function H(e,t,n){await p(e,U(t,n))}function U(e,t){return!e||!t||e.endsWith(`
1
+ import{P as e}from"./sdk-contracts.js";import{a as t,i as n,o as r}from"./sdk-batch-runner.js";import{r as i}from"./diagnostics.js";import"./diagnostics2.js";import{g as a,h as o}from"./sdk-device.js";import{n as s,t as c}from"./launch-console.js";import"./observability.js";import{i as l,r as u}from"./exec.js";import{r as d,t as f}from"./retry.js";import"./command.js";import"./retry2.js";import{D as p,o as m}from"./host-file.js";import{d as h,g,n as _}from"./config.js";import{a as v,o as y}from"./tool-provider.js";import{t as b}from"./physical-device-control.js";import{n as x}from"./simctl.js";import{c as S}from"./runner-client.js";import{t as C}from"./simulator.js";import{a as w,d as T,u as E}from"./app-resolution.js";import D from"node:path";function O(t){if(!(t instanceof e)||t.code!==`COMMAND_FAILED`)return!1;let n=t.details??{};if(n.exitCode!==4)return!1;let r=String(n.stderr??``).toLowerCase();return r.includes(`fbsopenapplicationserviceerrordomain`)&&r.includes(`the request to open`)}async function k(e,t){let n=await y(x(e,[`get_app_container`,e.id,t]),{allowFailure:!0});if(n.exitCode!==0)return{installed:!1};let r=n.stdout.trim();if(!r)return{installed:!1};let i=await v(`plutil`,[`-extract`,`CFBundleExecutable`,`raw`,`-o`,`-`,`${r}/Info.plist`],{allowFailure:!0});if(i.exitCode!==0||!i.stdout.trim())return{installed:!0};let a=`${r}/${i.stdout.trim()}`,o=await v(`otool`,[`-l`,a],{allowFailure:!0});if(o.exitCode!==0)return{installed:!0};let s=o.stdout.toLowerCase();return{installed:!0,simulatorCompatible:s.includes(`iossimulator`)||s.includes(`platform 7`)}}function A(e){return e.installed?e.simulatorCompatible===!1?`ARCH_MISMATCH`:`PERSISTENT_LAUNCH_FAIL`:`APP_NOT_INSTALLED`}function j(e){switch(e){case`ARCH_MISMATCH`:return`The app binary was not built for the simulator platform. Rebuild with a simulator destination or use a physical device.`;case`APP_NOT_INSTALLED`:return`The app bundle is not installed on this simulator. Run install before open.`;case`PERSISTENT_LAUNCH_FAIL`:return`The simulator repeatedly refused to launch the app. Inspect crash logs in Console.app or ~/Library/Logs/DiagnosticReports/ and consider reinstalling the app.`;default:return`The simulator failed to launch the app. Retry with --debug and inspect diagnostics log for details.`}}const M=25e3;async function N(i,l,u){let d=u?.launchConsole?.trim(),f=u?.launchArgs;if(d&&(!o(i)||i.kind!==`simulator`))throw new e(`UNSUPPORTED_OPERATION`,s);if(a(i)){if(f&&f.length>0)throw new e(`UNSUPPORTED_OPERATION`,`--launch-args is not supported on macOS; launch arguments are currently iOS-only.`);await T(i,l,u);return}let p=u?.url?.trim();if(p){if(d)throw new e(`INVALID_ARGS`,c);if(!n(p))throw new e(`INVALID_ARGS`,`open <app> <url> requires a valid URL target`);if(i.kind===`simulator`){let e=!!f||t(p);if(u?.terminateRunningApp||e){let t=u?.appBundleId??await w(i,l);e?await z(i,t,{...f?{launchArgs:f}:{},...u?.terminateRunningApp?{terminateRunningApp:!0}:{}}):await R(i,t)}await P(i,p,void 0,u?.runnerOptions);return}let a=u?.appBundleId??await w(i,l),o=r(a,p);if(!o)throw new e(`INVALID_ARGS`,`Deep link open on iOS devices requires an active app bundle ID. Open the app first, then open the URL.`);await W(i,o,{payloadUrl:p,launchArgs:f,runnerOptions:u?.runnerOptions});return}let m=l.trim();if(n(m)){if(d)throw new e(`INVALID_ARGS`,c);if(i.kind===`simulator`){await P(i,m,f,u?.runnerOptions);return}let t=r(u?.appBundleId,m);if(!t)throw new e(`INVALID_ARGS`,`Deep link open on iOS devices requires an active app bundle ID. Open the app first, then open the URL.`);await W(i,t,{payloadUrl:m,launchArgs:f,runnerOptions:u?.runnerOptions});return}let h=u?.appBundleId??await w(i,l);if(i.kind===`simulator`){await z(i,h,{...d?{launchConsole:d}:{},...f?{launchArgs:f}:{},...u?.terminateRunningApp?{terminateRunningApp:!0}:{}});return}await W(i,h,{launchArgs:f,runnerOptions:u?.runnerOptions})}async function P(t,n,r,i){if(r&&r.length>0)throw new e(`INVALID_ARGS`,`--launch-args is not supported with iOS simulator URL opens (simctl openurl ignores launch args). Launch the app first with --launch-args, then issue the URL open in a separate call.`);await C(t);let a=x(t,[`openurl`,t.id,n]);try{await y(a,{timeoutMs:h,...i?.signal?{signal:i.signal}:{}})}catch(n){throw l(n)?new e(`COMMAND_FAILED`,`xcrun simctl openurl did not answer within ${h}ms.`,{...n.details,reason:`ios-simulator-openurl-timeout`,timeoutMs:h,deviceId:t.id,hint:`The Simulator may still have received the URL; CoreSimulator is slow to answer. Retry the open, or answer any "Open in" prompt with alert accept.`}):n}}async function F(e){a(e)||e.kind===`simulator`&&await C(e)}async function I(e,t,n){if(a(e)){await E(e,t);return}let r=await w(e,t);if(e.kind===`simulator`){await R(e,r);return}await L(r),await b(e).terminateApp(e,r,{runnerOptions:n,runRunnerCommand:S})}async function L(t){let{iosSystemSurfaceHost:n,iosSystemSurfaceOpenRefusal:r}=await import(`./ios-system-surface.js`).then(e=>e.a);if(n(t))throw new e(`UNSUPPORTED_OPERATION`,r(t),{reason:`system-surface-host-not-openable`,appBundleId:t})}async function R(t,n){await L(n),await C(t);let r=x(t,[`terminate`,t.id,n]),i=await y(r,{allowFailure:!0,timeoutMs:g});if(i.exitCode!==0&&!i.stderr.toLowerCase().includes(`found nothing to terminate`))throw new e(`COMMAND_FAILED`,`xcrun exited with code ${i.exitCode}`,u(i,{cmd:`xcrun`,args:r}))}async function z(t,n,r){await L(n),await C(t);let i=0,a=f.fromTimeoutMs(_);try{await d(async({deadline:i})=>{if(i?.isExpired())throw new e(`COMMAND_FAILED`,`App launch deadline exceeded`,{timeoutMs:_});let a=x(t,B(t.id,n,r)),o=r?.launchConsole?await V(a,r.launchConsole):await y(a,{allowFailure:!0});if(o.exitCode!==0)throw new e(`COMMAND_FAILED`,`xcrun exited with code ${o.exitCode}`,u(o,{cmd:`xcrun`,args:a}))},{maxAttempts:10,baseDelayMs:1e3,maxDelayMs:5e3,jitter:.2,shouldRetry(e){return O(e)?(i+=1,i<3):!1}},{deadline:a})}catch(e){if(O(e)){let r=e,i=A(await k(t,n));r.details={...r.details,hint:j(i)}}throw e}}function B(e,t,n){let r=[`launch`];return n?.launchConsole&&r.push(`--console-pty`),n?.terminateRunningApp&&r.push(`--terminate-running-process`),r.push(e,t),n?.launchArgs&&n.launchArgs.length>0&&r.push(...n.launchArgs),r}async function V(t,n){await m(D.dirname(n));try{let e=await y(t,{allowFailure:!0,timeoutMs:M});return await H(n,e.stdout,e.stderr),e}catch(t){let r=(t instanceof e?t:void 0)?.details;if(r?.timeoutMs===M){let e=typeof r.stdout==`string`?r.stdout:``,t=typeof r.stderr==`string`?r.stderr:``;return await H(n,e,t),i({level:`warn`,phase:`ios_simulator_launch_console_capture_timeout`,data:{timeoutMs:M,logPath:n,stdoutBytes:Buffer.byteLength(e),stderrBytes:Buffer.byteLength(t)}}),{stdout:e,stderr:t,exitCode:0}}throw t}}async function H(e,t,n){await p(e,U(t,n))}function U(e,t){return!e||!t||e.endsWith(`
2
2
  `)||e.endsWith(`\r`)?`${e}${t}`:`${e}\n${t}`}async function W(e,t,n){await L(t),await b(e).launchApp(e,t,{...n,runRunnerCommand:S})}export{N as n,F as r,I as t};
@@ -1,3 +1,4 @@
1
- import{r as e}from"./rolldown-runtime.js";import{F as t,P as n}from"./sdk-contracts.js";import{i as r}from"./sdk-batch-runner.js";import{d as i,g as a}from"./exec.js";import{t as o}from"./timeouts.js";import"./command.js";import{i as s,n as c}from"./retry.js";import{_ as l,g as u,o as d,p as f}from"./adb-executor.js";import{n as p}from"./device-shell.js";import{i as m,o as h}from"./adb-transport.js";import{n as g}from"./adb-failure.js";import{o as _}from"./adb.js";import{n as v,t as ee}from"./boot-diagnostics.js";import{n as y,r as b,t as te}from"./app-deployment-resolution.js";import{a as ne,i as re}from"./app-parsers.js";import{n as ie}from"./window-state.js";import x from"node:path";const ae=[`emulator`,`platform-tools`,x.join(`cmdline-tools`,`latest`,`bin`),x.join(`cmdline-tools`,`tools`,`bin`)];function S(e){let t=new Set,n=[];for(let r of e){let e=r.trim();!e||t.has(e)||(t.add(e),n.push(e))}return n}function C(e=u().environment,t){let n=e.ANDROID_SDK_ROOT?.trim(),r=e.ANDROID_HOME?.trim(),i=e.HOME?.trim(),a=t===`darwin`&&i?x.join(i,`Library`,`Android`,`sdk`):``,o=i?x.join(i,`Android`,`Sdk`):``;return S([n??``,r??``,a,o])}async function w(e=u().environment,t=u().files){let n=[],r,{hostPlatform:i}=await import(`./process.js`).then(e=>e.t);for(let a of C(e,i())){let e=[];for(let n of ae){let r=x.join(a,n);await t.isExecutable(r)&&e.push(r)}e.length!==0&&(r||=a,n.push(...e))}if(r&&(e.ANDROID_SDK_ROOT=e.ANDROID_SDK_ROOT?.trim()||r,e.ANDROID_HOME=e.ANDROID_HOME?.trim()||r),n.length===0)return;let a=(e.PATH??``).split(x.delimiter).map(e=>e.trim()).filter(e=>e.length>0);e.PATH=S([...n,...a]).join(x.delimiter)}const T=1e4;async function oe(e,t){await w();let r=e.avdName.trim();if(!r)throw new n(`INVALID_ARGS`,`Android emulator boot requires a non-empty AVD name.`);let o=e.timeoutMs??12e4;if(!await a(`adb`))throw new n(`TOOL_MISSING`,`adb not found in PATH`);if(!await a(`emulator`))throw new n(`TOOL_MISSING`,`emulator not found in PATH`);let s=await E(t,e.serial),c=D(s,r,e.serial);if(!c)throw new n(`DEVICE_NOT_FOUND`,`No Android emulator AVD named ${e.avdName}`,{requestedAvdName:r,availableAvds:s.map(e=>e.name),hint:"Run `emulator -list-avds` and pass an existing AVD name to --device."});let l=c.name,u=Date.now(),d=O(c)?c:void 0;if(!d){let t=[`-avd`,l];e.headless&&t.push(`-no-window`,`-no-audio`),i(`emulator`,t)}let f=d??await se({dependencies:t,avdName:l,serial:e.serial,timeoutMs:o}),p=Date.now()-u;return await j(f.id,Math.max(1e3,o-p)),{...(await E(t,e.serial)).find(e=>e.id===f.id)??f,name:l,booted:!0}}async function E(e,t){return await e.discoverLocal({platform:`android`,kind:`emulator`,...t?{serial:t}:{},...e.androidSerialAllowlist?{androidSerialAllowlist:[...e.androidSerialAllowlist]}:{}})}function D(e,t,n){let r=A(t);return e.find(e=>e.platform===`android`&&e.kind===`emulator`&&A(e.name)===r&&(!n||!O(e)||e.id===n))}function O(e){return k(e.id)}function k(e){return e.startsWith(`emulator-`)}function A(e){return e.toLowerCase().replaceAll(`_`,` `).replaceAll(/\s+/g,` `).trim()}async function se(e){let t=Date.now(),r=Math.min(1e3,Math.max(50,Math.floor(e.timeoutMs/20)));for(;Date.now()-t<e.timeoutMs;){try{let t=D(await E(e.dependencies,e.serial),e.avdName,e.serial);if(t&&O(t))return t}catch{}await o(r)}throw new n(`COMMAND_FAILED`,`Android emulator did not appear in time`,{avdName:e.avdName,serial:e.serial,timeoutMs:e.timeoutMs,hint:`Check emulator logs and verify the AVD can start from command line.`})}async function ce(e,t=T,n){return await l(m(h(e),p(`adb`,`shell`,[`getprop`,`sys.boot_completed`])),{allowFailure:!0,signal:n,timeoutMs:t})}async function j(e,t=6e4,r){let i=c.fromTimeoutMs(t),a=Math.min(1e3,Math.max(50,Math.floor(t/20))),o=Math.max(1,Math.ceil(t/a)),l,u=!1;try{await s(async({deadline:a})=>{if(a?.isExpired())throw u=!0,new n(`COMMAND_FAILED`,`Android boot deadline exceeded`,{serial:e,timeoutMs:t,elapsedMs:i.elapsedMs(),message:`timeout`});let o=Math.max(1e3,a?.remainingMs()??t),s=await ce(e,Math.min(o,T),r);if(l=s,s.stdout.trim()!==`1`)throw new n(`COMMAND_FAILED`,`Android device is still booting`,{serial:e,stdout:s.stdout,stderr:s.stderr,exitCode:s.exitCode})},{maxAttempts:o,baseDelayMs:a,maxDelayMs:a,jitter:0,shouldRetry:e=>{let t=v({error:e,stdout:l?.stdout,stderr:l?.stderr,context:{platform:`android`,phase:`boot`}});return t!==`ADB_TRANSPORT_UNAVAILABLE`&&t!==`ANDROID_BOOT_TIMEOUT`}},{deadline:i,phase:`boot`,signal:r,classifyReason:e=>v({error:e,stdout:l?.stdout,stderr:l?.stderr,context:{platform:`android`,phase:`boot`}})})}catch(n){le({error:n,serial:e,timeoutMs:t,deadline:i,lastBootResult:l,timedOut:u})}}function le(e){let n=t(e.error),r=ue(e,n);throw fe(n,r,e.timedOut,de(e,r))}function ue(e,t){let n=v({error:e.error,stdout:e.lastBootResult?.stdout,stderr:e.lastBootResult?.stderr,context:{platform:`android`,phase:`boot`}});return n===`BOOT_COMMAND_FAILED`&&t.message===`Android device is still booting`?`ANDROID_BOOT_TIMEOUT`:n}function de(e,n){return{serial:e.serial,timeoutMs:e.timeoutMs,elapsedMs:e.deadline.elapsedMs(),reason:n,hint:ee(n),stdout:e.lastBootResult?.stdout,stderr:e.lastBootResult?.stderr,exitCode:e.lastBootResult?.exitCode,...t(e.error).details??{}}}function fe(e,t,r,i){return r||t===`ANDROID_BOOT_TIMEOUT`?new n(`COMMAND_FAILED`,`Android device did not finish booting in time`,i):e.code===`TOOL_MISSING`?new n(`TOOL_MISSING`,e.message,i):t===`ADB_TRANSPORT_UNAVAILABLE`?new n(`COMMAND_FAILED`,e.message,i):new n(e.code,e.message,i,e.cause)}var pe=e({closeAndroidApp:()=>Z,isAmStartError:()=>J,listAndroidApps:()=>I,openAndroidApp:()=>U,openAndroidDevice:()=>X,parseAndroidLaunchComponent:()=>Y});const M=`android.intent.category.LAUNCHER`,N=`android.intent.category.LEANBACK_LAUNCHER`,P=`android.intent.category.DEFAULT`,F=new Set([`localhost`,`127.0.0.1`,`::1`,`[::1]`]);async function I(e,t){let n=await L(e);return(t===`user-installed`?(await B(e)).filter(e=>n.has(e)):Array.from(n)).sort((e,t)=>e.localeCompare(t)).map(e=>({package:e,name:y(e)}))}async function L(e){let t=new Set;for(let n of z(e,{includeFallbackWhenUnknown:!0})){let r=await _(e,[`cmd`,`package`,`query-activities`,`--brief`,`-a`,`android.intent.action.MAIN`,`-c`,n],{allowFailure:!0});if(r.exitCode===0&&r.stdout.trim().length!==0)for(let e of re(r.stdout))t.add(e)}return t}function R(e){return z(e)[0]??M}function z(e,t={}){return e.target===`tv`?[N]:e.target===`mobile`?[M]:t.includeFallbackWhenUnknown?[M,N]:[M]}async function B(e){let t=await _(e,[`pm`,`list`,`packages`,`-3`]);return ne(t.stdout)}function me(e){let t;try{t=new URL(e)}catch{return null}let n=t.hostname.toLowerCase();if(!F.has(n)||!t.port)return null;let r=Number(t.port);return Number.isInteger(r)?`tcp:${r}`:null}async function V(e,t){let r=me(t);if(!r)return;let i=f(d(e));try{await i.ensure({local:r,remote:r,ownerId:`localhost-url`})}catch(e){let t={localPort:r.replace(`tcp:`,``),operation:`adb reverse ${r} ${r}`};throw e instanceof n&&Object.assign(t,{reason:e.details?.reason,hint:e.details?.hint,diagnosticId:e.details?.diagnosticId,logPath:e.details?.logPath}),new n(`COMMAND_FAILED`,`Failed to ensure Android port reverse ${r} before opening localhost URL`,t,e)}}function H(e){return e.launchArgs??[]}async function U(e,t,n){e.booted||await j(e.id);let i=xe(n),a=i.activity,o=t.trim();if(r(o)){await he(e,o,i);return}if(i.url!==void 0){await ge(e,t,i);return}let s=await b(e,t),c=R(e);if(s.type===`intent`){await _e(e,s.value,i);return}if(a){await ve(e,s.value,a,c,i);return}await ye(e,s.value,c,i)}async function he(e,t,r){if(r.activity)throw new n(`INVALID_ARGS`,`Activity override is not supported when opening a deep link URL`);await V(e,t),await _(e,[`am`,`start`,`-W`,`-a`,`android.intent.action.VIEW`,`-d`,t,...Se(r.appBundleId),...H(r)])}async function ge(e,t,i){if(i.activity)throw new n(`INVALID_ARGS`,`Activity override is not supported when opening an app-bound deep link URL`);let a=i.url?.trim()??``;if(!r(a))throw new n(`INVALID_ARGS`,`Android app-bound open requires a valid URL target`);await V(e,a);let o=await be(e,t,`app-bound open`);await _(e,[`am`,`start`,`-W`,`-a`,`android.intent.action.VIEW`,`-d`,a,`-p`,o,...H(i)])}async function _e(e,t,r){if(r.activity)throw new n(`INVALID_ARGS`,`Activity override requires a package name, not an intent`);await _(e,[`am`,`start`,`-W`,`-a`,t,...H(r)])}async function ve(e,t,n,r,i){let a=n.includes(`/`)?n:`${t}/${n.startsWith(`.`)?n:`.${n}`}`;try{await _(e,W(a,r,i))}catch(n){throw await Ce(e,t,n),n}}async function ye(e,t,n,r){let i=await _(e,[`am`,`start`,`-W`,`-a`,`android.intent.action.MAIN`,`-c`,P,`-c`,n,`-p`,t,...H(r)],{allowFailure:!0});if(i.exitCode===0&&!J(i.stdout,i.stderr))return;let a=await we(e,t);if(!a)throw await K(e,t)?g(`Failed to launch ${t}`,i):G(t);await _(e,W(a,n,r))}function W(e,t,n){return[`am`,`start`,`-W`,`-a`,`android.intent.action.MAIN`,`-c`,P,`-c`,t,`-n`,e,...H(n)]}async function be(e,t,r){let i=await b(e,t);if(i.type===`intent`)throw new n(`INVALID_ARGS`,`Android ${r} requires a package name, not an intent`);return i.value}function xe(e){return typeof e==`string`?{activity:e}:e??{}}function Se(e){let t=e?.trim();return t?[`-p`,t]:[]}function G(e){return new n(`APP_NOT_INSTALLED`,`No package found matching "${e}"`,{package:e,hint:te})}async function K(e,t){let n=await _(e,[`pm`,`path`,t],{allowFailure:!0}),r=`${n.stdout}\n${n.stderr}`;return n.exitCode===0&&/\bpackage:/i.test(r)?!0:(q(r),!1)}async function Ce(e,t,r){if(q(r instanceof n?`${String(r.details?.stdout??``)}\n${String(r.details?.stderr??``)}`:``)||!await K(e,t))throw G(t)}function q(e){return/\bunknown package\b/i.test(e)||/\bpackage .* (?:was|is) not found\b/i.test(e)||/\bpackage .* does not exist\b/i.test(e)||/\bcould not find package\b/i.test(e)}async function we(e,t){let n=Array.from(new Set(z(e,{includeFallbackWhenUnknown:!0})));for(let r of n){let n=await _(e,[`cmd`,`package`,`resolve-activity`,`--brief`,`-a`,`android.intent.action.MAIN`,`-c`,r,t],{allowFailure:!0});if(n.exitCode!==0)continue;let i=Y(n.stdout);if(i)return i}return null}function J(e,t){return`${e}\n${t}`.split(`
2
- `).some(e=>{let t=e.toLowerCase();return t.startsWith(`error:`)&&(t.includes(`activity not started`)||t.includes(`unable to resolve intent`))})}function Y(e){let t=e.split(`
3
- `).map(e=>e.trim()).filter(Boolean);for(let e=t.length-1;e>=0;--e){let n=t[e];if(n===void 0||!n.includes(`/`))continue;let r=n.split(/\s+/)[0];if(r!==void 0)return r}return null}async function X(e){e.booted||await j(e.id)}async function Z(e,t){if(t.trim().toLowerCase()===`settings`){await _(e,[`am`,`force-stop`,`com.android.settings`]),await Q(e,`com.android.settings`);return}let r=await b(e,t);if(r.type===`intent`)throw new n(`INVALID_ARGS`,`Close requires a package name, not an intent`);await _(e,[`am`,`force-stop`,r.value]),await Q(e,r.value)}async function Q(e,t){await Te(e,t),await De(e,t)}async function Te(e,t){let n=Date.now()+2e3;for(;Date.now()<n;){if((await Ee(e))?.package!==t)return;await o(50)}}async function Ee(e){let t=await ie(e);return t.package?t:null}async function De(e,t){let n=Date.now()+2e3;for(;Date.now()<n;){if(!await $(e,t)&&(await o(150),!await $(e,t)))return;await o(50)}}async function $(e,t){return((await _(e,[`pidof`,t],{allowFailure:!0})).stdout??``).trim().length>0}export{X as a,j as c,U as i,w as l,Z as n,Y as o,J as r,oe as s,pe as t,C as u};
1
+ import{r as e}from"./rolldown-runtime.js";import{I as t,P as n}from"./sdk-contracts.js";import{i as r}from"./sdk-batch-runner.js";import{d as i,g as a}from"./exec.js";import{i as o,r as s,t as c}from"./retry.js";import"./command.js";import"./retry2.js";import{C as l,S as u,g as d,h as f,o as p,p as ee}from"./adb-executor.js";import{n as te}from"./device-shell.js";import{n as ne}from"./adb-failure.js";import{o as m}from"./adb.js";import{n as h,t as re}from"./boot-diagnostics.js";import{t as ie}from"./app-resolution-cache.js";import{a as ae,i as oe,n as g,o as se,t as ce}from"./app-parsers.js";import _ from"node:path";const le=[`emulator`,`platform-tools`,_.join(`cmdline-tools`,`latest`,`bin`),_.join(`cmdline-tools`,`tools`,`bin`)];function v(e){let t=new Set,n=[];for(let r of e){let e=r.trim();!e||t.has(e)||(t.add(e),n.push(e))}return n}function y(e=u().environment,t){let n=e.ANDROID_SDK_ROOT?.trim(),r=e.ANDROID_HOME?.trim(),i=e.HOME?.trim(),a=t===`darwin`&&i?_.join(i,`Library`,`Android`,`sdk`):``,o=i?_.join(i,`Android`,`Sdk`):``;return v([n??``,r??``,a,o])}async function ue(e=u().environment,t=u().files){let n=[],r,{hostPlatform:i}=await import(`./process.js`).then(e=>e.t);for(let a of y(e,i())){let e=[];for(let n of le){let r=_.join(a,n);await t.isExecutable(r)&&e.push(r)}e.length!==0&&(r||=a,n.push(...e))}if(r&&(e.ANDROID_SDK_ROOT=e.ANDROID_SDK_ROOT?.trim()||r,e.ANDROID_HOME=e.ANDROID_HOME?.trim()||r),n.length===0)return;let a=(e.PATH??``).split(_.delimiter).map(e=>e.trim()).filter(e=>e.length>0);e.PATH=v([...n,...a]).join(_.delimiter)}const de=1e4;async function fe(e,t){await ue();let r=e.avdName.trim();if(!r)throw new n(`INVALID_ARGS`,`Android emulator boot requires a non-empty AVD name.`);let o=e.timeoutMs??12e4;if(!await a(`adb`))throw new n(`TOOL_MISSING`,`adb not found in PATH`);if(!await a(`emulator`))throw new n(`TOOL_MISSING`,`emulator not found in PATH`);let s=await b(t,e.serial),c=x(s,r,e.serial);if(!c)throw new n(`DEVICE_NOT_FOUND`,`No Android emulator AVD named ${e.avdName}`,{requestedAvdName:r,availableAvds:s.map(e=>e.name),hint:"Run `emulator -list-avds` and pass an existing AVD name to --device."});let l=c.name,u=Date.now(),d=S(c)?c:void 0;if(!d){let t=[`-avd`,l];e.headless&&t.push(`-no-window`,`-no-audio`),i(`emulator`,t)}let f=d??await me({dependencies:t,avdName:l,serial:e.serial,timeoutMs:o}),p=Date.now()-u;return await w(f.id,Math.max(1e3,o-p)),{...(await b(t,e.serial)).find(e=>e.id===f.id)??f,name:l,booted:!0}}async function b(e,t){return await e.discoverLocal({platform:`android`,kind:`emulator`,...t?{serial:t}:{},...e.androidSerialAllowlist?{androidSerialAllowlist:[...e.androidSerialAllowlist]}:{}})}function x(e,t,n){let r=C(t);return e.find(e=>e.platform===`android`&&e.kind===`emulator`&&C(e.name)===r&&(!n||!S(e)||e.id===n))}function S(e){return pe(e.id)}function pe(e){return e.startsWith(`emulator-`)}function C(e){return e.toLowerCase().replaceAll(`_`,` `).replaceAll(/\s+/g,` `).trim()}async function me(e){let t=Date.now(),r=Math.min(1e3,Math.max(50,Math.floor(e.timeoutMs/20)));for(;Date.now()-t<e.timeoutMs;){try{let t=x(await b(e.dependencies,e.serial),e.avdName,e.serial);if(t&&S(t))return t}catch{}await o(r)}throw new n(`COMMAND_FAILED`,`Android emulator did not appear in time`,{avdName:e.avdName,serial:e.serial,timeoutMs:e.timeoutMs,hint:`Check emulator logs and verify the AVD can start from command line.`})}async function he(e,t=de,n){return await l(f(d(e),te(`adb`,`shell`,[`getprop`,`sys.boot_completed`])),{allowFailure:!0,signal:n,timeoutMs:t})}async function w(e,t=6e4,r){let i=c.fromTimeoutMs(t),a=Math.min(1e3,Math.max(50,Math.floor(t/20))),o=Math.max(1,Math.ceil(t/a)),l,u=!1;try{await s(async({deadline:a})=>{if(a?.isExpired())throw u=!0,new n(`COMMAND_FAILED`,`Android boot deadline exceeded`,{serial:e,timeoutMs:t,elapsedMs:i.elapsedMs(),message:`timeout`});let o=Math.max(1e3,a?.remainingMs()??t),s=await he(e,Math.min(o,de),r);if(l=s,s.stdout.trim()!==`1`)throw new n(`COMMAND_FAILED`,`Android device is still booting`,{serial:e,stdout:s.stdout,stderr:s.stderr,exitCode:s.exitCode})},{maxAttempts:o,baseDelayMs:a,maxDelayMs:a,jitter:0,shouldRetry:e=>{let t=h({error:e,stdout:l?.stdout,stderr:l?.stderr,context:{platform:`android`,phase:`boot`}});return t!==`ADB_TRANSPORT_UNAVAILABLE`&&t!==`ANDROID_BOOT_TIMEOUT`}},{deadline:i,phase:`boot`,signal:r,classifyReason:e=>h({error:e,stdout:l?.stdout,stderr:l?.stderr,context:{platform:`android`,phase:`boot`}})})}catch(n){ge({error:n,serial:e,timeoutMs:t,deadline:i,lastBootResult:l,timedOut:u})}}function ge(e){let n=t(e.error),r=_e(e,n);throw ye(n,r,e.timedOut,ve(e,r))}function _e(e,t){let n=h({error:e.error,stdout:e.lastBootResult?.stdout,stderr:e.lastBootResult?.stderr,context:{platform:`android`,phase:`boot`}});return n===`BOOT_COMMAND_FAILED`&&t.message===`Android device is still booting`?`ANDROID_BOOT_TIMEOUT`:n}function ve(e,n){return{serial:e.serial,timeoutMs:e.timeoutMs,elapsedMs:e.deadline.elapsedMs(),reason:n,hint:re(n),stdout:e.lastBootResult?.stdout,stderr:e.lastBootResult?.stderr,exitCode:e.lastBootResult?.exitCode,...t(e.error).details??{}}}function ye(e,t,r,i){return r||t===`ANDROID_BOOT_TIMEOUT`?new n(`COMMAND_FAILED`,`Android device did not finish booting in time`,i):e.code===`TOOL_MISSING`?new n(`TOOL_MISSING`,e.message,i):t===`ADB_TRANSPORT_UNAVAILABLE`?new n(`COMMAND_FAILED`,e.message,i):new n(e.code,e.message,i,e.cause)}const be=/\.(?:apk|aab)$/i,xe=/^[A-Za-z_][\w]*(\.[A-Za-z_][\w]*)+$/;function T(e){let t=e.trim();return t.length===0?`other`:be.test(t)?t.includes(`/`)||t.includes(`\\`)||t.startsWith(`.`)||t.startsWith(`~`)||!E(t)?`binary`:`package`:E(t)?`package`:`other`}function E(e){return xe.test(e)}function Se(e){return`Android runtime hints require an installed package name, not "${e}". Install or reinstall the app first, then relaunch by package.`}const Ce={settings:{type:`intent`,value:`android.settings.SETTINGS`}},D=`Run agent-device apps --platform android to discover the installed package name, then retry open with that exact package.`,O=ie();function k(e){return{platform:`android`,deviceId:e.id,variant:e.target??``}}async function we(e,t){return await O.invalidateWhile(k(e),t)}async function A(e,t,r={}){let i=t.trim(),a=T(i)===`package`;if(a&&!r.installedOnly)return{type:`package`,value:i};let o=Ce[i.toLowerCase()];if(o)return o;let s=k(e),c=r.installedOnly?void 0:O.get(s,i);if(c)return c;let l=r.userId===void 0?[]:[`--user`,String(r.userId)],u=(await m(e,[`pm`,`list`,`packages`,...l])).stdout.split(`
2
+ `).map(e=>e.replace(`package:`,``).trim()).filter(Boolean),d=e=>r.userId===void 0?O.set(s,i,e):e;if(a){if(!u.includes(i))throw j(t);return d({type:`package`,value:i})}let f=u.filter(e=>e.toLowerCase().includes(i.toLowerCase())),p=f[0];if(p!==void 0&&f.length===1)return d({type:`package`,value:p});throw f.length>1?new n(`INVALID_ARGS`,`Multiple packages matched "${t}"`,{matches:f,hint:`Run agent-device apps --platform android to see the exact installed package names before retrying open.`}):j(t)}function j(e){return new n(`APP_NOT_INSTALLED`,`No package found matching "${e}"`,{hint:D})}function M(e){let t=new Set([`com`,`android`,`google`,`app`,`apps`,`service`,`services`,`mobile`,`client`]),n=e.split(`.`).flatMap(e=>e.split(/[_-]+/)).map(e=>e.trim().toLowerCase()).filter(e=>e.length>0),r=n.at(-1)??e;for(let e=n.length-1;e>=0;--e){let i=n[e];if(i&&!t.has(i)){r=i;break}}return r.split(/[^a-z0-9]+/i).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}const N=[[`dumpsys`,`window`,`windows`],[`dumpsys`,`window`]],P={foreground:{tiers:[N,[[`dumpsys`,`activity`,`activities`],[`dumpsys`,`activity`]]],section:B(g)},blockingDialog:{tiers:[N],section:B([ce])}},Te=RegExp(`(?:${g.map(V).join(`|`)})(.*)$`,`gm`),F=new Map;function I(e){let t=new Map;return n=>{let r=n.join(` `),i=t.get(r)??m(e,n,{allowFailure:!0}).then(t=>{let n=t.stdout??``;return Oe(e,r,n),n});return t.set(r,i),i}}async function L(e,t=I(e)){for(let n of R(e,`foreground`)){let e=Ae(await t(n));if(e)return e}return{}}async function Ee(e,t=I(e)){for(let n of R(e,`blockingDialog`)){let{focusObserved:e,focus:r}=se(await t(n));if(r)return{status:`dialog`,focus:r};if(e)return{status:`clear`}}return{status:`unknown`}}function De(){F.clear()}function Oe(e,t,n){if(n.length===0)return;let r=F.get(e.id)??new Map;for(let[e,i]of Object.entries(P)){let a=z(e,t);r.get(a)!==!0&&r.set(a,i.section.test(n))}F.set(e.id,r)}function R(e,t){let n=F.get(e.id);return P[t].tiers.flatMap(e=>ke(e,t,n))}function ke(e,t,n){if(!n)return e;let r=e=>n.get(z(t,e.join(` `)))===!1,i=e.filter(e=>!r(e));return i.length===e.length||i.length===0?e:[...i,...e.filter(r)]}function z(e,t){return`${e} ${t}`}function B(e){return new RegExp(e.map(V).join(`|`))}function V(e){return e.replaceAll(/[.*+?^${}()|[\]\\]/g,String.raw`\$&`)}function Ae(e){for(let t of e.matchAll(Te)){let e=t[1]?.match(/\b([A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z0-9_]+)+)\/([A-Za-z0-9_.$]+)/);if(e?.[1]&&e[2])return{package:e[1],activity:e[2]}}return null}var je=e({androidActivityComponent:()=>Y,closeAndroidApp:()=>nt,isAmStartError:()=>Z,listAndroidApps:()=>Ne,openAndroidApp:()=>Be,openAndroidDevice:()=>tt,parseAndroidLaunchComponent:()=>Q});const H=`android.intent.category.LAUNCHER`,U=`android.intent.category.LEANBACK_LAUNCHER`,W=`android.intent.category.DEFAULT`,Me=new Set([`localhost`,`127.0.0.1`,`::1`,`[::1]`]);async function Ne(e,t){let n=await Pe(e);return(t===`user-installed`?(await Ie(e)).filter(e=>n.has(e)):Array.from(n)).sort((e,t)=>e.localeCompare(t)).map(e=>({package:e,name:M(e)}))}async function Pe(e){let t=new Set;for(let n of G(e,{includeFallbackWhenUnknown:!0})){let r=await m(e,[`cmd`,`package`,`query-activities`,`--brief`,`-a`,`android.intent.action.MAIN`,`-c`,n],{allowFailure:!0});if(r.exitCode===0&&r.stdout.trim().length!==0)for(let e of oe(r.stdout))t.add(e)}return t}function Fe(e){return G(e)[0]??H}function G(e,t={}){return e.target===`tv`?[U]:e.target===`mobile`?[H]:t.includeFallbackWhenUnknown?[H,U]:[H]}async function Ie(e){let t=await m(e,[`pm`,`list`,`packages`,`-3`]);return ae(t.stdout)}function Le(e){let t;try{t=new URL(e)}catch{return null}let n=t.hostname.toLowerCase();if(!Me.has(n)||!t.port)return null;let r=Number(t.port);return Number.isInteger(r)?`tcp:${r}`:null}async function K(e,t){let r=Le(t);if(!r)return;let i=ee(p(e));try{await i.ensure({local:r,remote:r,ownerId:`localhost-url`})}catch(e){let t={localPort:r.replace(`tcp:`,``),operation:`adb reverse ${r} ${r}`};throw e instanceof n&&Object.assign(t,{reason:e.details?.reason,hint:e.details?.hint,diagnosticId:e.details?.diagnosticId,logPath:e.details?.logPath}),new n(`COMMAND_FAILED`,`Failed to ensure Android port reverse ${r} before opening localhost URL`,t,e)}}const Re=String.raw`[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)*`,q=String.raw`[A-Za-z_$][A-Za-z0-9_$]*`,ze=RegExp(`^(?:${Re}/)?\\.?${q}(?:\\.${q})*$`);function J(e){if(!ze.test(e))throw new n(`INVALID_ARGS`,`Invalid Android activity component: ${e}`,{reason:`invalid-android-activity-component`,activity:e,hint:"Pass --activity as <package>/<Class>, .<Class>, or <Class>, using letters, digits, `_`, `.`, and `$`."})}function Y(e,t){return J(t),t.includes(`/`)?t:`${e}/${t.startsWith(`.`)?t:`.${t}`}`}function X(e){return e.launchArgs??[]}async function Be(e,t,n){let i=Je(n),a=i.activity;a!==void 0&&J(a),e.booted||await w(e.id);let o=t.trim();if(r(o)){await Ve(e,o,i);return}if(i.url!==void 0){await He(e,t,i);return}let s=await A(e,t),c=Fe(e);if(s.type===`intent`){await Ue(e,s.value,i);return}if(a){await We(e,s.value,a,c,i);return}await Ge(e,s.value,c,i)}async function Ve(e,t,r){if(r.activity)throw new n(`INVALID_ARGS`,`Activity override is not supported when opening a deep link URL`);await K(e,t),await m(e,[`am`,`start`,`-W`,`-a`,`android.intent.action.VIEW`,`-d`,t,...Ye(r.appBundleId),...X(r)])}async function He(e,t,i){if(i.activity)throw new n(`INVALID_ARGS`,`Activity override is not supported when opening an app-bound deep link URL`);let a=i.url?.trim()??``;if(!r(a))throw new n(`INVALID_ARGS`,`Android app-bound open requires a valid URL target`);await K(e,a);let o=await qe(e,t,`app-bound open`);await m(e,[`am`,`start`,`-W`,`-a`,`android.intent.action.VIEW`,`-d`,a,`-p`,o,...X(i)])}async function Ue(e,t,r){if(r.activity)throw new n(`INVALID_ARGS`,`Activity override requires a package name, not an intent`);await m(e,[`am`,`start`,`-W`,`-a`,t,...X(r)])}async function We(e,t,n,r,i){let a=Y(t,n);try{await m(e,Ke(a,r,i))}catch(n){throw await Qe(e,t,n),n}}async function Ge(e,t,n,r){let i=await m(e,[`am`,`start`,`-W`,`-a`,`android.intent.action.MAIN`,`-c`,W,`-c`,n,`-p`,t,...X(r)],{allowFailure:!0});if(i.exitCode===0&&!Z(i.stdout,i.stderr))return;let a=await et(e,t);if(!a)throw await Ze(e,t)?ne(`Failed to launch ${t}`,i):Xe(t);await m(e,Ke(a,n,r))}function Ke(e,t,n){return[`am`,`start`,`-W`,`-a`,`android.intent.action.MAIN`,`-c`,W,`-c`,t,`-n`,e,...X(n)]}async function qe(e,t,r){let i=await A(e,t);if(i.type===`intent`)throw new n(`INVALID_ARGS`,`Android ${r} requires a package name, not an intent`);return i.value}function Je(e){return typeof e==`string`?{activity:e}:e??{}}function Ye(e){let t=e?.trim();return t?[`-p`,t]:[]}function Xe(e){return new n(`APP_NOT_INSTALLED`,`No package found matching "${e}"`,{package:e,hint:D})}async function Ze(e,t){let n=await m(e,[`pm`,`path`,t],{allowFailure:!0}),r=`${n.stdout}\n${n.stderr}`;return n.exitCode===0&&/\bpackage:/i.test(r)?!0:($e(r),!1)}async function Qe(e,t,r){if($e(r instanceof n?`${String(r.details?.stdout??``)}\n${String(r.details?.stderr??``)}`:``)||!await Ze(e,t))throw Xe(t)}function $e(e){return/\bunknown package\b/i.test(e)||/\bpackage .* (?:was|is) not found\b/i.test(e)||/\bpackage .* does not exist\b/i.test(e)||/\bcould not find package\b/i.test(e)}async function et(e,t){let n=Array.from(new Set(G(e,{includeFallbackWhenUnknown:!0})));for(let r of n){let n=await m(e,[`cmd`,`package`,`resolve-activity`,`--brief`,`-a`,`android.intent.action.MAIN`,`-c`,r,t],{allowFailure:!0});if(n.exitCode!==0)continue;let i=Q(n.stdout);if(i)return i}return null}function Z(e,t){return`${e}\n${t}`.split(`
3
+ `).some(e=>{let t=e.toLowerCase();return t.startsWith(`error:`)&&(t.includes(`activity not started`)||t.includes(`unable to resolve intent`))})}function Q(e){let t=e.split(`
4
+ `).map(e=>e.trim()).filter(Boolean);for(let e=t.length-1;e>=0;--e){let n=t[e];if(n===void 0||!n.includes(`/`))continue;let r=n.split(/\s+/)[0];if(r!==void 0)return r}return null}async function tt(e){e.booted||await w(e.id)}async function nt(e,t){if(t.trim().toLowerCase()===`settings`){await m(e,[`am`,`force-stop`,`com.android.settings`]),await rt(e,`com.android.settings`);return}let r=await A(e,t);if(r.type===`intent`)throw new n(`INVALID_ARGS`,`Close requires a package name, not an intent`);await m(e,[`am`,`force-stop`,r.value]),await rt(e,r.value)}async function rt(e,t){await it(e,t),await ot(e,t)}async function it(e,t){let n=Date.now()+2e3;for(;Date.now()<n;){if((await at(e))?.package!==t)return;await o(50)}}async function at(e){let t=await L(e);return t.package?t:null}async function ot(e,t){let n=Date.now()+2e3;for(;Date.now()<n;){if(!await $(e,t)&&(await o(150),!await $(e,t)))return;await o(50)}}async function $(e,t){return((await m(e,[`pidof`,t],{allowFailure:!0})).stdout??``).trim().length>0}export{Se as _,Be as a,ue as b,I as c,De as d,D as f,T as g,we as h,Z as i,L as l,A as m,je as n,tt as o,M as p,nt as r,Q as s,Y as t,Ee as u,fe as v,y as x,w as y};
@@ -1,2 +1,2 @@
1
- import{P as e}from"./sdk-contracts.js";import"./command.js";import{runHarmonyShell as t}from"./hdc.js";import{invalidateHarmonyGestureViewport as n}from"./snapshot2.js";function r(e){return e.split(`
2
- `).map(e=>e.trim()).filter(e=>/^([a-zA-Z0-9_]+\.)+[a-zA-Z0-9_]+$/.test(e))}function i(e){let t=o(e);if(!t)return;let n=t.hapModuleInfos?.find(e=>e.mainElementName);if(n?.mainElementName)return{ability:n.mainElementName,module:n.moduleName}}function a(e){let t=o(e),n=t?.applicationInfo?.isSystemApp??t?.appInfo?.isSystemApp;return typeof n==`boolean`?n:void 0}function o(e){let t=e.indexOf(`{`);if(t!==-1)try{return JSON.parse(e.slice(t))}catch{return}}async function s(n,i,a={}){if(i===`all`)return c(r((await t(n,[`bm`,`dump`,`-a`],{timeoutMs:15e3,signal:a.signal})).stdout));let o=new AbortController,s=setTimeout(()=>o.abort(),6e4),d=u(a.signal,o.signal);try{return c(await l(n,r((await t(n,[`bm`,`dump`,`-a`],{timeoutMs:15e3,signal:d})).stdout),d))}catch(t){throw o.signal.aborted?new e(`COMMAND_FAILED`,`Timed out while classifying HarmonyOS application inventory`,{hint:`Use apps --all to list bundles without per-bundle classification, then retry after the device is responsive.`}):t}finally{clearTimeout(s)}}function c(e){return e.map(e=>({package:e,name:e.split(`.`).at(-1)??e}))}async function l(n,r,i){let o=Array(r.length),s=new AbortController,c=u(i,s.signal),l=0,d,f=Math.min(4,r.length),p=Array.from({length:f},async()=>{try{for(;;){c?.throwIfAborted();let i=l++;if(i>=r.length)return;let s=r[i];if(!s)return;let u=a((await t(n,[`bm`,`dump`,`-n`,s],{timeoutMs:15e3,signal:c})).stdout);if(u===void 0)throw new e(`COMMAND_FAILED`,`Could not determine whether ${s} is a system application`,{hint:`Use apps --all to list all bundles when Bundle Manager does not expose applicationInfo.isSystemApp.`});o[i]=u}}catch(e){throw!c?.aborted&&d===void 0&&(d=e),s.abort(),e}}),m=await Promise.allSettled(p);if(d!==void 0)throw d;let h=m.find(e=>e.status===`rejected`);if(h)throw h.reason;return r.filter((e,t)=>!o[t])}function u(...e){let t=e.filter(e=>!!e);if(t.length!==0)return t.length===1?t[0]:AbortSignal.any(t)}async function d(r,a,o){let s=o?.activity?{ability:o.activity}:i((await t(r,[`bm`,`dump`,`-n`,a],{signal:o?.signal,timeoutMs:15e3})).stdout);if(!s)throw new e(`COMMAND_FAILED`,`Could not determine a launchable ability for ${a}`,{hint:`Pass --activity with the HarmonyOS ability name, or check that the bundle is installed.`});let c=[`aa`,`start`,`-a`,s.ability,`-b`,a];s.module&&c.push(`-m`,s.module);let l=await t(r,c,{signal:o?.signal});if(!l.stdout.includes(`start ability successfully`))throw new e(`COMMAND_FAILED`,`Failed to start ${a}`,{details:{output:l.stdout.trim()}});n(r)}async function f(e,r){await t(e,[`aa`,`force-stop`,r]),n(e)}export{f as closeHarmonyApp,s as listHarmonyApps,d as openHarmonyApp};
1
+ import{P as e}from"./sdk-contracts.js";import"./command.js";import{runHarmonyShell as t}from"./hdc.js";import{invalidateHarmonyGestureViewport as n}from"./snapshot.js";function r(e){return e.split(`
2
+ `).map(e=>e.trim()).filter(e=>/^([a-zA-Z0-9_]+\.)+[a-zA-Z0-9_]+$/.test(e))}function i(e){let t=o(e);if(!t)return;let n=t.hapModuleInfos?.find(e=>e.mainElementName);if(n?.mainElementName)return{ability:n.mainElementName,module:n.moduleName}}function a(e){let t=o(e),n=t?.applicationInfo?.isSystemApp??t?.appInfo?.isSystemApp;return typeof n==`boolean`?n:void 0}function o(e){let t=e.indexOf(`{`);if(t!==-1)try{return JSON.parse(e.slice(t))}catch{return}}async function s(n,i,a={}){if(i===`all`)return c(r((await t(n,[`bm`,`dump`,`-a`],{timeoutMs:15e3,signal:a.signal})).stdout));let o=new AbortController,s=setTimeout(()=>o.abort(),6e4),d=u(a.signal,o.signal);try{return c(await l(n,r((await t(n,[`bm`,`dump`,`-a`],{timeoutMs:15e3,signal:d})).stdout),d))}catch(t){throw o.signal.aborted?new e(`COMMAND_FAILED`,`Timed out while classifying HarmonyOS application inventory`,{hint:`Use apps --all to list bundles without per-bundle classification, then retry after the device is responsive.`}):t}finally{clearTimeout(s)}}function c(e){return e.map(e=>({package:e,name:e.split(`.`).at(-1)??e}))}async function l(n,r,i){let o=Array(r.length),s=new AbortController,c=u(i,s.signal),l=0,d,f=Math.min(4,r.length),p=Array.from({length:f},async()=>{try{for(;;){c?.throwIfAborted();let i=l++;if(i>=r.length)return;let s=r[i];if(!s)return;let u=a((await t(n,[`bm`,`dump`,`-n`,s],{timeoutMs:15e3,signal:c})).stdout);if(u===void 0)throw new e(`COMMAND_FAILED`,`Could not determine whether ${s} is a system application`,{hint:`Use apps --all to list all bundles when Bundle Manager does not expose applicationInfo.isSystemApp.`});o[i]=u}}catch(e){throw!c?.aborted&&d===void 0&&(d=e),s.abort(),e}}),m=await Promise.allSettled(p);if(d!==void 0)throw d;let h=m.find(e=>e.status===`rejected`);if(h)throw h.reason;return r.filter((e,t)=>!o[t])}function u(...e){let t=e.filter(e=>!!e);if(t.length!==0)return t.length===1?t[0]:AbortSignal.any(t)}const d=/^[A-Za-z][A-Za-z0-9_.]*$/;function f(t){if(!d.test(t))throw new e(`INVALID_ARGS`,`Invalid HarmonyOS ability name: ${t}`,{reason:`invalid-harmony-ability-name`,ability:t,hint:`Pass --activity as the ability name from module.json5, such as EntryAbility.`})}async function p(r,a,o){o?.activity!==void 0&&f(o.activity);let s=o?.activity?{ability:o.activity}:i((await t(r,[`bm`,`dump`,`-n`,a],{signal:o?.signal,timeoutMs:15e3})).stdout);if(!s)throw new e(`COMMAND_FAILED`,`Could not determine a launchable ability for ${a}`,{hint:`Pass --activity with the HarmonyOS ability name, or check that the bundle is installed.`});let c=[`aa`,`start`,`-a`,s.ability,`-b`,a];s.module&&c.push(`-m`,s.module);let l=await t(r,c,{signal:o?.signal});if(!l.stdout.includes(`start ability successfully`))throw new e(`COMMAND_FAILED`,`Failed to start ${a}`,{details:{output:l.stdout.trim()}});n(r)}async function m(e,r){await t(e,[`aa`,`force-stop`,r]),n(e)}export{m as closeHarmonyApp,s as listHarmonyApps,p as openHarmonyApp};
@@ -1 +1 @@
1
- import{P as e}from"./sdk-contracts.js";import{n as t,t as n}from"./verified-file.js";import"./file.js";import r from"node:fs";import i from"node:path";function a(e,t=process.env){let n=i.dirname(e);r.existsSync(n)||r.mkdirSync(n,{recursive:!0}),s(e),o(e,{maxBytes:l(t.AGENT_DEVICE_APP_LOG_MAX_BYTES,5242880),maxRotatedFiles:l(t.AGENT_DEVICE_APP_LOG_MAX_FILES,1)})}function o(e,t){let n=c(e);if(!(!n||n.size<t.maxBytes))for(let n=t.maxRotatedFiles;n>=1;--n){let t=n===1?e:`${e}.${n-1}`,i=`${e}.${n}`;c(t)&&(c(i)&&r.unlinkSync(i),r.renameSync(t,i))}}function s(e){c(e)}function c(r){let i=t(r);if(i?.isSymbolicLink())throw new e(`COMMAND_FAILED`,`App-log file must not be a symbolic link: ${r}`,{hint:n});return i}function l(e,t){let n=Number.parseInt(e??``,10);return Number.isInteger(n)&&n>0?n:t}export{a as t};
1
+ import{P as e}from"./sdk-contracts.js";import"./file.js";import t from"node:fs";import n from"node:path";const r=`agent-device only reads and writes regular files at this path. Remove the symbolic link or special file there and retry.`,i=`Another process replaced the file at this path while it was being opened. Stop the concurrent writer, then retry.`;function a(e){return c(e,t.constants.O_RDONLY,!1)}function o(e){return c(e,t.constants.O_WRONLY|t.constants.O_APPEND,!0)}function s(e){let n=c(e,t.constants.O_RDWR,!0);try{return t.ftruncateSync(n,0),n}catch(e){throw t.closeSync(n),e}}function c(t,n,r){for(let e=0;e<2;e+=1){let e=l(t,n,r);if(e.status!==`retry`)return e.status===`missing`?void 0:e.descriptor}throw new e(`COMMAND_FAILED`,`Final file could not be opened without an identity race: ${t}`,{hint:i})}function l(e,n,r){let i=m(e);if(!i&&!r)return{status:`missing`};let a=u(e,n,i===void 0,r);if(typeof a!=`number`)return a;try{return f(e,a,i),{status:`opened`,descriptor:a}}catch(e){throw t.closeSync(a),e}}function u(e,n,r,i){try{return t.openSync(e,n|_()|(r?t.constants.O_CREAT|t.constants.O_EXCL:0),384)}catch(e){let t=e.code,n=d(t,r,i);if(n)return n;throw e}}function d(e,t,n){if(e===`EEXIST`)return t?{status:`retry`}:void 0;if(e===`ENOENT`&&!t)return{status:n?`retry`:`missing`}}function f(e,n,r){let i=t.fstatSync(n),a=m(e);if(!i.isFile()||!a||!g(i,a)||r&&!g(r,i))throw p(e)}function p(t){return new e(`COMMAND_FAILED`,`Final file identity changed while it was opened: ${t}`,{hint:i})}function m(t){let n=h(t);if(n&&!n.isFile())throw new e(`COMMAND_FAILED`,`Final path must be a regular file: ${t}`,{hint:r});return n}function h(e){try{return t.lstatSync(e)}catch(e){if(e.code===`ENOENT`)return;throw e}}function g(e,t){return e.dev===t.dev&&e.ino===t.ino}function _(){let e=t.constants.O_NOFOLLOW;return Number.isInteger(e)&&e>0?e:0}function v(e,r=process.env){let i=n.dirname(e);t.existsSync(i)||t.mkdirSync(i,{recursive:!0}),b(e),y(e,{maxBytes:S(r.AGENT_DEVICE_APP_LOG_MAX_BYTES,5242880),maxRotatedFiles:S(r.AGENT_DEVICE_APP_LOG_MAX_FILES,1)})}function y(e,n){let r=x(e);if(!(!r||r.size<n.maxBytes))for(let r=n.maxRotatedFiles;r>=1;--r){let n=r===1?e:`${e}.${r-1}`,i=`${e}.${r}`;x(n)&&(x(i)&&t.unlinkSync(i),t.renameSync(n,i))}}function b(e){x(e)}function x(t){let n=h(t);if(n?.isSymbolicLink())throw new e(`COMMAND_FAILED`,`App-log file must not be a symbolic link: ${t}`,{hint:r});return n}function S(e,t){let n=Number.parseInt(e??``,10);return Number.isInteger(n)&&n>0?n:t}export{s as a,a as i,h as n,o as r,v as t};
@@ -1 +1 @@
1
- import{r as e}from"./device2.js";import{r as t}from"./client-options.js";import{N as n}from"./log-stream.js";import{t as r}from"./ios-client.js";import{t as i}from"./instance-client.js";import{t as a}from"./async-lifecycle.js";async function o(e){if(e.signal?.throwIfAborted(),e.descriptor.ownership===`attached`)return await s(e.instances??{},e.descriptor,e.dependencies);let r=t(e.limrun,`Reconnecting app logs`);try{return e.descriptor.platform===`ios`?await l({...e,limrun:r}):await d({...e,limrun:r})}catch(e){if(e instanceof n)return{status:`missing`};throw e}}async function s(e,t,n){return t.platform===`ios`?c(e.ios,t)?await u(e.ios,t):{status:`ownership-lost`}:c(e.android,t)?await f(e.android,t,n):{status:`ownership-lost`}}function c(t,n){return t!==void 0&&e(t.apiUrl)===n.instanceId}async function l(e){let t=await p(async()=>await e.limrun.iosInstances.get(e.descriptor.instanceId,{timeout:5e3,maxRetries:0,signal:e.signal}),e.descriptor);return t.status===`active`?await u({apiUrl:t.apiUrl,token:t.token},e.descriptor):t}async function u(e,t){let n=await r({apiUrl:e.apiUrl,token:e.token,logLevel:`warn`});return{status:`opened`,reader:{platform:`ios`,leaseId:t.leaseId,instanceId:t.instanceId,ownership:t.ownership,readLogs:async(e,t)=>await n.appLogTail(e,t),[Symbol.asyncDispose]:async()=>n.disconnect()}}}async function d(e){let t=await p(async()=>await e.limrun.androidInstances.get(e.descriptor.instanceId,{timeout:5e3,maxRetries:0,signal:e.signal}),e.descriptor);if(t.status!==`active`)return t;let{instance:n}=t;return n.status.adbWebSocketUrl?await f({apiUrl:t.apiUrl,adbUrl:n.status.adbWebSocketUrl,token:t.token},e.descriptor,e.dependencies):{status:`missing`}}async function f(e,t,n){let r=await i({apiUrl:e.apiUrl,adbUrl:e.adbUrl,token:e.token,logLevel:`warn`}),o=new a,s=!1;o.defer(async()=>{s||r.disconnect()});try{let e=await r.startAdbTunnel();o.defer(async()=>{s||e.close()});let i=`${e.address.address}:${e.address.port}`,a=async(e,t)=>await n.host.runAdb(n.android.deviceAdbInvocation(i,e),t),c={platform:`android`,leaseId:t.leaseId,instanceId:t.instanceId,ownership:t.ownership,readLogs:async(e,t)=>await n.android.readLogs(a,t),[Symbol.asyncDispose]:async()=>{await n.host.runAdb(n.android.hostAdbInvocation([`disconnect`,i]),{allowFailure:!0,timeoutMs:1e4}).catch(()=>void 0);let t=(await Promise.allSettled([Promise.resolve().then(()=>e.close()),Promise.resolve().then(()=>r.disconnect())])).flatMap(e=>e.status===`rejected`?[e.reason]:[]);if(t.length===1)throw t[0];if(t.length>1)throw AggregateError(t,`Limrun Android app-log reader cleanup failed`)}};return s=!0,{status:`opened`,reader:c}}finally{await o[Symbol.asyncDispose]()}}async function p(e,t){let n=await e();if(!m(n.metadata.labels,t))return{status:`ownership-lost`};let{apiUrl:r,token:i}=n.status;return n.status.state===`terminated`||!r||!i?{status:`missing`}:{status:`active`,instance:n,apiUrl:r,token:i}}function m(e,t){return e?.provider===`limrun`&&e.leaseId===t.leaseId}export{o as reconnectLimrunAppLogReader};
1
+ import{h as e,i as t}from"./src.js";import{N as n}from"./log-stream.js";import{t as r}from"./ios-client.js";import{t as i}from"./instance-client.js";import{t as a}from"./async-lifecycle.js";async function o(e){if(e.signal?.throwIfAborted(),e.descriptor.ownership===`attached`)return await s(e.instances??{},e.descriptor,e.dependencies);let r=t(e.limrun,`Reconnecting app logs`);try{return e.descriptor.platform===`ios`?await l({...e,limrun:r}):await d({...e,limrun:r})}catch(e){if(e instanceof n)return{status:`missing`};throw e}}async function s(e,t,n){return t.platform===`ios`?c(e.ios,t)?await u(e.ios,t):{status:`ownership-lost`}:c(e.android,t)?await f(e.android,t,n):{status:`ownership-lost`}}function c(t,n){return t!==void 0&&e(t.apiUrl)===n.instanceId}async function l(e){let t=await p(async()=>await e.limrun.iosInstances.get(e.descriptor.instanceId,{timeout:5e3,maxRetries:0,signal:e.signal}),e.descriptor);return t.status===`active`?await u({apiUrl:t.apiUrl,token:t.token},e.descriptor):t}async function u(e,t){let n=await r({apiUrl:e.apiUrl,token:e.token,logLevel:`warn`});return{status:`opened`,reader:{platform:`ios`,leaseId:t.leaseId,instanceId:t.instanceId,ownership:t.ownership,readLogs:async(e,t)=>await n.appLogTail(e,t),[Symbol.asyncDispose]:async()=>n.disconnect()}}}async function d(e){let t=await p(async()=>await e.limrun.androidInstances.get(e.descriptor.instanceId,{timeout:5e3,maxRetries:0,signal:e.signal}),e.descriptor);if(t.status!==`active`)return t;let{instance:n}=t;return n.status.adbWebSocketUrl?await f({apiUrl:t.apiUrl,adbUrl:n.status.adbWebSocketUrl,token:t.token},e.descriptor,e.dependencies):{status:`missing`}}async function f(e,t,n){let r=await i({apiUrl:e.apiUrl,adbUrl:e.adbUrl,token:e.token,logLevel:`warn`}),o=new a,s=!1;o.defer(async()=>{s||r.disconnect()});try{let e=await r.startAdbTunnel();o.defer(async()=>{s||e.close()});let i=`${e.address.address}:${e.address.port}`,a=async(e,t)=>await n.host.runAdb(n.android.deviceAdbInvocation(i,e),t),c={platform:`android`,leaseId:t.leaseId,instanceId:t.instanceId,ownership:t.ownership,readLogs:async(e,t)=>await n.android.readLogs(a,t),[Symbol.asyncDispose]:async()=>{await n.host.runAdb(n.android.hostAdbInvocation([`disconnect`,i]),{allowFailure:!0,timeoutMs:1e4}).catch(()=>void 0);let t=(await Promise.allSettled([Promise.resolve().then(()=>e.close()),Promise.resolve().then(()=>r.disconnect())])).flatMap(e=>e.status===`rejected`?[e.reason]:[]);if(t.length===1)throw t[0];if(t.length>1)throw AggregateError(t,`Limrun Android app-log reader cleanup failed`)}};return s=!0,{status:`opened`,reader:c}}finally{await o[Symbol.asyncDispose]()}}async function p(e,t){let n=await e();if(!m(n.metadata.labels,t))return{status:`ownership-lost`};let{apiUrl:r,token:i}=n.status;return n.status.state===`terminated`||!r||!i?{status:`missing`}:{status:`active`,instance:n,apiUrl:r,token:i}}function m(e,t){return e?.provider===`limrun`&&e.leaseId===t.leaseId}export{o as reconnectLimrunAppLogReader};
@@ -1,4 +1,4 @@
1
- import{P as e}from"./sdk-contracts.js";import{p as t}from"./sdk-device.js";import{$t as n,tn as r}from"./sdk-batch.js";import{a as i,o as a}from"./device2.js";import{n as o,r as s}from"./request-cancellation.js";import{n as c,t as l}from"./application-lifecycle-runtime.js";import{A as u,B as d,C as f,D as ee,F as te,G as p,I as m,J as h,M as ne,N as re,R as ie,U as ae,V as g,d as _,h as oe,k as se,n as ce,o as le,q as ue,s as de,v as fe,w as v,x as y,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,n as _e}from"./touch-runtime.js";import{r as ve}from"./platform-runtime-unavailable.js";import{a as ye,n as be}from"./durable-resource.js";import{t as xe}from"./async-lifecycle.js";import{a as b,d as Se,f as Ce,n as we,o as Te,u as Ee}from"./src7.js";import{i as De,t as Oe}from"./gesture-admission.js";import{n as ke}from"./interactor-operation-catalog.js";import{t as x}from"./app-log-runtime.js";import{r as Ae,t as je}from"./application-lifecycle-interaction.js";import{n as Me,r as Ne,t as Pe}from"./screen-recording-transport.js";import{setTimeout as Fe}from"node:timers/promises";const S=Object.freeze({available:!0}),Ie=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Limrun iOS direct sessions do not expose portable gesture execution yet.`}),Le=Object.freeze({available:!1,reason:`unsupported-provider-mode`}),Re=Object.freeze({available:!1,reason:`unsupported-provider-mode`}),ze=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:Oe}),Be=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:De});function C(e,t){if(!t.available)return m({unsupported:t});if(e.platform!==`android`)return m({unsupported:Ie});let n=e.target===`tv`;return m({unsupported:Le,plan:S,directionalFling:S,multiTouch:n?ze:S,targetAuthoredDrag:n?Be:S,viewport:S})}const Ve=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Limrun iOS direct sessions do not expose tv remote control.`}),He=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`tv-remote is supported only on Android TV targets.`}),Ue=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Limrun iOS direct sessions do not expose keyboard actions.`}),We=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Limrun iOS direct sessions cannot read settings back.`}),Ge=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Limrun iOS direct sessions do not expose app switcher yet.`}),w=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`No Limrun session exposes this system button.`});function T(e,n){let r=n??S,i=Object.freeze({available:!1,reason:`unsupported-provider-mode`});return Object.freeze({...pe({focus:r}),...u({type:r}),...ge({unsupported:i,tap:r,longPress:r,hover:n??i,fill:r,tapElementSelector:n??(t(e)?r:i)}),...C(e,r),...re({scroll:r})})}function Ke(e){let{device:t,signal:n}=e,r=n=>e.getInteractor(t,n);return Object.freeze({...ae({device:t,signal:n,resolveInteractor:r,presentIosAcquisition:e.presentIosAcquisition}),...ie({device:t,signal:n,resolveInteractor:r}),...se({device:t,signal:n,resolveInteractor:r}),..._e({device:t,signal:n,resolveInteractor:r,facts:T(t),pause:async e=>await Fe(e,void 0,{signal:n})}),...ue({device:t,signal:n,resolveInteractor:r}),...te({device:t,signal:n,facts:C(t,S),resolveInteractor:r}),...ne({device:t,signal:n,resolveInteractor:r})})}function E(e,t){return t?Object.freeze({...v({back:t}),...f({orientation:t}),...y({tvRemote:t})}):e.platform===`android`?Object.freeze({...v({back:S}),...f({orientation:S}),...y({tvRemote:e.target===`tv`?S:He})}):Object.freeze({...v({back:S}),...f({orientation:S}),...y({tvRemote:Ve})})}function D(e){return Object.freeze(e?{...oe({unsupported:e})}:{...oe({unsupported:Re,read:S,write:S})})}const qe=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Limrun iOS direct sessions do not expose alert inspection yet.`});function O(e,t){let n=t??(e.platform===`android`?S:qe);return Object.freeze({...ce({read:n,wait:n,accept:n,dismiss:n})})}function k(e,t){return t?_({unsupported:t}):e.platform===`android`?_({unsupported:w,home:S,appSwitcher:S}):_({unsupported:w,home:S,appSwitcher:Ge})}const A=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`fold runs a HID helper through simctl spawn inside a foldable iPhone simulator on the daemon host; a Limrun session has no such simulator.`});function j(){return Object.freeze({setFoldPose:A})}function M(e,t){return Object.freeze({...de({triggerAppEvent:t??S})})}function N(e,t){let n=t??S,r=t??(e.platform===`android`?S:We);return Object.freeze({...le({setSetting:n,readSetting:r})})}function P(e,t){let n=t??Ue,r=t===void 0&&e.platform===`android`;return Object.freeze({...fe(r?{unsupported:n,status:S,dismiss:S,enter:S}:{unsupported:n})})}const F=Object.freeze({resourceKind:x,version:1,encode:e=>({...e}),decode:e=>{let t=Ye(e.ownership);return!t||e.transport!==`limrun-log-poller`||e.platform!==`ios`&&e.platform!==`android`||!I(e.leaseId)||!I(e.instanceId)||!I(e.appBundleId)||!I(e.outputPath)?{status:`invalid`,message:`Invalid Limrun app-log descriptor`}:{status:`decoded`,descriptor:Object.freeze({transport:`limrun-log-poller`,platform:e.platform,leaseId:e.leaseId,instanceId:e.instanceId,ownership:t,appBundleId:e.appBundleId,outputPath:e.outputPath})}}});function Je(e){if(e.device.platform===`apple`&&!e.device.appleOs)throw TypeError(`Limrun Apple app-log persistence requires an explicit appleOs identity`);return be({resourceKind:x,sessionId:e.sessionId,device:{id:e.device.id,family:e.device.platform,...e.device.appleOs===void 0?{}:{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:ye(F,e.descriptor)})}function Ye(e){return e===void 0?`created`:e===`created`||e===`attached`?e:void 0}function I(e){return typeof e==`string`&&e.trim().length>0}async function L(e){let t=new xe,n=!1;t.defer(async()=>{n||await e.reader[Symbol.asyncDispose]()});try{let r=await e.host.outputs.readTail(e.outputPath,262144),i=await e.host.outputs.openAppend(e.outputPath);t.defer(async()=>{n||await i[Symbol.asyncDispose]()});let a=Xe(e,i,tt(r));return n=!0,a}finally{await t[Symbol.asyncDispose]()}}function Xe(e,t,n){let r=rt(e.reader),i=e.host.clock.now(),a=`active`,o=!1,s=n,c=(async()=>{for(;!o;){try{let n=await Ze(e);if(n.status===`timeout`){a=`failed`;return}if(o)return;let r=Qe(s,n.text);s=n.text,r&&await t.write(r.endsWith(`
2
- `)?r:`${r}\n`),a=`active`}catch{if(o)return;a=`recovering`}await e.host.clock.sleep(1e3)}})(),l;return Ee({inspect:()=>({backend:r,state:a,startedAt:i}),finish:async()=>l??=(async()=>(o=!0,await c,(await nt([e.reader,t])).length>0?(a=`failed`,{status:`cleanup-pending`,reason:`transport-failed`,message:`Limrun app-log cleanup did not settle every owned resource`}):(a=`ended`,{status:`completed`,result:{backend:r,outputPath:e.outputPath,completedAt:e.host.clock.now()}})))()})}async function Ze(e){let t=new AbortController,n=o(e.reader.readLogs(e.appBundleId,1e3),t.signal,`App-log provider read aborted`).then(e=>({status:`read`,text:e}));try{let r=await Promise.race([n,e.host.clock.sleep(5e3,t.signal).then(()=>({status:`timeout`}))]);return r.status===`timeout`&&(t.abort(),await n.catch(()=>void 0)),r}finally{t.abort()}}function Qe(e,t){if(!e||!t)return t;let n=$e(t),r=Math.min(e.length,t.length),i=e.slice(e.length-r);return t.slice(et(i,t,n))}function $e(e){let t=new Uint32Array(e.length),n=0;for(let r=1;r<e.length;r+=1){for(;n>0&&e[r]!==e[n];)n=t[n-1];e[r]===e[n]&&(n+=1),t[r]=n}return t}function et(e,t,n){let r=0;for(let i=0;i<e.length;i+=1){for(;r>0&&e[i]!==t[r];)r=n[r-1];e[i]===t[r]&&(r+=1),r===t.length&&i<e.length-1&&(r=n[r-1])}return r}function tt(e){return e.split(`
1
+ import{P as e}from"./sdk-contracts.js";import{h as t}from"./sdk-device.js";import{$t as n,Zt as r,en as i}from"./sdk-batch.js";import{_ as a,d as o,f as s,v as c}from"./src.js";import{B as l,C as u,E as d,F as ee,G as te,H as f,L as ne,M as re,P as ie,Q as ae,R as p,T as m,U as h,V as oe,X as g,Y as se,Z as ce,_,b as le,c as ue,i as de,j as fe,k as pe,l as me,n as he,p as v,q as y}from"./perf-runtime.js";import{i as ge,n as _e}from"./touch-runtime.js";import{n as ve}from"./audio-probe-runtime.js";import{r as ye}from"./platform-runtime-unavailable.js";import{a as be,n as xe}from"./durable-resource.js";import{t as Se}from"./async-lifecycle.js";import{a as b,d as Ce,f as we,n as Te,o as Ee,u as De}from"./src3.js";import{i as Oe,t as ke}from"./gesture-admission.js";import{n as Ae}from"./interactor-operation-catalog.js";import{t as x}from"./app-log-runtime.js";import{i as je,t as Me}from"./application-lifecycle-interaction.js";import{n as Ne,r as Pe,t as Fe}from"./screen-recording-transport.js";import{setTimeout as Ie}from"node:timers/promises";const S=Object.freeze({available:!0}),Le=i(`unsupported-provider-mode`,`Limrun iOS direct sessions do not expose portable gesture execution yet.`),Re=i(`unsupported-provider-mode`),ze=i(`unsupported-provider-mode`),Be=i(`unsupported-platform-leaf`,ke),Ve=i(`unsupported-platform-leaf`,Oe);function C(e,t){if(!t.available)return p({unsupported:t});if(e.platform!==`android`)return p({unsupported:Le});let n=e.target===`tv`;return p({unsupported:Re,plan:S,directionalFling:S,multiTouch:n?Be:S,targetAuthoredDrag:n?Ve:S,viewport:S})}const He=i(`unsupported-provider-mode`,`Limrun iOS direct sessions do not expose tv remote control.`),Ue=i(`unsupported-device-kind`,`tv-remote is supported only on Android TV targets.`),We=i(`unsupported-provider-mode`,`Limrun iOS direct sessions do not expose keyboard actions.`),Ge=i(`unsupported-provider-mode`,`Limrun iOS direct sessions cannot read settings back.`),Ke=i(`unsupported-provider-mode`,`Limrun iOS direct sessions do not expose app switcher yet.`),w=i(`unsupported-provider-mode`,`No Limrun session exposes this system button.`);function T(e,n){let r=n??S,a=i(`unsupported-provider-mode`);return Object.freeze({...oe({focus:r}),...re({type:r}),...ge({unsupported:a,tap:r,longPress:r,hover:n??a,fill:r,tapElementSelector:n??(t(e)?r:a)}),...C(e,r),...ee({scroll:r})})}function qe(e){let{device:t,signal:n}=e,r=n=>e.getInteractor(t,n);return Object.freeze({...te({device:t,signal:n,resolveInteractor:r,presentIosAcquisition:e.presentIosAcquisition}),...l({device:t,signal:n,resolveInteractor:r}),...fe({device:t,signal:n,resolveInteractor:r}),..._e({device:t,signal:n,resolveInteractor:r,facts:T(t),pause:async e=>await Ie(e,void 0,{signal:n})}),...se({device:t,signal:n,resolveInteractor:r}),...ne({device:t,signal:n,facts:C(t,S),resolveInteractor:r}),...ie({device:t,signal:n,resolveInteractor:r})})}function E(e,t){return t?Object.freeze({...d({back:t}),...m({orientation:t}),...u({tvRemote:t})}):e.platform===`android`?Object.freeze({...d({back:S}),...m({orientation:S}),...u({tvRemote:e.target===`tv`?S:Ue})}):Object.freeze({...d({back:S}),...m({orientation:S}),...u({tvRemote:He})})}function D(e){return Object.freeze(e?{..._({unsupported:e})}:{..._({unsupported:ze,read:S,write:S})})}const Je=i(`unsupported-provider-mode`,`Limrun iOS direct sessions do not expose alert inspection yet.`);function O(e,t){let n=t??(e.platform===`android`?S:Je);return Object.freeze({...de({read:n,wait:n,accept:n,dismiss:n})})}function k(e,t){return t?v({unsupported:t}):e.platform===`android`?v({unsupported:w,home:S,appSwitcher:S}):v({unsupported:w,home:S,appSwitcher:Ke})}const A=i(`unsupported-provider-mode`,`fold runs a HID helper through simctl spawn inside a foldable iPhone simulator on the daemon host; a Limrun session has no such simulator.`);function j(){return Object.freeze({setFoldPose:A})}function M(e,t){return Object.freeze({...me({triggerAppEvent:t??S})})}function N(e,t){let n=t??S,r=t??(e.platform===`android`?S:Ge);return Object.freeze({...ue({setSetting:n,readSetting:r})})}function P(e,t){let n=t??We,r=t===void 0&&e.platform===`android`;return Object.freeze({...le(r?{unsupported:n,status:S,dismiss:S,enter:S}:{unsupported:n})})}const F=Object.freeze({resourceKind:x,version:1,encode:e=>({...e}),decode:e=>{let t=Xe(e.ownership);return!t||e.transport!==`limrun-log-poller`||e.platform!==`ios`&&e.platform!==`android`||!I(e.leaseId)||!I(e.instanceId)||!I(e.appBundleId)||!I(e.outputPath)?{status:`invalid`,message:`Invalid Limrun app-log descriptor`}:{status:`decoded`,descriptor:Object.freeze({transport:`limrun-log-poller`,platform:e.platform,leaseId:e.leaseId,instanceId:e.instanceId,ownership:t,appBundleId:e.appBundleId,outputPath:e.outputPath})}}});function Ye(e){if(e.device.platform===`apple`&&!e.device.appleOs)throw TypeError(`Limrun Apple app-log persistence requires an explicit appleOs identity`);return xe({resourceKind:x,sessionId:e.sessionId,device:{id:e.device.id,family:e.device.platform,...e.device.appleOs===void 0?{}:{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:be(F,e.descriptor)})}function Xe(e){return e===void 0?`created`:e===`created`||e===`attached`?e:void 0}function I(e){return typeof e==`string`&&e.trim().length>0}async function L(e){let t=new Se,n=!1;t.defer(async()=>{n||await e.reader[Symbol.asyncDispose]()});try{let r=await e.host.outputs.readTail(e.outputPath,262144),i=await e.host.outputs.openAppend(e.outputPath);t.defer(async()=>{n||await i[Symbol.asyncDispose]()});let a=Ze(e,i,nt(r));return n=!0,a}finally{await t[Symbol.asyncDispose]()}}function Ze(e,t,n){let r=it(e.reader),i=e.host.clock.now(),a=`active`,o=!1,s=n,c=(async()=>{for(;!o;){try{let n=await Qe(e);if(n.status===`timeout`){a=`failed`;return}if(o)return;let r=$e(s,n.text);s=n.text,r&&await t.write(r.endsWith(`
2
+ `)?r:`${r}\n`),a=`active`}catch{if(o)return;a=`recovering`}await e.host.clock.sleep(1e3)}})(),l;return De({inspect:()=>({backend:r,state:a,startedAt:i}),finish:async()=>l??=(async()=>(o=!0,await c,(await rt([e.reader,t])).length>0?(a=`failed`,{status:`cleanup-pending`,reason:`transport-failed`,message:`Limrun app-log cleanup did not settle every owned resource`}):(a=`ended`,{status:`completed`,result:{backend:r,outputPath:e.outputPath,completedAt:e.host.clock.now()}})))()})}async function Qe(e){let t=new AbortController,n=o(e.reader.readLogs(e.appBundleId,1e3),t.signal,`App-log provider read aborted`).then(e=>({status:`read`,text:e}));try{let r=await Promise.race([n,e.host.clock.sleep(5e3,t.signal).then(()=>({status:`timeout`}))]);return r.status===`timeout`&&(t.abort(),await n.catch(()=>void 0)),r}finally{t.abort()}}function $e(e,t){if(!e||!t)return t;let n=et(t),r=Math.min(e.length,t.length),i=e.slice(e.length-r);return t.slice(tt(i,t,n))}function et(e){let t=new Uint32Array(e.length),n=0;for(let r=1;r<e.length;r+=1){for(;n>0&&e[r]!==e[n];)n=t[n-1];e[r]===e[n]&&(n+=1),t[r]=n}return t}function tt(e,t,n){let r=0;for(let i=0;i<e.length;i+=1){for(;r>0&&e[i]!==t[r];)r=n[r-1];e[i]===t[r]&&(r+=1),r===t.length&&i<e.length-1&&(r=n[r-1])}return r}function nt(e){return e.split(`
3
3
  `).filter(e=>!e.startsWith(`[agent-device][mark]`)).join(`
4
- `)}async function nt(e){return(await Promise.allSettled(e.map(async e=>await e[Symbol.asyncDispose]()))).flatMap(e=>e.status===`rejected`?[e.reason]:[])}function rt(e){return e.platform===`ios`?`ios-simulator`:`android`}function it(e){let t=je({owner:`Limrun`,openTargetIdentity:`bundle-id`,closeBeforeRelaunch:!0,configureProviderPortReverse:async t=>await e.configurePortReverse(t),binding:Ae({device:e.device,signal:e.signal,resolveInteractor:t=>e.getInteractor(e.device,t)})}),n=e.resolveAppReference;return n?Object.freeze({...t,resolveOpenTarget:async e=>await t.resolveOpenTarget(at(e,n)),openApplication:async e=>await t.openApplication(ot(e,n)),closeApplication:async e=>await t.closeApplication(st(e,n))}):t}function at(e,t){return e.target===void 0?e:{...e,target:t(e.target)}}function ot(e,t){return{...e,target:z(e.target,t),positionals:R(e.positionals,t),appBundleId:z(e.appBundleId,t)}}function st(e,t){return{...e,positionals:R(e.positionals,t),appBundleId:z(e.appBundleId,t)}}function R(e,t){let n=e[0];return n===void 0?e:[t(n),...e.slice(1)]}function z(e,t){return e===void 0?void 0:t(e)}function ct(e){let t=a(e.id);return!t||e.target!==`mobile`?!1:t.platform===`ios`?e.platform===`apple`&&e.appleOs===`ios`&&e.kind===`simulator`&&e.iosPhysicalDeviceBackend===void 0:e.platform===`android`&&e.appleOs===void 0&&e.kind===`emulator`&&e.iosPhysicalDeviceBackend===void 0}const lt=Object.freeze({available:!0}),B=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`The Limrun provider session is no longer active for this device.`}),ut=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Push notifications are unavailable for Limrun provider-owned devices.`});function V(e,t){let n=ft(e,t);return Object.freeze({deployApp:n,materializeAppSource:n,deployMaterializedApp:n,sendPushNotification:H(e,t)?ut:B})}function dt(e,t,n,r){let i=e.deployApp,a=e.deployMaterializedApp;return!V(e,t).deployApp.available||!i||!a?Object.freeze({}):Object.freeze({deployApp:async e=>U(await i(t,e,n,r)),materializeAppSource:async r=>await pt(e.host,t,r,n),deployMaterializedApp:async e=>U(await a(t,e,n,r))})}function ft(e,t){return ct(t)&&H(e,t)&&e.deployApp&&e.deployMaterializedApp?lt:B}function H(e,t){return e.isSessionActive?.(t)??e.ownsDevice(t)}async function pt(e,t,n,r){return await(t.platform===`apple`?e.appleDeployment:e.androidDeployment).prepareArtifact(n,{signal:r})}function U(t){if(!t)throw new e(`UNSUPPORTED_OPERATION`,`The Limrun provider session is no longer active.`);return t}const mt=Object.freeze({medium:5,high:8});function ht(e){return Object.freeze({screenRecordingStart:async t=>await gt(e,t),screenRecordingReattach:async()=>Ne(`Limrun recordings cannot be reattached after daemon restart.`),screenRecordingCleanup:async()=>Me(`Limrun recordings cannot be cleaned after daemon restart; the instance disposes them when it terminates.`)})}async function gt(t,n){let r=t.getDeviceSession(t.device);if(!r)throw new e(`UNSUPPORTED_OPERATION`,`Limrun recording requires a live provider session for this device.`,{deviceId:t.device.id});return await Pe({host:t.host,device:t.device,owner:t.owner,input:n,signal:t.signal,transport:{backend:`limrun-recorder`,targetLabel:`Limrun recording`,start:async()=>{await r.startRecording({quality:mt[n.exportQuality??`medium`]})},stop:async()=>(await r.stopRecording()).downloadUrl,collect:async(e,t)=>{await r.downloadRecording({downloadUrl:e,outPath:t})}},support:{scopes:[`app`,`device`,`system`],fps:!1,exportQuality:!0,hideTouches:!1},unsupported:e=>`Limrun recordings do not support ${e.join(`, `)}`})}const W=Object.freeze({available:!0}),G=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Custom snapshot actions are available only for Limrun iOS simulator sessions.`}),_t=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Limrun does not expose viewport resizing.`}),K=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Limrun-owned devices read element text from the captured tree only.`}),vt=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Headless boot is unavailable for provider-owned devices.`}),q=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`Limrun requires a matching live provider session for this device.`}),yt=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Apple runner preparation is unavailable for Limrun-owned devices.`}),bt=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Limrun iOS appstate is session-owned; no sessionless provider foreground probe is exposed.`}),xt=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Limrun open requires a Limrun-owned iOS simulator or Android emulator.`}),St=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Limrun close requires a Limrun-owned iOS simulator or Android emulator.`}),J=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Runtime hints are not applied to provider-owned devices.`}),Ct=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Limrun port reverse requires an active Android Limrun session.`}),Y=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Limrun does not expose the audio probe.`});function wt(e){return{...e,isSessionActive:e.hasLiveSession}}function X(e,t){let n=Tt(e,t),r=Et(e,t),i=Dt(e,t);return l({resolveOpenTarget:n,prepareApplicationOpen:n,openApplication:n,applyRuntimeHints:J,clearRuntimeHints:J,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:yt,configureProviderPortReverse:i})}function Tt(e,t){return i(e)?t?W:q:xt}function Et(e,t){return i(e)?t?W:q:St}function Dt(e,t){return t?e.platform===`android`?W:Ct:q}function Z(e,n){let r=V(wt(e),n),i=n.platform===`android`,a=t(n)&&n.kind===`simulator`?W:G;return Object.freeze({device:{family:n.platform,...n.appleOs===void 0?{}:{appleOs:n.appleOs},kind:n.kind,...n.target===void 0?{}:{target:n.target},...n.iosPhysicalDeviceBackend===void 0?{}:{iosPhysicalDeviceBackend:n.iosPhysicalDeviceBackend},providerMode:`provider-runtime`},operations:{appLogInspect:W,appLogDoctor:W,appLogStart:W,appLogReattach:W,appLogCleanup:W,...r,appState:i?W:bt,networkDump:W,screenRecordingStart:W,screenRecordingReattach:W,screenRecordingCleanup:W,...p({capture:W,customActions:a,withoutActiveApp:W}),...h({capture:W}),...g({findText:G}),...d({setViewport:_t}),...T(n),...ee({readTextAtPoint:K}),...E(n),...P(n),...D(),...k(n),...j(),...M(n),...N(n),...O(n),...me({capture:Y,query:Y}),...he({frames:K,memorySample:K,memorySnapshot:K,nativeCapture:K,profileReport:K}),ensureReady:W,bootTarget:W,bootTargetHeadless:vt,listApps:W,shutdownTarget:{available:!1,reason:`unsupported-provider-mode`,hint:`Limrun owns the target lifecycle for provider-owned devices.`},...X(n,!0)}})}function Ot(e,t){let n=Z(e,t);return Object.freeze({device:n.device,operations:{...n.operations,appLogInspect:q,appLogDoctor:q,appLogStart:q,appLogReattach:W,appLogCleanup:W,appState:q,networkDump:q,screenRecordingStart:q,screenRecordingReattach:q,screenRecordingCleanup:q,...p({capture:q,customActions:q,withoutActiveApp:q}),...h({capture:q}),...g({findText:q}),...d({setViewport:q}),...T(t,q),...E(t,q),...P(t,q),...D(q),...k(t,q),...j(),...M(t,q),...N(t,q),...O(t,q),ensureReady:q,bootTarget:q,bootTargetHeadless:q,listApps:q,deployApp:q,materializeAppSource:q,deployMaterializedApp:q,sendPushNotification:q,shutdownTarget:q,...X(t,!1)}})}function kt(t){let a=n(`limrun`,t.runtimeInstance),o=e=>i(e)&&t.ownsDevice(e),s=e=>o(e)&&t.hasLiveSession(e);return Object.freeze({owner:a,ownsDevice:o,inspectFacts:async e=>s(e)?Z(t,e):ve(e,a,{appLog:q,appState:q,appDeployment:q,network:q,screenshot:q,viewport:q,focus:q,gesture:q,scroll:q,typeText:q,touch:q,elementText:q,back:q,orientation:q,tvRemote:q,keyboard:q,clipboard:q,systemButton:q,fold:A,triggerAppEvent:q,settings:q,readAlert:q,awaitAlert:q,acceptAlert:q,dismissAlert:q,audioProbeCapture:q,audioProbeQuery:q,perf:q,readiness:q,shutdown:q,lifecycle:X(e,!1)}),bind:async n=>{if(n.intent.kind===`exact-owner`&&!r(n.intent.owner,a))throw new e(`UNSUPPORTED_OPERATION`,`Limrun app-log owner identity does not match`);if(!i(n.device))throw new e(`UNSUPPORTED_PLATFORM`,`Limrun app logs require an iOS simulator or Android emulator device identity`);let o=s(n.device);if(n.intent.kind!==`exact-owner`&&!o)throw new e(`UNSUPPORTED_OPERATION`,`Limrun provider session is no longer live for the selected device`,{reason:`provider-session-unavailable`});return At(t,a,n.device,n.scope.signal,!o)},shutdown:async()=>void 0})}function At(t,n,r,i,a){let o=a?Ot(t,r):Z(t,r),l=s(),u=Se({codec:F,reattach:async(e,n)=>{if(!$(e,r)||!b(t.host,n.sessionId,e))return{status:`unreattachable`,reason:`descriptor-invalid`,message:`Limrun app-log descriptor does not match the bound device or owning session`};let a=await t.reconnect(e,i);return a.status===`missing`?{status:`missing`}:a.status===`ownership-lost`?{status:`unreattachable`,reason:`ownership-fence-lost`}:{status:`active`,handle:await L({host:t.host,reader:a.reader,appBundleId:e.appBundleId,outputPath:e.outputPath})}},cleanup:async(e,n)=>$(e,r)&&b(t.host,n.sessionId,e)?{status:`cleaned`}:{status:`cleanup-pending`,reason:`ownership-fence-lost`,message:`Limrun app-log descriptor does not match the bound device or owning session`}}),d={appLogInspect:async()=>({backend:Q(r)}),appLogDoctor:async()=>({backend:Q(r),checks:{limrunSessionAvailable:await jt(t,r,i)},notes:[]}),appLogStart:async a=>{Te(t.host,a),i.throwIfAborted();let o=await t.openCurrent(r);if(!o)throw new e(`UNSUPPORTED_OPERATION`,`Limrun app logs require an active instance`);let s={transport:`limrun-log-poller`,platform:o.platform,leaseId:o.leaseId,instanceId:o.instanceId,ownership:o.ownership,appBundleId:a.appBundleId,outputPath:a.outputPath},c=!1;try{i.throwIfAborted();let e=Je({sessionId:a.sessionId,device:r,owner:n,fence:a.fence,descriptor:s});c=!0;let l=await L({host:t.host,reader:o,appBundleId:a.appBundleId,outputPath:a.outputPath});return Ce(l,e)}catch(e){throw c||await o[Symbol.asyncDispose](),e}},...u,networkDump:async e=>{let n=await t.host.appLogs.readRecent(e.sessionId,e.maxScanLines),i=Q(r),{dump:a}=we(n.text,{...e,path:n.path,exists:n.exists,lineNumberOffset:n.skippedLines,backend:i}),o=a.entries.length===0?[`No HTTP(s) entries were found in recent session app logs.`]:[];return Object.freeze({source:`app-log`,backend:i,dump:a,notes:o})},ensureReady:async()=>({...r,booted:!0}),bootTarget:async()=>({...r,booted:!0}),listApps:async e=>await t.listApps(e.device,e.filter,i),...r.platform===`android`?{appState:async()=>await t.getAppState(r,i)}:{},...c(it({device:r,signal:i,getInteractor:t.getInteractor,resolveAppReference:e=>t.resolveAppReference?.(r,e)??e,configurePortReverse:t.configurePortReverse}),o.operations),...Ke({device:r,signal:i,getInteractor:t.getInteractor,presentIosAcquisition:t.host.snapshot.presentIosAcquisition}),...ke({device:r,signal:i,resolveInteractor:e=>t.getInteractor(r,e),facts:o.operations}),...dt(wt(t),r,i,l),...ht({host:t.host,device:r,owner:n,signal:i,getDeviceSession:t.getDeviceSession})};return Object.freeze({device:r,owner:n,facts:o,operations:Object.freeze(a?{appLogReattach:u.appLogReattach,appLogCleanup:u.appLogCleanup}:d),[Symbol.asyncDispose]:async()=>await l[Symbol.asyncDispose]()})}async function jt(e,t,n){n.throwIfAborted();let r=await e.openCurrent(t);if(!r)return!1;try{n.throwIfAborted()}finally{await r[Symbol.asyncDispose]()}return!0}function Q(e){return e.platform===`apple`?`ios-simulator`:`android`}function $(e,t){if(!i(t))return!1;let n=a(t.id);return n!==void 0&&n.leaseId===e.leaseId&&n.platform===e.platform&&(t.platform===`apple`?e.platform===`ios`:e.platform===`android`)}export{kt as createLimrunPlatformRuntimeOwner};
4
+ `)}async function rt(e){return(await Promise.allSettled(e.map(async e=>await e[Symbol.asyncDispose]()))).flatMap(e=>e.status===`rejected`?[e.reason]:[])}function it(e){return e.platform===`ios`?`ios-simulator`:`android`}function at(e){let t=Me({owner:`Limrun`,openTargetIdentity:`bundle-id`,closeBeforeRelaunch:!0,configureProviderPortReverse:async t=>await e.configurePortReverse(t),binding:je({device:e.device,signal:e.signal,resolveInteractor:t=>e.getInteractor(e.device,t)})}),n=e.resolveAppReference;return n?Object.freeze({...t,resolveOpenTarget:async e=>await t.resolveOpenTarget(ot(e,n)),openApplication:async e=>await t.openApplication(st(e,n)),closeApplication:async e=>await t.closeApplication(ct(e,n))}):t}function ot(e,t){return e.target===void 0?e:{...e,target:t(e.target)}}function st(e,t){return{...e,target:z(e.target,t),positionals:R(e.positionals,t),appBundleId:z(e.appBundleId,t)}}function ct(e,t){return{...e,positionals:R(e.positionals,t),appBundleId:z(e.appBundleId,t)}}function R(e,t){let n=e[0];return n===void 0?e:[t(n),...e.slice(1)]}function z(e,t){return e===void 0?void 0:t(e)}function lt(e){let t=c(e.id);return!t||e.target!==`mobile`?!1:t.platform===`ios`?e.platform===`apple`&&e.appleOs===`ios`&&e.kind===`simulator`&&e.iosPhysicalDeviceBackend===void 0:e.platform===`android`&&e.appleOs===void 0&&e.kind===`emulator`&&e.iosPhysicalDeviceBackend===void 0}const ut=Object.freeze({available:!0}),B=i(`owner-capability-missing`,`The Limrun provider session is no longer active for this device.`),dt=i(`unsupported-provider-mode`,`Push notifications are unavailable for Limrun provider-owned devices.`);function V(e,t){let n=pt(e,t);return Object.freeze({deployApp:n,materializeAppSource:n,deployMaterializedApp:n,sendPushNotification:H(e,t)?dt:B})}function ft(e,t,n,r){let i=e.deployApp,a=e.deployMaterializedApp;return!V(e,t).deployApp.available||!i||!a?Object.freeze({}):Object.freeze({deployApp:async e=>U(await i(t,e,n,r)),materializeAppSource:async r=>await mt(e.host,t,r,n),deployMaterializedApp:async e=>U(await a(t,e,n,r))})}function pt(e,t){return lt(t)&&H(e,t)&&e.deployApp&&e.deployMaterializedApp?ut:B}function H(e,t){return e.isSessionActive?.(t)??e.ownsDevice(t)}async function mt(e,t,n,r){return await(t.platform===`apple`?e.appleDeployment:e.androidDeployment).prepareArtifact(n,{signal:r})}function U(t){if(!t)throw new e(`UNSUPPORTED_OPERATION`,`The Limrun provider session is no longer active.`);return t}const ht=Object.freeze({medium:5,high:8});function gt(e){return Object.freeze({screenRecordingStart:async t=>await _t(e,t),screenRecordingReattach:async()=>Pe(`Limrun recordings cannot be reattached after daemon restart.`),screenRecordingCleanup:async()=>Ne(`Limrun recordings cannot be cleaned after daemon restart; the instance disposes them when it terminates.`)})}async function _t(t,n){let r=t.getDeviceSession(t.device);if(!r)throw new e(`UNSUPPORTED_OPERATION`,`Limrun recording requires a live provider session for this device.`,{deviceId:t.device.id});return await Fe({host:t.host,device:t.device,owner:t.owner,input:n,signal:t.signal,transport:{backend:`limrun-recorder`,targetLabel:`Limrun recording`,start:async()=>{await r.startRecording({quality:ht[n.exportQuality??`medium`]})},stop:async()=>(await r.stopRecording()).downloadUrl,collect:async(e,t)=>{await r.downloadRecording({downloadUrl:e,outPath:t})}},support:{scopes:[`app`,`device`,`system`],fps:!1,exportQuality:!0,hideTouches:!1},unsupported:e=>`Limrun recordings do not support ${e.join(`, `)}`})}const W=Object.freeze({available:!0}),G=i(`unsupported-provider-mode`,`Custom snapshot actions are available only for Limrun iOS simulator sessions.`),vt=i(`unsupported-provider-mode`,`Limrun does not expose viewport resizing.`),K=i(`unsupported-provider-mode`,`Limrun-owned devices read element text from the captured tree only.`),yt=i(`unsupported-provider-mode`,`Headless boot is unavailable for provider-owned devices.`),q=i(`owner-capability-missing`,`Limrun requires a matching live provider session for this device.`),bt=i(`unsupported-provider-mode`,`Apple runner preparation is unavailable for Limrun-owned devices.`),xt=i(`unsupported-provider-mode`,`Limrun iOS appstate is session-owned; no sessionless provider foreground probe is exposed.`),St=i(`unsupported-provider-mode`,`Limrun open requires a Limrun-owned iOS simulator or Android emulator.`),Ct=i(`unsupported-provider-mode`,`Limrun close requires a Limrun-owned iOS simulator or Android emulator.`),J=i(`unsupported-provider-mode`,`Runtime hints are not applied to provider-owned devices.`),wt=i(`unsupported-provider-mode`,`Limrun port reverse requires an active Android Limrun session.`),Y=i(`unsupported-provider-mode`,`Limrun does not expose the audio probe.`);function X(e){return{...e,isSessionActive:e.hasLiveSession}}function Z(e,t){let n=Tt(e,t),r=Et(e,t),i=Dt(e,t);return ce({resolveOpenTarget:n,prepareApplicationOpen:n,openApplication:n,applyRuntimeHints:J,clearRuntimeHints:J,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:bt,configureProviderPortReverse:i})}function Tt(e,t){return a(e)?t?W:q:St}function Et(e,t){return a(e)?t?W:q:Ct}function Dt(e,t){return t?e.platform===`android`?W:wt:q}function Q(e,n){let r=V(X(e),n),a=n.platform===`android`,o=t(n)&&n.kind===`simulator`?W:G;return Object.freeze({device:{family:n.platform,...n.appleOs===void 0?{}:{appleOs:n.appleOs},kind:n.kind,...n.target===void 0?{}:{target:n.target},...n.iosPhysicalDeviceBackend===void 0?{}:{iosPhysicalDeviceBackend:n.iosPhysicalDeviceBackend},providerMode:`provider-runtime`},operations:{appLogInspect:W,appLogDoctor:W,appLogStart:W,appLogReattach:W,appLogCleanup:W,...r,appState:a?W:xt,networkDump:W,screenRecordingStart:W,screenRecordingReattach:W,screenRecordingCleanup:W,...y({capture:W,customActions:o,withoutActiveApp:W}),...g({capture:W}),...h({findText:G}),...f({setViewport:vt}),...T(n),...pe({readTextAtPoint:K}),...E(n),...P(n),...D(),...k(n),...j(),...M(n),...N(n),...O(n),...ve({capture:Y,query:Y}),...he({frames:K,memorySample:K,memorySnapshot:K,nativeCapture:K,profileReport:K}),ensureReady:W,bootTarget:W,bootTargetHeadless:yt,listApps:W,shutdownTarget:i(`unsupported-provider-mode`,`Limrun owns the target lifecycle for provider-owned devices.`),...Z(n,!0)}})}function Ot(e,t){let n=Q(e,t);return Object.freeze({device:n.device,operations:{...n.operations,appLogInspect:q,appLogDoctor:q,appLogStart:q,appLogReattach:W,appLogCleanup:W,appState:q,networkDump:q,screenRecordingStart:q,screenRecordingReattach:q,screenRecordingCleanup:q,...y({capture:q,customActions:q,withoutActiveApp:q}),...g({capture:q}),...h({findText:q}),...f({setViewport:q}),...T(t,q),...E(t,q),...P(t,q),...D(q),...k(t,q),...j(),...M(t,q),...N(t,q),...O(t,q),ensureReady:q,bootTarget:q,bootTargetHeadless:q,listApps:q,deployApp:q,materializeAppSource:q,deployMaterializedApp:q,sendPushNotification:q,shutdownTarget:q,...Z(t,!1)}})}function kt(t){let i=r(`limrun`,t.runtimeInstance),o=e=>a(e)&&t.ownsDevice(e),s=e=>o(e)&&t.hasLiveSession(e);return Object.freeze({owner:i,ownsDevice:o,inspectFacts:async e=>s(e)?Q(t,e):ye(e,i,{appLog:q,appState:q,appDeployment:q,network:q,screenshot:q,viewport:q,focus:q,gesture:q,scroll:q,typeText:q,touch:q,elementText:q,back:q,orientation:q,tvRemote:q,keyboard:q,clipboard:q,systemButton:q,fold:A,triggerAppEvent:q,settings:q,readAlert:q,awaitAlert:q,acceptAlert:q,dismissAlert:q,audioProbeCapture:q,audioProbeQuery:q,perf:q,readiness:q,shutdown:q,lifecycle:Z(e,!1)}),bind:async r=>{if(r.intent.kind===`exact-owner`&&!n(r.intent.owner,i))throw new e(`UNSUPPORTED_OPERATION`,`Limrun app-log owner identity does not match`);if(!a(r.device))throw new e(`UNSUPPORTED_PLATFORM`,`Limrun app logs require an iOS simulator or Android emulator device identity`);let o=s(r.device);if(r.intent.kind!==`exact-owner`&&!o)throw new e(`UNSUPPORTED_OPERATION`,`Limrun provider session is no longer live for the selected device`,{reason:`provider-session-unavailable`});return At(t,i,r.device,r.scope.signal,!o)},shutdown:async()=>void 0})}function At(t,n,r,i,a){let o=a?Ot(t,r):Q(t,r),c=s(),l=Ce({codec:F,reattach:async(e,n)=>{if(!Mt(e,r)||!b(t.host,n.sessionId,e))return{status:`unreattachable`,reason:`descriptor-invalid`,message:`Limrun app-log descriptor does not match the bound device or owning session`};let a=await t.reconnect(e,i);return a.status===`missing`?{status:`missing`}:a.status===`ownership-lost`?{status:`unreattachable`,reason:`ownership-fence-lost`}:{status:`active`,handle:await L({host:t.host,reader:a.reader,appBundleId:e.appBundleId,outputPath:e.outputPath})}},cleanup:async(e,n)=>Mt(e,r)&&b(t.host,n.sessionId,e)?{status:`cleaned`}:{status:`cleanup-pending`,reason:`ownership-fence-lost`,message:`Limrun app-log descriptor does not match the bound device or owning session`}}),u={appLogInspect:async()=>({backend:$(r)}),appLogDoctor:async()=>({backend:$(r),checks:{limrunSessionAvailable:await jt(t,r,i)},notes:[]}),appLogStart:async a=>{Ee(t.host,a),i.throwIfAborted();let o=await t.openCurrent(r);if(!o)throw new e(`UNSUPPORTED_OPERATION`,`Limrun app logs require an active instance`);let s={transport:`limrun-log-poller`,platform:o.platform,leaseId:o.leaseId,instanceId:o.instanceId,ownership:o.ownership,appBundleId:a.appBundleId,outputPath:a.outputPath},c=!1;try{i.throwIfAborted();let e=Ye({sessionId:a.sessionId,device:r,owner:n,fence:a.fence,descriptor:s});c=!0;let l=await L({host:t.host,reader:o,appBundleId:a.appBundleId,outputPath:a.outputPath});return we(l,e)}catch(e){throw c||await o[Symbol.asyncDispose](),e}},...l,networkDump:async e=>{let n=await t.host.appLogs.readRecent(e.sessionId,e.maxScanLines),i=$(r),{dump:a}=Te(n.text,{...e,path:n.path,exists:n.exists,lineNumberOffset:n.skippedLines,backend:i}),o=a.entries.length===0?[`No HTTP(s) entries were found in recent session app logs.`]:[];return Object.freeze({source:`app-log`,backend:i,dump:a,notes:o})},ensureReady:async()=>({...r,booted:!0}),bootTarget:async()=>({...r,booted:!0}),listApps:async e=>await t.listApps(e.device,e.filter,i),...r.platform===`android`?{appState:async()=>await t.getAppState(r,i)}:{},...ae(at({device:r,signal:i,getInteractor:t.getInteractor,resolveAppReference:e=>t.resolveAppReference?.(r,e)??e,configurePortReverse:t.configurePortReverse}),o.operations),...qe({device:r,signal:i,getInteractor:t.getInteractor,presentIosAcquisition:t.host.snapshot.presentIosAcquisition}),...Ae({device:r,signal:i,resolveInteractor:e=>t.getInteractor(r,e),facts:o.operations}),...ft(X(t),r,i,c),...gt({host:t.host,device:r,owner:n,signal:i,getDeviceSession:t.getDeviceSession})};return Object.freeze({device:r,owner:n,facts:o,operations:Object.freeze(a?{appLogReattach:l.appLogReattach,appLogCleanup:l.appLogCleanup}:u),[Symbol.asyncDispose]:async()=>await c[Symbol.asyncDispose]()})}async function jt(e,t,n){n.throwIfAborted();let r=await e.openCurrent(t);if(!r)return!1;try{n.throwIfAborted()}finally{await r[Symbol.asyncDispose]()}return!0}function $(e){return e.platform===`apple`?`ios-simulator`:`android`}function Mt(e,t){if(!a(t))return!1;let n=c(t.id);return n!==void 0&&n.leaseId===e.leaseId&&n.platform===e.platform&&(t.platform===`apple`?e.platform===`ios`:e.platform===`android`)}export{kt as createLimrunPlatformRuntimeOwner};
@@ -1 +1 @@
1
- import{a as e,c as t,i as n,n as r,o as i,r as a,s as o}from"./app-resolution.js";export{t as buildAppNotInstalledError,r as detectSoleRunningIosSimulatorApp,a as findIosSimulatorInstalledApp,n as invalidateIosAppResolutionCache,e as resolveIosApp,i as resolveIosAppAlias,o as resolveIosSimulatorDeepLinkBundleId};
1
+ import{a as e,i as t,l as n,n as r,o as i,r as a,s as o}from"./app-resolution.js";export{n as buildAppNotInstalledError,r as detectSoleRunningIosSimulatorApp,a as findIosSimulatorInstalledApp,t as invalidateIosAppResolutionCache,e as resolveIosApp,i as resolveIosAppAlias,o as resolveIosSimulatorDeepLinkBundleId};
@@ -1,2 +1,2 @@
1
- import{r as e}from"./rolldown-runtime.js";import{K as t,P as n}from"./sdk-contracts.js";import{i as r}from"./sdk-batch-runner.js";import{m as i,p as a}from"./sdk-device.js";import{_ as o}from"./settings.js";import{i as s}from"./exec.js";import"./command.js";import{t as c}from"./ttl-memo.js";import{n as l}from"./retry.js";import{t as u}from"./app-resolution-cache.js";import{u as ee}from"./host-file.js";import{a as d,i as f,l as p}from"./tool-provider.js";import{t as m}from"./physical-device-control.js";import{a as h}from"./simctl.js";import{r as g}from"./helper.js";import _ from"node:path";import{fileURLToPath as te}from"node:url";import{setTimeout as v}from"node:timers/promises";const y={settings:`com.apple.systempreferences`},b=/^[a-z0-9-]+(?:\.[a-z0-9-]+)+$/,x={platform:`macos`,deviceId:`host`,variant:`all`},S=u();function C(e){return b.test(e)}async function w(e){let t=e.trim(),r=y[t.toLowerCase()];if(r)return r;if(C(t))return t;let i=S.get(x,t);if(i)return i;let a=(await j(`all`)).filter(e=>e.name.toLowerCase()===t.toLowerCase()),o=a[0];if(o!==void 0&&a.length===1)return S.set(x,t,o.bundleId);throw a.length>1?new n(`INVALID_ARGS`,`Multiple apps matched "${e}"`,{matches:a}):new n(`APP_NOT_INSTALLED`,`No app found matching "${e}"`)}async function T(e,t,i){let a=i?.url?.trim();if(a){if(!r(a))throw new n(`INVALID_ARGS`,`open <app> <url> requires a valid URL target`);let e=i?.appBundleId??await w(t);await M().openBundle(e,a);return}let o=t.trim();if(r(o)){await M().openTarget(o);return}let s=i?.appBundleId??await w(o);await M().openBundle(s)}async function E(e,t){let r=await w(t),i=await g(r);if(i.running){if(!i.terminated&&!i.forceTerminated)throw new n(`COMMAND_FAILED`,`Failed to close macOS app ${t}`,{bundleId:r,running:i.running,terminated:i.terminated,forceTerminated:i.forceTerminated});for(let e=1;e<20;e+=1)if(await v(100),!(await g(r)).running)return;throw new n(`COMMAND_FAILED`,`Timed out waiting for macOS app ${t} to close`,{reason:`MACOS_APP_TERMINATION_TIMEOUT`,bundleId:r,attempts:20})}}async function D(){return await M().readClipboard()}async function O(e){await M().writeClipboard(e)}async function k(){return await M().readDarkMode()}async function A(e){let t=o(e),n=t===`toggle`?!await k():t===`dark`;await M().setDarkMode(n)}async function j(e){return await M().listApps(e)}function M(){let e=f().macosHost;if(!e)throw new n(`UNSUPPORTED_OPERATION`,`macOS host provider is not available`);return e}function N(e){return new n(`APP_NOT_INSTALLED`,`No app found matching "${e}"`)}var P=e({buildAppNotInstalledError:()=>N,detectSoleRunningIosSimulatorApp:()=>W,findIosSimulatorInstalledApp:()=>B,invalidateIosAppResolutionCache:()=>R,listIosApps:()=>Y,resolveIosApp:()=>z,resolveIosAppAlias:()=>V,resolveIosSimulatorDeepLinkBundleId:()=>K});const F={settings:`com.apple.Preferences`},I=u();function L(e){return{platform:`ios`,deviceId:e.id,variant:e.kind}}async function R(e,t){return await I.invalidateWhile(L(e),t)}async function z(e,t){if(i(e))return await w(t);let r=t.trim();if(r.includes(`.`))return r;let a=V(r);if(a!==r)return a;let o=L(e),s=I.get(o,r);if(s)return s;let c=(e.kind===`simulator`?await X(e):await m(e).listApps(e,`all`)).filter(e=>e.name.toLowerCase()===r.toLowerCase()),l=c[0];if(l!==void 0&&c.length===1)return I.set(o,r,l.bundleId);throw c.length>1?new n(`INVALID_ARGS`,`Multiple apps matched "${t}"`,{matches:c}):N(t)}async function B(e,t){if(!a(e)||e.kind!==`simulator`||e.booted!==!0)return;let n=V(t.trim());if(!n)return;let r=await X(e);if(n.includes(`.`))return r.find(e=>e.bundleId===n)?.bundleId;let i=r.filter(e=>e.name.toLowerCase()===n.toLowerCase());return i.length===1?i[0]?.bundleId:void 0}function V(e){let t=e.trim();return F[t.toLowerCase()]??e}const H=3e3,U=/UIKitApplication:([^[\s]+)\[/;async function W(e){if(!(!a(e)||e.kind!==`simulator`||e.booted!==!0))try{let[t,n]=await Promise.all([G(e),X(e,{timeoutMs:H})]);if(t.length===0)return;let r=new Map(n.map(e=>[e.bundleId,e])),i=new Map;for(let e of t){let t=r.get(e);t&&i.set(t.bundleId,t)}return i.size===1?[...i.values()][0]:void 0}catch{return}}async function G(e){let t=await h(e,[`spawn`,e.id,`launchctl`,`list`],{allowFailure:!0,timeoutMs:H});if(t.exitCode!==0)return[];let n=[];for(let e of t.stdout.split(`
2
- `)){let t=U.exec(e);t?.[1]&&n.push(t[1])}return n}async function K(e,t,n={}){if(!a(e)||e.kind!==`simulator`)return;let r=J(t);if(!r)return;let i=q(n),o=await Z(e,i()),s=[];for(let e of o)e.bundleId.startsWith(`com.callstack.agentdevice.runner`)||e.path&&(await ae(_.join(e.path,`Info.plist`),i())).has(r)&&s.push(e);let c=s.filter(e=>e.applicationType===`User`);if(c.length===1)return c[0]?.bundleId;if(!(c.length>1))return s.length===1?s[0]?.bundleId:void 0}function q({timeoutMs:e,signal:t}){let n=t?{signal:t}:{};if(e===void 0)return()=>n;let r=l.fromTimeoutMs(e);return()=>({timeoutMs:Math.max(1,r.remainingMs()),...n})}function J(e){return/^([A-Za-z][A-Za-z0-9+.-]*):/.exec(e.trim())?.[1]?.toLowerCase()}async function Y(e,t){if(i(e))return await j(t);if(e.kind===`simulator`){let n=await X(e);return p(n,t)}return await m(e).listApps(e,t)}async function X(e,t){return(await Z(e,t)).map(e=>({bundleId:e.bundleId,name:e.name}))}async function Z(e,t){let n=q(t??{}),r=(await h(e,[`listapps`,e.id],{allowFailure:!0,...n()})).stdout.trim();if(!r.startsWith(`{`))return[];let i=ne(r)??await re(r,n());return i?Object.entries(i).map(([e,t])=>{let n=ie(t);return{bundleId:e,name:t.CFBundleDisplayName??t.CFBundleName??e,...n?{path:n}:{},...t.ApplicationType?{applicationType:t.ApplicationType}:{}}}):[]}function ne(e){try{return JSON.parse(e)}catch{return null}}async function re(e,n){try{let t=await d(`plutil`,[`-convert`,`json`,`-o`,`-`,`-`],{allowFailure:!0,stdin:e,...n});return t.exitCode!==0||!t.stdout.trim().startsWith(`{`)?null:JSON.parse(t.stdout)}catch(e){if(s(e)||t(e))throw e;return null}}function ie(e){if(e.Path)return e.Path;if(e.Bundle)try{return te(e.Bundle)}catch{return}}const Q=c({ttlMs:18e5,scheduleExpiry:!0});async function ae(e,t){let n;try{n=`${e}:${(await ee(e)).mtimeMs}`}catch{n=void 0}if(n===void 0)return await $(e,t)??new Set;let r=Q.get(n);if(r)return r;let i=await $(e,t);return i&&Q.set(n,i),i??new Set}async function $(e,t){let n=await d(`plutil`,[`-convert`,`json`,`-o`,`-`,e],{allowFailure:!0,...t});if(n.exitCode===0)try{let e=JSON.parse(n.stdout),t=new Set;for(let n of e.CFBundleURLTypes??[])if(Array.isArray(n.CFBundleURLSchemes))for(let e of n.CFBundleURLSchemes)typeof e==`string`&&e.trim()&&t.add(e.trim().toLowerCase());return t}catch{return}}export{z as a,N as c,D as d,A as f,R as i,E as l,W as n,V as o,O as p,B as r,K as s,P as t,T as u};
1
+ import{r as e}from"./rolldown-runtime.js";import{P as t,q as n}from"./sdk-contracts.js";import{i as r}from"./sdk-batch-runner.js";import{g as i,h as a}from"./sdk-device.js";import{v as o}from"./settings.js";import{i as s}from"./exec.js";import{t as c}from"./retry.js";import"./command.js";import{o as l}from"./version.js";import"./retry2.js";import{t as u}from"./app-resolution-cache.js";import{u as ee}from"./host-file.js";import{a as d,i as te,l as f}from"./tool-provider.js";import{t as p}from"./physical-device-control.js";import{o as m,r as ne}from"./simctl.js";import{r as h}from"./helper.js";import g from"node:path";import{fileURLToPath as _}from"node:url";import{setTimeout as re}from"node:timers/promises";const ie={settings:`com.apple.systempreferences`},ae=/^[a-z0-9-]+(?:\.[a-z0-9-]+)+$/,v={platform:`macos`,deviceId:`host`,variant:`all`},y=u();function b(e){return ae.test(e)}async function x(e){let n=e.trim(),r=ie[n.toLowerCase()];if(r)return r;if(b(n))return n;let i=y.get(v,n);if(i)return i;let a=(await O(`all`)).filter(e=>e.name.toLowerCase()===n.toLowerCase()),o=a[0];if(o!==void 0&&a.length===1)return y.set(v,n,o.bundleId);throw a.length>1?new t(`INVALID_ARGS`,`Multiple apps matched "${e}"`,{matches:a}):new t(`APP_NOT_INSTALLED`,`No app found matching "${e}"`)}async function S(e,n,i){let a=i?.url?.trim();if(a){if(!r(a))throw new t(`INVALID_ARGS`,`open <app> <url> requires a valid URL target`);let e=i?.appBundleId??await x(n);await k().openBundle(e,a);return}let o=n.trim();if(r(o)){await k().openTarget(o);return}let s=i?.appBundleId??await x(o);await k().openBundle(s)}async function C(e,n){let r=await x(n),i=await h(r);if(i.running){if(!i.terminated&&!i.forceTerminated)throw new t(`COMMAND_FAILED`,`Failed to close macOS app ${n}`,{bundleId:r,running:i.running,terminated:i.terminated,forceTerminated:i.forceTerminated});for(let e=1;e<20;e+=1)if(await re(100),!(await h(r)).running)return;throw new t(`COMMAND_FAILED`,`Timed out waiting for macOS app ${n} to close`,{reason:`MACOS_APP_TERMINATION_TIMEOUT`,bundleId:r,attempts:20})}}async function w(){return await k().readClipboard()}async function T(e){await k().writeClipboard(e)}async function E(){return await k().readDarkMode()}async function D(e){let t=o(e),n=t===`toggle`?!await E():t===`dark`;await k().setDarkMode(n)}async function O(e){return await k().listApps(e)}function k(){let e=te().macosHost;if(!e)throw new t(`UNSUPPORTED_OPERATION`,`macOS host provider is not available`);return e}function A(e){return new t(`APP_NOT_INSTALLED`,`No app found matching "${e}"`)}var j=e({buildAppNotInstalledError:()=>A,detectSoleRunningIosSimulatorApp:()=>H,findIosSimulatorInstalledApp:()=>L,invalidateIosAppResolutionCache:()=>P,listIosApps:()=>ce,resolveIosApp:()=>F,resolveIosAppAlias:()=>z,resolveIosSimulatorDeepLinkBundleId:()=>W,resolveIosSimulatorExpoDevClientScheme:()=>G});const oe={settings:`com.apple.Preferences`},M=u();function N(e){return{platform:`ios`,deviceId:e.id,variant:e.kind}}async function P(e,t){return await M.invalidateWhile(N(e),t)}async function F(e,t,n={}){if(i(e))return await x(t);let r=t.trim(),a=z(r),o=N(e);if(!n.installedOnly){if(r.includes(`.`))return r;if(a!==r)return a;let e=M.get(o,r);if(e)return e}let s=e.kind===`simulator`?await le(e):await p(e).listApps(e,`all`);return M.set(o,r,I(s,t,r,a))}function I(e,n,r,i){let a=i!==r;if((a||r.includes(`.`))&&e.some(e=>e.bundleId===i))return i;if(a)throw A(n);let o=e.filter(e=>e.name.toLowerCase()===r.toLowerCase()),s=o[0];if(s!==void 0&&o.length===1)return s.bundleId;throw o.length>1?new t(`INVALID_ARGS`,`Multiple apps matched "${n}"`,{matches:o}):A(n)}async function L(e,t){if(!(!a(e)||e.kind!==`simulator`||e.booted!==!0)&&t.trim())try{return await F(e,t,{installedOnly:!0})}catch(e){if(R(e))return;throw e}}function R(e){return e instanceof t?e.code===`APP_NOT_INSTALLED`||e.details?.reason===J||Array.isArray(e.details?.matches):!1}function z(e){let t=e.trim();return oe[t.toLowerCase()]??e}const B=3e3,V=/UIKitApplication:([^[\s]+)\[/;async function H(e){if(!(!a(e)||e.kind!==`simulator`||e.booted!==!0))try{let[t,n]=await Promise.all([U(e),q(e,{timeoutMs:B})]);if(t.length===0)return;let r=new Map(n.map(e=>[e.bundleId,e])),i=new Map;for(let e of t){let t=r.get(e);t&&i.set(t.bundleId,t)}return i.size===1?[...i.values()][0]:void 0}catch{return}}async function U(e){let t=await m(e,[`spawn`,e.id,`launchctl`,`list`],{allowFailure:!0,timeoutMs:B});if(t.exitCode!==0)return[];let n=[];for(let e of t.stdout.split(`
2
+ `)){let t=V.exec(e);t?.[1]&&n.push(t[1])}return n}async function W(e,t,n={}){if(!a(e)||e.kind!==`simulator`)return;let r=se(t);if(!r)return;let i=K(n),o=await Y(e,i()),s=[];for(let e of o)e.bundleId.startsWith(`com.callstack.agentdevice.runner`)||e.path&&(await Q(g.join(e.path,`Info.plist`),i())).has(r)&&s.push(e);let c=s.filter(e=>e.applicationType===`User`);if(c.length===1)return c[0]?.bundleId;if(!(c.length>1))return s.length===1?s[0]?.bundleId:void 0}async function G(e,t,n={}){if(!a(e)||e.kind!==`simulator`)return;let r=K(n),i=await m(e,[`get_app_container`,e.id,t,`app`],{allowFailure:!0,...r()}),o=ne(String(i.stdout));if(i.exitCode!==0||!o)return;let s=[...await Q(g.join(o,`Info.plist`),r())].filter(e=>e.startsWith(`exp+`)&&e.length>4);if(s.length!==1)return;let c=s[0];return await W(e,`${c}://`,r())===t?c:void 0}function K({timeoutMs:e,signal:t}){let n=t?{signal:t}:{};if(e===void 0)return()=>n;let r=c.fromTimeoutMs(e);return()=>({timeoutMs:Math.max(1,r.remainingMs()),...n})}function se(e){return/^([A-Za-z][A-Za-z0-9+.-]*):/.exec(e.trim())?.[1]?.toLowerCase()}async function ce(e,t){if(i(e))return await O(t);if(e.kind===`simulator`){let n=await q(e);return f(n,t)}return await p(e).listApps(e,t)}async function q(e,t){return(await Y(e,t)).map(e=>({bundleId:e.bundleId,name:e.name}))}const J=`app-list-unreadable`;async function le(e){let n=await X(e);if(n.type===`unreadable`)throw new t(`COMMAND_FAILED`,`Could not list the apps installed on ${e.id}`,{reason:J,deviceId:e.id,exitCode:n.exitCode,stderr:n.stderr,hint:"Check that the simulator is booted and that `xcrun simctl listapps <udid>` answers, then retry."});return n.apps.map(e=>({bundleId:e.bundleId,name:e.name}))}async function Y(e,t){let n=await X(e,t);return n.type===`listed`?n.apps:[]}async function X(e,t){let n=K(t??{}),r=await m(e,[`listapps`,e.id],{allowFailure:!0,...n()}),i={type:`unreadable`,exitCode:r.exitCode,stderr:String(r.stderr??``)},a=r.stdout.trim();if(!a.startsWith(`{`))return i;let o=ue(a)??await de(a,n());return o?{type:`listed`,apps:Object.entries(o).map(([e,t])=>{let n=fe(t);return{bundleId:e,name:t.CFBundleDisplayName??t.CFBundleName??e,...n?{path:n}:{},...t.ApplicationType?{applicationType:t.ApplicationType}:{}}})}:i}function ue(e){try{return JSON.parse(e)}catch{return null}}async function de(e,t){try{let n=await d(`plutil`,[`-convert`,`json`,`-o`,`-`,`-`],{allowFailure:!0,stdin:e,...t});return n.exitCode!==0||!n.stdout.trim().startsWith(`{`)?null:JSON.parse(n.stdout)}catch(e){if(s(e)||n(e))throw e;return null}}function fe(e){if(e.Path)return e.Path;if(e.Bundle)try{return _(e.Bundle)}catch{return}}const Z=l({ttlMs:18e5,scheduleExpiry:!0});async function Q(e,t){let n;try{n=`${e}:${(await ee(e)).mtimeMs}`}catch{n=void 0}if(n===void 0)return await $(e,t)??new Set;let r=Z.get(n);if(r)return r;let i=await $(e,t);return i&&Z.set(n,i),i??new Set}async function $(e,t){let n=await d(`plutil`,[`-convert`,`json`,`-o`,`-`,e],{allowFailure:!0,...t});if(n.exitCode===0)try{let e=JSON.parse(n.stdout),t=new Set;for(let n of e.CFBundleURLTypes??[])if(Array.isArray(n.CFBundleURLSchemes))for(let e of n.CFBundleURLSchemes)typeof e==`string`&&e.trim()&&t.add(e.trim().toLowerCase());return t}catch{return}}export{F as a,G as c,S as d,w as f,P as i,A as l,T as m,H as n,z as o,D as p,L as r,W as s,j as t,C as u};
@@ -0,0 +1,15 @@
1
+ import { E as AppleApplicationState } from "./sdk-contracts.js";
2
+ //#region packages/contracts/src/app-state-runtime.d.ts
3
+ /** Neutral foreground identity returned by a selected platform/provider runtime. */
4
+ type AppStateRuntimeResult = Readonly<{
5
+ package?: string;
6
+ activity?: string;
7
+ /**
8
+ * Apple: how the app named by the input is running, as a live runner reads it. It says nothing
9
+ * about which app is frontmost; a session app in a background state has left the foreground.
10
+ * Absent when no runner session is live to ask, so the read never starts one.
11
+ */
12
+ applicationState?: AppleApplicationState;
13
+ }>;
14
+ //#endregion
15
+ export { AppStateRuntimeResult as t };
@@ -1 +1 @@
1
- import{P as e}from"./sdk-contracts.js";import{O as t,T as n,d as r,m as i}from"./sdk-device.js";import{E as a}from"./host.js";const o=3e4,s={iOS:{sdkName:{simulator:`iphonesimulator`,device:`iphoneos`},derivedBaseName:{simulator:`ios-simulator`,device:`ios-device`},xctestrunHints:{simulator:{preferred:[`iphonesimulator`],disallowed:[`iphoneos`,`appletvos`,`appletvsimulator`,`macos`]},device:{preferred:[`iphoneos`],disallowed:[`iphonesimulator`,`appletvos`,`appletvsimulator`,`macos`]}}},tvOS:{sdkName:{simulator:`appletvsimulator`,device:`appletvos`},derivedBaseName:{simulator:`tvos-simulator`,device:`tvos-device`},xctestrunHints:{simulator:{preferred:[`appletvsimulator`],disallowed:[`appletvos`,`iphoneos`,`iphonesimulator`,`macos`]},device:{preferred:[`appletvos`],disallowed:[`appletvsimulator`,`iphoneos`,`iphonesimulator`,`macos`]}}},macOS:{sdkName:{simulator:`macosx`,device:`macosx`},derivedBaseName:{simulator:`macos`,device:`macos`},xctestrunHints:{simulator:{preferred:[`macos`],disallowed:[`iphoneos`,`iphonesimulator`,`appletvos`,`appletvsimulator`]},device:{preferred:[`macos`],disallowed:[`iphoneos`,`iphonesimulator`,`appletvos`,`appletvsimulator`]}}},visionOS:{sdkName:{simulator:`xrsimulator`,device:`xros`},derivedBaseName:{simulator:`visionos-simulator`,device:`visionos-device`},xctestrunHints:{simulator:{preferred:[`xrsimulator`],disallowed:[`xros`,`iphoneos`,`iphonesimulator`,`appletvos`,`appletvsimulator`,`macos`]},device:{preferred:[`xros`],disallowed:[`xrsimulator`,`iphoneos`,`iphonesimulator`,`appletvos`,`appletvsimulator`,`macos`]}}}},c=[`ios`,`macos`,`tvos`,`visionos`];function l(e){return c.includes(e)}const u={ios:`mobile`,macos:`desktop`,tvos:`tv`,visionos:`mobile`},d={ios:`ios`,macos:`macos`,tvos:`tvos`,visionos:`visionos`};function f(e,t){return{platform:`apple`,id:`runner-script-${e}`,name:`Apple runner build script (${e})`,kind:e===`macos`?`device`:p(t),target:u[e],appleOs:d[e]}}function p(t){let n=m(t);if(n===void 0)throw new e(`INVALID_ARGS`,`The Apple runner build destination must name its platform`,{destination:t,hint:`Pass a destination with a platform= token, e.g. generic/platform=iOS Simulator for a simulator or generic/platform=iOS for a physical device.`});return n.toLowerCase().endsWith(`simulator`)?`simulator`:`device`}function m(e){for(let t of e.split(`,`)){let e=t.indexOf(`=`);if(!(e<0)&&t.slice(0,e).trim().toLowerCase().replace(/^generic\//,``)===`platform`)return t.slice(e+1).trim()||void 0}}function h(t){if(!r(t.platform))throw new e(`UNSUPPORTED_PLATFORM`,`Unsupported platform for Apple runner: ${t.platform}`);return i(t)?`macOS`:n(t.target,t.appleOs)}function g(e){if(!r(e.platform))return{handoff:!1,reason:`non_apple_target`};if(e.kind===`simulator`)return{handoff:!0,lane:`simulator`};if(i(e))return{handoff:!1,reason:`macos_host`};let n=t(e);return n!==`ios`&&n!==`ipados`?{handoff:!1,reason:`physical_non_ios_os`}:e.iosPhysicalDeviceBackend===`xctest`?{handoff:!1,reason:`xctest_backend`}:{handoff:!0,lane:`physical_coredevice`}}function _(e,t){return s[e].sdkName[C(t)]}function v(e){return s[h(e)].derivedBaseName[C(e.kind)]}function y(e){return s[h(e)].xctestrunHints[C(e.kind)]}function b(e){let t=h(e);return t===`macOS`?`platform=macOS,arch=${w()}`:e.kind===`simulator`?`platform=${t} Simulator,id=${e.id}`:`platform=${t},id=${e.id}`}function x(e){let t=h(e);return t===`macOS`?`platform=macOS,arch=${w()}`:e.kind===`simulator`?`platform=${t} Simulator,id=${e.id}`:`generic/platform=${t}`}function S(e){let t=h(e);return t===`macOS`?`platform=macOS,arch=${w()}`:e.kind===`simulator`?`generic/platform=${t} Simulator`:`generic/platform=${t}`}function C(e){return e===`simulator`?`simulator`:`device`}function w(){return a()===`arm64`?`arm64`:`x86_64`}export{v as a,h as c,y as d,S as i,f as l,l as n,b as o,x as r,g as s,o as t,_ as u};
1
+ import{P as e}from"./sdk-contracts.js";import{A as t,D as n,f as r,g as i}from"./sdk-device.js";let a;function ee(e){if(a&&a!==e)throw Error(`Apple runner host is already bound to a different implementation.`);a=e}function o(){if(!a)throw Error(`Apple runner host is not bound. Production binds it in core/runner-client.ts; package tests bind it through runner/test-host.ts.`);return a}function s(e){return((...t)=>o()[e](...t))}const te=s(`runCmdStreaming`),ne=s(`runCmdSync`),re=s(`runCmdBackground`),c=s(`requireExecSuccess`),l=s(`isCommandTimeoutError`),u=s(`commandDeveloperDir`),d=s(`shellQuote`),f=s(`emitDiagnostic`),p=s(`withDiagnosticTimer`),m=s(`retryWithPolicy`),h=s(`isEnvTruthy`),g=s(`isProcessAlive`),_=s(`isProcessGroupAlive`),v=s(`readProcessStartTime`),y=s(`readProcessCommand`),b=s(`signalPidsBestEffort`),x=s(`signalProcessGroupBestEffort`),S=s(`classifyOwnerLiveness`),C=s(`readHostCpuArchSync`),w=s(`findProjectRoot`),T=s(`readVersion`),E=s(`acquireProcessLock`),D=s(`withProcessLock`),O=s(`publishFileSync`),k=s(`emitRequestProgress`),A=s(`getRequestSignal`),j=s(`isRequestCanceled`),M=s(`withKeyedLock`),N=s(`createTtlMemo`),P=s(`isRecord`),F=s(`parseBooleanLiteral`),ie=s(`classifyBootFailure`),I=s(`bootFailureHint`),L=s(`runAppleToolCommand`),R=s(`runXcrun`),z=s(`readApplePlistJson`),B=s(`hasScopedAppleToolProvider`),V=s(`buildSimctlArgsForDevice`),H=s(`simulatorAddressFor`),U=s(`visitXmlPlistEntries`),W=s(`resolveIosPhysicalDeviceControl`),G=s(`leaseOwnerStateDir`),K=s(`hasDeviceClaimAuthority`),q={fromTimeoutMs:s(`deadlineFromTimeoutMs`)},J=3e4,Y={iOS:{sdkName:{simulator:`iphonesimulator`,device:`iphoneos`},derivedBaseName:{simulator:`ios-simulator`,device:`ios-device`},xctestrunHints:{simulator:{preferred:[`iphonesimulator`],disallowed:[`iphoneos`,`appletvos`,`appletvsimulator`,`macos`]},device:{preferred:[`iphoneos`],disallowed:[`iphonesimulator`,`appletvos`,`appletvsimulator`,`macos`]}}},tvOS:{sdkName:{simulator:`appletvsimulator`,device:`appletvos`},derivedBaseName:{simulator:`tvos-simulator`,device:`tvos-device`},xctestrunHints:{simulator:{preferred:[`appletvsimulator`],disallowed:[`appletvos`,`iphoneos`,`iphonesimulator`,`macos`]},device:{preferred:[`appletvos`],disallowed:[`appletvsimulator`,`iphoneos`,`iphonesimulator`,`macos`]}}},macOS:{sdkName:{simulator:`macosx`,device:`macosx`},derivedBaseName:{simulator:`macos`,device:`macos`},xctestrunHints:{simulator:{preferred:[`macos`],disallowed:[`iphoneos`,`iphonesimulator`,`appletvos`,`appletvsimulator`]},device:{preferred:[`macos`],disallowed:[`iphoneos`,`iphonesimulator`,`appletvos`,`appletvsimulator`]}}},visionOS:{sdkName:{simulator:`xrsimulator`,device:`xros`},derivedBaseName:{simulator:`visionos-simulator`,device:`visionos-device`},xctestrunHints:{simulator:{preferred:[`xrsimulator`],disallowed:[`xros`,`iphoneos`,`iphonesimulator`,`appletvos`,`appletvsimulator`,`macos`]},device:{preferred:[`xros`],disallowed:[`xrsimulator`,`iphoneos`,`iphonesimulator`,`appletvos`,`appletvsimulator`,`macos`]}}}},ae=[`ios`,`macos`,`tvos`,`visionos`];function oe(e){return ae.includes(e)}const se={ios:`mobile`,macos:`desktop`,tvos:`tv`,visionos:`mobile`},ce={ios:`ios`,macos:`macos`,tvos:`tvos`,visionos:`visionos`};function le(e,t){return{platform:`apple`,id:`runner-script-${e}`,name:`Apple runner build script (${e})`,kind:e===`macos`?`device`:ue(t),target:se[e],appleOs:ce[e]}}function ue(t){let n=de(t);if(n===void 0)throw new e(`INVALID_ARGS`,`The Apple runner build destination must name its platform`,{destination:t,hint:`Pass a destination with a platform= token, e.g. generic/platform=iOS Simulator for a simulator or generic/platform=iOS for a physical device.`});return n.toLowerCase().endsWith(`simulator`)?`simulator`:`device`}function de(e){for(let t of e.split(`,`)){let e=t.indexOf(`=`);if(!(e<0)&&t.slice(0,e).trim().toLowerCase().replace(/^generic\//,``)===`platform`)return t.slice(e+1).trim()||void 0}}function X(t){if(!r(t.platform))throw new e(`UNSUPPORTED_PLATFORM`,`Unsupported platform for Apple runner: ${t.platform}`);return i(t)?`macOS`:n(t.target,t.appleOs)}function fe(e){if(!r(e.platform))return{handoff:!1,reason:`non_apple_target`};if(e.kind===`simulator`)return{handoff:!0,lane:`simulator`};if(i(e))return{handoff:!1,reason:`macos_host`};let n=t(e);return n!==`ios`&&n!==`ipados`?{handoff:!1,reason:`physical_non_ios_os`}:e.iosPhysicalDeviceBackend===`xctest`?{handoff:!1,reason:`xctest_backend`}:{handoff:!0,lane:`physical_coredevice`}}function pe(e,t){return Y[e].sdkName[Q(t)]}function me(e){return Y[X(e)].derivedBaseName[Q(e.kind)]}function he(e){return Y[X(e)].xctestrunHints[Q(e.kind)]}function Z(e){let t=X(e);return t===`macOS`?`platform=macOS,arch=${$()}`:e.kind===`simulator`?`platform=${t} Simulator,id=${e.id}`:`platform=${t},id=${e.id}`}function ge(e){let t=X(e);return t===`macOS`?`platform=macOS,arch=${$()}`:e.kind===`simulator`?`platform=${t} Simulator,id=${e.id}`:`generic/platform=${t}`}function _e(e){let t=X(e);return t===`macOS`?`platform=macOS,arch=${$()}`:e.kind===`simulator`?`generic/platform=${t} Simulator`:`generic/platform=${t}`}function Q(e){return e===`simulator`?`simulator`:`device`}function $(){return C()===`arm64`?`arm64`:`x86_64`}export{p as $,_ as A,c as B,w as C,l as D,B as E,O as F,te as G,m as H,z as I,d as J,ne as K,y as L,j as M,G as N,h as O,F as P,U as Q,v as R,k as S,K as T,L as U,W as V,re as W,x as X,b as Y,H as Z,ie as _,me as a,N as b,X as c,he as d,M as et,q as f,V as g,I as h,_e as i,P as j,g as k,le as l,ee as m,oe as n,Z as o,E as p,R as q,ge as r,fe as s,J as t,D as tt,pe as u,S as v,A as w,f as x,u as y,T as z};
@@ -1 +1 @@
1
- import{P as e}from"./sdk-contracts.js";import{i as t}from"./sdk-batch-runner.js";import{p as n}from"./sdk-device.js";import{n as r,t as i}from"./launch-console.js";function a(e,t,n){return{requestId:e.requestId,signal:n,appBundleId:t,verbose:e.verbose,logPath:e.logPath,traceLogPath:e.traceLogPath,iosXctestrunFile:e.iosXctestrunFile,iosXctestDerivedDataPath:e.iosXctestDerivedDataPath,iosXctestEnvDir:e.iosXctestEnvDir,runnerLeaseContext:e.runnerLeaseContext}}function o(t){let{device:n,signal:r,ownership:i}=t;return Object.freeze({device:n,signal:r,resolveInteractor:async(o,s)=>{let c=a(o,s,r);if(i===`local`)return await t.resolveLocalInteractor(n,c);let l=i.resolveInteractor(c);if(l)return l;throw new e(`UNSUPPORTED_OPERATION`,`Provider-owned application lifecycle operation has no bound provider interactor.`,{reason:`provider-runtime-interactor-missing`,deviceId:n.id})}})}function s(e){return o({device:e.device,signal:e.signal,resolveLocalInteractor:e.resolveInteractor,ownership:`local`})}function c(e){return o({device:e.device,signal:e.signal,ownership:{kind:`provider`,resolveInteractor:e.resolveInteractor}})}async function l(e){let{device:t,positionals:n,execution:r}=e;u(n);let i=n[0],a=n[1];if(!i){await d(e);return}if(f(t,r),a!==void 0){await p(e,i,a);return}await m(e,i)}function u(t){if(t.length>2)throw new e(`INVALID_ARGS`,`open accepts at most two arguments: <app|url> [url]`)}async function d(t){if(t.execution.launchConsole)throw new e(`INVALID_ARGS`,`--launch-console requires an app target`);if(t.execution.launchArgs&&t.execution.launchArgs.length>0)throw new e(`INVALID_ARGS`,`--launch-args requires an app target`);await t.interactor.openDevice()}function f(t,i){if(i.launchConsole&&(!n(t)||t.kind!==`simulator`))throw new e(`UNSUPPORTED_OPERATION`,r);if(t.platform===`linux`&&i.launchArgs&&i.launchArgs.length>0)throw new e(`UNSUPPORTED_OPERATION`,`--launch-args is not supported on Linux.`)}async function p(n,r,a){if(t(r))throw new e(`INVALID_ARGS`,`open <app> <url> requires an app target as the first argument`);if(!t(a))throw new e(`INVALID_ARGS`,`open <app> <url> requires a valid URL target`);if(n.execution.launchConsole)throw new e(`INVALID_ARGS`,i);await n.interactor.open(r,{activity:n.execution.activity,appBundleId:n.appBundleId,launchArgs:n.execution.launchArgs?[...n.execution.launchArgs]:void 0,terminateRunningApp:n.terminateRunningApp,url:a})}async function m(n,r){let{execution:a,interactor:o}=n;if(a.launchConsole&&t(r))throw new e(`INVALID_ARGS`,i);if(a.clearAppState){if(t(r))throw new e(`INVALID_ARGS`,`Clearing app state requires an app target, not a deep link.`);await o.setSetting(`clear-app-state`,`clear`,r)}await o.open(r,{activity:a.activity,appBundleId:n.appBundleId,launchConsole:a.launchConsole,launchArgs:a.launchArgs?[...a.launchArgs]:void 0,terminateRunningApp:n.terminateRunningApp})}function h(t){let{binding:n}=t,r=async()=>{throw new e(`UNSUPPORTED_OPERATION`,`This lifecycle operation is unavailable for ${t.owner}.`)};return Object.freeze({resolveOpenTarget:async e=>v(t.openTargetIdentity,e),prepareApplicationOpen:async()=>void 0,openApplication:async e=>await g(t,e),applyRuntimeHints:r,clearRuntimeHints:r,closeApplication:async e=>{await y({device:n.device,interactor:await n.resolveInteractor(e.execution,e.appBundleId),positionals:e.positionals})},finalizeApplicationClose:async()=>({}),prepareAppleRunner:r,configureProviderPortReverse:t.configureProviderPortReverse??r})}async function g(e,t){let{binding:n}=e,r=await n.resolveInteractor(t.execution,t.appBundleId);e.closeBeforeRelaunch&&t.relaunch&&t.target!==void 0&&await y({device:n.device,interactor:r,positionals:[t.appBundleId??t.target]}),await l({device:n.device,interactor:r,positionals:t.positionals,appBundleId:t.appBundleId,execution:t.execution});let i=_(t);return i&&await l({device:n.device,interactor:r,positionals:[i],appBundleId:t.appBundleId,execution:{...t.execution,clearAppState:void 0,launchConsole:void 0,launchArgs:void 0}}),{appBundleId:t.appBundleId,timing:{}}}function _(e){let n=e.runtimeLaunchUrl?.trim(),r=e.positionals.length===1?e.positionals[0]?.trim():void 0;if(!(!n||!r||t(r)))return n}function v(e,n){let r=n.target;if(e===`app-name`)return Object.freeze(r===void 0?{}:{appName:r});let i=r?.trim(),a=i&&i.includes(`.`)&&!t(i)?i:n.currentAppBundleId;return Object.freeze({...a===void 0?{}:{appBundleId:a},...r===void 0?{}:{appName:r}})}async function y(e){let{device:t,interactor:n,positionals:r}=e,i=r[0];if(!i){t.platform===`web`&&await n.close(``);return}await n.close(i)}export{y as a,_ as i,s as n,l as o,c as r,h as t};
1
+ import{P as e}from"./sdk-contracts.js";import{i as t}from"./sdk-batch-runner.js";import{h as n}from"./sdk-device.js";import{n as r,t as i}from"./launch-console.js";function a(e,t,n){return{requestId:e.requestId,signal:n,appBundleId:t,verbose:e.verbose,logPath:e.logPath,traceLogPath:e.traceLogPath,iosXctestrunFile:e.iosXctestrunFile,iosXctestDerivedDataPath:e.iosXctestDerivedDataPath,iosXctestEnvDir:e.iosXctestEnvDir,runnerLeaseContext:e.runnerLeaseContext}}function o(t){let{device:n,signal:r,ownership:i}=t;return Object.freeze({device:n,signal:r,resolveInteractor:async(o,s)=>{let c=a(o,s,r);if(i===`local`)return await t.resolveLocalInteractor(n,c);let l=i.resolveInteractor(c);if(l)return l;throw new e(`UNSUPPORTED_OPERATION`,`Provider-owned application lifecycle operation has no bound provider interactor.`,{reason:`provider-runtime-interactor-missing`,deviceId:n.id})}})}function s(e){return o({device:e.device,signal:e.signal,resolveLocalInteractor:e.resolveInteractor,ownership:`local`})}function c(e){return o({device:e.device,signal:e.signal,ownership:{kind:`provider`,resolveInteractor:e.resolveInteractor}})}async function l(e){let{device:t,positionals:n,execution:r}=e;u(n);let i=n[0],a=n[1];if(!i){await d(e);return}if(f(t,r),a!==void 0){await p(e,i,a);return}await m(e,i)}function u(t){if(t.length>2)throw new e(`INVALID_ARGS`,`open accepts at most two arguments: <app|url> [url]`)}async function d(t){if(t.execution.launchConsole)throw new e(`INVALID_ARGS`,`--launch-console requires an app target`);if(t.execution.launchArgs&&t.execution.launchArgs.length>0)throw new e(`INVALID_ARGS`,`--launch-args requires an app target`);await t.interactor.openDevice()}function f(t,i){if(i.launchConsole&&(!n(t)||t.kind!==`simulator`))throw new e(`UNSUPPORTED_OPERATION`,r);if(t.platform===`linux`&&i.launchArgs&&i.launchArgs.length>0)throw new e(`UNSUPPORTED_OPERATION`,`--launch-args is not supported on Linux.`)}async function p(n,r,a){if(t(r))throw new e(`INVALID_ARGS`,`open <app> <url> requires an app target as the first argument`);if(!t(a))throw new e(`INVALID_ARGS`,`open <app> <url> requires a valid URL target`);if(n.execution.launchConsole)throw new e(`INVALID_ARGS`,i);await n.interactor.open(r,{activity:n.execution.activity,appBundleId:n.appBundleId,launchArgs:n.execution.launchArgs?[...n.execution.launchArgs]:void 0,terminateRunningApp:n.terminateRunningApp,url:a})}async function m(n,r){let{execution:a,interactor:o}=n;if(a.launchConsole&&t(r))throw new e(`INVALID_ARGS`,i);if(a.clearAppState){if(t(r))throw new e(`INVALID_ARGS`,`Clearing app state requires an app target, not a deep link.`);await o.setSetting(`clear-app-state`,`clear`,r)}await o.open(r,{activity:a.activity,appBundleId:n.appBundleId,launchConsole:a.launchConsole,launchArgs:a.launchArgs?[...a.launchArgs]:void 0,terminateRunningApp:n.terminateRunningApp})}function h(t){let{binding:n}=t,r=async()=>{throw new e(`UNSUPPORTED_OPERATION`,`This lifecycle operation is unavailable for ${t.owner}.`)};return Object.freeze({resolveOpenTarget:async e=>v(t.openTargetIdentity,e),prepareApplicationOpen:async()=>void 0,openApplication:async e=>await g(t,e),applyRuntimeHints:r,clearRuntimeHints:r,closeApplication:async e=>{await y({device:n.device,interactor:await n.resolveInteractor(e.execution,e.appBundleId),positionals:e.positionals})},finalizeApplicationClose:async()=>({}),prepareAppleRunner:r,configureProviderPortReverse:t.configureProviderPortReverse??r})}async function g(e,t){let{binding:n}=e,r=await n.resolveInteractor(t.execution,t.appBundleId);e.closeBeforeRelaunch&&t.relaunch&&t.target!==void 0&&await y({device:n.device,interactor:r,positionals:[t.appBundleId??t.target]}),await l({device:n.device,interactor:r,positionals:t.positionals,appBundleId:t.appBundleId,execution:t.execution});let i=_(t);return i&&await l({device:n.device,interactor:r,positionals:[i],appBundleId:t.appBundleId,execution:{...t.execution,clearAppState:void 0,launchConsole:void 0,launchArgs:void 0}}),{appBundleId:t.appBundleId,timing:{}}}function _(e){let n=e.runtimeLaunchUrl?.trim(),r=e.positionals.length===1?e.positionals[0]?.trim():void 0;if(!(!n||!r||t(r)))return n}function v(e,n){let r=n.target;if(e===`app-name`)return Object.freeze(r===void 0?{}:{appName:r});let i=r?.trim(),a=i&&i.includes(`.`)&&!t(i)?i:n.currentAppBundleId;return Object.freeze({...a===void 0?{}:{appBundleId:a},...r===void 0?{}:{appName:r}})}async function y(e){let{device:t,interactor:n,positionals:r}=e,i=r[0];if(!i){t.platform===`web`&&await n.close(``);return}await n.close(i)}function b(e){return h({owner:e.owner,openTargetIdentity:e.openTargetIdentity,binding:s({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}export{_ as a,c as i,s as n,y as o,b as r,l as s,h as t};
@@ -1 +1 @@
1
- import{P as e}from"./sdk-contracts.js";import{d as t,l as n}from"./daemon-http.js";import{n as r}from"./transport.js";import i from"node:fs";import a from"node:path";import{pipeline as o}from"node:stream/promises";function s(e){let{destinationPath:t}=e;return e.isDirectory?{prepare:async()=>{await i.promises.mkdir(t,{recursive:!0})},cleanupOnError:async()=>{},materialize:(e,n)=>l(e,t,n)}:{prepare:async()=>{await i.promises.mkdir(a.dirname(t),{recursive:!0})},cleanupOnError:()=>i.promises.rm(t,{force:!0}),materialize:async(e,n)=>(await o(e,i.createWriteStream(t),{signal:n}),t)}}async function c(i){let a=await r(i.artifactUrl.protocol),o=s(i);return await o.prepare(),await new Promise((r,s)=>{let c=!1,l=!1,u,d=new AbortController,f=i.timeoutMs??9e4,p=(e,t)=>{if(!c){if(c=!0,clearTimeout(h),t){o.cleanupOnError().finally(()=>s(t));return}r(e??i.destinationPath)}},m=a.request({protocol:i.artifactUrl.protocol,host:i.artifactUrl.hostname,port:i.artifactUrl.port,method:`GET`,path:i.artifactUrl.pathname+i.artifactUrl.search,headers:{...n(i.token),...t(i.requestScope?.tenantId)}},t=>{if((t.statusCode??500)>=400){let n=``;t.setEncoding(`utf8`),t.on(`data`,e=>{n+=e}),t.on(`end`,()=>{p(void 0,new e(`COMMAND_FAILED`,`Failed to download remote artifact`,{artifactId:i.artifactId,statusCode:t.statusCode,requestId:i.requestScope?.requestId,body:n}))});return}l=!0,o.materialize(t,d.signal).then(e=>p(e),e=>p(void 0,u??(e instanceof Error?e:Error(String(e)))))}),h=setTimeout(()=>{u=new e(`COMMAND_FAILED`,`Remote artifact download timed out`,{artifactId:i.artifactId,requestId:i.requestScope?.requestId,timeoutMs:f}),d.abort(u),m.destroy(u),l||p(void 0,u)},f);m.on(`error`,t=>{if(!l){if(t instanceof e){p(void 0,u??t);return}p(void 0,new e(`COMMAND_FAILED`,`Failed to download remote artifact`,{artifactId:i.artifactId,requestId:i.requestScope?.requestId,timeoutMs:f},t instanceof Error?t:void 0))}}),m.end()})}async function l(t,n,r){let s=await i.promises.mkdtemp(a.join(n,`.agent-device-download-`)),c=a.join(s,`artifact.tar.gz`),l=a.join(s,`extracted`);try{await o(t,i.createWriteStream(c),{signal:r});let{extractArchiveSafely:s}=await import(`./archive.js`).then(e=>e.t);await s({archivePath:c,outputRoot:l,type:`tgz`,signal:r}),r.throwIfAborted();let[u,...d]=await i.promises.readdir(l);if(!u||d.length>0)throw new e(`COMMAND_FAILED`,`Downloaded directory artifact has an unexpected shape: expected exactly one top-level entry, found ${d.length+ +!!u}`);r.throwIfAborted();let f=a.join(n,u);return await i.promises.rename(a.join(l,u),f),f}finally{await i.promises.rm(s,{recursive:!0,force:!0})}}export{c as downloadRemoteArtifactFromUrl};
1
+ import{P as e}from"./sdk-contracts.js";import{F as t,N as n,x as r}from"./daemon-resolution.js";import i from"node:fs";import a from"node:path";import{pipeline as o}from"node:stream/promises";function s(e){let{destinationPath:t}=e;return e.isDirectory?{prepare:async()=>{await i.promises.mkdir(t,{recursive:!0})},cleanupOnError:async()=>{},materialize:(e,n)=>l(e,t,n)}:{prepare:async()=>{await i.promises.mkdir(a.dirname(t),{recursive:!0})},cleanupOnError:()=>i.promises.rm(t,{force:!0}),materialize:async(e,n)=>(await o(e,i.createWriteStream(t),{signal:n}),t)}}async function c(i){let a=await r(i.artifactUrl.protocol),o=s(i);return await o.prepare(),await new Promise((r,s)=>{let c=!1,l=!1,u,d=new AbortController,f=i.timeoutMs??9e4,p=(e,t)=>{if(!c){if(c=!0,clearTimeout(h),t){o.cleanupOnError().finally(()=>s(t));return}r(e??i.destinationPath)}},m=a.request({protocol:i.artifactUrl.protocol,host:i.artifactUrl.hostname,port:i.artifactUrl.port,method:`GET`,path:i.artifactUrl.pathname+i.artifactUrl.search,headers:{...n(i.token),...t(i.requestScope?.tenantId)}},t=>{if((t.statusCode??500)>=400){let n=``;t.setEncoding(`utf8`),t.on(`data`,e=>{n+=e}),t.on(`end`,()=>{p(void 0,new e(`COMMAND_FAILED`,`Failed to download remote artifact`,{artifactId:i.artifactId,statusCode:t.statusCode,requestId:i.requestScope?.requestId,body:n}))});return}l=!0,o.materialize(t,d.signal).then(e=>p(e),e=>p(void 0,u??(e instanceof Error?e:Error(String(e)))))}),h=setTimeout(()=>{u=new e(`COMMAND_FAILED`,`Remote artifact download timed out`,{artifactId:i.artifactId,requestId:i.requestScope?.requestId,timeoutMs:f}),d.abort(u),m.destroy(u),l||p(void 0,u)},f);m.on(`error`,t=>{if(!l){if(t instanceof e){p(void 0,u??t);return}p(void 0,new e(`COMMAND_FAILED`,`Failed to download remote artifact`,{artifactId:i.artifactId,requestId:i.requestScope?.requestId,timeoutMs:f},t instanceof Error?t:void 0))}}),m.end()})}async function l(t,n,r){let s=await i.promises.mkdtemp(a.join(n,`.agent-device-download-`)),c=a.join(s,`artifact.tar.gz`),l=a.join(s,`extracted`);try{await o(t,i.createWriteStream(c),{signal:r});let{extractArchiveSafely:s}=await import(`./archive.js`).then(e=>e.t);await s({archivePath:c,outputRoot:l,type:`tgz`,signal:r}),r.throwIfAborted();let[u,...d]=await i.promises.readdir(l);if(!u||d.length>0)throw new e(`COMMAND_FAILED`,`Downloaded directory artifact has an unexpected shape: expected exactly one top-level entry, found ${d.length+ +!!u}`);r.throwIfAborted();let f=a.join(n,u);return await i.promises.rename(a.join(l,u),f),f}finally{await i.promises.rm(s,{recursive:!0,force:!0})}}export{c as downloadRemoteArtifactFromUrl};
package/dist/src/auth.js CHANGED
@@ -1,2 +1,2 @@
1
- import{P as e}from"./sdk-contracts.js";import{t}from"./daemon-resolution.js";import{a as n,n as r,t as i}from"./auth-session.js";import{t as a}from"./shared.js";const o=async({positionals:o,flags:c})=>{let l=o[0]??`status`,u=t(c.stateDir).baseDir;if(l===`status`){let e=n({stateDir:u});return await a(c,e,()=>s(e)),!0}if(l===`login`){let e=await i({stateDir:u,flags:c,commandLabel:`agent-device auth login`}),t={authenticated:!0,source:`cli-session`,sessionId:e.session.id,cloudBaseUrl:e.session.cloudBaseUrl,workspaceId:e.session.workspaceId,accountId:e.session.accountId,expiresAt:e.session.expiresAt,agentTokenExpiresAt:e.expiresAt};return await a(c,t,()=>`Authenticated with cloud CLI session.`),!0}if(l===`logout`){let e=r({stateDir:u});return await a(c,{authenticated:!1,removed:e},()=>e?`Removed stored cloud CLI session.`:`No stored cloud CLI session.`),!0}throw new e(`INVALID_ARGS`,`auth accepts only: status, login, logout`)};function s(e){return e.authenticated?[`Authenticated with cloud CLI session.`,`cloud=${e.cloudBaseUrl}`,`session=${e.sessionId}`,e.workspaceId?`workspace=${e.workspaceId}`:null,e.accountId?`account=${e.accountId}`:null,e.expiresAt?`expiresAt=${e.expiresAt}`:null,e.expired?`status=expired`:null].filter(e=>!!e).join(`
1
+ import{P as e}from"./sdk-contracts.js";import{t}from"./daemon-resolution.js";import{a as n,n as r,r as i}from"./cli.js";import{t as a}from"./shared.js";const o=async({positionals:o,flags:c})=>{let l=o[0]??`status`,u=t(c.stateDir).baseDir;if(l===`status`){let e=n({stateDir:u});return await a(c,e,()=>s(e)),!0}if(l===`login`){let e=await r({stateDir:u,flags:c,commandLabel:`agent-device auth login`}),t={authenticated:!0,source:`cli-session`,sessionId:e.session.id,cloudBaseUrl:e.session.cloudBaseUrl,workspaceId:e.session.workspaceId,accountId:e.session.accountId,expiresAt:e.session.expiresAt,agentTokenExpiresAt:e.expiresAt};return await a(c,t,()=>`Authenticated with cloud CLI session.`),!0}if(l===`logout`){let e=i({stateDir:u});return await a(c,{authenticated:!1,removed:e},()=>e?`Removed stored cloud CLI session.`:`No stored cloud CLI session.`),!0}throw new e(`INVALID_ARGS`,`auth accepts only: status, login, logout`)};function s(e){return e.authenticated?[`Authenticated with cloud CLI session.`,`cloud=${e.cloudBaseUrl}`,`session=${e.sessionId}`,e.workspaceId?`workspace=${e.workspaceId}`:null,e.accountId?`account=${e.accountId}`:null,e.expiresAt?`expiresAt=${e.expiresAt}`:null,e.expired?`status=expired`:null].filter(e=>!!e).join(`
2
2
  `):`Not authenticated.`}export{o as authCommand};
@@ -0,0 +1 @@
1
+ import{f as e}from"./runtime.js";import{c as t,d as n,f as r,u as i}from"./provider-webdriver.js";import{l as a}from"./store.js";import{i as o,n as s,r as c}from"./provider-profile-fields.js";import{t as l}from"./connection-verification.js";const u=a.awsDeviceFarm,d=`connect ${u}`;function f(a){let{env:f}=a;return{resolve:({flags:a})=>{s(a,t);let o=e(a,u),c=r(a.awsProjectArn,f,`awsProjectArn`,d);return{profile:{leaseProvider:u,platform:o,device:a.device,awsProjectArn:c,awsDeviceArn:r(a.awsDeviceArn,f,`awsDeviceArn`,d),awsAppArn:a.awsAppArn??n(f,`awsAppArn`),awsRegion:a.awsRegion??n(f,`awsRegion`)??i(c),awsInteractionMode:a.awsInteractionMode,providerSessionName:a.providerSessionName}}},verify:async({flags:e})=>await l({platform:c(e.platform,`AWS Device Farm`),projectArn:o(e.awsProjectArn,`AWS Device Farm profile missed project ARN.`),deviceArn:o(e.awsDeviceArn,`AWS Device Farm profile missed device ARN.`),appArn:e.awsAppArn,region:e.awsRegion},a.runHostCommand)}}export{f as createAwsDeviceFarmConnection};