Commit 442ab59
authored
refactor(8/12): migrate UI automation tools to event-based handlers (#326)
## Summary
This is **PR 8 of 12** in a stacked PR series that decouples the rendering pipeline from MCP transport. Depends on PR 7 (device/macOS migrations).
Migrates all UI automation tool handlers to the new event-based handler contract.
### Tools migrated (25 files)
`button`, `gesture`, `key_press`, `key_sequence`, `long_press`, `screenshot`, `snapshot_ui`, `swipe`, `tap`, `touch`, `type_text`
### Notable changes
- **Shared AXe command module** (`src/mcp/tools/ui-automation/shared/axe-command.ts`): Extracted common AXe CLI invocation logic that was duplicated across all 11 UI automation tools. Each tool had its own copy of AXe process spawning, timeout handling, and error formatting. Now consolidated into one shared module that accepts an `emit` callback.
- `axe-helpers.ts` and `axe/index.ts`: Minor updates to work with the shared command module.
- `screenshot.ts`: Uses `ctx.attach()` for image data instead of constructing `ToolResponseContent` directly. This is the only tool that produces non-text output.
### Pattern
UI automation tools are simpler than build tools -- they invoke AXe, parse the response, and emit result events. The main simplification is removing the per-tool AXe boilerplate:
\`\`\`typescript
// Before: each tool had ~30 lines of AXe setup
const axeResult = await executeAxeCommand({ ... });
return toolResponse([...formatResult(axeResult)]);
// After: shared module handles AXe setup
await executeAxeAction(ctx, { ... });
ctx.emit(statusLine('success', '...'));
\`\`\`
## Stack navigation
- PR 1-5/12: Foundation, utilities, runtime contract
- PR 6-7/12: Simulator, device, macOS migrations
- **PR 8/12** (this PR): UI automation tool migrations
- PR 9/12: Remaining tool migrations
- PR 10-12/12: Boundaries, config, tests
## Test plan
- [ ] `npx vitest run` passes -- all UI automation tool tests updated
- [ ] Screenshot tool correctly uses `ctx.attach()` for image data
- [ ] Shared AXe command module correctly propagates errors via events1 parent 7317fb4 commit 442ab59
File tree
26 files changed
+2299
-3766
lines changed- src
- mcp/tools/ui-automation
- __tests__
- utils
- axe
- debugger
26 files changed
+2299
-3766
lines changedLarge diffs are not rendered by default.
Large diffs are not rendered by default.
Lines changed: 121 additions & 149 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | 1 | | |
6 | 2 | | |
7 | 3 | | |
| |||
13 | 9 | | |
14 | 10 | | |
15 | 11 | | |
| 12 | + | |
| 13 | + | |
16 | 14 | | |
17 | 15 | | |
18 | 16 | | |
19 | 17 | | |
20 | 18 | | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | 19 | | |
31 | 20 | | |
32 | 21 | | |
| |||
98 | 87 | | |
99 | 88 | | |
100 | 89 | | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
108 | 99 | | |
109 | 100 | | |
110 | 101 | | |
| |||
130 | 121 | | |
131 | 122 | | |
132 | 123 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
141 | 134 | | |
142 | 135 | | |
143 | 136 | | |
| |||
165 | 158 | | |
166 | 159 | | |
167 | 160 | | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
175 | 170 | | |
176 | 171 | | |
177 | 172 | | |
| |||
198 | 193 | | |
199 | 194 | | |
200 | 195 | | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | 196 | | |
211 | 197 | | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
219 | 207 | | |
220 | 208 | | |
221 | 209 | | |
| |||
241 | 229 | | |
242 | 230 | | |
243 | 231 | | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
251 | 241 | | |
252 | 242 | | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
| 243 | + | |
| 244 | + | |
257 | 245 | | |
258 | 246 | | |
259 | 247 | | |
| |||
265 | 253 | | |
266 | 254 | | |
267 | 255 | | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
276 | 266 | | |
277 | 267 | | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
| 268 | + | |
| 269 | + | |
282 | 270 | | |
283 | 271 | | |
284 | 272 | | |
285 | 273 | | |
286 | 274 | | |
287 | 275 | | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | 276 | | |
298 | 277 | | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
| 278 | + | |
| 279 | + | |
310 | 280 | | |
311 | | - | |
312 | | - | |
| 281 | + | |
| 282 | + | |
313 | 283 | | |
314 | | - | |
315 | | - | |
316 | | - | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
317 | 291 | | |
318 | 292 | | |
319 | 293 | | |
| |||
325 | 299 | | |
326 | 300 | | |
327 | 301 | | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
| 302 | + | |
| 303 | + | |
339 | 304 | | |
340 | | - | |
341 | | - | |
| 305 | + | |
| 306 | + | |
342 | 307 | | |
343 | | - | |
344 | | - | |
345 | | - | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
346 | 317 | | |
347 | 318 | | |
348 | 319 | | |
| |||
352 | 323 | | |
353 | 324 | | |
354 | 325 | | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
362 | 335 | | |
363 | 336 | | |
364 | 337 | | |
365 | | - | |
366 | | - | |
| 338 | + | |
| 339 | + | |
367 | 340 | | |
368 | 341 | | |
369 | 342 | | |
| |||
374 | 347 | | |
375 | 348 | | |
376 | 349 | | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
384 | 359 | | |
385 | 360 | | |
386 | 361 | | |
387 | | - | |
388 | | - | |
| 362 | + | |
| 363 | + | |
389 | 364 | | |
390 | 365 | | |
391 | 366 | | |
| |||
396 | 371 | | |
397 | 372 | | |
398 | 373 | | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
| 374 | + | |
| 375 | + | |
410 | 376 | | |
411 | | - | |
412 | | - | |
| 377 | + | |
| 378 | + | |
413 | 379 | | |
414 | | - | |
415 | | - | |
416 | | - | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
417 | 389 | | |
418 | 390 | | |
419 | 391 | | |
0 commit comments