@developerz.ai/ui-debugger-mcp 1.8.0 → 1.10.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 (205) hide show
  1. package/README.md +70 -52
  2. package/dist/adapters/android/adb.d.ts +19 -7
  3. package/dist/adapters/android/adb.js +50 -13
  4. package/dist/adapters/android/adb.js.map +1 -1
  5. package/dist/adapters/android/android-adapter.d.ts +42 -2
  6. package/dist/adapters/android/android-adapter.js +366 -36
  7. package/dist/adapters/android/android-adapter.js.map +1 -1
  8. package/dist/adapters/android/commands.js.map +1 -1
  9. package/dist/adapters/android/ports.js.map +1 -1
  10. package/dist/adapters/android/sdk.d.ts +65 -0
  11. package/dist/adapters/android/sdk.js +107 -0
  12. package/dist/adapters/android/sdk.js.map +1 -0
  13. package/dist/adapters/android/uiautomator.d.ts +23 -7
  14. package/dist/adapters/android/uiautomator.js +31 -7
  15. package/dist/adapters/android/uiautomator.js.map +1 -1
  16. package/dist/adapters/availability.d.ts +39 -0
  17. package/dist/adapters/availability.js +62 -0
  18. package/dist/adapters/availability.js.map +1 -0
  19. package/dist/adapters/browser/browser-adapter.d.ts +12 -22
  20. package/dist/adapters/browser/browser-adapter.js +133 -67
  21. package/dist/adapters/browser/browser-adapter.js.map +1 -1
  22. package/dist/adapters/browser/cdp.d.ts +15 -7
  23. package/dist/adapters/browser/cdp.js +25 -3
  24. package/dist/adapters/browser/cdp.js.map +1 -1
  25. package/dist/adapters/browser/filters.d.ts +1 -1
  26. package/dist/adapters/browser/filters.js.map +1 -1
  27. package/dist/adapters/browser/geometry.js.map +1 -1
  28. package/dist/adapters/browser/launch.d.ts +14 -5
  29. package/dist/adapters/browser/launch.js +14 -5
  30. package/dist/adapters/browser/launch.js.map +1 -1
  31. package/dist/adapters/browser/lifecycle.d.ts +58 -0
  32. package/dist/adapters/browser/lifecycle.js +98 -0
  33. package/dist/adapters/browser/lifecycle.js.map +1 -0
  34. package/dist/adapters/browser/log-filters.d.ts +2 -2
  35. package/dist/adapters/browser/log-filters.js.map +1 -1
  36. package/dist/adapters/browser/log-format.d.ts +14 -23
  37. package/dist/adapters/browser/log-format.js +16 -55
  38. package/dist/adapters/browser/log-format.js.map +1 -1
  39. package/dist/adapters/browser/tab-context.d.ts +30 -0
  40. package/dist/adapters/browser/tab-context.js +41 -0
  41. package/dist/adapters/browser/tab-context.js.map +1 -0
  42. package/dist/adapters/contract.d.ts +111 -5
  43. package/dist/adapters/contract.js +7 -2
  44. package/dist/adapters/contract.js.map +1 -1
  45. package/dist/adapters/desktop/atspi-busctl.d.ts +26 -0
  46. package/dist/adapters/desktop/atspi-busctl.js +330 -0
  47. package/dist/adapters/desktop/atspi-busctl.js.map +1 -0
  48. package/dist/adapters/desktop/atspi-parse.d.ts +39 -0
  49. package/dist/adapters/desktop/atspi-parse.js +155 -0
  50. package/dist/adapters/desktop/atspi-parse.js.map +1 -0
  51. package/dist/adapters/desktop/atspi.d.ts +75 -50
  52. package/dist/adapters/desktop/atspi.js +64 -285
  53. package/dist/adapters/desktop/atspi.js.map +1 -1
  54. package/dist/adapters/desktop/capture.d.ts +11 -20
  55. package/dist/adapters/desktop/capture.js +68 -37
  56. package/dist/adapters/desktop/capture.js.map +1 -1
  57. package/dist/adapters/desktop/desktop-adapter.d.ts +20 -2
  58. package/dist/adapters/desktop/desktop-adapter.js +91 -9
  59. package/dist/adapters/desktop/desktop-adapter.js.map +1 -1
  60. package/dist/adapters/desktop/input.d.ts +18 -4
  61. package/dist/adapters/desktop/input.js +15 -10
  62. package/dist/adapters/desktop/input.js.map +1 -1
  63. package/dist/adapters/desktop/proc.d.ts +32 -4
  64. package/dist/adapters/desktop/proc.js +33 -6
  65. package/dist/adapters/desktop/proc.js.map +1 -1
  66. package/dist/adapters/factory.d.ts +12 -5
  67. package/dist/adapters/factory.js +29 -3
  68. package/dist/adapters/factory.js.map +1 -1
  69. package/dist/adapters/log-format.d.ts +32 -0
  70. package/dist/adapters/log-format.js +39 -0
  71. package/dist/adapters/log-format.js.map +1 -0
  72. package/dist/agent/belt/act.d.ts +440 -21
  73. package/dist/agent/belt/act.js +43 -6
  74. package/dist/agent/belt/act.js.map +1 -1
  75. package/dist/agent/belt/look.d.ts +471 -14
  76. package/dist/agent/belt/look.js +74 -12
  77. package/dist/agent/belt/look.js.map +1 -1
  78. package/dist/agent/belt/observe.d.ts +663 -42
  79. package/dist/agent/belt/observe.js +76 -12
  80. package/dist/agent/belt/observe.js.map +1 -1
  81. package/dist/agent/belt/report.d.ts +754 -48
  82. package/dist/agent/belt/report.js +121 -38
  83. package/dist/agent/belt/report.js.map +1 -1
  84. package/dist/agent/belt/trail.d.ts +44 -16
  85. package/dist/agent/belt/trail.js +46 -11
  86. package/dist/agent/belt/trail.js.map +1 -1
  87. package/dist/agent/capabilities.js.map +1 -1
  88. package/dist/agent/fallback.d.ts +33 -0
  89. package/dist/agent/fallback.js +84 -0
  90. package/dist/agent/fallback.js.map +1 -0
  91. package/dist/agent/loop.d.ts +54 -52
  92. package/dist/agent/loop.js +173 -176
  93. package/dist/agent/loop.js.map +1 -1
  94. package/dist/agent/models.d.ts +10 -6
  95. package/dist/agent/models.js +15 -9
  96. package/dist/agent/models.js.map +1 -1
  97. package/dist/agent/prompts/compose.d.ts +1 -1
  98. package/dist/agent/prompts/debug-agent.js +45 -8
  99. package/dist/agent/prompts/debug-agent.js.map +1 -1
  100. package/dist/agent/prompts/web-addendum.d.ts +1 -1
  101. package/dist/agent/prompts/web-addendum.js +15 -3
  102. package/dist/agent/prompts/web-addendum.js.map +1 -1
  103. package/dist/agent/provider.d.ts +38 -0
  104. package/dist/agent/provider.js +55 -3
  105. package/dist/agent/provider.js.map +1 -1
  106. package/dist/boot.d.ts +64 -0
  107. package/dist/boot.js +145 -0
  108. package/dist/boot.js.map +1 -0
  109. package/dist/cli/chromium-libs.d.ts +262 -0
  110. package/dist/cli/chromium-libs.js +522 -0
  111. package/dist/cli/chromium-libs.js.map +1 -0
  112. package/dist/cli/control.js +51 -9
  113. package/dist/cli/control.js.map +1 -1
  114. package/dist/cli/help.js +1 -1
  115. package/dist/cli/init.d.ts +54 -3
  116. package/dist/cli/init.js +89 -24
  117. package/dist/cli/init.js.map +1 -1
  118. package/dist/config/fingerprint.d.ts +6 -1
  119. package/dist/config/fingerprint.js +8 -4
  120. package/dist/config/fingerprint.js.map +1 -1
  121. package/dist/config/load.d.ts +50 -10
  122. package/dist/config/load.js +93 -27
  123. package/dist/config/load.js.map +1 -1
  124. package/dist/config/schema.d.ts +18 -6
  125. package/dist/config/schema.js +22 -7
  126. package/dist/config/schema.js.map +1 -1
  127. package/dist/errors.d.ts +14 -0
  128. package/dist/errors.js +18 -0
  129. package/dist/errors.js.map +1 -1
  130. package/dist/findings/schema.d.ts +44 -6
  131. package/dist/findings/schema.js +39 -3
  132. package/dist/findings/schema.js.map +1 -1
  133. package/dist/index.d.ts +1 -1
  134. package/dist/index.js +1 -1
  135. package/dist/index.js.map +1 -1
  136. package/dist/main.js +4 -76
  137. package/dist/main.js.map +1 -1
  138. package/dist/mcp/server.js.map +1 -1
  139. package/dist/mcp/tools/describe.d.ts +5 -4
  140. package/dist/mcp/tools/describe.js +14 -10
  141. package/dist/mcp/tools/describe.js.map +1 -1
  142. package/dist/mcp/tools/end-session.d.ts +3 -1
  143. package/dist/mcp/tools/end-session.js +7 -3
  144. package/dist/mcp/tools/end-session.js.map +1 -1
  145. package/dist/mcp/tools/output.d.ts +5 -4
  146. package/dist/mcp/tools/output.js +10 -2
  147. package/dist/mcp/tools/output.js.map +1 -1
  148. package/dist/mcp/tools/result.d.ts +10 -1
  149. package/dist/mcp/tools/result.js +8 -6
  150. package/dist/mcp/tools/result.js.map +1 -1
  151. package/dist/mcp/tools/start-debug.js +7 -5
  152. package/dist/mcp/tools/start-debug.js.map +1 -1
  153. package/dist/redact.d.ts +28 -0
  154. package/dist/redact.js +51 -0
  155. package/dist/redact.js.map +1 -0
  156. package/dist/services/catalog.d.ts +28 -0
  157. package/dist/services/catalog.js +65 -0
  158. package/dist/services/catalog.js.map +1 -0
  159. package/dist/services/debug-api.d.ts +172 -0
  160. package/dist/services/debug-api.js +9 -0
  161. package/dist/services/debug-api.js.map +1 -0
  162. package/dist/services/debug-service.d.ts +25 -173
  163. package/dist/services/debug-service.js +108 -175
  164. package/dist/services/debug-service.js.map +1 -1
  165. package/dist/services/login.d.ts +7 -2
  166. package/dist/services/login.js +210 -10
  167. package/dist/services/login.js.map +1 -1
  168. package/dist/services/retained-snapshot.d.ts +36 -0
  169. package/dist/services/retained-snapshot.js +63 -0
  170. package/dist/services/retained-snapshot.js.map +1 -0
  171. package/dist/services/session-builder.d.ts +26 -0
  172. package/dist/services/session-builder.js +46 -19
  173. package/dist/services/session-builder.js.map +1 -1
  174. package/dist/services/start-guards.d.ts +32 -0
  175. package/dist/services/start-guards.js +50 -0
  176. package/dist/services/start-guards.js.map +1 -0
  177. package/dist/services/summarize.d.ts +12 -3
  178. package/dist/services/summarize.js +13 -5
  179. package/dist/services/summarize.js.map +1 -1
  180. package/dist/session/cleanup.js.map +1 -1
  181. package/dist/session/findings-store.d.ts +2 -1
  182. package/dist/session/findings-store.js +30 -2
  183. package/dist/session/findings-store.js.map +1 -1
  184. package/dist/session/live-pointer.d.ts +19 -0
  185. package/dist/session/live-pointer.js +41 -0
  186. package/dist/session/live-pointer.js.map +1 -0
  187. package/dist/session/manager.d.ts +11 -1
  188. package/dist/session/manager.js +46 -2
  189. package/dist/session/manager.js.map +1 -1
  190. package/dist/session/owner-lock.d.ts +208 -0
  191. package/dist/session/owner-lock.js +499 -0
  192. package/dist/session/owner-lock.js.map +1 -0
  193. package/dist/session/process-identity.js.map +1 -1
  194. package/dist/session/session.js +61 -7
  195. package/dist/session/session.js.map +1 -1
  196. package/dist/session/state-file.d.ts +74 -14
  197. package/dist/session/state-file.js +203 -21
  198. package/dist/session/state-file.js.map +1 -1
  199. package/package.json +7 -7
  200. package/dist/adapters/android/android-adapter.test-helpers.d.ts +0 -52
  201. package/dist/adapters/android/android-adapter.test-helpers.js +0 -115
  202. package/dist/adapters/android/android-adapter.test-helpers.js.map +0 -1
  203. package/dist/mcp/server.test-helpers.d.ts +0 -23
  204. package/dist/mcp/server.test-helpers.js +0 -49
  205. package/dist/mcp/server.test-helpers.js.map +0 -1
@@ -5,8 +5,13 @@
5
5
  * same small interface, so the debug agent's loop is **adapter-blind**: the
6
6
  * inner tool belt (`observe`/`act`/`look`) hits these methods and never learns
7
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.
8
+ * the view hierarchy — all three normalize to the {@link Node} shape below, and
9
+ * each adapter exposes exactly ONE structured tree (DOM / AT-SPI / uiautomator).
10
+ * There is no automatic vision/OCR fallback in this contract, and the adapter
11
+ * never switches to pixels: a read yields tree nodes or nothing. `screenshot`
12
+ * only captures a frame — for evidence, and for the agent-level `look` belt
13
+ * call, the one path by which pixels reach a model. `look` describes and judges
14
+ * a frame; it never yields elements an adapter could find, click or type into.
10
15
  *
11
16
  * Reads are **SQL-like**, not RPC: a handful of verbs with composable params
12
17
  * (`query`/`fields`/`filters`/`limit`/`within`) — see {@link Query}. The belt's
@@ -152,6 +157,15 @@ export interface ConsoleEntry {
152
157
  location?: string;
153
158
  /** Capture time, ms since epoch. */
154
159
  timestamp: number;
160
+ /**
161
+ * Stable label of the tab that produced the row (`tab-1`, `tab-2`, …).
162
+ *
163
+ * The label follows the PAGE for the whole run: it survives a tab switch and
164
+ * a closing tab shifting the positional indices, so the index a driver passes
165
+ * to `switch_tab` never has to name a tab. Absent on targets that have no
166
+ * tabs (desktop, mobile).
167
+ */
168
+ tab?: string;
155
169
  }
156
170
  /** One network exchange captured from the target (CDP responses + failures). */
157
171
  export interface NetworkEntry {
@@ -196,23 +210,88 @@ export interface NetworkEntry {
196
210
  * (and from there, logs, findings, and the caller's transcript).
197
211
  */
198
212
  responseHeaders?: Record<string, string>;
213
+ /**
214
+ * Stable label of the tab that produced the exchange (`tab-1`, `tab-2`, …).
215
+ *
216
+ * Stamped when the response FIRED, not when its log line is written: the line
217
+ * lands only after the body/header await resolves, and by then the driver may
218
+ * have switched tabs. Same rationale as {@link ConsoleEntry.tab}.
219
+ */
220
+ tab?: string;
199
221
  }
222
+ /**
223
+ * Where captured console/network lines are streamed — the seam between an
224
+ * adapter's capture and the run's durable log trail.
225
+ *
226
+ * Declared HERE, in the contract, because two adapters stream to it (the browser's
227
+ * CDP capture and the android logcat drain): a second declaration would be a second
228
+ * type identity for the same seam. `browser/cdp.ts` re-exports it, so every reader
229
+ * of the capture channel keeps its import path.
230
+ */
231
+ export type CaptureSink = (channel: 'console' | 'network', line: string) => void;
200
232
  /** One open tab/window of a multi-tab target (web). */
201
233
  export interface TabInfo {
202
234
  /** Position in the target's tab list — what {@link Adapter.selectTab} takes. */
203
235
  index: number;
204
- /** Current URL of the tab. */
236
+ /**
237
+ * Current URL of the tab. Credential-bearing query values (`?code=`,
238
+ * `?token=`, `?signature=`, …) are redacted to `<redacted, N chars>` before
239
+ * the URL is returned — the same posture as {@link NetworkEntry.url} and
240
+ * unrequested loads — so tab listings are safe to surface. Any future
241
+ * `tabs()` implementation must keep this guarantee.
242
+ */
205
243
  url: string;
206
244
  /** Document title, empty while a fresh tab is still loading. */
207
245
  title: string;
208
- /** Whether this is the tab the adapter currently drives. */
246
+ /**
247
+ * Stable label of this tab (`tab-1`, `tab-2`, …) — the same marker the
248
+ * console/network rows carry, so a `[tab-2]` line in the durable log resolves
249
+ * to the tab that produced it. The label follows the PAGE, so it stays valid
250
+ * after an earlier tab closes and the indices shift. Absent when the target
251
+ * has no tab registry.
252
+ */
253
+ id?: string;
254
+ /** Whether this is the tab the adapter currently drives, independent of visibility. */
209
255
  active: boolean;
256
+ /** Live document.visibilityState === 'visible', when measured; not OS-window focus. */
257
+ visible?: boolean;
210
258
  }
259
+ /**
260
+ * Which selector grammar a target's `find({query})` parses — and therefore which
261
+ * grammar the belt must EMIT, since the driver copies a node's `target` verbatim
262
+ * into `act`.
263
+ *
264
+ * - `web` — Playwright engines (`data-testid="…"`, `role=button[name="…" i]`,
265
+ * `text=…`, `>> nth=N`), normalized by `adapters/browser/query.ts`.
266
+ * - `native` — the desktop (AT-SPI) and android (uiautomator) parsers, which take
267
+ * exactly two shapes and NOTHING else: `role "name"`, or a bare substring. The
268
+ * substring matches the node's name on desktop, and the node's name OR its
269
+ * `resource-id` on android — so a bare `resource-id` (android's `testid`)
270
+ * resolves there too. An engine-prefixed web selector degrades to a literal
271
+ * substring, matches nothing, and `act` throws `no element matched …`.
272
+ *
273
+ * DECLARED per adapter ({@link Adapter.selectorDialect}) — never inferred from
274
+ * the optional `tabs` capability, which says nothing about the grammar a target
275
+ * parses.
276
+ */
277
+ export type SelectorDialect = 'web' | 'native';
211
278
  /**
212
279
  * One contract, three protocols. The agent loop calls only these methods; each
213
280
  * adapter wires them to its real backend (CDP / X11-Wayland / ADB).
214
281
  */
215
282
  export interface Adapter {
283
+ /**
284
+ * The selector grammar this adapter's `find`/`click`/`type` parse — DECLARED,
285
+ * never inferred.
286
+ *
287
+ * The belt emits every tree node's `target` in this dialect and the driver
288
+ * copies it verbatim, so a target in the wrong dialect makes every click and
289
+ * type fail. It used to be inferred from {@link Adapter.tabs}, which is a
290
+ * CAPABILITY, not a dialect marker: a target that grows a tab listing must not
291
+ * silently switch the grammar the belt hands the driver. A missing or unknown
292
+ * declaration now fails loud rather than falling back to `web`.
293
+ */
294
+ readonly selectorDialect: SelectorDialect;
216
295
  /**
217
296
  * Go to the app: navigate to a URL (web) · launch/focus the window (desktop) · start the activity (android).
218
297
  *
@@ -258,6 +337,9 @@ export interface Adapter {
258
337
  * List the target's open tabs, newest last. OPTIONAL — implemented by targets
259
338
  * that have a tab concept (web); absent elsewhere, and the belt says so rather
260
339
  * than pretending a single-window target has one tab.
340
+ *
341
+ * A CAPABILITY, not a dialect marker: it says nothing about
342
+ * {@link Adapter.selectorDialect}, which every adapter declares on its own.
261
343
  */
262
344
  tabs?(): Promise<TabInfo[]>;
263
345
  /**
@@ -266,6 +348,30 @@ export interface Adapter {
266
348
  * Throws when the index names no open tab.
267
349
  */
268
350
  selectTab?(index: number): Promise<void>;
269
- /** Release the target: stop a **managed** process; for **attach**, disconnect only — never stop it. */
351
+ /**
352
+ * URLs of full-document loads the driven target performed on its own, oldest
353
+ * first — DRAINED by reading, so each caller gets only what happened since the
354
+ * last read. OPTIONAL: implemented by targets with a document concept (web).
355
+ *
356
+ * A new document wipes every bit of in-page state, and nothing on screen says
357
+ * so: a form that submits without `preventDefault`, a click on a plain link,
358
+ * a session that expires into a redirect. The driver reads the fresh page,
359
+ * finds its own earlier work undone, and reports the action it just took as
360
+ * having done nothing — or, worse, as having worked. The queue is what lets
361
+ * the belt say "the page reloaded" on the step that caused it.
362
+ *
363
+ * {@link open} drains its own load before returning, so a navigation the
364
+ * driver ASKED for never surfaces here — what is left is exactly the surprise.
365
+ *
366
+ * Returned URLs are credential-redacted (a query secret like `?code=`/`?token=`
367
+ * becomes `<redacted, N chars>`): this list reaches the model's context and the
368
+ * durable findings, the same posture the network capture holds for its URLs.
369
+ */
370
+ takeUnrequestedLoads?(): Promise<string[]>;
371
+ /**
372
+ * Release the target: stop a **managed** process; for **attach**, disconnect
373
+ * only — never stop it. The web adapter first returns an adopted tab to its
374
+ * pre-run URL (best-effort).
375
+ */
270
376
  close(): Promise<void>;
271
377
  }
@@ -5,8 +5,13 @@
5
5
  * same small interface, so the debug agent's loop is **adapter-blind**: the
6
6
  * inner tool belt (`observe`/`act`/`look`) hits these methods and never learns
7
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.
8
+ * the view hierarchy — all three normalize to the {@link Node} shape below, and
9
+ * each adapter exposes exactly ONE structured tree (DOM / AT-SPI / uiautomator).
10
+ * There is no automatic vision/OCR fallback in this contract, and the adapter
11
+ * never switches to pixels: a read yields tree nodes or nothing. `screenshot`
12
+ * only captures a frame — for evidence, and for the agent-level `look` belt
13
+ * call, the one path by which pixels reach a model. `look` describes and judges
14
+ * a frame; it never yields elements an adapter could find, click or type into.
10
15
  *
11
16
  * Reads are **SQL-like**, not RPC: a handful of verbs with composable params
12
17
  * (`query`/`fields`/`filters`/`limit`/`within`) — see {@link Query}. The belt's
@@ -1 +1 @@
1
- {"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/adapters/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG"}
1
+ {"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/adapters/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * busctl-backed AT-SPI2 reader — the integration-validated half of the desktop read.
3
+ *
4
+ * Moved verbatim out of `atspi.ts`: {@link BusctlAtspi} walks the a11y tree over
5
+ * D-Bus via `busctl` (one spawn per call, bounded by `maxNodes`/`maxDepth` and an
6
+ * optional deadline), resolving the named application/window scope FIRST so a
7
+ * duplicate label in another app is never read. Every reply is validated by the
8
+ * pure parsers in `atspi-parse.ts`; failures throw loud.
9
+ */
10
+ import { type AtspiNode, type AtspiReadOptions, type AtspiSource } from './atspi.js';
11
+ import { type ExecOptions } from './proc.js';
12
+ /** A busctl invocation (args only — the `busctl` binary is fixed). Injected for tests. */
13
+ export type BusctlExec = (args: string[], opts?: ExecOptions) => Promise<string>;
14
+ /**
15
+ * {@link AtspiSource} backed by `busctl`. Walks the a11y tree breadth-first from the
16
+ * registry root, bounded by `maxNodes`/`maxDepth`. Resolves the a11y bus address once
17
+ * and caches it. Every reply is validated by the pure parsers above; failures throw loud.
18
+ */
19
+ export declare class BusctlAtspi implements AtspiSource {
20
+ #private;
21
+ constructor(init?: {
22
+ display?: string;
23
+ exec?: BusctlExec;
24
+ });
25
+ readTree(opts?: AtspiReadOptions): Promise<AtspiNode[]>;
26
+ }
@@ -0,0 +1,330 @@
1
+ /**
2
+ * busctl-backed AT-SPI2 reader — the integration-validated half of the desktop read.
3
+ *
4
+ * Moved verbatim out of `atspi.ts`: {@link BusctlAtspi} walks the a11y tree over
5
+ * D-Bus via `busctl` (one spawn per call, bounded by `maxNodes`/`maxDepth` and an
6
+ * optional deadline), resolving the named application/window scope FIRST so a
7
+ * duplicate label in another app is never read. Every reply is validated by the
8
+ * pure parsers in `atspi-parse.ts`; failures throw loud.
9
+ */
10
+ import { AdapterError, ExecTimeoutError } from '../../errors.js';
11
+ import { describeScope, matchesScope, oneWindow, } from './atspi.js';
12
+ import { asString, busctlData, firstReturn, mapRole, matchesQuery, parseChildren, parseExtents, parseStateWords, stateFlags, } from './atspi-parse.js';
13
+ import { desktopEnv, makeExec } from './proc.js';
14
+ const A11Y_IFACE = 'org.a11y.atspi.Accessible';
15
+ const COMPONENT_IFACE = 'org.a11y.atspi.Component';
16
+ const REGISTRY_DEST = 'org.a11y.atspi.Registry';
17
+ const ROOT_PATH = '/org/a11y/atspi/accessible/root';
18
+ /** `ATSPI_COORD_TYPE_SCREEN` — extents relative to the screen, for clicks + vision. */
19
+ const COORD_SCREEN = 0;
20
+ /** Placeholder bounds for a node with no `Component` — paired with `measured: false`. */
21
+ const UNMEASURED_BOUNDS = { x: 0, y: 0, width: 0, height: 0 };
22
+ /** Walk caps — keep the (spawn-heavy) tree read bounded. */
23
+ const DEFAULT_MAX_NODES = 200;
24
+ const DEFAULT_MAX_DEPTH = 25;
25
+ /**
26
+ * {@link AtspiSource} backed by `busctl`. Walks the a11y tree breadth-first from the
27
+ * registry root, bounded by `maxNodes`/`maxDepth`. Resolves the a11y bus address once
28
+ * and caches it. Every reply is validated by the pure parsers above; failures throw loud.
29
+ */
30
+ export class BusctlAtspi {
31
+ #exec;
32
+ #address = null;
33
+ constructor(init = {}) {
34
+ const exec = makeExec(desktopEnv(init.display));
35
+ this.#exec = init.exec ?? ((args, opts) => exec('busctl', args, opts));
36
+ }
37
+ async readTree(opts = {}) {
38
+ const maxNodes = opts.maxNodes ?? DEFAULT_MAX_NODES;
39
+ const maxDepth = opts.maxDepth ?? DEFAULT_MAX_DEPTH;
40
+ const query = opts.query;
41
+ const deadline = opts.deadline;
42
+ const out = [];
43
+ const seen = new Set();
44
+ // Start at the registry root's children (apps); the desktop root itself is not UI.
45
+ // A scoped read resolves the application/window it is bound to FIRST: the
46
+ // registry spans EVERY application on the desktop, so an unscoped walk
47
+ // resolves a label like "Save" against whichever app answered first and
48
+ // the click lands in the wrong window.
49
+ let frontier;
50
+ if (opts.scope) {
51
+ // The scoped walk resolves its own root and reports why it could not:
52
+ // an exhausted deadline and a scope that matches nothing are different
53
+ // failures, and the caller must not read one as the other.
54
+ frontier = await this.#scopeRoots(opts.scope, deadline, maxDepth);
55
+ }
56
+ else {
57
+ // Already out of time: spend no spawn at all — there is nothing left to read.
58
+ if (deadline !== undefined && Date.now() >= deadline)
59
+ return out;
60
+ frontier = await this.#children({ dest: REGISTRY_DEST, path: ROOT_PATH }, deadline);
61
+ }
62
+ for (let depth = 0; frontier.length > 0 && depth < maxDepth; depth += 1) {
63
+ const next = [];
64
+ for (const ref of frontier) {
65
+ // With a query, `out` holds only matches — so this also stops the walk as
66
+ // soon as enough matches are found, not merely enough nodes visited.
67
+ if (out.length >= maxNodes)
68
+ return out;
69
+ // Out of time: stop before spending another pair of spawns on this node.
70
+ if (deadline !== undefined && Date.now() >= deadline)
71
+ return out;
72
+ const key = `${ref.dest}${ref.path}`;
73
+ if (seen.has(key))
74
+ continue;
75
+ seen.add(key);
76
+ const { role, name } = await this.#roleAndName(ref, deadline);
77
+ // A query-pruned non-match: skip the State/Extents calls (they'd just be
78
+ // filtered out downstream) but keep walking its children for deeper matches.
79
+ if (!query ||
80
+ matchesQuery({ role, name, bounds: UNMEASURED_BOUNDS, enabled: false }, query)) {
81
+ out.push(await this.#describeRest(ref, role, name, deadline));
82
+ }
83
+ next.push(...(await this.#children(ref, deadline)));
84
+ }
85
+ frontier = next;
86
+ }
87
+ return out;
88
+ }
89
+ /**
90
+ * Resolve the scope to the ONE tree root the walk starts from.
91
+ *
92
+ * The registry root's children ARE the applications on the desktop, so the
93
+ * scope is resolved against them first — an unscoped walk starts there and
94
+ * therefore sees EVERY application, which is how a duplicate label ("Save"
95
+ * in two apps) resolves to the wrong one.
96
+ *
97
+ * The scope resolves to exactly ONE root, never a set: the walk starts from
98
+ * every root it is handed, so two of them put two applications' subtrees in
99
+ * the result and the lookup resolves against whichever the bus listed
100
+ * first — the duplicate-label hole this scope exists to close. A scope that
101
+ * names two applications, or two windows, is ambiguous: it fails loud
102
+ * instead of guessing which one was meant.
103
+ *
104
+ * Resolution order: a `class` names the application outright — the title
105
+ * then only picks the window inside it, and other applications whose NAMES
106
+ * carry the title are irrelevant. Without a class, matching WINDOWS come
107
+ * first: a window actually titled "Doc" beats an application merely named
108
+ * "Doc Editor"; only when no window carries the title is an application
109
+ * carrying it taken as the scope.
110
+ *
111
+ * The top level is matched as an application whatever role the toolkit
112
+ * reports for it (real trees say `application`, some say `frame`), so the
113
+ * match must not depend on that role string.
114
+ *
115
+ * A scope that matches nothing resolves to no root at all: the caller then
116
+ * fails loud instead of reading a tree that belongs to another application.
117
+ */
118
+ async #scopeRoots(scope, deadline, maxDepth) {
119
+ // Out of time before the search even starts: no root can be resolved, and
120
+ // the caller must not read that as "the scope matched nothing".
121
+ if (deadline !== undefined && Date.now() >= deadline) {
122
+ throw new AdapterError('AT-SPI: the scoped walk ran out of time before it reached the scoped window');
123
+ }
124
+ const apps = await this.#children({ dest: REGISTRY_DEST, path: ROOT_PATH }, deadline);
125
+ // Which applications does the scope name? The class is the application's
126
+ // OWN identity, so it decides the application; the title names the WINDOW
127
+ // inside it. An application matched by class is the one the scope is
128
+ // bound to — the title then picks the window within it.
129
+ const byTitle = [];
130
+ const byClass = [];
131
+ for (const ref of apps) {
132
+ const { name } = await this.#roleAndName(ref, deadline);
133
+ if (matchesScope({ role: 'application', name }, { class: scope.class })) {
134
+ byClass.push(ref);
135
+ }
136
+ else if (matchesScope({ role: 'application', name }, { title: scope.title })) {
137
+ byTitle.push(ref);
138
+ }
139
+ }
140
+ // The class is the application's OWN identity: once it names an
141
+ // application, the scope is bound to THAT application and the title only
142
+ // picks the window inside it. Other applications whose NAMES carry the
143
+ // title are irrelevant — they must not trip an application-title
144
+ // ambiguity, and the read must never be handed to them.
145
+ if (byClass.length > 0) {
146
+ const window = oneWindow(await this.#windowsUnder(byClass, scope, deadline, maxDepth), scope);
147
+ if (window)
148
+ return [window.ref];
149
+ if (byClass.length > 1) {
150
+ throw new AdapterError(`AT-SPI: the scope (${describeScope(scope)}) is ambiguous — ${byClass.length} applications ` +
151
+ 'carry that class; the scope must name exactly one');
152
+ }
153
+ // The class matched exactly one application but the title matched no
154
+ // window in it. Returning the whole application would let find/click
155
+ // resolve labels in ANOTHER window of that app — the one thing a scoped
156
+ // read must never do. Fail loud instead.
157
+ if (scope.title) {
158
+ throw new AdapterError(`AT-SPI: the scope (${describeScope(scope)}) matched the application but no window in it ` +
159
+ 'carries that title; the scope must name a window that exists');
160
+ }
161
+ return byClass; // exactly one application, and no title to narrow it by
162
+ }
163
+ // No class: matching WINDOWS come first. An application whose NAME merely
164
+ // carries the title must not win while the window actually titled so
165
+ // lives in another application — that hands find/click to the wrong app.
166
+ // Only when NO window carries the title is an application named by it
167
+ // taken as the scope, and two of those is an ambiguity, not a choice.
168
+ if (scope.title) {
169
+ const window = oneWindow(await this.#windowsUnder(apps, scope, deadline, maxDepth), scope);
170
+ if (window)
171
+ return [window.ref];
172
+ if (byTitle.length > 1) {
173
+ throw new AdapterError(`AT-SPI: the scope (${describeScope(scope)}) is ambiguous — ${byTitle.length} applications ` +
174
+ 'carry that title; the scope must name exactly one');
175
+ }
176
+ if (byTitle.length === 1)
177
+ return byTitle;
178
+ }
179
+ // Nothing matched. A deadline that expired on the way here is a timeout,
180
+ // not a miss: reporting it as "no match" would send the caller looking for
181
+ // a window that is simply out of reach in the time it had.
182
+ if (deadline !== undefined && Date.now() >= deadline) {
183
+ throw new AdapterError('AT-SPI: the scoped walk ran out of time before it reached the scoped window');
184
+ }
185
+ throw new AdapterError(`AT-SPI: no application or window matched the scope (${describeScope(scope)})`);
186
+ }
187
+ /**
188
+ * The windows inside these applications whose name carries the scoped title.
189
+ *
190
+ * A walk that gave up mid-search (deadline spent) is a failure, not a
191
+ * partial answer: acting on the hits found so far would read a window the
192
+ * scope never actually named.
193
+ */
194
+ async #windowsUnder(apps, scope, deadline, maxDepth) {
195
+ const windows = [];
196
+ for (const app of apps) {
197
+ windows.push(...(await this.#windowsIn(app, scope, deadline, maxDepth)));
198
+ if (deadline !== undefined && Date.now() >= deadline) {
199
+ throw new AdapterError('AT-SPI: the scoped walk ran out of time before it reached the scoped window');
200
+ }
201
+ }
202
+ return windows;
203
+ }
204
+ /**
205
+ * The windows inside `app` whose name carries the scoped title.
206
+ *
207
+ * Only container roles are descended into: a window's children are its
208
+ * widgets, and a widget's subtree never holds another toplevel. That keeps
209
+ * the scoped search from walking an entire application just to find its
210
+ * frame.
211
+ */
212
+ async #windowsIn(app, scope, deadline, maxDepth) {
213
+ const title = scope.title?.toLowerCase() ?? '';
214
+ if (title === '')
215
+ return [];
216
+ const hits = [];
217
+ const seen = new Set();
218
+ let frontier = await this.#children(app, deadline);
219
+ for (let depth = 0; frontier.length > 0 && depth < maxDepth; depth += 1) {
220
+ const next = [];
221
+ for (const ref of frontier) {
222
+ if (deadline !== undefined && Date.now() >= deadline)
223
+ return hits;
224
+ const key = `${ref.dest}${ref.path}`;
225
+ if (seen.has(key))
226
+ continue;
227
+ seen.add(key);
228
+ const { role, name } = await this.#roleAndName(ref, deadline);
229
+ if (role === 'window') {
230
+ if (name.toLowerCase().includes(title))
231
+ hits.push({ ref, name });
232
+ continue; // a window's children are its widgets, never another toplevel
233
+ }
234
+ if (role !== 'application' && role !== 'dialog')
235
+ continue;
236
+ next.push(...(await this.#children(ref, deadline)));
237
+ }
238
+ frontier = next;
239
+ }
240
+ return hits;
241
+ }
242
+ /**
243
+ * One busctl spawn, bounded by the walk's deadline.
244
+ *
245
+ * The subprocess is capped by the time left until the deadline, so a wedged bus
246
+ * cannot hold the walk (and the `waitFor` that asked for it) past its timeout. A
247
+ * reply that arrives after the deadline is a failure, not a partial tree: the
248
+ * caller must not read a stale tree as the answer.
249
+ */
250
+ async #spawn(args, deadline) {
251
+ const out = await this.#exec(args, deadline === undefined ? undefined : { deadline });
252
+ if (deadline !== undefined && Date.now() >= deadline) {
253
+ throw new ExecTimeoutError(`desktop: \`busctl\` resolved after the walk deadline (${deadline}) had passed`);
254
+ }
255
+ return out;
256
+ }
257
+ /** Resolve (and cache) the a11y peer-bus address via the session bus. */
258
+ async #a11yAddress(deadline) {
259
+ if (this.#address)
260
+ return this.#address;
261
+ const data = busctlData(await this.#spawn([
262
+ '--user',
263
+ '--json=short',
264
+ 'call',
265
+ 'org.a11y.Bus',
266
+ '/org/a11y/bus',
267
+ 'org.a11y.Bus',
268
+ 'GetAddress',
269
+ ], deadline));
270
+ const address = asString(firstReturn(data, 'GetAddress'), 'a11y bus address');
271
+ if (address === '')
272
+ throw new AdapterError('AT-SPI: empty a11y bus address');
273
+ this.#address = address;
274
+ return address;
275
+ }
276
+ /** Call a method on the a11y bus, returning the parsed `data` array of return values. */
277
+ async #call(ref, iface, member, extra = [], deadline) {
278
+ const address = await this.#a11yAddress(deadline);
279
+ return busctlData(await this.#spawn([
280
+ `--address=${address}`,
281
+ '--json=short',
282
+ 'call',
283
+ ref.dest,
284
+ ref.path,
285
+ iface,
286
+ member,
287
+ ...extra,
288
+ ], deadline));
289
+ }
290
+ async #children(ref, deadline) {
291
+ return parseChildren(firstReturn(await this.#call(ref, A11Y_IFACE, 'GetChildren', [], deadline), 'GetChildren'));
292
+ }
293
+ /** Read the `Name` property as a plain scalar (`get-property` avoids a variant wrapper). */
294
+ async #name(ref, deadline) {
295
+ const address = await this.#a11yAddress(deadline);
296
+ const data = busctlData(await this.#spawn([
297
+ `--address=${address}`,
298
+ '--json=short',
299
+ 'get-property',
300
+ ref.dest,
301
+ ref.path,
302
+ A11Y_IFACE,
303
+ 'Name',
304
+ ], deadline));
305
+ return asString(data, 'Name');
306
+ }
307
+ /** Read just role + name — cheap enough to spend on every node for query pruning. */
308
+ async #roleAndName(ref, deadline) {
309
+ const roleName = asString(firstReturn(await this.#call(ref, A11Y_IFACE, 'GetRoleName', [], deadline), 'GetRoleName'), 'GetRoleName');
310
+ return { role: mapRole(roleName), name: await this.#name(ref, deadline) };
311
+ }
312
+ /** Finish describing a node (state + extents) once its role/name are known to matter. */
313
+ async #describeRest(ref, role, name, deadline) {
314
+ const { enabled, visible } = stateFlags(parseStateWords(firstReturn(await this.#call(ref, A11Y_IFACE, 'GetState', [], deadline), 'GetState')));
315
+ // Application roots + some toolkit filler nodes don't implement Component, so
316
+ // busctl exits non-zero on GetExtents. Keep the node (killing the whole walk over
317
+ // an unmeasurable filler helps nobody) but mark it `measured: false` — the zeros
318
+ // below are a placeholder, never geometry. Role/name/state failures stay loud.
319
+ // An expired per-call cap (`proc.ts`) is not "no Component":
320
+ // swallowing it would spend the cap again on every remaining node of the walk.
321
+ const extents = await this.#call(ref, COMPONENT_IFACE, 'GetExtents', ['u', String(COORD_SCREEN)], deadline).catch((error) => {
322
+ if (error instanceof ExecTimeoutError)
323
+ throw error;
324
+ return null;
325
+ });
326
+ const bounds = extents === null ? UNMEASURED_BOUNDS : parseExtents(firstReturn(extents, 'GetExtents'));
327
+ return { role, name, bounds, enabled, visible, measured: extents !== null };
328
+ }
329
+ }
330
+ //# sourceMappingURL=atspi-busctl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atspi-busctl.js","sourceRoot":"","sources":["../../../src/adapters/desktop/atspi-busctl.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAE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C,EAC3B,QAAQ,CACT,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;YACzB,IAAI,KAAK,YAAY,gBAAgB;gBAAE,MAAM,KAAK,CAAC;YACnD,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;QACH,MAAM,MAAM,GACV,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,YAAY,CAAC,WAAW,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC;QAC1F,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,KAAK,IAAI,EAAE,CAAC;IAC9E,CAAC;CACF"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * AT-SPI2 wire-shape parsing — the pure, unit-tested half of the desktop read.
3
+ *
4
+ * Moved verbatim out of `atspi.ts` (which keeps the shared types and the
5
+ * filter/shaping helpers): the AT-SPI role map, the fail-loud type guards, the
6
+ * busctl `--json=short` reply parsers and the role/name query helpers.
7
+ * `BusctlAtspi` (`atspi-busctl.ts`) is the integration-validated runner on top.
8
+ */
9
+ import type { Bounds, Node } from '../contract.js';
10
+ import type { AtspiRef } from './atspi.js';
11
+ /** Normalize an AT-SPI role name to a contract role; unknown roles pass through cleaned. */
12
+ export declare function mapRole(roleName: string): string;
13
+ export declare function asString(value: unknown, ctx: string): string;
14
+ /** Parse a busctl `--json=short` reply, returning its `data` field (loud on malformed JSON). */
15
+ export declare function busctlData(stdout: string): unknown;
16
+ /** First return value of a method `call` (busctl wraps returns in a `data` array). */
17
+ export declare function firstReturn(data: unknown, ctx: string): unknown;
18
+ /** Decode `Component.GetExtents` `(iiii)` → screen {@link Bounds}. */
19
+ export declare function parseExtents(value: unknown): Bounds;
20
+ /** Decode `Accessible.GetState` `au` → the two 32-bit state words `[low, high]`. */
21
+ export declare function parseStateWords(value: unknown): [number, number];
22
+ /** True when `bit` is set in the split 64-bit AT-SPI state field. */
23
+ export declare function hasState(words: [number, number], bit: number): boolean;
24
+ /** Derive the contract `enabled` + internal `visible` flags from a state field. */
25
+ export declare function stateFlags(words: [number, number]): {
26
+ enabled: boolean;
27
+ visible: boolean;
28
+ };
29
+ /** Decode `Accessible.GetChildren` `a(so)` → child {@link AtspiRef}s. */
30
+ export declare function parseChildren(value: unknown): AtspiRef[];
31
+ /** A parsed agent query: an optional role and/or a name substring. */
32
+ export interface ParsedQuery {
33
+ role?: string;
34
+ name?: string;
35
+ }
36
+ /** Parse an agent target (`button "Save"` or plain `Save`) into a {@link ParsedQuery}. */
37
+ export declare function parseRoleNameQuery(raw: string): ParsedQuery;
38
+ /** True when a node satisfies a {@link ParsedQuery} (role exact, name case-insensitive substring). */
39
+ export declare function matchesQuery(node: Node, parsed: ParsedQuery): boolean;