agent-device 0.21.11 → 0.21.13
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.11.apk → agent-device-android-ime-helper-0.21.13.apk} +0 -0
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.13.apk.sha256 +1 -0
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.11.manifest.json → agent-device-android-ime-helper-0.21.13.manifest.json} +4 -4
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.11.apk → 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 +1 -0
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.11.manifest.json → agent-device-android-snapshot-helper-0.21.13.manifest.json} +6 -6
- package/apple/fold-helper/Fold.m +97 -0
- package/apple/macos-helper/Package.swift +3 -6
- package/apple/macos-helper/Sources/AgentDeviceMacOSHelper/main.swift +3 -8
- package/apple/macos-helper/Tests/AgentDeviceMacOSHelperTests/ScreenshotResponseTests.swift +15 -0
- package/apple/snapshot-bridge/SnapshotBridgeRuntime.m +47 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerApp.m +99 -42
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunner/Info.plist +23 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunner.xcodeproj/project.pbxproj +17 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAppScreenCapture.swift +21 -13
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerScrollViewportPolicy.swift +1 -162
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.h +0 -9
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.m +0 -56
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSystemSurfaceHostPolicy.swift +0 -48
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTapPointPolicy.swift +0 -50
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AXSnapshotFallback.swift +22 -568
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Alert.swift +21 -9
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+BlockingSystemModalResolution.swift +0 -36
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandDispatch.swift +630 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +18 -2236
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandJournal.swift +1 -338
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Environment.swift +0 -12
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+GestureExecution.swift +165 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +0 -24
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Keyboard.swift +0 -142
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Lifecycle.swift +90 -39
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+MainThreadWork.swift +78 -106
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +23 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Navigation.swift +147 -95
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+PrivateAXPresentation.swift +0 -209
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScreenRecorder.swift +86 -10
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScrollDragExecution.swift +287 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScrollGesture.swift +1 -200
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SequenceExecution.swift +0 -185
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift +75 -285
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotAcquisition.swift +23 -10
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotBackendCapabilities.swift +0 -78
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotCapturePlan.swift +83 -578
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotCaptureTarget.swift +106 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotExecution.swift +142 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotTiming.swift +49 -78
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedCommitDeadline.swift +0 -44
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedGesturePolicy.swift +27 -97
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedInteraction.swift +1 -11
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedTextEntry.swift +11 -87
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SystemModal.swift +2 -10
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntry.swift +1 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryFocus.swift +0 -35
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextInputCandidatePolicy.swift +0 -31
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextTyping.swift +2 -18
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Transport.swift +34 -52
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TvRemote.swift +0 -22
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TypeExecution.swift +142 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +22 -6
- package/dist/apple/runner/AgentDeviceRunner/RecordingScripts/recording-overlay.swift +140 -20
- package/dist/src/absence-observation-errors.js +1 -1
- package/dist/src/adapter.js +1 -1
- package/dist/src/agent-device-client.js +1 -1
- package/dist/src/alert-runtime.js +1 -1
- package/dist/src/android-adb.d.ts +1 -1
- package/dist/src/app-launch.js +2 -2
- package/dist/src/app-log-runtime2.js +3 -3
- package/dist/src/app-resolution.js +2 -2
- package/dist/src/back-mode.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 +10 -7
- package/dist/src/cli-runner.js +1 -1
- package/dist/src/cli.js +1 -1
- package/dist/src/client-types.d.ts +5 -8
- package/dist/src/code-signature.js +1 -1
- package/dist/src/command-schema.js +3 -3
- package/dist/src/command-tools.js +3 -3
- package/dist/src/connection.js +1 -1
- package/dist/src/daemon-client-lifecycle.js +1 -1
- package/dist/src/daemon-resolution.js +1 -1
- package/dist/src/device-claim-rule.js +2 -2
- package/dist/src/device-input-state.d.ts +1 -1
- package/dist/src/device-rotation.js +1 -1
- package/dist/src/device-session.js +1 -1
- package/dist/src/devicectl.js +1 -1
- package/dist/src/display-inventory.js +1 -1
- package/dist/src/doctor-facade.js +1 -1
- package/dist/src/find.js +1 -1
- package/dist/src/gesture-plan-types.d.ts +38 -0
- package/dist/src/harmonyos.js +1 -1
- package/dist/src/helper.js +2 -2
- package/dist/src/host.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-ref-policy.js +1 -1
- package/dist/src/interaction2.js +1 -1
- package/dist/src/interactor-operation-catalog.js +1 -1
- package/dist/src/interactor.js +4 -4
- package/dist/src/interactor2.js +1 -1
- package/dist/src/internal/bin.js +1 -1
- package/dist/src/internal/daemon.js +2 -2
- package/dist/src/inventory2.js +1 -1
- package/dist/src/ios-snapshot-acquisition.js +1 -1
- package/dist/src/ios-snapshot-runtime.js +1 -1
- package/dist/src/limrun-runtime-dependencies.js +1 -1
- package/dist/src/limrun.d.ts +435 -4
- package/dist/src/linux.js +1 -1
- package/dist/src/local-interactor-operation-set.js +1 -1
- package/dist/src/macos-facade.js +1 -1
- package/dist/src/managed-device-scope.js +1 -1
- package/dist/src/mechanics.js +4 -4
- package/dist/src/mobile-snapshot-semantics.js +1 -1
- package/dist/src/perf-facade.js +1 -2
- package/dist/src/perf-runtime-plan.js +1 -1
- package/dist/src/perf-target.js +2 -0
- package/dist/src/physical-device-apps.js +1 -0
- package/dist/src/physical-device-control.js +1 -1
- package/dist/src/platform-request-scope.js +1 -1
- package/dist/src/platform-runtime-operation-host.js +1 -1
- package/dist/src/platform-runtime-screen-recording-finalizer-host.js +1 -1
- package/dist/src/platform-runtime-unavailable.js +1 -1
- package/dist/src/platform-runtime.js +1 -1
- package/dist/src/platform-runtime2.js +1 -1
- package/dist/src/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/registry.js +35 -35
- package/dist/src/request-admission.js +1 -1
- package/dist/src/request-runtime-binding.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 +3 -0
- package/dist/src/runner-operations-facade.js +1 -1
- package/dist/src/runner-presentation.js +1 -1
- package/dist/src/runner.js +1 -1
- package/dist/src/runtime.js +3 -3
- package/dist/src/runtime10.js +1 -1
- package/dist/src/runtime2.js +2 -2
- 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-resource-recovery.js +1 -1
- package/dist/src/screen-recording-transport.js +1 -1
- package/dist/src/screenshot-runtime.js +1 -1
- package/dist/src/screenshot3.js +1 -1
- package/dist/src/script.js +1 -1
- package/dist/src/scroll-command.d.ts +377 -0
- package/dist/src/scroll-command.js +1 -1
- package/dist/src/sdk-batch.js +2 -2
- package/dist/src/sdk-contracts.d.ts +9 -0
- package/dist/src/sdk-device.js +1 -1
- package/dist/src/sdk-selectors.d.ts +23 -715
- package/dist/src/selection.js +0 -0
- package/dist/src/selector-runtime.js +1 -1
- package/dist/src/semantic-index.js +1 -1
- package/dist/src/server.js +1 -1
- package/dist/src/session-observation.js +1 -1
- package/dist/src/session-snapshot.js +1 -1
- package/dist/src/session2.js +2 -2
- package/dist/src/simctl-facade.js +1 -1
- package/dist/src/simctl.js +1 -1
- package/dist/src/simulator-facade.js +1 -1
- package/dist/src/simulator-state.js +1 -1
- package/dist/src/simulator.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/snapshot4.js +1 -1
- package/dist/src/src7.js +1 -1
- package/dist/src/text-entry-focus.js +1 -1
- package/dist/src/tool-provider.js +1 -1
- package/dist/src/touch-runtime.js +1 -1
- package/dist/src/tree.js +1 -1
- package/dist/src/update-check.js +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/web2.js +1 -1
- package/package.json +4 -2
- package/server.json +2 -2
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.11.apk.sha256 +0 -1
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.11.apk.sha256 +0 -1
- package/apple/macos-helper/Sources/AgentDeviceMacOSDeviceHub/DeviceHubPose.swift +0 -47
- package/apple/macos-helper/Sources/AgentDeviceMacOSDeviceHub/DeviceHubWindowInventory.swift +0 -65
- package/apple/macos-helper/Sources/AgentDeviceMacOSHelper/DeviceHubPose.swift +0 -225
- package/apple/macos-helper/Sources/AgentDeviceMacOSHelper/DeviceHubSidebar.swift +0 -57
- package/apple/macos-helper/Sources/AgentDeviceMacOSHelper/DeviceHubWindowDiscovery.swift +0 -108
- package/apple/macos-helper/Tests/AgentDeviceMacOSDeviceHubTests/DeviceHubPoseTests.swift +0 -30
- package/apple/macos-helper/Tests/AgentDeviceMacOSDeviceHubTests/DeviceHubWindowInventoryTests.swift +0 -65
- package/dist/src/app-inventory.d.ts +0 -4
- package/dist/src/apps-simctl.js +0 -1
- package/dist/src/cloud-artifacts.d.ts +0 -61
- package/dist/src/runner-contract.js +0 -3
package/dist/src/runtime2.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{D as e}from"./sdk-contracts.js";import{
|
|
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{i as a,n as o}from"./recording-stop-observation.js";import{n as s,r as c,t as l}from"./application-lifecycle-runtime.js";import{A as u,B as d,C as f,D as p,G as m,H as h,I as g,J as ee,N as _,V as te,d as ne,h as re,n as ie,o as ae,s as oe,v as se,w as ce,x as le,z as ue}from"./alert-runtime.js";import{n as de}from"./audio-probe-runtime.js";import{n as fe}from"./perf-runtime.js";import{i as pe}from"./touch-runtime.js";import{a as me,n as he}from"./durable-resource.js";import{n as ge}from"./async-lifecycle.js";import{i as _e,l as ve,n as ye,r as be,t as xe}from"./src7.js";import{n as Se}from"./screen-recording-completion.js";import{a as Ce,i as v,o as we,s as Te,t as Ee}from"./stop-sequence.js";import{n as De}from"./screen-recording-runtime.js";import{readAndroidAppStateWithExecutor as Oe}from"./app-state.js";import{ANDROID_CLIPBOARD_SHELL_COMMAND_UNAVAILABLE_HINT as ke}from"./clipboard-shell-response.js";import{i as Ae,t as je}from"./gesture-admission.js";import{t as Me}from"./local-interactor-operation-set.js";import{a as Ne,i as Pe,n as Fe,r as Ie,t as Le}from"./perf-runtime-operation-builder.js";import{t as Re}from"./app-log-runtime.js";import{t as ze}from"./mp4-duration.js";import{n as y,r as Be}from"./managed-device-scope.js";import{a as Ve,i as He,n as Ue,o as We}from"./application-lifecycle-interaction.js";import b from"node:path";function Ge(e){return Ce(e)?Object.freeze({available:!0}):e.kind===`emulator`?Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`audio probe capture requires a macOS host.`}):Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`audio probe capture is supported for Android emulators on macOS hosts.`})}function Ke(e){let{resolveHost:t,device:n,owner:r}=e;return Object.freeze({...Le({platform:`Android`,expectedProfileKind:`simpleperf`,start:async e=>await t().start(n,r,e),reattach:async e=>await t().reattach(n,e),cleanup:async e=>await t().cleanup(n,e),writeProfileReport:async e=>await t().writeProfileReport(n,e)}),perfFrames:async({appId:e})=>({metric:e?await Pe(t().sampleFrames(n,e)):Fe(`Android`,`package`),sampling:{method:`adb-shell-dumpsys-gfxinfo-framestats`,description:`Rendered-frame health from the current adb shell dumpsys gfxinfo <package> framestats window. Dropped frames use Android gfxinfo janky-frame/frame-deadline data when available; this is not video recording FPS.`,unit:`percent`,primaryField:`droppedFramePercent`,window:`since previous Android gfxinfo reset or app process start`,resetsAfterRead:!0,relatedActionsLimit:12}}),perfMemorySample:async({appId:e})=>({metric:e?await Pe(t().sampleMemory(n,e)):Fe(`Android`,`package`),sampling:{method:`adb-shell-dumpsys-meminfo`,description:`Memory snapshot from adb shell dumpsys meminfo <package>. Values are reported in kilobytes.`,unit:`kB`,topConsumerLimit:5}}),perfMemorySnapshot:async({appId:e,kind:r,outPath:i,artifactsDir:a})=>{let o=r??`android-hprof`,s=qe();if(o!==`android-hprof`)return Ne(`Android`,o,s,`Use perf memory snapshot --kind android-hprof for Android Java heap artifacts.`);if(!e)throw Ie();let c=i??b.join(a,`memory-android-hprof-${Je()}.hprof`);return{artifact:await t().captureMemorySnapshot(n,e,c),support:s,sampling:{method:`adb-shell-am-dumpheap`,description:`Java heap dump captured with adb shell am dumpheap, pulled to a local artifact path.`,defaultKind:`android-hprof`,artifactOnly:!0}}}})}function qe(){return{platform:`android`,defaultKind:`android-hprof`,androidHprof:!0,memgraph:!1,heapprofd:!1,heapprofdDecision:`Deferred until Android Perfetto/heapprofd plumbing is available in the perf trace slice.`}}function Je(){return new Date().toISOString().replaceAll(/[:.]/g,`-`)}function Ye(t){if(!/^[a-zA-Z0-9._:-]+$/.test(t))throw new e(`INVALID_ARGS`,`Invalid Android package name for logs: ${t}`)}const x=Object.freeze({resourceKind:Re,version:1,encode:e=>({...e}),decode:e=>e.transport!==`android-logcat-local`&&e.transport!==`android-logcat-transport-composed`||!Ze(e.outputPath)||!Ze(e.pidPath)?{status:`invalid`,message:`Invalid Android app-log descriptor`}:{status:`decoded`,descriptor:Object.freeze({transport:e.transport,outputPath:e.outputPath,pidPath:e.pidPath})}});function Xe(e){let t=x.decode(e.descriptor);if(t.status!==`decoded`)throw TypeError(t.message);return he({resourceKind:Re,sessionId:e.sessionId,device:{id:e.device.id,family:`android`,kind:e.device.kind,...e.device.target===void 0?{}:{target:e.device.target}},owner:e.owner,fence:e.fence,lifecycle:`open`,descriptor:me(x,t.descriptor)})}function Ze(e){return typeof e==`string`&&e.trim().length>0}function Qe(e){return be(e,{family:`android`,backend:`android`,label:`Android`,codec:x,startUnavailableHint:`The selected Android transport cannot start a background adb logcat stream.`,cleanupFailureMessage:`Android app-log cleanup did not settle every owned resource`,doctor:async({host:e,device:t,signal:n},r)=>await $e(e,t.id,r,n),validateStart:({input:e})=>Ye(e.appBundleId),process:async({host:e,device:t,input:n})=>({resolvePid:async r=>await _e(e,et(t.id,n.appBundleId),r),command:e=>({kind:`android-adb`,serial:t.id,args:[`logcat`,`-v`,`time`,`--pid`,e],options:{allowFailure:!0}})}),descriptor:({artifacts:e,transport:t})=>({transport:t.mode===`transport-composed`?`android-logcat-transport-composed`:`android-logcat-local`,...e}),envelope:({input:e,device:t,owner:n,descriptor:r})=>Xe({sessionId:e.sessionId,device:t,owner:n,fence:e.fence,descriptor:r})})}async function $e(e,t,n,r){let a={};return a.adbAvailable=await Te(async()=>we(await e.commands.run({executable:`adb`,args:i(`adb`,`shell`,[`echo`,`ok`],[`-s`,t]),allowFailure:!0,timeoutMs:1e3},r)),r),n&&(a.androidPidVisible=await Te(async()=>!!await _e(e,et(t,n),r),r)),{backend:`android`,checks:a,notes:n?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`]}}function et(e,t){return{executable:`adb`,args:i(`adb`,`shell`,[`pidof`,t],[`-s`,e]),allowFailure:!0,timeoutMs:5e3}}async function tt(e,t,n,r){let i=await e.appLogs.readRecent(n.sessionId,n.maxScanLines),a=ye(i.text,{...n,path:i.path,exists:i.exists,lineNumberOffset:i.skippedLines,backend:`android`}),o=[],s=await rt(e,t,n,r);if(s&&n.appBundleId){Ye(n.appBundleId);let c=await at(e,t,n.appBundleId,r);if(c){let e=ye(c.text,{...n,path:`${i.path} (adb logcat recovery)`,exists:!0,backend:`android`});e.dump.entries.length>0&&(a=xe(e,a,n.maxEntries),o.push(s.reason===`stale-active`?`Session app log stream was still bound to prior Android PID ${s.trackedPid}. Recovered recent Android HTTP entries from adb logcat for PID set ${c.pids.join(`, `)}.`:`Session app log stream was inactive. Recovered recent Android HTTP entries from adb logcat for PID set ${c.pids.join(`, `)}.`))}}return n.appLogSnapshot?n.appLogSnapshot.state!==`active`&&o.length===0&&o.push(`Session app log stream is inactive. Run logs clear --restart, reproduce the request window again, then rerun network dump.`):o.push(`Capture uses the session app log file. For fresh traffic, run logs clear --restart before reproducing requests.`),a.dump.entries.length===0&&o.push(`No HTTP(s) entries were found in recent session app logs.`),Object.freeze({source:`app-log`,backend:`android`,dump:a.dump,notes:Object.freeze(o)})}async function nt(e,t,n){n.throwIfAborted();try{let r=await e.commands.run(t,n);return n.throwIfAborted(),r}catch{n.throwIfAborted();return}}async function rt(e,t,n,r){if(!n.appBundleId||n.appLogSnapshot?.state===void 0)return;if(n.appLogSnapshot.state!==`active`)return{reason:`inactive`};let i=it(await e.appLogs.readProcessMarker(n.sessionId));if(!i)return;let a=await ot(e,t.id,n.appBundleId,r);if(!(!a||a===i))return{reason:`stale-active`,trackedPid:i}}function it(e){if(e.status===`decoded`)return/(?:^|\s)--pid\s+(\d+)(?:\s|$)/.exec(e.marker.command)?.[1]}async function at(e,t,n,r){let i=await ot(e,t.id,n,r),a=await nt(e,{executable:`adb`,args:[`-s`,t.id,`logcat`,`-d`,`-v`,`time`,`-t`,`4000`],allowFailure:!0,timeoutMs:3e3},r);if(!a||a.exitCode!==0||!a.stdout.trim())return;let o=st(a.stdout,n,i);if(o.length===0)return;let s=new Set(o),c=a.stdout.split(`
|
|
2
2
|
`).filter(e=>{if(!e.trim())return!1;if(e.includes(n))return!0;let t=/\(\s*(\d+)\)\s*:/.exec(e)?.[1];return!!(t&&s.has(t))}).join(`
|
|
3
3
|
`);return c.trim()?{text:c,pids:o}:void 0}async function ot(e,t,n,r){let a=await nt(e,{executable:`adb`,args:i(`adb`,`shell`,[`pidof`,n],[`-s`,t]),allowFailure:!0},r);if(!a)return;let o=a.stdout.trim().split(/\s+/)[0];return o&&/^\d+$/.test(o)?o:void 0}function st(e,t,n){let r=new Set(n?[n]:[]),i=t.replaceAll(/[.*+?^${}()|[\]\\]/g,String.raw`\$&`),a=[RegExp(`\\bStart proc\\s+(\\d+):${i}(?:\\b|/)`,`i`),RegExp(`\\b(\\d+):${i}(?:\\b|/)`,`i`),RegExp(`${i}.*?\\bpid\\s*[=:]?\\s*(\\d+)\\b`,`i`),RegExp(`\\bpid\\s*[=:]?\\s*(\\d+)\\b.*${i}`,`i`)];for(let n of e.split(`
|
|
4
4
|
`))if(n.includes(t))for(let e of a){let t=e.exec(n)?.[1];t&&/^\d+$/.test(t)&&r.add(t)}return Object.freeze([...r])}function S(e,t){if(t===1)return e;let n=b.parse(e);return b.join(n.dir,`${n.name}.part-${String(t).padStart(3,`0`)}${n.ext||`.mp4`}`)}const ct=/^(?:\/sdcard|\/data\/local\/tmp)\/agent-device-recording-\d{1,20}\.mp4$/,lt=/^(?:\/sdcard|\/data\/local\/tmp)\/agent-device-recording-active\.json$/;function ut(e){return pt(e)&&mt(e)&&ht(e)}function dt(e){if(!w(e))return!1;let t=e;return gt(t)&&_t(t)&&vt(t)&&yt(t)&&(t.completion===void 0||Et(t))}function ft(e,t){return Dt(e,t)&&C(e,t.outputPath,t.clientOutputPath)}function pt(e){return e.backend===`adb-screenrecord`&&typeof e.manifestPath==`string`&<.test(e.manifestPath)&&typeof e.outputPath==`string`}function mt(e){return kt(e.clientOutputPath)&&v(e)}function ht(e){return Ot(e.transportMode)}function gt(e){return e.version===1&&e.resourceKind===`screen-recording`&&typeof e.fenceToken==`string`&&Number.isInteger(e.fenceGeneration)&&typeof e.sessionId==`string`&&typeof e.deviceId==`string`&&Number.isFinite(e.startedAt)}function _t(e){return typeof e.outputPath==`string`&&kt(e.clientOutputPath)&&v(e)}function vt(e){return Ot(e.transportMode)&&(e.pendingRemotePath===void 0||At(e.pendingRemotePath))}function yt(e){return Array.isArray(e.chunks)&&e.chunks.every(bt)&&(e.chunks.length>0||e.pendingRemotePath!==void 0)&&(e.completion===void 0||xt(e.completion))}function bt(e,t){if(!w(e))return!1;let n=e;return n.index===t+1&&At(n.remotePath)&&jt(n.remotePid)&&jt(n.remoteStartTime)}function xt(e){if(!w(e))return!1;let t=e;return Ct(t)&&wt(t)&&St(t)&&(t.chunks===void 0||t.chunks.every(Tt))}function St(e){return(e.stopObservation===void 0||o(e.stopObservation))&&(e.nativePathDisposition===void 0||a(e.nativePathDisposition))}function Ct(e){return typeof e.backend==`string`&&typeof e.outPath==`string`&&(e.clientOutPath===void 0||typeof e.clientOutPath==`string`)&&Number.isFinite(e.startedAt)&&Number.isFinite(e.completedAt)&&(e.capturedDurationMs===void 0||Number.isFinite(e.capturedDurationMs))}function wt(e){return v(e)}function Tt(e,t){return e.index===t+1&&typeof e.path==`string`&&(e.clientOutPath===void 0||typeof e.clientOutPath==`string`)}function Et(e){let t=e.completion;return t!==void 0&&Dt(t,e)&&t.startedAt===e.startedAt&&C(t,e.outputPath,e.clientOutputPath,e.chunks.length)}function Dt(e,t){return e.backend===`adb screenrecord`&&e.outPath===t.outputPath&&e.clientOutPath===t.clientOutputPath&&e.scope===t.scope&&e.showTouches===t.showTouches&&e.recordOnlySession===t.recordOnlySession&&Mt(e.activeSessionApp,t.activeSessionApp)}function C(e,t,n,r=e.chunks===void 0?1:e.chunks.length){return r===1?e.chunks===void 0:e.chunks?.length===r&&e.chunks.every((e,r)=>e.path===S(t,r+1)&&e.clientOutPath===(n===void 0?void 0:S(n,r+1)))}function w(e){return typeof e==`object`&&!!e}function Ot(e){return e===`local`||e===`transport-composed`}function kt(e){return e===void 0||typeof e==`string`}function At(e){return typeof e==`string`&&ct.test(e)}function jt(e){return typeof e==`string`&&/^\d+$/.test(e)}function Mt(e,t){return JSON.stringify(e)===JSON.stringify(t)}const T=Object.freeze({resourceKind:De,version:1,encode:e=>({...e}),decode:e=>ut(e)?{status:`decoded`,descriptor:Object.freeze({backend:`adb-screenrecord`,manifestPath:e.manifestPath,outputPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutputPath:e.clientOutputPath},scope:e.scope,showTouches:e.showTouches,recordOnlySession:e.recordOnlySession,transportMode:e.transportMode,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},...e.exportQuality===void 0?{}:{exportQuality:e.exportQuality}})}:{status:`invalid`,message:`Invalid Android screen-recording descriptor`}});function E(e,t,n,r,i,a=`local`){return Object.freeze({version:1,resourceKind:`screen-recording`,fenceToken:t.fence.token,fenceGeneration:t.fence.generation,sessionId:t.sessionId,deviceId:e.id,startedAt:n,outputPath:t.outputPath,...t.clientOutputPath===void 0?{}:{clientOutputPath:t.clientOutputPath},scope:t.scope,showTouches:t.showTouches,recordOnlySession:t.recordOnlySession,...t.activeSessionApp===void 0?{}:{activeSessionApp:t.activeSessionApp},...t.exportQuality===void 0?{}:{exportQuality:t.exportQuality},chunks:r,...i===void 0?{}:{pendingRemotePath:i},transportMode:a})}function Nt(e,t){return Object.freeze({...e,completion:t})}function D(e){try{let t=e&&JSON.parse(e);return dt(t)?t:void 0}catch{return}}function Pt(e,t,n){return e.deviceId===t.id&&e.deviceId===n.device.id&&e.fenceToken===n.fence.token&&e.fenceGeneration===n.fence.generation&&e.sessionId===n.sessionId}function Ft(e,t){return e.outputPath===t.outputPath&&e.clientOutputPath===t.clientOutputPath&&e.scope===t.scope&&e.showTouches===t.showTouches&&e.recordOnlySession===t.recordOnlySession&&JSON.stringify(e.activeSessionApp)===JSON.stringify(t.activeSessionApp)&&e.exportQuality===t.exportQuality&&e.transportMode===t.transportMode&&(e.completion===void 0||ft(e.completion,t))}function O(e){switch(e){case`missing`:case`ownership-lost`:case`foreign-writer`:return!0;case`owned-alive`:case`uncertain`:return!1}}function It(e){switch(e){case`missing`:case`ownership-lost`:return!0;case`foreign-writer`:case`owned-alive`:case`uncertain`:return!1}}const Lt=1e4,Rt=1e3;var k=class extends Error{constructor(e){super(`Android screenrecord launch rollback could not be confirmed`,{cause:e})}};function A(e,t=Date.now()){return[...new Set(e?[e,`/sdcard`,`/data/local/tmp`]:[`/sdcard`,`/data/local/tmp`])].map(e=>`${e}/agent-device-recording-${t}.mp4`)}async function zt(e,t,n,r){let i;try{if(i=(await e.start({remotePath:t,quality:n.exportQuality??`medium`},r)).process,!/^\d+$/.test(i.pid)||!/^\d+$/.test(i.startTime)||i.remotePath!==t)throw Error(`Android screenrecord returned an invalid process identity`);if(!await Gt(e,t,i,r))throw Error(`Android screenrecord did not begin producing frames`);return{index:1,remotePath:t,remotePid:i.pid,remoteStartTime:i.startTime}}catch(t){throw i&&Bt(i)&&!await Kt(e,i)?new k(t):r?.aborted?r.reason:t}}function Bt(e){return/^\d+$/.test(e.pid)&&/^\d+$/.test(e.startTime)&&e.remotePath.length>0}async function j(e,t){let n=t.at(-1),r=!1,i;for(let a of[...t].reverse())try{let t=await N(e,a);a===n&&(r=t)}catch(e){i??=e}if(i)throw i;return r}async function Vt(e,t){for(let n of t){let t;for(let r=0;r<3;r+=1){let i=await e.size(n.remotePath);if(typeof i==`number`&&i>0&&i===t)break;if(t=typeof i==`number`&&i>0?i:void 0,r===2)throw Error(`Android recording artifact is not stable: ${n.remotePath}`);await new Promise(e=>setTimeout(e,250))}}}async function Ht(e,t,n){for(let[r,i]of t.entries())await qt(e,i.remotePath,S(n,r+1))}async function M(e,t){let n;for(let r of t)try{if(!await e.remove(r.remotePath))throw Error(`failed to remove Android recording artifact: ${r.remotePath}`)}catch(e){n??=e}if(n)throw n}async function Ut(e,t){for(let n of t)if(await e.exists(n.remotePath)!==!1)return`retirable`;return`retired`}async function Wt(e,t){try{await j(e,t)}finally{await M(e,t)}}async function Gt(e,t,n,r){for(let i=0;i<3;i+=1){if(r?.throwIfAborted(),await e.exists(t,r)===!0)return!0;if(await e.inspect(n,r)!==`owned-alive`)return!1;i<2&&await new Promise(e=>setTimeout(e,250))}return!0}async function Kt(e,t){try{let n=await e.stop(t,{force:!0});return(n===`stopped`||n===`already-missing`)&&await e.remove(t.remotePath)}catch{return!1}}async function N(e,t){if(!t)return!1;let n={pid:t.remotePid,remotePath:t.remotePath,startTime:t.remoteStartTime},r=await e.stop(n);if(r===`already-missing`)return!0;if(r===`ownership-lost`)throw Error(`Android screenrecord ownership could not be confirmed for pid ${t.remotePid}`);if(await Jt(e,n))return!1;let i=await e.stop(n,{force:!0});if(i===`stopped`||i===`already-missing`)return!1;throw Error(`failed to stop Android screenrecord pid ${t.remotePid}`)}async function qt(e,t,n){for(let r=0;r<3;r+=1){let i=await e.pullPlayable({remotePath:t,outputPath:n});if(i.exitCode===0&&i.playable)return;r+1<3&&await Yt(1e3)}throw Error(`failed to retrieve playable Android recording`)}async function Jt(e,t){for(let n=0;n<=Lt;n+=Rt){let r=await e.inspect(t);if(r===`missing`)return!0;if(O(r))throw Error(`Android screenrecord ownership could not be confirmed for pid ${t.pid}`);n<Lt&&await Yt(Rt)}return!1}function Yt(e){return new Promise(t=>setTimeout(t,e))}async function P(e,t,n,r){await e.writeManifest({manifestPath:t,contents:JSON.stringify(n)},r)}async function F(e,t){if(!await e.removeManifest(t))throw Error(`failed to remove Android recording manifest: ${t}`)}async function Xt(e,t){let n=(await Zt(e)).flatMap(n=>Qt(n,t,e.mode));for(let t of n)await en(e,t.evidence,t.manifestPath)}async function Zt(e){return await Promise.all(A(void 0).map(async t=>{let n=e.manifestPathFor(t);return{manifestPath:n,read:await e.readManifest(n)}}))}function Qt(e,t,n){if(e.read.status===`missing`)return[];if(e.read.status!==`read`)throw rn(e.manifestPath,e.read.message);let r=D(e.read.contents);if(r===void 0)throw an(e.manifestPath);if(r.transportMode!==n)throw on(e.manifestPath,r,n);if(!$t(r,t))throw sn(e.manifestPath,r,t);return[{manifestPath:e.manifestPath,evidence:r}]}function $t(e,t){return e.completion!==void 0||e.deviceId!==t.id}async function en(e,t,n){if(await tn(e,t),await M(e,t.chunks),await nn(e,t),await F(e,n),(await e.readManifest(n)).status!==`missing`)throw un(n)}async function tn(e,t){for(let n of t.chunks){let t=await e.inspect({pid:n.remotePid,remotePath:n.remotePath,startTime:n.remoteStartTime});if(!It(t))throw t===`uncertain`?dn(n.remotePath):cn(n.remotePath,t===`owned-alive`?`named-recorder`:`other-recorder`)}let n=t.pendingRemotePath;if(n===void 0)return;let r=await e.probeRunningWriters(n);if(r.writers.length>0)throw cn(n,`other-recorder`);if(!r.conclusive)throw dn(n)}async function nn(e,t){let n=t.pendingRemotePath;if(n!==void 0&&!await e.remove(n))throw ln(n)}function rn(t,n){return new e(`COMMAND_FAILED`,`Android screenrecord native recovery evidence is unavailable: ${t}`,{reason:`native_recovery_evidence_unavailable`,manifestPath:t,hint:`Confirm the device is online and its storage readable, then run record start again.`},Error(n))}function an(t){return new e(`COMMAND_FAILED`,`Android screenrecord native recovery evidence is unreadable: ${t}`,{reason:`native_recovery_evidence_unreadable`,manifestPath:t,hint:I(t)})}function on(t,n,r){return new e(`COMMAND_FAILED`,`Android screenrecord native recovery evidence was written by the ${n.transportMode} transport, not this ${r} one: ${t}`,{reason:`native_recovery_evidence_transport_mismatch`,manifestPath:t,evidenceTransportMode:n.transportMode,hint:I(t)})}function sn(t,n,r){return new e(`DEVICE_IN_USE`,`Android screenrecord native recovery evidence already exists: ${t} (open recording of session "${n.sessionId}" on ${r.id})`,{reason:`native_recovery_evidence_open`,manifestPath:t,sessionId:n.sessionId,retriable:!1,hint:`Run record stop --session ${n.sessionId} to retire it, or close that session. If it is already closed, ${I(t)}`})}function cn(t,n){let r=n===`named-recorder`;return new e(`DEVICE_IN_USE`,`Android screenrecord recovery evidence is retained: ${r?`its recorder`:`another recorder`} is writing ${t}`,{reason:`native_recording_artifact_claimed`,remotePath:t,writer:n,...r?{retriable:!1}:{},hint:r?`Run record stop for the session that owns that recording before starting another.`:`Android ends any recorder after 180 seconds. Run record start again once that recorder has stopped.`})}function ln(t){return new e(`COMMAND_FAILED`,`Android screenrecord recovery evidence could not remove ${t}`,{reason:`native_recording_artifact_removal_failed`,remotePath:t,hint:`Confirm the device is online and run record start again.`})}function un(t){return new e(`COMMAND_FAILED`,`Android screenrecord recovery evidence removal could not be confirmed: ${t}`,{reason:`native_recovery_evidence_retirement_unconfirmed`,manifestPath:t,hint:`Run record start again; the marker is retired from the beginning.`})}function dn(t){return new e(`COMMAND_FAILED`,`Android screenrecord recovery evidence cannot be safely retired: ${t}`,{reason:`native_recording_recorder_unproven`,remotePath:t,hint:`Confirm the device is online and run record start again.`})}function I(e){return`no recording session can retire this marker; remove it on the device with \`adb shell rm -f ${e}\`.`}async function fn(e){let{transport:t,device:n,input:r,startedAt:i,signal:a,prepareOutput:o}=e;await Xt(t,n),await o();let s;for(let e of A(void 0)){let o=t.manifestPathFor(e);await P(t,o,E(n,r,i,[],e,t.mode),a);let c,l;try{l=Date.now(),c=await zt(t,e,r,a)}catch(e){if(a.aborted)throw await pn(t,o,e),a.reason;await gn(t,o,e),s=e;continue}try{await P(t,o,E(n,r,i,[c],void 0,t.mode),a)}catch(e){throw await mn(t,o,c),e}return{chunk:c,manifestPath:o,startedAtMs:l}}throw s??Error(`Android screenrecord did not begin producing frames`)}async function pn(e,t,n){n instanceof k||await F(e,t).catch(()=>{})}async function mn(e,t,n){try{await Wt(e,[n])}catch{return}await F(e,t).catch(()=>{})}async function hn(e){let{transport:t,device:n,input:r,startedAt:i,chunks:a,manifestPath:o,preferredDir:s}=e,c;for(let e of A(s)){await P(t,o,E(n,r,i,a,e,t.mode));try{return await zt(t,e,r)}catch(e){if(e instanceof k)throw e;try{await P(t,o,E(n,r,i,a,void 0,t.mode))}catch{throw new k(e)}c=e}}throw c??Error(`failed to start next Android recording chunk`)}async function gn(e,t,n){if(n instanceof k)throw n;try{await F(e,t)}catch{throw new k(n)}}function _n(e,t){return Object.freeze({backend:`adb screenrecord`,outPath:e.outputPath,...e.clientOutputPath?{clientOutPath:e.clientOutputPath}:{},startedAt:t,scope:e.scope,showTouches:e.showTouches,recordOnlySession:e.recordOnlySession,...e.activeSessionApp?{activeSessionApp:e.activeSessionApp}:{},...e.exportQuality?{exportQuality:e.exportQuality}:{},gestureEvents:[]})}function vn(e){let t=yn(e.chunkPaths);if(t===void 0)return{};let n=e.stoppedAtMs-e.startedAtMs;return n-t<2e3?{capturedDurationMs:t}:{capturedDurationMs:t,idleTailWarning:`Android screenrecord encodes a frame only when the screen changes, so this video ends at the last frame it encoded: it covers ${bn(t)}s of the ${bn(n)}s recording window.`}}function yn(e){let t=0;for(let n of e){let e=ze(n);if(e===void 0)return;t+=e}return t}function bn(e){return(e/1e3).toFixed(1)}async function xn(e){let{host:t,transport:n,evidence:r,recording:i,startedAtMs:a,progress:o}=e,s=e.reachedLimit===!0;return await En(e,await Ee({snapshot:i,progress:o,steps:{stop:async()=>(s=await j(n,r.chunks)||s,await Vt(n,r.chunks),{observation:{recorder:`confirmed`},...s?{warning:`Android adb screenrecord stopped before record stop, likely after reaching the 180s platform limit. The MP4 may be truncated; final interactions after the limit are not in the video.`}:{}}),collect:e=>Ht(n,r.chunks,e),finalize:({collectedPath:e,exportPath:n,stoppedAtMs:o})=>Sn({host:t,evidence:r,recording:i,startedAtMs:a,stoppedAtMs:o,collectedPath:e,exportPath:n}),discard:e=>wn(t,e,r.chunks.length)}}))}async function Sn(e){let{host:t,evidence:n,recording:r,collectedPath:i,exportPath:a}=e,o=Dn({collectedPath:i,exportPath:a,exportClientPath:r.clientOutPath,count:n.chunks.length}),s=o.length>1,c;try{await Cn(t,o),c=await t.screenRecording.finalize.complete({outputPath:a,showTouches:!s&&r.showTouches,gestureEvents:r.gestureEvents,exportQuality:r.exportQuality??`medium`,targetLabel:`Android recording`})}catch(e){for(let{served:e}of o)await t.screenRecording.outputs.remove(e.path);throw e}let l=vn({chunkPaths:o.map(({collected:e})=>e.path),startedAtMs:e.startedAtMs,stoppedAtMs:e.stoppedAtMs});return Tn({finalization:c,captured:l,recording:r,chunked:s,files:o})}async function Cn(e,t){for(let{collected:n,served:r}of t)await e.screenRecording.outputs.copy({from:n.path,to:r.path})}async function wn(e,t,n){for(let r=1;r<=n;r+=1)await e.screenRecording.outputs.remove(S(t,r))}function Tn(e){let{finalization:t,captured:n,recording:r,chunked:i,files:a}=e,o=[t.warning,...i?[`Android adb screenrecord is capped at 180s, so this recording was split into multiple MP4 chunks.`]:[],n.idleTailWarning].filter(e=>e!==void 0&&e.length>0);return{...t.telemetryPath===void 0?{}:{telemetryPath:t.telemetryPath},...o.length===0?{}:{warning:o.join(` `)},...i&&r.showTouches&&r.gestureEvents.length>0?{overlayWarning:`touch overlay burn-in is skipped for chunked Android recordings; returning raw chunks plus gesture telemetry`}:{},...n.capturedDurationMs===void 0?{}:{capturedDurationMs:n.capturedDurationMs},...i?{chunks:a.map(e=>e.served)}:{},nativePathDisposition:`retirable`}}async function En(e,t){let{transport:n,evidence:r,manifestPath:i}=e;return await P(n,i,Nt(r,t.result)),await M(n,r.chunks),{status:`completed`,result:{...t.result,nativePathDisposition:await Ut(n,r.chunks)}}}function Dn(e){return Object.freeze(Array.from({length:e.count},(t,n)=>({collected:Object.freeze({index:n+1,path:S(e.collectedPath,n+1)}),served:Object.freeze({index:n+1,path:S(e.exportPath,n+1),...e.exportClientPath===void 0?{}:{clientOutPath:S(e.exportClientPath,n+1)}})})))}async function On(e,t,n){try{let r=t.pendingRemotePath;if(await j(e,[...t.chunks,...await kn(e,t)]),await M(e,t.chunks),r!==void 0&&!await e.remove(r))throw Error(`failed to remove Android recording artifact: ${r}`);return await F(e,n),{status:`cleaned`}}catch(e){return An(e)}}async function kn(e,t){let n=t.pendingRemotePath;if(n===void 0)return[];let r=await e.probeRunningWriters(n);if(!r.conclusive)throw Error(`cannot list every recorder writing Android artifact: ${n}`);return r.writers.map((e,r)=>({index:t.chunks.length+1+r,remotePath:n,remotePid:e.pid,remoteStartTime:e.startTime}))}function An(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:String(e)}}async function jn(e){let{transport:t,device:n,envelope:r,descriptor:i}=e;if(i.transportMode!==t.mode)return{status:`transport-unavailable`};let a=await t.readManifest(i.manifestPath);if(a.status===`unavailable`)return{status:`transport-unavailable`};let o=a.status===`read`?D(a.contents):void 0;return o&&Pt(o,n,r)&&Ft(o,i)?{status:`matched`,evidence:o}:{status:`ownership-lost`}}async function Mn(e){let t=await e.transport.readManifest(e.manifestPath);if(t.status!==`read`)return;let n=D(t.contents);return n&&Nn(n,e)?n:void 0}function Nn(e,t){return e.deviceId===t.deviceId&&e.sessionId===t.sessionId&&e.fenceToken===t.fence.token&&e.fenceGeneration===t.fence.generation}async function Pn(e){let{host:t,transport:n,device:r,input:i}=e,a=T.decode(i.envelope.descriptor.body);if(a.status!==`decoded`)return R(`descriptor-invalid`);let o=await jn({transport:n,device:r,envelope:i.envelope,descriptor:a.descriptor});return o.status===`matched`?await Fn({host:t,transport:n,device:r,input:i,descriptor:a.descriptor,evidence:o.evidence}):R(o.status===`transport-unavailable`?`transport-not-reattachable`:`ownership-fence-lost`)}async function L(e){let t=T.decode(e.input.envelope.descriptor.body);if(t.status!==`decoded`)return{status:`cleanup-pending`,reason:`manual-recovery-required`};let n=await jn({transport:e.transport,device:e.device,envelope:e.input.envelope,descriptor:t.descriptor});return n.status===`matched`?await On(e.transport,n.evidence,t.descriptor.manifestPath):n.status===`transport-unavailable`?{status:`cleanup-pending`,reason:`owner-unavailable`}:{status:`cleanup-pending`,reason:`ownership-fence-lost`}}async function Fn(e){let{host:t,transport:n,device:r,input:i,descriptor:a,evidence:o}=e;if(o.completion!==void 0){let e=await In(n,o);return e.status===`terminal`?{status:`completed`,result:{...o.completion,nativePathDisposition:e.nativePathDisposition}}:R(`ownership-fence-lost`,`Android recording completed evidence still names a live or unverifiable recorder.`)}if(o.pendingRemotePath!==void 0)return R(`transport-not-reattachable`,`Android recording launch was interrupted before its process identity was committed.`);let s=o.chunks.at(-1);if(!s)return{status:`missing`};let c=await n.inspect({pid:s.remotePid,remotePath:s.remotePath,startTime:s.remoteStartTime});if(c!==`owned-alive`&&await n.exists(s.remotePath)===!1)return R(`transport-not-reattachable`,`Android recording process ended before its artifact could be recovered.`);let l=Ln(i.envelope.sessionId,i.envelope.fence,a),u=!1;return{status:`active`,handle:Se(_n(l,o.startedAt),{finish:async(e,r)=>{let i=await xn({host:t,transport:n,evidence:o,manifestPath:a.manifestPath,recording:e,startedAtMs:o.startedAt,reachedLimit:O(c),progress:r});return u=!0,i},forceCleanup:async()=>u?{status:`cleaned`}:await L({transport:n,device:r,input:i})})}}async function In(e,t){try{for(let n of t.chunks)if(!O(await e.inspect({pid:n.remotePid,remotePath:n.remotePath,startTime:n.remoteStartTime})))return{status:`retained`};return{status:`terminal`,nativePathDisposition:await Ut(e,t.chunks)}}catch{return{status:`retained`}}}function Ln(e,t,n){return{sessionId:e,outputPath:n.outputPath,...n.clientOutputPath===void 0?{}:{clientOutputPath:n.clientOutputPath},scope:n.scope,showTouches:n.showTouches,hideTouchesRequested:!1,recordOnlySession:n.recordOnlySession,...n.activeSessionApp===void 0?{}:{activeSessionApp:n.activeSessionApp},...n.exportQuality===void 0?{}:{exportQuality:n.exportQuality},fence:t}}function R(e,t){return{status:`unreattachable`,reason:e,...t===void 0?{}:{message:t}}}async function Rn(e){let{host:t,device:n,owner:r,signal:i}=e,a=await t.screenRecording.android.resolve(n);return Object.freeze({screenRecordingStart:async e=>await zn({host:t,transport:a,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async e=>await Pn({host:t,transport:a,device:n,input:e}),screenRecordingCleanup:async e=>await L({transport:a,device:n,input:e})})}async function zn(e){let{host:n,transport:r,device:i,owner:a,input:o,signal:s}=e;s.throwIfAborted();let c=Date.now(),l=await fn({transport:r,device:i,input:o,startedAt:c,signal:s,prepareOutput:async()=>await n.screenRecording.outputs.prepare(o.outputPath)}),u=l.manifestPath,d=[l.chunk],f,p,m,h=!1,g=()=>{f=setTimeout(()=>{p=ee().catch(e=>{m=e})},17e4),f.unref?.()},ee=async()=>{let e=d.at(-1);if(!e)throw Error(`Android recording has no active chunk`);let t=!1,n;try{n=await hn({transport:r,device:i,input:o,startedAt:c,chunks:d,manifestPath:u,preferredDir:b.posix.dirname(e.remotePath)})}catch(a){await N(r,e),t=!0;try{n=await hn({transport:r,device:i,input:o,startedAt:c,chunks:d,manifestPath:u,preferredDir:b.posix.dirname(e.remotePath)})}catch(e){throw e instanceof Error?e:a}}let a=[...d,{...n,index:d.length+1}];try{await P(r,u,E(i,o,c,a,void 0,r.mode))}catch(a){if(await Wt(r,[n]).catch(()=>{}),t)await P(r,u,E(i,o,c,d,n.remotePath,r.mode)).catch(()=>{});else try{await P(r,u,E(i,o,c,d,void 0,r.mode))}catch{await N(r,e).catch(()=>{}),await P(r,u,E(i,o,c,d,n.remotePath,r.mode)).catch(()=>{})}throw a}d=a,t||await N(r,e),g()};g();let _=Se(_n(o,c),{finish:async(e,t)=>{if(f&&clearTimeout(f),await p,m)throw m;let a=await xn({host:n,transport:r,evidence:E(i,o,c,d,void 0,r.mode),manifestPath:u,recording:e,startedAtMs:l.startedAtMs,progress:t});return h=!0,a},forceCleanup:async()=>{if(f&&clearTimeout(f),h)return{status:`cleaned`};try{await p}catch(e){m=e}let e=await Mn({transport:r,deviceId:i.id,sessionId:o.sessionId,fence:o.fence,manifestPath:u});return e?await On(r,e,u):{status:`cleanup-pending`,reason:`ownership-fence-lost`}}});return Object.freeze({pendingHandle:new ge(_),envelope:he({resourceKind:De,sessionId:o.sessionId,device:t(i),owner:a,fence:o.fence,lifecycle:`open`,descriptor:me(T,{backend:`adb-screenrecord`,manifestPath:u,outputPath:o.outputPath,...o.clientOutputPath===void 0?{}:{clientOutputPath:o.clientOutputPath},scope:o.scope,showTouches:o.showTouches,recordOnlySession:o.recordOnlySession,...o.activeSessionApp===void 0?{}:{activeSessionApp:o.activeSessionApp},...o.exportQuality===void 0?{}:{exportQuality:o.exportQuality},transportMode:r.mode})})})}const z=12e4,Bn=1e3;async function B(e,t,n,r){return r.throwIfAborted(),await Be(t)?{...t,booted:!0}:t.kind===`emulator`&&(t.booted!==!0||!V(t))?await Vn(e,t,n,r):(t.booted!==!0&&await Gn(e,t.id,z,r),{...t,booted:!0})}async function Vn(e,t,n,r){await Hn(e);let i=Kn(n),a=Un(await e.deviceReadiness.androidEmulator.discover(i,r),t.name,n.serial),o=V(a)?a:void 0,s=o?void 0:e.deviceReadiness.androidEmulator.launch(a.name,n.headless);try{let t=o??await Wn(e,a.name,i,n.serial,r);return await Gn(e,t.id,z,r),{...(await e.deviceReadiness.androidEmulator.discover(i,r)).find(e=>e.id===t.id)??t,name:a.name,booted:!0}}catch(t){throw s!==void 0&&r.aborted&&await e.deviceReadiness.androidEmulator.terminate(s),r.throwIfAborted(),t}}async function Hn(t){if(await t.toolchains.prepare(`android`),!await t.commands.which(`adb`))throw new e(`TOOL_MISSING`,`adb not found in PATH`);if(!await t.commands.which(`emulator`))throw new e(`TOOL_MISSING`,`emulator not found in PATH`)}function Un(t,n,r){let i=qn(t,n,r);if(i)return i;throw new e(`DEVICE_NOT_FOUND`,`No Android emulator AVD named ${n}`,{requestedAvdName:n,availableAvds:t.map(e=>e.name),hint:"Run `emulator -list-avds` and pass an existing AVD name to --device."})}async function Wn(t,n,r,i,a){let o=t.clock.now()+z;for(;t.clock.now()<o;){let e=qn(await t.deviceReadiness.androidEmulator.discover(r,a),n,i);if(e&&V(e))return e;await t.clock.sleep(Bn,a)}throw new e(`COMMAND_FAILED`,`Android emulator did not appear in time`,{avdName:n,serial:i,timeoutMs:z})}async function Gn(t,n,r,a){let o=t.clock.now()+r;for(;t.clock.now()<o;){if((await t.commands.run({executable:`adb`,args:i(`adb`,`shell`,[`getprop`,`sys.boot_completed`],[`-s`,n]),allowFailure:!0,timeoutMs:Math.min(1e4,Math.max(1e3,o-t.clock.now()))},a)).stdout.trim()===`1`)return;await t.clock.sleep(Bn,a)}throw new e(`COMMAND_FAILED`,`Android device failed to finish booting`,{serial:n,timeoutMs:r,reason:`ANDROID_BOOT_TIMEOUT`})}function Kn(e){return{platform:`android`,kind:`emulator`,...e.serial?{serial:e.serial}:{},...e.androidSerialAllowlist?{androidSerialAllowlist:[...e.androidSerialAllowlist]}:{}}}function qn(e,t,n){let r=Jn(t);return e.find(e=>e.platform===`android`&&e.kind===`emulator`&&Jn(e.name)===r&&(!n||!V(e)||e.id===n))}function V(e){return e.id.startsWith(`emulator-`)}function Jn(e){return e.toLowerCase().replaceAll(`_`,` `).replaceAll(/\s+/g,` `).trim()}function Yn(e){let{host:t,device:n,signal:r}=e,i=Ue({device:n,signal:r,resolveInteractor:t.localInteractors.resolve});return Object.freeze({resolveOpenTarget:async e=>await t.androidApplications.resolveOpenTarget(n,e),prepareApplicationOpen:async e=>{await B(t,n,{headless:!1},r)},openApplication:async e=>await Xn(t,i,e),applyRuntimeHints:async e=>await t.androidApplications.applyRuntimeHints(n,e),clearRuntimeHints:async e=>await t.androidApplications.clearRuntimeHints(n,e),closeApplication:async e=>{e.ensureReady&&await B(t,n,{headless:!1},r),await Ve({device:n,interactor:await i.resolveInteractor(e.execution,e.appBundleId),positionals:e.positionals})},finalizeApplicationClose:async e=>{await t.androidApplications.restoreTestIme(n,{stateDir:e.stateDir});let i=e.shutdownTarget&&n.kind===`emulator`?await t.deviceShutdown.android.shutdownTarget(n,r):void 0;return i===void 0?{}:{shutdown:i}},prepareAppleRunner:Zn,configureProviderPortReverse:Zn})}async function Xn(t,n,r){let i={};if(r.relaunch&&r.target){let e=Date.now();await Ve({device:n.device,interactor:await n.resolveInteractor(r.execution,r.appBundleId),positionals:[r.appBundleId??r.target]}),i.relaunchCloseDurationMs=H(e)}if(c(r.runtimeHints)){if(!r.applyRuntimeHints)throw new e(`COMMAND_FAILED`,`Runtime hint operation was not admitted for this open.`,{reason:`runtime-hints-operation-missing`});let t=Date.now();await r.applyRuntimeHints({appId:r.appBundleId,values:r.runtimeHints}),i.runtimeHintsDurationMs=H(t)}let a=Date.now();await We({device:n.device,interactor:await n.resolveInteractor(r.execution,r.appBundleId),positionals:r.positionals,appBundleId:r.appBundleId,execution:r.execution}),i.openDispatchDurationMs=H(a),r.enableTestIme&&await t.androidApplications.activateTestIme(n.device,{stateDir:r.stateDir});let o=He(r);if(o){let e=Date.now();await We({device:n.device,interactor:await n.resolveInteractor({...r.execution,clearAppState:void 0,launchConsole:void 0,launchArgs:void 0},r.appBundleId),positionals:[o],appBundleId:r.appBundleId,execution:{...r.execution,clearAppState:void 0,launchConsole:void 0,launchArgs:void 0}}),i.launchUrlDurationMs=H(e)}else i.launchUrlDurationMs=0;let s=await t.androidApplications.inferOpenedAppBundleId(n.device,r.target,r.appBundleId);return s&&await t.androidApplications.resetFramePerfStats(n.device,s),i.postOpenSettleDurationMs=0,{appBundleId:s,timing:i}}function H(e){return Math.max(0,Date.now()-e)}async function Zn(){throw new e(`UNSUPPORTED_OPERATION`,`This lifecycle operation is unavailable for Android.`)}async function U(e,t,n,r,i){W(n);let a=r?void 0:await nr(e,t,i);if(b.extname(n).toLowerCase()===`.aab`?await tr(e,t,n,i):K(await e.androidTools.installPackage(t,n,{replace:!0},i),`adb install failed`),r)return r;let o=[...await nr(e,t,i)].filter(e=>!a?.has(e));return o.length===1?o[0]:void 0}function W(t){if(y()&&b.extname(t).toLowerCase()===`.aab`)throw new e(`UNSUPPORTED_OPERATION`,`Managed Android deployment does not support app bundles.`,{reason:`managed-bundle-install-unavailable`,hint:`Install an APK on this managed device.`})}async function Qn(e,t,n,r){let i=await G(e,t,[`uninstall`,n],r);if(i.exitCode===0)return;let a=`${i.stdout}\n${i.stderr}`.toLowerCase();a.includes(`unknown package`)||a.includes(`not installed`)||K(i,`adb uninstall failed for ${n}`)}async function $n(t,n,r,a){let o=r.payload,s=typeof o.action==`string`&&o.action.trim()?o.action.trim():`${r.appId}.TEST_PUSH`,c=[`am`,`broadcast`,`-a`,s,`-p`,r.appId];typeof o.receiver==`string`&&o.receiver.trim()&&c.push(`-n`,o.receiver.trim());let l=o.extras??{};if(typeof l!=`object`||!l||Array.isArray(l))throw new e(`INVALID_ARGS`,`Android push payload extras must be an object`);let u=0;for(let[e,t]of Object.entries(l))e&&(rr(c,e,t),u+=1);return K(await G(t,n,i(`adb`,`shell`,c),a),`adb push broadcast failed`),{action:s,extrasCount:u}}function er(e){let t=new Set([`com`,`android`,`google`,`app`,`apps`,`service`,`services`,`mobile`,`client`]),n=e.split(/[._-]+/).map(e=>e.trim().toLowerCase()).filter(Boolean),r=[...n].reverse().find(e=>!t.has(e))??n.at(-1)??e;return r.charAt(0).toUpperCase()+r.slice(1)}async function tr(t,n,r,i){if(await t.androidTools.installBundle(n,r,`universal`,i))return;let a=await t.commands.which(`bundletool`),o=t.androidDeployment.bundletoolJar;if(!a&&!o)throw new e(`TOOL_MISSING`,`bundletool not found in PATH. Install bundletool or set AGENT_DEVICE_BUNDLETOOL_JAR.`);let s=a?`bundletool`:`java`,c=a?[]:[`-jar`,o],l=await t.temporaryFiles.create({prefix:`agent-device-aab-`,suffix:`.apks`}),u=l.path;try{K(await t.commands.run({executable:s,args:[...c,`build-apks`,`--bundle`,r,`--output`,u,`--mode`,`universal`]},i),`bundletool build-apks failed`),K(await t.commands.run({executable:s,args:[...c,`install-apks`,`--apks`,u,`--device-id`,n.id]},i),`bundletool install-apks failed`)}finally{await l[Symbol.asyncDispose]()}}async function nr(e,t,n){let r=await G(e,t,i(`adb`,`shell`,[`pm`,`list`,`packages`]),n);return K(r,`adb package inventory failed`),new Set(r.stdout.split(`
|
|
5
|
-
`).map(e=>e.replace(`package:`,``).trim()).filter(Boolean))}function rr(t,n,r){if(typeof r==`string`)t.push(`--es`,n,r);else if(typeof r==`boolean`)t.push(`--ez`,n,String(r));else if(typeof r==`number`&&Number.isFinite(r))t.push(Number.isInteger(r)?`--ei`:`--ef`,n,String(r));else throw new e(`INVALID_ARGS`,`Unsupported Android broadcast extra type for "${n}". Use string, boolean, or number.`)}async function G(e,t,n,r,i=15e3){return await e.androidTools.runAdb(t,n,{timeoutMs:i,allowFailure:!0},r)}function K(t,n){if(t.exitCode===0)return;let r={stdout:t.stdout,stderr:t.stderr,exitCode:t.exitCode};throw new e(`COMMAND_FAILED`,n,r)}const ir=Object.freeze({available:!0});function ar(e){let t=lr(e);return Object.freeze({deployApp:t,materializeAppSource:t,deployMaterializedApp:t,sendPushNotification:t})}function or(e){let{host:t,device:n,signal:r}=e;return ar(n).deployApp.available?Object.freeze({deployApp:async e=>await sr(t,n,e,r),materializeAppSource:async e=>await t.androidDeployment.prepareArtifact(e,{signal:r}),deployMaterializedApp:async e=>await cr(t,n,e,r),sendPushNotification:async e=>await $n(t,n,e,r)}):Object.freeze({})}async function sr(e,t,n,r){if(n.replaceExisting)return await e.androidDeployment.withInvalidatedAppResolutionCache(t,async()=>{let i;try{y()&&(i=await e.androidDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{resolveIdentity:!1,signal:r}),W(i.installablePath)),t.booted!==!0&&await B(e,t,{headless:!1},r);let a=await e.androidDeployment.resolveAppPackage(t,n.app);return await Qn(e,t,a,r),i??=await e.androidDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{resolveIdentity:!1,signal:r}),await U(e,t,i.installablePath,void 0,r),{packageName:a,launchTarget:a}}finally{await i?.cleanup()}});let i;try{y()&&(i=await e.androidDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{resolveIdentity:!0,signal:r}),W(i.installablePath)),t.booted!==!0&&await B(e,t,{headless:!1},r),i??=await e.androidDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{resolveIdentity:!0,signal:r});let a=await U(e,t,i.installablePath,i.packageName,r);return a?{packageName:a,appName:er(a),launchTarget:a}:{}}finally{await i?.cleanup()}}async function cr(t,n,r,i){let a=await U(t,n,r.artifact.installablePath,r.artifact.packageName,i);if(!a)throw new e(`COMMAND_FAILED`,`Installed Android app identity could not be resolved from the artifact or device state`);return{packageName:a,appName:er(a),launchTarget:a}}function lr(e){return e.kind===`emulator`||e.kind===`device`?ir:Object.freeze({available:!1,reason:`unsupported-device-kind`})}const q=n(`android`),J=Object.freeze({available:!0}),ur=Object.freeze({available:!1,reason:`unsupported-device-kind`}),dr=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`focus is supported on Android emulators and physical devices.`}),fr=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`keyboard actions are supported on Android emulators and physical devices.`}),pr=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),mr=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Android has no key event for this system button.`}),hr=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`fold drives the hinge of a foldable iPhone simulator; the Android emulator posture control is not driven by agent-device yet.`}),gr=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Headless boot is supported only for Android emulators.`}),_r=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Android appstate is supported only for Android emulators and devices.`}),vr=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple runner preparation is supported only for Apple targets.`}),yr=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`open is supported only for Android emulators and devices.`}),br=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`close is supported only for Android emulators and devices.`}),xr=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Runtime hints are supported only for Android emulators and devices.`}),Sr=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`}),Cr=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`shutdown is supported only for Apple simulators and Android emulators.`}),wr=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`screenshot is supported only for Android emulators and devices.`}),Y=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`snapshot is supported only for Android emulators and devices.`}),Tr=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Re-run without --actions, or target an iOS simulator.`}),Er=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`viewport resizes web targets only (--platform web).`}),Dr=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`the stateless audio page probe is a web-session operation; Android targets use the host capture.`});function Or(e){let t=kr(e),n=Ar(e),r=jr(e);return l({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:r,clearRuntimeHints:r,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:vr,configureProviderPortReverse:Sr})}function kr(e){return e.kind===`emulator`||e.kind===`device`?J:yr}function Ar(e){return e.kind===`emulator`||e.kind===`device`?J:br}function jr(e){return e.kind===`emulator`||e.kind===`device`?J:xr}const X=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Gestures are supported on Android emulators and physical devices.`}),Mr=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:je}),Nr=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:Ae});function Pr(e,t){return e.kind===`simulator`?X:e.target===`tv`?t:J}function Z(e){return e.kind===`simulator`?X:J}function Q(e){return e.kind===`simulator`?dr:J}const $=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:ke}),Fr=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`Could not determine whether this Android build supports a shell clipboard: the adb probe did not complete. Retry once the device is reachable.`});async function Ir(e,t){let n=e.androidTools?.probeClipboardShellSupport;return n?await n.call(e.androidTools,t):`probe-failed`}const Lr=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`tv-remote is supported only on Android TV targets.`});function Rr(e){return e.kind!==`simulator`&&e.target===`tv`?J:Lr}function zr(e){let t=Qe(e),n=new Map,i=async t=>{if(t.kind===`simulator`)return $;let r=n.get(t.id)??await Ir(e,t);return r!==`probe-failed`&&n.set(t.id,r),r===`supported`?J:r===`unsupported`?$:Fr},a=async e=>{let n=await t.inspectFacts(e),r=ar(e),a=await i(e);return Object.freeze({device:n.device,operations:{...n.operations,...r,appState:e.kind===`simulator`?_r:J,networkDump:J,screenRecordingStart:J,screenRecordingReattach:J,screenRecordingCleanup:J,...p({capture:e.kind===`simulator`?Y:J,customActions:Tr,withoutActiveApp:e.kind===`simulator`?Y:J}),...f({capture:e.kind===`simulator`?wr:J}),...ee({findText:Y}),...h({setViewport:Er}),...m({focus:Q(e)}),...g({unsupported:X,plan:Z(e),directionalFling:Z(e),multiTouch:Pr(e,Mr),targetAuthoredDrag:Pr(e,Nr),viewport:Z(e)}),...u({scroll:Z(e)}),...d({type:Q(e)}),...pe({unsupported:dr,tap:Q(e),longPress:Q(e),hover:pr,fill:Q(e)}),...ce({readTextAtPoint:e.kind===`simulator`?ur:J}),...le({back:Q(e)}),...oe({unsupported:mr,home:Q(e),appSwitcher:Q(e)}),setFoldPose:hr,...re({triggerAppEvent:Q(e)}),..._({setSetting:Q(e),readSetting:Q(e)}),...ae({read:Q(e),wait:Q(e),accept:Q(e),dismiss:Q(e)}),...te({orientation:Q(e)}),...se({tvRemote:Rr(e)}),...ne({unsupported:fr,status:Q(e),dismiss:Q(e),enter:Q(e)}),...ie({unsupported:a.available?$:a,read:a,write:a}),...de({capture:Ge(e),query:Dr}),...fe({frames:Q(e),memorySample:Q(e),memorySnapshot:Q(e),nativeCapture:Q(e),profileReport:Q(e)}),ensureReady:J,bootTarget:J,bootTargetHeadless:e.kind===`emulator`?J:gr,listApps:J,...Or(e),shutdownTarget:e.kind===`emulator`?J:Cr}})};return Object.freeze({owner:q,ownsDevice:e=>e.platform===`android`,inspectFacts:a,bind:async n=>{let i=await t.bind(n),o=await a(n.device),c=await Rn({host:e,device:n.device,owner:q,signal:n.scope.signal});return Object.freeze({device:i.device,owner:q,facts:o,operations:Object.freeze({...i.operations,...or({host:e,device:n.device,signal:n.scope.signal}),...o.operations.appState.available?{appState:async()=>{n.scope.signal.throwIfAborted();let{runAndroidAdb:e}=await import(`./adb.js`).then(e=>e.t);return await Oe(async(t,r)=>await e(n.device,t,{...r,signal:n.scope.signal}),n.scope.signal)}}:{},networkDump:async t=>await tt(e,n.device,t,n.scope.signal),...c,...r(o.operations.audioProbeStart,()=>ve({host:e.audioProbe.hostCapture,device:n.device,owner:q})),...r(o.operations.perfFrames,()=>Ke({resolveHost:()=>e.perf.android,device:n.device,owner:q})),...Br(e,n,o),ensureReady:async t=>await B(e,n.device,{...t,headless:!1},n.scope.signal),bootTarget:async t=>await B(e,n.device,{...t,headless:!1},n.scope.signal),...o.operations.bootTargetHeadless.available?{bootTargetHeadless:async t=>await B(e,n.device,{...t,headless:!0},n.scope.signal)}:{},listApps:async e=>{n.scope.signal.throwIfAborted();let{listAndroidApps:t}=await import(`./app-lifecycle.js`).then(e=>e.t);return(await t(e.device,e.filter)).map(e=>({id:e.package,name:e.name}))},...s(Yn({host:e,device:n.device,signal:n.scope.signal}),o.operations),...o.operations.shutdownTarget.available?{shutdownTarget:async()=>await e.deviceShutdown.android.shutdownTarget(n.device,n.scope.signal)}:{}}),[Symbol.asyncDispose]:async()=>await i[Symbol.asyncDispose]()})},shutdown:async()=>await t.shutdown()})}function Br(e,t,n){let r={device:t.device,signal:t.scope.signal,resolveInteractor:e.localInteractors.resolve};return{...n.operations.captureSnapshot.available?ue(r):{},...Me({...r,facts:n.operations,pause:async n=>await e.clock.sleep(n,t.scope.signal)})}}export{zr as createAndroidPlatformRuntime};
|
|
5
|
+
`).map(e=>e.replace(`package:`,``).trim()).filter(Boolean))}function rr(t,n,r){if(typeof r==`string`)t.push(`--es`,n,r);else if(typeof r==`boolean`)t.push(`--ez`,n,String(r));else if(typeof r==`number`&&Number.isFinite(r))t.push(Number.isInteger(r)?`--ei`:`--ef`,n,String(r));else throw new e(`INVALID_ARGS`,`Unsupported Android broadcast extra type for "${n}". Use string, boolean, or number.`)}async function G(e,t,n,r,i=15e3){return await e.androidTools.runAdb(t,n,{timeoutMs:i,allowFailure:!0},r)}function K(t,n){if(t.exitCode===0)return;let r={stdout:t.stdout,stderr:t.stderr,exitCode:t.exitCode};throw new e(`COMMAND_FAILED`,n,r)}const ir=Object.freeze({available:!0});function ar(e){let t=lr(e);return Object.freeze({deployApp:t,materializeAppSource:t,deployMaterializedApp:t,sendPushNotification:t})}function or(e){let{host:t,device:n,signal:r}=e;return ar(n).deployApp.available?Object.freeze({deployApp:async e=>await sr(t,n,e,r),materializeAppSource:async e=>await t.androidDeployment.prepareArtifact(e,{signal:r}),deployMaterializedApp:async e=>await cr(t,n,e,r),sendPushNotification:async e=>await $n(t,n,e,r)}):Object.freeze({})}async function sr(e,t,n,r){if(n.replaceExisting)return await e.androidDeployment.withInvalidatedAppResolutionCache(t,async()=>{let i;try{y()&&(i=await e.androidDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{resolveIdentity:!1,signal:r}),W(i.installablePath)),t.booted!==!0&&await B(e,t,{headless:!1},r);let a=await e.androidDeployment.resolveAppPackage(t,n.app);return await Qn(e,t,a,r),i??=await e.androidDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{resolveIdentity:!1,signal:r}),await U(e,t,i.installablePath,void 0,r),{packageName:a,launchTarget:a}}finally{await i?.cleanup()}});let i;try{y()&&(i=await e.androidDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{resolveIdentity:!0,signal:r}),W(i.installablePath)),t.booted!==!0&&await B(e,t,{headless:!1},r),i??=await e.androidDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{resolveIdentity:!0,signal:r});let a=await U(e,t,i.installablePath,i.packageName,r);return a?{packageName:a,appName:er(a),launchTarget:a}:{}}finally{await i?.cleanup()}}async function cr(t,n,r,i){let a=await U(t,n,r.artifact.installablePath,r.artifact.packageName,i);if(!a)throw new e(`COMMAND_FAILED`,`Installed Android app identity could not be resolved from the artifact or device state`);return{packageName:a,appName:er(a),launchTarget:a}}function lr(e){return e.kind===`emulator`||e.kind===`device`?ir:Object.freeze({available:!1,reason:`unsupported-device-kind`})}const q=n(`android`),J=Object.freeze({available:!0}),ur=Object.freeze({available:!1,reason:`unsupported-device-kind`}),dr=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`focus is supported on Android emulators and physical devices.`}),fr=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`keyboard actions are supported on Android emulators and physical devices.`}),pr=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),mr=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Android has no key event for this system button.`}),hr=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`fold drives the hinge of a foldable iPhone simulator; the Android emulator posture control is not driven by agent-device yet.`}),gr=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Headless boot is supported only for Android emulators.`}),_r=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Android appstate is supported only for Android emulators and devices.`}),vr=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple runner preparation is supported only for Apple targets.`}),yr=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`open is supported only for Android emulators and devices.`}),br=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`close is supported only for Android emulators and devices.`}),xr=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Runtime hints are supported only for Android emulators and devices.`}),Sr=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`}),Cr=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`shutdown is supported only for Apple simulators and Android emulators.`}),wr=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`screenshot is supported only for Android emulators and devices.`}),Y=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`snapshot is supported only for Android emulators and devices.`}),Tr=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Re-run without --actions, or target an iOS simulator.`}),Er=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`viewport resizes web targets only (--platform web).`}),Dr=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`the stateless audio page probe is a web-session operation; Android targets use the host capture.`});function Or(e){let t=kr(e),n=Ar(e),r=jr(e);return l({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:r,clearRuntimeHints:r,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:vr,configureProviderPortReverse:Sr})}function kr(e){return e.kind===`emulator`||e.kind===`device`?J:yr}function Ar(e){return e.kind===`emulator`||e.kind===`device`?J:br}function jr(e){return e.kind===`emulator`||e.kind===`device`?J:xr}const X=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Gestures are supported on Android emulators and physical devices.`}),Mr=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:je}),Nr=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:Ae});function Pr(e,t){return e.kind===`simulator`?X:e.target===`tv`?t:J}function Z(e){return e.kind===`simulator`?X:J}function Q(e){return e.kind===`simulator`?dr:J}const $=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:ke}),Fr=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`Could not determine whether this Android build supports a shell clipboard: the adb probe did not complete. Retry once the device is reachable.`});async function Ir(e,t){let n=e.androidTools?.probeClipboardShellSupport;return n?await n.call(e.androidTools,t):`probe-failed`}const Lr=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`tv-remote is supported only on Android TV targets.`});function Rr(e){return e.kind!==`simulator`&&e.target===`tv`?J:Lr}function zr(e){let t=Qe(e),n=new Map,i=async t=>{if(t.kind===`simulator`)return $;let r=n.get(t.id)??await Ir(e,t);return r!==`probe-failed`&&n.set(t.id,r),r===`supported`?J:r===`unsupported`?$:Fr},a=async e=>{let n=await t.inspectFacts(e),r=ar(e),a=await i(e);return Object.freeze({device:n.device,operations:{...n.operations,...r,appState:e.kind===`simulator`?_r:J,networkDump:J,screenRecordingStart:J,screenRecordingReattach:J,screenRecordingCleanup:J,...m({capture:e.kind===`simulator`?Y:J,customActions:Tr,withoutActiveApp:e.kind===`simulator`?Y:J}),...ee({capture:e.kind===`simulator`?wr:J}),...te({findText:Y}),...d({setViewport:Er}),...ue({focus:Q(e)}),...g({unsupported:X,plan:Z(e),directionalFling:Z(e),multiTouch:Pr(e,Mr),targetAuthoredDrag:Pr(e,Nr),viewport:Z(e)}),..._({scroll:Z(e)}),...u({type:Q(e)}),...pe({unsupported:dr,tap:Q(e),longPress:Q(e),hover:pr,fill:Q(e)}),...p({readTextAtPoint:e.kind===`simulator`?ur:J}),...ce({back:Q(e)}),...ne({unsupported:mr,home:Q(e),appSwitcher:Q(e)}),setFoldPose:hr,...oe({triggerAppEvent:Q(e)}),...ae({setSetting:Q(e),readSetting:Q(e)}),...ie({read:Q(e),wait:Q(e),accept:Q(e),dismiss:Q(e)}),...f({orientation:Q(e)}),...le({tvRemote:Rr(e)}),...se({unsupported:fr,status:Q(e),dismiss:Q(e),enter:Q(e)}),...re({unsupported:a.available?$:a,read:a,write:a}),...de({capture:Ge(e),query:Dr}),...fe({frames:Q(e),memorySample:Q(e),memorySnapshot:Q(e),nativeCapture:Q(e),profileReport:Q(e)}),ensureReady:J,bootTarget:J,bootTargetHeadless:e.kind===`emulator`?J:gr,listApps:J,...Or(e),shutdownTarget:e.kind===`emulator`?J:Cr}})};return Object.freeze({owner:q,ownsDevice:e=>e.platform===`android`,inspectFacts:a,bind:async n=>{let i=await t.bind(n),o=await a(n.device),c=await Rn({host:e,device:n.device,owner:q,signal:n.scope.signal});return Object.freeze({device:i.device,owner:q,facts:o,operations:Object.freeze({...i.operations,...or({host:e,device:n.device,signal:n.scope.signal}),...o.operations.appState.available?{appState:async()=>{n.scope.signal.throwIfAborted();let{runAndroidAdb:e}=await import(`./adb.js`).then(e=>e.t);return await Oe(async(t,r)=>await e(n.device,t,{...r,signal:n.scope.signal}),n.scope.signal)}}:{},networkDump:async t=>await tt(e,n.device,t,n.scope.signal),...c,...r(o.operations.audioProbeStart,()=>ve({host:e.audioProbe.hostCapture,device:n.device,owner:q})),...r(o.operations.perfFrames,()=>Ke({resolveHost:()=>e.perf.android,device:n.device,owner:q})),...Br(e,n,o),ensureReady:async t=>await B(e,n.device,{...t,headless:!1},n.scope.signal),bootTarget:async t=>await B(e,n.device,{...t,headless:!1},n.scope.signal),...o.operations.bootTargetHeadless.available?{bootTargetHeadless:async t=>await B(e,n.device,{...t,headless:!0},n.scope.signal)}:{},listApps:async e=>{n.scope.signal.throwIfAborted();let{listAndroidApps:t}=await import(`./app-lifecycle.js`).then(e=>e.t);return(await t(e.device,e.filter)).map(e=>({id:e.package,name:e.name}))},...s(Yn({host:e,device:n.device,signal:n.scope.signal}),o.operations),...o.operations.shutdownTarget.available?{shutdownTarget:async()=>await e.deviceShutdown.android.shutdownTarget(n.device,n.scope.signal)}:{}}),[Symbol.asyncDispose]:async()=>await i[Symbol.asyncDispose]()})},shutdown:async()=>await t.shutdown()})}function Br(e,t,n){let r={device:t.device,signal:t.scope.signal,resolveInteractor:e.localInteractors.resolve};return{...n.operations.captureSnapshot.available?h(r):{},...Me({...r,facts:n.operations,pause:async n=>await e.clock.sleep(n,t.scope.signal)})}}export{zr as createAndroidPlatformRuntime};
|
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{E 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{s as h}from"./device-rotation.js";import{c as ee,r as g}from"./diagnostics.js";import{n as te}from"./exec.js";import"./diagnostics2.js";import"./command.js";import{n as ne}from"./scoped-provider.js";import{i as re,n as ie,r as ae}from"./ios-snapshot-planning.js";import{n as oe,t as se}from"./fold-runtime.js";import{t as ce}from"./request.js";import{n as le,r as ue,t as de}from"./application-lifecycle-runtime.js";import{A as fe,C as pe,D as me,G as he,H as ge,I as _e,L as ve,N as ye,O as be,P as xe,R as Se,T as Ce,U as we,V as Te,a as Ee,b as De,g as Oe,j as ke,o as Ae,p as je,t as Me,u as Ne,v as Pe,w as Fe,x as Ie,z as Le}from"./alert-runtime.js";import{n as Re}from"./audio-probe-runtime.js";import{n as ze}from"./perf-runtime.js";import{i as Be,t as Ve}from"./touch-runtime.js";import{a as He,n as Ue}from"./durable-resource.js";import{n as We,t as Ge}from"./async-lifecycle.js";import{a as Ke,c as qe,d as Je,f as Ye,l as Xe,n as Ze,o as Qe,s as $e,t as et,u as tt}from"./src7.js";import{n as nt,t as rt}from"./screen-recording-completion.js";import{a as it,i as at,n as ot,o as st,r as ct,s as lt,t as ut}from"./stop-sequence.js";import{n as dt}from"./screen-recording-runtime.js";import{t as ft}from"./ios-system-surface.js";import{i as pt,r as mt}from"./gesture-admission.js";import{t as ht}from"./interactor-operation-catalog.js";import{a as gt,i as _t,n as vt,r as yt,t as bt}from"./perf-runtime-operation-builder.js";import{t as xt}from"./app-log-runtime.js";import{n as St}from"./artifact-paths.js";import{i as Ct,r as wt}from"./managed-device-scope.js";import{a as Tt,n as Et,o as Dt}from"./application-lifecycle-interaction.js";import{o as Ot,s as kt}from"./config.js";import{a as At,o as jt}from"./tool-provider.js";import{n as Mt}from"./apps-simctl.js";import{i as Nt,o as Pt,r as Ft}from"./simulator.js";import{a as It}from"./helper.js";import{r as Lt}from"./display-inventory.js";import{t as Rt}from"./multitouch-support.js";import{n as _,t as zt}from"./simulator-state.js";import{n as Bt,r as Vt,t as Ht}from"./snapshot-process.js";import Ut from"node:path";import{randomUUID as Wt}from"node:crypto";function Gt(e){let t=Ct();return Object.freeze(t?{...ne({...e},e=>Pt(t,e))}:e)}function Kt(e){return it(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 qt(e){let{resolveHost:t,device:n,owner:r}=e;return Object.freeze({...bt({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 _t(t().sampleFrames(n,e)):vt(`Apple`,`bundle ID`),sampling:await t().frameSampling(n)}),perfMemorySample:async({appId:e})=>({metric:e?await _t(t().sampleMemory(n,e)):vt(`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 gt(`Apple`,o,s,`Use perf memory snapshot --kind memgraph for supported Apple app sessions.`);if(!e)throw yt();let c=i??Ut.join(a,`memory-memgraph-${Jt()}.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 Jt(){return new Date().toISOString().replaceAll(/[:.]/g,`-`)}const v=Object.freeze({available:!0}),y=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),b=Qt(`Gestures are supported only for Apple simulators and devices.`),Yt=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:mt}),Xt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:pt}),Zt=Qt(`scroll is supported only for Apple simulators and devices.`);function Qt(e){return Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:e})}function $t(e){return{...ye({unsupported:en(e),plan:tn(e),directionalFling:tn(e),multiTouch:nn(e),targetAuthoredDrag:rn(e),viewport:an(e)}),...fe({scroll:on(e)})}}function en(e){return e.appleOs===`watchos`||e.appleOs===`visionos`?y:b}function tn(e){return e.appleOs===`watchos`||e.appleOs===`visionos`?y:x(e)?v:b}function nn(e){if(e.appleOs===`watchos`)return y;if(!x(e))return b;let t=d(e);if(t!==`ios`&&t!==`ipados`){let e=Rt[t];return Object.freeze({available:!1,reason:`unsupported-platform-leaf`,...e===void 0?{}:{hint:e}})}return e.kind===`simulator`?v:Yt}function rn(e){return x(e)?(e.appleOs===void 0?e.target!==`desktop`&&e.target!==`tv`:e.appleOs===`ios`||e.appleOs===`ipados`)?v:Xt:b}function an(e){return e.appleOs===`watchos`?y:x(e)?v:b}function on(e){return x(e)?v:Zt}function x(e){return e.kind===`simulator`||e.kind===`device`}const S=`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`;function C(e){return s(e)?`macos`:e.kind===`device`?`ios-device`:`ios-simulator`}const sn=Object.freeze({resourceKind:xt,version:1,encode:e=>({...e}),decode:e=>!ln(e.transport)||!un(e.backend)||!mn(e.outputPath)||!fn(e.pidPath)||!dn(e.transport,e.backend)?cn():{status:`decoded`,descriptor:Object.freeze({transport:e.transport,backend:e.backend,outputPath:e.outputPath,...e.pidPath===void 0?{}:{pidPath:e.pidPath}})}});function cn(){return{status:`invalid`,message:`Invalid Apple app-log descriptor`}}function ln(e){return e===`apple-log-stream`||e===`coredevice-console`}function un(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 fn(e){return e===void 0||mn(e)}function pn(e){if(!e.device.appleOs)throw TypeError(`Apple app-log persistence requires an explicit appleOs identity`);return Ue({resourceKind:xt,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:He(sn,e.descriptor)})}function mn(e){return typeof e==`string`&&e.trim().length>0}const hn={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.`},gn={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 _n(e,t){try{let n=await e.appleTools.run({tool:`devicectl`,args:[`device`,`process`,`launch`,`--help`],allowFailure:!0,timeoutMs:5e3},t),r=n.stderr.trim()||void 0;if(n.exitCode!==0)return{supported:!1,reason:`probe-failed`,stderr:r};let i=`${n.stdout}\n${n.stderr}`;return/\bUSAGE:\s+devicectl device process launch\b/i.test(i)&&/--console\b/.test(i)&&/--terminate-existing\b/.test(i)?{supported:!0,...r?{stderr:r}:{}}:{supported:!1,reason:`unsupported`,...r?{stderr:r}:{}}}catch(e){if(t?.aborted)throw t.reason;return{supported:!1,reason:`probe-failed`,...e instanceof Error?{stderr:e.message}:{}}}}async function vn(e,t,n,r){let i={},a=n?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`];if(s(t))i.logAvailable=!!await e.commands.which(`log`);else if(t.kind===`simulator`)i.simctlAvailable=await lt(async()=>st(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(S);else{i.devicectlAvailable=await lt(async()=>st(await e.appleTools.run({tool:`devicectl`,args:[`--version`],allowFailure:!0},r)),r);let t=await _n(e,r);if(i.devicectlConsoleCapture=t.supported,!t.supported){let e=t.reason===`unsupported`?hn:gn;a.push(`${e.message} ${e.hint}`)}}return{backend:C(t),checks:i,notes:a}}function yn(e,t){let n=Sn(e),r=[`subsystem == "${n}"`,`subsystem CONTAINS "${n}"`,`processImagePath ENDSWITH[c] "/${n}"`,`senderImagePath ENDSWITH[c] "/${n}"`];if(t){let e=Sn(t);r.push(`process == "${e}"`,`processImagePath ENDSWITH[c] "/${e}"`,`senderImagePath ENDSWITH[c] "/${e}"`,`processImagePath CONTAINS[c] "/${e}.app/"`,`senderImagePath CONTAINS[c] "/${e}.app/"`)}return r.join(` OR `)}function bn(e){return[...e.simulatorSetPath?[`simctl`,`--set`,e.simulatorSetPath]:[`simctl`],`spawn`,e.deviceId,`log`,`stream`,`--style`,`compact`,`--level`,`info`,`--predicate`,yn(e.appBundleId,e.executableName)]}function xn(e,t){return[`devicectl`,`device`,`process`,`launch`,`--device`,e,`--console`,`--terminate-existing`,t]}function Sn(e){return e.replaceAll(`\\`,String.raw`\\`).replaceAll(`"`,String.raw`\"`)}async function Cn(e,t,n,r,i){wn(t),Qe(e,n);let a=C(t),o=await En(e,t,n.appBundleId,i),s=new Ge,c=!1;try{let l=await e.outputs.openAppend(n.outputPath);s.defer(async()=>{c||await l[Symbol.asyncDispose]()}),i?.throwIfAborted();let u=await Tn(e,t,o,l,n.pidPath,i);s.defer(async()=>{c||await u[Symbol.asyncDispose]()});let d=On(e,u,l,a,n.outputPath),f={transport:a===`ios-device`?`coredevice-console`:`apple-log-stream`,backend:a,outputPath:n.outputPath,...n.pidPath===void 0?{}:{pidPath:n.pidPath}},p=Ye(d,pn({sessionId:n.sessionId,device:t,owner:r,fence:n.fence,descriptor:f}));return c=!0,p}finally{await s[Symbol.asyncDispose]()}}function wn(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`,S,{hint:S})}async function Tn(t,n,r,i,a,s){if(o(n)&&n.kind===`device`){let n=await _n(t,s);if(!n.supported){let t=n.reason===`unsupported`?hn:gn;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 En(e,t,n,r){if(s(t))return{executable:`log`,args:[`stream`,`--style`,`compact`,`--predicate`,yn(n)],allowFailure:!0};if(t.kind===`device`)return{executable:`xcrun`,args:xn(t.id,n),allowFailure:!0};let i=await Dn(e,t,n,r);return{executable:`xcrun`,args:bn({deviceId:t.id,appBundleId:n,executableName:i,simulatorSetPath:t.simulatorSetPath}),allowFailure:!0}}async function Dn(e,t,n,r){let i=t.simulatorSetPath?[`--set`,t.simulatorSetPath]:[],a=await e.appleTools.run({tool:`simctl`,args:[...i,`get_app_container`,t.id,n,`app`],allowFailure:!0,timeoutMs:4e3},r),o=a.exitCode===0?a.stdout.trim():``;if(!o)return;let s=await e.commands.run({executable:`plutil`,args:[`-extract`,`CFBundleExecutable`,`raw`,`-o`,`-`,Ut.join(o,`Info.plist`)],allowFailure:!0,timeoutMs:4e3},r);return s.exitCode===0&&s.stdout.trim()||void 0}function On(e,t,n,r,i){let a=e.clock.now(),o=`active`;t.wait.then(e=>{o=e.exitCode===0?`ended`:`failed`},()=>{o=`failed`});let s;return tt({inspect:()=>({backend:r,state:o,startedAt:a}),finish:async()=>s??=(async()=>(await kn([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 kn(e){let t=[];for(let n of e)try{await n()}catch(e){t.push(e)}return t}const w=f(`apple`),T=Object.freeze({available:!0});function An(t){return Object.freeze({owner:w,ownsDevice:e=>e.platform===`apple`,inspectFacts:async e=>Mn(e),bind:async n=>{if(n.intent.kind===`exact-owner`&&!p(n.intent.owner,w))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=Je({codec:sn,reattach:async(e,r)=>e.backend!==C(n)||!Ke(t,r.sessionId,e)?{status:`unreattachable`,reason:`descriptor-invalid`,message:`Apple app-log descriptor does not match the bound device or owning session`}:await qe(t,e.pidPath),cleanup:async(e,r)=>e.backend===C(n)&&Ke(t,r.sessionId,e)?await $e(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:C(n)}),appLogDoctor:async({appBundleId:e})=>await vn(t,n,e,r),appLogStart:async e=>await Cn(t,n,e,w,r),...i});return Object.freeze({device:n,owner:w,facts:Mn(n),operations:a,[Symbol.asyncDispose]:async()=>void 0})}function Mn(e){if(e.appleOs===`watchos`)return Nn(e);let t=o(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?{available:!1,reason:`unsupported-device-backend`,hint:S}:T;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:T,appLogCleanup:T}})}function Nn(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 Pn(e,t,n,r){let i=C(t),a=await e.appLogs.readRecent(n.sessionId,n.maxScanLines),o=Ze(a.text,{...n,path:a.path,exists:a.exists,lineNumberOffset:a.skippedLines,backend:i}),s=[];if(In(t,n,o.dump)){let i=await Ln(e,t,n,a.path,r);i&&(o=Fn(s,o,i,n.maxEntries))}return Bn(s,t,n),zn(s,o.dump),o.dump.entries.length===0&&s.push(Vn(t)),Object.freeze({source:`app-log`,backend:i,dump:o.dump,notes:Object.freeze(s)})}function Fn(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).`),et(n.scan,t,r))}function In(e,t,n){return o(e)&&e.kind===`simulator`&&!!t.appBundleId&&n.entries.length===0}async function Ln(e,t,n,r,i){let a=[...t.simulatorSetPath?[`--set`,t.simulatorSetPath]:[],`spawn`,t.id,`log`,`show`,`--style`,`compact`,`--info`,`--predicate`,Rn(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 Rn(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 zn(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 Bn(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 Vn(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 Hn(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 rt(r,{...c,...l.length>0?{warning:l.join(` `)}:{},...r.invalidatedReason?{overlayWarning:`overlay unavailable: ${r.invalidatedReason}`}:{}},{stopObservation:s,...o===void 0?{}:{nativePathDisposition:o}})}async function Un(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 Wn(()=>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 Wn(e){try{return await e()}catch(e){throw t(e,`COMMAND_FAILED`)}}const Gn=[`outPath`,`startedAt`,`clientOutPath`,...ct],E=Object.freeze({resourceKind:dt,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=>rr(e)});function Kn(e){let{device:t,owner:n,input:r,descriptor:a}=e;return Ue({resourceKind:dt,sessionId:r.sessionId,device:i(t),owner:n,fence:r.fence,lifecycle:`open`,descriptor:He(E,a)})}function qn(e){let t={};for(let n of Gn)e[n]!==void 0&&Object.assign(t,{[n]:e[n]});return t}async function Jn(e,t,n,r){let i=E.decode(n);return i.status!==`decoded`||!pr(t,i.descriptor)?{status:`cleanup-pending`,reason:`manual-recovery-required`}:i.descriptor.backend===`simctl`?await Yn(e,i.descriptor.processes,r):await Zn(e,t,i.descriptor)}async function Yn(e,t,n){let r=await Promise.all(t.map(async t=>await e.screenRecording.apple.inspectProcess(t)));if(r.includes(`ownership-lost`))return{status:`cleanup-pending`,reason:`ownership-fence-lost`};if(r.every(e=>e===`missing`))return n!==void 0&&e.screenRecording.ownedProcesses.clear(Xn(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(Xn(n)),i.every(e=>e===`already-missing`)?{status:`already-missing`}:{status:`cleaned`})}function Xn(e){return{kind:`session`,sessionId:e}}async function Zn(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 Qn(e){let{host:t,device:n,envelope:r}=e,i=E.decode(r.descriptor.body);return i.status===`decoded`?pr(n,i.descriptor)?i.descriptor.backend===`simctl`?await $n(e,i.descriptor):await tr(t,n,i.descriptor):D(`descriptor-invalid`,`Apple screen-recording descriptor does not match the bound device.`):D(`descriptor-invalid`,i.message)}async function $n(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 D(`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=er(ot(e.envelope.metadata),t.outputPath);return r===void 0||i!==void 0&&!await nr(e.host,i)?{status:`missing`}:{status:`restore-export`,recording:r,nativePath:t.outputPath,cleanup:async()=>await Yn(e.host,t.processes,e.envelope.sessionId)}}function er(e,t){if(e.finalization===void 0)return e.collectedPath??t}async function tr(e,t,n){let r=await e.screenRecording.apple.inspectRunner(t,n.runnerSessionId,n.runnerAuthority);return r===`missing`?{status:`missing`}:D(`transport-not-reattachable`,r===`ownership-lost`?`Apple recording ownership no longer matches the durable descriptor.`:`Apple screen recordings require exact cleanup after daemon restart.`)}async function nr(e,t){try{return await e.screenRecording.finalize.sniff({outputPath:t}),!0}catch{return!1}}function D(e,t){return{status:`unreattachable`,reason:e,message:t}}function rr(e){return typeof e.outputPath!=`string`||e.outputPath.length===0?k():e.backend===`simctl`?ir(e,e.outputPath):e.backend===`runner`?sr(e,e.outputPath):k()}function ir(e,t){let n=mr(e.processes),r=ar(e.recording);return!n||r===`invalid`?k():{status:`decoded`,descriptor:Object.freeze({backend:`simctl`,outputPath:t,processes:n,...r===void 0?{}:{recording:r}})}}function ar(e){if(e!==void 0)return n(e)&&or(e)?Object.freeze(e):`invalid`}function or(e){return O(e.outPath)&&lr(e.startedAt)&&cr(e.clientOutPath)&&at(e)}function sr(e,t){return!O(e.appBundleId)||!O(e.runnerSessionId)||!ur(e.runnerAuthority)||!dr(e.remotePath)?k():{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 O(e){return typeof e==`string`&&e.length>0}function cr(e){return e===void 0||O(e)}function lr(e){return typeof e==`number`&&Number.isFinite(e)}function ur(e){return e===`local-lease`||e===`scoped-provider`}function dr(e){return e===void 0||fr(e)}function fr(e){return typeof e==`string`&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(e)}function pr(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&&fr(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 k(){return{status:`invalid`,message:`Invalid Apple screen-recording descriptor`}}async function hr(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 gr=`iOS recording`,_r=`simctl recordVideo`;function vr(e){return e.appleOs===`watchos`?Mr(`unsupported-platform-leaf`,`watchOS recording is not supported.`):o(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?Mr(`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 yr(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await br({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async e=>{let r=await Qn({host:t,device:n,envelope:e.envelope});return r.status===`restore-export`?{status:`active`,handle:Sr({host:t,restored:r})}:r},screenRecordingCleanup:async e=>await Jn(t,n,e.envelope.descriptor.body,e.envelope.sessionId)})}async function br(e){return e.signal.throwIfAborted(),e.device.kind===`simulator`?await xr(e):await wr(e)}async function xr(e){let{host:t,device:n,owner:r,input:i,signal:a}=e;await hr(n,i,t.screenRecording.apple.isRunnerBundleId);let o=i.activeSessionApp?await t.screenRecording.apple.captureClockAnchor(n,i.activeSessionApp.bundleId,a):void 0,s=St(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 A(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 A(c).catch(()=>{}),e}let u,d,f=async()=>{await c.terminate();let e=await c.wait;return d=e,u=Er(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=jr(i,_r,{},o);return Ar({device:n,owner:r,input:i,descriptor:{backend:`simctl`,outputPath:s,processes:l,recording:qn(p)},snapshot:p,finish:(e,n)=>ut({snapshot:e,progress:n,steps:{stop:f,collect:async e=>{try{await Cr(t,s,e)}catch(e){throw Dr(e,u,d)}},finalize:async({collectedPath:n,exportPath:r})=>{try{return await Un({host:t,snapshot:e,targetLabel:gr,collectedPath:n,exportPath:r,nativePath:s})}catch(e){throw Dr(e,u,d)}},discard:async e=>{await t.screenRecording.outputs.remove(e)}}}),cleanup:async()=>{let e=await kr(c);return(e.status===`cleaned`||e.status===`already-missing`)&&t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId}),e}})}function Sr(e){let{host:t,restored:{recording:n,nativePath:r,cleanup:i}}=e,a=Object.freeze({...n,backend:_r,gestureEvents:[]});return nt(a,{finish:(e,i)=>ut({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 Cr(t,r,e)},finalize:async({collectedPath:i,exportPath:a})=>await Un({host:t,snapshot:e,targetLabel:gr,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 Cr(e,t,n){await e.screenRecording.outputs.copy({from:t,to:n}),await e.screenRecording.finalize.sniff({outputPath:n})}async function wr(e){let{host:t,device:n,owner:r,input:i,signal:a}=e,o=i.activeSessionApp?.bundleId;if(!o)throw TypeError(`Apple runner recording requires an active app session identity`);await t.screenRecording.outputs.prepare(i.outputPath);let s=await t.screenRecording.apple.runRunner(n,{kind:`start`,appBundleId:o,outputPath:i.outputPath,...i.fps===void 0?{}:{fps:i.fps}},a);if(!s.runnerSessionId||!s.runnerAuthority)throw Error(`Apple runner recording did not expose durable session ownership`);let c={runnerSessionId:s.runnerSessionId,runnerAuthority:s.runnerAuthority},l,u=()=>(l??=Tr(()=>t.screenRecording.apple.runRunner(n,{kind:`stop`,appBundleId:o,...c}).then(()=>void 0)).catch(e=>{throw l=void 0,e}),l);if(!Or(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 Ar({device:n,owner:r,input:i,descriptor:{backend:`runner`,outputPath:i.outputPath,appBundleId:o,...c,...s.remotePath===void 0?{}:{remotePath:s.remotePath}},snapshot:jr(i,`runner AVAssetWriter`,s),finish:async e=>(await u(),s.remotePath!==void 0&&await t.screenRecording.apple.retrieveRunnerRecording(n,s.remotePath,e.outPath),await Hn({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 Tr(e){try{return await e()}catch(e){throw t(e,`COMMAND_FAILED`)}}function Er(e){if(e.exitCode!==0)return e.signal?`simctl recordVideo was killed by ${e.signal}`:`simctl recordVideo exited with code ${e.exitCode}`}function Dr(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}`,te(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 Or(e,t){return e.appleOs===`macos`||!o(e)?t===void 0:t!==void 0&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(t)}async function A(e){return await e.terminate(),await e.wait}async function kr(e){try{return await A(e),{status:`cleaned`}}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`Apple simulator cleanup failed`}}}function Ar(e){let{device:t,owner:n,input:r,descriptor:i,snapshot:a,finish:o,cleanup:s}=e,c=nt(a,{finish:o,forceCleanup:s});return Object.freeze({pendingHandle:new We(c),envelope:Kn({device:t,owner:n,input:r,descriptor:i})})}function jr(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 Mr(e,t){return Object.freeze({available:!1,reason:e,hint:t})}const Nr=15e3;async function j(e,t,n,r={}){return n.throwIfAborted(),await wt(t)||s(t)?{...t,booted:!0}:t.kind===`device`?(await e.deviceReadiness.applePhysical.ensureConnected(t,n),{...t,booted:!0}):t.kind===`simulator`?((await Pr(e,t)?`Booted`:await Rr(e,t,n))!==`Booted`&&(r.onColdBootStart?.(),e.deviceReadiness.appleAutomation.keepHot(t),await Fr(e,t,n,r.deadlineAtMs),await zr(e,n)),e.deviceReadiness.appleAutomation.keepHot(t),e.deviceReadiness.appleAutomation.markBooted(t),{...t,booted:!0}):{...t,booted:!0}}async function Pr(e,t){try{return await e.deviceReadiness.appleAutomation.wasRecentlyObservedBooted(t)}catch{return!1}}async function Fr(e,t,n,r=Date.now()+12e4){let i=!1;try{i=await Ir(e,t,n,r),await Lr(e,t,n,r)}catch(a){throw i&&n.aborted&&Br(e,t),n.throwIfAborted(),Date.now()>=r?N(t,a):a}}async function Ir(t,n,r,i){let a=await t.appleTools.run({tool:`simctl`,args:_(n,[`boot`,n.id]),allowFailure:!0,timeoutMs:M(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 Lr(t,n,r,i){ce({type:`command`,status:`progress`,message:`Waiting for the Simulator to finish booting...`});let a=await t.appleTools.run({tool:`simctl`,args:_(n,[`bootstatus`,n.id,`-b`]),allowFailure:!0,timeoutMs:M(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 zt(t.appleTools,n,r,Math.min(Nr,M(i,n)))!==`Booted`)throw new e(`COMMAND_FAILED`,`Simulator is still booting`,{deviceId:n.id});if(Date.now()>=i)throw N(n)}function M(e,t){let n=e-Date.now();if(n<=0)throw N(t);return n}function N(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 Rr(e,t,n){return await zt(e.appleTools,t,n,Nr)}async function zr(e,t){await e.commands.run({executable:`open`,args:[`-a`,`Simulator`],allowFailure:!0,timeoutMs:1e4},t)}function Br(e,t){e.appleTools.run({tool:`simctl`,args:_(t,[`shutdown`,t.id]),allowFailure:!0}).catch(()=>{})}const Vr=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 Hr(e){return e===void 0?`possible`:e.some(e=>Vr[e]===`runner`)?`required`:`none`}const Ur=new Map([[`application-element-missing`,5e3],[`application-server-unavailable`,5e3],[`foreground-owner-unverified`,1e3],[`foreground-owner-changed`,1e3]]);function P(e){return e.platform===`apple`&&e.appleOs===`ios`&&e.kind===`simulator`}function Wr(e){let t=re(ae({depth:1,interactiveOnly:!0}));return Object.freeze({awaitObservable:async(n,r,i)=>{if(!P(n))return`not-eligible`;let a;for(;;){let o=await e.resolveTarget(n,r,i).catch(()=>void 0);if(i.throwIfAborted(),!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=Ur.get(s.failure.code);if(c===void 0)return`unobservable`;let l=e.clock.now();if(a=Math.min(a??1/0,l+c),l>=a)return`unobservable`;await e.clock.sleep(Math.min(150,a-l),i)}}})}function Gr(e,t,n){let r=n&&P(e),i=r?Hr(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 Kr(e,t,n,r){r.runnerDemand===`none`&&e.appleApplications.releaseSpeculativeRunner(t.device,n.execution).catch(()=>{})}async function qr(e,t,n,r,i,a){let o=Date.now();r&&P(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 Jr(e){let t=Et({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 j(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 Yr(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 ai(e.host,t,n),finalizeApplicationClose:async t=>await oi(e.host,e.device,e.signal,t),prepareAppleRunner:async t=>await si(e.host,e.device,e.signal,t),configureProviderPortReverse:fi})}async function Yr(e,t,n,r){let i={},a=F(t.device),o=ci(e,t,n,i),s=Gr(t.device,n,a);s.runnerDemand&&(i.runnerDemand=s.runnerDemand),Kr(e,t,n,s);let{shouldPrewarmRunner:c}=s,l=ii(t.device,n,a);a&&c&&!n.prewarmRunnerBeforeOpen&&o.schedule();try{await Xr(e,t,n,a,l,i),await Zr(n,i),await Qr(o,c,n.prewarmRunnerBeforeOpen);let u=o.wasAwaited();return await $r(t,n,a,i),await ti(o,c,s.awaitPrewarmAfterOpen),await ni(e,t,n,a,u,l),await qr(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 Xr(e,t,n,r,i,a){if(!ri(n,r)||!n.target)return;let o=Date.now();c(t.device.platform)&&!r&&!i&&await e.appleApplications.stopRunnerSession(t.device.id),await Tt({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=I(o)}async function Zr(t,n){if(!ue(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=I(r)}async function Qr(e,t,n){!t||!n||(e.schedule(!0),await e.wait())}async function $r(e,t,n,r){let i=ui(t,n),a=Date.now();await Dt({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=I(a),await ei(e,t,i.followUpUrl,r)}async function ei(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 Dt({device:e.device,interactor:await e.resolveInteractor(i,t.appBundleId),positionals:[n],appBundleId:t.appBundleId,execution:i}),r.launchUrlDurationMs=I(a)}async function ti(e,t,n){t&&!e.wasScheduled()&&e.schedule(),n?await e.wait():e.recordUnawaited()}async function ni(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 ri(e,t){return!!(e.relaunch&&e.target)&&!(t&&!e.execution.clearAppState)}function ii(e,t,n){return e.kind===`device`&&e.appleOs===`ios`&&ri(t,n)}async function ai(e,t,n){n.ensureReady&&await j(e,t.device,t.signal),c(t.device.platform)&&!F(t.device)&&await e.appleApplications.stopRunnerSession(t.device.id),await Tt({device:t.device,interactor:await t.resolveInteractor(n.execution,n.appBundleId),positionals:n.positionals}),F(t.device)&&await e.clock.sleep(300,t.signal)}async function oi(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&&F(t)?await e.deviceShutdown.apple.shutdownTarget(t,n):void 0;return i===void 0?{}:{shutdown:i}}async function si(e,t,n,r){let i=Date.now()+r.timeoutMs;await j(e,t,n,{deadlineAtMs:i});let a=Math.max(1,i-Date.now());return await e.appleApplications.prepareRunner(t,{...r,timeoutMs:a},n)}function ci(e,t,n,r){let i,a=!1,o=li(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=I(e)},wasAwaited:()=>a,wasScheduled:()=>i!==void 0,recordUnawaited:()=>{i&&!a&&(r.runnerPrewarmWaited=!1)}}}function li(e,t){return e.kind===`device`&&e.appleOs===`ios`&&!t.hasExistingSession&&!t.relaunch&&!t.prewarmRunnerBeforeOpen}function ui(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&&!di(e)?{positionals:[i,n]}:{positionals:e.positionals,followUpUrl:n}}function di(e){return e.execution.clearAppState===!0||!!e.execution.launchConsole?.trim()||!!e.execution.launchArgs?.length}function F(e){return o(e)&&e.kind===`simulator`}function I(e){return Math.max(0,Date.now()-e)}async function fi(){throw new e(`UNSUPPORTED_OPERATION`,`This lifecycle operation is unavailable for Apple.`)}const pi=Object.freeze({available:!0}),mi=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.`}),gi=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),_i=Object.freeze({available:!1,reason:`unsupported-device-kind`});function vi(e){let t=Ei(e);return Object.freeze({deployApp:t,materializeAppSource:t,deployMaterializedApp:t,sendPushNotification:Di(e)})}function yi(e){let{host:t,device:n,signal:r}=e,i=vi(n);return Object.freeze({...i.deployApp.available?{deployApp:async e=>await bi(t,n,e,r),materializeAppSource:async e=>await t.appleDeployment.prepareArtifact(e,{signal:r}),deployMaterializedApp:async e=>await xi(t,n,e,r)}:{},...i.sendPushNotification.available?{sendPushNotification:async e=>(await wi(t,n,e,r),{})}:{}})}async function bi(e,t,n,r){if(n.replaceExisting)return await e.appleDeployment.withInvalidatedAppResolutionCache(t,async()=>{let i=await e.appleDeployment.resolveAppBundleId(t,n.app);await Ci(e,t,i,r);let a=await e.appleDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{appIdentifierHint:n.app,signal:r});try{return await Si(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 xi(e,t,{artifact:i},r)}finally{await i.cleanup()}}async function xi(e,t,n,r){return await Si(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 Si(e,t,n,r){await j(e,t,r),L(await e.appleTools.run(t.kind===`simulator`?{tool:`simctl`,args:_(t,[`install`,t.id,n])}:{tool:`devicectl`,args:[`device`,`install`,`app`,`--device`,t.id,n],timeoutMs:12e4},r),`Apple app install failed`)}async function Ci(e,t,n,r){await j(e,t,r);let i=await e.appleTools.run(t.kind===`simulator`?{tool:`simctl`,args:_(t,[`uninstall`,t.id,n]),allowFailure:!0}:{tool:`devicectl`,args:[`device`,`uninstall`,`app`,`--device`,t.id,n],allowFailure:!0},r);i.exitCode===0||Ti(`${i.stdout}\n${i.stderr}`)||L(i,`Apple app uninstall failed for ${n}`)}async function wi(t,n,r,i){if(n.kind!==`simulator`)throw new e(`UNSUPPORTED_OPERATION`,`Apple push notifications require a simulator`);await j(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`),L(await t.appleTools.run({tool:`simctl`,args:_(n,[`push`,n.id,r.appId,a.path])},i),`Apple push notification failed`)}finally{await a[Symbol.asyncDispose]()}}function Ti(e){let t=e.toLowerCase();return t.includes(`not installed`)||t.includes(`not found`)||t.includes(`no such file`)}function L(t,n){if(t.exitCode!==0)throw new e(`COMMAND_FAILED`,n,{stdout:t.stdout,stderr:t.stderr,exitCode:t.exitCode})}function Ei(e){return Oi(e)?e.kind!==`simulator`&&e.kind!==`device`?_i:e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?mi:pi:gi}function Di(e){return Oi(e)?e.kind===`simulator`?pi:hi:gi}function Oi(e){return o(e)&&e.appleOs!==`watchos`}const R=Object.freeze({available:!0}),ki=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`back is supported on Apple simulators and physical devices.`}),Ai=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function ji(e){return e.kind!==`simulator`&&e.kind!==`device`?ki:d(e)===`watchos`?Ai:R}const Mi=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`home is supported on Apple simulators and physical devices.`}),Ni=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Pi=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`app-switcher is supported on Apple simulators and physical devices.`});function Fi(e,t){if(e.kind!==`simulator`&&e.kind!==`device`)return t;let n=d(e);return n===`macos`||n===`watchos`?Ni:R}function z(e){if(e.kind!==`simulator`&&e.kind!==`device`)return!1;let t=d(e);return t!==`tvos`&&t!==`macos`&&t!==`watchos`}const Ii=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`orientation is supported on Apple simulators and physical devices.`}),Li=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function Ri(e){return e.kind!==`simulator`&&e.kind!==`device`?Ii:z(e)?R:Li}const zi=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`tv-remote is supported only on tvOS devices.`});function Bi(e){return(e.kind===`simulator`||e.kind===`device`)&&a(e)?R:zi}const B=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Vi=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 Hi(e){return z(e)?Vi:B}function Ui(e){return z(e)?R:B}function Wi(e){return z(e)?R:B}const Gi=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`No Apple leaf carries this system button.`}),Ki=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`action-button is supported on iPhone and iPad simulators and physical devices.`}),qi=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 Ji(e){return e.kind!==`simulator`&&e.kind!==`device`?Ki:l(e)?R:qi}function Yi(e){return Object.freeze({...Ie({back:ji(e)}),...Ne({unsupported:Gi,home:Fi(e,Mi),appSwitcher:Fi(e,Pi),actionButton:Ji(e)}),...De({orientation:Ri(e)}),...Pe({tvRemote:Bi(e)}),...Oe({unsupported:B,status:Hi(e),dismiss:Ui(e),enter:Wi(e)})})}function Xi(e){let{host:t,device:n,signal:r}=e;return ht({device:n,signal:r,resolveInteractor:t.localInteractors.resolve,facts:Yi(n)})}const V=Object.freeze({available:!0}),Zi=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`clipboard is supported on Apple simulators and the macOS host.`}),Qi=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`settings is supported on Apple simulators and the macOS host.`}),$i=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."}),ta=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`clipboard is supported on Apple simulators and the macOS host, not on physical devices of this OS.`}),H=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function na(e,t,n){if(e.kind!==`simulator`&&e.kind!==`device`)return t;let r=d(e);return r===`watchos`?H:e.kind===`simulator`||r===`macos`?V:n}function ra(e){return na(e,Zi,ta)}const ia=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`trigger-app-event is supported on Apple simulators and physical devices.`}),aa=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`alert is supported on Apple simulators and physical devices.`}),oa=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`alert is supported on Apple simulators, the macOS host, and physical iOS devices.`});function sa(e){if(e.kind!==`simulator`&&e.kind!==`device`)return aa;let t=d(e);return t===`watchos`?H:e.kind===`simulator`||t===`ios`||t===`macos`?V:oa}function ca(e){return e.kind!==`simulator`&&e.kind!==`device`?ia:d(e)===`watchos`?H:V}function la(e){let t=ra(e);return t.available?ta:t}function ua(e){return e.kind!==`simulator`&&e.kind!==`device`?Qi:d(e)===`watchos`?H:u(e)?V:ea}function da(e){let t=ra(e),n=sa(e);return Object.freeze({...je({unsupported:la(e),read:t,write:t}),...Me({read:n,wait:n,accept:n,dismiss:n}),...Ae({triggerAppEvent:ca(e)}),...Ee({setSetting:na(e,Qi,$i),readSetting:ua(e)})})}function fa(e){let{host:t,device:n,signal:r}=e;return ht({device:n,signal:r,resolveInteractor:t.localInteractors.resolve,facts:da(n)})}const pa=/Angle:\s*(-?\d+(?:[.,]\d+)?)\s*°/g;async function ma(t,n={}){let r=[`devicectl`,`device`,`motion`,`hinge-angle`,`--device`,t.id,`--session-timeout`,`1`,`--timeout`,`5`],i=await jt(r,{allowFailure:!0,signal:n.signal,timeoutMs:kt}),a=ha(i.stdout)??ha(i.stderr);if(a!==void 0)return a;throw new e(`COMMAND_FAILED`,`CoreDevice reported no hinge angle sample`,te(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 ha(e){let t;for(let n of e.matchAll(pa)){let e=Number.parseFloat(n[1].replace(`,`,`.`));Number.isFinite(e)&&(t=e)}return t}const ga={closed:`closed`,"half-open":`book`,open:`open`};async function _a(e,t,n={}){Nt(e,`fold`),va(e,await Lt(e,{signal:n.signal})),await Ft({deviceHub:!0,background:!0,signal:n.signal});let r=await It({udid:e.id,deviceName:e.name,pose:ga[t],signal:n.signal});g({level:`info`,phase:`apple_fold_pose_pressed`,data:{deviceId:e.id,pose:t,control:r.control,windowTitle:r.windowTitle,reopened:r.reopened,selected:r.selected}});let i=await ya(e,t,n.signal),a=await wa(e,n.signal);return{pose:t,hingeAngleDegrees:i,...a?{screen:Ta(a)}:{}}}function va(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 drives the pose controls Xcode Device Hub shows for a foldable simulator such as iPhone Duo; this simulator reports one integrated panel, so it has no hinge to pose.`})}async function ya(e,t,n){let r,i;for(let a=1;a<=4;a+=1)if(n?.throwIfAborted(),i=r,r=await ma(e,{signal:n}),h(r)===t&&(t!==`half-open`||i!==void 0&&ba(r,i)))return r;throw r!==void 0&&t===`half-open`&&h(r)===t?Ca(e,r,i):Sa(e,t,r)}function ba(e,t){return h(e)===`half-open`&&h(t)===`half-open`&&Math.abs(e-t)<=.5}function xa(e,t,n){return{deviceId:e.id,requestedPose:t,observedPose:n===void 0?void 0:h(n),hingeAngleDegrees:n}}function Sa(t,n,r){return new e(`COMMAND_FAILED`,`${t.name} did not reach the ${n} pose: CoreDevice still reports a hinge angle of ${r}°`,{...xa(t,n,r),reason:`fold-pose-unverified`,hint:`The Device Hub pose control was pressed, but the hinge did not follow. If several Device Hub windows are titled with this device name, close the ones for other simulators so the press reaches this one, then retry.`})}function Ca(t,n,r){return new e(`COMMAND_FAILED`,`${t.name} was observed half-open at ${n}° but did not settle: 4 hinge reads never held two consecutive half-open angles within ${Ot}° of each other`,{...xa(t,`half-open`,n),reason:`fold-pose-unsettled`,...r===void 0?{}:{previousHingeAngleDegrees:r},hint:`The hinge reached the requested pose and was still moving when the read budget ended. Retry the fold, then read the angle directly with xcrun devicectl device motion hinge-angle --device <udid> --session-timeout 1 --timeout 5 to see whether the simulator holds the pose.`})}async function wa(e,t){let n=await Lt(e,{signal:t});if(!(n.unresolved||n.ambiguous))return n.activeDisplay}function Ta(e){return{display:e.name,coordinateSpace:se,widthPt:Math.round(e.widthPx/e.pointScale),heightPt:Math.round(e.heightPx/e.pointScale)}}const Ea=Object.freeze({available:!0}),Da=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`fold is supported on foldable iPhone simulators driven by Xcode Device Hub; a physical device is folded by hand.`}),Oa=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 Da;let t=d(e);return t===`ios`||t===`ipados`?Ea:Oa}function Aa(e){return oe({fold:ka(e)})}function ja(e){let{device:t,signal:n}=e;return m(Aa(t).setFoldPose,()=>({setFoldPose:async e=>(n.throwIfAborted(),await _a(t,e.pose,{signal:n}))}))}function Ma(e,t,n){let r=Le({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,Te(t.signal,i));if(!n)return await r.captureSnapshot(i);let a=Te(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 Na(e,t){return Object.freeze({findText:async n=>{let r=await Pa(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 Pa(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 Fa(e,t.device,n.execution))return{appBundleId:r,signal:a}}async function Fa(e,t,n){return!P(t)||await e.appleApplications.hasLiveRunnerSession(t,n??{})}function Ia(){let e,t=!1,n=async()=>(e??=import(`./adapter.js`).then(({createSimulatorSnapshotSource:e})=>e()),await e);return{acquire:async e=>t?{stage:`failed`,failure:{kind:`unsupported`,code:`source-closed`}}:await(await n()).acquire(e),close:async()=>{t=!0,e&&await(await e).close()}}}const La=3e3;function Ra(){let e=new Map,t=new Map,n=Bt({waitMs:1500});return async(r,i,a,o)=>{a.throwIfAborted();let s=`${r.id}:${i}`,c=e.get(s);return c&&o!==`refresh`&&await Ht(c.pid,{signal:a,timeoutMs:La})===c.processStartTime?c:(e.delete(s),await n.value(s,{start:async()=>{let n=await za(r,i,t);return e.set(s,n),n},wait:(e,t)=>Vt({waitMs:e,signal:a,stop:t,cancelled:()=>a.reason}),pending:()=>W(`simulator-target-discovery-pending`,r,i)}))}}async function za(e,t,n){let r=Date.now()+15e3,[i,a]=await Promise.allSettled([Mt(e,[`spawn`,e.id,`launchctl`,`list`],{allowFailure:!0,timeoutMs:U(r)}),Ba(e,n,r)]);if(i.status===`rejected`)throw i.reason;if(a.status===`rejected`)throw a.reason;let o=i.value,s=a.value;if(o.exitCode!==0)throw W(`simulator-target-probe-failed`,e,t);let c=Va(o.stdout,t);if(!c)throw W(`simulator-target-unavailable`,e,t);let l=await Ht(c.pid,{timeoutMs:Math.min(La,U(r))});if(!l)throw W(`simulator-target-identity-unavailable`,e,t);return Object.freeze({udid:e.id,runtime:s,pid:c.pid,generation:`${c.pid}:${c.label}:${l}`,targetId:`${e.id}:${t}`,processStartTime:l})}async function Ba(e,t,n){let r=t.get(e.id);if(r)return await r;let i=Mt(e,[`list`,`devices`,`-j`],{allowFailure:!0,timeoutMs:U(n)}).then(t=>{if(t.exitCode!==0)throw W(`simulator-runtime-probe-failed`,e,``);let n=JSON.parse(t.stdout),r=Object.entries(n.devices??{}).find(([,t])=>t.some(t=>t.udid===e.id))?.[0];if(!r)throw W(`simulator-runtime-unavailable`,e,``);return r});t.set(e.id,i);try{return await i}catch(n){throw t.delete(e.id),n}}function Va(e,t){for(let n of e.split(`
|
|
4
|
-
`)){let[e,,r]=n.trim().split(/\s+/);if(!e||!r||!r.startsWith(`UIKitApplication:${t}[`))continue;let i=Number(e);if(Number.isSafeInteger(i)&&i>0)return{pid:i,label:r}}}function U(e){return Math.max(1,e-Date.now())}function W(t,n,r){return new e(`COMMAND_FAILED`,`Unable to resolve the running iOS Simulator app (${t}).`,{reason:t,deviceId:n.id,appBundleId:r})}function Ha(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 Ua(n,r);return a!==`absent`&&a!==`unknown`&&t.set(n.id,{at:e(),host:a.host}),a}}async function Ua(e,t){let n=!1;for(let r of ft){let i=await Wa(r.processExecutable,t);if(i===`unknown`){n=!0;continue}for(let a of i){let i=await Ga(a,e.id,t);if(i===`unknown`)n=!0;else if(i)return{kind:`present`,host:r}}}return n?`unknown`:`absent`}async function Wa(e,t){let n=await Ka(`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 Ga(e,t,n){let r=await Ka(`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 Ka(e,t,n){try{let r=await At(e,t,{allowFailure:!0,timeoutMs:3e3,...n?{signal:n}:{}});return{exitCode:r.exitCode,stdout:r.stdout}}catch{return`unknown`}}const qa=`system-surface-presented`,Ja=`system-surface-host-lingering`,Ya=`window-coordinate-space-unresolved`;function Xa(t,n={}){let r=n.source??Ia(),i=n.resolveTarget??Ra(),a=n.systemSurfacePresent??Ha(),o=new Set,s=new Map,c=e=>(uo(e,s,o),o.has(fo(e))),l=Wr({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(!$a(n,s))return await ro(n,s,u);let d=await a(n,l);if(d===`unknown`)return await G(n.id,s,u,K(n.id,s),q(s),`system-surface-probe-unavailable`,[lo()]);if(d!==`absent`)return await no(n,s,u,d.host.bundleId);let f;try{f=await Za(t,i,n,s,l)}catch(e){return l.throwIfAborted(),J(`target-resolution-failed`,n,void 0,e),await G(n.id,s,u,K(n.id,s),q(s),`target-resolution-failed`,[lo()])}if(c(f))return await G(n.id,s,u,f,q(s),`circuit-disabled`);let p=q(s),m=await r.acquire({target:f,hint:re(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 co(m.failure,f,n,s.options.appBundleId,l,i);return await eo(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 eo(s,u,f,{lineage:f,residue:[]},p,{kind:`malformed-tree`,code:`presentation-invariant`},o,e)}}})}async function Za(e,t,n,r,i){let a=r.options.appBundleId;for(;;)try{return await t(n,a,i)}catch(t){if(!Qa(t))throw t;let i={requestId:r.execution?.requestId};if(await e.appleApplications.hasLiveRunnerSession(n,i))throw t}}function Qa(t){return t instanceof e&&t.details?.reason===`simulator-target-discovery-pending`}function $a(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 eo(e,t,n,r,i,a,o,s){return to(a)&&o.add(fo(n)),J(a.code,{id:n.udid},n.generation,s,a.details),await G(n.udid,e,t,r.lineage,i,a.code,r.residue)}function to(e){return e.kind!==`preparing`&&e.code!==Ya}async function G(e,t,n,r,i,a,o=[]){return io(e,await n(t),r,i,a,o)}async function no(e,t,n,r){let i=await n(t),a=i.systemSurface?qa:Ja;return i.systemSurface||J(a,e,void 0,void 0,{detectedHost:r}),io(e.id,i,K(e.id,t),q(t),a)}async function ro(e,t,n){let r=await n(t),i=r.systemSurface;return i?{...r,comparisonIdentity:oo(ao(e.id,i.bundleId),q(t),[])}:r}function io(e,t,n,r,i,a=[]){let o=t.systemSurface;return{...t,comparisonIdentity:oo(o?ao(e,o.bundleId):n,r,[...o?[]:a,{kind:`fallback-source`,producer:`apple-runner`}]),warnings:[...t.warnings??[],so(i,n,o!==void 0)]}}function K(e,t){return{targetId:`${e}:${t.options.appBundleId}`}}function ao(e,t){return{targetId:`${e}:${t}`}}function oo(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:ie(t),residue:Object.freeze([...n])})}function so(e,t,n){return e===qa?`Simulator AX snapshot inapplicable (${e}); used XCTest to read the system surface presented over the app.`:e===Ja?`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===Ya?`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 co(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:[lo()]}}}function lo(){return{kind:`unknown-generation`,captureId:Wt()}}function q(e){return ae({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 uo(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 fo(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`}),po=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.`}),mo=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.`}),ho=Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`perf requires an Apple simulator, macOS device, or CoreDevice-backed physical Apple device.`}),go=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: 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).`}),vo=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Headless boot is supported only for local Android emulators.`}),yo=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS has no XCUITest-driveable UI, so element text comes from the captured tree only.`}),bo=Object.freeze({available:!1,reason:`unsupported-device-kind`}),xo=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS open is not supported because XCUITest cannot drive watchOS UI.`}),So=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS runner preparation is not supported because XCUITest cannot drive watchOS UI.`}),Co=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS close is not supported because XCUITest cannot drive watchOS UI.`}),wo=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Runtime hints are supported only for local iOS-family simulators and Android devices.`}),To=Q(`open is supported only for Apple simulators and devices.`),Eo=Q(`prepare is supported only for Apple simulators and devices.`),Do=Q(`close is supported only for Apple simulators and devices.`),Oo=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`}),ko=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`shutdown is supported only for Apple simulators and Android emulators.`}),Ao=Q(`snapshot is supported only for Apple simulators and devices.`),jo=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Re-run without --actions, or target an iOS simulator.`}),Mo=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`screenshot is not supported on watchOS because XCUITest cannot drive watchOS UI.`}),No=Q(`screenshot is supported only for Apple simulators and devices.`),Po=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 Fo(e){return!o(e)||e.appleOs===`watchos`?Z:e.kind===`simulator`?X:ko}function Io(e){let t=Lo(e),n=Ro(e),r=zo(e),i=Bo(e);return de({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:i,clearRuntimeHints:i,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:n,configureProviderPortReverse:Oo})}function Lo(e){return d(e)===`watchos`?xo:e.kind===`simulator`||e.kind===`device`?X:To}function Ro(e){return d(e)===`watchos`?So:e.kind===`simulator`||e.kind===`device`?X:Eo}function zo(e){return d(e)===`watchos`?Co:e.kind===`simulator`||e.kind===`device`?X:Do}function Bo(e){return d(e)!==`watchos`&&o(e)&&e.kind===`simulator`?X:wo}function Vo(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:go}function Ho(e){let t=An(e),n=Xa(e),r=async n=>{let r=await t.inspectFacts(n),i=vi(n),a=vr(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=Vo(n);return Object.freeze({device:r.device,operations:{...r.operations,...i,appState:_o,networkDump:X,screenRecordingStart:l,screenRecordingReattach:l,screenRecordingCleanup:l,...qo(n),...he({capture:Ko(n)}),...Se({findText:Go(n)}),...ve({setViewport:po}),..._e({focus:$(n)}),...$t(n),...me({type:$(n)}),...Be({unsupported:Z,tap:$(n),longPress:$(n),fill:$(n),...o(n)?{tapElementSelector:$(n)}:{}}),...Fe({readTextAtPoint:Wo(n)}),...Yi(n),...Aa(n),...da(n),...Re({capture:Kt(n),query:mo}),...ze(Uo(n)),ensureReady:u,bootTarget:d,bootTargetHeadless:vo,listApps:f,...Io(n),shutdownTarget:Fo(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,...yi({host:e,device:i.device,signal:i.scope.signal}),networkDump:async t=>await Pn(e,i.device,t,i.scope.signal),...m(s,()=>yr({host:e,device:i.device,owner:Y,signal:i.scope.signal})),...m(o.operations.audioProbeStart,()=>Xe({host:e.audioProbe.hostCapture,device:i.device,owner:Y})),...m(o.operations.perfFrames,()=>qt({resolveHost:()=>e.perf.apple,device:i.device,owner:Y})),...m(o.operations.captureSnapshot,()=>Ma(e,{device:i.device,signal:i.scope.signal},n)),...m(o.operations.captureScreenshot,()=>we({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...m(o.operations.focusPoint,()=>xe({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...ke({device:i.device,signal:i.scope.signal,facts:o.operations,resolveInteractor:e.localInteractors.resolve}),...m(o.operations.scrollDirection,()=>be({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...m(o.operations.typeText,()=>Ce({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...m(o.operations.tapPoint,()=>Ve({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,()=>pe({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...m(o.operations.findText,()=>Na(e,{device:i.device,signal:i.scope.signal})),...Xi({host:e,device:i.device,signal:i.scope.signal}),...fa({host:e,device:i.device,signal:i.scope.signal}),...ja({device:i.device,signal:i.scope.signal}),...m(o.operations.ensureReady,()=>({ensureReady:async()=>await j(e,i.device,i.scope.signal)})),...m(o.operations.bootTarget,()=>({bootTarget:async()=>await j(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}))}})),...le(Jr({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:Gt(c),[Symbol.asyncDispose]:async()=>await a[Symbol.asyncDispose]()})},shutdown:async()=>{await Promise.all([t.shutdown(),n.shutdown()])}})}function Uo(e){let t=e.iosPhysicalDeviceBackend!==`xctest`&&d(e)!==`watchos`?X:ho;return{frames:t,memorySample:t,memorySnapshot:t,nativeCapture:t,profileReport:t}}function Wo(e){return d(e)===`watchos`?yo:e.kind===`simulator`||e.kind===`device`?X:bo}function Go(e){return d(e)===`watchos`?Ao:e.kind===`simulator`||e.kind===`device`?X:Ao}function Ko(e){return d(e)===`watchos`?Mo:e.kind===`simulator`||e.kind===`device`?X:No}function qo(e){let t=Go(e);return ge({capture:t,customActions:t.available&&o(e)&&e.kind===`simulator`?X:jo,withoutActiveApp:o(e)?Po:t})}export{Ho as createApplePlatformRuntime};
|
|
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:Qe(`${c.join(`
|
|
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};
|
package/dist/src/runtime5.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{L as e}from"./sdk-contracts.js";import{d as t}from"./sdk-device.js";import{n
|
|
1
|
+
import{L as e}from"./sdk-contracts.js";import{d as t}from"./sdk-device.js";import{s as n}from"./simctl.js";import{t as r}from"./simulator-state.js";const i=15e3;function a(e){return Object.freeze({canShutdownTarget:o,shutdownTarget:async(t,n)=>await s(e.appleTools,t,n)})}function o(e){return t(e)&&e.appleOs!==`watchos`&&e.kind===`simulator`}async function s(t,r,a){a.throwIfAborted();try{let e=await t.run({tool:`simctl`,args:n(r,[`shutdown`,r.id]),allowFailure:!0,timeoutMs:i},a);a.throwIfAborted();let o=l(e);return o.success?o:await c(t,r,a)===`Shutdown`?{...o,success:!0,exitCode:0}:o}catch(t){a.throwIfAborted();let n=e(t);return{success:!1,exitCode:-1,stdout:``,stderr:n.message,error:n}}}async function c(e,t,n){try{return await r(e,t,n,i)}catch{return n.throwIfAborted(),null}}function l(e){let t=e.exitCode??-1;return{success:t===0,exitCode:t,stdout:e.stdout,stderr:e.stderr}}export{a as createAppleShutdownRuntime};
|