@colbymchenry/codegraph-win32-arm64 1.4.1 → 1.6.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 (314) hide show
  1. package/bin/codegraph.cmd +1 -1
  2. package/lib/dist/bin/codegraph.js +206 -44
  3. package/lib/dist/bin/codegraph.js.map +1 -1
  4. package/lib/dist/context/formatter.d.ts +7 -1
  5. package/lib/dist/context/formatter.d.ts.map +1 -1
  6. package/lib/dist/context/formatter.js +12 -6
  7. package/lib/dist/context/formatter.js.map +1 -1
  8. package/lib/dist/context/index.d.ts +12 -0
  9. package/lib/dist/context/index.d.ts.map +1 -1
  10. package/lib/dist/context/index.js +101 -25
  11. package/lib/dist/context/index.js.map +1 -1
  12. package/lib/dist/db/index.d.ts +179 -0
  13. package/lib/dist/db/index.d.ts.map +1 -1
  14. package/lib/dist/db/index.js +368 -7
  15. package/lib/dist/db/index.js.map +1 -1
  16. package/lib/dist/db/migrations.d.ts +1 -1
  17. package/lib/dist/db/migrations.d.ts.map +1 -1
  18. package/lib/dist/db/migrations.js +25 -1
  19. package/lib/dist/db/migrations.js.map +1 -1
  20. package/lib/dist/db/queries.d.ts +234 -5
  21. package/lib/dist/db/queries.d.ts.map +1 -1
  22. package/lib/dist/db/queries.js +687 -53
  23. package/lib/dist/db/queries.js.map +1 -1
  24. package/lib/dist/db/schema.sql +16 -3
  25. package/lib/dist/db/sqlite-adapter.d.ts +3 -1
  26. package/lib/dist/db/sqlite-adapter.d.ts.map +1 -1
  27. package/lib/dist/db/sqlite-adapter.js +22 -4
  28. package/lib/dist/db/sqlite-adapter.js.map +1 -1
  29. package/lib/dist/db/wal-valve.d.ts +15 -2
  30. package/lib/dist/db/wal-valve.d.ts.map +1 -1
  31. package/lib/dist/db/wal-valve.js +88 -6
  32. package/lib/dist/db/wal-valve.js.map +1 -1
  33. package/lib/dist/directory.d.ts +29 -0
  34. package/lib/dist/directory.d.ts.map +1 -1
  35. package/lib/dist/directory.js +52 -0
  36. package/lib/dist/directory.js.map +1 -1
  37. package/lib/dist/extraction/extraction-version.d.ts +1 -1
  38. package/lib/dist/extraction/extraction-version.js +1 -1
  39. package/lib/dist/extraction/function-ref.d.ts.map +1 -1
  40. package/lib/dist/extraction/function-ref.js +6 -0
  41. package/lib/dist/extraction/function-ref.js.map +1 -1
  42. package/lib/dist/extraction/generated-detection.d.ts +48 -12
  43. package/lib/dist/extraction/generated-detection.d.ts.map +1 -1
  44. package/lib/dist/extraction/generated-detection.js +176 -11
  45. package/lib/dist/extraction/generated-detection.js.map +1 -1
  46. package/lib/dist/extraction/grammars.d.ts.map +1 -1
  47. package/lib/dist/extraction/grammars.js +101 -2
  48. package/lib/dist/extraction/grammars.js.map +1 -1
  49. package/lib/dist/extraction/index.d.ts +138 -3
  50. package/lib/dist/extraction/index.d.ts.map +1 -1
  51. package/lib/dist/extraction/index.js +518 -94
  52. package/lib/dist/extraction/index.js.map +1 -1
  53. package/lib/dist/extraction/kernel/decode.d.ts +9 -0
  54. package/lib/dist/extraction/kernel/decode.d.ts.map +1 -0
  55. package/lib/dist/extraction/kernel/decode.js +162 -0
  56. package/lib/dist/extraction/kernel/decode.js.map +1 -0
  57. package/lib/dist/extraction/kernel/index.d.ts +64 -0
  58. package/lib/dist/extraction/kernel/index.d.ts.map +1 -0
  59. package/lib/dist/extraction/kernel/index.js +279 -0
  60. package/lib/dist/extraction/kernel/index.js.map +1 -0
  61. package/lib/dist/extraction/kernel/layout.d.ts +101 -0
  62. package/lib/dist/extraction/kernel/layout.d.ts.map +1 -0
  63. package/lib/dist/extraction/kernel/layout.js +104 -0
  64. package/lib/dist/extraction/kernel/layout.js.map +1 -0
  65. package/lib/dist/extraction/kernel/loader.d.ts +103 -0
  66. package/lib/dist/extraction/kernel/loader.d.ts.map +1 -0
  67. package/lib/dist/extraction/kernel/loader.js +146 -0
  68. package/lib/dist/extraction/kernel/loader.js.map +1 -0
  69. package/lib/dist/extraction/languages/c-cpp.d.ts +14 -0
  70. package/lib/dist/extraction/languages/c-cpp.d.ts.map +1 -1
  71. package/lib/dist/extraction/languages/c-cpp.js +868 -16
  72. package/lib/dist/extraction/languages/c-cpp.js.map +1 -1
  73. package/lib/dist/extraction/languages/erlang.d.ts.map +1 -1
  74. package/lib/dist/extraction/languages/erlang.js +58 -22
  75. package/lib/dist/extraction/languages/erlang.js.map +1 -1
  76. package/lib/dist/extraction/languages/objc.d.ts.map +1 -1
  77. package/lib/dist/extraction/languages/objc.js +4 -0
  78. package/lib/dist/extraction/languages/objc.js.map +1 -1
  79. package/lib/dist/extraction/languages/rust.d.ts +20 -0
  80. package/lib/dist/extraction/languages/rust.d.ts.map +1 -1
  81. package/lib/dist/extraction/languages/rust.js +47 -20
  82. package/lib/dist/extraction/languages/rust.js.map +1 -1
  83. package/lib/dist/extraction/parse-pool.d.ts +15 -0
  84. package/lib/dist/extraction/parse-pool.d.ts.map +1 -1
  85. package/lib/dist/extraction/parse-pool.js +35 -1
  86. package/lib/dist/extraction/parse-pool.js.map +1 -1
  87. package/lib/dist/extraction/parse-worker.js +35 -1
  88. package/lib/dist/extraction/parse-worker.js.map +1 -1
  89. package/lib/dist/extraction/store-worker.d.ts +24 -0
  90. package/lib/dist/extraction/store-worker.d.ts.map +1 -0
  91. package/lib/dist/extraction/store-worker.js +139 -0
  92. package/lib/dist/extraction/store-worker.js.map +1 -0
  93. package/lib/dist/extraction/store-writer.d.ts +63 -0
  94. package/lib/dist/extraction/store-writer.d.ts.map +1 -0
  95. package/lib/dist/extraction/store-writer.js +174 -0
  96. package/lib/dist/extraction/store-writer.js.map +1 -0
  97. package/lib/dist/extraction/tree-sitter-types.d.ts +2 -0
  98. package/lib/dist/extraction/tree-sitter-types.d.ts.map +1 -1
  99. package/lib/dist/extraction/tree-sitter.d.ts +27 -5
  100. package/lib/dist/extraction/tree-sitter.d.ts.map +1 -1
  101. package/lib/dist/extraction/tree-sitter.js +257 -56
  102. package/lib/dist/extraction/tree-sitter.js.map +1 -1
  103. package/lib/dist/extraction/wasm/tree-sitter-c.wasm +0 -0
  104. package/lib/dist/extraction/wasm/tree-sitter-cpp.wasm +0 -0
  105. package/lib/dist/extraction/wasm/tree-sitter-dart.wasm +0 -0
  106. package/lib/dist/extraction/wasm/tree-sitter-go.wasm +0 -0
  107. package/lib/dist/extraction/wasm/tree-sitter-java.wasm +0 -0
  108. package/lib/dist/extraction/wasm/tree-sitter-javascript.wasm +0 -0
  109. package/lib/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
  110. package/lib/dist/extraction/wasm/tree-sitter-php.wasm +0 -0
  111. package/lib/dist/extraction/wasm/tree-sitter-python.wasm +0 -0
  112. package/lib/dist/extraction/wasm/tree-sitter-ruby.wasm +0 -0
  113. package/lib/dist/extraction/wasm/tree-sitter-rust.wasm +0 -0
  114. package/lib/dist/extraction/wasm/tree-sitter-swift.wasm +0 -0
  115. package/lib/dist/extraction/wasm/tree-sitter-tsx.wasm +0 -0
  116. package/lib/dist/extraction/wasm/tree-sitter-typescript.wasm +0 -0
  117. package/lib/dist/extraction/wasm-runtime-flags.d.ts +15 -0
  118. package/lib/dist/extraction/wasm-runtime-flags.d.ts.map +1 -1
  119. package/lib/dist/extraction/wasm-runtime-flags.js +27 -3
  120. package/lib/dist/extraction/wasm-runtime-flags.js.map +1 -1
  121. package/lib/dist/graph/queries.d.ts.map +1 -1
  122. package/lib/dist/graph/queries.js +2 -0
  123. package/lib/dist/graph/queries.js.map +1 -1
  124. package/lib/dist/graph/traversal.js +1 -1
  125. package/lib/dist/graph/traversal.js.map +1 -1
  126. package/lib/dist/index.d.ts +36 -2
  127. package/lib/dist/index.d.ts.map +1 -1
  128. package/lib/dist/index.js +305 -11
  129. package/lib/dist/index.js.map +1 -1
  130. package/lib/dist/installer/beta-signup.d.ts +54 -0
  131. package/lib/dist/installer/beta-signup.d.ts.map +1 -0
  132. package/lib/dist/installer/beta-signup.js +178 -0
  133. package/lib/dist/installer/beta-signup.js.map +1 -0
  134. package/lib/dist/installer/index.d.ts +4 -3
  135. package/lib/dist/installer/index.d.ts.map +1 -1
  136. package/lib/dist/installer/index.js +19 -6
  137. package/lib/dist/installer/index.js.map +1 -1
  138. package/lib/dist/installer/targets/claude.d.ts.map +1 -1
  139. package/lib/dist/installer/targets/claude.js +37 -5
  140. package/lib/dist/installer/targets/claude.js.map +1 -1
  141. package/lib/dist/installer/targets/codex.d.ts +22 -8
  142. package/lib/dist/installer/targets/codex.d.ts.map +1 -1
  143. package/lib/dist/installer/targets/codex.js +65 -48
  144. package/lib/dist/installer/targets/codex.js.map +1 -1
  145. package/lib/dist/installer/targets/copilot-cli.d.ts +32 -0
  146. package/lib/dist/installer/targets/copilot-cli.d.ts.map +1 -0
  147. package/lib/dist/installer/targets/copilot-cli.js +209 -0
  148. package/lib/dist/installer/targets/copilot-cli.js.map +1 -0
  149. package/lib/dist/installer/targets/copilot-jetbrains.d.ts +42 -0
  150. package/lib/dist/installer/targets/copilot-jetbrains.d.ts.map +1 -0
  151. package/lib/dist/installer/targets/copilot-jetbrains.js +238 -0
  152. package/lib/dist/installer/targets/copilot-jetbrains.js.map +1 -0
  153. package/lib/dist/installer/targets/copilot-vscode.d.ts +47 -0
  154. package/lib/dist/installer/targets/copilot-vscode.d.ts.map +1 -0
  155. package/lib/dist/installer/targets/copilot-vscode.js +219 -0
  156. package/lib/dist/installer/targets/copilot-vscode.js.map +1 -0
  157. package/lib/dist/installer/targets/registry.d.ts.map +1 -1
  158. package/lib/dist/installer/targets/registry.js +6 -0
  159. package/lib/dist/installer/targets/registry.js.map +1 -1
  160. package/lib/dist/installer/targets/toml.d.ts +6 -5
  161. package/lib/dist/installer/targets/toml.d.ts.map +1 -1
  162. package/lib/dist/installer/targets/toml.js +99 -20
  163. package/lib/dist/installer/targets/toml.js.map +1 -1
  164. package/lib/dist/installer/targets/types.d.ts +5 -5
  165. package/lib/dist/installer/targets/types.d.ts.map +1 -1
  166. package/lib/dist/mcp/daemon-manager.d.ts +1 -1
  167. package/lib/dist/mcp/daemon-manager.d.ts.map +1 -1
  168. package/lib/dist/mcp/daemon-manager.js +1 -1
  169. package/lib/dist/mcp/daemon-manager.js.map +1 -1
  170. package/lib/dist/mcp/daemon-paths.d.ts +6 -0
  171. package/lib/dist/mcp/daemon-paths.d.ts.map +1 -1
  172. package/lib/dist/mcp/daemon-paths.js +54 -0
  173. package/lib/dist/mcp/daemon-paths.js.map +1 -1
  174. package/lib/dist/mcp/daemon-registry.d.ts +10 -0
  175. package/lib/dist/mcp/daemon-registry.d.ts.map +1 -1
  176. package/lib/dist/mcp/daemon-registry.js +51 -3
  177. package/lib/dist/mcp/daemon-registry.js.map +1 -1
  178. package/lib/dist/mcp/daemon.d.ts +9 -6
  179. package/lib/dist/mcp/daemon.d.ts.map +1 -1
  180. package/lib/dist/mcp/daemon.js +10 -8
  181. package/lib/dist/mcp/daemon.js.map +1 -1
  182. package/lib/dist/mcp/engine.d.ts +3 -0
  183. package/lib/dist/mcp/engine.d.ts.map +1 -1
  184. package/lib/dist/mcp/engine.js +45 -3
  185. package/lib/dist/mcp/engine.js.map +1 -1
  186. package/lib/dist/mcp/explore-dedup.d.ts +137 -0
  187. package/lib/dist/mcp/explore-dedup.d.ts.map +1 -0
  188. package/lib/dist/mcp/explore-dedup.js +236 -0
  189. package/lib/dist/mcp/explore-dedup.js.map +1 -0
  190. package/lib/dist/mcp/explore-diagnostics.d.ts +289 -0
  191. package/lib/dist/mcp/explore-diagnostics.d.ts.map +1 -0
  192. package/lib/dist/mcp/explore-diagnostics.js +558 -0
  193. package/lib/dist/mcp/explore-diagnostics.js.map +1 -0
  194. package/lib/dist/mcp/explore-session-state.d.ts +217 -0
  195. package/lib/dist/mcp/explore-session-state.d.ts.map +1 -0
  196. package/lib/dist/mcp/explore-session-state.js +322 -0
  197. package/lib/dist/mcp/explore-session-state.js.map +1 -0
  198. package/lib/dist/mcp/index.d.ts +24 -0
  199. package/lib/dist/mcp/index.d.ts.map +1 -1
  200. package/lib/dist/mcp/index.js +67 -6
  201. package/lib/dist/mcp/index.js.map +1 -1
  202. package/lib/dist/mcp/liveness-watchdog.d.ts.map +1 -1
  203. package/lib/dist/mcp/liveness-watchdog.js +3 -1
  204. package/lib/dist/mcp/liveness-watchdog.js.map +1 -1
  205. package/lib/dist/mcp/proxy.d.ts.map +1 -1
  206. package/lib/dist/mcp/proxy.js +6 -1
  207. package/lib/dist/mcp/proxy.js.map +1 -1
  208. package/lib/dist/mcp/server-instructions.d.ts +2 -2
  209. package/lib/dist/mcp/server-instructions.d.ts.map +1 -1
  210. package/lib/dist/mcp/server-instructions.js +8 -3
  211. package/lib/dist/mcp/server-instructions.js.map +1 -1
  212. package/lib/dist/mcp/session.d.ts +16 -0
  213. package/lib/dist/mcp/session.d.ts.map +1 -1
  214. package/lib/dist/mcp/session.js +36 -13
  215. package/lib/dist/mcp/session.js.map +1 -1
  216. package/lib/dist/mcp/tools.d.ts +276 -10
  217. package/lib/dist/mcp/tools.d.ts.map +1 -1
  218. package/lib/dist/mcp/tools.js +2425 -237
  219. package/lib/dist/mcp/tools.js.map +1 -1
  220. package/lib/dist/project-config.d.ts +23 -0
  221. package/lib/dist/project-config.d.ts.map +1 -1
  222. package/lib/dist/project-config.js +39 -2
  223. package/lib/dist/project-config.js.map +1 -1
  224. package/lib/dist/resolution/c-fnptr-synthesizer.d.ts +1 -1
  225. package/lib/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -1
  226. package/lib/dist/resolution/c-fnptr-synthesizer.js +582 -138
  227. package/lib/dist/resolution/c-fnptr-synthesizer.js.map +1 -1
  228. package/lib/dist/resolution/callback-synthesizer.d.ts +54 -10
  229. package/lib/dist/resolution/callback-synthesizer.d.ts.map +1 -1
  230. package/lib/dist/resolution/callback-synthesizer.js +287 -167
  231. package/lib/dist/resolution/callback-synthesizer.js.map +1 -1
  232. package/lib/dist/resolution/cooperative-yield.d.ts +10 -2
  233. package/lib/dist/resolution/cooperative-yield.d.ts.map +1 -1
  234. package/lib/dist/resolution/cooperative-yield.js +6 -4
  235. package/lib/dist/resolution/cooperative-yield.js.map +1 -1
  236. package/lib/dist/resolution/frameworks/go.d.ts.map +1 -1
  237. package/lib/dist/resolution/frameworks/go.js +29 -6
  238. package/lib/dist/resolution/frameworks/go.js.map +1 -1
  239. package/lib/dist/resolution/frameworks/swift.d.ts.map +1 -1
  240. package/lib/dist/resolution/frameworks/swift.js +11 -1
  241. package/lib/dist/resolution/frameworks/swift.js.map +1 -1
  242. package/lib/dist/resolution/import-resolver.d.ts +2 -3
  243. package/lib/dist/resolution/import-resolver.d.ts.map +1 -1
  244. package/lib/dist/resolution/import-resolver.js +184 -9
  245. package/lib/dist/resolution/import-resolver.js.map +1 -1
  246. package/lib/dist/resolution/index.d.ts +87 -2
  247. package/lib/dist/resolution/index.d.ts.map +1 -1
  248. package/lib/dist/resolution/index.js +731 -134
  249. package/lib/dist/resolution/index.js.map +1 -1
  250. package/lib/dist/resolution/memory-budget.d.ts +48 -0
  251. package/lib/dist/resolution/memory-budget.d.ts.map +1 -0
  252. package/lib/dist/resolution/memory-budget.js +162 -0
  253. package/lib/dist/resolution/memory-budget.js.map +1 -0
  254. package/lib/dist/resolution/name-matcher.d.ts +42 -1
  255. package/lib/dist/resolution/name-matcher.d.ts.map +1 -1
  256. package/lib/dist/resolution/name-matcher.js +681 -99
  257. package/lib/dist/resolution/name-matcher.js.map +1 -1
  258. package/lib/dist/resolution/path-aliases.d.ts +6 -4
  259. package/lib/dist/resolution/path-aliases.d.ts.map +1 -1
  260. package/lib/dist/resolution/path-aliases.js +125 -17
  261. package/lib/dist/resolution/path-aliases.js.map +1 -1
  262. package/lib/dist/resolution/resolver-pool.d.ts +106 -0
  263. package/lib/dist/resolution/resolver-pool.d.ts.map +1 -0
  264. package/lib/dist/resolution/resolver-pool.js +344 -0
  265. package/lib/dist/resolution/resolver-pool.js.map +1 -0
  266. package/lib/dist/resolution/resolver-worker.d.ts +17 -0
  267. package/lib/dist/resolution/resolver-worker.d.ts.map +1 -0
  268. package/lib/dist/resolution/resolver-worker.js +141 -0
  269. package/lib/dist/resolution/resolver-worker.js.map +1 -0
  270. package/lib/dist/resolution/types.d.ts +3 -0
  271. package/lib/dist/resolution/types.d.ts.map +1 -1
  272. package/lib/dist/search/identifier-segments.d.ts +10 -0
  273. package/lib/dist/search/identifier-segments.d.ts.map +1 -1
  274. package/lib/dist/search/identifier-segments.js +29 -0
  275. package/lib/dist/search/identifier-segments.js.map +1 -1
  276. package/lib/dist/search/query-paths.d.ts +57 -0
  277. package/lib/dist/search/query-paths.d.ts.map +1 -0
  278. package/lib/dist/search/query-paths.js +298 -0
  279. package/lib/dist/search/query-paths.js.map +1 -0
  280. package/lib/dist/search/query-utils.d.ts +1 -1
  281. package/lib/dist/search/query-utils.d.ts.map +1 -1
  282. package/lib/dist/search/query-utils.js +13 -3
  283. package/lib/dist/search/query-utils.js.map +1 -1
  284. package/lib/dist/sync/watcher.d.ts +47 -1
  285. package/lib/dist/sync/watcher.d.ts.map +1 -1
  286. package/lib/dist/sync/watcher.js +127 -8
  287. package/lib/dist/sync/watcher.js.map +1 -1
  288. package/lib/dist/types.d.ts +61 -3
  289. package/lib/dist/types.d.ts.map +1 -1
  290. package/lib/dist/types.js +27 -1
  291. package/lib/dist/types.js.map +1 -1
  292. package/lib/dist/ui/color.d.ts +21 -0
  293. package/lib/dist/ui/color.d.ts.map +1 -0
  294. package/lib/dist/ui/color.js +42 -0
  295. package/lib/dist/ui/color.js.map +1 -0
  296. package/lib/dist/ui/glyphs.d.ts +35 -10
  297. package/lib/dist/ui/glyphs.d.ts.map +1 -1
  298. package/lib/dist/ui/glyphs.js +59 -12
  299. package/lib/dist/ui/glyphs.js.map +1 -1
  300. package/lib/dist/ui/shimmer-progress.d.ts.map +1 -1
  301. package/lib/dist/ui/shimmer-progress.js +78 -4
  302. package/lib/dist/ui/shimmer-progress.js.map +1 -1
  303. package/lib/dist/ui/shimmer-worker.js +25 -17
  304. package/lib/dist/ui/shimmer-worker.js.map +1 -1
  305. package/lib/dist/ui/types.d.ts +0 -2
  306. package/lib/dist/ui/types.d.ts.map +1 -1
  307. package/lib/dist/upgrade/index.d.ts +7 -0
  308. package/lib/dist/upgrade/index.d.ts.map +1 -1
  309. package/lib/dist/upgrade/index.js +18 -5
  310. package/lib/dist/upgrade/index.js.map +1 -1
  311. package/lib/kernel/codegraph-kernel.node +0 -0
  312. package/lib/node_modules/.package-lock.json +1 -1
  313. package/lib/package.json +6 -1
  314. package/package.json +6 -2
@@ -5,20 +5,26 @@
5
5
  * Prepared statements for CRUD operations on the knowledge graph.
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.QueryBuilder = void 0;
8
+ exports.QueryBuilder = exports.DEPRIORITIZED_NAME_BONUS_SCALE = void 0;
9
9
  const utils_1 = require("../utils");
10
10
  const query_utils_1 = require("../search/query-utils");
11
11
  const query_parser_1 = require("../search/query-parser");
12
12
  const generated_detection_1 = require("../extraction/generated-detection");
13
13
  const identifier_segments_1 = require("../search/identifier-segments");
14
14
  /**
15
- * Path-only heuristic for files that should not be candidates for
16
- * "dominant file" detection: test/spec files and tool-generated files.
17
- * Generated files (`*.pb.go`, `*.pulsar.go`, mock outputs, …) often
18
- * have huge in-file edge counts that dwarf the real source — etcd's
19
- * `rpc.pb.go` has 4× the in-file edges of `server.go`.
15
+ * Files that should not be candidates for "dominant file" detection: test/spec
16
+ * files and tool-generated files. Generated files (`*.pb.go`, `*.pulsar.go`,
17
+ * mock outputs, …) often have huge in-file edge counts that dwarf the real
18
+ * source — etcd's `rpc.pb.go` has 4× the in-file edges of `server.go`.
19
+ *
20
+ * Path patterns plus, when the caller passes the indexed set, files whose
21
+ * HEADER declares them generated — a `payroll.go` full of generated CRUD has
22
+ * exactly the same edge-density problem as `rpc.pb.go` and nothing in its name
23
+ * to catch it (#1500).
20
24
  */
21
- function isLowValueFile(filePath) {
25
+ function isLowValueFile(filePath, generated) {
26
+ if (generated?.has(filePath))
27
+ return true;
22
28
  const lp = filePath.toLowerCase();
23
29
  return (/(?:^|\/)(tests?|__tests?__|spec)\//.test(lp) ||
24
30
  /_test\.go$/.test(lp) ||
@@ -34,6 +40,22 @@ function isLowValueFile(filePath) {
34
40
  (0, generated_detection_1.isGeneratedFile)(filePath));
35
41
  }
36
42
  const SQLITE_PARAM_CHUNK_SIZE = 500;
43
+ /**
44
+ * How much of the exact-name bonus a `deprioritize`d path keeps (#982). Damped
45
+ * rather than zeroed: a query that genuinely targets that tree must still rank
46
+ * it, the same "discount, don't erase" rule the path penalty follows.
47
+ *
48
+ * Derived rather than picked. `nameMatchBonus`'s prefix arm tops out below
49
+ * `10 + 30 = 40`, and a de-prioritized node also takes the -15 path penalty, so
50
+ * `80 * SCALE - 15 > 40` is what stops a damped WHOLE-QUERY exact match from
51
+ * losing to a mere prefix match. 0.75 clears it (45). Measured on a 62k-node
52
+ * django index: at 0.25 that invariant breaks in practice — `child`, `parent`
53
+ * and `method` lose rank 1 to `children`, `all_parents` and `method_decorator`
54
+ * — while crowd-out removal is almost flat between 0.75 and 0.5 (39 vs 40 of 88
55
+ * peripheral top-10 slots cleared), so a deeper discount buys little and costs
56
+ * the invariant. Pinned by a test.
57
+ */
58
+ exports.DEPRIORITIZED_NAME_BONUS_SCALE = 0.75;
37
59
  /**
38
60
  * Last segment of a (possibly dotted/qualified) reference name — the part a
39
61
  * new symbol's plain node name could match: 'util.greet' → 'greet',
@@ -42,8 +64,11 @@ const SQLITE_PARAM_CHUNK_SIZE = 500;
42
64
  * refs against newly-added node names.
43
65
  */
44
66
  function referenceNameTail(referenceName) {
45
- const idx = Math.max(referenceName.lastIndexOf('.'), referenceName.lastIndexOf(':'));
46
- return idx >= 0 ? referenceName.slice(idx + 1) : referenceName;
67
+ // Erlang refs carry a written arity (`f/1`, `mod::fn/2` — #1610); the tail a
68
+ // new symbol's plain name could match is the arity-less function name.
69
+ const base = referenceName.replace(/\/\d{1,3}$/, '') || referenceName;
70
+ const idx = Math.max(base.lastIndexOf('.'), base.lastIndexOf(':'));
71
+ return idx >= 0 ? base.slice(idx + 1) : base;
47
72
  }
48
73
  /**
49
74
  * Convert database row to Node object
@@ -100,6 +125,7 @@ function rowToFileRecord(row) {
100
125
  indexedAt: row.indexed_at,
101
126
  nodeCount: row.node_count,
102
127
  errors: row.errors ? (0, utils_1.safeJsonParse)(row.errors, undefined) : undefined,
128
+ generated: row.generated === 1,
103
129
  };
104
130
  }
105
131
  /**
@@ -112,6 +138,7 @@ class QueryBuilder {
112
138
  // whole project, not a symbol, so it carries no discriminative signal (#720).
113
139
  // Set once by the CodeGraph instance; empty by default (no down-weighting).
114
140
  projectNameTokens = new Set();
141
+ isDeprioritizedPath;
115
142
  // Node cache for frequently accessed nodes (LRU-style, max 1000 entries)
116
143
  nodeCache = new Map();
117
144
  maxCacheSize = 1000;
@@ -123,9 +150,67 @@ class QueryBuilder {
123
150
  // correctness backstop. Bounded so a pathological repo can't grow it forever.
124
151
  segmentedNames = new Set();
125
152
  static MAX_SEGMENTED_NAMES = 65536;
153
+ // Multi-row INSERT statements, cached per (statement kind × row count). The
154
+ // bulk write path decomposes N rows into a few fixed batch sizes so each
155
+ // size's statement is prepared once and reused — one .run() binds a whole
156
+ // chunk instead of one row, which is where the per-call overhead lives.
157
+ // Row order within and across chunks is the input order, so rowid assignment
158
+ // (and therefore resolution's insertion-order disambiguation) is identical
159
+ // to the one-row-per-run path.
160
+ batchStmts = new Map();
161
+ static BATCH_SIZES = [128, 32, 8, 1];
162
+ /**
163
+ * Run `rows` through a multi-row `INSERT` built as `head + (tuple,)*n`,
164
+ * decomposed greedily into the cached batch sizes. Preserves row order.
165
+ */
166
+ runBatched(kind, head, tuple, rows) {
167
+ if (rows.length === 0)
168
+ return;
169
+ let i = 0;
170
+ for (const size of QueryBuilder.BATCH_SIZES) {
171
+ while (rows.length - i >= size) {
172
+ const key = `${kind}:${size}`;
173
+ let stmt = this.batchStmts.get(key);
174
+ if (!stmt) {
175
+ stmt = this.db.prepare(head + new Array(size).fill(tuple).join(','));
176
+ this.batchStmts.set(key, stmt);
177
+ }
178
+ if (size === 1) {
179
+ stmt.run(...rows[i]);
180
+ }
181
+ else {
182
+ const params = [];
183
+ for (let r = 0; r < size; r++) {
184
+ const row = rows[i + r];
185
+ for (let c = 0; c < row.length; c++)
186
+ params.push(row[c]);
187
+ }
188
+ stmt.run(...params);
189
+ }
190
+ i += size;
191
+ }
192
+ }
193
+ }
126
194
  constructor(db) {
127
195
  this.db = db;
128
196
  }
197
+ /**
198
+ * Swap the underlying connection in place. Used by pool workers'
199
+ * connection recycling (plan §7a.6, writes-under-readers): a long-lived
200
+ * read connection pins WAL checkpoint progress, and the deep WAL that
201
+ * accumulates behind it taxes every main-thread B-tree page operation
202
+ * (deletes measured 42.6s → 118.8s from 0 to 4 attached readers on
203
+ * identical hardware). Workers therefore close and reopen their read-only
204
+ * connection at the pool-idle boundary; everything above the connection —
205
+ * this QueryBuilder, the resolver and its warm caches — survives, and only
206
+ * connection-derived state (prepared statements) resets, re-preparing
207
+ * lazily on next use.
208
+ */
209
+ rebind(db) {
210
+ this.db = db;
211
+ this.stmts = {};
212
+ this.batchStmts.clear();
213
+ }
129
214
  /** Set the normalized project-name tokens used to down-weight non-discriminative
130
215
  * query words in path scoring (#720). Called once when the project opens. */
131
216
  setProjectNameTokens(tokens) {
@@ -135,6 +220,19 @@ class QueryBuilder {
135
220
  getProjectNameTokens() {
136
221
  return this.projectNameTokens;
137
222
  }
223
+ /**
224
+ * Set the predicate that marks a path as de-prioritized by the project's
225
+ * `codegraph.json` `deprioritize` patterns (#982). Ranking-only: those paths
226
+ * stay indexed and findable, they just stop outranking first-party code.
227
+ * Called once when the project opens; undefined disables the lever.
228
+ */
229
+ setDeprioritizedPathMatcher(matcher) {
230
+ this.isDeprioritizedPath = matcher;
231
+ }
232
+ /** The `deprioritize` predicate (#982), so other rankers apply the same lever. */
233
+ getDeprioritizedPathMatcher() {
234
+ return this.isDeprioritizedPath;
235
+ }
138
236
  // ===========================================================================
139
237
  // Node Operations
140
238
  // ===========================================================================
@@ -220,28 +318,115 @@ class QueryBuilder {
220
318
  }
221
319
  /** Write `name`'s segments into name_segment_vocab (idempotent). */
222
320
  insertNameSegments(name) {
223
- if (this.segmentedNames.has(name))
224
- return;
225
- if (this.segmentedNames.size >= QueryBuilder.MAX_SEGMENTED_NAMES)
226
- this.segmentedNames.clear();
227
- this.segmentedNames.add(name);
228
- if (!this.stmts.insertNameSegment) {
229
- this.stmts.insertNameSegment = this.db.prepare('INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES (?, ?)');
230
- }
231
- for (const segment of (0, identifier_segments_1.splitIdentifierSegments)(name)) {
232
- this.stmts.insertNameSegment.run(segment, name);
233
- }
321
+ const rows = [];
322
+ this.collectNameSegmentRows(name, rows);
323
+ this.runBatched('insertNameSegments', 'INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES ', '(?,?)', rows);
234
324
  }
235
325
  /**
236
326
  * Insert multiple nodes in a transaction
237
327
  */
238
328
  insertNodes(nodes) {
239
329
  this.db.transaction(() => {
330
+ // Bulk path: same semantics as insertNode() per row (validation, cache
331
+ // invalidation, segment vocab), but bound as multi-row INSERTs — the
332
+ // per-.run() call overhead dominates the store phase on full indexes.
333
+ const rows = [];
334
+ const segmentRows = [];
240
335
  for (const node of nodes) {
241
- this.insertNode(node);
336
+ if (!node.id || !node.kind || !node.name || !node.filePath || !node.language) {
337
+ console.error('[CodeGraph] Skipping node with missing required fields:', {
338
+ id: node.id,
339
+ kind: node.kind,
340
+ name: node.name,
341
+ filePath: node.filePath,
342
+ language: node.language,
343
+ });
344
+ continue;
345
+ }
346
+ this.nodeCache.delete(node.id);
347
+ rows.push([
348
+ node.id,
349
+ node.kind,
350
+ node.name,
351
+ node.qualifiedName ?? node.name,
352
+ node.filePath,
353
+ node.language,
354
+ node.startLine ?? 0,
355
+ node.endLine ?? 0,
356
+ node.startColumn ?? 0,
357
+ node.endColumn ?? 0,
358
+ node.docstring ?? null,
359
+ node.signature ?? null,
360
+ node.visibility ?? null,
361
+ node.isExported ? 1 : 0,
362
+ node.isAsync ? 1 : 0,
363
+ node.isStatic ? 1 : 0,
364
+ node.isAbstract ? 1 : 0,
365
+ node.decorators ? JSON.stringify(node.decorators) : null,
366
+ node.typeParameters ? JSON.stringify(node.typeParameters) : null,
367
+ node.returnType ?? null,
368
+ node.updatedAt ?? Date.now(),
369
+ ]);
370
+ if (this.isSegmentableKind(node.kind))
371
+ this.collectNameSegmentRows(node.name, segmentRows);
372
+ }
373
+ this.runBatched('insertNodes', `INSERT OR REPLACE INTO nodes (
374
+ id, kind, name, qualified_name, file_path, language,
375
+ start_line, end_line, start_column, end_column,
376
+ docstring, signature, visibility,
377
+ is_exported, is_async, is_static, is_abstract,
378
+ decorators, type_parameters, return_type, updated_at
379
+ ) VALUES `, '(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', rows);
380
+ this.runBatched('insertNameSegments', 'INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES ', '(?,?)', segmentRows);
381
+ })();
382
+ }
383
+ /**
384
+ * Store one file's whole extraction bundle — nodes, edges, unresolved refs,
385
+ * and the file record — in a SINGLE transaction. The bulk-index path calls
386
+ * this once per file instead of opening one transaction per table (#1015
387
+ * file-order commit discipline is unchanged: callers still invoke it in file
388
+ * order, and row order within is input order).
389
+ *
390
+ * Edges MUST already be endpoint-filtered by the caller (the store path
391
+ * filters to the file's own inserted node ids), so the per-file existence
392
+ * SELECT that insertEdges() pays is skipped here.
393
+ */
394
+ storeFileBundle(bundle) {
395
+ this.db.transaction(() => {
396
+ this.insertNodes(bundle.nodes);
397
+ if (bundle.edges.length > 0) {
398
+ const rows = [];
399
+ for (const edge of bundle.edges) {
400
+ rows.push([
401
+ edge.source,
402
+ edge.target,
403
+ edge.kind,
404
+ edge.metadata ? JSON.stringify(edge.metadata) : null,
405
+ edge.line ?? null,
406
+ edge.column ?? null,
407
+ edge.provenance ?? null,
408
+ ]);
409
+ }
410
+ this.runBatched('insertEdges', 'INSERT OR IGNORE INTO edges (source, target, kind, metadata, line, col, provenance) VALUES ', '(?,?,?,?,?,?,?)', rows);
242
411
  }
412
+ if (bundle.refs.length > 0)
413
+ this.insertUnresolvedRefsBatch(bundle.refs);
414
+ this.upsertFile(bundle.file);
243
415
  })();
244
416
  }
417
+ /**
418
+ * Collect (segment, name) rows for a name, honouring the same session-dedupe
419
+ * semantics as insertNameSegments(). Shared by the bulk write paths.
420
+ */
421
+ collectNameSegmentRows(name, out) {
422
+ if (this.segmentedNames.has(name))
423
+ return;
424
+ if (this.segmentedNames.size >= QueryBuilder.MAX_SEGMENTED_NAMES)
425
+ this.segmentedNames.clear();
426
+ this.segmentedNames.add(name);
427
+ for (const segment of (0, identifier_segments_1.splitIdentifierSegments)(name))
428
+ out.push([segment, name]);
429
+ }
245
430
  /**
246
431
  * Update an existing node
247
432
  */
@@ -367,8 +552,10 @@ class QueryBuilder {
367
552
  /** Insert segments for a batch of names in one transaction (vocab heal path). */
368
553
  insertNameSegmentsBatch(names) {
369
554
  this.db.transaction(() => {
555
+ const rows = [];
370
556
  for (const name of names)
371
- this.insertNameSegments(name);
557
+ this.collectNameSegmentRows(name, rows);
558
+ this.runBatched('insertNameSegments', 'INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES ', '(?,?)', rows);
372
559
  })();
373
560
  }
374
561
  /**
@@ -579,7 +766,8 @@ class QueryBuilder {
579
766
  `);
580
767
  }
581
768
  const rows = this.stmts.getDominantFile.all();
582
- const filtered = rows.filter(r => !isLowValueFile(r.file_path));
769
+ const generated = this.getGeneratedPathsAmong(rows.map(r => r.file_path));
770
+ const filtered = rows.filter(r => !isLowValueFile(r.file_path, generated));
583
771
  if (filtered.length === 0 || filtered[0].edge_count < 20)
584
772
  return null;
585
773
  return {
@@ -612,7 +800,8 @@ class QueryBuilder {
612
800
  `);
613
801
  }
614
802
  const rows = this.stmts.getTopRouteFile.all();
615
- const filtered = rows.filter(r => !isLowValueFile(r.file_path));
803
+ const generated = this.getGeneratedPathsAmong(rows.map(r => r.file_path));
804
+ const filtered = rows.filter(r => !isLowValueFile(r.file_path, generated));
616
805
  if (filtered.length === 0)
617
806
  return null;
618
807
  const totalRoutes = filtered.reduce((sum, r) => sum + r.cnt, 0);
@@ -658,7 +847,8 @@ class QueryBuilder {
658
847
  }
659
848
  const rows = this.stmts.getRoutingManifest.all(limit);
660
849
  // Drop test/generated handlers — same hygiene as elsewhere.
661
- const filtered = rows.filter(r => !isLowValueFile(r.handler_file));
850
+ const generated = this.getGeneratedPathsAmong(rows.map(r => r.handler_file));
851
+ const filtered = rows.filter(r => !isLowValueFile(r.handler_file, generated));
662
852
  if (filtered.length < 3)
663
853
  return null;
664
854
  // Identify the file holding the most handlers (the "primary handler file").
@@ -747,11 +937,26 @@ class QueryBuilder {
747
937
  return new Set(rows.map((r) => r.language));
748
938
  }
749
939
  /**
750
- * Get nodes by exact name match (uses idx_nodes_name index)
940
+ * Get nodes by exact name match (uses idx_nodes_name index).
941
+ *
942
+ * This is resolution's candidate list, and the ORDER BY is load-bearing for
943
+ * index correctness, not cosmetic (CG-33). When a reference names a symbol
944
+ * that several files define and nothing disambiguates them, resolution binds
945
+ * to the first candidate — so without an ORDER BY the winner was decided by
946
+ * rowid, i.e. by the order files happened to be WRITTEN. A full index writes
947
+ * them in scan order; an incremental sync appends each file as it changes, so
948
+ * the same tree resolved to different edges depending on how the index was
949
+ * built, and a long-lived synced index drifted away from a rebuild of itself
950
+ * (measured at 4.3% of distinct edges, mostly `calls`).
951
+ *
952
+ * `(file_path, start_line)` is a property of the CODE, so both paths now pick
953
+ * the same candidate. The sort is paid once per distinct name per resolution
954
+ * run — ReferenceResolver memoizes this in its nameCache — and the population
955
+ * is capped by AMBIGUOUS_NAME_CEILING (#999).
751
956
  */
752
957
  getNodesByName(name) {
753
958
  if (!this.stmts.getNodesByName) {
754
- this.stmts.getNodesByName = this.db.prepare('SELECT * FROM nodes WHERE name = ?');
959
+ this.stmts.getNodesByName = this.db.prepare('SELECT * FROM nodes WHERE name = ? ORDER BY file_path, start_line');
755
960
  }
756
961
  const rows = this.stmts.getNodesByName.all(name);
757
962
  return rows.map(rowToNode);
@@ -778,13 +983,24 @@ class QueryBuilder {
778
983
  return rows.map(rowToNode);
779
984
  }
780
985
  /**
781
- * Get nodes by lowercase name match (uses idx_nodes_lower_name expression index)
986
+ * Get nodes by name, case-insensitively (seeks the idx_nodes_lower_name
987
+ * expression index).
988
+ *
989
+ * The parameter is lowered in SQL rather than trusted to arrive lowered, so
990
+ * the lookup means the same thing whatever casing a caller hands it. Written
991
+ * as a bare `lower(name) = ?` it silently returned nothing for any input
992
+ * carrying an uppercase letter, and — because SQLite's `lower()` folds ASCII
993
+ * only while JavaScript's `.toLowerCase()` folds Unicode — a caller that
994
+ * pre-lowered in JavaScript could not match a non-ASCII name at all.
995
+ *
996
+ * Note this hardens the query, not its one caller: `matchFuzzy` still lowers
997
+ * in JavaScript before calling, so the non-ASCII gap remains open there.
782
998
  */
783
- getNodesByLowerName(lowerName) {
999
+ getNodesByLowerName(name) {
784
1000
  if (!this.stmts.getNodesByLowerName) {
785
- this.stmts.getNodesByLowerName = this.db.prepare('SELECT * FROM nodes WHERE lower(name) = ?');
1001
+ this.stmts.getNodesByLowerName = this.db.prepare('SELECT * FROM nodes WHERE lower(name) = lower(?)');
786
1002
  }
787
- const rows = this.stmts.getNodesByLowerName.all(lowerName);
1003
+ const rows = this.stmts.getNodesByLowerName.all(name);
788
1004
  return rows.map(rowToNode);
789
1005
  }
790
1006
  /**
@@ -842,12 +1058,25 @@ class QueryBuilder {
842
1058
  // pushing them past the FTS fetch limit before post-hoc scoring can help.
843
1059
  // Use the max BM25 score as the base so the nameMatchBonus (exact=30 vs
844
1060
  // prefix=20) actually differentiates them after rescoring.
1061
+ //
1062
+ // Whole-name equality MUST be written as `lower(name) = lower(?)` so it
1063
+ // seeks `idx_nodes_lower_name`. The equivalent `name = ? COLLATE NOCASE`
1064
+ // matches no index — `idx_nodes_name` is BINARY-collated and the expression
1065
+ // index only matches the same expression — and degrades to a full table
1066
+ // scan. The `LIMIT 20` does not rescue it: SQLite can only stop early once
1067
+ // it has produced 20 rows, and this runs once per query term, most of which
1068
+ // name nothing in the corpus. Measured per term on an unmatched term:
1069
+ // 0.08ms on gin (2.5k nodes), 0.39ms on excalidraw (11k), 2.4ms on django
1070
+ // (62k) — and growing with the corpus, where the seek is flat at ~0.002ms.
1071
+ // Lowering the parameter in SQL rather than in JS is deliberate: SQLite's
1072
+ // `lower()` and NOCASE both fold ASCII only, while JS `.toLowerCase()`
1073
+ // folds Unicode, which would silently stop matching non-ASCII names.
845
1074
  if (results.length > 0 && query) {
846
1075
  const existingIds = new Set(results.map(r => r.node.id));
847
1076
  const maxFtsScore = Math.max(...results.map(r => r.score));
848
1077
  const terms = query.split(/\s+/).filter(t => t.length >= 2);
849
1078
  for (const term of terms) {
850
- let sql = 'SELECT * FROM nodes WHERE name = ? COLLATE NOCASE';
1079
+ let sql = 'SELECT * FROM nodes WHERE lower(name) = lower(?)';
851
1080
  const params = [term];
852
1081
  if (kinds && kinds.length > 0) {
853
1082
  sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
@@ -870,13 +1099,24 @@ class QueryBuilder {
870
1099
  // Apply multi-signal scoring
871
1100
  if (results.length > 0 && (text || query)) {
872
1101
  const scoringQuery = text || query;
873
- results = results.map(r => ({
874
- ...r,
875
- score: r.score
876
- + (0, query_utils_1.kindBonus)(r.node.kind)
877
- + (0, query_utils_1.scorePathRelevance)(r.node.filePath, scoringQuery, this.projectNameTokens)
878
- + (0, query_utils_1.nameMatchBonus)(r.node.name, scoringQuery),
879
- }));
1102
+ results = results.map(r => {
1103
+ // A path the project de-prioritized is saying its symbol NAMES are not
1104
+ // the answer, so the exact-name bonus has to be damped too. The -15 path
1105
+ // penalty alone cannot do it: the bonus is additive and larger (measured
1106
+ // on #982's repro, a `usage()` helper sat at 74.8 vs 51.2 for the top
1107
+ // product symbol — -15 lands at 59.8, still ahead). Damped, not zeroed,
1108
+ // so the tree stays findable when it genuinely is what you asked for.
1109
+ // Evaluated once and reused: the predicate stats the config file.
1110
+ const deprioritized = this.isDeprioritizedPath?.(r.node.filePath) ?? false;
1111
+ const nameBonus = (0, query_utils_1.nameMatchBonus)(r.node.name, scoringQuery);
1112
+ return {
1113
+ ...r,
1114
+ score: r.score
1115
+ + (0, query_utils_1.kindBonus)(r.node.kind)
1116
+ + (0, query_utils_1.scorePathRelevance)(r.node.filePath, scoringQuery, this.projectNameTokens, deprioritized)
1117
+ + (deprioritized ? Math.round(nameBonus * exports.DEPRIORITIZED_NAME_BONUS_SCALE) : nameBonus),
1118
+ };
1119
+ });
880
1120
  results.sort((a, b) => b.score - a.score);
881
1121
  // Trim to requested limit after rescoring
882
1122
  if (results.length > limit) {
@@ -1115,9 +1355,16 @@ class QueryBuilder {
1115
1355
  // Pass 1: Find which files contain distinctive (rare) symbols from the query.
1116
1356
  // Pass 2: Query each name, boosting results that co-locate with distinctive symbols.
1117
1357
  // Pass 1: Find files containing each queried name, identify distinctive names
1358
+ //
1359
+ // Both passes spell whole-name equality as `lower(name) = lower(?)` so they
1360
+ // seek `idx_nodes_lower_name` — see the note in `searchNodes` for why the
1361
+ // `name = ? COLLATE NOCASE` form full-scans instead. This path is the one
1362
+ // that hurts most: it runs both passes for every symbol extracted from the
1363
+ // query, and extraction is generous, so most of those names are absent from
1364
+ // the corpus and never reach either LIMIT.
1118
1365
  const nameToFiles = new Map();
1119
1366
  for (const name of names) {
1120
- let sql = 'SELECT DISTINCT file_path FROM nodes WHERE name COLLATE NOCASE = ?';
1367
+ let sql = 'SELECT DISTINCT file_path FROM nodes WHERE lower(name) = lower(?)';
1121
1368
  const params = [name];
1122
1369
  if (kinds && kinds.length > 0) {
1123
1370
  sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
@@ -1143,7 +1390,7 @@ class QueryBuilder {
1143
1390
  let sql = `
1144
1391
  SELECT nodes.*, 1.0 as score
1145
1392
  FROM nodes
1146
- WHERE name COLLATE NOCASE = ?
1393
+ WHERE lower(name) = lower(?)
1147
1394
  `;
1148
1395
  const params = [name];
1149
1396
  if (kinds && kinds.length > 0) {
@@ -1250,12 +1497,22 @@ class QueryBuilder {
1250
1497
  endpointIds.add(edge.target);
1251
1498
  }
1252
1499
  const existingNodeIds = this.getExistingNodeIds([...endpointIds]);
1500
+ const rows = [];
1253
1501
  for (const edge of edges) {
1254
1502
  if (!existingNodeIds.has(edge.source) || !existingNodeIds.has(edge.target)) {
1255
1503
  continue;
1256
1504
  }
1257
- this.insertEdge(edge);
1505
+ rows.push([
1506
+ edge.source,
1507
+ edge.target,
1508
+ edge.kind,
1509
+ edge.metadata ? JSON.stringify(edge.metadata) : null,
1510
+ edge.line ?? null,
1511
+ edge.column ?? null,
1512
+ edge.provenance ?? null,
1513
+ ]);
1258
1514
  }
1515
+ this.runBatched('insertEdges', 'INSERT OR IGNORE INTO edges (source, target, kind, metadata, line, col, provenance) VALUES ', '(?,?,?,?,?,?,?)', rows);
1259
1516
  })();
1260
1517
  }
1261
1518
  /**
@@ -1404,8 +1661,8 @@ class QueryBuilder {
1404
1661
  upsertFile(file) {
1405
1662
  if (!this.stmts.upsertFile) {
1406
1663
  this.stmts.upsertFile = this.db.prepare(`
1407
- INSERT INTO files (path, content_hash, language, size, modified_at, indexed_at, node_count, errors)
1408
- VALUES (@path, @contentHash, @language, @size, @modifiedAt, @indexedAt, @nodeCount, @errors)
1664
+ INSERT INTO files (path, content_hash, language, size, modified_at, indexed_at, node_count, errors, generated)
1665
+ VALUES (@path, @contentHash, @language, @size, @modifiedAt, @indexedAt, @nodeCount, @errors, @generated)
1409
1666
  ON CONFLICT(path) DO UPDATE SET
1410
1667
  content_hash = @contentHash,
1411
1668
  language = @language,
@@ -1413,7 +1670,8 @@ class QueryBuilder {
1413
1670
  modified_at = @modifiedAt,
1414
1671
  indexed_at = @indexedAt,
1415
1672
  node_count = @nodeCount,
1416
- errors = @errors
1673
+ errors = @errors,
1674
+ generated = @generated
1417
1675
  `);
1418
1676
  }
1419
1677
  this.stmts.upsertFile.run({
@@ -1425,8 +1683,149 @@ class QueryBuilder {
1425
1683
  indexedAt: file.indexedAt,
1426
1684
  nodeCount: file.nodeCount,
1427
1685
  errors: file.errors ? JSON.stringify(file.errors) : null,
1686
+ // The upsert always REWRITES the flag: a file that loses its banner in an
1687
+ // edit must lose the flag on the next sync, not keep a stale 1.
1688
+ generated: file.generated ? 1 : 0,
1428
1689
  });
1429
1690
  }
1691
+ /**
1692
+ * Which of `filePaths` the index flagged as tool-generated (schema v9+).
1693
+ *
1694
+ * Bounded-lookup by design: every consumer already holds a short candidate
1695
+ * list (a ranked file group, an FTS result page, a LIMIT-20 aggregate), so
1696
+ * this stays a partial-index probe over a handful of paths — no whole-repo
1697
+ * set to materialize, and no cache to invalidate, which means a ranking call
1698
+ * can never serve a verdict the last sync already replaced.
1699
+ *
1700
+ * Returns ONLY the content/index signal; callers union it with
1701
+ * {@link isGeneratedFile} so pre-v9 databases (column present, all zeros
1702
+ * until a re-index) keep the path-only behavior rather than regressing.
1703
+ */
1704
+ getGeneratedPathsAmong(filePaths) {
1705
+ const unique = [...new Set(filePaths)];
1706
+ const found = new Set();
1707
+ if (unique.length === 0)
1708
+ return found;
1709
+ for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
1710
+ const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
1711
+ const placeholders = chunk.map(() => '?').join(',');
1712
+ const rows = this.db
1713
+ .prepare(`SELECT path FROM files WHERE generated = 1 AND path IN (${placeholders})`)
1714
+ .all(...chunk);
1715
+ for (const row of rows)
1716
+ found.add(row.path);
1717
+ }
1718
+ return found;
1719
+ }
1720
+ /**
1721
+ * A reusable `(path) => boolean` over a bounded candidate list, unioning the
1722
+ * indexed flag with the path convention. This is the shape every ranking
1723
+ * comparator wants: one query up front, then O(1) per comparison.
1724
+ */
1725
+ generatedPredicateFor(filePaths) {
1726
+ const flagged = this.getGeneratedPathsAmong(filePaths);
1727
+ return (filePath) => flagged.has(filePath) || (0, generated_detection_1.isGeneratedFile)(filePath);
1728
+ }
1729
+ /**
1730
+ * Which of `filePaths` are AMBIENT DECLARATION files — they declare nothing
1731
+ * but types, and nothing in the index depends on them (CG-28). A hand-written
1732
+ * ambient `.d.ts` of global shims, a vendored typings file, module
1733
+ * augmentation: reachable only by name, structurally attached to nothing.
1734
+ *
1735
+ * Structural, not extension-based, so a hand-written `types.ts` and a `.d.ts`
1736
+ * are judged by the same rule and a `.d.ts` that does declare a class or a
1737
+ * const is (correctly) not caught. Four conditions, all required:
1738
+ *
1739
+ * 1. it declares at least one symbol — an empty or unparsed file is not a
1740
+ * declaration file, it is a file we know nothing about;
1741
+ * 2. EVERY declared symbol is a type-level kind (interface / type alias /
1742
+ * enum / namespace). The narrowness is deliberate and measured: a rule
1743
+ * of "no callables" alone flags 1–18% of a repo, including Kotlin sealed
1744
+ * classes, Rust `mod.rs` re-exports and django's locale constant tables —
1745
+ * real source that must not be demoted. This rule flags 0–4%;
1746
+ * 3. no symbol in it originates a `calls`/`instantiates` edge — the direct
1747
+ * evidence that nothing here has a body;
1748
+ * 4. NOTHING ELSE IN THE INDEX points at it. This is the condition that
1749
+ * separates an ambient shim from a working type module, and it is why
1750
+ * the flag is narrow enough to be safe: `displacement-ts`'s pipeline
1751
+ * `types.ts` passes 1–3 identically but carries 13 inbound imports and
1752
+ * 21 references, so the files that answer a query about the pipeline are
1753
+ * typed BY it — it is part of that answer's structure. An ambient
1754
+ * `declare global` shim has zero. Deliberately index-wide rather than
1755
+ * restricted to the candidate list: the file that imports it is usually
1756
+ * not itself a candidate.
1757
+ *
1758
+ * Bounded-lookup like {@link getGeneratedPathsAmong}: callers hold a ranked
1759
+ * candidate list, so this is a partial-index probe over a handful of paths.
1760
+ */
1761
+ getAmbientDeclarationPathsAmong(filePaths) {
1762
+ const unique = [...new Set(filePaths)];
1763
+ const found = new Set();
1764
+ if (unique.length === 0)
1765
+ return found;
1766
+ for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
1767
+ const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
1768
+ const placeholders = chunk.map(() => '?').join(',');
1769
+ // `file`/`import`/`export`/`parameter` are structural bookkeeping, not
1770
+ // things the file declares, so they neither qualify nor disqualify.
1771
+ const rows = this.db
1772
+ .prepare(`
1773
+ SELECT file_path,
1774
+ SUM(CASE WHEN kind NOT IN ('file','import','export','parameter')
1775
+ THEN 1 ELSE 0 END) AS declared,
1776
+ SUM(CASE WHEN kind IN ('interface','type_alias','enum','enum_member','namespace')
1777
+ THEN 1 ELSE 0 END) AS typeDeclared
1778
+ FROM nodes
1779
+ WHERE file_path IN (${placeholders})
1780
+ GROUP BY file_path
1781
+ `)
1782
+ .all(...chunk);
1783
+ let candidates = rows
1784
+ .filter((r) => r.declared > 0 && r.declared === r.typeDeclared)
1785
+ .map((r) => r.file_path);
1786
+ if (candidates.length === 0)
1787
+ continue;
1788
+ const disqualify = (sql) => {
1789
+ if (candidates.length === 0)
1790
+ return;
1791
+ const hit = new Set(this.db
1792
+ .prepare(sql.replace('$IN$', candidates.map(() => '?').join(',')))
1793
+ .all(...candidates).map((r) => r.file_path));
1794
+ candidates = candidates.filter((p) => !hit.has(p));
1795
+ };
1796
+ // (3) originates behaviour
1797
+ disqualify(`
1798
+ SELECT DISTINCT n.file_path AS file_path
1799
+ FROM edges e JOIN nodes n ON n.id = e.source
1800
+ WHERE e.kind IN ('calls','instantiates') AND n.file_path IN ($IN$)
1801
+ `);
1802
+ // (4) something outside the file depends on it
1803
+ disqualify(`
1804
+ SELECT DISTINCT t.file_path AS file_path
1805
+ FROM edges e JOIN nodes t ON t.id = e.target JOIN nodes s ON s.id = e.source
1806
+ WHERE t.file_path IN ($IN$) AND s.file_path <> t.file_path
1807
+ `);
1808
+ for (const path of candidates)
1809
+ found.add(path);
1810
+ }
1811
+ return found;
1812
+ }
1813
+ /**
1814
+ * A reusable `(path) => boolean` ambient-declaration test over a bounded
1815
+ * candidate list — the shape a ranking comparator wants: one query up front,
1816
+ * O(1) per comparison.
1817
+ */
1818
+ ambientDeclarationPredicateFor(filePaths) {
1819
+ const flagged = this.getAmbientDeclarationPathsAmong(filePaths);
1820
+ return (filePath) => flagged.has(filePath);
1821
+ }
1822
+ /** How many indexed files carry the generated flag. Surfaced by `status`. */
1823
+ countGeneratedFiles() {
1824
+ const row = this.db
1825
+ .prepare('SELECT COUNT(*) AS n FROM files WHERE generated = 1')
1826
+ .get();
1827
+ return row?.n ?? 0;
1828
+ }
1430
1829
  /**
1431
1830
  * Delete a file record and its nodes
1432
1831
  */
@@ -1510,9 +1909,20 @@ class QueryBuilder {
1510
1909
  if (refs.length === 0)
1511
1910
  return;
1512
1911
  const insert = this.db.transaction(() => {
1912
+ const rows = [];
1513
1913
  for (const ref of refs) {
1514
- this.insertUnresolvedRef(ref);
1914
+ rows.push([
1915
+ ref.fromNodeId,
1916
+ ref.referenceName,
1917
+ ref.referenceKind,
1918
+ ref.line,
1919
+ ref.column,
1920
+ ref.candidates ? JSON.stringify(ref.candidates) : null,
1921
+ ref.filePath ?? '',
1922
+ ref.language ?? 'unknown',
1923
+ ]);
1515
1924
  }
1925
+ this.runBatched('insertUnresolvedRefs', 'INSERT INTO unresolved_refs (from_node_id, reference_name, reference_kind, line, col, candidates, file_path, language) VALUES ', '(?,?,?,?,?,?,?,?)', rows);
1516
1926
  });
1517
1927
  insert();
1518
1928
  }
@@ -1542,6 +1952,7 @@ class QueryBuilder {
1542
1952
  candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
1543
1953
  filePath: row.file_path,
1544
1954
  language: row.language,
1955
+ rowId: row.id,
1545
1956
  }));
1546
1957
  }
1547
1958
  /**
@@ -1558,6 +1969,7 @@ class QueryBuilder {
1558
1969
  candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
1559
1970
  filePath: row.file_path,
1560
1971
  language: row.language,
1972
+ rowId: row.id,
1561
1973
  }));
1562
1974
  }
1563
1975
  /**
@@ -1582,7 +1994,12 @@ class QueryBuilder {
1582
1994
  */
1583
1995
  getUnresolvedReferencesBatch(offset, limit) {
1584
1996
  if (!this.stmts.getUnresolvedBatch) {
1585
- this.stmts.getUnresolvedBatch = this.db.prepare("SELECT * FROM unresolved_refs WHERE status = 'pending' LIMIT ? OFFSET ?");
1997
+ // ORDER BY rowid is load-bearing for the pipelined resolution loop: it
1998
+ // prefetches batch k+1 at OFFSET batch_k.length while batch k's rows are
1999
+ // still pending, which is only exact under a stable enumeration. (A plain
2000
+ // scan and the status index both return rowid order anyway — this pins
2001
+ // it.)
2002
+ this.stmts.getUnresolvedBatch = this.db.prepare("SELECT * FROM unresolved_refs WHERE status = 'pending' ORDER BY rowid LIMIT ? OFFSET ?");
1586
2003
  }
1587
2004
  const rows = this.stmts.getUnresolvedBatch.all(limit, offset);
1588
2005
  return rows.map((row) => ({
@@ -1594,6 +2011,32 @@ class QueryBuilder {
1594
2011
  candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
1595
2012
  filePath: row.file_path,
1596
2013
  language: row.language,
2014
+ rowId: row.id,
2015
+ }));
2016
+ }
2017
+ /**
2018
+ * Keyset variant of {@link getUnresolvedReferencesBatch} for the batched
2019
+ * resolution loop: seek past the last-seen row id instead of OFFSET-walking.
2020
+ * OFFSET reads re-scan the accumulated failed-row prefix on every batch —
2021
+ * O(failed rows) per read, measured at 54.6s of the kernel-scale batch loop
2022
+ * (§7a.2) — while the seek is O(batch) forever. `id` is the rowid alias, so
2023
+ * the enumeration order is identical to the OFFSET reader's.
2024
+ */
2025
+ getUnresolvedReferencesBatchAfter(afterRowId, limit) {
2026
+ if (!this.stmts.getUnresolvedBatchAfter) {
2027
+ this.stmts.getUnresolvedBatchAfter = this.db.prepare("SELECT * FROM unresolved_refs WHERE status = 'pending' AND id > ? ORDER BY id LIMIT ?");
2028
+ }
2029
+ const rows = this.stmts.getUnresolvedBatchAfter.all(afterRowId, limit);
2030
+ return rows.map((row) => ({
2031
+ fromNodeId: row.from_node_id,
2032
+ referenceName: row.reference_name,
2033
+ referenceKind: row.reference_kind,
2034
+ line: row.line,
2035
+ column: row.col,
2036
+ candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
2037
+ filePath: row.file_path,
2038
+ language: row.language,
2039
+ rowId: row.id,
1597
2040
  }));
1598
2041
  }
1599
2042
  /**
@@ -1646,7 +2089,13 @@ class QueryBuilder {
1646
2089
  const chunkRows = this.db
1647
2090
  .prepare(`SELECT * FROM unresolved_refs WHERE status = 'pending' AND file_path IN (${placeholders})`)
1648
2091
  .all(...chunk);
1649
- rows.push(...chunkRows);
2092
+ // Append with a loop, never a spread: the INPUT chunk is bounded, but
2093
+ // the RESULT rows per chunk are not — a dense recovery sync (e.g. the
2094
+ // #1541 self-heal re-indexing hundreds of files) returns more rows than
2095
+ // V8 allows as arguments, and `push(...chunkRows)` dies with "Maximum
2096
+ // call stack size exceeded", aborting resolution mid-sync (#1558).
2097
+ for (const row of chunkRows)
2098
+ rows.push(row);
1650
2099
  }
1651
2100
  return rows.map((row) => ({
1652
2101
  fromNodeId: row.from_node_id,
@@ -1657,6 +2106,7 @@ class QueryBuilder {
1657
2106
  candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
1658
2107
  filePath: row.file_path,
1659
2108
  language: row.language,
2109
+ rowId: row.id,
1660
2110
  }));
1661
2111
  }
1662
2112
  /**
@@ -1688,14 +2138,55 @@ class QueryBuilder {
1688
2138
  */
1689
2139
  deleteSpecificResolvedReferences(refs) {
1690
2140
  if (refs.length === 0)
1691
- return;
2141
+ return 0;
1692
2142
  const stmt = this.db.prepare('DELETE FROM unresolved_refs WHERE from_node_id = ? AND reference_name = ? AND reference_kind = ?');
2143
+ // Returns rows actually removed (SQLite `changes`, summed): the batched
2144
+ // resolution loop's non-progress guard keys on this — zero removals from
2145
+ // a batch that claimed work is the direct runaway signal (§7a.2).
2146
+ let changed = 0;
1693
2147
  const deleteMany = this.db.transaction((items) => {
1694
2148
  for (const ref of items) {
1695
- stmt.run(ref.fromNodeId, ref.referenceName, ref.referenceKind);
2149
+ changed += stmt.run(ref.fromNodeId, ref.referenceName, ref.referenceKind).changes;
1696
2150
  }
1697
2151
  });
1698
2152
  deleteMany(refs);
2153
+ return changed;
2154
+ }
2155
+ /**
2156
+ * Delete unresolved-ref rows by row id — the precise cleanup for refs a
2157
+ * resolution pass actually processed. The key-tuple variant above also
2158
+ * deletes SIBLING rows (same caller calling the same callee at other lines)
2159
+ * that a later batch hasn't attempted yet, so when a batch boundary split a
2160
+ * caller's same-named call sites, the later sites' edges were silently never
2161
+ * created (#1269).
2162
+ */
2163
+ deleteReferencesByRowIds(rowIds) {
2164
+ if (rowIds.length === 0)
2165
+ return 0;
2166
+ // One transaction for all chunks (each chunk was previously its own
2167
+ // implicit transaction = its own WAL commit — measurable on 100k+-ref
2168
+ // resolution persists), and the full-size chunk statement is cached so
2169
+ // repeat calls skip the re-prepare; only the final partial chunk (if any)
2170
+ // prepares ad hoc. Returns rows actually removed (summed `changes`) for
2171
+ // the batched loop's non-progress guard (§7a.2).
2172
+ let changed = 0;
2173
+ this.db.transaction(() => {
2174
+ for (let i = 0; i < rowIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
2175
+ const chunk = rowIds.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
2176
+ if (chunk.length === SQLITE_PARAM_CHUNK_SIZE) {
2177
+ if (!this.stmts.deleteRefsByRowIdsFull) {
2178
+ const placeholders = new Array(SQLITE_PARAM_CHUNK_SIZE).fill('?').join(',');
2179
+ this.stmts.deleteRefsByRowIdsFull = this.db.prepare(`DELETE FROM unresolved_refs WHERE id IN (${placeholders})`);
2180
+ }
2181
+ changed += this.stmts.deleteRefsByRowIdsFull.run(...chunk).changes;
2182
+ }
2183
+ else {
2184
+ const placeholders = chunk.map(() => '?').join(',');
2185
+ changed += this.db.prepare(`DELETE FROM unresolved_refs WHERE id IN (${placeholders})`).run(...chunk).changes;
2186
+ }
2187
+ }
2188
+ })();
2189
+ return changed;
1699
2190
  }
1700
2191
  /**
1701
2192
  * Mark refs a completed resolution pass could not resolve as status='failed'
@@ -1708,14 +2199,37 @@ class QueryBuilder {
1708
2199
  */
1709
2200
  markReferencesFailed(refs) {
1710
2201
  if (refs.length === 0)
1711
- return;
2202
+ return 0;
1712
2203
  const stmt = this.db.prepare("UPDATE unresolved_refs SET status = 'failed', name_tail = ? WHERE from_node_id = ? AND reference_name = ? AND reference_kind = ?");
2204
+ let changed = 0;
1713
2205
  const markMany = this.db.transaction((items) => {
1714
2206
  for (const ref of items) {
1715
- stmt.run(referenceNameTail(ref.referenceName), ref.fromNodeId, ref.referenceName, ref.referenceKind);
2207
+ changed += stmt.run(referenceNameTail(ref.referenceName), ref.fromNodeId, ref.referenceName, ref.referenceKind).changes;
1716
2208
  }
1717
2209
  });
1718
2210
  markMany(refs);
2211
+ return changed;
2212
+ }
2213
+ /**
2214
+ * Park refs as status='failed' by row id — the precise counterpart of
2215
+ * markReferencesFailed, for the same reason as deleteReferencesByRowIds:
2216
+ * the key-tuple variant also flips same-key sibling rows in later batches
2217
+ * to 'failed' before they were ever attempted (#1269). Resolution outcome
2218
+ * can differ per call site (receiver-type inference reads the ref's line),
2219
+ * so a sibling must not inherit this row's failure.
2220
+ */
2221
+ markReferencesFailedByRowIds(refs) {
2222
+ if (refs.length === 0)
2223
+ return 0;
2224
+ const stmt = this.db.prepare("UPDATE unresolved_refs SET status = 'failed', name_tail = ? WHERE id = ?");
2225
+ let changed = 0;
2226
+ const markMany = this.db.transaction((items) => {
2227
+ for (const ref of items) {
2228
+ changed += stmt.run(referenceNameTail(ref.referenceName), ref.rowId).changes;
2229
+ }
2230
+ });
2231
+ markMany(refs);
2232
+ return changed;
1719
2233
  }
1720
2234
  /**
1721
2235
  * Failed refs whose name tail matches one of the given symbol names — the
@@ -1752,7 +2266,11 @@ class QueryBuilder {
1752
2266
  const chunkRows = this.db
1753
2267
  .prepare(`SELECT * FROM unresolved_refs WHERE status = 'failed' AND name_tail IN (${placeholders})`)
1754
2268
  .all(...chunk);
1755
- rows.push(...chunkRows);
2269
+ // Loop, not spread — same V8 argument-limit hazard as
2270
+ // getUnresolvedReferencesByFiles (#1558): a large definition delta can
2271
+ // select an unbounded number of failed rows per chunk.
2272
+ for (const row of chunkRows)
2273
+ rows.push(row);
1756
2274
  }
1757
2275
  return rows.map((row) => ({
1758
2276
  fromNodeId: row.from_node_id,
@@ -1763,8 +2281,95 @@ class QueryBuilder {
1763
2281
  candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
1764
2282
  filePath: row.file_path,
1765
2283
  language: row.language,
2284
+ rowId: row.id,
1766
2285
  }));
1767
2286
  }
2287
+ /**
2288
+ * Resolution edges whose TARGET symbol is named one of `names` — the edges a
2289
+ * sync must re-resolve after `names` gained or lost a definition (CG-33).
2290
+ *
2291
+ * Resolution binds a reference to a node whose name matches the reference's
2292
+ * tail, and it picks among ALL same-named definitions project-wide. So adding
2293
+ * or removing one definition of `pct` changes the answer for every `pct(...)`
2294
+ * reference in the repo — including references in files this sync never
2295
+ * touches, whose edges nothing else revisits. Those edges' current target is,
2296
+ * by that same rule, a node named `pct`, which is why the target's name is a
2297
+ * sufficient (and index-backed, via idx_nodes_name) way to find them without
2298
+ * a schema change or a scan of edge metadata.
2299
+ *
2300
+ * Returns the source file/language alongside each edge so the caller can
2301
+ * resurrect it as its original reference. Excludes `provenance='heuristic'`
2302
+ * (synthesized dispatch edges are not resolution output and carry no refName
2303
+ * stamp to resurrect from — deleting one would be a permanent loss).
2304
+ *
2305
+ * Names matching more than `perNameCeiling` edges are skipped entirely, same
2306
+ * rationale and same default as {@link getRetryableFailedReferences}: at that
2307
+ * population the name is generic (`get`, `clear`, …), one definition changing
2308
+ * won't flip most of them, and rebinding an arbitrary subset is both wasted
2309
+ * work and incoherent coverage.
2310
+ */
2311
+ getResolutionEdgesByTargetName(names, perNameCeiling = 500) {
2312
+ if (names.length === 0)
2313
+ return [];
2314
+ // Pass 1: per-name edge counts, chunked under the SQLite parameter limit.
2315
+ const keep = [];
2316
+ for (let i = 0; i < names.length; i += SQLITE_PARAM_CHUNK_SIZE) {
2317
+ const chunk = names.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
2318
+ const placeholders = chunk.map(() => '?').join(',');
2319
+ const counts = this.db
2320
+ .prepare(`SELECT tgt.name AS name, COUNT(*) AS count
2321
+ FROM edges e
2322
+ JOIN nodes tgt ON tgt.id = e.target
2323
+ WHERE tgt.name IN (${placeholders})
2324
+ AND (e.provenance IS NULL OR e.provenance != 'heuristic')
2325
+ GROUP BY tgt.name`)
2326
+ .all(...chunk);
2327
+ for (const row of counts) {
2328
+ if (row.count <= perNameCeiling)
2329
+ keep.push(row.name);
2330
+ }
2331
+ }
2332
+ if (keep.length === 0)
2333
+ return [];
2334
+ // Pass 2: load the surviving edges with the source file context a
2335
+ // resurrection needs.
2336
+ const out = [];
2337
+ for (let i = 0; i < keep.length; i += SQLITE_PARAM_CHUNK_SIZE) {
2338
+ const chunk = keep.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
2339
+ const placeholders = chunk.map(() => '?').join(',');
2340
+ const rows = this.db
2341
+ .prepare(`SELECT e.*, src.file_path AS source_file_path, src.language AS source_language
2342
+ FROM edges e
2343
+ JOIN nodes tgt ON tgt.id = e.target
2344
+ JOIN nodes src ON src.id = e.source
2345
+ WHERE tgt.name IN (${placeholders})
2346
+ AND (e.provenance IS NULL OR e.provenance != 'heuristic')`)
2347
+ .all(...chunk);
2348
+ for (const row of rows) {
2349
+ out.push({
2350
+ ...rowToEdge(row),
2351
+ edgeId: row.id,
2352
+ sourceFilePath: row.source_file_path,
2353
+ sourceLanguage: row.source_language,
2354
+ });
2355
+ }
2356
+ }
2357
+ return out;
2358
+ }
2359
+ /** Delete edges by primary key — the rebind pass's half of a re-resolution. */
2360
+ deleteEdgesByIds(edgeIds) {
2361
+ if (edgeIds.length === 0)
2362
+ return 0;
2363
+ let changed = 0;
2364
+ this.db.transaction(() => {
2365
+ for (let i = 0; i < edgeIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
2366
+ const chunk = edgeIds.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
2367
+ const placeholders = chunk.map(() => '?').join(',');
2368
+ changed += this.db.prepare(`DELETE FROM edges WHERE id IN (${placeholders})`).run(...chunk).changes;
2369
+ }
2370
+ })();
2371
+ return changed;
2372
+ }
1768
2373
  /**
1769
2374
  * Distinct node names present in the given files — the symbol names a sync
1770
2375
  * pass uses to look up retryable failed refs after those files changed.
@@ -1784,6 +2389,34 @@ class QueryBuilder {
1784
2389
  }
1785
2390
  return [...names];
1786
2391
  }
2392
+ /**
2393
+ * Distinct `file\0name` pairs defined by the given files — the shape sync's
2394
+ * definition delta needs (CG-33).
2395
+ *
2396
+ * Deliberately NOT `getNodeNamesByFiles`: a bare name set is taken over the
2397
+ * WHOLE changed batch, so a name that moves between two files in one commit
2398
+ * (or exists in one changed file and is newly added to another) appears on
2399
+ * both sides and cancels out of the symmetric difference — even though a
2400
+ * definition genuinely appeared or vanished and every reference to that name
2401
+ * repo-wide may now bind elsewhere. Keying by file makes each definition its
2402
+ * own fact, so the move is seen as one removal plus one addition.
2403
+ */
2404
+ getNodeNamePairsByFiles(filePaths) {
2405
+ const pairs = new Set();
2406
+ if (filePaths.length === 0)
2407
+ return pairs;
2408
+ for (let i = 0; i < filePaths.length; i += SQLITE_PARAM_CHUNK_SIZE) {
2409
+ const chunk = filePaths.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
2410
+ const placeholders = chunk.map(() => '?').join(',');
2411
+ const rows = this.db
2412
+ .prepare(`SELECT DISTINCT file_path, name FROM nodes WHERE file_path IN (${placeholders})`)
2413
+ .all(...chunk);
2414
+ // NUL-joined: a path or a symbol name can contain a space, never a NUL.
2415
+ for (const row of rows)
2416
+ pairs.add(`${row.file_path}\0${row.name}`);
2417
+ }
2418
+ return pairs;
2419
+ }
1787
2420
  // ===========================================================================
1788
2421
  // Statistics
1789
2422
  // ===========================================================================
@@ -1839,6 +2472,7 @@ class QueryBuilder {
1839
2472
  edgesByKind,
1840
2473
  filesByLanguage,
1841
2474
  dbSizeBytes: 0, // Set by caller using DatabaseConnection.getSize()
2475
+ walSizeBytes: 0, // Set by caller using DatabaseConnection.getWalSizeBytes()
1842
2476
  lastUpdated: Date.now(),
1843
2477
  };
1844
2478
  }