@developerz.ai/ui-debugger-mcp 1.9.0 → 1.11.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 (274) hide show
  1. package/README.md +63 -47
  2. package/dist/adapters/android/abortable.d.ts +6 -0
  3. package/dist/adapters/android/abortable.js +22 -0
  4. package/dist/adapters/android/abortable.js.map +1 -0
  5. package/dist/adapters/android/adb.d.ts +19 -7
  6. package/dist/adapters/android/adb.js +50 -13
  7. package/dist/adapters/android/adb.js.map +1 -1
  8. package/dist/adapters/android/android-adapter.d.ts +20 -12
  9. package/dist/adapters/android/android-adapter.js +113 -165
  10. package/dist/adapters/android/android-adapter.js.map +1 -1
  11. package/dist/adapters/android/commands.d.ts +10 -0
  12. package/dist/adapters/android/commands.js +22 -0
  13. package/dist/adapters/android/commands.js.map +1 -1
  14. package/dist/adapters/android/emulator.d.ts +41 -0
  15. package/dist/adapters/android/emulator.js +115 -0
  16. package/dist/adapters/android/emulator.js.map +1 -0
  17. package/dist/adapters/android/logcat.d.ts +87 -0
  18. package/dist/adapters/android/logcat.js +352 -0
  19. package/dist/adapters/android/logcat.js.map +1 -0
  20. package/dist/adapters/android/ports.js.map +1 -1
  21. package/dist/adapters/android/sdk.d.ts +65 -0
  22. package/dist/adapters/android/sdk.js +107 -0
  23. package/dist/adapters/android/sdk.js.map +1 -0
  24. package/dist/adapters/android/uiautomator.d.ts +23 -7
  25. package/dist/adapters/android/uiautomator.js +31 -7
  26. package/dist/adapters/android/uiautomator.js.map +1 -1
  27. package/dist/adapters/availability.d.ts +39 -0
  28. package/dist/adapters/availability.js +62 -0
  29. package/dist/adapters/availability.js.map +1 -0
  30. package/dist/adapters/browser/browser-adapter.d.ts +11 -22
  31. package/dist/adapters/browser/browser-adapter.js +90 -71
  32. package/dist/adapters/browser/browser-adapter.js.map +1 -1
  33. package/dist/adapters/browser/cdp.d.ts +22 -17
  34. package/dist/adapters/browser/cdp.js +118 -72
  35. package/dist/adapters/browser/cdp.js.map +1 -1
  36. package/dist/adapters/browser/exchange-read.d.ts +39 -0
  37. package/dist/adapters/browser/exchange-read.js +102 -0
  38. package/dist/adapters/browser/exchange-read.js.map +1 -0
  39. package/dist/adapters/browser/extractor.js +9 -2
  40. package/dist/adapters/browser/extractor.js.map +1 -1
  41. package/dist/adapters/browser/filters.d.ts +1 -1
  42. package/dist/adapters/browser/filters.js.map +1 -1
  43. package/dist/adapters/browser/geometry.js.map +1 -1
  44. package/dist/adapters/browser/launch.d.ts +14 -5
  45. package/dist/adapters/browser/launch.js +14 -5
  46. package/dist/adapters/browser/launch.js.map +1 -1
  47. package/dist/adapters/browser/lifecycle.d.ts +91 -0
  48. package/dist/adapters/browser/lifecycle.js +141 -0
  49. package/dist/adapters/browser/lifecycle.js.map +1 -0
  50. package/dist/adapters/browser/locate.d.ts +18 -2
  51. package/dist/adapters/browser/locate.js +48 -3
  52. package/dist/adapters/browser/locate.js.map +1 -1
  53. package/dist/adapters/browser/log-filters.d.ts +2 -2
  54. package/dist/adapters/browser/log-filters.js +15 -4
  55. package/dist/adapters/browser/log-filters.js.map +1 -1
  56. package/dist/adapters/browser/log-format.d.ts +23 -20
  57. package/dist/adapters/browser/log-format.js +133 -56
  58. package/dist/adapters/browser/log-format.js.map +1 -1
  59. package/dist/adapters/browser/tab-context.d.ts +30 -0
  60. package/dist/adapters/browser/tab-context.js +41 -0
  61. package/dist/adapters/browser/tab-context.js.map +1 -0
  62. package/dist/adapters/contract.d.ts +113 -10
  63. package/dist/adapters/contract.js +7 -2
  64. package/dist/adapters/contract.js.map +1 -1
  65. package/dist/adapters/desktop/atspi-busctl.d.ts +26 -0
  66. package/dist/adapters/desktop/atspi-busctl.js +332 -0
  67. package/dist/adapters/desktop/atspi-busctl.js.map +1 -0
  68. package/dist/adapters/desktop/atspi-parse.d.ts +39 -0
  69. package/dist/adapters/desktop/atspi-parse.js +155 -0
  70. package/dist/adapters/desktop/atspi-parse.js.map +1 -0
  71. package/dist/adapters/desktop/atspi.d.ts +81 -50
  72. package/dist/adapters/desktop/atspi.js +64 -285
  73. package/dist/adapters/desktop/atspi.js.map +1 -1
  74. package/dist/adapters/desktop/capture.d.ts +11 -20
  75. package/dist/adapters/desktop/capture.js +68 -37
  76. package/dist/adapters/desktop/capture.js.map +1 -1
  77. package/dist/adapters/desktop/desktop-adapter.d.ts +22 -2
  78. package/dist/adapters/desktop/desktop-adapter.js +202 -86
  79. package/dist/adapters/desktop/desktop-adapter.js.map +1 -1
  80. package/dist/adapters/desktop/input.d.ts +19 -5
  81. package/dist/adapters/desktop/input.js +29 -13
  82. package/dist/adapters/desktop/input.js.map +1 -1
  83. package/dist/adapters/desktop/managed-app.d.ts +43 -0
  84. package/dist/adapters/desktop/managed-app.js +114 -0
  85. package/dist/adapters/desktop/managed-app.js.map +1 -0
  86. package/dist/adapters/desktop/proc.d.ts +34 -4
  87. package/dist/adapters/desktop/proc.js +37 -6
  88. package/dist/adapters/desktop/proc.js.map +1 -1
  89. package/dist/adapters/desktop/wait-poll.d.ts +17 -0
  90. package/dist/adapters/desktop/wait-poll.js +38 -0
  91. package/dist/adapters/desktop/wait-poll.js.map +1 -0
  92. package/dist/adapters/factory.d.ts +13 -6
  93. package/dist/adapters/factory.js +30 -4
  94. package/dist/adapters/factory.js.map +1 -1
  95. package/dist/adapters/log-format.d.ts +38 -0
  96. package/dist/adapters/log-format.js +47 -0
  97. package/dist/adapters/log-format.js.map +1 -0
  98. package/dist/agent/belt/act.d.ts +426 -23
  99. package/dist/agent/belt/act.js +44 -64
  100. package/dist/agent/belt/act.js.map +1 -1
  101. package/dist/agent/belt/look.d.ts +479 -16
  102. package/dist/agent/belt/look.js +94 -16
  103. package/dist/agent/belt/look.js.map +1 -1
  104. package/dist/agent/belt/observe.d.ts +652 -65
  105. package/dist/agent/belt/observe.js +119 -231
  106. package/dist/agent/belt/observe.js.map +1 -1
  107. package/dist/agent/belt/redact-output.d.ts +20 -0
  108. package/dist/agent/belt/redact-output.js +70 -0
  109. package/dist/agent/belt/redact-output.js.map +1 -0
  110. package/dist/agent/belt/report.d.ts +754 -48
  111. package/dist/agent/belt/report.js +121 -38
  112. package/dist/agent/belt/report.js.map +1 -1
  113. package/dist/agent/belt/same-origin.d.ts +21 -0
  114. package/dist/agent/belt/same-origin.js +38 -0
  115. package/dist/agent/belt/same-origin.js.map +1 -0
  116. package/dist/agent/belt/target-refs.d.ts +39 -0
  117. package/dist/agent/belt/target-refs.js +60 -0
  118. package/dist/agent/belt/target-refs.js.map +1 -0
  119. package/dist/agent/belt/trail.d.ts +44 -16
  120. package/dist/agent/belt/trail.js +46 -11
  121. package/dist/agent/belt/trail.js.map +1 -1
  122. package/dist/agent/belt/tree-targets.d.ts +79 -0
  123. package/dist/agent/belt/tree-targets.js +242 -0
  124. package/dist/agent/belt/tree-targets.js.map +1 -0
  125. package/dist/agent/capabilities.js.map +1 -1
  126. package/dist/agent/fallback.d.ts +33 -0
  127. package/dist/agent/fallback.js +84 -0
  128. package/dist/agent/fallback.js.map +1 -0
  129. package/dist/agent/loop-frames.d.ts +26 -0
  130. package/dist/agent/loop-frames.js +106 -0
  131. package/dist/agent/loop-frames.js.map +1 -0
  132. package/dist/agent/loop.d.ts +56 -65
  133. package/dist/agent/loop.js +122 -189
  134. package/dist/agent/loop.js.map +1 -1
  135. package/dist/agent/models.d.ts +10 -6
  136. package/dist/agent/models.js +15 -9
  137. package/dist/agent/models.js.map +1 -1
  138. package/dist/agent/prompts/compose.d.ts +1 -1
  139. package/dist/agent/prompts/debug-agent.js +48 -10
  140. package/dist/agent/prompts/debug-agent.js.map +1 -1
  141. package/dist/agent/prompts/web-addendum.d.ts +2 -2
  142. package/dist/agent/prompts/web-addendum.js +26 -25
  143. package/dist/agent/prompts/web-addendum.js.map +1 -1
  144. package/dist/agent/provider.d.ts +41 -1
  145. package/dist/agent/provider.js +59 -5
  146. package/dist/agent/provider.js.map +1 -1
  147. package/dist/boot.d.ts +64 -0
  148. package/dist/boot.js +147 -0
  149. package/dist/boot.js.map +1 -0
  150. package/dist/cli/chromium-libs.d.ts +267 -0
  151. package/dist/cli/chromium-libs.js +546 -0
  152. package/dist/cli/chromium-libs.js.map +1 -0
  153. package/dist/cli/control.js +79 -12
  154. package/dist/cli/control.js.map +1 -1
  155. package/dist/cli/init.d.ts +52 -3
  156. package/dist/cli/init.js +62 -10
  157. package/dist/cli/init.js.map +1 -1
  158. package/dist/config/load.d.ts +25 -8
  159. package/dist/config/load.js +50 -13
  160. package/dist/config/load.js.map +1 -1
  161. package/dist/config/schema.d.ts +18 -6
  162. package/dist/config/schema.js +34 -17
  163. package/dist/config/schema.js.map +1 -1
  164. package/dist/errors.d.ts +30 -15
  165. package/dist/errors.js +49 -30
  166. package/dist/errors.js.map +1 -1
  167. package/dist/findings/schema.d.ts +44 -6
  168. package/dist/findings/schema.js +39 -3
  169. package/dist/findings/schema.js.map +1 -1
  170. package/dist/index.d.ts +1 -1
  171. package/dist/index.js +1 -1
  172. package/dist/index.js.map +1 -1
  173. package/dist/main.js +4 -82
  174. package/dist/main.js.map +1 -1
  175. package/dist/mcp/server.js +10 -1
  176. package/dist/mcp/server.js.map +1 -1
  177. package/dist/mcp/tools/describe.d.ts +5 -4
  178. package/dist/mcp/tools/describe.js +14 -10
  179. package/dist/mcp/tools/describe.js.map +1 -1
  180. package/dist/mcp/tools/end-session.d.ts +3 -1
  181. package/dist/mcp/tools/end-session.js +8 -3
  182. package/dist/mcp/tools/end-session.js.map +1 -1
  183. package/dist/mcp/tools/output.d.ts +12 -4
  184. package/dist/mcp/tools/output.js +15 -2
  185. package/dist/mcp/tools/output.js.map +1 -1
  186. package/dist/mcp/tools/result.d.ts +10 -1
  187. package/dist/mcp/tools/result.js +12 -7
  188. package/dist/mcp/tools/result.js.map +1 -1
  189. package/dist/mcp/tools/start-debug.js +7 -5
  190. package/dist/mcp/tools/start-debug.js.map +1 -1
  191. package/dist/redact.d.ts +44 -0
  192. package/dist/redact.js +166 -0
  193. package/dist/redact.js.map +1 -0
  194. package/dist/services/auth-persona.d.ts +19 -0
  195. package/dist/services/auth-persona.js +32 -0
  196. package/dist/services/auth-persona.js.map +1 -0
  197. package/dist/services/catalog.d.ts +28 -0
  198. package/dist/services/catalog.js +65 -0
  199. package/dist/services/catalog.js.map +1 -0
  200. package/dist/services/debug-api.d.ts +179 -0
  201. package/dist/services/debug-api.js +9 -0
  202. package/dist/services/debug-api.js.map +1 -0
  203. package/dist/services/debug-service.d.ts +26 -174
  204. package/dist/services/debug-service.js +159 -227
  205. package/dist/services/debug-service.js.map +1 -1
  206. package/dist/services/foreign-findings.d.ts +22 -0
  207. package/dist/services/foreign-findings.js +38 -0
  208. package/dist/services/foreign-findings.js.map +1 -0
  209. package/dist/services/login-failure.d.ts +10 -0
  210. package/dist/services/login-failure.js +24 -0
  211. package/dist/services/login-failure.js.map +1 -0
  212. package/dist/services/login-selectors.d.ts +18 -0
  213. package/dist/services/login-selectors.js +44 -0
  214. package/dist/services/login-selectors.js.map +1 -0
  215. package/dist/services/login-session.d.ts +25 -0
  216. package/dist/services/login-session.js +59 -0
  217. package/dist/services/login-session.js.map +1 -0
  218. package/dist/services/login.d.ts +16 -29
  219. package/dist/services/login.js +269 -97
  220. package/dist/services/login.js.map +1 -1
  221. package/dist/services/replay.js +15 -3
  222. package/dist/services/replay.js.map +1 -1
  223. package/dist/services/retained-snapshot.d.ts +36 -0
  224. package/dist/services/retained-snapshot.js +63 -0
  225. package/dist/services/retained-snapshot.js.map +1 -0
  226. package/dist/services/session-builder.d.ts +26 -0
  227. package/dist/services/session-builder.js +63 -21
  228. package/dist/services/session-builder.js.map +1 -1
  229. package/dist/services/shutdown.d.ts +8 -4
  230. package/dist/services/shutdown.js +21 -8
  231. package/dist/services/shutdown.js.map +1 -1
  232. package/dist/services/start-guards.d.ts +37 -0
  233. package/dist/services/start-guards.js +61 -0
  234. package/dist/services/start-guards.js.map +1 -0
  235. package/dist/services/summarize.d.ts +12 -3
  236. package/dist/services/summarize.js +13 -5
  237. package/dist/services/summarize.js.map +1 -1
  238. package/dist/session/cleanup.d.ts +3 -2
  239. package/dist/session/cleanup.js +6 -2
  240. package/dist/session/cleanup.js.map +1 -1
  241. package/dist/session/finalize.d.ts +45 -0
  242. package/dist/session/finalize.js +150 -0
  243. package/dist/session/finalize.js.map +1 -0
  244. package/dist/session/findings-store.d.ts +2 -1
  245. package/dist/session/findings-store.js +30 -2
  246. package/dist/session/findings-store.js.map +1 -1
  247. package/dist/session/flock-backend.d.ts +117 -0
  248. package/dist/session/flock-backend.js +293 -0
  249. package/dist/session/flock-backend.js.map +1 -0
  250. package/dist/session/live-pointer.d.ts +19 -0
  251. package/dist/session/live-pointer.js +41 -0
  252. package/dist/session/live-pointer.js.map +1 -0
  253. package/dist/session/manager.d.ts +11 -1
  254. package/dist/session/manager.js +46 -2
  255. package/dist/session/manager.js.map +1 -1
  256. package/dist/session/owner-lock.d.ts +117 -0
  257. package/dist/session/owner-lock.js +218 -0
  258. package/dist/session/owner-lock.js.map +1 -0
  259. package/dist/session/process-identity.js.map +1 -1
  260. package/dist/session/session.js +40 -109
  261. package/dist/session/session.js.map +1 -1
  262. package/dist/session/state-file.d.ts +74 -14
  263. package/dist/session/state-file.js +211 -21
  264. package/dist/session/state-file.js.map +1 -1
  265. package/dist/session/workspace.d.ts +32 -2
  266. package/dist/session/workspace.js +65 -4
  267. package/dist/session/workspace.js.map +1 -1
  268. package/package.json +11 -11
  269. package/dist/adapters/android/android-adapter.test-helpers.d.ts +0 -52
  270. package/dist/adapters/android/android-adapter.test-helpers.js +0 -115
  271. package/dist/adapters/android/android-adapter.test-helpers.js.map +0 -1
  272. package/dist/mcp/server.test-helpers.d.ts +0 -23
  273. package/dist/mcp/server.test-helpers.js +0 -49
  274. package/dist/mcp/server.test-helpers.js.map +0 -1
@@ -2,18 +2,36 @@
2
2
  * Rendering + redaction for captured console/network entries.
3
3
  *
4
4
  * Split out of `cdp.ts` to keep that file under the 500-LOC cap — no behavior
5
- * change. Everything here is pure: level normalization, body truncation, the two
6
- * `logs/*.log` line renderers, and the two redactors that keep a credential out
7
- * of the model's context and out of the durable trail (a secret in a header
5
+ * change. Everything here is pure: level normalization, body truncation, the
6
+ * `logs/network.log` line renderer, and the two redactors that keep a credential
7
+ * out of the model's context and out of the durable trail (a secret in a header
8
8
  * VALUE, or in a query param of the URL itself).
9
+ *
10
+ * The console-line renderer is SHARED (the android logcat drain renders the
11
+ * same shape), so it lives in `src/adapters/log-format.ts` and is re-exported
12
+ * here — every existing reader keeps its import path.
13
+ *
14
+ * Both renderers put the TAB MARKER between the timestamp and the row
15
+ * (`<ISO> [tab-1] LEVEL text @ location`, `<ISO> [tab-1] METHOD url → 200 …`),
16
+ * so a line says which tab produced it. The marker is an opaque label — no
17
+ * URL, no title, no secret — and a row without a tab renders exactly as it did
18
+ * before the marker existed.
9
19
  */
20
+ import { oneLine, stamp, tabMarker } from '../log-format.js';
21
+ export { formatConsoleLine } from '../log-format.js';
10
22
  /**
11
23
  * Per-body character cap. Big enough for an error payload or a small collection,
12
24
  * small enough that the driver re-reading tool results every step cannot drown.
13
25
  */
14
26
  export const BODY_CAP = 4096;
15
- /** Header names whose VALUE is a credential — kept as a length marker, never verbatim. */
16
- const SENSITIVE_HEADER = /^(authorization|proxy-authorization|cookie|set-cookie|x-api-key|x-auth-token|x-csrf-token)$/i;
27
+ /**
28
+ * Header names whose VALUE is a credential — kept as a length marker, never verbatim.
29
+ * Beyond the standard auth/cookie pair: the API-key spellings hosted backends send
30
+ * from the browser (Supabase `apikey`, Google `x-goog-api-key`), the CSRF/XSRF pair
31
+ * (Angular/Laravel send `x-xsrf-token`), bearer-ish custom headers, and the AWS
32
+ * session token a presigned/SigV4 request carries.
33
+ */
34
+ const SENSITIVE_HEADER = /^(authorization|proxy-authorization|cookie|set-cookie|apikey|api-key|x-api-key|x-goog-api-key|x-auth-token|x-access-token|x-refresh-token|x-session-token|x-csrf-token|x-xsrf-token|x-amz-security-token)$/i;
17
35
  /** Truncate a captured body, marking what was dropped (never silently shortened). */
18
36
  export function truncateBody(body, cap = BODY_CAP) {
19
37
  if (body.length <= cap)
@@ -71,46 +89,111 @@ export function redactUrl(url) {
71
89
  return `${url.slice(0, start + 1)}${query}${url.slice(end)}`;
72
90
  }
73
91
  /**
74
- * Values a CONFIGURED auth persona types into the app (`targets.<t>.auth.<p>.fields`).
75
- *
76
- * The two redactors above key off a NAME they recognize (`authorization`,
77
- * `?password=`). A persona's values have no such tell: they land in a form POST
78
- * body, in a `type` tool input on the agent trail, in whatever an adapter error
79
- * echoes back. So this one keys off the VALUE — the only thing all three share —
80
- * and is bound per run to the persona the caller named.
81
- *
82
- * Same posture as the other two: presence stays diagnostic (`<redacted, N chars>`
83
- * still tells you a password of the right length was typed), the secret itself
84
- * never reaches the durable trail. Form-encoded and JSON-escaped spellings are
85
- * redacted too — a password with an `@` rides a form POST as `%40`, and matching
86
- * only the plain text would leave the real body in `logs/network.log`.
87
- *
88
- * Longest first, so a value that contains another still redacts whole.
92
+ * A body key whose VALUE is a credential, matched on the key with case and
93
+ * `_`/`-` folded away, and on EVERY segment of a bracket path — so `password`,
94
+ * `new_password`, `accessToken`, `client-secret`, `x_api_key`, `user[password]`
95
+ * and the array field `password[]` all match. A suffix rule, not a list: a login body names its
96
+ * secret a dozen ways, and over-masking a pagination `nextPageToken` is the
97
+ * cheap side of that trade.
89
98
  */
90
- export function createSecretRedactor(secrets) {
91
- const spellings = new Set();
92
- for (const secret of secrets) {
93
- if (secret.length === 0)
94
- continue;
95
- spellings.add(secret);
96
- const encoded = encodeURIComponent(secret);
97
- spellings.add(encoded);
98
- spellings.add(encoded.replaceAll('%20', '+')); // form encoding spells a space `+`
99
- spellings.add(JSON.stringify(secret).slice(1, -1)); // JSON body escaping
100
- }
101
- const values = [...spellings].sort((a, b) => b.length - a.length);
102
- if (values.length === 0)
103
- return (line) => line;
104
- return (line) => {
105
- let out = line;
106
- for (const value of values) {
107
- // `split`/`join`, not a regex: a credential is arbitrary text and escaping it
108
- // for a pattern is one missed metacharacter away from not redacting at all.
109
- if (out.includes(value))
110
- out = out.split(value).join(`<redacted, ${value.length} chars>`);
99
+ const SENSITIVE_KEY = /(password|passwd|pwd|secret|token|apikey|authorization|otp|passcode)$/;
100
+ function isSensitiveKey(key) {
101
+ return (key.match(/[^[\]]+/g) ?? []).some((segment) => SENSITIVE_KEY.test(segment.toLowerCase().replace(/[-_]/g, '')));
102
+ }
103
+ const marker = (length) => `<redacted, ${length} chars>`;
104
+ /**
105
+ * Mask credential-keyed values anywhere in a parsed JSON value; `true` if ANY
106
+ * credential key was seen — masked or not (a `null` one). The caller must then
107
+ * re-serialize: `JSON.parse` keeps only the LAST of duplicate keys, so the raw
108
+ * text of `{"password":"hunter2","password":null}` still holds the secret the
109
+ * parsed value no longer shows.
110
+ */
111
+ function maskJson(value) {
112
+ if (value === null || typeof value !== 'object')
113
+ return false;
114
+ let seen = false;
115
+ for (const [key, child] of Object.entries(value)) {
116
+ if (isSensitiveKey(key)) {
117
+ seen = true;
118
+ if (child === null || typeof child === 'boolean')
119
+ continue;
120
+ const text = typeof child === 'object' ? JSON.stringify(child) : String(child);
121
+ value[key] = marker(text.length);
122
+ }
123
+ else if (maskJson(child)) {
124
+ seen = true;
111
125
  }
112
- return out;
113
- };
126
+ }
127
+ return seen;
128
+ }
129
+ /** A declared `application/x-www-form-urlencoded` content type (any params). */
130
+ const FORM_TYPE = /^\s*application\/x-www-form-urlencoded\b/i;
131
+ const NOT_JSON = Symbol('not-json');
132
+ /** `text` parsed as JSON, or {@link NOT_JSON} when it does not parse. */
133
+ function parseJson(text) {
134
+ try {
135
+ return JSON.parse(text);
136
+ }
137
+ catch {
138
+ return NOT_JSON;
139
+ }
140
+ }
141
+ /**
142
+ * Whether to treat `text` as form-urlencoded. A DECLARED form always is. Else the
143
+ * test is deliberately loose — every valid form passes it (empty names `=x`,
144
+ * empty pairs, bare keys, stray `=`); a grammar that rejected any of those let
145
+ * the password beside it through. Only text that cannot be a form is out: no
146
+ * `=` at all, or raw whitespace (a serialized form encodes it as `+`/`%20`).
147
+ */
148
+ function isForm(text, contentType) {
149
+ if (contentType !== undefined && FORM_TYPE.test(contentType))
150
+ return true;
151
+ return text.includes('=') && !/\s/.test(text);
152
+ }
153
+ /**
154
+ * A form key as the server reads it (`user%5Bpassword%5D` → `user[password]`),
155
+ * decoded by `URLSearchParams` — the WHATWG parser, lenient exactly where servers
156
+ * are: a malformed `%zz` stays literal while the valid escapes around it
157
+ * (`%zz%5Bpassword%5D` → `%zz[password]`) still decode, instead of the whole key failing to decode.
158
+ */
159
+ function formKey(raw) {
160
+ return new URLSearchParams(`${raw}=`).keys().next().value ?? raw;
161
+ }
162
+ /**
163
+ * Copy a captured request/response body with credential-keyed values replaced by
164
+ * `<redacted, N chars>` — JSON (at any depth) and `application/x-www-form-urlencoded`.
165
+ * `contentType`, when the exchange's header is known, makes a declared form
166
+ * parse as one even if it breaks the shape heuristic (raw spaces).
167
+ *
168
+ * A login POST and the token response it gets back carry the secret in the BODY,
169
+ * which reaches the driver on every network read and `network.log` on failure;
170
+ * the header and URL redactors above never see it. Anything else (plain text, HTML,
171
+ * a body with nothing sensitive in it) comes back byte-for-byte untouched.
172
+ */
173
+ export function redactBody(body, contentType) {
174
+ const trimmed = body.trim();
175
+ // Every masker that applies, whatever the declared type says: a body that
176
+ // PARSES as JSON is JSON-masked (a JSON login mislabelled as a form included),
177
+ // and only a body that does NOT parse gets the form check — so valid JSON
178
+ // holding `=` is never form-split, and a failed parse (`[x]=1&password=…`)
179
+ // falls through to the form masker, never to "return untouched".
180
+ const parsed = parseJson(trimmed);
181
+ if (parsed !== NOT_JSON)
182
+ return maskJson(parsed) ? JSON.stringify(parsed) : body;
183
+ if (!isForm(trimmed, contentType))
184
+ return body;
185
+ let masked = false;
186
+ const out = trimmed
187
+ .split('&')
188
+ .map((pair) => {
189
+ const eq = pair.indexOf('=');
190
+ if (eq === -1 || !isSensitiveKey(formKey(pair.slice(0, eq))))
191
+ return pair;
192
+ masked = true;
193
+ return `${pair.slice(0, eq)}=${marker(pair.length - eq - 1)}`;
194
+ })
195
+ .join('&');
196
+ return masked ? out : body;
114
197
  }
115
198
  // --- Normalizers ------------------------------------------------------------
116
199
  /** Map a CDP console `type()` onto the normalized {@link ConsoleEntry} level. */
@@ -133,20 +216,12 @@ export function normalizeConsoleLevel(type) {
133
216
  }
134
217
  }
135
218
  // --- Line formatting (durable log trail) ------------------------------------
136
- /** ISO-8601 stamp from epoch ms; deterministic given the injected clock. */
137
- function stamp(ts) {
138
- return new Date(ts).toISOString();
139
- }
140
- /** Render a {@link ConsoleEntry} as one greppable `logs/console.log` line. */
141
- export function formatConsoleLine(entry) {
142
- const where = entry.location ? ` @ ${entry.location}` : '';
143
- return `${stamp(entry.timestamp)} ${entry.level.toUpperCase()} ${entry.text}${where}`;
144
- }
145
219
  /** One log line's worth of a captured body — single-line, hard-capped, never secret-bearing. */
146
220
  function bodySnippet(label, body) {
147
221
  if (body === undefined || body.length === 0)
148
222
  return '';
149
- return ` ${label}=${JSON.stringify(truncateBody(body, 500))}`;
223
+ // `JSON.stringify` escapes CR/LF but leaves U+2028/U+2029 raw — fold those too.
224
+ return ` ${label}=${oneLine(JSON.stringify(truncateBody(body, 500)))}`;
150
225
  }
151
226
  /**
152
227
  * Render a {@link NetworkEntry} as one greppable `logs/network.log` line.
@@ -156,11 +231,13 @@ function bodySnippet(label, body) {
156
231
  * the exact dead end this log exists to prevent.
157
232
  */
158
233
  export function formatNetworkLine(entry) {
159
- const head = `${stamp(entry.timestamp)} ${entry.method} ${entry.url}`;
234
+ // Every page-controlled field is folded to one line (`oneLine`): a URL, method or
235
+ // error carrying a line break would otherwise plant a forged row in the trail.
236
+ const head = `${stamp(entry.timestamp)}${tabMarker(entry.tab)} ${oneLine(entry.method)} ${oneLine(entry.url)}`;
160
237
  const sent = bodySnippet('req', entry.requestBody);
161
238
  if (entry.error !== undefined)
162
- return `${head} → FAILED ${entry.error}${sent}`;
163
- const type = entry.resourceType ? ` [${entry.resourceType}]` : '';
239
+ return `${head} → FAILED ${oneLine(entry.error)}${sent}`;
240
+ const type = entry.resourceType ? ` [${oneLine(entry.resourceType)}]` : '';
164
241
  const took = entry.durationMs !== undefined ? ` ${entry.durationMs}ms` : '';
165
242
  const got = entry.ok ? '' : bodySnippet('res', entry.responseBody);
166
243
  return `${head} → ${entry.status}${type}${took}${sent}${got}`;
@@ -1 +1 @@
1
- {"version":3,"file":"log-format.js","sourceRoot":"","sources":["../../../src/adapters/browser/log-format.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,CAAC;AAE7B,0FAA0F;AAC1F,MAAM,gBAAgB,GACpB,8FAA8F,CAAC;AAEjG,qFAAqF;AACrF,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,GAAG,GAAG,QAAQ;IACvD,IAAI,IAAI,CAAC,MAAM,IAAI,GAAG;QAAE,OAAO,IAAI,CAAC;IACpC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,gBAAgB,IAAI,CAAC,MAAM,eAAe,CAAC;AACzE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,OAA+B;IAC3D,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACpD,GAAG,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,cAAc,KAAK,CAAC,MAAM,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;IACxF,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;GAKG;AACH,MAAM,eAAe,GACnB,oJAAoJ,CAAC;AAEvJ;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW;IACnC,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AAK,SAAS,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,UAAU,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5E,MAAM,GAAG,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;IACnE,OAAO,GAAG,IAAI,MAAM,KAAK,CAAC,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,GAAG,EAAE,CAAC;AAChE,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Tab identity for one browser run — the registry that NAMES a tab.
3
+ *
4
+ * A browser tab is named by a stable label (`tab-1`, `tab-2`, …) that follows
5
+ * the PAGE, never its position in the tab list. Positions do not survive the
6
+ * run: `switch_tab` takes an index, closing an earlier tab shifts every later
7
+ * index down, and a row captured before the shift would land under the wrong
8
+ * tab. So a label is handed out on FIRST SIGHT of a page and is never
9
+ * renumbered and never reused — a closed tab's label is never handed to some
10
+ * other page later in the same run.
11
+ *
12
+ * ONE registry per run: the CDP capture stamps a row with the label of the
13
+ * page the event fired on, and the adapter's `tabs()` listing reports the same
14
+ * label — so a `[tab-2]` marker in `logs/console.log` resolves to the tab the
15
+ * driver drove, and a row captured before a switch still names its own tab.
16
+ *
17
+ * The label is an opaque marker: it carries no URL, no title and no secret —
18
+ * only the shape `tab-N`.
19
+ */
20
+ import type { Page } from 'playwright-core';
21
+ export declare class TabContext {
22
+ #private;
23
+ /**
24
+ * The label of `page`, assigning one the first time the page is seen.
25
+ *
26
+ * Idempotent: the same page always gets the same label for the whole run,
27
+ * and a page seen for the first time joins the sequence at the end.
28
+ */
29
+ label(page: Page): string;
30
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Tab identity for one browser run — the registry that NAMES a tab.
3
+ *
4
+ * A browser tab is named by a stable label (`tab-1`, `tab-2`, …) that follows
5
+ * the PAGE, never its position in the tab list. Positions do not survive the
6
+ * run: `switch_tab` takes an index, closing an earlier tab shifts every later
7
+ * index down, and a row captured before the shift would land under the wrong
8
+ * tab. So a label is handed out on FIRST SIGHT of a page and is never
9
+ * renumbered and never reused — a closed tab's label is never handed to some
10
+ * other page later in the same run.
11
+ *
12
+ * ONE registry per run: the CDP capture stamps a row with the label of the
13
+ * page the event fired on, and the adapter's `tabs()` listing reports the same
14
+ * label — so a `[tab-2]` marker in `logs/console.log` resolves to the tab the
15
+ * driver drove, and a row captured before a switch still names its own tab.
16
+ *
17
+ * The label is an opaque marker: it carries no URL, no title and no secret —
18
+ * only the shape `tab-N`.
19
+ */
20
+ export class TabContext {
21
+ /** Page → its label. Weak: a closed tab's entry evaporates with the page. */
22
+ #labels = new WeakMap();
23
+ /** Next label number — monotonic and never reused, so a marker never changes meaning. */
24
+ #next = 1;
25
+ /**
26
+ * The label of `page`, assigning one the first time the page is seen.
27
+ *
28
+ * Idempotent: the same page always gets the same label for the whole run,
29
+ * and a page seen for the first time joins the sequence at the end.
30
+ */
31
+ label(page) {
32
+ const known = this.#labels.get(page);
33
+ if (known !== undefined)
34
+ return known;
35
+ const label = `tab-${this.#next}`;
36
+ this.#next += 1;
37
+ this.#labels.set(page, label);
38
+ return label;
39
+ }
40
+ }
41
+ //# sourceMappingURL=tab-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tab-context.js","sourceRoot":"","sources":["../../../src/adapters/browser/tab-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,MAAM,OAAO,UAAU;IACrB,6EAA6E;IACpE,OAAO,GAAG,IAAI,OAAO,EAAgB,CAAC;IAC/C,yFAAyF;IACzF,KAAK,GAAG,CAAC,CAAC;IAEV;;;;;OAKG;IACH,KAAK,CAAC,IAAU;QACd,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC;QACtC,MAAM,KAAK,GAAG,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;QAClC,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC;QAChB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
@@ -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
@@ -130,6 +135,8 @@ export interface WaitOptions {
130
135
  networkIdle?: boolean;
131
136
  /** Hard cap in ms; on expiry the adapter throws (never resolves silently). */
132
137
  timeout?: number;
138
+ /** Abort the wait early (run ended/timed out); the adapter rejects with an AbortError-named error. */
139
+ signal?: AbortSignal;
133
140
  }
134
141
  /** Cardinal direction for {@link Adapter.scroll}; each adapter maps it to wheel/gesture deltas. */
135
142
  export type ScrollDirection = 'up' | 'down' | 'left' | 'right';
@@ -152,6 +159,15 @@ export interface ConsoleEntry {
152
159
  location?: string;
153
160
  /** Capture time, ms since epoch. */
154
161
  timestamp: number;
162
+ /**
163
+ * Stable label of the tab that produced the row (`tab-1`, `tab-2`, …).
164
+ *
165
+ * The label follows the PAGE for the whole run: it survives a tab switch and
166
+ * a closing tab shifting the positional indices, so the index a driver passes
167
+ * to `switch_tab` never has to name a tab. Absent on targets that have no
168
+ * tabs (desktop, mobile).
169
+ */
170
+ tab?: string;
155
171
  }
156
172
  /** One network exchange captured from the target (CDP responses + failures). */
157
173
  export interface NetworkEntry {
@@ -159,9 +175,15 @@ export interface NetworkEntry {
159
175
  method: string;
160
176
  /** Request URL. */
161
177
  url: string;
162
- /** HTTP status code; `0` when the request failed/aborted before a response. */
178
+ /**
179
+ * HTTP status code; `0` when there is no response — the request failed/aborted
180
+ * (`error` set) OR is still in flight (`pending: true`, no `error`).
181
+ */
163
182
  status: number;
164
- /** `true` for a settled `2xx`/`3xx`; `false` for `4xx`/`5xx` or a failure. */
183
+ /**
184
+ * `true` for a settled `2xx`/`3xx`; `false` for `4xx`/`5xx`, a failure, or a
185
+ * {@link NetworkEntry.pending} row (not ok YET — `error` tells a failure apart).
186
+ */
165
187
  ok: boolean;
166
188
  /** Resource kind — `'fetch' | 'xhr' | 'document' | 'image' | …` — for filtering. */
167
189
  resourceType?: string;
@@ -170,9 +192,10 @@ export interface NetworkEntry {
170
192
  /** Capture time, ms since epoch. */
171
193
  timestamp: number;
172
194
  /**
173
- * Wall-clock ms from the request leaving the page to its response arriving.
174
- * Absent when the request never produced a response, or when it was already
175
- * in flight before capture started.
195
+ * Wall-clock ms from the request leaving the page to its response arriving —
196
+ * or, on a {@link NetworkEntry.pending} row, the time in flight SO FAR (it
197
+ * grows on every read). Absent when a request failed without a timed start,
198
+ * or when it was already in flight before capture started.
176
199
  */
177
200
  durationMs?: number;
178
201
  /**
@@ -196,23 +219,96 @@ export interface NetworkEntry {
196
219
  * (and from there, logs, findings, and the caller's transcript).
197
220
  */
198
221
  responseHeaders?: Record<string, string>;
222
+ /**
223
+ * Stable label of the tab that produced the exchange (`tab-1`, `tab-2`, …).
224
+ *
225
+ * Stamped when the response FIRED, not when its log line is written: the line
226
+ * lands only after the body/header await resolves, and by then the driver may
227
+ * have switched tabs. Same rationale as {@link ConsoleEntry.tab}.
228
+ */
229
+ tab?: string;
230
+ /**
231
+ * `true` when the request was SENT but had neither a response nor a failure
232
+ * at read time — the hung call behind a spinner that never stops. Such a row
233
+ * carries `status: 0`, `ok: false` (not ok YET) and no `error` (not failed),
234
+ * `timestamp` is when it was sent, and `durationMs` the time in flight so far.
235
+ * Absent on every settled exchange.
236
+ */
237
+ pending?: boolean;
199
238
  }
239
+ /**
240
+ * Where captured console/network lines are streamed — the seam between an
241
+ * adapter's capture and the run's durable log trail.
242
+ *
243
+ * Declared HERE, in the contract, because two adapters stream to it (the browser's
244
+ * CDP capture and the android logcat drain): a second declaration would be a second
245
+ * type identity for the same seam. `browser/cdp.ts` re-exports it, so every reader
246
+ * of the capture channel keeps its import path.
247
+ */
248
+ export type CaptureSink = (channel: 'console' | 'network', line: string) => void;
200
249
  /** One open tab/window of a multi-tab target (web). */
201
250
  export interface TabInfo {
202
251
  /** Position in the target's tab list — what {@link Adapter.selectTab} takes. */
203
252
  index: number;
204
- /** Current URL of the tab. */
253
+ /**
254
+ * Current URL of the tab. Credential-bearing query values (`?code=`,
255
+ * `?token=`, `?signature=`, …) are redacted to `<redacted, N chars>` before
256
+ * the URL is returned — the same posture as {@link NetworkEntry.url} and
257
+ * unrequested loads — so tab listings are safe to surface. Any future
258
+ * `tabs()` implementation must keep this guarantee.
259
+ */
205
260
  url: string;
206
261
  /** Document title, empty while a fresh tab is still loading. */
207
262
  title: string;
208
- /** Whether this is the tab the adapter currently drives. */
263
+ /**
264
+ * Stable label of this tab (`tab-1`, `tab-2`, …) — the same marker the
265
+ * console/network rows carry, so a `[tab-2]` line in the durable log resolves
266
+ * to the tab that produced it. The label follows the PAGE, so it stays valid
267
+ * after an earlier tab closes and the indices shift. Absent when the target
268
+ * has no tab registry.
269
+ */
270
+ id?: string;
271
+ /** Whether this is the tab the adapter currently drives, independent of visibility. */
209
272
  active: boolean;
273
+ /** Live document.visibilityState === 'visible', when measured; not OS-window focus. */
274
+ visible?: boolean;
210
275
  }
276
+ /**
277
+ * Which selector grammar a target's `find({query})` parses — and therefore which
278
+ * grammar the belt must EMIT, since the driver copies a node's `target` verbatim
279
+ * into `act`.
280
+ *
281
+ * - `web` — Playwright engines (`data-testid="…"`, `role=button[name="…" i]`,
282
+ * `text=…`, `>> nth=N`), normalized by `adapters/browser/query.ts`.
283
+ * - `native` — the desktop (AT-SPI) and android (uiautomator) parsers, which take
284
+ * exactly two shapes and NOTHING else: `role "name"`, or a bare substring. The
285
+ * substring matches the node's name on desktop, and the node's name OR its
286
+ * `resource-id` on android — so a bare `resource-id` (android's `testid`)
287
+ * resolves there too. An engine-prefixed web selector degrades to a literal
288
+ * substring, matches nothing, and `act` throws `no element matched …`.
289
+ *
290
+ * DECLARED per adapter ({@link Adapter.selectorDialect}) — never inferred from
291
+ * the optional `tabs` capability, which says nothing about the grammar a target
292
+ * parses.
293
+ */
294
+ export type SelectorDialect = 'web' | 'native';
211
295
  /**
212
296
  * One contract, three protocols. The agent loop calls only these methods; each
213
297
  * adapter wires them to its real backend (CDP / X11-Wayland / ADB).
214
298
  */
215
299
  export interface Adapter {
300
+ /**
301
+ * The selector grammar this adapter's `find`/`click`/`type` parse — DECLARED,
302
+ * never inferred.
303
+ *
304
+ * The belt emits every tree node's `target` in this dialect and the driver
305
+ * copies it verbatim, so a target in the wrong dialect makes every click and
306
+ * type fail. It used to be inferred from {@link Adapter.tabs}, which is a
307
+ * CAPABILITY, not a dialect marker: a target that grows a tab listing must not
308
+ * silently switch the grammar the belt hands the driver. A missing or unknown
309
+ * declaration now fails loud rather than falling back to `web`.
310
+ */
311
+ readonly selectorDialect: SelectorDialect;
216
312
  /**
217
313
  * Go to the app: navigate to a URL (web) · launch/focus the window (desktop) · start the activity (android).
218
314
  *
@@ -258,6 +354,9 @@ export interface Adapter {
258
354
  * List the target's open tabs, newest last. OPTIONAL — implemented by targets
259
355
  * that have a tab concept (web); absent elsewhere, and the belt says so rather
260
356
  * than pretending a single-window target has one tab.
357
+ *
358
+ * A CAPABILITY, not a dialect marker: it says nothing about
359
+ * {@link Adapter.selectorDialect}, which every adapter declares on its own.
261
360
  */
262
361
  tabs?(): Promise<TabInfo[]>;
263
362
  /**
@@ -286,6 +385,10 @@ export interface Adapter {
286
385
  * durable findings, the same posture the network capture holds for its URLs.
287
386
  */
288
387
  takeUnrequestedLoads?(): Promise<string[]>;
289
- /** Release the target: stop a **managed** process; for **attach**, disconnect only — never stop it. */
388
+ /**
389
+ * Release the target: stop a **managed** process; for **attach**, disconnect
390
+ * only — never stop it. The web adapter first returns an adopted tab to its
391
+ * pre-run URL (best-effort).
392
+ */
290
393
  close(): Promise<void>;
291
394
  }
@@ -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
+ }