@colbymchenry/codegraph-darwin-x64 1.1.1 → 1.1.3

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 (88) hide show
  1. package/lib/dist/bin/codegraph.js +99 -59
  2. package/lib/dist/bin/codegraph.js.map +1 -1
  3. package/lib/dist/bin/command-supervision.d.ts +12 -0
  4. package/lib/dist/bin/command-supervision.d.ts.map +1 -0
  5. package/lib/dist/bin/command-supervision.js +76 -0
  6. package/lib/dist/bin/command-supervision.js.map +1 -0
  7. package/lib/dist/db/migrations.d.ts +1 -1
  8. package/lib/dist/db/migrations.d.ts.map +1 -1
  9. package/lib/dist/db/migrations.js +25 -1
  10. package/lib/dist/db/migrations.js.map +1 -1
  11. package/lib/dist/db/queries.d.ts.map +1 -1
  12. package/lib/dist/db/queries.js +10 -2
  13. package/lib/dist/db/queries.js.map +1 -1
  14. package/lib/dist/db/schema.sql +11 -0
  15. package/lib/dist/directory.d.ts +32 -0
  16. package/lib/dist/directory.d.ts.map +1 -1
  17. package/lib/dist/directory.js +83 -0
  18. package/lib/dist/directory.js.map +1 -1
  19. package/lib/dist/extraction/index.d.ts +13 -1
  20. package/lib/dist/extraction/index.d.ts.map +1 -1
  21. package/lib/dist/extraction/index.js +310 -218
  22. package/lib/dist/extraction/index.js.map +1 -1
  23. package/lib/dist/extraction/languages/c-cpp.d.ts +16 -0
  24. package/lib/dist/extraction/languages/c-cpp.d.ts.map +1 -1
  25. package/lib/dist/extraction/languages/c-cpp.js +33 -0
  26. package/lib/dist/extraction/languages/c-cpp.js.map +1 -1
  27. package/lib/dist/extraction/parse-pool.d.ts +126 -0
  28. package/lib/dist/extraction/parse-pool.d.ts.map +1 -0
  29. package/lib/dist/extraction/parse-pool.js +319 -0
  30. package/lib/dist/extraction/parse-pool.js.map +1 -0
  31. package/lib/dist/extraction/tree-sitter.d.ts +21 -0
  32. package/lib/dist/extraction/tree-sitter.d.ts.map +1 -1
  33. package/lib/dist/extraction/tree-sitter.js +106 -21
  34. package/lib/dist/extraction/tree-sitter.js.map +1 -1
  35. package/lib/dist/mcp/daemon-paths.d.ts +30 -3
  36. package/lib/dist/mcp/daemon-paths.d.ts.map +1 -1
  37. package/lib/dist/mcp/daemon-paths.js +50 -10
  38. package/lib/dist/mcp/daemon-paths.js.map +1 -1
  39. package/lib/dist/mcp/daemon-registry.d.ts.map +1 -1
  40. package/lib/dist/mcp/daemon-registry.js +7 -3
  41. package/lib/dist/mcp/daemon-registry.js.map +1 -1
  42. package/lib/dist/mcp/daemon.d.ts +48 -0
  43. package/lib/dist/mcp/daemon.d.ts.map +1 -1
  44. package/lib/dist/mcp/daemon.js +203 -32
  45. package/lib/dist/mcp/daemon.js.map +1 -1
  46. package/lib/dist/mcp/engine.d.ts +17 -0
  47. package/lib/dist/mcp/engine.d.ts.map +1 -1
  48. package/lib/dist/mcp/engine.js +73 -1
  49. package/lib/dist/mcp/engine.js.map +1 -1
  50. package/lib/dist/mcp/index.d.ts.map +1 -1
  51. package/lib/dist/mcp/index.js +25 -43
  52. package/lib/dist/mcp/index.js.map +1 -1
  53. package/lib/dist/mcp/ppid-watchdog.d.ts +18 -0
  54. package/lib/dist/mcp/ppid-watchdog.d.ts.map +1 -1
  55. package/lib/dist/mcp/ppid-watchdog.js +37 -0
  56. package/lib/dist/mcp/ppid-watchdog.js.map +1 -1
  57. package/lib/dist/mcp/query-pool.d.ts +94 -0
  58. package/lib/dist/mcp/query-pool.d.ts.map +1 -0
  59. package/lib/dist/mcp/query-pool.js +297 -0
  60. package/lib/dist/mcp/query-pool.js.map +1 -0
  61. package/lib/dist/mcp/query-worker.d.ts +24 -0
  62. package/lib/dist/mcp/query-worker.d.ts.map +1 -0
  63. package/lib/dist/mcp/query-worker.js +87 -0
  64. package/lib/dist/mcp/query-worker.js.map +1 -0
  65. package/lib/dist/mcp/tools.d.ts +57 -0
  66. package/lib/dist/mcp/tools.d.ts.map +1 -1
  67. package/lib/dist/mcp/tools.js +196 -40
  68. package/lib/dist/mcp/tools.js.map +1 -1
  69. package/lib/dist/project-config.d.ts +20 -0
  70. package/lib/dist/project-config.d.ts.map +1 -1
  71. package/lib/dist/project-config.js +42 -2
  72. package/lib/dist/project-config.js.map +1 -1
  73. package/lib/dist/resolution/c-fnptr-synthesizer.d.ts +0 -28
  74. package/lib/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -1
  75. package/lib/dist/resolution/c-fnptr-synthesizer.js +765 -79
  76. package/lib/dist/resolution/c-fnptr-synthesizer.js.map +1 -1
  77. package/lib/dist/resolution/name-matcher.d.ts.map +1 -1
  78. package/lib/dist/resolution/name-matcher.js +44 -0
  79. package/lib/dist/resolution/name-matcher.js.map +1 -1
  80. package/lib/dist/sync/worktree.d.ts +9 -0
  81. package/lib/dist/sync/worktree.d.ts.map +1 -1
  82. package/lib/dist/sync/worktree.js +40 -0
  83. package/lib/dist/sync/worktree.js.map +1 -1
  84. package/lib/dist/types.d.ts +6 -1
  85. package/lib/dist/types.d.ts.map +1 -1
  86. package/lib/node_modules/.package-lock.json +1 -1
  87. package/lib/package.json +1 -1
  88. package/package.json +1 -1
@@ -16,11 +16,38 @@
16
16
  * an absolute-path hash under `os.tmpdir()`. The pidfile always stays in the
17
17
  * project (it doesn't have a length limit) — and acts as the authoritative
18
18
  * pointer to the socket path the daemon chose.
19
+ *
20
+ * Second special-case (#997, #974): some filesystems can't host an AF_UNIX node
21
+ * AT ALL — ExFAT/FAT external volumes, certain network mounts, WSL2 DrvFs — so
22
+ * `listen()` throws ENOTSUP/EACCES regardless of path length. We can't cheaply
23
+ * tell those apart from a normal volume up front, so instead of guessing we
24
+ * expose an ORDERED candidate list (`getDaemonSocketCandidates`): the in-project
25
+ * path first, the deterministic tmpdir path as the fallback of last resort. The
26
+ * daemon binds the first that works (relocating past a capability error); the
27
+ * proxy connects the first that answers. Both walk the SAME list, so they still
28
+ * converge on whichever the daemon bound with zero coordination.
29
+ */
30
+ /**
31
+ * Ordered socket / named-pipe path candidates the daemon should try to bind (and
32
+ * the proxy should try to connect) for `projectRoot`, most-preferred first.
33
+ * Deterministic given a project root, so independent processes converge without
34
+ * coordination — even when the preferred candidate is unusable and both fall
35
+ * through to the same fallback.
36
+ *
37
+ * - Windows: a single named pipe (lives in the kernel pipe namespace, not on
38
+ * the project FS, so neither the length nor the ExFAT hazard applies).
39
+ * - Short in-project path: `[ .codegraph/daemon.sock , <tmpdir> ]` — try the
40
+ * project first, fall back to tmpdir if its FS can't host a socket (#997).
41
+ * - Long in-project path (deep monorepos, Bazel out dirs): `[ <tmpdir> ]` only
42
+ * — bind would throw ENAMETOOLONG, so we skip straight to tmpdir.
19
43
  */
44
+ export declare function getDaemonSocketCandidates(projectRoot: string): string[];
20
45
  /**
21
- * Compute the socket / named-pipe path the daemon should listen on (and the
22
- * proxy should connect to) for `projectRoot`. Deterministic given a project
23
- * root, so independent processes converge without coordination.
46
+ * The PREFERRED (primary) socket path candidate 0. Use this only where a
47
+ * single representative path is wanted (the lockfile's informational
48
+ * `socketPath` field, status display). For binding/connecting, walk the full
49
+ * {@link getDaemonSocketCandidates} list — the daemon may bind a fallback when
50
+ * candidate 0 is unusable.
24
51
  */
25
52
  export declare function getDaemonSocketPath(projectRoot: string): string;
26
53
  /** Absolute path to the daemon pid lockfile for `projectRoot`. */
@@ -1 +1 @@
1
- {"version":3,"file":"daemon-paths.d.ts","sourceRoot":"","sources":["../../src/mcp/daemon-paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAeH;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAS/D;AAED,kEAAkE;AAClE,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED,+CAA+C;AAC/C,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,CAE3D;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAuBjE"}
1
+ {"version":3,"file":"daemon-paths.d.ts","sourceRoot":"","sources":["../../src/mcp/daemon-paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AA0BH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,CAQvE;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAG/D;AAED,kEAAkE;AAClE,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED,+CAA+C;AAC/C,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,CAE3D;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAuBjE"}
@@ -17,6 +17,16 @@
17
17
  * an absolute-path hash under `os.tmpdir()`. The pidfile always stays in the
18
18
  * project (it doesn't have a length limit) — and acts as the authoritative
19
19
  * pointer to the socket path the daemon chose.
20
+ *
21
+ * Second special-case (#997, #974): some filesystems can't host an AF_UNIX node
22
+ * AT ALL — ExFAT/FAT external volumes, certain network mounts, WSL2 DrvFs — so
23
+ * `listen()` throws ENOTSUP/EACCES regardless of path length. We can't cheaply
24
+ * tell those apart from a normal volume up front, so instead of guessing we
25
+ * expose an ORDERED candidate list (`getDaemonSocketCandidates`): the in-project
26
+ * path first, the deterministic tmpdir path as the fallback of last resort. The
27
+ * daemon binds the first that works (relocating past a capability error); the
28
+ * proxy connects the first that answers. Both walk the SAME list, so they still
29
+ * converge on whichever the daemon bound with zero coordination.
20
30
  */
21
31
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
22
32
  if (k2 === undefined) k2 = k;
@@ -52,6 +62,7 @@ var __importStar = (this && this.__importStar) || (function () {
52
62
  };
53
63
  })();
54
64
  Object.defineProperty(exports, "__esModule", { value: true });
65
+ exports.getDaemonSocketCandidates = getDaemonSocketCandidates;
55
66
  exports.getDaemonSocketPath = getDaemonSocketPath;
56
67
  exports.getDaemonPidPath = getDaemonPidPath;
57
68
  exports.encodeLockInfo = encodeLockInfo;
@@ -67,20 +78,49 @@ function projectHash(projectRoot) {
67
78
  return crypto.createHash('sha256').update(path.resolve(projectRoot)).digest('hex').slice(0, 16);
68
79
  }
69
80
  /**
70
- * Compute the socket / named-pipe path the daemon should listen on (and the
71
- * proxy should connect to) for `projectRoot`. Deterministic given a project
72
- * root, so independent processes converge without coordination.
81
+ * The deterministic tmpdir socket path for `projectRoot` the fallback used
82
+ * when the in-project location can't host a socket (too long, or an FS that
83
+ * doesn't support AF_UNIX). Hash keeps it project-scoped, and being purely a
84
+ * function of the root means the daemon and the proxy compute the identical
85
+ * path without talking to each other.
73
86
  */
74
- function getDaemonSocketPath(projectRoot) {
87
+ function tmpdirSocketPath(projectRoot) {
88
+ return path.join(os.tmpdir(), `codegraph-${projectHash(projectRoot)}.sock`);
89
+ }
90
+ /**
91
+ * Ordered socket / named-pipe path candidates the daemon should try to bind (and
92
+ * the proxy should try to connect) for `projectRoot`, most-preferred first.
93
+ * Deterministic given a project root, so independent processes converge without
94
+ * coordination — even when the preferred candidate is unusable and both fall
95
+ * through to the same fallback.
96
+ *
97
+ * - Windows: a single named pipe (lives in the kernel pipe namespace, not on
98
+ * the project FS, so neither the length nor the ExFAT hazard applies).
99
+ * - Short in-project path: `[ .codegraph/daemon.sock , <tmpdir> ]` — try the
100
+ * project first, fall back to tmpdir if its FS can't host a socket (#997).
101
+ * - Long in-project path (deep monorepos, Bazel out dirs): `[ <tmpdir> ]` only
102
+ * — bind would throw ENAMETOOLONG, so we skip straight to tmpdir.
103
+ */
104
+ function getDaemonSocketCandidates(projectRoot) {
75
105
  if (process.platform === 'win32') {
76
- return `\\\\.\\pipe\\codegraph-${projectHash(projectRoot)}`;
106
+ return [`\\\\.\\pipe\\codegraph-${projectHash(projectRoot)}`];
77
107
  }
78
108
  const inProject = path.join((0, directory_1.getCodeGraphDir)(projectRoot), 'daemon.sock');
79
- if (inProject.length <= POSIX_SOCKET_PATH_LIMIT)
80
- return inProject;
81
- // Long project paths (deep monorepos, Bazel out dirs) need tmpdir fallback
82
- // or `bind` returns EADDRINUSE / ENAMETOOLONG. Hash keeps it project-scoped.
83
- return path.join(os.tmpdir(), `codegraph-${projectHash(projectRoot)}.sock`);
109
+ const tmp = tmpdirSocketPath(projectRoot);
110
+ if (inProject.length > POSIX_SOCKET_PATH_LIMIT)
111
+ return [tmp];
112
+ return [inProject, tmp];
113
+ }
114
+ /**
115
+ * The PREFERRED (primary) socket path — candidate 0. Use this only where a
116
+ * single representative path is wanted (the lockfile's informational
117
+ * `socketPath` field, status display). For binding/connecting, walk the full
118
+ * {@link getDaemonSocketCandidates} list — the daemon may bind a fallback when
119
+ * candidate 0 is unusable.
120
+ */
121
+ function getDaemonSocketPath(projectRoot) {
122
+ // The candidate list is never empty (≥1 on every platform), so [0] is safe.
123
+ return getDaemonSocketCandidates(projectRoot)[0];
84
124
  }
85
125
  /** Absolute path to the daemon pid lockfile for `projectRoot`. */
86
126
  function getDaemonPidPath(projectRoot) {
@@ -1 +1 @@
1
- {"version":3,"file":"daemon-paths.js","sourceRoot":"","sources":["../../src/mcp/daemon-paths.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;;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nD;AAED,0EAA0E;AAC1E,wBAAgB,cAAc,CAAC,GAAG,EAAE,YAAY,GAAG,IAAI,CAOtD;AAED,mEAAmE;AACnE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAMnD;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,YAAY,EAAE,CA2B1E;AA2BD,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,uFAAuF;IACvF,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,aAAa,GAAG,WAAW,CAAC;CACxD;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAmCpE;AAED,0CAA0C;AAC1C,wBAAsB,cAAc,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,CAM5D"}
@@ -155,11 +155,15 @@ function cleanupDaemonArtifacts(root) {
155
155
  }
156
156
  catch { /* gone */ }
157
157
  // POSIX sockets are real files; Windows named pipes vanish with the process.
158
+ // Sweep every candidate — a daemon that relocated past an unusable in-project
159
+ // FS (ExFAT/FAT; #997) left its socket at the tmpdir fallback, not candidate 0.
158
160
  if (process.platform !== 'win32') {
159
- try {
160
- fs.unlinkSync((0, daemon_paths_1.getDaemonSocketPath)(root));
161
+ for (const candidate of (0, daemon_paths_1.getDaemonSocketCandidates)(root)) {
162
+ try {
163
+ fs.unlinkSync(candidate);
164
+ }
165
+ catch { /* gone */ }
161
166
  }
162
- catch { /* gone */ }
163
167
  }
164
168
  deregisterDaemon(root);
165
169
  }
@@ -1 +1 @@
1
- {"version":3,"file":"daemon-registry.js","sourceRoot":"","sources":["../../src/mcp/daemon-registry.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,wCA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AAsB,CAAC,IAAI,CAAC,CAAC;QAC7B,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;IAC/C,CAAC;IAED,gFAAgF;IAChF,oEAAoE;IACpE,IAAI,CAAC;QAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IAAC,CAAC;IAAC,MAAM,CAAC,CAAC,mBAAmB,CAAC,CAAC;IACnE,IAAI,OAAO,GAA0B,MAAM,CAAC;IAC5C,IAAI,CAAC,CAAC,MAAM,YAAY,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC;QACrC,IAAI,CAAC;YAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QAAC,CAAC;QAAC,MAAM,CAAC,CAAC,mBAAmB,CAAC,CAAC;QACnE,MAAM,YAAY,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAC9B,OAAO,GAAG,MAAM,CAAC;IACnB,CAAC;IACD,sBAAsB,CAAC,IAAI,CAAC,CAAC;IAC7B,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC;AAChC,CAAC;AAED,0CAA0C;AACnC,KAAK,UAAU,cAAc;IAClC,MAAM,OAAO,GAAiB,EAAE,CAAC;IACjC,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,EAAE,CAAC;QAChC,OAAO,CAAC,IAAI,CAAC,MAAM,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -39,7 +39,18 @@
39
39
  * - The decision of *whether* to run as daemon at all — that's `MCPServer`.
40
40
  * - The MCP protocol state machine — that's `./session.ts`.
41
41
  */
42
+ import * as net from 'net';
42
43
  import { DaemonLockInfo } from './daemon-paths';
44
+ /**
45
+ * Finalize daemon shutdown. On POSIX, exit immediately — it's clean and fast.
46
+ * On Windows, do NOT force an exit while watchers may still be closing (that
47
+ * trips the libuv assertion above); instead mark success and let the loop drain
48
+ * to a natural exit, with an UNREF'd backstop that force-exits only if a stray
49
+ * handle would otherwise hang shutdown. Pure and platform-injected so both
50
+ * branches are unit-testable off-Windows. Returns the backstop timer (Windows)
51
+ * so callers/tests can clear it.
52
+ */
53
+ export declare function finalizeDaemonExit(platform: NodeJS.Platform, exit: (code: number) => void): NodeJS.Timeout | null;
43
54
  /** Bytes/parse-window for an oversized hello line — bounded against a malicious peer. */
44
55
  declare const MAX_HELLO_LINE_BYTES = 4096;
45
56
  /**
@@ -177,8 +188,29 @@ export type AcquireResult = {
177
188
  * the pidfile becomes visible in one step already containing a full record.
178
189
  * Whoever links first wins; everyone else gets EEXIST and reads a complete file.
179
190
  * There is no empty-file window at all.
191
+ *
192
+ * Filesystems without hard links (#997): ExFAT/FAT external volumes and some
193
+ * network mounts can't `link()` at all — it throws ENOTSUP/EPERM, which would
194
+ * otherwise kill the daemon before it ever reaches the socket bind. There we
195
+ * fall back to an O_EXCL create (`acquireLockViaExclusiveOpen`): still exclusive
196
+ * ("first writer wins"), but the full record is written through the fd in a
197
+ * second step, so the empty-file window the link approach removed is reopened —
198
+ * only on these filesystems, only for the microseconds between create and write
199
+ * (far narrower than the original bug, which the file watcher's startup latency
200
+ * widened). The race's worst case is two daemons briefly; on a single external
201
+ * drive that's strictly better than the daemon never starting at all.
180
202
  */
181
203
  export declare function tryAcquireDaemonLock(projectRoot: string): AcquireResult;
204
+ /**
205
+ * Exclusive-create the pidfile (O_CREAT|O_EXCL via the `wx` flag) and write the
206
+ * full record through the same fd — the hard-link-free fallback used by
207
+ * {@link tryAcquireDaemonLock} on filesystems without `link()`. Returns true if
208
+ * we created it (acquired the lock), false on EEXIST (another candidate holds
209
+ * it). Any other error propagates. Still exclusive, so "first writer wins" holds
210
+ * exactly as the link path does; the only difference is the brief empty-file
211
+ * window between create and write. Exported for testing.
212
+ */
213
+ export declare function acquireLockViaExclusiveOpen(pidPath: string, info: DaemonLockInfo): boolean;
182
214
  /**
183
215
  * Remove a stale pidfile, but only if it still names a dead process. Re-reads
184
216
  * the file immediately before unlinking so we never delete a lock that a live
@@ -197,6 +229,22 @@ export declare function clearStaleDaemonLock(pidPath: string, expectedDeadPid?:
197
229
  * mistake a live daemon for a dead one and clear its lock.
198
230
  */
199
231
  export declare function isProcessAlive(pid: number): boolean;
232
+ /**
233
+ * Bind the first usable socket from an ordered candidate list, relocating past
234
+ * any path that fails to bind for a non-conflict reason (see {@link
235
+ * SOCKET_BIND_CONFLICT_CODE}). The injected `listen` does the real
236
+ * `net.Server.listen` (and stale-socket clear); abstracted so the relocation
237
+ * policy is unit-testable without a real unsupported filesystem. Returns the
238
+ * server plus the path actually bound. An EADDRINUSE, or any error on the LAST
239
+ * candidate, propagates — the caller releases the lockfile and falls back to
240
+ * direct mode (#974). Exported for testing.
241
+ */
242
+ export declare function bindFirstUsableSocket(candidates: string[], listen: (socketPath: string) => Promise<net.Server>, opts?: {
243
+ onRelocate?: (from: string, to: string, code: string) => void;
244
+ }): Promise<{
245
+ server: net.Server;
246
+ socketPath: string;
247
+ }>;
200
248
  /**
201
249
  * Parse one client-hello line. Returns the peer pids if `line` is a well-formed
202
250
  * client-hello (carries the `codegraph_client` marker), or null otherwise — in
@@ -1 +1 @@
1
- {"version":3,"file":"daemon.d.ts","sourceRoot":"","sources":["../../src/mcp/daemon.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAQH,OAAO,EACL,cAAc,EAKf,MAAM,gBAAgB,CAAC;AAuBxB,yFAAyF;AACzF,QAAA,MAAM,oBAAoB,OAAO,CAAC;AAElC;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,CAAC,CAAC;CACb;AAED;;;;;;;;GAQ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oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,OAAO,CAiBvF;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CASnD;AAkBD;;;;;;;;;GASG;AACH,wBAAsB,qBAAqB,CACzC,UAAU,EAAE,MAAM,EAAE,EACpB,MAAM,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EACnD,IAAI,GAAE;IAAE,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CAAO,GAC3E,OAAO,CAAC;IAAE,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,CAoBrD;AA0BD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,GACX;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG,IAAI,CAOhD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE;IAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EACrD,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,GAChC,OAAO,CAKT;AAiED,sEAAsE;AACtE,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
@@ -75,9 +75,12 @@ var __importStar = (this && this.__importStar) || (function () {
75
75
  })();
76
76
  Object.defineProperty(exports, "__esModule", { value: true });
77
77
  exports.MAX_HELLO_LINE_BYTES = exports.Daemon = void 0;
78
+ exports.finalizeDaemonExit = finalizeDaemonExit;
78
79
  exports.tryAcquireDaemonLock = tryAcquireDaemonLock;
80
+ exports.acquireLockViaExclusiveOpen = acquireLockViaExclusiveOpen;
79
81
  exports.clearStaleDaemonLock = clearStaleDaemonLock;
80
82
  exports.isProcessAlive = isProcessAlive;
83
+ exports.bindFirstUsableSocket = bindFirstUsableSocket;
81
84
  exports.parseClientHelloLine = parseClientHelloLine;
82
85
  exports.peerIsDead = peerIsDead;
83
86
  const fs = __importStar(require("fs"));
@@ -100,6 +103,40 @@ const DEFAULT_IDLE_TIMEOUT_MS = 300_000;
100
103
  * Set generously so a real but momentarily-idle session isn't reaped mid-use.
101
104
  */
102
105
  const DEFAULT_MAX_IDLE_MS = 1_800_000; // 30 min
106
+ /**
107
+ * Windows-only shutdown backstop. On Windows, calling `process.exit()` while a
108
+ * recursive `fs.watch` handle is still tearing down aborts the process with a
109
+ * libuv `UV_HANDLE_CLOSING` assertion (`0xC0000409`) — reproducible whenever the
110
+ * watched tree contains a nested repo (submodule / embedded clone), since that's
111
+ * what keeps a watch active at shutdown. The fix is to let the event loop drain
112
+ * so libuv finishes closing those handles, then exit naturally; this timer only
113
+ * force-exits if some unexpected handle keeps the loop alive past the grace
114
+ * window. Kept short so shutdown stays snappy in that fallback. See
115
+ * `finalizeDaemonExit`.
116
+ */
117
+ const DAEMON_SHUTDOWN_BACKSTOP_MS = 2_000;
118
+ /**
119
+ * Finalize daemon shutdown. On POSIX, exit immediately — it's clean and fast.
120
+ * On Windows, do NOT force an exit while watchers may still be closing (that
121
+ * trips the libuv assertion above); instead mark success and let the loop drain
122
+ * to a natural exit, with an UNREF'd backstop that force-exits only if a stray
123
+ * handle would otherwise hang shutdown. Pure and platform-injected so both
124
+ * branches are unit-testable off-Windows. Returns the backstop timer (Windows)
125
+ * so callers/tests can clear it.
126
+ */
127
+ function finalizeDaemonExit(platform, exit) {
128
+ if (platform === 'win32') {
129
+ process.exitCode = 0;
130
+ const backstop = setTimeout(() => exit(0), DAEMON_SHUTDOWN_BACKSTOP_MS);
131
+ // Unref so it never keeps the loop alive: a natural drain (watchers closed,
132
+ // nothing else pending) exits before it fires; it only fires when some other
133
+ // handle is keeping the loop running, which is exactly when we need it.
134
+ backstop.unref?.();
135
+ return backstop;
136
+ }
137
+ exit(0);
138
+ return null;
139
+ }
103
140
  /** How often the daemon sweeps connected clients for a dead peer process (#692). */
104
141
  const DEFAULT_CLIENT_SWEEP_MS = 30_000;
105
142
  /** How long the daemon waits for the optional client-hello before proceeding without it. */
@@ -140,7 +177,12 @@ class Daemon {
140
177
  this.pidPath = (0, daemon_paths_1.getDaemonPidPath)(projectRoot);
141
178
  this.idleTimeoutMs = opts.idleTimeoutMs ?? resolveIdleTimeoutMs();
142
179
  this.maxIdleMs = opts.maxIdleMs ?? resolveMaxIdleMs();
143
- this.engine = new engine_1.MCPEngine();
180
+ // Daemon mode serves many concurrent clients on one event loop, so off-load
181
+ // read-tool dispatch to a worker pool — otherwise concurrent explores
182
+ // serialize and starve the MCP transport (clients time out). Direct mode
183
+ // (one stdio client) leaves the pool off; `CODEGRAPH_QUERY_POOL_SIZE=0`
184
+ // disables it here too.
185
+ this.engine = new engine_1.MCPEngine({ queryPool: true });
144
186
  this.engine.setProjectPathHint(projectRoot);
145
187
  }
146
188
  /**
@@ -154,53 +196,83 @@ class Daemon {
154
196
  // to land waits on `ensureInitialized` either way, and unloaded sessions
155
197
  // (cross-project tool calls only) shouldn't pay any open cost.
156
198
  void this.engine.ensureInitialized(this.projectRoot);
157
- // Stale socket file (left over from a SIGKILL'd previous daemon) will
158
- // wedge `listen` with EADDRINUSE. We arrived here holding the lockfile,
159
- // which means there's no live daemon, so it's safe to clear.
160
- if (process.platform !== 'win32') {
161
- try {
162
- fs.unlinkSync(this.socketPath);
199
+ // Walk the ordered socket candidates and bind the first that works. The
200
+ // in-project path comes first; the deterministic tmpdir path is the fallback
201
+ // for a filesystem that can't host an AF_UNIX node at all (ExFAT/FAT external
202
+ // volumes, some network mounts, WSL2 DrvFs → ENOTSUP/EACCES; #997, #974). The
203
+ // `listen` closure clears a stale socket (left by a SIGKILL'd previous daemon)
204
+ // before each attempt — safe because we hold the lockfile, so no live daemon
205
+ // owns it; without it `listen` would wedge on EADDRINUSE.
206
+ const candidates = (0, daemon_paths_1.getDaemonSocketCandidates)(this.projectRoot);
207
+ const listen = (socketPath) => new Promise((resolve, reject) => {
208
+ if (process.platform !== 'win32') {
209
+ try {
210
+ fs.unlinkSync(socketPath);
211
+ }
212
+ catch { /* not-exists is fine */ }
163
213
  }
164
- catch { /* not-exists is fine */ }
165
- }
166
- await new Promise((resolve, reject) => {
167
214
  const server = net.createServer((socket) => this.handleConnection(socket));
168
- server.once('error', (err) => reject(err));
169
- server.listen(this.socketPath, () => {
215
+ server.once('error', reject);
216
+ server.listen(socketPath, () => {
170
217
  // POSIX: tighten permissions to user-only — the socket lives under
171
- // `.codegraph/`, which is git-ignored but may be on a shared FS.
218
+ // `.codegraph/` (git-ignored, maybe a shared FS) or tmpdir.
172
219
  if (process.platform !== 'win32') {
173
220
  try {
174
- fs.chmodSync(this.socketPath, 0o600);
221
+ fs.chmodSync(socketPath, 0o600);
175
222
  }
176
223
  catch { /* best-effort */ }
177
224
  }
178
- this.server = server;
179
- resolve();
225
+ resolve(server);
180
226
  });
181
- }).catch((err) => {
182
- // Bind failed — e.g. AF_UNIX is unsupported/unreliable on this filesystem
183
- // (the WSL2 DrvFs hazard behind #974), or a stale socket we couldn't clear.
184
- // We already hold the lockfile that `tryAcquireDaemonLock` wrote; release it
185
- // and any partial socket so the NEXT launcher doesn't spin respawning us on
186
- // a stale lock that points at our now-dying pid. Then re-throw so the caller
187
- // (the bin's try/catch) exits this detached daemon cleanly and every
188
- // launcher falls back to direct mode.
227
+ });
228
+ let bound;
229
+ try {
230
+ bound = await bindFirstUsableSocket(candidates, listen, {
231
+ onRelocate: (from, to, code) => process.stderr.write(`[CodeGraph daemon] Socket ${from} unusable (${code}); relocating to ${to}.\n`),
232
+ });
233
+ }
234
+ catch (err) {
235
+ // Every candidate failed (the last one, or a non-relocatable error like a
236
+ // racing EADDRINUSE). We already hold the lockfile `tryAcquireDaemonLock`
237
+ // wrote; release it and any partial sockets so the NEXT launcher doesn't
238
+ // spin respawning us on a stale lock pointing at our now-dying pid. Then
239
+ // re-throw so the caller (the bin's try/catch) exits this detached daemon
240
+ // cleanly and every launcher falls back to direct mode (#974).
189
241
  this.cleanupLockfile();
190
242
  if (process.platform !== 'win32') {
191
- try {
192
- fs.unlinkSync(this.socketPath);
243
+ for (const candidate of candidates) {
244
+ try {
245
+ fs.unlinkSync(candidate);
246
+ }
247
+ catch { /* may not exist */ }
193
248
  }
194
- catch { /* may not exist */ }
195
249
  }
196
250
  throw err;
197
- });
251
+ }
252
+ this.server = bound.server;
253
+ // Adopt the path we ACTUALLY bound — it may be a tmpdir fallback past an
254
+ // unusable in-project location. Everything downstream (lockfile, registry,
255
+ // chmod, cleanup, status) keys off this real path, not the preferred guess.
256
+ this.socketPath = bound.socketPath;
198
257
  const lock = {
199
258
  pid: process.pid,
200
259
  version: version_1.CodeGraphPackageVersion,
201
260
  socketPath: this.socketPath,
202
261
  startedAt: Date.now(),
203
262
  };
263
+ // `tryAcquireDaemonLock` wrote the pidfile with the PREFERRED path (candidate
264
+ // 0) before we knew which one would bind. If we relocated, rewrite it so the
265
+ // per-project record is honest. Atomic temp+rename; safe because we hold the
266
+ // lock and we're alive — `clearStaleDaemonLock` pid-verifies, so no racing
267
+ // candidate clears or clobbers a live daemon's lock.
268
+ if (this.socketPath !== candidates[0]) {
269
+ try {
270
+ const tmpPid = `${this.pidPath}.${process.pid}.relocate`;
271
+ fs.writeFileSync(tmpPid, (0, daemon_paths_1.encodeLockInfo)(lock), { mode: 0o600 });
272
+ fs.renameSync(tmpPid, this.pidPath);
273
+ }
274
+ catch { /* best-effort; the registry record below carries the real path */ }
275
+ }
204
276
  // Drop a discovery record so `codegraph list` / `stop --all` can find us.
205
277
  // Best-effort; a missing record only means list's liveness prune covers it.
206
278
  (0, daemon_registry_1.registerDaemon)({ root: this.projectRoot, ...lock });
@@ -260,7 +332,10 @@ class Daemon {
260
332
  }
261
333
  catch { /* may already be gone */ }
262
334
  }
263
- process.exit(0);
335
+ // POSIX exits here; Windows drains first (engine.stop() above began closing
336
+ // the file watcher, and exiting mid-teardown aborts the process). See
337
+ // finalizeDaemonExit / DAEMON_SHUTDOWN_BACKSTOP_MS.
338
+ finalizeDaemonExit(process.platform, (code) => process.exit(code));
264
339
  }
265
340
  handleConnection(socket) {
266
341
  // Hello first so the proxy can verify versions before piping any
@@ -415,6 +490,17 @@ exports.Daemon = Daemon;
415
490
  * the pidfile becomes visible in one step already containing a full record.
416
491
  * Whoever links first wins; everyone else gets EEXIST and reads a complete file.
417
492
  * There is no empty-file window at all.
493
+ *
494
+ * Filesystems without hard links (#997): ExFAT/FAT external volumes and some
495
+ * network mounts can't `link()` at all — it throws ENOTSUP/EPERM, which would
496
+ * otherwise kill the daemon before it ever reaches the socket bind. There we
497
+ * fall back to an O_EXCL create (`acquireLockViaExclusiveOpen`): still exclusive
498
+ * ("first writer wins"), but the full record is written through the fd in a
499
+ * second step, so the empty-file window the link approach removed is reopened —
500
+ * only on these filesystems, only for the microseconds between create and write
501
+ * (far narrower than the original bug, which the file watcher's startup latency
502
+ * widened). The race's worst case is two daemons briefly; on a single external
503
+ * drive that's strictly better than the daemon never starting at all.
418
504
  */
419
505
  function tryAcquireDaemonLock(projectRoot) {
420
506
  const pidPath = (0, daemon_paths_1.getDaemonPidPath)(projectRoot);
@@ -433,12 +519,23 @@ function tryAcquireDaemonLock(projectRoot) {
433
519
  try {
434
520
  fs.writeFileSync(tmp, (0, daemon_paths_1.encodeLockInfo)(info), { mode: 0o600 });
435
521
  try {
436
- fs.linkSync(tmp, pidPath); // atomic + exclusive
522
+ fs.linkSync(tmp, pidPath); // atomic + exclusive (race-free; see must-fix 1)
437
523
  acquired = true;
438
524
  }
439
525
  catch (err) {
440
- if (err.code !== 'EEXIST')
441
- throw err;
526
+ if (err.code === 'EEXIST') {
527
+ // Lost the race — another candidate already holds it. Fall through to read.
528
+ }
529
+ else {
530
+ // link() failed for a non-conflict reason — nearly always "this filesystem
531
+ // has no hard links" (ExFAT/FAT external volumes, some network mounts),
532
+ // which surfaces as a DIFFERENT errno on every OS: ENOTSUP on macOS, EPERM
533
+ // on Linux, EISDIR on Windows (#997). Enumerating them is whack-a-mole and
534
+ // unnecessary: the `tmp` write above already proved this directory is
535
+ // writable, so an O_EXCL create is a valid atomic+exclusive substitute. If
536
+ // IT fails too, that's a genuine error and propagates. EEXIST ⇒ taken.
537
+ acquired = acquireLockViaExclusiveOpen(pidPath, info);
538
+ }
442
539
  }
443
540
  }
444
541
  finally {
@@ -459,6 +556,33 @@ function tryAcquireDaemonLock(projectRoot) {
459
556
  catch { /* unreadable lockfile — treat as malformed */ }
460
557
  return { kind: 'taken', existing, pidPath };
461
558
  }
559
+ /**
560
+ * Exclusive-create the pidfile (O_CREAT|O_EXCL via the `wx` flag) and write the
561
+ * full record through the same fd — the hard-link-free fallback used by
562
+ * {@link tryAcquireDaemonLock} on filesystems without `link()`. Returns true if
563
+ * we created it (acquired the lock), false on EEXIST (another candidate holds
564
+ * it). Any other error propagates. Still exclusive, so "first writer wins" holds
565
+ * exactly as the link path does; the only difference is the brief empty-file
566
+ * window between create and write. Exported for testing.
567
+ */
568
+ function acquireLockViaExclusiveOpen(pidPath, info) {
569
+ let fd;
570
+ try {
571
+ fd = fs.openSync(pidPath, 'wx', 0o600); // O_CREAT | O_EXCL | O_WRONLY
572
+ }
573
+ catch (err) {
574
+ if (err.code === 'EEXIST')
575
+ return false;
576
+ throw err;
577
+ }
578
+ try {
579
+ fs.writeSync(fd, (0, daemon_paths_1.encodeLockInfo)(info));
580
+ }
581
+ finally {
582
+ fs.closeSync(fd);
583
+ }
584
+ return true;
585
+ }
462
586
  /**
463
587
  * Remove a stale pidfile, but only if it still names a dead process. Re-reads
464
588
  * the file immediately before unlinking so we never delete a lock that a live
@@ -509,6 +633,53 @@ function isProcessAlive(pid) {
509
633
  return false;
510
634
  }
511
635
  }
636
+ /**
637
+ * The one `listen()` error we must NOT relocate past. EADDRINUSE means the path
638
+ * is genuinely occupied — a racing daemon that legitimately owns it, or a
639
+ * leftover node we couldn't clear (the #974 planted-dir case) — so relocating
640
+ * would abandon a path another daemon owns; the caller instead releases its lock
641
+ * and falls back to direct mode. EVERY OTHER bind error just means "this path
642
+ * didn't work," almost always a filesystem that can't host an AF_UNIX node at all
643
+ * (ExFAT/FAT, network mounts, WSL2 DrvFs), which reports a DIFFERENT errno per OS
644
+ * (ENOTSUP macOS, EPERM Linux; #997). Enumerating the "unsupported" codes is
645
+ * whack-a-mole, so we relocate on anything-but-conflict instead — robust and
646
+ * self-correcting: if the deterministic tmpdir fallback ALSO fails, that error
647
+ * propagates from the last candidate. (ENAMETOOLONG never reaches here — the
648
+ * candidate list already routes over-long paths straight to tmpdir.)
649
+ */
650
+ const SOCKET_BIND_CONFLICT_CODE = 'EADDRINUSE';
651
+ /**
652
+ * Bind the first usable socket from an ordered candidate list, relocating past
653
+ * any path that fails to bind for a non-conflict reason (see {@link
654
+ * SOCKET_BIND_CONFLICT_CODE}). The injected `listen` does the real
655
+ * `net.Server.listen` (and stale-socket clear); abstracted so the relocation
656
+ * policy is unit-testable without a real unsupported filesystem. Returns the
657
+ * server plus the path actually bound. An EADDRINUSE, or any error on the LAST
658
+ * candidate, propagates — the caller releases the lockfile and falls back to
659
+ * direct mode (#974). Exported for testing.
660
+ */
661
+ async function bindFirstUsableSocket(candidates, listen, opts = {}) {
662
+ let lastErr;
663
+ for (let i = 0; i < candidates.length; i++) {
664
+ const socketPath = candidates[i]; // i < length, so always defined
665
+ const isLast = i === candidates.length - 1;
666
+ try {
667
+ const server = await listen(socketPath);
668
+ return { server, socketPath };
669
+ }
670
+ catch (err) {
671
+ lastErr = err;
672
+ const code = err.code;
673
+ if (!isLast && code !== SOCKET_BIND_CONFLICT_CODE) {
674
+ opts.onRelocate?.(socketPath, candidates[i + 1], code ?? ''); // !isLast ⇒ i+1 in range
675
+ continue;
676
+ }
677
+ throw err;
678
+ }
679
+ }
680
+ // Only reachable with an empty candidate list — a programmer error.
681
+ throw lastErr ?? new Error('no socket candidates to bind');
682
+ }
512
683
  function resolveIdleTimeoutMs() {
513
684
  const raw = process.env.CODEGRAPH_DAEMON_IDLE_TIMEOUT_MS;
514
685
  if (raw === undefined || raw === '')