agent-device 0.21.12 → 0.21.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.12.apk → agent-device-android-ime-helper-0.21.13.apk} +0 -0
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.13.apk.sha256 +1 -0
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.12.manifest.json → agent-device-android-ime-helper-0.21.13.manifest.json} +4 -4
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.12.apk → agent-device-android-snapshot-helper-0.21.13.apk} +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.13.apk.sha256 +1 -0
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.12.manifest.json → agent-device-android-snapshot-helper-0.21.13.manifest.json} +6 -6
- package/apple/macos-helper/Package.swift +4 -0
- package/apple/macos-helper/Sources/AgentDeviceMacOSHelper/main.swift +3 -6
- package/apple/macos-helper/Tests/AgentDeviceMacOSHelperTests/ScreenshotResponseTests.swift +15 -0
- package/apple/snapshot-bridge/SnapshotBridgeRuntime.m +47 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerApp.m +99 -42
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunner/Info.plist +23 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunner.xcodeproj/project.pbxproj +17 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAppScreenCapture.swift +21 -13
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerScrollViewportPolicy.swift +1 -162
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.h +0 -9
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.m +0 -56
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSystemSurfaceHostPolicy.swift +0 -48
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTapPointPolicy.swift +0 -50
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AXSnapshotFallback.swift +22 -568
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Alert.swift +21 -9
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+BlockingSystemModalResolution.swift +0 -36
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandDispatch.swift +630 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +18 -2236
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandJournal.swift +1 -338
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Environment.swift +0 -12
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+GestureExecution.swift +165 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +0 -24
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Keyboard.swift +0 -142
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Lifecycle.swift +90 -39
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+MainThreadWork.swift +78 -106
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +23 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Navigation.swift +147 -95
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+PrivateAXPresentation.swift +0 -209
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScreenRecorder.swift +86 -10
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScrollDragExecution.swift +287 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScrollGesture.swift +1 -200
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SequenceExecution.swift +0 -185
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift +75 -285
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotAcquisition.swift +23 -10
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotBackendCapabilities.swift +0 -78
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotCapturePlan.swift +83 -578
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotCaptureTarget.swift +106 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotExecution.swift +142 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotTiming.swift +49 -78
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedCommitDeadline.swift +0 -44
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedGesturePolicy.swift +27 -97
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedInteraction.swift +1 -11
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedTextEntry.swift +11 -87
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SystemModal.swift +2 -10
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntry.swift +1 -1
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntryFocus.swift +0 -35
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextInputCandidatePolicy.swift +0 -31
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextTyping.swift +2 -18
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Transport.swift +34 -52
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TvRemote.swift +0 -22
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TypeExecution.swift +142 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +22 -6
- package/dist/apple/runner/AgentDeviceRunner/RecordingScripts/recording-overlay.swift +140 -20
- package/dist/src/absence-observation-errors.js +1 -1
- package/dist/src/adapter.js +1 -1
- package/dist/src/agent-device-client.js +1 -1
- package/dist/src/alert-runtime.js +1 -1
- package/dist/src/android-adb.d.ts +1 -1
- package/dist/src/app-launch.js +2 -2
- package/dist/src/app-log-runtime2.js +3 -3
- package/dist/src/app-resolution.js +2 -2
- package/dist/src/back-mode.js +1 -1
- package/dist/src/capture-disclosure.js +1 -1
- package/dist/src/capture.js +1 -1
- package/dist/src/cli-config.js +1 -1
- package/dist/src/cli-help.js +6 -5
- package/dist/src/cli-runner.js +1 -1
- package/dist/src/cli.js +1 -1
- package/dist/src/client-types.d.ts +4 -5
- package/dist/src/code-signature.js +1 -1
- package/dist/src/command-schema.js +3 -3
- package/dist/src/command-tools.js +3 -3
- package/dist/src/connection.js +1 -1
- package/dist/src/daemon-client-lifecycle.js +1 -1
- package/dist/src/daemon-resolution.js +1 -1
- package/dist/src/device-claim-rule.js +2 -2
- package/dist/src/device-input-state.d.ts +1 -1
- package/dist/src/device-session.js +1 -1
- package/dist/src/devicectl.js +1 -1
- package/dist/src/display-inventory.js +1 -1
- package/dist/src/doctor-facade.js +1 -1
- package/dist/src/find.js +1 -1
- package/dist/src/gesture-plan-types.d.ts +38 -0
- package/dist/src/harmonyos.js +1 -1
- package/dist/src/helper.js +1 -1
- package/dist/src/host.js +1 -1
- package/dist/src/install-source-network-transport.js +1 -1
- package/dist/src/install-source2.js +1 -1
- package/dist/src/interaction-ref-policy.js +1 -1
- package/dist/src/interaction2.js +1 -1
- package/dist/src/interactor-operation-catalog.js +1 -1
- package/dist/src/interactor.js +4 -4
- package/dist/src/interactor2.js +1 -1
- package/dist/src/internal/bin.js +1 -1
- package/dist/src/internal/daemon.js +2 -2
- package/dist/src/inventory2.js +1 -1
- package/dist/src/ios-snapshot-acquisition.js +1 -1
- package/dist/src/ios-snapshot-runtime.js +1 -1
- package/dist/src/limrun-runtime-dependencies.js +1 -1
- package/dist/src/limrun.d.ts +435 -4
- package/dist/src/linux.js +1 -1
- package/dist/src/local-interactor-operation-set.js +1 -1
- package/dist/src/managed-device-scope.js +1 -1
- package/dist/src/mechanics.js +4 -4
- package/dist/src/mobile-snapshot-semantics.js +1 -1
- package/dist/src/perf-facade.js +1 -2
- package/dist/src/perf-runtime-plan.js +1 -1
- package/dist/src/perf-target.js +2 -0
- package/dist/src/physical-device-apps.js +1 -0
- package/dist/src/physical-device-control.js +1 -1
- package/dist/src/platform-request-scope.js +1 -1
- package/dist/src/platform-runtime-operation-host.js +1 -1
- package/dist/src/platform-runtime-screen-recording-finalizer-host.js +1 -1
- package/dist/src/platform-runtime-unavailable.js +1 -1
- package/dist/src/platform-runtime.js +1 -1
- package/dist/src/platform-runtime2.js +1 -1
- package/dist/src/provider-webdriver.js +1 -1
- package/dist/src/proxy.js +1 -1
- package/dist/src/quality-warnings.js +1 -1
- package/dist/src/react-native.js +1 -1
- package/dist/src/record-runtime.js +1 -1
- package/dist/src/registry.js +35 -35
- package/dist/src/request-admission.js +1 -1
- package/dist/src/request-runtime-binding.js +1 -1
- package/dist/src/runner-client.js +1 -1
- package/dist/src/runner-dev-tools-security.js +1 -1
- package/dist/src/runner-device-readiness.js +1 -1
- package/dist/src/runner-disposal.js +1 -1
- package/dist/src/runner-error-classification.js +3 -0
- package/dist/src/runner-operations-facade.js +1 -1
- package/dist/src/runner-presentation.js +1 -1
- package/dist/src/runner.js +1 -1
- package/dist/src/runtime.js +3 -3
- package/dist/src/runtime10.js +1 -1
- package/dist/src/runtime2.js +2 -2
- package/dist/src/runtime4.js +5 -5
- package/dist/src/runtime5.js +1 -1
- package/dist/src/runtime6.js +1 -1
- package/dist/src/runtime7.js +1 -1
- package/dist/src/runtime8.js +1 -1
- package/dist/src/runtime9.js +1 -1
- package/dist/src/screen-recording-admission-ledger.js +1 -1
- package/dist/src/screen-recording-resource-recovery.js +1 -1
- package/dist/src/screen-recording-transport.js +1 -1
- package/dist/src/screenshot-runtime.js +1 -1
- package/dist/src/screenshot3.js +1 -1
- package/dist/src/script.js +1 -1
- package/dist/src/scroll-command.d.ts +377 -0
- package/dist/src/scroll-command.js +1 -1
- package/dist/src/sdk-batch.js +2 -2
- package/dist/src/sdk-contracts.d.ts +9 -0
- package/dist/src/sdk-device.js +1 -1
- package/dist/src/sdk-selectors.d.ts +23 -726
- package/dist/src/selection.js +0 -0
- package/dist/src/selector-runtime.js +1 -1
- package/dist/src/semantic-index.js +1 -1
- package/dist/src/server.js +1 -1
- package/dist/src/session-observation.js +1 -1
- package/dist/src/session-snapshot.js +1 -1
- package/dist/src/session2.js +2 -2
- package/dist/src/simctl-facade.js +1 -1
- package/dist/src/simctl.js +1 -1
- package/dist/src/simulator-state.js +1 -1
- package/dist/src/simulator.js +1 -1
- package/dist/src/snapshot-runtime-binding.js +1 -1
- package/dist/src/snapshot-runtime.js +1 -1
- package/dist/src/snapshot-state.js +1 -1
- package/dist/src/snapshot4.js +1 -1
- package/dist/src/src7.js +1 -1
- package/dist/src/text-entry-focus.js +1 -1
- package/dist/src/tool-provider.js +1 -1
- package/dist/src/touch-runtime.js +1 -1
- package/dist/src/tree.js +1 -1
- package/dist/src/update-check.js +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/web2.js +1 -1
- package/package.json +3 -2
- package/server.json +2 -2
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.12.apk.sha256 +0 -1
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.12.apk.sha256 +0 -1
- package/dist/src/app-inventory.d.ts +0 -4
- package/dist/src/apps-simctl.js +0 -1
- package/dist/src/cloud-artifacts.d.ts +0 -61
- package/dist/src/runner-contract.js +0 -3
|
@@ -11,6 +11,13 @@ let minimumPinchVisibility: CFTimeInterval = 0.5
|
|
|
11
11
|
let swipeVisibilityTail: CFTimeInterval = 0.16
|
|
12
12
|
let trailOpacityKeyTimes: [NSNumber] = [0.0, 0.08, 0.62, 1.0]
|
|
13
13
|
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
let compositedBlackFrameLuma: Double = 1.0
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
let sourceVisibleFrameLuma: Double = 2.0
|
|
20
|
+
|
|
14
21
|
struct GestureEnvelope: Decodable {
|
|
15
22
|
let events: [GestureEvent]
|
|
16
23
|
}
|
|
@@ -129,7 +136,7 @@ func run() throws {
|
|
|
129
136
|
|
|
130
137
|
|
|
131
138
|
|
|
132
|
-
let presetName = exportPresetName(
|
|
139
|
+
let presetName = try exportPresetName(compatibleWith: composition)
|
|
133
140
|
let exporter = try makeRecordingExporter(
|
|
134
141
|
composition,
|
|
135
142
|
presetName: presetName,
|
|
@@ -141,17 +148,19 @@ func run() throws {
|
|
|
141
148
|
timeoutMessage: "Touch overlay export timed out.",
|
|
142
149
|
failureMessage: "Touch overlay export failed."
|
|
143
150
|
)
|
|
151
|
+
try verifyCompositedOverlay(
|
|
152
|
+
input: inputURL,
|
|
153
|
+
output: outputURL,
|
|
154
|
+
expectedRenderSize: renderSize
|
|
155
|
+
)
|
|
144
156
|
}
|
|
145
157
|
|
|
146
158
|
func parseArguments(
|
|
147
159
|
_ arguments: [String]
|
|
148
|
-
) throws -> (inputPath: String, outputPath: String, eventsPath: String
|
|
160
|
+
) throws -> (inputPath: String, outputPath: String, eventsPath: String) {
|
|
149
161
|
var inputPath: String?
|
|
150
162
|
var outputPath: String?
|
|
151
163
|
var eventsPath: String?
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
var exportQuality: ExportQuality = .medium
|
|
155
164
|
var index = 0
|
|
156
165
|
|
|
157
166
|
while index < arguments.count {
|
|
@@ -168,11 +177,13 @@ func parseArguments(
|
|
|
168
177
|
eventsPath = try recordingOptionValue(arguments, nextIndex, "--events")
|
|
169
178
|
index += 2
|
|
170
179
|
case "--quality":
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
171
183
|
let rawValue = try recordingOptionValue(arguments, nextIndex, "--quality")
|
|
172
|
-
guard
|
|
184
|
+
guard ExportQuality(rawValue: rawValue) != nil else {
|
|
173
185
|
throw RecordingScriptError.invalidArgs("--quality must be one of: medium, high")
|
|
174
186
|
}
|
|
175
|
-
exportQuality = parsed
|
|
176
187
|
index += 2
|
|
177
188
|
default:
|
|
178
189
|
throw RecordingScriptError.invalidArgs("Unknown argument: \(argument)")
|
|
@@ -184,24 +195,22 @@ func parseArguments(
|
|
|
184
195
|
"Usage: recording-overlay.swift --input <video> --output <video> --events <json> [--quality <medium|high>]"
|
|
185
196
|
)
|
|
186
197
|
}
|
|
187
|
-
return (inputPath, outputPath, eventsPath
|
|
198
|
+
return (inputPath, outputPath, eventsPath)
|
|
188
199
|
}
|
|
189
200
|
|
|
190
|
-
func exportPresetName(
|
|
191
|
-
for exportQuality: ExportQuality,
|
|
192
|
-
compatibleWith asset: AVAsset
|
|
193
|
-
) -> String {
|
|
194
|
-
switch exportQuality {
|
|
195
|
-
case .high:
|
|
196
|
-
return AVAssetExportPresetHighestQuality
|
|
197
|
-
case .medium:
|
|
198
201
|
|
|
199
202
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
func exportPresetName(compatibleWith asset: AVAsset) throws -> String {
|
|
208
|
+
guard AVAssetExportSession.exportPresets(compatibleWith: asset).contains(AVAssetExportPresetHighestQuality) else {
|
|
209
|
+
throw RecordingScriptError.exportFailed(
|
|
210
|
+
"No geometry-preserving export preset is available; refusing to rescale the capture."
|
|
211
|
+
)
|
|
204
212
|
}
|
|
213
|
+
return AVAssetExportPresetHighestQuality
|
|
205
214
|
}
|
|
206
215
|
|
|
207
216
|
func resolvedRenderSize(for track: AVAssetTrack) -> CGSize {
|
|
@@ -209,6 +218,117 @@ func resolvedRenderSize(for track: AVAssetTrack) -> CGSize {
|
|
|
209
218
|
return CGSize(width: abs(transformed.width), height: abs(transformed.height))
|
|
210
219
|
}
|
|
211
220
|
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
func verifyCompositedOverlay(input: URL, output: URL, expectedRenderSize: CGSize) throws {
|
|
226
|
+
let composited = AVURLAsset(url: output)
|
|
227
|
+
guard let track = composited.tracks(withMediaType: .video).first else {
|
|
228
|
+
throw RecordingScriptError.exportFailed("Touch overlay export produced no video track.")
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
let producedSize = resolvedRenderSize(for: track)
|
|
232
|
+
if !renderSizeMatches(producedSize, expectedRenderSize) {
|
|
233
|
+
throw RecordingScriptError.exportFailed(
|
|
234
|
+
"Touch overlay export changed the track geometry: \(Int(producedSize.width))x\(Int(producedSize.height)) instead of \(Int(expectedRenderSize.width))x\(Int(expectedRenderSize.height))."
|
|
235
|
+
)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
guard let compositedLuma = meanFrameLuma(of: composited) else {
|
|
240
|
+
throw RecordingScriptError.exportFailed("Touch overlay export produced no decodable frames.")
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
let source = AVURLAsset(url: input)
|
|
244
|
+
let sourceDuration = CMTimeGetSeconds(source.duration)
|
|
245
|
+
let producedDuration = CMTimeGetSeconds(composited.duration)
|
|
246
|
+
if sourceDuration.isFinite, sourceDuration > 1, producedDuration.isFinite,
|
|
247
|
+
producedDuration < sourceDuration * 0.5
|
|
248
|
+
{
|
|
249
|
+
throw RecordingScriptError.exportFailed(
|
|
250
|
+
"Touch overlay export truncated the track to \(Int(producedDuration))s of \(Int(sourceDuration))s."
|
|
251
|
+
)
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if compositedLuma <= compositedBlackFrameLuma,
|
|
255
|
+
let sourceLuma = meanFrameLuma(of: source),
|
|
256
|
+
sourceLuma > sourceVisibleFrameLuma
|
|
257
|
+
{
|
|
258
|
+
throw RecordingScriptError.exportFailed(
|
|
259
|
+
"Touch overlay export produced an all-black track while the raw capture had visible content."
|
|
260
|
+
)
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
func renderSizeMatches(_ produced: CGSize, _ expected: CGSize) -> Bool {
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
let tolerance: CGFloat = 32
|
|
268
|
+
return abs(produced.width - expected.width) <= tolerance
|
|
269
|
+
&& abs(produced.height - expected.height) <= tolerance
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
func meanFrameLuma(of asset: AVURLAsset, sampleCount: Int = 5) -> Double? {
|
|
273
|
+
let duration = CMTimeGetSeconds(asset.duration)
|
|
274
|
+
guard duration.isFinite, duration > 0 else { return nil }
|
|
275
|
+
let generator = AVAssetImageGenerator(asset: asset)
|
|
276
|
+
generator.appliesPreferredTrackTransform = true
|
|
277
|
+
generator.requestedTimeToleranceBefore = .positiveInfinity
|
|
278
|
+
generator.requestedTimeToleranceAfter = .positiveInfinity
|
|
279
|
+
|
|
280
|
+
generator.maximumSize = CGSize(width: 64, height: 64)
|
|
281
|
+
|
|
282
|
+
var total = 0.0
|
|
283
|
+
var sampled = 0
|
|
284
|
+
for index in 0..<sampleCount {
|
|
285
|
+
let fraction = (Double(index) + 0.5) / Double(sampleCount)
|
|
286
|
+
let time = CMTime(seconds: fraction * duration, preferredTimescale: 600)
|
|
287
|
+
guard let image = try? generator.copyCGImage(at: time, actualTime: nil),
|
|
288
|
+
let luma = frameMeanLuma(image)
|
|
289
|
+
else { continue }
|
|
290
|
+
total += luma
|
|
291
|
+
sampled += 1
|
|
292
|
+
}
|
|
293
|
+
guard sampled > 0 else { return nil }
|
|
294
|
+
return total / Double(sampled)
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
func frameMeanLuma(_ image: CGImage) -> Double? {
|
|
298
|
+
let width = image.width
|
|
299
|
+
let height = image.height
|
|
300
|
+
guard width > 0, height > 0 else { return nil }
|
|
301
|
+
let bytesPerRow = width * 4
|
|
302
|
+
var pixels = [UInt8](repeating: 0, count: bytesPerRow * height)
|
|
303
|
+
let drawn = pixels.withUnsafeMutableBytes { raw -> Bool in
|
|
304
|
+
guard
|
|
305
|
+
let context = CGContext(
|
|
306
|
+
data: raw.baseAddress,
|
|
307
|
+
width: width,
|
|
308
|
+
height: height,
|
|
309
|
+
bitsPerComponent: 8,
|
|
310
|
+
bytesPerRow: bytesPerRow,
|
|
311
|
+
space: CGColorSpaceCreateDeviceRGB(),
|
|
312
|
+
bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue
|
|
313
|
+
)
|
|
314
|
+
else { return false }
|
|
315
|
+
context.draw(image, in: CGRect(x: 0, y: 0, width: width, height: height))
|
|
316
|
+
return true
|
|
317
|
+
}
|
|
318
|
+
guard drawn else { return nil }
|
|
319
|
+
|
|
320
|
+
var total = 0.0
|
|
321
|
+
var count = 0
|
|
322
|
+
for offset in stride(from: 0, to: bytesPerRow * height, by: 4) {
|
|
323
|
+
total += 0.299 * Double(pixels[offset])
|
|
324
|
+
+ 0.587 * Double(pixels[offset + 1])
|
|
325
|
+
+ 0.114 * Double(pixels[offset + 2])
|
|
326
|
+
count += 1
|
|
327
|
+
}
|
|
328
|
+
guard count > 0 else { return nil }
|
|
329
|
+
return total / Double(count)
|
|
330
|
+
}
|
|
331
|
+
|
|
212
332
|
func resolvedFrameDuration(for track: AVAssetTrack) -> CMTime {
|
|
213
333
|
let minFrameDuration = track.minFrameDuration
|
|
214
334
|
if minFrameDuration.isValid && !minFrameDuration.isIndefinite && minFrameDuration.seconds > 0 {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{D as e,O as t}from"./sdk-contracts.js";import{Ir as n,Mr as r,qn as i,rr as a}from"./sdk-batch.js";import{n as o}from"./scroll-indicator.js";function s(e){let t=f(e.label),n=f(e.value),r=f(e.identifier),i=m(r)?r:``;return p(e.type??``)?n||t||i:t||n||i}function c(e,t){if(t===`text-view`||t===`text-field`||t===`search`)return!0;let r=n(e.type??``),i=`${e.role??``} ${e.subrole??``}`.toLowerCase();return r.includes(`textview`)||r.includes(`textarea`)||r.includes(`textfield`)||r.includes(`securetextfield`)||r.includes(`searchfield`)||r.includes(`edittext`)||i.includes(`text area`)||i.includes(`text field`)}function l(e){let t=e.replaceAll(/\s+/g,` `).trim();return t.length<=48?t:`${t.slice(0,45)}...`}function u(e,t){let n=s(e),r=c(e,t);return{text:n,isLargeSurface:r,shouldSummarize:r&&d(n)}}function d(e){return e?e.length>80||/[\r\n]/.test(e):!1}function f(e){return typeof e==`string`?e.trim():``}function p(e){let t=n(e);return t.includes(`textfield`)||t.includes(`securetextfield`)||t.includes(`searchfield`)||t.includes(`edittext`)||t.includes(`textview`)||t.includes(`textarea`)}function m(e){return e?!/^[\w.]+:id\/[\w.-]+$/i.test(e)&&!/^_?NS:\d+$/i.test(e):!1}const h={application:`application`,navigationbar:`navigation-bar`,tabbar:`tab-bar`,button:`button`,imagebutton:`button`,link:`link`,cell:`cell`,statictext:`text`,checkedtextview:`text`,textbox:`text-field`,textfield:`text-field`,edittext:`text-field`,textarea:`text-view`,switch:`switch`,slider:`slider`,image:`image`,imageview:`image`,webview:`webview`,framelayout:`group`,linearlayout:`group`,relativelayout:`group`,constraintlayout:`group`,viewgroup:`group`,view:`group`,listview:`list`,recyclerview:`list`,collectionview:`collection`,searchfield:`search`,heading:`heading`,activityindicator:`activity-indicator`,progressindicator:`progress-indicator`,segmentedcontrol:`segmented-control`,group:`group`,window:`window`,checkbox:`checkbox`,radio:`radio`,menuitem:`menu-item`,toolbar:`toolbar`,scrollarea:`scroll-area`,scrollview:`scroll-area`,nestedscrollview:`scroll-area`,table:`table`};function g(e,t={}){let n=[],r=[];for(let i of e){let e=i.depth??0,a=i.label?.trim()||i.value?.trim()||i.identifier?.trim()||``,o=x(i.type??`Element`),s=i.inheritsLabel===!0||i.inheritsIdentifier===!0;if(o===`group`&&!a&&!s)continue;for(;n.length>0&&e<=n.at(-1);)n.pop();let c=n.length;n.push(e),r.push({node:i,depth:c,type:o,text:_(i,c,!1,o,t)})}return r}function _(e,t,n,r,i={}){let a=r??x(e.type??`Element`),o=u(e,a),s=E(e,a,i,o),c=` `.repeat(t),l=e.ref?`@${e.ref}`:``,d=D(e,a,i,o);!s&&(e.inheritsLabel===!0||e.inheritsIdentifier===!0)&&d.push(`same label as parent`);let f=d.map(e=>` [${e}]`).join(``),p=s?` "${s}"`:``,m=v(e);return n?`${c}${l} [${a}]${f}${m}`.trimEnd():`${c}${l} [${a}]${p}${f}${m}`.trimEnd()}function v(e){let t=e.actions?.filter(e=>e.trim().length>0);return!t||t.length===0?``:` actions: [${t.map(e=>`"${A(y(e))}"`).join(`, `)}]`}function y(e){return e.replaceAll(/\s+/g,` `).replaceAll(/[\u0000-\u001f\u007f-\u009f]/g,``).trim()}function b(e,t){let n=e.label?.trim();if(n&&w(t,n))return``;let r=e.value?.trim();if(C(t)){if(r)return r;if(n)return n}else if(n)return n;if(r)return r;let i=e.identifier?.trim();return!i||T(i)&&(t===`group`||t===`image`||t===`list`||t===`collection`)?``:i}function x(e){let t=e,n=e.replaceAll(/XCUIElementType/gi,``).toLowerCase(),r=t.includes(`.`)&&(t.startsWith(`android.`)||t.startsWith(`androidx.`)||t.startsWith(`com.`));return n.includes(`.`)&&(n=n.replace(/^android\.widget\./,``).replace(/^android\.view\./,``).replace(/^android\.webkit\./,``).replace(/^androidx\./,``).replace(/^com\.google\.android\./,``).replace(/^com\.android\./,``),r&&n.includes(`.`)&&(n=n.slice(n.lastIndexOf(`.`)+1))),n===`textview`?r?`text`:`text-view`:S(n)||n||`element`}function S(e){return Object.prototype.hasOwnProperty.call(h,e)?h[e]:void 0}function C(e){return e===`text-field`||e===`text-view`||e===`search`}function w(e,t){return e!==`scroll-area`&&e!==`list`&&e!==`collection`&&e!==`table`?!1:o(t)}function T(e){return/^[\w.]+:id\/[\w.-]+$/i.test(e)}function E(e,t,n,r){return!n.summarizeTextSurfaces||!r.shouldSummarize?b(e,t):O(e,t,r.text)||b(e,t)}function D(e,t,n,r){let i=[];return e.enabled===!1&&i.push(`disabled`),e.selected===!0&&i.push(`selected`),i.push(...e.presentationHints??[]),!n.summarizeTextSurfaces||(e.focused===!0&&i.push(`focused`),C(t)&&i.push(`editable`),k(e,t)&&i.push(`scrollable`),!r.shouldSummarize)?j(i):(i.push(`preview:"${A(l(r.text))}"`),i.push(`truncated`),j(i))}function O(e,t,n){let r=f(e.label);if(r&&r!==n)return r;let i=f(e.identifier);if(i&&!T(i)&&i!==n)return i;switch(t){case`text`:case`text-view`:return`Text view`;case`text-field`:return`Text field`;case`search`:return`Search field`;default:return``}}function k(e,t){if(t===`scroll-area`)return!0;let n=(e.type??``).toLowerCase(),r=`${e.role??``} ${e.subrole??``}`.toLowerCase();return n.includes(`scroll`)||r.includes(`scroll`)}function A(e){return e.replaceAll(`\\`,String.raw`\\`).replaceAll(`"`,String.raw`\"`)}function j(e){return[...new Set(e)]}const M={state:`sparse`,backend:`tree`,reason:`legacy iOS capture exposed only the application root`,reasonCode:`sparse-tree`};function N(e){if(e.scope!==void 0)return`scope`;if(e.depth!==void 0)return`depth`}function
|
|
1
|
+
import{D as e,O as t}from"./sdk-contracts.js";import{Ir as n,Mr as r,qn as i,rr as a}from"./sdk-batch.js";import{n as o}from"./scroll-indicator.js";function s(e){let t=f(e.label),n=f(e.value),r=f(e.identifier),i=m(r)?r:``;return p(e.type??``)?n||t||i:t||n||i}function c(e,t){if(t===`text-view`||t===`text-field`||t===`search`)return!0;let r=n(e.type??``),i=`${e.role??``} ${e.subrole??``}`.toLowerCase();return r.includes(`textview`)||r.includes(`textarea`)||r.includes(`textfield`)||r.includes(`securetextfield`)||r.includes(`searchfield`)||r.includes(`edittext`)||i.includes(`text area`)||i.includes(`text field`)}function l(e){let t=e.replaceAll(/\s+/g,` `).trim();return t.length<=48?t:`${t.slice(0,45)}...`}function u(e,t){let n=s(e),r=c(e,t);return{text:n,isLargeSurface:r,shouldSummarize:r&&d(n)}}function d(e){return e?e.length>80||/[\r\n]/.test(e):!1}function f(e){return typeof e==`string`?e.trim():``}function p(e){let t=n(e);return t.includes(`textfield`)||t.includes(`securetextfield`)||t.includes(`searchfield`)||t.includes(`edittext`)||t.includes(`textview`)||t.includes(`textarea`)}function m(e){return e?!/^[\w.]+:id\/[\w.-]+$/i.test(e)&&!/^_?NS:\d+$/i.test(e):!1}const h={application:`application`,navigationbar:`navigation-bar`,tabbar:`tab-bar`,button:`button`,imagebutton:`button`,link:`link`,cell:`cell`,statictext:`text`,checkedtextview:`text`,textbox:`text-field`,textfield:`text-field`,edittext:`text-field`,textarea:`text-view`,switch:`switch`,slider:`slider`,image:`image`,imageview:`image`,webview:`webview`,framelayout:`group`,linearlayout:`group`,relativelayout:`group`,constraintlayout:`group`,viewgroup:`group`,view:`group`,listview:`list`,recyclerview:`list`,collectionview:`collection`,searchfield:`search`,heading:`heading`,activityindicator:`activity-indicator`,progressindicator:`progress-indicator`,segmentedcontrol:`segmented-control`,group:`group`,window:`window`,checkbox:`checkbox`,radio:`radio`,menuitem:`menu-item`,toolbar:`toolbar`,scrollarea:`scroll-area`,scrollview:`scroll-area`,nestedscrollview:`scroll-area`,table:`table`};function g(e,t={}){let n=[],r=[];for(let i of e){let e=i.depth??0,a=i.label?.trim()||i.value?.trim()||i.identifier?.trim()||``,o=x(i.type??`Element`),s=i.inheritsLabel===!0||i.inheritsIdentifier===!0;if(o===`group`&&!a&&!s)continue;for(;n.length>0&&e<=n.at(-1);)n.pop();let c=n.length;n.push(e),r.push({node:i,depth:c,type:o,text:_(i,c,!1,o,t)})}return r}function _(e,t,n,r,i={}){let a=r??x(e.type??`Element`),o=u(e,a),s=E(e,a,i,o),c=` `.repeat(t),l=e.ref?`@${e.ref}`:``,d=D(e,a,i,o);!s&&(e.inheritsLabel===!0||e.inheritsIdentifier===!0)&&d.push(`same label as parent`);let f=d.map(e=>` [${e}]`).join(``),p=s?` "${s}"`:``,m=v(e);return n?`${c}${l} [${a}]${f}${m}`.trimEnd():`${c}${l} [${a}]${p}${f}${m}`.trimEnd()}function v(e){let t=e.actions?.filter(e=>e.trim().length>0);return!t||t.length===0?``:` actions: [${t.map(e=>`"${A(y(e))}"`).join(`, `)}]`}function y(e){return e.replaceAll(/\s+/g,` `).replaceAll(/[\u0000-\u001f\u007f-\u009f]/g,``).trim()}function b(e,t){let n=e.label?.trim();if(n&&w(t,n))return``;let r=e.value?.trim();if(C(t)){if(r)return r;if(n)return n}else if(n)return n;if(r)return r;let i=e.identifier?.trim();return!i||T(i)&&(t===`group`||t===`image`||t===`list`||t===`collection`)?``:i}function x(e){let t=e,n=e.replaceAll(/XCUIElementType/gi,``).toLowerCase(),r=t.includes(`.`)&&(t.startsWith(`android.`)||t.startsWith(`androidx.`)||t.startsWith(`com.`));return n.includes(`.`)&&(n=n.replace(/^android\.widget\./,``).replace(/^android\.view\./,``).replace(/^android\.webkit\./,``).replace(/^androidx\./,``).replace(/^com\.google\.android\./,``).replace(/^com\.android\./,``),r&&n.includes(`.`)&&(n=n.slice(n.lastIndexOf(`.`)+1))),n===`textview`?r?`text`:`text-view`:S(n)||n||`element`}function S(e){return Object.prototype.hasOwnProperty.call(h,e)?h[e]:void 0}function C(e){return e===`text-field`||e===`text-view`||e===`search`}function w(e,t){return e!==`scroll-area`&&e!==`list`&&e!==`collection`&&e!==`table`?!1:o(t)}function T(e){return/^[\w.]+:id\/[\w.-]+$/i.test(e)}function E(e,t,n,r){return!n.summarizeTextSurfaces||!r.shouldSummarize?b(e,t):O(e,t,r.text)||b(e,t)}function D(e,t,n,r){let i=[];return e.enabled===!1&&i.push(`disabled`),e.selected===!0&&i.push(`selected`),i.push(...e.presentationHints??[]),!n.summarizeTextSurfaces||(e.focused===!0&&i.push(`focused`),C(t)&&i.push(`editable`),k(e,t)&&i.push(`scrollable`),!r.shouldSummarize)?j(i):(i.push(`preview:"${A(l(r.text))}"`),i.push(`truncated`),j(i))}function O(e,t,n){let r=f(e.label);if(r&&r!==n)return r;let i=f(e.identifier);if(i&&!T(i)&&i!==n)return i;switch(t){case`text`:case`text-view`:return`Text view`;case`text-field`:return`Text field`;case`search`:return`Search field`;default:return``}}function k(e,t){if(t===`scroll-area`)return!0;let n=(e.type??``).toLowerCase(),r=`${e.role??``} ${e.subrole??``}`.toLowerCase();return n.includes(`scroll`)||r.includes(`scroll`)}function A(e){return e.replaceAll(`\\`,String.raw`\\`).replaceAll(`"`,String.raw`\"`)}function j(e){return[...new Set(e)]}const M={state:`sparse`,backend:`tree`,reason:`legacy iOS capture exposed only the application root`,reasonCode:`sparse-tree`},N={sparse:`capture was sparse`,truncated:`capture was truncated`,unsettled:`the surface was still changing after a gesture`};function P(e){return typeof e==`string`&&Object.hasOwn(N,e)}function F(e){if(e.scope!==void 0)return`scope`;if(e.depth!==void 0)return`depth`}function I(e,t=`is`){let n=`${t} absent`;return e===`scope`?`${n} does not support --scope; it requires an unscoped capture`:`${n} does not support --depth; it requires a full-depth capture`}function L(e,t){let n=t[0]?B(t[0]):void 0,r=t.length;if(e.truncated===!0)return{kind:`truncated`,matches:r,...n?{firstMatch:n}:{}};let i=R(e);return i?{kind:`sparse`,matches:r,...n?{firstMatch:n}:{},quality:{state:i.state,backend:i.backend,...i.reason?{reason:i.reason}:{},...i.reasonCode?{reasonCode:i.reasonCode}:{}}}:r===0?{kind:e.unsettledGesture?`unsettled`:`absent`,matches:0}:{kind:`present`,matches:r,firstMatch:n}}function R(e){let t=e.snapshotQuality;return t?.state===`sparse`?{state:t.state,backend:t.backend,...t.reason?{reason:t.reason}:{},...t.reasonCode?{reasonCode:t.reasonCode}:{}}:z(e)?M:void 0}function z(e){return e.snapshotQuality||e.backend!==`xctest`||e.nodes.length!==1?!1:n(e.nodes[0]?.type??``)===`application`}function B(e){let t=i(e),n=a(r(e),256);return{...t,...n&&n!==t.label?{text:n}:{}}}const V={selectorNotFound:`selector_not_found`,predicateFailed:`predicate_failed`};function H(t,n=`is`){return new e(`INVALID_ARGS`,I(t,n),{command:n,predicate:`absent`,rejectedOption:t})}function U(t,n,r=`is`){let i=`firstMatch`in n?n.firstMatch:void 0,a={command:r,reason:V.predicateFailed,predicate:`absent`,selector:t,matches:n.matches,observation:n.kind,...i?{firstMatch:i}:{},...n.kind===`sparse`?{snapshotQuality:n.quality}:{},...n.kind===`truncated`?{truncated:!0}:{}};if(n.kind===`present`){let i=n.matches>1;return new e(`COMMAND_FAILED`,`${r} absent failed for selector ${t}: ${n.matches} match${i?`es`:``} found`,{...a,...i?{hint:`Refine the selector to match no elements.`}:{}})}return new e(`COMMAND_FAILED`,`${r} absent could not prove absence for selector ${t}: ${N[n.kind]}`,{...a,hint:`Retry after the accessibility capture is complete.`})}function W(n,r,i=`is`){let a=t(r),o=typeof a.details?.reason==`string`?a.details.reason:typeof a.details?.androidSnapshotHelperFailureReason==`string`?a.details.androidSnapshotHelperFailureReason:void 0;return new e(`COMMAND_FAILED`,`${i} absent could not prove absence for selector ${n}: capture was unreadable`,{command:i,reason:V.predicateFailed,predicate:`absent`,selector:n,matches:0,observation:`unreadable`,captureErrorCode:a.code,...o?{captureErrorReason:o}:{},hint:`Retry after the accessibility capture is readable.`},a)}export{F as a,P as c,b as d,x as f,p as h,V as i,R as l,s as m,U as n,L as o,_ as p,W as r,z as s,H as t,g as u};
|
package/dist/src/adapter.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{D as e,F as t}from"./sdk-contracts.js";import{Ur as n,Wr as r}from"./sdk-batch.js";import{c as i,r as a}from"./diagnostics.js";import{f as o,x as s}from"./owner-identity.js";import{c,l,m as u,r as d}from"./exec.js";import{n as f,t as p}from"./file.js";import"./diagnostics2.js";import"./command.js";import{n as m}from"./retry.js";import{n as ee}from"./version.js";import"./process.js";import{C as te,D as ne,c as re,f as ie,h as ae,n as oe,o as se,w as ce,y as le}from"./host-file.js";import{t as h}from"./apple-runner-platform.js";import{n as ue,r as de,t as fe}from"./snapshot-process.js";import g from"node:path";import{createHash as _,randomUUID as v}from"node:crypto";import pe from"node:net";import{Buffer as y}from"node:buffer";const me={unsupported:`UNSUPPORTED_OPERATION`,"malformed-tree":`COMMAND_FAILED`,"stale-target":`COMMAND_FAILED`,timeout:`COMMAND_FAILED`,cancelled:`COMMAND_FAILED`,"process-crash":`COMMAND_FAILED`,"transport-failure":`COMMAND_FAILED`,preparing:`COMMAND_FAILED`};var b=class extends e{failureKind;failureCode;constructor(e,t,n=`iOS Simulator snapshot source ${e}: ${t}`,r={},i){super(me[e],n,{...r,bridgeFailure:e,bridgeFailureCode:t,...e===`cancelled`?{reason:`request_canceled`}:{}},i),this.name=`SnapshotSourceError`,this.failureKind=e,this.failureCode=t}};function x(e,t,n={},r){return new b(e,t,void 0,n,r)}function S(n){return n instanceof b?n:t(n)?x(`cancelled`,`abort-signal`,{},n):n instanceof e&&typeof n.details?.timeoutMs==`number`?x(`timeout`,`host-operation-timeout`,{timeoutMs:n.details.timeoutMs},n):x(`transport-failure`,`unexpected-host-error`,{error:n instanceof Error?n.message:String(n)},n)}function C(e,t,n=Date.now){if(t?.aborted)throw x(`cancelled`,`abort-signal`);return{clock:m.fromTimeoutMs(e,n()),now:n,signal:t}}function w(e,t){if(e.signal?.aborted)throw x(`cancelled`,`abort-signal`);let n=e.clock.remainingMs(e.now());if(n<=0)throw x(`timeout`,t);return Math.max(1,Math.floor(n))}async function T(e,t,n,r){let i=Math.min(t,w(e,n));await de({waitMs:i,signal:e.signal,stop:r,cancelled:()=>x(`cancelled`,`abort-signal`)})}var he=class{entries=new Map;probeBackAfterUses;constructor(e=8){this.probeBackAfterUses=e}consume(e,t,n){if(n)return{nativeLevels:void 0,reason:`explicit-depth`};let r=this.currentEntry(e);return r===`unidentified`?{nativeLevels:void 0,reason:`unidentified-target`}:!r||r.nativeLevels>=t?{nativeLevels:void 0,reason:`no-hint`}:r.remainingUses<=0?{nativeLevels:void 0,reason:`probe-back`}:(--r.remainingUses,{nativeLevels:r.nativeLevels,reason:`hinted`})}learn(e,t,n,r){return n||!e.targetId?`ignored`:r.rejected>0&&r.acceptedLevels<t?(this.remember(e.targetId,{generation:e.generation,nativeLevels:r.acceptedLevels,remainingUses:this.probeBackAfterUses}),`learned`):r.rejected===0&&r.acceptedLevels>=t?this.entries.delete(e.targetId)?`forgotten`:`ignored`:this.currentEntry(e)?`kept`:`ignored`}currentEntry(e){if(!e.targetId)return`unidentified`;let t=this.entries.get(e.targetId);if(t){if(t.generation!==e.generation){this.entries.delete(e.targetId);return}return t}}remember(e,t){if(this.entries.delete(e),this.entries.size>=32){let e=this.entries.keys().next().value;e!==void 0&&this.entries.delete(e)}this.entries.set(e,t)}};const E=65536;function ge(){return{projectRoot:ee,homeDirectory:ie,run:async(e,t,n)=>await c(e,t,n),start:_e,connect:ve,readText:le,readBinary:ae,writeText:ne,ensureDirectory:se,chmod:oe,exists:re,rename:ce,remove:te,acquireLock:ye,emitDiagnostic:a,withDiagnosticTimer:i,processId:o,readTargetProcessStartTime:fe}}function _e(e,t,n,r={}){if(r.signal?.aborted)throw x(`cancelled`,`abort-signal`);let i=l(`xcrun`,[`simctl`,`spawn`,e,t,`serve`,n,`--idle-timeout`,`60`,`--exit-on-disconnect`,`false`],{allowFailure:!0,captureOutput:!1,detached:!0}),a=i.child.pid??0;if(a<=0)throw x(`transport-failure`,`bridge-process-pid-missing`);let o=``;return i.child.stderr?.setEncoding(`utf8`),i.child.stderr?.on(`data`,e=>{o=be(o,String(e))}),{pid:a,wait:i.wait,isAlive:()=>i.child.exitCode===null&&i.child.signalCode===null,signal:e=>{u(a,e)||i.child.kill(e)},readLog:()=>o}}async function ve(e,t){if(t.signal?.aborted)throw x(`cancelled`,`abort-signal`);let n=Math.max(1,Math.floor(t.timeoutMs));return await new Promise((r,i)=>{let a=pe.createConnection({path:e}),o=!1,s=!1,c=setTimeout(()=>{p(x(`timeout`,`bridge-connect-timeout`)),a.destroy()},n),l=()=>{p(x(`cancelled`,`abort-signal`)),a.destroy()},u=()=>{o=!0,clearTimeout(c),t.signal?.removeEventListener(`abort`,l),a.off(`error`,d),a.off(`close`,f),a.setTimeout(0),r(a)},d=e=>{p(e),a.destroy()},f=()=>{o||p(x(`transport-failure`,`bridge-closed-before-connect`))},p=e=>{s||o||(s=!0,clearTimeout(c),t.signal?.removeEventListener(`abort`,l),a.off(`connect`,u),a.off(`error`,d),a.off(`close`,f),i(e))};a.once(`connect`,u),a.once(`error`,d),a.once(`close`,f),t.signal?.addEventListener(`abort`,l,{once:!0}),t.signal?.aborted&&l()})}async function ye(e,t){let n=o(),r=t.deadline,i=p({lockDirPath:e,owner:{pid:n,startTime:s(n),acquiredAtMs:Date.now()},timeoutMs:w(r,`cache-lock-deadline`),pollMs:100,ownerGraceMs:5e3,description:`iOS Simulator snapshot bridge cache`}),a=r.signal;if(!a)return await i;let c=!1,l,u=new Promise((e,t)=>{l=()=>{c=!0,t(x(`cancelled`,`abort-signal`))},a.addEventListener(`abort`,l,{once:!0}),a.aborted&&l()});try{return await Promise.race([i,u])}catch(e){throw c&&i.then(e=>e().catch(()=>void 0),()=>void 0),r.clock.isExpired()&&!(e instanceof b&&e.failureKind===`cancelled`)?x(`timeout`,`cache-lock-deadline`):e}finally{a.removeEventListener(`abort`,l)}}function be(e,t){let n=e+t;return n.length<=E?n:n.slice(n.length-E)}function xe(e,t,n){let r=_(`sha256`).update(t).digest(`hex`).slice(0,12),i=_(`sha256`).update(n).digest(`hex`).slice(0,12);return g.join(`/tmp`,`agent-device-ax-${r}-${e.processId()}-${i}`,`snapshot.sock`)}const D=new WeakSet;async function O(e,t){let n;try{n=(await t.wait).exitCode}catch{n=void 0}return D.has(t)||(D.add(t),e.emitDiagnostic({level:`error`,phase:`ios.snapshot-source.bridge-process-exit`,data:{pid:t.pid,...n===void 0?{}:{exitCode:n},stderr:Se(t.readLog())}})),x(`process-crash`,`bridge-exited`,{pid:t.pid,...n===void 0?{}:{exitCode:n}})}function Se(e){let t=y.from(e);return t.length<=65536?e:t.subarray(-65536).toString(`utf8`)}const k=`agent-device-simulator-ax-v1.6.0`;Object.freeze([`verb`,`requestId`,`pid`,`generation`,`snapshotTree`,`automationMode`,`maxDepth`,`maxNodes`,`maxDurationMs`,`maxResponseBytes`,`nativeLevelsHint`]),Object.freeze([`protocolVersion`,`sourceVersion`,`requestId`,`generation`,`ok`,`pid`,`tree`,`truncated`,`automationEnabled`,`recovery`,`error_kind`,`error_code`,`error`]),Object.freeze([`XC_kAXXCAttributeElementType`,`XC_kAXXCAttributeElementBaseType`,`XC_kAXXCAttributeLabel`,`XC_kAXXCAttributeValue`,`XC_kAXXCAttributeIdentifier`,`XC_kAXXCAttributeFrame`,`XC_kAXXCAttributeAutomationType`,`XC_kAXXCAttributeTraits`,`XC_kAXXCAttributeChildren`]);const Ce=[`requests`,`rejected`,`continuations`,`acceptedLevels`];function A(e){let t=e.recovery;if(!j(t))throw x(`malformed-tree`,`recovery-invalid`);let n=Ce.map(e=>[e,t[e]]);if(n.some(([,e])=>!Number.isSafeInteger(e)||e<0))throw x(`malformed-tree`,`recovery-invalid`);return Object.freeze(Object.fromEntries(n))}function we(e,t){let n;try{n=y.from(JSON.stringify(e),`utf8`)}catch(e){throw x(`malformed-tree`,`request-not-json`,{},e)}let r=n.length+4;if(r>t.maxRequestBytes)throw x(`transport-failure`,`request-limit-exceeded`,{frameBytes:r,maxRequestBytes:t.maxRequestBytes});let i=y.alloc(4);return i.writeUInt32BE(n.length,0),y.concat([i,n])}var Te=class{header=y.alloc(4);headerBytes=0;chunks=[];payloadBytes=0;expectedBodyBytes;frame;maxFrameBytes;constructor(e){if(!Number.isSafeInteger(e)||e<=0)throw x(`malformed-tree`,`frame-limit-invalid`,{maxFrameBytes:e});this.maxFrameBytes=e}push(e){if(this.frame)return this.acceptTrailingChunk(e);let t=this.readHeader(e);if(t&&(this.appendPayload(e,t.offset,t.bodyBytes),this.payloadBytes===t.bodyBytes))return this.frame=y.concat(this.chunks,t.bodyBytes),this.frame}acceptTrailingChunk(e){if(e.length>0)throw x(`malformed-tree`,`multiple-frames`,{trailingBytes:e.length});return this.frame}readHeader(e){if(this.headerBytes===4)return{offset:0,bodyBytes:this.expectedBodyBytes};let t=Math.min(4-this.headerBytes,e.length);if(e.copy(this.header,this.headerBytes,0,t),this.headerBytes+=t,this.headerBytes<4)return;let n=this.header.readUInt32BE(0);if(n===0||n>this.maxFrameBytes)throw x(`malformed-tree`,`frame-limit-exceeded`,{bodyBytes:n,maxFrameBytes:this.maxFrameBytes});return this.expectedBodyBytes=n,{offset:t,bodyBytes:n}}appendPayload(e,t,n){let r=n-this.payloadBytes,i=e.length-t;if(i>r)throw x(`malformed-tree`,`multiple-frames`,{trailingBytes:i-r});i!==0&&(this.chunks.push(e.subarray(t)),this.payloadBytes+=i)}finish(){if(this.frame)return this.frame;throw x(`transport-failure`,`bridge-frame-incomplete`,{headerBytes:this.headerBytes,payloadBytes:this.payloadBytes,expectedBodyBytes:this.expectedBodyBytes})}};function Ee(e){let t;try{t=JSON.parse(e.toString(`utf8`))}catch(e){throw x(`malformed-tree`,`response-not-json`,{},e)}if(!j(t))throw x(`malformed-tree`,`response-not-object`);return t}function De(e){return Object.freeze({verb:`describe`,requestId:e.requestId,pid:e.pid,generation:e.generation,snapshotTree:!0,automationMode:!0,maxDepth:e.maxDepth,maxNodes:e.maxNodes,maxDurationMs:e.maxDurationMs,maxResponseBytes:e.maxResponseBytes,...e.nativeLevelsHint===void 0?{}:{nativeLevelsHint:e.nativeLevelsHint}})}function Oe(e,t){if(e.protocolVersion!==1)throw x(`transport-failure`,`protocol-version-mismatch`,{expected:1,observed:e.protocolVersion});if(e.sourceVersion!==`agent-device-simulator-ax-v1.6.0`)throw x(`transport-failure`,`source-version-mismatch`,{expected:k,observed:e.sourceVersion});if(e.requestId!==t)throw x(`transport-failure`,`request-id-mismatch`,{expected:t,observed:e.requestId})}function ke(e,t){if(typeof e.pid!=`number`||e.pid!==t.pid)throw x(`stale-target`,`bridge-pid-mismatch`,{expectedPid:t.pid,observedPid:e.pid});if(e.generation!==t.generation)throw x(`stale-target`,`bridge-generation-mismatch`,{expectedGeneration:t.generation,observedGeneration:e.generation})}function Ae(e){let t=e.error_kind,n=typeof e.error_code==`string`?e.error_code:`guest-error`,r=typeof e.error==`string`?e.error:void 0,i=r?{guestMessage:r.slice(0,1024)}:{};throw x(t===`unsupported`?`unsupported`:t===`malformed_tree`?`malformed-tree`:t===`application_not_responding`?`timeout`:t===`application_unavailable`?`transport-failure`:t===`bad_request`?`malformed-tree`:`transport-failure`,n,i)}function j(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}async function je(e){let t=new Te(e.limits.maxResponseBytes-4),n=w(e.deadline,`bridge-request-deadline`);return await new Promise((r,i)=>{let a=!1,o=!1,s=setTimeout(()=>{p(x(`timeout`,`bridge-request-deadline`,{dispatched:o})),e.socket.destroy()},n),c=()=>{p(x(`cancelled`,`abort-signal`,{dispatched:o})),e.socket.destroy()},l=n=>{try{if(!Buffer.isBuffer(n))throw x(`transport-failure`,`bridge-data-invalid`);let r=t.push(n);if(r){let t=Ee(r);if(Oe(t,e.requestId),ke(t,{pid:e.expectedPid,generation:e.expectedGeneration}),t.ok!==!0&&Ae(t),typeof t.truncated!=`boolean`)throw x(`malformed-tree`,`truncated-invalid`);f(t);return}}catch(t){p(t),e.socket.destroy()}},u=e=>p(S(e)),d=()=>{a||(e.process.isAlive()?p(x(`transport-failure`,`bridge-connection-closed`)):O(e.host,e.process).then(p))};e.process.wait.then(()=>{a||O(e.host,e.process).then(p)},e=>{a||p(S(e))});let f=e=>m(()=>r(e)),p=e=>m(()=>i(e)),m=t=>{a||(a=!0,clearTimeout(s),e.deadline.signal?.removeEventListener(`abort`,c),e.socket.off(`data`,l),e.socket.off(`error`,u),e.socket.off(`close`,d),t())};e.socket.on(`data`,l),e.socket.on(`error`,u),e.socket.on(`close`,d),e.deadline.signal?.addEventListener(`abort`,c,{once:!0});try{if(e.deadline.signal?.aborted)throw x(`cancelled`,`abort-signal`);o=!0,e.socket.write(e.frame)}catch(t){p(S(t)),e.socket.destroy()}})}var Me=class{sessions=new Map;requestQueues=new Map;ownerId=v();closed=!1;host;constructor(e){this.host=e}async request(e){if(this.closed)throw x(`unsupported`,`source-closed`);return await this.withSimulatorLock(e.target.udid,e.deadline,()=>this.requestInSimulator(e))}async requestInSimulator(e){if(this.closed)throw x(`unsupported`,`source-closed`);let t=e.deadline;w(t,`bridge-request-deadline`);let n=this.sessions.get(e.target.udid),r=await this.ensureSession(e,t);try{let n=await this.readTargetStartTime(e.target,t),i=await this.exchange(r,e,t);return await this.assertTargetStillCurrent(e.target,n,t),i}catch(e){throw await this.handleRequestFailure(e,r,n)}}async handleRequestFailure(e,t,n){let r=S(e);return Pe(r,t,n)?await this.removeSession(t,!0):r.failureKind===`process-crash`?await this.removeSession(t,!1):r.failureKind===`transport-failure`&&(t.socket?.destroy(),t.socket=void 0),r}async withSimulatorLock(e,t,n){let r=this.requestQueues.get(e)??Promise.resolve(),i,a=new Promise(e=>{i=e}),o=r.then(()=>a);this.requestQueues.set(e,o);try{return await Ne(r,t),await n()}finally{i(),this.requestQueues.get(e)===o&&this.requestQueues.delete(e)}}async close(){if(this.closed)return;this.closed=!0;let e=[...this.sessions.values()];this.sessions.clear(),await Promise.all(e.map(async e=>await this.dispose(e,!0)))}async ensureSession(e,t){let n=e.target.udid,r=this.sessions.get(n);if(r&&r.bridgePath===e.bridge.path&&r.process.isAlive())return(!r.socket||r.socket.destroyed)&&(r.socket=await this.connectUntilReady(r,t)),r;r&&await this.removeSession(r,!0);let i=xe(this.host,e.target.udid,this.ownerId);await this.host.ensureDirectory(g.dirname(i)),await this.host.remove(i);let a=this.host.start(e.target.udid,e.bridge.path,i,{signal:t.signal}),o={udid:e.target.udid,bridgePath:e.bridge.path,socketPath:i,process:a};this.sessions.set(n,o);try{return o.socket=await this.connectUntilReady(o,t),o}catch(e){throw await this.removeSession(o,!0),S(e)}}async connectUntilReady(e,t){let n;for(;;){let r=w(t,`bridge-connect-deadline`);if(!e.process.isAlive())throw await O(this.host,e.process);try{return await this.host.connect(e.socketPath,{signal:t.signal,timeoutMs:Math.min(250,r)})}catch(e){if(n=e,e instanceof b&&e.failureKind===`cancelled`)throw e;let r=Math.min(20,w(t,`bridge-connect-deadline`));try{await T(t,r,`bridge-connect-deadline`)}catch(e){throw S(e)}}if(n instanceof b&&n.failureKind===`timeout`)throw n}}async exchange(e,t,n){(!e.socket||e.socket.destroyed)&&(e.socket=await this.connectUntilReady(e,n));let r=v(),i=we(De({requestId:r,pid:t.target.pid,generation:t.target.generation,maxDepth:Math.min(t.limits.maxTraversalDepth,t.maxDepth),maxNodes:t.limits.maxNodes,maxDurationMs:w(n,`bridge-request-deadline`),maxResponseBytes:t.limits.maxResponseBytes,...t.nativeLevelsHint===void 0?{}:{nativeLevelsHint:t.nativeLevelsHint}}),t.limits);return await je({process:e.process,socket:e.socket,frame:i,requestId:r,deadline:n,limits:t.limits,expectedPid:t.target.pid,expectedGeneration:t.target.generation,host:this.host})}async readTargetStartTime(e,t){let n=await this.host.readTargetProcessStartTime(e.pid,{signal:t.signal,timeoutMs:w(t,`target-identity-deadline`)});if(!n)throw x(`stale-target`,`target-process-unavailable`,{pid:e.pid,generation:e.generation});if(e.processStartTime!==void 0&&e.processStartTime!==n)throw x(`stale-target`,`target-process-changed`,{pid:e.pid,generation:e.generation,expectedStartTime:e.processStartTime,observedStartTime:n});return n}async assertTargetStillCurrent(e,t,n){let r=await this.host.readTargetProcessStartTime(e.pid,{signal:n.signal,timeoutMs:w(n,`target-identity-deadline`)});if(r!==t)throw x(`stale-target`,`target-process-changed`,{pid:e.pid,generation:e.generation,expectedStartTime:t,observedStartTime:r})}async removeSession(e,t){this.sessions.get(e.udid)===e&&this.sessions.delete(e.udid),await this.dispose(e,t)}async dispose(e,t){e.socket?.destroy(),e.socket=void 0,t&&e.process.isAlive()&&(e.process.signal(`SIGTERM`),await M(e.process,500),e.process.isAlive()&&(e.process.signal(`SIGKILL`),await M(e.process,500))),await this.host.remove(e.socketPath)}};async function Ne(e,t){let n=w(t,`bridge-request-deadline`);await Promise.race([e,T(t,n,`bridge-request-deadline`).then(()=>{throw x(`timeout`,`bridge-request-deadline`)})])}function Pe(e,t,n){return(e.failureKind===`cancelled`||e.failureKind===`timeout`)&&(e.details?.dispatched===!0||n!==t)}async function M(e,t){await Promise.race([e.wait.catch(()=>void 0),new Promise(e=>setTimeout(e,t))])}const N=16777216,P=12e4,F=1e4,Fe=Object.freeze({maxRequestBytes:65536,maxResponseBytes:4194304,maxNodes:5e3,maxTraversalDepth:64,maxDurationMs:5e3});function I(t){let n={...Fe,...t??{}};for(let[t,r]of Object.entries(n))if(!Number.isSafeInteger(r)||r<=0)throw new e(`INVALID_ARGS`,`Snapshot source limit ${t} must be a positive integer`,{name:t,value:r});if(n.maxRequestBytes>n.maxResponseBytes)throw new e(`INVALID_ARGS`,`Snapshot source request bytes cannot exceed response bytes`,{maxRequestBytes:n.maxRequestBytes,maxResponseBytes:n.maxResponseBytes});if(n.maxRequestBytes>N||n.maxResponseBytes>N)throw new e(`INVALID_ARGS`,`Snapshot source frame limits exceed the bridge bound`,{maxRequestBytes:n.maxRequestBytes,maxResponseBytes:n.maxResponseBytes,maximumFrameBytes:N});if(n.maxNodes>F||n.maxTraversalDepth>128)throw new e(`INVALID_ARGS`,`Snapshot source tree limits exceed the bridge bound`,{maxNodes:n.maxNodes,maxTraversalDepth:n.maxTraversalDepth,maximumNodes:F,maximumDepth:128});if(n.maxDurationMs>P)throw new e(`INVALID_ARGS`,`Snapshot source duration exceeds the bridge bound`,{maxDurationMs:n.maxDurationMs,maximumDurationMs:P});if(n.maxRequestBytes<=4||n.maxResponseBytes<=4)throw new e(`INVALID_ARGS`,`Snapshot source frame limits must leave room for a body`,{maxRequestBytes:n.maxRequestBytes,maxResponseBytes:n.maxResponseBytes});return Object.freeze(n)}const L=[`SnapshotBridge.m`,`SnapshotBridgeRuntime.m`,`SnapshotBridgeRuntime.h`,`SnapshotBridgeCapture.h`,`SnapshotBridgeCapture.m`],Ie=[`SnapshotBridge.m`,`SnapshotBridgeRuntime.m`,`SnapshotBridgeCapture.m`];async function Le(e,t,n){let r=_(`sha256`);for(let i of L){let a=g.join(t,i);if(w(n,`native-source-fingerprint-deadline`),!e.exists(a))throw x(`unsupported`,`native-source-missing`,{filePath:a});r.update(i),r.update(`\0`),r.update(await e.readBinary(a)),r.update(`\0`)}return r.digest(`hex`)}async function Re(e,t,n){let r=await R(e,`xcodebuild`,[`-version`],n),i=await R(e,`sw_vers`,[`-productVersion`],n),a=await R(e,`sw_vers`,[`-buildVersion`],n),o=await R(e,`uname`,[`-m`],n),s=await R(e,`xcrun`,[`--sdk`,`iphonesimulator`,`--show-sdk-version`],n),c=t.trim();if(!c)throw x(`unsupported`,`simulator-runtime-missing`);if(o!==`arm64`&&o!==`x86_64`)throw x(`unsupported`,`simulator-architecture-unsupported`,{architecture:o});return{xcode:r,macosProductVersion:i,macosBuild:a,architecture:o,simulatorSdk:s,simulatorRuntime:c}}async function R(e,t,n,r){let i=await ze(e,t,n,r);if(i.exitCode!==0)throw x(`unsupported`,`toolchain-probe-failed`,{command:t,exitCode:i.exitCode,stderr:i.stderr.slice(0,1024)});let a=(i.stdout||i.stderr).trim();if(!a)throw x(`unsupported`,`toolchain-probe-empty`,{command:t});return a}async function ze(e,t,n,r){try{return await z(e,t,n,r)}catch(i){if(!d(i))throw i;if(r.signal?.aborted)throw x(`cancelled`,`abort-signal`);if(r.clock.remainingMs(r.now())<=0)throw i;return await z(e,t,n,r)}}function z(e,t,n,r){return e.run(t,n,{allowFailure:!0,signal:r.signal,timeoutMs:Math.min(h,w(r,`toolchain-probe-deadline`))})}const B=`snapshot-bridge`,V=`manifest.json`,H=12e4;async function Be(e){let t=e.deadline,n=e.sourceRoot??Ve(e.host),r=await Le(e.host,n,t),i=await Re(e.host,e.runtime,t),a=Ue({schemaVersion:1,protocolVersion:1,sourceVersion:k,sourceHash:r,toolchain:i}),o=e.cacheRoot??g.join(e.host.homeDirectory(),`.agent-device`,`snapshot-source`),s=g.join(o,a);return await f({acquire:()=>e.host.acquireLock(g.join(o,`${a}.lock`),{deadline:t}),task:async()=>{let c=await He(e.host,s,{sourceHash:r,cacheKey:a,toolchain:i},t);if(c)return c;w(t,`native-build-deadline`),e.host.exists(s)&&await e.host.remove(s),w(t,`native-build-deadline`),await e.host.ensureDirectory(o);let l=g.join(o,`.${a}.${e.host.processId()}.tmp`);w(t,`native-build-deadline`),await e.host.remove(l);try{w(t,`native-build-deadline`),await e.host.ensureDirectory(l);let o=g.join(l,B),c=await e.host.run(`xcrun`,[`--sdk`,`iphonesimulator`,`clang`,`-arch`,i.architecture,`-mios-simulator-version-min=15.0`,`-fobjc-arc`,`-Werror`,`-Wall`,`-Wextra`,`-framework`,`Foundation`,`-framework`,`CoreGraphics`,...Ie.map(e=>g.join(n,e)),`-o`,o],{signal:t.signal,timeoutMs:Math.min(H,w(t,`native-build-deadline`)),allowFailure:!0});if(c.exitCode!==0||!e.host.exists(o))throw x(`unsupported`,`native-build-failed`,{exitCode:c.exitCode,stderr:c.stderr.slice(0,4096)});w(t,`native-build-deadline`),await e.host.chmod(o,493);let u=await U(e.host,o,t),d={schemaVersion:1,protocolVersion:1,sourceVersion:k,sourceHash:r,cacheKey:a,toolchain:i,binarySha256:u};return await e.host.writeText(g.join(l,V),`${JSON.stringify(d,null,2)}\n`),w(t,`native-build-deadline`),await e.host.rename(l,s),{path:g.join(s,B),sourceHash:r,cacheKey:a,protocolVersion:1,sourceVersion:k}}catch(t){throw await e.host.remove(l),t}}})}function Ve(e){let t=e.projectRoot(),n=g.join(t,`apple`,`snapshot-bridge`);if(L.every(t=>e.exists(g.join(n,t))))return n;let r=g.join(t,`dist`,`apple`,`snapshot-bridge`);if(L.every(t=>e.exists(g.join(r,t))))return r;throw x(`unsupported`,`native-source-missing`,{projectRoot:t})}async function He(e,t,n,r){let i=g.join(t,B);if(!(!e.exists(i)||!e.exists(g.join(t,V))))try{let a=JSON.parse(await e.readText(g.join(t,V)));return a.schemaVersion!==1||a.protocolVersion!==1||a.sourceVersion!==`agent-device-simulator-ax-v1.6.0`||a.sourceHash!==n.sourceHash||a.cacheKey!==n.cacheKey||JSON.stringify(a.toolchain)!==JSON.stringify(n.toolchain)||typeof a.binarySha256!=`string`||await U(e,i,r)!==a.binarySha256?void 0:{path:i,sourceHash:n.sourceHash,cacheKey:n.cacheKey,protocolVersion:1,sourceVersion:k}}catch(e){if(e instanceof b&&(e.failureKind===`cancelled`||e.failureKind===`timeout`))throw e;return}}async function U(e,t,n){return w(n,`native-cache-hash-deadline`),_(`sha256`).update(await e.readBinary(t)).digest(`hex`)}function Ue(e){return _(`sha256`).update(JSON.stringify(e)).digest(`hex`).slice(0,32)}const We=h+H;function Ge(e){let t=e.now??Date.now,n=new Map,r=ue({waitMs:2e3,waitGrant:`first-caller`,retryAfterMs:6e4,now:t}),i=async(r,i)=>{let a=C(We,i,t);try{let t=await e.host.withDiagnosticTimer(`ios.snapshot-source.prepare`,async()=>await Be({host:e.host,runtime:r,limits:e.limits,deadline:a,sourceRoot:e.sourceRoot,cacheRoot:e.cacheRoot}),{producer:e.producer});return n.set(r,t),t}catch(e){throw S(e)}};return{readyBinary:async(e,t,a)=>n.get(e)||await r.value(e,{start:t=>i(e,t),wait:(e,n)=>T(t,e,a,n),pending:()=>x(`preparing`,`bridge-preparation-pending`)}),close:()=>{n.clear(),r.close()}}}function Ke(e,t){return!n(e)||!n(t)||Math.abs(t.width-t.height)<=1?!1:Math.abs(e.width-t.height)<=1&&Math.abs(e.height-t.width)<=1}const W=Object.freeze({elementType:`XC_kAXXCAttributeElementType`,elementBaseType:`XC_kAXXCAttributeElementBaseType`,label:`XC_kAXXCAttributeLabel`,value:`XC_kAXXCAttributeValue`,identifier:`XC_kAXXCAttributeIdentifier`,frame:`XC_kAXXCAttributeFrame`,automationType:`XC_kAXXCAttributeAutomationType`,traits:`XC_kAXXCAttributeTraits`,children:`XC_kAXXCAttributeChildren`}),G=`Other.Other.Application.Group.Window.Sheet.Drawer.Alert.Dialog.Button.RadioButton.RadioGroup.CheckBox.DisclosureTriangle.PopUpButton.ComboBox.MenuButton.ToolbarButton.Popover.Keyboard.Key.NavigationBar.TabBar.TabGroup.Toolbar.StatusBar.Table.TableRow.TableColumn.Outline.OutlineRow.Browser.CollectionView.Slider.PageIndicator.ProgressIndicator.ActivityIndicator.SegmentedControl.Picker.PickerWheel.Switch.Toggle.Link.Image.Icon.SearchField.ScrollView.ScrollBar.StaticText.TextField.SecureTextField.DatePicker.TextView.Menu.MenuItem.MenuBar.MenuBarItem.Map.WebView.IncrementArrow.DecrementArrow.Timeline.RatingIndicator.ValueIndicator.SplitGroup.Splitter.RelevanceIndicator.ColorWell.HelpTag.Matte.DockItem.Ruler.RulerMarker.Grid.LevelIndicator.Cell.LayoutArea.LayoutItem.Handle.Stepper.Tab.TouchBar.StatusItem`.split(`.`),K={UIApplication:`Application`,UIWindow:`Window`},qe=new Set(Object.values(W)),Je=1n<<8n,Ye={x:0,y:0,width:0,height:0};function Xe(e,t,n){let r=Array.isArray(e)?e:[e];if(r.length===0||r.some(e=>!j(e)))throw x(`malformed-tree`,`guest-tree-root-invalid`);let i=[],a=[],o=0;for(let e of r)c(e,void 0,0,!1);if(i.length>n.maxNodes)throw x(`malformed-tree`,`node-limit-exceeded`,{nodeCount:i.length,maxNodes:n.maxNodes});if(o>n.maxTraversalDepth)throw x(`malformed-tree`,`traversal-depth-exceeded`,{maxTraversalDepth:o,maxAllowedDepth:n.maxTraversalDepth});if(typeof t.truncated!=`boolean`)throw x(`malformed-tree`,`truncated-invalid`);let s=et(i.filter(Y)[0]);return{nodes:i,maxTraversalDepth:o,viewport:s,opaqueRemoteElements:a.filter(e=>$e(e,s)).length,unresolvedCoordinateSpaceWindows:tt(i,s)};function c(e,t,r,s){if(i.length>=n.maxNodes)throw x(`malformed-tree`,`node-limit-exceeded`,{maxNodes:n.maxNodes});for(let t of Object.keys(e))if(!qe.has(t))throw x(`malformed-tree`,`node-contains-unknown-field`,{key:t});let l=e[W.children];if(!Array.isArray(l))throw x(`malformed-tree`,`children-invalid`);let u=i.length,d=Ze(e,u,t,r);i.push(d),o=Math.max(o,r),Qe(d,l.length,s)&&a.push(d.rect);let f=s||d.type===`WebView`;for(let e of l){if(!j(e))throw x(`malformed-tree`,`child-invalid`);c(e,u,r+1,f)}}}function Ze(e,t,n,r){let i=X(e[W.elementType]),a=X(e[W.elementBaseType]),o=it(e[W.automationType]),s=J(e[W.frame]),c=rt(e[W.traits]);return{index:t,...n===void 0?{}:{parentIndex:n},...q(i,o)?{type:q(i,o)}:{},...i?{role:i}:{},...a&&a!==i?{subrole:a}:{},...X(e[W.label])?{label:X(e[W.label])}:{},...Z(e[W.value])?{value:Z(e[W.value])}:{},...X(e[W.identifier])?{identifier:X(e[W.identifier])}:{},...s?{rect:s}:{},...c===void 0?{}:{enabled:c},depth:r}}function q(e,t){if(e!==void 0&&K[e])return K[e];if(e!==void 0&&G.includes(e))return e;if(t!==void 0)return G[t]??`Other`}function Qe(e,t,n){return n&&e.role===`AXRemoteElement`&&t===0}function $e(e,t){return e===void 0?!0:n(e)?t.kind!==`reported`||r(e,t.rect):!1}function J(e){if(e===void 0)return;if(!j(e))throw x(`malformed-tree`,`frame-invalid`);let t=[`X`,`Y`,`Width`,`Height`].map(t=>e[t]);if(!t.every(e=>typeof e==`number`&&Number.isFinite(e)))throw x(`malformed-tree`,`frame-invalid`);let[n,r,i,a]=t;if(i<0||a<0)throw x(`malformed-tree`,`frame-invalid`);return{x:n,y:r,width:i,height:a}}function et(e){return!e||!Y(e)?{kind:`missing`,reason:`not-provided`}:n(e.rect)?{kind:`reported`,rect:e.rect}:{kind:`missing`,reason:e.rect?`invalid`:`not-provided`}}function Y(e){return e.type===`Application`||e.type===`Window`}function tt(e,t){return t.kind===`reported`?e.filter(n=>nt(n,e)&&Ke(n.rect??Ye,t.rect)).length:0}function nt(e,t){return Y(e)?!0:e.parentIndex!==void 0&&Y(t[e.parentIndex]??e)}function X(e){return typeof e==`string`&&e.length>0?e:void 0}function Z(e){if(typeof e==`string`)return e.length>0?e:void 0;if(typeof e==`number`||typeof e==`boolean`)return String(e);if(e!=null)throw x(`malformed-tree`,`scalar-invalid`)}function rt(e){if(e!=null){if(typeof e!=`string`||!/^\d{1,20}$/.test(e))throw x(`malformed-tree`,`traits-invalid`);return(BigInt(e)&Je)===0n}}function it(e){if(e!=null){if(!Number.isSafeInteger(e))throw x(`malformed-tree`,`automation-type-invalid`);return e}}const Q=`simulator-ax-bridge`;function at(e={}){let t=e.host??ge(),n=new Me(t),r=new he,i=Ge({host:t,limits:I(e.limits),producer:Q,sourceRoot:e.sourceRoot,cacheRoot:e.cacheRoot}),a=!1;return{acquire:async o=>{try{if(a)throw x(`unsupported`,`source-closed`);ot(o);let s=I({...e.limits,...o.limits}),c=C(s.maxDurationMs,o.signal),l=ct(o.hint,s.maxTraversalDepth),u=l+1,d=o.hint.rawTraversalDepth!==null;return await t.withDiagnosticTimer(`ios.snapshot-source.acquire`,async()=>{let e=await i.readyBinary(o.target.runtime,c,`bridge-preparation-deadline`),a=r.consume(o.target,u,d),f=await n.request({target:o.target,bridge:e,limits:s,maxDepth:l,nativeLevelsHint:a.nativeLevels,deadline:c});w(c,`snapshot-decode-deadline`);let p=lt(o.hint,o.target,f,s);return st(t,r,o.target,u,d,a,f),{stage:`acquired`,acquisition:p}},{producer:Q})}catch(e){let t=S(e);return{stage:`failed`,failure:{kind:t.failureKind,code:t.failureCode,...t.details?{details:t.details}:{}}}}},close:async()=>{a||(a=!0,i.close(),await n.close())}}}function ot(t){if(!t.target.udid.trim()||!t.target.runtime.trim()||!t.target.generation.trim()||!Number.isSafeInteger(t.target.pid)||t.target.pid<=0)throw new e(`INVALID_ARGS`,`Simulator snapshot source target identity is incomplete`);let n=t.hint;if(n.projection!==`raw`&&n.projection!==`regular`||![`full`,`surface-observation`].includes(n.acquisitionIntent)||typeof n.interactiveOnly!=`boolean`||typeof n.customActions!=`boolean`||!$(n.rawTraversalDepth)||!$(n.regularPresentedDepth))throw new e(`INVALID_ARGS`,`Simulator snapshot source capture hint is invalid`)}function st(e,t,n,r,i,a,o){let s=A(o),c=o.truncated===!0,l=t.learn(n,r,i,s);e.emitDiagnostic({level:`debug`,phase:`ios_snapshot_source_recovery`,data:{producer:Q,...n.targetId?{targetId:n.targetId}:{},generation:n.generation,requestedLevels:r,hint:a.reason,...a.nativeLevels===void 0?{}:{hintedLevels:a.nativeLevels},...s,truncated:c,learning:l}})}function ct(t,n){let r=t.rawTraversalDepth??n;if(r>n)throw new e(`INVALID_ARGS`,`Simulator snapshot source depth exceeds its bound`,{requested:r,maximum:n});return r}function $(e){return e===null||Number.isSafeInteger(e)&&e>=0}function lt(e,t,n,r){if(n.automationEnabled!==!0)throw x(`unsupported`,`automation-mode-unavailable`);let i=n.tree,a=n.truncated;if(typeof a!=`boolean`)throw x(`malformed-tree`,`truncated-invalid`);let o=Xe(i,{truncated:a},r),s=n.generation;if(typeof s!=`string`||!s)throw x(`malformed-tree`,`generation-invalid`);if(o.opaqueRemoteElements>0)throw x(`unsupported`,`remote-content-boundary`,{remoteElements:o.opaqueRemoteElements});if(o.unresolvedCoordinateSpaceWindows>0)throw x(`unsupported`,`window-coordinate-space-unresolved`,{windows:o.unresolvedCoordinateSpaceWindows});let c=Object.freeze(o.nodes.map(e=>Object.freeze({...e,pid:t.pid}))),l=ut(e,a,o.viewport),u=Object.freeze({...t.targetId?{targetId:t.targetId}:{},generation:s}),d={producer:Q,nodes:c,truncated:a,viewport:o.viewport,lineage:u,residue:l};return e.acquisitionIntent===`full`?{...d,intent:`full`,hint:{...e,acquisitionIntent:`full`}}:{...d,intent:`surface-observation`,hint:{...e,acquisitionIntent:`surface-observation`}}}function ut(e,t,n){return Object.freeze([{kind:`unavailable-fact`,fact:`hittability`},...e.interactiveOnly?[{kind:`unavailable-fact`,fact:`interactive-query`}]:[],...t?[{kind:`truncated`}]:[],...n.kind===`missing`?[{kind:`missing-viewport`,reason:n.reason}]:[]])}export{at as createSimulatorSnapshotSource};
|
|
1
|
+
import{D as e,F as t}from"./sdk-contracts.js";import{Gr as n,Ur as r,Wr as i}from"./sdk-batch.js";import{c as a,r as o}from"./diagnostics.js";import{f as s,x as c}from"./owner-identity.js";import{c as l,l as u,m as d,r as f}from"./exec.js";import{n as p,t as m}from"./file.js";import"./diagnostics2.js";import"./command.js";import{n as ee}from"./retry.js";import{r as te}from"./version.js";import"./process.js";import{C as ne,D as re,c as ie,f as ae,h as oe,n as se,o as ce,w as le,y as ue}from"./host-file.js";import{t as h}from"./apple-runner-platform.js";import{t as de}from"./simctl.js";import{n as fe,r as g,t as pe}from"./snapshot-process.js";import _ from"node:path";import{createHash as v,randomUUID as y}from"node:crypto";import me from"node:net";import{Buffer as b}from"node:buffer";const he={unsupported:`UNSUPPORTED_OPERATION`,"malformed-tree":`COMMAND_FAILED`,"stale-target":`COMMAND_FAILED`,timeout:`COMMAND_FAILED`,cancelled:`COMMAND_FAILED`,"process-crash":`COMMAND_FAILED`,"transport-failure":`COMMAND_FAILED`,preparing:`COMMAND_FAILED`};var x=class extends e{failureKind;failureCode;constructor(e,t,n=`iOS Simulator snapshot source ${e}: ${t}`,r={},i){super(he[e],n,{...r,bridgeFailure:e,bridgeFailureCode:t,...e===`cancelled`?{reason:`request_canceled`}:{}},i),this.name=`SnapshotSourceError`,this.failureKind=e,this.failureCode=t}};function S(e,t,n={},r){return new x(e,t,void 0,n,r)}function C(n){return n instanceof x?n:t(n)?S(`cancelled`,`abort-signal`,{},n):n instanceof e&&typeof n.details?.timeoutMs==`number`?S(`timeout`,`host-operation-timeout`,{timeoutMs:n.details.timeoutMs},n):S(`transport-failure`,`unexpected-host-error`,{error:n instanceof Error?n.message:String(n)},n)}function w(e,t,n=Date.now){if(t?.aborted)throw S(`cancelled`,`abort-signal`);return{clock:ee.fromTimeoutMs(e,n()),now:n,signal:t}}function T(e,t){if(e.signal?.aborted)throw S(`cancelled`,`abort-signal`);let n=e.clock.remainingMs(e.now());if(n<=0)throw S(`timeout`,t);return Math.max(1,Math.floor(n))}async function E(e,t,n,r){let i=Math.min(t,T(e,n));await g({waitMs:i,signal:e.signal,stop:r,cancelled:()=>S(`cancelled`,`abort-signal`)})}var ge=class{entries=new Map;probeBackAfterUses;constructor(e=8){this.probeBackAfterUses=e}consume(e,t,n){if(n)return{nativeLevels:void 0,reason:`explicit-depth`};let r=this.currentEntry(e);return r===`unidentified`?{nativeLevels:void 0,reason:`unidentified-target`}:!r||r.nativeLevels>=t?{nativeLevels:void 0,reason:`no-hint`}:r.remainingUses<=0?{nativeLevels:void 0,reason:`probe-back`}:(--r.remainingUses,{nativeLevels:r.nativeLevels,reason:`hinted`})}learn(e,t,n,r){return n||!e.targetId?`ignored`:r.rejected>0&&r.acceptedLevels<t?(this.remember(e.targetId,{generation:e.generation,nativeLevels:r.acceptedLevels,remainingUses:this.probeBackAfterUses}),`learned`):r.rejected===0&&r.acceptedLevels>=t?this.entries.delete(e.targetId)?`forgotten`:`ignored`:this.currentEntry(e)?`kept`:`ignored`}currentEntry(e){if(!e.targetId)return`unidentified`;let t=this.entries.get(e.targetId);if(t){if(t.generation!==e.generation){this.entries.delete(e.targetId);return}return t}}remember(e,t){if(this.entries.delete(e),this.entries.size>=32){let e=this.entries.keys().next().value;e!==void 0&&this.entries.delete(e)}this.entries.set(e,t)}};const D=65536;function _e(){return{projectRoot:te,homeDirectory:ae,run:async(e,t,n)=>await l(e,t,n),start:ve,connect:ye,readText:ue,readBinary:oe,writeText:re,ensureDirectory:ce,chmod:se,exists:ie,rename:le,remove:ne,acquireLock:be,emitDiagnostic:o,withDiagnosticTimer:a,processId:s,readTargetProcessStartTime:pe}}function ve(e,t,n,r={}){if(r.signal?.aborted)throw S(`cancelled`,`abort-signal`);let i=u(`xcrun`,de([`spawn`,e.udid,t,`serve`,n,`--idle-timeout`,`60`,`--exit-on-disconnect`,`false`],{simulatorSetPath:e.simulatorSetPath}),{allowFailure:!0,captureOutput:!1,detached:!0}),a=i.child.pid??0;if(a<=0)throw S(`transport-failure`,`bridge-process-pid-missing`);let o=``;return i.child.stderr?.setEncoding(`utf8`),i.child.stderr?.on(`data`,e=>{o=xe(o,String(e))}),{pid:a,wait:i.wait,isAlive:()=>i.child.exitCode===null&&i.child.signalCode===null,signal:e=>{d(a,e)||i.child.kill(e)},readLog:()=>o}}async function ye(e,t){if(t.signal?.aborted)throw S(`cancelled`,`abort-signal`);let n=Math.max(1,Math.floor(t.timeoutMs));return await new Promise((r,i)=>{let a=me.createConnection({path:e}),o=!1,s=!1,c=setTimeout(()=>{p(S(`timeout`,`bridge-connect-timeout`)),a.destroy()},n),l=()=>{p(S(`cancelled`,`abort-signal`)),a.destroy()},u=()=>{o=!0,clearTimeout(c),t.signal?.removeEventListener(`abort`,l),a.off(`error`,d),a.off(`close`,f),a.setTimeout(0),r(a)},d=e=>{p(e),a.destroy()},f=()=>{o||p(S(`transport-failure`,`bridge-closed-before-connect`))},p=e=>{s||o||(s=!0,clearTimeout(c),t.signal?.removeEventListener(`abort`,l),a.off(`connect`,u),a.off(`error`,d),a.off(`close`,f),i(e))};a.once(`connect`,u),a.once(`error`,d),a.once(`close`,f),t.signal?.addEventListener(`abort`,l,{once:!0}),t.signal?.aborted&&l()})}async function be(e,t){let n=s(),r=t.deadline,i=m({lockDirPath:e,owner:{pid:n,startTime:c(n),acquiredAtMs:Date.now()},timeoutMs:T(r,`cache-lock-deadline`),pollMs:100,ownerGraceMs:5e3,description:`iOS Simulator snapshot bridge cache`}),a=r.signal;if(!a)return await i;let o=!1,l,u=new Promise((e,t)=>{l=()=>{o=!0,t(S(`cancelled`,`abort-signal`))},a.addEventListener(`abort`,l,{once:!0}),a.aborted&&l()});try{return await Promise.race([i,u])}catch(e){throw o&&i.then(e=>e().catch(()=>void 0),()=>void 0),r.clock.isExpired()&&!(e instanceof x&&e.failureKind===`cancelled`)?S(`timeout`,`cache-lock-deadline`):e}finally{a.removeEventListener(`abort`,l)}}function xe(e,t){let n=e+t;return n.length<=D?n:n.slice(n.length-D)}function Se(e,t,n){let r=v(`sha256`).update(t).digest(`hex`).slice(0,12),i=v(`sha256`).update(n).digest(`hex`).slice(0,12);return _.join(`/tmp`,`agent-device-ax-${r}-${e.processId()}-${i}`,`snapshot.sock`)}const O=new WeakSet;async function k(e,t){let n;try{n=(await t.wait).exitCode}catch{n=void 0}return O.has(t)||(O.add(t),e.emitDiagnostic({level:`error`,phase:`ios.snapshot-source.bridge-process-exit`,data:{pid:t.pid,...n===void 0?{}:{exitCode:n},stderr:A(t.readLog())}})),S(`process-crash`,`bridge-exited`,{pid:t.pid,...n===void 0?{}:{exitCode:n}})}function A(e){let t=b.from(e);return t.length<=65536?e:t.subarray(-65536).toString(`utf8`)}const j=`agent-device-simulator-ax-v1.7.0`;Object.freeze([`verb`,`requestId`,`pid`,`generation`,`snapshotTree`,`automationMode`,`maxDepth`,`maxNodes`,`maxDurationMs`,`maxResponseBytes`,`nativeLevelsHint`]),Object.freeze([`protocolVersion`,`sourceVersion`,`requestId`,`generation`,`ok`,`pid`,`tree`,`truncated`,`automationEnabled`,`recovery`,`error_kind`,`error_code`,`error`]),Object.freeze([`XC_kAXXCAttributeElementType`,`XC_kAXXCAttributeElementBaseType`,`XC_kAXXCAttributeLabel`,`XC_kAXXCAttributeValue`,`XC_kAXXCAttributeIdentifier`,`XC_kAXXCAttributeFrame`,`XC_kAXXCAttributeAutomationType`,`XC_kAXXCAttributeTraits`,`XC_kAXXCAttributeIsUserInteractionEnabled`,`XC_kAXXCAttributeChildren`]);const Ce=[`requests`,`rejected`,`continuations`,`acceptedLevels`];function we(e){let t=e.recovery;if(!M(t))throw S(`malformed-tree`,`recovery-invalid`);let n=Ce.map(e=>[e,t[e]]);if(n.some(([,e])=>!Number.isSafeInteger(e)||e<0))throw S(`malformed-tree`,`recovery-invalid`);return Object.freeze(Object.fromEntries(n))}function Te(e,t){let n;try{n=b.from(JSON.stringify(e),`utf8`)}catch(e){throw S(`malformed-tree`,`request-not-json`,{},e)}let r=n.length+4;if(r>t.maxRequestBytes)throw S(`transport-failure`,`request-limit-exceeded`,{frameBytes:r,maxRequestBytes:t.maxRequestBytes});let i=b.alloc(4);return i.writeUInt32BE(n.length,0),b.concat([i,n])}var Ee=class{header=b.alloc(4);headerBytes=0;chunks=[];payloadBytes=0;expectedBodyBytes;frame;maxFrameBytes;constructor(e){if(!Number.isSafeInteger(e)||e<=0)throw S(`malformed-tree`,`frame-limit-invalid`,{maxFrameBytes:e});this.maxFrameBytes=e}push(e){if(this.frame)return this.acceptTrailingChunk(e);let t=this.readHeader(e);if(t&&(this.appendPayload(e,t.offset,t.bodyBytes),this.payloadBytes===t.bodyBytes))return this.frame=b.concat(this.chunks,t.bodyBytes),this.frame}acceptTrailingChunk(e){if(e.length>0)throw S(`malformed-tree`,`multiple-frames`,{trailingBytes:e.length});return this.frame}readHeader(e){if(this.headerBytes===4)return{offset:0,bodyBytes:this.expectedBodyBytes};let t=Math.min(4-this.headerBytes,e.length);if(e.copy(this.header,this.headerBytes,0,t),this.headerBytes+=t,this.headerBytes<4)return;let n=this.header.readUInt32BE(0);if(n===0||n>this.maxFrameBytes)throw S(`malformed-tree`,`frame-limit-exceeded`,{bodyBytes:n,maxFrameBytes:this.maxFrameBytes});return this.expectedBodyBytes=n,{offset:t,bodyBytes:n}}appendPayload(e,t,n){let r=n-this.payloadBytes,i=e.length-t;if(i>r)throw S(`malformed-tree`,`multiple-frames`,{trailingBytes:i-r});i!==0&&(this.chunks.push(e.subarray(t)),this.payloadBytes+=i)}finish(){if(this.frame)return this.frame;throw S(`transport-failure`,`bridge-frame-incomplete`,{headerBytes:this.headerBytes,payloadBytes:this.payloadBytes,expectedBodyBytes:this.expectedBodyBytes})}};function De(e){let t;try{t=JSON.parse(e.toString(`utf8`))}catch(e){throw S(`malformed-tree`,`response-not-json`,{},e)}if(!M(t))throw S(`malformed-tree`,`response-not-object`);return t}function Oe(e){return Object.freeze({verb:`describe`,requestId:e.requestId,pid:e.pid,generation:e.generation,snapshotTree:!0,automationMode:!0,maxDepth:e.maxDepth,maxNodes:e.maxNodes,maxDurationMs:e.maxDurationMs,maxResponseBytes:e.maxResponseBytes,...e.nativeLevelsHint===void 0?{}:{nativeLevelsHint:e.nativeLevelsHint}})}function ke(e,t){if(e.protocolVersion!==1)throw S(`transport-failure`,`protocol-version-mismatch`,{expected:1,observed:e.protocolVersion});if(e.sourceVersion!==`agent-device-simulator-ax-v1.7.0`)throw S(`transport-failure`,`source-version-mismatch`,{expected:j,observed:e.sourceVersion});if(e.requestId!==t)throw S(`transport-failure`,`request-id-mismatch`,{expected:t,observed:e.requestId})}function Ae(e,t){if(typeof e.pid!=`number`||e.pid!==t.pid)throw S(`stale-target`,`bridge-pid-mismatch`,{expectedPid:t.pid,observedPid:e.pid});if(e.generation!==t.generation)throw S(`stale-target`,`bridge-generation-mismatch`,{expectedGeneration:t.generation,observedGeneration:e.generation})}function je(e){let t=e.error_kind,n=typeof e.error_code==`string`?e.error_code:`guest-error`,r=typeof e.error==`string`?e.error:void 0,i=r?{guestMessage:r.slice(0,1024)}:{};throw S(t===`unsupported`?`unsupported`:t===`malformed_tree`?`malformed-tree`:t===`application_not_responding`?`timeout`:t===`application_unavailable`?`transport-failure`:t===`bad_request`?`malformed-tree`:`transport-failure`,n,i)}function M(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}async function Me(e){let t=new Ee(e.limits.maxResponseBytes-4),n=T(e.deadline,`bridge-request-deadline`);return await new Promise((r,i)=>{let a=!1,o=!1,s=setTimeout(()=>{p(S(`timeout`,`bridge-request-deadline`,{dispatched:o})),e.socket.destroy()},n),c=()=>{p(S(`cancelled`,`abort-signal`,{dispatched:o})),e.socket.destroy()},l=n=>{try{if(!Buffer.isBuffer(n))throw S(`transport-failure`,`bridge-data-invalid`);let r=t.push(n);if(r){let t=De(r);if(ke(t,e.requestId),Ae(t,{pid:e.expectedPid,generation:e.expectedGeneration}),t.ok!==!0&&je(t),typeof t.truncated!=`boolean`)throw S(`malformed-tree`,`truncated-invalid`);f(t);return}}catch(t){p(t),e.socket.destroy()}},u=e=>p(C(e)),d=()=>{a||(e.process.isAlive()?p(S(`transport-failure`,`bridge-connection-closed`)):k(e.host,e.process).then(p))};e.process.wait.then(()=>{a||k(e.host,e.process).then(p)},e=>{a||p(C(e))});let f=e=>m(()=>r(e)),p=e=>m(()=>i(e)),m=t=>{a||(a=!0,clearTimeout(s),e.deadline.signal?.removeEventListener(`abort`,c),e.socket.off(`data`,l),e.socket.off(`error`,u),e.socket.off(`close`,d),t())};e.socket.on(`data`,l),e.socket.on(`error`,u),e.socket.on(`close`,d),e.deadline.signal?.addEventListener(`abort`,c,{once:!0});try{if(e.deadline.signal?.aborted)throw S(`cancelled`,`abort-signal`);o=!0,e.socket.write(e.frame)}catch(t){p(C(t)),e.socket.destroy()}})}var Ne=class{sessions=new Map;requestQueues=new Map;ownerId=y();closed=!1;host;constructor(e){this.host=e}async request(e){if(this.closed)throw S(`unsupported`,`source-closed`);return await this.withSimulatorLock(e.target.udid,e.deadline,()=>this.requestInSimulator(e))}async requestInSimulator(e){if(this.closed)throw S(`unsupported`,`source-closed`);let t=e.deadline;T(t,`bridge-request-deadline`);let n=this.sessions.get(e.target.udid),r=await this.ensureSession(e,t);try{let n=await this.readTargetStartTime(e.target,t),i=await this.exchange(r,e,t);return await this.assertTargetStillCurrent(e.target,n,t),i}catch(e){throw await this.handleRequestFailure(e,r,n)}}async handleRequestFailure(e,t,n){let r=C(e);return Fe(r,t,n)?await this.removeSession(t,!0):r.failureKind===`process-crash`?await this.removeSession(t,!1):r.failureKind===`transport-failure`&&(t.socket?.destroy(),t.socket=void 0),r}async withSimulatorLock(e,t,n){let r=this.requestQueues.get(e)??Promise.resolve(),i,a=new Promise(e=>{i=e}),o=r.then(()=>a);this.requestQueues.set(e,o);try{return await Pe(r,t),await n()}finally{i(),this.requestQueues.get(e)===o&&this.requestQueues.delete(e)}}async close(){if(this.closed)return;this.closed=!0;let e=[...this.sessions.values()];this.sessions.clear(),await Promise.all(e.map(async e=>await this.dispose(e,!0)))}async ensureSession(e,t){let n=e.target.udid,r=this.sessions.get(n);if(r&&r.bridgePath===e.bridge.path&&r.process.isAlive())return(!r.socket||r.socket.destroyed)&&(r.socket=await this.connectUntilReady(r,t)),r;r&&await this.removeSession(r,!0);let i=Se(this.host,e.target.udid,this.ownerId);await this.host.ensureDirectory(_.dirname(i)),await this.host.remove(i);let a=this.host.start(e.target,e.bridge.path,i,{signal:t.signal}),o={udid:e.target.udid,bridgePath:e.bridge.path,socketPath:i,process:a};this.sessions.set(n,o);try{return o.socket=await this.connectUntilReady(o,t),o}catch(e){throw await this.removeSession(o,!0),C(e)}}async connectUntilReady(e,t){let n;for(;;){let r=T(t,`bridge-connect-deadline`);if(!e.process.isAlive())throw await k(this.host,e.process);try{return await this.host.connect(e.socketPath,{signal:t.signal,timeoutMs:Math.min(250,r)})}catch(e){if(n=e,e instanceof x&&e.failureKind===`cancelled`)throw e;let r=Math.min(20,T(t,`bridge-connect-deadline`));try{await E(t,r,`bridge-connect-deadline`)}catch(e){throw C(e)}}if(n instanceof x&&n.failureKind===`timeout`)throw n}}async exchange(e,t,n){(!e.socket||e.socket.destroyed)&&(e.socket=await this.connectUntilReady(e,n));let r=y(),i=Te(Oe({requestId:r,pid:t.target.pid,generation:t.target.generation,maxDepth:Math.min(t.limits.maxTraversalDepth,t.maxDepth),maxNodes:t.limits.maxNodes,maxDurationMs:T(n,`bridge-request-deadline`),maxResponseBytes:t.limits.maxResponseBytes,...t.nativeLevelsHint===void 0?{}:{nativeLevelsHint:t.nativeLevelsHint}}),t.limits);return await Me({process:e.process,socket:e.socket,frame:i,requestId:r,deadline:n,limits:t.limits,expectedPid:t.target.pid,expectedGeneration:t.target.generation,host:this.host})}async readTargetStartTime(e,t){let n=await this.host.readTargetProcessStartTime(e.pid,{signal:t.signal,timeoutMs:T(t,`target-identity-deadline`)});if(!n)throw S(`stale-target`,`target-process-unavailable`,{pid:e.pid,generation:e.generation});if(e.processStartTime!==void 0&&e.processStartTime!==n)throw S(`stale-target`,`target-process-changed`,{pid:e.pid,generation:e.generation,expectedStartTime:e.processStartTime,observedStartTime:n});return n}async assertTargetStillCurrent(e,t,n){let r=await this.host.readTargetProcessStartTime(e.pid,{signal:n.signal,timeoutMs:T(n,`target-identity-deadline`)});if(r!==t)throw S(`stale-target`,`target-process-changed`,{pid:e.pid,generation:e.generation,expectedStartTime:t,observedStartTime:r})}async removeSession(e,t){this.sessions.get(e.udid)===e&&this.sessions.delete(e.udid),await this.dispose(e,t)}async dispose(e,t){e.socket?.destroy(),e.socket=void 0,t&&e.process.isAlive()&&(e.process.signal(`SIGTERM`),await N(e.process,500),e.process.isAlive()&&(e.process.signal(`SIGKILL`),await N(e.process,500))),await this.host.remove(e.socketPath)}};async function Pe(e,t){let n=T(t,`bridge-request-deadline`);await Promise.race([e,E(t,n,`bridge-request-deadline`).then(()=>{throw S(`timeout`,`bridge-request-deadline`)})])}function Fe(e,t,n){return(e.failureKind===`cancelled`||e.failureKind===`timeout`)&&(e.details?.dispatched===!0||n!==t)}async function N(e,t){await Promise.race([e.wait.catch(()=>void 0),new Promise(e=>setTimeout(e,t))])}const P=16777216,F=12e4,I=1e4,Ie=Object.freeze({maxRequestBytes:65536,maxResponseBytes:4194304,maxNodes:5e3,maxTraversalDepth:64,maxDurationMs:5e3});function L(t){let n={...Ie,...t??{}};for(let[t,r]of Object.entries(n))if(!Number.isSafeInteger(r)||r<=0)throw new e(`INVALID_ARGS`,`Snapshot source limit ${t} must be a positive integer`,{name:t,value:r});if(n.maxRequestBytes>n.maxResponseBytes)throw new e(`INVALID_ARGS`,`Snapshot source request bytes cannot exceed response bytes`,{maxRequestBytes:n.maxRequestBytes,maxResponseBytes:n.maxResponseBytes});if(n.maxRequestBytes>P||n.maxResponseBytes>P)throw new e(`INVALID_ARGS`,`Snapshot source frame limits exceed the bridge bound`,{maxRequestBytes:n.maxRequestBytes,maxResponseBytes:n.maxResponseBytes,maximumFrameBytes:P});if(n.maxNodes>I||n.maxTraversalDepth>128)throw new e(`INVALID_ARGS`,`Snapshot source tree limits exceed the bridge bound`,{maxNodes:n.maxNodes,maxTraversalDepth:n.maxTraversalDepth,maximumNodes:I,maximumDepth:128});if(n.maxDurationMs>F)throw new e(`INVALID_ARGS`,`Snapshot source duration exceeds the bridge bound`,{maxDurationMs:n.maxDurationMs,maximumDurationMs:F});if(n.maxRequestBytes<=4||n.maxResponseBytes<=4)throw new e(`INVALID_ARGS`,`Snapshot source frame limits must leave room for a body`,{maxRequestBytes:n.maxRequestBytes,maxResponseBytes:n.maxResponseBytes});return Object.freeze(n)}const R=[`SnapshotBridge.m`,`SnapshotBridgeRuntime.m`,`SnapshotBridgeRuntime.h`,`SnapshotBridgeCapture.h`,`SnapshotBridgeCapture.m`],Le=[`SnapshotBridge.m`,`SnapshotBridgeRuntime.m`,`SnapshotBridgeCapture.m`];async function Re(e,t,n){let r=v(`sha256`);for(let i of R){let a=_.join(t,i);if(T(n,`native-source-fingerprint-deadline`),!e.exists(a))throw S(`unsupported`,`native-source-missing`,{filePath:a});r.update(i),r.update(`\0`),r.update(await e.readBinary(a)),r.update(`\0`)}return r.digest(`hex`)}async function ze(e,t,n){let r=await z(e,`xcodebuild`,[`-version`],n),i=await z(e,`sw_vers`,[`-productVersion`],n),a=await z(e,`sw_vers`,[`-buildVersion`],n),o=await z(e,`uname`,[`-m`],n),s=t.trim();if(!s)throw S(`unsupported`,`simulator-runtime-missing`);if(o!==`arm64`&&o!==`x86_64`)throw S(`unsupported`,`simulator-architecture-unsupported`,{architecture:o});return{xcode:r,macosProductVersion:i,macosBuild:a,architecture:o,simulatorRuntime:s}}async function z(e,t,n,r){let i=await Be(e,t,n,r);if(i.exitCode!==0)throw S(`unsupported`,`toolchain-probe-failed`,{command:t,exitCode:i.exitCode,stderr:i.stderr.slice(0,1024)});let a=(i.stdout||i.stderr).trim();if(!a)throw S(`unsupported`,`toolchain-probe-empty`,{command:t});return a}async function Be(e,t,n,r){let i=[],a;for(let o=1;;o+=1){let s;try{s=Math.min(h,T(r,`toolchain-probe-deadline`))}catch(e){throw a??e}i.push(s);try{return await He(e,t,n,r,s)}catch(e){if(!f(e))throw e;if(r.signal?.aborted)throw S(`cancelled`,`abort-signal`);if(a=Ve(t,i,e),o>=2)throw a}}}function Ve(e,t,n){let r=t.length;return S(`timeout`,`toolchain-probe-stalled`,{command:e,attemptTimeoutsMs:[...t],hint:`${e} did not answer within ${t[r-1]}ms on ${r} attempt(s). A toolchain probe that cannot answer is a host condition rather than a toolchain defect: run \`${e}\` by hand until it answers, then retry.`},n)}function He(e,t,n,r,i){return e.run(t,n,{allowFailure:!0,signal:r.signal,timeoutMs:i})}const B=`snapshot-bridge`,V=`manifest.json`,H=12e4;async function Ue(e){let t=e.deadline,n=e.sourceRoot??Ge(e.host),r=await Re(e.host,n,t),i=await ze(e.host,e.runtime,t),a=qe({schemaVersion:1,protocolVersion:1,sourceVersion:j,sourceHash:r,toolchain:i}),o=e.cacheRoot??_.join(e.host.homeDirectory(),`.agent-device`,`snapshot-source`),s=_.join(o,a);return await p({acquire:()=>e.host.acquireLock(_.join(o,`${a}.lock`),{deadline:t}),task:async()=>{let c=await Ke(e.host,s,{sourceHash:r,cacheKey:a,toolchain:i},t);if(c)return c;T(t,`native-build-deadline`),e.host.exists(s)&&await e.host.remove(s),T(t,`native-build-deadline`),await e.host.ensureDirectory(o);let l=_.join(o,`.${a}.${e.host.processId()}.tmp`);T(t,`native-build-deadline`),await e.host.remove(l);try{T(t,`native-build-deadline`),await e.host.ensureDirectory(l);let o=_.join(l,B),c=await We(e.host,t,i.architecture,n,o);if(c.exitCode!==0||!e.host.exists(o))throw S(`unsupported`,`native-build-failed`,{exitCode:c.exitCode,stderr:c.stderr.slice(0,4096)});T(t,`native-build-deadline`),await e.host.chmod(o,493);let u=await U(e.host,o,t),d={schemaVersion:1,protocolVersion:1,sourceVersion:j,sourceHash:r,cacheKey:a,toolchain:i,binarySha256:u};return await e.host.writeText(_.join(l,V),`${JSON.stringify(d,null,2)}\n`),T(t,`native-build-deadline`),await e.host.rename(l,s),{path:_.join(s,B),sourceHash:r,cacheKey:a,protocolVersion:1,sourceVersion:j}}catch(t){throw await e.host.remove(l),t}}})}async function We(e,t,n,r,i){let a=Math.min(H,T(t,`native-build-deadline`));try{return await e.run(`xcrun`,[`--sdk`,`iphonesimulator`,`clang`,`-arch`,n,`-mios-simulator-version-min=15.0`,`-fobjc-arc`,`-Werror`,`-Wall`,`-Wextra`,`-framework`,`Foundation`,`-framework`,`CoreGraphics`,...Le.map(e=>_.join(r,e)),`-o`,i],{signal:t.signal,timeoutMs:a,allowFailure:!0})}catch(e){throw f(e)?S(`timeout`,`native-build-stalled`,{timeoutMs:a,hint:`The Simulator SDK toolchain did not answer within ${a}ms, which stopped the bridge build before clang reported anything. Run \`xcrun --sdk iphonesimulator clang --version\` by hand until it answers, then retry.`},e):e}}function Ge(e){let t=e.projectRoot(),n=_.join(t,`apple`,`snapshot-bridge`);if(R.every(t=>e.exists(_.join(n,t))))return n;let r=_.join(t,`dist`,`apple`,`snapshot-bridge`);if(R.every(t=>e.exists(_.join(r,t))))return r;throw S(`unsupported`,`native-source-missing`,{projectRoot:t})}async function Ke(e,t,n,r){let i=_.join(t,B);if(!(!e.exists(i)||!e.exists(_.join(t,V))))try{let a=JSON.parse(await e.readText(_.join(t,V)));return a.schemaVersion!==1||a.protocolVersion!==1||a.sourceVersion!==`agent-device-simulator-ax-v1.7.0`||a.sourceHash!==n.sourceHash||a.cacheKey!==n.cacheKey||JSON.stringify(a.toolchain)!==JSON.stringify(n.toolchain)||typeof a.binarySha256!=`string`||await U(e,i,r)!==a.binarySha256?void 0:{path:i,sourceHash:n.sourceHash,cacheKey:n.cacheKey,protocolVersion:1,sourceVersion:j}}catch(e){if(e instanceof x&&(e.failureKind===`cancelled`||e.failureKind===`timeout`))throw e;return}}async function U(e,t,n){return T(n,`native-cache-hash-deadline`),v(`sha256`).update(await e.readBinary(t)).digest(`hex`)}function qe(e){return v(`sha256`).update(JSON.stringify(e)).digest(`hex`).slice(0,32)}const Je=h+H;function Ye(e){let t=e.now??Date.now,n=new Map,r=fe({waitMs:2e3,waitGrant:`first-caller`,retryAfterMs:6e4,now:t}),i=async(r,i)=>{let a=w(Je,i,t);try{let t=await e.host.withDiagnosticTimer(`ios.snapshot-source.prepare`,async()=>await Ue({host:e.host,runtime:r,limits:e.limits,deadline:a,sourceRoot:e.sourceRoot,cacheRoot:e.cacheRoot}),{producer:e.producer});return n.set(r,t),t}catch(e){throw C(e)}};return{readyBinary:async(e,t,a)=>n.get(e)||await r.value(e,{start:t=>i(e,t),wait:(e,n)=>E(t,e,a,n),pending:()=>S(`preparing`,`bridge-preparation-pending`)}),close:()=>{n.clear(),r.close()}}}function Xe(e,t){return!i(e)||!i(t)||Math.abs(t.width-t.height)<=1?!1:Math.abs(e.width-t.height)<=1&&Math.abs(e.height-t.width)<=1}const W=Object.freeze({elementType:`XC_kAXXCAttributeElementType`,elementBaseType:`XC_kAXXCAttributeElementBaseType`,label:`XC_kAXXCAttributeLabel`,value:`XC_kAXXCAttributeValue`,identifier:`XC_kAXXCAttributeIdentifier`,frame:`XC_kAXXCAttributeFrame`,automationType:`XC_kAXXCAttributeAutomationType`,traits:`XC_kAXXCAttributeTraits`,userInteractionEnabled:`XC_kAXXCAttributeIsUserInteractionEnabled`,children:`XC_kAXXCAttributeChildren`}),G=`Other.Other.Application.Group.Window.Sheet.Drawer.Alert.Dialog.Button.RadioButton.RadioGroup.CheckBox.DisclosureTriangle.PopUpButton.ComboBox.MenuButton.ToolbarButton.Popover.Keyboard.Key.NavigationBar.TabBar.TabGroup.Toolbar.StatusBar.Table.TableRow.TableColumn.Outline.OutlineRow.Browser.CollectionView.Slider.PageIndicator.ProgressIndicator.ActivityIndicator.SegmentedControl.Picker.PickerWheel.Switch.Toggle.Link.Image.Icon.SearchField.ScrollView.ScrollBar.StaticText.TextField.SecureTextField.DatePicker.TextView.Menu.MenuItem.MenuBar.MenuBarItem.Map.WebView.IncrementArrow.DecrementArrow.Timeline.RatingIndicator.ValueIndicator.SplitGroup.Splitter.RelevanceIndicator.ColorWell.HelpTag.Matte.DockItem.Ruler.RulerMarker.Grid.LevelIndicator.Cell.LayoutArea.LayoutItem.Handle.Stepper.Tab.TouchBar.StatusItem`.split(`.`),K={UIApplication:`Application`,UIWindow:`Window`},Ze=new Set(Object.values(W)),Qe=1n<<8n,$e=1n<<3n,et={x:0,y:0,width:0,height:0};function tt(e,t,n){let r=Array.isArray(e)?e:[e];if(r.length===0||r.some(e=>!M(e)))throw S(`malformed-tree`,`guest-tree-root-invalid`);let i=[],a=[],o=0;for(let e of r)c(e,void 0,0,!1);if(i.length>n.maxNodes)throw S(`malformed-tree`,`node-limit-exceeded`,{nodeCount:i.length,maxNodes:n.maxNodes});if(o>n.maxTraversalDepth)throw S(`malformed-tree`,`traversal-depth-exceeded`,{maxTraversalDepth:o,maxAllowedDepth:n.maxTraversalDepth});if(typeof t.truncated!=`boolean`)throw S(`malformed-tree`,`truncated-invalid`);let s=ot(i.filter(J)[0]);return s.kind===`reported`&&st(i,s.rect),{nodes:i,maxTraversalDepth:o,viewport:s,opaqueRemoteElements:a.filter(e=>it(e,s)).length,unresolvedCoordinateSpaceWindows:ct(i,s)};function c(e,t,r,s){if(i.length>=n.maxNodes)throw S(`malformed-tree`,`node-limit-exceeded`,{maxNodes:n.maxNodes});for(let t of Object.keys(e))if(!Ze.has(t))throw S(`malformed-tree`,`node-contains-unknown-field`,{key:t});let l=e[W.children];if(!Array.isArray(l))throw S(`malformed-tree`,`children-invalid`);let u=i.length,d=nt(e,u,t,r);i.push(d),o=Math.max(o,r),rt(d,l.length,s)&&a.push(d.rect);let f=s||d.type===`WebView`;for(let e of l){if(!M(e))throw S(`malformed-tree`,`child-invalid`);c(e,u,r+1,f)}}}function nt(e,t,n,r){let i=X(e[W.elementType]),a=X(e[W.elementBaseType]),o=dt(e[W.automationType]),s=at(e[W.frame]),c=lt(e[W.traits]),l=c===void 0?void 0:(c&Qe)===0n,u=c===void 0||(c&$e)===0n?void 0:!0,d=ut(e[W.userInteractionEnabled]);return{index:t,...n===void 0?{}:{parentIndex:n},...q(i,o)?{type:q(i,o)}:{},...i?{role:i}:{},...a&&a!==i?{subrole:a}:{},...X(e[W.label])?{label:X(e[W.label])}:{},...Z(e[W.value])?{value:Z(e[W.value])}:{},...X(e[W.identifier])?{identifier:X(e[W.identifier])}:{},...s?{rect:s}:{},...l===void 0?{}:{enabled:l},...u===void 0?{}:{selected:u},...d===void 0?{}:{userInteractionEnabled:d},depth:r}}function q(e,t){if(e!==void 0&&K[e])return K[e];if(e!==void 0&&G.includes(e))return e;if(t!==void 0)return G[t]??`Other`}function rt(e,t,n){return n&&e.role===`AXRemoteElement`&&t===0}function it(e,t){return e===void 0?!0:i(e)?t.kind!==`reported`||n(e,t.rect):!1}function at(e){if(e===void 0)return;if(!M(e))throw S(`malformed-tree`,`frame-invalid`);let t=[`X`,`Y`,`Width`,`Height`].map(t=>e[t]);if(!t.every(e=>typeof e==`number`&&Number.isFinite(e)))throw S(`malformed-tree`,`frame-invalid`);let[n,r,i,a]=t;if(i<0||a<0)throw S(`malformed-tree`,`frame-invalid`);return{x:n,y:r,width:i,height:a}}function ot(e){return!e||!J(e)?{kind:`missing`,reason:`not-provided`}:i(e.rect)?{kind:`reported`,rect:e.rect}:{kind:`missing`,reason:e.rect?`invalid`:`not-provided`}}function J(e){return e.type===`Application`||e.type===`Window`}function st(e,t){for(let n of e)n.hittable=n.parentIndex!==void 0&&r(n.enabled!==!1,n.rect,t)}function ct(e,t){return t.kind===`reported`?e.filter(n=>Y(n,e)&&Xe(n.rect??et,t.rect)).length:0}function Y(e,t){return J(e)?!0:e.parentIndex!==void 0&&J(t[e.parentIndex]??e)}function X(e){return typeof e==`string`&&e.length>0?e:void 0}function Z(e){if(typeof e==`string`)return e.length>0?e:void 0;if(typeof e==`number`||typeof e==`boolean`)return String(e);if(e!=null)throw S(`malformed-tree`,`scalar-invalid`)}function lt(e){if(e!=null){if(typeof e!=`string`||!/^\d{1,20}$/.test(e))throw S(`malformed-tree`,`traits-invalid`);return BigInt(e)}}function ut(e){if(e!=null){if(typeof e!=`boolean`)throw S(`malformed-tree`,`user-interaction-invalid`);return e}}function dt(e){if(e!=null){if(!Number.isSafeInteger(e))throw S(`malformed-tree`,`automation-type-invalid`);return e}}const Q=`simulator-ax-bridge`;function ft(e={}){let t=e.host??_e(),n=new Ne(t),r=new ge,i=Ye({host:t,limits:L(e.limits),producer:Q,sourceRoot:e.sourceRoot,cacheRoot:e.cacheRoot}),a=!1;return{acquire:async o=>{try{if(a)throw S(`unsupported`,`source-closed`);pt(o);let s=L({...e.limits,...o.limits}),c=w(s.maxDurationMs,o.signal),l=ht(o.hint,s.maxTraversalDepth),u=l+1,d=o.hint.rawTraversalDepth!==null;return await t.withDiagnosticTimer(`ios.snapshot-source.acquire`,async()=>{let e=await i.readyBinary(o.target.runtime,c,`bridge-preparation-deadline`),a=r.consume(o.target,u,d),f=await n.request({target:o.target,bridge:e,limits:s,maxDepth:l,nativeLevelsHint:a.nativeLevels,deadline:c});T(c,`snapshot-decode-deadline`);let p=gt(o.hint,o.target,f,s);return mt(t,r,o.target,u,d,a,f),{stage:`acquired`,acquisition:p}},{producer:Q})}catch(e){let t=C(e);return{stage:`failed`,failure:{kind:t.failureKind,code:t.failureCode,...t.details?{details:t.details}:{}}}}},close:async()=>{a||(a=!0,i.close(),await n.close())}}}function pt(t){if(!t.target.udid.trim()||!t.target.runtime.trim()||!t.target.generation.trim()||!Number.isSafeInteger(t.target.pid)||t.target.pid<=0)throw new e(`INVALID_ARGS`,`Simulator snapshot source target identity is incomplete`);let n=t.hint;if(n.projection!==`raw`&&n.projection!==`regular`||![`full`,`surface-observation`].includes(n.acquisitionIntent)||typeof n.interactiveOnly!=`boolean`||typeof n.customActions!=`boolean`||!$(n.rawTraversalDepth)||!$(n.regularPresentedDepth))throw new e(`INVALID_ARGS`,`Simulator snapshot source capture hint is invalid`)}function mt(e,t,n,r,i,a,o){let s=we(o),c=o.truncated===!0,l=t.learn(n,r,i,s);e.emitDiagnostic({level:`debug`,phase:`ios_snapshot_source_recovery`,data:{producer:Q,...n.targetId?{targetId:n.targetId}:{},generation:n.generation,requestedLevels:r,hint:a.reason,...a.nativeLevels===void 0?{}:{hintedLevels:a.nativeLevels},...s,truncated:c,learning:l}})}function ht(t,n){let r=t.rawTraversalDepth??n;if(r>n)throw new e(`INVALID_ARGS`,`Simulator snapshot source depth exceeds its bound`,{requested:r,maximum:n});return r}function $(e){return e===null||Number.isSafeInteger(e)&&e>=0}function gt(e,t,n,r){if(n.automationEnabled!==!0)throw S(`unsupported`,`automation-mode-unavailable`);let i=n.tree,a=n.truncated;if(typeof a!=`boolean`)throw S(`malformed-tree`,`truncated-invalid`);let o=tt(i,{truncated:a},r),s=n.generation;if(typeof s!=`string`||!s)throw S(`malformed-tree`,`generation-invalid`);if(o.opaqueRemoteElements>0)throw S(`unsupported`,`remote-content-boundary`,{remoteElements:o.opaqueRemoteElements});if(o.unresolvedCoordinateSpaceWindows>0)throw S(`unsupported`,`window-coordinate-space-unresolved`,{windows:o.unresolvedCoordinateSpaceWindows});let c=Object.freeze(o.nodes.map(e=>Object.freeze({...e,pid:t.pid}))),l=_t(e,a,o.viewport),u=Object.freeze({...t.targetId?{targetId:t.targetId}:{},generation:s}),d={producer:Q,nodes:c,truncated:a,viewport:o.viewport,lineage:u,residue:l};return e.acquisitionIntent===`full`?{...d,intent:`full`,hint:{...e,acquisitionIntent:`full`}}:{...d,intent:`surface-observation`,hint:{...e,acquisitionIntent:`surface-observation`}}}function _t(e,t,n){let r=n.kind===`reported`?[]:[{kind:`unavailable-fact`,fact:`hittability`}];return Object.freeze([...r,...e.interactiveOnly?[{kind:`unavailable-fact`,fact:`interactive-query`}]:[],...t?[{kind:`truncated`}]:[],...n.kind===`missing`?[{kind:`missing-viewport`,reason:n.reason}]:[]])}export{ft as createSimulatorSnapshotSource};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime.js";import{D as t,G as n,H as r,c as i,s as a}from"./sdk-contracts.js";import"./capture.js";import{n as o}from"./snapshot-capture-annotations.js";import{C as s,D as c,E as l,S as u,T as d,_ as f,b as p,g as ee,k as te,w as ne,x as m}from"./sdk-batch-runner.js";import{n as re}from"./snapshot-diagnostics.js";import{c as ie,g as h,h as ae,l as oe}from"./sdk-device.js";import{f as se,i as ce}from"./lease-scope.js";import{an as le,w as ue}from"./sdk-batch.js";import{n as g,t as _}from"./catalog.js";import{
|
|
1
|
+
import{r as e}from"./rolldown-runtime.js";import{D as t,G as n,H as r,c as i,s as a}from"./sdk-contracts.js";import"./capture.js";import{n as o}from"./snapshot-capture-annotations.js";import{C as s,D as c,E as l,S as u,T as d,_ as f,b as p,g as ee,k as te,w as ne,x as m}from"./sdk-batch-runner.js";import{n as re}from"./snapshot-diagnostics.js";import{c as ie,g as h,h as ae,l as oe}from"./sdk-device.js";import{f as se,i as ce}from"./lease-scope.js";import{an as le,w as ue}from"./sdk-batch.js";import{n as g,t as _}from"./catalog.js";import{A as de,h as fe,i as v,k as y}from"./registry.js";import{n as b}from"./success-text.js";import{c as x,n as pe,r as me}from"./diagnostics.js";import{t as S}from"./command-metadata.js";import"./diagnostics2.js";import{a as he,c as ge,i as _e,l as ve,n as ye,o as be,r as xe,s as Se,t as Ce}from"./daemon-client-lifecycle.js";import{t as C}from"./daemon-resolution.js";import{r as w}from"./session-paths.js";import{n as T,t as E}from"./client-metro.js";import{t as D}from"./screenshot-result.js";import O from"node:path";import k from"node:fs";function A(e){let t=e.appId??e.bundleId??e.packageName;return{session:e.session,appId:t,appBundleId:e.bundleId,package:e.packageName}}function j(e,t,n){return{deviceId:t,deviceName:n,...h(e)?{serial:t}:e===`ios`?{udid:t}:{}}}function M(e,t){let n=u(e,`bundleId`),r=u(e,`package`);return{app:l(e,`app`),appPath:l(e,`appPath`),platform:d(e,`platform`),appId:n??r,bundleId:n,package:r,identifiers:A({session:t,bundleId:n,packageName:r})}}function we(e,n){let r=u(e,`bundleId`),i=u(e,`packageName`),a=r??i??u(e,`appId`),o=u(e,`launchTarget`)??i??r??a;if(!o)throw new t(`COMMAND_FAILED`,`Daemon response is missing "launchTarget".`,{response:e});return{appName:u(e,`appName`),appId:a,bundleId:r,packageName:i,launchTarget:o,installablePath:u(e,`installablePath`),archivePath:u(e,`archivePath`),materializationId:u(e,`materializationId`),materializationExpiresAt:u(e,`materializationExpiresAt`),identifiers:A({session:n,bundleId:r,packageName:i,appId:a})}}function Te(e){return{released:e.released===!0,materializationId:l(e,`materializationId`),identifiers:{}}}function N(e){let{record:t,platform:n,id:r,name:i,target:a}=F(e,`name`),o=P(t);return{platform:n,target:a,kind:s(t,`kind`),id:r,name:i,booted:typeof t.booted==`boolean`?t.booted:void 0,...oe(n)&&o?{appleOs:o}:{},identifiers:j(n,r,i),...Ee(t),...I(n,r)}}function Ee(e){let t=e.claimedBy;if(!t||typeof t!=`object`||Array.isArray(t))return{};let n=t,r=n.session,i=n.workspace;return typeof r!=`string`||typeof i!=`string`?{}:{claimedBy:{session:r,workspace:i}}}function De(e){let{record:t,platform:n,id:r,name:i,target:a}=F(e,`name`),o=l(t,`device`),s=P(t),c={session:i,...j(n,r,o)};return{name:i,address:u(t,`address`),createdAt:ne(t,`createdAt`),sessionStateDir:u(t,`sessionStateDir`),runnerLogPath:u(t,`runnerLogPath`),device:{platform:n,target:a,id:r,name:o,...s?{appleOs:s}:{},identifiers:c,...I(n,r,{simulatorSetPath:m(t,`ios_simulator_device_set`)})},identifiers:c}}function P(e){let t=e.appleOs;return ie(t)?t:void 0}function F(e,t){let n=ee(e);return{record:n,platform:d(n,`platform`),id:l(n,`id`),name:l(n,t),target:p(n,`target`)}}function I(e,t,n={}){if(e===`ios`)return{ios:{udid:t,...n.simulatorSetPath===void 0?{}:{simulatorSetPath:n.simulatorSetPath}}};if(!h(e))return{};let r=n.serial??t;return e===`android`?{android:{serial:r}}:e===`harmonyos`?{harmonyos:{serial:r}}:{vega:{serial:r}}}function Oe(e){if(!f(e))return;let t=e.platform,n=u(e,`metroHost`),r=typeof e.metroPort==`number`?e.metroPort:void 0,a=u(e,`bundleUrl`),o=u(e,`launchUrl`);return{platform:i(t)?t:void 0,metroHost:n,metroPort:r,bundleUrl:a,launchUrl:o}}function ke(e){let t=e.platform,n=u(e,`id`),r=u(e,`device`);if(!ae(t)||!n||!r)return;let i=p(e,`target`),a=h(t)?u(e,`serial`)??n:void 0;return{platform:t,target:i,id:n,name:r,identifiers:{...j(t,n,r),...a?{serial:a}:{}},...I(t,t===`ios`?u(e,`device_udid`)??n:n,{simulatorSetPath:m(e,`ios_simulator_device_set`),serial:a})}}const Ae=[`explicit-selector`,`existing-session`,`single-booted-local`,`single-bootable-local`,`single-app-installed-local`,`preferred-local`,`single-provider-device`],je=[`session`,`local`,`provider`];function Me(e){if(!f(e))return;let{reason:t,source:n,candidateCount:r,bootOccurred:i}=e;if(!(!Ae.includes(t)||!je.includes(n)||typeof r!=`number`||!Number.isInteger(r)||r<0||typeof i!=`boolean`))return{reason:t,source:n,candidateCount:r,bootOccurred:i}}function Ne(e){if(f(e)&&typeof e.durationMs==`number`&&typeof e.measuredAt==`string`&&typeof e.method==`string`)return{durationMs:e.durationMs,measuredAt:e.measuredAt,method:e.method,appTarget:u(e,`appTarget`),appBundleId:u(e,`appBundleId`)}}function L(e){if(!f(e)||typeof e.success!=`boolean`||typeof e.exitCode!=`number`||typeof e.stdout!=`string`||typeof e.stderr!=`string`)return;let t=R(e.error);return{success:e.success,exitCode:e.exitCode,stdout:e.stdout,stderr:e.stderr,...t?{error:t}:{}}}const Pe=[`hint`,`diagnosticId`,`logPath`,`supportedOn`];function R(e){if(!f(e)||typeof e.code!=`string`||typeof e.message!=`string`)return;let t={code:e.code,message:e.message};Object.assign(t,z(e.cause));for(let n of Pe){let r=e[n];typeof r==`string`&&(t[n]=r)}return f(e.details)&&(t.details=e.details),typeof e.retriable==`boolean`&&(t.retriable=e.retriable),t}function z(e){let t=n(e);return t?{cause:t}:void 0}function Fe(e){let t=R(e.initialSnapshotError);return{...e.snapshot&&typeof e.snapshot==`object`?{snapshot:e.snapshot}:{},...t?{initialSnapshotError:t}:{}}}function Ie(e){return Array.isArray(e)?e:[]}function Le(e){let t=ce(e);return te({requestId:e.requestId,cwd:e.cwd,sessionExplicit:e.session!==void 0,debug:e.debug,includeCost:e.cost,responseLevel:e.responseLevel,lockPolicy:e.lockPolicy,lockPlatform:e.lockPlatform,...se(t),sessionIsolation:e.sessionIsolation,installSource:e.installSource,retainMaterializedPaths:e.retainMaterializedPaths,materializedPathRetentionMs:e.materializedPathRetentionMs,materializationId:e.materializationId})}function B(e){return e??`default`}const V={...v(),batch:fe(Re)};async function Re(e,n,r){let i=V[e];if(!i)throw Error(`Missing daemon writer for batch command: ${e}`);let a=S(e);if(!a)throw Error(`Missing command metadata for batch command: ${e}`);try{return await H(i,a,a.readInput(n))}catch(n){let i=n instanceof Error?n.message:String(n);throw new t(`INVALID_ARGS`,`Batch step ${r} ${e} input is invalid: ${i}`,void 0,n)}}async function ze(e,t){let n=V[e];if(!n)throw Error(`Missing daemon writer for command: ${e}`);return await H(n,S(e),t)}async function H(e,t,n){let r=await e(n);return{...r,...t?{metadataFlags:de(t,r.options)}:{}}}async function U(e,t={}){let n=e.meta?.requestId??pe(),r=!!(e.meta?.debug||e.flags?.verbose),i=e.flags,{daemonAuthToken:a,...o}=i??{},s=i?{...e,flags:o}:e,c=Se(s,t.authToken??a),l=le(ue(s.command),s),u=await x(`daemon_startup`,async()=>await _e(c),{requestId:n,session:e.session}),d=u.info,f=await ve(s,d);qe(s.command);let p=Be(s,f,d.token,n,r);return me({level:`info`,phase:`daemon_request_prepare`,data:{requestId:n,command:s.command,session:s.session}}),await We(s,u,c,async()=>Ke(Ge(await x(`daemon_request`,async()=>await ge(d,p,c.transportPreference,c.paths,l,t.onProgress?{onProgress:t.onProgress}:void 0),{requestId:n,command:e.command}),c),s,c))}function Be(e,t,n,r,i){return{...e,positionals:t.positionals,flags:t.flags,token:n,meta:Ve(e,t,r,i)}}function Ve(e,t,n,r){let i=e.meta??{};return{...i,requestId:n,debug:r,...He(i,e.flags),...Ue(t)}}function He(e,t){return{includeCost:e.includeCost,cwd:e.cwd,sessionExplicit:e.sessionExplicit,tenantId:e.tenantId??t?.tenant,runId:e.runId??t?.runId,leaseId:e.leaseId??t?.leaseId,sessionIsolation:e.sessionIsolation??t?.sessionIsolation,lockPolicy:e.lockPolicy,lockPlatform:e.lockPlatform}}function Ue(e){return{...e.uploadedArtifactId?{uploadedArtifactId:e.uploadedArtifactId}:{},...e.clientArtifactPaths?{clientArtifactPaths:e.clientArtifactPaths}:{},...e.installSource?{installSource:e.installSource}:{}}}async function We(e,n,r,i){let a,o=!1,s;try{a=await i()}catch(e){o=!0,s=e}let c=await xe(e,n,r,a);if(o)throw s;if(!c)throw new t(`COMMAND_FAILED`,`Daemon request produced no response after cleanup`);return c}function Ge(e,t){return e.ok||!t.ownedStateDir||!be(e)?e:ye(e,t.paths.baseDir)}function Ke(e,t,n){return!e.ok||!he(t,e)?e:Ce(e,n.ownedStateDir?n.paths.baseDir:void 0)}function qe(e){!Je(e)||process.stderr.isTTY!==!0||process.env.CI||process.stderr.write(e===g.reinstall?`Reinstalling...
|
|
2
2
|
`:`Installing...
|
|
3
3
|
`)}function Je(e){return e===g.install||e===g.reinstall||e===_.installSource}function W(e,t){return O.join(e,`metro-sessions`,`${w(t)}.json`)}function G(e){let t=W(e.stateDir,e.session);k.mkdirSync(O.dirname(t),{recursive:!0}),k.writeFileSync(t,`${JSON.stringify(e.hints,null,2)}\n`,`utf8`)}function Ye(e){let t=W(e.stateDir,e.session),n;try{n=k.readFileSync(t,`utf8`)}catch{return}let r;try{r=JSON.parse(n)}catch{return}if(!r||typeof r!=`object`||Array.isArray(r))return;let i=r,a={};return typeof i.metroHost==`string`&&i.metroHost&&(a.metroHost=i.metroHost),typeof i.metroPort==`number`&&Number.isInteger(i.metroPort)&&(a.metroPort=i.metroPort),typeof i.bundleUrl==`string`&&i.bundleUrl&&(a.bundleUrl=i.bundleUrl),Object.keys(a).length>0?a:void 0}function K(e){k.rmSync(W(e.stateDir,e.session),{force:!0})}function Xe(e){let n=async(t,n)=>await e(_.humanControl,t,n);return{allocate:async t=>J(await e(_.leaseAllocate,[],{...t,leaseId:void 0})),heartbeat:async t=>J(await e(_.leaseHeartbeat,[],t)),release:async t=>{let n=await e(_.leaseRelease,[],t);return{released:n.released===!0,provider:f(n.provider)?n.provider:void 0}},humanControl:{list:async e=>{let r=await n([`list`],e);if(!Array.isArray(r.holds))throw new t(`COMMAND_FAILED`,`Daemon did not return human-control holds.`);return r.holds.map(q)},put:async(e,t={},r)=>q((await n([`put`,e,JSON.stringify(t)],r)).hold),remove:async(e,t)=>(await n([`remove`,e],t)).released===!0}}}function q(e){if(!f(e)||!f(e.scope)||e.state!==`active`&&e.state!==`activating`||typeof e.createdAt!=`number`||typeof e.updatedAt!=`number`)throw new t(`COMMAND_FAILED`,`Daemon returned an invalid human-control hold.`);return{id:l(e,`id`),scope:{backend:l(e.scope,`backend`),leaseProvider:u(e.scope,`leaseProvider`),deviceKey:l(e.scope,`deviceKey`)},state:e.state,reason:u(e,`reason`),createdAt:e.createdAt,updatedAt:e.updatedAt,...typeof e.expiresAt==`number`?{expiresAt:e.expiresAt}:{}}}function J(e){let t=e.lease;if(!f(t))throw Error(`Invalid lease response from daemon`);return{leaseId:l(t,`leaseId`),tenantId:l(t,`tenantId`),runId:l(t,`runId`),backend:l(t,`backend`),leaseProvider:u(t,`leaseProvider`),clientId:u(t,`clientId`),deviceKey:u(t,`deviceKey`),createdAt:typeof t.createdAt==`number`?t.createdAt:void 0,heartbeatAt:typeof t.heartbeatAt==`number`?t.heartbeatAt:void 0,expiresAt:typeof t.expiresAt==`number`?t.expiresAt:void 0}}var Ze=e({createAgentDeviceClient:()=>Y});function Y(e={},n={}){let i=n.transport??U,o=t=>a(t.responseLevel??e.responseLevel),s=async(t,n=[],a={},o,s)=>{let c=Q(e,a),l={session:B(c.session),command:t,positionals:n,...s?{input:s}:{},flags:y(c,o),runtime:c.runtime,meta:Le(c)},u=await i(l,{authToken:c.daemonAuthToken});return u.ok||r(u.error),u.data??{}},c=async(e={})=>{let t=await s(_.sessionList,[],e);return(Array.isArray(t.sessions)?t.sessions:[]).map(De)},d=async(e,t={})=>{let n=await ze(e,t);return await s(n.command,n.positionals,n.options,n.metadataFlags,n.input)},f=(t={})=>B(Q(e,t).session);return{command:{wait:async e=>await d(`wait`,e),alert:async(e={})=>await d(`alert`,e),appState:async(e={})=>await d(`appstate`,e),back:async(e={})=>await d(`back`,e),home:async(e={})=>await d(`home`,e),orientation:async e=>await d(`orientation`,e),fold:async e=>await d(`fold`,e),appSwitcher:async(e={})=>await d(`app-switcher`,e),actionButton:async(e={})=>await d(`action-button`,e),keyboard:async(e={})=>await d(`keyboard`,e),clipboard:async e=>await d(`clipboard`,e),tvRemote:async e=>await d(`tv-remote`,e),reactNative:async e=>await d(`react-native`,e),doctor:async(e={})=>await d(`doctor`,e),prepare:async e=>await d(`prepare`,e),viewport:async e=>await d(`viewport`,e)},devices:{list:async(e={})=>{let t=await d(`devices`,e);return(Array.isArray(t.devices)?t.devices:[]).map(N)},capabilities:async(e={})=>{let t=await d(`capabilities`,e),n=Array.isArray(t.availableCommands)?t.availableCommands.filter(e=>typeof e==`string`):[];return{device:N(t.device),availableCommands:n}},boot:async(e={})=>await d(`boot`,e),shutdown:async(e={})=>await d(`shutdown`,e)},sessions:{list:async(e={})=>await c(e),stateDir:async(t={})=>{let n=Q(e,t);return C(n.stateDir??process.env.AGENT_DEVICE_STATE_DIR).baseDir},close:async(t={})=>{let n=f(t);try{let e=await d(`close`,t);return{session:n,shutdown:L(e.shutdown),provider:Z(e.provider),savedScript:u(e,`savedScript`),identifiers:{session:n}}}finally{dt(e,t)}},saveScript:async(e={})=>{let n=await s(_.sessionSaveScript,e.path===void 0?[]:[e.path],e,{force:e.force}),r=n.actionCount;if(typeof r!=`number`||!Number.isInteger(r)||r<0)throw new t(`COMMAND_FAILED`,`Daemon returned an invalid saved-script action count.`);let i=l(n,`session`);return{session:i,savedScript:l(n,`savedScript`),actionCount:r,identifiers:{session:i}}},artifacts:async(e={})=>await d(`artifacts`,e)},apps:{install:async e=>M(await d(`install`,e),f(e)),reinstall:async e=>M(await d(`reinstall`,e),f(e)),installFromSource:async e=>we(await d(`install-from-source`,e),f(e)),list:async(e={})=>{let t=await d(`apps`,e);return Array.isArray(t.apps)?t.apps.filter(e=>typeof e==`string`):[]},open:async t=>{let n=f(t),r=await d(`open`,t);ut({config:e,options:t,runtime:Q(e,t).runtime,sessionReused:r.sessionReused===!0});let i=ke(r),a=u(r,`appBundleId`),o=a,s=b(r);return{session:n,...s.length>0?{warnings:s}:{},sessionStateDir:u(r,`sessionStateDir`),runnerLogPath:u(r,`runnerLogPath`),requestLogPath:u(r,`requestLogPath`),eventLogPath:u(r,`eventLogPath`),appName:u(r,`appName`),appBundleId:a,appId:o,selection:Me(r.selection),startup:Ne(r.startup),runtime:Oe(r.runtime),device:i,...Fe(r),identifiers:{session:n,deviceId:i?.id,deviceName:i?.name,udid:i?.ios?.udid,serial:i?.android?.serial,appId:o,appBundleId:a}}},close:async(e={})=>{let t=f(e),n=await d(`close`,e);return{session:t,closedApp:e.app,shutdown:L(n.shutdown),savedScript:u(n,`savedScript`),identifiers:{session:t}}},push:async e=>await d(`push`,e),triggerEvent:async e=>await d(`trigger-app-event`,e)},materializations:{release:async e=>Te(await s(_.releaseMaterializedPaths,[],{...e,materializationId:e.materializationId}))},leases:Xe(s),metro:{prepare:async t=>{let n=await E({projectRoot:t.projectRoot??e.cwd,kind:t.kind,publicBaseUrl:t.publicBaseUrl,proxyBaseUrl:t.proxyBaseUrl,proxyBearerToken:t.bearerToken,bridgeScope:t.bridgeScope,launchUrl:t.launchUrl,companionProfileKey:t.companionProfileKey,companionConsumerKey:t.companionConsumerKey,metroPort:t.port,listenHost:t.listenHost,statusHost:t.statusHost,startupTimeoutMs:t.startupTimeoutMs,probeTimeoutMs:t.probeTimeoutMs,reuseExisting:t.reuseExisting,installDependenciesIfNeeded:t.installDependenciesIfNeeded,runtimeFilePath:t.runtimeFilePath,logPath:t.logPath});return st(e,n),n},reload:async(t={})=>await T({metroHost:t.metroHost,metroPort:t.metroPort,bundleUrl:t.bundleUrl,runtime:e.runtime??ct(e),timeoutMs:t.timeoutMs})},capture:{snapshot:async(e={})=>{let t=f(e),n=await d(`snapshot`,e);return o(e)?n:at(n,t)},screenshot:async(e={})=>{let t=f(e),n=await d(`screenshot`,e);return o(e)?n:D(n,t)},diff:async e=>await d(`diff`,e)},interactions:{click:async e=>await d(`click`,e),press:async e=>await d(`press`,e),longPress:async e=>await d(`longpress`,e),hover:async e=>await d(`hover`,e),swipe:async e=>await d(`swipe`,e),pan:async e=>await d(`gesture`,Qe(e)),drag:async e=>await d(`gesture`,$e(e)),fling:async e=>await d(`gesture`,et(e)),swipeGesture:async e=>await d(`gesture`,tt(e)),focus:async e=>await d(`focus`,e),type:async e=>await d(`type`,e),fill:async e=>await d(`fill`,e),scroll:async e=>await d(`scroll`,e),pinch:async e=>await d(`gesture`,nt(e)),rotateGesture:async e=>await d(`gesture`,rt(e)),transformGesture:async e=>await d(`gesture`,it(e)),get:async e=>await d(`get`,e),is:async e=>await d(`is`,e),find:async e=>await d(`find`,e)},replay:{run:async e=>await d(`replay`,e),test:async e=>await d(`test`,e)},batch:{run:async e=>await d(`batch`,e)},observability:{perf:async e=>await d(`perf`,e),logs:async(e={})=>await d(`logs`,e),events:async(e={})=>await d(`events`,e),network:async(e={})=>await d(`network`,e),audio:async(e={})=>await d(`audio`,e)},debug:{symbols:async t=>{let{symbolicateCrashArtifact:n}=await import(`./debug-symbols-facade.js`);return n({cwd:t.cwd??e.cwd,...t})}},recording:{record:async e=>await d(`record`,e),trace:async e=>await d(`trace`,e)},settings:{update:async e=>await d(`settings`,e)}}}function Qe(e){let{x:t,y:n,dx:r,dy:i,...a}=e;return{...a,kind:`pan`,origin:{x:t,y:n},delta:{x:r,y:i}}}function $e(e){return{...e,kind:`drag`}}function et(e){let{x:t,y:n,...r}=e;return{...r,kind:`fling`,origin:{x:t,y:n}}}function tt(e){return{...e,kind:`swipe`}}function nt(e){let{x:t,y:n,...r}=e;return X(t,n,`pinch`),{...r,kind:`pinch`,...t===void 0&&n===void 0?{}:{origin:{x:t,y:n}}}}function rt(e){let{x:t,y:n,...r}=e;return X(t,n,`rotate`),{...r,kind:`rotate`,...t===void 0&&n===void 0?{}:{origin:{x:t,y:n}}}}function it(e){let{x:t,y:n,dx:r,dy:i,...a}=e;return{...a,kind:`transform`,origin:{x:t,y:n},delta:{x:r,y:i}}}function X(e,n,r){if(e===void 0!=(n===void 0))throw new t(`INVALID_ARGS`,`gesture ${r} center requires both x and y`)}function at(e,t){let n=u(e,`appBundleId`);return{nodes:Ie(e.nodes),...typeof e.truncated==`boolean`?{truncated:e.truncated}:{},appName:u(e,`appName`),appBundleId:n,...ot(e),identifiers:{session:t,appId:n,appBundleId:n}}}function ot(e){let t=Z(e.visibility),n=Z(e.unchanged),r=c(e.keyboard),i=re(e.snapshotDiagnostics);return{...r?{keyboard:r}:{},...t?{visibility:t}:{},...o(e),...n?{unchanged:n}:{},...i?{snapshotDiagnostics:i}:{},...typeof e.fallbackScreenshotPath==`string`?{fallbackScreenshotPath:e.fallbackScreenshotPath}:{},...typeof e.refsGeneration==`number`?{refsGeneration:e.refsGeneration}:{}}}function Z(e){return f(e)?e:void 0}function Q(e,t){return{...e,...t}}function $(e,t={}){let n=Q(e,t);return{stateDir:C(n.stateDir??process.env.AGENT_DEVICE_STATE_DIR).baseDir,session:B(n.session)}}function st(e,t){try{let n=new URL(t.statusUrl),r=Number.parseInt(n.port,10);if(!n.hostname||!Number.isInteger(r))return;let i=t.bridge?void 0:t.iosRuntime.bundleUrl??t.androidRuntime.bundleUrl;G({...$(e),hints:{metroHost:n.hostname,metroPort:r,bundleUrl:i}})}catch{}}function ct(e){try{return Ye($(e))}catch{return}}function lt(e){if(!e)return;let{metroHost:t,metroPort:n,bundleUrl:r}=e;if(t!==void 0||n!==void 0||r!==void 0)return{metroHost:t,metroPort:n,bundleUrl:r}}function ut(e){try{let t=$(e.config,e.options),n=lt(e.runtime);if(n){G({...t,hints:n});return}e.sessionReused||K(t)}catch{}}function dt(e,t){try{K($(e,t))}catch{}}export{Y as n,U as r,Ze as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{D as e}from"./sdk-contracts.js";import{nn as t}from"./sdk-batch.js";import{i as n,n as r,r as i}from"./interactor-operation-binding.js";function a(e){return Object.freeze({captureScreenshot:e.capture})}function o(e,t){return Object.freeze({captureScreenshot:async n=>{await(await t({...n.execution,appBundleId:n.options?.appBundleId,signal:e})).screenshot(n.outPath,n.options)}})}function
|
|
1
|
+
import{D as e}from"./sdk-contracts.js";import{nn as t}from"./sdk-batch.js";import{i as n,n as r,r as i}from"./interactor-operation-binding.js";function a(e){return Object.freeze({captureScreenshot:e.capture})}function o(e,t){return Object.freeze({captureScreenshot:async n=>{await(await t({...n.execution,appBundleId:n.options?.appBundleId,signal:e})).screenshot(n.outPath,n.options)}})}function s(e){return o(e.signal,r(e))}function c(e){return o(e.signal,i({...e,operation:`screenshot`}))}function l(e,t){return t.signal===void 0?e:AbortSignal.any([e,t.signal])}function ee(e){return Object.freeze({captureSnapshot:e.capture,captureSnapshotWithCustomActions:e.customActions,captureSnapshotWithoutActiveApp:e.withoutActiveApp})}function u(t){let n=async n=>{let r=l(t.signal,n),i={...n.execution,appBundleId:n.options?.appBundleId,signal:r},a=t.ownership===`local`?await t.resolveInteractor(t.device,i):t.resolveInteractor(i);if(!a)throw new e(`UNSUPPORTED_OPERATION`,`Provider-owned snapshot operation has no bound provider interactor.`,{reason:`provider-runtime-interactor-missing`,deviceId:t.device.id});let o=await a.snapshot({...n.options,signal:r});if(!p(o))return o;if(!t.presentIosAcquisition)throw new e(`COMMAND_FAILED`,`Acquired iOS snapshot has no host presentation owner.`,{reason:`ios-snapshot-presenter-missing`,deviceId:t.device.id});return await t.presentIosAcquisition(o,n.options)};return Object.freeze({captureSnapshot:n,captureSnapshotWithCustomActions:n,captureSnapshotWithoutActiveApp:n})}function d(e){return u({...e,ownership:`local`})}function f(e){return u({...e,ownership:`provider`})}function p(e){return`stage`in e&&e.stage===`acquired`}function m(e){return Object.freeze({findText:e.findText})}function h(e){return Object.freeze({setViewport:e.setViewport})}function g(e){return Object.freeze({focusPoint:e.focus})}function _(e,t){return Object.freeze({focusPoint:async n=>{e.throwIfAborted(),await(await t({...n.execution,appBundleId:n.options?.appBundleId,signal:e})).focus(n.point.x,n.point.y)}})}function te(e){return _(e.signal,r(e))}function ne(e){return _(e.signal,i({...e,operation:`focus`}))}function re(e){let t=t=>t??e.unsupported;return Object.freeze({performGesturePlan:t(e.plan),performDirectionalFlingPlan:t(e.directionalFling),performMultiTouchGesturePlan:t(e.multiTouch),performTargetAuthoredDrag:t(e.targetAuthoredDrag),gestureViewport:t(e.viewport)})}function v(e,n,r){let i=async e=>{let i=await y(n,r,e);if(typeof i.performGesture!=`function`)throw t(`Runtime owner advertised gesture execution without an interactor implementation`);return await i.performGesture(e.plan)};return Object.freeze({...e.performGesturePlan.available?{performGesturePlan:i}:{},...e.performDirectionalFlingPlan.available?{performDirectionalFlingPlan:i}:{},...e.performMultiTouchGesturePlan.available?{performMultiTouchGesturePlan:i}:{},...e.performTargetAuthoredDrag.available?{performTargetAuthoredDrag:i}:{},...e.gestureViewport.available?{gestureViewport:async e=>{let i=await y(n,r,e);if(typeof i.gestureViewport!=`function`)throw t(`Runtime owner advertised gestureViewport without an interactor implementation`);return await i.gestureViewport()}}:{}})}async function y(e,t,n){return e.throwIfAborted(),await t({...n.execution,appBundleId:n.options?.appBundleId,signal:e})}function b(e){return v(e.facts,e.signal,r(e))}function x(e){return v(e.facts,e.signal,i({...e,operation:`gesture`}))}function S(e){return Object.freeze({scrollDirection:e.scroll})}function C(e,t){return Object.freeze({scrollDirection:async n=>(e.throwIfAborted(),await(await t({...n.execution,appBundleId:n.target?.appBundleId,signal:e})).scroll(n.direction,n.options))})}function w(e){return C(e.signal,r(e))}function T(e){return C(e.signal,i({...e,operation:`scroll`}))}function E(e){return Object.freeze({typeText:e.type})}function D(e,t){return Object.freeze({typeText:async n=>(e.throwIfAborted(),await(await t({...n.execution,appBundleId:n.options?.appBundleId,signal:e})).type(n.text,n.delayMs))})}function O(e){return D(e.signal,r(e))}function k(e){return D(e.signal,i({...e,operation:`type`}))}function A(e){return typeof e!=`string`||e.trim().length===0?Object.freeze({status:`unreadable`,reason:`no-text-at-point`}):Object.freeze({status:`read`,text:e})}function j(e){return Object.freeze({readTextAtPoint:e.readTextAtPoint})}function M(e){return Object.freeze({readTextAtPoint:async n=>{let r=e.signal;r.throwIfAborted();let i=await e.resolveInteractor(e.device,{...n.execution,appBundleId:n.options?.appBundleId,signal:r});if(typeof i.readTextAtPoint!=`function`)throw t(`Runtime owner advertised readTextAtPoint without an interactor implementation`);return A(await i.readTextAtPoint(n.point,{appBundleId:n.options?.appBundleId,surface:n.options?.surface,signal:r}))}})}function N(e){return Object.freeze({back:e.back})}function P(e,t){return Object.freeze({back:async n=>{e.throwIfAborted(),await(await t({...n.execution,appBundleId:n.options?.appBundleId,signal:e})).back(n.mode)}})}function F(e){return Object.freeze({setOrientation:e.orientation})}function I(e,t){return Object.freeze({setOrientation:async n=>(e.throwIfAborted(),await(await t({...n.execution,appBundleId:n.options?.appBundleId,signal:e})).setOrientation(n.rotation))})}function L(e){return Object.freeze({tvRemote:e.tvRemote})}const R=`tv-remote`;function ie(e,t){return Object.freeze({tvRemote:async n=>{e.throwIfAborted();let r=await t({...n.execution,appBundleId:n.options?.appBundleId,signal:e}),{requireInteractorMethod:i}=await import(`./interactor-operation-binding.js`).then(e=>e.t);await i(r.tvRemote,R).call(r,n.button,n.durationMs)}})}function z(e){let t=t=>t??e.unsupported;return Object.freeze({keyboardStatus:t(e.status),keyboardDismiss:t(e.dismiss),keyboardEnter:t(e.enter)})}async function B(e,t,n){return e.throwIfAborted(),await t({...n.execution,appBundleId:n.options?.appBundleId,signal:e})}const V={keyboardStatus:`keyboard status`,keyboardDismiss:`keyboard dismiss`,keyboardEnter:`keyboard enter`};function H(e,t,n){let r=async r=>{let i=await B(t,n,r),{requireInteractorMethod:a}=await import(`./interactor-operation-binding.js`).then(e=>e.t);return await a(i[e],V[e]).call(i)};return Object.freeze({[e]:r})}function U(e){let t=t=>t??e.unsupported;return Object.freeze({readClipboard:t(e.read),writeClipboard:t(e.write)})}const W={readClipboard:`clipboard read`,writeClipboard:`clipboard write`};async function G(e,t,n){return e.throwIfAborted(),await t({...n.execution,appBundleId:n.options?.appBundleId,signal:e})}async function K(e,t){let{requireInteractorMethod:n}=await import(`./interactor-operation-binding.js`).then(e=>e.t);return n(e[t],W[t])}function q(e,t){return Object.freeze({readClipboard:async n=>{let r=await G(e,t,n);return await(await K(r,`readClipboard`)).call(r)}})}function J(e,t){return Object.freeze({writeClipboard:async n=>{let r=await G(e,t,n);await(await K(r,`writeClipboard`)).call(r,n.text)}})}const Y=[`home`,`appSwitcher`,`actionButton`],X={home:`home`,appSwitcher:`app-switcher`,actionButton:`action-button`};function ae(e){let t={};for(let n of Y)t[n]=e[n]??e.unsupported;return Object.freeze(t)}function oe(e,t,r){let i=async i=>{t.throwIfAborted();let a=await r({...i.execution,appBundleId:i.options?.appBundleId,signal:t});await n(a[e],X[e]).call(a)};return Object.freeze({[e]:i})}function se(e){return Object.freeze({triggerAppEvent:e.triggerAppEvent})}function ce(e,t){return Object.freeze({triggerAppEvent:async n=>{e.throwIfAborted(),await(await t({...n.execution,appBundleId:n.options?.appBundleId,signal:e})).open(n.eventUrl,{appBundleId:n.options?.appBundleId})}})}function Z(e){return Object.freeze({setSetting:e.setSetting,readSetting:e.readSetting})}async function Q(e,t,n){return e.throwIfAborted(),await t({...n.execution,appBundleId:n.appBundleId,signal:e})}function le(e,t){return Object.freeze({setSetting:async n=>await(await Q(e,t,n)).setSetting(n.setting,n.state,n.appBundleId,n.options)})}function ue(e,t){return Object.freeze({readSetting:async n=>{let r=await Q(e,t,n),{requireInteractorMethod:i}=await import(`./interactor-operation-binding.js`).then(e=>e.t);return await i(r.readSetting,`settings read`).call(r,n.setting)}})}function de(e){return Object.freeze({readAlert:e.read,awaitAlert:e.wait,acceptAlert:e.accept,dismissAlert:e.dismiss})}async function fe(e,t,n){return e.throwIfAborted(),await t({...n.execution,appBundleId:n.appBundleId,signal:e})}function pe(e){return{...e.timeoutMs===void 0?{}:{timeoutMs:e.timeoutMs},...e.appBundleId===void 0?{}:{appBundleId:e.appBundleId},...e.surface===void 0?{}:{surface:e.surface}}}const $={readAlert:`alert get`,awaitAlert:`alert wait`,acceptAlert:`alert accept`,dismissAlert:`alert dismiss`};function me(e,t,n){return Object.freeze({[e]:async r=>{let i=await fe(t,n,r),{requireInteractorMethod:a}=await import(`./interactor-operation-binding.js`).then(e=>e.t);return await a(i[e],$[e]).call(i,pe(r))}})}export{E as A,h as B,F as C,j as D,M as E,x as F,ee as G,d as H,re as I,a as J,s as K,te as L,T as M,S as N,O,b as P,ne as R,I as S,P as T,f as U,m as V,l as W,H as _,le as a,ie as b,ce as c,ae as d,W as f,V as g,U as h,ue as i,w as j,k,X as l,J as m,de as n,Z as o,q as p,c as q,me as r,se as s,$ as t,oe as u,z as v,N as w,L as x,R as y,g as z};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { b as DeviceInfo } from "./sdk-contracts.js";
|
|
2
|
-
import {
|
|
2
|
+
import { s as AppsFilter } from "./gesture-plan-types.js";
|
|
3
3
|
import { a as readAndroidClipboardWithAdb, c as AndroidAdbExecutor, d as AndroidAdbProvider, f as AndroidPortReverseEndpoint, i as getAndroidKeyboardStatusWithAdb, l as AndroidAdbExecutorOptions, n as AndroidKeyboardState, o as writeAndroidClipboardWithAdb, p as AndroidPortReverseProvider, r as dismissAndroidKeyboardWithAdb, t as AndroidKeyboardDismissResult, u as AndroidAdbExecutorResult } from "./device-input-state.js";
|
|
4
4
|
//#region packages/platform-android/src/adb-port-reverse.d.ts
|
|
5
5
|
declare function createAndroidPortReverseManager(provider: AndroidAdbProvider | AndroidAdbExecutor): AndroidPortReverseProvider;
|
package/dist/src/app-launch.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{D as e}from"./sdk-contracts.js";import{a as t,i as n,o as r}from"./sdk-batch-runner.js";import{d as i,f as a}from"./sdk-device.js";import{n as o,t as s}from"./launch-console.js";import"./observability.js";import{r as c}from"./diagnostics.js";import{n as l}from"./exec.js";import"./diagnostics2.js";import"./command.js";import{i as u,n as d}from"./retry.js";import{D as f,o as p}from"./host-file.js";import{h as m,n as h}from"./config.js";import{a as g,o as _}from"./tool-provider.js";import{t as v}from"./
|
|
2
|
-
`)||e.endsWith(`\r`)?`${e}${t}`:`${e}\n${t}`}async function
|
|
1
|
+
import{D as e}from"./sdk-contracts.js";import{a as t,i as n,o as r}from"./sdk-batch-runner.js";import{d as i,f as a}from"./sdk-device.js";import{n as o,t as s}from"./launch-console.js";import"./observability.js";import{r as c}from"./diagnostics.js";import{n as l}from"./exec.js";import"./diagnostics2.js";import"./command.js";import{i as u,n as d}from"./retry.js";import{D as f,o as p}from"./host-file.js";import{h as m,n as h}from"./config.js";import{a as g,o as _}from"./tool-provider.js";import{t as v}from"./physical-device-control.js";import{a as y,n as b}from"./simctl.js";import{c as x}from"./runner-client.js";import{t as S}from"./simulator.js";import{a as C,l as w,u as T}from"./app-resolution.js";import E from"node:path";function D(t){if(!(t instanceof e)||t.code!==`COMMAND_FAILED`)return!1;let n=t.details??{};if(n.exitCode!==4)return!1;let r=String(n.stderr??``).toLowerCase();return r.includes(`fbsopenapplicationserviceerrordomain`)&&r.includes(`the request to open`)}async function O(e,t){let n=await _(b(e,[`get_app_container`,e.id,t]),{allowFailure:!0});if(n.exitCode!==0)return{installed:!1};let r=n.stdout.trim();if(!r)return{installed:!1};let i=await g(`plutil`,[`-extract`,`CFBundleExecutable`,`raw`,`-o`,`-`,`${r}/Info.plist`],{allowFailure:!0});if(i.exitCode!==0||!i.stdout.trim())return{installed:!0};let a=`${r}/${i.stdout.trim()}`,o=await g(`otool`,[`-l`,a],{allowFailure:!0});if(o.exitCode!==0)return{installed:!0};let s=o.stdout.toLowerCase();return{installed:!0,simulatorCompatible:s.includes(`iossimulator`)||s.includes(`platform 7`)}}function k(e){return e.installed?e.simulatorCompatible===!1?`ARCH_MISMATCH`:`PERSISTENT_LAUNCH_FAIL`:`APP_NOT_INSTALLED`}function A(e){switch(e){case`ARCH_MISMATCH`:return`The app binary was not built for the simulator platform. Rebuild with a simulator destination or use a physical device.`;case`APP_NOT_INSTALLED`:return`The app bundle is not installed on this simulator. Run install before open.`;case`PERSISTENT_LAUNCH_FAIL`:return`The simulator repeatedly refused to launch the app. Inspect crash logs in Console.app or ~/Library/Logs/DiagnosticReports/ and consider reinstalling the app.`;default:return`The simulator failed to launch the app. Retry with --debug and inspect diagnostics log for details.`}}const j=25e3;async function M(c,l,u){let d=u?.launchConsole?.trim(),f=u?.launchArgs;if(d&&(!i(c)||c.kind!==`simulator`))throw new e(`UNSUPPORTED_OPERATION`,o);if(a(c)){if(f&&f.length>0)throw new e(`UNSUPPORTED_OPERATION`,`--launch-args is not supported on macOS; launch arguments are currently iOS-only.`);await T(c,l,u);return}let p=u?.url?.trim();if(p){if(d)throw new e(`INVALID_ARGS`,s);if(!n(p))throw new e(`INVALID_ARGS`,`open <app> <url> requires a valid URL target`);if(c.kind===`simulator`){let e=!!f||t(p);if(u?.terminateRunningApp||e){let t=u?.appBundleId??await C(c,l);e?await R(c,t,{...f?{launchArgs:f}:{},...u?.terminateRunningApp?{terminateRunningApp:!0}:{}}):await L(c,t)}await N(c,p,void 0);return}let i=u?.appBundleId??await C(c,l),a=r(i,p);if(!a)throw new e(`INVALID_ARGS`,`Deep link open on iOS devices requires an active app bundle ID. Open the app first, then open the URL.`);await U(c,a,{payloadUrl:p,launchArgs:f,runnerOptions:u?.runnerOptions});return}let m=l.trim();if(n(m)){if(d)throw new e(`INVALID_ARGS`,s);if(c.kind===`simulator`){await N(c,m,f);return}let t=r(u?.appBundleId,m);if(!t)throw new e(`INVALID_ARGS`,`Deep link open on iOS devices requires an active app bundle ID. Open the app first, then open the URL.`);await U(c,t,{payloadUrl:m,launchArgs:f,runnerOptions:u?.runnerOptions});return}let h=u?.appBundleId??await C(c,l);if(c.kind===`simulator`){await R(c,h,{...d?{launchConsole:d}:{},...f?{launchArgs:f}:{},...u?.terminateRunningApp?{terminateRunningApp:!0}:{}});return}await U(c,h,{launchArgs:f,runnerOptions:u?.runnerOptions})}async function N(t,n,r){if(r&&r.length>0)throw new e(`INVALID_ARGS`,`--launch-args is not supported with iOS simulator URL opens (simctl openurl ignores launch args). Launch the app first with --launch-args, then issue the URL open in a separate call.`);await S(t),await y(t,[`openurl`,t.id,n])}async function P(e){a(e)||e.kind===`simulator`&&await S(e)}async function F(e,t,n){if(a(e)){await w(e,t);return}let r=await C(e,t);if(e.kind===`simulator`){await L(e,r);return}await I(r),await v(e).terminateApp(e,r,{runnerOptions:n,runRunnerCommand:x})}async function I(t){let{iosSystemSurfaceHost:n,iosSystemSurfaceOpenRefusal:r}=await import(`./ios-system-surface.js`).then(e=>e.a);if(n(t))throw new e(`UNSUPPORTED_OPERATION`,r(t),{reason:`system-surface-host-not-openable`,appBundleId:t})}async function L(t,n){await I(n),await S(t);let r=b(t,[`terminate`,t.id,n]),i=await _(r,{allowFailure:!0,timeoutMs:m});if(i.exitCode!==0&&!i.stderr.toLowerCase().includes(`found nothing to terminate`))throw new e(`COMMAND_FAILED`,`xcrun exited with code ${i.exitCode}`,l(i,{cmd:`xcrun`,args:r}))}async function R(t,n,r){await I(n),await S(t);let i=0,a=d.fromTimeoutMs(h);try{await u(async({deadline:i})=>{if(i?.isExpired())throw new e(`COMMAND_FAILED`,`App launch deadline exceeded`,{timeoutMs:h});let a=b(t,z(t.id,n,r)),o=r?.launchConsole?await B(a,r.launchConsole):await _(a,{allowFailure:!0});if(o.exitCode!==0)throw new e(`COMMAND_FAILED`,`xcrun exited with code ${o.exitCode}`,l(o,{cmd:`xcrun`,args:a}))},{maxAttempts:10,baseDelayMs:1e3,maxDelayMs:5e3,jitter:.2,shouldRetry(e){return D(e)?(i+=1,i<3):!1}},{deadline:a})}catch(e){if(D(e)){let r=e,i=k(await O(t,n));r.details={...r.details,hint:A(i)}}throw e}}function z(e,t,n){let r=[`launch`];return n?.launchConsole&&r.push(`--console-pty`),n?.terminateRunningApp&&r.push(`--terminate-running-process`),r.push(e,t),n?.launchArgs&&n.launchArgs.length>0&&r.push(...n.launchArgs),r}async function B(t,n){await p(E.dirname(n));try{let e=await _(t,{allowFailure:!0,timeoutMs:j});return await V(n,e.stdout,e.stderr),e}catch(t){let r=(t instanceof e?t:void 0)?.details;if(r?.timeoutMs===j){let e=typeof r.stdout==`string`?r.stdout:``,t=typeof r.stderr==`string`?r.stderr:``;return await V(n,e,t),c({level:`warn`,phase:`ios_simulator_launch_console_capture_timeout`,data:{timeoutMs:j,logPath:n,stdoutBytes:Buffer.byteLength(e),stderrBytes:Buffer.byteLength(t)}}),{stdout:e,stderr:t,exitCode:0}}throw t}}async function V(e,t,n){await f(e,H(t,n))}function H(e,t){return!e||!t||e.endsWith(`
|
|
2
|
+
`)||e.endsWith(`\r`)?`${e}${t}`:`${e}\n${t}`}async function U(e,t,n){await I(t),await v(e).launchApp(e,t,{...n,runRunnerCommand:x})}export{M as n,P as r,F as t};
|