@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
@@ -0,0 +1,522 @@
1
+ /**
2
+ * Chromium system-library pre-check — the gate `bin/setup` runs BEFORE its
3
+ * launch verification.
4
+ *
5
+ * A headless Chromium that cannot resolve `libX.so` fails at launch with a
6
+ * stack trace naming no library, so the failure surfaces deep inside
7
+ * `bin/check` / `bun test` instead of at setup. This module resolves the
8
+ * library question directly: it locates pinned Chromium and its headless shell
9
+ * in the Playwright cache dir, runs `ldd` on both, and reports the libraries the
10
+ * loader cannot find.
11
+ *
12
+ * Contract (the shape `bin/setup` depends on):
13
+ * - exit 0 — every shared library resolves.
14
+ * - exit 1 — libraries are missing and could not be installed. stderr
15
+ * carries a message STARTING WITH `X_CHROMIUM_LIBS_MISSING:` naming every
16
+ * missing library and the remediation command.
17
+ *
18
+ * The binaries checked are the ones playwright-core will actually LAUNCH: the
19
+ * `chromium-<rev>` and `chromium_headless_shell-<rev>` dirs whose revision the installed
20
+ * playwright-core pins in `node_modules/playwright-core/browsers.json`. A
21
+ * cache that also holds other revisions (left by earlier playwright versions)
22
+ * must not be mistaken for the pinned one — a healthy foreign binary says
23
+ * nothing about the pinned one, and a broken foreign one would block a
24
+ * healthy pinned browser on unrelated dependencies.
25
+ *
26
+ * Remediation runs only when the libraries are missing AND elevation for the
27
+ * ACTUAL installer command is available noninteractively.
28
+ * `node node_modules/playwright-core/cli.js install-deps chromium` elevates
29
+ * through `sudo -- sh -c ...` and PROMPTS for a password when sudo wants one,
30
+ * which would hang a CI/setup run forever. So noninteractivity is enforced on
31
+ * the invocation itself — the installer runs under `sudo -n` (never a bare
32
+ * sudo; as root, without sudo at all), and the probe reads the POLICY for
33
+ * that exact argv via `sudo -n -ll <command…>` — the long listing, the only
34
+ * COMMAND-SCOPED query whose output carries the authentication tag on GNU
35
+ * sudo (the short `sudo -l <command…>` prints just the fully-qualified path
36
+ * and arguments, with no tag at all). Exit 0 alone is only the LISTING
37
+ * answer: under sudo's default `listpw=any` a password-required command is
38
+ * listed without a password whenever the user holds ANY NOPASSWD rule — so
39
+ * elevation additionally requires the matched entry to render the NOPASSWD
40
+ * tag, which the long form spells `!authenticate` (`authenticate` there =
41
+ * PASSWD). A sudo whose `-ll` listing is TAGLESS all the same — sudo-rs, the
42
+ * default sudo on recent Ubuntu images, accepts `-ll` but prints the same
43
+ * short form as `-l` (real CI: `sudo -n -ll /bin/true` on a `NOPASSWD: ALL`
44
+ * host printed just `/bin/true`) — cannot answer that way. There the probe
45
+ * falls back to the FULL listing and accepts only `NOPASSWD: ALL`: exit 0 on
46
+ * `-ll` already proved THIS command is listed, and a full listing rendering
47
+ * `NOPASSWD: ALL` proves everything listed executes without a password. A
48
+ * narrower NOPASSWD scope behind a tagless `-ll` (a RunAs-scoped ALL, a
49
+ * per-command rule) has no portable query to prove it and answers false —
50
+ * the blocked diagnostic; a wrong `true` there would still be caught by the
51
+ * installer's own `sudo -n`, which fails instantly and loud, never hangs. A
52
+ * sudoers rule permitting passwordless `true` while the install command
53
+ * itself needs a password therefore fails here, loud, instead of passing a
54
+ * probe and hitting the password demand mid-install. Without elevation the
55
+ * check fails with the diagnostic instead of attempting an install that
56
+ * would block on a prompt.
57
+ *
58
+ * A failing install stays a failure. `install-deps` is allowed to fix the
59
+ * machine; it is never allowed to make a broken machine look healthy.
60
+ *
61
+ * The module NEVER launches Chromium — the launch check stays `bin/setup`'s
62
+ * own final gate.
63
+ */
64
+ import { execFileSync } from 'node:child_process';
65
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
66
+ import { join } from 'node:path';
67
+ import { ChromiumLibsMissingError } from '../errors.js';
68
+ /**
69
+ * The repo-pinned Playwright CLI invocation that installs the Chromium system
70
+ * dependencies. NEVER `bunx playwright` — that resolves an unpinned version.
71
+ */
72
+ export const INSTALL_DEPS_COMMAND = 'node node_modules/playwright-core/cli.js install-deps chromium';
73
+ /** Machine-readable marker every failure message starts with. */
74
+ export const MISSING_LIBS_MARKER = 'X_CHROMIUM_LIBS_MISSING:';
75
+ /**
76
+ * Directory prefixes of the Playwright cache that hold the Chromium headless
77
+ * shell. The revision suffix varies with the pinned playwright-core version,
78
+ * so the dir name is matched by prefix and the revision read from the dir.
79
+ */
80
+ const HEADLESS_SHELL_DIR_PREFIX = 'chromium_headless_shell-';
81
+ /**
82
+ * Candidate file names of the headless shell, across the layouts Playwright
83
+ * has shipped (linux-x64 `chrome-headless-shell`, linux-arm64 `headless_shell`).
84
+ * The dir is SCANNED rather than hardcoded — a layout change must degrade to
85
+ * "binary not found", never to "libX.so missing" (a wrong answer).
86
+ */
87
+ const HEADLESS_SHELL_BINARIES = ['chrome-headless-shell', 'headless_shell'];
88
+ /** Subdirectories (relative to the cache dir) the headless shell may live in. */
89
+ const HEADLESS_SHELL_SUBDIRS = ['chrome-headless-shell-linux64', 'chrome-linux', 'chrome-linux64'];
90
+ /**
91
+ * The installed playwright-core's revision manifest — the same one `bin/setup`
92
+ * reads for the skip-when-cached check. Resolved relative to this module, so
93
+ * the CLI works from any cwd as long as it runs from this checkout.
94
+ */
95
+ export const BROWSERS_JSON_PATH = join(import.meta.dirname, '../../node_modules/playwright-core/browsers.json');
96
+ /**
97
+ * Parse the headless-shell revision the installed playwright-core pins — the
98
+ * revision of the binary a `chromium.launch({ headless: true })` will run.
99
+ *
100
+ * Modern manifests name it `chromium-headless-shell`; older ones only name
101
+ * `chromium` (same revision for both). `null` when the manifest is unreadable,
102
+ * invalid, or names neither — the caller then falls back to scanning the cache
103
+ * rather than answering from a guess.
104
+ */
105
+ export function readPinnedHeadlessShellRevision(manifestPath = BROWSERS_JSON_PATH) {
106
+ let raw;
107
+ try {
108
+ raw = readFileSync(manifestPath, 'utf8');
109
+ }
110
+ catch {
111
+ return null;
112
+ }
113
+ let manifest;
114
+ try {
115
+ manifest = JSON.parse(raw);
116
+ }
117
+ catch {
118
+ return null;
119
+ }
120
+ if (!Array.isArray(manifest.browsers))
121
+ return null;
122
+ const entry = manifest.browsers.find((b) => b.name === 'chromium-headless-shell') ??
123
+ manifest.browsers.find((b) => b.name === 'chromium');
124
+ if (!entry || (typeof entry.revision !== 'string' && typeof entry.revision !== 'number')) {
125
+ return null;
126
+ }
127
+ const rev = Number.parseInt(String(entry.revision), 10);
128
+ return Number.isNaN(rev) ? null : rev;
129
+ }
130
+ /**
131
+ * Parse the shared libraries `ldd` could not resolve.
132
+ *
133
+ * `ldd` prints one line per dependency and reports an unresolved one as
134
+ * `libX.so => not found`. The library name is the text LEFT of the `=>` — the
135
+ * right side is the (absent) resolved path.
136
+ *
137
+ * @param lddOutput combined stdout/stderr of an `ldd` run.
138
+ * @returns the missing library names, de-duplicated, in first-seen order.
139
+ */
140
+ export function parseMissingLibs(lddOutput) {
141
+ const missing = [];
142
+ const seen = new Set();
143
+ for (const rawLine of lddOutput.split('\n')) {
144
+ const line = rawLine.trim();
145
+ if (!line)
146
+ continue;
147
+ const arrow = line.indexOf('=>');
148
+ if (arrow < 0)
149
+ continue;
150
+ if (!line
151
+ .slice(arrow + 2)
152
+ .trim()
153
+ .startsWith('not found'))
154
+ continue;
155
+ const name = line.slice(0, arrow).trim();
156
+ if (!name || seen.has(name))
157
+ continue;
158
+ seen.add(name);
159
+ missing.push(name);
160
+ }
161
+ return missing;
162
+ }
163
+ /**
164
+ * The diagnostic for missing libraries. Starts with {@link MISSING_LIBS_MARKER}
165
+ * (the marker CI greps for) and names every missing library plus the command
166
+ * that installs them.
167
+ */
168
+ export function formatMissingLibsMessage(missing, installCommand = INSTALL_DEPS_COMMAND, binary = 'the Chromium headless shell') {
169
+ const libs = missing.length > 0 ? missing.join(', ') : '(none listed)';
170
+ return (`${MISSING_LIBS_MARKER} ${missing.length} shared librar${missing.length === 1 ? 'y' : 'ies'} ` +
171
+ `missing for ${binary}: ${libs}. ` +
172
+ `Fix with: ${installCommand}`);
173
+ }
174
+ /**
175
+ * Decide how to remediate the missing libraries.
176
+ *
177
+ * `none` — nothing is missing, so nothing is attempted.
178
+ * `install-deps` — libraries are missing and noninteractive elevation exists,
179
+ * so the pinned install-deps command may run.
180
+ * `blocked` — libraries are missing but elevation is unavailable; the message
181
+ * is the diagnostic to report. The install is NOT attempted (it would prompt).
182
+ */
183
+ export function remediationPlan(missing, elevated, installCommand = INSTALL_DEPS_COMMAND) {
184
+ if (missing.length === 0)
185
+ return { kind: 'none' };
186
+ if (!elevated) {
187
+ return { kind: 'blocked', message: formatMissingLibsMessage(missing, installCommand) };
188
+ }
189
+ return { kind: 'install-deps', command: installCommand };
190
+ }
191
+ /**
192
+ * The revision number of a `chromium_headless_shell-<rev>` dir name, or -1
193
+ * when the suffix is not numeric.
194
+ */
195
+ function shellRevision(dirName) {
196
+ const suffix = dirName.slice(dirName.lastIndexOf('-') + 1);
197
+ const rev = Number.parseInt(suffix, 10);
198
+ return Number.isNaN(rev) ? -1 : rev;
199
+ }
200
+ /**
201
+ * Scan ONE `chromium_headless_shell-<rev>` dir for the executable — the known
202
+ * names/subpaths first, then a shallow scan of the dir itself: a layout that
203
+ * changed in an unforeseen way still resolves rather than reporting a missing
204
+ * binary. `null` when this dir holds no executable we recognize.
205
+ */
206
+ function binaryIn(base, subdirs, binaries) {
207
+ for (const sub of subdirs) {
208
+ for (const bin of binaries) {
209
+ const candidate = join(base, sub, bin);
210
+ if (existsSync(candidate))
211
+ return candidate;
212
+ }
213
+ }
214
+ for (const bin of binaries) {
215
+ const candidate = join(base, bin);
216
+ if (existsSync(candidate))
217
+ return candidate;
218
+ }
219
+ return null;
220
+ }
221
+ /**
222
+ * Locate the PINNED Chromium headless-shell binary inside the Playwright
223
+ * cache dir — the binary `chromium.launch()` will actually execute.
224
+ *
225
+ * With a `pinnedRevision` (from {@link readPinnedHeadlessShellRevision}), ONLY
226
+ * that revision's `chromium_headless_shell-<rev>` dir is acceptable: a cache
227
+ * holding a NEWER revision too (left by another playwright version) must not
228
+ * be checked in its place — the launch uses the pinned one, and a foreign
229
+ * binary answers the wrong question in both directions. When the pinned dir is
230
+ * absent the check must fail (launch would fail too), never pass off another
231
+ * revision's binary.
232
+ *
233
+ * Without a pinned revision (manifest unreadable), it falls back to scanning
234
+ * for the `chromium_headless_shell-<rev>` folder and the known executable
235
+ * names/subpaths inside it — the layout moves between playwright-core
236
+ * versions, so it is discovered, never hardcoded.
237
+ */
238
+ export function locateHeadlessShell(cacheDir, pinnedRevision) {
239
+ return locateCachedBinary(cacheDir, pinnedRevision, HEADLESS_SHELL_DIR_PREFIX, HEADLESS_SHELL_SUBDIRS, HEADLESS_SHELL_BINARIES);
240
+ }
241
+ /** Full Chromium: explicit executablePath launches this rather than the shell. */
242
+ export function locateChromium(cacheDir, pinnedRevision) {
243
+ return locateCachedBinary(cacheDir, pinnedRevision, 'chromium-', ['chrome-linux64', 'chrome-linux'], ['chrome']);
244
+ }
245
+ function locateCachedBinary(cacheDir, pinnedRevision, prefix, subdirs, binaries) {
246
+ if (!existsSync(cacheDir))
247
+ return null;
248
+ if (pinnedRevision !== undefined && pinnedRevision !== null) {
249
+ return binaryIn(join(cacheDir, `${prefix}${pinnedRevision}`), subdirs, binaries);
250
+ }
251
+ let entries;
252
+ try {
253
+ entries = readdirSync(cacheDir);
254
+ }
255
+ catch {
256
+ return null;
257
+ }
258
+ const shellDirs = entries
259
+ .filter((name) => name.startsWith(prefix))
260
+ // Highest revision first: the suffix is numeric, and a lexical sort would
261
+ // put "9999" before "1228" (the pinned revision is the older one here).
262
+ .sort((a, b) => shellRevision(b) - shellRevision(a));
263
+ for (const dir of shellDirs) {
264
+ const found = binaryIn(join(cacheDir, dir), subdirs, binaries);
265
+ if (found)
266
+ return found;
267
+ }
268
+ return null;
269
+ }
270
+ /** The stdout/stderr of a failed exec run, as strings (empty when absent). */
271
+ function capturedOutput(err) {
272
+ if (typeof err !== 'object' || err === null)
273
+ return { stdout: '', stderr: '' };
274
+ const failure = err;
275
+ return {
276
+ stdout: typeof failure.stdout === 'string' ? failure.stdout : '',
277
+ stderr: typeof failure.stderr === 'string' ? failure.stderr : '',
278
+ };
279
+ }
280
+ /**
281
+ * Default `ldd` runner: the real thing, combined stdout+stderr.
282
+ *
283
+ * `ldd` exits NON-ZERO precisely when a shared library is missing — the exact
284
+ * case this module exists to detect — so `execFileSync` throws and the output
285
+ * is trapped inside the thrown error. Letting that throw escape would abort
286
+ * the check BEFORE `parseMissingLibs` ever ran: the raw `Command failed: ldd
287
+ * …` text would reach stderr, naming no library and no fix, and the
288
+ * remediation path would never be reached.
289
+ *
290
+ * So the non-zero exit is treated as DATA, not as an error: the captured
291
+ * stdout+stderr is returned for parsing. The library listing (`libX.so => not
292
+ * found`) is printed on stdout even when `ldd` exits non-zero, and the
293
+ * diagnostics land on stderr — hence both streams, combined.
294
+ */
295
+ export const runLdd = (binary) => {
296
+ try {
297
+ return execFileSync('ldd', [binary], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });
298
+ }
299
+ catch (err) {
300
+ const { stdout, stderr } = capturedOutput(err);
301
+ const combined = `${stdout}${stderr}`;
302
+ // `ldd` failed without producing a library listing at all (e.g. "not a
303
+ // dynamic executable", or `ldd` missing from PATH). The check cannot
304
+ // conclude anything from that, so it fails LOUD — reporting "every
305
+ // library resolves" off a run that never resolved one would be a false
306
+ // healthy. A listing that DOES contain `=>` lines is a real answer and is
307
+ // handed to the parser, missing libraries included.
308
+ if (!combined.includes('=>')) {
309
+ throw new ChromiumLibsMissingError(`${MISSING_LIBS_MARKER} \`ldd\` could not resolve the shared libraries of ` +
310
+ `${binary}: ${combined.trim() || 'no output'}. ` +
311
+ `Fix with: ${INSTALL_DEPS_COMMAND}`);
312
+ }
313
+ return combined;
314
+ }
315
+ };
316
+ /** Split a fixed, repo-owned command string on whitespace (never user input). */
317
+ function splitCommand(command) {
318
+ const [bin, ...args] = command.split(' ');
319
+ return bin ? { bin, args } : null;
320
+ }
321
+ /** Is this process running as root (no sudo needed at all)? */
322
+ function isRoot() {
323
+ return typeof process.getuid === 'function' && process.getuid() === 0;
324
+ }
325
+ /**
326
+ * Run `sudo -n <argv…>` capturing stdout; `null` when it exits non-zero or
327
+ * cannot run. The locale is pinned to C so the tokens matched against the
328
+ * listings (`!authenticate`, `NOPASSWD: ALL`) are never translated.
329
+ */
330
+ function sudoListing(argv) {
331
+ try {
332
+ return execFileSync('sudo', ['-n', ...argv], {
333
+ encoding: 'utf8',
334
+ stdio: ['ignore', 'pipe', 'pipe'],
335
+ env: { ...process.env, LC_ALL: 'C', LANG: 'C' },
336
+ });
337
+ }
338
+ catch {
339
+ return null;
340
+ }
341
+ }
342
+ /**
343
+ * Default elevation probe: COMMAND-SCOPED, reading BOTH permissions sudo
344
+ * keeps separate — via the LONG listing (`sudo -n -ll <command…>`), the only
345
+ * command-scoped query whose output carries the authentication tag on GNU
346
+ * sudo.
347
+ *
348
+ * The short listing (`sudo -l <command…>`) does NOT: real sudo (verified
349
+ * against 1.9.15p5; pinned by the real-sudo regressions in
350
+ * `chromium-libs.test.ts`) prints just the fully-qualified path and arguments
351
+ * for a permitted command — no `NOPASSWD` token, whether the matched rule is
352
+ * NOPASSWD or PASSWD — so a tag read over the short listing rejects every
353
+ * passwordless host.
354
+ *
355
+ * `-ll` on a listed command prints the matched sudoers entry, rendering the
356
+ * tag as an option:
357
+ *
358
+ * Sudoers entry: /etc/sudoers.d/ci
359
+ * RunAsUsers: ALL
360
+ * Options: !authenticate <- the NOPASSWD tag ...
361
+ * Commands:
362
+ * /bin/true
363
+ * Matched: /bin/true
364
+ *
365
+ * ... and `Options: authenticate` when the matched rule is PASSWD-tagged —
366
+ * the dangerous middle that motivated command-scoping in the first place:
367
+ * under sudo's default `listpw=any` the listing succeeds without a password
368
+ * as soon as the user holds ANY NOPASSWD rule, so a passwordless `true`
369
+ * lists a password-required install command. Exit 0 alone is therefore only
370
+ * the LISTING answer; the EXECUTION answer is the tag on the matched entry.
371
+ *
372
+ * A sudo whose `-ll` listing is TAGLESS cannot answer that way: sudo-rs —
373
+ * the default sudo on recent Ubuntu images, GitHub Actions runner images
374
+ * among them — accepts `-ll` but prints the same short form as `-l` (real
375
+ * CI: `sudo -n -ll /bin/true` on a `NOPASSWD: ALL` host printed just
376
+ * `/bin/true`). The probe falls back to the FULL listing (`sudo -n -l`,
377
+ * every privilege with its tag) and accepts only `NOPASSWD: ALL`: the `-ll`
378
+ * exit 0 already proved THIS command is listed, and `NOPASSWD: ALL` proves
379
+ * everything listed executes passwordless. A narrower NOPASSWD scope behind
380
+ * a tagless `-ll` has no portable query to prove it and stays `false` — the
381
+ * blocked diagnostic; a wrong `true` there would still be caught by the
382
+ * installer's own `sudo -n`, which fails instantly and loud. An exit-1 run
383
+ * — unlisted ("Sorry, user … may not run …"), unresolvable, or a listing
384
+ * that itself needed a password (no NOPASSWD rule anywhere) — is not
385
+ * passwordless elevation. uid 0 counts as elevated (no sudo needed at all).
386
+ */
387
+ export const probeElevation = (command) => {
388
+ if (isRoot())
389
+ return true;
390
+ const parsed = splitCommand(command);
391
+ if (!parsed)
392
+ return false;
393
+ const listing = sudoListing(['-ll', parsed.bin, ...parsed.args]);
394
+ if (listing === null) {
395
+ // Non-zero: the command is unlisted ("Sorry, user … may not run …"), or
396
+ // even the LISTING needed a password (no NOPASSWD rule anywhere, per the
397
+ // default `listpw=any`). Neither is passwordless elevation.
398
+ return false;
399
+ }
400
+ // GNU sudo renders the matched entry's authentication tag: `!authenticate`
401
+ // is exactly when `sudo -n <command…>` can succeed without a password;
402
+ // bare `authenticate` is the PASSWD render.
403
+ if (listing.includes('!authenticate'))
404
+ return true;
405
+ if (listing.includes('authenticate'))
406
+ return false;
407
+ // Exit 0 but NO tag anywhere — the tagless `-ll` (sudo-rs shape). The only
408
+ // portable execution answer left is the FULL listing's NOPASSWD: ALL; the
409
+ // command-scoped listing already succeeded, so the question left is only
410
+ // whether everything the user may run is passwordless.
411
+ return sudoListing(['-l'])?.includes('NOPASSWD: ALL') ?? false;
412
+ };
413
+ /**
414
+ * Default installer: run the command under NONINTERACTIVE elevation.
415
+ *
416
+ * As root the command runs directly (install-deps then invokes its package
417
+ * manager without any inner sudo). Otherwise the WHOLE installer is invoked as
418
+ * `sudo -n …`: elevation is enforced on the actual invocation, so a sudoers
419
+ * rule that allows passwordless `true` but wants a password for `sh` makes
420
+ * sudo FAIL here, instantly — instead of install-deps' ordinary `sudo -- sh -c
421
+ * …` prompting a CI/setup run into a permanent hang. Running as root also
422
+ * means install-deps skips its own sudo entirely.
423
+ */
424
+ export const runInstaller = (command) => {
425
+ const parsed = splitCommand(command);
426
+ if (!parsed)
427
+ throw new ChromiumLibsMissingError(`${MISSING_LIBS_MARKER} empty install command`);
428
+ if (isRoot()) {
429
+ execFileSync(parsed.bin, parsed.args, { stdio: 'inherit' });
430
+ return;
431
+ }
432
+ execFileSync('sudo', ['-n', parsed.bin, ...parsed.args], { stdio: 'inherit' });
433
+ };
434
+ /**
435
+ * Check full Chromium AND its headless shell at the existing pinned revision.
436
+ *
437
+ * Throws {@link ChromiumLibsMissingError} when libraries are missing and could
438
+ * not be installed (no elevation, or the install failed).
439
+ */
440
+ export function checkChromiumLibs(cacheDir, deps = {}) {
441
+ const pinnedRevision = deps.pinnedRevision ?? readPinnedHeadlessShellRevision;
442
+ const locate = deps.locateBinary ??
443
+ ((dir, revision, kind) => kind === 'full' ? locateChromium(dir, revision) : locateHeadlessShell(dir, revision));
444
+ const ldd = deps.ldd ?? runLdd;
445
+ const probe = deps.probeElevation ?? probeElevation;
446
+ const install = deps.install ?? runInstaller;
447
+ const revision = pinnedRevision();
448
+ const requireBinary = (kind) => {
449
+ const binary = locate(cacheDir, revision, kind);
450
+ if (binary)
451
+ return binary;
452
+ const pinned = revision !== null && revision !== undefined ? ` (revision ${revision})` : '';
453
+ const name = kind === 'shell' ? 'Chromium headless shell' : 'Chromium';
454
+ throw new ChromiumLibsMissingError(`${MISSING_LIBS_MARKER} ${name}${pinned} not found under ${cacheDir}. ` +
455
+ `Install it with: node node_modules/playwright-core/cli.js install chromium`);
456
+ };
457
+ const binary = requireBinary('shell');
458
+ const binaries = [binary, requireBinary('full')];
459
+ const inspect = () => binaries.map((path) => ({ path, missing: parseMissingLibs(ldd(path)) }));
460
+ const diagnostic = (reports) => reports
461
+ .filter((report) => report.missing.length > 0)
462
+ .map((report) => formatMissingLibsMessage(report.missing, INSTALL_DEPS_COMMAND, report.path))
463
+ .join('\n');
464
+ const reports = inspect();
465
+ const missing = [...new Set(reports.flatMap((report) => report.missing))];
466
+ // Nothing missing => nothing attempted. The elevation probe is skipped too:
467
+ // it shells out to `sudo`, and a healthy machine must not pay for it.
468
+ if (missing.length === 0)
469
+ return { ok: true, binary, binaries, missing };
470
+ const installCommand = INSTALL_DEPS_COMMAND;
471
+ // The probe is asked about the exact command the installer will run — a
472
+ // command-scoped answer, not a generic "sudo exists".
473
+ const plan = remediationPlan(missing, probe(installCommand), installCommand);
474
+ if (plan.kind === 'none')
475
+ return { ok: true, binary, binaries, missing };
476
+ if (plan.kind === 'blocked') {
477
+ throw new ChromiumLibsMissingError(diagnostic(reports));
478
+ }
479
+ // Libraries are missing and elevation is available: install them. A FAILING
480
+ // install stays a failure — the error names the failed command, so the
481
+ // operator sees which remediation broke rather than a bare non-zero exit.
482
+ try {
483
+ install(plan.command);
484
+ }
485
+ catch (err) {
486
+ const detail = err instanceof Error ? err.message : String(err);
487
+ throw new ChromiumLibsMissingError(`${MISSING_LIBS_MARKER} remediation failed: \`${plan.command}\` — ${detail}. ` +
488
+ `Resolve the missing libraries manually, then re-run.\n${diagnostic(reports)}`);
489
+ }
490
+ // The install claims success — verify, never trust. A still-missing library
491
+ // must not be reported as healthy.
492
+ const stillMissing = diagnostic(inspect());
493
+ if (stillMissing) {
494
+ throw new ChromiumLibsMissingError(stillMissing);
495
+ }
496
+ return { ok: true, binary, binaries, missing };
497
+ }
498
+ /**
499
+ * CLI entry: `bun src/cli/chromium-libs.ts <cacheDir>`.
500
+ *
501
+ * Exit 0 — every shared library resolves. Exit 1 — the diagnostic on stderr.
502
+ */
503
+ export function runCli(argv = process.argv.slice(2)) {
504
+ const cacheDir = argv[0];
505
+ if (!cacheDir) {
506
+ console.error(`${MISSING_LIBS_MARKER} usage: chromium-libs <playwright-cache-dir>`);
507
+ return 1;
508
+ }
509
+ try {
510
+ const result = checkChromiumLibs(cacheDir);
511
+ console.log(`chromium libraries OK (${result.binaries.join(', ')})`);
512
+ return 0;
513
+ }
514
+ catch (err) {
515
+ console.error(err instanceof Error ? err.message : String(err));
516
+ return 1;
517
+ }
518
+ }
519
+ if (import.meta.main) {
520
+ process.exit(runCli());
521
+ }
522
+ //# sourceMappingURL=chromium-libs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chromium-libs.js","sourceRoot":"","sources":["../../src/cli/chromium-libs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAExD;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAC/B,gEAAgE,CAAC;AAEnE,iEAAiE;AACjE,MAAM,CAAC,MAAM,mBAAmB,GAAG,0BAA0B,CAAC;AAE9D;;;;GAIG;AACH,MAAM,yBAAyB,GAAG,0BAA0B,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,uBAAuB,GAAG,CAAC,uBAAuB,EAAE,gBAAgB,CAAC,CAAC;AAE5E,iFAAiF;AACjF,MAAM,sBAAsB,GAAG,CAAC,+BAA+B,EAAE,cAAc,EAAE,gBAAgB,CAAC,CAAC;AAEnG;;;;GAIG;AAC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I,GAAa,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3D,MAAM,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,CAAC,KAAK,CAAC,GAAG,mBAAmB,8CAA8C,CAAC,CAAC;QACpF,OAAO,CAAC,CAAC;IACX,CAAC;IACD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QAC3C,OAAO,CAAC,GAAG,CAAC,0BAA0B,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACrE,OAAO,CAAC,CAAC;IACX,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAChE,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC;AAED,IAAI,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;IACrB,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;AACzB,CAAC"}
@@ -14,9 +14,11 @@
14
14
  * Neither needs the model API key — they resolve only the workspace dir.
15
15
  */
16
16
  import { readFile } from 'node:fs/promises';
17
- import { isAbsolute, join } from 'node:path';
17
+ import { isAbsolute, join, resolve } from 'node:path';
18
18
  import { loadWorkspaceDir } from '../config/load.js';
19
+ import { ConfigError } from '../errors.js';
19
20
  import { FindingsSchema } from '../findings/schema.js';
21
+ import { readLivePointer } from '../session/live-pointer.js';
20
22
  import { ownerAlive } from '../session/process-identity.js';
21
23
  import { markStatus, readState, restoreRunning } from '../session/state-file.js';
22
24
  import { resolveProject, workspacePaths } from '../session/workspace.js';
@@ -31,16 +33,54 @@ async function readFindings(sessionDir) {
31
33
  return null;
32
34
  }
33
35
  }
34
- /** Resolve `state.json` for the current project (no API key needed). */
35
- function stateJsonPath(cwd = process.cwd()) {
36
- // A relative workspace is anchored at the project root (cwd), matching the server.
37
- const base = loadWorkspaceDir(cwd);
38
- const workspace = workspacePaths(cwd, isAbsolute(base) ? base : join(cwd, base));
39
- return { project: resolveProject(cwd), stateJson: workspace.stateJson };
36
+ /** The workspace the CURRENT config resolves to; `null` when the config is unreadable/invalid. */
37
+ function configWorkspace(cwd) {
38
+ try {
39
+ // A relative workspace is anchored at the project root (cwd), matching the server.
40
+ const base = loadWorkspaceDir(cwd);
41
+ return workspacePaths(cwd, isAbsolute(base) ? base : join(cwd, base));
42
+ }
43
+ catch (err) {
44
+ if (err instanceof ConfigError)
45
+ return null;
46
+ throw err;
47
+ }
48
+ }
49
+ /**
50
+ * Resolve `state.json` for the current project (no API key needed).
51
+ *
52
+ * The server's workspace was fixed from the config at boot; the config may have
53
+ * been edited since. The live pointer names the root the server really owns, so
54
+ * it wins — even over an invalid config. A recorded pointer without its matching
55
+ * breadcrumb is config drift, not evidence that no run exists: fail loud rather
56
+ * than falling back to the current config's possibly unrelated workspace. No
57
+ * pointer (legacy server, no run yet) → the config-resolved workspace, whose
58
+ * ConfigError then surfaces loud. `drift` is set when live and config roots differ.
59
+ */
60
+ async function resolveState(cwd) {
61
+ const project = resolveProject(cwd);
62
+ const config = configWorkspace(cwd);
63
+ const liveRoot = await readLivePointer(cwd);
64
+ if (liveRoot !== null) {
65
+ const stateJson = join(liveRoot, 'state.json');
66
+ if ((await readState(stateJson)) === null) {
67
+ throw new ConfigError(`Config drift: recorded live workspace ${liveRoot} has no readable state breadcrumb at ${stateJson}. ` +
68
+ 'The config may have changed since the server started; restore the live workspace or restart the server.');
69
+ }
70
+ if (config !== null && resolve(config.root) === resolve(liveRoot)) {
71
+ return { project, stateJson };
72
+ }
73
+ const now = config === null ? 'is unreadable or invalid' : `resolves to ${config.root}`;
74
+ const drift = `the live run's workspace is ${liveRoot}, but the config now ${now} — config edited since the server started`;
75
+ return { project, stateJson, drift };
76
+ }
77
+ if (config === null)
78
+ loadWorkspaceDir(cwd); // rethrows the ConfigError — fail loud
79
+ return { project, stateJson: (config ?? workspacePaths(cwd)).stateJson };
40
80
  }
41
81
  /** `ui-debugger-mcp status` — print the active run's state + findings summary. */
42
82
  export async function runStatus(cwd = process.cwd()) {
43
- const { project, stateJson } = stateJsonPath(cwd);
83
+ const { project, stateJson, drift } = await resolveState(cwd);
44
84
  const state = await readState(stateJson);
45
85
  if (!state) {
46
86
  console.log(`ui-debugger-mcp: no debug run recorded for '${project}'.`);
@@ -71,12 +111,14 @@ export async function runStatus(cwd = process.cwd()) {
71
111
  console.log(` findings: ${counts}`);
72
112
  console.log(` started: ${state.startedAt}`);
73
113
  console.log(` session: ${state.sessionDir}`);
114
+ if (drift)
115
+ console.log(` drift: ${drift}`);
74
116
  }
75
117
  /** `ui-debugger-mcp stop` — signal the server to tear the run down, mark state stopped. */
76
118
  export async function runStop(cwd = process.cwd(), kill = (pid, signal) => {
77
119
  process.kill(pid, signal);
78
120
  }) {
79
- const { project, stateJson } = stateJsonPath(cwd);
121
+ const { project, stateJson } = await resolveState(cwd);
80
122
  const state = await readState(stateJson);
81
123
  if (!state) {
82
124
  console.log(`ui-debugger-mcp: no active debug run to stop for '${project}'.`);