@developerz.ai/ui-debugger-mcp 1.0.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/LICENSE +21 -0
- package/README.md +295 -0
- package/dist/adapters/android/adb.d.ts +38 -0
- package/dist/adapters/android/adb.js +72 -0
- package/dist/adapters/android/adb.js.map +1 -0
- package/dist/adapters/android/android-adapter.d.ts +63 -0
- package/dist/adapters/android/android-adapter.js +306 -0
- package/dist/adapters/android/android-adapter.js.map +1 -0
- package/dist/adapters/android/commands.d.ts +59 -0
- package/dist/adapters/android/commands.js +178 -0
- package/dist/adapters/android/commands.js.map +1 -0
- package/dist/adapters/android/uiautomator.d.ts +81 -0
- package/dist/adapters/android/uiautomator.js +296 -0
- package/dist/adapters/android/uiautomator.js.map +1 -0
- package/dist/adapters/browser/browser-adapter.d.ts +72 -0
- package/dist/adapters/browser/browser-adapter.js +434 -0
- package/dist/adapters/browser/browser-adapter.js.map +1 -0
- package/dist/adapters/browser/cdp.d.ts +83 -0
- package/dist/adapters/browser/cdp.js +308 -0
- package/dist/adapters/browser/cdp.js.map +1 -0
- package/dist/adapters/browser/query.d.ts +25 -0
- package/dist/adapters/browser/query.js +85 -0
- package/dist/adapters/browser/query.js.map +1 -0
- package/dist/adapters/contract.d.ts +159 -0
- package/dist/adapters/contract.js +22 -0
- package/dist/adapters/contract.js.map +1 -0
- package/dist/adapters/desktop/atspi.d.ts +95 -0
- package/dist/adapters/desktop/atspi.js +359 -0
- package/dist/adapters/desktop/atspi.js.map +1 -0
- package/dist/adapters/desktop/capture.d.ts +35 -0
- package/dist/adapters/desktop/capture.js +67 -0
- package/dist/adapters/desktop/capture.js.map +1 -0
- package/dist/adapters/desktop/desktop-adapter.d.ts +60 -0
- package/dist/adapters/desktop/desktop-adapter.js +215 -0
- package/dist/adapters/desktop/desktop-adapter.js.map +1 -0
- package/dist/adapters/desktop/input.d.ts +67 -0
- package/dist/adapters/desktop/input.js +191 -0
- package/dist/adapters/desktop/input.js.map +1 -0
- package/dist/adapters/desktop/proc.d.ts +23 -0
- package/dist/adapters/desktop/proc.js +38 -0
- package/dist/adapters/desktop/proc.js.map +1 -0
- package/dist/adapters/factory.d.ts +23 -0
- package/dist/adapters/factory.js +45 -0
- package/dist/adapters/factory.js.map +1 -0
- package/dist/agent/belt/act.d.ts +100 -0
- package/dist/agent/belt/act.js +166 -0
- package/dist/agent/belt/act.js.map +1 -0
- package/dist/agent/belt/look.d.ts +98 -0
- package/dist/agent/belt/look.js +160 -0
- package/dist/agent/belt/look.js.map +1 -0
- package/dist/agent/belt/observe.d.ts +102 -0
- package/dist/agent/belt/observe.js +185 -0
- package/dist/agent/belt/observe.js.map +1 -0
- package/dist/agent/belt/report.d.ts +133 -0
- package/dist/agent/belt/report.js +112 -0
- package/dist/agent/belt/report.js.map +1 -0
- package/dist/agent/loop.d.ts +136 -0
- package/dist/agent/loop.js +173 -0
- package/dist/agent/loop.js.map +1 -0
- package/dist/agent/models.d.ts +26 -0
- package/dist/agent/models.js +22 -0
- package/dist/agent/models.js.map +1 -0
- package/dist/agent/prompts/android-addendum.d.ts +12 -0
- package/dist/agent/prompts/android-addendum.js +76 -0
- package/dist/agent/prompts/android-addendum.js.map +1 -0
- package/dist/agent/prompts/compose.d.ts +30 -0
- package/dist/agent/prompts/compose.js +52 -0
- package/dist/agent/prompts/compose.js.map +1 -0
- package/dist/agent/prompts/debug-agent.d.ts +9 -0
- package/dist/agent/prompts/debug-agent.js +102 -0
- package/dist/agent/prompts/debug-agent.js.map +1 -0
- package/dist/agent/prompts/desktop-addendum.d.ts +10 -0
- package/dist/agent/prompts/desktop-addendum.js +66 -0
- package/dist/agent/prompts/desktop-addendum.js.map +1 -0
- package/dist/agent/prompts/web-addendum.d.ts +9 -0
- package/dist/agent/prompts/web-addendum.js +70 -0
- package/dist/agent/prompts/web-addendum.js.map +1 -0
- package/dist/agent/provider.d.ts +17 -0
- package/dist/agent/provider.js +29 -0
- package/dist/agent/provider.js.map +1 -0
- package/dist/cli/control.d.ts +19 -0
- package/dist/cli/control.js +152 -0
- package/dist/cli/control.js.map +1 -0
- package/dist/cli/help.d.ts +9 -0
- package/dist/cli/help.js +41 -0
- package/dist/cli/help.js.map +1 -0
- package/dist/cli/init.d.ts +20 -0
- package/dist/cli/init.js +119 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/config/load.d.ts +64 -0
- package/dist/config/load.js +105 -0
- package/dist/config/load.js.map +1 -0
- package/dist/config/schema.d.ts +105 -0
- package/dist/config/schema.js +62 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/errors.d.ts +41 -0
- package/dist/errors.js +90 -0
- package/dist/errors.js.map +1 -0
- package/dist/findings/schema.d.ts +64 -0
- package/dist/findings/schema.js +27 -0
- package/dist/findings/schema.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +95 -0
- package/dist/main.js.map +1 -0
- package/dist/mcp/server.d.ts +25 -0
- package/dist/mcp/server.js +31 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools/describe.d.ts +12 -0
- package/dist/mcp/tools/describe.js +32 -0
- package/dist/mcp/tools/describe.js.map +1 -0
- package/dist/mcp/tools/end-session.d.ts +11 -0
- package/dist/mcp/tools/end-session.js +27 -0
- package/dist/mcp/tools/end-session.js.map +1 -0
- package/dist/mcp/tools/get-findings.d.ts +12 -0
- package/dist/mcp/tools/get-findings.js +42 -0
- package/dist/mcp/tools/get-findings.js.map +1 -0
- package/dist/mcp/tools/index.d.ts +17 -0
- package/dist/mcp/tools/index.js +24 -0
- package/dist/mcp/tools/index.js.map +1 -0
- package/dist/mcp/tools/result.d.ts +10 -0
- package/dist/mcp/tools/result.js +20 -0
- package/dist/mcp/tools/result.js.map +1 -0
- package/dist/mcp/tools/send-message.d.ts +11 -0
- package/dist/mcp/tools/send-message.js +31 -0
- package/dist/mcp/tools/send-message.js.map +1 -0
- package/dist/mcp/tools/start-debug.d.ts +12 -0
- package/dist/mcp/tools/start-debug.js +50 -0
- package/dist/mcp/tools/start-debug.js.map +1 -0
- package/dist/services/debug-service.d.ts +133 -0
- package/dist/services/debug-service.js +163 -0
- package/dist/services/debug-service.js.map +1 -0
- package/dist/services/replay.d.ts +102 -0
- package/dist/services/replay.js +184 -0
- package/dist/services/replay.js.map +1 -0
- package/dist/services/session-builder.d.ts +65 -0
- package/dist/services/session-builder.js +198 -0
- package/dist/services/session-builder.js.map +1 -0
- package/dist/services/summarize.d.ts +59 -0
- package/dist/services/summarize.js +93 -0
- package/dist/services/summarize.js.map +1 -0
- package/dist/session/findings-store.d.ts +52 -0
- package/dist/session/findings-store.js +176 -0
- package/dist/session/findings-store.js.map +1 -0
- package/dist/session/manager.d.ts +47 -0
- package/dist/session/manager.js +66 -0
- package/dist/session/manager.js.map +1 -0
- package/dist/session/process-identity.d.ts +45 -0
- package/dist/session/process-identity.js +81 -0
- package/dist/session/process-identity.js.map +1 -0
- package/dist/session/session.d.ts +156 -0
- package/dist/session/session.js +309 -0
- package/dist/session/session.js.map +1 -0
- package/dist/session/state-file.d.ts +72 -0
- package/dist/session/state-file.js +104 -0
- package/dist/session/state-file.js.map +1 -0
- package/dist/session/workspace.d.ts +60 -0
- package/dist/session/workspace.js +75 -0
- package/dist/session/workspace.js.map +1 -0
- package/package.json +53 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Desktop adapter — drives a native Linux app behind the shared {@link Adapter}
|
|
3
|
+
* contract, so the agent loop stays adapter-blind.
|
|
4
|
+
*
|
|
5
|
+
* Composition (split per SRP — see siblings):
|
|
6
|
+
* - read → {@link AtspiSource} (AT-SPI2 a11y tree over D-Bus, `atspi.ts`)
|
|
7
|
+
* - input → {@link PointerInput} (xdotool, X11/XWayland, `input.ts`)
|
|
8
|
+
* - capture→ {@link ScreenCapture} (scrot/grim per compositor, `capture.ts`)
|
|
9
|
+
*
|
|
10
|
+
* **Managed only**: the desktop target has no attach handle (unlike web `cdpUrl` /
|
|
11
|
+
* android `adbSerial`), so `open` launches the configured command and `close` stops
|
|
12
|
+
* it. Reads/clicks key off AT-SPI screen extents; vision fallback is future work.
|
|
13
|
+
*
|
|
14
|
+
* Desktop apps expose no console/network channels — those methods throw loud
|
|
15
|
+
* ({@link AdapterError}), never a silent empty list. Every backend failure surfaces
|
|
16
|
+
* as an {@link AdapterError}; our own loud errors pass through un-rewrapped.
|
|
17
|
+
*/
|
|
18
|
+
import { spawn } from 'node:child_process';
|
|
19
|
+
import { AdapterError, UiDebuggerError } from '../../errors.js';
|
|
20
|
+
import { BusctlAtspi, shapeNodes } from './atspi.js';
|
|
21
|
+
import { Screenshot } from './capture.js';
|
|
22
|
+
import { centerOf, Xdotool } from './input.js';
|
|
23
|
+
import { desktopEnv } from './proc.js';
|
|
24
|
+
/** Default cap on `readState` so the tree stays small (overridable via `limit`). */
|
|
25
|
+
const DEFAULT_LIMIT = 200;
|
|
26
|
+
/** `waitFor` defaults — poll the a11y tree for a query until it appears or times out. */
|
|
27
|
+
const DEFAULT_WAIT_MS = 5000;
|
|
28
|
+
const POLL_MS = 200;
|
|
29
|
+
/** How long `open` waits for the launched window to appear before failing loud. */
|
|
30
|
+
const WINDOW_WAIT_MS = 10_000;
|
|
31
|
+
/** Wheel-step calibration: pixels-per-click, and the default page-ish distance. */
|
|
32
|
+
const SCROLL_STEP_PX = 120;
|
|
33
|
+
const DEFAULT_SCROLL_AMOUNT = 360;
|
|
34
|
+
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
35
|
+
/** Map a pixel scroll `amount` onto a positive integer count of wheel clicks. */
|
|
36
|
+
export function scrollRepeat(amount) {
|
|
37
|
+
return Math.max(1, Math.round((amount ?? DEFAULT_SCROLL_AMOUNT) / SCROLL_STEP_PX));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The desktop {@link Adapter}: an xdotool + AT-SPI2 + scrot/grim trio behind one
|
|
41
|
+
* contract. Construct via {@link DesktopAdapter.create}.
|
|
42
|
+
*/
|
|
43
|
+
export class DesktopAdapter {
|
|
44
|
+
#config;
|
|
45
|
+
#env;
|
|
46
|
+
#atspi;
|
|
47
|
+
#input;
|
|
48
|
+
#capture;
|
|
49
|
+
#process = null;
|
|
50
|
+
constructor(handles) {
|
|
51
|
+
this.#config = handles.config;
|
|
52
|
+
this.#env = handles.env;
|
|
53
|
+
this.#atspi = handles.atspi;
|
|
54
|
+
this.#input = handles.input;
|
|
55
|
+
this.#capture = handles.capture;
|
|
56
|
+
}
|
|
57
|
+
/** Wire the adapter from config, binding each backend to the chosen X11 display. */
|
|
58
|
+
static create(init) {
|
|
59
|
+
const display = init.config.display ?? undefined;
|
|
60
|
+
return new DesktopAdapter({
|
|
61
|
+
config: init.config,
|
|
62
|
+
env: desktopEnv(display),
|
|
63
|
+
atspi: init.atspi ?? new BusctlAtspi({ display }),
|
|
64
|
+
input: init.input ?? new Xdotool({ display }),
|
|
65
|
+
capture: init.capture ?? new Screenshot({ display }),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/** Launch the managed app (once) and activate the target window. `target` is a title fallback. */
|
|
69
|
+
async open(target) {
|
|
70
|
+
await this.#run('open', async () => {
|
|
71
|
+
if (!this.#process) {
|
|
72
|
+
this.#process = spawn('/bin/sh', ['-c', this.#config.launch], {
|
|
73
|
+
env: this.#env,
|
|
74
|
+
detached: true,
|
|
75
|
+
stdio: 'ignore',
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
const match = this.#windowMatch(target);
|
|
79
|
+
if (match)
|
|
80
|
+
await this.#input.activateWindow(match, WINDOW_WAIT_MS);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
async find(opts) {
|
|
84
|
+
return this.#run('find', async () => {
|
|
85
|
+
const nodes = await this.readState({ ...opts, limit: 1 });
|
|
86
|
+
return nodes[0] ?? null;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
async readState(opts = {}) {
|
|
90
|
+
return this.#run('readState', async () => {
|
|
91
|
+
const region = opts.within !== undefined ? await this.#regionBounds(opts.within) : undefined;
|
|
92
|
+
const nodes = await this.#atspi.readTree();
|
|
93
|
+
return shapeNodes(nodes, opts, DEFAULT_LIMIT, region);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
async click(target) {
|
|
97
|
+
await this.#run('click', async () => {
|
|
98
|
+
const { x, y } = centerOf((await this.#resolve(target)).bounds);
|
|
99
|
+
await this.#input.clickPoint(x, y);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
async type(target, text) {
|
|
103
|
+
// Contract: focus the target first, then type. Click its center to focus.
|
|
104
|
+
await this.#run('type', async () => {
|
|
105
|
+
const { x, y } = centerOf((await this.#resolve(target)).bounds);
|
|
106
|
+
await this.#input.clickPoint(x, y);
|
|
107
|
+
await this.#input.typeText(text);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
async pressKey(key) {
|
|
111
|
+
if (key.trim() === '') {
|
|
112
|
+
throw new AdapterError('pressKey requires a non-empty key');
|
|
113
|
+
}
|
|
114
|
+
await this.#run('pressKey', () => this.#input.key(key));
|
|
115
|
+
}
|
|
116
|
+
async scroll(opts) {
|
|
117
|
+
await this.#run('scroll', async () => {
|
|
118
|
+
// Scope: park the cursor over the region first so the wheel targets it.
|
|
119
|
+
if (opts.within !== undefined) {
|
|
120
|
+
const { x, y } = centerOf(await this.#regionBounds(opts.within));
|
|
121
|
+
await this.#input.move(x, y);
|
|
122
|
+
}
|
|
123
|
+
await this.#input.scroll(opts.direction, scrollRepeat(opts.amount));
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
async screenshot() {
|
|
127
|
+
return this.#run('screenshot', () => this.#capture.capture());
|
|
128
|
+
}
|
|
129
|
+
async waitFor(opts) {
|
|
130
|
+
if (opts.networkIdle) {
|
|
131
|
+
throw new AdapterError('desktop: `networkIdle` wait is unsupported (no network channel)');
|
|
132
|
+
}
|
|
133
|
+
const query = opts.query;
|
|
134
|
+
if (!query) {
|
|
135
|
+
throw new AdapterError('waitFor requires `query` (desktop has no networkIdle)');
|
|
136
|
+
}
|
|
137
|
+
const timeout = opts.timeout ?? DEFAULT_WAIT_MS;
|
|
138
|
+
await this.#run('waitFor', async () => {
|
|
139
|
+
const start = Date.now();
|
|
140
|
+
for (;;) {
|
|
141
|
+
if (await this.find({ query }))
|
|
142
|
+
return;
|
|
143
|
+
if (Date.now() - start >= timeout) {
|
|
144
|
+
throw new AdapterError(`desktop: waitFor timed out after ${timeout}ms (${query})`);
|
|
145
|
+
}
|
|
146
|
+
await delay(POLL_MS);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
/** Desktop apps expose no console channel — unsupported, surfaced loud. */
|
|
151
|
+
async console() {
|
|
152
|
+
throw new AdapterError('desktop target has no console channel (unsupported)');
|
|
153
|
+
}
|
|
154
|
+
/** Desktop apps expose no network channel — unsupported, surfaced loud. */
|
|
155
|
+
async network() {
|
|
156
|
+
throw new AdapterError('desktop target has no network channel (unsupported)');
|
|
157
|
+
}
|
|
158
|
+
/** Managed teardown: SIGTERM the launched process group; an already-dead process is a no-op. */
|
|
159
|
+
async close() {
|
|
160
|
+
const pid = this.#process?.pid;
|
|
161
|
+
this.#process = null;
|
|
162
|
+
if (pid === undefined)
|
|
163
|
+
return;
|
|
164
|
+
await this.#run('close', async () => {
|
|
165
|
+
try {
|
|
166
|
+
// Negative pid → the whole detached group (the shell + the app it spawned).
|
|
167
|
+
process.kill(-pid, 'SIGTERM');
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
if (error.code !== 'ESRCH')
|
|
171
|
+
throw error;
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
/** Resolve a {@link NodeRef} to a concrete {@link Node}, re-querying a selector. */
|
|
176
|
+
async #resolve(target) {
|
|
177
|
+
if (typeof target !== 'string')
|
|
178
|
+
return target;
|
|
179
|
+
const node = await this.find({ query: target });
|
|
180
|
+
if (!node) {
|
|
181
|
+
throw new AdapterError(`desktop: no element matched query ${JSON.stringify(target)}`);
|
|
182
|
+
}
|
|
183
|
+
return node;
|
|
184
|
+
}
|
|
185
|
+
/** Resolve a scope `within` (a {@link Node} or a selector) to an on-screen rectangle. */
|
|
186
|
+
async #regionBounds(within) {
|
|
187
|
+
if (typeof within !== 'string')
|
|
188
|
+
return within.bounds;
|
|
189
|
+
const node = await this.find({ query: within });
|
|
190
|
+
if (!node)
|
|
191
|
+
throw new AdapterError(`desktop: \`within\` target not found: ${within}`);
|
|
192
|
+
return node.bounds;
|
|
193
|
+
}
|
|
194
|
+
/** Pick the window to drive: configured match wins, else a non-empty `open` title fallback. */
|
|
195
|
+
#windowMatch(target) {
|
|
196
|
+
const configured = this.#config.window;
|
|
197
|
+
if (configured && (configured.title || configured.class))
|
|
198
|
+
return configured;
|
|
199
|
+
if (target.trim() !== '')
|
|
200
|
+
return { title: target };
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
/** Run a backend call, re-throwing as a loud {@link AdapterError} (our own errors pass through). */
|
|
204
|
+
async #run(op, fn) {
|
|
205
|
+
try {
|
|
206
|
+
return await fn();
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
if (error instanceof UiDebuggerError)
|
|
210
|
+
throw error;
|
|
211
|
+
throw new AdapterError(`desktop.${op} failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=desktop-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"desktop-adapter.js","sourceRoot":"","sources":["../../../src/adapters/desktop/desktop-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAqB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,EAAE,YAAY,EAA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AM,CAAC;QACvC,IAAI,UAAU,IAAI,CAAC,UAAU,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK,CAAC;YAAE,OAAO,UAAU,CAAC;QAC5E,IAAI,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE;YAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QACnD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,oGAAoG;IACpG,KAAK,CAAC,IAAI,CAAI,EAAU,EAAE,EAAoB;QAC5C,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,EAAE,CAAC;QACpB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,eAAe;gBAAE,MAAM,KAAK,CAAC;YAClD,MAAM,IAAI,YAAY,CACpB,WAAW,EAAE,YAAY,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAClF,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Desktop input — synthesize pointer/keyboard/scroll via **xdotool** (X11/XWayland).
|
|
3
|
+
*
|
|
4
|
+
* The chosen, proven path for a container/Xvfb default (what Anthropic Computer
|
|
5
|
+
* Use, OSWorld, et al. use — see `idea/desktop-control.md`). xdotool needs screen
|
|
6
|
+
* coordinates, which the adapter feeds from AT-SPI `Component.GetExtents(SCREEN)`
|
|
7
|
+
* (or a Node's `bounds`). Native-Wayland injection (libei/ydotool) is future work.
|
|
8
|
+
*
|
|
9
|
+
* The pure builders here (key-chord mapping, scroll-button mapping, arg arrays)
|
|
10
|
+
* carry the real logic and are unit-tested without spawning; {@link Xdotool} is
|
|
11
|
+
* the thin runner that shells out and fails loud as an {@link AdapterError}.
|
|
12
|
+
*/
|
|
13
|
+
import type { Bounds, ScrollDirection } from '../contract.js';
|
|
14
|
+
import { type Exec } from './proc.js';
|
|
15
|
+
/**
|
|
16
|
+
* Map a contract key/chord (`'Enter'`, `'Control+a'`, `'Escape'`) onto an
|
|
17
|
+
* xdotool keysym chord (`'Return'`, `'ctrl+a'`, `'Escape'`). Throws on an empty key.
|
|
18
|
+
*/
|
|
19
|
+
export declare function mapKeyChord(key: string): string;
|
|
20
|
+
/** Map a {@link ScrollDirection} onto its X11 wheel button (4 up · 5 down · 6 left · 7 right). */
|
|
21
|
+
export declare function scrollButton(direction: ScrollDirection): number;
|
|
22
|
+
/** The integer screen-pixel center of a {@link Bounds} — where a click/scroll lands. */
|
|
23
|
+
export declare function centerOf(bounds: Bounds): {
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
};
|
|
27
|
+
/** `mousemove --sync x y click <button>` — move then click in one synced invocation. */
|
|
28
|
+
export declare function clickArgs(x: number, y: number, button?: number): string[];
|
|
29
|
+
/** `mousemove --sync x y` — park the cursor (used to scope a scroll to a region). */
|
|
30
|
+
export declare function moveArgs(x: number, y: number): string[];
|
|
31
|
+
/** `type --clearmodifiers -- <text>` — `--` guards text that starts with a dash. */
|
|
32
|
+
export declare function typeArgs(text: string): string[];
|
|
33
|
+
/** `key --clearmodifiers <chord>` — press a mapped key/chord on the focused element. */
|
|
34
|
+
export declare function keyArgs(chord: string): string[];
|
|
35
|
+
/** `click --repeat <n> <wheel-button>` — N wheel steps in one direction. */
|
|
36
|
+
export declare function scrollArgs(direction: ScrollDirection, repeat: number): string[];
|
|
37
|
+
/** WM properties used to find the window to drive (X11: WM_NAME / WM_CLASS). */
|
|
38
|
+
export interface WindowMatch {
|
|
39
|
+
title?: string;
|
|
40
|
+
class?: string;
|
|
41
|
+
}
|
|
42
|
+
/** `search --onlyvisible (--name|--class) <value>` — locate the window to activate. */
|
|
43
|
+
export declare function searchArgs(match: WindowMatch): string[];
|
|
44
|
+
/** Pointer/keyboard surface the adapter drives — implemented by {@link Xdotool}, faked in tests. */
|
|
45
|
+
export interface PointerInput {
|
|
46
|
+
clickPoint(x: number, y: number): Promise<void>;
|
|
47
|
+
move(x: number, y: number): Promise<void>;
|
|
48
|
+
typeText(text: string): Promise<void>;
|
|
49
|
+
key(chord: string): Promise<void>;
|
|
50
|
+
scroll(direction: ScrollDirection, repeat: number): Promise<void>;
|
|
51
|
+
activateWindow(match: WindowMatch, timeoutMs: number): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
/** xdotool-backed {@link PointerInput}. Construct with a target `display` (or inject `exec` for tests). */
|
|
54
|
+
export declare class Xdotool implements PointerInput {
|
|
55
|
+
#private;
|
|
56
|
+
constructor(init?: {
|
|
57
|
+
display?: string;
|
|
58
|
+
exec?: Exec;
|
|
59
|
+
});
|
|
60
|
+
clickPoint(x: number, y: number): Promise<void>;
|
|
61
|
+
move(x: number, y: number): Promise<void>;
|
|
62
|
+
typeText(text: string): Promise<void>;
|
|
63
|
+
key(chord: string): Promise<void>;
|
|
64
|
+
scroll(direction: ScrollDirection, repeat: number): Promise<void>;
|
|
65
|
+
/** Poll `search` until the window exists, then `windowactivate --sync`; throw loud on timeout. */
|
|
66
|
+
activateWindow(match: WindowMatch, timeoutMs: number): Promise<void>;
|
|
67
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Desktop input — synthesize pointer/keyboard/scroll via **xdotool** (X11/XWayland).
|
|
3
|
+
*
|
|
4
|
+
* The chosen, proven path for a container/Xvfb default (what Anthropic Computer
|
|
5
|
+
* Use, OSWorld, et al. use — see `idea/desktop-control.md`). xdotool needs screen
|
|
6
|
+
* coordinates, which the adapter feeds from AT-SPI `Component.GetExtents(SCREEN)`
|
|
7
|
+
* (or a Node's `bounds`). Native-Wayland injection (libei/ydotool) is future work.
|
|
8
|
+
*
|
|
9
|
+
* The pure builders here (key-chord mapping, scroll-button mapping, arg arrays)
|
|
10
|
+
* carry the real logic and are unit-tested without spawning; {@link Xdotool} is
|
|
11
|
+
* the thin runner that shells out and fails loud as an {@link AdapterError}.
|
|
12
|
+
*/
|
|
13
|
+
import { AdapterError } from '../../errors.js';
|
|
14
|
+
import { desktopEnv, errMessage, isEnoent, makeExec } from './proc.js';
|
|
15
|
+
const XDOTOOL = 'xdotool';
|
|
16
|
+
/** Poll interval (ms) while waiting for a target window to appear. */
|
|
17
|
+
const POLL_MS = 150;
|
|
18
|
+
/** Contract modifier tokens → xdotool keysym modifiers (chords split on `+`). */
|
|
19
|
+
const MOD_ALIASES = {
|
|
20
|
+
control: 'ctrl',
|
|
21
|
+
ctrl: 'ctrl',
|
|
22
|
+
cmd: 'super',
|
|
23
|
+
command: 'super',
|
|
24
|
+
meta: 'super',
|
|
25
|
+
super: 'super',
|
|
26
|
+
win: 'super',
|
|
27
|
+
alt: 'alt',
|
|
28
|
+
option: 'alt',
|
|
29
|
+
shift: 'shift',
|
|
30
|
+
};
|
|
31
|
+
/** Contract named keys → xdotool keysyms (everything else passes through verbatim). */
|
|
32
|
+
const KEY_ALIASES = {
|
|
33
|
+
enter: 'Return',
|
|
34
|
+
return: 'Return',
|
|
35
|
+
esc: 'Escape',
|
|
36
|
+
escape: 'Escape',
|
|
37
|
+
tab: 'Tab',
|
|
38
|
+
backspace: 'BackSpace',
|
|
39
|
+
delete: 'Delete',
|
|
40
|
+
del: 'Delete',
|
|
41
|
+
space: 'space',
|
|
42
|
+
up: 'Up',
|
|
43
|
+
down: 'Down',
|
|
44
|
+
left: 'Left',
|
|
45
|
+
right: 'Right',
|
|
46
|
+
arrowup: 'Up',
|
|
47
|
+
arrowdown: 'Down',
|
|
48
|
+
arrowleft: 'Left',
|
|
49
|
+
arrowright: 'Right',
|
|
50
|
+
home: 'Home',
|
|
51
|
+
end: 'End',
|
|
52
|
+
pageup: 'Prior',
|
|
53
|
+
pagedown: 'Next',
|
|
54
|
+
};
|
|
55
|
+
/** Map one chord token onto an xdotool keysym (modifier, named key, or verbatim keysym). */
|
|
56
|
+
function mapKeyToken(token) {
|
|
57
|
+
const lower = token.toLowerCase();
|
|
58
|
+
return MOD_ALIASES[lower] ?? KEY_ALIASES[lower] ?? token;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Map a contract key/chord (`'Enter'`, `'Control+a'`, `'Escape'`) onto an
|
|
62
|
+
* xdotool keysym chord (`'Return'`, `'ctrl+a'`, `'Escape'`). Throws on an empty key.
|
|
63
|
+
*/
|
|
64
|
+
export function mapKeyChord(key) {
|
|
65
|
+
const parts = key
|
|
66
|
+
.split('+')
|
|
67
|
+
.map((part) => part.trim())
|
|
68
|
+
.filter((part) => part.length > 0);
|
|
69
|
+
if (parts.length === 0) {
|
|
70
|
+
throw new AdapterError('pressKey requires a non-empty key');
|
|
71
|
+
}
|
|
72
|
+
return parts.map(mapKeyToken).join('+');
|
|
73
|
+
}
|
|
74
|
+
/** Map a {@link ScrollDirection} onto its X11 wheel button (4 up · 5 down · 6 left · 7 right). */
|
|
75
|
+
export function scrollButton(direction) {
|
|
76
|
+
switch (direction) {
|
|
77
|
+
case 'up':
|
|
78
|
+
return 4;
|
|
79
|
+
case 'down':
|
|
80
|
+
return 5;
|
|
81
|
+
case 'left':
|
|
82
|
+
return 6;
|
|
83
|
+
case 'right':
|
|
84
|
+
return 7;
|
|
85
|
+
default: {
|
|
86
|
+
const unreachable = direction;
|
|
87
|
+
throw new AdapterError(`unknown scroll direction: ${JSON.stringify(unreachable)}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** The integer screen-pixel center of a {@link Bounds} — where a click/scroll lands. */
|
|
92
|
+
export function centerOf(bounds) {
|
|
93
|
+
return {
|
|
94
|
+
x: Math.round(bounds.x + bounds.width / 2),
|
|
95
|
+
y: Math.round(bounds.y + bounds.height / 2),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/** `mousemove --sync x y click <button>` — move then click in one synced invocation. */
|
|
99
|
+
export function clickArgs(x, y, button = 1) {
|
|
100
|
+
return ['mousemove', '--sync', String(x), String(y), 'click', String(button)];
|
|
101
|
+
}
|
|
102
|
+
/** `mousemove --sync x y` — park the cursor (used to scope a scroll to a region). */
|
|
103
|
+
export function moveArgs(x, y) {
|
|
104
|
+
return ['mousemove', '--sync', String(x), String(y)];
|
|
105
|
+
}
|
|
106
|
+
/** `type --clearmodifiers -- <text>` — `--` guards text that starts with a dash. */
|
|
107
|
+
export function typeArgs(text) {
|
|
108
|
+
return ['type', '--clearmodifiers', '--', text];
|
|
109
|
+
}
|
|
110
|
+
/** `key --clearmodifiers <chord>` — press a mapped key/chord on the focused element. */
|
|
111
|
+
export function keyArgs(chord) {
|
|
112
|
+
return ['key', '--clearmodifiers', mapKeyChord(chord)];
|
|
113
|
+
}
|
|
114
|
+
/** `click --repeat <n> <wheel-button>` — N wheel steps in one direction. */
|
|
115
|
+
export function scrollArgs(direction, repeat) {
|
|
116
|
+
if (!Number.isInteger(repeat) || repeat < 1) {
|
|
117
|
+
throw new AdapterError('scroll `repeat` must be a positive integer');
|
|
118
|
+
}
|
|
119
|
+
return ['click', '--repeat', String(repeat), String(scrollButton(direction))];
|
|
120
|
+
}
|
|
121
|
+
/** `search --onlyvisible (--name|--class) <value>` — locate the window to activate. */
|
|
122
|
+
export function searchArgs(match) {
|
|
123
|
+
if (match.title)
|
|
124
|
+
return ['search', '--onlyvisible', '--name', match.title];
|
|
125
|
+
if (match.class)
|
|
126
|
+
return ['search', '--onlyvisible', '--class', match.class];
|
|
127
|
+
throw new AdapterError('window match requires `title` or `class`');
|
|
128
|
+
}
|
|
129
|
+
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
130
|
+
/** xdotool-backed {@link PointerInput}. Construct with a target `display` (or inject `exec` for tests). */
|
|
131
|
+
export class Xdotool {
|
|
132
|
+
#exec;
|
|
133
|
+
constructor(init = {}) {
|
|
134
|
+
this.#exec = init.exec ?? makeExec(desktopEnv(init.display));
|
|
135
|
+
}
|
|
136
|
+
clickPoint(x, y) {
|
|
137
|
+
return this.#do(clickArgs(x, y));
|
|
138
|
+
}
|
|
139
|
+
move(x, y) {
|
|
140
|
+
return this.#do(moveArgs(x, y));
|
|
141
|
+
}
|
|
142
|
+
typeText(text) {
|
|
143
|
+
return this.#do(typeArgs(text));
|
|
144
|
+
}
|
|
145
|
+
key(chord) {
|
|
146
|
+
return this.#do(keyArgs(chord));
|
|
147
|
+
}
|
|
148
|
+
scroll(direction, repeat) {
|
|
149
|
+
return this.#do(scrollArgs(direction, repeat));
|
|
150
|
+
}
|
|
151
|
+
/** Poll `search` until the window exists, then `windowactivate --sync`; throw loud on timeout. */
|
|
152
|
+
async activateWindow(match, timeoutMs) {
|
|
153
|
+
const args = searchArgs(match);
|
|
154
|
+
const start = Date.now();
|
|
155
|
+
for (;;) {
|
|
156
|
+
// `search` exits non-zero when nothing matches (→ rejects); that means
|
|
157
|
+
// "not up yet", so keep polling. A MISSING xdotool (ENOENT) is fatal — loud.
|
|
158
|
+
const out = await this.#exec(XDOTOOL, args).catch((error) => {
|
|
159
|
+
if (isEnoent(error)) {
|
|
160
|
+
throw new AdapterError('desktop: `xdotool` not found on PATH (install xdotool)');
|
|
161
|
+
}
|
|
162
|
+
return '';
|
|
163
|
+
});
|
|
164
|
+
const id = out
|
|
165
|
+
.split('\n')
|
|
166
|
+
.map((line) => line.trim())
|
|
167
|
+
.find((line) => line.length > 0);
|
|
168
|
+
if (id) {
|
|
169
|
+
await this.#do(['windowactivate', '--sync', id]);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (Date.now() - start >= timeoutMs) {
|
|
173
|
+
throw new AdapterError(`desktop: window not found within ${timeoutMs}ms (${JSON.stringify(match)})`);
|
|
174
|
+
}
|
|
175
|
+
await delay(POLL_MS);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/** Run one xdotool invocation, re-throwing any failure as a loud {@link AdapterError}. */
|
|
179
|
+
async #do(args) {
|
|
180
|
+
try {
|
|
181
|
+
await this.#exec(XDOTOOL, args);
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
if (isEnoent(error)) {
|
|
185
|
+
throw new AdapterError('desktop: `xdotool` not found on PATH (install xdotool)');
|
|
186
|
+
}
|
|
187
|
+
throw new AdapterError(`xdotool ${args[0] ?? ''} failed: ${errMessage(error)}`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../../src/adapters/desktop/input.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,UAAU,EAAa,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAElF,MAAM,OAAO,GAAG,SAAS,CAAC;AAE1B,sEAAsE;AACtE,MAAM,OAAO,GAAG,GAAG,CAAC;AAEpB,iFAAiF;AACjF,MAAM,WAAW,GAA2B;IAC1C,OAAO,EAAE,MAAM;IACf,IAAI,EAAE,MAAM;IACZ,GAAG,EAAE,OAAO;IACZ,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,OAAO;IACb,KAAK,EAAE,OAAO;IACd,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,KAAK;IACV,MAAM,EAAE,KAAK;IACb,KAAK,EAAE,OAAO;CACf,CAAC;AAEF,uFAAuF;AACvF,MAAM,WAAW,GAA2B;IAC1C,KAAK,EAAE,QAAQ;IACf,MAAM,EAAE,QAAQ;IAChB,GAAG,EAAE,QAAQ;IACb,MAAM,EAAE,QAAQ;IAChB,GAAG,EAAE,KAAK;IACV,SAAS,EAAE,WAAW;IACtB,MAAM,EAAE,QAAQ;IAChB,GAAG,EAAE,QAAQ;IACb,KAAK,EAAE,OAAO;IACd,EAAE,EAAE,IAAI;IACR,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;IACd,OAAO,E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I,SAAS,EAAE,CAAC;gBACpC,MAAM,IAAI,YAAY,CACpB,oCAAoC,SAAS,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAC7E,CAAC;YACJ,CAAC;YACD,MAAM,KAAK,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IAED,0FAA0F;IAC1F,KAAK,CAAC,GAAG,CAAC,IAAc;QACtB,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAClC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;gBACpB,MAAM,IAAI,YAAY,CAAC,wDAAwD,CAAC,CAAC;YACnF,CAAC;YACD,MAAM,IAAI,YAAY,CAAC,WAAW,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,YAAY,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAClF,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subprocess + environment plumbing shared by the desktop adapter's CLI tools
|
|
3
|
+
* (`xdotool`, `scrot`/`grim`, `busctl`).
|
|
4
|
+
*
|
|
5
|
+
* The desktop adapter drives the target by shelling out — there is no in-process
|
|
6
|
+
* SDK like CDP. Every tool runs on a chosen X11 `DISPLAY` (e.g. `:99` for an Xvfb
|
|
7
|
+
* container), so {@link desktopEnv} threads that through. {@link makeExec} is the
|
|
8
|
+
* one I/O seam: production binds the real `execFile`, tests inject a fake to drive
|
|
9
|
+
* the pure orchestration without spawning anything.
|
|
10
|
+
*
|
|
11
|
+
* Fails loud — a non-zero exit rejects through `execFile`, and callers re-wrap it
|
|
12
|
+
* as an {@link AdapterError}; never a silent fallback.
|
|
13
|
+
*/
|
|
14
|
+
/** Run a CLI tool, resolve its stdout, reject (loud) on a non-zero exit or a missing binary. */
|
|
15
|
+
export type Exec = (cmd: string, args: string[]) => Promise<string>;
|
|
16
|
+
/** A child env with `DISPLAY` overridden when a target display is configured (else inherit). */
|
|
17
|
+
export declare function desktopEnv(display?: string): NodeJS.ProcessEnv;
|
|
18
|
+
/** The real {@link Exec}: `execFile` bound to a fixed child env. */
|
|
19
|
+
export declare function makeExec(env: NodeJS.ProcessEnv): Exec;
|
|
20
|
+
/** True when an error is a "binary not found on PATH" (`ENOENT`) — for a clear, loud message. */
|
|
21
|
+
export declare function isEnoent(error: unknown): boolean;
|
|
22
|
+
/** Compact message extractor for wrapping a thrown subprocess error. */
|
|
23
|
+
export declare function errMessage(error: unknown): string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subprocess + environment plumbing shared by the desktop adapter's CLI tools
|
|
3
|
+
* (`xdotool`, `scrot`/`grim`, `busctl`).
|
|
4
|
+
*
|
|
5
|
+
* The desktop adapter drives the target by shelling out — there is no in-process
|
|
6
|
+
* SDK like CDP. Every tool runs on a chosen X11 `DISPLAY` (e.g. `:99` for an Xvfb
|
|
7
|
+
* container), so {@link desktopEnv} threads that through. {@link makeExec} is the
|
|
8
|
+
* one I/O seam: production binds the real `execFile`, tests inject a fake to drive
|
|
9
|
+
* the pure orchestration without spawning anything.
|
|
10
|
+
*
|
|
11
|
+
* Fails loud — a non-zero exit rejects through `execFile`, and callers re-wrap it
|
|
12
|
+
* as an {@link AdapterError}; never a silent fallback.
|
|
13
|
+
*/
|
|
14
|
+
import { execFile } from 'node:child_process';
|
|
15
|
+
import { promisify } from 'node:util';
|
|
16
|
+
const pExecFile = promisify(execFile);
|
|
17
|
+
/** 16 MiB stdout cap — busctl JSON is small; the screenshots route through a file. */
|
|
18
|
+
const MAX_BUFFER = 16 * 1024 * 1024;
|
|
19
|
+
/** A child env with `DISPLAY` overridden when a target display is configured (else inherit). */
|
|
20
|
+
export function desktopEnv(display) {
|
|
21
|
+
return display ? { ...process.env, DISPLAY: display } : { ...process.env };
|
|
22
|
+
}
|
|
23
|
+
/** The real {@link Exec}: `execFile` bound to a fixed child env. */
|
|
24
|
+
export function makeExec(env) {
|
|
25
|
+
return async (cmd, args) => {
|
|
26
|
+
const { stdout } = await pExecFile(cmd, args, { env, maxBuffer: MAX_BUFFER });
|
|
27
|
+
return stdout;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** True when an error is a "binary not found on PATH" (`ENOENT`) — for a clear, loud message. */
|
|
31
|
+
export function isEnoent(error) {
|
|
32
|
+
return error instanceof Error && error.code === 'ENOENT';
|
|
33
|
+
}
|
|
34
|
+
/** Compact message extractor for wrapping a thrown subprocess error. */
|
|
35
|
+
export function errMessage(error) {
|
|
36
|
+
return error instanceof Error ? error.message : String(error);
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=proc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proc.js","sourceRoot":"","sources":["../../../src/adapters/desktop/proc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,SAAS,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAEtC,sFAAsF;AACtF,MAAM,UAAU,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAKpC,gGAAgG;AAChG,MAAM,UAAU,UAAU,CAAC,OAAgB;IACzC,OAAO,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;AAC7E,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,QAAQ,CAAC,GAAsB;IAC7C,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACzB,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC;QAC9E,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAED,iGAAiG;AACjG,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,KAAK,YAAY,KAAK,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ,CAAC;AACtF,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter factory — resolve a target name to a concrete Adapter implementation.
|
|
3
|
+
*
|
|
4
|
+
* Maps config targets (`web`, `desktop`, `mobile`, …) to their adapter protocols
|
|
5
|
+
* (CDP browser, X11-Wayland, ADB). Throws {@link TargetNotFoundError} if the target
|
|
6
|
+
* name doesn't exist in the config; throws {@link AdapterError} only for an unknown
|
|
7
|
+
* adapter kind. `browser` (CDP), `desktop` (X11) and `android` (ADB) are operational.
|
|
8
|
+
*/
|
|
9
|
+
import type { Config } from '../config/schema.js';
|
|
10
|
+
import { type BrowserAdapterInit } from './browser/browser-adapter.js';
|
|
11
|
+
import type { Adapter } from './contract.js';
|
|
12
|
+
/**
|
|
13
|
+
* Create an adapter for a named target from the resolved config.
|
|
14
|
+
*
|
|
15
|
+
* @param targetName — the key in config.targets (e.g., "web")
|
|
16
|
+
* @param config — the resolved `.ui-debugger-mcp.json` config
|
|
17
|
+
* @param profileDir — absolute path to persistent profile dir (for managed browser adapter)
|
|
18
|
+
* @param onLog — optional sink for streaming console/network logs to findings store
|
|
19
|
+
* @returns the wired Adapter instance
|
|
20
|
+
* @throws TargetNotFoundError if targetName doesn't exist in config.targets
|
|
21
|
+
* @throws AdapterError if the adapter type is not yet implemented
|
|
22
|
+
*/
|
|
23
|
+
export declare function createAdapter(targetName: string, config: Config, profileDir: string, onLog?: BrowserAdapterInit['onLog']): Promise<Adapter>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter factory — resolve a target name to a concrete Adapter implementation.
|
|
3
|
+
*
|
|
4
|
+
* Maps config targets (`web`, `desktop`, `mobile`, …) to their adapter protocols
|
|
5
|
+
* (CDP browser, X11-Wayland, ADB). Throws {@link TargetNotFoundError} if the target
|
|
6
|
+
* name doesn't exist in the config; throws {@link AdapterError} only for an unknown
|
|
7
|
+
* adapter kind. `browser` (CDP), `desktop` (X11) and `android` (ADB) are operational.
|
|
8
|
+
*/
|
|
9
|
+
import { AdapterError, TargetNotFoundError } from '../errors.js';
|
|
10
|
+
import { AndroidAdapter } from './android/android-adapter.js';
|
|
11
|
+
import { BrowserAdapter } from './browser/browser-adapter.js';
|
|
12
|
+
import { DesktopAdapter } from './desktop/desktop-adapter.js';
|
|
13
|
+
/**
|
|
14
|
+
* Create an adapter for a named target from the resolved config.
|
|
15
|
+
*
|
|
16
|
+
* @param targetName — the key in config.targets (e.g., "web")
|
|
17
|
+
* @param config — the resolved `.ui-debugger-mcp.json` config
|
|
18
|
+
* @param profileDir — absolute path to persistent profile dir (for managed browser adapter)
|
|
19
|
+
* @param onLog — optional sink for streaming console/network logs to findings store
|
|
20
|
+
* @returns the wired Adapter instance
|
|
21
|
+
* @throws TargetNotFoundError if targetName doesn't exist in config.targets
|
|
22
|
+
* @throws AdapterError if the adapter type is not yet implemented
|
|
23
|
+
*/
|
|
24
|
+
export async function createAdapter(targetName, config, profileDir, onLog) {
|
|
25
|
+
const target = config.targets[targetName];
|
|
26
|
+
if (!target) {
|
|
27
|
+
throw new TargetNotFoundError(`target "${targetName}" not found in config.targets`);
|
|
28
|
+
}
|
|
29
|
+
switch (target.adapter) {
|
|
30
|
+
case 'browser':
|
|
31
|
+
return BrowserAdapter.create({ config: target, profileDir, onLog });
|
|
32
|
+
case 'desktop':
|
|
33
|
+
// Desktop is managed-only (no attach handle), so `profileDir`/`onLog` don't apply.
|
|
34
|
+
return DesktopAdapter.create({ config: target });
|
|
35
|
+
case 'android':
|
|
36
|
+
// Managed (boot `emulator @avd`) unless `adbSerial` attaches — `create` reads that
|
|
37
|
+
// off the config. No page profile or CDP log sink applies, so neither is threaded.
|
|
38
|
+
return AndroidAdapter.create({ config: target });
|
|
39
|
+
default: {
|
|
40
|
+
const unreachable = target;
|
|
41
|
+
throw new AdapterError(`unknown adapter type: ${unreachable}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/adapters/factory.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAA2B,MAAM,8BAA8B,CAAC;AAEvF,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,UAAkB,EAClB,MAAc,EACd,UAAkB,EAClB,KAAmC;IAEnC,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAE1C,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,mBAAmB,CAAC,WAAW,UAAU,+BAA+B,CAAC,CAAC;IACtF,CAAC;IAED,QAAQ,MAAM,CAAC,OAAO,EAAE,CAAC;QACvB,KAAK,SAAS;YACZ,OAAO,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,K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