@developerz.ai/ui-debugger-mcp 1.10.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 (178) hide show
  1. package/README.md +9 -5
  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/android-adapter.d.ts +7 -39
  6. package/dist/adapters/android/android-adapter.js +54 -436
  7. package/dist/adapters/android/android-adapter.js.map +1 -1
  8. package/dist/adapters/android/commands.d.ts +10 -0
  9. package/dist/adapters/android/commands.js +22 -0
  10. package/dist/adapters/android/commands.js.map +1 -1
  11. package/dist/adapters/android/emulator.d.ts +41 -0
  12. package/dist/adapters/android/emulator.js +115 -0
  13. package/dist/adapters/android/emulator.js.map +1 -0
  14. package/dist/adapters/android/logcat.d.ts +87 -0
  15. package/dist/adapters/android/logcat.js +352 -0
  16. package/dist/adapters/android/logcat.js.map +1 -0
  17. package/dist/adapters/browser/browser-adapter.js +30 -42
  18. package/dist/adapters/browser/browser-adapter.js.map +1 -1
  19. package/dist/adapters/browser/cdp.d.ts +7 -10
  20. package/dist/adapters/browser/cdp.js +93 -69
  21. package/dist/adapters/browser/cdp.js.map +1 -1
  22. package/dist/adapters/browser/exchange-read.d.ts +39 -0
  23. package/dist/adapters/browser/exchange-read.js +102 -0
  24. package/dist/adapters/browser/exchange-read.js.map +1 -0
  25. package/dist/adapters/browser/extractor.js +9 -2
  26. package/dist/adapters/browser/extractor.js.map +1 -1
  27. package/dist/adapters/browser/lifecycle.d.ts +33 -0
  28. package/dist/adapters/browser/lifecycle.js +47 -4
  29. package/dist/adapters/browser/lifecycle.js.map +1 -1
  30. package/dist/adapters/browser/locate.d.ts +18 -2
  31. package/dist/adapters/browser/locate.js +48 -3
  32. package/dist/adapters/browser/locate.js.map +1 -1
  33. package/dist/adapters/browser/log-filters.d.ts +1 -1
  34. package/dist/adapters/browser/log-filters.js +15 -4
  35. package/dist/adapters/browser/log-filters.js.map +1 -1
  36. package/dist/adapters/browser/log-format.d.ts +12 -0
  37. package/dist/adapters/browser/log-format.js +123 -7
  38. package/dist/adapters/browser/log-format.js.map +1 -1
  39. package/dist/adapters/contract.d.ts +22 -5
  40. package/dist/adapters/desktop/atspi-busctl.js +3 -1
  41. package/dist/adapters/desktop/atspi-busctl.js.map +1 -1
  42. package/dist/adapters/desktop/atspi.d.ts +6 -0
  43. package/dist/adapters/desktop/atspi.js.map +1 -1
  44. package/dist/adapters/desktop/desktop-adapter.d.ts +2 -0
  45. package/dist/adapters/desktop/desktop-adapter.js +132 -98
  46. package/dist/adapters/desktop/desktop-adapter.js.map +1 -1
  47. package/dist/adapters/desktop/input.d.ts +1 -1
  48. package/dist/adapters/desktop/input.js +14 -3
  49. package/dist/adapters/desktop/input.js.map +1 -1
  50. package/dist/adapters/desktop/managed-app.d.ts +43 -0
  51. package/dist/adapters/desktop/managed-app.js +114 -0
  52. package/dist/adapters/desktop/managed-app.js.map +1 -0
  53. package/dist/adapters/desktop/proc.d.ts +2 -0
  54. package/dist/adapters/desktop/proc.js +4 -0
  55. package/dist/adapters/desktop/proc.js.map +1 -1
  56. package/dist/adapters/desktop/wait-poll.d.ts +17 -0
  57. package/dist/adapters/desktop/wait-poll.js +38 -0
  58. package/dist/adapters/desktop/wait-poll.js.map +1 -0
  59. package/dist/adapters/factory.d.ts +1 -1
  60. package/dist/adapters/factory.js +1 -1
  61. package/dist/adapters/log-format.d.ts +6 -0
  62. package/dist/adapters/log-format.js +10 -2
  63. package/dist/adapters/log-format.js.map +1 -1
  64. package/dist/agent/belt/act.d.ts +6 -3
  65. package/dist/agent/belt/act.js +40 -60
  66. package/dist/agent/belt/act.js.map +1 -1
  67. package/dist/agent/belt/look.d.ts +9 -3
  68. package/dist/agent/belt/look.js +21 -5
  69. package/dist/agent/belt/look.js.map +1 -1
  70. package/dist/agent/belt/observe.d.ts +9 -43
  71. package/dist/agent/belt/observe.js +66 -242
  72. package/dist/agent/belt/observe.js.map +1 -1
  73. package/dist/agent/belt/redact-output.d.ts +20 -0
  74. package/dist/agent/belt/redact-output.js +70 -0
  75. package/dist/agent/belt/redact-output.js.map +1 -0
  76. package/dist/agent/belt/same-origin.d.ts +21 -0
  77. package/dist/agent/belt/same-origin.js +38 -0
  78. package/dist/agent/belt/same-origin.js.map +1 -0
  79. package/dist/agent/belt/target-refs.d.ts +39 -0
  80. package/dist/agent/belt/target-refs.js +60 -0
  81. package/dist/agent/belt/target-refs.js.map +1 -0
  82. package/dist/agent/belt/tree-targets.d.ts +79 -0
  83. package/dist/agent/belt/tree-targets.js +242 -0
  84. package/dist/agent/belt/tree-targets.js.map +1 -0
  85. package/dist/agent/loop-frames.d.ts +26 -0
  86. package/dist/agent/loop-frames.js +106 -0
  87. package/dist/agent/loop-frames.js.map +1 -0
  88. package/dist/agent/loop.d.ts +13 -24
  89. package/dist/agent/loop.js +40 -104
  90. package/dist/agent/loop.js.map +1 -1
  91. package/dist/agent/prompts/debug-agent.js +3 -2
  92. package/dist/agent/prompts/debug-agent.js.map +1 -1
  93. package/dist/agent/prompts/web-addendum.d.ts +2 -2
  94. package/dist/agent/prompts/web-addendum.js +21 -32
  95. package/dist/agent/prompts/web-addendum.js.map +1 -1
  96. package/dist/agent/provider.d.ts +3 -1
  97. package/dist/agent/provider.js +4 -2
  98. package/dist/agent/provider.js.map +1 -1
  99. package/dist/boot.js +3 -1
  100. package/dist/boot.js.map +1 -1
  101. package/dist/cli/chromium-libs.d.ts +6 -1
  102. package/dist/cli/chromium-libs.js +27 -3
  103. package/dist/cli/chromium-libs.js.map +1 -1
  104. package/dist/cli/control.js +30 -5
  105. package/dist/cli/control.js.map +1 -1
  106. package/dist/config/load.js +10 -0
  107. package/dist/config/load.js.map +1 -1
  108. package/dist/config/schema.js +12 -10
  109. package/dist/config/schema.js.map +1 -1
  110. package/dist/errors.d.ts +17 -16
  111. package/dist/errors.js +33 -32
  112. package/dist/errors.js.map +1 -1
  113. package/dist/index.d.ts +1 -1
  114. package/dist/index.js +1 -1
  115. package/dist/mcp/server.js +10 -1
  116. package/dist/mcp/server.js.map +1 -1
  117. package/dist/mcp/tools/end-session.js +2 -1
  118. package/dist/mcp/tools/end-session.js.map +1 -1
  119. package/dist/mcp/tools/output.d.ts +7 -0
  120. package/dist/mcp/tools/output.js +5 -0
  121. package/dist/mcp/tools/output.js.map +1 -1
  122. package/dist/mcp/tools/result.js +4 -1
  123. package/dist/mcp/tools/result.js.map +1 -1
  124. package/dist/redact.d.ts +20 -4
  125. package/dist/redact.js +134 -19
  126. package/dist/redact.js.map +1 -1
  127. package/dist/services/auth-persona.d.ts +19 -0
  128. package/dist/services/auth-persona.js +32 -0
  129. package/dist/services/auth-persona.js.map +1 -0
  130. package/dist/services/debug-api.d.ts +7 -0
  131. package/dist/services/debug-service.d.ts +1 -1
  132. package/dist/services/debug-service.js +64 -65
  133. package/dist/services/debug-service.js.map +1 -1
  134. package/dist/services/foreign-findings.d.ts +22 -0
  135. package/dist/services/foreign-findings.js +38 -0
  136. package/dist/services/foreign-findings.js.map +1 -0
  137. package/dist/services/login-failure.d.ts +10 -0
  138. package/dist/services/login-failure.js +24 -0
  139. package/dist/services/login-failure.js.map +1 -0
  140. package/dist/services/login-selectors.d.ts +18 -0
  141. package/dist/services/login-selectors.js +44 -0
  142. package/dist/services/login-selectors.js.map +1 -0
  143. package/dist/services/login-session.d.ts +25 -0
  144. package/dist/services/login-session.js +59 -0
  145. package/dist/services/login-session.js.map +1 -0
  146. package/dist/services/login.d.ts +9 -27
  147. package/dist/services/login.js +78 -80
  148. package/dist/services/login.js.map +1 -1
  149. package/dist/services/replay.js +15 -3
  150. package/dist/services/replay.js.map +1 -1
  151. package/dist/services/session-builder.js +19 -4
  152. package/dist/services/session-builder.js.map +1 -1
  153. package/dist/services/shutdown.d.ts +8 -4
  154. package/dist/services/shutdown.js +21 -8
  155. package/dist/services/shutdown.js.map +1 -1
  156. package/dist/services/start-guards.d.ts +6 -1
  157. package/dist/services/start-guards.js +13 -2
  158. package/dist/services/start-guards.js.map +1 -1
  159. package/dist/session/cleanup.d.ts +3 -2
  160. package/dist/session/cleanup.js +6 -2
  161. package/dist/session/cleanup.js.map +1 -1
  162. package/dist/session/finalize.d.ts +45 -0
  163. package/dist/session/finalize.js +150 -0
  164. package/dist/session/finalize.js.map +1 -0
  165. package/dist/session/flock-backend.d.ts +117 -0
  166. package/dist/session/flock-backend.js +293 -0
  167. package/dist/session/flock-backend.js.map +1 -0
  168. package/dist/session/owner-lock.d.ts +4 -95
  169. package/dist/session/owner-lock.js +7 -288
  170. package/dist/session/owner-lock.js.map +1 -1
  171. package/dist/session/session.js +11 -134
  172. package/dist/session/session.js.map +1 -1
  173. package/dist/session/state-file.js +9 -1
  174. package/dist/session/state-file.js.map +1 -1
  175. package/dist/session/workspace.d.ts +32 -2
  176. package/dist/session/workspace.js +65 -4
  177. package/dist/session/workspace.js.map +1 -1
  178. package/package.json +8 -8
@@ -0,0 +1,293 @@
1
+ /**
2
+ * The `flock(2)` backend behind the workspace ownership lock (`owner-lock.ts`).
3
+ *
4
+ * `flock` comes from the kernel, and the RUNTIME decides how this process
5
+ * reaches it. Under Bun it is libc's, through Bun's FFI; under Node there is
6
+ * no FFI, so the very same kernel lock is taken by util-linux's `flock(1)`,
7
+ * applied to the descriptor this process already holds. Either way it is ONE
8
+ * lock on ONE file: the kernel refuses every other `flock` on it, and it dies
9
+ * with the descriptor. The server targets Linux (see CLAUDE.md); the glibc and
10
+ * musl sonames and the macOS libc are covered, and anything else fails loud —
11
+ * a silent fallback here would be two processes both believing they own the
12
+ * workspace.
13
+ *
14
+ * The FFI access is DYNAMIC: the published bin runs on Node (`package.json` →
15
+ * `dist/main.js` behind `#!/usr/bin/env node`), where `bun:ffi` does not
16
+ * exist — a static import would crash the module on LOAD, before any probe
17
+ * could report why. The boot gate ({@link assertOwnerLockBackend}) resolves
18
+ * the backend BEFORE the server comes up: a host that cannot provide one can
19
+ * never enforce the one-run rule.
20
+ */
21
+ import { spawn } from 'node:child_process';
22
+ import { accessSync, closeSync, constants as fsConstants } from 'node:fs';
23
+ import { delimiter, join } from 'node:path';
24
+ import { WorkspaceError } from '../errors.js';
25
+ /** flock(2) operations — the Linux/glibc values, identical on the BSDs and macOS. */
26
+ const LOCK_EX = 2;
27
+ const LOCK_NB = 4;
28
+ const LOCK_UN = 8;
29
+ /** libc sonames carrying `flock`, in probe order (glibc, musl, macOS). */
30
+ export const LIBC_CANDIDATES = [
31
+ 'libc.so.6',
32
+ 'libc.musl-x86_64.so.1',
33
+ 'libc.musl-aarch64.so.1',
34
+ 'libc.dylib',
35
+ ];
36
+ /**
37
+ * The FFI module, loaded DYNAMICALLY.
38
+ *
39
+ * `bun:ffi` exists only under Bun, and the published bin runs on Node: a
40
+ * static import of it crashes the module on LOAD, before any probe can report
41
+ * why the backend is missing. A failed load is NOT cached — the next attempt
42
+ * retries, so a host that gains the backend (or a later boot in the same
43
+ * process) is not stuck with the first failure.
44
+ */
45
+ let ffiModule;
46
+ async function loadFfi() {
47
+ if (ffiModule !== undefined)
48
+ return ffiModule;
49
+ let loaded;
50
+ try {
51
+ loaded = await import('bun:ffi');
52
+ }
53
+ catch (error) {
54
+ // The runtime has no FFI backend AT ALL (Node): say so plainly. "flock is
55
+ // missing" would send an operator hunting for the wrong libc, when the
56
+ // backend that could have opened one was never there.
57
+ throw new WorkspaceError(`no FFI backend on this runtime — bun:ffi is unavailable: ${error.message}`);
58
+ }
59
+ ffiModule = loaded;
60
+ return loaded;
61
+ }
62
+ /**
63
+ * The default opener: the platform's libc, through Bun's FFI.
64
+ *
65
+ * Exported so a test can compose a failing opener with the REAL backend: a
66
+ * stub symbol cannot prove that a kernel lock was actually taken.
67
+ */
68
+ export async function openFlockInLibc(soname) {
69
+ const ffi = await loadFfi();
70
+ const lib = ffi.dlopen(soname, {
71
+ flock: { args: [ffi.FFIType.int, ffi.FFIType.int], returns: ffi.FFIType.int },
72
+ });
73
+ return lib.symbols.flock;
74
+ }
75
+ /**
76
+ * Probe the libc candidates for `flock(2)`.
77
+ *
78
+ * Fails loud, naming the platform and EVERY soname tried with what each one
79
+ * said: an operator needs to know which libc was looked for, not just that
80
+ * "something went wrong".
81
+ */
82
+ export async function resolveFlock(opener) {
83
+ const misses = [];
84
+ for (const name of LIBC_CANDIDATES) {
85
+ try {
86
+ return await opener(name);
87
+ }
88
+ catch (error) {
89
+ // A house error is a BACKEND-level failure, not a soname-level miss: the
90
+ // FFI itself could not be loaded, so no libc was ever opened. Folding it
91
+ // into the misses would name sonames that were never tried and bury the
92
+ // one fact that matters ("this runtime has no FFI backend") — so it goes
93
+ // out unchanged.
94
+ if (error instanceof WorkspaceError)
95
+ throw error;
96
+ misses.push(`${name}: ${error.message}`);
97
+ }
98
+ }
99
+ throw new WorkspaceError(`cannot load flock(2) for the workspace ownership lock on ${process.platform} ` +
100
+ `(tried ${LIBC_CANDIDATES.join(', ')}): ${misses.join('; ')}`);
101
+ }
102
+ /**
103
+ * The backend over a RESOLVED `flock(2)` symbol.
104
+ *
105
+ * The symbol is the libc one, so the unlock is an explicit `LOCK_UN` — and
106
+ * the descriptor is closed even when that call fails, because closing alone
107
+ * releases the flock and a descriptor left open would keep the kernel lock
108
+ * alive with no registry entry to reach it by.
109
+ */
110
+ export function symbolBackend(flock) {
111
+ return {
112
+ async tryLock(fd) {
113
+ return flock(fd, LOCK_EX | LOCK_NB) === 0;
114
+ },
115
+ release(fd) {
116
+ try {
117
+ flock(fd, LOCK_UN);
118
+ }
119
+ finally {
120
+ closeSync(fd);
121
+ }
122
+ },
123
+ };
124
+ }
125
+ /**
126
+ * The Bun-side backend: libc's `flock(2)`, through Bun's FFI.
127
+ *
128
+ * `bun:ffi` is a Bun-only module, and a STATIC import of it would make every
129
+ * installed copy die on Node with ERR_UNSUPPORTED_ESM_URL_SCHEME before it
130
+ * could print its own help — the published bin runs on the node floor
131
+ * package.json declares. So the import is dynamic ({@link loadFfi}), and only
132
+ * the runtime check that picks this backend ever reaches it.
133
+ */
134
+ async function bunFlockBackend() {
135
+ return symbolBackend(await resolveFlock(openFlockInLibc));
136
+ }
137
+ /** util-linux `flock(1)`'s exit code for "another process holds the lock". */
138
+ const FLOCK_CONFLICT_EXIT = 42;
139
+ /**
140
+ * The slot our descriptor rides in on the child's stdio.
141
+ *
142
+ * `flock(1)` locks THAT descriptor — the one this process already holds — so
143
+ * the lock lands on the open file description we keep: it stays ours after the
144
+ * child exits, every rival is refused by the kernel, and the kernel drops it
145
+ * when we close the descriptor or die.
146
+ */
147
+ const CHILD_FD = 3;
148
+ /** Run util-linux's `flock(1)` against our descriptor and read what it decided. */
149
+ function runFlockCli(fd, bin) {
150
+ return new Promise((resolve) => {
151
+ const child = spawn(bin, [
152
+ '--exclusive',
153
+ '--nonblock',
154
+ '--conflict-exit-code',
155
+ String(FLOCK_CONFLICT_EXIT),
156
+ String(CHILD_FD),
157
+ ], { stdio: ['ignore', 'ignore', 'pipe', fd] });
158
+ let stderr = '';
159
+ child.stderr?.on('data', (chunk) => {
160
+ stderr += chunk.toString();
161
+ });
162
+ child.on('error', (error) => {
163
+ resolve({
164
+ granted: false,
165
+ conflict: false,
166
+ detail: `cannot run ${bin} to take the workspace lock: ${error.message}`,
167
+ });
168
+ });
169
+ child.on('close', (code) => {
170
+ if (code === 0) {
171
+ resolve({ granted: true, conflict: false, detail: '' });
172
+ return;
173
+ }
174
+ if (code === FLOCK_CONFLICT_EXIT) {
175
+ resolve({ granted: false, conflict: true, detail: '' });
176
+ return;
177
+ }
178
+ resolve({
179
+ granted: false,
180
+ conflict: false,
181
+ detail: `${bin} could not take the workspace lock (exit ${code ?? 'none'}): ` +
182
+ (stderr.trim() || 'no output'),
183
+ });
184
+ });
185
+ });
186
+ }
187
+ /**
188
+ * `flock(2)` through util-linux's `flock(1)` — how Node reaches the syscall.
189
+ *
190
+ * Node has no FFI, so a short-lived child inherits our descriptor and locks
191
+ * it. The child exits at once; the lock stays ours because it lives on the
192
+ * open file description we still hold, and the kernel drops it when that
193
+ * descriptor closes or this process dies — a crashed owner never wedges the
194
+ * workspace.
195
+ *
196
+ * `bin` is a seam: the tests point it at a binary that does not exist to
197
+ * prove the failure is loud instead of a quiet "nobody holds this".
198
+ */
199
+ export async function nodeFlockBackend(bin = 'flock') {
200
+ return {
201
+ async tryLock(fd) {
202
+ const outcome = await runFlockCli(fd, bin);
203
+ if (outcome.granted)
204
+ return true;
205
+ if (outcome.conflict)
206
+ return false;
207
+ throw new WorkspaceError(`cannot take the workspace ownership lock on ${process.platform}: ${outcome.detail}`);
208
+ },
209
+ release(fd) {
210
+ // Closing IS the unlock here: the child is long gone, so ours is the
211
+ // last descriptor referring to the locked description, and the kernel
212
+ // drops the flock when it closes.
213
+ closeSync(fd);
214
+ },
215
+ };
216
+ }
217
+ /**
218
+ * The backend for THIS runtime, resolved fresh.
219
+ *
220
+ * Bun reaches libc through its own FFI; Node has none, so the same kernel
221
+ * lock comes from util-linux's `flock(1)`. The choice is the runtime's, made
222
+ * once — never a fallback: a platform with neither fails loud at first use
223
+ * rather than pretending the workspace is free.
224
+ */
225
+ function createBackend() {
226
+ return 'bun' in process.versions ? bunFlockBackend() : nodeFlockBackend();
227
+ }
228
+ /** The resolved backend of THIS runtime, cached once it is known to work. */
229
+ let backend;
230
+ export function loadBackend() {
231
+ backend ??= createBackend().catch((error) => {
232
+ // A failed resolution is not a verdict: the next attempt retries instead
233
+ // of replaying a dead one.
234
+ backend = undefined;
235
+ throw error;
236
+ });
237
+ return backend;
238
+ }
239
+ /**
240
+ * The gate's Node-side check: util-linux's `flock(1)` must be reachable.
241
+ *
242
+ * The Node backend reaches the kernel through that binary, so a host without
243
+ * it can never enforce the one-run rule — the same hole the libc probe closes
244
+ * on Bun. Nothing is locked and no file is touched: this only asks whether
245
+ * the binary is there.
246
+ */
247
+ function assertFlockCli(bin = 'flock') {
248
+ for (const dir of (process.env.PATH ?? '').split(delimiter)) {
249
+ if (dir === '')
250
+ continue;
251
+ try {
252
+ accessSync(join(dir, bin), fsConstants.X_OK);
253
+ return;
254
+ }
255
+ catch {
256
+ // not this directory — keep looking
257
+ }
258
+ }
259
+ throw new WorkspaceError(`cannot take the workspace ownership lock on ${process.platform}: ` +
260
+ `${bin}(1) is not on PATH — the workspace lock needs util-linux's flock`);
261
+ }
262
+ /**
263
+ * The BOOT GATE: resolve this host's `flock(2)` WITHOUT taking a lock.
264
+ *
265
+ * The workspace's one-run rule rests on a kernel-held lock. A host that cannot
266
+ * provide that backend can never enforce it — two servers would each believe
267
+ * they own the workspace — so the server refuses to come up instead. This
268
+ * runs BEFORE the workspace exists, before a config is read and before the MCP
269
+ * server starts.
270
+ *
271
+ * It RESOLVES the backend and nothing more: no file is opened, no `flock` is
272
+ * called, `<workspace>/owner.lock` is never created, and the acquire path's
273
+ * module cache is never written — an injected opener must not leak into the
274
+ * real one. A failed resolution is not cached either: the next attempt
275
+ * retries. A backend that failed outright (no FFI on this runtime) is
276
+ * reported as it is — never as a hunt through sonames it never opened.
277
+ *
278
+ * @param opener the libc seam to resolve through — the real one by default,
279
+ * injectable so a failed resolution is testable. An injected opener probes
280
+ * the libc candidates; without one, THIS runtime's own backend is resolved.
281
+ */
282
+ export async function assertOwnerLockBackend(opener) {
283
+ if (opener !== undefined) {
284
+ await resolveFlock(opener);
285
+ return;
286
+ }
287
+ if ('bun' in process.versions) {
288
+ await bunFlockBackend(); // resolves libc's `flock(2)` — takes no lock
289
+ return;
290
+ }
291
+ assertFlockCli(); // Node has no FFI: util-linux's `flock(1)` is the backend
292
+ }
293
+ //# sourceMappingURL=flock-backend.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flock-backend.js","sourceRoot":"","sources":["../../src/session/flock-backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,IAAI,WAAW,E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AAG,SAAS,CAAC;QACpB,MAAM,KAAK,CAAC;IACd,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,cAAc,CAAC,GAAG,GAAG,OAAO;IACnC,KAAK,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;QAC5D,IAAI,GAAG,KAAK,EAAE;YAAE,SAAS;QACzB,IAAI,CAAC;YACH,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;YAC7C,OAAO;QACT,CAAC;QAAC,MAAM,CAAC;YACP,oCAAoC;QACtC,CAAC;IACH,CAAC;IACD,MAAM,IAAI,cAAc,CACtB,+CAA+C,OAAO,CAAC,QAAQ,IAAI;QACjE,GAAG,GAAG,kEAAkE,CAC3E,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,MAAoB;IAC/D,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,MAAM,YAAY,CAAC,MAAM,CAAC,CAAC;QAC3B,OAAO;IACT,CAAC;IACD,IAAI,KAAK,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QAC9B,MAAM,eAAe,EAAE,CAAC,CAAC,6CAA6C;QACtE,OAAO;IACT,CAAC;IACD,cAAc,EAAE,CAAC,CAAC,0DAA0D;AAC9E,CAAC"}
@@ -39,26 +39,14 @@
39
39
  * reads or removes it. It cannot resurrect an owner — exclusion lives in the
40
40
  * kernel, not in file contents.
41
41
  *
42
- * `flock` comes from the kernel, and the RUNTIME decides how this process
43
- * reaches it. Under Bun it is libc's, through Bun's FFI; under Node there is
44
- * no FFI, so the very same kernel lock is taken by util-linux's `flock(1)`,
45
- * applied to the descriptor this process already holds. Either way it is ONE
46
- * lock on ONE file: the kernel refuses every other `flock` on it, and it dies
47
- * with the descriptor. The server targets Linux (see CLAUDE.md); the glibc and
48
- * musl sonames and the macOS libc are covered, and anything else fails loud —
49
- * a silent fallback here would be two processes both believing they own the
50
- * workspace.
51
- *
52
- * The FFI access is DYNAMIC: the published bin runs on Node (`package.json` →
53
- * `dist/main.js` behind `#!/usr/bin/env node`), where `bun:ffi` does not
54
- * exist — a static import would crash the module on LOAD, before any probe
55
- * could report why. The boot gate ({@link assertOwnerLockBackend}) resolves
56
- * the backend BEFORE the server comes up: a host that cannot provide one can
57
- * never enforce the one-run rule.
42
+ * How this process reaches `flock(2)` (Bun FFI or util-linux `flock(1)`) lives
43
+ * in `flock-backend.ts`; its public surface is re-exported from here.
58
44
  */
59
45
  import { z } from 'zod';
60
46
  import { SessionBusyError } from '../errors.js';
47
+ import { type FlockOpener } from './flock-backend.js';
61
48
  import type { WorkspacePaths } from './workspace.js';
49
+ export { assertOwnerLockBackend, type FlockBackend, type FlockFn, type FlockOpener, LIBC_CANDIDATES, nodeFlockBackend, openFlockInLibc, } from './flock-backend.js';
62
50
  /** The owner recorded in `<workspace>/owner.lock`. */
63
51
  export declare const OwnerLockSchema: z.ZodObject<{
64
52
  pid: z.ZodNumber;
@@ -74,85 +62,6 @@ export declare class OwnerLockBusyError extends SessionBusyError {
74
62
  }
75
63
  /** `<workspace.root>/owner.lock` */
76
64
  export declare function ownerLockPath(workspace: WorkspacePaths): string;
77
- /**
78
- * Taking the kernel's `flock(2)` on a descriptor.
79
- *
80
- * Both backends lock the SAME open file description — the one this process
81
- * holds on `owner.lock` — so every invariant above survives either one: a
82
- * rival is refused by the kernel, the lock is not revocable, and it dies with
83
- * the descriptor.
84
- */
85
- export interface FlockBackend {
86
- /**
87
- * Take the exclusive, non-blocking lock on `fd`.
88
- *
89
- * `false` means a rival holds it — a fact the kernel reported, not a
90
- * judgment this process made. Anything else (no `flock(1)`, a platform
91
- * without one) throws: a lock nobody took is not a busy workspace.
92
- */
93
- tryLock(fd: number): Promise<boolean>;
94
- /**
95
- * Give the lock back and dispose of the descriptor.
96
- *
97
- * The kernel drops a flock when the last descriptor referring to it is
98
- * closed, so releasing means closing — the explicit unlock is only there
99
- * for the runtime that can make one.
100
- */
101
- release(fd: number): void;
102
- }
103
- /** libc sonames carrying `flock`, in probe order (glibc, musl, macOS). */
104
- export declare const LIBC_CANDIDATES: readonly ['libc.so.6', 'libc.musl-x86_64.so.1', 'libc.musl-aarch64.so.1', 'libc.dylib'];
105
- /** `flock(2)` — the C function: (fd, operation) → 0 on success. */
106
- export type FlockFn = (fd: number, operation: number) => number;
107
- /**
108
- * Opens ONE libc soname and hands back its `flock` symbol.
109
- *
110
- * Throws when that soname cannot be opened or carries no `flock`. This is the
111
- * seam the boot gate AND the acquire path are injected through — never a
112
- * module mock, which would leak into the suites running alongside.
113
- */
114
- export type FlockOpener = (soname: string) => Promise<FlockFn>;
115
- /**
116
- * The default opener: the platform's libc, through Bun's FFI.
117
- *
118
- * Exported so a test can compose a failing opener with the REAL backend: a
119
- * stub symbol cannot prove that a kernel lock was actually taken.
120
- */
121
- export declare function openFlockInLibc(soname: string): Promise<FlockFn>;
122
- /**
123
- * `flock(2)` through util-linux's `flock(1)` — how Node reaches the syscall.
124
- *
125
- * Node has no FFI, so a short-lived child inherits our descriptor and locks
126
- * it. The child exits at once; the lock stays ours because it lives on the
127
- * open file description we still hold, and the kernel drops it when that
128
- * descriptor closes or this process dies — a crashed owner never wedges the
129
- * workspace.
130
- *
131
- * `bin` is a seam: the tests point it at a binary that does not exist to
132
- * prove the failure is loud instead of a quiet "nobody holds this".
133
- */
134
- export declare function nodeFlockBackend(bin?: string): Promise<FlockBackend>;
135
- /**
136
- * The BOOT GATE: resolve this host's `flock(2)` WITHOUT taking a lock.
137
- *
138
- * The workspace's one-run rule rests on a kernel-held lock. A host that cannot
139
- * provide that backend can never enforce it — two servers would each believe
140
- * they own the workspace — so the server refuses to come up instead. This
141
- * runs BEFORE the workspace exists, before a config is read and before the MCP
142
- * server starts.
143
- *
144
- * It RESOLVES the backend and nothing more: no file is opened, no `flock` is
145
- * called, `<workspace>/owner.lock` is never created, and the acquire path's
146
- * module cache is never written — an injected opener must not leak into the
147
- * real one. A failed resolution is not cached either: the next attempt
148
- * retries. A backend that failed outright (no FFI on this runtime) is
149
- * reported as it is — never as a hunt through sonames it never opened.
150
- *
151
- * @param opener the libc seam to resolve through — the real one by default,
152
- * injectable so a failed resolution is testable. An injected opener probes
153
- * the libc candidates; without one, THIS runtime's own backend is resolved.
154
- */
155
- export declare function assertOwnerLockBackend(opener?: FlockOpener): Promise<void>;
156
65
  /**
157
66
  * Acquire the exclusive workspace claim.
158
67
  *