screenhand 0.1.1 → 0.3.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.
- package/README.md +193 -109
- package/bin/darwin-arm64/macos-bridge +0 -0
- package/dist/mcp-desktop.js +5876 -0
- package/dist/scripts/codex-monitor-daemon.js +335 -0
- package/dist/scripts/export-help-center.js +112 -0
- package/dist/scripts/marketing-loop.js +117 -0
- package/dist/scripts/observer-daemon.js +288 -0
- package/dist/scripts/orchestrator-daemon.js +399 -0
- package/dist/scripts/supervisor-daemon.js +272 -0
- package/dist/scripts/threads-campaign.js +208 -0
- package/dist/scripts/worker-daemon.js +228 -0
- package/dist/src/agent/cli.js +82 -0
- package/dist/src/agent/loop.js +274 -0
- package/dist/src/community/fetcher.js +109 -0
- package/dist/src/community/index.js +6 -0
- package/dist/src/community/publisher.js +191 -0
- package/dist/src/community/remote-api.js +121 -0
- package/dist/src/community/types.js +3 -0
- package/dist/src/community/validator.js +95 -0
- package/{src/config.ts → dist/src/config.js} +5 -10
- package/dist/src/context-tracker.js +489 -0
- package/{src/index.ts → dist/src/index.js} +32 -52
- package/dist/src/ingestion/coverage-auditor.js +233 -0
- package/dist/src/ingestion/doc-parser.js +164 -0
- package/dist/src/ingestion/index.js +8 -0
- package/dist/src/ingestion/menu-scanner.js +152 -0
- package/dist/src/ingestion/reference-merger.js +186 -0
- package/dist/src/ingestion/shortcut-extractor.js +180 -0
- package/dist/src/ingestion/tutorial-extractor.js +170 -0
- package/dist/src/ingestion/types.js +3 -0
- package/dist/src/jobs/manager.js +305 -0
- package/dist/src/jobs/runner.js +806 -0
- package/dist/src/jobs/store.js +102 -0
- package/dist/src/jobs/types.js +30 -0
- package/dist/src/jobs/worker.js +97 -0
- package/dist/src/learning/engine.js +356 -0
- package/dist/src/learning/index.js +9 -0
- package/dist/src/learning/locator-policy.js +120 -0
- package/dist/src/learning/pattern-policy.js +89 -0
- package/dist/src/learning/recovery-policy.js +116 -0
- package/dist/src/learning/sensor-policy.js +115 -0
- package/dist/src/learning/timing-model.js +204 -0
- package/dist/src/learning/topology-policy.js +90 -0
- package/dist/src/learning/types.js +9 -0
- package/dist/src/logging/timeline-logger.js +48 -0
- package/dist/src/mcp/mcp-stdio-server.js +464 -0
- package/dist/src/mcp/server.js +363 -0
- package/dist/src/mcp-entry.js +60 -0
- package/dist/src/memory/playbook-seeds.js +200 -0
- package/dist/src/memory/recall.js +222 -0
- package/dist/src/memory/research.js +104 -0
- package/dist/src/memory/seeds.js +101 -0
- package/dist/src/memory/service.js +446 -0
- package/dist/src/memory/session.js +169 -0
- package/dist/src/memory/store.js +451 -0
- package/{src/runtime/locator-cache.ts → dist/src/memory/types.js} +1 -17
- package/dist/src/monitor/codex-monitor.js +382 -0
- package/dist/src/monitor/task-queue.js +97 -0
- package/dist/src/monitor/types.js +62 -0
- package/dist/src/native/bridge-client.js +412 -0
- package/{src/native/macos-bridge-client.ts → dist/src/native/macos-bridge-client.js} +0 -1
- package/dist/src/observer/state.js +199 -0
- package/dist/src/observer/types.js +43 -0
- package/dist/src/orchestrator/state.js +68 -0
- package/dist/src/orchestrator/types.js +22 -0
- package/dist/src/perception/ax-source.js +162 -0
- package/dist/src/perception/cdp-source.js +162 -0
- package/dist/src/perception/coordinator.js +771 -0
- package/dist/src/perception/frame-differ.js +287 -0
- package/dist/src/perception/index.js +22 -0
- package/dist/src/perception/manager.js +199 -0
- package/dist/src/perception/types.js +47 -0
- package/dist/src/perception/vision-source.js +399 -0
- package/dist/src/planner/deterministic.js +298 -0
- package/dist/src/planner/executor.js +870 -0
- package/dist/src/planner/goal-store.js +92 -0
- package/dist/src/planner/index.js +21 -0
- package/dist/src/planner/planner.js +520 -0
- package/dist/src/planner/tool-registry.js +71 -0
- package/dist/src/planner/types.js +22 -0
- package/dist/src/platform/explorer.js +213 -0
- package/dist/src/platform/help-center-markdown.js +527 -0
- package/dist/src/platform/learner.js +257 -0
- package/dist/src/playbook/engine.js +486 -0
- package/dist/src/playbook/index.js +20 -0
- package/dist/src/playbook/mcp-recorder.js +204 -0
- package/dist/src/playbook/recorder.js +536 -0
- package/dist/src/playbook/runner.js +408 -0
- package/dist/src/playbook/store.js +312 -0
- package/dist/src/playbook/types.js +17 -0
- package/dist/src/recovery/detectors.js +156 -0
- package/dist/src/recovery/engine.js +327 -0
- package/dist/src/recovery/index.js +20 -0
- package/dist/src/recovery/strategies.js +274 -0
- package/dist/src/recovery/types.js +20 -0
- package/dist/src/runtime/accessibility-adapter.js +430 -0
- package/dist/src/runtime/app-adapter.js +64 -0
- package/dist/src/runtime/applescript-adapter.js +305 -0
- package/dist/src/runtime/ax-role-map.js +96 -0
- package/dist/src/runtime/browser-adapter.js +52 -0
- package/dist/src/runtime/cdp-chrome-adapter.js +521 -0
- package/dist/src/runtime/composite-adapter.js +221 -0
- package/dist/src/runtime/execution-contract.js +159 -0
- package/dist/src/runtime/executor.js +286 -0
- package/dist/src/runtime/locator-cache.js +50 -0
- package/dist/src/runtime/planning-loop.js +63 -0
- package/dist/src/runtime/service.js +432 -0
- package/dist/src/runtime/session-manager.js +63 -0
- package/dist/src/runtime/state-observer.js +121 -0
- package/dist/src/runtime/vision-adapter.js +225 -0
- package/dist/src/state/app-map-types.js +72 -0
- package/dist/src/state/app-map.js +1974 -0
- package/dist/src/state/entity-tracker.js +108 -0
- package/dist/src/state/fusion.js +96 -0
- package/dist/src/state/index.js +21 -0
- package/dist/src/state/ladder-generator.js +236 -0
- package/dist/src/state/persistence.js +156 -0
- package/dist/src/state/types.js +17 -0
- package/dist/src/state/world-model.js +1456 -0
- package/dist/src/supervisor/locks.js +186 -0
- package/dist/src/supervisor/supervisor.js +403 -0
- package/dist/src/supervisor/types.js +30 -0
- package/dist/src/test-mcp-protocol.js +154 -0
- package/dist/src/types.js +17 -0
- package/dist/src/util/atomic-write.js +133 -0
- package/dist/src/util/sanitize.js +146 -0
- package/dist-app-maps/com.figma.Desktop.json +959 -0
- package/dist-app-maps/com.hnc.Discord.json +1146 -0
- package/dist-app-maps/notion.id.json +2831 -0
- package/dist-playbooks/canva-screenhand-carousel.json +445 -0
- package/dist-playbooks/codex-desktop.json +76 -0
- package/dist-playbooks/competitor-research-stack.json +122 -0
- package/dist-playbooks/davinci-color-grade.json +153 -0
- package/dist-playbooks/davinci-edit-timeline.json +162 -0
- package/dist-playbooks/davinci-render.json +114 -0
- package/dist-playbooks/devto.json +52 -0
- package/dist-playbooks/discord.json +41 -0
- package/dist-playbooks/google-flow-create-project.json +59 -0
- package/dist-playbooks/google-flow-edit-image.json +90 -0
- package/dist-playbooks/google-flow-edit-video.json +90 -0
- package/dist-playbooks/google-flow-generate-image.json +68 -0
- package/dist-playbooks/google-flow-generate-video.json +191 -0
- package/dist-playbooks/google-flow-open-project.json +48 -0
- package/dist-playbooks/google-flow-open-scenebuilder.json +64 -0
- package/dist-playbooks/google-flow-search-assets.json +64 -0
- package/dist-playbooks/instagram.json +57 -0
- package/dist-playbooks/linkedin.json +52 -0
- package/dist-playbooks/n8n.json +43 -0
- package/dist-playbooks/reddit.json +52 -0
- package/dist-playbooks/threads.json +59 -0
- package/dist-playbooks/x-twitter.json +59 -0
- package/dist-playbooks/youtube.json +59 -0
- package/dist-references/canva.json +646 -0
- package/dist-references/codex-desktop.json +305 -0
- package/dist-references/davinci-resolve-keyboard.json +594 -0
- package/dist-references/davinci-resolve-menu-map.json +1139 -0
- package/dist-references/davinci-resolve-menus-batch1.json +116 -0
- package/dist-references/davinci-resolve-menus-batch2.json +372 -0
- package/dist-references/davinci-resolve-menus-batch3.json +330 -0
- package/dist-references/davinci-resolve-menus-batch4.json +297 -0
- package/dist-references/davinci-resolve-shortcuts.json +333 -0
- package/dist-references/devto.json +317 -0
- package/dist-references/discord.json +549 -0
- package/dist-references/figma.json +1186 -0
- package/dist-references/finder.json +146 -0
- package/dist-references/google-ads-transparency.json +95 -0
- package/dist-references/google-flow.json +649 -0
- package/dist-references/instagram.json +341 -0
- package/dist-references/linkedin.json +324 -0
- package/dist-references/meta-ad-library.json +86 -0
- package/dist-references/n8n.json +387 -0
- package/dist-references/notes.json +27 -0
- package/dist-references/notion.json +163 -0
- package/dist-references/reddit.json +341 -0
- package/dist-references/threads.json +337 -0
- package/dist-references/x-twitter.json +403 -0
- package/dist-references/youtube.json +373 -0
- package/native/macos-bridge/Package.swift +1 -0
- package/native/macos-bridge/Sources/AccessibilityBridge.swift +257 -36
- package/native/macos-bridge/Sources/AppManagement.swift +212 -2
- package/native/macos-bridge/Sources/CoreGraphicsBridge.swift +348 -53
- package/native/macos-bridge/Sources/StreamCapture.swift +136 -0
- package/native/macos-bridge/Sources/VisionBridge.swift +165 -7
- package/native/macos-bridge/Sources/main.swift +169 -16
- package/native/windows-bridge/Program.cs +5 -0
- package/native/windows-bridge/ScreenCapture.cs +124 -0
- package/package.json +29 -4
- package/scripts/postinstall.cjs +127 -0
- package/.claude/commands/automate.md +0 -28
- package/.claude/commands/debug-ui.md +0 -19
- package/.claude/commands/screenshot.md +0 -15
- package/.github/FUNDING.yml +0 -1
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -27
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.mcp.json +0 -8
- package/DESKTOP_MCP_GUIDE.md +0 -92
- package/SECURITY.md +0 -44
- package/docs/architecture.md +0 -47
- package/install-skills.sh +0 -19
- package/mcp-bridge.ts +0 -271
- package/mcp-desktop.ts +0 -1221
- package/playbooks/instagram.json +0 -41
- package/playbooks/instagram_v2.json +0 -201
- package/playbooks/x_v1.json +0 -211
- package/scripts/devpost-live-loop.mjs +0 -421
- package/src/logging/timeline-logger.ts +0 -55
- package/src/mcp/server.ts +0 -449
- package/src/memory/recall.ts +0 -191
- package/src/memory/research.ts +0 -146
- package/src/memory/seeds.ts +0 -123
- package/src/memory/session.ts +0 -201
- package/src/memory/store.ts +0 -434
- package/src/memory/types.ts +0 -69
- package/src/native/bridge-client.ts +0 -239
- package/src/runtime/accessibility-adapter.ts +0 -487
- package/src/runtime/app-adapter.ts +0 -169
- package/src/runtime/applescript-adapter.ts +0 -376
- package/src/runtime/ax-role-map.ts +0 -102
- package/src/runtime/browser-adapter.ts +0 -129
- package/src/runtime/cdp-chrome-adapter.ts +0 -676
- package/src/runtime/composite-adapter.ts +0 -274
- package/src/runtime/executor.ts +0 -396
- package/src/runtime/planning-loop.ts +0 -81
- package/src/runtime/service.ts +0 -448
- package/src/runtime/session-manager.ts +0 -50
- package/src/runtime/state-observer.ts +0 -136
- package/src/runtime/vision-adapter.ts +0 -297
- package/src/types.ts +0 -297
- package/tests/bridge-client.test.ts +0 -176
- package/tests/browser-stealth.test.ts +0 -210
- package/tests/composite-adapter.test.ts +0 -64
- package/tests/mcp-server.test.ts +0 -151
- package/tests/memory-recall.test.ts +0 -339
- package/tests/memory-research.test.ts +0 -159
- package/tests/memory-seeds.test.ts +0 -120
- package/tests/memory-store.test.ts +0 -392
- package/tests/types.test.ts +0 -92
- package/tsconfig.check.json +0 -17
- package/tsconfig.json +0 -19
- package/vitest.config.ts +0 -8
- /package/{playbooks → dist-references}/devpost.json +0 -0
|
@@ -0,0 +1,363 @@
|
|
|
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
|
+
export class MvpMcpServer {
|
|
18
|
+
runtime;
|
|
19
|
+
constructor(runtime) {
|
|
20
|
+
this.runtime = runtime;
|
|
21
|
+
}
|
|
22
|
+
async invoke(request) {
|
|
23
|
+
switch (request.tool) {
|
|
24
|
+
case "session_start":
|
|
25
|
+
return this.runtime.sessionStart(optionalString(request.args, "profile"));
|
|
26
|
+
case "navigate": {
|
|
27
|
+
const timeoutMs = optionalNumber(request.args, "timeoutMs");
|
|
28
|
+
const input = {
|
|
29
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
30
|
+
url: requiredString(request.args, "url"),
|
|
31
|
+
};
|
|
32
|
+
if (typeof timeoutMs === "number") {
|
|
33
|
+
input.timeoutMs = timeoutMs;
|
|
34
|
+
}
|
|
35
|
+
return this.runtime.navigate(input);
|
|
36
|
+
}
|
|
37
|
+
case "press": {
|
|
38
|
+
const verify = parseOptionalWaitCondition(request.args.verify);
|
|
39
|
+
const input = {
|
|
40
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
41
|
+
target: parseTarget(request.args.target),
|
|
42
|
+
};
|
|
43
|
+
if (verify) {
|
|
44
|
+
input.verify = verify;
|
|
45
|
+
}
|
|
46
|
+
return this.runtime.press(input);
|
|
47
|
+
}
|
|
48
|
+
case "type_into": {
|
|
49
|
+
const clear = optionalBoolean(request.args, "clear");
|
|
50
|
+
const verify = parseOptionalWaitCondition(request.args.verify);
|
|
51
|
+
const input = {
|
|
52
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
53
|
+
target: parseTarget(request.args.target),
|
|
54
|
+
text: requiredString(request.args, "text"),
|
|
55
|
+
};
|
|
56
|
+
if (typeof clear === "boolean") {
|
|
57
|
+
input.clear = clear;
|
|
58
|
+
}
|
|
59
|
+
if (verify) {
|
|
60
|
+
input.verify = verify;
|
|
61
|
+
}
|
|
62
|
+
return this.runtime.typeInto(input);
|
|
63
|
+
}
|
|
64
|
+
case "wait_for": {
|
|
65
|
+
const timeoutMs = optionalNumber(request.args, "timeoutMs");
|
|
66
|
+
const input = {
|
|
67
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
68
|
+
condition: parseWaitCondition(request.args.condition),
|
|
69
|
+
};
|
|
70
|
+
if (typeof timeoutMs === "number") {
|
|
71
|
+
input.timeoutMs = timeoutMs;
|
|
72
|
+
}
|
|
73
|
+
return this.runtime.waitFor(input);
|
|
74
|
+
}
|
|
75
|
+
case "extract":
|
|
76
|
+
return this.runtime.extract({
|
|
77
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
78
|
+
target: parseTarget(request.args.target),
|
|
79
|
+
format: parseExtractFormat(request.args.format),
|
|
80
|
+
});
|
|
81
|
+
case "screenshot": {
|
|
82
|
+
const region = parseOptionalRegion(request.args.region);
|
|
83
|
+
const input = {
|
|
84
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
85
|
+
};
|
|
86
|
+
if (region) {
|
|
87
|
+
input.region = region;
|
|
88
|
+
}
|
|
89
|
+
return this.runtime.screenshot(input);
|
|
90
|
+
}
|
|
91
|
+
// ── Desktop automation tools ──
|
|
92
|
+
case "app_launch":
|
|
93
|
+
return this.runtime.appLaunch({
|
|
94
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
95
|
+
bundleId: requiredString(request.args, "bundleId"),
|
|
96
|
+
});
|
|
97
|
+
case "app_focus":
|
|
98
|
+
return this.runtime.appFocus({
|
|
99
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
100
|
+
bundleId: requiredString(request.args, "bundleId"),
|
|
101
|
+
});
|
|
102
|
+
case "app_list":
|
|
103
|
+
return this.runtime.appList(requiredString(request.args, "sessionId"));
|
|
104
|
+
case "window_list":
|
|
105
|
+
return this.runtime.windowList(requiredString(request.args, "sessionId"));
|
|
106
|
+
case "menu_click":
|
|
107
|
+
return this.runtime.menuClick({
|
|
108
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
109
|
+
menuPath: requiredStringArray(request.args, "menuPath"),
|
|
110
|
+
});
|
|
111
|
+
case "key_combo":
|
|
112
|
+
return this.runtime.keyCombo({
|
|
113
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
114
|
+
keys: requiredStringArray(request.args, "keys"),
|
|
115
|
+
});
|
|
116
|
+
case "element_tree": {
|
|
117
|
+
const maxDepth = optionalNumber(request.args, "maxDepth");
|
|
118
|
+
const root = request.args.root ? parseTarget(request.args.root) : undefined;
|
|
119
|
+
const etInput = {
|
|
120
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
121
|
+
};
|
|
122
|
+
if (typeof maxDepth === "number")
|
|
123
|
+
etInput.maxDepth = maxDepth;
|
|
124
|
+
if (root)
|
|
125
|
+
etInput.root = root;
|
|
126
|
+
return this.runtime.elementTree(etInput);
|
|
127
|
+
}
|
|
128
|
+
case "observe_start": {
|
|
129
|
+
const events = request.args.events;
|
|
130
|
+
const osInput = {
|
|
131
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
132
|
+
};
|
|
133
|
+
if (Array.isArray(events)) {
|
|
134
|
+
osInput.events = events;
|
|
135
|
+
}
|
|
136
|
+
return this.runtime.observeStart(osInput);
|
|
137
|
+
}
|
|
138
|
+
case "observe_stop":
|
|
139
|
+
return this.runtime.observeStop({
|
|
140
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
141
|
+
});
|
|
142
|
+
case "drag":
|
|
143
|
+
return this.runtime.drag({
|
|
144
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
145
|
+
from: parseTarget(request.args.from),
|
|
146
|
+
to: parseTarget(request.args.to),
|
|
147
|
+
});
|
|
148
|
+
case "scroll": {
|
|
149
|
+
const scrollTarget = request.args.target ? parseTarget(request.args.target) : undefined;
|
|
150
|
+
const scrollAmount = optionalNumber(request.args, "amount");
|
|
151
|
+
const scrollInput = {
|
|
152
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
153
|
+
direction: requiredString(request.args, "direction"),
|
|
154
|
+
};
|
|
155
|
+
if (scrollTarget)
|
|
156
|
+
scrollInput.target = scrollTarget;
|
|
157
|
+
if (typeof scrollAmount === "number")
|
|
158
|
+
scrollInput.amount = scrollAmount;
|
|
159
|
+
return this.runtime.scroll(scrollInput);
|
|
160
|
+
}
|
|
161
|
+
default:
|
|
162
|
+
throw new Error(`Unsupported tool: ${String(request.tool)}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function parseTarget(input) {
|
|
167
|
+
if (typeof input === "string") {
|
|
168
|
+
if (input.startsWith("css=")) {
|
|
169
|
+
return { type: "selector", value: input.slice(4) };
|
|
170
|
+
}
|
|
171
|
+
if (input.startsWith("text=")) {
|
|
172
|
+
return { type: "text", value: input.slice(5), exact: true };
|
|
173
|
+
}
|
|
174
|
+
if (input.startsWith("ax_id=")) {
|
|
175
|
+
return { type: "ax_attribute", attribute: "identifier", value: input.slice(6) };
|
|
176
|
+
}
|
|
177
|
+
return { type: "text", value: input };
|
|
178
|
+
}
|
|
179
|
+
if (!isRecord(input)) {
|
|
180
|
+
throw new Error("target must be a string or object");
|
|
181
|
+
}
|
|
182
|
+
if (typeof input.selector === "string") {
|
|
183
|
+
return { type: "selector", value: input.selector };
|
|
184
|
+
}
|
|
185
|
+
if (typeof input.text === "string") {
|
|
186
|
+
return {
|
|
187
|
+
type: "text",
|
|
188
|
+
value: input.text,
|
|
189
|
+
exact: input.exact === true,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
if (typeof input.role === "string" && typeof input.name === "string") {
|
|
193
|
+
return {
|
|
194
|
+
type: "role",
|
|
195
|
+
role: input.role,
|
|
196
|
+
name: input.name,
|
|
197
|
+
exact: input.exact === true,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
if (Array.isArray(input.path)) {
|
|
201
|
+
return { type: "ax_path", path: input.path };
|
|
202
|
+
}
|
|
203
|
+
if (typeof input.attribute === "string" && typeof input.value === "string") {
|
|
204
|
+
return { type: "ax_attribute", attribute: input.attribute, value: input.value };
|
|
205
|
+
}
|
|
206
|
+
if (typeof input.x === "number" && typeof input.y === "number") {
|
|
207
|
+
return { type: "coordinates", x: input.x, y: input.y };
|
|
208
|
+
}
|
|
209
|
+
if (typeof input.base64 === "string") {
|
|
210
|
+
const target = { type: "image", base64: input.base64 };
|
|
211
|
+
if (typeof input.confidence === "number") {
|
|
212
|
+
target.confidence = input.confidence;
|
|
213
|
+
}
|
|
214
|
+
return target;
|
|
215
|
+
}
|
|
216
|
+
throw new Error("target object must contain selector, text, role+name, path, attribute+value, x+y, or base64");
|
|
217
|
+
}
|
|
218
|
+
function parseWaitCondition(input) {
|
|
219
|
+
if (!isRecord(input) || typeof input.type !== "string") {
|
|
220
|
+
throw new Error("condition must be an object with a type");
|
|
221
|
+
}
|
|
222
|
+
switch (input.type) {
|
|
223
|
+
case "selector_visible":
|
|
224
|
+
return {
|
|
225
|
+
type: "selector_visible",
|
|
226
|
+
selector: requiredObjectString(input, "selector"),
|
|
227
|
+
};
|
|
228
|
+
case "selector_hidden":
|
|
229
|
+
return {
|
|
230
|
+
type: "selector_hidden",
|
|
231
|
+
selector: requiredObjectString(input, "selector"),
|
|
232
|
+
};
|
|
233
|
+
case "url_matches":
|
|
234
|
+
return {
|
|
235
|
+
type: "url_matches",
|
|
236
|
+
regex: requiredObjectString(input, "regex"),
|
|
237
|
+
};
|
|
238
|
+
case "text_appears":
|
|
239
|
+
return {
|
|
240
|
+
type: "text_appears",
|
|
241
|
+
text: requiredObjectString(input, "text"),
|
|
242
|
+
};
|
|
243
|
+
case "spinner_disappears":
|
|
244
|
+
return {
|
|
245
|
+
type: "spinner_disappears",
|
|
246
|
+
selector: requiredObjectString(input, "selector"),
|
|
247
|
+
};
|
|
248
|
+
case "element_exists":
|
|
249
|
+
return {
|
|
250
|
+
type: "element_exists",
|
|
251
|
+
target: parseTarget(input.target),
|
|
252
|
+
};
|
|
253
|
+
case "element_gone":
|
|
254
|
+
return {
|
|
255
|
+
type: "element_gone",
|
|
256
|
+
target: parseTarget(input.target),
|
|
257
|
+
};
|
|
258
|
+
case "window_title_matches":
|
|
259
|
+
return {
|
|
260
|
+
type: "window_title_matches",
|
|
261
|
+
regex: requiredObjectString(input, "regex"),
|
|
262
|
+
};
|
|
263
|
+
case "app_idle": {
|
|
264
|
+
const cond = {
|
|
265
|
+
type: "app_idle",
|
|
266
|
+
bundleId: requiredObjectString(input, "bundleId"),
|
|
267
|
+
};
|
|
268
|
+
if (typeof input.timeoutMs === "number") {
|
|
269
|
+
cond.timeoutMs = input.timeoutMs;
|
|
270
|
+
}
|
|
271
|
+
return cond;
|
|
272
|
+
}
|
|
273
|
+
default:
|
|
274
|
+
throw new Error(`Unsupported condition type: ${input.type}`);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
function parseOptionalWaitCondition(input) {
|
|
278
|
+
if (typeof input === "undefined") {
|
|
279
|
+
return undefined;
|
|
280
|
+
}
|
|
281
|
+
return parseWaitCondition(input);
|
|
282
|
+
}
|
|
283
|
+
function parseExtractFormat(input) {
|
|
284
|
+
if (input === "text" || input === "table" || input === "json") {
|
|
285
|
+
return input;
|
|
286
|
+
}
|
|
287
|
+
throw new Error("format must be one of: text, table, json");
|
|
288
|
+
}
|
|
289
|
+
function parseOptionalRegion(input) {
|
|
290
|
+
if (typeof input === "undefined") {
|
|
291
|
+
return undefined;
|
|
292
|
+
}
|
|
293
|
+
if (!isRecord(input)) {
|
|
294
|
+
throw new Error("region must be an object");
|
|
295
|
+
}
|
|
296
|
+
return {
|
|
297
|
+
x: requiredObjectNumber(input, "x"),
|
|
298
|
+
y: requiredObjectNumber(input, "y"),
|
|
299
|
+
width: requiredObjectNumber(input, "width"),
|
|
300
|
+
height: requiredObjectNumber(input, "height"),
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
function requiredString(input, key) {
|
|
304
|
+
const value = input[key];
|
|
305
|
+
if (typeof value !== "string") {
|
|
306
|
+
throw new Error(`${key} must be a string`);
|
|
307
|
+
}
|
|
308
|
+
return value;
|
|
309
|
+
}
|
|
310
|
+
function requiredStringArray(input, key) {
|
|
311
|
+
const value = input[key];
|
|
312
|
+
if (!Array.isArray(value) || !value.every((v) => typeof v === "string")) {
|
|
313
|
+
throw new Error(`${key} must be an array of strings`);
|
|
314
|
+
}
|
|
315
|
+
return value;
|
|
316
|
+
}
|
|
317
|
+
function optionalString(input, key) {
|
|
318
|
+
const value = input[key];
|
|
319
|
+
if (typeof value === "undefined") {
|
|
320
|
+
return undefined;
|
|
321
|
+
}
|
|
322
|
+
if (typeof value !== "string") {
|
|
323
|
+
throw new Error(`${key} must be a string`);
|
|
324
|
+
}
|
|
325
|
+
return value;
|
|
326
|
+
}
|
|
327
|
+
function optionalNumber(input, key) {
|
|
328
|
+
const value = input[key];
|
|
329
|
+
if (typeof value === "undefined") {
|
|
330
|
+
return undefined;
|
|
331
|
+
}
|
|
332
|
+
if (typeof value !== "number") {
|
|
333
|
+
throw new Error(`${key} must be a number`);
|
|
334
|
+
}
|
|
335
|
+
return value;
|
|
336
|
+
}
|
|
337
|
+
function optionalBoolean(input, key) {
|
|
338
|
+
const value = input[key];
|
|
339
|
+
if (typeof value === "undefined") {
|
|
340
|
+
return undefined;
|
|
341
|
+
}
|
|
342
|
+
if (typeof value !== "boolean") {
|
|
343
|
+
throw new Error(`${key} must be a boolean`);
|
|
344
|
+
}
|
|
345
|
+
return value;
|
|
346
|
+
}
|
|
347
|
+
function requiredObjectString(input, key) {
|
|
348
|
+
const value = input[key];
|
|
349
|
+
if (typeof value !== "string") {
|
|
350
|
+
throw new Error(`${key} must be a string`);
|
|
351
|
+
}
|
|
352
|
+
return value;
|
|
353
|
+
}
|
|
354
|
+
function requiredObjectNumber(input, key) {
|
|
355
|
+
const value = input[key];
|
|
356
|
+
if (typeof value !== "number") {
|
|
357
|
+
throw new Error(`${key} must be a number`);
|
|
358
|
+
}
|
|
359
|
+
return value;
|
|
360
|
+
}
|
|
361
|
+
function isRecord(input) {
|
|
362
|
+
return typeof input === "object" && input !== null;
|
|
363
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Copyright (C) 2025 Clazro Technology Private Limited
|
|
3
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
4
|
+
//
|
|
5
|
+
// This file is part of ScreenHand.
|
|
6
|
+
//
|
|
7
|
+
// ScreenHand is free software: you can redistribute it and/or modify
|
|
8
|
+
// it under the terms of the GNU Affero General Public License as
|
|
9
|
+
// published by the Free Software Foundation, version 3.
|
|
10
|
+
//
|
|
11
|
+
// ScreenHand is distributed in the hope that it will be useful,
|
|
12
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
// GNU Affero General Public License for more details.
|
|
15
|
+
//
|
|
16
|
+
// You should have received a copy of the GNU Affero General Public License
|
|
17
|
+
// along with ScreenHand. If not, see <https://www.gnu.org/licenses/>.
|
|
18
|
+
import { PlaceholderAppAdapter } from "./runtime/app-adapter.js";
|
|
19
|
+
import { CdpChromeAdapter } from "./runtime/cdp-chrome-adapter.js";
|
|
20
|
+
import { TimelineLogger } from "./logging/timeline-logger.js";
|
|
21
|
+
import { AutomationRuntimeService } from "./runtime/service.js";
|
|
22
|
+
import { startMcpStdioServer } from "./mcp/mcp-stdio-server.js";
|
|
23
|
+
async function createAdapter() {
|
|
24
|
+
const adapterType = process.env.SCREENHAND_ADAPTER ?? process.env.AUTOMATOR_ADAPTER ?? "accessibility";
|
|
25
|
+
switch (adapterType) {
|
|
26
|
+
case "placeholder":
|
|
27
|
+
return new PlaceholderAppAdapter();
|
|
28
|
+
case "cdp":
|
|
29
|
+
return new CdpChromeAdapter({
|
|
30
|
+
headless: process.env.SCREENHAND_HEADLESS === "1" || process.env.AUTOMATOR_HEADLESS === "1",
|
|
31
|
+
});
|
|
32
|
+
case "composite": {
|
|
33
|
+
const { BridgeClient } = await import("./native/bridge-client.js");
|
|
34
|
+
const { CompositeAdapter } = await import("./runtime/composite-adapter.js");
|
|
35
|
+
const bridge = new BridgeClient();
|
|
36
|
+
return new CompositeAdapter(bridge, {
|
|
37
|
+
headless: process.env.SCREENHAND_HEADLESS === "1" || process.env.AUTOMATOR_HEADLESS === "1",
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
case "accessibility":
|
|
41
|
+
default: {
|
|
42
|
+
const { BridgeClient } = await import("./native/bridge-client.js");
|
|
43
|
+
const { AccessibilityAdapter } = await import("./runtime/accessibility-adapter.js");
|
|
44
|
+
const bridge = new BridgeClient();
|
|
45
|
+
return new AccessibilityAdapter(bridge);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const adapter = await createAdapter();
|
|
51
|
+
const logger = new TimelineLogger();
|
|
52
|
+
const runtime = new AutomationRuntimeService(adapter, logger);
|
|
53
|
+
process.stderr.write("ScreenHand MCP server starting...\n");
|
|
54
|
+
await startMcpStdioServer(runtime);
|
|
55
|
+
process.stderr.write("ScreenHand MCP server connected.\n");
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
process.stderr.write(`ScreenHand startup error: ${e instanceof Error ? e.message : String(e)}\n`);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
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
|
+
* Playbook Seeds — converts playbook reference knowledge into memory-compatible formats.
|
|
7
|
+
*
|
|
8
|
+
* Reads all playbooks from disk and extracts:
|
|
9
|
+
* - errors[] → ErrorPattern[] (for quickErrorCheck auto-warnings)
|
|
10
|
+
* - flows{} → Learning[] (for pattern recall)
|
|
11
|
+
* - selectors{} → Learning[] (for verified selector patterns)
|
|
12
|
+
* - policyNotes{} → Learning[] (for rate limits and safety)
|
|
13
|
+
*
|
|
14
|
+
* Called once during MemoryStore.init() to seed the memory system with
|
|
15
|
+
* months of team-curated platform knowledge.
|
|
16
|
+
*/
|
|
17
|
+
import fs from "node:fs";
|
|
18
|
+
import path from "node:path";
|
|
19
|
+
// ── Tool name inference from error/solution text ──
|
|
20
|
+
const TOOL_KEYWORDS = {
|
|
21
|
+
browser_click: ["click", "el.click", ".click()", "button"],
|
|
22
|
+
browser_human_click: ["human_click", "dispatchMouseEvent", "CDP Input"],
|
|
23
|
+
browser_fill_form: ["fill_form", "browser_fill_form", "form"],
|
|
24
|
+
browser_type: ["browser_type", "type into", "typing"],
|
|
25
|
+
browser_js: ["browser_js", "evaluate", "script", "execCommand"],
|
|
26
|
+
browser_navigate: ["navigate", "navigation", "url"],
|
|
27
|
+
browser_dom: ["querySelector", "selector", "DOM"],
|
|
28
|
+
browser_wait: ["wait", "timeout", "load"],
|
|
29
|
+
click: ["native click", "coordinates", "screen click"],
|
|
30
|
+
type_text: ["type_text", "native typing"],
|
|
31
|
+
scroll: ["scroll"],
|
|
32
|
+
};
|
|
33
|
+
function inferTool(text) {
|
|
34
|
+
const lower = text.toLowerCase();
|
|
35
|
+
for (const [tool, keywords] of Object.entries(TOOL_KEYWORDS)) {
|
|
36
|
+
if (keywords.some(kw => lower.includes(kw.toLowerCase())))
|
|
37
|
+
return tool;
|
|
38
|
+
}
|
|
39
|
+
return "browser_click"; // default — most errors are click-related
|
|
40
|
+
}
|
|
41
|
+
// ── Main seed functions ──
|
|
42
|
+
/**
|
|
43
|
+
* Read all playbooks from a directory and extract error patterns.
|
|
44
|
+
* These get loaded into memory's errorsCache so quickErrorCheck() catches them.
|
|
45
|
+
*/
|
|
46
|
+
export function seedErrorsFromPlaybooks(playbooksDir) {
|
|
47
|
+
const playbooks = loadPlaybooks(playbooksDir);
|
|
48
|
+
const errors = [];
|
|
49
|
+
const seen = new Set(); // deduplicate by error text
|
|
50
|
+
for (const pb of playbooks) {
|
|
51
|
+
const platform = pb.platform ?? pb.id ?? "unknown";
|
|
52
|
+
// Extract from errors[]
|
|
53
|
+
if (pb.errors) {
|
|
54
|
+
for (const err of pb.errors) {
|
|
55
|
+
const key = `${platform}::${err.error}`;
|
|
56
|
+
if (seen.has(key))
|
|
57
|
+
continue;
|
|
58
|
+
seen.add(key);
|
|
59
|
+
errors.push({
|
|
60
|
+
id: `pb_err_${platform}_${errors.length}`,
|
|
61
|
+
tool: inferTool(`${err.error} ${err.context} ${err.solution}`),
|
|
62
|
+
params: { _source: "playbook", _platform: platform },
|
|
63
|
+
error: `[${platform}] ${err.error}`,
|
|
64
|
+
resolution: err.solution,
|
|
65
|
+
occurrences: err.severity === "high" ? 10 : err.severity === "medium" ? 5 : 2,
|
|
66
|
+
lastSeen: new Date().toISOString(),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Extract from flows — tips and why fields often contain error knowledge
|
|
71
|
+
if (pb.flows) {
|
|
72
|
+
for (const [flowName, flow] of Object.entries(pb.flows)) {
|
|
73
|
+
if (flow.why && flow.why.includes("doesn't") || flow.why?.includes("don't") || flow.why?.includes("NOT")) {
|
|
74
|
+
const key = `${platform}::${flowName}::why`;
|
|
75
|
+
if (seen.has(key))
|
|
76
|
+
continue;
|
|
77
|
+
seen.add(key);
|
|
78
|
+
errors.push({
|
|
79
|
+
id: `pb_err_${platform}_flow_${errors.length}`,
|
|
80
|
+
tool: inferTool(flow.why ?? ""),
|
|
81
|
+
params: { _source: "playbook", _platform: platform, _flow: flowName },
|
|
82
|
+
error: `[${platform}/${flowName}] ${flow.why.slice(0, 200)}`,
|
|
83
|
+
resolution: flow.steps?.join(" → ") ?? null,
|
|
84
|
+
occurrences: 5,
|
|
85
|
+
lastSeen: new Date().toISOString(),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return errors;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Read all playbooks and extract learnings (selectors, patterns, policy notes).
|
|
95
|
+
* These get loaded into memory's learningsCache so queryPatterns() finds them.
|
|
96
|
+
*/
|
|
97
|
+
export function seedLearningsFromPlaybooks(playbooksDir) {
|
|
98
|
+
const playbooks = loadPlaybooks(playbooksDir);
|
|
99
|
+
const learnings = [];
|
|
100
|
+
for (const pb of playbooks) {
|
|
101
|
+
const platform = pb.platform ?? pb.id ?? "unknown";
|
|
102
|
+
const reliability = (pb.successCount ?? 0) + (pb.failCount ?? 0) > 0
|
|
103
|
+
? (pb.successCount ?? 0) / ((pb.successCount ?? 0) + (pb.failCount ?? 0))
|
|
104
|
+
: 0.7;
|
|
105
|
+
// Selectors → learnings (verified working CSS selectors)
|
|
106
|
+
if (pb.selectors) {
|
|
107
|
+
for (const [group, sels] of Object.entries(pb.selectors)) {
|
|
108
|
+
for (const [name, selector] of Object.entries(sels)) {
|
|
109
|
+
// Skip notes/annotations (keys starting with _)
|
|
110
|
+
if (name.startsWith("_"))
|
|
111
|
+
continue;
|
|
112
|
+
learnings.push({
|
|
113
|
+
scope: `chrome/${platform}`,
|
|
114
|
+
pattern: `${group}.${name}: ${selector}`,
|
|
115
|
+
method: "cdp",
|
|
116
|
+
confidence: reliability,
|
|
117
|
+
successCount: Math.max(1, Math.round(reliability * 10)),
|
|
118
|
+
failCount: Math.round((1 - reliability) * 10),
|
|
119
|
+
lastSeen: new Date().toISOString(),
|
|
120
|
+
fix: null,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// Flow selectors → learnings
|
|
126
|
+
if (pb.flows) {
|
|
127
|
+
for (const [flowName, flow] of Object.entries(pb.flows)) {
|
|
128
|
+
if (flow.selectors) {
|
|
129
|
+
for (const [name, selector] of Object.entries(flow.selectors)) {
|
|
130
|
+
learnings.push({
|
|
131
|
+
scope: `chrome/${platform}/${flowName}`,
|
|
132
|
+
pattern: `${name}: ${selector}`,
|
|
133
|
+
method: "cdp",
|
|
134
|
+
confidence: reliability,
|
|
135
|
+
successCount: Math.max(1, Math.round(reliability * 10)),
|
|
136
|
+
failCount: Math.round((1 - reliability) * 10),
|
|
137
|
+
lastSeen: new Date().toISOString(),
|
|
138
|
+
fix: null,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// Policy notes → learnings (rate limits, safety rules)
|
|
145
|
+
if (pb.policyNotes) {
|
|
146
|
+
for (const [category, notes] of Object.entries(pb.policyNotes)) {
|
|
147
|
+
for (const note of notes) {
|
|
148
|
+
learnings.push({
|
|
149
|
+
scope: `policy/${platform}`,
|
|
150
|
+
pattern: `[${category}] ${note}`,
|
|
151
|
+
method: "cdp",
|
|
152
|
+
confidence: 1.0,
|
|
153
|
+
successCount: 10,
|
|
154
|
+
failCount: 0,
|
|
155
|
+
lastSeen: new Date().toISOString(),
|
|
156
|
+
fix: null,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
// Detection expressions → learnings
|
|
162
|
+
if (pb.detection) {
|
|
163
|
+
for (const [name, expr] of Object.entries(pb.detection)) {
|
|
164
|
+
learnings.push({
|
|
165
|
+
scope: `chrome/${platform}/detection`,
|
|
166
|
+
pattern: `${name}: ${expr}`,
|
|
167
|
+
method: "cdp",
|
|
168
|
+
confidence: reliability,
|
|
169
|
+
successCount: Math.max(1, Math.round(reliability * 10)),
|
|
170
|
+
failCount: 0,
|
|
171
|
+
lastSeen: new Date().toISOString(),
|
|
172
|
+
fix: null,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return learnings;
|
|
178
|
+
}
|
|
179
|
+
// ── Helpers ──
|
|
180
|
+
function loadPlaybooks(dir) {
|
|
181
|
+
if (!fs.existsSync(dir))
|
|
182
|
+
return [];
|
|
183
|
+
const files = fs.readdirSync(dir).filter(f => f.endsWith(".json"));
|
|
184
|
+
const playbooks = [];
|
|
185
|
+
for (const file of files) {
|
|
186
|
+
try {
|
|
187
|
+
const raw = JSON.parse(fs.readFileSync(path.join(dir, file), "utf-8"));
|
|
188
|
+
// Ensure it has an id
|
|
189
|
+
if (!raw.id)
|
|
190
|
+
raw.id = file.replace(".json", "");
|
|
191
|
+
if (!raw.platform)
|
|
192
|
+
raw.platform = raw.id;
|
|
193
|
+
playbooks.push(raw);
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
// Skip unparseable files
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return playbooks;
|
|
200
|
+
}
|