agent-device 0.20.9 → 0.20.10

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 (140) hide show
  1. package/android/ime-helper/dist/{agent-device-android-ime-helper-0.20.9.apk → agent-device-android-ime-helper-0.20.10.apk} +0 -0
  2. package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.10.apk.sha256 +1 -0
  3. package/android/ime-helper/dist/{agent-device-android-ime-helper-0.20.9.manifest.json → agent-device-android-ime-helper-0.20.10.manifest.json} +4 -4
  4. package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.20.9.apk → agent-device-android-snapshot-helper-0.20.10.apk} +0 -0
  5. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.10.apk.sha256 +1 -0
  6. package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.20.9.manifest.json → agent-device-android-snapshot-helper-0.20.10.manifest.json} +6 -6
  7. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AXSnapshotFallback.swift +6 -5
  8. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +4 -4
  9. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+FlatSnapshotFiltering.swift +94 -1
  10. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +22 -23
  11. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +3 -23
  12. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Navigation.swift +10 -11
  13. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+PrivateAXPresentation.swift +30 -12
  14. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScrollGesture.swift +8 -5
  15. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift +133 -63
  16. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotCapturePlan.swift +13 -12
  17. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotPresentation.swift +183 -0
  18. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotPresentationTests.swift +0 -0
  19. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SystemModal.swift +20 -18
  20. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextInputCandidatePolicy.swift +19 -0
  21. package/dist/src/agent-device-client.js +2 -2
  22. package/dist/src/ai-sdk.d.ts +61 -0
  23. package/dist/src/ai-sdk.js +1 -0
  24. package/dist/src/android-adb.d.ts +1 -1
  25. package/dist/src/app-lifecycle.js +1 -1
  26. package/dist/src/app-log-reconnect.js +1 -1
  27. package/dist/src/app-log-runtime.js +3 -3
  28. package/dist/src/app-resolution.js +2 -2
  29. package/dist/src/apps.js +5 -5
  30. package/dist/src/audio-probe.js +1 -1
  31. package/dist/src/boot-diagnostics.js +2 -2
  32. package/dist/src/cli-config.js +1 -1
  33. package/dist/src/cli-help.js +30 -23
  34. package/dist/src/cli-runner.js +1 -1
  35. package/dist/src/cli.js +7 -7
  36. package/dist/src/client-metro.js +1 -1
  37. package/dist/src/client-types.d.ts +1582 -0
  38. package/dist/src/command-tools.js +2 -0
  39. package/dist/src/connection-runtime.js +1 -1
  40. package/dist/src/contracts.d.ts +1 -1
  41. package/dist/src/contracts.js +1 -1
  42. package/dist/src/daemon-shutdown-report.js +1 -1
  43. package/dist/src/daemon.js +1 -1
  44. package/dist/src/debug-symbols.js +1 -1
  45. package/dist/src/device-input-state.js +1 -1
  46. package/dist/src/dispatch.js +1 -1
  47. package/dist/src/find.js +1 -1
  48. package/dist/src/finders.js +1 -1
  49. package/dist/src/generic-settle.js +1 -1
  50. package/dist/src/generic.js +1 -1
  51. package/dist/src/helper-package-install.js +1 -1
  52. package/dist/src/helper.js +1 -1
  53. package/dist/src/ime-lifecycle.js +1 -1
  54. package/dist/src/ime-recovery-marker.js +1 -1
  55. package/dist/src/index.d.ts +2 -1578
  56. package/dist/src/index.js +1 -1
  57. package/dist/src/input-actions.js +1 -1
  58. package/dist/src/input-actions3.js +1 -1
  59. package/dist/src/install-source2.js +1 -1
  60. package/dist/src/interaction-common.js +1 -1
  61. package/dist/src/interaction-runtime.js +1 -1
  62. package/dist/src/interaction-snapshot.js +1 -1
  63. package/dist/src/interaction.js +1 -1
  64. package/dist/src/interaction2.js +1 -1
  65. package/dist/src/interactor.js +2 -2
  66. package/dist/src/interactor2.js +1 -1
  67. package/dist/src/interactors.js +1 -1
  68. package/dist/src/internal/bin.js +2 -2
  69. package/dist/src/internal/daemon.js +4 -4
  70. package/dist/src/internal/png-worker.js +1 -1
  71. package/dist/src/lease-context.js +1 -1
  72. package/dist/src/lease.js +1 -1
  73. package/dist/src/limrun.d.ts +10 -2
  74. package/dist/src/linux.js +1 -1
  75. package/dist/src/location-coordinates.js +1 -1
  76. package/dist/src/{screenshot-geometry.js → mobile-snapshot-semantics.js} +1 -1
  77. package/dist/src/perf.js +1 -1
  78. package/dist/src/platform-runtime-open-target.js +1 -1
  79. package/dist/src/platform-runtime-operation-host.js +4 -4
  80. package/dist/src/platform-runtime.js +1 -1
  81. package/dist/src/platform-runtime2.js +1 -1
  82. package/dist/src/png-resize.js +1 -1
  83. package/dist/src/provider.js +1 -1
  84. package/dist/src/proxy.js +1 -1
  85. package/dist/src/react-native.js +1 -1
  86. package/dist/src/record-runtime.js +1 -1
  87. package/dist/src/registry.js +27 -27
  88. package/dist/src/remote-config2.js +1 -1
  89. package/dist/src/replay.js +2 -2
  90. package/dist/src/reporting.js +5 -5
  91. package/dist/src/runner-client.js +1 -1
  92. package/dist/src/runner-disposal.js +1 -1
  93. package/dist/src/runner-sequence.js +1 -1
  94. package/dist/src/runtime.js +3 -3
  95. package/dist/src/runtime2.js +4 -4
  96. package/dist/src/runtime3.js +1 -1
  97. package/dist/src/runtime4.js +3 -3
  98. package/dist/src/runtime5.js +1 -1
  99. package/dist/src/runtime6.js +1 -1
  100. package/dist/src/runtime7.js +1 -1
  101. package/dist/src/runtime8.js +1 -1
  102. package/dist/src/runtime9.js +1 -1
  103. package/dist/src/screenshot-result.js +4 -4
  104. package/dist/src/screenshot.js +1 -1
  105. package/dist/src/script-source-bundle.js +16 -0
  106. package/dist/src/sdk-android-adb.d.ts +40 -40
  107. package/dist/src/sdk-android-adb.js +4 -4
  108. package/dist/src/sdk-batch-runner.js +3 -3
  109. package/dist/src/sdk-contracts.d.ts +122 -85
  110. package/dist/src/sdk-contracts.js +2 -2
  111. package/dist/src/sdk-finders.d.ts +1 -1
  112. package/dist/src/sdk-finders.js +1 -1
  113. package/dist/src/sdk-selectors.d.ts +89 -77
  114. package/dist/src/sdk-selectors.js +1 -1
  115. package/dist/src/selector-runtime.js +1 -1
  116. package/dist/src/selectors.js +1 -1
  117. package/dist/src/server.js +10 -3
  118. package/dist/src/session-target-evidence.js +1 -1
  119. package/dist/src/session2.js +7 -8
  120. package/dist/src/shared.js +1 -1
  121. package/dist/src/snapshot-runtime.js +1 -1
  122. package/dist/src/snapshot-scope.js +1 -0
  123. package/dist/src/snapshot.js +6 -6
  124. package/dist/src/snapshot2.js +1 -1
  125. package/dist/src/snapshot3.js +1 -1
  126. package/dist/src/src.js +1 -1
  127. package/dist/src/src2.js +1 -1
  128. package/dist/src/src3.js +1 -1
  129. package/dist/src/src4.js +1 -0
  130. package/dist/src/tool-provider2.js +1 -1
  131. package/dist/src/tool-provider3.js +1 -0
  132. package/dist/src/verified-file.js +1 -1
  133. package/dist/src/web.js +1 -1
  134. package/package.json +21 -8
  135. package/server.json +2 -2
  136. package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.9.apk.sha256 +0 -1
  137. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.9.apk.sha256 +0 -1
  138. package/dist/src/cancel.js +0 -1
  139. package/dist/src/prepare-kind.js +0 -15
  140. package/dist/src/selector-vocabulary.js +0 -1
@@ -1,3 +1,3 @@
1
- import{_ as e,v as t}from"./sdk-contracts.js";import{H as n,K as r,U as i,at as a,bt as o,dt as s,et as c,ot as l,st as u,tt as d,ut as f,wt as p,z as ee}from"./sdk-batch-runner.js";import{C as te,c as m,l as h,s as g,x as _}from"./sdk-device.js";import{c as ne,f as re,g as ie,h as ae,i as oe,l as se,m as ce,n as le,p as ue,r as v,s as y,t as de,u as fe,v as b,x}from"./src3.js";import{n as S,t as pe}from"./simulator-state.js";import me from"node:path";const C=`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`;function w(e){return h(e)?`macos`:e.kind===`device`?`ios-device`:`ios-simulator`}const T=Object.freeze({resourceKind:d,version:1,encode:e=>({...e}),decode:e=>!ge(e.transport)||!_e(e.backend)||!E(e.outputPath)||!ye(e.pidPath)||!ve(e.transport,e.backend)?he():{status:`decoded`,descriptor:Object.freeze({transport:e.transport,backend:e.backend,outputPath:e.outputPath,...e.pidPath===void 0?{}:{pidPath:e.pidPath}})}});function he(){return{status:`invalid`,message:`Invalid Apple app-log descriptor`}}function ge(e){return e===`apple-log-stream`||e===`coredevice-console`}function _e(e){return e===`ios-simulator`||e===`ios-device`||e===`macos`}function ve(e,t){return e===`coredevice-console`?t===`ios-device`:t!==`ios-device`}function ye(e){return e===void 0||E(e)}function be(e){if(!e.device.appleOs)throw TypeError(`Apple app-log persistence requires an explicit appleOs identity`);return b({resourceKind:d,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:x(T,e.descriptor)})}function E(e){return typeof e==`string`&&e.trim().length>0}const D={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.`},xe={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 Se(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 Ce(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(h(t))i.logAvailable=!!await e.commands.which(`log`);else if(t.kind===`simulator`)i.simctlAvailable=await oe(async()=>v(await e.appleTools.run({tool:`simctl`,args:[`help`],allowFailure:!0},r)),r);else if(t.iosPhysicalDeviceBackend===`xctest`)i.devicectlAvailable=!1,i.devicectlConsoleCapture=!1,a.push(C);else{i.devicectlAvailable=await oe(async()=>v(await e.appleTools.run({tool:`devicectl`,args:[`--version`],allowFailure:!0},r)),r);let t=await Se(e,r);if(i.devicectlConsoleCapture=t.supported,!t.supported){let e=t.reason===`unsupported`?D:xe;a.push(`${e.message} ${e.hint}`)}}return{backend:w(t),checks:i,notes:a}}function we(e,t){let n=O(e),r=[`subsystem == "${n}"`,`subsystem CONTAINS "${n}"`,`processImagePath ENDSWITH[c] "/${n}"`,`senderImagePath ENDSWITH[c] "/${n}"`];if(t){let e=O(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 Te(e){return[...e.simulatorSetPath?[`simctl`,`--set`,e.simulatorSetPath]:[`simctl`],`spawn`,e.deviceId,`log`,`stream`,`--style`,`compact`,`--level`,`info`,`--predicate`,we(e.appBundleId,e.executableName)]}function Ee(e,t){return[`devicectl`,`device`,`process`,`launch`,`--device`,e,`--console`,`--terminate-existing`,t]}function O(e){return e.replaceAll(`\\`,`\\\\`).replaceAll(`"`,`\\"`)}async function De(e,t,n,r,i){Oe(t),ne(e,n);let a=w(t),o=await Ae(e,t,n.appBundleId,i),s=new f,c=!1;try{let l=await e.outputs.openAppend(n.outputPath);s.defer(async()=>{c||await l[Symbol.asyncDispose]()}),i?.throwIfAborted();let u=await ke(e,t,o,l,n.pidPath,i);s.defer(async()=>{c||await u[Symbol.asyncDispose]()});let d=Me(e,u,l,a,n.outputPath),f={transport:a===`ios-device`?`coredevice-console`:`apple-log-stream`,backend:a,outputPath:n.outputPath,...n.pidPath===void 0?{}:{pidPath:n.pidPath}},p=ie(d,be({sessionId:n.sessionId,device:t,owner:r,fence:n.fence,descriptor:f}));return c=!0,p}finally{await s[Symbol.asyncDispose]()}}function Oe(t){if(t.appleOs===`watchos`)throw new e(`UNSUPPORTED_PLATFORM`,`watchOS app logs are not supported`);if(m(t)&&t.kind===`device`&&t.iosPhysicalDeviceBackend===`xctest`)throw new e(`UNSUPPORTED_OPERATION`,C,{hint:C})}async function ke(t,n,r,i,a,o){if(m(n)&&n.kind===`device`){let n=await Se(t,o);if(!n.supported){let t=n.reason===`unsupported`?D:xe;throw new e(n.reason===`unsupported`?`UNSUPPORTED_OPERATION`:`COMMAND_FAILED`,t.message,{backend:`ios-device`,hint:t.hint,stderr:n.stderr})}}return o?.throwIfAborted(),await t.processes.start({command:{kind:`host`,request:r},output:i,...a?{markerPath:a}:{}})}async function Ae(e,t,n,r){if(h(t))return{executable:`log`,args:[`stream`,`--style`,`compact`,`--predicate`,we(n)],allowFailure:!0};if(t.kind===`device`)return{executable:`xcrun`,args:Ee(t.id,n),allowFailure:!0};let i=await je(e,t,n,r);return{executable:`xcrun`,args:Te({deviceId:t.id,appBundleId:n,executableName:i,simulatorSetPath:t.simulatorSetPath}),allowFailure:!0}}async function je(e,t,n,r){let i=t.simulatorSetPath?[`--set`,t.simulatorSetPath]:[],a=await e.appleTools.run({tool:`simctl`,args:[...i,`get_app_container`,t.id,n,`app`],allowFailure:!0,timeoutMs:4e3},r),o=a.exitCode===0?a.stdout.trim():``;if(!o)return;let s=await e.commands.run({executable:`plutil`,args:[`-extract`,`CFBundleExecutable`,`raw`,`-o`,`-`,me.join(o,`Info.plist`)],allowFailure:!0,timeoutMs:4e3},r);return s.exitCode===0&&s.stdout.trim()||void 0}function Me(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 ce({inspect:()=>({backend:r,state:o,startedAt:a}),finish:async()=>s??=(async()=>(await Ne([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 Ne(e){let t=[];for(let n of e)try{await n()}catch(e){t.push(e)}return t}const k=o(`apple`),A=Object.freeze({available:!0});function Pe(t){return Object.freeze({owner:k,ownsDevice:e=>e.platform===`apple`,inspectFacts:async e=>j(e),bind:async n=>{if(n.intent.kind===`exact-owner`&&!p(n.intent.owner,k))throw new e(`UNSUPPORTED_OPERATION`,`Apple app-log owner identity does not match`);return Fe(t,n.device,n.scope.signal)},shutdown:async()=>void 0})}function Fe(t,n,r){if(n.platform!==`apple`)throw new e(`UNSUPPORTED_PLATFORM`,`Apple app-log owner cannot bind ${n.platform}`);let i=ae({codec:T,reattach:async(e,r)=>e.backend!==w(n)||!y(t,r.sessionId,e)?{status:`unreattachable`,reason:`descriptor-invalid`,message:`Apple app-log descriptor does not match the bound device or owning session`}:await fe(t,e.pidPath),cleanup:async(e,r)=>e.backend===w(n)&&y(t,r.sessionId,e)?await se(t,e.pidPath):{status:`cleanup-pending`,reason:`ownership-fence-lost`,message:`Apple app-log descriptor does not match the bound device or owning session`}}),a=Object.freeze({appLogInspect:async()=>({backend:w(n)}),appLogDoctor:async({appBundleId:e})=>await Ce(t,n,e,r),appLogStart:async e=>await De(t,n,e,k,r),...i});return Object.freeze({device:n,owner:k,facts:j(n),operations:a,[Symbol.asyncDispose]:async()=>void 0})}function j(e){if(e.appleOs===`watchos`)return Ie(e);let t=m(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?{available:!1,reason:`unsupported-device-backend`,hint:C}:A;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:A,appLogCleanup:A}})}function Ie(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 Le(e,t,n,r){let i=w(t),a=await e.appLogs.readRecent(n.sessionId,n.maxScanLines),o=le(a.text,{...n,path:a.path,exists:a.exists,lineNumberOffset:a.skippedLines,backend:i}),s=[];if(Re(t,n,o)){let i=await ze(e,t,n,a.path,r);i&&(i.dump.entries.length>0?(o=de(i.dump,o,n.maxEntries),s.push(`Recovered ${i.dump.entries.length} iOS simulator HTTP entr${i.dump.entries.length===1?`y`:`ies`} from simctl log show (${i.lineCount} app log lines scanned).`)):i.lineCount>0&&s.push(`Recovered ${i.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.`))}return Ve(s,t,n),o.entries.length===0&&s.push(He(t)),Object.freeze({source:`app-log`,backend:i,dump:o,notes:Object.freeze(s)})}function Re(e,t,n){return m(e)&&e.kind===`simulator`&&!!t.appBundleId&&n.entries.length===0}async function ze(e,t,n,r,i){let a=[...t.simulatorSetPath?[`--set`,t.simulatorSetPath]:[],`spawn`,t.id,`log`,`show`,`--style`,`compact`,`--info`,`--predicate`,Be(n.appBundleId)],o=n.appLogSnapshot?.startedAt;a.push(...typeof o==`number`&&Number.isFinite(o)&&o>0?[`--start`,`@${Math.floor(o/1e3)}`]:[`--last`,`5m`]);let s=await e.appleTools.run({tool:`simctl`,args:a,allowFailure:!0,timeoutMs:4e3},i);if(s.exitCode!==0||!s.stdout.trim())return;let c=s.stdout.split(`
2
- `).map(e=>e.trimEnd()).filter(e=>e.trim()&&!e.trim().startsWith(`Timestamp Ty Process[PID:TID]`));if(c.length!==0)return{dump:le(`${c.join(`
3
- `)}\n`,{...n,path:`${r} (simctl log show recovery)`,exists:!0,backend:`ios-simulator`}),lineCount:c.length}}function Be(e){let t=e.replaceAll(`\\`,`\\\\`).replaceAll(`"`,`\\"`);return[`subsystem == "${t}"`,`subsystem CONTAINS "${t}"`,`processImagePath ENDSWITH[c] "/${t}"`,`senderImagePath ENDSWITH[c] "/${t}"`].join(` OR `)}function Ve(e,t,n){n.appLogSnapshot?n.appLogSnapshot.state!==`active`&&e.length===0&&e.push(m(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 He(e){return m(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.`:m(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 M(e,n,r){if(n.invalidatedReason&&!n.showTouches)throw Error(`recording invalidated: ${n.invalidatedReason}`);let i;try{i=await e.screenRecording.finalize.complete({outputPath:n.outPath,showTouches:n.invalidatedReason?!1:n.showTouches,gestureEvents:n.gestureEvents,exportQuality:n.exportQuality??`medium`,...n.runnerStartedAtUptimeMs!==void 0&&n.targetAppReadyUptimeMs!==void 0?{trimStartMs:Math.max(0,n.targetAppReadyUptimeMs-n.runnerStartedAtUptimeMs)}:{},targetLabel:r})}catch(e){throw t(e,`COMMAND_FAILED`)}return re(n,{...i,...n.invalidatedReason?{overlayWarning:`overlay unavailable: ${n.invalidatedReason}`}:{}})}const N=Object.freeze({resourceKind:c,version:1,encode:e=>e.backend===`simctl`?{backend:e.backend,outputPath:e.outputPath,processes:e.processes.map(e=>({...e}))}:{backend:e.backend,outputPath:e.outputPath,appBundleId:e.appBundleId,runnerSessionId:e.runnerSessionId,runnerAuthority:e.runnerAuthority,...e.remotePath===void 0?{}:{remotePath:e.remotePath}},decode:e=>Je(e)});function Ue(e){let{device:t,owner:n,input:r,descriptor:i}=e;return b({resourceKind:c,sessionId:r.sessionId,device:te(t),owner:n,fence:r.fence,lifecycle:`open`,descriptor:x(N,i)})}async function We(e,t,n){let r=N.decode(n);return r.status!==`decoded`||!I(t,r.descriptor)?{status:`cleanup-pending`,reason:`manual-recovery-required`}:r.descriptor.backend===`simctl`?await Ge(e,r.descriptor.processes):await Ke(e,t,r.descriptor)}async function Ge(e,t){let n=await Promise.all(t.map(async t=>await e.screenRecording.apple.inspectProcess(t)));if(n.includes(`ownership-lost`))return{status:`cleanup-pending`,reason:`ownership-fence-lost`};if(n.every(e=>e===`missing`))return{status:`already-missing`};let r=await Promise.all(t.flatMap((t,r)=>n[r]===`owned-alive`?[e.screenRecording.apple.terminateProcess(t)]:[]));return r.includes(`ownership-lost`)?{status:`cleanup-pending`,reason:`ownership-fence-lost`}:r.every(e=>e===`already-missing`)?{status:`already-missing`}:{status:`cleaned`}}async function Ke(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 qe(e,t,n){let r=N.decode(n);if(r.status!==`decoded`)return{status:`unreattachable`,reason:`descriptor-invalid`,message:r.message};if(!I(t,r.descriptor))return{status:`unreattachable`,reason:`descriptor-invalid`,message:`Apple screen-recording descriptor does not match the bound device.`};let i=r.descriptor.backend===`simctl`?await Promise.all(r.descriptor.processes.map(async t=>await e.screenRecording.apple.inspectProcess(t))):[await e.screenRecording.apple.inspectRunner(t,r.descriptor.runnerSessionId,r.descriptor.runnerAuthority)];return i.every(e=>e===`missing`)?{status:`missing`}:{status:`unreattachable`,reason:`transport-not-reattachable`,message:i.includes(`ownership-lost`)?`Apple recording ownership no longer matches the durable descriptor.`:`Apple screen recordings require exact cleanup after daemon restart.`}}function Je(e){return typeof e.outputPath!=`string`||e.outputPath.length===0?L():e.backend===`simctl`?Ye(e,e.outputPath):e.backend===`runner`?Xe(e,e.outputPath):L()}function Ye(e,t){let n=$e(e.processes);return n?{status:`decoded`,descriptor:Object.freeze({backend:`simctl`,outputPath:t,processes:n})}:L()}function Xe(e,t){return!P(e.appBundleId)||!P(e.runnerSessionId)||!Ze(e.runnerAuthority)||!Qe(e.remotePath)?L():{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 Ze(e){return e===`local-lease`||e===`scoped-provider`}function Qe(e){return e===void 0||F(e)}function F(e){return typeof e==`string`&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(e)}function I(e,t){return e.kind===`simulator`?t.backend===`simctl`:t.backend===`runner`?e.appleOs===`macos`?t.remotePath===void 0:m(e)?t.remotePath!==void 0&&F(t.remotePath):t.remotePath===void 0:!1}function $e(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 L(){return{status:`invalid`,message:`Invalid Apple screen-recording descriptor`}}async function et(e,t,n){if(e.kind!==`simulator`||t.scope!==`app`)return;let r=t.activeSessionApp?.bundleId;if(!r)throw TypeError(`App-scoped recording requires an active app session; open the app under test before recording.`);if(await n(r))throw TypeError(`App-scoped recording requires a real application session; open the app under test before recording.`)}function tt(e){return e.appleOs===`watchos`?V(`unsupported-platform-leaf`,`watchOS recording is not supported.`):m(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?V(`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 nt(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await rt({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async e=>await qe(t,n,e.envelope.descriptor.body),screenRecordingCleanup:async e=>await We(t,n,e.envelope.descriptor.body)})}async function rt(e){return e.signal.throwIfAborted(),e.device.kind===`simulator`?await it(e):await at(e)}async function it(e){let{host:t,device:n,owner:r,input:i,signal:a}=e;await et(n,i,t.screenRecording.apple.isRunnerBundleId);let o=i.activeSessionApp?await t.screenRecording.apple.captureClockAnchor(n,i.activeSessionApp.bundleId,a):void 0;await t.screenRecording.outputs.prepare(i.outputPath);let s=await t.screenRecording.apple.startSimulator(n,i.outputPath,a),c=s.markers;if(!c||c.length===0)throw await R(s).catch(()=>{}),Error(`simctl recordVideo did not expose durable process identity`);try{a.throwIfAborted()}catch(e){throw await R(s).catch(()=>{}),e}return z({device:n,owner:r,input:i,descriptor:{backend:`simctl`,outputPath:i.outputPath,processes:c},snapshot:B(i,`simctl recordVideo`,{},o),finish:async e=>{await s.terminate();let n=await s.wait;if(n.exitCode!==0)throw Error(`simctl recordVideo exited with code ${n.exitCode}`);return await M(t,e,`iOS recording`)},cleanup:async()=>await ct(s)})}async function at(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??=ot(()=>t.screenRecording.apple.runRunner(n,{kind:`stop`,appBundleId:o,...c}).then(()=>void 0));if(!st(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 z({device:n,owner:r,input:i,descriptor:{backend:`runner`,outputPath:i.outputPath,appBundleId:o,...c,...s.remotePath===void 0?{}:{remotePath:s.remotePath}},snapshot:B(i,`runner AVAssetWriter`,s),finish:async e=>(await u(),s.remotePath!==void 0&&await t.screenRecording.apple.retrieveRunnerRecording(n,s.remotePath,e.outPath),await M(t,e,n.appleOs===`macos`?`macOS recording`:`iOS recording`)),cleanup:async()=>(await u(),{status:`cleaned`})})}async function ot(e){try{return await e()}catch(e){throw t(e,`COMMAND_FAILED`)}}function st(e,t){return e.appleOs===`macos`||!m(e)?t===void 0:t!==void 0&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(t)}async function R(e){return await e.terminate(),await e.wait}async function ct(e){try{return await R(e),{status:`cleaned`}}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`Apple simulator cleanup failed`}}}function z(e){let{device:t,owner:n,input:r,descriptor:i,snapshot:a,finish:o,cleanup:c}=e,l=ue(a,{finish:o,forceCleanup:c});return Object.freeze({pendingHandle:new s(l),envelope:Ue({device:t,owner:n,input:r,descriptor:i})})}function B(e,t,n={},r){let i=Date.now();return Object.freeze({backend:t,outPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutPath:e.clientOutputPath},startedAt:i,scope:e.scope,showTouches:e.showTouches,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},...e.exportQuality===void 0?{}:{exportQuality:e.exportQuality},gestureEvents:[],...r===void 0?{}:{gestureClockOriginAtMs:r.wallClockAtMs,gestureClockOriginUptimeMs:r.uptimeMs},...n.recorderStartUptimeMs===void 0?{}:{gestureClockOriginAtMs:i,gestureClockOriginUptimeMs:n.recorderStartUptimeMs,runnerStartedAtUptimeMs:n.recorderStartUptimeMs},...n.targetAppReadyUptimeMs===void 0?{}:{targetAppReadyUptimeMs:n.targetAppReadyUptimeMs},...n.runnerSessionId===void 0?{}:{runnerSessionId:n.runnerSessionId}})}function V(e,t){return Object.freeze({available:!1,reason:e,hint:t})}const H=12e4;async function U(e,t,n,r={}){return n.throwIfAborted(),h(t)?{...t,booted:!0}:t.kind===`device`?(await e.deviceReadiness.applePhysical.ensureConnected(t,n),{...t,booted:!0}):t.kind===`simulator`?(await W(e,t,n)!==`Booted`&&(r.onColdBootStart?.(),e.deviceReadiness.appleAutomation.keepHot(t),await lt(e,t,n),await ut(e,n)),e.deviceReadiness.appleAutomation.keepHot(t),e.deviceReadiness.appleAutomation.markBooted(t),{...t,booted:!0}):{...t,booted:!0}}async function lt(t,n,r){let i=!1;try{let a=await t.appleTools.run({tool:`simctl`,args:S(n,[`boot`,n.id]),allowFailure:!0,timeoutMs:H},r),o=`${a.stdout}\n${a.stderr}`.toLowerCase(),s=o.includes(`already booted`)||o.includes(`current state: booted`);if(a.exitCode!==0&&!s)throw new e(`COMMAND_FAILED`,`simctl boot failed`,{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode});i=!s;let c=await t.appleTools.run({tool:`simctl`,args:S(n,[`bootstatus`,n.id,`-b`]),allowFailure:!0,timeoutMs:H},r);if(c.exitCode!==0)throw new e(`COMMAND_FAILED`,`simctl bootstatus failed`,{stdout:c.stdout,stderr:c.stderr,exitCode:c.exitCode});if(await W(t,n,r)!==`Booted`)throw new e(`COMMAND_FAILED`,`Simulator is still booting`,{deviceId:n.id})}catch(e){throw i&&r.aborted&&dt(t,n),r.throwIfAborted(),e}}async function W(e,t,n){return await pe(e.appleTools,t,n,15e3)}async function ut(e,t){await e.commands.run({executable:`open`,args:[`-a`,`Simulator`],allowFailure:!0,timeoutMs:1e4},t)}function dt(e,t){e.appleTools.run({tool:`simctl`,args:S(t,[`shutdown`,t.id]),allowFailure:!0}).catch(()=>{})}function ft(e){let t=ee({device:e.device,signal:e.signal,resolveInteractor:e.host.localInteractors.resolve});return Object.freeze({resolveOpenTarget:async t=>await e.host.appleApplications.resolveOpenTarget(e.device,t),prepareApplicationOpen:async t=>{await U(e.host,e.device,e.signal,{onColdBootStart:t.prewarmRunnerOnColdBoot?()=>{e.host.appleApplications.prewarmRunnerCache(e.device,t.execution,e.signal).catch(()=>{})}:void 0})},openApplication:async n=>await pt(e.host,t,n),applyRuntimeHints:async t=>await e.host.appleApplications.applyRuntimeHints(e.device,t),clearRuntimeHints:async t=>await e.host.appleApplications.clearRuntimeHints(e.device,t),closeApplication:async n=>await Ct(e.host,t,n),finalizeApplicationClose:async t=>await wt(e.host,e.device,e.signal,t),prepareAppleRunner:async t=>await Tt(e.host,e.device,e.signal,t),configureProviderPortReverse:kt})}async function pt(e,t,n){let r={},i=G(t.device),a=Et(e,t,n,r),o=m(t.device)&&n.surface===`app`&&n.positionals.length>0&&!!n.appBundleId;i&&o&&!n.prewarmRunnerBeforeOpen&&a.schedule(),await mt(e,t,n,i,r),await ht(n,r),await gt(a,o,n.prewarmRunnerBeforeOpen);let s=a.wasAwaited();return await _t(t,n,i,r),await yt(a,o,n.relaunch),await bt(e,t,n,i,s),await xt(e,t,i,r),{appBundleId:n.appBundleId,timing:r}}async function mt(e,t,r,i,a){if(!St(r,i)||!r.target)return;let o=Date.now();g(t.device.platform)&&!i&&await e.appleApplications.stopRunnerSession(t.device.id),await n({device:t.device,interactor:await t.resolveInteractor(r.execution,r.appBundleId),positionals:[r.appBundleId??r.target]}),i&&await e.clock.sleep(300,t.signal),a.relaunchCloseDurationMs=K(o)}async function ht(t,n){if(!u(t.runtimeHints))return;if(!t.applyRuntimeHints)throw new e(`COMMAND_FAILED`,`Runtime hint operation was not admitted for this open.`,{reason:`runtime-hints-operation-missing`});let r=Date.now();await t.applyRuntimeHints({appId:t.appBundleId,values:t.runtimeHints}),n.runtimeHintsDurationMs=K(r)}async function gt(e,t,n){!t||!n||(e.schedule(!0),await e.wait())}async function _t(e,t,n,r){let a=Dt(t,n),o=Date.now();await i({device:e.device,interactor:await e.resolveInteractor(t.execution,t.appBundleId),positionals:a.positionals,appBundleId:t.appBundleId,execution:t.execution,...n&&t.relaunch&&!t.execution.clearAppState?{terminateRunningApp:!0}:{}}),r.openDispatchDurationMs=K(o),await vt(e,t,a.followUpUrl,r)}async function vt(e,t,n,r){if(!n){r.launchUrlDurationMs=0;return}let a={...t.execution,clearAppState:void 0,launchConsole:void 0,launchArgs:void 0},o=Date.now();await i({device:e.device,interactor:await e.resolveInteractor(a,t.appBundleId),positionals:[n],appBundleId:t.appBundleId,execution:a}),r.launchUrlDurationMs=K(o)}async function yt(e,t,n){t&&!e.wasScheduled()&&e.schedule(),n?await e.wait():e.recordUnawaited()}async function bt(e,t,n,r,i){!r||!n.relaunch&&!i||await e.appleApplications.notifyRunnerAppRelaunched(t.device,n.execution,t.signal)}async function xt(e,t,n,r){let i=Date.now();n&&await e.clock.sleep(300,t.signal),r.postOpenSettleDurationMs=K(i)}function St(e,t){return!!(e.relaunch&&e.target)&&!(t&&!e.execution.clearAppState)}async function Ct(e,t,r){r.ensureReady&&await U(e,t.device,t.signal),g(t.device.platform)&&!G(t.device)&&await e.appleApplications.stopRunnerSession(t.device.id),await n({device:t.device,interactor:await t.resolveInteractor(r.execution,r.appBundleId),positionals:r.positionals}),G(t.device)&&await e.clock.sleep(300,t.signal)}async function wt(e,t,n,r){r.daemonShutdown?await e.appleApplications.dismissCloseAlerts(t,r).catch(()=>{}):r.retainRunner?(e.appleApplications.scheduleRunnerIdleStop(t.id),await e.appleApplications.dismissCloseAlerts(t,r).catch(()=>{})):(await e.appleApplications.stopRunnerSession(t.id),await e.appleApplications.dismissCloseAlerts(t,r).catch(()=>{}));let i=r.shutdownTarget&&G(t)?await e.deviceShutdown.apple.shutdownTarget(t,n):void 0;return i===void 0?{}:{shutdown:i}}async function Tt(e,t,n,r){return await U(e,t,n),await e.appleApplications.prepareRunner(t,r,n)}function Et(e,t,n,r){let i,a=!1;return{schedule:(a=!1)=>{i||=(r.runnerPrewarmKind=`session`,r.runnerPrewarmScheduled=!0,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=K(e)},wasAwaited:()=>a,wasScheduled:()=>i!==void 0,recordUnawaited:()=>{i&&!a&&(r.runnerPrewarmWaited=!1)}}}function Dt(e,t){let n=e.runtimeLaunchUrl?.trim(),i=e.positionals.length===1?e.positionals[0]?.trim():void 0;return!n||!i||r(i)?{positionals:e.positionals}:t&&!Ot(e)?{positionals:[i,n]}:{positionals:e.positionals,followUpUrl:n}}function Ot(e){return e.execution.clearAppState===!0||!!e.execution.launchConsole?.trim()||!!e.execution.launchArgs?.length}function G(e){return m(e)&&e.kind===`simulator`}function K(e){return Math.max(0,Date.now()-e)}async function kt(){throw new e(`UNSUPPORTED_OPERATION`,`This lifecycle operation is unavailable for Apple.`)}const q=Object.freeze({available:!0}),At=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.`}),jt=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Push notifications are supported on Apple simulators only.`}),J=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Mt=Object.freeze({available:!1,reason:`unsupported-device-kind`});function Y(e){let t=Bt(e);return Object.freeze({deployApp:t,materializeAppSource:t,deployMaterializedApp:t,sendPushNotification:Vt(e)})}function Nt(e){let{host:t,device:n,signal:r}=e,i=Y(n);return Object.freeze({...i.deployApp.available?{deployApp:async e=>await Pt(t,n,e,r),materializeAppSource:async e=>await t.appleDeployment.prepareArtifact(e,{signal:r}),deployMaterializedApp:async e=>await Ft(t,n,e,r)}:{},...i.sendPushNotification.available?{sendPushNotification:async e=>(await Rt(t,n,e,r),{})}:{}})}async function Pt(e,t,n,r){if(n.replaceExisting)return await e.appleDeployment.withInvalidatedAppResolutionCache(t,async()=>{let i=await e.appleDeployment.resolveAppBundleId(t,n.app);await Lt(e,t,i,r);let a=await e.appleDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{appIdentifierHint:n.app,signal:r});try{return await It(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 Ft(e,t,{artifact:i},r)}finally{await i.cleanup()}}async function Ft(e,t,n,r){return await It(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 It(e,t,n,r){await U(e,t,r),X(await e.appleTools.run(t.kind===`simulator`?{tool:`simctl`,args:S(t,[`install`,t.id,n])}:{tool:`devicectl`,args:[`device`,`install`,`app`,`--device`,t.id,n],timeoutMs:12e4},r),`Apple app install failed`)}async function Lt(e,t,n,r){await U(e,t,r);let i=await e.appleTools.run(t.kind===`simulator`?{tool:`simctl`,args:S(t,[`uninstall`,t.id,n]),allowFailure:!0}:{tool:`devicectl`,args:[`device`,`uninstall`,`app`,`--device`,t.id,n],allowFailure:!0},r);i.exitCode===0||zt(`${i.stdout}\n${i.stderr}`)||X(i,`Apple app uninstall failed for ${n}`)}async function Rt(t,n,r,i){if(n.kind!==`simulator`)throw new e(`UNSUPPORTED_OPERATION`,`Apple push notifications require a simulator`);await U(t,n,i);let a=await t.temporaryFiles.create({prefix:`agent-device-ios-push-`,suffix:`.apns`});try{await a.writeText(`${JSON.stringify(r.payload)}\n`),X(await t.appleTools.run({tool:`simctl`,args:S(n,[`push`,n.id,r.appId,a.path])},i),`Apple push notification failed`)}finally{await a[Symbol.asyncDispose]()}}function zt(e){let t=e.toLowerCase();return t.includes(`not installed`)||t.includes(`not found`)||t.includes(`no such file`)}function X(t,n){if(t.exitCode!==0)throw new e(`COMMAND_FAILED`,n,{stdout:t.stdout,stderr:t.stderr,exitCode:t.exitCode})}function Bt(e){return Ht(e)?e.kind!==`simulator`&&e.kind!==`device`?Mt:e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?At:q:J}function Vt(e){return Ht(e)?e.kind===`simulator`?q:jt:J}function Ht(e){return m(e)&&e.appleOs!==`watchos`}const Z=o(`apple`),Q=Object.freeze({available:!0}),$=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Ut=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple appstate reads the active session state; a sessionless runtime foreground probe is unavailable.`}),Wt=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Headless boot is supported only for local Android emulators.`}),Gt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS open is not supported because XCUITest cannot drive watchOS UI.`}),Kt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS runner preparation is not supported because XCUITest cannot drive watchOS UI.`}),qt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS close is not supported because XCUITest cannot drive watchOS UI.`}),Jt=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Runtime hints are supported only for local iOS-family simulators and Android devices.`}),Yt=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`open is supported only for Apple simulators and devices.`}),Xt=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`prepare is supported only for Apple simulators and devices.`}),Zt=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`close is supported only for Apple simulators and devices.`}),Qt=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`}),$t=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`shutdown is supported only for Apple simulators and Android emulators.`});function en(e){return!m(e)||e.appleOs===`watchos`?$:e.kind===`simulator`?Q:$t}function tn(e){let t=nn(e),n=rn(e),r=an(e),i=on(e);return a({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:i,clearRuntimeHints:i,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:n,configureProviderPortReverse:Qt})}function nn(e){return _(e)===`watchos`?Gt:e.kind===`simulator`||e.kind===`device`?Q:Yt}function rn(e){return _(e)===`watchos`?Kt:e.kind===`simulator`||e.kind===`device`?Q:Xt}function an(e){return _(e)===`watchos`?qt:e.kind===`simulator`||e.kind===`device`?Q:Zt}function on(e){return _(e)!==`watchos`&&m(e)&&e.kind===`simulator`?Q:Jt}function sn(e){return e.appleOs===`watchos`?Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS app inventory is not supported.`}):e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`App inventory is available only on CoreDevice-backed physical iOS devices.`}):Q}function cn(e){let t=Pe(e),n=async n=>{let r=await t.inspectFacts(n),i=Y(n),a=tt(n),o=a.available?await e.screenRecording.apple.availability(n):void 0,s=a.available&&o?.available===!1?Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:o.hint}):a,c=n.appleOs===`watchos`?$:Q,l=h(n)||n.appleOs===`watchos`?$:Q,u=sn(n);return Object.freeze({device:r.device,operations:{...r.operations,...i,appState:Ut,networkDump:Q,screenRecordingStart:s,screenRecordingReattach:s,screenRecordingCleanup:s,ensureReady:c,bootTarget:l,bootTargetHeadless:Wt,listApps:u,...tn(n),shutdownTarget:en(n)}})};return Object.freeze({owner:Z,ownsDevice:e=>e.platform===`apple`,inspectFacts:n,bind:async r=>{let i=await t.bind(r),a=await n(r.device),o=a.operations.screenRecordingStart;return Object.freeze({device:i.device,owner:Z,facts:a,operations:Object.freeze({...i.operations,...Nt({host:e,device:r.device,signal:r.scope.signal}),networkDump:async t=>await Le(e,r.device,t,r.scope.signal),...o.available?nt({host:e,device:r.device,owner:Z,signal:r.scope.signal}):{},...a.operations.ensureReady.available?{ensureReady:async()=>await U(e,r.device,r.scope.signal)}:{},...a.operations.bootTarget.available?{bootTarget:async()=>await U(e,r.device,r.scope.signal)}:{},...a.operations.listApps.available?{listApps:async t=>await e.appInventory.apple.listApps(t.device,t.filter,r.scope.signal)}:{},...l(ft({host:e,device:r.device,signal:r.scope.signal}),a.operations),...a.operations.shutdownTarget.available?{shutdownTarget:async()=>await e.deviceShutdown.apple.shutdownTarget(r.device,r.scope.signal)}:{}}),[Symbol.asyncDispose]:async()=>await i[Symbol.asyncDispose]()})},shutdown:async()=>await t.shutdown()})}export{cn as createApplePlatformRuntime};
1
+ import{_ as e,v as t}from"./sdk-contracts.js";import{At as n,Et as r,G as i,J as a,V as o,W as s,dt as c,ft as l,gt as u,ht as ee,lt as d,nt as f,rt as p,st as te,ut as ne}from"./sdk-batch-runner.js";import{C as re,c as m,l as h,s as ie,x as g}from"./sdk-device.js";import{c as ae,f as oe,g as se,h as ce,i as _,l as le,m as ue,n as v,p as de,r as y,s as b,t as fe,u as pe,v as me,x}from"./src3.js";import{n as S,t as he}from"./simulator-state.js";import ge from"node:path";const C=`This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.`;function w(e){return h(e)?`macos`:e.kind===`device`?`ios-device`:`ios-simulator`}const _e=Object.freeze({resourceKind:p,version:1,encode:e=>({...e}),decode:e=>!ye(e.transport)||!be(e.backend)||!we(e.outputPath)||!Se(e.pidPath)||!xe(e.transport,e.backend)?ve():{status:`decoded`,descriptor:Object.freeze({transport:e.transport,backend:e.backend,outputPath:e.outputPath,...e.pidPath===void 0?{}:{pidPath:e.pidPath}})}});function ve(){return{status:`invalid`,message:`Invalid Apple app-log descriptor`}}function ye(e){return e===`apple-log-stream`||e===`coredevice-console`}function be(e){return e===`ios-simulator`||e===`ios-device`||e===`macos`}function xe(e,t){return e===`coredevice-console`?t===`ios-device`:t!==`ios-device`}function Se(e){return e===void 0||we(e)}function Ce(e){if(!e.device.appleOs)throw TypeError(`Apple app-log persistence requires an explicit appleOs identity`);return me({resourceKind:p,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:x(_e,e.descriptor)})}function we(e){return typeof e==`string`&&e.trim().length>0}const Te={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.`},Ee={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 De(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 Oe(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(h(t))i.logAvailable=!!await e.commands.which(`log`);else if(t.kind===`simulator`)i.simctlAvailable=await _(async()=>y(await e.appleTools.run({tool:`simctl`,args:[`help`],allowFailure:!0},r)),r);else if(t.iosPhysicalDeviceBackend===`xctest`)i.devicectlAvailable=!1,i.devicectlConsoleCapture=!1,a.push(C);else{i.devicectlAvailable=await _(async()=>y(await e.appleTools.run({tool:`devicectl`,args:[`--version`],allowFailure:!0},r)),r);let t=await De(e,r);if(i.devicectlConsoleCapture=t.supported,!t.supported){let e=t.reason===`unsupported`?Te:Ee;a.push(`${e.message} ${e.hint}`)}}return{backend:w(t),checks:i,notes:a}}function T(e,t){let n=E(e),r=[`subsystem == "${n}"`,`subsystem CONTAINS "${n}"`,`processImagePath ENDSWITH[c] "/${n}"`,`senderImagePath ENDSWITH[c] "/${n}"`];if(t){let e=E(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 ke(e){return[...e.simulatorSetPath?[`simctl`,`--set`,e.simulatorSetPath]:[`simctl`],`spawn`,e.deviceId,`log`,`stream`,`--style`,`compact`,`--level`,`info`,`--predicate`,T(e.appBundleId,e.executableName)]}function Ae(e,t){return[`devicectl`,`device`,`process`,`launch`,`--device`,e,`--console`,`--terminate-existing`,t]}function E(e){return e.replaceAll(`\\`,`\\\\`).replaceAll(`"`,`\\"`)}async function je(e,t,n,r,i){Me(t),ae(e,n);let a=w(t),o=await Pe(e,t,n.appBundleId,i),s=new ee,c=!1;try{let l=await e.outputs.openAppend(n.outputPath);s.defer(async()=>{c||await l[Symbol.asyncDispose]()}),i?.throwIfAborted();let u=await Ne(e,t,o,l,n.pidPath,i);s.defer(async()=>{c||await u[Symbol.asyncDispose]()});let ee=Ie(e,u,l,a,n.outputPath),d={transport:a===`ios-device`?`coredevice-console`:`apple-log-stream`,backend:a,outputPath:n.outputPath,...n.pidPath===void 0?{}:{pidPath:n.pidPath}},f=se(ee,Ce({sessionId:n.sessionId,device:t,owner:r,fence:n.fence,descriptor:d}));return c=!0,f}finally{await s[Symbol.asyncDispose]()}}function Me(t){if(t.appleOs===`watchos`)throw new e(`UNSUPPORTED_PLATFORM`,`watchOS app logs are not supported`);if(m(t)&&t.kind===`device`&&t.iosPhysicalDeviceBackend===`xctest`)throw new e(`UNSUPPORTED_OPERATION`,C,{hint:C})}async function Ne(t,n,r,i,a,o){if(m(n)&&n.kind===`device`){let n=await De(t,o);if(!n.supported){let t=n.reason===`unsupported`?Te:Ee;throw new e(n.reason===`unsupported`?`UNSUPPORTED_OPERATION`:`COMMAND_FAILED`,t.message,{backend:`ios-device`,hint:t.hint,stderr:n.stderr})}}return o?.throwIfAborted(),await t.processes.start({command:{kind:`host`,request:r},output:i,...a?{markerPath:a}:{}})}async function Pe(e,t,n,r){if(h(t))return{executable:`log`,args:[`stream`,`--style`,`compact`,`--predicate`,T(n)],allowFailure:!0};if(t.kind===`device`)return{executable:`xcrun`,args:Ae(t.id,n),allowFailure:!0};let i=await Fe(e,t,n,r);return{executable:`xcrun`,args:ke({deviceId:t.id,appBundleId:n,executableName:i,simulatorSetPath:t.simulatorSetPath}),allowFailure:!0}}async function Fe(e,t,n,r){let i=t.simulatorSetPath?[`--set`,t.simulatorSetPath]:[],a=await e.appleTools.run({tool:`simctl`,args:[...i,`get_app_container`,t.id,n,`app`],allowFailure:!0,timeoutMs:4e3},r),o=a.exitCode===0?a.stdout.trim():``;if(!o)return;let s=await e.commands.run({executable:`plutil`,args:[`-extract`,`CFBundleExecutable`,`raw`,`-o`,`-`,ge.join(o,`Info.plist`)],allowFailure:!0,timeoutMs:4e3},r);return s.exitCode===0&&s.stdout.trim()||void 0}function Ie(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 ue({inspect:()=>({backend:r,state:o,startedAt:a}),finish:async()=>s??=(async()=>(await Le([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 Le(e){let t=[];for(let n of e)try{await n()}catch(e){t.push(e)}return t}const D=r(`apple`),O=Object.freeze({available:!0});function Re(t){return Object.freeze({owner:D,ownsDevice:e=>e.platform===`apple`,inspectFacts:async e=>k(e),bind:async r=>{if(r.intent.kind===`exact-owner`&&!n(r.intent.owner,D))throw new e(`UNSUPPORTED_OPERATION`,`Apple app-log owner identity does not match`);return ze(t,r.device,r.scope.signal)},shutdown:async()=>void 0})}function ze(t,n,r){if(n.platform!==`apple`)throw new e(`UNSUPPORTED_PLATFORM`,`Apple app-log owner cannot bind ${n.platform}`);let i=ce({codec:_e,reattach:async(e,r)=>e.backend!==w(n)||!b(t,r.sessionId,e)?{status:`unreattachable`,reason:`descriptor-invalid`,message:`Apple app-log descriptor does not match the bound device or owning session`}:await pe(t,e.pidPath),cleanup:async(e,r)=>e.backend===w(n)&&b(t,r.sessionId,e)?await le(t,e.pidPath):{status:`cleanup-pending`,reason:`ownership-fence-lost`,message:`Apple app-log descriptor does not match the bound device or owning session`}}),a=Object.freeze({appLogInspect:async()=>({backend:w(n)}),appLogDoctor:async({appBundleId:e})=>await Oe(t,n,e,r),appLogStart:async e=>await je(t,n,e,D,r),...i});return Object.freeze({device:n,owner:D,facts:k(n),operations:a,[Symbol.asyncDispose]:async()=>void 0})}function k(e){if(e.appleOs===`watchos`)return Be(e);let t=m(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?{available:!1,reason:`unsupported-device-backend`,hint:C}:O;return Object.freeze({device:{family:`apple`,appleOs:e.appleOs,kind:e.kind,...e.target===void 0?{}:{target:e.target},...e.iosPhysicalDeviceBackend===void 0?{}:{iosPhysicalDeviceBackend:e.iosPhysicalDeviceBackend},providerMode:`local`},operations:{appLogInspect:t,appLogDoctor:t,appLogStart:t,appLogReattach:O,appLogCleanup:O}})}function Be(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 Ve(e,t,n,r){let i=w(t),a=await e.appLogs.readRecent(n.sessionId,n.maxScanLines),o=v(a.text,{...n,path:a.path,exists:a.exists,lineNumberOffset:a.skippedLines,backend:i}),s=[];if(He(t,n,o)){let i=await Ue(e,t,n,a.path,r);i&&(i.dump.entries.length>0?(o=fe(i.dump,o,n.maxEntries),s.push(`Recovered ${i.dump.entries.length} iOS simulator HTTP entr${i.dump.entries.length===1?`y`:`ies`} from simctl log show (${i.lineCount} app log lines scanned).`)):i.lineCount>0&&s.push(`Recovered ${i.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.`))}return Ge(s,t,n),o.entries.length===0&&s.push(Ke(t)),Object.freeze({source:`app-log`,backend:i,dump:o,notes:Object.freeze(s)})}function He(e,t,n){return m(e)&&e.kind===`simulator`&&!!t.appBundleId&&n.entries.length===0}async function Ue(e,t,n,r,i){let a=[...t.simulatorSetPath?[`--set`,t.simulatorSetPath]:[],`spawn`,t.id,`log`,`show`,`--style`,`compact`,`--info`,`--predicate`,We(n.appBundleId)],o=n.appLogSnapshot?.startedAt;a.push(...typeof o==`number`&&Number.isFinite(o)&&o>0?[`--start`,`@${Math.floor(o/1e3)}`]:[`--last`,`5m`]);let s=await e.appleTools.run({tool:`simctl`,args:a,allowFailure:!0,timeoutMs:4e3},i);if(s.exitCode!==0||!s.stdout.trim())return;let c=s.stdout.split(`
2
+ `).map(e=>e.trimEnd()).filter(e=>e.trim()&&!e.trim().startsWith(`Timestamp Ty Process[PID:TID]`));if(c.length!==0)return{dump:v(`${c.join(`
3
+ `)}\n`,{...n,path:`${r} (simctl log show recovery)`,exists:!0,backend:`ios-simulator`}),lineCount:c.length}}function We(e){let t=e.replaceAll(`\\`,`\\\\`).replaceAll(`"`,`\\"`);return[`subsystem == "${t}"`,`subsystem CONTAINS "${t}"`,`processImagePath ENDSWITH[c] "/${t}"`,`senderImagePath ENDSWITH[c] "/${t}"`].join(` OR `)}function Ge(e,t,n){n.appLogSnapshot?n.appLogSnapshot.state!==`active`&&e.length===0&&e.push(m(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 Ke(e){return m(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.`:m(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 A(e,n,r){if(n.invalidatedReason&&!n.showTouches)throw Error(`recording invalidated: ${n.invalidatedReason}`);let i;try{i=await e.screenRecording.finalize.complete({outputPath:n.outPath,showTouches:n.invalidatedReason?!1:n.showTouches,gestureEvents:n.gestureEvents,exportQuality:n.exportQuality??`medium`,...n.runnerStartedAtUptimeMs!==void 0&&n.targetAppReadyUptimeMs!==void 0?{trimStartMs:Math.max(0,n.targetAppReadyUptimeMs-n.runnerStartedAtUptimeMs)}:{},targetLabel:r})}catch(e){throw t(e,`COMMAND_FAILED`)}return oe(n,{...i,...n.invalidatedReason?{overlayWarning:`overlay unavailable: ${n.invalidatedReason}`}:{}})}const j=Object.freeze({resourceKind:f,version:1,encode:e=>e.backend===`simctl`?{backend:e.backend,outputPath:e.outputPath,processes:e.processes.map(e=>({...e}))}:{backend:e.backend,outputPath:e.outputPath,appBundleId:e.appBundleId,runnerSessionId:e.runnerSessionId,runnerAuthority:e.runnerAuthority,...e.remotePath===void 0?{}:{remotePath:e.remotePath}},decode:e=>Qe(e)});function qe(e){let{device:t,owner:n,input:r,descriptor:i}=e;return me({resourceKind:f,sessionId:r.sessionId,device:re(t),owner:n,fence:r.fence,lifecycle:`open`,descriptor:x(j,i)})}async function Je(e,t,n){let r=j.decode(n);return r.status!==`decoded`||!P(t,r.descriptor)?{status:`cleanup-pending`,reason:`manual-recovery-required`}:r.descriptor.backend===`simctl`?await Ye(e,r.descriptor.processes):await Xe(e,t,r.descriptor)}async function Ye(e,t){let n=await Promise.all(t.map(async t=>await e.screenRecording.apple.inspectProcess(t)));if(n.includes(`ownership-lost`))return{status:`cleanup-pending`,reason:`ownership-fence-lost`};if(n.every(e=>e===`missing`))return{status:`already-missing`};let r=await Promise.all(t.flatMap((t,r)=>n[r]===`owned-alive`?[e.screenRecording.apple.terminateProcess(t)]:[]));return r.includes(`ownership-lost`)?{status:`cleanup-pending`,reason:`ownership-fence-lost`}:r.every(e=>e===`already-missing`)?{status:`already-missing`}:{status:`cleaned`}}async function Xe(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 Ze(e,t,n){let r=j.decode(n);if(r.status!==`decoded`)return{status:`unreattachable`,reason:`descriptor-invalid`,message:r.message};if(!P(t,r.descriptor))return{status:`unreattachable`,reason:`descriptor-invalid`,message:`Apple screen-recording descriptor does not match the bound device.`};let i=r.descriptor.backend===`simctl`?await Promise.all(r.descriptor.processes.map(async t=>await e.screenRecording.apple.inspectProcess(t))):[await e.screenRecording.apple.inspectRunner(t,r.descriptor.runnerSessionId,r.descriptor.runnerAuthority)];return i.every(e=>e===`missing`)?{status:`missing`}:{status:`unreattachable`,reason:`transport-not-reattachable`,message:i.includes(`ownership-lost`)?`Apple recording ownership no longer matches the durable descriptor.`:`Apple screen recordings require exact cleanup after daemon restart.`}}function Qe(e){return typeof e.outputPath!=`string`||e.outputPath.length===0?F():e.backend===`simctl`?$e(e,e.outputPath):e.backend===`runner`?et(e,e.outputPath):F()}function $e(e,t){let n=rt(e.processes);return n?{status:`decoded`,descriptor:Object.freeze({backend:`simctl`,outputPath:t,processes:n})}:F()}function et(e,t){return!M(e.appBundleId)||!M(e.runnerSessionId)||!tt(e.runnerAuthority)||!nt(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 M(e){return typeof e==`string`&&e.length>0}function tt(e){return e===`local-lease`||e===`scoped-provider`}function nt(e){return e===void 0||N(e)}function N(e){return typeof e==`string`&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(e)}function P(e,t){return e.kind===`simulator`?t.backend===`simctl`:t.backend===`runner`?e.appleOs===`macos`?t.remotePath===void 0:m(e)?t.remotePath!==void 0&&N(t.remotePath):t.remotePath===void 0:!1}function rt(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 it(e,t,n){if(e.kind!==`simulator`||t.scope!==`app`)return;let r=t.activeSessionApp?.bundleId;if(!r)throw TypeError(`App-scoped recording requires an active app session; open the app under test before recording.`);if(await n(r))throw TypeError(`App-scoped recording requires a real application session; open the app under test before recording.`)}function at(e){return e.appleOs===`watchos`?z(`unsupported-platform-leaf`,`watchOS recording is not supported.`):m(e)&&e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?z(`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 ot(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await st({host:t,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async e=>await Ze(t,n,e.envelope.descriptor.body),screenRecordingCleanup:async e=>await Je(t,n,e.envelope.descriptor.body)})}async function st(e){return e.signal.throwIfAborted(),e.device.kind===`simulator`?await ct(e):await lt(e)}async function ct(e){let{host:t,device:n,owner:r,input:i,signal:a}=e;await it(n,i,t.screenRecording.apple.isRunnerBundleId);let o=i.activeSessionApp?await t.screenRecording.apple.captureClockAnchor(n,i.activeSessionApp.bundleId,a):void 0;await t.screenRecording.outputs.prepare(i.outputPath);let s=await t.screenRecording.apple.startSimulator(n,i.outputPath,a),c=s.markers;if(!c||c.length===0)throw await I(s).catch(()=>{}),Error(`simctl recordVideo did not expose durable process identity`);try{a.throwIfAborted()}catch(e){throw await I(s).catch(()=>{}),e}return L({device:n,owner:r,input:i,descriptor:{backend:`simctl`,outputPath:i.outputPath,processes:c},snapshot:R(i,`simctl recordVideo`,{},o),finish:async e=>{await s.terminate();let n=await s.wait;if(n.exitCode!==0)throw Error(`simctl recordVideo exited with code ${n.exitCode}`);return await A(t,e,`iOS recording`)},cleanup:async()=>await ft(s)})}async function lt(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??=ut(()=>t.screenRecording.apple.runRunner(n,{kind:`stop`,appBundleId:o,...c}).then(()=>void 0));if(!dt(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 L({device:n,owner:r,input:i,descriptor:{backend:`runner`,outputPath:i.outputPath,appBundleId:o,...c,...s.remotePath===void 0?{}:{remotePath:s.remotePath}},snapshot:R(i,`runner AVAssetWriter`,s),finish:async e=>(await u(),s.remotePath!==void 0&&await t.screenRecording.apple.retrieveRunnerRecording(n,s.remotePath,e.outPath),await A(t,e,n.appleOs===`macos`?`macOS recording`:`iOS recording`)),cleanup:async()=>(await u(),{status:`cleaned`})})}async function ut(e){try{return await e()}catch(e){throw t(e,`COMMAND_FAILED`)}}function dt(e,t){return e.appleOs===`macos`||!m(e)?t===void 0:t!==void 0&&/^tmp\/agent-device-recording-\d+\.mp4$/.test(t)}async function I(e){return await e.terminate(),await e.wait}async function ft(e){try{return await I(e),{status:`cleaned`}}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`Apple simulator cleanup failed`}}}function L(e){let{device:t,owner:n,input:r,descriptor:i,snapshot:a,finish:o,cleanup:s}=e,c=de(a,{finish:o,forceCleanup:s});return Object.freeze({pendingHandle:new u(c),envelope:qe({device:t,owner:n,input:r,descriptor:i})})}function R(e,t,n={},r){let i=Date.now();return Object.freeze({backend:t,outPath:e.outputPath,...e.clientOutputPath===void 0?{}:{clientOutPath:e.clientOutputPath},startedAt:i,scope:e.scope,showTouches:e.showTouches,recordOnlySession:e.recordOnlySession,...e.activeSessionApp===void 0?{}:{activeSessionApp:e.activeSessionApp},...e.exportQuality===void 0?{}:{exportQuality:e.exportQuality},gestureEvents:[],...r===void 0?{}:{gestureClockOriginAtMs:r.wallClockAtMs,gestureClockOriginUptimeMs:r.uptimeMs},...n.recorderStartUptimeMs===void 0?{}:{gestureClockOriginAtMs:i,gestureClockOriginUptimeMs:n.recorderStartUptimeMs,runnerStartedAtUptimeMs:n.recorderStartUptimeMs},...n.targetAppReadyUptimeMs===void 0?{}:{targetAppReadyUptimeMs:n.targetAppReadyUptimeMs},...n.runnerSessionId===void 0?{}:{runnerSessionId:n.runnerSessionId}})}function z(e,t){return Object.freeze({available:!1,reason:e,hint:t})}const B=12e4;async function V(e,t,n,r={}){return n.throwIfAborted(),h(t)?{...t,booted:!0}:t.kind===`device`?(await e.deviceReadiness.applePhysical.ensureConnected(t,n),{...t,booted:!0}):t.kind===`simulator`?(await H(e,t,n)!==`Booted`&&(r.onColdBootStart?.(),e.deviceReadiness.appleAutomation.keepHot(t),await pt(e,t,n),await mt(e,n)),e.deviceReadiness.appleAutomation.keepHot(t),e.deviceReadiness.appleAutomation.markBooted(t),{...t,booted:!0}):{...t,booted:!0}}async function pt(t,n,r){let i=!1;try{let a=await t.appleTools.run({tool:`simctl`,args:S(n,[`boot`,n.id]),allowFailure:!0,timeoutMs:B},r),o=`${a.stdout}\n${a.stderr}`.toLowerCase(),s=o.includes(`already booted`)||o.includes(`current state: booted`);if(a.exitCode!==0&&!s)throw new e(`COMMAND_FAILED`,`simctl boot failed`,{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode});i=!s;let c=await t.appleTools.run({tool:`simctl`,args:S(n,[`bootstatus`,n.id,`-b`]),allowFailure:!0,timeoutMs:B},r);if(c.exitCode!==0)throw new e(`COMMAND_FAILED`,`simctl bootstatus failed`,{stdout:c.stdout,stderr:c.stderr,exitCode:c.exitCode});if(await H(t,n,r)!==`Booted`)throw new e(`COMMAND_FAILED`,`Simulator is still booting`,{deviceId:n.id})}catch(e){throw i&&r.aborted&&ht(t,n),r.throwIfAborted(),e}}async function H(e,t,n){return await he(e.appleTools,t,n,15e3)}async function mt(e,t){await e.commands.run({executable:`open`,args:[`-a`,`Simulator`],allowFailure:!0,timeoutMs:1e4},t)}function ht(e,t){e.appleTools.run({tool:`simctl`,args:S(t,[`shutdown`,t.id]),allowFailure:!0}).catch(()=>{})}function gt(e){let t=o({device:e.device,signal:e.signal,resolveInteractor:e.host.localInteractors.resolve});return Object.freeze({resolveOpenTarget:async t=>await e.host.appleApplications.resolveOpenTarget(e.device,t),prepareApplicationOpen:async t=>{await V(e.host,e.device,e.signal,{onColdBootStart:t.prewarmRunnerOnColdBoot?()=>{e.host.appleApplications.prewarmRunnerCache(e.device,t.execution,e.signal).catch(()=>{})}:void 0})},openApplication:async n=>await _t(e.host,t,n),applyRuntimeHints:async t=>await e.host.appleApplications.applyRuntimeHints(e.device,t),clearRuntimeHints:async t=>await e.host.appleApplications.clearRuntimeHints(e.device,t),closeApplication:async n=>await Dt(e.host,t,n),finalizeApplicationClose:async t=>await Ot(e.host,e.device,e.signal,t),prepareAppleRunner:async t=>await kt(e.host,e.device,e.signal,t),configureProviderPortReverse:Nt})}async function _t(e,t,n){let r={},i=U(t.device),a=At(e,t,n,r),o=m(t.device)&&n.surface===`app`&&n.positionals.length>0&&!!n.appBundleId;i&&o&&!n.prewarmRunnerBeforeOpen&&a.schedule(),await vt(e,t,n,i,r),await yt(n,r),await bt(a,o,n.prewarmRunnerBeforeOpen);let s=a.wasAwaited();return await xt(t,n,i,r),await Ct(a,o,n.relaunch),await wt(e,t,n,i,s),await Tt(e,t,i,r),{appBundleId:n.appBundleId,timing:r}}async function vt(e,t,n,r,i){if(!Et(n,r)||!n.target)return;let a=Date.now();ie(t.device.platform)&&!r&&await e.appleApplications.stopRunnerSession(t.device.id),await s({device:t.device,interactor:await t.resolveInteractor(n.execution,n.appBundleId),positionals:[n.appBundleId??n.target]}),r&&await e.clock.sleep(300,t.signal),i.relaunchCloseDurationMs=W(a)}async function yt(t,n){if(!l(t.runtimeHints))return;if(!t.applyRuntimeHints)throw new e(`COMMAND_FAILED`,`Runtime hint operation was not admitted for this open.`,{reason:`runtime-hints-operation-missing`});let r=Date.now();await t.applyRuntimeHints({appId:t.appBundleId,values:t.runtimeHints}),n.runtimeHintsDurationMs=W(r)}async function bt(e,t,n){!t||!n||(e.schedule(!0),await e.wait())}async function xt(e,t,n,r){let a=jt(t,n),o=Date.now();await i({device:e.device,interactor:await e.resolveInteractor(t.execution,t.appBundleId),positionals:a.positionals,appBundleId:t.appBundleId,execution:t.execution,...n&&t.relaunch&&!t.execution.clearAppState?{terminateRunningApp:!0}:{}}),r.openDispatchDurationMs=W(o),await St(e,t,a.followUpUrl,r)}async function St(e,t,n,r){if(!n){r.launchUrlDurationMs=0;return}let a={...t.execution,clearAppState:void 0,launchConsole:void 0,launchArgs:void 0},o=Date.now();await i({device:e.device,interactor:await e.resolveInteractor(a,t.appBundleId),positionals:[n],appBundleId:t.appBundleId,execution:a}),r.launchUrlDurationMs=W(o)}async function Ct(e,t,n){t&&!e.wasScheduled()&&e.schedule(),n?await e.wait():e.recordUnawaited()}async function wt(e,t,n,r,i){!r||!n.relaunch&&!i||await e.appleApplications.notifyRunnerAppRelaunched(t.device,n.execution,t.signal)}async function Tt(e,t,n,r){let i=Date.now();n&&await e.clock.sleep(300,t.signal),r.postOpenSettleDurationMs=W(i)}function Et(e,t){return!!(e.relaunch&&e.target)&&!(t&&!e.execution.clearAppState)}async function Dt(e,t,n){n.ensureReady&&await V(e,t.device,t.signal),ie(t.device.platform)&&!U(t.device)&&await e.appleApplications.stopRunnerSession(t.device.id),await s({device:t.device,interactor:await t.resolveInteractor(n.execution,n.appBundleId),positionals:n.positionals}),U(t.device)&&await e.clock.sleep(300,t.signal)}async function Ot(e,t,n,r){r.daemonShutdown?await e.appleApplications.dismissCloseAlerts(t,r).catch(()=>{}):r.retainRunner?(e.appleApplications.scheduleRunnerIdleStop(t.id),await e.appleApplications.dismissCloseAlerts(t,r).catch(()=>{})):(await e.appleApplications.stopRunnerSession(t.id),await e.appleApplications.dismissCloseAlerts(t,r).catch(()=>{}));let i=r.shutdownTarget&&U(t)?await e.deviceShutdown.apple.shutdownTarget(t,n):void 0;return i===void 0?{}:{shutdown:i}}async function kt(e,t,n,r){return await V(e,t,n),await e.appleApplications.prepareRunner(t,r,n)}function At(e,t,n,r){let i,a=!1;return{schedule:(a=!1)=>{i||=(r.runnerPrewarmKind=`session`,r.runnerPrewarmScheduled=!0,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=W(e)},wasAwaited:()=>a,wasScheduled:()=>i!==void 0,recordUnawaited:()=>{i&&!a&&(r.runnerPrewarmWaited=!1)}}}function jt(e,t){let n=e.runtimeLaunchUrl?.trim(),r=e.positionals.length===1?e.positionals[0]?.trim():void 0;return!n||!r||a(r)?{positionals:e.positionals}:t&&!Mt(e)?{positionals:[r,n]}:{positionals:e.positionals,followUpUrl:n}}function Mt(e){return e.execution.clearAppState===!0||!!e.execution.launchConsole?.trim()||!!e.execution.launchArgs?.length}function U(e){return m(e)&&e.kind===`simulator`}function W(e){return Math.max(0,Date.now()-e)}async function Nt(){throw new e(`UNSUPPORTED_OPERATION`,`This lifecycle operation is unavailable for Apple.`)}const G=Object.freeze({available:!0}),Pt=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.`}),Ft=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Push notifications are supported on Apple simulators only.`}),K=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),It=Object.freeze({available:!1,reason:`unsupported-device-kind`});function q(e){let t=Wt(e);return Object.freeze({deployApp:t,materializeAppSource:t,deployMaterializedApp:t,sendPushNotification:Gt(e)})}function Lt(e){let{host:t,device:n,signal:r}=e,i=q(n);return Object.freeze({...i.deployApp.available?{deployApp:async e=>await Rt(t,n,e,r),materializeAppSource:async e=>await t.appleDeployment.prepareArtifact(e,{signal:r}),deployMaterializedApp:async e=>await zt(t,n,e,r)}:{},...i.sendPushNotification.available?{sendPushNotification:async e=>(await Ht(t,n,e,r),{})}:{}})}async function Rt(e,t,n,r){if(n.replaceExisting)return await e.appleDeployment.withInvalidatedAppResolutionCache(t,async()=>{let i=await e.appleDeployment.resolveAppBundleId(t,n.app);await Vt(e,t,i,r);let a=await e.appleDeployment.prepareArtifact({source:{kind:`path`,path:n.appPath}},{appIdentifierHint:n.app,signal:r});try{return await Bt(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 zt(e,t,{artifact:i},r)}finally{await i.cleanup()}}async function zt(e,t,n,r){return await Bt(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 Bt(e,t,n,r){await V(e,t,r),J(await e.appleTools.run(t.kind===`simulator`?{tool:`simctl`,args:S(t,[`install`,t.id,n])}:{tool:`devicectl`,args:[`device`,`install`,`app`,`--device`,t.id,n],timeoutMs:12e4},r),`Apple app install failed`)}async function Vt(e,t,n,r){await V(e,t,r);let i=await e.appleTools.run(t.kind===`simulator`?{tool:`simctl`,args:S(t,[`uninstall`,t.id,n]),allowFailure:!0}:{tool:`devicectl`,args:[`device`,`uninstall`,`app`,`--device`,t.id,n],allowFailure:!0},r);i.exitCode===0||Ut(`${i.stdout}\n${i.stderr}`)||J(i,`Apple app uninstall failed for ${n}`)}async function Ht(t,n,r,i){if(n.kind!==`simulator`)throw new e(`UNSUPPORTED_OPERATION`,`Apple push notifications require a simulator`);await V(t,n,i);let a=await t.temporaryFiles.create({prefix:`agent-device-ios-push-`,suffix:`.apns`});try{await a.writeText(`${JSON.stringify(r.payload)}\n`),J(await t.appleTools.run({tool:`simctl`,args:S(n,[`push`,n.id,r.appId,a.path])},i),`Apple push notification failed`)}finally{await a[Symbol.asyncDispose]()}}function Ut(e){let t=e.toLowerCase();return t.includes(`not installed`)||t.includes(`not found`)||t.includes(`no such file`)}function J(t,n){if(t.exitCode!==0)throw new e(`COMMAND_FAILED`,n,{stdout:t.stdout,stderr:t.stderr,exitCode:t.exitCode})}function Wt(e){return Kt(e)?e.kind!==`simulator`&&e.kind!==`device`?It:e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?Pt:G:K}function Gt(e){return Kt(e)?e.kind===`simulator`?G:Ft:K}function Kt(e){return m(e)&&e.appleOs!==`watchos`}function qt(e,t){let n=te({device:t.device,signal:t.signal,resolveInteractor:e.localInteractors.resolve}),r=async r=>h(t.device)&&r.options?.surface!==void 0&&r.options.surface!==`app`?await e.snapshot.captureSurface(t.device,r.options,t.signal):await n.captureSnapshot(r);return Object.freeze({captureSnapshot:r,captureSnapshotWithCustomActions:r,captureSnapshotWithoutActiveApp:r})}const Y=r(`apple`),X=Object.freeze({available:!0}),Z=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),Jt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple appstate reads the active session state; a sessionless runtime foreground probe is unavailable.`}),Yt=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Headless boot is supported only for local Android emulators.`}),Xt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS open is not supported because XCUITest cannot drive watchOS UI.`}),Zt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS runner preparation is not supported because XCUITest cannot drive watchOS UI.`}),Qt=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS close is not supported because XCUITest cannot drive watchOS UI.`}),$t=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`Runtime hints are supported only for local iOS-family simulators and Android devices.`}),en=$(`open is supported only for Apple simulators and devices.`),tn=$(`prepare is supported only for Apple simulators and devices.`),nn=$(`close is supported only for Apple simulators and devices.`),rn=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`}),an=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`shutdown is supported only for Apple simulators and Android emulators.`}),Q=$(`snapshot is supported only for Apple simulators and devices.`),on=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Re-run without --actions, or target an iOS simulator.`}),sn=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`Open the app under test before capturing its snapshot.`});function $(e){return Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:e})}function cn(e){return!m(e)||e.appleOs===`watchos`?Z:e.kind===`simulator`?X:an}function ln(e){let t=un(e),n=dn(e),r=fn(e),i=pn(e);return ne({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:i,clearRuntimeHints:i,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:n,configureProviderPortReverse:rn})}function un(e){return g(e)===`watchos`?Xt:e.kind===`simulator`||e.kind===`device`?X:en}function dn(e){return g(e)===`watchos`?Zt:e.kind===`simulator`||e.kind===`device`?X:tn}function fn(e){return g(e)===`watchos`?Qt:e.kind===`simulator`||e.kind===`device`?X:nn}function pn(e){return g(e)!==`watchos`&&m(e)&&e.kind===`simulator`?X:$t}function mn(e){return e.appleOs===`watchos`?Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`watchOS app inventory is not supported.`}):e.kind===`device`&&e.iosPhysicalDeviceBackend===`xctest`?Object.freeze({available:!1,reason:`unsupported-device-backend`,hint:`App inventory is available only on CoreDevice-backed physical iOS devices.`}):X}function hn(e){let t=Re(e),n=async n=>{let r=await t.inspectFacts(n),i=q(n),a=at(n),o=a.available?await e.screenRecording.apple.availability(n):void 0,s=a.available&&o?.available===!1?Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:o.hint}):a,c=n.appleOs===`watchos`?Z:X,l=h(n)||n.appleOs===`watchos`?Z:X,u=mn(n);return Object.freeze({device:r.device,operations:{...r.operations,...i,appState:Jt,networkDump:X,screenRecordingStart:s,screenRecordingReattach:s,screenRecordingCleanup:s,..._n(n),ensureReady:c,bootTarget:l,bootTargetHeadless:Yt,listApps:u,...ln(n),shutdownTarget:cn(n)}})};return Object.freeze({owner:Y,ownsDevice:e=>e.platform===`apple`,inspectFacts:n,bind:async r=>{let i=await t.bind(r),a=await n(r.device),o=a.operations.screenRecordingStart;return Object.freeze({device:i.device,owner:Y,facts:a,operations:Object.freeze({...i.operations,...Lt({host:e,device:r.device,signal:r.scope.signal}),networkDump:async t=>await Ve(e,r.device,t,r.scope.signal),...o.available?ot({host:e,device:r.device,owner:Y,signal:r.scope.signal}):{},...a.operations.captureSnapshot.available?qt(e,{device:r.device,signal:r.scope.signal}):{},...a.operations.ensureReady.available?{ensureReady:async()=>await V(e,r.device,r.scope.signal)}:{},...a.operations.bootTarget.available?{bootTarget:async()=>await V(e,r.device,r.scope.signal)}:{},...a.operations.listApps.available?{listApps:async t=>await e.appInventory.apple.listApps(t.device,t.filter,r.scope.signal)}:{},...c(gt({host:e,device:r.device,signal:r.scope.signal}),a.operations),...a.operations.shutdownTarget.available?{shutdownTarget:async()=>await e.deviceShutdown.apple.shutdownTarget(r.device,r.scope.signal)}:{}}),[Symbol.asyncDispose]:async()=>await i[Symbol.asyncDispose]()})},shutdown:async()=>await t.shutdown()})}function gn(e){return g(e)===`watchos`?Q:e.kind===`simulator`||e.kind===`device`?X:Q}function _n(e){let t=gn(e);return d({capture:t,customActions:t.available&&m(e)&&e.kind===`simulator`?X:on,withoutActiveApp:m(e)?sn:t})}export{hn as createApplePlatformRuntime};
@@ -1 +1 @@
1
- import{C as e}from"./sdk-contracts.js";import{c as t}from"./sdk-device.js";import{n,t as r}from"./simulator-state.js";const i=15e3;function a(e){return Object.freeze({canShutdownTarget:o,shutdownTarget:async(t,n)=>await s(e.appleTools,t,n)})}function o(e){return t(e)&&e.appleOs!==`watchos`&&e.kind===`simulator`}async function s(t,r,a){if(r.booted===!1)return u();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}}function u(){return{success:!0,exitCode:0,stdout:``,stderr:``}}export{a as createAppleShutdownRuntime};
1
+ import{E as e}from"./sdk-contracts.js";import{c as t}from"./sdk-device.js";import{n,t as r}from"./simulator-state.js";const i=15e3;function a(e){return Object.freeze({canShutdownTarget:o,shutdownTarget:async(t,n)=>await s(e.appleTools,t,n)})}function o(e){return t(e)&&e.appleOs!==`watchos`&&e.kind===`simulator`}async function s(t,r,a){if(r.booted===!1)return u();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}}function u(){return{success:!0,exitCode:0,stdout:``,stderr:``}}export{a as createAppleShutdownRuntime};
@@ -1 +1 @@
1
- import{_ as e}from"./sdk-contracts.js";import{R as t,at as n,bt as r,dt as i,et as a,ot as o,tt as s,z as c}from"./sdk-batch-runner.js";import{C as l}from"./sdk-device.js";import{a as u,d,f,o as p,p as m,v as h,x as g}from"./src3.js";import{randomUUID as _}from"node:crypto";import{setTimeout as ee}from"node:timers/promises";const v=Object.freeze({resourceKind:s,version:1,encode:e=>({...e}),decode:e=>e.transport!==`harmony-hilog`||!y(e.outputPath)||!y(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 te(e){return h({resourceKind:s,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:g(v,e.descriptor)})}function y(e){return typeof e==`string`&&e.trim().length>0}function b(e){return u(e,{family:`harmonyos`,backend:`harmonyos`,label:`HarmonyOS`,codec:v,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 x(e,r);return{resolvePid:async r=>await p(e,{executable:i,args:[`-t`,t.id,`shell`,`pidof`,n.appBundleId],allowFailure:!0,timeoutMs:5e3},r),command:e=>({kind:`host`,request:{executable:i,args:[`-t`,t.id,`shell`,`hilog`,`-P`,e],allowFailure:!0}})}},descriptor:({artifacts:e})=>({transport:`harmony-hilog`,...e}),envelope:({input:e,device:t,owner:n,descriptor:r})=>te({sessionId:e.sessionId,device:t,owner:n,fence:e.fence,descriptor:r})})}async function x(t,n){n.throwIfAborted(),await S(async()=>await t.toolchains.prepare(`harmonyos`),n),n.throwIfAborted();let r=await S(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 S(e,t){try{return await e()}catch(e){throw t.throwIfAborted(),e}}const C=Object.freeze({resourceKind:a,version:1,encode:e=>({...e}),decode:e=>e.backend===`harmony-screen-recorder`&&typeof e.fileName==`string`&&ne(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 w(e){let{device:t,owner:n,input:r,descriptor:i}=e;return h({resourceKind:a,sessionId:r.sessionId,device:l(t),owner:n,fence:r.fence,lifecycle:`open`,descriptor:g(C,i)})}function T(e){return C.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 ne(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 E(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 re(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await ie({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=>T(e.envelope.descriptor.body)})}async function ie(t){let{host:n,device:r,owner:a,input:o,signal:s}=t;if(o.scope===`app`)throw new e(`INVALID_ARGS`,`HarmonyOS recording captures the whole physical-device screen; use --scope device or --scope system`);d(o,{scopes:[`device`,`system`],fps:!1,exportQuality:!1,hideTouches:!1},e=>`HarmonyOS recordings do not support ${e.join(`, `)}`),s.throwIfAborted(),await n.screenRecording.outputs.prepare(o.outputPath);let c=`agent-device-recording-${_()}.mp4`,l={backend:`harmony-screen-recorder`,fileName:c,remotePath:`/data/local/tmp/${c}`},u;try{u=await n.screenRecording.harmony.start(r,c,s),s.throwIfAborted()}catch(e){throw s.aborted?(await N(n,r,l).catch(()=>{}),s.reason):e}I(u,`start`);try{s.throwIfAborted()}catch(e){throw await N(n,r,l).catch(()=>{}),e}let f=D(o),p=!1,h=async()=>{p||=(I(await n.screenRecording.harmony.stop(r),`stop`),!0)},g=m(f,{finish:async e=>await O(n,r,e,l,h),forceCleanup:async()=>await N(n,r,l,h)});return Object.freeze({pendingHandle:new i(g),envelope:w({device:r,owner:a,input:o,descriptor:l})})}function D(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 O(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 M(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 k(e,t,r,a);return f(n,{...i,...j(i.warning,o)},!1)}catch(n){throw await e.screenRecording.harmony.remove(t,r.remotePath).catch(()=>{}),n}}async function k(e,t,n,r){let i=[];return await A(()=>e.screenRecording.harmony.remove(t,n.remotePath))||i.push(`staging artifact`),await A(()=>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 A(e){try{return await e()}catch{return!1}}function j(e,t){let n=[e,t].filter(e=>e!==void 0).join(` `);return n.length===0?{}:{warning:n}}async function M(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 N(e,t,n,r=async()=>{I(await e.screenRecording.harmony.stop(t),`stop`)}){let i=[await F(r),await F(async()=>{if(!await e.screenRecording.harmony.remove(t,n.remotePath))throw Error(`HarmonyOS recording staging artifact removal was not confirmed`)}),await F(async()=>await P(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 P(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 F(e){try{await e();return}catch(e){return e}}function I(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 L(t,n,r){r.throwIfAborted();let i=await t.run(n,{args:[`shell`,`aa`,`dump`,`-l`],timeoutMs:15e3},r);r.throwIfAborted();let a=R(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 R(e){let t=e.split(/(?=^\s*Mission ID #)/m);for(let e of t){if(!/\bstate #FOREGROUND\b/.test(e))continue;let t=e.match(/mission name #\[#([^:]+):[^:]*:([^\]]+)]/);if(!t)continue;let[,n,r]=t;if(!(!n||!r))return{package:n,activity:r}}}function z(e){return t({owner:`HarmonyOS`,openTargetIdentity:`bundle-id`,binding:c({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const B=Object.freeze({available:!0}),V=Object.freeze({available:!1,reason:`unsupported-device-kind`}),H=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function U(e){let t=e.kind===`emulator`||e.kind===`device`?B:V;return Object.freeze({deployApp:t,materializeAppSource:H,deployMaterializedApp:H,sendPushNotification:H})}function W(e){return U(e.device).deployApp.available?Object.freeze({deployApp:async t=>await G(e.commands,e.device,t,e.signal)}):Object.freeze({})}async function G(t,n,r,i){let a=await K(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 Y(t,n,[`install`,`-r`,r.appPath],i,18e4),r.replaceExisting&&(await ee(1e3,void 0,{signal:i}),await q(t,n,a,i)),{packageName:a,launchTarget:a}}async function K(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 q(t,n,r,i){let a=J((await Y(t,n,[`shell`,`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 Y(t,n,[`shell`,`aa`,`start`,`-b`,r,...a.module?[`-m`,a.module]:[],`-a`,a.ability],i)}function J(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 Y(e,t,n,r,i=15e3){return await e.run({executable:`hdc`,args:[`-t`,t.id,...n],timeoutMs:i},r)}const X=r(`harmonyos`),Z=Object.freeze({available:!0}),Q=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),ae=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`HarmonyOS appstate is supported only for HarmonyOS emulators and devices.`}),oe=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple runner preparation is supported only for Apple targets.`}),$=Object.freeze({available:!0}),se=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`open is supported only for HarmonyOS emulators and devices.`}),ce=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`close is supported only for HarmonyOS emulators and devices.`}),le=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`});function ue(e){let t=de(e),r=fe(e);return n({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:Q,clearRuntimeHints:Q,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:oe,configureProviderPortReverse:le})}function de(e){return e.kind===`emulator`||e.kind===`device`?$:se}function fe(e){return e.kind===`emulator`||e.kind===`device`?$:ce}function pe(e){let t=b(e),n=async e=>{let n=await t.inspectFacts(e),r=U(e),i=E(e);return Object.freeze({device:n.device,operations:{...n.operations,...r,appState:e.kind===`simulator`?ae:Z,networkDump:Q,screenRecordingStart:i,screenRecordingReattach:i,screenRecordingCleanup:i,ensureReady:Z,bootTarget:Q,bootTargetHeadless:Q,listApps:Z,...ue(e),shutdownTarget:Q}})};return Object.freeze({owner:X,ownsDevice:e=>e.platform===`harmonyos`,inspectFacts:n,bind:async r=>{let i=await t.bind(r),a=await n(r.device),s=a.operations.screenRecordingStart;return Object.freeze({device:i.device,owner:X,facts:a,operations:Object.freeze({...i.operations,...W({commands:e.commands,device:r.device,signal:r.scope.signal}),...a.operations.appState.available?{appState:async()=>await L(e.appState.harmonyos,r.device,r.scope.signal)}:{},ensureReady:async()=>({...r.device,booted:!0}),...s.available?re({host:e,device:r.device,owner:X,signal:r.scope.signal}):{},listApps:async t=>await e.appInventory.harmonyos.listApps(t.device,t.filter,r.scope.signal),...o(z({host:e.localInteractors,device:r.device,signal:r.scope.signal}),a.operations)}),[Symbol.asyncDispose]:async()=>await i[Symbol.asyncDispose]()})},shutdown:async()=>await t.shutdown()})}export{pe as createHarmonyPlatformRuntime};
1
+ import{_ as e}from"./sdk-contracts.js";import{B as t,Et as n,V as r,dt as i,gt as a,lt as o,nt as s,rt as c,st as l,ut as u}from"./sdk-batch-runner.js";import{C as d}from"./sdk-device.js";import{a as f,d as p,f as m,o as h,p as ee,v as g,x as _}from"./src3.js";import{randomUUID as v}from"node:crypto";import{setTimeout as y}from"node:timers/promises";const b=Object.freeze({resourceKind:c,version:1,encode:e=>({...e}),decode:e=>e.transport!==`harmony-hilog`||!S(e.outputPath)||!S(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 x(e){return g({resourceKind:c,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:_(b,e.descriptor)})}function S(e){return typeof e==`string`&&e.trim().length>0}function C(e){return f(e,{family:`harmonyos`,backend:`harmonyos`,label:`HarmonyOS`,codec:b,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 w(e,r);return{resolvePid:async r=>await h(e,{executable:i,args:[`-t`,t.id,`shell`,`pidof`,n.appBundleId],allowFailure:!0,timeoutMs:5e3},r),command:e=>({kind:`host`,request:{executable:i,args:[`-t`,t.id,`shell`,`hilog`,`-P`,e],allowFailure:!0}})}},descriptor:({artifacts:e})=>({transport:`harmony-hilog`,...e}),envelope:({input:e,device:t,owner:n,descriptor:r})=>x({sessionId:e.sessionId,device:t,owner:n,fence:e.fence,descriptor:r})})}async function w(t,n){n.throwIfAborted(),await T(async()=>await t.toolchains.prepare(`harmonyos`),n),n.throwIfAborted();let r=await T(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 T(e,t){try{return await e()}catch(e){throw t.throwIfAborted(),e}}const E=Object.freeze({resourceKind:s,version:1,encode:e=>({...e}),decode:e=>e.backend===`harmony-screen-recorder`&&typeof e.fileName==`string`&&re(e.fileName)&&e.remotePath===`/data/local/tmp/${e.fileName}`?{status:`decoded`,descriptor:Object.freeze({backend:`harmony-screen-recorder`,fileName:e.fileName,remotePath:e.remotePath})}:{status:`invalid`,message:`Invalid HarmonyOS screen-recording descriptor`}});function te(e){let{device:t,owner:n,input:r,descriptor:i}=e;return g({resourceKind:s,sessionId:r.sessionId,device:d(t),owner:n,fence:r.fence,lifecycle:`open`,descriptor:_(E,i)})}function ne(e){return E.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 re(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 ie(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 ae(e){let{host:t,device:n,owner:r,signal:i}=e;return Object.freeze({screenRecordingStart:async e=>await oe({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=>ne(e.envelope.descriptor.body)})}async function oe(t){let{host:n,device:r,owner:i,input:o,signal:s}=t;if(o.scope===`app`)throw new e(`INVALID_ARGS`,`HarmonyOS recording captures the whole physical-device screen; use --scope device or --scope system`);p(o,{scopes:[`device`,`system`],fps:!1,exportQuality:!1,hideTouches:!1},e=>`HarmonyOS recordings do not support ${e.join(`, `)}`),s.throwIfAborted(),await n.screenRecording.outputs.prepare(o.outputPath);let c=`agent-device-recording-${v()}.mp4`,l={backend:`harmony-screen-recorder`,fileName:c,remotePath:`/data/local/tmp/${c}`},u;try{u=await n.screenRecording.harmony.start(r,c,s),s.throwIfAborted()}catch(e){throw s.aborted?(await N(n,r,l).catch(()=>{}),s.reason):e}I(u,`start`);try{s.throwIfAborted()}catch(e){throw await N(n,r,l).catch(()=>{}),e}let d=D(o),f=!1,m=async()=>{f||=(I(await n.screenRecording.harmony.stop(r),`stop`),!0)},h=ee(d,{finish:async e=>await O(n,r,e,l,m),forceCleanup:async()=>await N(n,r,l,m)});return Object.freeze({pendingHandle:new a(h),envelope:te({device:r,owner:i,input:o,descriptor:l})})}function D(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 O(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 M(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 k(e,t,r,a);return m(n,{...i,...j(i.warning,o)},!1)}catch(n){throw await e.screenRecording.harmony.remove(t,r.remotePath).catch(()=>{}),n}}async function k(e,t,n,r){let i=[];return await A(()=>e.screenRecording.harmony.remove(t,n.remotePath))||i.push(`staging artifact`),await A(()=>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 A(e){try{return await e()}catch{return!1}}function j(e,t){let n=[e,t].filter(e=>e!==void 0).join(` `);return n.length===0?{}:{warning:n}}async function M(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 N(e,t,n,r=async()=>{I(await e.screenRecording.harmony.stop(t),`stop`)}){let i=[await F(r),await F(async()=>{if(!await e.screenRecording.harmony.remove(t,n.remotePath))throw Error(`HarmonyOS recording staging artifact removal was not confirmed`)}),await F(async()=>await P(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 P(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 F(e){try{await e();return}catch(e){return e}}function I(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 L(t,n,r){r.throwIfAborted();let i=await t.run(n,{args:[`shell`,`aa`,`dump`,`-l`],timeoutMs:15e3},r);r.throwIfAborted();let a=R(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 R(e){let t=e.split(/(?=^\s*Mission ID #)/m);for(let e of t){if(!/\bstate #FOREGROUND\b/.test(e))continue;let t=e.match(/mission name #\[#([^:]+):[^:]*:([^\]]+)]/);if(!t)continue;let[,n,r]=t;if(!(!n||!r))return{package:n,activity:r}}}function z(e){return t({owner:`HarmonyOS`,openTargetIdentity:`bundle-id`,binding:r({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const B=Object.freeze({available:!0}),V=Object.freeze({available:!1,reason:`unsupported-device-kind`}),H=Object.freeze({available:!1,reason:`unsupported-platform-leaf`});function U(e){let t=e.kind===`emulator`||e.kind===`device`?B:V;return Object.freeze({deployApp:t,materializeAppSource:H,deployMaterializedApp:H,sendPushNotification:H})}function W(e){return U(e.device).deployApp.available?Object.freeze({deployApp:async t=>await G(e.commands,e.device,t,e.signal)}):Object.freeze({})}async function G(t,n,r,i){let a=await K(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 J(t,n,[`install`,`-r`,r.appPath],i,18e4),r.replaceExisting&&(await y(1e3,void 0,{signal:i}),await q(t,n,a,i)),{packageName:a,launchTarget:a}}async function K(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 q(t,n,r,i){let a=se((await J(t,n,[`shell`,`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 J(t,n,[`shell`,`aa`,`start`,`-b`,r,...a.module?[`-m`,a.module]:[],`-a`,a.ability],i)}function se(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 J(e,t,n,r,i=15e3){return await e.run({executable:`hdc`,args:[`-t`,t.id,...n],timeoutMs:i},r)}const Y=n(`harmonyos`),X=Object.freeze({available:!0}),Z=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),ce=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`HarmonyOS appstate is supported only for HarmonyOS emulators and devices.`}),le=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple runner preparation is supported only for Apple targets.`}),Q=Object.freeze({available:!0}),ue=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`open is supported only for HarmonyOS emulators and devices.`}),de=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`close is supported only for HarmonyOS emulators and devices.`}),fe=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`}),$=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`snapshot is supported only for HarmonyOS emulators and devices.`}),pe=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Re-run without --actions, or target an iOS simulator.`});function me(e){let t=he(e),n=ge(e);return u({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:Z,clearRuntimeHints:Z,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:le,configureProviderPortReverse:fe})}function he(e){return e.kind===`emulator`||e.kind===`device`?Q:ue}function ge(e){return e.kind===`emulator`||e.kind===`device`?Q:de}function _e(e){let t=C(e),n=async e=>{let n=await t.inspectFacts(e),r=U(e),i=ie(e);return Object.freeze({device:n.device,operations:{...n.operations,...r,appState:e.kind===`simulator`?ce:X,networkDump:Z,screenRecordingStart:i,screenRecordingReattach:i,screenRecordingCleanup:i,...o({capture:e.kind===`emulator`||e.kind===`device`?X:$,customActions:pe,withoutActiveApp:e.kind===`emulator`||e.kind===`device`?X:$}),ensureReady:X,bootTarget:Z,bootTargetHeadless:Z,listApps:X,...me(e),shutdownTarget:Z}})};return Object.freeze({owner:Y,ownsDevice:e=>e.platform===`harmonyos`,inspectFacts:n,bind:async r=>{let a=await t.bind(r),o=await n(r.device),s=o.operations.screenRecordingStart;return Object.freeze({device:a.device,owner:Y,facts:o,operations:Object.freeze({...a.operations,...W({commands:e.commands,device:r.device,signal:r.scope.signal}),...o.operations.appState.available?{appState:async()=>await L(e.appState.harmonyos,r.device,r.scope.signal)}:{},ensureReady:async()=>({...r.device,booted:!0}),...s.available?ae({host:e,device:r.device,owner:Y,signal:r.scope.signal}):{},...o.operations.captureSnapshot.available?l({device:r.device,signal:r.scope.signal,resolveInteractor:e.localInteractors.resolve}):{},listApps:async t=>await e.appInventory.harmonyos.listApps(t.device,t.filter,r.scope.signal),...i(z({host:e.localInteractors,device:r.device,signal:r.scope.signal}),o.operations)}),[Symbol.asyncDispose]:async()=>await a[Symbol.asyncDispose]()})},shutdown:async()=>await t.shutdown()})}export{_e as createHarmonyPlatformRuntime};
@@ -1 +1 @@
1
- import{_ as e}from"./sdk-contracts.js";import{R as t,at as n,bt as r,it as i,ot as a,wt as o,z as s}from"./sdk-batch-runner.js";function c(e){return t({owner:`Linux`,openTargetIdentity:`app-name`,binding:s({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const l=Object.freeze({available:!0}),u=r(`linux`),d=y(`unsupported-platform-leaf`),f=y(`unsupported-platform-leaf`,`Runtime hints are supported only for local iOS-family simulators and Android devices.`),p=y(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),m=y(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),h=y(`unsupported-device-kind`,`open is supported only for the Linux desktop device.`),g=y(`unsupported-device-kind`,`close is supported only for the Linux desktop device.`);function _(t){return Object.freeze({owner:u,ownsDevice:e=>e.platform===`linux`,inspectFacts:async e=>v(e),bind:async n=>{if(n.intent.kind===`exact-owner`&&!o(n.intent.owner,u))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 r=v(n.device),i=c({host:t.localInteractors,device:n.device,signal:n.scope.signal});return Object.freeze({device:n.device,owner:u,facts:r,operations:Object.freeze(a(i,r.operations)),[Symbol.asyncDispose]:async()=>void 0})},shutdown:async()=>void 0})}function v(e){let t=e.kind===`device`?l:h,r=e.kind===`device`?l:g;return i(e,u,{appLog:d,network:d,readiness:d,lifecycle:n({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:f,clearRuntimeHints:f,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:p,configureProviderPortReverse:m})})}function y(e,t){return Object.freeze(t===void 0?{available:!1,reason:e}:{available:!1,reason:e,hint:t})}export{_ as createLinuxPlatformRuntime};
1
+ import{_ as e}from"./sdk-contracts.js";import{At as t,B as n,Et as r,V as i,dt as a,lt as o,ot as s,ut as c}from"./sdk-batch-runner.js";function l(e){return n({owner:`Linux`,openTargetIdentity:`app-name`,binding:i({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const u=Object.freeze({available:!0}),d=r(`linux`),f=C(`unsupported-platform-leaf`),p=C(`unsupported-platform-leaf`,`Runtime hints are supported only for local iOS-family simulators and Android devices.`),m=C(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),h=C(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),g=C(`unsupported-device-kind`,`open is supported only for the Linux desktop device.`),_=C(`unsupported-device-kind`,`close is supported only for the Linux desktop device.`),v=C(`unsupported-device-kind`,`snapshot is supported only for the Linux desktop device.`),y=C(`unsupported-platform-leaf`,`Re-run without --actions, or target an iOS simulator.`);function b(n){return Object.freeze({owner:d,ownsDevice:e=>e.platform===`linux`,inspectFacts:async e=>x(e),bind:async r=>{if(r.intent.kind===`exact-owner`&&!t(r.intent.owner,d))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 i=x(r.device),o=l({host:n.localInteractors,device:r.device,signal:r.scope.signal});return Object.freeze({device:r.device,owner:d,facts:i,operations:Object.freeze({...a(o,i.operations),...i.operations.captureSnapshot.available?S(n,r):{}}),[Symbol.asyncDispose]:async()=>void 0})},shutdown:async()=>void 0})}function x(e){let t=e.kind===`device`?u:g,n=e.kind===`device`?u:_,r=s(e,d,{appLog:f,network:f,snapshot:v,readiness:f,lifecycle:c({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:p,clearRuntimeHints:p,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:m,configureProviderPortReverse:h})});return Object.freeze({device:r.device,operations:{...r.operations,...o({capture:e.kind===`device`?u:v,customActions:y,withoutActiveApp:e.kind===`device`?u:v})}})}function S(e,t){let n=async n=>await e.snapshot.captureSurface(t.device,n.options,t.scope.signal);return Object.freeze({captureSnapshot:n,captureSnapshotWithCustomActions:n,captureSnapshotWithoutActiveApp:n})}function C(e,t){return Object.freeze(t===void 0?{available:!1,reason:e}:{available:!1,reason:e,hint:t})}export{b as createLinuxPlatformRuntime};
@@ -1 +1 @@
1
- import{_ as e}from"./sdk-contracts.js";import{R as t,at as n,bt as r,it as i,ot as a,wt as o,z as s}from"./sdk-batch-runner.js";function c(e){return t({owner:`Vega`,openTargetIdentity:`app-name`,binding:s({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const l=r(`vega`),u=Object.freeze({available:!0}),d=y(`unsupported-platform-leaf`),f=y(`unsupported-platform-leaf`,`Runtime hints are supported only for local iOS-family simulators and Android devices.`),p=y(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),m=y(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),h=y(`unsupported-device-kind`,`open currently supports only Vega Virtual Devices.`),g=y(`unsupported-device-kind`,`close currently supports only Vega Virtual Devices.`);function _(t){return Object.freeze({owner:l,ownsDevice:e=>e.platform===`vega`,inspectFacts:async e=>v(e),bind:async n=>{if(n.intent.kind===`exact-owner`&&!o(n.intent.owner,l))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=v(n.device),i=c({host:t.localInteractors,device:n.device,signal:n.scope.signal});return Object.freeze({device:n.device,owner:l,facts:r,operations:Object.freeze(a(i,r.operations)),[Symbol.asyncDispose]:async()=>void 0})},shutdown:async()=>void 0})}function v(e){let t=e.kind===`emulator`&&e.target===`tv`,r=t?u:h,a=t?u:g;return i(e,l,{appLog:d,network:d,readiness:d,lifecycle:n({resolveOpenTarget:r,prepareApplicationOpen:r,openApplication:r,applyRuntimeHints:f,clearRuntimeHints:f,closeApplication:a,finalizeApplicationClose:a,prepareAppleRunner:p,configureProviderPortReverse:m})})}function y(e,t){let n={available:!1,reason:e,...t===void 0?{}:{hint:t}};return Object.freeze(n)}export{_ as createVegaPlatformRuntime};
1
+ import{_ as e}from"./sdk-contracts.js";import{At as t,B as n,Et as r,V as i,dt as a,ot as o,ut as s}from"./sdk-batch-runner.js";function c(e){return n({owner:`Vega`,openTargetIdentity:`app-name`,binding:i({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const l=r(`vega`),u=Object.freeze({available:!0}),d=y(`unsupported-platform-leaf`),f=y(`unsupported-platform-leaf`,`Runtime hints are supported only for local iOS-family simulators and Android devices.`),p=y(`unsupported-platform-leaf`,`Apple runner preparation is supported only for Apple targets.`),m=y(`unsupported-provider-mode`,`Port reverse is supported only by an owning provider runtime.`),h=y(`unsupported-device-kind`,`open currently supports only Vega Virtual Devices.`),g=y(`unsupported-device-kind`,`close currently supports only Vega Virtual Devices.`);function _(n){return Object.freeze({owner:l,ownsDevice:e=>e.platform===`vega`,inspectFacts:async e=>v(e),bind:async r=>{if(r.intent.kind===`exact-owner`&&!t(r.intent.owner,l))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=v(r.device),o=c({host:n.localInteractors,device:r.device,signal:r.scope.signal});return Object.freeze({device:r.device,owner:l,facts:i,operations:Object.freeze(a(o,i.operations)),[Symbol.asyncDispose]:async()=>void 0})},shutdown:async()=>void 0})}function v(e){let t=e.kind===`emulator`&&e.target===`tv`,n=t?u:h,r=t?u:g;return o(e,l,{appLog:d,network:d,snapshot:d,readiness:d,lifecycle:s({resolveOpenTarget:n,prepareApplicationOpen:n,openApplication:n,applyRuntimeHints:f,clearRuntimeHints:f,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:p,configureProviderPortReverse:m})})}function y(e,t){let n={available:!1,reason:e,...t===void 0?{}:{hint:t}};return Object.freeze(n)}export{_ as createVegaPlatformRuntime};
@@ -1 +1 @@
1
- import{_ as e}from"./sdk-contracts.js";import{R as t,at as n,bt as r,dt as i,et as a,ot as o,wt as s,z as c}from"./sdk-batch-runner.js";import{C as l}from"./sdk-device.js";import{d as u,f as d,p as f,v as p,x as m}from"./src3.js";const h=Object.freeze({resourceKind:a,version:1,encode:e=>({...e}),decode:e=>e.backend===`agent-browser`&&typeof e.outputPath==`string`?{status:`decoded`,descriptor:Object.freeze({backend:`agent-browser`,outputPath:e.outputPath})}:{status:`invalid`,message:`Invalid web screen-recording descriptor`}});async function g(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=>await _({host:t,transport:a,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async()=>({status:`unreattachable`,reason:`transport-not-reattachable`,message:`Web recordings cannot be reattached after daemon restart.`}),screenRecordingCleanup:async()=>v()}}:{available:!1,operations:{}}}async function _(t){let{host:n,transport:r,device:o,owner:s,input:c,signal:g}=t;if(c.recordOnlySession)throw new e(`INVALID_ARGS`,`record on web requires an active browser session; run open <url> --platform web first`);if(!c.outputPath.toLowerCase().endsWith(`.webm`))throw new e(`INVALID_ARGS`,`web recordings require a .webm output path; agent-browser records WebM directly`);u(c,{scopes:[`app`],fps:!1,exportQuality:!1,hideTouches:!1},e=>`web recordings do not support ${e.join(`, `)}; agent-browser records WebM directly`),g.throwIfAborted(),await n.screenRecording.outputs.prepare(c.outputPath);let _=!1;try{await r.start(c.outputPath,g),_=!0,g.throwIfAborted()}catch(e){throw _&&await r.stop().catch(()=>{}),g.throwIfAborted(),e}let v=!1,y=async()=>{v||=(await r.stop(),!0)},b=f({backend:`agent-browser`,outPath:c.outputPath,...c.clientOutputPath===void 0?{}:{clientOutPath:c.clientOutputPath},startedAt:Date.now(),scope:c.scope,showTouches:!1,recordOnlySession:c.recordOnlySession,...c.activeSessionApp===void 0?{}:{activeSessionApp:c.activeSessionApp},gestureEvents:[]},{finish:async e=>(await y(),d(e,await n.screenRecording.finalize.complete({outputPath:e.outPath,showTouches:!1,gestureEvents:e.gestureEvents,targetLabel:`web recording`}),!1)),forceCleanup:async()=>{try{return await y(),{status:`cleaned`}}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`Web recording cleanup failed`}}}});return Object.freeze({pendingHandle:new i(b),envelope:p({resourceKind:a,sessionId:c.sessionId,device:l(o),owner:s,fence:c.fence,lifecycle:`open`,descriptor:m(h,{backend:`agent-browser`,outputPath:c.outputPath})})})}function v(){return{status:`cleanup-pending`,reason:`manual-recovery-required`,message:`Web recordings cannot be cleaned after daemon restart.`}}function y(e){return t({owner:`web`,openTargetIdentity:`app-name`,binding:c({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const b=r(`web`),x=Object.freeze({available:!0}),S=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),C=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`record is not supported by this web provider`}),w=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),T=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`apps is not supported on web targets.`}),E=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),D=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple runner preparation is supported only for Apple targets.`}),O=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`open is supported only for web browser devices.`}),k=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`close is supported only for web browser devices.`}),A=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`});function j(e){let t=M(e),r=N(e);return n({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:w,clearRuntimeHints:w,closeApplication:r,finalizeApplicationClose:r,prepareAppleRunner:D,configureProviderPortReverse:A})}function M(e){return e.kind===`device`?x:O}function N(e){return e.kind===`device`?x:k}function P(t){return Object.freeze({owner:b,ownsDevice:e=>e.platform===`web`,inspectFacts:async e=>I(e,await t.networkTransports.resolve(e),(await g({host:t,device:e,owner:b,signal:new AbortController().signal})).available),bind:async n=>{if(n.intent.kind===`exact-owner`&&!s(n.intent.owner,b))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),i=await g({host:t,device:n.device,owner:b,signal:n.scope.signal});return F(t,n.device,n.scope.signal,r,i,I(n.device,r,i.available))},shutdown:async()=>void 0})}function F(e,t,n,r,i,a){let s=r.dump,c={...s?{networkDump:async e=>{let t=await s({maxEntries:e.maxEntries,include:e.include},n);return Object.freeze({source:`provider`,...t})}}:{},...i.operations,...o(y({host:e.localInteractors,device:t,signal:n}),a.operations)};return Object.freeze({device:t,owner:b,facts:a,operations:Object.freeze(c),[Symbol.asyncDispose]:async()=>void 0})}function I(e,t,n){let r=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`network is not supported by this web provider`});return Object.freeze({device:{family:`web`,kind:e.kind,...e.target===void 0?{}:{target:e.target},providerMode:t.mode},operations:{appLogInspect:S,appLogDoctor:S,appLogStart:S,appLogReattach:S,appLogCleanup:S,appState:E,networkDump:t.dump?x:r,screenRecordingStart:n?x:C,screenRecordingReattach:n?x:C,screenRecordingCleanup:n?x:C,ensureReady:w,bootTarget:w,bootTargetHeadless:w,listApps:T,deployApp:w,materializeAppSource:w,deployMaterializedApp:w,sendPushNotification:w,shutdownTarget:w,...j(e)}})}export{P as createWebPlatformRuntime};
1
+ import{_ as e}from"./sdk-contracts.js";import{At as t,B as n,Et as r,V as i,dt as a,gt as o,lt as s,nt as c,st as l,ut as u}from"./sdk-batch-runner.js";import{C as d}from"./sdk-device.js";import{d as f,f as p,p as m,v as h,x as g}from"./src3.js";const _=Object.freeze({resourceKind:c,version:1,encode:e=>({...e}),decode:e=>e.backend===`agent-browser`&&typeof e.outputPath==`string`?{status:`decoded`,descriptor:Object.freeze({backend:`agent-browser`,outputPath:e.outputPath})}:{status:`invalid`,message:`Invalid web screen-recording descriptor`}});async function v(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=>await y({host:t,transport:a,device:n,owner:r,input:e,signal:i}),screenRecordingReattach:async()=>({status:`unreattachable`,reason:`transport-not-reattachable`,message:`Web recordings cannot be reattached after daemon restart.`}),screenRecordingCleanup:async()=>b()}}:{available:!1,operations:{}}}async function y(t){let{host:n,transport:r,device:i,owner:a,input:s,signal:l}=t;if(s.recordOnlySession)throw new e(`INVALID_ARGS`,`record on web requires an active browser session; run open <url> --platform web first`);if(!s.outputPath.toLowerCase().endsWith(`.webm`))throw new e(`INVALID_ARGS`,`web recordings require a .webm output path; agent-browser records WebM directly`);f(s,{scopes:[`app`],fps:!1,exportQuality:!1,hideTouches:!1},e=>`web recordings do not support ${e.join(`, `)}; agent-browser records WebM directly`),l.throwIfAborted(),await n.screenRecording.outputs.prepare(s.outputPath);let u=!1;try{await r.start(s.outputPath,l),u=!0,l.throwIfAborted()}catch(e){throw u&&await r.stop().catch(()=>{}),l.throwIfAborted(),e}let v=!1,y=async()=>{v||=(await r.stop(),!0)},b=m({backend:`agent-browser`,outPath:s.outputPath,...s.clientOutputPath===void 0?{}:{clientOutPath:s.clientOutputPath},startedAt:Date.now(),scope:s.scope,showTouches:!1,recordOnlySession:s.recordOnlySession,...s.activeSessionApp===void 0?{}:{activeSessionApp:s.activeSessionApp},gestureEvents:[]},{finish:async e=>(await y(),p(e,await n.screenRecording.finalize.complete({outputPath:e.outPath,showTouches:!1,gestureEvents:e.gestureEvents,targetLabel:`web recording`}),!1)),forceCleanup:async()=>{try{return await y(),{status:`cleaned`}}catch(e){return{status:`cleanup-pending`,reason:`transport-failed`,message:e instanceof Error?e.message:`Web recording cleanup failed`}}}});return Object.freeze({pendingHandle:new o(b),envelope:h({resourceKind:c,sessionId:s.sessionId,device:d(i),owner:a,fence:s.fence,lifecycle:`open`,descriptor:g(_,{backend:`agent-browser`,outputPath:s.outputPath})})})}function b(){return{status:`cleanup-pending`,reason:`manual-recovery-required`,message:`Web recordings cannot be cleaned after daemon restart.`}}function x(e){return n({owner:`web`,openTargetIdentity:`app-name`,binding:i({device:e.device,signal:e.signal,resolveInteractor:e.host.resolve})})}const S=r(`web`),C=Object.freeze({available:!0}),w=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),T=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`record is not supported by this web provider`}),E=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Re-run without --actions, or target an iOS simulator.`}),D=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),O=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`apps is not supported on web targets.`}),k=Object.freeze({available:!1,reason:`unsupported-platform-leaf`}),A=Object.freeze({available:!1,reason:`unsupported-platform-leaf`,hint:`Apple runner preparation is supported only for Apple targets.`}),j=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`open is supported only for web browser devices.`}),M=Object.freeze({available:!1,reason:`unsupported-device-kind`,hint:`close is supported only for web browser devices.`}),N=Object.freeze({available:!1,reason:`unsupported-provider-mode`,hint:`Port reverse is supported only by an owning provider runtime.`});function P(e){let t=F(e),n=I(e);return u({resolveOpenTarget:t,prepareApplicationOpen:t,openApplication:t,applyRuntimeHints:D,clearRuntimeHints:D,closeApplication:n,finalizeApplicationClose:n,prepareAppleRunner:A,configureProviderPortReverse:N})}function F(e){return e.kind===`device`?C:j}function I(e){return e.kind===`device`?C:M}function L(n){return Object.freeze({owner:S,ownsDevice:e=>e.platform===`web`,inspectFacts:async e=>z(e,await n.networkTransports.resolve(e),(await v({host:n,device:e,owner:S,signal:new AbortController().signal})).available),bind:async r=>{if(r.intent.kind===`exact-owner`&&!t(r.intent.owner,S))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 v({host:n,device:r.device,owner:S,signal:r.scope.signal});return R(n,r.device,r.scope.signal,i,a,z(r.device,i,a.available))},shutdown:async()=>void 0})}function R(e,t,n,r,i,o){let s=r.dump,c={...s?{networkDump:async e=>{let t=await s({maxEntries:e.maxEntries,include:e.include},n);return Object.freeze({source:`provider`,...t})}}:{},...i.operations,...o.operations.captureSnapshot.available?l({device:t,signal:n,resolveInteractor:e.localInteractors.resolve}):{},...a(x({host:e.localInteractors,device:t,signal:n}),o.operations)};return Object.freeze({device:t,owner:S,facts:o,operations:Object.freeze(c),[Symbol.asyncDispose]:async()=>void 0})}function z(e,t,n){let r=Object.freeze({available:!1,reason:`owner-capability-missing`,hint:`network is not supported by this web provider`});return Object.freeze({device:{family:`web`,kind:e.kind,...e.target===void 0?{}:{target:e.target},providerMode:t.mode},operations:{appLogInspect:w,appLogDoctor:w,appLogStart:w,appLogReattach:w,appLogCleanup:w,appState:k,networkDump:t.dump?C:r,screenRecordingStart:n?C:T,screenRecordingReattach:n?C:T,screenRecordingCleanup:n?C:T,...s({capture:e.kind===`device`?C:j,customActions:E,withoutActiveApp:e.kind===`device`?C:j}),ensureReady:D,bootTarget:D,bootTargetHeadless:D,listApps:O,deployApp:D,materializeAppSource:D,deployMaterializedApp:D,sendPushNotification:D,shutdownTarget:D,...P(e)}})}export{L as createWebPlatformRuntime};