agent-device 0.21.34 → 0.21.35

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 (174) hide show
  1. package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.34.apk → agent-device-android-ime-helper-0.21.35.apk} +0 -0
  2. package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.35.apk.sha256 +1 -0
  3. package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.34.manifest.json → agent-device-android-ime-helper-0.21.35.manifest.json} +4 -4
  4. package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.34.apk → agent-device-android-snapshot-helper-0.21.35.apk} +0 -0
  5. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.35.apk.sha256 +1 -0
  6. package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.34.manifest.json → agent-device-android-snapshot-helper-0.21.35.manifest.json} +7 -7
  7. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Keyboard.swift +27 -18
  8. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextInputProbe.swift +26 -7
  9. package/dist/src/agent-browser-provider.js +1 -1
  10. package/dist/src/agent-device-client.js +1 -1
  11. package/dist/src/ai-sdk.d.ts +1 -1
  12. package/dist/src/alert.js +1 -1
  13. package/dist/src/android-adb.d.ts +1 -1
  14. package/dist/src/app-backend.js +1 -1
  15. package/dist/src/app-launch.js +1 -1
  16. package/dist/src/app-lifecycle.js +1 -1
  17. package/dist/src/app-log-reconnect.js +1 -1
  18. package/dist/src/app-log-runtime2.js +2 -2
  19. package/dist/src/app-log-session-resource.js +1 -1
  20. package/dist/src/app-resolution.js +2 -2
  21. package/dist/src/app-state-runtime.d.ts +1 -1
  22. package/dist/src/apple-runner-platform.js +1 -1
  23. package/dist/src/application-lifecycle-interaction.js +1 -1
  24. package/dist/src/artifact-download.js +1 -1
  25. package/dist/src/back-mode.js +1 -1
  26. package/dist/src/cli-config.js +1 -1
  27. package/dist/src/cli-help.js +3 -2
  28. package/dist/src/cli.js +2 -2
  29. package/dist/src/client-types.d.ts +17 -4
  30. package/dist/src/cloud-artifacts.d.ts +2 -2
  31. package/dist/src/command-metadata.js +41 -41
  32. package/dist/src/command-schema.js +3 -1
  33. package/dist/src/command-tools.js +1 -1
  34. package/dist/src/composed-inventory-gateways.js +1 -1
  35. package/dist/src/composite-resource-admission.js +1 -1
  36. package/dist/src/connection-runtime.js +1 -1
  37. package/dist/src/connection.js +5 -5
  38. package/dist/src/contract.d.ts +2 -1
  39. package/dist/src/contracts.d.ts +1 -1
  40. package/dist/src/daemon-client-lease-beat.js +1 -1
  41. package/dist/src/daemon-client.js +2 -2
  42. package/dist/src/daemon-command-registry.js +1 -1
  43. package/dist/src/daemon-composition.js +1 -1
  44. package/dist/src/daemon-policy-file.js +1 -1
  45. package/dist/src/debug-symbols-facade.js +1 -1
  46. package/dist/src/destination-tunnel-dialer.js +27 -0
  47. package/dist/src/device-claim-recovery.js +1 -1
  48. package/dist/src/device-claims.js +1 -1
  49. package/dist/src/device-input-state.d.ts +1 -1
  50. package/dist/src/device-readiness-runtime.js +1 -1
  51. package/dist/src/device-selection-resolver.js +1 -1
  52. package/dist/src/device.js +1 -1
  53. package/dist/src/discovery.js +1 -1
  54. package/dist/src/doctor-facade.js +1 -1
  55. package/dist/src/durable-resource.js +1 -1
  56. package/dist/src/explicit-session-resolution.js +1 -1
  57. package/dist/src/find.js +1 -1
  58. package/dist/src/generic.js +1 -1
  59. package/dist/src/gesture-admission.js +1 -1
  60. package/dist/src/gesture-plan-types.d.ts +1 -1
  61. package/dist/src/gesture-runtime.js +1 -1
  62. package/dist/src/human-control.js +1 -1
  63. package/dist/src/index.d.ts +1 -1
  64. package/dist/src/instance-client.js +1 -1
  65. package/dist/src/interaction.js +1 -1
  66. package/dist/src/interaction2.js +1 -1
  67. package/dist/src/interactor.js +5 -5
  68. package/dist/src/interactor4.js +1 -1
  69. package/dist/src/interactors.js +1 -1
  70. package/dist/src/internal/bin.js +1 -1
  71. package/dist/src/inventory2.js +1 -1
  72. package/dist/src/ios-client.js +4 -4
  73. package/dist/src/launch-confirmation.js +1 -1
  74. package/dist/src/lease-context.js +1 -1
  75. package/dist/src/lease-registry-scope.js +1 -1
  76. package/dist/src/lease.js +1 -1
  77. package/dist/src/leased-recording-retention.js +1 -1
  78. package/dist/src/legacy.js +1 -1
  79. package/dist/src/limrun.d.ts +6 -1
  80. package/dist/src/local-interactor-operation-set.js +1 -1
  81. package/dist/src/log-stream.js +2 -28
  82. package/dist/src/mechanics.js +1 -1
  83. package/dist/src/metro.d.ts +1 -1
  84. package/dist/src/network-har.js +2 -0
  85. package/dist/src/open-target-resolution.js +1 -1
  86. package/dist/src/perf-facade.js +1 -1
  87. package/dist/src/perf-target.js +1 -1
  88. package/dist/src/platform-runtime-daemon-services.js +1 -1
  89. package/dist/src/platform-runtime-open-target.js +1 -1
  90. package/dist/src/platform-runtime-operation-host.js +3 -3
  91. package/dist/src/platform-runtime-runtime-hints.js +1 -1
  92. package/dist/src/platform-runtime-unavailable.js +1 -1
  93. package/dist/src/platform-runtime.js +1 -1
  94. package/dist/src/platform-runtime2.js +1 -1
  95. package/dist/src/plugin-inventory.js +1 -1
  96. package/dist/src/provider-device-runtime.d.ts +1 -1
  97. package/dist/src/provider-plugin.d.ts +1 -1
  98. package/dist/src/proxy.js +2 -2
  99. package/dist/src/react-native.js +1 -1
  100. package/dist/src/record-runtime-response.js +1 -1
  101. package/dist/src/record-runtime.js +1 -1
  102. package/dist/src/record-trace.js +1 -1
  103. package/dist/src/registry.js +1 -1
  104. package/dist/src/replay-maestro-backend.js +3 -3
  105. package/dist/src/replay-script-selection.js +1 -1
  106. package/dist/src/replay.d.ts +1 -1
  107. package/dist/src/request-runtime-binding.js +1 -1
  108. package/dist/src/result-serialization.js +2 -1
  109. package/dist/src/runner-client.js +1 -1
  110. package/dist/src/runner-dev-tools-security.js +1 -1
  111. package/dist/src/runner-device-readiness.js +1 -1
  112. package/dist/src/runner-retention.js +1 -1
  113. package/dist/src/runner-selector-query.js +1 -1
  114. package/dist/src/runner-startup-transport.js +1 -1
  115. package/dist/src/runner.js +1 -1
  116. package/dist/src/runtime-admission.js +1 -1
  117. package/dist/src/runtime-deployment.js +1 -1
  118. package/dist/src/runtime-session.js +1 -1
  119. package/dist/src/runtime.js +2 -2
  120. package/dist/src/runtime3.js +4 -4
  121. package/dist/src/runtime4.js +1 -1
  122. package/dist/src/runtime5.js +1 -1
  123. package/dist/src/runtime6.js +1 -1
  124. package/dist/src/runtime7.js +1 -1
  125. package/dist/src/runtime8.js +1 -1
  126. package/dist/src/runtime9.js +1 -1
  127. package/dist/src/screen-recording-resource-recovery.js +1 -1
  128. package/dist/src/screen-recording-session-resource.js +1 -1
  129. package/dist/src/screen-recording-transport.js +1 -1
  130. package/dist/src/screenshot-density.js +1 -1
  131. package/dist/src/screenshot-runtime.js +1 -1
  132. package/dist/src/sdk-batch-runner.js +2 -2
  133. package/dist/src/sdk-batch.js +2 -2
  134. package/dist/src/sdk-contracts.d.ts +4 -1
  135. package/dist/src/sdk-device.js +1 -1
  136. package/dist/src/sdk-finders.d.ts +1 -1
  137. package/dist/src/sdk-remote-config.d.ts +8 -1
  138. package/dist/src/sdk-remote-config.js +1 -1
  139. package/dist/src/sdk-selectors.d.ts +1 -1
  140. package/dist/src/selector-runtime.js +1 -1
  141. package/dist/src/server-startup.js +1 -1
  142. package/dist/src/server.js +1 -1
  143. package/dist/src/session-artifact-paths.js +1 -1
  144. package/dist/src/session-device-resolution.js +1 -1
  145. package/dist/src/session-open.js +1 -1
  146. package/dist/src/session-runtime.js +1 -1
  147. package/dist/src/session-selector.js +1 -1
  148. package/dist/src/session-store.js +1 -1
  149. package/dist/src/session2.js +4 -4
  150. package/dist/src/settle-observation-capture.js +1 -1
  151. package/dist/src/simctl.js +1 -1
  152. package/dist/src/simulator-boot.js +1 -1
  153. package/dist/src/snapshot-diagnostics.js +1 -1
  154. package/dist/src/snapshot-runtime-binding.js +1 -1
  155. package/dist/src/snapshot-runtime-capture-input.js +1 -1
  156. package/dist/src/snapshot-runtime.js +1 -1
  157. package/dist/src/snapshot.js +1 -1
  158. package/dist/src/src.js +1 -1
  159. package/dist/src/src3.js +4 -4
  160. package/dist/src/src4.js +1 -1
  161. package/dist/src/src9.js +1 -1
  162. package/dist/src/store.js +1 -1
  163. package/dist/src/telephony-runtime.js +1 -1
  164. package/dist/src/touch-runtime2.js +1 -1
  165. package/dist/src/transport.js +2 -2
  166. package/dist/src/tv-remote-runtime.js +1 -1
  167. package/dist/src/tv-remote.js +1 -1
  168. package/dist/src/type-text-runtime.js +1 -1
  169. package/package.json +1 -1
  170. package/server.json +2 -2
  171. package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.34.apk.sha256 +0 -1
  172. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.34.apk.sha256 +0 -1
  173. package/dist/src/session-capture-binding.js +0 -1
  174. package/dist/src/session-teardown.js +0 -1
@@ -1,5 +1,5 @@
1
- import{D as e,H as t,Q as n,R as r,V as i,tt as a}from"./sdk-contracts.js";import{l as o}from"./tv-remote.js";import{a as s,b as c,i as l,v as u}from"./sdk-batch-runner.js";import{K as d,St as f,Y as p,_t as m}from"./sdk-io.js";import"./diagnostics.js";import{A as h,C as g,H as _,R as v,S as ee,w as y,x as te,y as ne}from"./sdk-device.js";import{Cn as b,Sn as x,gn as re,wn as ie,xn as ae}from"./sdk-batch.js";import{i as oe,r as se}from"./session.js";import"./command.js";import{i as ce,n as le,r as ue}from"./ios-snapshot-planning.js";import{i as de,n as fe}from"./durable-resource.js";import{n as pe}from"./screen-recording-runtime.js";import{t as me}from"./request.js";import{n as he,r as ge,t as _e}from"./application-lifecycle-runtime.js";import{n as ve,t as ye}from"./async-lifecycle.js";import{i as be,t as xe}from"./touch-runtime.js";import{t as Se}from"./ios-system-surface.js";import{r as Ce}from"./gesture-admission.js";import{B as we,C as Te,E as Ee,I as De,K as Oe,M as ke,N as Ae,O as je,P as Me,R as Ne,T as Pe,U as Fe,V as Ie,W as Le,X as Re,Y as ze,Z as Be,_ as Ve,j as He,k as Ue,l as We,o as Ge,p as Ke,q as qe,r as Je,v as Ye,x as Xe}from"./tv-remote-runtime.js";import{n as Ze,o as Qe,s as $e,u as et}from"./application-lifecycle-interaction.js";import{t as tt}from"./interactor-operation-catalog.js";import{a as nt,i as rt,n as it,o as at,r as ot,s as st,t as ct}from"./network-traffic.js";import{a as lt,i as ut,r as dt}from"./src4.js";import{n as ft,t as pt}from"./screen-recording-completion.js";import{a as mt,c as ht,i as gt,n as _t,o as vt,r as yt,s as bt,t as xt}from"./device-readiness-runtime.js";import{a as St,i as Ct,n as wt,r as Tt,t as Et}from"./perf-runtime-operation-builder.js";import{t as Dt}from"./app-log-runtime.js";import{n as Ot}from"./artifact-paths.js";import{a as kt}from"./config.js";import{a as At}from"./tool-provider.js";import{o as jt}from"./devicectl.js";import{i as Mt}from"./physical-device-control.js";import{a as Nt,c as Pt,n as Ft,o as It,s as S,u as Lt}from"./simctl.js";import{c as Rt,u as zt}from"./runner-client.js";import{i as Bt,n as Vt,r as Ht,t as Ut}from"./app-backend.js";import{t as Wt}from"./simulator-state.js";import{randomUUID as Gt}from"node:crypto";import Kt from"node:path";function qt(e,t){return Object.freeze({appState:async n=>{if(t.signal.throwIfAborted(),!await e.appleApplications.hasLiveRunnerSession(t.device,{}))return{};let r=await t.resolveInteractor(t.device,{appBundleId:n?.appBundleId,signal:t.signal});if(typeof r.appState!=`function`)throw ie(`Runtime owner advertised appState without an interactor implementation`);return await r.appState()}})}function Jt(e){return e.hostApp?Object.freeze({available:!1,reason:`unsupported-device-scope`,hint:`This session holds one app of the Mac. Use a --surface desktop session for audio probe.`}):vt(e)?Object.freeze({available:!0}):y(e)||g(e)&&e.kind===`simulator`?Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`audio probe capture requires a macOS host.`}):Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`audio is supported for macOS sessions and iOS simulators on macOS hosts; physical iOS devices expose no host audio tap.`})}function Yt(e){let{resolveHost:t,device:n,owner:r}=e;return Object.freeze({...Et({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 Ct(t().sampleFrames(n,e)):wt(`Apple`,`bundle ID`),sampling:await t().frameSampling(n)}),perfMemorySample:async({appId:e})=>({metric:e?await Ct(t().sampleMemory(n,e)):wt(`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 St(`Apple`,o,s,`Use perf memory snapshot --kind memgraph for supported Apple app sessions.`);if(!e)throw Tt();let c=i??Kt.join(a,`memory-memgraph-${Xt()}.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 Xt(){return new Date().toISOString().replaceAll(/[:.]/g,`-`)}const C=Object.freeze({available:!0}),w=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),T=$t(`Gestures are supported only for Apple simulators and devices.`),Zt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:Ce}),Qt=$t(`scroll is supported only for Apple simulators and devices.`);function $t(e){return Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:e})}function en(e){return{...Oe({unsupported:tn(e),plan:nn(e),directionalFling:nn(e),multiTouch:rn(e),targetAuthoredDrag:an(e),viewport:on(e)}),...Fe({scroll:sn(e)})}}function tn(e){return e.appleOs===`watchos`||e.appleOs===`visionos`?w:T}function nn(e){return e.appleOs===`watchos`||e.appleOs===`visionos`?w:E(e)?C:T}function rn(e){if(e.appleOs===`watchos`)return w;if(!E(e))return T;let t=v(e);if(t!==`ios`&&t!==`ipados`){let e=Bt[t];return Object.freeze({available:!1,reason:`unsupported-platform-leaf`,...e===void 0?{}:{hint:e}})}return C}function an(e){return E(e)?(e.appleOs===void 0?e.target!==`desktop`&&e.target!==`tv`:e.appleOs===`ios`||e.appleOs===`ipados`)?C:Zt:T}function on(e){return e.appleOs===`watchos`?w:E(e)?C:T}function sn(e){return E(e)?C:Qt}function E(e){return e.kind===`simulator`||e.kind===`device`}const D=`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`;function O(e){return y(e)?`macos`:e.kind===`device`?`ios-device`:`ios-simulator`}const cn=Object.freeze({resourceKind:Dt,version:1,encode:e=>({...e}),decode:e=>!un(e.transport)||!dn(e.backend)||!hn(e.outputPath)||!pn(e.pidPath)||!fn(e.transport,e.backend)?ln():{status:`decoded`,descriptor:Object.freeze({transport:e.transport,backend:e.backend,outputPath:e.outputPath,...e.pidPath===void 0?{}:{pidPath:e.pidPath}})}});function ln(){return{status:`invalid`,message:`Invalid Apple app-log descriptor`}}function un(e){return e===`apple-log-stream`||e===`coredevice-console`}function dn(e){return e===`ios-simulator`||e===`ios-device`||e===`macos`}function fn(e,t){return e===`coredevice-console`?t===`ios-device`:t!==`ios-device`}function pn(e){return e===void 0||hn(e)}function mn(e){if(!e.device.appleOs)throw TypeError(`Apple app-log persistence requires an explicit appleOs identity`);return fe({resourceKind:Dt,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:de(cn,e.descriptor)})}function hn(e){return typeof e==`string`&&e.trim().length>0}const gn={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.`},_n={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 vn(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 yn(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(y(t))i.logAvailable=!!await e.commands.which(`log`);else if(t.kind===`simulator`)i.simctlAvailable=await ht(async()=>bt(await e.appleTools.run({tool:`simctl`,args:Pt(),allowFailure:!0},r)),r);else if(t.iosPhysicalDeviceBackend===`xctest`)i.devicectlAvailable=!1,i.devicectlConsoleCapture=!1,a.push(D);else{i.devicectlAvailable=await ht(async()=>bt(await e.appleTools.run({tool:`devicectl`,args:[`--version`],allowFailure:!0},r)),r);let t=await vn(e,r);if(i.devicectlConsoleCapture=t.supported,!t.supported){let e=t.reason===`unsupported`?gn:_n;a.push(`${e.message} ${e.hint}`)}}return{backend:O(t),checks:i,notes:a}}function bn(e,t){let n=Cn(e),r=[`subsystem == "${n}"`,`subsystem CONTAINS "${n}"`,`processImagePath ENDSWITH[c] "/${n}"`,`senderImagePath ENDSWITH[c] "/${n}"`];if(t){let e=Cn(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 xn(e,t){return Ft(e,[`spawn`,e.id,`log`,`stream`,`--style`,`compact`,`--level`,`info`,`--predicate`,bn(t.appBundleId,t.executableName)])}function Sn(e,t){return[`devicectl`,`device`,`process`,`launch`,`--device`,e,`--console`,`--terminate-existing`,t]}function Cn(e){return e.replaceAll(`\\`,String.raw`\\`).replaceAll(`"`,String.raw`\"`)}const wn=1e4;async function Tn(e,t,n,r,i){En(t),rt(e,n);let a=O(t),o=await On(e,t,n.appBundleId,i),s=new ye,c=!1;try{let l=await e.outputs.openAppend(n.outputPath);s.defer(async()=>{c||await l[Symbol.asyncDispose]()}),i?.throwIfAborted();let u=An(l),d=await Dn(e,t,o,u.sink,n.pidPath,i);s.defer(async()=>{c||await d[Symbol.asyncDispose]()}),t.kind===`simulator`&&await jn(e,u.written,d.wait,i);let f=Mn(e,d,l,a,n.outputPath),p={transport:a===`ios-device`?`coredevice-console`:`apple-log-stream`,backend:a,outputPath:n.outputPath,...n.pidPath===void 0?{}:{pidPath:n.pidPath}},m=st(f,mn({sessionId:n.sessionId,device:t,owner:r,fence:n.fence,descriptor:p}));return c=!0,m}finally{await s[Symbol.asyncDispose]()}}function En(e){if(e.appleOs===`watchos`)throw new r(`UNSUPPORTED_PLATFORM`,`watchOS app logs are not supported`);if(g(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`)throw new r(`UNSUPPORTED_OPERATION`,D,{hint:D})}async function Dn(e,t,n,i,a,o){if(g(t)&&t.kind===`device`){let t=await vn(e,o);if(!t.supported){let e=t.reason===`unsupported`?gn:_n;throw new r(t.reason===`unsupported`?`UNSUPPORTED_OPERATION`:`COMMAND_FAILED`,e.message,{backend:`ios-device`,hint:e.hint,stderr:t.stderr})}}return o?.throwIfAborted(),await e.processes.start({command:{kind:`host`,request:n},output:i,...a?{markerPath:a}:{}})}async function On(e,t,n,r){return y(t)?{executable:`log`,args:[`stream`,`--style`,`compact`,`--predicate`,bn(n)],allowFailure:!0}:t.kind===`device`?{executable:`xcrun`,args:Sn(t.id,n),allowFailure:!0}:{executable:`xcrun`,args:xn(t,{appBundleId:n,executableName:await kn(e,t,n,r)}),allowFailure:!0}}async function kn(e,t,n,r){let i=await e.appleTools.run({tool:`simctl`,args:S(t,[`get_app_container`,t.id,n,`app`]),allowFailure:!0,timeoutMs:4e3},r),a=i.exitCode===0?i.stdout.trim():``;if(!a)return;let o=await e.commands.run({executable:`plutil`,args:[`-extract`,`CFBundleExecutable`,`raw`,`-o`,`-`,Kt.join(a,`Info.plist`)],allowFailure:!0,timeoutMs:4e3},r);return o.exitCode===0&&o.stdout.trim()||void 0}function An(e){let t=k,n=new Promise(e=>{t=e});return{sink:{write:async n=>{t(),await e.write(n)},[Symbol.asyncDispose]:async()=>await e[Symbol.asyncDispose]()},written:n}}async function jn(e,t,n,i){i?.throwIfAborted();let a=k,o=new Promise((e,t)=>{a=()=>t(i?.reason),i?.addEventListener(`abort`,a,{once:!0})}),s=new AbortController,c=e.clock.sleep(wn,s.signal).then(()=>`timed-out`);c.catch(k);try{let e=Promise.race([t,n.then(k,k)]).then(()=>`launched`);if(await Promise.race([e,c,o])===`timed-out`)throw new r(`COMMAND_FAILED`,`Simulator log stream did not start within ${wn}ms`,{reason:`simulator-log-stream-launch-timeout`,timeoutMs:wn,hint:`Check that the simulator finished booting, then retry logs start.`})}finally{s.abort(),i?.removeEventListener(`abort`,a)}}function k(){}function Mn(e,t,n,r,i){let a=e.clock.now(),o=`active`;t.wait.then(e=>{o=e.exitCode===0?`ended`:`failed`},()=>{o=`failed`});let s;return nt({inspect:()=>({backend:r,state:o,startedAt:a}),finish:async()=>s??=(async()=>(await Nn([async()=>await t.terminate(),async()=>await t.wait.then(()=>void 0),async()=>await t[Symbol.asyncDispose](),async()=>await n[Symbol.asyncDispose]()])).length>0?(o=`failed`,{status:`cleanup-pending`,reason:`transport-failed`,message:`Apple app-log cleanup did not settle every owned resource`}):(o=`ended`,{status:`completed`,result:{backend:r,outputPath:i,completedAt:e.clock.now()}}))()})}async function Nn(e){let t=[];for(let n of e)try{await n()}catch(e){t.push(e)}return t}const A=re(`apple`),Pn=Object.freeze({available:!0});function Fn(e){return Object.freeze({owner:A,ownsDevice:e=>e.platform===`apple`,inspectFacts:async e=>Ln(e),bind:async t=>{if(t.intent.kind===`exact-owner`&&!ae(t.intent.owner,A))throw new r(`UNSUPPORTED_OPERATION`,`Apple app-log owner identity does not match`);return In(e,t.device,t.scope.signal)},shutdown:async()=>void 0})}function In(e,t,n){if(t.platform!==`apple`)throw new r(`UNSUPPORTED_PLATFORM`,`Apple app-log owner cannot bind ${t.platform}`);let i=at({codec:cn,reattach:async(n,r)=>n.backend!==O(t)||!ot(e,r.sessionId,n)?{status:`unreattachable`,reason:`descriptor-invalid`,message:`Apple app-log descriptor does not match the bound device or owning session`}:await ut(e,n.pidPath),cleanup:async(n,r)=>n.backend===O(t)&&ot(e,r.sessionId,n)?await dt(e,n.pidPath):{status:`cleanup-pending`,reason:`ownership-fence-lost`,message:`Apple app-log descriptor does not match the bound device or owning session`}}),a=Object.freeze({appLogInspect:async()=>({backend:O(t)}),appLogDoctor:async({appBundleId:r})=>await yn(e,t,r,n),appLogStart:async r=>await Tn(e,t,r,A,n),...i});return Object.freeze({device:t,owner:A,facts:Ln(t),operations:a,[Symbol.asyncDispose]:async()=>void 0})}function Ln(e){if(e.appleOs===`watchos`)return Rn(e);let t=g(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?{available:!1,reason:`unsupported-device-backend`,hint:D}:Pn;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:Pn,appLogCleanup:Pn}})}function Rn(e){let t=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS app logs are not supported.`});return Object.freeze({device:{family:`apple`,appleOs:`watchos`,kind:e.kind,...e.target===void 0?{}:{target:e.target},providerMode:`local`},operations:{appLogInspect:t,appLogDoctor:t,appLogStart:t,appLogReattach:t,appLogCleanup:t}})}async function zn(e,t,n,r){let i=O(t),a=await e.appLogs.readRecent(n.sessionId,n.maxScanLines),o=it(a.text,{...n,path:a.path,exists:a.exists,lineNumberOffset:a.skippedLines,backend:i}),s=[];if(Vn(t,n,o.dump)){let i=await Hn(e,t,n,a.path,r);i&&(o=Bn(s,o,i,n.maxEntries))}return Gn(s,t,n),Wn(s,o.dump),o.dump.entries.length===0&&s.push(Kn(t)),Object.freeze({source:`app-log`,backend:i,dump:o.dump,notes:Object.freeze(s)})}function Bn(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).`),ct(n.scan,t,r))}function Vn(e,t,n){return g(e)&&e.kind===`simulator`&&!!t.appBundleId&&n.entries.length===0}async function Hn(e,t,n,r,i){let a=n.appLogSnapshot?.startedAt,o=S(t,[`spawn`,t.id,`log`,`show`,`--style`,`compact`,`--info`,`--predicate`,Un(n.appBundleId),...typeof a==`number`&&Number.isFinite(a)&&a>0?[`--start`,`@${Math.floor(a/1e3)}`]:[`--last`,`5m`]]),s=await e.appleTools.run({tool:`simctl`,args:o,allowFailure:!0,timeoutMs:4e3},i);if(s.exitCode!==0||!s.stdout.trim())return;let c=s.stdout.split(`
1
+ import{D as e,H as t,Q as n,R as r,V as i,tt as a}from"./sdk-contracts.js";import{l as o}from"./tv-remote.js";import{a as s,o as c,x as l,y as u}from"./sdk-batch-runner.js";import{K as d,St as f,Y as p,_t as m}from"./sdk-io.js";import"./diagnostics.js";import{B as h,C as g,S as _,T as v,W as ee,b as te,j as ne,w as y}from"./sdk-device.js";import{Cn as re,En as ie,Tn as b,vn as ae,wn as x}from"./sdk-batch.js";import{i as oe,r as se}from"./session.js";import"./command.js";import{i as ce,n as le,r as ue}from"./ios-snapshot-planning.js";import{i as de,n as fe}from"./durable-resource.js";import{n as pe}from"./screen-recording-runtime.js";import{t as me}from"./request.js";import{n as he,r as ge,t as _e}from"./application-lifecycle-runtime.js";import{n as ve,t as ye}from"./async-lifecycle.js";import{i as be,t as xe}from"./touch-runtime.js";import{t as Se}from"./ios-system-surface.js";import{r as Ce}from"./gesture-admission.js";import{B as we,C as Te,E as Ee,I as De,K as Oe,M as ke,N as Ae,O as je,P as Me,R as Ne,T as Pe,U as Fe,V as Ie,W as Le,X as Re,Y as ze,Z as Be,_ as Ve,j as He,k as Ue,l as We,o as Ge,p as Ke,q as qe,r as Je,v as Ye,x as Xe}from"./tv-remote-runtime.js";import{n as Ze,o as Qe,s as $e,u as et}from"./application-lifecycle-interaction.js";import{t as tt}from"./interactor-operation-catalog.js";import{a as nt,i as rt,n as it,o as at,r as ot,s as st,t as ct}from"./network-traffic.js";import{a as lt,i as ut,r as dt}from"./src4.js";import{n as ft,t as pt}from"./screen-recording-completion.js";import{a as mt,c as ht,i as gt,n as _t,o as vt,r as yt,s as bt,t as xt}from"./device-readiness-runtime.js";import{a as St,i as Ct,n as wt,r as Tt,t as Et}from"./perf-runtime-operation-builder.js";import{t as Dt}from"./app-log-runtime.js";import{n as Ot}from"./artifact-paths.js";import{a as kt}from"./config.js";import{a as At}from"./tool-provider.js";import{o as jt}from"./devicectl.js";import{i as Mt}from"./physical-device-control.js";import{a as Nt,c as Pt,n as Ft,o as It,s as S,u as Lt}from"./simctl.js";import{c as Rt,u as zt}from"./runner-client.js";import{i as Bt,n as Vt,r as Ht,t as Ut}from"./app-backend.js";import{t as Wt}from"./simulator-state.js";import{randomUUID as Gt}from"node:crypto";import Kt from"node:path";function qt(e,t){return Object.freeze({appState:async n=>{if(t.signal.throwIfAborted(),!await e.appleApplications.hasLiveRunnerSession(t.device,{}))return{};let r=await t.resolveInteractor(t.device,{appBundleId:n?.appBundleId,signal:t.signal});if(typeof r.appState!=`function`)throw ie(`Runtime owner advertised appState without an interactor implementation`);return await r.appState()}})}function Jt(e){return e.hostApp?Object.freeze({available:!1,reason:`unsupported-device-scope`,hint:`This session holds one app of the Mac. Use a --surface desktop session for audio probe.`}):vt(e)?Object.freeze({available:!0}):v(e)||y(e)&&e.kind===`simulator`?Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`audio probe capture requires a macOS host.`}):Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`audio is supported for macOS sessions and iOS simulators on macOS hosts; physical iOS devices expose no host audio tap.`})}function Yt(e){let{resolveHost:t,device:n,owner:r}=e;return Object.freeze({...Et({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 Ct(t().sampleFrames(n,e)):wt(`Apple`,`bundle ID`),sampling:await t().frameSampling(n)}),perfMemorySample:async({appId:e})=>({metric:e?await Ct(t().sampleMemory(n,e)):wt(`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 St(`Apple`,o,s,`Use perf memory snapshot --kind memgraph for supported Apple app sessions.`);if(!e)throw Tt();let c=i??Kt.join(a,`memory-memgraph-${Xt()}.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 Xt(){return new Date().toISOString().replaceAll(/[:.]/g,`-`)}const C=Object.freeze({available:!0}),w=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),T=$t(`Gestures are supported only for Apple simulators and devices.`),Zt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:Ce}),Qt=$t(`scroll is supported only for Apple simulators and devices.`);function $t(e){return Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:e})}function en(e){return{...Oe({unsupported:tn(e),plan:nn(e),directionalFling:nn(e),multiTouch:rn(e),targetAuthoredDrag:an(e),viewport:on(e)}),...Fe({scroll:sn(e)})}}function tn(e){return e.appleOs===`watchos`||e.appleOs===`visionos`?w:T}function nn(e){return e.appleOs===`watchos`||e.appleOs===`visionos`?w:E(e)?C:T}function rn(e){if(e.appleOs===`watchos`)return w;if(!E(e))return T;let t=h(e);if(t!==`ios`&&t!==`ipados`){let e=Bt[t];return Object.freeze({available:!1,reason:`unsupported-platform-leaf`,...e===void 0?{}:{hint:e}})}return C}function an(e){return E(e)?(e.appleOs===void 0?e.target!==`desktop`&&e.target!==`tv`:e.appleOs===`ios`||e.appleOs===`ipados`)?C:Zt:T}function on(e){return e.appleOs===`watchos`?w:E(e)?C:T}function sn(e){return E(e)?C:Qt}function E(e){return e.kind===`simulator`||e.kind===`device`}const D=`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`;function O(e){return v(e)?`macos`:e.kind===`device`?`ios-device`:`ios-simulator`}const cn=Object.freeze({resourceKind:Dt,version:1,encode:e=>({...e}),decode:e=>!un(e.transport)||!dn(e.backend)||!hn(e.outputPath)||!pn(e.pidPath)||!fn(e.transport,e.backend)?ln():{status:`decoded`,descriptor:Object.freeze({transport:e.transport,backend:e.backend,outputPath:e.outputPath,...e.pidPath===void 0?{}:{pidPath:e.pidPath}})}});function ln(){return{status:`invalid`,message:`Invalid Apple app-log descriptor`}}function un(e){return e===`apple-log-stream`||e===`coredevice-console`}function dn(e){return e===`ios-simulator`||e===`ios-device`||e===`macos`}function fn(e,t){return e===`coredevice-console`?t===`ios-device`:t!==`ios-device`}function pn(e){return e===void 0||hn(e)}function mn(e){if(!e.device.appleOs)throw TypeError(`Apple app-log persistence requires an explicit appleOs identity`);return fe({resourceKind:Dt,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:de(cn,e.descriptor)})}function hn(e){return typeof e==`string`&&e.trim().length>0}const gn={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.`},_n={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 vn(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 yn(e,t,n,r){let i={},a=n?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`];if(v(t))i.logAvailable=!!await e.commands.which(`log`);else if(t.kind===`simulator`)i.simctlAvailable=await ht(async()=>bt(await e.appleTools.run({tool:`simctl`,args:Pt(),allowFailure:!0},r)),r);else if(t.iosPhysicalDeviceBackend===`xctest`)i.devicectlAvailable=!1,i.devicectlConsoleCapture=!1,a.push(D);else{i.devicectlAvailable=await ht(async()=>bt(await e.appleTools.run({tool:`devicectl`,args:[`--version`],allowFailure:!0},r)),r);let t=await vn(e,r);if(i.devicectlConsoleCapture=t.supported,!t.supported){let e=t.reason===`unsupported`?gn:_n;a.push(`${e.message} ${e.hint}`)}}return{backend:O(t),checks:i,notes:a}}function bn(e,t){let n=Cn(e),r=[`subsystem == "${n}"`,`subsystem CONTAINS "${n}"`,`processImagePath ENDSWITH[c] "/${n}"`,`senderImagePath ENDSWITH[c] "/${n}"`];if(t){let e=Cn(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 xn(e,t){return Ft(e,[`spawn`,e.id,`log`,`stream`,`--style`,`compact`,`--level`,`info`,`--predicate`,bn(t.appBundleId,t.executableName)])}function Sn(e,t){return[`devicectl`,`device`,`process`,`launch`,`--device`,e,`--console`,`--terminate-existing`,t]}function Cn(e){return e.replaceAll(`\\`,String.raw`\\`).replaceAll(`"`,String.raw`\"`)}const k=1e4;async function wn(e,t,n,r,i){Tn(t),rt(e,n);let a=O(t),o=await Dn(e,t,n.appBundleId,i),s=new ye,c=!1;try{let l=await e.outputs.openAppend(n.outputPath);s.defer(async()=>{c||await l[Symbol.asyncDispose]()}),i?.throwIfAborted();let u=kn(l),d=await En(e,t,o,u.sink,n.pidPath,i);s.defer(async()=>{c||await d[Symbol.asyncDispose]()}),t.kind===`simulator`&&await An(e,u.written,d.wait,i);let f=jn(e,d,l,a,n.outputPath),p={transport:a===`ios-device`?`coredevice-console`:`apple-log-stream`,backend:a,outputPath:n.outputPath,...n.pidPath===void 0?{}:{pidPath:n.pidPath}},m=st(f,mn({sessionId:n.sessionId,device:t,owner:r,fence:n.fence,descriptor:p}));return c=!0,m}finally{await s[Symbol.asyncDispose]()}}function Tn(e){if(e.appleOs===`watchos`)throw new r(`UNSUPPORTED_PLATFORM`,`watchOS app logs are not supported`);if(y(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`)throw new r(`UNSUPPORTED_OPERATION`,D,{hint:D})}async function En(e,t,n,i,a,o){if(y(t)&&t.kind===`device`){let t=await vn(e,o);if(!t.supported){let e=t.reason===`unsupported`?gn:_n;throw new r(t.reason===`unsupported`?`UNSUPPORTED_OPERATION`:`COMMAND_FAILED`,e.message,{backend:`ios-device`,hint:e.hint,stderr:t.stderr})}}return o?.throwIfAborted(),await e.processes.start({command:{kind:`host`,request:n},output:i,...a?{markerPath:a}:{}})}async function Dn(e,t,n,r){return v(t)?{executable:`log`,args:[`stream`,`--style`,`compact`,`--predicate`,bn(n)],allowFailure:!0}:t.kind===`device`?{executable:`xcrun`,args:Sn(t.id,n),allowFailure:!0}:{executable:`xcrun`,args:xn(t,{appBundleId:n,executableName:await On(e,t,n,r)}),allowFailure:!0}}async function On(e,t,n,r){let i=await e.appleTools.run({tool:`simctl`,args:S(t,[`get_app_container`,t.id,n,`app`]),allowFailure:!0,timeoutMs:4e3},r),a=i.exitCode===0?i.stdout.trim():``;if(!a)return;let o=await e.commands.run({executable:`plutil`,args:[`-extract`,`CFBundleExecutable`,`raw`,`-o`,`-`,Kt.join(a,`Info.plist`)],allowFailure:!0,timeoutMs:4e3},r);return o.exitCode===0&&o.stdout.trim()||void 0}function kn(e){let t=A,n=new Promise(e=>{t=e});return{sink:{write:async n=>{t(),await e.write(n)},[Symbol.asyncDispose]:async()=>await e[Symbol.asyncDispose]()},written:n}}async function An(e,t,n,i){i?.throwIfAborted();let a=A,o=new Promise((e,t)=>{a=()=>t(i?.reason),i?.addEventListener(`abort`,a,{once:!0})}),s=new AbortController,c=e.clock.sleep(k,s.signal).then(()=>`timed-out`);c.catch(A);try{let e=Promise.race([t,n.then(A,A)]).then(()=>`launched`);if(await Promise.race([e,c,o])===`timed-out`)throw new r(`COMMAND_FAILED`,`Simulator log stream did not start within ${k}ms`,{reason:`simulator-log-stream-launch-timeout`,timeoutMs:k,hint:`Check that the simulator finished booting, then retry logs start.`})}finally{s.abort(),i?.removeEventListener(`abort`,a)}}function A(){}function jn(e,t,n,r,i){let a=e.clock.now(),o=`active`;t.wait.then(e=>{o=e.exitCode===0?`ended`:`failed`},()=>{o=`failed`});let s;return nt({inspect:()=>({backend:r,state:o,startedAt:a}),finish:async()=>s??=(async()=>(await Mn([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 Mn(e){let t=[];for(let n of e)try{await n()}catch(e){t.push(e)}return t}const j=ae(`apple`),M=Object.freeze({available:!0});function Nn(e){return Object.freeze({owner:j,ownsDevice:e=>e.platform===`apple`,inspectFacts:async e=>Fn(e),bind:async t=>{if(t.intent.kind===`exact-owner`&&!re(t.intent.owner,j))throw new r(`UNSUPPORTED_OPERATION`,`Apple app-log owner identity does not match`);return Pn(e,t.device,t.scope.signal)},shutdown:async()=>void 0})}function Pn(e,t,n){if(t.platform!==`apple`)throw new r(`UNSUPPORTED_PLATFORM`,`Apple app-log owner cannot bind ${t.platform}`);let i=at({codec:cn,reattach:async(n,r)=>n.backend!==O(t)||!ot(e,r.sessionId,n)?{status:`unreattachable`,reason:`descriptor-invalid`,message:`Apple app-log descriptor does not match the bound device or owning session`}:await ut(e,n.pidPath),cleanup:async(n,r)=>n.backend===O(t)&&ot(e,r.sessionId,n)?await dt(e,n.pidPath):{status:`cleanup-pending`,reason:`ownership-fence-lost`,message:`Apple app-log descriptor does not match the bound device or owning session`}}),a=Object.freeze({appLogInspect:async()=>({backend:O(t)}),appLogDoctor:async({appBundleId:r})=>await yn(e,t,r,n),appLogStart:async r=>await wn(e,t,r,j,n),...i});return Object.freeze({device:t,owner:j,facts:Fn(t),operations:a,[Symbol.asyncDispose]:async()=>void 0})}function Fn(e){if(e.appleOs===`watchos`)return In(e);let t=y(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?{available:!1,reason:`unsupported-device-backend`,hint:D}:M;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:M,appLogCleanup:M}})}function In(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 Ln(e,t,n,r){let i=O(t),a=await e.appLogs.readRecent(n.sessionId,n.maxScanLines),o=it(a.text,{...n,path:a.path,exists:a.exists,lineNumberOffset:a.skippedLines,backend:i}),s=[];if(zn(t,n,o.dump)){let i=await Bn(e,t,n,a.path,r);i&&(o=Rn(s,o,i,n.maxEntries))}return Un(s,t,n),Hn(s,o.dump),o.dump.entries.length===0&&s.push(Wn(t)),Object.freeze({source:`app-log`,backend:i,dump:o.dump,notes:Object.freeze(s)})}function Rn(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).`),ct(n.scan,t,r))}function zn(e,t,n){return y(e)&&e.kind===`simulator`&&!!t.appBundleId&&n.entries.length===0}async function Bn(e,t,n,r,i){let a=n.appLogSnapshot?.startedAt,o=S(t,[`spawn`,t.id,`log`,`show`,`--style`,`compact`,`--info`,`--predicate`,Vn(n.appBundleId),...typeof a==`number`&&Number.isFinite(a)&&a>0?[`--start`,`@${Math.floor(a/1e3)}`]:[`--last`,`5m`]]),s=await e.appleTools.run({tool:`simctl`,args:o,allowFailure:!0,timeoutMs:4e3},i);if(s.exitCode!==0||!s.stdout.trim())return;let c=s.stdout.split(`
2
2
  `).map(e=>e.trimEnd()).filter(e=>e.trim()&&!e.trim().startsWith(`Timestamp Ty Process[PID:TID]`));if(c.length!==0)return{scan:it(`${c.join(`
3
- `)}\n`,{...n,path:`${r} (simctl log show recovery)`,exists:!0,backend:`ios-simulator`}),lineCount:c.length}}function Un(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 Wn(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 Gn(e,t,n){n.appLogSnapshot?n.appLogSnapshot.state!==`active`&&e.length===0&&e.push(g(t)&&t.kind===`simulator`?`Session app log stream is inactive. The iOS simulator recovery path scanned recent simctl log history, but a fresh logs clear --restart window is still the most reliable repro loop.`:`Session app log stream is inactive. Run logs clear --restart, reproduce the request window again, then rerun network dump.`):e.push(`Capture uses the session app log file. For fresh traffic, run logs clear --restart before reproducing requests.`)}function Kn(e){return g(e)&&e.kind===`simulator`?`No HTTP(s) entries were found in recent iOS simulator app logs. If the app only emits non-HTTP diagnostics, inspect logs path or add app-side URLSession/network logging for per-request timing and payload details.`:g(e)?`No HTTP(s) entries were found in recent iOS device app logs. iOS network dump only sees what the app emits into Unified Logging for this process.`:`No HTTP(s) entries were found in recent session app logs.`}async function qn(e){let{host:t,snapshot:n,targetLabel:r,recorderWarning:a,nativePathDisposition:o}=e,s=n.invalidatedReason?{recorder:`lost`,why:`owner-session-lost`}:e.stopObservation;if(n.invalidatedReason&&!n.showTouches)throw Error(`recording invalidated: ${n.invalidatedReason}`);let c;try{c=await t.screenRecording.finalize.complete({outputPath:n.outPath,showTouches:!n.invalidatedReason&&n.showTouches,gestureEvents:n.gestureEvents,exportQuality:n.exportQuality??`medium`,...n.fps===void 0?{}:{fps:n.fps},targetLabel:r})}catch(e){throw i(e,`COMMAND_FAILED`)}let l=[...c.warning?[c.warning]:[],...a?[a]:[]];return pt(n,{...c,...l.length>0?{warning:l.join(` `)}:{},...n.invalidatedReason?{overlayWarning:`overlay unavailable: ${n.invalidatedReason}`}:{}},{stopObservation:s,...o===void 0?{}:{nativePathDisposition:o}})}async function Jn(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 Yn(()=>t.screenRecording.finalize.complete({outputPath:a,showTouches:s===void 0&&n.showTouches,gestureEvents:n.gestureEvents,exportQuality:n.exportQuality??`medium`,...n.fps===void 0?{}:{fps:n.fps},targetLabel:r}))}catch(e){throw await t.screenRecording.outputs.remove(a),e}return{...c,...s===void 0?{}:{overlayWarning:`overlay unavailable: ${s}`},nativePathDisposition:await t.screenRecording.outputs.remove(o)===`removed`?`retired`:`retirable`}}async function Yn(e){try{return await e()}catch(e){throw i(e,`COMMAND_FAILED`)}}const Xn=[`outPath`,`startedAt`,`clientOutPath`,...gt],Zn=Object.freeze({resourceKind:pe,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=>lr(e)});function Qn(e){let{device:t,owner:n,input:r,descriptor:i}=e;return fe({resourceKind:pe,sessionId:r.sessionId,device:_(t),owner:n,fence:r.fence,lifecycle:`open`,descriptor:de(Zn,i)})}function $n(e){let t={};for(let n of Xn)e[n]!==void 0&&Object.assign(t,{[n]:e[n]});return t}async function er(e,t,n,r){let i=Zn.decode(n);return i.status!==`decoded`||!yr(t,i.descriptor)?{status:`cleanup-pending`,reason:`manual-recovery-required`}:i.descriptor.backend===`simctl`?await tr(e,i.descriptor.processes,r):await rr(e,t,i.descriptor)}async function tr(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(nr(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(nr(n)),i.every(e=>e===`already-missing`)?{status:`already-missing`}:{status:`cleaned`})}function nr(e){return{kind:`session`,sessionId:e}}async function rr(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 ir(e){let{host:t,device:n,envelope:r}=e,i=Zn.decode(r.descriptor.body);return i.status===`decoded`?yr(n,i.descriptor)?i.descriptor.backend===`simctl`?await ar(e,i.descriptor):await sr(t,n,i.descriptor):j(`descriptor-invalid`,`Apple screen-recording descriptor does not match the bound device.`):j(`descriptor-invalid`,i.message)}async function ar(e,t){let n=await Promise.all(t.processes.map(async t=>await e.host.screenRecording.apple.inspectProcess(t)));if(!n.every(e=>e===`missing`))return j(`transport-not-reattachable`,n.includes(`ownership-lost`)?`Apple recording ownership no longer matches the durable descriptor.`:`Apple screen recordings require exact cleanup after daemon restart.`);let{recording:r}=t,i=or(yt(e.envelope.metadata),t.outputPath);return r===void 0||i!==void 0&&!await cr(e.host,i)?{status:`missing`}:{status:`restore-export`,recording:r,nativePath:t.outputPath,cleanup:async()=>await tr(e.host,t.processes,e.envelope.sessionId)}}function or(e,t){if(e.finalization===void 0)return e.collectedPath??t}async function sr(e,t,n){let r=await e.screenRecording.apple.inspectRunner(t,n.runnerSessionId,n.runnerAuthority);return r===`missing`?{status:`missing`}:j(`transport-not-reattachable`,r===`ownership-lost`?`Apple recording ownership no longer matches the durable descriptor.`:`Apple screen recordings require exact cleanup after daemon restart.`)}async function cr(e,t){try{return await e.screenRecording.finalize.sniff({outputPath:t}),!0}catch{return!1}}function j(e,t){return{status:`unreattachable`,reason:e,message:t}}function lr(e){return typeof e.outputPath!=`string`||e.outputPath.length===0?N():e.backend===`simctl`?ur(e,e.outputPath):e.backend===`runner`?pr(e,e.outputPath):N()}function ur(e,t){let n=br(e.processes),r=dr(e.recording);return!n||r===`invalid`?N():{status:`decoded`,descriptor:Object.freeze({backend:`simctl`,outputPath:t,processes:n,...r===void 0?{}:{recording:r}})}}function dr(e){if(e!==void 0)return u(e)&&fr(e)?Object.freeze(e):`invalid`}function fr(e){return M(e.outPath)&&hr(e.startedAt)&&mr(e.clientOutPath)&&mt(e)}function pr(e,t){return!M(e.appBundleId)||!M(e.runnerSessionId)||!gr(e.runnerAuthority)||!_r(e.remotePath)?N():{status:`decoded`,descriptor:Object.freeze({backend:`runner`,outputPath:t,appBundleId:e.appBundleId,runnerSessionId:e.runnerSessionId,runnerAuthority:e.runnerAuthority,...e.remotePath===void 0?{}:{remotePath:e.remotePath}})}}function M(e){return typeof e==`string`&&e.length>0}function mr(e){return e===void 0||M(e)}function hr(e){return typeof e==`number`&&Number.isFinite(e)}function gr(e){return e===`local-lease`||e===`scoped-provider`}function _r(e){return e===void 0||vr(e)}function vr(e){return typeof e==`string`&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(e)}function yr(e,t){return e.kind===`simulator`?t.backend===`simctl`:t.backend===`runner`?e.appleOs===`macos`?t.remotePath===void 0:g(e)?t.remotePath!==void 0&&vr(t.remotePath):t.remotePath===void 0:!1}function br(e){if(!Array.isArray(e)||e.length===0)return;let t=e.filter(e=>typeof e==`object`&&!!e&&Number.isInteger(e.pid)&&(e.pid??0)>0&&typeof e.startTime==`string`&&e.startTime.length>0&&typeof e.command==`string`&&e.command.length>0);return t.length===e.length?Object.freeze([...t]):void 0}function N(){return{status:`invalid`,message:`Invalid Apple screen-recording descriptor`}}async function xr(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 Sr=`iOS recording`,Cr=`simctl recordVideo`;function wr(e){return e.appleOs===`watchos`?x(`unsupported-platform-leaf`,`watchOS recording is not supported.`):g(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?x(`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 Tr(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await Er({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async e=>{let r=await ir({host:t,device:n,envelope:e.envelope});return r.status===`restore-export`?{status:`active`,handle:Or({host:t,restored:r})}:r},screenRecordingCleanup:async e=>await er(t,n,e.envelope.descriptor.body,e.envelope.sessionId)})}async function Er(e){return e.signal.throwIfAborted(),e.device.kind===`simulator`?await Dr(e):await Ar(e)}async function Dr(e){let{host:t,device:n,owner:r,input:i,signal:a}=e;await xr(n,i,t.screenRecording.apple.isRunnerBundleId);let o=i.activeSessionApp?await t.screenRecording.apple.captureClockAnchor(n,i.activeSessionApp.bundleId,a):void 0,s=Ot(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 P(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 P(c).catch(()=>{}),e}let u,d,f=async()=>{await c.terminate();let e=await c.wait;return d=e,u=Mr(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=Lr(i,Cr,{},o);return Ir({device:n,owner:r,input:i,descriptor:{backend:`simctl`,outputPath:s,processes:l,recording:$n(p)},snapshot:p,finish:(e,n)=>_t({snapshot:e,progress:n,steps:{stop:f,collect:async e=>{try{await kr(t,s,e)}catch(e){throw Nr(e,u,d)}},finalize:async({collectedPath:n,exportPath:r})=>{try{return await Jn({host:t,snapshot:e,targetLabel:Sr,collectedPath:n,exportPath:r,nativePath:s})}catch(e){throw Nr(e,u,d)}},discard:async e=>{await t.screenRecording.outputs.remove(e)}}}),cleanup:async()=>{let e=await Fr(c);return(e.status===`cleaned`||e.status===`already-missing`)&&t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId}),e}})}function Or(e){let{host:t,restored:{recording:n,nativePath:r,cleanup:i}}=e,a=Object.freeze({...n,backend:Cr,gestureEvents:[]});return ft(a,{finish:(e,i)=>_t({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 kr(t,r,e)},finalize:async({collectedPath:i,exportPath:a})=>await Jn({host:t,snapshot:e,targetLabel:Sr,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 kr(e,t,n){await e.screenRecording.outputs.copy({from:t,to:n}),await e.screenRecording.finalize.sniff({outputPath:n})}async function Ar(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??=jr(()=>t.screenRecording.apple.runRunner(n,{kind:`stop`,appBundleId:o,...c}).then(()=>void 0)).catch(e=>{throw l=void 0,e}),l);if(!Pr(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 Ir({device:n,owner:r,input:i,descriptor:{backend:`runner`,outputPath:i.outputPath,appBundleId:o,...c,...s.remotePath===void 0?{}:{remotePath:s.remotePath}},snapshot:Lr(i,`runner AVAssetWriter`,s),finish:async e=>(await u(),s.remotePath!==void 0&&await t.screenRecording.apple.retrieveRunnerRecording(n,s.remotePath,e.outPath),await qn({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 jr(e){try{return await e()}catch(e){throw i(e,`COMMAND_FAILED`)}}function Mr(e){if(e.exitCode!==0)return e.signal?`simctl recordVideo was killed by ${e.signal}`:`simctl recordVideo exited with code ${e.exitCode}`}function Nr(e,t,n){let a=i(e,`COMMAND_FAILED`);return t===void 0||n===void 0||a.details?.reason!==`recording-output-unplayable`?e:new r(a.code,`${a.message}; ${t}`,d(n,{...a.details??{},...n.signal===void 0?{}:{signal:n.signal},retriable:!1,hint:`The recorder exited before record stop, so the next record stop reads the same file. Close this session to release the device, then record again.`}))}function Pr(e,t){return e.appleOs===`macos`||!g(e)?t===void 0:t!==void 0&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(t)}async function P(e){return await e.terminate(),await e.wait}async function Fr(e){try{return await P(e),{status:`cleaned`}}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`Apple simulator cleanup failed`}}}function Ir(e){let{device:t,owner:n,input:r,descriptor:i,snapshot:a,finish:o,cleanup:s}=e,c=ft(a,{finish:o,forceCleanup:s});return Object.freeze({pendingHandle:new ve(c),envelope:Qn({device:t,owner:n,input:r,descriptor:i})})}function Lr(e,t,n={},r){let i=Date.now();return Object.freeze({backend:t,outPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutPath:e.clientOutputPath},startedAt:i,scope:e.scope,showTouches:e.showTouches,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},...e.exportQuality===void 0?{}:{exportQuality:e.exportQuality},...e.fps===void 0?{}:{fps:e.fps},gestureEvents:[],...r===void 0?{}:{gestureClockOriginAtMs:r.wallClockAtMs,gestureClockOriginUptimeMs:r.uptimeMs},...n.recorderStartUptimeMs===void 0?{}:{gestureClockOriginAtMs:i,gestureClockOriginUptimeMs:n.recorderStartUptimeMs,runnerStartedAtUptimeMs:n.recorderStartUptimeMs},...n.runnerSessionId===void 0?{}:{runnerSessionId:n.runnerSessionId}})}async function F(e,t,n,r={}){return n.throwIfAborted(),y(t)?{...t,booted:!0}:t.kind===`device`?(await e.deviceReadiness.applePhysical.ensureConnected(t,n),{...t,booted:!0}):t.kind===`simulator`?((await Rr(e,t)?`Booted`:await Wr(e,t,n))!==`Booted`&&(r.onColdBootStart?.(),e.deviceReadiness.appleAutomation.keepHot(t),await zr(e,t,n,r.deadlineAtMs),await Gr(e,n)),e.deviceReadiness.appleAutomation.keepHot(t),e.deviceReadiness.appleAutomation.markBooted(t),{...t,booted:!0}):{...t,booted:!0}}async function Rr(e,t){try{return await e.deviceReadiness.appleAutomation.wasRecentlyObservedBooted(t)}catch{return!1}}async function zr(e,t,n,r=Date.now()+12e4){let i=!1;try{i=await Br(e,t,n,r),await Vr(e,t,n,r)}catch(a){throw i&&n.aborted&&Kr(e,t),n.throwIfAborted(),Date.now()>=r?Ur(t,a):a}}async function Br(e,t,n,i){let a=await e.appleTools.run({tool:`simctl`,args:S(t,[`boot`,t.id]),allowFailure:!0,timeoutMs:Hr(i,t)},n),o=`${a.stdout}\n${a.stderr}`.toLowerCase(),s=o.includes(`already booted`)||o.includes(`current state: booted`);if(a.exitCode!==0&&!s)throw new r(`COMMAND_FAILED`,`simctl boot failed`,{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode});return!s}async function Vr(e,t,n,i){me({type:`command`,status:`progress`,message:`Waiting for the Simulator to finish booting...`});let a=await e.appleTools.run({tool:`simctl`,args:S(t,[`bootstatus`,t.id,`-b`]),allowFailure:!0,timeoutMs:Hr(i,t)},n);if(a.exitCode!==0)throw new r(`COMMAND_FAILED`,`simctl bootstatus failed`,{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode});if(n.throwIfAborted(),Date.now()>=i)throw Ur(t)}function Hr(e,t){let n=e-Date.now();if(n<=0)throw Ur(t);return n}function Ur(e,t){return new r(`COMMAND_FAILED`,`Simulator did not finish booting within the startup budget`,{reason:xt,deviceId:e.id,hint:`The Simulator keeps booting in the background; a first boot can take several minutes. Retry once it is up, or pass a larger --timeout.`},t instanceof Error?t:void 0)}async function Wr(e,t,n){return await Wt(e.appleTools,t,n,15e3)}async function Gr(e,t){await e.commands.run({executable:`open`,args:[`-g`,`-a`,`Simulator`],allowFailure:!0,timeoutMs:1e4},t)}function Kr(e,t){e.appleTools.run({tool:`simctl`,args:S(t,[`shutdown`,t.id]),allowFailure:!0}).catch(()=>{})}const qr=Object.freeze({resolveOpenTarget:`simulator`,prepareApplicationOpen:`simulator`,openApplication:`simulator`,applyRuntimeHints:`simulator`,clearRuntimeHints:`simulator`,closeApplication:`simulator`,finalizeApplicationClose:`simulator`,prepareAppleRunner:`runner`,configureProviderPortReverse:`simulator`,ensureReady:`simulator`,bootTarget:`simulator`,bootTargetHeadless:`simulator`,shutdownTarget:`simulator`,listApps:`simulator`,deployApp:`simulator`,materializeAppSource:`simulator`,deployMaterializedApp:`simulator`,sendPushNotification:`simulator`,uninstallApp:`simulator`,appState:`simulator`,appLogStart:`simulator`,appLogInspect:`simulator`,appLogDoctor:`simulator`,appLogReattach:`simulator`,appLogCleanup:`simulator`,networkDump:`simulator`,audioProbeStart:`simulator`,audioProbeQuery:`simulator`,audioProbeReattach:`simulator`,audioProbeCleanup:`simulator`,readClipboard:`simulator`,writeClipboard:`runner`,setSetting:`simulator`,readSetting:`simulator`,setFoldPose:`simulator`,sendTelephonyEvent:`simulator`,unlockOrientation:`simulator`,power:`simulator`,volumeDown:`simulator`,volumeUp:`simulator`,mute:`simulator`,sleep:`simulator`,wake:`simulator`,mediaPlayPause:`simulator`,mediaNext:`simulator`,mediaPrevious:`simulator`,mediaRewind:`simulator`,mediaFastForward:`simulator`,captureSnapshot:`simulator`,captureSnapshotWithoutActiveApp:`simulator`,captureSnapshotWithCustomActions:`runner`,captureScreenshot:`simulator`,findText:`runner`,querySelector:`runner`,readTextAtPoint:`runner`,tapPoint:`runner`,tapRef:`runner`,tapElementSelector:`runner`,fillPoint:`runner`,fillRef:`runner`,longPressPoint:`runner`,hoverPoint:`runner`,hoverRef:`runner`,focusPoint:`runner`,typeText:`runner`,scrollDirection:`runner`,performGesturePlan:`runner`,performMultiTouchGesturePlan:`runner`,performTargetAuthoredDrag:`runner`,performDirectionalFlingPlan:`runner`,gestureViewport:`runner`,setViewport:`runner`,back:`runner`,home:`runner`,setOrientation:`runner`,appSwitcher:`runner`,actionButton:`runner`,tvRemote:`runner`,keyboardDismiss:`runner`,keyboardEnter:`runner`,keyboardStatus:`runner`,triggerAppEvent:`runner`,readAlert:`runner`,awaitAlert:`runner`,acceptAlert:`runner`,dismissAlert:`runner`,perfFrames:`runner`,perfMemorySample:`runner`,perfMemorySnapshot:`runner`,perfNativeCaptureStart:`runner`,perfNativeCaptureReattach:`runner`,perfNativeCaptureCleanup:`runner`,perfProfileReport:`runner`,screenRecordingStart:`runner`,screenRecordingReattach:`runner`,screenRecordingCleanup:`runner`});function Jr(e){return e===void 0?`possible`:e.some(e=>qr[e]===`runner`)?`required`:`none`}function Yr(e){let{waitMs:t,signal:n,stop:r,cancelled:i}=e;return new Promise((e,a)=>{let o=()=>l(()=>a(i())),s=()=>l(e),c=setTimeout(()=>l(e),t);function l(e){clearTimeout(c),n?.removeEventListener(`abort`,o),r?.removeEventListener(`abort`,s),e()}n?.addEventListener(`abort`,o,{once:!0}),r?.addEventListener(`abort`,s,{once:!0}),n?.aborted?o():r?.aborted&&s()})}function Xr(e){let t=e.now??Date.now,n=e.waitGrant??`every-caller`,r=new Map,i=(n,i)=>{let a={status:`pending`,value:void 0,error:void 0,settledAtMs:t(),waitSpent:!1,controller:new AbortController,settled:void 0},o=()=>{};a.settled=new Promise(e=>{o=e}),r.set(n,a);let s=(i,s)=>{a.status=i,i===`ready`?a.value=s:a.error=s,a.settledAtMs=t(),(i===`ready`||e.retryAfterMs===void 0)&&r.get(n)===a&&r.delete(n),o()};try{i(a.controller.signal).then(e=>s(`ready`,e),e=>s(`failed`,e))}catch(e){s(`failed`,e)}return a},a=(n,a)=>{let o=r.get(n);if(!o)return i(n,a);if(o.status!==`failed`)return o;let s=t()-o.settledAtMs;return e.retryAfterMs===void 0||s>=e.retryAfterMs?i(n,a):o};return{value:async(t,r)=>{let i=a(t,r.start);if(i.status===`pending`&&(n===`every-caller`||!i.waitSpent)){i.waitSpent=!0;let t=new AbortController,n=r.wait(e.waitMs,t.signal);n.catch(()=>{});try{await Promise.race([i.settled,n])}finally{t.abort()}}if(i.status===`ready`)return i.value;throw i.status===`failed`?i.error:r.pending()},close:()=>{let e=[...r.values()];r.clear();for(let t of e)t.controller.abort()}}}async function Zr(e,t){let n=await At(`ps`,[`-p`,String(e),`-o`,`lstart=`],{allowFailure:!0,signal:t.signal,timeoutMs:t.timeoutMs});return n.exitCode===0&&n.stdout.trim()||null}const Qr=3e3,$r=`simulator-target-discovery-pending`,ei=`simulator-target-unavailable`;function ti(){let e=new Map,t=new Map,n=Xr({waitMs:1500});return async(r,i,a,o)=>{a.throwIfAborted();let s=`${r.id}:${i}`,c=e.get(s);if(c&&o!==`refresh`){let e=await Zr(c.pid,{signal:a,timeoutMs:Qr});if(a.throwIfAborted(),e===c.processStartTime)return c}return e.delete(s),await n.value(s,{start:async()=>{let n=await ai(r,i,t);return e.set(s,n),n},wait:(e,t)=>Yr({waitMs:e,signal:a,stop:t,cancelled:()=>ni(a)}),pending:()=>I($r,r,i)})}}function ni(e){return t({readinessPhase:`target-discovery`},e.reason)}function ri(e){return e instanceof r&&e.details?.reason===$r}function ii(e){return e instanceof r&&e.details?.reason===ei}async function ai(e,t,n){let r=Date.now()+15e3,[i,a]=await Promise.allSettled([It(e,[`spawn`,e.id,`launchctl`,`list`],{allowFailure:!0,timeoutMs:ci(r)}),oi(e,n,r)]);if(i.status===`rejected`)throw i.reason;if(a.status===`rejected`)throw a.reason;let o=i.value,s=a.value;if(o.exitCode!==0)throw I(`simulator-target-probe-failed`,e,t);let c=si(o.stdout,t);if(!c)throw I(ei,e,t);let l=await Zr(c.pid,{timeoutMs:Math.min(Qr,ci(r))});if(!l)throw I(`simulator-target-identity-unavailable`,e,t);return Object.freeze({simulator:Lt(e),runtime:s,pid:c.pid,generation:`${c.pid}:${c.label}:${l}`,targetId:`${e.id}:${t}`,processStartTime:l})}async function oi(e,t,n){let r=t.get(e.id);if(r)return await r;let i=It(e,[`list`,`devices`,`-j`],{allowFailure:!0,timeoutMs:ci(n)}).then(t=>{if(t.exitCode!==0)throw I(`simulator-runtime-probe-failed`,e,``);let n=Object.entries(Nt(t.stdout)).find(([,t])=>t.some(t=>t.udid===e.id))?.[0];if(!n)throw I(`simulator-runtime-unavailable`,e,``);return n});t.set(e.id,i);try{return await i}catch(n){throw t.delete(e.id),n}}function si(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 ci(e){return Math.max(1,e-Date.now())}function I(e,t,n){return new r(`COMMAND_FAILED`,`Unable to resolve the running iOS Simulator app (${e}).`,{reason:e,deviceId:t.id,appBundleId:n})}function li(e){return e?.observation===`unobservable`&&e.proof===`no-running-process`}const ui=new Map([[`application-element-missing`,5e3],[`application-server-unavailable`,5e3],[`foreground-owner-unverified`,1e3],[`foreground-owner-changed`,1e3]]);function L(e){return e.platform===`apple`&&ee(e)}function di(e){let t=ce(ue({depth:1,interactiveOnly:!0}));return Object.freeze({awaitObservable:async(n,r,i)=>{if(!L(n))return{observation:`not-eligible`};let a;for(;;){let o=await pi(e.resolveTarget,n,r,i);if(`verdict`in o)return o.verdict;let{target:s}=o;if(e.isBridgeDisabled(s))return m({level:`debug`,phase:`ios_launch_observation_skipped`,data:{reason:`circuit-disabled`,deviceId:n.id,generation:s.generation}}),fi({source:`circuit`});let c=await e.source.acquire({target:s,hint:t,signal:i});if(c.stage!==`failed`)return{observation:`observable`};i.throwIfAborted();let{kind:l,code:u}=c.failure,d=ui.get(u);if(d===void 0)return fi({source:`bridge`,kind:l,code:u});let f=e.clock.now();if(a=Math.min(a??1/0,f+d),f>=a)return{observation:`unobservable`,proof:`launch-transition`};await e.clock.sleep(Math.min(150,a-f),i)}}})}function fi(e){return{observation:`probe-failed`,failure:e}}async function pi(e,t,n,r){for(;;)try{return{target:await e(t,n,r)}}catch(e){if(r.throwIfAborted(),ri(e))continue;if(ii(e))return{verdict:{observation:`unobservable`,proof:`no-running-process`}};let{code:t,details:n}=a(e),i=n?.reason;return{verdict:fi(typeof i==`string`?{source:`target`,code:t,reason:i}:{source:`target`,code:t})}}}function mi(e,t,n){let r=n&&L(e),i=r?Jr(t.execution.plannedOperations):void 0,a=g(e)&&t.surface===`app`&&t.positionals.length>0&&!!t.appBundleId&&i!==`none`;return{...i?{runnerDemand:i}:{},shouldPrewarmRunner:a,awaitPrewarmAfterOpen:t.relaunch&&!r}}function hi(e,t,n,r){r.runnerDemand===`none`&&e.appleApplications.releaseSpeculativeRunner(t.device,n.execution).catch(()=>{})}async function gi(e,t,n,i,a,o){let s=Date.now(),c=async()=>await Ci(t,n,i,a.observation),l=await c(),u,d,f=a.answerConfirmation,p=f&&l?.observation!==`observable`?await _i(f,a.redispatchLaunchUrl,c,l):void 0;if(p&&(o.runnerDemand=`required`,u=p.report,d=p.probeFailure,l=p.observed,p.unanswered))throw new r(`COMMAND_FAILED`,`The Simulator has not completed the launch URL for ${n.appBundleId}.`,{reason:`launch_confirmation_unanswered`,appBundleId:n.appBundleId,hint:`iOS may still be holding an "Open in" prompt, or the answer died with the runner session that raised it. Inspect the current alert before deciding on another action.`});if(i&&l?.observation!==`observable`&&await e.clock.sleep(300,t.signal),l&&(o.postOpenObservation=l.observation,l.observation===`probe-failed`&&(o.postOpenObservationFailure=l.failure)),o.postOpenSettleDurationMs=Math.max(0,Date.now()-s),u)return u;if(d)return{launchConfirmationProbeFailure:d}}async function _i(e,t,n,r){let i={observed:r,acceptAttempted:!1,confirmationStillPresent:!1};for(let r=0;r<2;r+=1){i=await vi(e,n,i);let a=r===1;if(i.confirmationStillPresent||a||!xi(i)||!t)break;await t()}return{observed:i.observed,report:i.report,probeFailure:i.probeFailure,unanswered:xi(i)||i.confirmationStillPresent}}async function vi(e,t,n){let r=await e(),i=r.outcome===`unanswered`&&r.reason===`alert-still-present`,a=n.acceptAttempted||Si(r),o=bi(n,r);return a?{observed:await t(),...o,acceptAttempted:a,confirmationStillPresent:i}:{observed:n.observed,...o,acceptAttempted:a,confirmationStillPresent:i}}function yi(e){switch(e.outcome){case`accepted`:return{seen:{launchConfirmation:`accepted`}};case`absent`:return{};case`unreadable`:return e.step===`url-owner`?{seen:{launchConfirmation:`unanswered`,launchConfirmationReason:`url-owner-unresolved`}}:{probeFailure:e.step};case`unanswered`:return e.reason===`alert-still-present`?{}:{seen:{launchConfirmation:`unanswered`,launchConfirmationReason:e.reason}}}}function bi(e,t){let n=yi(t);return`seen`in n?{report:n.seen,probeFailure:void 0}:`probeFailure`in n?{report:void 0,probeFailure:n.probeFailure}:{report:e.report,probeFailure:void 0}}function xi(e){return e.acceptAttempted&&li(e.observed)}function Si(e){return e.outcome===`accepted`||e.outcome===`unanswered`&&e.reason===`alert-still-present`||e.outcome===`unreadable`&&e.step===`alert-accept`}async function Ci(e,t,n,r){if(!(!n||!L(e.device))&&!(!r||!t.appBundleId))return await r.awaitObservable(e.device,t.appBundleId,e.signal)}let wi;const Ti=()=>wi??=import(`./launch-confirmation.js`);let Ei;const Di=()=>Ei??=import(`./expo-dev-client-launch.js`);function Oi(e){let t=t=>Ze({device:t,signal:e.signal,resolveInteractor:e.host.localInteractors.resolve}),n=e.device,r=t(n),i=e=>{n=e,r=t(e)};return Object.freeze({resolveOpenTarget:async t=>await e.host.appleApplications.resolveOpenTarget(n,t),prepareApplicationOpen:async t=>{let r=await F(e.host,n,e.signal,{deadlineAtMs:t.execution.startupDeadlineAtMs,onColdBootStart:t.prewarmRunnerOnColdBoot?()=>{e.host.appleApplications.prewarmRunnerCache(n,t.execution,e.signal).catch(()=>{})}:void 0});i(r)},openApplication:async t=>await ki(e.host,r,t,e.observation),applyRuntimeHints:async t=>await e.host.appleApplications.applyRuntimeHints(n,t),clearRuntimeHints:async t=>await e.host.appleApplications.clearRuntimeHints(n,t),closeApplication:async t=>{t.ensureReady&&i(await F(e.host,n,e.signal)),await Hi(e.host,r,t)},finalizeApplicationClose:async t=>await Ui(e.host,n,e.signal,t),prepareAppleRunner:async t=>{let r=await Wi(e.host,n,e.signal,t);return i(r.readied),r.prepared},configureProviderPortReverse:Xi})}async function ki(e,t,n,r){let i={},a=R(t.device),o=Gi(e,t,n,i),s=mi(t.device,n,a);s.runnerDemand&&(i.runnerDemand=s.runnerDemand),hi(e,t,n,s);let{shouldPrewarmRunner:c}=s,l=Vi(t.device,n,a);a&&c&&!n.prewarmRunnerBeforeOpen&&o.schedule();try{await Ai(e,t,n,a,l,i);let u=await ji(t,n,a,i),d=qi(t.device,u?{...n,runtimeLaunchUrl:u}:n,a);await Mi(o,c,n.prewarmRunnerBeforeOpen);let f=o.wasAwaited();await Ni(t,n,d,a,i),await Ri(o,c,s.awaitPrewarmAfterOpen),await zi(e,t,n,a,f,l);let p=await gi(e,t,n,a,{observation:r,answerConfirmation:Ii(t,n,d),redispatchLaunchUrl:Li(t,n,d)},i);return{appBundleId:n.appBundleId,timing:i,...p??{}}}catch(n){throw l&&await e.appleApplications.stopRunnerSession(t.device.id).catch(()=>{}),n}}async function Ai(e,t,n,r,i,a){if(!Bi(n,r)||!n.target)return;let o=Date.now();ne(t.device.platform)&&!r&&!i&&await e.appleApplications.stopRunnerSession(t.device.id),await Qe({device:t.device,interactor:await t.resolveInteractor(n.execution,n.appBundleId),positionals:[n.appBundleId??n.target]}),r&&await e.clock.sleep(300,t.signal),a.relaunchCloseDurationMs=z(o)}async function ji(e,t,n,i){if(!ge(t.runtimeHints))return;let a=Date.now(),o=n?await(await Di()).resolveExpoDevClientLaunchUrl(e.device,t):void 0;if(!o){if(!t.applyRuntimeHints)throw new r(`COMMAND_FAILED`,`Runtime hint operation was not admitted for this open.`,{reason:`runtime-hints-operation-missing`});await t.applyRuntimeHints({appId:t.appBundleId,values:t.runtimeHints})}return i.runtimeHintsDurationMs=z(a),o}async function Mi(e,t,n){!t||!n||(e.schedule(!0),await e.wait())}async function Ni(e,t,n,r,i){let a=Date.now();await $e({device:e.device,interactor:await e.resolveInteractor(t.execution,t.appBundleId),positionals:n.positionals,appBundleId:t.appBundleId,execution:t.execution,...r&&t.relaunch&&!t.execution.clearAppState?{terminateRunningApp:!0}:{}}),i.openDispatchDurationMs=z(a),await Pi(e,t,n.followUpUrl,i)}async function Pi(e,t,n,r){if(!n){r.launchUrlDurationMs=0;return}let i=Date.now();await Fi(e,t,n),r.launchUrlDurationMs=z(i)}async function Fi(e,t,n){let r={...t.execution,clearAppState:void 0,launchConsole:void 0,launchArgs:void 0};await $e({device:e.device,interactor:await e.resolveInteractor(r,t.appBundleId),positionals:[n],appBundleId:t.appBundleId,execution:r})}function Ii(e,t,{confirmation:n}){if(n)return async()=>{let{answerSimulatorLaunchConfirmation:r}=await Ti();return await r(e.device,n,e.resolveInteractor(t.execution,n.appBundleId),e.signal,t.execution.requestDeadlineAtMs)}}function Li(e,t,{confirmation:n}){if(n)return async()=>{await Fi(e,t,n.url)}}async function Ri(e,t,n){t&&!e.wasScheduled()&&e.schedule(),n?await e.wait():e.recordUnawaited()}async function zi(e,t,n,r,i,a){!g(t.device)||!r&&!a||!n.relaunch&&!i||r&&!i&&!await e.appleApplications.hasLiveRunnerSession(t.device,n.execution)||await e.appleApplications.notifyRunnerAppRelaunched(t.device,n.execution,t.signal)}function Bi(e,t){return!!(e.relaunch&&e.target)&&!(t&&!e.execution.clearAppState)}function Vi(e,t,n){return e.kind===`device`&&e.appleOs===`ios`&&Bi(t,n)}async function Hi(e,t,n){ne(t.device.platform)&&!R(t.device)&&await e.appleApplications.stopRunnerSession(t.device.id),await Qe({device:t.device,interactor:await t.resolveInteractor(n.execution,n.appBundleId),positionals:n.positionals}),R(t.device)&&await e.clock.sleep(300,t.signal)}async function Ui(e,t,n,r){r.daemonShutdown||await e.appleApplications.releaseRunnerOnClose(t.id,{retain:r.retainRunner}),await e.appleApplications.dismissCloseAlerts(t,r).catch(()=>{});let i=r.shutdownTarget&&R(t)?await e.deviceShutdown.apple.shutdownTarget(t,n):void 0;return i===void 0?{}:{shutdown:i}}async function Wi(e,t,n,r){let i=Date.now()+r.timeoutMs,a=performance.now();return await f(`prepare_apple_runner`,async()=>{let o=await F(e,t,n,{deadlineAtMs:i}),s=Math.max(1,i-Date.now());return m({phase:`prepare_apple_runner`,durationMs:performance.now()-a,data:{event:`runner_start`,timeoutMs:r.timeoutMs,remainingMs:i-Date.now()}}),{readied:o,prepared:await e.appleApplications.prepareRunner(o,{...r,timeoutMs:s},n)}},()=>({timeoutMs:r.timeoutMs,remainingMs:i-Date.now()}),`readiness_start`)}function Gi(e,t,n,r){let i,a=!1,o=Ki(t.device,n)?{healthCheck:!1}:void 0;return{schedule:(a=!1)=>{i||=(r.runnerPrewarmKind=`session`,r.runnerPrewarmScheduled=!0,o?e.appleApplications.prewarmRunnerSession(t.device,n.execution,t.signal,a,o):e.appleApplications.prewarmRunnerSession(t.device,n.execution,t.signal,a))},wait:async()=>{if(!i||a)return;a=!0;let e=Date.now();await i,r.runnerPrewarmWaited=!0,r.runnerPrewarmDurationMs=z(e)},wasAwaited:()=>a,wasScheduled:()=>i!==void 0,recordUnawaited:()=>{i&&!a&&(r.runnerPrewarmWaited=!1)}}}function Ki(e,t){return e.kind===`device`&&e.appleOs===`ios`&&!t.hasExistingSession&&!t.relaunch&&!t.prewarmRunnerBeforeOpen}function qi(e,t,n){let r=t.runtimeLaunchUrl?.trim(),i=t.positionals.length===1?t.positionals[0]?.trim():void 0;if(!r||!i||l(i))return{positionals:t.positionals};let a=Ji(e,t.appBundleId,r),o=a?{confirmation:a}:{};return n&&!Yi(t)?{positionals:[i,r],...o}:{positionals:t.positionals,followUpUrl:r,...o}}function Ji(e,t,n){if(e.appleOs===`ios`&&e.kind===`simulator`&&!(t===void 0||s(n)))return{url:n,appBundleId:t}}function Yi(e){return e.execution.clearAppState===!0||!!e.execution.launchConsole?.trim()||!!e.execution.launchArgs?.length}function R(e){return g(e)&&e.kind===`simulator`}function z(e){return Math.max(0,Date.now()-e)}async function Xi(){throw new r(`UNSUPPORTED_OPERATION`,`This lifecycle operation is unavailable for Apple.`)}const Zi=Object.freeze({available:!0}),Qi=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.`}),$i=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Push notifications are supported on Apple simulators only.`}),ea=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),ta=Object.freeze({available:!1,reason:`unsupported-device-kind`});function na(e){let t=ua(e);return Object.freeze({deployApp:t,materializeAppSource:t,deployMaterializedApp:t,sendPushNotification:da(e),uninstallApp:t})}function ra(e){let{host:t,device:n,signal:r}=e,i=na(n);return Object.freeze({...i.deployApp.available?{deployApp:async e=>await ia(t,n,e,r),materializeAppSource:async e=>await t.appleDeployment.prepareArtifact(e,{signal:r}),deployMaterializedApp:async e=>await oa(t,n,e,r),uninstallApp:async e=>await aa(t,n,e,r)}:{},...i.sendPushNotification.available?{sendPushNotification:async e=>(await la(t,n,e,r),{})}:{}})}async function ia(e,t,n,r){if(n.replaceExisting)return await e.appleDeployment.withInvalidatedAppResolutionCache(t,async()=>{let i=await e.appleDeployment.resolveAppBundleId(t,n.app);await ca(e,t,i,r);let a=await e.appleDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{appIdentifierHint:n.app,signal:r});try{return await sa(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 oa(e,t,{artifact:i},r)}finally{await i.cleanup()}}async function aa(e,t,n,i){return await e.appleDeployment.withInvalidatedAppResolutionCache(t,async()=>{await F(e,t,i);let a;try{a=await e.appleDeployment.resolveAppBundleId(t,n.app,{installedOnly:!0})}catch(e){if(e instanceof r&&e.code===`APP_NOT_INSTALLED`&&n.app.trim().includes(`.`))return{wasInstalled:!1};throw e}return await ca(e,t,a,i),{wasInstalled:!0,bundleId:a}})}async function oa(e,t,n,r){return await sa(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 sa(e,t,n,r){await F(e,t,r),await B(e,t.kind===`simulator`?{tool:`simctl`,args:S(t,[`install`,t.id,n])}:{tool:`devicectl`,args:[`device`,`install`,`app`,`--device`,t.id,n],timeoutMs:kt},r,`Apple app install failed`)}async function ca(e,t,n,r){await F(e,t,r),await B(e,t.kind===`simulator`?{tool:`simctl`,args:S(t,[`uninstall`,t.id,n])}:{tool:`devicectl`,args:[`device`,`uninstall`,`app`,`--device`,t.id,n]},r,`Apple app uninstall failed for ${n}`,{tolerate:e=>Mt(`${e.stdout}\n${e.stderr}`.toLowerCase())})}async function la(e,t,n,i){if(t.kind!==`simulator`)throw new r(`UNSUPPORTED_OPERATION`,`Apple push notifications require a simulator`);await F(e,t,i);let a=await e.temporaryFiles.create({prefix:`agent-device-ios-push-`,suffix:`.apns`});try{await a.writeText(`${JSON.stringify(n.payload)}\n`),await B(e,{tool:`simctl`,args:S(t,[`push`,t.id,n.appId,a.path])},i,`Apple push notification failed`)}finally{await a[Symbol.asyncDispose]()}}async function B(e,t,n,r,i){let a=await e.appleTools.run({...t,allowFailure:!0},n);return i?.tolerate?.(a)?a:p(a,r,e=>({cmd:`xcrun`,args:[t.tool,...t.args],...t.tool===`devicectl`?{hint:jt(e.stdout,e.stderr)??`Ensure the iOS device is unlocked, trusted, and available in Xcode > Devices, then retry.`}:{}}))}function ua(e){return fa(e)?e.kind!==`simulator`&&e.kind!==`device`?ta:e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?Qi:Zi:ea}function da(e){return fa(e)?e.kind===`simulator`?Zi:$i:ea}function fa(e){return g(e)&&e.appleOs!==`watchos`}const V=Object.freeze({available:!0}),pa=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`back is supported on Apple simulators and physical devices.`}),ma=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function ha(e){return e.kind!==`simulator`&&e.kind!==`device`?pa:v(e)===`watchos`?ma:V}const ga=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`home is supported on Apple simulators and physical devices.`}),_a=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),va=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`app-switcher is supported on Apple simulators and physical devices.`});function ya(e,t){if(e.kind!==`simulator`&&e.kind!==`device`)return t;let n=v(e);return n===`macos`||n===`watchos`?_a:V}function H(e){if(e.kind!==`simulator`&&e.kind!==`device`)return!1;let t=v(e);return t!==`tvos`&&t!==`macos`&&t!==`watchos`}const ba=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`orientation is supported on Apple simulators and physical devices.`}),xa=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function Sa(e){return e.kind!==`simulator`&&e.kind!==`device`?ba:H(e)?V:xa}const Ca=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`tv-remote is supported only on tvOS devices.`});function wa(e){return(e.kind===`simulator`||e.kind===`device`)&&h(e)?V:Ca}const U=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Ta=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 Ea(e){return H(e)?Ta:U}function Da(e){return H(e)?V:U}function Oa(e){return H(e)?V:U}const ka=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`No Apple leaf carries this system button.`}),Aa=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`action-button is supported on iPhone and iPad simulators and physical devices.`}),ja=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 Ma(e){return e.kind!==`simulator`&&e.kind!==`device`?Aa:te(e)?V:ja}const Na=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`hardware-button volume presses the iPhone/iPad volume key; this Apple leaf has none.`}),Pa=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`hardware-button volume is supported on physical iPhone and iPad; iOS Simulators refuse because XCUIDevice exposes no volume press there.`});function Fa(e){return te(e)?e.kind===`device`?V:Pa:Na}function Ia(e){return Object.freeze({...Te({back:ha(e)}),...Ve({unsupported:ka,home:ya(e,ga),appSwitcher:ya(e,va),actionButton:Ma(e),volumeUp:Fa(e),volumeDown:Fa(e)}),...Ge({orientation:Sa(e)}),...Je({tvRemote:wa(e),buttonSupport:{supported:o(`apple`),unsupported:{available:!1,reason:`unsupported-platform-leaf`,hint:`This TV remote button is not supported on tvOS.`}}}),...We({unsupported:U,status:Ea(e),dismiss:Da(e),enter:Oa(e)})})}function La(e){let{host:t,device:n,signal:r,admitted:i}=e,a=Object.keys(Ia(n));return tt({device:n,signal:r,resolveInteractor:t.localInteractors.resolve,facts:Object.fromEntries(a.map(e=>[e,i[e]]))})}const W=Object.freeze({available:!0}),Ra=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`clipboard is supported on Apple simulators and the macOS host.`}),za=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`settings is supported on Apple simulators and the macOS host.`}),Ba=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.`}),Va=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:"Run `agent-device settings --help` for the settings each target serves."}),Ha=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`The macOS host supports settings appearance and settings permission <grant|reset> <accessibility|screen-recording|input-monitoring>.`}),Ua=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Select a booted iPhone or iPad simulator: this setting runs only there.`}),Wa=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.`}),Ga=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function Ka(e,t,n){if(e.kind!==`simulator`&&e.kind!==`device`)return t;let r=v(e);return r===`watchos`?Ga:e.kind===`simulator`||r===`macos`?W:n}const qa=Object.freeze({available:!1,reason:`unsupported-device-scope`,hint:`This session holds one app of the Mac. Use a --surface desktop session for the clipboard and host settings.`});function Ja(e){return e.hostApp?qa:Ka(e,Ra,Wa)}const Ya=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`trigger-app-event is supported on Apple simulators and physical devices.`}),Xa=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`alert is supported on Apple simulators and physical devices.`}),Za=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`alert is supported on Apple simulators, the macOS host, and physical iOS devices.`});function Qa(e){if(e.kind!==`simulator`&&e.kind!==`device`)return Xa;let t=v(e);return t===`watchos`?Ga:e.kind===`simulator`||t===`ios`||t===`macos`?W:Za}function $a(e){return e.kind!==`simulator`&&e.kind!==`device`?Ya:v(e)===`watchos`?Ga:W}function eo(e){let t=Ja(e);return t.available?Wa:t}function to(e){let t=e.hostApp?qa:Ka(e,za,Ba);if(y(e))return et({target:t,unsupported:Ha,write:{appearance:W,permission:W}});let n=ee(e)?W:Ua;return et({target:t,unsupported:Va,write:{wifi:W,airplane:W,location:W,appearance:W,"clear-app-state":W,"reset-keychain":W,permission:W,"text-size":n,faceid:n,touchid:n},read:{"text-size":n}})}function no(e){let t=Ja(e),n=Qa(e);return Object.freeze({...Ke({unsupported:eo(e),read:t,write:t}),...Xe({read:n,wait:n,accept:n,dismiss:n}),...Ye({triggerAppEvent:$a(e)}),...to(e)})}function ro(e){let{host:t,device:n,signal:r}=e;return tt({device:n,signal:r,resolveInteractor:t.localInteractors.resolve,facts:no(n)})}function io(e,t,n){let r=Ue({device:t.device,signal:t.signal,resolveInteractor:e.localInteractors.resolve}),i=async i=>{if(i.options?.observeOnly===!0)return await r.captureSnapshot(i);let a=y(t.device)?se(i.options?.surface,t.appBackend):void 0;if(a)return await e.snapshot.captureSurface(t.device,{...i.options,surface:a},He(t.signal,i));if(!n)return await r.captureSnapshot(i);let o=He(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 ao(e,t){return Object.freeze({findText:async n=>{let r=await oo(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 oo(e,t,n){let r=n.options?.appBundleId;if(r===void 0||y(t.device)&&oe(n.options?.surface,t.appBackend)===`macos-helper`)return;let i=n.signal?AbortSignal.any([t.signal,n.signal]):t.signal;if(i.throwIfAborted(),await so(e,t.device,n.execution))return{appBundleId:r,signal:i}}async function so(e,t,n){return!L(t)||await e.appleApplications.hasLiveRunnerSession(t,n??{})}function co(e){return Object.freeze({querySelector:async t=>{let n=t.signal?AbortSignal.any([e.signal,t.signal]):e.signal;n.throwIfAborted();let r={...t.execution,signal:n},{queryAppleRunnerSelector:i}=await import(`./runner-selector-query.js`),a=await i(e.device,t.selector,t.options?.appBundleId,r),o=lo(a);return Object.freeze({found:a.found===!0,...o?{node:o}:{}})}})}function lo(e){let t=e.nodes;if(!Array.isArray(t))return;let n=t[0];if(!n||typeof n!=`object`)return;let r=c(n.rect);if(r)return Object.freeze({rect:r,hittable:n.hittable===!0})}const G=Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`The native macOS app backend never starts the XCTest runner, which this command needs. Unset AGENT_DEVICE_MACOS_APP_BACKEND to use XCTest.`});function uo(e,t){return!y(e)||t!==`native`?{}:Object.freeze({screenRecordingStart:G,screenRecordingReattach:G,prepareAppleRunner:G,longPressPoint:G,...Te({back:G}),...Oe({unsupported:G})})}function fo(e){let t,n=!1,r=async()=>(t??=import(`./host4.js`).then(e=>e.t).then(({createSnapshotSourceHost:t})=>import(`./adapter.js`).then(({createSimulatorSnapshotSource:n})=>n({host:t(e)}))),await t);return{acquire:async e=>n?{stage:`failed`,failure:{kind:`unsupported`,code:`source-closed`}}:await(await r()).acquire(e),close:async()=>{n=!0,t&&await(await t).close()}}}const po=new Set([`notRunning`,`runningBackground`,`runningBackgroundSuspended`]);function mo(){return async(e,t)=>{let n=zt(e.id);if(!n||n.liveness!==`ready`)return`unknown`;for(let r of Se){let i=await ho(e,r.bundleId,n.sessionId,t);if(i===`runningForeground`)return{kind:`foreground`,host:r};if(i===void 0||!po.has(i))return`unknown`}return`background`}}async function ho(t,n,r,i){try{let a=(await Rt(t,{command:`appState`,appBundleId:n},{signal:AbortSignal.any([i.signal,AbortSignal.timeout(1e3)]),expectedRunnerSessionId:r,...i.requestId?{requestId:i.requestId}:{}})).applicationState;return e(a)?a:void 0}catch{i.signal.throwIfAborted();return}}function go(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 _o(n,r);return a!==`absent`&&a!==`unknown`&&t.set(n.id,{at:e(),host:a.host}),a}}async function _o(e,t){let n=await Promise.all(Se.map(async e=>({host:e,pids:await vo(e.processExecutable,t)}))),r=!1;for(let{host:i,pids:a}of n){if(a===`unknown`){r=!0;continue}for(let n of a){let a=await yo(n,e.id,t);if(a===`unknown`)r=!0;else if(a)return{kind:`present`,host:i}}}return r?`unknown`:`absent`}async function vo(e,t){let n=await bo(`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 yo(e,t,n){let r=await bo(`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 bo(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 xo=new Map([[`window-coordinate-space-unresolved`,`coordinate-space-unresolved`],[`app-window-not-full-screen`,`window-not-full-screen`],[`foreground-owner-unverified`,`foreground-ownership`],[`foreground-owner-changed`,`foreground-ownership`]]);function So(e){if(e.kind===`preparing`)return{scope:`capture`,code:e.code,consequence:`bridge-preparation`};let t=xo.get(e.code);return t?{scope:`capture`,code:e.code,consequence:t}:{scope:`generation`,code:e.code}}const Co=`system-surface-presented`,wo=`system-surface-host-lingering`;function To(e,t={}){let n=t.source??fo(e.hostEnvironment),i=t.resolveTarget??ti(),a=t.systemSurfacePresent??go(),o=t.systemSurfaceForeground??mo(),s=new Set,c=new Map,l=e=>(Vo(e,c,s),s.has(Ho(e))),u=di({source:n,resolveTarget:i,clock:e.clock,isBridgeDisabled:l});return Object.freeze({awaitObservable:u.awaitObservable,shutdown:async()=>await n.close(),capture:async(t,c,u,d)=>{if(!ko(t,c))return await Mo(t,c,d);let p=await Eo(t,c,u,o);if(p!==`background`&&p!==`unknown`)return await jo(t,c,d,p.host.bundleId);let m=p===`background`?`absent`:await a(t,u);if(m===`unknown`)return await K(t.id,c,d,Po(t.id,c),q(c),`system-surface-probe-unavailable`,[Bo()]);if(m!==`absent`)return await jo(t,c,d,m.host.bundleId);let h;try{h=await Do(e,i,t,c,u)}catch(e){return Oo(u,e),J(`target-resolution-failed`,t,void 0,e),await K(t.id,c,d,Po(t.id,c),q(c),`target-resolution-failed`,[Bo()])}if(l(h))return J(`circuit-disabled`,t,h.generation),await K(t.id,c,d,h,q(c),`circuit-disabled`);let g=q(c),_=await n.acquire({target:h,hint:ce(g),signal:u});if(_.stage===`failed`){if(_.failure.kind===`cancelled`)throw u.throwIfAborted(),new r(`COMMAND_FAILED`,`Simulator AX snapshot acquisition was cancelled.`,{reason:_.failure.code,..._.failure.details});let e=await zo(_.failure,h,t,c.options.appBundleId,u,i);return await Ao(c,d,h,e,g,_.failure,s)}try{return await f(`ios.snapshot-source.present`,async()=>await e.snapshot.presentIosAcquisition(_,c.options),{producer:`simulator-ax-bridge`})}catch(e){return await Ao(c,d,h,{lineage:h,residue:[]},g,{kind:`malformed-tree`,code:`presentation-invariant`},s,e)}}})}async function Eo(e,t,n,r){let i=t.execution?.requestId,a=await r(e,{signal:n,...i?{requestId:i}:{}});return a===`background`&&m({level:`debug`,phase:`ios_snapshot_route_surface_host_background`,data:{deviceId:e.id}}),a}async function Do(e,t,n,r,i){let a=r.options.appBundleId;for(;;)try{return await t(n,a,i)}catch(t){if(!ri(t))throw t;let i={requestId:r.execution?.requestId};if(await e.appleApplications.hasLiveRunnerSession(n,i))throw t}}function Oo(e,t){if(e.aborted)throw n(t)?t:e.reason}function ko(e,t){return L(e)&&!!t.options?.appBundleId&&t.options?.customActions!==!0&&t.options?.preferredBackend===void 0}async function Ao(e,t,n,r,i,a,o,s){let c=So(a);return c.scope===`generation`&&o.add(Ho(n)),J(a.code,{id:n.simulator.udid},n.generation,s,a.details),await K(n.simulator.udid,e,t,r.lineage,i,c,r.residue)}async function K(e,t,n,r,i,a,o=[]){return No(e,await n(t),r,i,a,o)}async function jo(e,t,n,r){let i=await n(t),a=i.systemSurface?Co:wo;return i.systemSurface||J(a,e,void 0,void 0,{detectedHost:r}),No(e.id,i,Po(e.id,t),q(t),a)}async function Mo(e,t,n){let r=await n(t),i=r.systemSurface;return i?{...r,comparisonIdentity:Io(Fo(e.id,i.bundleId),q(t),[])}:r}function No(e,t,n,r,i,a=[]){let o=t.systemSurface;return{...t,comparisonIdentity:Io(o?Fo(e,o.bundleId):n,r,[...o?[]:a,{kind:`fallback-source`,producer:`apple-runner`}]),warnings:[...t.warnings??[],Lo(i,n,o!==void 0)]}}function Po(e,t){return{targetId:`${e}:${t.options.appBundleId}`}}function Fo(e,t){return{targetId:`${e}:${t}`}}function Io(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:le(t),residue:Object.freeze([...n])})}function Lo(e,t,n){if(e===Co)return`Simulator AX snapshot inapplicable (${e}); used XCTest to read the system surface presented over the app.`;if(e===wo)return`Simulator AX snapshot inapplicable (${e}); used XCTest, which read app content: the system surface host process was still running but no longer presenting.`;let r=typeof e==`string`?e:e.code;return n?`Simulator AX snapshot unavailable (${r}); used XCTest, which read the system surface presented over the app.`:typeof e!=`string`&&e.scope===`capture`?Ro(r,e.consequence):`Simulator AX snapshot unavailable (${r}); used XCTest for ${t.generation?`this app generation`:`an unverified app generation`}.`}function Ro(e,t){let n=`Simulator AX snapshot unavailable (${e}); used XCTest for this capture`;switch(t){case`bridge-preparation`:return`${n} while the bridge is still being prepared.`;case`foreground-ownership`:return`${n}, while another surface owned the foreground.`;case`window-not-full-screen`:return`${n}, while the app window did not fill the screen; the runner republishes a windowed capture in screen space.`;case`coordinate-space-unresolved`:return`${n}, which reports captured geometry in the app's own orientation space.`}}async function zo(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:[Bo()]}}}function Bo(){return{kind:`unknown-generation`,captureId:Gt()}}function q(e){return ue({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 Vo(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 Ho(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=re(`apple`),X=Object.freeze({available:!0}),Z=x(`unsupported-platform-leaf`),Uo=x(`unsupported-platform-leaf`,`viewport resizes web targets only (--platform web). Apple screen geometry is fixed by the selected simulator or device type — open a different simulator to test another screen size.`),Wo=x(`unsupported-platform-leaf`,`the stateless audio page probe is a web-session operation; Apple targets use the host capture.`),Go=x(`unsupported-device-backend`,`perf requires an Apple simulator, macOS device, or CoreDevice-backed physical Apple device.`),Ko=x(`unsupported-device-kind`,`focus is supported on Apple simulators and physical devices.`),qo=x(`unsupported-platform-leaf`,`telephony simulates calls and SMS through the Android emulator console; Apple simulators and devices expose no host control that injects a call or text message.`),Jo=x(`unsupported-platform-leaf`,`Apple appstate is unavailable here: the runner reads the session app's XCUIApplication state on iOS-family simulators and physical devices only, and the Apple target answers no sessionless foreground probe. The per-command answer is the targetActivation disclosure, which a capture carries when its command had to re-activate the session app (#2682).`);function Yo(e){return!g(e)||e.appleOs===`watchos`?Jo:e.kind===`simulator`||e.kind===`device`?X:Jo}const Xo=x(`unsupported-provider-mode`,`Headless boot is supported only for local Android emulators.`),Zo=x(`unsupported-platform-leaf`,`watchOS has no XCUITest-driveable UI, so element text comes from the captured tree only.`),Qo=x(`unsupported-device-kind`),$o=x(`unsupported-platform-leaf`,`watchOS open is not supported because XCUITest cannot drive watchOS UI.`),es=x(`unsupported-platform-leaf`,`watchOS runner preparation is not supported because XCUITest cannot drive watchOS UI.`),ts=x(`unsupported-platform-leaf`,`watchOS close is not supported because XCUITest cannot drive watchOS UI.`),ns=x(`unsupported-device-kind`,`Runtime hints are supported only for local iOS-family simulators and Android devices.`),rs=Q(`open is supported only for Apple simulators and devices.`),is=Q(`prepare is supported only for Apple simulators and devices.`),as=Q(`close is supported only for Apple simulators and devices.`),os=x(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),ss=x(`unsupported-device-kind`,`shutdown is supported only for Apple simulators and Android emulators.`),cs=Q(`snapshot is supported only for Apple simulators and devices.`),ls=x(`unsupported-platform-leaf`,`Re-run without --actions, or target an iOS simulator.`),us=x(`unsupported-platform-leaf`,`screenshot is not supported on watchOS because XCUITest cannot drive watchOS UI.`),ds=Q(`screenshot is supported only for Apple simulators and devices.`),fs=x(`owner-capability-missing`,`Open the app under test before capturing its snapshot.`);function Q(e){return x(`unsupported-device-kind`,e)}function ps(e){return!g(e)||e.appleOs===`watchos`?Z:e.kind===`simulator`?X:ss}function ms(e){let t=hs(e),n=gs(e),r=_s(e),i=vs(e);return _e({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:i,clearRuntimeHints:i,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:n,configureProviderPortReverse:os})}function hs(e){return v(e)===`watchos`?$o:e.kind===`simulator`||e.kind===`device`?X:rs}function gs(e){return v(e)===`watchos`?es:e.kind===`simulator`||e.kind===`device`?X:is}function _s(e){return v(e)===`watchos`?ts:e.kind===`simulator`||e.kind===`device`?X:as}function vs(e){return v(e)!==`watchos`&&g(e)&&e.kind===`simulator`?X:ns}function ys(e){return e.appleOs===`watchos`?x(`unsupported-platform-leaf`,`watchOS app inventory is not supported.`):e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?x(`unsupported-device-backend`,`App inventory is available only on CoreDevice-backed physical iOS devices.`):X}function $(e){return e.kind===`simulator`||e.kind===`device`?X:Ko}function bs(e){let t=Fn(e),n=To(e),r,i=t=>y(t)?r??=Ut(e.hostEnvironment.env):`xctest`,a=async n=>{let r=await t.inspectFacts(n),a=na(n),o=wr(n),s=o.available?await e.screenRecording.apple.availability(n):void 0,c=o.available&&s?.available===!1?x(`unsupported-provider-mode`,s.hint):o,l=n.appleOs===`watchos`?Z:X,u=y(n)||n.appleOs===`watchos`?Z:X,d=ys(n);return Object.freeze({device:r.device,operations:{...r.operations,...a,appState:Yo(n),networkDump:X,screenRecordingStart:c,screenRecordingReattach:c,screenRecordingCleanup:c,...Ts(n),...De({capture:ws(n)}),...Ae({findText:Cs(n),querySelector:g(n)?$(n):Z}),...Pe({setViewport:Uo}),...ze({focus:$(n)}),...en(n),...je({type:$(n)}),...be({unsupported:Z,tap:$(n),longPress:$(n),fill:$(n),...g(n)?{tapElementSelector:$(n)}:{}}),...Be({readTextAtPoint:Ss(n)}),...Ia(n),...Vt(n),sendTelephonyEvent:qo,...no(n),...we({capture:Jt(n),query:Wo}),...Ne(xs(n)),ensureReady:l,bootTarget:u,bootTargetHeadless:Xo,listApps:d,...ms(n),shutdownTarget:ps(n),...uo(n,i(n))}})};return Object.freeze({owner:Y,ownsDevice:e=>e.platform===`apple`,inspectFacts:a,bind:async r=>{let o=await t.bind(r),s=await a(r.device),c=s.operations.screenRecordingStart,l=b(s.operations.appState,()=>qt(e,{device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),u=b(s.operations.querySelector,()=>co({device:r.device,signal:r.scope.signal})),d={...l,...u,...o.operations,...ra({host:e,device:r.device,signal:r.scope.signal}),networkDump:async t=>await zn(e,r.device,t,r.scope.signal),...b(c,()=>Tr({host:e,device:r.device,owner:Y,signal:r.scope.signal})),...b(s.operations.audioProbeStart,()=>lt({host:e.audioProbe.hostCapture,device:r.device,owner:Y})),...b(s.operations.perfFrames,()=>Yt({resolveHost:()=>e.perf.apple,device:r.device,owner:Y})),...b(s.operations.captureSnapshot,()=>io(e,{device:r.device,signal:r.scope.signal,appBackend:i(r.device)},n)),...b(s.operations.captureScreenshot,()=>Me({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...b(s.operations.focusPoint,()=>qe({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...Le({device:r.device,signal:r.scope.signal,facts:s.operations,resolveInteractor:e.localInteractors.resolve}),...b(s.operations.scrollDirection,()=>Ie({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...b(s.operations.typeText,()=>Ee({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...b(s.operations.tapPoint,()=>xe({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:s.operations,pause:async t=>await e.clock.sleep(t,r.scope.signal)})),...b(s.operations.readTextAtPoint,()=>Re({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...b(s.operations.findText,()=>ao(e,{device:r.device,signal:r.scope.signal,appBackend:i(r.device)})),...La({host:e,device:r.device,signal:r.scope.signal,admitted:s.operations}),...ro({host:e,device:r.device,signal:r.scope.signal}),...Ht({device:r.device,signal:r.scope.signal}),...b(s.operations.ensureReady,()=>({ensureReady:async()=>await F(e,r.device,r.scope.signal)})),...b(s.operations.bootTarget,()=>({bootTarget:async t=>await F(e,r.device,r.scope.signal,{deadlineAtMs:t.deadlineAtMs})})),...b(s.operations.listApps,()=>({listApps:async e=>{r.scope.signal.throwIfAborted();let{listIosApps:t}=await import(`./app-resolution.js`).then(e=>e.t);return(await t(e.device,e.filter)).map(e=>({id:e.bundleId,name:e.name}))}})),...he(Oi({host:e,device:r.device,signal:r.scope.signal,observation:n}),s.operations),...b(s.operations.shutdownTarget,()=>({shutdownTarget:async()=>await e.deviceShutdown.apple.shutdownTarget(r.device,r.scope.signal)}))};return Object.freeze({device:o.device,owner:Y,facts:s,operations:Object.freeze(d),[Symbol.asyncDispose]:async()=>await o[Symbol.asyncDispose]()})},shutdown:async()=>{await Promise.all([t.shutdown(),n.shutdown()])}})}function xs(e){let t=e.iosPhysicalDeviceBackend!==`xctest`&&v(e)!==`watchos`?X:Go;return{frames:t,memorySample:t,memorySnapshot:t,nativeCapture:t,profileReport:t}}function Ss(e){return v(e)===`watchos`?Zo:e.kind===`simulator`||e.kind===`device`?X:Qo}function Cs(e){return v(e)===`watchos`?cs:e.kind===`simulator`||e.kind===`device`?X:cs}function ws(e){return v(e)===`watchos`?us:e.kind===`simulator`||e.kind===`device`?X:ds}function Ts(e){let t=Cs(e);return ke({capture:t,customActions:t.available&&g(e)&&e.kind===`simulator`?X:ls,withoutActiveApp:g(e)?fs:t})}export{bs as createApplePlatformRuntime,Xr as n,Yr as r,Zr as t};
3
+ `)}\n`,{...n,path:`${r} (simctl log show recovery)`,exists:!0,backend:`ios-simulator`}),lineCount:c.length}}function Vn(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 Hn(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 Un(e,t,n){n.appLogSnapshot?n.appLogSnapshot.state!==`active`&&e.length===0&&e.push(y(t)&&t.kind===`simulator`?`Session app log stream is inactive. The iOS simulator recovery path scanned recent simctl log history, but a fresh logs clear --restart window is still the most reliable repro loop.`:`Session app log stream is inactive. Run logs clear --restart, reproduce the request window again, then rerun network dump.`):e.push(`Capture uses the session app log file. For fresh traffic, run logs clear --restart before reproducing requests.`)}function Wn(e){return y(e)&&e.kind===`simulator`?`No HTTP(s) entries were found in recent iOS simulator app logs. If the app only emits non-HTTP diagnostics, inspect logs path or add app-side URLSession/network logging for per-request timing and payload details.`:y(e)?`No HTTP(s) entries were found in recent iOS device app logs. iOS network dump only sees what the app emits into Unified Logging for this process.`:`No HTTP(s) entries were found in recent session app logs.`}async function Gn(e){let{host:t,snapshot:n,targetLabel:r,recorderWarning:a,nativePathDisposition:o}=e,s=n.invalidatedReason?{recorder:`lost`,why:`owner-session-lost`}:e.stopObservation;if(n.invalidatedReason&&!n.showTouches)throw Error(`recording invalidated: ${n.invalidatedReason}`);let c;try{c=await t.screenRecording.finalize.complete({outputPath:n.outPath,showTouches:!n.invalidatedReason&&n.showTouches,gestureEvents:n.gestureEvents,exportQuality:n.exportQuality??`medium`,...n.fps===void 0?{}:{fps:n.fps},targetLabel:r})}catch(e){throw i(e,`COMMAND_FAILED`)}let l=[...c.warning?[c.warning]:[],...a?[a]:[]];return pt(n,{...c,...l.length>0?{warning:l.join(` `)}:{},...n.invalidatedReason?{overlayWarning:`overlay unavailable: ${n.invalidatedReason}`}:{}},{stopObservation:s,...o===void 0?{}:{nativePathDisposition:o}})}async function Kn(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 qn(()=>t.screenRecording.finalize.complete({outputPath:a,showTouches:s===void 0&&n.showTouches,gestureEvents:n.gestureEvents,exportQuality:n.exportQuality??`medium`,...n.fps===void 0?{}:{fps:n.fps},targetLabel:r}))}catch(e){throw await t.screenRecording.outputs.remove(a),e}return{...c,...s===void 0?{}:{overlayWarning:`overlay unavailable: ${s}`},nativePathDisposition:await t.screenRecording.outputs.remove(o)===`removed`?`retired`:`retirable`}}async function qn(e){try{return await e()}catch(e){throw i(e,`COMMAND_FAILED`)}}const Jn=[`outPath`,`startedAt`,`clientOutPath`,...gt],Yn=Object.freeze({resourceKind:pe,version:1,encode:e=>e.backend===`simctl`?{backend:e.backend,outputPath:e.outputPath,processes:e.processes.map(e=>({...e})),...e.recording===void 0?{}:{recording:{...e.recording}}}:{backend:e.backend,outputPath:e.outputPath,appBundleId:e.appBundleId,runnerSessionId:e.runnerSessionId,runnerAuthority:e.runnerAuthority,...e.remotePath===void 0?{}:{remotePath:e.remotePath}},decode:e=>sr(e)});function Xn(e){let{device:t,owner:n,input:r,descriptor:i}=e;return fe({resourceKind:pe,sessionId:r.sessionId,device:ee(t),owner:n,fence:r.fence,lifecycle:`open`,descriptor:de(Yn,i)})}function Zn(e){let t={};for(let n of Jn)e[n]!==void 0&&Object.assign(t,{[n]:e[n]});return t}async function Qn(e,t,n,r){let i=Yn.decode(n);return i.status!==`decoded`||!_r(t,i.descriptor)?{status:`cleanup-pending`,reason:`manual-recovery-required`}:i.descriptor.backend===`simctl`?await $n(e,i.descriptor.processes,r):await tr(e,t,i.descriptor)}async function $n(e,t,n){let r=await Promise.all(t.map(async t=>await e.screenRecording.apple.inspectProcess(t)));if(r.includes(`ownership-lost`))return{status:`cleanup-pending`,reason:`ownership-fence-lost`};if(r.every(e=>e===`missing`))return n!==void 0&&e.screenRecording.ownedProcesses.clear(er(n)),{status:`already-missing`};let i=await Promise.all(t.flatMap((t,n)=>r[n]===`owned-alive`?[e.screenRecording.apple.terminateProcess(t)]:[]));return i.includes(`ownership-lost`)?{status:`cleanup-pending`,reason:`ownership-fence-lost`}:(n!==void 0&&e.screenRecording.ownedProcesses.clear(er(n)),i.every(e=>e===`already-missing`)?{status:`already-missing`}:{status:`cleaned`})}function er(e){return{kind:`session`,sessionId:e}}async function tr(e,t,n){try{let r=await e.screenRecording.apple.inspectRunner(t,n.runnerSessionId,n.runnerAuthority);return r===`missing`?{status:`already-missing`}:r===`ownership-lost`?{status:`cleanup-pending`,reason:`ownership-fence-lost`}:(await e.screenRecording.apple.runRunner(t,{kind:`stop`,appBundleId:n.appBundleId,runnerSessionId:n.runnerSessionId,runnerAuthority:n.runnerAuthority}),{status:`cleaned`})}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`Apple recording cleanup failed`}}}async function nr(e){let{host:t,device:n,envelope:r}=e,i=Yn.decode(r.descriptor.body);return i.status===`decoded`?_r(n,i.descriptor)?i.descriptor.backend===`simctl`?await rr(e,i.descriptor):await ar(t,n,i.descriptor):N(`descriptor-invalid`,`Apple screen-recording descriptor does not match the bound device.`):N(`descriptor-invalid`,i.message)}async function rr(e,t){let n=await Promise.all(t.processes.map(async t=>await e.host.screenRecording.apple.inspectProcess(t)));if(!n.every(e=>e===`missing`))return N(`transport-not-reattachable`,n.includes(`ownership-lost`)?`Apple recording ownership no longer matches the durable descriptor.`:`Apple screen recordings require exact cleanup after daemon restart.`);let{recording:r}=t,i=ir(yt(e.envelope.metadata),t.outputPath);return r===void 0||i!==void 0&&!await or(e.host,i)?{status:`missing`}:{status:`restore-export`,recording:r,nativePath:t.outputPath,cleanup:async()=>await $n(e.host,t.processes,e.envelope.sessionId)}}function ir(e,t){if(e.finalization===void 0)return e.collectedPath??t}async function ar(e,t,n){let r=await e.screenRecording.apple.inspectRunner(t,n.runnerSessionId,n.runnerAuthority);return r===`missing`?{status:`missing`}:N(`transport-not-reattachable`,r===`ownership-lost`?`Apple recording ownership no longer matches the durable descriptor.`:`Apple screen recordings require exact cleanup after daemon restart.`)}async function or(e,t){try{return await e.screenRecording.finalize.sniff({outputPath:t}),!0}catch{return!1}}function N(e,t){return{status:`unreattachable`,reason:e,message:t}}function sr(e){return typeof e.outputPath!=`string`||e.outputPath.length===0?F():e.backend===`simctl`?cr(e,e.outputPath):e.backend===`runner`?dr(e,e.outputPath):F()}function cr(e,t){let n=vr(e.processes),r=lr(e.recording);return!n||r===`invalid`?F():{status:`decoded`,descriptor:Object.freeze({backend:`simctl`,outputPath:t,processes:n,...r===void 0?{}:{recording:r}})}}function lr(e){if(e!==void 0)return u(e)&&ur(e)?Object.freeze(e):`invalid`}function ur(e){return P(e.outPath)&&pr(e.startedAt)&&fr(e.clientOutPath)&&mt(e)}function dr(e,t){return!P(e.appBundleId)||!P(e.runnerSessionId)||!mr(e.runnerAuthority)||!hr(e.remotePath)?F():{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 P(e){return typeof e==`string`&&e.length>0}function fr(e){return e===void 0||P(e)}function pr(e){return typeof e==`number`&&Number.isFinite(e)}function mr(e){return e===`local-lease`||e===`scoped-provider`}function hr(e){return e===void 0||gr(e)}function gr(e){return typeof e==`string`&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(e)}function _r(e,t){return e.kind===`simulator`?t.backend===`simctl`:t.backend===`runner`?e.appleOs===`macos`?t.remotePath===void 0:y(e)?t.remotePath!==void 0&&gr(t.remotePath):t.remotePath===void 0:!1}function vr(e){if(!Array.isArray(e)||e.length===0)return;let t=e.filter(e=>typeof e==`object`&&!!e&&Number.isInteger(e.pid)&&(e.pid??0)>0&&typeof e.startTime==`string`&&e.startTime.length>0&&typeof e.command==`string`&&e.command.length>0);return t.length===e.length?Object.freeze([...t]):void 0}function F(){return{status:`invalid`,message:`Invalid Apple screen-recording descriptor`}}async function yr(e,t,n){if(e.kind!==`simulator`||t.scope!==`app`)return;let r=t.activeSessionApp?.bundleId;if(!r)throw TypeError(`App-scoped recording requires an active app session; open the app under test before recording.`);if(await n(r))throw TypeError(`App-scoped recording requires a real application session; open the app under test before recording.`)}const br=`iOS recording`,xr=`simctl recordVideo`;function Sr(e){return e.appleOs===`watchos`?x(`unsupported-platform-leaf`,`watchOS recording is not supported.`):y(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?x(`unsupported-device-backend`,`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`):Object.freeze({available:!0})}function Cr(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await wr({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async e=>{let r=await nr({host:t,device:n,envelope:e.envelope});return r.status===`restore-export`?{status:`active`,handle:Er({host:t,restored:r})}:r},screenRecordingCleanup:async e=>await Qn(t,n,e.envelope.descriptor.body,e.envelope.sessionId)})}async function wr(e){return e.signal.throwIfAborted(),e.device.kind===`simulator`?await Tr(e):await Or(e)}async function Tr(e){let{host:t,device:n,owner:r,input:i,signal:a}=e;await yr(n,i,t.screenRecording.apple.isRunnerBundleId);let o=i.activeSessionApp?await t.screenRecording.apple.captureClockAnchor(n,i.activeSessionApp.bundleId,a):void 0,s=Ot(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 Nr(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 Nr(c).catch(()=>{}),e}let u,d,f=async()=>{await c.terminate();let e=await c.wait;return d=e,u=Ar(e),t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId}),{observation:{recorder:`confirmed`},...u===void 0?{}:{warning:`${u} before record stop; the video covers only what the recorder wrote before it stopped.`}}},p=Ir(i,xr,{},o);return Fr({device:n,owner:r,input:i,descriptor:{backend:`simctl`,outputPath:s,processes:l,recording:Zn(p)},snapshot:p,finish:(e,n)=>_t({snapshot:e,progress:n,steps:{stop:f,collect:async e=>{try{await Dr(t,s,e)}catch(e){throw jr(e,u,d)}},finalize:async({collectedPath:n,exportPath:r})=>{try{return await Kn({host:t,snapshot:e,targetLabel:br,collectedPath:n,exportPath:r,nativePath:s})}catch(e){throw jr(e,u,d)}},discard:async e=>{await t.screenRecording.outputs.remove(e)}}}),cleanup:async()=>{let e=await Pr(c);return(e.status===`cleaned`||e.status===`already-missing`)&&t.screenRecording.ownedProcesses.clear({kind:`session`,sessionId:i.sessionId}),e}})}function Er(e){let{host:t,restored:{recording:n,nativePath:r,cleanup:i}}=e,a=Object.freeze({...n,backend:xr,gestureEvents:[]});return ft(a,{finish:(e,i)=>_t({snapshot:e,progress:i,steps:{stop:async()=>({observation:{recorder:`confirmed`},warning:`simctl recordVideo had already ended when record stop reattached to it; the video covers only what the recorder wrote before it stopped.`}),collect:async e=>{await Dr(t,r,e)},finalize:async({collectedPath:i,exportPath:a})=>await Kn({host:t,snapshot:e,targetLabel:br,collectedPath:i,exportPath:a,nativePath:r,...n.showTouches?{overlayUnavailable:`the daemon that held the touch events ended before record stop`}:{}}),discard:async e=>{await t.screenRecording.outputs.remove(e)}}}),forceCleanup:async()=>await i()})}async function Dr(e,t,n){await e.screenRecording.outputs.copy({from:t,to:n}),await e.screenRecording.finalize.sniff({outputPath:n})}async function Or(e){let{host:t,device:n,owner:r,input:i,signal:a}=e,o=i.activeSessionApp?.bundleId;if(!o)throw TypeError(`Apple runner recording requires an active app session identity`);await t.screenRecording.outputs.prepare(i.outputPath);let s=await t.screenRecording.apple.runRunner(n,{kind:`start`,appBundleId:o,outputPath:i.outputPath,...i.fps===void 0?{}:{fps:i.fps}},a);if(!s.runnerSessionId||!s.runnerAuthority)throw Error(`Apple runner recording did not expose durable session ownership`);let c={runnerSessionId:s.runnerSessionId,runnerAuthority:s.runnerAuthority},l,u=()=>(l??=kr(()=>t.screenRecording.apple.runRunner(n,{kind:`stop`,appBundleId:o,...c}).then(()=>void 0)).catch(e=>{throw l=void 0,e}),l);if(!Mr(n,s.remotePath))throw await u().catch(()=>{}),Error(`Apple runner recording did not expose coherent durable media ownership`);try{a.throwIfAborted()}catch(e){throw await u().catch(()=>{}),e}return Fr({device:n,owner:r,input:i,descriptor:{backend:`runner`,outputPath:i.outputPath,appBundleId:o,...c,...s.remotePath===void 0?{}:{remotePath:s.remotePath}},snapshot:Ir(i,`runner AVAssetWriter`,s),finish:async e=>(await u(),s.remotePath!==void 0&&await t.screenRecording.apple.retrieveRunnerRecording(n,s.remotePath,e.outPath),await Gn({host:t,snapshot:e,targetLabel:n.appleOs===`macos`?`macOS recording`:`iOS recording`,stopObservation:{recorder:`confirmed`},...s.remotePath===void 0?{}:{nativePathDisposition:`retirable`}})),cleanup:async()=>(await u(),{status:`cleaned`})})}async function kr(e){try{return await e()}catch(e){throw i(e,`COMMAND_FAILED`)}}function Ar(e){if(e.exitCode!==0)return e.signal?`simctl recordVideo was killed by ${e.signal}`:`simctl recordVideo exited with code ${e.exitCode}`}function jr(e,t,n){let a=i(e,`COMMAND_FAILED`);return t===void 0||n===void 0||a.details?.reason!==`recording-output-unplayable`?e:new r(a.code,`${a.message}; ${t}`,d(n,{...a.details??{},...n.signal===void 0?{}:{signal:n.signal},retriable:!1,hint:`The recorder exited before record stop, so the next record stop reads the same file. Close this session to release the device, then record again.`}))}function Mr(e,t){return e.appleOs===`macos`||!y(e)?t===void 0:t!==void 0&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(t)}async function Nr(e){return await e.terminate(),await e.wait}async function Pr(e){try{return await Nr(e),{status:`cleaned`}}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`Apple simulator cleanup failed`}}}function Fr(e){let{device:t,owner:n,input:r,descriptor:i,snapshot:a,finish:o,cleanup:s}=e,c=ft(a,{finish:o,forceCleanup:s});return Object.freeze({pendingHandle:new ve(c),envelope:Xn({device:t,owner:n,input:r,descriptor:i})})}function Ir(e,t,n={},r){let i=Date.now();return Object.freeze({backend:t,outPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutPath:e.clientOutputPath},startedAt:i,scope:e.scope,showTouches:e.showTouches,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},...e.exportQuality===void 0?{}:{exportQuality:e.exportQuality},...e.fps===void 0?{}:{fps:e.fps},gestureEvents:[],...r===void 0?{}:{gestureClockOriginAtMs:r.wallClockAtMs,gestureClockOriginUptimeMs:r.uptimeMs},...n.recorderStartUptimeMs===void 0?{}:{gestureClockOriginAtMs:i,gestureClockOriginUptimeMs:n.recorderStartUptimeMs,runnerStartedAtUptimeMs:n.recorderStartUptimeMs},...n.runnerSessionId===void 0?{}:{runnerSessionId:n.runnerSessionId}})}async function I(e,t,n,r={}){return n.throwIfAborted(),v(t)?{...t,booted:!0}:t.kind===`device`?(await e.deviceReadiness.applePhysical.ensureConnected(t,n),{...t,booted:!0}):t.kind===`simulator`?((await Lr(e,t)?`Booted`:await Ur(e,t,n))!==`Booted`&&(r.onColdBootStart?.(),e.deviceReadiness.appleAutomation.keepHot(t),await Rr(e,t,n,r.deadlineAtMs),await Wr(e,n)),e.deviceReadiness.appleAutomation.keepHot(t),e.deviceReadiness.appleAutomation.markBooted(t),{...t,booted:!0}):{...t,booted:!0}}async function Lr(e,t){try{return await e.deviceReadiness.appleAutomation.wasRecentlyObservedBooted(t)}catch{return!1}}async function Rr(e,t,n,r=Date.now()+12e4){let i=!1;try{i=await zr(e,t,n,r),await Br(e,t,n,r)}catch(a){throw i&&n.aborted&&Gr(e,t),n.throwIfAborted(),Date.now()>=r?Hr(t,a):a}}async function zr(e,t,n,i){let a=await e.appleTools.run({tool:`simctl`,args:S(t,[`boot`,t.id]),allowFailure:!0,timeoutMs:Vr(i,t)},n),o=`${a.stdout}\n${a.stderr}`.toLowerCase(),s=o.includes(`already booted`)||o.includes(`current state: booted`);if(a.exitCode!==0&&!s)throw new r(`COMMAND_FAILED`,`simctl boot failed`,{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode});return!s}async function Br(e,t,n,i){me({type:`command`,status:`progress`,message:`Waiting for the Simulator to finish booting...`});let a=await e.appleTools.run({tool:`simctl`,args:S(t,[`bootstatus`,t.id,`-b`]),allowFailure:!0,timeoutMs:Vr(i,t)},n);if(a.exitCode!==0)throw new r(`COMMAND_FAILED`,`simctl bootstatus failed`,{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode});if(n.throwIfAborted(),Date.now()>=i)throw Hr(t)}function Vr(e,t){let n=e-Date.now();if(n<=0)throw Hr(t);return n}function Hr(e,t){return new r(`COMMAND_FAILED`,`Simulator did not finish booting within the startup budget`,{reason:xt,deviceId:e.id,hint:`The Simulator keeps booting in the background; a first boot can take several minutes. Retry once it is up, or pass a larger --timeout.`},t instanceof Error?t:void 0)}async function Ur(e,t,n){return await Wt(e.appleTools,t,n,15e3)}async function Wr(e,t){await e.commands.run({executable:`open`,args:[`-g`,`-a`,`Simulator`],allowFailure:!0,timeoutMs:1e4},t)}function Gr(e,t){e.appleTools.run({tool:`simctl`,args:S(t,[`shutdown`,t.id]),allowFailure:!0}).catch(()=>{})}const Kr=Object.freeze({resolveOpenTarget:`simulator`,prepareApplicationOpen:`simulator`,openApplication:`simulator`,applyRuntimeHints:`simulator`,clearRuntimeHints:`simulator`,closeApplication:`simulator`,finalizeApplicationClose:`simulator`,prepareAppleRunner:`runner`,configureProviderPortReverse:`simulator`,ensureReady:`simulator`,bootTarget:`simulator`,bootTargetHeadless:`simulator`,shutdownTarget:`simulator`,listApps:`simulator`,deployApp:`simulator`,materializeAppSource:`simulator`,deployMaterializedApp:`simulator`,sendPushNotification:`simulator`,uninstallApp:`simulator`,appState:`simulator`,appLogStart:`simulator`,appLogInspect:`simulator`,appLogDoctor:`simulator`,appLogReattach:`simulator`,appLogCleanup:`simulator`,networkDump:`simulator`,audioProbeStart:`simulator`,audioProbeQuery:`simulator`,audioProbeReattach:`simulator`,audioProbeCleanup:`simulator`,readClipboard:`simulator`,writeClipboard:`runner`,setSetting:`simulator`,readSetting:`simulator`,setFoldPose:`simulator`,sendTelephonyEvent:`simulator`,unlockOrientation:`simulator`,power:`simulator`,volumeDown:`simulator`,volumeUp:`simulator`,mute:`simulator`,sleep:`simulator`,wake:`simulator`,mediaPlayPause:`simulator`,mediaNext:`simulator`,mediaPrevious:`simulator`,mediaRewind:`simulator`,mediaFastForward:`simulator`,captureSnapshot:`simulator`,captureSnapshotWithoutActiveApp:`simulator`,captureSnapshotWithCustomActions:`runner`,captureScreenshot:`simulator`,findText:`runner`,querySelector:`runner`,readTextAtPoint:`runner`,tapPoint:`runner`,tapRef:`runner`,tapElementSelector:`runner`,fillPoint:`runner`,fillRef:`runner`,longPressPoint:`runner`,hoverPoint:`runner`,hoverRef:`runner`,focusPoint:`runner`,typeText:`runner`,scrollDirection:`runner`,performGesturePlan:`runner`,performMultiTouchGesturePlan:`runner`,performTargetAuthoredDrag:`runner`,performDirectionalFlingPlan:`runner`,gestureViewport:`runner`,setViewport:`runner`,back:`runner`,home:`runner`,setOrientation:`runner`,appSwitcher:`runner`,actionButton:`runner`,tvRemote:`runner`,keyboardDismiss:`runner`,keyboardEnter:`runner`,keyboardStatus:`runner`,triggerAppEvent:`runner`,readAlert:`runner`,awaitAlert:`runner`,acceptAlert:`runner`,dismissAlert:`runner`,perfFrames:`runner`,perfMemorySample:`runner`,perfMemorySnapshot:`runner`,perfNativeCaptureStart:`runner`,perfNativeCaptureReattach:`runner`,perfNativeCaptureCleanup:`runner`,perfProfileReport:`runner`,screenRecordingStart:`runner`,screenRecordingReattach:`runner`,screenRecordingCleanup:`runner`});function qr(e){return e===void 0?`possible`:e.some(e=>Kr[e]===`runner`)?`required`:`none`}function Jr(e){let{waitMs:t,signal:n,stop:r,cancelled:i}=e;return new Promise((e,a)=>{let o=()=>l(()=>a(i())),s=()=>l(e),c=setTimeout(()=>l(e),t);function l(e){clearTimeout(c),n?.removeEventListener(`abort`,o),r?.removeEventListener(`abort`,s),e()}n?.addEventListener(`abort`,o,{once:!0}),r?.addEventListener(`abort`,s,{once:!0}),n?.aborted?o():r?.aborted&&s()})}function Yr(e){let t=e.now??Date.now,n=e.waitGrant??`every-caller`,r=new Map,i=(n,i)=>{let a={status:`pending`,value:void 0,error:void 0,settledAtMs:t(),waitSpent:!1,controller:new AbortController,settled:void 0},o=()=>{};a.settled=new Promise(e=>{o=e}),r.set(n,a);let s=(i,s)=>{a.status=i,i===`ready`?a.value=s:a.error=s,a.settledAtMs=t(),(i===`ready`||e.retryAfterMs===void 0)&&r.get(n)===a&&r.delete(n),o()};try{i(a.controller.signal).then(e=>s(`ready`,e),e=>s(`failed`,e))}catch(e){s(`failed`,e)}return a},a=(n,a)=>{let o=r.get(n);if(!o)return i(n,a);if(o.status!==`failed`)return o;let s=t()-o.settledAtMs;return e.retryAfterMs===void 0||s>=e.retryAfterMs?i(n,a):o};return{value:async(t,r)=>{let i=a(t,r.start);if(i.status===`pending`&&(n===`every-caller`||!i.waitSpent)){i.waitSpent=!0;let t=new AbortController,n=r.wait(e.waitMs,t.signal);n.catch(()=>{});try{await Promise.race([i.settled,n])}finally{t.abort()}}if(i.status===`ready`)return i.value;throw i.status===`failed`?i.error:r.pending()},close:()=>{let e=[...r.values()];r.clear();for(let t of e)t.controller.abort()}}}async function Xr(e,t){let n=await At(`ps`,[`-p`,String(e),`-o`,`lstart=`],{allowFailure:!0,signal:t.signal,timeoutMs:t.timeoutMs});return n.exitCode===0&&n.stdout.trim()||null}const Zr=3e3,Qr=`simulator-target-discovery-pending`,$r=`simulator-target-unavailable`;function ei(){let e=new Map,t=new Map,n=Yr({waitMs:1500});return async(r,i,a,o)=>{a.throwIfAborted();let s=`${r.id}:${i}`,c=e.get(s);if(c&&o!==`refresh`){let e=await Xr(c.pid,{signal:a,timeoutMs:Zr});if(a.throwIfAborted(),e===c.processStartTime)return c}return e.delete(s),await n.value(s,{start:async()=>{let n=await ii(r,i,t);return e.set(s,n),n},wait:(e,t)=>Jr({waitMs:e,signal:a,stop:t,cancelled:()=>ti(a)}),pending:()=>L(Qr,r,i)})}}function ti(e){return t({readinessPhase:`target-discovery`},e.reason)}function ni(e){return e instanceof r&&e.details?.reason===Qr}function ri(e){return e instanceof r&&e.details?.reason===$r}async function ii(e,t,n){let r=Date.now()+15e3,[i,a]=await Promise.allSettled([It(e,[`spawn`,e.id,`launchctl`,`list`],{allowFailure:!0,timeoutMs:si(r)}),ai(e,n,r)]);if(i.status===`rejected`)throw i.reason;if(a.status===`rejected`)throw a.reason;let o=i.value,s=a.value;if(o.exitCode!==0)throw L(`simulator-target-probe-failed`,e,t);let c=oi(o.stdout,t);if(!c)throw L($r,e,t);let l=await Xr(c.pid,{timeoutMs:Math.min(Zr,si(r))});if(!l)throw L(`simulator-target-identity-unavailable`,e,t);return Object.freeze({simulator:Lt(e),runtime:s,pid:c.pid,generation:`${c.pid}:${c.label}:${l}`,targetId:`${e.id}:${t}`,processStartTime:l})}async function ai(e,t,n){let r=t.get(e.id);if(r)return await r;let i=It(e,[`list`,`devices`,`-j`],{allowFailure:!0,timeoutMs:si(n)}).then(t=>{if(t.exitCode!==0)throw L(`simulator-runtime-probe-failed`,e,``);let n=Object.entries(Nt(t.stdout)).find(([,t])=>t.some(t=>t.udid===e.id))?.[0];if(!n)throw L(`simulator-runtime-unavailable`,e,``);return n});t.set(e.id,i);try{return await i}catch(n){throw t.delete(e.id),n}}function oi(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 si(e){return Math.max(1,e-Date.now())}function L(e,t,n){return new r(`COMMAND_FAILED`,`Unable to resolve the running iOS Simulator app (${e}).`,{reason:e,deviceId:t.id,appBundleId:n})}function ci(e){return e?.observation===`unobservable`&&e.proof===`no-running-process`}const li=new Map([[`application-element-missing`,5e3],[`application-server-unavailable`,5e3],[`foreground-owner-unverified`,1e3],[`foreground-owner-changed`,1e3]]);function R(e){return e.platform===`apple`&&g(e)}function ui(e){let t=ce(ue({depth:1,interactiveOnly:!0}));return Object.freeze({awaitObservable:async(n,r,i)=>{if(!R(n))return{observation:`not-eligible`};let a;for(;;){let o=await fi(e.resolveTarget,n,r,i);if(`verdict`in o)return o.verdict;let{target:s}=o;if(e.isBridgeDisabled(s))return m({level:`debug`,phase:`ios_launch_observation_skipped`,data:{reason:`circuit-disabled`,deviceId:n.id,generation:s.generation}}),di({source:`circuit`});let c=await e.source.acquire({target:s,hint:t,signal:i});if(c.stage!==`failed`)return{observation:`observable`};i.throwIfAborted();let{kind:l,code:u}=c.failure,d=li.get(u);if(d===void 0)return di({source:`bridge`,kind:l,code:u});let f=e.clock.now();if(a=Math.min(a??1/0,f+d),f>=a)return{observation:`unobservable`,proof:`launch-transition`};await e.clock.sleep(Math.min(150,a-f),i)}}})}function di(e){return{observation:`probe-failed`,failure:e}}async function fi(e,t,n,r){for(;;)try{return{target:await e(t,n,r)}}catch(e){if(r.throwIfAborted(),ni(e))continue;if(ri(e))return{verdict:{observation:`unobservable`,proof:`no-running-process`}};let{code:t,details:n}=a(e),i=n?.reason;return{verdict:di(typeof i==`string`?{source:`target`,code:t,reason:i}:{source:`target`,code:t})}}}function pi(e,t,n){let r=n&&R(e),i=r?qr(t.execution.plannedOperations):void 0,a=y(e)&&t.surface===`app`&&t.positionals.length>0&&!!t.appBundleId&&i!==`none`;return{...i?{runnerDemand:i}:{},shouldPrewarmRunner:a,awaitPrewarmAfterOpen:t.relaunch&&!r}}function mi(e,t,n,r){r.runnerDemand===`none`&&e.appleApplications.releaseSpeculativeRunner(t.device,n.execution).catch(()=>{})}async function hi(e,t,n,i,a,o){let s=Date.now(),c=async()=>await Si(t,n,i,a.observation),l=await c(),u,d,f=a.answerConfirmation,p=f&&l?.observation!==`observable`?await gi(f,a.redispatchLaunchUrl,c,l):void 0;if(p&&(o.runnerDemand=`required`,u=p.report,d=p.probeFailure,l=p.observed,p.unanswered))throw new r(`COMMAND_FAILED`,`The Simulator has not completed the launch URL for ${n.appBundleId}.`,{reason:`launch_confirmation_unanswered`,appBundleId:n.appBundleId,hint:`iOS may still be holding an "Open in" prompt, or the answer died with the runner session that raised it. Inspect the current alert before deciding on another action.`});if(i&&l?.observation!==`observable`&&await e.clock.sleep(300,t.signal),l&&(o.postOpenObservation=l.observation,l.observation===`probe-failed`&&(o.postOpenObservationFailure=l.failure)),o.postOpenSettleDurationMs=Math.max(0,Date.now()-s),u)return u;if(d)return{launchConfirmationProbeFailure:d}}async function gi(e,t,n,r){let i={observed:r,acceptAttempted:!1,confirmationStillPresent:!1};for(let r=0;r<2;r+=1){i=await _i(e,n,i);let a=r===1;if(i.confirmationStillPresent||a||!bi(i)||!t)break;await t()}return{observed:i.observed,report:i.report,probeFailure:i.probeFailure,unanswered:bi(i)||i.confirmationStillPresent}}async function _i(e,t,n){let r=await e(),i=r.outcome===`unanswered`&&r.reason===`alert-still-present`,a=n.acceptAttempted||xi(r),o=yi(n,r);return a?{observed:await t(),...o,acceptAttempted:a,confirmationStillPresent:i}:{observed:n.observed,...o,acceptAttempted:a,confirmationStillPresent:i}}function vi(e){switch(e.outcome){case`accepted`:return{seen:{launchConfirmation:`accepted`}};case`absent`:return{};case`unreadable`:return e.step===`url-owner`?{seen:{launchConfirmation:`unanswered`,launchConfirmationReason:`url-owner-unresolved`}}:{probeFailure:e.step};case`unanswered`:return e.reason===`alert-still-present`?{}:{seen:{launchConfirmation:`unanswered`,launchConfirmationReason:e.reason}}}}function yi(e,t){let n=vi(t);return`seen`in n?{report:n.seen,probeFailure:void 0}:`probeFailure`in n?{report:void 0,probeFailure:n.probeFailure}:{report:e.report,probeFailure:void 0}}function bi(e){return e.acceptAttempted&&ci(e.observed)}function xi(e){return e.outcome===`accepted`||e.outcome===`unanswered`&&e.reason===`alert-still-present`||e.outcome===`unreadable`&&e.step===`alert-accept`}async function Si(e,t,n,r){if(!(!n||!R(e.device))&&!(!r||!t.appBundleId))return await r.awaitObservable(e.device,t.appBundleId,e.signal)}let Ci;const wi=()=>Ci??=import(`./launch-confirmation.js`);let Ti;const Ei=()=>Ti??=import(`./expo-dev-client-launch.js`);function Di(e){let t=t=>Ze({device:t,signal:e.signal,resolveInteractor:e.host.localInteractors.resolve}),n=e.device,r=t(n),i=e=>{n=e,r=t(e)};return Object.freeze({resolveOpenTarget:async t=>await e.host.appleApplications.resolveOpenTarget(n,t),prepareApplicationOpen:async t=>{let r=await I(e.host,n,e.signal,{deadlineAtMs:t.execution.startupDeadlineAtMs,onColdBootStart:t.prewarmRunnerOnColdBoot?()=>{e.host.appleApplications.prewarmRunnerCache(n,t.execution,e.signal).catch(()=>{})}:void 0});i(r)},openApplication:async t=>await Oi(e.host,r,t,e.observation),applyRuntimeHints:async t=>await e.host.appleApplications.applyRuntimeHints(n,t),clearRuntimeHints:async t=>await e.host.appleApplications.clearRuntimeHints(n,t),closeApplication:async t=>{t.ensureReady&&i(await I(e.host,n,e.signal)),await Vi(e.host,r,t)},finalizeApplicationClose:async t=>await Hi(e.host,n,e.signal,t),prepareAppleRunner:async t=>{let r=await Ui(e.host,n,e.signal,t);return i(r.readied),r.prepared},configureProviderPortReverse:Yi})}async function Oi(e,t,n,r){let i={},a=z(t.device),o=Wi(e,t,n,i),s=pi(t.device,n,a);s.runnerDemand&&(i.runnerDemand=s.runnerDemand),mi(e,t,n,s);let{shouldPrewarmRunner:c}=s,l=Bi(t.device,n,a);a&&c&&!n.prewarmRunnerBeforeOpen&&o.schedule();try{await ki(e,t,n,a,l,i);let u=await Ai(t,n,a,i),d=Ki(t.device,u?{...n,runtimeLaunchUrl:u}:n,a);await ji(o,c,n.prewarmRunnerBeforeOpen);let f=o.wasAwaited();await Mi(t,n,d,a,i),await Li(o,c,s.awaitPrewarmAfterOpen),await Ri(e,t,n,a,f,l);let p=await hi(e,t,n,a,{observation:r,answerConfirmation:Fi(t,n,d),redispatchLaunchUrl:Ii(t,n,d)},i);return{appBundleId:n.appBundleId,timing:i,...p??{}}}catch(n){throw l&&await e.appleApplications.stopRunnerSession(t.device.id).catch(()=>{}),n}}async function ki(e,t,n,r,i,a){if(!zi(n,r)||!n.target)return;let o=Date.now();te(t.device.platform)&&!r&&!i&&await e.appleApplications.stopRunnerSession(t.device.id),await Qe({device:t.device,interactor:await t.resolveInteractor(n.execution,n.appBundleId),positionals:[n.appBundleId??n.target]}),r&&await e.clock.sleep(300,t.signal),a.relaunchCloseDurationMs=B(o)}async function Ai(e,t,n,i){if(!ge(t.runtimeHints))return;let a=Date.now(),o=n?await(await Ei()).resolveExpoDevClientLaunchUrl(e.device,t):void 0;if(!o){if(!t.applyRuntimeHints)throw new r(`COMMAND_FAILED`,`Runtime hint operation was not admitted for this open.`,{reason:`runtime-hints-operation-missing`});await t.applyRuntimeHints({appId:t.appBundleId,values:t.runtimeHints})}return i.runtimeHintsDurationMs=B(a),o}async function ji(e,t,n){!t||!n||(e.schedule(!0),await e.wait())}async function Mi(e,t,n,r,i){let a=Date.now();await $e({device:e.device,interactor:await e.resolveInteractor(t.execution,t.appBundleId),positionals:n.positionals,appBundleId:t.appBundleId,execution:t.execution,...r&&t.relaunch&&!t.execution.clearAppState?{terminateRunningApp:!0}:{}}),i.openDispatchDurationMs=B(a),await Ni(e,t,n.followUpUrl,i)}async function Ni(e,t,n,r){if(!n){r.launchUrlDurationMs=0;return}let i=Date.now();await Pi(e,t,n),r.launchUrlDurationMs=B(i)}async function Pi(e,t,n){let r={...t.execution,clearAppState:void 0,launchConsole:void 0,launchArgs:void 0};await $e({device:e.device,interactor:await e.resolveInteractor(r,t.appBundleId),positionals:[n],appBundleId:t.appBundleId,execution:r})}function Fi(e,t,{confirmation:n}){if(n)return async()=>{let{answerSimulatorLaunchConfirmation:r}=await wi();return await r(e.device,n,e.resolveInteractor(t.execution,n.appBundleId),e.signal,t.execution.requestDeadlineAtMs)}}function Ii(e,t,{confirmation:n}){if(n)return async()=>{await Pi(e,t,n.url)}}async function Li(e,t,n){t&&!e.wasScheduled()&&e.schedule(),n?await e.wait():e.recordUnawaited()}async function Ri(e,t,n,r,i,a){!y(t.device)||!r&&!a||!n.relaunch&&!i||r&&!i&&!await e.appleApplications.hasLiveRunnerSession(t.device,n.execution)||await e.appleApplications.notifyRunnerAppRelaunched(t.device,n.execution,t.signal)}function zi(e,t){return!!(e.relaunch&&e.target)&&!(t&&!e.execution.clearAppState)}function Bi(e,t,n){return e.kind===`device`&&e.appleOs===`ios`&&zi(t,n)}async function Vi(e,t,n){te(t.device.platform)&&!z(t.device)&&await e.appleApplications.stopRunnerSession(t.device.id),await Qe({device:t.device,interactor:await t.resolveInteractor(n.execution,n.appBundleId),positionals:n.positionals}),z(t.device)&&await e.clock.sleep(300,t.signal)}async function Hi(e,t,n,r){r.daemonShutdown||await e.appleApplications.releaseRunnerOnClose(t.id,{retain:r.retainRunner}),await e.appleApplications.dismissCloseAlerts(t,r).catch(()=>{});let i=r.shutdownTarget&&z(t)?await e.deviceShutdown.apple.shutdownTarget(t,n):void 0;return i===void 0?{}:{shutdown:i}}async function Ui(e,t,n,r){let i=Date.now()+r.timeoutMs,a=performance.now();return await f(`prepare_apple_runner`,async()=>{let o=await I(e,t,n,{deadlineAtMs:i}),s=Math.max(1,i-Date.now());return m({phase:`prepare_apple_runner`,durationMs:performance.now()-a,data:{event:`runner_start`,timeoutMs:r.timeoutMs,remainingMs:i-Date.now()}}),{readied:o,prepared:await e.appleApplications.prepareRunner(o,{...r,timeoutMs:s},n)}},()=>({timeoutMs:r.timeoutMs,remainingMs:i-Date.now()}),`readiness_start`)}function Wi(e,t,n,r){let i,a=!1,o=Gi(t.device,n)?{healthCheck:!1}:void 0;return{schedule:(a=!1)=>{i||=(r.runnerPrewarmKind=`session`,r.runnerPrewarmScheduled=!0,o?e.appleApplications.prewarmRunnerSession(t.device,n.execution,t.signal,a,o):e.appleApplications.prewarmRunnerSession(t.device,n.execution,t.signal,a))},wait:async()=>{if(!i||a)return;a=!0;let e=Date.now();await i,r.runnerPrewarmWaited=!0,r.runnerPrewarmDurationMs=B(e)},wasAwaited:()=>a,wasScheduled:()=>i!==void 0,recordUnawaited:()=>{i&&!a&&(r.runnerPrewarmWaited=!1)}}}function Gi(e,t){return e.kind===`device`&&e.appleOs===`ios`&&!t.hasExistingSession&&!t.relaunch&&!t.prewarmRunnerBeforeOpen}function Ki(e,t,n){let r=t.runtimeLaunchUrl?.trim(),i=t.positionals.length===1?t.positionals[0]?.trim():void 0;if(!r||!i||s(i))return{positionals:t.positionals};let a=qi(e,t.appBundleId,r),o=a?{confirmation:a}:{};return n&&!Ji(t)?{positionals:[i,r],...o}:{positionals:t.positionals,followUpUrl:r,...o}}function qi(e,t,n){if(e.appleOs===`ios`&&e.kind===`simulator`&&!(t===void 0||c(n)))return{url:n,appBundleId:t}}function Ji(e){return e.execution.clearAppState===!0||!!e.execution.launchConsole?.trim()||!!e.execution.launchArgs?.length}function z(e){return y(e)&&e.kind===`simulator`}function B(e){return Math.max(0,Date.now()-e)}async function Yi(){throw new r(`UNSUPPORTED_OPERATION`,`This lifecycle operation is unavailable for Apple.`)}const Xi=Object.freeze({available:!0}),Zi=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.`}),Qi=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Push notifications are supported on Apple simulators only.`}),$i=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),ea=Object.freeze({available:!1,reason:`unsupported-device-kind`});function ta(e){let t=ua(e);return Object.freeze({deployApp:t,materializeAppSource:t,deployMaterializedApp:t,sendPushNotification:da(e),uninstallApp:t})}function na(e){let{host:t,device:n,signal:r}=e,i=ta(n);return Object.freeze({...i.deployApp.available?{deployApp:async e=>await ra(t,n,e,r),materializeAppSource:async e=>await t.appleDeployment.prepareArtifact(e,{signal:r}),deployMaterializedApp:async e=>await aa(t,n,e,r),uninstallApp:async e=>await ia(t,n,e,r)}:{},...i.sendPushNotification.available?{sendPushNotification:async e=>(await ca(t,n,e,r),{})}:{}})}async function ra(e,t,n,r){if(n.replaceExisting)return await e.appleDeployment.withInvalidatedAppResolutionCache(t,async()=>{let i=await e.appleDeployment.resolveAppBundleId(t,n.app);await sa(e,t,i,r);let a=await e.appleDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{appIdentifierHint:n.app,signal:r});try{return await oa(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 aa(e,t,{artifact:i},r)}finally{await i.cleanup()}}async function ia(e,t,n,i){return await e.appleDeployment.withInvalidatedAppResolutionCache(t,async()=>{await I(e,t,i);let a;try{a=await e.appleDeployment.resolveAppBundleId(t,n.app,{installedOnly:!0})}catch(e){if(e instanceof r&&e.code===`APP_NOT_INSTALLED`&&n.app.trim().includes(`.`))return{wasInstalled:!1};throw e}return await sa(e,t,a,i),{wasInstalled:!0,bundleId:a}})}async function aa(e,t,n,r){return await oa(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 oa(e,t,n,r){await I(e,t,r),await la(e,t.kind===`simulator`?{tool:`simctl`,args:S(t,[`install`,t.id,n])}:{tool:`devicectl`,args:[`device`,`install`,`app`,`--device`,t.id,n],timeoutMs:kt},r,`Apple app install failed`)}async function sa(e,t,n,r){await I(e,t,r),await la(e,t.kind===`simulator`?{tool:`simctl`,args:S(t,[`uninstall`,t.id,n])}:{tool:`devicectl`,args:[`device`,`uninstall`,`app`,`--device`,t.id,n]},r,`Apple app uninstall failed for ${n}`,{tolerate:e=>Mt(`${e.stdout}\n${e.stderr}`.toLowerCase())})}async function ca(e,t,n,i){if(t.kind!==`simulator`)throw new r(`UNSUPPORTED_OPERATION`,`Apple push notifications require a simulator`);await I(e,t,i);let a=await e.temporaryFiles.create({prefix:`agent-device-ios-push-`,suffix:`.apns`});try{await a.writeText(`${JSON.stringify(n.payload)}\n`),await la(e,{tool:`simctl`,args:S(t,[`push`,t.id,n.appId,a.path])},i,`Apple push notification failed`)}finally{await a[Symbol.asyncDispose]()}}async function la(e,t,n,r,i){let a=await e.appleTools.run({...t,allowFailure:!0},n);return i?.tolerate?.(a)?a:p(a,r,e=>({cmd:`xcrun`,args:[t.tool,...t.args],...t.tool===`devicectl`?{hint:jt(e.stdout,e.stderr)??`Ensure the iOS device is unlocked, trusted, and available in Xcode > Devices, then retry.`}:{}}))}function ua(e){return fa(e)?e.kind!==`simulator`&&e.kind!==`device`?ea:e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?Zi:Xi:$i}function da(e){return fa(e)?e.kind===`simulator`?Xi:Qi:$i}function fa(e){return y(e)&&e.appleOs!==`watchos`}const V=Object.freeze({available:!0}),pa=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`back is supported on Apple simulators and physical devices.`}),ma=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function ha(e){return e.kind!==`simulator`&&e.kind!==`device`?pa:h(e)===`watchos`?ma:V}const ga=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`home is supported on Apple simulators and physical devices.`}),_a=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),va=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`app-switcher is supported on Apple simulators and physical devices.`});function ya(e,t){if(e.kind!==`simulator`&&e.kind!==`device`)return t;let n=h(e);return n===`macos`||n===`watchos`?_a:V}function H(e){if(e.kind!==`simulator`&&e.kind!==`device`)return!1;let t=h(e);return t!==`tvos`&&t!==`macos`&&t!==`watchos`}const ba=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`orientation is supported on Apple simulators and physical devices.`}),xa=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function Sa(e){return e.kind!==`simulator`&&e.kind!==`device`?ba:H(e)?V:xa}const Ca=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`tv-remote is supported only on tvOS devices.`});function wa(e){return(e.kind===`simulator`||e.kind===`device`)&&ne(e)?V:Ca}const U=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Ta=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 Ea(e){return H(e)?Ta:U}function Da(e){return H(e)?V:U}function Oa(e){return H(e)?V:U}const ka=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`No Apple leaf carries this system button.`}),Aa=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`action-button is supported on iPhone and iPad simulators and physical devices.`}),ja=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 Ma(e){return e.kind!==`simulator`&&e.kind!==`device`?Aa:_(e)?V:ja}const Na=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`hardware-button volume presses the iPhone/iPad volume key; this Apple leaf has none.`}),Pa=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`hardware-button volume is supported on physical iPhone and iPad; iOS Simulators refuse because XCUIDevice exposes no volume press there.`});function Fa(e){return _(e)?e.kind===`device`?V:Pa:Na}function Ia(e){return Object.freeze({...Te({back:ha(e)}),...Ve({unsupported:ka,home:ya(e,ga),appSwitcher:ya(e,va),actionButton:Ma(e),volumeUp:Fa(e),volumeDown:Fa(e)}),...Ge({orientation:Sa(e)}),...Je({tvRemote:wa(e),buttonSupport:{supported:o(`apple`),unsupported:{available:!1,reason:`unsupported-platform-leaf`,hint:`This TV remote button is not supported on tvOS.`}}}),...We({unsupported:U,status:Ea(e),dismiss:Da(e),enter:Oa(e)})})}function La(e){let{host:t,device:n,signal:r,admitted:i}=e,a=Object.keys(Ia(n));return tt({device:n,signal:r,resolveInteractor:t.localInteractors.resolve,facts:Object.fromEntries(a.map(e=>[e,i[e]]))})}const W=Object.freeze({available:!0}),Ra=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`clipboard is supported on Apple simulators and the macOS host.`}),za=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`settings is supported on Apple simulators and the macOS host.`}),Ba=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.`}),Va=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:"Run `agent-device settings --help` for the settings each target serves."}),Ha=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`The macOS host supports settings appearance and settings permission <grant|reset> <accessibility|screen-recording|input-monitoring>.`}),Ua=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Select a booted iPhone or iPad simulator: this setting runs only there.`}),Wa=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.`}),Ga=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function Ka(e,t,n){if(e.kind!==`simulator`&&e.kind!==`device`)return t;let r=h(e);return r===`watchos`?Ga:e.kind===`simulator`||r===`macos`?W:n}const qa=Object.freeze({available:!1,reason:`unsupported-device-scope`,hint:`This session holds one app of the Mac. Use a --surface desktop session for the clipboard and host settings.`});function Ja(e){return e.hostApp?qa:Ka(e,Ra,Wa)}const Ya=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`trigger-app-event is supported on Apple simulators and physical devices.`}),Xa=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`alert is supported on Apple simulators and physical devices.`}),Za=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`alert is supported on Apple simulators, the macOS host, and physical iOS devices.`});function Qa(e){if(e.kind!==`simulator`&&e.kind!==`device`)return Xa;let t=h(e);return t===`watchos`?Ga:e.kind===`simulator`||t===`ios`||t===`macos`?W:Za}function $a(e){return e.kind!==`simulator`&&e.kind!==`device`?Ya:h(e)===`watchos`?Ga:W}function eo(e){let t=Ja(e);return t.available?Wa:t}function to(e){let t=e.hostApp?qa:Ka(e,za,Ba);if(v(e))return et({target:t,unsupported:Ha,write:{appearance:W,permission:W}});let n=g(e)?W:Ua;return et({target:t,unsupported:Va,write:{wifi:W,airplane:W,location:W,appearance:W,"clear-app-state":W,"reset-keychain":W,permission:W,"text-size":n,faceid:n,touchid:n},read:{"text-size":n}})}function no(e){let t=Ja(e),n=Qa(e);return Object.freeze({...Ke({unsupported:eo(e),read:t,write:t}),...Xe({read:n,wait:n,accept:n,dismiss:n}),...Ye({triggerAppEvent:$a(e)}),...to(e)})}function ro(e){let{host:t,device:n,signal:r}=e;return tt({device:n,signal:r,resolveInteractor:t.localInteractors.resolve,facts:no(n)})}function io(e,t,n){let r=Ue({device:t.device,signal:t.signal,resolveInteractor:e.localInteractors.resolve}),i=async i=>{if(i.options?.observeOnly===!0)return await r.captureSnapshot(i);let a=v(t.device)?se(i.options?.surface,t.appBackend):void 0;if(a)return await e.snapshot.captureSurface(t.device,{...i.options,surface:a},He(t.signal,i));if(!n)return await r.captureSnapshot(i);let o=He(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 ao(e,t){return Object.freeze({findText:async n=>{let r=await oo(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 oo(e,t,n){let r=n.options?.appBundleId;if(r===void 0||v(t.device)&&oe(n.options?.surface,t.appBackend)===`macos-helper`)return;let i=n.signal?AbortSignal.any([t.signal,n.signal]):t.signal;if(i.throwIfAborted(),await so(e,t.device,n.execution))return{appBundleId:r,signal:i}}async function so(e,t,n){return!R(t)||await e.appleApplications.hasLiveRunnerSession(t,n??{})}function co(e){return Object.freeze({querySelector:async t=>{let n=t.signal?AbortSignal.any([e.signal,t.signal]):e.signal;n.throwIfAborted();let r={...t.execution,signal:n},{queryAppleRunnerSelector:i}=await import(`./runner-selector-query.js`),a=await i(e.device,t.selector,t.options?.appBundleId,r),o=lo(a);return Object.freeze({found:a.found===!0,...o?{node:o}:{}})}})}function lo(e){let t=e.nodes;if(!Array.isArray(t))return;let n=t[0];if(!n||typeof n!=`object`)return;let r=l(n.rect);if(r)return Object.freeze({rect:r,hittable:n.hittable===!0})}const G=Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`The native macOS app backend never starts the XCTest runner, which this command needs. Unset AGENT_DEVICE_MACOS_APP_BACKEND to use XCTest.`});function uo(e,t){return!v(e)||t!==`native`?{}:Object.freeze({screenRecordingStart:G,screenRecordingReattach:G,prepareAppleRunner:G,longPressPoint:G,...Te({back:G}),...Oe({unsupported:G})})}function fo(e){let t,n=!1,r=async()=>(t??=import(`./host4.js`).then(e=>e.t).then(({createSnapshotSourceHost:t})=>import(`./adapter.js`).then(({createSimulatorSnapshotSource:n})=>n({host:t(e)}))),await t);return{acquire:async e=>n?{stage:`failed`,failure:{kind:`unsupported`,code:`source-closed`}}:await(await r()).acquire(e),close:async()=>{n=!0,t&&await(await t).close()}}}const po=new Set([`notRunning`,`runningBackground`,`runningBackgroundSuspended`]);function mo(){return async(e,t)=>{let n=zt(e.id);if(!n||n.liveness!==`ready`)return`unknown`;for(let r of Se){let i=await ho(e,r.bundleId,n.sessionId,t);if(i===`runningForeground`)return{kind:`foreground`,host:r};if(i===void 0||!po.has(i))return`unknown`}return`background`}}async function ho(t,n,r,i){try{let a=(await Rt(t,{command:`appState`,appBundleId:n},{signal:AbortSignal.any([i.signal,AbortSignal.timeout(1e3)]),expectedRunnerSessionId:r,...i.requestId?{requestId:i.requestId}:{}})).applicationState;return e(a)?a:void 0}catch{i.signal.throwIfAborted();return}}function go(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 _o(n,r);return a!==`absent`&&a!==`unknown`&&t.set(n.id,{at:e(),host:a.host}),a}}async function _o(e,t){let n=await Promise.all(Se.map(async e=>({host:e,pids:await vo(e.processExecutable,t)}))),r=!1;for(let{host:i,pids:a}of n){if(a===`unknown`){r=!0;continue}for(let n of a){let a=await yo(n,e.id,t);if(a===`unknown`)r=!0;else if(a)return{kind:`present`,host:i}}}return r?`unknown`:`absent`}async function vo(e,t){let n=await bo(`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 yo(e,t,n){let r=await bo(`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 bo(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 xo=new Map([[`window-coordinate-space-unresolved`,`coordinate-space-unresolved`],[`app-window-not-full-screen`,`window-not-full-screen`],[`foreground-owner-unverified`,`foreground-ownership`],[`foreground-owner-changed`,`foreground-ownership`]]);function So(e){if(e.kind===`preparing`)return{scope:`capture`,code:e.code,consequence:`bridge-preparation`};let t=xo.get(e.code);return t?{scope:`capture`,code:e.code,consequence:t}:{scope:`generation`,code:e.code}}const Co=`system-surface-presented`,wo=`system-surface-host-lingering`;function To(e,t={}){let n=t.source??fo(e.hostEnvironment),i=t.resolveTarget??ei(),a=t.systemSurfacePresent??go(),o=t.systemSurfaceForeground??mo(),s=new Set,c=new Map,l=e=>(Vo(e,c,s),s.has(Ho(e))),u=ui({source:n,resolveTarget:i,clock:e.clock,isBridgeDisabled:l});return Object.freeze({awaitObservable:u.awaitObservable,shutdown:async()=>await n.close(),capture:async(t,c,u,d)=>{if(!ko(t,c))return await Mo(t,c,d);let p=await Eo(t,c,u,o);if(p!==`background`&&p!==`unknown`)return await jo(t,c,d,p.host.bundleId);let m=p===`background`?`absent`:await a(t,u);if(m===`unknown`)return await K(t.id,c,d,Po(t.id,c),q(c),`system-surface-probe-unavailable`,[Bo()]);if(m!==`absent`)return await jo(t,c,d,m.host.bundleId);let h;try{h=await Do(e,i,t,c,u)}catch(e){return Oo(u,e),J(`target-resolution-failed`,t,void 0,e),await K(t.id,c,d,Po(t.id,c),q(c),`target-resolution-failed`,[Bo()])}if(l(h))return J(`circuit-disabled`,t,h.generation),await K(t.id,c,d,h,q(c),`circuit-disabled`);let g=q(c),_=await n.acquire({target:h,hint:ce(g),signal:u});if(_.stage===`failed`){if(_.failure.kind===`cancelled`)throw u.throwIfAborted(),new r(`COMMAND_FAILED`,`Simulator AX snapshot acquisition was cancelled.`,{reason:_.failure.code,..._.failure.details});let e=await zo(_.failure,h,t,c.options.appBundleId,u,i);return await Ao(c,d,h,e,g,_.failure,s)}try{return await f(`ios.snapshot-source.present`,async()=>await e.snapshot.presentIosAcquisition(_,c.options),{producer:`simulator-ax-bridge`})}catch(e){return await Ao(c,d,h,{lineage:h,residue:[]},g,{kind:`malformed-tree`,code:`presentation-invariant`},s,e)}}})}async function Eo(e,t,n,r){let i=t.execution?.requestId,a=await r(e,{signal:n,...i?{requestId:i}:{}});return a===`background`&&m({level:`debug`,phase:`ios_snapshot_route_surface_host_background`,data:{deviceId:e.id}}),a}async function Do(e,t,n,r,i){let a=r.options.appBundleId;for(;;)try{return await t(n,a,i)}catch(t){if(!ni(t))throw t;let i={requestId:r.execution?.requestId};if(await e.appleApplications.hasLiveRunnerSession(n,i))throw t}}function Oo(e,t){if(e.aborted)throw n(t)?t:e.reason}function ko(e,t){return R(e)&&!!t.options?.appBundleId&&t.options?.customActions!==!0&&t.options?.preferredBackend===void 0}async function Ao(e,t,n,r,i,a,o,s){let c=So(a);return c.scope===`generation`&&o.add(Ho(n)),J(a.code,{id:n.simulator.udid},n.generation,s,a.details),await K(n.simulator.udid,e,t,r.lineage,i,c,r.residue)}async function K(e,t,n,r,i,a,o=[]){return No(e,await n(t),r,i,a,o)}async function jo(e,t,n,r){let i=await n(t),a=i.systemSurface?Co:wo;return i.systemSurface||J(a,e,void 0,void 0,{detectedHost:r}),No(e.id,i,Po(e.id,t),q(t),a)}async function Mo(e,t,n){let r=await n(t),i=r.systemSurface;return i?{...r,comparisonIdentity:Io(Fo(e.id,i.bundleId),q(t),[])}:r}function No(e,t,n,r,i,a=[]){let o=t.systemSurface;return{...t,comparisonIdentity:Io(o?Fo(e,o.bundleId):n,r,[...o?[]:a,{kind:`fallback-source`,producer:`apple-runner`}]),warnings:[...t.warnings??[],Lo(i,n,o!==void 0)]}}function Po(e,t){return{targetId:`${e}:${t.options.appBundleId}`}}function Fo(e,t){return{targetId:`${e}:${t}`}}function Io(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:le(t),residue:Object.freeze([...n])})}function Lo(e,t,n){if(e===Co)return`Simulator AX snapshot inapplicable (${e}); used XCTest to read the system surface presented over the app.`;if(e===wo)return`Simulator AX snapshot inapplicable (${e}); used XCTest, which read app content: the system surface host process was still running but no longer presenting.`;let r=typeof e==`string`?e:e.code;return n?`Simulator AX snapshot unavailable (${r}); used XCTest, which read the system surface presented over the app.`:typeof e!=`string`&&e.scope===`capture`?Ro(r,e.consequence):`Simulator AX snapshot unavailable (${r}); used XCTest for ${t.generation?`this app generation`:`an unverified app generation`}.`}function Ro(e,t){let n=`Simulator AX snapshot unavailable (${e}); used XCTest for this capture`;switch(t){case`bridge-preparation`:return`${n} while the bridge is still being prepared.`;case`foreground-ownership`:return`${n}, while another surface owned the foreground.`;case`window-not-full-screen`:return`${n}, while the app window did not fill the screen; the runner republishes a windowed capture in screen space.`;case`coordinate-space-unresolved`:return`${n}, which reports captured geometry in the app's own orientation space.`}}async function zo(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:[Bo()]}}}function Bo(){return{kind:`unknown-generation`,captureId:Gt()}}function q(e){return ue({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 Vo(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 Ho(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=ae(`apple`),X=Object.freeze({available:!0}),Z=x(`unsupported-platform-leaf`),Uo=x(`unsupported-platform-leaf`,`viewport resizes web targets only (--platform web). Apple screen geometry is fixed by the selected simulator or device type — open a different simulator to test another screen size.`),Wo=x(`unsupported-platform-leaf`,`the stateless audio page probe is a web-session operation; Apple targets use the host capture.`),Go=x(`unsupported-device-backend`,`perf requires an Apple simulator, macOS device, or CoreDevice-backed physical Apple device.`),Ko=x(`unsupported-device-kind`,`focus is supported on Apple simulators and physical devices.`),qo=x(`unsupported-platform-leaf`,`telephony simulates calls and SMS through the Android emulator console; Apple simulators and devices expose no host control that injects a call or text message.`),Jo=x(`unsupported-platform-leaf`,`Apple appstate is unavailable here: the runner reads the session app's XCUIApplication state on iOS-family simulators and physical devices only, and the Apple target answers no sessionless foreground probe. The per-command answer is the targetActivation disclosure, which a capture carries when its command had to re-activate the session app (#2682).`);function Yo(e){return!y(e)||e.appleOs===`watchos`?Jo:e.kind===`simulator`||e.kind===`device`?X:Jo}const Xo=x(`unsupported-provider-mode`,`Headless boot is supported only for local Android emulators.`),Zo=x(`unsupported-platform-leaf`,`watchOS has no XCUITest-driveable UI, so element text comes from the captured tree only.`),Qo=x(`unsupported-device-kind`),$o=x(`unsupported-platform-leaf`,`watchOS open is not supported because XCUITest cannot drive watchOS UI.`),es=x(`unsupported-platform-leaf`,`watchOS runner preparation is not supported because XCUITest cannot drive watchOS UI.`),ts=x(`unsupported-platform-leaf`,`watchOS close is not supported because XCUITest cannot drive watchOS UI.`),ns=x(`unsupported-device-kind`,`Runtime hints are supported only for local iOS-family simulators and Android devices.`),rs=Q(`open is supported only for Apple simulators and devices.`),is=Q(`prepare is supported only for Apple simulators and devices.`),as=Q(`close is supported only for Apple simulators and devices.`),os=x(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),ss=x(`unsupported-device-kind`,`shutdown is supported only for Apple simulators and Android emulators.`),cs=Q(`snapshot is supported only for Apple simulators and devices.`),ls=x(`unsupported-platform-leaf`,`Re-run without --actions, or target an iOS simulator.`),us=x(`unsupported-platform-leaf`,`screenshot is not supported on watchOS because XCUITest cannot drive watchOS UI.`),ds=Q(`screenshot is supported only for Apple simulators and devices.`),fs=x(`owner-capability-missing`,`Open the app under test before capturing its snapshot.`);function Q(e){return x(`unsupported-device-kind`,e)}function ps(e){return!y(e)||e.appleOs===`watchos`?Z:e.kind===`simulator`?X:ss}function ms(e){let t=hs(e),n=gs(e),r=_s(e),i=vs(e);return _e({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:i,clearRuntimeHints:i,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:n,configureProviderPortReverse:os})}function hs(e){return h(e)===`watchos`?$o:e.kind===`simulator`||e.kind===`device`?X:rs}function gs(e){return h(e)===`watchos`?es:e.kind===`simulator`||e.kind===`device`?X:is}function _s(e){return h(e)===`watchos`?ts:e.kind===`simulator`||e.kind===`device`?X:as}function vs(e){return h(e)!==`watchos`&&y(e)&&e.kind===`simulator`?X:ns}function ys(e){return e.appleOs===`watchos`?x(`unsupported-platform-leaf`,`watchOS app inventory is not supported.`):e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?x(`unsupported-device-backend`,`App inventory is available only on CoreDevice-backed physical iOS devices.`):X}function $(e){return e.kind===`simulator`||e.kind===`device`?X:Ko}function bs(e){let t=Nn(e),n=To(e),r,i=t=>v(t)?r??=Ut(e.hostEnvironment.env):`xctest`,a=async n=>{let r=await t.inspectFacts(n),a=ta(n),o=Sr(n),s=o.available?await e.screenRecording.apple.availability(n):void 0,c=o.available&&s?.available===!1?x(`unsupported-provider-mode`,s.hint):o,l=n.appleOs===`watchos`?Z:X,u=v(n)||n.appleOs===`watchos`?Z:X,d=ys(n);return Object.freeze({device:r.device,operations:{...r.operations,...a,appState:Yo(n),networkDump:X,screenRecordingStart:c,screenRecordingReattach:c,screenRecordingCleanup:c,...Ts(n),...De({capture:ws(n)}),...Ae({findText:Cs(n),querySelector:y(n)?$(n):Z}),...Pe({setViewport:Uo}),...ze({focus:$(n)}),...en(n),...je({type:$(n)}),...be({unsupported:Z,tap:$(n),longPress:$(n),fill:$(n),...y(n)?{tapElementSelector:$(n)}:{}}),...Be({readTextAtPoint:Ss(n)}),...Ia(n),...Vt(n),sendTelephonyEvent:qo,...no(n),...we({capture:Jt(n),query:Wo}),...Ne(xs(n)),ensureReady:l,bootTarget:u,bootTargetHeadless:Xo,listApps:d,...ms(n),shutdownTarget:ps(n),...uo(n,i(n))}})};return Object.freeze({owner:Y,ownsDevice:e=>e.platform===`apple`,inspectFacts:a,bind:async r=>{let o=await t.bind(r),s=await a(r.device),c=s.operations.screenRecordingStart,l=b(s.operations.appState,()=>qt(e,{device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),u=b(s.operations.querySelector,()=>co({device:r.device,signal:r.scope.signal})),d={...l,...u,...o.operations,...na({host:e,device:r.device,signal:r.scope.signal}),networkDump:async t=>await Ln(e,r.device,t,r.scope.signal),...b(c,()=>Cr({host:e,device:r.device,owner:Y,signal:r.scope.signal})),...b(s.operations.audioProbeStart,()=>lt({host:e.audioProbe.hostCapture,device:r.device,owner:Y})),...b(s.operations.perfFrames,()=>Yt({resolveHost:()=>e.perf.apple,device:r.device,owner:Y})),...b(s.operations.captureSnapshot,()=>io(e,{device:r.device,signal:r.scope.signal,appBackend:i(r.device)},n)),...b(s.operations.captureScreenshot,()=>Me({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...b(s.operations.focusPoint,()=>qe({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...Le({device:r.device,signal:r.scope.signal,facts:s.operations,resolveInteractor:e.localInteractors.resolve}),...b(s.operations.scrollDirection,()=>Ie({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...b(s.operations.typeText,()=>Ee({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...b(s.operations.tapPoint,()=>xe({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:s.operations,pause:async t=>await e.clock.sleep(t,r.scope.signal)})),...b(s.operations.readTextAtPoint,()=>Re({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve})),...b(s.operations.findText,()=>ao(e,{device:r.device,signal:r.scope.signal,appBackend:i(r.device)})),...La({host:e,device:r.device,signal:r.scope.signal,admitted:s.operations}),...ro({host:e,device:r.device,signal:r.scope.signal}),...Ht({device:r.device,signal:r.scope.signal}),...b(s.operations.ensureReady,()=>({ensureReady:async()=>await I(e,r.device,r.scope.signal)})),...b(s.operations.bootTarget,()=>({bootTarget:async t=>await I(e,r.device,r.scope.signal,{deadlineAtMs:t.deadlineAtMs})})),...b(s.operations.listApps,()=>({listApps:async e=>{r.scope.signal.throwIfAborted();let{listIosApps:t}=await import(`./app-resolution.js`).then(e=>e.t);return(await t(e.device,e.filter)).map(e=>({id:e.bundleId,name:e.name}))}})),...he(Di({host:e,device:r.device,signal:r.scope.signal,observation:n}),s.operations),...b(s.operations.shutdownTarget,()=>({shutdownTarget:async()=>await e.deviceShutdown.apple.shutdownTarget(r.device,r.scope.signal)}))};return Object.freeze({device:o.device,owner:Y,facts:s,operations:Object.freeze(d),[Symbol.asyncDispose]:async()=>await o[Symbol.asyncDispose]()})},shutdown:async()=>{await Promise.all([t.shutdown(),n.shutdown()])}})}function xs(e){let t=e.iosPhysicalDeviceBackend!==`xctest`&&h(e)!==`watchos`?X:Go;return{frames:t,memorySample:t,memorySnapshot:t,nativeCapture:t,profileReport:t}}function Ss(e){return h(e)===`watchos`?Zo:e.kind===`simulator`||e.kind===`device`?X:Qo}function Cs(e){return h(e)===`watchos`?cs:e.kind===`simulator`||e.kind===`device`?X:cs}function ws(e){return h(e)===`watchos`?us:e.kind===`simulator`||e.kind===`device`?X:ds}function Ts(e){let t=Cs(e);return ke({capture:t,customActions:t.available&&y(e)&&e.kind===`simulator`?X:ls,withoutActiveApp:y(e)?fs:t})}export{bs as createApplePlatformRuntime,Yr as n,Jr as r,Xr as t};
@@ -1 +1 @@
1
- import{tt as e}from"./sdk-contracts.js";import{C as t}from"./sdk-device.js";import{s as n}from"./simctl.js";import{t as r}from"./simulator-state.js";const i=15e3;function a(e){return Object.freeze({canShutdownTarget:o,shutdownTarget:async(t,n)=>await s(e.appleTools,t,n)})}function o(e){return t(e)&&e.appleOs!==`watchos`&&e.kind===`simulator`}async function s(t,r,a){a.throwIfAborted();try{let e=await t.run({tool:`simctl`,args:n(r,[`shutdown`,r.id]),allowFailure:!0,timeoutMs:i},a);a.throwIfAborted();let o=l(e);return o.success?o:await c(t,r,a)===`Shutdown`?{...o,success:!0,exitCode:0}:o}catch(t){a.throwIfAborted();let n=e(t);return{success:!1,exitCode:-1,stdout:``,stderr:n.message,error:n}}}async function c(e,t,n){try{return await r(e,t,n,i)}catch{return n.throwIfAborted(),null}}function l(e){let t=e.exitCode??-1;return{success:t===0,exitCode:t,stdout:e.stdout,stderr:e.stderr}}export{a as createAppleShutdownRuntime};
1
+ import{tt as e}from"./sdk-contracts.js";import{w as t}from"./sdk-device.js";import{s as n}from"./simctl.js";import{t as r}from"./simulator-state.js";const i=15e3;function a(e){return Object.freeze({canShutdownTarget:o,shutdownTarget:async(t,n)=>await s(e.appleTools,t,n)})}function o(e){return t(e)&&e.appleOs!==`watchos`&&e.kind===`simulator`}async function s(t,r,a){a.throwIfAborted();try{let e=await t.run({tool:`simctl`,args:n(r,[`shutdown`,r.id]),allowFailure:!0,timeoutMs:i},a);a.throwIfAborted();let o=l(e);return o.success?o:await c(t,r,a)===`Shutdown`?{...o,success:!0,exitCode:0}:o}catch(t){a.throwIfAborted();let n=e(t);return{success:!1,exitCode:-1,stdout:``,stderr:n.message,error:n}}}async function c(e,t,n){try{return await r(e,t,n,i)}catch{return n.throwIfAborted(),null}}function l(e){let t=e.exitCode??-1;return{success:t===0,exitCode:t,stdout:e.stdout,stderr:e.stderr}}export{a as createAppleShutdownRuntime};
@@ -1 +1 @@
1
- import{R as e}from"./sdk-contracts.js";import{H as t}from"./sdk-device.js";import{Cn as n,Sn as r,gn as i}from"./sdk-batch.js";import{n as a}from"./device-shell.js";import{i as o,n as s}from"./durable-resource.js";import{n as c}from"./screen-recording-runtime.js";import{n as l,t as u}from"./application-lifecycle-runtime.js";import{n as ee}from"./async-lifecycle.js";import{i as d}from"./touch-runtime.js";import{r as f}from"./gesture-admission.js";import{B as p,C as te,I as ne,K as re,M as ie,N as ae,O as oe,R as se,T as ce,U as le,Y as ue,Z as m,_ as h,k as g,l as _,o as v,p as de,r as fe,v as pe,x as me}from"./tv-remote-runtime.js";import{r as he,u as ge}from"./application-lifecycle-interaction.js";import{t as _e}from"./local-interactor-operation-set.js";import{n as ve,t as y}from"./src4.js";import{n as b,t as x}from"./screen-recording-completion.js";import{t as S}from"./screen-recording-options.js";import{i as C,n as w}from"./perf-runtime-operation-builder.js";import{t as T}from"./app-log-runtime.js";import{randomUUID as E}from"node:crypto";import{setTimeout as D}from"node:timers/promises";const O=Object.freeze({resourceKind:T,version:1,encode:e=>({...e}),decode:e=>e.transport!==`harmony-hilog`||!A(e.outputPath)||!A(e.pidPath)?{status:`invalid`,message:`Invalid HarmonyOS app-log descriptor`}:{status:`decoded`,descriptor:Object.freeze({transport:`harmony-hilog`,outputPath:e.outputPath,pidPath:e.pidPath})}});function k(e){return s({resourceKind:T,sessionId:e.sessionId,device:{id:e.device.id,family:`harmonyos`,kind:e.device.kind,...e.device.target===void 0?{}:{target:e.device.target}},owner:e.owner,fence:e.fence,lifecycle:`open`,descriptor:o(O,e.descriptor)})}function A(e){return typeof e==`string`&&e.trim().length>0}function j(e){return y(e,{family:`harmonyos`,backend:`harmonyos`,label:`HarmonyOS`,codec:O,startUnavailableHint:`The selected HarmonyOS transport cannot start a background hilog stream.`,cleanupFailureMessage:`HarmonyOS app-log cleanup did not settle every owned resource`,doctor:async(e,t)=>({backend:`harmonyos`,checks:{},notes:t?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`]}),process:async({host:e,device:t,input:n,signal:r})=>{let i=await M(e,r);return{resolvePid:async r=>await ve(e,{executable:i,args:a(`hdc`,`shell`,[`pidof`,n.appBundleId],[`-t`,t.id]),allowFailure:!0,timeoutMs:5e3},r),command:e=>({kind:`host`,request:{executable:i,args:a(`hdc`,`shell`,[`hilog`,`-P`,e],[`-t`,t.id]),allowFailure:!0}})}},descriptor:({artifacts:e})=>({transport:`harmony-hilog`,...e}),envelope:({input:e,device:t,owner:n,descriptor:r})=>k({sessionId:e.sessionId,device:t,owner:n,fence:e.fence,descriptor:r})})}async function M(t,n){n.throwIfAborted(),await N(async()=>await t.toolchains.prepare(`harmonyos`),n),n.throwIfAborted();let r=await N(async()=>await t.commands.which(`hdc`),n);if(n.throwIfAborted(),!r)throw new e(`TOOL_MISSING`,`hdc not found in PATH`,{hint:`Install HarmonyOS Command Line Tools, then add its sdk/default/openharmony/toolchains directory to PATH.`});return r}async function N(e,t){try{return await e()}catch(e){throw t.throwIfAborted(),e}}function P(e){let{resolveHost:t,device:n}=e,r={available:!1,reason:`Dropped-frame sampling is currently available only on Android app sessions and connected iOS device app sessions.`};return Object.freeze({perfFrames:async()=>({metric:r,sampling:r}),perfMemorySample:async({appId:e})=>({metric:e?await C(t().sampleMemory(n,e)):w(`HarmonyOS`,`bundle`),sampling:{method:`hdc-shell-proc-status`,description:`Resident memory snapshot from HarmonyOS /proc/<pid>/status. Values are reported in kilobytes.`,unit:`kB`,topConsumerLimit:1}}),perfMemorySnapshot:async({kind:e})=>({artifact:{available:!1,kind:e??`memgraph`,reason:`Memory snapshot artifacts are not supported on harmonyos.`,hint:`Use perf memory sample where supported, or run the snapshot against Android, iOS simulator, or macOS.`,support:{platform:`harmonyos`,defaultKind:`memgraph`,androidHprof:!1,memgraph:!1,heapprofd:!1}},sampling:{method:`unsupported`,description:`HarmonyOS memory snapshot capture is not available through HDC.`,artifactOnly:!0}})})}const F=Object.freeze({resourceKind:c,version:1,encode:e=>({...e}),decode:e=>e.backend===`harmony-screen-recorder`&&typeof e.fileName==`string`&&xe(e.fileName)&&e.remotePath===`/data/local/tmp/${e.fileName}`?{status:`decoded`,descriptor:Object.freeze({backend:`harmony-screen-recorder`,fileName:e.fileName,remotePath:e.remotePath})}:{status:`invalid`,message:`Invalid HarmonyOS screen-recording descriptor`}});function ye(e){let{device:n,owner:r,input:i,descriptor:a}=e;return s({resourceKind:c,sessionId:i.sessionId,device:t(n),owner:r,fence:i.fence,lifecycle:`open`,descriptor:o(F,a)})}function be(e){return F.decode(e).status===`decoded`?{status:`cleanup-pending`,reason:`manual-recovery-required`,message:`HarmonyOS recorder ownership cannot be proven after daemon restart; no recorder was stopped.`}:{status:`cleanup-pending`,reason:`manual-recovery-required`}}function xe(e){return/^agent-device-recording-[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\.mp4$/i.test(e)}function Se(e){return e.kind===`device`?Object.freeze({available:!0}):Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`HarmonyOS recording is supported on physical devices only.`})}function Ce(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await we({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async()=>({status:`unreattachable`,reason:`transport-not-reattachable`,message:`HarmonyOS recordings cannot be reattached after daemon restart.`}),screenRecordingCleanup:async e=>be(e.envelope.descriptor.body)})}async function we(t){let{host:n,device:r,owner:i,input:a,signal:o}=t;if(a.scope===`app`)throw new e(`INVALID_ARGS`,`HarmonyOS recording captures the whole physical-device screen; use --scope device or --scope system`);S(a,{scopes:[`device`,`system`],fps:!1,exportQuality:!1,hideTouches:!1},e=>`HarmonyOS recordings do not support ${e.join(`, `)}`),o.throwIfAborted(),await n.screenRecording.outputs.prepare(a.outputPath);let s=`agent-device-recording-${E()}.mp4`,c={backend:`harmony-screen-recorder`,fileName:s,remotePath:`/data/local/tmp/${s}`},l;try{l=await n.screenRecording.harmony.start(r,s,o),o.throwIfAborted()}catch(e){throw o.aborted?(await L(n,r,c).catch(()=>{}),o.reason):e}z(l,`start`);try{o.throwIfAborted()}catch(e){throw await L(n,r,c).catch(()=>{}),e}let u=Te(a),d=!1,f=async()=>{d||=(z(await n.screenRecording.harmony.stop(r),`stop`),!0)},p=b(u,{finish:async e=>await Ee(n,r,e,c,f),forceCleanup:async()=>await L(n,r,c,f)});return Object.freeze({pendingHandle:new ee(p),envelope:ye({device:r,owner:i,input:a,descriptor:c})})}function Te(e){return Object.freeze({backend:`HarmonyOS ScreenRecorder`,outPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutPath:e.clientOutputPath},startedAt:Date.now(),scope:e.scope,showTouches:!1,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},gestureEvents:[]})}async function Ee(e,t,n,r,i){await i();let a=await e.screenRecording.harmony.findMedia(t,r.fileName);if(!a)throw Error(`failed to find finalized HarmonyOS recording '${r.fileName}'`);if(!await ke(e,t,r,a))throw Error(`failed to finalize HarmonyOS recording: ${r.fileName} did not produce a non-empty media file`);try{if((await e.screenRecording.harmony.pull(t,{remotePath:r.remotePath,outputPath:n.outPath})).exitCode!==0)throw Error(`failed to retrieve HarmonyOS recording`);let i=await e.screenRecording.finalize.complete({outputPath:n.outPath,showTouches:!1,gestureEvents:n.gestureEvents,targetLabel:`HarmonyOS recording`}),o=await De(e,t,r,a);return x(n,{...i,...Oe(i.warning,o)},{stopObservation:{recorder:`confirmed`},nativePathDisposition:o===void 0?`retired`:`retirable`,showTouches:!1})}catch(n){throw await e.screenRecording.harmony.remove(t,r.remotePath).catch(()=>{}),n}}async function De(e,t,n,r){let i=[];return await I(()=>e.screenRecording.harmony.remove(t,n.remotePath))||i.push(`staging artifact`),await I(()=>e.screenRecording.harmony.removeMedia(t,r))||i.push(`media-library artifact`),i.length===0?void 0:`HarmonyOS recording completed, but cleanup was not confirmed for the ${i.join(` and `)}.`}async function I(e){try{return await e()}catch{return!1}}function Oe(e,t){let n=[e,t].filter(e=>e!==void 0).join(` `);return n.length===0?{}:{warning:n}}async function ke(e,t,n,r){let i;for(let a=0;a<40;a+=1){if(await e.screenRecording.harmony.remove(t,n.remotePath).catch(()=>{}),await e.screenRecording.harmony.stageMedia(t,{mediaUri:r,remotePath:n.remotePath})){let r=await e.screenRecording.harmony.stagedFileSize(t,n.remotePath);if(r!==void 0&&r>0&&r===i)return!0;i=r!==void 0&&r>0?r:void 0}else i=void 0;a<39&&await e.clock.sleep(250)}return!1}async function L(e,t,n,r=async()=>{z(await e.screenRecording.harmony.stop(t),`stop`)}){let i=[await R(r),await R(async()=>{if(!await e.screenRecording.harmony.remove(t,n.remotePath))throw Error(`HarmonyOS recording staging artifact removal was not confirmed`)}),await R(async()=>await Ae(e,t,n.fileName))].find(e=>e!==void 0);return i===void 0?{status:`cleaned`}:{status:`cleanup-pending`,reason:`transport-failed`,message:i instanceof Error?i.message:`HarmonyOS recording cleanup failed`}}async function Ae(e,t,n){let r=await e.screenRecording.harmony.findMedia(t,n);if(r&&!await e.screenRecording.harmony.removeMedia(t,r))throw Error(`HarmonyOS recording media removal was not confirmed`)}async function R(e){try{await e();return}catch(e){return e}}function z(e,t){if(e.exitCode===0&&e.stdout.includes(`start ability successfully`))return;let n=e.stdout.trim()||e.stderr.trim()||`hdc exit ${e.exitCode}`;throw Error(`failed to ${t} HarmonyOS screen recording: ${n}`)}async function B(t,n){n.throwIfAborted();let{runHarmonyShell:r}=await import(`./hdc.js`),i=await r(t,[`aa`,`dump`,`-l`],{timeoutMs:15e3,signal:n});n.throwIfAborted();let a=je(i.stdout);if(!a)throw new e(`COMMAND_FAILED`,`Could not determine the foreground HarmonyOS app`,{hint:`Open an app on the target, then retry appstate.`});return a}function je(e){let t=e.split(/(?=^\s*Mission ID #)/m);for(let e of t){if(!/\bstate #FOREGROUND\b/.test(e))continue;let t=e.match(/mission name #\[#([^:]+):[^:]*:([^\]]+)]/);if(!t)continue;let[,n,r]=t;if(!(!n||!r))return{package:n,activity:r}}}const Me=Object.freeze({available:!0}),Ne=Object.freeze({available:!1,reason:`unsupported-device-kind`}),V=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function H(e){let t=e.kind===`emulator`||e.kind===`device`?Me:Ne;return Object.freeze({deployApp:t,materializeAppSource:V,deployMaterializedApp:V,sendPushNotification:V,uninstallApp:V})}function Pe(e){return H(e.device).deployApp.available?Object.freeze({deployApp:async t=>await Fe(e.commands,e.device,t,e.signal)}):Object.freeze({})}async function Fe(t,n,r,i){let a=await Ie(t,r.appPath,i)??r.app.trim();if(!a)throw new e(`INVALID_ARGS`,`Could not determine the bundle name from the HAP archive`,{hint:`Pass the HarmonyOS bundle name before the HAP path, or provide a valid HAP containing module.json.`});return await ze(t,n,[`install`,`-r`,r.appPath],i,18e4),r.replaceExisting&&(await D(1e3,void 0,{signal:i}),await Le(t,n,a,i)),{packageName:a,launchTarget:a}}async function Ie(e,t,n){let r=await e.run({executable:`unzip`,args:[`-p`,t,`module.json`],allowFailure:!0,timeoutMs:15e3},n);if(r.exitCode===0&&r.stdout.trim().length!==0)try{return JSON.parse(r.stdout).app?.bundleName?.trim()||void 0}catch{return}}async function Le(t,n,r,i){let a=Re((await U(t,n,[`bm`,`dump`,`-n`,r],i)).stdout);if(!a)throw new e(`COMMAND_FAILED`,`Could not determine a launchable ability for ${r}`,{hint:`Check that the HarmonyOS bundle exposes a main ability.`});await U(t,n,[`aa`,`start`,`-b`,r,...a.module?[`-m`,a.module]:[],`-a`,a.ability],i)}function Re(e){let t=e.indexOf(`{`);if(t!==-1)try{let n=JSON.parse(e.slice(t)).hapModuleInfos?.find(e=>e.mainElementName);return n?.mainElementName?{ability:n.mainElementName,...n.moduleName?{module:n.moduleName}:{}}:void 0}catch{return}}async function ze(e,t,n,r,i=15e3){return await e.run({executable:`hdc`,args:[`-t`,t.id,...n],timeoutMs:i},r)}async function U(e,t,n,r,i=15e3){return await e.run({executable:`hdc`,args:a(`hdc`,`shell`,n,[`-t`,t.id]),timeoutMs:i},r)}const W=i(`harmonyos`),Be=r(`unsupported-platform-leaf`,`HarmonyOS reads element text from the captured tree only.`),Ve=r(`unsupported-device-kind`,`focus is supported on HarmonyOS emulators and physical devices.`),G=Object.freeze({available:!0}),K=r(`unsupported-platform-leaf`),He=r(`unsupported-device-kind`,`HarmonyOS appstate is supported only for HarmonyOS emulators and devices.`),Ue=r(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),q=Object.freeze({available:!0}),We=r(`unsupported-device-kind`,`open is supported only for HarmonyOS emulators and devices.`),Ge=r(`unsupported-device-kind`,`close is supported only for HarmonyOS emulators and devices.`),Ke=r(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),J=r(`unsupported-device-kind`,`snapshot is supported only for HarmonyOS emulators and devices.`),qe=r(`unsupported-device-kind`,`screenshot is supported only for HarmonyOS emulators and devices.`),Je=r(`unsupported-platform-leaf`,`Re-run without --actions, or target an iOS simulator.`),Ye=r(`unsupported-platform-leaf`,`viewport resizes web targets only (--platform web).`);function Xe(e){let t=Ze(e),n=Qe(e);return u({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:K,clearRuntimeHints:K,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:Ue,configureProviderPortReverse:Ke})}function Ze(e){return e.kind===`emulator`||e.kind===`device`?q:We}function Qe(e){return e.kind===`emulator`||e.kind===`device`?q:Ge}const Y=r(`unsupported-device-kind`,`Gestures are supported on HarmonyOS emulators and physical devices.`),$e=r(`unsupported-platform-leaf`),et=r(`unsupported-platform-leaf`,f);function X(e){return e.kind===`emulator`||e.kind===`device`?G:Y}function Z(e){return e.kind===`emulator`||e.kind===`device`?G:Ve}const Q=r(`unsupported-platform-leaf`),tt=r(`unsupported-platform-leaf`,`HarmonyOS supports settings clear-app-state only.`),nt=r(`unsupported-platform-leaf`,`keyboard status/get is not available through the public HarmonyOS HDC API; use keyboard dismiss or enter`),$=r(`unsupported-platform-leaf`,`audio is supported for web browser sessions, macOS sessions, iOS simulators, and Android emulators on macOS hosts`);function rt(e){let t=j(e),r=async e=>{let n=await t.inspectFacts(e),r=H(e),i=Se(e);return Object.freeze({device:n.device,operations:{...n.operations,...r,appState:e.kind===`simulator`?He:G,networkDump:K,screenRecordingStart:i,screenRecordingReattach:i,screenRecordingCleanup:i,...ie({capture:e.kind===`emulator`||e.kind===`device`?G:J,customActions:Je,withoutActiveApp:e.kind===`emulator`||e.kind===`device`?G:J}),...ne({capture:e.kind===`emulator`||e.kind===`device`?G:qe}),...ae({findText:J,querySelector:J}),...ce({setViewport:Ye}),...ue({focus:Z(e)}),...re({unsupported:Y,plan:X(e),directionalFling:X(e),multiTouch:$e,targetAuthoredDrag:et,viewport:X(e)}),...le({scroll:X(e)}),...oe({type:Z(e)}),...d({unsupported:K,tap:Z(e),longPress:Z(e),fill:Z(e)}),...m({readTextAtPoint:Be}),...te({back:Z(e)}),...h({unsupported:Q,home:Z(e),appSwitcher:Z(e)}),setFoldPose:Q,sendTelephonyEvent:Q,...pe({triggerAppEvent:Q}),...ge({target:Z(e),unsupported:tt,write:{"clear-app-state":G}}),...me({read:Q,wait:Q,accept:Q,dismiss:Q}),...v({orientation:Q}),...fe({tvRemote:Q}),..._({unsupported:Q,status:nt,dismiss:Z(e),enter:Z(e)}),...de({unsupported:Q}),...p({capture:$,query:$}),...se({frames:Z(e),memorySample:Z(e),memorySnapshot:Z(e),nativeCapture:Q,profileReport:Q}),ensureReady:G,bootTarget:K,bootTargetHeadless:K,listApps:G,...Xe(e),shutdownTarget:K}})};return Object.freeze({owner:W,ownsDevice:e=>e.platform===`harmonyos`,inspectFacts:r,bind:async i=>{let a=await t.bind(i),o=await r(i.device),s=o.operations.screenRecordingStart;return Object.freeze({device:a.device,owner:W,facts:o,operations:Object.freeze({...a.operations,...Pe({commands:e.commands,device:i.device,signal:i.scope.signal}),...o.operations.appState.available?{appState:async()=>await B(i.device,i.scope.signal)}:{},ensureReady:async()=>({...i.device,booted:!0}),...s.available?Ce({host:e,device:i.device,owner:W,signal:i.scope.signal}):{},...o.operations.captureSnapshot.available?g({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},..._e({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:o.operations,pause:async t=>await e.clock.sleep(t,i.scope.signal)}),...n(o.operations.perfFrames,()=>P({resolveHost:()=>e.perf.harmony,device:i.device})),listApps:async e=>{i.scope.signal.throwIfAborted();let{listHarmonyApps:t}=await import(`./app-lifecycle2.js`);return(await t(e.device,e.filter,{signal:i.scope.signal})).map(e=>({id:e.package,name:e.name}))},...l(he({owner:`HarmonyOS`,openTargetIdentity:`bundle-id`,host:e.localInteractors,device:i.device,signal:i.scope.signal}),o.operations)}),[Symbol.asyncDispose]:async()=>await a[Symbol.asyncDispose]()})},shutdown:async()=>await t.shutdown()})}export{rt as createHarmonyPlatformRuntime};
1
+ import{R as e}from"./sdk-contracts.js";import{W as t}from"./sdk-device.js";import{Tn as n,vn as r,wn as i}from"./sdk-batch.js";import{n as a}from"./device-shell.js";import{i as o,n as s}from"./durable-resource.js";import{n as c}from"./screen-recording-runtime.js";import{n as l,t as u}from"./application-lifecycle-runtime.js";import{n as ee}from"./async-lifecycle.js";import{i as d}from"./touch-runtime.js";import{r as f}from"./gesture-admission.js";import{B as p,C as te,I as ne,K as re,M as ie,N as ae,O as oe,R as se,T as ce,U as le,Y as ue,Z as m,_ as h,k as g,l as _,o as v,p as de,r as fe,v as pe,x as me}from"./tv-remote-runtime.js";import{r as he,u as ge}from"./application-lifecycle-interaction.js";import{t as _e}from"./local-interactor-operation-set.js";import{n as ve,t as y}from"./src4.js";import{n as b,t as x}from"./screen-recording-completion.js";import{t as S}from"./screen-recording-options.js";import{i as C,n as w}from"./perf-runtime-operation-builder.js";import{t as T}from"./app-log-runtime.js";import{randomUUID as E}from"node:crypto";import{setTimeout as D}from"node:timers/promises";const O=Object.freeze({resourceKind:T,version:1,encode:e=>({...e}),decode:e=>e.transport!==`harmony-hilog`||!A(e.outputPath)||!A(e.pidPath)?{status:`invalid`,message:`Invalid HarmonyOS app-log descriptor`}:{status:`decoded`,descriptor:Object.freeze({transport:`harmony-hilog`,outputPath:e.outputPath,pidPath:e.pidPath})}});function k(e){return s({resourceKind:T,sessionId:e.sessionId,device:{id:e.device.id,family:`harmonyos`,kind:e.device.kind,...e.device.target===void 0?{}:{target:e.device.target}},owner:e.owner,fence:e.fence,lifecycle:`open`,descriptor:o(O,e.descriptor)})}function A(e){return typeof e==`string`&&e.trim().length>0}function j(e){return y(e,{family:`harmonyos`,backend:`harmonyos`,label:`HarmonyOS`,codec:O,startUnavailableHint:`The selected HarmonyOS transport cannot start a background hilog stream.`,cleanupFailureMessage:`HarmonyOS app-log cleanup did not settle every owned resource`,doctor:async(e,t)=>({backend:`harmonyos`,checks:{},notes:t?[]:[`No app bundle is tracked in this session. Run open <app> first for app-scoped logs.`]}),process:async({host:e,device:t,input:n,signal:r})=>{let i=await M(e,r);return{resolvePid:async r=>await ve(e,{executable:i,args:a(`hdc`,`shell`,[`pidof`,n.appBundleId],[`-t`,t.id]),allowFailure:!0,timeoutMs:5e3},r),command:e=>({kind:`host`,request:{executable:i,args:a(`hdc`,`shell`,[`hilog`,`-P`,e],[`-t`,t.id]),allowFailure:!0}})}},descriptor:({artifacts:e})=>({transport:`harmony-hilog`,...e}),envelope:({input:e,device:t,owner:n,descriptor:r})=>k({sessionId:e.sessionId,device:t,owner:n,fence:e.fence,descriptor:r})})}async function M(t,n){n.throwIfAborted(),await N(async()=>await t.toolchains.prepare(`harmonyos`),n),n.throwIfAborted();let r=await N(async()=>await t.commands.which(`hdc`),n);if(n.throwIfAborted(),!r)throw new e(`TOOL_MISSING`,`hdc not found in PATH`,{hint:`Install HarmonyOS Command Line Tools, then add its sdk/default/openharmony/toolchains directory to PATH.`});return r}async function N(e,t){try{return await e()}catch(e){throw t.throwIfAborted(),e}}function P(e){let{resolveHost:t,device:n}=e,r={available:!1,reason:`Dropped-frame sampling is currently available only on Android app sessions and connected iOS device app sessions.`};return Object.freeze({perfFrames:async()=>({metric:r,sampling:r}),perfMemorySample:async({appId:e})=>({metric:e?await C(t().sampleMemory(n,e)):w(`HarmonyOS`,`bundle`),sampling:{method:`hdc-shell-proc-status`,description:`Resident memory snapshot from HarmonyOS /proc/<pid>/status. Values are reported in kilobytes.`,unit:`kB`,topConsumerLimit:1}}),perfMemorySnapshot:async({kind:e})=>({artifact:{available:!1,kind:e??`memgraph`,reason:`Memory snapshot artifacts are not supported on harmonyos.`,hint:`Use perf memory sample where supported, or run the snapshot against Android, iOS simulator, or macOS.`,support:{platform:`harmonyos`,defaultKind:`memgraph`,androidHprof:!1,memgraph:!1,heapprofd:!1}},sampling:{method:`unsupported`,description:`HarmonyOS memory snapshot capture is not available through HDC.`,artifactOnly:!0}})})}const F=Object.freeze({resourceKind:c,version:1,encode:e=>({...e}),decode:e=>e.backend===`harmony-screen-recorder`&&typeof e.fileName==`string`&&xe(e.fileName)&&e.remotePath===`/data/local/tmp/${e.fileName}`?{status:`decoded`,descriptor:Object.freeze({backend:`harmony-screen-recorder`,fileName:e.fileName,remotePath:e.remotePath})}:{status:`invalid`,message:`Invalid HarmonyOS screen-recording descriptor`}});function ye(e){let{device:n,owner:r,input:i,descriptor:a}=e;return s({resourceKind:c,sessionId:i.sessionId,device:t(n),owner:r,fence:i.fence,lifecycle:`open`,descriptor:o(F,a)})}function be(e){return F.decode(e).status===`decoded`?{status:`cleanup-pending`,reason:`manual-recovery-required`,message:`HarmonyOS recorder ownership cannot be proven after daemon restart; no recorder was stopped.`}:{status:`cleanup-pending`,reason:`manual-recovery-required`}}function xe(e){return/^agent-device-recording-[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\.mp4$/i.test(e)}function Se(e){return e.kind===`device`?Object.freeze({available:!0}):Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`HarmonyOS recording is supported on physical devices only.`})}function Ce(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await we({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async()=>({status:`unreattachable`,reason:`transport-not-reattachable`,message:`HarmonyOS recordings cannot be reattached after daemon restart.`}),screenRecordingCleanup:async e=>be(e.envelope.descriptor.body)})}async function we(t){let{host:n,device:r,owner:i,input:a,signal:o}=t;if(a.scope===`app`)throw new e(`INVALID_ARGS`,`HarmonyOS recording captures the whole physical-device screen; use --scope device or --scope system`);S(a,{scopes:[`device`,`system`],fps:!1,exportQuality:!1,hideTouches:!1},e=>`HarmonyOS recordings do not support ${e.join(`, `)}`),o.throwIfAborted(),await n.screenRecording.outputs.prepare(a.outputPath);let s=`agent-device-recording-${E()}.mp4`,c={backend:`harmony-screen-recorder`,fileName:s,remotePath:`/data/local/tmp/${s}`},l;try{l=await n.screenRecording.harmony.start(r,s,o),o.throwIfAborted()}catch(e){throw o.aborted?(await L(n,r,c).catch(()=>{}),o.reason):e}z(l,`start`);try{o.throwIfAborted()}catch(e){throw await L(n,r,c).catch(()=>{}),e}let u=Te(a),d=!1,f=async()=>{d||=(z(await n.screenRecording.harmony.stop(r),`stop`),!0)},p=b(u,{finish:async e=>await Ee(n,r,e,c,f),forceCleanup:async()=>await L(n,r,c,f)});return Object.freeze({pendingHandle:new ee(p),envelope:ye({device:r,owner:i,input:a,descriptor:c})})}function Te(e){return Object.freeze({backend:`HarmonyOS ScreenRecorder`,outPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutPath:e.clientOutputPath},startedAt:Date.now(),scope:e.scope,showTouches:!1,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},gestureEvents:[]})}async function Ee(e,t,n,r,i){await i();let a=await e.screenRecording.harmony.findMedia(t,r.fileName);if(!a)throw Error(`failed to find finalized HarmonyOS recording '${r.fileName}'`);if(!await ke(e,t,r,a))throw Error(`failed to finalize HarmonyOS recording: ${r.fileName} did not produce a non-empty media file`);try{if((await e.screenRecording.harmony.pull(t,{remotePath:r.remotePath,outputPath:n.outPath})).exitCode!==0)throw Error(`failed to retrieve HarmonyOS recording`);let i=await e.screenRecording.finalize.complete({outputPath:n.outPath,showTouches:!1,gestureEvents:n.gestureEvents,targetLabel:`HarmonyOS recording`}),o=await De(e,t,r,a);return x(n,{...i,...Oe(i.warning,o)},{stopObservation:{recorder:`confirmed`},nativePathDisposition:o===void 0?`retired`:`retirable`,showTouches:!1})}catch(n){throw await e.screenRecording.harmony.remove(t,r.remotePath).catch(()=>{}),n}}async function De(e,t,n,r){let i=[];return await I(()=>e.screenRecording.harmony.remove(t,n.remotePath))||i.push(`staging artifact`),await I(()=>e.screenRecording.harmony.removeMedia(t,r))||i.push(`media-library artifact`),i.length===0?void 0:`HarmonyOS recording completed, but cleanup was not confirmed for the ${i.join(` and `)}.`}async function I(e){try{return await e()}catch{return!1}}function Oe(e,t){let n=[e,t].filter(e=>e!==void 0).join(` `);return n.length===0?{}:{warning:n}}async function ke(e,t,n,r){let i;for(let a=0;a<40;a+=1){if(await e.screenRecording.harmony.remove(t,n.remotePath).catch(()=>{}),await e.screenRecording.harmony.stageMedia(t,{mediaUri:r,remotePath:n.remotePath})){let r=await e.screenRecording.harmony.stagedFileSize(t,n.remotePath);if(r!==void 0&&r>0&&r===i)return!0;i=r!==void 0&&r>0?r:void 0}else i=void 0;a<39&&await e.clock.sleep(250)}return!1}async function L(e,t,n,r=async()=>{z(await e.screenRecording.harmony.stop(t),`stop`)}){let i=[await R(r),await R(async()=>{if(!await e.screenRecording.harmony.remove(t,n.remotePath))throw Error(`HarmonyOS recording staging artifact removal was not confirmed`)}),await R(async()=>await Ae(e,t,n.fileName))].find(e=>e!==void 0);return i===void 0?{status:`cleaned`}:{status:`cleanup-pending`,reason:`transport-failed`,message:i instanceof Error?i.message:`HarmonyOS recording cleanup failed`}}async function Ae(e,t,n){let r=await e.screenRecording.harmony.findMedia(t,n);if(r&&!await e.screenRecording.harmony.removeMedia(t,r))throw Error(`HarmonyOS recording media removal was not confirmed`)}async function R(e){try{await e();return}catch(e){return e}}function z(e,t){if(e.exitCode===0&&e.stdout.includes(`start ability successfully`))return;let n=e.stdout.trim()||e.stderr.trim()||`hdc exit ${e.exitCode}`;throw Error(`failed to ${t} HarmonyOS screen recording: ${n}`)}async function B(t,n){n.throwIfAborted();let{runHarmonyShell:r}=await import(`./hdc.js`),i=await r(t,[`aa`,`dump`,`-l`],{timeoutMs:15e3,signal:n});n.throwIfAborted();let a=je(i.stdout);if(!a)throw new e(`COMMAND_FAILED`,`Could not determine the foreground HarmonyOS app`,{hint:`Open an app on the target, then retry appstate.`});return a}function je(e){let t=e.split(/(?=^\s*Mission ID #)/m);for(let e of t){if(!/\bstate #FOREGROUND\b/.test(e))continue;let t=e.match(/mission name #\[#([^:]+):[^:]*:([^\]]+)]/);if(!t)continue;let[,n,r]=t;if(!(!n||!r))return{package:n,activity:r}}}const Me=Object.freeze({available:!0}),Ne=Object.freeze({available:!1,reason:`unsupported-device-kind`}),V=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function H(e){let t=e.kind===`emulator`||e.kind===`device`?Me:Ne;return Object.freeze({deployApp:t,materializeAppSource:V,deployMaterializedApp:V,sendPushNotification:V,uninstallApp:V})}function Pe(e){return H(e.device).deployApp.available?Object.freeze({deployApp:async t=>await Fe(e.commands,e.device,t,e.signal)}):Object.freeze({})}async function Fe(t,n,r,i){let a=await Ie(t,r.appPath,i)??r.app.trim();if(!a)throw new e(`INVALID_ARGS`,`Could not determine the bundle name from the HAP archive`,{hint:`Pass the HarmonyOS bundle name before the HAP path, or provide a valid HAP containing module.json.`});return await ze(t,n,[`install`,`-r`,r.appPath],i,18e4),r.replaceExisting&&(await D(1e3,void 0,{signal:i}),await Le(t,n,a,i)),{packageName:a,launchTarget:a}}async function Ie(e,t,n){let r=await e.run({executable:`unzip`,args:[`-p`,t,`module.json`],allowFailure:!0,timeoutMs:15e3},n);if(r.exitCode===0&&r.stdout.trim().length!==0)try{return JSON.parse(r.stdout).app?.bundleName?.trim()||void 0}catch{return}}async function Le(t,n,r,i){let a=Re((await U(t,n,[`bm`,`dump`,`-n`,r],i)).stdout);if(!a)throw new e(`COMMAND_FAILED`,`Could not determine a launchable ability for ${r}`,{hint:`Check that the HarmonyOS bundle exposes a main ability.`});await U(t,n,[`aa`,`start`,`-b`,r,...a.module?[`-m`,a.module]:[],`-a`,a.ability],i)}function Re(e){let t=e.indexOf(`{`);if(t!==-1)try{let n=JSON.parse(e.slice(t)).hapModuleInfos?.find(e=>e.mainElementName);return n?.mainElementName?{ability:n.mainElementName,...n.moduleName?{module:n.moduleName}:{}}:void 0}catch{return}}async function ze(e,t,n,r,i=15e3){return await e.run({executable:`hdc`,args:[`-t`,t.id,...n],timeoutMs:i},r)}async function U(e,t,n,r,i=15e3){return await e.run({executable:`hdc`,args:a(`hdc`,`shell`,n,[`-t`,t.id]),timeoutMs:i},r)}const W=r(`harmonyos`),Be=i(`unsupported-platform-leaf`,`HarmonyOS reads element text from the captured tree only.`),Ve=i(`unsupported-device-kind`,`focus is supported on HarmonyOS emulators and physical devices.`),G=Object.freeze({available:!0}),K=i(`unsupported-platform-leaf`),He=i(`unsupported-device-kind`,`HarmonyOS appstate is supported only for HarmonyOS emulators and devices.`),Ue=i(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),q=Object.freeze({available:!0}),We=i(`unsupported-device-kind`,`open is supported only for HarmonyOS emulators and devices.`),Ge=i(`unsupported-device-kind`,`close is supported only for HarmonyOS emulators and devices.`),Ke=i(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),J=i(`unsupported-device-kind`,`snapshot is supported only for HarmonyOS emulators and devices.`),qe=i(`unsupported-device-kind`,`screenshot is supported only for HarmonyOS emulators and devices.`),Je=i(`unsupported-platform-leaf`,`Re-run without --actions, or target an iOS simulator.`),Ye=i(`unsupported-platform-leaf`,`viewport resizes web targets only (--platform web).`);function Xe(e){let t=Ze(e),n=Qe(e);return u({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:K,clearRuntimeHints:K,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:Ue,configureProviderPortReverse:Ke})}function Ze(e){return e.kind===`emulator`||e.kind===`device`?q:We}function Qe(e){return e.kind===`emulator`||e.kind===`device`?q:Ge}const Y=i(`unsupported-device-kind`,`Gestures are supported on HarmonyOS emulators and physical devices.`),$e=i(`unsupported-platform-leaf`),et=i(`unsupported-platform-leaf`,f);function X(e){return e.kind===`emulator`||e.kind===`device`?G:Y}function Z(e){return e.kind===`emulator`||e.kind===`device`?G:Ve}const Q=i(`unsupported-platform-leaf`),tt=i(`unsupported-platform-leaf`,`HarmonyOS supports settings clear-app-state only.`),nt=i(`unsupported-platform-leaf`,`keyboard status/get is not available through the public HarmonyOS HDC API; use keyboard dismiss or enter`),$=i(`unsupported-platform-leaf`,`audio is supported for web browser sessions, macOS sessions, iOS simulators, and Android emulators on macOS hosts`);function rt(e){let t=j(e),r=async e=>{let n=await t.inspectFacts(e),r=H(e),i=Se(e);return Object.freeze({device:n.device,operations:{...n.operations,...r,appState:e.kind===`simulator`?He:G,networkDump:K,screenRecordingStart:i,screenRecordingReattach:i,screenRecordingCleanup:i,...ie({capture:e.kind===`emulator`||e.kind===`device`?G:J,customActions:Je,withoutActiveApp:e.kind===`emulator`||e.kind===`device`?G:J}),...ne({capture:e.kind===`emulator`||e.kind===`device`?G:qe}),...ae({findText:J,querySelector:J}),...ce({setViewport:Ye}),...ue({focus:Z(e)}),...re({unsupported:Y,plan:X(e),directionalFling:X(e),multiTouch:$e,targetAuthoredDrag:et,viewport:X(e)}),...le({scroll:X(e)}),...oe({type:Z(e)}),...d({unsupported:K,tap:Z(e),longPress:Z(e),fill:Z(e)}),...m({readTextAtPoint:Be}),...te({back:Z(e)}),...h({unsupported:Q,home:Z(e),appSwitcher:Z(e)}),setFoldPose:Q,sendTelephonyEvent:Q,...pe({triggerAppEvent:Q}),...ge({target:Z(e),unsupported:tt,write:{"clear-app-state":G}}),...me({read:Q,wait:Q,accept:Q,dismiss:Q}),...v({orientation:Q}),...fe({tvRemote:Q}),..._({unsupported:Q,status:nt,dismiss:Z(e),enter:Z(e)}),...de({unsupported:Q}),...p({capture:$,query:$}),...se({frames:Z(e),memorySample:Z(e),memorySnapshot:Z(e),nativeCapture:Q,profileReport:Q}),ensureReady:G,bootTarget:K,bootTargetHeadless:K,listApps:G,...Xe(e),shutdownTarget:K}})};return Object.freeze({owner:W,ownsDevice:e=>e.platform===`harmonyos`,inspectFacts:r,bind:async i=>{let a=await t.bind(i),o=await r(i.device),s=o.operations.screenRecordingStart;return Object.freeze({device:a.device,owner:W,facts:o,operations:Object.freeze({...a.operations,...Pe({commands:e.commands,device:i.device,signal:i.scope.signal}),...o.operations.appState.available?{appState:async()=>await B(i.device,i.scope.signal)}:{},ensureReady:async()=>({...i.device,booted:!0}),...s.available?Ce({host:e,device:i.device,owner:W,signal:i.scope.signal}):{},...o.operations.captureSnapshot.available?g({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},..._e({device:i.device,signal:i.scope.signal,resolveInteractor:e.localInteractors.resolve,facts:o.operations,pause:async t=>await e.clock.sleep(t,i.scope.signal)}),...n(o.operations.perfFrames,()=>P({resolveHost:()=>e.perf.harmony,device:i.device})),listApps:async e=>{i.scope.signal.throwIfAborted();let{listHarmonyApps:t}=await import(`./app-lifecycle2.js`);return(await t(e.device,e.filter,{signal:i.scope.signal})).map(e=>({id:e.package,name:e.name}))},...l(he({owner:`HarmonyOS`,openTargetIdentity:`bundle-id`,host:e.localInteractors,device:i.device,signal:i.scope.signal}),o.operations)}),[Symbol.asyncDispose]:async()=>await a[Symbol.asyncDispose]()})},shutdown:async()=>await t.shutdown()})}export{rt as createHarmonyPlatformRuntime};
@@ -1 +1 @@
1
- import{R as e}from"./sdk-contracts.js";import{Sn as t,gn as n,xn as r}from"./sdk-batch.js";import{n as i,t as a}from"./application-lifecycle-runtime.js";import{i as o}from"./touch-runtime.js";import{r as s}from"./gesture-admission.js";import{C as c,I as l,K as u,M as d,O as f,U as p,Y as m,Z as h,_ as g,j as _,p as v}from"./tv-remote-runtime.js";import{r as y}from"./application-lifecycle-interaction.js";import{t as b}from"./local-interactor-operation-set.js";import{r as x}from"./platform-runtime-unavailable.js";const S=Object.freeze({available:!0}),C=n(`linux`),w=t(`unsupported-platform-leaf`),T=t(`unsupported-device-kind`),E=t(`unsupported-device-kind`,`focus is supported only for the Linux desktop device.`),D=t(`unsupported-device-kind`,`type is supported only for the Linux desktop device.`),O=t(`unsupported-device-kind`,`Gestures are supported only for the Linux desktop device.`),k=t(`unsupported-device-kind`,`scroll is supported only for the Linux desktop device.`),A=t(`unsupported-platform-leaf`),j=t(`unsupported-platform-leaf`),M=t(`unsupported-platform-leaf`,s),N=t(`unsupported-platform-leaf`),P=t(`unsupported-platform-leaf`,`Runtime hints are supported only for local iOS-family simulators and Android devices.`),F=t(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),I=t(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),L=t(`unsupported-device-kind`,`open is supported only for the Linux desktop device.`),R=t(`unsupported-device-kind`,`close is supported only for the Linux desktop device.`),z=t(`unsupported-device-kind`,`snapshot is supported only for the Linux desktop device.`),B=t(`unsupported-device-kind`,`screenshot is supported only for the Linux desktop device.`),V=t(`unsupported-platform-leaf`,`Re-run without --actions, or target an iOS simulator.`),H=t(`unsupported-device-kind`,`back is supported only for the Linux desktop device.`),U=t(`unsupported-device-kind`,`home is supported only for the Linux desktop device.`),W=t(`unsupported-device-kind`,`clipboard is supported only for the Linux desktop device.`),G=w,K=t(`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 n=>{if(n.intent.kind===`exact-owner`&&!r(n.intent.owner,C))throw new e(`UNSUPPORTED_OPERATION`,`Linux runtime owner identity does not match`);if(n.device.platform!==`linux`)throw new e(`UNSUPPORTED_PLATFORM`,`Linux runtime cannot bind this device`);let a=Y(n.device),o=y({owner:`Linux`,openTargetIdentity:`app-name`,host:t.localInteractors,device:n.device,signal:n.scope.signal});return Object.freeze({device:n.device,owner:C,facts:a,operations:Object.freeze({...i(o,a.operations),...a.operations.captureSnapshot.available?Q(t,n):{},...J(t,n,a)}),[Symbol.asyncDispose]:async()=>void 0})},shutdown:async()=>void 0})}function J(e,t,n){let r={device:t.device,signal:t.scope.signal,resolveInteractor:e.localInteractors.resolve};return b({...r,facts:n.operations,pause:async n=>await e.clock.sleep(n,t.scope.signal)})}function Y(e){let t=e.kind===`device`?S:L,n=e.kind===`device`?S:R,r=x(e,C,{appLog:w,network:w,screenshot:B,snapshot:z,viewport:w,focus:E,gesture:O,scroll:k,typeText:D,touch:E,elementText:T,back:H,orientation:G,tvRemote:G,clipboard:W,systemButton:G,fold:G,telephony:G,triggerAppEvent:G,settings:G,readAlert:G,awaitAlert:G,acceptAlert:G,dismissAlert:G,keyboard:G,audioProbeCapture:K,audioProbeQuery:K,perf:G,readiness:w,lifecycle:a({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:P,clearRuntimeHints:P,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:F,configureProviderPortReverse:I})});return Object.freeze({device:r.device,operations:{...r.operations,...d({capture:X(e,z),customActions:V,withoutActiveApp:X(e,z)}),...l({capture:X(e,B)}),...m({focus:X(e,E)}),...u({unsupported:O,plan:X(e,O),directionalFling:A,multiTouch:j,targetAuthoredDrag:M,viewport:N}),...p({scroll:X(e,k)}),...f({type:X(e,D)}),...Z(e),...h({readTextAtPoint:X(e,T)}),...c({back:X(e,H)}),...g({unsupported:G,home:X(e,U)}),...v({unsupported:W,read:X(e,W),write:X(e,W)})}})}function X(e,t){return e.kind===`device`?S:t}function Z(e){let t=e.kind===`device`?S:E;return o({unsupported:w,tap:t,longPress:t,fill:t})}function Q(e,t){let n=async n=>await e.snapshot.captureSurface(t.device,n.options,_(t.scope.signal,n));return Object.freeze({captureSnapshot:n,captureSnapshotWithCustomActions:n,captureSnapshotWithoutActiveApp:n})}export{q as createLinuxPlatformRuntime};
1
+ import{R as e}from"./sdk-contracts.js";import{Cn as t,vn as n,wn as r}from"./sdk-batch.js";import{n as i,t as a}from"./application-lifecycle-runtime.js";import{i as o}from"./touch-runtime.js";import{r as s}from"./gesture-admission.js";import{C as c,I as l,K as u,M as d,O as f,U as p,Y as m,Z as h,_ as g,j as _,p as v}from"./tv-remote-runtime.js";import{r as y}from"./application-lifecycle-interaction.js";import{t as b}from"./local-interactor-operation-set.js";import{r as x}from"./platform-runtime-unavailable.js";const S=Object.freeze({available:!0}),C=n(`linux`),w=r(`unsupported-platform-leaf`),T=r(`unsupported-device-kind`),E=r(`unsupported-device-kind`,`focus is supported only for the Linux desktop device.`),D=r(`unsupported-device-kind`,`type is supported only for the Linux desktop device.`),O=r(`unsupported-device-kind`,`Gestures are supported only for the Linux desktop device.`),k=r(`unsupported-device-kind`,`scroll is supported only for the Linux desktop device.`),A=r(`unsupported-platform-leaf`),j=r(`unsupported-platform-leaf`),M=r(`unsupported-platform-leaf`,s),N=r(`unsupported-platform-leaf`),P=r(`unsupported-platform-leaf`,`Runtime hints are supported only for local iOS-family simulators and Android devices.`),F=r(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),I=r(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),L=r(`unsupported-device-kind`,`open is supported only for the Linux desktop device.`),R=r(`unsupported-device-kind`,`close is supported only for the Linux desktop device.`),z=r(`unsupported-device-kind`,`snapshot is supported only for the Linux desktop device.`),B=r(`unsupported-device-kind`,`screenshot is supported only for the Linux desktop device.`),V=r(`unsupported-platform-leaf`,`Re-run without --actions, or target an iOS simulator.`),H=r(`unsupported-device-kind`,`back is supported only for the Linux desktop device.`),U=r(`unsupported-device-kind`,`home is supported only for the Linux desktop device.`),W=r(`unsupported-device-kind`,`clipboard is supported only for the Linux desktop device.`),G=w,K=r(`unsupported-platform-leaf`,`audio is supported for web browser sessions, macOS sessions, iOS simulators, and Android emulators on macOS hosts`);function q(n){return Object.freeze({owner:C,ownsDevice:e=>e.platform===`linux`,inspectFacts:async e=>Y(e),bind:async r=>{if(r.intent.kind===`exact-owner`&&!t(r.intent.owner,C))throw new e(`UNSUPPORTED_OPERATION`,`Linux runtime owner identity does not match`);if(r.device.platform!==`linux`)throw new e(`UNSUPPORTED_PLATFORM`,`Linux runtime cannot bind this device`);let a=Y(r.device),o=y({owner:`Linux`,openTargetIdentity:`app-name`,host:n.localInteractors,device:r.device,signal:r.scope.signal});return Object.freeze({device:r.device,owner:C,facts:a,operations:Object.freeze({...i(o,a.operations),...a.operations.captureSnapshot.available?Q(n,r):{},...J(n,r,a)}),[Symbol.asyncDispose]:async()=>void 0})},shutdown:async()=>void 0})}function J(e,t,n){let r={device:t.device,signal:t.scope.signal,resolveInteractor:e.localInteractors.resolve};return b({...r,facts:n.operations,pause:async n=>await e.clock.sleep(n,t.scope.signal)})}function Y(e){let t=e.kind===`device`?S:L,n=e.kind===`device`?S:R,r=x(e,C,{appLog:w,network:w,screenshot:B,snapshot:z,viewport:w,focus:E,gesture:O,scroll:k,typeText:D,touch:E,elementText:T,back:H,orientation:G,tvRemote:G,clipboard:W,systemButton:G,fold:G,telephony:G,triggerAppEvent:G,settings:G,readAlert:G,awaitAlert:G,acceptAlert:G,dismissAlert:G,keyboard:G,audioProbeCapture:K,audioProbeQuery:K,perf:G,readiness:w,lifecycle:a({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:P,clearRuntimeHints:P,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:F,configureProviderPortReverse:I})});return Object.freeze({device:r.device,operations:{...r.operations,...d({capture:X(e,z),customActions:V,withoutActiveApp:X(e,z)}),...l({capture:X(e,B)}),...m({focus:X(e,E)}),...u({unsupported:O,plan:X(e,O),directionalFling:A,multiTouch:j,targetAuthoredDrag:M,viewport:N}),...p({scroll:X(e,k)}),...f({type:X(e,D)}),...Z(e),...h({readTextAtPoint:X(e,T)}),...c({back:X(e,H)}),...g({unsupported:G,home:X(e,U)}),...v({unsupported:W,read:X(e,W),write:X(e,W)})}})}function X(e,t){return e.kind===`device`?S:t}function Z(e){let t=e.kind===`device`?S:E;return o({unsupported:w,tap:t,longPress:t,fill:t})}function Q(e,t){let n=async n=>await e.snapshot.captureSurface(t.device,n.options,_(t.scope.signal,n));return Object.freeze({captureSnapshot:n,captureSnapshotWithCustomActions:n,captureSnapshotWithoutActiveApp:n})}export{q as createLinuxPlatformRuntime};
@@ -1 +1 @@
1
- import{R as e}from"./sdk-contracts.js";import{l as t}from"./tv-remote.js";import{Sn as n,gn as r,xn as i}from"./sdk-batch.js";import{n as a,t as o}from"./application-lifecycle-runtime.js";import{r as s}from"./gesture-admission.js";import{C as c,K as l,_ as u,r as d}from"./tv-remote-runtime.js";import{r as f}from"./application-lifecycle-interaction.js";import{t as p}from"./interactor-operation-catalog.js";import{r as m}from"./platform-runtime-unavailable.js";const h=r(`vega`),g=Object.freeze({available:!0}),_=n(`unsupported-platform-leaf`),v=n(`unsupported-platform-leaf`,`Runtime hints are supported only for local iOS-family simulators and Android devices.`),y=n(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),b=n(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),x=n(`unsupported-device-kind`,`open currently supports only Vega Virtual Devices.`),S=n(`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=>W(e),bind:async n=>{if(n.intent.kind===`exact-owner`&&!i(n.intent.owner,h))throw new e(`UNSUPPORTED_OPERATION`,`Vega runtime owner identity does not match`);if(n.device.platform!==`vega`)throw new e(`UNSUPPORTED_PLATFORM`,`Vega runtime cannot bind this device`);let r=W(n.device),o=f({owner:`Vega`,openTargetIdentity:`app-name`,host:t.localInteractors,device:n.device,signal:n.scope.signal});return Object.freeze({device:n.device,owner:h,facts:r,operations:Object.freeze({...a(o,r.operations),...p({device:n.device,signal:n.scope.signal,resolveInteractor:t.localInteractors.resolve,facts:r.operations})}),[Symbol.asyncDispose]:async()=>void 0})},shutdown:async()=>void 0})}const w=n(`unsupported-platform-leaf`,`screenshot is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),T=n(`unsupported-platform-leaf`,`focus is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),E=n(`unsupported-platform-leaf`,`type is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),D=n(`unsupported-platform-leaf`,`Gestures are not supported on Vega OS: the Vega runtime exposes remote navigation only.`),O=n(`unsupported-platform-leaf`,`scroll is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),k=n(`unsupported-platform-leaf`),A=n(`unsupported-platform-leaf`,s),j=n(`unsupported-platform-leaf`,`orientation is not supported on Vega OS.`),M=n(`unsupported-platform-leaf`,`keyboard is not supported on Vega OS.`),N=n(`unsupported-platform-leaf`,`alert is not supported on Vega OS.`),P=n(`unsupported-platform-leaf`,`settings is not supported on Vega OS.`),F=n(`unsupported-platform-leaf`,`trigger-app-event is not supported on Vega OS.`),I=n(`unsupported-platform-leaf`,`System buttons other than home are not supported on Vega OS.`),L=n(`unsupported-platform-leaf`,`fold is not supported on Vega OS.`),R=n(`unsupported-platform-leaf`,`telephony is not supported on Vega OS.`),z=n(`unsupported-platform-leaf`,`clipboard is not supported on Vega OS.`),B=n(`unsupported-device-kind`,`back currently supports only Vega Virtual Devices.`),V=n(`unsupported-device-kind`,`home currently supports only Vega Virtual Devices.`),H=n(`unsupported-device-kind`,`tv-remote currently supports only Vega Virtual Devices.`),U=n(`unsupported-platform-leaf`,`audio is supported for web browser sessions, macOS sessions, iOS simulators, and Android emulators on macOS hosts`);function W(e){let n=e.kind===`emulator`&&e.target===`tv`,r=n?g:x,i=n?g:S,a=m(e,h,{appLog:_,network:_,screenshot:w,snapshot:_,viewport:_,focus:T,gesture:D,scroll:O,typeText:E,touch:_,elementText:_,back:B,orientation:j,tvRemote:H,clipboard:z,systemButton:I,fold:L,telephony:R,triggerAppEvent:F,settings:P,readAlert:N,awaitAlert:N,acceptAlert:N,dismissAlert:N,keyboard:M,audioProbeCapture:U,audioProbeQuery:U,perf:_,readiness:_,lifecycle:o({resolveOpenTarget:r,prepareApplicationOpen:r,openApplication:r,applyRuntimeHints:v,clearRuntimeHints:v,closeApplication:i,finalizeApplicationClose:i,prepareAppleRunner:y,configureProviderPortReverse:b})});return Object.freeze({device:a.device,operations:{...a.operations,...c({back:n?g:B}),...u({unsupported:I,home:n?g:V}),...d({tvRemote:n?g:H,buttonSupport:{supported:t(`vega`),unsupported:{available:!1,reason:`unsupported-platform-leaf`,hint:`This TV remote button is not supported on Vega OS.`}}}),...l({unsupported:D,multiTouch:k,targetAuthoredDrag:A})}})}export{C as createVegaPlatformRuntime};
1
+ import{R as e}from"./sdk-contracts.js";import{l as t}from"./tv-remote.js";import{Cn as n,vn as r,wn as i}from"./sdk-batch.js";import{n as a,t as o}from"./application-lifecycle-runtime.js";import{r as s}from"./gesture-admission.js";import{C as c,K as l,_ as u,r as d}from"./tv-remote-runtime.js";import{r as f}from"./application-lifecycle-interaction.js";import{t as p}from"./interactor-operation-catalog.js";import{r as m}from"./platform-runtime-unavailable.js";const h=r(`vega`),g=Object.freeze({available:!0}),_=i(`unsupported-platform-leaf`),v=i(`unsupported-platform-leaf`,`Runtime hints are supported only for local iOS-family simulators and Android devices.`),y=i(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),b=i(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),x=i(`unsupported-device-kind`,`open currently supports only Vega Virtual Devices.`),S=i(`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=>W(e),bind:async r=>{if(r.intent.kind===`exact-owner`&&!n(r.intent.owner,h))throw new e(`UNSUPPORTED_OPERATION`,`Vega runtime owner identity does not match`);if(r.device.platform!==`vega`)throw new e(`UNSUPPORTED_PLATFORM`,`Vega runtime cannot bind this device`);let i=W(r.device),o=f({owner:`Vega`,openTargetIdentity:`app-name`,host:t.localInteractors,device:r.device,signal:r.scope.signal});return Object.freeze({device:r.device,owner:h,facts:i,operations:Object.freeze({...a(o,i.operations),...p({device:r.device,signal:r.scope.signal,resolveInteractor:t.localInteractors.resolve,facts:i.operations})}),[Symbol.asyncDispose]:async()=>void 0})},shutdown:async()=>void 0})}const w=i(`unsupported-platform-leaf`,`screenshot is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),T=i(`unsupported-platform-leaf`,`focus is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),E=i(`unsupported-platform-leaf`,`type is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),D=i(`unsupported-platform-leaf`,`Gestures are not supported on Vega OS: the Vega runtime exposes remote navigation only.`),O=i(`unsupported-platform-leaf`,`scroll is not supported on Vega OS: the Vega runtime exposes remote navigation only.`),k=i(`unsupported-platform-leaf`),A=i(`unsupported-platform-leaf`,s),j=i(`unsupported-platform-leaf`,`orientation is not supported on Vega OS.`),M=i(`unsupported-platform-leaf`,`keyboard is not supported on Vega OS.`),N=i(`unsupported-platform-leaf`,`alert is not supported on Vega OS.`),P=i(`unsupported-platform-leaf`,`settings is not supported on Vega OS.`),F=i(`unsupported-platform-leaf`,`trigger-app-event is not supported on Vega OS.`),I=i(`unsupported-platform-leaf`,`System buttons other than home are not supported on Vega OS.`),L=i(`unsupported-platform-leaf`,`fold is not supported on Vega OS.`),R=i(`unsupported-platform-leaf`,`telephony is not supported on Vega OS.`),z=i(`unsupported-platform-leaf`,`clipboard is not supported on Vega OS.`),B=i(`unsupported-device-kind`,`back currently supports only Vega Virtual Devices.`),V=i(`unsupported-device-kind`,`home currently supports only Vega Virtual Devices.`),H=i(`unsupported-device-kind`,`tv-remote currently supports only Vega Virtual Devices.`),U=i(`unsupported-platform-leaf`,`audio is supported for web browser sessions, macOS sessions, iOS simulators, and Android emulators on macOS hosts`);function W(e){let n=e.kind===`emulator`&&e.target===`tv`,r=n?g:x,i=n?g:S,a=m(e,h,{appLog:_,network:_,screenshot:w,snapshot:_,viewport:_,focus:T,gesture:D,scroll:O,typeText:E,touch:_,elementText:_,back:B,orientation:j,tvRemote:H,clipboard:z,systemButton:I,fold:L,telephony:R,triggerAppEvent:F,settings:P,readAlert:N,awaitAlert:N,acceptAlert:N,dismissAlert:N,keyboard:M,audioProbeCapture:U,audioProbeQuery:U,perf:_,readiness:_,lifecycle:o({resolveOpenTarget:r,prepareApplicationOpen:r,openApplication:r,applyRuntimeHints:v,clearRuntimeHints:v,closeApplication:i,finalizeApplicationClose:i,prepareAppleRunner:y,configureProviderPortReverse:b})});return Object.freeze({device:a.device,operations:{...a.operations,...c({back:n?g:B}),...u({unsupported:I,home:n?g:V}),...d({tvRemote:n?g:H,buttonSupport:{supported:t(`vega`),unsupported:{available:!1,reason:`unsupported-platform-leaf`,hint:`This TV remote button is not supported on Vega OS.`}}}),...l({unsupported:D,multiTouch:k,targetAuthoredDrag:A})}})}export{C as createVegaPlatformRuntime};
@@ -1 +1 @@
1
- import{R as e}from"./sdk-contracts.js";import{Cn as t,Sn as n,gn as r,xn as i}from"./sdk-batch.js";import{n as a,t as o}from"./application-lifecycle-runtime.js";import{i as s,t as c}from"./touch-runtime.js";import{r as l}from"./gesture-admission.js";import{B as u,C as d,E as f,I as p,K as m,M as h,N as g,O as _,P as ee,R as te,T as ne,U as re,V as ie,Y as v,Z as y,_ as b,k as x,l as S,o as C,p as w,q as T,r as E,v as D,x as O}from"./tv-remote-runtime.js";import{r as k,u as A}from"./application-lifecycle-interaction.js";import{n as j,r as M,t as N}from"./screen-recording-transport.js";async function P(e){let{host:t,device:n,owner:r,signal:i}=e,a=await t.screenRecording.web.resolve(n);return a?{available:!0,operations:{screenRecordingStart:async e=>(F(e),await N({host:t,device:n,owner:r,input:e,signal:i,transport:{backend:`agent-browser`,targetLabel:`web recording`,start:async t=>await a.start(e.outputPath,t),stop:async()=>await a.stop()},support:{scopes:[`app`],fps:!1,exportQuality:!1,hideTouches:!1},unsupported:e=>`web recordings do not support ${e.join(`, `)}; agent-browser records WebM directly`})),screenRecordingReattach:async()=>M(`Web recordings cannot be reattached after daemon restart.`),screenRecordingCleanup:async()=>j(`Web recordings cannot be cleaned after daemon restart.`)}}:{available:!1,operations:{}}}function F(t){if(t.recordOnlySession)throw new e(`INVALID_ARGS`,`record on web requires an active browser session; run open <url> --platform web first`);if(!t.outputPath.toLowerCase().endsWith(`.webm`))throw new e(`INVALID_ARGS`,`web recordings require a .webm output path; agent-browser records WebM directly`)}const I=r(`web`),L=Object.freeze({available:!0}),ae=n(`unsupported-platform-leaf`,`Web targets read element text from the captured tree only.`),R=n(`unsupported-platform-leaf`),z=n(`owner-capability-missing`,`record is not supported by this web provider`),B=n(`unsupported-platform-leaf`,`Re-run without --actions, or target an iOS simulator.`),V=n(`unsupported-platform-leaf`),H=n(`unsupported-platform-leaf`,`apps is not supported on web targets.`),U=n(`unsupported-platform-leaf`),W=n(`unsupported-platform-leaf`),G=n(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),K=n(`owner-capability-missing`),q=n(`unsupported-platform-leaf`,`A web click is one immediate pointer press; the browser backend has no timed hold.`),J=n(`unsupported-platform-leaf`,`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:K}function X(e,t){return e?L:t}const oe=n(`unsupported-platform-leaf`),se=n(`unsupported-platform-leaf`,l),Z=n(`unsupported-device-kind`,`open is supported only for web browser devices.`),ce=n(`unsupported-device-kind`,`close is supported only for web browser devices.`),le=n(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`);function ue(e){let t=Q(e),n=de(e);return o({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:V,clearRuntimeHints:V,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:G,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 P({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 n=>{if(n.intent.kind===`exact-owner`&&!i(n.intent.owner,I))throw new e(`UNSUPPORTED_OPERATION`,`Web runtime owner identity does not match`);if(n.device.platform!==`web`)throw new e(`UNSUPPORTED_PLATFORM`,`Web runtime owner cannot bind ${n.device.platform}`);let r=await t.networkTransports.resolve(n.device),a=await P({host:t,device:n.device,owner:I,signal:n.scope.signal}),o=n.device.kind===`device`?await t.localInteractors.resolve(n.device,{signal:n.scope.signal}):void 0;return pe(t,n.device,n.scope.signal,r,a,$(n.device,r,a.available,o))},shutdown:async()=>void 0})}function pe(n,r,i,o,s,l){let u=o.dump,d={...u?{networkDump:async e=>{let t=await u({maxEntries:e.maxEntries,include:e.include},i);return Object.freeze({source:`provider`,...t})}}:{},...s.operations,...l.operations.captureSnapshot.available?x({device:r,signal:i,resolveInteractor:n.localInteractors.resolve}):{},...l.operations.captureScreenshot.available?ee({device:r,signal:i,resolveInteractor:n.localInteractors.resolve}):{},...l.operations.focusPoint.available?T({device:r,signal:i,resolveInteractor:n.localInteractors.resolve}):{},...l.operations.typeText.available?f({device:r,signal:i,resolveInteractor:n.localInteractors.resolve}):{},...t(l.operations.tapPoint,()=>c({device:r,signal:i,resolveInteractor:n.localInteractors.resolve,facts:l.operations,pause:async e=>await n.clock.sleep(e,i)})),...l.operations.scrollDirection.available?ie({device:r,signal:i,resolveInteractor:n.localInteractors.resolve}):{},...l.operations.setViewport.available?{setViewport:async t=>{i.throwIfAborted();let a=await n.localInteractors.resolve(r,{signal:i});if(!a.setViewport)throw new e(`UNSUPPORTED_OPERATION`,`viewport is not supported by the bound web interactor`);await a.setViewport(t.width,t.height),i.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)}})),...a(k({owner:`web`,openTargetIdentity:`app-name`,host:n.localInteractors,device:r,signal:i}),l.operations)};return Object.freeze({device:r,owner:I,facts:l,operations:Object.freeze(d),[Symbol.asyncDispose]:async()=>void 0})}function $(e,t,r,i){let a=n(`owner-capability-missing`,`network is not supported by this web provider`),o=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:R,appLogDoctor:R,appLogStart:R,appLogReattach:R,appLogCleanup:R,appState:U,networkDump:X(!!t.dump,a),screenRecordingStart:X(r,z),screenRecordingReattach:X(r,z),screenRecordingCleanup:X(r,z),...h({capture:o,customActions:B,withoutActiveApp:o}),...g({findText:Z,querySelector:Z}),...p({capture:o}),...v({focus:o}),..._({type:o}),...s({unsupported:V,tap:o,tapRef:Y(i?.tapRef,o),longPress:q,hover:Y(i?.hover,o),hoverRef:Y(i?.hoverRef,o),fill:o,fillRef:Y(i?.fillRef,o)}),...re({scroll:o}),...m({unsupported:oe,targetAuthoredDrag:se}),...ne({setViewport:o}),...y({readTextAtPoint:ae}),...d({back:W}),...C({orientation:W}),...E({tvRemote:W}),...S({unsupported:W}),...w({unsupported:W}),...u({capture:J,query:L}),...te({frames:W,memorySample:W,memorySnapshot:W,nativeCapture:W,profileReport:W}),...b({unsupported:W}),setFoldPose:W,sendTelephonyEvent:W,...D({triggerAppEvent:W}),...A({target:W,unsupported:W,write:{}}),...O({read:W,wait:W,accept:W,dismiss:W}),ensureReady:V,bootTarget:V,bootTargetHeadless:V,listApps:H,deployApp:V,materializeAppSource:V,deployMaterializedApp:V,sendPushNotification:V,uninstallApp:V,shutdownTarget:V,...ue(e)}})}export{fe as createWebPlatformRuntime};
1
+ import{R as e}from"./sdk-contracts.js";import{Cn as t,Tn as n,vn as r,wn as i}from"./sdk-batch.js";import{n as a,t as o}from"./application-lifecycle-runtime.js";import{i as s,t as c}from"./touch-runtime.js";import{r as l}from"./gesture-admission.js";import{B as u,C as d,E as f,I as p,K as m,M as h,N as g,O as _,P as ee,R as te,T as ne,U as re,V as ie,Y as v,Z as y,_ as b,k as x,l as S,o as C,p as w,q as T,r as E,v as D,x as O}from"./tv-remote-runtime.js";import{r as k,u as A}from"./application-lifecycle-interaction.js";import{n as j,r as M,t as N}from"./screen-recording-transport.js";async function P(e){let{host:t,device:n,owner:r,signal:i}=e,a=await t.screenRecording.web.resolve(n);return a?{available:!0,operations:{screenRecordingStart:async e=>(F(e),await N({host:t,device:n,owner:r,input:e,signal:i,transport:{backend:`agent-browser`,targetLabel:`web recording`,start:async t=>await a.start(e.outputPath,t),stop:async()=>await a.stop()},support:{scopes:[`app`],fps:!1,exportQuality:!1,hideTouches:!1},unsupported:e=>`web recordings do not support ${e.join(`, `)}; agent-browser records WebM directly`})),screenRecordingReattach:async()=>M(`Web recordings cannot be reattached after daemon restart.`),screenRecordingCleanup:async()=>j(`Web recordings cannot be cleaned after daemon restart.`)}}:{available:!1,operations:{}}}function F(t){if(t.recordOnlySession)throw new e(`INVALID_ARGS`,`record on web requires an active browser session; run open <url> --platform web first`);if(!t.outputPath.toLowerCase().endsWith(`.webm`))throw new e(`INVALID_ARGS`,`web recordings require a .webm output path; agent-browser records WebM directly`)}const I=r(`web`),L=Object.freeze({available:!0}),ae=i(`unsupported-platform-leaf`,`Web targets read element text from the captured tree only.`),R=i(`unsupported-platform-leaf`),z=i(`owner-capability-missing`,`record is not supported by this web provider`),B=i(`unsupported-platform-leaf`,`Re-run without --actions, or target an iOS simulator.`),V=i(`unsupported-platform-leaf`),H=i(`unsupported-platform-leaf`,`apps is not supported on web targets.`),U=i(`unsupported-platform-leaf`),W=i(`unsupported-platform-leaf`),G=i(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),K=i(`owner-capability-missing`),q=i(`unsupported-platform-leaf`,`A web click is one immediate pointer press; the browser backend has no timed hold.`),J=i(`unsupported-platform-leaf`,`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:K}function X(e,t){return e?L:t}const oe=i(`unsupported-platform-leaf`),se=i(`unsupported-platform-leaf`,l),Z=i(`unsupported-device-kind`,`open is supported only for web browser devices.`),ce=i(`unsupported-device-kind`,`close is supported only for web browser devices.`),le=i(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`);function ue(e){let t=Q(e),n=de(e);return o({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:V,clearRuntimeHints:V,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:G,configureProviderPortReverse:le})}function Q(e){return e.kind===`device`?L:Z}function de(e){return e.kind===`device`?L:ce}function fe(n){return Object.freeze({owner:I,ownsDevice:e=>e.platform===`web`,inspectFacts:async e=>{let t=await n.networkTransports.resolve(e),r=await P({host:n,device:e,owner:I,signal:new AbortController().signal}),i=e.kind===`device`?await n.localInteractors.resolve(e,{}):void 0;return $(e,t,r.available,i)},bind:async r=>{if(r.intent.kind===`exact-owner`&&!t(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 n.networkTransports.resolve(r.device),a=await P({host:n,device:r.device,owner:I,signal:r.scope.signal}),o=r.device.kind===`device`?await n.localInteractors.resolve(r.device,{signal:r.scope.signal}):void 0;return pe(n,r.device,r.scope.signal,i,a,$(r.device,i,a.available,o))},shutdown:async()=>void 0})}function pe(t,r,i,o,s,l){let u=o.dump,d={...u?{networkDump:async e=>{let t=await u({maxEntries:e.maxEntries,include:e.include},i);return Object.freeze({source:`provider`,...t})}}:{},...s.operations,...l.operations.captureSnapshot.available?x({device:r,signal:i,resolveInteractor:t.localInteractors.resolve}):{},...l.operations.captureScreenshot.available?ee({device:r,signal:i,resolveInteractor:t.localInteractors.resolve}):{},...l.operations.focusPoint.available?T({device:r,signal:i,resolveInteractor:t.localInteractors.resolve}):{},...l.operations.typeText.available?f({device:r,signal:i,resolveInteractor:t.localInteractors.resolve}):{},...n(l.operations.tapPoint,()=>c({device:r,signal:i,resolveInteractor:t.localInteractors.resolve,facts:l.operations,pause:async e=>await t.clock.sleep(e,i)})),...l.operations.scrollDirection.available?ie({device:r,signal:i,resolveInteractor:t.localInteractors.resolve}):{},...l.operations.setViewport.available?{setViewport:async n=>{i.throwIfAborted();let a=await t.localInteractors.resolve(r,{signal:i});if(!a.setViewport)throw new e(`UNSUPPORTED_OPERATION`,`viewport is not supported by the bound web interactor`);await a.setViewport(n.width,n.height),i.throwIfAborted()}}:{},...n(l.operations.audioProbeQuery,()=>({audioProbeQuery:async n=>{let i=await t.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(n)}})),...a(k({owner:`web`,openTargetIdentity:`app-name`,host:t.localInteractors,device:r,signal:i}),l.operations)};return Object.freeze({device:r,owner:I,facts:l,operations:Object.freeze(d),[Symbol.asyncDispose]:async()=>void 0})}function $(e,t,n,r){let a=i(`owner-capability-missing`,`network is not supported by this web provider`),o=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:R,appLogDoctor:R,appLogStart:R,appLogReattach:R,appLogCleanup:R,appState:U,networkDump:X(!!t.dump,a),screenRecordingStart:X(n,z),screenRecordingReattach:X(n,z),screenRecordingCleanup:X(n,z),...h({capture:o,customActions:B,withoutActiveApp:o}),...g({findText:Z,querySelector:Z}),...p({capture:o}),...v({focus:o}),..._({type:o}),...s({unsupported:V,tap:o,tapRef:Y(r?.tapRef,o),longPress:q,hover:Y(r?.hover,o),hoverRef:Y(r?.hoverRef,o),fill:o,fillRef:Y(r?.fillRef,o)}),...re({scroll:o}),...m({unsupported:oe,targetAuthoredDrag:se}),...ne({setViewport:o}),...y({readTextAtPoint:ae}),...d({back:W}),...C({orientation:W}),...E({tvRemote:W}),...S({unsupported:W}),...w({unsupported:W}),...u({capture:J,query:L}),...te({frames:W,memorySample:W,memorySnapshot:W,nativeCapture:W,profileReport:W}),...b({unsupported:W}),setFoldPose:W,sendTelephonyEvent:W,...D({triggerAppEvent:W}),...A({target:W,unsupported:W,write:{}}),...O({read:W,wait:W,accept:W,dismiss:W}),ensureReady:V,bootTarget:V,bootTargetHeadless:V,listApps:H,deployApp:V,materializeAppSource:V,deployMaterializedApp:V,sendPushNotification:V,uninstallApp:V,shutdownTarget:V,...ue(e)}})}export{fe as createWebPlatformRuntime};