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
@@ -1,376 +0,0 @@
1
- // Copyright (C) 2025 Clazro Technology Private Limited
2
- // SPDX-License-Identifier: AGPL-3.0-only
3
- //
4
- // This file is part of ScreenHand.
5
- //
6
- // ScreenHand is free software: you can redistribute it and/or modify
7
- // it under the terms of the GNU Affero General Public License as
8
- // published by the Free Software Foundation, version 3.
9
- //
10
- // ScreenHand is distributed in the hope that it will be useful,
11
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- // GNU Affero General Public License for more details.
14
- //
15
- // You should have received a copy of the GNU Affero General Public License
16
- // along with ScreenHand. If not, see <https://www.gnu.org/licenses/>.
17
-
18
- import { execFile } from "node:child_process";
19
- import { promisify } from "node:util";
20
- import type {
21
- AppContext,
22
- ExtractFormat,
23
- LocatedElement,
24
- PageMeta,
25
- RunningApp,
26
- SessionInfo,
27
- Target,
28
- WaitCondition,
29
- WindowInfo,
30
- } from "../types.js";
31
- import type { AppAdapter } from "./app-adapter.js";
32
-
33
- const execFileAsync = promisify(execFile);
34
- const POLL_INTERVAL_MS = 100;
35
-
36
- /** Apps known to have AppleScript scripting dictionaries. */
37
- const SCRIPTABLE_APPS: Record<string, string> = {
38
- "com.apple.finder": "Finder",
39
- "com.apple.Safari": "Safari",
40
- "com.apple.mail": "Mail",
41
- "com.apple.iWork.Pages": "Pages",
42
- "com.apple.iWork.Keynote": "Keynote",
43
- "com.apple.iWork.Numbers": "Numbers",
44
- "com.apple.Notes": "Notes",
45
- "com.apple.reminders": "Reminders",
46
- "com.apple.iCal": "Calendar",
47
- "com.apple.TextEdit": "TextEdit",
48
- "com.apple.Preview": "Preview",
49
- "com.apple.systempreferences": "System Preferences",
50
- "com.apple.Terminal": "Terminal",
51
- "com.apple.Music": "Music",
52
- "com.apple.TV": "TV",
53
- "com.apple.Podcasts": "Podcasts",
54
- };
55
-
56
- interface ASSessionState {
57
- info: SessionInfo;
58
- appName: string;
59
- bundleId: string;
60
- }
61
-
62
- export class AppleScriptAdapter implements AppAdapter {
63
- private readonly sessions = new Map<string, ASSessionState>();
64
- private readonly sessionsByProfile = new Map<string, ASSessionState>();
65
-
66
- /** Check if a bundle ID is scriptable. */
67
- static isScriptable(bundleId: string): boolean {
68
- return bundleId in SCRIPTABLE_APPS;
69
- }
70
-
71
- async attach(profile: string): Promise<SessionInfo> {
72
- const existing = this.sessionsByProfile.get(profile);
73
- if (existing) return existing.info;
74
-
75
- const info: SessionInfo = {
76
- sessionId: `as_session_${profile}_${Date.now()}`,
77
- profile,
78
- createdAt: new Date().toISOString(),
79
- adapterType: "applescript",
80
- };
81
-
82
- // Default to Finder
83
- const state: ASSessionState = {
84
- info,
85
- appName: "Finder",
86
- bundleId: "com.apple.finder",
87
- };
88
-
89
- this.sessions.set(info.sessionId, state);
90
- this.sessionsByProfile.set(profile, state);
91
- return info;
92
- }
93
-
94
- async getAppContext(sessionId: string): Promise<AppContext> {
95
- const state = this.requireSession(sessionId);
96
- const windowTitle = await this.runScript(
97
- `tell application "${state.appName}" to get name of front window`,
98
- ).catch(() => state.appName);
99
-
100
- const pidStr = await this.runScript(
101
- `tell application "System Events" to get unix id of (first process whose bundle identifier is "${state.bundleId}")`,
102
- ).catch(() => "0");
103
-
104
- return {
105
- bundleId: state.bundleId,
106
- appName: state.appName,
107
- pid: parseInt(pidStr, 10) || 0,
108
- windowTitle,
109
- };
110
- }
111
-
112
- async getPageMeta(sessionId: string): Promise<PageMeta> {
113
- const ctx = await this.getAppContext(sessionId);
114
- let url = `app://${ctx.bundleId}`;
115
-
116
- // For Safari, get the current URL
117
- if (ctx.bundleId === "com.apple.Safari") {
118
- try {
119
- url = await this.runScript(
120
- 'tell application "Safari" to get URL of current tab of front window',
121
- );
122
- } catch {
123
- // Ignore
124
- }
125
- }
126
-
127
- return { url, title: ctx.windowTitle };
128
- }
129
-
130
- async navigate(sessionId: string, url: string, _timeoutMs: number): Promise<PageMeta> {
131
- const state = this.requireSession(sessionId);
132
-
133
- if (url.startsWith("app://")) {
134
- const bundleId = url.slice(6);
135
- const appName = SCRIPTABLE_APPS[bundleId] ?? bundleId;
136
- state.bundleId = bundleId;
137
- state.appName = appName;
138
- await this.runScript(`tell application "${appName}" to activate`);
139
- } else if (state.bundleId === "com.apple.Safari") {
140
- await this.runScript(
141
- `tell application "Safari" to set URL of current tab of front window to "${this.escapeAS(url)}"`,
142
- );
143
- } else if (state.bundleId === "com.apple.finder") {
144
- // Open path in Finder
145
- await this.runScript(
146
- `tell application "Finder" to open POSIX file "${this.escapeAS(url)}"`,
147
- );
148
- }
149
-
150
- return this.getPageMeta(sessionId);
151
- }
152
-
153
- async locate(sessionId: string, target: Target, timeoutMs: number): Promise<LocatedElement | null> {
154
- const state = this.requireSession(sessionId);
155
- const deadline = Date.now() + timeoutMs;
156
-
157
- while (Date.now() < deadline) {
158
- try {
159
- const script = this.buildLocateScript(state, target);
160
- const result = await this.runScript(script);
161
- if (result && result !== "missing value") {
162
- return {
163
- handleId: `as_${result.replace(/\s+/g, "_").slice(0, 50)}`,
164
- locatorUsed: `applescript:${target.type}`,
165
- label: result,
166
- };
167
- }
168
- } catch {
169
- // Not found yet
170
- }
171
- await sleep(POLL_INTERVAL_MS);
172
- }
173
- return null;
174
- }
175
-
176
- async click(sessionId: string, element: LocatedElement): Promise<void> {
177
- const state = this.requireSession(sessionId);
178
- await this.runScript(
179
- `tell application "System Events" to tell process "${state.appName}" to click button "${this.escapeAS(element.label ?? element.handleId)}" of front window`,
180
- );
181
- }
182
-
183
- async setValue(sessionId: string, element: LocatedElement, text: string, _clear: boolean): Promise<void> {
184
- const state = this.requireSession(sessionId);
185
- await this.runScript(
186
- `tell application "System Events" to tell process "${state.appName}" to set value of text field "${this.escapeAS(element.label ?? "")}" of front window to "${this.escapeAS(text)}"`,
187
- );
188
- }
189
-
190
- async getValue(sessionId: string, element: LocatedElement): Promise<string> {
191
- const state = this.requireSession(sessionId);
192
- return this.runScript(
193
- `tell application "System Events" to tell process "${state.appName}" to get value of text field "${this.escapeAS(element.label ?? "")}" of front window`,
194
- );
195
- }
196
-
197
- async waitFor(sessionId: string, condition: WaitCondition, timeoutMs: number): Promise<boolean> {
198
- const deadline = Date.now() + timeoutMs;
199
- while (Date.now() < deadline) {
200
- try {
201
- if (condition.type === "text_appears") {
202
- const found = await this.locate(
203
- sessionId,
204
- { type: "text", value: condition.text },
205
- 200,
206
- );
207
- if (found) return true;
208
- } else if (condition.type === "window_title_matches") {
209
- const ctx = await this.getAppContext(sessionId);
210
- if (new RegExp(condition.regex).test(ctx.windowTitle)) return true;
211
- }
212
- } catch {
213
- // Keep trying
214
- }
215
- await sleep(POLL_INTERVAL_MS);
216
- }
217
- return false;
218
- }
219
-
220
- async extract(sessionId: string, target: Target, format: ExtractFormat): Promise<unknown> {
221
- const state = this.requireSession(sessionId);
222
-
223
- if (state.bundleId === "com.apple.finder" && format === "json") {
224
- // Get selected files
225
- const result = await this.runScript(
226
- 'tell application "Finder" to get name of every item of (target of front window) as list',
227
- );
228
- return { items: result.split(", ") };
229
- }
230
-
231
- // Generic: extract UI element text
232
- const element = await this.locate(sessionId, target, 1500);
233
- if (!element) throw new Error("Extract target not found");
234
- return element.label ?? "";
235
- }
236
-
237
- async screenshot(_sessionId: string, _region?: { x: number; y: number; width: number; height: number }): Promise<string> {
238
- const path = `/tmp/as_screenshot_${Date.now()}.png`;
239
- await this.runScript(
240
- `do shell script "screencapture -x '${path}'"`,
241
- );
242
- return path;
243
- }
244
-
245
- // ── Desktop methods ──
246
-
247
- async launchApp(sessionId: string, bundleId: string): Promise<AppContext> {
248
- const state = this.requireSession(sessionId);
249
- const appName = SCRIPTABLE_APPS[bundleId] ?? bundleId;
250
- await this.runScript(`tell application "${appName}" to activate`);
251
- state.bundleId = bundleId;
252
- state.appName = appName;
253
- return this.getAppContext(sessionId);
254
- }
255
-
256
- async focusApp(sessionId: string, bundleId: string): Promise<void> {
257
- const appName = SCRIPTABLE_APPS[bundleId] ?? bundleId;
258
- await this.runScript(`tell application "${appName}" to activate`);
259
- const state = this.requireSession(sessionId);
260
- state.bundleId = bundleId;
261
- state.appName = appName;
262
- }
263
-
264
- async listApps(_sessionId: string): Promise<RunningApp[]> {
265
- const result = await this.runScript(
266
- 'tell application "System Events" to get {bundle identifier, name, unix id, frontmost} of every application process whose background only is false',
267
- );
268
- // Parse the AppleScript list output
269
- const parts = result.split(", ");
270
- const count = Math.floor(parts.length / 4);
271
- const apps: RunningApp[] = [];
272
- for (let i = 0; i < count; i++) {
273
- apps.push({
274
- bundleId: parts[i] ?? "unknown",
275
- name: parts[count + i] ?? "Unknown",
276
- pid: parseInt(parts[2 * count + i] ?? "0", 10),
277
- isActive: parts[3 * count + i] === "true",
278
- });
279
- }
280
- return apps;
281
- }
282
-
283
- async listWindows(_sessionId: string): Promise<WindowInfo[]> {
284
- // Simplified — AppleScript window listing is limited
285
- const result = await this.runScript(
286
- 'tell application "System Events" to get {name, position, size} of every window of (first process whose frontmost is true)',
287
- );
288
- return [{
289
- windowId: 0,
290
- title: result,
291
- bundleId: "",
292
- pid: 0,
293
- bounds: { x: 0, y: 0, width: 0, height: 0 },
294
- isOnScreen: true,
295
- }];
296
- }
297
-
298
- async menuClick(sessionId: string, menuPath: string[]): Promise<void> {
299
- const state = this.requireSession(sessionId);
300
- if (menuPath.length === 0) throw new Error("menuPath must not be empty");
301
-
302
- let script = `tell application "System Events" to tell process "${state.appName}"\n`;
303
- if (menuPath.length === 1) {
304
- script += ` click menu item "${this.escapeAS(menuPath[0]!)}" of menu bar 1\n`;
305
- } else if (menuPath.length === 2) {
306
- script += ` click menu item "${this.escapeAS(menuPath[1]!)}" of menu "${this.escapeAS(menuPath[0]!)}" of menu bar 1\n`;
307
- } else {
308
- // Deep menu path
309
- script += ` click menu item "${this.escapeAS(menuPath[menuPath.length - 1]!)}" of menu "${this.escapeAS(menuPath[menuPath.length - 2]!)}"`;
310
- for (let i = menuPath.length - 3; i >= 0; i--) {
311
- script += ` of menu item "${this.escapeAS(menuPath[i]!)}" of menu "${this.escapeAS(menuPath[i]!)}"`;
312
- }
313
- script += ` of menu bar 1\n`;
314
- }
315
- script += `end tell`;
316
-
317
- await this.runScript(script);
318
- }
319
-
320
- async keyCombo(_sessionId: string, keys: string[]): Promise<void> {
321
- const modifiers: string[] = [];
322
- let keyChar = "";
323
-
324
- for (const key of keys) {
325
- const lower = key.toLowerCase();
326
- if (lower === "cmd" || lower === "command") modifiers.push("command down");
327
- else if (lower === "shift") modifiers.push("shift down");
328
- else if (lower === "alt" || lower === "option") modifiers.push("option down");
329
- else if (lower === "ctrl" || lower === "control") modifiers.push("control down");
330
- else keyChar = lower;
331
- }
332
-
333
- const modStr = modifiers.length > 0 ? ` using {${modifiers.join(", ")}}` : "";
334
- await this.runScript(
335
- `tell application "System Events" to keystroke "${this.escapeAS(keyChar)}"${modStr}`,
336
- );
337
- }
338
-
339
- // ── Private helpers ──
340
-
341
- private requireSession(sessionId: string): ASSessionState {
342
- const state = this.sessions.get(sessionId);
343
- if (!state) throw new Error(`Session not found: ${sessionId}`);
344
- return state;
345
- }
346
-
347
- private async runScript(script: string): Promise<string> {
348
- const { stdout } = await execFileAsync("osascript", ["-e", script], {
349
- timeout: 10_000,
350
- });
351
- return stdout.trim();
352
- }
353
-
354
- private buildLocateScript(state: ASSessionState, target: Target): string {
355
- const proc = state.appName;
356
-
357
- if (target.type === "text" || target.type === "role") {
358
- const searchText = target.type === "text" ? target.value : target.name;
359
- return `tell application "System Events" to tell process "${proc}" to get name of first UI element of front window whose name contains "${this.escapeAS(searchText)}"`;
360
- }
361
-
362
- if (target.type === "selector") {
363
- return `tell application "System Events" to tell process "${proc}" to get name of first UI element of front window whose description contains "${this.escapeAS(target.value)}"`;
364
- }
365
-
366
- throw new Error(`AppleScript adapter does not support target type: ${target.type}`);
367
- }
368
-
369
- private escapeAS(str: string): string {
370
- return str.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
371
- }
372
- }
373
-
374
- function sleep(ms: number): Promise<void> {
375
- return new Promise((resolve) => setTimeout(resolve, ms));
376
- }
@@ -1,102 +0,0 @@
1
- // Copyright (C) 2025 Clazro Technology Private Limited
2
- // SPDX-License-Identifier: AGPL-3.0-only
3
- //
4
- // This file is part of ScreenHand.
5
- //
6
- // ScreenHand is free software: you can redistribute it and/or modify
7
- // it under the terms of the GNU Affero General Public License as
8
- // published by the Free Software Foundation, version 3.
9
- //
10
- // ScreenHand is distributed in the hope that it will be useful,
11
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- // GNU Affero General Public License for more details.
14
- //
15
- // You should have received a copy of the GNU Affero General Public License
16
- // along with ScreenHand. If not, see <https://www.gnu.org/licenses/>.
17
-
18
- /**
19
- * Maps web ARIA roles to macOS Accessibility roles.
20
- * Used to translate web-style role targets to native AX queries.
21
- */
22
- export const WEB_TO_AX_ROLE: Record<string, string> = {
23
- // Interactive
24
- button: "AXButton",
25
- link: "AXLink",
26
- textbox: "AXTextField",
27
- checkbox: "AXCheckBox",
28
- radio: "AXRadioButton",
29
- combobox: "AXComboBox",
30
- slider: "AXSlider",
31
- switch: "AXCheckBox",
32
- tab: "AXRadioButton",
33
- menuitem: "AXMenuItem",
34
- menu: "AXMenu",
35
- menubar: "AXMenuBar",
36
- option: "AXMenuItem",
37
- listbox: "AXList",
38
- spinbutton: "AXIncrementor",
39
- scrollbar: "AXScrollBar",
40
-
41
- // Structure
42
- heading: "AXHeading",
43
- list: "AXList",
44
- listitem: "AXGroup",
45
- table: "AXTable",
46
- row: "AXRow",
47
- cell: "AXCell",
48
- grid: "AXTable",
49
- treegrid: "AXOutline",
50
- tree: "AXOutline",
51
- treeitem: "AXOutlineRow",
52
- toolbar: "AXToolbar",
53
- tablist: "AXTabGroup",
54
- tabpanel: "AXGroup",
55
- group: "AXGroup",
56
- region: "AXGroup",
57
- dialog: "AXSheet",
58
- alertdialog: "AXSheet",
59
-
60
- // Semantic
61
- img: "AXImage",
62
- image: "AXImage",
63
- progressbar: "AXProgressIndicator",
64
- separator: "AXSplitter",
65
- status: "AXStaticText",
66
- tooltip: "AXHelpTag",
67
- banner: "AXGroup",
68
- navigation: "AXGroup",
69
- main: "AXGroup",
70
- contentinfo: "AXGroup",
71
- complementary: "AXGroup",
72
- article: "AXGroup",
73
- document: "AXGroup",
74
-
75
- // Text
76
- statictext: "AXStaticText",
77
- textarea: "AXTextArea",
78
- text: "AXStaticText",
79
-
80
- // Window-level
81
- window: "AXWindow",
82
- application: "AXApplication",
83
- };
84
-
85
- /**
86
- * Maps macOS AX roles back to web ARIA roles.
87
- */
88
- export const AX_TO_WEB_ROLE: Record<string, string> = {};
89
- for (const [web, ax] of Object.entries(WEB_TO_AX_ROLE)) {
90
- if (!(ax in AX_TO_WEB_ROLE)) {
91
- AX_TO_WEB_ROLE[ax] = web;
92
- }
93
- }
94
-
95
- /**
96
- * Convert a web-style role to macOS AX role.
97
- * If already an AX role (starts with "AX"), pass through.
98
- */
99
- export function toAXRole(role: string): string {
100
- if (role.startsWith("AX")) return role;
101
- return WEB_TO_AX_ROLE[role.toLowerCase()] ?? role;
102
- }
@@ -1,129 +0,0 @@
1
- // Copyright (C) 2025 Clazro Technology Private Limited
2
- // SPDX-License-Identifier: AGPL-3.0-only
3
- //
4
- // This file is part of ScreenHand.
5
- //
6
- // ScreenHand is free software: you can redistribute it and/or modify
7
- // it under the terms of the GNU Affero General Public License as
8
- // published by the Free Software Foundation, version 3.
9
- //
10
- // ScreenHand is distributed in the hope that it will be useful,
11
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- // GNU Affero General Public License for more details.
14
- //
15
- // You should have received a copy of the GNU Affero General Public License
16
- // along with ScreenHand. If not, see <https://www.gnu.org/licenses/>.
17
-
18
- import type {
19
- ExtractFormat,
20
- LocatedElement,
21
- PageMeta,
22
- SessionInfo,
23
- Target,
24
- WaitCondition,
25
- } from "../types.js";
26
-
27
- export interface BrowserAdapter {
28
- connect(profile: string): Promise<SessionInfo>;
29
- getPageMeta(sessionId: string): Promise<PageMeta>;
30
- navigate(sessionId: string, url: string, timeoutMs: number): Promise<PageMeta>;
31
- locate(
32
- sessionId: string,
33
- target: Target,
34
- timeoutMs: number,
35
- ): Promise<LocatedElement | null>;
36
- click(sessionId: string, element: LocatedElement): Promise<void>;
37
- setValue(
38
- sessionId: string,
39
- element: LocatedElement,
40
- text: string,
41
- clear: boolean,
42
- ): Promise<void>;
43
- getValue(sessionId: string, element: LocatedElement): Promise<string>;
44
- waitFor(
45
- sessionId: string,
46
- condition: WaitCondition,
47
- timeoutMs: number,
48
- ): Promise<boolean>;
49
- extract(
50
- sessionId: string,
51
- target: Target,
52
- format: ExtractFormat,
53
- ): Promise<unknown>;
54
- screenshot(
55
- sessionId: string,
56
- region?: { x: number; y: number; width: number; height: number },
57
- ): Promise<string>;
58
- }
59
-
60
- export class PlaceholderBrowserAdapter implements BrowserAdapter {
61
- async connect(profile: string): Promise<SessionInfo> {
62
- return {
63
- sessionId: `session_${profile}_${Date.now()}`,
64
- profile,
65
- createdAt: new Date().toISOString(),
66
- };
67
- }
68
-
69
- async getPageMeta(_sessionId: string): Promise<PageMeta> {
70
- return { url: "about:blank", title: "Placeholder Session" };
71
- }
72
-
73
- async navigate(
74
- _sessionId: string,
75
- url: string,
76
- _timeoutMs: number,
77
- ): Promise<PageMeta> {
78
- return { url, title: "Placeholder Navigation" };
79
- }
80
-
81
- async locate(
82
- _sessionId: string,
83
- _target: Target,
84
- _timeoutMs: number,
85
- ): Promise<LocatedElement | null> {
86
- throw new Error("Browser adapter not implemented: locate");
87
- }
88
-
89
- async click(_sessionId: string, _element: LocatedElement): Promise<void> {
90
- throw new Error("Browser adapter not implemented: click");
91
- }
92
-
93
- async setValue(
94
- _sessionId: string,
95
- _element: LocatedElement,
96
- _text: string,
97
- _clear: boolean,
98
- ): Promise<void> {
99
- throw new Error("Browser adapter not implemented: setValue");
100
- }
101
-
102
- async getValue(_sessionId: string, _element: LocatedElement): Promise<string> {
103
- throw new Error("Browser adapter not implemented: getValue");
104
- }
105
-
106
- async waitFor(
107
- _sessionId: string,
108
- _condition: WaitCondition,
109
- _timeoutMs: number,
110
- ): Promise<boolean> {
111
- throw new Error("Browser adapter not implemented: waitFor");
112
- }
113
-
114
- async extract(
115
- _sessionId: string,
116
- _target: Target,
117
- _format: ExtractFormat,
118
- ): Promise<unknown> {
119
- throw new Error("Browser adapter not implemented: extract");
120
- }
121
-
122
- async screenshot(
123
- _sessionId: string,
124
- _region?: { x: number; y: number; width: number; height: number },
125
- ): Promise<string> {
126
- throw new Error("Browser adapter not implemented: screenshot");
127
- }
128
- }
129
-