@kkvcrobatz107/codegraph 0.9.6-pkm.1

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 (501) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +595 -0
  3. package/dist/bin/codegraph.d.ts +25 -0
  4. package/dist/bin/codegraph.d.ts.map +1 -0
  5. package/dist/bin/codegraph.js +1563 -0
  6. package/dist/bin/codegraph.js.map +1 -0
  7. package/dist/bin/node-version-check.d.ts +37 -0
  8. package/dist/bin/node-version-check.d.ts.map +1 -0
  9. package/dist/bin/node-version-check.js +79 -0
  10. package/dist/bin/node-version-check.js.map +1 -0
  11. package/dist/bin/uninstall.d.ts +14 -0
  12. package/dist/bin/uninstall.d.ts.map +1 -0
  13. package/dist/bin/uninstall.js +36 -0
  14. package/dist/bin/uninstall.js.map +1 -0
  15. package/dist/context/formatter.d.ts +30 -0
  16. package/dist/context/formatter.d.ts.map +1 -0
  17. package/dist/context/formatter.js +244 -0
  18. package/dist/context/formatter.js.map +1 -0
  19. package/dist/context/index.d.ts +110 -0
  20. package/dist/context/index.d.ts.map +1 -0
  21. package/dist/context/index.js +1169 -0
  22. package/dist/context/index.js.map +1 -0
  23. package/dist/db/index.d.ts +101 -0
  24. package/dist/db/index.d.ts.map +1 -0
  25. package/dist/db/index.js +251 -0
  26. package/dist/db/index.js.map +1 -0
  27. package/dist/db/migrations.d.ts +44 -0
  28. package/dist/db/migrations.d.ts.map +1 -0
  29. package/dist/db/migrations.js +131 -0
  30. package/dist/db/migrations.js.map +1 -0
  31. package/dist/db/queries.d.ts +281 -0
  32. package/dist/db/queries.d.ts.map +1 -0
  33. package/dist/db/queries.js +1300 -0
  34. package/dist/db/queries.js.map +1 -0
  35. package/dist/db/schema.sql +151 -0
  36. package/dist/db/sqlite-adapter.d.ts +46 -0
  37. package/dist/db/sqlite-adapter.d.ts.map +1 -0
  38. package/dist/db/sqlite-adapter.js +114 -0
  39. package/dist/db/sqlite-adapter.js.map +1 -0
  40. package/dist/directory.d.ts +57 -0
  41. package/dist/directory.d.ts.map +1 -0
  42. package/dist/directory.js +264 -0
  43. package/dist/directory.js.map +1 -0
  44. package/dist/errors.d.ts +136 -0
  45. package/dist/errors.d.ts.map +1 -0
  46. package/dist/errors.js +219 -0
  47. package/dist/errors.js.map +1 -0
  48. package/dist/extraction/dfm-extractor.d.ts +31 -0
  49. package/dist/extraction/dfm-extractor.d.ts.map +1 -0
  50. package/dist/extraction/dfm-extractor.js +151 -0
  51. package/dist/extraction/dfm-extractor.js.map +1 -0
  52. package/dist/extraction/grammars.d.ts +90 -0
  53. package/dist/extraction/grammars.d.ts.map +1 -0
  54. package/dist/extraction/grammars.js +407 -0
  55. package/dist/extraction/grammars.js.map +1 -0
  56. package/dist/extraction/index.d.ts +138 -0
  57. package/dist/extraction/index.d.ts.map +1 -0
  58. package/dist/extraction/index.js +1378 -0
  59. package/dist/extraction/index.js.map +1 -0
  60. package/dist/extraction/languages/c-cpp.d.ts +4 -0
  61. package/dist/extraction/languages/c-cpp.d.ts.map +1 -0
  62. package/dist/extraction/languages/c-cpp.js +171 -0
  63. package/dist/extraction/languages/c-cpp.js.map +1 -0
  64. package/dist/extraction/languages/csharp.d.ts +3 -0
  65. package/dist/extraction/languages/csharp.d.ts.map +1 -0
  66. package/dist/extraction/languages/csharp.js +73 -0
  67. package/dist/extraction/languages/csharp.js.map +1 -0
  68. package/dist/extraction/languages/dart.d.ts +3 -0
  69. package/dist/extraction/languages/dart.d.ts.map +1 -0
  70. package/dist/extraction/languages/dart.js +192 -0
  71. package/dist/extraction/languages/dart.js.map +1 -0
  72. package/dist/extraction/languages/go.d.ts +3 -0
  73. package/dist/extraction/languages/go.d.ts.map +1 -0
  74. package/dist/extraction/languages/go.js +70 -0
  75. package/dist/extraction/languages/go.js.map +1 -0
  76. package/dist/extraction/languages/index.d.ts +10 -0
  77. package/dist/extraction/languages/index.d.ts.map +1 -0
  78. package/dist/extraction/languages/index.js +51 -0
  79. package/dist/extraction/languages/index.js.map +1 -0
  80. package/dist/extraction/languages/java.d.ts +3 -0
  81. package/dist/extraction/languages/java.d.ts.map +1 -0
  82. package/dist/extraction/languages/java.js +70 -0
  83. package/dist/extraction/languages/java.js.map +1 -0
  84. package/dist/extraction/languages/javascript.d.ts +3 -0
  85. package/dist/extraction/languages/javascript.d.ts.map +1 -0
  86. package/dist/extraction/languages/javascript.js +90 -0
  87. package/dist/extraction/languages/javascript.js.map +1 -0
  88. package/dist/extraction/languages/kotlin.d.ts +3 -0
  89. package/dist/extraction/languages/kotlin.d.ts.map +1 -0
  90. package/dist/extraction/languages/kotlin.js +259 -0
  91. package/dist/extraction/languages/kotlin.js.map +1 -0
  92. package/dist/extraction/languages/lua.d.ts +3 -0
  93. package/dist/extraction/languages/lua.d.ts.map +1 -0
  94. package/dist/extraction/languages/lua.js +150 -0
  95. package/dist/extraction/languages/lua.js.map +1 -0
  96. package/dist/extraction/languages/luau.d.ts +3 -0
  97. package/dist/extraction/languages/luau.d.ts.map +1 -0
  98. package/dist/extraction/languages/luau.js +37 -0
  99. package/dist/extraction/languages/luau.js.map +1 -0
  100. package/dist/extraction/languages/objc.d.ts +3 -0
  101. package/dist/extraction/languages/objc.d.ts.map +1 -0
  102. package/dist/extraction/languages/objc.js +133 -0
  103. package/dist/extraction/languages/objc.js.map +1 -0
  104. package/dist/extraction/languages/pascal.d.ts +3 -0
  105. package/dist/extraction/languages/pascal.d.ts.map +1 -0
  106. package/dist/extraction/languages/pascal.js +66 -0
  107. package/dist/extraction/languages/pascal.js.map +1 -0
  108. package/dist/extraction/languages/php.d.ts +3 -0
  109. package/dist/extraction/languages/php.d.ts.map +1 -0
  110. package/dist/extraction/languages/php.js +107 -0
  111. package/dist/extraction/languages/php.js.map +1 -0
  112. package/dist/extraction/languages/python.d.ts +3 -0
  113. package/dist/extraction/languages/python.d.ts.map +1 -0
  114. package/dist/extraction/languages/python.js +56 -0
  115. package/dist/extraction/languages/python.js.map +1 -0
  116. package/dist/extraction/languages/ruby.d.ts +3 -0
  117. package/dist/extraction/languages/ruby.d.ts.map +1 -0
  118. package/dist/extraction/languages/ruby.js +114 -0
  119. package/dist/extraction/languages/ruby.js.map +1 -0
  120. package/dist/extraction/languages/rust.d.ts +3 -0
  121. package/dist/extraction/languages/rust.d.ts.map +1 -0
  122. package/dist/extraction/languages/rust.js +109 -0
  123. package/dist/extraction/languages/rust.js.map +1 -0
  124. package/dist/extraction/languages/scala.d.ts +3 -0
  125. package/dist/extraction/languages/scala.d.ts.map +1 -0
  126. package/dist/extraction/languages/scala.js +139 -0
  127. package/dist/extraction/languages/scala.js.map +1 -0
  128. package/dist/extraction/languages/swift.d.ts +3 -0
  129. package/dist/extraction/languages/swift.d.ts.map +1 -0
  130. package/dist/extraction/languages/swift.js +91 -0
  131. package/dist/extraction/languages/swift.js.map +1 -0
  132. package/dist/extraction/languages/typescript.d.ts +3 -0
  133. package/dist/extraction/languages/typescript.d.ts.map +1 -0
  134. package/dist/extraction/languages/typescript.js +129 -0
  135. package/dist/extraction/languages/typescript.js.map +1 -0
  136. package/dist/extraction/liquid-extractor.d.ts +52 -0
  137. package/dist/extraction/liquid-extractor.d.ts.map +1 -0
  138. package/dist/extraction/liquid-extractor.js +313 -0
  139. package/dist/extraction/liquid-extractor.js.map +1 -0
  140. package/dist/extraction/mybatis-extractor.d.ts +48 -0
  141. package/dist/extraction/mybatis-extractor.d.ts.map +1 -0
  142. package/dist/extraction/mybatis-extractor.js +198 -0
  143. package/dist/extraction/mybatis-extractor.js.map +1 -0
  144. package/dist/extraction/parse-worker.d.ts +8 -0
  145. package/dist/extraction/parse-worker.d.ts.map +1 -0
  146. package/dist/extraction/parse-worker.js +94 -0
  147. package/dist/extraction/parse-worker.js.map +1 -0
  148. package/dist/extraction/svelte-extractor.d.ts +56 -0
  149. package/dist/extraction/svelte-extractor.d.ts.map +1 -0
  150. package/dist/extraction/svelte-extractor.js +272 -0
  151. package/dist/extraction/svelte-extractor.js.map +1 -0
  152. package/dist/extraction/tree-sitter-helpers.d.ts +28 -0
  153. package/dist/extraction/tree-sitter-helpers.d.ts.map +1 -0
  154. package/dist/extraction/tree-sitter-helpers.js +103 -0
  155. package/dist/extraction/tree-sitter-helpers.js.map +1 -0
  156. package/dist/extraction/tree-sitter-types.d.ts +193 -0
  157. package/dist/extraction/tree-sitter-types.d.ts.map +1 -0
  158. package/dist/extraction/tree-sitter-types.js +10 -0
  159. package/dist/extraction/tree-sitter-types.js.map +1 -0
  160. package/dist/extraction/tree-sitter.d.ts +291 -0
  161. package/dist/extraction/tree-sitter.d.ts.map +1 -0
  162. package/dist/extraction/tree-sitter.js +2961 -0
  163. package/dist/extraction/tree-sitter.js.map +1 -0
  164. package/dist/extraction/vue-extractor.d.ts +36 -0
  165. package/dist/extraction/vue-extractor.d.ts.map +1 -0
  166. package/dist/extraction/vue-extractor.js +163 -0
  167. package/dist/extraction/vue-extractor.js.map +1 -0
  168. package/dist/extraction/wasm/tree-sitter-lua.wasm +0 -0
  169. package/dist/extraction/wasm/tree-sitter-luau.wasm +0 -0
  170. package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  171. package/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
  172. package/dist/extraction/wasm-runtime-flags.d.ts +38 -0
  173. package/dist/extraction/wasm-runtime-flags.d.ts.map +1 -0
  174. package/dist/extraction/wasm-runtime-flags.js +105 -0
  175. package/dist/extraction/wasm-runtime-flags.js.map +1 -0
  176. package/dist/graph/index.d.ts +8 -0
  177. package/dist/graph/index.d.ts.map +1 -0
  178. package/dist/graph/index.js +13 -0
  179. package/dist/graph/index.js.map +1 -0
  180. package/dist/graph/queries.d.ts +106 -0
  181. package/dist/graph/queries.d.ts.map +1 -0
  182. package/dist/graph/queries.js +366 -0
  183. package/dist/graph/queries.js.map +1 -0
  184. package/dist/graph/traversal.d.ts +127 -0
  185. package/dist/graph/traversal.d.ts.map +1 -0
  186. package/dist/graph/traversal.js +528 -0
  187. package/dist/graph/traversal.js.map +1 -0
  188. package/dist/index.d.ts +460 -0
  189. package/dist/index.d.ts.map +1 -0
  190. package/dist/index.js +863 -0
  191. package/dist/index.js.map +1 -0
  192. package/dist/installer/claude-md-template.d.ts +14 -0
  193. package/dist/installer/claude-md-template.d.ts.map +1 -0
  194. package/dist/installer/claude-md-template.js +21 -0
  195. package/dist/installer/claude-md-template.js.map +1 -0
  196. package/dist/installer/config-writer.d.ts +29 -0
  197. package/dist/installer/config-writer.d.ts.map +1 -0
  198. package/dist/installer/config-writer.js +111 -0
  199. package/dist/installer/config-writer.js.map +1 -0
  200. package/dist/installer/index.d.ts +117 -0
  201. package/dist/installer/index.d.ts.map +1 -0
  202. package/dist/installer/index.js +528 -0
  203. package/dist/installer/index.js.map +1 -0
  204. package/dist/installer/instructions-template.d.ts +28 -0
  205. package/dist/installer/instructions-template.d.ts.map +1 -0
  206. package/dist/installer/instructions-template.js +65 -0
  207. package/dist/installer/instructions-template.js.map +1 -0
  208. package/dist/installer/targets/antigravity.d.ts +57 -0
  209. package/dist/installer/targets/antigravity.d.ts.map +1 -0
  210. package/dist/installer/targets/antigravity.js +307 -0
  211. package/dist/installer/targets/antigravity.js.map +1 -0
  212. package/dist/installer/targets/claude.d.ts +47 -0
  213. package/dist/installer/targets/claude.d.ts.map +1 -0
  214. package/dist/installer/targets/claude.js +401 -0
  215. package/dist/installer/targets/claude.js.map +1 -0
  216. package/dist/installer/targets/codex.d.ts +18 -0
  217. package/dist/installer/targets/codex.d.ts.map +1 -0
  218. package/dist/installer/targets/codex.js +185 -0
  219. package/dist/installer/targets/codex.js.map +1 -0
  220. package/dist/installer/targets/cursor.d.ts +35 -0
  221. package/dist/installer/targets/cursor.d.ts.map +1 -0
  222. package/dist/installer/targets/cursor.js +283 -0
  223. package/dist/installer/targets/cursor.js.map +1 -0
  224. package/dist/installer/targets/gemini.d.ts +26 -0
  225. package/dist/installer/targets/gemini.d.ts.map +1 -0
  226. package/dist/installer/targets/gemini.js +165 -0
  227. package/dist/installer/targets/gemini.js.map +1 -0
  228. package/dist/installer/targets/hermes.d.ts +18 -0
  229. package/dist/installer/targets/hermes.d.ts.map +1 -0
  230. package/dist/installer/targets/hermes.js +359 -0
  231. package/dist/installer/targets/hermes.js.map +1 -0
  232. package/dist/installer/targets/kiro.d.ts +27 -0
  233. package/dist/installer/targets/kiro.d.ts.map +1 -0
  234. package/dist/installer/targets/kiro.js +196 -0
  235. package/dist/installer/targets/kiro.js.map +1 -0
  236. package/dist/installer/targets/opencode.d.ts +30 -0
  237. package/dist/installer/targets/opencode.d.ts.map +1 -0
  238. package/dist/installer/targets/opencode.js +235 -0
  239. package/dist/installer/targets/opencode.js.map +1 -0
  240. package/dist/installer/targets/registry.d.ts +35 -0
  241. package/dist/installer/targets/registry.d.ts.map +1 -0
  242. package/dist/installer/targets/registry.js +91 -0
  243. package/dist/installer/targets/registry.js.map +1 -0
  244. package/dist/installer/targets/shared.d.ts +77 -0
  245. package/dist/installer/targets/shared.d.ts.map +1 -0
  246. package/dist/installer/targets/shared.js +246 -0
  247. package/dist/installer/targets/shared.js.map +1 -0
  248. package/dist/installer/targets/toml.d.ts +52 -0
  249. package/dist/installer/targets/toml.d.ts.map +1 -0
  250. package/dist/installer/targets/toml.js +147 -0
  251. package/dist/installer/targets/toml.js.map +1 -0
  252. package/dist/installer/targets/types.d.ts +116 -0
  253. package/dist/installer/targets/types.d.ts.map +1 -0
  254. package/dist/installer/targets/types.js +16 -0
  255. package/dist/installer/targets/types.js.map +1 -0
  256. package/dist/mcp/daemon-paths.d.ts +46 -0
  257. package/dist/mcp/daemon-paths.d.ts.map +1 -0
  258. package/dist/mcp/daemon-paths.js +125 -0
  259. package/dist/mcp/daemon-paths.js.map +1 -0
  260. package/dist/mcp/daemon.d.ts +161 -0
  261. package/dist/mcp/daemon.d.ts.map +1 -0
  262. package/dist/mcp/daemon.js +403 -0
  263. package/dist/mcp/daemon.js.map +1 -0
  264. package/dist/mcp/engine.d.ts +100 -0
  265. package/dist/mcp/engine.d.ts.map +1 -0
  266. package/dist/mcp/engine.js +291 -0
  267. package/dist/mcp/engine.js.map +1 -0
  268. package/dist/mcp/index.d.ts +109 -0
  269. package/dist/mcp/index.d.ts.map +1 -0
  270. package/dist/mcp/index.js +470 -0
  271. package/dist/mcp/index.js.map +1 -0
  272. package/dist/mcp/proxy.d.ts +46 -0
  273. package/dist/mcp/proxy.d.ts.map +1 -0
  274. package/dist/mcp/proxy.js +276 -0
  275. package/dist/mcp/proxy.js.map +1 -0
  276. package/dist/mcp/server-instructions.d.ts +19 -0
  277. package/dist/mcp/server-instructions.d.ts.map +1 -0
  278. package/dist/mcp/server-instructions.js +73 -0
  279. package/dist/mcp/server-instructions.js.map +1 -0
  280. package/dist/mcp/session.d.ts +67 -0
  281. package/dist/mcp/session.d.ts.map +1 -0
  282. package/dist/mcp/session.js +276 -0
  283. package/dist/mcp/session.js.map +1 -0
  284. package/dist/mcp/tools.d.ts +385 -0
  285. package/dist/mcp/tools.d.ts.map +1 -0
  286. package/dist/mcp/tools.js +2545 -0
  287. package/dist/mcp/tools.js.map +1 -0
  288. package/dist/mcp/transport.d.ts +188 -0
  289. package/dist/mcp/transport.d.ts.map +1 -0
  290. package/dist/mcp/transport.js +343 -0
  291. package/dist/mcp/transport.js.map +1 -0
  292. package/dist/mcp/version.d.ts +19 -0
  293. package/dist/mcp/version.d.ts.map +1 -0
  294. package/dist/mcp/version.js +71 -0
  295. package/dist/mcp/version.js.map +1 -0
  296. package/dist/resolution/callback-synthesizer.d.ts +10 -0
  297. package/dist/resolution/callback-synthesizer.d.ts.map +1 -0
  298. package/dist/resolution/callback-synthesizer.js +924 -0
  299. package/dist/resolution/callback-synthesizer.js.map +1 -0
  300. package/dist/resolution/frameworks/cargo-workspace.d.ts +18 -0
  301. package/dist/resolution/frameworks/cargo-workspace.d.ts.map +1 -0
  302. package/dist/resolution/frameworks/cargo-workspace.js +225 -0
  303. package/dist/resolution/frameworks/cargo-workspace.js.map +1 -0
  304. package/dist/resolution/frameworks/csharp.d.ts +8 -0
  305. package/dist/resolution/frameworks/csharp.d.ts.map +1 -0
  306. package/dist/resolution/frameworks/csharp.js +241 -0
  307. package/dist/resolution/frameworks/csharp.js.map +1 -0
  308. package/dist/resolution/frameworks/drupal.d.ts +51 -0
  309. package/dist/resolution/frameworks/drupal.d.ts.map +1 -0
  310. package/dist/resolution/frameworks/drupal.js +367 -0
  311. package/dist/resolution/frameworks/drupal.js.map +1 -0
  312. package/dist/resolution/frameworks/expo-modules.d.ts +3 -0
  313. package/dist/resolution/frameworks/expo-modules.d.ts.map +1 -0
  314. package/dist/resolution/frameworks/expo-modules.js +143 -0
  315. package/dist/resolution/frameworks/expo-modules.js.map +1 -0
  316. package/dist/resolution/frameworks/express.d.ts +8 -0
  317. package/dist/resolution/frameworks/express.d.ts.map +1 -0
  318. package/dist/resolution/frameworks/express.js +308 -0
  319. package/dist/resolution/frameworks/express.js.map +1 -0
  320. package/dist/resolution/frameworks/fabric.d.ts +3 -0
  321. package/dist/resolution/frameworks/fabric.d.ts.map +1 -0
  322. package/dist/resolution/frameworks/fabric.js +354 -0
  323. package/dist/resolution/frameworks/fabric.js.map +1 -0
  324. package/dist/resolution/frameworks/go.d.ts +8 -0
  325. package/dist/resolution/frameworks/go.d.ts.map +1 -0
  326. package/dist/resolution/frameworks/go.js +161 -0
  327. package/dist/resolution/frameworks/go.js.map +1 -0
  328. package/dist/resolution/frameworks/index.d.ts +48 -0
  329. package/dist/resolution/frameworks/index.d.ts.map +1 -0
  330. package/dist/resolution/frameworks/index.js +161 -0
  331. package/dist/resolution/frameworks/index.js.map +1 -0
  332. package/dist/resolution/frameworks/java.d.ts +8 -0
  333. package/dist/resolution/frameworks/java.d.ts.map +1 -0
  334. package/dist/resolution/frameworks/java.js +504 -0
  335. package/dist/resolution/frameworks/java.js.map +1 -0
  336. package/dist/resolution/frameworks/laravel.d.ts +13 -0
  337. package/dist/resolution/frameworks/laravel.d.ts.map +1 -0
  338. package/dist/resolution/frameworks/laravel.js +257 -0
  339. package/dist/resolution/frameworks/laravel.js.map +1 -0
  340. package/dist/resolution/frameworks/nestjs.d.ts +26 -0
  341. package/dist/resolution/frameworks/nestjs.d.ts.map +1 -0
  342. package/dist/resolution/frameworks/nestjs.js +698 -0
  343. package/dist/resolution/frameworks/nestjs.js.map +1 -0
  344. package/dist/resolution/frameworks/play.d.ts +19 -0
  345. package/dist/resolution/frameworks/play.d.ts.map +1 -0
  346. package/dist/resolution/frameworks/play.js +111 -0
  347. package/dist/resolution/frameworks/play.js.map +1 -0
  348. package/dist/resolution/frameworks/python.d.ts +10 -0
  349. package/dist/resolution/frameworks/python.d.ts.map +1 -0
  350. package/dist/resolution/frameworks/python.js +396 -0
  351. package/dist/resolution/frameworks/python.js.map +1 -0
  352. package/dist/resolution/frameworks/react-native.d.ts +3 -0
  353. package/dist/resolution/frameworks/react-native.d.ts.map +1 -0
  354. package/dist/resolution/frameworks/react-native.js +360 -0
  355. package/dist/resolution/frameworks/react-native.js.map +1 -0
  356. package/dist/resolution/frameworks/react.d.ts +8 -0
  357. package/dist/resolution/frameworks/react.d.ts.map +1 -0
  358. package/dist/resolution/frameworks/react.js +365 -0
  359. package/dist/resolution/frameworks/react.js.map +1 -0
  360. package/dist/resolution/frameworks/ruby.d.ts +8 -0
  361. package/dist/resolution/frameworks/ruby.d.ts.map +1 -0
  362. package/dist/resolution/frameworks/ruby.js +302 -0
  363. package/dist/resolution/frameworks/ruby.js.map +1 -0
  364. package/dist/resolution/frameworks/rust.d.ts +8 -0
  365. package/dist/resolution/frameworks/rust.d.ts.map +1 -0
  366. package/dist/resolution/frameworks/rust.js +304 -0
  367. package/dist/resolution/frameworks/rust.js.map +1 -0
  368. package/dist/resolution/frameworks/svelte.d.ts +9 -0
  369. package/dist/resolution/frameworks/svelte.d.ts.map +1 -0
  370. package/dist/resolution/frameworks/svelte.js +249 -0
  371. package/dist/resolution/frameworks/svelte.js.map +1 -0
  372. package/dist/resolution/frameworks/swift-objc.d.ts +37 -0
  373. package/dist/resolution/frameworks/swift-objc.d.ts.map +1 -0
  374. package/dist/resolution/frameworks/swift-objc.js +252 -0
  375. package/dist/resolution/frameworks/swift-objc.js.map +1 -0
  376. package/dist/resolution/frameworks/swift.d.ts +10 -0
  377. package/dist/resolution/frameworks/swift.d.ts.map +1 -0
  378. package/dist/resolution/frameworks/swift.js +400 -0
  379. package/dist/resolution/frameworks/swift.js.map +1 -0
  380. package/dist/resolution/frameworks/vue.d.ts +9 -0
  381. package/dist/resolution/frameworks/vue.d.ts.map +1 -0
  382. package/dist/resolution/frameworks/vue.js +306 -0
  383. package/dist/resolution/frameworks/vue.js.map +1 -0
  384. package/dist/resolution/go-module.d.ts +26 -0
  385. package/dist/resolution/go-module.d.ts.map +1 -0
  386. package/dist/resolution/go-module.js +78 -0
  387. package/dist/resolution/go-module.js.map +1 -0
  388. package/dist/resolution/import-resolver.d.ts +68 -0
  389. package/dist/resolution/import-resolver.d.ts.map +1 -0
  390. package/dist/resolution/import-resolver.js +1231 -0
  391. package/dist/resolution/import-resolver.js.map +1 -0
  392. package/dist/resolution/index.d.ts +116 -0
  393. package/dist/resolution/index.d.ts.map +1 -0
  394. package/dist/resolution/index.js +878 -0
  395. package/dist/resolution/index.js.map +1 -0
  396. package/dist/resolution/lru-cache.d.ts +24 -0
  397. package/dist/resolution/lru-cache.d.ts.map +1 -0
  398. package/dist/resolution/lru-cache.js +62 -0
  399. package/dist/resolution/lru-cache.js.map +1 -0
  400. package/dist/resolution/name-matcher.d.ts +32 -0
  401. package/dist/resolution/name-matcher.d.ts.map +1 -0
  402. package/dist/resolution/name-matcher.js +596 -0
  403. package/dist/resolution/name-matcher.js.map +1 -0
  404. package/dist/resolution/path-aliases.d.ts +68 -0
  405. package/dist/resolution/path-aliases.d.ts.map +1 -0
  406. package/dist/resolution/path-aliases.js +238 -0
  407. package/dist/resolution/path-aliases.js.map +1 -0
  408. package/dist/resolution/strip-comments.d.ts +27 -0
  409. package/dist/resolution/strip-comments.d.ts.map +1 -0
  410. package/dist/resolution/strip-comments.js +441 -0
  411. package/dist/resolution/strip-comments.js.map +1 -0
  412. package/dist/resolution/swift-objc-bridge.d.ts +134 -0
  413. package/dist/resolution/swift-objc-bridge.d.ts.map +1 -0
  414. package/dist/resolution/swift-objc-bridge.js +256 -0
  415. package/dist/resolution/swift-objc-bridge.js.map +1 -0
  416. package/dist/resolution/types.d.ts +209 -0
  417. package/dist/resolution/types.d.ts.map +1 -0
  418. package/dist/resolution/types.js +8 -0
  419. package/dist/resolution/types.js.map +1 -0
  420. package/dist/search/query-parser.d.ts +57 -0
  421. package/dist/search/query-parser.d.ts.map +1 -0
  422. package/dist/search/query-parser.js +177 -0
  423. package/dist/search/query-parser.js.map +1 -0
  424. package/dist/search/query-utils.d.ts +53 -0
  425. package/dist/search/query-utils.d.ts.map +1 -0
  426. package/dist/search/query-utils.js +350 -0
  427. package/dist/search/query-utils.js.map +1 -0
  428. package/dist/sync/git-hooks.d.ts +45 -0
  429. package/dist/sync/git-hooks.d.ts.map +1 -0
  430. package/dist/sync/git-hooks.js +223 -0
  431. package/dist/sync/git-hooks.js.map +1 -0
  432. package/dist/sync/index.d.ts +19 -0
  433. package/dist/sync/index.d.ts.map +1 -0
  434. package/dist/sync/index.js +35 -0
  435. package/dist/sync/index.js.map +1 -0
  436. package/dist/sync/watch-policy.d.ts +48 -0
  437. package/dist/sync/watch-policy.d.ts.map +1 -0
  438. package/dist/sync/watch-policy.js +124 -0
  439. package/dist/sync/watch-policy.js.map +1 -0
  440. package/dist/sync/watcher.d.ts +191 -0
  441. package/dist/sync/watcher.d.ts.map +1 -0
  442. package/dist/sync/watcher.js +398 -0
  443. package/dist/sync/watcher.js.map +1 -0
  444. package/dist/sync/worktree.d.ts +54 -0
  445. package/dist/sync/worktree.d.ts.map +1 -0
  446. package/dist/sync/worktree.js +136 -0
  447. package/dist/sync/worktree.js.map +1 -0
  448. package/dist/types.d.ts +369 -0
  449. package/dist/types.d.ts.map +1 -0
  450. package/dist/types.js +78 -0
  451. package/dist/types.js.map +1 -0
  452. package/dist/ui/glyphs.d.ts +42 -0
  453. package/dist/ui/glyphs.d.ts.map +1 -0
  454. package/dist/ui/glyphs.js +78 -0
  455. package/dist/ui/glyphs.js.map +1 -0
  456. package/dist/ui/shimmer-progress.d.ts +11 -0
  457. package/dist/ui/shimmer-progress.d.ts.map +1 -0
  458. package/dist/ui/shimmer-progress.js +90 -0
  459. package/dist/ui/shimmer-progress.js.map +1 -0
  460. package/dist/ui/shimmer-worker.d.ts +2 -0
  461. package/dist/ui/shimmer-worker.d.ts.map +1 -0
  462. package/dist/ui/shimmer-worker.js +118 -0
  463. package/dist/ui/shimmer-worker.js.map +1 -0
  464. package/dist/ui/types.d.ts +17 -0
  465. package/dist/ui/types.d.ts.map +1 -0
  466. package/dist/ui/types.js +3 -0
  467. package/dist/ui/types.js.map +1 -0
  468. package/dist/utils.d.ts +205 -0
  469. package/dist/utils.d.ts.map +1 -0
  470. package/dist/utils.js +549 -0
  471. package/dist/utils.js.map +1 -0
  472. package/package.json +59 -0
  473. package/scripts/add-lang/bench.sh +60 -0
  474. package/scripts/add-lang/check-grammar.mjs +75 -0
  475. package/scripts/add-lang/dump-ast.mjs +103 -0
  476. package/scripts/add-lang/verify-extraction.mjs +70 -0
  477. package/scripts/agent-eval/arms-F.sh +21 -0
  478. package/scripts/agent-eval/arms-matrix.sh +37 -0
  479. package/scripts/agent-eval/audit.sh +68 -0
  480. package/scripts/agent-eval/bench-readme.sh +28 -0
  481. package/scripts/agent-eval/block-read-hook.sh +19 -0
  482. package/scripts/agent-eval/hook-settings.json +15 -0
  483. package/scripts/agent-eval/itrun.sh +107 -0
  484. package/scripts/agent-eval/parse-arms.mjs +116 -0
  485. package/scripts/agent-eval/parse-bench-readme.mjs +67 -0
  486. package/scripts/agent-eval/parse-run.mjs +45 -0
  487. package/scripts/agent-eval/parse-session.mjs +93 -0
  488. package/scripts/agent-eval/probe-context.mjs +21 -0
  489. package/scripts/agent-eval/probe-explore.mjs +40 -0
  490. package/scripts/agent-eval/probe-node.mjs +20 -0
  491. package/scripts/agent-eval/probe-trace.mjs +20 -0
  492. package/scripts/agent-eval/run-agent.sh +34 -0
  493. package/scripts/agent-eval/run-all.sh +67 -0
  494. package/scripts/agent-eval/run-arms.sh +56 -0
  495. package/scripts/agent-eval/seq-matrix.mjs +137 -0
  496. package/scripts/build-bundle.sh +118 -0
  497. package/scripts/extract-release-notes.mjs +130 -0
  498. package/scripts/local-install.sh +41 -0
  499. package/scripts/npm-shim.js +246 -0
  500. package/scripts/pack-npm.sh +95 -0
  501. package/scripts/prepare-release.mjs +270 -0
@@ -0,0 +1,1300 @@
1
+ "use strict";
2
+ /**
3
+ * Database Queries
4
+ *
5
+ * Prepared statements for CRUD operations on the knowledge graph.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.QueryBuilder = void 0;
9
+ const utils_1 = require("../utils");
10
+ const query_utils_1 = require("../search/query-utils");
11
+ const query_parser_1 = require("../search/query-parser");
12
+ const SQLITE_PARAM_CHUNK_SIZE = 500;
13
+ /**
14
+ * Convert database row to Node object
15
+ */
16
+ function rowToNode(row) {
17
+ return {
18
+ id: row.id,
19
+ kind: row.kind,
20
+ name: row.name,
21
+ qualifiedName: row.qualified_name,
22
+ filePath: row.file_path,
23
+ language: row.language,
24
+ startLine: row.start_line,
25
+ endLine: row.end_line,
26
+ startColumn: row.start_column,
27
+ endColumn: row.end_column,
28
+ docstring: row.docstring ?? undefined,
29
+ signature: row.signature ?? undefined,
30
+ visibility: row.visibility,
31
+ isExported: row.is_exported === 1,
32
+ isAsync: row.is_async === 1,
33
+ isStatic: row.is_static === 1,
34
+ isAbstract: row.is_abstract === 1,
35
+ decorators: row.decorators ? (0, utils_1.safeJsonParse)(row.decorators, undefined) : undefined,
36
+ typeParameters: row.type_parameters ? (0, utils_1.safeJsonParse)(row.type_parameters, undefined) : undefined,
37
+ updatedAt: row.updated_at,
38
+ };
39
+ }
40
+ /**
41
+ * Convert database row to Edge object
42
+ */
43
+ function rowToEdge(row) {
44
+ return {
45
+ source: row.source,
46
+ target: row.target,
47
+ kind: row.kind,
48
+ metadata: row.metadata ? (0, utils_1.safeJsonParse)(row.metadata, undefined) : undefined,
49
+ line: row.line ?? undefined,
50
+ column: row.col ?? undefined,
51
+ provenance: row.provenance,
52
+ };
53
+ }
54
+ /**
55
+ * Convert database row to FileRecord object
56
+ */
57
+ function rowToFileRecord(row) {
58
+ return {
59
+ path: row.path,
60
+ contentHash: row.content_hash,
61
+ language: row.language,
62
+ size: row.size,
63
+ modifiedAt: row.modified_at,
64
+ indexedAt: row.indexed_at,
65
+ nodeCount: row.node_count,
66
+ errors: row.errors ? (0, utils_1.safeJsonParse)(row.errors, undefined) : undefined,
67
+ };
68
+ }
69
+ /**
70
+ * Query builder for the knowledge graph database
71
+ */
72
+ class QueryBuilder {
73
+ db;
74
+ // Node cache for frequently accessed nodes (LRU-style, max 1000 entries)
75
+ nodeCache = new Map();
76
+ maxCacheSize = 1000;
77
+ // Prepared statements (lazily initialized)
78
+ stmts = {};
79
+ constructor(db) {
80
+ this.db = db;
81
+ }
82
+ // ===========================================================================
83
+ // Node Operations
84
+ // ===========================================================================
85
+ /**
86
+ * Insert a new node
87
+ */
88
+ insertNode(node) {
89
+ if (!this.stmts.insertNode) {
90
+ this.stmts.insertNode = this.db.prepare(`
91
+ INSERT OR REPLACE INTO nodes (
92
+ id, kind, name, qualified_name, file_path, language,
93
+ start_line, end_line, start_column, end_column,
94
+ docstring, signature, visibility,
95
+ is_exported, is_async, is_static, is_abstract,
96
+ decorators, type_parameters, updated_at
97
+ ) VALUES (
98
+ @id, @kind, @name, @qualifiedName, @filePath, @language,
99
+ @startLine, @endLine, @startColumn, @endColumn,
100
+ @docstring, @signature, @visibility,
101
+ @isExported, @isAsync, @isStatic, @isAbstract,
102
+ @decorators, @typeParameters, @updatedAt
103
+ )
104
+ `);
105
+ }
106
+ // Validate required fields to prevent SQLite bind errors
107
+ if (!node.id || !node.kind || !node.name || !node.filePath || !node.language) {
108
+ console.error('[CodeGraph] Skipping node with missing required fields:', {
109
+ id: node.id,
110
+ kind: node.kind,
111
+ name: node.name,
112
+ filePath: node.filePath,
113
+ language: node.language,
114
+ });
115
+ return;
116
+ }
117
+ // INSERT OR REPLACE may overwrite a node we have cached. Drop the
118
+ // stale entry so the next getNodeById sees the new row, not the old
119
+ // one (matches the cache-invalidation pattern used by updateNode and
120
+ // deleteNode below).
121
+ this.nodeCache.delete(node.id);
122
+ this.stmts.insertNode.run({
123
+ id: node.id,
124
+ kind: node.kind,
125
+ name: node.name,
126
+ qualifiedName: node.qualifiedName ?? node.name,
127
+ filePath: node.filePath,
128
+ language: node.language,
129
+ startLine: node.startLine ?? 0,
130
+ endLine: node.endLine ?? 0,
131
+ startColumn: node.startColumn ?? 0,
132
+ endColumn: node.endColumn ?? 0,
133
+ docstring: node.docstring ?? null,
134
+ signature: node.signature ?? null,
135
+ visibility: node.visibility ?? null,
136
+ isExported: node.isExported ? 1 : 0,
137
+ isAsync: node.isAsync ? 1 : 0,
138
+ isStatic: node.isStatic ? 1 : 0,
139
+ isAbstract: node.isAbstract ? 1 : 0,
140
+ decorators: node.decorators ? JSON.stringify(node.decorators) : null,
141
+ typeParameters: node.typeParameters ? JSON.stringify(node.typeParameters) : null,
142
+ updatedAt: node.updatedAt ?? Date.now(),
143
+ });
144
+ }
145
+ /**
146
+ * Insert multiple nodes in a transaction
147
+ */
148
+ insertNodes(nodes) {
149
+ this.db.transaction(() => {
150
+ for (const node of nodes) {
151
+ this.insertNode(node);
152
+ }
153
+ })();
154
+ }
155
+ /**
156
+ * Update an existing node
157
+ */
158
+ updateNode(node) {
159
+ if (!this.stmts.updateNode) {
160
+ this.stmts.updateNode = this.db.prepare(`
161
+ UPDATE nodes SET
162
+ kind = @kind,
163
+ name = @name,
164
+ qualified_name = @qualifiedName,
165
+ file_path = @filePath,
166
+ language = @language,
167
+ start_line = @startLine,
168
+ end_line = @endLine,
169
+ start_column = @startColumn,
170
+ end_column = @endColumn,
171
+ docstring = @docstring,
172
+ signature = @signature,
173
+ visibility = @visibility,
174
+ is_exported = @isExported,
175
+ is_async = @isAsync,
176
+ is_static = @isStatic,
177
+ is_abstract = @isAbstract,
178
+ decorators = @decorators,
179
+ type_parameters = @typeParameters,
180
+ updated_at = @updatedAt
181
+ WHERE id = @id
182
+ `);
183
+ }
184
+ // Invalidate cache before update
185
+ this.nodeCache.delete(node.id);
186
+ // Validate required fields
187
+ if (!node.id || !node.kind || !node.name || !node.filePath || !node.language) {
188
+ console.error('[CodeGraph] Skipping node update with missing required fields:', node.id);
189
+ return;
190
+ }
191
+ this.stmts.updateNode.run({
192
+ id: node.id,
193
+ kind: node.kind,
194
+ name: node.name,
195
+ qualifiedName: node.qualifiedName ?? node.name,
196
+ filePath: node.filePath,
197
+ language: node.language,
198
+ startLine: node.startLine ?? 0,
199
+ endLine: node.endLine ?? 0,
200
+ startColumn: node.startColumn ?? 0,
201
+ endColumn: node.endColumn ?? 0,
202
+ docstring: node.docstring ?? null,
203
+ signature: node.signature ?? null,
204
+ visibility: node.visibility ?? null,
205
+ isExported: node.isExported ? 1 : 0,
206
+ isAsync: node.isAsync ? 1 : 0,
207
+ isStatic: node.isStatic ? 1 : 0,
208
+ isAbstract: node.isAbstract ? 1 : 0,
209
+ decorators: node.decorators ? JSON.stringify(node.decorators) : null,
210
+ typeParameters: node.typeParameters ? JSON.stringify(node.typeParameters) : null,
211
+ updatedAt: node.updatedAt ?? Date.now(),
212
+ });
213
+ }
214
+ /**
215
+ * Delete a node by ID
216
+ */
217
+ deleteNode(id) {
218
+ if (!this.stmts.deleteNode) {
219
+ this.stmts.deleteNode = this.db.prepare('DELETE FROM nodes WHERE id = ?');
220
+ }
221
+ // Invalidate cache
222
+ this.nodeCache.delete(id);
223
+ this.stmts.deleteNode.run(id);
224
+ }
225
+ /**
226
+ * Delete all nodes for a file
227
+ */
228
+ deleteNodesByFile(filePath) {
229
+ if (!this.stmts.deleteNodesByFile) {
230
+ this.stmts.deleteNodesByFile = this.db.prepare('DELETE FROM nodes WHERE file_path = ?');
231
+ }
232
+ // Invalidate cache for nodes in this file
233
+ for (const [id, node] of this.nodeCache) {
234
+ if (node.filePath === filePath) {
235
+ this.nodeCache.delete(id);
236
+ }
237
+ }
238
+ this.stmts.deleteNodesByFile.run(filePath);
239
+ }
240
+ /**
241
+ * Get a node by ID
242
+ */
243
+ getNodeById(id) {
244
+ // Check cache first
245
+ if (this.nodeCache.has(id)) {
246
+ const cached = this.nodeCache.get(id);
247
+ // Move to end to implement LRU (delete and re-add)
248
+ this.nodeCache.delete(id);
249
+ this.nodeCache.set(id, cached);
250
+ return cached;
251
+ }
252
+ if (!this.stmts.getNodeById) {
253
+ this.stmts.getNodeById = this.db.prepare('SELECT * FROM nodes WHERE id = ?');
254
+ }
255
+ const row = this.stmts.getNodeById.get(id);
256
+ if (!row) {
257
+ return null;
258
+ }
259
+ const node = rowToNode(row);
260
+ this.cacheNode(node);
261
+ return node;
262
+ }
263
+ /**
264
+ * Batch lookup: fetch many nodes by ID in a single SQL round-trip.
265
+ *
266
+ * Replaces the N+1 pattern in graph traversal where every edge would
267
+ * trigger its own `getNodeById` call. For a function with 50 callers
268
+ * this collapses 50 point reads into one IN-list query (~10-50x
269
+ * faster end-to-end).
270
+ *
271
+ * Returns a Map keyed by id so callers can preserve their own ordering
272
+ * (typically the order edges were returned from the graph). Missing IDs
273
+ * are simply absent from the map.
274
+ *
275
+ * Cache-aware: ids already in the LRU cache are served from memory and
276
+ * the SQL query only touches the misses.
277
+ */
278
+ getNodesByIds(ids) {
279
+ const out = new Map();
280
+ if (ids.length === 0)
281
+ return out;
282
+ // Serve cache hits first; build the miss list for SQL.
283
+ const misses = [];
284
+ for (const id of ids) {
285
+ const cached = this.nodeCache.get(id);
286
+ if (cached !== undefined) {
287
+ // LRU touch
288
+ this.nodeCache.delete(id);
289
+ this.nodeCache.set(id, cached);
290
+ out.set(id, cached);
291
+ }
292
+ else {
293
+ misses.push(id);
294
+ }
295
+ }
296
+ if (misses.length === 0)
297
+ return out;
298
+ // Chunk under SQLite's parameter limit (default 999, raised to 32766
299
+ // in better-sqlite3 builds — chunk at 500 for safety across both
300
+ // backends and to keep the query plan simple).
301
+ for (let i = 0; i < misses.length; i += SQLITE_PARAM_CHUNK_SIZE) {
302
+ const chunk = misses.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
303
+ const placeholders = chunk.map(() => '?').join(',');
304
+ const rows = this.db
305
+ .prepare(`SELECT * FROM nodes WHERE id IN (${placeholders})`)
306
+ .all(...chunk);
307
+ for (const row of rows) {
308
+ const node = rowToNode(row);
309
+ out.set(node.id, node);
310
+ this.cacheNode(node);
311
+ }
312
+ }
313
+ return out;
314
+ }
315
+ getExistingNodeIds(ids) {
316
+ const out = new Set();
317
+ if (ids.length === 0)
318
+ return out;
319
+ const uniqueIds = [...new Set(ids)];
320
+ for (let i = 0; i < uniqueIds.length; i += SQLITE_PARAM_CHUNK_SIZE) {
321
+ const chunk = uniqueIds.slice(i, i + SQLITE_PARAM_CHUNK_SIZE);
322
+ const placeholders = chunk.map(() => '?').join(',');
323
+ const rows = this.db
324
+ .prepare(`SELECT id FROM nodes WHERE id IN (${placeholders})`)
325
+ .all(...chunk);
326
+ for (const row of rows) {
327
+ out.add(row.id);
328
+ }
329
+ }
330
+ return out;
331
+ }
332
+ /**
333
+ * Add a node to the cache, evicting oldest if needed
334
+ */
335
+ cacheNode(node) {
336
+ if (this.nodeCache.size >= this.maxCacheSize) {
337
+ // Evict oldest (first) entry
338
+ const firstKey = this.nodeCache.keys().next().value;
339
+ if (firstKey) {
340
+ this.nodeCache.delete(firstKey);
341
+ }
342
+ }
343
+ this.nodeCache.set(node.id, node);
344
+ }
345
+ /**
346
+ * Clear the node cache
347
+ */
348
+ clearCache() {
349
+ this.nodeCache.clear();
350
+ }
351
+ /**
352
+ * Get all nodes in a file
353
+ */
354
+ getNodesByFile(filePath) {
355
+ if (!this.stmts.getNodesByFile) {
356
+ this.stmts.getNodesByFile = this.db.prepare('SELECT * FROM nodes WHERE file_path = ? ORDER BY start_line');
357
+ }
358
+ const rows = this.stmts.getNodesByFile.all(filePath);
359
+ return rows.map(rowToNode);
360
+ }
361
+ /**
362
+ * Get all nodes of a specific kind
363
+ */
364
+ getNodesByKind(kind) {
365
+ if (!this.stmts.getNodesByKind) {
366
+ this.stmts.getNodesByKind = this.db.prepare('SELECT * FROM nodes WHERE kind = ?');
367
+ }
368
+ const rows = this.stmts.getNodesByKind.all(kind);
369
+ return rows.map(rowToNode);
370
+ }
371
+ /**
372
+ * Get all nodes in the database
373
+ */
374
+ getAllNodes() {
375
+ const rows = this.db.prepare('SELECT * FROM nodes').all();
376
+ return rows.map(rowToNode);
377
+ }
378
+ /**
379
+ * Get nodes by exact name match (uses idx_nodes_name index)
380
+ */
381
+ getNodesByName(name) {
382
+ if (!this.stmts.getNodesByName) {
383
+ this.stmts.getNodesByName = this.db.prepare('SELECT * FROM nodes WHERE name = ?');
384
+ }
385
+ const rows = this.stmts.getNodesByName.all(name);
386
+ return rows.map(rowToNode);
387
+ }
388
+ /**
389
+ * Get nodes by exact qualified name match (uses idx_nodes_qualified_name index)
390
+ */
391
+ getNodesByQualifiedNameExact(qualifiedName) {
392
+ if (!this.stmts.getNodesByQualifiedNameExact) {
393
+ this.stmts.getNodesByQualifiedNameExact = this.db.prepare('SELECT * FROM nodes WHERE qualified_name = ?');
394
+ }
395
+ const rows = this.stmts.getNodesByQualifiedNameExact.all(qualifiedName);
396
+ return rows.map(rowToNode);
397
+ }
398
+ /**
399
+ * Get nodes by lowercase name match (uses idx_nodes_lower_name expression index)
400
+ */
401
+ getNodesByLowerName(lowerName) {
402
+ if (!this.stmts.getNodesByLowerName) {
403
+ this.stmts.getNodesByLowerName = this.db.prepare('SELECT * FROM nodes WHERE lower(name) = ?');
404
+ }
405
+ const rows = this.stmts.getNodesByLowerName.all(lowerName);
406
+ return rows.map(rowToNode);
407
+ }
408
+ /**
409
+ * Search nodes by name using FTS with fallback to LIKE for better matching
410
+ *
411
+ * Search strategy:
412
+ * 1. Try FTS5 prefix match (query*) for word-start matching
413
+ * 2. If no results, try LIKE for substring matching (e.g., "signIn" finds "signInWithGoogle")
414
+ * 3. Score results based on match quality
415
+ */
416
+ searchNodes(query, options = {}) {
417
+ const { limit = 100, offset = 0 } = options;
418
+ // Parse field-qualified bits out of the raw query (kind:, lang:,
419
+ // path:, name:). Anything not recognised stays in `text` and goes
420
+ // to FTS unchanged. Filters compose with the SearchOptions arg —
421
+ // both are applied (intersection-style).
422
+ const parsed = (0, query_parser_1.parseQuery)(query);
423
+ const mergedKinds = parsed.kinds.length > 0
424
+ ? Array.from(new Set([...(options.kinds ?? []), ...parsed.kinds]))
425
+ : options.kinds;
426
+ const mergedLanguages = parsed.languages.length > 0
427
+ ? Array.from(new Set([...(options.languages ?? []), ...parsed.languages]))
428
+ : options.languages;
429
+ const pathFilters = parsed.pathFilters;
430
+ const nameFilters = parsed.nameFilters;
431
+ // The text portion drives FTS/LIKE; if all the user typed was
432
+ // filters (`kind:function`), we still need *some* candidate set,
433
+ // so synthesise an empty-text path that returns everything matching
434
+ // the filters.
435
+ const text = parsed.text;
436
+ const kinds = mergedKinds;
437
+ const languages = mergedLanguages;
438
+ // First try FTS5 with prefix matching
439
+ let results = text
440
+ ? this.searchNodesFTS(text, { kinds, languages, limit, offset })
441
+ // Over-fetch by 5× when running filter-only (no text). The
442
+ // post-scoring path: + name: filters can be very selective, so
443
+ // a smaller multiplier risks returning fewer than `limit`
444
+ // results despite the DB having plenty of matches.
445
+ : this.searchAllByFilters({ kinds, languages, limit: limit * 5 });
446
+ // If no FTS results, try LIKE-based substring search
447
+ if (results.length === 0 && text.length >= 2) {
448
+ results = this.searchNodesLike(text, { kinds, languages, limit, offset });
449
+ }
450
+ // Final fuzzy fallback: scan all known names and keep those within
451
+ // a tight Levenshtein distance. Only fires when both FTS and LIKE
452
+ // returned nothing AND there's a text portion long enough to be
453
+ // worth fuzzing (1-char queries would match too much).
454
+ if (results.length === 0 && text.length >= 3) {
455
+ results = this.searchNodesFuzzy(text, { kinds, languages, limit });
456
+ }
457
+ // Supplement: ensure exact name matches are always candidates.
458
+ // BM25 can bury short exact-match names (e.g. "getBean") under hundreds of
459
+ // compound names (e.g. "getBeanDescriptor") in large codebases,
460
+ // pushing them past the FTS fetch limit before post-hoc scoring can help.
461
+ // Use the max BM25 score as the base so the nameMatchBonus (exact=30 vs
462
+ // prefix=20) actually differentiates them after rescoring.
463
+ if (results.length > 0 && query) {
464
+ const existingIds = new Set(results.map(r => r.node.id));
465
+ const maxFtsScore = Math.max(...results.map(r => r.score));
466
+ const terms = query.split(/\s+/).filter(t => t.length >= 2);
467
+ for (const term of terms) {
468
+ let sql = 'SELECT * FROM nodes WHERE name = ? COLLATE NOCASE';
469
+ const params = [term];
470
+ if (kinds && kinds.length > 0) {
471
+ sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
472
+ params.push(...kinds);
473
+ }
474
+ if (languages && languages.length > 0) {
475
+ sql += ` AND language IN (${languages.map(() => '?').join(',')})`;
476
+ params.push(...languages);
477
+ }
478
+ sql += ' LIMIT 20';
479
+ const rows = this.db.prepare(sql).all(...params);
480
+ for (const row of rows) {
481
+ if (!existingIds.has(row.id)) {
482
+ results.push({ node: rowToNode(row), score: maxFtsScore });
483
+ existingIds.add(row.id);
484
+ }
485
+ }
486
+ }
487
+ }
488
+ // Apply multi-signal scoring
489
+ if (results.length > 0 && (text || query)) {
490
+ const scoringQuery = text || query;
491
+ results = results.map(r => ({
492
+ ...r,
493
+ score: r.score
494
+ + (0, query_utils_1.kindBonus)(r.node.kind)
495
+ + (0, query_utils_1.scorePathRelevance)(r.node.filePath, scoringQuery)
496
+ + (0, query_utils_1.nameMatchBonus)(r.node.name, scoringQuery),
497
+ }));
498
+ results.sort((a, b) => b.score - a.score);
499
+ // Trim to requested limit after rescoring
500
+ if (results.length > limit) {
501
+ results = results.slice(0, limit);
502
+ }
503
+ }
504
+ // Apply path: + name: filters AFTER scoring. Scoring already uses
505
+ // path/name as a soft signal; the explicit filters here are a hard
506
+ // gate. Done last so the FTS limit fetched plenty of candidates to
507
+ // narrow from.
508
+ if (pathFilters.length > 0) {
509
+ const lowered = pathFilters.map((p) => p.toLowerCase());
510
+ results = results.filter((r) => {
511
+ const fp = r.node.filePath.toLowerCase();
512
+ return lowered.some((p) => fp.includes(p));
513
+ });
514
+ }
515
+ if (nameFilters.length > 0) {
516
+ const lowered = nameFilters.map((n) => n.toLowerCase());
517
+ results = results.filter((r) => {
518
+ const nm = r.node.name.toLowerCase();
519
+ return lowered.some((n) => nm.includes(n));
520
+ });
521
+ }
522
+ return results;
523
+ }
524
+ /**
525
+ * Match-everything path used when the user supplied only field
526
+ * filters (`kind:function lang:typescript`) with no text. Returns
527
+ * candidates ordered by name; the caller's filter pass narrows to
528
+ * what was asked for.
529
+ */
530
+ searchAllByFilters(options) {
531
+ const { kinds, languages, limit } = options;
532
+ let sql = 'SELECT * FROM nodes WHERE 1=1';
533
+ const params = [];
534
+ if (kinds && kinds.length > 0) {
535
+ sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
536
+ params.push(...kinds);
537
+ }
538
+ if (languages && languages.length > 0) {
539
+ sql += ` AND language IN (${languages.map(() => '?').join(',')})`;
540
+ params.push(...languages);
541
+ }
542
+ sql += ' ORDER BY name LIMIT ?';
543
+ params.push(limit);
544
+ const rows = this.db.prepare(sql).all(...params);
545
+ return rows.map((row) => ({ node: rowToNode(row), score: 1 }));
546
+ }
547
+ /**
548
+ * Fuzzy fallback: when zero FTS/LIKE hits, try an edit-distance
549
+ * sweep over the distinct symbol-name set. Caps `maxDist` at 2 so
550
+ * `getUssr` finds `getUser` but `process` doesn't match `prosody`.
551
+ * Bounded edit distance keeps each comparison cheap; the per-query
552
+ * scan is O(distinct-name-count) which is far smaller than total
553
+ * node count on any real codebase.
554
+ */
555
+ searchNodesFuzzy(text, options) {
556
+ const { kinds, languages, limit } = options;
557
+ const lowered = text.toLowerCase();
558
+ const maxDist = lowered.length <= 4 ? 1 : 2;
559
+ // Pull the distinct name list once. The set is cached on QueryBuilder
560
+ // by getAllNodeNames(); even on a 200k-node project the distinct
561
+ // name set is typically O(10k) because most names repeat. The
562
+ // candidate-cap below bounds memory regardless.
563
+ const allNames = this.getAllNodeNames();
564
+ const candidates = [];
565
+ for (const name of allNames) {
566
+ const dist = (0, query_parser_1.boundedEditDistance)(name.toLowerCase(), lowered, maxDist);
567
+ if (dist <= maxDist)
568
+ candidates.push({ name, dist });
569
+ }
570
+ candidates.sort((a, b) => a.dist - b.dist);
571
+ // Cap the per-name follow-up queries. Each survivor triggers a
572
+ // separate `SELECT * FROM nodes WHERE name = ?`; without this cap
573
+ // a project with many similar names (`getUser1`, `getUser2`...)
574
+ // could fan out far beyond `limit` queries before the inner-loop
575
+ // limit kicks in.
576
+ const FUZZY_FOLLOWUP_CAP = Math.max(limit * 2, 50);
577
+ const cappedCandidates = candidates.slice(0, FUZZY_FOLLOWUP_CAP);
578
+ const results = [];
579
+ const seen = new Set();
580
+ for (const c of cappedCandidates) {
581
+ if (results.length >= limit)
582
+ break;
583
+ let sql = 'SELECT * FROM nodes WHERE name = ?';
584
+ const params = [c.name];
585
+ if (kinds && kinds.length > 0) {
586
+ sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
587
+ params.push(...kinds);
588
+ }
589
+ if (languages && languages.length > 0) {
590
+ sql += ` AND language IN (${languages.map(() => '?').join(',')})`;
591
+ params.push(...languages);
592
+ }
593
+ sql += ' LIMIT 5';
594
+ const rows = this.db.prepare(sql).all(...params);
595
+ for (const row of rows) {
596
+ if (seen.has(row.id))
597
+ continue;
598
+ seen.add(row.id);
599
+ // Lower the score for each edit step away from the query so
600
+ // exact-match fallbacks (dist 0) outrank dist-2 typos.
601
+ results.push({ node: rowToNode(row), score: 1 / (1 + c.dist) });
602
+ if (results.length >= limit)
603
+ break;
604
+ }
605
+ }
606
+ return results;
607
+ }
608
+ /**
609
+ * FTS5 search with prefix matching
610
+ */
611
+ searchNodesFTS(query, options) {
612
+ const { kinds, languages, limit = 100, offset = 0 } = options;
613
+ // Add prefix wildcard for better matching (e.g., "auth" matches "AuthService", "authenticate")
614
+ // Escape special FTS5 characters and add prefix wildcard.
615
+ //
616
+ // `::` is a qualifier separator in Rust/C++/Ruby, not a token char,
617
+ // so treat it as whitespace before the strip step. Otherwise queries
618
+ // like `stage_apply::run` collapse to `stage_applyrun` (the colons
619
+ // are stripped without splitting) and find nothing. See #173.
620
+ const ftsQuery = query
621
+ .replace(/::/g, ' ') // Rust/C++/Ruby qualifier separator
622
+ .replace(/['"*():^]/g, '') // Remove FTS5 special chars
623
+ .split(/\s+/)
624
+ .filter(term => term.length > 0)
625
+ // Strip FTS5 boolean operators to prevent query manipulation
626
+ .filter(term => !/^(AND|OR|NOT|NEAR)$/i.test(term))
627
+ .map(term => `"${term}"*`) // Prefix match each term
628
+ .join(' OR ');
629
+ if (!ftsQuery) {
630
+ return [];
631
+ }
632
+ // BM25 column weights: id=0, name=20, qualified_name=5, docstring=1, signature=2
633
+ // Heavy name weight ensures exact/prefix name matches rank above incidental
634
+ // mentions in long docstrings or qualified names of nested symbols.
635
+ // Fetch 5x requested limit so post-hoc rescoring (kindBonus, pathRelevance,
636
+ // nameMatchBonus) can promote results that BM25 alone undervalues.
637
+ const ftsLimit = Math.max(limit * 5, 100);
638
+ let sql = `
639
+ SELECT nodes.*, bm25(nodes_fts, 0, 20, 5, 1, 2) as score
640
+ FROM nodes_fts
641
+ JOIN nodes ON nodes_fts.id = nodes.id
642
+ WHERE nodes_fts MATCH ?
643
+ `;
644
+ const params = [ftsQuery];
645
+ if (kinds && kinds.length > 0) {
646
+ sql += ` AND nodes.kind IN (${kinds.map(() => '?').join(',')})`;
647
+ params.push(...kinds);
648
+ }
649
+ if (languages && languages.length > 0) {
650
+ sql += ` AND nodes.language IN (${languages.map(() => '?').join(',')})`;
651
+ params.push(...languages);
652
+ }
653
+ sql += ' ORDER BY score LIMIT ? OFFSET ?';
654
+ params.push(ftsLimit, offset);
655
+ try {
656
+ const rows = this.db.prepare(sql).all(...params);
657
+ return rows.map((row) => ({
658
+ node: rowToNode(row),
659
+ score: Math.abs(row.score), // bm25 returns negative scores
660
+ }));
661
+ }
662
+ catch {
663
+ // FTS query failed, return empty
664
+ return [];
665
+ }
666
+ }
667
+ /**
668
+ * LIKE-based substring search for cases where FTS doesn't match
669
+ * Useful for camelCase matching (e.g., "signIn" finds "signInWithGoogle")
670
+ */
671
+ searchNodesLike(query, options) {
672
+ const { kinds, languages, limit = 100, offset = 0 } = options;
673
+ let sql = `
674
+ SELECT nodes.*,
675
+ CASE
676
+ WHEN name = ? THEN 1.0
677
+ WHEN name LIKE ? THEN 0.9
678
+ WHEN name LIKE ? THEN 0.8
679
+ WHEN qualified_name LIKE ? THEN 0.7
680
+ ELSE 0.5
681
+ END as score
682
+ FROM nodes
683
+ WHERE (
684
+ name LIKE ? OR
685
+ qualified_name LIKE ? OR
686
+ name LIKE ?
687
+ )
688
+ `;
689
+ // Pattern variants for better matching
690
+ const exactMatch = query;
691
+ const startsWith = `${query}%`;
692
+ const contains = `%${query}%`;
693
+ const params = [
694
+ exactMatch, // Exact match score
695
+ startsWith, // Starts with score
696
+ contains, // Contains score
697
+ contains, // Qualified name score
698
+ contains, // WHERE: name contains
699
+ contains, // WHERE: qualified_name contains
700
+ startsWith, // WHERE: name starts with
701
+ ];
702
+ if (kinds && kinds.length > 0) {
703
+ sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
704
+ params.push(...kinds);
705
+ }
706
+ if (languages && languages.length > 0) {
707
+ sql += ` AND language IN (${languages.map(() => '?').join(',')})`;
708
+ params.push(...languages);
709
+ }
710
+ sql += ' ORDER BY score DESC, length(name) ASC LIMIT ? OFFSET ?';
711
+ params.push(limit, offset);
712
+ const rows = this.db.prepare(sql).all(...params);
713
+ return rows.map((row) => ({
714
+ node: rowToNode(row),
715
+ score: row.score,
716
+ }));
717
+ }
718
+ /**
719
+ * Find nodes by exact name match
720
+ *
721
+ * Used for hybrid search - looks up symbols by exact name or case-insensitive match.
722
+ * Returns high-confidence matches for known symbol names extracted from query.
723
+ *
724
+ * @param names - Array of symbol names to look up
725
+ * @param options - Search options (kinds, languages, limit)
726
+ * @returns SearchResult array with exact matches scored at 1.0
727
+ */
728
+ findNodesByExactName(names, options = {}) {
729
+ if (names.length === 0)
730
+ return [];
731
+ const { kinds, languages, limit = 50 } = options;
732
+ // Two-pass approach to handle common names (e.g., "run" has 40+ matches):
733
+ // Pass 1: Find which files contain distinctive (rare) symbols from the query.
734
+ // Pass 2: Query each name, boosting results that co-locate with distinctive symbols.
735
+ // Pass 1: Find files containing each queried name, identify distinctive names
736
+ const nameToFiles = new Map();
737
+ for (const name of names) {
738
+ let sql = 'SELECT DISTINCT file_path FROM nodes WHERE name COLLATE NOCASE = ?';
739
+ const params = [name];
740
+ if (kinds && kinds.length > 0) {
741
+ sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
742
+ params.push(...kinds);
743
+ }
744
+ sql += ' LIMIT 100';
745
+ const rows = this.db.prepare(sql).all(...params);
746
+ nameToFiles.set(name.toLowerCase(), new Set(rows.map(r => r.file_path)));
747
+ }
748
+ // Distinctive names are those with fewer than 10 file matches (e.g., "scrapeLoop" = 1 file)
749
+ const distinctiveFiles = new Set();
750
+ for (const [, files] of nameToFiles) {
751
+ if (files.size > 0 && files.size < 10) {
752
+ for (const f of files)
753
+ distinctiveFiles.add(f);
754
+ }
755
+ }
756
+ // Pass 2: Query each name with per-name limit, scoring by co-location
757
+ const perNameLimit = Math.max(8, Math.ceil(limit / names.length));
758
+ const allResults = [];
759
+ const seenIds = new Set();
760
+ for (const name of names) {
761
+ let sql = `
762
+ SELECT nodes.*, 1.0 as score
763
+ FROM nodes
764
+ WHERE name COLLATE NOCASE = ?
765
+ `;
766
+ const params = [name];
767
+ if (kinds && kinds.length > 0) {
768
+ sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
769
+ params.push(...kinds);
770
+ }
771
+ if (languages && languages.length > 0) {
772
+ sql += ` AND language IN (${languages.map(() => '?').join(',')})`;
773
+ params.push(...languages);
774
+ }
775
+ // Fetch enough to find co-located results among common names
776
+ sql += ' LIMIT ?';
777
+ params.push(Math.max(perNameLimit * 3, 50));
778
+ const rows = this.db.prepare(sql).all(...params);
779
+ const nameResults = [];
780
+ for (const row of rows) {
781
+ const node = rowToNode(row);
782
+ if (seenIds.has(node.id))
783
+ continue;
784
+ // Boost results in files that also contain distinctive symbols
785
+ const coLocationBoost = distinctiveFiles.has(node.filePath) ? 20 : 0;
786
+ nameResults.push({ node, score: row.score + coLocationBoost });
787
+ }
788
+ // Sort by score (co-located first), take per-name limit
789
+ nameResults.sort((a, b) => b.score - a.score);
790
+ for (const r of nameResults.slice(0, perNameLimit)) {
791
+ seenIds.add(r.node.id);
792
+ allResults.push(r);
793
+ }
794
+ }
795
+ // Sort all results by score so co-located results bubble up
796
+ allResults.sort((a, b) => b.score - a.score);
797
+ return allResults.slice(0, limit);
798
+ }
799
+ /**
800
+ * Find nodes whose name contains a substring (LIKE-based).
801
+ * Useful for CamelCase-part matching where FTS fails because
802
+ * e.g. "TransportSearchAction" is one FTS token, not matchable by "Search"*.
803
+ *
804
+ * Results are ordered by name length (shorter = more likely to be the core type).
805
+ */
806
+ findNodesByNameSubstring(substring, options = {}) {
807
+ const { kinds, languages, limit = 30, excludePrefix } = options;
808
+ let sql = `
809
+ SELECT nodes.*, 1.0 as score
810
+ FROM nodes
811
+ WHERE name LIKE ?
812
+ `;
813
+ const params = [`%${substring}%`];
814
+ // Exclude prefix matches (handled by FTS-based prefix search in Step 2b)
815
+ if (excludePrefix) {
816
+ sql += ` AND name NOT LIKE ?`;
817
+ params.push(`${substring}%`);
818
+ }
819
+ if (kinds && kinds.length > 0) {
820
+ sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
821
+ params.push(...kinds);
822
+ }
823
+ if (languages && languages.length > 0) {
824
+ sql += ` AND language IN (${languages.map(() => '?').join(',')})`;
825
+ params.push(...languages);
826
+ }
827
+ sql += ' ORDER BY length(name) ASC LIMIT ?';
828
+ params.push(limit);
829
+ const rows = this.db.prepare(sql).all(...params);
830
+ return rows.map((row) => ({
831
+ node: rowToNode(row),
832
+ score: row.score,
833
+ }));
834
+ }
835
+ // ===========================================================================
836
+ // Edge Operations
837
+ // ===========================================================================
838
+ /**
839
+ * Insert a new edge
840
+ */
841
+ insertEdge(edge) {
842
+ if (!this.stmts.insertEdge) {
843
+ this.stmts.insertEdge = this.db.prepare(`
844
+ INSERT OR IGNORE INTO edges (source, target, kind, metadata, line, col, provenance)
845
+ VALUES (@source, @target, @kind, @metadata, @line, @col, @provenance)
846
+ `);
847
+ }
848
+ this.stmts.insertEdge.run({
849
+ source: edge.source,
850
+ target: edge.target,
851
+ kind: edge.kind,
852
+ metadata: edge.metadata ? JSON.stringify(edge.metadata) : null,
853
+ line: edge.line ?? null,
854
+ col: edge.column ?? null,
855
+ provenance: edge.provenance ?? null,
856
+ });
857
+ }
858
+ /**
859
+ * Insert multiple edges in a transaction
860
+ */
861
+ insertEdges(edges) {
862
+ if (edges.length === 0)
863
+ return;
864
+ this.db.transaction(() => {
865
+ const endpointIds = new Set();
866
+ for (const edge of edges) {
867
+ endpointIds.add(edge.source);
868
+ endpointIds.add(edge.target);
869
+ }
870
+ const existingNodeIds = this.getExistingNodeIds([...endpointIds]);
871
+ for (const edge of edges) {
872
+ if (!existingNodeIds.has(edge.source) || !existingNodeIds.has(edge.target)) {
873
+ continue;
874
+ }
875
+ this.insertEdge(edge);
876
+ }
877
+ })();
878
+ }
879
+ /**
880
+ * Delete all edges from a source node
881
+ */
882
+ deleteEdgesBySource(sourceId) {
883
+ if (!this.stmts.deleteEdgesBySource) {
884
+ this.stmts.deleteEdgesBySource = this.db.prepare('DELETE FROM edges WHERE source = ?');
885
+ }
886
+ this.stmts.deleteEdgesBySource.run(sourceId);
887
+ }
888
+ /**
889
+ * Get outgoing edges from a node
890
+ */
891
+ getOutgoingEdges(sourceId, kinds, provenance) {
892
+ if ((kinds && kinds.length > 0) || provenance) {
893
+ let sql = 'SELECT * FROM edges WHERE source = ?';
894
+ const params = [sourceId];
895
+ if (kinds && kinds.length > 0) {
896
+ sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
897
+ params.push(...kinds);
898
+ }
899
+ if (provenance) {
900
+ sql += ' AND provenance = ?';
901
+ params.push(provenance);
902
+ }
903
+ const rows = this.db.prepare(sql).all(...params);
904
+ return rows.map(rowToEdge);
905
+ }
906
+ if (!this.stmts.getEdgesBySource) {
907
+ this.stmts.getEdgesBySource = this.db.prepare('SELECT * FROM edges WHERE source = ?');
908
+ }
909
+ const rows = this.stmts.getEdgesBySource.all(sourceId);
910
+ return rows.map(rowToEdge);
911
+ }
912
+ /**
913
+ * Get incoming edges to a node
914
+ */
915
+ getIncomingEdges(targetId, kinds) {
916
+ if (kinds && kinds.length > 0) {
917
+ const sql = `SELECT * FROM edges WHERE target = ? AND kind IN (${kinds.map(() => '?').join(',')})`;
918
+ const rows = this.db.prepare(sql).all(targetId, ...kinds);
919
+ return rows.map(rowToEdge);
920
+ }
921
+ if (!this.stmts.getEdgesByTarget) {
922
+ this.stmts.getEdgesByTarget = this.db.prepare('SELECT * FROM edges WHERE target = ?');
923
+ }
924
+ const rows = this.stmts.getEdgesByTarget.all(targetId);
925
+ return rows.map(rowToEdge);
926
+ }
927
+ /**
928
+ * Find all edges where both source and target are in the given node set.
929
+ * Useful for recovering inter-node connectivity after BFS.
930
+ */
931
+ findEdgesBetweenNodes(nodeIds, kinds) {
932
+ if (nodeIds.length === 0)
933
+ return [];
934
+ const idsJson = JSON.stringify(nodeIds);
935
+ let sql = `SELECT * FROM edges WHERE source IN (SELECT value FROM json_each(?)) AND target IN (SELECT value FROM json_each(?))`;
936
+ const params = [idsJson, idsJson];
937
+ if (kinds && kinds.length > 0) {
938
+ sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
939
+ params.push(...kinds);
940
+ }
941
+ const rows = this.db.prepare(sql).all(...params);
942
+ return rows.map(rowToEdge);
943
+ }
944
+ // ===========================================================================
945
+ // File Operations
946
+ // ===========================================================================
947
+ /**
948
+ * Insert or update a file record
949
+ */
950
+ upsertFile(file) {
951
+ if (!this.stmts.upsertFile) {
952
+ this.stmts.upsertFile = this.db.prepare(`
953
+ INSERT INTO files (path, content_hash, language, size, modified_at, indexed_at, node_count, errors)
954
+ VALUES (@path, @contentHash, @language, @size, @modifiedAt, @indexedAt, @nodeCount, @errors)
955
+ ON CONFLICT(path) DO UPDATE SET
956
+ content_hash = @contentHash,
957
+ language = @language,
958
+ size = @size,
959
+ modified_at = @modifiedAt,
960
+ indexed_at = @indexedAt,
961
+ node_count = @nodeCount,
962
+ errors = @errors
963
+ `);
964
+ }
965
+ this.stmts.upsertFile.run({
966
+ path: file.path,
967
+ contentHash: file.contentHash,
968
+ language: file.language,
969
+ size: file.size,
970
+ modifiedAt: file.modifiedAt,
971
+ indexedAt: file.indexedAt,
972
+ nodeCount: file.nodeCount,
973
+ errors: file.errors ? JSON.stringify(file.errors) : null,
974
+ });
975
+ }
976
+ /**
977
+ * Delete a file record and its nodes
978
+ */
979
+ deleteFile(filePath) {
980
+ this.db.transaction(() => {
981
+ this.deleteNodesByFile(filePath);
982
+ if (!this.stmts.deleteFile) {
983
+ this.stmts.deleteFile = this.db.prepare('DELETE FROM files WHERE path = ?');
984
+ }
985
+ this.stmts.deleteFile.run(filePath);
986
+ })();
987
+ }
988
+ /**
989
+ * Get a file record by path
990
+ */
991
+ getFileByPath(filePath) {
992
+ if (!this.stmts.getFileByPath) {
993
+ this.stmts.getFileByPath = this.db.prepare('SELECT * FROM files WHERE path = ?');
994
+ }
995
+ const row = this.stmts.getFileByPath.get(filePath);
996
+ return row ? rowToFileRecord(row) : null;
997
+ }
998
+ /**
999
+ * Get all tracked files
1000
+ */
1001
+ getAllFiles() {
1002
+ if (!this.stmts.getAllFiles) {
1003
+ this.stmts.getAllFiles = this.db.prepare('SELECT * FROM files ORDER BY path');
1004
+ }
1005
+ const rows = this.stmts.getAllFiles.all();
1006
+ return rows.map(rowToFileRecord);
1007
+ }
1008
+ /**
1009
+ * Get files that need re-indexing (hash changed)
1010
+ */
1011
+ getStaleFiles(currentHashes) {
1012
+ const files = this.getAllFiles();
1013
+ return files.filter((f) => {
1014
+ const currentHash = currentHashes.get(f.path);
1015
+ return currentHash && currentHash !== f.contentHash;
1016
+ });
1017
+ }
1018
+ // ===========================================================================
1019
+ // Unresolved References
1020
+ // ===========================================================================
1021
+ /**
1022
+ * Insert an unresolved reference
1023
+ */
1024
+ insertUnresolvedRef(ref) {
1025
+ if (!this.stmts.insertUnresolved) {
1026
+ this.stmts.insertUnresolved = this.db.prepare(`
1027
+ INSERT INTO unresolved_refs (from_node_id, reference_name, reference_kind, line, col, candidates, file_path, language)
1028
+ VALUES (@fromNodeId, @referenceName, @referenceKind, @line, @col, @candidates, @filePath, @language)
1029
+ `);
1030
+ }
1031
+ this.stmts.insertUnresolved.run({
1032
+ fromNodeId: ref.fromNodeId,
1033
+ referenceName: ref.referenceName,
1034
+ referenceKind: ref.referenceKind,
1035
+ line: ref.line,
1036
+ col: ref.column,
1037
+ candidates: ref.candidates ? JSON.stringify(ref.candidates) : null,
1038
+ filePath: ref.filePath ?? '',
1039
+ language: ref.language ?? 'unknown',
1040
+ });
1041
+ }
1042
+ /**
1043
+ * Insert multiple unresolved references in a transaction
1044
+ */
1045
+ insertUnresolvedRefsBatch(refs) {
1046
+ if (refs.length === 0)
1047
+ return;
1048
+ const insert = this.db.transaction(() => {
1049
+ for (const ref of refs) {
1050
+ this.insertUnresolvedRef(ref);
1051
+ }
1052
+ });
1053
+ insert();
1054
+ }
1055
+ /**
1056
+ * Delete unresolved references from a node
1057
+ */
1058
+ deleteUnresolvedByNode(nodeId) {
1059
+ if (!this.stmts.deleteUnresolvedByNode) {
1060
+ this.stmts.deleteUnresolvedByNode = this.db.prepare('DELETE FROM unresolved_refs WHERE from_node_id = ?');
1061
+ }
1062
+ this.stmts.deleteUnresolvedByNode.run(nodeId);
1063
+ }
1064
+ /**
1065
+ * Get unresolved references by name (for resolution)
1066
+ */
1067
+ getUnresolvedByName(name) {
1068
+ if (!this.stmts.getUnresolvedByName) {
1069
+ this.stmts.getUnresolvedByName = this.db.prepare('SELECT * FROM unresolved_refs WHERE reference_name = ?');
1070
+ }
1071
+ const rows = this.stmts.getUnresolvedByName.all(name);
1072
+ return rows.map((row) => ({
1073
+ fromNodeId: row.from_node_id,
1074
+ referenceName: row.reference_name,
1075
+ referenceKind: row.reference_kind,
1076
+ line: row.line,
1077
+ column: row.col,
1078
+ candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
1079
+ filePath: row.file_path,
1080
+ language: row.language,
1081
+ }));
1082
+ }
1083
+ /**
1084
+ * Get all unresolved references
1085
+ */
1086
+ getUnresolvedReferences() {
1087
+ const rows = this.db.prepare('SELECT * FROM unresolved_refs').all();
1088
+ return rows.map((row) => ({
1089
+ fromNodeId: row.from_node_id,
1090
+ referenceName: row.reference_name,
1091
+ referenceKind: row.reference_kind,
1092
+ line: row.line,
1093
+ column: row.col,
1094
+ candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
1095
+ filePath: row.file_path,
1096
+ language: row.language,
1097
+ }));
1098
+ }
1099
+ /**
1100
+ * Get the count of unresolved references without loading them into memory
1101
+ */
1102
+ getUnresolvedReferencesCount() {
1103
+ if (!this.stmts.getUnresolvedCount) {
1104
+ this.stmts.getUnresolvedCount = this.db.prepare('SELECT COUNT(*) as count FROM unresolved_refs');
1105
+ }
1106
+ const row = this.stmts.getUnresolvedCount.get();
1107
+ return row.count;
1108
+ }
1109
+ /**
1110
+ * Get a batch of unresolved references using LIMIT/OFFSET pagination.
1111
+ * Used to process references in bounded memory chunks.
1112
+ */
1113
+ getUnresolvedReferencesBatch(offset, limit) {
1114
+ if (!this.stmts.getUnresolvedBatch) {
1115
+ this.stmts.getUnresolvedBatch = this.db.prepare('SELECT * FROM unresolved_refs LIMIT ? OFFSET ?');
1116
+ }
1117
+ const rows = this.stmts.getUnresolvedBatch.all(limit, offset);
1118
+ return rows.map((row) => ({
1119
+ fromNodeId: row.from_node_id,
1120
+ referenceName: row.reference_name,
1121
+ referenceKind: row.reference_kind,
1122
+ line: row.line,
1123
+ column: row.col,
1124
+ candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
1125
+ filePath: row.file_path,
1126
+ language: row.language,
1127
+ }));
1128
+ }
1129
+ /**
1130
+ * Get all tracked file paths (lightweight — no full FileRecord objects)
1131
+ */
1132
+ getAllFilePaths() {
1133
+ if (!this.stmts.getAllFilePaths) {
1134
+ this.stmts.getAllFilePaths = this.db.prepare('SELECT path FROM files ORDER BY path');
1135
+ }
1136
+ const rows = this.stmts.getAllFilePaths.all();
1137
+ return rows.map((r) => r.path);
1138
+ }
1139
+ /**
1140
+ * Get all distinct node names (lightweight — just name strings for pre-filtering)
1141
+ */
1142
+ getAllNodeNames() {
1143
+ if (!this.stmts.getAllNodeNames) {
1144
+ this.stmts.getAllNodeNames = this.db.prepare('SELECT DISTINCT name FROM nodes');
1145
+ }
1146
+ const rows = this.stmts.getAllNodeNames.all();
1147
+ return rows.map((r) => r.name);
1148
+ }
1149
+ /**
1150
+ * Get unresolved references scoped to specific file paths.
1151
+ * Uses the idx_unresolved_file_path index for efficient lookup.
1152
+ */
1153
+ getUnresolvedReferencesByFiles(filePaths) {
1154
+ if (filePaths.length === 0)
1155
+ return [];
1156
+ const placeholders = filePaths.map(() => '?').join(',');
1157
+ const rows = this.db
1158
+ .prepare(`SELECT * FROM unresolved_refs WHERE file_path IN (${placeholders})`)
1159
+ .all(...filePaths);
1160
+ return rows.map((row) => ({
1161
+ fromNodeId: row.from_node_id,
1162
+ referenceName: row.reference_name,
1163
+ referenceKind: row.reference_kind,
1164
+ line: row.line,
1165
+ column: row.col,
1166
+ candidates: row.candidates ? (0, utils_1.safeJsonParse)(row.candidates, undefined) : undefined,
1167
+ filePath: row.file_path,
1168
+ language: row.language,
1169
+ }));
1170
+ }
1171
+ /**
1172
+ * Delete all unresolved references (after resolution)
1173
+ */
1174
+ clearUnresolvedReferences() {
1175
+ this.db.exec('DELETE FROM unresolved_refs');
1176
+ }
1177
+ /**
1178
+ * Delete resolved references by their IDs
1179
+ */
1180
+ deleteResolvedReferences(fromNodeIds) {
1181
+ if (fromNodeIds.length === 0)
1182
+ return;
1183
+ const placeholders = fromNodeIds.map(() => '?').join(',');
1184
+ this.db.prepare(`DELETE FROM unresolved_refs WHERE from_node_id IN (${placeholders})`).run(...fromNodeIds);
1185
+ }
1186
+ /**
1187
+ * Delete specific resolved references by (fromNodeId, referenceName, referenceKind) tuples.
1188
+ * More precise than deleteResolvedReferences — only removes refs that were actually resolved.
1189
+ */
1190
+ deleteSpecificResolvedReferences(refs) {
1191
+ if (refs.length === 0)
1192
+ return;
1193
+ const stmt = this.db.prepare('DELETE FROM unresolved_refs WHERE from_node_id = ? AND reference_name = ? AND reference_kind = ?');
1194
+ const deleteMany = this.db.transaction((items) => {
1195
+ for (const ref of items) {
1196
+ stmt.run(ref.fromNodeId, ref.referenceName, ref.referenceKind);
1197
+ }
1198
+ });
1199
+ deleteMany(refs);
1200
+ }
1201
+ // ===========================================================================
1202
+ // Statistics
1203
+ // ===========================================================================
1204
+ /**
1205
+ * Lightweight (nodes, edges) count snapshot. Used around an index/sync
1206
+ * run to compute true additions across extraction + resolution +
1207
+ * synthesis — the per-phase counter in the orchestrator only sees
1208
+ * extraction's contribution, which is why the CLI summary under-reported
1209
+ * the edge count (resolution + synthesizer edges were invisible).
1210
+ */
1211
+ getNodeAndEdgeCount() {
1212
+ return this.db
1213
+ .prepare('SELECT (SELECT COUNT(*) FROM nodes) AS nodes, (SELECT COUNT(*) FROM edges) AS edges')
1214
+ .get();
1215
+ }
1216
+ /**
1217
+ * Get graph statistics
1218
+ */
1219
+ getStats() {
1220
+ // Single query for all three aggregate counts
1221
+ const counts = this.db.prepare(`
1222
+ SELECT
1223
+ (SELECT COUNT(*) FROM nodes) AS node_count,
1224
+ (SELECT COUNT(*) FROM edges) AS edge_count,
1225
+ (SELECT COUNT(*) FROM files) AS file_count
1226
+ `).get();
1227
+ const nodesByKind = {};
1228
+ const nodeKindRows = this.db
1229
+ .prepare('SELECT kind, COUNT(*) as count FROM nodes GROUP BY kind')
1230
+ .all();
1231
+ for (const row of nodeKindRows) {
1232
+ nodesByKind[row.kind] = row.count;
1233
+ }
1234
+ const edgesByKind = {};
1235
+ const edgeKindRows = this.db
1236
+ .prepare('SELECT kind, COUNT(*) as count FROM edges GROUP BY kind')
1237
+ .all();
1238
+ for (const row of edgeKindRows) {
1239
+ edgesByKind[row.kind] = row.count;
1240
+ }
1241
+ const filesByLanguage = {};
1242
+ const languageRows = this.db
1243
+ .prepare('SELECT language, COUNT(*) as count FROM files GROUP BY language')
1244
+ .all();
1245
+ for (const row of languageRows) {
1246
+ filesByLanguage[row.language] = row.count;
1247
+ }
1248
+ return {
1249
+ nodeCount: counts.node_count,
1250
+ edgeCount: counts.edge_count,
1251
+ fileCount: counts.file_count,
1252
+ nodesByKind,
1253
+ edgesByKind,
1254
+ filesByLanguage,
1255
+ dbSizeBytes: 0, // Set by caller using DatabaseConnection.getSize()
1256
+ lastUpdated: Date.now(),
1257
+ };
1258
+ }
1259
+ // ===========================================================================
1260
+ // Project Metadata
1261
+ // ===========================================================================
1262
+ /**
1263
+ * Get a metadata value by key
1264
+ */
1265
+ getMetadata(key) {
1266
+ const row = this.db.prepare('SELECT value FROM project_metadata WHERE key = ?').get(key);
1267
+ return row?.value ?? null;
1268
+ }
1269
+ /**
1270
+ * Set a metadata key-value pair (upsert)
1271
+ */
1272
+ setMetadata(key, value) {
1273
+ 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());
1274
+ }
1275
+ /**
1276
+ * Get all metadata as a key-value record
1277
+ */
1278
+ getAllMetadata() {
1279
+ const rows = this.db.prepare('SELECT key, value FROM project_metadata').all();
1280
+ const result = {};
1281
+ for (const row of rows) {
1282
+ result[row.key] = row.value;
1283
+ }
1284
+ return result;
1285
+ }
1286
+ /**
1287
+ * Clear all data from the database
1288
+ */
1289
+ clear() {
1290
+ this.nodeCache.clear();
1291
+ this.db.transaction(() => {
1292
+ this.db.exec('DELETE FROM unresolved_refs');
1293
+ this.db.exec('DELETE FROM edges');
1294
+ this.db.exec('DELETE FROM nodes');
1295
+ this.db.exec('DELETE FROM files');
1296
+ })();
1297
+ }
1298
+ }
1299
+ exports.QueryBuilder = QueryBuilder;
1300
+ //# sourceMappingURL=queries.js.map