screenhand 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +165 -446
- package/bin/darwin-arm64/macos-bridge +0 -0
- package/dist/mcp-desktop.js +3615 -400
- 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/threads-campaign.js +208 -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/dist/src/context-tracker.js +489 -0
- 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 +82 -14
- package/dist/src/jobs/runner.js +138 -15
- 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 +4 -1
- package/dist/src/memory/playbook-seeds.js +200 -0
- package/dist/src/memory/recall.js +60 -8
- package/dist/src/memory/service.js +30 -5
- package/dist/src/memory/store.js +34 -5
- package/dist/src/native/bridge-client.js +253 -31
- 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 +296 -11
- package/dist/src/playbook/mcp-recorder.js +204 -0
- package/dist/src/playbook/recorder.js +3 -2
- package/dist/src/playbook/runner.js +1 -1
- package/dist/src/playbook/store.js +139 -10
- 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 +55 -18
- package/dist/src/runtime/applescript-adapter.js +8 -2
- package/dist/src/runtime/cdp-chrome-adapter.js +1 -1
- package/dist/src/runtime/executor.js +23 -3
- package/dist/src/runtime/locator-cache.js +24 -2
- package/dist/src/runtime/service.js +59 -15
- package/dist/src/runtime/session-manager.js +4 -1
- package/dist/src/runtime/vision-adapter.js +2 -1
- 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/util/atomic-write.js +19 -4
- 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/devpost.json +186 -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 +22 -0
- package/native/macos-bridge/Sources/AccessibilityBridge.swift +482 -0
- package/native/macos-bridge/Sources/AppManagement.swift +339 -0
- package/native/macos-bridge/Sources/CoreGraphicsBridge.swift +537 -0
- package/native/macos-bridge/Sources/ObserverBridge.swift +120 -0
- package/native/macos-bridge/Sources/StreamCapture.swift +136 -0
- package/native/macos-bridge/Sources/VisionBridge.swift +238 -0
- package/native/macos-bridge/Sources/main.swift +498 -0
- package/native/windows-bridge/AppManagement.cs +234 -0
- package/native/windows-bridge/InputBridge.cs +436 -0
- package/native/windows-bridge/Program.cs +270 -0
- package/native/windows-bridge/ScreenCapture.cs +453 -0
- package/native/windows-bridge/UIAutomationBridge.cs +571 -0
- package/native/windows-bridge/WindowsBridge.csproj +17 -0
- package/package.json +12 -1
- package/scripts/postinstall.cjs +127 -0
- package/dist/.audit-log.jsonl +0 -55
- package/dist/.screenhand/memory/.lock +0 -1
- package/dist/.screenhand/memory/actions.jsonl +0 -85
- package/dist/.screenhand/memory/errors.jsonl +0 -5
- package/dist/.screenhand/memory/errors.jsonl.bak +0 -4
- package/dist/.screenhand/memory/state.json +0 -35
- package/dist/.screenhand/memory/state.json.bak +0 -35
- package/dist/.screenhand/memory/strategies.jsonl +0 -12
- package/dist/agent/cli.js +0 -73
- package/dist/agent/loop.js +0 -258
- package/dist/config.js +0 -9
- package/dist/index.js +0 -56
- package/dist/logging/timeline-logger.js +0 -29
- package/dist/mcp/mcp-stdio-server.js +0 -448
- package/dist/mcp/server.js +0 -347
- package/dist/mcp-entry.js +0 -59
- package/dist/memory/recall.js +0 -160
- package/dist/memory/research.js +0 -98
- package/dist/memory/seeds.js +0 -89
- package/dist/memory/session.js +0 -161
- package/dist/memory/store.js +0 -391
- package/dist/memory/types.js +0 -4
- package/dist/monitor/codex-monitor.js +0 -377
- package/dist/monitor/task-queue.js +0 -84
- package/dist/monitor/types.js +0 -49
- package/dist/native/bridge-client.js +0 -174
- package/dist/native/macos-bridge-client.js +0 -5
- package/dist/npm-publish-helper.js +0 -117
- package/dist/npm-token-cdp.js +0 -113
- package/dist/npm-token-create.js +0 -135
- package/dist/npm-token-finish.js +0 -126
- package/dist/playbook/engine.js +0 -193
- package/dist/playbook/index.js +0 -4
- package/dist/playbook/recorder.js +0 -519
- package/dist/playbook/runner.js +0 -392
- package/dist/playbook/store.js +0 -166
- package/dist/playbook/types.js +0 -4
- package/dist/runtime/accessibility-adapter.js +0 -377
- package/dist/runtime/app-adapter.js +0 -48
- package/dist/runtime/applescript-adapter.js +0 -283
- package/dist/runtime/ax-role-map.js +0 -80
- package/dist/runtime/browser-adapter.js +0 -36
- package/dist/runtime/cdp-chrome-adapter.js +0 -505
- package/dist/runtime/composite-adapter.js +0 -205
- package/dist/runtime/executor.js +0 -250
- package/dist/runtime/locator-cache.js +0 -12
- package/dist/runtime/planning-loop.js +0 -47
- package/dist/runtime/service.js +0 -372
- package/dist/runtime/session-manager.js +0 -28
- package/dist/runtime/state-observer.js +0 -105
- package/dist/runtime/vision-adapter.js +0 -208
- package/dist/test-mcp-protocol.js +0 -138
- package/dist/types.js +0 -1
package/dist/agent/loop.js
DELETED
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ScreenHand Agent Loop
|
|
3
|
-
*
|
|
4
|
-
* Continuous observe → decide → act loop powered by Claude.
|
|
5
|
-
* Uses element_tree (accessibility tree) as the primary observation — not screenshots.
|
|
6
|
-
* ~50ms per observe, ~50ms per action. Only the LLM call adds latency.
|
|
7
|
-
*/
|
|
8
|
-
import Anthropic from "@anthropic-ai/sdk";
|
|
9
|
-
/**
|
|
10
|
-
* Compact AX tree representation for LLM consumption.
|
|
11
|
-
* Converts the full AXNode tree into a concise text format:
|
|
12
|
-
* [button] "Send" (350,200)
|
|
13
|
-
* [textField] "Search" value="hello" (100,50)
|
|
14
|
-
*/
|
|
15
|
-
function compactTree(node, depth = 0, maxDepth = 5) {
|
|
16
|
-
if (depth > maxDepth)
|
|
17
|
-
return "";
|
|
18
|
-
const indent = " ".repeat(depth);
|
|
19
|
-
const parts = [];
|
|
20
|
-
// Role
|
|
21
|
-
const role = node.role.replace("AX", "").toLowerCase();
|
|
22
|
-
// Label — prefer title, then description, then identifier
|
|
23
|
-
const label = node.title || node.description || node.identifier || "";
|
|
24
|
-
// Value
|
|
25
|
-
const val = node.value ? ` value="${node.value.slice(0, 50)}"` : "";
|
|
26
|
-
// Position
|
|
27
|
-
const pos = node.position ? ` (${Math.round(node.position.x)},${Math.round(node.position.y)})` : "";
|
|
28
|
-
// Focused/enabled markers
|
|
29
|
-
const markers = [];
|
|
30
|
-
if (node.focused)
|
|
31
|
-
markers.push("focused");
|
|
32
|
-
if (node.enabled === false)
|
|
33
|
-
markers.push("disabled");
|
|
34
|
-
const markerStr = markers.length ? ` [${markers.join(",")}]` : "";
|
|
35
|
-
// Skip noise nodes with no useful info
|
|
36
|
-
const isNoise = !label && !val && !node.focused && (role === "group" || role === "splitgroup" || role === "scrollarea");
|
|
37
|
-
if (!isNoise) {
|
|
38
|
-
parts.push(`${indent}[${role}] "${label}"${val}${pos}${markerStr}`);
|
|
39
|
-
}
|
|
40
|
-
if (node.children) {
|
|
41
|
-
for (const child of node.children) {
|
|
42
|
-
const childStr = compactTree(child, isNoise ? depth : depth + 1, maxDepth);
|
|
43
|
-
if (childStr)
|
|
44
|
-
parts.push(childStr);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return parts.join("\n");
|
|
48
|
-
}
|
|
49
|
-
const SYSTEM_PROMPT = `You are a desktop automation agent. You control a computer through ScreenHand tools.
|
|
50
|
-
|
|
51
|
-
On each turn you receive the current UI state as an accessibility tree. You must decide the SINGLE next action to take.
|
|
52
|
-
|
|
53
|
-
Respond in this exact JSON format (no markdown, no explanation outside the JSON):
|
|
54
|
-
{
|
|
55
|
-
"reasoning": "Brief explanation of what you see and why you're taking this action",
|
|
56
|
-
"action": { "tool": "...", ... },
|
|
57
|
-
"done": false
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
When the task is fully complete, respond with:
|
|
61
|
-
{
|
|
62
|
-
"reasoning": "Task is complete because ...",
|
|
63
|
-
"action": { "tool": "done", "summary": "What was accomplished" },
|
|
64
|
-
"done": true
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
Available actions:
|
|
68
|
-
- {"tool": "press", "target": "Button text or element name"}
|
|
69
|
-
- {"tool": "type_into", "target": "Field name", "text": "text to type"}
|
|
70
|
-
- {"tool": "navigate", "url": "https://..."}
|
|
71
|
-
- {"tool": "scroll", "direction": "up|down|left|right", "amount": 3}
|
|
72
|
-
- {"tool": "key_combo", "keys": ["cmd", "c"]}
|
|
73
|
-
- {"tool": "menu_click", "menuPath": ["File", "Save"]}
|
|
74
|
-
- {"tool": "app_launch", "bundleId": "com.apple.Safari"}
|
|
75
|
-
- {"tool": "app_focus", "bundleId": "com.apple.Safari"}
|
|
76
|
-
- {"tool": "extract", "target": "element name", "format": "text"}
|
|
77
|
-
- {"tool": "wait", "ms": 1000}
|
|
78
|
-
- {"tool": "done", "summary": "what was accomplished"}
|
|
79
|
-
|
|
80
|
-
Rules:
|
|
81
|
-
- Take ONE action per turn. After each action you'll see the updated UI.
|
|
82
|
-
- Use the accessibility tree to find elements — look for roles and labels.
|
|
83
|
-
- Target elements by their visible text/label, not coordinates (unless no label exists).
|
|
84
|
-
- If an action fails, try an alternative approach — don't repeat the same failed action.
|
|
85
|
-
- If you're stuck after 3 attempts, explain what's blocking you and mark done.
|
|
86
|
-
- Be efficient. Don't take unnecessary actions.`;
|
|
87
|
-
export async function runAgentLoop(runtime, sessionId, task, options = {}) {
|
|
88
|
-
const { maxSteps = 50, model = "claude-sonnet-4-20250514", maxTokens = 1024, onStep, screenshotOnStart = false, } = options;
|
|
89
|
-
const client = new Anthropic();
|
|
90
|
-
const steps = [];
|
|
91
|
-
const messages = [];
|
|
92
|
-
const startTime = Date.now();
|
|
93
|
-
// Optional initial screenshot for context
|
|
94
|
-
if (screenshotOnStart) {
|
|
95
|
-
await runtime.screenshot({ sessionId });
|
|
96
|
-
}
|
|
97
|
-
for (let i = 0; i < maxSteps; i++) {
|
|
98
|
-
const stepStart = Date.now();
|
|
99
|
-
// 1. OBSERVE — get accessibility tree (~50ms)
|
|
100
|
-
const treeResult = await runtime.elementTree({ sessionId, maxDepth: 5 });
|
|
101
|
-
let observation;
|
|
102
|
-
if (treeResult.ok) {
|
|
103
|
-
observation = compactTree(treeResult.data);
|
|
104
|
-
// Truncate if too large to keep tokens manageable
|
|
105
|
-
if (observation.length > 8000) {
|
|
106
|
-
observation = observation.slice(0, 8000) + "\n... (truncated)";
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
observation = `[Error getting UI tree: ${treeResult.error.message}]`;
|
|
111
|
-
}
|
|
112
|
-
// Also get app context
|
|
113
|
-
let contextLine = "";
|
|
114
|
-
try {
|
|
115
|
-
const apps = await runtime.appList(sessionId);
|
|
116
|
-
if (apps.ok) {
|
|
117
|
-
const active = apps.data.find(a => a.isActive);
|
|
118
|
-
if (active)
|
|
119
|
-
contextLine = `Active app: ${active.name} (${active.bundleId})`;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
catch { /* ignore */ }
|
|
123
|
-
// 2. BUILD prompt
|
|
124
|
-
const userMsg = i === 0
|
|
125
|
-
? `Task: ${task}\n\nCurrent UI state:\n${contextLine}\n${observation}`
|
|
126
|
-
: `Action result: ${steps[i - 1].result}\n\nUpdated UI state:\n${contextLine}\n${observation}`;
|
|
127
|
-
messages.push({ role: "user", content: userMsg });
|
|
128
|
-
// 3. DECIDE — ask Claude what to do next
|
|
129
|
-
let reasoning = "";
|
|
130
|
-
let action = null;
|
|
131
|
-
let done = false;
|
|
132
|
-
try {
|
|
133
|
-
const resp = await client.messages.create({
|
|
134
|
-
model,
|
|
135
|
-
max_tokens: maxTokens,
|
|
136
|
-
system: SYSTEM_PROMPT,
|
|
137
|
-
messages,
|
|
138
|
-
});
|
|
139
|
-
const text = resp.content[0]?.type === "text" ? resp.content[0].text : "";
|
|
140
|
-
messages.push({ role: "assistant", content: text });
|
|
141
|
-
// Parse JSON response
|
|
142
|
-
const jsonMatch = text.match(/\{[\s\S]*\}/);
|
|
143
|
-
if (jsonMatch) {
|
|
144
|
-
const parsed = JSON.parse(jsonMatch[0]);
|
|
145
|
-
reasoning = parsed.reasoning ?? "";
|
|
146
|
-
action = parsed.action ?? null;
|
|
147
|
-
done = parsed.done === true;
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
reasoning = text;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
catch (e) {
|
|
154
|
-
reasoning = `LLM error: ${e instanceof Error ? e.message : String(e)}`;
|
|
155
|
-
}
|
|
156
|
-
// 4. ACT — execute the action (~50ms)
|
|
157
|
-
let result = "";
|
|
158
|
-
if (action) {
|
|
159
|
-
try {
|
|
160
|
-
result = await executeAction(runtime, sessionId, action);
|
|
161
|
-
}
|
|
162
|
-
catch (e) {
|
|
163
|
-
result = `Error: ${e instanceof Error ? e.message : String(e)}`;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
result = "No action taken";
|
|
168
|
-
}
|
|
169
|
-
// Record step
|
|
170
|
-
const step = {
|
|
171
|
-
index: i,
|
|
172
|
-
observation: observation.slice(0, 500),
|
|
173
|
-
reasoning,
|
|
174
|
-
action,
|
|
175
|
-
result,
|
|
176
|
-
done,
|
|
177
|
-
durationMs: Date.now() - stepStart,
|
|
178
|
-
};
|
|
179
|
-
steps.push(step);
|
|
180
|
-
if (onStep)
|
|
181
|
-
onStep(step);
|
|
182
|
-
if (done)
|
|
183
|
-
break;
|
|
184
|
-
}
|
|
185
|
-
const lastStep = steps[steps.length - 1];
|
|
186
|
-
const summary = lastStep?.action?.tool === "done"
|
|
187
|
-
? lastStep.action.summary
|
|
188
|
-
: `Stopped after ${steps.length} steps`;
|
|
189
|
-
return {
|
|
190
|
-
success: lastStep?.done ?? false,
|
|
191
|
-
summary,
|
|
192
|
-
steps,
|
|
193
|
-
totalMs: Date.now() - startTime,
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
async function executeAction(runtime, sessionId, action) {
|
|
197
|
-
switch (action.tool) {
|
|
198
|
-
case "press": {
|
|
199
|
-
const r = await runtime.press({
|
|
200
|
-
sessionId,
|
|
201
|
-
target: { type: "text", value: action.target },
|
|
202
|
-
});
|
|
203
|
-
return r.ok ? `Pressed "${action.target}"` : `Failed: ${r.error.message}`;
|
|
204
|
-
}
|
|
205
|
-
case "type_into": {
|
|
206
|
-
const r = await runtime.typeInto({
|
|
207
|
-
sessionId,
|
|
208
|
-
target: { type: "text", value: action.target },
|
|
209
|
-
text: action.text,
|
|
210
|
-
});
|
|
211
|
-
return r.ok ? `Typed "${action.text}" into "${action.target}"` : `Failed: ${r.error.message}`;
|
|
212
|
-
}
|
|
213
|
-
case "navigate": {
|
|
214
|
-
const r = await runtime.navigate({ sessionId, url: action.url });
|
|
215
|
-
return r.ok ? `Navigated to ${action.url}` : `Failed: ${r.error.message}`;
|
|
216
|
-
}
|
|
217
|
-
case "scroll": {
|
|
218
|
-
const input = { sessionId, direction: action.direction };
|
|
219
|
-
if (typeof action.amount === "number")
|
|
220
|
-
input.amount = action.amount;
|
|
221
|
-
const r = await runtime.scroll(input);
|
|
222
|
-
return r.ok ? `Scrolled ${action.direction}` : `Failed: ${r.error.message}`;
|
|
223
|
-
}
|
|
224
|
-
case "key_combo": {
|
|
225
|
-
const r = await runtime.keyCombo({ sessionId, keys: action.keys });
|
|
226
|
-
return r.ok ? `Key combo: ${action.keys.join("+")}` : `Failed: ${r.error.message}`;
|
|
227
|
-
}
|
|
228
|
-
case "menu_click": {
|
|
229
|
-
const r = await runtime.menuClick({ sessionId, menuPath: action.menuPath });
|
|
230
|
-
return r.ok ? `Menu: ${action.menuPath.join(" → ")}` : `Failed: ${r.error.message}`;
|
|
231
|
-
}
|
|
232
|
-
case "app_launch": {
|
|
233
|
-
const r = await runtime.appLaunch({ sessionId, bundleId: action.bundleId });
|
|
234
|
-
return r.ok ? `Launched ${action.bundleId}` : `Failed: ${r.error.message}`;
|
|
235
|
-
}
|
|
236
|
-
case "app_focus": {
|
|
237
|
-
const r = await runtime.appFocus({ sessionId, bundleId: action.bundleId });
|
|
238
|
-
return r.ok ? `Focused ${action.bundleId}` : `Failed: ${r.error.message}`;
|
|
239
|
-
}
|
|
240
|
-
case "extract": {
|
|
241
|
-
const r = await runtime.extract({
|
|
242
|
-
sessionId,
|
|
243
|
-
target: { type: "text", value: action.target },
|
|
244
|
-
format: action.format,
|
|
245
|
-
});
|
|
246
|
-
return r.ok ? `Extracted: ${JSON.stringify(r.data).slice(0, 500)}` : `Failed: ${r.error.message}`;
|
|
247
|
-
}
|
|
248
|
-
case "wait": {
|
|
249
|
-
await new Promise(resolve => setTimeout(resolve, action.ms));
|
|
250
|
-
return `Waited ${action.ms}ms`;
|
|
251
|
-
}
|
|
252
|
-
case "done": {
|
|
253
|
-
return `Task complete: ${action.summary}`;
|
|
254
|
-
}
|
|
255
|
-
default:
|
|
256
|
-
return `Unknown action: ${action.tool}`;
|
|
257
|
-
}
|
|
258
|
-
}
|
package/dist/config.js
DELETED
package/dist/index.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { TimelineLogger } from "./logging/timeline-logger.js";
|
|
2
|
-
import { MvpMcpServer } from "./mcp/server.js";
|
|
3
|
-
import { PlaceholderAppAdapter, } from "./runtime/app-adapter.js";
|
|
4
|
-
import { CdpChromeAdapter } from "./runtime/cdp-chrome-adapter.js";
|
|
5
|
-
import { AutomationRuntimeService } from "./runtime/service.js";
|
|
6
|
-
export { PlaceholderAppAdapter } from "./runtime/app-adapter.js";
|
|
7
|
-
export { CdpChromeAdapter } from "./runtime/cdp-chrome-adapter.js";
|
|
8
|
-
export { AccessibilityAdapter } from "./runtime/accessibility-adapter.js";
|
|
9
|
-
export { AppleScriptAdapter } from "./runtime/applescript-adapter.js";
|
|
10
|
-
export { VisionAdapter } from "./runtime/vision-adapter.js";
|
|
11
|
-
export { CompositeAdapter } from "./runtime/composite-adapter.js";
|
|
12
|
-
export { BridgeClient, BridgeClient as MacOSBridgeClient } from "./native/bridge-client.js";
|
|
13
|
-
export { StateObserver } from "./runtime/state-observer.js";
|
|
14
|
-
export { PlanningLoop } from "./runtime/planning-loop.js";
|
|
15
|
-
export { AutomationRuntimeService } from "./runtime/service.js";
|
|
16
|
-
export { MvpMcpServer } from "./mcp/server.js";
|
|
17
|
-
export { createMcpStdioServer, startMcpStdioServer } from "./mcp/mcp-stdio-server.js";
|
|
18
|
-
export { runAgentLoop } from "./agent/loop.js";
|
|
19
|
-
export function createRuntimeApp(adapter) {
|
|
20
|
-
const logger = new TimelineLogger();
|
|
21
|
-
const runtime = new AutomationRuntimeService(adapter, logger);
|
|
22
|
-
const mcp = new MvpMcpServer(runtime);
|
|
23
|
-
return { runtime, mcp };
|
|
24
|
-
}
|
|
25
|
-
async function createDefaultAdapter() {
|
|
26
|
-
if (process.env.AUTOMATOR_ADAPTER === "placeholder") {
|
|
27
|
-
return new PlaceholderAppAdapter();
|
|
28
|
-
}
|
|
29
|
-
if (process.env.AUTOMATOR_ADAPTER === "composite") {
|
|
30
|
-
// Lazy import to avoid requiring Swift bridge for CDP-only usage
|
|
31
|
-
const { MacOSBridgeClient } = await import("./native/macos-bridge-client.js");
|
|
32
|
-
const { CompositeAdapter } = await import("./runtime/composite-adapter.js");
|
|
33
|
-
const bridge = new MacOSBridgeClient();
|
|
34
|
-
return new CompositeAdapter(bridge, {
|
|
35
|
-
headless: process.env.AUTOMATOR_HEADLESS === "1",
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
if (process.env.AUTOMATOR_ADAPTER === "accessibility") {
|
|
39
|
-
const { MacOSBridgeClient } = await import("./native/macos-bridge-client.js");
|
|
40
|
-
const { AccessibilityAdapter } = await import("./runtime/accessibility-adapter.js");
|
|
41
|
-
const bridge = new MacOSBridgeClient();
|
|
42
|
-
return new AccessibilityAdapter(bridge);
|
|
43
|
-
}
|
|
44
|
-
return new CdpChromeAdapter({
|
|
45
|
-
headless: process.env.AUTOMATOR_HEADLESS === "1",
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
const app = createRuntimeApp(await createDefaultAdapter());
|
|
49
|
-
if (process.argv.includes("--healthcheck")) {
|
|
50
|
-
const session = await app.runtime.sessionStart("automation");
|
|
51
|
-
console.log(JSON.stringify({
|
|
52
|
-
status: "ok",
|
|
53
|
-
session,
|
|
54
|
-
note: "Runtime loaded with universal adapter support.",
|
|
55
|
-
}, null, 2));
|
|
56
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export class TimelineLogger {
|
|
2
|
-
timeline = [];
|
|
3
|
-
start(action, sessionId) {
|
|
4
|
-
return {
|
|
5
|
-
action,
|
|
6
|
-
sessionId,
|
|
7
|
-
startedAt: new Date().toISOString(),
|
|
8
|
-
locateMs: 0,
|
|
9
|
-
actMs: 0,
|
|
10
|
-
verifyMs: 0,
|
|
11
|
-
retries: 0,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
finish(telemetry, status) {
|
|
15
|
-
const finishedAt = new Date().toISOString();
|
|
16
|
-
const totalMs = new Date(finishedAt).getTime() - new Date(telemetry.startedAt).getTime();
|
|
17
|
-
const finalized = {
|
|
18
|
-
...telemetry,
|
|
19
|
-
finishedAt,
|
|
20
|
-
totalMs,
|
|
21
|
-
status,
|
|
22
|
-
};
|
|
23
|
-
this.timeline.push(finalized);
|
|
24
|
-
return finalized;
|
|
25
|
-
}
|
|
26
|
-
getRecent(limit = 50) {
|
|
27
|
-
return this.timeline.slice(-limit);
|
|
28
|
-
}
|
|
29
|
-
}
|