@selvakumaresra/specship 0.1.2 → 0.1.3

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