devlens-mcp 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +10 -21
  2. package/dist/src/server.js +1 -1
  3. package/docs/setup-guide.md +39 -34
  4. package/package.json +1 -1
  5. package/.claude/settings.json +0 -12
  6. package/.claude/settings.local.json +0 -17
  7. package/bin/cli.ts +0 -22
  8. package/bin/register.ts +0 -96
  9. package/src/config/devlens-config.ts +0 -76
  10. package/src/index.ts +0 -5
  11. package/src/metro/cdp-client.ts +0 -160
  12. package/src/metro/log-collector.ts +0 -137
  13. package/src/metro/metro-bridge.ts +0 -307
  14. package/src/metro/network-inspector.ts +0 -134
  15. package/src/platform/android/adb.ts +0 -200
  16. package/src/platform/android/android-device.ts +0 -116
  17. package/src/platform/android/ui-automator.ts +0 -141
  18. package/src/platform/device-manager.ts +0 -229
  19. package/src/platform/device.ts +0 -110
  20. package/src/platform/ios/accessibility.ts +0 -189
  21. package/src/platform/ios/ios-device.ts +0 -116
  22. package/src/platform/ios/simctl.ts +0 -244
  23. package/src/server.ts +0 -228
  24. package/src/snapshot/formatter.ts +0 -102
  25. package/src/snapshot/ref-registry.ts +0 -230
  26. package/src/snapshot/snapshot-differ.ts +0 -220
  27. package/src/tools/app-tools.ts +0 -111
  28. package/src/tools/device-tools.ts +0 -96
  29. package/src/tools/ds-tools.ts +0 -395
  30. package/src/tools/interaction-tools.ts +0 -467
  31. package/src/tools/metro-tools.ts +0 -320
  32. package/src/tools/navigation-tools.ts +0 -71
  33. package/src/tools/screenshot-tools.ts +0 -698
  34. package/src/tools/snapshot-tools.ts +0 -585
  35. package/src/utils/image-preprocess.ts +0 -430
  36. package/src/utils/retry.ts +0 -51
  37. package/src/visual/comparator.ts +0 -191
  38. package/src/visual/layout-analyzer.ts +0 -283
  39. package/src/visual/screenshot.ts +0 -49
@@ -1,200 +0,0 @@
1
- import { execFile } from "child_process";
2
- import { promisify } from "util";
3
- import { retry } from "../../utils/retry.js";
4
-
5
- const execFileAsync = promisify(execFile);
6
-
7
- /**
8
- * ADB command wrapper — handles all communication with Android devices via ADB.
9
- */
10
- export class Adb {
11
- private adbPath: string;
12
-
13
- constructor(private deviceId: string) {
14
- const androidHome =
15
- process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT;
16
- this.adbPath = androidHome
17
- ? `${androidHome}/platform-tools/adb`
18
- : "adb";
19
- }
20
-
21
- /** Execute an ADB shell command on the device (with retry for transient failures) */
22
- async shell(command: string): Promise<string> {
23
- return retry(
24
- async () => {
25
- const { stdout } = await execFileAsync(
26
- this.adbPath,
27
- ["-s", this.deviceId, "shell", command],
28
- { maxBuffer: 10 * 1024 * 1024, timeout: 30000 }
29
- );
30
- return stdout;
31
- },
32
- { maxAttempts: 2, delayMs: 500 }
33
- );
34
- }
35
-
36
- /** Execute an ADB command (non-shell) */
37
- async exec(...args: string[]): Promise<string> {
38
- const { stdout } = await execFileAsync(
39
- this.adbPath,
40
- ["-s", this.deviceId, ...args],
41
- { maxBuffer: 10 * 1024 * 1024, timeout: 30000 }
42
- );
43
- return stdout;
44
- }
45
-
46
- /** Take a screenshot and return the PNG buffer (with retry) */
47
- async screenshot(): Promise<Buffer> {
48
- return retry(
49
- async () => {
50
- const { stdout } = await execFileAsync(
51
- this.adbPath,
52
- ["-s", this.deviceId, "exec-out", "screencap", "-p"],
53
- { maxBuffer: 20 * 1024 * 1024, encoding: "buffer", timeout: 15000 }
54
- );
55
- return stdout as unknown as Buffer;
56
- },
57
- { maxAttempts: 2, delayMs: 300 }
58
- );
59
- }
60
-
61
- /** Dump the UI hierarchy XML (with retry) */
62
- async dumpUiHierarchy(): Promise<string> {
63
- return retry(
64
- async () => {
65
- const dumpPath = "/sdcard/devlens-ui-dump.xml";
66
- await execFileAsync(
67
- this.adbPath,
68
- ["-s", this.deviceId, "shell", `uiautomator dump ${dumpPath}`],
69
- { maxBuffer: 10 * 1024 * 1024, timeout: 30000 }
70
- );
71
- const { stdout: xml } = await execFileAsync(
72
- this.adbPath,
73
- ["-s", this.deviceId, "shell", `cat ${dumpPath}`],
74
- { maxBuffer: 10 * 1024 * 1024, timeout: 30000 }
75
- );
76
- // Clean up
77
- execFileAsync(
78
- this.adbPath,
79
- ["-s", this.deviceId, "shell", `rm ${dumpPath}`]
80
- ).catch(() => {});
81
- return xml;
82
- },
83
- { maxAttempts: 2, delayMs: 500 }
84
- );
85
- }
86
-
87
- /** Tap at screen coordinates */
88
- async tap(x: number, y: number): Promise<void> {
89
- await this.shell(`input tap ${Math.round(x)} ${Math.round(y)}`);
90
- }
91
-
92
- /** Long press at coordinates */
93
- async longPress(x: number, y: number, durationMs: number = 1000): Promise<void> {
94
- await this.shell(
95
- `input swipe ${Math.round(x)} ${Math.round(y)} ${Math.round(x)} ${Math.round(y)} ${durationMs}`
96
- );
97
- }
98
-
99
- /** Swipe between two points */
100
- async swipe(
101
- startX: number,
102
- startY: number,
103
- endX: number,
104
- endY: number,
105
- durationMs: number = 300
106
- ): Promise<void> {
107
- await this.shell(
108
- `input swipe ${Math.round(startX)} ${Math.round(startY)} ${Math.round(endX)} ${Math.round(endY)} ${durationMs}`
109
- );
110
- }
111
-
112
- /** Type text using ADB input */
113
- async typeText(text: string): Promise<void> {
114
- // Escape special characters for ADB shell
115
- const escaped = text
116
- .replace(/\\/g, "\\\\")
117
- .replace(/"/g, '\\"')
118
- .replace(/ /g, "%s")
119
- .replace(/'/g, "\\'")
120
- .replace(/&/g, "\\&")
121
- .replace(/</g, "\\<")
122
- .replace(/>/g, "\\>")
123
- .replace(/\|/g, "\\|")
124
- .replace(/;/g, "\\;")
125
- .replace(/\(/g, "\\(")
126
- .replace(/\)/g, "\\)");
127
- await this.shell(`input text "${escaped}"`);
128
- }
129
-
130
- /** Press a key event */
131
- async keyEvent(keyCode: number): Promise<void> {
132
- await this.shell(`input keyevent ${keyCode}`);
133
- }
134
-
135
- /** Get device screen size */
136
- async getScreenSize(): Promise<{ width: number; height: number }> {
137
- const output = await this.shell("wm size");
138
- const match = output.match(/(\d+)x(\d+)/);
139
- if (!match) throw new Error("Could not determine screen size");
140
- return { width: parseInt(match[1]), height: parseInt(match[2]) };
141
- }
142
-
143
- /** Get device orientation (0=portrait, 1=landscape, 2=reverse-portrait, 3=reverse-landscape) */
144
- async getOrientation(): Promise<number> {
145
- const output = await this.shell(
146
- "dumpsys input | grep 'SurfaceOrientation'"
147
- );
148
- const match = output.match(/SurfaceOrientation:\s*(\d)/);
149
- return match ? parseInt(match[1]) : 0;
150
- }
151
-
152
- /** Get Android version */
153
- async getAndroidVersion(): Promise<string> {
154
- return (await this.shell("getprop ro.build.version.release")).trim();
155
- }
156
-
157
- /** Get device model name */
158
- async getDeviceName(): Promise<string> {
159
- return (await this.shell("getprop ro.product.model")).trim();
160
- }
161
-
162
- /** Launch an app by package name */
163
- async launchApp(packageName: string): Promise<void> {
164
- await this.shell(
165
- `monkey -p ${packageName} -c android.intent.category.LAUNCHER 1`
166
- );
167
- }
168
-
169
- /** Force stop an app */
170
- async terminateApp(packageName: string): Promise<void> {
171
- await this.shell(`am force-stop ${packageName}`);
172
- }
173
-
174
- /** Install an APK */
175
- async installApp(apkPath: string): Promise<void> {
176
- await this.exec("install", "-r", apkPath);
177
- }
178
-
179
- /** List installed packages */
180
- async listPackages(): Promise<string[]> {
181
- const output = await this.shell("pm list packages -3");
182
- return output
183
- .split("\n")
184
- .filter((line) => line.startsWith("package:"))
185
- .map((line) => line.replace("package:", "").trim());
186
- }
187
-
188
- /** Open a URL */
189
- async openUrl(url: string): Promise<void> {
190
- await this.shell(
191
- `am start -a android.intent.action.VIEW -d "${url}"`
192
- );
193
- }
194
-
195
- /** Set orientation (0=auto, 1=portrait, 2=landscape) */
196
- async setRotation(rotation: number): Promise<void> {
197
- await this.shell("settings put system accelerometer_rotation 0");
198
- await this.shell(`settings put system user_rotation ${rotation}`);
199
- }
200
- }
@@ -1,116 +0,0 @@
1
- import type { Device, DeviceInfo, AppInfo, SnapshotNode } from "../device.js";
2
- import { Adb } from "./adb.js";
3
- import { parseUiAutomatorXml } from "./ui-automator.js";
4
-
5
- // Android key codes
6
- const KEY_HOME = 3;
7
- const KEY_BACK = 4;
8
- const KEY_ENTER = 66;
9
-
10
- export class AndroidDevice implements Device {
11
- private adb: Adb;
12
-
13
- constructor(deviceId: string) {
14
- this.adb = new Adb(deviceId);
15
- }
16
-
17
- async getInfo(): Promise<DeviceInfo> {
18
- const [screenSize, orientation, version, name] = await Promise.all([
19
- this.adb.getScreenSize(),
20
- this.adb.getOrientation(),
21
- this.adb.getAndroidVersion(),
22
- this.adb.getDeviceName(),
23
- ]);
24
-
25
- return {
26
- id: (this.adb as any).deviceId,
27
- name,
28
- platform: "android",
29
- osVersion: version,
30
- screenWidth: screenSize.width,
31
- screenHeight: screenSize.height,
32
- orientation: orientation === 0 || orientation === 2 ? "portrait" : "landscape",
33
- isBooted: true,
34
- };
35
- }
36
-
37
- async getSnapshot(): Promise<SnapshotNode> {
38
- const xml = await this.adb.dumpUiHierarchy();
39
- return parseUiAutomatorXml(xml);
40
- }
41
-
42
- async takeScreenshot(): Promise<Buffer> {
43
- return this.adb.screenshot();
44
- }
45
-
46
- async tap(x: number, y: number): Promise<void> {
47
- await this.adb.tap(x, y);
48
- }
49
-
50
- async doubleTap(x: number, y: number): Promise<void> {
51
- await this.adb.tap(x, y);
52
- await sleep(100);
53
- await this.adb.tap(x, y);
54
- }
55
-
56
- async longPress(x: number, y: number, durationMs = 1000): Promise<void> {
57
- await this.adb.longPress(x, y, durationMs);
58
- }
59
-
60
- async typeText(text: string): Promise<void> {
61
- await this.adb.typeText(text);
62
- }
63
-
64
- async swipe(
65
- startX: number,
66
- startY: number,
67
- endX: number,
68
- endY: number,
69
- durationMs = 300
70
- ): Promise<void> {
71
- await this.adb.swipe(startX, startY, endX, endY, durationMs);
72
- }
73
-
74
- async pressButton(button: "home" | "back" | "enter"): Promise<void> {
75
- const keyMap: Record<string, number> = {
76
- home: KEY_HOME,
77
- back: KEY_BACK,
78
- enter: KEY_ENTER,
79
- };
80
- await this.adb.keyEvent(keyMap[button]);
81
- }
82
-
83
- async setOrientation(orientation: "portrait" | "landscape"): Promise<void> {
84
- const rotation = orientation === "portrait" ? 0 : 1;
85
- await this.adb.setRotation(rotation);
86
- }
87
-
88
- async launchApp(appId: string): Promise<void> {
89
- await this.adb.launchApp(appId);
90
- }
91
-
92
- async terminateApp(appId: string): Promise<void> {
93
- await this.adb.terminateApp(appId);
94
- }
95
-
96
- async installApp(path: string): Promise<void> {
97
- await this.adb.installApp(path);
98
- }
99
-
100
- async listApps(): Promise<AppInfo[]> {
101
- const packages = await this.adb.listPackages();
102
- return packages.map((pkg) => ({
103
- appId: pkg,
104
- name: pkg,
105
- isRunning: false, // Would need `ps` to determine
106
- }));
107
- }
108
-
109
- async openUrl(url: string): Promise<void> {
110
- await this.adb.openUrl(url);
111
- }
112
- }
113
-
114
- function sleep(ms: number): Promise<void> {
115
- return new Promise((resolve) => setTimeout(resolve, ms));
116
- }
@@ -1,141 +0,0 @@
1
- import { XMLParser } from "fast-xml-parser";
2
- import type { SnapshotNode, Bounds } from "../device.js";
3
-
4
- /**
5
- * Parses Android UI Automator XML dump into SnapshotNode tree.
6
- *
7
- * The XML format from `uiautomator dump` looks like:
8
- * <hierarchy rotation="0">
9
- * <node index="0" text="" resource-id="..." class="android.widget.FrameLayout"
10
- * package="com.example" content-desc="" checkable="false" checked="false"
11
- * clickable="false" enabled="true" focusable="false" focused="false"
12
- * scrollable="false" long-clickable="false" password="false" selected="false"
13
- * bounds="[0,0][1080,2340]">
14
- * <node ... />
15
- * </node>
16
- * </hierarchy>
17
- */
18
- export function parseUiAutomatorXml(xml: string): SnapshotNode {
19
- const parser = new XMLParser({
20
- ignoreAttributes: false,
21
- attributeNamePrefix: "@_",
22
- allowBooleanAttributes: true,
23
- isArray: (name) => name === "node",
24
- });
25
-
26
- const parsed = parser.parse(xml);
27
- const hierarchy = parsed.hierarchy;
28
-
29
- if (!hierarchy || !hierarchy.node) {
30
- throw new Error(
31
- "Invalid UI Automator dump: no hierarchy or root node found"
32
- );
33
- }
34
-
35
- const rootNodes: any[] = Array.isArray(hierarchy.node)
36
- ? hierarchy.node
37
- : [hierarchy.node];
38
-
39
- // Create a virtual root that contains all top-level nodes
40
- return {
41
- type: "hierarchy",
42
- text: undefined,
43
- label: undefined,
44
- description: undefined,
45
- bounds: { x: 0, y: 0, width: 0, height: 0 },
46
- interactive: false,
47
- children: rootNodes.map(convertNode),
48
- };
49
- }
50
-
51
- function convertNode(node: any): SnapshotNode {
52
- const bounds = parseBounds(node["@_bounds"] || "[0,0][0,0]");
53
- const text = node["@_text"] || undefined;
54
- const description = node["@_content-desc"] || undefined;
55
- const resourceId = node["@_resource-id"] || undefined;
56
- const className = node["@_class"] || "unknown";
57
-
58
- const clickable = node["@_clickable"] === "true";
59
- const longClickable = node["@_long-clickable"] === "true";
60
- const checkable = node["@_checkable"] === "true";
61
- const scrollable = node["@_scrollable"] === "true";
62
- const focusable = node["@_focusable"] === "true";
63
- const interactive =
64
- clickable || longClickable || checkable || scrollable || focusable;
65
-
66
- const children: SnapshotNode[] = [];
67
- if (node.node) {
68
- const childNodes = Array.isArray(node.node) ? node.node : [node.node];
69
- for (const child of childNodes) {
70
- children.push(convertNode(child));
71
- }
72
- }
73
-
74
- return {
75
- type: simplifyClassName(className),
76
- text: text && text.length > 0 ? text : undefined,
77
- label: description && description.length > 0 ? description : undefined,
78
- description:
79
- description && description.length > 0 ? description : undefined,
80
- bounds,
81
- interactive,
82
- focused: node["@_focused"] === "true",
83
- enabled: node["@_enabled"] === "true",
84
- visible: bounds.width > 0 && bounds.height > 0,
85
- value: getElementValue(node),
86
- resourceId: resourceId && resourceId.length > 0 ? resourceId : undefined,
87
- children,
88
- rawAttributes: extractRawAttributes(node),
89
- };
90
- }
91
-
92
- /** Parse Android bounds format "[left,top][right,bottom]" into Bounds */
93
- function parseBounds(boundsStr: string): Bounds {
94
- const match = boundsStr.match(
95
- /\[(\d+),(\d+)\]\[(\d+),(\d+)\]/
96
- );
97
- if (!match) {
98
- return { x: 0, y: 0, width: 0, height: 0 };
99
- }
100
-
101
- const left = parseInt(match[1]);
102
- const top = parseInt(match[2]);
103
- const right = parseInt(match[3]);
104
- const bottom = parseInt(match[4]);
105
-
106
- return {
107
- x: left,
108
- y: top,
109
- width: right - left,
110
- height: bottom - top,
111
- };
112
- }
113
-
114
- /** Simplify Android class names for readability */
115
- function simplifyClassName(className: string): string {
116
- // "android.widget.TextView" → "TextView"
117
- // "android.view.View" → "View"
118
- const parts = className.split(".");
119
- return parts[parts.length - 1];
120
- }
121
-
122
- /** Extract element value (for checkboxes, switches, inputs, etc.) */
123
- function getElementValue(node: any): string | undefined {
124
- if (node["@_checked"] === "true") return "checked";
125
- if (node["@_checked"] === "false" && node["@_checkable"] === "true")
126
- return "unchecked";
127
- if (node["@_selected"] === "true") return "selected";
128
- if (node["@_password"] === "true") return "•••";
129
- return undefined;
130
- }
131
-
132
- /** Extract all raw attributes for debugging */
133
- function extractRawAttributes(node: any): Record<string, string> {
134
- const attrs: Record<string, string> = {};
135
- for (const key of Object.keys(node)) {
136
- if (key.startsWith("@_")) {
137
- attrs[key.replace("@_", "")] = String(node[key]);
138
- }
139
- }
140
- return attrs;
141
- }
@@ -1,229 +0,0 @@
1
- import { execFile } from "child_process";
2
- import { promisify } from "util";
3
- import type { Device, DeviceInfo } from "./device.js";
4
- import { AndroidDevice } from "./android/android-device.js";
5
- import { IosDevice } from "./ios/ios-device.js";
6
-
7
- const execFileAsync = promisify(execFile);
8
-
9
- export interface DiscoveredDevice {
10
- id: string;
11
- name: string;
12
- platform: "ios" | "android";
13
- osVersion: string;
14
- isBooted: boolean;
15
- }
16
-
17
- /**
18
- * DeviceManager discovers running iOS Simulators and Android Emulators,
19
- * and creates Device instances for them.
20
- */
21
- export class DeviceManager {
22
- private activeDevice: Device | null = null;
23
- private activeDeviceId: string | null = null;
24
- private activePlatform: "ios" | "android" | null = null;
25
-
26
- async discoverDevices(): Promise<DiscoveredDevice[]> {
27
- const devices: DiscoveredDevice[] = [];
28
-
29
- const [androidDevices, iosDevices] = await Promise.allSettled([
30
- this.discoverAndroidDevices(),
31
- this.discoverIosDevices(),
32
- ]);
33
-
34
- if (androidDevices.status === "fulfilled") {
35
- devices.push(...androidDevices.value);
36
- }
37
- if (iosDevices.status === "fulfilled") {
38
- devices.push(...iosDevices.value);
39
- }
40
-
41
- return devices;
42
- }
43
-
44
- async getDevice(deviceId?: string): Promise<Device> {
45
- // If we have a cached device and it matches, verify it's still healthy
46
- if (
47
- this.activeDevice &&
48
- this.activeDeviceId &&
49
- (!deviceId || deviceId === this.activeDeviceId)
50
- ) {
51
- const isHealthy = await this.checkDeviceHealth(
52
- this.activeDeviceId,
53
- this.activePlatform
54
- );
55
- if (isHealthy) {
56
- return this.activeDevice;
57
- }
58
- // Device is stale — clear cache and rediscover
59
- this.activeDevice = null;
60
- this.activeDeviceId = null;
61
- this.activePlatform = null;
62
- }
63
-
64
- const devices = await this.discoverDevices();
65
- const bootedDevices = devices.filter((d) => d.isBooted);
66
-
67
- if (bootedDevices.length === 0) {
68
- throw new Error(
69
- "No running simulators or emulators found. Please start a device first."
70
- );
71
- }
72
-
73
- let target: DiscoveredDevice;
74
- if (deviceId) {
75
- const found = bootedDevices.find((d) => d.id === deviceId);
76
- if (!found) {
77
- throw new Error(
78
- `Device "${deviceId}" not found or not running. Available: ${bootedDevices.map((d) => d.id).join(", ")}`
79
- );
80
- }
81
- target = found;
82
- } else {
83
- target = bootedDevices[0];
84
- }
85
-
86
- if (target.platform === "android") {
87
- this.activeDevice = new AndroidDevice(target.id);
88
- } else {
89
- this.activeDevice = new IosDevice(target.id);
90
- }
91
-
92
- this.activeDeviceId = target.id;
93
- this.activePlatform = target.platform;
94
- return this.activeDevice;
95
- }
96
-
97
- /**
98
- * Quick health check to verify a cached device is still alive.
99
- * Returns false if the device is disconnected or no longer booted.
100
- */
101
- private async checkDeviceHealth(
102
- deviceId: string,
103
- platform: "ios" | "android" | null
104
- ): Promise<boolean> {
105
- try {
106
- if (platform === "android") {
107
- const adbPath = this.getAdbPath();
108
- const { stdout } = await execFileAsync(adbPath, ["-s", deviceId, "get-state"], {
109
- timeout: 5000,
110
- });
111
- return stdout.trim() === "device";
112
- } else if (platform === "ios") {
113
- const { stdout } = await execFileAsync(
114
- "xcrun",
115
- ["simctl", "list", "devices", "--json"],
116
- { timeout: 5000 }
117
- );
118
- const data = JSON.parse(stdout);
119
- for (const deviceList of Object.values(
120
- data.devices as Record<string, Array<{ udid: string; state: string }>>
121
- )) {
122
- const found = deviceList.find((d) => d.udid === deviceId);
123
- if (found) return found.state === "Booted";
124
- }
125
- return false;
126
- }
127
- return true;
128
- } catch {
129
- return false;
130
- }
131
- }
132
-
133
- private async discoverAndroidDevices(): Promise<DiscoveredDevice[]> {
134
- try {
135
- const adbPath = this.getAdbPath();
136
- const { stdout } = await execFileAsync(adbPath, ["devices", "-l"]);
137
- const devices: DiscoveredDevice[] = [];
138
-
139
- for (const line of stdout.split("\n").slice(1)) {
140
- const trimmed = line.trim();
141
- if (!trimmed || trimmed === "") continue;
142
-
143
- const parts = trimmed.split(/\s+/);
144
- const id = parts[0];
145
- const status = parts[1];
146
-
147
- if (status !== "device") continue;
148
-
149
- // Extract model name from properties
150
- const modelMatch = trimmed.match(/model:(\S+)/);
151
- const name = modelMatch ? modelMatch[1] : id;
152
-
153
- // Get Android version
154
- let osVersion = "unknown";
155
- try {
156
- const { stdout: versionOut } = await execFileAsync(adbPath, [
157
- "-s",
158
- id,
159
- "shell",
160
- "getprop",
161
- "ro.build.version.release",
162
- ]);
163
- osVersion = versionOut.trim();
164
- } catch {
165
- // Ignore version fetch errors
166
- }
167
-
168
- devices.push({
169
- id,
170
- name,
171
- platform: "android",
172
- osVersion,
173
- isBooted: true,
174
- });
175
- }
176
-
177
- return devices;
178
- } catch {
179
- return [];
180
- }
181
- }
182
-
183
- private async discoverIosDevices(): Promise<DiscoveredDevice[]> {
184
- try {
185
- const { stdout } = await execFileAsync("xcrun", [
186
- "simctl",
187
- "list",
188
- "devices",
189
- "--json",
190
- ]);
191
- const data = JSON.parse(stdout);
192
- const devices: DiscoveredDevice[] = [];
193
-
194
- for (const [runtime, deviceList] of Object.entries(
195
- data.devices as Record<string, Array<{ udid: string; name: string; state: string }>>
196
- )) {
197
- const osVersion = runtime.replace(
198
- /^com\.apple\.CoreSimulator\.SimRuntime\./,
199
- ""
200
- ).replace(/-/g, ".").replace(/^iOS\./, "");
201
-
202
- for (const device of deviceList) {
203
- if (device.state === "Booted") {
204
- devices.push({
205
- id: device.udid,
206
- name: device.name,
207
- platform: "ios",
208
- osVersion,
209
- isBooted: true,
210
- });
211
- }
212
- }
213
- }
214
-
215
- return devices;
216
- } catch {
217
- return [];
218
- }
219
- }
220
-
221
- private getAdbPath(): string {
222
- const androidHome =
223
- process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT;
224
- if (androidHome) {
225
- return `${androidHome}/platform-tools/adb`;
226
- }
227
- return "adb";
228
- }
229
- }