agent-device 0.21.30 → 0.21.31
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.
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.30.apk → agent-device-android-ime-helper-0.21.31.apk} +0 -0
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.31.apk.sha256 +1 -0
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.30.manifest.json → agent-device-android-ime-helper-0.21.31.manifest.json} +4 -4
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.31.apk +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.31.apk.sha256 +1 -0
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.30.manifest.json → agent-device-android-snapshot-helper-0.21.31.manifest.json} +7 -7
- package/apple/macos-helper/Sources/AgentDeviceMacOSHelper/BackgroundInteraction.swift +20 -6
- package/apple/snapshot-bridge/README.md +16 -3
- package/apple/snapshot-bridge/SnapshotBridgeRuntime.m +33 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerApp.m +110 -8
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAppScreenCapture.swift +20 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.m +4 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AXSnapshotFallback.swift +1 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +30 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +14 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Navigation.swift +81 -41
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SequenceExecution.swift +40 -6
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotAcquisition.swift +5 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotCapturePlan.swift +74 -10
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotTiming.swift +33 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedCommitDeadline.swift +2 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedGesturePolicy.swift +23 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedInteraction.swift +158 -6
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntry.swift +165 -70
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryConfirmation.swift +2 -3
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryFocus.swift +49 -27
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryReadiness.swift +17 -9
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextInputProbe.swift +30 -28
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextTyping.swift +87 -87
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +4 -3
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerXCTestEventBridge.h +13 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerXCTestEventBridge.m +45 -0
- package/dist/src/absence-observation-errors.js +1 -1
- package/dist/src/adapter.js +1 -1
- package/dist/src/adb-executor.js +1 -1
- package/dist/src/adb-failure.js +2 -2
- package/dist/src/agent-browser-lifecycle.js +1 -1
- package/dist/src/agent-browser-process-record.js +1 -1
- package/dist/src/agent-browser-provider.js +1 -1
- package/dist/src/agent-browser-tool.js +1 -1
- package/dist/src/agent-device-client.js +1 -1
- package/dist/src/alert-tree-driver.js +1 -1
- package/dist/src/alert.js +1 -1
- package/dist/src/alert2.js +1 -1
- package/dist/src/android.js +1 -1
- package/dist/src/app-backend.js +1 -1
- package/dist/src/app-launch.js +1 -1
- package/dist/src/app-lifecycle.js +4 -4
- package/dist/src/app-log-runtime2.js +3 -3
- package/dist/src/app-log-session-resource.js +1 -1
- package/dist/src/app-resolution-facade.js +1 -1
- package/dist/src/app-resolution.js +2 -2
- package/dist/src/apple-runner-platform.js +1 -1
- package/dist/src/application-lifecycle-interaction.js +1 -1
- package/dist/src/artifact-tracking.js +1 -1
- package/dist/src/automation-helper-artifact.js +1 -1
- package/dist/src/automation-helper.js +1 -1
- package/dist/src/back-mode.js +1 -1
- package/dist/src/boot-diagnostics.js +1 -1
- package/dist/src/browser-launch.js +1 -1
- package/dist/src/cli-config.js +1 -1
- package/dist/src/cli-help.js +35 -29
- package/dist/src/cli-runner.js +1 -1
- package/dist/src/cli.js +3 -3
- package/dist/src/client-metro-companion.js +1 -1
- package/dist/src/client-metro.js +1 -1
- package/dist/src/client-types.d.ts +3 -3
- package/dist/src/cloud-artifacts.d.ts +5 -4
- package/dist/src/code-signature-cache.js +1 -1
- package/dist/src/command-metadata.js +10 -10
- package/dist/src/command-tools.js +2 -2
- package/dist/src/command.js +1 -1
- package/dist/src/composed-inventory-gateways.js +1 -1
- package/dist/src/connection-runtime.js +1 -1
- package/dist/src/connection.js +5 -5
- package/dist/src/contracts.js +1 -1
- package/dist/src/daemon-client-ensure.js +1 -1
- package/dist/src/daemon-client-lease-beat.js +1 -1
- package/dist/src/daemon-client-lifecycle.js +1 -1
- package/dist/src/daemon-client-liveness-probe.js +1 -1
- package/dist/src/daemon-client.js +1 -1
- package/dist/src/daemon-command-registry.js +1 -1
- package/dist/src/daemon-composition.js +1 -1
- package/dist/src/daemon-policy-file.js +1 -1
- package/dist/src/daemon-registration-owner.js +3 -3
- package/dist/src/daemon-resolution.js +1 -1
- package/dist/src/daemon-startup-diagnostics.js +1 -1
- package/dist/src/debug-symbols-facade.js +3 -3
- package/dist/src/device-claim-recovery.js +1 -1
- package/dist/src/device-claims.js +1 -1
- package/dist/src/device-inventory-context.js +1 -1
- package/dist/src/device-readiness-runtime.js +1 -1
- package/dist/src/device-selection-resolver.js +1 -1
- package/dist/src/device.js +1 -1
- package/dist/src/devicectl.js +1 -1
- package/dist/src/diagnostics.js +1 -1
- package/dist/src/display-inventory.js +1 -1
- package/dist/src/doctor-facade.js +1 -1
- package/dist/src/durable-capture-resource.js +1 -1
- package/dist/src/durable-resource.js +1 -1
- package/dist/src/engine-eval-script.js +1 -1
- package/dist/src/error.js +1 -1
- package/dist/src/explicit-session-resolution.js +1 -1
- package/dist/src/expo-dev-client-launch.js +1 -1
- package/dist/src/file.js +1 -1
- package/dist/src/find.js +1 -1
- package/dist/src/finders.js +1 -1
- package/dist/src/gesture-admission.js +1 -1
- package/dist/src/gesture-plan.js +1 -1
- package/dist/src/gesture-runtime.js +1 -1
- package/dist/src/hdc.js +1 -1
- package/dist/src/helper.js +2 -2
- package/dist/src/host.js +1 -1
- package/dist/src/host2.js +1 -1
- package/dist/src/host3.js +1 -1
- package/dist/src/host4.js +1 -1
- package/dist/src/host5.js +1 -0
- package/dist/src/human-control.js +1 -1
- package/dist/src/ime-rebind.js +1 -1
- package/dist/src/ime-state.js +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/input-actions.js +1 -1
- package/dist/src/input-actions2.js +1 -1
- package/dist/src/install-source-network-transport.js +1 -1
- package/dist/src/install-source2.js +1 -1
- package/dist/src/interaction-positionals.js +1 -1
- package/dist/src/interaction.js +1 -1
- package/dist/src/interaction2.js +1 -1
- package/dist/src/interactor-operation-catalog.js +1 -1
- package/dist/src/interactor.js +5 -5
- package/dist/src/interactor2.js +1 -1
- package/dist/src/interactor3.js +1 -1
- package/dist/src/interactor4.js +1 -1
- package/dist/src/interactor5.js +1 -1
- package/dist/src/interactors.js +1 -1
- package/dist/src/internal/bin.js +1 -1
- package/dist/src/internal/daemon.js +1 -1
- package/dist/src/internal/png-worker.js +1 -1
- package/dist/src/inventory.js +1 -1
- package/dist/src/inventory2.js +1 -1
- package/dist/src/inventory6.js +1 -1
- package/dist/src/ios-node-interpretation.js +1 -1
- package/dist/src/ios-settings.js +1 -1
- package/dist/src/ios-snapshot-acquisition.js +1 -1
- package/dist/src/ios-snapshot-engine.js +1 -1
- package/dist/src/ios-snapshot-runtime.js +1 -1
- package/dist/src/keyboard-occlusion.js +1 -1
- package/dist/src/keyed-lock.js +1 -1
- package/dist/src/launch-confirmation.js +1 -1
- package/dist/src/launch-services-registration.js +4 -4
- package/dist/src/lease.js +1 -1
- package/dist/src/legacy.js +1 -1
- package/dist/src/limrun-runtime-dependencies.js +1 -1
- package/dist/src/local-interactor-operation-set.js +1 -1
- package/dist/src/mechanics.js +12 -12
- package/dist/src/mobile-snapshot-semantics.js +1 -1
- package/dist/src/observability.js +1 -1
- package/dist/src/output-path.js +1 -1
- package/dist/src/parameterized-recorded-fill.js +1 -1
- package/dist/src/perf-facade.js +1 -1
- package/dist/src/perf-runtime-operation-builder.js +1 -1
- package/dist/src/perf-target.js +1 -1
- package/dist/src/physical-device-control.js +1 -1
- package/dist/src/platform-runtime-android-adb-host.js +1 -1
- package/dist/src/platform-runtime-claim-recovery.js +1 -1
- package/dist/src/platform-runtime-daemon-services.js +1 -1
- package/dist/src/platform-runtime-host.js +1 -1
- package/dist/src/platform-runtime-open-target.js +1 -1
- package/dist/src/platform-runtime-operation-host.js +5 -5
- package/dist/src/platform-runtime-runtime-hints.js +2 -2
- package/dist/src/platform-runtime-screen-recording-apple-simulator-host.js +1 -1
- package/dist/src/platform-runtime-screen-recording-finalizer-host.js +1 -1
- package/dist/src/platform-runtime-unavailable.js +1 -1
- package/dist/src/platform-runtime.js +1 -1
- package/dist/src/platform-runtime2.js +1 -1
- package/dist/src/png-resize.js +1 -1
- package/dist/src/png-worker-client.js +1 -1
- package/dist/src/process-exit.js +1 -1
- package/dist/src/provider-device-runtime.d.ts +28 -0
- package/dist/src/provider-plugin-catalog.js +2 -0
- package/dist/src/provider-plugin.d.ts +1 -1
- package/dist/src/provider-webdriver.js +1 -1
- package/dist/src/proxy.js +1 -1
- package/dist/src/react-native-overlay2.js +1 -1
- package/dist/src/react-native.js +1 -1
- package/dist/src/react-profile-command.js +1 -1
- package/dist/src/record-runtime.js +1 -1
- package/dist/src/record-trace.js +1 -1
- package/dist/src/recording-scope.js +1 -1
- package/dist/src/recording.js +1 -1
- package/dist/src/registry.js +1 -1
- package/dist/src/remote-config-core.js +1 -1
- package/dist/src/replay-backend-host.js +1 -1
- package/dist/src/replay-divergence.js +1 -1
- package/dist/src/replay-maestro-backend.js +3 -3
- package/dist/src/replay-script-selection.js +1 -1
- package/dist/src/replay2.js +1 -1
- package/dist/src/request-runtime-binding.js +1 -1
- package/dist/src/request.js +1 -1
- package/dist/src/result-serialization.js +1 -1
- package/dist/src/retry.js +1 -1
- package/dist/src/runner-cache-retention.js +1 -1
- package/dist/src/runner-client.js +1 -1
- package/dist/src/runner-dev-tools-security.js +1 -1
- package/dist/src/runner-device-readiness.js +1 -1
- package/dist/src/runner-device-set.js +1 -1
- package/dist/src/runner-error-classification.js +2 -2
- package/dist/src/runner-exchange.js +1 -1
- package/dist/src/runner-lease.js +1 -1
- package/dist/src/runner-operations-facade.js +1 -1
- package/dist/src/runner-retention.js +1 -1
- package/dist/src/runner-selector-query.js +1 -1
- package/dist/src/runner-start-budget.js +1 -1
- package/dist/src/runner-startup-transport.js +1 -1
- package/dist/src/runner-toolchain-probe.js +1 -1
- package/dist/src/runner.js +2 -2
- package/dist/src/runtime-admission.js +1 -1
- package/dist/src/runtime-deployment.js +1 -1
- package/dist/src/runtime-factory.js +1 -1
- package/dist/src/runtime-session.js +1 -1
- package/dist/src/runtime.js +4 -4
- package/dist/src/runtime10.js +2 -2
- package/dist/src/runtime2.js +1 -1
- package/dist/src/runtime3.js +5 -5
- package/dist/src/runtime4.js +1 -1
- package/dist/src/runtime5.js +1 -1
- package/dist/src/runtime6.js +1 -1
- package/dist/src/runtime7.js +1 -1
- package/dist/src/runtime8.js +1 -1
- package/dist/src/runtime9.js +2 -2
- package/dist/src/screen-recording-transport.js +1 -1
- package/dist/src/screenshot-density.js +1 -1
- package/dist/src/screenshot-runtime.js +1 -1
- package/dist/src/screenshot3.js +1 -1
- package/dist/src/sdk-batch-runner.js +2 -2
- package/dist/src/sdk-batch.js +2 -2
- package/dist/src/sdk-contracts.d.ts +9 -0
- package/dist/src/sdk-contracts.js +2 -2
- package/dist/src/sdk-device.js +1 -1
- package/dist/src/sdk-finders.js +1 -1
- package/dist/src/sdk-io.js +5 -5
- package/dist/src/sdk-remote-config.js +1 -1
- package/dist/src/sdk-selectors.js +1 -1
- package/dist/src/selection.js +0 -0
- package/dist/src/selector-pipeline-policy.js +1 -1
- package/dist/src/selector-runtime.js +1 -1
- package/dist/src/selectors.js +1 -1
- package/dist/src/server-startup.js +1 -1
- package/dist/src/session-paths.js +1 -1
- package/dist/src/session-replay-vars.js +1 -1
- package/dist/src/session-runtime.js +1 -1
- package/dist/src/session-store.js +3 -3
- package/dist/src/session.js +1 -1
- package/dist/src/session2.js +5 -5
- package/dist/src/settings-bluetooth.js +1 -1
- package/dist/src/settings.js +1 -1
- package/dist/src/settings2.js +1 -1
- package/dist/src/settle-observation-capture.js +1 -1
- package/dist/src/simctl-settings.js +1 -1
- package/dist/src/simctl.js +1 -1
- package/dist/src/simulator-boot.js +1 -1
- package/dist/src/simulator-state.js +1 -1
- package/dist/src/simulator.js +1 -1
- package/dist/src/snapshot-chrome.js +1 -1
- package/dist/src/snapshot-desktop-projection.js +1 -1
- package/dist/src/snapshot-helper-install.js +6 -6
- package/dist/src/snapshot-node-lookup.js +1 -1
- package/dist/src/snapshot-occlusion.js +1 -1
- package/dist/src/snapshot-runtime-binding.js +1 -1
- package/dist/src/snapshot-runtime-capture-input.js +1 -1
- package/dist/src/snapshot-runtime.js +1 -1
- package/dist/src/snapshot-state.js +1 -1
- package/dist/src/snapshot.js +1 -1
- package/dist/src/snapshot3.js +1 -1
- package/dist/src/src.js +1 -1
- package/dist/src/src3.js +1 -1
- package/dist/src/src4.js +1 -1
- package/dist/src/store.js +1 -1
- package/dist/src/tap-keyboard-occlusion.js +1 -1
- package/dist/src/target-evidence-tree.js +1 -1
- package/dist/src/target-evidence.js +1 -1
- package/dist/src/telephony-runtime.js +1 -1
- package/dist/src/text-entry-focus.js +1 -1
- package/dist/src/tool-provider.js +3 -3
- package/dist/src/tool-provider2.js +1 -1
- package/dist/src/tool-provider3.js +1 -1
- package/dist/src/toolchain-probe.js +1 -1
- package/dist/src/touch-reference-frame.js +1 -1
- package/dist/src/touch-runtime.js +1 -1
- package/dist/src/touch-runtime2.js +1 -1
- package/dist/src/tree.js +1 -1
- package/dist/src/tv-remote-runtime.js +1 -1
- package/dist/src/tv-remote.js +2 -2
- package/dist/src/type-text-runtime.js +1 -1
- package/dist/src/update-check.js +1 -1
- package/dist/src/vega-executable.js +1 -1
- package/dist/src/video.js +1 -1
- package/dist/src/webdriver-source.js +1 -1
- package/package.json +7 -6
- package/server.json +2 -2
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.30.apk.sha256 +0 -1
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.30.apk +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.30.apk.sha256 +0 -1
- package/dist/src/physical-device-apps.js +0 -1
package/dist/src/runtime3.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{B as e,R as t,V as n,Z as r,et as i}from"./sdk-contracts.js";import{A as a,l as o,x as s}from"./tv-remote.js";import{a as c,b as l,i as u,v as d}from"./sdk-batch-runner.js";import{G as f,J as p,K as m,L as ee,T as te,bt as ne,ht as h,j as re,y as ie}from"./sdk-io.js";import"./diagnostics.js";import{C as ae,F as oe,_ as g,g as se,j as _,p as ce,u as le,v}from"./sdk-device.js";import{an as ue,cn as de,en as fe,on as y,sn as b}from"./sdk-batch.js";import{n as pe,r as me}from"./session.js";import{a as he,t as ge}from"./file.js";import"./command.js";import{r as _e}from"./version.js";import"./retry.js";import{i as ve,n as ye,r as be}from"./ios-snapshot-planning.js";import{i as xe,n as Se}from"./durable-resource.js";import{n as Ce}from"./screen-recording-runtime.js";import{t as we}from"./request.js";import{n as Te,r as Ee,t as De}from"./application-lifecycle-runtime.js";import{n as Oe,t as ke}from"./async-lifecycle.js";import{i as Ae,t as je}from"./touch-runtime.js";import{t as Me}from"./ios-system-surface.js";import{r as Ne}from"./gesture-admission.js";import{B as Pe,C as Fe,E as Ie,I as Le,K as Re,M as ze,N as Be,O as Ve,P as He,R as Ue,T as We,U as Ge,V as Ke,W as qe,X as Je,Y as Ye,Z as Xe,_ as Ze,j as Qe,k as $e,l as et,o as tt,p as nt,q as rt,r as it,v as at,x as ot}from"./tv-remote-runtime.js";import{n as st,o as ct,s as lt,u as ut}from"./application-lifecycle-interaction.js";import{t as dt}from"./interactor-operation-catalog.js";import{a as ft,i as pt,n as mt,o as ht,r as gt,s as _t,t as vt}from"./network-traffic.js";import{a as yt,i as bt,r as xt}from"./src4.js";import{n as St,t as Ct}from"./screen-recording-completion.js";import{a as wt,c as Tt,i as Et,l as Dt,n as Ot,o as kt,r as At,s as jt,t as Mt}from"./device-readiness-runtime.js";import{a as Nt,i as Pt,n as Ft,r as It,t as Lt}from"./perf-runtime-operation-builder.js";import{t as Rt}from"./app-log-runtime.js";import{n as zt}from"./artifact-paths.js";import{O as Bt,T as Vt,b as Ht,c as Ut,f as Wt,g as Gt,n as Kt,o as qt,w as Jt}from"./host-file.js";import{a as Yt,o as Xt,s as Zt}from"./config.js";import{a as Qt,o as $t}from"./tool-provider.js";import{o as en}from"./devicectl.js";import{t as tn}from"./physical-device-apps.js";import{t as nn}from"./apple-runner-platform.js";import{a as rn,c as an,n as on,o as sn,s as x,u as cn}from"./simctl.js";import{r as ln}from"./simulator.js";import{r as un}from"./display-inventory.js";import{n as dn,t as fn}from"./app-backend.js";import{t as pn}from"./simulator-state.js";import{createHash as mn,randomUUID as hn}from"node:crypto";import S from"node:path";function gn(e,t){return Object.freeze({appState:async n=>{if(t.signal.throwIfAborted(),!await e.appleApplications.hasLiveRunnerSession(t.device,{}))return{};let r=await t.resolveInteractor(t.device,{appBundleId:n?.appBundleId,signal:t.signal});if(typeof r.appState!=`function`)throw de(`Runtime owner advertised appState without an interactor implementation`);return await r.appState()}})}function _n(e){return kt(e)?Object.freeze({available:!0}):v(e)||g(e)&&e.kind===`simulator`?Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`audio probe capture requires a macOS host.`}):Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`audio is supported for macOS sessions and iOS simulators on macOS hosts; physical iOS devices expose no host audio tap.`})}function vn(e){let{resolveHost:t,device:n,owner:r}=e;return Object.freeze({...Lt({platform:`Apple`,expectedProfileKind:`xctrace`,start:async e=>await t().start(n,r,e),reattach:async e=>await t().reattach(n,e),cleanup:async e=>await t().cleanup(n,e),writeProfileReport:async e=>await t().writeProfileReport(e)}),perfFrames:async({appId:e})=>({metric:e?await Pt(t().sampleFrames(n,e)):Ft(`Apple`,`bundle ID`),sampling:await t().frameSampling(n)}),perfMemorySample:async({appId:e})=>({metric:e?await Pt(t().sampleMemory(n,e)):Ft(`Apple`,`bundle ID`),sampling:await t().memorySampling(n)}),perfMemorySnapshot:async({appId:e,kind:r,outPath:i,artifactsDir:a})=>{let o=r??`memgraph`,s={...await t().memorySnapshotSupport(n),androidHprof:!1,heapprofd:!1};if(o!==`memgraph`)return Nt(`Apple`,o,s,`Use perf memory snapshot --kind memgraph for supported Apple app sessions.`);if(!e)throw It();let c=i??S.join(a,`memory-memgraph-${yn()}.memgraph`);return{artifact:await t().captureMemorySnapshot(n,e,c),support:s,sampling:{method:`xcrun memgraph`,description:`Native Apple memory graph captured for offline inspection.`,defaultKind:`memgraph`,artifactOnly:!0}}}})}function yn(){return new Date().toISOString().replaceAll(/[:.]/g,`-`)}const C=Object.freeze({available:!0}),w=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),T=Sn(`Gestures are supported only for Apple simulators and devices.`),bn=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:Ne}),xn=Sn(`scroll is supported only for Apple simulators and devices.`);function Sn(e){return Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:e})}function Cn(e){return{...Re({unsupported:wn(e),plan:Tn(e),directionalFling:Tn(e),multiTouch:En(e),targetAuthoredDrag:Dn(e),viewport:On(e)}),...Ge({scroll:kn(e)})}}function wn(e){return e.appleOs===`watchos`||e.appleOs===`visionos`?w:T}function Tn(e){return e.appleOs===`watchos`||e.appleOs===`visionos`?w:E(e)?C:T}function En(e){if(e.appleOs===`watchos`)return w;if(!E(e))return T;let t=_(e);if(t!==`ios`&&t!==`ipados`){let e=dn[t];return Object.freeze({available:!1,reason:`unsupported-platform-leaf`,...e===void 0?{}:{hint:e}})}return C}function Dn(e){return E(e)?(e.appleOs===void 0?e.target!==`desktop`&&e.target!==`tv`:e.appleOs===`ios`||e.appleOs===`ipados`)?C:bn:T}function On(e){return e.appleOs===`watchos`?w:E(e)?C:T}function kn(e){return E(e)?C:xn}function E(e){return e.kind===`simulator`||e.kind===`device`}const D=`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`;function O(e){return v(e)?`macos`:e.kind===`device`?`ios-device`:`ios-simulator`}const An=Object.freeze({resourceKind:Rt,version:1,encode:e=>({...e}),decode:e=>!Mn(e.transport)||!Nn(e.backend)||!Ln(e.outputPath)||!Fn(e.pidPath)||!Pn(e.transport,e.backend)?jn():{status:`decoded`,descriptor:Object.freeze({transport:e.transport,backend:e.backend,outputPath:e.outputPath,...e.pidPath===void 0?{}:{pidPath:e.pidPath}})}});function jn(){return{status:`invalid`,message:`Invalid Apple app-log descriptor`}}function Mn(e){return e===`apple-log-stream`||e===`coredevice-console`}function Nn(e){return e===`ios-simulator`||e===`ios-device`||e===`macos`}function Pn(e,t){return e===`coredevice-console`?t===`ios-device`:t!==`ios-device`}function Fn(e){return e===void 0||Ln(e)}function In(e){if(!e.device.appleOs)throw TypeError(`Apple app-log persistence requires an explicit appleOs identity`);return Se({resourceKind:Rt,sessionId:e.sessionId,device:{id:e.device.id,family:`apple`,appleOs:e.device.appleOs,kind:e.device.kind,...e.device.target===void 0?{}:{target:e.device.target},...e.device.iosPhysicalDeviceBackend===void 0?{}:{iosPhysicalDeviceBackend:e.device.iosPhysicalDeviceBackend}},owner:e.owner,fence:e.fence,lifecycle:`open`,descriptor:xe(An,e.descriptor)})}function Ln(e){return typeof e==`string`&&e.trim().length>0}const Rn={message:`iOS physical-device app console capture is not supported by the installed devicectl.`,hint:`This devicectl does not expose process launch --console. Markers can still be written to app.log, but app output is not being captured. Use an iOS simulator for agent-device app logs or inspect physical-device logs in Console.app/Xcode until this Xcode toolchain exposes scriptable console capture.`},zn={message:`Could not verify iOS physical-device app console capture support.`,hint:`Retry logs clear --restart. If the probe keeps failing, run logs doctor and inspect the request diagnostics for the devicectl help command.`};async function Bn(e,t){try{let n=await e.appleTools.run({tool:`devicectl`,args:[`device`,`process`,`launch`,`--help`],allowFailure:!0,timeoutMs:5e3},t),r=n.stderr.trim()||void 0;if(n.exitCode!==0)return{supported:!1,reason:`probe-failed`,stderr:r};let i=`${n.stdout}\n${n.stderr}`;return/\bUSAGE:\s+devicectl device process launch\b/i.test(i)&&/--console\b/.test(i)&&/--terminate-existing\b/.test(i)?{supported:!0,...r?{stderr:r}:{}}:{supported:!1,reason:`unsupported`,...r?{stderr:r}:{}}}catch(e){if(t?.aborted)throw t.reason;return{supported:!1,reason:`probe-failed`,...e instanceof Error?{stderr:e.message}:{}}}}async function Vn(e,t,n,r){let i={},a=n?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`];if(v(t))i.logAvailable=!!await e.commands.which(`log`);else if(t.kind===`simulator`)i.simctlAvailable=await Dt(async()=>Tt(await e.appleTools.run({tool:`simctl`,args:an(),allowFailure:!0},r)),r);else if(t.iosPhysicalDeviceBackend===`xctest`)i.devicectlAvailable=!1,i.devicectlConsoleCapture=!1,a.push(D);else{i.devicectlAvailable=await Dt(async()=>Tt(await e.appleTools.run({tool:`devicectl`,args:[`--version`],allowFailure:!0},r)),r);let t=await Bn(e,r);if(i.devicectlConsoleCapture=t.supported,!t.supported){let e=t.reason===`unsupported`?Rn:zn;a.push(`${e.message} ${e.hint}`)}}return{backend:O(t),checks:i,notes:a}}function Hn(e,t){let n=Gn(e),r=[`subsystem == "${n}"`,`subsystem CONTAINS "${n}"`,`processImagePath ENDSWITH[c] "/${n}"`,`senderImagePath ENDSWITH[c] "/${n}"`];if(t){let e=Gn(t);r.push(`process == "${e}"`,`processImagePath ENDSWITH[c] "/${e}"`,`senderImagePath ENDSWITH[c] "/${e}"`,`processImagePath CONTAINS[c] "/${e}.app/"`,`senderImagePath CONTAINS[c] "/${e}.app/"`)}return r.join(` OR `)}function Un(e,t){return on(e,[`spawn`,e.id,`log`,`stream`,`--style`,`compact`,`--level`,`info`,`--predicate`,Hn(t.appBundleId,t.executableName)])}function Wn(e,t){return[`devicectl`,`device`,`process`,`launch`,`--device`,e,`--console`,`--terminate-existing`,t]}function Gn(e){return e.replaceAll(`\\`,String.raw`\\`).replaceAll(`"`,String.raw`\"`)}async function Kn(e,t,n,r,i){qn(t),pt(e,n);let a=O(t),o=await Yn(e,t,n.appBundleId,i),s=new ke,c=!1;try{let l=await e.outputs.openAppend(n.outputPath);s.defer(async()=>{c||await l[Symbol.asyncDispose]()}),i?.throwIfAborted();let u=await Jn(e,t,o,l,n.pidPath,i);s.defer(async()=>{c||await u[Symbol.asyncDispose]()});let d=Zn(e,u,l,a,n.outputPath),f={transport:a===`ios-device`?`coredevice-console`:`apple-log-stream`,backend:a,outputPath:n.outputPath,...n.pidPath===void 0?{}:{pidPath:n.pidPath}},p=_t(d,In({sessionId:n.sessionId,device:t,owner:r,fence:n.fence,descriptor:f}));return c=!0,p}finally{await s[Symbol.asyncDispose]()}}function qn(e){if(e.appleOs===`watchos`)throw new t(`UNSUPPORTED_PLATFORM`,`watchOS app logs are not supported`);if(g(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`)throw new t(`UNSUPPORTED_OPERATION`,D,{hint:D})}async function Jn(e,n,r,i,a,o){if(g(n)&&n.kind===`device`){let n=await Bn(e,o);if(!n.supported){let e=n.reason===`unsupported`?Rn:zn;throw new t(n.reason===`unsupported`?`UNSUPPORTED_OPERATION`:`COMMAND_FAILED`,e.message,{backend:`ios-device`,hint:e.hint,stderr:n.stderr})}}return o?.throwIfAborted(),await e.processes.start({command:{kind:`host`,request:r},output:i,...a?{markerPath:a}:{}})}async function Yn(e,t,n,r){return v(t)?{executable:`log`,args:[`stream`,`--style`,`compact`,`--predicate`,Hn(n)],allowFailure:!0}:t.kind===`device`?{executable:`xcrun`,args:Wn(t.id,n),allowFailure:!0}:{executable:`xcrun`,args:Un(t,{appBundleId:n,executableName:await Xn(e,t,n,r)}),allowFailure:!0}}async function Xn(e,t,n,r){let i=await e.appleTools.run({tool:`simctl`,args:x(t,[`get_app_container`,t.id,n,`app`]),allowFailure:!0,timeoutMs:4e3},r),a=i.exitCode===0?i.stdout.trim():``;if(!a)return;let o=await e.commands.run({executable:`plutil`,args:[`-extract`,`CFBundleExecutable`,`raw`,`-o`,`-`,S.join(a,`Info.plist`)],allowFailure:!0,timeoutMs:4e3},r);return o.exitCode===0&&o.stdout.trim()||void 0}function Zn(e,t,n,r,i){let a=e.clock.now(),o=`active`;t.wait.then(e=>{o=e.exitCode===0?`ended`:`failed`},()=>{o=`failed`});let s;return ft({inspect:()=>({backend:r,state:o,startedAt:a}),finish:async()=>s??=(async()=>(await Qn([async()=>await t.terminate(),async()=>await t.wait.then(()=>void 0),async()=>await t[Symbol.asyncDispose](),async()=>await n[Symbol.asyncDispose]()])).length>0?(o=`failed`,{status:`cleanup-pending`,reason:`transport-failed`,message:`Apple app-log cleanup did not settle every owned resource`}):(o=`ended`,{status:`completed`,result:{backend:r,outputPath:i,completedAt:e.clock.now()}}))()})}async function Qn(e){let t=[];for(let n of e)try{await n()}catch(e){t.push(e)}return t}const k=fe(`apple`),$n=Object.freeze({available:!0});function er(e){return Object.freeze({owner:k,ownsDevice:e=>e.platform===`apple`,inspectFacts:async e=>nr(e),bind:async n=>{if(n.intent.kind===`exact-owner`&&!ue(n.intent.owner,k))throw new t(`UNSUPPORTED_OPERATION`,`Apple app-log owner identity does not match`);return tr(e,n.device,n.scope.signal)},shutdown:async()=>void 0})}function tr(e,n,r){if(n.platform!==`apple`)throw new t(`UNSUPPORTED_PLATFORM`,`Apple app-log owner cannot bind ${n.platform}`);let i=ht({codec:An,reattach:async(t,r)=>t.backend!==O(n)||!gt(e,r.sessionId,t)?{status:`unreattachable`,reason:`descriptor-invalid`,message:`Apple app-log descriptor does not match the bound device or owning session`}:await bt(e,t.pidPath),cleanup:async(t,r)=>t.backend===O(n)&>(e,r.sessionId,t)?await xt(e,t.pidPath):{status:`cleanup-pending`,reason:`ownership-fence-lost`,message:`Apple app-log descriptor does not match the bound device or owning session`}}),a=Object.freeze({appLogInspect:async()=>({backend:O(n)}),appLogDoctor:async({appBundleId:t})=>await Vn(e,n,t,r),appLogStart:async t=>await Kn(e,n,t,k,r),...i});return Object.freeze({device:n,owner:k,facts:nr(n),operations:a,[Symbol.asyncDispose]:async()=>void 0})}function nr(e){if(e.appleOs===`watchos`)return rr(e);let t=g(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?{available:!1,reason:`unsupported-device-backend`,hint:D}:$n;return Object.freeze({device:{family:`apple`,appleOs:e.appleOs,kind:e.kind,...e.target===void 0?{}:{target:e.target},...e.iosPhysicalDeviceBackend===void 0?{}:{iosPhysicalDeviceBackend:e.iosPhysicalDeviceBackend},providerMode:`local`},operations:{appLogInspect:t,appLogDoctor:t,appLogStart:t,appLogReattach:$n,appLogCleanup:$n}})}function rr(e){let t=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS app logs are not supported.`});return Object.freeze({device:{family:`apple`,appleOs:`watchos`,kind:e.kind,...e.target===void 0?{}:{target:e.target},providerMode:`local`},operations:{appLogInspect:t,appLogDoctor:t,appLogStart:t,appLogReattach:t,appLogCleanup:t}})}async function ir(e,t,n,r){let i=O(t),a=await e.appLogs.readRecent(n.sessionId,n.maxScanLines),o=mt(a.text,{...n,path:a.path,exists:a.exists,lineNumberOffset:a.skippedLines,backend:i}),s=[];if(or(t,n,o.dump)){let i=await sr(e,t,n,a.path,r);i&&(o=ar(s,o,i,n.maxEntries))}return ur(s,t,n),lr(s,o.dump),o.dump.entries.length===0&&s.push(dr(t)),Object.freeze({source:`app-log`,backend:i,dump:o.dump,notes:Object.freeze(s)})}function ar(e,t,n,r){let i=n.scan.dump.entries.length;return i===0&&(n.scan.dump.unnamedRequests??0)===0?(n.lineCount>0&&e.push(`Recovered ${n.lineCount} recent iOS simulator app log lines from simctl log show, but none looked like HTTP traffic. This app may not emit request URLs, status, or timing into Unified Logging for this repro window.`),t):(i>0&&e.push(`Recovered ${i} iOS simulator HTTP entr${i===1?`y`:`ies`} from simctl log show (${n.lineCount} app log lines scanned).`),vt(n.scan,t,r))}function or(e,t,n){return g(e)&&e.kind===`simulator`&&!!t.appBundleId&&n.entries.length===0}async function sr(e,t,n,r,i){let a=n.appLogSnapshot?.startedAt,o=x(t,[`spawn`,t.id,`log`,`show`,`--style`,`compact`,`--info`,`--predicate`,cr(n.appBundleId),...typeof a==`number`&&Number.isFinite(a)&&a>0?[`--start`,`@${Math.floor(a/1e3)}`]:[`--last`,`5m`]]),s=await e.appleTools.run({tool:`simctl`,args:o,allowFailure:!0,timeoutMs:4e3},i);if(s.exitCode!==0||!s.stdout.trim())return;let c=s.stdout.split(`
|
|
2
|
-
`).map(e=>e.trimEnd()).filter(e=>e.trim()&&!e.trim().startsWith(`Timestamp Ty Process[PID:TID]`));if(c.length!==0)return{scan:
|
|
3
|
-
`)}\n`,{...n,path:`${r} (simctl log show recovery)`,exists:!0,backend:`ios-simulator`}),lineCount:c.length}}function cr(e){let t=e.replaceAll(`\\`,String.raw`\\`).replaceAll(`"`,String.raw`\"`);return[`subsystem == "${t}"`,`subsystem CONTAINS "${t}"`,`processImagePath ENDSWITH[c] "/${t}"`,`senderImagePath ENDSWITH[c] "/${t}"`].join(` OR `)}function lr(e,t){let n=t.entries.filter(e=>e.pathUnavailable).length,r=t.unnamedRequests??0,i=n+r;if(i===0)return;let a=[`${i} request${i===1?``:`s`} reused a keep-alive connection, so CFNetwork logged no request URL.`];n>0&&a.push(`${n} listed against the origin the connection was opened for, without a path.`),r>0&&a.push(`${r} opened before this scan window and are missing from the entries entirely; scan more lines, or run logs clear --restart before the repro.`),a.push(`Absence of an endpoint in this dump does not prove it was not called.`),e.push(a.join(` `))}function ur(e,t,n){n.appLogSnapshot?n.appLogSnapshot.state!==`active`&&e.length===0&&e.push(g(t)&&t.kind===`simulator`?`Session app log stream is inactive. The iOS simulator recovery path scanned recent simctl log history, but a fresh logs clear --restart window is still the most reliable repro loop.`:`Session app log stream is inactive. Run logs clear --restart, reproduce the request window again, then rerun network dump.`):e.push(`Capture uses the session app log file. For fresh traffic, run logs clear --restart before reproducing requests.`)}function dr(e){return g(e)&&e.kind===`simulator`?`No HTTP(s) entries were found in recent iOS simulator app logs. If the app only emits non-HTTP diagnostics, inspect logs path or add app-side URLSession/network logging for per-request timing and payload details.`:g(e)?`No HTTP(s) entries were found in recent iOS device app logs. iOS network dump only sees what the app emits into Unified Logging for this process.`:`No HTTP(s) entries were found in recent session app logs.`}async function fr(t){let{host:n,snapshot:r,targetLabel:i,recorderWarning:a,nativePathDisposition:o}=t,s=r.invalidatedReason?{recorder:`lost`,why:`owner-session-lost`}:t.stopObservation;if(r.invalidatedReason&&!r.showTouches)throw Error(`recording invalidated: ${r.invalidatedReason}`);let c;try{c=await n.screenRecording.finalize.complete({outputPath:r.outPath,showTouches:!r.invalidatedReason&&r.showTouches,gestureEvents:r.gestureEvents,exportQuality:r.exportQuality??`medium`,...r.fps===void 0?{}:{fps:r.fps},targetLabel:i})}catch(t){throw e(t,`COMMAND_FAILED`)}let l=[...c.warning?[c.warning]:[],...a?[a]:[]];return Ct(r,{...c,...l.length>0?{warning:l.join(` `)}:{},...r.invalidatedReason?{overlayWarning:`overlay unavailable: ${r.invalidatedReason}`}:{}},{stopObservation:s,...o===void 0?{}:{nativePathDisposition:o}})}async function pr(e){let{host:t,snapshot:n,targetLabel:r,collectedPath:i,exportPath:a,nativePath:o}=e;if(n.invalidatedReason&&!n.showTouches)throw Error(`recording invalidated: ${n.invalidatedReason}`);let s=e.overlayUnavailable??n.invalidatedReason,c;try{await t.screenRecording.outputs.copy({from:i,to:a}),c=await mr(()=>t.screenRecording.finalize.complete({outputPath:a,showTouches:s===void 0&&n.showTouches,gestureEvents:n.gestureEvents,exportQuality:n.exportQuality??`medium`,...n.fps===void 0?{}:{fps:n.fps},targetLabel:r}))}catch(e){throw await t.screenRecording.outputs.remove(a),e}return{...c,...s===void 0?{}:{overlayWarning:`overlay unavailable: ${s}`},nativePathDisposition:await t.screenRecording.outputs.remove(o)===`removed`?`retired`:`retirable`}}async function mr(t){try{return await t()}catch(t){throw e(t,`COMMAND_FAILED`)}}const hr=[`outPath`,`startedAt`,`clientOutPath`,...Et],gr=Object.freeze({resourceKind:Ce,version:1,encode:e=>e.backend===`simctl`?{backend:e.backend,outputPath:e.outputPath,processes:e.processes.map(e=>({...e})),...e.recording===void 0?{}:{recording:{...e.recording}}}:{backend:e.backend,outputPath:e.outputPath,appBundleId:e.appBundleId,runnerSessionId:e.runnerSessionId,runnerAuthority:e.runnerAuthority,...e.remotePath===void 0?{}:{remotePath:e.remotePath}},decode:e=>Or(e)});function _r(e){let{device:t,owner:n,input:r,descriptor:i}=e;return Se({resourceKind:Ce,sessionId:r.sessionId,device:oe(t),owner:n,fence:r.fence,lifecycle:`open`,descriptor:xe(gr,i)})}function vr(e){let t={};for(let n of hr)e[n]!==void 0&&Object.assign(t,{[n]:e[n]});return t}async function yr(e,t,n,r){let i=gr.decode(n);return i.status!==`decoded`||!Rr(t,i.descriptor)?{status:`cleanup-pending`,reason:`manual-recovery-required`}:i.descriptor.backend===`simctl`?await br(e,i.descriptor.processes,r):await Sr(e,t,i.descriptor)}async function br(e,t,n){let r=await Promise.all(t.map(async t=>await e.screenRecording.apple.inspectProcess(t)));if(r.includes(`ownership-lost`))return{status:`cleanup-pending`,reason:`ownership-fence-lost`};if(r.every(e=>e===`missing`))return n!==void 0&&e.screenRecording.ownedProcesses.clear(xr(n)),{status:`already-missing`};let i=await Promise.all(t.flatMap((t,n)=>r[n]===`owned-alive`?[e.screenRecording.apple.terminateProcess(t)]:[]));return i.includes(`ownership-lost`)?{status:`cleanup-pending`,reason:`ownership-fence-lost`}:(n!==void 0&&e.screenRecording.ownedProcesses.clear(xr(n)),i.every(e=>e===`already-missing`)?{status:`already-missing`}:{status:`cleaned`})}function xr(e){return{kind:`session`,sessionId:e}}async function Sr(e,t,n){try{let r=await e.screenRecording.apple.inspectRunner(t,n.runnerSessionId,n.runnerAuthority);return r===`missing`?{status:`already-missing`}:r===`ownership-lost`?{status:`cleanup-pending`,reason:`ownership-fence-lost`}:(await e.screenRecording.apple.runRunner(t,{kind:`stop`,appBundleId:n.appBundleId,runnerSessionId:n.runnerSessionId,runnerAuthority:n.runnerAuthority}),{status:`cleaned`})}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`Apple recording cleanup failed`}}}async function Cr(e){let{host:t,device:n,envelope:r}=e,i=gr.decode(r.descriptor.body);return i.status===`decoded`?Rr(n,i.descriptor)?i.descriptor.backend===`simctl`?await wr(e,i.descriptor):await Er(t,n,i.descriptor):A(`descriptor-invalid`,`Apple screen-recording descriptor does not match the bound device.`):A(`descriptor-invalid`,i.message)}async function wr(e,t){let n=await Promise.all(t.processes.map(async t=>await e.host.screenRecording.apple.inspectProcess(t)));if(!n.every(e=>e===`missing`))return A(`transport-not-reattachable`,n.includes(`ownership-lost`)?`Apple recording ownership no longer matches the durable descriptor.`:`Apple screen recordings require exact cleanup after daemon restart.`);let{recording:r}=t,i=Tr(At(e.envelope.metadata),t.outputPath);return r===void 0||i!==void 0&&!await Dr(e.host,i)?{status:`missing`}:{status:`restore-export`,recording:r,nativePath:t.outputPath,cleanup:async()=>await br(e.host,t.processes,e.envelope.sessionId)}}function Tr(e,t){if(e.finalization===void 0)return e.collectedPath??t}async function Er(e,t,n){let r=await e.screenRecording.apple.inspectRunner(t,n.runnerSessionId,n.runnerAuthority);return r===`missing`?{status:`missing`}:A(`transport-not-reattachable`,r===`ownership-lost`?`Apple recording ownership no longer matches the durable descriptor.`:`Apple screen recordings require exact cleanup after daemon restart.`)}async function Dr(e,t){try{return await e.screenRecording.finalize.sniff({outputPath:t}),!0}catch{return!1}}function A(e,t){return{status:`unreattachable`,reason:e,message:t}}function Or(e){return typeof e.outputPath!=`string`||e.outputPath.length===0?M():e.backend===`simctl`?kr(e,e.outputPath):e.backend===`runner`?Mr(e,e.outputPath):M()}function kr(e,t){let n=zr(e.processes),r=Ar(e.recording);return!n||r===`invalid`?M():{status:`decoded`,descriptor:Object.freeze({backend:`simctl`,outputPath:t,processes:n,...r===void 0?{}:{recording:r}})}}function Ar(e){if(e!==void 0)return d(e)&&jr(e)?Object.freeze(e):`invalid`}function jr(e){return j(e.outPath)&&Pr(e.startedAt)&&Nr(e.clientOutPath)&&wt(e)}function Mr(e,t){return!j(e.appBundleId)||!j(e.runnerSessionId)||!Fr(e.runnerAuthority)||!Ir(e.remotePath)?M():{status:`decoded`,descriptor:Object.freeze({backend:`runner`,outputPath:t,appBundleId:e.appBundleId,runnerSessionId:e.runnerSessionId,runnerAuthority:e.runnerAuthority,...e.remotePath===void 0?{}:{remotePath:e.remotePath}})}}function j(e){return typeof e==`string`&&e.length>0}function Nr(e){return e===void 0||j(e)}function Pr(e){return typeof e==`number`&&Number.isFinite(e)}function Fr(e){return e===`local-lease`||e===`scoped-provider`}function Ir(e){return e===void 0||Lr(e)}function Lr(e){return typeof e==`string`&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(e)}function Rr(e,t){return e.kind===`simulator`?t.backend===`simctl`:t.backend===`runner`?e.appleOs===`macos`?t.remotePath===void 0:g(e)?t.remotePath!==void 0&&Lr(t.remotePath):t.remotePath===void 0:!1}function zr(e){if(!Array.isArray(e)||e.length===0)return;let t=e.filter(e=>typeof e==`object`&&!!e&&Number.isInteger(e.pid)&&(e.pid??0)>0&&typeof e.startTime==`string`&&e.startTime.length>0&&typeof e.command==`string`&&e.command.length>0);return t.length===e.length?Object.freeze([...t]):void 0}function M(){return{status:`invalid`,message:`Invalid Apple screen-recording descriptor`}}async function Br(e,t,n){if(e.kind!==`simulator`||t.scope!==`app`)return;let r=t.activeSessionApp?.bundleId;if(!r)throw TypeError(`App-scoped recording requires an active app session; open the app under test before recording.`);if(await n(r))throw TypeError(`App-scoped recording requires a real application session; open the app under test before recording.`)}const Vr=`iOS recording`,Hr=`simctl recordVideo`;function Ur(e){return e.appleOs===`watchos`?y(`unsupported-platform-leaf`,`watchOS recording is not supported.`):g(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?y(`unsupported-device-backend`,`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`):Object.freeze({available:!0})}function Wr(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await Gr({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async e=>{let r=await Cr({host:t,device:n,envelope:e.envelope});return r.status===`restore-export`?{status:`active`,handle:qr({host:t,restored:r})}:r},screenRecordingCleanup:async e=>await yr(t,n,e.envelope.descriptor.body,e.envelope.sessionId)})}async function Gr(e){return e.signal.throwIfAborted(),e.device.kind===`simulator`?await Kr(e):await Yr(e)}async function Kr(e){let{host:t,device:n,owner:r,input:i,signal:a}=e;await Br(n,i,t.screenRecording.apple.isRunnerBundleId);let o=i.activeSessionApp?await t.screenRecording.apple.captureClockAnchor(n,i.activeSessionApp.bundleId,a):void 0,s=zt(i.outputPath);await t.screenRecording.outputs.prepare(s);let c=await t.screenRecording.apple.startSimulator(n,s,a),l=c.markers;if(!l||l.length===0)throw await ei(c).catch(()=>{}),Error(`simctl recordVideo did not expose durable process identity`);try{a.throwIfAborted(),t.screenRecording.ownedProcesses.replace({kind:`session`,sessionId:i.sessionId},l.map(e=>({...e,purpose:`simctl-screen-recording`})))}catch(e){try{t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId})}catch{}throw await ei(c).catch(()=>{}),e}let u,d,f=async()=>{await c.terminate();let e=await c.wait;return d=e,u=Zr(e),t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId}),{observation:{recorder:`confirmed`},...u===void 0?{}:{warning:`${u} before record stop; the video covers only what the recorder wrote before it stopped.`}}},p=ri(i,Hr,{},o);return ni({device:n,owner:r,input:i,descriptor:{backend:`simctl`,outputPath:s,processes:l,recording:vr(p)},snapshot:p,finish:(e,n)=>Ot({snapshot:e,progress:n,steps:{stop:f,collect:async e=>{try{await Jr(t,s,e)}catch(e){throw Qr(e,u,d)}},finalize:async({collectedPath:n,exportPath:r})=>{try{return await pr({host:t,snapshot:e,targetLabel:Vr,collectedPath:n,exportPath:r,nativePath:s})}catch(e){throw Qr(e,u,d)}},discard:async e=>{await t.screenRecording.outputs.remove(e)}}}),cleanup:async()=>{let e=await ti(c);return(e.status===`cleaned`||e.status===`already-missing`)&&t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId}),e}})}function qr(e){let{host:t,restored:{recording:n,nativePath:r,cleanup:i}}=e,a=Object.freeze({...n,backend:Hr,gestureEvents:[]});return St(a,{finish:(e,i)=>Ot({snapshot:e,progress:i,steps:{stop:async()=>({observation:{recorder:`confirmed`},warning:`simctl recordVideo had already ended when record stop reattached to it; the video covers only what the recorder wrote before it stopped.`}),collect:async e=>{await Jr(t,r,e)},finalize:async({collectedPath:i,exportPath:a})=>await pr({host:t,snapshot:e,targetLabel:Vr,collectedPath:i,exportPath:a,nativePath:r,...n.showTouches?{overlayUnavailable:`the daemon that held the touch events ended before record stop`}:{}}),discard:async e=>{await t.screenRecording.outputs.remove(e)}}}),forceCleanup:async()=>await i()})}async function Jr(e,t,n){await e.screenRecording.outputs.copy({from:t,to:n}),await e.screenRecording.finalize.sniff({outputPath:n})}async function Yr(e){let{host:t,device:n,owner:r,input:i,signal:a}=e,o=i.activeSessionApp?.bundleId;if(!o)throw TypeError(`Apple runner recording requires an active app session identity`);await t.screenRecording.outputs.prepare(i.outputPath);let s=await t.screenRecording.apple.runRunner(n,{kind:`start`,appBundleId:o,outputPath:i.outputPath,...i.fps===void 0?{}:{fps:i.fps}},a);if(!s.runnerSessionId||!s.runnerAuthority)throw Error(`Apple runner recording did not expose durable session ownership`);let c={runnerSessionId:s.runnerSessionId,runnerAuthority:s.runnerAuthority},l,u=()=>(l??=Xr(()=>t.screenRecording.apple.runRunner(n,{kind:`stop`,appBundleId:o,...c}).then(()=>void 0)).catch(e=>{throw l=void 0,e}),l);if(!$r(n,s.remotePath))throw await u().catch(()=>{}),Error(`Apple runner recording did not expose coherent durable media ownership`);try{a.throwIfAborted()}catch(e){throw await u().catch(()=>{}),e}return ni({device:n,owner:r,input:i,descriptor:{backend:`runner`,outputPath:i.outputPath,appBundleId:o,...c,...s.remotePath===void 0?{}:{remotePath:s.remotePath}},snapshot:ri(i,`runner AVAssetWriter`,s),finish:async e=>(await u(),s.remotePath!==void 0&&await t.screenRecording.apple.retrieveRunnerRecording(n,s.remotePath,e.outPath),await fr({host:t,snapshot:e,targetLabel:n.appleOs===`macos`?`macOS recording`:`iOS recording`,stopObservation:{recorder:`confirmed`},...s.remotePath===void 0?{}:{nativePathDisposition:`retirable`}})),cleanup:async()=>(await u(),{status:`cleaned`})})}async function Xr(t){try{return await t()}catch(t){throw e(t,`COMMAND_FAILED`)}}function Zr(e){if(e.exitCode!==0)return e.signal?`simctl recordVideo was killed by ${e.signal}`:`simctl recordVideo exited with code ${e.exitCode}`}function Qr(n,r,i){let a=e(n,`COMMAND_FAILED`);return r===void 0||i===void 0||a.details?.reason!==`recording-output-unplayable`?n:new t(a.code,`${a.message}; ${r}`,f(i,{...a.details??{},...i.signal===void 0?{}:{signal:i.signal},retriable:!1,hint:`The recorder exited before record stop, so the next record stop reads the same file. Close this session to release the device, then record again.`}))}function $r(e,t){return e.appleOs===`macos`||!g(e)?t===void 0:t!==void 0&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(t)}async function ei(e){return await e.terminate(),await e.wait}async function ti(e){try{return await ei(e),{status:`cleaned`}}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`Apple simulator cleanup failed`}}}function ni(e){let{device:t,owner:n,input:r,descriptor:i,snapshot:a,finish:o,cleanup:s}=e,c=St(a,{finish:o,forceCleanup:s});return Object.freeze({pendingHandle:new Oe(c),envelope:_r({device:t,owner:n,input:r,descriptor:i})})}function ri(e,t,n={},r){let i=Date.now();return Object.freeze({backend:t,outPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutPath:e.clientOutputPath},startedAt:i,scope:e.scope,showTouches:e.showTouches,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},...e.exportQuality===void 0?{}:{exportQuality:e.exportQuality},...e.fps===void 0?{}:{fps:e.fps},gestureEvents:[],...r===void 0?{}:{gestureClockOriginAtMs:r.wallClockAtMs,gestureClockOriginUptimeMs:r.uptimeMs},...n.recorderStartUptimeMs===void 0?{}:{gestureClockOriginAtMs:i,gestureClockOriginUptimeMs:n.recorderStartUptimeMs,runnerStartedAtUptimeMs:n.recorderStartUptimeMs},...n.runnerSessionId===void 0?{}:{runnerSessionId:n.runnerSessionId}})}async function N(e,t,n,r={}){return n.throwIfAborted(),v(t)?{...t,booted:!0}:t.kind===`device`?(await e.deviceReadiness.applePhysical.ensureConnected(t,n),{...t,booted:!0}):t.kind===`simulator`?((await ii(e,t)?`Booted`:await ui(e,t,n))!==`Booted`&&(r.onColdBootStart?.(),e.deviceReadiness.appleAutomation.keepHot(t),await ai(e,t,n,r.deadlineAtMs),await di(e,n)),e.deviceReadiness.appleAutomation.keepHot(t),e.deviceReadiness.appleAutomation.markBooted(t),{...t,booted:!0}):{...t,booted:!0}}async function ii(e,t){try{return await e.deviceReadiness.appleAutomation.wasRecentlyObservedBooted(t)}catch{return!1}}async function ai(e,t,n,r=Date.now()+12e4){let i=!1;try{i=await oi(e,t,n,r),await si(e,t,n,r)}catch(a){throw i&&n.aborted&&fi(e,t),n.throwIfAborted(),Date.now()>=r?li(t,a):a}}async function oi(e,n,r,i){let a=await e.appleTools.run({tool:`simctl`,args:x(n,[`boot`,n.id]),allowFailure:!0,timeoutMs:ci(i,n)},r),o=`${a.stdout}\n${a.stderr}`.toLowerCase(),s=o.includes(`already booted`)||o.includes(`current state: booted`);if(a.exitCode!==0&&!s)throw new t(`COMMAND_FAILED`,`simctl boot failed`,{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode});return!s}async function si(e,n,r,i){we({type:`command`,status:`progress`,message:`Waiting for the Simulator to finish booting...`});let a=await e.appleTools.run({tool:`simctl`,args:x(n,[`bootstatus`,n.id,`-b`]),allowFailure:!0,timeoutMs:ci(i,n)},r);if(a.exitCode!==0)throw new t(`COMMAND_FAILED`,`simctl bootstatus failed`,{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode});if(r.throwIfAborted(),Date.now()>=i)throw li(n)}function ci(e,t){let n=e-Date.now();if(n<=0)throw li(t);return n}function li(e,n){return new t(`COMMAND_FAILED`,`Simulator did not finish booting within the startup budget`,{reason:Mt,deviceId:e.id,hint:`The Simulator keeps booting in the background; a first boot can take several minutes. Retry once it is up, or pass a larger --timeout.`},n instanceof Error?n:void 0)}async function ui(e,t,n){return await pn(e.appleTools,t,n,15e3)}async function di(e,t){await e.commands.run({executable:`open`,args:[`-g`,`-a`,`Simulator`],allowFailure:!0,timeoutMs:1e4},t)}function fi(e,t){e.appleTools.run({tool:`simctl`,args:x(t,[`shutdown`,t.id]),allowFailure:!0}).catch(()=>{})}const pi=Object.freeze({resolveOpenTarget:`simulator`,prepareApplicationOpen:`simulator`,openApplication:`simulator`,applyRuntimeHints:`simulator`,clearRuntimeHints:`simulator`,closeApplication:`simulator`,finalizeApplicationClose:`simulator`,prepareAppleRunner:`runner`,configureProviderPortReverse:`simulator`,ensureReady:`simulator`,bootTarget:`simulator`,bootTargetHeadless:`simulator`,shutdownTarget:`simulator`,listApps:`simulator`,deployApp:`simulator`,materializeAppSource:`simulator`,deployMaterializedApp:`simulator`,sendPushNotification:`simulator`,uninstallApp:`simulator`,appState:`simulator`,appLogStart:`simulator`,appLogInspect:`simulator`,appLogDoctor:`simulator`,appLogReattach:`simulator`,appLogCleanup:`simulator`,networkDump:`simulator`,audioProbeStart:`simulator`,audioProbeQuery:`simulator`,audioProbeReattach:`simulator`,audioProbeCleanup:`simulator`,readClipboard:`simulator`,writeClipboard:`runner`,setSetting:`simulator`,readSetting:`simulator`,setFoldPose:`simulator`,sendTelephonyEvent:`simulator`,unlockOrientation:`simulator`,power:`simulator`,volumeDown:`simulator`,volumeUp:`simulator`,captureSnapshot:`simulator`,captureSnapshotWithoutActiveApp:`simulator`,captureSnapshotWithCustomActions:`runner`,captureScreenshot:`simulator`,findText:`runner`,querySelector:`runner`,readTextAtPoint:`runner`,tapPoint:`runner`,tapRef:`runner`,tapElementSelector:`runner`,fillPoint:`runner`,fillRef:`runner`,longPressPoint:`runner`,hoverPoint:`runner`,hoverRef:`runner`,focusPoint:`runner`,typeText:`runner`,scrollDirection:`runner`,performGesturePlan:`runner`,performMultiTouchGesturePlan:`runner`,performTargetAuthoredDrag:`runner`,performDirectionalFlingPlan:`runner`,gestureViewport:`runner`,setViewport:`runner`,back:`runner`,home:`runner`,setOrientation:`runner`,appSwitcher:`runner`,actionButton:`runner`,tvRemote:`runner`,keyboardDismiss:`runner`,keyboardEnter:`runner`,keyboardStatus:`runner`,triggerAppEvent:`runner`,readAlert:`runner`,awaitAlert:`runner`,acceptAlert:`runner`,dismissAlert:`runner`,perfFrames:`runner`,perfMemorySample:`runner`,perfMemorySnapshot:`runner`,perfNativeCaptureStart:`runner`,perfNativeCaptureReattach:`runner`,perfNativeCaptureCleanup:`runner`,perfProfileReport:`runner`,screenRecordingStart:`runner`,screenRecordingReattach:`runner`,screenRecordingCleanup:`runner`});function mi(e){return e===void 0?`possible`:e.some(e=>pi[e]===`runner`)?`required`:`none`}function hi(e){let{waitMs:t,signal:n,stop:r,cancelled:i}=e;return new Promise((e,a)=>{let o=()=>l(()=>a(i())),s=()=>l(e),c=setTimeout(()=>l(e),t);function l(e){clearTimeout(c),n?.removeEventListener(`abort`,o),r?.removeEventListener(`abort`,s),e()}n?.addEventListener(`abort`,o,{once:!0}),r?.addEventListener(`abort`,s,{once:!0}),n?.aborted?o():r?.aborted&&s()})}function gi(e){let t=e.now??Date.now,n=e.waitGrant??`every-caller`,r=new Map,i=(n,i)=>{let a={status:`pending`,value:void 0,error:void 0,settledAtMs:t(),waitSpent:!1,controller:new AbortController,settled:void 0},o=()=>{};a.settled=new Promise(e=>{o=e}),r.set(n,a);let s=(i,s)=>{a.status=i,i===`ready`?a.value=s:a.error=s,a.settledAtMs=t(),(i===`ready`||e.retryAfterMs===void 0)&&r.get(n)===a&&r.delete(n),o()};try{i(a.controller.signal).then(e=>s(`ready`,e),e=>s(`failed`,e))}catch(e){s(`failed`,e)}return a},a=(n,a)=>{let o=r.get(n);if(!o)return i(n,a);if(o.status!==`failed`)return o;let s=t()-o.settledAtMs;return e.retryAfterMs===void 0||s>=e.retryAfterMs?i(n,a):o};return{value:async(t,r)=>{let i=a(t,r.start);if(i.status===`pending`&&(n===`every-caller`||!i.waitSpent)){i.waitSpent=!0;let t=new AbortController,n=r.wait(e.waitMs,t.signal);n.catch(()=>{});try{await Promise.race([i.settled,n])}finally{t.abort()}}if(i.status===`ready`)return i.value;throw i.status===`failed`?i.error:r.pending()},close:()=>{let e=[...r.values()];r.clear();for(let t of e)t.controller.abort()}}}async function _i(e,t){let n=await Qt(`ps`,[`-p`,String(e),`-o`,`lstart=`],{allowFailure:!0,signal:t.signal,timeoutMs:t.timeoutMs});return n.exitCode===0&&n.stdout.trim()||null}const vi=3e3,yi=`simulator-target-discovery-pending`,bi=`simulator-target-unavailable`;function xi(){let e=new Map,t=new Map,n=gi({waitMs:1500});return async(r,i,a,o)=>{a.throwIfAborted();let s=`${r.id}:${i}`,c=e.get(s);if(c&&o!==`refresh`){let e=await _i(c.pid,{signal:a,timeoutMs:vi});if(a.throwIfAborted(),e===c.processStartTime)return c}return e.delete(s),await n.value(s,{start:async()=>{let n=await Ti(r,i,t);return e.set(s,n),n},wait:(e,t)=>hi({waitMs:e,signal:a,stop:t,cancelled:()=>Si(a)}),pending:()=>P(yi,r,i)})}}function Si(e){return n({readinessPhase:`target-discovery`},e.reason)}function Ci(e){return e instanceof t&&e.details?.reason===yi}function wi(e){return e instanceof t&&e.details?.reason===bi}async function Ti(e,t,n){let r=Date.now()+15e3,[i,a]=await Promise.allSettled([sn(e,[`spawn`,e.id,`launchctl`,`list`],{allowFailure:!0,timeoutMs:Oi(r)}),Ei(e,n,r)]);if(i.status===`rejected`)throw i.reason;if(a.status===`rejected`)throw a.reason;let o=i.value,s=a.value;if(o.exitCode!==0)throw P(`simulator-target-probe-failed`,e,t);let c=Di(o.stdout,t);if(!c)throw P(bi,e,t);let l=await _i(c.pid,{timeoutMs:Math.min(vi,Oi(r))});if(!l)throw P(`simulator-target-identity-unavailable`,e,t);return Object.freeze({simulator:cn(e),runtime:s,pid:c.pid,generation:`${c.pid}:${c.label}:${l}`,targetId:`${e.id}:${t}`,processStartTime:l})}async function Ei(e,t,n){let r=t.get(e.id);if(r)return await r;let i=sn(e,[`list`,`devices`,`-j`],{allowFailure:!0,timeoutMs:Oi(n)}).then(t=>{if(t.exitCode!==0)throw P(`simulator-runtime-probe-failed`,e,``);let n=Object.entries(rn(t.stdout)).find(([,t])=>t.some(t=>t.udid===e.id))?.[0];if(!n)throw P(`simulator-runtime-unavailable`,e,``);return n});t.set(e.id,i);try{return await i}catch(n){throw t.delete(e.id),n}}function Di(e,t){for(let n of e.split(`
|
|
4
|
-
`)){let[e,,r]=n.trim().split(/\s+/);if(!e||!r||!r.startsWith(`UIKitApplication:${t}[`))continue;let i=Number(e);if(Number.isSafeInteger(i)&&i>0)return{pid:i,label:r}}}function Oi(e){return Math.max(1,e-Date.now())}function P(e,n,r){return new t(`COMMAND_FAILED`,`Unable to resolve the running iOS Simulator app (${e}).`,{reason:e,deviceId:n.id,appBundleId:r})}function ki(e){return e?.observation===`unobservable`&&e.proof===`no-running-process`}const Ai=new Map([[`application-element-missing`,5e3],[`application-server-unavailable`,5e3],[`foreground-owner-unverified`,1e3],[`foreground-owner-changed`,1e3]]);function F(e){return e.platform===`apple`&&e.appleOs===`ios`&&e.kind===`simulator`}function ji(e){let t=ve(be({depth:1,interactiveOnly:!0}));return Object.freeze({awaitObservable:async(n,r,i)=>{if(!F(n))return{observation:`not-eligible`};let a;for(;;){let o=await Ni(e.resolveTarget,n,r,i);if(`verdict`in o)return o.verdict;let{target:s}=o;if(e.isBridgeDisabled(s))return h({level:`debug`,phase:`ios_launch_observation_skipped`,data:{reason:`circuit-disabled`,deviceId:n.id,generation:s.generation}}),Mi({source:`circuit`});let c=await e.source.acquire({target:s,hint:t,signal:i});if(c.stage!==`failed`)return{observation:`observable`};i.throwIfAborted();let{kind:l,code:u}=c.failure,d=Ai.get(u);if(d===void 0)return Mi({source:`bridge`,kind:l,code:u});let f=e.clock.now();if(a=Math.min(a??1/0,f+d),f>=a)return{observation:`unobservable`,proof:`launch-transition`};await e.clock.sleep(Math.min(150,a-f),i)}}})}function Mi(e){return{observation:`probe-failed`,failure:e}}async function Ni(e,t,n,r){for(;;)try{return{target:await e(t,n,r)}}catch(e){if(r.throwIfAborted(),Ci(e))continue;if(wi(e))return{verdict:{observation:`unobservable`,proof:`no-running-process`}};let{code:t,details:n}=i(e),a=n?.reason;return{verdict:Mi(typeof a==`string`?{source:`target`,code:t,reason:a}:{source:`target`,code:t})}}}function Pi(e,t,n){let r=n&&F(e),i=r?mi(t.execution.plannedOperations):void 0,a=g(e)&&t.surface===`app`&&t.positionals.length>0&&!!t.appBundleId&&i!==`none`;return{...i?{runnerDemand:i}:{},shouldPrewarmRunner:a,awaitPrewarmAfterOpen:t.relaunch&&!r}}function Fi(e,t,n,r){r.runnerDemand===`none`&&e.appleApplications.releaseSpeculativeRunner(t.device,n.execution).catch(()=>{})}async function Ii(e,n,r,i,a,o){let s=Date.now(),c=async()=>await Ui(n,r,i,a.observation),l=await c(),u,d,f=a.answerConfirmation,p=f&&l?.observation!==`observable`?await Li(f,a.redispatchLaunchUrl,c,l):void 0;if(p&&(o.runnerDemand=`required`,u=p.report,d=p.probeFailure,l=p.observed,p.unanswered))throw new t(`COMMAND_FAILED`,`The Simulator has not completed the launch URL for ${r.appBundleId}.`,{reason:`launch_confirmation_unanswered`,appBundleId:r.appBundleId,hint:`iOS may still be holding an "Open in" prompt, or the answer died with the runner session that raised it. Inspect the current alert before deciding on another action.`});if(i&&l?.observation!==`observable`&&await e.clock.sleep(300,n.signal),l&&(o.postOpenObservation=l.observation,l.observation===`probe-failed`&&(o.postOpenObservationFailure=l.failure)),o.postOpenSettleDurationMs=Math.max(0,Date.now()-s),u)return u;if(d)return{launchConfirmationProbeFailure:d}}async function Li(e,t,n,r){let i={observed:r,acceptAttempted:!1,confirmationStillPresent:!1};for(let r=0;r<2;r+=1){i=await Ri(e,n,i);let a=r===1;if(i.confirmationStillPresent||a||!Vi(i)||!t)break;await t()}return{observed:i.observed,report:i.report,probeFailure:i.probeFailure,unanswered:Vi(i)||i.confirmationStillPresent}}async function Ri(e,t,n){let r=await e(),i=r.outcome===`unanswered`&&r.reason===`alert-still-present`,a=n.acceptAttempted||Hi(r),o=Bi(n,r);return a?{observed:await t(),...o,acceptAttempted:a,confirmationStillPresent:i}:{observed:n.observed,...o,acceptAttempted:a,confirmationStillPresent:i}}function zi(e){switch(e.outcome){case`accepted`:return{seen:{launchConfirmation:`accepted`}};case`absent`:return{};case`unreadable`:return e.step===`url-owner`?{seen:{launchConfirmation:`unanswered`,launchConfirmationReason:`url-owner-unresolved`}}:{probeFailure:e.step};case`unanswered`:return e.reason===`alert-still-present`?{}:{seen:{launchConfirmation:`unanswered`,launchConfirmationReason:e.reason}}}}function Bi(e,t){let n=zi(t);return`seen`in n?{report:n.seen,probeFailure:void 0}:`probeFailure`in n?{report:void 0,probeFailure:n.probeFailure}:{report:e.report,probeFailure:void 0}}function Vi(e){return e.acceptAttempted&&ki(e.observed)}function Hi(e){return e.outcome===`accepted`||e.outcome===`unanswered`&&e.reason===`alert-still-present`||e.outcome===`unreadable`&&e.step===`alert-accept`}async function Ui(e,t,n,r){if(!(!n||!F(e.device))&&!(!r||!t.appBundleId))return await r.awaitObservable(e.device,t.appBundleId,e.signal)}let Wi;const Gi=()=>Wi??=import(`./launch-confirmation.js`);let Ki;const qi=()=>Ki??=import(`./expo-dev-client-launch.js`);function Ji(e){let t=t=>st({device:t,signal:e.signal,resolveInteractor:e.host.localInteractors.resolve}),n=e.device,r=t(n),i=e=>{n=e,r=t(e)};return Object.freeze({resolveOpenTarget:async t=>await e.host.appleApplications.resolveOpenTarget(n,t),prepareApplicationOpen:async t=>{let r=await N(e.host,n,e.signal,{deadlineAtMs:t.execution.startupDeadlineAtMs,onColdBootStart:t.prewarmRunnerOnColdBoot?()=>{e.host.appleApplications.prewarmRunnerCache(n,t.execution,e.signal).catch(()=>{})}:void 0});i(r)},openApplication:async t=>await Yi(e.host,r,t,e.observation),applyRuntimeHints:async t=>await e.host.appleApplications.applyRuntimeHints(n,t),clearRuntimeHints:async t=>await e.host.appleApplications.clearRuntimeHints(n,t),closeApplication:async t=>{t.ensureReady&&i(await N(e.host,n,e.signal)),await ca(e.host,r,t)},finalizeApplicationClose:async t=>await la(e.host,n,e.signal,t),prepareAppleRunner:async t=>{let r=await ua(e.host,n,e.signal,t);return i(r.readied),r.prepared},configureProviderPortReverse:ga})}async function Yi(e,t,n,r){let i={},a=I(t.device),o=da(e,t,n,i),s=Pi(t.device,n,a);s.runnerDemand&&(i.runnerDemand=s.runnerDemand),Fi(e,t,n,s);let{shouldPrewarmRunner:c}=s,l=sa(t.device,n,a);a&&c&&!n.prewarmRunnerBeforeOpen&&o.schedule();try{await Xi(e,t,n,a,l,i);let u=await Zi(t,n,a,i),d=pa(t.device,u?{...n,runtimeLaunchUrl:u}:n,a);await Qi(o,c,n.prewarmRunnerBeforeOpen);let f=o.wasAwaited();await $i(t,n,d,a,i),await ia(o,c,s.awaitPrewarmAfterOpen),await aa(e,t,n,a,f,l);let p=await Ii(e,t,n,a,{observation:r,answerConfirmation:na(t,n,d),redispatchLaunchUrl:ra(t,n,d)},i);return{appBundleId:n.appBundleId,timing:i,...p??{}}}catch(n){throw l&&await e.appleApplications.stopRunnerSession(t.device.id).catch(()=>{}),n}}async function Xi(e,t,n,r,i,a){if(!oa(n,r)||!n.target)return;let o=Date.now();ce(t.device.platform)&&!r&&!i&&await e.appleApplications.stopRunnerSession(t.device.id),await ct({device:t.device,interactor:await t.resolveInteractor(n.execution,n.appBundleId),positionals:[n.appBundleId??n.target]}),r&&await e.clock.sleep(300,t.signal),a.relaunchCloseDurationMs=L(o)}async function Zi(e,n,r,i){if(!Ee(n.runtimeHints))return;let a=Date.now(),o=r?await(await qi()).resolveExpoDevClientLaunchUrl(e.device,n):void 0;if(!o){if(!n.applyRuntimeHints)throw new t(`COMMAND_FAILED`,`Runtime hint operation was not admitted for this open.`,{reason:`runtime-hints-operation-missing`});await n.applyRuntimeHints({appId:n.appBundleId,values:n.runtimeHints})}return i.runtimeHintsDurationMs=L(a),o}async function Qi(e,t,n){!t||!n||(e.schedule(!0),await e.wait())}async function $i(e,t,n,r,i){let a=Date.now();await lt({device:e.device,interactor:await e.resolveInteractor(t.execution,t.appBundleId),positionals:n.positionals,appBundleId:t.appBundleId,execution:t.execution,...r&&t.relaunch&&!t.execution.clearAppState?{terminateRunningApp:!0}:{}}),i.openDispatchDurationMs=L(a),await ea(e,t,n.followUpUrl,i)}async function ea(e,t,n,r){if(!n){r.launchUrlDurationMs=0;return}let i=Date.now();await ta(e,t,n),r.launchUrlDurationMs=L(i)}async function ta(e,t,n){let r={...t.execution,clearAppState:void 0,launchConsole:void 0,launchArgs:void 0};await lt({device:e.device,interactor:await e.resolveInteractor(r,t.appBundleId),positionals:[n],appBundleId:t.appBundleId,execution:r})}function na(e,t,{confirmation:n}){if(n)return async()=>{let{answerSimulatorLaunchConfirmation:r}=await Gi();return await r(e.device,n,e.resolveInteractor(t.execution,n.appBundleId),e.signal)}}function ra(e,t,{confirmation:n}){if(n)return async()=>{await ta(e,t,n.url)}}async function ia(e,t,n){t&&!e.wasScheduled()&&e.schedule(),n?await e.wait():e.recordUnawaited()}async function aa(e,t,n,r,i,a){!g(t.device)||!r&&!a||!n.relaunch&&!i||r&&!i&&!await e.appleApplications.hasLiveRunnerSession(t.device,n.execution)||await e.appleApplications.notifyRunnerAppRelaunched(t.device,n.execution,t.signal)}function oa(e,t){return!!(e.relaunch&&e.target)&&!(t&&!e.execution.clearAppState)}function sa(e,t,n){return e.kind===`device`&&e.appleOs===`ios`&&oa(t,n)}async function ca(e,t,n){ce(t.device.platform)&&!I(t.device)&&await e.appleApplications.stopRunnerSession(t.device.id),await ct({device:t.device,interactor:await t.resolveInteractor(n.execution,n.appBundleId),positionals:n.positionals}),I(t.device)&&await e.clock.sleep(300,t.signal)}async function la(e,t,n,r){r.daemonShutdown||await e.appleApplications.releaseRunnerOnClose(t.id,{retain:r.retainRunner}),await e.appleApplications.dismissCloseAlerts(t,r).catch(()=>{});let i=r.shutdownTarget&&I(t)?await e.deviceShutdown.apple.shutdownTarget(t,n):void 0;return i===void 0?{}:{shutdown:i}}async function ua(e,t,n,r){let i=Date.now()+r.timeoutMs,a=performance.now();return await ne(`prepare_apple_runner`,async()=>{let o=await N(e,t,n,{deadlineAtMs:i}),s=Math.max(1,i-Date.now());return h({phase:`prepare_apple_runner`,durationMs:performance.now()-a,data:{event:`runner_start`,timeoutMs:r.timeoutMs,remainingMs:i-Date.now()}}),{readied:o,prepared:await e.appleApplications.prepareRunner(o,{...r,timeoutMs:s},n)}},()=>({timeoutMs:r.timeoutMs,remainingMs:i-Date.now()}),`readiness_start`)}function da(e,t,n,r){let i,a=!1,o=fa(t.device,n)?{healthCheck:!1}:void 0;return{schedule:(a=!1)=>{i||=(r.runnerPrewarmKind=`session`,r.runnerPrewarmScheduled=!0,o?e.appleApplications.prewarmRunnerSession(t.device,n.execution,t.signal,a,o):e.appleApplications.prewarmRunnerSession(t.device,n.execution,t.signal,a))},wait:async()=>{if(!i||a)return;a=!0;let e=Date.now();await i,r.runnerPrewarmWaited=!0,r.runnerPrewarmDurationMs=L(e)},wasAwaited:()=>a,wasScheduled:()=>i!==void 0,recordUnawaited:()=>{i&&!a&&(r.runnerPrewarmWaited=!1)}}}function fa(e,t){return e.kind===`device`&&e.appleOs===`ios`&&!t.hasExistingSession&&!t.relaunch&&!t.prewarmRunnerBeforeOpen}function pa(e,t,n){let r=t.runtimeLaunchUrl?.trim(),i=t.positionals.length===1?t.positionals[0]?.trim():void 0;if(!r||!i||u(i))return{positionals:t.positionals};let a=ma(e,t.appBundleId,r),o=a?{confirmation:a}:{};return n&&!ha(t)?{positionals:[i,r],...o}:{positionals:t.positionals,followUpUrl:r,...o}}function ma(e,t,n){if(e.appleOs===`ios`&&e.kind===`simulator`&&!(t===void 0||c(n)))return{url:n,appBundleId:t}}function ha(e){return e.execution.clearAppState===!0||!!e.execution.launchConsole?.trim()||!!e.execution.launchArgs?.length}function I(e){return g(e)&&e.kind===`simulator`}function L(e){return Math.max(0,Date.now()-e)}async function ga(){throw new t(`UNSUPPORTED_OPERATION`,`This lifecycle operation is unavailable for Apple.`)}const _a=Object.freeze({available:!0}),va=Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`}),ya=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Push notifications are supported on Apple simulators only.`}),ba=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),xa=Object.freeze({available:!1,reason:`unsupported-device-kind`});function Sa(e){let t=ja(e);return Object.freeze({deployApp:t,materializeAppSource:t,deployMaterializedApp:t,sendPushNotification:Ma(e),uninstallApp:t})}function Ca(e){let{host:t,device:n,signal:r}=e,i=Sa(n);return Object.freeze({...i.deployApp.available?{deployApp:async e=>await wa(t,n,e,r),materializeAppSource:async e=>await t.appleDeployment.prepareArtifact(e,{signal:r}),deployMaterializedApp:async e=>await Ea(t,n,e,r),uninstallApp:async e=>await Ta(t,n,e,r)}:{},...i.sendPushNotification.available?{sendPushNotification:async e=>(await ka(t,n,e,r),{})}:{}})}async function wa(e,t,n,r){if(n.replaceExisting)return await e.appleDeployment.withInvalidatedAppResolutionCache(t,async()=>{let i=await e.appleDeployment.resolveAppBundleId(t,n.app);await Oa(e,t,i,r);let a=await e.appleDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{appIdentifierHint:n.app,signal:r});try{return await Da(e,t,a.installablePath,r),{bundleId:i,launchTarget:i}}finally{await a.cleanup()}});let i=await e.appleDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{appIdentifierHint:n.app,signal:r});try{return await Ea(e,t,{artifact:i},r)}finally{await i.cleanup()}}async function Ta(e,n,r,i){return await e.appleDeployment.withInvalidatedAppResolutionCache(n,async()=>{await N(e,n,i);let a;try{a=await e.appleDeployment.resolveAppBundleId(n,r.app,{installedOnly:!0})}catch(e){if(e instanceof t&&e.code===`APP_NOT_INSTALLED`&&r.app.trim().includes(`.`))return{wasInstalled:!1};throw e}return await Oa(e,n,a,i),{wasInstalled:!0,bundleId:a}})}async function Ea(e,t,n,r){return await Da(e,t,n.artifact.installablePath,r),{...n.artifact.bundleId?{bundleId:n.artifact.bundleId}:{},...n.artifact.appName?{appName:n.artifact.appName}:{},...n.artifact.bundleId?{launchTarget:n.artifact.bundleId}:{}}}async function Da(e,t,n,r){await N(e,t,r),await Aa(e,t.kind===`simulator`?{tool:`simctl`,args:x(t,[`install`,t.id,n])}:{tool:`devicectl`,args:[`device`,`install`,`app`,`--device`,t.id,n],timeoutMs:Yt},r,`Apple app install failed`)}async function Oa(e,t,n,r){await N(e,t,r),await Aa(e,t.kind===`simulator`?{tool:`simctl`,args:x(t,[`uninstall`,t.id,n])}:{tool:`devicectl`,args:[`device`,`uninstall`,`app`,`--device`,t.id,n]},r,`Apple app uninstall failed for ${n}`,{tolerate:e=>tn(`${e.stdout}\n${e.stderr}`.toLowerCase())})}async function ka(e,n,r,i){if(n.kind!==`simulator`)throw new t(`UNSUPPORTED_OPERATION`,`Apple push notifications require a simulator`);await N(e,n,i);let a=await e.temporaryFiles.create({prefix:`agent-device-ios-push-`,suffix:`.apns`});try{await a.writeText(`${JSON.stringify(r.payload)}\n`),await Aa(e,{tool:`simctl`,args:x(n,[`push`,n.id,r.appId,a.path])},i,`Apple push notification failed`)}finally{await a[Symbol.asyncDispose]()}}async function Aa(e,t,n,r,i){let a=await e.appleTools.run({...t,allowFailure:!0},n);return i?.tolerate?.(a)?a:p(a,r,e=>({cmd:`xcrun`,args:[t.tool,...t.args],...t.tool===`devicectl`?{hint:en(e.stdout,e.stderr)??`Ensure the iOS device is unlocked, trusted, and available in Xcode > Devices, then retry.`}:{}}))}function ja(e){return Na(e)?e.kind!==`simulator`&&e.kind!==`device`?xa:e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?va:_a:ba}function Ma(e){return Na(e)?e.kind===`simulator`?_a:ya:ba}function Na(e){return g(e)&&e.appleOs!==`watchos`}const R=Object.freeze({available:!0}),Pa=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`back is supported on Apple simulators and physical devices.`}),Fa=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function Ia(e){return e.kind!==`simulator`&&e.kind!==`device`?Pa:_(e)===`watchos`?Fa:R}const La=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`home is supported on Apple simulators and physical devices.`}),Ra=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),za=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`app-switcher is supported on Apple simulators and physical devices.`});function Ba(e,t){if(e.kind!==`simulator`&&e.kind!==`device`)return t;let n=_(e);return n===`macos`||n===`watchos`?Ra:R}function z(e){if(e.kind!==`simulator`&&e.kind!==`device`)return!1;let t=_(e);return t!==`tvos`&&t!==`macos`&&t!==`watchos`}const Va=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`orientation is supported on Apple simulators and physical devices.`}),Ha=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function Ua(e){return e.kind!==`simulator`&&e.kind!==`device`?Va:z(e)?R:Ha}const Wa=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`tv-remote is supported only on tvOS devices.`});function Ga(e){return(e.kind===`simulator`||e.kind===`device`)&&ae(e)?R:Wa}const B=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Ka=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`keyboard status/get is currently supported only on Android; use keyboard dismiss or enter on iOS`});function qa(e){return z(e)?Ka:B}function Ja(e){return z(e)?R:B}function Ya(e){return z(e)?R:B}const Xa=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`No Apple leaf carries this system button.`}),Za=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`action-button is supported on iPhone and iPad simulators and physical devices.`}),Qa=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`The Action Button is iPhone and iPad hardware; tvOS, macOS, watchOS and visionOS have no such control.`});function $a(e){return e.kind!==`simulator`&&e.kind!==`device`?Za:le(e)?R:Qa}const eo=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`hardware-button volume presses the iPhone/iPad volume key; this Apple leaf has none.`}),to=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`hardware-button volume is supported on physical iPhone and iPad; iOS Simulators refuse because XCUIDevice exposes no volume press there.`});function no(e){return le(e)?e.kind===`device`?R:to:eo}function ro(e){return Object.freeze({...Fe({back:Ia(e)}),...Ze({unsupported:Xa,home:Ba(e,La),appSwitcher:Ba(e,za),actionButton:$a(e),volumeUp:no(e),volumeDown:no(e)}),...tt({orientation:Ua(e)}),...it({tvRemote:Ga(e),buttonSupport:{supported:o(`apple`),unsupported:{available:!1,reason:`unsupported-platform-leaf`,hint:`This TV remote button is not supported on tvOS.`}}}),...et({unsupported:B,status:qa(e),dismiss:Ja(e),enter:Ya(e)})})}function io(e){let{host:t,device:n,signal:r,admitted:i}=e,a=Object.keys(ro(n));return dt({device:n,signal:r,resolveInteractor:t.localInteractors.resolve,facts:Object.fromEntries(a.map(e=>[e,i[e]]))})}const V=Object.freeze({available:!0}),ao=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`clipboard is supported on Apple simulators and the macOS host.`}),oo=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`settings is supported on Apple simulators and the macOS host.`}),so=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`settings is supported on Apple simulators and the macOS host, not on physical devices of this OS.`}),co=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:"Run `agent-device settings --help` for the settings each target serves."}),lo=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`The macOS host supports settings appearance and settings permission <grant|reset> <accessibility|screen-recording|input-monitoring>.`}),uo=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Select a booted iPhone or iPad simulator: this setting runs only there.`}),fo=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`clipboard is supported on Apple simulators and the macOS host, not on physical devices of this OS.`}),po=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function mo(e,t,n){if(e.kind!==`simulator`&&e.kind!==`device`)return t;let r=_(e);return r===`watchos`?po:e.kind===`simulator`||r===`macos`?V:n}function ho(e){return mo(e,ao,fo)}const go=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`trigger-app-event is supported on Apple simulators and physical devices.`}),_o=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`alert is supported on Apple simulators and physical devices.`}),vo=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`alert is supported on Apple simulators, the macOS host, and physical iOS devices.`});function yo(e){if(e.kind!==`simulator`&&e.kind!==`device`)return _o;let t=_(e);return t===`watchos`?po:e.kind===`simulator`||t===`ios`||t===`macos`?V:vo}function bo(e){return e.kind!==`simulator`&&e.kind!==`device`?go:_(e)===`watchos`?po:V}function xo(e){let t=ho(e);return t.available?fo:t}function So(e){let t=mo(e,oo,so);if(v(e))return ut({target:t,unsupported:lo,write:{appearance:V,permission:V}});let n=se(e)?V:uo;return ut({target:t,unsupported:co,write:{wifi:V,airplane:V,location:V,appearance:V,"clear-app-state":V,"reset-keychain":V,permission:V,"text-size":n,faceid:n,touchid:n},read:{"text-size":n}})}function Co(e){let t=ho(e),n=yo(e);return Object.freeze({...nt({unsupported:xo(e),read:t,write:t}),...ot({read:n,wait:n,accept:n,dismiss:n}),...at({triggerAppEvent:bo(e)}),...So(e)})}function wo(e){let{host:t,device:n,signal:r}=e;return dt({device:n,signal:r,resolveInteractor:t.localInteractors.resolve,facts:Co(n)})}const To=/Angle:\s*(-?\d+(?:[.,]\d+)?)\s*°/g;async function Eo(e,n={}){let r=[`devicectl`,`device`,`motion`,`hinge-angle`,`--device`,e.id,`--session-timeout`,`1`,`--timeout`,`5`],i=await $t(r,{allowFailure:!0,signal:n.signal,timeoutMs:Zt}),a=Do(i.stdout)??Do(i.stderr);if(a!==void 0)return a;throw new t(`COMMAND_FAILED`,`CoreDevice reported no hinge angle sample`,f(i,{cmd:`xcrun`,args:r,stdout:i.stdout,stderr:i.stderr,deviceId:e.id,reason:`fold-hinge-angle-no-sample`,hint:`'devicectl device motion hinge-angle' printed no sample, and foldable poses can be verified only through that stream. The stderr in the details names the cause, such as a devicectl without the subcommand or a device CoreDevice cannot reach.`}))}function Do(e){let t;for(let n of e.matchAll(To)){let e=Number.parseFloat(n[1].replace(`,`,`.`));Number.isFinite(e)&&(t=e)}return t}var H=class extends t{buildFailureKind;buildFailureCode;buildDetails;constructor(e,t,n=`native build ${e}: ${t}`,r={},i){super(`COMMAND_FAILED`,n,{...r,nativeBuildFailure:e,nativeBuildFailureCode:t,...e===`cancelled`?{reason:`request_canceled`}:{}},i),this.name=`NativeBuildError`,this.buildFailureKind=e,this.buildFailureCode=t,this.buildDetails=r}};function U(e,t,n={},r){return new H(e,t,void 0,n,r)}function Oo(e,t,n=Date.now){if(t?.aborted)throw U(`cancelled`,`abort-signal`);return{clock:ee.fromTimeoutMs(e,n()),now:n,signal:t}}function W(e,t){if(e.signal?.aborted)throw U(`cancelled`,`abort-signal`);let n=e.clock.remainingMs(e.now());if(n<=0)throw U(`timeout`,t);return Math.max(1,Math.floor(n))}function ko(e){return{run:e,readText:Ht,readBinary:Gt,writeText:Bt,ensureDirectory:qt,chmod:Kt,exists:Ut,rename:Vt,remove:Jt,acquireLock:Ao,processId:ie,cpuArch:te}}async function Ao(e,t){let n=ie(),r=t.deadline,i=ge({lockDirPath:e,owner:{pid:n,startTime:re(n),acquiredAtMs:Date.now()},timeoutMs:W(r,`cache-lock-deadline`),pollMs:100,description:t.description}),a=r.signal;if(!a)try{return await i}catch(e){throw jo(e,r)}let o=!1,s,c=new Promise((e,t)=>{s=()=>{o=!0,t(U(`cancelled`,`abort-signal`))},a.addEventListener(`abort`,s,{once:!0}),a.aborted&&s()});try{return await Promise.race([i,c])}catch(e){throw o&&i.then(e=>e().catch(()=>void 0),()=>void 0),jo(e,r)}finally{a.removeEventListener(`abort`,s)}}function jo(e,t){return t.clock.isExpired()&&!(e instanceof H&&e.buildFailureKind===`cancelled`)?U(`timeout`,`cache-lock-deadline`):e}async function Mo(e,t){let n=await Po(e,`xcodebuild`,[`-version`],t),r=await Po(e,`sw_vers`,[`-productVersion`],t),i=await Po(e,`sw_vers`,[`-buildVersion`],t),a=await No(e,t);if(a!==`arm64`&&a!==`x86_64`)throw U(`unsupported`,`simulator-architecture-unsupported`,{architecture:a});return{xcode:n,macosProductVersion:r,macosBuild:i,architecture:a}}async function No(e,t){let n=W(t,`host-arch-deadline`),r=t.signal,i,a,o=new Promise((e,t)=>{i=setTimeout(()=>t(U(`timeout`,`host-arch-deadline`)),n),i.unref?.(),a=()=>t(U(`cancelled`,`abort-signal`)),r?.addEventListener(`abort`,a,{once:!0})});try{return await Promise.race([e.cpuArch(),o])}finally{clearTimeout(i),a&&r?.removeEventListener(`abort`,a)}}async function Po(e,t,n,r){let i=await Fo(e,t,n,r);if(i.exitCode!==0)throw U(`unsupported`,`toolchain-probe-failed`,{command:t,exitCode:i.exitCode,stderr:i.stderr.slice(0,1024)});let a=(i.stdout||i.stderr).trim();if(!a)throw U(`unsupported`,`toolchain-probe-empty`,{command:t});return a}async function Fo(e,t,n,r){let i=[],a;for(let o=1;;o+=1){let s;try{s=Math.min(nn,W(r,`toolchain-probe-deadline`))}catch(e){throw a??e}i.push(s);try{return await Ro(e,t,n,r,s)}catch(e){if(a=Io(e,t,r,i),o>=2)throw a}}}function Io(e,t,n,i){if(r(e))throw U(`cancelled`,`abort-signal`,{},e);if(!m(e))throw e;if(n.signal?.aborted)throw U(`cancelled`,`abort-signal`);return Lo(t,i,e)}function Lo(e,t,n){let r=t.length;return U(`timeout`,`toolchain-probe-stalled`,{command:e,attemptTimeoutsMs:[...t],hint:`${e} did not answer within ${t[r-1]}ms on ${r} attempt(s). A toolchain probe that cannot answer is a host condition rather than a toolchain defect: run \`${e}\` by hand until it answers, then retry.`},n)}function Ro(e,t,n,r,i){return e.run(t,n,{allowFailure:!0,signal:r.signal,timeoutMs:i})}const zo=`manifest.json`;async function Bo(e){let{host:t,deadline:n,cacheRoot:r,binaryFilename:i}=e,a=mn(`sha256`).update(JSON.stringify(e.keyInputs)).digest(`hex`).slice(0,32),o=S.join(r,a);return await he({acquire:()=>t.acquireLock(S.join(r,`${a}.lock`),{deadline:n,description:e.lockDescription}),task:async()=>{let s=await Vo(t,o,i,a,n);if(s)return{path:s,cacheKey:a};W(n,`native-build-deadline`),t.exists(o)&&await t.remove(o),W(n,`native-build-deadline`),await t.ensureDirectory(r);let c=S.join(r,`.${a}.${t.processId()}.tmp`);W(n,`native-build-deadline`),await t.remove(c);try{W(n,`native-build-deadline`),await t.ensureDirectory(c);let r=S.join(c,i);await e.build(r),W(n,`native-build-deadline`),await t.chmod(r,493);let s=await Uo(t,r),l={...e.keyInputs,cacheKey:a,binarySha256:s};return await t.writeText(S.join(c,zo),`${JSON.stringify(l,null,2)}\n`),W(n,`native-build-deadline`),await t.rename(c,o),{path:S.join(o,i),cacheKey:a}}catch(e){throw await t.remove(c),e}}})}async function Vo(e,t,n,r,i){let a=S.join(t,n),o=S.join(t,zo);if(!(!e.exists(a)||!e.exists(o)))try{let t=JSON.parse(await e.readText(o));return t.cacheKey!==r||typeof t.binarySha256!=`string`?void 0:(W(i,`native-cache-hash-deadline`),await Uo(e,a)===t.binarySha256?a:void 0)}catch(e){if(Ho(e))throw e;return}}function Ho(e){return e instanceof H&&(e.buildFailureKind===`cancelled`||e.buildFailureKind===`timeout`)}async function Uo(e,t){return mn(`sha256`).update(await e.readBinary(t)).digest(`hex`)}async function Wo(e,t,n,r){let i=mn(`sha256`);for(let a of n){let n=S.join(t,a);if(W(r,`native-source-fingerprint-deadline`),!e.exists(n))throw U(`unsupported`,`native-source-missing`,{filePath:n});i.update(a),i.update(`\0`),i.update(await e.readBinary(n)),i.update(`\0`)}return i.digest(`hex`)}async function Go(e){let t=Math.min(e.budgetMs,W(e.deadline,`native-build-deadline`));try{return await e.host.run(`xcrun`,[...e.argv],{signal:e.deadline.signal,timeoutMs:t,allowFailure:!0})}catch(n){throw m(n)?U(`timeout`,`native-build-stalled`,{timeoutMs:t,hint:`The Simulator SDK toolchain did not answer within ${t}ms, which stopped the ${e.label} build before clang reported anything. Run \`xcrun --sdk iphonesimulator clang --version\` by hand until it answers, then retry.`},n):n}}const Ko=`Fold.m`,qo=3e4,Jo=nn+qo;async function Yo(e={}){let t=e.host??Xo(),n=Oo(Jo,e.signal);try{let r=e.sourceRoot??S.join(_e(),`apple`,`fold-helper`),i=await Wo(t,r,[Ko],n),a=await Mo(t,n);return await Bo({host:t,deadline:n,lockDescription:`iOS Simulator fold helper cache`,cacheRoot:e.cacheRoot??S.join(Wt(),`.agent-device`,`fold-helper`),binaryFilename:`fold-helper`,keyInputs:{schemaVersion:1,sourceHash:i,toolchain:a,compileArgv:Zo({sourceRoot:``,outputPath:``})},build:e=>Qo(t,n,r,e)})}catch(e){throw $o(e)}}function Xo(){return ko(Qt)}function Zo(e){return[`--sdk`,`iphonesimulator`,`clang`,`-mios-simulator-version-min=15.0`,`-fobjc-arc`,`-Wall`,`-Wextra`,`-framework`,`Foundation`,`-framework`,`IOKit`,S.join(e.sourceRoot,Ko),`-o`,e.outputPath]}async function Qo(e,t,n,r){let i=await Go({host:e,deadline:t,argv:Zo({sourceRoot:n,outputPath:r}),budgetMs:qo,label:`fold helper`});if(i.exitCode!==0||!e.exists(r))throw es(f(i))}function $o(e){return!(e instanceof H)||e.buildFailureKind===`cancelled`?e:es({...e.buildDetails,cause:e.buildFailureCode},e)}function es(e,n){return new t(`COMMAND_FAILED`,`Unable to build the simulator fold helper`,{hint:`Select an Xcode with the iOS simulator SDK and foldable HID support using DEVELOPER_DIR.`,...e,reason:`fold-helper-build-failed`},n)}async function ts(e,n,r){r?.throwIfAborted();let i=await Yo({signal:r});r?.throwIfAborted();let a=typeof n==`string`?0:n.at(-1).atMs,o=typeof n==`string`?n:JSON.stringify(n),s=await sn(e,[`spawn`,e.id,i.path,o],{signal:r,timeoutMs:a+1e4,kill:{signal:`SIGTERM`,graceMs:1e3},allowFailure:!0});if(s.exitCode!==0)throw new t(`COMMAND_FAILED`,`Unable to send the simulator hinge pose`,f(s,{reason:`fold-hid-dispatch-failed`,deviceId:e.id}))}async function ns(e,t,n={}){n.signal?.throwIfAborted(),ln(e,`fold`);let r=t,i=r.keyframes?.at(-1)?.angle,o=r.pose??a(i);as(e,await un(e,{signal:n.signal})),await ts(e,r.keyframes??o,n.signal),h({level:`info`,phase:`apple_fold_pose_dispatched`,data:{deviceId:e.id,pose:o}});let s=await os(e,o,n.signal,i),c=await hs(e,n.signal);return{pose:a(s),hingeAngleDegrees:s,...c?{screen:gs(c)}:{}}}function rs(e){return e instanceof t&&e.details?.reason===`fold-hinge-angle-no-sample`}async function is(e,n,r,i,a){let o=await hs(e,r);return new t(`COMMAND_FAILED`,`${e.name} received the ${n} pose request, but the first hinge-angle read returned no sample to verify it`,{deviceId:e.id,requestedPose:n,...i===void 0?{}:{targetAngleDegrees:i},reason:`fold-pose-dispatched-unverified`,...o?{screen:gs(o)}:{},...a instanceof t?{hingeReadFailure:a.details}:{},hint:`The pose request was sent and the device may have followed it, but the first hinge-angle read returned no sample, so fold cannot confirm it. Take a screenshot or snapshot to see which panel is lit; hingeReadFailure names why the read failed.`},a)}function as(e,n){if(n.unresolved)throw new t(`COMMAND_FAILED`,`CoreDevice reported no display table for this simulator`,{deviceId:e.id,hint:`fold needs 'devicectl device info displays' to tell a foldable from a single-panel simulator; update Xcode to a version that ships the display-information feature.`});if(!n.multiScreen)throw new t(`UNSUPPORTED_OPERATION`,`${e.name} is not a foldable simulator: fold requires more than one integrated panel`,{deviceId:e.id,reason:`single-panel-device`,hint:`fold sets the hinge angle of a foldable simulator such as iPhone Duo; this simulator reports one integrated panel, so it has no hinge to pose.`})}async function os(e,t,n,r){let i,a;for(let o=1;o<=4;o+=1){n?.throwIfAborted(),a=i;try{i=await Eo(e,{signal:n})}catch(a){throw i!==void 0||!rs(a)?a:await is(e,t,n,r,a)}if(ss(i,a,t,r))return i}throw us(e,t,i,a,r)}function ss(e,t,n,r){return r===void 0?a(e)===n?n!==`half-open`||t!==void 0&&ds(e,t):!1:cs(e,t,r)}function cs(e,t,n){return ls(e,n)?n===0||n===180||t!==void 0&&ls(t,n)&&Math.abs(e-t)<=.5:!1}function ls(e,t){return t===void 0||e!==void 0&&Math.abs(e-t)<=.5}function us(e,n,r,i,o){return ls(r,o)?o!==void 0&&r!==void 0?ms(e,a(r),r,i):r!==void 0&&n===`half-open`&&a(r)===n?ms(e,n,r,i):ps(e,n,r):new t(`COMMAND_FAILED`,`The hinge did not reach the final keyframe angle`,{reason:`fold-angle-unverified`,targetAngleDegrees:o,hingeAngleDegrees:r,deviceId:e.id})}function ds(e,t){return a(e)===`half-open`&&a(t)===`half-open`&&Math.abs(e-t)<=.5}function fs(e,t,n){return{deviceId:e.id,requestedPose:t,observedPose:n===void 0?void 0:a(n),hingeAngleDegrees:n}}function ps(e,n,r){return new t(`COMMAND_FAILED`,`${e.name} did not reach the ${n} pose: CoreDevice still reports a hinge angle of ${r}°`,{...fs(e,n,r),reason:`fold-pose-unverified`,hint:`The simulator HID command completed, but the hinge did not follow. Verify that the selected Xcode and simulator runtime support foldable HID control, then retry.`})}function ms(e,n,r,i){return new t(`COMMAND_FAILED`,`${e.name} was observed ${n} at ${r}° but did not settle: 4 hinge reads never held two consecutive angles within ${Xt}° of each other`,{...fs(e,n,r),reason:`fold-pose-unsettled`,...i===void 0?{}:{previousHingeAngleDegrees:i},hint:`The hinge reached the requested pose and was still moving when the read budget ended. Retry the fold, then read the angle directly with xcrun devicectl device motion hinge-angle --device <udid> --session-timeout 1 --timeout 5 to see whether the simulator holds the pose.`})}async function hs(e,t){let n=await un(e,{signal:t});if(!(n.unresolved||n.ambiguous))return n.activeDisplay}function gs(e){return{display:e.name,coordinateSpace:s,widthPt:Math.round(e.widthPx/e.pointScale),heightPt:Math.round(e.heightPx/e.pointScale)}}const _s=Object.freeze({available:!0}),vs=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`fold is supported on foldable iPhone simulators controlled through simulator HID; a physical device is folded by hand.`}),ys=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`fold poses the hinge of a foldable iPhone; tvOS, macOS, watchOS and visionOS simulators have no hinge.`});function bs(e){return{available:!1,reason:`unsupported-device-scope`,hint:`fold cannot resolve a simulator scoped to the set at "${e}": CoreDevice's display inventory and hinge-angle readback need a simulator in the default set, so the pose could not be verified. Run fold without --ios-simulator-device-set.`}}function xs(e){if(e.kind!==`simulator`)return vs;let t=_(e);return t!==`ios`&&t!==`ipados`?ys:e.simulatorSetPath?bs(e.simulatorSetPath):_s}function Ss(e){return jt({fold:xs(e)})}function Cs(e){let{device:t,signal:n}=e;return b(Ss(t).setFoldPose,()=>({setFoldPose:async e=>(n.throwIfAborted(),await ns(t,e,{signal:n}))}))}function ws(e,t,n){let r=$e({device:t.device,signal:t.signal,resolveInteractor:e.localInteractors.resolve}),i=async i=>{if(i.options?.observeOnly===!0)return await r.captureSnapshot(i);let a=v(t.device)?pe(i.options?.surface,t.appBackend):void 0;if(a)return await e.snapshot.captureSurface(t.device,{...i.options,surface:a},Qe(t.signal,i));if(!n)return await r.captureSnapshot(i);let o=Qe(t.signal,i);return await n.capture(t.device,i,o,async e=>await r.captureSnapshot(e))};return Object.freeze({captureSnapshot:i,captureSnapshotWithCustomActions:i,captureSnapshotWithoutActiveApp:i})}function Ts(e,t){return Object.freeze({findText:async n=>{let r=await Es(e,t,n);if(!r)return{found:!1};let i=await e.localInteractors.resolve(t.device,{...n.execution,...r});return i.findText?await i.findText(n.text,r):{found:!1}}})}async function Es(e,t,n){let r=n.options?.appBundleId;if(r===void 0||v(t.device)&&me(n.options?.surface,t.appBackend)===`macos-helper`)return;let i=n.signal?AbortSignal.any([t.signal,n.signal]):t.signal;if(i.throwIfAborted(),await Ds(e,t.device,n.execution))return{appBundleId:r,signal:i}}async function Ds(e,t,n){return!F(t)||await e.appleApplications.hasLiveRunnerSession(t,n??{})}function Os(e){return Object.freeze({querySelector:async t=>{let n=t.signal?AbortSignal.any([e.signal,t.signal]):e.signal;n.throwIfAborted();let r={...t.execution,signal:n},{queryAppleRunnerSelector:i}=await import(`./runner-selector-query.js`),a=await i(e.device,t.selector,t.options?.appBundleId,r),o=ks(a);return Object.freeze({found:a.found===!0,...o?{node:o}:{}})}})}function ks(e){let t=e.nodes;if(!Array.isArray(t))return;let n=t[0];if(!n||typeof n!=`object`)return;let r=l(n.rect);if(r)return Object.freeze({rect:r,hittable:n.hittable===!0})}const G=Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`The native macOS app backend never starts the XCTest runner, which this command needs. Unset AGENT_DEVICE_MACOS_APP_BACKEND to use XCTest.`});function As(e,t){return!v(e)||t!==`native`?{}:Object.freeze({screenRecordingStart:G,screenRecordingReattach:G,prepareAppleRunner:G,longPressPoint:G,...Fe({back:G}),...Re({unsupported:G})})}function js(e){let t,n=!1,r=async()=>(t??=import(`./host2.js`).then(e=>e.t).then(({createSnapshotSourceHost:t})=>import(`./adapter.js`).then(({createSimulatorSnapshotSource:n})=>n({host:t(e)}))),await t);return{acquire:async e=>n?{stage:`failed`,failure:{kind:`unsupported`,code:`source-closed`}}:await(await r()).acquire(e),close:async()=>{n=!0,t&&await(await t).close()}}}function Ms(e=Date.now){let t=new Map;return async(n,r)=>{if(n.kind!==`simulator`)return`absent`;let i=t.get(n.id);if(i!==void 0&&e()-i.at<1e3)return{kind:`present`,host:i.host};t.delete(n.id);let a=await Ns(n,r);return a!==`absent`&&a!==`unknown`&&t.set(n.id,{at:e(),host:a.host}),a}}async function Ns(e,t){let n=await Promise.all(Me.map(async e=>({host:e,pids:await Ps(e.processExecutable,t)}))),r=!1;for(let{host:i,pids:a}of n){if(a===`unknown`){r=!0;continue}for(let n of a){let a=await Fs(n,e.id,t);if(a===`unknown`)r=!0;else if(a)return{kind:`present`,host:i}}}return r?`unknown`:`absent`}async function Ps(e,t){let n=await Is(`pgrep`,[`-f`,e],t);return n===`unknown`?`unknown`:n.exitCode===1?[]:n.exitCode===0?n.stdout.split(`
|
|
5
|
-
`).map(e=>Number.parseInt(e.trim(),10)).filter(e=>Number.isSafeInteger(e)&&e>0):`unknown`}async function Fs(e,t,n){let r=await Is(`ps`,[`eww`,`-p`,String(e),`-o`,`command=`],n);return r===`unknown`||r.exitCode!==0?`unknown`:r.stdout.includes(`SIMULATOR_UDID=${t}`)?!0:!r.stdout.includes(`SIMULATOR_UDID=`)&&`unknown`}async function Is(e,t,n){try{let r=await Qt(e,t,{allowFailure:!0,timeoutMs:3e3,...n?{signal:n}:{}});return{exitCode:r.exitCode,stdout:r.stdout}}catch{return`unknown`}}const Ls=`system-surface-presented`,Rs=`system-surface-host-lingering`,zs=`window-coordinate-space-unresolved`;function Bs(e,n={}){let r=n.source??js(e.hostEnvironment),i=n.resolveTarget??xi(),a=n.systemSurfacePresent??Ms(),o=new Set,s=new Map,c=e=>(tc(e,s,o),o.has(nc(e))),l=ji({source:r,resolveTarget:i,clock:e.clock,isBridgeDisabled:c});return Object.freeze({awaitObservable:l.awaitObservable,shutdown:async()=>await r.close(),capture:async(n,s,l,u)=>{if(!Us(n,s))return await qs(n,s,u);let d=await a(n,l);if(d===`unknown`)return await K(n.id,s,u,Ys(n.id,s),q(s),`system-surface-probe-unavailable`,[ec()]);if(d!==`absent`)return await Ks(n,s,u,d.host.bundleId);let f;try{f=await Vs(e,i,n,s,l)}catch(e){return Hs(l,e),J(`target-resolution-failed`,n,void 0,e),await K(n.id,s,u,Ys(n.id,s),q(s),`target-resolution-failed`,[ec()])}if(c(f))return J(`circuit-disabled`,n,f.generation),await K(n.id,s,u,f,q(s),`circuit-disabled`);let p=q(s),m=await r.acquire({target:f,hint:ve(p),signal:l});if(m.stage===`failed`){if(m.failure.kind===`cancelled`)throw l.throwIfAborted(),new t(`COMMAND_FAILED`,`Simulator AX snapshot acquisition was cancelled.`,{reason:m.failure.code,...m.failure.details});let e=await $s(m.failure,f,n,s.options.appBundleId,l,i);return await Ws(s,u,f,e,p,m.failure,o)}try{return await ne(`ios.snapshot-source.present`,async()=>await e.snapshot.presentIosAcquisition(m,s.options),{producer:`simulator-ax-bridge`})}catch(e){return await Ws(s,u,f,{lineage:f,residue:[]},p,{kind:`malformed-tree`,code:`presentation-invariant`},o,e)}}})}async function Vs(e,t,n,r,i){let a=r.options.appBundleId;for(;;)try{return await t(n,a,i)}catch(t){if(!Ci(t))throw t;let i={requestId:r.execution?.requestId};if(await e.appleApplications.hasLiveRunnerSession(n,i))throw t}}function Hs(e,t){if(e.aborted)throw r(t)?t:e.reason}function Us(e,t){return e.platform===`apple`&&e.appleOs===`ios`&&e.kind===`simulator`&&!!t.options?.appBundleId&&t.options?.customActions!==!0&&t.options?.preferredBackend===void 0}async function Ws(e,t,n,r,i,a,o,s){return Gs(a)&&o.add(nc(n)),J(a.code,{id:n.simulator.udid},n.generation,s,a.details),await K(n.simulator.udid,e,t,r.lineage,i,a.code,r.residue)}function Gs(e){return e.kind!==`preparing`&&e.code!==zs}async function K(e,t,n,r,i,a,o=[]){return Js(e,await n(t),r,i,a,o)}async function Ks(e,t,n,r){let i=await n(t),a=i.systemSurface?Ls:Rs;return i.systemSurface||J(a,e,void 0,void 0,{detectedHost:r}),Js(e.id,i,Ys(e.id,t),q(t),a)}async function qs(e,t,n){let r=await n(t),i=r.systemSurface;return i?{...r,comparisonIdentity:Zs(Xs(e.id,i.bundleId),q(t),[])}:r}function Js(e,t,n,r,i,a=[]){let o=t.systemSurface;return{...t,comparisonIdentity:Zs(o?Xs(e,o.bundleId):n,r,[...o?[]:a,{kind:`fallback-source`,producer:`apple-runner`}]),warnings:[...t.warnings??[],Qs(i,n,o!==void 0)]}}function Ys(e,t){return{targetId:`${e}:${t.options.appBundleId}`}}function Xs(e,t){return{targetId:`${e}:${t}`}}function Zs(e,t,n){return Object.freeze({producer:`apple-runner`,intent:t.acquisitionIntent,lineage:Object.freeze({...e.targetId?{targetId:e.targetId}:{},...e.generation?{generation:e.generation}:{}}),presentationKey:ye(t),residue:Object.freeze([...n])})}function Qs(e,t,n){return e===Ls?`Simulator AX snapshot inapplicable (${e}); used XCTest to read the system surface presented over the app.`:e===Rs?`Simulator AX snapshot inapplicable (${e}); used XCTest, which read app content: the system surface host process was still running but no longer presenting.`:n?`Simulator AX snapshot unavailable (${e}); used XCTest, which read the system surface presented over the app.`:e===`bridge-preparation-pending`?`Simulator AX snapshot unavailable (${e}); used XCTest for this capture while the bridge is still being prepared.`:e===zs?`Simulator AX snapshot unavailable (${e}); used XCTest for this capture, which reports captured geometry in the app's own orientation space.`:`Simulator AX snapshot unavailable (${e}); used XCTest for ${t.generation?`this app generation`:`an unverified app generation`}.`}async function $s(e,t,n,r,i,a){if(e.kind!==`stale-target`)return{lineage:t,residue:[]};try{return{lineage:await a(n,r,i,`refresh`),residue:[]}}catch(e){return i.throwIfAborted(),J(`fallback-target-resolution-failed`,n,void 0,e),{lineage:{targetId:t.targetId},residue:[ec()]}}}function ec(){return{kind:`unknown-generation`,captureId:hn()}}function q(e){return be({raw:e.options?.raw,interactiveOnly:e.options?.interactiveOnly,depth:e.options?.depth,scope:e.options?.scope,customActions:e.options?.customActions,acquisitionIntent:e.options?.acquisitionIntent})}function tc(e,t,n){let r=t.get(e.targetId);r&&r!==e.generation&&n.delete(`${e.targetId}:${r}`),t.set(e.targetId,e.generation)}function nc(e){return`${e.targetId}:${e.generation}`}function J(e,t,n,r,i){h({level:`debug`,phase:`ios_snapshot_route_fallback`,data:{reason:e,deviceId:t.id,...n?{generation:n}:{},...r?{error:r instanceof Error?r.message:String(r)}:{},...i?{details:i}:{}}})}const Y=fe(`apple`),X=Object.freeze({available:!0}),Z=y(`unsupported-platform-leaf`),rc=y(`unsupported-platform-leaf`,`viewport resizes web targets only (--platform web). Apple screen geometry is fixed by the selected simulator or device type — open a different simulator to test another screen size.`),ic=y(`unsupported-platform-leaf`,`the stateless audio page probe is a web-session operation; Apple targets use the host capture.`),ac=y(`unsupported-device-backend`,`perf requires an Apple simulator, macOS device, or CoreDevice-backed physical Apple device.`),oc=y(`unsupported-device-kind`,`focus is supported on Apple simulators and physical devices.`),sc=y(`unsupported-platform-leaf`,`telephony simulates calls and SMS through the Android emulator console; Apple simulators and devices expose no host control that injects a call or text message.`),cc=y(`unsupported-platform-leaf`,`Apple appstate is unavailable here: the runner reads the session app's XCUIApplication state on iOS-family simulators and physical devices only, and the Apple target answers no sessionless foreground probe. The per-command answer is the targetActivation disclosure, which a capture carries when its command had to re-activate the session app (#2682).`);function lc(e){return!g(e)||e.appleOs===`watchos`?cc:e.kind===`simulator`||e.kind===`device`?X:cc}const uc=y(`unsupported-provider-mode`,`Headless boot is supported only for local Android emulators.`),dc=y(`unsupported-platform-leaf`,`watchOS has no XCUITest-driveable UI, so element text comes from the captured tree only.`),fc=y(`unsupported-device-kind`),pc=y(`unsupported-platform-leaf`,`watchOS open is not supported because XCUITest cannot drive watchOS UI.`),mc=y(`unsupported-platform-leaf`,`watchOS runner preparation is not supported because XCUITest cannot drive watchOS UI.`),hc=y(`unsupported-platform-leaf`,`watchOS close is not supported because XCUITest cannot drive watchOS UI.`),gc=y(`unsupported-device-kind`,`Runtime hints are supported only for local iOS-family simulators and Android devices.`),_c=Q(`open is supported only for Apple simulators and devices.`),vc=Q(`prepare is supported only for Apple simulators and devices.`),yc=Q(`close is supported only for Apple simulators and devices.`),bc=y(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),xc=y(`unsupported-device-kind`,`shutdown is supported only for Apple simulators and Android emulators.`),Sc=Q(`snapshot is supported only for Apple simulators and devices.`),Cc=y(`unsupported-platform-leaf`,`Re-run without --actions, or target an iOS simulator.`),wc=y(`unsupported-platform-leaf`,`screenshot is not supported on watchOS because XCUITest cannot drive watchOS UI.`),Tc=Q(`screenshot is supported only for Apple simulators and devices.`),Ec=y(`owner-capability-missing`,`Open the app under test before capturing its snapshot.`);function Q(e){return y(`unsupported-device-kind`,e)}function Dc(e){return!g(e)||e.appleOs===`watchos`?Z:e.kind===`simulator`?X:xc}function Oc(e){let t=kc(e),n=Ac(e),r=jc(e),i=Mc(e);return De({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:i,clearRuntimeHints:i,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:n,configureProviderPortReverse:bc})}function kc(e){return _(e)===`watchos`?pc:e.kind===`simulator`||e.kind===`device`?X:_c}function Ac(e){return _(e)===`watchos`?mc:e.kind===`simulator`||e.kind===`device`?X:vc}function jc(e){return _(e)===`watchos`?hc:e.kind===`simulator`||e.kind===`device`?X:yc}function Mc(e){return _(e)!==`watchos`&&g(e)&&e.kind===`simulator`?X:gc}function Nc(e){return e.appleOs===`watchos`?y(`unsupported-platform-leaf`,`watchOS app inventory is not supported.`):e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?y(`unsupported-device-backend`,`App inventory is available only on CoreDevice-backed physical iOS devices.`):X}function $(e){return e.kind===`simulator`||e.kind===`device`?X:oc}function Pc(e){let t=er(e),n=Bs(e),r,i=t=>v(t)?r??=fn(e.hostEnvironment.env):`xctest`,a=async n=>{let r=await t.inspectFacts(n),a=Sa(n),o=Ur(n),s=o.available?await e.screenRecording.apple.availability(n):void 0,c=o.available&&s?.available===!1?y(`unsupported-provider-mode`,s.hint):o,l=n.appleOs===`watchos`?Z:X,u=v(n)||n.appleOs===`watchos`?Z:X,d=Nc(n);return Object.freeze({device:r.device,operations:{...r.operations,...a,appState:lc(n),networkDump:X,screenRecordingStart:c,screenRecordingReattach:c,screenRecordingCleanup:c,...zc(n),...Le({capture:Rc(n)}),...Be({findText:Lc(n),querySelector:g(n)?$(n):Z}),...We({setViewport:rc}),...Ye({focus:$(n)}),...Cn(n),...Ve({type:$(n)}),...Ae({unsupported:Z,tap:$(n),longPress:$(n),fill:$(n),...g(n)?{tapElementSelector:$(n)}:{}}),...Xe({readTextAtPoint:Ic(n)}),...ro(n),...Ss(n),sendTelephonyEvent:sc,...Co(n),...Pe({capture:_n(n),query:ic}),...Ue(Fc(n)),ensureReady:l,bootTarget:u,bootTargetHeadless:uc,listApps:d,...Oc(n),shutdownTarget:Dc(n),...As(n,i(n))}})};return Object.freeze({owner:Y,ownsDevice:e=>e.platform===`apple`,inspectFacts:a,bind:async r=>{let o=await t.bind(r),s=await a(r.device),c=s.operations.screenRecordingStart,l=b(s.operations.appState,()=>gn(e,{device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),u=b(s.operations.querySelector,()=>Os({device:r.device,signal:r.scope.signal})),d={...l,...u,...o.operations,...Ca({host:e,device:r.device,signal:r.scope.signal}),networkDump:async t=>await ir(e,r.device,t,r.scope.signal),...b(c,()=>Wr({host:e,device:r.device,owner:Y,signal:r.scope.signal})),...b(s.operations.audioProbeStart,()=>yt({host:e.audioProbe.hostCapture,device:r.device,owner:Y})),...b(s.operations.perfFrames,()=>vn({resolveHost:()=>e.perf.apple,device:r.device,owner:Y})),...b(s.operations.captureSnapshot,()=>ws(e,{device:r.device,signal:r.scope.signal,appBackend:i(r.device)},n)),...b(s.operations.captureScreenshot,()=>He({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...b(s.operations.focusPoint,()=>rt({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...qe({device:r.device,signal:r.scope.signal,facts:s.operations,resolveInteractor:e.localInteractors.resolve}),...b(s.operations.scrollDirection,()=>Ke({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...b(s.operations.typeText,()=>Ie({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...b(s.operations.tapPoint,()=>je({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:s.operations,pause:async t=>await e.clock.sleep(t,r.scope.signal)})),...b(s.operations.readTextAtPoint,()=>Je({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...b(s.operations.findText,()=>Ts(e,{device:r.device,signal:r.scope.signal,appBackend:i(r.device)})),...io({host:e,device:r.device,signal:r.scope.signal,admitted:s.operations}),...wo({host:e,device:r.device,signal:r.scope.signal}),...Cs({device:r.device,signal:r.scope.signal}),...b(s.operations.ensureReady,()=>({ensureReady:async()=>await N(e,r.device,r.scope.signal)})),...b(s.operations.bootTarget,()=>({bootTarget:async t=>await N(e,r.device,r.scope.signal,{deadlineAtMs:t.deadlineAtMs})})),...b(s.operations.listApps,()=>({listApps:async e=>{r.scope.signal.throwIfAborted();let{listIosApps:t}=await import(`./app-resolution.js`).then(e=>e.t);return(await t(e.device,e.filter)).map(e=>({id:e.bundleId,name:e.name}))}})),...Te(Ji({host:e,device:r.device,signal:r.scope.signal,observation:n}),s.operations),...b(s.operations.shutdownTarget,()=>({shutdownTarget:async()=>await e.deviceShutdown.apple.shutdownTarget(r.device,r.scope.signal)}))};return Object.freeze({device:o.device,owner:Y,facts:s,operations:Object.freeze(d),[Symbol.asyncDispose]:async()=>await o[Symbol.asyncDispose]()})},shutdown:async()=>{await Promise.all([t.shutdown(),n.shutdown()])}})}function Fc(e){let t=e.iosPhysicalDeviceBackend!==`xctest`&&_(e)!==`watchos`?X:ac;return{frames:t,memorySample:t,memorySnapshot:t,nativeCapture:t,profileReport:t}}function Ic(e){return _(e)===`watchos`?dc:e.kind===`simulator`||e.kind===`device`?X:fc}function Lc(e){return _(e)===`watchos`?Sc:e.kind===`simulator`||e.kind===`device`?X:Sc}function Rc(e){return _(e)===`watchos`?wc:e.kind===`simulator`||e.kind===`device`?X:Tc}function zc(e){let t=Lc(e);return ze({capture:t,customActions:t.available&&g(e)&&e.kind===`simulator`?X:Cc,withoutActiveApp:g(e)?Ec:t})}export{ko as a,H as c,Pc as createApplePlatformRuntime,hi as d,Mo as i,_i as l,Go as n,Oo as o,Wo as r,W as s,Bo as t,gi as u};
|
|
1
|
+
import{E as e,H as t,Q as n,R as r,V as i,tt as a}from"./sdk-contracts.js";import{C as o,M as s,l as c}from"./tv-remote.js";import{a as l,b as u,i as d,v as f}from"./sdk-batch-runner.js";import{K as p,L as m,St as ee,T as h,Y as g,_t as _,j as te,q as ne,y as re}from"./sdk-io.js";import"./diagnostics.js";import{C as ie,T as v,U as ae,b as oe,j as se,p as ce,w as y,z as b}from"./sdk-device.js";import{bn as x,pn as le,vn as ue,xn as de,yn as S}from"./sdk-batch.js";import{i as fe,r as pe}from"./session.js";import{n as me,o as he}from"./file.js";import"./command.js";import{r as ge}from"./version.js";import"./retry.js";import{i as _e,n as ve,r as ye}from"./ios-snapshot-planning.js";import{i as be,n as xe}from"./durable-resource.js";import{n as Se}from"./screen-recording-runtime.js";import{t as Ce}from"./request.js";import{n as we,r as Te,t as Ee}from"./application-lifecycle-runtime.js";import{n as De,t as Oe}from"./async-lifecycle.js";import{i as ke,t as Ae}from"./touch-runtime.js";import{t as je}from"./ios-system-surface.js";import{r as Me}from"./gesture-admission.js";import{B as Ne,C as Pe,E as Fe,I as Ie,K as Le,M as Re,N as ze,O as Be,P as Ve,R as He,T as Ue,U as We,V as Ge,W as Ke,X as qe,Y as Je,Z as Ye,_ as Xe,j as Ze,k as Qe,l as $e,o as et,p as tt,q as nt,r as rt,v as it,x as at}from"./tv-remote-runtime.js";import{n as ot,o as st,s as ct,u as lt}from"./application-lifecycle-interaction.js";import{t as ut}from"./interactor-operation-catalog.js";import{a as dt,i as ft,n as pt,o as mt,r as ht,s as gt,t as _t}from"./network-traffic.js";import{a as vt,i as yt,r as bt}from"./src4.js";import{n as xt,t as St}from"./screen-recording-completion.js";import{a as Ct,c as wt,i as Tt,l as Et,n as Dt,o as Ot,r as kt,s as At,t as jt}from"./device-readiness-runtime.js";import{a as Mt,i as Nt,n as Pt,r as Ft,t as It}from"./perf-runtime-operation-builder.js";import{t as Lt}from"./app-log-runtime.js";import{n as Rt}from"./artifact-paths.js";import{O as zt,T as Bt,b as Vt,c as Ht,f as Ut,g as Wt,n as Gt,o as Kt,w as qt}from"./host-file.js";import{a as Jt,o as Yt,s as Xt}from"./config.js";import{a as Zt,o as Qt}from"./tool-provider.js";import{o as $t}from"./devicectl.js";import{i as en}from"./physical-device-control.js";import{t as tn}from"./apple-runner-platform.js";import{a as nn,c as rn,n as an,o as on,s as C,u as sn}from"./simctl.js";import{c as cn,u as ln}from"./runner-client.js";import{r as un}from"./simulator.js";import{r as dn}from"./display-inventory.js";import{n as fn,t as pn}from"./app-backend.js";import{t as mn}from"./simulator-state.js";import{createHash as hn,randomUUID as gn}from"node:crypto";import w from"node:path";function _n(e,t){return Object.freeze({appState:async n=>{if(t.signal.throwIfAborted(),!await e.appleApplications.hasLiveRunnerSession(t.device,{}))return{};let r=await t.resolveInteractor(t.device,{appBundleId:n?.appBundleId,signal:t.signal});if(typeof r.appState!=`function`)throw de(`Runtime owner advertised appState without an interactor implementation`);return await r.appState()}})}function vn(e){return e.hostApp?Object.freeze({available:!1,reason:`unsupported-device-scope`,hint:`This session holds one app of the Mac. Use a --surface desktop session for audio probe.`}):Ot(e)?Object.freeze({available:!0}):v(e)||y(e)&&e.kind===`simulator`?Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`audio probe capture requires a macOS host.`}):Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`audio is supported for macOS sessions and iOS simulators on macOS hosts; physical iOS devices expose no host audio tap.`})}function yn(e){let{resolveHost:t,device:n,owner:r}=e;return Object.freeze({...It({platform:`Apple`,expectedProfileKind:`xctrace`,start:async e=>await t().start(n,r,e),reattach:async e=>await t().reattach(n,e),cleanup:async e=>await t().cleanup(n,e),writeProfileReport:async e=>await t().writeProfileReport(e)}),perfFrames:async({appId:e})=>({metric:e?await Nt(t().sampleFrames(n,e)):Pt(`Apple`,`bundle ID`),sampling:await t().frameSampling(n)}),perfMemorySample:async({appId:e})=>({metric:e?await Nt(t().sampleMemory(n,e)):Pt(`Apple`,`bundle ID`),sampling:await t().memorySampling(n)}),perfMemorySnapshot:async({appId:e,kind:r,outPath:i,artifactsDir:a})=>{let o=r??`memgraph`,s={...await t().memorySnapshotSupport(n),androidHprof:!1,heapprofd:!1};if(o!==`memgraph`)return Mt(`Apple`,o,s,`Use perf memory snapshot --kind memgraph for supported Apple app sessions.`);if(!e)throw Ft();let c=i??w.join(a,`memory-memgraph-${bn()}.memgraph`);return{artifact:await t().captureMemorySnapshot(n,e,c),support:s,sampling:{method:`xcrun memgraph`,description:`Native Apple memory graph captured for offline inspection.`,defaultKind:`memgraph`,artifactOnly:!0}}}})}function bn(){return new Date().toISOString().replaceAll(/[:.]/g,`-`)}const T=Object.freeze({available:!0}),E=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),D=Cn(`Gestures are supported only for Apple simulators and devices.`),xn=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:Me}),Sn=Cn(`scroll is supported only for Apple simulators and devices.`);function Cn(e){return Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:e})}function wn(e){return{...Le({unsupported:Tn(e),plan:En(e),directionalFling:En(e),multiTouch:Dn(e),targetAuthoredDrag:On(e),viewport:kn(e)}),...We({scroll:An(e)})}}function Tn(e){return e.appleOs===`watchos`||e.appleOs===`visionos`?E:D}function En(e){return e.appleOs===`watchos`||e.appleOs===`visionos`?E:O(e)?T:D}function Dn(e){if(e.appleOs===`watchos`)return E;if(!O(e))return D;let t=b(e);if(t!==`ios`&&t!==`ipados`){let e=fn[t];return Object.freeze({available:!1,reason:`unsupported-platform-leaf`,...e===void 0?{}:{hint:e}})}return T}function On(e){return O(e)?(e.appleOs===void 0?e.target!==`desktop`&&e.target!==`tv`:e.appleOs===`ios`||e.appleOs===`ipados`)?T:xn:D}function kn(e){return e.appleOs===`watchos`?E:O(e)?T:D}function An(e){return O(e)?T:Sn}function O(e){return e.kind===`simulator`||e.kind===`device`}const jn=`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`;function k(e){return v(e)?`macos`:e.kind===`device`?`ios-device`:`ios-simulator`}const Mn=Object.freeze({resourceKind:Lt,version:1,encode:e=>({...e}),decode:e=>!Pn(e.transport)||!Fn(e.backend)||!zn(e.outputPath)||!Ln(e.pidPath)||!In(e.transport,e.backend)?Nn():{status:`decoded`,descriptor:Object.freeze({transport:e.transport,backend:e.backend,outputPath:e.outputPath,...e.pidPath===void 0?{}:{pidPath:e.pidPath}})}});function Nn(){return{status:`invalid`,message:`Invalid Apple app-log descriptor`}}function Pn(e){return e===`apple-log-stream`||e===`coredevice-console`}function Fn(e){return e===`ios-simulator`||e===`ios-device`||e===`macos`}function In(e,t){return e===`coredevice-console`?t===`ios-device`:t!==`ios-device`}function Ln(e){return e===void 0||zn(e)}function Rn(e){if(!e.device.appleOs)throw TypeError(`Apple app-log persistence requires an explicit appleOs identity`);return xe({resourceKind:Lt,sessionId:e.sessionId,device:{id:e.device.id,family:`apple`,appleOs:e.device.appleOs,kind:e.device.kind,...e.device.target===void 0?{}:{target:e.device.target},...e.device.iosPhysicalDeviceBackend===void 0?{}:{iosPhysicalDeviceBackend:e.device.iosPhysicalDeviceBackend}},owner:e.owner,fence:e.fence,lifecycle:`open`,descriptor:be(Mn,e.descriptor)})}function zn(e){return typeof e==`string`&&e.trim().length>0}const Bn={message:`iOS physical-device app console capture is not supported by the installed devicectl.`,hint:`This devicectl does not expose process launch --console. Markers can still be written to app.log, but app output is not being captured. Use an iOS simulator for agent-device app logs or inspect physical-device logs in Console.app/Xcode until this Xcode toolchain exposes scriptable console capture.`},Vn={message:`Could not verify iOS physical-device app console capture support.`,hint:`Retry logs clear --restart. If the probe keeps failing, run logs doctor and inspect the request diagnostics for the devicectl help command.`};async function Hn(e,t){try{let n=await e.appleTools.run({tool:`devicectl`,args:[`device`,`process`,`launch`,`--help`],allowFailure:!0,timeoutMs:5e3},t),r=n.stderr.trim()||void 0;if(n.exitCode!==0)return{supported:!1,reason:`probe-failed`,stderr:r};let i=`${n.stdout}\n${n.stderr}`;return/\bUSAGE:\s+devicectl device process launch\b/i.test(i)&&/--console\b/.test(i)&&/--terminate-existing\b/.test(i)?{supported:!0,...r?{stderr:r}:{}}:{supported:!1,reason:`unsupported`,...r?{stderr:r}:{}}}catch(e){if(t?.aborted)throw t.reason;return{supported:!1,reason:`probe-failed`,...e instanceof Error?{stderr:e.message}:{}}}}async function Un(e,t,n,r){let i={},a=n?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`];if(v(t))i.logAvailable=!!await e.commands.which(`log`);else if(t.kind===`simulator`)i.simctlAvailable=await Et(async()=>wt(await e.appleTools.run({tool:`simctl`,args:rn(),allowFailure:!0},r)),r);else if(t.iosPhysicalDeviceBackend===`xctest`)i.devicectlAvailable=!1,i.devicectlConsoleCapture=!1,a.push(jn);else{i.devicectlAvailable=await Et(async()=>wt(await e.appleTools.run({tool:`devicectl`,args:[`--version`],allowFailure:!0},r)),r);let t=await Hn(e,r);if(i.devicectlConsoleCapture=t.supported,!t.supported){let e=t.reason===`unsupported`?Bn:Vn;a.push(`${e.message} ${e.hint}`)}}return{backend:k(t),checks:i,notes:a}}function Wn(e,t){let n=qn(e),r=[`subsystem == "${n}"`,`subsystem CONTAINS "${n}"`,`processImagePath ENDSWITH[c] "/${n}"`,`senderImagePath ENDSWITH[c] "/${n}"`];if(t){let e=qn(t);r.push(`process == "${e}"`,`processImagePath ENDSWITH[c] "/${e}"`,`senderImagePath ENDSWITH[c] "/${e}"`,`processImagePath CONTAINS[c] "/${e}.app/"`,`senderImagePath CONTAINS[c] "/${e}.app/"`)}return r.join(` OR `)}function Gn(e,t){return an(e,[`spawn`,e.id,`log`,`stream`,`--style`,`compact`,`--level`,`info`,`--predicate`,Wn(t.appBundleId,t.executableName)])}function Kn(e,t){return[`devicectl`,`device`,`process`,`launch`,`--device`,e,`--console`,`--terminate-existing`,t]}function qn(e){return e.replaceAll(`\\`,String.raw`\\`).replaceAll(`"`,String.raw`\"`)}const Jn=1e4;async function Yn(e,t,n,r,i){Xn(t),ft(e,n);let a=k(t),o=await Qn(e,t,n.appBundleId,i),s=new Oe,c=!1;try{let l=await e.outputs.openAppend(n.outputPath);s.defer(async()=>{c||await l[Symbol.asyncDispose]()}),i?.throwIfAborted();let u=er(l),d=await Zn(e,t,o,u.sink,n.pidPath,i);s.defer(async()=>{c||await d[Symbol.asyncDispose]()}),t.kind===`simulator`&&await tr(e,u.written,d.wait,i);let f=nr(e,d,l,a,n.outputPath),p={transport:a===`ios-device`?`coredevice-console`:`apple-log-stream`,backend:a,outputPath:n.outputPath,...n.pidPath===void 0?{}:{pidPath:n.pidPath}},m=gt(f,Rn({sessionId:n.sessionId,device:t,owner:r,fence:n.fence,descriptor:p}));return c=!0,m}finally{await s[Symbol.asyncDispose]()}}function Xn(e){if(e.appleOs===`watchos`)throw new r(`UNSUPPORTED_PLATFORM`,`watchOS app logs are not supported`);if(y(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`)throw new r(`UNSUPPORTED_OPERATION`,jn,{hint:jn})}async function Zn(e,t,n,i,a,o){if(y(t)&&t.kind===`device`){let t=await Hn(e,o);if(!t.supported){let e=t.reason===`unsupported`?Bn:Vn;throw new r(t.reason===`unsupported`?`UNSUPPORTED_OPERATION`:`COMMAND_FAILED`,e.message,{backend:`ios-device`,hint:e.hint,stderr:t.stderr})}}return o?.throwIfAborted(),await e.processes.start({command:{kind:`host`,request:n},output:i,...a?{markerPath:a}:{}})}async function Qn(e,t,n,r){return v(t)?{executable:`log`,args:[`stream`,`--style`,`compact`,`--predicate`,Wn(n)],allowFailure:!0}:t.kind===`device`?{executable:`xcrun`,args:Kn(t.id,n),allowFailure:!0}:{executable:`xcrun`,args:Gn(t,{appBundleId:n,executableName:await $n(e,t,n,r)}),allowFailure:!0}}async function $n(e,t,n,r){let i=await e.appleTools.run({tool:`simctl`,args:C(t,[`get_app_container`,t.id,n,`app`]),allowFailure:!0,timeoutMs:4e3},r),a=i.exitCode===0?i.stdout.trim():``;if(!a)return;let o=await e.commands.run({executable:`plutil`,args:[`-extract`,`CFBundleExecutable`,`raw`,`-o`,`-`,w.join(a,`Info.plist`)],allowFailure:!0,timeoutMs:4e3},r);return o.exitCode===0&&o.stdout.trim()||void 0}function er(e){let t=A,n=new Promise(e=>{t=e});return{sink:{write:async n=>{t(),await e.write(n)},[Symbol.asyncDispose]:async()=>await e[Symbol.asyncDispose]()},written:n}}async function tr(e,t,n,i){i?.throwIfAborted();let a=A,o=new Promise((e,t)=>{a=()=>t(i?.reason),i?.addEventListener(`abort`,a,{once:!0})}),s=new AbortController,c=e.clock.sleep(Jn,s.signal).then(()=>`timed-out`);c.catch(A);try{let e=Promise.race([t,n.then(A,A)]).then(()=>`launched`);if(await Promise.race([e,c,o])===`timed-out`)throw new r(`COMMAND_FAILED`,`Simulator log stream did not start within ${Jn}ms`,{reason:`simulator-log-stream-launch-timeout`,timeoutMs:Jn,hint:`Check that the simulator finished booting, then retry logs start.`})}finally{s.abort(),i?.removeEventListener(`abort`,a)}}function A(){}function nr(e,t,n,r,i){let a=e.clock.now(),o=`active`;t.wait.then(e=>{o=e.exitCode===0?`ended`:`failed`},()=>{o=`failed`});let s;return dt({inspect:()=>({backend:r,state:o,startedAt:a}),finish:async()=>s??=(async()=>(await rr([async()=>await t.terminate(),async()=>await t.wait.then(()=>void 0),async()=>await t[Symbol.asyncDispose](),async()=>await n[Symbol.asyncDispose]()])).length>0?(o=`failed`,{status:`cleanup-pending`,reason:`transport-failed`,message:`Apple app-log cleanup did not settle every owned resource`}):(o=`ended`,{status:`completed`,result:{backend:r,outputPath:i,completedAt:e.clock.now()}}))()})}async function rr(e){let t=[];for(let n of e)try{await n()}catch(e){t.push(e)}return t}const ir=le(`apple`),ar=Object.freeze({available:!0});function or(e){return Object.freeze({owner:ir,ownsDevice:e=>e.platform===`apple`,inspectFacts:async e=>cr(e),bind:async t=>{if(t.intent.kind===`exact-owner`&&!ue(t.intent.owner,ir))throw new r(`UNSUPPORTED_OPERATION`,`Apple app-log owner identity does not match`);return sr(e,t.device,t.scope.signal)},shutdown:async()=>void 0})}function sr(e,t,n){if(t.platform!==`apple`)throw new r(`UNSUPPORTED_PLATFORM`,`Apple app-log owner cannot bind ${t.platform}`);let i=mt({codec:Mn,reattach:async(n,r)=>n.backend!==k(t)||!ht(e,r.sessionId,n)?{status:`unreattachable`,reason:`descriptor-invalid`,message:`Apple app-log descriptor does not match the bound device or owning session`}:await yt(e,n.pidPath),cleanup:async(n,r)=>n.backend===k(t)&&ht(e,r.sessionId,n)?await bt(e,n.pidPath):{status:`cleanup-pending`,reason:`ownership-fence-lost`,message:`Apple app-log descriptor does not match the bound device or owning session`}}),a=Object.freeze({appLogInspect:async()=>({backend:k(t)}),appLogDoctor:async({appBundleId:r})=>await Un(e,t,r,n),appLogStart:async r=>await Yn(e,t,r,ir,n),...i});return Object.freeze({device:t,owner:ir,facts:cr(t),operations:a,[Symbol.asyncDispose]:async()=>void 0})}function cr(e){if(e.appleOs===`watchos`)return lr(e);let t=y(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?{available:!1,reason:`unsupported-device-backend`,hint:jn}:ar;return Object.freeze({device:{family:`apple`,appleOs:e.appleOs,kind:e.kind,...e.target===void 0?{}:{target:e.target},...e.iosPhysicalDeviceBackend===void 0?{}:{iosPhysicalDeviceBackend:e.iosPhysicalDeviceBackend},providerMode:`local`},operations:{appLogInspect:t,appLogDoctor:t,appLogStart:t,appLogReattach:ar,appLogCleanup:ar}})}function lr(e){let t=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS app logs are not supported.`});return Object.freeze({device:{family:`apple`,appleOs:`watchos`,kind:e.kind,...e.target===void 0?{}:{target:e.target},providerMode:`local`},operations:{appLogInspect:t,appLogDoctor:t,appLogStart:t,appLogReattach:t,appLogCleanup:t}})}async function ur(e,t,n,r){let i=k(t),a=await e.appLogs.readRecent(n.sessionId,n.maxScanLines),o=pt(a.text,{...n,path:a.path,exists:a.exists,lineNumberOffset:a.skippedLines,backend:i}),s=[];if(fr(t,n,o.dump)){let i=await pr(e,t,n,a.path,r);i&&(o=dr(s,o,i,n.maxEntries))}return gr(s,t,n),hr(s,o.dump),o.dump.entries.length===0&&s.push(_r(t)),Object.freeze({source:`app-log`,backend:i,dump:o.dump,notes:Object.freeze(s)})}function dr(e,t,n,r){let i=n.scan.dump.entries.length;return i===0&&(n.scan.dump.unnamedRequests??0)===0?(n.lineCount>0&&e.push(`Recovered ${n.lineCount} recent iOS simulator app log lines from simctl log show, but none looked like HTTP traffic. This app may not emit request URLs, status, or timing into Unified Logging for this repro window.`),t):(i>0&&e.push(`Recovered ${i} iOS simulator HTTP entr${i===1?`y`:`ies`} from simctl log show (${n.lineCount} app log lines scanned).`),_t(n.scan,t,r))}function fr(e,t,n){return y(e)&&e.kind===`simulator`&&!!t.appBundleId&&n.entries.length===0}async function pr(e,t,n,r,i){let a=n.appLogSnapshot?.startedAt,o=C(t,[`spawn`,t.id,`log`,`show`,`--style`,`compact`,`--info`,`--predicate`,mr(n.appBundleId),...typeof a==`number`&&Number.isFinite(a)&&a>0?[`--start`,`@${Math.floor(a/1e3)}`]:[`--last`,`5m`]]),s=await e.appleTools.run({tool:`simctl`,args:o,allowFailure:!0,timeoutMs:4e3},i);if(s.exitCode!==0||!s.stdout.trim())return;let c=s.stdout.split(`
|
|
2
|
+
`).map(e=>e.trimEnd()).filter(e=>e.trim()&&!e.trim().startsWith(`Timestamp Ty Process[PID:TID]`));if(c.length!==0)return{scan:pt(`${c.join(`
|
|
3
|
+
`)}\n`,{...n,path:`${r} (simctl log show recovery)`,exists:!0,backend:`ios-simulator`}),lineCount:c.length}}function mr(e){let t=e.replaceAll(`\\`,String.raw`\\`).replaceAll(`"`,String.raw`\"`);return[`subsystem == "${t}"`,`subsystem CONTAINS "${t}"`,`processImagePath ENDSWITH[c] "/${t}"`,`senderImagePath ENDSWITH[c] "/${t}"`].join(` OR `)}function hr(e,t){let n=t.entries.filter(e=>e.pathUnavailable).length,r=t.unnamedRequests??0,i=n+r;if(i===0)return;let a=[`${i} request${i===1?``:`s`} reused a keep-alive connection, so CFNetwork logged no request URL.`];n>0&&a.push(`${n} listed against the origin the connection was opened for, without a path.`),r>0&&a.push(`${r} opened before this scan window and are missing from the entries entirely; scan more lines, or run logs clear --restart before the repro.`),a.push(`Absence of an endpoint in this dump does not prove it was not called.`),e.push(a.join(` `))}function gr(e,t,n){n.appLogSnapshot?n.appLogSnapshot.state!==`active`&&e.length===0&&e.push(y(t)&&t.kind===`simulator`?`Session app log stream is inactive. The iOS simulator recovery path scanned recent simctl log history, but a fresh logs clear --restart window is still the most reliable repro loop.`:`Session app log stream is inactive. Run logs clear --restart, reproduce the request window again, then rerun network dump.`):e.push(`Capture uses the session app log file. For fresh traffic, run logs clear --restart before reproducing requests.`)}function _r(e){return y(e)&&e.kind===`simulator`?`No HTTP(s) entries were found in recent iOS simulator app logs. If the app only emits non-HTTP diagnostics, inspect logs path or add app-side URLSession/network logging for per-request timing and payload details.`:y(e)?`No HTTP(s) entries were found in recent iOS device app logs. iOS network dump only sees what the app emits into Unified Logging for this process.`:`No HTTP(s) entries were found in recent session app logs.`}async function vr(e){let{host:t,snapshot:n,targetLabel:r,recorderWarning:a,nativePathDisposition:o}=e,s=n.invalidatedReason?{recorder:`lost`,why:`owner-session-lost`}:e.stopObservation;if(n.invalidatedReason&&!n.showTouches)throw Error(`recording invalidated: ${n.invalidatedReason}`);let c;try{c=await t.screenRecording.finalize.complete({outputPath:n.outPath,showTouches:!n.invalidatedReason&&n.showTouches,gestureEvents:n.gestureEvents,exportQuality:n.exportQuality??`medium`,...n.fps===void 0?{}:{fps:n.fps},targetLabel:r})}catch(e){throw i(e,`COMMAND_FAILED`)}let l=[...c.warning?[c.warning]:[],...a?[a]:[]];return St(n,{...c,...l.length>0?{warning:l.join(` `)}:{},...n.invalidatedReason?{overlayWarning:`overlay unavailable: ${n.invalidatedReason}`}:{}},{stopObservation:s,...o===void 0?{}:{nativePathDisposition:o}})}async function yr(e){let{host:t,snapshot:n,targetLabel:r,collectedPath:i,exportPath:a,nativePath:o}=e;if(n.invalidatedReason&&!n.showTouches)throw Error(`recording invalidated: ${n.invalidatedReason}`);let s=e.overlayUnavailable??n.invalidatedReason,c;try{await t.screenRecording.outputs.copy({from:i,to:a}),c=await br(()=>t.screenRecording.finalize.complete({outputPath:a,showTouches:s===void 0&&n.showTouches,gestureEvents:n.gestureEvents,exportQuality:n.exportQuality??`medium`,...n.fps===void 0?{}:{fps:n.fps},targetLabel:r}))}catch(e){throw await t.screenRecording.outputs.remove(a),e}return{...c,...s===void 0?{}:{overlayWarning:`overlay unavailable: ${s}`},nativePathDisposition:await t.screenRecording.outputs.remove(o)===`removed`?`retired`:`retirable`}}async function br(e){try{return await e()}catch(e){throw i(e,`COMMAND_FAILED`)}}const xr=[`outPath`,`startedAt`,`clientOutPath`,...Tt],Sr=Object.freeze({resourceKind:Se,version:1,encode:e=>e.backend===`simctl`?{backend:e.backend,outputPath:e.outputPath,processes:e.processes.map(e=>({...e})),...e.recording===void 0?{}:{recording:{...e.recording}}}:{backend:e.backend,outputPath:e.outputPath,appBundleId:e.appBundleId,runnerSessionId:e.runnerSessionId,runnerAuthority:e.runnerAuthority,...e.remotePath===void 0?{}:{remotePath:e.remotePath}},decode:e=>Pr(e)});function Cr(e){let{device:t,owner:n,input:r,descriptor:i}=e;return xe({resourceKind:Se,sessionId:r.sessionId,device:ae(t),owner:n,fence:r.fence,lifecycle:`open`,descriptor:be(Sr,i)})}function wr(e){let t={};for(let n of xr)e[n]!==void 0&&Object.assign(t,{[n]:e[n]});return t}async function Tr(e,t,n,r){let i=Sr.decode(n);return i.status!==`decoded`||!Wr(t,i.descriptor)?{status:`cleanup-pending`,reason:`manual-recovery-required`}:i.descriptor.backend===`simctl`?await Er(e,i.descriptor.processes,r):await Or(e,t,i.descriptor)}async function Er(e,t,n){let r=await Promise.all(t.map(async t=>await e.screenRecording.apple.inspectProcess(t)));if(r.includes(`ownership-lost`))return{status:`cleanup-pending`,reason:`ownership-fence-lost`};if(r.every(e=>e===`missing`))return n!==void 0&&e.screenRecording.ownedProcesses.clear(Dr(n)),{status:`already-missing`};let i=await Promise.all(t.flatMap((t,n)=>r[n]===`owned-alive`?[e.screenRecording.apple.terminateProcess(t)]:[]));return i.includes(`ownership-lost`)?{status:`cleanup-pending`,reason:`ownership-fence-lost`}:(n!==void 0&&e.screenRecording.ownedProcesses.clear(Dr(n)),i.every(e=>e===`already-missing`)?{status:`already-missing`}:{status:`cleaned`})}function Dr(e){return{kind:`session`,sessionId:e}}async function Or(e,t,n){try{let r=await e.screenRecording.apple.inspectRunner(t,n.runnerSessionId,n.runnerAuthority);return r===`missing`?{status:`already-missing`}:r===`ownership-lost`?{status:`cleanup-pending`,reason:`ownership-fence-lost`}:(await e.screenRecording.apple.runRunner(t,{kind:`stop`,appBundleId:n.appBundleId,runnerSessionId:n.runnerSessionId,runnerAuthority:n.runnerAuthority}),{status:`cleaned`})}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`Apple recording cleanup failed`}}}async function kr(e){let{host:t,device:n,envelope:r}=e,i=Sr.decode(r.descriptor.body);return i.status===`decoded`?Wr(n,i.descriptor)?i.descriptor.backend===`simctl`?await Ar(e,i.descriptor):await Mr(t,n,i.descriptor):j(`descriptor-invalid`,`Apple screen-recording descriptor does not match the bound device.`):j(`descriptor-invalid`,i.message)}async function Ar(e,t){let n=await Promise.all(t.processes.map(async t=>await e.host.screenRecording.apple.inspectProcess(t)));if(!n.every(e=>e===`missing`))return j(`transport-not-reattachable`,n.includes(`ownership-lost`)?`Apple recording ownership no longer matches the durable descriptor.`:`Apple screen recordings require exact cleanup after daemon restart.`);let{recording:r}=t,i=jr(kt(e.envelope.metadata),t.outputPath);return r===void 0||i!==void 0&&!await Nr(e.host,i)?{status:`missing`}:{status:`restore-export`,recording:r,nativePath:t.outputPath,cleanup:async()=>await Er(e.host,t.processes,e.envelope.sessionId)}}function jr(e,t){if(e.finalization===void 0)return e.collectedPath??t}async function Mr(e,t,n){let r=await e.screenRecording.apple.inspectRunner(t,n.runnerSessionId,n.runnerAuthority);return r===`missing`?{status:`missing`}:j(`transport-not-reattachable`,r===`ownership-lost`?`Apple recording ownership no longer matches the durable descriptor.`:`Apple screen recordings require exact cleanup after daemon restart.`)}async function Nr(e,t){try{return await e.screenRecording.finalize.sniff({outputPath:t}),!0}catch{return!1}}function j(e,t){return{status:`unreattachable`,reason:e,message:t}}function Pr(e){return typeof e.outputPath!=`string`||e.outputPath.length===0?N():e.backend===`simctl`?Fr(e,e.outputPath):e.backend===`runner`?Rr(e,e.outputPath):N()}function Fr(e,t){let n=Gr(e.processes),r=Ir(e.recording);return!n||r===`invalid`?N():{status:`decoded`,descriptor:Object.freeze({backend:`simctl`,outputPath:t,processes:n,...r===void 0?{}:{recording:r}})}}function Ir(e){if(e!==void 0)return f(e)&&Lr(e)?Object.freeze(e):`invalid`}function Lr(e){return M(e.outPath)&&Br(e.startedAt)&&zr(e.clientOutPath)&&Ct(e)}function Rr(e,t){return!M(e.appBundleId)||!M(e.runnerSessionId)||!Vr(e.runnerAuthority)||!Hr(e.remotePath)?N():{status:`decoded`,descriptor:Object.freeze({backend:`runner`,outputPath:t,appBundleId:e.appBundleId,runnerSessionId:e.runnerSessionId,runnerAuthority:e.runnerAuthority,...e.remotePath===void 0?{}:{remotePath:e.remotePath}})}}function M(e){return typeof e==`string`&&e.length>0}function zr(e){return e===void 0||M(e)}function Br(e){return typeof e==`number`&&Number.isFinite(e)}function Vr(e){return e===`local-lease`||e===`scoped-provider`}function Hr(e){return e===void 0||Ur(e)}function Ur(e){return typeof e==`string`&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(e)}function Wr(e,t){return e.kind===`simulator`?t.backend===`simctl`:t.backend===`runner`?e.appleOs===`macos`?t.remotePath===void 0:y(e)?t.remotePath!==void 0&&Ur(t.remotePath):t.remotePath===void 0:!1}function Gr(e){if(!Array.isArray(e)||e.length===0)return;let t=e.filter(e=>typeof e==`object`&&!!e&&Number.isInteger(e.pid)&&(e.pid??0)>0&&typeof e.startTime==`string`&&e.startTime.length>0&&typeof e.command==`string`&&e.command.length>0);return t.length===e.length?Object.freeze([...t]):void 0}function N(){return{status:`invalid`,message:`Invalid Apple screen-recording descriptor`}}async function Kr(e,t,n){if(e.kind!==`simulator`||t.scope!==`app`)return;let r=t.activeSessionApp?.bundleId;if(!r)throw TypeError(`App-scoped recording requires an active app session; open the app under test before recording.`);if(await n(r))throw TypeError(`App-scoped recording requires a real application session; open the app under test before recording.`)}const qr=`iOS recording`,Jr=`simctl recordVideo`;function Yr(e){return e.appleOs===`watchos`?S(`unsupported-platform-leaf`,`watchOS recording is not supported.`):y(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?S(`unsupported-device-backend`,`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`):Object.freeze({available:!0})}function Xr(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await Zr({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async e=>{let r=await kr({host:t,device:n,envelope:e.envelope});return r.status===`restore-export`?{status:`active`,handle:$r({host:t,restored:r})}:r},screenRecordingCleanup:async e=>await Tr(t,n,e.envelope.descriptor.body,e.envelope.sessionId)})}async function Zr(e){return e.signal.throwIfAborted(),e.device.kind===`simulator`?await Qr(e):await ti(e)}async function Qr(e){let{host:t,device:n,owner:r,input:i,signal:a}=e;await Kr(n,i,t.screenRecording.apple.isRunnerBundleId);let o=i.activeSessionApp?await t.screenRecording.apple.captureClockAnchor(n,i.activeSessionApp.bundleId,a):void 0,s=Rt(i.outputPath);await t.screenRecording.outputs.prepare(s);let c=await t.screenRecording.apple.startSimulator(n,s,a),l=c.markers;if(!l||l.length===0)throw await oi(c).catch(()=>{}),Error(`simctl recordVideo did not expose durable process identity`);try{a.throwIfAborted(),t.screenRecording.ownedProcesses.replace({kind:`session`,sessionId:i.sessionId},l.map(e=>({...e,purpose:`simctl-screen-recording`})))}catch(e){try{t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId})}catch{}throw await oi(c).catch(()=>{}),e}let u,d,f=async()=>{await c.terminate();let e=await c.wait;return d=e,u=ri(e),t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId}),{observation:{recorder:`confirmed`},...u===void 0?{}:{warning:`${u} before record stop; the video covers only what the recorder wrote before it stopped.`}}},p=li(i,Jr,{},o);return ci({device:n,owner:r,input:i,descriptor:{backend:`simctl`,outputPath:s,processes:l,recording:wr(p)},snapshot:p,finish:(e,n)=>Dt({snapshot:e,progress:n,steps:{stop:f,collect:async e=>{try{await ei(t,s,e)}catch(e){throw ii(e,u,d)}},finalize:async({collectedPath:n,exportPath:r})=>{try{return await yr({host:t,snapshot:e,targetLabel:qr,collectedPath:n,exportPath:r,nativePath:s})}catch(e){throw ii(e,u,d)}},discard:async e=>{await t.screenRecording.outputs.remove(e)}}}),cleanup:async()=>{let e=await si(c);return(e.status===`cleaned`||e.status===`already-missing`)&&t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId}),e}})}function $r(e){let{host:t,restored:{recording:n,nativePath:r,cleanup:i}}=e,a=Object.freeze({...n,backend:Jr,gestureEvents:[]});return xt(a,{finish:(e,i)=>Dt({snapshot:e,progress:i,steps:{stop:async()=>({observation:{recorder:`confirmed`},warning:`simctl recordVideo had already ended when record stop reattached to it; the video covers only what the recorder wrote before it stopped.`}),collect:async e=>{await ei(t,r,e)},finalize:async({collectedPath:i,exportPath:a})=>await yr({host:t,snapshot:e,targetLabel:qr,collectedPath:i,exportPath:a,nativePath:r,...n.showTouches?{overlayUnavailable:`the daemon that held the touch events ended before record stop`}:{}}),discard:async e=>{await t.screenRecording.outputs.remove(e)}}}),forceCleanup:async()=>await i()})}async function ei(e,t,n){await e.screenRecording.outputs.copy({from:t,to:n}),await e.screenRecording.finalize.sniff({outputPath:n})}async function ti(e){let{host:t,device:n,owner:r,input:i,signal:a}=e,o=i.activeSessionApp?.bundleId;if(!o)throw TypeError(`Apple runner recording requires an active app session identity`);await t.screenRecording.outputs.prepare(i.outputPath);let s=await t.screenRecording.apple.runRunner(n,{kind:`start`,appBundleId:o,outputPath:i.outputPath,...i.fps===void 0?{}:{fps:i.fps}},a);if(!s.runnerSessionId||!s.runnerAuthority)throw Error(`Apple runner recording did not expose durable session ownership`);let c={runnerSessionId:s.runnerSessionId,runnerAuthority:s.runnerAuthority},l,u=()=>(l??=ni(()=>t.screenRecording.apple.runRunner(n,{kind:`stop`,appBundleId:o,...c}).then(()=>void 0)).catch(e=>{throw l=void 0,e}),l);if(!ai(n,s.remotePath))throw await u().catch(()=>{}),Error(`Apple runner recording did not expose coherent durable media ownership`);try{a.throwIfAborted()}catch(e){throw await u().catch(()=>{}),e}return ci({device:n,owner:r,input:i,descriptor:{backend:`runner`,outputPath:i.outputPath,appBundleId:o,...c,...s.remotePath===void 0?{}:{remotePath:s.remotePath}},snapshot:li(i,`runner AVAssetWriter`,s),finish:async e=>(await u(),s.remotePath!==void 0&&await t.screenRecording.apple.retrieveRunnerRecording(n,s.remotePath,e.outPath),await vr({host:t,snapshot:e,targetLabel:n.appleOs===`macos`?`macOS recording`:`iOS recording`,stopObservation:{recorder:`confirmed`},...s.remotePath===void 0?{}:{nativePathDisposition:`retirable`}})),cleanup:async()=>(await u(),{status:`cleaned`})})}async function ni(e){try{return await e()}catch(e){throw i(e,`COMMAND_FAILED`)}}function ri(e){if(e.exitCode!==0)return e.signal?`simctl recordVideo was killed by ${e.signal}`:`simctl recordVideo exited with code ${e.exitCode}`}function ii(e,t,n){let a=i(e,`COMMAND_FAILED`);return t===void 0||n===void 0||a.details?.reason!==`recording-output-unplayable`?e:new r(a.code,`${a.message}; ${t}`,p(n,{...a.details??{},...n.signal===void 0?{}:{signal:n.signal},retriable:!1,hint:`The recorder exited before record stop, so the next record stop reads the same file. Close this session to release the device, then record again.`}))}function ai(e,t){return e.appleOs===`macos`||!y(e)?t===void 0:t!==void 0&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(t)}async function oi(e){return await e.terminate(),await e.wait}async function si(e){try{return await oi(e),{status:`cleaned`}}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`Apple simulator cleanup failed`}}}function ci(e){let{device:t,owner:n,input:r,descriptor:i,snapshot:a,finish:o,cleanup:s}=e,c=xt(a,{finish:o,forceCleanup:s});return Object.freeze({pendingHandle:new De(c),envelope:Cr({device:t,owner:n,input:r,descriptor:i})})}function li(e,t,n={},r){let i=Date.now();return Object.freeze({backend:t,outPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutPath:e.clientOutputPath},startedAt:i,scope:e.scope,showTouches:e.showTouches,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},...e.exportQuality===void 0?{}:{exportQuality:e.exportQuality},...e.fps===void 0?{}:{fps:e.fps},gestureEvents:[],...r===void 0?{}:{gestureClockOriginAtMs:r.wallClockAtMs,gestureClockOriginUptimeMs:r.uptimeMs},...n.recorderStartUptimeMs===void 0?{}:{gestureClockOriginAtMs:i,gestureClockOriginUptimeMs:n.recorderStartUptimeMs,runnerStartedAtUptimeMs:n.recorderStartUptimeMs},...n.runnerSessionId===void 0?{}:{runnerSessionId:n.runnerSessionId}})}async function P(e,t,n,r={}){return n.throwIfAborted(),v(t)?{...t,booted:!0}:t.kind===`device`?(await e.deviceReadiness.applePhysical.ensureConnected(t,n),{...t,booted:!0}):t.kind===`simulator`?((await ui(e,t)?`Booted`:await gi(e,t,n))!==`Booted`&&(r.onColdBootStart?.(),e.deviceReadiness.appleAutomation.keepHot(t),await di(e,t,n,r.deadlineAtMs),await _i(e,n)),e.deviceReadiness.appleAutomation.keepHot(t),e.deviceReadiness.appleAutomation.markBooted(t),{...t,booted:!0}):{...t,booted:!0}}async function ui(e,t){try{return await e.deviceReadiness.appleAutomation.wasRecentlyObservedBooted(t)}catch{return!1}}async function di(e,t,n,r=Date.now()+12e4){let i=!1;try{i=await fi(e,t,n,r),await pi(e,t,n,r)}catch(a){throw i&&n.aborted&&vi(e,t),n.throwIfAborted(),Date.now()>=r?hi(t,a):a}}async function fi(e,t,n,i){let a=await e.appleTools.run({tool:`simctl`,args:C(t,[`boot`,t.id]),allowFailure:!0,timeoutMs:mi(i,t)},n),o=`${a.stdout}\n${a.stderr}`.toLowerCase(),s=o.includes(`already booted`)||o.includes(`current state: booted`);if(a.exitCode!==0&&!s)throw new r(`COMMAND_FAILED`,`simctl boot failed`,{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode});return!s}async function pi(e,t,n,i){Ce({type:`command`,status:`progress`,message:`Waiting for the Simulator to finish booting...`});let a=await e.appleTools.run({tool:`simctl`,args:C(t,[`bootstatus`,t.id,`-b`]),allowFailure:!0,timeoutMs:mi(i,t)},n);if(a.exitCode!==0)throw new r(`COMMAND_FAILED`,`simctl bootstatus failed`,{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode});if(n.throwIfAborted(),Date.now()>=i)throw hi(t)}function mi(e,t){let n=e-Date.now();if(n<=0)throw hi(t);return n}function hi(e,t){return new r(`COMMAND_FAILED`,`Simulator did not finish booting within the startup budget`,{reason:jt,deviceId:e.id,hint:`The Simulator keeps booting in the background; a first boot can take several minutes. Retry once it is up, or pass a larger --timeout.`},t instanceof Error?t:void 0)}async function gi(e,t,n){return await mn(e.appleTools,t,n,15e3)}async function _i(e,t){await e.commands.run({executable:`open`,args:[`-g`,`-a`,`Simulator`],allowFailure:!0,timeoutMs:1e4},t)}function vi(e,t){e.appleTools.run({tool:`simctl`,args:C(t,[`shutdown`,t.id]),allowFailure:!0}).catch(()=>{})}const yi=Object.freeze({resolveOpenTarget:`simulator`,prepareApplicationOpen:`simulator`,openApplication:`simulator`,applyRuntimeHints:`simulator`,clearRuntimeHints:`simulator`,closeApplication:`simulator`,finalizeApplicationClose:`simulator`,prepareAppleRunner:`runner`,configureProviderPortReverse:`simulator`,ensureReady:`simulator`,bootTarget:`simulator`,bootTargetHeadless:`simulator`,shutdownTarget:`simulator`,listApps:`simulator`,deployApp:`simulator`,materializeAppSource:`simulator`,deployMaterializedApp:`simulator`,sendPushNotification:`simulator`,uninstallApp:`simulator`,appState:`simulator`,appLogStart:`simulator`,appLogInspect:`simulator`,appLogDoctor:`simulator`,appLogReattach:`simulator`,appLogCleanup:`simulator`,networkDump:`simulator`,audioProbeStart:`simulator`,audioProbeQuery:`simulator`,audioProbeReattach:`simulator`,audioProbeCleanup:`simulator`,readClipboard:`simulator`,writeClipboard:`runner`,setSetting:`simulator`,readSetting:`simulator`,setFoldPose:`simulator`,sendTelephonyEvent:`simulator`,unlockOrientation:`simulator`,power:`simulator`,volumeDown:`simulator`,volumeUp:`simulator`,mute:`simulator`,sleep:`simulator`,wake:`simulator`,mediaPlayPause:`simulator`,mediaNext:`simulator`,mediaPrevious:`simulator`,mediaRewind:`simulator`,mediaFastForward:`simulator`,captureSnapshot:`simulator`,captureSnapshotWithoutActiveApp:`simulator`,captureSnapshotWithCustomActions:`runner`,captureScreenshot:`simulator`,findText:`runner`,querySelector:`runner`,readTextAtPoint:`runner`,tapPoint:`runner`,tapRef:`runner`,tapElementSelector:`runner`,fillPoint:`runner`,fillRef:`runner`,longPressPoint:`runner`,hoverPoint:`runner`,hoverRef:`runner`,focusPoint:`runner`,typeText:`runner`,scrollDirection:`runner`,performGesturePlan:`runner`,performMultiTouchGesturePlan:`runner`,performTargetAuthoredDrag:`runner`,performDirectionalFlingPlan:`runner`,gestureViewport:`runner`,setViewport:`runner`,back:`runner`,home:`runner`,setOrientation:`runner`,appSwitcher:`runner`,actionButton:`runner`,tvRemote:`runner`,keyboardDismiss:`runner`,keyboardEnter:`runner`,keyboardStatus:`runner`,triggerAppEvent:`runner`,readAlert:`runner`,awaitAlert:`runner`,acceptAlert:`runner`,dismissAlert:`runner`,perfFrames:`runner`,perfMemorySample:`runner`,perfMemorySnapshot:`runner`,perfNativeCaptureStart:`runner`,perfNativeCaptureReattach:`runner`,perfNativeCaptureCleanup:`runner`,perfProfileReport:`runner`,screenRecordingStart:`runner`,screenRecordingReattach:`runner`,screenRecordingCleanup:`runner`});function bi(e){return e===void 0?`possible`:e.some(e=>yi[e]===`runner`)?`required`:`none`}function xi(e){let{waitMs:t,signal:n,stop:r,cancelled:i}=e;return new Promise((e,a)=>{let o=()=>l(()=>a(i())),s=()=>l(e),c=setTimeout(()=>l(e),t);function l(e){clearTimeout(c),n?.removeEventListener(`abort`,o),r?.removeEventListener(`abort`,s),e()}n?.addEventListener(`abort`,o,{once:!0}),r?.addEventListener(`abort`,s,{once:!0}),n?.aborted?o():r?.aborted&&s()})}function Si(e){let t=e.now??Date.now,n=e.waitGrant??`every-caller`,r=new Map,i=(n,i)=>{let a={status:`pending`,value:void 0,error:void 0,settledAtMs:t(),waitSpent:!1,controller:new AbortController,settled:void 0},o=()=>{};a.settled=new Promise(e=>{o=e}),r.set(n,a);let s=(i,s)=>{a.status=i,i===`ready`?a.value=s:a.error=s,a.settledAtMs=t(),(i===`ready`||e.retryAfterMs===void 0)&&r.get(n)===a&&r.delete(n),o()};try{i(a.controller.signal).then(e=>s(`ready`,e),e=>s(`failed`,e))}catch(e){s(`failed`,e)}return a},a=(n,a)=>{let o=r.get(n);if(!o)return i(n,a);if(o.status!==`failed`)return o;let s=t()-o.settledAtMs;return e.retryAfterMs===void 0||s>=e.retryAfterMs?i(n,a):o};return{value:async(t,r)=>{let i=a(t,r.start);if(i.status===`pending`&&(n===`every-caller`||!i.waitSpent)){i.waitSpent=!0;let t=new AbortController,n=r.wait(e.waitMs,t.signal);n.catch(()=>{});try{await Promise.race([i.settled,n])}finally{t.abort()}}if(i.status===`ready`)return i.value;throw i.status===`failed`?i.error:r.pending()},close:()=>{let e=[...r.values()];r.clear();for(let t of e)t.controller.abort()}}}async function Ci(e,t){let n=await Zt(`ps`,[`-p`,String(e),`-o`,`lstart=`],{allowFailure:!0,signal:t.signal,timeoutMs:t.timeoutMs});return n.exitCode===0&&n.stdout.trim()||null}const wi=3e3,Ti=`simulator-target-discovery-pending`,Ei=`simulator-target-unavailable`;function Di(){let e=new Map,t=new Map,n=Si({waitMs:1500});return async(r,i,a,o)=>{a.throwIfAborted();let s=`${r.id}:${i}`,c=e.get(s);if(c&&o!==`refresh`){let e=await Ci(c.pid,{signal:a,timeoutMs:wi});if(a.throwIfAborted(),e===c.processStartTime)return c}return e.delete(s),await n.value(s,{start:async()=>{let n=await ji(r,i,t);return e.set(s,n),n},wait:(e,t)=>xi({waitMs:e,signal:a,stop:t,cancelled:()=>Oi(a)}),pending:()=>F(Ti,r,i)})}}function Oi(e){return t({readinessPhase:`target-discovery`},e.reason)}function ki(e){return e instanceof r&&e.details?.reason===Ti}function Ai(e){return e instanceof r&&e.details?.reason===Ei}async function ji(e,t,n){let r=Date.now()+15e3,[i,a]=await Promise.allSettled([on(e,[`spawn`,e.id,`launchctl`,`list`],{allowFailure:!0,timeoutMs:Pi(r)}),Mi(e,n,r)]);if(i.status===`rejected`)throw i.reason;if(a.status===`rejected`)throw a.reason;let o=i.value,s=a.value;if(o.exitCode!==0)throw F(`simulator-target-probe-failed`,e,t);let c=Ni(o.stdout,t);if(!c)throw F(Ei,e,t);let l=await Ci(c.pid,{timeoutMs:Math.min(wi,Pi(r))});if(!l)throw F(`simulator-target-identity-unavailable`,e,t);return Object.freeze({simulator:sn(e),runtime:s,pid:c.pid,generation:`${c.pid}:${c.label}:${l}`,targetId:`${e.id}:${t}`,processStartTime:l})}async function Mi(e,t,n){let r=t.get(e.id);if(r)return await r;let i=on(e,[`list`,`devices`,`-j`],{allowFailure:!0,timeoutMs:Pi(n)}).then(t=>{if(t.exitCode!==0)throw F(`simulator-runtime-probe-failed`,e,``);let n=Object.entries(nn(t.stdout)).find(([,t])=>t.some(t=>t.udid===e.id))?.[0];if(!n)throw F(`simulator-runtime-unavailable`,e,``);return n});t.set(e.id,i);try{return await i}catch(n){throw t.delete(e.id),n}}function Ni(e,t){for(let n of e.split(`
|
|
4
|
+
`)){let[e,,r]=n.trim().split(/\s+/);if(!e||!r||!r.startsWith(`UIKitApplication:${t}[`))continue;let i=Number(e);if(Number.isSafeInteger(i)&&i>0)return{pid:i,label:r}}}function Pi(e){return Math.max(1,e-Date.now())}function F(e,t,n){return new r(`COMMAND_FAILED`,`Unable to resolve the running iOS Simulator app (${e}).`,{reason:e,deviceId:t.id,appBundleId:n})}function Fi(e){return e?.observation===`unobservable`&&e.proof===`no-running-process`}const Ii=new Map([[`application-element-missing`,5e3],[`application-server-unavailable`,5e3],[`foreground-owner-unverified`,1e3],[`foreground-owner-changed`,1e3]]);function I(e){return e.platform===`apple`&&ie(e)}function Li(e){let t=_e(ye({depth:1,interactiveOnly:!0}));return Object.freeze({awaitObservable:async(n,r,i)=>{if(!I(n))return{observation:`not-eligible`};let a;for(;;){let o=await zi(e.resolveTarget,n,r,i);if(`verdict`in o)return o.verdict;let{target:s}=o;if(e.isBridgeDisabled(s))return _({level:`debug`,phase:`ios_launch_observation_skipped`,data:{reason:`circuit-disabled`,deviceId:n.id,generation:s.generation}}),Ri({source:`circuit`});let c=await e.source.acquire({target:s,hint:t,signal:i});if(c.stage!==`failed`)return{observation:`observable`};i.throwIfAborted();let{kind:l,code:u}=c.failure,d=Ii.get(u);if(d===void 0)return Ri({source:`bridge`,kind:l,code:u});let f=e.clock.now();if(a=Math.min(a??1/0,f+d),f>=a)return{observation:`unobservable`,proof:`launch-transition`};await e.clock.sleep(Math.min(150,a-f),i)}}})}function Ri(e){return{observation:`probe-failed`,failure:e}}async function zi(e,t,n,r){for(;;)try{return{target:await e(t,n,r)}}catch(e){if(r.throwIfAborted(),ki(e))continue;if(Ai(e))return{verdict:{observation:`unobservable`,proof:`no-running-process`}};let{code:t,details:n}=a(e),i=n?.reason;return{verdict:Ri(typeof i==`string`?{source:`target`,code:t,reason:i}:{source:`target`,code:t})}}}function Bi(e,t,n){let r=n&&I(e),i=r?bi(t.execution.plannedOperations):void 0,a=y(e)&&t.surface===`app`&&t.positionals.length>0&&!!t.appBundleId&&i!==`none`;return{...i?{runnerDemand:i}:{},shouldPrewarmRunner:a,awaitPrewarmAfterOpen:t.relaunch&&!r}}function Vi(e,t,n,r){r.runnerDemand===`none`&&e.appleApplications.releaseSpeculativeRunner(t.device,n.execution).catch(()=>{})}async function Hi(e,t,n,i,a,o){let s=Date.now(),c=async()=>await Yi(t,n,i,a.observation),l=await c(),u,d,f=a.answerConfirmation,p=f&&l?.observation!==`observable`?await Ui(f,a.redispatchLaunchUrl,c,l):void 0;if(p&&(o.runnerDemand=`required`,u=p.report,d=p.probeFailure,l=p.observed,p.unanswered))throw new r(`COMMAND_FAILED`,`The Simulator has not completed the launch URL for ${n.appBundleId}.`,{reason:`launch_confirmation_unanswered`,appBundleId:n.appBundleId,hint:`iOS may still be holding an "Open in" prompt, or the answer died with the runner session that raised it. Inspect the current alert before deciding on another action.`});if(i&&l?.observation!==`observable`&&await e.clock.sleep(300,t.signal),l&&(o.postOpenObservation=l.observation,l.observation===`probe-failed`&&(o.postOpenObservationFailure=l.failure)),o.postOpenSettleDurationMs=Math.max(0,Date.now()-s),u)return u;if(d)return{launchConfirmationProbeFailure:d}}async function Ui(e,t,n,r){let i={observed:r,acceptAttempted:!1,confirmationStillPresent:!1};for(let r=0;r<2;r+=1){i=await Wi(e,n,i);let a=r===1;if(i.confirmationStillPresent||a||!qi(i)||!t)break;await t()}return{observed:i.observed,report:i.report,probeFailure:i.probeFailure,unanswered:qi(i)||i.confirmationStillPresent}}async function Wi(e,t,n){let r=await e(),i=r.outcome===`unanswered`&&r.reason===`alert-still-present`,a=n.acceptAttempted||Ji(r),o=Ki(n,r);return a?{observed:await t(),...o,acceptAttempted:a,confirmationStillPresent:i}:{observed:n.observed,...o,acceptAttempted:a,confirmationStillPresent:i}}function Gi(e){switch(e.outcome){case`accepted`:return{seen:{launchConfirmation:`accepted`}};case`absent`:return{};case`unreadable`:return e.step===`url-owner`?{seen:{launchConfirmation:`unanswered`,launchConfirmationReason:`url-owner-unresolved`}}:{probeFailure:e.step};case`unanswered`:return e.reason===`alert-still-present`?{}:{seen:{launchConfirmation:`unanswered`,launchConfirmationReason:e.reason}}}}function Ki(e,t){let n=Gi(t);return`seen`in n?{report:n.seen,probeFailure:void 0}:`probeFailure`in n?{report:void 0,probeFailure:n.probeFailure}:{report:e.report,probeFailure:void 0}}function qi(e){return e.acceptAttempted&&Fi(e.observed)}function Ji(e){return e.outcome===`accepted`||e.outcome===`unanswered`&&e.reason===`alert-still-present`||e.outcome===`unreadable`&&e.step===`alert-accept`}async function Yi(e,t,n,r){if(!(!n||!I(e.device))&&!(!r||!t.appBundleId))return await r.awaitObservable(e.device,t.appBundleId,e.signal)}let Xi;const Zi=()=>Xi??=import(`./launch-confirmation.js`);let Qi;const $i=()=>Qi??=import(`./expo-dev-client-launch.js`);function ea(e){let t=t=>ot({device:t,signal:e.signal,resolveInteractor:e.host.localInteractors.resolve}),n=e.device,r=t(n),i=e=>{n=e,r=t(e)};return Object.freeze({resolveOpenTarget:async t=>await e.host.appleApplications.resolveOpenTarget(n,t),prepareApplicationOpen:async t=>{let r=await P(e.host,n,e.signal,{deadlineAtMs:t.execution.startupDeadlineAtMs,onColdBootStart:t.prewarmRunnerOnColdBoot?()=>{e.host.appleApplications.prewarmRunnerCache(n,t.execution,e.signal).catch(()=>{})}:void 0});i(r)},openApplication:async t=>await ta(e.host,r,t,e.observation),applyRuntimeHints:async t=>await e.host.appleApplications.applyRuntimeHints(n,t),clearRuntimeHints:async t=>await e.host.appleApplications.clearRuntimeHints(n,t),closeApplication:async t=>{t.ensureReady&&i(await P(e.host,n,e.signal)),await ma(e.host,r,t)},finalizeApplicationClose:async t=>await ha(e.host,n,e.signal,t),prepareAppleRunner:async t=>{let r=await ga(e.host,n,e.signal,t);return i(r.readied),r.prepared},configureProviderPortReverse:Sa})}async function ta(e,t,n,r){let i={},a=L(t.device),o=_a(e,t,n,i),s=Bi(t.device,n,a);s.runnerDemand&&(i.runnerDemand=s.runnerDemand),Vi(e,t,n,s);let{shouldPrewarmRunner:c}=s,l=pa(t.device,n,a);a&&c&&!n.prewarmRunnerBeforeOpen&&o.schedule();try{await na(e,t,n,a,l,i);let u=await ra(t,n,a,i),d=ya(t.device,u?{...n,runtimeLaunchUrl:u}:n,a);await ia(o,c,n.prewarmRunnerBeforeOpen);let f=o.wasAwaited();await aa(t,n,d,a,i),await ua(o,c,s.awaitPrewarmAfterOpen),await da(e,t,n,a,f,l);let p=await Hi(e,t,n,a,{observation:r,answerConfirmation:ca(t,n,d),redispatchLaunchUrl:la(t,n,d)},i);return{appBundleId:n.appBundleId,timing:i,...p??{}}}catch(n){throw l&&await e.appleApplications.stopRunnerSession(t.device.id).catch(()=>{}),n}}async function na(e,t,n,r,i,a){if(!fa(n,r)||!n.target)return;let o=Date.now();oe(t.device.platform)&&!r&&!i&&await e.appleApplications.stopRunnerSession(t.device.id),await st({device:t.device,interactor:await t.resolveInteractor(n.execution,n.appBundleId),positionals:[n.appBundleId??n.target]}),r&&await e.clock.sleep(300,t.signal),a.relaunchCloseDurationMs=R(o)}async function ra(e,t,n,i){if(!Te(t.runtimeHints))return;let a=Date.now(),o=n?await(await $i()).resolveExpoDevClientLaunchUrl(e.device,t):void 0;if(!o){if(!t.applyRuntimeHints)throw new r(`COMMAND_FAILED`,`Runtime hint operation was not admitted for this open.`,{reason:`runtime-hints-operation-missing`});await t.applyRuntimeHints({appId:t.appBundleId,values:t.runtimeHints})}return i.runtimeHintsDurationMs=R(a),o}async function ia(e,t,n){!t||!n||(e.schedule(!0),await e.wait())}async function aa(e,t,n,r,i){let a=Date.now();await ct({device:e.device,interactor:await e.resolveInteractor(t.execution,t.appBundleId),positionals:n.positionals,appBundleId:t.appBundleId,execution:t.execution,...r&&t.relaunch&&!t.execution.clearAppState?{terminateRunningApp:!0}:{}}),i.openDispatchDurationMs=R(a),await oa(e,t,n.followUpUrl,i)}async function oa(e,t,n,r){if(!n){r.launchUrlDurationMs=0;return}let i=Date.now();await sa(e,t,n),r.launchUrlDurationMs=R(i)}async function sa(e,t,n){let r={...t.execution,clearAppState:void 0,launchConsole:void 0,launchArgs:void 0};await ct({device:e.device,interactor:await e.resolveInteractor(r,t.appBundleId),positionals:[n],appBundleId:t.appBundleId,execution:r})}function ca(e,t,{confirmation:n}){if(n)return async()=>{let{answerSimulatorLaunchConfirmation:r}=await Zi();return await r(e.device,n,e.resolveInteractor(t.execution,n.appBundleId),e.signal)}}function la(e,t,{confirmation:n}){if(n)return async()=>{await sa(e,t,n.url)}}async function ua(e,t,n){t&&!e.wasScheduled()&&e.schedule(),n?await e.wait():e.recordUnawaited()}async function da(e,t,n,r,i,a){!y(t.device)||!r&&!a||!n.relaunch&&!i||r&&!i&&!await e.appleApplications.hasLiveRunnerSession(t.device,n.execution)||await e.appleApplications.notifyRunnerAppRelaunched(t.device,n.execution,t.signal)}function fa(e,t){return!!(e.relaunch&&e.target)&&!(t&&!e.execution.clearAppState)}function pa(e,t,n){return e.kind===`device`&&e.appleOs===`ios`&&fa(t,n)}async function ma(e,t,n){oe(t.device.platform)&&!L(t.device)&&await e.appleApplications.stopRunnerSession(t.device.id),await st({device:t.device,interactor:await t.resolveInteractor(n.execution,n.appBundleId),positionals:n.positionals}),L(t.device)&&await e.clock.sleep(300,t.signal)}async function ha(e,t,n,r){r.daemonShutdown||await e.appleApplications.releaseRunnerOnClose(t.id,{retain:r.retainRunner}),await e.appleApplications.dismissCloseAlerts(t,r).catch(()=>{});let i=r.shutdownTarget&&L(t)?await e.deviceShutdown.apple.shutdownTarget(t,n):void 0;return i===void 0?{}:{shutdown:i}}async function ga(e,t,n,r){let i=Date.now()+r.timeoutMs,a=performance.now();return await ee(`prepare_apple_runner`,async()=>{let o=await P(e,t,n,{deadlineAtMs:i}),s=Math.max(1,i-Date.now());return _({phase:`prepare_apple_runner`,durationMs:performance.now()-a,data:{event:`runner_start`,timeoutMs:r.timeoutMs,remainingMs:i-Date.now()}}),{readied:o,prepared:await e.appleApplications.prepareRunner(o,{...r,timeoutMs:s},n)}},()=>({timeoutMs:r.timeoutMs,remainingMs:i-Date.now()}),`readiness_start`)}function _a(e,t,n,r){let i,a=!1,o=va(t.device,n)?{healthCheck:!1}:void 0;return{schedule:(a=!1)=>{i||=(r.runnerPrewarmKind=`session`,r.runnerPrewarmScheduled=!0,o?e.appleApplications.prewarmRunnerSession(t.device,n.execution,t.signal,a,o):e.appleApplications.prewarmRunnerSession(t.device,n.execution,t.signal,a))},wait:async()=>{if(!i||a)return;a=!0;let e=Date.now();await i,r.runnerPrewarmWaited=!0,r.runnerPrewarmDurationMs=R(e)},wasAwaited:()=>a,wasScheduled:()=>i!==void 0,recordUnawaited:()=>{i&&!a&&(r.runnerPrewarmWaited=!1)}}}function va(e,t){return e.kind===`device`&&e.appleOs===`ios`&&!t.hasExistingSession&&!t.relaunch&&!t.prewarmRunnerBeforeOpen}function ya(e,t,n){let r=t.runtimeLaunchUrl?.trim(),i=t.positionals.length===1?t.positionals[0]?.trim():void 0;if(!r||!i||d(i))return{positionals:t.positionals};let a=ba(e,t.appBundleId,r),o=a?{confirmation:a}:{};return n&&!xa(t)?{positionals:[i,r],...o}:{positionals:t.positionals,followUpUrl:r,...o}}function ba(e,t,n){if(e.appleOs===`ios`&&e.kind===`simulator`&&!(t===void 0||l(n)))return{url:n,appBundleId:t}}function xa(e){return e.execution.clearAppState===!0||!!e.execution.launchConsole?.trim()||!!e.execution.launchArgs?.length}function L(e){return y(e)&&e.kind===`simulator`}function R(e){return Math.max(0,Date.now()-e)}async function Sa(){throw new r(`UNSUPPORTED_OPERATION`,`This lifecycle operation is unavailable for Apple.`)}const Ca=Object.freeze({available:!0}),wa=Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`}),Ta=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Push notifications are supported on Apple simulators only.`}),Ea=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Da=Object.freeze({available:!1,reason:`unsupported-device-kind`});function Oa(e){let t=La(e);return Object.freeze({deployApp:t,materializeAppSource:t,deployMaterializedApp:t,sendPushNotification:Ra(e),uninstallApp:t})}function ka(e){let{host:t,device:n,signal:r}=e,i=Oa(n);return Object.freeze({...i.deployApp.available?{deployApp:async e=>await Aa(t,n,e,r),materializeAppSource:async e=>await t.appleDeployment.prepareArtifact(e,{signal:r}),deployMaterializedApp:async e=>await Ma(t,n,e,r),uninstallApp:async e=>await ja(t,n,e,r)}:{},...i.sendPushNotification.available?{sendPushNotification:async e=>(await Fa(t,n,e,r),{})}:{}})}async function Aa(e,t,n,r){if(n.replaceExisting)return await e.appleDeployment.withInvalidatedAppResolutionCache(t,async()=>{let i=await e.appleDeployment.resolveAppBundleId(t,n.app);await Pa(e,t,i,r);let a=await e.appleDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{appIdentifierHint:n.app,signal:r});try{return await Na(e,t,a.installablePath,r),{bundleId:i,launchTarget:i}}finally{await a.cleanup()}});let i=await e.appleDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{appIdentifierHint:n.app,signal:r});try{return await Ma(e,t,{artifact:i},r)}finally{await i.cleanup()}}async function ja(e,t,n,i){return await e.appleDeployment.withInvalidatedAppResolutionCache(t,async()=>{await P(e,t,i);let a;try{a=await e.appleDeployment.resolveAppBundleId(t,n.app,{installedOnly:!0})}catch(e){if(e instanceof r&&e.code===`APP_NOT_INSTALLED`&&n.app.trim().includes(`.`))return{wasInstalled:!1};throw e}return await Pa(e,t,a,i),{wasInstalled:!0,bundleId:a}})}async function Ma(e,t,n,r){return await Na(e,t,n.artifact.installablePath,r),{...n.artifact.bundleId?{bundleId:n.artifact.bundleId}:{},...n.artifact.appName?{appName:n.artifact.appName}:{},...n.artifact.bundleId?{launchTarget:n.artifact.bundleId}:{}}}async function Na(e,t,n,r){await P(e,t,r),await Ia(e,t.kind===`simulator`?{tool:`simctl`,args:C(t,[`install`,t.id,n])}:{tool:`devicectl`,args:[`device`,`install`,`app`,`--device`,t.id,n],timeoutMs:Jt},r,`Apple app install failed`)}async function Pa(e,t,n,r){await P(e,t,r),await Ia(e,t.kind===`simulator`?{tool:`simctl`,args:C(t,[`uninstall`,t.id,n])}:{tool:`devicectl`,args:[`device`,`uninstall`,`app`,`--device`,t.id,n]},r,`Apple app uninstall failed for ${n}`,{tolerate:e=>en(`${e.stdout}\n${e.stderr}`.toLowerCase())})}async function Fa(e,t,n,i){if(t.kind!==`simulator`)throw new r(`UNSUPPORTED_OPERATION`,`Apple push notifications require a simulator`);await P(e,t,i);let a=await e.temporaryFiles.create({prefix:`agent-device-ios-push-`,suffix:`.apns`});try{await a.writeText(`${JSON.stringify(n.payload)}\n`),await Ia(e,{tool:`simctl`,args:C(t,[`push`,t.id,n.appId,a.path])},i,`Apple push notification failed`)}finally{await a[Symbol.asyncDispose]()}}async function Ia(e,t,n,r,i){let a=await e.appleTools.run({...t,allowFailure:!0},n);return i?.tolerate?.(a)?a:g(a,r,e=>({cmd:`xcrun`,args:[t.tool,...t.args],...t.tool===`devicectl`?{hint:$t(e.stdout,e.stderr)??`Ensure the iOS device is unlocked, trusted, and available in Xcode > Devices, then retry.`}:{}}))}function La(e){return za(e)?e.kind!==`simulator`&&e.kind!==`device`?Da:e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?wa:Ca:Ea}function Ra(e){return za(e)?e.kind===`simulator`?Ca:Ta:Ea}function za(e){return y(e)&&e.appleOs!==`watchos`}const z=Object.freeze({available:!0}),Ba=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`back is supported on Apple simulators and physical devices.`}),Va=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function Ha(e){return e.kind!==`simulator`&&e.kind!==`device`?Ba:b(e)===`watchos`?Va:z}const Ua=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`home is supported on Apple simulators and physical devices.`}),Wa=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Ga=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`app-switcher is supported on Apple simulators and physical devices.`});function Ka(e,t){if(e.kind!==`simulator`&&e.kind!==`device`)return t;let n=b(e);return n===`macos`||n===`watchos`?Wa:z}function B(e){if(e.kind!==`simulator`&&e.kind!==`device`)return!1;let t=b(e);return t!==`tvos`&&t!==`macos`&&t!==`watchos`}const qa=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`orientation is supported on Apple simulators and physical devices.`}),Ja=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function Ya(e){return e.kind!==`simulator`&&e.kind!==`device`?qa:B(e)?z:Ja}const Xa=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`tv-remote is supported only on tvOS devices.`});function Za(e){return(e.kind===`simulator`||e.kind===`device`)&&se(e)?z:Xa}const V=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Qa=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`keyboard status/get is currently supported only on Android; use keyboard dismiss or enter on iOS`});function $a(e){return B(e)?Qa:V}function eo(e){return B(e)?z:V}function to(e){return B(e)?z:V}const no=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`No Apple leaf carries this system button.`}),ro=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`action-button is supported on iPhone and iPad simulators and physical devices.`}),io=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`The Action Button is iPhone and iPad hardware; tvOS, macOS, watchOS and visionOS have no such control.`});function ao(e){return e.kind!==`simulator`&&e.kind!==`device`?ro:ce(e)?z:io}const oo=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`hardware-button volume presses the iPhone/iPad volume key; this Apple leaf has none.`}),so=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`hardware-button volume is supported on physical iPhone and iPad; iOS Simulators refuse because XCUIDevice exposes no volume press there.`});function co(e){return ce(e)?e.kind===`device`?z:so:oo}function lo(e){return Object.freeze({...Pe({back:Ha(e)}),...Xe({unsupported:no,home:Ka(e,Ua),appSwitcher:Ka(e,Ga),actionButton:ao(e),volumeUp:co(e),volumeDown:co(e)}),...et({orientation:Ya(e)}),...rt({tvRemote:Za(e),buttonSupport:{supported:c(`apple`),unsupported:{available:!1,reason:`unsupported-platform-leaf`,hint:`This TV remote button is not supported on tvOS.`}}}),...$e({unsupported:V,status:$a(e),dismiss:eo(e),enter:to(e)})})}function uo(e){let{host:t,device:n,signal:r,admitted:i}=e,a=Object.keys(lo(n));return ut({device:n,signal:r,resolveInteractor:t.localInteractors.resolve,facts:Object.fromEntries(a.map(e=>[e,i[e]]))})}const H=Object.freeze({available:!0}),fo=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`clipboard is supported on Apple simulators and the macOS host.`}),po=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`settings is supported on Apple simulators and the macOS host.`}),mo=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`settings is supported on Apple simulators and the macOS host, not on physical devices of this OS.`}),ho=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:"Run `agent-device settings --help` for the settings each target serves."}),go=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`The macOS host supports settings appearance and settings permission <grant|reset> <accessibility|screen-recording|input-monitoring>.`}),_o=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Select a booted iPhone or iPad simulator: this setting runs only there.`}),vo=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`clipboard is supported on Apple simulators and the macOS host, not on physical devices of this OS.`}),yo=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function bo(e,t,n){if(e.kind!==`simulator`&&e.kind!==`device`)return t;let r=b(e);return r===`watchos`?yo:e.kind===`simulator`||r===`macos`?H:n}const xo=Object.freeze({available:!1,reason:`unsupported-device-scope`,hint:`This session holds one app of the Mac. Use a --surface desktop session for the clipboard and host settings.`});function So(e){return e.hostApp?xo:bo(e,fo,vo)}const Co=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`trigger-app-event is supported on Apple simulators and physical devices.`}),wo=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`alert is supported on Apple simulators and physical devices.`}),To=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`alert is supported on Apple simulators, the macOS host, and physical iOS devices.`});function Eo(e){if(e.kind!==`simulator`&&e.kind!==`device`)return wo;let t=b(e);return t===`watchos`?yo:e.kind===`simulator`||t===`ios`||t===`macos`?H:To}function Do(e){return e.kind!==`simulator`&&e.kind!==`device`?Co:b(e)===`watchos`?yo:H}function Oo(e){let t=So(e);return t.available?vo:t}function ko(e){let t=e.hostApp?xo:bo(e,po,mo);if(v(e))return lt({target:t,unsupported:go,write:{appearance:H,permission:H}});let n=ie(e)?H:_o;return lt({target:t,unsupported:ho,write:{wifi:H,airplane:H,location:H,appearance:H,"clear-app-state":H,"reset-keychain":H,permission:H,"text-size":n,faceid:n,touchid:n},read:{"text-size":n}})}function Ao(e){let t=So(e),n=Eo(e);return Object.freeze({...tt({unsupported:Oo(e),read:t,write:t}),...at({read:n,wait:n,accept:n,dismiss:n}),...it({triggerAppEvent:Do(e)}),...ko(e)})}function jo(e){let{host:t,device:n,signal:r}=e;return ut({device:n,signal:r,resolveInteractor:t.localInteractors.resolve,facts:Ao(n)})}const Mo=/Angle:\s*(-?\d+(?:[.,]\d+)?)\s*°/g;async function No(e,t={}){let n=[`devicectl`,`device`,`motion`,`hinge-angle`,`--device`,e.id,`--session-timeout`,`1`,`--timeout`,`5`],i=await Qt(n,{allowFailure:!0,signal:t.signal,timeoutMs:Xt}),a=Po(i.stdout)??Po(i.stderr);if(a!==void 0)return a;throw new r(`COMMAND_FAILED`,`CoreDevice reported no hinge angle sample`,p(i,{cmd:`xcrun`,args:n,stdout:i.stdout,stderr:i.stderr,deviceId:e.id,reason:`fold-hinge-angle-no-sample`,hint:`'devicectl device motion hinge-angle' printed no sample, and foldable poses can be verified only through that stream. The stderr in the details names the cause, such as a devicectl without the subcommand or a device CoreDevice cannot reach.`}))}function Po(e){let t;for(let n of e.matchAll(Mo)){let e=Number.parseFloat(n[1].replace(`,`,`.`));Number.isFinite(e)&&(t=e)}return t}var U=class extends r{buildFailureKind;buildFailureCode;buildDetails;constructor(e,t,n=`native build ${e}: ${t}`,r={},i){super(`COMMAND_FAILED`,n,{...r,nativeBuildFailure:e,nativeBuildFailureCode:t,...e===`cancelled`?{reason:`request_canceled`}:{}},i),this.name=`NativeBuildError`,this.buildFailureKind=e,this.buildFailureCode=t,this.buildDetails=r}};function W(e,t,n={},r){return new U(e,t,void 0,n,r)}function Fo(e,t,n=Date.now){if(t?.aborted)throw W(`cancelled`,`abort-signal`);return{clock:m.fromTimeoutMs(e,n()),now:n,signal:t}}function G(e,t){if(e.signal?.aborted)throw W(`cancelled`,`abort-signal`);let n=e.clock.remainingMs(e.now());if(n<=0)throw W(`timeout`,t);return Math.max(1,Math.floor(n))}function Io(e){return{run:e,readText:Vt,readBinary:Wt,writeText:zt,ensureDirectory:Kt,chmod:Gt,exists:Ht,rename:Bt,remove:qt,acquireLock:Lo,processId:re,cpuArch:h}}async function Lo(e,t){let n=re(),r=t.deadline,i=me({lockDirPath:e,owner:{pid:n,startTime:te(n),acquiredAtMs:Date.now()},timeoutMs:G(r,`cache-lock-deadline`),pollMs:100,description:t.description}),a=r.signal;if(!a)try{return await i}catch(e){throw Ro(e,r)}let o=!1,s,c=new Promise((e,t)=>{s=()=>{o=!0,t(W(`cancelled`,`abort-signal`))},a.addEventListener(`abort`,s,{once:!0}),a.aborted&&s()});try{return await Promise.race([i,c])}catch(e){throw o&&i.then(e=>e().catch(()=>void 0),()=>void 0),Ro(e,r)}finally{a.removeEventListener(`abort`,s)}}function Ro(e,t){return t.clock.isExpired()&&!(e instanceof U&&e.buildFailureKind===`cancelled`)?W(`timeout`,`cache-lock-deadline`):e}async function zo(e,t){let n=await Vo(e,`xcodebuild`,[`-version`],t),r=await Vo(e,`sw_vers`,[`-productVersion`],t),i=await Vo(e,`sw_vers`,[`-buildVersion`],t),a=await Bo(e,t);if(a!==`arm64`&&a!==`x86_64`)throw W(`unsupported`,`simulator-architecture-unsupported`,{architecture:a});return{xcode:n,macosProductVersion:r,macosBuild:i,architecture:a}}async function Bo(e,t){let n=G(t,`host-arch-deadline`),r=t.signal,i,a,o=new Promise((e,t)=>{i=setTimeout(()=>t(W(`timeout`,`host-arch-deadline`)),n),i.unref?.(),a=()=>t(W(`cancelled`,`abort-signal`)),r?.addEventListener(`abort`,a,{once:!0})});try{return await Promise.race([e.cpuArch(),o])}finally{clearTimeout(i),a&&r?.removeEventListener(`abort`,a)}}async function Vo(e,t,n,r){let i=await Ho(e,t,n,r);if(i.exitCode!==0)throw W(`unsupported`,`toolchain-probe-failed`,{command:t,exitCode:i.exitCode,stderr:i.stderr.slice(0,1024)});let a=(i.stdout||i.stderr).trim();if(!a)throw W(`unsupported`,`toolchain-probe-empty`,{command:t});return a}async function Ho(e,t,n,r){let i=[],a;for(let o=1;;o+=1){let s;try{s=Math.min(tn,G(r,`toolchain-probe-deadline`))}catch(e){throw a??e}i.push(s);try{return await Go(e,t,n,r,s)}catch(e){if(a=Uo(e,t,r,i),o>=2)throw a}}}function Uo(e,t,r,i){if(n(e))throw W(`cancelled`,`abort-signal`,{},e);if(!ne(e))throw e;if(r.signal?.aborted)throw W(`cancelled`,`abort-signal`);return Wo(t,i,e)}function Wo(e,t,n){let r=t.length;return W(`timeout`,`toolchain-probe-stalled`,{command:e,attemptTimeoutsMs:[...t],hint:`${e} did not answer within ${t[r-1]}ms on ${r} attempt(s). A toolchain probe that cannot answer is a host condition rather than a toolchain defect: run \`${e}\` by hand until it answers, then retry.`},n)}function Go(e,t,n,r,i){return e.run(t,n,{allowFailure:!0,signal:r.signal,timeoutMs:i})}const Ko=`manifest.json`;async function qo(e){let{host:t,deadline:n,cacheRoot:r,binaryFilename:i}=e,a=hn(`sha256`).update(JSON.stringify(e.keyInputs)).digest(`hex`).slice(0,32),o=w.join(r,a);return await he({acquire:()=>t.acquireLock(w.join(r,`${a}.lock`),{deadline:n,description:e.lockDescription}),task:async()=>{let s=await Jo(t,o,i,a,n);if(s)return{path:s,cacheKey:a};G(n,`native-build-deadline`),t.exists(o)&&await t.remove(o),G(n,`native-build-deadline`),await t.ensureDirectory(r);let c=w.join(r,`.${a}.${t.processId()}.tmp`);G(n,`native-build-deadline`),await t.remove(c);try{G(n,`native-build-deadline`),await t.ensureDirectory(c);let r=w.join(c,i);await e.build(r),G(n,`native-build-deadline`),await t.chmod(r,493);let s=await Xo(t,r),l={...e.keyInputs,cacheKey:a,binarySha256:s};return await t.writeText(w.join(c,Ko),`${JSON.stringify(l,null,2)}\n`),G(n,`native-build-deadline`),await t.rename(c,o),{path:w.join(o,i),cacheKey:a}}catch(e){throw await t.remove(c),e}}})}async function Jo(e,t,n,r,i){let a=w.join(t,n),o=w.join(t,Ko);if(!(!e.exists(a)||!e.exists(o)))try{let t=JSON.parse(await e.readText(o));return t.cacheKey!==r||typeof t.binarySha256!=`string`?void 0:(G(i,`native-cache-hash-deadline`),await Xo(e,a)===t.binarySha256?a:void 0)}catch(e){if(Yo(e))throw e;return}}function Yo(e){return e instanceof U&&(e.buildFailureKind===`cancelled`||e.buildFailureKind===`timeout`)}async function Xo(e,t){return hn(`sha256`).update(await e.readBinary(t)).digest(`hex`)}async function Zo(e,t,n,r){let i=hn(`sha256`);for(let a of n){let n=w.join(t,a);if(G(r,`native-source-fingerprint-deadline`),!e.exists(n))throw W(`unsupported`,`native-source-missing`,{filePath:n});i.update(a),i.update(`\0`),i.update(await e.readBinary(n)),i.update(`\0`)}return i.digest(`hex`)}async function Qo(e){let t=Math.min(e.budgetMs,G(e.deadline,`native-build-deadline`));try{return await e.host.run(`xcrun`,[...e.argv],{signal:e.deadline.signal,timeoutMs:t,allowFailure:!0})}catch(n){throw ne(n)?W(`timeout`,`native-build-stalled`,{timeoutMs:t,hint:`The Simulator SDK toolchain did not answer within ${t}ms, which stopped the ${e.label} build before clang reported anything. Run \`xcrun --sdk iphonesimulator clang --version\` by hand until it answers, then retry.`},n):n}}const $o=`Fold.m`,es=3e4,ts=tn+es;async function ns(e={}){let t=e.host??rs(),n=Fo(ts,e.signal);try{let r=e.sourceRoot??w.join(ge(),`apple`,`fold-helper`),i=await Zo(t,r,[$o],n),a=await zo(t,n);return await qo({host:t,deadline:n,lockDescription:`iOS Simulator fold helper cache`,cacheRoot:e.cacheRoot??w.join(Ut(),`.agent-device`,`fold-helper`),binaryFilename:`fold-helper`,keyInputs:{schemaVersion:1,sourceHash:i,toolchain:a,compileArgv:is({sourceRoot:``,outputPath:``})},build:e=>as(t,n,r,e)})}catch(e){throw os(e)}}function rs(){return Io(Zt)}function is(e){return[`--sdk`,`iphonesimulator`,`clang`,`-mios-simulator-version-min=15.0`,`-fobjc-arc`,`-Wall`,`-Wextra`,`-framework`,`Foundation`,`-framework`,`IOKit`,w.join(e.sourceRoot,$o),`-o`,e.outputPath]}async function as(e,t,n,r){let i=await Qo({host:e,deadline:t,argv:is({sourceRoot:n,outputPath:r}),budgetMs:es,label:`fold helper`});if(i.exitCode!==0||!e.exists(r))throw ss(p(i))}function os(e){return!(e instanceof U)||e.buildFailureKind===`cancelled`?e:ss({...e.buildDetails,cause:e.buildFailureCode},e)}function ss(e,t){return new r(`COMMAND_FAILED`,`Unable to build the simulator fold helper`,{hint:`Select an Xcode with the iOS simulator SDK and foldable HID support using DEVELOPER_DIR.`,...e,reason:`fold-helper-build-failed`},t)}async function cs(e,t,n){n?.throwIfAborted();let i=await ns({signal:n});n?.throwIfAborted();let a=typeof t==`string`?0:t.at(-1).atMs,o=typeof t==`string`?t:JSON.stringify(t),s=await on(e,[`spawn`,e.id,i.path,o],{signal:n,timeoutMs:a+1e4,kill:{signal:`SIGTERM`,graceMs:1e3},allowFailure:!0});if(s.exitCode!==0)throw new r(`COMMAND_FAILED`,`Unable to send the simulator hinge pose`,p(s,{reason:`fold-hid-dispatch-failed`,deviceId:e.id}))}async function ls(e,t,n={}){n.signal?.throwIfAborted(),un(e,`fold`);let r=t,i=r.keyframes?.at(-1)?.angle,a=r.pose??s(i);fs(e,await dn(e,{signal:n.signal})),await cs(e,r.keyframes??a,n.signal),_({level:`info`,phase:`apple_fold_pose_dispatched`,data:{deviceId:e.id,pose:a}});let o=await ps(e,a,n.signal,i),c=await Ss(e,n.signal);return{pose:s(o),hingeAngleDegrees:o,...c?{screen:Cs(c)}:{}}}function us(e){return e instanceof r&&e.details?.reason===`fold-hinge-angle-no-sample`}async function ds(e,t,n,i,a){let o=await Ss(e,n);return new r(`COMMAND_FAILED`,`${e.name} received the ${t} pose request, but the first hinge-angle read returned no sample to verify it`,{deviceId:e.id,requestedPose:t,...i===void 0?{}:{targetAngleDegrees:i},reason:`fold-pose-dispatched-unverified`,...o?{screen:Cs(o)}:{},...a instanceof r?{hingeReadFailure:a.details}:{},hint:`The pose request was sent and the device may have followed it, but the first hinge-angle read returned no sample, so fold cannot confirm it. Take a screenshot or snapshot to see which panel is lit; hingeReadFailure names why the read failed.`},a)}function fs(e,t){if(t.unresolved)throw new r(`COMMAND_FAILED`,`CoreDevice reported no display table for this simulator`,{deviceId:e.id,hint:`fold needs 'devicectl device info displays' to tell a foldable from a single-panel simulator; update Xcode to a version that ships the display-information feature.`});if(!t.multiScreen)throw new r(`UNSUPPORTED_OPERATION`,`${e.name} is not a foldable simulator: fold requires more than one integrated panel`,{deviceId:e.id,reason:`single-panel-device`,hint:`fold sets the hinge angle of a foldable simulator such as iPhone Duo; this simulator reports one integrated panel, so it has no hinge to pose.`})}async function ps(e,t,n,r){let i,a;for(let o=1;o<=4;o+=1){n?.throwIfAborted(),a=i;try{i=await No(e,{signal:n})}catch(a){throw i!==void 0||!us(a)?a:await ds(e,t,n,r,a)}if(ms(i,a,t,r))return i}throw _s(e,t,i,a,r)}function ms(e,t,n,r){return r===void 0?s(e)===n?n!==`half-open`||t!==void 0&&vs(e,t):!1:hs(e,t,r)}function hs(e,t,n){return gs(e,n)?n===0||n===180||t!==void 0&&gs(t,n)&&Math.abs(e-t)<=.5:!1}function gs(e,t){return t===void 0||e!==void 0&&Math.abs(e-t)<=.5}function _s(e,t,n,i,a){return gs(n,a)?a!==void 0&&n!==void 0?xs(e,s(n),n,i):n!==void 0&&t===`half-open`&&s(n)===t?xs(e,t,n,i):bs(e,t,n):new r(`COMMAND_FAILED`,`The hinge did not reach the final keyframe angle`,{reason:`fold-angle-unverified`,targetAngleDegrees:a,hingeAngleDegrees:n,deviceId:e.id})}function vs(e,t){return s(e)===`half-open`&&s(t)===`half-open`&&Math.abs(e-t)<=.5}function ys(e,t,n){return{deviceId:e.id,requestedPose:t,observedPose:n===void 0?void 0:s(n),hingeAngleDegrees:n}}function bs(e,t,n){return new r(`COMMAND_FAILED`,`${e.name} did not reach the ${t} pose: CoreDevice still reports a hinge angle of ${n}°`,{...ys(e,t,n),reason:`fold-pose-unverified`,hint:`The simulator HID command completed, but the hinge did not follow. Verify that the selected Xcode and simulator runtime support foldable HID control, then retry.`})}function xs(e,t,n,i){return new r(`COMMAND_FAILED`,`${e.name} was observed ${t} at ${n}° but did not settle: 4 hinge reads never held two consecutive angles within ${Yt}° of each other`,{...ys(e,t,n),reason:`fold-pose-unsettled`,...i===void 0?{}:{previousHingeAngleDegrees:i},hint:`The hinge reached the requested pose and was still moving when the read budget ended. Retry the fold, then read the angle directly with xcrun devicectl device motion hinge-angle --device <udid> --session-timeout 1 --timeout 5 to see whether the simulator holds the pose.`})}async function Ss(e,t){let n=await dn(e,{signal:t});if(!(n.unresolved||n.ambiguous))return n.activeDisplay}function Cs(e){return{display:e.name,coordinateSpace:o,widthPt:Math.round(e.widthPx/e.pointScale),heightPt:Math.round(e.heightPx/e.pointScale)}}const ws=Object.freeze({available:!0}),Ts=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`fold is supported on foldable iPhone simulators controlled through simulator HID; a physical device is folded by hand.`}),Es=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`fold poses the hinge of a foldable iPhone; tvOS, macOS, watchOS and visionOS simulators have no hinge.`});function Ds(e){return{available:!1,reason:`unsupported-device-scope`,hint:`fold cannot resolve a simulator scoped to the set at "${e}": CoreDevice's display inventory and hinge-angle readback need a simulator in the default set, so the pose could not be verified. Run fold without --ios-simulator-device-set.`}}function Os(e){if(e.kind!==`simulator`)return Ts;let t=b(e);return t!==`ios`&&t!==`ipados`?Es:e.simulatorSetPath?Ds(e.simulatorSetPath):ws}function ks(e){return At({fold:Os(e)})}function As(e){let{device:t,signal:n}=e;return x(ks(t).setFoldPose,()=>({setFoldPose:async e=>(n.throwIfAborted(),await ls(t,e,{signal:n}))}))}function js(e,t,n){let r=Qe({device:t.device,signal:t.signal,resolveInteractor:e.localInteractors.resolve}),i=async i=>{if(i.options?.observeOnly===!0)return await r.captureSnapshot(i);let a=v(t.device)?pe(i.options?.surface,t.appBackend):void 0;if(a)return await e.snapshot.captureSurface(t.device,{...i.options,surface:a},Ze(t.signal,i));if(!n)return await r.captureSnapshot(i);let o=Ze(t.signal,i);return await n.capture(t.device,i,o,async e=>await r.captureSnapshot(e))};return Object.freeze({captureSnapshot:i,captureSnapshotWithCustomActions:i,captureSnapshotWithoutActiveApp:i})}function Ms(e,t){return Object.freeze({findText:async n=>{let r=await Ns(e,t,n);if(!r)return{found:!1};let i=await e.localInteractors.resolve(t.device,{...n.execution,...r});return i.findText?await i.findText(n.text,r):{found:!1}}})}async function Ns(e,t,n){let r=n.options?.appBundleId;if(r===void 0||v(t.device)&&fe(n.options?.surface,t.appBackend)===`macos-helper`)return;let i=n.signal?AbortSignal.any([t.signal,n.signal]):t.signal;if(i.throwIfAborted(),await Ps(e,t.device,n.execution))return{appBundleId:r,signal:i}}async function Ps(e,t,n){return!I(t)||await e.appleApplications.hasLiveRunnerSession(t,n??{})}function Fs(e){return Object.freeze({querySelector:async t=>{let n=t.signal?AbortSignal.any([e.signal,t.signal]):e.signal;n.throwIfAborted();let r={...t.execution,signal:n},{queryAppleRunnerSelector:i}=await import(`./runner-selector-query.js`),a=await i(e.device,t.selector,t.options?.appBundleId,r),o=Is(a);return Object.freeze({found:a.found===!0,...o?{node:o}:{}})}})}function Is(e){let t=e.nodes;if(!Array.isArray(t))return;let n=t[0];if(!n||typeof n!=`object`)return;let r=u(n.rect);if(r)return Object.freeze({rect:r,hittable:n.hittable===!0})}const K=Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`The native macOS app backend never starts the XCTest runner, which this command needs. Unset AGENT_DEVICE_MACOS_APP_BACKEND to use XCTest.`});function Ls(e,t){return!v(e)||t!==`native`?{}:Object.freeze({screenRecordingStart:K,screenRecordingReattach:K,prepareAppleRunner:K,longPressPoint:K,...Pe({back:K}),...Le({unsupported:K})})}function Rs(e){let t,n=!1,r=async()=>(t??=import(`./host3.js`).then(e=>e.t).then(({createSnapshotSourceHost:t})=>import(`./adapter.js`).then(({createSimulatorSnapshotSource:n})=>n({host:t(e)}))),await t);return{acquire:async e=>n?{stage:`failed`,failure:{kind:`unsupported`,code:`source-closed`}}:await(await r()).acquire(e),close:async()=>{n=!0,t&&await(await t).close()}}}const zs=new Set([`notRunning`,`runningBackground`,`runningBackgroundSuspended`]);function Bs(){return async(e,t)=>{let n=ln(e.id);if(!n||n.liveness!==`ready`)return`unknown`;for(let r of je){let i=await Vs(e,r.bundleId,n.sessionId,t);if(i===`runningForeground`)return{kind:`foreground`,host:r};if(i===void 0||!zs.has(i))return`unknown`}return`background`}}async function Vs(t,n,r,i){try{let a=(await cn(t,{command:`appState`,appBundleId:n},{signal:AbortSignal.any([i.signal,AbortSignal.timeout(1e3)]),expectedRunnerSessionId:r,...i.requestId?{requestId:i.requestId}:{}})).applicationState;return e(a)?a:void 0}catch{i.signal.throwIfAborted();return}}function Hs(e=Date.now){let t=new Map;return async(n,r)=>{if(n.kind!==`simulator`)return`absent`;let i=t.get(n.id);if(i!==void 0&&e()-i.at<1e3)return{kind:`present`,host:i.host};t.delete(n.id);let a=await Us(n,r);return a!==`absent`&&a!==`unknown`&&t.set(n.id,{at:e(),host:a.host}),a}}async function Us(e,t){let n=await Promise.all(je.map(async e=>({host:e,pids:await Ws(e.processExecutable,t)}))),r=!1;for(let{host:i,pids:a}of n){if(a===`unknown`){r=!0;continue}for(let n of a){let a=await Gs(n,e.id,t);if(a===`unknown`)r=!0;else if(a)return{kind:`present`,host:i}}}return r?`unknown`:`absent`}async function Ws(e,t){let n=await Ks(`pgrep`,[`-f`,e],t);return n===`unknown`?`unknown`:n.exitCode===1?[]:n.exitCode===0?n.stdout.split(`
|
|
5
|
+
`).map(e=>Number.parseInt(e.trim(),10)).filter(e=>Number.isSafeInteger(e)&&e>0):`unknown`}async function Gs(e,t,n){let r=await Ks(`ps`,[`eww`,`-p`,String(e),`-o`,`command=`],n);return r===`unknown`||r.exitCode!==0?`unknown`:r.stdout.includes(`SIMULATOR_UDID=${t}`)?!0:!r.stdout.includes(`SIMULATOR_UDID=`)&&`unknown`}async function Ks(e,t,n){try{let r=await Zt(e,t,{allowFailure:!0,timeoutMs:3e3,...n?{signal:n}:{}});return{exitCode:r.exitCode,stdout:r.stdout}}catch{return`unknown`}}const qs=`system-surface-presented`,Js=`system-surface-host-lingering`,Ys=`window-coordinate-space-unresolved`,Xs=`app-window-not-full-screen`,Zs=new Set([`foreground-owner-unverified`,`foreground-owner-changed`]);function Qs(e,t={}){let n=t.source??Rs(e.hostEnvironment),i=t.resolveTarget??Di(),a=t.systemSurfacePresent??Hs(),o=t.systemSurfaceForeground??Bs(),s=new Set,c=new Map,l=e=>(hc(e,c,s),s.has(gc(e))),u=Li({source:n,resolveTarget:i,clock:e.clock,isBridgeDisabled:l});return Object.freeze({awaitObservable:u.awaitObservable,shutdown:async()=>await n.close(),capture:async(t,c,u,d)=>{if(!nc(t,c))return await sc(t,c,d);let f=await $s(t,c,u,o);if(f!==`background`&&f!==`unknown`)return await oc(t,c,d,f.host.bundleId);let p=f===`background`?`absent`:await a(t,u);if(p===`unknown`)return await ac(t.id,c,d,lc(t.id,c),q(c),`system-surface-probe-unavailable`,[mc()]);if(p!==`absent`)return await oc(t,c,d,p.host.bundleId);let m;try{m=await ec(e,i,t,c,u)}catch(e){return tc(u,e),J(`target-resolution-failed`,t,void 0,e),await ac(t.id,c,d,lc(t.id,c),q(c),`target-resolution-failed`,[mc()])}if(l(m))return J(`circuit-disabled`,t,m.generation),await ac(t.id,c,d,m,q(c),`circuit-disabled`);let h=q(c),g=await n.acquire({target:m,hint:_e(h),signal:u});if(g.stage===`failed`){if(g.failure.kind===`cancelled`)throw u.throwIfAborted(),new r(`COMMAND_FAILED`,`Simulator AX snapshot acquisition was cancelled.`,{reason:g.failure.code,...g.failure.details});let e=await pc(g.failure,m,t,c.options.appBundleId,u,i);return await rc(c,d,m,e,h,g.failure,s)}try{return await ee(`ios.snapshot-source.present`,async()=>await e.snapshot.presentIosAcquisition(g,c.options),{producer:`simulator-ax-bridge`})}catch(e){return await rc(c,d,m,{lineage:m,residue:[]},h,{kind:`malformed-tree`,code:`presentation-invariant`},s,e)}}})}async function $s(e,t,n,r){let i=t.execution?.requestId,a=await r(e,{signal:n,...i?{requestId:i}:{}});return a===`background`&&_({level:`debug`,phase:`ios_snapshot_route_surface_host_background`,data:{deviceId:e.id}}),a}async function ec(e,t,n,r,i){let a=r.options.appBundleId;for(;;)try{return await t(n,a,i)}catch(t){if(!ki(t))throw t;let i={requestId:r.execution?.requestId};if(await e.appleApplications.hasLiveRunnerSession(n,i))throw t}}function tc(e,t){if(e.aborted)throw n(t)?t:e.reason}function nc(e,t){return I(e)&&!!t.options?.appBundleId&&t.options?.customActions!==!0&&t.options?.preferredBackend===void 0}async function rc(e,t,n,r,i,a,o,s){return ic(a)&&o.add(gc(n)),J(a.code,{id:n.simulator.udid},n.generation,s,a.details),await ac(n.simulator.udid,e,t,r.lineage,i,a.code,r.residue)}function ic(e){return e.kind!==`preparing`&&e.code!==Ys&&e.code!==Xs&&!Zs.has(e.code)}async function ac(e,t,n,r,i,a,o=[]){return cc(e,await n(t),r,i,a,o)}async function oc(e,t,n,r){let i=await n(t),a=i.systemSurface?qs:Js;return i.systemSurface||J(a,e,void 0,void 0,{detectedHost:r}),cc(e.id,i,lc(e.id,t),q(t),a)}async function sc(e,t,n){let r=await n(t),i=r.systemSurface;return i?{...r,comparisonIdentity:dc(uc(e.id,i.bundleId),q(t),[])}:r}function cc(e,t,n,r,i,a=[]){let o=t.systemSurface;return{...t,comparisonIdentity:dc(o?uc(e,o.bundleId):n,r,[...o?[]:a,{kind:`fallback-source`,producer:`apple-runner`}]),warnings:[...t.warnings??[],fc(i,n,o!==void 0)]}}function lc(e,t){return{targetId:`${e}:${t.options.appBundleId}`}}function uc(e,t){return{targetId:`${e}:${t}`}}function dc(e,t,n){return Object.freeze({producer:`apple-runner`,intent:t.acquisitionIntent,lineage:Object.freeze({...e.targetId?{targetId:e.targetId}:{},...e.generation?{generation:e.generation}:{}}),presentationKey:ve(t),residue:Object.freeze([...n])})}function fc(e,t,n){return e===qs?`Simulator AX snapshot inapplicable (${e}); used XCTest to read the system surface presented over the app.`:e===Js?`Simulator AX snapshot inapplicable (${e}); used XCTest, which read app content: the system surface host process was still running but no longer presenting.`:n?`Simulator AX snapshot unavailable (${e}); used XCTest, which read the system surface presented over the app.`:e===`bridge-preparation-pending`?`Simulator AX snapshot unavailable (${e}); used XCTest for this capture while the bridge is still being prepared.`:Zs.has(e)?`Simulator AX snapshot unavailable (${e}); used XCTest for this capture, while another surface owned the foreground.`:e===Xs?`Simulator AX snapshot unavailable (${e}); used XCTest for this capture, while the app window did not fill the screen; XCTest geometry for a windowed app can also be offset from the screen.`:e===Ys?`Simulator AX snapshot unavailable (${e}); used XCTest for this capture, which reports captured geometry in the app's own orientation space.`:`Simulator AX snapshot unavailable (${e}); used XCTest for ${t.generation?`this app generation`:`an unverified app generation`}.`}async function pc(e,t,n,r,i,a){if(e.kind!==`stale-target`)return{lineage:t,residue:[]};try{return{lineage:await a(n,r,i,`refresh`),residue:[]}}catch(e){return i.throwIfAborted(),J(`fallback-target-resolution-failed`,n,void 0,e),{lineage:{targetId:t.targetId},residue:[mc()]}}}function mc(){return{kind:`unknown-generation`,captureId:gn()}}function q(e){return ye({raw:e.options?.raw,interactiveOnly:e.options?.interactiveOnly,depth:e.options?.depth,scope:e.options?.scope,customActions:e.options?.customActions,acquisitionIntent:e.options?.acquisitionIntent})}function hc(e,t,n){let r=t.get(e.targetId);r&&r!==e.generation&&n.delete(`${e.targetId}:${r}`),t.set(e.targetId,e.generation)}function gc(e){return`${e.targetId}:${e.generation}`}function J(e,t,n,r,i){_({level:`debug`,phase:`ios_snapshot_route_fallback`,data:{reason:e,deviceId:t.id,...n?{generation:n}:{},...r?{error:r instanceof Error?r.message:String(r)}:{},...i?{details:i}:{}}})}const Y=le(`apple`),X=Object.freeze({available:!0}),Z=S(`unsupported-platform-leaf`),_c=S(`unsupported-platform-leaf`,`viewport resizes web targets only (--platform web). Apple screen geometry is fixed by the selected simulator or device type — open a different simulator to test another screen size.`),vc=S(`unsupported-platform-leaf`,`the stateless audio page probe is a web-session operation; Apple targets use the host capture.`),yc=S(`unsupported-device-backend`,`perf requires an Apple simulator, macOS device, or CoreDevice-backed physical Apple device.`),bc=S(`unsupported-device-kind`,`focus is supported on Apple simulators and physical devices.`),xc=S(`unsupported-platform-leaf`,`telephony simulates calls and SMS through the Android emulator console; Apple simulators and devices expose no host control that injects a call or text message.`),Sc=S(`unsupported-platform-leaf`,`Apple appstate is unavailable here: the runner reads the session app's XCUIApplication state on iOS-family simulators and physical devices only, and the Apple target answers no sessionless foreground probe. The per-command answer is the targetActivation disclosure, which a capture carries when its command had to re-activate the session app (#2682).`);function Cc(e){return!y(e)||e.appleOs===`watchos`?Sc:e.kind===`simulator`||e.kind===`device`?X:Sc}const wc=S(`unsupported-provider-mode`,`Headless boot is supported only for local Android emulators.`),Tc=S(`unsupported-platform-leaf`,`watchOS has no XCUITest-driveable UI, so element text comes from the captured tree only.`),Ec=S(`unsupported-device-kind`),Dc=S(`unsupported-platform-leaf`,`watchOS open is not supported because XCUITest cannot drive watchOS UI.`),Oc=S(`unsupported-platform-leaf`,`watchOS runner preparation is not supported because XCUITest cannot drive watchOS UI.`),kc=S(`unsupported-platform-leaf`,`watchOS close is not supported because XCUITest cannot drive watchOS UI.`),Ac=S(`unsupported-device-kind`,`Runtime hints are supported only for local iOS-family simulators and Android devices.`),jc=Q(`open is supported only for Apple simulators and devices.`),Mc=Q(`prepare is supported only for Apple simulators and devices.`),Nc=Q(`close is supported only for Apple simulators and devices.`),Pc=S(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),Fc=S(`unsupported-device-kind`,`shutdown is supported only for Apple simulators and Android emulators.`),Ic=Q(`snapshot is supported only for Apple simulators and devices.`),Lc=S(`unsupported-platform-leaf`,`Re-run without --actions, or target an iOS simulator.`),Rc=S(`unsupported-platform-leaf`,`screenshot is not supported on watchOS because XCUITest cannot drive watchOS UI.`),zc=Q(`screenshot is supported only for Apple simulators and devices.`),Bc=S(`owner-capability-missing`,`Open the app under test before capturing its snapshot.`);function Q(e){return S(`unsupported-device-kind`,e)}function Vc(e){return!y(e)||e.appleOs===`watchos`?Z:e.kind===`simulator`?X:Fc}function Hc(e){let t=Uc(e),n=Wc(e),r=Gc(e),i=Kc(e);return Ee({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:i,clearRuntimeHints:i,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:n,configureProviderPortReverse:Pc})}function Uc(e){return b(e)===`watchos`?Dc:e.kind===`simulator`||e.kind===`device`?X:jc}function Wc(e){return b(e)===`watchos`?Oc:e.kind===`simulator`||e.kind===`device`?X:Mc}function Gc(e){return b(e)===`watchos`?kc:e.kind===`simulator`||e.kind===`device`?X:Nc}function Kc(e){return b(e)!==`watchos`&&y(e)&&e.kind===`simulator`?X:Ac}function qc(e){return e.appleOs===`watchos`?S(`unsupported-platform-leaf`,`watchOS app inventory is not supported.`):e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?S(`unsupported-device-backend`,`App inventory is available only on CoreDevice-backed physical iOS devices.`):X}function $(e){return e.kind===`simulator`||e.kind===`device`?X:bc}function Jc(e){let t=or(e),n=Qs(e),r,i=t=>v(t)?r??=pn(e.hostEnvironment.env):`xctest`,a=async n=>{let r=await t.inspectFacts(n),a=Oa(n),o=Yr(n),s=o.available?await e.screenRecording.apple.availability(n):void 0,c=o.available&&s?.available===!1?S(`unsupported-provider-mode`,s.hint):o,l=n.appleOs===`watchos`?Z:X,u=v(n)||n.appleOs===`watchos`?Z:X,d=qc(n);return Object.freeze({device:r.device,operations:{...r.operations,...a,appState:Cc(n),networkDump:X,screenRecordingStart:c,screenRecordingReattach:c,screenRecordingCleanup:c,...$c(n),...Ie({capture:Qc(n)}),...ze({findText:Zc(n),querySelector:y(n)?$(n):Z}),...Ue({setViewport:_c}),...Je({focus:$(n)}),...wn(n),...Be({type:$(n)}),...ke({unsupported:Z,tap:$(n),longPress:$(n),fill:$(n),...y(n)?{tapElementSelector:$(n)}:{}}),...Ye({readTextAtPoint:Xc(n)}),...lo(n),...ks(n),sendTelephonyEvent:xc,...Ao(n),...Ne({capture:vn(n),query:vc}),...He(Yc(n)),ensureReady:l,bootTarget:u,bootTargetHeadless:wc,listApps:d,...Hc(n),shutdownTarget:Vc(n),...Ls(n,i(n))}})};return Object.freeze({owner:Y,ownsDevice:e=>e.platform===`apple`,inspectFacts:a,bind:async r=>{let o=await t.bind(r),s=await a(r.device),c=s.operations.screenRecordingStart,l=x(s.operations.appState,()=>_n(e,{device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),u=x(s.operations.querySelector,()=>Fs({device:r.device,signal:r.scope.signal})),d={...l,...u,...o.operations,...ka({host:e,device:r.device,signal:r.scope.signal}),networkDump:async t=>await ur(e,r.device,t,r.scope.signal),...x(c,()=>Xr({host:e,device:r.device,owner:Y,signal:r.scope.signal})),...x(s.operations.audioProbeStart,()=>vt({host:e.audioProbe.hostCapture,device:r.device,owner:Y})),...x(s.operations.perfFrames,()=>yn({resolveHost:()=>e.perf.apple,device:r.device,owner:Y})),...x(s.operations.captureSnapshot,()=>js(e,{device:r.device,signal:r.scope.signal,appBackend:i(r.device)},n)),...x(s.operations.captureScreenshot,()=>Ve({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...x(s.operations.focusPoint,()=>nt({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...Ke({device:r.device,signal:r.scope.signal,facts:s.operations,resolveInteractor:e.localInteractors.resolve}),...x(s.operations.scrollDirection,()=>Ge({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...x(s.operations.typeText,()=>Fe({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...x(s.operations.tapPoint,()=>Ae({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:s.operations,pause:async t=>await e.clock.sleep(t,r.scope.signal)})),...x(s.operations.readTextAtPoint,()=>qe({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...x(s.operations.findText,()=>Ms(e,{device:r.device,signal:r.scope.signal,appBackend:i(r.device)})),...uo({host:e,device:r.device,signal:r.scope.signal,admitted:s.operations}),...jo({host:e,device:r.device,signal:r.scope.signal}),...As({device:r.device,signal:r.scope.signal}),...x(s.operations.ensureReady,()=>({ensureReady:async()=>await P(e,r.device,r.scope.signal)})),...x(s.operations.bootTarget,()=>({bootTarget:async t=>await P(e,r.device,r.scope.signal,{deadlineAtMs:t.deadlineAtMs})})),...x(s.operations.listApps,()=>({listApps:async e=>{r.scope.signal.throwIfAborted();let{listIosApps:t}=await import(`./app-resolution.js`).then(e=>e.t);return(await t(e.device,e.filter)).map(e=>({id:e.bundleId,name:e.name}))}})),...we(ea({host:e,device:r.device,signal:r.scope.signal,observation:n}),s.operations),...x(s.operations.shutdownTarget,()=>({shutdownTarget:async()=>await e.deviceShutdown.apple.shutdownTarget(r.device,r.scope.signal)}))};return Object.freeze({device:o.device,owner:Y,facts:s,operations:Object.freeze(d),[Symbol.asyncDispose]:async()=>await o[Symbol.asyncDispose]()})},shutdown:async()=>{await Promise.all([t.shutdown(),n.shutdown()])}})}function Yc(e){let t=e.iosPhysicalDeviceBackend!==`xctest`&&b(e)!==`watchos`?X:yc;return{frames:t,memorySample:t,memorySnapshot:t,nativeCapture:t,profileReport:t}}function Xc(e){return b(e)===`watchos`?Tc:e.kind===`simulator`||e.kind===`device`?X:Ec}function Zc(e){return b(e)===`watchos`?Ic:e.kind===`simulator`||e.kind===`device`?X:Ic}function Qc(e){return b(e)===`watchos`?Rc:e.kind===`simulator`||e.kind===`device`?X:zc}function $c(e){let t=Zc(e);return Re({capture:t,customActions:t.available&&y(e)&&e.kind===`simulator`?X:Lc,withoutActiveApp:y(e)?Bc:t})}export{Io as a,U as c,Jc as createApplePlatformRuntime,xi as d,zo as i,Ci as l,Qo as n,Fo as o,Zo as r,G as s,qo as t,Si as u};
|
package/dist/src/runtime4.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{tt as e}from"./sdk-contracts.js";import{w as t}from"./sdk-device.js";import{s as n}from"./simctl.js";import{t as r}from"./simulator-state.js";const i=15e3;function a(e){return Object.freeze({canShutdownTarget:o,shutdownTarget:async(t,n)=>await s(e.appleTools,t,n)})}function o(e){return t(e)&&e.appleOs!==`watchos`&&e.kind===`simulator`}async function s(t,r,a){a.throwIfAborted();try{let e=await t.run({tool:`simctl`,args:n(r,[`shutdown`,r.id]),allowFailure:!0,timeoutMs:i},a);a.throwIfAborted();let o=l(e);return o.success?o:await c(t,r,a)===`Shutdown`?{...o,success:!0,exitCode:0}:o}catch(t){a.throwIfAborted();let n=e(t);return{success:!1,exitCode:-1,stdout:``,stderr:n.message,error:n}}}async function c(e,t,n){try{return await r(e,t,n,i)}catch{return n.throwIfAborted(),null}}function l(e){let t=e.exitCode??-1;return{success:t===0,exitCode:t,stdout:e.stdout,stderr:e.stderr}}export{a as createAppleShutdownRuntime};
|
package/dist/src/runtime5.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{R as e}from"./sdk-contracts.js";import{F as t}from"./sdk-device.js";import{en as n,on as r,sn as i}from"./sdk-batch.js";import{n as a}from"./device-shell.js";import{i as o,n as s}from"./durable-resource.js";import{n as c}from"./screen-recording-runtime.js";import{n as l,t as u}from"./application-lifecycle-runtime.js";import{n as ee}from"./async-lifecycle.js";import{i as d}from"./touch-runtime.js";import{r as f}from"./gesture-admission.js";import{B as p,C as te,I as ne,K as re,M as ie,N as ae,O as oe,R as se,T as ce,U as le,Y as ue,Z as m,_ as h,k as g,l as _,o as v,p as de,r as fe,v as pe,x as me}from"./tv-remote-runtime.js";import{r as he,u as ge}from"./application-lifecycle-interaction.js";import{t as _e}from"./local-interactor-operation-set.js";import{n as ve,t as y}from"./src4.js";import{n as b,t as x}from"./screen-recording-completion.js";import{t as S}from"./screen-recording-options.js";import{i as C,n as w}from"./perf-runtime-operation-builder.js";import{t as T}from"./app-log-runtime.js";import{randomUUID as E}from"node:crypto";import{setTimeout as D}from"node:timers/promises";const O=Object.freeze({resourceKind:T,version:1,encode:e=>({...e}),decode:e=>e.transport!==`harmony-hilog`||!A(e.outputPath)||!A(e.pidPath)?{status:`invalid`,message:`Invalid HarmonyOS app-log descriptor`}:{status:`decoded`,descriptor:Object.freeze({transport:`harmony-hilog`,outputPath:e.outputPath,pidPath:e.pidPath})}});function k(e){return s({resourceKind:T,sessionId:e.sessionId,device:{id:e.device.id,family:`harmonyos`,kind:e.device.kind,...e.device.target===void 0?{}:{target:e.device.target}},owner:e.owner,fence:e.fence,lifecycle:`open`,descriptor:o(O,e.descriptor)})}function A(e){return typeof e==`string`&&e.trim().length>0}function j(e){return y(e,{family:`harmonyos`,backend:`harmonyos`,label:`HarmonyOS`,codec:O,startUnavailableHint:`The selected HarmonyOS transport cannot start a background hilog stream.`,cleanupFailureMessage:`HarmonyOS app-log cleanup did not settle every owned resource`,doctor:async(e,t)=>({backend:`harmonyos`,checks:{},notes:t?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`]}),process:async({host:e,device:t,input:n,signal:r})=>{let i=await M(e,r);return{resolvePid:async r=>await ve(e,{executable:i,args:a(`hdc`,`shell`,[`pidof`,n.appBundleId],[`-t`,t.id]),allowFailure:!0,timeoutMs:5e3},r),command:e=>({kind:`host`,request:{executable:i,args:a(`hdc`,`shell`,[`hilog`,`-P`,e],[`-t`,t.id]),allowFailure:!0}})}},descriptor:({artifacts:e})=>({transport:`harmony-hilog`,...e}),envelope:({input:e,device:t,owner:n,descriptor:r})=>k({sessionId:e.sessionId,device:t,owner:n,fence:e.fence,descriptor:r})})}async function M(t,n){n.throwIfAborted(),await N(async()=>await t.toolchains.prepare(`harmonyos`),n),n.throwIfAborted();let r=await N(async()=>await t.commands.which(`hdc`),n);if(n.throwIfAborted(),!r)throw new e(`TOOL_MISSING`,`hdc not found in PATH`,{hint:`Install HarmonyOS Command Line Tools, then add its sdk/default/openharmony/toolchains directory to PATH.`});return r}async function N(e,t){try{return await e()}catch(e){throw t.throwIfAborted(),e}}function P(e){let{resolveHost:t,device:n}=e,r={available:!1,reason:`Dropped-frame sampling is currently available only on Android app sessions and connected iOS device app sessions.`};return Object.freeze({perfFrames:async()=>({metric:r,sampling:r}),perfMemorySample:async({appId:e})=>({metric:e?await C(t().sampleMemory(n,e)):w(`HarmonyOS`,`bundle`),sampling:{method:`hdc-shell-proc-status`,description:`Resident memory snapshot from HarmonyOS /proc/<pid>/status. Values are reported in kilobytes.`,unit:`kB`,topConsumerLimit:1}}),perfMemorySnapshot:async({kind:e})=>({artifact:{available:!1,kind:e??`memgraph`,reason:`Memory snapshot artifacts are not supported on harmonyos.`,hint:`Use perf memory sample where supported, or run the snapshot against Android, iOS simulator, or macOS.`,support:{platform:`harmonyos`,defaultKind:`memgraph`,androidHprof:!1,memgraph:!1,heapprofd:!1}},sampling:{method:`unsupported`,description:`HarmonyOS memory snapshot capture is not available through HDC.`,artifactOnly:!0}})})}const F=Object.freeze({resourceKind:c,version:1,encode:e=>({...e}),decode:e=>e.backend===`harmony-screen-recorder`&&typeof e.fileName==`string`&&xe(e.fileName)&&e.remotePath===`/data/local/tmp/${e.fileName}`?{status:`decoded`,descriptor:Object.freeze({backend:`harmony-screen-recorder`,fileName:e.fileName,remotePath:e.remotePath})}:{status:`invalid`,message:`Invalid HarmonyOS screen-recording descriptor`}});function ye(e){let{device:n,owner:r,input:i,descriptor:a}=e;return s({resourceKind:c,sessionId:i.sessionId,device:t(n),owner:r,fence:i.fence,lifecycle:`open`,descriptor:o(F,a)})}function be(e){return F.decode(e).status===`decoded`?{status:`cleanup-pending`,reason:`manual-recovery-required`,message:`HarmonyOS recorder ownership cannot be proven after daemon restart; no recorder was stopped.`}:{status:`cleanup-pending`,reason:`manual-recovery-required`}}function xe(e){return/^agent-device-recording-[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\.mp4$/i.test(e)}function Se(e){return e.kind===`device`?Object.freeze({available:!0}):Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`HarmonyOS recording is supported on physical devices only.`})}function Ce(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await we({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async()=>({status:`unreattachable`,reason:`transport-not-reattachable`,message:`HarmonyOS recordings cannot be reattached after daemon restart.`}),screenRecordingCleanup:async e=>be(e.envelope.descriptor.body)})}async function we(t){let{host:n,device:r,owner:i,input:a,signal:o}=t;if(a.scope===`app`)throw new e(`INVALID_ARGS`,`HarmonyOS recording captures the whole physical-device screen; use --scope device or --scope system`);S(a,{scopes:[`device`,`system`],fps:!1,exportQuality:!1,hideTouches:!1},e=>`HarmonyOS recordings do not support ${e.join(`, `)}`),o.throwIfAborted(),await n.screenRecording.outputs.prepare(a.outputPath);let s=`agent-device-recording-${E()}.mp4`,c={backend:`harmony-screen-recorder`,fileName:s,remotePath:`/data/local/tmp/${s}`},l;try{l=await n.screenRecording.harmony.start(r,s,o),o.throwIfAborted()}catch(e){throw o.aborted?(await L(n,r,c).catch(()=>{}),o.reason):e}z(l,`start`);try{o.throwIfAborted()}catch(e){throw await L(n,r,c).catch(()=>{}),e}let u=Te(a),d=!1,f=async()=>{d||=(z(await n.screenRecording.harmony.stop(r),`stop`),!0)},p=b(u,{finish:async e=>await Ee(n,r,e,c,f),forceCleanup:async()=>await L(n,r,c,f)});return Object.freeze({pendingHandle:new ee(p),envelope:ye({device:r,owner:i,input:a,descriptor:c})})}function Te(e){return Object.freeze({backend:`HarmonyOS ScreenRecorder`,outPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutPath:e.clientOutputPath},startedAt:Date.now(),scope:e.scope,showTouches:!1,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},gestureEvents:[]})}async function Ee(e,t,n,r,i){await i();let a=await e.screenRecording.harmony.findMedia(t,r.fileName);if(!a)throw Error(`failed to find finalized HarmonyOS recording '${r.fileName}'`);if(!await ke(e,t,r,a))throw Error(`failed to finalize HarmonyOS recording: ${r.fileName} did not produce a non-empty media file`);try{if((await e.screenRecording.harmony.pull(t,{remotePath:r.remotePath,outputPath:n.outPath})).exitCode!==0)throw Error(`failed to retrieve HarmonyOS recording`);let i=await e.screenRecording.finalize.complete({outputPath:n.outPath,showTouches:!1,gestureEvents:n.gestureEvents,targetLabel:`HarmonyOS recording`}),o=await De(e,t,r,a);return x(n,{...i,...Oe(i.warning,o)},{stopObservation:{recorder:`confirmed`},nativePathDisposition:o===void 0?`retired`:`retirable`,showTouches:!1})}catch(n){throw await e.screenRecording.harmony.remove(t,r.remotePath).catch(()=>{}),n}}async function De(e,t,n,r){let i=[];return await I(()=>e.screenRecording.harmony.remove(t,n.remotePath))||i.push(`staging artifact`),await I(()=>e.screenRecording.harmony.removeMedia(t,r))||i.push(`media-library artifact`),i.length===0?void 0:`HarmonyOS recording completed, but cleanup was not confirmed for the ${i.join(` and `)}.`}async function I(e){try{return await e()}catch{return!1}}function Oe(e,t){let n=[e,t].filter(e=>e!==void 0).join(` `);return n.length===0?{}:{warning:n}}async function ke(e,t,n,r){let i;for(let a=0;a<40;a+=1){if(await e.screenRecording.harmony.remove(t,n.remotePath).catch(()=>{}),await e.screenRecording.harmony.stageMedia(t,{mediaUri:r,remotePath:n.remotePath})){let r=await e.screenRecording.harmony.stagedFileSize(t,n.remotePath);if(r!==void 0&&r>0&&r===i)return!0;i=r!==void 0&&r>0?r:void 0}else i=void 0;a<39&&await e.clock.sleep(250)}return!1}async function L(e,t,n,r=async()=>{z(await e.screenRecording.harmony.stop(t),`stop`)}){let i=[await R(r),await R(async()=>{if(!await e.screenRecording.harmony.remove(t,n.remotePath))throw Error(`HarmonyOS recording staging artifact removal was not confirmed`)}),await R(async()=>await Ae(e,t,n.fileName))].find(e=>e!==void 0);return i===void 0?{status:`cleaned`}:{status:`cleanup-pending`,reason:`transport-failed`,message:i instanceof Error?i.message:`HarmonyOS recording cleanup failed`}}async function Ae(e,t,n){let r=await e.screenRecording.harmony.findMedia(t,n);if(r&&!await e.screenRecording.harmony.removeMedia(t,r))throw Error(`HarmonyOS recording media removal was not confirmed`)}async function R(e){try{await e();return}catch(e){return e}}function z(e,t){if(e.exitCode===0&&e.stdout.includes(`start ability successfully`))return;let n=e.stdout.trim()||e.stderr.trim()||`hdc exit ${e.exitCode}`;throw Error(`failed to ${t} HarmonyOS screen recording: ${n}`)}async function B(t,n){n.throwIfAborted();let{runHarmonyShell:r}=await import(`./hdc.js`),i=await r(t,[`aa`,`dump`,`-l`],{timeoutMs:15e3,signal:n});n.throwIfAborted();let a=je(i.stdout);if(!a)throw new e(`COMMAND_FAILED`,`Could not determine the foreground HarmonyOS app`,{hint:`Open an app on the target, then retry appstate.`});return a}function je(e){let t=e.split(/(?=^\s*Mission ID #)/m);for(let e of t){if(!/\bstate #FOREGROUND\b/.test(e))continue;let t=e.match(/mission name #\[#([^:]+):[^:]*:([^\]]+)]/);if(!t)continue;let[,n,r]=t;if(!(!n||!r))return{package:n,activity:r}}}const Me=Object.freeze({available:!0}),Ne=Object.freeze({available:!1,reason:`unsupported-device-kind`}),V=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function H(e){let t=e.kind===`emulator`||e.kind===`device`?Me:Ne;return Object.freeze({deployApp:t,materializeAppSource:V,deployMaterializedApp:V,sendPushNotification:V,uninstallApp:V})}function Pe(e){return H(e.device).deployApp.available?Object.freeze({deployApp:async t=>await Fe(e.commands,e.device,t,e.signal)}):Object.freeze({})}async function Fe(t,n,r,i){let a=await Ie(t,r.appPath,i)??r.app.trim();if(!a)throw new e(`INVALID_ARGS`,`Could not determine the bundle name from the HAP archive`,{hint:`Pass the HarmonyOS bundle name before the HAP path, or provide a valid HAP containing module.json.`});return await ze(t,n,[`install`,`-r`,r.appPath],i,18e4),r.replaceExisting&&(await D(1e3,void 0,{signal:i}),await Le(t,n,a,i)),{packageName:a,launchTarget:a}}async function Ie(e,t,n){let r=await e.run({executable:`unzip`,args:[`-p`,t,`module.json`],allowFailure:!0,timeoutMs:15e3},n);if(r.exitCode===0&&r.stdout.trim().length!==0)try{return JSON.parse(r.stdout).app?.bundleName?.trim()||void 0}catch{return}}async function Le(t,n,r,i){let a=Re((await U(t,n,[`bm`,`dump`,`-n`,r],i)).stdout);if(!a)throw new e(`COMMAND_FAILED`,`Could not determine a launchable ability for ${r}`,{hint:`Check that the HarmonyOS bundle exposes a main ability.`});await U(t,n,[`aa`,`start`,`-b`,r,...a.module?[`-m`,a.module]:[],`-a`,a.ability],i)}function Re(e){let t=e.indexOf(`{`);if(t!==-1)try{let n=JSON.parse(e.slice(t)).hapModuleInfos?.find(e=>e.mainElementName);return n?.mainElementName?{ability:n.mainElementName,...n.moduleName?{module:n.moduleName}:{}}:void 0}catch{return}}async function ze(e,t,n,r,i=15e3){return await e.run({executable:`hdc`,args:[`-t`,t.id,...n],timeoutMs:i},r)}async function U(e,t,n,r,i=15e3){return await e.run({executable:`hdc`,args:a(`hdc`,`shell`,n,[`-t`,t.id]),timeoutMs:i},r)}const W=n(`harmonyos`),Be=r(`unsupported-platform-leaf`,`HarmonyOS reads element text from the captured tree only.`),Ve=r(`unsupported-device-kind`,`focus is supported on HarmonyOS emulators and physical devices.`),G=Object.freeze({available:!0}),K=r(`unsupported-platform-leaf`),He=r(`unsupported-device-kind`,`HarmonyOS appstate is supported only for HarmonyOS emulators and devices.`),Ue=r(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),q=Object.freeze({available:!0}),We=r(`unsupported-device-kind`,`open is supported only for HarmonyOS emulators and devices.`),Ge=r(`unsupported-device-kind`,`close is supported only for HarmonyOS emulators and devices.`),Ke=r(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),J=r(`unsupported-device-kind`,`snapshot is supported only for HarmonyOS emulators and devices.`),qe=r(`unsupported-device-kind`,`screenshot is supported only for HarmonyOS emulators and devices.`),Je=r(`unsupported-platform-leaf`,`Re-run without --actions, or target an iOS simulator.`),Ye=r(`unsupported-platform-leaf`,`viewport resizes web targets only (--platform web).`);function Xe(e){let t=Ze(e),n=Qe(e);return u({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:K,clearRuntimeHints:K,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:Ue,configureProviderPortReverse:Ke})}function Ze(e){return e.kind===`emulator`||e.kind===`device`?q:We}function Qe(e){return e.kind===`emulator`||e.kind===`device`?q:Ge}const Y=r(`unsupported-device-kind`,`Gestures are supported on HarmonyOS emulators and physical devices.`),$e=r(`unsupported-platform-leaf`),et=r(`unsupported-platform-leaf`,f);function X(e){return e.kind===`emulator`||e.kind===`device`?G:Y}function Z(e){return e.kind===`emulator`||e.kind===`device`?G:Ve}const Q=r(`unsupported-platform-leaf`),tt=r(`unsupported-platform-leaf`,`HarmonyOS supports settings clear-app-state only.`),nt=r(`unsupported-platform-leaf`,`keyboard status/get is not available through the public HarmonyOS HDC API; use keyboard dismiss or enter`),$=r(`unsupported-platform-leaf`,`audio is supported for web browser sessions, macOS sessions, iOS simulators, and Android emulators on macOS hosts`);function rt(e){let t=j(e),n=async e=>{let n=await t.inspectFacts(e),r=H(e),i=Se(e);return Object.freeze({device:n.device,operations:{...n.operations,...r,appState:e.kind===`simulator`?He:G,networkDump:K,screenRecordingStart:i,screenRecordingReattach:i,screenRecordingCleanup:i,...ie({capture:e.kind===`emulator`||e.kind===`device`?G:J,customActions:Je,withoutActiveApp:e.kind===`emulator`||e.kind===`device`?G:J}),...ne({capture:e.kind===`emulator`||e.kind===`device`?G:qe}),...ae({findText:J,querySelector:J}),...ce({setViewport:Ye}),...ue({focus:Z(e)}),...re({unsupported:Y,plan:X(e),directionalFling:X(e),multiTouch:$e,targetAuthoredDrag:et,viewport:X(e)}),...le({scroll:X(e)}),...oe({type:Z(e)}),...d({unsupported:K,tap:Z(e),longPress:Z(e),fill:Z(e)}),...m({readTextAtPoint:Be}),...te({back:Z(e)}),...h({unsupported:Q,home:Z(e),appSwitcher:Z(e)}),setFoldPose:Q,sendTelephonyEvent:Q,...pe({triggerAppEvent:Q}),...ge({target:Z(e),unsupported:tt,write:{"clear-app-state":G}}),...me({read:Q,wait:Q,accept:Q,dismiss:Q}),...v({orientation:Q}),...fe({tvRemote:Q}),..._({unsupported:Q,status:nt,dismiss:Z(e),enter:Z(e)}),...de({unsupported:Q}),...p({capture:$,query:$}),...se({frames:Z(e),memorySample:Z(e),memorySnapshot:Z(e),nativeCapture:Q,profileReport:Q}),ensureReady:G,bootTarget:K,bootTargetHeadless:K,listApps:G,...Xe(e),shutdownTarget:K}})};return Object.freeze({owner:W,ownsDevice:e=>e.platform===`harmonyos`,inspectFacts:n,bind:async r=>{let a=await t.bind(r),o=await n(r.device),s=o.operations.screenRecordingStart;return Object.freeze({device:a.device,owner:W,facts:o,operations:Object.freeze({...a.operations,...Pe({commands:e.commands,device:r.device,signal:r.scope.signal}),...o.operations.appState.available?{appState:async()=>await B(r.device,r.scope.signal)}:{},ensureReady:async()=>({...r.device,booted:!0}),...s.available?Ce({host:e,device:r.device,owner:W,signal:r.scope.signal}):{},...o.operations.captureSnapshot.available?g({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},..._e({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:o.operations,pause:async t=>await e.clock.sleep(t,r.scope.signal)}),...i(o.operations.perfFrames,()=>P({resolveHost:()=>e.perf.harmony,device:r.device})),listApps:async e=>{r.scope.signal.throwIfAborted();let{listHarmonyApps:t}=await import(`./app-lifecycle2.js`);return(await t(e.device,e.filter,{signal:r.scope.signal})).map(e=>({id:e.package,name:e.name}))},...l(he({owner:`HarmonyOS`,openTargetIdentity:`bundle-id`,host:e.localInteractors,device:r.device,signal:r.scope.signal}),o.operations)}),[Symbol.asyncDispose]:async()=>await a[Symbol.asyncDispose]()})},shutdown:async()=>await t.shutdown()})}export{rt as createHarmonyPlatformRuntime};
|
|
1
|
+
import{R as e}from"./sdk-contracts.js";import{U as t}from"./sdk-device.js";import{bn as n,pn as r,yn as i}from"./sdk-batch.js";import{n as a}from"./device-shell.js";import{i as o,n as s}from"./durable-resource.js";import{n as c}from"./screen-recording-runtime.js";import{n as l,t as u}from"./application-lifecycle-runtime.js";import{n as ee}from"./async-lifecycle.js";import{i as d}from"./touch-runtime.js";import{r as f}from"./gesture-admission.js";import{B as p,C as te,I as ne,K as re,M as ie,N as ae,O as oe,R as se,T as ce,U as le,Y as ue,Z as m,_ as h,k as g,l as _,o as v,p as de,r as fe,v as pe,x as me}from"./tv-remote-runtime.js";import{r as he,u as ge}from"./application-lifecycle-interaction.js";import{t as _e}from"./local-interactor-operation-set.js";import{n as ve,t as y}from"./src4.js";import{n as b,t as x}from"./screen-recording-completion.js";import{t as S}from"./screen-recording-options.js";import{i as C,n as w}from"./perf-runtime-operation-builder.js";import{t as T}from"./app-log-runtime.js";import{randomUUID as E}from"node:crypto";import{setTimeout as D}from"node:timers/promises";const O=Object.freeze({resourceKind:T,version:1,encode:e=>({...e}),decode:e=>e.transport!==`harmony-hilog`||!A(e.outputPath)||!A(e.pidPath)?{status:`invalid`,message:`Invalid HarmonyOS app-log descriptor`}:{status:`decoded`,descriptor:Object.freeze({transport:`harmony-hilog`,outputPath:e.outputPath,pidPath:e.pidPath})}});function k(e){return s({resourceKind:T,sessionId:e.sessionId,device:{id:e.device.id,family:`harmonyos`,kind:e.device.kind,...e.device.target===void 0?{}:{target:e.device.target}},owner:e.owner,fence:e.fence,lifecycle:`open`,descriptor:o(O,e.descriptor)})}function A(e){return typeof e==`string`&&e.trim().length>0}function j(e){return y(e,{family:`harmonyos`,backend:`harmonyos`,label:`HarmonyOS`,codec:O,startUnavailableHint:`The selected HarmonyOS transport cannot start a background hilog stream.`,cleanupFailureMessage:`HarmonyOS app-log cleanup did not settle every owned resource`,doctor:async(e,t)=>({backend:`harmonyos`,checks:{},notes:t?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`]}),process:async({host:e,device:t,input:n,signal:r})=>{let i=await M(e,r);return{resolvePid:async r=>await ve(e,{executable:i,args:a(`hdc`,`shell`,[`pidof`,n.appBundleId],[`-t`,t.id]),allowFailure:!0,timeoutMs:5e3},r),command:e=>({kind:`host`,request:{executable:i,args:a(`hdc`,`shell`,[`hilog`,`-P`,e],[`-t`,t.id]),allowFailure:!0}})}},descriptor:({artifacts:e})=>({transport:`harmony-hilog`,...e}),envelope:({input:e,device:t,owner:n,descriptor:r})=>k({sessionId:e.sessionId,device:t,owner:n,fence:e.fence,descriptor:r})})}async function M(t,n){n.throwIfAborted(),await N(async()=>await t.toolchains.prepare(`harmonyos`),n),n.throwIfAborted();let r=await N(async()=>await t.commands.which(`hdc`),n);if(n.throwIfAborted(),!r)throw new e(`TOOL_MISSING`,`hdc not found in PATH`,{hint:`Install HarmonyOS Command Line Tools, then add its sdk/default/openharmony/toolchains directory to PATH.`});return r}async function N(e,t){try{return await e()}catch(e){throw t.throwIfAborted(),e}}function P(e){let{resolveHost:t,device:n}=e,r={available:!1,reason:`Dropped-frame sampling is currently available only on Android app sessions and connected iOS device app sessions.`};return Object.freeze({perfFrames:async()=>({metric:r,sampling:r}),perfMemorySample:async({appId:e})=>({metric:e?await C(t().sampleMemory(n,e)):w(`HarmonyOS`,`bundle`),sampling:{method:`hdc-shell-proc-status`,description:`Resident memory snapshot from HarmonyOS /proc/<pid>/status. Values are reported in kilobytes.`,unit:`kB`,topConsumerLimit:1}}),perfMemorySnapshot:async({kind:e})=>({artifact:{available:!1,kind:e??`memgraph`,reason:`Memory snapshot artifacts are not supported on harmonyos.`,hint:`Use perf memory sample where supported, or run the snapshot against Android, iOS simulator, or macOS.`,support:{platform:`harmonyos`,defaultKind:`memgraph`,androidHprof:!1,memgraph:!1,heapprofd:!1}},sampling:{method:`unsupported`,description:`HarmonyOS memory snapshot capture is not available through HDC.`,artifactOnly:!0}})})}const F=Object.freeze({resourceKind:c,version:1,encode:e=>({...e}),decode:e=>e.backend===`harmony-screen-recorder`&&typeof e.fileName==`string`&&xe(e.fileName)&&e.remotePath===`/data/local/tmp/${e.fileName}`?{status:`decoded`,descriptor:Object.freeze({backend:`harmony-screen-recorder`,fileName:e.fileName,remotePath:e.remotePath})}:{status:`invalid`,message:`Invalid HarmonyOS screen-recording descriptor`}});function ye(e){let{device:n,owner:r,input:i,descriptor:a}=e;return s({resourceKind:c,sessionId:i.sessionId,device:t(n),owner:r,fence:i.fence,lifecycle:`open`,descriptor:o(F,a)})}function be(e){return F.decode(e).status===`decoded`?{status:`cleanup-pending`,reason:`manual-recovery-required`,message:`HarmonyOS recorder ownership cannot be proven after daemon restart; no recorder was stopped.`}:{status:`cleanup-pending`,reason:`manual-recovery-required`}}function xe(e){return/^agent-device-recording-[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\.mp4$/i.test(e)}function Se(e){return e.kind===`device`?Object.freeze({available:!0}):Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`HarmonyOS recording is supported on physical devices only.`})}function Ce(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await we({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async()=>({status:`unreattachable`,reason:`transport-not-reattachable`,message:`HarmonyOS recordings cannot be reattached after daemon restart.`}),screenRecordingCleanup:async e=>be(e.envelope.descriptor.body)})}async function we(t){let{host:n,device:r,owner:i,input:a,signal:o}=t;if(a.scope===`app`)throw new e(`INVALID_ARGS`,`HarmonyOS recording captures the whole physical-device screen; use --scope device or --scope system`);S(a,{scopes:[`device`,`system`],fps:!1,exportQuality:!1,hideTouches:!1},e=>`HarmonyOS recordings do not support ${e.join(`, `)}`),o.throwIfAborted(),await n.screenRecording.outputs.prepare(a.outputPath);let s=`agent-device-recording-${E()}.mp4`,c={backend:`harmony-screen-recorder`,fileName:s,remotePath:`/data/local/tmp/${s}`},l;try{l=await n.screenRecording.harmony.start(r,s,o),o.throwIfAborted()}catch(e){throw o.aborted?(await L(n,r,c).catch(()=>{}),o.reason):e}z(l,`start`);try{o.throwIfAborted()}catch(e){throw await L(n,r,c).catch(()=>{}),e}let u=Te(a),d=!1,f=async()=>{d||=(z(await n.screenRecording.harmony.stop(r),`stop`),!0)},p=b(u,{finish:async e=>await Ee(n,r,e,c,f),forceCleanup:async()=>await L(n,r,c,f)});return Object.freeze({pendingHandle:new ee(p),envelope:ye({device:r,owner:i,input:a,descriptor:c})})}function Te(e){return Object.freeze({backend:`HarmonyOS ScreenRecorder`,outPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutPath:e.clientOutputPath},startedAt:Date.now(),scope:e.scope,showTouches:!1,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},gestureEvents:[]})}async function Ee(e,t,n,r,i){await i();let a=await e.screenRecording.harmony.findMedia(t,r.fileName);if(!a)throw Error(`failed to find finalized HarmonyOS recording '${r.fileName}'`);if(!await ke(e,t,r,a))throw Error(`failed to finalize HarmonyOS recording: ${r.fileName} did not produce a non-empty media file`);try{if((await e.screenRecording.harmony.pull(t,{remotePath:r.remotePath,outputPath:n.outPath})).exitCode!==0)throw Error(`failed to retrieve HarmonyOS recording`);let i=await e.screenRecording.finalize.complete({outputPath:n.outPath,showTouches:!1,gestureEvents:n.gestureEvents,targetLabel:`HarmonyOS recording`}),o=await De(e,t,r,a);return x(n,{...i,...Oe(i.warning,o)},{stopObservation:{recorder:`confirmed`},nativePathDisposition:o===void 0?`retired`:`retirable`,showTouches:!1})}catch(n){throw await e.screenRecording.harmony.remove(t,r.remotePath).catch(()=>{}),n}}async function De(e,t,n,r){let i=[];return await I(()=>e.screenRecording.harmony.remove(t,n.remotePath))||i.push(`staging artifact`),await I(()=>e.screenRecording.harmony.removeMedia(t,r))||i.push(`media-library artifact`),i.length===0?void 0:`HarmonyOS recording completed, but cleanup was not confirmed for the ${i.join(` and `)}.`}async function I(e){try{return await e()}catch{return!1}}function Oe(e,t){let n=[e,t].filter(e=>e!==void 0).join(` `);return n.length===0?{}:{warning:n}}async function ke(e,t,n,r){let i;for(let a=0;a<40;a+=1){if(await e.screenRecording.harmony.remove(t,n.remotePath).catch(()=>{}),await e.screenRecording.harmony.stageMedia(t,{mediaUri:r,remotePath:n.remotePath})){let r=await e.screenRecording.harmony.stagedFileSize(t,n.remotePath);if(r!==void 0&&r>0&&r===i)return!0;i=r!==void 0&&r>0?r:void 0}else i=void 0;a<39&&await e.clock.sleep(250)}return!1}async function L(e,t,n,r=async()=>{z(await e.screenRecording.harmony.stop(t),`stop`)}){let i=[await R(r),await R(async()=>{if(!await e.screenRecording.harmony.remove(t,n.remotePath))throw Error(`HarmonyOS recording staging artifact removal was not confirmed`)}),await R(async()=>await Ae(e,t,n.fileName))].find(e=>e!==void 0);return i===void 0?{status:`cleaned`}:{status:`cleanup-pending`,reason:`transport-failed`,message:i instanceof Error?i.message:`HarmonyOS recording cleanup failed`}}async function Ae(e,t,n){let r=await e.screenRecording.harmony.findMedia(t,n);if(r&&!await e.screenRecording.harmony.removeMedia(t,r))throw Error(`HarmonyOS recording media removal was not confirmed`)}async function R(e){try{await e();return}catch(e){return e}}function z(e,t){if(e.exitCode===0&&e.stdout.includes(`start ability successfully`))return;let n=e.stdout.trim()||e.stderr.trim()||`hdc exit ${e.exitCode}`;throw Error(`failed to ${t} HarmonyOS screen recording: ${n}`)}async function B(t,n){n.throwIfAborted();let{runHarmonyShell:r}=await import(`./hdc.js`),i=await r(t,[`aa`,`dump`,`-l`],{timeoutMs:15e3,signal:n});n.throwIfAborted();let a=je(i.stdout);if(!a)throw new e(`COMMAND_FAILED`,`Could not determine the foreground HarmonyOS app`,{hint:`Open an app on the target, then retry appstate.`});return a}function je(e){let t=e.split(/(?=^\s*Mission ID #)/m);for(let e of t){if(!/\bstate #FOREGROUND\b/.test(e))continue;let t=e.match(/mission name #\[#([^:]+):[^:]*:([^\]]+)]/);if(!t)continue;let[,n,r]=t;if(!(!n||!r))return{package:n,activity:r}}}const Me=Object.freeze({available:!0}),Ne=Object.freeze({available:!1,reason:`unsupported-device-kind`}),V=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function H(e){let t=e.kind===`emulator`||e.kind===`device`?Me:Ne;return Object.freeze({deployApp:t,materializeAppSource:V,deployMaterializedApp:V,sendPushNotification:V,uninstallApp:V})}function Pe(e){return H(e.device).deployApp.available?Object.freeze({deployApp:async t=>await Fe(e.commands,e.device,t,e.signal)}):Object.freeze({})}async function Fe(t,n,r,i){let a=await Ie(t,r.appPath,i)??r.app.trim();if(!a)throw new e(`INVALID_ARGS`,`Could not determine the bundle name from the HAP archive`,{hint:`Pass the HarmonyOS bundle name before the HAP path, or provide a valid HAP containing module.json.`});return await ze(t,n,[`install`,`-r`,r.appPath],i,18e4),r.replaceExisting&&(await D(1e3,void 0,{signal:i}),await Le(t,n,a,i)),{packageName:a,launchTarget:a}}async function Ie(e,t,n){let r=await e.run({executable:`unzip`,args:[`-p`,t,`module.json`],allowFailure:!0,timeoutMs:15e3},n);if(r.exitCode===0&&r.stdout.trim().length!==0)try{return JSON.parse(r.stdout).app?.bundleName?.trim()||void 0}catch{return}}async function Le(t,n,r,i){let a=Re((await U(t,n,[`bm`,`dump`,`-n`,r],i)).stdout);if(!a)throw new e(`COMMAND_FAILED`,`Could not determine a launchable ability for ${r}`,{hint:`Check that the HarmonyOS bundle exposes a main ability.`});await U(t,n,[`aa`,`start`,`-b`,r,...a.module?[`-m`,a.module]:[],`-a`,a.ability],i)}function Re(e){let t=e.indexOf(`{`);if(t!==-1)try{let n=JSON.parse(e.slice(t)).hapModuleInfos?.find(e=>e.mainElementName);return n?.mainElementName?{ability:n.mainElementName,...n.moduleName?{module:n.moduleName}:{}}:void 0}catch{return}}async function ze(e,t,n,r,i=15e3){return await e.run({executable:`hdc`,args:[`-t`,t.id,...n],timeoutMs:i},r)}async function U(e,t,n,r,i=15e3){return await e.run({executable:`hdc`,args:a(`hdc`,`shell`,n,[`-t`,t.id]),timeoutMs:i},r)}const W=r(`harmonyos`),Be=i(`unsupported-platform-leaf`,`HarmonyOS reads element text from the captured tree only.`),Ve=i(`unsupported-device-kind`,`focus is supported on HarmonyOS emulators and physical devices.`),G=Object.freeze({available:!0}),K=i(`unsupported-platform-leaf`),He=i(`unsupported-device-kind`,`HarmonyOS appstate is supported only for HarmonyOS emulators and devices.`),Ue=i(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),q=Object.freeze({available:!0}),We=i(`unsupported-device-kind`,`open is supported only for HarmonyOS emulators and devices.`),Ge=i(`unsupported-device-kind`,`close is supported only for HarmonyOS emulators and devices.`),Ke=i(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),J=i(`unsupported-device-kind`,`snapshot is supported only for HarmonyOS emulators and devices.`),qe=i(`unsupported-device-kind`,`screenshot is supported only for HarmonyOS emulators and devices.`),Je=i(`unsupported-platform-leaf`,`Re-run without --actions, or target an iOS simulator.`),Ye=i(`unsupported-platform-leaf`,`viewport resizes web targets only (--platform web).`);function Xe(e){let t=Ze(e),n=Qe(e);return u({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:K,clearRuntimeHints:K,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:Ue,configureProviderPortReverse:Ke})}function Ze(e){return e.kind===`emulator`||e.kind===`device`?q:We}function Qe(e){return e.kind===`emulator`||e.kind===`device`?q:Ge}const Y=i(`unsupported-device-kind`,`Gestures are supported on HarmonyOS emulators and physical devices.`),$e=i(`unsupported-platform-leaf`),et=i(`unsupported-platform-leaf`,f);function X(e){return e.kind===`emulator`||e.kind===`device`?G:Y}function Z(e){return e.kind===`emulator`||e.kind===`device`?G:Ve}const Q=i(`unsupported-platform-leaf`),tt=i(`unsupported-platform-leaf`,`HarmonyOS supports settings clear-app-state only.`),nt=i(`unsupported-platform-leaf`,`keyboard status/get is not available through the public HarmonyOS HDC API; use keyboard dismiss or enter`),$=i(`unsupported-platform-leaf`,`audio is supported for web browser sessions, macOS sessions, iOS simulators, and Android emulators on macOS hosts`);function rt(e){let t=j(e),r=async e=>{let n=await t.inspectFacts(e),r=H(e),i=Se(e);return Object.freeze({device:n.device,operations:{...n.operations,...r,appState:e.kind===`simulator`?He:G,networkDump:K,screenRecordingStart:i,screenRecordingReattach:i,screenRecordingCleanup:i,...ie({capture:e.kind===`emulator`||e.kind===`device`?G:J,customActions:Je,withoutActiveApp:e.kind===`emulator`||e.kind===`device`?G:J}),...ne({capture:e.kind===`emulator`||e.kind===`device`?G:qe}),...ae({findText:J,querySelector:J}),...ce({setViewport:Ye}),...ue({focus:Z(e)}),...re({unsupported:Y,plan:X(e),directionalFling:X(e),multiTouch:$e,targetAuthoredDrag:et,viewport:X(e)}),...le({scroll:X(e)}),...oe({type:Z(e)}),...d({unsupported:K,tap:Z(e),longPress:Z(e),fill:Z(e)}),...m({readTextAtPoint:Be}),...te({back:Z(e)}),...h({unsupported:Q,home:Z(e),appSwitcher:Z(e)}),setFoldPose:Q,sendTelephonyEvent:Q,...pe({triggerAppEvent:Q}),...ge({target:Z(e),unsupported:tt,write:{"clear-app-state":G}}),...me({read:Q,wait:Q,accept:Q,dismiss:Q}),...v({orientation:Q}),...fe({tvRemote:Q}),..._({unsupported:Q,status:nt,dismiss:Z(e),enter:Z(e)}),...de({unsupported:Q}),...p({capture:$,query:$}),...se({frames:Z(e),memorySample:Z(e),memorySnapshot:Z(e),nativeCapture:Q,profileReport:Q}),ensureReady:G,bootTarget:K,bootTargetHeadless:K,listApps:G,...Xe(e),shutdownTarget:K}})};return Object.freeze({owner:W,ownsDevice:e=>e.platform===`harmonyos`,inspectFacts:r,bind:async i=>{let a=await t.bind(i),o=await r(i.device),s=o.operations.screenRecordingStart;return Object.freeze({device:a.device,owner:W,facts:o,operations:Object.freeze({...a.operations,...Pe({commands:e.commands,device:i.device,signal:i.scope.signal}),...o.operations.appState.available?{appState:async()=>await B(i.device,i.scope.signal)}:{},ensureReady:async()=>({...i.device,booted:!0}),...s.available?Ce({host:e,device:i.device,owner:W,signal:i.scope.signal}):{},...o.operations.captureSnapshot.available?g({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},..._e({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:o.operations,pause:async t=>await e.clock.sleep(t,i.scope.signal)}),...n(o.operations.perfFrames,()=>P({resolveHost:()=>e.perf.harmony,device:i.device})),listApps:async e=>{i.scope.signal.throwIfAborted();let{listHarmonyApps:t}=await import(`./app-lifecycle2.js`);return(await t(e.device,e.filter,{signal:i.scope.signal})).map(e=>({id:e.package,name:e.name}))},...l(he({owner:`HarmonyOS`,openTargetIdentity:`bundle-id`,host:e.localInteractors,device:i.device,signal:i.scope.signal}),o.operations)}),[Symbol.asyncDispose]:async()=>await a[Symbol.asyncDispose]()})},shutdown:async()=>await t.shutdown()})}export{rt as createHarmonyPlatformRuntime};
|
package/dist/src/runtime6.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{R as e}from"./sdk-contracts.js";import{
|
|
1
|
+
import{R as e}from"./sdk-contracts.js";import{pn as t,vn as n,yn as r}from"./sdk-batch.js";import{n as i,t as a}from"./application-lifecycle-runtime.js";import{i as o}from"./touch-runtime.js";import{r as s}from"./gesture-admission.js";import{C as c,I as l,K as u,M as d,O as f,U as p,Y as m,Z as h,_ as g,j as _,p as v}from"./tv-remote-runtime.js";import{r as y}from"./application-lifecycle-interaction.js";import{t as b}from"./local-interactor-operation-set.js";import{r as x}from"./platform-runtime-unavailable.js";const S=Object.freeze({available:!0}),C=t(`linux`),w=r(`unsupported-platform-leaf`),T=r(`unsupported-device-kind`),E=r(`unsupported-device-kind`,`focus is supported only for the Linux desktop device.`),D=r(`unsupported-device-kind`,`type is supported only for the Linux desktop device.`),O=r(`unsupported-device-kind`,`Gestures are supported only for the Linux desktop device.`),k=r(`unsupported-device-kind`,`scroll is supported only for the Linux desktop device.`),A=r(`unsupported-platform-leaf`),j=r(`unsupported-platform-leaf`),M=r(`unsupported-platform-leaf`,s),N=r(`unsupported-platform-leaf`),P=r(`unsupported-platform-leaf`,`Runtime hints are supported only for local iOS-family simulators and Android devices.`),F=r(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),I=r(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),L=r(`unsupported-device-kind`,`open is supported only for the Linux desktop device.`),R=r(`unsupported-device-kind`,`close is supported only for the Linux desktop device.`),z=r(`unsupported-device-kind`,`snapshot is supported only for the Linux desktop device.`),B=r(`unsupported-device-kind`,`screenshot is supported only for the Linux desktop device.`),V=r(`unsupported-platform-leaf`,`Re-run without --actions, or target an iOS simulator.`),H=r(`unsupported-device-kind`,`back is supported only for the Linux desktop device.`),U=r(`unsupported-device-kind`,`home is supported only for the Linux desktop device.`),W=r(`unsupported-device-kind`,`clipboard is supported only for the Linux desktop device.`),G=w,K=r(`unsupported-platform-leaf`,`audio is supported for web browser sessions, macOS sessions, iOS simulators, and Android emulators on macOS hosts`);function q(t){return Object.freeze({owner:C,ownsDevice:e=>e.platform===`linux`,inspectFacts:async e=>Y(e),bind:async r=>{if(r.intent.kind===`exact-owner`&&!n(r.intent.owner,C))throw new e(`UNSUPPORTED_OPERATION`,`Linux runtime owner identity does not match`);if(r.device.platform!==`linux`)throw new e(`UNSUPPORTED_PLATFORM`,`Linux runtime cannot bind this device`);let a=Y(r.device),o=y({owner:`Linux`,openTargetIdentity:`app-name`,host:t.localInteractors,device:r.device,signal:r.scope.signal});return Object.freeze({device:r.device,owner:C,facts:a,operations:Object.freeze({...i(o,a.operations),...a.operations.captureSnapshot.available?Q(t,r):{},...J(t,r,a)}),[Symbol.asyncDispose]:async()=>void 0})},shutdown:async()=>void 0})}function J(e,t,n){let r={device:t.device,signal:t.scope.signal,resolveInteractor:e.localInteractors.resolve};return b({...r,facts:n.operations,pause:async n=>await e.clock.sleep(n,t.scope.signal)})}function Y(e){let t=e.kind===`device`?S:L,n=e.kind===`device`?S:R,r=x(e,C,{appLog:w,network:w,screenshot:B,snapshot:z,viewport:w,focus:E,gesture:O,scroll:k,typeText:D,touch:E,elementText:T,back:H,orientation:G,tvRemote:G,clipboard:W,systemButton:G,fold:G,telephony:G,triggerAppEvent:G,settings:G,readAlert:G,awaitAlert:G,acceptAlert:G,dismissAlert:G,keyboard:G,audioProbeCapture:K,audioProbeQuery:K,perf:G,readiness:w,lifecycle:a({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:P,clearRuntimeHints:P,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:F,configureProviderPortReverse:I})});return Object.freeze({device:r.device,operations:{...r.operations,...d({capture:X(e,z),customActions:V,withoutActiveApp:X(e,z)}),...l({capture:X(e,B)}),...m({focus:X(e,E)}),...u({unsupported:O,plan:X(e,O),directionalFling:A,multiTouch:j,targetAuthoredDrag:M,viewport:N}),...p({scroll:X(e,k)}),...f({type:X(e,D)}),...Z(e),...h({readTextAtPoint:X(e,T)}),...c({back:X(e,H)}),...g({unsupported:G,home:X(e,U)}),...v({unsupported:W,read:X(e,W),write:X(e,W)})}})}function X(e,t){return e.kind===`device`?S:t}function Z(e){let t=e.kind===`device`?S:E;return o({unsupported:w,tap:t,longPress:t,fill:t})}function Q(e,t){let n=async n=>await e.snapshot.captureSurface(t.device,n.options,_(t.scope.signal,n));return Object.freeze({captureSnapshot:n,captureSnapshotWithCustomActions:n,captureSnapshotWithoutActiveApp:n})}export{q as createLinuxPlatformRuntime};
|