@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
package/dist/boot.js ADDED
@@ -0,0 +1,145 @@
1
+ /**
2
+ * Server boot — the sequence that turns a project directory into a live stdio
3
+ * MCP server.
4
+ *
5
+ * It lives apart from the CLI (`src/main.ts`) for one reason: the boot has a
6
+ * GATE in front of it. The workspace's one-run ownership rests on a
7
+ * kernel-held `flock(2)`, and a host that cannot provide that backend can
8
+ * never enforce it — two servers would each believe it owns the workspace. So
9
+ * the gate runs FIRST: a host without a flock backend must not have created a
10
+ * workspace, read a config, probed a provider or accepted a run.
11
+ *
12
+ * Everything after the gate is the wiring `main.ts` used to do inline, moved
13
+ * verbatim: config → workspace → provider/models → self-look → the debug
14
+ * service → the outer tools → the stdio server, plus the shutdown path.
15
+ *
16
+ * Every step a test needs to observe is a seam ({@link BootDeps}), so the
17
+ * whole boot is drivable in-process — no module mock, which would leak into
18
+ * the suites running alongside.
19
+ */
20
+ import { supportsImageInput } from './agent/capabilities.js';
21
+ import { resolveModels } from './agent/models.js';
22
+ import { createOpenRouterProvider, resolveProviderConfig } from './agent/provider.js';
23
+ import { makeConfigWatch } from './config/fingerprint.js';
24
+ import { CONFIG_CANDIDATES, ignoredRootConfig, loadConfig } from './config/load.js';
25
+ import { NAME } from './index.js';
26
+ import { startStdioServer } from './mcp/server.js';
27
+ import { outerTools } from './mcp/tools/index.js';
28
+ import { DebugService } from './services/debug-service.js';
29
+ import { makeSessionBuilder } from './services/session-builder.js';
30
+ import { createShutdown } from './services/shutdown.js';
31
+ import { SessionManager } from './session/manager.js';
32
+ import { assertOwnerLockBackend } from './session/owner-lock.js';
33
+ import { FileStatePort } from './session/state-file.js';
34
+ import { ensureWorkspace, workspacePaths } from './session/workspace.js';
35
+ /**
36
+ * Boot the stdio MCP server for `cwd`.
37
+ *
38
+ * The owner-lock backend gate runs FIRST — a host that cannot lock the
39
+ * workspace must not get one. Everything after it is the wiring moved out of
40
+ * `main.ts`.
41
+ */
42
+ export async function bootServer(cwd, deps = {}) {
43
+ const gate = deps.assertOwnerLockBackend ?? (() => assertOwnerLockBackend());
44
+ const start = deps.startServer ?? startStdioServer;
45
+ const exit = deps.exit ?? ((code) => process.exit(code));
46
+ // The gate: resolve `flock(2)` WITHOUT taking the run lock. It fails loud
47
+ // when this host has no libc carrying it — and it runs before the config is
48
+ // read, before the workspace exists and before the server is started.
49
+ await gate();
50
+ // Load project config (cwd-keyed)
51
+ const config = loadConfig({ cwd });
52
+ // Both candidates on disk: name the ignored root copy ONCE, on stderr —
53
+ // stdout is the stdio MCP JSON-RPC channel and must stay machine-only.
54
+ const ignoredRoot = ignoredRootConfig(cwd);
55
+ if (ignoredRoot) {
56
+ console.error(`${NAME}: using ${CONFIG_CANDIDATES[0]} — ignoring the root ${ignoredRoot} (remove it to stop this notice)`);
57
+ }
58
+ // Bootstrap workspace directories (chrome-user-data/, sessions/).
59
+ // A relative workspace anchors at the project root; an absolute (shared) one
60
+ // gets a cwd-derived project dir — see `workspacePaths`.
61
+ const workspace = workspacePaths(cwd, config.workspace);
62
+ await ensureWorkspace(workspace);
63
+ // Resolve provider + per-role models (driver, vision, summary)
64
+ const providerOptions = {
65
+ apiKey: config.provider.apiKey,
66
+ baseURL: config.provider.baseUrl,
67
+ };
68
+ const provider = createOpenRouterProvider(providerOptions);
69
+ // Every switch to the paid fallback is reported on stderr (stdout is the
70
+ // JSON-RPC channel): a free primary that is permanently throttled shows up
71
+ // as a stream of these lines, not as a silently larger bill.
72
+ const roleModels = resolveModels(provider, config.models, (role, e) => console.error(`${NAME}: ${role} fell back ${e.primary} -> ${e.fallback} (${e.reason})`));
73
+ // Self-look: control + vision on the SAME model AND the provider catalog
74
+ // confirms it takes image input → `look` hands the frame to the driver
75
+ // itself (full context, no second call). Unknown capability (null) keeps
76
+ // the safe separate-call path — its vision latch fails soft, while an
77
+ // image pushed at a text-only driver would poison every later step.
78
+ let selfLook = false;
79
+ // The fallback can serve any driver step, so it must see images too.
80
+ if (config.models.driver === config.models.vision) {
81
+ const { apiKey, baseURL } = resolveProviderConfig(providerOptions);
82
+ const ids = [...new Set([config.models.driver, config.models.fallback])];
83
+ const caps = await Promise.all(ids.map((id) => supportsImageInput(baseURL, apiKey, id)));
84
+ selfLook = caps.every((cap) => cap === true);
85
+ }
86
+ // Wire the debug session service
87
+ const manager = new SessionManager();
88
+ const builder = makeSessionBuilder({
89
+ config,
90
+ models: {
91
+ driver: roleModels.driver,
92
+ vision: roleModels.vision,
93
+ summary: roleModels.summary,
94
+ selfLook,
95
+ },
96
+ workspace,
97
+ });
98
+ const createStatePort = deps.createStatePort ?? ((ws, opts) => new FileStatePort(ws, opts));
99
+ const service = new DebugService({
100
+ manager,
101
+ config,
102
+ cwd,
103
+ build: builder,
104
+ state: createStatePort(workspace, { cwd }),
105
+ // Everything above was resolved from the config file as it read a moment
106
+ // ago; if it changes underneath us, say so instead of running on stale wiring.
107
+ configChanged: makeConfigWatch(cwd),
108
+ });
109
+ // Graceful stop: a CLI `stop` (or any SIGTERM/SIGINT) tears the run down —
110
+ // abort the loop, close the browser, free the profile — then exits cleanly.
111
+ // Bounded: a teardown that wedges (a tool call that never observes its abort)
112
+ // must not leave the process alive forever, because `stop` only signals once.
113
+ const shutdown = createShutdown({
114
+ endActive: () => service.endActive(),
115
+ exit,
116
+ });
117
+ const onSigterm = () => shutdown(0);
118
+ const onSigint = () => shutdown(130);
119
+ process.once('SIGTERM', onSigterm);
120
+ process.once('SIGINT', onSigint);
121
+ // Boot stdio MCP server with outer tools. A dead client is a shutdown too:
122
+ // nothing can read findings or `end_session` any more, so the run must not
123
+ // keep a browser (and the profile lock) alive until its cap. Same idempotent
124
+ // teardown path as the signals above.
125
+ const tools = outerTools(service);
126
+ let server;
127
+ try {
128
+ server = await start(tools, { onClose: () => shutdown(0) });
129
+ }
130
+ catch (error) {
131
+ // A server that never started must not leave its signal handlers behind:
132
+ // they would outlive the boot and fire into a process that has no run.
133
+ process.removeListener('SIGTERM', onSigterm);
134
+ process.removeListener('SIGINT', onSigint);
135
+ throw error;
136
+ }
137
+ return {
138
+ server,
139
+ dispose: () => {
140
+ process.removeListener('SIGTERM', onSigterm);
141
+ process.removeListener('SIGINT', onSigint);
142
+ },
143
+ };
144
+ }
145
+ //# sourceMappingURL=boot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boot.js","sourceRoot":"","sources":["../src/boot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACpF,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAgB,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,OAAO,EAAE,aAAa,EAAkB,MAAM,yBAAyB,CAAC;AACxE,OAAO,EAAE,eAAe,EAAuB,cAAc,EAAE,MAAM,wBAA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AC;QACf,yEAAyE;QACzE,uEAAuE;QACvE,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAC7C,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC3C,MAAM,KAAK,CAAC;IACd,CAAC;IAED,OAAO;QACL,MAAM;QACN,OAAO,EAAE,GAAG,EAAE;YACZ,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;YAC7C,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC7C,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,262 @@
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
+ /**
65
+ * The repo-pinned Playwright CLI invocation that installs the Chromium system
66
+ * dependencies. NEVER `bunx playwright` — that resolves an unpinned version.
67
+ */
68
+ export declare const INSTALL_DEPS_COMMAND = "node node_modules/playwright-core/cli.js install-deps chromium";
69
+ /** Machine-readable marker every failure message starts with. */
70
+ export declare const MISSING_LIBS_MARKER = "X_CHROMIUM_LIBS_MISSING:";
71
+ /**
72
+ * The installed playwright-core's revision manifest — the same one `bin/setup`
73
+ * reads for the skip-when-cached check. Resolved relative to this module, so
74
+ * the CLI works from any cwd as long as it runs from this checkout.
75
+ */
76
+ export declare const BROWSERS_JSON_PATH: string;
77
+ /**
78
+ * Parse the headless-shell revision the installed playwright-core pins — the
79
+ * revision of the binary a `chromium.launch({ headless: true })` will run.
80
+ *
81
+ * Modern manifests name it `chromium-headless-shell`; older ones only name
82
+ * `chromium` (same revision for both). `null` when the manifest is unreadable,
83
+ * invalid, or names neither — the caller then falls back to scanning the cache
84
+ * rather than answering from a guess.
85
+ */
86
+ export declare function readPinnedHeadlessShellRevision(manifestPath?: string): number | null;
87
+ /**
88
+ * Parse the shared libraries `ldd` could not resolve.
89
+ *
90
+ * `ldd` prints one line per dependency and reports an unresolved one as
91
+ * `libX.so => not found`. The library name is the text LEFT of the `=>` — the
92
+ * right side is the (absent) resolved path.
93
+ *
94
+ * @param lddOutput combined stdout/stderr of an `ldd` run.
95
+ * @returns the missing library names, de-duplicated, in first-seen order.
96
+ */
97
+ export declare function parseMissingLibs(lddOutput: string): string[];
98
+ /**
99
+ * The diagnostic for missing libraries. Starts with {@link MISSING_LIBS_MARKER}
100
+ * (the marker CI greps for) and names every missing library plus the command
101
+ * that installs them.
102
+ */
103
+ export declare function formatMissingLibsMessage(missing: string[], installCommand?: string, binary?: string): string;
104
+ /** What the check may do about the missing libraries. */
105
+ export type RemediationPlan = {
106
+ kind: 'none';
107
+ } | {
108
+ kind: 'install-deps';
109
+ command: string;
110
+ } | {
111
+ kind: 'blocked';
112
+ message: string;
113
+ };
114
+ /**
115
+ * Decide how to remediate the missing libraries.
116
+ *
117
+ * `none` — nothing is missing, so nothing is attempted.
118
+ * `install-deps` — libraries are missing and noninteractive elevation exists,
119
+ * so the pinned install-deps command may run.
120
+ * `blocked` — libraries are missing but elevation is unavailable; the message
121
+ * is the diagnostic to report. The install is NOT attempted (it would prompt).
122
+ */
123
+ export declare function remediationPlan(missing: string[], elevated: boolean, installCommand?: string): RemediationPlan;
124
+ /** Seam: run `ldd` on a binary; returns combined stdout+stderr. */
125
+ export type LddRunner = (binary: string) => string;
126
+ /**
127
+ * Seam: is noninteractive elevation available for THIS command? The command is
128
+ * the one the installer will run — the probe is command-scoped, not a generic
129
+ * "can I sudo something".
130
+ */
131
+ export type ElevationProbe = (command: string) => boolean;
132
+ /** Seam: run the remediation command; throws on failure. */
133
+ export type Installer = (command: string) => void;
134
+ /**
135
+ * Seam: locate either binary; `null` when absent. `pinnedRevision`
136
+ * is the revision resolved from the installed playwright-core manifest — when
137
+ * known, ONLY that revision's dir is acceptable (see {@link locateHeadlessShell}).
138
+ */
139
+ export type BinaryLocator = (cacheDir: string, pinnedRevision?: number | null, kind?: 'shell' | 'full') => string | null;
140
+ /**
141
+ * Locate the PINNED Chromium headless-shell binary inside the Playwright
142
+ * cache dir — the binary `chromium.launch()` will actually execute.
143
+ *
144
+ * With a `pinnedRevision` (from {@link readPinnedHeadlessShellRevision}), ONLY
145
+ * that revision's `chromium_headless_shell-<rev>` dir is acceptable: a cache
146
+ * holding a NEWER revision too (left by another playwright version) must not
147
+ * be checked in its place — the launch uses the pinned one, and a foreign
148
+ * binary answers the wrong question in both directions. When the pinned dir is
149
+ * absent the check must fail (launch would fail too), never pass off another
150
+ * revision's binary.
151
+ *
152
+ * Without a pinned revision (manifest unreadable), it falls back to scanning
153
+ * for the `chromium_headless_shell-<rev>` folder and the known executable
154
+ * names/subpaths inside it — the layout moves between playwright-core
155
+ * versions, so it is discovered, never hardcoded.
156
+ */
157
+ export declare function locateHeadlessShell(cacheDir: string, pinnedRevision?: number | null): string | null;
158
+ /** Full Chromium: explicit executablePath launches this rather than the shell. */
159
+ export declare function locateChromium(cacheDir: string, pinnedRevision?: number | null): string | null;
160
+ /**
161
+ * Default `ldd` runner: the real thing, combined stdout+stderr.
162
+ *
163
+ * `ldd` exits NON-ZERO precisely when a shared library is missing — the exact
164
+ * case this module exists to detect — so `execFileSync` throws and the output
165
+ * is trapped inside the thrown error. Letting that throw escape would abort
166
+ * the check BEFORE `parseMissingLibs` ever ran: the raw `Command failed: ldd
167
+ * …` text would reach stderr, naming no library and no fix, and the
168
+ * remediation path would never be reached.
169
+ *
170
+ * So the non-zero exit is treated as DATA, not as an error: the captured
171
+ * stdout+stderr is returned for parsing. The library listing (`libX.so => not
172
+ * found`) is printed on stdout even when `ldd` exits non-zero, and the
173
+ * diagnostics land on stderr — hence both streams, combined.
174
+ */
175
+ export declare const runLdd: LddRunner;
176
+ /**
177
+ * Default elevation probe: COMMAND-SCOPED, reading BOTH permissions sudo
178
+ * keeps separate — via the LONG listing (`sudo -n -ll <command…>`), the only
179
+ * command-scoped query whose output carries the authentication tag on GNU
180
+ * sudo.
181
+ *
182
+ * The short listing (`sudo -l <command…>`) does NOT: real sudo (verified
183
+ * against 1.9.15p5; pinned by the real-sudo regressions in
184
+ * `chromium-libs.test.ts`) prints just the fully-qualified path and arguments
185
+ * for a permitted command — no `NOPASSWD` token, whether the matched rule is
186
+ * NOPASSWD or PASSWD — so a tag read over the short listing rejects every
187
+ * passwordless host.
188
+ *
189
+ * `-ll` on a listed command prints the matched sudoers entry, rendering the
190
+ * tag as an option:
191
+ *
192
+ * Sudoers entry: /etc/sudoers.d/ci
193
+ * RunAsUsers: ALL
194
+ * Options: !authenticate <- the NOPASSWD tag ...
195
+ * Commands:
196
+ * /bin/true
197
+ * Matched: /bin/true
198
+ *
199
+ * ... and `Options: authenticate` when the matched rule is PASSWD-tagged —
200
+ * the dangerous middle that motivated command-scoping in the first place:
201
+ * under sudo's default `listpw=any` the listing succeeds without a password
202
+ * as soon as the user holds ANY NOPASSWD rule, so a passwordless `true`
203
+ * lists a password-required install command. Exit 0 alone is therefore only
204
+ * the LISTING answer; the EXECUTION answer is the tag on the matched entry.
205
+ *
206
+ * A sudo whose `-ll` listing is TAGLESS cannot answer that way: sudo-rs —
207
+ * the default sudo on recent Ubuntu images, GitHub Actions runner images
208
+ * among them — accepts `-ll` but prints the same short form as `-l` (real
209
+ * CI: `sudo -n -ll /bin/true` on a `NOPASSWD: ALL` host printed just
210
+ * `/bin/true`). The probe falls back to the FULL listing (`sudo -n -l`,
211
+ * every privilege with its tag) and accepts only `NOPASSWD: ALL`: the `-ll`
212
+ * exit 0 already proved THIS command is listed, and `NOPASSWD: ALL` proves
213
+ * everything listed executes passwordless. A narrower NOPASSWD scope behind
214
+ * a tagless `-ll` has no portable query to prove it and stays `false` — the
215
+ * blocked diagnostic; a wrong `true` there would still be caught by the
216
+ * installer's own `sudo -n`, which fails instantly and loud. An exit-1 run
217
+ * — unlisted ("Sorry, user … may not run …"), unresolvable, or a listing
218
+ * that itself needed a password (no NOPASSWD rule anywhere) — is not
219
+ * passwordless elevation. uid 0 counts as elevated (no sudo needed at all).
220
+ */
221
+ export declare const probeElevation: ElevationProbe;
222
+ /**
223
+ * Default installer: run the command under NONINTERACTIVE elevation.
224
+ *
225
+ * As root the command runs directly (install-deps then invokes its package
226
+ * manager without any inner sudo). Otherwise the WHOLE installer is invoked as
227
+ * `sudo -n …`: elevation is enforced on the actual invocation, so a sudoers
228
+ * rule that allows passwordless `true` but wants a password for `sh` makes
229
+ * sudo FAIL here, instantly — instead of install-deps' ordinary `sudo -- sh -c
230
+ * …` prompting a CI/setup run into a permanent hang. Running as root also
231
+ * means install-deps skips its own sudo entirely.
232
+ */
233
+ export declare const runInstaller: Installer;
234
+ /** The injectable seams of {@link checkChromiumLibs}. */
235
+ export type ChromiumLibsDeps = {
236
+ /** The installed playwright-core's pinned headless-shell revision. */
237
+ pinnedRevision?: () => number | null;
238
+ locateBinary?: BinaryLocator;
239
+ ldd?: LddRunner;
240
+ probeElevation?: ElevationProbe;
241
+ install?: Installer;
242
+ };
243
+ /** Outcome of a successful check. */
244
+ export type ChromiumLibsOk = {
245
+ ok: true;
246
+ binary: string;
247
+ binaries: string[];
248
+ missing: string[];
249
+ };
250
+ /**
251
+ * Check full Chromium AND its headless shell at the existing pinned revision.
252
+ *
253
+ * Throws {@link ChromiumLibsMissingError} when libraries are missing and could
254
+ * not be installed (no elevation, or the install failed).
255
+ */
256
+ export declare function checkChromiumLibs(cacheDir: string, deps?: ChromiumLibsDeps): ChromiumLibsOk;
257
+ /**
258
+ * CLI entry: `bun src/cli/chromium-libs.ts <cacheDir>`.
259
+ *
260
+ * Exit 0 — every shared library resolves. Exit 1 — the diagnostic on stderr.
261
+ */
262
+ export declare function runCli(argv?: string[]): number;