@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,308 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CDP console + network capture — the browser adapter's passive observers.
|
|
3
|
+
*
|
|
4
|
+
* Subscribes to Playwright/CDP events the moment the adapter opens and keeps a
|
|
5
|
+
* bounded, in-memory ring of normalized entries:
|
|
6
|
+
* - `page.on('console')` → {@link ConsoleEntry} (severity normalized)
|
|
7
|
+
* - `page.on('pageerror')` → {@link ConsoleEntry} at `level: 'error'` (uncaught
|
|
8
|
+
* exceptions never surface as console messages, but the contract says
|
|
9
|
+
* console capture covers them — so we fold them in)
|
|
10
|
+
* - `page.on('requestfailed')` → {@link NetworkEntry} (`status: 0`, `ok: false`)
|
|
11
|
+
* - `page.on('response')` → {@link NetworkEntry} (covers 4xx/5xx too)
|
|
12
|
+
*
|
|
13
|
+
* Every listener is scoped to the SELECTED page, not the context — an attach or
|
|
14
|
+
* persistent session can hold unrelated tabs, and their traffic must not leak
|
|
15
|
+
* into this run's `network()`.
|
|
16
|
+
*
|
|
17
|
+
* Each captured entry is ALSO streamed line-by-line to an optional {@link CaptureSink}
|
|
18
|
+
* (the session layer wires it to `findings-store`'s `logs/console.log` /
|
|
19
|
+
* `logs/network.log`), so the persistent trail and the live buffer stay in sync.
|
|
20
|
+
*
|
|
21
|
+
* Reads are non-destructive and SQL-like: `console`/`network` return newest-first,
|
|
22
|
+
* narrowed by the whitelisted {@link LogQuery.filters} and capped by `limit`. The
|
|
23
|
+
* buffer is the source of truth for the agent's `observe`; the on-disk log is the
|
|
24
|
+
* durable record. Filters fail loud — an unknown key or wrong value type throws
|
|
25
|
+
* {@link AdapterError}, never a silent ignore.
|
|
26
|
+
*/
|
|
27
|
+
import { AdapterError } from '../../errors.js';
|
|
28
|
+
/** Default ring size per channel — keeps memory bounded on chatty pages. */
|
|
29
|
+
const DEFAULT_BUFFER_CAP = 1000;
|
|
30
|
+
/** Whitelisted `filters` keys for the console channel — anything else is rejected. */
|
|
31
|
+
export const CONSOLE_FILTER_KEYS = ['level_eq', 'level_in', 'text_contains'];
|
|
32
|
+
/** Whitelisted `filters` keys for the network channel — anything else is rejected. */
|
|
33
|
+
export const NETWORK_FILTER_KEYS = [
|
|
34
|
+
'status_eq',
|
|
35
|
+
'status_gte',
|
|
36
|
+
'status_lt',
|
|
37
|
+
'ok_eq',
|
|
38
|
+
'failed_eq',
|
|
39
|
+
'method_eq',
|
|
40
|
+
'resource_in',
|
|
41
|
+
'url_contains',
|
|
42
|
+
];
|
|
43
|
+
// --- Normalizers ------------------------------------------------------------
|
|
44
|
+
/** Map a CDP console `type()` onto the normalized {@link ConsoleEntry} level. */
|
|
45
|
+
export function normalizeConsoleLevel(type) {
|
|
46
|
+
switch (type) {
|
|
47
|
+
case 'error':
|
|
48
|
+
case 'assert':
|
|
49
|
+
return 'error';
|
|
50
|
+
case 'warning':
|
|
51
|
+
case 'warn':
|
|
52
|
+
return 'warn';
|
|
53
|
+
case 'info':
|
|
54
|
+
case 'count':
|
|
55
|
+
case 'timeEnd':
|
|
56
|
+
return 'info';
|
|
57
|
+
case 'debug':
|
|
58
|
+
return 'debug';
|
|
59
|
+
default:
|
|
60
|
+
return 'log';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// --- Line formatting (durable log trail) ------------------------------------
|
|
64
|
+
/** ISO-8601 stamp from epoch ms; deterministic given the injected clock. */
|
|
65
|
+
function stamp(ts) {
|
|
66
|
+
return new Date(ts).toISOString();
|
|
67
|
+
}
|
|
68
|
+
/** Render a {@link ConsoleEntry} as one greppable `logs/console.log` line. */
|
|
69
|
+
export function formatConsoleLine(entry) {
|
|
70
|
+
const where = entry.location ? ` @ ${entry.location}` : '';
|
|
71
|
+
return `${stamp(entry.timestamp)} ${entry.level.toUpperCase()} ${entry.text}${where}`;
|
|
72
|
+
}
|
|
73
|
+
/** Render a {@link NetworkEntry} as one greppable `logs/network.log` line. */
|
|
74
|
+
export function formatNetworkLine(entry) {
|
|
75
|
+
const head = `${stamp(entry.timestamp)} ${entry.method} ${entry.url}`;
|
|
76
|
+
if (entry.error !== undefined)
|
|
77
|
+
return `${head} → FAILED ${entry.error}`;
|
|
78
|
+
const type = entry.resourceType ? ` [${entry.resourceType}]` : '';
|
|
79
|
+
return `${head} → ${entry.status}${type}`;
|
|
80
|
+
}
|
|
81
|
+
// --- Filter value type-guards (fail loud, never coerce) ---------------------
|
|
82
|
+
function expectBoolean(key, value) {
|
|
83
|
+
if (typeof value !== 'boolean')
|
|
84
|
+
throw new AdapterError(`filter \`${key}\` expects a boolean`);
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
function expectNumber(key, value) {
|
|
88
|
+
if (typeof value !== 'number')
|
|
89
|
+
throw new AdapterError(`filter \`${key}\` expects a number`);
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
function expectString(key, value) {
|
|
93
|
+
if (typeof value !== 'string')
|
|
94
|
+
throw new AdapterError(`filter \`${key}\` expects a string`);
|
|
95
|
+
return value;
|
|
96
|
+
}
|
|
97
|
+
function expectStringArray(key, value) {
|
|
98
|
+
if (!Array.isArray(value) || value.some((v) => typeof v !== 'string')) {
|
|
99
|
+
throw new AdapterError(`filter \`${key}\` expects a string[]`);
|
|
100
|
+
}
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
// --- Filtering (whitelisted, per-channel) -----------------------------------
|
|
104
|
+
/**
|
|
105
|
+
* Narrow console entries by the whitelisted `filters` keys
|
|
106
|
+
* ({@link CONSOLE_FILTER_KEYS}). Throws {@link AdapterError} on an unknown key
|
|
107
|
+
* (no silent injection surface) or a wrong value type.
|
|
108
|
+
*/
|
|
109
|
+
export function filterConsole(entries, filters) {
|
|
110
|
+
if (!filters)
|
|
111
|
+
return entries;
|
|
112
|
+
let out = entries;
|
|
113
|
+
for (const [key, value] of Object.entries(filters)) {
|
|
114
|
+
switch (key) {
|
|
115
|
+
case 'level_eq': {
|
|
116
|
+
const want = expectString(key, value);
|
|
117
|
+
out = out.filter((e) => e.level === want);
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
case 'level_in': {
|
|
121
|
+
const want = expectStringArray(key, value);
|
|
122
|
+
out = out.filter((e) => want.includes(e.level));
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
case 'text_contains': {
|
|
126
|
+
const needle = expectString(key, value).toLowerCase();
|
|
127
|
+
out = out.filter((e) => e.text.toLowerCase().includes(needle));
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
default:
|
|
131
|
+
throw new AdapterError(`unknown console filter \`${key}\` (allowed: ${CONSOLE_FILTER_KEYS.join(', ')})`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return out;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Narrow network entries by the whitelisted `filters` keys
|
|
138
|
+
* ({@link NETWORK_FILTER_KEYS}). Throws {@link AdapterError} on an unknown key or
|
|
139
|
+
* a wrong value type.
|
|
140
|
+
*/
|
|
141
|
+
export function filterNetwork(entries, filters) {
|
|
142
|
+
if (!filters)
|
|
143
|
+
return entries;
|
|
144
|
+
let out = entries;
|
|
145
|
+
for (const [key, value] of Object.entries(filters)) {
|
|
146
|
+
switch (key) {
|
|
147
|
+
case 'status_eq': {
|
|
148
|
+
const want = expectNumber(key, value);
|
|
149
|
+
out = out.filter((e) => e.status === want);
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
case 'status_gte': {
|
|
153
|
+
const want = expectNumber(key, value);
|
|
154
|
+
out = out.filter((e) => e.status >= want);
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
case 'status_lt': {
|
|
158
|
+
const want = expectNumber(key, value);
|
|
159
|
+
out = out.filter((e) => e.status < want);
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
case 'ok_eq': {
|
|
163
|
+
const want = expectBoolean(key, value);
|
|
164
|
+
out = out.filter((e) => e.ok === want);
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
case 'failed_eq': {
|
|
168
|
+
const want = expectBoolean(key, value);
|
|
169
|
+
out = out.filter((e) => (e.error !== undefined) === want);
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
case 'method_eq': {
|
|
173
|
+
const want = expectString(key, value).toUpperCase();
|
|
174
|
+
out = out.filter((e) => e.method.toUpperCase() === want);
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
case 'resource_in': {
|
|
178
|
+
const want = expectStringArray(key, value);
|
|
179
|
+
out = out.filter((e) => e.resourceType !== undefined && want.includes(e.resourceType));
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
case 'url_contains': {
|
|
183
|
+
const needle = expectString(key, value).toLowerCase();
|
|
184
|
+
out = out.filter((e) => e.url.toLowerCase().includes(needle));
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
default:
|
|
188
|
+
throw new AdapterError(`unknown network filter \`${key}\` (allowed: ${NETWORK_FILTER_KEYS.join(', ')})`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return out;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Reverse to newest-first and apply `limit` — the shared `console`/`network` read
|
|
195
|
+
* tail. Rejects bad limits loud: `slice` would silently coerce `-1` to "all but
|
|
196
|
+
* the oldest" and `NaN` to `[]`, so non-negative integers only.
|
|
197
|
+
*/
|
|
198
|
+
function newestFirst(filtered, limit) {
|
|
199
|
+
const out = [...filtered].reverse();
|
|
200
|
+
if (limit === undefined)
|
|
201
|
+
return out;
|
|
202
|
+
if (!Number.isInteger(limit) || limit < 0) {
|
|
203
|
+
throw new AdapterError('`limit` must be a non-negative integer');
|
|
204
|
+
}
|
|
205
|
+
return out.slice(0, limit);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Captures and buffers console + network activity for one browser adapter.
|
|
209
|
+
* Construct with the open page/context, then {@link CdpCapture.start}; release the
|
|
210
|
+
* listeners with {@link CdpCapture.stop} before the page closes.
|
|
211
|
+
*/
|
|
212
|
+
export class CdpCapture {
|
|
213
|
+
#page;
|
|
214
|
+
#sink;
|
|
215
|
+
#now;
|
|
216
|
+
#cap;
|
|
217
|
+
#console = [];
|
|
218
|
+
#network = [];
|
|
219
|
+
/** Detacher thunks captured at `start`, replayed at `stop`. */
|
|
220
|
+
#detachers = [];
|
|
221
|
+
#started = false;
|
|
222
|
+
constructor(init) {
|
|
223
|
+
this.#page = init.page;
|
|
224
|
+
this.#sink = init.sink;
|
|
225
|
+
this.#now = init.now ?? (() => Date.now());
|
|
226
|
+
this.#cap = init.cap ?? DEFAULT_BUFFER_CAP;
|
|
227
|
+
}
|
|
228
|
+
/** Subscribe to the console/error/network events. Idempotent (a re-`start` is a no-op). */
|
|
229
|
+
start() {
|
|
230
|
+
if (this.#started)
|
|
231
|
+
return;
|
|
232
|
+
this.#started = true;
|
|
233
|
+
this.#page.on('console', this.#onConsole);
|
|
234
|
+
this.#page.on('pageerror', this.#onPageError);
|
|
235
|
+
this.#page.on('requestfailed', this.#onRequestFailed);
|
|
236
|
+
this.#page.on('response', this.#onResponse);
|
|
237
|
+
this.#detachers.push(() => this.#page.off('console', this.#onConsole), () => this.#page.off('pageerror', this.#onPageError), () => this.#page.off('requestfailed', this.#onRequestFailed), () => this.#page.off('response', this.#onResponse));
|
|
238
|
+
}
|
|
239
|
+
/** Detach every listener. Idempotent; safe to call after the page is gone. */
|
|
240
|
+
stop() {
|
|
241
|
+
for (const detach of this.#detachers.splice(0))
|
|
242
|
+
detach();
|
|
243
|
+
this.#started = false;
|
|
244
|
+
}
|
|
245
|
+
/** Captured console messages, newest first, narrowed by {@link LogQuery}. */
|
|
246
|
+
console(opts = {}) {
|
|
247
|
+
return newestFirst(filterConsole(this.#console, opts.filters), opts.limit);
|
|
248
|
+
}
|
|
249
|
+
/** Captured network exchanges, newest first, narrowed by {@link LogQuery}. */
|
|
250
|
+
network(opts = {}) {
|
|
251
|
+
return newestFirst(filterNetwork(this.#network, opts.filters), opts.limit);
|
|
252
|
+
}
|
|
253
|
+
// --- Event handlers (arrow fields: bound `this`, stable refs for `off`) ----
|
|
254
|
+
#onConsole = (msg) => {
|
|
255
|
+
const loc = msg.location();
|
|
256
|
+
this.#pushConsole({
|
|
257
|
+
level: normalizeConsoleLevel(msg.type()),
|
|
258
|
+
text: msg.text(),
|
|
259
|
+
location: loc.url ? `${loc.url}:${loc.line}:${loc.column}` : undefined,
|
|
260
|
+
timestamp: this.#now(),
|
|
261
|
+
});
|
|
262
|
+
};
|
|
263
|
+
#onPageError = (error) => {
|
|
264
|
+
this.#pushConsole({
|
|
265
|
+
level: 'error',
|
|
266
|
+
text: error.message,
|
|
267
|
+
location: error.stack?.split('\n')[1]?.trim(),
|
|
268
|
+
timestamp: this.#now(),
|
|
269
|
+
});
|
|
270
|
+
};
|
|
271
|
+
#onRequestFailed = (request) => {
|
|
272
|
+
this.#pushNetwork({
|
|
273
|
+
method: request.method(),
|
|
274
|
+
url: request.url(),
|
|
275
|
+
status: 0,
|
|
276
|
+
ok: false,
|
|
277
|
+
resourceType: request.resourceType(),
|
|
278
|
+
error: request.failure()?.errorText ?? 'request failed',
|
|
279
|
+
timestamp: this.#now(),
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
#onResponse = (response) => {
|
|
283
|
+
const request = response.request();
|
|
284
|
+
this.#pushNetwork({
|
|
285
|
+
method: request.method(),
|
|
286
|
+
url: response.url(),
|
|
287
|
+
status: response.status(),
|
|
288
|
+
ok: response.ok(),
|
|
289
|
+
resourceType: request.resourceType(),
|
|
290
|
+
timestamp: this.#now(),
|
|
291
|
+
});
|
|
292
|
+
};
|
|
293
|
+
/** Ring-buffer a console entry and stream its formatted line to the sink. */
|
|
294
|
+
#pushConsole(entry) {
|
|
295
|
+
this.#console.push(entry);
|
|
296
|
+
if (this.#console.length > this.#cap)
|
|
297
|
+
this.#console.shift();
|
|
298
|
+
this.#sink?.('console', formatConsoleLine(entry));
|
|
299
|
+
}
|
|
300
|
+
/** Ring-buffer a network entry and stream its formatted line to the sink. */
|
|
301
|
+
#pushNetwork(entry) {
|
|
302
|
+
this.#network.push(entry);
|
|
303
|
+
if (this.#network.length > this.#cap)
|
|
304
|
+
this.#network.shift();
|
|
305
|
+
this.#sink?.('network', formatNetworkLine(entry));
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
//# sourceMappingURL=cdp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cdp.js","sourceRoot":"","sources":["../../../src/adapters/browser/cdp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;A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AAiB,CAAC,KAAK,CAAC,CAAC,CAAC;IACpD,CAAC;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query normalization — bridge the gap between what the driver *reads* and what
|
|
3
|
+
* Playwright *accepts*.
|
|
4
|
+
*
|
|
5
|
+
* `observe({kind:'tree'})` hands the agent nodes as `role` + accessible `name`
|
|
6
|
+
* (e.g. `[button] "Add to cart"`) — it never sees a CSS selector. So when the
|
|
7
|
+
* agent acts, the natural targets it produces are role+name (`button "Add to
|
|
8
|
+
* cart"`) or plain text (`Add to cart`) — both of which a raw
|
|
9
|
+
* `page.locator(selector)` rejects (invalid CSS) or misses. That mismatch made
|
|
10
|
+
* the driver loop forever without ever landing a click.
|
|
11
|
+
*
|
|
12
|
+
* {@link normalizeQuery} maps those LLM-natural targets onto Playwright selector
|
|
13
|
+
* engines, while passing real CSS / explicit-engine / XPath selectors straight
|
|
14
|
+
* through. The result is always a string a Playwright `locator()` understands.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Turn an agent-supplied target into a Playwright-resolvable selector string.
|
|
18
|
+
*
|
|
19
|
+
* Resolution order (first match wins):
|
|
20
|
+
* 1. explicit engine / XPath (`text=…`, `role=…`, `css=…`, `//…`) → verbatim
|
|
21
|
+
* 2. `role "name"` → `role=<role>[name="<name>" i]` (case-insensitive)
|
|
22
|
+
* 3. CSS-looking → verbatim CSS
|
|
23
|
+
* 4. anything else (plain visible text) → `text=<query>` (case-insensitive substring)
|
|
24
|
+
*/
|
|
25
|
+
export declare function normalizeQuery(raw: string): string;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query normalization — bridge the gap between what the driver *reads* and what
|
|
3
|
+
* Playwright *accepts*.
|
|
4
|
+
*
|
|
5
|
+
* `observe({kind:'tree'})` hands the agent nodes as `role` + accessible `name`
|
|
6
|
+
* (e.g. `[button] "Add to cart"`) — it never sees a CSS selector. So when the
|
|
7
|
+
* agent acts, the natural targets it produces are role+name (`button "Add to
|
|
8
|
+
* cart"`) or plain text (`Add to cart`) — both of which a raw
|
|
9
|
+
* `page.locator(selector)` rejects (invalid CSS) or misses. That mismatch made
|
|
10
|
+
* the driver loop forever without ever landing a click.
|
|
11
|
+
*
|
|
12
|
+
* {@link normalizeQuery} maps those LLM-natural targets onto Playwright selector
|
|
13
|
+
* engines, while passing real CSS / explicit-engine / XPath selectors straight
|
|
14
|
+
* through. The result is always a string a Playwright `locator()` understands.
|
|
15
|
+
*/
|
|
16
|
+
/** Selector engines (and XPath) Playwright already understands — passed through verbatim. */
|
|
17
|
+
const ENGINE_PREFIX = /^(css|text|role|id|data-testid|xpath|internal:[a-z-]+)=/i;
|
|
18
|
+
/**
|
|
19
|
+
* ARIA roles Playwright's `role=` engine accepts — the allow-list that gates the
|
|
20
|
+
* `role "name"` shorthand. A first token outside this set is an ordinary label,
|
|
21
|
+
* not a role (so `Sale "50% off"` stays text, never `role=sale`), and falls through
|
|
22
|
+
* to the plain-text engine. Mirrors the role set `observe` uses to build targets.
|
|
23
|
+
*/
|
|
24
|
+
const ARIA_ROLES = new Set([
|
|
25
|
+
'button',
|
|
26
|
+
'link',
|
|
27
|
+
'checkbox',
|
|
28
|
+
'radio',
|
|
29
|
+
'textbox',
|
|
30
|
+
'combobox',
|
|
31
|
+
'slider',
|
|
32
|
+
'heading',
|
|
33
|
+
'img',
|
|
34
|
+
'navigation',
|
|
35
|
+
'main',
|
|
36
|
+
'form',
|
|
37
|
+
'list',
|
|
38
|
+
'listitem',
|
|
39
|
+
'tab',
|
|
40
|
+
'menuitem',
|
|
41
|
+
'switch',
|
|
42
|
+
'dialog',
|
|
43
|
+
'banner',
|
|
44
|
+
'contentinfo',
|
|
45
|
+
'region',
|
|
46
|
+
'article',
|
|
47
|
+
'search',
|
|
48
|
+
'table',
|
|
49
|
+
]);
|
|
50
|
+
/** `role "Accessible Name"` (or single quotes / smart quotes), e.g. `button "Add to cart"`. */
|
|
51
|
+
const ROLE_NAME = /^([a-zA-Z][\w-]*)\s+["'“”](.+?)["'”“]$/;
|
|
52
|
+
/**
|
|
53
|
+
* CSS-ish, kept deliberately narrow so ordinary labels are not misread as selectors:
|
|
54
|
+
* - starts with `.`/`#`/`[`/`*`,
|
|
55
|
+
* - a `tag` immediately followed by `.`/`#`/`[`/`:` (e.g. `div.card`, `a:hover`),
|
|
56
|
+
* - a combinator (`>`/`~`) flanked by simple selectors on BOTH sides — a tag or a
|
|
57
|
+
* `.`/`#`/`[`/`*` token — so `nav > a` is CSS while `Next >` and `A ~ B` stay text,
|
|
58
|
+
* - or a structural pseudo (`:has(`, `:nth-`, `::`).
|
|
59
|
+
*/
|
|
60
|
+
const CSS_LIKE = /^[.#[*]|^[a-zA-Z][\w-]*[.#:[]|(?:[a-z][\w-]*|[.#][\w-]+|\*|\])\s*[>~]\s*(?:[a-z][\w-]*|[.#[*])|:has\(|:nth-|::/;
|
|
61
|
+
/**
|
|
62
|
+
* Turn an agent-supplied target into a Playwright-resolvable selector string.
|
|
63
|
+
*
|
|
64
|
+
* Resolution order (first match wins):
|
|
65
|
+
* 1. explicit engine / XPath (`text=…`, `role=…`, `css=…`, `//…`) → verbatim
|
|
66
|
+
* 2. `role "name"` → `role=<role>[name="<name>" i]` (case-insensitive)
|
|
67
|
+
* 3. CSS-looking → verbatim CSS
|
|
68
|
+
* 4. anything else (plain visible text) → `text=<query>` (case-insensitive substring)
|
|
69
|
+
*/
|
|
70
|
+
export function normalizeQuery(raw) {
|
|
71
|
+
const q = raw.trim();
|
|
72
|
+
if (q === '')
|
|
73
|
+
return q;
|
|
74
|
+
if (ENGINE_PREFIX.test(q) || q.startsWith('//') || q.startsWith('(//'))
|
|
75
|
+
return q;
|
|
76
|
+
const roleName = ROLE_NAME.exec(q);
|
|
77
|
+
if (roleName?.[1] && roleName[2] && ARIA_ROLES.has(roleName[1].toLowerCase())) {
|
|
78
|
+
return `role=${roleName[1].toLowerCase()}[name=${JSON.stringify(roleName[2])} i]`;
|
|
79
|
+
}
|
|
80
|
+
if (CSS_LIKE.test(q))
|
|
81
|
+
return q;
|
|
82
|
+
// Plain text the agent copied out of the tree's `name` — match it as visible text.
|
|
83
|
+
return `text=${q}`;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../../src/adapters/browser/query.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,6FAA6F;AAC7F,MAAM,aAAa,GAAG,0DAA0D,CAAC;AAEjF;;;;;GAKG;AACH,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IACzB,QAAQ;IACR,MAAM;IACN,UAAU;IACV,OAAO;IACP,SAAS;IACT,UAAU;IACV,QAAQ;IACR,SAAS;IACT,KAAK;IACL,YAAY;IACZ,MAAM;IACN,MAAM;IACN,MAAM;IACN,UAAU;IACV,KAAK;IACL,UAAU;IACV,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,aAAa;IACb,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,OAAO;CACR,CAAC,CAAC;AAEH,+FAA+F;AAC/F,MAAM,SAAS,GAAG,wCAAwC,CAAC;AAE3D;;;;;;;GAOG;AACH,MAAM,QAAQ,GACZ,gHAAgH,CAAC;AAEnH;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IACrB,IAAI,CAAC,KAAK,EAAE;QAAE,OAAO,CAAC,CAAC;IACvB,IAAI,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAEjF,MAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACnC,IAAI,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;QAC9E,OAAO,QAAQ,QAAQ,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,SAAS,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACpF,CAAC;IAED,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC;IAE/B,mFAAmF;IACnF,OAAO,QAAQ,CAAC,EAAE,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared adapter contract — the one real seam in the system.
|
|
3
|
+
*
|
|
4
|
+
* Every adapter (browser/CDP, desktop/X11-Wayland, android/ADB) implements this
|
|
5
|
+
* same small interface, so the debug agent's loop is **adapter-blind**: the
|
|
6
|
+
* inner tool belt (`observe`/`act`/`look`) hits these methods and never learns
|
|
7
|
+
* which protocol is underneath. Web reads the DOM, desktop the a11y tree, mobile
|
|
8
|
+
* the view hierarchy — but all three normalize to the {@link Node} shape below,
|
|
9
|
+
* falling back to vision (screenshot + coordinates) when no tree exists.
|
|
10
|
+
*
|
|
11
|
+
* Reads are **SQL-like**, not RPC: a handful of verbs with composable params
|
|
12
|
+
* (`query`/`fields`/`filters`/`limit`/`within`) — see {@link Query}. The belt's
|
|
13
|
+
* `observe({ kind })` selects the table (`tree`/`screenshot`/`console`/`network`)
|
|
14
|
+
* and routes to the matching method here.
|
|
15
|
+
*
|
|
16
|
+
* Implementations MUST fail loud — throw an {@link AdapterError} (or a more
|
|
17
|
+
* specific custom error), never swallow or return a silent fallback.
|
|
18
|
+
*
|
|
19
|
+
* See `idea/adapters.md` and `idea/mcp-tools.md`.
|
|
20
|
+
*/
|
|
21
|
+
/** On-screen rectangle in CSS/device pixels, origin top-left. Powers clicks + vision. */
|
|
22
|
+
export interface Bounds {
|
|
23
|
+
x: number;
|
|
24
|
+
y: number;
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A single UI element, normalized across targets (DOM node / a11y node /
|
|
30
|
+
* view-hierarchy node). Adapters map their native shape onto these four fields.
|
|
31
|
+
*/
|
|
32
|
+
export interface Node {
|
|
33
|
+
/** Semantic role — `'button' | 'link' | 'textbox' | …` (ARIA/a11y, target-agnostic). */
|
|
34
|
+
role: string;
|
|
35
|
+
/** Accessible name — the visible label or text content. */
|
|
36
|
+
name: string;
|
|
37
|
+
/** On-screen rectangle; needed to click and to point the vision guy at it. */
|
|
38
|
+
bounds: Bounds;
|
|
39
|
+
/** Interactable — `false` when disabled/readonly. */
|
|
40
|
+
enabled: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** Selectable {@link Node} columns for the `fields` projection (a `SELECT` whitelist). */
|
|
43
|
+
export type NodeField = keyof Node;
|
|
44
|
+
/**
|
|
45
|
+
* How to point an action at an element: either a raw `query` selector the
|
|
46
|
+
* adapter re-resolves (CSS/role/text · a11y role+name · resource-id/text), or a
|
|
47
|
+
* {@link Node} already returned by {@link Adapter.find}/{@link Adapter.readState}.
|
|
48
|
+
*/
|
|
49
|
+
export type NodeRef = string | Node;
|
|
50
|
+
/** A single `filters` predicate value. Arrays back `_in`-style set membership. */
|
|
51
|
+
export type FilterValue = string | number | boolean | string[];
|
|
52
|
+
/**
|
|
53
|
+
* Structured `WHERE field_op` predicates, keyed `<field>_<op>` — e.g.
|
|
54
|
+
* `{ visible_eq: true, role_in: ['button', 'link'], status_gte: 400 }`. The set
|
|
55
|
+
* of allowed keys is **whitelisted per adapter** (never an open injection
|
|
56
|
+
* surface); unknown keys are rejected by the adapter, not silently ignored.
|
|
57
|
+
*/
|
|
58
|
+
export type Filters = Record<string, FilterValue>;
|
|
59
|
+
/**
|
|
60
|
+
* SQL-like read parameters — push composition into params, like a `SELECT`.
|
|
61
|
+
* All optional; an empty `Query` reads the whole (capped) tree.
|
|
62
|
+
*/
|
|
63
|
+
export interface Query {
|
|
64
|
+
/** `WHERE` / selector — target node(s): CSS/role/text (web), a11y role+name (desktop), resource-id/text (android). */
|
|
65
|
+
query?: string;
|
|
66
|
+
/** `SELECT cols` — which {@link Node} fields to populate for a sparse read; omit for all. */
|
|
67
|
+
fields?: NodeField[];
|
|
68
|
+
/** `WHERE field_op` — structured predicates; see {@link Filters}. Whitelisted per adapter. */
|
|
69
|
+
filters?: Filters;
|
|
70
|
+
/** `LIMIT` — cap how many nodes come back, to keep the tree small. */
|
|
71
|
+
limit?: number;
|
|
72
|
+
/** Scope — restrict the search to a subtree/region (a selector or {@link Node}). */
|
|
73
|
+
within?: NodeRef;
|
|
74
|
+
}
|
|
75
|
+
/** Read parameters for the append-only log channels (`console`/`network`). */
|
|
76
|
+
export interface LogQuery {
|
|
77
|
+
/** `WHERE field_op` — e.g. `{ level_eq: 'error' }` (console) or `{ status_gte: 400 }` (network). */
|
|
78
|
+
filters?: Filters;
|
|
79
|
+
/** `LIMIT` — cap how many entries come back (most recent first). */
|
|
80
|
+
limit?: number;
|
|
81
|
+
}
|
|
82
|
+
/** What {@link Adapter.waitFor} should block on; combine fields (all that are set must hold). */
|
|
83
|
+
export interface WaitOptions {
|
|
84
|
+
/** Wait until a node matching this selector exists/becomes visible. */
|
|
85
|
+
query?: string;
|
|
86
|
+
/** Wait until in-flight requests settle (web: network idle). */
|
|
87
|
+
networkIdle?: boolean;
|
|
88
|
+
/** Hard cap in ms; on expiry the adapter throws (never resolves silently). */
|
|
89
|
+
timeout?: number;
|
|
90
|
+
}
|
|
91
|
+
/** Cardinal direction for {@link Adapter.scroll}; each adapter maps it to wheel/gesture deltas. */
|
|
92
|
+
export type ScrollDirection = 'up' | 'down' | 'left' | 'right';
|
|
93
|
+
/** How {@link Adapter.scroll} moves content — a {@link ScrollDirection} plus optional distance and scope. */
|
|
94
|
+
export interface ScrollOptions {
|
|
95
|
+
/** Which way to move the content (the viewport scrolls toward this edge). */
|
|
96
|
+
direction: ScrollDirection;
|
|
97
|
+
/** Distance in CSS/device pixels; omit for one adapter-default page-ish step. */
|
|
98
|
+
amount?: number;
|
|
99
|
+
/** Scope — scroll inside this subtree/region instead of the viewport (a selector or {@link Node}). */
|
|
100
|
+
within?: NodeRef;
|
|
101
|
+
}
|
|
102
|
+
/** One console message captured from the target (CDP `console` + uncaught errors). */
|
|
103
|
+
export interface ConsoleEntry {
|
|
104
|
+
/** Normalized severity (`'warning'` collapses to `'warn'`). */
|
|
105
|
+
level: 'log' | 'info' | 'warn' | 'error' | 'debug';
|
|
106
|
+
/** The logged text (args joined). */
|
|
107
|
+
text: string;
|
|
108
|
+
/** Source location `url:line:col`, when known. */
|
|
109
|
+
location?: string;
|
|
110
|
+
/** Capture time, ms since epoch. */
|
|
111
|
+
timestamp: number;
|
|
112
|
+
}
|
|
113
|
+
/** One network exchange captured from the target (CDP responses + failures). */
|
|
114
|
+
export interface NetworkEntry {
|
|
115
|
+
/** HTTP method — `GET` | `POST` | … */
|
|
116
|
+
method: string;
|
|
117
|
+
/** Request URL. */
|
|
118
|
+
url: string;
|
|
119
|
+
/** HTTP status code; `0` when the request failed/aborted before a response. */
|
|
120
|
+
status: number;
|
|
121
|
+
/** `true` for a settled `2xx`/`3xx`; `false` for `4xx`/`5xx` or a failure. */
|
|
122
|
+
ok: boolean;
|
|
123
|
+
/** Resource kind — `'fetch' | 'xhr' | 'document' | 'image' | …` — for filtering. */
|
|
124
|
+
resourceType?: string;
|
|
125
|
+
/** Failure reason when the request errored/aborted (CDP `requestfailed`). */
|
|
126
|
+
error?: string;
|
|
127
|
+
/** Capture time, ms since epoch. */
|
|
128
|
+
timestamp: number;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* One contract, three protocols. The agent loop calls only these methods; each
|
|
132
|
+
* adapter wires them to its real backend (CDP / X11-Wayland / ADB).
|
|
133
|
+
*/
|
|
134
|
+
export interface Adapter {
|
|
135
|
+
/** Go to the app: navigate to a URL (web) · launch/focus the window (desktop) · start the activity (android). */
|
|
136
|
+
open(target: string): Promise<void>;
|
|
137
|
+
/** Resolve the first node matching {@link Query}; `null` if none match. */
|
|
138
|
+
find(opts: Query): Promise<Node | null>;
|
|
139
|
+
/** Click an element (re-resolving a selector, or using a found {@link Node}). */
|
|
140
|
+
click(target: NodeRef): Promise<void>;
|
|
141
|
+
/** Type `text` into an element (focuses it first). */
|
|
142
|
+
type(target: NodeRef, text: string): Promise<void>;
|
|
143
|
+
/** Press a key or chord on the focused element — `'Enter'` · `'Escape'` · `'Control+a'` (chords split on `+`). */
|
|
144
|
+
pressKey(key: string): Promise<void>;
|
|
145
|
+
/** Scroll the viewport — or a scoped region via {@link ScrollOptions.within} — one {@link ScrollDirection} step. */
|
|
146
|
+
scroll(opts: ScrollOptions): Promise<void>;
|
|
147
|
+
/** Read the structured UI tree as normalized {@link Node}s (DOM · a11y tree · view hierarchy). */
|
|
148
|
+
readState(opts?: Query): Promise<Node[]>;
|
|
149
|
+
/** Capture the current frame as PNG bytes (for evidence + the vision guy). */
|
|
150
|
+
screenshot(): Promise<Uint8Array>;
|
|
151
|
+
/** Block until {@link WaitOptions} hold (node appears, network idle, …) or time out. */
|
|
152
|
+
waitFor(opts: WaitOptions): Promise<void>;
|
|
153
|
+
/** Drain captured console messages, newest first, narrowed by {@link LogQuery}. */
|
|
154
|
+
console(opts?: LogQuery): Promise<ConsoleEntry[]>;
|
|
155
|
+
/** Drain captured network exchanges, newest first, narrowed by {@link LogQuery}. */
|
|
156
|
+
network(opts?: LogQuery): Promise<NetworkEntry[]>;
|
|
157
|
+
/** Release the target: stop a **managed** process; for **attach**, disconnect only — never stop it. */
|
|
158
|
+
close(): Promise<void>;
|
|
159
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared adapter contract — the one real seam in the system.
|
|
3
|
+
*
|
|
4
|
+
* Every adapter (browser/CDP, desktop/X11-Wayland, android/ADB) implements this
|
|
5
|
+
* same small interface, so the debug agent's loop is **adapter-blind**: the
|
|
6
|
+
* inner tool belt (`observe`/`act`/`look`) hits these methods and never learns
|
|
7
|
+
* which protocol is underneath. Web reads the DOM, desktop the a11y tree, mobile
|
|
8
|
+
* the view hierarchy — but all three normalize to the {@link Node} shape below,
|
|
9
|
+
* falling back to vision (screenshot + coordinates) when no tree exists.
|
|
10
|
+
*
|
|
11
|
+
* Reads are **SQL-like**, not RPC: a handful of verbs with composable params
|
|
12
|
+
* (`query`/`fields`/`filters`/`limit`/`within`) — see {@link Query}. The belt's
|
|
13
|
+
* `observe({ kind })` selects the table (`tree`/`screenshot`/`console`/`network`)
|
|
14
|
+
* and routes to the matching method here.
|
|
15
|
+
*
|
|
16
|
+
* Implementations MUST fail loud — throw an {@link AdapterError} (or a more
|
|
17
|
+
* specific custom error), never swallow or return a silent fallback.
|
|
18
|
+
*
|
|
19
|
+
* See `idea/adapters.md` and `idea/mcp-tools.md`.
|
|
20
|
+
*/
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/adapters/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG"}
|