@colbymchenry/codegraph-win32-arm64 1.6.1 → 1.6.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 (1094) hide show
  1. package/bin/codegraph +1 -1
  2. package/bin/codegraph.cmd +1 -1
  3. package/lib/dist/.test-build-engine.json +1 -1
  4. package/lib/dist/.test-build-viewer.json +1 -1
  5. package/lib/dist/bin/codegraph.d.ts +3 -0
  6. package/lib/dist/bin/codegraph.d.ts.map +1 -1
  7. package/lib/dist/bin/codegraph.js +427 -684
  8. package/lib/dist/bin/codegraph.js.map +1 -1
  9. package/lib/dist/bin/command-supervision.d.ts +7 -0
  10. package/lib/dist/bin/command-supervision.d.ts.map +1 -1
  11. package/lib/dist/bin/command-supervision.js +30 -74
  12. package/lib/dist/bin/command-supervision.js.map +1 -1
  13. package/lib/dist/bin/fatal-handler.js +0 -46
  14. package/lib/dist/bin/fatal-handler.js.map +1 -1
  15. package/lib/dist/bin/node-version-check.js +0 -33
  16. package/lib/dist/bin/node-version-check.js.map +1 -1
  17. package/lib/dist/bin/uninstall.js +0 -19
  18. package/lib/dist/bin/uninstall.js.map +1 -1
  19. package/lib/dist/bin/viewer-gate.js +0 -14
  20. package/lib/dist/bin/viewer-gate.js.map +1 -1
  21. package/lib/dist/compile-cache.d.ts +2 -0
  22. package/lib/dist/compile-cache.d.ts.map +1 -0
  23. package/lib/dist/compile-cache.js +45 -0
  24. package/lib/dist/compile-cache.js.map +1 -0
  25. package/lib/dist/context/formatter.js +3 -66
  26. package/lib/dist/context/formatter.js.map +1 -1
  27. package/lib/dist/context/index.d.ts +44 -1
  28. package/lib/dist/context/index.d.ts.map +1 -1
  29. package/lib/dist/context/index.js +123 -430
  30. package/lib/dist/context/index.js.map +1 -1
  31. package/lib/dist/context/markers.js +0 -17
  32. package/lib/dist/context/markers.js.map +1 -1
  33. package/lib/dist/db/index.d.ts +44 -1
  34. package/lib/dist/db/index.d.ts.map +1 -1
  35. package/lib/dist/db/index.js +123 -395
  36. package/lib/dist/db/index.js.map +1 -1
  37. package/lib/dist/db/migrations.d.ts +11 -1
  38. package/lib/dist/db/migrations.d.ts.map +1 -1
  39. package/lib/dist/db/migrations.js +71 -79
  40. package/lib/dist/db/migrations.js.map +1 -1
  41. package/lib/dist/db/name-substring-index.d.ts +63 -0
  42. package/lib/dist/db/name-substring-index.d.ts.map +1 -0
  43. package/lib/dist/db/name-substring-index.js +151 -0
  44. package/lib/dist/db/name-substring-index.js.map +1 -0
  45. package/lib/dist/db/node-sqlite.d.ts +19 -0
  46. package/lib/dist/db/node-sqlite.d.ts.map +1 -0
  47. package/lib/dist/db/node-sqlite.js +23 -0
  48. package/lib/dist/db/node-sqlite.js.map +1 -0
  49. package/lib/dist/db/open-error.d.ts +36 -0
  50. package/lib/dist/db/open-error.d.ts.map +1 -0
  51. package/lib/dist/db/open-error.js +63 -0
  52. package/lib/dist/db/open-error.js.map +1 -0
  53. package/lib/dist/db/parameter-flow-queries.d.ts +120 -0
  54. package/lib/dist/db/parameter-flow-queries.d.ts.map +1 -0
  55. package/lib/dist/db/parameter-flow-queries.js +168 -0
  56. package/lib/dist/db/parameter-flow-queries.js.map +1 -0
  57. package/lib/dist/db/queries.d.ts +641 -40
  58. package/lib/dist/db/queries.d.ts.map +1 -1
  59. package/lib/dist/db/queries.js +1370 -1398
  60. package/lib/dist/db/queries.js.map +1 -1
  61. package/lib/dist/db/reference-tail.d.ts +83 -0
  62. package/lib/dist/db/reference-tail.d.ts.map +1 -0
  63. package/lib/dist/db/reference-tail.js +68 -0
  64. package/lib/dist/db/reference-tail.js.map +1 -0
  65. package/lib/dist/db/schema.sql +18 -2
  66. package/lib/dist/db/sqlite-adapter.d.ts +18 -1
  67. package/lib/dist/db/sqlite-adapter.d.ts.map +1 -1
  68. package/lib/dist/db/sqlite-adapter.js +12 -62
  69. package/lib/dist/db/sqlite-adapter.js.map +1 -1
  70. package/lib/dist/db/synthesis-stage.d.ts.map +1 -1
  71. package/lib/dist/db/synthesis-stage.js +2 -6
  72. package/lib/dist/db/synthesis-stage.js.map +1 -1
  73. package/lib/dist/db/wal-valve.js +1 -153
  74. package/lib/dist/db/wal-valve.js.map +1 -1
  75. package/lib/dist/db/wsl-shared-index.js +0 -37
  76. package/lib/dist/db/wsl-shared-index.js.map +1 -1
  77. package/lib/dist/directory.d.ts +81 -0
  78. package/lib/dist/directory.d.ts.map +1 -1
  79. package/lib/dist/directory.js +91 -500
  80. package/lib/dist/directory.js.map +1 -1
  81. package/lib/dist/engine.d.ts +15 -0
  82. package/lib/dist/engine.d.ts.map +1 -0
  83. package/lib/dist/engine.js +34 -0
  84. package/lib/dist/engine.js.map +1 -0
  85. package/lib/dist/errors.d.ts +10 -0
  86. package/lib/dist/errors.d.ts.map +1 -1
  87. package/lib/dist/errors.js +8 -101
  88. package/lib/dist/errors.js.map +1 -1
  89. package/lib/dist/extraction/astro-extractor.d.ts.map +1 -1
  90. package/lib/dist/extraction/astro-extractor.js +15 -133
  91. package/lib/dist/extraction/astro-extractor.js.map +1 -1
  92. package/lib/dist/extraction/cfml-extractor.d.ts +102 -10
  93. package/lib/dist/extraction/cfml-extractor.d.ts.map +1 -1
  94. package/lib/dist/extraction/cfml-extractor.js +260 -179
  95. package/lib/dist/extraction/cfml-extractor.js.map +1 -1
  96. package/lib/dist/extraction/commonjs-requires.d.ts +23 -0
  97. package/lib/dist/extraction/commonjs-requires.d.ts.map +1 -0
  98. package/lib/dist/extraction/commonjs-requires.js +37 -0
  99. package/lib/dist/extraction/commonjs-requires.js.map +1 -0
  100. package/lib/dist/extraction/dfm-extractor.js +0 -21
  101. package/lib/dist/extraction/dfm-extractor.js.map +1 -1
  102. package/lib/dist/extraction/extraction-version.d.ts +1 -1
  103. package/lib/dist/extraction/extraction-version.js +1 -24
  104. package/lib/dist/extraction/extraction-version.js.map +1 -1
  105. package/lib/dist/extraction/function-ref.d.ts +40 -0
  106. package/lib/dist/extraction/function-ref.d.ts.map +1 -1
  107. package/lib/dist/extraction/function-ref.js +145 -206
  108. package/lib/dist/extraction/function-ref.js.map +1 -1
  109. package/lib/dist/extraction/generated-detection.d.ts +9 -0
  110. package/lib/dist/extraction/generated-detection.d.ts.map +1 -1
  111. package/lib/dist/extraction/generated-detection.js +29 -154
  112. package/lib/dist/extraction/generated-detection.js.map +1 -1
  113. package/lib/dist/extraction/grammars.d.ts +47 -4
  114. package/lib/dist/extraction/grammars.d.ts.map +1 -1
  115. package/lib/dist/extraction/grammars.js +91 -374
  116. package/lib/dist/extraction/grammars.js.map +1 -1
  117. package/lib/dist/extraction/index.d.ts +216 -11
  118. package/lib/dist/extraction/index.d.ts.map +1 -1
  119. package/lib/dist/extraction/index.js +703 -1368
  120. package/lib/dist/extraction/index.js.map +1 -1
  121. package/lib/dist/extraction/kernel/decode.js +0 -16
  122. package/lib/dist/extraction/kernel/decode.js.map +1 -1
  123. package/lib/dist/extraction/kernel/index.d.ts +3 -1
  124. package/lib/dist/extraction/kernel/index.d.ts.map +1 -1
  125. package/lib/dist/extraction/kernel/index.js +29 -131
  126. package/lib/dist/extraction/kernel/index.js.map +1 -1
  127. package/lib/dist/extraction/kernel/layout.js +42 -76
  128. package/lib/dist/extraction/kernel/layout.js.map +1 -1
  129. package/lib/dist/extraction/kernel/loader.js +0 -37
  130. package/lib/dist/extraction/kernel/loader.js.map +1 -1
  131. package/lib/dist/extraction/languages/arkts.js +0 -59
  132. package/lib/dist/extraction/languages/arkts.js.map +1 -1
  133. package/lib/dist/extraction/languages/c-cpp.d.ts +140 -28
  134. package/lib/dist/extraction/languages/c-cpp.d.ts.map +1 -1
  135. package/lib/dist/extraction/languages/c-cpp.js +876 -823
  136. package/lib/dist/extraction/languages/c-cpp.js.map +1 -1
  137. package/lib/dist/extraction/languages/cfquery.js +0 -9
  138. package/lib/dist/extraction/languages/cfquery.js.map +1 -1
  139. package/lib/dist/extraction/languages/cfscript.d.ts +20 -0
  140. package/lib/dist/extraction/languages/cfscript.d.ts.map +1 -1
  141. package/lib/dist/extraction/languages/cfscript.js +80 -9
  142. package/lib/dist/extraction/languages/cfscript.js.map +1 -1
  143. package/lib/dist/extraction/languages/cobol.js +0 -114
  144. package/lib/dist/extraction/languages/cobol.js.map +1 -1
  145. package/lib/dist/extraction/languages/cpp-brace-scopes.d.ts +66 -0
  146. package/lib/dist/extraction/languages/cpp-brace-scopes.d.ts.map +1 -0
  147. package/lib/dist/extraction/languages/cpp-brace-scopes.js +343 -0
  148. package/lib/dist/extraction/languages/cpp-brace-scopes.js.map +1 -0
  149. package/lib/dist/extraction/languages/cpp-macro-methods.d.ts +41 -0
  150. package/lib/dist/extraction/languages/cpp-macro-methods.d.ts.map +1 -0
  151. package/lib/dist/extraction/languages/cpp-macro-methods.js +487 -0
  152. package/lib/dist/extraction/languages/cpp-macro-methods.js.map +1 -0
  153. package/lib/dist/extraction/languages/csharp.d.ts.map +1 -1
  154. package/lib/dist/extraction/languages/csharp.js +11 -54
  155. package/lib/dist/extraction/languages/csharp.js.map +1 -1
  156. package/lib/dist/extraction/languages/dart.d.ts +84 -0
  157. package/lib/dist/extraction/languages/dart.d.ts.map +1 -1
  158. package/lib/dist/extraction/languages/dart.js +335 -159
  159. package/lib/dist/extraction/languages/dart.js.map +1 -1
  160. package/lib/dist/extraction/languages/erlang.d.ts.map +1 -1
  161. package/lib/dist/extraction/languages/erlang.js +15 -102
  162. package/lib/dist/extraction/languages/erlang.js.map +1 -1
  163. package/lib/dist/extraction/languages/go.d.ts +48 -0
  164. package/lib/dist/extraction/languages/go.d.ts.map +1 -1
  165. package/lib/dist/extraction/languages/go.js +102 -31
  166. package/lib/dist/extraction/languages/go.js.map +1 -1
  167. package/lib/dist/extraction/languages/index.js +0 -6
  168. package/lib/dist/extraction/languages/index.js.map +1 -1
  169. package/lib/dist/extraction/languages/java.d.ts.map +1 -1
  170. package/lib/dist/extraction/languages/java.js +67 -78
  171. package/lib/dist/extraction/languages/java.js.map +1 -1
  172. package/lib/dist/extraction/languages/javascript.d.ts.map +1 -1
  173. package/lib/dist/extraction/languages/javascript.js +2 -12
  174. package/lib/dist/extraction/languages/javascript.js.map +1 -1
  175. package/lib/dist/extraction/languages/kotlin.d.ts +15 -0
  176. package/lib/dist/extraction/languages/kotlin.d.ts.map +1 -1
  177. package/lib/dist/extraction/languages/kotlin.js +69 -150
  178. package/lib/dist/extraction/languages/kotlin.js.map +1 -1
  179. package/lib/dist/extraction/languages/lua.js +2 -39
  180. package/lib/dist/extraction/languages/lua.js.map +1 -1
  181. package/lib/dist/extraction/languages/luau.js +0 -14
  182. package/lib/dist/extraction/languages/luau.js.map +1 -1
  183. package/lib/dist/extraction/languages/nix.js +0 -16
  184. package/lib/dist/extraction/languages/nix.js.map +1 -1
  185. package/lib/dist/extraction/languages/objc.d.ts.map +1 -1
  186. package/lib/dist/extraction/languages/objc.js +5 -16
  187. package/lib/dist/extraction/languages/objc.js.map +1 -1
  188. package/lib/dist/extraction/languages/pascal-preparse.d.ts +66 -0
  189. package/lib/dist/extraction/languages/pascal-preparse.d.ts.map +1 -0
  190. package/lib/dist/extraction/languages/pascal-preparse.js +958 -0
  191. package/lib/dist/extraction/languages/pascal-preparse.js.map +1 -0
  192. package/lib/dist/extraction/languages/pascal-system.d.ts +11 -0
  193. package/lib/dist/extraction/languages/pascal-system.d.ts.map +1 -0
  194. package/lib/dist/extraction/languages/pascal-system.js +23 -0
  195. package/lib/dist/extraction/languages/pascal-system.js.map +1 -0
  196. package/lib/dist/extraction/languages/pascal.d.ts.map +1 -1
  197. package/lib/dist/extraction/languages/pascal.js +3 -4
  198. package/lib/dist/extraction/languages/pascal.js.map +1 -1
  199. package/lib/dist/extraction/languages/php.js +5 -42
  200. package/lib/dist/extraction/languages/php.js.map +1 -1
  201. package/lib/dist/extraction/languages/python.js +2 -20
  202. package/lib/dist/extraction/languages/python.js.map +1 -1
  203. package/lib/dist/extraction/languages/r.js +8 -78
  204. package/lib/dist/extraction/languages/r.js.map +1 -1
  205. package/lib/dist/extraction/languages/ruby.d.ts.map +1 -1
  206. package/lib/dist/extraction/languages/ruby.js +17 -25
  207. package/lib/dist/extraction/languages/ruby.js.map +1 -1
  208. package/lib/dist/extraction/languages/rust.d.ts +10 -0
  209. package/lib/dist/extraction/languages/rust.d.ts.map +1 -1
  210. package/lib/dist/extraction/languages/rust.js +15 -47
  211. package/lib/dist/extraction/languages/rust.js.map +1 -1
  212. package/lib/dist/extraction/languages/scala.js +5 -41
  213. package/lib/dist/extraction/languages/scala.js.map +1 -1
  214. package/lib/dist/extraction/languages/solidity.js +1 -82
  215. package/lib/dist/extraction/languages/solidity.js.map +1 -1
  216. package/lib/dist/extraction/languages/swift.d.ts +15 -0
  217. package/lib/dist/extraction/languages/swift.d.ts.map +1 -1
  218. package/lib/dist/extraction/languages/swift.js +33 -27
  219. package/lib/dist/extraction/languages/swift.js.map +1 -1
  220. package/lib/dist/extraction/languages/terraform.js +6 -152
  221. package/lib/dist/extraction/languages/terraform.js.map +1 -1
  222. package/lib/dist/extraction/languages/typescript.d.ts +71 -0
  223. package/lib/dist/extraction/languages/typescript.d.ts.map +1 -1
  224. package/lib/dist/extraction/languages/typescript.js +86 -41
  225. package/lib/dist/extraction/languages/typescript.js.map +1 -1
  226. package/lib/dist/extraction/languages/vbnet.d.ts.map +1 -1
  227. package/lib/dist/extraction/languages/vbnet.js +9 -42
  228. package/lib/dist/extraction/languages/vbnet.js.map +1 -1
  229. package/lib/dist/extraction/lazy-frameworks.d.ts +15 -0
  230. package/lib/dist/extraction/lazy-frameworks.d.ts.map +1 -0
  231. package/lib/dist/extraction/lazy-frameworks.js +8 -0
  232. package/lib/dist/extraction/lazy-frameworks.js.map +1 -0
  233. package/lib/dist/extraction/liquid-extractor.d.ts +29 -3
  234. package/lib/dist/extraction/liquid-extractor.d.ts.map +1 -1
  235. package/lib/dist/extraction/liquid-extractor.js +89 -148
  236. package/lib/dist/extraction/liquid-extractor.js.map +1 -1
  237. package/lib/dist/extraction/mybatis-extractor.js +0 -78
  238. package/lib/dist/extraction/mybatis-extractor.js.map +1 -1
  239. package/lib/dist/extraction/parse-budget.d.ts +16 -0
  240. package/lib/dist/extraction/parse-budget.d.ts.map +1 -0
  241. package/lib/dist/extraction/parse-budget.js +11 -0
  242. package/lib/dist/extraction/parse-budget.js.map +1 -0
  243. package/lib/dist/extraction/parse-pool.d.ts +41 -5
  244. package/lib/dist/extraction/parse-pool.d.ts.map +1 -1
  245. package/lib/dist/extraction/parse-pool.js +74 -158
  246. package/lib/dist/extraction/parse-pool.js.map +1 -1
  247. package/lib/dist/extraction/parse-worker.d.ts +1 -1
  248. package/lib/dist/extraction/parse-worker.d.ts.map +1 -1
  249. package/lib/dist/extraction/parse-worker.js +7 -58
  250. package/lib/dist/extraction/parse-worker.js.map +1 -1
  251. package/lib/dist/extraction/razor-extractor.d.ts +9 -0
  252. package/lib/dist/extraction/razor-extractor.d.ts.map +1 -1
  253. package/lib/dist/extraction/razor-extractor.js +45 -69
  254. package/lib/dist/extraction/razor-extractor.js.map +1 -1
  255. package/lib/dist/extraction/razor-script.d.ts +23 -0
  256. package/lib/dist/extraction/razor-script.d.ts.map +1 -0
  257. package/lib/dist/extraction/razor-script.js +244 -0
  258. package/lib/dist/extraction/razor-script.js.map +1 -0
  259. package/lib/dist/extraction/sfc-script.d.ts +85 -0
  260. package/lib/dist/extraction/sfc-script.d.ts.map +1 -0
  261. package/lib/dist/extraction/sfc-script.js +136 -0
  262. package/lib/dist/extraction/sfc-script.js.map +1 -0
  263. package/lib/dist/extraction/store-worker.d.ts +1 -1
  264. package/lib/dist/extraction/store-worker.d.ts.map +1 -1
  265. package/lib/dist/extraction/store-worker.js +5 -37
  266. package/lib/dist/extraction/store-worker.js.map +1 -1
  267. package/lib/dist/extraction/store-writer.d.ts +10 -2
  268. package/lib/dist/extraction/store-writer.d.ts.map +1 -1
  269. package/lib/dist/extraction/store-writer.js +8 -32
  270. package/lib/dist/extraction/store-writer.js.map +1 -1
  271. package/lib/dist/extraction/svelte-extractor.d.ts.map +1 -1
  272. package/lib/dist/extraction/svelte-extractor.js +16 -122
  273. package/lib/dist/extraction/svelte-extractor.js.map +1 -1
  274. package/lib/dist/extraction/syntax-tokens.d.ts +6 -5
  275. package/lib/dist/extraction/syntax-tokens.d.ts.map +1 -1
  276. package/lib/dist/extraction/syntax-tokens.js +6 -153
  277. package/lib/dist/extraction/syntax-tokens.js.map +1 -1
  278. package/lib/dist/extraction/tree-sitter-helpers.d.ts +37 -1
  279. package/lib/dist/extraction/tree-sitter-helpers.d.ts.map +1 -1
  280. package/lib/dist/extraction/tree-sitter-helpers.js +76 -68
  281. package/lib/dist/extraction/tree-sitter-helpers.js.map +1 -1
  282. package/lib/dist/extraction/tree-sitter-types.d.ts +102 -22
  283. package/lib/dist/extraction/tree-sitter-types.d.ts.map +1 -1
  284. package/lib/dist/extraction/tree-sitter-types.js +0 -7
  285. package/lib/dist/extraction/tree-sitter-types.js.map +1 -1
  286. package/lib/dist/extraction/tree-sitter.d.ts +455 -9
  287. package/lib/dist/extraction/tree-sitter.d.ts.map +1 -1
  288. package/lib/dist/extraction/tree-sitter.js +1998 -2517
  289. package/lib/dist/extraction/tree-sitter.js.map +1 -1
  290. package/lib/dist/extraction/vue-extractor.d.ts +20 -0
  291. package/lib/dist/extraction/vue-extractor.d.ts.map +1 -1
  292. package/lib/dist/extraction/vue-extractor.js +113 -115
  293. package/lib/dist/extraction/vue-extractor.js.map +1 -1
  294. package/lib/dist/extraction/vue-options-api.d.ts +28 -0
  295. package/lib/dist/extraction/vue-options-api.d.ts.map +1 -0
  296. package/lib/dist/extraction/vue-options-api.js +164 -0
  297. package/lib/dist/extraction/vue-options-api.js.map +1 -0
  298. package/lib/dist/extraction/vue-template-calls.d.ts +37 -0
  299. package/lib/dist/extraction/vue-template-calls.d.ts.map +1 -0
  300. package/lib/dist/extraction/vue-template-calls.js +497 -0
  301. package/lib/dist/extraction/vue-template-calls.js.map +1 -0
  302. package/lib/dist/extraction/wasm/tree-sitter-cobol.wasm +0 -0
  303. package/lib/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
  304. package/lib/dist/extraction/wasm/tree-sitter-vbnet.wasm +0 -0
  305. package/lib/dist/extraction/wasm-runtime-flags.d.ts +6 -0
  306. package/lib/dist/extraction/wasm-runtime-flags.d.ts.map +1 -1
  307. package/lib/dist/extraction/wasm-runtime-flags.js +1 -88
  308. package/lib/dist/extraction/wasm-runtime-flags.js.map +1 -1
  309. package/lib/dist/file-limits.d.ts +8 -0
  310. package/lib/dist/file-limits.d.ts.map +1 -1
  311. package/lib/dist/file-limits.js +13 -28
  312. package/lib/dist/file-limits.js.map +1 -1
  313. package/lib/dist/graph/branch-guards.d.ts +17 -0
  314. package/lib/dist/graph/branch-guards.d.ts.map +1 -1
  315. package/lib/dist/graph/branch-guards.js +98 -250
  316. package/lib/dist/graph/branch-guards.js.map +1 -1
  317. package/lib/dist/graph/call-sites.d.ts +12 -0
  318. package/lib/dist/graph/call-sites.d.ts.map +1 -0
  319. package/lib/dist/graph/call-sites.js +17 -0
  320. package/lib/dist/graph/call-sites.js.map +1 -0
  321. package/lib/dist/graph/cobol-copybooks.d.ts +75 -0
  322. package/lib/dist/graph/cobol-copybooks.d.ts.map +1 -0
  323. package/lib/dist/graph/cobol-copybooks.js +45 -0
  324. package/lib/dist/graph/cobol-copybooks.js.map +1 -0
  325. package/lib/dist/graph/dead-code.d.ts +26 -4
  326. package/lib/dist/graph/dead-code.d.ts.map +1 -1
  327. package/lib/dist/graph/dead-code.js +157 -311
  328. package/lib/dist/graph/dead-code.js.map +1 -1
  329. package/lib/dist/graph/dynamic-boundary-report.js +1 -88
  330. package/lib/dist/graph/dynamic-boundary-report.js.map +1 -1
  331. package/lib/dist/graph/file-cycles.d.ts +20 -0
  332. package/lib/dist/graph/file-cycles.d.ts.map +1 -0
  333. package/lib/dist/graph/file-cycles.js +79 -0
  334. package/lib/dist/graph/file-cycles.js.map +1 -0
  335. package/lib/dist/graph/go-package.d.ts +27 -0
  336. package/lib/dist/graph/go-package.d.ts.map +1 -0
  337. package/lib/dist/graph/go-package.js +49 -0
  338. package/lib/dist/graph/go-package.js.map +1 -0
  339. package/lib/dist/graph/index.d.ts +2 -0
  340. package/lib/dist/graph/index.d.ts.map +1 -1
  341. package/lib/dist/graph/index.js +4 -6
  342. package/lib/dist/graph/index.js.map +1 -1
  343. package/lib/dist/graph/named-symbol-flow.d.ts +5 -1
  344. package/lib/dist/graph/named-symbol-flow.d.ts.map +1 -1
  345. package/lib/dist/graph/named-symbol-flow.js +85 -219
  346. package/lib/dist/graph/named-symbol-flow.js.map +1 -1
  347. package/lib/dist/graph/owning-package.d.ts +59 -0
  348. package/lib/dist/graph/owning-package.d.ts.map +1 -0
  349. package/lib/dist/graph/owning-package.js +120 -0
  350. package/lib/dist/graph/owning-package.js.map +1 -0
  351. package/lib/dist/graph/queries.d.ts +2 -2
  352. package/lib/dist/graph/queries.d.ts.map +1 -1
  353. package/lib/dist/graph/queries.js +2 -135
  354. package/lib/dist/graph/queries.js.map +1 -1
  355. package/lib/dist/graph/symbol-lookup.d.ts +15 -3
  356. package/lib/dist/graph/symbol-lookup.d.ts.map +1 -1
  357. package/lib/dist/graph/symbol-lookup.js +47 -89
  358. package/lib/dist/graph/symbol-lookup.js.map +1 -1
  359. package/lib/dist/graph/synthesized-hop.d.ts +37 -0
  360. package/lib/dist/graph/synthesized-hop.d.ts.map +1 -0
  361. package/lib/dist/graph/synthesized-hop.js +62 -0
  362. package/lib/dist/graph/synthesized-hop.js.map +1 -0
  363. package/lib/dist/graph/test-code.d.ts +21 -0
  364. package/lib/dist/graph/test-code.d.ts.map +1 -0
  365. package/lib/dist/graph/test-code.js +50 -0
  366. package/lib/dist/graph/test-code.js.map +1 -0
  367. package/lib/dist/graph/traversal.d.ts +31 -2
  368. package/lib/dist/graph/traversal.d.ts.map +1 -1
  369. package/lib/dist/graph/traversal.js +98 -226
  370. package/lib/dist/graph/traversal.js.map +1 -1
  371. package/lib/dist/graph/type-hierarchy.js +0 -138
  372. package/lib/dist/graph/type-hierarchy.js.map +1 -1
  373. package/lib/dist/index.d.ts +195 -25
  374. package/lib/dist/index.d.ts.map +1 -1
  375. package/lib/dist/index.js +697 -1105
  376. package/lib/dist/index.js.map +1 -1
  377. package/lib/dist/installer/beta-signup.js +0 -39
  378. package/lib/dist/installer/beta-signup.js.map +1 -1
  379. package/lib/dist/installer/config-writer.js +0 -24
  380. package/lib/dist/installer/config-writer.js.map +1 -1
  381. package/lib/dist/installer/index.d.ts +9 -5
  382. package/lib/dist/installer/index.d.ts.map +1 -1
  383. package/lib/dist/installer/index.js +25 -159
  384. package/lib/dist/installer/index.js.map +1 -1
  385. package/lib/dist/installer/instructions-template.d.ts +1 -1
  386. package/lib/dist/installer/instructions-template.js +0 -37
  387. package/lib/dist/installer/instructions-template.js.map +1 -1
  388. package/lib/dist/installer/targets/antigravity.js +0 -113
  389. package/lib/dist/installer/targets/antigravity.js.map +1 -1
  390. package/lib/dist/installer/targets/bob.d.ts +20 -0
  391. package/lib/dist/installer/targets/bob.d.ts.map +1 -0
  392. package/lib/dist/installer/targets/bob.js +83 -0
  393. package/lib/dist/installer/targets/bob.js.map +1 -0
  394. package/lib/dist/installer/targets/claude.d.ts.map +1 -1
  395. package/lib/dist/installer/targets/claude.js +1 -185
  396. package/lib/dist/installer/targets/claude.js.map +1 -1
  397. package/lib/dist/installer/targets/codex.d.ts.map +1 -1
  398. package/lib/dist/installer/targets/codex.js +17 -109
  399. package/lib/dist/installer/targets/codex.js.map +1 -1
  400. package/lib/dist/installer/targets/copilot-cli.d.ts.map +1 -1
  401. package/lib/dist/installer/targets/copilot-cli.js +2 -54
  402. package/lib/dist/installer/targets/copilot-cli.js.map +1 -1
  403. package/lib/dist/installer/targets/copilot-jetbrains.js +0 -57
  404. package/lib/dist/installer/targets/copilot-jetbrains.js.map +1 -1
  405. package/lib/dist/installer/targets/copilot-vscode.js +0 -58
  406. package/lib/dist/installer/targets/copilot-vscode.js.map +1 -1
  407. package/lib/dist/installer/targets/cursor.js +7 -88
  408. package/lib/dist/installer/targets/cursor.js.map +1 -1
  409. package/lib/dist/installer/targets/droid.d.ts +18 -0
  410. package/lib/dist/installer/targets/droid.d.ts.map +1 -0
  411. package/lib/dist/installer/targets/droid.js +92 -0
  412. package/lib/dist/installer/targets/droid.js.map +1 -0
  413. package/lib/dist/installer/targets/dsh.d.ts +35 -0
  414. package/lib/dist/installer/targets/dsh.d.ts.map +1 -0
  415. package/lib/dist/installer/targets/dsh.js +267 -0
  416. package/lib/dist/installer/targets/dsh.js.map +1 -0
  417. package/lib/dist/installer/targets/gemini.js +0 -37
  418. package/lib/dist/installer/targets/gemini.js.map +1 -1
  419. package/lib/dist/installer/targets/grok.d.ts +25 -0
  420. package/lib/dist/installer/targets/grok.d.ts.map +1 -0
  421. package/lib/dist/installer/targets/grok.js +96 -0
  422. package/lib/dist/installer/targets/grok.js.map +1 -0
  423. package/lib/dist/installer/targets/hermes.d.ts +19 -7
  424. package/lib/dist/installer/targets/hermes.d.ts.map +1 -1
  425. package/lib/dist/installer/targets/hermes.js +218 -214
  426. package/lib/dist/installer/targets/hermes.js.map +1 -1
  427. package/lib/dist/installer/targets/json-config.d.ts +45 -0
  428. package/lib/dist/installer/targets/json-config.d.ts.map +1 -0
  429. package/lib/dist/installer/targets/json-config.js +128 -0
  430. package/lib/dist/installer/targets/json-config.js.map +1 -0
  431. package/lib/dist/installer/targets/kimi.d.ts +21 -0
  432. package/lib/dist/installer/targets/kimi.d.ts.map +1 -0
  433. package/lib/dist/installer/targets/kimi.js +97 -0
  434. package/lib/dist/installer/targets/kimi.js.map +1 -0
  435. package/lib/dist/installer/targets/kiro.js +1 -41
  436. package/lib/dist/installer/targets/kiro.js.map +1 -1
  437. package/lib/dist/installer/targets/opencode.js +0 -102
  438. package/lib/dist/installer/targets/opencode.js.map +1 -1
  439. package/lib/dist/installer/targets/pi.d.ts +24 -0
  440. package/lib/dist/installer/targets/pi.d.ts.map +1 -0
  441. package/lib/dist/installer/targets/pi.js +100 -0
  442. package/lib/dist/installer/targets/pi.js.map +1 -0
  443. package/lib/dist/installer/targets/qoder.d.ts +23 -0
  444. package/lib/dist/installer/targets/qoder.d.ts.map +1 -0
  445. package/lib/dist/installer/targets/qoder.js +83 -0
  446. package/lib/dist/installer/targets/qoder.js.map +1 -0
  447. package/lib/dist/installer/targets/qwen.d.ts +21 -0
  448. package/lib/dist/installer/targets/qwen.d.ts.map +1 -0
  449. package/lib/dist/installer/targets/qwen.js +115 -0
  450. package/lib/dist/installer/targets/qwen.js.map +1 -0
  451. package/lib/dist/installer/targets/registry.d.ts.map +1 -1
  452. package/lib/dist/installer/targets/registry.js +18 -25
  453. package/lib/dist/installer/targets/registry.js.map +1 -1
  454. package/lib/dist/installer/targets/shared.d.ts +81 -11
  455. package/lib/dist/installer/targets/shared.d.ts.map +1 -1
  456. package/lib/dist/installer/targets/shared.js +183 -129
  457. package/lib/dist/installer/targets/shared.js.map +1 -1
  458. package/lib/dist/installer/targets/toml.d.ts +82 -6
  459. package/lib/dist/installer/targets/toml.d.ts.map +1 -1
  460. package/lib/dist/installer/targets/toml.js +318 -112
  461. package/lib/dist/installer/targets/toml.js.map +1 -1
  462. package/lib/dist/installer/targets/types.d.ts +1 -1
  463. package/lib/dist/installer/targets/types.d.ts.map +1 -1
  464. package/lib/dist/installer/targets/types.js +0 -13
  465. package/lib/dist/installer/targets/types.js.map +1 -1
  466. package/lib/dist/installer/targets/windsurf.d.ts +22 -0
  467. package/lib/dist/installer/targets/windsurf.d.ts.map +1 -0
  468. package/lib/dist/installer/targets/windsurf.js +90 -0
  469. package/lib/dist/installer/targets/windsurf.js.map +1 -0
  470. package/lib/dist/lazy-engine.d.ts +22 -0
  471. package/lib/dist/lazy-engine.d.ts.map +1 -0
  472. package/lib/dist/lazy-engine.js +16 -0
  473. package/lib/dist/lazy-engine.js.map +1 -0
  474. package/lib/dist/mcp/answer-freshness.js +0 -6
  475. package/lib/dist/mcp/answer-freshness.js.map +1 -1
  476. package/lib/dist/mcp/daemon-manager.js +2 -23
  477. package/lib/dist/mcp/daemon-manager.js.map +1 -1
  478. package/lib/dist/mcp/daemon-paths.d.ts.map +1 -1
  479. package/lib/dist/mcp/daemon-paths.js +2 -79
  480. package/lib/dist/mcp/daemon-paths.js.map +1 -1
  481. package/lib/dist/mcp/daemon-registry.d.ts +44 -0
  482. package/lib/dist/mcp/daemon-registry.d.ts.map +1 -1
  483. package/lib/dist/mcp/daemon-registry.js +189 -118
  484. package/lib/dist/mcp/daemon-registry.js.map +1 -1
  485. package/lib/dist/mcp/daemon.d.ts +23 -0
  486. package/lib/dist/mcp/daemon.d.ts.map +1 -1
  487. package/lib/dist/mcp/daemon.js +89 -373
  488. package/lib/dist/mcp/daemon.js.map +1 -1
  489. package/lib/dist/mcp/dynamic-boundaries.js +4 -78
  490. package/lib/dist/mcp/dynamic-boundaries.js.map +1 -1
  491. package/lib/dist/mcp/early-ppid.js +0 -24
  492. package/lib/dist/mcp/early-ppid.js.map +1 -1
  493. package/lib/dist/mcp/engine.d.ts +10 -0
  494. package/lib/dist/mcp/engine.d.ts.map +1 -1
  495. package/lib/dist/mcp/engine.js +41 -152
  496. package/lib/dist/mcp/engine.js.map +1 -1
  497. package/lib/dist/mcp/explore-dedup.js +0 -108
  498. package/lib/dist/mcp/explore-dedup.js.map +1 -1
  499. package/lib/dist/mcp/explore-diagnostics.js +0 -116
  500. package/lib/dist/mcp/explore-diagnostics.js.map +1 -1
  501. package/lib/dist/mcp/explore-session-state.js +0 -129
  502. package/lib/dist/mcp/explore-session-state.js.map +1 -1
  503. package/lib/dist/mcp/index-freshness-worker.js +5 -4
  504. package/lib/dist/mcp/index-freshness-worker.js.map +1 -1
  505. package/lib/dist/mcp/index-freshness.d.ts +7 -1
  506. package/lib/dist/mcp/index-freshness.d.ts.map +1 -1
  507. package/lib/dist/mcp/index-freshness.js +20 -12
  508. package/lib/dist/mcp/index-freshness.js.map +1 -1
  509. package/lib/dist/mcp/index-version-warning.d.ts +21 -0
  510. package/lib/dist/mcp/index-version-warning.d.ts.map +1 -0
  511. package/lib/dist/mcp/index-version-warning.js +38 -0
  512. package/lib/dist/mcp/index-version-warning.js.map +1 -0
  513. package/lib/dist/mcp/index.d.ts +19 -1
  514. package/lib/dist/mcp/index.d.ts.map +1 -1
  515. package/lib/dist/mcp/index.js +118 -293
  516. package/lib/dist/mcp/index.js.map +1 -1
  517. package/lib/dist/mcp/liveness-watchdog.d.ts +13 -3
  518. package/lib/dist/mcp/liveness-watchdog.d.ts.map +1 -1
  519. package/lib/dist/mcp/liveness-watchdog.js +106 -121
  520. package/lib/dist/mcp/liveness-watchdog.js.map +1 -1
  521. package/lib/dist/mcp/ppid-watchdog.js +0 -24
  522. package/lib/dist/mcp/ppid-watchdog.js.map +1 -1
  523. package/lib/dist/mcp/process-identity.d.ts +42 -0
  524. package/lib/dist/mcp/process-identity.d.ts.map +1 -0
  525. package/lib/dist/mcp/process-identity.js +130 -0
  526. package/lib/dist/mcp/process-identity.js.map +1 -0
  527. package/lib/dist/mcp/project-lifecycle.d.ts.map +1 -1
  528. package/lib/dist/mcp/project-lifecycle.js +55 -21
  529. package/lib/dist/mcp/project-lifecycle.js.map +1 -1
  530. package/lib/dist/mcp/proxy.d.ts +26 -8
  531. package/lib/dist/mcp/proxy.d.ts.map +1 -1
  532. package/lib/dist/mcp/proxy.js +209 -223
  533. package/lib/dist/mcp/proxy.js.map +1 -1
  534. package/lib/dist/mcp/query-pool.d.ts +58 -3
  535. package/lib/dist/mcp/query-pool.d.ts.map +1 -1
  536. package/lib/dist/mcp/query-pool.js +140 -100
  537. package/lib/dist/mcp/query-pool.js.map +1 -1
  538. package/lib/dist/mcp/query-worker.js +24 -36
  539. package/lib/dist/mcp/query-worker.js.map +1 -1
  540. package/lib/dist/mcp/server-instructions.js +0 -31
  541. package/lib/dist/mcp/server-instructions.js.map +1 -1
  542. package/lib/dist/mcp/session.d.ts +27 -0
  543. package/lib/dist/mcp/session.d.ts.map +1 -1
  544. package/lib/dist/mcp/session.js +29 -130
  545. package/lib/dist/mcp/session.js.map +1 -1
  546. package/lib/dist/mcp/startup-handshake.js +1 -48
  547. package/lib/dist/mcp/startup-handshake.js.map +1 -1
  548. package/lib/dist/mcp/stdin-teardown.js +0 -28
  549. package/lib/dist/mcp/stdin-teardown.js.map +1 -1
  550. package/lib/dist/mcp/stdout-teardown.d.ts +26 -0
  551. package/lib/dist/mcp/stdout-teardown.d.ts.map +1 -0
  552. package/lib/dist/mcp/stdout-teardown.js +20 -0
  553. package/lib/dist/mcp/stdout-teardown.js.map +1 -0
  554. package/lib/dist/mcp/tools.d.ts +159 -20
  555. package/lib/dist/mcp/tools.d.ts.map +1 -1
  556. package/lib/dist/mcp/tools.js +730 -3545
  557. package/lib/dist/mcp/tools.js.map +1 -1
  558. package/lib/dist/mcp/transport.d.ts.map +1 -1
  559. package/lib/dist/mcp/transport.js +4 -96
  560. package/lib/dist/mcp/transport.js.map +1 -1
  561. package/lib/dist/mcp/version.d.ts +13 -1
  562. package/lib/dist/mcp/version.d.ts.map +1 -1
  563. package/lib/dist/mcp/version.js +19 -21
  564. package/lib/dist/mcp/version.js.map +1 -1
  565. package/lib/dist/mcp/writer-lock.d.ts +11 -0
  566. package/lib/dist/mcp/writer-lock.d.ts.map +1 -1
  567. package/lib/dist/mcp/writer-lock.js +49 -46
  568. package/lib/dist/mcp/writer-lock.js.map +1 -1
  569. package/lib/dist/project-config.js +1 -138
  570. package/lib/dist/project-config.js.map +1 -1
  571. package/lib/dist/resolution/alias-binding.d.ts +7 -0
  572. package/lib/dist/resolution/alias-binding.d.ts.map +1 -1
  573. package/lib/dist/resolution/alias-binding.js +19 -52
  574. package/lib/dist/resolution/alias-binding.js.map +1 -1
  575. package/lib/dist/resolution/ambient-modules.d.ts +185 -0
  576. package/lib/dist/resolution/ambient-modules.d.ts.map +1 -0
  577. package/lib/dist/resolution/ambient-modules.js +732 -0
  578. package/lib/dist/resolution/ambient-modules.js.map +1 -0
  579. package/lib/dist/resolution/angular-template-synthesizer.d.ts +96 -0
  580. package/lib/dist/resolution/angular-template-synthesizer.d.ts.map +1 -0
  581. package/lib/dist/resolution/angular-template-synthesizer.js +695 -0
  582. package/lib/dist/resolution/angular-template-synthesizer.js.map +1 -0
  583. package/lib/dist/resolution/c-feature-variants.d.ts +40 -0
  584. package/lib/dist/resolution/c-feature-variants.d.ts.map +1 -0
  585. package/lib/dist/resolution/c-feature-variants.js +249 -0
  586. package/lib/dist/resolution/c-feature-variants.js.map +1 -0
  587. package/lib/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -1
  588. package/lib/dist/resolution/c-fnptr-synthesizer.js +23 -391
  589. package/lib/dist/resolution/c-fnptr-synthesizer.js.map +1 -1
  590. package/lib/dist/resolution/c-macro-renames.d.ts +25 -0
  591. package/lib/dist/resolution/c-macro-renames.d.ts.map +1 -0
  592. package/lib/dist/resolution/c-macro-renames.js +95 -0
  593. package/lib/dist/resolution/c-macro-renames.js.map +1 -0
  594. package/lib/dist/resolution/callback-synthesizer.d.ts +15 -1
  595. package/lib/dist/resolution/callback-synthesizer.d.ts.map +1 -1
  596. package/lib/dist/resolution/callback-synthesizer.js +1487 -1234
  597. package/lib/dist/resolution/callback-synthesizer.js.map +1 -1
  598. package/lib/dist/resolution/const-alias-synthesizer.d.ts +48 -0
  599. package/lib/dist/resolution/const-alias-synthesizer.d.ts.map +1 -0
  600. package/lib/dist/resolution/const-alias-synthesizer.js +234 -0
  601. package/lib/dist/resolution/const-alias-synthesizer.js.map +1 -0
  602. package/lib/dist/resolution/cooperative-yield.js +0 -27
  603. package/lib/dist/resolution/cooperative-yield.js.map +1 -1
  604. package/lib/dist/resolution/cpp-constructor.d.ts.map +1 -1
  605. package/lib/dist/resolution/cpp-constructor.js +15 -17
  606. package/lib/dist/resolution/cpp-constructor.js.map +1 -1
  607. package/lib/dist/resolution/cpp-includers.d.ts +46 -0
  608. package/lib/dist/resolution/cpp-includers.d.ts.map +1 -0
  609. package/lib/dist/resolution/cpp-includers.js +153 -0
  610. package/lib/dist/resolution/cpp-includers.js.map +1 -0
  611. package/lib/dist/resolution/cpp-macro-visibility.d.ts +16 -0
  612. package/lib/dist/resolution/cpp-macro-visibility.d.ts.map +1 -1
  613. package/lib/dist/resolution/cpp-macro-visibility.js +60 -61
  614. package/lib/dist/resolution/cpp-macro-visibility.js.map +1 -1
  615. package/lib/dist/resolution/cpp-namespaces.d.ts +54 -0
  616. package/lib/dist/resolution/cpp-namespaces.d.ts.map +1 -0
  617. package/lib/dist/resolution/cpp-namespaces.js +151 -0
  618. package/lib/dist/resolution/cpp-namespaces.js.map +1 -0
  619. package/lib/dist/resolution/cpp-raw-strings.d.ts +33 -0
  620. package/lib/dist/resolution/cpp-raw-strings.d.ts.map +1 -0
  621. package/lib/dist/resolution/cpp-raw-strings.js +167 -0
  622. package/lib/dist/resolution/cpp-raw-strings.js.map +1 -0
  623. package/lib/dist/resolution/cpp-supertypes.d.ts +118 -0
  624. package/lib/dist/resolution/cpp-supertypes.d.ts.map +1 -0
  625. package/lib/dist/resolution/cpp-supertypes.js +322 -0
  626. package/lib/dist/resolution/cpp-supertypes.js.map +1 -0
  627. package/lib/dist/resolution/cpp-template-instantiations.d.ts +83 -0
  628. package/lib/dist/resolution/cpp-template-instantiations.d.ts.map +1 -0
  629. package/lib/dist/resolution/cpp-template-instantiations.js +983 -0
  630. package/lib/dist/resolution/cpp-template-instantiations.js.map +1 -0
  631. package/lib/dist/resolution/cpp-type-aliases.d.ts +194 -0
  632. package/lib/dist/resolution/cpp-type-aliases.d.ts.map +1 -0
  633. package/lib/dist/resolution/cpp-type-aliases.js +648 -0
  634. package/lib/dist/resolution/cpp-type-aliases.js.map +1 -0
  635. package/lib/dist/resolution/dart-libraries.d.ts +75 -0
  636. package/lib/dist/resolution/dart-libraries.d.ts.map +1 -0
  637. package/lib/dist/resolution/dart-libraries.js +721 -0
  638. package/lib/dist/resolution/dart-libraries.js.map +1 -0
  639. package/lib/dist/resolution/dart-local-scope.d.ts +41 -0
  640. package/lib/dist/resolution/dart-local-scope.d.ts.map +1 -0
  641. package/lib/dist/resolution/dart-local-scope.js +565 -0
  642. package/lib/dist/resolution/dart-local-scope.js.map +1 -0
  643. package/lib/dist/resolution/expo-router-synthesizer.js +0 -52
  644. package/lib/dist/resolution/expo-router-synthesizer.js.map +1 -1
  645. package/lib/dist/resolution/frameworks/angular-router.d.ts +142 -0
  646. package/lib/dist/resolution/frameworks/angular-router.d.ts.map +1 -0
  647. package/lib/dist/resolution/frameworks/angular-router.js +959 -0
  648. package/lib/dist/resolution/frameworks/angular-router.js.map +1 -0
  649. package/lib/dist/resolution/frameworks/astro.d.ts.map +1 -1
  650. package/lib/dist/resolution/frameworks/astro.js +30 -60
  651. package/lib/dist/resolution/frameworks/astro.js.map +1 -1
  652. package/lib/dist/resolution/frameworks/cargo-workspace.d.ts +18 -1
  653. package/lib/dist/resolution/frameworks/cargo-workspace.d.ts.map +1 -1
  654. package/lib/dist/resolution/frameworks/cargo-workspace.js +65 -15
  655. package/lib/dist/resolution/frameworks/cargo-workspace.js.map +1 -1
  656. package/lib/dist/resolution/frameworks/cics.d.ts.map +1 -1
  657. package/lib/dist/resolution/frameworks/cics.js +7 -33
  658. package/lib/dist/resolution/frameworks/cics.js.map +1 -1
  659. package/lib/dist/resolution/frameworks/codeigniter.d.ts +23 -0
  660. package/lib/dist/resolution/frameworks/codeigniter.d.ts.map +1 -0
  661. package/lib/dist/resolution/frameworks/codeigniter.js +271 -0
  662. package/lib/dist/resolution/frameworks/codeigniter.js.map +1 -0
  663. package/lib/dist/resolution/frameworks/component-folder.d.ts +17 -0
  664. package/lib/dist/resolution/frameworks/component-folder.d.ts.map +1 -0
  665. package/lib/dist/resolution/frameworks/component-folder.js +11 -0
  666. package/lib/dist/resolution/frameworks/component-folder.js.map +1 -0
  667. package/lib/dist/resolution/frameworks/csharp.d.ts.map +1 -1
  668. package/lib/dist/resolution/frameworks/csharp.js +106 -101
  669. package/lib/dist/resolution/frameworks/csharp.js.map +1 -1
  670. package/lib/dist/resolution/frameworks/drupal.d.ts +17 -8
  671. package/lib/dist/resolution/frameworks/drupal.d.ts.map +1 -1
  672. package/lib/dist/resolution/frameworks/drupal.js +377 -142
  673. package/lib/dist/resolution/frameworks/drupal.js.map +1 -1
  674. package/lib/dist/resolution/frameworks/expo-modules.d.ts +10 -0
  675. package/lib/dist/resolution/frameworks/expo-modules.d.ts.map +1 -1
  676. package/lib/dist/resolution/frameworks/expo-modules.js +79 -65
  677. package/lib/dist/resolution/frameworks/expo-modules.js.map +1 -1
  678. package/lib/dist/resolution/frameworks/expo-router.d.ts +6 -0
  679. package/lib/dist/resolution/frameworks/expo-router.d.ts.map +1 -1
  680. package/lib/dist/resolution/frameworks/expo-router.js +64 -183
  681. package/lib/dist/resolution/frameworks/expo-router.js.map +1 -1
  682. package/lib/dist/resolution/frameworks/express.d.ts.map +1 -1
  683. package/lib/dist/resolution/frameworks/express.js +215 -173
  684. package/lib/dist/resolution/frameworks/express.js.map +1 -1
  685. package/lib/dist/resolution/frameworks/fabric.d.ts.map +1 -1
  686. package/lib/dist/resolution/frameworks/fabric.js +11 -112
  687. package/lib/dist/resolution/frameworks/fabric.js.map +1 -1
  688. package/lib/dist/resolution/frameworks/go.d.ts.map +1 -1
  689. package/lib/dist/resolution/frameworks/go.js +15 -61
  690. package/lib/dist/resolution/frameworks/go.js.map +1 -1
  691. package/lib/dist/resolution/frameworks/goframe.js +1 -55
  692. package/lib/dist/resolution/frameworks/goframe.js.map +1 -1
  693. package/lib/dist/resolution/frameworks/index.d.ts +16 -2
  694. package/lib/dist/resolution/frameworks/index.d.ts.map +1 -1
  695. package/lib/dist/resolution/frameworks/index.js +20 -48
  696. package/lib/dist/resolution/frameworks/index.js.map +1 -1
  697. package/lib/dist/resolution/frameworks/java.d.ts.map +1 -1
  698. package/lib/dist/resolution/frameworks/java.js +209 -147
  699. package/lib/dist/resolution/frameworks/java.js.map +1 -1
  700. package/lib/dist/resolution/frameworks/laravel.d.ts.map +1 -1
  701. package/lib/dist/resolution/frameworks/laravel.js +291 -71
  702. package/lib/dist/resolution/frameworks/laravel.js.map +1 -1
  703. package/lib/dist/resolution/frameworks/name-heuristic.d.ts +35 -0
  704. package/lib/dist/resolution/frameworks/name-heuristic.d.ts.map +1 -0
  705. package/lib/dist/resolution/frameworks/name-heuristic.js +33 -0
  706. package/lib/dist/resolution/frameworks/name-heuristic.js.map +1 -0
  707. package/lib/dist/resolution/frameworks/nestjs.d.ts.map +1 -1
  708. package/lib/dist/resolution/frameworks/nestjs.js +236 -192
  709. package/lib/dist/resolution/frameworks/nestjs.js.map +1 -1
  710. package/lib/dist/resolution/frameworks/next-proxy.d.ts +67 -0
  711. package/lib/dist/resolution/frameworks/next-proxy.d.ts.map +1 -0
  712. package/lib/dist/resolution/frameworks/next-proxy.js +239 -0
  713. package/lib/dist/resolution/frameworks/next-proxy.js.map +1 -0
  714. package/lib/dist/resolution/frameworks/nextjs.d.ts.map +1 -1
  715. package/lib/dist/resolution/frameworks/nextjs.js +11 -66
  716. package/lib/dist/resolution/frameworks/nextjs.js.map +1 -1
  717. package/lib/dist/resolution/frameworks/object-literal.js +0 -21
  718. package/lib/dist/resolution/frameworks/object-literal.js.map +1 -1
  719. package/lib/dist/resolution/frameworks/package-deps.d.ts +11 -7
  720. package/lib/dist/resolution/frameworks/package-deps.d.ts.map +1 -1
  721. package/lib/dist/resolution/frameworks/package-deps.js +35 -26
  722. package/lib/dist/resolution/frameworks/package-deps.js.map +1 -1
  723. package/lib/dist/resolution/frameworks/page-component.d.ts +20 -0
  724. package/lib/dist/resolution/frameworks/page-component.d.ts.map +1 -0
  725. package/lib/dist/resolution/frameworks/page-component.js +31 -0
  726. package/lib/dist/resolution/frameworks/page-component.js.map +1 -0
  727. package/lib/dist/resolution/frameworks/play.d.ts.map +1 -1
  728. package/lib/dist/resolution/frameworks/play.js +27 -33
  729. package/lib/dist/resolution/frameworks/play.js.map +1 -1
  730. package/lib/dist/resolution/frameworks/python.d.ts.map +1 -1
  731. package/lib/dist/resolution/frameworks/python.js +106 -116
  732. package/lib/dist/resolution/frameworks/python.js.map +1 -1
  733. package/lib/dist/resolution/frameworks/react-native.d.ts.map +1 -1
  734. package/lib/dist/resolution/frameworks/react-native.js +1 -166
  735. package/lib/dist/resolution/frameworks/react-native.js.map +1 -1
  736. package/lib/dist/resolution/frameworks/react-router.d.ts +17 -7
  737. package/lib/dist/resolution/frameworks/react-router.d.ts.map +1 -1
  738. package/lib/dist/resolution/frameworks/react-router.js +21 -79
  739. package/lib/dist/resolution/frameworks/react-router.js.map +1 -1
  740. package/lib/dist/resolution/frameworks/react.d.ts +68 -1
  741. package/lib/dist/resolution/frameworks/react.d.ts.map +1 -1
  742. package/lib/dist/resolution/frameworks/react.js +1721 -114
  743. package/lib/dist/resolution/frameworks/react.js.map +1 -1
  744. package/lib/dist/resolution/frameworks/ruby.d.ts.map +1 -1
  745. package/lib/dist/resolution/frameworks/ruby.js +152 -52
  746. package/lib/dist/resolution/frameworks/ruby.js.map +1 -1
  747. package/lib/dist/resolution/frameworks/rust.d.ts.map +1 -1
  748. package/lib/dist/resolution/frameworks/rust.js +51 -70
  749. package/lib/dist/resolution/frameworks/rust.js.map +1 -1
  750. package/lib/dist/resolution/frameworks/svelte.d.ts.map +1 -1
  751. package/lib/dist/resolution/frameworks/svelte.js +9 -74
  752. package/lib/dist/resolution/frameworks/svelte.js.map +1 -1
  753. package/lib/dist/resolution/frameworks/sveltekit-router.d.ts.map +1 -1
  754. package/lib/dist/resolution/frameworks/sveltekit-router.js +8 -46
  755. package/lib/dist/resolution/frameworks/sveltekit-router.js.map +1 -1
  756. package/lib/dist/resolution/frameworks/swift-objc.js +0 -97
  757. package/lib/dist/resolution/frameworks/swift-objc.js.map +1 -1
  758. package/lib/dist/resolution/frameworks/swift.d.ts.map +1 -1
  759. package/lib/dist/resolution/frameworks/swift.js +199 -167
  760. package/lib/dist/resolution/frameworks/swift.js.map +1 -1
  761. package/lib/dist/resolution/frameworks/tanstack-router.d.ts.map +1 -1
  762. package/lib/dist/resolution/frameworks/tanstack-router.js +9 -130
  763. package/lib/dist/resolution/frameworks/tanstack-router.js.map +1 -1
  764. package/lib/dist/resolution/frameworks/terraform.js +1 -85
  765. package/lib/dist/resolution/frameworks/terraform.js.map +1 -1
  766. package/lib/dist/resolution/frameworks/vue-router.d.ts +26 -10
  767. package/lib/dist/resolution/frameworks/vue-router.d.ts.map +1 -1
  768. package/lib/dist/resolution/frameworks/vue-router.js +147 -147
  769. package/lib/dist/resolution/frameworks/vue-router.js.map +1 -1
  770. package/lib/dist/resolution/frameworks/vue.d.ts +9 -2
  771. package/lib/dist/resolution/frameworks/vue.d.ts.map +1 -1
  772. package/lib/dist/resolution/frameworks/vue.js +69 -107
  773. package/lib/dist/resolution/frameworks/vue.js.map +1 -1
  774. package/lib/dist/resolution/go-func-field-synthesizer.d.ts +58 -0
  775. package/lib/dist/resolution/go-func-field-synthesizer.d.ts.map +1 -0
  776. package/lib/dist/resolution/go-func-field-synthesizer.js +696 -0
  777. package/lib/dist/resolution/go-func-field-synthesizer.js.map +1 -0
  778. package/lib/dist/resolution/go-module.d.ts +23 -7
  779. package/lib/dist/resolution/go-module.d.ts.map +1 -1
  780. package/lib/dist/resolution/go-module.js +21 -24
  781. package/lib/dist/resolution/go-module.js.map +1 -1
  782. package/lib/dist/resolution/go-stdlib-methods.d.ts +9 -0
  783. package/lib/dist/resolution/go-stdlib-methods.d.ts.map +1 -0
  784. package/lib/dist/resolution/go-stdlib-methods.js +224 -0
  785. package/lib/dist/resolution/go-stdlib-methods.js.map +1 -0
  786. package/lib/dist/resolution/goframe-synthesizer.js +2 -53
  787. package/lib/dist/resolution/goframe-synthesizer.js.map +1 -1
  788. package/lib/dist/resolution/import-resolver.d.ts +298 -23
  789. package/lib/dist/resolution/import-resolver.d.ts.map +1 -1
  790. package/lib/dist/resolution/import-resolver.js +1802 -1280
  791. package/lib/dist/resolution/import-resolver.js.map +1 -1
  792. package/lib/dist/resolution/index.d.ts +449 -5
  793. package/lib/dist/resolution/index.d.ts.map +1 -1
  794. package/lib/dist/resolution/index.js +1477 -981
  795. package/lib/dist/resolution/index.js.map +1 -1
  796. package/lib/dist/resolution/js-builtins.d.ts +14 -0
  797. package/lib/dist/resolution/js-builtins.d.ts.map +1 -1
  798. package/lib/dist/resolution/js-builtins.js +15 -13
  799. package/lib/dist/resolution/js-builtins.js.map +1 -1
  800. package/lib/dist/resolution/js-class-expressions.d.ts +48 -0
  801. package/lib/dist/resolution/js-class-expressions.d.ts.map +1 -0
  802. package/lib/dist/resolution/js-class-expressions.js +25 -0
  803. package/lib/dist/resolution/js-class-expressions.js.map +1 -0
  804. package/lib/dist/resolution/js-super-calls.d.ts +18 -0
  805. package/lib/dist/resolution/js-super-calls.d.ts.map +1 -0
  806. package/lib/dist/resolution/js-super-calls.js +94 -0
  807. package/lib/dist/resolution/js-super-calls.js.map +1 -0
  808. package/lib/dist/resolution/jsx-code.d.ts +28 -0
  809. package/lib/dist/resolution/jsx-code.d.ts.map +1 -0
  810. package/lib/dist/resolution/jsx-code.js +459 -0
  811. package/lib/dist/resolution/jsx-code.js.map +1 -0
  812. package/lib/dist/resolution/lru-cache.d.ts +5 -13
  813. package/lib/dist/resolution/lru-cache.d.ts.map +1 -1
  814. package/lib/dist/resolution/lru-cache.js +43 -32
  815. package/lib/dist/resolution/lru-cache.js.map +1 -1
  816. package/lib/dist/resolution/memory-budget.js +0 -52
  817. package/lib/dist/resolution/memory-budget.js.map +1 -1
  818. package/lib/dist/resolution/module-importers.d.ts +185 -0
  819. package/lib/dist/resolution/module-importers.d.ts.map +1 -0
  820. package/lib/dist/resolution/module-importers.js +588 -0
  821. package/lib/dist/resolution/module-importers.js.map +1 -0
  822. package/lib/dist/resolution/name-matcher.d.ts +891 -8
  823. package/lib/dist/resolution/name-matcher.d.ts.map +1 -1
  824. package/lib/dist/resolution/name-matcher.js +25013 -2928
  825. package/lib/dist/resolution/name-matcher.js.map +1 -1
  826. package/lib/dist/resolution/next-router-synthesizer.d.ts +19 -0
  827. package/lib/dist/resolution/next-router-synthesizer.d.ts.map +1 -1
  828. package/lib/dist/resolution/next-router-synthesizer.js +46 -28
  829. package/lib/dist/resolution/next-router-synthesizer.js.map +1 -1
  830. package/lib/dist/resolution/override-parameters.d.ts +40 -0
  831. package/lib/dist/resolution/override-parameters.d.ts.map +1 -0
  832. package/lib/dist/resolution/override-parameters.js +339 -0
  833. package/lib/dist/resolution/override-parameters.js.map +1 -0
  834. package/lib/dist/resolution/parameter-flow.d.ts +218 -0
  835. package/lib/dist/resolution/parameter-flow.d.ts.map +1 -0
  836. package/lib/dist/resolution/parameter-flow.js +474 -0
  837. package/lib/dist/resolution/parameter-flow.js.map +1 -0
  838. package/lib/dist/resolution/pascal-scope.d.ts +91 -0
  839. package/lib/dist/resolution/pascal-scope.d.ts.map +1 -0
  840. package/lib/dist/resolution/pascal-scope.js +961 -0
  841. package/lib/dist/resolution/pascal-scope.js.map +1 -0
  842. package/lib/dist/resolution/path-aliases.d.ts +32 -4
  843. package/lib/dist/resolution/path-aliases.d.ts.map +1 -1
  844. package/lib/dist/resolution/path-aliases.js +43 -110
  845. package/lib/dist/resolution/path-aliases.js.map +1 -1
  846. package/lib/dist/resolution/project-scans.d.ts +38 -0
  847. package/lib/dist/resolution/project-scans.d.ts.map +1 -0
  848. package/lib/dist/resolution/project-scans.js +30 -0
  849. package/lib/dist/resolution/project-scans.js.map +1 -0
  850. package/lib/dist/resolution/react-router-synthesizer.d.ts +2 -0
  851. package/lib/dist/resolution/react-router-synthesizer.d.ts.map +1 -1
  852. package/lib/dist/resolution/react-router-synthesizer.js +67 -48
  853. package/lib/dist/resolution/react-router-synthesizer.js.map +1 -1
  854. package/lib/dist/resolution/resolver-pool.d.ts +43 -3
  855. package/lib/dist/resolution/resolver-pool.d.ts.map +1 -1
  856. package/lib/dist/resolution/resolver-pool.js +55 -97
  857. package/lib/dist/resolution/resolver-pool.js.map +1 -1
  858. package/lib/dist/resolution/resolver-worker.d.ts +1 -1
  859. package/lib/dist/resolution/resolver-worker.d.ts.map +1 -1
  860. package/lib/dist/resolution/resolver-worker.js +10 -36
  861. package/lib/dist/resolution/resolver-worker.js.map +1 -1
  862. package/lib/dist/resolution/resurrect-ref.d.ts +25 -0
  863. package/lib/dist/resolution/resurrect-ref.d.ts.map +1 -0
  864. package/lib/dist/resolution/resurrect-ref.js +19 -0
  865. package/lib/dist/resolution/resurrect-ref.js.map +1 -0
  866. package/lib/dist/resolution/ruby-constant-paths.d.ts +56 -0
  867. package/lib/dist/resolution/ruby-constant-paths.d.ts.map +1 -0
  868. package/lib/dist/resolution/ruby-constant-paths.js +255 -0
  869. package/lib/dist/resolution/ruby-constant-paths.js.map +1 -0
  870. package/lib/dist/resolution/ruby-parameter-flow.d.ts +10 -0
  871. package/lib/dist/resolution/ruby-parameter-flow.d.ts.map +1 -0
  872. package/lib/dist/resolution/ruby-parameter-flow.js +801 -0
  873. package/lib/dist/resolution/ruby-parameter-flow.js.map +1 -0
  874. package/lib/dist/resolution/rust-scopes.d.ts +120 -0
  875. package/lib/dist/resolution/rust-scopes.d.ts.map +1 -0
  876. package/lib/dist/resolution/rust-scopes.js +730 -0
  877. package/lib/dist/resolution/rust-scopes.js.map +1 -0
  878. package/lib/dist/resolution/shopify-themes.d.ts +10 -0
  879. package/lib/dist/resolution/shopify-themes.d.ts.map +1 -0
  880. package/lib/dist/resolution/shopify-themes.js +19 -0
  881. package/lib/dist/resolution/shopify-themes.js.map +1 -0
  882. package/lib/dist/resolution/strip-comments.d.ts +20 -1
  883. package/lib/dist/resolution/strip-comments.d.ts.map +1 -1
  884. package/lib/dist/resolution/strip-comments.js +164 -119
  885. package/lib/dist/resolution/strip-comments.js.map +1 -1
  886. package/lib/dist/resolution/sveltekit-synthesizer.js +0 -64
  887. package/lib/dist/resolution/sveltekit-synthesizer.js.map +1 -1
  888. package/lib/dist/resolution/swift-objc-bridge.js +0 -160
  889. package/lib/dist/resolution/swift-objc-bridge.js.map +1 -1
  890. package/lib/dist/resolution/swift-type-visibility.d.ts +68 -0
  891. package/lib/dist/resolution/swift-type-visibility.d.ts.map +1 -0
  892. package/lib/dist/resolution/swift-type-visibility.js +355 -0
  893. package/lib/dist/resolution/swift-type-visibility.js.map +1 -0
  894. package/lib/dist/resolution/synth-utils.js +1 -22
  895. package/lib/dist/resolution/synth-utils.js.map +1 -1
  896. package/lib/dist/resolution/tanstack-router-synthesizer.js +0 -32
  897. package/lib/dist/resolution/tanstack-router-synthesizer.js.map +1 -1
  898. package/lib/dist/resolution/tauri-synthesizer.d.ts +37 -0
  899. package/lib/dist/resolution/tauri-synthesizer.d.ts.map +1 -0
  900. package/lib/dist/resolution/tauri-synthesizer.js +1038 -0
  901. package/lib/dist/resolution/tauri-synthesizer.js.map +1 -0
  902. package/lib/dist/resolution/tier-synthesizer.d.ts +7 -2
  903. package/lib/dist/resolution/tier-synthesizer.d.ts.map +1 -1
  904. package/lib/dist/resolution/tier-synthesizer.js +318 -121
  905. package/lib/dist/resolution/tier-synthesizer.js.map +1 -1
  906. package/lib/dist/resolution/type-parameters.d.ts +34 -0
  907. package/lib/dist/resolution/type-parameters.d.ts.map +1 -0
  908. package/lib/dist/resolution/type-parameters.js +285 -0
  909. package/lib/dist/resolution/type-parameters.js.map +1 -0
  910. package/lib/dist/resolution/types.d.ts +209 -10
  911. package/lib/dist/resolution/types.d.ts.map +1 -1
  912. package/lib/dist/resolution/types.js +0 -47
  913. package/lib/dist/resolution/types.js.map +1 -1
  914. package/lib/dist/resolution/vbnet-receivers.d.ts +92 -0
  915. package/lib/dist/resolution/vbnet-receivers.d.ts.map +1 -0
  916. package/lib/dist/resolution/vbnet-receivers.js +1482 -0
  917. package/lib/dist/resolution/vbnet-receivers.js.map +1 -0
  918. package/lib/dist/resolution/vue-router-synthesizer.js +0 -31
  919. package/lib/dist/resolution/vue-router-synthesizer.js.map +1 -1
  920. package/lib/dist/resolution/workspace-packages.d.ts +206 -15
  921. package/lib/dist/resolution/workspace-packages.d.ts.map +1 -1
  922. package/lib/dist/resolution/workspace-packages.js +570 -152
  923. package/lib/dist/resolution/workspace-packages.js.map +1 -1
  924. package/lib/dist/search/identifier-segments.js +2 -93
  925. package/lib/dist/search/identifier-segments.js.map +1 -1
  926. package/lib/dist/search/query-parser.js +0 -54
  927. package/lib/dist/search/query-parser.js.map +1 -1
  928. package/lib/dist/search/query-paths.js +0 -167
  929. package/lib/dist/search/query-paths.js.map +1 -1
  930. package/lib/dist/search/query-utils.d.ts +44 -0
  931. package/lib/dist/search/query-utils.d.ts.map +1 -1
  932. package/lib/dist/search/query-utils.js +120 -198
  933. package/lib/dist/search/query-utils.js.map +1 -1
  934. package/lib/dist/sync/git-hooks.d.ts +14 -5
  935. package/lib/dist/sync/git-hooks.d.ts.map +1 -1
  936. package/lib/dist/sync/git-hooks.js +118 -65
  937. package/lib/dist/sync/git-hooks.js.map +1 -1
  938. package/lib/dist/sync/index.js +0 -14
  939. package/lib/dist/sync/index.js.map +1 -1
  940. package/lib/dist/sync/watch-policy.js +0 -45
  941. package/lib/dist/sync/watch-policy.js.map +1 -1
  942. package/lib/dist/sync/watcher.d.ts +29 -11
  943. package/lib/dist/sync/watcher.d.ts.map +1 -1
  944. package/lib/dist/sync/watcher.js +83 -487
  945. package/lib/dist/sync/watcher.js.map +1 -1
  946. package/lib/dist/sync/worktree.d.ts +29 -2
  947. package/lib/dist/sync/worktree.d.ts.map +1 -1
  948. package/lib/dist/sync/worktree.js +59 -78
  949. package/lib/dist/sync/worktree.js.map +1 -1
  950. package/lib/dist/telemetry/index.d.ts.map +1 -1
  951. package/lib/dist/telemetry/index.js +68 -146
  952. package/lib/dist/telemetry/index.js.map +1 -1
  953. package/lib/dist/types.d.ts +46 -0
  954. package/lib/dist/types.d.ts.map +1 -1
  955. package/lib/dist/types.js +15 -44
  956. package/lib/dist/types.js.map +1 -1
  957. package/lib/dist/ui/color.js +0 -19
  958. package/lib/dist/ui/color.js.map +1 -1
  959. package/lib/dist/ui/glyphs.js +2 -45
  960. package/lib/dist/ui/glyphs.js.map +1 -1
  961. package/lib/dist/ui/shimmer-progress.js +0 -21
  962. package/lib/dist/ui/shimmer-progress.js.map +1 -1
  963. package/lib/dist/ui/shimmer-worker.js +0 -22
  964. package/lib/dist/ui/shimmer-worker.js.map +1 -1
  965. package/lib/dist/ui-server/api/deadcode.d.ts.map +1 -1
  966. package/lib/dist/ui-server/api/deadcode.js +2 -31
  967. package/lib/dist/ui-server/api/deadcode.js.map +1 -1
  968. package/lib/dist/ui-server/api/effects.d.ts +7 -0
  969. package/lib/dist/ui-server/api/effects.d.ts.map +1 -1
  970. package/lib/dist/ui-server/api/effects.js +20 -103
  971. package/lib/dist/ui-server/api/effects.js.map +1 -1
  972. package/lib/dist/ui-server/api/entrypoints.d.ts +6 -0
  973. package/lib/dist/ui-server/api/entrypoints.d.ts.map +1 -1
  974. package/lib/dist/ui-server/api/entrypoints.js +73 -130
  975. package/lib/dist/ui-server/api/entrypoints.js.map +1 -1
  976. package/lib/dist/ui-server/api/events.js +0 -145
  977. package/lib/dist/ui-server/api/events.js.map +1 -1
  978. package/lib/dist/ui-server/api/file.js +0 -80
  979. package/lib/dist/ui-server/api/file.js.map +1 -1
  980. package/lib/dist/ui-server/api/filecode.js +0 -95
  981. package/lib/dist/ui-server/api/filecode.js.map +1 -1
  982. package/lib/dist/ui-server/api/flow.js +0 -149
  983. package/lib/dist/ui-server/api/flow.js.map +1 -1
  984. package/lib/dist/ui-server/api/hierarchy.js +0 -28
  985. package/lib/dist/ui-server/api/hierarchy.js.map +1 -1
  986. package/lib/dist/ui-server/api/index.js +0 -88
  987. package/lib/dist/ui-server/api/index.js.map +1 -1
  988. package/lib/dist/ui-server/api/map.d.ts +41 -6
  989. package/lib/dist/ui-server/api/map.d.ts.map +1 -1
  990. package/lib/dist/ui-server/api/map.js +95 -308
  991. package/lib/dist/ui-server/api/map.js.map +1 -1
  992. package/lib/dist/ui-server/api/node.d.ts.map +1 -1
  993. package/lib/dist/ui-server/api/node.js +4 -109
  994. package/lib/dist/ui-server/api/node.js.map +1 -1
  995. package/lib/dist/ui-server/api/nodes.js +0 -16
  996. package/lib/dist/ui-server/api/nodes.js.map +1 -1
  997. package/lib/dist/ui-server/api/program.js +0 -90
  998. package/lib/dist/ui-server/api/program.js.map +1 -1
  999. package/lib/dist/ui-server/api/respond.js +0 -60
  1000. package/lib/dist/ui-server/api/respond.js.map +1 -1
  1001. package/lib/dist/ui-server/api/route-roots.d.ts +6 -0
  1002. package/lib/dist/ui-server/api/route-roots.d.ts.map +1 -1
  1003. package/lib/dist/ui-server/api/route-roots.js +18 -39
  1004. package/lib/dist/ui-server/api/route-roots.js.map +1 -1
  1005. package/lib/dist/ui-server/api/routes.d.ts +2 -0
  1006. package/lib/dist/ui-server/api/routes.d.ts.map +1 -1
  1007. package/lib/dist/ui-server/api/routes.js +47 -47
  1008. package/lib/dist/ui-server/api/routes.js.map +1 -1
  1009. package/lib/dist/ui-server/api/screens.d.ts.map +1 -1
  1010. package/lib/dist/ui-server/api/screens.js +16 -171
  1011. package/lib/dist/ui-server/api/screens.js.map +1 -1
  1012. package/lib/dist/ui-server/api/search.js +0 -62
  1013. package/lib/dist/ui-server/api/search.js.map +1 -1
  1014. package/lib/dist/ui-server/api/session.js +0 -58
  1015. package/lib/dist/ui-server/api/session.js.map +1 -1
  1016. package/lib/dist/ui-server/api/source.d.ts.map +1 -1
  1017. package/lib/dist/ui-server/api/source.js +0 -161
  1018. package/lib/dist/ui-server/api/source.js.map +1 -1
  1019. package/lib/dist/ui-server/api/stats.js +0 -58
  1020. package/lib/dist/ui-server/api/stats.js.map +1 -1
  1021. package/lib/dist/ui-server/api/steps.d.ts.map +1 -1
  1022. package/lib/dist/ui-server/api/steps.js +105 -373
  1023. package/lib/dist/ui-server/api/steps.js.map +1 -1
  1024. package/lib/dist/ui-server/api/trail-store.d.ts +3 -3
  1025. package/lib/dist/ui-server/api/trail-store.d.ts.map +1 -1
  1026. package/lib/dist/ui-server/api/trail-store.js +24 -106
  1027. package/lib/dist/ui-server/api/trail-store.js.map +1 -1
  1028. package/lib/dist/ui-server/api/trails.d.ts.map +1 -1
  1029. package/lib/dist/ui-server/api/trails.js +20 -94
  1030. package/lib/dist/ui-server/api/trails.js.map +1 -1
  1031. package/lib/dist/ui-server/api/when.d.ts +10 -2
  1032. package/lib/dist/ui-server/api/when.d.ts.map +1 -1
  1033. package/lib/dist/ui-server/api/when.js +32 -44
  1034. package/lib/dist/ui-server/api/when.js.map +1 -1
  1035. package/lib/dist/ui-server/api/wire.js +0 -58
  1036. package/lib/dist/ui-server/api/wire.js.map +1 -1
  1037. package/lib/dist/ui-server/assets.js +0 -35
  1038. package/lib/dist/ui-server/assets.js.map +1 -1
  1039. package/lib/dist/ui-server/constants.js +0 -26
  1040. package/lib/dist/ui-server/constants.js.map +1 -1
  1041. package/lib/dist/ui-server/highlight/bounded-tokenize.d.ts +28 -0
  1042. package/lib/dist/ui-server/highlight/bounded-tokenize.d.ts.map +1 -0
  1043. package/lib/dist/ui-server/highlight/bounded-tokenize.js +114 -0
  1044. package/lib/dist/ui-server/highlight/bounded-tokenize.js.map +1 -0
  1045. package/lib/dist/ui-server/highlight/index.d.ts.map +1 -1
  1046. package/lib/dist/ui-server/highlight/index.js +7 -133
  1047. package/lib/dist/ui-server/highlight/index.js.map +1 -1
  1048. package/lib/dist/ui-server/highlight/languages.d.ts +3 -3
  1049. package/lib/dist/ui-server/highlight/languages.js +0 -31
  1050. package/lib/dist/ui-server/highlight/languages.js.map +1 -1
  1051. package/lib/dist/ui-server/highlight/tokenize-worker.d.ts +7 -0
  1052. package/lib/dist/ui-server/highlight/tokenize-worker.d.ts.map +1 -0
  1053. package/lib/dist/ui-server/highlight/tokenize-worker.js +15 -0
  1054. package/lib/dist/ui-server/highlight/tokenize-worker.js.map +1 -0
  1055. package/lib/dist/ui-server/index.d.ts +25 -0
  1056. package/lib/dist/ui-server/index.d.ts.map +1 -1
  1057. package/lib/dist/ui-server/index.js +35 -103
  1058. package/lib/dist/ui-server/index.js.map +1 -1
  1059. package/lib/dist/ui-server/open-browser.js +0 -34
  1060. package/lib/dist/ui-server/open-browser.js.map +1 -1
  1061. package/lib/dist/ui-server/security.d.ts +5 -0
  1062. package/lib/dist/ui-server/security.d.ts.map +1 -1
  1063. package/lib/dist/ui-server/security.js +11 -147
  1064. package/lib/dist/ui-server/security.js.map +1 -1
  1065. package/lib/dist/ui-server/static.js +0 -41
  1066. package/lib/dist/ui-server/static.js.map +1 -1
  1067. package/lib/dist/upgrade/index.d.ts +61 -10
  1068. package/lib/dist/upgrade/index.d.ts.map +1 -1
  1069. package/lib/dist/upgrade/index.js +191 -225
  1070. package/lib/dist/upgrade/index.js.map +1 -1
  1071. package/lib/dist/upgrade/remove-binary.js +2 -67
  1072. package/lib/dist/upgrade/remove-binary.js.map +1 -1
  1073. package/lib/dist/upgrade/update-check.js +1 -81
  1074. package/lib/dist/upgrade/update-check.js.map +1 -1
  1075. package/lib/dist/utils.d.ts +69 -1
  1076. package/lib/dist/utils.d.ts.map +1 -1
  1077. package/lib/dist/utils.js +224 -266
  1078. package/lib/dist/utils.js.map +1 -1
  1079. package/lib/dist/viewer/assets/{index-D4S7YUPf.js → index-BSGpxBr9.js} +60 -58
  1080. package/lib/dist/viewer/index.html +1 -1
  1081. package/lib/dist/worker-teardown.d.ts +48 -0
  1082. package/lib/dist/worker-teardown.d.ts.map +1 -0
  1083. package/lib/dist/worker-teardown.js +53 -0
  1084. package/lib/dist/worker-teardown.js.map +1 -0
  1085. package/lib/kernel/codegraph-kernel.node +2 -2
  1086. package/lib/node_modules/.package-lock.json +4 -4
  1087. package/lib/node_modules/ignore/README.md +138 -8
  1088. package/lib/node_modules/ignore/index.d.ts +56 -20
  1089. package/lib/node_modules/ignore/index.js +1033 -221
  1090. package/lib/node_modules/ignore/legacy.js +871 -178
  1091. package/lib/node_modules/ignore/package.json +10 -4
  1092. package/lib/package.json +14 -8
  1093. package/node.exe +2 -2
  1094. package/package.json +1 -1
@@ -1,95 +1,38 @@
1
1
  "use strict";
2
- /**
3
- * Database Queries
4
- *
5
- * Prepared statements for CRUD operations on the knowledge graph.
6
- */
7
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.QueryBuilder = exports.DEPRIORITIZED_NAME_BONUS_SCALE = void 0;
3
+ exports.QueryBuilder = exports.DOMINANT_FILE_SQL = exports.DEPRIORITIZED_NAME_BONUS_SCALE = void 0;
9
4
  const utils_1 = require("../utils");
10
5
  const query_utils_1 = require("../search/query-utils");
11
6
  const query_parser_1 = require("../search/query-parser");
12
7
  const generated_detection_1 = require("../extraction/generated-detection");
13
8
  const identifier_segments_1 = require("../search/identifier-segments");
14
- /**
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).
24
- */
9
+ const reference_tail_1 = require("./reference-tail");
10
+ const parameter_flow_queries_1 = require("./parameter-flow-queries");
11
+ const name_substring_index_1 = require("./name-substring-index");
25
12
  function isLowValueFile(filePath, generated) {
26
13
  if (generated?.has(filePath))
27
14
  return true;
28
- const lp = filePath.toLowerCase();
29
- return (/(?:^|\/)(tests?|__tests?__|spec)\//.test(lp) ||
30
- /_test\.go$/.test(lp) ||
31
- /(?:^|\/)test_[^/]+\.py$/.test(lp) ||
32
- /_test\.py$/.test(lp) ||
33
- /_spec\.rb$/.test(lp) ||
34
- /_test\.rb$/.test(lp) ||
35
- /\.(test|spec)\.[jt]sx?$/.test(lp) ||
36
- /(test|spec|tests)\.(java|kt|scala)$/.test(lp) ||
37
- /(tests?|spec)\.cs$/.test(lp) ||
38
- /tests?\.swift$/.test(lp) ||
39
- /_test\.dart$/.test(lp) ||
40
- (0, generated_detection_1.isGeneratedFile)(filePath));
15
+ return (0, query_utils_1.isTestFile)(filePath) || /(?:^|\/)__test__\//i.test(filePath) || (0, generated_detection_1.isGeneratedFile)(filePath);
41
16
  }
42
17
  const SQLITE_PARAM_CHUNK_SIZE = 500;
43
- /**
44
- * A SQL predicate: is the node aliased `alias` a member an INTERFACE declares?
45
- *
46
- * `method_signature` / `property_signature` enter the graph as `method` /
47
- * `property` nodes hung off their interface by a `contains` edge (#1638). They
48
- * have no body and originate no behaviour, so for a structural judgement about
49
- * a FILE they are the interface restated, not an extra thing the file declares.
50
- * See {@link QueryBuilder.getAmbientDeclarationPathsAmong}, the one caller, for
51
- * why treating them as opaque would break that rule in three places at once.
52
- *
53
- * Seeks `idx_edges_target_kind`, so it costs a key lookup per row rather than a
54
- * join over the whole edge table.
55
- */
18
+ const FOLDER_SPECIFIERS = (() => {
19
+ const names = ['.', './'];
20
+ for (let levels = 1; levels <= 12; levels++) {
21
+ const up = Array.from({ length: levels }, () => '..').join('/');
22
+ names.push(up, `${up}/`);
23
+ }
24
+ return names;
25
+ })();
26
+ const RECEIVER_NAME = /^[A-Za-z_$][\w$]*$/;
56
27
  const IS_INTERFACE_MEMBER = (alias) => `EXISTS (
57
28
  SELECT 1 FROM edges ce JOIN nodes owner ON owner.id = ce.source
58
29
  WHERE ce.target = ${alias}.id AND ce.kind = 'contains' AND owner.kind = 'interface'
59
30
  )`;
60
- /**
61
- * How much of the exact-name bonus a `deprioritize`d path keeps (#982). Damped
62
- * rather than zeroed: a query that genuinely targets that tree must still rank
63
- * it, the same "discount, don't erase" rule the path penalty follows.
64
- *
65
- * Derived rather than picked. `nameMatchBonus`'s prefix arm tops out below
66
- * `10 + 30 = 40`, and a de-prioritized node also takes the -15 path penalty, so
67
- * `80 * SCALE - 15 > 40` is what stops a damped WHOLE-QUERY exact match from
68
- * losing to a mere prefix match. 0.75 clears it (45). Measured on a 62k-node
69
- * django index: at 0.25 that invariant breaks in practice — `child`, `parent`
70
- * and `method` lose rank 1 to `children`, `all_parents` and `method_decorator`
71
- * — while crowd-out removal is almost flat between 0.75 and 0.5 (39 vs 40 of 88
72
- * peripheral top-10 slots cleared), so a deeper discount buys little and costs
73
- * the invariant. Pinned by a test.
74
- */
31
+ const THROUGH_NAMES = (column) => `(
32
+ ${column} IN (SELECT value FROM json_each(?))
33
+ OR (instr(${column}, '.') > 1 AND substr(${column}, 1, instr(${column}, '.') - 1) IN (SELECT value FROM json_each(?)))
34
+ )`;
75
35
  exports.DEPRIORITIZED_NAME_BONUS_SCALE = 0.75;
76
- /**
77
- * Last segment of a (possibly dotted/qualified) reference name — the part a
78
- * new symbol's plain node name could match: 'util.greet' → 'greet',
79
- * 'mod::fn' → 'fn', 'greet' → 'greet'. Written to unresolved_refs.name_tail
80
- * when a ref is marked failed, so the #1240 retry lookup can match dotted
81
- * refs against newly-added node names.
82
- */
83
- function referenceNameTail(referenceName) {
84
- // Erlang refs carry a written arity (`f/1`, `mod::fn/2` — #1610); the tail a
85
- // new symbol's plain name could match is the arity-less function name.
86
- const base = referenceName.replace(/\/\d{1,3}$/, '') || referenceName;
87
- const idx = Math.max(base.lastIndexOf('.'), base.lastIndexOf(':'));
88
- return idx >= 0 ? base.slice(idx + 1) : base;
89
- }
90
- /**
91
- * Convert database row to Node object
92
- */
93
36
  function rowToNode(row) {
94
37
  return {
95
38
  id: row.id,
@@ -115,9 +58,112 @@ function rowToNode(row) {
115
58
  updatedAt: row.updated_at,
116
59
  };
117
60
  }
118
- /**
119
- * Convert database row to Edge object
120
- */
61
+ function arrayToNode(columns) {
62
+ const at = (column) => columns.indexOf(column);
63
+ const id = at('id');
64
+ const kind = at('kind');
65
+ const name = at('name');
66
+ const qualifiedName = at('qualified_name');
67
+ const filePath = at('file_path');
68
+ const language = at('language');
69
+ const startLine = at('start_line');
70
+ const endLine = at('end_line');
71
+ const startColumn = at('start_column');
72
+ const endColumn = at('end_column');
73
+ const docstring = at('docstring');
74
+ const signature = at('signature');
75
+ const visibility = at('visibility');
76
+ const isExported = at('is_exported');
77
+ const isAsync = at('is_async');
78
+ const isStatic = at('is_static');
79
+ const isAbstract = at('is_abstract');
80
+ const decorators = at('decorators');
81
+ const typeParameters = at('type_parameters');
82
+ const returnType = at('return_type');
83
+ const updatedAt = at('updated_at');
84
+ return (row) => ({
85
+ id: row[id],
86
+ kind: row[kind],
87
+ name: row[name],
88
+ qualifiedName: row[qualifiedName],
89
+ filePath: row[filePath],
90
+ language: row[language],
91
+ startLine: row[startLine],
92
+ endLine: row[endLine],
93
+ startColumn: row[startColumn],
94
+ endColumn: row[endColumn],
95
+ docstring: (row[docstring] ?? undefined),
96
+ signature: (row[signature] ?? undefined),
97
+ visibility: row[visibility],
98
+ isExported: row[isExported] === 1,
99
+ isAsync: row[isAsync] === 1,
100
+ isStatic: row[isStatic] === 1,
101
+ isAbstract: row[isAbstract] === 1,
102
+ decorators: row[decorators] ? (0, utils_1.safeJsonParse)(row[decorators], undefined) : undefined,
103
+ typeParameters: row[typeParameters] ? (0, utils_1.safeJsonParse)(row[typeParameters], undefined) : undefined,
104
+ returnType: (row[returnType] ?? undefined),
105
+ updatedAt: row[updatedAt],
106
+ });
107
+ }
108
+ function prepareNodeStatement(db, sql) {
109
+ const stmt = db.prepare(sql);
110
+ const columns = stmt.rowsAsArrays();
111
+ const toNode = (columns ? arrayToNode(columns) : rowToNode);
112
+ return {
113
+ all: (...params) => stmt.all(...params).map(toNode),
114
+ get: (...params) => {
115
+ const row = stmt.get(...params);
116
+ return row === undefined ? undefined : toNode(row);
117
+ },
118
+ *iterate(...params) {
119
+ for (const row of stmt.iterate(...params))
120
+ yield toNode(row);
121
+ },
122
+ };
123
+ }
124
+ function fieldFiltersOf(parsed) {
125
+ if (parsed.pathFilters.length === 0 && parsed.nameFilters.length === 0)
126
+ return undefined;
127
+ return {
128
+ paths: parsed.pathFilters.map((p) => p.toLowerCase()),
129
+ names: parsed.nameFilters.map((n) => n.toLowerCase()),
130
+ };
131
+ }
132
+ function passesNameFilters(name, filters) {
133
+ if (filters.names.length === 0)
134
+ return true;
135
+ const lowered = name.toLowerCase();
136
+ return filters.names.some((n) => lowered.includes(n));
137
+ }
138
+ function passesFieldFilters(name, filePath, filters) {
139
+ if (filters.paths.length > 0) {
140
+ const lowered = filePath.toLowerCase();
141
+ if (!filters.paths.some((p) => lowered.includes(p)))
142
+ return false;
143
+ }
144
+ return passesNameFilters(name, filters);
145
+ }
146
+ const PRINTABLE_ASCII = /^[ -~]*$/;
147
+ function fieldFilterSql(filters, params) {
148
+ let sql = '';
149
+ for (const [column, values] of [['nodes.file_path', filters.paths], ['nodes.name', filters.names]]) {
150
+ if (values.length === 0)
151
+ continue;
152
+ const terms = [];
153
+ for (const value of values) {
154
+ if (!PRINTABLE_ASCII.test(value))
155
+ continue;
156
+ terms.push(`instr(lower(${column}), ?) > 0`);
157
+ params.push(value);
158
+ }
159
+ terms.push(`${column} GLOB '*[^ -~]*'`);
160
+ sql += ` AND (${terms.join(' OR ')})`;
161
+ }
162
+ return sql;
163
+ }
164
+ const FAILED_PY_ATTR_REF = `status = 'failed' AND language = 'python'
165
+ AND reference_name NOT GLOB '*.*.*.*'
166
+ AND (reference_name GLOB '*.*.*' OR reference_name GLOB '*().*')`;
121
167
  function rowToEdge(row) {
122
168
  return {
123
169
  source: row.source,
@@ -129,9 +175,6 @@ function rowToEdge(row) {
129
175
  provenance: row.provenance,
130
176
  };
131
177
  }
132
- /**
133
- * Convert database row to FileRecord object
134
- */
135
178
  function rowToFileRecord(row) {
136
179
  return {
137
180
  path: row.path,
@@ -145,52 +188,32 @@ function rowToFileRecord(row) {
145
188
  generated: row.generated === 1,
146
189
  };
147
190
  }
148
- /**
149
- * Query builder for the knowledge graph database
150
- */
191
+ exports.DOMINANT_FILE_SQL = `
192
+ SELECT n.file_path AS file_path, COUNT(*) AS edge_count
193
+ FROM edges e
194
+ CROSS JOIN nodes n ON e.source = n.id
195
+ CROSS JOIN nodes m ON e.target = m.id
196
+ WHERE n.file_path = m.file_path
197
+ GROUP BY n.file_path
198
+ ORDER BY edge_count DESC, n.file_path
199
+ `;
200
+ const DOMINANT_FILE_BATCH = 20;
151
201
  class QueryBuilder {
152
202
  db;
153
- // Project-name tokens (go.mod / package.json / repo dir), normalized. A query
154
- // word matching one is dropped from path-relevance scoring — it names the
155
- // whole project, not a symbol, so it carries no discriminative signal (#720).
156
- // Set once by the CodeGraph instance; empty by default (no down-weighting).
157
203
  projectNameTokens = new Set();
158
204
  isDeprioritizedPath;
159
- // FTS5 availability flag — detected once at construction time (#1532)
160
205
  _fts5Available;
161
- // Node cache for frequently accessed nodes (LRU-style, max 1000 entries)
162
206
  nodeCache = new Map();
163
207
  maxCacheSize = 1000;
164
- // getDominantFile()'s answer, tagged with the database change stamp it was
165
- // computed under (see getChangeStamp). Query-independent, so one value
166
- // serves every explore until the database changes (#1864).
167
208
  dominantFileMemo;
168
- // Prepared statements (lazily initialized)
209
+ readMemos = new Map();
210
+ flowQueries;
169
211
  stmts = {};
170
- // Names whose segments were already written this session — skips re-splitting
171
- // and re-inserting for the same-named nodes that repeat across files ("get",
172
- // "render", …). Purely a write-path fast path; INSERT OR IGNORE is the
173
- // correctness backstop. Bounded so a pathological repo can't grow it forever.
174
212
  segmentedNames = new Set();
175
213
  static MAX_SEGMENTED_NAMES = 65536;
176
- // Multi-row INSERT statements, cached per (statement kind × row count). The
177
- // bulk write path decomposes N rows into a few fixed batch sizes so each
178
- // size's statement is prepared once and reused — one .run() binds a whole
179
- // chunk instead of one row, which is where the per-call overhead lives.
180
- // Row order within and across chunks is the input order, so rowid assignment
181
- // (and therefore resolution's insertion-order disambiguation) is identical
182
- // to the one-row-per-run path.
183
214
  batchStmts = new Map();
184
- // Kind-filtered edge reads build their SQL per call (a variable IN list),
185
- // but from a handful of kind sets: prepare each shape once. Supertype walks
186
- // and the member-lookup passes issue them per node, and preparing cost
187
- // about a third of the read.
188
215
  edgeKindStmts = new Map();
189
216
  static BATCH_SIZES = [128, 32, 8, 1];
190
- /**
191
- * Run `rows` through a multi-row `INSERT` built as `head + (tuple,)*n`,
192
- * decomposed greedily into the cached batch sizes. Preserves row order.
193
- */
194
217
  runBatched(kind, head, tuple, rows) {
195
218
  if (rows.length === 0)
196
219
  return;
@@ -221,7 +244,6 @@ class QueryBuilder {
221
244
  }
222
245
  constructor(db) {
223
246
  this.db = db;
224
- // Detect FTS5 availability once (#1532)
225
247
  try {
226
248
  db.prepare("SELECT * FROM nodes_fts LIMIT 0").get();
227
249
  this._fts5Available = true;
@@ -230,27 +252,40 @@ class QueryBuilder {
230
252
  this._fts5Available = false;
231
253
  }
232
254
  }
233
- /**
234
- * Swap the underlying connection in place. Used by pool workers'
235
- * connection recycling (plan §7a.6, writes-under-readers): a long-lived
236
- * read connection pins WAL checkpoint progress, and the deep WAL that
237
- * accumulates behind it taxes every main-thread B-tree page operation
238
- * (deletes measured 42.6s → 118.8s from 0 to 4 attached readers on
239
- * identical hardware). Workers therefore close and reopen their read-only
240
- * connection at the pool-idle boundary; everything above the connection —
241
- * this QueryBuilder, the resolver and its warm caches — survives, and only
242
- * connection-derived state (prepared statements) resets, re-preparing
243
- * lazily on next use.
244
- */
245
255
  rebind(db) {
246
256
  this.db = db;
247
257
  this.stmts = {};
248
258
  this.batchStmts.clear();
249
259
  this.edgeKindStmts.clear();
250
- // The change stamp is per connection, and fresh connections to two
251
- // different databases report the same one — the memo goes with the old
252
- // connection, or a worker following a rebuilt index keeps its answer (#1864).
260
+ this.flowQueries = undefined;
253
261
  this.dominantFileMemo = undefined;
262
+ this.readMemos.clear();
263
+ this.presentSchema.clear();
264
+ }
265
+ presentSchema = new Set();
266
+ hasSchema(table, column) {
267
+ const key = column ? `${table}.${column}` : table;
268
+ if (this.presentSchema.has(key))
269
+ return true;
270
+ const found = column
271
+ ? this.db.prepare('SELECT 1 FROM pragma_table_info(?) WHERE name = ?').get(table, column) !== undefined
272
+ : this.db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) !== undefined;
273
+ if (found)
274
+ this.presentSchema.add(key);
275
+ return found;
276
+ }
277
+ memoizedRead(key, compute) {
278
+ if (this.db.inTransaction !== false) {
279
+ this.readMemos.delete(key);
280
+ return null;
281
+ }
282
+ const stamp = this.getChangeStamp();
283
+ const memo = this.readMemos.get(key);
284
+ if (memo?.stamp === stamp)
285
+ return memo.value;
286
+ const value = compute();
287
+ this.readMemos.set(key, { stamp, value });
288
+ return value;
254
289
  }
255
290
  edgeKindStmt(sql) {
256
291
  let stmt = this.edgeKindStmts.get(sql);
@@ -262,34 +297,22 @@ class QueryBuilder {
262
297
  }
263
298
  return stmt;
264
299
  }
265
- /** Set the normalized project-name tokens used to down-weight non-discriminative
266
- * query words in path scoring (#720). Called once when the project opens. */
267
300
  setProjectNameTokens(tokens) {
268
301
  this.projectNameTokens = tokens;
269
302
  }
270
- /** The normalized project-name tokens (#720); empty if none were derived. */
271
303
  getProjectNameTokens() {
272
304
  return this.projectNameTokens;
273
305
  }
274
- /**
275
- * Set the predicate that marks a path as de-prioritized by the project's
276
- * `codegraph.json` `deprioritize` patterns (#982). Ranking-only: those paths
277
- * stay indexed and findable, they just stop outranking first-party code.
278
- * Called once when the project opens; undefined disables the lever.
279
- */
280
306
  setDeprioritizedPathMatcher(matcher) {
281
307
  this.isDeprioritizedPath = matcher;
282
308
  }
283
- /** The `deprioritize` predicate (#982), so other rankers apply the same lever. */
284
309
  getDeprioritizedPathMatcher() {
285
310
  return this.isDeprioritizedPath;
286
311
  }
287
- // ===========================================================================
288
- // Node Operations
289
- // ===========================================================================
290
- /**
291
- * Insert a new node
292
- */
312
+ getDeprioritizedPathSnapshot() {
313
+ const matcher = this.isDeprioritizedPath;
314
+ return matcher?.snapshot ? matcher.snapshot() : matcher;
315
+ }
293
316
  insertNode(node) {
294
317
  if (!this.stmts.insertNode) {
295
318
  this.stmts.insertNode = this.db.prepare(`
@@ -308,7 +331,6 @@ class QueryBuilder {
308
331
  )
309
332
  `);
310
333
  }
311
- // Validate required fields to prevent SQLite bind errors
312
334
  if (!node.id || !node.kind || !node.name || !node.filePath || !node.language) {
313
335
  console.error('[CodeGraph] Skipping node with missing required fields:', {
314
336
  id: node.id,
@@ -319,10 +341,6 @@ class QueryBuilder {
319
341
  });
320
342
  return;
321
343
  }
322
- // INSERT OR REPLACE may overwrite a node we have cached. Drop the
323
- // stale entry so the next getNodeById sees the new row, not the old
324
- // one (matches the cache-invalidation pattern used by updateNode and
325
- // deleteNode below).
326
344
  this.nodeCache.delete(node.id);
327
345
  this.stmts.insertNode.run({
328
346
  id: node.id,
@@ -347,40 +365,19 @@ class QueryBuilder {
347
365
  returnType: node.returnType ?? null,
348
366
  updatedAt: node.updatedAt ?? Date.now(),
349
367
  });
350
- // Segment vocabulary rides the same write path (and transaction) so it can
351
- // never drift ahead of the nodes it describes. Deletes intentionally leave
352
- // orphans behind — vocab rows are proposals re-verified against nodes
353
- // before use, and a full index clears the table at its start. File nodes
354
- // are excluded: a file's basename duplicates the symbols inside it
355
- // (state-machine.ts / OrderStateMachine), which double-counts every
356
- // concept and defeats the singleton-vs-cluster rarity statistics. Import
357
- // nodes are excluded too (#1144): they're named after module specifiers
358
- // ("external-unindexed-pkg", "./utils/helpers"), not symbols — an
359
- // import-only name can never be surfaced (getSegmentMatches requires a
360
- // real definition), so its rows would only inflate the rarity statistics.
361
368
  if (this.isSegmentableKind(node.kind))
362
369
  this.insertNameSegments(node.name);
363
370
  }
364
- /** Which node kinds contribute their name to the segment vocabulary — the
365
- * single gate shared by insertNode, updateNode, and the rebuild page query
366
- * (getDistinctNodeNames), so the write paths can't drift apart. */
367
371
  isSegmentableKind(kind) {
368
372
  return kind !== 'file' && kind !== 'import';
369
373
  }
370
- /** Write `name`'s segments into name_segment_vocab (idempotent). */
371
374
  insertNameSegments(name) {
372
375
  const rows = [];
373
376
  this.collectNameSegmentRows(name, rows);
374
377
  this.runBatched('insertNameSegments', 'INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES ', '(?,?)', rows);
375
378
  }
376
- /**
377
- * Insert multiple nodes in a transaction
378
- */
379
379
  insertNodes(nodes) {
380
380
  this.db.transaction(() => {
381
- // Bulk path: same semantics as insertNode() per row (validation, cache
382
- // invalidation, segment vocab), but bound as multi-row INSERTs — the
383
- // per-.run() call overhead dominates the store phase on full indexes.
384
381
  const rows = [];
385
382
  const segmentRows = [];
386
383
  for (const node of nodes) {
@@ -431,17 +428,9 @@ class QueryBuilder {
431
428
  this.runBatched('insertNameSegments', 'INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES ', '(?,?)', segmentRows);
432
429
  })();
433
430
  }
434
- /**
435
- * Store one file's whole extraction bundle — nodes, edges, unresolved refs,
436
- * and the file record — in a SINGLE transaction. The bulk-index path calls
437
- * this once per file instead of opening one transaction per table (#1015
438
- * file-order commit discipline is unchanged: callers still invoke it in file
439
- * order, and row order within is input order).
440
- *
441
- * Edges MUST already be endpoint-filtered by the caller (the store path
442
- * filters to the file's own inserted node ids), so the per-file existence
443
- * SELECT that insertEdges() pays is skipped here.
444
- */
431
+ runInTransaction(fn) {
432
+ return this.db.transaction(fn)();
433
+ }
445
434
  storeFileBundle(bundle) {
446
435
  this.db.transaction(() => {
447
436
  this.insertNodes(bundle.nodes);
@@ -465,10 +454,6 @@ class QueryBuilder {
465
454
  this.upsertFile(bundle.file);
466
455
  })();
467
456
  }
468
- /**
469
- * Collect (segment, name) rows for a name, honouring the same session-dedupe
470
- * semantics as insertNameSegments(). Shared by the bulk write paths.
471
- */
472
457
  collectNameSegmentRows(name, out) {
473
458
  if (this.segmentedNames.has(name))
474
459
  return;
@@ -478,9 +463,6 @@ class QueryBuilder {
478
463
  for (const segment of (0, identifier_segments_1.splitIdentifierSegments)(name))
479
464
  out.push([segment, name]);
480
465
  }
481
- /**
482
- * Update an existing node
483
- */
484
466
  updateNode(node) {
485
467
  if (!this.stmts.updateNode) {
486
468
  this.stmts.updateNode = this.db.prepare(`
@@ -508,9 +490,7 @@ class QueryBuilder {
508
490
  WHERE id = @id
509
491
  `);
510
492
  }
511
- // Invalidate cache before update
512
493
  this.nodeCache.delete(node.id);
513
- // Validate required fields
514
494
  if (!node.id || !node.kind || !node.name || !node.filePath || !node.language) {
515
495
  console.error('[CodeGraph] Skipping node update with missing required fields:', node.id);
516
496
  return;
@@ -538,36 +518,20 @@ class QueryBuilder {
538
518
  returnType: node.returnType ?? null,
539
519
  updatedAt: node.updatedAt ?? Date.now(),
540
520
  });
541
- // updateNode is a second real write path to `nodes` — framework
542
- // post-extract passes rewrite names through it (NestJS route prefixing),
543
- // and a renamed node's new name must reach the segment vocabulary just
544
- // like an inserted one's (#1141). Without this the rename left the new
545
- // name permanently unsearchable: the old name's rows became honest-gate
546
- // orphans and the only backfill is gated on the vocab being EMPTY.
547
- // insertNameSegments is idempotent (in-memory set + INSERT OR IGNORE),
548
- // so no name-changed check is needed.
549
521
  if (this.isSegmentableKind(node.kind))
550
522
  this.insertNameSegments(node.name);
551
523
  }
552
- /**
553
- * Delete a node by ID
554
- */
555
524
  deleteNode(id) {
556
525
  if (!this.stmts.deleteNode) {
557
526
  this.stmts.deleteNode = this.db.prepare('DELETE FROM nodes WHERE id = ?');
558
527
  }
559
- // Invalidate cache
560
528
  this.nodeCache.delete(id);
561
529
  this.stmts.deleteNode.run(id);
562
530
  }
563
- /**
564
- * Delete all nodes for a file
565
- */
566
531
  deleteNodesByFile(filePath) {
567
532
  if (!this.stmts.deleteNodesByFile) {
568
533
  this.stmts.deleteNodesByFile = this.db.prepare('DELETE FROM nodes WHERE file_path = ?');
569
534
  }
570
- // Invalidate cache for nodes in this file
571
535
  for (const [id, node] of this.nodeCache) {
572
536
  if (node.filePath === filePath) {
573
537
  this.nodeCache.delete(id);
@@ -575,32 +539,26 @@ class QueryBuilder {
575
539
  }
576
540
  this.stmts.deleteNodesByFile.run(filePath);
577
541
  }
578
- // ===========================================================================
579
- // Name-segment vocabulary (prompt-hook graph-derived gate)
580
- // ===========================================================================
581
- /** Wipe the segment vocabulary. A full index calls this at its start; the
582
- * node write path repopulates it as files (re-)index, so the end state is
583
- * exactly the current names with no orphan rows. */
584
542
  clearNameSegmentVocab() {
585
543
  this.db.exec('DELETE FROM name_segment_vocab');
586
544
  this.segmentedNames.clear();
587
545
  }
588
- /** True when the vocab has no rows — an index built before the table existed.
589
- * `sync` uses this to heal such databases (see rebuildNameSegmentVocabFrom). */
546
+ pruneNameSegmentVocab() {
547
+ this.db.exec("DELETE FROM name_segment_vocab WHERE name NOT IN (SELECT name FROM nodes WHERE kind NOT IN ('file', 'import'))");
548
+ this.segmentedNames.clear();
549
+ }
590
550
  isNameSegmentVocabEmpty() {
551
+ if (!this.hasSchema('name_segment_vocab'))
552
+ return true;
591
553
  const row = this.db.prepare('SELECT 1 FROM name_segment_vocab LIMIT 1').get();
592
554
  return row === undefined;
593
555
  }
594
- /** One page of distinct segmentable node names, for batched vocab rebuilds
595
- * (file basenames and import specifiers are excluded from the vocab — see
596
- * insertNode). */
597
556
  getDistinctNodeNames(limit, offset) {
598
557
  const rows = this.db
599
558
  .prepare("SELECT DISTINCT name FROM nodes WHERE kind NOT IN ('file', 'import') ORDER BY name LIMIT ? OFFSET ?")
600
559
  .all(limit, offset);
601
560
  return rows.map((r) => r.name);
602
561
  }
603
- /** Insert segments for a batch of names in one transaction (vocab heal path). */
604
562
  insertNameSegmentsBatch(names) {
605
563
  this.db.transaction(() => {
606
564
  const rows = [];
@@ -609,21 +567,8 @@ class QueryBuilder {
609
567
  this.runBatched('insertNameSegments', 'INSERT OR IGNORE INTO name_segment_vocab (segment, name) VALUES ', '(?,?)', rows);
610
568
  })();
611
569
  }
612
- /**
613
- * Names whose segments cover at least `minWords` distinct PROMPT WORDS —
614
- * the co-occurrence probe behind the prompt hook's medium tier: the words
615
- * "state" and "machine" both being segments of `OrderStateMachine` is strong
616
- * evidence the prompt names that symbol in prose. Ordered by coverage.
617
- *
618
- * Takes (segment variant → original word) pairs and folds variants back to
619
- * their word INSIDE the SQL: a name matching both `service` and `services`
620
- * counts ONE word, not two. Counting raw variants let plural-variant pairs
621
- * of a single word tie with genuine two-word matches and — because ORDER
622
- * BY/LIMIT run here, before any JS-side re-check — crowd a real match past
623
- * the LIMIT on vocab-heavy repos (#1146).
624
- */
625
570
  getSegmentCoOccurrence(variants, minWords, limit) {
626
- if (variants.length === 0)
571
+ if (variants.length === 0 || !this.hasSchema('name_segment_vocab'))
627
572
  return [];
628
573
  const placeholders = variants.map(() => '?').join(', ');
629
574
  const whens = variants.map(() => 'WHEN ? THEN ?').join(' ');
@@ -638,10 +583,8 @@ class QueryBuilder {
638
583
  .all(...variants.flatMap((v) => [v.segment, v.word]), ...variants.map((v) => v.segment), minWords, limit);
639
584
  return rows;
640
585
  }
641
- /** How many distinct names each segment appears in — the rarity signal that
642
- * separates a discriminative word ("checkout") from a ubiquitous one ("state"). */
643
586
  getSegmentNameCounts(segments) {
644
- if (segments.length === 0)
587
+ if (segments.length === 0 || !this.hasSchema('name_segment_vocab'))
645
588
  return new Map();
646
589
  const placeholders = segments.map(() => '?').join(', ');
647
590
  const rows = this.db
@@ -650,61 +593,39 @@ class QueryBuilder {
650
593
  .all(...segments);
651
594
  return new Map(rows.map((r) => [r.segment, r.n]));
652
595
  }
653
- /** Names containing the given segment (rare-single-word tier). */
654
596
  getNamesForSegment(segment, limit) {
597
+ if (!this.hasSchema('name_segment_vocab'))
598
+ return [];
655
599
  const rows = this.db
656
600
  .prepare('SELECT name FROM name_segment_vocab WHERE segment = ? ORDER BY length(name) ASC LIMIT ?')
657
601
  .all(segment, limit);
658
602
  return rows.map((r) => r.name);
659
603
  }
660
- /**
661
- * Get a node by ID
662
- */
663
604
  getNodeById(id) {
664
- // Check cache first
665
605
  if (this.nodeCache.has(id)) {
666
606
  const cached = this.nodeCache.get(id);
667
- // Move to end to implement LRU (delete and re-add)
668
607
  this.nodeCache.delete(id);
669
608
  this.nodeCache.set(id, cached);
670
609
  return cached;
671
610
  }
672
611
  if (!this.stmts.getNodeById) {
673
- this.stmts.getNodeById = this.db.prepare('SELECT * FROM nodes WHERE id = ?');
612
+ this.stmts.getNodeById = prepareNodeStatement(this.db, 'SELECT * FROM nodes WHERE id = ?');
674
613
  }
675
- const row = this.stmts.getNodeById.get(id);
676
- if (!row) {
614
+ const node = this.stmts.getNodeById.get(id);
615
+ if (!node) {
677
616
  return null;
678
617
  }
679
- const node = rowToNode(row);
680
618
  this.cacheNode(node);
681
619
  return node;
682
620
  }
683
- /**
684
- * Batch lookup: fetch many nodes by ID in a single SQL round-trip.
685
- *
686
- * Replaces the N+1 pattern in graph traversal where every edge would
687
- * trigger its own `getNodeById` call. For a function with 50 callers
688
- * this collapses 50 point reads into one IN-list query (~10-50x
689
- * faster end-to-end).
690
- *
691
- * Returns a Map keyed by id so callers can preserve their own ordering
692
- * (typically the order edges were returned from the graph). Missing IDs
693
- * are simply absent from the map.
694
- *
695
- * Cache-aware: ids already in the LRU cache are served from memory and
696
- * the SQL query only touches the misses.
697
- */
698
621
  getNodesByIds(ids) {
699
622
  const out = new Map();
700
623
  if (ids.length === 0)
701
624
  return out;
702
- // Serve cache hits first; build the miss list for SQL.
703
625
  const misses = [];
704
626
  for (const id of ids) {
705
627
  const cached = this.nodeCache.get(id);
706
628
  if (cached !== undefined) {
707
- // LRU touch
708
629
  this.nodeCache.delete(id);
709
630
  this.nodeCache.set(id, cached);
710
631
  out.set(id, cached);
@@ -715,9 +636,6 @@ class QueryBuilder {
715
636
  }
716
637
  if (misses.length === 0)
717
638
  return out;
718
- // Chunk under SQLite's parameter limit (default 999, raised to 32766
719
- // in better-sqlite3 builds — chunk at 500 for safety across both
720
- // backends and to keep the query plan simple).
721
639
  for (let i = 0; i < misses.length; i += SQLITE_PARAM_CHUNK_SIZE) {
722
640
  const chunk = misses.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
723
641
  const placeholders = chunk.map(() => '?').join(',');
@@ -739,8 +657,6 @@ class QueryBuilder {
739
657
  const uniqueIds = [...new Set(ids)];
740
658
  for (let i = 0; i < uniqueIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
741
659
  const chunk = uniqueIds.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
742
- // Every edge insert checks its endpoints here, a chunk at a time: the
743
- // full-size statement is prepared once, the final partial chunk ad hoc.
744
660
  let stmt;
745
661
  if (chunk.length === SQLITE_PARAM_CHUNK_SIZE) {
746
662
  stmt = this.stmts.existingNodeIdsFull ??= this.db.prepare(`SELECT id FROM nodes WHERE id IN (${new Array(SQLITE_PARAM_CHUNK_SIZE).fill('?').join(',')})`);
@@ -755,12 +671,8 @@ class QueryBuilder {
755
671
  }
756
672
  return out;
757
673
  }
758
- /**
759
- * Add a node to the cache, evicting oldest if needed
760
- */
761
674
  cacheNode(node) {
762
675
  if (this.nodeCache.size >= this.maxCacheSize) {
763
- // Evict oldest (first) entry
764
676
  const firstKey = this.nodeCache.keys().next().value;
765
677
  if (firstKey) {
766
678
  this.nodeCache.delete(firstKey);
@@ -768,50 +680,48 @@ class QueryBuilder {
768
680
  }
769
681
  this.nodeCache.set(node.id, node);
770
682
  }
771
- /**
772
- * Clear the node cache
773
- */
774
683
  clearCache() {
775
684
  this.nodeCache.clear();
776
685
  }
777
- /**
778
- * Whether any node in `filePath` is exported — `getNodesByFile(f).some((n) =>
779
- * n.isExported)` as one indexed probe, without decoding the file's nodes.
780
- */
781
686
  fileHasExportedNode(filePath) {
782
687
  if (!this.stmts.fileHasExportedNode) {
783
688
  this.stmts.fileHasExportedNode = this.db.prepare('SELECT 1 FROM nodes WHERE file_path = ? AND is_exported = 1 LIMIT 1');
784
689
  }
785
690
  return this.stmts.fileHasExportedNode.get(filePath) !== undefined;
786
691
  }
787
- /** The exported nodes of a file, in {@link getNodesByFile} order, decoding only those rows. */
788
692
  getExportedNodesByFile(filePath) {
789
693
  if (!this.stmts.getExportedNodesByFile) {
790
694
  this.stmts.getExportedNodesByFile = this.db.prepare('SELECT * FROM nodes WHERE file_path = ? AND is_exported = 1 ORDER BY start_line, id');
791
695
  }
792
696
  return this.stmts.getExportedNodesByFile.all(filePath).map(rowToNode);
793
697
  }
794
- /** The nodes of a file with one name, in {@link getNodesByFile} order, decoding only those rows. */
795
698
  getNodesByFileAndName(filePath, name) {
796
699
  if (!this.stmts.getNodesByFileAndName) {
797
- this.stmts.getNodesByFileAndName = this.db.prepare('SELECT * FROM nodes WHERE file_path = ? AND name = ? ORDER BY start_line, id');
700
+ this.stmts.getNodesByFileAndName = prepareNodeStatement(this.db, 'SELECT * FROM nodes WHERE file_path = ? AND name = ? ORDER BY start_line, id');
798
701
  }
799
- return this.stmts.getNodesByFileAndName.all(filePath, name).map(rowToNode);
702
+ return this.stmts.getNodesByFileAndName.all(filePath, name);
800
703
  }
801
- /**
802
- * Get all nodes in a file
803
- */
804
704
  getNodesByFile(filePath) {
805
705
  if (!this.stmts.getNodesByFile) {
806
- this.stmts.getNodesByFile = this.db.prepare('SELECT * FROM nodes WHERE file_path = ? ORDER BY start_line, id');
706
+ this.stmts.getNodesByFile = prepareNodeStatement(this.db, 'SELECT * FROM nodes WHERE file_path = ? ORDER BY start_line, id');
807
707
  }
808
- const rows = this.stmts.getNodesByFile.all(filePath);
809
- return rows.map(rowToNode);
708
+ return this.stmts.getNodesByFile.all(filePath);
709
+ }
710
+ getNodeIdentitiesByFile(filePath) {
711
+ if (!this.stmts.getNodeIdentitiesByFile) {
712
+ this.stmts.getNodeIdentitiesByFile = this.db.prepare('SELECT id, kind, name, qualified_name, signature, start_line, start_column FROM nodes WHERE file_path = ?');
713
+ }
714
+ const rows = this.stmts.getNodeIdentitiesByFile.all(filePath);
715
+ return rows.map((row) => ({
716
+ id: row.id,
717
+ kind: row.kind,
718
+ name: row.name,
719
+ qualifiedName: row.qualified_name,
720
+ signature: row.signature ?? undefined,
721
+ startLine: row.start_line,
722
+ startColumn: row.start_column,
723
+ }));
810
724
  }
811
- /**
812
- * Get all nodes in several files at once — one chunked `IN` query rather than
813
- * one {@link getNodesByFile} per file (#1975).
814
- */
815
725
  getNodesByFiles(filePaths) {
816
726
  const unique = [...new Set(filePaths)];
817
727
  const out = [];
@@ -826,34 +736,7 @@ class QueryBuilder {
826
736
  }
827
737
  return out;
828
738
  }
829
- /**
830
- * Find the file that holds the densest concentration of the project's
831
- * internal call graph — the "core" file. Used by context-builder to
832
- * boost ranking of symbols in that file's directory (so e.g. sinatra
833
- * queries surface `lib/sinatra/base.rb`'s `route!` instead of
834
- * `sinatra-contrib/lib/sinatra/multi_route.rb`'s `route` extension).
835
- *
836
- * Returns null if no file has a meaningful concentration (e.g. spread
837
- * evenly across many files, or empty index).
838
- *
839
- * "Internal" = source and target are in the same file. Cross-file
840
- * edges aren't useful here — they don't tell us which file is the
841
- * functional center.
842
- *
843
- * Excludes test/spec files from candidacy via path-pattern. The agent's
844
- * typical question is "how does X work", not "how is X tested", so
845
- * boosting a test file's directory would be a misfire.
846
- *
847
- * The answer depends only on the graph, never on the query, and the
848
- * aggregation behind it scans every edge — seconds on a large index, paid
849
- * by every generic explore (#1864). So it is memoized per database change
850
- * stamp: recomputed only after something wrote to the database.
851
- */
852
739
  getDominantFile() {
853
- // total_changes() counts writes that are later rolled back, so a result
854
- // read inside a transaction could outlive a ROLLBACK under an unchanged
855
- // stamp. Never keep one; `undefined` (a runtime without the getter) is
856
- // treated the same way.
857
740
  if (this.db.inTransaction !== false) {
858
741
  this.dominantFileMemo = undefined;
859
742
  return this.computeDominantFile();
@@ -865,16 +748,6 @@ class QueryBuilder {
865
748
  this.dominantFileMemo = { stamp, value };
866
749
  return value;
867
750
  }
868
- /**
869
- * A value that differs whenever the database content may have changed
870
- * since the last call, whoever changed it: `total_changes()` counts the
871
- * rows this connection inserted, updated or deleted, and
872
- * `PRAGMA data_version` moves when any OTHER connection — another process's
873
- * sync, a CLI `codegraph index` beside a running MCP server — commits. Both
874
- * are O(1), so no write path has to remember to invalidate anything.
875
- * Coarse on purpose: any write, not just one to nodes/edges, forces a
876
- * recompute, which only costs time, never a stale answer.
877
- */
878
751
  getChangeStamp() {
879
752
  if (!this.stmts.getChangeStamp) {
880
753
  this.stmts.getChangeStamp = this.db.prepare('SELECT total_changes() AS changes, (SELECT data_version FROM pragma_data_version) AS version');
@@ -884,47 +757,29 @@ class QueryBuilder {
884
757
  }
885
758
  computeDominantFile() {
886
759
  if (!this.stmts.getDominantFile) {
887
- // Pull top 20 candidates; we then filter out test/generated files
888
- // in code (regex-grade matching that SQL LIKE can't express). The
889
- // generated-file filter is critical — without it, etcd's
890
- // `api/etcdserverpb/rpc.pb.go` (1916 in-file edges, generated
891
- // protobuf stub) outranks the real `server/etcdserver/server.go`
892
- // (470 edges) by 4×, and the boost would push the agent toward
893
- // generated code.
894
- this.stmts.getDominantFile = this.db.prepare(`
895
- SELECT n.file_path AS file_path, COUNT(*) AS edge_count
896
- FROM edges e
897
- JOIN nodes n ON e.source = n.id
898
- JOIN nodes m ON e.target = m.id
899
- WHERE n.file_path = m.file_path
900
- GROUP BY n.file_path
901
- ORDER BY edge_count DESC
902
- LIMIT 20
903
- `);
760
+ this.stmts.getDominantFile = this.db.prepare(exports.DOMINANT_FILE_SQL);
904
761
  }
905
762
  const rows = this.stmts.getDominantFile.all();
906
- const generated = this.getGeneratedPathsAmong(rows.map(r => r.file_path));
907
- const filtered = rows.filter(r => !isLowValueFile(r.file_path, generated));
908
- if (filtered.length === 0 || filtered[0].edge_count < 20)
763
+ const kept = [];
764
+ for (let i = 0; i < rows.length && kept.length < 2; i += DOMINANT_FILE_BATCH) {
765
+ const batch = rows.slice(i, i + DOMINANT_FILE_BATCH);
766
+ const generated = this.getGeneratedPathsAmong(batch.map(r => r.file_path));
767
+ for (const r of batch) {
768
+ if (isLowValueFile(r.file_path, generated))
769
+ continue;
770
+ kept.push(r);
771
+ if (kept.length === 2)
772
+ break;
773
+ }
774
+ }
775
+ if (kept.length === 0 || kept[0].edge_count < 20)
909
776
  return null;
910
777
  return {
911
- filePath: filtered[0].file_path,
912
- edgeCount: filtered[0].edge_count,
913
- nextEdgeCount: filtered[1]?.edge_count ?? 0,
778
+ filePath: kept[0].file_path,
779
+ edgeCount: kept[0].edge_count,
780
+ nextEdgeCount: kept[1]?.edge_count ?? 0,
914
781
  };
915
782
  }
916
- /**
917
- * Find the file that holds the densest concentration of the project's
918
- * `route` nodes (framework-emitted: Express/Gin/Flask/Rails/Drupal/etc.).
919
- * Used by handleContext on small repos to inline the project's routing
920
- * config when the agent's query is about request flow — eliminating the
921
- * "Glob + Read routes.rb" pattern that beats codegraph on tiny realworld
922
- * template repos.
923
- *
924
- * Excludes test/generated files from candidacy. Returns null if there
925
- * are fewer than 3 non-test routes total, or if no file holds at least
926
- * 30% of them (diffuse routing → no single answer file).
927
- */
928
783
  getTopRouteFile() {
929
784
  if (!this.stmts.getTopRouteFile) {
930
785
  this.stmts.getTopRouteFile = this.db.prepare(`
@@ -932,8 +787,7 @@ class QueryBuilder {
932
787
  FROM nodes
933
788
  WHERE kind = 'route'
934
789
  GROUP BY file_path
935
- ORDER BY cnt DESC
936
- LIMIT 20
790
+ ORDER BY cnt DESC, file_path
937
791
  `);
938
792
  }
939
793
  const rows = this.stmts.getTopRouteFile.all();
@@ -949,23 +803,12 @@ class QueryBuilder {
949
803
  return null;
950
804
  return { filePath: top.file_path, routeCount: top.cnt, totalRoutes };
951
805
  }
952
- /**
953
- * Build a URL → handler manifest from the index. Each route node's
954
- * `references` edge points at the function/method that handles the
955
- * request. We join them in one pass; the agent gets the canonical
956
- * routing answer ("POST /users/login → AuthController#login") without
957
- * having to parse the framework's route DSL itself.
958
- *
959
- * Also returns the file with the most handler endpoints — used as the
960
- * "top handler file" to inline source for, so the agent has both the
961
- * mapping AND the handler implementations.
962
- */
963
- getRoutingManifest(limit = 40) {
964
- if (!this.stmts.getRoutingManifest) {
965
- // Edge kind varies across framework resolvers: Spring/Rails/
966
- // Laravel/Drupal emit `references`, Express emits `calls`. Accept
967
- // both — the semantic is the same (route → its handler).
968
- this.stmts.getRoutingManifest = this.db.prepare(`
806
+ getRoutingManifest(limit = 40, perRoute = false) {
807
+ const key = perRoute ? 'getRoutingManifestPerRoute' : 'getRoutingManifest';
808
+ if (!this.stmts[key]) {
809
+ const serves = `e.kind IN ('references', 'calls')
810
+ AND h.kind IN ('function', 'method', 'class', 'constant', 'variable', 'component')`;
811
+ this.stmts[key] = this.db.prepare(`
969
812
  SELECT
970
813
  r.name AS url,
971
814
  r.id AS route_id,
@@ -979,19 +822,23 @@ class QueryBuilder {
979
822
  JOIN edges e ON e.source = r.id
980
823
  JOIN nodes h ON e.target = h.id
981
824
  WHERE r.kind = 'route'
982
- AND e.kind IN ('references', 'calls')
983
- AND h.kind IN ('function', 'method', 'class', 'constant', 'variable')
825
+ AND ${serves}
826
+ ${perRoute ? `AND r.id IN (
827
+ SELECT r2.id FROM nodes r2
828
+ WHERE r2.kind = 'route'
829
+ AND EXISTS (SELECT 1 FROM edges e JOIN nodes h ON e.target = h.id WHERE e.source = r2.id AND ${serves})
830
+ ORDER BY r2.file_path, r2.start_line
831
+ LIMIT ?
832
+ )` : ''}
984
833
  ORDER BY r.file_path, r.start_line
985
- LIMIT ?
834
+ ${perRoute ? '' : 'LIMIT ?'}
986
835
  `);
987
836
  }
988
- const rows = this.stmts.getRoutingManifest.all(limit);
989
- // Drop test/generated handlers — same hygiene as elsewhere.
837
+ const rows = this.stmts[key].all(limit);
990
838
  const generated = this.getGeneratedPathsAmong(rows.map(r => r.handler_file));
991
839
  const filtered = rows.filter(r => !isLowValueFile(r.handler_file, generated));
992
840
  if (filtered.length < 3)
993
841
  return null;
994
- // Identify the file holding the most handlers (the "primary handler file").
995
842
  const fileCounts = new Map();
996
843
  for (const r of filtered) {
997
844
  fileCounts.set(r.handler_file, (fileCounts.get(r.handler_file) ?? 0) + 1);
@@ -1020,112 +867,54 @@ class QueryBuilder {
1020
867
  totalRoutes: filtered.length,
1021
868
  };
1022
869
  }
1023
- /**
1024
- * Get all nodes of a specific kind
1025
- */
1026
870
  getNodesByKind(kind) {
1027
871
  if (!this.stmts.getNodesByKind) {
1028
- this.stmts.getNodesByKind = this.db.prepare('SELECT * FROM nodes WHERE kind = ? ORDER BY file_path, start_line, id');
872
+ this.stmts.getNodesByKind = prepareNodeStatement(this.db, 'SELECT * FROM nodes WHERE kind = ? ORDER BY file_path, start_line, id');
1029
873
  }
1030
- const rows = this.stmts.getNodesByKind.all(kind);
1031
- return rows.map(rowToNode);
874
+ return this.stmts.getNodesByKind.all(kind);
1032
875
  }
1033
- /**
1034
- * Stream every node of a kind one at a time (lazy) instead of materializing
1035
- * them all like {@link getNodesByKind}. For unbounded kinds (`function`,
1036
- * `method`) on a symbol-dense project the full array is gigabytes; the
1037
- * dynamic-edge synthesizers only scan-and-filter, so they iterate to keep
1038
- * memory O(1) in the node count rather than O(nodes) (#610).
1039
- */
1040
876
  *iterateNodesByKind(kind) {
1041
- // Fresh statement per call (not a cached one): an iterator holds an open
1042
- // cursor, so a shared statement would conflict across overlapping scans.
1043
- // Synthesis uses first/last-match precedence and caps: insertion order
1044
- // changes on sync. idx_nodes_kind streams this canonical order without
1045
- // materializing/sorting all of a large project's methods in memory.
1046
- const stmt = this.db.prepare('SELECT * FROM nodes WHERE kind = ? ORDER BY file_path, start_line, id');
1047
- for (const row of stmt.iterate(kind)) {
1048
- yield rowToNode(row);
1049
- }
877
+ yield* prepareNodeStatement(this.db, 'SELECT * FROM nodes WHERE kind = ? ORDER BY file_path, start_line, id').iterate(kind);
1050
878
  }
1051
- /**
1052
- * iterateNodesByKind narrowed to some languages, in the same canonical
1053
- * order — the ORDER BY is total (`id` is unique), so this yields exactly the
1054
- * nodes a caller filtering iterateNodesByKind by language would keep, in the
1055
- * same sequence. A Go pass on a TypeScript monorepo otherwise materialized
1056
- * every method in the project to find a couple of Go ones.
1057
- */
1058
879
  *iterateNodesByKindIn(kind, languages) {
1059
- if (languages.length === 0)
880
+ const kinds = typeof kind === 'string' ? [kind] : kind;
881
+ if (kinds.length === 0 || languages.length === 0)
1060
882
  return;
1061
- const stmt = this.db.prepare(`SELECT * FROM nodes WHERE kind = ? AND language IN (${languages.map(() => '?').join(', ')}) ORDER BY file_path, start_line, id`);
1062
- for (const row of stmt.iterate(kind, ...languages)) {
883
+ const kindTest = kinds.length === 1 ? 'kind = ?' : `kind IN (${kinds.map(() => '?').join(', ')})`;
884
+ const stmt = this.db.prepare(`SELECT * FROM nodes WHERE ${kindTest} AND language IN (${languages.map(() => '?').join(', ')}) ORDER BY file_path, start_line, id`);
885
+ for (const row of stmt.iterate(...kinds, ...languages)) {
1063
886
  yield rowToNode(row);
1064
887
  }
1065
888
  }
1066
- /**
1067
- * Get all nodes in the database
1068
- */
889
+ getTopLevelSignaturesMentioning(kinds, languages, names) {
890
+ const marks = (n) => new Array(n).fill('?').join(', ');
891
+ const rows = this.db.prepare(`SELECT signature FROM nodes WHERE kind IN (${marks(kinds.length)}) AND language IN (${marks(languages.length)})
892
+ AND qualified_name = name AND (${names.map(() => 'instr(signature, ?) > 0').join(' OR ')})`).all(...kinds, ...languages, ...names);
893
+ return rows.map((row) => row.signature);
894
+ }
1069
895
  getAllNodes() {
1070
896
  const rows = this.db.prepare('SELECT * FROM nodes').all();
1071
897
  return rows.map(rowToNode);
1072
898
  }
1073
- /**
1074
- * Stream nodes of one language whose `decorators` JSON array contains
1075
- * `decorator`. The LIKE on the JSON text is a cheap index-free pre-filter
1076
- * (a decorator name can appear as a substring of another), so callers must
1077
- * still exact-check `node.decorators.includes(decorator)`. Exists so the
1078
- * kotlin expect/actual synthesizer never materializes the whole node table
1079
- * the way `getAllNodes().filter(...)` did — that array alone OOM'd Node's
1080
- * default heap on a 2M-node graph (#1212).
1081
- */
1082
899
  *iterateNodesByLanguageWithDecorator(language, decorator) {
1083
- // Fresh statement per call — an iterator holds an open cursor (see
1084
- // iterateNodesByKind).
1085
900
  const stmt = this.db.prepare("SELECT * FROM nodes WHERE language = ? AND decorators LIKE '%' || ? || '%' ORDER BY file_path, start_line, id");
1086
901
  for (const row of stmt.iterate(language, `"${decorator}"`)) {
1087
902
  yield rowToNode(row);
1088
903
  }
1089
904
  }
1090
- /**
1091
- * Distinct languages present in the files table. One indexed aggregate —
1092
- * lets the dynamic-edge synthesizers skip passes for languages the project
1093
- * doesn't contain at all (a Kotlin pass has no work on a pure-C repo), so
1094
- * their cost is zero rather than a full-graph scan that finds nothing (#1212).
1095
- */
1096
905
  getDistinctFileLanguages() {
1097
906
  const rows = this.db.prepare('SELECT DISTINCT language FROM files').all();
1098
907
  return new Set(rows.map((r) => r.language));
1099
908
  }
1100
- /**
1101
- * Get nodes by exact name match (uses idx_nodes_name index).
1102
- *
1103
- * This is resolution's candidate list, and the ORDER BY is load-bearing for
1104
- * index correctness, not cosmetic (CG-33). When a reference names a symbol
1105
- * that several files define and nothing disambiguates them, resolution binds
1106
- * to the first candidate — so without an ORDER BY the winner was decided by
1107
- * rowid, i.e. by the order files happened to be WRITTEN. A full index writes
1108
- * them in scan order; an incremental sync appends each file as it changes, so
1109
- * the same tree resolved to different edges depending on how the index was
1110
- * built, and a long-lived synced index drifted away from a rebuild of itself
1111
- * (measured at 4.3% of distinct edges, mostly `calls`).
1112
- *
1113
- * `(file_path, start_line)` is a property of the CODE, so both paths now pick
1114
- * the same candidate. The sort is paid once per distinct name per resolution
1115
- * run — ReferenceResolver memoizes this in its nameCache — and the population
1116
- * is capped by AMBIGUOUS_NAME_CEILING (#999).
1117
- */
909
+ hasDecoratedFunction(language, decorator) {
910
+ return !!this.db.prepare(`SELECT 1 FROM nodes WHERE kind = 'function' AND language = ? AND decorators LIKE ? LIMIT 1`).get(language, `%"${decorator}"%`);
911
+ }
1118
912
  getNodesByName(name) {
1119
913
  if (!this.stmts.getNodesByName) {
1120
- this.stmts.getNodesByName = this.db.prepare('SELECT * FROM nodes WHERE name = ? ORDER BY file_path, start_line, id');
914
+ this.stmts.getNodesByName = prepareNodeStatement(this.db, 'SELECT * FROM nodes WHERE name = ? ORDER BY file_path, start_line, id');
1121
915
  }
1122
- const rows = this.stmts.getNodesByName.all(name);
1123
- return rows.map(rowToNode);
916
+ return this.stmts.getNodesByName.all(name);
1124
917
  }
1125
- /**
1126
- * Nodes whose name starts with `prefix`, by index range scan (a LIKE would
1127
- * skip idx_nodes_name under SQLite's default case-insensitive LIKE).
1128
- */
1129
918
  getNodesByNamePrefix(prefix, limit = 20) {
1130
919
  if (!this.stmts.getNodesByNamePrefix) {
1131
920
  this.stmts.getNodesByNamePrefix = this.db.prepare('SELECT * FROM nodes WHERE name >= ? AND name < ? ORDER BY name LIMIT ?');
@@ -1133,7 +922,6 @@ class QueryBuilder {
1133
922
  const rows = this.stmts.getNodesByNamePrefix.all(prefix, prefix + '￿', limit);
1134
923
  return rows.map(rowToNode);
1135
924
  }
1136
- /** File nodes whose basename starts with `prefix`, without a result cap. */
1137
925
  getFileNodesByNamePrefix(prefix) {
1138
926
  if (!this.stmts.getFileNodesByNamePrefix) {
1139
927
  this.stmts.getFileNodesByNamePrefix = this.db.prepare("SELECT * FROM nodes WHERE kind = 'file' AND name >= ? AND name < ? ORDER BY name");
@@ -1141,51 +929,42 @@ class QueryBuilder {
1141
929
  const rows = this.stmts.getFileNodesByNamePrefix.all(prefix, prefix + '￿');
1142
930
  return rows.map(rowToNode);
1143
931
  }
1144
- /**
1145
- * Get nodes by exact qualified name match (uses idx_nodes_qualified_name index)
1146
- */
1147
932
  getNodesByQualifiedNameExact(qualifiedName) {
1148
933
  if (!this.stmts.getNodesByQualifiedNameExact) {
1149
- this.stmts.getNodesByQualifiedNameExact = this.db.prepare('SELECT * FROM nodes WHERE qualified_name = ? ORDER BY file_path, start_line, id');
934
+ this.stmts.getNodesByQualifiedNameExact = prepareNodeStatement(this.db, 'SELECT * FROM nodes WHERE qualified_name = ? ORDER BY file_path, start_line, id');
1150
935
  }
1151
- const rows = this.stmts.getNodesByQualifiedNameExact.all(qualifiedName);
1152
- return rows.map(rowToNode);
936
+ return this.stmts.getNodesByQualifiedNameExact.all(qualifiedName);
1153
937
  }
1154
- /**
1155
- * Get nodes by name, case-insensitively (seeks the idx_nodes_lower_name
1156
- * expression index).
1157
- *
1158
- * The parameter is lowered in SQL rather than trusted to arrive lowered, so
1159
- * the lookup means the same thing whatever casing a caller hands it. Written
1160
- * as a bare `lower(name) = ?` it silently returned nothing for any input
1161
- * carrying an uppercase letter, and — because SQLite's `lower()` folds ASCII
1162
- * only while JavaScript's `.toLowerCase()` folds Unicode — a caller that
1163
- * pre-lowered in JavaScript could not match a non-ASCII name at all.
1164
- *
1165
- * Note this hardens the query, not its one caller: `matchFuzzy` still lowers
1166
- * in JavaScript before calling, so the non-ASCII gap remains open there.
1167
- */
1168
938
  getNodesByLowerName(name) {
1169
939
  if (!this.stmts.getNodesByLowerName) {
1170
- this.stmts.getNodesByLowerName = this.db.prepare('SELECT * FROM nodes WHERE lower(name) = lower(?)');
940
+ this.stmts.getNodesByLowerName = prepareNodeStatement(this.db, 'SELECT * FROM nodes WHERE lower(name) = lower(?)');
941
+ }
942
+ return this.stmts.getNodesByLowerName.all(name);
943
+ }
944
+ hasFilesOfLanguage(language) {
945
+ if (!this.stmts.hasFilesOfLanguage) {
946
+ this.stmts.hasFilesOfLanguage = this.db.prepare('SELECT 1 FROM files WHERE language = ? LIMIT 1');
947
+ }
948
+ return this.stmts.hasFilesOfLanguage.get(language) !== undefined;
949
+ }
950
+ getCobolIncludesByMember(member, limit) {
951
+ if (!this.stmts.getCobolIncludesByMember) {
952
+ this.stmts.getCobolIncludesByMember = this.db.prepare("SELECT * FROM nodes WHERE lower(name) = lower(?) AND +kind = 'import' AND +language = 'cobol'"
953
+ + ' ORDER BY file_path, start_line, id LIMIT ?');
1171
954
  }
1172
- const rows = this.stmts.getNodesByLowerName.all(name);
955
+ const rows = this.stmts.getCobolIncludesByMember.all(member, limit);
956
+ return rows.map(rowToNode);
957
+ }
958
+ getCobolFilesByStem(member) {
959
+ if (!this.stmts.getCobolFilesByStem) {
960
+ this.stmts.getCobolFilesByStem = this.db.prepare("SELECT * FROM nodes WHERE lower(name) >= lower(?) || '.' AND lower(name) < lower(?) || '/'"
961
+ + " AND +kind = 'file' AND +language = 'cobol' ORDER BY file_path");
962
+ }
963
+ const rows = this.stmts.getCobolFilesByStem.all(member, member);
1173
964
  return rows.map(rowToNode);
1174
965
  }
1175
- /**
1176
- * Search nodes by name using FTS with fallback to LIKE for better matching
1177
- *
1178
- * Search strategy:
1179
- * 1. Try FTS5 prefix match (query*) for word-start matching
1180
- * 2. If no results, try LIKE for substring matching (e.g., "signIn" finds "signInWithGoogle")
1181
- * 3. Score results based on match quality
1182
- */
1183
966
  searchNodes(query, options = {}) {
1184
967
  const { limit = 100, offset = 0 } = options;
1185
- // Parse field-qualified bits out of the raw query (kind:, lang:,
1186
- // path:, name:). Anything not recognised stays in `text` and goes
1187
- // to FTS unchanged. Filters compose with the SearchOptions arg —
1188
- // both are applied (intersection-style).
1189
968
  const parsed = (0, query_parser_1.parseQuery)(query);
1190
969
  const mergedKinds = parsed.kinds.length > 0
1191
970
  ? Array.from(new Set([...(options.kinds ?? []), ...parsed.kinds]))
@@ -1193,53 +972,21 @@ class QueryBuilder {
1193
972
  const mergedLanguages = parsed.languages.length > 0
1194
973
  ? Array.from(new Set([...(options.languages ?? []), ...parsed.languages]))
1195
974
  : options.languages;
1196
- const pathFilters = parsed.pathFilters;
1197
- const nameFilters = parsed.nameFilters;
1198
- // The text portion drives FTS/LIKE; if all the user typed was
1199
- // filters (`kind:function`), we still need *some* candidate set,
1200
- // so synthesise an empty-text path that returns everything matching
1201
- // the filters.
975
+ const filters = fieldFiltersOf(parsed);
976
+ if (filters && !this.fieldFiltersCanMatch(filters))
977
+ return [];
1202
978
  const text = parsed.text;
1203
979
  const kinds = mergedKinds;
1204
980
  const languages = mergedLanguages;
1205
- // First try FTS5 with prefix matching (skip if FTS5 not available, #1532)
1206
981
  let results = text
1207
- ? (this._fts5Available !== false ? this.searchNodesFTS(text, { kinds, languages, limit, offset }) : [])
1208
- // Over-fetch by 5× when running filter-only (no text). The
1209
- // post-scoring path: + name: filters can be very selective, so
1210
- // a smaller multiplier risks returning fewer than `limit`
1211
- // results despite the DB having plenty of matches.
1212
- : this.searchAllByFilters({ kinds, languages, limit: limit * 5 });
1213
- // If no FTS results, try LIKE-based substring search
982
+ ? (this._fts5Available !== false ? this.searchNodesFTS(text, { kinds, languages, limit, offset }, filters) : [])
983
+ : this.searchAllByFilters({ kinds, languages, limit: limit * 5, offset }, filters);
1214
984
  if (results.length === 0 && text.length >= 2) {
1215
- results = this.searchNodesLike(text, { kinds, languages, limit, offset });
985
+ results = this.searchNodesLike(text, { kinds, languages, limit, offset }, filters);
1216
986
  }
1217
- // Final fuzzy fallback: scan all known names and keep those within
1218
- // a tight Levenshtein distance. Only fires when both FTS and LIKE
1219
- // returned nothing AND there's a text portion long enough to be
1220
- // worth fuzzing (1-char queries would match too much).
1221
987
  if (results.length === 0 && text.length >= 3) {
1222
- results = this.searchNodesFuzzy(text, { kinds, languages, limit });
1223
- }
1224
- // Supplement: ensure exact name matches are always candidates.
1225
- // BM25 can bury short exact-match names (e.g. "getBean") under hundreds of
1226
- // compound names (e.g. "getBeanDescriptor") in large codebases,
1227
- // pushing them past the FTS fetch limit before post-hoc scoring can help.
1228
- // Use the max BM25 score as the base so the nameMatchBonus (exact=30 vs
1229
- // prefix=20) actually differentiates them after rescoring.
1230
- //
1231
- // Whole-name equality MUST be written as `lower(name) = lower(?)` so it
1232
- // seeks `idx_nodes_lower_name`. The equivalent `name = ? COLLATE NOCASE`
1233
- // matches no index — `idx_nodes_name` is BINARY-collated and the expression
1234
- // index only matches the same expression — and degrades to a full table
1235
- // scan. The `LIMIT 20` does not rescue it: SQLite can only stop early once
1236
- // it has produced 20 rows, and this runs once per query term, most of which
1237
- // name nothing in the corpus. Measured per term on an unmatched term:
1238
- // 0.08ms on gin (2.5k nodes), 0.39ms on excalidraw (11k), 2.4ms on django
1239
- // (62k) — and growing with the corpus, where the seek is flat at ~0.002ms.
1240
- // Lowering the parameter in SQL rather than in JS is deliberate: SQLite's
1241
- // `lower()` and NOCASE both fold ASCII only, while JS `.toLowerCase()`
1242
- // folds Unicode, which would silently stop matching non-ASCII names.
988
+ results = this.searchNodesFuzzy(text, { kinds, languages, limit }, filters);
989
+ }
1243
990
  if (results.length > 0 && query) {
1244
991
  const existingIds = new Set(results.map(r => r.node.id));
1245
992
  const maxFtsScore = Math.max(...results.map(r => r.score));
@@ -1255,8 +1002,11 @@ class QueryBuilder {
1255
1002
  sql += ` AND language IN (${languages.map(() => '?').join(',')})`;
1256
1003
  params.push(...languages);
1257
1004
  }
1258
- sql += ' LIMIT 20';
1259
- const rows = this.db.prepare(sql).all(...params);
1005
+ if (filters)
1006
+ sql += fieldFilterSql(filters, params);
1007
+ const rows = filters
1008
+ ? this.readFilteredPage(sql, params, filters, 20, 0)
1009
+ : this.db.prepare(`${sql} LIMIT 20`).all(...params);
1260
1010
  for (const row of rows) {
1261
1011
  if (!existingIds.has(row.id)) {
1262
1012
  results.push({ node: rowToNode(row), score: maxFtsScore });
@@ -1265,18 +1015,14 @@ class QueryBuilder {
1265
1015
  }
1266
1016
  }
1267
1017
  }
1268
- // Apply multi-signal scoring
1018
+ if (filters) {
1019
+ results = results.filter((r) => passesFieldFilters(r.node.name, r.node.filePath, filters));
1020
+ }
1269
1021
  if (results.length > 0 && (text || query)) {
1270
1022
  const scoringQuery = text || query;
1023
+ const isDeprioritizedPath = this.getDeprioritizedPathSnapshot();
1271
1024
  results = results.map(r => {
1272
- // A path the project de-prioritized is saying its symbol NAMES are not
1273
- // the answer, so the exact-name bonus has to be damped too. The -15 path
1274
- // penalty alone cannot do it: the bonus is additive and larger (measured
1275
- // on #982's repro, a `usage()` helper sat at 74.8 vs 51.2 for the top
1276
- // product symbol — -15 lands at 59.8, still ahead). Damped, not zeroed,
1277
- // so the tree stays findable when it genuinely is what you asked for.
1278
- // Evaluated once and reused: the predicate stats the config file.
1279
- const deprioritized = this.isDeprioritizedPath?.(r.node.filePath) ?? false;
1025
+ const deprioritized = isDeprioritizedPath?.(r.node.filePath) ?? false;
1280
1026
  const nameBonus = (0, query_utils_1.nameMatchBonus)(r.node.name, scoringQuery);
1281
1027
  return {
1282
1028
  ...r,
@@ -1287,39 +1033,32 @@ class QueryBuilder {
1287
1033
  };
1288
1034
  });
1289
1035
  results.sort((a, b) => b.score - a.score);
1290
- // Trim to requested limit after rescoring
1291
1036
  if (results.length > limit) {
1292
1037
  results = results.slice(0, limit);
1293
1038
  }
1294
1039
  }
1295
- // Apply path: + name: filters AFTER scoring. Scoring already uses
1296
- // path/name as a soft signal; the explicit filters here are a hard
1297
- // gate. Done last so the FTS limit fetched plenty of candidates to
1298
- // narrow from.
1299
- if (pathFilters.length > 0) {
1300
- const lowered = pathFilters.map((p) => p.toLowerCase());
1301
- results = results.filter((r) => {
1302
- const fp = r.node.filePath.toLowerCase();
1303
- return lowered.some((p) => fp.includes(p));
1304
- });
1305
- }
1306
- if (nameFilters.length > 0) {
1307
- const lowered = nameFilters.map((n) => n.toLowerCase());
1308
- results = results.filter((r) => {
1309
- const nm = r.node.name.toLowerCase();
1310
- return lowered.some((n) => nm.includes(n));
1311
- });
1312
- }
1313
1040
  return results;
1314
1041
  }
1315
- /**
1316
- * Match-everything path used when the user supplied only field
1317
- * filters (`kind:function lang:typescript`) with no text. Returns
1318
- * candidates ordered by name; the caller's filter pass narrows to
1319
- * what was asked for.
1320
- */
1321
- searchAllByFilters(options) {
1322
- const { kinds, languages, limit } = options;
1042
+ readFilteredPage(sql, params, filters, limit, offset) {
1043
+ const page = [];
1044
+ if (limit === 0)
1045
+ return page;
1046
+ let skipped = 0;
1047
+ for (const row of this.db.prepare(sql).iterate(...params)) {
1048
+ if (!passesFieldFilters(row.name, row.file_path, filters))
1049
+ continue;
1050
+ if (skipped < offset) {
1051
+ skipped++;
1052
+ continue;
1053
+ }
1054
+ page.push(row);
1055
+ if (page.length === limit)
1056
+ break;
1057
+ }
1058
+ return page;
1059
+ }
1060
+ searchAllByFilters(options, filters) {
1061
+ const { kinds, languages, limit, offset } = options;
1323
1062
  let sql = 'SELECT * FROM nodes WHERE 1=1';
1324
1063
  const params = [];
1325
1064
  if (kinds && kinds.length > 0) {
@@ -1330,47 +1069,38 @@ class QueryBuilder {
1330
1069
  sql += ` AND language IN (${languages.map(() => '?').join(',')})`;
1331
1070
  params.push(...languages);
1332
1071
  }
1333
- sql += ' ORDER BY name LIMIT ?';
1334
- params.push(limit);
1335
- const rows = this.db.prepare(sql).all(...params);
1072
+ if (filters)
1073
+ sql += fieldFilterSql(filters, params);
1074
+ sql += ' ORDER BY name';
1075
+ const rows = filters
1076
+ ? this.readFilteredPage(sql, params, filters, limit, offset)
1077
+ : this.db.prepare(`${sql} LIMIT ? OFFSET ?`).all(...params, limit, offset);
1336
1078
  return rows.map((row) => ({ node: rowToNode(row), score: 1 }));
1337
1079
  }
1338
- /**
1339
- * Fuzzy fallback: when zero FTS/LIKE hits, try an edit-distance
1340
- * sweep over the distinct symbol-name set. Caps `maxDist` at 2 so
1341
- * `getUssr` finds `getUser` but `process` doesn't match `prosody`.
1342
- * Bounded edit distance keeps each comparison cheap; the per-query
1343
- * scan is O(distinct-name-count) which is far smaller than total
1344
- * node count on any real codebase.
1345
- */
1346
- searchNodesFuzzy(text, options) {
1080
+ searchNodesFuzzy(text, options, filters) {
1347
1081
  const { kinds, languages, limit } = options;
1348
1082
  const lowered = text.toLowerCase();
1349
1083
  const maxDist = lowered.length <= 4 ? 1 : 2;
1350
- // Pull the distinct name list once. The set is cached on QueryBuilder
1351
- // by getAllNodeNames(); even on a 200k-node project the distinct
1352
- // name set is typically O(10k) because most names repeat. The
1353
- // candidate-cap below bounds memory regardless.
1354
- const allNames = this.getAllNodeNames();
1084
+ const { names, lowered: loweredNames, starts } = this.fuzzyNames();
1355
1085
  const candidates = [];
1356
- for (const name of allNames) {
1357
- const dist = (0, query_parser_1.boundedEditDistance)(name.toLowerCase(), lowered, maxDist);
1086
+ for (let i = 0; i < names.length; i++) {
1087
+ const end = starts[i + 1] - 1;
1088
+ if (Math.abs(end - starts[i] - lowered.length) > maxDist)
1089
+ continue;
1090
+ const dist = (0, query_parser_1.boundedEditDistance)(loweredNames.slice(starts[i], end), lowered, maxDist);
1358
1091
  if (dist <= maxDist)
1359
- candidates.push({ name, dist });
1092
+ candidates.push({ name: names[i], dist });
1360
1093
  }
1361
1094
  candidates.sort((a, b) => a.dist - b.dist);
1362
- // Cap the per-name follow-up queries. Each survivor triggers a
1363
- // separate `SELECT * FROM nodes WHERE name = ?`; without this cap
1364
- // a project with many similar names (`getUser1`, `getUser2`...)
1365
- // could fan out far beyond `limit` queries before the inner-loop
1366
- // limit kicks in.
1367
1095
  const FUZZY_FOLLOWUP_CAP = Math.max(limit * 2, 50);
1368
- const cappedCandidates = candidates.slice(0, FUZZY_FOLLOWUP_CAP);
1096
+ const cappedCandidates = filters ? candidates : candidates.slice(0, FUZZY_FOLLOWUP_CAP);
1369
1097
  const results = [];
1370
1098
  const seen = new Set();
1371
1099
  for (const c of cappedCandidates) {
1372
1100
  if (results.length >= limit)
1373
1101
  break;
1102
+ if (filters && !passesNameFilters(c.name, filters))
1103
+ continue;
1374
1104
  let sql = 'SELECT * FROM nodes WHERE name = ?';
1375
1105
  const params = [c.name];
1376
1106
  if (kinds && kinds.length > 0) {
@@ -1381,14 +1111,15 @@ class QueryBuilder {
1381
1111
  sql += ` AND language IN (${languages.map(() => '?').join(',')})`;
1382
1112
  params.push(...languages);
1383
1113
  }
1384
- sql += ' LIMIT 5';
1385
- const rows = this.db.prepare(sql).all(...params);
1114
+ if (filters)
1115
+ sql += fieldFilterSql(filters, params);
1116
+ const rows = filters
1117
+ ? this.readFilteredPage(sql, params, filters, 5, 0)
1118
+ : this.db.prepare(`${sql} LIMIT 5`).all(...params);
1386
1119
  for (const row of rows) {
1387
1120
  if (seen.has(row.id))
1388
1121
  continue;
1389
1122
  seen.add(row.id);
1390
- // Lower the score for each edit step away from the query so
1391
- // exact-match fallbacks (dist 0) outrank dist-2 typos.
1392
1123
  results.push({ node: rowToNode(row), score: 1 / (1 + c.dist) });
1393
1124
  if (results.length >= limit)
1394
1125
  break;
@@ -1396,39 +1127,37 @@ class QueryBuilder {
1396
1127
  }
1397
1128
  return results;
1398
1129
  }
1399
- /** Bounded miss diagnostics, independent of relevance filters and ranking. */
1400
1130
  getExploreMissDiagnostics(query) {
1401
1131
  const words = [...new Set((query.match(/[\p{L}\p{N}]+/gu) ?? []).map(w => w.toLowerCase()))];
1402
1132
  const checked = words.filter(w => w.length <= 64).slice(0, 16);
1403
1133
  const limited = checked.length !== words.length;
1404
1134
  if (checked.length === 0)
1405
1135
  return { matched: [], unmatched: [], candidates: [], limited };
1406
- // EXISTS uses FTS postings and the segment primary key, never source scans.
1407
- // Vocab rows can outlive deleted definitions, so verify them against nodes.
1136
+ const vocab = this.hasSchema('name_segment_vocab');
1408
1137
  const rows = this.db.prepare(`
1409
1138
  WITH words(word, pattern) AS (VALUES ${checked.map(() => '(?, ?)').join(', ')})
1410
1139
  SELECT word, (
1411
- EXISTS (SELECT 1 FROM nodes_fts WHERE nodes_fts MATCH pattern)
1140
+ EXISTS (SELECT 1 FROM nodes_fts WHERE nodes_fts MATCH pattern)${vocab ? `
1412
1141
  OR EXISTS (
1413
1142
  SELECT 1 FROM name_segment_vocab v WHERE v.segment = word
1414
1143
  AND EXISTS (SELECT 1 FROM nodes n WHERE n.name = v.name AND n.kind NOT IN ('file', 'import'))
1415
- )
1144
+ )` : ''}
1416
1145
  ) AS matched FROM words
1417
1146
  `).all(...checked.flatMap(w => [w, `{name qualified_name signature docstring} : "${w}"*`]));
1418
- const names = this.db.prepare(`
1147
+ const names = this.db.prepare(`${vocab ? `
1419
1148
  SELECT name FROM (
1420
1149
  SELECT v.name FROM name_segment_vocab v
1421
1150
  WHERE v.segment IN (${checked.map(() => '?').join(', ')})
1422
1151
  AND EXISTS (SELECT 1 FROM nodes n WHERE n.name = v.name AND n.kind NOT IN ('file', 'import'))
1423
1152
  LIMIT 12
1424
1153
  )
1425
- UNION ALL
1154
+ UNION ALL` : ''}
1426
1155
  SELECT name FROM (
1427
1156
  SELECT n.name FROM nodes_fts JOIN nodes n ON n.rowid = nodes_fts.rowid
1428
1157
  WHERE nodes_fts MATCH ? AND n.kind NOT IN ('file', 'import')
1429
1158
  LIMIT 12
1430
1159
  )
1431
- `).all(...checked, `name : (${checked.map(w => `"${w}"*`).join(' OR ')})`);
1160
+ `).all(...(vocab ? checked : []), `name : (${checked.map(w => `"${w}"*`).join(' OR ')})`);
1432
1161
  return {
1433
1162
  matched: rows.filter(r => r.matched).map(r => r.word),
1434
1163
  unmatched: rows.filter(r => !r.matched).map(r => r.word),
@@ -1436,40 +1165,44 @@ class QueryBuilder {
1436
1165
  limited,
1437
1166
  };
1438
1167
  }
1439
- /**
1440
- * FTS5 search with prefix matching
1441
- */
1442
- searchNodesFTS(query, options) {
1168
+ getUnseenNames(names) {
1169
+ const checked = [...new Set(names)].filter((n) => n.length > 0 && n.length <= 128).slice(0, 16);
1170
+ if (checked.length === 0)
1171
+ return [];
1172
+ if (!this.stmts.unseenName) {
1173
+ this.stmts.unseenName = this.db.prepare(`
1174
+ SELECT EXISTS (SELECT 1 FROM nodes WHERE lower(name) = lower(?))
1175
+ OR EXISTS (SELECT 1 FROM nodes_fts WHERE nodes_fts MATCH ?) AS seen
1176
+ `);
1177
+ }
1178
+ const stmt = this.stmts.unseenName;
1179
+ return checked.filter((name) => {
1180
+ const member = name.split(/::|\./).pop();
1181
+ const phrase = member.replace(/"/g, '');
1182
+ if (phrase.length === 0)
1183
+ return false;
1184
+ const row = stmt.get(member, `{name qualified_name signature docstring} : "${phrase}"*`);
1185
+ return !row.seen;
1186
+ });
1187
+ }
1188
+ searchNodesFTS(query, options, filters) {
1443
1189
  const { kinds, languages, limit = 100, offset = 0 } = options;
1444
- // Add prefix wildcard for better matching (e.g., "auth" matches "AuthService", "authenticate")
1445
- // Escape special FTS5 characters and add prefix wildcard.
1446
- //
1447
- // `::` is a qualifier separator in Rust/C++/Ruby, not a token char,
1448
- // so treat it as whitespace before the strip step. Otherwise queries
1449
- // like `stage_apply::run` collapse to `stage_applyrun` (the colons
1450
- // are stripped without splitting) and find nothing. See #173.
1451
1190
  const ftsQuery = query
1452
- .replace(/::/g, ' ') // Rust/C++/Ruby qualifier separator
1453
- .replace(/['"*():^]/g, '') // Remove FTS5 special chars
1191
+ .replace(/::/g, ' ')
1192
+ .replace(/['"*():^]/g, ' ')
1454
1193
  .split(/\s+/)
1455
1194
  .filter(term => term.length > 0)
1456
- // Strip FTS5 boolean operators to prevent query manipulation
1457
1195
  .filter(term => !/^(AND|OR|NOT|NEAR)$/i.test(term))
1458
- .map(term => `"${term}"*`) // Prefix match each term
1196
+ .map(term => `"${term}"*`)
1459
1197
  .join(' OR ');
1460
1198
  if (!ftsQuery) {
1461
1199
  return [];
1462
1200
  }
1463
- // BM25 column weights: id=0, name=20, qualified_name=5, docstring=1, signature=2
1464
- // Heavy name weight ensures exact/prefix name matches rank above incidental
1465
- // mentions in long docstrings or qualified names of nested symbols.
1466
- // Fetch 5x requested limit so post-hoc rescoring (kindBonus, pathRelevance,
1467
- // nameMatchBonus) can promote results that BM25 alone undervalues.
1468
1201
  const ftsLimit = Math.max(limit * 5, 100);
1469
1202
  let sql = `
1470
1203
  SELECT nodes.*, bm25(nodes_fts, 0, 20, 5, 1, 2) as score
1471
1204
  FROM nodes_fts
1472
- JOIN nodes ON nodes_fts.id = nodes.id
1205
+ CROSS JOIN nodes ON nodes.rowid = nodes_fts.rowid
1473
1206
  WHERE nodes_fts MATCH ?
1474
1207
  `;
1475
1208
  const params = [ftsQuery];
@@ -1481,26 +1214,38 @@ class QueryBuilder {
1481
1214
  sql += ` AND nodes.language IN (${languages.map(() => '?').join(',')})`;
1482
1215
  params.push(...languages);
1483
1216
  }
1484
- sql += ' ORDER BY score LIMIT ? OFFSET ?';
1485
- params.push(ftsLimit, offset);
1217
+ if (filters)
1218
+ sql += fieldFilterSql(filters, params);
1219
+ sql += ' ORDER BY score';
1486
1220
  try {
1487
- const rows = this.db.prepare(sql).all(...params);
1221
+ let rows;
1222
+ if (filters) {
1223
+ rows = this.readFilteredPage(sql, params, filters, ftsLimit, offset);
1224
+ }
1225
+ else {
1226
+ sql += ' LIMIT ? OFFSET ?';
1227
+ params.push(ftsLimit, offset);
1228
+ rows = this.db.prepare(sql).all(...params);
1229
+ }
1488
1230
  return rows.map((row) => ({
1489
1231
  node: rowToNode(row),
1490
- score: Math.abs(row.score), // bm25 returns negative scores
1232
+ score: Math.abs(row.score),
1491
1233
  }));
1492
1234
  }
1493
1235
  catch {
1494
- // FTS query failed, return empty
1495
1236
  return [];
1496
1237
  }
1497
1238
  }
1498
- /**
1499
- * LIKE-based substring search for cases where FTS doesn't match
1500
- * Useful for camelCase matching (e.g., "signIn" finds "signInWithGoogle")
1501
- */
1502
- searchNodesLike(query, options) {
1239
+ searchNodesLike(query, options, filters) {
1503
1240
  const { kinds, languages, limit = 100, offset = 0 } = options;
1241
+ if (/^[A-Za-z0-9]+$/.test(query)) {
1242
+ const runs = this.memoizedRead('qualifiedNameRuns', () => this.readQualifiedNameRuns());
1243
+ if (runs !== null) {
1244
+ const word = query.toLowerCase();
1245
+ if (!this.fuzzyNames().lowered.includes(word) && !runs.includes(word))
1246
+ return [];
1247
+ }
1248
+ }
1504
1249
  let sql = `
1505
1250
  SELECT nodes.*,
1506
1251
  CASE
@@ -1517,18 +1262,17 @@ class QueryBuilder {
1517
1262
  name LIKE ?
1518
1263
  )
1519
1264
  `;
1520
- // Pattern variants for better matching
1521
1265
  const exactMatch = query;
1522
1266
  const startsWith = `${query}%`;
1523
1267
  const contains = `%${query}%`;
1524
1268
  const params = [
1525
- exactMatch, // Exact match score
1526
- startsWith, // Starts with score
1527
- contains, // Contains score
1528
- contains, // Qualified name score
1529
- contains, // WHERE: name contains
1530
- contains, // WHERE: qualified_name contains
1531
- startsWith, // WHERE: name starts with
1269
+ exactMatch,
1270
+ startsWith,
1271
+ contains,
1272
+ contains,
1273
+ contains,
1274
+ contains,
1275
+ startsWith,
1532
1276
  ];
1533
1277
  if (kinds && kinds.length > 0) {
1534
1278
  sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
@@ -1538,39 +1282,27 @@ class QueryBuilder {
1538
1282
  sql += ` AND language IN (${languages.map(() => '?').join(',')})`;
1539
1283
  params.push(...languages);
1540
1284
  }
1541
- sql += ' ORDER BY score DESC, length(name) ASC LIMIT ? OFFSET ?';
1542
- params.push(limit, offset);
1543
- const rows = this.db.prepare(sql).all(...params);
1285
+ if (filters)
1286
+ sql += fieldFilterSql(filters, params);
1287
+ sql += ' ORDER BY score DESC, length(name) ASC';
1288
+ let rows;
1289
+ if (filters) {
1290
+ rows = this.readFilteredPage(sql, params, filters, limit, offset);
1291
+ }
1292
+ else {
1293
+ sql += ' LIMIT ? OFFSET ?';
1294
+ params.push(limit, offset);
1295
+ rows = this.db.prepare(sql).all(...params);
1296
+ }
1544
1297
  return rows.map((row) => ({
1545
1298
  node: rowToNode(row),
1546
1299
  score: row.score,
1547
1300
  }));
1548
1301
  }
1549
- /**
1550
- * Find nodes by exact name match
1551
- *
1552
- * Used for hybrid search - looks up symbols by exact name or case-insensitive match.
1553
- * Returns high-confidence matches for known symbol names extracted from query.
1554
- *
1555
- * @param names - Array of symbol names to look up
1556
- * @param options - Search options (kinds, languages, limit)
1557
- * @returns SearchResult array with exact matches scored at 1.0
1558
- */
1559
1302
  findNodesByExactName(names, options = {}) {
1560
1303
  if (names.length === 0)
1561
1304
  return [];
1562
1305
  const { kinds, languages, limit = 50 } = options;
1563
- // Two-pass approach to handle common names (e.g., "run" has 40+ matches):
1564
- // Pass 1: Find which files contain distinctive (rare) symbols from the query.
1565
- // Pass 2: Query each name, boosting results that co-locate with distinctive symbols.
1566
- // Pass 1: Find files containing each queried name, identify distinctive names
1567
- //
1568
- // Both passes spell whole-name equality as `lower(name) = lower(?)` so they
1569
- // seek `idx_nodes_lower_name` — see the note in `searchNodes` for why the
1570
- // `name = ? COLLATE NOCASE` form full-scans instead. This path is the one
1571
- // that hurts most: it runs both passes for every symbol extracted from the
1572
- // query, and extraction is generous, so most of those names are absent from
1573
- // the corpus and never reach either LIMIT.
1574
1306
  const nameToFiles = new Map();
1575
1307
  for (const name of names) {
1576
1308
  let sql = 'SELECT DISTINCT file_path FROM nodes WHERE lower(name) = lower(?)';
@@ -1583,7 +1315,6 @@ class QueryBuilder {
1583
1315
  const rows = this.db.prepare(sql).all(...params);
1584
1316
  nameToFiles.set(name.toLowerCase(), new Set(rows.map(r => r.file_path)));
1585
1317
  }
1586
- // Distinctive names are those with fewer than 10 file matches (e.g., "scrapeLoop" = 1 file)
1587
1318
  const distinctiveFiles = new Set();
1588
1319
  for (const [, files] of nameToFiles) {
1589
1320
  if (files.size > 0 && files.size < 10) {
@@ -1591,7 +1322,6 @@ class QueryBuilder {
1591
1322
  distinctiveFiles.add(f);
1592
1323
  }
1593
1324
  }
1594
- // Pass 2: Query each name with per-name limit, scoring by co-location
1595
1325
  const perNameLimit = Math.max(8, Math.ceil(limit / names.length));
1596
1326
  const allResults = [];
1597
1327
  const seenIds = new Set();
@@ -1610,7 +1340,6 @@ class QueryBuilder {
1610
1340
  sql += ` AND language IN (${languages.map(() => '?').join(',')})`;
1611
1341
  params.push(...languages);
1612
1342
  }
1613
- // Fetch enough to find co-located results among common names
1614
1343
  sql += ' LIMIT ?';
1615
1344
  params.push(Math.max(perNameLimit * 3, 50));
1616
1345
  const rows = this.db.prepare(sql).all(...params);
@@ -1619,28 +1348,18 @@ class QueryBuilder {
1619
1348
  const node = rowToNode(row);
1620
1349
  if (seenIds.has(node.id))
1621
1350
  continue;
1622
- // Boost results in files that also contain distinctive symbols
1623
1351
  const coLocationBoost = distinctiveFiles.has(node.filePath) ? 20 : 0;
1624
1352
  nameResults.push({ node, score: row.score + coLocationBoost });
1625
1353
  }
1626
- // Sort by score (co-located first), take per-name limit
1627
1354
  nameResults.sort((a, b) => b.score - a.score);
1628
1355
  for (const r of nameResults.slice(0, perNameLimit)) {
1629
1356
  seenIds.add(r.node.id);
1630
1357
  allResults.push(r);
1631
1358
  }
1632
1359
  }
1633
- // Sort all results by score so co-located results bubble up
1634
1360
  allResults.sort((a, b) => b.score - a.score);
1635
1361
  return allResults.slice(0, limit);
1636
1362
  }
1637
- /**
1638
- * Find nodes whose name contains a substring (LIKE-based).
1639
- * Useful for CamelCase-part matching where FTS fails because
1640
- * e.g. "TransportSearchAction" is one FTS token, not matchable by "Search"*.
1641
- *
1642
- * Results are ordered by name length (shorter = more likely to be the core type).
1643
- */
1644
1363
  findNodesByNameSubstring(substring, options = {}) {
1645
1364
  const { kinds, languages, limit = 30, excludePrefix } = options;
1646
1365
  let sql = `
@@ -1649,7 +1368,6 @@ class QueryBuilder {
1649
1368
  WHERE name LIKE ?
1650
1369
  `;
1651
1370
  const params = [`%${substring}%`];
1652
- // Exclude prefix matches (handled by FTS-based prefix search in Step 2b)
1653
1371
  if (excludePrefix) {
1654
1372
  sql += ` AND name NOT LIKE ?`;
1655
1373
  params.push(`${substring}%`);
@@ -1664,16 +1382,71 @@ class QueryBuilder {
1664
1382
  }
1665
1383
  sql += ' ORDER BY length(name) ASC LIMIT ?';
1666
1384
  params.push(limit);
1385
+ if (kinds && kinds.length > 0 && !(languages && languages.length > 0)) {
1386
+ const index = this.memoizedRead('nameSubstringIndex', () => this.readNameSubstringIndex());
1387
+ const order = index ? this.substringScanOrder(index, sql, params, excludePrefix ? 2 : 1) : null;
1388
+ const rowids = order ? (0, name_substring_index_1.searchNameSubstring)(index.index, substring, kinds, excludePrefix === true, limit, order) : null;
1389
+ if (rowids) {
1390
+ return this.getNodeRowsByRowid(rowids).map((row) => ({ node: rowToNode(row), score: 1.0 }));
1391
+ }
1392
+ }
1667
1393
  const rows = this.db.prepare(sql).all(...params);
1668
1394
  return rows.map((row) => ({
1669
1395
  node: rowToNode(row),
1670
1396
  score: row.score,
1671
1397
  }));
1672
1398
  }
1673
- // ===========================================================================
1674
- // Edge Operations
1675
- // ===========================================================================
1676
- /** Must run before file replacement/deletion cascades the endpoint edges. */
1399
+ substringScanOrder(memo, sql, params, patternCount) {
1400
+ const key = `${sql}\u0000${params.slice(patternCount).join('\u0000')}`;
1401
+ let order = memo.plans.get(key);
1402
+ if (order === undefined) {
1403
+ order = null;
1404
+ try {
1405
+ const details = this.db.prepare(`EXPLAIN QUERY PLAN ${sql}`).all(...params)
1406
+ .map((row) => row.detail)
1407
+ .filter((detail) => /^(SCAN|SEARCH) (TABLE )?nodes\b/.test(detail));
1408
+ if (details.length === 1) {
1409
+ if (/^SEARCH (TABLE )?nodes USING (COVERING )?INDEX idx_nodes_kind \(/.test(details[0]))
1410
+ order = 'index';
1411
+ else if (/^SCAN (TABLE )?nodes$/.test(details[0]))
1412
+ order = 'rowid';
1413
+ }
1414
+ }
1415
+ catch {
1416
+ order = null;
1417
+ }
1418
+ memo.plans.set(key, order);
1419
+ }
1420
+ return order;
1421
+ }
1422
+ readNameSubstringIndex() {
1423
+ const rows = this.db
1424
+ .prepare(`SELECT rowid AS rowid, kind, name FROM nodes WHERE kind IN (${name_substring_index_1.NAME_SUBSTRING_KINDS.map(() => '?').join(',')})`
1425
+ + ' ORDER BY kind, file_path, start_line, id')
1426
+ .all(...name_substring_index_1.NAME_SUBSTRING_KINDS);
1427
+ const index = (0, name_substring_index_1.buildNameSubstringIndex)(rows);
1428
+ return index ? { index, plans: new Map() } : null;
1429
+ }
1430
+ getNodeRowsByRowid(rowids) {
1431
+ if (rowids.length === 0)
1432
+ return [];
1433
+ const byRowid = new Map();
1434
+ for (let i = 0; i < rowids.length; i += SQLITE_PARAM_CHUNK_SIZE) {
1435
+ const chunk = rowids.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
1436
+ const rows = this.db
1437
+ .prepare(`SELECT rowid AS rowid_, nodes.* FROM nodes WHERE rowid IN (${chunk.map(() => '?').join(',')})`)
1438
+ .all(...chunk);
1439
+ for (const row of rows)
1440
+ byRowid.set(row.rowid_, row);
1441
+ }
1442
+ const out = [];
1443
+ for (const rowid of rowids) {
1444
+ const row = byRowid.get(rowid);
1445
+ if (row)
1446
+ out.push(row);
1447
+ }
1448
+ return out;
1449
+ }
1677
1450
  hasSynthesizedEdgesTouchingFile(filePath) {
1678
1451
  const owned = "CASE WHEN json_valid(e.metadata) THEN json_extract(e.metadata, '$.synthesizedBy') END IS NOT NULL";
1679
1452
  for (const endpoint of ['source', 'target']) {
@@ -1681,7 +1454,6 @@ class QueryBuilder {
1681
1454
  WHERE n.file_path = ? AND ${owned} LIMIT 1`).get(filePath))
1682
1455
  return true;
1683
1456
  }
1684
- // Wiring often lives in a third file, with neither endpoint in it.
1685
1457
  return !!this.db.prepare(`SELECT 1 FROM edges e WHERE ${owned}
1686
1458
  AND CASE WHEN json_valid(e.metadata) THEN json_extract(e.metadata, '$.registeredAt') END >= ?
1687
1459
  AND CASE WHEN json_valid(e.metadata) THEN json_extract(e.metadata, '$.registeredAt') END < ? LIMIT 1`).get(`${filePath}:`, `${filePath};`);
@@ -1692,14 +1464,11 @@ class QueryBuilder {
1692
1464
  replaceSynthesisInputs(files) {
1693
1465
  this.db.transaction(() => {
1694
1466
  this.db.exec('DELETE FROM synthesis_inputs');
1695
- const insert = this.db.prepare('INSERT INTO synthesis_inputs(file_path) VALUES (?)');
1467
+ const insert = this.db.prepare('INSERT OR IGNORE INTO synthesis_inputs(file_path) SELECT path FROM files WHERE path = ?');
1696
1468
  for (const file of files)
1697
1469
  insert.run(file);
1698
1470
  })();
1699
1471
  }
1700
- /**
1701
- * Insert a new edge
1702
- */
1703
1472
  insertEdge(edge) {
1704
1473
  if (!this.stmts.insertEdge) {
1705
1474
  this.stmts.insertEdge = this.db.prepare(`
@@ -1717,9 +1486,6 @@ class QueryBuilder {
1717
1486
  provenance: edge.provenance ?? null,
1718
1487
  });
1719
1488
  }
1720
- /**
1721
- * Insert multiple edges in a transaction
1722
- */
1723
1489
  insertEdges(edges) {
1724
1490
  if (edges.length === 0)
1725
1491
  return;
@@ -1748,21 +1514,14 @@ class QueryBuilder {
1748
1514
  this.runBatched('insertEdges', 'INSERT OR IGNORE INTO edges (source, target, kind, metadata, line, col, provenance) VALUES ', '(?,?,?,?,?,?,?)', rows);
1749
1515
  })();
1750
1516
  }
1751
- /**
1752
- * Delete all edges from a source node
1753
- */
1754
1517
  deleteEdgesBySource(sourceId) {
1755
1518
  if (!this.stmts.deleteEdgesBySource) {
1756
1519
  this.stmts.deleteEdgesBySource = this.db.prepare('DELETE FROM edges WHERE source = ?');
1757
1520
  }
1758
1521
  this.stmts.deleteEdgesBySource.run(sourceId);
1759
1522
  }
1760
- /**
1761
- * Get outgoing edges from a node. Preserve the source/kind index order
1762
- * (calls before imports/references), then break ties deterministically.
1763
- */
1764
- getOutgoingEdges(sourceId, kinds, provenance) {
1765
- if ((kinds && kinds.length > 0) || provenance) {
1523
+ getOutgoingEdges(sourceId, kinds, provenance, limit) {
1524
+ if ((kinds && kinds.length > 0) || provenance || limit !== undefined) {
1766
1525
  let sql = 'SELECT * FROM edges WHERE source = ?';
1767
1526
  const params = [sourceId];
1768
1527
  if (kinds && kinds.length > 0) {
@@ -1774,6 +1533,10 @@ class QueryBuilder {
1774
1533
  params.push(provenance);
1775
1534
  }
1776
1535
  sql += ' ORDER BY kind, target, line, col';
1536
+ if (limit !== undefined) {
1537
+ sql += ' LIMIT ?';
1538
+ params.push(Math.max(0, Math.floor(limit)));
1539
+ }
1777
1540
  const rows = this.edgeKindStmt(sql).all(...params);
1778
1541
  return rows.map(rowToEdge);
1779
1542
  }
@@ -1783,16 +1546,20 @@ class QueryBuilder {
1783
1546
  const rows = this.stmts.getEdgesBySource.all(sourceId);
1784
1547
  return rows.map(rowToEdge);
1785
1548
  }
1786
- /**
1787
- * Get incoming edges to a node. Kind must precede opaque source IDs:
1788
- * file IDs sort before function IDs, so source-first ordering lets imports
1789
- * displace actual calls in capped caller lists. Keep deterministic ties
1790
- * without changing the target/kind index's established kind precedence.
1791
- */
1792
- getIncomingEdges(targetId, kinds) {
1793
- if (kinds && kinds.length > 0) {
1794
- const sql = `SELECT * FROM edges WHERE target = ? AND kind IN (${kinds.map(() => '?').join(',')}) ORDER BY kind, source, line, col`;
1795
- const rows = this.edgeKindStmt(sql).all(targetId, ...kinds);
1549
+ getIncomingEdges(targetId, kinds, limit) {
1550
+ if ((kinds && kinds.length > 0) || limit !== undefined) {
1551
+ let sql = 'SELECT * FROM edges WHERE target = ?';
1552
+ const params = [targetId];
1553
+ if (kinds && kinds.length > 0) {
1554
+ sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
1555
+ params.push(...kinds);
1556
+ }
1557
+ sql += ' ORDER BY kind, source, line, col';
1558
+ if (limit !== undefined) {
1559
+ sql += ' LIMIT ?';
1560
+ params.push(Math.max(0, Math.floor(limit)));
1561
+ }
1562
+ const rows = this.edgeKindStmt(sql).all(...params);
1796
1563
  return rows.map(rowToEdge);
1797
1564
  }
1798
1565
  if (!this.stmts.getEdgesByTarget) {
@@ -1801,13 +1568,6 @@ class QueryBuilder {
1801
1568
  const rows = this.stmts.getEdgesByTarget.all(targetId);
1802
1569
  return rows.map(rowToEdge);
1803
1570
  }
1804
- /**
1805
- * Outgoing edges for MANY source nodes in one query.
1806
- *
1807
- * The batch form of {@link getOutgoingEdges}. Building a nested outline needs
1808
- * the `contains` edges of every container in a file at once; doing that one
1809
- * source at a time is a query per symbol on files that have hundreds.
1810
- */
1811
1571
  getOutgoingEdgesFrom(sourceIds, kinds) {
1812
1572
  if (sourceIds.length === 0)
1813
1573
  return [];
@@ -1828,15 +1588,6 @@ class QueryBuilder {
1828
1588
  }
1829
1589
  return out;
1830
1590
  }
1831
- /**
1832
- * Fan-in (total incoming edge count) for MANY nodes in one query.
1833
- *
1834
- * The per-node alternative — `getIncomingEdges(id).length` — is an indexed
1835
- * lookup each, but a symbol screen rendering a couple of hundred callees
1836
- * would issue a couple of hundred of them. Ids with no incoming edges are
1837
- * absent from the map rather than present as 0, so callers can tell "no
1838
- * edges" from "not asked about".
1839
- */
1840
1591
  countIncomingEdges(ids) {
1841
1592
  const out = new Map();
1842
1593
  if (ids.length === 0)
@@ -1846,18 +1597,14 @@ class QueryBuilder {
1846
1597
  const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
1847
1598
  const placeholders = chunk.map(() => '?').join(',');
1848
1599
  const rows = this.db
1849
- .prepare(`SELECT target, COUNT(*) AS count FROM edges WHERE target IN (${placeholders}) GROUP BY target`)
1600
+ .prepare(`SELECT target, COUNT(*) AS count FROM edges WHERE target IN (${placeholders})
1601
+ AND (metadata IS NULL OR metadata NOT LIKE '%"synthesizedBy":"test-request"%') GROUP BY target`)
1850
1602
  .all(...chunk);
1851
1603
  for (const row of rows)
1852
1604
  out.set(row.target, row.count);
1853
1605
  }
1854
1606
  return out;
1855
1607
  }
1856
- /**
1857
- * Incoming edges for MANY target nodes in one query — the mirror of
1858
- * {@link getOutgoingEdgesFrom}. Needed wherever a whole file's inbound edges
1859
- * are wanted at once ("which files import anything in this one?").
1860
- */
1861
1608
  getIncomingEdgesTo(targetIds, kinds) {
1862
1609
  if (targetIds.length === 0)
1863
1610
  return [];
@@ -1878,11 +1625,6 @@ class QueryBuilder {
1878
1625
  }
1879
1626
  return out;
1880
1627
  }
1881
- /**
1882
- * Fan-out (total outgoing edge count) for MANY nodes in one query — the
1883
- * mirror of {@link countIncomingEdges}. Ids with no outgoing edges are absent
1884
- * from the map rather than present as 0.
1885
- */
1886
1628
  countOutgoingEdges(ids) {
1887
1629
  const out = new Map();
1888
1630
  if (ids.length === 0)
@@ -1899,32 +1641,13 @@ class QueryBuilder {
1899
1641
  }
1900
1642
  return out;
1901
1643
  }
1902
- /**
1903
- * Symbols nothing in the index points at — the candidate set behind the dead
1904
- * code list (`src/graph/dead-code.ts`).
1905
- *
1906
- * "Points at" is every edge kind EXCEPT `contains`: a class containing a
1907
- * method is structure, not use, and counting it would make every member look
1908
- * reached by its own container. A self-edge is excluded for the same reason
1909
- * a recursive function is not its own caller.
1910
- *
1911
- * One scan, one index probe per candidate. `NOT EXISTS` over
1912
- * `idx_edges_target_kind` is what keeps it that way — the alternative
1913
- * (`LEFT JOIN edges … GROUP BY`) builds a row per edge for the whole table
1914
- * before discarding all but the empty groups. Ordered by position so the
1915
- * answer is stable across runs and groups by file without a second sort.
1916
- *
1917
- * The result is deliberately NOT called dead code: an unreferenced symbol is
1918
- * a symbol with no STATIC reference, and the caller applies the exclusions
1919
- * (tests, generated files, overrides, unresolved names) that turn the
1920
- * candidate set into a claim worth making.
1921
- */
1922
1644
  getUnreferencedNodes(kinds, limit) {
1923
1645
  if (kinds.length === 0 || limit <= 0)
1924
1646
  return [];
1925
1647
  const placeholders = kinds.map(() => '?').join(',');
1648
+ const generated = this.hasSchema('files', 'generated') ? 'COALESCE(f.generated, 0)' : '0';
1926
1649
  const rows = this.db
1927
- .prepare(`SELECT n.*, COALESCE(f.generated, 0) AS file_generated
1650
+ .prepare(`SELECT n.*, ${generated} AS file_generated
1928
1651
  FROM nodes n
1929
1652
  LEFT JOIN files f ON f.path = n.file_path
1930
1653
  WHERE n.kind IN (${placeholders})
@@ -1939,84 +1662,84 @@ class QueryBuilder {
1939
1662
  .all(...kinds, limit);
1940
1663
  return rows.map((row) => ({ node: rowToNode(row), generated: row.file_generated === 1 }));
1941
1664
  }
1942
- /**
1943
- * Which of `names` the index holds an UNRESOLVED reference to.
1944
- *
1945
- * The point is honesty about our own blind spots. A `failed` row in
1946
- * `unresolved_refs` records that some file referenced a name and the resolver
1947
- * could not decide what it meant — so a symbol with that name cannot be
1948
- * called unreferenced, whatever the edge table says. It is deliberately
1949
- * matched loosely, on the reference name AND on its tail (`util.greet` →
1950
- * `greet`), because the question being asked is "could this name be the one
1951
- * we failed to follow", and a maybe has to count as a yes.
1952
- *
1953
- * Bounded-lookup like {@link getGeneratedPathsAmong}: the caller holds a
1954
- * candidate list, so this is a chunked probe over `idx_unresolved_name`, not
1955
- * a scan of the table.
1956
- */
1957
1665
  getUnresolvedNamesAmong(names) {
1958
1666
  const unique = [...new Set(names)].filter((name) => name.length > 0);
1959
1667
  const found = new Set();
1960
1668
  if (unique.length === 0)
1961
1669
  return found;
1670
+ const parked = this.hasSchema('unresolved_refs', 'status');
1962
1671
  for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
1963
1672
  const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
1964
1673
  const placeholders = chunk.map(() => '?').join(',');
1965
- const rows = this.db
1966
- .prepare(`SELECT DISTINCT reference_name AS name FROM unresolved_refs
1967
- WHERE reference_name IN (${placeholders})
1674
+ const byName = `SELECT DISTINCT reference_name AS name FROM unresolved_refs
1675
+ WHERE reference_name IN (${placeholders})`;
1676
+ const rows = (parked
1677
+ ? this.db
1678
+ .prepare(`${byName}
1968
1679
  UNION
1969
1680
  SELECT DISTINCT name_tail AS name FROM unresolved_refs
1970
- WHERE name_tail IN (${placeholders})`)
1971
- .all(...chunk, ...chunk);
1681
+ WHERE name_tail IN (${placeholders})
1682
+ UNION
1683
+ SELECT DISTINCT ${reference_tail_1.MEMBER_TAIL_SQL} AS name FROM unresolved_refs
1684
+ WHERE ${reference_tail_1.MODULE_PARKED_SQL} AND ${reference_tail_1.MEMBER_TAIL_SQL} IN (${placeholders})`)
1685
+ .all(...chunk, ...chunk, ...chunk)
1686
+ : this.db.prepare(byName).all(...chunk));
1972
1687
  for (const row of rows)
1973
1688
  found.add(row.name);
1974
1689
  }
1975
1690
  return found;
1976
1691
  }
1977
- /**
1978
- * Which of `nodeIds` extend or implement a type the resolver could not follow.
1979
- * An ancestor outside the index (`React.Component`, `stream.Transform`, a
1980
- * framework interface) leaves no edge, only this `extends` / `implements`
1981
- * row, so it is the one record that such an ancestor exists (#1973).
1982
- * Chunked probe over `idx_unresolved_from_node`.
1983
- */
1984
1692
  getUnresolvedSupertypeSourcesAmong(nodeIds) {
1693
+ return new Set(this.getUnresolvedReferenceNamesFrom(nodeIds, ['extends', 'implements']).keys());
1694
+ }
1695
+ getUnresolvedReferenceNamesFrom(nodeIds, kinds) {
1985
1696
  const unique = [...new Set(nodeIds)];
1986
- const found = new Set();
1697
+ const found = new Map();
1698
+ if (unique.length === 0 || kinds.length === 0)
1699
+ return found;
1700
+ const kindPlaceholders = kinds.map(() => '?').join(',');
1987
1701
  for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
1988
1702
  const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
1989
1703
  const placeholders = chunk.map(() => '?').join(',');
1990
1704
  const rows = this.db
1991
- .prepare(`SELECT DISTINCT from_node_id AS id FROM unresolved_refs
1705
+ .prepare(`SELECT DISTINCT from_node_id AS id, reference_name AS name FROM unresolved_refs
1992
1706
  WHERE from_node_id IN (${placeholders})
1993
- AND reference_kind IN ('extends', 'implements')`)
1994
- .all(...chunk);
1995
- for (const row of rows)
1996
- found.add(row.id);
1707
+ AND reference_kind IN (${kindPlaceholders})`)
1708
+ .all(...chunk, ...kinds);
1709
+ for (const row of rows) {
1710
+ const names = found.get(row.id);
1711
+ if (names)
1712
+ names.push(row.name);
1713
+ else
1714
+ found.set(row.id, [row.name]);
1715
+ }
1716
+ }
1717
+ return found;
1718
+ }
1719
+ getUnresolvedReferenceSourcesNamed(names, kinds) {
1720
+ const unique = [...new Set(names)].filter((name) => name.length > 0);
1721
+ const found = new Map();
1722
+ if (unique.length === 0 || kinds.length === 0)
1723
+ return found;
1724
+ const kindPlaceholders = kinds.map(() => '?').join(',');
1725
+ for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
1726
+ const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
1727
+ const placeholders = chunk.map(() => '?').join(',');
1728
+ const rows = this.db
1729
+ .prepare(`SELECT DISTINCT reference_name AS name, from_node_id AS id FROM unresolved_refs
1730
+ WHERE reference_name IN (${placeholders})
1731
+ AND reference_kind IN (${kindPlaceholders})`)
1732
+ .all(...chunk, ...kinds);
1733
+ for (const row of rows) {
1734
+ const ids = found.get(row.name);
1735
+ if (ids)
1736
+ ids.add(row.id);
1737
+ else
1738
+ found.set(row.name, new Set([row.id]));
1739
+ }
1997
1740
  }
1998
1741
  return found;
1999
1742
  }
2000
- /**
2001
- * Which of `names` are carried by MORE THAN ONE symbol, at least one of which
2002
- * something points at.
2003
- *
2004
- * The false positive this exists to kill: `CodeGraph.getTopRouteFile` calls
2005
- * `this.queries.getTopRouteFile()`, and the resolver — which prefers a
2006
- * same-name definition in the call site's own file — attaches that edge to
2007
- * the *calling* method. One of the two ends up with a self-edge and the other
2008
- * with nothing at all, and neither is unreferenced. From the edge table the
2009
- * mis-resolution and a genuinely unused twin are the same picture, so the
2010
- * claim is not made about either.
2011
- *
2012
- * Both halves of the condition are load-bearing. **More than one symbol**:
2013
- * a uniquely-named function that only calls itself is genuinely dead, and
2014
- * excluding every recursive function would gut the list. **Self-edges
2015
- * counted**: the self-edge IS the fingerprint of the mis-resolution above, so
2016
- * it has to count as evidence that this name resolves somewhere.
2017
- *
2018
- * Chunked probe over `idx_nodes_name`, bounded by the caller's candidate list.
2019
- */
2020
1743
  getAmbiguousReferencedNames(names) {
2021
1744
  const unique = [...new Set(names)].filter((name) => name.length > 0);
2022
1745
  const found = new Set();
@@ -2043,22 +1766,6 @@ class QueryBuilder {
2043
1766
  }
2044
1767
  return found;
2045
1768
  }
2046
- /**
2047
- * Which of the given languages the index records an EXPORT marker for.
2048
- *
2049
- * A self-measurement, and the honest basis for a whole class of exclusion.
2050
- * The dead code report's strongest filter is "exported symbols may be reached
2051
- * from outside this repository" — and that filter silently does nothing for a
2052
- * language whose exports are not recorded, either because the extractor does
2053
- * not record them (Rust `pub`) or because the language has no such concept at
2054
- * all (Python, C, Ruby: the header or the module IS the surface). Rather than
2055
- * carry a table of which is which, ask the index: if nothing in this language
2056
- * is marked exported, the filter did not run, and no claim about outside
2057
- * reachability can be made for it.
2058
- *
2059
- * `idx_nodes_language` covers the grouping; the caller passes the handful of
2060
- * languages its candidates are actually in.
2061
- */
2062
1769
  getLanguagesWithExports(languages) {
2063
1770
  const unique = [...new Set(languages)].filter((language) => language.length > 0);
2064
1771
  const found = new Set();
@@ -2079,17 +1786,6 @@ class QueryBuilder {
2079
1786
  }
2080
1787
  return found;
2081
1788
  }
2082
- /**
2083
- * The nodes with the most DISTINCT dependents, most first.
2084
- *
2085
- * "Distinct" is the difference that matters: a helper called forty times from
2086
- * one function has a fan-in of 40 but exactly one dependent. This counts the
2087
- * second thing — the number a reader means by "N callers" — so the top of
2088
- * this list is the set of symbols a change actually radiates furthest from.
2089
- *
2090
- * `contains` is excluded because it is structure, not dependency: counting it
2091
- * would rank every file and class above the code they hold.
2092
- */
2093
1789
  getTopDependedOn(limit) {
2094
1790
  if (limit <= 0)
2095
1791
  return [];
@@ -2103,30 +1799,6 @@ class QueryBuilder {
2103
1799
  .all(limit);
2104
1800
  return rows;
2105
1801
  }
2106
- /**
2107
- * The graph's executable roots — files that RUN something at module level,
2108
- * ranked by how much of the project they set in motion.
2109
- *
2110
- * The engine records a statement at the top level of a file as an edge from
2111
- * the *file* node, so `src/bin/codegraph.ts` calling `program.parse()` at
2112
- * module scope is a `calls` edge out of a `file`. That set is what makes the
2113
- * roots of a dependency graph visible: a library module holds definitions and
2114
- * runs nothing until someone imports it, while a CLI, a worker entry or a
2115
- * build script does its work on the way down the file. `instantiates` counts
2116
- * the same way — `new Server(...)` at module scope is the same act.
2117
- *
2118
- * A call made while initializing a module-level `variable` / `constant` —
2119
- * `const service = new Service()`, `app = FastAPI()` — is attributed to the
2120
- * declared name (#693), not to the file, so the file's own edges alone would
2121
- * miss most of what a real entry point runs. Those names are the file's
2122
- * top-level code too, so `tops` counts them alongside the file node.
2123
- *
2124
- * Ranking multiplies the two things an entry point does: it runs (calls), and
2125
- * it wires the project together (distinct other files its symbols reach). One
2126
- * alone is misleading — a registration table makes hundreds of module-level
2127
- * calls into itself, and a barrel file imports everything and runs nothing.
2128
- * The product puts the file that does both at the top.
2129
- */
2130
1802
  getTopCallingFiles(limit) {
2131
1803
  if (limit <= 0)
2132
1804
  return [];
@@ -2175,15 +1847,6 @@ class QueryBuilder {
2175
1847
  LIMIT ?`)
2176
1848
  .all(limit);
2177
1849
  }
2178
- /**
2179
- * How many OTHER files depend on each of the given files.
2180
- *
2181
- * Counted through the symbols, not the file nodes: an `imports` edge points
2182
- * at the imported symbol, so a file node almost never receives one and
2183
- * counting edges into it would report every file as depended on by nobody.
2184
- * Same-file edges are excluded, which is what makes zero mean "nothing else
2185
- * in the index reaches into this file" — the honest reading of a root.
2186
- */
2187
1850
  getFileDependentCounts(filePaths) {
2188
1851
  if (filePaths.length === 0)
2189
1852
  return [];
@@ -2198,17 +1861,6 @@ class QueryBuilder {
2198
1861
  GROUP BY tn.file_path`)
2199
1862
  .all(JSON.stringify(filePaths));
2200
1863
  }
2201
- /**
2202
- * How far each of the given files reaches OUT: distinct other files its
2203
- * symbols touch, and how many references that is.
2204
- *
2205
- * The mirror of {@link getFileDependentCounts}, and the same reasoning about
2206
- * `contains` and same-file edges applies. It is driven from `nodes` rather
2207
- * than from `edges` so the work is proportional to the files asked about —
2208
- * the entry-points endpoint asks it about every test file in the index, and
2209
- * an edge-first plan would scan the whole table to answer a question about a
2210
- * tenth of it.
2211
- */
2212
1864
  getFileReachCounts(filePaths) {
2213
1865
  if (filePaths.length === 0)
2214
1866
  return [];
@@ -2225,13 +1877,6 @@ class QueryBuilder {
2225
1877
  GROUP BY sn.file_path`)
2226
1878
  .all(JSON.stringify(filePaths));
2227
1879
  }
2228
- /**
2229
- * The `file` nodes for the given paths, in one query.
2230
- *
2231
- * A file's own node is what makes a file row navigable, and looking it up
2232
- * with {@link getNodesInFile} means materialising every symbol in the file to
2233
- * throw all but one away.
2234
- */
2235
1880
  getFileNodes(filePaths) {
2236
1881
  if (filePaths.length === 0)
2237
1882
  return [];
@@ -2242,39 +1887,6 @@ class QueryBuilder {
2242
1887
  .all(JSON.stringify(filePaths));
2243
1888
  return rows.map(rowToNode);
2244
1889
  }
2245
- /**
2246
- * Roll the whole edge table up to module granularity in one pass.
2247
- *
2248
- * The caller decides what a module IS — it hands in a file → module
2249
- * assignment and gets back the cross-module traffic. That split is
2250
- * deliberate: naming modules is a *policy* (top-level directories, a façade
2251
- * file kept separate, a monorepo root) that belongs where the reader lives,
2252
- * while grouping a million edges by it is *mechanics* that must happen in
2253
- * SQLite. Doing the fold in JavaScript instead means materialising every
2254
- * cross-file edge in memory; doing the naming in SQL means a tower of
2255
- * `instr`/`substr` no one can read.
2256
- *
2257
- * The assignment lands in a TEMP table with a primary key, so the join is
2258
- * indexed and the result set is bounded by modules², not by edges. Temp
2259
- * tables live in SQLite's own temp database, so this stays valid against a
2260
- * read-only main.
2261
- *
2262
- * Two result sets, because they need two different groupings over the same
2263
- * join: `links` counts edges per (module, module, kind), and `pairs` names
2264
- * the busiest symbol pairs behind each link (the map's tooltip). `pairs` is
2265
- * ranked and cut inside SQLite — the un-cut grouping is the one thing here
2266
- * that scales with distinct symbol names rather than with modules. Pairs are
2267
- * ranked by `declared` before raw count, so a link's tooltip names the
2268
- * symbols the source actually points at rather than whichever `has`/`get`
2269
- * happened to name-match most often.
2270
- *
2271
- * `declared` is the subset of a link's edges that came from something the
2272
- * source *writes down*: an import, a qualified name, an inheritance clause,
2273
- * or a call through a typed receiver. It exists because bare name matching
2274
- * (`resolvedBy: 'exact-match'`) is what invents cross-module links out of
2275
- * common method names — `run`, `push`, `finish` — and a map that lets those
2276
- * decide the layering puts the storage layer above the CLI.
2277
- */
2278
1890
  aggregateModuleGraph(assignments, options) {
2279
1891
  if (assignments.length === 0 || options.kinds.length === 0)
2280
1892
  return { links: [], pairs: [] };
@@ -2297,13 +1909,6 @@ class QueryBuilder {
2297
1909
  this.db.exec('ROLLBACK');
2298
1910
  throw err;
2299
1911
  }
2300
- // ONE pass over the edge table. Grouping by the symbol names as well as
2301
- // the modules costs nothing extra in scan time — the join is what is
2302
- // expensive — and it buys both results from a single scan. Measured on
2303
- // this index inflated to 1.6M edges: 1.66s for this query against 3.0s
2304
- // for the module-level and name-level queries run separately, which is
2305
- // the difference between meeting and missing the map's cold budget on a
2306
- // ten-thousand-file repository.
2307
1912
  const rows = this.db
2308
1913
  .prepare(`SELECT ms.mod AS source, mt.mod AS target, e.kind AS kind,
2309
1914
  sn.name AS "from", tn.name AS "to",
@@ -2325,20 +1930,6 @@ class QueryBuilder {
2325
1930
  this.db.exec('DROP TABLE IF EXISTS temp.cg_module_map');
2326
1931
  }
2327
1932
  }
2328
- /**
2329
- * Every ordered pair of files where one reaches into the other, once each.
2330
- *
2331
- * The input a cycle finder wants: file-level circular dependencies are the
2332
- * strongly connected components of this graph. One query instead of the
2333
- * dependency lookup per file that {@link GraphQueryManager.findCircularDependencies}
2334
- * does — which matters because a cycle report is only interesting on a large
2335
- * repo, and that is exactly where a query per file stops being affordable.
2336
- *
2337
- * `contains` is excluded (a file "contains" its own symbols, which is not a
2338
- * dependency), and so are same-file edges and low-confidence name matches:
2339
- * a cycle conjured by a common method name is a false alarm a reader cannot
2340
- * check.
2341
- */
2342
1933
  getCrossFileDependencyPairs(minConfidence) {
2343
1934
  return this.db
2344
1935
  .prepare(`SELECT DISTINCT sn.file_path AS source, tn.file_path AS target
@@ -2350,20 +1941,16 @@ class QueryBuilder {
2350
1941
  AND COALESCE(json_extract(e.metadata, '$.confidence'), 1) >= ?`)
2351
1942
  .all(minConfidence);
2352
1943
  }
2353
- /**
2354
- * Every unresolved reference recorded in one FILE, ordered by line.
2355
- *
2356
- * The per-symbol form above answers "what does this body reach that the
2357
- * index does not hold". A whole-file reader asks the same question of every
2358
- * line at once, and asking it one symbol at a time is a query per symbol —
2359
- * 153 of them on this repo's largest file. `unresolved_refs.file_path` is
2360
- * indexed, so this is one lookup whatever the file holds.
2361
- *
2362
- * `limit` bounds the answer rather than the work: the caller draws a marker
2363
- * per row, and a generated file with fifty thousand of them would ship
2364
- * megabytes to say something a count already says. Rows come back in line
2365
- * order, so a cap trims the END of the file, which is at least legible.
2366
- */
1944
+ getFileImportPairs() {
1945
+ return this.db
1946
+ .prepare(`SELECT DISTINCT sn.file_path AS source, tn.file_path AS target
1947
+ FROM edges e
1948
+ JOIN nodes sn ON sn.id = e.source
1949
+ JOIN nodes tn ON tn.id = e.target
1950
+ WHERE e.kind = 'imports'
1951
+ AND sn.file_path <> tn.file_path`)
1952
+ .all();
1953
+ }
2367
1954
  getUnresolvedReferencesInFile(filePath, limit = 5000) {
2368
1955
  if (!this.stmts.getUnresolvedInFile) {
2369
1956
  this.stmts.getUnresolvedInFile = this.db.prepare('SELECT * FROM unresolved_refs WHERE file_path = ? ORDER BY line, col LIMIT ?');
@@ -2381,15 +1968,6 @@ class QueryBuilder {
2381
1968
  rowId: row.id,
2382
1969
  }));
2383
1970
  }
2384
- /**
2385
- * References recorded against a symbol that never resolved to a node — the
2386
- * calls and type mentions that leave the index (a third-party package, a
2387
- * runtime builtin, a language construct extraction doesn't model).
2388
- *
2389
- * Read-only. It exists so a reader can say "N calls into symbols outside the
2390
- * index" instead of silently showing a callee list shorter than the body's
2391
- * call sites, which reads as "nothing else happens here".
2392
- */
2393
1971
  getUnresolvedReferencesFrom(fromNodeId) {
2394
1972
  if (!this.stmts.getUnresolvedFromNode) {
2395
1973
  this.stmts.getUnresolvedFromNode = this.db.prepare('SELECT * FROM unresolved_refs WHERE from_node_id = ?');
@@ -2407,10 +1985,35 @@ class QueryBuilder {
2407
1985
  rowId: row.id,
2408
1986
  }));
2409
1987
  }
2410
- /**
2411
- * Find all edges where both source and target are in the given node set.
2412
- * Useful for recovering inter-node connectivity after BFS.
2413
- */
1988
+ getUnresolvedReferencesFromNodes(nodeIds, kinds) {
1989
+ const unique = [...new Set(nodeIds)];
1990
+ const found = [];
1991
+ if (unique.length === 0 || kinds.length === 0)
1992
+ return found;
1993
+ const kindPlaceholders = kinds.map(() => '?').join(',');
1994
+ for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
1995
+ const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
1996
+ const placeholders = chunk.map(() => '?').join(',');
1997
+ const rows = this.db
1998
+ .prepare(`SELECT * FROM unresolved_refs
1999
+ WHERE from_node_id IN (${placeholders})
2000
+ AND reference_kind IN (${kindPlaceholders})`)
2001
+ .all(...chunk, ...kinds);
2002
+ for (const row of rows) {
2003
+ found.push({
2004
+ fromNodeId: row.from_node_id,
2005
+ referenceName: row.reference_name,
2006
+ referenceKind: row.reference_kind,
2007
+ line: row.line,
2008
+ column: row.col,
2009
+ filePath: row.file_path,
2010
+ language: row.language,
2011
+ rowId: row.id,
2012
+ });
2013
+ }
2014
+ }
2015
+ return found;
2016
+ }
2414
2017
  findEdgesBetweenNodes(nodeIds, kinds) {
2415
2018
  if (nodeIds.length === 0)
2416
2019
  return [];
@@ -2424,22 +2027,6 @@ class QueryBuilder {
2424
2027
  const rows = this.db.prepare(sql).all(...params);
2425
2028
  return rows.map(rowToEdge);
2426
2029
  }
2427
- /**
2428
- * Distinct file paths that DEPEND ON `filePath`: every file containing a
2429
- * symbol with a cross-file edge (any kind except `contains`) into a symbol
2430
- * of this file. This is the file-level projection of the symbol dependency
2431
- * graph and the basis for blast-radius / `affected` test selection.
2432
- *
2433
- * It deliberately does NOT restrict to `imports` edges. In this graph an
2434
- * `imports` edge connects a file to its own local import declarations
2435
- * (it is always same-file), so an imports-only lookup returns zero
2436
- * cross-file dependents for every file. The real cross-file dependency
2437
- * signal is the resolved call/reference graph — calls, references,
2438
- * instantiates, extends, implements, overrides, type_of, returns,
2439
- * decorates — exactly what {@link GraphTraverser.getImpactRadius} traverses.
2440
- * `contains` is excluded: a parent containing a symbol does not *depend* on
2441
- * it. One indexed query (idx_nodes_file_path + idx_edges_target_kind).
2442
- */
2443
2030
  getDependentFilePaths(filePath) {
2444
2031
  const sql = `SELECT DISTINCT src.file_path AS fp
2445
2032
  FROM edges e
@@ -2451,12 +2038,6 @@ class QueryBuilder {
2451
2038
  const rows = this.db.prepare(sql).all(filePath, filePath);
2452
2039
  return rows.map((r) => r.fp);
2453
2040
  }
2454
- /**
2455
- * Distinct file paths that `filePath` DEPENDS ON — the inverse of
2456
- * {@link getDependentFilePaths}: every file containing a symbol that a
2457
- * symbol of this file has a cross-file edge into. Same edge-kind rules
2458
- * (all kinds except `contains`); same reason imports-only is insufficient.
2459
- */
2460
2041
  getDependencyFilePaths(filePath) {
2461
2042
  const sql = `SELECT DISTINCT tgt.file_path AS fp
2462
2043
  FROM edges e
@@ -2468,16 +2049,6 @@ class QueryBuilder {
2468
2049
  const rows = this.db.prepare(sql).all(filePath, filePath);
2469
2050
  return rows.map((r) => r.fp);
2470
2051
  }
2471
- /**
2472
- * Cross-file edges whose TARGET is a node in `filePath` and whose SOURCE is a
2473
- * node in a *different* file, paired with the target node's (name, kind) so a
2474
- * caller can re-resolve the edge to the re-indexed target's new ID (node IDs
2475
- * are `sha256(filePath:kind:name:line)`, so any line shift in the callee file
2476
- * changes target IDs and a naive re-insert by old ID silently drops them).
2477
- * Used by `storeExtractionResult` to preserve incoming edges across a file
2478
- * re-index (issue #899). Same edge-kind rules as
2479
- * {@link getDependentFilePaths}: all kinds except `contains`.
2480
- */
2481
2052
  getCrossFileIncomingEdgesWithTarget(filePath) {
2482
2053
  const sql = `SELECT e.*, tgt.name AS target_name, tgt.kind AS target_kind,
2483
2054
  src.file_path AS source_file_path, src.language AS source_language
@@ -2490,18 +2061,216 @@ class QueryBuilder {
2490
2061
  const rows = this.db.prepare(sql).all(filePath, filePath);
2491
2062
  return rows.map(row => ({
2492
2063
  ...rowToEdge(row),
2064
+ edgeId: row.id,
2493
2065
  targetName: row.target_name,
2494
2066
  targetKind: row.target_kind,
2495
2067
  sourceFilePath: row.source_file_path,
2496
2068
  sourceLanguage: row.source_language,
2497
2069
  }));
2498
2070
  }
2499
- // ===========================================================================
2500
- // File Operations
2501
- // ===========================================================================
2502
- /**
2503
- * Insert or update a file record
2504
- */
2071
+ getResolutionEdgesThrough(filePath, names) {
2072
+ const rows = this.db
2073
+ .prepare(`SELECT * FROM (
2074
+ SELECT e.*, src.file_path AS source_file_path, src.language AS source_language, tgt.file_path AS target_file_path,
2075
+ CASE WHEN json_valid(e.metadata) THEN json_extract(e.metadata, '$.refName') END AS ref_name
2076
+ FROM nodes src
2077
+ JOIN edges e ON e.source = src.id
2078
+ JOIN nodes tgt ON tgt.id = e.target
2079
+ WHERE src.file_path = ?
2080
+ AND e.kind != 'contains'
2081
+ AND (e.provenance IS NULL OR e.provenance != 'heuristic')
2082
+ ) WHERE ${THROUGH_NAMES('ref_name')}`)
2083
+ .all(filePath, JSON.stringify(names), JSON.stringify(names));
2084
+ return rows.map((row) => ({
2085
+ ...rowToEdge(row),
2086
+ edgeId: row.id,
2087
+ sourceFilePath: row.source_file_path,
2088
+ sourceLanguage: row.source_language,
2089
+ targetFilePath: row.target_file_path,
2090
+ }));
2091
+ }
2092
+ getImportBindingsResolvedElsewhere(filePaths) {
2093
+ const out = [];
2094
+ const unique = [...new Set(filePaths)].map((filePath) => `file:${filePath}`);
2095
+ for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
2096
+ const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
2097
+ const placeholders = chunk.map(() => '?').join(',');
2098
+ const rows = this.db
2099
+ .prepare(`SELECT e.*, src.file_path AS source_file_path, src.language AS source_language, tgt.file_path AS target_file_path
2100
+ FROM edges e
2101
+ JOIN nodes src ON src.id = e.source
2102
+ JOIN nodes tgt ON tgt.id = e.target
2103
+ WHERE e.source IN (${placeholders})
2104
+ AND e.kind = 'imports'
2105
+ AND (e.provenance IS NULL OR e.provenance != 'heuristic')
2106
+ AND json_valid(e.metadata)
2107
+ AND json_extract(e.metadata, '$.resolvedBy') != 'import'`)
2108
+ .all(...chunk);
2109
+ for (const row of rows) {
2110
+ out.push({
2111
+ ...rowToEdge(row),
2112
+ edgeId: row.id,
2113
+ sourceFilePath: row.source_file_path,
2114
+ sourceLanguage: row.source_language,
2115
+ targetFilePath: row.target_file_path,
2116
+ });
2117
+ }
2118
+ }
2119
+ return out;
2120
+ }
2121
+ getResolutionEdgesInto(targetIds) {
2122
+ const out = [];
2123
+ const unique = [...new Set(targetIds)];
2124
+ for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
2125
+ const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
2126
+ const placeholders = chunk.map(() => '?').join(',');
2127
+ const rows = this.db
2128
+ .prepare(`SELECT e.*, src.file_path AS source_file_path, src.language AS source_language, tgt.file_path AS target_file_path
2129
+ FROM edges e
2130
+ JOIN nodes src ON src.id = e.source
2131
+ JOIN nodes tgt ON tgt.id = e.target
2132
+ WHERE e.target IN (${placeholders})
2133
+ AND e.kind != 'contains'
2134
+ AND (e.provenance IS NULL OR e.provenance != 'heuristic')`)
2135
+ .all(...chunk);
2136
+ for (const row of rows) {
2137
+ out.push({
2138
+ ...rowToEdge(row),
2139
+ edgeId: row.id,
2140
+ sourceFilePath: row.source_file_path,
2141
+ sourceLanguage: row.source_language,
2142
+ targetFilePath: row.target_file_path,
2143
+ });
2144
+ }
2145
+ }
2146
+ return out;
2147
+ }
2148
+ getFailedReferencesThrough(filePath, modules, names) {
2149
+ return this.db
2150
+ .prepare(`SELECT id FROM unresolved_refs
2151
+ WHERE file_path = ? AND status = 'failed'
2152
+ AND ((reference_kind = 'imports' AND reference_name IN (SELECT value FROM json_each(?)))
2153
+ OR ${THROUGH_NAMES('reference_name')})`)
2154
+ .all(filePath, JSON.stringify(modules), JSON.stringify(names), JSON.stringify(names))
2155
+ .map((row) => row.id);
2156
+ }
2157
+ getImportTargetsFromFile(filePath) {
2158
+ return this.db
2159
+ .prepare(`SELECT DISTINCT e.target AS target
2160
+ FROM nodes src
2161
+ JOIN edges e ON e.source = src.id
2162
+ JOIN nodes tgt ON tgt.id = e.target
2163
+ WHERE src.file_path = ?
2164
+ AND e.kind = 'imports'
2165
+ AND (e.provenance IS NULL OR e.provenance != 'heuristic')
2166
+ AND tgt.file_path != ?`)
2167
+ .all(filePath, filePath)
2168
+ .map((row) => row.target);
2169
+ }
2170
+ getImportsInto(targetId, exceptFile) {
2171
+ return this.db
2172
+ .prepare(`SELECT src.file_path AS file_path, src.language AS language,
2173
+ CASE WHEN json_valid(e.metadata) THEN json_extract(e.metadata, '$.refName') END AS ref_name
2174
+ FROM edges e
2175
+ JOIN nodes src ON src.id = e.source
2176
+ WHERE e.target = ? AND e.kind = 'imports' AND src.file_path != ?`)
2177
+ .all(targetId, exceptFile)
2178
+ .map((row) => ({
2179
+ filePath: row.file_path,
2180
+ language: row.language,
2181
+ refName: typeof row.ref_name === 'string' ? row.ref_name : null,
2182
+ }));
2183
+ }
2184
+ getModuleImportsUnder(dir) {
2185
+ const rows = this.db
2186
+ .prepare(`SELECT e.*, tgt.file_path AS target_file_path, src.file_path AS source_file_path, src.language AS source_language
2187
+ FROM nodes tgt
2188
+ JOIN edges e ON e.target = tgt.id AND e.kind = 'imports'
2189
+ JOIN nodes src ON src.id = e.source
2190
+ WHERE tgt.kind = 'file' AND tgt.file_path >= ? AND tgt.file_path < ?`)
2191
+ .all(`${dir}/`, `${dir}0`);
2192
+ return rows.map((row) => ({
2193
+ ...rowToEdge(row),
2194
+ edgeId: row.id,
2195
+ targetFilePath: row.target_file_path,
2196
+ sourceFilePath: row.source_file_path,
2197
+ sourceLanguage: row.source_language,
2198
+ }));
2199
+ }
2200
+ getModuleImportsIntoDeclarationFiles() {
2201
+ const rows = this.db
2202
+ .prepare(`SELECT e.*, tgt.file_path AS target_file_path, src.file_path AS source_file_path, src.language AS source_language
2203
+ FROM nodes tgt
2204
+ JOIN edges e ON e.target = tgt.id AND e.kind = 'imports'
2205
+ JOIN nodes src ON src.id = e.source
2206
+ WHERE tgt.kind = 'file'
2207
+ AND (tgt.file_path LIKE '%.d.ts' OR tgt.file_path LIKE '%.d.mts' OR tgt.file_path LIKE '%.d.cts')`)
2208
+ .all();
2209
+ return rows.map((row) => ({
2210
+ ...rowToEdge(row),
2211
+ edgeId: row.id,
2212
+ targetFilePath: row.target_file_path,
2213
+ sourceFilePath: row.source_file_path,
2214
+ sourceLanguage: row.source_language,
2215
+ }));
2216
+ }
2217
+ getModuleImportsNamed(dir, name) {
2218
+ const base = dir ? `${dir}/${name}` : name;
2219
+ const rows = this.db
2220
+ .prepare(`SELECT e.*, tgt.file_path AS target_file_path, src.file_path AS source_file_path, src.language AS source_language
2221
+ FROM nodes tgt
2222
+ JOIN edges e ON e.target = tgt.id AND e.kind = 'imports'
2223
+ JOIN nodes src ON src.id = e.source
2224
+ WHERE tgt.kind = 'file'
2225
+ AND ((tgt.file_path >= ? AND tgt.file_path < ?) OR (tgt.file_path >= ? AND tgt.file_path < ?) OR tgt.file_path = ?)`)
2226
+ .all(`${base}.`, `${base}/`, `${base}/index.`, `${base}/index/`, `${base}/__init__.py`);
2227
+ return rows
2228
+ .filter((row) => {
2229
+ const file = row.target_file_path;
2230
+ if (file === `${base}/__init__.py`)
2231
+ return true;
2232
+ const index = `${base}/index.`;
2233
+ return !(file.startsWith(index) ? file.slice(index.length) : file.slice(base.length + 1)).includes('/');
2234
+ })
2235
+ .map((row) => ({
2236
+ ...rowToEdge(row),
2237
+ edgeId: row.id,
2238
+ targetFilePath: row.target_file_path,
2239
+ sourceFilePath: row.source_file_path,
2240
+ sourceLanguage: row.source_language,
2241
+ }));
2242
+ }
2243
+ getFilesWithEdgesInto(targetIds) {
2244
+ const files = new Set();
2245
+ for (let i = 0; i < targetIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
2246
+ const chunk = targetIds.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
2247
+ const placeholders = chunk.map(() => '?').join(',');
2248
+ const rows = this.db
2249
+ .prepare(`SELECT DISTINCT src.file_path AS file_path
2250
+ FROM edges e
2251
+ JOIN nodes src ON src.id = e.source
2252
+ WHERE e.target IN (${placeholders})
2253
+ AND e.kind != 'contains'
2254
+ AND (e.provenance IS NULL OR e.provenance != 'heuristic')`)
2255
+ .all(...chunk);
2256
+ for (const row of rows)
2257
+ files.add(row.file_path);
2258
+ }
2259
+ return [...files];
2260
+ }
2261
+ getImportNodesByNames(names) {
2262
+ const out = [];
2263
+ for (let i = 0; i < names.length; i += SQLITE_PARAM_CHUNK_SIZE) {
2264
+ const chunk = names.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
2265
+ const placeholders = chunk.map(() => '?').join(',');
2266
+ const rows = this.db
2267
+ .prepare(`SELECT file_path, name, language FROM nodes WHERE name IN (${placeholders}) AND kind = 'import'`)
2268
+ .all(...chunk);
2269
+ for (const row of rows)
2270
+ out.push({ filePath: row.file_path, name: row.name, language: row.language });
2271
+ }
2272
+ return out;
2273
+ }
2505
2274
  upsertFile(file) {
2506
2275
  if (!this.stmts.upsertFile) {
2507
2276
  this.stmts.upsertFile = this.db.prepare(`
@@ -2527,29 +2296,16 @@ class QueryBuilder {
2527
2296
  indexedAt: file.indexedAt,
2528
2297
  nodeCount: file.nodeCount,
2529
2298
  errors: file.errors ? JSON.stringify(file.errors) : null,
2530
- // The upsert always REWRITES the flag: a file that loses its banner in an
2531
- // edit must lose the flag on the next sync, not keep a stale 1.
2532
2299
  generated: file.generated ? 1 : 0,
2533
2300
  });
2534
2301
  }
2535
- /**
2536
- * Which of `filePaths` the index flagged as tool-generated (schema v9+).
2537
- *
2538
- * Bounded-lookup by design: every consumer already holds a short candidate
2539
- * list (a ranked file group, an FTS result page, a LIMIT-20 aggregate), so
2540
- * this stays a partial-index probe over a handful of paths — no whole-repo
2541
- * set to materialize, and no cache to invalidate, which means a ranking call
2542
- * can never serve a verdict the last sync already replaced.
2543
- *
2544
- * Returns ONLY the content/index signal; callers union it with
2545
- * {@link isGeneratedFile} so pre-v9 databases (column present, all zeros
2546
- * until a re-index) keep the path-only behavior rather than regressing.
2547
- */
2548
2302
  getGeneratedPathsAmong(filePaths) {
2549
2303
  const unique = [...new Set(filePaths)];
2550
2304
  const found = new Set();
2551
2305
  if (unique.length === 0)
2552
2306
  return found;
2307
+ if (!this.hasSchema('files', 'generated'))
2308
+ return found;
2553
2309
  for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
2554
2310
  const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
2555
2311
  const placeholders = chunk.map(() => '?').join(',');
@@ -2561,70 +2317,10 @@ class QueryBuilder {
2561
2317
  }
2562
2318
  return found;
2563
2319
  }
2564
- /**
2565
- * A reusable `(path) => boolean` over a bounded candidate list, unioning the
2566
- * indexed flag with the path convention. This is the shape every ranking
2567
- * comparator wants: one query up front, then O(1) per comparison.
2568
- */
2569
2320
  generatedPredicateFor(filePaths) {
2570
2321
  const flagged = this.getGeneratedPathsAmong(filePaths);
2571
2322
  return (filePath) => flagged.has(filePath) || (0, generated_detection_1.isGeneratedFile)(filePath);
2572
2323
  }
2573
- /**
2574
- * Which of `filePaths` are AMBIENT DECLARATION files — they declare nothing
2575
- * but types, and nothing in the index depends on them (CG-28). A hand-written
2576
- * ambient `.d.ts` of global shims, a vendored typings file, module
2577
- * augmentation: reachable only by name, structurally attached to nothing.
2578
- *
2579
- * Structural, not extension-based, so a hand-written `types.ts` and a `.d.ts`
2580
- * are judged by the same rule and a `.d.ts` that does declare a class or a
2581
- * const is (correctly) not caught. Four conditions, all required:
2582
- *
2583
- * 1. it declares at least one symbol — an empty or unparsed file is not a
2584
- * declaration file, it is a file we know nothing about;
2585
- * 2. EVERY declared symbol is a type-level kind (interface / type alias /
2586
- * enum / namespace). The narrowness is deliberate and measured: a rule
2587
- * of "no callables" alone flags 1–18% of a repo, including Kotlin sealed
2588
- * classes, Rust `mod.rs` re-exports and django's locale constant tables —
2589
- * real source that must not be demoted. This rule flags 0–4%;
2590
- * 3. no symbol in it originates a `calls`/`instantiates` edge — the direct
2591
- * evidence that nothing here has a body;
2592
- * 4. NOTHING ELSE IN THE INDEX points at it. This is the condition that
2593
- * separates an ambient shim from a working type module, and it is why
2594
- * the flag is narrow enough to be safe: `displacement-ts`'s pipeline
2595
- * `types.ts` passes 1–3 identically but carries 13 inbound imports and
2596
- * 21 references, so the files that answer a query about the pipeline are
2597
- * typed BY it — it is part of that answer's structure. An ambient
2598
- * `declare global` shim has zero. Deliberately index-wide rather than
2599
- * restricted to the candidate list: the file that imports it is usually
2600
- * not itself a candidate.
2601
- *
2602
- * ### Interface MEMBERS are transparent to all four conditions
2603
- *
2604
- * A `method_signature` / `property_signature` inside an interface enters the
2605
- * graph as a `method` / `property` node (#1638). Read literally that would
2606
- * break every condition here at once: condition 2 sees non-type kinds and
2607
- * stops flagging, and — worse, because it is silent — condition 4 starts
2608
- * seeing inbound `calls` edges the moment a call site through the shim's API
2609
- * finally has a signature to land on. An ambient `.d.ts` would quietly lose
2610
- * its damping precisely BECAUSE the platform API it declares is widely used.
2611
- *
2612
- * So an interface-owned member is treated the way `parameter` already is: it
2613
- * neither qualifies, disqualifies, nor counts as inbound dependency. That is
2614
- * not a new judgement call, it is what keeps the rule measuring what it was
2615
- * measured on — before #1638 these nodes did not exist, so excluding them
2616
- * reproduces the 0–4% flag rate the thresholds above were tuned against. It
2617
- * is also the semantically right answer: a signature with no body is on the
2618
- * same side of the line as the interface that owns it, and a call edge
2619
- * landing on one is still not a file that can answer a flow question.
2620
- *
2621
- * The interface ITSELF is untouched: the `references` edges an importing
2622
- * module aims at `UploadStorage` still disqualify the file under (4), which
2623
- * is what keeps a depended-on `types.ts` out of the flag.
2624
- *
2625
- * Bounded-lookup like {@link getGeneratedPathsAmong}: callers hold a ranked
2626
- * candidate list, so this is a partial-index probe over a handful of paths.
2627
- */
2628
2324
  getAmbientDeclarationPathsAmong(filePaths) {
2629
2325
  const unique = [...new Set(filePaths)];
2630
2326
  const found = new Set();
@@ -2633,8 +2329,6 @@ class QueryBuilder {
2633
2329
  for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
2634
2330
  const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
2635
2331
  const placeholders = chunk.map(() => '?').join(',');
2636
- // `file`/`import`/`export`/`parameter` are structural bookkeeping, not
2637
- // things the file declares, so they neither qualify nor disqualify.
2638
2332
  const rows = this.db
2639
2333
  .prepare(`
2640
2334
  SELECT n.file_path AS file_path,
@@ -2661,17 +2355,12 @@ class QueryBuilder {
2661
2355
  .all(...candidates).map((r) => r.file_path));
2662
2356
  candidates = candidates.filter((p) => !hit.has(p));
2663
2357
  };
2664
- // (3) originates behaviour — a signature has no body to originate from,
2665
- // so an edge attributed to one is not evidence about this file.
2666
2358
  disqualify(`
2667
2359
  SELECT DISTINCT n.file_path AS file_path
2668
2360
  FROM edges e JOIN nodes n ON n.id = e.source
2669
2361
  WHERE e.kind IN ('calls','instantiates') AND n.file_path IN ($IN$)
2670
2362
  AND NOT ${IS_INTERFACE_MEMBER('n')}
2671
2363
  `);
2672
- // (4) something outside the file depends on it — but a call that lands on
2673
- // an interface's own signature is a use of the API, not a dependency on
2674
- // this file's structure. The edges aimed at the interface still count.
2675
2364
  disqualify(`
2676
2365
  SELECT DISTINCT t.file_path AS file_path
2677
2366
  FROM edges e JOIN nodes t ON t.id = e.target JOIN nodes s ON s.id = e.source
@@ -2683,25 +2372,18 @@ class QueryBuilder {
2683
2372
  }
2684
2373
  return found;
2685
2374
  }
2686
- /**
2687
- * A reusable `(path) => boolean` ambient-declaration test over a bounded
2688
- * candidate list — the shape a ranking comparator wants: one query up front,
2689
- * O(1) per comparison.
2690
- */
2691
2375
  ambientDeclarationPredicateFor(filePaths) {
2692
2376
  const flagged = this.getAmbientDeclarationPathsAmong(filePaths);
2693
2377
  return (filePath) => flagged.has(filePath);
2694
2378
  }
2695
- /** How many indexed files carry the generated flag. Surfaced by `status`. */
2696
2379
  countGeneratedFiles() {
2380
+ if (!this.hasSchema('files', 'generated'))
2381
+ return 0;
2697
2382
  const row = this.db
2698
2383
  .prepare('SELECT COUNT(*) AS n FROM files WHERE generated = 1')
2699
2384
  .get();
2700
2385
  return row?.n ?? 0;
2701
2386
  }
2702
- /**
2703
- * Delete a file record and its nodes
2704
- */
2705
2387
  deleteFile(filePath) {
2706
2388
  this.db.transaction(() => {
2707
2389
  this.deleteNodesByFile(filePath);
@@ -2711,9 +2393,6 @@ class QueryBuilder {
2711
2393
  this.stmts.deleteFile.run(filePath);
2712
2394
  })();
2713
2395
  }
2714
- /**
2715
- * Get a file record by path
2716
- */
2717
2396
  getFileByPath(filePath) {
2718
2397
  if (!this.stmts.getFileByPath) {
2719
2398
  this.stmts.getFileByPath = this.db.prepare('SELECT * FROM files WHERE path = ?');
@@ -2721,9 +2400,12 @@ class QueryBuilder {
2721
2400
  const row = this.stmts.getFileByPath.get(filePath);
2722
2401
  return row ? rowToFileRecord(row) : null;
2723
2402
  }
2724
- /**
2725
- * Get all tracked files
2726
- */
2403
+ hasFilesUnder(dir) {
2404
+ if (!this.stmts.hasFilesUnder) {
2405
+ this.stmts.hasFilesUnder = this.db.prepare('SELECT 1 FROM files WHERE path >= ? AND path < ? LIMIT 1');
2406
+ }
2407
+ return this.stmts.hasFilesUnder.get(`${dir}/`, `${dir}0`) !== undefined;
2408
+ }
2727
2409
  getAllFiles() {
2728
2410
  if (!this.stmts.getAllFiles) {
2729
2411
  this.stmts.getAllFiles = this.db.prepare('SELECT * FROM files ORDER BY path');
@@ -2731,41 +2413,24 @@ class QueryBuilder {
2731
2413
  const rows = this.stmts.getAllFiles.all();
2732
2414
  return rows.map(rowToFileRecord);
2733
2415
  }
2734
- /**
2735
- * Most recent index timestamp (ms since epoch) across all tracked files, or
2736
- * null when nothing is indexed yet. One indexed aggregate, no per-row scan. (#329)
2737
- */
2416
+ getFilesWithoutNodesOrWithErrors() {
2417
+ const rows = this.db
2418
+ .prepare('SELECT * FROM files WHERE node_count = 0 OR errors IS NOT NULL ORDER BY path')
2419
+ .all();
2420
+ return rows.map(rowToFileRecord);
2421
+ }
2738
2422
  getLastIndexedAt() {
2739
2423
  const row = this.db
2740
2424
  .prepare('SELECT MAX(indexed_at) AS last FROM files')
2741
2425
  .get();
2742
2426
  return row?.last ?? null;
2743
2427
  }
2744
- /**
2745
- * The index's revision marker: how far the last sync got, and how many files
2746
- * it left behind — one query, both numbers.
2747
- *
2748
- * This is the cheapest honest answer to "has the index moved since I last
2749
- * looked". `MAX(indexed_at)` alone is not enough: a sync that only DELETES
2750
- * files (a branch checkout that removed a directory) advances nothing, and
2751
- * the graph the viewer is showing has still changed underneath it. The row
2752
- * count catches exactly that case.
2753
- */
2754
2428
  getIndexRevision() {
2755
2429
  const row = this.db
2756
2430
  .prepare('SELECT MAX(indexed_at) AS last, COUNT(*) AS files FROM files')
2757
2431
  .get();
2758
2432
  return { lastIndexedAt: row?.last ?? null, fileCount: row?.files ?? 0 };
2759
2433
  }
2760
- /**
2761
- * Files re-indexed strictly after `since` (ms since epoch), newest first.
2762
- *
2763
- * `total` is the real count; `paths` is capped at `limit`. Used by the
2764
- * viewer's live channel to name what a sync just picked up. A file the same
2765
- * sync DELETED cannot appear here — it has no row left — which is why the
2766
- * caller compares {@link getIndexRevision} as well rather than treating an
2767
- * empty list as "nothing happened".
2768
- */
2769
2434
  getFilesIndexedSince(since, limit) {
2770
2435
  const count = this.db
2771
2436
  .prepare('SELECT COUNT(*) AS n FROM files WHERE indexed_at > ?')
@@ -2775,9 +2440,6 @@ class QueryBuilder {
2775
2440
  .all(since, Math.max(0, limit));
2776
2441
  return { paths: rows.map((r) => r.path), total: count?.n ?? rows.length };
2777
2442
  }
2778
- /**
2779
- * Get files that need re-indexing (hash changed)
2780
- */
2781
2443
  getStaleFiles(currentHashes) {
2782
2444
  const files = this.getAllFiles();
2783
2445
  return files.filter((f) => {
@@ -2785,12 +2447,6 @@ class QueryBuilder {
2785
2447
  return currentHash && currentHash !== f.contentHash;
2786
2448
  });
2787
2449
  }
2788
- // ===========================================================================
2789
- // Unresolved References
2790
- // ===========================================================================
2791
- /**
2792
- * Insert an unresolved reference
2793
- */
2794
2450
  insertUnresolvedRef(ref) {
2795
2451
  if (!this.stmts.insertUnresolved) {
2796
2452
  this.stmts.insertUnresolved = this.db.prepare(`
@@ -2809,9 +2465,6 @@ class QueryBuilder {
2809
2465
  language: ref.language ?? 'unknown',
2810
2466
  });
2811
2467
  }
2812
- /**
2813
- * Insert multiple unresolved references in a transaction
2814
- */
2815
2468
  insertUnresolvedRefsBatch(refs) {
2816
2469
  if (refs.length === 0)
2817
2470
  return;
@@ -2833,18 +2486,12 @@ class QueryBuilder {
2833
2486
  });
2834
2487
  insert();
2835
2488
  }
2836
- /**
2837
- * Delete unresolved references from a node
2838
- */
2839
2489
  deleteUnresolvedByNode(nodeId) {
2840
2490
  if (!this.stmts.deleteUnresolvedByNode) {
2841
2491
  this.stmts.deleteUnresolvedByNode = this.db.prepare('DELETE FROM unresolved_refs WHERE from_node_id = ?');
2842
2492
  }
2843
2493
  this.stmts.deleteUnresolvedByNode.run(nodeId);
2844
2494
  }
2845
- /**
2846
- * Get unresolved references by name (for resolution)
2847
- */
2848
2495
  getUnresolvedByName(name) {
2849
2496
  if (!this.stmts.getUnresolvedByName) {
2850
2497
  this.stmts.getUnresolvedByName = this.db.prepare('SELECT * FROM unresolved_refs WHERE reference_name = ?');
@@ -2862,9 +2509,6 @@ class QueryBuilder {
2862
2509
  rowId: row.id,
2863
2510
  }));
2864
2511
  }
2865
- /**
2866
- * Get all unresolved references
2867
- */
2868
2512
  getUnresolvedReferences() {
2869
2513
  const rows = this.db.prepare('SELECT * FROM unresolved_refs').all();
2870
2514
  return rows.map((row) => ({
@@ -2879,33 +2523,42 @@ class QueryBuilder {
2879
2523
  rowId: row.id,
2880
2524
  }));
2881
2525
  }
2882
- /**
2883
- * Get the count of PENDING (never-attempted) references without loading
2884
- * them into memory. Rows marked status='failed' — attempted by a completed
2885
- * pass, no match — are excluded: they are not outstanding work, only retry
2886
- * candidates for the #1240 sweep, so they must not trip the #1187 orphan
2887
- * sweep or the `status` pending-refs warning.
2888
- */
2526
+ getCppIncludeEdges() {
2527
+ return this.db.prepare(`SELECT s.file_path AS source, t.file_path AS target FROM edges e
2528
+ JOIN nodes s ON s.id = e.source JOIN nodes t ON t.id = e.target
2529
+ WHERE e.kind = 'imports' AND s.kind = 'file' AND t.kind = 'file' AND s.language IN ('c', 'cpp')`).all();
2530
+ }
2531
+ *iterateFailedCppTypeReferences(files) {
2532
+ const rows = this.db.prepare(`SELECT from_node_id, reference_name, reference_kind, line, col, file_path FROM unresolved_refs
2533
+ WHERE +status = 'failed' AND language = 'cpp' AND file_path IN (SELECT value FROM json_each(?))
2534
+ AND (reference_kind = 'instantiates'
2535
+ OR (reference_kind IN ('calls', 'function_ref') AND reference_name GLOB '*::*' AND reference_name NOT GLOB 'std::*')
2536
+ OR (reference_kind = 'calls' AND reference_name GLOB '*.*' AND reference_name NOT GLOB '*(*'))`).iterate(JSON.stringify(files));
2537
+ for (const row of rows) {
2538
+ yield {
2539
+ fromNodeId: row.from_node_id,
2540
+ referenceName: row.reference_name,
2541
+ referenceKind: row.reference_kind,
2542
+ line: row.line,
2543
+ column: row.col,
2544
+ filePath: row.file_path,
2545
+ language: 'cpp',
2546
+ };
2547
+ }
2548
+ this.db.exec('PRAGMA shrink_memory');
2549
+ }
2889
2550
  getUnresolvedReferencesCount() {
2890
2551
  if (!this.stmts.getUnresolvedCount) {
2552
+ if (!this.hasSchema('unresolved_refs', 'status')) {
2553
+ return this.db.prepare('SELECT COUNT(*) as count FROM unresolved_refs').get().count;
2554
+ }
2891
2555
  this.stmts.getUnresolvedCount = this.db.prepare("SELECT COUNT(*) as count FROM unresolved_refs WHERE status = 'pending'");
2892
2556
  }
2893
2557
  const row = this.stmts.getUnresolvedCount.get();
2894
2558
  return row.count;
2895
2559
  }
2896
- /**
2897
- * Get a batch of PENDING unresolved references using LIMIT/OFFSET
2898
- * pagination. Used to process references in bounded memory chunks; failed
2899
- * rows are excluded so the batched drain loop terminates once every row
2900
- * has been attempted.
2901
- */
2902
2560
  getUnresolvedReferencesBatch(offset, limit) {
2903
2561
  if (!this.stmts.getUnresolvedBatch) {
2904
- // ORDER BY rowid is load-bearing for the pipelined resolution loop: it
2905
- // prefetches batch k+1 at OFFSET batch_k.length while batch k's rows are
2906
- // still pending, which is only exact under a stable enumeration. (A plain
2907
- // scan and the status index both return rowid order anyway — this pins
2908
- // it.)
2909
2562
  this.stmts.getUnresolvedBatch = this.db.prepare("SELECT * FROM unresolved_refs WHERE status = 'pending' ORDER BY rowid LIMIT ? OFFSET ?");
2910
2563
  }
2911
2564
  const rows = this.stmts.getUnresolvedBatch.all(limit, offset);
@@ -2921,19 +2574,7 @@ class QueryBuilder {
2921
2574
  rowId: row.id,
2922
2575
  }));
2923
2576
  }
2924
- /**
2925
- * Keyset variant of {@link getUnresolvedReferencesBatch} for the batched
2926
- * resolution loop: seek past the last-seen row id instead of OFFSET-walking.
2927
- * OFFSET reads re-scan the accumulated failed-row prefix on every batch —
2928
- * O(failed rows) per read, measured at 54.6s of the kernel-scale batch loop
2929
- * (§7a.2) — while the seek is O(batch) forever. `id` is the rowid alias, so
2930
- * the enumeration order is identical to the OFFSET reader's.
2931
- */
2932
2577
  getUnresolvedReferencesBatchAfter(afterRowId, limit, prerequisites) {
2933
- // Resolution prerequisites must be committed before dependent calls,
2934
- // even when an interrupted sync queued their rows in a different order
2935
- // from a clean index (#1577). Each phase still seeks by row id in bounded
2936
- // memory; the default preserves the public reader's original enumeration.
2937
2578
  const key = prerequisites === undefined ? 'getUnresolvedBatchAfter'
2938
2579
  : prerequisites ? 'getUnresolvedPrerequisitesAfter' : 'getUnresolvedDependentsAfter';
2939
2580
  if (!this.stmts[key]) {
@@ -2954,9 +2595,6 @@ class QueryBuilder {
2954
2595
  rowId: row.id,
2955
2596
  }));
2956
2597
  }
2957
- /**
2958
- * Get all tracked file paths (lightweight — no full FileRecord objects)
2959
- */
2960
2598
  getAllFilePaths() {
2961
2599
  if (!this.stmts.getAllFilePaths) {
2962
2600
  this.stmts.getAllFilePaths = this.db.prepare('SELECT path FROM files ORDER BY path');
@@ -2964,9 +2602,6 @@ class QueryBuilder {
2964
2602
  const rows = this.stmts.getAllFilePaths.all();
2965
2603
  return rows.map((r) => r.path);
2966
2604
  }
2967
- /**
2968
- * Get all distinct node names (lightweight — just name strings for pre-filtering)
2969
- */
2970
2605
  getAllNodeNames() {
2971
2606
  if (!this.stmts.getAllNodeNames) {
2972
2607
  this.stmts.getAllNodeNames = this.db.prepare('SELECT DISTINCT name FROM nodes');
@@ -2974,29 +2609,70 @@ class QueryBuilder {
2974
2609
  const rows = this.stmts.getAllNodeNames.all();
2975
2610
  return rows.map((r) => r.name);
2976
2611
  }
2977
- /**
2978
- * Stream the distinct node names one row at a time — the incremental
2979
- * counterpart to {@link getAllNodeNames} for callers that need to yield
2980
- * to the event loop mid-scan (resolver cache warm-up on multi-million-node
2981
- * indexes). Fresh statement per call: the iterator holds an open cursor.
2982
- */
2612
+ fuzzyNames() {
2613
+ const read = () => {
2614
+ const names = this.getAllNodeNames();
2615
+ const lowered = names.map((name) => name.toLowerCase());
2616
+ const starts = new Int32Array(names.length + 1);
2617
+ for (let i = 0; i < lowered.length; i++)
2618
+ starts[i + 1] = starts[i] + lowered[i].length + 1;
2619
+ return { names, lowered: lowered.join('\n') + '\n', starts };
2620
+ };
2621
+ return this.memoizedRead('fuzzyNames', read) ?? read();
2622
+ }
2623
+ loweredNodePaths() {
2624
+ const read = () => {
2625
+ const rows = this.db.prepare('SELECT DISTINCT file_path FROM nodes').all();
2626
+ return rows.map((row) => row.file_path.toLowerCase()).join('\n') + '\n';
2627
+ };
2628
+ return this.memoizedRead('loweredNodePaths', read) ?? read();
2629
+ }
2630
+ fieldFiltersCanMatch(filters) {
2631
+ if (filters.names.length > 0) {
2632
+ const names = this.fuzzyNames().lowered;
2633
+ if (!filters.names.some((n) => names.includes(n)))
2634
+ return false;
2635
+ }
2636
+ if (filters.paths.length > 0) {
2637
+ const paths = this.loweredNodePaths();
2638
+ if (!filters.paths.some((p) => paths.includes(p)))
2639
+ return false;
2640
+ }
2641
+ return true;
2642
+ }
2643
+ readQualifiedNameRuns() {
2644
+ const runs = new Set();
2645
+ const rows = this.db.prepare('SELECT DISTINCT qualified_name AS name FROM nodes').all();
2646
+ for (const row of rows) {
2647
+ for (const run of row.name.toLowerCase().split(/[^a-z0-9]+/)) {
2648
+ if (run)
2649
+ runs.add(run);
2650
+ }
2651
+ }
2652
+ return [...runs].join('\n');
2653
+ }
2654
+ getNodeNamesOfKinds(language, kinds) {
2655
+ const rows = this.db
2656
+ .prepare(`SELECT name FROM nodes WHERE kind IN (${kinds.map(() => '?').join(', ')}) AND +language = ?`)
2657
+ .all(...kinds, language);
2658
+ return rows.map((r) => r.name);
2659
+ }
2660
+ getCppIncludeNodes() {
2661
+ if (!this.stmts.getCppIncludeNodes) {
2662
+ this.stmts.getCppIncludeNodes = this.db.prepare(`SELECT id, name, file_path AS filePath, language, start_line AS startLine, start_column AS startColumn
2663
+ FROM nodes WHERE kind = 'import' AND language IN ('c', 'cpp')`);
2664
+ }
2665
+ return this.stmts.getCppIncludeNodes.all();
2666
+ }
2983
2667
  *iterateNodeNames() {
2984
2668
  const stmt = this.db.prepare('SELECT DISTINCT name FROM nodes');
2985
2669
  for (const row of stmt.iterate()) {
2986
2670
  yield row.name;
2987
2671
  }
2988
2672
  }
2989
- /**
2990
- * Get unresolved references scoped to specific file paths.
2991
- * Uses the idx_unresolved_file_path index for efficient lookup.
2992
- */
2993
2673
  getUnresolvedReferencesByFiles(filePaths) {
2994
2674
  if (filePaths.length === 0)
2995
2675
  return [];
2996
- // Chunk under SQLite's parameter limit: the first sync of a very large repo
2997
- // passes every changed file here, which an unbounded `IN (...)` would bind
2998
- // as one parameter each — exceeding MAX_VARIABLE_NUMBER and aborting with
2999
- // "too many SQL variables". (#540)
3000
2676
  const rows = [];
3001
2677
  for (let i = 0; i < filePaths.length; i += SQLITE_PARAM_CHUNK_SIZE) {
3002
2678
  const chunk = filePaths.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
@@ -3004,11 +2680,6 @@ class QueryBuilder {
3004
2680
  const chunkRows = this.db
3005
2681
  .prepare(`SELECT * FROM unresolved_refs WHERE status = 'pending' AND file_path IN (${placeholders})`)
3006
2682
  .all(...chunk);
3007
- // Append with a loop, never a spread: the INPUT chunk is bounded, but
3008
- // the RESULT rows per chunk are not — a dense recovery sync (e.g. the
3009
- // #1541 self-heal re-indexing hundreds of files) returns more rows than
3010
- // V8 allows as arguments, and `push(...chunkRows)` dies with "Maximum
3011
- // call stack size exceeded", aborting resolution mid-sync (#1558).
3012
2683
  for (const row of chunkRows)
3013
2684
  rows.push(row);
3014
2685
  }
@@ -3024,40 +2695,22 @@ class QueryBuilder {
3024
2695
  rowId: row.id,
3025
2696
  }));
3026
2697
  }
3027
- /**
3028
- * Delete all unresolved references (after resolution)
3029
- */
3030
2698
  clearUnresolvedReferences() {
3031
2699
  this.db.exec('DELETE FROM unresolved_refs');
3032
2700
  }
3033
- /**
3034
- * Delete resolved references by their IDs
3035
- */
3036
2701
  deleteResolvedReferences(fromNodeIds) {
3037
2702
  if (fromNodeIds.length === 0)
3038
2703
  return;
3039
- // Chunk under SQLite's parameter limit, matching every other IN-list in
3040
- // this file. The internal resolution path uses deleteSpecificResolvedReferences
3041
- // instead, but QueryBuilder is part of the public API, so a library consumer
3042
- // passing more ids than SQLITE_MAX_VARIABLE_NUMBER (32766 on the bundled
3043
- // node:sqlite) would otherwise hit "too many SQL variables". (#540, #1001)
3044
2704
  for (let i = 0; i < fromNodeIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
3045
2705
  const chunk = fromNodeIds.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
3046
2706
  const placeholders = chunk.map(() => '?').join(',');
3047
2707
  this.db.prepare(`DELETE FROM unresolved_refs WHERE from_node_id IN (${placeholders})`).run(...chunk);
3048
2708
  }
3049
2709
  }
3050
- /**
3051
- * Delete specific resolved references by (fromNodeId, referenceName, referenceKind) tuples.
3052
- * More precise than deleteResolvedReferences — only removes refs that were actually resolved.
3053
- */
3054
2710
  deleteSpecificResolvedReferences(refs) {
3055
2711
  if (refs.length === 0)
3056
2712
  return 0;
3057
2713
  const stmt = this.db.prepare('DELETE FROM unresolved_refs WHERE from_node_id = ? AND reference_name = ? AND reference_kind = ?');
3058
- // Returns rows actually removed (SQLite `changes`, summed): the batched
3059
- // resolution loop's non-progress guard keys on this — zero removals from
3060
- // a batch that claimed work is the direct runaway signal (§7a.2).
3061
2714
  let changed = 0;
3062
2715
  const deleteMany = this.db.transaction((items) => {
3063
2716
  for (const ref of items) {
@@ -3067,23 +2720,9 @@ class QueryBuilder {
3067
2720
  deleteMany(refs);
3068
2721
  return changed;
3069
2722
  }
3070
- /**
3071
- * Delete unresolved-ref rows by row id — the precise cleanup for refs a
3072
- * resolution pass actually processed. The key-tuple variant above also
3073
- * deletes SIBLING rows (same caller calling the same callee at other lines)
3074
- * that a later batch hasn't attempted yet, so when a batch boundary split a
3075
- * caller's same-named call sites, the later sites' edges were silently never
3076
- * created (#1269).
3077
- */
3078
2723
  deleteReferencesByRowIds(rowIds) {
3079
2724
  if (rowIds.length === 0)
3080
2725
  return 0;
3081
- // One transaction for all chunks (each chunk was previously its own
3082
- // implicit transaction = its own WAL commit — measurable on 100k+-ref
3083
- // resolution persists), and the full-size chunk statement is cached so
3084
- // repeat calls skip the re-prepare; only the final partial chunk (if any)
3085
- // prepares ad hoc. Returns rows actually removed (summed `changes`) for
3086
- // the batched loop's non-progress guard (§7a.2).
3087
2726
  let changed = 0;
3088
2727
  this.db.transaction(() => {
3089
2728
  for (let i = 0; i < rowIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
@@ -3103,15 +2742,6 @@ class QueryBuilder {
3103
2742
  })();
3104
2743
  return changed;
3105
2744
  }
3106
- /**
3107
- * Mark refs a completed resolution pass could not resolve as status='failed'
3108
- * instead of deleting them (#1240). Failed rows are invisible to the pending
3109
- * count/batch readers (so drain loops and the #1187 orphan sweep still
3110
- * terminate) but stay queryable by name_tail so a later sync can retry them
3111
- * when a changed file introduces a symbol that could satisfy them. name_tail
3112
- * is (re)written here so rows inserted before the v8 migration get their
3113
- * tail the first time they're attempted.
3114
- */
3115
2745
  markReferencesFailed(refs) {
3116
2746
  if (refs.length === 0)
3117
2747
  return 0;
@@ -3119,20 +2749,12 @@ class QueryBuilder {
3119
2749
  let changed = 0;
3120
2750
  const markMany = this.db.transaction((items) => {
3121
2751
  for (const ref of items) {
3122
- changed += stmt.run(referenceNameTail(ref.referenceName), ref.fromNodeId, ref.referenceName, ref.referenceKind).changes;
2752
+ changed += stmt.run(ref.nameTail ?? (0, reference_tail_1.referenceNameTail)(ref.referenceName, ref.referenceKind), ref.fromNodeId, ref.referenceName, ref.referenceKind).changes;
3123
2753
  }
3124
2754
  });
3125
2755
  markMany(refs);
3126
2756
  return changed;
3127
2757
  }
3128
- /**
3129
- * Park refs as status='failed' by row id — the precise counterpart of
3130
- * markReferencesFailed, for the same reason as deleteReferencesByRowIds:
3131
- * the key-tuple variant also flips same-key sibling rows in later batches
3132
- * to 'failed' before they were ever attempted (#1269). Resolution outcome
3133
- * can differ per call site (receiver-type inference reads the ref's line),
3134
- * so a sibling must not inherit this row's failure.
3135
- */
3136
2758
  markReferencesFailedByRowIds(refs) {
3137
2759
  if (refs.length === 0)
3138
2760
  return 0;
@@ -3140,54 +2762,148 @@ class QueryBuilder {
3140
2762
  let changed = 0;
3141
2763
  const markMany = this.db.transaction((items) => {
3142
2764
  for (const ref of items) {
3143
- changed += stmt.run(referenceNameTail(ref.referenceName), ref.rowId).changes;
2765
+ changed += stmt.run(ref.nameTail ?? (0, reference_tail_1.referenceNameTail)(ref.referenceName, ref.referenceKind), ref.rowId).changes;
3144
2766
  }
3145
2767
  });
3146
2768
  markMany(refs);
3147
2769
  return changed;
3148
2770
  }
3149
- /**
3150
- * Failed refs whose name tail matches one of the given symbol names — the
3151
- * candidates a sync should retry after files carrying those names changed
3152
- * (#1240). Names matching more than `perNameCeiling` failed refs are
3153
- * skipped entirely: at that population a name is external/builtin noise
3154
- * (`get`, `map`, …) that one new definition won't resolve — the same
3155
- * rationale as resolution's AMBIGUOUS_NAME_CEILING (#999) — and retrying an
3156
- * arbitrary subset would be both wasted work and incoherent coverage.
3157
- */
3158
- getRetryableFailedReferences(names, perNameCeiling = 500) {
2771
+ getRetryableFailedReferences(names, perNameCeiling = 500, perModuleCeiling = 5000) {
3159
2772
  if (names.length === 0)
3160
2773
  return [];
3161
- // Pass 1: per-tail counts, chunked under the SQLite parameter limit.
3162
- const retryNames = [];
3163
- for (let i = 0; i < names.length; i += SQLITE_PARAM_CHUNK_SIZE) {
3164
- const chunk = names.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
3165
- const placeholders = chunk.map(() => '?').join(',');
3166
- const counts = this.db
3167
- .prepare(`SELECT name_tail, COUNT(*) as count FROM unresolved_refs WHERE status = 'failed' AND name_tail IN (${placeholders}) GROUP BY name_tail`)
3168
- .all(...chunk);
3169
- for (const row of counts) {
3170
- if (row.count <= perNameCeiling)
3171
- retryNames.push(row.name_tail);
2774
+ const lookups = [
2775
+ { column: 'name_tail', where: "status = 'failed'" },
2776
+ { column: 'reference_name', where: reference_tail_1.MODULE_PARKED_SQL },
2777
+ { column: reference_tail_1.MEMBER_TAIL_SQL, where: `${reference_tail_1.MODULE_PARKED_SQL} AND instr(reference_name, '.') > 0` },
2778
+ ];
2779
+ const counts = lookups.map(({ column, where }) => {
2780
+ const byKey = new Map();
2781
+ for (let i = 0; i < names.length; i += SQLITE_PARAM_CHUNK_SIZE) {
2782
+ const chunk = names.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
2783
+ const placeholders = chunk.map(() => '?').join(',');
2784
+ const found = this.db
2785
+ .prepare(`SELECT ${column} AS key, COUNT(*) AS count FROM unresolved_refs WHERE ${where} AND ${column} IN (${placeholders}) GROUP BY ${column}`)
2786
+ .all(...chunk);
2787
+ for (const row of found)
2788
+ byKey.set(row.key, row.count);
2789
+ }
2790
+ return byKey;
2791
+ });
2792
+ const [byTail, , byMember] = counts;
2793
+ const population = (lookup, key, count) => lookup === 1 ? count : (byTail.get(key) ?? 0) + (byMember.get(key) ?? 0);
2794
+ const rows = new Map();
2795
+ for (const [lookup, { column, where }] of lookups.entries()) {
2796
+ const retryKeys = [...counts[lookup]]
2797
+ .filter(([key, count]) => (lookup === 0 && (0, reference_tail_1.isModuleKey)(key) ? count <= perModuleCeiling : population(lookup, key, count) <= perNameCeiling))
2798
+ .map(([key]) => key);
2799
+ for (let i = 0; i < retryKeys.length; i += SQLITE_PARAM_CHUNK_SIZE) {
2800
+ const chunk = retryKeys.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
2801
+ const placeholders = chunk.map(() => '?').join(',');
2802
+ const chunkRows = this.db
2803
+ .prepare(`SELECT * FROM unresolved_refs WHERE ${where} AND ${column} IN (${placeholders})`)
2804
+ .all(...chunk);
2805
+ for (const row of chunkRows)
2806
+ rows.set(row.id, row);
3172
2807
  }
3173
2808
  }
3174
- if (retryNames.length === 0)
3175
- return [];
3176
- // Pass 2: load the surviving rows.
3177
- const rows = [];
3178
- for (let i = 0; i < retryNames.length; i += SQLITE_PARAM_CHUNK_SIZE) {
3179
- const chunk = retryNames.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
3180
- const placeholders = chunk.map(() => '?').join(',');
3181
- const chunkRows = this.db
3182
- .prepare(`SELECT * FROM unresolved_refs WHERE status = 'failed' AND name_tail IN (${placeholders})`)
3183
- .all(...chunk);
3184
- // Loop, not spread — same V8 argument-limit hazard as
3185
- // getUnresolvedReferencesByFiles (#1558): a large definition delta can
3186
- // select an unbounded number of failed rows per chunk.
3187
- for (const row of chunkRows)
3188
- rows.push(row);
2809
+ const byReceiver = this.db.prepare(`SELECT * FROM unresolved_refs WHERE ${reference_tail_1.MODULE_PARKED_SQL} AND reference_name >= ? AND reference_name < ? LIMIT ?`);
2810
+ for (const name of names) {
2811
+ if (!RECEIVER_NAME.test(name))
2812
+ continue;
2813
+ const found = byReceiver.all(`${name}.`, `${name}/`, perNameCeiling + 1);
2814
+ if (found.length > perNameCeiling)
2815
+ continue;
2816
+ for (const row of found)
2817
+ rows.set(row.id, row);
3189
2818
  }
3190
- return rows.map((row) => ({
2819
+ return [...rows.values()].map((row) => ({
2820
+ fromNodeId: row.from_node_id,
2821
+ referenceName: row.reference_name,
2822
+ referenceKind: row.reference_kind,
2823
+ line: row.line,
2824
+ column: row.col,
2825
+ candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
2826
+ filePath: row.file_path,
2827
+ language: row.language,
2828
+ rowId: row.id,
2829
+ }));
2830
+ }
2831
+ getRetryableFailedImports(pathKeys, names = [], perNameCeiling = 500, resolvedModules = [], perModuleCeiling = 5000, couldName) {
2832
+ const failedImports = "status = 'failed' AND reference_kind = 'imports'";
2833
+ const lookups = [
2834
+ { keys: pathKeys, column: 'name_tail', where: failedImports, ceiling: perNameCeiling, couldName },
2835
+ { keys: pathKeys, column: 'reference_name', where: failedImports, ceiling: perNameCeiling, couldName },
2836
+ { keys: names, column: 'reference_name', where: `${failedImports} AND name_tail != reference_name`, ceiling: perNameCeiling },
2837
+ { keys: resolvedModules, column: 'reference_name', where: failedImports, ceiling: perModuleCeiling },
2838
+ ];
2839
+ const toReference = (row) => ({
2840
+ fromNodeId: row.from_node_id,
2841
+ referenceName: row.reference_name,
2842
+ referenceKind: row.reference_kind,
2843
+ line: row.line,
2844
+ column: row.col,
2845
+ candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
2846
+ filePath: row.file_path,
2847
+ language: row.language,
2848
+ rowId: row.id,
2849
+ });
2850
+ const rows = new Map();
2851
+ for (const { keys, column, where, ceiling, couldName } of lookups) {
2852
+ const unique = [...new Set(keys)].filter((key) => key.length > 0);
2853
+ const retryKeys = [];
2854
+ const crowdedKeys = [];
2855
+ for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
2856
+ const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
2857
+ const placeholders = chunk.map(() => '?').join(',');
2858
+ const counts = this.db
2859
+ .prepare(`SELECT ${column} AS key, COUNT(*) AS count FROM unresolved_refs WHERE ${where} AND ${column} IN (${placeholders}) GROUP BY ${column}`)
2860
+ .all(...chunk);
2861
+ for (const row of counts) {
2862
+ if (row.count <= ceiling)
2863
+ retryKeys.push(row.key);
2864
+ else if (couldName)
2865
+ crowdedKeys.push(row.key);
2866
+ }
2867
+ }
2868
+ for (let i = 0; i < retryKeys.length; i += SQLITE_PARAM_CHUNK_SIZE) {
2869
+ const chunk = retryKeys.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
2870
+ const placeholders = chunk.map(() => '?').join(',');
2871
+ const chunkRows = this.db
2872
+ .prepare(`SELECT * FROM unresolved_refs WHERE ${where} AND ${column} IN (${placeholders})`)
2873
+ .all(...chunk);
2874
+ for (const row of chunkRows)
2875
+ rows.set(row.id, row);
2876
+ }
2877
+ for (const key of crowdedKeys) {
2878
+ const keyRows = this.db
2879
+ .prepare(`SELECT * FROM unresolved_refs WHERE ${where} AND ${column} IN (?)`)
2880
+ .all(key);
2881
+ const named = keyRows.filter((row) => couldName(toReference(row)));
2882
+ if (named.length > perModuleCeiling)
2883
+ continue;
2884
+ for (const row of named)
2885
+ rows.set(row.id, row);
2886
+ }
2887
+ }
2888
+ return [...rows.values()].map(toReference);
2889
+ }
2890
+ getFailedScopedImports() {
2891
+ return this.db
2892
+ .prepare(`SELECT reference_name AS name, MIN(file_path) AS file_path, language
2893
+ FROM unresolved_refs
2894
+ WHERE status = 'failed' AND reference_kind = 'imports'
2895
+ AND reference_name GLOB '@?*/?*' AND reference_name NOT GLOB '@*/*/*'
2896
+ GROUP BY reference_name`)
2897
+ .all()
2898
+ .map((row) => ({ name: row.name, filePath: row.file_path, language: row.language }));
2899
+ }
2900
+ getFailedFolderImports() {
2901
+ const placeholders = FOLDER_SPECIFIERS.map(() => '?').join(',');
2902
+ return this.db
2903
+ .prepare(`SELECT * FROM unresolved_refs
2904
+ WHERE status = 'failed' AND reference_kind = 'imports' AND reference_name IN (${placeholders})`)
2905
+ .all(...FOLDER_SPECIFIERS)
2906
+ .map((row) => ({
3191
2907
  fromNodeId: row.from_node_id,
3192
2908
  referenceName: row.reference_name,
3193
2909
  referenceKind: row.reference_kind,
@@ -3199,35 +2915,66 @@ class QueryBuilder {
3199
2915
  rowId: row.id,
3200
2916
  }));
3201
2917
  }
3202
- /**
3203
- * Resolution edges whose TARGET symbol is named one of `names` — the edges a
3204
- * sync must re-resolve after `names` gained or lost a definition (CG-33).
3205
- *
3206
- * Resolution binds a reference to a node whose name matches the reference's
3207
- * tail, and it picks among ALL same-named definitions project-wide. So adding
3208
- * or removing one definition of `pct` changes the answer for every `pct(...)`
3209
- * reference in the repo — including references in files this sync never
3210
- * touches, whose edges nothing else revisits. Those edges' current target is,
3211
- * by that same rule, a node named `pct`, which is why the target's name is a
3212
- * sufficient (and index-backed, via idx_nodes_name) way to find them without
3213
- * a schema change or a scan of edge metadata.
3214
- *
3215
- * Returns the source file/language alongside each edge so the caller can
3216
- * resurrect it as its original reference. Excludes `provenance='heuristic'`
3217
- * (synthesized dispatch edges are not resolution output and carry no refName
3218
- * stamp to resurrect from — deleting one would be a permanent loss).
3219
- *
3220
- * Names matching more than `perNameCeiling` edges are skipped entirely, same
3221
- * rationale and same default as {@link getRetryableFailedReferences}: at that
3222
- * population the name is generic (`get`, `clear`, …), one definition changing
3223
- * won't flip most of them, and rebinding an arbitrary subset is both wasted
3224
- * work and incoherent coverage.
3225
- */
3226
- getResolutionEdgesByTargetName(names, perNameCeiling = 500) {
2918
+ getFailedCallsByTail(tails) {
2919
+ const out = [];
2920
+ const unique = [...new Set(tails)];
2921
+ for (let i = 0; i < unique.length; i += SQLITE_PARAM_CHUNK_SIZE) {
2922
+ const chunk = unique.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
2923
+ const placeholders = chunk.map(() => '?').join(',');
2924
+ const rows = this.db
2925
+ .prepare(`SELECT id, reference_name, file_path FROM unresolved_refs
2926
+ WHERE status = 'failed' AND reference_kind = 'calls' AND name_tail IN (${placeholders})
2927
+ UNION ALL
2928
+ SELECT id, reference_name, file_path FROM unresolved_refs
2929
+ WHERE ${reference_tail_1.MODULE_PARKED_SQL} AND reference_kind = 'calls' AND ${reference_tail_1.MEMBER_TAIL_SQL} IN (${placeholders})`)
2930
+ .all(...chunk, ...chunk);
2931
+ for (const row of rows)
2932
+ out.push({ rowId: row.id, referenceName: row.reference_name, filePath: row.file_path });
2933
+ }
2934
+ return out;
2935
+ }
2936
+ getResolvedNavigations() {
2937
+ const rows = this.db
2938
+ .prepare(`SELECT e.*, src.file_path AS source_file_path, src.language AS source_language
2939
+ FROM edges e
2940
+ JOIN nodes src ON src.id = e.source
2941
+ WHERE e.kind = 'navigates' AND (e.provenance IS NULL OR e.provenance != 'heuristic')`)
2942
+ .all();
2943
+ return rows.map((row) => ({
2944
+ ...rowToEdge(row),
2945
+ edgeId: row.id,
2946
+ sourceFilePath: row.source_file_path,
2947
+ sourceLanguage: row.source_language,
2948
+ }));
2949
+ }
2950
+ getFailedModuleKeys() {
2951
+ return this.db
2952
+ .prepare(`SELECT DISTINCT name_tail AS key FROM unresolved_refs WHERE status = 'failed' AND name_tail GLOB 'module:*'`)
2953
+ .all().map((row) => row.key);
2954
+ }
2955
+ reopenFailedReferences(rowIds) {
2956
+ if (rowIds.length === 0)
2957
+ return 0;
2958
+ let changed = 0;
2959
+ this.db.transaction(() => {
2960
+ for (let i = 0; i < rowIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
2961
+ const chunk = rowIds.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
2962
+ const placeholders = chunk.map(() => '?').join(',');
2963
+ changed += this.db
2964
+ .prepare(`UPDATE unresolved_refs SET status = 'pending' WHERE status = 'failed' AND id IN (${placeholders})`)
2965
+ .run(...chunk).changes;
2966
+ }
2967
+ })();
2968
+ return changed;
2969
+ }
2970
+ getMaxEdgeId() {
2971
+ return this.db.prepare('SELECT COALESCE(MAX(id), 0) AS id FROM edges').get().id;
2972
+ }
2973
+ getResolutionEdgesByTargetName(names, perNameCeiling = 500, countedUpToEdgeId) {
3227
2974
  if (names.length === 0)
3228
2975
  return [];
3229
- // Pass 1: per-name edge counts, chunked under the SQLite parameter limit.
3230
2976
  const keep = [];
2977
+ const counted = countedUpToEdgeId === undefined ? '' : 'AND e.id <= ?';
3231
2978
  for (let i = 0; i < names.length; i += SQLITE_PARAM_CHUNK_SIZE) {
3232
2979
  const chunk = names.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
3233
2980
  const placeholders = chunk.map(() => '?').join(',');
@@ -3237,8 +2984,9 @@ class QueryBuilder {
3237
2984
  JOIN nodes tgt ON tgt.id = e.target
3238
2985
  WHERE tgt.name IN (${placeholders})
3239
2986
  AND (e.provenance IS NULL OR e.provenance != 'heuristic')
2987
+ ${counted}
3240
2988
  GROUP BY tgt.name`)
3241
- .all(...chunk);
2989
+ .all(...chunk, ...(countedUpToEdgeId === undefined ? [] : [countedUpToEdgeId]));
3242
2990
  for (const row of counts) {
3243
2991
  if (row.count <= perNameCeiling)
3244
2992
  keep.push(row.name);
@@ -3246,8 +2994,6 @@ class QueryBuilder {
3246
2994
  }
3247
2995
  if (keep.length === 0)
3248
2996
  return [];
3249
- // Pass 2: load the surviving edges with the source file context a
3250
- // resurrection needs.
3251
2997
  const out = [];
3252
2998
  for (let i = 0; i < keep.length; i += SQLITE_PARAM_CHUNK_SIZE) {
3253
2999
  const chunk = keep.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
@@ -3271,7 +3017,166 @@ class QueryBuilder {
3271
3017
  }
3272
3018
  return out;
3273
3019
  }
3274
- /** Delete edges by primary key — the rebind pass's half of a re-resolution. */
3020
+ getRouteEdgesMovedBy(filePaths) {
3021
+ if (filePaths.length === 0)
3022
+ return [];
3023
+ const files = JSON.stringify(filePaths);
3024
+ const rows = this.db
3025
+ .prepare(`SELECT e.*, src.file_path AS source_file_path, src.language AS source_language
3026
+ FROM nodes src
3027
+ JOIN edges e ON e.source = src.id
3028
+ JOIN nodes tgt ON tgt.id = e.target
3029
+ WHERE src.kind = 'route'
3030
+ AND e.kind != 'contains'
3031
+ AND (e.provenance IS NULL OR e.provenance != 'heuristic')
3032
+ AND src.file_path NOT IN (SELECT value FROM json_each(?))
3033
+ AND (tgt.file_path IN (SELECT value FROM json_each(?))
3034
+ OR (tgt.file_path = src.file_path AND tgt.kind IN ('constant', 'variable')))
3035
+ ORDER BY e.id`)
3036
+ .all(files, files);
3037
+ return rows.map((row) => ({
3038
+ ...rowToEdge(row),
3039
+ edgeId: row.id,
3040
+ sourceFilePath: row.source_file_path,
3041
+ sourceLanguage: row.source_language,
3042
+ }));
3043
+ }
3044
+ getResolutionEdgesBySourceLanguage(language) {
3045
+ const rows = this.db
3046
+ .prepare(`SELECT e.*, src.file_path AS source_file_path, src.language AS source_language
3047
+ FROM edges e
3048
+ JOIN nodes src ON src.id = e.source
3049
+ WHERE src.language = ?
3050
+ AND e.kind != 'contains'
3051
+ AND (e.provenance IS NULL OR e.provenance != 'heuristic')`)
3052
+ .all(language);
3053
+ return rows.map((row) => ({
3054
+ ...rowToEdge(row),
3055
+ edgeId: row.id,
3056
+ sourceFilePath: row.source_file_path,
3057
+ sourceLanguage: row.source_language,
3058
+ }));
3059
+ }
3060
+ getResolutionEdgesTouchingFiles(language, targetFiles, sourceDirs, importNodeSegments = []) {
3061
+ const candidates = new Set();
3062
+ const idsWhere = (column, nodeIds) => {
3063
+ for (let i = 0; i < nodeIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
3064
+ const chunk = nodeIds.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
3065
+ const rows = this.db
3066
+ .prepare(`SELECT id FROM edges WHERE ${column} IN (${chunk.map(() => '?').join(',')})`)
3067
+ .all(...chunk);
3068
+ for (const r of rows)
3069
+ candidates.add(r.id);
3070
+ }
3071
+ };
3072
+ for (let i = 0; i < targetFiles.length; i += SQLITE_PARAM_CHUNK_SIZE) {
3073
+ const chunk = targetFiles.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
3074
+ const nodes = this.db
3075
+ .prepare(`SELECT id FROM nodes WHERE file_path IN (${chunk.map(() => '?').join(',')})`)
3076
+ .all(...chunk);
3077
+ idsWhere('target', nodes.map((n) => n.id));
3078
+ }
3079
+ for (const dir of sourceDirs) {
3080
+ const nodes = (dir === ''
3081
+ ? this.db.prepare('SELECT id FROM nodes WHERE language = ?').all(language)
3082
+ : this.db
3083
+ .prepare('SELECT id FROM nodes WHERE file_path >= ? AND file_path < ?')
3084
+ .all(`${dir}/`, `${dir}0`));
3085
+ idsWhere('source', nodes.map((n) => n.id));
3086
+ }
3087
+ if (importNodeSegments.length > 0) {
3088
+ const wanted = new Set(importNodeSegments);
3089
+ const nodes = this.db
3090
+ .prepare("SELECT id, name FROM nodes WHERE kind = 'import' AND language = ?")
3091
+ .all(language);
3092
+ idsWhere('target', nodes.filter((n) => n.name.split('.').some((seg) => wanted.has(seg))).map((n) => n.id));
3093
+ }
3094
+ return this.loadResolutionEdges(language, [...candidates]);
3095
+ }
3096
+ getResolutionEdgesFromFiles(language, files) {
3097
+ const ids = [];
3098
+ for (let i = 0; i < files.length; i += SQLITE_PARAM_CHUNK_SIZE) {
3099
+ const chunk = files.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
3100
+ const rows = this.db
3101
+ .prepare(`SELECT e.id AS id FROM nodes n CROSS JOIN edges e ON e.source = n.id
3102
+ WHERE n.file_path IN (${chunk.map(() => '?').join(',')})`)
3103
+ .all(...chunk);
3104
+ for (const r of rows)
3105
+ ids.push(r.id);
3106
+ }
3107
+ return this.loadResolutionEdges(language, ids);
3108
+ }
3109
+ loadResolutionEdges(language, ids) {
3110
+ const out = [];
3111
+ for (let i = 0; i < ids.length; i += SQLITE_PARAM_CHUNK_SIZE) {
3112
+ const chunk = ids.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
3113
+ const rows = this.db
3114
+ .prepare(`SELECT e.*, src.file_path AS source_file_path, src.language AS source_language
3115
+ FROM edges e
3116
+ CROSS JOIN nodes src ON src.id = e.source
3117
+ CROSS JOIN nodes tgt ON tgt.id = e.target
3118
+ WHERE e.id IN (${chunk.map(() => '?').join(',')})
3119
+ AND src.language = ?
3120
+ AND e.kind != 'contains'
3121
+ AND (e.provenance IS NULL OR e.provenance != 'heuristic')`)
3122
+ .all(...chunk, language);
3123
+ for (const row of rows) {
3124
+ out.push({ ...rowToEdge(row), edgeId: row.id, sourceFilePath: row.source_file_path, sourceLanguage: row.source_language });
3125
+ }
3126
+ }
3127
+ return out;
3128
+ }
3129
+ requeueFailedReferencesBinding(language, names) {
3130
+ const files = [...names.keys()];
3131
+ const ids = [];
3132
+ for (let i = 0; i < files.length; i += SQLITE_PARAM_CHUNK_SIZE) {
3133
+ const chunk = files.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
3134
+ const rows = this.db
3135
+ .prepare(`SELECT id, file_path, reference_name FROM unresolved_refs
3136
+ WHERE status = 'failed' AND language = ? AND file_path IN (${chunk.map(() => '?').join(',')})`)
3137
+ .all(language, ...chunk);
3138
+ for (const r of rows) {
3139
+ if (names.get(r.file_path)?.has(r.reference_name.split('.')[0]))
3140
+ ids.push(r.id);
3141
+ }
3142
+ }
3143
+ let changed = 0;
3144
+ this.db.transaction(() => {
3145
+ for (let i = 0; i < ids.length; i += SQLITE_PARAM_CHUNK_SIZE) {
3146
+ const chunk = ids.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
3147
+ changed += this.db
3148
+ .prepare(`UPDATE unresolved_refs SET status = 'pending' WHERE id IN (${chunk.map(() => '?').join(',')})`)
3149
+ .run(...chunk).changes;
3150
+ }
3151
+ })();
3152
+ return changed;
3153
+ }
3154
+ requeueFailedReferencesByLanguage(language, segments, files) {
3155
+ const sql = "UPDATE unresolved_refs SET status = 'pending' WHERE status = 'failed' AND language = ?";
3156
+ if (!segments)
3157
+ return this.db.prepare(sql).run(language).changes;
3158
+ if (segments.length === 0)
3159
+ return 0;
3160
+ const wanted = new Set(segments);
3161
+ const ids = this.db
3162
+ .prepare("SELECT id, reference_name, file_path FROM unresolved_refs WHERE status = 'failed' AND language = ?")
3163
+ .all(language)
3164
+ .filter((r) => r.reference_name.split('.').some((seg) => wanted.has(seg)))
3165
+ .map((r) => {
3166
+ files?.add(r.file_path);
3167
+ return r.id;
3168
+ });
3169
+ let changed = 0;
3170
+ this.db.transaction(() => {
3171
+ for (let i = 0; i < ids.length; i += SQLITE_PARAM_CHUNK_SIZE) {
3172
+ const chunk = ids.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
3173
+ changed += this.db
3174
+ .prepare(`UPDATE unresolved_refs SET status = 'pending' WHERE id IN (${chunk.map(() => '?').join(',')})`)
3175
+ .run(...chunk).changes;
3176
+ }
3177
+ })();
3178
+ return changed;
3179
+ }
3275
3180
  deleteEdgesByIds(edgeIds) {
3276
3181
  if (edgeIds.length === 0)
3277
3182
  return 0;
@@ -3285,10 +3190,96 @@ class QueryBuilder {
3285
3190
  })();
3286
3191
  return changed;
3287
3192
  }
3288
- /**
3289
- * Replace resolution edges with their original unresolved references as one
3290
- * transaction. If ref insertion fails, the edge deletion is rolled back.
3291
- */
3193
+ getEdgesWithTypeFrom() {
3194
+ const rows = this.db
3195
+ .prepare(`SELECT e.*, src.file_path AS source_file_path, src.language AS source_language
3196
+ FROM edges e
3197
+ JOIN nodes src ON src.id = e.source
3198
+ WHERE e.metadata LIKE '%"typeFrom"%'`)
3199
+ .all();
3200
+ return rows.map((row) => ({
3201
+ ...rowToEdge(row),
3202
+ edgeId: row.id,
3203
+ sourceFilePath: row.source_file_path,
3204
+ sourceLanguage: row.source_language,
3205
+ }));
3206
+ }
3207
+ get parameterFlows() {
3208
+ return (this.flowQueries ??= new parameter_flow_queries_1.ParameterFlowQueries(this.db, this));
3209
+ }
3210
+ getPythonImporterClosure(filePaths, depth = 6) {
3211
+ const closure = new Set(filePaths);
3212
+ let frontier = [...filePaths];
3213
+ for (let hop = 0; hop < depth && frontier.length > 0; hop++) {
3214
+ const next = [];
3215
+ for (let i = 0; i < frontier.length; i += SQLITE_PARAM_CHUNK_SIZE) {
3216
+ const chunk = frontier.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
3217
+ const placeholders = chunk.map(() => '?').join(',');
3218
+ const rows = this.db
3219
+ .prepare(`SELECT DISTINCT src.file_path AS file_path
3220
+ FROM edges e
3221
+ JOIN nodes tgt ON tgt.id = e.target
3222
+ JOIN nodes src ON src.id = e.source
3223
+ WHERE e.kind = 'imports' AND tgt.file_path IN (${placeholders}) AND src.language = 'python'`)
3224
+ .all(...chunk);
3225
+ for (const row of rows) {
3226
+ if (!closure.has(row.file_path)) {
3227
+ closure.add(row.file_path);
3228
+ next.push(row.file_path);
3229
+ }
3230
+ }
3231
+ }
3232
+ frontier = next;
3233
+ }
3234
+ return [...closure];
3235
+ }
3236
+ getFailedPythonAttrRefKeys(filePaths) {
3237
+ const wanted = new Set(filePaths);
3238
+ const rows = this.db
3239
+ .prepare(`SELECT id, from_node_id, reference_name, file_path FROM unresolved_refs WHERE ${FAILED_PY_ATTR_REF}`)
3240
+ .all();
3241
+ const out = [];
3242
+ for (const r of rows) {
3243
+ if (wanted.has(r.file_path))
3244
+ out.push({ id: r.id, fromNodeId: r.from_node_id, referenceName: r.reference_name, filePath: r.file_path });
3245
+ }
3246
+ return out;
3247
+ }
3248
+ getUnresolvedReferencesByIds(ids) {
3249
+ const rows = [];
3250
+ for (let i = 0; i < ids.length; i += SQLITE_PARAM_CHUNK_SIZE) {
3251
+ const chunk = ids.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
3252
+ const placeholders = chunk.map(() => '?').join(',');
3253
+ const chunkRows = this.db
3254
+ .prepare(`SELECT * FROM unresolved_refs WHERE id IN (${placeholders})`)
3255
+ .all(...chunk);
3256
+ for (const row of chunkRows)
3257
+ rows.push(row);
3258
+ }
3259
+ return rows.map((row) => ({
3260
+ fromNodeId: row.from_node_id,
3261
+ referenceName: row.reference_name,
3262
+ referenceKind: row.reference_kind,
3263
+ line: row.line,
3264
+ column: row.col,
3265
+ candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
3266
+ filePath: row.file_path,
3267
+ language: row.language,
3268
+ rowId: row.id,
3269
+ }));
3270
+ }
3271
+ getPythonFilesWithEdgesInto(filePath, kinds, targetKinds) {
3272
+ const kp = kinds.map(() => '?').join(',');
3273
+ const tp = targetKinds.map(() => '?').join(',');
3274
+ return this.db
3275
+ .prepare(`SELECT DISTINCT src.file_path AS file_path
3276
+ FROM edges e
3277
+ JOIN nodes tgt ON tgt.id = e.target
3278
+ JOIN nodes src ON src.id = e.source
3279
+ WHERE tgt.file_path = ? AND e.kind IN (${kp}) AND tgt.kind IN (${tp})
3280
+ AND src.language = 'python' AND src.file_path != ?`)
3281
+ .all(filePath, ...kinds, ...targetKinds, filePath).map((r) => r.file_path);
3282
+ }
3292
3283
  replaceResolutionEdgesWithUnresolvedRefs(edgeIds, refs) {
3293
3284
  return this.db.transaction(() => {
3294
3285
  const changed = this.deleteEdgesByIds(edgeIds);
@@ -3296,37 +3287,22 @@ class QueryBuilder {
3296
3287
  return changed;
3297
3288
  })();
3298
3289
  }
3299
- /**
3300
- * Distinct node names present in the given files — the symbol names a sync
3301
- * pass uses to look up retryable failed refs after those files changed.
3302
- */
3303
- getNodeNamesByFiles(filePaths) {
3290
+ getNodeNamesByFiles(filePaths, kinds) {
3304
3291
  if (filePaths.length === 0)
3305
3292
  return [];
3293
+ const kindFilter = kinds ? ` AND kind IN (${kinds.map(() => '?').join(',')})` : '';
3306
3294
  const names = new Set();
3307
3295
  for (let i = 0; i < filePaths.length; i += SQLITE_PARAM_CHUNK_SIZE) {
3308
3296
  const chunk = filePaths.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
3309
3297
  const placeholders = chunk.map(() => '?').join(',');
3310
3298
  const rows = this.db
3311
- .prepare(`SELECT DISTINCT name FROM nodes WHERE file_path IN (${placeholders})`)
3312
- .all(...chunk);
3299
+ .prepare(`SELECT DISTINCT name FROM nodes WHERE file_path IN (${placeholders})${kindFilter}`)
3300
+ .all(...chunk, ...(kinds ?? []));
3313
3301
  for (const row of rows)
3314
3302
  names.add(row.name);
3315
3303
  }
3316
3304
  return [...names];
3317
3305
  }
3318
- /**
3319
- * Distinct `file\0name` pairs defined by the given files — the shape sync's
3320
- * definition delta needs (CG-33).
3321
- *
3322
- * Deliberately NOT `getNodeNamesByFiles`: a bare name set is taken over the
3323
- * WHOLE changed batch, so a name that moves between two files in one commit
3324
- * (or exists in one changed file and is newly added to another) appears on
3325
- * both sides and cancels out of the symmetric difference — even though a
3326
- * definition genuinely appeared or vanished and every reference to that name
3327
- * repo-wide may now bind elsewhere. Keying by file makes each definition its
3328
- * own fact, so the move is seen as one removal plus one addition.
3329
- */
3330
3306
  getNodeNamePairsByFiles(filePaths) {
3331
3307
  const pairs = new Set();
3332
3308
  if (filePaths.length === 0)
@@ -3337,32 +3313,48 @@ class QueryBuilder {
3337
3313
  const rows = this.db
3338
3314
  .prepare(`SELECT DISTINCT file_path, name FROM nodes WHERE file_path IN (${placeholders})`)
3339
3315
  .all(...chunk);
3340
- // NUL-joined: a path or a symbol name can contain a space, never a NUL.
3341
3316
  for (const row of rows)
3342
3317
  pairs.add(`${row.file_path}\0${row.name}`);
3343
3318
  }
3344
3319
  return pairs;
3345
3320
  }
3346
- // ===========================================================================
3347
- // Statistics
3348
- // ===========================================================================
3349
- /**
3350
- * Lightweight (nodes, edges) count snapshot. Used around an index/sync
3351
- * run to compute true additions across extraction + resolution +
3352
- * synthesis — the per-phase counter in the orchestrator only sees
3353
- * extraction's contribution, which is why the CLI summary under-reported
3354
- * the edge count (resolution + synthesizer edges were invisible).
3355
- */
3321
+ getReExportStatementsByFiles(filePaths) {
3322
+ const pairs = new Set();
3323
+ if (filePaths.length === 0)
3324
+ return pairs;
3325
+ for (let i = 0; i < filePaths.length; i += SQLITE_PARAM_CHUNK_SIZE) {
3326
+ const chunk = filePaths.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
3327
+ const placeholders = chunk.map(() => '?').join(',');
3328
+ const rows = this.db
3329
+ .prepare(`SELECT DISTINCT file_path, signature FROM nodes
3330
+ WHERE kind = 'import' AND file_path IN (${placeholders}) AND signature LIKE 'export%'`)
3331
+ .all(...chunk);
3332
+ for (const row of rows)
3333
+ pairs.add(`${row.file_path}\0${row.signature}`);
3334
+ }
3335
+ return pairs;
3336
+ }
3356
3337
  getNodeAndEdgeCount() {
3357
3338
  return this.db
3358
3339
  .prepare('SELECT (SELECT COUNT(*) FROM nodes) AS nodes, (SELECT COUNT(*) FROM edges) AS edges')
3359
3340
  .get();
3360
3341
  }
3361
- /**
3362
- * Get graph statistics
3363
- */
3342
+ getParsedFileCounts() {
3343
+ return this.db
3344
+ .prepare(`
3345
+ SELECT f.language AS language, COUNT(*) AS files,
3346
+ SUM(CASE
3347
+ WHEN f.node_count > 1 THEN 1
3348
+ WHEN EXISTS (SELECT 1 FROM nodes n WHERE n.file_path = f.path AND n.kind <> 'file') THEN 1
3349
+ ELSE 0
3350
+ END) AS parsed
3351
+ FROM files f
3352
+ GROUP BY f.language
3353
+ ORDER BY f.language
3354
+ `)
3355
+ .all();
3356
+ }
3364
3357
  getStats() {
3365
- // Single query for all three aggregate counts
3366
3358
  const counts = this.db.prepare(`
3367
3359
  SELECT
3368
3360
  (SELECT COUNT(*) FROM nodes) AS node_count,
@@ -3397,30 +3389,18 @@ class QueryBuilder {
3397
3389
  nodesByKind,
3398
3390
  edgesByKind,
3399
3391
  filesByLanguage,
3400
- dbSizeBytes: 0, // Set by caller using DatabaseConnection.getSize()
3401
- walSizeBytes: 0, // Set by caller using DatabaseConnection.getWalSizeBytes()
3392
+ dbSizeBytes: 0,
3393
+ walSizeBytes: 0,
3402
3394
  lastUpdated: Date.now(),
3403
3395
  };
3404
3396
  }
3405
- // ===========================================================================
3406
- // Project Metadata
3407
- // ===========================================================================
3408
- /**
3409
- * Get a metadata value by key
3410
- */
3411
3397
  getMetadata(key) {
3412
3398
  const row = this.db.prepare('SELECT value FROM project_metadata WHERE key = ?').get(key);
3413
3399
  return row?.value ?? null;
3414
3400
  }
3415
- /**
3416
- * Set a metadata key-value pair (upsert)
3417
- */
3418
3401
  setMetadata(key, value) {
3419
3402
  this.db.prepare('INSERT INTO project_metadata (key, value, updated_at) VALUES (?, ?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = excluded.updated_at').run(key, value, Date.now());
3420
3403
  }
3421
- /**
3422
- * Get all metadata as a key-value record
3423
- */
3424
3404
  getAllMetadata() {
3425
3405
  const rows = this.db.prepare('SELECT key, value FROM project_metadata').all();
3426
3406
  const result = {};
@@ -3429,9 +3409,6 @@ class QueryBuilder {
3429
3409
  }
3430
3410
  return result;
3431
3411
  }
3432
- /**
3433
- * Clear all data from the database
3434
- */
3435
3412
  clear() {
3436
3413
  this.nodeCache.clear();
3437
3414
  this.db.transaction(() => {
@@ -3444,8 +3421,6 @@ class QueryBuilder {
3444
3421
  }
3445
3422
  exports.QueryBuilder = QueryBuilder;
3446
3423
  function foldModuleRows(rows, options) {
3447
- // A module id is a path and may contain anything printable, so the key
3448
- // separator has to be something a path cannot hold.
3449
3424
  const SEP = '\u0000';
3450
3425
  const links = new Map();
3451
3426
  const pairKinds = new Set(options.pairKinds);
@@ -3469,9 +3444,6 @@ function foldModuleRows(rows, options) {
3469
3444
  uncertain: row.uncertain,
3470
3445
  });
3471
3446
  }
3472
- // Only the confident half of a row can be named: an uncertain edge is a
3473
- // guess, and printing "a to b, 12" for twelve guesses is the map claiming
3474
- // something it does not know.
3475
3447
  if (!wantPairs || row.count === 0 || !pairKinds.has(row.kind))
3476
3448
  continue;
3477
3449
  const pairKey = `${row.source}${SEP}${row.target}${SEP}${row.from}${SEP}${row.to}`;