agent-device 0.21.13 → 0.21.15
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.13.apk → agent-device-android-ime-helper-0.21.15.apk} +0 -0
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.15.apk.sha256 +1 -0
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.13.manifest.json → agent-device-android-ime-helper-0.21.15.manifest.json} +4 -4
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.15.apk +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.15.apk.sha256 +1 -0
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.13.manifest.json → agent-device-android-snapshot-helper-0.21.15.manifest.json} +6 -6
- package/apple/snapshot-bridge/SnapshotBridgeRuntime.m +11 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerApp.m +110 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAXSnapshotBridge.m +4 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerMainOwnedState.swift +27 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedTextEntry.h +8 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedTextEntry.m +26 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AXSnapshotFallback.swift +12 -19
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Alert.swift +59 -20
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AlertObservation.swift +2 -3
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandDispatch.swift +179 -91
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +21 -24
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandJournal.swift +1 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+GestureExecution.swift +9 -13
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Lifecycle.swift +36 -49
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+MainThreadWork.swift +11 -15
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +136 -29
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Navigation.swift +20 -21
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+PrivateAXPresentation.swift +3 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScreenRecorder.swift +6 -5
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScrollDragExecution.swift +12 -24
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SequenceExecution.swift +22 -42
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift +15 -18
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotAcquisition.swift +73 -31
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotCapturePlan.swift +20 -11
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotCaptureTarget.swift +9 -7
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotExecution.swift +5 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotTiming.swift +2 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedGesturePolicy.swift +51 -19
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedInteraction.swift +5 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedTextEntry.swift +78 -10
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntry.swift +32 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryFocus.swift +7 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextTyping.swift +23 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Transport.swift +17 -10
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TvRemote.swift +8 -9
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TypeExecution.swift +9 -15
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +12 -11
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotCoordinateSpace.swift +16 -19
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotGeometry.swift +24 -9
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotModels.swift +66 -10
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotPresentationInvariant.swift +12 -10
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotPresentationProjection.swift +1 -0
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotVisibilityFold.swift +27 -5
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotVisibilityFoldProjection.swift +1 -0
- package/dist/src/adapter.js +1 -1
- package/dist/src/adb-executor.js +1 -1
- package/dist/src/adb-failure.js +1 -1
- package/dist/src/adb-transport.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 +2 -2
- package/dist/src/ai-sdk.js +1 -1
- package/dist/src/alert-runtime.js +1 -1
- package/dist/src/android-adb.d.ts +1 -8
- package/dist/src/android-input-ownership.js +1 -1
- package/dist/src/android-snapshot-quality.js +1 -0
- package/dist/src/android-system-chrome.js +1 -1
- package/dist/src/android.js +1 -1
- package/dist/src/app-catalog.js +1 -1
- package/dist/src/app-deployment-resolution.js +1 -1
- package/dist/src/app-inventory.js +1 -1
- package/dist/src/app-launch.js +1 -1
- package/dist/src/app-lifecycle.js +1 -1
- package/dist/src/app-lifecycle2.js +1 -1
- package/dist/src/app-log-files.js +1 -1
- package/dist/src/app-log-runtime2.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/archive.js +1 -1
- package/dist/src/artifact-download.js +1 -1
- package/dist/src/auth-session.js +1 -1
- package/dist/src/auth.js +1 -1
- package/dist/src/backend-snapshot-options.js +1 -1
- package/dist/src/boot-diagnostics.js +1 -1
- package/dist/src/capture-disclosure.js +1 -1
- package/dist/src/capture.js +1 -1
- package/dist/src/cli-config.js +1 -1
- package/dist/src/cli-help.js +2 -2
- package/dist/src/cli.js +4 -4
- package/dist/src/click-button.js +1 -1
- package/dist/src/client-metro.js +1 -1
- package/dist/src/client-types.d.ts +102 -95
- package/dist/src/clipboard-shell-response.js +1 -1
- package/dist/src/command-schema.js +1 -1
- package/dist/src/command-tools.js +3 -3
- package/dist/src/connection-runtime.js +1 -1
- package/dist/src/connection.js +1 -1
- package/dist/src/contracts.d.ts +1 -1
- package/dist/src/contracts.js +1 -1
- package/dist/src/daemon-client-lifecycle.js +1 -1
- package/dist/src/daemon.js +1 -1
- package/dist/src/debug-symbols-facade.js +1 -1
- package/dist/src/device-claim-rule.js +2 -2
- package/dist/src/device-input-state.d.ts +15 -2
- package/dist/src/device-inventory-context.js +1 -1
- package/dist/src/device-rotation.js +1 -1
- package/dist/src/device-selection-resolver.js +1 -1
- package/dist/src/device-session.js +1 -1
- package/dist/src/device-shell.js +1 -1
- package/dist/src/device2.js +1 -1
- package/dist/src/devicectl.js +1 -1
- package/dist/src/diagnostics.js +1 -1
- package/dist/src/dispatch-resolve.js +1 -1
- package/dist/src/doctor2.js +1 -1
- package/dist/src/engine-eval-script.js +1 -1
- package/dist/src/error.js +1 -1
- package/dist/src/exec.js +1 -1
- package/dist/src/file.js +1 -1
- package/dist/src/find.js +1 -1
- package/dist/src/format.js +1 -1
- package/dist/src/gesture-plan-types.d.ts +1 -1
- package/dist/src/gesture-plan.js +1 -1
- package/dist/src/gesture-runtime.js +1 -1
- package/dist/src/harmonyos.js +1 -1
- package/dist/src/helper.js +2 -2
- package/dist/src/human-control-contract.js +1 -1
- package/dist/src/human-control.js +1 -1
- package/dist/src/index.d.ts +7 -3
- 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-artifact-facade.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-ref-policy.js +1 -1
- package/dist/src/interaction2.js +1 -1
- package/dist/src/interactor-operation-binding.js +1 -1
- package/dist/src/interactor.js +4 -4
- package/dist/src/interactor2.js +1 -1
- package/dist/src/interactors.js +1 -1
- package/dist/src/internal/bin.js +1 -1
- package/dist/src/internal/daemon.js +2 -2
- package/dist/src/internal/png-worker.js +1 -1
- package/dist/src/internal/run-script-http-child.js +1 -1
- package/dist/src/inventory.js +1 -1
- package/dist/src/inventory2.js +1 -1
- package/dist/src/inventory3.js +1 -1
- package/dist/src/inventory5.js +1 -1
- package/dist/src/ios-snapshot-acquisition.js +1 -1
- package/dist/src/ios-snapshot-engine.js +1 -0
- package/dist/src/ios-snapshot-runtime.js +1 -1
- package/dist/src/lease.js +1 -1
- package/dist/src/limrun-download-file.js +1 -1
- package/dist/src/limrun-runtime-dependencies.js +1 -1
- package/dist/src/limrun.d.ts +16 -3
- package/dist/src/linux.js +1 -1
- package/dist/src/location-coordinates.js +1 -1
- package/dist/src/managed-device-scope.js +1 -1
- package/dist/src/mechanics.js +17 -17
- package/dist/src/mobile-snapshot-semantics.js +1 -1
- package/dist/src/multitouch-support.js +1 -1
- package/dist/src/native-build-cache.js +1 -0
- package/dist/src/observation.js +1 -1
- package/dist/src/overlay.js +3 -0
- 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-runtime-plan.js +1 -1
- package/dist/src/perf-target.js +2 -2
- package/dist/src/perf.js +1 -1
- package/dist/src/physical-device-control.js +1 -1
- package/dist/src/platform-runtime-host.js +1 -1
- package/dist/src/platform-runtime-managed-owner.js +1 -1
- package/dist/src/platform-runtime-open-target.js +1 -1
- package/dist/src/platform-runtime-operation-host.js +4 -4
- package/dist/src/platform-runtime-runtime-hints.js +1 -1
- 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-screen-recording-process-host.js +1 -1
- package/dist/src/platform-runtime.js +1 -1
- package/dist/src/platform-runtime2.js +1 -1
- package/dist/src/png-crop-bytes.js +1 -1
- package/dist/src/png-size.js +1 -1
- package/dist/src/png-worker-client.js +1 -1
- package/dist/src/png.js +1 -1
- package/dist/src/prepare-kind.js +1 -1
- package/dist/src/provider-session-ownership.js +1 -1
- package/dist/src/provider-webdriver.js +1 -1
- package/dist/src/proxy.js +1 -1
- package/dist/src/quality-warnings.js +1 -1
- package/dist/src/react-native.js +1 -1
- package/dist/src/record-runtime.js +1 -1
- package/dist/src/recording.js +1 -1
- package/dist/src/rect-center.js +1 -1
- package/dist/src/register-builtins.js +1 -1
- package/dist/src/registry.js +36 -36
- package/dist/src/remote-config2.js +1 -1
- package/dist/src/replay-divergence.js +1 -1
- package/dist/src/replay.js +1 -1
- package/dist/src/reporting.js +1 -1
- package/dist/src/request-admission.js +1 -1
- package/dist/src/request-cancel.js +1 -1
- package/dist/src/request-runtime-binding.js +1 -1
- package/dist/src/retry.js +1 -1
- package/dist/src/runner-cache-metadata.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-disposal.js +1 -1
- package/dist/src/runner-error-classification.js +1 -1
- package/dist/src/runner.js +1 -1
- package/dist/src/runtime-transport-hints.js +1 -1
- package/dist/src/runtime.js +1 -3
- package/dist/src/runtime10.js +2 -2
- package/dist/src/runtime2.js +4 -4
- package/dist/src/runtime3.js +1 -1
- package/dist/src/runtime4.js +5 -5
- 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 +1 -1
- package/dist/src/screen-recording-admission-ledger.js +1 -1
- package/dist/src/screen-recording-completion.js +1 -1
- package/dist/src/screen-recording-options.js +1 -1
- package/dist/src/screen-recording-resource-recovery.js +1 -1
- package/dist/src/screenshot-density.js +1 -1
- package/dist/src/screenshot-image.js +1 -1
- package/dist/src/screenshot-overlay-draw.js +1 -1
- package/dist/src/screenshot-runtime.js +1 -1
- package/dist/src/screenshot.js +1 -1
- package/dist/src/screenshot3.js +1 -1
- package/dist/src/script.js +1 -1
- package/dist/src/scroll-command.d.ts +13 -6
- package/dist/src/scroll-command.js +1 -1
- package/dist/src/scroll-gesture.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 +59 -12
- package/dist/src/sdk-contracts.js +2 -2
- package/dist/src/sdk-device.js +1 -1
- package/dist/src/sdk-finders.d.ts +1 -1
- package/dist/src/sdk-io.js +1 -1
- package/dist/src/sdk-remote-config.js +1 -1
- package/dist/src/sdk-selectors.d.ts +1 -1
- package/dist/src/selection.js +0 -0
- package/dist/src/selector-runtime.js +1 -1
- package/dist/src/server.js +1 -1
- package/dist/src/session-allocation.js +1 -1
- package/dist/src/session-routing.js +1 -1
- package/dist/src/session-runtime-admission.js +1 -1
- package/dist/src/session-snapshot.js +1 -1
- package/dist/src/session-store.js +1 -1
- package/dist/src/session.js +1 -1
- package/dist/src/session2.js +4 -4
- package/dist/src/settings.js +1 -1
- package/dist/src/settings2.js +1 -0
- package/dist/src/simctl.js +1 -1
- package/dist/src/simulator-state.js +1 -1
- package/dist/src/simulator.js +1 -1
- package/dist/src/snapshot-capture-annotations.js +1 -1
- package/dist/src/snapshot-desktop-projection.js +1 -1
- package/dist/src/snapshot-runtime-binding.js +1 -1
- package/dist/src/snapshot-runtime.js +1 -1
- package/dist/src/snapshot-state.js +1 -1
- package/dist/src/snapshot2.js +1 -1
- package/dist/src/snapshot3.js +1 -1
- package/dist/src/snapshot4.js +1 -1
- package/dist/src/src.js +1 -1
- package/dist/src/src4.js +1 -1
- package/dist/src/src7.js +1 -1
- package/dist/src/src8.js +1 -1
- package/dist/src/string-enum.js +1 -1
- package/dist/src/surface-snapshot.js +1 -1
- package/dist/src/takeover.js +1 -1
- package/dist/src/text-entry-focus.js +1 -1
- package/dist/src/tool-provider-facade.js +1 -1
- package/dist/src/tool-provider.js +2 -2
- package/dist/src/tool-provider2.js +1 -1
- package/dist/src/touch-runtime.js +1 -1
- package/dist/src/transport.js +1 -1
- package/dist/src/tree.js +1 -1
- package/dist/src/tv-remote.js +1 -1
- package/dist/src/type-text-runtime.js +1 -1
- package/dist/src/verified-file.js +1 -1
- package/dist/src/video.js +1 -1
- package/dist/src/viewport.js +1 -1
- package/dist/src/web.js +1 -1
- package/dist/src/web2.js +1 -1
- package/dist/src/webdriver-source.js +1 -1
- package/package.json +1 -1
- package/server.json +2 -2
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.13.apk.sha256 +0 -1
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.13.apk +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.13.apk.sha256 +0 -1
- package/dist/src/absence-observation-errors.js +0 -1
- package/dist/src/runner-presentation.js +0 -1
- package/dist/src/semantic-index.js +0 -1
- package/dist/src/snapshot-process.js +0 -1
- package/dist/src/snapshot-scope.js +0 -1
package/dist/src/runtime4.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{D as e,O as t}from"./sdk-contracts.js";import{_ as n,i as r}from"./sdk-batch-runner.js";import{D as i,_ as a,d as o,f as s,l as c,o as l,u,w as d}from"./sdk-device.js";import{Yt as f,en as p,tn as m}from"./sdk-batch.js";import"./device.js";import{c as h}from"./device-rotation.js";import{c as ee,r as g}from"./diagnostics.js";import{a as te,n as _}from"./exec.js";import"./diagnostics2.js";import"./command.js";import{r as ne}from"./version.js";import{n as re}from"./scoped-provider.js";import{i as ie,n as ae,r as oe}from"./ios-snapshot-planning.js";import{n as se,t as ce}from"./fold-runtime.js";import{t as le}from"./request.js";import{n as ue,r as de,t as fe}from"./application-lifecycle-runtime.js";import{A as pe,B as me,C as he,D as ge,E as _e,G as ve,H as ye,I as be,J as xe,K as Se,L as Ce,N as we,O as Te,P as Ee,V as De,W as Oe,d as ke,h as Ae,j as je,n as Me,o as Ne,s as Pe,v as Fe,w as Ie,x as Le,z as Re}from"./alert-runtime.js";import{n as ze}from"./audio-probe-runtime.js";import{n as Be}from"./perf-runtime.js";import{i as Ve,t as He}from"./touch-runtime.js";import{a as Ue,n as We}from"./durable-resource.js";import{n as Ge,t as Ke}from"./async-lifecycle.js";import{a as qe,c as Je,d as Ye,f as Xe,l as Ze,n as Qe,o as $e,s as et,t as tt,u as nt}from"./src7.js";import{n as rt,t as it}from"./screen-recording-completion.js";import{a as at,i as ot,n as st,o as ct,r as lt,s as ut,t as dt}from"./stop-sequence.js";import{n as ft}from"./screen-recording-runtime.js";import{t as pt}from"./ios-system-surface.js";import{i as mt,r as ht}from"./gesture-admission.js";import{t as gt}from"./interactor-operation-catalog.js";import{a as _t,i as vt,n as yt,r as bt,t as xt}from"./perf-runtime-operation-builder.js";import{t as St}from"./app-log-runtime.js";import{n as Ct}from"./artifact-paths.js";import{i as wt,r as Tt}from"./managed-device-scope.js";import{a as Et,n as Dt,o as Ot}from"./application-lifecycle-interaction.js";import{m as kt,x as At}from"./host-file.js";import{a as jt,o as Mt,s as Nt}from"./config.js";import{a as Pt,o as Ft}from"./tool-provider.js";import{o as It}from"./devicectl.js";import{t as Lt}from"./physical-device-apps.js";import{a as v,i as Rt,s as y,t as zt}from"./simctl.js";import{a as Bt,r as Vt}from"./simulator.js";import{r as Ht}from"./display-inventory.js";import{t as Ut}from"./multitouch-support.js";import{t as Wt}from"./simulator-state.js";import{n as Gt,r as Kt,t as qt}from"./snapshot-process.js";import b from"node:path";import{randomUUID as Jt}from"node:crypto";function Yt(e){let t=wt();return Object.freeze(t?{...re({...e},e=>Bt(t,e))}:e)}function Xt(e){return at(e)?Object.freeze({available:!0}):s(e)||o(e)&&e.kind===`simulator`?Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`audio probe capture requires a macOS host.`}):Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`audio is supported for macOS sessions and iOS simulators on macOS hosts; physical iOS devices expose no host audio tap.`})}function Zt(e){let{resolveHost:t,device:n,owner:r}=e;return Object.freeze({...xt({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 vt(t().sampleFrames(n,e)):yt(`Apple`,`bundle ID`),sampling:await t().frameSampling(n)}),perfMemorySample:async({appId:e})=>({metric:e?await vt(t().sampleMemory(n,e)):yt(`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 _t(`Apple`,o,s,`Use perf memory snapshot --kind memgraph for supported Apple app sessions.`);if(!e)throw bt();let c=i??b.join(a,`memory-memgraph-${Qt()}.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 Qt(){return new Date().toISOString().replaceAll(/[:.]/g,`-`)}const x=Object.freeze({available:!0}),S=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),C=nn(`Gestures are supported only for Apple simulators and devices.`),$t=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:ht}),en=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:mt}),tn=nn(`scroll is supported only for Apple simulators and devices.`);function nn(e){return Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:e})}function rn(e){return{...be({unsupported:an(e),plan:on(e),directionalFling:on(e),multiTouch:sn(e),targetAuthoredDrag:cn(e),viewport:ln(e)}),...we({scroll:un(e)})}}function an(e){return e.appleOs===`watchos`||e.appleOs===`visionos`?S:C}function on(e){return e.appleOs===`watchos`||e.appleOs===`visionos`?S:w(e)?x:C}function sn(e){if(e.appleOs===`watchos`)return S;if(!w(e))return C;let t=d(e);if(t!==`ios`&&t!==`ipados`){let e=Ut[t];return Object.freeze({available:!1,reason:`unsupported-platform-leaf`,...e===void 0?{}:{hint:e}})}return e.kind===`simulator`?x:$t}function cn(e){return w(e)?(e.appleOs===void 0?e.target!==`desktop`&&e.target!==`tv`:e.appleOs===`ios`||e.appleOs===`ipados`)?x:en:C}function ln(e){return e.appleOs===`watchos`?S:w(e)?x:C}function un(e){return w(e)?x:tn}function w(e){return e.kind===`simulator`||e.kind===`device`}const T=`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`;function E(e){return s(e)?`macos`:e.kind===`device`?`ios-device`:`ios-simulator`}const dn=Object.freeze({resourceKind:St,version:1,encode:e=>({...e}),decode:e=>!pn(e.transport)||!mn(e.backend)||!vn(e.outputPath)||!gn(e.pidPath)||!hn(e.transport,e.backend)?fn():{status:`decoded`,descriptor:Object.freeze({transport:e.transport,backend:e.backend,outputPath:e.outputPath,...e.pidPath===void 0?{}:{pidPath:e.pidPath}})}});function fn(){return{status:`invalid`,message:`Invalid Apple app-log descriptor`}}function pn(e){return e===`apple-log-stream`||e===`coredevice-console`}function mn(e){return e===`ios-simulator`||e===`ios-device`||e===`macos`}function hn(e,t){return e===`coredevice-console`?t===`ios-device`:t!==`ios-device`}function gn(e){return e===void 0||vn(e)}function _n(e){if(!e.device.appleOs)throw TypeError(`Apple app-log persistence requires an explicit appleOs identity`);return We({resourceKind:St,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:Ue(dn,e.descriptor)})}function vn(e){return typeof e==`string`&&e.trim().length>0}const yn={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.`},bn={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 xn(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 Sn(e,t,n,r){let i={},a=n?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`];if(s(t))i.logAvailable=!!await e.commands.which(`log`);else if(t.kind===`simulator`)i.simctlAvailable=await ut(async()=>ct(await e.appleTools.run({tool:`simctl`,args:[`help`],allowFailure:!0},r)),r);else if(t.iosPhysicalDeviceBackend===`xctest`)i.devicectlAvailable=!1,i.devicectlConsoleCapture=!1,a.push(T);else{i.devicectlAvailable=await ut(async()=>ct(await e.appleTools.run({tool:`devicectl`,args:[`--version`],allowFailure:!0},r)),r);let t=await xn(e,r);if(i.devicectlConsoleCapture=t.supported,!t.supported){let e=t.reason===`unsupported`?yn:bn;a.push(`${e.message} ${e.hint}`)}}return{backend:E(t),checks:i,notes:a}}function Cn(e,t){let n=En(e),r=[`subsystem == "${n}"`,`subsystem CONTAINS "${n}"`,`processImagePath ENDSWITH[c] "/${n}"`,`senderImagePath ENDSWITH[c] "/${n}"`];if(t){let e=En(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 wn(e){return zt([`spawn`,e.deviceId,`log`,`stream`,`--style`,`compact`,`--level`,`info`,`--predicate`,Cn(e.appBundleId,e.executableName)],{simulatorSetPath:e.simulatorSetPath})}function Tn(e,t){return[`devicectl`,`device`,`process`,`launch`,`--device`,e,`--console`,`--terminate-existing`,t]}function En(e){return e.replaceAll(`\\`,String.raw`\\`).replaceAll(`"`,String.raw`\"`)}async function Dn(e,t,n,r,i){On(t),$e(e,n);let a=E(t),o=await An(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 kn(e,t,o,l,n.pidPath,i);s.defer(async()=>{c||await u[Symbol.asyncDispose]()});let d=Mn(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=Xe(d,_n({sessionId:n.sessionId,device:t,owner:r,fence:n.fence,descriptor:f}));return c=!0,p}finally{await s[Symbol.asyncDispose]()}}function On(t){if(t.appleOs===`watchos`)throw new e(`UNSUPPORTED_PLATFORM`,`watchOS app logs are not supported`);if(o(t)&&t.kind===`device`&&t.iosPhysicalDeviceBackend===`xctest`)throw new e(`UNSUPPORTED_OPERATION`,T,{hint:T})}async function kn(t,n,r,i,a,s){if(o(n)&&n.kind===`device`){let n=await xn(t,s);if(!n.supported){let t=n.reason===`unsupported`?yn:bn;throw new e(n.reason===`unsupported`?`UNSUPPORTED_OPERATION`:`COMMAND_FAILED`,t.message,{backend:`ios-device`,hint:t.hint,stderr:n.stderr})}}return s?.throwIfAborted(),await t.processes.start({command:{kind:`host`,request:r},output:i,...a?{markerPath:a}:{}})}async function An(e,t,n,r){if(s(t))return{executable:`log`,args:[`stream`,`--style`,`compact`,`--predicate`,Cn(n)],allowFailure:!0};if(t.kind===`device`)return{executable:`xcrun`,args:Tn(t.id,n),allowFailure:!0};let i=await jn(e,t,n,r);return{executable:`xcrun`,args:wn({deviceId:t.id,appBundleId:n,executableName:i,simulatorSetPath:t.simulatorSetPath}),allowFailure:!0}}async function jn(e,t,n,r){let i=await e.appleTools.run({tool:`simctl`,args:y(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`,`-`,b.join(a,`Info.plist`)],allowFailure:!0,timeoutMs:4e3},r);return o.exitCode===0&&o.stdout.trim()||void 0}function Mn(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 nt({inspect:()=>({backend:r,state:o,startedAt:a}),finish:async()=>s??=(async()=>(await Nn([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 Nn(e){let t=[];for(let n of e)try{await n()}catch(e){t.push(e)}return t}const D=f(`apple`),O=Object.freeze({available:!0});function Pn(t){return Object.freeze({owner:D,ownsDevice:e=>e.platform===`apple`,inspectFacts:async e=>In(e),bind:async n=>{if(n.intent.kind===`exact-owner`&&!p(n.intent.owner,D))throw new e(`UNSUPPORTED_OPERATION`,`Apple app-log owner identity does not match`);return Fn(t,n.device,n.scope.signal)},shutdown:async()=>void 0})}function Fn(t,n,r){if(n.platform!==`apple`)throw new e(`UNSUPPORTED_PLATFORM`,`Apple app-log owner cannot bind ${n.platform}`);let i=Ye({codec:dn,reattach:async(e,r)=>e.backend!==E(n)||!qe(t,r.sessionId,e)?{status:`unreattachable`,reason:`descriptor-invalid`,message:`Apple app-log descriptor does not match the bound device or owning session`}:await Je(t,e.pidPath),cleanup:async(e,r)=>e.backend===E(n)&&qe(t,r.sessionId,e)?await et(t,e.pidPath):{status:`cleanup-pending`,reason:`ownership-fence-lost`,message:`Apple app-log descriptor does not match the bound device or owning session`}}),a=Object.freeze({appLogInspect:async()=>({backend:E(n)}),appLogDoctor:async({appBundleId:e})=>await Sn(t,n,e,r),appLogStart:async e=>await Dn(t,n,e,D,r),...i});return Object.freeze({device:n,owner:D,facts:In(n),operations:a,[Symbol.asyncDispose]:async()=>void 0})}function In(e){if(e.appleOs===`watchos`)return Ln(e);let t=o(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?{available:!1,reason:`unsupported-device-backend`,hint:T}:O;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:O,appLogCleanup:O}})}function Ln(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 Rn(e,t,n,r){let i=E(t),a=await e.appLogs.readRecent(n.sessionId,n.maxScanLines),o=Qe(a.text,{...n,path:a.path,exists:a.exists,lineNumberOffset:a.skippedLines,backend:i}),s=[];if(Bn(t,n,o.dump)){let i=await Vn(e,t,n,a.path,r);i&&(o=zn(s,o,i,n.maxEntries))}return Wn(s,t,n),Un(s,o.dump),o.dump.entries.length===0&&s.push(Gn(t)),Object.freeze({source:`app-log`,backend:i,dump:o.dump,notes:Object.freeze(s)})}function zn(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).`),tt(n.scan,t,r))}function Bn(e,t,n){return o(e)&&e.kind===`simulator`&&!!t.appBundleId&&n.entries.length===0}async function Vn(e,t,n,r,i){let a=y(t,[`spawn`,t.id,`log`,`show`,`--style`,`compact`,`--info`,`--predicate`,Hn(n.appBundleId)]),o=n.appLogSnapshot?.startedAt;a.push(...typeof o==`number`&&Number.isFinite(o)&&o>0?[`--start`,`@${Math.floor(o/1e3)}`]:[`--last`,`5m`]);let s=await e.appleTools.run({tool:`simctl`,args:a,allowFailure:!0,timeoutMs:4e3},i);if(s.exitCode!==0||!s.stdout.trim())return;let c=s.stdout.split(`
|
|
2
|
-
`).map(e=>e.trimEnd()).filter(e=>e.trim()&&!e.trim().startsWith(`Timestamp Ty Process[PID:TID]`));if(c.length!==0)return{scan:
|
|
3
|
-
`)}\n`,{...n,path:`${r} (simctl log show recovery)`,exists:!0,backend:`ios-simulator`}),lineCount:c.length}}function Hn(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 Un(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 Wn(e,t,n){n.appLogSnapshot?n.appLogSnapshot.state!==`active`&&e.length===0&&e.push(o(t)&&t.kind===`simulator`?`Session app log stream is inactive. The iOS simulator recovery path scanned recent simctl log history, but a fresh logs clear --restart window is still the most reliable repro loop.`:`Session app log stream is inactive. Run logs clear --restart, reproduce the request window again, then rerun network dump.`):e.push(`Capture uses the session app log file. For fresh traffic, run logs clear --restart before reproducing requests.`)}function Gn(e){return o(e)&&e.kind===`simulator`?`No HTTP(s) entries were found in recent iOS simulator app logs. If the app only emits non-HTTP diagnostics, inspect logs path or add app-side URLSession/network logging for per-request timing and payload details.`:o(e)?`No HTTP(s) entries were found in recent iOS device app logs. iOS network dump only sees what the app emits into Unified Logging for this process.`:`No HTTP(s) entries were found in recent session app logs.`}async function Kn(e){let{host:n,snapshot:r,targetLabel:i,recorderWarning:a,nativePathDisposition:o}=e,s=r.invalidatedReason?{recorder:`lost`,why:`owner-session-lost`}:e.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`,targetLabel:i})}catch(e){throw t(e,`COMMAND_FAILED`)}let l=[...c.warning?[c.warning]:[],...a?[a]:[]];return it(r,{...c,...l.length>0?{warning:l.join(` `)}:{},...r.invalidatedReason?{overlayWarning:`overlay unavailable: ${r.invalidatedReason}`}:{}},{stopObservation:s,...o===void 0?{}:{nativePathDisposition:o}})}async function qn(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 Jn(()=>t.screenRecording.finalize.complete({outputPath:a,showTouches:s===void 0&&n.showTouches,gestureEvents:n.gestureEvents,exportQuality:n.exportQuality??`medium`,targetLabel:r}))}catch(e){throw await t.screenRecording.outputs.remove(a),e}return{...c,...s===void 0?{}:{overlayWarning:`overlay unavailable: ${s}`},nativePathDisposition:await t.screenRecording.outputs.remove(o)===`removed`?`retired`:`retirable`}}async function Jn(e){try{return await e()}catch(e){throw t(e,`COMMAND_FAILED`)}}const Yn=[`outPath`,`startedAt`,`clientOutPath`,...lt],k=Object.freeze({resourceKind:ft,version:1,encode:e=>e.backend===`simctl`?{backend:e.backend,outputPath:e.outputPath,processes:e.processes.map(e=>({...e})),...e.recording===void 0?{}:{recording:{...e.recording}}}:{backend:e.backend,outputPath:e.outputPath,appBundleId:e.appBundleId,runnerSessionId:e.runnerSessionId,runnerAuthority:e.runnerAuthority,...e.remotePath===void 0?{}:{remotePath:e.remotePath}},decode:e=>sr(e)});function Xn(e){let{device:t,owner:n,input:r,descriptor:a}=e;return We({resourceKind:ft,sessionId:r.sessionId,device:i(t),owner:n,fence:r.fence,lifecycle:`open`,descriptor:Ue(k,a)})}function Zn(e){let t={};for(let n of Yn)e[n]!==void 0&&Object.assign(t,{[n]:e[n]});return t}async function Qn(e,t,n,r){let i=k.decode(n);return i.status!==`decoded`||!_r(t,i.descriptor)?{status:`cleanup-pending`,reason:`manual-recovery-required`}:i.descriptor.backend===`simctl`?await $n(e,i.descriptor.processes,r):await tr(e,t,i.descriptor)}async function $n(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(er(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(er(n)),i.every(e=>e===`already-missing`)?{status:`already-missing`}:{status:`cleaned`})}function er(e){return{kind:`session`,sessionId:e}}async function tr(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 nr(e){let{host:t,device:n,envelope:r}=e,i=k.decode(r.descriptor.body);return i.status===`decoded`?_r(n,i.descriptor)?i.descriptor.backend===`simctl`?await rr(e,i.descriptor):await ar(t,n,i.descriptor):A(`descriptor-invalid`,`Apple screen-recording descriptor does not match the bound device.`):A(`descriptor-invalid`,i.message)}async function rr(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=ir(st(e.envelope.metadata),t.outputPath);return r===void 0||i!==void 0&&!await or(e.host,i)?{status:`missing`}:{status:`restore-export`,recording:r,nativePath:t.outputPath,cleanup:async()=>await $n(e.host,t.processes,e.envelope.sessionId)}}function ir(e,t){if(e.finalization===void 0)return e.collectedPath??t}async function ar(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 or(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 sr(e){return typeof e.outputPath!=`string`||e.outputPath.length===0?M():e.backend===`simctl`?cr(e,e.outputPath):e.backend===`runner`?dr(e,e.outputPath):M()}function cr(e,t){let n=vr(e.processes),r=lr(e.recording);return!n||r===`invalid`?M():{status:`decoded`,descriptor:Object.freeze({backend:`simctl`,outputPath:t,processes:n,...r===void 0?{}:{recording:r}})}}function lr(e){if(e!==void 0)return n(e)&&ur(e)?Object.freeze(e):`invalid`}function ur(e){return j(e.outPath)&&pr(e.startedAt)&&fr(e.clientOutPath)&&ot(e)}function dr(e,t){return!j(e.appBundleId)||!j(e.runnerSessionId)||!mr(e.runnerAuthority)||!hr(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 fr(e){return e===void 0||j(e)}function pr(e){return typeof e==`number`&&Number.isFinite(e)}function mr(e){return e===`local-lease`||e===`scoped-provider`}function hr(e){return e===void 0||gr(e)}function gr(e){return typeof e==`string`&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(e)}function _r(e,t){return e.kind===`simulator`?t.backend===`simctl`:t.backend===`runner`?e.appleOs===`macos`?t.remotePath===void 0:o(e)?t.remotePath!==void 0&&gr(t.remotePath):t.remotePath===void 0:!1}function vr(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 yr(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 br=`iOS recording`,xr=`simctl recordVideo`;function Sr(e){return e.appleOs===`watchos`?Ir(`unsupported-platform-leaf`,`watchOS recording is not supported.`):o(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?Ir(`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 Cr(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await wr({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async e=>{let r=await nr({host:t,device:n,envelope:e.envelope});return r.status===`restore-export`?{status:`active`,handle:Er({host:t,restored:r})}:r},screenRecordingCleanup:async e=>await Qn(t,n,e.envelope.descriptor.body,e.envelope.sessionId)})}async function wr(e){return e.signal.throwIfAborted(),e.device.kind===`simulator`?await Tr(e):await Or(e)}async function Tr(e){let{host:t,device:n,owner:r,input:i,signal:a}=e;await yr(n,i,t.screenRecording.apple.isRunnerBundleId);let o=i.activeSessionApp?await t.screenRecording.apple.captureClockAnchor(n,i.activeSessionApp.bundleId,a):void 0,s=Ct(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 N(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 N(c).catch(()=>{}),e}let u,d,f=async()=>{await c.terminate();let e=await c.wait;return d=e,u=Ar(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=Fr(i,xr,{},o);return Pr({device:n,owner:r,input:i,descriptor:{backend:`simctl`,outputPath:s,processes:l,recording:Zn(p)},snapshot:p,finish:(e,n)=>dt({snapshot:e,progress:n,steps:{stop:f,collect:async e=>{try{await Dr(t,s,e)}catch(e){throw jr(e,u,d)}},finalize:async({collectedPath:n,exportPath:r})=>{try{return await qn({host:t,snapshot:e,targetLabel:br,collectedPath:n,exportPath:r,nativePath:s})}catch(e){throw jr(e,u,d)}},discard:async e=>{await t.screenRecording.outputs.remove(e)}}}),cleanup:async()=>{let e=await Nr(c);return(e.status===`cleaned`||e.status===`already-missing`)&&t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId}),e}})}function Er(e){let{host:t,restored:{recording:n,nativePath:r,cleanup:i}}=e,a=Object.freeze({...n,backend:xr,gestureEvents:[]});return rt(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 Dr(t,r,e)},finalize:async({collectedPath:i,exportPath:a})=>await qn({host:t,snapshot:e,targetLabel:br,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 Dr(e,t,n){await e.screenRecording.outputs.copy({from:t,to:n}),await e.screenRecording.finalize.sniff({outputPath:n})}async function Or(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??=kr(()=>t.screenRecording.apple.runRunner(n,{kind:`stop`,appBundleId:o,...c}).then(()=>void 0)).catch(e=>{throw l=void 0,e}),l);if(!Mr(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 Pr({device:n,owner:r,input:i,descriptor:{backend:`runner`,outputPath:i.outputPath,appBundleId:o,...c,...s.remotePath===void 0?{}:{remotePath:s.remotePath}},snapshot:Fr(i,`runner AVAssetWriter`,s),finish:async e=>(await u(),s.remotePath!==void 0&&await t.screenRecording.apple.retrieveRunnerRecording(n,s.remotePath,e.outPath),await Kn({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 kr(e){try{return await e()}catch(e){throw t(e,`COMMAND_FAILED`)}}function Ar(e){if(e.exitCode!==0)return e.signal?`simctl recordVideo was killed by ${e.signal}`:`simctl recordVideo exited with code ${e.exitCode}`}function jr(n,r,i){let a=t(n,`COMMAND_FAILED`);return r===void 0||i===void 0||a.details?.reason!==`recording-output-unplayable`?n:new e(a.code,`${a.message}; ${r}`,_(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 Mr(e,t){return e.appleOs===`macos`||!o(e)?t===void 0:t!==void 0&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(t)}async function N(e){return await e.terminate(),await e.wait}async function Nr(e){try{return await N(e),{status:`cleaned`}}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`Apple simulator cleanup failed`}}}function Pr(e){let{device:t,owner:n,input:r,descriptor:i,snapshot:a,finish:o,cleanup:s}=e,c=rt(a,{finish:o,forceCleanup:s});return Object.freeze({pendingHandle:new Ge(c),envelope:Xn({device:t,owner:n,input:r,descriptor:i})})}function Fr(e,t,n={},r){let i=Date.now();return Object.freeze({backend:t,outPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutPath:e.clientOutputPath},startedAt:i,scope:e.scope,showTouches:e.showTouches,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},...e.exportQuality===void 0?{}:{exportQuality:e.exportQuality},gestureEvents:[],...r===void 0?{}:{gestureClockOriginAtMs:r.wallClockAtMs,gestureClockOriginUptimeMs:r.uptimeMs},...n.recorderStartUptimeMs===void 0?{}:{gestureClockOriginAtMs:i,gestureClockOriginUptimeMs:n.recorderStartUptimeMs,runnerStartedAtUptimeMs:n.recorderStartUptimeMs},...n.runnerSessionId===void 0?{}:{runnerSessionId:n.runnerSessionId}})}function Ir(e,t){return Object.freeze({available:!1,reason:e,hint:t})}const Lr=15e3;async function P(e,t,n,r={}){return n.throwIfAborted(),await Tt(t)||s(t)?{...t,booted:!0}:t.kind===`device`?(await e.deviceReadiness.applePhysical.ensureConnected(t,n),{...t,booted:!0}):t.kind===`simulator`?((await Rr(e,t)?`Booted`:await Hr(e,t,n))!==`Booted`&&(r.onColdBootStart?.(),e.deviceReadiness.appleAutomation.keepHot(t),await zr(e,t,n,r.deadlineAtMs),await Ur(e,n)),e.deviceReadiness.appleAutomation.keepHot(t),e.deviceReadiness.appleAutomation.markBooted(t),{...t,booted:!0}):{...t,booted:!0}}async function Rr(e,t){try{return await e.deviceReadiness.appleAutomation.wasRecentlyObservedBooted(t)}catch{return!1}}async function zr(e,t,n,r=Date.now()+12e4){let i=!1;try{i=await Br(e,t,n,r),await Vr(e,t,n,r)}catch(a){throw i&&n.aborted&&Wr(e,t),n.throwIfAborted(),Date.now()>=r?I(t,a):a}}async function Br(t,n,r,i){let a=await t.appleTools.run({tool:`simctl`,args:y(n,[`boot`,n.id]),allowFailure:!0,timeoutMs:F(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 e(`COMMAND_FAILED`,`simctl boot failed`,{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode});return!s}async function Vr(t,n,r,i){le({type:`command`,status:`progress`,message:`Waiting for the Simulator to finish booting...`});let a=await t.appleTools.run({tool:`simctl`,args:y(n,[`bootstatus`,n.id,`-b`]),allowFailure:!0,timeoutMs:F(i,n)},r);if(a.exitCode!==0)throw new e(`COMMAND_FAILED`,`simctl bootstatus failed`,{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode});if(await Wt(t.appleTools,n,r,Math.min(Lr,F(i,n)))!==`Booted`)throw new e(`COMMAND_FAILED`,`Simulator is still booting`,{deviceId:n.id});if(Date.now()>=i)throw I(n)}function F(e,t){let n=e-Date.now();if(n<=0)throw I(t);return n}function I(t,n){return new e(`COMMAND_FAILED`,`Simulator did not finish booting within the startup budget`,{reason:`boot_timeout`,deviceId:t.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 Hr(e,t,n){return await Wt(e.appleTools,t,n,Lr)}async function Ur(e,t){await e.commands.run({executable:`open`,args:[`-a`,`Simulator`],allowFailure:!0,timeoutMs:1e4},t)}function Wr(e,t){e.appleTools.run({tool:`simctl`,args:y(t,[`shutdown`,t.id]),allowFailure:!0}).catch(()=>{})}const Gr=Object.freeze({resolveOpenTarget:`simulator`,prepareApplicationOpen:`simulator`,openApplication:`simulator`,applyRuntimeHints:`simulator`,clearRuntimeHints:`simulator`,closeApplication:`simulator`,finalizeApplicationClose:`simulator`,prepareAppleRunner:`runner`,configureProviderPortReverse:`simulator`,ensureReady:`simulator`,bootTarget:`simulator`,bootTargetHeadless:`simulator`,shutdownTarget:`simulator`,listApps:`simulator`,deployApp:`simulator`,materializeAppSource:`simulator`,deployMaterializedApp:`simulator`,sendPushNotification:`simulator`,appState:`simulator`,appLogStart:`simulator`,appLogInspect:`simulator`,appLogDoctor:`simulator`,appLogReattach:`simulator`,appLogCleanup:`simulator`,networkDump:`simulator`,audioProbeStart:`simulator`,audioProbeQuery:`simulator`,audioProbeReattach:`simulator`,audioProbeCleanup:`simulator`,readClipboard:`simulator`,writeClipboard:`simulator`,setSetting:`simulator`,readSetting:`simulator`,setFoldPose:`simulator`,captureSnapshot:`simulator`,captureSnapshotWithoutActiveApp:`simulator`,captureSnapshotWithCustomActions:`runner`,captureScreenshot:`simulator`,findText:`runner`,readTextAtPoint:`runner`,tapPoint:`runner`,tapRef:`runner`,tapElementSelector:`runner`,fillPoint:`runner`,fillRef:`runner`,longPressPoint:`runner`,hoverPoint:`runner`,hoverRef:`runner`,focusPoint:`runner`,typeText:`runner`,scrollDirection:`runner`,performGesturePlan:`runner`,performMultiTouchGesturePlan:`runner`,performTargetAuthoredDrag:`runner`,performDirectionalFlingPlan:`runner`,gestureViewport:`runner`,setViewport:`runner`,back:`runner`,home:`runner`,setOrientation:`runner`,appSwitcher:`runner`,actionButton:`runner`,tvRemote:`runner`,keyboardDismiss:`runner`,keyboardEnter:`runner`,keyboardStatus:`runner`,triggerAppEvent:`runner`,readAlert:`runner`,awaitAlert:`runner`,acceptAlert:`runner`,dismissAlert:`runner`,perfFrames:`runner`,perfMemorySample:`runner`,perfMemorySnapshot:`runner`,perfNativeCaptureStart:`runner`,perfNativeCaptureReattach:`runner`,perfNativeCaptureCleanup:`runner`,perfProfileReport:`runner`,screenRecordingStart:`runner`,screenRecordingReattach:`runner`,screenRecordingCleanup:`runner`});function Kr(e){return e===void 0?`possible`:e.some(e=>Gr[e]===`runner`)?`required`:`none`}const qr=3e3,Jr=`simulator-target-discovery-pending`;function Yr(){let e=new Map,t=new Map,n=Gt({waitMs:1500});return async(r,i,a,o)=>{a.throwIfAborted();let s=`${r.id}:${i}`,c=e.get(s);return c&&o!==`refresh`&&await qt(c.pid,{signal:a,timeoutMs:qr})===c.processStartTime?c:(e.delete(s),await n.value(s,{start:async()=>{let n=await Zr(r,i,t);return e.set(s,n),n},wait:(e,t)=>Kt({waitMs:e,signal:a,stop:t,cancelled:()=>a.reason}),pending:()=>L(Jr,r,i)}))}}function Xr(t){return t instanceof e&&t.details?.reason===Jr}async function Zr(e,t,n){let r=Date.now()+15e3,[i,a]=await Promise.allSettled([v(e,[`spawn`,e.id,`launchctl`,`list`],{allowFailure:!0,timeoutMs:ei(r)}),Qr(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 L(`simulator-target-probe-failed`,e,t);let c=$r(o.stdout,t);if(!c)throw L(`simulator-target-unavailable`,e,t);let l=await qt(c.pid,{timeoutMs:Math.min(qr,ei(r))});if(!l)throw L(`simulator-target-identity-unavailable`,e,t);return Object.freeze({udid:e.id,runtime:s,pid:c.pid,generation:`${c.pid}:${c.label}:${l}`,targetId:`${e.id}:${t}`,processStartTime:l,...e.simulatorSetPath?{simulatorSetPath:e.simulatorSetPath}:{}})}async function Qr(e,t,n){let r=t.get(e.id);if(r)return await r;let i=v(e,[`list`,`devices`,`-j`],{allowFailure:!0,timeoutMs:ei(n)}).then(t=>{if(t.exitCode!==0)throw L(`simulator-runtime-probe-failed`,e,``);let n=Object.entries(Rt(t.stdout)).find(([,t])=>t.some(t=>t.udid===e.id))?.[0];if(!n)throw L(`simulator-runtime-unavailable`,e,``);return n});t.set(e.id,i);try{return await i}catch(n){throw t.delete(e.id),n}}function $r(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 ei(e){return Math.max(1,e-Date.now())}function L(t,n,r){return new e(`COMMAND_FAILED`,`Unable to resolve the running iOS Simulator app (${t}).`,{reason:t,deviceId:n.id,appBundleId:r})}const ti=new Map([[`application-element-missing`,5e3],[`application-server-unavailable`,5e3],[`foreground-owner-unverified`,1e3],[`foreground-owner-changed`,1e3]]);function R(e){return e.platform===`apple`&&e.appleOs===`ios`&&e.kind===`simulator`}function ni(e){let t=ie(oe({depth:1,interactiveOnly:!0}));return Object.freeze({awaitObservable:async(n,r,i)=>{if(!R(n))return`not-eligible`;let a;for(;;){let o=await ri(e.resolveTarget,n,r,i);if(!o)return`unobservable`;if(e.isBridgeDisabled(o))return g({level:`debug`,phase:`ios_launch_observation_skipped`,data:{reason:`circuit-disabled`,deviceId:n.id,generation:o.generation}}),`unobservable`;let s=await e.source.acquire({target:o,hint:t,signal:i});if(s.stage!==`failed`)return`observable`;i.throwIfAborted();let c=ti.get(s.failure.code);if(c===void 0)return`unobservable`;let l=e.clock.now();if(a=Math.min(a??1/0,l+c),l>=a)return`unobservable`;await e.clock.sleep(Math.min(150,a-l),i)}}})}async function ri(e,t,n,r){for(;;)try{return await e(t,n,r)}catch(e){if(r.throwIfAborted(),!Xr(e))return}}function ii(e,t,n){let r=n&&R(e),i=r?Kr(t.execution.plannedOperations):void 0,a=o(e)&&t.surface===`app`&&t.positionals.length>0&&!!t.appBundleId&&i!==`none`;return{...i?{runnerDemand:i}:{},shouldPrewarmRunner:a,awaitPrewarmAfterOpen:t.relaunch&&!r}}function ai(e,t,n,r){r.runnerDemand===`none`&&e.appleApplications.releaseSpeculativeRunner(t.device,n.execution).catch(()=>{})}async function oi(e,t,n,r,i,a){let o=Date.now();r&&R(t.device)&&i&&n.appBundleId&&(a.postOpenObservation=await i.awaitObservable(t.device,n.appBundleId,t.signal)),r&&a.postOpenObservation!==`observable`&&await e.clock.sleep(300,t.signal),a.postOpenSettleDurationMs=Math.max(0,Date.now()-o)}function si(e){let t=Dt({device:e.device,signal:e.signal,resolveInteractor:e.host.localInteractors.resolve});return Object.freeze({resolveOpenTarget:async t=>await e.host.appleApplications.resolveOpenTarget(e.device,t),prepareApplicationOpen:async t=>{await P(e.host,e.device,e.signal,{deadlineAtMs:t.execution.startupDeadlineAtMs,onColdBootStart:t.prewarmRunnerOnColdBoot?()=>{e.host.appleApplications.prewarmRunnerCache(e.device,t.execution,e.signal).catch(()=>{})}:void 0})},openApplication:async n=>await ci(e.host,t,n,e.observation),applyRuntimeHints:async t=>await e.host.appleApplications.applyRuntimeHints(e.device,t),clearRuntimeHints:async t=>await e.host.appleApplications.clearRuntimeHints(e.device,t),closeApplication:async n=>await vi(e.host,t,n),finalizeApplicationClose:async t=>await yi(e.host,e.device,e.signal,t),prepareAppleRunner:async t=>await bi(e.host,e.device,e.signal,t),configureProviderPortReverse:Ti})}async function ci(e,t,n,r){let i={},a=z(t.device),o=xi(e,t,n,i),s=ii(t.device,n,a);s.runnerDemand&&(i.runnerDemand=s.runnerDemand),ai(e,t,n,s);let{shouldPrewarmRunner:c}=s,l=_i(t.device,n,a);a&&c&&!n.prewarmRunnerBeforeOpen&&o.schedule();try{await li(e,t,n,a,l,i),await ui(n,i),await di(o,c,n.prewarmRunnerBeforeOpen);let u=o.wasAwaited();return await fi(t,n,a,i),await mi(o,c,s.awaitPrewarmAfterOpen),await hi(e,t,n,a,u,l),await oi(e,t,n,a,r,i),{appBundleId:n.appBundleId,timing:i}}catch(n){throw l&&await e.appleApplications.stopRunnerSession(t.device.id).catch(()=>{}),n}}async function li(e,t,n,r,i,a){if(!gi(n,r)||!n.target)return;let o=Date.now();c(t.device.platform)&&!r&&!i&&await e.appleApplications.stopRunnerSession(t.device.id),await Et({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=B(o)}async function ui(t,n){if(!de(t.runtimeHints))return;if(!t.applyRuntimeHints)throw new e(`COMMAND_FAILED`,`Runtime hint operation was not admitted for this open.`,{reason:`runtime-hints-operation-missing`});let r=Date.now();await t.applyRuntimeHints({appId:t.appBundleId,values:t.runtimeHints}),n.runtimeHintsDurationMs=B(r)}async function di(e,t,n){!t||!n||(e.schedule(!0),await e.wait())}async function fi(e,t,n,r){let i=Ci(t,n),a=Date.now();await Ot({device:e.device,interactor:await e.resolveInteractor(t.execution,t.appBundleId),positionals:i.positionals,appBundleId:t.appBundleId,execution:t.execution,...n&&t.relaunch&&!t.execution.clearAppState?{terminateRunningApp:!0}:{}}),r.openDispatchDurationMs=B(a),await pi(e,t,i.followUpUrl,r)}async function pi(e,t,n,r){if(!n){r.launchUrlDurationMs=0;return}let i={...t.execution,clearAppState:void 0,launchConsole:void 0,launchArgs:void 0},a=Date.now();await Ot({device:e.device,interactor:await e.resolveInteractor(i,t.appBundleId),positionals:[n],appBundleId:t.appBundleId,execution:i}),r.launchUrlDurationMs=B(a)}async function mi(e,t,n){t&&!e.wasScheduled()&&e.schedule(),n?await e.wait():e.recordUnawaited()}async function hi(e,t,n,r,i,a){!o(t.device)||!r&&!a||!n.relaunch&&!i||r&&!i&&!await e.appleApplications.hasLiveRunnerSession(t.device,n.execution)||await e.appleApplications.notifyRunnerAppRelaunched(t.device,n.execution,t.signal)}function gi(e,t){return!!(e.relaunch&&e.target)&&!(t&&!e.execution.clearAppState)}function _i(e,t,n){return e.kind===`device`&&e.appleOs===`ios`&&gi(t,n)}async function vi(e,t,n){n.ensureReady&&await P(e,t.device,t.signal),c(t.device.platform)&&!z(t.device)&&await e.appleApplications.stopRunnerSession(t.device.id),await Et({device:t.device,interactor:await t.resolveInteractor(n.execution,n.appBundleId),positionals:n.positionals}),z(t.device)&&await e.clock.sleep(300,t.signal)}async function yi(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&&z(t)?await e.deviceShutdown.apple.shutdownTarget(t,n):void 0;return i===void 0?{}:{shutdown:i}}async function bi(e,t,n,r){let i=Date.now()+r.timeoutMs;await P(e,t,n,{deadlineAtMs:i});let a=Math.max(1,i-Date.now());return await e.appleApplications.prepareRunner(t,{...r,timeoutMs:a},n)}function xi(e,t,n,r){let i,a=!1,o=Si(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=B(e)},wasAwaited:()=>a,wasScheduled:()=>i!==void 0,recordUnawaited:()=>{i&&!a&&(r.runnerPrewarmWaited=!1)}}}function Si(e,t){return e.kind===`device`&&e.appleOs===`ios`&&!t.hasExistingSession&&!t.relaunch&&!t.prewarmRunnerBeforeOpen}function Ci(e,t){let n=e.runtimeLaunchUrl?.trim(),i=e.positionals.length===1?e.positionals[0]?.trim():void 0;return!n||!i||r(i)?{positionals:e.positionals}:t&&!wi(e)?{positionals:[i,n]}:{positionals:e.positionals,followUpUrl:n}}function wi(e){return e.execution.clearAppState===!0||!!e.execution.launchConsole?.trim()||!!e.execution.launchArgs?.length}function z(e){return o(e)&&e.kind===`simulator`}function B(e){return Math.max(0,Date.now()-e)}async function Ti(){throw new e(`UNSUPPORTED_OPERATION`,`This lifecycle operation is unavailable for Apple.`)}const Ei=Object.freeze({available:!0}),Di=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.`}),Oi=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Push notifications are supported on Apple simulators only.`}),ki=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Ai=Object.freeze({available:!1,reason:`unsupported-device-kind`});function ji(e){let t=zi(e);return Object.freeze({deployApp:t,materializeAppSource:t,deployMaterializedApp:t,sendPushNotification:Bi(e)})}function Mi(e){let{host:t,device:n,signal:r}=e,i=ji(n);return Object.freeze({...i.deployApp.available?{deployApp:async e=>await Ni(t,n,e,r),materializeAppSource:async e=>await t.appleDeployment.prepareArtifact(e,{signal:r}),deployMaterializedApp:async e=>await Pi(t,n,e,r)}:{},...i.sendPushNotification.available?{sendPushNotification:async e=>(await Li(t,n,e,r),{})}:{}})}async function Ni(e,t,n,r){if(n.replaceExisting)return await e.appleDeployment.withInvalidatedAppResolutionCache(t,async()=>{let i=await e.appleDeployment.resolveAppBundleId(t,n.app);await Ii(e,t,i,r);let a=await e.appleDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{appIdentifierHint:n.app,signal:r});try{return await Fi(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 Pi(e,t,{artifact:i},r)}finally{await i.cleanup()}}async function Pi(e,t,n,r){return await Fi(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 Fi(e,t,n,r){await P(e,t,r),await Ri(e,t.kind===`simulator`?{tool:`simctl`,args:y(t,[`install`,t.id,n])}:{tool:`devicectl`,args:[`device`,`install`,`app`,`--device`,t.id,n],timeoutMs:jt},r,`Apple app install failed`)}async function Ii(e,t,n,r){await P(e,t,r),await Ri(e,t.kind===`simulator`?{tool:`simctl`,args:y(t,[`uninstall`,t.id,n])}:{tool:`devicectl`,args:[`device`,`uninstall`,`app`,`--device`,t.id,n]},r,`Apple app uninstall failed for ${n}`,{tolerate:e=>Lt(`${e.stdout}\n${e.stderr}`.toLowerCase())})}async function Li(t,n,r,i){if(n.kind!==`simulator`)throw new e(`UNSUPPORTED_OPERATION`,`Apple push notifications require a simulator`);await P(t,n,i);let a=await t.temporaryFiles.create({prefix:`agent-device-ios-push-`,suffix:`.apns`});try{await a.writeText(`${JSON.stringify(r.payload)}\n`),await Ri(t,{tool:`simctl`,args:y(n,[`push`,n.id,r.appId,a.path])},i,`Apple push notification failed`)}finally{await a[Symbol.asyncDispose]()}}async function Ri(e,t,n,r,i){let a=await e.appleTools.run({...t,allowFailure:!0},n);return i?.tolerate?.(a)?a:te(a,r,e=>({cmd:`xcrun`,args:[t.tool,...t.args],...t.tool===`devicectl`?{hint:It(e.stdout,e.stderr)??`Ensure the iOS device is unlocked, trusted, and available in Xcode > Devices, then retry.`}:{}}))}function zi(e){return Vi(e)?e.kind!==`simulator`&&e.kind!==`device`?Ai:e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?Di:Ei:ki}function Bi(e){return Vi(e)?e.kind===`simulator`?Ei:Oi:ki}function Vi(e){return o(e)&&e.appleOs!==`watchos`}const V=Object.freeze({available:!0}),Hi=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`back is supported on Apple simulators and physical devices.`}),Ui=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function Wi(e){return e.kind!==`simulator`&&e.kind!==`device`?Hi:d(e)===`watchos`?Ui:V}const Gi=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`home is supported on Apple simulators and physical devices.`}),Ki=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),qi=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`app-switcher is supported on Apple simulators and physical devices.`});function Ji(e,t){if(e.kind!==`simulator`&&e.kind!==`device`)return t;let n=d(e);return n===`macos`||n===`watchos`?Ki:V}function H(e){if(e.kind!==`simulator`&&e.kind!==`device`)return!1;let t=d(e);return t!==`tvos`&&t!==`macos`&&t!==`watchos`}const Yi=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`orientation is supported on Apple simulators and physical devices.`}),Xi=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function Zi(e){return e.kind!==`simulator`&&e.kind!==`device`?Yi:H(e)?V:Xi}const Qi=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`tv-remote is supported only on tvOS devices.`});function $i(e){return(e.kind===`simulator`||e.kind===`device`)&&a(e)?V:Qi}const U=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),ea=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 ta(e){return H(e)?ea:U}function na(e){return H(e)?V:U}function ra(e){return H(e)?V:U}const ia=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`No Apple leaf carries this system button.`}),aa=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`action-button is supported on iPhone and iPad simulators and physical devices.`}),oa=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 sa(e){return e.kind!==`simulator`&&e.kind!==`device`?aa:l(e)?V:oa}function ca(e){return Object.freeze({...Ie({back:Wi(e)}),...ke({unsupported:ia,home:Ji(e,Gi),appSwitcher:Ji(e,qi),actionButton:sa(e)}),...he({orientation:Zi(e)}),...Le({tvRemote:$i(e)}),...Fe({unsupported:U,status:ta(e),dismiss:na(e),enter:ra(e)})})}function la(e){let{host:t,device:n,signal:r}=e;return gt({device:n,signal:r,resolveInteractor:t.localInteractors.resolve,facts:ca(n)})}const W=Object.freeze({available:!0}),ua=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`clipboard is supported on Apple simulators and the macOS host.`}),da=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`settings is supported on Apple simulators and the macOS host.`}),fa=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.`}),pa=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:"Apple targets answer a settings read only on iPhone and iPad simulators, where `simctl ui` reports the value the device holds."}),ma=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.`}),G=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function ha(e,t,n){if(e.kind!==`simulator`&&e.kind!==`device`)return t;let r=d(e);return r===`watchos`?G:e.kind===`simulator`||r===`macos`?W:n}function ga(e){return ha(e,ua,ma)}const _a=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`trigger-app-event is supported on Apple simulators and physical devices.`}),va=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`alert is supported on Apple simulators and physical devices.`}),ya=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`alert is supported on Apple simulators, the macOS host, and physical iOS devices.`});function ba(e){if(e.kind!==`simulator`&&e.kind!==`device`)return va;let t=d(e);return t===`watchos`?G:e.kind===`simulator`||t===`ios`||t===`macos`?W:ya}function xa(e){return e.kind!==`simulator`&&e.kind!==`device`?_a:d(e)===`watchos`?G:W}function Sa(e){let t=ga(e);return t.available?ma:t}function Ca(e){return e.kind!==`simulator`&&e.kind!==`device`?da:d(e)===`watchos`?G:u(e)?W:pa}function wa(e){let t=ga(e),n=ba(e);return Object.freeze({...Ae({unsupported:Sa(e),read:t,write:t}),...Me({read:n,wait:n,accept:n,dismiss:n}),...Pe({triggerAppEvent:xa(e)}),...Ne({setSetting:ha(e,da,fa),readSetting:Ca(e)})})}function Ta(e){let{host:t,device:n,signal:r}=e;return gt({device:n,signal:r,resolveInteractor:t.localInteractors.resolve,facts:wa(n)})}const Ea=/Angle:\s*(-?\d+(?:[.,]\d+)?)\s*°/g;async function Da(t,n={}){let r=[`devicectl`,`device`,`motion`,`hinge-angle`,`--device`,t.id,`--session-timeout`,`1`,`--timeout`,`5`],i=await Ft(r,{allowFailure:!0,signal:n.signal,timeoutMs:Nt}),a=Oa(i.stdout)??Oa(i.stderr);if(a!==void 0)return a;throw new e(`COMMAND_FAILED`,`CoreDevice reported no hinge angle sample`,_(i,{cmd:`xcrun`,args:r,stdout:i.stdout,stderr:i.stderr,deviceId:t.id,hint:`This Xcode/CoreDevice toolchain does not stream 'devicectl device motion hinge-angle' for this device. Foldable poses can be verified only through that stream; update Xcode to a version that ships it.`}))}function Oa(e){let t;for(let n of e.matchAll(Ea)){let e=Number.parseFloat(n[1].replace(`,`,`.`));Number.isFinite(e)&&(t=e)}return t}async function ka(t,n,r){r?.throwIfAborted();let i=await kt(`agent-device-fold-`);try{let a=b.join(i,`fold`),o=await Ft([`--sdk`,`iphonesimulator`,`clang`,`-mios-simulator-version-min=15.0`,`-fobjc-arc`,`-Wall`,`-Wextra`,`-Werror`,`-framework`,`Foundation`,`-framework`,`IOKit`,b.join(ne(),`apple`,`fold-helper`,`Fold.m`),`-o`,a],{signal:r,timeoutMs:3e4,allowFailure:!0});if(o.exitCode!==0)throw new e(`COMMAND_FAILED`,`Unable to build the simulator fold helper`,_(o,{reason:`fold-helper-build-failed`,hint:`Select an Xcode with the iOS simulator SDK and foldable HID support using DEVELOPER_DIR.`}));r?.throwIfAborted();let s=typeof n==`string`?0:n.at(-1).atMs,c=typeof n==`string`?n:JSON.stringify(n),l=await v(t,[`spawn`,t.id,a,c],{signal:r,timeoutMs:s+1e4,kill:{signal:`SIGTERM`,graceMs:1e3},allowFailure:!0});if(l.exitCode!==0)throw new e(`COMMAND_FAILED`,`Unable to send the simulator hinge pose`,_(l,{reason:`fold-hid-dispatch-failed`,deviceId:t.id}))}finally{await At(i)}}async function Aa(e,t,n={}){n.signal?.throwIfAborted(),Vt(e,`fold`);let r=t,i=r.keyframes?.at(-1)?.angle,a=r.pose??h(i);ja(e,await Ht(e,{signal:n.signal})),await ka(e,r.keyframes??a,n.signal),g({level:`info`,phase:`apple_fold_pose_dispatched`,data:{deviceId:e.id,pose:a}});let o=await Ma(e,a,n.signal,i),s=await Va(e,n.signal);return{pose:h(o),hingeAngleDegrees:o,...s?{screen:Ha(s)}:{}}}function ja(t,n){if(n.unresolved)throw new e(`COMMAND_FAILED`,`CoreDevice reported no display table for this simulator`,{deviceId:t.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 e(`UNSUPPORTED_OPERATION`,`${t.name} is not a foldable simulator: fold requires more than one integrated panel`,{deviceId:t.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 Ma(e,t,n,r){let i,a;for(let o=1;o<=4;o+=1)if(n?.throwIfAborted(),a=i,i=await Da(e,{signal:n}),Na(i,a,t,r))return i;throw Ia(e,t,i,a,r)}function Na(e,t,n,r){return r===void 0?h(e)===n?n!==`half-open`||t!==void 0&&La(e,t):!1:Pa(e,t,r)}function Pa(e,t,n){return Fa(e,n)?n===0||n===180||t!==void 0&&Fa(t,n)&&Math.abs(e-t)<=.5:!1}function Fa(e,t){return t===void 0||e!==void 0&&Math.abs(e-t)<=.5}function Ia(t,n,r,i,a){return Fa(r,a)?a!==void 0&&r!==void 0?Ba(t,h(r),r,i):r!==void 0&&n===`half-open`&&h(r)===n?Ba(t,n,r,i):za(t,n,r):new e(`COMMAND_FAILED`,`The hinge did not reach the final keyframe angle`,{reason:`fold-angle-unverified`,targetAngleDegrees:a,hingeAngleDegrees:r,deviceId:t.id})}function La(e,t){return h(e)===`half-open`&&h(t)===`half-open`&&Math.abs(e-t)<=.5}function Ra(e,t,n){return{deviceId:e.id,requestedPose:t,observedPose:n===void 0?void 0:h(n),hingeAngleDegrees:n}}function za(t,n,r){return new e(`COMMAND_FAILED`,`${t.name} did not reach the ${n} pose: CoreDevice still reports a hinge angle of ${r}°`,{...Ra(t,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 Ba(t,n,r,i){return new e(`COMMAND_FAILED`,`${t.name} was observed ${n} at ${r}° but did not settle: 4 hinge reads never held two consecutive angles within ${Mt}° of each other`,{...Ra(t,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 Va(e,t){let n=await Ht(e,{signal:t});if(!(n.unresolved||n.ambiguous))return n.activeDisplay}function Ha(e){return{display:e.name,coordinateSpace:ce,widthPt:Math.round(e.widthPx/e.pointScale),heightPt:Math.round(e.heightPx/e.pointScale)}}const Ua=Object.freeze({available:!0}),Wa=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.`}),Ga=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 Ka(e){if(e.kind!==`simulator`)return Wa;let t=d(e);return t===`ios`||t===`ipados`?Ua:Ga}function qa(e){return se({fold:Ka(e)})}function Ja(e){let{device:t,signal:n}=e;return m(qa(t).setFoldPose,()=>({setFoldPose:async e=>(n.throwIfAborted(),await Aa(t,e,{signal:n}))}))}function Ya(e,t,n){let r=ye({device:t.device,signal:t.signal,resolveInteractor:e.localInteractors.resolve}),i=async i=>{if(s(t.device)&&i.options?.surface!==void 0&&i.options.surface!==`app`)return await e.snapshot.captureSurface(t.device,i.options,Oe(t.signal,i));if(!n)return await r.captureSnapshot(i);let a=Oe(t.signal,i);return await n.capture(t.device,i,a,async e=>await r.captureSnapshot(e))};return Object.freeze({captureSnapshot:i,captureSnapshotWithCustomActions:i,captureSnapshotWithoutActiveApp:i})}function Xa(e,t){return Object.freeze({findText:async n=>{let r=await Za(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 Za(e,t,n){let r=n.options?.appBundleId;if(r===void 0)return;let i=n.options?.surface;if(s(t.device)&&i!==void 0&&i!==`app`)return;let a=n.signal?AbortSignal.any([t.signal,n.signal]):t.signal;if(a.throwIfAborted(),await Qa(e,t.device,n.execution))return{appBundleId:r,signal:a}}async function Qa(e,t,n){return!R(t)||await e.appleApplications.hasLiveRunnerSession(t,n??{})}function $a(){let e,t=!1,n=async()=>(e??=import(`./adapter.js`).then(({createSimulatorSnapshotSource:e})=>e()),await e);return{acquire:async e=>t?{stage:`failed`,failure:{kind:`unsupported`,code:`source-closed`}}:await(await n()).acquire(e),close:async()=>{t=!0,e&&await(await e).close()}}}function eo(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 to(n,r);return a!==`absent`&&a!==`unknown`&&t.set(n.id,{at:e(),host:a.host}),a}}async function to(e,t){let n=!1;for(let r of pt){let i=await no(r.processExecutable,t);if(i===`unknown`){n=!0;continue}for(let a of i){let i=await ro(a,e.id,t);if(i===`unknown`)n=!0;else if(i)return{kind:`present`,host:r}}}return n?`unknown`:`absent`}async function no(e,t){let n=await io(`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 ro(e,t,n){let r=await io(`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 io(e,t,n){try{let r=await Pt(e,t,{allowFailure:!0,timeoutMs:3e3,...n?{signal:n}:{}});return{exitCode:r.exitCode,stdout:r.stdout}}catch{return`unknown`}}const ao=`system-surface-presented`,oo=`system-surface-host-lingering`,so=`window-coordinate-space-unresolved`;function co(t,n={}){let r=n.source??$a(),i=n.resolveTarget??Yr(),a=n.systemSurfacePresent??eo(),o=new Set,s=new Map,c=e=>(Co(e,s,o),o.has(wo(e))),l=ni({source:r,resolveTarget:i,clock:t.clock,isBridgeDisabled:c});return Object.freeze({awaitObservable:l.awaitObservable,shutdown:async()=>await r.close(),capture:async(n,s,l,u)=>{if(!uo(n,s))return await ho(n,s,u);let d=await a(n,l);if(d===`unknown`)return await K(n.id,s,u,_o(n.id,s),q(s),`system-surface-probe-unavailable`,[So()]);if(d!==`absent`)return await mo(n,s,u,d.host.bundleId);let f;try{f=await lo(t,i,n,s,l)}catch(e){return l.throwIfAborted(),J(`target-resolution-failed`,n,void 0,e),await K(n.id,s,u,_o(n.id,s),q(s),`target-resolution-failed`,[So()])}if(c(f))return await K(n.id,s,u,f,q(s),`circuit-disabled`);let p=q(s),m=await r.acquire({target:f,hint:ie(p),signal:l});if(m.stage===`failed`){if(m.failure.kind===`cancelled`)throw l.throwIfAborted(),new e(`COMMAND_FAILED`,`Simulator AX snapshot acquisition was cancelled.`,{reason:m.failure.code,...m.failure.details});let t=await xo(m.failure,f,n,s.options.appBundleId,l,i);return await fo(s,u,f,t,p,m.failure,o)}try{return await ee(`ios.snapshot-source.present`,async()=>await t.snapshot.presentIosAcquisition(m,s.options),{producer:`simulator-ax-bridge`})}catch(e){return await fo(s,u,f,{lineage:f,residue:[]},p,{kind:`malformed-tree`,code:`presentation-invariant`},o,e)}}})}async function lo(e,t,n,r,i){let a=r.options.appBundleId;for(;;)try{return await t(n,a,i)}catch(t){if(!Xr(t))throw t;let i={requestId:r.execution?.requestId};if(await e.appleApplications.hasLiveRunnerSession(n,i))throw t}}function uo(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 fo(e,t,n,r,i,a,o,s){return po(a)&&o.add(wo(n)),J(a.code,{id:n.udid},n.generation,s,a.details),await K(n.udid,e,t,r.lineage,i,a.code,r.residue)}function po(e){return e.kind!==`preparing`&&e.code!==so}async function K(e,t,n,r,i,a,o=[]){return go(e,await n(t),r,i,a,o)}async function mo(e,t,n,r){let i=await n(t),a=i.systemSurface?ao:oo;return i.systemSurface||J(a,e,void 0,void 0,{detectedHost:r}),go(e.id,i,_o(e.id,t),q(t),a)}async function ho(e,t,n){let r=await n(t),i=r.systemSurface;return i?{...r,comparisonIdentity:yo(vo(e.id,i.bundleId),q(t),[])}:r}function go(e,t,n,r,i,a=[]){let o=t.systemSurface;return{...t,comparisonIdentity:yo(o?vo(e,o.bundleId):n,r,[...o?[]:a,{kind:`fallback-source`,producer:`apple-runner`}]),warnings:[...t.warnings??[],bo(i,n,o!==void 0)]}}function _o(e,t){return{targetId:`${e}:${t.options.appBundleId}`}}function vo(e,t){return{targetId:`${e}:${t}`}}function yo(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:ae(t),residue:Object.freeze([...n])})}function bo(e,t,n){return e===ao?`Simulator AX snapshot inapplicable (${e}); used XCTest to read the system surface presented over the app.`:e===oo?`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===so?`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 xo(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:[So()]}}}function So(){return{kind:`unknown-generation`,captureId:Jt()}}function q(e){return oe({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 Co(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 wo(e){return`${e.targetId}:${e.generation}`}function J(e,t,n,r,i){g({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=f(`apple`),X=Object.freeze({available:!0}),Z=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),To=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`viewport resizes web targets only (--platform web). Apple screen geometry is fixed by the selected simulator or device type — open a different simulator to test another screen size.`}),Eo=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`the stateless audio page probe is a web-session operation; Apple targets use the host capture.`}),Do=Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`perf requires an Apple simulator, macOS device, or CoreDevice-backed physical Apple device.`}),Oo=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`focus is supported on Apple simulators and physical devices.`}),ko=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple appstate is unavailable: the Apple target answers no sessionless foreground probe, and a session-scoped guess about the foreground is not a fact. The per-command answer is the targetActivation disclosure, which a capture carries when its command had to re-activate the session app (#2682).`}),Ao=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Headless boot is supported only for local Android emulators.`}),jo=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS has no XCUITest-driveable UI, so element text comes from the captured tree only.`}),Mo=Object.freeze({available:!1,reason:`unsupported-device-kind`}),No=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS open is not supported because XCUITest cannot drive watchOS UI.`}),Po=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS runner preparation is not supported because XCUITest cannot drive watchOS UI.`}),Fo=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS close is not supported because XCUITest cannot drive watchOS UI.`}),Io=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Runtime hints are supported only for local iOS-family simulators and Android devices.`}),Lo=Q(`open is supported only for Apple simulators and devices.`),Ro=Q(`prepare is supported only for Apple simulators and devices.`),zo=Q(`close is supported only for Apple simulators and devices.`),Bo=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`}),Vo=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`shutdown is supported only for Apple simulators and Android emulators.`}),Ho=Q(`snapshot is supported only for Apple simulators and devices.`),Uo=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Re-run without --actions, or target an iOS simulator.`}),Wo=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`screenshot is not supported on watchOS because XCUITest cannot drive watchOS UI.`}),Go=Q(`screenshot is supported only for Apple simulators and devices.`),Ko=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`Open the app under test before capturing its snapshot.`});function Q(e){return Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:e})}function qo(e){return!o(e)||e.appleOs===`watchos`?Z:e.kind===`simulator`?X:Vo}function Jo(e){let t=Yo(e),n=Xo(e),r=Zo(e),i=Qo(e);return fe({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:i,clearRuntimeHints:i,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:n,configureProviderPortReverse:Bo})}function Yo(e){return d(e)===`watchos`?No:e.kind===`simulator`||e.kind===`device`?X:Lo}function Xo(e){return d(e)===`watchos`?Po:e.kind===`simulator`||e.kind===`device`?X:Ro}function Zo(e){return d(e)===`watchos`?Fo:e.kind===`simulator`||e.kind===`device`?X:zo}function Qo(e){return d(e)!==`watchos`&&o(e)&&e.kind===`simulator`?X:Io}function $o(e){return e.appleOs===`watchos`?Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS app inventory is not supported.`}):e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`App inventory is available only on CoreDevice-backed physical iOS devices.`}):X}function $(e){return e.kind===`simulator`||e.kind===`device`?X:Oo}function es(e){let t=Pn(e),n=co(e),r=async n=>{let r=await t.inspectFacts(n),i=ji(n),a=Sr(n),c=a.available?await e.screenRecording.apple.availability(n):void 0,l=a.available&&c?.available===!1?Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:c.hint}):a,u=n.appleOs===`watchos`?Z:X,d=s(n)||n.appleOs===`watchos`?Z:X,f=$o(n);return Object.freeze({device:r.device,operations:{...r.operations,...i,appState:ko,networkDump:X,screenRecordingStart:l,screenRecordingReattach:l,screenRecordingCleanup:l,...as(n),...xe({capture:is(n)}),...De({findText:rs(n)}),...me({setViewport:To}),...Re({focus:$(n)}),...rn(n),...pe({type:$(n)}),...Ve({unsupported:Z,tap:$(n),longPress:$(n),fill:$(n),...o(n)?{tapElementSelector:$(n)}:{}}),...ge({readTextAtPoint:ns(n)}),...ca(n),...qa(n),...wa(n),...ze({capture:Xt(n),query:Eo}),...Be(ts(n)),ensureReady:u,bootTarget:d,bootTargetHeadless:Ao,listApps:f,...Jo(n),shutdownTarget:qo(n)}})};return Object.freeze({owner:Y,ownsDevice:e=>e.platform===`apple`,inspectFacts:r,bind:async i=>{let a=await t.bind(i),o=await r(i.device),s=o.operations.screenRecordingStart,c={...a.operations,...Mi({host:e,device:i.device,signal:i.scope.signal}),networkDump:async t=>await Rn(e,i.device,t,i.scope.signal),...m(s,()=>Cr({host:e,device:i.device,owner:Y,signal:i.scope.signal})),...m(o.operations.audioProbeStart,()=>Ze({host:e.audioProbe.hostCapture,device:i.device,owner:Y})),...m(o.operations.perfFrames,()=>Zt({resolveHost:()=>e.perf.apple,device:i.device,owner:Y})),...m(o.operations.captureSnapshot,()=>Ya(e,{device:i.device,signal:i.scope.signal},n)),...m(o.operations.captureScreenshot,()=>Se({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...m(o.operations.focusPoint,()=>Ce({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...Ee({device:i.device,signal:i.scope.signal,facts:o.operations,resolveInteractor:e.localInteractors.resolve}),...m(o.operations.scrollDirection,()=>je({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...m(o.operations.typeText,()=>Te({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...m(o.operations.tapPoint,()=>He({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)})),...m(o.operations.readTextAtPoint,()=>_e({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...m(o.operations.findText,()=>Xa(e,{device:i.device,signal:i.scope.signal})),...la({host:e,device:i.device,signal:i.scope.signal}),...Ta({host:e,device:i.device,signal:i.scope.signal}),...Ja({device:i.device,signal:i.scope.signal}),...m(o.operations.ensureReady,()=>({ensureReady:async()=>await P(e,i.device,i.scope.signal)})),...m(o.operations.bootTarget,()=>({bootTarget:async()=>await P(e,i.device,i.scope.signal)})),...m(o.operations.listApps,()=>({listApps:async e=>{i.scope.signal.throwIfAborted();let{listIosApps:t}=await import(`./app-resolution.js`).then(e=>e.t);return(await t(e.device,e.filter)).map(e=>({id:e.bundleId,name:e.name}))}})),...ue(si({host:e,device:i.device,signal:i.scope.signal,observation:n}),o.operations),...m(o.operations.shutdownTarget,()=>({shutdownTarget:async()=>await e.deviceShutdown.apple.shutdownTarget(i.device,i.scope.signal)}))};return Object.freeze({device:a.device,owner:Y,facts:o,operations:Yt(c),[Symbol.asyncDispose]:async()=>await a[Symbol.asyncDispose]()})},shutdown:async()=>{await Promise.all([t.shutdown(),n.shutdown()])}})}function ts(e){let t=e.iosPhysicalDeviceBackend!==`xctest`&&d(e)!==`watchos`?X:Do;return{frames:t,memorySample:t,memorySnapshot:t,nativeCapture:t,profileReport:t}}function ns(e){return d(e)===`watchos`?jo:e.kind===`simulator`||e.kind===`device`?X:Mo}function rs(e){return d(e)===`watchos`?Ho:e.kind===`simulator`||e.kind===`device`?X:Ho}function is(e){return d(e)===`watchos`?Wo:e.kind===`simulator`||e.kind===`device`?X:Go}function as(e){let t=rs(e);return ve({capture:t,customActions:t.available&&o(e)&&e.kind===`simulator`?X:Uo,withoutActiveApp:o(e)?Ko:t})}export{es as createApplePlatformRuntime};
|
|
1
|
+
import{A as e,M as t,R as n,j as r}from"./sdk-contracts.js";import{_ as i,i as a}from"./sdk-batch-runner.js";import{D as o,_ as s,d as c,f as l,l as u,o as d,u as f,w as p}from"./sdk-device.js";import{Yt as m,en as ee,nn as te,tn as h}from"./sdk-batch.js";import{r as ne}from"./session.js";import"./device.js";import{c as g}from"./device-rotation.js";import{c as re,r as _}from"./diagnostics.js";import{a as ie,n as v}from"./exec.js";import"./diagnostics2.js";import"./command.js";import{n as ae}from"./scoped-provider.js";import{i as oe,n as se,r as ce}from"./ios-snapshot-planning.js";import{n as le,t as ue}from"./fold-runtime.js";import{t as de}from"./request.js";import{n as fe,r as pe,t as me}from"./application-lifecycle-runtime.js";import{A as he,B as ge,C as _e,D as ve,E as ye,G as be,H as xe,I as Se,J as Ce,K as we,L as Te,N as Ee,O as De,P as Oe,V as ke,W as Ae,d as je,h as Me,j as Ne,n as Pe,o as Fe,s as Ie,v as Le,w as Re,x as ze,z as Be}from"./alert-runtime.js";import{n as Ve}from"./audio-probe-runtime.js";import{n as He}from"./perf-runtime.js";import{i as Ue,t as We}from"./touch-runtime.js";import{a as Ge,n as Ke}from"./durable-resource.js";import{n as qe,t as Je}from"./async-lifecycle.js";import{a as Ye,c as Xe,d as Ze,f as Qe,l as $e,n as et,o as tt,s as nt,t as rt,u as it}from"./src7.js";import{n as at,t as ot}from"./screen-recording-completion.js";import{a as st,i as ct,n as lt,o as ut,r as dt,s as ft,t as pt}from"./stop-sequence.js";import{n as mt}from"./screen-recording-runtime.js";import{t as ht}from"./ios-system-surface.js";import{i as gt,r as _t}from"./gesture-admission.js";import{t as vt}from"./interactor-operation-catalog.js";import{a as yt,i as bt,n as xt,r as St,t as Ct}from"./perf-runtime-operation-builder.js";import{t as wt}from"./app-log-runtime.js";import{n as Tt}from"./artifact-paths.js";import{i as Et,r as Dt}from"./managed-device-scope.js";import{a as Ot,n as kt,o as At}from"./application-lifecycle-interaction.js";import{a as jt,o as Mt,s as Nt}from"./config.js";import{a as Pt,o as Ft}from"./tool-provider.js";import{o as It}from"./devicectl.js";import{t as Lt}from"./physical-device-apps.js";import{t as Rt}from"./apple-runner-platform.js";import{a as zt,i as Bt,l as Vt,n as Ht,o as y,s as Ut}from"./simctl.js";import{a as Wt,r as Gt}from"./simulator.js";import{r as Kt}from"./display-inventory.js";import{t as qt}from"./multitouch-support.js";import{t as Jt}from"./simulator-state.js";import{_ as Yt,c as Xt,g as Zt,i as Qt,n as $t,p as en,r as tn,t as nn,u as rn,v as an}from"./native-build-cache.js";import b from"node:path";import{randomUUID as on}from"node:crypto";function sn(e){let t=Et();return Object.freeze(t?{...ae({...e},e=>Wt(t,e))}:e)}function cn(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 te(`Runtime owner advertised appState without an interactor implementation`);return await r.appState()}})}function ln(e){return st(e)?Object.freeze({available:!0}):l(e)||c(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 un(e){let{resolveHost:t,device:n,owner:r}=e;return Object.freeze({...Ct({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 bt(t().sampleFrames(n,e)):xt(`Apple`,`bundle ID`),sampling:await t().frameSampling(n)}),perfMemorySample:async({appId:e})=>({metric:e?await bt(t().sampleMemory(n,e)):xt(`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 yt(`Apple`,o,s,`Use perf memory snapshot --kind memgraph for supported Apple app sessions.`);if(!e)throw St();let c=i??b.join(a,`memory-memgraph-${dn()}.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 dn(){return new Date().toISOString().replaceAll(/[:.]/g,`-`)}const x=Object.freeze({available:!0}),S=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),C=hn(`Gestures are supported only for Apple simulators and devices.`),fn=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:_t}),pn=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:gt}),mn=hn(`scroll is supported only for Apple simulators and devices.`);function hn(e){return Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:e})}function gn(e){return{...Se({unsupported:_n(e),plan:vn(e),directionalFling:vn(e),multiTouch:yn(e),targetAuthoredDrag:bn(e),viewport:xn(e)}),...Ee({scroll:Sn(e)})}}function _n(e){return e.appleOs===`watchos`||e.appleOs===`visionos`?S:C}function vn(e){return e.appleOs===`watchos`||e.appleOs===`visionos`?S:w(e)?x:C}function yn(e){if(e.appleOs===`watchos`)return S;if(!w(e))return C;let t=p(e);if(t!==`ios`&&t!==`ipados`){let e=qt[t];return Object.freeze({available:!1,reason:`unsupported-platform-leaf`,...e===void 0?{}:{hint:e}})}return e.kind===`simulator`?x:fn}function bn(e){return w(e)?(e.appleOs===void 0?e.target!==`desktop`&&e.target!==`tv`:e.appleOs===`ios`||e.appleOs===`ipados`)?x:pn:C}function xn(e){return e.appleOs===`watchos`?S:w(e)?x:C}function Sn(e){return w(e)?x:mn}function w(e){return e.kind===`simulator`||e.kind===`device`}const T=`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`;function E(e){return l(e)?`macos`:e.kind===`device`?`ios-device`:`ios-simulator`}const Cn=Object.freeze({resourceKind:wt,version:1,encode:e=>({...e}),decode:e=>!Tn(e.transport)||!En(e.backend)||!An(e.outputPath)||!On(e.pidPath)||!Dn(e.transport,e.backend)?wn():{status:`decoded`,descriptor:Object.freeze({transport:e.transport,backend:e.backend,outputPath:e.outputPath,...e.pidPath===void 0?{}:{pidPath:e.pidPath}})}});function wn(){return{status:`invalid`,message:`Invalid Apple app-log descriptor`}}function Tn(e){return e===`apple-log-stream`||e===`coredevice-console`}function En(e){return e===`ios-simulator`||e===`ios-device`||e===`macos`}function Dn(e,t){return e===`coredevice-console`?t===`ios-device`:t!==`ios-device`}function On(e){return e===void 0||An(e)}function kn(e){if(!e.device.appleOs)throw TypeError(`Apple app-log persistence requires an explicit appleOs identity`);return Ke({resourceKind:wt,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:Ge(Cn,e.descriptor)})}function An(e){return typeof e==`string`&&e.trim().length>0}const jn={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.`},Mn={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 Nn(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 Pn(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(l(t))i.logAvailable=!!await e.commands.which(`log`);else if(t.kind===`simulator`)i.simctlAvailable=await ft(async()=>ut(await e.appleTools.run({tool:`simctl`,args:Ut(),allowFailure:!0},r)),r);else if(t.iosPhysicalDeviceBackend===`xctest`)i.devicectlAvailable=!1,i.devicectlConsoleCapture=!1,a.push(T);else{i.devicectlAvailable=await ft(async()=>ut(await e.appleTools.run({tool:`devicectl`,args:[`--version`],allowFailure:!0},r)),r);let t=await Nn(e,r);if(i.devicectlConsoleCapture=t.supported,!t.supported){let e=t.reason===`unsupported`?jn:Mn;a.push(`${e.message} ${e.hint}`)}}return{backend:E(t),checks:i,notes:a}}function Fn(e,t){let n=Rn(e),r=[`subsystem == "${n}"`,`subsystem CONTAINS "${n}"`,`processImagePath ENDSWITH[c] "/${n}"`,`senderImagePath ENDSWITH[c] "/${n}"`];if(t){let e=Rn(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 In(e,t){return Ht(e,[`spawn`,e.id,`log`,`stream`,`--style`,`compact`,`--level`,`info`,`--predicate`,Fn(t.appBundleId,t.executableName)])}function Ln(e,t){return[`devicectl`,`device`,`process`,`launch`,`--device`,e,`--console`,`--terminate-existing`,t]}function Rn(e){return e.replaceAll(`\\`,String.raw`\\`).replaceAll(`"`,String.raw`\"`)}async function zn(e,t,n,r,i){Bn(t),tt(e,n);let a=E(t),o=await Hn(e,t,n.appBundleId,i),s=new Je,c=!1;try{let l=await e.outputs.openAppend(n.outputPath);s.defer(async()=>{c||await l[Symbol.asyncDispose]()}),i?.throwIfAborted();let u=await Vn(e,t,o,l,n.pidPath,i);s.defer(async()=>{c||await u[Symbol.asyncDispose]()});let d=Wn(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=Qe(d,kn({sessionId:n.sessionId,device:t,owner:r,fence:n.fence,descriptor:f}));return c=!0,p}finally{await s[Symbol.asyncDispose]()}}function Bn(t){if(t.appleOs===`watchos`)throw new e(`UNSUPPORTED_PLATFORM`,`watchOS app logs are not supported`);if(c(t)&&t.kind===`device`&&t.iosPhysicalDeviceBackend===`xctest`)throw new e(`UNSUPPORTED_OPERATION`,T,{hint:T})}async function Vn(t,n,r,i,a,o){if(c(n)&&n.kind===`device`){let n=await Nn(t,o);if(!n.supported){let t=n.reason===`unsupported`?jn:Mn;throw new e(n.reason===`unsupported`?`UNSUPPORTED_OPERATION`:`COMMAND_FAILED`,t.message,{backend:`ios-device`,hint:t.hint,stderr:n.stderr})}}return o?.throwIfAborted(),await t.processes.start({command:{kind:`host`,request:r},output:i,...a?{markerPath:a}:{}})}async function Hn(e,t,n,r){return l(t)?{executable:`log`,args:[`stream`,`--style`,`compact`,`--predicate`,Fn(n)],allowFailure:!0}:t.kind===`device`?{executable:`xcrun`,args:Ln(t.id,n),allowFailure:!0}:{executable:`xcrun`,args:In(t,{appBundleId:n,executableName:await Un(e,t,n,r)}),allowFailure:!0}}async function Un(e,t,n,r){let i=await e.appleTools.run({tool:`simctl`,args:y(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`,`-`,b.join(a,`Info.plist`)],allowFailure:!0,timeoutMs:4e3},r);return o.exitCode===0&&o.stdout.trim()||void 0}function Wn(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 it({inspect:()=>({backend:r,state:o,startedAt:a}),finish:async()=>s??=(async()=>(await Gn([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 Gn(e){let t=[];for(let n of e)try{await n()}catch(e){t.push(e)}return t}const D=m(`apple`),Kn=Object.freeze({available:!0});function qn(t){return Object.freeze({owner:D,ownsDevice:e=>e.platform===`apple`,inspectFacts:async e=>Yn(e),bind:async n=>{if(n.intent.kind===`exact-owner`&&!ee(n.intent.owner,D))throw new e(`UNSUPPORTED_OPERATION`,`Apple app-log owner identity does not match`);return Jn(t,n.device,n.scope.signal)},shutdown:async()=>void 0})}function Jn(t,n,r){if(n.platform!==`apple`)throw new e(`UNSUPPORTED_PLATFORM`,`Apple app-log owner cannot bind ${n.platform}`);let i=Ze({codec:Cn,reattach:async(e,r)=>e.backend!==E(n)||!Ye(t,r.sessionId,e)?{status:`unreattachable`,reason:`descriptor-invalid`,message:`Apple app-log descriptor does not match the bound device or owning session`}:await Xe(t,e.pidPath),cleanup:async(e,r)=>e.backend===E(n)&&Ye(t,r.sessionId,e)?await nt(t,e.pidPath):{status:`cleanup-pending`,reason:`ownership-fence-lost`,message:`Apple app-log descriptor does not match the bound device or owning session`}}),a=Object.freeze({appLogInspect:async()=>({backend:E(n)}),appLogDoctor:async({appBundleId:e})=>await Pn(t,n,e,r),appLogStart:async e=>await zn(t,n,e,D,r),...i});return Object.freeze({device:n,owner:D,facts:Yn(n),operations:a,[Symbol.asyncDispose]:async()=>void 0})}function Yn(e){if(e.appleOs===`watchos`)return Xn(e);let t=c(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?{available:!1,reason:`unsupported-device-backend`,hint:T}:Kn;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:Kn,appLogCleanup:Kn}})}function Xn(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 Zn(e,t,n,r){let i=E(t),a=await e.appLogs.readRecent(n.sessionId,n.maxScanLines),o=et(a.text,{...n,path:a.path,exists:a.exists,lineNumberOffset:a.skippedLines,backend:i}),s=[];if($n(t,n,o.dump)){let i=await er(e,t,n,a.path,r);i&&(o=Qn(s,o,i,n.maxEntries))}return rr(s,t,n),nr(s,o.dump),o.dump.entries.length===0&&s.push(ir(t)),Object.freeze({source:`app-log`,backend:i,dump:o.dump,notes:Object.freeze(s)})}function Qn(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).`),rt(n.scan,t,r))}function $n(e,t,n){return c(e)&&e.kind===`simulator`&&!!t.appBundleId&&n.entries.length===0}async function er(e,t,n,r,i){let a=n.appLogSnapshot?.startedAt,o=y(t,[`spawn`,t.id,`log`,`show`,`--style`,`compact`,`--info`,`--predicate`,tr(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:et(`${c.join(`
|
|
3
|
+
`)}\n`,{...n,path:`${r} (simctl log show recovery)`,exists:!0,backend:`ios-simulator`}),lineCount:c.length}}function tr(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 nr(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 rr(e,t,n){n.appLogSnapshot?n.appLogSnapshot.state!==`active`&&e.length===0&&e.push(c(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 ir(e){return c(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.`:c(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 ar(e){let{host:t,snapshot:n,targetLabel:i,recorderWarning:a,nativePathDisposition:o}=e,s=n.invalidatedReason?{recorder:`lost`,why:`owner-session-lost`}:e.stopObservation;if(n.invalidatedReason&&!n.showTouches)throw Error(`recording invalidated: ${n.invalidatedReason}`);let c;try{c=await t.screenRecording.finalize.complete({outputPath:n.outPath,showTouches:!n.invalidatedReason&&n.showTouches,gestureEvents:n.gestureEvents,exportQuality:n.exportQuality??`medium`,targetLabel:i})}catch(e){throw r(e,`COMMAND_FAILED`)}let l=[...c.warning?[c.warning]:[],...a?[a]:[]];return ot(n,{...c,...l.length>0?{warning:l.join(` `)}:{},...n.invalidatedReason?{overlayWarning:`overlay unavailable: ${n.invalidatedReason}`}:{}},{stopObservation:s,...o===void 0?{}:{nativePathDisposition:o}})}async function or(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 sr(()=>t.screenRecording.finalize.complete({outputPath:a,showTouches:s===void 0&&n.showTouches,gestureEvents:n.gestureEvents,exportQuality:n.exportQuality??`medium`,targetLabel:r}))}catch(e){throw await t.screenRecording.outputs.remove(a),e}return{...c,...s===void 0?{}:{overlayWarning:`overlay unavailable: ${s}`},nativePathDisposition:await t.screenRecording.outputs.remove(o)===`removed`?`retired`:`retirable`}}async function sr(e){try{return await e()}catch(e){throw r(e,`COMMAND_FAILED`)}}const cr=[`outPath`,`startedAt`,`clientOutPath`,...dt],lr=Object.freeze({resourceKind:mt,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=>xr(e)});function ur(e){let{device:t,owner:n,input:r,descriptor:i}=e;return Ke({resourceKind:mt,sessionId:r.sessionId,device:o(t),owner:n,fence:r.fence,lifecycle:`open`,descriptor:Ge(lr,i)})}function dr(e){let t={};for(let n of cr)e[n]!==void 0&&Object.assign(t,{[n]:e[n]});return t}async function fr(e,t,n,r){let i=lr.decode(n);return i.status!==`decoded`||!jr(t,i.descriptor)?{status:`cleanup-pending`,reason:`manual-recovery-required`}:i.descriptor.backend===`simctl`?await pr(e,i.descriptor.processes,r):await hr(e,t,i.descriptor)}async function pr(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(mr(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(mr(n)),i.every(e=>e===`already-missing`)?{status:`already-missing`}:{status:`cleaned`})}function mr(e){return{kind:`session`,sessionId:e}}async function hr(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 gr(e){let{host:t,device:n,envelope:r}=e,i=lr.decode(r.descriptor.body);return i.status===`decoded`?jr(n,i.descriptor)?i.descriptor.backend===`simctl`?await _r(e,i.descriptor):await yr(t,n,i.descriptor):O(`descriptor-invalid`,`Apple screen-recording descriptor does not match the bound device.`):O(`descriptor-invalid`,i.message)}async function _r(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 O(`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=vr(lt(e.envelope.metadata),t.outputPath);return r===void 0||i!==void 0&&!await br(e.host,i)?{status:`missing`}:{status:`restore-export`,recording:r,nativePath:t.outputPath,cleanup:async()=>await pr(e.host,t.processes,e.envelope.sessionId)}}function vr(e,t){if(e.finalization===void 0)return e.collectedPath??t}async function yr(e,t,n){let r=await e.screenRecording.apple.inspectRunner(t,n.runnerSessionId,n.runnerAuthority);return r===`missing`?{status:`missing`}:O(`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 br(e,t){try{return await e.screenRecording.finalize.sniff({outputPath:t}),!0}catch{return!1}}function O(e,t){return{status:`unreattachable`,reason:e,message:t}}function xr(e){return typeof e.outputPath!=`string`||e.outputPath.length===0?A():e.backend===`simctl`?Sr(e,e.outputPath):e.backend===`runner`?Tr(e,e.outputPath):A()}function Sr(e,t){let n=Mr(e.processes),r=Cr(e.recording);return!n||r===`invalid`?A():{status:`decoded`,descriptor:Object.freeze({backend:`simctl`,outputPath:t,processes:n,...r===void 0?{}:{recording:r}})}}function Cr(e){if(e!==void 0)return i(e)&&wr(e)?Object.freeze(e):`invalid`}function wr(e){return k(e.outPath)&&Dr(e.startedAt)&&Er(e.clientOutPath)&&ct(e)}function Tr(e,t){return!k(e.appBundleId)||!k(e.runnerSessionId)||!Or(e.runnerAuthority)||!kr(e.remotePath)?A():{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 k(e){return typeof e==`string`&&e.length>0}function Er(e){return e===void 0||k(e)}function Dr(e){return typeof e==`number`&&Number.isFinite(e)}function Or(e){return e===`local-lease`||e===`scoped-provider`}function kr(e){return e===void 0||Ar(e)}function Ar(e){return typeof e==`string`&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(e)}function jr(e,t){return e.kind===`simulator`?t.backend===`simctl`:t.backend===`runner`?e.appleOs===`macos`?t.remotePath===void 0:c(e)?t.remotePath!==void 0&&Ar(t.remotePath):t.remotePath===void 0:!1}function Mr(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 A(){return{status:`invalid`,message:`Invalid Apple screen-recording descriptor`}}async function Nr(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 Pr=`iOS recording`,Fr=`simctl recordVideo`;function Ir(e){return e.appleOs===`watchos`?Xr(`unsupported-platform-leaf`,`watchOS recording is not supported.`):c(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?Xr(`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 Lr(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await Rr({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async e=>{let r=await gr({host:t,device:n,envelope:e.envelope});return r.status===`restore-export`?{status:`active`,handle:Br({host:t,restored:r})}:r},screenRecordingCleanup:async e=>await fr(t,n,e.envelope.descriptor.body,e.envelope.sessionId)})}async function Rr(e){return e.signal.throwIfAborted(),e.device.kind===`simulator`?await zr(e):await Hr(e)}async function zr(e){let{host:t,device:n,owner:r,input:i,signal:a}=e;await Nr(n,i,t.screenRecording.apple.isRunnerBundleId);let o=i.activeSessionApp?await t.screenRecording.apple.captureClockAnchor(n,i.activeSessionApp.bundleId,a):void 0,s=Tt(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 j(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 j(c).catch(()=>{}),e}let u,d,f=async()=>{await c.terminate();let e=await c.wait;return d=e,u=Wr(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=Yr(i,Fr,{},o);return Jr({device:n,owner:r,input:i,descriptor:{backend:`simctl`,outputPath:s,processes:l,recording:dr(p)},snapshot:p,finish:(e,n)=>pt({snapshot:e,progress:n,steps:{stop:f,collect:async e=>{try{await Vr(t,s,e)}catch(e){throw Gr(e,u,d)}},finalize:async({collectedPath:n,exportPath:r})=>{try{return await or({host:t,snapshot:e,targetLabel:Pr,collectedPath:n,exportPath:r,nativePath:s})}catch(e){throw Gr(e,u,d)}},discard:async e=>{await t.screenRecording.outputs.remove(e)}}}),cleanup:async()=>{let e=await qr(c);return(e.status===`cleaned`||e.status===`already-missing`)&&t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId}),e}})}function Br(e){let{host:t,restored:{recording:n,nativePath:r,cleanup:i}}=e,a=Object.freeze({...n,backend:Fr,gestureEvents:[]});return at(a,{finish:(e,i)=>pt({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 Vr(t,r,e)},finalize:async({collectedPath:i,exportPath:a})=>await or({host:t,snapshot:e,targetLabel:Pr,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 Vr(e,t,n){await e.screenRecording.outputs.copy({from:t,to:n}),await e.screenRecording.finalize.sniff({outputPath:n})}async function Hr(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??=Ur(()=>t.screenRecording.apple.runRunner(n,{kind:`stop`,appBundleId:o,...c}).then(()=>void 0)).catch(e=>{throw l=void 0,e}),l);if(!Kr(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 Jr({device:n,owner:r,input:i,descriptor:{backend:`runner`,outputPath:i.outputPath,appBundleId:o,...c,...s.remotePath===void 0?{}:{remotePath:s.remotePath}},snapshot:Yr(i,`runner AVAssetWriter`,s),finish:async e=>(await u(),s.remotePath!==void 0&&await t.screenRecording.apple.retrieveRunnerRecording(n,s.remotePath,e.outPath),await ar({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 Ur(e){try{return await e()}catch(e){throw r(e,`COMMAND_FAILED`)}}function Wr(e){if(e.exitCode!==0)return e.signal?`simctl recordVideo was killed by ${e.signal}`:`simctl recordVideo exited with code ${e.exitCode}`}function Gr(t,n,i){let a=r(t,`COMMAND_FAILED`);return n===void 0||i===void 0||a.details?.reason!==`recording-output-unplayable`?t:new e(a.code,`${a.message}; ${n}`,v(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 Kr(e,t){return e.appleOs===`macos`||!c(e)?t===void 0:t!==void 0&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(t)}async function j(e){return await e.terminate(),await e.wait}async function qr(e){try{return await j(e),{status:`cleaned`}}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`Apple simulator cleanup failed`}}}function Jr(e){let{device:t,owner:n,input:r,descriptor:i,snapshot:a,finish:o,cleanup:s}=e,c=at(a,{finish:o,forceCleanup:s});return Object.freeze({pendingHandle:new qe(c),envelope:ur({device:t,owner:n,input:r,descriptor:i})})}function Yr(e,t,n={},r){let i=Date.now();return Object.freeze({backend:t,outPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutPath:e.clientOutputPath},startedAt:i,scope:e.scope,showTouches:e.showTouches,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},...e.exportQuality===void 0?{}:{exportQuality:e.exportQuality},gestureEvents:[],...r===void 0?{}:{gestureClockOriginAtMs:r.wallClockAtMs,gestureClockOriginUptimeMs:r.uptimeMs},...n.recorderStartUptimeMs===void 0?{}:{gestureClockOriginAtMs:i,gestureClockOriginUptimeMs:n.recorderStartUptimeMs,runnerStartedAtUptimeMs:n.recorderStartUptimeMs},...n.runnerSessionId===void 0?{}:{runnerSessionId:n.runnerSessionId}})}function Xr(e,t){return Object.freeze({available:!1,reason:e,hint:t})}const Zr=15e3;async function M(e,t,n,r={}){return n.throwIfAborted(),await Dt(t)||l(t)?{...t,booted:!0}:t.kind===`device`?(await e.deviceReadiness.applePhysical.ensureConnected(t,n),{...t,booted:!0}):t.kind===`simulator`?((await Qr(e,t)?`Booted`:await ni(e,t,n))!==`Booted`&&(r.onColdBootStart?.(),e.deviceReadiness.appleAutomation.keepHot(t),await $r(e,t,n,r.deadlineAtMs),await ri(e,n)),e.deviceReadiness.appleAutomation.keepHot(t),e.deviceReadiness.appleAutomation.markBooted(t),{...t,booted:!0}):{...t,booted:!0}}async function Qr(e,t){try{return await e.deviceReadiness.appleAutomation.wasRecentlyObservedBooted(t)}catch{return!1}}async function $r(e,t,n,r=Date.now()+12e4){let i=!1;try{i=await ei(e,t,n,r),await ti(e,t,n,r)}catch(a){throw i&&n.aborted&&ii(e,t),n.throwIfAborted(),Date.now()>=r?P(t,a):a}}async function ei(t,n,r,i){let a=await t.appleTools.run({tool:`simctl`,args:y(n,[`boot`,n.id]),allowFailure:!0,timeoutMs:N(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 e(`COMMAND_FAILED`,`simctl boot failed`,{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode});return!s}async function ti(t,n,r,i){de({type:`command`,status:`progress`,message:`Waiting for the Simulator to finish booting...`});let a=await t.appleTools.run({tool:`simctl`,args:y(n,[`bootstatus`,n.id,`-b`]),allowFailure:!0,timeoutMs:N(i,n)},r);if(a.exitCode!==0)throw new e(`COMMAND_FAILED`,`simctl bootstatus failed`,{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode});if(await Jt(t.appleTools,n,r,Math.min(Zr,N(i,n)))!==`Booted`)throw new e(`COMMAND_FAILED`,`Simulator is still booting`,{deviceId:n.id});if(Date.now()>=i)throw P(n)}function N(e,t){let n=e-Date.now();if(n<=0)throw P(t);return n}function P(t,n){return new e(`COMMAND_FAILED`,`Simulator did not finish booting within the startup budget`,{reason:`boot_timeout`,deviceId:t.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 ni(e,t,n){return await Jt(e.appleTools,t,n,Zr)}async function ri(e,t){await e.commands.run({executable:`open`,args:[`-a`,`Simulator`],allowFailure:!0,timeoutMs:1e4},t)}function ii(e,t){e.appleTools.run({tool:`simctl`,args:y(t,[`shutdown`,t.id]),allowFailure:!0}).catch(()=>{})}const ai=Object.freeze({resolveOpenTarget:`simulator`,prepareApplicationOpen:`simulator`,openApplication:`simulator`,applyRuntimeHints:`simulator`,clearRuntimeHints:`simulator`,closeApplication:`simulator`,finalizeApplicationClose:`simulator`,prepareAppleRunner:`runner`,configureProviderPortReverse:`simulator`,ensureReady:`simulator`,bootTarget:`simulator`,bootTargetHeadless:`simulator`,shutdownTarget:`simulator`,listApps:`simulator`,deployApp:`simulator`,materializeAppSource:`simulator`,deployMaterializedApp:`simulator`,sendPushNotification:`simulator`,appState:`simulator`,appLogStart:`simulator`,appLogInspect:`simulator`,appLogDoctor:`simulator`,appLogReattach:`simulator`,appLogCleanup:`simulator`,networkDump:`simulator`,audioProbeStart:`simulator`,audioProbeQuery:`simulator`,audioProbeReattach:`simulator`,audioProbeCleanup:`simulator`,readClipboard:`simulator`,writeClipboard:`simulator`,setSetting:`simulator`,readSetting:`simulator`,setFoldPose:`simulator`,captureSnapshot:`simulator`,captureSnapshotWithoutActiveApp:`simulator`,captureSnapshotWithCustomActions:`runner`,captureScreenshot:`simulator`,findText:`runner`,readTextAtPoint:`runner`,tapPoint:`runner`,tapRef:`runner`,tapElementSelector:`runner`,fillPoint:`runner`,fillRef:`runner`,longPressPoint:`runner`,hoverPoint:`runner`,hoverRef:`runner`,focusPoint:`runner`,typeText:`runner`,scrollDirection:`runner`,performGesturePlan:`runner`,performMultiTouchGesturePlan:`runner`,performTargetAuthoredDrag:`runner`,performDirectionalFlingPlan:`runner`,gestureViewport:`runner`,setViewport:`runner`,back:`runner`,home:`runner`,setOrientation:`runner`,appSwitcher:`runner`,actionButton:`runner`,tvRemote:`runner`,keyboardDismiss:`runner`,keyboardEnter:`runner`,keyboardStatus:`runner`,triggerAppEvent:`runner`,readAlert:`runner`,awaitAlert:`runner`,acceptAlert:`runner`,dismissAlert:`runner`,perfFrames:`runner`,perfMemorySample:`runner`,perfMemorySnapshot:`runner`,perfNativeCaptureStart:`runner`,perfNativeCaptureReattach:`runner`,perfNativeCaptureCleanup:`runner`,perfProfileReport:`runner`,screenRecordingStart:`runner`,screenRecordingReattach:`runner`,screenRecordingCleanup:`runner`});function oi(e){return e===void 0?`possible`:e.some(e=>ai[e]===`runner`)?`required`:`none`}const si=3e3,ci=`simulator-target-discovery-pending`;function li(){let e=new Map,t=new Map,n=Yt({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 Zt(c.pid,{signal:a,timeoutMs:si});if(a.throwIfAborted(),e===c.processStartTime)return c}return e.delete(s),await n.value(s,{start:async()=>{let n=await fi(r,i,t);return e.set(s,n),n},wait:(e,t)=>an({waitMs:e,signal:a,stop:t,cancelled:()=>ui(a)}),pending:()=>I(ci,r,i)})}}function ui(e){return t({readinessPhase:`target-discovery`},e.reason)}function di(t){return t instanceof e&&t.details?.reason===ci}async function fi(e,t,n){let r=Date.now()+15e3,[i,a]=await Promise.allSettled([zt(e,[`spawn`,e.id,`launchctl`,`list`],{allowFailure:!0,timeoutMs:F(r)}),pi(e,n,r)]);if(i.status===`rejected`)throw i.reason;if(a.status===`rejected`)throw a.reason;let o=i.value,s=a.value;if(o.exitCode!==0)throw I(`simulator-target-probe-failed`,e,t);let c=mi(o.stdout,t);if(!c)throw I(`simulator-target-unavailable`,e,t);let l=await Zt(c.pid,{timeoutMs:Math.min(si,F(r))});if(!l)throw I(`simulator-target-identity-unavailable`,e,t);return Object.freeze({simulator:Vt(e),runtime:s,pid:c.pid,generation:`${c.pid}:${c.label}:${l}`,targetId:`${e.id}:${t}`,processStartTime:l})}async function pi(e,t,n){let r=t.get(e.id);if(r)return await r;let i=zt(e,[`list`,`devices`,`-j`],{allowFailure:!0,timeoutMs:F(n)}).then(t=>{if(t.exitCode!==0)throw I(`simulator-runtime-probe-failed`,e,``);let n=Object.entries(Bt(t.stdout)).find(([,t])=>t.some(t=>t.udid===e.id))?.[0];if(!n)throw I(`simulator-runtime-unavailable`,e,``);return n});t.set(e.id,i);try{return await i}catch(n){throw t.delete(e.id),n}}function mi(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 F(e){return Math.max(1,e-Date.now())}function I(t,n,r){return new e(`COMMAND_FAILED`,`Unable to resolve the running iOS Simulator app (${t}).`,{reason:t,deviceId:n.id,appBundleId:r})}const hi=new Map([[`application-element-missing`,5e3],[`application-server-unavailable`,5e3],[`foreground-owner-unverified`,1e3],[`foreground-owner-changed`,1e3]]);function L(e){return e.platform===`apple`&&e.appleOs===`ios`&&e.kind===`simulator`}function gi(e){let t=oe(ce({depth:1,interactiveOnly:!0}));return Object.freeze({awaitObservable:async(n,r,i)=>{if(!L(n))return`not-eligible`;let a;for(;;){let o=await _i(e.resolveTarget,n,r,i);if(!o)return`unobservable`;if(e.isBridgeDisabled(o))return _({level:`debug`,phase:`ios_launch_observation_skipped`,data:{reason:`circuit-disabled`,deviceId:n.id,generation:o.generation}}),`unobservable`;let s=await e.source.acquire({target:o,hint:t,signal:i});if(s.stage!==`failed`)return`observable`;i.throwIfAborted();let c=hi.get(s.failure.code);if(c===void 0)return`unobservable`;let l=e.clock.now();if(a=Math.min(a??1/0,l+c),l>=a)return`unobservable`;await e.clock.sleep(Math.min(150,a-l),i)}}})}async function _i(e,t,n,r){for(;;)try{return await e(t,n,r)}catch(e){if(r.throwIfAborted(),!di(e))return}}function vi(e,t,n){let r=n&&L(e),i=r?oi(t.execution.plannedOperations):void 0,a=c(e)&&t.surface===`app`&&t.positionals.length>0&&!!t.appBundleId&&i!==`none`;return{...i?{runnerDemand:i}:{},shouldPrewarmRunner:a,awaitPrewarmAfterOpen:t.relaunch&&!r}}function yi(e,t,n,r){r.runnerDemand===`none`&&e.appleApplications.releaseSpeculativeRunner(t.device,n.execution).catch(()=>{})}async function bi(e,t,n,r,i,a){let o=Date.now();r&&L(t.device)&&i&&n.appBundleId&&(a.postOpenObservation=await i.awaitObservable(t.device,n.appBundleId,t.signal)),r&&a.postOpenObservation!==`observable`&&await e.clock.sleep(300,t.signal),a.postOpenSettleDurationMs=Math.max(0,Date.now()-o)}function xi(e){let t=kt({device:e.device,signal:e.signal,resolveInteractor:e.host.localInteractors.resolve});return Object.freeze({resolveOpenTarget:async t=>await e.host.appleApplications.resolveOpenTarget(e.device,t),prepareApplicationOpen:async t=>{await M(e.host,e.device,e.signal,{deadlineAtMs:t.execution.startupDeadlineAtMs,onColdBootStart:t.prewarmRunnerOnColdBoot?()=>{e.host.appleApplications.prewarmRunnerCache(e.device,t.execution,e.signal).catch(()=>{})}:void 0})},openApplication:async n=>await Si(e.host,t,n,e.observation),applyRuntimeHints:async t=>await e.host.appleApplications.applyRuntimeHints(e.device,t),clearRuntimeHints:async t=>await e.host.appleApplications.clearRuntimeHints(e.device,t),closeApplication:async n=>await Mi(e.host,t,n),finalizeApplicationClose:async t=>await Ni(e.host,e.device,e.signal,t),prepareAppleRunner:async t=>await Pi(e.host,e.device,e.signal,t),configureProviderPortReverse:zi})}async function Si(e,t,n,r){let i={},a=R(t.device),o=Fi(e,t,n,i),s=vi(t.device,n,a);s.runnerDemand&&(i.runnerDemand=s.runnerDemand),yi(e,t,n,s);let{shouldPrewarmRunner:c}=s,l=ji(t.device,n,a);a&&c&&!n.prewarmRunnerBeforeOpen&&o.schedule();try{await Ci(e,t,n,a,l,i),await wi(n,i),await Ti(o,c,n.prewarmRunnerBeforeOpen);let u=o.wasAwaited();return await Ei(t,n,a,i),await Oi(o,c,s.awaitPrewarmAfterOpen),await ki(e,t,n,a,u,l),await bi(e,t,n,a,r,i),{appBundleId:n.appBundleId,timing:i}}catch(n){throw l&&await e.appleApplications.stopRunnerSession(t.device.id).catch(()=>{}),n}}async function Ci(e,t,n,r,i,a){if(!Ai(n,r)||!n.target)return;let o=Date.now();u(t.device.platform)&&!r&&!i&&await e.appleApplications.stopRunnerSession(t.device.id),await Ot({device:t.device,interactor:await t.resolveInteractor(n.execution,n.appBundleId),positionals:[n.appBundleId??n.target]}),r&&await e.clock.sleep(300,t.signal),a.relaunchCloseDurationMs=z(o)}async function wi(t,n){if(!pe(t.runtimeHints))return;if(!t.applyRuntimeHints)throw new e(`COMMAND_FAILED`,`Runtime hint operation was not admitted for this open.`,{reason:`runtime-hints-operation-missing`});let r=Date.now();await t.applyRuntimeHints({appId:t.appBundleId,values:t.runtimeHints}),n.runtimeHintsDurationMs=z(r)}async function Ti(e,t,n){!t||!n||(e.schedule(!0),await e.wait())}async function Ei(e,t,n,r){let i=Li(t,n),a=Date.now();await At({device:e.device,interactor:await e.resolveInteractor(t.execution,t.appBundleId),positionals:i.positionals,appBundleId:t.appBundleId,execution:t.execution,...n&&t.relaunch&&!t.execution.clearAppState?{terminateRunningApp:!0}:{}}),r.openDispatchDurationMs=z(a),await Di(e,t,i.followUpUrl,r)}async function Di(e,t,n,r){if(!n){r.launchUrlDurationMs=0;return}let i={...t.execution,clearAppState:void 0,launchConsole:void 0,launchArgs:void 0},a=Date.now();await At({device:e.device,interactor:await e.resolveInteractor(i,t.appBundleId),positionals:[n],appBundleId:t.appBundleId,execution:i}),r.launchUrlDurationMs=z(a)}async function Oi(e,t,n){t&&!e.wasScheduled()&&e.schedule(),n?await e.wait():e.recordUnawaited()}async function ki(e,t,n,r,i,a){!c(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 Ai(e,t){return!!(e.relaunch&&e.target)&&!(t&&!e.execution.clearAppState)}function ji(e,t,n){return e.kind===`device`&&e.appleOs===`ios`&&Ai(t,n)}async function Mi(e,t,n){n.ensureReady&&await M(e,t.device,t.signal),u(t.device.platform)&&!R(t.device)&&await e.appleApplications.stopRunnerSession(t.device.id),await Ot({device:t.device,interactor:await t.resolveInteractor(n.execution,n.appBundleId),positionals:n.positionals}),R(t.device)&&await e.clock.sleep(300,t.signal)}async function Ni(e,t,n,r){r.daemonShutdown||await e.appleApplications.releaseRunnerOnClose(t.id,{retain:r.retainRunner}),await e.appleApplications.dismissCloseAlerts(t,r).catch(()=>{});let i=r.shutdownTarget&&R(t)?await e.deviceShutdown.apple.shutdownTarget(t,n):void 0;return i===void 0?{}:{shutdown:i}}async function Pi(e,t,n,r){let i=Date.now()+r.timeoutMs;await M(e,t,n,{deadlineAtMs:i});let a=Math.max(1,i-Date.now());return await e.appleApplications.prepareRunner(t,{...r,timeoutMs:a},n)}function Fi(e,t,n,r){let i,a=!1,o=Ii(t.device,n)?{healthCheck:!1}:void 0;return{schedule:(a=!1)=>{i||=(r.runnerPrewarmKind=`session`,r.runnerPrewarmScheduled=!0,o?e.appleApplications.prewarmRunnerSession(t.device,n.execution,t.signal,a,o):e.appleApplications.prewarmRunnerSession(t.device,n.execution,t.signal,a))},wait:async()=>{if(!i||a)return;a=!0;let e=Date.now();await i,r.runnerPrewarmWaited=!0,r.runnerPrewarmDurationMs=z(e)},wasAwaited:()=>a,wasScheduled:()=>i!==void 0,recordUnawaited:()=>{i&&!a&&(r.runnerPrewarmWaited=!1)}}}function Ii(e,t){return e.kind===`device`&&e.appleOs===`ios`&&!t.hasExistingSession&&!t.relaunch&&!t.prewarmRunnerBeforeOpen}function Li(e,t){let n=e.runtimeLaunchUrl?.trim(),r=e.positionals.length===1?e.positionals[0]?.trim():void 0;return!n||!r||a(r)?{positionals:e.positionals}:t&&!Ri(e)?{positionals:[r,n]}:{positionals:e.positionals,followUpUrl:n}}function Ri(e){return e.execution.clearAppState===!0||!!e.execution.launchConsole?.trim()||!!e.execution.launchArgs?.length}function R(e){return c(e)&&e.kind===`simulator`}function z(e){return Math.max(0,Date.now()-e)}async function zi(){throw new e(`UNSUPPORTED_OPERATION`,`This lifecycle operation is unavailable for Apple.`)}const Bi=Object.freeze({available:!0}),Vi=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.`}),Hi=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Push notifications are supported on Apple simulators only.`}),Ui=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Wi=Object.freeze({available:!1,reason:`unsupported-device-kind`});function Gi(e){let t=Qi(e);return Object.freeze({deployApp:t,materializeAppSource:t,deployMaterializedApp:t,sendPushNotification:$i(e)})}function Ki(e){let{host:t,device:n,signal:r}=e,i=Gi(n);return Object.freeze({...i.deployApp.available?{deployApp:async e=>await qi(t,n,e,r),materializeAppSource:async e=>await t.appleDeployment.prepareArtifact(e,{signal:r}),deployMaterializedApp:async e=>await Ji(t,n,e,r)}:{},...i.sendPushNotification.available?{sendPushNotification:async e=>(await Zi(t,n,e,r),{})}:{}})}async function qi(e,t,n,r){if(n.replaceExisting)return await e.appleDeployment.withInvalidatedAppResolutionCache(t,async()=>{let i=await e.appleDeployment.resolveAppBundleId(t,n.app);await Xi(e,t,i,r);let a=await e.appleDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{appIdentifierHint:n.app,signal:r});try{return await Yi(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 Ji(e,t,{artifact:i},r)}finally{await i.cleanup()}}async function Ji(e,t,n,r){return await Yi(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 Yi(e,t,n,r){await M(e,t,r),await B(e,t.kind===`simulator`?{tool:`simctl`,args:y(t,[`install`,t.id,n])}:{tool:`devicectl`,args:[`device`,`install`,`app`,`--device`,t.id,n],timeoutMs:jt},r,`Apple app install failed`)}async function Xi(e,t,n,r){await M(e,t,r),await B(e,t.kind===`simulator`?{tool:`simctl`,args:y(t,[`uninstall`,t.id,n])}:{tool:`devicectl`,args:[`device`,`uninstall`,`app`,`--device`,t.id,n]},r,`Apple app uninstall failed for ${n}`,{tolerate:e=>Lt(`${e.stdout}\n${e.stderr}`.toLowerCase())})}async function Zi(t,n,r,i){if(n.kind!==`simulator`)throw new e(`UNSUPPORTED_OPERATION`,`Apple push notifications require a simulator`);await M(t,n,i);let a=await t.temporaryFiles.create({prefix:`agent-device-ios-push-`,suffix:`.apns`});try{await a.writeText(`${JSON.stringify(r.payload)}\n`),await B(t,{tool:`simctl`,args:y(n,[`push`,n.id,r.appId,a.path])},i,`Apple push notification failed`)}finally{await a[Symbol.asyncDispose]()}}async function B(e,t,n,r,i){let a=await e.appleTools.run({...t,allowFailure:!0},n);return i?.tolerate?.(a)?a:ie(a,r,e=>({cmd:`xcrun`,args:[t.tool,...t.args],...t.tool===`devicectl`?{hint:It(e.stdout,e.stderr)??`Ensure the iOS device is unlocked, trusted, and available in Xcode > Devices, then retry.`}:{}}))}function Qi(e){return ea(e)?e.kind!==`simulator`&&e.kind!==`device`?Wi:e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?Vi:Bi:Ui}function $i(e){return ea(e)?e.kind===`simulator`?Bi:Hi:Ui}function ea(e){return c(e)&&e.appleOs!==`watchos`}const V=Object.freeze({available:!0}),ta=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`back is supported on Apple simulators and physical devices.`}),na=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function ra(e){return e.kind!==`simulator`&&e.kind!==`device`?ta:p(e)===`watchos`?na:V}const ia=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`home is supported on Apple simulators and physical devices.`}),aa=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),oa=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`app-switcher is supported on Apple simulators and physical devices.`});function sa(e,t){if(e.kind!==`simulator`&&e.kind!==`device`)return t;let n=p(e);return n===`macos`||n===`watchos`?aa:V}function H(e){if(e.kind!==`simulator`&&e.kind!==`device`)return!1;let t=p(e);return t!==`tvos`&&t!==`macos`&&t!==`watchos`}const ca=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`orientation is supported on Apple simulators and physical devices.`}),la=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function ua(e){return e.kind!==`simulator`&&e.kind!==`device`?ca:H(e)?V:la}const da=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`tv-remote is supported only on tvOS devices.`});function fa(e){return(e.kind===`simulator`||e.kind===`device`)&&s(e)?V:da}const U=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),pa=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 ma(e){return H(e)?pa:U}function ha(e){return H(e)?V:U}function ga(e){return H(e)?V:U}const _a=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`No Apple leaf carries this system button.`}),va=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`action-button is supported on iPhone and iPad simulators and physical devices.`}),ya=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 ba(e){return e.kind!==`simulator`&&e.kind!==`device`?va:d(e)?V:ya}function xa(e){return Object.freeze({...Re({back:ra(e)}),...je({unsupported:_a,home:sa(e,ia),appSwitcher:sa(e,oa),actionButton:ba(e)}),..._e({orientation:ua(e)}),...ze({tvRemote:fa(e)}),...Le({unsupported:U,status:ma(e),dismiss:ha(e),enter:ga(e)})})}function Sa(e){let{host:t,device:n,signal:r}=e;return vt({device:n,signal:r,resolveInteractor:t.localInteractors.resolve,facts:xa(n)})}const W=Object.freeze({available:!0}),Ca=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`clipboard is supported on Apple simulators and the macOS host.`}),wa=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`settings is supported on Apple simulators and the macOS host.`}),Ta=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.`}),Ea=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:"Apple targets answer a settings read only on iPhone and iPad simulators, where `simctl ui` reports the value the device holds."}),Da=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.`}),G=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function Oa(e,t,n){if(e.kind!==`simulator`&&e.kind!==`device`)return t;let r=p(e);return r===`watchos`?G:e.kind===`simulator`||r===`macos`?W:n}function ka(e){return Oa(e,Ca,Da)}const Aa=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`trigger-app-event is supported on Apple simulators and physical devices.`}),ja=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`alert is supported on Apple simulators and physical devices.`}),Ma=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`alert is supported on Apple simulators, the macOS host, and physical iOS devices.`});function Na(e){if(e.kind!==`simulator`&&e.kind!==`device`)return ja;let t=p(e);return t===`watchos`?G:e.kind===`simulator`||t===`ios`||t===`macos`?W:Ma}function Pa(e){return e.kind!==`simulator`&&e.kind!==`device`?Aa:p(e)===`watchos`?G:W}function Fa(e){let t=ka(e);return t.available?Da:t}function Ia(e){return e.kind!==`simulator`&&e.kind!==`device`?wa:p(e)===`watchos`?G:f(e)?W:Ea}function La(e){let t=ka(e),n=Na(e);return Object.freeze({...Me({unsupported:Fa(e),read:t,write:t}),...Pe({read:n,wait:n,accept:n,dismiss:n}),...Ie({triggerAppEvent:Pa(e)}),...Fe({setSetting:Oa(e,wa,Ta),readSetting:Ia(e)})})}function Ra(e){let{host:t,device:n,signal:r}=e;return vt({device:n,signal:r,resolveInteractor:t.localInteractors.resolve,facts:La(n)})}const za=/Angle:\s*(-?\d+(?:[.,]\d+)?)\s*°/g;async function Ba(t,n={}){let r=[`devicectl`,`device`,`motion`,`hinge-angle`,`--device`,t.id,`--session-timeout`,`1`,`--timeout`,`5`],i=await Ft(r,{allowFailure:!0,signal:n.signal,timeoutMs:Nt}),a=Va(i.stdout)??Va(i.stderr);if(a!==void 0)return a;throw new e(`COMMAND_FAILED`,`CoreDevice reported no hinge angle sample`,v(i,{cmd:`xcrun`,args:r,stdout:i.stdout,stderr:i.stderr,deviceId:t.id,hint:`This Xcode/CoreDevice toolchain does not stream 'devicectl device motion hinge-angle' for this device. Foldable poses can be verified only through that stream; update Xcode to a version that ships it.`}))}function Va(e){let t;for(let n of e.matchAll(za)){let e=Number.parseFloat(n[1].replace(`,`,`.`));Number.isFinite(e)&&(t=e)}return t}const Ha=`Fold.m`,Ua=3e4,Wa=Rt+Ua;async function Ga(e={}){let t=e.host??Ka(),n=rn(Wa,e.signal);try{let r=e.sourceRoot??b.join(t.projectRoot(),`apple`,`fold-helper`),i=await tn(t,r,[Ha],n),a=await Xt(t,n),o=e.cacheRoot??b.join(t.homeDirectory(),`.agent-device`,`fold-helper`);return await nn({host:t,deadline:n,lockDescription:`iOS Simulator fold helper cache`,cacheRoot:o,binaryFilename:`fold-helper`,keyInputs:{schemaVersion:1,sourceHash:i,toolchain:a,compileArgv:qa({sourceRoot:``,outputPath:``})},build:e=>Ja(t,n,r,e)})}catch(e){throw Ya(e)}}function Ka(){return{...Qt(),run:(e,t,n)=>Pt(e,t,n)}}function qa(e){return[`--sdk`,`iphonesimulator`,`clang`,`-mios-simulator-version-min=15.0`,`-fobjc-arc`,`-Wall`,`-Wextra`,`-framework`,`Foundation`,`-framework`,`IOKit`,b.join(e.sourceRoot,Ha),`-o`,e.outputPath]}async function Ja(e,t,n,r){let i=await $t({host:e,deadline:t,argv:qa({sourceRoot:n,outputPath:r}),budgetMs:Ua,label:`fold helper`});if(i.exitCode!==0||!e.exists(r))throw Xa(v(i))}function Ya(e){if(!(e instanceof en)||e.failureKind===`cancelled`)return e;let{bridgeFailure:t,bridgeFailureCode:n,...r}=e.details??{};return Xa({...r,cause:n},e)}function Xa(t,n){return new e(`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.`,...t,reason:`fold-helper-build-failed`},n)}async function Za(t,n,r){r?.throwIfAborted();let i=await Ga({signal:r});r?.throwIfAborted();let a=typeof n==`string`?0:n.at(-1).atMs,o=typeof n==`string`?n:JSON.stringify(n),s=await zt(t,[`spawn`,t.id,i.path,o],{signal:r,timeoutMs:a+1e4,kill:{signal:`SIGTERM`,graceMs:1e3},allowFailure:!0});if(s.exitCode!==0)throw new e(`COMMAND_FAILED`,`Unable to send the simulator hinge pose`,v(s,{reason:`fold-hid-dispatch-failed`,deviceId:t.id}))}async function Qa(e,t,n={}){n.signal?.throwIfAborted(),Gt(e,`fold`);let r=t,i=r.keyframes?.at(-1)?.angle,a=r.pose??g(i);$a(e,await Kt(e,{signal:n.signal})),await Za(e,r.keyframes??a,n.signal),_({level:`info`,phase:`apple_fold_pose_dispatched`,data:{deviceId:e.id,pose:a}});let o=await eo(e,a,n.signal,i),s=await lo(e,n.signal);return{pose:g(o),hingeAngleDegrees:o,...s?{screen:uo(s)}:{}}}function $a(t,n){if(n.unresolved)throw new e(`COMMAND_FAILED`,`CoreDevice reported no display table for this simulator`,{deviceId:t.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 e(`UNSUPPORTED_OPERATION`,`${t.name} is not a foldable simulator: fold requires more than one integrated panel`,{deviceId:t.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 eo(e,t,n,r){let i,a;for(let o=1;o<=4;o+=1)if(n?.throwIfAborted(),a=i,i=await Ba(e,{signal:n}),to(i,a,t,r))return i;throw io(e,t,i,a,r)}function to(e,t,n,r){return r===void 0?g(e)===n?n!==`half-open`||t!==void 0&&ao(e,t):!1:no(e,t,r)}function no(e,t,n){return ro(e,n)?n===0||n===180||t!==void 0&&ro(t,n)&&Math.abs(e-t)<=.5:!1}function ro(e,t){return t===void 0||e!==void 0&&Math.abs(e-t)<=.5}function io(t,n,r,i,a){return ro(r,a)?a!==void 0&&r!==void 0?co(t,g(r),r,i):r!==void 0&&n===`half-open`&&g(r)===n?co(t,n,r,i):so(t,n,r):new e(`COMMAND_FAILED`,`The hinge did not reach the final keyframe angle`,{reason:`fold-angle-unverified`,targetAngleDegrees:a,hingeAngleDegrees:r,deviceId:t.id})}function ao(e,t){return g(e)===`half-open`&&g(t)===`half-open`&&Math.abs(e-t)<=.5}function oo(e,t,n){return{deviceId:e.id,requestedPose:t,observedPose:n===void 0?void 0:g(n),hingeAngleDegrees:n}}function so(t,n,r){return new e(`COMMAND_FAILED`,`${t.name} did not reach the ${n} pose: CoreDevice still reports a hinge angle of ${r}°`,{...oo(t,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 co(t,n,r,i){return new e(`COMMAND_FAILED`,`${t.name} was observed ${n} at ${r}° but did not settle: 4 hinge reads never held two consecutive angles within ${Mt}° of each other`,{...oo(t,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 lo(e,t){let n=await Kt(e,{signal:t});if(!(n.unresolved||n.ambiguous))return n.activeDisplay}function uo(e){return{display:e.name,coordinateSpace:ue,widthPt:Math.round(e.widthPx/e.pointScale),heightPt:Math.round(e.heightPx/e.pointScale)}}const fo=Object.freeze({available:!0}),po=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.`}),mo=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 ho(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 go(e){if(e.kind!==`simulator`)return po;let t=p(e);return t!==`ios`&&t!==`ipados`?mo:e.simulatorSetPath?ho(e.simulatorSetPath):fo}function _o(e){return le({fold:go(e)})}function vo(e){let{device:t,signal:n}=e;return h(_o(t).setFoldPose,()=>({setFoldPose:async e=>(n.throwIfAborted(),await Qa(t,e,{signal:n}))}))}function yo(e,t,n){let r=xe({device:t.device,signal:t.signal,resolveInteractor:e.localInteractors.resolve}),i=async i=>{if(l(t.device)&&ne(i.options?.surface)===`macos-helper`)return await e.snapshot.captureSurface(t.device,i.options,Ae(t.signal,i));if(!n)return await r.captureSnapshot(i);let a=Ae(t.signal,i);return await n.capture(t.device,i,a,async e=>await r.captureSnapshot(e))};return Object.freeze({captureSnapshot:i,captureSnapshotWithCustomActions:i,captureSnapshotWithoutActiveApp:i})}function bo(e,t){return Object.freeze({findText:async n=>{let r=await xo(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 xo(e,t,n){let r=n.options?.appBundleId;if(r===void 0||l(t.device)&&ne(n.options?.surface)===`macos-helper`)return;let i=n.signal?AbortSignal.any([t.signal,n.signal]):t.signal;if(i.throwIfAborted(),await So(e,t.device,n.execution))return{appBundleId:r,signal:i}}async function So(e,t,n){return!L(t)||await e.appleApplications.hasLiveRunnerSession(t,n??{})}function Co(){let e,t=!1,n=async()=>(e??=import(`./adapter.js`).then(({createSimulatorSnapshotSource:e})=>e()),await e);return{acquire:async e=>t?{stage:`failed`,failure:{kind:`unsupported`,code:`source-closed`}}:await(await n()).acquire(e),close:async()=>{t=!0,e&&await(await e).close()}}}function wo(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 To(n,r);return a!==`absent`&&a!==`unknown`&&t.set(n.id,{at:e(),host:a.host}),a}}async function To(e,t){let n=!1;for(let r of ht){let i=await Eo(r.processExecutable,t);if(i===`unknown`){n=!0;continue}for(let a of i){let i=await Do(a,e.id,t);if(i===`unknown`)n=!0;else if(i)return{kind:`present`,host:r}}}return n?`unknown`:`absent`}async function Eo(e,t){let n=await Oo(`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 Do(e,t,n){let r=await Oo(`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 Oo(e,t,n){try{let r=await Pt(e,t,{allowFailure:!0,timeoutMs:3e3,...n?{signal:n}:{}});return{exitCode:r.exitCode,stdout:r.stdout}}catch{return`unknown`}}const ko=`system-surface-presented`,Ao=`system-surface-host-lingering`,jo=`window-coordinate-space-unresolved`;function Mo(t,n={}){let r=n.source??Co(),i=n.resolveTarget??li(),a=n.systemSurfacePresent??wo(),o=new Set,s=new Map,c=e=>(qo(e,s,o),o.has(Jo(e))),l=gi({source:r,resolveTarget:i,clock:t.clock,isBridgeDisabled:c});return Object.freeze({awaitObservable:l.awaitObservable,shutdown:async()=>await r.close(),capture:async(n,s,l,u)=>{if(!Fo(n,s))return await zo(n,s,u);let d=await a(n,l);if(d===`unknown`)return await K(n.id,s,u,Vo(n.id,s),q(s),`system-surface-probe-unavailable`,[Ko()]);if(d!==`absent`)return await Ro(n,s,u,d.host.bundleId);let f;try{f=await No(t,i,n,s,l)}catch(e){return Po(l,e),J(`target-resolution-failed`,n,void 0,e),await K(n.id,s,u,Vo(n.id,s),q(s),`target-resolution-failed`,[Ko()])}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:oe(p),signal:l});if(m.stage===`failed`){if(m.failure.kind===`cancelled`)throw l.throwIfAborted(),new e(`COMMAND_FAILED`,`Simulator AX snapshot acquisition was cancelled.`,{reason:m.failure.code,...m.failure.details});let t=await Go(m.failure,f,n,s.options.appBundleId,l,i);return await Io(s,u,f,t,p,m.failure,o)}try{return await re(`ios.snapshot-source.present`,async()=>await t.snapshot.presentIosAcquisition(m,s.options),{producer:`simulator-ax-bridge`})}catch(e){return await Io(s,u,f,{lineage:f,residue:[]},p,{kind:`malformed-tree`,code:`presentation-invariant`},o,e)}}})}async function No(e,t,n,r,i){let a=r.options.appBundleId;for(;;)try{return await t(n,a,i)}catch(t){if(!di(t))throw t;let i={requestId:r.execution?.requestId};if(await e.appleApplications.hasLiveRunnerSession(n,i))throw t}}function Po(e,t){if(e.aborted)throw n(t)?t:e.reason}function Fo(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 Io(e,t,n,r,i,a,o,s){return Lo(a)&&o.add(Jo(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 Lo(e){return e.kind!==`preparing`&&e.code!==jo}async function K(e,t,n,r,i,a,o=[]){return Bo(e,await n(t),r,i,a,o)}async function Ro(e,t,n,r){let i=await n(t),a=i.systemSurface?ko:Ao;return i.systemSurface||J(a,e,void 0,void 0,{detectedHost:r}),Bo(e.id,i,Vo(e.id,t),q(t),a)}async function zo(e,t,n){let r=await n(t),i=r.systemSurface;return i?{...r,comparisonIdentity:Uo(Ho(e.id,i.bundleId),q(t),[])}:r}function Bo(e,t,n,r,i,a=[]){let o=t.systemSurface;return{...t,comparisonIdentity:Uo(o?Ho(e,o.bundleId):n,r,[...o?[]:a,{kind:`fallback-source`,producer:`apple-runner`}]),warnings:[...t.warnings??[],Wo(i,n,o!==void 0)]}}function Vo(e,t){return{targetId:`${e}:${t.options.appBundleId}`}}function Ho(e,t){return{targetId:`${e}:${t}`}}function Uo(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:se(t),residue:Object.freeze([...n])})}function Wo(e,t,n){return e===ko?`Simulator AX snapshot inapplicable (${e}); used XCTest to read the system surface presented over the app.`:e===Ao?`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===jo?`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 Go(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:[Ko()]}}}function Ko(){return{kind:`unknown-generation`,captureId:on()}}function q(e){return ce({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 qo(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 Jo(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=m(`apple`),X=Object.freeze({available:!0}),Z=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Yo=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`viewport resizes web targets only (--platform web). Apple screen geometry is fixed by the selected simulator or device type — open a different simulator to test another screen size.`}),Xo=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`the stateless audio page probe is a web-session operation; Apple targets use the host capture.`}),Zo=Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`perf requires an Apple simulator, macOS device, or CoreDevice-backed physical Apple device.`}),Qo=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`focus is supported on Apple simulators and physical devices.`}),$o=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple appstate is unavailable here: the runner reads the session app's XCUIApplication state on iOS-family simulators and physical devices only, and the Apple target answers no sessionless foreground probe. The per-command answer is the targetActivation disclosure, which a capture carries when its command had to re-activate the session app (#2682).`});function es(e){return!c(e)||e.appleOs===`watchos`?$o:e.kind===`simulator`||e.kind===`device`?X:$o}const ts=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Headless boot is supported only for local Android emulators.`}),ns=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS has no XCUITest-driveable UI, so element text comes from the captured tree only.`}),rs=Object.freeze({available:!1,reason:`unsupported-device-kind`}),is=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS open is not supported because XCUITest cannot drive watchOS UI.`}),as=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS runner preparation is not supported because XCUITest cannot drive watchOS UI.`}),os=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS close is not supported because XCUITest cannot drive watchOS UI.`}),ss=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Runtime hints are supported only for local iOS-family simulators and Android devices.`}),cs=Q(`open is supported only for Apple simulators and devices.`),ls=Q(`prepare is supported only for Apple simulators and devices.`),us=Q(`close is supported only for Apple simulators and devices.`),ds=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`}),fs=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`shutdown is supported only for Apple simulators and Android emulators.`}),ps=Q(`snapshot is supported only for Apple simulators and devices.`),ms=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Re-run without --actions, or target an iOS simulator.`}),hs=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`screenshot is not supported on watchOS because XCUITest cannot drive watchOS UI.`}),gs=Q(`screenshot is supported only for Apple simulators and devices.`),_s=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`Open the app under test before capturing its snapshot.`});function Q(e){return Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:e})}function vs(e){return!c(e)||e.appleOs===`watchos`?Z:e.kind===`simulator`?X:fs}function ys(e){let t=bs(e),n=xs(e),r=Ss(e),i=Cs(e);return me({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:i,clearRuntimeHints:i,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:n,configureProviderPortReverse:ds})}function bs(e){return p(e)===`watchos`?is:e.kind===`simulator`||e.kind===`device`?X:cs}function xs(e){return p(e)===`watchos`?as:e.kind===`simulator`||e.kind===`device`?X:ls}function Ss(e){return p(e)===`watchos`?os:e.kind===`simulator`||e.kind===`device`?X:us}function Cs(e){return p(e)!==`watchos`&&c(e)&&e.kind===`simulator`?X:ss}function ws(e){return e.appleOs===`watchos`?Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS app inventory is not supported.`}):e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`App inventory is available only on CoreDevice-backed physical iOS devices.`}):X}function $(e){return e.kind===`simulator`||e.kind===`device`?X:Qo}function Ts(e){let t=qn(e),n=Mo(e),r=async n=>{let r=await t.inspectFacts(n),i=Gi(n),a=Ir(n),o=a.available?await e.screenRecording.apple.availability(n):void 0,s=a.available&&o?.available===!1?Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:o.hint}):a,u=n.appleOs===`watchos`?Z:X,d=l(n)||n.appleOs===`watchos`?Z:X,f=ws(n);return Object.freeze({device:r.device,operations:{...r.operations,...i,appState:es(n),networkDump:X,screenRecordingStart:s,screenRecordingReattach:s,screenRecordingCleanup:s,...As(n),...Ce({capture:ks(n)}),...ke({findText:Os(n)}),...ge({setViewport:Yo}),...Be({focus:$(n)}),...gn(n),...he({type:$(n)}),...Ue({unsupported:Z,tap:$(n),longPress:$(n),fill:$(n),...c(n)?{tapElementSelector:$(n)}:{}}),...ve({readTextAtPoint:Ds(n)}),...xa(n),..._o(n),...La(n),...Ve({capture:ln(n),query:Xo}),...He(Es(n)),ensureReady:u,bootTarget:d,bootTargetHeadless:ts,listApps:f,...ys(n),shutdownTarget:vs(n)}})};return Object.freeze({owner:Y,ownsDevice:e=>e.platform===`apple`,inspectFacts:r,bind:async i=>{let a=await t.bind(i),o=await r(i.device),s=o.operations.screenRecordingStart,c={...h(o.operations.appState,()=>cn(e,{device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...a.operations,...Ki({host:e,device:i.device,signal:i.scope.signal}),networkDump:async t=>await Zn(e,i.device,t,i.scope.signal),...h(s,()=>Lr({host:e,device:i.device,owner:Y,signal:i.scope.signal})),...h(o.operations.audioProbeStart,()=>$e({host:e.audioProbe.hostCapture,device:i.device,owner:Y})),...h(o.operations.perfFrames,()=>un({resolveHost:()=>e.perf.apple,device:i.device,owner:Y})),...h(o.operations.captureSnapshot,()=>yo(e,{device:i.device,signal:i.scope.signal},n)),...h(o.operations.captureScreenshot,()=>we({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...h(o.operations.focusPoint,()=>Te({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...Oe({device:i.device,signal:i.scope.signal,facts:o.operations,resolveInteractor:e.localInteractors.resolve}),...h(o.operations.scrollDirection,()=>Ne({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...h(o.operations.typeText,()=>De({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...h(o.operations.tapPoint,()=>We({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:o.operations,pause:async t=>await e.clock.sleep(t,i.scope.signal)})),...h(o.operations.readTextAtPoint,()=>ye({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...h(o.operations.findText,()=>bo(e,{device:i.device,signal:i.scope.signal})),...Sa({host:e,device:i.device,signal:i.scope.signal}),...Ra({host:e,device:i.device,signal:i.scope.signal}),...vo({device:i.device,signal:i.scope.signal}),...h(o.operations.ensureReady,()=>({ensureReady:async()=>await M(e,i.device,i.scope.signal)})),...h(o.operations.bootTarget,()=>({bootTarget:async()=>await M(e,i.device,i.scope.signal)})),...h(o.operations.listApps,()=>({listApps:async e=>{i.scope.signal.throwIfAborted();let{listIosApps:t}=await import(`./app-resolution.js`).then(e=>e.t);return(await t(e.device,e.filter)).map(e=>({id:e.bundleId,name:e.name}))}})),...fe(xi({host:e,device:i.device,signal:i.scope.signal,observation:n}),o.operations),...h(o.operations.shutdownTarget,()=>({shutdownTarget:async()=>await e.deviceShutdown.apple.shutdownTarget(i.device,i.scope.signal)}))};return Object.freeze({device:a.device,owner:Y,facts:o,operations:sn(c),[Symbol.asyncDispose]:async()=>await a[Symbol.asyncDispose]()})},shutdown:async()=>{await Promise.all([t.shutdown(),n.shutdown()])}})}function Es(e){let t=e.iosPhysicalDeviceBackend!==`xctest`&&p(e)!==`watchos`?X:Zo;return{frames:t,memorySample:t,memorySnapshot:t,nativeCapture:t,profileReport:t}}function Ds(e){return p(e)===`watchos`?ns:e.kind===`simulator`||e.kind===`device`?X:rs}function Os(e){return p(e)===`watchos`?ps:e.kind===`simulator`||e.kind===`device`?X:ps}function ks(e){return p(e)===`watchos`?hs:e.kind===`simulator`||e.kind===`device`?X:gs}function As(e){let t=Os(e);return be({capture:t,customActions:t.available&&c(e)&&e.kind===`simulator`?X:ms,withoutActiveApp:c(e)?_s:t})}export{Ts as createApplePlatformRuntime};
|
package/dist/src/runtime5.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{B as e}from"./sdk-contracts.js";import{d as t}from"./sdk-device.js";import{o as n}from"./simctl.js";import{t as r}from"./simulator-state.js";const i=15e3;function a(e){return Object.freeze({canShutdownTarget:o,shutdownTarget:async(t,n)=>await s(e.appleTools,t,n)})}function o(e){return t(e)&&e.appleOs!==`watchos`&&e.kind===`simulator`}async function s(t,r,a){a.throwIfAborted();try{let e=await t.run({tool:`simctl`,args:n(r,[`shutdown`,r.id]),allowFailure:!0,timeoutMs:i},a);a.throwIfAborted();let o=l(e);return o.success?o:await c(t,r,a)===`Shutdown`?{...o,success:!0,exitCode:0}:o}catch(t){a.throwIfAborted();let n=e(t);return{success:!1,exitCode:-1,stdout:``,stderr:n.message,error:n}}}async function c(e,t,n){try{return await r(e,t,n,i)}catch{return n.throwIfAborted(),null}}function l(e){let t=e.exitCode??-1;return{success:t===0,exitCode:t,stdout:e.stdout,stderr:e.stderr}}export{a as createAppleShutdownRuntime};
|
package/dist/src/runtime6.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{D as e}from"./sdk-contracts.js";import{D as t}from"./sdk-device.js";import{Yt as n,tn as r}from"./sdk-batch.js";import{n as i}from"./device-shell.js";import{n as a,t as o}from"./application-lifecycle-runtime.js";import{A as s,B as c,C as l,D as u,G as d,H as f,I as p,J as ee,K as te,L as ne,N as re,O as ie,P as ae,V as oe,d as se,h as ce,j as le,n as ue,o as de,s as fe,v as m,w as h,x as g,z as pe}from"./alert-runtime.js";import{n as me}from"./audio-probe-runtime.js";import{n as he}from"./perf-runtime.js";import{i as ge,t as _e}from"./touch-runtime.js";import{a as _,n as v}from"./durable-resource.js";import{n as ve}from"./async-lifecycle.js";import{i as ye,r as be}from"./src7.js";import{n as xe,t as y}from"./screen-recording-completion.js";import{t as b}from"./screen-recording-options.js";import{n as x}from"./screen-recording-runtime.js";import{i as S}from"./gesture-admission.js";import{t as C}from"./interactor-operation-catalog.js";import{i as w,n as T}from"./perf-runtime-operation-builder.js";import{t as E}from"./app-log-runtime.js";import{n as D,t as O}from"./application-lifecycle-interaction.js";import{randomUUID as k}from"node:crypto";import{setTimeout as A}from"node:timers/promises";const j=Object.freeze({resourceKind:E,version:1,encode:e=>({...e}),decode:e=>e.transport!==`harmony-hilog`||!N(e.outputPath)||!N(e.pidPath)?{status:`invalid`,message:`Invalid HarmonyOS app-log descriptor`}:{status:`decoded`,descriptor:Object.freeze({transport:`harmony-hilog`,outputPath:e.outputPath,pidPath:e.pidPath})}});function M(e){return v({resourceKind:E,sessionId:e.sessionId,device:{id:e.device.id,family:`harmonyos`,kind:e.device.kind,...e.device.target===void 0?{}:{target:e.device.target}},owner:e.owner,fence:e.fence,lifecycle:`open`,descriptor:_(j,e.descriptor)})}function N(e){return typeof e==`string`&&e.trim().length>0}function Se(e){return be(e,{family:`harmonyos`,backend:`harmonyos`,label:`HarmonyOS`,codec:j,startUnavailableHint:`The selected HarmonyOS transport cannot start a background hilog stream.`,cleanupFailureMessage:`HarmonyOS app-log cleanup did not settle every owned resource`,doctor:async(e,t)=>({backend:`harmonyos`,checks:{},notes:t?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`]}),process:async({host:e,device:t,input:n,signal:r})=>{let a=await Ce(e,r);return{resolvePid:async r=>await ye(e,{executable:a,args:i(`hdc`,`shell`,[`pidof`,n.appBundleId],[`-t`,t.id]),allowFailure:!0,timeoutMs:5e3},r),command:e=>({kind:`host`,request:{executable:a,args:i(`hdc`,`shell`,[`hilog`,`-P`,e],[`-t`,t.id]),allowFailure:!0}})}},descriptor:({artifacts:e})=>({transport:`harmony-hilog`,...e}),envelope:({input:e,device:t,owner:n,descriptor:r})=>M({sessionId:e.sessionId,device:t,owner:n,fence:e.fence,descriptor:r})})}async function Ce(t,n){n.throwIfAborted(),await P(async()=>await t.toolchains.prepare(`harmonyos`),n),n.throwIfAborted();let r=await P(async()=>await t.commands.which(`hdc`),n);if(n.throwIfAborted(),!r)throw new e(`TOOL_MISSING`,`hdc not found in PATH`,{hint:`Install HarmonyOS Command Line Tools, then add its sdk/default/openharmony/toolchains directory to PATH.`});return r}async function P(e,t){try{return await e()}catch(e){throw t.throwIfAborted(),e}}function we(e){let{resolveHost:t,device:n}=e,r={available:!1,reason:`Dropped-frame sampling is currently available only on Android app sessions and connected iOS device app sessions.`};return Object.freeze({perfFrames:async()=>({metric:r,sampling:r}),perfMemorySample:async({appId:e})=>({metric:e?await w(t().sampleMemory(n,e)):T(`HarmonyOS`,`bundle`),sampling:{method:`hdc-shell-proc-status`,description:`Resident memory snapshot from HarmonyOS /proc/<pid>/status. Values are reported in kilobytes.`,unit:`kB`,topConsumerLimit:1}}),perfMemorySnapshot:async({kind:e})=>({artifact:{available:!1,kind:e??`memgraph`,reason:`Memory snapshot artifacts are not supported on harmonyos.`,hint:`Use perf memory sample where supported, or run the snapshot against Android, iOS simulator, or macOS.`,support:{platform:`harmonyos`,defaultKind:`memgraph`,androidHprof:!1,memgraph:!1,heapprofd:!1}},sampling:{method:`unsupported`,description:`HarmonyOS memory snapshot capture is not available through HDC.`,artifactOnly:!0}})})}const F=Object.freeze({resourceKind:x,version:1,encode:e=>({...e}),decode:e=>e.backend===`harmony-screen-recorder`&&typeof e.fileName==`string`&&De(e.fileName)&&e.remotePath===`/data/local/tmp/${e.fileName}`?{status:`decoded`,descriptor:Object.freeze({backend:`harmony-screen-recorder`,fileName:e.fileName,remotePath:e.remotePath})}:{status:`invalid`,message:`Invalid HarmonyOS screen-recording descriptor`}});function Te(e){let{device:n,owner:r,input:i,descriptor:a}=e;return v({resourceKind:x,sessionId:i.sessionId,device:t(n),owner:r,fence:i.fence,lifecycle:`open`,descriptor:_(F,a)})}function Ee(e){return F.decode(e).status===`decoded`?{status:`cleanup-pending`,reason:`manual-recovery-required`,message:`HarmonyOS recorder ownership cannot be proven after daemon restart; no recorder was stopped.`}:{status:`cleanup-pending`,reason:`manual-recovery-required`}}function De(e){return/^agent-device-recording-[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\.mp4$/i.test(e)}function Oe(e){return e.kind===`device`?Object.freeze({available:!0}):Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`HarmonyOS recording is supported on physical devices only.`})}function ke(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await Ae({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async()=>({status:`unreattachable`,reason:`transport-not-reattachable`,message:`HarmonyOS recordings cannot be reattached after daemon restart.`}),screenRecordingCleanup:async e=>Ee(e.envelope.descriptor.body)})}async function Ae(t){let{host:n,device:r,owner:i,input:a,signal:o}=t;if(a.scope===`app`)throw new e(`INVALID_ARGS`,`HarmonyOS recording captures the whole physical-device screen; use --scope device or --scope system`);b(a,{scopes:[`device`,`system`],fps:!1,exportQuality:!1,hideTouches:!1},e=>`HarmonyOS recordings do not support ${e.join(`, `)}`),o.throwIfAborted(),await n.screenRecording.outputs.prepare(a.outputPath);let s=`agent-device-recording-${k()}.mp4`,c={backend:`harmony-screen-recorder`,fileName:s,remotePath:`/data/local/tmp/${s}`},l;try{l=await n.screenRecording.harmony.start(r,s,o),o.throwIfAborted()}catch(e){throw o.aborted?(await R(n,r,c).catch(()=>{}),o.reason):e}B(l,`start`);try{o.throwIfAborted()}catch(e){throw await R(n,r,c).catch(()=>{}),e}let u=je(a),d=!1,f=async()=>{d||=(B(await n.screenRecording.harmony.stop(r),`stop`),!0)},p=xe(u,{finish:async e=>await Me(n,r,e,c,f),forceCleanup:async()=>await R(n,r,c,f)});return Object.freeze({pendingHandle:new ve(p),envelope:Te({device:r,owner:i,input:a,descriptor:c})})}function je(e){return Object.freeze({backend:`HarmonyOS ScreenRecorder`,outPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutPath:e.clientOutputPath},startedAt:Date.now(),scope:e.scope,showTouches:!1,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},gestureEvents:[]})}async function Me(e,t,n,r,i){await i();let a=await e.screenRecording.harmony.findMedia(t,r.fileName);if(!a)throw Error(`failed to find finalized HarmonyOS recording '${r.fileName}'`);if(!await Pe(e,t,r,a))throw Error(`failed to finalize HarmonyOS recording: ${r.fileName} did not produce a non-empty media file`);try{if((await e.screenRecording.harmony.pull(t,{remotePath:r.remotePath,outputPath:n.outPath})).exitCode!==0)throw Error(`failed to retrieve HarmonyOS recording`);let i=await e.screenRecording.finalize.complete({outputPath:n.outPath,showTouches:!1,gestureEvents:n.gestureEvents,targetLabel:`HarmonyOS recording`}),o=await Ne(e,t,r,a);return y(n,{...i,...L(i.warning,o)},{stopObservation:{recorder:`confirmed`},nativePathDisposition:o===void 0?`retired`:`retirable`,showTouches:!1})}catch(n){throw await e.screenRecording.harmony.remove(t,r.remotePath).catch(()=>{}),n}}async function Ne(e,t,n,r){let i=[];return await I(()=>e.screenRecording.harmony.remove(t,n.remotePath))||i.push(`staging artifact`),await I(()=>e.screenRecording.harmony.removeMedia(t,r))||i.push(`media-library artifact`),i.length===0?void 0:`HarmonyOS recording completed, but cleanup was not confirmed for the ${i.join(` and `)}.`}async function I(e){try{return await e()}catch{return!1}}function L(e,t){let n=[e,t].filter(e=>e!==void 0).join(` `);return n.length===0?{}:{warning:n}}async function Pe(e,t,n,r){let i;for(let a=0;a<40;a+=1){if(await e.screenRecording.harmony.remove(t,n.remotePath).catch(()=>{}),await e.screenRecording.harmony.stageMedia(t,{mediaUri:r,remotePath:n.remotePath})){let r=await e.screenRecording.harmony.stagedFileSize(t,n.remotePath);if(r!==void 0&&r>0&&r===i)return!0;i=r!==void 0&&r>0?r:void 0}else i=void 0;a<39&&await e.clock.sleep(250)}return!1}async function R(e,t,n,r=async()=>{B(await e.screenRecording.harmony.stop(t),`stop`)}){let i=[await z(r),await z(async()=>{if(!await e.screenRecording.harmony.remove(t,n.remotePath))throw Error(`HarmonyOS recording staging artifact removal was not confirmed`)}),await z(async()=>await Fe(e,t,n.fileName))].find(e=>e!==void 0);return i===void 0?{status:`cleaned`}:{status:`cleanup-pending`,reason:`transport-failed`,message:i instanceof Error?i.message:`HarmonyOS recording cleanup failed`}}async function Fe(e,t,n){let r=await e.screenRecording.harmony.findMedia(t,n);if(r&&!await e.screenRecording.harmony.removeMedia(t,r))throw Error(`HarmonyOS recording media removal was not confirmed`)}async function z(e){try{await e();return}catch(e){return e}}function B(e,t){if(e.exitCode===0&&e.stdout.includes(`start ability successfully`))return;let n=e.stdout.trim()||e.stderr.trim()||`hdc exit ${e.exitCode}`;throw Error(`failed to ${t} HarmonyOS screen recording: ${n}`)}async function Ie(t,n){n.throwIfAborted();let{runHarmonyShell:r}=await import(`./hdc.js`),i=await r(t,[`aa`,`dump`,`-l`],{timeoutMs:15e3,signal:n});n.throwIfAborted();let a=Le(i.stdout);if(!a)throw new e(`COMMAND_FAILED`,`Could not determine the foreground HarmonyOS app`,{hint:`Open an app on the target, then retry appstate.`});return a}function Le(e){let t=e.split(/(?=^\s*Mission ID #)/m);for(let e of t){if(!/\bstate #FOREGROUND\b/.test(e))continue;let t=e.match(/mission name #\[#([^:]+):[^:]*:([^\]]+)]/);if(!t)continue;let[,n,r]=t;if(!(!n||!r))return{package:n,activity:r}}}function Re(e){return O({owner:`HarmonyOS`,openTargetIdentity:`bundle-id`,binding:D({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const ze=Object.freeze({available:!0}),Be=Object.freeze({available:!1,reason:`unsupported-device-kind`}),V=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function H(e){let t=e.kind===`emulator`||e.kind===`device`?ze:Be;return Object.freeze({deployApp:t,materializeAppSource:V,deployMaterializedApp:V,sendPushNotification:V})}function Ve(e){return H(e.device).deployApp.available?Object.freeze({deployApp:async t=>await He(e.commands,e.device,t,e.signal)}):Object.freeze({})}async function He(t,n,r,i){let a=await Ue(t,r.appPath,i)??r.app.trim();if(!a)throw new e(`INVALID_ARGS`,`Could not determine the bundle name from the HAP archive`,{hint:`Pass the HarmonyOS bundle name before the HAP path, or provide a valid HAP containing module.json.`});return await Ke(t,n,[`install`,`-r`,r.appPath],i,18e4),r.replaceExisting&&(await A(1e3,void 0,{signal:i}),await We(t,n,a,i)),{packageName:a,launchTarget:a}}async function Ue(e,t,n){let r=await e.run({executable:`unzip`,args:[`-p`,t,`module.json`],allowFailure:!0,timeoutMs:15e3},n);if(r.exitCode===0&&r.stdout.trim().length!==0)try{return JSON.parse(r.stdout).app?.bundleName?.trim()||void 0}catch{return}}async function We(t,n,r,i){let a=Ge((await U(t,n,[`bm`,`dump`,`-n`,r],i)).stdout);if(!a)throw new e(`COMMAND_FAILED`,`Could not determine a launchable ability for ${r}`,{hint:`Check that the HarmonyOS bundle exposes a main ability.`});await U(t,n,[`aa`,`start`,`-b`,r,...a.module?[`-m`,a.module]:[],`-a`,a.ability],i)}function Ge(e){let t=e.indexOf(`{`);if(t!==-1)try{let n=JSON.parse(e.slice(t)).hapModuleInfos?.find(e=>e.mainElementName);return n?.mainElementName?{ability:n.mainElementName,...n.moduleName?{module:n.moduleName}:{}}:void 0}catch{return}}async function Ke(e,t,n,r,i=15e3){return await e.run({executable:`hdc`,args:[`-t`,t.id,...n],timeoutMs:i},r)}async function U(e,t,n,r,a=15e3){return await e.run({executable:`hdc`,args:i(`hdc`,`shell`,n,[`-t`,t.id]),timeoutMs:a},r)}const W=n(`harmonyos`),qe=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`HarmonyOS reads element text from the captured tree only.`}),Je=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`focus is supported on HarmonyOS emulators and physical devices.`}),G=Object.freeze({available:!0}),K=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Ye=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`HarmonyOS appstate is supported only for HarmonyOS emulators and devices.`}),Xe=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple runner preparation is supported only for Apple targets.`}),q=Object.freeze({available:!0}),Ze=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`open is supported only for HarmonyOS emulators and devices.`}),Qe=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`close is supported only for HarmonyOS emulators and devices.`}),$e=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`}),J=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`snapshot is supported only for HarmonyOS emulators and devices.`}),et=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`screenshot is supported only for HarmonyOS emulators and devices.`}),tt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Re-run without --actions, or target an iOS simulator.`}),nt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`viewport resizes web targets only (--platform web).`});function rt(e){let t=it(e),n=at(e);return o({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:K,clearRuntimeHints:K,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:Xe,configureProviderPortReverse:$e})}function it(e){return e.kind===`emulator`||e.kind===`device`?q:Ze}function at(e){return e.kind===`emulator`||e.kind===`device`?q:Qe}const Y=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Gestures are supported on HarmonyOS emulators and physical devices.`}),ot=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),st=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:S});function X(e){return e.kind===`emulator`||e.kind===`device`?G:Y}function Z(e){return e.kind===`emulator`||e.kind===`device`?G:Je}const Q=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),ct=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`keyboard status/get is not available through the public HarmonyOS HDC API; use keyboard dismiss or enter`}),$=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`audio is supported for web browser sessions, macOS sessions, iOS simulators, and Android emulators on macOS hosts`});function lt(e){let t=Se(e),n=async e=>{let n=await t.inspectFacts(e),r=H(e),i=Oe(e);return Object.freeze({device:n.device,operations:{...n.operations,...r,appState:e.kind===`simulator`?Ye:G,networkDump:K,screenRecordingStart:i,screenRecordingReattach:i,screenRecordingCleanup:i,...d({capture:e.kind===`emulator`||e.kind===`device`?G:J,customActions:tt,withoutActiveApp:e.kind===`emulator`||e.kind===`device`?G:J}),...ee({capture:e.kind===`emulator`||e.kind===`device`?G:et}),...oe({findText:J}),...c({setViewport:nt}),...pe({focus:Z(e)}),...p({unsupported:Y,plan:X(e),directionalFling:X(e),multiTouch:ot,targetAuthoredDrag:st,viewport:X(e)}),...re({scroll:X(e)}),...s({type:Z(e)}),...ge({unsupported:K,tap:Z(e),longPress:Z(e),fill:Z(e)}),...u({readTextAtPoint:qe}),...h({back:Z(e)}),...se({unsupported:Q,home:Z(e),appSwitcher:Z(e)}),setFoldPose:Q,...fe({triggerAppEvent:Q}),...de({setSetting:Z(e),readSetting:Q}),...ue({read:Q,wait:Q,accept:Q,dismiss:Q}),...l({orientation:Q}),...g({tvRemote:Q}),...m({unsupported:Q,status:ct,dismiss:Z(e),enter:Z(e)}),...ce({unsupported:Q}),...me({capture:$,query:$}),...he({frames:Z(e),memorySample:Z(e),memorySnapshot:Z(e),nativeCapture:Q,profileReport:Q}),ensureReady:G,bootTarget:K,bootTargetHeadless:K,listApps:G,...rt(e),shutdownTarget:K}})};return Object.freeze({owner:W,ownsDevice:e=>e.platform===`harmonyos`,inspectFacts:n,bind:async i=>{let o=await t.bind(i),s=await n(i.device),c=s.operations.screenRecordingStart;return Object.freeze({device:o.device,owner:W,facts:s,operations:Object.freeze({...o.operations,...Ve({commands:e.commands,device:i.device,signal:i.scope.signal}),...s.operations.appState.available?{appState:async()=>await Ie(i.device,i.scope.signal)}:{},ensureReady:async()=>({...i.device,booted:!0}),...c.available?ke({host:e,device:i.device,owner:W,signal:i.scope.signal}):{},...s.operations.captureSnapshot.available?f({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...s.operations.captureScreenshot.available?te({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...s.operations.focusPoint.available?ne({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...s.operations.typeText.available?ie({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...ae({device:i.device,signal:i.scope.signal,facts:s.operations,resolveInteractor:e.localInteractors.resolve}),...s.operations.scrollDirection.available?le({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...C({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:s.operations}),...r(s.operations.perfFrames,()=>we({resolveHost:()=>e.perf.harmony,device:i.device})),...r(s.operations.tapPoint,()=>_e({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:s.operations,pause:async t=>await e.clock.sleep(t,i.scope.signal)})),listApps:async e=>{i.scope.signal.throwIfAborted();let{listHarmonyApps:t}=await import(`./app-lifecycle2.js`);return(await t(e.device,e.filter,{signal:i.scope.signal})).map(e=>({id:e.package,name:e.name}))},...a(Re({host:e.localInteractors,device:i.device,signal:i.scope.signal}),s.operations)}),[Symbol.asyncDispose]:async()=>await o[Symbol.asyncDispose]()})},shutdown:async()=>await t.shutdown()})}export{lt as createHarmonyPlatformRuntime};
|
|
1
|
+
import{A as e}from"./sdk-contracts.js";import{D as t}from"./sdk-device.js";import{Yt as n,tn as r}from"./sdk-batch.js";import{n as i}from"./device-shell.js";import{n as a,t as o}from"./application-lifecycle-runtime.js";import{A as s,B as c,C as l,D as u,G as d,H as f,I as p,J as ee,K as te,L as ne,N as re,O as ie,P as ae,V as oe,d as se,h as ce,j as le,n as ue,o as de,s as fe,v as m,w as h,x as g,z as pe}from"./alert-runtime.js";import{n as me}from"./audio-probe-runtime.js";import{n as he}from"./perf-runtime.js";import{i as ge,t as _e}from"./touch-runtime.js";import{a as _,n as v}from"./durable-resource.js";import{n as ve}from"./async-lifecycle.js";import{i as ye,r as be}from"./src7.js";import{n as xe,t as y}from"./screen-recording-completion.js";import{t as b}from"./screen-recording-options.js";import{n as x}from"./screen-recording-runtime.js";import{i as S}from"./gesture-admission.js";import{t as C}from"./interactor-operation-catalog.js";import{i as w,n as T}from"./perf-runtime-operation-builder.js";import{t as E}from"./app-log-runtime.js";import{n as D,t as O}from"./application-lifecycle-interaction.js";import{randomUUID as k}from"node:crypto";import{setTimeout as A}from"node:timers/promises";const j=Object.freeze({resourceKind:E,version:1,encode:e=>({...e}),decode:e=>e.transport!==`harmony-hilog`||!N(e.outputPath)||!N(e.pidPath)?{status:`invalid`,message:`Invalid HarmonyOS app-log descriptor`}:{status:`decoded`,descriptor:Object.freeze({transport:`harmony-hilog`,outputPath:e.outputPath,pidPath:e.pidPath})}});function M(e){return v({resourceKind:E,sessionId:e.sessionId,device:{id:e.device.id,family:`harmonyos`,kind:e.device.kind,...e.device.target===void 0?{}:{target:e.device.target}},owner:e.owner,fence:e.fence,lifecycle:`open`,descriptor:_(j,e.descriptor)})}function N(e){return typeof e==`string`&&e.trim().length>0}function Se(e){return be(e,{family:`harmonyos`,backend:`harmonyos`,label:`HarmonyOS`,codec:j,startUnavailableHint:`The selected HarmonyOS transport cannot start a background hilog stream.`,cleanupFailureMessage:`HarmonyOS app-log cleanup did not settle every owned resource`,doctor:async(e,t)=>({backend:`harmonyos`,checks:{},notes:t?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`]}),process:async({host:e,device:t,input:n,signal:r})=>{let a=await Ce(e,r);return{resolvePid:async r=>await ye(e,{executable:a,args:i(`hdc`,`shell`,[`pidof`,n.appBundleId],[`-t`,t.id]),allowFailure:!0,timeoutMs:5e3},r),command:e=>({kind:`host`,request:{executable:a,args:i(`hdc`,`shell`,[`hilog`,`-P`,e],[`-t`,t.id]),allowFailure:!0}})}},descriptor:({artifacts:e})=>({transport:`harmony-hilog`,...e}),envelope:({input:e,device:t,owner:n,descriptor:r})=>M({sessionId:e.sessionId,device:t,owner:n,fence:e.fence,descriptor:r})})}async function Ce(t,n){n.throwIfAborted(),await P(async()=>await t.toolchains.prepare(`harmonyos`),n),n.throwIfAborted();let r=await P(async()=>await t.commands.which(`hdc`),n);if(n.throwIfAborted(),!r)throw new e(`TOOL_MISSING`,`hdc not found in PATH`,{hint:`Install HarmonyOS Command Line Tools, then add its sdk/default/openharmony/toolchains directory to PATH.`});return r}async function P(e,t){try{return await e()}catch(e){throw t.throwIfAborted(),e}}function we(e){let{resolveHost:t,device:n}=e,r={available:!1,reason:`Dropped-frame sampling is currently available only on Android app sessions and connected iOS device app sessions.`};return Object.freeze({perfFrames:async()=>({metric:r,sampling:r}),perfMemorySample:async({appId:e})=>({metric:e?await w(t().sampleMemory(n,e)):T(`HarmonyOS`,`bundle`),sampling:{method:`hdc-shell-proc-status`,description:`Resident memory snapshot from HarmonyOS /proc/<pid>/status. Values are reported in kilobytes.`,unit:`kB`,topConsumerLimit:1}}),perfMemorySnapshot:async({kind:e})=>({artifact:{available:!1,kind:e??`memgraph`,reason:`Memory snapshot artifacts are not supported on harmonyos.`,hint:`Use perf memory sample where supported, or run the snapshot against Android, iOS simulator, or macOS.`,support:{platform:`harmonyos`,defaultKind:`memgraph`,androidHprof:!1,memgraph:!1,heapprofd:!1}},sampling:{method:`unsupported`,description:`HarmonyOS memory snapshot capture is not available through HDC.`,artifactOnly:!0}})})}const F=Object.freeze({resourceKind:x,version:1,encode:e=>({...e}),decode:e=>e.backend===`harmony-screen-recorder`&&typeof e.fileName==`string`&&De(e.fileName)&&e.remotePath===`/data/local/tmp/${e.fileName}`?{status:`decoded`,descriptor:Object.freeze({backend:`harmony-screen-recorder`,fileName:e.fileName,remotePath:e.remotePath})}:{status:`invalid`,message:`Invalid HarmonyOS screen-recording descriptor`}});function Te(e){let{device:n,owner:r,input:i,descriptor:a}=e;return v({resourceKind:x,sessionId:i.sessionId,device:t(n),owner:r,fence:i.fence,lifecycle:`open`,descriptor:_(F,a)})}function Ee(e){return F.decode(e).status===`decoded`?{status:`cleanup-pending`,reason:`manual-recovery-required`,message:`HarmonyOS recorder ownership cannot be proven after daemon restart; no recorder was stopped.`}:{status:`cleanup-pending`,reason:`manual-recovery-required`}}function De(e){return/^agent-device-recording-[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\.mp4$/i.test(e)}function Oe(e){return e.kind===`device`?Object.freeze({available:!0}):Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`HarmonyOS recording is supported on physical devices only.`})}function ke(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await Ae({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async()=>({status:`unreattachable`,reason:`transport-not-reattachable`,message:`HarmonyOS recordings cannot be reattached after daemon restart.`}),screenRecordingCleanup:async e=>Ee(e.envelope.descriptor.body)})}async function Ae(t){let{host:n,device:r,owner:i,input:a,signal:o}=t;if(a.scope===`app`)throw new e(`INVALID_ARGS`,`HarmonyOS recording captures the whole physical-device screen; use --scope device or --scope system`);b(a,{scopes:[`device`,`system`],fps:!1,exportQuality:!1,hideTouches:!1},e=>`HarmonyOS recordings do not support ${e.join(`, `)}`),o.throwIfAborted(),await n.screenRecording.outputs.prepare(a.outputPath);let s=`agent-device-recording-${k()}.mp4`,c={backend:`harmony-screen-recorder`,fileName:s,remotePath:`/data/local/tmp/${s}`},l;try{l=await n.screenRecording.harmony.start(r,s,o),o.throwIfAborted()}catch(e){throw o.aborted?(await R(n,r,c).catch(()=>{}),o.reason):e}B(l,`start`);try{o.throwIfAborted()}catch(e){throw await R(n,r,c).catch(()=>{}),e}let u=je(a),d=!1,f=async()=>{d||=(B(await n.screenRecording.harmony.stop(r),`stop`),!0)},p=xe(u,{finish:async e=>await Me(n,r,e,c,f),forceCleanup:async()=>await R(n,r,c,f)});return Object.freeze({pendingHandle:new ve(p),envelope:Te({device:r,owner:i,input:a,descriptor:c})})}function je(e){return Object.freeze({backend:`HarmonyOS ScreenRecorder`,outPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutPath:e.clientOutputPath},startedAt:Date.now(),scope:e.scope,showTouches:!1,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},gestureEvents:[]})}async function Me(e,t,n,r,i){await i();let a=await e.screenRecording.harmony.findMedia(t,r.fileName);if(!a)throw Error(`failed to find finalized HarmonyOS recording '${r.fileName}'`);if(!await Pe(e,t,r,a))throw Error(`failed to finalize HarmonyOS recording: ${r.fileName} did not produce a non-empty media file`);try{if((await e.screenRecording.harmony.pull(t,{remotePath:r.remotePath,outputPath:n.outPath})).exitCode!==0)throw Error(`failed to retrieve HarmonyOS recording`);let i=await e.screenRecording.finalize.complete({outputPath:n.outPath,showTouches:!1,gestureEvents:n.gestureEvents,targetLabel:`HarmonyOS recording`}),o=await Ne(e,t,r,a);return y(n,{...i,...L(i.warning,o)},{stopObservation:{recorder:`confirmed`},nativePathDisposition:o===void 0?`retired`:`retirable`,showTouches:!1})}catch(n){throw await e.screenRecording.harmony.remove(t,r.remotePath).catch(()=>{}),n}}async function Ne(e,t,n,r){let i=[];return await I(()=>e.screenRecording.harmony.remove(t,n.remotePath))||i.push(`staging artifact`),await I(()=>e.screenRecording.harmony.removeMedia(t,r))||i.push(`media-library artifact`),i.length===0?void 0:`HarmonyOS recording completed, but cleanup was not confirmed for the ${i.join(` and `)}.`}async function I(e){try{return await e()}catch{return!1}}function L(e,t){let n=[e,t].filter(e=>e!==void 0).join(` `);return n.length===0?{}:{warning:n}}async function Pe(e,t,n,r){let i;for(let a=0;a<40;a+=1){if(await e.screenRecording.harmony.remove(t,n.remotePath).catch(()=>{}),await e.screenRecording.harmony.stageMedia(t,{mediaUri:r,remotePath:n.remotePath})){let r=await e.screenRecording.harmony.stagedFileSize(t,n.remotePath);if(r!==void 0&&r>0&&r===i)return!0;i=r!==void 0&&r>0?r:void 0}else i=void 0;a<39&&await e.clock.sleep(250)}return!1}async function R(e,t,n,r=async()=>{B(await e.screenRecording.harmony.stop(t),`stop`)}){let i=[await z(r),await z(async()=>{if(!await e.screenRecording.harmony.remove(t,n.remotePath))throw Error(`HarmonyOS recording staging artifact removal was not confirmed`)}),await z(async()=>await Fe(e,t,n.fileName))].find(e=>e!==void 0);return i===void 0?{status:`cleaned`}:{status:`cleanup-pending`,reason:`transport-failed`,message:i instanceof Error?i.message:`HarmonyOS recording cleanup failed`}}async function Fe(e,t,n){let r=await e.screenRecording.harmony.findMedia(t,n);if(r&&!await e.screenRecording.harmony.removeMedia(t,r))throw Error(`HarmonyOS recording media removal was not confirmed`)}async function z(e){try{await e();return}catch(e){return e}}function B(e,t){if(e.exitCode===0&&e.stdout.includes(`start ability successfully`))return;let n=e.stdout.trim()||e.stderr.trim()||`hdc exit ${e.exitCode}`;throw Error(`failed to ${t} HarmonyOS screen recording: ${n}`)}async function Ie(t,n){n.throwIfAborted();let{runHarmonyShell:r}=await import(`./hdc.js`),i=await r(t,[`aa`,`dump`,`-l`],{timeoutMs:15e3,signal:n});n.throwIfAborted();let a=Le(i.stdout);if(!a)throw new e(`COMMAND_FAILED`,`Could not determine the foreground HarmonyOS app`,{hint:`Open an app on the target, then retry appstate.`});return a}function Le(e){let t=e.split(/(?=^\s*Mission ID #)/m);for(let e of t){if(!/\bstate #FOREGROUND\b/.test(e))continue;let t=e.match(/mission name #\[#([^:]+):[^:]*:([^\]]+)]/);if(!t)continue;let[,n,r]=t;if(!(!n||!r))return{package:n,activity:r}}}function Re(e){return O({owner:`HarmonyOS`,openTargetIdentity:`bundle-id`,binding:D({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const ze=Object.freeze({available:!0}),Be=Object.freeze({available:!1,reason:`unsupported-device-kind`}),V=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function H(e){let t=e.kind===`emulator`||e.kind===`device`?ze:Be;return Object.freeze({deployApp:t,materializeAppSource:V,deployMaterializedApp:V,sendPushNotification:V})}function Ve(e){return H(e.device).deployApp.available?Object.freeze({deployApp:async t=>await He(e.commands,e.device,t,e.signal)}):Object.freeze({})}async function He(t,n,r,i){let a=await Ue(t,r.appPath,i)??r.app.trim();if(!a)throw new e(`INVALID_ARGS`,`Could not determine the bundle name from the HAP archive`,{hint:`Pass the HarmonyOS bundle name before the HAP path, or provide a valid HAP containing module.json.`});return await Ke(t,n,[`install`,`-r`,r.appPath],i,18e4),r.replaceExisting&&(await A(1e3,void 0,{signal:i}),await We(t,n,a,i)),{packageName:a,launchTarget:a}}async function Ue(e,t,n){let r=await e.run({executable:`unzip`,args:[`-p`,t,`module.json`],allowFailure:!0,timeoutMs:15e3},n);if(r.exitCode===0&&r.stdout.trim().length!==0)try{return JSON.parse(r.stdout).app?.bundleName?.trim()||void 0}catch{return}}async function We(t,n,r,i){let a=Ge((await U(t,n,[`bm`,`dump`,`-n`,r],i)).stdout);if(!a)throw new e(`COMMAND_FAILED`,`Could not determine a launchable ability for ${r}`,{hint:`Check that the HarmonyOS bundle exposes a main ability.`});await U(t,n,[`aa`,`start`,`-b`,r,...a.module?[`-m`,a.module]:[],`-a`,a.ability],i)}function Ge(e){let t=e.indexOf(`{`);if(t!==-1)try{let n=JSON.parse(e.slice(t)).hapModuleInfos?.find(e=>e.mainElementName);return n?.mainElementName?{ability:n.mainElementName,...n.moduleName?{module:n.moduleName}:{}}:void 0}catch{return}}async function Ke(e,t,n,r,i=15e3){return await e.run({executable:`hdc`,args:[`-t`,t.id,...n],timeoutMs:i},r)}async function U(e,t,n,r,a=15e3){return await e.run({executable:`hdc`,args:i(`hdc`,`shell`,n,[`-t`,t.id]),timeoutMs:a},r)}const W=n(`harmonyos`),qe=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`HarmonyOS reads element text from the captured tree only.`}),Je=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`focus is supported on HarmonyOS emulators and physical devices.`}),G=Object.freeze({available:!0}),K=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Ye=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`HarmonyOS appstate is supported only for HarmonyOS emulators and devices.`}),Xe=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple runner preparation is supported only for Apple targets.`}),q=Object.freeze({available:!0}),Ze=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`open is supported only for HarmonyOS emulators and devices.`}),Qe=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`close is supported only for HarmonyOS emulators and devices.`}),$e=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`}),J=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`snapshot is supported only for HarmonyOS emulators and devices.`}),et=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`screenshot is supported only for HarmonyOS emulators and devices.`}),tt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Re-run without --actions, or target an iOS simulator.`}),nt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`viewport resizes web targets only (--platform web).`});function rt(e){let t=it(e),n=at(e);return o({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:K,clearRuntimeHints:K,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:Xe,configureProviderPortReverse:$e})}function it(e){return e.kind===`emulator`||e.kind===`device`?q:Ze}function at(e){return e.kind===`emulator`||e.kind===`device`?q:Qe}const Y=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Gestures are supported on HarmonyOS emulators and physical devices.`}),ot=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),st=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:S});function X(e){return e.kind===`emulator`||e.kind===`device`?G:Y}function Z(e){return e.kind===`emulator`||e.kind===`device`?G:Je}const Q=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),ct=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`keyboard status/get is not available through the public HarmonyOS HDC API; use keyboard dismiss or enter`}),$=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`audio is supported for web browser sessions, macOS sessions, iOS simulators, and Android emulators on macOS hosts`});function lt(e){let t=Se(e),n=async e=>{let n=await t.inspectFacts(e),r=H(e),i=Oe(e);return Object.freeze({device:n.device,operations:{...n.operations,...r,appState:e.kind===`simulator`?Ye:G,networkDump:K,screenRecordingStart:i,screenRecordingReattach:i,screenRecordingCleanup:i,...d({capture:e.kind===`emulator`||e.kind===`device`?G:J,customActions:tt,withoutActiveApp:e.kind===`emulator`||e.kind===`device`?G:J}),...ee({capture:e.kind===`emulator`||e.kind===`device`?G:et}),...oe({findText:J}),...c({setViewport:nt}),...pe({focus:Z(e)}),...p({unsupported:Y,plan:X(e),directionalFling:X(e),multiTouch:ot,targetAuthoredDrag:st,viewport:X(e)}),...re({scroll:X(e)}),...s({type:Z(e)}),...ge({unsupported:K,tap:Z(e),longPress:Z(e),fill:Z(e)}),...u({readTextAtPoint:qe}),...h({back:Z(e)}),...se({unsupported:Q,home:Z(e),appSwitcher:Z(e)}),setFoldPose:Q,...fe({triggerAppEvent:Q}),...de({setSetting:Z(e),readSetting:Q}),...ue({read:Q,wait:Q,accept:Q,dismiss:Q}),...l({orientation:Q}),...g({tvRemote:Q}),...m({unsupported:Q,status:ct,dismiss:Z(e),enter:Z(e)}),...ce({unsupported:Q}),...me({capture:$,query:$}),...he({frames:Z(e),memorySample:Z(e),memorySnapshot:Z(e),nativeCapture:Q,profileReport:Q}),ensureReady:G,bootTarget:K,bootTargetHeadless:K,listApps:G,...rt(e),shutdownTarget:K}})};return Object.freeze({owner:W,ownsDevice:e=>e.platform===`harmonyos`,inspectFacts:n,bind:async i=>{let o=await t.bind(i),s=await n(i.device),c=s.operations.screenRecordingStart;return Object.freeze({device:o.device,owner:W,facts:s,operations:Object.freeze({...o.operations,...Ve({commands:e.commands,device:i.device,signal:i.scope.signal}),...s.operations.appState.available?{appState:async()=>await Ie(i.device,i.scope.signal)}:{},ensureReady:async()=>({...i.device,booted:!0}),...c.available?ke({host:e,device:i.device,owner:W,signal:i.scope.signal}):{},...s.operations.captureSnapshot.available?f({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...s.operations.captureScreenshot.available?te({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...s.operations.focusPoint.available?ne({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...s.operations.typeText.available?ie({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...ae({device:i.device,signal:i.scope.signal,facts:s.operations,resolveInteractor:e.localInteractors.resolve}),...s.operations.scrollDirection.available?le({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...C({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:s.operations}),...r(s.operations.perfFrames,()=>we({resolveHost:()=>e.perf.harmony,device:i.device})),...r(s.operations.tapPoint,()=>_e({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:s.operations,pause:async t=>await e.clock.sleep(t,i.scope.signal)})),listApps:async e=>{i.scope.signal.throwIfAborted();let{listHarmonyApps:t}=await import(`./app-lifecycle2.js`);return(await t(e.device,e.filter,{signal:i.scope.signal})).map(e=>({id:e.package,name:e.name}))},...a(Re({host:e.localInteractors,device:i.device,signal:i.scope.signal}),s.operations)}),[Symbol.asyncDispose]:async()=>await o[Symbol.asyncDispose]()})},shutdown:async()=>await t.shutdown()})}export{lt as createHarmonyPlatformRuntime};
|
package/dist/src/runtime7.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{A as e}from"./sdk-contracts.js";import{Yt as t,en as n}from"./sdk-batch.js";import{n as r,t as i}from"./application-lifecycle-runtime.js";import{A as a,D as o,G as s,I as c,J as ee,N as l,W as u,d,h as f,w as p,z as m}from"./alert-runtime.js";import{i as h}from"./touch-runtime.js";import{r as g}from"./platform-runtime-unavailable.js";import{i as _}from"./gesture-admission.js";import{t as v}from"./local-interactor-operation-set.js";import{n as y,t as b}from"./application-lifecycle-interaction.js";function x(e){return b({owner:`Linux`,openTargetIdentity:`app-name`,binding:y({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const S=Object.freeze({available:!0}),C=t(`linux`),w=$(`unsupported-platform-leaf`),T=$(`unsupported-device-kind`),E=$(`unsupported-device-kind`,`focus is supported only for the Linux desktop device.`),D=$(`unsupported-device-kind`,`type is supported only for the Linux desktop device.`),O=$(`unsupported-device-kind`,`Gestures are supported only for the Linux desktop device.`),k=$(`unsupported-device-kind`,`scroll is supported only for the Linux desktop device.`),A=$(`unsupported-platform-leaf`),j=$(`unsupported-platform-leaf`),M=$(`unsupported-platform-leaf`,_),N=$(`unsupported-platform-leaf`),P=$(`unsupported-platform-leaf`,`Runtime hints are supported only for local iOS-family simulators and Android devices.`),F=$(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),I=$(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),L=$(`unsupported-device-kind`,`open is supported only for the Linux desktop device.`),R=$(`unsupported-device-kind`,`close is supported only for the Linux desktop device.`),z=$(`unsupported-device-kind`,`snapshot is supported only for the Linux desktop device.`),B=$(`unsupported-device-kind`,`screenshot is supported only for the Linux desktop device.`),V=$(`unsupported-platform-leaf`,`Re-run without --actions, or target an iOS simulator.`),H=$(`unsupported-device-kind`,`back is supported only for the Linux desktop device.`),U=$(`unsupported-device-kind`,`home is supported only for the Linux desktop device.`),W=$(`unsupported-device-kind`,`clipboard is supported only for the Linux desktop device.`),G=w,K=$(`unsupported-platform-leaf`,`audio is supported for web browser sessions, macOS sessions, iOS simulators, and Android emulators on macOS hosts`);function q(t){return Object.freeze({owner:C,ownsDevice:e=>e.platform===`linux`,inspectFacts:async e=>Y(e),bind:async i=>{if(i.intent.kind===`exact-owner`&&!n(i.intent.owner,C))throw new e(`UNSUPPORTED_OPERATION`,`Linux runtime owner identity does not match`);if(i.device.platform!==`linux`)throw new e(`UNSUPPORTED_PLATFORM`,`Linux runtime cannot bind this device`);let a=Y(i.device),o=x({host:t.localInteractors,device:i.device,signal:i.scope.signal});return Object.freeze({device:i.device,owner:C,facts:a,operations:Object.freeze({...r(o,a.operations),...a.operations.captureSnapshot.available?Q(t,i):{},...J(t,i,a)}),[Symbol.asyncDispose]:async()=>void 0})},shutdown:async()=>void 0})}function J(e,t,n){let r={device:t.device,signal:t.scope.signal,resolveInteractor:e.localInteractors.resolve};return v({...r,facts:n.operations,pause:async n=>await e.clock.sleep(n,t.scope.signal)})}function Y(e){let t=e.kind===`device`?S:L,n=e.kind===`device`?S:R,r=g(e,C,{appLog:w,network:w,screenshot:B,snapshot:z,viewport:w,focus:E,gesture:O,scroll:k,typeText:D,touch:E,elementText:T,back:H,orientation:G,tvRemote:G,clipboard:W,systemButton:G,fold:G,triggerAppEvent:G,settings:G,readAlert:G,awaitAlert:G,acceptAlert:G,dismissAlert:G,keyboard:G,audioProbeCapture:K,audioProbeQuery:K,perf:G,readiness:w,lifecycle:i({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:P,clearRuntimeHints:P,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:F,configureProviderPortReverse:I})});return Object.freeze({device:r.device,operations:{...r.operations,...s({capture:X(e,z),customActions:V,withoutActiveApp:X(e,z)}),...ee({capture:X(e,B)}),...m({focus:X(e,E)}),...c({unsupported:O,plan:X(e,O),directionalFling:A,multiTouch:j,targetAuthoredDrag:M,viewport:N}),...l({scroll:X(e,k)}),...a({type:X(e,D)}),...Z(e),...o({readTextAtPoint:X(e,T)}),...p({back:X(e,H)}),...d({unsupported:G,home:X(e,U)}),...f({unsupported:W,read:X(e,W),write:X(e,W)})}})}function X(e,t){return e.kind===`device`?S:t}function Z(e){let t=e.kind===`device`?S:E;return h({unsupported:w,tap:t,longPress:t,fill:t})}function Q(e,t){let n=async n=>await e.snapshot.captureSurface(t.device,n.options,u(t.scope.signal,n));return Object.freeze({captureSnapshot:n,captureSnapshotWithCustomActions:n,captureSnapshotWithoutActiveApp:n})}function $(e,t){return Object.freeze(t===void 0?{available:!1,reason:e}:{available:!1,reason:e,hint:t})}export{q as createLinuxPlatformRuntime};
|
package/dist/src/runtime8.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{A as e}from"./sdk-contracts.js";import{Yt as t,en as n}from"./sdk-batch.js";import{n as r,t as i}from"./application-lifecycle-runtime.js";import{I as a,d as o,w as s,x as c}from"./alert-runtime.js";import{r as l}from"./platform-runtime-unavailable.js";import{i as u}from"./gesture-admission.js";import{t as d}from"./interactor-operation-catalog.js";import{n as f,t as p}from"./application-lifecycle-interaction.js";function m(e){return p({owner:`Vega`,openTargetIdentity:`app-name`,binding:f({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const h=t(`vega`),g=Object.freeze({available:!0}),_=W(`unsupported-platform-leaf`),v=W(`unsupported-platform-leaf`,`Runtime hints are supported only for local iOS-family simulators and Android devices.`),y=W(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),b=W(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),x=W(`unsupported-device-kind`,`open currently supports only Vega Virtual Devices.`),S=W(`unsupported-device-kind`,`close currently supports only Vega Virtual Devices.`);function C(t){return Object.freeze({owner:h,ownsDevice:e=>e.platform===`vega`,inspectFacts:async e=>U(e),bind:async i=>{if(i.intent.kind===`exact-owner`&&!n(i.intent.owner,h))throw new e(`UNSUPPORTED_OPERATION`,`Vega runtime owner identity does not match`);if(i.device.platform!==`vega`)throw new e(`UNSUPPORTED_PLATFORM`,`Vega runtime cannot bind this device`);let a=U(i.device),o=m({host:t.localInteractors,device:i.device,signal:i.scope.signal});return Object.freeze({device:i.device,owner:h,facts:a,operations:Object.freeze({...r(o,a.operations),...d({device:i.device,signal:i.scope.signal,resolveInteractor:t.localInteractors.resolve,facts:a.operations})}),[Symbol.asyncDispose]:async()=>void 0})},shutdown:async()=>void 0})}const w=W(`unsupported-platform-leaf`,`screenshot is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),T=W(`unsupported-platform-leaf`,`focus is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),E=W(`unsupported-platform-leaf`,`type is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),D=W(`unsupported-platform-leaf`,`Gestures are not supported on Vega OS: the Vega runtime exposes remote navigation only.`),O=W(`unsupported-platform-leaf`,`scroll is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),k=W(`unsupported-platform-leaf`),A=W(`unsupported-platform-leaf`,u),j=W(`unsupported-platform-leaf`,`orientation is not supported on Vega OS.`),M=W(`unsupported-platform-leaf`,`keyboard is not supported on Vega OS.`),N=W(`unsupported-platform-leaf`,`alert is not supported on Vega OS.`),P=W(`unsupported-platform-leaf`,`settings is not supported on Vega OS.`),F=W(`unsupported-platform-leaf`,`trigger-app-event is not supported on Vega OS.`),I=W(`unsupported-platform-leaf`,`System buttons other than home are not supported on Vega OS.`),L=W(`unsupported-platform-leaf`,`fold is not supported on Vega OS.`),R=W(`unsupported-platform-leaf`,`clipboard is not supported on Vega OS.`),z=W(`unsupported-device-kind`,`back currently supports only Vega Virtual Devices.`),B=W(`unsupported-device-kind`,`home currently supports only Vega Virtual Devices.`),V=W(`unsupported-device-kind`,`tv-remote currently supports only Vega Virtual Devices.`),H=W(`unsupported-platform-leaf`,`audio is supported for web browser sessions, macOS sessions, iOS simulators, and Android emulators on macOS hosts`);function U(e){let t=e.kind===`emulator`&&e.target===`tv`,n=t?g:x,r=t?g:S,u=l(e,h,{appLog:_,network:_,screenshot:w,snapshot:_,viewport:_,focus:T,gesture:D,scroll:O,typeText:E,touch:_,elementText:_,back:z,orientation:j,tvRemote:V,clipboard:R,systemButton:I,fold:L,triggerAppEvent:F,settings:P,readAlert:N,awaitAlert:N,acceptAlert:N,dismissAlert:N,keyboard:M,audioProbeCapture:H,audioProbeQuery:H,perf:_,readiness:_,lifecycle:i({resolveOpenTarget:n,prepareApplicationOpen:n,openApplication:n,applyRuntimeHints:v,clearRuntimeHints:v,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:y,configureProviderPortReverse:b})});return Object.freeze({device:u.device,operations:{...u.operations,...s({back:t?g:z}),...o({unsupported:I,home:t?g:B}),...c({tvRemote:t?g:V}),...a({unsupported:D,multiTouch:k,targetAuthoredDrag:A})}})}function W(e,t){let n={available:!1,reason:e,...t===void 0?{}:{hint:t}};return Object.freeze(n)}export{C as createVegaPlatformRuntime};
|
package/dist/src/runtime9.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{A as e}from"./sdk-contracts.js";import{Yt as t,en as n,tn as r}from"./sdk-batch.js";import{n as i,t as a}from"./application-lifecycle-runtime.js";import{A as o,B as s,C as c,D as l,G as u,H as d,I as ee,J as f,K as te,L as ne,N as p,O as m,V as h,d as re,h as g,j as _,n as v,o as ie,s as y,v as b,w as x,x as S,z as C}from"./alert-runtime.js";import{n as w}from"./audio-probe-runtime.js";import{n as T}from"./perf-runtime.js";import{i as E,t as D}from"./touch-runtime.js";import{i as O}from"./gesture-admission.js";import{n as k,t as A}from"./application-lifecycle-interaction.js";import{n as j,r as M,t as N}from"./screen-recording-transport.js";async function P(e){let{host:t,device:n,owner:r,signal:i}=e,a=await t.screenRecording.web.resolve(n);return a?{available:!0,operations:{screenRecordingStart:async e=>(F(e),await N({host:t,device:n,owner:r,input:e,signal:i,transport:{backend:`agent-browser`,targetLabel:`web recording`,start:async t=>await a.start(e.outputPath,t),stop:async()=>await a.stop()},support:{scopes:[`app`],fps:!1,exportQuality:!1,hideTouches:!1},unsupported:e=>`web recordings do not support ${e.join(`, `)}; agent-browser records WebM directly`})),screenRecordingReattach:async()=>M(`Web recordings cannot be reattached after daemon restart.`),screenRecordingCleanup:async()=>j(`Web recordings cannot be cleaned after daemon restart.`)}}:{available:!1,operations:{}}}function F(t){if(t.recordOnlySession)throw new e(`INVALID_ARGS`,`record on web requires an active browser session; run open <url> --platform web first`);if(!t.outputPath.toLowerCase().endsWith(`.webm`))throw new e(`INVALID_ARGS`,`web recordings require a .webm output path; agent-browser records WebM directly`)}function I(e){return A({owner:`web`,openTargetIdentity:`app-name`,binding:k({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const L=t(`web`),R=Object.freeze({available:!0}),z=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Web targets read element text from the captured tree only.`}),B=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),V=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`record is not supported by this web provider`}),H=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Re-run without --actions, or target an iOS simulator.`}),U=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),W=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`apps is not supported on web targets.`}),G=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),K=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),q=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple runner preparation is supported only for Apple targets.`}),J=Object.freeze({available:!1,reason:`owner-capability-missing`}),Y=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`A web click is one immediate pointer press; the browser backend has no timed hold.`}),ae=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`audio on web sessions is the stateless page probe; host capture is a macOS-host operation.`});function X(e,t){return typeof e==`function`?t:J}function Z(e,t){return e?R:t}const oe=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),se=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:O}),Q=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`open is supported only for web browser devices.`}),ce=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`close is supported only for web browser devices.`}),le=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`});function ue(e){let t=de(e),n=fe(e);return a({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:U,clearRuntimeHints:U,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:q,configureProviderPortReverse:le})}function de(e){return e.kind===`device`?R:Q}function fe(e){return e.kind===`device`?R:ce}function pe(t){return Object.freeze({owner:L,ownsDevice:e=>e.platform===`web`,inspectFacts:async e=>{let n=await t.networkTransports.resolve(e),r=await P({host:t,device:e,owner:L,signal:new AbortController().signal}),i=e.kind===`device`?await t.localInteractors.resolve(e,{}):void 0;return $(e,n,r.available,i)},bind:async r=>{if(r.intent.kind===`exact-owner`&&!n(r.intent.owner,L))throw new e(`UNSUPPORTED_OPERATION`,`Web runtime owner identity does not match`);if(r.device.platform!==`web`)throw new e(`UNSUPPORTED_PLATFORM`,`Web runtime owner cannot bind ${r.device.platform}`);let i=await t.networkTransports.resolve(r.device),a=await P({host:t,device:r.device,owner:L,signal:r.scope.signal}),o=r.device.kind===`device`?await t.localInteractors.resolve(r.device,{signal:r.scope.signal}):void 0;return me(t,r.device,r.scope.signal,i,a,$(r.device,i,a.available,o))},shutdown:async()=>void 0})}function me(t,n,a,o,s,c){let l=o.dump,u={...l?{networkDump:async e=>{let t=await l({maxEntries:e.maxEntries,include:e.include},a);return Object.freeze({source:`provider`,...t})}}:{},...s.operations,...c.operations.captureSnapshot.available?d({device:n,signal:a,resolveInteractor:t.localInteractors.resolve}):{},...c.operations.captureScreenshot.available?te({device:n,signal:a,resolveInteractor:t.localInteractors.resolve}):{},...c.operations.focusPoint.available?ne({device:n,signal:a,resolveInteractor:t.localInteractors.resolve}):{},...c.operations.typeText.available?m({device:n,signal:a,resolveInteractor:t.localInteractors.resolve}):{},...r(c.operations.tapPoint,()=>D({device:n,signal:a,resolveInteractor:t.localInteractors.resolve,facts:c.operations,pause:async e=>await t.clock.sleep(e,a)})),...c.operations.scrollDirection.available?_({device:n,signal:a,resolveInteractor:t.localInteractors.resolve}):{},...c.operations.setViewport.available?{setViewport:async r=>{a.throwIfAborted();let i=await t.localInteractors.resolve(n,{signal:a});if(!i.setViewport)throw new e(`UNSUPPORTED_OPERATION`,`viewport is not supported by the bound web interactor`);await i.setViewport(r.width,r.height),a.throwIfAborted()}}:{},...r(c.operations.audioProbeQuery,()=>({audioProbeQuery:async r=>{let i=await t.audioProbe.web.resolve(n);if(i===void 0)throw new e(`UNSUPPORTED_OPERATION`,`audio is not supported by this web provider`);return await i.probe(r)}})),...i(I({host:t.localInteractors,device:n,signal:a}),c.operations)};return Object.freeze({device:n,owner:L,facts:c,operations:Object.freeze(u),[Symbol.asyncDispose]:async()=>void 0})}function $(e,t,n,r){let i=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`network is not supported by this web provider`}),a=Z(e.kind===`device`,Q);return Object.freeze({device:{family:`web`,kind:e.kind,...e.target===void 0?{}:{target:e.target},providerMode:t.mode},operations:{appLogInspect:B,appLogDoctor:B,appLogStart:B,appLogReattach:B,appLogCleanup:B,appState:G,networkDump:Z(!!t.dump,i),screenRecordingStart:Z(n,V),screenRecordingReattach:Z(n,V),screenRecordingCleanup:Z(n,V),...u({capture:a,customActions:H,withoutActiveApp:a}),...h({findText:Q}),...f({capture:a}),...C({focus:a}),...o({type:a}),...E({unsupported:U,tap:a,tapRef:X(r?.tapRef,a),longPress:Y,hover:X(r?.hover,a),hoverRef:X(r?.hoverRef,a),fill:a,fillRef:X(r?.fillRef,a)}),...p({scroll:a}),...ee({unsupported:oe,targetAuthoredDrag:se}),...s({setViewport:a}),...l({readTextAtPoint:z}),...x({back:K}),...c({orientation:K}),...S({tvRemote:K}),...b({unsupported:K}),...g({unsupported:K}),...w({capture:ae,query:R}),...T({frames:K,memorySample:K,memorySnapshot:K,nativeCapture:K,profileReport:K}),...re({unsupported:K}),setFoldPose:K,...y({triggerAppEvent:K}),...ie({setSetting:K,readSetting:K}),...v({read:K,wait:K,accept:K,dismiss:K}),ensureReady:U,bootTarget:U,bootTargetHeadless:U,listApps:W,deployApp:U,materializeAppSource:U,deployMaterializedApp:U,sendPushNotification:U,shutdownTarget:U,...ue(e)}})}export{pe as createWebPlatformRuntime};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{A as e}from"./sdk-contracts.js";import{D as t,O as n}from"./sdk-device.js";function r(r){let i=r.now??Date.now,a=r.undurableCleanupTtlMs??3e5,o=new Map;return Object.freeze({blockUndurableCleanup(e,r){let s=t(e);o.set(n(s),{device:s,reason:r,expiresAt:i()+a})},clearUndurableCleanup(e){o.delete(n(t(e)))},assertStartAllowed(a){let s=n(t(a)),c=o.get(s);if(c){if(i()>c.expiresAt){o.delete(s),r.onUndurableCleanupExpired?.({device:c.device,reason:c.reason});return}throw new e(`COMMAND_FAILED`,`The existing ${r.displayName.toLowerCase()} resource has process-local unconfirmed ownership`,{reason:`cleanup-unconfirmed`,hint:`Do not start a replacement in this daemon process: ${c.reason}`})}}})}function i(){return r({displayName:`screen recording`})}export{r as n,i as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{A as e}from"./sdk-contracts.js";import{t}from"./durable-resource.js";function n(e,t){let n=r(e),a,o=!1,s,c,l=()=>o||s!==void 0,u=e=>(o=!0,a??=t.finish(n,e).catch(e=>{throw a=void 0,e}),a),d=()=>s??=a?a.then(async e=>e.status===`completed`?{status:`cleaned`}:await t.forceCleanup(n),async()=>await t.forceCleanup(n)):t.forceCleanup(n);return Object.freeze({inspect:()=>n,appendGestureEvents:e=>{e.length===0||l()||(n=r({...n,gestureEvents:[...n.gestureEvents,...e]}))},setTouchReferenceFrame:e=>{l()||(n=r({...n,...e?{touchReferenceFrame:e}:{}}))},setRunnerSessionId:e=>{l()||e.trim().length===0||(n=r({...n,runnerSessionId:e}))},invalidate:e=>{l()||n.invalidatedReason||(n=r({...n,invalidatedReason:e}))},finish:u,forceCleanup:d,[Symbol.asyncDispose]:async()=>{c??=d().then(i),await c}})}function r(e){return Object.freeze({...e,gestureEvents:Object.freeze([...e.gestureEvents])})}function i(n){if(!t(n))throw new e(`COMMAND_FAILED`,n.message??`Screen recording cleanup could not be confirmed`,{reason:n.reason,retriable:n.reason!==`ownership-fence-lost`,hint:n.reason===`ownership-fence-lost`?`Use the current recording owner or recovery record before retrying cleanup.`:`Keep the recovery record and retry cleanup through the exact runtime owner.`})}function a(e,t,n){let{stopObservation:r,nativePathDisposition:i,showTouches:a=e.showTouches}=n;return Object.freeze({status:`completed`,result:Object.freeze({backend:e.backend,outPath:e.outPath,...e.clientOutPath===void 0?{}:{clientOutPath:e.clientOutPath},startedAt:e.startedAt,completedAt:Date.now(),stopObservation:r,...i===void 0?{}:{nativePathDisposition:i},scope:e.scope,showTouches:a,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},...t})})}export{n,a as t};
|