agent-device 0.17.10 → 0.18.1
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/README.md +3 -2
- package/android-multitouch-helper/dist/{agent-device-android-multitouch-helper-0.17.10.apk → agent-device-android-multitouch-helper-0.18.1.apk} +0 -0
- package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.18.1.apk.sha256 +1 -0
- package/android-multitouch-helper/dist/{agent-device-android-multitouch-helper-0.17.10.manifest.json → agent-device-android-multitouch-helper-0.18.1.manifest.json} +4 -4
- package/android-snapshot-helper/dist/{agent-device-android-snapshot-helper-0.17.10.apk → agent-device-android-snapshot-helper-0.18.1.apk} +0 -0
- package/android-snapshot-helper/dist/agent-device-android-snapshot-helper-0.18.1.apk.sha256 +1 -0
- package/android-snapshot-helper/dist/{agent-device-android-snapshot-helper-0.17.10.manifest.json → agent-device-android-snapshot-helper-0.18.1.manifest.json} +6 -6
- package/apple-runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerApp.m +156 -0
- package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunner.xcodeproj/project.pbxproj +10 -16
- package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AXSnapshotFallback.swift +2 -0
- package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +3 -1
- package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandJournal.swift +2 -0
- package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+FlatSnapshotFiltering.swift +2 -4
- package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +9 -36
- package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScrollGesture.swift +2 -0
- package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SequenceExecution.swift +2 -0
- package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift +2 -0
- package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotCapturePlan.swift +2 -0
- package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntry.swift +0 -1
- package/dist/src/1986.js +1 -0
- package/dist/src/2748.js +1 -1
- package/dist/src/2948.js +21 -21
- package/dist/src/314.js +1 -1
- package/dist/src/3340.js +8 -7
- package/dist/src/432.js +4 -4
- package/dist/src/4418.js +1 -1
- package/dist/src/4428.js +3 -3
- package/dist/src/485.js +1 -0
- package/dist/src/495.js +5 -0
- package/dist/src/5484.js +1 -1
- package/dist/src/5643.js +1 -0
- package/dist/src/587.js +1 -1
- package/dist/src/5913.js +4 -0
- package/dist/src/6849.js +1 -0
- package/dist/src/6918.js +1 -1
- package/dist/src/6967.js +1 -0
- package/dist/src/760.js +1 -0
- package/dist/src/7871.js +1 -0
- package/dist/src/8225.js +1 -1
- package/dist/src/8391.js +1 -0
- package/dist/src/8404.js +2 -0
- package/dist/src/8414.js +2 -0
- package/dist/src/8875.js +1 -1
- package/dist/src/8936.js +1 -0
- package/dist/src/9414.js +1 -0
- package/dist/src/9581.js +5 -5
- package/dist/src/9624.js +1 -1
- package/dist/src/9722.js +37 -37
- package/dist/src/android-adb.d.ts +19 -54
- package/dist/src/android-adb.js +1 -1
- package/dist/src/android.js +5 -5
- package/dist/src/apps.js +9 -11
- package/dist/src/audio-probe.js +1 -0
- package/dist/src/batch.d.ts +50 -25
- package/dist/src/batch.js +1 -1
- package/dist/src/cli-help.js +104 -37
- package/dist/src/cli.js +36 -27
- package/dist/src/contracts.d.ts +46 -122
- package/dist/src/contracts.js +1 -1
- package/dist/src/debug-symbols.js +3 -0
- package/dist/src/devices.js +1 -1
- package/dist/src/devices~1.js +1 -1
- package/dist/src/devices~2.js +1 -1
- package/dist/src/find.js +1 -1
- package/dist/src/finders.d.ts +2 -6
- package/dist/src/finders.js +1 -1
- package/dist/src/generic.js +1 -9
- package/dist/src/handler-utils.js +1 -0
- package/dist/src/index.d.ts +500 -182
- package/dist/src/index.js +1 -1
- package/dist/src/input-actions.js +1 -1
- package/dist/src/input-actions~1.js +1 -1
- package/dist/src/install-source.d.ts +0 -26
- package/dist/src/install-source.js +1 -1
- package/dist/src/interaction.js +1 -1
- package/dist/src/interactor.js +1 -0
- package/dist/src/internal/bin.js +1 -1
- package/dist/src/internal/companion-tunnel.js +1 -1
- package/dist/src/internal/png-worker.js +1 -1
- package/dist/src/lease.js +1 -1
- package/dist/src/linux.js +1 -1
- package/dist/src/metro.d.ts +10 -134
- package/dist/src/metro.js +1 -1
- package/dist/src/notifications.js +1 -1
- package/dist/src/react-native.js +1 -1
- package/dist/src/record-trace-recording.js +3 -3
- package/dist/src/record-trace.js +1 -1
- package/dist/src/remote-config.d.ts +28 -24
- package/dist/src/remote-config.js +1 -1
- package/dist/src/runner-sequence.js +1 -0
- package/dist/src/selector-runtime.js +1 -1
- package/dist/src/selectors.d.ts +7 -3
- package/dist/src/selectors.js +1 -1
- package/dist/src/server.js +2 -2
- package/dist/src/session.js +11 -8
- package/dist/src/simulator.js +2 -0
- package/dist/src/snapshot.js +2 -2
- package/dist/src/web.js +1 -1
- package/macos-helper/Sources/AgentDeviceMacOSHelper/AudioProbe.swift +297 -0
- package/macos-helper/Sources/AgentDeviceMacOSHelper/main.swift +30 -0
- package/package.json +15 -11
- package/server.json +2 -2
- package/android-multitouch-helper/README.md +0 -41
- package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.17.10.apk.sha256 +0 -1
- package/android-snapshot-helper/README.md +0 -88
- package/android-snapshot-helper/dist/agent-device-android-snapshot-helper-0.17.10.apk.sha256 +0 -1
- package/dist/src/2133.js +0 -1
- package/dist/src/2577.js +0 -1
- package/dist/src/2954.js +0 -2
- package/dist/src/4291.js +0 -1
- package/dist/src/4723.js +0 -1
- package/dist/src/5628.js +0 -1
- package/dist/src/5910.js +0 -2
- package/dist/src/6024.js +0 -1
- package/dist/src/733.js +0 -1
- package/dist/src/7394.js +0 -6
- package/dist/src/8275.js +0 -2
- package/dist/src/8358.js +0 -4
- package/dist/src/9919.js +0 -6
- package/dist/src/android-snapshot-helper.d.ts +0 -359
- package/dist/src/android-snapshot-helper.js +0 -1
- package/dist/src/apple.js +0 -1
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerApp.swift +0 -17
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunner/Assets.xcassets/AccentColor.colorset/Contents.json +0 -11
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunner/Assets.xcassets/AppIcon.appiconset/Contents.json +0 -36
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunner/Assets.xcassets/AppIcon.appiconset/logo.jpg +0 -0
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunner/Assets.xcassets/Contents.json +0 -6
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunner/Assets.xcassets/Logo.imageset/Contents.json +0 -21
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunner/Assets.xcassets/Logo.imageset/logo.jpg +0 -0
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunner/Assets.xcassets/PoweredBy.imageset/Contents.json +0 -21
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunner/Assets.xcassets/PoweredBy.imageset/powered-by.png +0 -0
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunner/ContentView.swift +0 -34
- package/ios-runner/README.md +0 -53
- package/ios-runner/RUNNER_PROTOCOL.md +0 -76
- /package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunner.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -0
- /package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunner.xcodeproj/xcshareddata/xcschemes/AgentDeviceRunner.xcscheme +0 -0
- /package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/AgentDeviceRunnerUITests-Bridging-Header.h +0 -0
- /package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/AgentDeviceRunnerUITests.entitlements +0 -0
- /package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAXSnapshotBridge.h +0 -0
- /package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAXSnapshotBridge.m +0 -0
- /package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerObjCExceptionCatcher.h +0 -0
- /package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerObjCExceptionCatcher.m +0 -0
- /package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.h +0 -0
- /package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.m +0 -0
- /package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Alert.swift +0 -0
- /package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Environment.swift +0 -0
- /package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Exceptions.swift +0 -0
- /package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Lifecycle.swift +0 -0
- /package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +0 -0
- /package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScreenRecorder.swift +0 -0
- /package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SystemModal.swift +0 -0
- /package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Transport.swift +0 -0
- /package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TvRemote.swift +0 -0
- /package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +0 -0
- /package/{ios-runner → apple-runner}/AgentDeviceRunner/AgentDeviceRunnerUITests.xctestplan +0 -0
- /package/{ios-runner → apple-runner}/AgentDeviceRunner/RecordingScripts/recording-overlay.swift +0 -0
- /package/{ios-runner → apple-runner}/AgentDeviceRunner/RecordingScripts/recording-resize.swift +0 -0
- /package/{ios-runner → apple-runner}/AgentDeviceRunner/RecordingScripts/recording-trim.swift +0 -0
- /package/dist/src/{4069.js → 4917.js} +0 -0
- /package/dist/src/{9836.js → 893.js} +0 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
1
|
import type { Readable } from 'node:stream';
|
|
3
2
|
import { StdioOptions } from 'node:child_process';
|
|
4
3
|
import type { Writable } from 'node:stream';
|
|
@@ -11,22 +10,22 @@ export declare type AndroidAdbExecutor = (args: string[], options?: AndroidAdbEx
|
|
|
11
10
|
|
|
12
11
|
export declare type AndroidAdbExecutorOptions = Pick<ExecOptions, 'allowFailure' | 'timeoutMs' | 'binaryStdout' | 'stdin' | 'signal'>;
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
declare type AndroidAdbExecutorResult = Pick<ExecResult, 'exitCode' | 'stdout' | 'stderr' | 'stdoutBuffer'>;
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
16
|
* Installs an APK path. Implementations are responsible for honoring semantic
|
|
18
17
|
* install options such as replace/test/downgrade/grant-permissions.
|
|
19
18
|
*/
|
|
20
|
-
|
|
19
|
+
declare type AndroidAdbInstaller = (apkPath: string, options?: AndroidAdbInstallOptions) => Promise<AndroidAdbExecutorResult>;
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
declare type AndroidAdbInstallOptions = AndroidAdbTransferOptions & {
|
|
23
22
|
replace?: boolean;
|
|
24
23
|
allowTestPackages?: boolean;
|
|
25
24
|
allowDowngrade?: boolean;
|
|
26
25
|
grantPermissions?: boolean;
|
|
27
26
|
};
|
|
28
27
|
|
|
29
|
-
|
|
28
|
+
declare type AndroidAdbProcess = {
|
|
30
29
|
pid?: number;
|
|
31
30
|
stdin: Writable | null;
|
|
32
31
|
stdout: Readable | null;
|
|
@@ -38,7 +37,7 @@ export declare type AndroidAdbProcess = {
|
|
|
38
37
|
on(event: 'exit' | 'close', listener: (code: number | null, signal: NodeJS.Signals | null) => void): unknown;
|
|
39
38
|
};
|
|
40
39
|
|
|
41
|
-
|
|
40
|
+
declare type AndroidAdbProvider = {
|
|
42
41
|
/**
|
|
43
42
|
* Fallback executor for device-scoped adb arguments. Providers may omit explicit
|
|
44
43
|
* methods to keep the legacy exec-shaped pull/install fallback.
|
|
@@ -53,20 +52,20 @@ export declare type AndroidAdbProvider = {
|
|
|
53
52
|
touch?: AndroidTouchInjector;
|
|
54
53
|
};
|
|
55
54
|
|
|
56
|
-
|
|
55
|
+
declare type AndroidAdbPuller = (remotePath: string, localPath: string, options?: AndroidAdbTransferOptions) => Promise<AndroidAdbExecutorResult>;
|
|
57
56
|
|
|
58
|
-
|
|
57
|
+
declare type AndroidAdbSpawner = (args: string[], options?: ExecBackgroundOptions) => AndroidAdbProcess;
|
|
59
58
|
|
|
60
|
-
|
|
59
|
+
declare type AndroidAdbTransferOptions = AndroidAdbExecutorOptions;
|
|
61
60
|
|
|
62
|
-
|
|
61
|
+
declare type AndroidAppListFilter = AppsFilter;
|
|
63
62
|
|
|
64
|
-
|
|
63
|
+
declare type AndroidAppListOptions = {
|
|
65
64
|
filter?: AndroidAppListFilter;
|
|
66
65
|
target?: AndroidAppListTarget;
|
|
67
66
|
};
|
|
68
67
|
|
|
69
|
-
|
|
68
|
+
declare type AndroidAppListTarget = 'mobile' | 'tv' | 'auto';
|
|
70
69
|
|
|
71
70
|
declare type AndroidBundleInstaller = (bundlePath: string, options: {
|
|
72
71
|
mode: string;
|
|
@@ -85,7 +84,7 @@ declare type AndroidKeyboardDismissResult = AndroidKeyboardState & {
|
|
|
85
84
|
dismissed: boolean;
|
|
86
85
|
};
|
|
87
86
|
|
|
88
|
-
|
|
87
|
+
declare type AndroidKeyboardState = {
|
|
89
88
|
visible: boolean;
|
|
90
89
|
inputType?: string;
|
|
91
90
|
type?: AndroidKeyboardType;
|
|
@@ -97,44 +96,38 @@ export declare type AndroidKeyboardState = {
|
|
|
97
96
|
|
|
98
97
|
declare type AndroidKeyboardType = 'text' | 'number' | 'email' | 'phone' | 'password' | 'datetime' | 'unknown';
|
|
99
98
|
|
|
100
|
-
|
|
99
|
+
declare type AndroidLogcatCaptureOptions = {
|
|
101
100
|
lines?: number;
|
|
102
101
|
timeoutMs?: number;
|
|
103
102
|
signal?: AbortSignal;
|
|
104
103
|
};
|
|
105
104
|
|
|
106
|
-
|
|
107
|
-
pid?: string;
|
|
108
|
-
signal?: AbortSignal;
|
|
109
|
-
output?: fs.WriteStream;
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
export declare type AndroidOpenAppWithAdbOptions = {
|
|
105
|
+
declare type AndroidOpenAppWithAdbOptions = {
|
|
113
106
|
activity?: string;
|
|
114
107
|
category?: string;
|
|
115
108
|
};
|
|
116
109
|
|
|
117
110
|
export declare type AndroidPortReverseEndpoint = `tcp:${number}` | `localabstract:${string}`;
|
|
118
111
|
|
|
119
|
-
|
|
112
|
+
declare type AndroidPortReverseMapping = {
|
|
120
113
|
local: AndroidPortReverseEndpoint;
|
|
121
114
|
remote: AndroidPortReverseEndpoint;
|
|
122
115
|
ownerId?: string;
|
|
123
116
|
};
|
|
124
117
|
|
|
125
|
-
|
|
118
|
+
declare type AndroidPortReverseOptions = {
|
|
126
119
|
signal?: AbortSignal;
|
|
127
120
|
timeoutMs?: number;
|
|
128
121
|
};
|
|
129
122
|
|
|
130
|
-
|
|
123
|
+
declare type AndroidPortReverseProvider = {
|
|
131
124
|
ensure(mapping: AndroidPortReverseMapping, options?: AndroidPortReverseOptions): Promise<void>;
|
|
132
125
|
remove(local: AndroidPortReverseEndpoint, options?: AndroidPortReverseOptions): Promise<void>;
|
|
133
126
|
removeAllOwned(ownerId: string, options?: AndroidPortReverseOptions): Promise<void>;
|
|
134
127
|
list?(options?: AndroidPortReverseOptions): Promise<AndroidPortReverseMapping[]>;
|
|
135
128
|
};
|
|
136
129
|
|
|
137
|
-
|
|
130
|
+
declare type AndroidTextInjectionRequest = {
|
|
138
131
|
action: AndroidTextInputAction;
|
|
139
132
|
text: string;
|
|
140
133
|
delayMs?: number;
|
|
@@ -148,7 +141,7 @@ export declare type AndroidTextInjectionRequest = {
|
|
|
148
141
|
};
|
|
149
142
|
};
|
|
150
143
|
|
|
151
|
-
|
|
144
|
+
declare type AndroidTextInjector = (request: AndroidTextInjectionRequest) => Promise<void>;
|
|
152
145
|
|
|
153
146
|
declare type AndroidTextInputAction = 'type' | 'fill';
|
|
154
147
|
|
|
@@ -190,26 +183,6 @@ export declare function captureAndroidLogcatWithAdb(adb: AndroidAdbExecutor, opt
|
|
|
190
183
|
|
|
191
184
|
export declare function createAndroidPortReverseManager(provider: AndroidAdbProvider | AndroidAdbExecutor): AndroidPortReverseProvider;
|
|
192
185
|
|
|
193
|
-
export declare function createLocalAndroidAdbProvider(device: DeviceInfo): AndroidAdbProvider;
|
|
194
|
-
|
|
195
|
-
declare const DEVICE_KINDS: readonly ['simulator', 'emulator', 'device'];
|
|
196
|
-
|
|
197
|
-
declare const DEVICE_TARGETS: readonly ['mobile', 'tv', 'desktop'];
|
|
198
|
-
|
|
199
|
-
declare type DeviceInfo = {
|
|
200
|
-
platform: Platform;
|
|
201
|
-
id: string;
|
|
202
|
-
name: string;
|
|
203
|
-
kind: DeviceKind;
|
|
204
|
-
target?: DeviceTarget;
|
|
205
|
-
booted?: boolean;
|
|
206
|
-
simulatorSetPath?: string;
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
declare type DeviceKind = (typeof DEVICE_KINDS)[number];
|
|
210
|
-
|
|
211
|
-
declare type DeviceTarget = (typeof DEVICE_TARGETS)[number];
|
|
212
|
-
|
|
213
186
|
export declare function dismissAndroidKeyboardWithAdb(adb: AndroidAdbExecutor): Promise<AndroidKeyboardDismissResult>;
|
|
214
187
|
|
|
215
188
|
declare type ExecBackgroundOptions = ExecOptions & {
|
|
@@ -254,16 +227,8 @@ export declare function listAndroidAppsWithAdb(adb: AndroidAdbExecutor, options?
|
|
|
254
227
|
|
|
255
228
|
export declare function openAndroidAppWithAdb(adb: AndroidAdbExecutor, packageName: string, options?: AndroidOpenAppWithAdbOptions): Promise<void>;
|
|
256
229
|
|
|
257
|
-
declare type Platform = (typeof PLATFORMS)[number];
|
|
258
|
-
|
|
259
|
-
declare const PLATFORMS: readonly ['ios', 'macos', 'android', 'linux', 'web'];
|
|
260
|
-
|
|
261
230
|
export declare function readAndroidClipboardWithAdb(adb: AndroidAdbExecutor): Promise<string>;
|
|
262
231
|
|
|
263
|
-
export declare function resolveAndroidLaunchComponentWithAdb(adb: AndroidAdbExecutor, packageName: string, categories?: string[]): Promise<string | null>;
|
|
264
|
-
|
|
265
|
-
export declare function streamAndroidLogcatWithAdb(provider: Pick<AndroidAdbProvider, 'spawn'>, options?: AndroidLogcatStreamOptions): AndroidAdbProcess;
|
|
266
|
-
|
|
267
232
|
export declare function writeAndroidClipboardWithAdb(adb: AndroidAdbExecutor, text: string): Promise<void>;
|
|
268
233
|
|
|
269
234
|
export { }
|
package/dist/src/android-adb.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{AppError as t}from"./
|
|
1
|
+
import{AppError as t}from"./485.js";import{resolveAppsFilter as e}from"./2748.js";import{parseAndroidForegroundApp as i,parseAndroidLaunchablePackages as a,parseAndroidUserInstalledPackages as r,inferAndroidAppName as o,parseAndroidLaunchComponent as n,isAmStartError as d}from"./3340.js";let l="android.intent.category.LAUNCHER",s="android.intent.category.LEANBACK_LAUNCHER";async function c(t,i={}){let a=await A(t,i.target??"auto");return("user-installed"===e(i.filter)?(await p(t)).filter(t=>a.has(t)):Array.from(a)).map(t=>({package:t,name:o(t)})).sort((t,e)=>t.package.localeCompare(e.package))}async function u(t){let e=await f(t,[["shell","dumpsys","window","windows"],["shell","dumpsys","window"]]);if(e)return e;let i=await f(t,[["shell","dumpsys","activity","activities"],["shell","dumpsys","activity"]]);return i||{}}async function A(t,e){return new Set((await Promise.all((function(t){switch(t){case"mobile":return[l];case"tv":return[s];default:return[l,s]}})(e).map(async e=>{var i;let r=await t(["shell","cmd","package","query-activities","--brief","-a","android.intent.action.MAIN","-c",e],{allowFailure:!0});return 0===r.exitCode?0===(i=r.stdout).trim().length?[]:a(i):[]}))).flat())}async function p(e){let i=await e(["shell","pm","list","packages","-3"],{allowFailure:!0});if(0!==i.exitCode)throw new t("COMMAND_FAILED","Failed to list Android user-installed apps",{stdout:i.stdout,stderr:i.stderr,exitCode:i.exitCode});return r(i.stdout)}async function f(t,e){for(let a of e){let e=i((await t(a,{allowFailure:!0})).stdout??"");if(e)return e}return null}let w="android.intent.category.LAUNCHER",m="android.intent.category.DEFAULT";async function _(t,e){await t(["shell","am","force-stop",e])}async function h(t,e,i=[w]){for(let a of i){let i=await t(["shell","cmd","package","resolve-activity","--brief","-a","android.intent.action.MAIN","-c",a,e],{allowFailure:!0});if(0!==i.exitCode)continue;let r=n(i.stdout);if(r)return r}return null}async function y(e,i,a={}){let r=a.category??w;if(a.activity){var o,n;return void await e(["shell","am","start","-W","-a","android.intent.action.MAIN","-c",m,"-c",r,"-n",(o=i,(n=a.activity).includes("/")?n:`${o}/${n.startsWith(".")?n:`.${n}`}`)])}let l=await e(["shell","am","start","-W","-a","android.intent.action.MAIN","-c",m,"-c",r,"-p",i],{allowFailure:!0});if(0===l.exitCode&&!d(l.stdout,l.stderr))return;let s=await h(e,i,[r]);if(!s)throw new t("COMMAND_FAILED",`Failed to resolve Android launch component for ${i}`,{stdout:l.stdout,stderr:l.stderr,exitCode:l.exitCode});await e(["shell","am","start","-W","-a","android.intent.action.MAIN","-c",m,"-c",r,"-n",s])}export{captureAndroidLogcatWithAdb,createAndroidPortReverseManager}from"./3340.js";export{dismissAndroidKeyboardWithAdb,getAndroidKeyboardStatusWithAdb,readAndroidClipboardWithAdb,writeAndroidClipboardWithAdb}from"./9624.js";export{_ as forceStopAndroidAppWithAdb,u as getAndroidAppStateWithAdb,c as listAndroidAppsWithAdb,y as openAndroidAppWithAdb};
|
package/dist/src/android.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import e from"node:crypto";import t from"node:fs/promises";import r from"node:path";import{promises as
|
|
2
|
-
${
|
|
3
|
-
${r.stderr}`);return
|
|
4
|
-
${r}`.toLowerCase()).includes("unknown command")||
|
|
5
|
-
${t}`);if(!r)return null;let
|
|
1
|
+
import e from"node:crypto";import t from"node:fs/promises";import r from"node:path";import{promises as a}from"node:fs";import{normalizeError as i,AppError as n}from"./485.js";import{withDiagnosticTimer as o,emitDiagnostic as s}from"./432.js";import{readVersion as d,findProjectRoot as l}from"./1404.js";import{openAndroidDevice as u,runAndroidAdb as c,resolveAndroidApp as p,resolveAndroidTouchInjector as m,closeAndroidApp as h,openAndroidApp as f,resolveAndroidAdbProvider as w,resolveAndroidAdbExecutor as _,installAndroidAdbPackage as A}from"./3340.js";import{appSwitcherAndroid as g,homeAndroid as y,scrollAndroid as N,longPressAndroid as v,typeAndroid as I,getAndroidScreenSize as M,pressAndroid as C,focusAndroid as k,swipeAndroid as x,rotateAndroid as S,fillAndroid as D,backAndroid as E}from"./input-actions.js";import{parseInstrumentationRecords as R,readAndroidHelperManifestInteger as b,readInstrumentationResultNumber as F,snapshotAndroid as L,readAndroidHelperManifestLiteral as O}from"./9722.js";import{requireLocationCoordinates as P,snapshotCaptureAnnotationsFrom as T}from"./2948.js";import{parseAppearanceAction as U,summarizeCommandAttemptFailures as $,parseSettingState as G,parsePermissionTarget as K,parsePermissionAction as V}from"./8225.js";import{writeAndroidClipboardText as H,readAndroidClipboardText as B}from"./9624.js";import{sleep as q}from"./5560.js";let j="android-multitouch-helper-v1",z="ANDROID_MULTITOUCH_HELPER_NO_FINAL_RESULT",J="ANDROID_MULTITOUCH_HELPER_REPORTED_FAILURE";async function X(e,t){let r=await et(e,{kind:"swipe",...t});if(r)return r;try{return await er(e,{kind:"swipe",...t})}catch(r){return s({level:"warn",phase:"android_swipe_helper_fallback",data:{error:i(r).message}}),await x(e,t.x1,t.y1,t.x2,t.y2,t.durationMs),{backend:"adb-input-swipe-fallback"}}}async function Q(e,t){if(!Number.isFinite(t.scale)||t.scale<=0)throw new n("INVALID_ARGS","gesture pinch requires scale > 0");let r=await Z(e,t.x,t.y);return await ee(e,{kind:"pinch",x:r.x,y:r.y,scale:t.scale,durationMs:t.durationMs})}async function W(e,t){if(!Number.isFinite(t.degrees))throw new n("INVALID_ARGS","gesture rotate requires finite degrees");if(void 0!==t.velocity&&(!Number.isFinite(t.velocity)||0===t.velocity))throw new n("INVALID_ARGS","gesture rotate velocity must be a non-zero number");let r=await Z(e,t.x,t.y),a=t.degrees;return await ee(e,{kind:"rotate",x:r.x,y:r.y,degrees:a,durationMs:t.durationMs})}async function Y(e,t){if(!Number.isFinite(t.scale)||t.scale<=0)throw new n("INVALID_ARGS","gesture transform requires scale > 0");if(!Number.isFinite(t.degrees))throw new n("INVALID_ARGS","gesture transform requires finite degrees");if(![t.x,t.y,t.dx,t.dy].every(Number.isFinite))throw new n("INVALID_ARGS","gesture transform requires finite x y dx dy");return await ee(e,{kind:"transform",x:t.x,y:t.y,dx:t.dx,dy:t.dy,scale:t.scale,degrees:t.degrees,durationMs:t.durationMs})}async function Z(e,t,r){if(void 0!==t&&void 0!==r)return{x:t,y:r};let a=await M(e);return{x:Math.round(a.width/2),y:Math.round(a.height/2)}}async function ee(e,t){let r=await et(e,t);return r||await er(e,t)}async function et(e,t){let r=m(e);if(r)return{backend:"provider-native-touch",...await r(t)??{}}}async function er(e,t){let r=_(e),a=await ei(),i=w(e),n=await o("android_multitouch_helper_install",async()=>{var t;return await en({adb:r,adbProvider:i,artifact:a,deviceKey:(t=e,`${t.platform}:${t.id}`)})},{packageName:a.manifest.packageName,versionCode:a.manifest.versionCode});s({phase:"android_multitouch_helper_install_decision",data:n});let d=await o("android_multitouch_helper_gesture",async()=>await ea({adb:r,request:function(e){var t;let r=Math.round(void 0!==(t=e).durationMs?t.durationMs:"swipe"===t.kind||"pinch"===t.kind?300:Math.min(Math.max(300,16*Math.ceil(Math.abs(t.degrees)/3)),2400));switch(e.kind){case"swipe":return{kind:"swipe",x1:Math.round(e.x1),y1:Math.round(e.y1),x2:Math.round(e.x2),y2:Math.round(e.y2),durationMs:r};case"pinch":return{kind:"pinch",x:Math.round(e.x),y:Math.round(e.y),scale:e.scale,radius:160,durationMs:r};case"rotate":return{kind:"rotate",x:Math.round(e.x),y:Math.round(e.y),degrees:e.degrees,radius:160,durationMs:r};case"transform":return{kind:"transform",x:Math.round(e.x),y:Math.round(e.y),dx:Math.round(e.dx),dy:Math.round(e.dy),scale:e.scale,degrees:e.degrees,durationMs:r}}}(t),packageName:a.manifest.packageName,instrumentationRunner:a.manifest.instrumentationRunner}),{packageName:a.manifest.packageName,version:a.manifest.version});return{backend:"android-multitouch-helper",helperVersion:a.manifest.version,installReason:n.reason,...d}}async function ea(e){let t,r=Buffer.from(JSON.stringify({protocol:j,...e.request})).toString("base64"),a=await e.adb(["shell","am","instrument","-w","-e","payloadBase64",r,e.instrumentationRunner],{allowFailure:!0,timeoutMs:45e3});try{t=function(e){let t=R(e).results.find(e=>e.agentDeviceProtocol===j);if(!t)throw new n(z,"Android multi-touch helper did not return a final result");if("true"!==t.ok){var r;throw new n(J,(r=t).message&&"null"!==r.message?r.message:r.errorType||"Android multi-touch helper returned an error",{errorType:t.errorType,helper:t})}return{kind:t.kind,helperApiVersion:t.helperApiVersion,injectedEvents:F(t.injectedEvents),elapsedMs:F(t.elapsedMs)}}(`${a.stdout}
|
|
2
|
+
${a.stderr}`)}catch(e){if(e instanceof n){if(e.code===J)throw new n("COMMAND_FAILED",e.message,e.details,e);if(e.code!==z)throw e}throw new n("COMMAND_FAILED",0===a.exitCode?"Android multi-touch helper output could not be parsed":"Android multi-touch helper failed before returning parseable output",{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode},e)}if(0!==a.exitCode)throw new n("COMMAND_FAILED","Android multi-touch helper failed",{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode,helper:t});return t}async function ei(){let e=d(),a=r.join(l(),"android-multitouch-helper","dist"),o=r.join(a,`agent-device-android-multitouch-helper-${e}.manifest.json`);try{let e=function(e){var t,r;if(!e||"object"!=typeof e||Array.isArray(e))throw new n("INVALID_ARGS","Android multi-touch helper manifest must be an object.");return{name:ec(e.name,"name","android-multitouch-helper"),version:eu(e.version,"version"),assetName:eu(e.assetName,"assetName"),sha256:function(e){let t=eu(e,"sha256").trim().toLowerCase();if(64!==t.length||!/^[0-9a-f]+$/.test(t))throw new n("INVALID_ARGS","Android multi-touch helper manifest sha256 must be a 64-character hex string.");return t}(e.sha256),packageName:ec(e.packageName,"packageName","com.callstack.agentdevice.multitouchhelper"),versionCode:(t=e.versionCode,r="versionCode",b(t,r,"multi-touch helper")),instrumentationRunner:ec(e.instrumentationRunner,"instrumentationRunner","com.callstack.agentdevice.multitouchhelper/.MultiTouchInstrumentation"),statusProtocol:ec(e.statusProtocol,"statusProtocol",j)}}(JSON.parse(await t.readFile(o,"utf8"))),i=r.join(a,e.assetName);return await t.access(i),{apkPath:i,manifest:e}}catch(e){throw new n("UNSUPPORTED_OPERATION","Android touch gestures require the bundled Android touch helper artifact, but it was not found or could not be read",{manifestPath:o,error:i(e).message},e)}}async function en(e){let{adb:t,artifact:r}=e,a=r.manifest.packageName,i=r.manifest.versionCode,o=`${e.deviceKey}\0${a}\0${i}`;if(eo.has(o))return{packageName:a,versionCode:i,installed:!1,reason:"current"};let s=await es(t,a);if(void 0!==s&&s>=i)return eo.add(o),{packageName:a,versionCode:i,installedVersionCode:s,installed:!1,reason:"current"};await ed(r);let d=await A(r.apkPath,{provider:e.adbProvider,replace:!0,allowTestPackages:!0,allowFailure:!0,timeoutMs:3e4});if(0!==d.exitCode)throw new n("COMMAND_FAILED","Failed to install Android multi-touch helper",{packageName:a,versionCode:i,stdout:d.stdout,stderr:d.stderr,exitCode:d.exitCode});return eo.add(o),{packageName:a,versionCode:i,installedVersionCode:s,installed:!0,reason:void 0===s?"missing":"outdated"}}let eo=new Set;async function es(e,t){let r=await e(["shell","cmd","package","list","packages","--show-versioncode",t],{allowFailure:!0,timeoutMs:5e3});if(0!==r.exitCode)return;let a=RegExp(`package:${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}(?:\\s|$).*versionCode:(\\d+)`).exec(`${r.stdout}
|
|
3
|
+
${r.stderr}`);return a?Number(a[1]):void 0}async function ed(e){let t=await el(e.apkPath);if(t!==e.manifest.sha256)throw new n("COMMAND_FAILED","Android multi-touch helper APK checksum mismatch",{apkPath:e.apkPath,expectedSha256:e.manifest.sha256,actualSha256:t})}async function el(r){let a=e.createHash("sha256");return a.update(await t.readFile(r)),a.digest("hex")}function eu(e,t){if("string"!=typeof e||0===e.length)throw new n("INVALID_ARGS",`Android multi-touch helper manifest ${t} is required.`);return e}function ec(e,t,r){return O(e,t,r,"multi-touch helper")}let ep=["window_animation_scale","transition_animation_scale","animator_duration_scale"];async function em(e,t,r,a,i){switch(t.toLowerCase()){case"wifi":{let t=G(r);await c(e,["shell","svc","wifi",t?"enable":"disable"]);return}case"airplane":{let t=G(r);await c(e,["shell","settings","put","global","airplane_mode_on",t?"1":"0"]),await c(e,["shell","am","broadcast","-a","android.intent.action.AIRPLANE_MODE","--ez","state",t?"true":"false"]);return}case"location":{if("set"===r.toLowerCase()){if("emulator"!==e.kind)throw new n("UNSUPPORTED_OPERATION","Android precise location coordinates are supported only on emulators.",{deviceId:e.id,hint:"Use an Android emulator for adb emu geo fix, or configure location through device/provider tooling."});let{latitude:t,longitude:r}=P(i);return await c(e,["emu","geo","fix",String(r),String(t)]),{latitude:t,longitude:r}}let t=G(r);await c(e,["shell","settings","put","secure","location_mode",t?"3":"0"]);return}case"animations":{let t=G(r)?"1":"0";for(let r of ep)await c(e,["shell","settings","put","global",r,t]);return{scale:t,keys:[...ep]}}case"appearance":{let t=await ef(e,r);await c(e,["shell","cmd","uimode","night","dark"===t?"yes":"no"]);return}case"clear-app-state":{if("clear"!==r.toLowerCase())throw new n("INVALID_ARGS","settings clear-app-state only supports clear.");if(!a)throw new n("INVALID_ARGS","settings clear-app-state requires an app id or an active app session.");let t=await p(e,a);if("intent"===t.type)throw new n("INVALID_ARGS","settings clear-app-state requires a package name, not an intent.");await c(e,["shell","am","force-stop",t.value],{allowFailure:!0});let i=await c(e,["shell","pm","clear",t.value],{allowFailure:!0});if(0!==i.exitCode||!/\bSuccess\b/i.test(i.stdout))throw new n("COMMAND_FAILED",`Failed to clear Android app data for ${t.value}`,{package:t.value,stdout:i.stdout,stderr:i.stderr,exitCode:i.exitCode});return{package:t.value,cleared:!0}}case"fingerprint":{let t=function(e){let t=e.trim().toLowerCase();if("match"===t)return"match";if("nonmatch"===t)return"nonmatch";throw new n("INVALID_ARGS",`Invalid fingerprint state: ${e}. Use match|nonmatch.`)}(r);await eh(e,t);return}case"permission":{if(!a)throw new n("INVALID_ARGS","permission setting requires an active app in session");let t=V(r),o=function(e,t){let r=K(e);if(t?.trim())throw new n("INVALID_ARGS",`Permission mode is only supported for photos. Received: ${t}.`);if("camera"===r)return{kind:"pm",value:"android.permission.CAMERA",type:"camera"};if("microphone"===r)return{kind:"pm",value:"android.permission.RECORD_AUDIO",type:"microphone"};if("photos"===r)return{kind:"pm",value:"android.permission.READ_MEDIA_IMAGES",type:"photos"};if("contacts"===r)return{kind:"pm",value:"android.permission.READ_CONTACTS",type:"contacts"};if("notifications"===r)return{kind:"notifications",appOps:"POST_NOTIFICATION",permission:"android.permission.POST_NOTIFICATIONS"};throw new n("INVALID_ARGS",`Unsupported permission target on Android: ${e}. Use camera|microphone|photos|contacts|notifications.`)}(i?.permissionTarget,i?.permissionMode);if("notifications"===o.kind)return void await e_(e,a,t,o);let s="grant"===t?"grant":"revoke";if("photos"===o.type)return void await ew(e,a,s);await c(e,["shell","pm",s,a,o.value]);return}default:throw new n("INVALID_ARGS",`Unsupported setting: ${t}`)}}async function eh(e,t){var r;let a,i,o=(r=e,i=[["shell","cmd","fingerprint","touch",a="match"===t?"1":"9999"],["shell","cmd","fingerprint","finger",a]],"emulator"===r.kind&&i.push(["emu","finger","touch",a]),i),s=[];for(let t of o){let r=await c(e,t,{allowFailure:!0});if(0===r.exitCode)return;s.push({args:t,stdout:r.stdout,stderr:r.stderr,exitCode:r.exitCode})}let d=$(s);if(s.length>0&&s.every(e=>{var t,r;let a;return t=e.stdout,r=e.stderr,(a=`${t}
|
|
4
|
+
${r}`.toLowerCase()).includes("unknown command")||a.includes("can't find service: fingerprint")||a.includes("service fingerprint was not found")||a.includes("fingerprint cmd unavailable")||a.includes("emu command is not supported")||a.includes("emulator console is not running")||a.includes("fingerprint")&&a.includes("not found")}))throw new n("UNSUPPORTED_OPERATION","Android fingerprint simulation is not supported on this target/runtime.",{deviceId:e.id,action:t,hint:"Use an Android emulator with biometric support, or a device/runtime that exposes cmd fingerprint.",attempts:d});throw new n("COMMAND_FAILED","Failed to simulate Android fingerprint.",{deviceId:e.id,action:t,attempts:d})}async function ef(e,t){let r=U(t);if("toggle"!==r)return r;let a=await c(e,["shell","cmd","uimode","night"],{allowFailure:!0});if(0!==a.exitCode)throw new n("COMMAND_FAILED","Failed to read current Android appearance",{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode});let i=function(e,t){let r=/night mode:\s*(yes|no|auto)\b/i.exec(`${e}
|
|
5
|
+
${t}`);if(!r)return null;let a=r[1]?.toLowerCase();return"yes"===a?"dark":"no"===a?"light":"auto"===a?"auto":null}(a.stdout,a.stderr);if(!i)throw new n("COMMAND_FAILED","Unable to determine current Android appearance for toggle",{stdout:a.stdout,stderr:a.stderr});return"auto"===i?"dark":"dark"===i?"light":"dark"}async function ew(e,t,r){let a=await eA(e),i=[];for(let n of null!==a&&a>=33?["android.permission.READ_MEDIA_IMAGES","android.permission.READ_EXTERNAL_STORAGE"]:["android.permission.READ_EXTERNAL_STORAGE","android.permission.READ_MEDIA_IMAGES"]){let a=await c(e,["shell","pm",r,t,n],{allowFailure:!0});if(0===a.exitCode)return;i.push({permission:n,stderr:a.stderr,exitCode:a.exitCode})}throw new n("COMMAND_FAILED",`Failed to ${r} Android photos permission`,{appPackage:t,sdkInt:a,attempts:i})}async function e_(e,t,r,a){"grant"===r?await c(e,["shell","pm","grant",t,a.permission],{allowFailure:!0}):(await c(e,["shell","pm","revoke",t,a.permission],{allowFailure:!0}),"reset"===r&&(await c(e,["shell","pm","clear-permission-flags",t,a.permission,"user-set"],{allowFailure:!0}),await c(e,["shell","pm","clear-permission-flags",t,a.permission,"user-fixed"],{allowFailure:!0}))),await c(e,["shell","appops","set",t,a.appOps,"grant"===r?"allow":"deny"===r?"deny":"default"])}async function eA(e){let t=await c(e,["shell","getprop","ro.build.version.sdk"],{allowFailure:!0});if(0!==t.exitCode)return null;let r=Number.parseInt(t.stdout.trim(),10);return!Number.isFinite(r)||r<=0?null:r}let eg=Buffer.from([137,80,78,71,13,10,26,10]);async function ey(e,t,r={}){if(!1===r.stabilize)return void await eI(e,t);await eN(e);try{await q(1e3),await eI(e,t)}finally{await ev(e).catch(()=>{})}}async function eN(e){let t=t=>c(e,["shell",t],{allowFailure:!0});await t("settings put global sysui_demo_allowed 1");let r=e=>t(`am broadcast -a com.android.systemui.demo -e command ${e}`);await r("clock -e hhmm 0941"),await r("notifications -e visible false")}async function ev(e){await c(e,["shell","am broadcast -a com.android.systemui.demo -e command exit"],{allowFailure:!0})}async function eI(e,t){let r=await c(e,["exec-out","screencap","-p"],{binaryStdout:!0});if(!r.stdoutBuffer)throw new n("COMMAND_FAILED","Failed to capture screenshot");let i=r.stdoutBuffer.indexOf(eg);if(i<0)throw new n("COMMAND_FAILED","Screenshot data does not contain a valid PNG header");let o=function(e,t){let r=t+eg.length;for(;r+8<=e.length;){let t=e.readUInt32BE(r),a=r+4,i=e.toString("ascii",a,a+4),n=r+12+t;if(n>e.length)break;if("IEND"===i)return n;r=n}return null}(r.stdoutBuffer,i);if(!o)throw new n("COMMAND_FAILED","Screenshot data does not contain a complete PNG payload");await a.writeFile(t,r.stdoutBuffer.subarray(i,o))}function eM(e){return{open:(t,r)=>f(e,t,{activity:r?.activity,appBundleId:r?.appBundleId,launchArgs:r?.launchArgs,url:r?.url}),openDevice:()=>u(e),close:t=>h(e,t),tap:(t,r)=>C(e,t,r),doubleTap:async(t,r)=>{await C(e,t,r),await C(e,t,r)},swipe:(t,r,a,i,n)=>X(e,{x1:t,y1:r,x2:a,y2:i,durationMs:n}),pan:(t,r,a,i,n)=>X(e,{x1:t,y1:r,x2:a,y2:i,durationMs:n}),fling:(t,r,a,i,n)=>X(e,{x1:t,y1:r,x2:a,y2:i,durationMs:n}),longPress:(t,r,a)=>v(e,t,r,a),focus:(t,r)=>k(e,t,r),type:(t,r)=>I(e,t,r),fill:(t,r,a,i)=>D(e,t,r,a,i),scroll:(t,r)=>N(e,t,r),pinch:(t,r,a)=>Q(e,{scale:t,x:r,y:a}),screenshot:(t,r)=>ey(e,t,r),snapshot:async t=>{let r=await o("snapshot_capture",async()=>await L(e,{appBundleId:t?.appBundleId,interactiveOnly:t?.interactiveOnly,depth:t?.depth,scope:t?.scope,raw:t?.raw,helperSessionScope:t?.appBundleId?"daemon-session":"command"}),{backend:"android"});return{nodes:r.nodes??[],truncated:r.truncated??!1,backend:"android",...T(r)}},back:t=>E(e),home:()=>y(e),rotate:t=>S(e,t),rotateGesture:(t,r,a,i)=>W(e,{degrees:t,x:r,y:a,velocity:i}),transformGesture:t=>Y(e,t),appSwitcher:()=>g(e),readClipboard:()=>B(e),writeClipboard:t=>H(e,t),setSetting:(t,r,a,i)=>em(e,t,r,a,i)}}export{eM as createAndroidInteractor};
|
package/dist/src/apps.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
let e;import{promises as t}from"node:fs";import i from"node:os";import a from"node:path";import{fileURLToPath as r}from"node:url";import{AppError as n}from"./733.js";import{runXcrun as o,IOS_RUNNER_CONTAINER_BUNDLE_IDS as l,resolveIosDevicectlHint as s,LAUNCH_CONSOLE_DIRECT_APP_ONLY_MESSAGE as d,runIosRunnerCommand as u,resolveAppleToolProvider as c,runSimctlForDevice as p,IOS_DEVICECTL_DEFAULT_HINT as f,readInfoPlistString as w,requireSimulatorDevice as m,buildSimctlArgsForDevice as h,runMacOsPermissionAction as y,runIosDevicectl as A,filterAppleAppsByBundlePrefix as I,runAppleToolCommand as v,listIosDeviceApps as g,quitMacOsApp as _,ensureBootedSimulator as C,LAUNCH_CONSOLE_IOS_SIMULATOR_ONLY_MESSAGE as b,getSimulatorState as N}from"./9722.js";import{runCmd as S}from"./8875.js";import{materializeInstallablePath as L,isTrustedInstallSourceUrl as D}from"./5484.js";import{parseAppearanceAction as M,summarizeCommandAttemptFailures as O,parseSettingState as P,parsePermissionTarget as F,parsePermissionAction as x}from"./8225.js";import{isWebUrl as R,createAppResolutionCache as $,isDeepLinkTarget as E,resolveIosSimulatorDeviceSetPath as k,resolveIosDeviceDeepLinkBundleId as T,retryWithPolicy as U,Deadline as B}from"./3340.js";import{emitDiagnostic as G}from"./432.js";import{getUnsupportedMacOsSettingMessage as V,requireLocationCoordinates as j}from"./2948.js";function W(e){if(!(e instanceof n)||"COMMAND_FAILED"!==e.code)return!1;let t=e.details??{};if(4!==t.exitCode)return!1;let i=String(t.stderr??"").toLowerCase();return i.includes("fbsopenapplicationserviceerrordomain")&&i.includes("the request to open")}async function H(e,t){let i=await o(h(e,["get_app_container",e.id,t]),{allowFailure:!0});if(0!==i.exitCode)return{installed:!1};let a=i.stdout.trim();if(!a)return{installed:!1};let r=await v("plutil",["-extract","CFBundleExecutable","raw","-o","-",`${a}/Info.plist`],{allowFailure:!0});if(0!==r.exitCode||!r.stdout.trim())return{installed:!0};let n=r.stdout.trim(),l=`${a}/${n}`,s=await v("otool",["-l",l],{allowFailure:!0});if(0!==s.exitCode)return{installed:!0};let d=s.stdout.toLowerCase();return{installed:!0,simulatorCompatible:d.includes("iossimulator")||d.includes("platform 7")}}async function K(e,t){let i;if("url"===e.kind&&!D(e.url))throw new n("INVALID_ARGS","iOS install_from_source URL sources are only supported for trusted artifact services such as GitHub Actions and EAS. Use a path source for other hosts.");let a=await L({source:e,isInstallablePath:(e,t)=>t.isDirectory()&&e.toLowerCase().endsWith(".app")||t.isFile()&&e.toLowerCase().endsWith(".ipa"),installableLabel:"iOS installable (.app or .ipa)",allowArchiveExtraction:"url"!==e.kind||D(e.url),signal:t?.signal});try{let e=i=await q(a.installablePath,t),r=await z(e.installPath);return{archivePath:a.archivePath??(a.installablePath.toLowerCase().endsWith(".ipa")?a.installablePath:void 0),installablePath:e.installPath,bundleId:r.bundleId,appName:r.appName,cleanup:async()=>{await e.cleanup(),await a.cleanup()}}}catch(e){try{await i?.cleanup()}finally{await a.cleanup()}throw e}}async function z(e){let t=a.join(e,"Info.plist"),[i,r,n]=await Promise.all([w(t,"CFBundleIdentifier"),w(t,"CFBundleDisplayName"),w(t,"CFBundleName")]);return{bundleId:i,appName:r??n}}async function q(e,r){if(!e.toLowerCase().endsWith(".ipa"))return{installPath:e,cleanup:async()=>{}};let o=await t.mkdtemp(a.join(i.tmpdir(),"agent-device-ios-ipa-")),l=async()=>{await t.rm(o,{recursive:!0,force:!0})};try{await S("unzip",["-q",e,"-d",o]);let i=a.join(o,"Payload"),s=(await t.readdir(i,{withFileTypes:!0}).catch(()=>{throw new n("INVALID_ARGS","Invalid IPA: missing Payload directory")})).filter(e=>e.isDirectory()&&e.name.toLowerCase().endsWith(".app")).map(e=>({installPath:a.join(i,e.name),bundleName:e.name.replace(/\.app$/i,"")})),d=s[0];if(void 0!==d&&1===s.length)return{installPath:d.installPath,cleanup:l};if(0===s.length)throw new n("INVALID_ARGS","Invalid IPA: expected at least one .app under Payload, found 0");await J(s);let u=r?.appIdentifierHint?.trim();if(u){let e=function(e,t){let i=t.toLowerCase(),a=e.filter(e=>e.bundleName.toLowerCase()===i);if(1===a.length)return a[0];if(a.length>1)throw new n("INVALID_ARGS",`Invalid IPA: multiple app bundles matched "${t}" by name. Use a bundle id hint instead.`);if(t.includes(".")){let t=e.filter(e=>e.bundleId?.toLowerCase()===i);if(1===t.length)return t[0]}}(s,u);if(e)return{installPath:e.installPath,cleanup:l};throw new n("INVALID_ARGS",`Invalid IPA: found ${s.length} .app bundles under Payload and none matched "${u}". Available bundles: ${s.map(Z).join(", ")}`)}throw new n("INVALID_ARGS",`Invalid IPA: found ${s.length} .app bundles under Payload. Pass an app identifier or bundle name matching one of: ${s.map(Z).join(", ")}`)}catch(e){throw await l(),e}}async function J(e){await Promise.all(e.map(async e=>{if(e.bundleId&&e.appName)return;let t=await z(e.installPath);e.bundleId=e.bundleId??t.bundleId,e.appName=e.appName??t.appName}))}function Z(e){let t=e.bundleId??e.appName;return t?`${e.bundleName}.app (${t})`:`${e.bundleName}.app`}let Q={settings:"com.apple.systempreferences"},X=/^[a-z0-9-]+(?:\.[a-z0-9-]+)+$/,Y={platform:"macos",deviceId:"host",variant:"all"},ee=$();async function et(e){let t=e.trim(),i=Q[t.toLowerCase()];if(i)return i;if(X.test(t))return t;let a=ee.get(Y,t);if(a)return a;let r=(await es("all")).filter(e=>e.name.toLowerCase()===t.toLowerCase()),o=r[0];if(void 0!==o&&1===r.length)return ee.set(Y,t,o.bundleId);if(r.length>1)throw new n("INVALID_ARGS",`Multiple apps matched "${e}"`,{matches:r});throw new n("APP_NOT_INSTALLED",`No app found matching "${e}"`)}async function ei(e,t,i){let a=i?.url?.trim();if(a){if(!E(a))throw new n("INVALID_ARGS","open <app> <url> requires a valid URL target");let e=i?.appBundleId??await et(t);await ed().openBundle(e,a);return}let r=t.trim();if(E(r))return void await ed().openTarget(r);let o=i?.appBundleId??await et(r);await ed().openBundle(o)}async function ea(e,t){let i=await et(t),a=await _(i);if(a.running&&!a.terminated&&!a.forceTerminated)throw new n("COMMAND_FAILED",`Failed to close macOS app ${t}`,{bundleId:i,running:a.running,terminated:a.terminated,forceTerminated:a.forceTerminated})}async function er(){return await ed().readClipboard()}async function en(e){await ed().writeClipboard(e)}async function eo(){return await ed().readDarkMode()}async function el(e){let t=M(e),i="toggle"===t?!await eo():"dark"===t;await ed().setDarkMode(i)}async function es(e){return await ed().listApps(e)}function ed(){let e=c().macosHost;if(!e)throw new n("UNSUPPORTED_OPERATION","macOS host provider is not available");return e}function eu(e){if(!(e instanceof n))return{reason:e instanceof Error?e.message:String(e)};let t=e.details??{},i=Array.isArray(t.args)?t.args.filter(e=>"string"==typeof e).join(" "):void 0;return{errorCode:e.code,reason:e.message,timeoutMs:"number"==typeof t.timeoutMs?t.timeoutMs:void 0,exitCode:"number"==typeof t.exitCode?t.exitCode:void 0,stderr:"string"==typeof t.stderr&&t.stderr.trim()?t.stderr:void 0,stdout:"string"==typeof t.stdout&&t.stdout.trim()?t.stdout:void 0,commandArgs:i}}let ec=["--time","9:41","--dataNetwork","wifi","--wifiMode","active","--wifiBars","3","--batteryState","charged","--batteryLevel","100"],ep={0:"hide",1:"wifi",6:"3g",7:"4g",8:"lte",9:"lte-a",10:"lte+",11:"5g",12:"5g+",13:"5g-uwb",14:"5g-uc"},ef={1:"searching",2:"failed",3:"active"},ew={0:"notSupported",1:"searching",2:"failed",3:"active"};async function em(e){let t=null,i=!1;try{t=await ey(e),i=!0}catch(t){ev(e,"snapshot_failed",t)}try{await eA(e),await eI(e,ec)}catch(t){ev(e,"prepare_failed",t)}return async()=>{await eh(e,i?t:null)}}async function eh(e,t){var i,a;let r;await eA(e),t&&await eI(e,(r=[],(i=t).dataNetwork&&r.push("--dataNetwork",i.dataNetwork),i.wifiMode&&r.push("--wifiMode",i.wifiMode),void 0!==i.wifiBars&&("wifi"===i.dataNetwork||i.wifiMode)&&r.push("--wifiBars",i.wifiBars),i.cellularMode&&r.push("--cellularMode",i.cellularMode),void 0!==i.cellularBars&&(i.cellularMode||(a=i.dataNetwork)&&"hide"!==a&&"wifi"!==a||void 0!==i.operatorName)&&r.push("--cellularBars",i.cellularBars),void 0!==i.operatorName&&r.push("--operatorName",i.operatorName),r))}async function ey(e){var t;let i=await (t=["status_bar",e.id,"list"],p(e,t,{allowFailure:!0}));if(0!==i.exitCode)throw new n("COMMAND_FAILED","Failed to read simulator status bar overrides",{exitCode:i.exitCode,stdout:i.stdout,stderr:i.stderr});return function(e){let t={};for(let i of e.split("\n").map(e=>e.trim()).filter(e=>e.length>0&&"Current Status Bar Overrides:"!==e&&!/^=+$/.test(e))){let e=/^DataNetworkType:\s+(\d+)$/.exec(i);if(e){let i=Number(e[1]),a=ep[i];if(!a)throw new n("COMMAND_FAILED",`Unsupported simulator data network type: ${i}`);t.dataNetwork=a;continue}let a=/^WiFi Mode:\s+(\d+),\s+WiFi Bars:\s+(\d+)$/.exec(i);if(a){let e=ef[Number(a[1])];e&&(t.wifiMode=e),t.wifiBars=a[2];continue}let r=/^Cell Mode:\s+(\d+),\s+Cell Bars:\s+(\d+)$/.exec(i);if(r){let e=Number(r[1]),i=ew[e];if(!i)throw new n("COMMAND_FAILED",`Unsupported simulator cellular mode: ${e}`);t.cellularMode=i,t.cellularBars=r[2];continue}let o=/^Operator Name:\s*(.*)$/.exec(i);if(o){t.operatorName=o[1]??"";continue}}return 0===Object.keys(t).length?null:t}(i.stdout)}async function eA(e){await p(e,["status_bar",e.id,"clear"],void 0)}async function eI(e,t){0!==t.length&&await p(e,["status_bar",e.id,"override",...t],void 0)}function ev(e,t,i){G({level:"warn",phase:`ios_screenshot_status_bar_${t}`,data:{platform:e.platform,deviceKind:e.kind,deviceId:e.id,...eu(i)}})}let eg={ensureBooted:C,prepareStatusBarForScreenshot:em,captureWithRetry:eb,captureWithRunner:eN,shouldFallbackToRunner:eP};async function e_(e,t,i,a,r){if("macos"===e.platform)return void await eN(e,t,i,a,r);if("simulator"===e.kind)return void await eC(e,t,i,a,void 0,r);try{await A(["device","screenshot","--device",e.id,t],{action:"capture iOS screenshot",deviceId:e.id});return}catch(t){if(!function(e){if(!(e instanceof n)||"COMMAND_FAILED"!==e.code)return!1;let t=e.details??{},i="string"==typeof t.stdout?t.stdout:"",a="string"==typeof t.stderr?t.stderr:"",r=`${e.message}
|
|
2
|
-
${i}
|
|
3
|
-
${a}`.toLowerCase();return r.includes("unknown option '--device'")||r.includes("unknown subcommand")&&r.includes("screenshot")||r.includes("unrecognized subcommand")&&r.includes("screenshot")}(t))throw t;eM(e,"devicectl_screenshot",t)}await eN(e,t,i,a,r)}async function eC(e,t,i,a,r=eg,o){if("simulator"!==e.kind)throw new n("UNSUPPORTED_OPERATION","Simulator screenshot fallback flow supports only iOS simulators");let l="object"==typeof a&&null!==a?a:r;await l.ensureBooted(e);let s=async()=>{};try{s=await l.prepareStatusBarForScreenshot(e)}catch(t){eO(e,"prepare_failed",t)}try{try{await l.captureWithRetry(e,t);return}catch(t){if(!l.shouldFallbackToRunner(t))throw t;eM(e,"simctl_screenshot",t)}await l.captureWithRunner(e,t,i,"boolean"==typeof a?a:void 0,o)}finally{await s().catch(t=>eO(e,"restore_failed",t))}}async function eb(e,t){let i=B.fromTimeoutMs(2e4);await U(async({deadline:i})=>{var a;await (a=["io",e.id,"screenshot",t],p(e,a,{timeoutMs:Math.max(1e3,i?.remainingMs()??2e4)}))},{maxAttempts:5,baseDelayMs:1e3,maxDelayMs:5e3,jitter:.2,shouldRetry:e=>eP(e)},{deadline:i,phase:"ios_simulator_screenshot"})}async function eN(e,i,a,r,o){let l=(await u(e,{command:"screenshot",appBundleId:a,fullscreen:r},o)).message;if(!l)throw new n("COMMAND_FAILED","Failed to capture iOS screenshot: runner returned no file path");"macos"===e.platform?await t.copyFile(l,i):"simulator"===e.kind?await eL(e,l,i):await eS(e,l,i)}async function eS(e,t,i){let a=B.fromTimeoutMs(2e4),r={exitCode:1,stdout:"",stderr:""};for(let n of l)if(0===(r=await o(["devicectl","device","copy","from","--device",e.id,"--source",t,"--destination",i,"--domain-type","appDataContainer","--domain-identifier",n],{allowFailure:!0,timeoutMs:eD(a,2e4,"runner screenshot copy")})).exitCode)return;let s=r.stderr.trim()||r.stdout.trim()||`devicectl exited with code ${r.exitCode}`;throw new n("COMMAND_FAILED",`Failed to capture iOS screenshot: ${s}`)}async function eL(e,i,r){let o=B.fromTimeoutMs(2e4),s="Unable to locate runner container for simulator screenshot";for(let n of l){var d;let l=await (d=["get_app_container",e.id,n,"data"],p(e,d,{allowFailure:!0,timeoutMs:eD(o,2e4,"runner screenshot container lookup")}));if(0!==l.exitCode){let e=l.stderr.trim();e&&(s=e);continue}let u=l.stdout.trim();if(!u){s="simctl get_app_container returned empty output";continue}for(let e of function(e,t){let i=a.resolve(e),r=t.trim();if(!r)return[];let n=[],o=new Set,l=e=>{let t=a.normalize(e);o.has(t)||(o.add(t),n.push(t))},s=r.replace(/^\/+/,""),d=s.replace(/\\/g,"/");if(s&&l(a.join(i,s)),a.isAbsolute(r)&&l(a.normalize(r)),d.startsWith("tmp/"))l(a.join(i,d));else{let e=d.lastIndexOf("/tmp/");if(e>=0){let t=d.slice(e+1);l(a.join(i,t))}}let u=a.basename(r);return u&&l(a.join(i,"tmp",u)),n}(u,i))try{await t.copyFile(e,r);return}catch(e){s=e instanceof Error?e.message:String(e)}}throw new n("COMMAND_FAILED",`Failed to capture iOS screenshot: ${s}`)}function eD(e,t,i){let a=e.remainingMs();if(a>0)return a;throw new n("COMMAND_FAILED",`iOS ${i} timed out after ${t}ms`,{timeoutMs:t,step:i})}function eM(e,t,i){let a=eu(i);G({level:"warn",phase:"ios_screenshot_fallback",data:{platform:e.platform,deviceKind:e.kind,deviceId:e.id,from:t,to:"runner",...a}})}function eO(e,t,i){G({level:"warn",phase:`ios_screenshot_status_bar_${t}`,data:{platform:e.platform,deviceKind:e.kind,deviceId:e.id,...eu(i)}})}function eP(e){if(!(e instanceof n)||"COMMAND_FAILED"!==e.code)return!1;let t=e.details??{},i="string"==typeof t.stdout?t.stdout:"",a="string"==typeof t.stderr?t.stderr:"",r=Array.isArray(t.args)?t.args.filter(e=>"string"==typeof e).join(" "):"",o=`${e.message}
|
|
1
|
+
let e;import{promises as t}from"node:fs";import i from"node:os";import a from"node:path";import{fileURLToPath as r}from"node:url";import{AppError as n}from"./485.js";import{runXcrun as o,resolveIosDevicectlHint as l,LAUNCH_CONSOLE_DIRECT_APP_ONLY_MESSAGE as s,resolveAppleToolProvider as d,runSimctlForDevice as u,IOS_DEVICECTL_DEFAULT_HINT as c,readInfoPlistString as p,buildSimctlArgsForDevice as f,runAppleRunnerCommand as w,runMacOsPermissionAction as m,runIosDevicectl as h,filterAppleAppsByBundlePrefix as y,runAppleToolCommand as A,listIosDeviceApps as I,quitMacOsApp as _,LAUNCH_CONSOLE_IOS_SIMULATOR_ONLY_MESSAGE as C,IOS_RUNNER_CONTAINER_BUNDLE_IDS as v}from"./9722.js";import{runCmd as g}from"./8875.js";import{materializeInstallablePath as b,isTrustedInstallSourceUrl as N}from"./5484.js";import{parseAppearanceAction as S,summarizeCommandAttemptFailures as L,parseSettingState as D,parsePermissionTarget as M,parsePermissionAction as O}from"./8225.js";import{isWebUrl as P,createAppResolutionCache as F,isDeepLinkTarget as R,resolveIosSimulatorDeviceSetPath as x,resolveIosDeviceDeepLinkBundleId as $,retryWithPolicy as k,Deadline as E}from"./3340.js";import{emitDiagnostic as T}from"./432.js";import{requireSimulatorDevice as U,ensureBootedSimulator as B,getSimulatorState as G}from"./simulator.js";import{getUnsupportedMacOsSettingMessage as V,requireLocationCoordinates as j}from"./2948.js";function W(e){if(!(e instanceof n)||"COMMAND_FAILED"!==e.code)return!1;let t=e.details??{};if(4!==t.exitCode)return!1;let i=String(t.stderr??"").toLowerCase();return i.includes("fbsopenapplicationserviceerrordomain")&&i.includes("the request to open")}async function K(e,t){let i=await o(f(e,["get_app_container",e.id,t]),{allowFailure:!0});if(0!==i.exitCode)return{installed:!1};let a=i.stdout.trim();if(!a)return{installed:!1};let r=await A("plutil",["-extract","CFBundleExecutable","raw","-o","-",`${a}/Info.plist`],{allowFailure:!0});if(0!==r.exitCode||!r.stdout.trim())return{installed:!0};let n=r.stdout.trim(),l=`${a}/${n}`,s=await A("otool",["-l",l],{allowFailure:!0});if(0!==s.exitCode)return{installed:!0};let d=s.stdout.toLowerCase();return{installed:!0,simulatorCompatible:d.includes("iossimulator")||d.includes("platform 7")}}async function H(e,t){let i;if("url"===e.kind&&!N(e.url))throw new n("INVALID_ARGS","iOS install_from_source URL sources are only supported for trusted artifact services such as GitHub Actions and EAS. Use a path source for other hosts.");let a=await b({source:e,isInstallablePath:(e,t)=>t.isDirectory()&&e.toLowerCase().endsWith(".app")||t.isFile()&&e.toLowerCase().endsWith(".ipa"),installableLabel:"iOS installable (.app or .ipa)",allowArchiveExtraction:"url"!==e.kind||N(e.url),signal:t?.signal});try{let e=i=await q(a.installablePath,t),r=await z(e.installPath);return{archivePath:a.archivePath??(a.installablePath.toLowerCase().endsWith(".ipa")?a.installablePath:void 0),installablePath:e.installPath,bundleId:r.bundleId,appName:r.appName,cleanup:async()=>{await e.cleanup(),await a.cleanup()}}}catch(e){try{await i?.cleanup()}finally{await a.cleanup()}throw e}}async function z(e){let t=a.join(e,"Info.plist"),[i,r,n]=await Promise.all([p(t,"CFBundleIdentifier"),p(t,"CFBundleDisplayName"),p(t,"CFBundleName")]);return{bundleId:i,appName:r??n}}async function q(e,r){if(!e.toLowerCase().endsWith(".ipa"))return{installPath:e,cleanup:async()=>{}};let o=await t.mkdtemp(a.join(i.tmpdir(),"agent-device-ios-ipa-")),l=async()=>{await t.rm(o,{recursive:!0,force:!0})};try{await g("unzip",["-q",e,"-d",o]);let i=a.join(o,"Payload"),s=(await t.readdir(i,{withFileTypes:!0}).catch(()=>{throw new n("INVALID_ARGS","Invalid IPA: missing Payload directory")})).filter(e=>e.isDirectory()&&e.name.toLowerCase().endsWith(".app")).map(e=>({installPath:a.join(i,e.name),bundleName:e.name.replace(/\.app$/i,"")})),d=s[0];if(void 0!==d&&1===s.length)return{installPath:d.installPath,cleanup:l};if(0===s.length)throw new n("INVALID_ARGS","Invalid IPA: expected at least one .app under Payload, found 0");await J(s);let u=r?.appIdentifierHint?.trim();if(u){let e=function(e,t){let i=t.toLowerCase(),a=e.filter(e=>e.bundleName.toLowerCase()===i);if(1===a.length)return a[0];if(a.length>1)throw new n("INVALID_ARGS",`Invalid IPA: multiple app bundles matched "${t}" by name. Use a bundle id hint instead.`);if(t.includes(".")){let t=e.filter(e=>e.bundleId?.toLowerCase()===i);if(1===t.length)return t[0]}}(s,u);if(e)return{installPath:e.installPath,cleanup:l};throw new n("INVALID_ARGS",`Invalid IPA: found ${s.length} .app bundles under Payload and none matched "${u}". Available bundles: ${s.map(Z).join(", ")}`)}throw new n("INVALID_ARGS",`Invalid IPA: found ${s.length} .app bundles under Payload. Pass an app identifier or bundle name matching one of: ${s.map(Z).join(", ")}`)}catch(e){throw await l(),e}}async function J(e){await Promise.all(e.map(async e=>{if(e.bundleId&&e.appName)return;let t=await z(e.installPath);e.bundleId=e.bundleId??t.bundleId,e.appName=e.appName??t.appName}))}function Z(e){let t=e.bundleId??e.appName;return t?`${e.bundleName}.app (${t})`:`${e.bundleName}.app`}let Q={settings:"com.apple.systempreferences"},X=/^[a-z0-9-]+(?:\.[a-z0-9-]+)+$/,Y={platform:"macos",deviceId:"host",variant:"all"},ee=F();async function et(e){let t=e.trim(),i=Q[t.toLowerCase()];if(i)return i;if(X.test(t))return t;let a=ee.get(Y,t);if(a)return a;let r=(await es("all")).filter(e=>e.name.toLowerCase()===t.toLowerCase()),o=r[0];if(void 0!==o&&1===r.length)return ee.set(Y,t,o.bundleId);if(r.length>1)throw new n("INVALID_ARGS",`Multiple apps matched "${e}"`,{matches:r});throw new n("APP_NOT_INSTALLED",`No app found matching "${e}"`)}async function ei(e,t,i){let a=i?.url?.trim();if(a){if(!R(a))throw new n("INVALID_ARGS","open <app> <url> requires a valid URL target");let e=i?.appBundleId??await et(t);await ed().openBundle(e,a);return}let r=t.trim();if(R(r))return void await ed().openTarget(r);let o=i?.appBundleId??await et(r);await ed().openBundle(o)}async function ea(e,t){let i=await et(t),a=await _(i);if(a.running&&!a.terminated&&!a.forceTerminated)throw new n("COMMAND_FAILED",`Failed to close macOS app ${t}`,{bundleId:i,running:a.running,terminated:a.terminated,forceTerminated:a.forceTerminated})}async function er(){return await ed().readClipboard()}async function en(e){await ed().writeClipboard(e)}async function eo(){return await ed().readDarkMode()}async function el(e){let t=S(e),i="toggle"===t?!await eo():"dark"===t;await ed().setDarkMode(i)}async function es(e){return await ed().listApps(e)}function ed(){let e=d().macosHost;if(!e)throw new n("UNSUPPORTED_OPERATION","macOS host provider is not available");return e}function eu(e){if(!(e instanceof n))return{reason:e instanceof Error?e.message:String(e)};let t=e.details??{},i=Array.isArray(t.args)?t.args.filter(e=>"string"==typeof e).join(" "):void 0;return{errorCode:e.code,reason:e.message,timeoutMs:"number"==typeof t.timeoutMs?t.timeoutMs:void 0,exitCode:"number"==typeof t.exitCode?t.exitCode:void 0,stderr:"string"==typeof t.stderr&&t.stderr.trim()?t.stderr:void 0,stdout:"string"==typeof t.stdout&&t.stdout.trim()?t.stdout:void 0,commandArgs:i}}let ec=["--time","9:41","--dataNetwork","wifi","--wifiMode","active","--wifiBars","3","--batteryState","charged","--batteryLevel","100"],ep={0:"hide",1:"wifi",6:"3g",7:"4g",8:"lte",9:"lte-a",10:"lte+",11:"5g",12:"5g+",13:"5g-uwb",14:"5g-uc"},ef={1:"searching",2:"failed",3:"active"},ew={0:"notSupported",1:"searching",2:"failed",3:"active"},em=new Set;async function eh(e){var t;let i=null,a=!1;if(t=e,em.has(eI(t)))a=!0;else try{i=await e_(e),a=!0}catch(t){eg(e,"snapshot_failed",t)}try{(!a||i)&&await eC(e),await ev(e,ec)}catch(t){eg(e,"prepare_failed",t)}return async()=>{await ey(e,a?i:null)}}async function ey(e,t){var i,a,r;let n;(await eC(e),t)?(await ev(e,(n=[],(i=t).dataNetwork&&n.push("--dataNetwork",i.dataNetwork),i.wifiMode&&n.push("--wifiMode",i.wifiMode),void 0!==i.wifiBars&&("wifi"===i.dataNetwork||i.wifiMode)&&n.push("--wifiBars",i.wifiBars),i.cellularMode&&n.push("--cellularMode",i.cellularMode),void 0!==i.cellularBars&&(i.cellularMode||(a=i.dataNetwork)&&"hide"!==a&&"wifi"!==a||void 0!==i.operatorName)&&n.push("--cellularBars",i.cellularBars),void 0!==i.operatorName&&n.push("--operatorName",i.operatorName),n)),eA(e)):(r=e,em.add(eI(r)))}function eA(e){em.delete(eI(e))}function eI(e){return`${e.platform}:${e.kind}:${e.id}`}async function e_(e){var t;let i=await (t=["status_bar",e.id,"list"],u(e,t,{allowFailure:!0}));if(0!==i.exitCode)throw new n("COMMAND_FAILED","Failed to read simulator status bar overrides",{exitCode:i.exitCode,stdout:i.stdout,stderr:i.stderr});return function(e){let t={};for(let i of e.split("\n").map(e=>e.trim()).filter(e=>e.length>0&&"Current Status Bar Overrides:"!==e&&!/^=+$/.test(e))){let e=/^DataNetworkType:\s+(\d+)$/.exec(i);if(e){let i=Number(e[1]),a=ep[i];if(!a)throw new n("COMMAND_FAILED",`Unsupported simulator data network type: ${i}`);t.dataNetwork=a;continue}let a=/^WiFi Mode:\s+(\d+),\s+WiFi Bars:\s+(\d+)$/.exec(i);if(a){let e=ef[Number(a[1])];e&&(t.wifiMode=e),t.wifiBars=a[2];continue}let r=/^Cell Mode:\s+(\d+),\s+Cell Bars:\s+(\d+)$/.exec(i);if(r){let e=Number(r[1]),i=ew[e];if(!i)throw new n("COMMAND_FAILED",`Unsupported simulator cellular mode: ${e}`);t.cellularMode=i,t.cellularBars=r[2];continue}let o=/^Operator Name:\s*(.*)$/.exec(i);if(o){t.operatorName=o[1]??"";continue}}return 0===Object.keys(t).length?null:t}(i.stdout)}async function eC(e){await u(e,["status_bar",e.id,"clear"],void 0)}async function ev(e,t){0!==t.length&&await u(e,["status_bar",e.id,"override",...t],void 0)}function eg(e,t,i){T({level:"warn",phase:`ios_screenshot_status_bar_${t}`,data:{platform:e.platform,deviceKind:e.kind,deviceId:e.id,...eu(i)}})}let eb={ensureBooted:B,prepareStatusBarForScreenshot:eh,captureWithRetry:eL,captureWithRunner:eD,shouldFallbackToRunner:ex};async function eN(e,t,i={}){if("macos"===e.platform)return void await eD(e,t,i.appBundleId,i.fullscreen,i.runnerOptions);if("simulator"===e.kind)return void await eS(e,t,i);try{await h(["device","screenshot","--device",e.id,t],{action:"capture iOS screenshot",deviceId:e.id});return}catch(t){if(!function(e){if(!(e instanceof n)||"COMMAND_FAILED"!==e.code)return!1;let t=e$(e);return t.includes("unknown option '--device'")||t.includes("unknown subcommand")&&t.includes("screenshot")||t.includes("unrecognized subcommand")&&t.includes("screenshot")}(t))throw t;eF(e,"devicectl_screenshot",t)}await eD(e,t,i.appBundleId,i.fullscreen,i.runnerOptions)}async function eS(e,t,i={}){if("simulator"!==e.kind)throw new n("UNSUPPORTED_OPERATION","Simulator screenshot fallback flow supports only iOS simulators");let a=i.deps??eb;i.skipIosSimulatorBootCheck||await a.ensureBooted(e);let r=async()=>{};if(!0===i.normalizeStatusBar)try{r=await a.prepareStatusBarForScreenshot(e)}catch(t){eR(e,"prepare_failed",t)}try{try{await a.captureWithRetry(e,t);return}catch(o){let r=o;if(i.skipIosSimulatorBootCheck&&function(e){if(!(e instanceof n)||"COMMAND_FAILED"!==e.code)return!1;let t=e$(e);return t.includes("not booted")||t.includes("current state: shutdown")||t.includes("current state is shutdown")||t.includes("current state=shutdown")||t.includes("state: shutdown")||t.includes("state=shutdown")}(o)){await a.ensureBooted(e);try{await a.captureWithRetry(e,t);return}catch(e){r=e}}if(!a.shouldFallbackToRunner(r))throw r;eF(e,"simctl_screenshot",r)}await a.captureWithRunner(e,t,i.appBundleId,i.fullscreen,i.runnerOptions)}finally{await r().catch(t=>eR(e,"restore_failed",t))}}async function eL(e,t){let i=E.fromTimeoutMs(2e4);await k(async({deadline:i})=>{var a;await (a=["io",e.id,"screenshot",t],u(e,a,{timeoutMs:Math.max(1e3,i?.remainingMs()??2e4)}))},{maxAttempts:5,baseDelayMs:1e3,maxDelayMs:5e3,jitter:.2,shouldRetry:e=>ex(e)},{deadline:i,phase:"ios_simulator_screenshot"})}async function eD(e,i,a,r,o){let l=(await w(e,{command:"screenshot",appBundleId:a,fullscreen:r},o)).message;if(!l)throw new n("COMMAND_FAILED","Failed to capture iOS screenshot: runner returned no file path");"macos"===e.platform?await t.copyFile(l,i):"simulator"===e.kind?await eO(e,l,i):await eM(e,l,i)}async function eM(e,t,i){let a=E.fromTimeoutMs(2e4),r={exitCode:1,stdout:"",stderr:""};for(let n of v)if(0===(r=await o(["devicectl","device","copy","from","--device",e.id,"--source",t,"--destination",i,"--domain-type","appDataContainer","--domain-identifier",n],{allowFailure:!0,timeoutMs:eP(a,2e4,"runner screenshot copy")})).exitCode)return;let l=r.stderr.trim()||r.stdout.trim()||`devicectl exited with code ${r.exitCode}`;throw new n("COMMAND_FAILED",`Failed to capture iOS screenshot: ${l}`)}async function eO(e,i,r){let o=E.fromTimeoutMs(2e4),l="Unable to locate runner container for simulator screenshot";for(let n of v){var s;let d=await (s=["get_app_container",e.id,n,"data"],u(e,s,{allowFailure:!0,timeoutMs:eP(o,2e4,"runner screenshot container lookup")}));if(0!==d.exitCode){let e=d.stderr.trim();e&&(l=e);continue}let c=d.stdout.trim();if(!c){l="simctl get_app_container returned empty output";continue}for(let e of function(e,t){let i=a.resolve(e),r=t.trim();if(!r)return[];let n=[],o=new Set,l=e=>{let t=a.normalize(e);o.has(t)||(o.add(t),n.push(t))},s=r.replace(/^\/+/,""),d=s.replace(/\\/g,"/");if(s&&l(a.join(i,s)),a.isAbsolute(r)&&l(a.normalize(r)),d.startsWith("tmp/"))l(a.join(i,d));else{let e=d.lastIndexOf("/tmp/");if(e>=0){let t=d.slice(e+1);l(a.join(i,t))}}let u=a.basename(r);return u&&l(a.join(i,"tmp",u)),n}(c,i))try{await t.copyFile(e,r);return}catch(e){l=e instanceof Error?e.message:String(e)}}throw new n("COMMAND_FAILED",`Failed to capture iOS screenshot: ${l}`)}function eP(e,t,i){let a=e.remainingMs();if(a>0)return a;throw new n("COMMAND_FAILED",`iOS ${i} timed out after ${t}ms`,{timeoutMs:t,step:i})}function eF(e,t,i){let a=eu(i);T({level:"warn",phase:"ios_screenshot_fallback",data:{platform:e.platform,deviceKind:e.kind,deviceId:e.id,from:t,to:"runner",...a}})}function eR(e,t,i){T({level:"warn",phase:`ios_screenshot_status_bar_${t}`,data:{platform:e.platform,deviceKind:e.kind,deviceId:e.id,...eu(i)}})}function ex(e){if(!(e instanceof n)||"COMMAND_FAILED"!==e.code)return!1;let t=e$(e);return t.includes("timeout waiting for screen surfaces")||t.includes("nsposixerrordomain")&&t.includes("code=60")&&t.includes("screenshot")||t.includes("timed out")&&t.includes("screenshot")}function e$(e){let t=e.details??{},i="string"==typeof t.stdout?t.stdout:"",a="string"==typeof t.stderr?t.stderr:"",r=Array.isArray(t.args)?t.args.filter(e=>"string"==typeof e).join(" "):"";return`${e.message}
|
|
4
2
|
${i}
|
|
5
3
|
${a}
|
|
6
|
-
${r}`.toLowerCase()
|
|
7
|
-
${o}`.toLowerCase()))throw new n("COMMAND_FAILED",`Failed to uninstall iOS app ${i}`,{cmd:"xcrun",args:t,exitCode:a.exitCode,stdout:r,stderr:o,deviceId:e.id,hint:
|
|
8
|
-
${a.stderr}`.toLowerCase()))throw new n("COMMAND_FAILED",`simctl uninstall failed for ${i}`,{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode});return{bundleId:i}})}async function
|
|
9
|
-
`,"utf8"),await
|
|
10
|
-
${t}`);if(!i)return null;let a=i[1]?.toLowerCase();return"dark"===a?"dark":"light"===a?"light":null}(a.stdout,a.stderr);if(!r)throw new n("COMMAND_FAILED","Unable to determine current iOS appearance for toggle",{stdout:a.stdout,stderr:a.stderr});return"dark"===r?"light":"dark"}let
|
|
11
|
-
${r.stderr}`);if(0===o.size)throw new n("COMMAND_FAILED","Unable to determine supported simctl privacy services",{stdout:r.stdout,stderr:r.stderr,exitCode:r.exitCode,hint:"Run `xcrun simctl privacy help` manually to verify available services for this runtime."});return
|
|
12
|
-
${i}`.toLowerCase()).includes("unrecognized subcommand")||a.includes("unknown subcommand")||a.includes("not supported")||a.includes("unavailable")||a.includes("biometric")&&a.includes("invalid")}))throw new n("UNSUPPORTED_OPERATION",`${i.label} simulation is not supported on this simulator runtime.`,{deviceId:e.id,action:t,setting:i.settingName,attempts:l});throw new n("COMMAND_FAILED",`Failed to simulate ${i.settingName}.`,{deviceId:e.id,action:t,setting:i.settingName,attempts:l})}async function
|
|
13
|
-
${n}`),"utf8")}async function
|
|
4
|
+
${r}`.toLowerCase()}let ek={settings:"com.apple.Preferences"},eE=F(),eT=null;function eU(e){return{platform:"ios",deviceId:e.id,variant:e.kind}}function eB(e,t,i){return o(f(e,t),i)}function eG(e){return e.includes("not installed")||e.includes("not found")||e.includes("no such file")}async function eV(e,t){if("macos"===e.platform)return await et(t);let i=t.trim();if(i.includes("."))return i;let a=ek[i.toLowerCase()];if(a)return a;let r=eU(e),o=eE.get(r,i);if(o)return o;let l=("simulator"===e.kind?await e3(e):await I(e,"all")).filter(e=>e.name.toLowerCase()===i.toLowerCase()),s=l[0];if(void 0!==s&&1===l.length)return eE.set(r,i,s.bundleId);if(l.length>1)throw new n("INVALID_ARGS",`Multiple apps matched "${t}"`,{matches:l});throw new n("APP_NOT_INSTALLED",`No app found matching "${t}"`)}async function ej(e,t){var i;let r;if("ios"!==e.platform||"simulator"!==e.kind)return;let n=(i=t,r=/^([A-Za-z][A-Za-z0-9+.-]*):/.exec(i.trim()),r?.[1]?.toLowerCase());if(!n)return;let o=await e5(e),l=[];for(let e of o)!e.bundleId.startsWith("com.callstack.agentdevice.runner")&&e.path&&(await e8(a.join(e.path,"Info.plist"))).has(n)&&l.push(e);let s=l.filter(e=>"User"===e.applicationType);return 1===s.length?s[0]?.bundleId:s.length>1?void 0:1===l.length?l[0]?.bundleId:void 0}async function eW(e,t,i){let a=i?.launchConsole?.trim(),r=i?.launchArgs;if(a&&("ios"!==e.platform||"simulator"!==e.kind))throw new n("UNSUPPORTED_OPERATION",C);if("macos"===e.platform){if(r&&r.length>0)throw new n("UNSUPPORTED_OPERATION","--launch-args is not supported on macOS; launch arguments are currently iOS-only.");await ei(e,t,i);return}let o=i?.url?.trim();if(o){if(a)throw new n("INVALID_ARGS",s);if(!R(o))throw new n("INVALID_ARGS","open <app> <url> requires a valid URL target");if("simulator"===e.kind){if(r||P(o)){let a=i?.appBundleId??await eV(e,t);await ta(e,a,{...r?{launchArgs:r}:{}})}await eK(e,o,void 0);return}let l=$(i?.appBundleId??await eV(e,t),o);if(!l)throw new n("INVALID_ARGS","Deep link open on iOS devices requires an active app bundle ID. Open the app first, then open the URL.");await to(e,l,{payloadUrl:o,launchArgs:r});return}let l=t.trim();if(R(l)){if(a)throw new n("INVALID_ARGS",s);if("simulator"===e.kind)return void await eK(e,l,r);let t=$(i?.appBundleId,l);if(!t)throw new n("INVALID_ARGS","Deep link open on iOS devices requires an active app bundle ID. Open the app first, then open the URL.");return void await to(e,t,{payloadUrl:l,launchArgs:r})}let d=i?.appBundleId??await eV(e,t);"simulator"===e.kind?await ta(e,d,{...a?{launchConsole:a}:{},...r?{launchArgs:r}:{}}):await to(e,d,{launchArgs:r})}async function eK(e,t,i){if(i&&i.length>0)throw new n("INVALID_ARGS","--launch-args is not supported with iOS simulator URL opens (simctl openurl ignores launch args). Launch the app first with --launch-args, then issue the URL open in a separate call.");await B(e),await eB(e,["openurl",e.id,t])}async function eH(e){"macos"===e.platform||"simulator"!==e.kind||"Booted"!==await G(e)&&await B(e)}async function ez(e,t){if("macos"===e.platform)return void await ea(e,t);let i=await eV(e,t);if("simulator"===e.kind){await B(e);let t=f(e,["terminate",e.id,i]),a=await o(t,{allowFailure:!0,timeoutMs:15e3});if(0!==a.exitCode){if(a.stderr.toLowerCase().includes("found nothing to terminate"))return;throw new n("COMMAND_FAILED",`xcrun exited with code ${a.exitCode}`,{cmd:"xcrun",args:t,stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode})}return}await h(["device","process","terminate","--device",e.id,i],{action:"terminate iOS app",deviceId:e.id})}async function eq(e,i){if("ios"!==e.platform||"simulator"!==e.kind)throw new n("UNSUPPORTED_OPERATION","Clearing app state is currently supported only on iOS simulators.");let r=await eV(e,i);await B(e),await ez(e,r);let o=await eB(e,["get_app_container",e.id,r,"data"],{allowFailure:!0});if(0!==o.exitCode)throw new n("COMMAND_FAILED",`simctl get_app_container failed for ${r}`,{stdout:o.stdout,stderr:o.stderr,exitCode:o.exitCode});let l=o.stdout.trim();if(!l)throw new n("COMMAND_FAILED",`simctl get_app_container returned an empty data container path for ${r}`);let s=await t.readdir(l);return await Promise.all(s.map(e=>t.rm(a.join(l,e),{recursive:!0,force:!0}))),{bundleId:r,containerPath:l}}async function eJ(e,t){return await eE.invalidateWhile(eU(e),async()=>{let i=await eV(e,t);if("simulator"!==e.kind){let t=["devicectl","device","uninstall","app","--device",e.id,i],a=await o(t,{allowFailure:!0,timeoutMs:2e4});if(0!==a.exitCode){let r=String(a.stdout??""),o=String(a.stderr??"");if(!eG(`${r}
|
|
5
|
+
${o}`.toLowerCase()))throw new n("COMMAND_FAILED",`Failed to uninstall iOS app ${i}`,{cmd:"xcrun",args:t,exitCode:a.exitCode,stdout:r,stderr:o,deviceId:e.id,hint:l(r,o)??c})}return{bundleId:i}}await B(e);let a=await eB(e,["uninstall",e.id,i],{allowFailure:!0});if(0!==a.exitCode&&!eG(`${a.stdout}
|
|
6
|
+
${a.stderr}`.toLowerCase()))throw new n("COMMAND_FAILED",`simctl uninstall failed for ${i}`,{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode});return{bundleId:i}})}async function eZ(e,t,i){let a=await H({kind:"path",path:t},i);try{return await eX(e,a.installablePath),{archivePath:a.archivePath,installablePath:a.installablePath,bundleId:a.bundleId,appName:a.appName,launchTarget:a.bundleId}}finally{await a.cleanup()}}async function eQ(e,t,i){return await eE.invalidateWhile(eU(e),async()=>{let{bundleId:a}=await eJ(e,t);return await eZ(e,i,{appIdentifierHint:t}),{bundleId:a}})}async function eX(e,t){await eE.invalidateWhile(eU(e),async()=>{"simulator"!==e.kind?await h(["device","install","app","--device",e.id,t],{action:"install iOS app",deviceId:e.id},{timeoutMs:12e4}):(await B(e),await eB(e,["install",e.id,t]))})}async function eY(e){if("macos"===e.platform)return await er();U(e,"clipboard"),await B(e);let t=await eB(e,["pbpaste",e.id],{allowFailure:!0});if(0!==t.exitCode)throw new n("COMMAND_FAILED","Failed to read iOS simulator clipboard",{stdout:t.stdout,stderr:t.stderr,exitCode:t.exitCode});return t.stdout.replace(/\r\n/g,"\n").replace(/\n$/,"")}async function e0(e,t){if("macos"===e.platform)return void await en(t);U(e,"clipboard"),await B(e);let i=await eB(e,["pbcopy",e.id],{allowFailure:!0,stdin:t});if(0!==i.exitCode)throw new n("COMMAND_FAILED","Failed to write iOS simulator clipboard",{stdout:i.stdout,stderr:i.stderr,exitCode:i.exitCode})}async function e1(e,r,n){U(e,"push"),await B(e);let o=await t.mkdtemp(a.join(i.tmpdir(),"agent-device-ios-push-")),l=a.join(o,"payload.apns");try{await t.writeFile(l,`${JSON.stringify(n)}
|
|
7
|
+
`,"utf8"),await eB(e,["push",e.id,r,l])}finally{await t.rm(o,{recursive:!0,force:!0})}}async function e2(e,t,i,a,r){if("macos"===e.platform){let e=t.toLowerCase();if("appearance"===e)return void await el(i);if("permission"===e){let e=O(i);if("deny"===e)throw new n("INVALID_ARGS",V("permission"));let t=function(e){let t=e?.trim().toLowerCase();if("accessibility"===t||"screen-recording"===t||"input-monitoring"===t)return t;throw new n("INVALID_ARGS","Unsupported macOS permission target. Use accessibility|screen-recording|input-monitoring.")}(r?.permissionTarget);return await m(e,t)}throw new n("INVALID_ARGS",V(t))}U(e,"settings"),await B(e);let o=t.toLowerCase();switch(o){case"clear-app-state":{if("clear"!==i.toLowerCase())throw new n("INVALID_ARGS","settings clear-app-state only supports clear.");if(!a)throw new n("INVALID_ARGS","settings clear-app-state requires an app id or an active app session.");let t=await eq(e,a);return{bundleId:t.bundleId,containerPath:t.containerPath,cleared:!0}}case"wifi":{let t=D(i);await eB(e,["status_bar",e.id,"override","--wifiMode",t?"active":"failed"]),eA(e);return}case"airplane":if(D(i))await eB(e,["status_bar",e.id,"override","--dataNetwork","hide","--wifiMode","failed","--wifiBars","0","--cellularMode","failed","--cellularBars","0","--operatorName",""]),eA(e);else await eB(e,["status_bar",e.id,"clear"]),em.add(eI(e));return;case"location":{if("set"===i.toLowerCase()){let{latitude:t,longitude:i}=j(r);return await eB(e,["location",e.id,"set",`${t},${i}`]),{latitude:t,longitude:i}}let t=D(i);if(!a)throw new n("INVALID_ARGS","location setting requires an active app in session");await eB(e,["privacy",e.id,t?"grant":"revoke","location",a]);return}case"faceid":case"touchid":{let t=e6[o],a=function(e,t){let i=e.trim().toLowerCase();if("match"===i)return"match";if("nonmatch"===i)return"nonmatch";if("enroll"===i)return"enroll";if("unenroll"===i)return"unenroll";throw new n("INVALID_ARGS",`Invalid ${t} state: ${e}. Use match|nonmatch|enroll|unenroll.`)}(i,o);await ti(e,a,{settingName:o,label:t.label,modalityAliases:t.modalityAliases});return}case"appearance":{let t=await e9(e,i);await eB(e,["ui",e.id,"appearance",t]);return}case"permission":{var l;if(!a)throw new n("INVALID_ARGS","permission setting requires an active app in session");let t="deny"===(l=O(i))?"revoke":l,o=function(e,t){let i=M(e);if("photos"!==i&&t?.trim())throw new n("INVALID_ARGS",`Permission mode is only supported for photos. Received: ${t}.`);if("camera"===i)return"camera";if("microphone"===i)return"microphone";if("contacts"===i)return"contacts";if("contacts-limited"===i)return"contacts-limited";if("notifications"===i)return"notifications";if("calendar"===i)return"calendar";if("location"===i)return"location";if("location-always"===i)return"location-always";if("media-library"===i)return"media-library";if("motion"===i)return"motion";if("reminders"===i)return"reminders";if("siri"===i)return"siri";if("photos"===i){let e=t?.trim().toLowerCase();if(!e||"full"===e)return"photos";if("limited"===e)return"photos-add";throw new n("INVALID_ARGS",`Invalid photos mode: ${t}. Use full|limited.`)}throw new n("INVALID_ARGS",`Unsupported permission target: ${e}. Use camera|microphone|photos|contacts|contacts-limited|notifications|calendar|location|location-always|media-library|motion|reminders|siri.`)}(r?.permissionTarget,r?.permissionMode);await e7(e,t,o,a);return}default:throw new n("INVALID_ARGS",`Unsupported setting: ${t}`)}}async function e4(e,t){return"macos"===e.platform?await es(t):"simulator"===e.kind?y(await e3(e),t):await I(e,t)}async function e3(e){return(await e5(e)).map(e=>({bundleId:e.bundleId,name:e.name}))}async function e5(e){let t=(await eB(e,["listapps",e.id],{allowFailure:!0})).stdout.trim();if(!t)return[];let i=null;if(t.startsWith("{"))try{i=JSON.parse(t)}catch{i=null}if(!i&&t.startsWith("{"))try{let e=await A("plutil",["-convert","json","-o","-","-"],{allowFailure:!0,stdin:t});0===e.exitCode&&e.stdout.trim().startsWith("{")&&(i=JSON.parse(e.stdout))}catch{i=null}return i?Object.entries(i).map(([e,t])=>{let i=function(e){if(e.Path)return e.Path;if(e.Bundle)try{return r(e.Bundle)}catch{return}}(t);return{bundleId:e,name:t.CFBundleDisplayName??t.CFBundleName??e,...i?{path:i}:{},...t.ApplicationType?{applicationType:t.ApplicationType}:{}}}):[]}async function e8(e){let t=await A("plutil",["-convert","json","-o","-",e],{allowFailure:!0});if(0!==t.exitCode)return new Set;try{let e=JSON.parse(t.stdout),i=new Set;for(let t of e.CFBundleURLTypes??[])if(Array.isArray(t.CFBundleURLSchemes))for(let e of t.CFBundleURLSchemes)"string"==typeof e&&e.trim()&&i.add(e.trim().toLowerCase());return i}catch{return new Set}}async function e9(e,t){let i=S(t);if("toggle"!==i)return i;let a=await eB(e,["ui",e.id,"appearance"],{allowFailure:!0});if(0!==a.exitCode)throw new n("COMMAND_FAILED","Failed to read current iOS appearance",{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode});let r=function(e,t){let i=/\b(light|dark|unsupported|unknown)\b/i.exec(`${e}
|
|
8
|
+
${t}`);if(!i)return null;let a=i[1]?.toLowerCase();return"dark"===a?"dark":"light"===a?"light":null}(a.stdout,a.stderr);if(!r)throw new n("COMMAND_FAILED","Unable to determine current iOS appearance for toggle",{stdout:a.stdout,stderr:a.stderr});return"dark"===r?"light":"dark"}let e6={faceid:{label:"Face ID",modalityAliases:["face"]},touchid:{label:"Touch ID",modalityAliases:["finger","touch"]}};async function e7(e,t,i,a){let r=await tt(e);if(!r.has(i))throw new n("UNSUPPORTED_OPERATION",`iOS simctl privacy does not support service "${i}" on this runtime.`,{deviceId:e.id,appBundleId:a,hint:`Supported services: ${Array.from(r).sort().join(", ")}`});let o=["privacy",e.id,t,i,a],l="notifications"===i;if(!("reset"===t&&l))try{await eB(e,o);return}catch(t){if(!(l&&te(t)))throw t;throw new n("UNSUPPORTED_OPERATION","iOS simulator does not support setting notifications permission via simctl privacy on this runtime.",{deviceId:e.id,appBundleId:a,hint:"Use reset notifications for reprompt behavior, or toggle notifications manually in Settings."})}try{await eB(e,o);return}catch(e){if(!te(e))throw e}try{await eB(e,["privacy",e.id,"reset","all",a])}catch(t){throw new n("COMMAND_FAILED","iOS simulator blocked direct notifications reset. Fallback reset-all also failed.",{deviceId:e.id,appBundleId:a,hint:"Use reinstall to force a fresh notifications prompt, or reset simulator content and settings."},t instanceof Error?t:void 0)}}function te(e){if(!(e instanceof n)||"COMMAND_FAILED"!==e.code)return!1;let t=String(e.details?.stderr??"").toLowerCase();return(t.includes("failed to grant access")||t.includes("failed to revoke access")||t.includes("failed to reset access"))&&t.includes("operation not permitted")}async function tt(t){let i=x(t.simulatorSetPath),a=`${process.env.PATH??""}::${i??""}`;if(eT&&e===a)return eT;let r=await eB(t,["privacy","help"],{allowFailure:!0}),o=function(e){let t=new Set,i=!1;for(let a of e.split("\n")){let e=a.trim();if(!e)continue;if("service"===e){i=!0;continue}if(!i)continue;if(e.startsWith("bundle identifier"))break;let r=/^([a-z-]+)\s+-\s+/.exec(e),n=r?.[1];void 0!==n&&t.add(n)}return t}(`${r.stdout}
|
|
9
|
+
${r.stderr}`);if(0===o.size)throw new n("COMMAND_FAILED","Unable to determine supported simctl privacy services",{stdout:r.stdout,stderr:r.stderr,exitCode:r.exitCode,hint:"Run `xcrun simctl privacy help` manually to verify available services for this runtime."});return eT=o,e=a,o}async function ti(e,t,i){let a=function(e,t,i){let a=i.length>0?i:["face"];switch(t){case"match":return a.flatMap(t=>[["biometric",e,"match",t],["biometric","match",e,t]]);case"nonmatch":return a.flatMap(t=>[["biometric",e,"nonmatch",t],["biometric",e,"nomatch",t],["biometric","nonmatch",e,t],["biometric","nomatch",e,t]]);case"enroll":return[["biometric",e,"enroll","yes"],["biometric",e,"enroll","1"],["biometric","enroll",e,"yes"],["biometric","enroll",e,"1"]];case"unenroll":return[["biometric",e,"enroll","no"],["biometric",e,"enroll","0"],["biometric","enroll",e,"no"],["biometric","enroll",e,"0"]]}}(e.id,t,i.modalityAliases),r=[];for(let t of a){let i=f(e,t),a=await o(i,{allowFailure:!0});if(0===a.exitCode)return;r.push({args:i,stderr:a.stderr,stdout:a.stdout,exitCode:a.exitCode})}let l=L(r);if(r.length>0&&r.every(e=>{var t,i;let a;return t=e.stdout,i=e.stderr,(a=`${t}
|
|
10
|
+
${i}`.toLowerCase()).includes("unrecognized subcommand")||a.includes("unknown subcommand")||a.includes("not supported")||a.includes("unavailable")||a.includes("biometric")&&a.includes("invalid")}))throw new n("UNSUPPORTED_OPERATION",`${i.label} simulation is not supported on this simulator runtime.`,{deviceId:e.id,action:t,setting:i.settingName,attempts:l});throw new n("COMMAND_FAILED",`Failed to simulate ${i.settingName}.`,{deviceId:e.id,action:t,setting:i.settingName,attempts:l})}async function ta(e,t,i){await B(e);let a=0,r=E.fromTimeoutMs(6e4);try{await k(async({deadline:a})=>{var r,l,s,d;let u;if(a?.isExpired())throw new n("COMMAND_FAILED","App launch deadline exceeded",{timeoutMs:6e4});let c=(l=e.id,s=t,d=i,u=["launch"],d?.launchConsole&&u.push("--console-pty"),u.push(l,s),d?.launchArgs&&d.launchArgs.length>0&&u.push(...d.launchArgs),r=u,f(e,r)),p=i?.launchConsole?await tr(c,i.launchConsole):await o(c,{allowFailure:!0});if(0!==p.exitCode)throw new n("COMMAND_FAILED",`xcrun exited with code ${p.exitCode}`,{cmd:"xcrun",args:c,stdout:p.stdout,stderr:p.stderr,exitCode:p.exitCode})},{maxAttempts:10,baseDelayMs:1e3,maxDelayMs:5e3,jitter:.2,shouldRetry:e=>!!W(e)&&(a+=1)<3},{deadline:r})}catch(i){if(W(i)){var l;let a=(l=await K(e,t)).installed?!1===l.simulatorCompatible?"ARCH_MISMATCH":"PERSISTENT_LAUNCH_FAIL":"APP_NOT_INSTALLED";i.details={...i.details,hint:function(e){switch(e){case"ARCH_MISMATCH":return"The app binary was not built for the simulator platform. Rebuild with a simulator destination or use a physical device.";case"APP_NOT_INSTALLED":return"The app bundle is not installed on this simulator. Run install before open.";case"PERSISTENT_LAUNCH_FAIL":return"The simulator repeatedly refused to launch the app. Inspect crash logs in Console.app or ~/Library/Logs/DiagnosticReports/ and consider reinstalling the app.";default:return"The simulator failed to launch the app. Retry with --debug and inspect diagnostics log for details."}}(a)}}throw i}}async function tr(e,i){await t.mkdir(a.dirname(i),{recursive:!0});try{let t=await o(e,{allowFailure:!0,timeoutMs:25e3});return await tn(i,t.stdout,t.stderr),t}catch(t){let e=(t instanceof n?t:void 0)?.details;if(e?.timeoutMs===25e3){let t="string"==typeof e.stdout?e.stdout:"",a="string"==typeof e.stderr?e.stderr:"";return await tn(i,t,a),T({level:"warn",phase:"ios_simulator_launch_console_capture_timeout",data:{timeoutMs:25e3,logPath:i,stdoutBytes:Buffer.byteLength(t),stderrBytes:Buffer.byteLength(a)}}),{stdout:t,stderr:a,exitCode:0}}throw t}}async function tn(e,i,a){var r,n;await t.writeFile(e,(r=i,n=a,!r||!n||r.endsWith("\n")||r.endsWith("\r")?`${r}${n}`:`${r}
|
|
11
|
+
${n}`),"utf8")}async function to(e,t,i){let a=["device","process","launch","--device",e.id,t];i?.payloadUrl&&a.push("--payload-url",i.payloadUrl),i?.launchArgs&&i.launchArgs.length>0&&a.push("--",...i.launchArgs),await h(a,{action:"launch iOS app",deviceId:e.id})}export{ez as closeIosApp,eZ as installIosApp,eX as installIosInstallablePath,e4 as listIosApps,eW as openIosApp,eH as openIosDevice,H as prepareIosInstallArtifact,e1 as pushIosNotification,eY as readIosClipboardText,eQ as reinstallIosApp,eV as resolveIosApp,ej as resolveIosSimulatorDeepLinkBundleId,eN as screenshotIos,e2 as setIosSetting,e0 as writeIosClipboardText};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{startMacOsAudioProbeProcess as e}from"./9722.js";let t={platform:"host-system-audio",source:"system-audio",backend:"macos-screencapturekit",sourceCount:1,start:e,notes:function(e){let t="ios"===e.platform?"iOS simulator":"android"===e.platform?"Android emulator":"macOS session";return[`Audio probe samples host system audio through ScreenCaptureKit for this ${t}; it is not app-instrumented audio.`,"Screen Recording permission is required for host system audio capture.","Other audible host apps can contribute to the measured buckets."]}};export{t as macOsScreenCaptureKitAudioProbeBackend};
|