agent-device 0.21.8 → 0.21.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.8.apk → agent-device-android-ime-helper-0.21.9.apk} +0 -0
  2. package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.9.apk.sha256 +1 -0
  3. package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.8.manifest.json → agent-device-android-ime-helper-0.21.9.manifest.json} +4 -4
  4. package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.8.apk → agent-device-android-snapshot-helper-0.21.9.apk} +0 -0
  5. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.9.apk.sha256 +1 -0
  6. package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.8.manifest.json → agent-device-android-snapshot-helper-0.21.9.manifest.json} +6 -6
  7. package/apple/macos-helper/Sources/AgentDeviceMacOSDeviceHub/DeviceHubWindowInventory.swift +65 -0
  8. package/apple/macos-helper/Sources/AgentDeviceMacOSHelper/DeviceHubPose.swift +45 -140
  9. package/apple/macos-helper/Sources/AgentDeviceMacOSHelper/DeviceHubSidebar.swift +57 -0
  10. package/apple/macos-helper/Sources/AgentDeviceMacOSHelper/DeviceHubWindowDiscovery.swift +108 -0
  11. package/apple/macos-helper/Tests/AgentDeviceMacOSDeviceHubTests/DeviceHubWindowInventoryTests.swift +65 -0
  12. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/AgentDeviceRunnerUITests-Bridging-Header.h +1 -0
  13. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAppScreenCapture.swift +175 -0
  14. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.h +10 -2
  15. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.m +42 -15
  16. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Alert.swift +8 -0
  17. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +45 -22
  18. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +39 -734
  19. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Keyboard.swift +20 -4
  20. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Lifecycle.swift +63 -1
  21. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +13 -0
  22. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Navigation.swift +25 -10
  23. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift +5 -562
  24. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotAcquisition.swift +566 -0
  25. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedGesturePolicy.swift +5 -1
  26. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedInteraction.swift +594 -0
  27. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerXCTestEventBridge.h +35 -1
  28. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerXCTestEventBridge.m +160 -0
  29. package/dist/apple/runner/AgentDeviceRunner/RecordingScripts/RecordingExportSupport.swift +3 -0
  30. package/dist/apple/runner/AgentDeviceRunner/RecordingScripts/recording-frames.swift +203 -0
  31. package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotCoordinateSpace.swift +5 -0
  32. package/dist/src/absence-observation-errors.js +1 -1
  33. package/dist/src/adapter.js +1 -1
  34. package/dist/src/agent-browser-lifecycle.js +1 -1
  35. package/dist/src/agent-browser-process-record.js +1 -1
  36. package/dist/src/agent-device-client.js +1 -1
  37. package/dist/src/alert-runtime.js +1 -1
  38. package/dist/src/android-adb.js +1 -1
  39. package/dist/src/android-input-ownership.js +1 -1
  40. package/dist/src/android.js +1 -1
  41. package/dist/src/app-launch.js +1 -1
  42. package/dist/src/app-log-runtime2.js +3 -3
  43. package/dist/src/app-resolution.js +2 -2
  44. package/dist/src/apple-runner-platform.js +1 -1
  45. package/dist/src/application-lifecycle-interaction.js +1 -1
  46. package/dist/src/artifact-paths.js +1 -0
  47. package/dist/src/back-mode.js +1 -1
  48. package/dist/src/cli-config.js +1 -1
  49. package/dist/src/cli-help.js +8 -7
  50. package/dist/src/cli.js +4 -4
  51. package/dist/src/client-types.d.ts +23 -5
  52. package/dist/src/command-tools.js +3 -3
  53. package/dist/src/connection-runtime.js +1 -1
  54. package/dist/src/device-claim-inspection.js +1 -1
  55. package/dist/src/device-claim-rule.js +2 -2
  56. package/dist/src/device-input-state.d.ts +1 -1
  57. package/dist/src/device-selection-resolver.js +1 -1
  58. package/dist/src/device.js +1 -1
  59. package/dist/src/device2.js +1 -1
  60. package/dist/src/dispatch-resolve.js +1 -1
  61. package/dist/src/doctor-facade.js +1 -1
  62. package/dist/src/durable-resource.js +1 -1
  63. package/dist/src/find.js +1 -1
  64. package/dist/src/finders.js +1 -1
  65. package/dist/src/fold-runtime.js +1 -0
  66. package/dist/src/gesture-admission.js +1 -1
  67. package/dist/src/interaction-positionals.js +1 -1
  68. package/dist/src/interaction-ref-policy.js +1 -1
  69. package/dist/src/interaction.js +1 -1
  70. package/dist/src/interaction2.js +1 -1
  71. package/dist/src/interactor-operation-catalog.js +1 -1
  72. package/dist/src/interactor.js +4 -4
  73. package/dist/src/interactors.js +1 -1
  74. package/dist/src/internal/bin.js +1 -1
  75. package/dist/src/internal/daemon.js +2 -2
  76. package/dist/src/inventory2.js +1 -1
  77. package/dist/src/ios-snapshot-acquisition.js +1 -1
  78. package/dist/src/ios-snapshot-runtime.js +1 -1
  79. package/dist/src/lease.js +1 -1
  80. package/dist/src/local-interactor-operation-set.js +1 -1
  81. package/dist/src/location-coordinates.js +1 -1
  82. package/dist/src/managed-device-scope.js +1 -1
  83. package/dist/src/mechanics.js +17 -17
  84. package/dist/src/mobile-snapshot-semantics.js +1 -1
  85. package/dist/src/mp4-duration.js +1 -0
  86. package/dist/src/multitouch-support.js +1 -1
  87. package/dist/src/owner-identity.js +1 -1
  88. package/dist/src/parameterized-recorded-fill.js +1 -1
  89. package/dist/src/perf-facade.js +2 -2
  90. package/dist/src/perf-runtime-plan.js +1 -1
  91. package/dist/src/platform-request-scope.js +1 -1
  92. package/dist/src/platform-runtime-managed-owner.js +1 -1
  93. package/dist/src/platform-runtime-open-target.js +1 -1
  94. package/dist/src/platform-runtime-operation-host.js +2 -2
  95. package/dist/src/platform-runtime-runtime-hints.js +1 -1
  96. package/dist/src/platform-runtime-screen-recording-finalizer-host.js +1 -1
  97. package/dist/src/platform-runtime-unavailable.js +1 -1
  98. package/dist/src/platform-runtime.js +1 -1
  99. package/dist/src/platform-runtime2.js +1 -1
  100. package/dist/src/png-crop-bytes.js +1 -1
  101. package/dist/src/png-encode.js +1 -0
  102. package/dist/src/png-size.js +1 -0
  103. package/dist/src/provider-webdriver.js +1 -1
  104. package/dist/src/quality-warnings.js +1 -1
  105. package/dist/src/react-native.js +1 -1
  106. package/dist/src/record-runtime.js +1 -1
  107. package/dist/src/recording-export-quality.js +1 -1
  108. package/dist/src/recording-scope.js +1 -0
  109. package/dist/src/recording.js +3 -0
  110. package/dist/src/registry.js +35 -35
  111. package/dist/src/replay.js +2 -2
  112. package/dist/src/request-admission.js +1 -1
  113. package/dist/src/request-runtime-binding.js +1 -1
  114. package/dist/src/result-serialization.js +1 -1
  115. package/dist/src/runner-cache-metadata.js +2 -2
  116. package/dist/src/runner-client.js +1 -1
  117. package/dist/src/runner-contract.js +1 -1
  118. package/dist/src/runner-dev-tools-security.js +1 -1
  119. package/dist/src/runner-device-readiness.js +1 -1
  120. package/dist/src/runner-disposal.js +1 -1
  121. package/dist/src/runner-operations-facade.js +1 -1
  122. package/dist/src/runner-presentation.js +1 -1
  123. package/dist/src/runner.js +1 -1
  124. package/dist/src/runtime.js +2 -2
  125. package/dist/src/runtime10.js +2 -1
  126. package/dist/src/runtime2.js +4 -4
  127. package/dist/src/runtime4.js +5 -5
  128. package/dist/src/runtime5.js +1 -1
  129. package/dist/src/runtime6.js +1 -1
  130. package/dist/src/runtime7.js +1 -1
  131. package/dist/src/runtime8.js +1 -1
  132. package/dist/src/runtime9.js +1 -1
  133. package/dist/src/screen-recording-admission-ledger.js +1 -1
  134. package/dist/src/screen-recording-resource-recovery.js +1 -1
  135. package/dist/src/screen-recording-transport.js +1 -1
  136. package/dist/src/screenshot-density.js +1 -1
  137. package/dist/src/screenshot-overlay-draw.js +1 -0
  138. package/dist/src/screenshot-runtime.js +1 -1
  139. package/dist/src/script.js +1 -1
  140. package/dist/src/scroll-gesture.js +1 -1
  141. package/dist/src/sdk-batch.js +2 -2
  142. package/dist/src/sdk-contracts.d.ts +7 -5
  143. package/dist/src/sdk-device.js +1 -1
  144. package/dist/src/sdk-finders.js +1 -1
  145. package/dist/src/sdk-selectors.d.ts +44 -1
  146. package/dist/src/sdk-selectors.js +1 -1
  147. package/dist/src/selection.js +0 -0
  148. package/dist/src/selector-runtime.js +1 -1
  149. package/dist/src/selectors.js +1 -1
  150. package/dist/src/semantic-index.js +1 -1
  151. package/dist/src/session-routing.js +1 -1
  152. package/dist/src/session-snapshot.js +1 -1
  153. package/dist/src/session-store.js +3 -3
  154. package/dist/src/session2.js +3 -3
  155. package/dist/src/simctl.js +1 -1
  156. package/dist/src/simulator-boot.js +1 -1
  157. package/dist/src/snapshot-runtime-binding.js +1 -1
  158. package/dist/src/snapshot-runtime.js +1 -1
  159. package/dist/src/snapshot-state.js +1 -1
  160. package/dist/src/snapshot4.js +1 -1
  161. package/dist/src/src.js +1 -1
  162. package/dist/src/src7.js +1 -1
  163. package/dist/src/stop-sequence.js +1 -1
  164. package/dist/src/text-entry-focus.js +1 -1
  165. package/dist/src/tree.js +1 -1
  166. package/dist/src/type-text-runtime.js +1 -1
  167. package/dist/src/video.js +2 -2
  168. package/package.json +1 -1
  169. package/server.json +2 -2
  170. package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.8.apk.sha256 +0 -1
  171. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.8.apk.sha256 +0 -1
@@ -1,5 +1,5 @@
1
- import{D as e,O as t}from"./sdk-contracts.js";import{r as n}from"./sdk-batch-runner.js";import{C as r,T as i,d as a,g as o,l as s,o as c,u as l}from"./sdk-device.js";import{$t as u,Qt as d,qt as f}from"./sdk-batch.js";import"./device.js";import{s as p}from"./device-rotation.js";import{c as ee,r as m}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{t as oe}from"./request.js";import{n as se,r as ce,t as le}from"./application-lifecycle-runtime.js";import{A as ue,B as de,C as fe,D as pe,E as me,F as he,H as ge,I as _e,L as ve,M as ye,N as be,R as xe,S as Se,V as Ce,W as we,_ as Te,a as Ee,b as De,f as Oe,h as ke,i as Ae,k as je,l as Me,t as Ne,w as Pe,y as Fe}from"./alert-runtime.js";import{n as Ie}from"./audio-probe-runtime.js";import{n as Le}from"./perf-runtime.js";import{i as Re,t as ze}from"./touch-runtime.js";import{a as Be,n as Ve}from"./durable-resource.js";import{n as He,t as Ue}from"./async-lifecycle.js";import{a as We,c as Ge,d as Ke,f as qe,l as Je,n as Ye,o as Xe,s as Ze,t as Qe,u as $e}from"./src7.js";import{n as et,t as tt}from"./screen-recording-completion.js";import{a as h,i as nt,n as rt,r as it,t as at}from"./stop-sequence.js";import{n as ot}from"./screen-recording-runtime.js";import{t as st}from"./ios-system-surface.js";import{i as ct,r as lt}from"./gesture-admission.js";import{t as ut}from"./interactor-operation-catalog.js";import{a as dt,i as ft,n as pt,r as mt,t as ht}from"./perf-runtime-operation-builder.js";import{t as gt}from"./app-log-runtime.js";import{i as _t,r as vt}from"./managed-device-scope.js";import{a as yt,n as bt,o as xt}from"./application-lifecycle-interaction.js";import{s as St}from"./config.js";import{a as Ct,o as wt}from"./tool-provider.js";import{n as Tt}from"./apps-simctl.js";import{i as Et,o as Dt,r as Ot}from"./simulator.js";import{a as kt}from"./helper.js";import{r as At}from"./display-inventory.js";import{t as jt}from"./multitouch-support.js";import{n as g,t as Mt}from"./simulator-state.js";import{n as Nt,r as Pt,t as Ft}from"./snapshot-process.js";import It from"node:path";import{randomUUID as Lt}from"node:crypto";function Rt(e){let t=_t();return Object.freeze(t?{...ne({...e},e=>Dt(t,e))}:e)}function zt(e){return it(e)?Object.freeze({available:!0}):a(e)||l(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 Bt(e){let{resolveHost:t,device:n,owner:r}=e;return Object.freeze({...ht({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 ft(t().sampleFrames(n,e)):pt(`Apple`,`bundle ID`),sampling:await t().frameSampling(n)}),perfMemorySample:async({appId:e})=>({metric:e?await ft(t().sampleMemory(n,e)):pt(`Apple`,`bundle ID`),sampling:await t().memorySampling(n)}),perfMemorySnapshot:async({appId:e,kind:r,outPath:i,artifactsDir:a})=>{let o=r??`memgraph`,s={...await t().memorySnapshotSupport(n),androidHprof:!1,heapprofd:!1};if(o!==`memgraph`)return dt(`Apple`,o,s,`Use perf memory snapshot --kind memgraph for supported Apple app sessions.`);if(!e)throw mt();let c=i??It.join(a,`memory-memgraph-${Vt()}.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 Vt(){return new Date().toISOString().replaceAll(/[:.]/g,`-`)}const _=Object.freeze({available:!0}),v=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),y=Gt(`Gestures are supported only for Apple simulators and devices.`),Ht=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:lt}),Ut=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:ct}),Wt=Gt(`scroll is supported only for Apple simulators and devices.`);function Gt(e){return Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:e})}function Kt(e){return{...ye({unsupported:qt(e),plan:Jt(e),directionalFling:Jt(e),multiTouch:Yt(e),targetAuthoredDrag:Xt(e),viewport:Zt(e)}),...je({scroll:Qt(e)})}}function qt(e){return e.appleOs===`watchos`||e.appleOs===`visionos`?v:y}function Jt(e){return e.appleOs===`watchos`||e.appleOs===`visionos`?v:b(e)?_:y}function Yt(e){if(e.appleOs===`watchos`)return v;if(!b(e))return y;let t=r(e);if(t!==`ios`&&t!==`ipados`){let e=jt[t];return Object.freeze({available:!1,reason:`unsupported-platform-leaf`,...e===void 0?{}:{hint:e}})}return e.kind===`simulator`?_:Ht}function Xt(e){return b(e)?(e.appleOs===void 0?e.target!==`desktop`&&e.target!==`tv`:e.appleOs===`ios`||e.appleOs===`ipados`)?_:Ut:y}function Zt(e){return e.appleOs===`watchos`?v:b(e)?_:y}function Qt(e){return b(e)?_:Wt}function b(e){return e.kind===`simulator`||e.kind===`device`}const x=`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`;function S(e){return a(e)?`macos`:e.kind===`device`?`ios-device`:`ios-simulator`}const $t=Object.freeze({resourceKind:gt,version:1,encode:e=>({...e}),decode:e=>!tn(e.transport)||!nn(e.backend)||!sn(e.outputPath)||!an(e.pidPath)||!rn(e.transport,e.backend)?en():{status:`decoded`,descriptor:Object.freeze({transport:e.transport,backend:e.backend,outputPath:e.outputPath,...e.pidPath===void 0?{}:{pidPath:e.pidPath}})}});function en(){return{status:`invalid`,message:`Invalid Apple app-log descriptor`}}function tn(e){return e===`apple-log-stream`||e===`coredevice-console`}function nn(e){return e===`ios-simulator`||e===`ios-device`||e===`macos`}function rn(e,t){return e===`coredevice-console`?t===`ios-device`:t!==`ios-device`}function an(e){return e===void 0||sn(e)}function on(e){if(!e.device.appleOs)throw TypeError(`Apple app-log persistence requires an explicit appleOs identity`);return Ve({resourceKind:gt,sessionId:e.sessionId,device:{id:e.device.id,family:`apple`,appleOs:e.device.appleOs,kind:e.device.kind,...e.device.target===void 0?{}:{target:e.device.target},...e.device.iosPhysicalDeviceBackend===void 0?{}:{iosPhysicalDeviceBackend:e.device.iosPhysicalDeviceBackend}},owner:e.owner,fence:e.fence,lifecycle:`open`,descriptor:Be($t,e.descriptor)})}function sn(e){return typeof e==`string`&&e.trim().length>0}const cn={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.`},ln={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 un(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 dn(e,t,n,r){let i={},o=n?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`];if(a(t))i.logAvailable=!!await e.commands.which(`log`);else if(t.kind===`simulator`)i.simctlAvailable=await h(async()=>nt(await e.appleTools.run({tool:`simctl`,args:[`help`],allowFailure:!0},r)),r);else if(t.iosPhysicalDeviceBackend===`xctest`)i.devicectlAvailable=!1,i.devicectlConsoleCapture=!1,o.push(x);else{i.devicectlAvailable=await h(async()=>nt(await e.appleTools.run({tool:`devicectl`,args:[`--version`],allowFailure:!0},r)),r);let t=await un(e,r);if(i.devicectlConsoleCapture=t.supported,!t.supported){let e=t.reason===`unsupported`?cn:ln;o.push(`${e.message} ${e.hint}`)}}return{backend:S(t),checks:i,notes:o}}function fn(e,t){let n=hn(e),r=[`subsystem == "${n}"`,`subsystem CONTAINS "${n}"`,`processImagePath ENDSWITH[c] "/${n}"`,`senderImagePath ENDSWITH[c] "/${n}"`];if(t){let e=hn(t);r.push(`process == "${e}"`,`processImagePath ENDSWITH[c] "/${e}"`,`senderImagePath ENDSWITH[c] "/${e}"`,`processImagePath CONTAINS[c] "/${e}.app/"`,`senderImagePath CONTAINS[c] "/${e}.app/"`)}return r.join(` OR `)}function pn(e){return[...e.simulatorSetPath?[`simctl`,`--set`,e.simulatorSetPath]:[`simctl`],`spawn`,e.deviceId,`log`,`stream`,`--style`,`compact`,`--level`,`info`,`--predicate`,fn(e.appBundleId,e.executableName)]}function mn(e,t){return[`devicectl`,`device`,`process`,`launch`,`--device`,e,`--console`,`--terminate-existing`,t]}function hn(e){return e.replaceAll(`\\`,String.raw`\\`).replaceAll(`"`,String.raw`\"`)}async function gn(e,t,n,r,i){_n(t),Xe(e,n);let a=S(t),o=await yn(e,t,n.appBundleId,i),s=new Ue,c=!1;try{let l=await e.outputs.openAppend(n.outputPath);s.defer(async()=>{c||await l[Symbol.asyncDispose]()}),i?.throwIfAborted();let u=await vn(e,t,o,l,n.pidPath,i);s.defer(async()=>{c||await u[Symbol.asyncDispose]()});let d=xn(e,u,l,a,n.outputPath),f={transport:a===`ios-device`?`coredevice-console`:`apple-log-stream`,backend:a,outputPath:n.outputPath,...n.pidPath===void 0?{}:{pidPath:n.pidPath}},p=qe(d,on({sessionId:n.sessionId,device:t,owner:r,fence:n.fence,descriptor:f}));return c=!0,p}finally{await s[Symbol.asyncDispose]()}}function _n(t){if(t.appleOs===`watchos`)throw new e(`UNSUPPORTED_PLATFORM`,`watchOS app logs are not supported`);if(l(t)&&t.kind===`device`&&t.iosPhysicalDeviceBackend===`xctest`)throw new e(`UNSUPPORTED_OPERATION`,x,{hint:x})}async function vn(t,n,r,i,a,o){if(l(n)&&n.kind===`device`){let n=await un(t,o);if(!n.supported){let t=n.reason===`unsupported`?cn:ln;throw new e(n.reason===`unsupported`?`UNSUPPORTED_OPERATION`:`COMMAND_FAILED`,t.message,{backend:`ios-device`,hint:t.hint,stderr:n.stderr})}}return o?.throwIfAborted(),await t.processes.start({command:{kind:`host`,request:r},output:i,...a?{markerPath:a}:{}})}async function yn(e,t,n,r){if(a(t))return{executable:`log`,args:[`stream`,`--style`,`compact`,`--predicate`,fn(n)],allowFailure:!0};if(t.kind===`device`)return{executable:`xcrun`,args:mn(t.id,n),allowFailure:!0};let i=await bn(e,t,n,r);return{executable:`xcrun`,args:pn({deviceId:t.id,appBundleId:n,executableName:i,simulatorSetPath:t.simulatorSetPath}),allowFailure:!0}}async function bn(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`,`-`,It.join(o,`Info.plist`)],allowFailure:!0,timeoutMs:4e3},r);return s.exitCode===0&&s.stdout.trim()||void 0}function xn(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 $e({inspect:()=>({backend:r,state:o,startedAt:a}),finish:async()=>s??=(async()=>(await Sn([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 Sn(e){let t=[];for(let n of e)try{await n()}catch(e){t.push(e)}return t}const C=f(`apple`),w=Object.freeze({available:!0});function Cn(t){return Object.freeze({owner:C,ownsDevice:e=>e.platform===`apple`,inspectFacts:async e=>T(e),bind:async n=>{if(n.intent.kind===`exact-owner`&&!d(n.intent.owner,C))throw new e(`UNSUPPORTED_OPERATION`,`Apple app-log owner identity does not match`);return wn(t,n.device,n.scope.signal)},shutdown:async()=>void 0})}function wn(t,n,r){if(n.platform!==`apple`)throw new e(`UNSUPPORTED_PLATFORM`,`Apple app-log owner cannot bind ${n.platform}`);let i=Ke({codec:$t,reattach:async(e,r)=>e.backend!==S(n)||!We(t,r.sessionId,e)?{status:`unreattachable`,reason:`descriptor-invalid`,message:`Apple app-log descriptor does not match the bound device or owning session`}:await Ge(t,e.pidPath),cleanup:async(e,r)=>e.backend===S(n)&&We(t,r.sessionId,e)?await Ze(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:S(n)}),appLogDoctor:async({appBundleId:e})=>await dn(t,n,e,r),appLogStart:async e=>await gn(t,n,e,C,r),...i});return Object.freeze({device:n,owner:C,facts:T(n),operations:a,[Symbol.asyncDispose]:async()=>void 0})}function T(e){if(e.appleOs===`watchos`)return Tn(e);let t=l(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?{available:!1,reason:`unsupported-device-backend`,hint:x}:w;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:w,appLogCleanup:w}})}function Tn(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 En(e,t,n,r){let i=S(t),a=await e.appLogs.readRecent(n.sessionId,n.maxScanLines),o=Ye(a.text,{...n,path:a.path,exists:a.exists,lineNumberOffset:a.skippedLines,backend:i}),s=[];if(On(t,n,o.dump)){let i=await kn(e,t,n,a.path,r);i&&(o=Dn(s,o,i,n.maxEntries))}return Mn(s,t,n),jn(s,o.dump),o.dump.entries.length===0&&s.push(Nn(t)),Object.freeze({source:`app-log`,backend:i,dump:o.dump,notes:Object.freeze(s)})}function Dn(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).`),Qe(n.scan,t,r))}function On(e,t,n){return l(e)&&e.kind===`simulator`&&!!t.appBundleId&&n.entries.length===0}async function kn(e,t,n,r,i){let a=[...t.simulatorSetPath?[`--set`,t.simulatorSetPath]:[],`spawn`,t.id,`log`,`show`,`--style`,`compact`,`--info`,`--predicate`,An(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:Ye(`${c.join(`
3
- `)}\n`,{...n,path:`${r} (simctl log show recovery)`,exists:!0,backend:`ios-simulator`}),lineCount:c.length}}function An(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 jn(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 Mn(e,t,n){n.appLogSnapshot?n.appLogSnapshot.state!==`active`&&e.length===0&&e.push(l(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 Nn(e){return l(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.`:l(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 Pn(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 tt(r,{...c,...l.length>0?{warning:l.join(` `)}:{},...r.invalidatedReason?{overlayWarning:`overlay unavailable: ${r.invalidatedReason}`}:{}},{stopObservation:s,...o===void 0?{}:{nativePathDisposition:o}})}async function Fn(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;try{await t.screenRecording.outputs.copy({from:i,to:a}),s=await In(()=>t.screenRecording.finalize.complete({outputPath:a,showTouches:!n.invalidatedReason&&n.showTouches,gestureEvents:n.gestureEvents,exportQuality:n.exportQuality??`medium`,targetLabel:r}))}catch(e){throw await t.screenRecording.outputs.remove(a),e}return{...s,...n.invalidatedReason?{overlayWarning:`overlay unavailable: ${n.invalidatedReason}`}:{},nativePathDisposition:await t.screenRecording.outputs.remove(o)===`removed`?`retired`:`retirable`}}async function In(e){try{return await e()}catch(e){throw t(e,`COMMAND_FAILED`)}}const E=Object.freeze({resourceKind:ot,version:1,encode:e=>e.backend===`simctl`?{backend:e.backend,outputPath:e.outputPath,processes:e.processes.map(e=>({...e}))}:{backend:e.backend,outputPath:e.outputPath,appBundleId:e.appBundleId,runnerSessionId:e.runnerSessionId,runnerAuthority:e.runnerAuthority,...e.remotePath===void 0?{}:{remotePath:e.remotePath}},decode:e=>Un(e)});function Ln(e){let{device:t,owner:n,input:r,descriptor:a}=e;return Ve({resourceKind:ot,sessionId:r.sessionId,device:i(t),owner:n,fence:r.fence,lifecycle:`open`,descriptor:Be(E,a)})}async function Rn(e,t,n,r){let i=E.decode(n);return i.status!==`decoded`||!Xn(t,i.descriptor)?{status:`cleanup-pending`,reason:`manual-recovery-required`}:i.descriptor.backend===`simctl`?await zn(e,i.descriptor.processes,r):await Vn(e,t,i.descriptor)}async function zn(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(Bn(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(Bn(n)),i.every(e=>e===`already-missing`)?{status:`already-missing`}:{status:`cleaned`})}function Bn(e){return{kind:`session`,sessionId:e}}async function Vn(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 Hn(e,t,n){let r=E.decode(n);if(r.status!==`decoded`)return{status:`unreattachable`,reason:`descriptor-invalid`,message:r.message};if(!Xn(t,r.descriptor))return{status:`unreattachable`,reason:`descriptor-invalid`,message:`Apple screen-recording descriptor does not match the bound device.`};let i=r.descriptor.backend===`simctl`?await Promise.all(r.descriptor.processes.map(async t=>await e.screenRecording.apple.inspectProcess(t))):[await e.screenRecording.apple.inspectRunner(t,r.descriptor.runnerSessionId,r.descriptor.runnerAuthority)];return i.every(e=>e===`missing`)?{status:`missing`}:{status:`unreattachable`,reason:`transport-not-reattachable`,message:i.includes(`ownership-lost`)?`Apple recording ownership no longer matches the durable descriptor.`:`Apple screen recordings require exact cleanup after daemon restart.`}}function Un(e){return typeof e.outputPath!=`string`||e.outputPath.length===0?D():e.backend===`simctl`?Wn(e,e.outputPath):e.backend===`runner`?Gn(e,e.outputPath):D()}function Wn(e,t){let n=Zn(e.processes);return n?{status:`decoded`,descriptor:Object.freeze({backend:`simctl`,outputPath:t,processes:n})}:D()}function Gn(e,t){return!Kn(e.appBundleId)||!Kn(e.runnerSessionId)||!qn(e.runnerAuthority)||!Jn(e.remotePath)?D():{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 Kn(e){return typeof e==`string`&&e.length>0}function qn(e){return e===`local-lease`||e===`scoped-provider`}function Jn(e){return e===void 0||Yn(e)}function Yn(e){return typeof e==`string`&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(e)}function Xn(e,t){return e.kind===`simulator`?t.backend===`simctl`:t.backend===`runner`?e.appleOs===`macos`?t.remotePath===void 0:l(e)?t.remotePath!==void 0&&Yn(t.remotePath):t.remotePath===void 0:!1}function Zn(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 D(){return{status:`invalid`,message:`Invalid Apple screen-recording descriptor`}}async function Qn(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.`)}function $n(e){return e.appleOs===`watchos`?dr(`unsupported-platform-leaf`,`watchOS recording is not supported.`):l(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?dr(`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 er(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await tr({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async e=>await Hn(t,n,e.envelope.descriptor.body),screenRecordingCleanup:async e=>await Rn(t,n,e.envelope.descriptor.body,e.envelope.sessionId)})}async function tr(e){return e.signal.throwIfAborted(),e.device.kind===`simulator`?await nr(e):await rr(e)}async function nr(e){let{host:t,device:n,owner:r,input:i,signal:a}=e;await Qn(n,i,t.screenRecording.apple.isRunnerBundleId);let o=i.activeSessionApp?await t.screenRecording.apple.captureClockAnchor(n,i.activeSessionApp.bundleId,a):void 0,s=rt(i.outputPath);await t.screenRecording.outputs.prepare(s);let c=await t.screenRecording.apple.startSimulator(n,s,a),l=c.markers;if(!l||l.length===0)throw await O(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 O(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.`}}};return lr({device:n,owner:r,input:i,descriptor:{backend:`simctl`,outputPath:s,processes:l},snapshot:ur(i,`simctl recordVideo`,{},o),finish:(e,n)=>at({snapshot:e,progress:n,steps:{stop:f,collect:async e=>{try{await t.screenRecording.outputs.copy({from:s,to:e}),await t.screenRecording.finalize.sniff({outputPath:e})}catch(e){throw or(e,u,d)}},finalize:async({collectedPath:n,exportPath:r})=>{try{return await Fn({host:t,snapshot:e,targetLabel:`iOS recording`,collectedPath:n,exportPath:r,nativePath:s})}catch(e){throw or(e,u,d)}},discard:async e=>{await t.screenRecording.outputs.remove(e)}}}),cleanup:async()=>{let e=await cr(c);return(e.status===`cleaned`||e.status===`already-missing`)&&t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId}),e}})}async function rr(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??=ir(()=>t.screenRecording.apple.runRunner(n,{kind:`stop`,appBundleId:o,...c}).then(()=>void 0)).catch(e=>{throw l=void 0,e}),l);if(!sr(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 lr({device:n,owner:r,input:i,descriptor:{backend:`runner`,outputPath:i.outputPath,appBundleId:o,...c,...s.remotePath===void 0?{}:{remotePath:s.remotePath}},snapshot:ur(i,`runner AVAssetWriter`,s),finish:async e=>(await u(),s.remotePath!==void 0&&await t.screenRecording.apple.retrieveRunnerRecording(n,s.remotePath,e.outPath),await Pn({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 ir(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 or(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 sr(e,t){return e.appleOs===`macos`||!l(e)?t===void 0:t!==void 0&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(t)}async function O(e){return await e.terminate(),await e.wait}async function cr(e){try{return await O(e),{status:`cleaned`}}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`Apple simulator cleanup failed`}}}function lr(e){let{device:t,owner:n,input:r,descriptor:i,snapshot:a,finish:o,cleanup:s}=e,c=et(a,{finish:o,forceCleanup:s});return Object.freeze({pendingHandle:new He(c),envelope:Ln({device:t,owner:n,input:r,descriptor:i})})}function ur(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 dr(e,t){return Object.freeze({available:!1,reason:e,hint:t})}const fr=15e3;async function k(e,t,n,r={}){return n.throwIfAborted(),await vt(t)||a(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 _r(e,t,n))!==`Booted`&&(r.onColdBootStart?.(),e.deviceReadiness.appleAutomation.keepHot(t),await mr(e,t,n,r.deadlineAtMs),await vr(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 mr(e,t,n,r=Date.now()+12e4){let i=!1;try{i=await hr(e,t,n,r),await gr(e,t,n,r)}catch(a){throw i&&n.aborted&&yr(e,t),n.throwIfAborted(),Date.now()>=r?j(t,a):a}}async function hr(t,n,r,i){let a=await t.appleTools.run({tool:`simctl`,args:g(n,[`boot`,n.id]),allowFailure:!0,timeoutMs:A(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 gr(t,n,r,i){oe({type:`command`,status:`progress`,message:`Waiting for the Simulator to finish booting...`});let a=await t.appleTools.run({tool:`simctl`,args:g(n,[`bootstatus`,n.id,`-b`]),allowFailure:!0,timeoutMs:A(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 Mt(t.appleTools,n,r,Math.min(fr,A(i,n)))!==`Booted`)throw new e(`COMMAND_FAILED`,`Simulator is still booting`,{deviceId:n.id});if(Date.now()>=i)throw j(n)}function A(e,t){let n=e-Date.now();if(n<=0)throw j(t);return n}function j(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 _r(e,t,n){return await Mt(e.appleTools,t,n,fr)}async function vr(e,t){await e.commands.run({executable:`open`,args:[`-a`,`Simulator`],allowFailure:!0,timeoutMs:1e4},t)}function yr(e,t){e.appleTools.run({tool:`simctl`,args:g(t,[`shutdown`,t.id]),allowFailure:!0}).catch(()=>{})}const br=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`,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 xr(e){return e===void 0?`possible`:e.some(e=>br[e]===`runner`)?`required`:`none`}const Sr=new Map([[`application-element-missing`,5e3],[`application-server-unavailable`,5e3],[`foreground-owner-unverified`,1e3],[`foreground-owner-changed`,1e3]]);function M(e){return e.platform===`apple`&&e.appleOs===`ios`&&e.kind===`simulator`}function Cr(e){let t=re(ae({depth:1,interactiveOnly:!0}));return Object.freeze({awaitObservable:async(n,r,i)=>{if(!M(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 m({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=Sr.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 wr(e,t,n){let r=n&&M(e),i=r?xr(t.execution.plannedOperations):void 0,a=l(e)&&t.surface===`app`&&t.positionals.length>0&&!!t.appBundleId&&i!==`none`;return{...i?{runnerDemand:i}:{},shouldPrewarmRunner:a,awaitPrewarmAfterOpen:t.relaunch&&!r}}function Tr(e,t,n,r){r.runnerDemand===`none`&&e.appleApplications.releaseSpeculativeRunner(t.device,n.execution).catch(()=>{})}async function Er(e,t,n,r,i,a){let o=Date.now();r&&M(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 Dr(e){let t=bt({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 k(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 Or(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 Rr(e.host,t,n),finalizeApplicationClose:async t=>await zr(e.host,e.device,e.signal,t),prepareAppleRunner:async t=>await Br(e.host,e.device,e.signal,t),configureProviderPortReverse:Gr})}async function Or(e,t,n,r){let i={},a=N(t.device),o=Vr(e,t,n,i),s=wr(t.device,n,a);s.runnerDemand&&(i.runnerDemand=s.runnerDemand),Tr(e,t,n,s);let{shouldPrewarmRunner:c}=s,l=Lr(t.device,n,a);a&&c&&!n.prewarmRunnerBeforeOpen&&o.schedule();try{await kr(e,t,n,a,l,i),await Ar(n,i),await jr(o,c,n.prewarmRunnerBeforeOpen);let u=o.wasAwaited();return await Mr(t,n,a,i),await Pr(o,c,s.awaitPrewarmAfterOpen),await Fr(e,t,n,a,u,l),await Er(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 kr(e,t,n,r,i,a){if(!Ir(n,r)||!n.target)return;let o=Date.now();s(t.device.platform)&&!r&&!i&&await e.appleApplications.stopRunnerSession(t.device.id),await yt({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=P(o)}async function Ar(t,n){if(!ce(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=P(r)}async function jr(e,t,n){!t||!n||(e.schedule(!0),await e.wait())}async function Mr(e,t,n,r){let i=Ur(t,n),a=Date.now();await xt({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=P(a),await Nr(e,t,i.followUpUrl,r)}async function Nr(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 xt({device:e.device,interactor:await e.resolveInteractor(i,t.appBundleId),positionals:[n],appBundleId:t.appBundleId,execution:i}),r.launchUrlDurationMs=P(a)}async function Pr(e,t,n){t&&!e.wasScheduled()&&e.schedule(),n?await e.wait():e.recordUnawaited()}async function Fr(e,t,n,r,i,a){!l(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 Ir(e,t){return!!(e.relaunch&&e.target)&&!(t&&!e.execution.clearAppState)}function Lr(e,t,n){return e.kind===`device`&&e.appleOs===`ios`&&Ir(t,n)}async function Rr(e,t,n){n.ensureReady&&await k(e,t.device,t.signal),s(t.device.platform)&&!N(t.device)&&await e.appleApplications.stopRunnerSession(t.device.id),await yt({device:t.device,interactor:await t.resolveInteractor(n.execution,n.appBundleId),positionals:n.positionals}),N(t.device)&&await e.clock.sleep(300,t.signal)}async function zr(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&&N(t)?await e.deviceShutdown.apple.shutdownTarget(t,n):void 0;return i===void 0?{}:{shutdown:i}}async function Br(e,t,n,r){let i=Date.now()+r.timeoutMs;await k(e,t,n,{deadlineAtMs:i});let a=Math.max(1,i-Date.now());return await e.appleApplications.prepareRunner(t,{...r,timeoutMs:a},n)}function Vr(e,t,n,r){let i,a=!1,o=Hr(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=P(e)},wasAwaited:()=>a,wasScheduled:()=>i!==void 0,recordUnawaited:()=>{i&&!a&&(r.runnerPrewarmWaited=!1)}}}function Hr(e,t){return e.kind===`device`&&e.appleOs===`ios`&&!t.hasExistingSession&&!t.relaunch&&!t.prewarmRunnerBeforeOpen}function Ur(e,t){let r=e.runtimeLaunchUrl?.trim(),i=e.positionals.length===1?e.positionals[0]?.trim():void 0;return!r||!i||n(i)?{positionals:e.positionals}:t&&!Wr(e)?{positionals:[i,r]}:{positionals:e.positionals,followUpUrl:r}}function Wr(e){return e.execution.clearAppState===!0||!!e.execution.launchConsole?.trim()||!!e.execution.launchArgs?.length}function N(e){return l(e)&&e.kind===`simulator`}function P(e){return Math.max(0,Date.now()-e)}async function Gr(){throw new e(`UNSUPPORTED_OPERATION`,`This lifecycle operation is unavailable for Apple.`)}const Kr=Object.freeze({available:!0}),qr=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.`}),Jr=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Push notifications are supported on Apple simulators only.`}),Yr=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Xr=Object.freeze({available:!1,reason:`unsupported-device-kind`});function Zr(e){let t=ai(e);return Object.freeze({deployApp:t,materializeAppSource:t,deployMaterializedApp:t,sendPushNotification:oi(e)})}function Qr(e){let{host:t,device:n,signal:r}=e,i=Zr(n);return Object.freeze({...i.deployApp.available?{deployApp:async e=>await $r(t,n,e,r),materializeAppSource:async e=>await t.appleDeployment.prepareArtifact(e,{signal:r}),deployMaterializedApp:async e=>await ei(t,n,e,r)}:{},...i.sendPushNotification.available?{sendPushNotification:async e=>(await ri(t,n,e,r),{})}:{}})}async function $r(e,t,n,r){if(n.replaceExisting)return await e.appleDeployment.withInvalidatedAppResolutionCache(t,async()=>{let i=await e.appleDeployment.resolveAppBundleId(t,n.app);await ni(e,t,i,r);let a=await e.appleDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{appIdentifierHint:n.app,signal:r});try{return await ti(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 ei(e,t,{artifact:i},r)}finally{await i.cleanup()}}async function ei(e,t,n,r){return await ti(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 ti(e,t,n,r){await k(e,t,r),F(await e.appleTools.run(t.kind===`simulator`?{tool:`simctl`,args:g(t,[`install`,t.id,n])}:{tool:`devicectl`,args:[`device`,`install`,`app`,`--device`,t.id,n],timeoutMs:12e4},r),`Apple app install failed`)}async function ni(e,t,n,r){await k(e,t,r);let i=await e.appleTools.run(t.kind===`simulator`?{tool:`simctl`,args:g(t,[`uninstall`,t.id,n]),allowFailure:!0}:{tool:`devicectl`,args:[`device`,`uninstall`,`app`,`--device`,t.id,n],allowFailure:!0},r);i.exitCode===0||ii(`${i.stdout}\n${i.stderr}`)||F(i,`Apple app uninstall failed for ${n}`)}async function ri(t,n,r,i){if(n.kind!==`simulator`)throw new e(`UNSUPPORTED_OPERATION`,`Apple push notifications require a simulator`);await k(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`),F(await t.appleTools.run({tool:`simctl`,args:g(n,[`push`,n.id,r.appId,a.path])},i),`Apple push notification failed`)}finally{await a[Symbol.asyncDispose]()}}function ii(e){let t=e.toLowerCase();return t.includes(`not installed`)||t.includes(`not found`)||t.includes(`no such file`)}function F(t,n){if(t.exitCode!==0)throw new e(`COMMAND_FAILED`,n,{stdout:t.stdout,stderr:t.stderr,exitCode:t.exitCode})}function ai(e){return si(e)?e.kind!==`simulator`&&e.kind!==`device`?Xr:e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?qr:Kr:Yr}function oi(e){return si(e)?e.kind===`simulator`?Kr:Jr:Yr}function si(e){return l(e)&&e.appleOs!==`watchos`}const I=Object.freeze({available:!0}),ci=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`back is supported on Apple simulators and physical devices.`}),li=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function ui(e){return e.kind!==`simulator`&&e.kind!==`device`?ci:r(e)===`watchos`?li:I}const di=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`home is supported on Apple simulators and physical devices.`}),fi=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 mi(e,t){if(e.kind!==`simulator`&&e.kind!==`device`)return t;let n=r(e);return n===`macos`||n===`watchos`?fi:I}function L(e){if(e.kind!==`simulator`&&e.kind!==`device`)return!1;let t=r(e);return t!==`tvos`&&t!==`macos`&&t!==`watchos`}const hi=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`orientation is supported on Apple simulators and physical devices.`}),gi=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function _i(e){return e.kind!==`simulator`&&e.kind!==`device`?hi:L(e)?I:gi}const vi=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`tv-remote is supported only on tvOS devices.`});function yi(e){return(e.kind===`simulator`||e.kind===`device`)&&o(e)?I:vi}const R=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),bi=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 xi(e){return L(e)?bi:R}function Si(e){return L(e)?I:R}function Ci(e){return L(e)?I:R}const wi=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`No Apple leaf carries this system button.`}),Ti=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`action-button is supported on iPhone and iPad simulators and physical devices.`}),Ei=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 Di(e){return e.kind!==`simulator`&&e.kind!==`device`?Ti:c(e)?I:Ei}function Oi(e){return Object.freeze({...De({back:ui(e)}),...Me({unsupported:wi,home:mi(e,di),appSwitcher:mi(e,pi),actionButton:Di(e)}),...Fe({orientation:_i(e)}),...Te({tvRemote:yi(e)}),...ke({unsupported:R,status:xi(e),dismiss:Si(e),enter:Ci(e)})})}function ki(e){let{host:t,device:n,signal:r}=e;return ut({device:n,signal:r,resolveInteractor:t.localInteractors.resolve,facts:Oi(n)})}const z=Object.freeze({available:!0}),Ai=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`clipboard is supported on Apple simulators and the macOS host.`}),ji=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`settings is supported on Apple simulators and the macOS host.`}),Mi=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.`}),Ni=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.`}),B=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function Pi(e,t,n){if(e.kind!==`simulator`&&e.kind!==`device`)return t;let i=r(e);return i===`watchos`?B:e.kind===`simulator`||i===`macos`?z:n}function Fi(e){return Pi(e,Ai,Ni)}const Ii=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`trigger-app-event is supported on Apple simulators and physical devices.`}),Li=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`alert is supported on Apple simulators and physical devices.`}),Ri=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`alert is supported on Apple simulators, the macOS host, and physical iOS devices.`});function zi(e){if(e.kind!==`simulator`&&e.kind!==`device`)return Li;let t=r(e);return t===`watchos`?B:e.kind===`simulator`||t===`ios`||t===`macos`?z:Ri}function Bi(e){return e.kind!==`simulator`&&e.kind!==`device`?Ii:r(e)===`watchos`?B:z}function Vi(e){let t=Fi(e);return t.available?Ni:t}function Hi(e){let t=Fi(e),n=zi(e);return Object.freeze({...Oe({unsupported:Vi(e),read:t,write:t}),...Ne({read:n,wait:n,accept:n,dismiss:n}),...Ee({triggerAppEvent:Bi(e)}),...Ae({setSetting:Pi(e,ji,Mi)})})}function Ui(e){let{host:t,device:n,signal:r}=e;return ut({device:n,signal:r,resolveInteractor:t.localInteractors.resolve,facts:Hi(n)})}function Wi(e){return Object.freeze({setFoldPose:e.fold})}const Gi=/Angle:\s*(-?\d+(?:[.,]\d+)?)\s*°/g;async function Ki(t,n={}){let r=[`devicectl`,`device`,`motion`,`hinge-angle`,`--device`,t.id,`--session-timeout`,`1`,`--timeout`,`5`],i=await wt(r,{allowFailure:!0,signal:n.signal,timeoutMs:St}),a=qi(i.stdout)??qi(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 qi(e){let t;for(let n of e.matchAll(Gi)){let e=Number.parseFloat(n[1].replace(`,`,`.`));Number.isFinite(e)&&(t=e)}return t}const Ji={closed:`closed`,"half-open":`book`,open:`open`};async function Yi(e,t,n={}){Et(e,`fold`),Xi(e,await At(e,{signal:n.signal})),await Ot({deviceHub:!0,background:!0,signal:n.signal});let r=await kt({udid:e.id,deviceName:e.name,pose:Ji[t],signal:n.signal});m({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 Zi(e,t,n.signal),a=await Qi(e,n.signal);return{pose:t,hingeAngleDegrees:i,...a?{screen:$i(a)}:{}}}function Xi(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 Zi(t,n,r){let i,a;for(let e=1;e<=4;e+=1)if(r?.throwIfAborted(),a=i,i=await Ki(t,{signal:r}),p(i)===n&&(n!==`half-open`||a!==void 0&&Math.abs(i-a)<=.5))return i;if(i!==void 0&&p(i)===n)return i;throw new e(`COMMAND_FAILED`,`${t.name} did not reach the ${n} pose: CoreDevice still reports a hinge angle of ${i}°`,{deviceId:t.id,reason:`fold-pose-unverified`,requestedPose:n,observedPose:i===void 0?void 0:p(i),hingeAngleDegrees:i,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.`})}async function Qi(e,t){let n=await At(e,{signal:t});if(!(n.unresolved||n.ambiguous))return n.activeDisplay}function $i(e){return{display:e.name,widthPt:Math.round(e.widthPx/e.pointScale),heightPt:Math.round(e.heightPx/e.pointScale)}}const ea=Object.freeze({available:!0}),ta=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.`}),na=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 ra(e){if(e.kind!==`simulator`)return ta;let t=r(e);return t===`ios`||t===`ipados`?ea:na}function ia(e){return Wi({fold:ra(e)})}function aa(e){let{device:t,signal:n}=e;return u(ia(t).setFoldPose,()=>({setFoldPose:async e=>(n.throwIfAborted(),await Yi(t,e.pose,{signal:n}))}))}function oa(e,t,n){let r=xe({device:t.device,signal:t.signal,resolveInteractor:e.localInteractors.resolve}),i=async i=>{if(a(t.device)&&i.options?.surface!==void 0&&i.options.surface!==`app`)return await e.snapshot.captureSurface(t.device,i.options,de(t.signal,i));if(!n)return await r.captureSnapshot(i);let o=de(t.signal,i);return await n.capture(t.device,i,o,async e=>await r.captureSnapshot(e))};return Object.freeze({captureSnapshot:i,captureSnapshotWithCustomActions:i,captureSnapshotWithoutActiveApp:i})}function sa(e,t){return Object.freeze({findText:async n=>{let r=await ca(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 ca(e,t,n){let r=n.options?.appBundleId;if(r===void 0)return;let i=n.options?.surface;if(a(t.device)&&i!==void 0&&i!==`app`)return;let o=n.signal?AbortSignal.any([t.signal,n.signal]):t.signal;if(o.throwIfAborted(),await la(e,t.device,n.execution))return{appBundleId:r,signal:o}}async function la(e,t,n){return!M(t)||await e.appleApplications.hasLiveRunnerSession(t,n??{})}function ua(){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 da=3e3;function fa(){let e=new Map,t=new Map,n=Nt({waitMs:1500});return async(r,i,a,o)=>{a.throwIfAborted();let s=`${r.id}:${i}`,c=e.get(s);return c&&o!==`refresh`&&await Ft(c.pid,{signal:a,timeoutMs:da})===c.processStartTime?c:(e.delete(s),await n.value(s,{start:async()=>{let n=await pa(r,i,t);return e.set(s,n),n},wait:(e,t)=>Pt({waitMs:e,signal:a,stop:t,cancelled:()=>a.reason}),pending:()=>H(`simulator-target-discovery-pending`,r,i)}))}}async function pa(e,t,n){let r=Date.now()+15e3,[i,a]=await Promise.allSettled([Tt(e,[`spawn`,e.id,`launchctl`,`list`],{allowFailure:!0,timeoutMs:V(r)}),ma(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 H(`simulator-target-probe-failed`,e,t);let c=ha(o.stdout,t);if(!c)throw H(`simulator-target-unavailable`,e,t);let l=await Ft(c.pid,{timeoutMs:Math.min(da,V(r))});if(!l)throw H(`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 ma(e,t,n){let r=t.get(e.id);if(r)return await r;let i=Tt(e,[`list`,`devices`,`-j`],{allowFailure:!0,timeoutMs:V(n)}).then(t=>{if(t.exitCode!==0)throw H(`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 H(`simulator-runtime-unavailable`,e,``);return r});t.set(e.id,i);try{return await i}catch(n){throw t.delete(e.id),n}}function ha(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 V(e){return Math.max(1,e-Date.now())}function H(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 ga(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 _a(n,r);return a!==`absent`&&a!==`unknown`&&t.set(n.id,{at:e(),host:a.host}),a}}async function _a(e,t){let n=!1;for(let r of st){let i=await va(r.processExecutable,t);if(i===`unknown`){n=!0;continue}for(let a of i){let i=await ya(a,e.id,t);if(i===`unknown`)n=!0;else if(i)return{kind:`present`,host:r}}}return n?`unknown`:`absent`}async function va(e,t){let n=await ba(`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 ya(e,t,n){let r=await ba(`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 ba(e,t,n){try{let r=await Ct(e,t,{allowFailure:!0,timeoutMs:3e3,...n?{signal:n}:{}});return{exitCode:r.exitCode,stdout:r.stdout}}catch{return`unknown`}}const xa=`system-surface-presented`,Sa=`system-surface-host-lingering`,Ca=`window-coordinate-space-unresolved`;function wa(t,n={}){let r=n.source??ua(),i=n.resolveTarget??fa(),a=n.systemSurfacePresent??ga(),o=new Set,s=new Map,c=e=>(Ia(e,s,o),o.has(La(e))),l=Cr({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(!Da(n,s))return await Aa(n,s,u);let d=await a(n,l);if(d===`unknown`)return await W(n.id,s,u,G(n.id,s),q(s),`system-surface-probe-unavailable`,[K()]);if(d!==`absent`)return await ka(n,s,u,d.host.bundleId);let f;try{f=await Ta(t,i,n,s,l)}catch(e){return l.throwIfAborted(),J(`target-resolution-failed`,n,void 0,e),await W(n.id,s,u,G(n.id,s),q(s),`target-resolution-failed`,[K()])}if(c(f))return await W(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 Fa(m.failure,f,n,s.options.appBundleId,l,i);return await U(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 U(s,u,f,{lineage:f,residue:[]},p,{kind:`malformed-tree`,code:`presentation-invariant`},o,e)}}})}async function Ta(e,t,n,r,i){let a=r.options.appBundleId;for(;;)try{return await t(n,a,i)}catch(t){if(!Ea(t))throw t;let i={requestId:r.execution?.requestId};if(await e.appleApplications.hasLiveRunnerSession(n,i))throw t}}function Ea(t){return t instanceof e&&t.details?.reason===`simulator-target-discovery-pending`}function Da(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 U(e,t,n,r,i,a,o,s){return Oa(a)&&o.add(La(n)),J(a.code,{id:n.udid},n.generation,s,a.details),await W(n.udid,e,t,r.lineage,i,a.code,r.residue)}function Oa(e){return e.kind!==`preparing`&&e.code!==Ca}async function W(e,t,n,r,i,a,o=[]){return ja(e,await n(t),r,i,a,o)}async function ka(e,t,n,r){let i=await n(t),a=i.systemSurface?xa:Sa;return i.systemSurface||J(a,e,void 0,void 0,{detectedHost:r}),ja(e.id,i,G(e.id,t),q(t),a)}async function Aa(e,t,n){let r=await n(t),i=r.systemSurface;return i?{...r,comparisonIdentity:Na(Ma(e.id,i.bundleId),q(t),[])}:r}function ja(e,t,n,r,i,a=[]){let o=t.systemSurface;return{...t,comparisonIdentity:Na(o?Ma(e,o.bundleId):n,r,[...o?[]:a,{kind:`fallback-source`,producer:`apple-runner`}]),warnings:[...t.warnings??[],Pa(i,n,o!==void 0)]}}function G(e,t){return{targetId:`${e}:${t.options.appBundleId}`}}function Ma(e,t){return{targetId:`${e}:${t}`}}function Na(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 Pa(e,t,n){return e===xa?`Simulator AX snapshot inapplicable (${e}); used XCTest to read the system surface presented over the app.`:e===Sa?`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===Ca?`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 Fa(e,t,n,r,i,a){if(e.kind!==`stale-target`)return{lineage:t,residue:[]};try{return{lineage:await a(n,r,i,`refresh`),residue:[]}}catch(e){return i.throwIfAborted(),J(`fallback-target-resolution-failed`,n,void 0,e),{lineage:{targetId:t.targetId},residue:[K()]}}}function K(){return{kind:`unknown-generation`,captureId:Lt()}}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 Ia(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 La(e){return`${e.targetId}:${e.generation}`}function J(e,t,n,r,i){m({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`}),Ra=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.`}),za=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.`}),Ba=Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`perf requires an Apple simulator, macOS device, or CoreDevice-backed physical Apple device.`}),Va=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`focus is supported on Apple simulators and physical devices.`}),Ha=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).`}),Ua=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Headless boot is supported only for local Android emulators.`}),Wa=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS has no XCUITest-driveable UI, so element text comes from the captured tree only.`}),Ga=Object.freeze({available:!1,reason:`unsupported-device-kind`}),Ka=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS open is not supported because XCUITest cannot drive watchOS UI.`}),qa=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS runner preparation is not supported because XCUITest cannot drive watchOS UI.`}),Ja=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS close is not supported because XCUITest cannot drive watchOS UI.`}),Ya=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Runtime hints are supported only for local iOS-family simulators and Android devices.`}),Xa=Q(`open is supported only for Apple simulators and devices.`),Za=Q(`prepare is supported only for Apple simulators and devices.`),Qa=Q(`close is supported only for Apple simulators and devices.`),$a=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`}),eo=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`shutdown is supported only for Apple simulators and Android emulators.`}),to=Q(`snapshot is supported only for Apple simulators and devices.`),no=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Re-run without --actions, or target an iOS simulator.`}),ro=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`screenshot is not supported on watchOS because XCUITest cannot drive watchOS UI.`}),io=Q(`screenshot is supported only for Apple simulators and devices.`),ao=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 oo(e){return!l(e)||e.appleOs===`watchos`?Z:e.kind===`simulator`?X:eo}function so(e){let t=co(e),n=lo(e),r=uo(e),i=fo(e);return le({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:i,clearRuntimeHints:i,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:n,configureProviderPortReverse:$a})}function co(e){return r(e)===`watchos`?Ka:e.kind===`simulator`||e.kind===`device`?X:Xa}function lo(e){return r(e)===`watchos`?qa:e.kind===`simulator`||e.kind===`device`?X:Za}function uo(e){return r(e)===`watchos`?Ja:e.kind===`simulator`||e.kind===`device`?X:Qa}function fo(e){return r(e)!==`watchos`&&l(e)&&e.kind===`simulator`?X:Ya}function po(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:Va}function mo(e){let t=Cn(e),n=wa(e),r=async n=>{let r=await t.inspectFacts(n),i=Zr(n),o=$n(n),s=o.available?await e.screenRecording.apple.availability(n):void 0,c=o.available&&s?.available===!1?Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:s.hint}):o,u=n.appleOs===`watchos`?Z:X,d=a(n)||n.appleOs===`watchos`?Z:X,f=po(n);return Object.freeze({device:r.device,operations:{...r.operations,...i,appState:Ha,networkDump:X,screenRecordingStart:c,screenRecordingReattach:c,screenRecordingCleanup:c,...yo(n),...we({capture:vo(n)}),...ve({findText:_o(n)}),..._e({setViewport:Ra}),...he({focus:$(n)}),...Kt(n),...me({type:$(n)}),...Re({unsupported:Z,tap:$(n),longPress:$(n),fill:$(n),...l(n)?{tapElementSelector:$(n)}:{}}),...fe({readTextAtPoint:go(n)}),...Oi(n),...ia(n),...Hi(n),...Ie({capture:zt(n),query:za}),...Le(ho(n)),ensureReady:u,bootTarget:d,bootTargetHeadless:Ua,listApps:f,...so(n),shutdownTarget:oo(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,...Qr({host:e,device:i.device,signal:i.scope.signal}),networkDump:async t=>await En(e,i.device,t,i.scope.signal),...u(s,()=>er({host:e,device:i.device,owner:Y,signal:i.scope.signal})),...u(o.operations.audioProbeStart,()=>Je({host:e.audioProbe.hostCapture,device:i.device,owner:Y})),...u(o.operations.perfFrames,()=>Bt({resolveHost:()=>e.perf.apple,device:i.device,owner:Y})),...u(o.operations.captureSnapshot,()=>oa(e,{device:i.device,signal:i.scope.signal},n)),...u(o.operations.captureScreenshot,()=>ge({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...u(o.operations.focusPoint,()=>be({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...ue({device:i.device,signal:i.scope.signal,facts:o.operations,resolveInteractor:e.localInteractors.resolve}),...u(o.operations.scrollDirection,()=>pe({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...u(o.operations.typeText,()=>Pe({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...u(o.operations.tapPoint,()=>ze({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)})),...u(o.operations.readTextAtPoint,()=>Se({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve})),...u(o.operations.findText,()=>sa(e,{device:i.device,signal:i.scope.signal})),...ki({host:e,device:i.device,signal:i.scope.signal}),...Ui({host:e,device:i.device,signal:i.scope.signal}),...aa({device:i.device,signal:i.scope.signal}),...u(o.operations.ensureReady,()=>({ensureReady:async()=>await k(e,i.device,i.scope.signal)})),...u(o.operations.bootTarget,()=>({bootTarget:async()=>await k(e,i.device,i.scope.signal)})),...u(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}))}})),...se(Dr({host:e,device:i.device,signal:i.scope.signal,observation:n}),o.operations),...u(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:Rt(c),[Symbol.asyncDispose]:async()=>await a[Symbol.asyncDispose]()})},shutdown:async()=>{await Promise.all([t.shutdown(),n.shutdown()])}})}function ho(e){let t=e.iosPhysicalDeviceBackend!==`xctest`&&r(e)!==`watchos`?X:Ba;return{frames:t,memorySample:t,memorySnapshot:t,nativeCapture:t,profileReport:t}}function go(e){return r(e)===`watchos`?Wa:e.kind===`simulator`||e.kind===`device`?X:Ga}function _o(e){return r(e)===`watchos`?to:e.kind===`simulator`||e.kind===`device`?X:to}function vo(e){return r(e)===`watchos`?ro:e.kind===`simulator`||e.kind===`device`?X:io}function yo(e){let t=_o(e);return Ce({capture:t,customActions:t.available&&l(e)&&e.kind===`simulator`?X:no,withoutActiveApp:l(e)?ao:t})}export{mo as createApplePlatformRuntime};
1
+ import{D as e,O as t}from"./sdk-contracts.js";import{g as n,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:Ze(`${c.join(`
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 +1 @@
1
- import{L as e}from"./sdk-contracts.js";import{u as t}from"./sdk-device.js";import{n,t as r}from"./simulator-state.js";const i=15e3;function a(e){return Object.freeze({canShutdownTarget:o,shutdownTarget:async(t,n)=>await s(e.appleTools,t,n)})}function o(e){return t(e)&&e.appleOs!==`watchos`&&e.kind===`simulator`}async function s(t,r,a){a.throwIfAborted();try{let e=await t.run({tool:`simctl`,args:n(r,[`shutdown`,r.id]),allowFailure:!0,timeoutMs:i},a);a.throwIfAborted();let o=l(e);return o.success?o:await c(t,r,a)===`Shutdown`?{...o,success:!0,exitCode:0}:o}catch(t){a.throwIfAborted();let n=e(t);return{success:!1,exitCode:-1,stdout:``,stderr:n.message,error:n}}}async function c(e,t,n){try{return await r(e,t,n,i)}catch{return n.throwIfAborted(),null}}function l(e){let t=e.exitCode??-1;return{success:t===0,exitCode:t,stdout:e.stdout,stderr:e.stderr}}export{a as createAppleShutdownRuntime};
1
+ import{L as e}from"./sdk-contracts.js";import{d as t}from"./sdk-device.js";import{n,t as r}from"./simulator-state.js";const i=15e3;function a(e){return Object.freeze({canShutdownTarget:o,shutdownTarget:async(t,n)=>await s(e.appleTools,t,n)})}function o(e){return t(e)&&e.appleOs!==`watchos`&&e.kind===`simulator`}async function s(t,r,a){a.throwIfAborted();try{let e=await t.run({tool:`simctl`,args:n(r,[`shutdown`,r.id]),allowFailure:!0,timeoutMs:i},a);a.throwIfAborted();let o=l(e);return o.success?o:await c(t,r,a)===`Shutdown`?{...o,success:!0,exitCode:0}:o}catch(t){a.throwIfAborted();let n=e(t);return{success:!1,exitCode:-1,stdout:``,stderr:n.message,error:n}}}async function c(e,t,n){try{return await r(e,t,n,i)}catch{return n.throwIfAborted(),null}}function l(e){let t=e.exitCode??-1;return{success:t===0,exitCode:t,stdout:e.stdout,stderr:e.stderr}}export{a as createAppleShutdownRuntime};
@@ -1 +1 @@
1
- import{D as e}from"./sdk-contracts.js";import{T as t}from"./sdk-device.js";import{$t as n,qt as r}from"./sdk-batch.js";import{n as i}from"./device-shell.js";import{n as a,t as o}from"./application-lifecycle-runtime.js";import{A as s,C as c,D as l,E as u,F as d,H as f,I as p,L as ee,M as te,N as ne,R as re,V as ie,W as ae,_ as oe,a as se,b as ce,f as le,h as ue,i as de,k as fe,l as pe,t as m,w as h,y as g}from"./alert-runtime.js";import{n as me}from"./audio-probe-runtime.js";import{n as he}from"./perf-runtime.js";import{i as ge,t as _e}from"./touch-runtime.js";import{a as _,n as v}from"./durable-resource.js";import{n as ve}from"./async-lifecycle.js";import{i as ye,r as be}from"./src7.js";import{n as xe,t as y}from"./screen-recording-completion.js";import{t as b}from"./screen-recording-options.js";import{n as x}from"./screen-recording-runtime.js";import{i as S}from"./gesture-admission.js";import{t as C}from"./interactor-operation-catalog.js";import{i as w,n as T}from"./perf-runtime-operation-builder.js";import{t as E}from"./app-log-runtime.js";import{n as D,t as O}from"./application-lifecycle-interaction.js";import{randomUUID as k}from"node:crypto";import{setTimeout as A}from"node:timers/promises";const j=Object.freeze({resourceKind:E,version:1,encode:e=>({...e}),decode:e=>e.transport!==`harmony-hilog`||!N(e.outputPath)||!N(e.pidPath)?{status:`invalid`,message:`Invalid HarmonyOS app-log descriptor`}:{status:`decoded`,descriptor:Object.freeze({transport:`harmony-hilog`,outputPath:e.outputPath,pidPath:e.pidPath})}});function M(e){return v({resourceKind:E,sessionId:e.sessionId,device:{id:e.device.id,family:`harmonyos`,kind:e.device.kind,...e.device.target===void 0?{}:{target:e.device.target}},owner:e.owner,fence:e.fence,lifecycle:`open`,descriptor:_(j,e.descriptor)})}function N(e){return typeof e==`string`&&e.trim().length>0}function Se(e){return be(e,{family:`harmonyos`,backend:`harmonyos`,label:`HarmonyOS`,codec:j,startUnavailableHint:`The selected HarmonyOS transport cannot start a background hilog stream.`,cleanupFailureMessage:`HarmonyOS app-log cleanup did not settle every owned resource`,doctor:async(e,t)=>({backend:`harmonyos`,checks:{},notes:t?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`]}),process:async({host:e,device:t,input:n,signal:r})=>{let a=await Ce(e,r);return{resolvePid:async r=>await ye(e,{executable:a,args:i(`hdc`,`shell`,[`pidof`,n.appBundleId],[`-t`,t.id]),allowFailure:!0,timeoutMs:5e3},r),command:e=>({kind:`host`,request:{executable:a,args:i(`hdc`,`shell`,[`hilog`,`-P`,e],[`-t`,t.id]),allowFailure:!0}})}},descriptor:({artifacts:e})=>({transport:`harmony-hilog`,...e}),envelope:({input:e,device:t,owner:n,descriptor:r})=>M({sessionId:e.sessionId,device:t,owner:n,fence:e.fence,descriptor:r})})}async function Ce(t,n){n.throwIfAborted(),await P(async()=>await t.toolchains.prepare(`harmonyos`),n),n.throwIfAborted();let r=await P(async()=>await t.commands.which(`hdc`),n);if(n.throwIfAborted(),!r)throw new e(`TOOL_MISSING`,`hdc not found in PATH`,{hint:`Install HarmonyOS Command Line Tools, then add its sdk/default/openharmony/toolchains directory to PATH.`});return r}async function P(e,t){try{return await e()}catch(e){throw t.throwIfAborted(),e}}function we(e){let{resolveHost:t,device:n}=e,r={available:!1,reason:`Dropped-frame sampling is currently available only on Android app sessions and connected iOS device app sessions.`};return Object.freeze({perfFrames:async()=>({metric:r,sampling:r}),perfMemorySample:async({appId:e})=>({metric:e?await w(t().sampleMemory(n,e)):T(`HarmonyOS`,`bundle`),sampling:{method:`hdc-shell-proc-status`,description:`Resident memory snapshot from HarmonyOS /proc/<pid>/status. Values are reported in kilobytes.`,unit:`kB`,topConsumerLimit:1}}),perfMemorySnapshot:async({kind:e})=>({artifact:{available:!1,kind:e??`memgraph`,reason:`Memory snapshot artifacts are not supported on harmonyos.`,hint:`Use perf memory sample where supported, or run the snapshot against Android, iOS simulator, or macOS.`,support:{platform:`harmonyos`,defaultKind:`memgraph`,androidHprof:!1,memgraph:!1,heapprofd:!1}},sampling:{method:`unsupported`,description:`HarmonyOS memory snapshot capture is not available through HDC.`,artifactOnly:!0}})})}const F=Object.freeze({resourceKind:x,version:1,encode:e=>({...e}),decode:e=>e.backend===`harmony-screen-recorder`&&typeof e.fileName==`string`&&De(e.fileName)&&e.remotePath===`/data/local/tmp/${e.fileName}`?{status:`decoded`,descriptor:Object.freeze({backend:`harmony-screen-recorder`,fileName:e.fileName,remotePath:e.remotePath})}:{status:`invalid`,message:`Invalid HarmonyOS screen-recording descriptor`}});function Te(e){let{device:n,owner:r,input:i,descriptor:a}=e;return v({resourceKind:x,sessionId:i.sessionId,device:t(n),owner:r,fence:i.fence,lifecycle:`open`,descriptor:_(F,a)})}function Ee(e){return F.decode(e).status===`decoded`?{status:`cleanup-pending`,reason:`manual-recovery-required`,message:`HarmonyOS recorder ownership cannot be proven after daemon restart; no recorder was stopped.`}:{status:`cleanup-pending`,reason:`manual-recovery-required`}}function De(e){return/^agent-device-recording-[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\.mp4$/i.test(e)}function Oe(e){return e.kind===`device`?Object.freeze({available:!0}):Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`HarmonyOS recording is supported on physical devices only.`})}function ke(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await Ae({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async()=>({status:`unreattachable`,reason:`transport-not-reattachable`,message:`HarmonyOS recordings cannot be reattached after daemon restart.`}),screenRecordingCleanup:async e=>Ee(e.envelope.descriptor.body)})}async function Ae(t){let{host:n,device:r,owner:i,input:a,signal:o}=t;if(a.scope===`app`)throw new e(`INVALID_ARGS`,`HarmonyOS recording captures the whole physical-device screen; use --scope device or --scope system`);b(a,{scopes:[`device`,`system`],fps:!1,exportQuality:!1,hideTouches:!1},e=>`HarmonyOS recordings do not support ${e.join(`, `)}`),o.throwIfAborted(),await n.screenRecording.outputs.prepare(a.outputPath);let s=`agent-device-recording-${k()}.mp4`,c={backend:`harmony-screen-recorder`,fileName:s,remotePath:`/data/local/tmp/${s}`},l;try{l=await n.screenRecording.harmony.start(r,s,o),o.throwIfAborted()}catch(e){throw o.aborted?(await R(n,r,c).catch(()=>{}),o.reason):e}B(l,`start`);try{o.throwIfAborted()}catch(e){throw await R(n,r,c).catch(()=>{}),e}let u=je(a),d=!1,f=async()=>{d||=(B(await n.screenRecording.harmony.stop(r),`stop`),!0)},p=xe(u,{finish:async e=>await Me(n,r,e,c,f),forceCleanup:async()=>await R(n,r,c,f)});return Object.freeze({pendingHandle:new ve(p),envelope:Te({device:r,owner:i,input:a,descriptor:c})})}function je(e){return Object.freeze({backend:`HarmonyOS ScreenRecorder`,outPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutPath:e.clientOutputPath},startedAt:Date.now(),scope:e.scope,showTouches:!1,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},gestureEvents:[]})}async function Me(e,t,n,r,i){await i();let a=await e.screenRecording.harmony.findMedia(t,r.fileName);if(!a)throw Error(`failed to find finalized HarmonyOS recording '${r.fileName}'`);if(!await L(e,t,r,a))throw Error(`failed to finalize HarmonyOS recording: ${r.fileName} did not produce a non-empty media file`);try{if((await e.screenRecording.harmony.pull(t,{remotePath:r.remotePath,outputPath:n.outPath})).exitCode!==0)throw Error(`failed to retrieve HarmonyOS recording`);let i=await e.screenRecording.finalize.complete({outputPath:n.outPath,showTouches:!1,gestureEvents:n.gestureEvents,targetLabel:`HarmonyOS recording`}),o=await Ne(e,t,r,a);return y(n,{...i,...Pe(i.warning,o)},{stopObservation:{recorder:`confirmed`},nativePathDisposition:o===void 0?`retired`:`retirable`,showTouches:!1})}catch(n){throw await e.screenRecording.harmony.remove(t,r.remotePath).catch(()=>{}),n}}async function Ne(e,t,n,r){let i=[];return await I(()=>e.screenRecording.harmony.remove(t,n.remotePath))||i.push(`staging artifact`),await I(()=>e.screenRecording.harmony.removeMedia(t,r))||i.push(`media-library artifact`),i.length===0?void 0:`HarmonyOS recording completed, but cleanup was not confirmed for the ${i.join(` and `)}.`}async function I(e){try{return await e()}catch{return!1}}function Pe(e,t){let n=[e,t].filter(e=>e!==void 0).join(` `);return n.length===0?{}:{warning:n}}async function L(e,t,n,r){let i;for(let a=0;a<40;a+=1){if(await e.screenRecording.harmony.remove(t,n.remotePath).catch(()=>{}),await e.screenRecording.harmony.stageMedia(t,{mediaUri:r,remotePath:n.remotePath})){let r=await e.screenRecording.harmony.stagedFileSize(t,n.remotePath);if(r!==void 0&&r>0&&r===i)return!0;i=r!==void 0&&r>0?r:void 0}else i=void 0;a<39&&await e.clock.sleep(250)}return!1}async function R(e,t,n,r=async()=>{B(await e.screenRecording.harmony.stop(t),`stop`)}){let i=[await z(r),await z(async()=>{if(!await e.screenRecording.harmony.remove(t,n.remotePath))throw Error(`HarmonyOS recording staging artifact removal was not confirmed`)}),await z(async()=>await Fe(e,t,n.fileName))].find(e=>e!==void 0);return i===void 0?{status:`cleaned`}:{status:`cleanup-pending`,reason:`transport-failed`,message:i instanceof Error?i.message:`HarmonyOS recording cleanup failed`}}async function Fe(e,t,n){let r=await e.screenRecording.harmony.findMedia(t,n);if(r&&!await e.screenRecording.harmony.removeMedia(t,r))throw Error(`HarmonyOS recording media removal was not confirmed`)}async function z(e){try{await e();return}catch(e){return e}}function B(e,t){if(e.exitCode===0&&e.stdout.includes(`start ability successfully`))return;let n=e.stdout.trim()||e.stderr.trim()||`hdc exit ${e.exitCode}`;throw Error(`failed to ${t} HarmonyOS screen recording: ${n}`)}async function Ie(t,n){n.throwIfAborted();let{runHarmonyShell:r}=await import(`./hdc.js`),i=await r(t,[`aa`,`dump`,`-l`],{timeoutMs:15e3,signal:n});n.throwIfAborted();let a=Le(i.stdout);if(!a)throw new e(`COMMAND_FAILED`,`Could not determine the foreground HarmonyOS app`,{hint:`Open an app on the target, then retry appstate.`});return a}function Le(e){let t=e.split(/(?=^\s*Mission ID #)/m);for(let e of t){if(!/\bstate #FOREGROUND\b/.test(e))continue;let t=e.match(/mission name #\[#([^:]+):[^:]*:([^\]]+)]/);if(!t)continue;let[,n,r]=t;if(!(!n||!r))return{package:n,activity:r}}}function Re(e){return O({owner:`HarmonyOS`,openTargetIdentity:`bundle-id`,binding:D({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const ze=Object.freeze({available:!0}),Be=Object.freeze({available:!1,reason:`unsupported-device-kind`}),V=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function H(e){let t=e.kind===`emulator`||e.kind===`device`?ze:Be;return Object.freeze({deployApp:t,materializeAppSource:V,deployMaterializedApp:V,sendPushNotification:V})}function Ve(e){return H(e.device).deployApp.available?Object.freeze({deployApp:async t=>await He(e.commands,e.device,t,e.signal)}):Object.freeze({})}async function He(t,n,r,i){let a=await Ue(t,r.appPath,i)??r.app.trim();if(!a)throw new e(`INVALID_ARGS`,`Could not determine the bundle name from the HAP archive`,{hint:`Pass the HarmonyOS bundle name before the HAP path, or provide a valid HAP containing module.json.`});return await Ke(t,n,[`install`,`-r`,r.appPath],i,18e4),r.replaceExisting&&(await A(1e3,void 0,{signal:i}),await We(t,n,a,i)),{packageName:a,launchTarget:a}}async function Ue(e,t,n){let r=await e.run({executable:`unzip`,args:[`-p`,t,`module.json`],allowFailure:!0,timeoutMs:15e3},n);if(r.exitCode===0&&r.stdout.trim().length!==0)try{return JSON.parse(r.stdout).app?.bundleName?.trim()||void 0}catch{return}}async function We(t,n,r,i){let a=Ge((await U(t,n,[`bm`,`dump`,`-n`,r],i)).stdout);if(!a)throw new e(`COMMAND_FAILED`,`Could not determine a launchable ability for ${r}`,{hint:`Check that the HarmonyOS bundle exposes a main ability.`});await U(t,n,[`aa`,`start`,`-b`,r,...a.module?[`-m`,a.module]:[],`-a`,a.ability],i)}function Ge(e){let t=e.indexOf(`{`);if(t!==-1)try{let n=JSON.parse(e.slice(t)).hapModuleInfos?.find(e=>e.mainElementName);return n?.mainElementName?{ability:n.mainElementName,...n.moduleName?{module:n.moduleName}:{}}:void 0}catch{return}}async function Ke(e,t,n,r,i=15e3){return await e.run({executable:`hdc`,args:[`-t`,t.id,...n],timeoutMs:i},r)}async function U(e,t,n,r,a=15e3){return await e.run({executable:`hdc`,args:i(`hdc`,`shell`,n,[`-t`,t.id]),timeoutMs:a},r)}const W=r(`harmonyos`),qe=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`HarmonyOS reads element text from the captured tree only.`}),Je=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`focus is supported on HarmonyOS emulators and physical devices.`}),G=Object.freeze({available:!0}),K=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Ye=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`HarmonyOS appstate is supported only for HarmonyOS emulators and devices.`}),Xe=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple runner preparation is supported only for Apple targets.`}),q=Object.freeze({available:!0}),Ze=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`open is supported only for HarmonyOS emulators and devices.`}),Qe=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`close is supported only for HarmonyOS emulators and devices.`}),$e=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`}),J=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`snapshot is supported only for HarmonyOS emulators and devices.`}),et=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`screenshot is supported only for HarmonyOS emulators and devices.`}),tt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Re-run without --actions, or target an iOS simulator.`}),nt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`viewport resizes web targets only (--platform web).`});function rt(e){let t=it(e),n=at(e);return o({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:K,clearRuntimeHints:K,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:Xe,configureProviderPortReverse:$e})}function it(e){return e.kind===`emulator`||e.kind===`device`?q:Ze}function at(e){return e.kind===`emulator`||e.kind===`device`?q:Qe}const Y=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Gestures are supported on HarmonyOS emulators and physical devices.`}),ot=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),st=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:S});function X(e){return e.kind===`emulator`||e.kind===`device`?G:Y}function Z(e){return e.kind===`emulator`||e.kind===`device`?G:Je}const Q=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),ct=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`keyboard status/get is not available through the public HarmonyOS HDC API; use keyboard dismiss or enter`}),$=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`audio is supported for web browser sessions, macOS sessions, iOS simulators, and Android emulators on macOS hosts`});function lt(e){let t=Se(e),r=async e=>{let n=await t.inspectFacts(e),r=H(e),i=Oe(e);return Object.freeze({device:n.device,operations:{...n.operations,...r,appState:e.kind===`simulator`?Ye:G,networkDump:K,screenRecordingStart:i,screenRecordingReattach:i,screenRecordingCleanup:i,...ie({capture:e.kind===`emulator`||e.kind===`device`?G:J,customActions:tt,withoutActiveApp:e.kind===`emulator`||e.kind===`device`?G:J}),...ae({capture:e.kind===`emulator`||e.kind===`device`?G:et}),...ee({findText:J}),...p({setViewport:nt}),...d({focus:Z(e)}),...te({unsupported:Y,plan:X(e),directionalFling:X(e),multiTouch:ot,targetAuthoredDrag:st,viewport:X(e)}),...fe({scroll:X(e)}),...u({type:Z(e)}),...ge({unsupported:K,tap:Z(e),longPress:Z(e),fill:Z(e)}),...c({readTextAtPoint:qe}),...ce({back:Z(e)}),...pe({unsupported:Q,home:Z(e),appSwitcher:Z(e)}),setFoldPose:Q,...se({triggerAppEvent:Q}),...de({setSetting:Z(e)}),...m({read:Q,wait:Q,accept:Q,dismiss:Q}),...g({orientation:Q}),...oe({tvRemote:Q}),...ue({unsupported:Q,status:ct,dismiss:Z(e),enter:Z(e)}),...le({unsupported:Q}),...me({capture:$,query:$}),...he({frames:Z(e),memorySample:Z(e),memorySnapshot:Z(e),nativeCapture:Q,profileReport:Q}),ensureReady:G,bootTarget:K,bootTargetHeadless:K,listApps:G,...rt(e),shutdownTarget:K}})};return Object.freeze({owner:W,ownsDevice:e=>e.platform===`harmonyos`,inspectFacts:r,bind:async i=>{let o=await t.bind(i),c=await r(i.device),u=c.operations.screenRecordingStart;return Object.freeze({device:o.device,owner:W,facts:c,operations:Object.freeze({...o.operations,...Ve({commands:e.commands,device:i.device,signal:i.scope.signal}),...c.operations.appState.available?{appState:async()=>await Ie(i.device,i.scope.signal)}:{},ensureReady:async()=>({...i.device,booted:!0}),...u.available?ke({host:e,device:i.device,owner:W,signal:i.scope.signal}):{},...c.operations.captureSnapshot.available?re({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...c.operations.captureScreenshot.available?f({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...c.operations.focusPoint.available?ne({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...c.operations.typeText.available?h({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...s({device:i.device,signal:i.scope.signal,facts:c.operations,resolveInteractor:e.localInteractors.resolve}),...c.operations.scrollDirection.available?l({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...C({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:c.operations}),...n(c.operations.perfFrames,()=>we({resolveHost:()=>e.perf.harmony,device:i.device})),...n(c.operations.tapPoint,()=>_e({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:c.operations,pause:async t=>await e.clock.sleep(t,i.scope.signal)})),listApps:async e=>{i.scope.signal.throwIfAborted();let{listHarmonyApps:t}=await import(`./app-lifecycle2.js`);return(await t(e.device,e.filter,{signal:i.scope.signal})).map(e=>({id:e.package,name:e.name}))},...a(Re({host:e.localInteractors,device:i.device,signal:i.scope.signal}),c.operations)}),[Symbol.asyncDispose]:async()=>await o[Symbol.asyncDispose]()})},shutdown:async()=>await t.shutdown()})}export{lt as createHarmonyPlatformRuntime};
1
+ import{D as e}from"./sdk-contracts.js";import{E as t}from"./sdk-device.js";import{Yt as n,tn as r}from"./sdk-batch.js";import{n as i}from"./device-shell.js";import{n as a,t as o}from"./application-lifecycle-runtime.js";import{A as s,D as c,G as l,H as u,I as d,L as f,N as p,O as ee,P as te,R as ne,T as re,U as ie,a as ae,b as oe,g as se,j as ce,o as le,p as ue,t as de,u as fe,v as m,w as h,x as g,z as pe}from"./alert-runtime.js";import{n as me}from"./audio-probe-runtime.js";import{n as he}from"./perf-runtime.js";import{i as ge,t as _e}from"./touch-runtime.js";import{a as _,n as v}from"./durable-resource.js";import{n as ve}from"./async-lifecycle.js";import{i as ye,r as be}from"./src7.js";import{n as xe,t as y}from"./screen-recording-completion.js";import{t as b}from"./screen-recording-options.js";import{n as x}from"./screen-recording-runtime.js";import{i as S}from"./gesture-admission.js";import{t as C}from"./interactor-operation-catalog.js";import{i as w,n as T}from"./perf-runtime-operation-builder.js";import{t as E}from"./app-log-runtime.js";import{n as D,t as O}from"./application-lifecycle-interaction.js";import{randomUUID as k}from"node:crypto";import{setTimeout as A}from"node:timers/promises";const j=Object.freeze({resourceKind:E,version:1,encode:e=>({...e}),decode:e=>e.transport!==`harmony-hilog`||!N(e.outputPath)||!N(e.pidPath)?{status:`invalid`,message:`Invalid HarmonyOS app-log descriptor`}:{status:`decoded`,descriptor:Object.freeze({transport:`harmony-hilog`,outputPath:e.outputPath,pidPath:e.pidPath})}});function M(e){return v({resourceKind:E,sessionId:e.sessionId,device:{id:e.device.id,family:`harmonyos`,kind:e.device.kind,...e.device.target===void 0?{}:{target:e.device.target}},owner:e.owner,fence:e.fence,lifecycle:`open`,descriptor:_(j,e.descriptor)})}function N(e){return typeof e==`string`&&e.trim().length>0}function Se(e){return be(e,{family:`harmonyos`,backend:`harmonyos`,label:`HarmonyOS`,codec:j,startUnavailableHint:`The selected HarmonyOS transport cannot start a background hilog stream.`,cleanupFailureMessage:`HarmonyOS app-log cleanup did not settle every owned resource`,doctor:async(e,t)=>({backend:`harmonyos`,checks:{},notes:t?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`]}),process:async({host:e,device:t,input:n,signal:r})=>{let a=await Ce(e,r);return{resolvePid:async r=>await ye(e,{executable:a,args:i(`hdc`,`shell`,[`pidof`,n.appBundleId],[`-t`,t.id]),allowFailure:!0,timeoutMs:5e3},r),command:e=>({kind:`host`,request:{executable:a,args:i(`hdc`,`shell`,[`hilog`,`-P`,e],[`-t`,t.id]),allowFailure:!0}})}},descriptor:({artifacts:e})=>({transport:`harmony-hilog`,...e}),envelope:({input:e,device:t,owner:n,descriptor:r})=>M({sessionId:e.sessionId,device:t,owner:n,fence:e.fence,descriptor:r})})}async function Ce(t,n){n.throwIfAborted(),await P(async()=>await t.toolchains.prepare(`harmonyos`),n),n.throwIfAborted();let r=await P(async()=>await t.commands.which(`hdc`),n);if(n.throwIfAborted(),!r)throw new e(`TOOL_MISSING`,`hdc not found in PATH`,{hint:`Install HarmonyOS Command Line Tools, then add its sdk/default/openharmony/toolchains directory to PATH.`});return r}async function P(e,t){try{return await e()}catch(e){throw t.throwIfAborted(),e}}function we(e){let{resolveHost:t,device:n}=e,r={available:!1,reason:`Dropped-frame sampling is currently available only on Android app sessions and connected iOS device app sessions.`};return Object.freeze({perfFrames:async()=>({metric:r,sampling:r}),perfMemorySample:async({appId:e})=>({metric:e?await w(t().sampleMemory(n,e)):T(`HarmonyOS`,`bundle`),sampling:{method:`hdc-shell-proc-status`,description:`Resident memory snapshot from HarmonyOS /proc/<pid>/status. Values are reported in kilobytes.`,unit:`kB`,topConsumerLimit:1}}),perfMemorySnapshot:async({kind:e})=>({artifact:{available:!1,kind:e??`memgraph`,reason:`Memory snapshot artifacts are not supported on harmonyos.`,hint:`Use perf memory sample where supported, or run the snapshot against Android, iOS simulator, or macOS.`,support:{platform:`harmonyos`,defaultKind:`memgraph`,androidHprof:!1,memgraph:!1,heapprofd:!1}},sampling:{method:`unsupported`,description:`HarmonyOS memory snapshot capture is not available through HDC.`,artifactOnly:!0}})})}const F=Object.freeze({resourceKind:x,version:1,encode:e=>({...e}),decode:e=>e.backend===`harmony-screen-recorder`&&typeof e.fileName==`string`&&De(e.fileName)&&e.remotePath===`/data/local/tmp/${e.fileName}`?{status:`decoded`,descriptor:Object.freeze({backend:`harmony-screen-recorder`,fileName:e.fileName,remotePath:e.remotePath})}:{status:`invalid`,message:`Invalid HarmonyOS screen-recording descriptor`}});function Te(e){let{device:n,owner:r,input:i,descriptor:a}=e;return v({resourceKind:x,sessionId:i.sessionId,device:t(n),owner:r,fence:i.fence,lifecycle:`open`,descriptor:_(F,a)})}function Ee(e){return F.decode(e).status===`decoded`?{status:`cleanup-pending`,reason:`manual-recovery-required`,message:`HarmonyOS recorder ownership cannot be proven after daemon restart; no recorder was stopped.`}:{status:`cleanup-pending`,reason:`manual-recovery-required`}}function De(e){return/^agent-device-recording-[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\.mp4$/i.test(e)}function Oe(e){return e.kind===`device`?Object.freeze({available:!0}):Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`HarmonyOS recording is supported on physical devices only.`})}function ke(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await Ae({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async()=>({status:`unreattachable`,reason:`transport-not-reattachable`,message:`HarmonyOS recordings cannot be reattached after daemon restart.`}),screenRecordingCleanup:async e=>Ee(e.envelope.descriptor.body)})}async function Ae(t){let{host:n,device:r,owner:i,input:a,signal:o}=t;if(a.scope===`app`)throw new e(`INVALID_ARGS`,`HarmonyOS recording captures the whole physical-device screen; use --scope device or --scope system`);b(a,{scopes:[`device`,`system`],fps:!1,exportQuality:!1,hideTouches:!1},e=>`HarmonyOS recordings do not support ${e.join(`, `)}`),o.throwIfAborted(),await n.screenRecording.outputs.prepare(a.outputPath);let s=`agent-device-recording-${k()}.mp4`,c={backend:`harmony-screen-recorder`,fileName:s,remotePath:`/data/local/tmp/${s}`},l;try{l=await n.screenRecording.harmony.start(r,s,o),o.throwIfAborted()}catch(e){throw o.aborted?(await R(n,r,c).catch(()=>{}),o.reason):e}B(l,`start`);try{o.throwIfAborted()}catch(e){throw await R(n,r,c).catch(()=>{}),e}let u=je(a),d=!1,f=async()=>{d||=(B(await n.screenRecording.harmony.stop(r),`stop`),!0)},p=xe(u,{finish:async e=>await Me(n,r,e,c,f),forceCleanup:async()=>await R(n,r,c,f)});return Object.freeze({pendingHandle:new ve(p),envelope:Te({device:r,owner:i,input:a,descriptor:c})})}function je(e){return Object.freeze({backend:`HarmonyOS ScreenRecorder`,outPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutPath:e.clientOutputPath},startedAt:Date.now(),scope:e.scope,showTouches:!1,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},gestureEvents:[]})}async function Me(e,t,n,r,i){await i();let a=await e.screenRecording.harmony.findMedia(t,r.fileName);if(!a)throw Error(`failed to find finalized HarmonyOS recording '${r.fileName}'`);if(!await Pe(e,t,r,a))throw Error(`failed to finalize HarmonyOS recording: ${r.fileName} did not produce a non-empty media file`);try{if((await e.screenRecording.harmony.pull(t,{remotePath:r.remotePath,outputPath:n.outPath})).exitCode!==0)throw Error(`failed to retrieve HarmonyOS recording`);let i=await e.screenRecording.finalize.complete({outputPath:n.outPath,showTouches:!1,gestureEvents:n.gestureEvents,targetLabel:`HarmonyOS recording`}),o=await Ne(e,t,r,a);return y(n,{...i,...L(i.warning,o)},{stopObservation:{recorder:`confirmed`},nativePathDisposition:o===void 0?`retired`:`retirable`,showTouches:!1})}catch(n){throw await e.screenRecording.harmony.remove(t,r.remotePath).catch(()=>{}),n}}async function Ne(e,t,n,r){let i=[];return await I(()=>e.screenRecording.harmony.remove(t,n.remotePath))||i.push(`staging artifact`),await I(()=>e.screenRecording.harmony.removeMedia(t,r))||i.push(`media-library artifact`),i.length===0?void 0:`HarmonyOS recording completed, but cleanup was not confirmed for the ${i.join(` and `)}.`}async function I(e){try{return await e()}catch{return!1}}function L(e,t){let n=[e,t].filter(e=>e!==void 0).join(` `);return n.length===0?{}:{warning:n}}async function Pe(e,t,n,r){let i;for(let a=0;a<40;a+=1){if(await e.screenRecording.harmony.remove(t,n.remotePath).catch(()=>{}),await e.screenRecording.harmony.stageMedia(t,{mediaUri:r,remotePath:n.remotePath})){let r=await e.screenRecording.harmony.stagedFileSize(t,n.remotePath);if(r!==void 0&&r>0&&r===i)return!0;i=r!==void 0&&r>0?r:void 0}else i=void 0;a<39&&await e.clock.sleep(250)}return!1}async function R(e,t,n,r=async()=>{B(await e.screenRecording.harmony.stop(t),`stop`)}){let i=[await z(r),await z(async()=>{if(!await e.screenRecording.harmony.remove(t,n.remotePath))throw Error(`HarmonyOS recording staging artifact removal was not confirmed`)}),await z(async()=>await Fe(e,t,n.fileName))].find(e=>e!==void 0);return i===void 0?{status:`cleaned`}:{status:`cleanup-pending`,reason:`transport-failed`,message:i instanceof Error?i.message:`HarmonyOS recording cleanup failed`}}async function Fe(e,t,n){let r=await e.screenRecording.harmony.findMedia(t,n);if(r&&!await e.screenRecording.harmony.removeMedia(t,r))throw Error(`HarmonyOS recording media removal was not confirmed`)}async function z(e){try{await e();return}catch(e){return e}}function B(e,t){if(e.exitCode===0&&e.stdout.includes(`start ability successfully`))return;let n=e.stdout.trim()||e.stderr.trim()||`hdc exit ${e.exitCode}`;throw Error(`failed to ${t} HarmonyOS screen recording: ${n}`)}async function Ie(t,n){n.throwIfAborted();let{runHarmonyShell:r}=await import(`./hdc.js`),i=await r(t,[`aa`,`dump`,`-l`],{timeoutMs:15e3,signal:n});n.throwIfAborted();let a=Le(i.stdout);if(!a)throw new e(`COMMAND_FAILED`,`Could not determine the foreground HarmonyOS app`,{hint:`Open an app on the target, then retry appstate.`});return a}function Le(e){let t=e.split(/(?=^\s*Mission ID #)/m);for(let e of t){if(!/\bstate #FOREGROUND\b/.test(e))continue;let t=e.match(/mission name #\[#([^:]+):[^:]*:([^\]]+)]/);if(!t)continue;let[,n,r]=t;if(!(!n||!r))return{package:n,activity:r}}}function Re(e){return O({owner:`HarmonyOS`,openTargetIdentity:`bundle-id`,binding:D({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const ze=Object.freeze({available:!0}),Be=Object.freeze({available:!1,reason:`unsupported-device-kind`}),V=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function H(e){let t=e.kind===`emulator`||e.kind===`device`?ze:Be;return Object.freeze({deployApp:t,materializeAppSource:V,deployMaterializedApp:V,sendPushNotification:V})}function Ve(e){return H(e.device).deployApp.available?Object.freeze({deployApp:async t=>await He(e.commands,e.device,t,e.signal)}):Object.freeze({})}async function He(t,n,r,i){let a=await Ue(t,r.appPath,i)??r.app.trim();if(!a)throw new e(`INVALID_ARGS`,`Could not determine the bundle name from the HAP archive`,{hint:`Pass the HarmonyOS bundle name before the HAP path, or provide a valid HAP containing module.json.`});return await Ke(t,n,[`install`,`-r`,r.appPath],i,18e4),r.replaceExisting&&(await A(1e3,void 0,{signal:i}),await We(t,n,a,i)),{packageName:a,launchTarget:a}}async function Ue(e,t,n){let r=await e.run({executable:`unzip`,args:[`-p`,t,`module.json`],allowFailure:!0,timeoutMs:15e3},n);if(r.exitCode===0&&r.stdout.trim().length!==0)try{return JSON.parse(r.stdout).app?.bundleName?.trim()||void 0}catch{return}}async function We(t,n,r,i){let a=Ge((await U(t,n,[`bm`,`dump`,`-n`,r],i)).stdout);if(!a)throw new e(`COMMAND_FAILED`,`Could not determine a launchable ability for ${r}`,{hint:`Check that the HarmonyOS bundle exposes a main ability.`});await U(t,n,[`aa`,`start`,`-b`,r,...a.module?[`-m`,a.module]:[],`-a`,a.ability],i)}function Ge(e){let t=e.indexOf(`{`);if(t!==-1)try{let n=JSON.parse(e.slice(t)).hapModuleInfos?.find(e=>e.mainElementName);return n?.mainElementName?{ability:n.mainElementName,...n.moduleName?{module:n.moduleName}:{}}:void 0}catch{return}}async function Ke(e,t,n,r,i=15e3){return await e.run({executable:`hdc`,args:[`-t`,t.id,...n],timeoutMs:i},r)}async function U(e,t,n,r,a=15e3){return await e.run({executable:`hdc`,args:i(`hdc`,`shell`,n,[`-t`,t.id]),timeoutMs:a},r)}const W=n(`harmonyos`),qe=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`HarmonyOS reads element text from the captured tree only.`}),Je=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`focus is supported on HarmonyOS emulators and physical devices.`}),G=Object.freeze({available:!0}),K=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Ye=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`HarmonyOS appstate is supported only for HarmonyOS emulators and devices.`}),Xe=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple runner preparation is supported only for Apple targets.`}),q=Object.freeze({available:!0}),Ze=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`open is supported only for HarmonyOS emulators and devices.`}),Qe=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`close is supported only for HarmonyOS emulators and devices.`}),$e=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`}),J=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`snapshot is supported only for HarmonyOS emulators and devices.`}),et=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`screenshot is supported only for HarmonyOS emulators and devices.`}),tt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Re-run without --actions, or target an iOS simulator.`}),nt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`viewport resizes web targets only (--platform web).`});function rt(e){let t=it(e),n=at(e);return o({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:K,clearRuntimeHints:K,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:Xe,configureProviderPortReverse:$e})}function it(e){return e.kind===`emulator`||e.kind===`device`?q:Ze}function at(e){return e.kind===`emulator`||e.kind===`device`?q:Qe}const Y=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Gestures are supported on HarmonyOS emulators and physical devices.`}),ot=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),st=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:S});function X(e){return e.kind===`emulator`||e.kind===`device`?G:Y}function Z(e){return e.kind===`emulator`||e.kind===`device`?G:Je}const Q=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),ct=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`keyboard status/get is not available through the public HarmonyOS HDC API; use keyboard dismiss or enter`}),$=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`audio is supported for web browser sessions, macOS sessions, iOS simulators, and Android emulators on macOS hosts`});function lt(e){let t=Se(e),n=async e=>{let n=await t.inspectFacts(e),r=H(e),i=Oe(e);return Object.freeze({device:n.device,operations:{...n.operations,...r,appState:e.kind===`simulator`?Ye:G,networkDump:K,screenRecordingStart:i,screenRecordingReattach:i,screenRecordingCleanup:i,...u({capture:e.kind===`emulator`||e.kind===`device`?G:J,customActions:tt,withoutActiveApp:e.kind===`emulator`||e.kind===`device`?G:J}),...l({capture:e.kind===`emulator`||e.kind===`device`?G:et}),...ne({findText:J}),...f({setViewport:nt}),...d({focus:Z(e)}),...p({unsupported:Y,plan:X(e),directionalFling:X(e),multiTouch:ot,targetAuthoredDrag:st,viewport:X(e)}),...s({scroll:X(e)}),...c({type:Z(e)}),...ge({unsupported:K,tap:Z(e),longPress:Z(e),fill:Z(e)}),...h({readTextAtPoint:qe}),...g({back:Z(e)}),...fe({unsupported:Q,home:Z(e),appSwitcher:Z(e)}),setFoldPose:Q,...le({triggerAppEvent:Q}),...ae({setSetting:Z(e),readSetting:Q}),...de({read:Q,wait:Q,accept:Q,dismiss:Q}),...oe({orientation:Q}),...m({tvRemote:Q}),...se({unsupported:Q,status:ct,dismiss:Z(e),enter:Z(e)}),...ue({unsupported:Q}),...me({capture:$,query:$}),...he({frames:Z(e),memorySample:Z(e),memorySnapshot:Z(e),nativeCapture:Q,profileReport:Q}),ensureReady:G,bootTarget:K,bootTargetHeadless:K,listApps:G,...rt(e),shutdownTarget:K}})};return Object.freeze({owner:W,ownsDevice:e=>e.platform===`harmonyos`,inspectFacts:n,bind:async i=>{let o=await t.bind(i),s=await n(i.device),c=s.operations.screenRecordingStart;return Object.freeze({device:o.device,owner:W,facts:s,operations:Object.freeze({...o.operations,...Ve({commands:e.commands,device:i.device,signal:i.scope.signal}),...s.operations.appState.available?{appState:async()=>await Ie(i.device,i.scope.signal)}:{},ensureReady:async()=>({...i.device,booted:!0}),...c.available?ke({host:e,device:i.device,owner:W,signal:i.scope.signal}):{},...s.operations.captureSnapshot.available?pe({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...s.operations.captureScreenshot.available?ie({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...s.operations.focusPoint.available?te({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...s.operations.typeText.available?re({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...ce({device:i.device,signal:i.scope.signal,facts:s.operations,resolveInteractor:e.localInteractors.resolve}),...s.operations.scrollDirection.available?ee({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},...C({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:s.operations}),...r(s.operations.perfFrames,()=>we({resolveHost:()=>e.perf.harmony,device:i.device})),...r(s.operations.tapPoint,()=>_e({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:s.operations,pause:async t=>await e.clock.sleep(t,i.scope.signal)})),listApps:async e=>{i.scope.signal.throwIfAborted();let{listHarmonyApps:t}=await import(`./app-lifecycle2.js`);return(await t(e.device,e.filter,{signal:i.scope.signal})).map(e=>({id:e.package,name:e.name}))},...a(Re({host:e.localInteractors,device:i.device,signal:i.scope.signal}),s.operations)}),[Symbol.asyncDispose]:async()=>await o[Symbol.asyncDispose]()})},shutdown:async()=>await t.shutdown()})}export{lt as createHarmonyPlatformRuntime};
@@ -1 +1 @@
1
- import{D as e}from"./sdk-contracts.js";import{Qt as t,qt as n}from"./sdk-batch.js";import{n as r,t as i}from"./application-lifecycle-runtime.js";import{B as a,C as o,E as s,F as c,M as ee,V as l,W as u,b as d,f,k as p,l as m}from"./alert-runtime.js";import{i as h}from"./touch-runtime.js";import{r as g}from"./platform-runtime-unavailable.js";import{i as _}from"./gesture-admission.js";import{t as v}from"./local-interactor-operation-set.js";import{n as y,t as b}from"./application-lifecycle-interaction.js";function x(e){return b({owner:`Linux`,openTargetIdentity:`app-name`,binding:y({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const S=Object.freeze({available:!0}),C=n(`linux`),w=$(`unsupported-platform-leaf`),T=$(`unsupported-device-kind`),E=$(`unsupported-device-kind`,`focus is supported only for the Linux desktop device.`),D=$(`unsupported-device-kind`,`type is supported only for the Linux desktop device.`),O=$(`unsupported-device-kind`,`Gestures are supported only for the Linux desktop device.`),k=$(`unsupported-device-kind`,`scroll is supported only for the Linux desktop device.`),A=$(`unsupported-platform-leaf`),j=$(`unsupported-platform-leaf`),M=$(`unsupported-platform-leaf`,_),N=$(`unsupported-platform-leaf`),P=$(`unsupported-platform-leaf`,`Runtime hints are supported only for local iOS-family simulators and Android devices.`),F=$(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),I=$(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),L=$(`unsupported-device-kind`,`open is supported only for the Linux desktop device.`),R=$(`unsupported-device-kind`,`close is supported only for the Linux desktop device.`),z=$(`unsupported-device-kind`,`snapshot is supported only for the Linux desktop device.`),B=$(`unsupported-device-kind`,`screenshot is supported only for the Linux desktop device.`),V=$(`unsupported-platform-leaf`,`Re-run without --actions, or target an iOS simulator.`),H=$(`unsupported-device-kind`,`back is supported only for the Linux desktop device.`),U=$(`unsupported-device-kind`,`home is supported only for the Linux desktop device.`),W=$(`unsupported-device-kind`,`clipboard is supported only for the Linux desktop device.`),G=w,K=$(`unsupported-platform-leaf`,`audio is supported for web browser sessions, macOS sessions, iOS simulators, and Android emulators on macOS hosts`);function q(n){return Object.freeze({owner:C,ownsDevice:e=>e.platform===`linux`,inspectFacts:async e=>Y(e),bind:async i=>{if(i.intent.kind===`exact-owner`&&!t(i.intent.owner,C))throw new e(`UNSUPPORTED_OPERATION`,`Linux runtime owner identity does not match`);if(i.device.platform!==`linux`)throw new e(`UNSUPPORTED_PLATFORM`,`Linux runtime cannot bind this device`);let a=Y(i.device),o=x({host:n.localInteractors,device:i.device,signal:i.scope.signal});return Object.freeze({device:i.device,owner:C,facts:a,operations:Object.freeze({...r(o,a.operations),...a.operations.captureSnapshot.available?Q(n,i):{},...J(n,i,a)}),[Symbol.asyncDispose]:async()=>void 0})},shutdown:async()=>void 0})}function J(e,t,n){let r={device:t.device,signal:t.scope.signal,resolveInteractor:e.localInteractors.resolve};return v({...r,facts:n.operations,pause:async n=>await e.clock.sleep(n,t.scope.signal)})}function Y(e){let t=e.kind===`device`?S:L,n=e.kind===`device`?S:R,r=g(e,C,{appLog:w,network:w,screenshot:B,snapshot:z,viewport:w,focus:E,gesture:O,scroll:k,typeText:D,touch:E,elementText:T,back:H,orientation:G,tvRemote:G,clipboard:W,systemButton:G,fold:G,triggerAppEvent:G,setSetting:G,readAlert:G,awaitAlert:G,acceptAlert:G,dismissAlert:G,keyboard:G,audioProbeCapture:K,audioProbeQuery:K,perf:G,readiness:w,lifecycle:i({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:P,clearRuntimeHints:P,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:F,configureProviderPortReverse:I})});return Object.freeze({device:r.device,operations:{...r.operations,...l({capture:X(e,z),customActions:V,withoutActiveApp:X(e,z)}),...u({capture:X(e,B)}),...c({focus:X(e,E)}),...ee({unsupported:O,plan:X(e,O),directionalFling:A,multiTouch:j,targetAuthoredDrag:M,viewport:N}),...p({scroll:X(e,k)}),...s({type:X(e,D)}),...Z(e),...o({readTextAtPoint:X(e,T)}),...d({back:X(e,H)}),...m({unsupported:G,home:X(e,U)}),...f({unsupported:W,read:X(e,W),write:X(e,W)})}})}function X(e,t){return e.kind===`device`?S:t}function Z(e){let t=e.kind===`device`?S:E;return h({unsupported:w,tap:t,longPress:t,fill:t})}function Q(e,t){let n=async n=>await e.snapshot.captureSurface(t.device,n.options,a(t.scope.signal,n));return Object.freeze({captureSnapshot:n,captureSnapshotWithCustomActions:n,captureSnapshotWithoutActiveApp:n})}function $(e,t){return Object.freeze(t===void 0?{available:!1,reason:e}:{available:!1,reason:e,hint:t})}export{q as createLinuxPlatformRuntime};
1
+ import{D as e}from"./sdk-contracts.js";import{Yt as t,en as n}from"./sdk-batch.js";import{n as r,t as i}from"./application-lifecycle-runtime.js";import{A as a,D as o,G as s,H as c,I as ee,N as l,V as u,p as d,u as f,w as p,x as m}from"./alert-runtime.js";import{i as h}from"./touch-runtime.js";import{r as g}from"./platform-runtime-unavailable.js";import{i as _}from"./gesture-admission.js";import{t as v}from"./local-interactor-operation-set.js";import{n as y,t as b}from"./application-lifecycle-interaction.js";function x(e){return b({owner:`Linux`,openTargetIdentity:`app-name`,binding:y({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const S=Object.freeze({available:!0}),C=t(`linux`),w=$(`unsupported-platform-leaf`),T=$(`unsupported-device-kind`),E=$(`unsupported-device-kind`,`focus is supported only for the Linux desktop device.`),D=$(`unsupported-device-kind`,`type is supported only for the Linux desktop device.`),O=$(`unsupported-device-kind`,`Gestures are supported only for the Linux desktop device.`),k=$(`unsupported-device-kind`,`scroll is supported only for the Linux desktop device.`),A=$(`unsupported-platform-leaf`),j=$(`unsupported-platform-leaf`),M=$(`unsupported-platform-leaf`,_),N=$(`unsupported-platform-leaf`),P=$(`unsupported-platform-leaf`,`Runtime hints are supported only for local iOS-family simulators and Android devices.`),F=$(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),I=$(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),L=$(`unsupported-device-kind`,`open is supported only for the Linux desktop device.`),R=$(`unsupported-device-kind`,`close is supported only for the Linux desktop device.`),z=$(`unsupported-device-kind`,`snapshot is supported only for the Linux desktop device.`),B=$(`unsupported-device-kind`,`screenshot is supported only for the Linux desktop device.`),V=$(`unsupported-platform-leaf`,`Re-run without --actions, or target an iOS simulator.`),H=$(`unsupported-device-kind`,`back is supported only for the Linux desktop device.`),U=$(`unsupported-device-kind`,`home is supported only for the Linux desktop device.`),W=$(`unsupported-device-kind`,`clipboard is supported only for the Linux desktop device.`),G=w,K=$(`unsupported-platform-leaf`,`audio is supported for web browser sessions, macOS sessions, iOS simulators, and Android emulators on macOS hosts`);function q(t){return Object.freeze({owner:C,ownsDevice:e=>e.platform===`linux`,inspectFacts:async e=>Y(e),bind:async i=>{if(i.intent.kind===`exact-owner`&&!n(i.intent.owner,C))throw new e(`UNSUPPORTED_OPERATION`,`Linux runtime owner identity does not match`);if(i.device.platform!==`linux`)throw new e(`UNSUPPORTED_PLATFORM`,`Linux runtime cannot bind this device`);let a=Y(i.device),o=x({host:t.localInteractors,device:i.device,signal:i.scope.signal});return Object.freeze({device:i.device,owner:C,facts:a,operations:Object.freeze({...r(o,a.operations),...a.operations.captureSnapshot.available?Q(t,i):{},...J(t,i,a)}),[Symbol.asyncDispose]:async()=>void 0})},shutdown:async()=>void 0})}function J(e,t,n){let r={device:t.device,signal:t.scope.signal,resolveInteractor:e.localInteractors.resolve};return v({...r,facts:n.operations,pause:async n=>await e.clock.sleep(n,t.scope.signal)})}function Y(e){let t=e.kind===`device`?S:L,n=e.kind===`device`?S:R,r=g(e,C,{appLog:w,network:w,screenshot:B,snapshot:z,viewport:w,focus:E,gesture:O,scroll:k,typeText:D,touch:E,elementText:T,back:H,orientation:G,tvRemote:G,clipboard:W,systemButton:G,fold:G,triggerAppEvent:G,settings:G,readAlert:G,awaitAlert:G,acceptAlert:G,dismissAlert:G,keyboard:G,audioProbeCapture:K,audioProbeQuery:K,perf:G,readiness:w,lifecycle:i({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:P,clearRuntimeHints:P,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:F,configureProviderPortReverse:I})});return Object.freeze({device:r.device,operations:{...r.operations,...c({capture:X(e,z),customActions:V,withoutActiveApp:X(e,z)}),...s({capture:X(e,B)}),...ee({focus:X(e,E)}),...l({unsupported:O,plan:X(e,O),directionalFling:A,multiTouch:j,targetAuthoredDrag:M,viewport:N}),...a({scroll:X(e,k)}),...o({type:X(e,D)}),...Z(e),...p({readTextAtPoint:X(e,T)}),...m({back:X(e,H)}),...f({unsupported:G,home:X(e,U)}),...d({unsupported:W,read:X(e,W),write:X(e,W)})}})}function X(e,t){return e.kind===`device`?S:t}function Z(e){let t=e.kind===`device`?S:E;return h({unsupported:w,tap:t,longPress:t,fill:t})}function Q(e,t){let n=async n=>await e.snapshot.captureSurface(t.device,n.options,u(t.scope.signal,n));return Object.freeze({captureSnapshot:n,captureSnapshotWithCustomActions:n,captureSnapshotWithoutActiveApp:n})}function $(e,t){return Object.freeze(t===void 0?{available:!1,reason:e}:{available:!1,reason:e,hint:t})}export{q as createLinuxPlatformRuntime};
@@ -1 +1 @@
1
- import{D as e}from"./sdk-contracts.js";import{Qt as t,qt as n}from"./sdk-batch.js";import{n as r,t as i}from"./application-lifecycle-runtime.js";import{M as a,_ as o,b as s,l as c}from"./alert-runtime.js";import{r as l}from"./platform-runtime-unavailable.js";import{i as u}from"./gesture-admission.js";import{t as d}from"./interactor-operation-catalog.js";import{n as f,t as p}from"./application-lifecycle-interaction.js";function m(e){return p({owner:`Vega`,openTargetIdentity:`app-name`,binding:f({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const h=n(`vega`),g=Object.freeze({available:!0}),_=W(`unsupported-platform-leaf`),v=W(`unsupported-platform-leaf`,`Runtime hints are supported only for local iOS-family simulators and Android devices.`),y=W(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),b=W(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),x=W(`unsupported-device-kind`,`open currently supports only Vega Virtual Devices.`),S=W(`unsupported-device-kind`,`close currently supports only Vega Virtual Devices.`);function C(n){return Object.freeze({owner:h,ownsDevice:e=>e.platform===`vega`,inspectFacts:async e=>U(e),bind:async i=>{if(i.intent.kind===`exact-owner`&&!t(i.intent.owner,h))throw new e(`UNSUPPORTED_OPERATION`,`Vega runtime owner identity does not match`);if(i.device.platform!==`vega`)throw new e(`UNSUPPORTED_PLATFORM`,`Vega runtime cannot bind this device`);let a=U(i.device),o=m({host:n.localInteractors,device:i.device,signal:i.scope.signal});return Object.freeze({device:i.device,owner:h,facts:a,operations:Object.freeze({...r(o,a.operations),...d({device:i.device,signal:i.scope.signal,resolveInteractor:n.localInteractors.resolve,facts:a.operations})}),[Symbol.asyncDispose]:async()=>void 0})},shutdown:async()=>void 0})}const w=W(`unsupported-platform-leaf`,`screenshot is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),T=W(`unsupported-platform-leaf`,`focus is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),E=W(`unsupported-platform-leaf`,`type is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),D=W(`unsupported-platform-leaf`,`Gestures are not supported on Vega OS: the Vega runtime exposes remote navigation only.`),O=W(`unsupported-platform-leaf`,`scroll is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),k=W(`unsupported-platform-leaf`),A=W(`unsupported-platform-leaf`,u),j=W(`unsupported-platform-leaf`,`orientation is not supported on Vega OS.`),M=W(`unsupported-platform-leaf`,`keyboard is not supported on Vega OS.`),N=W(`unsupported-platform-leaf`,`alert is not supported on Vega OS.`),P=W(`unsupported-platform-leaf`,`settings is not supported on Vega OS.`),F=W(`unsupported-platform-leaf`,`trigger-app-event is not supported on Vega OS.`),I=W(`unsupported-platform-leaf`,`System buttons other than home are not supported on Vega OS.`),L=W(`unsupported-platform-leaf`,`fold is not supported on Vega OS.`),R=W(`unsupported-platform-leaf`,`clipboard is not supported on Vega OS.`),z=W(`unsupported-device-kind`,`back currently supports only Vega Virtual Devices.`),B=W(`unsupported-device-kind`,`home currently supports only Vega Virtual Devices.`),V=W(`unsupported-device-kind`,`tv-remote currently supports only Vega Virtual Devices.`),H=W(`unsupported-platform-leaf`,`audio is supported for web browser sessions, macOS sessions, iOS simulators, and Android emulators on macOS hosts`);function U(e){let t=e.kind===`emulator`&&e.target===`tv`,n=t?g:x,r=t?g:S,u=l(e,h,{appLog:_,network:_,screenshot:w,snapshot:_,viewport:_,focus:T,gesture:D,scroll:O,typeText:E,touch:_,elementText:_,back:z,orientation:j,tvRemote:V,clipboard:R,systemButton:I,fold:L,triggerAppEvent:F,setSetting:P,readAlert:N,awaitAlert:N,acceptAlert:N,dismissAlert:N,keyboard:M,audioProbeCapture:H,audioProbeQuery:H,perf:_,readiness:_,lifecycle:i({resolveOpenTarget:n,prepareApplicationOpen:n,openApplication:n,applyRuntimeHints:v,clearRuntimeHints:v,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:y,configureProviderPortReverse:b})});return Object.freeze({device:u.device,operations:{...u.operations,...s({back:t?g:z}),...c({unsupported:I,home:t?g:B}),...o({tvRemote:t?g:V}),...a({unsupported:D,multiTouch:k,targetAuthoredDrag:A})}})}function W(e,t){let n={available:!1,reason:e,...t===void 0?{}:{hint:t}};return Object.freeze(n)}export{C as createVegaPlatformRuntime};
1
+ import{D as e}from"./sdk-contracts.js";import{Yt as t,en as n}from"./sdk-batch.js";import{n as r,t as i}from"./application-lifecycle-runtime.js";import{N as a,u as o,v as s,x as c}from"./alert-runtime.js";import{r as l}from"./platform-runtime-unavailable.js";import{i as u}from"./gesture-admission.js";import{t as d}from"./interactor-operation-catalog.js";import{n as f,t as p}from"./application-lifecycle-interaction.js";function m(e){return p({owner:`Vega`,openTargetIdentity:`app-name`,binding:f({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const h=t(`vega`),g=Object.freeze({available:!0}),_=W(`unsupported-platform-leaf`),v=W(`unsupported-platform-leaf`,`Runtime hints are supported only for local iOS-family simulators and Android devices.`),y=W(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),b=W(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),x=W(`unsupported-device-kind`,`open currently supports only Vega Virtual Devices.`),S=W(`unsupported-device-kind`,`close currently supports only Vega Virtual Devices.`);function C(t){return Object.freeze({owner:h,ownsDevice:e=>e.platform===`vega`,inspectFacts:async e=>U(e),bind:async i=>{if(i.intent.kind===`exact-owner`&&!n(i.intent.owner,h))throw new e(`UNSUPPORTED_OPERATION`,`Vega runtime owner identity does not match`);if(i.device.platform!==`vega`)throw new e(`UNSUPPORTED_PLATFORM`,`Vega runtime cannot bind this device`);let a=U(i.device),o=m({host:t.localInteractors,device:i.device,signal:i.scope.signal});return Object.freeze({device:i.device,owner:h,facts:a,operations:Object.freeze({...r(o,a.operations),...d({device:i.device,signal:i.scope.signal,resolveInteractor:t.localInteractors.resolve,facts:a.operations})}),[Symbol.asyncDispose]:async()=>void 0})},shutdown:async()=>void 0})}const w=W(`unsupported-platform-leaf`,`screenshot is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),T=W(`unsupported-platform-leaf`,`focus is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),E=W(`unsupported-platform-leaf`,`type is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),D=W(`unsupported-platform-leaf`,`Gestures are not supported on Vega OS: the Vega runtime exposes remote navigation only.`),O=W(`unsupported-platform-leaf`,`scroll is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),k=W(`unsupported-platform-leaf`),A=W(`unsupported-platform-leaf`,u),j=W(`unsupported-platform-leaf`,`orientation is not supported on Vega OS.`),M=W(`unsupported-platform-leaf`,`keyboard is not supported on Vega OS.`),N=W(`unsupported-platform-leaf`,`alert is not supported on Vega OS.`),P=W(`unsupported-platform-leaf`,`settings is not supported on Vega OS.`),F=W(`unsupported-platform-leaf`,`trigger-app-event is not supported on Vega OS.`),I=W(`unsupported-platform-leaf`,`System buttons other than home are not supported on Vega OS.`),L=W(`unsupported-platform-leaf`,`fold is not supported on Vega OS.`),R=W(`unsupported-platform-leaf`,`clipboard is not supported on Vega OS.`),z=W(`unsupported-device-kind`,`back currently supports only Vega Virtual Devices.`),B=W(`unsupported-device-kind`,`home currently supports only Vega Virtual Devices.`),V=W(`unsupported-device-kind`,`tv-remote currently supports only Vega Virtual Devices.`),H=W(`unsupported-platform-leaf`,`audio is supported for web browser sessions, macOS sessions, iOS simulators, and Android emulators on macOS hosts`);function U(e){let t=e.kind===`emulator`&&e.target===`tv`,n=t?g:x,r=t?g:S,u=l(e,h,{appLog:_,network:_,screenshot:w,snapshot:_,viewport:_,focus:T,gesture:D,scroll:O,typeText:E,touch:_,elementText:_,back:z,orientation:j,tvRemote:V,clipboard:R,systemButton:I,fold:L,triggerAppEvent:F,settings:P,readAlert:N,awaitAlert:N,acceptAlert:N,dismissAlert:N,keyboard:M,audioProbeCapture:H,audioProbeQuery:H,perf:_,readiness:_,lifecycle:i({resolveOpenTarget:n,prepareApplicationOpen:n,openApplication:n,applyRuntimeHints:v,clearRuntimeHints:v,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:y,configureProviderPortReverse:b})});return Object.freeze({device:u.device,operations:{...u.operations,...c({back:t?g:z}),...o({unsupported:I,home:t?g:B}),...s({tvRemote:t?g:V}),...a({unsupported:D,multiTouch:k,targetAuthoredDrag:A})}})}function W(e,t){let n={available:!1,reason:e,...t===void 0?{}:{hint:t}};return Object.freeze(n)}export{C as createVegaPlatformRuntime};
@@ -1 +1 @@
1
- import{D as e}from"./sdk-contracts.js";import{$t as t,Qt as n,qt as r}from"./sdk-batch.js";import{n as i,t as a}from"./application-lifecycle-runtime.js";import{C as o,D as s,E as c,F as l,H as u,I as d,L as f,M as ee,N as p,R as m,V as h,W as g,_ as te,a as ne,b as re,f as ie,h as ae,i as _,k as v,l as y,t as b,w as x,y as S}from"./alert-runtime.js";import{n as C}from"./audio-probe-runtime.js";import{n as w}from"./perf-runtime.js";import{i as T,t as E}from"./touch-runtime.js";import{i as D}from"./gesture-admission.js";import{n as O,t as k}from"./application-lifecycle-interaction.js";import{n as A,r as j,t as M}from"./screen-recording-transport.js";async function N(e){let{host:t,device:n,owner:r,signal:i}=e,a=await t.screenRecording.web.resolve(n);return a?{available:!0,operations:{screenRecordingStart:async e=>(P(e),await M({host:t,device:n,owner:r,input:e,signal:i,transport:{backend:`agent-browser`,targetLabel:`web recording`,start:async t=>await a.start(e.outputPath,t),stop:async()=>await a.stop()},support:{scopes:[`app`],fps:!1,exportQuality:!1,hideTouches:!1},unsupported:e=>`web recordings do not support ${e.join(`, `)}; agent-browser records WebM directly`})),screenRecordingReattach:async()=>j(`Web recordings cannot be reattached after daemon restart.`),screenRecordingCleanup:async()=>A(`Web recordings cannot be cleaned after daemon restart.`)}}:{available:!1,operations:{}}}function P(t){if(t.recordOnlySession)throw new e(`INVALID_ARGS`,`record on web requires an active browser session; run open <url> --platform web first`);if(!t.outputPath.toLowerCase().endsWith(`.webm`))throw new e(`INVALID_ARGS`,`web recordings require a .webm output path; agent-browser records WebM directly`)}function F(e){return k({owner:`web`,openTargetIdentity:`app-name`,binding:O({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const I=r(`web`),L=Object.freeze({available:!0}),R=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Web targets read element text from the captured tree only.`}),z=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),B=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`record is not supported by this web provider`}),V=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Re-run without --actions, or target an iOS simulator.`}),H=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),U=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`apps is not supported on web targets.`}),W=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),G=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),K=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple runner preparation is supported only for Apple targets.`}),q=Object.freeze({available:!1,reason:`owner-capability-missing`}),J=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`audio on web sessions is the stateless page probe; host capture is a macOS-host operation.`});function Y(e,t){return typeof e==`function`?t:q}function X(e,t){return e?L:t}const oe=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),se=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:D}),Z=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`open is supported only for web browser devices.`}),ce=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`close is supported only for web browser devices.`}),le=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`});function ue(e){let t=Q(e),n=de(e);return a({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:H,clearRuntimeHints:H,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:K,configureProviderPortReverse:le})}function Q(e){return e.kind===`device`?L:Z}function de(e){return e.kind===`device`?L:ce}function fe(t){return Object.freeze({owner:I,ownsDevice:e=>e.platform===`web`,inspectFacts:async e=>{let n=await t.networkTransports.resolve(e),r=await N({host:t,device:e,owner:I,signal:new AbortController().signal}),i=e.kind===`device`?await t.localInteractors.resolve(e,{}):void 0;return $(e,n,r.available,i)},bind:async r=>{if(r.intent.kind===`exact-owner`&&!n(r.intent.owner,I))throw new e(`UNSUPPORTED_OPERATION`,`Web runtime owner identity does not match`);if(r.device.platform!==`web`)throw new e(`UNSUPPORTED_PLATFORM`,`Web runtime owner cannot bind ${r.device.platform}`);let i=await t.networkTransports.resolve(r.device),a=await N({host:t,device:r.device,owner:I,signal:r.scope.signal}),o=r.device.kind===`device`?await t.localInteractors.resolve(r.device,{signal:r.scope.signal}):void 0;return pe(t,r.device,r.scope.signal,i,a,$(r.device,i,a.available,o))},shutdown:async()=>void 0})}function pe(n,r,a,o,c,l){let d=o.dump,f={...d?{networkDump:async e=>{let t=await d({maxEntries:e.maxEntries,include:e.include},a);return Object.freeze({source:`provider`,...t})}}:{},...c.operations,...l.operations.captureSnapshot.available?m({device:r,signal:a,resolveInteractor:n.localInteractors.resolve}):{},...l.operations.captureScreenshot.available?u({device:r,signal:a,resolveInteractor:n.localInteractors.resolve}):{},...l.operations.focusPoint.available?p({device:r,signal:a,resolveInteractor:n.localInteractors.resolve}):{},...l.operations.typeText.available?x({device:r,signal:a,resolveInteractor:n.localInteractors.resolve}):{},...t(l.operations.tapPoint,()=>E({device:r,signal:a,resolveInteractor:n.localInteractors.resolve,facts:l.operations,pause:async e=>await n.clock.sleep(e,a)})),...l.operations.scrollDirection.available?s({device:r,signal:a,resolveInteractor:n.localInteractors.resolve}):{},...l.operations.setViewport.available?{setViewport:async t=>{a.throwIfAborted();let i=await n.localInteractors.resolve(r,{signal:a});if(!i.setViewport)throw new e(`UNSUPPORTED_OPERATION`,`viewport is not supported by the bound web interactor`);await i.setViewport(t.width,t.height),a.throwIfAborted()}}:{},...t(l.operations.audioProbeQuery,()=>({audioProbeQuery:async t=>{let i=await n.audioProbe.web.resolve(r);if(i===void 0)throw new e(`UNSUPPORTED_OPERATION`,`audio is not supported by this web provider`);return await i.probe(t)}})),...i(F({host:n.localInteractors,device:r,signal:a}),l.operations)};return Object.freeze({device:r,owner:I,facts:l,operations:Object.freeze(f),[Symbol.asyncDispose]:async()=>void 0})}function $(e,t,n,r){let i=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`network is not supported by this web provider`}),a=X(e.kind===`device`,Z);return Object.freeze({device:{family:`web`,kind:e.kind,...e.target===void 0?{}:{target:e.target},providerMode:t.mode},operations:{appLogInspect:z,appLogDoctor:z,appLogStart:z,appLogReattach:z,appLogCleanup:z,appState:W,networkDump:X(!!t.dump,i),screenRecordingStart:X(n,B),screenRecordingReattach:X(n,B),screenRecordingCleanup:X(n,B),...h({capture:a,customActions:V,withoutActiveApp:a}),...f({findText:Z}),...g({capture:a}),...l({focus:a}),...c({type:a}),...T({unsupported:H,tap:a,tapRef:Y(r?.tapRef,a),longPress:H,hover:Y(r?.hover,a),hoverRef:Y(r?.hoverRef,a),fill:a,fillRef:Y(r?.fillRef,a)}),...v({scroll:a}),...ee({unsupported:oe,targetAuthoredDrag:se}),...d({setViewport:a}),...o({readTextAtPoint:R}),...re({back:G}),...S({orientation:G}),...te({tvRemote:G}),...ae({unsupported:G}),...ie({unsupported:G}),...C({capture:J,query:L}),...w({frames:G,memorySample:G,memorySnapshot:G,nativeCapture:G,profileReport:G}),...y({unsupported:G}),setFoldPose:G,...ne({triggerAppEvent:G}),..._({setSetting:G}),...b({read:G,wait:G,accept:G,dismiss:G}),ensureReady:H,bootTarget:H,bootTargetHeadless:H,listApps:U,deployApp:H,materializeAppSource:H,deployMaterializedApp:H,sendPushNotification:H,shutdownTarget:H,...ue(e)}})}export{fe as createWebPlatformRuntime};
1
+ import{D as e}from"./sdk-contracts.js";import{Yt as t,en as n,tn as r}from"./sdk-batch.js";import{n as i,t as a}from"./application-lifecycle-runtime.js";import{A as o,D as s,G as c,H as l,I as u,L as d,N as f,O as ee,P as p,R as m,T as h,U as g,a as te,b as ne,g as re,o as ie,p as ae,t as _,u as v,v as y,w as b,x,z as S}from"./alert-runtime.js";import{n as C}from"./audio-probe-runtime.js";import{n as w}from"./perf-runtime.js";import{i as T,t as E}from"./touch-runtime.js";import{i as D}from"./gesture-admission.js";import{n as O,t as k}from"./application-lifecycle-interaction.js";import{n as A,r as j,t as M}from"./screen-recording-transport.js";async function N(e){let{host:t,device:n,owner:r,signal:i}=e,a=await t.screenRecording.web.resolve(n);return a?{available:!0,operations:{screenRecordingStart:async e=>(P(e),await M({host:t,device:n,owner:r,input:e,signal:i,transport:{backend:`agent-browser`,targetLabel:`web recording`,start:async t=>await a.start(e.outputPath,t),stop:async()=>await a.stop()},support:{scopes:[`app`],fps:!1,exportQuality:!1,hideTouches:!1},unsupported:e=>`web recordings do not support ${e.join(`, `)}; agent-browser records WebM directly`})),screenRecordingReattach:async()=>j(`Web recordings cannot be reattached after daemon restart.`),screenRecordingCleanup:async()=>A(`Web recordings cannot be cleaned after daemon restart.`)}}:{available:!1,operations:{}}}function P(t){if(t.recordOnlySession)throw new e(`INVALID_ARGS`,`record on web requires an active browser session; run open <url> --platform web first`);if(!t.outputPath.toLowerCase().endsWith(`.webm`))throw new e(`INVALID_ARGS`,`web recordings require a .webm output path; agent-browser records WebM directly`)}function F(e){return k({owner:`web`,openTargetIdentity:`app-name`,binding:O({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const I=t(`web`),L=Object.freeze({available:!0}),R=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Web targets read element text from the captured tree only.`}),z=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),B=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`record is not supported by this web provider`}),V=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Re-run without --actions, or target an iOS simulator.`}),H=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),U=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`apps is not supported on web targets.`}),W=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),G=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),K=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple runner preparation is supported only for Apple targets.`}),q=Object.freeze({available:!1,reason:`owner-capability-missing`}),J=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`audio on web sessions is the stateless page probe; host capture is a macOS-host operation.`});function Y(e,t){return typeof e==`function`?t:q}function X(e,t){return e?L:t}const oe=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),se=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:D}),Z=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`open is supported only for web browser devices.`}),ce=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`close is supported only for web browser devices.`}),le=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`});function ue(e){let t=Q(e),n=de(e);return a({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:H,clearRuntimeHints:H,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:K,configureProviderPortReverse:le})}function Q(e){return e.kind===`device`?L:Z}function de(e){return e.kind===`device`?L:ce}function fe(t){return Object.freeze({owner:I,ownsDevice:e=>e.platform===`web`,inspectFacts:async e=>{let n=await t.networkTransports.resolve(e),r=await N({host:t,device:e,owner:I,signal:new AbortController().signal}),i=e.kind===`device`?await t.localInteractors.resolve(e,{}):void 0;return $(e,n,r.available,i)},bind:async r=>{if(r.intent.kind===`exact-owner`&&!n(r.intent.owner,I))throw new e(`UNSUPPORTED_OPERATION`,`Web runtime owner identity does not match`);if(r.device.platform!==`web`)throw new e(`UNSUPPORTED_PLATFORM`,`Web runtime owner cannot bind ${r.device.platform}`);let i=await t.networkTransports.resolve(r.device),a=await N({host:t,device:r.device,owner:I,signal:r.scope.signal}),o=r.device.kind===`device`?await t.localInteractors.resolve(r.device,{signal:r.scope.signal}):void 0;return pe(t,r.device,r.scope.signal,i,a,$(r.device,i,a.available,o))},shutdown:async()=>void 0})}function pe(t,n,a,o,s,c){let l=o.dump,u={...l?{networkDump:async e=>{let t=await l({maxEntries:e.maxEntries,include:e.include},a);return Object.freeze({source:`provider`,...t})}}:{},...s.operations,...c.operations.captureSnapshot.available?S({device:n,signal:a,resolveInteractor:t.localInteractors.resolve}):{},...c.operations.captureScreenshot.available?g({device:n,signal:a,resolveInteractor:t.localInteractors.resolve}):{},...c.operations.focusPoint.available?p({device:n,signal:a,resolveInteractor:t.localInteractors.resolve}):{},...c.operations.typeText.available?h({device:n,signal:a,resolveInteractor:t.localInteractors.resolve}):{},...r(c.operations.tapPoint,()=>E({device:n,signal:a,resolveInteractor:t.localInteractors.resolve,facts:c.operations,pause:async e=>await t.clock.sleep(e,a)})),...c.operations.scrollDirection.available?ee({device:n,signal:a,resolveInteractor:t.localInteractors.resolve}):{},...c.operations.setViewport.available?{setViewport:async r=>{a.throwIfAborted();let i=await t.localInteractors.resolve(n,{signal:a});if(!i.setViewport)throw new e(`UNSUPPORTED_OPERATION`,`viewport is not supported by the bound web interactor`);await i.setViewport(r.width,r.height),a.throwIfAborted()}}:{},...r(c.operations.audioProbeQuery,()=>({audioProbeQuery:async r=>{let i=await t.audioProbe.web.resolve(n);if(i===void 0)throw new e(`UNSUPPORTED_OPERATION`,`audio is not supported by this web provider`);return await i.probe(r)}})),...i(F({host:t.localInteractors,device:n,signal:a}),c.operations)};return Object.freeze({device:n,owner:I,facts:c,operations:Object.freeze(u),[Symbol.asyncDispose]:async()=>void 0})}function $(e,t,n,r){let i=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`network is not supported by this web provider`}),a=X(e.kind===`device`,Z);return Object.freeze({device:{family:`web`,kind:e.kind,...e.target===void 0?{}:{target:e.target},providerMode:t.mode},operations:{appLogInspect:z,appLogDoctor:z,appLogStart:z,appLogReattach:z,appLogCleanup:z,appState:W,networkDump:X(!!t.dump,i),screenRecordingStart:X(n,B),screenRecordingReattach:X(n,B),screenRecordingCleanup:X(n,B),...l({capture:a,customActions:V,withoutActiveApp:a}),...m({findText:Z}),...c({capture:a}),...u({focus:a}),...s({type:a}),...T({unsupported:H,tap:a,tapRef:Y(r?.tapRef,a),longPress:H,hover:Y(r?.hover,a),hoverRef:Y(r?.hoverRef,a),fill:a,fillRef:Y(r?.fillRef,a)}),...o({scroll:a}),...f({unsupported:oe,targetAuthoredDrag:se}),...d({setViewport:a}),...b({readTextAtPoint:R}),...x({back:G}),...ne({orientation:G}),...y({tvRemote:G}),...re({unsupported:G}),...ae({unsupported:G}),...C({capture:J,query:L}),...w({frames:G,memorySample:G,memorySnapshot:G,nativeCapture:G,profileReport:G}),...v({unsupported:G}),setFoldPose:G,...ie({triggerAppEvent:G}),...te({setSetting:G,readSetting:G}),..._({read:G,wait:G,accept:G,dismiss:G}),ensureReady:H,bootTarget:H,bootTargetHeadless:H,listApps:U,deployApp:H,materializeAppSource:H,deployMaterializedApp:H,sendPushNotification:H,shutdownTarget:H,...ue(e)}})}export{fe as createWebPlatformRuntime};
@@ -1 +1 @@
1
- import{D as e}from"./sdk-contracts.js";import{E as t,T as n}from"./sdk-device.js";function r(r){let i=r.now??Date.now,a=r.undurableCleanupTtlMs??3e5,o=new Map;return Object.freeze({blockUndurableCleanup(e,r){let s=n(e);o.set(t(s),{device:s,reason:r,expiresAt:i()+a})},clearUndurableCleanup(e){o.delete(t(n(e)))},assertStartAllowed(a){let s=t(n(a)),c=o.get(s);if(c){if(i()>c.expiresAt){o.delete(s),r.onUndurableCleanupExpired?.({device:c.device,reason:c.reason});return}throw new e(`COMMAND_FAILED`,`The existing ${r.displayName.toLowerCase()} resource has process-local unconfirmed ownership`,{reason:`cleanup-unconfirmed`,hint:`Do not start a replacement in this daemon process: ${c.reason}`})}}})}function i(){return r({displayName:`screen recording`})}export{r as n,i as t};
1
+ import{D as e}from"./sdk-contracts.js";import{D as t,E as n}from"./sdk-device.js";function r(r){let i=r.now??Date.now,a=r.undurableCleanupTtlMs??3e5,o=new Map;return Object.freeze({blockUndurableCleanup(e,r){let s=n(e);o.set(t(s),{device:s,reason:r,expiresAt:i()+a})},clearUndurableCleanup(e){o.delete(t(n(e)))},assertStartAllowed(a){let s=t(n(a)),c=o.get(s);if(c){if(i()>c.expiresAt){o.delete(s),r.onUndurableCleanupExpired?.({device:c.device,reason:c.reason});return}throw new e(`COMMAND_FAILED`,`The existing ${r.displayName.toLowerCase()} resource has process-local unconfirmed ownership`,{reason:`cleanup-unconfirmed`,hint:`Do not start a replacement in this daemon process: ${c.reason}`})}}})}function i(){return r({displayName:`screen recording`})}export{r as n,i as t};