@jafreck/lore 0.3.5 → 0.3.7

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 (401) hide show
  1. package/README.md +51 -58
  2. package/dist/cli.js +76 -22
  3. package/dist/cli.js.map +1 -1
  4. package/dist/{lore-server/db.d.ts → db/read-only.d.ts} +1 -1
  5. package/dist/db/read-only.d.ts.map +1 -0
  6. package/dist/{lore-server/db.js → db/read-only.js} +1 -1
  7. package/dist/db/read-only.js.map +1 -0
  8. package/dist/{indexer/db.d.ts → db/schema.d.ts} +1 -1
  9. package/dist/db/schema.d.ts.map +1 -0
  10. package/dist/{indexer/db.js → db/schema.js} +10 -3
  11. package/dist/db/schema.js.map +1 -0
  12. package/dist/{indexer → discovery}/poller.d.ts +27 -2
  13. package/dist/discovery/poller.d.ts.map +1 -0
  14. package/dist/{indexer → discovery}/poller.js +60 -1
  15. package/dist/discovery/poller.js.map +1 -0
  16. package/dist/{indexer → discovery}/walker.d.ts +1 -1
  17. package/dist/discovery/walker.d.ts.map +1 -0
  18. package/dist/{indexer → discovery}/walker.js +1 -1
  19. package/dist/discovery/walker.js.map +1 -0
  20. package/dist/{indexer → discovery}/watcher.d.ts +27 -2
  21. package/dist/discovery/watcher.d.ts.map +1 -0
  22. package/dist/{indexer → discovery}/watcher.js +62 -1
  23. package/dist/discovery/watcher.js.map +1 -0
  24. package/dist/docs/docs.d.ts.map +1 -0
  25. package/dist/docs/docs.js.map +1 -0
  26. package/dist/{indexer → embeddings}/embedder.d.ts +12 -8
  27. package/dist/embeddings/embedder.d.ts.map +1 -0
  28. package/dist/{indexer → embeddings}/embedder.js +35 -19
  29. package/dist/embeddings/embedder.js.map +1 -0
  30. package/dist/{indexer/git-history.d.ts → git/history.d.ts} +2 -2
  31. package/dist/git/history.d.ts.map +1 -0
  32. package/dist/{indexer/git-history.js → git/history.js} +2 -2
  33. package/dist/git/history.js.map +1 -0
  34. package/dist/{indexer/git-hooks.d.ts → git/hooks.d.ts} +2 -1
  35. package/dist/git/hooks.d.ts.map +1 -0
  36. package/dist/{indexer/git-hooks.js → git/hooks.js} +5 -4
  37. package/dist/git/hooks.js.map +1 -0
  38. package/dist/index.d.ts +29 -28
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +14 -14
  41. package/dist/index.js.map +1 -1
  42. package/dist/indexer/index.d.ts +9 -6
  43. package/dist/indexer/index.d.ts.map +1 -1
  44. package/dist/indexer/index.js +58 -17
  45. package/dist/indexer/index.js.map +1 -1
  46. package/dist/indexer/pipeline.d.ts +58 -20
  47. package/dist/indexer/pipeline.d.ts.map +1 -1
  48. package/dist/indexer/pipeline.js +53 -26
  49. package/dist/indexer/pipeline.js.map +1 -1
  50. package/dist/indexer/stages/dependency-api.js +4 -4
  51. package/dist/indexer/stages/dependency-api.js.map +1 -1
  52. package/dist/indexer/stages/docs-index.d.ts +2 -2
  53. package/dist/indexer/stages/docs-index.d.ts.map +1 -1
  54. package/dist/indexer/stages/docs-index.js +2 -2
  55. package/dist/indexer/stages/docs-index.js.map +1 -1
  56. package/dist/indexer/stages/embedding.js +2 -2
  57. package/dist/indexer/stages/embedding.js.map +1 -1
  58. package/dist/indexer/stages/import-resolution.js +1 -1
  59. package/dist/indexer/stages/import-resolution.js.map +1 -1
  60. package/dist/indexer/stages/index.d.ts +2 -0
  61. package/dist/indexer/stages/index.d.ts.map +1 -1
  62. package/dist/indexer/stages/index.js +2 -0
  63. package/dist/indexer/stages/index.js.map +1 -1
  64. package/dist/indexer/stages/lsp-enrichment.d.ts +3 -3
  65. package/dist/indexer/stages/lsp-enrichment.d.ts.map +1 -1
  66. package/dist/indexer/stages/lsp-enrichment.js +147 -18
  67. package/dist/indexer/stages/lsp-enrichment.js.map +1 -1
  68. package/dist/indexer/stages/scip-enrichment.d.ts +43 -0
  69. package/dist/indexer/stages/scip-enrichment.d.ts.map +1 -0
  70. package/dist/indexer/stages/scip-enrichment.js +172 -0
  71. package/dist/indexer/stages/scip-enrichment.js.map +1 -0
  72. package/dist/indexer/stages/scip-source.d.ts +117 -0
  73. package/dist/indexer/stages/scip-source.d.ts.map +1 -0
  74. package/dist/indexer/stages/scip-source.js +924 -0
  75. package/dist/indexer/stages/scip-source.js.map +1 -0
  76. package/dist/indexer/stages/source-index.d.ts +3 -3
  77. package/dist/indexer/stages/source-index.d.ts.map +1 -1
  78. package/dist/indexer/stages/source-index.js +126 -46
  79. package/dist/indexer/stages/source-index.js.map +1 -1
  80. package/dist/lsp/client.d.ts.map +1 -0
  81. package/dist/{indexer/lsp → lsp}/client.js +1 -1
  82. package/dist/lsp/client.js.map +1 -0
  83. package/dist/lsp/config.d.ts.map +1 -0
  84. package/dist/{indexer/lsp → lsp}/config.js +1 -1
  85. package/dist/lsp/config.js.map +1 -0
  86. package/dist/lsp/enrichment.d.ts.map +1 -0
  87. package/dist/lsp/enrichment.js.map +1 -0
  88. package/dist/lsp/registry.d.ts.map +1 -0
  89. package/dist/{indexer/lsp → lsp}/registry.js +1 -1
  90. package/dist/lsp/registry.js.map +1 -0
  91. package/dist/{indexer → parsing}/complexity.d.ts.map +1 -1
  92. package/dist/{indexer → parsing}/complexity.js.map +1 -1
  93. package/dist/{indexer → parsing}/config-parser.d.ts.map +1 -1
  94. package/dist/{indexer → parsing}/config-parser.js.map +1 -1
  95. package/dist/{indexer → parsing}/extractors/bash.d.ts.map +1 -1
  96. package/dist/{indexer → parsing}/extractors/bash.js.map +1 -1
  97. package/dist/{indexer → parsing}/extractors/c.d.ts.map +1 -1
  98. package/dist/{indexer → parsing}/extractors/c.js +4 -4
  99. package/dist/parsing/extractors/c.js.map +1 -0
  100. package/dist/{indexer → parsing}/extractors/cpp.d.ts.map +1 -1
  101. package/dist/{indexer → parsing}/extractors/cpp.js +6 -12
  102. package/dist/parsing/extractors/cpp.js.map +1 -0
  103. package/dist/{indexer → parsing}/extractors/csharp.d.ts.map +1 -1
  104. package/dist/{indexer → parsing}/extractors/csharp.js +1 -6
  105. package/dist/{indexer → parsing}/extractors/csharp.js.map +1 -1
  106. package/dist/{indexer → parsing}/extractors/elixir.d.ts.map +1 -1
  107. package/dist/{indexer → parsing}/extractors/elixir.js +10 -15
  108. package/dist/parsing/extractors/elixir.js.map +1 -0
  109. package/dist/{indexer → parsing}/extractors/elm.d.ts.map +1 -1
  110. package/dist/{indexer → parsing}/extractors/elm.js.map +1 -1
  111. package/dist/{indexer → parsing}/extractors/go.d.ts.map +1 -1
  112. package/dist/{indexer → parsing}/extractors/go.js +0 -1
  113. package/dist/parsing/extractors/go.js.map +1 -0
  114. package/dist/{indexer → parsing}/extractors/haskell.d.ts.map +1 -1
  115. package/dist/{indexer → parsing}/extractors/haskell.js +2 -4
  116. package/dist/parsing/extractors/haskell.js.map +1 -0
  117. package/dist/{indexer → parsing}/extractors/java.d.ts.map +1 -1
  118. package/dist/{indexer → parsing}/extractors/java.js.map +1 -1
  119. package/dist/{indexer → parsing}/extractors/javascript.d.ts.map +1 -1
  120. package/dist/{indexer → parsing}/extractors/javascript.js +23 -3
  121. package/dist/parsing/extractors/javascript.js.map +1 -0
  122. package/dist/{indexer → parsing}/extractors/julia.d.ts.map +1 -1
  123. package/dist/{indexer → parsing}/extractors/julia.js.map +1 -1
  124. package/dist/{indexer → parsing}/extractors/kotlin.d.ts.map +1 -1
  125. package/dist/{indexer → parsing}/extractors/kotlin.js +4 -3
  126. package/dist/{indexer → parsing}/extractors/kotlin.js.map +1 -1
  127. package/dist/{indexer → parsing}/extractors/lua.d.ts.map +1 -1
  128. package/dist/{indexer → parsing}/extractors/lua.js +1 -13
  129. package/dist/parsing/extractors/lua.js.map +1 -0
  130. package/dist/{indexer → parsing}/extractors/objc.d.ts.map +1 -1
  131. package/dist/{indexer → parsing}/extractors/objc.js +4 -6
  132. package/dist/parsing/extractors/objc.js.map +1 -0
  133. package/dist/{indexer → parsing}/extractors/ocaml.d.ts.map +1 -1
  134. package/dist/{indexer → parsing}/extractors/ocaml.js +2 -10
  135. package/dist/parsing/extractors/ocaml.js.map +1 -0
  136. package/dist/{indexer → parsing}/extractors/php.d.ts.map +1 -1
  137. package/dist/{indexer → parsing}/extractors/php.js.map +1 -1
  138. package/dist/{indexer → parsing}/extractors/python.d.ts.map +1 -1
  139. package/dist/{indexer → parsing}/extractors/python.js.map +1 -1
  140. package/dist/{indexer → parsing}/extractors/ruby.d.ts.map +1 -1
  141. package/dist/{indexer → parsing}/extractors/ruby.js.map +1 -1
  142. package/dist/{indexer → parsing}/extractors/rust.d.ts.map +1 -1
  143. package/dist/{indexer → parsing}/extractors/rust.js +1 -1
  144. package/dist/{indexer → parsing}/extractors/rust.js.map +1 -1
  145. package/dist/{indexer → parsing}/extractors/scala.d.ts.map +1 -1
  146. package/dist/{indexer → parsing}/extractors/scala.js.map +1 -1
  147. package/dist/{indexer → parsing}/extractors/swift.d.ts.map +1 -1
  148. package/dist/{indexer → parsing}/extractors/swift.js.map +1 -1
  149. package/dist/{indexer → parsing}/extractors/types.d.ts.map +1 -1
  150. package/dist/{indexer → parsing}/extractors/types.js.map +1 -1
  151. package/dist/{indexer → parsing}/extractors/typescript.d.ts.map +1 -1
  152. package/dist/{indexer → parsing}/extractors/typescript.js +61 -19
  153. package/dist/parsing/extractors/typescript.js.map +1 -0
  154. package/dist/{indexer → parsing}/extractors/zig.d.ts.map +1 -1
  155. package/dist/{indexer → parsing}/extractors/zig.js +0 -4
  156. package/dist/parsing/extractors/zig.js.map +1 -0
  157. package/dist/{indexer → parsing}/parser.d.ts.map +1 -1
  158. package/dist/{indexer → parsing}/parser.js.map +1 -1
  159. package/dist/{indexer → resolution}/call-graph.d.ts +15 -1
  160. package/dist/resolution/call-graph.d.ts.map +1 -0
  161. package/dist/{indexer → resolution}/call-graph.js +34 -0
  162. package/dist/resolution/call-graph.js.map +1 -0
  163. package/dist/{indexer → resolution}/graph-analysis.d.ts +1 -1
  164. package/dist/resolution/graph-analysis.d.ts.map +1 -0
  165. package/dist/resolution/graph-analysis.js.map +1 -0
  166. package/dist/{indexer → resolution}/resolution-method.d.ts +3 -1
  167. package/dist/resolution/resolution-method.d.ts.map +1 -0
  168. package/dist/{indexer → resolution}/resolution-method.js +4 -0
  169. package/dist/resolution/resolution-method.js.map +1 -0
  170. package/dist/{indexer → resolution}/resolver.d.ts +7 -1
  171. package/dist/resolution/resolver.d.ts.map +1 -0
  172. package/dist/{indexer → resolution}/resolver.js +21 -0
  173. package/dist/resolution/resolver.js.map +1 -0
  174. package/dist/runtime.d.ts +6 -3
  175. package/dist/runtime.d.ts.map +1 -1
  176. package/dist/runtime.js +5 -3
  177. package/dist/runtime.js.map +1 -1
  178. package/dist/scip/config.d.ts +32 -0
  179. package/dist/scip/config.d.ts.map +1 -0
  180. package/dist/scip/config.js +96 -0
  181. package/dist/scip/config.js.map +1 -0
  182. package/dist/scip/enrichment.d.ts +56 -0
  183. package/dist/scip/enrichment.d.ts.map +1 -0
  184. package/dist/scip/enrichment.js +258 -0
  185. package/dist/scip/enrichment.js.map +1 -0
  186. package/dist/scip/index-reader.d.ts +100 -0
  187. package/dist/scip/index-reader.d.ts.map +1 -0
  188. package/dist/scip/index-reader.js +225 -0
  189. package/dist/scip/index-reader.js.map +1 -0
  190. package/dist/scip/registry.d.ts +51 -0
  191. package/dist/scip/registry.d.ts.map +1 -0
  192. package/dist/scip/registry.js +131 -0
  193. package/dist/scip/registry.js.map +1 -0
  194. package/dist/scip/scip_pb.d.ts +2118 -0
  195. package/dist/scip/scip_pb.d.ts.map +1 -0
  196. package/dist/scip/scip_pb.js +1534 -0
  197. package/dist/scip/scip_pb.js.map +1 -0
  198. package/dist/{lore-server → server}/server.d.ts +3 -4
  199. package/dist/server/server.d.ts.map +1 -0
  200. package/dist/{lore-server → server}/server.js +4 -13
  201. package/dist/server/server.js.map +1 -0
  202. package/dist/{lore-server → server}/tool-registry.d.ts +2 -2
  203. package/dist/server/tool-registry.d.ts.map +1 -0
  204. package/dist/{lore-server → server}/tool-registry.js +1 -26
  205. package/dist/server/tool-registry.js.map +1 -0
  206. package/dist/{lore-server → server}/tools/blame.d.ts +1 -1
  207. package/dist/server/tools/blame.d.ts.map +1 -0
  208. package/dist/{lore-server → server}/tools/blame.js +1 -1
  209. package/dist/server/tools/blame.js.map +1 -0
  210. package/dist/{lore-server → server}/tools/docs.d.ts +3 -3
  211. package/dist/server/tools/docs.d.ts.map +1 -0
  212. package/dist/{lore-server → server}/tools/docs.js +1 -1
  213. package/dist/server/tools/docs.js.map +1 -0
  214. package/dist/{lore-server → server}/tools/graph.d.ts +32 -6
  215. package/dist/server/tools/graph.d.ts.map +1 -0
  216. package/dist/{lore-server → server}/tools/graph.js +115 -90
  217. package/dist/server/tools/graph.js.map +1 -0
  218. package/dist/{lore-server → server}/tools/history.d.ts +3 -3
  219. package/dist/server/tools/history.d.ts.map +1 -0
  220. package/dist/{lore-server → server}/tools/history.js +1 -1
  221. package/dist/server/tools/history.js.map +1 -0
  222. package/dist/{lore-server → server}/tools/lookup.d.ts +2 -2
  223. package/dist/server/tools/lookup.d.ts.map +1 -0
  224. package/dist/{lore-server → server}/tools/lookup.js +1 -1
  225. package/dist/server/tools/lookup.js.map +1 -0
  226. package/dist/server/tools/metrics.d.ts +48 -0
  227. package/dist/server/tools/metrics.d.ts.map +1 -0
  228. package/dist/server/tools/metrics.js +44 -0
  229. package/dist/server/tools/metrics.js.map +1 -0
  230. package/dist/{lore-server → server}/tools/notes.d.ts +1 -1
  231. package/dist/server/tools/notes.d.ts.map +1 -0
  232. package/dist/server/tools/notes.js.map +1 -0
  233. package/dist/{lore-server → server}/tools/routes.d.ts +2 -2
  234. package/dist/server/tools/routes.d.ts.map +1 -0
  235. package/dist/{lore-server → server}/tools/routes.js +1 -1
  236. package/dist/server/tools/routes.js.map +1 -0
  237. package/dist/{lore-server → server}/tools/search.d.ts +2 -2
  238. package/dist/server/tools/search.d.ts.map +1 -0
  239. package/dist/{lore-server → server}/tools/search.js +1 -1
  240. package/dist/server/tools/search.js.map +1 -0
  241. package/dist/{lore-server → server}/tools/snippet.d.ts +1 -1
  242. package/dist/server/tools/snippet.d.ts.map +1 -0
  243. package/dist/{lore-server → server}/tools/snippet.js +1 -1
  244. package/dist/server/tools/snippet.js.map +1 -0
  245. package/dist/{lore-server → server}/tools/test-map.d.ts +1 -1
  246. package/dist/server/tools/test-map.d.ts.map +1 -0
  247. package/dist/{lore-server → server}/tools/test-map.js +1 -1
  248. package/dist/server/tools/test-map.js.map +1 -0
  249. package/dist/{indexer → testing}/coverage.d.ts +1 -1
  250. package/dist/testing/coverage.d.ts.map +1 -0
  251. package/dist/{indexer → testing}/coverage.js.map +1 -1
  252. package/dist/{indexer → testing}/test-mapper.d.ts +1 -1
  253. package/dist/testing/test-mapper.d.ts.map +1 -0
  254. package/dist/{indexer → testing}/test-mapper.js.map +1 -1
  255. package/package.json +12 -9
  256. package/dist/indexer/call-graph.d.ts.map +0 -1
  257. package/dist/indexer/call-graph.js.map +0 -1
  258. package/dist/indexer/coverage.d.ts.map +0 -1
  259. package/dist/indexer/db.d.ts.map +0 -1
  260. package/dist/indexer/db.js.map +0 -1
  261. package/dist/indexer/docs.d.ts.map +0 -1
  262. package/dist/indexer/docs.js.map +0 -1
  263. package/dist/indexer/embedder.d.ts.map +0 -1
  264. package/dist/indexer/embedder.js.map +0 -1
  265. package/dist/indexer/extractors/c.js.map +0 -1
  266. package/dist/indexer/extractors/cpp.js.map +0 -1
  267. package/dist/indexer/extractors/elixir.js.map +0 -1
  268. package/dist/indexer/extractors/go.js.map +0 -1
  269. package/dist/indexer/extractors/haskell.js.map +0 -1
  270. package/dist/indexer/extractors/javascript.js.map +0 -1
  271. package/dist/indexer/extractors/lua.js.map +0 -1
  272. package/dist/indexer/extractors/objc.js.map +0 -1
  273. package/dist/indexer/extractors/ocaml.js.map +0 -1
  274. package/dist/indexer/extractors/typescript.js.map +0 -1
  275. package/dist/indexer/extractors/zig.js.map +0 -1
  276. package/dist/indexer/git-history.d.ts.map +0 -1
  277. package/dist/indexer/git-history.js.map +0 -1
  278. package/dist/indexer/git-hooks.d.ts.map +0 -1
  279. package/dist/indexer/git-hooks.js.map +0 -1
  280. package/dist/indexer/graph-analysis.d.ts.map +0 -1
  281. package/dist/indexer/graph-analysis.js.map +0 -1
  282. package/dist/indexer/lsp/client.d.ts.map +0 -1
  283. package/dist/indexer/lsp/client.js.map +0 -1
  284. package/dist/indexer/lsp/config.d.ts.map +0 -1
  285. package/dist/indexer/lsp/config.js.map +0 -1
  286. package/dist/indexer/lsp/enrichment.d.ts.map +0 -1
  287. package/dist/indexer/lsp/enrichment.js.map +0 -1
  288. package/dist/indexer/lsp/registry.d.ts.map +0 -1
  289. package/dist/indexer/lsp/registry.js.map +0 -1
  290. package/dist/indexer/poller.d.ts.map +0 -1
  291. package/dist/indexer/poller.js.map +0 -1
  292. package/dist/indexer/resolution-method.d.ts.map +0 -1
  293. package/dist/indexer/resolution-method.js.map +0 -1
  294. package/dist/indexer/resolver.d.ts.map +0 -1
  295. package/dist/indexer/resolver.js.map +0 -1
  296. package/dist/indexer/test-mapper.d.ts.map +0 -1
  297. package/dist/indexer/walker.d.ts.map +0 -1
  298. package/dist/indexer/walker.js.map +0 -1
  299. package/dist/indexer/watcher.d.ts.map +0 -1
  300. package/dist/indexer/watcher.js.map +0 -1
  301. package/dist/lore-server/db.d.ts.map +0 -1
  302. package/dist/lore-server/db.js.map +0 -1
  303. package/dist/lore-server/server.d.ts.map +0 -1
  304. package/dist/lore-server/server.js.map +0 -1
  305. package/dist/lore-server/tool-registry.d.ts.map +0 -1
  306. package/dist/lore-server/tool-registry.js.map +0 -1
  307. package/dist/lore-server/tools/annotations.d.ts +0 -40
  308. package/dist/lore-server/tools/annotations.d.ts.map +0 -1
  309. package/dist/lore-server/tools/annotations.js +0 -35
  310. package/dist/lore-server/tools/annotations.js.map +0 -1
  311. package/dist/lore-server/tools/architecture.d.ts +0 -67
  312. package/dist/lore-server/tools/architecture.d.ts.map +0 -1
  313. package/dist/lore-server/tools/architecture.js +0 -209
  314. package/dist/lore-server/tools/architecture.js.map +0 -1
  315. package/dist/lore-server/tools/blame.d.ts.map +0 -1
  316. package/dist/lore-server/tools/blame.js.map +0 -1
  317. package/dist/lore-server/tools/coverage.d.ts +0 -67
  318. package/dist/lore-server/tools/coverage.d.ts.map +0 -1
  319. package/dist/lore-server/tools/coverage.js +0 -74
  320. package/dist/lore-server/tools/coverage.js.map +0 -1
  321. package/dist/lore-server/tools/docs.d.ts.map +0 -1
  322. package/dist/lore-server/tools/docs.js.map +0 -1
  323. package/dist/lore-server/tools/graph-analysis.d.ts +0 -64
  324. package/dist/lore-server/tools/graph-analysis.d.ts.map +0 -1
  325. package/dist/lore-server/tools/graph-analysis.js +0 -82
  326. package/dist/lore-server/tools/graph-analysis.js.map +0 -1
  327. package/dist/lore-server/tools/graph.d.ts.map +0 -1
  328. package/dist/lore-server/tools/graph.js.map +0 -1
  329. package/dist/lore-server/tools/history.d.ts.map +0 -1
  330. package/dist/lore-server/tools/history.js.map +0 -1
  331. package/dist/lore-server/tools/lookup.d.ts.map +0 -1
  332. package/dist/lore-server/tools/lookup.js.map +0 -1
  333. package/dist/lore-server/tools/metrics.d.ts +0 -73
  334. package/dist/lore-server/tools/metrics.d.ts.map +0 -1
  335. package/dist/lore-server/tools/metrics.js +0 -79
  336. package/dist/lore-server/tools/metrics.js.map +0 -1
  337. package/dist/lore-server/tools/notes.d.ts.map +0 -1
  338. package/dist/lore-server/tools/notes.js.map +0 -1
  339. package/dist/lore-server/tools/routes.d.ts.map +0 -1
  340. package/dist/lore-server/tools/routes.js.map +0 -1
  341. package/dist/lore-server/tools/search.d.ts.map +0 -1
  342. package/dist/lore-server/tools/search.js.map +0 -1
  343. package/dist/lore-server/tools/snippet.d.ts.map +0 -1
  344. package/dist/lore-server/tools/snippet.js.map +0 -1
  345. package/dist/lore-server/tools/test-map.d.ts.map +0 -1
  346. package/dist/lore-server/tools/test-map.js.map +0 -1
  347. package/dist/lore-server/tools/writeback.d.ts +0 -49
  348. package/dist/lore-server/tools/writeback.d.ts.map +0 -1
  349. package/dist/lore-server/tools/writeback.js +0 -68
  350. package/dist/lore-server/tools/writeback.js.map +0 -1
  351. /package/dist/{indexer → docs}/docs.d.ts +0 -0
  352. /package/dist/{indexer → docs}/docs.js +0 -0
  353. /package/dist/{indexer/lsp → lsp}/client.d.ts +0 -0
  354. /package/dist/{indexer/lsp → lsp}/config.d.ts +0 -0
  355. /package/dist/{indexer/lsp → lsp}/enrichment.d.ts +0 -0
  356. /package/dist/{indexer/lsp → lsp}/enrichment.js +0 -0
  357. /package/dist/{indexer/lsp → lsp}/registry.d.ts +0 -0
  358. /package/dist/{indexer → parsing}/complexity.d.ts +0 -0
  359. /package/dist/{indexer → parsing}/complexity.js +0 -0
  360. /package/dist/{indexer → parsing}/config-parser.d.ts +0 -0
  361. /package/dist/{indexer → parsing}/config-parser.js +0 -0
  362. /package/dist/{indexer → parsing}/extractors/bash.d.ts +0 -0
  363. /package/dist/{indexer → parsing}/extractors/bash.js +0 -0
  364. /package/dist/{indexer → parsing}/extractors/c.d.ts +0 -0
  365. /package/dist/{indexer → parsing}/extractors/cpp.d.ts +0 -0
  366. /package/dist/{indexer → parsing}/extractors/csharp.d.ts +0 -0
  367. /package/dist/{indexer → parsing}/extractors/elixir.d.ts +0 -0
  368. /package/dist/{indexer → parsing}/extractors/elm.d.ts +0 -0
  369. /package/dist/{indexer → parsing}/extractors/elm.js +0 -0
  370. /package/dist/{indexer → parsing}/extractors/go.d.ts +0 -0
  371. /package/dist/{indexer → parsing}/extractors/haskell.d.ts +0 -0
  372. /package/dist/{indexer → parsing}/extractors/java.d.ts +0 -0
  373. /package/dist/{indexer → parsing}/extractors/java.js +0 -0
  374. /package/dist/{indexer → parsing}/extractors/javascript.d.ts +0 -0
  375. /package/dist/{indexer → parsing}/extractors/julia.d.ts +0 -0
  376. /package/dist/{indexer → parsing}/extractors/julia.js +0 -0
  377. /package/dist/{indexer → parsing}/extractors/kotlin.d.ts +0 -0
  378. /package/dist/{indexer → parsing}/extractors/lua.d.ts +0 -0
  379. /package/dist/{indexer → parsing}/extractors/objc.d.ts +0 -0
  380. /package/dist/{indexer → parsing}/extractors/ocaml.d.ts +0 -0
  381. /package/dist/{indexer → parsing}/extractors/php.d.ts +0 -0
  382. /package/dist/{indexer → parsing}/extractors/php.js +0 -0
  383. /package/dist/{indexer → parsing}/extractors/python.d.ts +0 -0
  384. /package/dist/{indexer → parsing}/extractors/python.js +0 -0
  385. /package/dist/{indexer → parsing}/extractors/ruby.d.ts +0 -0
  386. /package/dist/{indexer → parsing}/extractors/ruby.js +0 -0
  387. /package/dist/{indexer → parsing}/extractors/rust.d.ts +0 -0
  388. /package/dist/{indexer → parsing}/extractors/scala.d.ts +0 -0
  389. /package/dist/{indexer → parsing}/extractors/scala.js +0 -0
  390. /package/dist/{indexer → parsing}/extractors/swift.d.ts +0 -0
  391. /package/dist/{indexer → parsing}/extractors/swift.js +0 -0
  392. /package/dist/{indexer → parsing}/extractors/types.d.ts +0 -0
  393. /package/dist/{indexer → parsing}/extractors/types.js +0 -0
  394. /package/dist/{indexer → parsing}/extractors/typescript.d.ts +0 -0
  395. /package/dist/{indexer → parsing}/extractors/zig.d.ts +0 -0
  396. /package/dist/{indexer → parsing}/parser.d.ts +0 -0
  397. /package/dist/{indexer → parsing}/parser.js +0 -0
  398. /package/dist/{indexer → resolution}/graph-analysis.js +0 -0
  399. /package/dist/{lore-server → server}/tools/notes.js +0 -0
  400. /package/dist/{indexer → testing}/coverage.js +0 -0
  401. /package/dist/{indexer → testing}/test-mapper.js +0 -0
@@ -0,0 +1,924 @@
1
+ /**
2
+ * @module indexer/stages/scip-source
3
+ *
4
+ * Pipeline stage: for SCIP-covered languages, populate `files`, `symbols`,
5
+ * `symbol_refs`, `type_refs`, `symbol_relationships`, and `file_imports`
6
+ * **directly from the SCIP index** — bypassing tree-sitter entirely.
7
+ *
8
+ * This is the SCIP-primary architecture. SCIP is the source of truth for
9
+ * both the symbol table and the call graph. For each SCIP document:
10
+ *
11
+ * 1. **Symbols**: Definition occurrences → `symbols` rows; kinds inferred
12
+ * from SCIP descriptor suffixes; spans from `enclosing_range`.
13
+ * 2. **Refs**: Non-definition, non-local reference occurrences →
14
+ * `symbol_refs` rows with both `caller_id` and `callee_id` resolved
15
+ * using containment (which symbol's span encloses this ref?) and
16
+ * definition lookup (where is the referenced SCIP symbol defined?).
17
+ *
18
+ * SCIP refs are inserted **pre-resolved** with `resolution_method =
19
+ * 'scip_definition'`. The downstream resolution stage only processes
20
+ * refs from non-SCIP languages.
21
+ *
22
+ * ## Data written
23
+ *
24
+ * Same tables as `SourceIndexStage`: `files`, `symbols`, `symbols_fts`,
25
+ * `symbol_refs`, `type_refs`, `symbol_relationships`, `file_imports`.
26
+ *
27
+ * ## Pipeline ordering
28
+ *
29
+ * This stage runs **before** `SourceIndexStage`. It stores which
30
+ * languages and files it handled in `context.scipSourcedLanguages` and
31
+ * `context.scipSourcedFiles` so the tree-sitter path can skip them.
32
+ */
33
+ import * as fs from 'node:fs';
34
+ import * as crypto from 'node:crypto';
35
+ import { resolve } from 'node:path';
36
+ import { fromBinary } from '@bufbuild/protobuf';
37
+ import { IndexSchema, SymbolRole, } from '../../scip/scip_pb.js';
38
+ import { normalizeTypeName } from '../../resolution/call-graph.js';
39
+ import { SCIP_SUPPORTED_LANGUAGES, resolveScipIndexerRegistry } from '../../scip/registry.js';
40
+ import { readFileSync, existsSync } from 'node:fs';
41
+ import { join } from 'node:path';
42
+ import { execFile } from 'node:child_process';
43
+ import { promisify } from 'node:util';
44
+ // ─── SCIP symbol string → Lore kind mapping ──────────────────────────────────
45
+ /**
46
+ * Infer a Lore symbol `kind` from a SCIP symbol string.
47
+ *
48
+ * SCIP symbol syntax: `<scheme> <package> (<descriptor>)+`
49
+ * Descriptor suffixes:
50
+ * - `/` → Namespace (module/package)
51
+ * - `#` → Type (class, interface, enum)
52
+ * - `.` → Term (variable, constant, property, enum member)
53
+ * - `().` → Method/Function
54
+ * - `(name)` → Parameter
55
+ * - `[name]` → Type parameter
56
+ * - `name:` → Meta (object property)
57
+ */
58
+ function inferKindFromScipSymbol(scipSymbol, docHint) {
59
+ // Method/function: ends with ().<any> or just ().
60
+ if (/\(\+?\d*\)\.$/.test(scipSymbol)) {
61
+ // Use doc hint to distinguish constructor
62
+ if (docHint.includes('constructor'))
63
+ return 'constructor';
64
+ // Check if inside a type — method vs function
65
+ const parts = scipSymbol.split(/(?<=[#/.])/);
66
+ const hasType = parts.some(p => p.endsWith('#'));
67
+ return hasType ? 'method' : 'function';
68
+ }
69
+ // Type: ends with #
70
+ if (scipSymbol.endsWith('#')) {
71
+ if (docHint.includes('interface '))
72
+ return 'interface';
73
+ if (docHint.includes('trait '))
74
+ return 'interface';
75
+ if (docHint.includes('enum '))
76
+ return 'enum';
77
+ if (docHint.includes('type '))
78
+ return 'type_alias';
79
+ return 'class';
80
+ }
81
+ // Namespace: ends with /
82
+ if (scipSymbol.endsWith('/'))
83
+ return 'module';
84
+ // Term: ends with .
85
+ if (scipSymbol.endsWith('.')) {
86
+ if (docHint.includes('(enum member)'))
87
+ return 'enum_member';
88
+ if (docHint.includes('const '))
89
+ return 'constant';
90
+ if (docHint.includes('(property)'))
91
+ return 'property';
92
+ return 'variable';
93
+ }
94
+ // Meta: ends with :
95
+ if (scipSymbol.endsWith(':'))
96
+ return 'property';
97
+ // Parameter
98
+ if (scipSymbol.endsWith(')') && !scipSymbol.endsWith(').'))
99
+ return 'parameter';
100
+ return 'variable';
101
+ }
102
+ /**
103
+ * Extract a human-readable name from a SCIP symbol string.
104
+ *
105
+ * E.g. `scip-typescript npm pkg 1.0 src/\`file.ts\`/MyClass#myMethod().`
106
+ * → `myMethod`
107
+ */
108
+ function extractNameFromScipSymbol(scipSymbol) {
109
+ // Strip trailing descriptor suffix (., #, /, :, etc.)
110
+ let cleaned = scipSymbol.replace(/[.#/:]$/, '');
111
+ // For methods, strip the disambiguator: `name(+1).` → `name`
112
+ cleaned = cleaned.replace(/\(\+?\d*\)$/, '');
113
+ // Get the last descriptor's name
114
+ // Descriptors are separated by ., #, /, :, or ()
115
+ const parts = cleaned.split(/[.#/:]/);
116
+ let name = parts[parts.length - 1] || '';
117
+ // Remove backtick escaping
118
+ name = name.replace(/`/g, '');
119
+ // Handle parameter descriptors like `(paramName)`
120
+ if (name.startsWith('(') && name.endsWith(')')) {
121
+ name = name.slice(1, -1);
122
+ }
123
+ return name || scipSymbol;
124
+ }
125
+ /**
126
+ * Extract a signature from SCIP SymbolInformation documentation.
127
+ *
128
+ * scip-typescript puts the TypeScript type signature in the first
129
+ * documentation entry wrapped in a markdown code fence.
130
+ */
131
+ function extractSignatureFromDoc(doc) {
132
+ const cleaned = doc
133
+ .replace(/```[a-z0-9_+-]*\n/gi, '')
134
+ .replace(/```/g, '')
135
+ .trim();
136
+ return cleaned || '';
137
+ }
138
+ // ─── Symbol-span fallback ─────────────────────────────────────────────────────
139
+ /**
140
+ * Estimate the end line of a symbol whose `enclosing_range` was absent.
141
+ *
142
+ * Strategy: from the definition line, scan forward for curly-brace blocks
143
+ * (classes, functions, structs in C-family / Rust / Go / Java / etc.) or
144
+ * indentation-based blocks (Python). If nothing works, scan to the next
145
+ * definition or EOF.
146
+ */
147
+ function estimateSymbolEndLine(sourceLines, defLine, nextDefLine) {
148
+ if (defLine >= sourceLines.length)
149
+ return defLine;
150
+ const src = sourceLines[defLine];
151
+ // Python-style: indentation-based scope.
152
+ // Detect lines ending with ":" (def, class, if, etc.).
153
+ if (/:\s*(#.*)?$/.test(src)) {
154
+ // Measure the indentation of the definition line itself.
155
+ const baseIndent = src.match(/^(\s*)/)[1].length;
156
+ let last = defLine;
157
+ for (let i = defLine + 1; i < sourceLines.length; i++) {
158
+ const line = sourceLines[i];
159
+ // Skip blank / comment-only lines
160
+ if (/^\s*$/.test(line) || /^\s*#/.test(line)) {
161
+ last = i;
162
+ continue;
163
+ }
164
+ const indent = line.match(/^(\s*)/)[1].length;
165
+ if (indent <= baseIndent)
166
+ break;
167
+ last = i;
168
+ }
169
+ if (last > defLine)
170
+ return last;
171
+ }
172
+ // Brace-counting: scan forward from the first '{' on or after defLine.
173
+ let braceStart = -1;
174
+ for (let i = defLine; i < Math.min(defLine + 5, sourceLines.length); i++) {
175
+ if (sourceLines[i].includes('{')) {
176
+ braceStart = i;
177
+ break;
178
+ }
179
+ }
180
+ if (braceStart >= 0) {
181
+ let depth = 0;
182
+ for (let i = braceStart; i < sourceLines.length; i++) {
183
+ const line = sourceLines[i];
184
+ for (const ch of line) {
185
+ if (ch === '{')
186
+ depth++;
187
+ else if (ch === '}') {
188
+ depth--;
189
+ if (depth === 0)
190
+ return i;
191
+ }
192
+ }
193
+ }
194
+ }
195
+ // Fallback: extend to just before the next definition, or EOF.
196
+ if (nextDefLine !== null && nextDefLine > defLine) {
197
+ return nextDefLine - 1;
198
+ }
199
+ return Math.min(defLine + 20, sourceLines.length - 1);
200
+ }
201
+ // ─── Type-ref kind inference ──────────────────────────────────────────────────
202
+ /**
203
+ * Infer a `ref_kind` for a type reference from its surrounding source context.
204
+ *
205
+ * Reads the source line at `refLine` and applies simple pattern matching to
206
+ * distinguish parameter, return, field, variable, generic_arg and bound usages.
207
+ * Falls back to `'other'` when the context is ambiguous.
208
+ */
209
+ function inferTypeRefKind(sourceLines, refLine, refChar) {
210
+ if (refLine >= sourceLines.length)
211
+ return 'other';
212
+ const line = sourceLines[refLine];
213
+ const before = line.slice(0, refChar);
214
+ // Return type: preceded by "->" or "=>" or "): "
215
+ if (/(->|=>)\s*$/.test(before))
216
+ return 'return';
217
+ if (/\)\s*:\s*$/.test(before))
218
+ return 'return';
219
+ // Type bound: "where T:" or "<T extends" patterns
220
+ if (/\bwhere\s+\w+\s*:\s*$/.test(before))
221
+ return 'bound';
222
+ if (/<[^>]*\b(extends|:)\s*$/.test(before))
223
+ return 'bound';
224
+ // Generic argument: preceded by '<' or ',' inside angle brackets
225
+ if (/<[^>]*$/.test(before) || /^[^<]*>/.test(line.slice(refChar))) {
226
+ return 'generic_arg';
227
+ }
228
+ // Parameter: inside a parenthesized parameter list with annotation
229
+ if (/[(,]\s*\w+\s*:\s*$/.test(before))
230
+ return 'parameter';
231
+ // Go-style: "func f(x Foo" — identifier then space then type, inside parens
232
+ if (/[(,]\s*\w+\s+$/.test(before) && /^[^)]*\)/.test(line.slice(refChar)))
233
+ return 'parameter';
234
+ // Variable: "let x: T", "const x: T", "var x: T" at statement level
235
+ if (/^\s*(let|const|var|val)\s+\w+\s*:\s*$/.test(before))
236
+ return 'variable';
237
+ // Field / property: line starts with an access modifier or class-body keyword
238
+ const trimmed = line.trimStart();
239
+ if (/^(public|private|protected|readonly|static|final)\s/.test(trimmed)) {
240
+ if (!before.includes('('))
241
+ return 'field';
242
+ }
243
+ return 'other';
244
+ }
245
+ // ─── Stage implementation ────────────────────────────────────────────────────
246
+ export class ScipSourceStage {
247
+ name = 'scip-source';
248
+ async execute(context, mode) {
249
+ if (!context.scip?.enabled)
250
+ return;
251
+ const log = context.log;
252
+ const rootDir = context.walkerConfig.rootDir;
253
+ // In update mode, determine which SCIP-supported languages have changed
254
+ // files so we only re-run the indexers that are actually stale.
255
+ let staleLanguages = null;
256
+ if (mode === 'update' && context.changedFiles && context.changedFiles.length > 0) {
257
+ staleLanguages = new Set();
258
+ for (const filePath of context.changedFiles) {
259
+ const dotIdx = filePath.lastIndexOf('.');
260
+ if (dotIdx >= 0) {
261
+ const ext = filePath.slice(dotIdx).toLowerCase();
262
+ const lang = EXT_TO_LANG[ext];
263
+ if (lang && SCIP_SUPPORTED_LANGUAGES.has(lang)) {
264
+ staleLanguages.add(lang);
265
+ }
266
+ }
267
+ }
268
+ if (staleLanguages.size === 0) {
269
+ log.indexing('scip-source: no SCIP-supported languages in changed files, skipping');
270
+ return;
271
+ }
272
+ log.indexing('scip-source: stale languages', { languages: [...staleLanguages] });
273
+ }
274
+ // Load SCIP index
275
+ const indexBuffer = await this.loadScipIndex(context.scip, rootDir, staleLanguages);
276
+ if (!indexBuffer) {
277
+ log.indexing('scip-source: no SCIP index available');
278
+ return;
279
+ }
280
+ const scipIndex = fromBinary(IndexSchema, indexBuffer);
281
+ log.indexing('scip-source: loaded index', {
282
+ documents: scipIndex.documents.length,
283
+ externalSymbols: scipIndex.externalSymbols.length,
284
+ });
285
+ if (scipIndex.documents.length === 0)
286
+ return;
287
+ // Determine which languages are covered
288
+ const coveredLanguages = new Set();
289
+ const coveredFiles = new Set();
290
+ for (const doc of scipIndex.documents) {
291
+ // scip-typescript (and some other indexers) leave language blank;
292
+ // fall back to file-extension inference.
293
+ const loreLang = inferLoreLanguage(doc.language, doc.relativePath);
294
+ if (loreLang)
295
+ coveredLanguages.add(loreLang);
296
+ }
297
+ log.indexing('scip-source: languages covered', { languages: [...coveredLanguages] });
298
+ // Determine the project's SCIP symbol prefix so we can distinguish
299
+ // internal symbols from external ones (stdlib, node_modules, etc.).
300
+ // Internal symbols are those whose SCIP string starts with the same
301
+ // scheme + package as symbols defined in the index's own documents.
302
+ const internalPrefixes = new Set();
303
+ for (const doc of scipIndex.documents) {
304
+ for (const sym of doc.symbols) {
305
+ if (sym.symbol && !sym.symbol.startsWith('local ')) {
306
+ // Extract "scheme package" prefix (first 4 space-separated tokens)
307
+ const parts = sym.symbol.split(' ');
308
+ if (parts.length >= 4) {
309
+ internalPrefixes.add(parts.slice(0, 4).join(' '));
310
+ }
311
+ break; // One per document is enough
312
+ }
313
+ }
314
+ }
315
+ /** Is this symbol from an external package (node_modules, stdlib, etc.)? */
316
+ function isExternalSymbol(scipSymbol) {
317
+ if (internalPrefixes.size === 0)
318
+ return false;
319
+ for (const prefix of internalPrefixes) {
320
+ if (scipSymbol.startsWith(prefix))
321
+ return false;
322
+ }
323
+ return true;
324
+ }
325
+ // Build a global SCIP symbol → definition location map
326
+ const symbolDefinitions = new Map();
327
+ for (const doc of scipIndex.documents) {
328
+ const absPath = resolve(rootDir, doc.relativePath);
329
+ for (const occ of doc.occurrences) {
330
+ if ((occ.symbolRoles & SymbolRole.Definition) !== 0 && occ.symbol && !occ.symbol.startsWith('local ')) {
331
+ if (!symbolDefinitions.has(occ.symbol)) {
332
+ symbolDefinitions.set(occ.symbol, {
333
+ filePath: absPath,
334
+ line: occ.range[0] ?? 0,
335
+ character: occ.range[1] ?? 0,
336
+ });
337
+ }
338
+ }
339
+ }
340
+ }
341
+ // Build a SymbolInformation map for signatures/docs
342
+ const symbolInfoMap = new Map();
343
+ for (const doc of scipIndex.documents) {
344
+ for (const sym of doc.symbols) {
345
+ if (sym.symbol)
346
+ symbolInfoMap.set(sym.symbol, sym);
347
+ }
348
+ }
349
+ // Process each document
350
+ const db = context.db;
351
+ const branch = context.branch;
352
+ // Prepared statements
353
+ const insertFile = db.prepare(`INSERT INTO files (path, branch, language, size_bytes, last_hash, source)
354
+ VALUES (?, ?, ?, ?, ?, ?)`);
355
+ const insertSymbol = db.prepare(`INSERT INTO symbols (file_id, name, kind, start_line, end_line, signature, doc_comment)
356
+ VALUES (?, ?, ?, ?, ?, ?, ?)`);
357
+ const insertCallRef = db.prepare(`INSERT INTO symbol_refs (caller_id, file_id, callee_id, callee_name, call_line, call_character, call_kind, resolution_method)
358
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)`);
359
+ const insertTypeRef = db.prepare(`INSERT INTO type_refs (file_id, symbol_id, type_id, type_name, type_name_bare, ref_kind, ref_line, ref_character, resolution_method)
360
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`);
361
+ const insertImport = db.prepare('INSERT INTO file_imports (file_id, raw_import) VALUES (?, ?)');
362
+ const insertRelationship = db.prepare(`INSERT INTO symbol_relationships (file_id, source_symbol_id, target_symbol_name, relationship_type, line, character, resolution_method)
363
+ VALUES (?, ?, ?, ?, ?, ?, ?)`);
364
+ // Global map: SCIP symbol string → Lore numeric symbol ID (across all files)
365
+ const scipToLoreId = new Map();
366
+ // Pass 1: Create files and symbols
367
+ const fileIdMap = new Map(); // absPath → file_id
368
+ const processDocuments = db.transaction(() => {
369
+ for (const doc of scipIndex.documents) {
370
+ const absPath = resolve(rootDir, doc.relativePath);
371
+ const loreLang = inferLoreLanguage(doc.language, doc.relativePath);
372
+ if (!loreLang)
373
+ continue;
374
+ // Read source file
375
+ let source;
376
+ try {
377
+ source = fs.readFileSync(absPath, 'utf8');
378
+ }
379
+ catch {
380
+ continue;
381
+ }
382
+ // Cache for downstream stages (metrics computation, enrichment).
383
+ context.sourceCache.set(absPath, source);
384
+ const sizeBytes = Buffer.byteLength(source, 'utf8');
385
+ const hash = crypto.createHash('sha256').update(source).digest('hex');
386
+ // Delete existing data for this file (like SourceIndexStage does)
387
+ const existing = db.prepare('SELECT id FROM files WHERE path = ? AND branch = ?').get(absPath, branch);
388
+ if (existing) {
389
+ db.prepare('DELETE FROM symbol_relationships WHERE file_id = ?').run(existing.id);
390
+ db.prepare('DELETE FROM type_refs WHERE file_id = ?').run(existing.id);
391
+ db.prepare('UPDATE symbol_refs SET callee_id = NULL WHERE callee_id IN (SELECT id FROM symbols WHERE file_id = ?)').run(existing.id);
392
+ db.prepare('UPDATE type_refs SET type_id = NULL WHERE type_id IN (SELECT id FROM symbols WHERE file_id = ?)').run(existing.id);
393
+ db.prepare('DELETE FROM symbols WHERE file_id = ?').run(existing.id);
394
+ db.prepare('DELETE FROM file_imports WHERE file_id = ?').run(existing.id);
395
+ db.prepare('DELETE FROM files WHERE id = ?').run(existing.id);
396
+ }
397
+ // Insert file
398
+ const fileInfo = insertFile.run(absPath, branch, loreLang, sizeBytes, hash, source);
399
+ const fileId = Number(fileInfo.lastInsertRowid);
400
+ fileIdMap.set(absPath, fileId);
401
+ coveredFiles.add(absPath);
402
+ // Collect definition occurrences for this document
403
+ // Build symbol spans: SCIP symbol → { startLine, endLine }
404
+ const sourceLines = source.split('\n');
405
+ const docDefs = new Map();
406
+ // First collect all definition lines so we can order them for fallback
407
+ const defOccs = [];
408
+ for (const occ of doc.occurrences) {
409
+ if ((occ.symbolRoles & SymbolRole.Definition) === 0)
410
+ continue;
411
+ if (!occ.symbol || occ.symbol.startsWith('local '))
412
+ continue;
413
+ defOccs.push({ symbol: occ.symbol, line: occ.range[0] ?? 0, character: occ.range[1] ?? 0, enclosingRange: [...occ.enclosingRange] });
414
+ }
415
+ // Sort by line so we know the "next definition" for span estimation
416
+ defOccs.sort((a, b) => a.line - b.line);
417
+ for (let di = 0; di < defOccs.length; di++) {
418
+ const occ = defOccs[di];
419
+ const { symbol, line, character, enclosingRange } = occ;
420
+ // Use enclosing_range for span; fall back to source-based estimation
421
+ let startLine = line;
422
+ let endLine = line;
423
+ if (enclosingRange.length >= 3) {
424
+ startLine = enclosingRange[0] ?? line;
425
+ endLine = enclosingRange.length >= 4
426
+ ? (enclosingRange[2] ?? line)
427
+ : startLine;
428
+ }
429
+ else {
430
+ // No enclosing_range — estimate from source
431
+ const nextDefLine = di + 1 < defOccs.length ? defOccs[di + 1].line : null;
432
+ endLine = estimateSymbolEndLine(sourceLines, line, nextDefLine);
433
+ }
434
+ // Keep the first definition per symbol in this file
435
+ if (!docDefs.has(symbol)) {
436
+ docDefs.set(symbol, { line, character, startLine, endLine });
437
+ }
438
+ }
439
+ // Insert symbols from SymbolInformation + definition occurrences
440
+ for (const symInfo of doc.symbols) {
441
+ if (!symInfo.symbol || symInfo.symbol.startsWith('local '))
442
+ continue;
443
+ const defLoc = docDefs.get(symInfo.symbol);
444
+ if (!defLoc)
445
+ continue; // No definition occurrence for this symbol info
446
+ const name = symInfo.displayName || extractNameFromScipSymbol(symInfo.symbol);
447
+ const firstDoc = symInfo.documentation[0] ?? '';
448
+ const docHint = firstDoc.toLowerCase();
449
+ const kind = inferKindFromScipSymbol(symInfo.symbol, docHint);
450
+ // Skip parameters, type parameters, and module-level namespace symbols
451
+ if (kind === 'parameter' || kind === 'module')
452
+ continue;
453
+ const signature = extractSignatureFromDoc(firstDoc);
454
+ const docComment = symInfo.documentation.slice(1).join('\n').trim() || null;
455
+ const info = insertSymbol.run(fileId, name, kind, defLoc.startLine, defLoc.endLine, signature || null, docComment);
456
+ const loreId = Number(info.lastInsertRowid);
457
+ scipToLoreId.set(symInfo.symbol, loreId);
458
+ }
459
+ // Insert imports (from Import-role occurrences)
460
+ // Prefer the actual import path from source; fall back to SCIP package
461
+ const seenImports = new Set();
462
+ for (const occ of doc.occurrences) {
463
+ if ((occ.symbolRoles & SymbolRole.Import) !== 0 && occ.symbol) {
464
+ const importLine = occ.range[0] ?? 0;
465
+ const srcImport = importLine < sourceLines.length
466
+ ? extractImportPathFromSource(sourceLines[importLine])
467
+ : null;
468
+ let rawImport;
469
+ if (srcImport) {
470
+ rawImport = srcImport;
471
+ }
472
+ else {
473
+ // Fall back to SCIP package descriptor
474
+ const parts = occ.symbol.split(' ');
475
+ rawImport = parts.length >= 4 ? parts[3] : occ.symbol;
476
+ }
477
+ if (rawImport && !seenImports.has(rawImport)) {
478
+ seenImports.add(rawImport);
479
+ insertImport.run(fileId, rawImport);
480
+ }
481
+ }
482
+ }
483
+ // Insert relationships (extends/implements) from SCIP SymbolInformation
484
+ for (const symInfo of doc.symbols) {
485
+ if (!symInfo.symbol || symInfo.relationships.length === 0)
486
+ continue;
487
+ const sourceId = scipToLoreId.get(symInfo.symbol) ?? null;
488
+ const sourceName = symInfo.displayName || extractNameFromScipSymbol(symInfo.symbol);
489
+ for (const rel of symInfo.relationships) {
490
+ if (!rel.symbol)
491
+ continue;
492
+ // Map SCIP relationship flags to Lore relationship types
493
+ // Disambiguate extends vs implements: if the target is a class/struct
494
+ // the source extends it; if the target is an interface/trait the
495
+ // source implements it.
496
+ let relType = null;
497
+ if (rel.isImplementation) {
498
+ const targetInfo = symbolInfoMap.get(rel.symbol);
499
+ const targetKind = targetInfo
500
+ ? inferKindFromScipSymbol(rel.symbol, (targetInfo.documentation[0] ?? '').toLowerCase())
501
+ : null;
502
+ relType = (targetKind === 'class') ? 'extends' : 'implements';
503
+ }
504
+ else if (rel.isTypeDefinition) {
505
+ relType = 'type_definition';
506
+ }
507
+ else if (rel.isDefinition) {
508
+ relType = 'defines';
509
+ }
510
+ if (!relType)
511
+ continue;
512
+ const targetName = extractNameFromScipSymbol(rel.symbol);
513
+ const targetId = scipToLoreId.get(rel.symbol) ?? null;
514
+ // Find a definition location for the line/character.
515
+ // Some SCIP indexers (e.g. scip-go) emit SymbolInformation with
516
+ // relationships for symbols whose definition is in another file or
517
+ // external package, so defLoc may be undefined.
518
+ const defLoc = symbolDefinitions.get(symInfo.symbol);
519
+ insertRelationship.run(fileId, sourceId, targetName, relType, defLoc?.line ?? null, defLoc?.character ?? null, targetId ? 'scip_definition' : 'unresolved');
520
+ // If we have both source and target IDs, update the resolved target
521
+ if (targetId) {
522
+ db.prepare('UPDATE symbol_relationships SET target_symbol_id = ? WHERE file_id = ? AND source_symbol_id = ? AND target_symbol_name = ? AND relationship_type = ?').run(targetId, fileId, sourceId, targetName, relType);
523
+ }
524
+ }
525
+ }
526
+ }
527
+ });
528
+ processDocuments();
529
+ log.indexing('scip-source: symbols inserted', {
530
+ files: fileIdMap.size,
531
+ symbols: scipToLoreId.size,
532
+ });
533
+ // Pass 2: Build a containment index for caller resolution
534
+ // For each file, sort symbols by span so we can find the narrowest
535
+ // enclosing symbol for any position.
536
+ const fileSymbolSpans = new Map();
537
+ {
538
+ const rows = db.prepare(`SELECT s.id, s.file_id, s.start_line, s.end_line
539
+ FROM symbols s
540
+ JOIN files f ON f.id = s.file_id
541
+ WHERE f.branch = ?
542
+ ORDER BY s.file_id, (s.end_line - s.start_line) ASC`).all(branch);
543
+ for (const row of rows) {
544
+ let spans = fileSymbolSpans.get(row.file_id);
545
+ if (!spans) {
546
+ spans = [];
547
+ fileSymbolSpans.set(row.file_id, spans);
548
+ }
549
+ spans.push({ id: row.id, startLine: row.start_line, endLine: row.end_line });
550
+ }
551
+ }
552
+ /** Find the narrowest enclosing symbol for a given line in a file. */
553
+ function findContainingSymbol(fileId, line) {
554
+ const spans = fileSymbolSpans.get(fileId);
555
+ if (!spans)
556
+ return null;
557
+ // Spans are sorted narrowest-first, so first match is best
558
+ for (const span of spans) {
559
+ if (line >= span.startLine && line <= span.endLine) {
560
+ return span.id;
561
+ }
562
+ }
563
+ return null;
564
+ }
565
+ // Pass 3: Insert call refs and type refs from reference occurrences
566
+ //
567
+ // SCIP tracks every identifier occurrence (calls, reads, type annotations,
568
+ // namespace imports, etc.). Only a subset belongs in Lore's graph:
569
+ // - Method/function refs → symbol_refs (call edges)
570
+ // - Type refs → type_refs (type usage edges)
571
+ // - Everything else → skipped (reads, imports, namespaces)
572
+ let refsInserted = 0;
573
+ let refsExternal = 0;
574
+ let refsNoCaller = 0;
575
+ let refsLocal = 0;
576
+ let refsSkippedNonCall = 0;
577
+ let typeRefsInserted = 0;
578
+ const processRefs = db.transaction(() => {
579
+ for (const doc of scipIndex.documents) {
580
+ const absPath = resolve(rootDir, doc.relativePath);
581
+ const fileId = fileIdMap.get(absPath);
582
+ if (!fileId)
583
+ continue;
584
+ // Read source for receiver-chain reconstruction.
585
+ let source = null;
586
+ try {
587
+ source = fs.readFileSync(absPath, 'utf8');
588
+ }
589
+ catch { /* skip */ }
590
+ const sourceLines = source?.split('\n') ?? [];
591
+ // Build a per-line index of all occurrences for receiver lookup.
592
+ const occsByLine = new Map();
593
+ for (const o of doc.occurrences) {
594
+ const ln = o.range[0] ?? 0;
595
+ const sc = o.range[1] ?? 0;
596
+ const ec = o.range.length >= 4 ? (o.range[3] ?? 0) : (o.range[2] ?? 0);
597
+ let list = occsByLine.get(ln);
598
+ if (!list) {
599
+ list = [];
600
+ occsByLine.set(ln, list);
601
+ }
602
+ list.push({ startChar: sc, endChar: ec, symbol: o.symbol });
603
+ }
604
+ for (const occ of doc.occurrences) {
605
+ // Skip definitions — we only want references
606
+ if ((occ.symbolRoles & SymbolRole.Definition) !== 0)
607
+ continue;
608
+ if (!occ.symbol)
609
+ continue;
610
+ // Skip locals
611
+ if (occ.symbol.startsWith('local ')) {
612
+ refsLocal++;
613
+ continue;
614
+ }
615
+ // Classify the reference by the SCIP descriptor suffix
616
+ const refKind = classifyScipReference(occ.symbol);
617
+ if (refKind === 'skip') {
618
+ refsSkippedNonCall++;
619
+ continue;
620
+ }
621
+ const line = occ.range[0] ?? 0;
622
+ const character = occ.range[1] ?? 0;
623
+ // Find the caller (containing symbol)
624
+ const callerId = findContainingSymbol(fileId, line);
625
+ if (!callerId) {
626
+ refsNoCaller++;
627
+ continue;
628
+ }
629
+ // Find the callee (definition of the referenced symbol)
630
+ const calleeId = scipToLoreId.get(occ.symbol) ?? null;
631
+ let calleeName = extractNameFromScipSymbol(occ.symbol);
632
+ const isExternal = !calleeId && isExternalSymbol(occ.symbol);
633
+ const method = calleeId ? 'scip_definition' : (isExternal ? 'external_definition' : 'unresolved');
634
+ // Reconstruct member-access callee_name (e.g. "db.prepare")
635
+ // by checking if there's a receiver occurrence immediately before
636
+ // the method on the same line (receiver ends at or near char-1).
637
+ if (refKind === 'call' && sourceLines.length > line) {
638
+ const srcLine = sourceLines[line];
639
+ // The dot is at character-1 (e.g., `db.prepare` → dot at char 2, method at char 3)
640
+ if (character > 0 && srcLine[character - 1] === '.') {
641
+ const lineOccs = occsByLine.get(line);
642
+ if (lineOccs) {
643
+ // Find the occurrence ending right before the dot
644
+ const receiver = lineOccs.find(o => o.endChar >= character - 2 && o.endChar <= character
645
+ && o.startChar < character);
646
+ if (receiver) {
647
+ // Extract the receiver text from source
648
+ const receiverText = srcLine.slice(receiver.startChar, receiver.endChar);
649
+ if (receiverText) {
650
+ calleeName = receiverText + '.' + calleeName;
651
+ }
652
+ }
653
+ }
654
+ }
655
+ }
656
+ if (refKind === 'type') {
657
+ const typeRefKind = inferTypeRefKind(sourceLines, line, character);
658
+ insertTypeRef.run(fileId, callerId, calleeId, calleeName, normalizeTypeName(calleeName), typeRefKind, line, character, method);
659
+ typeRefsInserted++;
660
+ }
661
+ else {
662
+ // refKind === 'call'
663
+ insertCallRef.run(callerId, fileId, calleeId, calleeName, line, character, 'direct', method);
664
+ refsInserted++;
665
+ if (isExternal)
666
+ refsExternal++;
667
+ }
668
+ }
669
+ }
670
+ });
671
+ processRefs();
672
+ log.indexing('scip-source: refs inserted', {
673
+ callRefs: refsInserted,
674
+ typeRefs: typeRefsInserted,
675
+ external: refsExternal,
676
+ noCaller: refsNoCaller,
677
+ skippedLocal: refsLocal,
678
+ skippedNonCall: refsSkippedNonCall,
679
+ });
680
+ // Communicate coverage to downstream stages
681
+ context.scipSourcedLanguages = coveredLanguages;
682
+ context.scipSourcedFiles = coveredFiles;
683
+ // Add SCIP-sourced files to context.files so later stages process them
684
+ for (const doc of scipIndex.documents) {
685
+ const absPath = resolve(rootDir, doc.relativePath);
686
+ const loreLang = inferLoreLanguage(doc.language, doc.relativePath);
687
+ if (loreLang && fileIdMap.has(absPath)) {
688
+ context.files.push({ path: absPath, language: loreLang });
689
+ }
690
+ }
691
+ }
692
+ async dispose() {
693
+ // No persistent resources to clean up
694
+ }
695
+ // ─── SCIP index loading ──────────────────────────────────────────────────
696
+ async loadScipIndex(settings, rootDir, staleLanguages = null) {
697
+ // Try pre-computed index directory first
698
+ if (settings.indexDir) {
699
+ // When staleLanguages is set, prefer per-language index files so
700
+ // we only load the languages that actually need re-processing.
701
+ if (staleLanguages) {
702
+ for (const lang of staleLanguages) {
703
+ const candidate = join(rootDir, settings.indexDir, `${lang}.scip`);
704
+ if (existsSync(candidate)) {
705
+ return readFileSync(candidate);
706
+ }
707
+ }
708
+ }
709
+ const candidates = [
710
+ join(rootDir, settings.indexDir, 'index.scip'),
711
+ // Language-specific index files
712
+ ...['typescript', 'javascript', 'python', 'java', 'rust', 'c', 'cpp', 'csharp', 'ruby', 'php', 'go', 'dart'].map(lang => join(rootDir, settings.indexDir, `${lang}.scip`)),
713
+ ];
714
+ for (const candidate of candidates) {
715
+ if (existsSync(candidate)) {
716
+ return readFileSync(candidate);
717
+ }
718
+ }
719
+ }
720
+ // Try running an indexer
721
+ const resolvedIndexers = resolveScipIndexerRegistry(settings.indexers);
722
+ for (const [lang, indexer] of Object.entries(resolvedIndexers)) {
723
+ if (!indexer.available)
724
+ continue;
725
+ // Per-language staleness: skip indexers for languages that haven't changed.
726
+ if (staleLanguages && !staleLanguages.has(lang))
727
+ continue;
728
+ try {
729
+ const outputPath = join(rootDir, `.lore-scip-${lang}.scip`);
730
+ const args = indexer.args.map(a => a.replace(/\{output\}/g, outputPath));
731
+ const execFileAsync = promisify(execFile);
732
+ await execFileAsync(indexer.command, args, {
733
+ cwd: rootDir,
734
+ timeout: settings.timeoutMs,
735
+ });
736
+ // Check for output
737
+ for (const candidate of [outputPath, join(rootDir, 'index.scip')]) {
738
+ if (existsSync(candidate)) {
739
+ const data = readFileSync(candidate);
740
+ try {
741
+ fs.unlinkSync(candidate);
742
+ }
743
+ catch { /* best effort */ }
744
+ return data;
745
+ }
746
+ }
747
+ }
748
+ catch {
749
+ continue;
750
+ }
751
+ }
752
+ return null;
753
+ }
754
+ }
755
+ // ─── SCIP reference classification ──────────────────────────────────────────
756
+ /**
757
+ * Classify a SCIP symbol reference into the graph edge type it represents.
758
+ *
759
+ * SCIP descriptor suffixes:
760
+ * `().` → Method/Function → call edge (symbol_refs)
761
+ * `#` → Type → type edge (type_refs)
762
+ * `.` → Term (variable, property, constant, enum member) → skip
763
+ * `/` → Namespace (module) → skip
764
+ * `:` → Meta (object property) → skip
765
+ * `)` → Parameter → skip
766
+ * `]` → Type parameter → type edge (type_refs)
767
+ */
768
+ function classifyScipReference(scipSymbol) {
769
+ // Method/function: ends with (). or (+N). (with disambiguator)
770
+ if (/\(\+?\d*\)\.$/.test(scipSymbol))
771
+ return 'call';
772
+ // Type: ends with #
773
+ if (scipSymbol.endsWith('#'))
774
+ return 'type';
775
+ // Type parameter: ends with ]
776
+ if (scipSymbol.endsWith(']'))
777
+ return 'type';
778
+ // Term (variable, property, constant, enum member): ends with .
779
+ // Namespace: ends with /
780
+ // Meta (object property): ends with :
781
+ // Parameter: ends with )
782
+ // All of these are reads/imports/structural — not call or type edges.
783
+ return 'skip';
784
+ }
785
+ // ─── Import path extraction ─────────────────────────────────────────────────
786
+ /**
787
+ * Extract the actual import/require path from a source line.
788
+ *
789
+ * Handles common patterns across languages:
790
+ * - JS/TS: `import ... from 'path'`, `require('path')`
791
+ * - Python: `import path`, `from path import ...`
792
+ * - Go: `"path"` (inside import block)
793
+ * - Java/Kotlin/Scala: `import path.to.Class`
794
+ * - Rust: `use path::to::item`
795
+ * - C/C++: `#include "path"` or `#include <path>`
796
+ * - Ruby: `require 'path'`, `require_relative 'path'`
797
+ * - PHP: `use Path\\To\\Class`
798
+ * - C#: `using Namespace.Name`
799
+ * - Dart: `import 'path'`
800
+ *
801
+ * Returns `null` when no recognizable import pattern is found.
802
+ */
803
+ function extractImportPathFromSource(line) {
804
+ const trimmed = line.trim();
805
+ // JS/TS: import ... from 'path' | import 'path' | require('path') | import('path')
806
+ let m = trimmed.match(/\bfrom\s+['"]([^'"]+)['"]/);
807
+ if (m)
808
+ return m[1];
809
+ m = trimmed.match(/\brequire\s*\(\s*['"]([^'"]+)['"]\s*\)/);
810
+ if (m)
811
+ return m[1];
812
+ m = trimmed.match(/^import\s+['"]([^'"]+)['"]/);
813
+ if (m)
814
+ return m[1];
815
+ m = trimmed.match(/\bimport\s*\(\s*['"]([^'"]+)['"]\s*\)/);
816
+ if (m)
817
+ return m[1];
818
+ // C/C++: #include "path" | #include <path>
819
+ m = trimmed.match(/^#\s*include\s*[<"]([^>"]+)[>"]/);
820
+ if (m)
821
+ return m[1];
822
+ // Python: from X import ... | import X
823
+ m = trimmed.match(/^from\s+([\w.]+)\s+import\b/);
824
+ if (m)
825
+ return m[1];
826
+ // C#: using Namespace.Name;
827
+ m = trimmed.match(/^using\s+(?:static\s+)?([\w.]+)\s*;/);
828
+ if (m)
829
+ return m[1];
830
+ // Ruby: require 'path' | require_relative 'path'
831
+ m = trimmed.match(/^require(?:_relative)?\s+['"]([^'"]+)['"]/);
832
+ if (m)
833
+ return m[1];
834
+ // Java/Kotlin/Scala: import [static] path.to.Class (dotted path, no quotes)
835
+ m = trimmed.match(/^import\s+(?:static\s+)?([\w.*]+)/);
836
+ if (m)
837
+ return m[1];
838
+ // Rust: use path::to::item (contains ::)
839
+ m = trimmed.match(/^use\s+([\w:]+::[\w:]+)/);
840
+ if (m)
841
+ return m[1].replace(/::/g, '/');
842
+ // PHP: use Path\To\Class (contains backslash)
843
+ m = trimmed.match(/^use\s+([\w\\]+\\[\w\\]+)/);
844
+ if (m)
845
+ return m[1];
846
+ // Go: "path/to/pkg" inside import block (bare quoted string)
847
+ m = trimmed.match(/^\s*(?:\w+\s+)?["']([^"']+)["']/);
848
+ if (m && !trimmed.startsWith('import') && !trimmed.startsWith('from'))
849
+ return m[1];
850
+ return null;
851
+ }
852
+ // ─── SCIP language detection ────────────────────────────────────────────────
853
+ const SCIP_LANG_MAP = {
854
+ typescript: 'typescript',
855
+ typescriptreact: 'typescript',
856
+ javascript: 'javascript',
857
+ javascriptreact: 'javascript',
858
+ python: 'python',
859
+ java: 'java',
860
+ scala: 'scala',
861
+ kotlin: 'kotlin',
862
+ rust: 'rust',
863
+ c: 'c',
864
+ 'c++': 'cpp',
865
+ cpp: 'cpp',
866
+ 'c#': 'csharp',
867
+ csharp: 'csharp',
868
+ visualbasic: 'csharp',
869
+ ruby: 'ruby',
870
+ php: 'php',
871
+ go: 'go',
872
+ dart: 'dart',
873
+ };
874
+ const EXT_TO_LANG = {
875
+ '.ts': 'typescript',
876
+ '.tsx': 'typescript',
877
+ '.js': 'javascript',
878
+ '.jsx': 'javascript',
879
+ '.mjs': 'javascript',
880
+ '.cjs': 'javascript',
881
+ '.py': 'python',
882
+ '.java': 'java',
883
+ '.scala': 'scala',
884
+ '.sc': 'scala',
885
+ '.kt': 'kotlin',
886
+ '.kts': 'kotlin',
887
+ '.rs': 'rust',
888
+ '.c': 'c',
889
+ '.h': 'c',
890
+ '.cpp': 'cpp',
891
+ '.cc': 'cpp',
892
+ '.cxx': 'cpp',
893
+ '.hpp': 'cpp',
894
+ '.cs': 'csharp',
895
+ '.rb': 'ruby',
896
+ '.php': 'php',
897
+ '.go': 'go',
898
+ '.dart': 'dart',
899
+ };
900
+ /**
901
+ * Determine the Lore language for a SCIP document.
902
+ *
903
+ * Many SCIP indexers (including scip-typescript) leave the `language` field
904
+ * blank. When that happens, infer from the file extension.
905
+ */
906
+ function inferLoreLanguage(scipLanguage, relativePath) {
907
+ // Try explicit language first
908
+ if (scipLanguage) {
909
+ const mapped = SCIP_LANG_MAP[scipLanguage.toLowerCase()];
910
+ if (mapped)
911
+ return mapped;
912
+ }
913
+ // Infer from file extension
914
+ const dotIdx = relativePath.lastIndexOf('.');
915
+ if (dotIdx >= 0) {
916
+ const ext = relativePath.slice(dotIdx).toLowerCase();
917
+ return EXT_TO_LANG[ext] ?? null;
918
+ }
919
+ return null;
920
+ }
921
+ // ─── Test-visible helpers ───────────────────────────────────────────────────
922
+ // Exported for unit testing only. Not part of the public API.
923
+ export { estimateSymbolEndLine as _estimateSymbolEndLine, inferTypeRefKind as _inferTypeRefKind, extractImportPathFromSource as _extractImportPathFromSource, inferKindFromScipSymbol as _inferKindFromScipSymbol, inferLoreLanguage as _inferLoreLanguage, classifyScipReference as _classifyScipReference, extractNameFromScipSymbol as _extractNameFromScipSymbol, };
924
+ //# sourceMappingURL=scip-source.js.map