@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.
Files changed (162) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +295 -0
  3. package/dist/adapters/android/adb.d.ts +38 -0
  4. package/dist/adapters/android/adb.js +72 -0
  5. package/dist/adapters/android/adb.js.map +1 -0
  6. package/dist/adapters/android/android-adapter.d.ts +63 -0
  7. package/dist/adapters/android/android-adapter.js +306 -0
  8. package/dist/adapters/android/android-adapter.js.map +1 -0
  9. package/dist/adapters/android/commands.d.ts +59 -0
  10. package/dist/adapters/android/commands.js +178 -0
  11. package/dist/adapters/android/commands.js.map +1 -0
  12. package/dist/adapters/android/uiautomator.d.ts +81 -0
  13. package/dist/adapters/android/uiautomator.js +296 -0
  14. package/dist/adapters/android/uiautomator.js.map +1 -0
  15. package/dist/adapters/browser/browser-adapter.d.ts +72 -0
  16. package/dist/adapters/browser/browser-adapter.js +434 -0
  17. package/dist/adapters/browser/browser-adapter.js.map +1 -0
  18. package/dist/adapters/browser/cdp.d.ts +83 -0
  19. package/dist/adapters/browser/cdp.js +308 -0
  20. package/dist/adapters/browser/cdp.js.map +1 -0
  21. package/dist/adapters/browser/query.d.ts +25 -0
  22. package/dist/adapters/browser/query.js +85 -0
  23. package/dist/adapters/browser/query.js.map +1 -0
  24. package/dist/adapters/contract.d.ts +159 -0
  25. package/dist/adapters/contract.js +22 -0
  26. package/dist/adapters/contract.js.map +1 -0
  27. package/dist/adapters/desktop/atspi.d.ts +95 -0
  28. package/dist/adapters/desktop/atspi.js +359 -0
  29. package/dist/adapters/desktop/atspi.js.map +1 -0
  30. package/dist/adapters/desktop/capture.d.ts +35 -0
  31. package/dist/adapters/desktop/capture.js +67 -0
  32. package/dist/adapters/desktop/capture.js.map +1 -0
  33. package/dist/adapters/desktop/desktop-adapter.d.ts +60 -0
  34. package/dist/adapters/desktop/desktop-adapter.js +215 -0
  35. package/dist/adapters/desktop/desktop-adapter.js.map +1 -0
  36. package/dist/adapters/desktop/input.d.ts +67 -0
  37. package/dist/adapters/desktop/input.js +191 -0
  38. package/dist/adapters/desktop/input.js.map +1 -0
  39. package/dist/adapters/desktop/proc.d.ts +23 -0
  40. package/dist/adapters/desktop/proc.js +38 -0
  41. package/dist/adapters/desktop/proc.js.map +1 -0
  42. package/dist/adapters/factory.d.ts +23 -0
  43. package/dist/adapters/factory.js +45 -0
  44. package/dist/adapters/factory.js.map +1 -0
  45. package/dist/agent/belt/act.d.ts +100 -0
  46. package/dist/agent/belt/act.js +166 -0
  47. package/dist/agent/belt/act.js.map +1 -0
  48. package/dist/agent/belt/look.d.ts +98 -0
  49. package/dist/agent/belt/look.js +160 -0
  50. package/dist/agent/belt/look.js.map +1 -0
  51. package/dist/agent/belt/observe.d.ts +102 -0
  52. package/dist/agent/belt/observe.js +185 -0
  53. package/dist/agent/belt/observe.js.map +1 -0
  54. package/dist/agent/belt/report.d.ts +133 -0
  55. package/dist/agent/belt/report.js +112 -0
  56. package/dist/agent/belt/report.js.map +1 -0
  57. package/dist/agent/loop.d.ts +136 -0
  58. package/dist/agent/loop.js +173 -0
  59. package/dist/agent/loop.js.map +1 -0
  60. package/dist/agent/models.d.ts +26 -0
  61. package/dist/agent/models.js +22 -0
  62. package/dist/agent/models.js.map +1 -0
  63. package/dist/agent/prompts/android-addendum.d.ts +12 -0
  64. package/dist/agent/prompts/android-addendum.js +76 -0
  65. package/dist/agent/prompts/android-addendum.js.map +1 -0
  66. package/dist/agent/prompts/compose.d.ts +30 -0
  67. package/dist/agent/prompts/compose.js +52 -0
  68. package/dist/agent/prompts/compose.js.map +1 -0
  69. package/dist/agent/prompts/debug-agent.d.ts +9 -0
  70. package/dist/agent/prompts/debug-agent.js +102 -0
  71. package/dist/agent/prompts/debug-agent.js.map +1 -0
  72. package/dist/agent/prompts/desktop-addendum.d.ts +10 -0
  73. package/dist/agent/prompts/desktop-addendum.js +66 -0
  74. package/dist/agent/prompts/desktop-addendum.js.map +1 -0
  75. package/dist/agent/prompts/web-addendum.d.ts +9 -0
  76. package/dist/agent/prompts/web-addendum.js +70 -0
  77. package/dist/agent/prompts/web-addendum.js.map +1 -0
  78. package/dist/agent/provider.d.ts +17 -0
  79. package/dist/agent/provider.js +29 -0
  80. package/dist/agent/provider.js.map +1 -0
  81. package/dist/cli/control.d.ts +19 -0
  82. package/dist/cli/control.js +152 -0
  83. package/dist/cli/control.js.map +1 -0
  84. package/dist/cli/help.d.ts +9 -0
  85. package/dist/cli/help.js +41 -0
  86. package/dist/cli/help.js.map +1 -0
  87. package/dist/cli/init.d.ts +20 -0
  88. package/dist/cli/init.js +119 -0
  89. package/dist/cli/init.js.map +1 -0
  90. package/dist/config/load.d.ts +64 -0
  91. package/dist/config/load.js +105 -0
  92. package/dist/config/load.js.map +1 -0
  93. package/dist/config/schema.d.ts +105 -0
  94. package/dist/config/schema.js +62 -0
  95. package/dist/config/schema.js.map +1 -0
  96. package/dist/errors.d.ts +41 -0
  97. package/dist/errors.js +90 -0
  98. package/dist/errors.js.map +1 -0
  99. package/dist/findings/schema.d.ts +64 -0
  100. package/dist/findings/schema.js +27 -0
  101. package/dist/findings/schema.js.map +1 -0
  102. package/dist/index.d.ts +2 -0
  103. package/dist/index.js +4 -0
  104. package/dist/index.js.map +1 -0
  105. package/dist/main.d.ts +2 -0
  106. package/dist/main.js +95 -0
  107. package/dist/main.js.map +1 -0
  108. package/dist/mcp/server.d.ts +25 -0
  109. package/dist/mcp/server.js +31 -0
  110. package/dist/mcp/server.js.map +1 -0
  111. package/dist/mcp/tools/describe.d.ts +12 -0
  112. package/dist/mcp/tools/describe.js +32 -0
  113. package/dist/mcp/tools/describe.js.map +1 -0
  114. package/dist/mcp/tools/end-session.d.ts +11 -0
  115. package/dist/mcp/tools/end-session.js +27 -0
  116. package/dist/mcp/tools/end-session.js.map +1 -0
  117. package/dist/mcp/tools/get-findings.d.ts +12 -0
  118. package/dist/mcp/tools/get-findings.js +42 -0
  119. package/dist/mcp/tools/get-findings.js.map +1 -0
  120. package/dist/mcp/tools/index.d.ts +17 -0
  121. package/dist/mcp/tools/index.js +24 -0
  122. package/dist/mcp/tools/index.js.map +1 -0
  123. package/dist/mcp/tools/result.d.ts +10 -0
  124. package/dist/mcp/tools/result.js +20 -0
  125. package/dist/mcp/tools/result.js.map +1 -0
  126. package/dist/mcp/tools/send-message.d.ts +11 -0
  127. package/dist/mcp/tools/send-message.js +31 -0
  128. package/dist/mcp/tools/send-message.js.map +1 -0
  129. package/dist/mcp/tools/start-debug.d.ts +12 -0
  130. package/dist/mcp/tools/start-debug.js +50 -0
  131. package/dist/mcp/tools/start-debug.js.map +1 -0
  132. package/dist/services/debug-service.d.ts +133 -0
  133. package/dist/services/debug-service.js +163 -0
  134. package/dist/services/debug-service.js.map +1 -0
  135. package/dist/services/replay.d.ts +102 -0
  136. package/dist/services/replay.js +184 -0
  137. package/dist/services/replay.js.map +1 -0
  138. package/dist/services/session-builder.d.ts +65 -0
  139. package/dist/services/session-builder.js +198 -0
  140. package/dist/services/session-builder.js.map +1 -0
  141. package/dist/services/summarize.d.ts +59 -0
  142. package/dist/services/summarize.js +93 -0
  143. package/dist/services/summarize.js.map +1 -0
  144. package/dist/session/findings-store.d.ts +52 -0
  145. package/dist/session/findings-store.js +176 -0
  146. package/dist/session/findings-store.js.map +1 -0
  147. package/dist/session/manager.d.ts +47 -0
  148. package/dist/session/manager.js +66 -0
  149. package/dist/session/manager.js.map +1 -0
  150. package/dist/session/process-identity.d.ts +45 -0
  151. package/dist/session/process-identity.js +81 -0
  152. package/dist/session/process-identity.js.map +1 -0
  153. package/dist/session/session.d.ts +156 -0
  154. package/dist/session/session.js +309 -0
  155. package/dist/session/session.js.map +1 -0
  156. package/dist/session/state-file.d.ts +72 -0
  157. package/dist/session/state-file.js +104 -0
  158. package/dist/session/state-file.js.map +1 -0
  159. package/dist/session/workspace.d.ts +60 -0
  160. package/dist/session/workspace.js +75 -0
  161. package/dist/session/workspace.js.map +1 -0
  162. package/package.json +53 -0
@@ -0,0 +1,306 @@
1
+ /**
2
+ * Android adapter — drives an emulator/device over **ADB** behind the shared
3
+ * {@link Adapter} contract, so the agent loop stays adapter-blind.
4
+ *
5
+ * Composition (split per SRP — see siblings):
6
+ * - transport → {@link Adb} (`adb` subprocess seam, `adb.ts`)
7
+ * - read → {@link UiAutomatorSource} (`uiautomator dump` → view hierarchy, `uiautomator.ts`)
8
+ * - commands → pure argv builders (`input tap/text/swipe/keyevent`, `commands.ts`)
9
+ *
10
+ * **Managed or attach** (`idea/adapters.md`): with an `adbSerial` the adapter attaches
11
+ * to a running device and `close` is disconnect-only (never stops it); otherwise it
12
+ * boots the configured `emulator @avd`, waits for `sys.boot_completed`, and `close`
13
+ * stops it. Android is fully framework-driven — no vision needed for actions.
14
+ *
15
+ * `console` is logcat-backed (real crash/error signal); `network` has no ADB channel
16
+ * and throws loud ({@link AdapterError}). Every backend failure surfaces as an
17
+ * {@link AdapterError}; our own loud errors pass through un-rewrapped.
18
+ */
19
+ import { spawn } from 'node:child_process';
20
+ import { AdapterError, UiDebuggerError } from '../../errors.js';
21
+ import { AdbCli } from './adb.js';
22
+ import { centerOf, keyArgs, parseScreenSize, scrollSwipe, startArgs, swipeArgs, tapArgs, textArgs, } from './commands.js';
23
+ import { AdbUiAutomator, shapeNodes } from './uiautomator.js';
24
+ /** Default cap on `readState` so the tree stays small (overridable via `limit`). */
25
+ const DEFAULT_LIMIT = 200;
26
+ /** `waitFor` defaults — poll the hierarchy for a query until it appears or times out. */
27
+ const DEFAULT_WAIT_MS = 5000;
28
+ const POLL_MS = 300;
29
+ /** How long managed boot waits for `sys.boot_completed` before failing loud. */
30
+ const BOOT_WAIT_MS = 120_000;
31
+ /** Default logcat tail (lines) drained per `console` read. */
32
+ const LOGCAT_TAIL = 500;
33
+ const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
34
+ /** Android logcat priority letter → normalized console {@link ConsoleEntry} level. */
35
+ const LOGCAT_LEVEL = {
36
+ V: 'log',
37
+ D: 'debug',
38
+ I: 'info',
39
+ W: 'warn',
40
+ E: 'error',
41
+ F: 'error',
42
+ };
43
+ /**
44
+ * Parse `logcat -v epoch` output into {@link ConsoleEntry}s (oldest first, as emitted).
45
+ * Line shape: `1546300800.000 1000 1000 I Tag: message` — unmatched lines are skipped.
46
+ */
47
+ export function parseLogcat(raw) {
48
+ const out = [];
49
+ for (const line of raw.split('\n')) {
50
+ const match = /^\s*(\d+)\.(\d+)\s+\d+\s+\d+\s+([VDIWEF])\s+([^:]*):\s?(.*)$/.exec(line);
51
+ if (!match)
52
+ continue;
53
+ const [, sec, frac, priority, tag, text] = match;
54
+ if (sec === undefined || frac === undefined || priority === undefined || text === undefined) {
55
+ continue;
56
+ }
57
+ const location = (tag ?? '').trim();
58
+ out.push({
59
+ level: LOGCAT_LEVEL[priority] ?? 'log',
60
+ text,
61
+ location: location === '' ? undefined : location,
62
+ timestamp: Math.round(Number(`${sec}.${frac}`) * 1000),
63
+ });
64
+ }
65
+ return out;
66
+ }
67
+ /** Apply the whitelisted console `filters` (logcat). Loud on an unknown key or wrong type. */
68
+ export function applyLogFilters(entries, filters) {
69
+ if (!filters)
70
+ return entries;
71
+ let out = entries;
72
+ for (const [key, value] of Object.entries(filters)) {
73
+ switch (key) {
74
+ case 'level_eq': {
75
+ if (typeof value !== 'string')
76
+ throw new AdapterError('filter `level_eq` expects a string');
77
+ out = out.filter((e) => e.level === value);
78
+ break;
79
+ }
80
+ case 'level_in': {
81
+ if (!Array.isArray(value) || value.some((v) => typeof v !== 'string')) {
82
+ throw new AdapterError('filter `level_in` expects a string[]');
83
+ }
84
+ out = out.filter((e) => value.includes(e.level));
85
+ break;
86
+ }
87
+ case 'text_contains': {
88
+ if (typeof value !== 'string') {
89
+ throw new AdapterError('filter `text_contains` expects a string');
90
+ }
91
+ const needle = value.toLowerCase();
92
+ out = out.filter((e) => e.text.toLowerCase().includes(needle));
93
+ break;
94
+ }
95
+ default:
96
+ throw new AdapterError(`unknown filter \`${key}\` for android console (allowed: level_eq, level_in, text_contains)`);
97
+ }
98
+ }
99
+ return out;
100
+ }
101
+ /**
102
+ * The android {@link Adapter}: an ADB + uiautomator pair behind one contract.
103
+ * Construct via {@link AndroidAdapter.create}.
104
+ */
105
+ export class AndroidAdapter {
106
+ #config;
107
+ #adb;
108
+ #ui;
109
+ #attach;
110
+ #emulator = null;
111
+ #booted;
112
+ #screen = null;
113
+ constructor(handles) {
114
+ this.#config = handles.config;
115
+ this.#adb = handles.adb;
116
+ this.#ui = handles.ui;
117
+ this.#attach = handles.attach;
118
+ // Attach mode targets an already-running device — treat it as booted from the start.
119
+ this.#booted = handles.attach;
120
+ }
121
+ /** Wire the adapter from config: `adbSerial` → attach (`-s serial`), else managed emulator (`-e`). */
122
+ static create(init) {
123
+ const serial = init.config.adbSerial ?? null;
124
+ const attach = serial !== null;
125
+ const adb = init.adb ?? new AdbCli(serial !== null ? ['-s', serial] : ['-e']);
126
+ return new AndroidAdapter({
127
+ config: init.config,
128
+ adb,
129
+ ui: init.ui ?? new AdbUiAutomator(adb),
130
+ attach,
131
+ });
132
+ }
133
+ /** Ensure the device is up (managed: boot the emulator), then start the activity/package. */
134
+ async open(target) {
135
+ await this.#run('open', async () => {
136
+ await this.#ensureBooted();
137
+ if (target.trim() !== '')
138
+ await this.#adb.shell(startArgs(target));
139
+ });
140
+ }
141
+ async find(opts) {
142
+ return this.#run('find', async () => {
143
+ const nodes = await this.readState({ ...opts, limit: 1 });
144
+ return nodes[0] ?? null;
145
+ });
146
+ }
147
+ async readState(opts = {}) {
148
+ return this.#run('readState', async () => {
149
+ const region = opts.within !== undefined ? await this.#regionBounds(opts.within) : undefined;
150
+ const nodes = await this.#ui.dump();
151
+ return shapeNodes(nodes, opts, DEFAULT_LIMIT, region);
152
+ });
153
+ }
154
+ async click(target) {
155
+ await this.#run('click', async () => {
156
+ const { x, y } = centerOf((await this.#resolve(target)).bounds);
157
+ await this.#adb.shell(tapArgs(x, y));
158
+ });
159
+ }
160
+ async type(target, text) {
161
+ // Contract: focus the target first, then type. Tap its center to focus.
162
+ await this.#run('type', async () => {
163
+ const { x, y } = centerOf((await this.#resolve(target)).bounds);
164
+ await this.#adb.shell(tapArgs(x, y));
165
+ if (text !== '')
166
+ await this.#adb.shell(textArgs(text));
167
+ });
168
+ }
169
+ async pressKey(key) {
170
+ if (key.trim() === '')
171
+ throw new AdapterError('pressKey requires a non-empty key');
172
+ await this.#run('pressKey', async () => {
173
+ await this.#adb.shell(keyArgs(key));
174
+ });
175
+ }
176
+ async scroll(opts) {
177
+ await this.#run('scroll', async () => {
178
+ const area = opts.within !== undefined
179
+ ? await this.#regionBounds(opts.within)
180
+ : await this.#screenSize();
181
+ const { x1, y1, x2, y2 } = scrollSwipe(opts.direction, area, opts.amount);
182
+ await this.#adb.shell(swipeArgs(x1, y1, x2, y2));
183
+ });
184
+ }
185
+ async screenshot() {
186
+ return this.#run('screenshot', () => this.#adb.execOut(['screencap', '-p']));
187
+ }
188
+ async waitFor(opts) {
189
+ if (opts.networkIdle) {
190
+ throw new AdapterError('android: `networkIdle` wait is unsupported (no network channel)');
191
+ }
192
+ const query = opts.query;
193
+ if (!query) {
194
+ throw new AdapterError('waitFor requires `query` (android has no networkIdle)');
195
+ }
196
+ const timeout = opts.timeout ?? DEFAULT_WAIT_MS;
197
+ await this.#run('waitFor', async () => {
198
+ const start = Date.now();
199
+ for (;;) {
200
+ if (await this.find({ query }))
201
+ return;
202
+ if (Date.now() - start >= timeout) {
203
+ throw new AdapterError(`android: waitFor timed out after ${timeout}ms (${query})`);
204
+ }
205
+ await delay(POLL_MS);
206
+ }
207
+ });
208
+ }
209
+ /** Drain recent logcat as normalized console entries (newest first), narrowed by {@link LogQuery}. */
210
+ async console(opts = {}) {
211
+ return this.#run('console', async () => {
212
+ const tail = opts.limit ?? LOGCAT_TAIL;
213
+ // `-t N` dumps the most recent N lines and exits (implies `-d`); `-v epoch` → real timestamps.
214
+ const raw = await this.#adb.shell(['logcat', '-v', 'epoch', '-t', String(tail)]);
215
+ const entries = applyLogFilters(parseLogcat(raw).reverse(), opts.filters);
216
+ return opts.limit !== undefined ? entries.slice(0, opts.limit) : entries;
217
+ });
218
+ }
219
+ /** Android exposes no network channel over ADB — unsupported, surfaced loud. */
220
+ async network() {
221
+ throw new AdapterError('android target has no network channel over ADB (use a proxy; unsupported)');
222
+ }
223
+ /** Attach: disconnect-only (never stop the device). Managed: stop the emulator. */
224
+ async close() {
225
+ if (this.#attach)
226
+ return;
227
+ await this.#run('close', async () => {
228
+ if (this.#booted) {
229
+ // Best-effort console kill; the SIGTERM below is the hard backstop.
230
+ await this.#adb.adb(['emu', 'kill']).catch(() => undefined);
231
+ }
232
+ const pid = this.#emulator?.pid;
233
+ this.#emulator = null;
234
+ this.#booted = false;
235
+ if (pid === undefined)
236
+ return;
237
+ try {
238
+ // Negative pid → the whole detached group.
239
+ process.kill(-pid, 'SIGTERM');
240
+ }
241
+ catch (error) {
242
+ if (error.code !== 'ESRCH')
243
+ throw error;
244
+ }
245
+ });
246
+ }
247
+ /** Managed boot: launch `emulator @avd` (once) and poll `sys.boot_completed`. No-op when attached. */
248
+ async #ensureBooted() {
249
+ if (this.#booted)
250
+ return;
251
+ if (!this.#emulator) {
252
+ const bin = this.#config.emulatorPath ?? 'emulator';
253
+ this.#emulator = spawn(bin, [`@${this.#config.avd}`], { detached: true, stdio: 'ignore' });
254
+ }
255
+ await this.#adb.adb(['wait-for-device']);
256
+ const start = Date.now();
257
+ for (;;) {
258
+ const out = (await this.#adb.shell(['getprop', 'sys.boot_completed'])).trim();
259
+ if (out === '1')
260
+ break;
261
+ if (Date.now() - start >= BOOT_WAIT_MS) {
262
+ throw new AdapterError(`android: emulator @${this.#config.avd} did not boot within ${BOOT_WAIT_MS}ms`);
263
+ }
264
+ await delay(POLL_MS);
265
+ }
266
+ this.#booted = true;
267
+ }
268
+ /** Read (and cache) the device screen size for viewport scrolls. */
269
+ async #screenSize() {
270
+ if (this.#screen)
271
+ return this.#screen;
272
+ this.#screen = parseScreenSize(await this.#adb.shell(['wm', 'size']));
273
+ return this.#screen;
274
+ }
275
+ /** Resolve a {@link NodeRef} to a concrete {@link Node}, re-querying a selector. */
276
+ async #resolve(target) {
277
+ if (typeof target !== 'string')
278
+ return target;
279
+ const node = await this.find({ query: target });
280
+ if (!node) {
281
+ throw new AdapterError(`android: no element matched query ${JSON.stringify(target)}`);
282
+ }
283
+ return node;
284
+ }
285
+ /** Resolve a scope `within` (a {@link Node} or a selector) to an on-screen rectangle. */
286
+ async #regionBounds(within) {
287
+ if (typeof within !== 'string')
288
+ return within.bounds;
289
+ const node = await this.find({ query: within });
290
+ if (!node)
291
+ throw new AdapterError(`android: \`within\` target not found: ${within}`);
292
+ return node.bounds;
293
+ }
294
+ /** Run a backend call, re-throwing as a loud {@link AdapterError} (our own errors pass through). */
295
+ async #run(op, fn) {
296
+ try {
297
+ return await fn();
298
+ }
299
+ catch (error) {
300
+ if (error instanceof UiDebuggerError)
301
+ throw error;
302
+ throw new AdapterError(`android.${op} failed: ${error instanceof Error ? error.message : String(error)}`);
303
+ }
304
+ }
305
+ }
306
+ //# sourceMappingURL=android-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"android-adapter.js","sourceRoot":"","sources":["../../../src/adapters/android/android-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAqB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAchE,OAAO,EAAY,MAAM,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EACL,QAAQ,EACR,OAAO,EACP,eAAe,EACf,WAAW,EACX,SAAS,EACT,SAAS,EACT,OAAO,EACP,QAAQ,GACT,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,UAAU,EAA0B,MAAM,kBAAkB,CAAC;AAEtF,oFA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YAAY,CAAC,qCAAqC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACxF,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,yFAAyF;IACzF,KAAK,CAAC,aAAa,CAAC,MAAe;QACjC,IAAI,OAAO,MAAM,KAAK,QAAQ;YAAE,OAAO,MAAM,CAAC,MAAM,CAAC;QACrD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QAChD,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,YAAY,CAAC,yCAAyC,MAAM,EAAE,CAAC,CAAC;QACrF,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,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,59 @@
1
+ /**
2
+ * Android shell-command builders — the pure argv shapes the adapter sends over the
3
+ * {@link Adb} seam (`input tap/text/swipe/keyevent`, `am start`, `wm size`).
4
+ *
5
+ * Android needs no vision: actions are framework calls (`idea/desktop-control.md`).
6
+ * Each builder returns the `string[]` handed to `adb shell …`, keeping the real logic
7
+ * (text escaping, keycode mapping, swipe geometry) testable without spawning. The
8
+ * adapter is the thin runner that pipes these to ADB.
9
+ *
10
+ * Coordinates come from a {@link Node}'s `bounds` (uiautomator) — same screen-pixel
11
+ * space as `input tap`. Fails loud — an empty open target or an unknown key throws
12
+ * {@link AdapterError}, never a silent no-op.
13
+ */
14
+ import type { Bounds, ScrollDirection } from '../contract.js';
15
+ /** The integer screen-pixel center of a {@link Bounds} — where a tap/swipe lands. */
16
+ export declare function centerOf(bounds: Bounds): {
17
+ x: number;
18
+ y: number;
19
+ };
20
+ /**
21
+ * Build the `open` launch command. A component (`pkg/.Activity`) starts that activity
22
+ * directly (`am start -W`); a bare package launches its default activity via `monkey`.
23
+ */
24
+ export declare function startArgs(target: string): string[];
25
+ /** `input tap <x> <y>`. */
26
+ export declare function tapArgs(x: number, y: number): string[];
27
+ /**
28
+ * Escape text for `input text` on the device shell: spaces → `%s` (literal space token),
29
+ * and the shell-special chars get backslash-escaped so they reach the app verbatim.
30
+ */
31
+ export declare function escapeInputText(text: string): string;
32
+ /** `input text <escaped>` — types into the focused field. */
33
+ export declare function textArgs(text: string): string[];
34
+ /** `input swipe <x1> <y1> <x2> <y2> <ms>`. */
35
+ export declare function swipeArgs(x1: number, y1: number, x2: number, y2: number, durationMs?: number): string[];
36
+ /**
37
+ * Geometry for a `scroll` step: a finger swipe inside `area` (a region or the screen).
38
+ * The finger moves **opposite** the requested {@link ScrollDirection} — e.g. `down`
39
+ * (reveal lower content) swipes up. Distance is capped to 80% of the area's span.
40
+ */
41
+ export declare function scrollSwipe(direction: ScrollDirection, area: Bounds, amount?: number): {
42
+ x1: number;
43
+ y1: number;
44
+ x2: number;
45
+ y2: number;
46
+ };
47
+ /** Map one key token onto a `KEYCODE_*` name (alias · single letter/digit · verbatim KEYCODE_). */
48
+ export declare function keycodeFor(token: string): string;
49
+ /**
50
+ * Build the keyevent argv for a contract key/chord. A single key → `input keyevent
51
+ * <KEYCODE>`; a chord (`Control+a`) → `input keycombination <KEYCODE…>` (Android 11+).
52
+ */
53
+ export declare function keyArgs(key: string): string[];
54
+ /**
55
+ * Parse `wm size` output → a full-screen {@link Bounds}. Prefers an `Override size`
56
+ * (the effective resolution) when present, else `Physical size`.
57
+ * `Physical size: 1080x2400` · `Override size: 720x1280`
58
+ */
59
+ export declare function parseScreenSize(output: string): Bounds;
@@ -0,0 +1,178 @@
1
+ /**
2
+ * Android shell-command builders — the pure argv shapes the adapter sends over the
3
+ * {@link Adb} seam (`input tap/text/swipe/keyevent`, `am start`, `wm size`).
4
+ *
5
+ * Android needs no vision: actions are framework calls (`idea/desktop-control.md`).
6
+ * Each builder returns the `string[]` handed to `adb shell …`, keeping the real logic
7
+ * (text escaping, keycode mapping, swipe geometry) testable without spawning. The
8
+ * adapter is the thin runner that pipes these to ADB.
9
+ *
10
+ * Coordinates come from a {@link Node}'s `bounds` (uiautomator) — same screen-pixel
11
+ * space as `input tap`. Fails loud — an empty open target or an unknown key throws
12
+ * {@link AdapterError}, never a silent no-op.
13
+ */
14
+ import { AdapterError } from '../../errors.js';
15
+ /** Default swipe distance (px) for one `scroll` step when no `amount` is given. */
16
+ const DEFAULT_SCROLL_AMOUNT = 600;
17
+ /** Default swipe duration (ms) — slow enough to register as a scroll, not a fling. */
18
+ const DEFAULT_SWIPE_MS = 300;
19
+ /** The integer screen-pixel center of a {@link Bounds} — where a tap/swipe lands. */
20
+ export function centerOf(bounds) {
21
+ return {
22
+ x: Math.round(bounds.x + bounds.width / 2),
23
+ y: Math.round(bounds.y + bounds.height / 2),
24
+ };
25
+ }
26
+ // --- launch -----------------------------------------------------------------
27
+ /**
28
+ * Build the `open` launch command. A component (`pkg/.Activity`) starts that activity
29
+ * directly (`am start -W`); a bare package launches its default activity via `monkey`.
30
+ */
31
+ export function startArgs(target) {
32
+ const t = target.trim();
33
+ if (t === '') {
34
+ throw new AdapterError('android open requires an activity component (pkg/.Activity) or a package');
35
+ }
36
+ if (t.includes('/'))
37
+ return ['am', 'start', '-W', '-n', t];
38
+ return ['monkey', '-p', t, '-c', 'android.intent.category.LAUNCHER', '1'];
39
+ }
40
+ // --- tap / type / swipe -----------------------------------------------------
41
+ /** `input tap <x> <y>`. */
42
+ export function tapArgs(x, y) {
43
+ return ['input', 'tap', String(x), String(y)];
44
+ }
45
+ /**
46
+ * Escape text for `input text` on the device shell: spaces → `%s` (literal space token),
47
+ * and the shell-special chars get backslash-escaped so they reach the app verbatim.
48
+ */
49
+ export function escapeInputText(text) {
50
+ let out = '';
51
+ for (const ch of text) {
52
+ if (ch === ' ')
53
+ out += '%s';
54
+ else if ('()<>|;&*\\~"\'`$'.includes(ch))
55
+ out += `\\${ch}`;
56
+ else
57
+ out += ch;
58
+ }
59
+ return out;
60
+ }
61
+ /** `input text <escaped>` — types into the focused field. */
62
+ export function textArgs(text) {
63
+ return ['input', 'text', escapeInputText(text)];
64
+ }
65
+ /** `input swipe <x1> <y1> <x2> <y2> <ms>`. */
66
+ export function swipeArgs(x1, y1, x2, y2, durationMs = DEFAULT_SWIPE_MS) {
67
+ return ['input', 'swipe', String(x1), String(y1), String(x2), String(y2), String(durationMs)];
68
+ }
69
+ /**
70
+ * Geometry for a `scroll` step: a finger swipe inside `area` (a region or the screen).
71
+ * The finger moves **opposite** the requested {@link ScrollDirection} — e.g. `down`
72
+ * (reveal lower content) swipes up. Distance is capped to 80% of the area's span.
73
+ */
74
+ export function scrollSwipe(direction, area, amount) {
75
+ const { x: cx, y: cy } = centerOf(area);
76
+ const horizontal = direction === 'left' || direction === 'right';
77
+ const span = horizontal ? area.width : area.height;
78
+ const distance = Math.min(amount ?? DEFAULT_SCROLL_AMOUNT, Math.round(span * 0.8));
79
+ const half = Math.max(1, Math.round(distance / 2));
80
+ switch (direction) {
81
+ case 'down':
82
+ return { x1: cx, y1: cy + half, x2: cx, y2: cy - half };
83
+ case 'up':
84
+ return { x1: cx, y1: cy - half, x2: cx, y2: cy + half };
85
+ case 'left':
86
+ return { x1: cx - half, y1: cy, x2: cx + half, y2: cy };
87
+ case 'right':
88
+ return { x1: cx + half, y1: cy, x2: cx - half, y2: cy };
89
+ default: {
90
+ const unreachable = direction;
91
+ throw new AdapterError(`unknown scroll direction: ${JSON.stringify(unreachable)}`);
92
+ }
93
+ }
94
+ }
95
+ // --- keys -------------------------------------------------------------------
96
+ /** Contract key/modifier tokens → Android `KEYCODE_*` names (everything else maps below). */
97
+ const KEYCODE_ALIASES = {
98
+ enter: 'KEYCODE_ENTER',
99
+ return: 'KEYCODE_ENTER',
100
+ tab: 'KEYCODE_TAB',
101
+ space: 'KEYCODE_SPACE',
102
+ backspace: 'KEYCODE_DEL',
103
+ delete: 'KEYCODE_FORWARD_DEL',
104
+ del: 'KEYCODE_FORWARD_DEL',
105
+ escape: 'KEYCODE_ESCAPE',
106
+ esc: 'KEYCODE_ESCAPE',
107
+ back: 'KEYCODE_BACK',
108
+ home: 'KEYCODE_HOME',
109
+ menu: 'KEYCODE_MENU',
110
+ search: 'KEYCODE_SEARCH',
111
+ up: 'KEYCODE_DPAD_UP',
112
+ arrowup: 'KEYCODE_DPAD_UP',
113
+ down: 'KEYCODE_DPAD_DOWN',
114
+ arrowdown: 'KEYCODE_DPAD_DOWN',
115
+ left: 'KEYCODE_DPAD_LEFT',
116
+ arrowleft: 'KEYCODE_DPAD_LEFT',
117
+ right: 'KEYCODE_DPAD_RIGHT',
118
+ arrowright: 'KEYCODE_DPAD_RIGHT',
119
+ pageup: 'KEYCODE_PAGE_UP',
120
+ pagedown: 'KEYCODE_PAGE_DOWN',
121
+ control: 'KEYCODE_CTRL_LEFT',
122
+ ctrl: 'KEYCODE_CTRL_LEFT',
123
+ alt: 'KEYCODE_ALT_LEFT',
124
+ option: 'KEYCODE_ALT_LEFT',
125
+ shift: 'KEYCODE_SHIFT_LEFT',
126
+ meta: 'KEYCODE_META_LEFT',
127
+ cmd: 'KEYCODE_META_LEFT',
128
+ command: 'KEYCODE_META_LEFT',
129
+ super: 'KEYCODE_META_LEFT',
130
+ win: 'KEYCODE_META_LEFT',
131
+ };
132
+ /** Map one key token onto a `KEYCODE_*` name (alias · single letter/digit · verbatim KEYCODE_). */
133
+ export function keycodeFor(token) {
134
+ const lower = token.toLowerCase();
135
+ const mapped = KEYCODE_ALIASES[lower];
136
+ if (mapped)
137
+ return mapped;
138
+ if (/^[a-z]$/.test(lower))
139
+ return `KEYCODE_${lower.toUpperCase()}`;
140
+ if (/^[0-9]$/.test(lower))
141
+ return `KEYCODE_${lower}`;
142
+ if (/^keycode_[a-z0-9_]+$/i.test(token))
143
+ return token.toUpperCase();
144
+ throw new AdapterError(`android: unknown key ${JSON.stringify(token)}`);
145
+ }
146
+ /**
147
+ * Build the keyevent argv for a contract key/chord. A single key → `input keyevent
148
+ * <KEYCODE>`; a chord (`Control+a`) → `input keycombination <KEYCODE…>` (Android 11+).
149
+ */
150
+ export function keyArgs(key) {
151
+ const codes = key
152
+ .split('+')
153
+ .map((part) => part.trim())
154
+ .filter((part) => part.length > 0)
155
+ .map(keycodeFor);
156
+ if (codes.length === 0)
157
+ throw new AdapterError('pressKey requires a non-empty key');
158
+ return codes.length === 1
159
+ ? ['input', 'keyevent', ...codes]
160
+ : ['input', 'keycombination', ...codes];
161
+ }
162
+ // --- screen -----------------------------------------------------------------
163
+ /**
164
+ * Parse `wm size` output → a full-screen {@link Bounds}. Prefers an `Override size`
165
+ * (the effective resolution) when present, else `Physical size`.
166
+ * `Physical size: 1080x2400` · `Override size: 720x1280`
167
+ */
168
+ export function parseScreenSize(output) {
169
+ const override = /Override size:\s*(\d+)x(\d+)/.exec(output);
170
+ const match = override ?? /(\d+)x(\d+)/.exec(output);
171
+ const width = Number(match?.[1]);
172
+ const height = Number(match?.[2]);
173
+ if (!Number.isFinite(width) || !Number.isFinite(height)) {
174
+ throw new AdapterError(`android: cannot parse screen size from ${JSON.stringify(output)}`);
175
+ }
176
+ return { x: 0, y: 0, width, height };
177
+ }
178
+ //# sourceMappingURL=commands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands.js","sourceRoot":"","sources":["../../../src/adapters/android/commands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C,mFAAmF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AM,EAAE,CAAC;AACvC,CAAC"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Android read state — the **view hierarchy** via `uiautomator dump` (`idea/adapters.md`).
3
+ *
4
+ * Android hands you a structured tree for free (unlike the Linux desktop): `uiautomator
5
+ * dump` writes a flat XML of `<node>` elements, each carrying `class`, `text`,
6
+ * `content-desc`, `resource-id`, the boolean state flags, and a `bounds="[x1,y1][x2,y2]"`
7
+ * screen rectangle. We flatten every `<node>` and normalize it onto the contract
8
+ * {@link Node} (role from the widget class, name from text/desc, bounds parsed to a rect),
9
+ * then apply the shared SQL-like shaping (`query`/`filters`/`within`/`limit`).
10
+ *
11
+ * The dump is read robustly as **dump-to-file then `cat`** — uiautomator interleaves a
12
+ * status line on `/dev/tty`, so a file round-trip keeps the XML clean. Canvas/Compose
13
+ * surfaces that expose no hierarchy fall back to vision (future). Fails loud — a missing
14
+ * `<hierarchy>` or a malformed `bounds` throws {@link AdapterError}, never a silent guess.
15
+ *
16
+ * The parsers + filters here are pure and unit-tested; {@link AdbUiAutomator} is the
17
+ * integration-validated runner over the {@link Adb} seam.
18
+ */
19
+ import type { Bounds, Filters, Node, Query } from '../contract.js';
20
+ import type { Adb } from './adb.js';
21
+ /** A node plus the internal flags backing android filters + query (dropped from the public {@link Node}). */
22
+ export interface AndroidNode extends Node {
23
+ clickable: boolean;
24
+ scrollable: boolean;
25
+ focusable: boolean;
26
+ /** `resource-id` (e.g. `com.app:id/submit`) — matched by the `query` and `id_contains` filter. */
27
+ resourceId: string;
28
+ }
29
+ /** The read seam the adapter depends on — implemented by {@link AdbUiAutomator}, faked in tests. */
30
+ export interface UiAutomatorSource {
31
+ dump(): Promise<AndroidNode[]>;
32
+ }
33
+ /** Whitelisted `filters` keys for android nodes — anything else is rejected, not ignored. */
34
+ export declare const ANDROID_FILTER_KEYS: readonly ["enabled_eq", "clickable_eq", "scrollable_eq", "role_in", "name_contains", "id_contains"];
35
+ /** Normalize an android widget class to a contract role; unknown classes pass through cleaned. */
36
+ export declare function mapAndroidRole(className: string): string;
37
+ /** Decode the five XML entities (`&amp;` last so already-decoded `&` is not re-decoded). */
38
+ export declare function unescapeXml(value: string): string;
39
+ /** Parse a `<node …>` opening tag's `key="value"` attributes (values XML-unescaped). */
40
+ export declare function parseAttrs(tag: string): Record<string, string>;
41
+ /** Decode a uiautomator `bounds="[x1,y1][x2,y2]"` string → screen {@link Bounds}. */
42
+ export declare function parseBounds(raw: string): Bounds;
43
+ /** Build an {@link AndroidNode} from one node's parsed attributes (name = text → content-desc). */
44
+ export declare function toAndroidNode(attrs: Record<string, string>): AndroidNode;
45
+ /**
46
+ * Flatten a `uiautomator dump` XML into {@link AndroidNode}s — every `<node>` opening
47
+ * tag (container or self-closing), in document order. Throws if no `<hierarchy>` root.
48
+ */
49
+ export declare function parseHierarchy(xml: string): AndroidNode[];
50
+ /** A parsed agent query: an optional role and/or a name/id substring. */
51
+ export interface ParsedQuery {
52
+ role?: string;
53
+ name?: string;
54
+ }
55
+ /** Parse an agent target (`button "Save"` or plain `Save` / a resource-id) into a {@link ParsedQuery}. */
56
+ export declare function parseAndroidQuery(raw: string): ParsedQuery;
57
+ /** True when a node satisfies a {@link ParsedQuery} (role exact; name matches text/desc OR resource-id). */
58
+ export declare function matchesAndroidNode(node: AndroidNode, parsed: ParsedQuery): boolean;
59
+ /**
60
+ * Apply the whitelisted node `filters` in JS. Throws {@link AdapterError} on an unknown
61
+ * key (no silent injection surface) or a wrong value type.
62
+ */
63
+ export declare function applyAndroidFilters(nodes: AndroidNode[], filters?: Filters): AndroidNode[];
64
+ /** Drop the internal flags — the public contract returns plain {@link Node}s. */
65
+ export declare function toNode(node: AndroidNode): Node;
66
+ /** True when a node's center sits inside `region` — used to scope a read by `within`. */
67
+ export declare function centerWithin(node: Node, region: Bounds): boolean;
68
+ /**
69
+ * Scope, query-match, filter and cap a dumped tree onto contract {@link Node}s — the
70
+ * shared shaping `readState`/`find` apply after the adapter-side dump.
71
+ */
72
+ export declare function shapeNodes(nodes: AndroidNode[], opts: Query, defaultLimit?: number, region?: Bounds): Node[];
73
+ /**
74
+ * {@link UiAutomatorSource} backed by the {@link Adb} seam. Dumps to a device file then
75
+ * `cat`s it (clean XML, no `/dev/tty` interleaving) and parses with {@link parseHierarchy}.
76
+ */
77
+ export declare class AdbUiAutomator implements UiAutomatorSource {
78
+ #private;
79
+ constructor(adb: Adb);
80
+ dump(): Promise<AndroidNode[]>;
81
+ }