devlens-mcp 0.3.0 → 0.3.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.
Files changed (162) hide show
  1. package/README.md +10 -21
  2. package/docs/setup-guide.md +11 -31
  3. package/package.json +1 -1
  4. package/.claude/settings.json +0 -12
  5. package/.claude/settings.local.json +0 -17
  6. package/bin/cli.ts +0 -22
  7. package/bin/register.ts +0 -96
  8. package/dist/src/config/devlens-config.d.ts +0 -92
  9. package/dist/src/config/devlens-config.d.ts.map +0 -1
  10. package/dist/src/config/devlens-config.js +0 -70
  11. package/dist/src/config/devlens-config.js.map +0 -1
  12. package/dist/src/index.d.ts +0 -35
  13. package/dist/src/index.d.ts.map +0 -1
  14. package/dist/src/index.js +0 -8
  15. package/dist/src/index.js.map +0 -1
  16. package/dist/src/metro/cdp-client.d.ts +0 -48
  17. package/dist/src/metro/cdp-client.d.ts.map +0 -1
  18. package/dist/src/metro/cdp-client.js +0 -127
  19. package/dist/src/metro/cdp-client.js.map +0 -1
  20. package/dist/src/metro/log-collector.d.ts +0 -30
  21. package/dist/src/metro/log-collector.d.ts.map +0 -1
  22. package/dist/src/metro/log-collector.js +0 -114
  23. package/dist/src/metro/log-collector.js.map +0 -1
  24. package/dist/src/metro/metro-bridge.d.ts +0 -56
  25. package/dist/src/metro/metro-bridge.d.ts.map +0 -1
  26. package/dist/src/metro/metro-bridge.js +0 -255
  27. package/dist/src/metro/metro-bridge.js.map +0 -1
  28. package/dist/src/metro/network-inspector.d.ts +0 -34
  29. package/dist/src/metro/network-inspector.d.ts.map +0 -1
  30. package/dist/src/metro/network-inspector.js +0 -100
  31. package/dist/src/metro/network-inspector.js.map +0 -1
  32. package/dist/src/platform/android/adb.d.ts +0 -50
  33. package/dist/src/platform/android/adb.d.ts.map +0 -1
  34. package/dist/src/platform/android/adb.js +0 -137
  35. package/dist/src/platform/android/adb.js.map +0 -1
  36. package/dist/src/platform/android/android-device.d.ts +0 -21
  37. package/dist/src/platform/android/android-device.d.ts.map +0 -1
  38. package/dist/src/platform/android/android-device.js +0 -94
  39. package/dist/src/platform/android/android-device.js.map +0 -1
  40. package/dist/src/platform/android/ui-automator.d.ts +0 -17
  41. package/dist/src/platform/android/ui-automator.d.ts.map +0 -1
  42. package/dist/src/platform/android/ui-automator.js +0 -126
  43. package/dist/src/platform/android/ui-automator.js.map +0 -1
  44. package/dist/src/platform/device-manager.d.ts +0 -28
  45. package/dist/src/platform/device-manager.d.ts.map +0 -1
  46. package/dist/src/platform/device-manager.js +0 -185
  47. package/dist/src/platform/device-manager.js.map +0 -1
  48. package/dist/src/platform/device.d.ts +0 -86
  49. package/dist/src/platform/device.d.ts.map +0 -1
  50. package/dist/src/platform/device.js +0 -7
  51. package/dist/src/platform/device.js.map +0 -1
  52. package/dist/src/platform/ios/accessibility.d.ts +0 -17
  53. package/dist/src/platform/ios/accessibility.d.ts.map +0 -1
  54. package/dist/src/platform/ios/accessibility.js +0 -159
  55. package/dist/src/platform/ios/accessibility.js.map +0 -1
  56. package/dist/src/platform/ios/ios-device.d.ts +0 -22
  57. package/dist/src/platform/ios/ios-device.d.ts.map +0 -1
  58. package/dist/src/platform/ios/ios-device.js +0 -97
  59. package/dist/src/platform/ios/ios-device.js.map +0 -1
  60. package/dist/src/platform/ios/simctl.d.ts +0 -54
  61. package/dist/src/platform/ios/simctl.d.ts.map +0 -1
  62. package/dist/src/platform/ios/simctl.js +0 -192
  63. package/dist/src/platform/ios/simctl.js.map +0 -1
  64. package/dist/src/server.d.ts +0 -3
  65. package/dist/src/server.d.ts.map +0 -1
  66. package/dist/src/server.js +0 -176
  67. package/dist/src/server.js.map +0 -1
  68. package/dist/src/snapshot/formatter.d.ts +0 -18
  69. package/dist/src/snapshot/formatter.d.ts.map +0 -1
  70. package/dist/src/snapshot/formatter.js +0 -86
  71. package/dist/src/snapshot/formatter.js.map +0 -1
  72. package/dist/src/snapshot/ref-registry.d.ts +0 -67
  73. package/dist/src/snapshot/ref-registry.d.ts.map +0 -1
  74. package/dist/src/snapshot/ref-registry.js +0 -169
  75. package/dist/src/snapshot/ref-registry.js.map +0 -1
  76. package/dist/src/snapshot/snapshot-differ.d.ts +0 -57
  77. package/dist/src/snapshot/snapshot-differ.d.ts.map +0 -1
  78. package/dist/src/snapshot/snapshot-differ.js +0 -153
  79. package/dist/src/snapshot/snapshot-differ.js.map +0 -1
  80. package/dist/src/tools/app-tools.d.ts +0 -71
  81. package/dist/src/tools/app-tools.d.ts.map +0 -1
  82. package/dist/src/tools/app-tools.js +0 -97
  83. package/dist/src/tools/app-tools.js.map +0 -1
  84. package/dist/src/tools/device-tools.d.ts +0 -53
  85. package/dist/src/tools/device-tools.d.ts.map +0 -1
  86. package/dist/src/tools/device-tools.js +0 -86
  87. package/dist/src/tools/device-tools.js.map +0 -1
  88. package/dist/src/tools/ds-tools.d.ts +0 -65
  89. package/dist/src/tools/ds-tools.d.ts.map +0 -1
  90. package/dist/src/tools/ds-tools.js +0 -314
  91. package/dist/src/tools/ds-tools.js.map +0 -1
  92. package/dist/src/tools/interaction-tools.d.ts +0 -248
  93. package/dist/src/tools/interaction-tools.d.ts.map +0 -1
  94. package/dist/src/tools/interaction-tools.js +0 -391
  95. package/dist/src/tools/interaction-tools.js.map +0 -1
  96. package/dist/src/tools/metro-tools.d.ts +0 -115
  97. package/dist/src/tools/metro-tools.d.ts.map +0 -1
  98. package/dist/src/tools/metro-tools.js +0 -270
  99. package/dist/src/tools/metro-tools.js.map +0 -1
  100. package/dist/src/tools/navigation-tools.d.ts +0 -36
  101. package/dist/src/tools/navigation-tools.d.ts.map +0 -1
  102. package/dist/src/tools/navigation-tools.js +0 -60
  103. package/dist/src/tools/navigation-tools.js.map +0 -1
  104. package/dist/src/tools/screenshot-tools.d.ts +0 -298
  105. package/dist/src/tools/screenshot-tools.d.ts.map +0 -1
  106. package/dist/src/tools/screenshot-tools.js +0 -565
  107. package/dist/src/tools/screenshot-tools.js.map +0 -1
  108. package/dist/src/tools/snapshot-tools.d.ts +0 -161
  109. package/dist/src/tools/snapshot-tools.d.ts.map +0 -1
  110. package/dist/src/tools/snapshot-tools.js +0 -479
  111. package/dist/src/tools/snapshot-tools.js.map +0 -1
  112. package/dist/src/utils/image-preprocess.d.ts +0 -49
  113. package/dist/src/utils/image-preprocess.d.ts.map +0 -1
  114. package/dist/src/utils/image-preprocess.js +0 -322
  115. package/dist/src/utils/image-preprocess.js.map +0 -1
  116. package/dist/src/utils/retry.d.ts +0 -21
  117. package/dist/src/utils/retry.d.ts.map +0 -1
  118. package/dist/src/utils/retry.js +0 -33
  119. package/dist/src/utils/retry.js.map +0 -1
  120. package/dist/src/visual/comparator.d.ts +0 -51
  121. package/dist/src/visual/comparator.d.ts.map +0 -1
  122. package/dist/src/visual/comparator.js +0 -119
  123. package/dist/src/visual/comparator.js.map +0 -1
  124. package/dist/src/visual/layout-analyzer.d.ts +0 -64
  125. package/dist/src/visual/layout-analyzer.d.ts.map +0 -1
  126. package/dist/src/visual/layout-analyzer.js +0 -198
  127. package/dist/src/visual/layout-analyzer.js.map +0 -1
  128. package/dist/src/visual/screenshot.d.ts +0 -17
  129. package/dist/src/visual/screenshot.d.ts.map +0 -1
  130. package/dist/src/visual/screenshot.js +0 -39
  131. package/dist/src/visual/screenshot.js.map +0 -1
  132. package/src/config/devlens-config.ts +0 -76
  133. package/src/index.ts +0 -5
  134. package/src/metro/cdp-client.ts +0 -160
  135. package/src/metro/log-collector.ts +0 -137
  136. package/src/metro/metro-bridge.ts +0 -307
  137. package/src/metro/network-inspector.ts +0 -134
  138. package/src/platform/android/adb.ts +0 -200
  139. package/src/platform/android/android-device.ts +0 -116
  140. package/src/platform/android/ui-automator.ts +0 -141
  141. package/src/platform/device-manager.ts +0 -229
  142. package/src/platform/device.ts +0 -110
  143. package/src/platform/ios/accessibility.ts +0 -189
  144. package/src/platform/ios/ios-device.ts +0 -116
  145. package/src/platform/ios/simctl.ts +0 -244
  146. package/src/server.ts +0 -228
  147. package/src/snapshot/formatter.ts +0 -102
  148. package/src/snapshot/ref-registry.ts +0 -230
  149. package/src/snapshot/snapshot-differ.ts +0 -220
  150. package/src/tools/app-tools.ts +0 -111
  151. package/src/tools/device-tools.ts +0 -96
  152. package/src/tools/ds-tools.ts +0 -395
  153. package/src/tools/interaction-tools.ts +0 -467
  154. package/src/tools/metro-tools.ts +0 -320
  155. package/src/tools/navigation-tools.ts +0 -71
  156. package/src/tools/screenshot-tools.ts +0 -698
  157. package/src/tools/snapshot-tools.ts +0 -585
  158. package/src/utils/image-preprocess.ts +0 -430
  159. package/src/utils/retry.ts +0 -51
  160. package/src/visual/comparator.ts +0 -191
  161. package/src/visual/layout-analyzer.ts +0 -283
  162. package/src/visual/screenshot.ts +0 -49
@@ -1,110 +0,0 @@
1
- /**
2
- * Abstract Device interface — the core abstraction that iOS and Android drivers implement.
3
- * Every MCP tool delegates to this interface. Tools never know which platform they're on.
4
- */
5
-
6
- export interface DeviceInfo {
7
- id: string;
8
- name: string;
9
- platform: "ios" | "android";
10
- osVersion: string;
11
- screenWidth: number;
12
- screenHeight: number;
13
- orientation: "portrait" | "landscape";
14
- isBooted: boolean;
15
- }
16
-
17
- export interface AppInfo {
18
- appId: string;
19
- name: string;
20
- isRunning: boolean;
21
- }
22
-
23
- export interface Bounds {
24
- x: number;
25
- y: number;
26
- width: number;
27
- height: number;
28
- }
29
-
30
- export interface SnapshotNode {
31
- /** Element class/type (e.g., "android.widget.TextView", "UILabel") */
32
- type: string;
33
- /** Text content of the element */
34
- text?: string;
35
- /** Accessibility label */
36
- label?: string;
37
- /** Content description / accessibility hint */
38
- description?: string;
39
- /** Bounding box in screen coordinates */
40
- bounds: Bounds;
41
- /** Whether the element is interactive (clickable, tappable) */
42
- interactive: boolean;
43
- /** Whether the element is focused */
44
- focused?: boolean;
45
- /** Whether the element is enabled */
46
- enabled?: boolean;
47
- /** Whether the element is visible */
48
- visible?: boolean;
49
- /** Element value (for inputs, toggles, etc.) */
50
- value?: string;
51
- /** Resource ID (Android) or accessibility identifier (iOS) */
52
- resourceId?: string;
53
- /** Child elements */
54
- children: SnapshotNode[];
55
- /** Platform-specific raw attributes (for debugging) */
56
- rawAttributes?: Record<string, string>;
57
- }
58
-
59
- export interface Device {
60
- /** Get device information */
61
- getInfo(): Promise<DeviceInfo>;
62
-
63
- /** Get the accessibility tree of the current screen */
64
- getSnapshot(): Promise<SnapshotNode>;
65
-
66
- /** Take a screenshot, returns PNG buffer */
67
- takeScreenshot(): Promise<Buffer>;
68
-
69
- /** Tap at screen coordinates */
70
- tap(x: number, y: number): Promise<void>;
71
-
72
- /** Double-tap at screen coordinates */
73
- doubleTap(x: number, y: number): Promise<void>;
74
-
75
- /** Long press at screen coordinates */
76
- longPress(x: number, y: number, durationMs?: number): Promise<void>;
77
-
78
- /** Type text (assumes an input is already focused) */
79
- typeText(text: string): Promise<void>;
80
-
81
- /** Swipe from one point to another */
82
- swipe(
83
- startX: number,
84
- startY: number,
85
- endX: number,
86
- endY: number,
87
- durationMs?: number
88
- ): Promise<void>;
89
-
90
- /** Press a hardware/system button */
91
- pressButton(button: "home" | "back" | "enter"): Promise<void>;
92
-
93
- /** Set device orientation */
94
- setOrientation(orientation: "portrait" | "landscape"): Promise<void>;
95
-
96
- /** Launch an app by its bundle/package ID */
97
- launchApp(appId: string): Promise<void>;
98
-
99
- /** Terminate a running app */
100
- terminateApp(appId: string): Promise<void>;
101
-
102
- /** Install an app from a file path */
103
- installApp(path: string): Promise<void>;
104
-
105
- /** List installed apps */
106
- listApps(): Promise<AppInfo[]>;
107
-
108
- /** Open a URL (deep link or web URL) */
109
- openUrl(url: string): Promise<void>;
110
- }
@@ -1,189 +0,0 @@
1
- import type { SnapshotNode, Bounds } from "../device.js";
2
-
3
- /**
4
- * Parses iOS accessibility output from `simctl ui` into SnapshotNode tree.
5
- *
6
- * The simctl accessibility output varies by iOS/Xcode version. This parser
7
- * handles the common formats:
8
- *
9
- * Format 1 (structured):
10
- * Element: UIButton, Label: "Submit", Traits: Button, Frame: {{20, 100}, {340, 44}}
11
- *
12
- * Format 2 (XML-like from accessibility inspector):
13
- * <AXElement type="UIButton" label="Submit" frame="20 100 340 44" ...>
14
- *
15
- * When neither format is available, we fall back to a basic tree.
16
- */
17
- export function parseIosAccessibilityOutput(
18
- output: string
19
- ): SnapshotNode {
20
- // Try XML-like format first
21
- if (output.includes("<AX") || output.includes("AXElement")) {
22
- return parseAxFormat(output);
23
- }
24
-
25
- // Try structured text format
26
- if (output.includes("Element:") || output.includes("Label:")) {
27
- return parseStructuredFormat(output);
28
- }
29
-
30
- // Try simctl describe format (indented tree)
31
- return parseDescribeFormat(output);
32
- }
33
-
34
- function parseAxFormat(output: string): SnapshotNode {
35
- const root: SnapshotNode = createContainerNode("Screen");
36
- const lines = output.split("\n");
37
-
38
- for (const line of lines) {
39
- const trimmed = line.trim();
40
- if (!trimmed) continue;
41
-
42
- const typeMatch = trimmed.match(/type[=:]\s*"?(\w+)"?/i);
43
- const labelMatch = trimmed.match(/label[=:]\s*"([^"]*)"/i);
44
- const frameMatch = trimmed.match(
45
- /frame[=:]\s*"?(\d+)\s+(\d+)\s+(\d+)\s+(\d+)"?/i
46
- );
47
- const traitsMatch = trimmed.match(/traits?[=:]\s*"?([^">\n]+)"?/i);
48
-
49
- if (typeMatch) {
50
- const node: SnapshotNode = {
51
- type: simplifyIosType(typeMatch[1]),
52
- text: labelMatch ? labelMatch[1] : undefined,
53
- label: labelMatch ? labelMatch[1] : undefined,
54
- description: undefined,
55
- bounds: frameMatch
56
- ? {
57
- x: parseInt(frameMatch[1]),
58
- y: parseInt(frameMatch[2]),
59
- width: parseInt(frameMatch[3]),
60
- height: parseInt(frameMatch[4]),
61
- }
62
- : { x: 0, y: 0, width: 0, height: 0 },
63
- interactive: isInteractiveTrait(traitsMatch?.[1] || ""),
64
- children: [],
65
- };
66
- root.children.push(node);
67
- }
68
- }
69
-
70
- return root;
71
- }
72
-
73
- function parseStructuredFormat(output: string): SnapshotNode {
74
- const root: SnapshotNode = createContainerNode("Screen");
75
- const blocks = output.split(/\n(?=Element:)/);
76
-
77
- for (const block of blocks) {
78
- const typeMatch = block.match(/Element:\s*(\w+)/);
79
- const labelMatch = block.match(/Label:\s*"([^"]*)"/);
80
- const frameMatch = block.match(
81
- /Frame:\s*\{\{(\d+),\s*(\d+)\},\s*\{(\d+),\s*(\d+)\}\}/
82
- );
83
- const traitsMatch = block.match(/Traits?:\s*(.+)/);
84
-
85
- if (typeMatch) {
86
- const node: SnapshotNode = {
87
- type: simplifyIosType(typeMatch[1]),
88
- text: labelMatch ? labelMatch[1] : undefined,
89
- label: labelMatch ? labelMatch[1] : undefined,
90
- description: undefined,
91
- bounds: frameMatch
92
- ? {
93
- x: parseInt(frameMatch[1]),
94
- y: parseInt(frameMatch[2]),
95
- width: parseInt(frameMatch[3]),
96
- height: parseInt(frameMatch[4]),
97
- }
98
- : { x: 0, y: 0, width: 0, height: 0 },
99
- interactive: isInteractiveTrait(traitsMatch?.[1] || ""),
100
- children: [],
101
- };
102
- root.children.push(node);
103
- }
104
- }
105
-
106
- return root;
107
- }
108
-
109
- function parseDescribeFormat(output: string): SnapshotNode {
110
- const root: SnapshotNode = createContainerNode("Screen");
111
- const lines = output.split("\n");
112
-
113
- const stack: Array<{ node: SnapshotNode; indent: number }> = [
114
- { node: root, indent: -1 },
115
- ];
116
-
117
- for (const line of lines) {
118
- if (!line.trim()) continue;
119
-
120
- const indent = line.search(/\S/);
121
- const trimmed = line.trim();
122
-
123
- // Parse "Type: Label" or just "Type"
124
- const parts = trimmed.split(/:\s*/);
125
- const type = parts[0] || "View";
126
- const label = parts.length > 1 ? parts.slice(1).join(": ") : undefined;
127
-
128
- const node: SnapshotNode = {
129
- type: simplifyIosType(type),
130
- text: label,
131
- label,
132
- description: undefined,
133
- bounds: { x: 0, y: 0, width: 0, height: 0 },
134
- interactive: isInteractiveType(type),
135
- children: [],
136
- };
137
-
138
- // Find parent based on indentation
139
- while (stack.length > 1 && stack[stack.length - 1].indent >= indent) {
140
- stack.pop();
141
- }
142
-
143
- stack[stack.length - 1].node.children.push(node);
144
- stack.push({ node, indent });
145
- }
146
-
147
- return root;
148
- }
149
-
150
- function createContainerNode(name: string): SnapshotNode {
151
- return {
152
- type: name,
153
- bounds: { x: 0, y: 0, width: 0, height: 0 },
154
- interactive: false,
155
- children: [],
156
- };
157
- }
158
-
159
- function simplifyIosType(type: string): string {
160
- return type
161
- .replace(/^UI/, "")
162
- .replace(/^AX/, "")
163
- .replace(/^_/, "");
164
- }
165
-
166
- function isInteractiveTrait(traits: string): boolean {
167
- const lower = traits.toLowerCase();
168
- return (
169
- lower.includes("button") ||
170
- lower.includes("link") ||
171
- lower.includes("textfield") ||
172
- lower.includes("searchfield") ||
173
- lower.includes("adjustable") ||
174
- lower.includes("toggle")
175
- );
176
- }
177
-
178
- function isInteractiveType(type: string): boolean {
179
- const lower = type.toLowerCase();
180
- return (
181
- lower.includes("button") ||
182
- lower.includes("textfield") ||
183
- lower.includes("textview") ||
184
- lower.includes("switch") ||
185
- lower.includes("slider") ||
186
- lower.includes("picker") ||
187
- lower.includes("link")
188
- );
189
- }
@@ -1,116 +0,0 @@
1
- import type { Device, DeviceInfo, AppInfo, SnapshotNode } from "../device.js";
2
- import { Simctl } from "./simctl.js";
3
- import { parseIosAccessibilityOutput } from "./accessibility.js";
4
-
5
- export class IosDevice implements Device {
6
- private simctl: Simctl;
7
-
8
- constructor(private deviceId: string) {
9
- this.simctl = new Simctl(deviceId);
10
- }
11
-
12
- async getInfo(): Promise<DeviceInfo> {
13
- const [deviceInfo, screenSize] = await Promise.all([
14
- this.simctl.getDeviceInfo(),
15
- this.simctl.getScreenSize(),
16
- ]);
17
-
18
- return {
19
- id: this.deviceId,
20
- name: deviceInfo.name,
21
- platform: "ios",
22
- osVersion: deviceInfo.runtime,
23
- screenWidth: screenSize.width,
24
- screenHeight: screenSize.height,
25
- orientation: "portrait", // Default; would need to query actual orientation
26
- isBooted: deviceInfo.state === "Booted",
27
- };
28
- }
29
-
30
- async getSnapshot(): Promise<SnapshotNode> {
31
- const output = await this.simctl.getAccessibilityTree();
32
- return parseIosAccessibilityOutput(output);
33
- }
34
-
35
- async takeScreenshot(): Promise<Buffer> {
36
- return this.simctl.screenshot();
37
- }
38
-
39
- async tap(x: number, y: number): Promise<void> {
40
- await this.simctl.tap(x, y);
41
- }
42
-
43
- async doubleTap(x: number, y: number): Promise<void> {
44
- await this.simctl.tap(x, y);
45
- await sleep(100);
46
- await this.simctl.tap(x, y);
47
- }
48
-
49
- async longPress(x: number, y: number, _durationMs = 1000): Promise<void> {
50
- // simctl doesn't have a native long-press; we hold via swipe-in-place
51
- await this.simctl.swipe(x, y, x, y);
52
- }
53
-
54
- async typeText(text: string): Promise<void> {
55
- await this.simctl.typeText(text);
56
- }
57
-
58
- async swipe(
59
- startX: number,
60
- startY: number,
61
- endX: number,
62
- endY: number,
63
- _durationMs = 300
64
- ): Promise<void> {
65
- await this.simctl.swipe(startX, startY, endX, endY);
66
- }
67
-
68
- async pressButton(button: "home" | "back" | "enter"): Promise<void> {
69
- switch (button) {
70
- case "home":
71
- await this.simctl.pressKey("home");
72
- break;
73
- case "back":
74
- // iOS doesn't have a hardware back button; swipe from left edge
75
- const screenSize = await this.simctl.getScreenSize();
76
- await this.simctl.swipe(0, screenSize.height / 2, screenSize.width / 2, screenSize.height / 2);
77
- break;
78
- case "enter":
79
- await this.simctl.pressKey("return");
80
- break;
81
- }
82
- }
83
-
84
- async setOrientation(orientation: "portrait" | "landscape"): Promise<void> {
85
- await this.simctl.setOrientation(orientation);
86
- }
87
-
88
- async launchApp(appId: string): Promise<void> {
89
- await this.simctl.launchApp(appId);
90
- }
91
-
92
- async terminateApp(appId: string): Promise<void> {
93
- await this.simctl.terminateApp(appId);
94
- }
95
-
96
- async installApp(path: string): Promise<void> {
97
- await this.simctl.installApp(path);
98
- }
99
-
100
- async listApps(): Promise<AppInfo[]> {
101
- const apps = await this.simctl.listApps();
102
- return apps.map((app) => ({
103
- appId: app.bundleId,
104
- name: app.name,
105
- isRunning: false,
106
- }));
107
- }
108
-
109
- async openUrl(url: string): Promise<void> {
110
- await this.simctl.openUrl(url);
111
- }
112
- }
113
-
114
- function sleep(ms: number): Promise<void> {
115
- return new Promise((resolve) => setTimeout(resolve, ms));
116
- }
@@ -1,244 +0,0 @@
1
- import { execFile } from "child_process";
2
- import { promisify } from "util";
3
-
4
- const execFileAsync = promisify(execFile);
5
-
6
- /**
7
- * Wrapper around `xcrun simctl` for iOS Simulator interaction.
8
- */
9
- export class Simctl {
10
- constructor(private deviceId: string) {}
11
-
12
- /** Execute a simctl command */
13
- async exec(...args: string[]): Promise<string> {
14
- const { stdout } = await execFileAsync(
15
- "xcrun",
16
- ["simctl", ...args],
17
- { maxBuffer: 10 * 1024 * 1024, timeout: 30000 }
18
- );
19
- return stdout;
20
- }
21
-
22
- /** Take a screenshot and return PNG buffer */
23
- async screenshot(): Promise<Buffer> {
24
- const tmpPath = `/tmp/devlens-screenshot-${Date.now()}.png`;
25
- await this.exec("io", this.deviceId, "screenshot", tmpPath);
26
-
27
- const { readFile, unlink } = await import("fs/promises");
28
- const buffer = await readFile(tmpPath);
29
- unlink(tmpPath).catch(() => {});
30
- return buffer;
31
- }
32
-
33
- /** Get the accessibility tree using simctl's accessibility audit */
34
- async getAccessibilityTree(): Promise<string> {
35
- // Use simctl ui to get the accessibility hierarchy
36
- try {
37
- const output = await this.exec(
38
- "ui",
39
- this.deviceId,
40
- "accessibility",
41
- );
42
- return output;
43
- } catch {
44
- // Fallback: use the description command for view hierarchy
45
- return this.getViewHierarchyViaXctest();
46
- }
47
- }
48
-
49
- /**
50
- * Fallback: Get view hierarchy by running a small XCTest snippet.
51
- * This uses `simctl launch` with a debugger approach, but the simplest
52
- * method is to use the accessibility description from the simulator.
53
- */
54
- private async getViewHierarchyViaXctest(): Promise<string> {
55
- // Use the simctl subprocess to query the UI
56
- // We'll use `simctl ui <device> describe` to get the UI hierarchy
57
- try {
58
- const output = await this.exec("ui", this.deviceId, "describe");
59
- return output;
60
- } catch {
61
- throw new Error(
62
- "Could not extract accessibility tree from iOS Simulator. " +
63
- "Ensure the simulator is booted and has an app running."
64
- );
65
- }
66
- }
67
-
68
- /** Get device info from simctl */
69
- async getDeviceInfo(): Promise<{
70
- name: string;
71
- runtime: string;
72
- state: string;
73
- }> {
74
- const { stdout } = await execFileAsync("xcrun", [
75
- "simctl",
76
- "list",
77
- "devices",
78
- "--json",
79
- ]);
80
- const data = JSON.parse(stdout);
81
-
82
- for (const [runtime, devices] of Object.entries(
83
- data.devices as Record<string, Array<{ udid: string; name: string; state: string }>>
84
- )) {
85
- for (const device of devices) {
86
- if (device.udid === this.deviceId) {
87
- return {
88
- name: device.name,
89
- runtime: runtime
90
- .replace(/^com\.apple\.CoreSimulator\.SimRuntime\./, "")
91
- .replace(/-/g, "."),
92
- state: device.state,
93
- };
94
- }
95
- }
96
- }
97
- throw new Error(`Device ${this.deviceId} not found in simctl list`);
98
- }
99
-
100
- /** Get screen size of the simulator */
101
- async getScreenSize(): Promise<{ width: number; height: number }> {
102
- // Take a tiny screenshot and check its dimensions via sharp
103
- const tmpPath = `/tmp/devlens-size-check-${Date.now()}.png`;
104
- await this.exec("io", this.deviceId, "screenshot", tmpPath);
105
-
106
- try {
107
- const sharp = (await import("sharp")).default;
108
- const metadata = await sharp(tmpPath).metadata();
109
- const { unlink } = await import("fs/promises");
110
- unlink(tmpPath).catch(() => {});
111
-
112
- return {
113
- width: metadata.width || 390,
114
- height: metadata.height || 844,
115
- };
116
- } catch {
117
- // Fallback defaults (iPhone 14)
118
- return { width: 390, height: 844 };
119
- }
120
- }
121
-
122
- /** Tap at coordinates using simctl */
123
- async tap(x: number, y: number): Promise<void> {
124
- // simctl doesn't have a direct tap command, so we use the io command
125
- // with the AppleScript approach or the simctl interact command
126
- try {
127
- await this.exec(
128
- "io",
129
- this.deviceId,
130
- "tap",
131
- String(Math.round(x)),
132
- String(Math.round(y))
133
- );
134
- } catch {
135
- // Fallback: use AppleScript to tap on the simulator
136
- await execFileAsync("osascript", [
137
- "-e",
138
- `tell application "Simulator" to activate`,
139
- ]);
140
- // Use cliclick or similar for coordinate-based tapping
141
- throw new Error(
142
- "Direct tap not supported on this simctl version. Consider using a newer Xcode."
143
- );
144
- }
145
- }
146
-
147
- /** Swipe on the simulator */
148
- async swipe(
149
- startX: number,
150
- startY: number,
151
- endX: number,
152
- endY: number
153
- ): Promise<void> {
154
- try {
155
- await this.exec(
156
- "io",
157
- this.deviceId,
158
- "swipe",
159
- String(Math.round(startX)),
160
- String(Math.round(startY)),
161
- String(Math.round(endX)),
162
- String(Math.round(endY))
163
- );
164
- } catch {
165
- throw new Error("Swipe not supported on this simctl version.");
166
- }
167
- }
168
-
169
- /** Type text using simctl keyboard input */
170
- async typeText(text: string): Promise<void> {
171
- await this.exec("io", this.deviceId, "keyboard", "type", text);
172
- }
173
-
174
- /** Press a key using simctl */
175
- async pressKey(key: string): Promise<void> {
176
- await this.exec("io", this.deviceId, "keyboard", "key", key);
177
- }
178
-
179
- /** Launch an app */
180
- async launchApp(bundleId: string): Promise<void> {
181
- await this.exec("launch", this.deviceId, bundleId);
182
- }
183
-
184
- /** Terminate an app */
185
- async terminateApp(bundleId: string): Promise<void> {
186
- await this.exec("terminate", this.deviceId, bundleId);
187
- }
188
-
189
- /** Install an app (.app bundle or .ipa) */
190
- async installApp(path: string): Promise<void> {
191
- await this.exec("install", this.deviceId, path);
192
- }
193
-
194
- /** List installed apps */
195
- async listApps(): Promise<Array<{ bundleId: string; name: string }>> {
196
- try {
197
- const output = await this.exec(
198
- "listapps",
199
- this.deviceId,
200
- );
201
- // Parse the plist/json output
202
- const apps: Array<{ bundleId: string; name: string }> = [];
203
- const bundleIdMatches = output.matchAll(
204
- /"CFBundleIdentifier"\s*=\s*"([^"]+)"/g
205
- );
206
- const nameMatches = output.matchAll(
207
- /"CFBundleDisplayName"\s*=\s*"([^"]+)"/g
208
- );
209
- const bundleIds = [...bundleIdMatches].map((m) => m[1]);
210
- const names = [...nameMatches].map((m) => m[1]);
211
-
212
- for (let i = 0; i < bundleIds.length; i++) {
213
- apps.push({
214
- bundleId: bundleIds[i],
215
- name: names[i] || bundleIds[i],
216
- });
217
- }
218
- return apps;
219
- } catch {
220
- return [];
221
- }
222
- }
223
-
224
- /** Open a URL */
225
- async openUrl(url: string): Promise<void> {
226
- await this.exec("openurl", this.deviceId, url);
227
- }
228
-
229
- /** Set device orientation */
230
- async setOrientation(orientation: "portrait" | "landscape"): Promise<void> {
231
- // simctl doesn't have a direct orientation command
232
- // Use the Simulator menu via AppleScript
233
- const rotation = orientation === "portrait" ? "0" : "90";
234
- try {
235
- await execFileAsync("osascript", [
236
- "-e",
237
- `tell application "System Events" to tell process "Simulator" to ` +
238
- `click menu item "Rotate ${orientation === "landscape" ? "Right" : "Left"}" of menu "Device" of menu bar 1`,
239
- ]);
240
- } catch {
241
- // Orientation setting may not be available in all environments
242
- }
243
- }
244
- }