screenhand 0.1.1 → 0.2.0

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 (177) hide show
  1. package/README.md +458 -93
  2. package/dist/.audit-log.jsonl +55 -0
  3. package/dist/.screenhand/memory/.lock +1 -0
  4. package/dist/.screenhand/memory/actions.jsonl +85 -0
  5. package/dist/.screenhand/memory/errors.jsonl +5 -0
  6. package/dist/.screenhand/memory/errors.jsonl.bak +4 -0
  7. package/dist/.screenhand/memory/state.json +35 -0
  8. package/dist/.screenhand/memory/state.json.bak +35 -0
  9. package/dist/.screenhand/memory/strategies.jsonl +12 -0
  10. package/dist/agent/cli.js +73 -0
  11. package/dist/agent/loop.js +258 -0
  12. package/dist/config.js +9 -0
  13. package/dist/index.js +56 -0
  14. package/dist/logging/timeline-logger.js +29 -0
  15. package/dist/mcp/mcp-stdio-server.js +448 -0
  16. package/dist/mcp/server.js +347 -0
  17. package/dist/mcp-desktop.js +2731 -0
  18. package/dist/mcp-entry.js +59 -0
  19. package/dist/memory/recall.js +160 -0
  20. package/dist/memory/research.js +98 -0
  21. package/dist/memory/seeds.js +89 -0
  22. package/dist/memory/session.js +161 -0
  23. package/dist/memory/store.js +391 -0
  24. package/dist/memory/types.js +4 -0
  25. package/dist/monitor/codex-monitor.js +377 -0
  26. package/dist/monitor/task-queue.js +84 -0
  27. package/dist/monitor/types.js +49 -0
  28. package/dist/native/bridge-client.js +174 -0
  29. package/dist/native/macos-bridge-client.js +5 -0
  30. package/dist/npm-publish-helper.js +117 -0
  31. package/dist/npm-token-cdp.js +113 -0
  32. package/dist/npm-token-create.js +135 -0
  33. package/dist/npm-token-finish.js +126 -0
  34. package/dist/playbook/engine.js +193 -0
  35. package/dist/playbook/index.js +4 -0
  36. package/dist/playbook/recorder.js +519 -0
  37. package/dist/playbook/runner.js +392 -0
  38. package/dist/playbook/store.js +166 -0
  39. package/dist/playbook/types.js +4 -0
  40. package/dist/runtime/accessibility-adapter.js +377 -0
  41. package/dist/runtime/app-adapter.js +48 -0
  42. package/dist/runtime/applescript-adapter.js +283 -0
  43. package/dist/runtime/ax-role-map.js +80 -0
  44. package/dist/runtime/browser-adapter.js +36 -0
  45. package/dist/runtime/cdp-chrome-adapter.js +505 -0
  46. package/dist/runtime/composite-adapter.js +205 -0
  47. package/dist/runtime/executor.js +250 -0
  48. package/dist/runtime/locator-cache.js +12 -0
  49. package/dist/runtime/planning-loop.js +47 -0
  50. package/dist/runtime/service.js +372 -0
  51. package/dist/runtime/session-manager.js +28 -0
  52. package/dist/runtime/state-observer.js +105 -0
  53. package/dist/runtime/vision-adapter.js +208 -0
  54. package/dist/scripts/codex-monitor-daemon.js +335 -0
  55. package/dist/scripts/supervisor-daemon.js +272 -0
  56. package/dist/scripts/worker-daemon.js +228 -0
  57. package/dist/src/agent/cli.js +82 -0
  58. package/dist/src/agent/loop.js +274 -0
  59. package/{src/config.ts → dist/src/config.js} +5 -10
  60. package/{src/index.ts → dist/src/index.js} +32 -52
  61. package/dist/src/jobs/manager.js +237 -0
  62. package/dist/src/jobs/runner.js +683 -0
  63. package/dist/src/jobs/store.js +102 -0
  64. package/dist/src/jobs/types.js +30 -0
  65. package/dist/src/jobs/worker.js +97 -0
  66. package/dist/src/logging/timeline-logger.js +45 -0
  67. package/dist/src/mcp/mcp-stdio-server.js +464 -0
  68. package/dist/src/mcp/server.js +363 -0
  69. package/dist/src/mcp-entry.js +60 -0
  70. package/dist/src/memory/recall.js +170 -0
  71. package/dist/src/memory/research.js +104 -0
  72. package/dist/src/memory/seeds.js +101 -0
  73. package/dist/src/memory/service.js +421 -0
  74. package/dist/src/memory/session.js +169 -0
  75. package/dist/src/memory/store.js +422 -0
  76. package/dist/src/memory/types.js +17 -0
  77. package/dist/src/monitor/codex-monitor.js +382 -0
  78. package/dist/src/monitor/task-queue.js +97 -0
  79. package/dist/src/monitor/types.js +62 -0
  80. package/dist/src/native/bridge-client.js +190 -0
  81. package/{src/native/macos-bridge-client.ts → dist/src/native/macos-bridge-client.js} +0 -1
  82. package/dist/src/playbook/engine.js +201 -0
  83. package/dist/src/playbook/index.js +20 -0
  84. package/dist/src/playbook/recorder.js +535 -0
  85. package/dist/src/playbook/runner.js +408 -0
  86. package/dist/src/playbook/store.js +183 -0
  87. package/dist/src/playbook/types.js +17 -0
  88. package/dist/src/runtime/accessibility-adapter.js +393 -0
  89. package/dist/src/runtime/app-adapter.js +64 -0
  90. package/dist/src/runtime/applescript-adapter.js +299 -0
  91. package/dist/src/runtime/ax-role-map.js +96 -0
  92. package/dist/src/runtime/browser-adapter.js +52 -0
  93. package/dist/src/runtime/cdp-chrome-adapter.js +521 -0
  94. package/dist/src/runtime/composite-adapter.js +221 -0
  95. package/dist/src/runtime/execution-contract.js +159 -0
  96. package/dist/src/runtime/executor.js +266 -0
  97. package/{src/runtime/locator-cache.ts → dist/src/runtime/locator-cache.js} +10 -15
  98. package/dist/src/runtime/planning-loop.js +63 -0
  99. package/dist/src/runtime/service.js +388 -0
  100. package/dist/src/runtime/session-manager.js +60 -0
  101. package/dist/src/runtime/state-observer.js +121 -0
  102. package/dist/src/runtime/vision-adapter.js +224 -0
  103. package/dist/src/supervisor/locks.js +186 -0
  104. package/dist/src/supervisor/supervisor.js +403 -0
  105. package/dist/src/supervisor/types.js +30 -0
  106. package/dist/src/test-mcp-protocol.js +154 -0
  107. package/dist/src/types.js +17 -0
  108. package/dist/src/util/atomic-write.js +118 -0
  109. package/dist/test-mcp-protocol.js +138 -0
  110. package/dist/types.js +1 -0
  111. package/package.json +18 -4
  112. package/.claude/commands/automate.md +0 -28
  113. package/.claude/commands/debug-ui.md +0 -19
  114. package/.claude/commands/screenshot.md +0 -15
  115. package/.github/FUNDING.yml +0 -1
  116. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -27
  117. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  118. package/.mcp.json +0 -8
  119. package/DESKTOP_MCP_GUIDE.md +0 -92
  120. package/SECURITY.md +0 -44
  121. package/docs/architecture.md +0 -47
  122. package/install-skills.sh +0 -19
  123. package/mcp-bridge.ts +0 -271
  124. package/mcp-desktop.ts +0 -1221
  125. package/native/macos-bridge/Package.swift +0 -21
  126. package/native/macos-bridge/Sources/AccessibilityBridge.swift +0 -261
  127. package/native/macos-bridge/Sources/AppManagement.swift +0 -129
  128. package/native/macos-bridge/Sources/CoreGraphicsBridge.swift +0 -242
  129. package/native/macos-bridge/Sources/ObserverBridge.swift +0 -120
  130. package/native/macos-bridge/Sources/VisionBridge.swift +0 -80
  131. package/native/macos-bridge/Sources/main.swift +0 -345
  132. package/native/windows-bridge/AppManagement.cs +0 -234
  133. package/native/windows-bridge/InputBridge.cs +0 -436
  134. package/native/windows-bridge/Program.cs +0 -265
  135. package/native/windows-bridge/ScreenCapture.cs +0 -329
  136. package/native/windows-bridge/UIAutomationBridge.cs +0 -571
  137. package/native/windows-bridge/WindowsBridge.csproj +0 -17
  138. package/playbooks/devpost.json +0 -186
  139. package/playbooks/instagram.json +0 -41
  140. package/playbooks/instagram_v2.json +0 -201
  141. package/playbooks/x_v1.json +0 -211
  142. package/scripts/devpost-live-loop.mjs +0 -421
  143. package/src/logging/timeline-logger.ts +0 -55
  144. package/src/mcp/server.ts +0 -449
  145. package/src/memory/recall.ts +0 -191
  146. package/src/memory/research.ts +0 -146
  147. package/src/memory/seeds.ts +0 -123
  148. package/src/memory/session.ts +0 -201
  149. package/src/memory/store.ts +0 -434
  150. package/src/memory/types.ts +0 -69
  151. package/src/native/bridge-client.ts +0 -239
  152. package/src/runtime/accessibility-adapter.ts +0 -487
  153. package/src/runtime/app-adapter.ts +0 -169
  154. package/src/runtime/applescript-adapter.ts +0 -376
  155. package/src/runtime/ax-role-map.ts +0 -102
  156. package/src/runtime/browser-adapter.ts +0 -129
  157. package/src/runtime/cdp-chrome-adapter.ts +0 -676
  158. package/src/runtime/composite-adapter.ts +0 -274
  159. package/src/runtime/executor.ts +0 -396
  160. package/src/runtime/planning-loop.ts +0 -81
  161. package/src/runtime/service.ts +0 -448
  162. package/src/runtime/session-manager.ts +0 -50
  163. package/src/runtime/state-observer.ts +0 -136
  164. package/src/runtime/vision-adapter.ts +0 -297
  165. package/src/types.ts +0 -297
  166. package/tests/bridge-client.test.ts +0 -176
  167. package/tests/browser-stealth.test.ts +0 -210
  168. package/tests/composite-adapter.test.ts +0 -64
  169. package/tests/mcp-server.test.ts +0 -151
  170. package/tests/memory-recall.test.ts +0 -339
  171. package/tests/memory-research.test.ts +0 -159
  172. package/tests/memory-seeds.test.ts +0 -120
  173. package/tests/memory-store.test.ts +0 -392
  174. package/tests/types.test.ts +0 -92
  175. package/tsconfig.check.json +0 -17
  176. package/tsconfig.json +0 -19
  177. package/vitest.config.ts +0 -8
@@ -0,0 +1,377 @@
1
+ import { toAXRole } from "./ax-role-map.js";
2
+ const POLL_INTERVAL_MS = 100;
3
+ export class AccessibilityAdapter {
4
+ bridge;
5
+ sessions = new Map();
6
+ sessionsByProfile = new Map();
7
+ constructor(bridge) {
8
+ this.bridge = bridge;
9
+ }
10
+ async attach(profile) {
11
+ const existing = this.sessionsByProfile.get(profile);
12
+ if (existing)
13
+ return existing.info;
14
+ // Ensure bridge is started
15
+ await this.bridge.start();
16
+ // Check accessibility permissions
17
+ const perms = await this.bridge.checkPermissions();
18
+ if (!perms.trusted) {
19
+ throw new Error("Accessibility permission not granted. Go to System Settings → Privacy & Security → Accessibility and enable this app.");
20
+ }
21
+ const info = {
22
+ sessionId: `ax_session_${profile}_${Date.now()}`,
23
+ profile,
24
+ createdAt: new Date().toISOString(),
25
+ adapterType: "accessibility",
26
+ };
27
+ // Default to frontmost app
28
+ const frontmost = await this.bridge.call("app.frontmost");
29
+ const state = {
30
+ info,
31
+ pid: frontmost.pid,
32
+ bundleId: frontmost.bundleId,
33
+ appName: frontmost.name,
34
+ };
35
+ this.sessions.set(info.sessionId, state);
36
+ this.sessionsByProfile.set(profile, state);
37
+ return info;
38
+ }
39
+ async getAppContext(sessionId) {
40
+ const state = this.requireSession(sessionId);
41
+ // Get window title from AX tree
42
+ let windowTitle = "";
43
+ try {
44
+ const tree = await this.bridge.call("ax.getElementTree", {
45
+ pid: state.pid,
46
+ maxDepth: 1,
47
+ });
48
+ const window = tree.children?.find((c) => c.role === "AXWindow");
49
+ windowTitle = window?.title ?? "";
50
+ }
51
+ catch {
52
+ // Ignore tree errors
53
+ }
54
+ return {
55
+ bundleId: state.bundleId,
56
+ appName: state.appName,
57
+ pid: state.pid,
58
+ windowTitle,
59
+ };
60
+ }
61
+ async getPageMeta(sessionId) {
62
+ const ctx = await this.getAppContext(sessionId);
63
+ return {
64
+ url: ctx.url ?? `app://${ctx.bundleId}`,
65
+ title: ctx.windowTitle || ctx.appName,
66
+ };
67
+ }
68
+ async navigate(sessionId, url, _timeoutMs) {
69
+ // For desktop apps, "navigate" means launching/focusing an app by bundle ID
70
+ const state = this.requireSession(sessionId);
71
+ if (url.startsWith("app://")) {
72
+ const bundleId = url.slice(6);
73
+ const result = await this.bridge.call("app.launch", { bundleId });
74
+ state.pid = result.pid;
75
+ state.bundleId = result.bundleId;
76
+ state.appName = result.appName;
77
+ }
78
+ return this.getPageMeta(sessionId);
79
+ }
80
+ async locate(sessionId, target, timeoutMs) {
81
+ const state = this.requireSession(sessionId);
82
+ const deadline = Date.now() + timeoutMs;
83
+ while (Date.now() < deadline) {
84
+ try {
85
+ const params = this.buildFindParams(target, state.pid);
86
+ const result = await this.bridge.call("ax.findElement", params);
87
+ if (result) {
88
+ const located = {
89
+ handleId: result.handleId,
90
+ locatorUsed: `ax:${target.type}`,
91
+ role: result.role,
92
+ label: result.title,
93
+ };
94
+ if (result.bounds) {
95
+ located.coordinates = result.bounds;
96
+ }
97
+ return located;
98
+ }
99
+ }
100
+ catch {
101
+ // Element not found yet, keep polling
102
+ }
103
+ await sleep(POLL_INTERVAL_MS);
104
+ }
105
+ return null;
106
+ }
107
+ async click(sessionId, element) {
108
+ const state = this.requireSession(sessionId);
109
+ const elementPath = this.parseElementPath(element.handleId);
110
+ if (elementPath) {
111
+ await this.bridge.call("ax.performAction", {
112
+ pid: state.pid,
113
+ elementPath,
114
+ action: "AXPress",
115
+ });
116
+ }
117
+ else if (element.coordinates) {
118
+ // Fallback to coordinate click
119
+ const cx = element.coordinates.x + element.coordinates.width / 2;
120
+ const cy = element.coordinates.y + element.coordinates.height / 2;
121
+ await this.bridge.call("cg.mouseClick", { x: cx, y: cy });
122
+ }
123
+ else {
124
+ throw new Error("Cannot click: no element path or coordinates");
125
+ }
126
+ }
127
+ async setValue(sessionId, element, text, clear) {
128
+ const state = this.requireSession(sessionId);
129
+ const elementPath = this.parseElementPath(element.handleId);
130
+ if (clear && elementPath) {
131
+ // Try AX value set first
132
+ try {
133
+ await this.bridge.call("ax.setElementValue", {
134
+ pid: state.pid,
135
+ elementPath,
136
+ value: text,
137
+ });
138
+ return;
139
+ }
140
+ catch {
141
+ // Fallback: click, select all, type
142
+ }
143
+ }
144
+ // Fallback: click to focus, select all if clearing, then type
145
+ await this.click(sessionId, element);
146
+ await sleep(50);
147
+ if (clear) {
148
+ await this.bridge.call("cg.keyCombo", { keys: ["cmd", "a"] });
149
+ await sleep(50);
150
+ }
151
+ await this.bridge.call("cg.typeText", { text });
152
+ }
153
+ async getValue(sessionId, element) {
154
+ const state = this.requireSession(sessionId);
155
+ const elementPath = this.parseElementPath(element.handleId);
156
+ if (!elementPath)
157
+ return "";
158
+ const result = await this.bridge.call("ax.getElementValue", {
159
+ pid: state.pid,
160
+ elementPath,
161
+ });
162
+ return result.value;
163
+ }
164
+ async waitFor(sessionId, condition, timeoutMs) {
165
+ const deadline = Date.now() + timeoutMs;
166
+ while (Date.now() < deadline) {
167
+ const met = await this.checkCondition(sessionId, condition);
168
+ if (met)
169
+ return true;
170
+ await sleep(POLL_INTERVAL_MS);
171
+ }
172
+ return false;
173
+ }
174
+ async extract(sessionId, target, format) {
175
+ const state = this.requireSession(sessionId);
176
+ if (format === "text") {
177
+ // Get element tree and extract text content
178
+ const element = await this.locate(sessionId, target, 1500);
179
+ if (!element)
180
+ throw new Error("Extract target not found");
181
+ const result = await this.getValue(sessionId, element);
182
+ return result || element.label || "";
183
+ }
184
+ if (format === "json") {
185
+ // Return the AX tree as JSON
186
+ const tree = await this.bridge.call("ax.getElementTree", {
187
+ pid: state.pid,
188
+ maxDepth: 3,
189
+ });
190
+ return tree;
191
+ }
192
+ // table format: return element tree in tabular form
193
+ const tree = await this.bridge.call("ax.getElementTree", {
194
+ pid: state.pid,
195
+ maxDepth: 2,
196
+ });
197
+ return {
198
+ headers: ["role", "title", "value"],
199
+ rows: this.flattenTree(tree).map((n) => [n.role, n.title ?? "", n.value ?? ""]),
200
+ };
201
+ }
202
+ async screenshot(sessionId, region) {
203
+ const state = this.requireSession(sessionId);
204
+ // Get window list to find the window ID for the app
205
+ const windows = await this.bridge.call("app.windows");
206
+ const appWindow = windows.find((w) => w.pid === state.pid);
207
+ if (appWindow) {
208
+ const result = await this.bridge.call("cg.captureWindow", { windowId: appWindow.windowId });
209
+ return result.path;
210
+ }
211
+ // Fallback to screen capture with region
212
+ const result = await this.bridge.call("cg.captureScreen", region ? { region } : {});
213
+ return result.path;
214
+ }
215
+ // ── Desktop-specific methods ──
216
+ async launchApp(sessionId, bundleId) {
217
+ const state = this.requireSession(sessionId);
218
+ const result = await this.bridge.call("app.launch", { bundleId });
219
+ // Update session to track new app
220
+ state.pid = result.pid;
221
+ state.bundleId = result.bundleId;
222
+ state.appName = result.appName;
223
+ return {
224
+ bundleId: result.bundleId,
225
+ appName: result.appName,
226
+ pid: result.pid,
227
+ windowTitle: "",
228
+ };
229
+ }
230
+ async focusApp(sessionId, bundleId) {
231
+ const state = this.requireSession(sessionId);
232
+ await this.bridge.call("app.focus", { bundleId });
233
+ // Update PID if different app
234
+ if (bundleId !== state.bundleId) {
235
+ const apps = await this.bridge.call("app.list");
236
+ const app = apps.find((a) => a.bundleId === bundleId);
237
+ if (app) {
238
+ state.pid = app.pid;
239
+ state.bundleId = bundleId;
240
+ state.appName = app.name;
241
+ }
242
+ }
243
+ }
244
+ async listApps(_sessionId) {
245
+ return this.bridge.call("app.list");
246
+ }
247
+ async listWindows(_sessionId) {
248
+ return this.bridge.call("app.windows");
249
+ }
250
+ async menuClick(sessionId, menuPath) {
251
+ const state = this.requireSession(sessionId);
252
+ await this.bridge.call("ax.menuClick", { pid: state.pid, menuPath });
253
+ }
254
+ async keyCombo(_sessionId, keys) {
255
+ await this.bridge.call("cg.keyCombo", { keys });
256
+ }
257
+ async elementTree(sessionId, maxDepth, _root) {
258
+ const state = this.requireSession(sessionId);
259
+ return this.bridge.call("ax.getElementTree", {
260
+ pid: state.pid,
261
+ maxDepth: maxDepth ?? 5,
262
+ });
263
+ }
264
+ async drag(sessionId, from, to) {
265
+ if (!from.coordinates || !to.coordinates) {
266
+ throw new Error("Drag requires elements with coordinates");
267
+ }
268
+ const fromX = from.coordinates.x + from.coordinates.width / 2;
269
+ const fromY = from.coordinates.y + from.coordinates.height / 2;
270
+ const toX = to.coordinates.x + to.coordinates.width / 2;
271
+ const toY = to.coordinates.y + to.coordinates.height / 2;
272
+ await this.bridge.call("cg.mouseDrag", { fromX, fromY, toX, toY });
273
+ }
274
+ async scroll(_sessionId, direction, amount, element) {
275
+ let x = 500;
276
+ let y = 400;
277
+ if (element?.coordinates) {
278
+ x = element.coordinates.x + element.coordinates.width / 2;
279
+ y = element.coordinates.y + element.coordinates.height / 2;
280
+ }
281
+ const deltaMap = {
282
+ up: { deltaX: 0, deltaY: -amount },
283
+ down: { deltaX: 0, deltaY: amount },
284
+ left: { deltaX: -amount, deltaY: 0 },
285
+ right: { deltaX: amount, deltaY: 0 },
286
+ };
287
+ const delta = deltaMap[direction];
288
+ await this.bridge.call("cg.scroll", { x, y, ...delta });
289
+ }
290
+ // ── Private helpers ──
291
+ requireSession(sessionId) {
292
+ const state = this.sessions.get(sessionId);
293
+ if (!state)
294
+ throw new Error(`Session not found: ${sessionId}`);
295
+ return state;
296
+ }
297
+ buildFindParams(target, pid) {
298
+ const params = { pid };
299
+ switch (target.type) {
300
+ case "role":
301
+ params.role = toAXRole(target.role);
302
+ params.title = target.name;
303
+ params.exact = target.exact ?? true;
304
+ break;
305
+ case "text":
306
+ params.title = target.value;
307
+ params.exact = target.exact ?? true;
308
+ break;
309
+ case "selector":
310
+ // For AX, treat selector as an identifier
311
+ params.identifier = target.value;
312
+ break;
313
+ case "ax_path":
314
+ // Direct path resolution handled differently
315
+ params.role = target.path[target.path.length - 1];
316
+ break;
317
+ case "ax_attribute":
318
+ params[target.attribute] = target.value;
319
+ break;
320
+ case "coordinates":
321
+ // Can't find by coordinates via AX, will fallback to vision
322
+ throw new Error("Cannot locate by coordinates using accessibility adapter");
323
+ case "image":
324
+ throw new Error("Cannot locate by image using accessibility adapter");
325
+ }
326
+ return params;
327
+ }
328
+ parseElementPath(handleId) {
329
+ // Handle IDs from the bridge are formatted as "ax_0_1_2"
330
+ if (!handleId.startsWith("ax_"))
331
+ return null;
332
+ const parts = handleId.slice(3).split("_");
333
+ const indices = parts.map(Number).filter((n) => !isNaN(n));
334
+ return indices.length > 0 ? indices : null;
335
+ }
336
+ async checkCondition(sessionId, condition) {
337
+ switch (condition.type) {
338
+ case "element_exists": {
339
+ const found = await this.locate(sessionId, condition.target, 100);
340
+ return found !== null;
341
+ }
342
+ case "element_gone": {
343
+ const found = await this.locate(sessionId, condition.target, 100);
344
+ return found === null;
345
+ }
346
+ case "window_title_matches": {
347
+ const ctx = await this.getAppContext(sessionId);
348
+ return new RegExp(condition.regex).test(ctx.windowTitle);
349
+ }
350
+ case "text_appears": {
351
+ const found = await this.locate(sessionId, { type: "text", value: condition.text }, 100);
352
+ return found !== null;
353
+ }
354
+ case "app_idle":
355
+ // Simplified: always return true after a short delay
356
+ return true;
357
+ case "selector_visible":
358
+ case "selector_hidden":
359
+ case "url_matches":
360
+ case "spinner_disappears":
361
+ // Browser-specific conditions not fully supported
362
+ return false;
363
+ }
364
+ }
365
+ flattenTree(node) {
366
+ const result = [node];
367
+ if (node.children) {
368
+ for (const child of node.children) {
369
+ result.push(...this.flattenTree(child));
370
+ }
371
+ }
372
+ return result;
373
+ }
374
+ }
375
+ function sleep(ms) {
376
+ return new Promise((resolve) => setTimeout(resolve, ms));
377
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Placeholder adapter that returns stubs for all methods.
3
+ * Used for testing or when no real adapter is configured.
4
+ */
5
+ export class PlaceholderAppAdapter {
6
+ async attach(profile) {
7
+ return {
8
+ sessionId: `session_${profile}_${Date.now()}`,
9
+ profile,
10
+ createdAt: new Date().toISOString(),
11
+ };
12
+ }
13
+ async getAppContext(_sessionId) {
14
+ return {
15
+ bundleId: "com.placeholder",
16
+ appName: "Placeholder",
17
+ pid: 0,
18
+ windowTitle: "Placeholder Session",
19
+ };
20
+ }
21
+ async getPageMeta(_sessionId) {
22
+ return { url: "about:blank", title: "Placeholder Session" };
23
+ }
24
+ async navigate(_sessionId, url, _timeoutMs) {
25
+ return { url, title: "Placeholder Navigation" };
26
+ }
27
+ async locate(_sessionId, _target, _timeoutMs) {
28
+ throw new Error("App adapter not implemented: locate");
29
+ }
30
+ async click(_sessionId, _element) {
31
+ throw new Error("App adapter not implemented: click");
32
+ }
33
+ async setValue(_sessionId, _element, _text, _clear) {
34
+ throw new Error("App adapter not implemented: setValue");
35
+ }
36
+ async getValue(_sessionId, _element) {
37
+ throw new Error("App adapter not implemented: getValue");
38
+ }
39
+ async waitFor(_sessionId, _condition, _timeoutMs) {
40
+ throw new Error("App adapter not implemented: waitFor");
41
+ }
42
+ async extract(_sessionId, _target, _format) {
43
+ throw new Error("App adapter not implemented: extract");
44
+ }
45
+ async screenshot(_sessionId, _region) {
46
+ throw new Error("App adapter not implemented: screenshot");
47
+ }
48
+ }