agent-device 0.21.18 → 0.21.20
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.18.apk → agent-device-android-ime-helper-0.21.20.apk} +0 -0
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.20.apk.sha256 +1 -0
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.18.manifest.json → agent-device-android-ime-helper-0.21.20.manifest.json} +4 -4
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.18.apk → agent-device-android-snapshot-helper-0.21.20.apk} +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.20.apk.sha256 +1 -0
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.18.manifest.json → agent-device-android-snapshot-helper-0.21.20.manifest.json} +6 -6
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerApp.m +12 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandJournal.swift +1 -14
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +14 -16
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +40 -14
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotModels.swift +20 -5
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotPresentationProjection.swift +2 -15
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotVisibilityFold.swift +10 -25
- package/dist/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotVisibilityFoldProjection.swift +1 -18
- package/dist/src/adapter.js +1 -1
- package/dist/src/adb-executor.js +2 -2
- package/dist/src/adb-failure.js +2 -1
- package/dist/src/agent-browser-lifecycle.js +1 -1
- package/dist/src/agent-browser-process-record.js +1 -1
- package/dist/src/agent-browser-provider.js +1 -1
- package/dist/src/agent-browser-tool.js +1 -1
- package/dist/src/agent-device-client.js +2 -2
- package/dist/src/ai-sdk.js +1 -1
- package/dist/src/alert-runtime.js +1 -1
- package/dist/src/alert.js +1 -0
- package/dist/src/android-input-ownership.js +1 -1
- package/dist/src/android.js +1 -1
- package/dist/src/app-launch.js +2 -2
- package/dist/src/app-lifecycle.js +1 -1
- package/dist/src/app-log-runtime2.js +1 -1
- package/dist/src/app-resolution.js +2 -2
- package/dist/src/apple-runner-platform.js +1 -1
- package/dist/src/archive.js +2 -2
- package/dist/src/browser-launch.js +1 -1
- package/dist/src/cache.js +1 -1
- package/dist/src/catalog.js +1 -1
- package/dist/src/cli-config.js +1 -1
- package/dist/src/cli-help.js +287 -301
- package/dist/src/cli-runner.js +1 -1
- package/dist/src/cli.js +4 -4
- package/dist/src/client-metro-companion.js +1 -1
- package/dist/src/client-metro.js +1 -1
- package/dist/src/client-types.d.ts +25 -6
- package/dist/src/{scroll-command.d.ts → cloud-artifacts.d.ts} +242 -238
- package/dist/src/command-metadata.js +1 -1
- package/dist/src/command-schema.js +3 -3
- package/dist/src/command-tools.js +2 -2
- package/dist/src/command.js +1 -1
- package/dist/src/config.js +1 -1
- package/dist/src/connection-runtime.js +1 -1
- package/dist/src/contracts.js +1 -1
- package/dist/src/daemon-client-lease-beat.js +1 -1
- package/dist/src/daemon-client-lifecycle.js +1 -1
- package/dist/src/daemon-client-transport.js +1 -1
- package/dist/src/daemon-policy-file.js +1 -1
- package/dist/src/daemon-registration.js +1 -1
- package/dist/src/debug-symbols-facade.js +3 -3
- package/dist/src/device-claim-inspection.js +1 -1
- package/dist/src/device-claim-rule.js +1 -1
- package/dist/src/device-inventory-context.js +1 -1
- package/dist/src/device-rotation.js +1 -1
- package/dist/src/device-session.js +1 -1
- package/dist/src/devicectl.js +1 -1
- package/dist/src/diagnostics.js +1 -1
- package/dist/src/diagnostics2.js +1 -1
- package/dist/src/display-inventory.js +1 -1
- package/dist/src/durable-resource.js +1 -1
- package/dist/src/engine-eval-script.js +1 -1
- package/dist/src/error.js +1 -1
- package/dist/src/exec.js +1 -1
- package/dist/src/find.js +1 -1
- package/dist/src/finders.js +1 -1
- package/dist/src/generic-settle.js +1 -1
- package/dist/src/gesture-runtime.js +1 -1
- package/dist/src/hdc.js +1 -1
- package/dist/src/helper.js +2 -2
- package/dist/src/host.js +1 -1
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.js +1 -1
- package/dist/src/input-actions2.js +2 -2
- package/dist/src/install-source-network-transport.js +1 -1
- package/dist/src/interaction-positionals.js +1 -1
- package/dist/src/interaction-ref-policy.js +1 -1
- package/dist/src/interaction.js +1 -1
- package/dist/src/interaction2.js +1 -1
- package/dist/src/interactor.js +5 -5
- 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/internal/png-worker.js +1 -1
- package/dist/src/ios-snapshot-acquisition.js +1 -1
- package/dist/src/ios-snapshot-engine.js +1 -1
- package/dist/src/launch-confirmation.js +1 -0
- package/dist/src/lease.js +1 -1
- package/dist/src/limrun-runtime-dependencies.js +1 -1
- package/dist/src/limrun.d.ts +50 -42
- package/dist/src/local-interactor-operation-set.js +1 -1
- package/dist/src/mechanics.js +16 -17
- package/dist/src/mobile-snapshot-semantics.js +1 -1
- package/dist/src/observe-until.js +1 -0
- package/dist/src/overlay.js +2 -2
- package/dist/src/owner-identity.js +1 -1
- package/dist/src/parameterized-recorded-fill.js +1 -1
- package/dist/src/perf-facade.js +1 -1
- package/dist/src/perf-runtime-operation-builder.js +1 -1
- package/dist/src/perf-runtime-plan.js +1 -1
- package/dist/src/perf-target.js +1 -1
- package/dist/src/physical-device-control.js +1 -1
- package/dist/src/platform-request-scope.js +1 -1
- package/dist/src/platform-runtime-android-adb-host.js +1 -1
- package/dist/src/platform-runtime-app-log-process.js +1 -1
- package/dist/src/platform-runtime-host.js +1 -1
- package/dist/src/platform-runtime-managed-owner.js +1 -1
- package/dist/src/platform-runtime-operation-host.js +2 -2
- package/dist/src/platform-runtime-runtime-hints.js +1 -1
- package/dist/src/platform-runtime-screen-recording-apple-simulator-host.js +1 -1
- package/dist/src/platform-runtime-screen-recording-finalizer-host.js +1 -1
- package/dist/src/platform-runtime-screen-recording-process-host.js +1 -1
- package/dist/src/platform-runtime.js +1 -1
- package/dist/src/platform-runtime2.js +1 -1
- package/dist/src/png-worker-client.js +1 -1
- package/dist/src/provider-device-admission.js +1 -0
- package/dist/src/provider-session-ownership.js +1 -1
- package/dist/src/provider-webdriver.js +1 -1
- package/dist/src/proxy.js +1 -1
- package/dist/src/react-native.js +1 -1
- package/dist/src/record-runtime.js +1 -1
- package/dist/src/registry.js +52 -36
- package/dist/src/replay-divergence.js +1 -1
- package/dist/src/replay.js +1 -1
- package/dist/src/request-admission.js +1 -1
- package/dist/src/request-runtime-binding.js +1 -1
- package/dist/src/result-serialization.js +1 -1
- package/dist/src/runner-cache-metadata.js +3 -3
- 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 -3
- package/dist/src/runner-exchange.js +1 -1
- package/dist/src/runner-operations-facade.js +1 -1
- package/dist/src/runner-session-types.js +1 -1
- package/dist/src/runner-start-budget.js +1 -1
- package/dist/src/runner-startup-transport.js +1 -1
- package/dist/src/runner-xctestrun.js +1 -1
- package/dist/src/runner.js +1 -1
- package/dist/src/runtime-admission.js +1 -0
- package/dist/src/runtime.js +1 -1
- package/dist/src/runtime10.js +2 -2
- package/dist/src/runtime2.js +2 -2
- package/dist/src/runtime3.js +1 -1
- 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-resource-recovery.js +1 -1
- package/dist/src/screenshot-result.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-gesture.js +1 -1
- package/dist/src/sdk-batch-runner.js +2 -2
- package/dist/src/sdk-batch.js +1 -1
- package/dist/src/sdk-contracts.d.ts +18 -2
- package/dist/src/sdk-contracts.js +2 -2
- package/dist/src/sdk-finders.js +1 -1
- package/dist/src/sdk-selectors.d.ts +13 -4
- package/dist/src/sdk-selectors.js +1 -1
- package/dist/src/selection.js +0 -0
- package/dist/src/selector-pipeline-policy.js +1 -0
- package/dist/src/selector-runtime.js +1 -1
- package/dist/src/selectors.js +1 -1
- package/dist/src/server.js +1 -1
- package/dist/src/session-runtime-admission.js +1 -1
- package/dist/src/session-snapshot.js +1 -1
- package/dist/src/session-store.js +3 -3
- package/dist/src/session2.js +5 -5
- package/dist/src/simulator-boot.js +1 -1
- package/dist/src/simulator.js +1 -1
- package/dist/src/snapshot-desktop-projection.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/src.js +1 -1
- package/dist/src/src7.js +1 -1
- package/dist/src/target-evidence.js +1 -1
- package/dist/src/text-entry-focus.js +1 -1
- package/dist/src/tool-provider.js +3 -3
- package/dist/src/tool-provider2.js +1 -1
- package/dist/src/tool-provider3.js +1 -1
- package/dist/src/toolchain-probe.js +1 -1
- package/dist/src/touch-runtime.js +1 -1
- package/dist/src/touch-runtime2.js +1 -0
- package/dist/src/tree.js +1 -1
- package/dist/src/type-text-runtime.js +1 -1
- package/dist/src/update-check.js +1 -1
- package/dist/src/video.js +1 -1
- package/package.json +1 -1
- package/server.json +2 -2
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.18.apk.sha256 +0 -1
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.18.apk.sha256 +0 -1
- package/dist/src/runner-command-traits.js +0 -1
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
232a1d7a3c39d9acf586ea07bf6c17edc382313a568272f6bab2ef3458d2b420 agent-device-android-ime-helper-0.21.20.apk
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "android-ime-helper",
|
|
3
|
-
"version": "0.21.
|
|
4
|
-
"assetName": "agent-device-android-ime-helper-0.21.
|
|
5
|
-
"sha256": "
|
|
3
|
+
"version": "0.21.20",
|
|
4
|
+
"assetName": "agent-device-android-ime-helper-0.21.20.apk",
|
|
5
|
+
"sha256": "232a1d7a3c39d9acf586ea07bf6c17edc382313a568272f6bab2ef3458d2b420",
|
|
6
6
|
"packageName": "com.callstack.agentdevice.imehelper",
|
|
7
|
-
"versionCode":
|
|
7
|
+
"versionCode": 21020,
|
|
8
8
|
"serviceComponent": "com.callstack.agentdevice.imehelper/.TestInputMethodService",
|
|
9
9
|
"broadcastProtocol": "android-ime-helper-v1"
|
|
10
10
|
}
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
4fa070b457f9b178e7c05706ff95c79cbb171da08dd5bd28dbb375f6293efc12 agent-device-android-snapshot-helper-0.21.20.apk
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "android-snapshot-helper",
|
|
3
|
-
"version": "0.21.
|
|
4
|
-
"releaseTag": "v0.21.
|
|
5
|
-
"assetName": "agent-device-android-snapshot-helper-0.21.
|
|
3
|
+
"version": "0.21.20",
|
|
4
|
+
"releaseTag": "v0.21.20",
|
|
5
|
+
"assetName": "agent-device-android-snapshot-helper-0.21.20.apk",
|
|
6
6
|
"apkUrl": null,
|
|
7
|
-
"sha256": "
|
|
8
|
-
"checksumName": "agent-device-android-snapshot-helper-0.21.
|
|
7
|
+
"sha256": "4fa070b457f9b178e7c05706ff95c79cbb171da08dd5bd28dbb375f6293efc12",
|
|
8
|
+
"checksumName": "agent-device-android-snapshot-helper-0.21.20.apk.sha256",
|
|
9
9
|
"packageName": "com.callstack.agentdevice.snapshothelper",
|
|
10
|
-
"versionCode":
|
|
10
|
+
"versionCode": 21020,
|
|
11
11
|
"instrumentationRunner": "com.callstack.agentdevice.snapshothelper/.SnapshotInstrumentation",
|
|
12
12
|
"minSdk": 23,
|
|
13
13
|
"targetSdk": 36,
|
|
@@ -422,6 +422,8 @@ static const NSTimeInterval AgentDeviceTextEntryBurstBreakSeconds = 1.0;
|
|
|
422
422
|
// UIApplicationSceneManifest in Info.plist names this class; a rename must update the manifest.
|
|
423
423
|
@interface AgentDeviceRunnerSceneDelegate : UIResponder <UIWindowSceneDelegate>
|
|
424
424
|
@property(nonatomic, strong) UIWindow *window;
|
|
425
|
+
// Held for the app's lifetime: a window nobody retained would be gone before the test queried it.
|
|
426
|
+
@property(nonatomic, strong) UIWindow *secondWindow;
|
|
425
427
|
@end
|
|
426
428
|
|
|
427
429
|
@implementation AgentDeviceRunnerSceneDelegate
|
|
@@ -442,6 +444,16 @@ static const NSTimeInterval AgentDeviceTextEntryBurstBreakSeconds = 1.0;
|
|
|
442
444
|
if ([NSProcessInfo.processInfo.arguments containsObject:@"--agent-device-dismiss-popup-window"]) {
|
|
443
445
|
self.window.accessibilityIdentifier = @"Dismiss popup";
|
|
444
446
|
}
|
|
447
|
+
// A second window the app keeps visible, so `app.windows` reports the main window and this one.
|
|
448
|
+
// Window order is what the resolver walks, and a candidate behind the answer must never be read.
|
|
449
|
+
if ([NSProcessInfo.processInfo.arguments containsObject:@"--agent-device-second-window"]) {
|
|
450
|
+
UIWindow *second = [[UIWindow alloc] initWithWindowScene:(UIWindowScene *)scene];
|
|
451
|
+
second.frame = ((UIWindowScene *)scene).coordinateSpace.bounds;
|
|
452
|
+
second.accessibilityIdentifier = @"agent-device-second-window";
|
|
453
|
+
second.rootViewController = [UIViewController new];
|
|
454
|
+
self.secondWindow = second;
|
|
455
|
+
[second makeKeyAndVisible];
|
|
456
|
+
}
|
|
445
457
|
#endif
|
|
446
458
|
[self.window makeKeyAndVisible];
|
|
447
459
|
}
|
|
@@ -125,22 +125,9 @@ final class RunnerCommandJournal {
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
private func encodeResponseJson(command: Command, response: Response) -> String? {
|
|
128
|
-
guard
|
|
128
|
+
guard command.traits.retainsJournalResponseJson else { return nil }
|
|
129
129
|
guard let data = try? JSONEncoder().encode(response) else { return nil }
|
|
130
130
|
guard data.count <= maxResponseJsonBytes else { return nil }
|
|
131
131
|
return String(data: data, encoding: .utf8)
|
|
132
132
|
}
|
|
133
|
-
|
|
134
|
-
private func shouldRetainResponseJson(command: Command) -> Bool {
|
|
135
|
-
switch command.command {
|
|
136
|
-
case .snapshot, .screenshot:
|
|
137
|
-
return false
|
|
138
|
-
case .tap, .mouseClick, .longPress, .drag,
|
|
139
|
-
.remotePress, .type, .swipe, .scroll, .desktopScroll, .findText, .querySelector, .readText,
|
|
140
|
-
.backInApp, .backSystem, .home, .rotate, .appSwitcher, .actionButton, .keyboardDismiss, .keyboardReturn,
|
|
141
|
-
.alert, .sequence, .gesture, .gestureViewport, .recordStart, .recordStop,
|
|
142
|
-
.status, .uptime, .appState, .pasteboardWrite, .activate, .terminate, .targetReset, .shutdown:
|
|
143
|
-
return true
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
133
|
}
|
package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift
CHANGED
|
@@ -224,25 +224,23 @@ extension RunnerTests {
|
|
|
224
224
|
|
|
225
225
|
|
|
226
226
|
|
|
227
|
-
func resolveRunnerWindow(app: XCUIApplication) -> (window: XCUIElement?, frame: CGRect) {
|
|
228
|
-
let windows = app.windows.allElementsBoundByIndex
|
|
229
|
-
var frames: [CGRect?] = []
|
|
230
|
-
for window in windows {
|
|
231
|
-
frames.append(window.exists ? window.frame : nil)
|
|
232
|
-
}
|
|
233
|
-
if let index = Self.firstUsableWindowIndex(frames: frames) {
|
|
234
|
-
return (windows[index], frames[index] ?? .zero)
|
|
235
|
-
}
|
|
236
|
-
return (nil, app.frame)
|
|
237
|
-
}
|
|
238
227
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
func resolveRunnerWindow(app: XCUIApplication) -> (window: XCUIElement?, frame: CGRect) {
|
|
237
|
+
for window in app.windows.allElementsBoundByIndex where window.exists {
|
|
238
|
+
let frame = window.frame
|
|
239
|
+
if !frame.isEmpty {
|
|
240
|
+
return (window, frame)
|
|
243
241
|
}
|
|
244
242
|
}
|
|
245
|
-
return nil
|
|
243
|
+
return (nil, app.frame)
|
|
246
244
|
}
|
|
247
245
|
|
|
248
246
|
func onScreenWindowFrame(app: XCUIApplication) -> CGRect {
|
package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift
CHANGED
|
@@ -102,16 +102,20 @@ struct CommandTraits {
|
|
|
102
102
|
|
|
103
103
|
let convertsRecordedFailure: Bool
|
|
104
104
|
|
|
105
|
+
let retainsJournalResponseJson: Bool
|
|
106
|
+
|
|
105
107
|
init(
|
|
106
108
|
isInteraction: Bool = false,
|
|
107
109
|
retryOnSessionLoss: Bool = false,
|
|
108
110
|
launchPolicy: CommandLaunchPolicy,
|
|
109
|
-
convertsRecordedFailure: Bool = false
|
|
111
|
+
convertsRecordedFailure: Bool = false,
|
|
112
|
+
retainsJournalResponseJson: Bool
|
|
110
113
|
) {
|
|
111
114
|
self.isInteraction = isInteraction
|
|
112
115
|
self.retryOnSessionLoss = retryOnSessionLoss
|
|
113
116
|
self.launchPolicy = launchPolicy
|
|
114
117
|
self.convertsRecordedFailure = convertsRecordedFailure
|
|
118
|
+
self.retainsJournalResponseJson = retainsJournalResponseJson
|
|
115
119
|
}
|
|
116
120
|
}
|
|
117
121
|
|
|
@@ -121,18 +125,26 @@ fileprivate extension CommandTraits {
|
|
|
121
125
|
static let interaction = CommandTraits(
|
|
122
126
|
isInteraction: true,
|
|
123
127
|
launchPolicy: .mayLaunch,
|
|
124
|
-
convertsRecordedFailure: true
|
|
128
|
+
convertsRecordedFailure: true,
|
|
129
|
+
retainsJournalResponseJson: true
|
|
125
130
|
)
|
|
126
131
|
|
|
127
132
|
|
|
128
133
|
|
|
129
134
|
|
|
130
135
|
|
|
131
|
-
static let appMutation = CommandTraits(
|
|
136
|
+
static let appMutation = CommandTraits(
|
|
137
|
+
launchPolicy: .mayLaunch, convertsRecordedFailure: true, retainsJournalResponseJson: true
|
|
138
|
+
)
|
|
132
139
|
|
|
133
140
|
|
|
134
141
|
|
|
135
|
-
static
|
|
142
|
+
static func appRead(retainsJournalResponseJson: Bool) -> CommandTraits {
|
|
143
|
+
CommandTraits(
|
|
144
|
+
retryOnSessionLoss: true, launchPolicy: .existingApp,
|
|
145
|
+
retainsJournalResponseJson: retainsJournalResponseJson
|
|
146
|
+
)
|
|
147
|
+
}
|
|
136
148
|
|
|
137
149
|
|
|
138
150
|
|
|
@@ -140,33 +152,41 @@ fileprivate extension CommandTraits {
|
|
|
140
152
|
|
|
141
153
|
static let selectorResolution = CommandTraits(
|
|
142
154
|
launchPolicy: .existingApp,
|
|
143
|
-
convertsRecordedFailure: true
|
|
155
|
+
convertsRecordedFailure: true,
|
|
156
|
+
retainsJournalResponseJson: true
|
|
144
157
|
)
|
|
145
158
|
|
|
146
159
|
|
|
147
160
|
|
|
148
|
-
static
|
|
161
|
+
static func runnerCaptureRead(retainsJournalResponseJson: Bool) -> CommandTraits {
|
|
162
|
+
CommandTraits(
|
|
163
|
+
retryOnSessionLoss: true, launchPolicy: .noApp,
|
|
164
|
+
retainsJournalResponseJson: retainsJournalResponseJson
|
|
165
|
+
)
|
|
166
|
+
}
|
|
149
167
|
|
|
150
168
|
|
|
151
|
-
static let runnerLifecycle = CommandTraits(launchPolicy: .noApp)
|
|
169
|
+
static let runnerLifecycle = CommandTraits(launchPolicy: .noApp, retainsJournalResponseJson: true)
|
|
152
170
|
|
|
153
171
|
|
|
154
172
|
|
|
155
173
|
|
|
156
|
-
static let deviceState = CommandTraits(launchPolicy: .noApp)
|
|
174
|
+
static let deviceState = CommandTraits(launchPolicy: .noApp, retainsJournalResponseJson: true)
|
|
157
175
|
|
|
158
176
|
|
|
159
177
|
|
|
160
178
|
|
|
161
179
|
static let presentedSurfaceMutation = CommandTraits(
|
|
162
180
|
launchPolicy: .presentedSurface,
|
|
163
|
-
convertsRecordedFailure: true
|
|
181
|
+
convertsRecordedFailure: true,
|
|
182
|
+
retainsJournalResponseJson: true
|
|
164
183
|
)
|
|
165
184
|
|
|
166
185
|
|
|
167
186
|
static let presentedSurfaceQuery = CommandTraits(
|
|
168
187
|
retryOnSessionLoss: true,
|
|
169
|
-
launchPolicy: .presentedSurface
|
|
188
|
+
launchPolicy: .presentedSurface,
|
|
189
|
+
retainsJournalResponseJson: true
|
|
170
190
|
)
|
|
171
191
|
}
|
|
172
192
|
|
|
@@ -243,13 +263,19 @@ extension Command {
|
|
|
243
263
|
.keyboardDismiss, .keyboardReturn, .sequence, .gesture:
|
|
244
264
|
return .interaction
|
|
245
265
|
|
|
246
|
-
case .findText, .readText, .
|
|
247
|
-
return .appRead
|
|
266
|
+
case .findText, .readText, .gestureViewport:
|
|
267
|
+
return .appRead(retainsJournalResponseJson: true)
|
|
268
|
+
|
|
269
|
+
case .snapshot:
|
|
270
|
+
return .appRead(retainsJournalResponseJson: false)
|
|
271
|
+
|
|
248
272
|
|
|
249
273
|
|
|
274
|
+
case .status, .appState:
|
|
275
|
+
return .runnerCaptureRead(retainsJournalResponseJson: true)
|
|
250
276
|
|
|
251
|
-
case .screenshot
|
|
252
|
-
return .runnerCaptureRead
|
|
277
|
+
case .screenshot:
|
|
278
|
+
return .runnerCaptureRead(retainsJournalResponseJson: false)
|
|
253
279
|
|
|
254
280
|
case .alert:
|
|
255
281
|
return (action ?? "get").lowercased() == "get"
|
|
@@ -29,7 +29,7 @@ public struct SnapshotRect: Codable, Equatable {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
public struct RawAXNode: Equatable {
|
|
32
|
-
public
|
|
32
|
+
public private(set) var index: Int
|
|
33
33
|
public let type: String
|
|
34
34
|
public let label: String?
|
|
35
35
|
public let identifier: String?
|
|
@@ -42,10 +42,10 @@ public struct RawAXNode: Equatable {
|
|
|
42
42
|
public let selected: Bool?
|
|
43
43
|
/// Geometric actionability; `nil` when the capture has no viewport box to decide it against.
|
|
44
44
|
public var hittable: Bool?
|
|
45
|
-
public
|
|
46
|
-
public
|
|
47
|
-
public
|
|
48
|
-
public
|
|
45
|
+
public private(set) var depth: Int
|
|
46
|
+
public private(set) var parentIndex: Int?
|
|
47
|
+
public private(set) var hiddenContentAbove: Bool?
|
|
48
|
+
public private(set) var hiddenContentBelow: Bool?
|
|
49
49
|
public var actions: [String]?
|
|
50
50
|
|
|
51
51
|
public init(
|
|
@@ -91,6 +91,21 @@ public struct RawAXNode: Equatable {
|
|
|
91
91
|
return updated
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
func reindexed(index: Int, depth: Int, parentIndex: Int?) -> RawAXNode {
|
|
95
|
+
var updated = self
|
|
96
|
+
updated.index = index
|
|
97
|
+
updated.depth = depth
|
|
98
|
+
updated.parentIndex = parentIndex
|
|
99
|
+
return updated
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
func addingHiddenContentHints(above: Bool, below: Bool) -> RawAXNode {
|
|
103
|
+
var updated = self
|
|
104
|
+
updated.hiddenContentAbove = hiddenContentAbove == true || above ? true : nil
|
|
105
|
+
updated.hiddenContentBelow = hiddenContentBelow == true || below ? true : nil
|
|
106
|
+
return updated
|
|
107
|
+
}
|
|
108
|
+
|
|
94
109
|
public var hasSemanticContent: Bool {
|
|
95
110
|
[label, identifier, value].contains {
|
|
96
111
|
!($0?.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty ?? true)
|
|
@@ -134,23 +134,10 @@ extension SnapshotPresentation {
|
|
|
134
134
|
return nodes.enumerated().map { offset, node in
|
|
135
135
|
let raw = node.raw
|
|
136
136
|
return SnapshotPresentationNode(
|
|
137
|
-
raw:
|
|
137
|
+
raw: raw.reindexed(
|
|
138
138
|
index: offset,
|
|
139
|
-
type: raw.type,
|
|
140
|
-
label: raw.label,
|
|
141
|
-
identifier: raw.identifier,
|
|
142
|
-
value: raw.value,
|
|
143
|
-
placeholder: raw.placeholder,
|
|
144
|
-
rect: raw.rect,
|
|
145
|
-
enabled: raw.enabled,
|
|
146
|
-
focused: raw.focused,
|
|
147
|
-
selected: raw.selected,
|
|
148
|
-
hittable: raw.hittable,
|
|
149
139
|
depth: max(0, raw.depth - depthOffset),
|
|
150
|
-
parentIndex: raw.parentIndex.flatMap { indexMap[$0] }
|
|
151
|
-
hiddenContentAbove: raw.hiddenContentAbove,
|
|
152
|
-
hiddenContentBelow: raw.hiddenContentBelow,
|
|
153
|
-
actions: raw.actions
|
|
140
|
+
parentIndex: raw.parentIndex.flatMap { indexMap[$0] }
|
|
154
141
|
),
|
|
155
142
|
effectiveRect: node.effectiveRect
|
|
156
143
|
)
|
|
@@ -191,33 +191,18 @@ public enum SnapshotVisibilityFold {
|
|
|
191
191
|
if decision.isIncluded {
|
|
192
192
|
let outIndex = kept.count
|
|
193
193
|
let outDepth = keptDepth + 1
|
|
194
|
+
var projected = node.reindexed(index: outIndex, depth: outDepth, parentIndex: keptIndex)
|
|
195
|
+
projected.hittable = node.parentIndex == nil
|
|
196
|
+
? false
|
|
197
|
+
: clippedHittability(
|
|
198
|
+
source: node.hittable,
|
|
199
|
+
enabled: node.enabled,
|
|
200
|
+
clippedFrame: decision.effectiveFrame,
|
|
201
|
+
viewport: viewport
|
|
202
|
+
)
|
|
194
203
|
kept.append(
|
|
195
204
|
SnapshotPresentationNode(
|
|
196
|
-
raw:
|
|
197
|
-
index: outIndex,
|
|
198
|
-
type: node.type,
|
|
199
|
-
label: node.label,
|
|
200
|
-
identifier: node.identifier,
|
|
201
|
-
value: node.value,
|
|
202
|
-
placeholder: node.placeholder,
|
|
203
|
-
rect: node.rect,
|
|
204
|
-
enabled: node.enabled,
|
|
205
|
-
focused: node.focused,
|
|
206
|
-
selected: node.selected,
|
|
207
|
-
hittable: node.parentIndex == nil
|
|
208
|
-
? false
|
|
209
|
-
: clippedHittability(
|
|
210
|
-
source: node.hittable,
|
|
211
|
-
enabled: node.enabled,
|
|
212
|
-
clippedFrame: decision.effectiveFrame,
|
|
213
|
-
viewport: viewport
|
|
214
|
-
),
|
|
215
|
-
depth: outDepth,
|
|
216
|
-
parentIndex: keptIndex,
|
|
217
|
-
hiddenContentAbove: node.hiddenContentAbove,
|
|
218
|
-
hiddenContentBelow: node.hiddenContentBelow,
|
|
219
|
-
actions: node.actions
|
|
220
|
-
),
|
|
205
|
+
raw: projected,
|
|
221
206
|
effectiveRect: SnapshotGeometry.snapshotRect(
|
|
222
207
|
from: decision.effectiveFrame,
|
|
223
208
|
reportedFrame: rect
|
|
@@ -73,24 +73,7 @@ extension SnapshotVisibilityFold {
|
|
|
73
73
|
let node = presentationNode.raw
|
|
74
74
|
guard let hint = hints[node.index] else { return presentationNode }
|
|
75
75
|
return SnapshotPresentationNode(
|
|
76
|
-
raw:
|
|
77
|
-
index: node.index,
|
|
78
|
-
type: node.type,
|
|
79
|
-
label: node.label,
|
|
80
|
-
identifier: node.identifier,
|
|
81
|
-
value: node.value,
|
|
82
|
-
placeholder: node.placeholder,
|
|
83
|
-
rect: node.rect,
|
|
84
|
-
enabled: node.enabled,
|
|
85
|
-
focused: node.focused,
|
|
86
|
-
selected: node.selected,
|
|
87
|
-
hittable: node.hittable,
|
|
88
|
-
depth: node.depth,
|
|
89
|
-
parentIndex: node.parentIndex,
|
|
90
|
-
hiddenContentAbove: node.hiddenContentAbove == true || hint.above ? true : nil,
|
|
91
|
-
hiddenContentBelow: node.hiddenContentBelow == true || hint.below ? true : nil,
|
|
92
|
-
actions: node.actions
|
|
93
|
-
),
|
|
76
|
+
raw: node.addingHiddenContentHints(above: hint.above, below: hint.below),
|
|
94
77
|
effectiveRect: presentationNode.effectiveRect
|
|
95
78
|
)
|
|
96
79
|
}
|
package/dist/src/adapter.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{N as e,V as t}from"./sdk-contracts.js";import{Jr as n,Yr as r,qr as i}from"./sdk-batch.js";import{c as a,r as o}from"./diagnostics.js";import{c as s,l as c,m as l}from"./exec.js";import"./diagnostics2.js";import"./command.js";import"./process.js";import{r as u}from"./version.js";import{f as d}from"./host-file.js";import{t as f}from"./apple-runner-platform.js";import{t as p}from"./simctl.js";import{a as m,c as ee,d as te,i as ne,l as re,n as ie,o as ae,r as oe,s as se,t as ce,u as le}from"./cache.js";import h from"node:path";import{createHash as g,randomUUID as _}from"node:crypto";import ue from"node:net";import{Buffer as v}from"node:buffer";const de={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 y=class extends e{failureKind;failureCode;constructor(e,t,n=`iOS Simulator snapshot source ${e}: ${t}`,r={},i){super(de[e],n,{...r,bridgeFailure:e,bridgeFailureCode:t,...e===`cancelled`?{reason:`request_canceled`}:{}},i),this.name=`SnapshotSourceError`,this.failureKind=e,this.failureCode=t}};function b(e,t,n={},r){return new y(e,t,void 0,n,r)}function x(e){return e instanceof ee?new y(e.buildFailureKind,e.buildFailureCode,void 0,e.buildDetails,e.cause):e}function S(n){return n instanceof y||(n=x(n),n instanceof y)?n:t(n)?b(`cancelled`,`abort-signal`,{},n):n instanceof e&&typeof n.details?.timeoutMs==`number`?b(`timeout`,`host-operation-timeout`,{timeoutMs:n.details.timeoutMs},n):b(`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 b(`cancelled`,`abort-signal`);return ae(e,t,n)}function w(e,t){try{return se(e,t)}catch(e){throw x(e)}}async function T(e,t,n,r){let i=Math.min(t,w(e,n));await te({waitMs:i,signal:e.signal,stop:r,cancelled:()=>b(`cancelled`,`abort-signal`)})}var fe=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 pe(){return{...m(async(e,t,n)=>await s(e,t,n)),projectRoot:u,homeDirectory:d,start:me,connect:he,emitDiagnostic:o,withDiagnosticTimer:a,readTargetProcessStartTime:re}}function me(e,t,n,r={}){if(r.signal?.aborted)throw b(`cancelled`,`abort-signal`);let i=c(`xcrun`,p(e,[`spawn`,e.udid,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 b(`transport-failure`,`bridge-process-pid-missing`);let o=``;return i.child.stderr?.setEncoding(`utf8`),i.child.stderr?.on(`data`,e=>{o=ge(o,String(e))}),{pid:a,wait:i.wait,isAlive:()=>i.child.exitCode===null&&i.child.signalCode===null,signal:e=>{l(a,e)||i.child.kill(e)},readLog:()=>o}}async function he(e,t){if(t.signal?.aborted)throw b(`cancelled`,`abort-signal`);let n=Math.max(1,Math.floor(t.timeoutMs));return await new Promise((r,i)=>{let a=ue.createConnection({path:e}),o=!1,s=!1,c=setTimeout(()=>{p(b(`timeout`,`bridge-connect-timeout`)),a.destroy()},n),l=()=>{p(b(`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(b(`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()})}function ge(e,t){let n=e+t;return n.length<=E?n:n.slice(n.length-E)}function _e(e,t,n){let r=g(`sha256`).update(t).digest(`hex`).slice(0,12),i=g(`sha256`).update(n).digest(`hex`).slice(0,12);return h.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:ve(t.readLog())}})),b(`process-crash`,`bridge-exited`,{pid:t.pid,...n===void 0?{}:{exitCode:n}})}function ve(e){let t=v.from(e);return t.length<=65536?e:t.subarray(-65536).toString(`utf8`)}const k=`agent-device-simulator-ax-v1.8.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_kAXXCAttributePlaceholderValue`,`XC_kAXXCAttributeIdentifier`,`XC_kAXXCAttributeFrame`,`XC_kAXXCAttributeAutomationType`,`XC_kAXXCAttributeTraits`,`XC_kAXXCAttributeIsUserInteractionEnabled`,`XC_kAXXCAttributeChildren`]);const ye=[`requests`,`rejected`,`continuations`,`acceptedLevels`];function A(e){let t=e.recovery;if(!F(t))throw b(`malformed-tree`,`recovery-invalid`);let n=ye.map(e=>[e,t[e]]);if(n.some(([,e])=>!Number.isSafeInteger(e)||e<0))throw b(`malformed-tree`,`recovery-invalid`);return Object.freeze(Object.fromEntries(n))}function j(e,t){let n;try{n=v.from(JSON.stringify(e),`utf8`)}catch(e){throw b(`malformed-tree`,`request-not-json`,{},e)}let r=n.length+4;if(r>t.maxRequestBytes)throw b(`transport-failure`,`request-limit-exceeded`,{frameBytes:r,maxRequestBytes:t.maxRequestBytes});let i=v.alloc(4);return i.writeUInt32BE(n.length,0),v.concat([i,n])}var M=class{header=v.alloc(4);headerBytes=0;chunks=[];payloadBytes=0;expectedBodyBytes;frame;maxFrameBytes;constructor(e){if(!Number.isSafeInteger(e)||e<=0)throw b(`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=v.concat(this.chunks,t.bodyBytes),this.frame}acceptTrailingChunk(e){if(e.length>0)throw b(`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 b(`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 b(`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 b(`transport-failure`,`bridge-frame-incomplete`,{headerBytes:this.headerBytes,payloadBytes:this.payloadBytes,expectedBodyBytes:this.expectedBodyBytes})}};function N(e){let t;try{t=JSON.parse(e.toString(`utf8`))}catch(e){throw b(`malformed-tree`,`response-not-json`,{},e)}if(!F(t))throw b(`malformed-tree`,`response-not-object`);return t}function P(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 be(e,t){if(e.protocolVersion!==1)throw b(`transport-failure`,`protocol-version-mismatch`,{expected:1,observed:e.protocolVersion});if(e.sourceVersion!==`agent-device-simulator-ax-v1.8.0`)throw b(`transport-failure`,`source-version-mismatch`,{expected:k,observed:e.sourceVersion});if(e.requestId!==t)throw b(`transport-failure`,`request-id-mismatch`,{expected:t,observed:e.requestId})}function xe(e,t){if(typeof e.pid!=`number`||e.pid!==t.pid)throw b(`stale-target`,`bridge-pid-mismatch`,{expectedPid:t.pid,observedPid:e.pid});if(e.generation!==t.generation)throw b(`stale-target`,`bridge-generation-mismatch`,{expectedGeneration:t.generation,observedGeneration:e.generation})}function Se(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 b(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 F(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}async function Ce(e){let t=new M(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(b(`timeout`,`bridge-request-deadline`,{dispatched:o})),e.socket.destroy()},n),c=()=>{p(b(`cancelled`,`abort-signal`,{dispatched:o})),e.socket.destroy()},l=n=>{try{if(!Buffer.isBuffer(n))throw b(`transport-failure`,`bridge-data-invalid`);let r=t.push(n);if(r){let t=N(r);if(be(t,e.requestId),xe(t,{pid:e.expectedPid,generation:e.expectedGeneration}),t.ok!==!0&&Se(t),typeof t.truncated!=`boolean`)throw b(`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(b(`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 b(`cancelled`,`abort-signal`);o=!0,e.socket.write(e.frame)}catch(t){p(S(t)),e.socket.destroy()}})}var we=class{sessions=new Map;requestQueues=new Map;ownerId=_();closed=!1;host;constructor(e){this.host=e}async request(e){if(this.closed)throw b(`unsupported`,`source-closed`);return await this.withSimulatorLock(e.target.simulator.udid,e.deadline,()=>this.requestInSimulator(e))}async requestInSimulator(e){if(this.closed)throw b(`unsupported`,`source-closed`);let t=e.deadline;w(t,`bridge-request-deadline`);let n=this.sessions.get(e.target.simulator.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 Ee(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 Te(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.simulator.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=_e(this.host,e.target.simulator.udid,this.ownerId);await this.host.ensureDirectory(h.dirname(i)),await this.host.remove(i);let a=this.host.start(e.target.simulator,e.bridge.path,i,{signal:t.signal}),o={udid:e.target.simulator.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 y&&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 y&&n.failureKind===`timeout`)throw n}}async exchange(e,t,n){(!e.socket||e.socket.destroyed)&&(e.socket=await this.connectUntilReady(e,n));let r=_(),i=j(P({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 Ce({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 b(`stale-target`,`target-process-unavailable`,{pid:e.pid,generation:e.generation});if(e.processStartTime!==void 0&&e.processStartTime!==n)throw b(`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 b(`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 I(e.process,500),e.process.isAlive()&&(e.process.signal(`SIGKILL`),await I(e.process,500))),await this.host.remove(e.socketPath)}};async function Te(e,t){let n=w(t,`bridge-request-deadline`);await Promise.race([e,T(t,n,`bridge-request-deadline`).then(()=>{throw b(`timeout`,`bridge-request-deadline`)})])}function Ee(e,t,n){return(e.failureKind===`cancelled`||e.failureKind===`timeout`)&&(e.details?.dispatched===!0||n!==t)}async function I(e,t){await Promise.race([e.wait.catch(()=>void 0),new Promise(e=>setTimeout(e,t))])}const L=16777216,R=12e4,z=1e4,De=Object.freeze({maxRequestBytes:65536,maxResponseBytes:4194304,maxNodes:5e3,maxTraversalDepth:64,maxDurationMs:5e3});function B(t){let n={...De,...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>L||n.maxResponseBytes>L)throw new e(`INVALID_ARGS`,`Snapshot source frame limits exceed the bridge bound`,{maxRequestBytes:n.maxRequestBytes,maxResponseBytes:n.maxResponseBytes,maximumFrameBytes:L});if(n.maxNodes>z||n.maxTraversalDepth>128)throw new e(`INVALID_ARGS`,`Snapshot source tree limits exceed the bridge bound`,{maxNodes:n.maxNodes,maxTraversalDepth:n.maxTraversalDepth,maximumNodes:z,maximumDepth:128});if(n.maxDurationMs>R)throw new e(`INVALID_ARGS`,`Snapshot source duration exceeds the bridge bound`,{maxDurationMs:n.maxDurationMs,maximumDurationMs:R});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 V=[`SnapshotBridge.m`,`SnapshotBridgeRuntime.m`,`SnapshotBridgeRuntime.h`,`SnapshotBridgeCapture.h`,`SnapshotBridgeCapture.m`],Oe=[`SnapshotBridge.m`,`SnapshotBridgeRuntime.m`,`SnapshotBridgeCapture.m`];async function ke(e,t,n){let r=await ne(e,n).catch(e=>{throw x(e)}),i=t.trim();if(!i)throw b(`unsupported`,`simulator-runtime-missing`);return{...r,simulatorRuntime:i}}const H=12e4;async function Ae(e){let t=e.deadline,n=e.sourceRoot??je(e.host);try{let r=await oe(e.host,n,V,t),i=await ke(e.host,e.runtime,t),a=e.cacheRoot??h.join(e.host.homeDirectory(),`.agent-device`,`snapshot-source`),o=await ce({host:e.host,deadline:t,cacheRoot:a,binaryFilename:`snapshot-bridge`,lockDescription:`iOS Simulator snapshot bridge cache`,keyInputs:{schemaVersion:1,protocolVersion:1,sourceVersion:k,sourceHash:r,toolchain:i,compileArgv:U({architecture:i.architecture,sourceRoot:``,outputPath:``})},build:async r=>{let a=await ie({host:e.host,deadline:t,argv:U({architecture:i.architecture,sourceRoot:n,outputPath:r}),budgetMs:H,label:`bridge`});if(a.exitCode!==0||!e.host.exists(r))throw b(`unsupported`,`native-build-failed`,{exitCode:a.exitCode,stderr:a.stderr.slice(0,4096)})}});return{path:o.path,sourceHash:r,cacheKey:o.cacheKey,protocolVersion:1,sourceVersion:k}}catch(e){throw x(e)}}function U(e){return[`--sdk`,`iphonesimulator`,`clang`,`-arch`,e.architecture,`-mios-simulator-version-min=15.0`,`-fobjc-arc`,`-Wall`,`-Wextra`,`-framework`,`Foundation`,`-framework`,`CoreGraphics`,...Oe.map(t=>h.join(e.sourceRoot,t)),`-o`,e.outputPath]}function je(e){let t=e.projectRoot(),n=h.join(t,`apple`,`snapshot-bridge`);if(V.every(t=>e.exists(h.join(n,t))))return n;let r=h.join(t,`dist`,`apple`,`snapshot-bridge`);if(V.every(t=>e.exists(h.join(r,t))))return r;throw b(`unsupported`,`native-source-missing`,{projectRoot:t})}const Me=f+H;function Ne(e){let t=e.now??Date.now,n=new Map,r=le({waitMs:2e3,waitGrant:`first-caller`,retryAfterMs:6e4,now:t}),i=async(r,i)=>{let a=C(Me,i,t);try{let t=await e.host.withDiagnosticTimer(`ios.snapshot-source.prepare`,async()=>await Ae({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:()=>b(`preparing`,`bridge-preparation-pending`)}),close:()=>{n.clear(),r.close()}}}function Pe(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`,placeholder:`XC_kAXXCAttributePlaceholderValue`,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`},Fe=new Set(Object.values(W)),Ie=1n<<8n,Le=1n<<3n,Re={x:0,y:0,width:0,height:0};function ze(e,t,n){let r=Array.isArray(e)?e:[e];if(r.length===0||r.some(e=>!F(e)))throw b(`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 b(`malformed-tree`,`node-limit-exceeded`,{nodeCount:i.length,maxNodes:n.maxNodes});if(o>n.maxTraversalDepth)throw b(`malformed-tree`,`traversal-depth-exceeded`,{maxTraversalDepth:o,maxAllowedDepth:n.maxTraversalDepth});if(typeof t.truncated!=`boolean`)throw b(`malformed-tree`,`truncated-invalid`);let s=We(i.filter(J)[0]);return s.kind===`reported`&&Ge(i,s.rect),{nodes:i,maxTraversalDepth:o,viewport:s,opaqueRemoteElements:a.filter(e=>He(e,s)).length,unresolvedCoordinateSpaceWindows:Y(i,s)};function c(e,t,r,s){if(i.length>=n.maxNodes)throw b(`malformed-tree`,`node-limit-exceeded`,{maxNodes:n.maxNodes});for(let t of Object.keys(e))if(!Fe.has(t))throw b(`malformed-tree`,`node-contains-unknown-field`,{key:t});let l=e[W.children];if(!Array.isArray(l))throw b(`malformed-tree`,`children-invalid`);let u=i.length,d=Be(e,u,t,r);i.push(d),o=Math.max(o,r),Ve(d,l.length,s)&&a.push(d.rect);let f=s||d.type===`WebView`;for(let e of l){if(!F(e))throw b(`malformed-tree`,`child-invalid`);c(e,u,r+1,f)}}}function Be(e,t,n,r){let i=X(e[W.elementType]),a=X(e[W.elementBaseType]),o=Ye(e[W.automationType]),s=Ue(e[W.frame]),c=qe(e[W.traits]),l=c===void 0?void 0:(c&Ie)===0n,u=c===void 0||(c&Le)===0n?void 0:!0,d=Je(e[W.userInteractionEnabled]),f=X(e[W.placeholder])?.trim();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])}:{},...f?{placeholder:f}:{},...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 Ve(e,t,n){return n&&e.role===`AXRemoteElement`&&t===0}function He(e,t){return e===void 0?!0:n(e)?t.kind!==`reported`||r(e,t.rect):!1}function Ue(e){if(e===void 0)return;if(!F(e))throw b(`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 b(`malformed-tree`,`frame-invalid`);let[n,r,i,a]=t;if(i<0||a<0)throw b(`malformed-tree`,`frame-invalid`);return{x:n,y:r,width:i,height:a}}function We(e){return!e||!J(e)?{kind:`missing`,reason:`not-provided`}:n(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 Ge(e,t){for(let n of e)n.hittable=n.parentIndex!==void 0&&i(n.enabled!==!1,n.rect,t)}function Y(e,t){return t.kind===`reported`?e.filter(n=>Ke(n,e)&&Pe(n.rect??Re,t.rect)).length:0}function Ke(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 b(`malformed-tree`,`scalar-invalid`)}function qe(e){if(e!=null){if(typeof e!=`string`||!/^\d{1,20}$/.test(e))throw b(`malformed-tree`,`traits-invalid`);return BigInt(e)}}function Je(e){if(e!=null){if(typeof e!=`boolean`)throw b(`malformed-tree`,`user-interaction-invalid`);return e}}function Ye(e){if(e!=null){if(!Number.isSafeInteger(e))throw b(`malformed-tree`,`automation-type-invalid`);return e}}const Q=`simulator-ax-bridge`;function Xe(e={}){let t=e.host??pe(),n=new we(t),r=new fe,i=Ne({host:t,limits:B(e.limits),producer:Q,sourceRoot:e.sourceRoot,cacheRoot:e.cacheRoot}),a=!1;return{acquire:async o=>{try{if(a)throw b(`unsupported`,`source-closed`);Ze(o);let s=B({...e.limits,...o.limits}),c=C(s.maxDurationMs,o.signal),l=$e(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=et(o.hint,o.target,f,s);return Qe(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 Ze(t){if(!t.target.simulator.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 Qe(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 $e(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 et(e,t,n,r){if(n.automationEnabled!==!0)throw b(`unsupported`,`automation-mode-unavailable`);let i=n.tree,a=n.truncated;if(typeof a!=`boolean`)throw b(`malformed-tree`,`truncated-invalid`);let o=ze(i,{truncated:a},r),s=n.generation;if(typeof s!=`string`||!s)throw b(`malformed-tree`,`generation-invalid`);if(o.opaqueRemoteElements>0)throw b(`unsupported`,`remote-content-boundary`,{remoteElements:o.opaqueRemoteElements});if(o.unresolvedCoordinateSpaceWindows>0)throw b(`unsupported`,`window-coordinate-space-unresolved`,{windows:o.unresolvedCoordinateSpaceWindows});let c=Object.freeze(o.nodes.map(e=>Object.freeze({...e,pid:t.pid}))),l=tt(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 tt(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{Xe as createSimulatorSnapshotSource};
|
|
1
|
+
import{G as e,N as t}from"./sdk-contracts.js";import{Jr as n,Xr as r,Yr as i}from"./sdk-batch.js";import{c as a,r as o}from"./diagnostics.js";import{h as s,l as c,u as l}from"./exec.js";import"./diagnostics2.js";import"./command.js";import"./process.js";import{r as u}from"./version.js";import{f as d}from"./host-file.js";import{t as f}from"./apple-runner-platform.js";import{t as p}from"./simctl.js";import{a as m,c as ee,d as te,i as ne,l as re,n as ie,o as ae,r as oe,s as se,t as ce,u as le}from"./cache.js";import h from"node:path";import{createHash as g,randomUUID as _}from"node:crypto";import ue from"node:net";import{Buffer as v}from"node:buffer";const de={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 y=class extends t{failureKind;failureCode;constructor(e,t,n=`iOS Simulator snapshot source ${e}: ${t}`,r={},i){super(de[e],n,{...r,bridgeFailure:e,bridgeFailureCode:t,...e===`cancelled`?{reason:`request_canceled`}:{}},i),this.name=`SnapshotSourceError`,this.failureKind=e,this.failureCode=t}};function b(e,t,n={},r){return new y(e,t,void 0,n,r)}function x(e){return e instanceof ee?new y(e.buildFailureKind,e.buildFailureCode,void 0,e.buildDetails,e.cause):e}function S(n){return n instanceof y||(n=x(n),n instanceof y)?n:e(n)?b(`cancelled`,`abort-signal`,{},n):n instanceof t&&typeof n.details?.timeoutMs==`number`?b(`timeout`,`host-operation-timeout`,{timeoutMs:n.details.timeoutMs},n):b(`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 b(`cancelled`,`abort-signal`);return ae(e,t,n)}function w(e,t){try{return se(e,t)}catch(e){throw x(e)}}async function T(e,t,n,r){let i=Math.min(t,w(e,n));await te({waitMs:i,signal:e.signal,stop:r,cancelled:()=>b(`cancelled`,`abort-signal`)})}var fe=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 pe(){return{...m(async(e,t,n)=>await c(e,t,n)),projectRoot:u,homeDirectory:d,start:me,connect:he,emitDiagnostic:o,withDiagnosticTimer:a,readTargetProcessStartTime:re}}function me(e,t,n,r={}){if(r.signal?.aborted)throw b(`cancelled`,`abort-signal`);let i=l(`xcrun`,p(e,[`spawn`,e.udid,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 b(`transport-failure`,`bridge-process-pid-missing`);let o=``;return i.child.stderr?.setEncoding(`utf8`),i.child.stderr?.on(`data`,e=>{o=ge(o,String(e))}),{pid:a,wait:i.wait,isAlive:()=>i.child.exitCode===null&&i.child.signalCode===null,signal:e=>{s(a,e)||i.child.kill(e)},readLog:()=>o}}async function he(e,t){if(t.signal?.aborted)throw b(`cancelled`,`abort-signal`);let n=Math.max(1,Math.floor(t.timeoutMs));return await new Promise((r,i)=>{let a=ue.createConnection({path:e}),o=!1,s=!1,c=setTimeout(()=>{p(b(`timeout`,`bridge-connect-timeout`)),a.destroy()},n),l=()=>{p(b(`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(b(`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()})}function ge(e,t){let n=e+t;return n.length<=E?n:n.slice(n.length-E)}function _e(e,t,n){let r=g(`sha256`).update(t).digest(`hex`).slice(0,12),i=g(`sha256`).update(n).digest(`hex`).slice(0,12);return h.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:ve(t.readLog())}})),b(`process-crash`,`bridge-exited`,{pid:t.pid,...n===void 0?{}:{exitCode:n}})}function ve(e){let t=v.from(e);return t.length<=65536?e:t.subarray(-65536).toString(`utf8`)}const k=`agent-device-simulator-ax-v1.8.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_kAXXCAttributePlaceholderValue`,`XC_kAXXCAttributeIdentifier`,`XC_kAXXCAttributeFrame`,`XC_kAXXCAttributeAutomationType`,`XC_kAXXCAttributeTraits`,`XC_kAXXCAttributeIsUserInteractionEnabled`,`XC_kAXXCAttributeChildren`]);const ye=[`requests`,`rejected`,`continuations`,`acceptedLevels`];function A(e){let t=e.recovery;if(!F(t))throw b(`malformed-tree`,`recovery-invalid`);let n=ye.map(e=>[e,t[e]]);if(n.some(([,e])=>!Number.isSafeInteger(e)||e<0))throw b(`malformed-tree`,`recovery-invalid`);return Object.freeze(Object.fromEntries(n))}function j(e,t){let n;try{n=v.from(JSON.stringify(e),`utf8`)}catch(e){throw b(`malformed-tree`,`request-not-json`,{},e)}let r=n.length+4;if(r>t.maxRequestBytes)throw b(`transport-failure`,`request-limit-exceeded`,{frameBytes:r,maxRequestBytes:t.maxRequestBytes});let i=v.alloc(4);return i.writeUInt32BE(n.length,0),v.concat([i,n])}var M=class{header=v.alloc(4);headerBytes=0;chunks=[];payloadBytes=0;expectedBodyBytes;frame;maxFrameBytes;constructor(e){if(!Number.isSafeInteger(e)||e<=0)throw b(`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=v.concat(this.chunks,t.bodyBytes),this.frame}acceptTrailingChunk(e){if(e.length>0)throw b(`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 b(`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 b(`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 b(`transport-failure`,`bridge-frame-incomplete`,{headerBytes:this.headerBytes,payloadBytes:this.payloadBytes,expectedBodyBytes:this.expectedBodyBytes})}};function N(e){let t;try{t=JSON.parse(e.toString(`utf8`))}catch(e){throw b(`malformed-tree`,`response-not-json`,{},e)}if(!F(t))throw b(`malformed-tree`,`response-not-object`);return t}function P(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 be(e,t){if(e.protocolVersion!==1)throw b(`transport-failure`,`protocol-version-mismatch`,{expected:1,observed:e.protocolVersion});if(e.sourceVersion!==`agent-device-simulator-ax-v1.8.0`)throw b(`transport-failure`,`source-version-mismatch`,{expected:k,observed:e.sourceVersion});if(e.requestId!==t)throw b(`transport-failure`,`request-id-mismatch`,{expected:t,observed:e.requestId})}function xe(e,t){if(typeof e.pid!=`number`||e.pid!==t.pid)throw b(`stale-target`,`bridge-pid-mismatch`,{expectedPid:t.pid,observedPid:e.pid});if(e.generation!==t.generation)throw b(`stale-target`,`bridge-generation-mismatch`,{expectedGeneration:t.generation,observedGeneration:e.generation})}function Se(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 b(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 F(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}async function Ce(e){let t=new M(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(b(`timeout`,`bridge-request-deadline`,{bridgeRequestSent:o})),e.socket.destroy()},n),c=()=>{p(b(`cancelled`,`abort-signal`,{bridgeRequestSent:o})),e.socket.destroy()},l=n=>{try{if(!Buffer.isBuffer(n))throw b(`transport-failure`,`bridge-data-invalid`);let r=t.push(n);if(r){let t=N(r);if(be(t,e.requestId),xe(t,{pid:e.expectedPid,generation:e.expectedGeneration}),t.ok!==!0&&Se(t),typeof t.truncated!=`boolean`)throw b(`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(b(`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 b(`cancelled`,`abort-signal`);o=!0,e.socket.write(e.frame)}catch(t){p(S(t)),e.socket.destroy()}})}var we=class{sessions=new Map;requestQueues=new Map;ownerId=_();closed=!1;host;constructor(e){this.host=e}async request(e){if(this.closed)throw b(`unsupported`,`source-closed`);return await this.withSimulatorLock(e.target.simulator.udid,e.deadline,()=>this.requestInSimulator(e))}async requestInSimulator(e){if(this.closed)throw b(`unsupported`,`source-closed`);let t=e.deadline;w(t,`bridge-request-deadline`);let n=this.sessions.get(e.target.simulator.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 Ee(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 Te(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.simulator.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=_e(this.host,e.target.simulator.udid,this.ownerId);await this.host.ensureDirectory(h.dirname(i)),await this.host.remove(i);let a=this.host.start(e.target.simulator,e.bridge.path,i,{signal:t.signal}),o={udid:e.target.simulator.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 y&&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 y&&n.failureKind===`timeout`)throw n}}async exchange(e,t,n){(!e.socket||e.socket.destroyed)&&(e.socket=await this.connectUntilReady(e,n));let r=_(),i=j(P({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 Ce({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 b(`stale-target`,`target-process-unavailable`,{pid:e.pid,generation:e.generation});if(e.processStartTime!==void 0&&e.processStartTime!==n)throw b(`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 b(`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 I(e.process,500),e.process.isAlive()&&(e.process.signal(`SIGKILL`),await I(e.process,500))),await this.host.remove(e.socketPath)}};async function Te(e,t){let n=w(t,`bridge-request-deadline`);await Promise.race([e,T(t,n,`bridge-request-deadline`).then(()=>{throw b(`timeout`,`bridge-request-deadline`)})])}function Ee(e,t,n){return(e.failureKind===`cancelled`||e.failureKind===`timeout`)&&(e.details?.bridgeRequestSent===!0||n!==t)}async function I(e,t){await Promise.race([e.wait.catch(()=>void 0),new Promise(e=>setTimeout(e,t))])}const L=16777216,R=12e4,z=1e4,De=Object.freeze({maxRequestBytes:65536,maxResponseBytes:4194304,maxNodes:5e3,maxTraversalDepth:64,maxDurationMs:5e3});function B(e){let n={...De,...e??{}};for(let[e,r]of Object.entries(n))if(!Number.isSafeInteger(r)||r<=0)throw new t(`INVALID_ARGS`,`Snapshot source limit ${e} must be a positive integer`,{name:e,value:r});if(n.maxRequestBytes>n.maxResponseBytes)throw new t(`INVALID_ARGS`,`Snapshot source request bytes cannot exceed response bytes`,{maxRequestBytes:n.maxRequestBytes,maxResponseBytes:n.maxResponseBytes});if(n.maxRequestBytes>L||n.maxResponseBytes>L)throw new t(`INVALID_ARGS`,`Snapshot source frame limits exceed the bridge bound`,{maxRequestBytes:n.maxRequestBytes,maxResponseBytes:n.maxResponseBytes,maximumFrameBytes:L});if(n.maxNodes>z||n.maxTraversalDepth>128)throw new t(`INVALID_ARGS`,`Snapshot source tree limits exceed the bridge bound`,{maxNodes:n.maxNodes,maxTraversalDepth:n.maxTraversalDepth,maximumNodes:z,maximumDepth:128});if(n.maxDurationMs>R)throw new t(`INVALID_ARGS`,`Snapshot source duration exceeds the bridge bound`,{maxDurationMs:n.maxDurationMs,maximumDurationMs:R});if(n.maxRequestBytes<=4||n.maxResponseBytes<=4)throw new t(`INVALID_ARGS`,`Snapshot source frame limits must leave room for a body`,{maxRequestBytes:n.maxRequestBytes,maxResponseBytes:n.maxResponseBytes});return Object.freeze(n)}const V=[`SnapshotBridge.m`,`SnapshotBridgeRuntime.m`,`SnapshotBridgeRuntime.h`,`SnapshotBridgeCapture.h`,`SnapshotBridgeCapture.m`],Oe=[`SnapshotBridge.m`,`SnapshotBridgeRuntime.m`,`SnapshotBridgeCapture.m`];async function ke(e,t,n){let r=await ne(e,n).catch(e=>{throw x(e)}),i=t.trim();if(!i)throw b(`unsupported`,`simulator-runtime-missing`);return{...r,simulatorRuntime:i}}const H=12e4;async function Ae(e){let t=e.deadline,n=e.sourceRoot??je(e.host);try{let r=await oe(e.host,n,V,t),i=await ke(e.host,e.runtime,t),a=e.cacheRoot??h.join(e.host.homeDirectory(),`.agent-device`,`snapshot-source`),o=await ce({host:e.host,deadline:t,cacheRoot:a,binaryFilename:`snapshot-bridge`,lockDescription:`iOS Simulator snapshot bridge cache`,keyInputs:{schemaVersion:1,protocolVersion:1,sourceVersion:k,sourceHash:r,toolchain:i,compileArgv:U({architecture:i.architecture,sourceRoot:``,outputPath:``})},build:async r=>{let a=await ie({host:e.host,deadline:t,argv:U({architecture:i.architecture,sourceRoot:n,outputPath:r}),budgetMs:H,label:`bridge`});if(a.exitCode!==0||!e.host.exists(r))throw b(`unsupported`,`native-build-failed`,{exitCode:a.exitCode,stderr:a.stderr.slice(0,4096)})}});return{path:o.path,sourceHash:r,cacheKey:o.cacheKey,protocolVersion:1,sourceVersion:k}}catch(e){throw x(e)}}function U(e){return[`--sdk`,`iphonesimulator`,`clang`,`-arch`,e.architecture,`-mios-simulator-version-min=15.0`,`-fobjc-arc`,`-Wall`,`-Wextra`,`-framework`,`Foundation`,`-framework`,`CoreGraphics`,...Oe.map(t=>h.join(e.sourceRoot,t)),`-o`,e.outputPath]}function je(e){let t=e.projectRoot(),n=h.join(t,`apple`,`snapshot-bridge`);if(V.every(t=>e.exists(h.join(n,t))))return n;let r=h.join(t,`dist`,`apple`,`snapshot-bridge`);if(V.every(t=>e.exists(h.join(r,t))))return r;throw b(`unsupported`,`native-source-missing`,{projectRoot:t})}const Me=f+H;function Ne(e){let t=e.now??Date.now,n=new Map,r=le({waitMs:2e3,waitGrant:`first-caller`,retryAfterMs:6e4,now:t}),i=async(r,i)=>{let a=C(Me,i,t);try{let t=await e.host.withDiagnosticTimer(`ios.snapshot-source.prepare`,async()=>await Ae({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:()=>b(`preparing`,`bridge-preparation-pending`)}),close:()=>{n.clear(),r.close()}}}function Pe(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`,placeholder:`XC_kAXXCAttributePlaceholderValue`,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`},Fe=new Set(Object.values(W)),Ie=1n<<8n,Le=1n<<3n,Re={x:0,y:0,width:0,height:0};function ze(e,t,n){let r=Array.isArray(e)?e:[e];if(r.length===0||r.some(e=>!F(e)))throw b(`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 b(`malformed-tree`,`node-limit-exceeded`,{nodeCount:i.length,maxNodes:n.maxNodes});if(o>n.maxTraversalDepth)throw b(`malformed-tree`,`traversal-depth-exceeded`,{maxTraversalDepth:o,maxAllowedDepth:n.maxTraversalDepth});if(typeof t.truncated!=`boolean`)throw b(`malformed-tree`,`truncated-invalid`);let s=We(i.filter(J)[0]);return s.kind===`reported`&&Ge(i,s.rect),{nodes:i,maxTraversalDepth:o,viewport:s,opaqueRemoteElements:a.filter(e=>He(e,s)).length,unresolvedCoordinateSpaceWindows:Y(i,s)};function c(e,t,r,s){if(i.length>=n.maxNodes)throw b(`malformed-tree`,`node-limit-exceeded`,{maxNodes:n.maxNodes});for(let t of Object.keys(e))if(!Fe.has(t))throw b(`malformed-tree`,`node-contains-unknown-field`,{key:t});let l=e[W.children];if(!Array.isArray(l))throw b(`malformed-tree`,`children-invalid`);let u=i.length,d=Be(e,u,t,r);i.push(d),o=Math.max(o,r),Ve(d,l.length,s)&&a.push(d.rect);let f=s||d.type===`WebView`;for(let e of l){if(!F(e))throw b(`malformed-tree`,`child-invalid`);c(e,u,r+1,f)}}}function Be(e,t,n,r){let i=X(e[W.elementType]),a=X(e[W.elementBaseType]),o=Ye(e[W.automationType]),s=Ue(e[W.frame]),c=qe(e[W.traits]),l=c===void 0?void 0:(c&Ie)===0n,u=c===void 0||(c&Le)===0n?void 0:!0,d=Je(e[W.userInteractionEnabled]),f=X(e[W.placeholder])?.trim();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])}:{},...f?{placeholder:f}:{},...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 Ve(e,t,n){return n&&e.role===`AXRemoteElement`&&t===0}function He(e,t){return e===void 0?!0:i(e)?t.kind!==`reported`||r(e,t.rect):!1}function Ue(e){if(e===void 0)return;if(!F(e))throw b(`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 b(`malformed-tree`,`frame-invalid`);let[n,r,i,a]=t;if(i<0||a<0)throw b(`malformed-tree`,`frame-invalid`);return{x:n,y:r,width:i,height:a}}function We(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 Ge(e,t){for(let r of e)r.hittable=r.parentIndex!==void 0&&n(r.enabled!==!1,r.rect,t)}function Y(e,t){return t.kind===`reported`?e.filter(n=>Ke(n,e)&&Pe(n.rect??Re,t.rect)).length:0}function Ke(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 b(`malformed-tree`,`scalar-invalid`)}function qe(e){if(e!=null){if(typeof e!=`string`||!/^\d{1,20}$/.test(e))throw b(`malformed-tree`,`traits-invalid`);return BigInt(e)}}function Je(e){if(e!=null){if(typeof e!=`boolean`)throw b(`malformed-tree`,`user-interaction-invalid`);return e}}function Ye(e){if(e!=null){if(!Number.isSafeInteger(e))throw b(`malformed-tree`,`automation-type-invalid`);return e}}const Q=`simulator-ax-bridge`;function Xe(e={}){let t=e.host??pe(),n=new we(t),r=new fe,i=Ne({host:t,limits:B(e.limits),producer:Q,sourceRoot:e.sourceRoot,cacheRoot:e.cacheRoot}),a=!1;return{acquire:async o=>{try{if(a)throw b(`unsupported`,`source-closed`);Ze(o);let s=B({...e.limits,...o.limits}),c=C(s.maxDurationMs,o.signal),l=$e(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=et(o.hint,o.target,f,s);return Qe(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 Ze(e){if(!e.target.simulator.udid.trim()||!e.target.runtime.trim()||!e.target.generation.trim()||!Number.isSafeInteger(e.target.pid)||e.target.pid<=0)throw new t(`INVALID_ARGS`,`Simulator snapshot source target identity is incomplete`);let n=e.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 t(`INVALID_ARGS`,`Simulator snapshot source capture hint is invalid`)}function Qe(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 $e(e,n){let r=e.rawTraversalDepth??n;if(r>n)throw new t(`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 et(e,t,n,r){if(n.automationEnabled!==!0)throw b(`unsupported`,`automation-mode-unavailable`);let i=n.tree,a=n.truncated;if(typeof a!=`boolean`)throw b(`malformed-tree`,`truncated-invalid`);let o=ze(i,{truncated:a},r),s=n.generation;if(typeof s!=`string`||!s)throw b(`malformed-tree`,`generation-invalid`);if(o.opaqueRemoteElements>0)throw b(`unsupported`,`remote-content-boundary`,{remoteElements:o.opaqueRemoteElements});if(o.unresolvedCoordinateSpaceWindows>0)throw b(`unsupported`,`window-coordinate-space-unresolved`,{windows:o.unresolvedCoordinateSpaceWindows});let c=Object.freeze(o.nodes.map(e=>Object.freeze({...e,pid:t.pid}))),l=tt(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 tt(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{Xe as createSimulatorSnapshotSource};
|
package/dist/src/adb-executor.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{N as e}from"./sdk-contracts.js";import{n as t,r as n,t as r}from"./device-shell.js";import{a as i,d as a,f as o,i as s,l as c,m as l,n as u,p as d,s as f,u as p}from"./adb-transport.js";import{
|
|
2
|
-
`).map(e=>e.trim().split(/\s+/)).filter(e=>e.length>=3).map(([,e,t])=>{let r=e;return{local:r,remote:t,ownerId:n.get(r)}})}function re(e,t){let n=`${e}\n${t}`.toLowerCase();return n.includes(`listener`)&&n.includes(`not found`)}const j=new
|
|
1
|
+
import{N as e}from"./sdk-contracts.js";import{n as t,r as n,t as r}from"./device-shell.js";import{a as i,d as a,f as o,i as s,l as c,m as l,n as u,p as d,s as f,u as p}from"./adb-transport.js";import{i as m,n as ee,s as te,u as h}from"./adb-failure.js";import{AsyncLocalStorage as g}from"node:async_hooks";let _;const v=new g;function y(e){_=e}function b(){if(!_)throw Error(`Android adb host port is not bound; import the platform composition wiring (src/platform-runtime-android-adb-host.ts) before using the adb/IME cluster.`);return _}async function x(e,t){let n=b(),r=v.getStore(),i=n.coerceAdbResult(r?await r(e,t):await n.execAdb(e,{...t,allowFailure:!0}));if(!t?.allowFailure&&i.exitCode!==0){let{androidAdbResultError:t}=await import(`./adb-failure.js`).then(e=>e.t),{serializeAndroidAdbInvocation:n}=await import(`./adb-transport.js`).then(e=>e.t);throw t(`adb ${n(e).join(` `)} exited with code ${i.exitCode}`,i)}return i}async function S(e,t){return await v.run(e,t)}function C(e){b().emitDiagnostic(e)}const w=new WeakSet;function T(e){return ne(typeof e==`function`?{exec:e}:e)}function ne(e){if(w.has(e))return e;let t={...e,exec:h(E(e.exec)),...e.pull?{pull:h(E(e.pull))}:{},...e.install?{install:h(E(e.install))}:{},...e.installBundle?{installBundle:h(e.installBundle)}:{}};return w.add(t),t}function E(e){return async(...t)=>b().coerceAdbResult(await e(...t))}const D=new WeakSet;function O(t){let n=T(t);if(n.reverse&&D.has(n.reverse))return n.reverse;let r=n.reverse??k(n.exec),i=new Map,a={async ensure(t,n){let a=i.get(t.local);if(a&&a.ownerId!==t.ownerId)throw new e(`COMMAND_FAILED`,`Android port reverse ${t.local} is already owned by ${a.ownerId??`another session`}`,{current:a,requested:t});a?.remote!==t.remote&&(await r.ensure(t,n),i.set(t.local,{...t}))},async remove(e,t){if(!i.has(e)){await r.remove(e,t);return}await r.remove(e,t),i.delete(e)},async removeAllOwned(e,t){let n=[...i.values()].filter(t=>t.ownerId===e).map(e=>e.local);if(n.length===0){await r.removeAllOwned(e,t);return}for(let e of n)await r.remove(e,t),i.delete(e)},async list(e){return r.list?await r.list(e):[...i.values()]}};return D.add(a),a}function k(e){let t=new Map;return{async ensure(n,r){if(await e([`reverse`,n.local,n.remote],{allowFailure:!1,signal:r?.signal,timeoutMs:r?.timeoutMs}),n.ownerId){let e=t.get(n.ownerId)??new Set;e.add(n.local),t.set(n.ownerId,e)}},async remove(n,r){let i=await e([`reverse`,`--remove`,n],{allowFailure:!0,signal:r?.signal,timeoutMs:r?.timeoutMs});if(i.exitCode!==0&&!re(i.stdout,i.stderr))throw ee(`Failed to remove Android port reverse ${n}`,i,{local:n});for(let e of t.values())e.delete(n)},async removeAllOwned(e,n){let r=[...t.get(e)??[]];for(let e of r)await this.remove(e,n);t.delete(e)},async list(n){let r=await e([`reverse`,`--list`],{allowFailure:!0,signal:n?.signal,timeoutMs:n?.timeoutMs});return r.exitCode===0?A(r.stdout,t):[]}}}function A(e,t){let n=new Map;for(let[e,r]of t)for(let t of r)n.set(t,e);return e.split(`
|
|
2
|
+
`).map(e=>e.trim().split(/\s+/)).filter(e=>e.length>=3).map(([,e,t])=>{let r=e;return{local:r,remote:t,ownerId:n.get(r)}})}function re(e,t){let n=`${e}\n${t}`.toLowerCase();return n.includes(`listener`)&&n.includes(`not found`)}const j=new g;function M(e,t={}){return Q(ie(e.id,t.serverPort))}function ie(e,t){return h(async(n,r)=>{let i=b(),a=async(n,r)=>{let a=V(e,t,n,r);return await i.withoutAdbCommandExecutorOverride(async()=>await i.execAdb(a.invocation,a.options))};return await P(`${t??r?.serverPort??``}/${e}`,r,async e=>await a(n,e),async e=>{await a([`wait-for-device`],{allowFailure:!0,timeoutMs:e,signal:r?.signal,env:r?.env,serverPort:r?.serverPort}).catch(()=>void 0)})})}function ae(e,t=new Map){return{has:e=>(t.get(e)??0)>Date.now(),mark:n=>{let r=Date.now();for(let[e,n]of t)n<=r&&t.delete(e);t.set(n,r+e)},forget:e=>{t.delete(e)}}}const N=ae(3e4);async function P(e,t,n,r){let i=Date.now(),a=await F(e,async()=>await n(t));if(!a.offline||N.has(e))return a.outcome();let o=t?.timeoutMs,s=()=>o===void 0?1/0:Math.floor(o-(Date.now()-i)),c=Math.min(15e3,Math.floor(s()/2));if(c<1)return a.outcome();await r(c),t?.signal?.throwIfAborted();let l=s();if(l<1)return a.outcome();let u=await F(e,async()=>await n(o===void 0?t:{...t,timeoutMs:l}));return u.offline&&N.mark(e),u.outcome()}async function F(e,t){try{let n=await t(),r=I(n);return r||N.forget(e),{offline:r,outcome:()=>n}}catch(t){let n=m(t),r=L(n);return!r&&z(n)&&N.forget(e),{offline:r,outcome:()=>{throw n}}}}function I(e){if(e.exitCode===0)return!1;let t=te(e.stderr,e.stdout);return R(t?.reason,t?.hostRefusal)}function L(t){return t instanceof e&&R(t.details?.adbFailure,t.details?.adbHostRefusal)}function R(e,t){return e===`device_offline`&&t===!0}function z(t){if(!(t instanceof e)||t.details?.timeoutMs!==void 0)return!1;let n=t.details?.exitCode;return typeof n==`number`&&n>=0}function B(e,t){return $((n,r)=>{let i=V(e,t,n,r);return b().spawnAdb(i.invocation,i.options)})}function V(e,t,n,r){let{serverPort:i,...a}=r??{};return{invocation:H(e,n,U(e,t,i)),options:a}}function H(e,t,n){let r=p(t),i=u(r.target,e);if(n===void 0)return s(i,r.command,[`-s`,e,...t]);let a=f(r,{port:n});return s(o(a.target,e),a.command)}function U(e,t,n){let r=j.getStore();return r&&Z(r,{kind:`serial`,serial:e}),r?.serverPort===void 0?t??n:(d(t,r.serverPort),d(n,r.serverPort))}function W(e,t={}){let n=M(e,t);return{exec:n,spawn:B(e.id,t.serverPort),reverse:k(n),pull:async(e,t,r)=>await n([`pull`,e,t],r),install:async(e,t)=>{let{installArgs:r,execOptions:i}=c(t);return await n([`install`,...r,e],i)}}}function G(e,t){let n=X(e);return t?Q(t):n?.serial===e.id?Q(n.provider.exec):M(e)}function K(e,t){let n=X(e);return me(t?T(t):n?.serial===e.id?T(n.provider):W(e))}function q(e){let t=X(e);return t?.serial===e.id?{mode:`transport-composed`,...t.provider.spawn?{spawn:$(t.provider.spawn)}:{}}:{mode:`local`}}function oe(e){let t=X(e);return t?.serial===e.id?t.provider.text:void 0}function se(e){let t=X(e);return t?.serial===e.id&&t.provider.touch?t.provider:void 0}function J(e,t){if(t)return T(t);if(e)return K(e);let n=j.getStore();if(n)return T(n.provider)}async function ce(e,t,n){if(!e)return await n();let r={provider:T(e),serial:t.serial,...t.serverPort===void 0?{}:{serverPort:t.serverPort}},i=le(r),a=async()=>await j.run(r,async()=>await b().withAdbCommandExecutorOverride(i,n));return t.serverPort===void 0?await a():await S(ue(r,t.serverPort),a)}function le(e){return(t,n,r)=>{if(!de(t)||e.serverPort===void 0&&t!==`adb`)return;let o=p(n);if(Z(e,o.target.selector),o.target.selector.kind===`serial`){if(o.target.selector.serial!==e.serial)return;e.serverPort!==void 0&&a(o.target,e.serverPort);let t=i(n,e.serial);return t===void 0?void 0:b().withoutAdbCommandExecutorOverride(async()=>await e.provider.exec(t,r))}let s=e.serverPort;if(s!==void 0)return Y(e,s,o,r)}}function ue(e,t){return async(n,r)=>(Z(e,n.target.selector),Y(e,t,n,r))}async function Y(e,t,n,r){d(t,r?.serverPort);let{serverPort:i,...a}=r??{},c=o(n.target,e.serial),l=f(s(c,n.command),{port:t}),u=b();return await u.withoutAdbCommandExecutorOverride(async()=>await u.execAdb(l,{...a,allowFailure:!0}))}function X(e){let t=j.getStore();return t&&Z(t,{kind:`serial`,serial:e.id}),t}function Z(e,t){e?.serverPort!==void 0&&l(t,e.serial)}function de(e){return n(e)===`adb`}async function fe(e,n,r){return await e(t(`adb`,`shell`,n),r)}async function pe(e,n,r){return await e(t(`adb`,`exec-out`,n),r)}function Q(e){return async(t,n)=>(r(t,`adb`),await e(t,n))}function $(e){return(t,n)=>(r(t,`adb`),e(t,n))}function me(e){return{...e,exec:Q(e.exec),...e.spawn?{spawn:$(e.spawn)}:{}}}async function he(t,n,r){let{device:i,provider:a,...o}=r??{},s=J(i,a),c=s?.pull,l=b();if(c)return await l.withoutAdbCommandExecutorOverride(async()=>await c(t,n,o));let u=s?.exec;if(!u)throw new e(`COMMAND_FAILED`,`Android adb pull requires an adb provider`);return await l.withoutAdbCommandExecutorOverride(async()=>await u([`pull`,t,n],o))}async function ge(t,n){let{device:r,provider:i,...a}=n??{},o=J(r,i),s=o?.install,l=b();if(s)return await l.withoutAdbCommandExecutorOverride(async()=>await s(t,a));let u=o?.exec;if(!u)throw new e(`COMMAND_FAILED`,`Android adb install requires an adb provider`);let{installArgs:d,execOptions:f}=c(a);return await l.withoutAdbCommandExecutorOverride(async()=>await u([`install`,...d,t],f))}export{x as _,G as a,se as c,fe as d,ce as f,b as g,C as h,W as i,q as l,y as m,he as n,K as o,O as p,M as r,oe as s,ge as t,pe as u,S as v};
|
package/dist/src/adb-failure.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime.js";import{N as t}from"./sdk-contracts.js";import{
|
|
1
|
+
import{r as e}from"./rolldown-runtime.js";import{N as t,R as n}from"./sdk-contracts.js";import{i as r}from"./exec.js";import"./command.js";var i=e({androidAdbResultError:()=>h,androidDiscoveryCommandError:()=>_,attachAdbFailureHint:()=>f,attachAndroidDiscoveryTimeout:()=>v,attachAndroidHelperInstallTimeoutHint:()=>p,classifyAndroidAdbFailure:()=>d,discloseAdbInputDispatch:()=>y,isAdbHostRefusal:()=>b,withAdbFailureHints:()=>g});const a=String.raw`(?:adb|error): `;function o(e){return RegExp(`^${a}${e}$`)}const s=[[/device unauthorized|device still authorizing/,{reason:`device_unauthorized`,hint:`USB debugging is not authorized — accept the authorization prompt on the device screen (re-plug the cable if none appears), then retry.`},{hostRefusal:o(String.raw`device (?:unauthorized|still authorizing)\.?`)}],[/device offline/,{reason:`device_offline`,hint:`The device is connected but offline — wait for it to finish booting or run adb reconnect, then retry.`,retriable:!0},{hostRefusal:o(String.raw`device (?:'[^']*' )?offline`)}],[/more than one (?:device\/emulator|device and emulator)/,{reason:`multiple_devices`,hint:`Multiple Android devices are connected — pass --serial <serial> (see adb devices) to select one.`},{hostRefusal:o(String.raw`more than one (?:device/emulator|device and emulator)`)}],[/no devices\/emulators found|no devices found/,{reason:`no_devices`,hint:`No Android devices detected — boot an emulator or connect a device and verify it appears in adb devices.`},{hostRefusal:o(String.raw`no devices(?:/emulators)? found`)}],[/device (?:'[^']*' )?not found/,{reason:`device_not_found`,hint:`The device disconnected or is restarting — verify it is listed in adb devices, then retry.`,retriable:!0},{hostRefusal:o(String.raw`device (?:'[^']*' )?not found`)}],[/adb server version \(\d+\) doesn't match this client/,{reason:`server_version_mismatch`,hint:`Multiple adb installs conflict — adb restarts its server automatically, so retry; align PATH to a single adb to stop recurrences.`,retriable:!0}],[/transport error|connection reset|broken pipe|protocol fault/,{reason:`connection_dropped`,hint:`The adb connection dropped — retry; if it persists, run adb kill-server and reconnect the device.`,retriable:!0}],[/install_failed_insufficient_storage/,{reason:`install_insufficient_storage`,hint:`The device is out of storage — free up space or uninstall unused apps, then retry the install.`},{matchStdout:!0}],[/install_failed_update_incompatible/,{reason:`install_update_incompatible`,hint:`The installed app has an incompatible signature — uninstall the existing app first, then retry the install.`},{matchStdout:!0}],[/install_failed_version_downgrade/,{reason:`install_version_downgrade`,hint:`The APK is older than the installed app — uninstall the app first (or install with downgrade allowed), then retry.`},{matchStdout:!0}],[/install_failed_\w+|install_parse_failed_\w+/,{reason:`install_failed`,hint:`The Android package installer rejected the APK — see the INSTALL_FAILED code in the error output for the exact cause.`},{matchStdout:!0}]],c=Object.freeze({reason:`timeout`,hint:`adb timed out — the adb server may be wedged. Run adb kill-server && adb start-server, check adb devices, then retry.`}),l=/^(?:this adb server's \$adb_vendor_keys is not set|try 'adb kill-server' if that seems wrong\.|(?:otherwise|please) check (?:for|the) (?:a )?confirmation dialog on your device\.)$/;function u(e,t){if(t!==``)return;let[n,...r]=e.split(`
|
|
2
|
+
`).map(e=>e.trim()).filter(e=>e!==``);if(n===void 0||!r.every(e=>l.test(e)))return;let i=s.find(([,,e])=>e?.hostRefusal?.test(n));return i&&{...i[1],hostRefusal:!0}}function d(e,t=``){let n=e.toLowerCase(),r=t.toLowerCase(),i=u(n,r);if(i)return i;for(let[e,t,i]of s)if(e.test(n)||i?.matchStdout&&e.test(r))return t}function f(e){if(!(e instanceof t)||e.code!==`COMMAND_FAILED`)return e;let n=m(e);return n&&(e.details={...e.details,adbFailure:n.reason,...n.hostRefusal?{adbHostRefusal:!0}:{},...typeof e.details?.hint==`string`?{}:{hint:n.hint},...n.retriable!==void 0&&e.details?.retriable===void 0?{retriable:n.retriable}:{}}),e}function p(e){if(!r(e))return e;let t=e.details?.hint;if(typeof t==`string`&&t!==c.hint)return e;let n=f(e);return n.details={...n.details,hint:`The helper install timed out — some OEM builds (ColorOS is one) hold the first install of each package behind a system install-confirmation dialog and adb waits for it. Check the device screen, confirm any pending install prompt, then retry; if none is showing, run adb kill-server && adb start-server and retry.`},n}function m(e){return typeof e.details?.timeoutMs==`number`?c:d(typeof e.details?.stderr==`string`?e.details.stderr:``,typeof e.details?.stdout==`string`?e.details.stdout:``)}function h(e,n,r){let i=n.exitCode===0?{stdout:n.stdout,stderr:n.stderr,exitCode:n.exitCode,...r}:{stdout:n.stdout,stderr:n.stderr,exitCode:n.exitCode,processExitError:!0,...r};return f(new t(`COMMAND_FAILED`,e,i))}function g(e){return async(...t)=>{try{return await e(...t)}catch(e){throw f(e)}}}function _(e,n,r){let i=d(n.stderr,n.stdout);return new t(`COMMAND_FAILED`,e,{stdout:n.stdout,stderr:n.stderr,exitCode:n.exitCode,processExitError:!0,hint:i?.hint??r,...i?{adbFailure:i.reason}:{},...i?.retriable===void 0?{}:{retriable:i.retriable}})}function v(e){return r(e)&&(e.details={...e.details,adbFailure:c.reason,...typeof e.details?.hint==`string`?{}:{hint:c.hint}}),e}function y(e){return e instanceof t?n(e,e.code===`TOOL_MISSING`||b(e)?`no`:`unknown`):e}function b(e){return e.details?.adbHostRefusal===!0}export{v as a,y as c,f as i,b as l,h as n,p as o,_ as r,d as s,i as t,g as u};
|