arceus-s 1.6.4

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 (1231) hide show
  1. package/README.md +395 -0
  2. package/dist/_shared/graph/types.d.ts +81 -0
  3. package/dist/_shared/graph/types.d.ts.map +1 -0
  4. package/dist/_shared/graph/types.js +8 -0
  5. package/dist/_shared/graph/types.js.map +1 -0
  6. package/dist/_shared/index.d.ts +63 -0
  7. package/dist/_shared/index.d.ts.map +1 -0
  8. package/dist/_shared/index.js +48 -0
  9. package/dist/_shared/index.js.map +1 -0
  10. package/dist/_shared/integrations/circuit-breaker.d.ts +183 -0
  11. package/dist/_shared/integrations/circuit-breaker.d.ts.map +1 -0
  12. package/dist/_shared/integrations/circuit-breaker.js +236 -0
  13. package/dist/_shared/integrations/circuit-breaker.js.map +1 -0
  14. package/dist/_shared/integrations/resilient-fetch.d.ts +99 -0
  15. package/dist/_shared/integrations/resilient-fetch.d.ts.map +1 -0
  16. package/dist/_shared/integrations/resilient-fetch.js +204 -0
  17. package/dist/_shared/integrations/resilient-fetch.js.map +1 -0
  18. package/dist/_shared/integrations/retry.d.ts +60 -0
  19. package/dist/_shared/integrations/retry.d.ts.map +1 -0
  20. package/dist/_shared/integrations/retry.js +67 -0
  21. package/dist/_shared/integrations/retry.js.map +1 -0
  22. package/dist/_shared/integrations/understand-quickly.d.ts +77 -0
  23. package/dist/_shared/integrations/understand-quickly.d.ts.map +1 -0
  24. package/dist/_shared/integrations/understand-quickly.js +176 -0
  25. package/dist/_shared/integrations/understand-quickly.js.map +1 -0
  26. package/dist/_shared/language-detection.d.ts +23 -0
  27. package/dist/_shared/language-detection.d.ts.map +1 -0
  28. package/dist/_shared/language-detection.js +139 -0
  29. package/dist/_shared/language-detection.js.map +1 -0
  30. package/dist/_shared/languages.d.ts +26 -0
  31. package/dist/_shared/languages.d.ts.map +1 -0
  32. package/dist/_shared/languages.js +27 -0
  33. package/dist/_shared/languages.js.map +1 -0
  34. package/dist/_shared/lbug/schema-constants.d.ts +16 -0
  35. package/dist/_shared/lbug/schema-constants.d.ts.map +1 -0
  36. package/dist/_shared/lbug/schema-constants.js +67 -0
  37. package/dist/_shared/lbug/schema-constants.js.map +1 -0
  38. package/dist/_shared/mro-strategy.d.ts +41 -0
  39. package/dist/_shared/mro-strategy.d.ts.map +1 -0
  40. package/dist/_shared/mro-strategy.js +2 -0
  41. package/dist/_shared/mro-strategy.js.map +1 -0
  42. package/dist/_shared/pipeline.d.ts +16 -0
  43. package/dist/_shared/pipeline.d.ts.map +1 -0
  44. package/dist/_shared/pipeline.js +5 -0
  45. package/dist/_shared/pipeline.js.map +1 -0
  46. package/dist/_shared/scope-resolution/def-index.d.ts +36 -0
  47. package/dist/_shared/scope-resolution/def-index.d.ts.map +1 -0
  48. package/dist/_shared/scope-resolution/def-index.js +51 -0
  49. package/dist/_shared/scope-resolution/def-index.js.map +1 -0
  50. package/dist/_shared/scope-resolution/evidence-weights.d.ts +69 -0
  51. package/dist/_shared/scope-resolution/evidence-weights.d.ts.map +1 -0
  52. package/dist/_shared/scope-resolution/evidence-weights.js +84 -0
  53. package/dist/_shared/scope-resolution/evidence-weights.js.map +1 -0
  54. package/dist/_shared/scope-resolution/finalize-algorithm.d.ts +149 -0
  55. package/dist/_shared/scope-resolution/finalize-algorithm.d.ts.map +1 -0
  56. package/dist/_shared/scope-resolution/finalize-algorithm.js +795 -0
  57. package/dist/_shared/scope-resolution/finalize-algorithm.js.map +1 -0
  58. package/dist/_shared/scope-resolution/language-classification.d.ts +26 -0
  59. package/dist/_shared/scope-resolution/language-classification.d.ts.map +1 -0
  60. package/dist/_shared/scope-resolution/language-classification.js +44 -0
  61. package/dist/_shared/scope-resolution/language-classification.js.map +1 -0
  62. package/dist/_shared/scope-resolution/method-dispatch-index.d.ts +106 -0
  63. package/dist/_shared/scope-resolution/method-dispatch-index.d.ts.map +1 -0
  64. package/dist/_shared/scope-resolution/method-dispatch-index.js +98 -0
  65. package/dist/_shared/scope-resolution/method-dispatch-index.js.map +1 -0
  66. package/dist/_shared/scope-resolution/module-scope-index.d.ts +46 -0
  67. package/dist/_shared/scope-resolution/module-scope-index.d.ts.map +1 -0
  68. package/dist/_shared/scope-resolution/module-scope-index.js +58 -0
  69. package/dist/_shared/scope-resolution/module-scope-index.js.map +1 -0
  70. package/dist/_shared/scope-resolution/origin-priority.d.ts +14 -0
  71. package/dist/_shared/scope-resolution/origin-priority.d.ts.map +1 -0
  72. package/dist/_shared/scope-resolution/origin-priority.js +21 -0
  73. package/dist/_shared/scope-resolution/origin-priority.js.map +1 -0
  74. package/dist/_shared/scope-resolution/parsed-file.d.ts +76 -0
  75. package/dist/_shared/scope-resolution/parsed-file.d.ts.map +1 -0
  76. package/dist/_shared/scope-resolution/parsed-file.js +54 -0
  77. package/dist/_shared/scope-resolution/parsed-file.js.map +1 -0
  78. package/dist/_shared/scope-resolution/position-index.d.ts +62 -0
  79. package/dist/_shared/scope-resolution/position-index.d.ts.map +1 -0
  80. package/dist/_shared/scope-resolution/position-index.js +134 -0
  81. package/dist/_shared/scope-resolution/position-index.js.map +1 -0
  82. package/dist/_shared/scope-resolution/qualified-name-index.d.ts +44 -0
  83. package/dist/_shared/scope-resolution/qualified-name-index.d.ts.map +1 -0
  84. package/dist/_shared/scope-resolution/qualified-name-index.js +75 -0
  85. package/dist/_shared/scope-resolution/qualified-name-index.js.map +1 -0
  86. package/dist/_shared/scope-resolution/reference-site.d.ts +75 -0
  87. package/dist/_shared/scope-resolution/reference-site.d.ts.map +1 -0
  88. package/dist/_shared/scope-resolution/reference-site.js +24 -0
  89. package/dist/_shared/scope-resolution/reference-site.js.map +1 -0
  90. package/dist/_shared/scope-resolution/registries/class-registry.d.ts +27 -0
  91. package/dist/_shared/scope-resolution/registries/class-registry.d.ts.map +1 -0
  92. package/dist/_shared/scope-resolution/registries/class-registry.js +30 -0
  93. package/dist/_shared/scope-resolution/registries/class-registry.js.map +1 -0
  94. package/dist/_shared/scope-resolution/registries/context.d.ts +69 -0
  95. package/dist/_shared/scope-resolution/registries/context.d.ts.map +1 -0
  96. package/dist/_shared/scope-resolution/registries/context.js +44 -0
  97. package/dist/_shared/scope-resolution/registries/context.js.map +1 -0
  98. package/dist/_shared/scope-resolution/registries/evidence.d.ts +56 -0
  99. package/dist/_shared/scope-resolution/registries/evidence.d.ts.map +1 -0
  100. package/dist/_shared/scope-resolution/registries/evidence.js +150 -0
  101. package/dist/_shared/scope-resolution/registries/evidence.js.map +1 -0
  102. package/dist/_shared/scope-resolution/registries/field-registry.d.ts +26 -0
  103. package/dist/_shared/scope-resolution/registries/field-registry.d.ts.map +1 -0
  104. package/dist/_shared/scope-resolution/registries/field-registry.js +31 -0
  105. package/dist/_shared/scope-resolution/registries/field-registry.js.map +1 -0
  106. package/dist/_shared/scope-resolution/registries/lookup-core.d.ts +81 -0
  107. package/dist/_shared/scope-resolution/registries/lookup-core.d.ts.map +1 -0
  108. package/dist/_shared/scope-resolution/registries/lookup-core.js +349 -0
  109. package/dist/_shared/scope-resolution/registries/lookup-core.js.map +1 -0
  110. package/dist/_shared/scope-resolution/registries/lookup-qualified.d.ts +33 -0
  111. package/dist/_shared/scope-resolution/registries/lookup-qualified.d.ts.map +1 -0
  112. package/dist/_shared/scope-resolution/registries/lookup-qualified.js +56 -0
  113. package/dist/_shared/scope-resolution/registries/lookup-qualified.js.map +1 -0
  114. package/dist/_shared/scope-resolution/registries/method-registry.d.ts +36 -0
  115. package/dist/_shared/scope-resolution/registries/method-registry.d.ts.map +1 -0
  116. package/dist/_shared/scope-resolution/registries/method-registry.js +32 -0
  117. package/dist/_shared/scope-resolution/registries/method-registry.js.map +1 -0
  118. package/dist/_shared/scope-resolution/registries/tie-breaks.d.ts +43 -0
  119. package/dist/_shared/scope-resolution/registries/tie-breaks.d.ts.map +1 -0
  120. package/dist/_shared/scope-resolution/registries/tie-breaks.js +60 -0
  121. package/dist/_shared/scope-resolution/registries/tie-breaks.js.map +1 -0
  122. package/dist/_shared/scope-resolution/resolve-type-ref.d.ts +53 -0
  123. package/dist/_shared/scope-resolution/resolve-type-ref.d.ts.map +1 -0
  124. package/dist/_shared/scope-resolution/resolve-type-ref.js +126 -0
  125. package/dist/_shared/scope-resolution/resolve-type-ref.js.map +1 -0
  126. package/dist/_shared/scope-resolution/scope-id.d.ts +43 -0
  127. package/dist/_shared/scope-resolution/scope-id.d.ts.map +1 -0
  128. package/dist/_shared/scope-resolution/scope-id.js +46 -0
  129. package/dist/_shared/scope-resolution/scope-id.js.map +1 -0
  130. package/dist/_shared/scope-resolution/scope-tree.d.ts +83 -0
  131. package/dist/_shared/scope-resolution/scope-tree.d.ts.map +1 -0
  132. package/dist/_shared/scope-resolution/scope-tree.js +220 -0
  133. package/dist/_shared/scope-resolution/scope-tree.js.map +1 -0
  134. package/dist/_shared/scope-resolution/shadow/aggregate.d.ts +63 -0
  135. package/dist/_shared/scope-resolution/shadow/aggregate.d.ts.map +1 -0
  136. package/dist/_shared/scope-resolution/shadow/aggregate.js +122 -0
  137. package/dist/_shared/scope-resolution/shadow/aggregate.js.map +1 -0
  138. package/dist/_shared/scope-resolution/shadow/diff.d.ts +59 -0
  139. package/dist/_shared/scope-resolution/shadow/diff.d.ts.map +1 -0
  140. package/dist/_shared/scope-resolution/shadow/diff.js +79 -0
  141. package/dist/_shared/scope-resolution/shadow/diff.js.map +1 -0
  142. package/dist/_shared/scope-resolution/symbol-definition.d.ts +34 -0
  143. package/dist/_shared/scope-resolution/symbol-definition.d.ts.map +1 -0
  144. package/dist/_shared/scope-resolution/symbol-definition.js +12 -0
  145. package/dist/_shared/scope-resolution/symbol-definition.js.map +1 -0
  146. package/dist/_shared/scope-resolution/types.d.ts +400 -0
  147. package/dist/_shared/scope-resolution/types.d.ts.map +1 -0
  148. package/dist/_shared/scope-resolution/types.js +25 -0
  149. package/dist/_shared/scope-resolution/types.js.map +1 -0
  150. package/dist/_shared/test-helpers.d.ts +13 -0
  151. package/dist/_shared/test-helpers.d.ts.map +1 -0
  152. package/dist/_shared/test-helpers.js +13 -0
  153. package/dist/_shared/test-helpers.js.map +1 -0
  154. package/dist/cli/ai-context.d.ts +28 -0
  155. package/dist/cli/ai-context.js +289 -0
  156. package/dist/cli/analyze.d.ts +80 -0
  157. package/dist/cli/analyze.js +525 -0
  158. package/dist/cli/augment.d.ts +13 -0
  159. package/dist/cli/augment.js +33 -0
  160. package/dist/cli/clean.d.ts +10 -0
  161. package/dist/cli/clean.js +79 -0
  162. package/dist/cli/cli-message.d.ts +16 -0
  163. package/dist/cli/cli-message.js +71 -0
  164. package/dist/cli/doctor.d.ts +1 -0
  165. package/dist/cli/doctor.js +31 -0
  166. package/dist/cli/eval-server.d.ts +37 -0
  167. package/dist/cli/eval-server.js +423 -0
  168. package/dist/cli/group.d.ts +1 -0
  169. package/dist/cli/group.js +323 -0
  170. package/dist/cli/index-repo.d.ts +15 -0
  171. package/dist/cli/index-repo.js +120 -0
  172. package/dist/cli/index.d.ts +2 -0
  173. package/dist/cli/index.js +492 -0
  174. package/dist/cli/lazy-action.d.ts +6 -0
  175. package/dist/cli/lazy-action.js +18 -0
  176. package/dist/cli/list.d.ts +6 -0
  177. package/dist/cli/list.js +40 -0
  178. package/dist/cli/mcp.d.ts +29 -0
  179. package/dist/cli/mcp.js +73 -0
  180. package/dist/cli/optional-grammars.d.ts +47 -0
  181. package/dist/cli/optional-grammars.js +87 -0
  182. package/dist/cli/publish.d.ts +29 -0
  183. package/dist/cli/publish.js +174 -0
  184. package/dist/cli/remove.d.ts +30 -0
  185. package/dist/cli/remove.js +102 -0
  186. package/dist/cli/serve.d.ts +4 -0
  187. package/dist/cli/serve.js +55 -0
  188. package/dist/cli/setup.d.ts +8 -0
  189. package/dist/cli/setup.js +642 -0
  190. package/dist/cli/skill-gen.d.ts +26 -0
  191. package/dist/cli/skill-gen.js +555 -0
  192. package/dist/cli/status.d.ts +6 -0
  193. package/dist/cli/status.js +36 -0
  194. package/dist/cli/tool.d.ts +43 -0
  195. package/dist/cli/tool.js +169 -0
  196. package/dist/cli/wiki.d.ts +23 -0
  197. package/dist/cli/wiki.js +616 -0
  198. package/dist/config/ignore-service.d.ts +35 -0
  199. package/dist/config/ignore-service.js +439 -0
  200. package/dist/config/supported-languages.d.ts +13 -0
  201. package/dist/config/supported-languages.js +13 -0
  202. package/dist/core/augmentation/engine.d.ts +26 -0
  203. package/dist/core/augmentation/engine.js +272 -0
  204. package/dist/core/embedding-mode.d.ts +51 -0
  205. package/dist/core/embedding-mode.js +48 -0
  206. package/dist/core/embeddings/ast-utils.d.ts +22 -0
  207. package/dist/core/embeddings/ast-utils.js +106 -0
  208. package/dist/core/embeddings/character-chunk.d.ts +12 -0
  209. package/dist/core/embeddings/character-chunk.js +43 -0
  210. package/dist/core/embeddings/chunker.d.ts +14 -0
  211. package/dist/core/embeddings/chunker.js +239 -0
  212. package/dist/core/embeddings/config.d.ts +2 -0
  213. package/dist/core/embeddings/config.js +36 -0
  214. package/dist/core/embeddings/embedder.d.ts +65 -0
  215. package/dist/core/embeddings/embedder.js +349 -0
  216. package/dist/core/embeddings/embedding-pipeline.d.ts +68 -0
  217. package/dist/core/embeddings/embedding-pipeline.js +552 -0
  218. package/dist/core/embeddings/exact-search.d.ts +15 -0
  219. package/dist/core/embeddings/exact-search.js +27 -0
  220. package/dist/core/embeddings/hf-env.d.ts +135 -0
  221. package/dist/core/embeddings/hf-env.js +232 -0
  222. package/dist/core/embeddings/http-client.d.ts +37 -0
  223. package/dist/core/embeddings/http-client.js +199 -0
  224. package/dist/core/embeddings/index.d.ts +10 -0
  225. package/dist/core/embeddings/index.js +10 -0
  226. package/dist/core/embeddings/line-index.d.ts +7 -0
  227. package/dist/core/embeddings/line-index.js +42 -0
  228. package/dist/core/embeddings/server-mapping.d.ts +15 -0
  229. package/dist/core/embeddings/server-mapping.js +33 -0
  230. package/dist/core/embeddings/structural-extractor.d.ts +15 -0
  231. package/dist/core/embeddings/structural-extractor.js +58 -0
  232. package/dist/core/embeddings/text-generator.d.ts +31 -0
  233. package/dist/core/embeddings/text-generator.js +208 -0
  234. package/dist/core/embeddings/types.d.ts +211 -0
  235. package/dist/core/embeddings/types.js +202 -0
  236. package/dist/core/git-staleness.d.ts +37 -0
  237. package/dist/core/git-staleness.js +167 -0
  238. package/dist/core/graph/graph.d.ts +2 -0
  239. package/dist/core/graph/graph.js +173 -0
  240. package/dist/core/graph/types.d.ts +36 -0
  241. package/dist/core/graph/types.js +1 -0
  242. package/dist/core/group/bridge-db.d.ts +82 -0
  243. package/dist/core/group/bridge-db.js +609 -0
  244. package/dist/core/group/bridge-schema.d.ts +27 -0
  245. package/dist/core/group/bridge-schema.js +55 -0
  246. package/dist/core/group/config-parser.d.ts +7 -0
  247. package/dist/core/group/config-parser.js +122 -0
  248. package/dist/core/group/contract-extractor.d.ts +7 -0
  249. package/dist/core/group/contract-extractor.js +1 -0
  250. package/dist/core/group/cross-impact.d.ts +85 -0
  251. package/dist/core/group/cross-impact.js +515 -0
  252. package/dist/core/group/extractors/elixir-workspace-extractor.d.ts +15 -0
  253. package/dist/core/group/extractors/elixir-workspace-extractor.js +204 -0
  254. package/dist/core/group/extractors/fs-utils.d.ts +10 -0
  255. package/dist/core/group/extractors/fs-utils.js +24 -0
  256. package/dist/core/group/extractors/go-workspace-extractor.d.ts +14 -0
  257. package/dist/core/group/extractors/go-workspace-extractor.js +217 -0
  258. package/dist/core/group/extractors/grpc-extractor.d.ts +25 -0
  259. package/dist/core/group/extractors/grpc-extractor.js +414 -0
  260. package/dist/core/group/extractors/grpc-patterns/go.d.ts +2 -0
  261. package/dist/core/group/extractors/grpc-patterns/go.js +97 -0
  262. package/dist/core/group/extractors/grpc-patterns/index.d.ts +19 -0
  263. package/dist/core/group/extractors/grpc-patterns/index.js +46 -0
  264. package/dist/core/group/extractors/grpc-patterns/java.d.ts +2 -0
  265. package/dist/core/group/extractors/grpc-patterns/java.js +173 -0
  266. package/dist/core/group/extractors/grpc-patterns/node.d.ts +4 -0
  267. package/dist/core/group/extractors/grpc-patterns/node.js +290 -0
  268. package/dist/core/group/extractors/grpc-patterns/proto.d.ts +9 -0
  269. package/dist/core/group/extractors/grpc-patterns/proto.js +134 -0
  270. package/dist/core/group/extractors/grpc-patterns/python.d.ts +2 -0
  271. package/dist/core/group/extractors/grpc-patterns/python.js +67 -0
  272. package/dist/core/group/extractors/grpc-patterns/types.d.ts +50 -0
  273. package/dist/core/group/extractors/grpc-patterns/types.js +1 -0
  274. package/dist/core/group/extractors/http-patterns/go.d.ts +2 -0
  275. package/dist/core/group/extractors/http-patterns/go.js +215 -0
  276. package/dist/core/group/extractors/http-patterns/index.d.ts +17 -0
  277. package/dist/core/group/extractors/http-patterns/index.js +44 -0
  278. package/dist/core/group/extractors/http-patterns/java.d.ts +2 -0
  279. package/dist/core/group/extractors/http-patterns/java.js +253 -0
  280. package/dist/core/group/extractors/http-patterns/node.d.ts +4 -0
  281. package/dist/core/group/extractors/http-patterns/node.js +484 -0
  282. package/dist/core/group/extractors/http-patterns/php.d.ts +2 -0
  283. package/dist/core/group/extractors/http-patterns/php.js +178 -0
  284. package/dist/core/group/extractors/http-patterns/python.d.ts +2 -0
  285. package/dist/core/group/extractors/http-patterns/python.js +308 -0
  286. package/dist/core/group/extractors/http-patterns/types.d.ts +61 -0
  287. package/dist/core/group/extractors/http-patterns/types.js +1 -0
  288. package/dist/core/group/extractors/http-route-extractor.d.ts +21 -0
  289. package/dist/core/group/extractors/http-route-extractor.js +430 -0
  290. package/dist/core/group/extractors/include-extractor.d.ts +39 -0
  291. package/dist/core/group/extractors/include-extractor.js +566 -0
  292. package/dist/core/group/extractors/java-workspace-extractor.d.ts +16 -0
  293. package/dist/core/group/extractors/java-workspace-extractor.js +204 -0
  294. package/dist/core/group/extractors/manifest-extractor.d.ts +54 -0
  295. package/dist/core/group/extractors/manifest-extractor.js +320 -0
  296. package/dist/core/group/extractors/node-workspace-extractor.d.ts +14 -0
  297. package/dist/core/group/extractors/node-workspace-extractor.js +207 -0
  298. package/dist/core/group/extractors/python-workspace-extractor.d.ts +15 -0
  299. package/dist/core/group/extractors/python-workspace-extractor.js +205 -0
  300. package/dist/core/group/extractors/rust-workspace-extractor.d.ts +44 -0
  301. package/dist/core/group/extractors/rust-workspace-extractor.js +240 -0
  302. package/dist/core/group/extractors/thrift-extractor.d.ts +22 -0
  303. package/dist/core/group/extractors/thrift-extractor.js +283 -0
  304. package/dist/core/group/extractors/thrift-patterns/index.d.ts +4 -0
  305. package/dist/core/group/extractors/thrift-patterns/index.js +10 -0
  306. package/dist/core/group/extractors/thrift-patterns/java.d.ts +2 -0
  307. package/dist/core/group/extractors/thrift-patterns/java.js +220 -0
  308. package/dist/core/group/extractors/thrift-patterns/types.d.ts +17 -0
  309. package/dist/core/group/extractors/thrift-patterns/types.js +1 -0
  310. package/dist/core/group/extractors/topic-extractor.d.ts +8 -0
  311. package/dist/core/group/extractors/topic-extractor.js +97 -0
  312. package/dist/core/group/extractors/topic-patterns/go.d.ts +2 -0
  313. package/dist/core/group/extractors/topic-patterns/go.js +120 -0
  314. package/dist/core/group/extractors/topic-patterns/index.d.ts +14 -0
  315. package/dist/core/group/extractors/topic-patterns/index.js +38 -0
  316. package/dist/core/group/extractors/topic-patterns/java.d.ts +2 -0
  317. package/dist/core/group/extractors/topic-patterns/java.js +80 -0
  318. package/dist/core/group/extractors/topic-patterns/node.d.ts +4 -0
  319. package/dist/core/group/extractors/topic-patterns/node.js +155 -0
  320. package/dist/core/group/extractors/topic-patterns/python.d.ts +2 -0
  321. package/dist/core/group/extractors/topic-patterns/python.js +116 -0
  322. package/dist/core/group/extractors/topic-patterns/types.d.ts +25 -0
  323. package/dist/core/group/extractors/topic-patterns/types.js +10 -0
  324. package/dist/core/group/extractors/tree-sitter-scanner.d.ts +113 -0
  325. package/dist/core/group/extractors/tree-sitter-scanner.js +95 -0
  326. package/dist/core/group/extractors/workspace-extractor.d.ts +13 -0
  327. package/dist/core/group/extractors/workspace-extractor.js +65 -0
  328. package/dist/core/group/group-path-utils.d.ts +17 -0
  329. package/dist/core/group/group-path-utils.js +40 -0
  330. package/dist/core/group/matching.d.ts +13 -0
  331. package/dist/core/group/matching.js +284 -0
  332. package/dist/core/group/normalization.d.ts +3 -0
  333. package/dist/core/group/normalization.js +115 -0
  334. package/dist/core/group/resolve-at-member.d.ts +10 -0
  335. package/dist/core/group/resolve-at-member.js +31 -0
  336. package/dist/core/group/service-boundary-detector.d.ts +8 -0
  337. package/dist/core/group/service-boundary-detector.js +155 -0
  338. package/dist/core/group/service.d.ts +56 -0
  339. package/dist/core/group/service.js +395 -0
  340. package/dist/core/group/storage.d.ts +9 -0
  341. package/dist/core/group/storage.js +157 -0
  342. package/dist/core/group/sync.d.ts +21 -0
  343. package/dist/core/group/sync.js +267 -0
  344. package/dist/core/group/types.d.ts +181 -0
  345. package/dist/core/group/types.js +1 -0
  346. package/dist/core/incremental/shadow-candidates.d.ts +44 -0
  347. package/dist/core/incremental/shadow-candidates.js +74 -0
  348. package/dist/core/incremental/subgraph-extract.d.ts +64 -0
  349. package/dist/core/incremental/subgraph-extract.js +111 -0
  350. package/dist/core/ingestion/ast-cache.d.ts +26 -0
  351. package/dist/core/ingestion/ast-cache.js +48 -0
  352. package/dist/core/ingestion/binding-accumulator.d.ts +212 -0
  353. package/dist/core/ingestion/binding-accumulator.js +336 -0
  354. package/dist/core/ingestion/call-extractors/configs/c-cpp.d.ts +3 -0
  355. package/dist/core/ingestion/call-extractors/configs/c-cpp.js +8 -0
  356. package/dist/core/ingestion/call-extractors/configs/csharp.d.ts +2 -0
  357. package/dist/core/ingestion/call-extractors/configs/csharp.js +6 -0
  358. package/dist/core/ingestion/call-extractors/configs/dart.d.ts +2 -0
  359. package/dist/core/ingestion/call-extractors/configs/dart.js +5 -0
  360. package/dist/core/ingestion/call-extractors/configs/go.d.ts +2 -0
  361. package/dist/core/ingestion/call-extractors/configs/go.js +5 -0
  362. package/dist/core/ingestion/call-extractors/configs/jvm.d.ts +3 -0
  363. package/dist/core/ingestion/call-extractors/configs/jvm.js +51 -0
  364. package/dist/core/ingestion/call-extractors/configs/php.d.ts +2 -0
  365. package/dist/core/ingestion/call-extractors/configs/php.js +5 -0
  366. package/dist/core/ingestion/call-extractors/configs/python.d.ts +2 -0
  367. package/dist/core/ingestion/call-extractors/configs/python.js +5 -0
  368. package/dist/core/ingestion/call-extractors/configs/ruby.d.ts +2 -0
  369. package/dist/core/ingestion/call-extractors/configs/ruby.js +5 -0
  370. package/dist/core/ingestion/call-extractors/configs/rust.d.ts +2 -0
  371. package/dist/core/ingestion/call-extractors/configs/rust.js +5 -0
  372. package/dist/core/ingestion/call-extractors/configs/swift.d.ts +2 -0
  373. package/dist/core/ingestion/call-extractors/configs/swift.js +5 -0
  374. package/dist/core/ingestion/call-extractors/configs/typescript-javascript.d.ts +3 -0
  375. package/dist/core/ingestion/call-extractors/configs/typescript-javascript.js +8 -0
  376. package/dist/core/ingestion/call-extractors/generic.d.ts +5 -0
  377. package/dist/core/ingestion/call-extractors/generic.js +59 -0
  378. package/dist/core/ingestion/call-processor.d.ts +235 -0
  379. package/dist/core/ingestion/call-processor.js +2754 -0
  380. package/dist/core/ingestion/call-routing.d.ts +55 -0
  381. package/dist/core/ingestion/call-routing.js +95 -0
  382. package/dist/core/ingestion/call-types.d.ts +135 -0
  383. package/dist/core/ingestion/call-types.js +2 -0
  384. package/dist/core/ingestion/class-extractors/configs/c-cpp.d.ts +3 -0
  385. package/dist/core/ingestion/class-extractors/configs/c-cpp.js +11 -0
  386. package/dist/core/ingestion/class-extractors/configs/csharp.d.ts +2 -0
  387. package/dist/core/ingestion/class-extractors/configs/csharp.js +21 -0
  388. package/dist/core/ingestion/class-extractors/configs/dart.d.ts +2 -0
  389. package/dist/core/ingestion/class-extractors/configs/dart.js +7 -0
  390. package/dist/core/ingestion/class-extractors/configs/go.d.ts +2 -0
  391. package/dist/core/ingestion/class-extractors/configs/go.js +20 -0
  392. package/dist/core/ingestion/class-extractors/configs/jvm.d.ts +3 -0
  393. package/dist/core/ingestion/class-extractors/configs/jvm.js +35 -0
  394. package/dist/core/ingestion/class-extractors/configs/php.d.ts +2 -0
  395. package/dist/core/ingestion/class-extractors/configs/php.js +7 -0
  396. package/dist/core/ingestion/class-extractors/configs/python.d.ts +2 -0
  397. package/dist/core/ingestion/class-extractors/configs/python.js +7 -0
  398. package/dist/core/ingestion/class-extractors/configs/ruby.d.ts +2 -0
  399. package/dist/core/ingestion/class-extractors/configs/ruby.js +7 -0
  400. package/dist/core/ingestion/class-extractors/configs/rust.d.ts +2 -0
  401. package/dist/core/ingestion/class-extractors/configs/rust.js +7 -0
  402. package/dist/core/ingestion/class-extractors/configs/swift.d.ts +2 -0
  403. package/dist/core/ingestion/class-extractors/configs/swift.js +18 -0
  404. package/dist/core/ingestion/class-extractors/configs/typescript-javascript.d.ts +4 -0
  405. package/dist/core/ingestion/class-extractors/configs/typescript-javascript.js +28 -0
  406. package/dist/core/ingestion/class-extractors/generic.d.ts +2 -0
  407. package/dist/core/ingestion/class-extractors/generic.js +135 -0
  408. package/dist/core/ingestion/class-types.d.ts +34 -0
  409. package/dist/core/ingestion/class-types.js +1 -0
  410. package/dist/core/ingestion/cluster-enricher.d.ts +38 -0
  411. package/dist/core/ingestion/cluster-enricher.js +169 -0
  412. package/dist/core/ingestion/cobol/cobol-copy-expander.d.ts +57 -0
  413. package/dist/core/ingestion/cobol/cobol-copy-expander.js +376 -0
  414. package/dist/core/ingestion/cobol/cobol-preprocessor.d.ts +212 -0
  415. package/dist/core/ingestion/cobol/cobol-preprocessor.js +1727 -0
  416. package/dist/core/ingestion/cobol/jcl-parser.d.ts +68 -0
  417. package/dist/core/ingestion/cobol/jcl-parser.js +217 -0
  418. package/dist/core/ingestion/cobol/jcl-processor.d.ts +33 -0
  419. package/dist/core/ingestion/cobol/jcl-processor.js +229 -0
  420. package/dist/core/ingestion/cobol-processor.d.ts +54 -0
  421. package/dist/core/ingestion/cobol-processor.js +1232 -0
  422. package/dist/core/ingestion/community-processor.d.ts +39 -0
  423. package/dist/core/ingestion/community-processor.js +336 -0
  424. package/dist/core/ingestion/constants.d.ts +17 -0
  425. package/dist/core/ingestion/constants.js +21 -0
  426. package/dist/core/ingestion/cpp-ue-preprocessor.d.ts +12 -0
  427. package/dist/core/ingestion/cpp-ue-preprocessor.js +260 -0
  428. package/dist/core/ingestion/emit-references.d.ts +88 -0
  429. package/dist/core/ingestion/emit-references.js +229 -0
  430. package/dist/core/ingestion/entry-point-scoring.d.ts +40 -0
  431. package/dist/core/ingestion/entry-point-scoring.js +196 -0
  432. package/dist/core/ingestion/export-detection.d.ts +57 -0
  433. package/dist/core/ingestion/export-detection.js +233 -0
  434. package/dist/core/ingestion/field-extractor.d.ts +29 -0
  435. package/dist/core/ingestion/field-extractor.js +25 -0
  436. package/dist/core/ingestion/field-extractors/configs/c-cpp.d.ts +3 -0
  437. package/dist/core/ingestion/field-extractors/configs/c-cpp.js +104 -0
  438. package/dist/core/ingestion/field-extractors/configs/csharp.d.ts +8 -0
  439. package/dist/core/ingestion/field-extractors/configs/csharp.js +121 -0
  440. package/dist/core/ingestion/field-extractors/configs/dart.d.ts +8 -0
  441. package/dist/core/ingestion/field-extractors/configs/dart.js +78 -0
  442. package/dist/core/ingestion/field-extractors/configs/go.d.ts +11 -0
  443. package/dist/core/ingestion/field-extractors/configs/go.js +60 -0
  444. package/dist/core/ingestion/field-extractors/configs/helpers.d.ts +53 -0
  445. package/dist/core/ingestion/field-extractors/configs/helpers.js +158 -0
  446. package/dist/core/ingestion/field-extractors/configs/jvm.d.ts +3 -0
  447. package/dist/core/ingestion/field-extractors/configs/jvm.js +118 -0
  448. package/dist/core/ingestion/field-extractors/configs/php.d.ts +8 -0
  449. package/dist/core/ingestion/field-extractors/configs/php.js +65 -0
  450. package/dist/core/ingestion/field-extractors/configs/python.d.ts +12 -0
  451. package/dist/core/ingestion/field-extractors/configs/python.js +91 -0
  452. package/dist/core/ingestion/field-extractors/configs/ruby.d.ts +16 -0
  453. package/dist/core/ingestion/field-extractors/configs/ruby.js +76 -0
  454. package/dist/core/ingestion/field-extractors/configs/rust.d.ts +9 -0
  455. package/dist/core/ingestion/field-extractors/configs/rust.js +52 -0
  456. package/dist/core/ingestion/field-extractors/configs/swift.d.ts +8 -0
  457. package/dist/core/ingestion/field-extractors/configs/swift.js +65 -0
  458. package/dist/core/ingestion/field-extractors/configs/typescript-javascript.d.ts +3 -0
  459. package/dist/core/ingestion/field-extractors/configs/typescript-javascript.js +56 -0
  460. package/dist/core/ingestion/field-extractors/generic.d.ts +49 -0
  461. package/dist/core/ingestion/field-extractors/generic.js +117 -0
  462. package/dist/core/ingestion/field-extractors/typescript.d.ts +77 -0
  463. package/dist/core/ingestion/field-extractors/typescript.js +291 -0
  464. package/dist/core/ingestion/field-types.d.ts +61 -0
  465. package/dist/core/ingestion/field-types.js +2 -0
  466. package/dist/core/ingestion/filesystem-walker.d.ts +28 -0
  467. package/dist/core/ingestion/filesystem-walker.js +92 -0
  468. package/dist/core/ingestion/finalize-orchestrator.d.ts +63 -0
  469. package/dist/core/ingestion/finalize-orchestrator.js +142 -0
  470. package/dist/core/ingestion/framework-detection.d.ts +30 -0
  471. package/dist/core/ingestion/framework-detection.js +428 -0
  472. package/dist/core/ingestion/heritage-extractors/configs/go.d.ts +13 -0
  473. package/dist/core/ingestion/heritage-extractors/configs/go.js +20 -0
  474. package/dist/core/ingestion/heritage-extractors/configs/ruby.d.ts +18 -0
  475. package/dist/core/ingestion/heritage-extractors/configs/ruby.js +65 -0
  476. package/dist/core/ingestion/heritage-extractors/generic.d.ts +23 -0
  477. package/dist/core/ingestion/heritage-extractors/generic.js +47 -0
  478. package/dist/core/ingestion/heritage-processor.d.ts +54 -0
  479. package/dist/core/ingestion/heritage-processor.js +367 -0
  480. package/dist/core/ingestion/heritage-types.d.ts +73 -0
  481. package/dist/core/ingestion/heritage-types.js +2 -0
  482. package/dist/core/ingestion/import-processor.d.ts +23 -0
  483. package/dist/core/ingestion/import-processor.js +377 -0
  484. package/dist/core/ingestion/import-resolvers/configs/c-cpp.d.ts +7 -0
  485. package/dist/core/ingestion/import-resolvers/configs/c-cpp.js +14 -0
  486. package/dist/core/ingestion/import-resolvers/configs/csharp.d.ts +8 -0
  487. package/dist/core/ingestion/import-resolvers/configs/csharp.js +27 -0
  488. package/dist/core/ingestion/import-resolvers/configs/dart.d.ts +17 -0
  489. package/dist/core/ingestion/import-resolvers/configs/dart.js +54 -0
  490. package/dist/core/ingestion/import-resolvers/configs/go.d.ts +8 -0
  491. package/dist/core/ingestion/import-resolvers/configs/go.js +26 -0
  492. package/dist/core/ingestion/import-resolvers/configs/jvm.d.ts +13 -0
  493. package/dist/core/ingestion/import-resolvers/configs/jvm.js +68 -0
  494. package/dist/core/ingestion/import-resolvers/configs/php.d.ts +8 -0
  495. package/dist/core/ingestion/import-resolvers/configs/php.js +15 -0
  496. package/dist/core/ingestion/import-resolvers/configs/python.d.ts +12 -0
  497. package/dist/core/ingestion/import-resolvers/configs/python.js +41 -0
  498. package/dist/core/ingestion/import-resolvers/configs/ruby.d.ts +8 -0
  499. package/dist/core/ingestion/import-resolvers/configs/ruby.js +16 -0
  500. package/dist/core/ingestion/import-resolvers/configs/rust.d.ts +8 -0
  501. package/dist/core/ingestion/import-resolvers/configs/rust.js +54 -0
  502. package/dist/core/ingestion/import-resolvers/configs/swift.d.ts +8 -0
  503. package/dist/core/ingestion/import-resolvers/configs/swift.js +29 -0
  504. package/dist/core/ingestion/import-resolvers/configs/typescript-javascript.d.ts +9 -0
  505. package/dist/core/ingestion/import-resolvers/configs/typescript-javascript.js +23 -0
  506. package/dist/core/ingestion/import-resolvers/csharp.d.ts +18 -0
  507. package/dist/core/ingestion/import-resolvers/csharp.js +115 -0
  508. package/dist/core/ingestion/import-resolvers/go.d.ts +17 -0
  509. package/dist/core/ingestion/import-resolvers/go.js +46 -0
  510. package/dist/core/ingestion/import-resolvers/jvm.d.ts +27 -0
  511. package/dist/core/ingestion/import-resolvers/jvm.js +106 -0
  512. package/dist/core/ingestion/import-resolvers/php.d.ts +24 -0
  513. package/dist/core/ingestion/import-resolvers/php.js +77 -0
  514. package/dist/core/ingestion/import-resolvers/python.d.ts +22 -0
  515. package/dist/core/ingestion/import-resolvers/python.js +72 -0
  516. package/dist/core/ingestion/import-resolvers/resolver-factory.d.ts +24 -0
  517. package/dist/core/ingestion/import-resolvers/resolver-factory.js +33 -0
  518. package/dist/core/ingestion/import-resolvers/ruby.d.ts +14 -0
  519. package/dist/core/ingestion/import-resolvers/ruby.js +17 -0
  520. package/dist/core/ingestion/import-resolvers/rust.d.ts +17 -0
  521. package/dist/core/ingestion/import-resolvers/rust.js +75 -0
  522. package/dist/core/ingestion/import-resolvers/standard.d.ts +35 -0
  523. package/dist/core/ingestion/import-resolvers/standard.js +168 -0
  524. package/dist/core/ingestion/import-resolvers/types.d.ts +68 -0
  525. package/dist/core/ingestion/import-resolvers/types.js +6 -0
  526. package/dist/core/ingestion/import-resolvers/utils.d.ts +35 -0
  527. package/dist/core/ingestion/import-resolvers/utils.js +153 -0
  528. package/dist/core/ingestion/import-target-adapter.d.ts +73 -0
  529. package/dist/core/ingestion/import-target-adapter.js +95 -0
  530. package/dist/core/ingestion/language-config.d.ts +52 -0
  531. package/dist/core/ingestion/language-config.js +182 -0
  532. package/dist/core/ingestion/language-provider.d.ts +465 -0
  533. package/dist/core/ingestion/language-provider.js +24 -0
  534. package/dist/core/ingestion/languages/c/arity-metadata.d.ts +14 -0
  535. package/dist/core/ingestion/languages/c/arity-metadata.js +94 -0
  536. package/dist/core/ingestion/languages/c/arity.d.ts +6 -0
  537. package/dist/core/ingestion/languages/c/arity.js +18 -0
  538. package/dist/core/ingestion/languages/c/captures.d.ts +2 -0
  539. package/dist/core/ingestion/languages/c/captures.js +105 -0
  540. package/dist/core/ingestion/languages/c/header-scan.d.ts +7 -0
  541. package/dist/core/ingestion/languages/c/header-scan.js +55 -0
  542. package/dist/core/ingestion/languages/c/import-decomposer.d.ts +8 -0
  543. package/dist/core/ingestion/languages/c/import-decomposer.js +50 -0
  544. package/dist/core/ingestion/languages/c/import-target.d.ts +14 -0
  545. package/dist/core/ingestion/languages/c/import-target.js +57 -0
  546. package/dist/core/ingestion/languages/c/index.d.ts +11 -0
  547. package/dist/core/ingestion/languages/c/index.js +11 -0
  548. package/dist/core/ingestion/languages/c/interpret.d.ts +14 -0
  549. package/dist/core/ingestion/languages/c/interpret.js +48 -0
  550. package/dist/core/ingestion/languages/c/merge-bindings.d.ts +7 -0
  551. package/dist/core/ingestion/languages/c/merge-bindings.js +23 -0
  552. package/dist/core/ingestion/languages/c/query.d.ts +3 -0
  553. package/dist/core/ingestion/languages/c/query.js +161 -0
  554. package/dist/core/ingestion/languages/c/scope-resolver.d.ts +13 -0
  555. package/dist/core/ingestion/languages/c/scope-resolver.js +60 -0
  556. package/dist/core/ingestion/languages/c/simple-hooks.d.ts +14 -0
  557. package/dist/core/ingestion/languages/c/simple-hooks.js +19 -0
  558. package/dist/core/ingestion/languages/c/static-linkage.d.ts +13 -0
  559. package/dist/core/ingestion/languages/c/static-linkage.js +57 -0
  560. package/dist/core/ingestion/languages/c-cpp.d.ts +12 -0
  561. package/dist/core/ingestion/languages/c-cpp.js +411 -0
  562. package/dist/core/ingestion/languages/cobol.d.ts +1 -0
  563. package/dist/core/ingestion/languages/cobol.js +28 -0
  564. package/dist/core/ingestion/languages/csharp/accessor-unwrap.d.ts +21 -0
  565. package/dist/core/ingestion/languages/csharp/accessor-unwrap.js +56 -0
  566. package/dist/core/ingestion/languages/csharp/arity-metadata.d.ts +26 -0
  567. package/dist/core/ingestion/languages/csharp/arity-metadata.js +46 -0
  568. package/dist/core/ingestion/languages/csharp/arity.d.ts +23 -0
  569. package/dist/core/ingestion/languages/csharp/arity.js +37 -0
  570. package/dist/core/ingestion/languages/csharp/cache-stats.d.ts +15 -0
  571. package/dist/core/ingestion/languages/csharp/cache-stats.js +26 -0
  572. package/dist/core/ingestion/languages/csharp/captures.d.ts +19 -0
  573. package/dist/core/ingestion/languages/csharp/captures.js +346 -0
  574. package/dist/core/ingestion/languages/csharp/import-decomposer.d.ts +19 -0
  575. package/dist/core/ingestion/languages/csharp/import-decomposer.js +93 -0
  576. package/dist/core/ingestion/languages/csharp/import-target.d.ts +25 -0
  577. package/dist/core/ingestion/languages/csharp/import-target.js +123 -0
  578. package/dist/core/ingestion/languages/csharp/index.d.ts +82 -0
  579. package/dist/core/ingestion/languages/csharp/index.js +82 -0
  580. package/dist/core/ingestion/languages/csharp/interpret.d.ts +15 -0
  581. package/dist/core/ingestion/languages/csharp/interpret.js +132 -0
  582. package/dist/core/ingestion/languages/csharp/merge-bindings.d.ts +27 -0
  583. package/dist/core/ingestion/languages/csharp/merge-bindings.js +55 -0
  584. package/dist/core/ingestion/languages/csharp/namespace-siblings.d.ts +51 -0
  585. package/dist/core/ingestion/languages/csharp/namespace-siblings.js +387 -0
  586. package/dist/core/ingestion/languages/csharp/query.d.ts +35 -0
  587. package/dist/core/ingestion/languages/csharp/query.js +521 -0
  588. package/dist/core/ingestion/languages/csharp/receiver-binding.d.ts +31 -0
  589. package/dist/core/ingestion/languages/csharp/receiver-binding.js +135 -0
  590. package/dist/core/ingestion/languages/csharp/scope-resolver.d.ts +10 -0
  591. package/dist/core/ingestion/languages/csharp/scope-resolver.js +63 -0
  592. package/dist/core/ingestion/languages/csharp/simple-hooks.d.ts +53 -0
  593. package/dist/core/ingestion/languages/csharp/simple-hooks.js +76 -0
  594. package/dist/core/ingestion/languages/csharp.d.ts +8 -0
  595. package/dist/core/ingestion/languages/csharp.js +201 -0
  596. package/dist/core/ingestion/languages/dart.d.ts +12 -0
  597. package/dist/core/ingestion/languages/dart.js +138 -0
  598. package/dist/core/ingestion/languages/go/arity-metadata.d.ts +8 -0
  599. package/dist/core/ingestion/languages/go/arity-metadata.js +37 -0
  600. package/dist/core/ingestion/languages/go/arity.d.ts +2 -0
  601. package/dist/core/ingestion/languages/go/arity.js +14 -0
  602. package/dist/core/ingestion/languages/go/cache-stats.d.ts +7 -0
  603. package/dist/core/ingestion/languages/go/cache-stats.js +15 -0
  604. package/dist/core/ingestion/languages/go/captures.d.ts +2 -0
  605. package/dist/core/ingestion/languages/go/captures.js +129 -0
  606. package/dist/core/ingestion/languages/go/expand-wildcards.d.ts +15 -0
  607. package/dist/core/ingestion/languages/go/expand-wildcards.js +93 -0
  608. package/dist/core/ingestion/languages/go/import-decomposer.d.ts +3 -0
  609. package/dist/core/ingestion/languages/go/import-decomposer.js +44 -0
  610. package/dist/core/ingestion/languages/go/import-target.d.ts +21 -0
  611. package/dist/core/ingestion/languages/go/import-target.js +67 -0
  612. package/dist/core/ingestion/languages/go/index.d.ts +17 -0
  613. package/dist/core/ingestion/languages/go/index.js +17 -0
  614. package/dist/core/ingestion/languages/go/interface-impls.d.ts +4 -0
  615. package/dist/core/ingestion/languages/go/interface-impls.js +72 -0
  616. package/dist/core/ingestion/languages/go/interpret.d.ts +11 -0
  617. package/dist/core/ingestion/languages/go/interpret.js +146 -0
  618. package/dist/core/ingestion/languages/go/merge-bindings.d.ts +2 -0
  619. package/dist/core/ingestion/languages/go/merge-bindings.js +18 -0
  620. package/dist/core/ingestion/languages/go/method-owners.d.ts +17 -0
  621. package/dist/core/ingestion/languages/go/method-owners.js +96 -0
  622. package/dist/core/ingestion/languages/go/namespace-mirror.d.ts +15 -0
  623. package/dist/core/ingestion/languages/go/namespace-mirror.js +53 -0
  624. package/dist/core/ingestion/languages/go/package-siblings.d.ts +11 -0
  625. package/dist/core/ingestion/languages/go/package-siblings.js +84 -0
  626. package/dist/core/ingestion/languages/go/query.d.ts +3 -0
  627. package/dist/core/ingestion/languages/go/query.js +207 -0
  628. package/dist/core/ingestion/languages/go/range-binding.d.ts +8 -0
  629. package/dist/core/ingestion/languages/go/range-binding.js +109 -0
  630. package/dist/core/ingestion/languages/go/receiver-binding.d.ts +3 -0
  631. package/dist/core/ingestion/languages/go/receiver-binding.js +21 -0
  632. package/dist/core/ingestion/languages/go/scope-resolver.d.ts +2 -0
  633. package/dist/core/ingestion/languages/go/scope-resolver.js +33 -0
  634. package/dist/core/ingestion/languages/go/simple-hooks.d.ts +4 -0
  635. package/dist/core/ingestion/languages/go/simple-hooks.js +21 -0
  636. package/dist/core/ingestion/languages/go/type-binding.d.ts +3 -0
  637. package/dist/core/ingestion/languages/go/type-binding.js +237 -0
  638. package/dist/core/ingestion/languages/go.d.ts +11 -0
  639. package/dist/core/ingestion/languages/go.js +94 -0
  640. package/dist/core/ingestion/languages/index.d.ts +39 -0
  641. package/dist/core/ingestion/languages/index.js +64 -0
  642. package/dist/core/ingestion/languages/java/arity-metadata.d.ts +18 -0
  643. package/dist/core/ingestion/languages/java/arity-metadata.js +40 -0
  644. package/dist/core/ingestion/languages/java/arity.d.ts +10 -0
  645. package/dist/core/ingestion/languages/java/arity.js +24 -0
  646. package/dist/core/ingestion/languages/java/cache-stats.d.ts +15 -0
  647. package/dist/core/ingestion/languages/java/cache-stats.js +26 -0
  648. package/dist/core/ingestion/languages/java/captures.d.ts +17 -0
  649. package/dist/core/ingestion/languages/java/captures.js +187 -0
  650. package/dist/core/ingestion/languages/java/import-decomposer.d.ts +18 -0
  651. package/dist/core/ingestion/languages/java/import-decomposer.js +85 -0
  652. package/dist/core/ingestion/languages/java/import-target.d.ts +17 -0
  653. package/dist/core/ingestion/languages/java/import-target.js +100 -0
  654. package/dist/core/ingestion/languages/java/index.d.ts +29 -0
  655. package/dist/core/ingestion/languages/java/index.js +29 -0
  656. package/dist/core/ingestion/languages/java/interpret.d.ts +13 -0
  657. package/dist/core/ingestion/languages/java/interpret.js +131 -0
  658. package/dist/core/ingestion/languages/java/merge-bindings.d.ts +12 -0
  659. package/dist/core/ingestion/languages/java/merge-bindings.js +40 -0
  660. package/dist/core/ingestion/languages/java/query.d.ts +30 -0
  661. package/dist/core/ingestion/languages/java/query.js +192 -0
  662. package/dist/core/ingestion/languages/java/receiver-binding.d.ts +11 -0
  663. package/dist/core/ingestion/languages/java/receiver-binding.js +95 -0
  664. package/dist/core/ingestion/languages/java/scope-resolver.d.ts +50 -0
  665. package/dist/core/ingestion/languages/java/scope-resolver.js +74 -0
  666. package/dist/core/ingestion/languages/java/simple-hooks.d.ts +13 -0
  667. package/dist/core/ingestion/languages/java/simple-hooks.js +34 -0
  668. package/dist/core/ingestion/languages/java.d.ts +9 -0
  669. package/dist/core/ingestion/languages/java.js +76 -0
  670. package/dist/core/ingestion/languages/kotlin.d.ts +9 -0
  671. package/dist/core/ingestion/languages/kotlin.js +164 -0
  672. package/dist/core/ingestion/languages/php/arity-metadata.d.ts +28 -0
  673. package/dist/core/ingestion/languages/php/arity-metadata.js +63 -0
  674. package/dist/core/ingestion/languages/php/arity.d.ts +25 -0
  675. package/dist/core/ingestion/languages/php/arity.js +40 -0
  676. package/dist/core/ingestion/languages/php/cache-stats.d.ts +15 -0
  677. package/dist/core/ingestion/languages/php/cache-stats.js +26 -0
  678. package/dist/core/ingestion/languages/php/captures.d.ts +34 -0
  679. package/dist/core/ingestion/languages/php/captures.js +739 -0
  680. package/dist/core/ingestion/languages/php/import-decomposer.d.ts +28 -0
  681. package/dist/core/ingestion/languages/php/import-decomposer.js +265 -0
  682. package/dist/core/ingestion/languages/php/import-target.d.ts +47 -0
  683. package/dist/core/ingestion/languages/php/import-target.js +100 -0
  684. package/dist/core/ingestion/languages/php/index.d.ts +68 -0
  685. package/dist/core/ingestion/languages/php/index.js +72 -0
  686. package/dist/core/ingestion/languages/php/interpret.d.ts +36 -0
  687. package/dist/core/ingestion/languages/php/interpret.js +241 -0
  688. package/dist/core/ingestion/languages/php/merge-bindings.d.ts +19 -0
  689. package/dist/core/ingestion/languages/php/merge-bindings.js +47 -0
  690. package/dist/core/ingestion/languages/php/namespace-siblings.d.ts +51 -0
  691. package/dist/core/ingestion/languages/php/namespace-siblings.js +288 -0
  692. package/dist/core/ingestion/languages/php/query.d.ts +32 -0
  693. package/dist/core/ingestion/languages/php/query.js +326 -0
  694. package/dist/core/ingestion/languages/php/receiver-binding.d.ts +36 -0
  695. package/dist/core/ingestion/languages/php/receiver-binding.js +128 -0
  696. package/dist/core/ingestion/languages/php/scope-resolver.d.ts +23 -0
  697. package/dist/core/ingestion/languages/php/scope-resolver.js +358 -0
  698. package/dist/core/ingestion/languages/php/simple-hooks.d.ts +42 -0
  699. package/dist/core/ingestion/languages/php/simple-hooks.js +111 -0
  700. package/dist/core/ingestion/languages/php.d.ts +1 -0
  701. package/dist/core/ingestion/languages/php.js +290 -0
  702. package/dist/core/ingestion/languages/python/arity-metadata.d.ts +24 -0
  703. package/dist/core/ingestion/languages/python/arity-metadata.js +45 -0
  704. package/dist/core/ingestion/languages/python/arity.d.ts +22 -0
  705. package/dist/core/ingestion/languages/python/arity.js +38 -0
  706. package/dist/core/ingestion/languages/python/cache-stats.d.ts +17 -0
  707. package/dist/core/ingestion/languages/python/cache-stats.js +28 -0
  708. package/dist/core/ingestion/languages/python/captures.d.ts +19 -0
  709. package/dist/core/ingestion/languages/python/captures.js +130 -0
  710. package/dist/core/ingestion/languages/python/import-decomposer.d.ts +15 -0
  711. package/dist/core/ingestion/languages/python/import-decomposer.js +112 -0
  712. package/dist/core/ingestion/languages/python/import-target.d.ts +21 -0
  713. package/dist/core/ingestion/languages/python/import-target.js +195 -0
  714. package/dist/core/ingestion/languages/python/index.d.ts +80 -0
  715. package/dist/core/ingestion/languages/python/index.js +80 -0
  716. package/dist/core/ingestion/languages/python/interpret.d.ts +15 -0
  717. package/dist/core/ingestion/languages/python/interpret.js +191 -0
  718. package/dist/core/ingestion/languages/python/merge-bindings.d.ts +16 -0
  719. package/dist/core/ingestion/languages/python/merge-bindings.js +44 -0
  720. package/dist/core/ingestion/languages/python/query.d.ts +9 -0
  721. package/dist/core/ingestion/languages/python/query.js +267 -0
  722. package/dist/core/ingestion/languages/python/receiver-binding.d.ts +21 -0
  723. package/dist/core/ingestion/languages/python/receiver-binding.js +116 -0
  724. package/dist/core/ingestion/languages/python/scope-resolver.d.ts +16 -0
  725. package/dist/core/ingestion/languages/python/scope-resolver.js +53 -0
  726. package/dist/core/ingestion/languages/python/simple-hooks.d.ts +25 -0
  727. package/dist/core/ingestion/languages/python/simple-hooks.js +43 -0
  728. package/dist/core/ingestion/languages/python.d.ts +12 -0
  729. package/dist/core/ingestion/languages/python.js +133 -0
  730. package/dist/core/ingestion/languages/ruby.d.ts +9 -0
  731. package/dist/core/ingestion/languages/ruby.js +235 -0
  732. package/dist/core/ingestion/languages/rust.d.ts +12 -0
  733. package/dist/core/ingestion/languages/rust.js +167 -0
  734. package/dist/core/ingestion/languages/swift.d.ts +12 -0
  735. package/dist/core/ingestion/languages/swift.js +312 -0
  736. package/dist/core/ingestion/languages/typescript/arity-metadata.d.ts +59 -0
  737. package/dist/core/ingestion/languages/typescript/arity-metadata.js +103 -0
  738. package/dist/core/ingestion/languages/typescript/arity.d.ts +37 -0
  739. package/dist/core/ingestion/languages/typescript/arity.js +54 -0
  740. package/dist/core/ingestion/languages/typescript/cache-stats.d.ts +17 -0
  741. package/dist/core/ingestion/languages/typescript/cache-stats.js +28 -0
  742. package/dist/core/ingestion/languages/typescript/captures.d.ts +28 -0
  743. package/dist/core/ingestion/languages/typescript/captures.js +474 -0
  744. package/dist/core/ingestion/languages/typescript/import-decomposer.d.ts +49 -0
  745. package/dist/core/ingestion/languages/typescript/import-decomposer.js +371 -0
  746. package/dist/core/ingestion/languages/typescript/import-target.d.ts +50 -0
  747. package/dist/core/ingestion/languages/typescript/import-target.js +61 -0
  748. package/dist/core/ingestion/languages/typescript/index.d.ts +94 -0
  749. package/dist/core/ingestion/languages/typescript/index.js +94 -0
  750. package/dist/core/ingestion/languages/typescript/interpret.d.ts +35 -0
  751. package/dist/core/ingestion/languages/typescript/interpret.js +317 -0
  752. package/dist/core/ingestion/languages/typescript/merge-bindings.d.ts +62 -0
  753. package/dist/core/ingestion/languages/typescript/merge-bindings.js +158 -0
  754. package/dist/core/ingestion/languages/typescript/query.d.ts +84 -0
  755. package/dist/core/ingestion/languages/typescript/query.js +978 -0
  756. package/dist/core/ingestion/languages/typescript/receiver-binding.d.ts +59 -0
  757. package/dist/core/ingestion/languages/typescript/receiver-binding.js +171 -0
  758. package/dist/core/ingestion/languages/typescript/scope-resolver.d.ts +16 -0
  759. package/dist/core/ingestion/languages/typescript/scope-resolver.js +113 -0
  760. package/dist/core/ingestion/languages/typescript/simple-hooks.d.ts +71 -0
  761. package/dist/core/ingestion/languages/typescript/simple-hooks.js +131 -0
  762. package/dist/core/ingestion/languages/typescript.d.ts +11 -0
  763. package/dist/core/ingestion/languages/typescript.js +324 -0
  764. package/dist/core/ingestion/languages/vue.d.ts +13 -0
  765. package/dist/core/ingestion/languages/vue.js +79 -0
  766. package/dist/core/ingestion/markdown-processor.d.ts +17 -0
  767. package/dist/core/ingestion/markdown-processor.js +124 -0
  768. package/dist/core/ingestion/method-extractors/configs/c-cpp.d.ts +3 -0
  769. package/dist/core/ingestion/method-extractors/configs/c-cpp.js +387 -0
  770. package/dist/core/ingestion/method-extractors/configs/csharp.d.ts +2 -0
  771. package/dist/core/ingestion/method-extractors/configs/csharp.js +287 -0
  772. package/dist/core/ingestion/method-extractors/configs/dart.d.ts +2 -0
  773. package/dist/core/ingestion/method-extractors/configs/dart.js +376 -0
  774. package/dist/core/ingestion/method-extractors/configs/go.d.ts +2 -0
  775. package/dist/core/ingestion/method-extractors/configs/go.js +176 -0
  776. package/dist/core/ingestion/method-extractors/configs/jvm.d.ts +3 -0
  777. package/dist/core/ingestion/method-extractors/configs/jvm.js +336 -0
  778. package/dist/core/ingestion/method-extractors/configs/php.d.ts +2 -0
  779. package/dist/core/ingestion/method-extractors/configs/php.js +304 -0
  780. package/dist/core/ingestion/method-extractors/configs/python.d.ts +2 -0
  781. package/dist/core/ingestion/method-extractors/configs/python.js +309 -0
  782. package/dist/core/ingestion/method-extractors/configs/ruby.d.ts +2 -0
  783. package/dist/core/ingestion/method-extractors/configs/ruby.js +286 -0
  784. package/dist/core/ingestion/method-extractors/configs/rust.d.ts +2 -0
  785. package/dist/core/ingestion/method-extractors/configs/rust.js +195 -0
  786. package/dist/core/ingestion/method-extractors/configs/swift.d.ts +2 -0
  787. package/dist/core/ingestion/method-extractors/configs/swift.js +276 -0
  788. package/dist/core/ingestion/method-extractors/configs/typescript-javascript.d.ts +3 -0
  789. package/dist/core/ingestion/method-extractors/configs/typescript-javascript.js +338 -0
  790. package/dist/core/ingestion/method-extractors/generic.d.ts +11 -0
  791. package/dist/core/ingestion/method-extractors/generic.js +205 -0
  792. package/dist/core/ingestion/method-types.d.ts +90 -0
  793. package/dist/core/ingestion/method-types.js +2 -0
  794. package/dist/core/ingestion/model/field-registry.d.ts +18 -0
  795. package/dist/core/ingestion/model/field-registry.js +22 -0
  796. package/dist/core/ingestion/model/heritage-map.d.ts +105 -0
  797. package/dist/core/ingestion/model/heritage-map.js +260 -0
  798. package/dist/core/ingestion/model/index.d.ts +20 -0
  799. package/dist/core/ingestion/model/index.js +43 -0
  800. package/dist/core/ingestion/model/method-registry.d.ts +71 -0
  801. package/dist/core/ingestion/model/method-registry.js +134 -0
  802. package/dist/core/ingestion/model/registration-table.d.ts +138 -0
  803. package/dist/core/ingestion/model/registration-table.js +224 -0
  804. package/dist/core/ingestion/model/resolution-context.d.ts +93 -0
  805. package/dist/core/ingestion/model/resolution-context.js +337 -0
  806. package/dist/core/ingestion/model/resolve.d.ts +61 -0
  807. package/dist/core/ingestion/model/resolve.js +401 -0
  808. package/dist/core/ingestion/model/scope-resolution-indexes.d.ts +72 -0
  809. package/dist/core/ingestion/model/scope-resolution-indexes.js +42 -0
  810. package/dist/core/ingestion/model/semantic-model.d.ts +150 -0
  811. package/dist/core/ingestion/model/semantic-model.js +175 -0
  812. package/dist/core/ingestion/model/symbol-table.d.ts +200 -0
  813. package/dist/core/ingestion/model/symbol-table.js +206 -0
  814. package/dist/core/ingestion/model/type-registry.d.ts +39 -0
  815. package/dist/core/ingestion/model/type-registry.js +62 -0
  816. package/dist/core/ingestion/mro-processor.d.ts +46 -0
  817. package/dist/core/ingestion/mro-processor.js +597 -0
  818. package/dist/core/ingestion/named-bindings/csharp.d.ts +3 -0
  819. package/dist/core/ingestion/named-bindings/csharp.js +37 -0
  820. package/dist/core/ingestion/named-bindings/java.d.ts +3 -0
  821. package/dist/core/ingestion/named-bindings/java.js +29 -0
  822. package/dist/core/ingestion/named-bindings/kotlin.d.ts +3 -0
  823. package/dist/core/ingestion/named-bindings/kotlin.js +36 -0
  824. package/dist/core/ingestion/named-bindings/php.d.ts +3 -0
  825. package/dist/core/ingestion/named-bindings/php.js +61 -0
  826. package/dist/core/ingestion/named-bindings/python.d.ts +3 -0
  827. package/dist/core/ingestion/named-bindings/python.js +49 -0
  828. package/dist/core/ingestion/named-bindings/rust.d.ts +3 -0
  829. package/dist/core/ingestion/named-bindings/rust.js +66 -0
  830. package/dist/core/ingestion/named-bindings/types.d.ts +16 -0
  831. package/dist/core/ingestion/named-bindings/types.js +6 -0
  832. package/dist/core/ingestion/named-bindings/typescript.d.ts +3 -0
  833. package/dist/core/ingestion/named-bindings/typescript.js +58 -0
  834. package/dist/core/ingestion/parsing-processor.d.ts +60 -0
  835. package/dist/core/ingestion/parsing-processor.js +627 -0
  836. package/dist/core/ingestion/pipeline-phases/cobol.d.ts +16 -0
  837. package/dist/core/ingestion/pipeline-phases/cobol.js +46 -0
  838. package/dist/core/ingestion/pipeline-phases/communities.d.ts +16 -0
  839. package/dist/core/ingestion/pipeline-phases/communities.js +63 -0
  840. package/dist/core/ingestion/pipeline-phases/cross-file-impl.d.ts +17 -0
  841. package/dist/core/ingestion/pipeline-phases/cross-file-impl.js +157 -0
  842. package/dist/core/ingestion/pipeline-phases/cross-file.d.ts +37 -0
  843. package/dist/core/ingestion/pipeline-phases/cross-file.js +64 -0
  844. package/dist/core/ingestion/pipeline-phases/index.d.ts +22 -0
  845. package/dist/core/ingestion/pipeline-phases/index.js +23 -0
  846. package/dist/core/ingestion/pipeline-phases/markdown.d.ts +17 -0
  847. package/dist/core/ingestion/pipeline-phases/markdown.js +34 -0
  848. package/dist/core/ingestion/pipeline-phases/mro.d.ts +18 -0
  849. package/dist/core/ingestion/pipeline-phases/mro.js +37 -0
  850. package/dist/core/ingestion/pipeline-phases/orm-extraction.d.ts +22 -0
  851. package/dist/core/ingestion/pipeline-phases/orm-extraction.js +92 -0
  852. package/dist/core/ingestion/pipeline-phases/orm.d.ts +15 -0
  853. package/dist/core/ingestion/pipeline-phases/orm.js +75 -0
  854. package/dist/core/ingestion/pipeline-phases/parse-impl.d.ts +63 -0
  855. package/dist/core/ingestion/pipeline-phases/parse-impl.js +567 -0
  856. package/dist/core/ingestion/pipeline-phases/parse.d.ts +88 -0
  857. package/dist/core/ingestion/pipeline-phases/parse.js +33 -0
  858. package/dist/core/ingestion/pipeline-phases/processes.d.ts +16 -0
  859. package/dist/core/ingestion/pipeline-phases/processes.js +149 -0
  860. package/dist/core/ingestion/pipeline-phases/routes.d.ts +21 -0
  861. package/dist/core/ingestion/pipeline-phases/routes.js +244 -0
  862. package/dist/core/ingestion/pipeline-phases/runner.d.ts +22 -0
  863. package/dist/core/ingestion/pipeline-phases/runner.js +204 -0
  864. package/dist/core/ingestion/pipeline-phases/scan.d.ts +21 -0
  865. package/dist/core/ingestion/pipeline-phases/scan.js +46 -0
  866. package/dist/core/ingestion/pipeline-phases/structure.d.ts +27 -0
  867. package/dist/core/ingestion/pipeline-phases/structure.js +35 -0
  868. package/dist/core/ingestion/pipeline-phases/tools.d.ts +21 -0
  869. package/dist/core/ingestion/pipeline-phases/tools.js +86 -0
  870. package/dist/core/ingestion/pipeline-phases/types.d.ts +79 -0
  871. package/dist/core/ingestion/pipeline-phases/types.js +37 -0
  872. package/dist/core/ingestion/pipeline-phases/wildcard-synthesis.d.ts +70 -0
  873. package/dist/core/ingestion/pipeline-phases/wildcard-synthesis.js +312 -0
  874. package/dist/core/ingestion/pipeline.d.ts +49 -0
  875. package/dist/core/ingestion/pipeline.js +89 -0
  876. package/dist/core/ingestion/process-processor.d.ts +51 -0
  877. package/dist/core/ingestion/process-processor.js +318 -0
  878. package/dist/core/ingestion/registry-primary-flag.d.ts +88 -0
  879. package/dist/core/ingestion/registry-primary-flag.js +117 -0
  880. package/dist/core/ingestion/resolve-references.d.ts +63 -0
  881. package/dist/core/ingestion/resolve-references.js +175 -0
  882. package/dist/core/ingestion/route-extractors/expo.d.ts +1 -0
  883. package/dist/core/ingestion/route-extractors/expo.js +36 -0
  884. package/dist/core/ingestion/route-extractors/middleware.d.ts +47 -0
  885. package/dist/core/ingestion/route-extractors/middleware.js +167 -0
  886. package/dist/core/ingestion/route-extractors/nextjs.d.ts +3 -0
  887. package/dist/core/ingestion/route-extractors/nextjs.js +76 -0
  888. package/dist/core/ingestion/route-extractors/php.d.ts +7 -0
  889. package/dist/core/ingestion/route-extractors/php.js +22 -0
  890. package/dist/core/ingestion/route-extractors/response-shapes.d.ts +20 -0
  891. package/dist/core/ingestion/route-extractors/response-shapes.js +294 -0
  892. package/dist/core/ingestion/scope-extractor-bridge.d.ts +35 -0
  893. package/dist/core/ingestion/scope-extractor-bridge.js +49 -0
  894. package/dist/core/ingestion/scope-extractor.d.ts +86 -0
  895. package/dist/core/ingestion/scope-extractor.js +772 -0
  896. package/dist/core/ingestion/scope-resolution/contract/scope-resolver.d.ts +558 -0
  897. package/dist/core/ingestion/scope-resolution/contract/scope-resolver.js +250 -0
  898. package/dist/core/ingestion/scope-resolution/graph-bridge/edges.d.ts +43 -0
  899. package/dist/core/ingestion/scope-resolution/graph-bridge/edges.js +79 -0
  900. package/dist/core/ingestion/scope-resolution/graph-bridge/ids.d.ts +57 -0
  901. package/dist/core/ingestion/scope-resolution/graph-bridge/ids.js +142 -0
  902. package/dist/core/ingestion/scope-resolution/graph-bridge/imports-to-edges.d.ts +17 -0
  903. package/dist/core/ingestion/scope-resolution/graph-bridge/imports-to-edges.js +46 -0
  904. package/dist/core/ingestion/scope-resolution/graph-bridge/method-dispatch.d.ts +19 -0
  905. package/dist/core/ingestion/scope-resolution/graph-bridge/method-dispatch.js +40 -0
  906. package/dist/core/ingestion/scope-resolution/graph-bridge/node-lookup.d.ts +37 -0
  907. package/dist/core/ingestion/scope-resolution/graph-bridge/node-lookup.js +118 -0
  908. package/dist/core/ingestion/scope-resolution/graph-bridge/references-to-edges.d.ts +38 -0
  909. package/dist/core/ingestion/scope-resolution/graph-bridge/references-to-edges.js +73 -0
  910. package/dist/core/ingestion/scope-resolution/passes/compound-receiver.d.ts +42 -0
  911. package/dist/core/ingestion/scope-resolution/passes/compound-receiver.js +467 -0
  912. package/dist/core/ingestion/scope-resolution/passes/free-call-fallback.d.ts +53 -0
  913. package/dist/core/ingestion/scope-resolution/passes/free-call-fallback.js +251 -0
  914. package/dist/core/ingestion/scope-resolution/passes/imported-return-types.d.ts +75 -0
  915. package/dist/core/ingestion/scope-resolution/passes/imported-return-types.js +202 -0
  916. package/dist/core/ingestion/scope-resolution/passes/mro.d.ts +42 -0
  917. package/dist/core/ingestion/scope-resolution/passes/mro.js +102 -0
  918. package/dist/core/ingestion/scope-resolution/passes/overload-narrowing.d.ts +30 -0
  919. package/dist/core/ingestion/scope-resolution/passes/overload-narrowing.js +81 -0
  920. package/dist/core/ingestion/scope-resolution/passes/receiver-bound-calls.d.ts +46 -0
  921. package/dist/core/ingestion/scope-resolution/passes/receiver-bound-calls.js +377 -0
  922. package/dist/core/ingestion/scope-resolution/pipeline/phase.d.ts +47 -0
  923. package/dist/core/ingestion/scope-resolution/pipeline/phase.js +152 -0
  924. package/dist/core/ingestion/scope-resolution/pipeline/reconcile-ownership.d.ts +68 -0
  925. package/dist/core/ingestion/scope-resolution/pipeline/reconcile-ownership.js +125 -0
  926. package/dist/core/ingestion/scope-resolution/pipeline/registry.d.ts +17 -0
  927. package/dist/core/ingestion/scope-resolution/pipeline/registry.js +31 -0
  928. package/dist/core/ingestion/scope-resolution/pipeline/run.d.ts +91 -0
  929. package/dist/core/ingestion/scope-resolution/pipeline/run.js +218 -0
  930. package/dist/core/ingestion/scope-resolution/pipeline/validate-bindings-immutability.d.ts +39 -0
  931. package/dist/core/ingestion/scope-resolution/pipeline/validate-bindings-immutability.js +65 -0
  932. package/dist/core/ingestion/scope-resolution/scope/namespace-targets.d.ts +36 -0
  933. package/dist/core/ingestion/scope-resolution/scope/namespace-targets.js +58 -0
  934. package/dist/core/ingestion/scope-resolution/scope/walkers.d.ts +170 -0
  935. package/dist/core/ingestion/scope-resolution/scope/walkers.js +447 -0
  936. package/dist/core/ingestion/scope-resolution/workspace-index.d.ts +52 -0
  937. package/dist/core/ingestion/scope-resolution/workspace-index.js +61 -0
  938. package/dist/core/ingestion/shadow-harness.d.ts +113 -0
  939. package/dist/core/ingestion/shadow-harness.js +148 -0
  940. package/dist/core/ingestion/structure-processor.d.ts +2 -0
  941. package/dist/core/ingestion/structure-processor.js +36 -0
  942. package/dist/core/ingestion/tree-sitter-queries.d.ts +16 -0
  943. package/dist/core/ingestion/tree-sitter-queries.js +1497 -0
  944. package/dist/core/ingestion/type-env.d.ts +86 -0
  945. package/dist/core/ingestion/type-env.js +1129 -0
  946. package/dist/core/ingestion/type-extractors/c-cpp.d.ts +7 -0
  947. package/dist/core/ingestion/type-extractors/c-cpp.js +532 -0
  948. package/dist/core/ingestion/type-extractors/csharp.d.ts +2 -0
  949. package/dist/core/ingestion/type-extractors/csharp.js +583 -0
  950. package/dist/core/ingestion/type-extractors/dart.d.ts +15 -0
  951. package/dist/core/ingestion/type-extractors/dart.js +369 -0
  952. package/dist/core/ingestion/type-extractors/go.d.ts +2 -0
  953. package/dist/core/ingestion/type-extractors/go.js +513 -0
  954. package/dist/core/ingestion/type-extractors/jvm.d.ts +3 -0
  955. package/dist/core/ingestion/type-extractors/jvm.js +856 -0
  956. package/dist/core/ingestion/type-extractors/php.d.ts +2 -0
  957. package/dist/core/ingestion/type-extractors/php.js +534 -0
  958. package/dist/core/ingestion/type-extractors/python.d.ts +2 -0
  959. package/dist/core/ingestion/type-extractors/python.js +474 -0
  960. package/dist/core/ingestion/type-extractors/ruby.d.ts +2 -0
  961. package/dist/core/ingestion/type-extractors/ruby.js +377 -0
  962. package/dist/core/ingestion/type-extractors/rust.d.ts +2 -0
  963. package/dist/core/ingestion/type-extractors/rust.js +515 -0
  964. package/dist/core/ingestion/type-extractors/shared.d.ts +131 -0
  965. package/dist/core/ingestion/type-extractors/shared.js +796 -0
  966. package/dist/core/ingestion/type-extractors/swift.d.ts +2 -0
  967. package/dist/core/ingestion/type-extractors/swift.js +487 -0
  968. package/dist/core/ingestion/type-extractors/types.d.ts +172 -0
  969. package/dist/core/ingestion/type-extractors/types.js +1 -0
  970. package/dist/core/ingestion/type-extractors/typescript.d.ts +2 -0
  971. package/dist/core/ingestion/type-extractors/typescript.js +661 -0
  972. package/dist/core/ingestion/utils/ast-helpers.d.ts +102 -0
  973. package/dist/core/ingestion/utils/ast-helpers.js +561 -0
  974. package/dist/core/ingestion/utils/call-analysis.d.ts +75 -0
  975. package/dist/core/ingestion/utils/call-analysis.js +574 -0
  976. package/dist/core/ingestion/utils/env.d.ts +20 -0
  977. package/dist/core/ingestion/utils/env.js +24 -0
  978. package/dist/core/ingestion/utils/event-loop.d.ts +5 -0
  979. package/dist/core/ingestion/utils/event-loop.js +5 -0
  980. package/dist/core/ingestion/utils/graph-sort.d.ts +58 -0
  981. package/dist/core/ingestion/utils/graph-sort.js +100 -0
  982. package/dist/core/ingestion/utils/max-file-size.d.ts +20 -0
  983. package/dist/core/ingestion/utils/max-file-size.js +53 -0
  984. package/dist/core/ingestion/utils/method-props.d.ts +32 -0
  985. package/dist/core/ingestion/utils/method-props.js +147 -0
  986. package/dist/core/ingestion/utils/ruby-self-call.d.ts +52 -0
  987. package/dist/core/ingestion/utils/ruby-self-call.js +59 -0
  988. package/dist/core/ingestion/utils/verbose.d.ts +1 -0
  989. package/dist/core/ingestion/utils/verbose.js +7 -0
  990. package/dist/core/ingestion/variable-extractors/configs/c-cpp.d.ts +3 -0
  991. package/dist/core/ingestion/variable-extractors/configs/c-cpp.js +81 -0
  992. package/dist/core/ingestion/variable-extractors/configs/csharp.d.ts +9 -0
  993. package/dist/core/ingestion/variable-extractors/configs/csharp.js +63 -0
  994. package/dist/core/ingestion/variable-extractors/configs/dart.d.ts +2 -0
  995. package/dist/core/ingestion/variable-extractors/configs/dart.js +94 -0
  996. package/dist/core/ingestion/variable-extractors/configs/go.d.ts +2 -0
  997. package/dist/core/ingestion/variable-extractors/configs/go.js +83 -0
  998. package/dist/core/ingestion/variable-extractors/configs/jvm.d.ts +18 -0
  999. package/dist/core/ingestion/variable-extractors/configs/jvm.js +115 -0
  1000. package/dist/core/ingestion/variable-extractors/configs/php.d.ts +14 -0
  1001. package/dist/core/ingestion/variable-extractors/configs/php.js +58 -0
  1002. package/dist/core/ingestion/variable-extractors/configs/python.d.ts +2 -0
  1003. package/dist/core/ingestion/variable-extractors/configs/python.js +101 -0
  1004. package/dist/core/ingestion/variable-extractors/configs/ruby.d.ts +11 -0
  1005. package/dist/core/ingestion/variable-extractors/configs/ruby.js +52 -0
  1006. package/dist/core/ingestion/variable-extractors/configs/rust.d.ts +2 -0
  1007. package/dist/core/ingestion/variable-extractors/configs/rust.js +76 -0
  1008. package/dist/core/ingestion/variable-extractors/configs/swift.d.ts +2 -0
  1009. package/dist/core/ingestion/variable-extractors/configs/swift.js +88 -0
  1010. package/dist/core/ingestion/variable-extractors/configs/typescript-javascript.d.ts +3 -0
  1011. package/dist/core/ingestion/variable-extractors/configs/typescript-javascript.js +83 -0
  1012. package/dist/core/ingestion/variable-extractors/generic.d.ts +5 -0
  1013. package/dist/core/ingestion/variable-extractors/generic.js +80 -0
  1014. package/dist/core/ingestion/variable-types.d.ts +82 -0
  1015. package/dist/core/ingestion/variable-types.js +2 -0
  1016. package/dist/core/ingestion/vue-sfc-extractor.d.ts +44 -0
  1017. package/dist/core/ingestion/vue-sfc-extractor.js +111 -0
  1018. package/dist/core/ingestion/workers/parse-worker.d.ts +199 -0
  1019. package/dist/core/ingestion/workers/parse-worker.js +1940 -0
  1020. package/dist/core/ingestion/workers/worker-pool.d.ts +23 -0
  1021. package/dist/core/ingestion/workers/worker-pool.js +380 -0
  1022. package/dist/core/lbug/csv-generator.d.ts +33 -0
  1023. package/dist/core/lbug/csv-generator.js +463 -0
  1024. package/dist/core/lbug/extension-loader.d.ts +86 -0
  1025. package/dist/core/lbug/extension-loader.js +186 -0
  1026. package/dist/core/lbug/lbug-adapter.d.ts +243 -0
  1027. package/dist/core/lbug/lbug-adapter.js +1377 -0
  1028. package/dist/core/lbug/lbug-config.d.ts +102 -0
  1029. package/dist/core/lbug/lbug-config.js +303 -0
  1030. package/dist/core/lbug/pool-adapter.d.ts +90 -0
  1031. package/dist/core/lbug/pool-adapter.js +592 -0
  1032. package/dist/core/lbug/schema.d.ts +62 -0
  1033. package/dist/core/lbug/schema.js +495 -0
  1034. package/dist/core/logger.d.ts +125 -0
  1035. package/dist/core/logger.js +323 -0
  1036. package/dist/core/platform/capabilities.d.ts +24 -0
  1037. package/dist/core/platform/capabilities.js +54 -0
  1038. package/dist/core/run-analyze.d.ts +92 -0
  1039. package/dist/core/run-analyze.js +672 -0
  1040. package/dist/core/search/bm25-index.d.ts +29 -0
  1041. package/dist/core/search/bm25-index.js +118 -0
  1042. package/dist/core/search/fts-indexes.d.ts +1 -0
  1043. package/dist/core/search/fts-indexes.js +7 -0
  1044. package/dist/core/search/fts-schema.d.ts +6 -0
  1045. package/dist/core/search/fts-schema.js +7 -0
  1046. package/dist/core/search/hybrid-search.d.ts +53 -0
  1047. package/dist/core/search/hybrid-search.js +136 -0
  1048. package/dist/core/search/phase-timer.d.ts +72 -0
  1049. package/dist/core/search/phase-timer.js +106 -0
  1050. package/dist/core/tree-sitter/parser-loader.d.ts +8 -0
  1051. package/dist/core/tree-sitter/parser-loader.js +189 -0
  1052. package/dist/core/tree-sitter/safe-parse.d.ts +6 -0
  1053. package/dist/core/tree-sitter/safe-parse.js +32 -0
  1054. package/dist/core/wiki/cursor-client.d.ts +31 -0
  1055. package/dist/core/wiki/cursor-client.js +123 -0
  1056. package/dist/core/wiki/generator.d.ts +129 -0
  1057. package/dist/core/wiki/generator.js +899 -0
  1058. package/dist/core/wiki/graph-queries.d.ts +84 -0
  1059. package/dist/core/wiki/graph-queries.js +244 -0
  1060. package/dist/core/wiki/html-viewer.d.ts +10 -0
  1061. package/dist/core/wiki/html-viewer.js +304 -0
  1062. package/dist/core/wiki/llm-client.d.ts +83 -0
  1063. package/dist/core/wiki/llm-client.js +267 -0
  1064. package/dist/core/wiki/mermaid-sanitizer.d.ts +2 -0
  1065. package/dist/core/wiki/mermaid-sanitizer.js +100 -0
  1066. package/dist/core/wiki/prompts.d.ts +53 -0
  1067. package/dist/core/wiki/prompts.js +181 -0
  1068. package/dist/lib/utils.d.ts +1 -0
  1069. package/dist/lib/utils.js +3 -0
  1070. package/dist/mcp/compatible-stdio-transport.d.ts +25 -0
  1071. package/dist/mcp/compatible-stdio-transport.js +206 -0
  1072. package/dist/mcp/core/embedder.d.ts +27 -0
  1073. package/dist/mcp/core/embedder.js +145 -0
  1074. package/dist/mcp/core/lbug-adapter.d.ts +11 -0
  1075. package/dist/mcp/core/lbug-adapter.js +11 -0
  1076. package/dist/mcp/local/local-backend.d.ts +356 -0
  1077. package/dist/mcp/local/local-backend.js +3251 -0
  1078. package/dist/mcp/resources.d.ts +62 -0
  1079. package/dist/mcp/resources.js +512 -0
  1080. package/dist/mcp/server.d.ts +23 -0
  1081. package/dist/mcp/server.js +314 -0
  1082. package/dist/mcp/staleness.d.ts +5 -0
  1083. package/dist/mcp/staleness.js +4 -0
  1084. package/dist/mcp/stdio-capture.d.ts +40 -0
  1085. package/dist/mcp/stdio-capture.js +53 -0
  1086. package/dist/mcp/stdio-context.d.ts +47 -0
  1087. package/dist/mcp/stdio-context.js +145 -0
  1088. package/dist/mcp/tools.d.ts +29 -0
  1089. package/dist/mcp/tools.js +506 -0
  1090. package/dist/server/analyze-job.d.ts +55 -0
  1091. package/dist/server/analyze-job.js +150 -0
  1092. package/dist/server/analyze-worker.d.ts +13 -0
  1093. package/dist/server/analyze-worker.js +59 -0
  1094. package/dist/server/api.d.ts +72 -0
  1095. package/dist/server/api.js +1638 -0
  1096. package/dist/server/git-clone.d.ts +99 -0
  1097. package/dist/server/git-clone.js +397 -0
  1098. package/dist/server/mcp-http.d.ts +13 -0
  1099. package/dist/server/mcp-http.js +101 -0
  1100. package/dist/server/validation.d.ts +98 -0
  1101. package/dist/server/validation.js +142 -0
  1102. package/dist/storage/file-hash.d.ts +47 -0
  1103. package/dist/storage/file-hash.js +86 -0
  1104. package/dist/storage/git.d.ts +148 -0
  1105. package/dist/storage/git.js +346 -0
  1106. package/dist/storage/parse-cache.d.ts +67 -0
  1107. package/dist/storage/parse-cache.js +182 -0
  1108. package/dist/storage/repo-manager.d.ts +467 -0
  1109. package/dist/storage/repo-manager.js +804 -0
  1110. package/dist/types/pipeline.d.ts +18 -0
  1111. package/dist/types/pipeline.js +1 -0
  1112. package/hooks/claude/arc-hook.cjs +334 -0
  1113. package/hooks/claude/hook-lock.cjs +119 -0
  1114. package/hooks/claude/pre-tool-use.sh +79 -0
  1115. package/hooks/claude/session-start.sh +42 -0
  1116. package/package.json +122 -0
  1117. package/scripts/bench-scope-resolution.ts +134 -0
  1118. package/scripts/build-tree-sitter-dart.cjs +53 -0
  1119. package/scripts/build-tree-sitter-proto.cjs +93 -0
  1120. package/scripts/build.js +99 -0
  1121. package/scripts/ci-list-migrated-languages.ts +24 -0
  1122. package/scripts/install-duckdb-extension.mjs +48 -0
  1123. package/skills/arc-cli.md +83 -0
  1124. package/skills/arc-debugging.md +89 -0
  1125. package/skills/arc-exploring.md +78 -0
  1126. package/skills/arc-guide.md +64 -0
  1127. package/skills/arc-impact-analysis.md +97 -0
  1128. package/skills/arc-pr-review.md +163 -0
  1129. package/skills/arc-refactoring.md +121 -0
  1130. package/vendor/leiden/index.cjs +355 -0
  1131. package/vendor/leiden/utils.cjs +392 -0
  1132. package/vendor/tree-sitter-dart/README.md +18 -0
  1133. package/vendor/tree-sitter-dart/binding.gyp +31 -0
  1134. package/vendor/tree-sitter-dart/bindings/node/binding.cc +20 -0
  1135. package/vendor/tree-sitter-dart/bindings/node/index.d.ts +28 -0
  1136. package/vendor/tree-sitter-dart/bindings/node/index.js +7 -0
  1137. package/vendor/tree-sitter-dart/grammar.js +2895 -0
  1138. package/vendor/tree-sitter-dart/package.json +18 -0
  1139. package/vendor/tree-sitter-dart/queries/highlights.scm +246 -0
  1140. package/vendor/tree-sitter-dart/queries/tags.scm +92 -0
  1141. package/vendor/tree-sitter-dart/queries/test.scm +1 -0
  1142. package/vendor/tree-sitter-dart/src/grammar.json +12459 -0
  1143. package/vendor/tree-sitter-dart/src/node-types.json +15055 -0
  1144. package/vendor/tree-sitter-dart/src/parser.c +196127 -0
  1145. package/vendor/tree-sitter-dart/src/scanner.c +130 -0
  1146. package/vendor/tree-sitter-dart/src/tree_sitter/alloc.h +54 -0
  1147. package/vendor/tree-sitter-dart/src/tree_sitter/array.h +290 -0
  1148. package/vendor/tree-sitter-dart/src/tree_sitter/parser.h +265 -0
  1149. package/vendor/tree-sitter-proto/binding.gyp +30 -0
  1150. package/vendor/tree-sitter-proto/bindings/node/binding.cc +20 -0
  1151. package/vendor/tree-sitter-proto/bindings/node/index.d.ts +28 -0
  1152. package/vendor/tree-sitter-proto/bindings/node/index.js +7 -0
  1153. package/vendor/tree-sitter-proto/package.json +12 -0
  1154. package/vendor/tree-sitter-proto/src/node-types.json +1145 -0
  1155. package/vendor/tree-sitter-proto/src/parser.c +10149 -0
  1156. package/vendor/tree-sitter-proto/src/tree_sitter/alloc.h +54 -0
  1157. package/vendor/tree-sitter-proto/src/tree_sitter/array.h +291 -0
  1158. package/vendor/tree-sitter-proto/src/tree_sitter/parser.h +266 -0
  1159. package/vendor/tree-sitter-swift/LICENSE +21 -0
  1160. package/vendor/tree-sitter-swift/README.md +139 -0
  1161. package/vendor/tree-sitter-swift/bindings/node/index.d.ts +28 -0
  1162. package/vendor/tree-sitter-swift/bindings/node/index.js +7 -0
  1163. package/vendor/tree-sitter-swift/package.json +28 -0
  1164. package/vendor/tree-sitter-swift/prebuilds/darwin-arm64/tree-sitter-swift.node +0 -0
  1165. package/vendor/tree-sitter-swift/prebuilds/darwin-x64/tree-sitter-swift.node +0 -0
  1166. package/vendor/tree-sitter-swift/prebuilds/linux-arm64/tree-sitter-swift.node +0 -0
  1167. package/vendor/tree-sitter-swift/prebuilds/linux-x64/tree-sitter-swift.node +0 -0
  1168. package/vendor/tree-sitter-swift/prebuilds/win32-arm64/tree-sitter-swift.node +0 -0
  1169. package/vendor/tree-sitter-swift/prebuilds/win32-x64/tree-sitter-swift.node +0 -0
  1170. package/vendor/tree-sitter-swift/src/node-types.json +30694 -0
  1171. package/web/assets/__vite-browser-external-CLwMvL_q.js +1 -0
  1172. package/web/assets/agent-DaYmiVrk.js +601 -0
  1173. package/web/assets/architecture-7EHR7CIX-6QZW5X65-aGTGQQQG.js +1 -0
  1174. package/web/assets/architectureDiagram-UL44E2DR-613o-OfM.js +36 -0
  1175. package/web/assets/blockDiagram-7IZFK4PR-BBJRt4vF.js +132 -0
  1176. package/web/assets/c4Diagram-Y2BXMSZH-BhR2CErx.js +10 -0
  1177. package/web/assets/chunk-3SSMPTDK-DWfEAoKy.js +321 -0
  1178. package/web/assets/chunk-6764PJDD-NOXEgi3n.js +1 -0
  1179. package/web/assets/chunk-AZZRMDJM-DVvcxwI7.js +15 -0
  1180. package/web/assets/chunk-JQRUD6KW-CQgkrimK.js +1 -0
  1181. package/web/assets/chunk-KGYTTC2M-DxOdSoAJ.js +161 -0
  1182. package/web/assets/chunk-KRXBNO2N-BlnQTnxv.js +1 -0
  1183. package/web/assets/chunk-LCXTWHL2-Dhf_u-1F.js +231 -0
  1184. package/web/assets/chunk-LII3EMHJ-Cb3HLCZX.js +1 -0
  1185. package/web/assets/chunk-RG4AUYOV-DLCfNede.js +206 -0
  1186. package/web/assets/chunk-T5OCTHI4-B0CGAG7q.js +1 -0
  1187. package/web/assets/chunk-W44A43WB-ZyrAMwtT.js +1 -0
  1188. package/web/assets/chunk-ZXARS5L4-B0TJPmj5.js +1 -0
  1189. package/web/assets/classDiagram-KGZ6W3CR-CvSnsfJD.js +1 -0
  1190. package/web/assets/classDiagram-v2-72OJOZXJ-CvSnsfJD.js +1 -0
  1191. package/web/assets/context-builder-BREgwful.js +15 -0
  1192. package/web/assets/cose-bilkent-UX7MHV2Q-BsPIaeag.js +1 -0
  1193. package/web/assets/dagre-ND4H6XIP-CV4l9vOZ.js +4 -0
  1194. package/web/assets/diagram-3NCE3AQN-9kSzEbS8.js +43 -0
  1195. package/web/assets/diagram-GF46GFSD-qRvqbex6.js +24 -0
  1196. package/web/assets/diagram-HNR7UZ2L-Dj_ye4Ua.js +3 -0
  1197. package/web/assets/diagram-QXG6HAR7-COwBV6B0.js +24 -0
  1198. package/web/assets/diagram-WEQXMOUZ-C9xjn5dU.js +10 -0
  1199. package/web/assets/erDiagram-L5TCEMPS-fRp0t1Yd.js +85 -0
  1200. package/web/assets/eventmodeling-FCH6USID-MREXMVOE-BR0Ygfrw.js +1 -0
  1201. package/web/assets/flowDiagram-H6V6AXG4-Ccr8FDLD.js +162 -0
  1202. package/web/assets/ganttDiagram-JCBTUEKG-DfBPqAGN.js +292 -0
  1203. package/web/assets/gitGraph-WXDBUCRP-R675I2BI-CYihBz6Z.js +1 -0
  1204. package/web/assets/gitGraphDiagram-S2ZK5IYY-CHvG_UQ0.js +106 -0
  1205. package/web/assets/index-B7cw1L6-.css +2 -0
  1206. package/web/assets/index-CJJQgfSH.js +886 -0
  1207. package/web/assets/info-J43DQDTF-KCYPFFUO-BmmoeX4D.js +1 -0
  1208. package/web/assets/infoDiagram-3YFTVSEB-C7cMy-GP.js +2 -0
  1209. package/web/assets/ishikawaDiagram-BNXS4ZKH-C80yCPYi.js +70 -0
  1210. package/web/assets/journeyDiagram-M6C3CM3L-BHxH1zjE.js +139 -0
  1211. package/web/assets/kanban-definition-75IXJCU3-DNZo1hOE.js +89 -0
  1212. package/web/assets/katex-K3KEBU37-CbyuvTf1.js +261 -0
  1213. package/web/assets/mindmap-definition-2TDM6QVE-Dpgl3Elt.js +96 -0
  1214. package/web/assets/packet-YPE3B663-LP52Z2RK-7JAqDnUy.js +1 -0
  1215. package/web/assets/pie-LRSECV5Y-TCRJHUBD-Bv9vE7io.js +1 -0
  1216. package/web/assets/pieDiagram-CU6KROY3-BW0mr0ek.js +30 -0
  1217. package/web/assets/quadrantDiagram-VICAPDV7-C1dCMBbk.js +7 -0
  1218. package/web/assets/radar-GUYGQ44K-RDLRG3WG-dtZpcOZd.js +1 -0
  1219. package/web/assets/requirementDiagram-JXO7QTGE-Dyqqny4j.js +84 -0
  1220. package/web/assets/sankeyDiagram-URQDO5SZ-B3FGr5SL.js +40 -0
  1221. package/web/assets/sequenceDiagram-VS2MUI6T-B4LlGP9C.js +162 -0
  1222. package/web/assets/stateDiagram-7D4R322I-V9F-klBP.js +1 -0
  1223. package/web/assets/stateDiagram-v2-36443NZ5-CKDYYzqR.js +1 -0
  1224. package/web/assets/timeline-definition-O6YCAMPW-CX2WjkZA.js +120 -0
  1225. package/web/assets/treeView-BLDUP644-QA4HXRO3-BQaKTdhr.js +1 -0
  1226. package/web/assets/treemap-LRROVOQU-LLAWBHMP-Bqlxdyrq.js +1 -0
  1227. package/web/assets/vennDiagram-MWXL3ELB-BxZPYqOF.js +34 -0
  1228. package/web/assets/wardley-L42UT6IY-5TKZOOLJ-dofeprUr.js +1 -0
  1229. package/web/assets/wardleyDiagram-CUQ6CDDI-BLdJJYkV.js +78 -0
  1230. package/web/assets/xychartDiagram-N2JHSOCM-DqDgigLa.js +7 -0
  1231. package/web/index.html +19 -0
@@ -0,0 +1,1377 @@
1
+ import fs from 'fs/promises';
2
+ import { createReadStream, createWriteStream } from 'fs';
3
+ import { createInterface } from 'readline';
4
+ import { once } from 'events';
5
+ import { finished } from 'stream/promises';
6
+ import path from 'path';
7
+ import lbug from '@ladybugdb/core';
8
+ import { NODE_TABLES, REL_TABLE_NAME, SCHEMA_QUERIES, EMBEDDING_TABLE_NAME, STALE_HASH_SENTINEL, } from './schema.js';
9
+ import { streamAllCSVsToDisk } from './csv-generator.js';
10
+ import { extensionManager } from './extension-loader.js';
11
+ import { closeLbugConnection, isDbBusyError, isOpenRetryExhausted, openLbugConnection, waitForWindowsHandleRelease, } from './lbug-config.js';
12
+ import { isVectorExtensionSupportedByPlatform } from '../platform/capabilities.js';
13
+ import { logger } from '../logger.js';
14
+ /**
15
+ * Split a relationship CSV into per-label-pair files on disk.
16
+ *
17
+ * Streams the CSV line-by-line, routing each relationship to a file named
18
+ * `rel_{fromLabel}_{toLabel}.csv`. Handles backpressure correctly: only one
19
+ * drain listener per stream at a time, and readline resumes only when ALL
20
+ * backpressured streams have drained.
21
+ *
22
+ * @param csvPath Path to the combined relationship CSV
23
+ * @param csvDir Directory to write per-pair CSV files
24
+ * @param validTables Set of valid node table names
25
+ * @param getNodeLabel Function to extract the label from a node ID
26
+ * @param wsFactory Optional WriteStream factory (defaults to fs.createWriteStream)
27
+ */
28
+ export const splitRelCsvByLabelPair = async (csvPath, csvDir, validTables, getNodeLabel, wsFactory = (p) => createWriteStream(p, 'utf-8')) => {
29
+ let relHeader = '';
30
+ const relsByPairMeta = new Map();
31
+ const pairWriteStreams = new Map();
32
+ let skippedRels = 0;
33
+ let totalValidRels = 0;
34
+ const inputStream = createReadStream(csvPath, 'utf-8');
35
+ const rl = createInterface({ input: inputStream, crlfDelay: Infinity });
36
+ // If any pair WriteStream errors (disk full, EMFILE, etc.) or the input
37
+ // stream fails, we need to abort the pending `once(ws, 'drain')` await.
38
+ // An AbortController gives us one signal to cancel all pending waits
39
+ // without a custom state machine.
40
+ const abortOnError = new AbortController();
41
+ let streamError = null;
42
+ const markStreamError = (err) => {
43
+ streamError ??= err;
44
+ abortOnError.abort(err);
45
+ };
46
+ try {
47
+ // `for await (const line of rl)` replaces the old manual
48
+ // on('line')/pause()/resume()/waitingForDrain state machine: readline's
49
+ // async iterator naturally serializes line delivery with our awaits, so
50
+ // at most one ws can be in backpressure at a time and we just await its
51
+ // 'drain' event.
52
+ let isFirst = true;
53
+ for await (const line of rl) {
54
+ if (streamError)
55
+ throw streamError;
56
+ if (isFirst) {
57
+ relHeader = line;
58
+ isFirst = false;
59
+ continue;
60
+ }
61
+ if (!line.trim())
62
+ continue;
63
+ const match = line.match(/"([^"]*)","([^"]*)"/);
64
+ if (!match) {
65
+ skippedRels++;
66
+ continue;
67
+ }
68
+ const fromLabel = getNodeLabel(match[1]);
69
+ const toLabel = getNodeLabel(match[2]);
70
+ if (!validTables.has(fromLabel) || !validTables.has(toLabel)) {
71
+ skippedRels++;
72
+ continue;
73
+ }
74
+ const pairKey = `${fromLabel}|${toLabel}`;
75
+ let ws = pairWriteStreams.get(pairKey);
76
+ if (!ws) {
77
+ const pairCsvPath = path.join(csvDir, `rel_${fromLabel}_${toLabel}.csv`);
78
+ ws = wsFactory(pairCsvPath);
79
+ ws.on('error', markStreamError);
80
+ pairWriteStreams.set(pairKey, ws);
81
+ relsByPairMeta.set(pairKey, { csvPath: pairCsvPath, rows: 0 });
82
+ if (!ws.write(relHeader + '\n')) {
83
+ await once(ws, 'drain', { signal: abortOnError.signal });
84
+ }
85
+ }
86
+ if (!ws.write(line + '\n')) {
87
+ await once(ws, 'drain', { signal: abortOnError.signal });
88
+ }
89
+ relsByPairMeta.get(pairKey).rows++;
90
+ totalValidRels++;
91
+ }
92
+ if (streamError)
93
+ throw streamError;
94
+ }
95
+ catch (err) {
96
+ // Tear down everything so no fd is left dangling. If the abort was caused
97
+ // by a stream error, rethrow that error (more actionable than AbortError).
98
+ for (const ws of pairWriteStreams.values())
99
+ ws.destroy();
100
+ inputStream.destroy();
101
+ throw streamError ?? err;
102
+ }
103
+ finally {
104
+ // Readline 'close' fires before the underlying fs.ReadStream releases its
105
+ // fd — on Windows that race caused ENOTEMPTY on the parent dir.
106
+ // stream/promises.finished is the stdlib "wait until this stream is fully
107
+ // closed" primitive and handles both success and error paths.
108
+ await finished(inputStream).catch(() => { });
109
+ }
110
+ return { relHeader, relsByPairMeta, pairWriteStreams, skippedRels, totalValidRels };
111
+ };
112
+ let db = null;
113
+ let conn = null;
114
+ let currentDbPath = null;
115
+ let ftsLoaded = false;
116
+ let vectorExtensionLoaded = false;
117
+ /**
118
+ * In-process cache of FTS indexes observed against the current singleton
119
+ * connection. Avoids repeated `CALL CREATE_FTS_INDEX` calls, which can trip
120
+ * native duplicate-index/WAL edge cases. Cleared on re-init and close.
121
+ *
122
+ * Key format: `${tableName}:${indexName}`.
123
+ */
124
+ const ensuredFTSIndexes = new Set();
125
+ const ftsIndexKey = (tableName, indexName) => `${tableName}:${indexName}`;
126
+ /**
127
+ * Check if an error indicates a missing column or table (schema-level problem)
128
+ * rather than a transient/connection error. Used for legacy DB fallback logic.
129
+ */
130
+ const isMissingColumnOrTableError = (msg) => msg.includes('does not exist') ||
131
+ // Kuzu-specific: "(table|column|property) ... not found" — narrow enough to avoid
132
+ // matching transient errors like "connection not found" or "key not found".
133
+ /(table|column|property).*not found/i.test(msg);
134
+ /** Expose the current Database for pool adapter reuse in tests. */
135
+ export const getDatabase = () => db;
136
+ // Global session lock for operations that touch module-level lbug globals.
137
+ // This guarantees no DB switch can happen while an operation is running.
138
+ let sessionLock = Promise.resolve();
139
+ /** Number of times to retry on a BUSY / lock-held error before giving up. */
140
+ const DB_LOCK_RETRY_ATTEMPTS = 3;
141
+ /** Base back-off in ms between BUSY retries (multiplied by attempt number). */
142
+ const DB_LOCK_RETRY_DELAY_MS = 500;
143
+ /**
144
+ * Return true when the error message indicates a write was attempted against
145
+ * a read-only LadybugDB connection. The MCP query pool opens DBs read-only,
146
+ * so any path that calls a `CREATE_*` procedure there will surface this
147
+ * (e.g. defensive `ensureFTSIndex` calls). Owners of the writable analyze
148
+ * path should ignore this error — index creation is owned by `arc
149
+ * analyze` and either already happened or will happen on the next run.
150
+ */
151
+ export const isReadOnlyDbError = (err) => {
152
+ const msg = err instanceof Error ? err.message : String(err);
153
+ return /read-only database/i.test(msg);
154
+ };
155
+ const runWithSessionLock = async (operation) => {
156
+ const previous = sessionLock;
157
+ let release = null;
158
+ sessionLock = new Promise((resolve) => {
159
+ release = resolve;
160
+ });
161
+ await previous;
162
+ try {
163
+ return await operation();
164
+ }
165
+ finally {
166
+ release?.();
167
+ }
168
+ };
169
+ const normalizeCopyPath = (filePath) => filePath.replace(/\\/g, '/');
170
+ const closeQueryResult = async (result) => {
171
+ try {
172
+ await result.close();
173
+ }
174
+ catch {
175
+ // Best-effort cleanup only.
176
+ }
177
+ };
178
+ const drainQueryResult = async (queryResult) => {
179
+ const results = Array.isArray(queryResult) ? queryResult : [queryResult];
180
+ let firstError;
181
+ let hasError = false;
182
+ for (const result of results) {
183
+ try {
184
+ await result.getAll();
185
+ }
186
+ catch (err) {
187
+ if (!hasError) {
188
+ firstError = err;
189
+ hasError = true;
190
+ }
191
+ }
192
+ finally {
193
+ await closeQueryResult(result);
194
+ }
195
+ }
196
+ if (hasError)
197
+ throw firstError;
198
+ };
199
+ const readQueryRows = async (queryResult) => {
200
+ const results = Array.isArray(queryResult) ? queryResult : [queryResult];
201
+ let rows = [];
202
+ let firstError;
203
+ let hasError = false;
204
+ for (let i = 0; i < results.length; i++) {
205
+ const result = results[i];
206
+ try {
207
+ const resultRows = await result.getAll();
208
+ if (i === 0)
209
+ rows = resultRows;
210
+ }
211
+ catch (err) {
212
+ if (!hasError) {
213
+ firstError = err;
214
+ hasError = true;
215
+ }
216
+ }
217
+ finally {
218
+ await closeQueryResult(result);
219
+ }
220
+ }
221
+ if (hasError)
222
+ throw firstError;
223
+ return rows;
224
+ };
225
+ const queryAndDrain = async (targetConn, cypher) => {
226
+ const queryResult = await targetConn.query(cypher);
227
+ await drainQueryResult(queryResult);
228
+ };
229
+ export const initLbug = async (dbPath) => {
230
+ return runWithSessionLock(() => ensureLbugInitialized(dbPath));
231
+ };
232
+ /**
233
+ * Execute multiple queries against one repo DB atomically.
234
+ * While the callback runs, no other request can switch the active DB.
235
+ *
236
+ * Automatically retries up to DB_LOCK_RETRY_ATTEMPTS times when the
237
+ * database is busy (e.g. `arc analyze` holds the write lock).
238
+ * Each retry waits DB_LOCK_RETRY_DELAY_MS * attempt milliseconds.
239
+ */
240
+ export const withLbugDb = async (dbPath, operation) => {
241
+ let lastError;
242
+ for (let attempt = 1; attempt <= DB_LOCK_RETRY_ATTEMPTS; attempt++) {
243
+ try {
244
+ return await runWithSessionLock(async () => {
245
+ await ensureLbugInitialized(dbPath);
246
+ return operation();
247
+ });
248
+ }
249
+ catch (err) {
250
+ lastError = err;
251
+ // Skip outer retry when the inner open-retry already exhausted: the
252
+ // ~1.5s open-time budget was just spent, repeating the full reset+
253
+ // reopen cycle would only add 4-5s of tail latency without changing
254
+ // the outcome (both layers consult the same isDbBusyError matcher).
255
+ if (!isDbBusyError(err) || isOpenRetryExhausted(err) || attempt === DB_LOCK_RETRY_ATTEMPTS) {
256
+ throw err;
257
+ }
258
+ // Close stale connection inside the session lock to prevent race conditions
259
+ // with concurrent operations that might acquire the lock between cleanup steps
260
+ await runWithSessionLock(async () => {
261
+ await safeClose();
262
+ currentDbPath = null;
263
+ ftsLoaded = false;
264
+ vectorExtensionLoaded = false;
265
+ ensuredFTSIndexes.clear();
266
+ });
267
+ // Sleep outside the lock — no need to block others while waiting
268
+ await new Promise((resolve) => setTimeout(resolve, DB_LOCK_RETRY_DELAY_MS * attempt));
269
+ }
270
+ }
271
+ // This line is unreachable — the loop either returns or throws inside,
272
+ // but TypeScript needs an explicit throw to satisfy the return type.
273
+ throw lastError;
274
+ };
275
+ const ensureLbugInitialized = async (dbPath) => {
276
+ if (conn && currentDbPath === dbPath) {
277
+ return { db, conn };
278
+ }
279
+ await doInitLbug(dbPath);
280
+ return { db, conn };
281
+ };
282
+ const doInitLbug = async (dbPath) => {
283
+ // Different database requested — close the old one first
284
+ if (conn || db) {
285
+ await safeClose();
286
+ currentDbPath = null;
287
+ ftsLoaded = false;
288
+ vectorExtensionLoaded = false;
289
+ ensuredFTSIndexes.clear();
290
+ }
291
+ // LadybugDB stores the database as a single file (not a directory).
292
+ // If the path already exists, it must be a valid LadybugDB database file.
293
+ // Remove stale empty directories or files from older versions.
294
+ try {
295
+ const stat = await fs.lstat(dbPath);
296
+ if (stat.isSymbolicLink()) {
297
+ // Never follow symlinks — just remove the link itself
298
+ await fs.unlink(dbPath);
299
+ }
300
+ else if (stat.isDirectory()) {
301
+ // Verify path is within expected storage directory before deleting
302
+ const realPath = await fs.realpath(dbPath);
303
+ const parentDir = path.dirname(dbPath);
304
+ const realParent = await fs.realpath(parentDir);
305
+ if (!realPath.startsWith(realParent + path.sep) && realPath !== realParent) {
306
+ throw new Error(`Refusing to delete ${dbPath}: resolved path ${realPath} is outside storage directory`);
307
+ }
308
+ // Old-style directory database or empty leftover - remove it
309
+ await fs.rm(dbPath, { recursive: true, force: true });
310
+ }
311
+ // If it's a file, assume it's an existing LadybugDB database - LadybugDB will open it
312
+ }
313
+ catch {
314
+ // Path doesn't exist, which is what LadybugDB wants for a new database
315
+ }
316
+ // Ensure parent directory exists
317
+ const parentDir = path.dirname(dbPath);
318
+ await fs.mkdir(parentDir, { recursive: true });
319
+ const opened = await openLbugConnection(lbug, dbPath);
320
+ db = opened.db;
321
+ conn = opened.conn;
322
+ for (const schemaQuery of SCHEMA_QUERIES) {
323
+ try {
324
+ await queryAndDrain(conn, schemaQuery);
325
+ }
326
+ catch (err) {
327
+ const msg = err instanceof Error ? err.message : String(err);
328
+ // Suppression list:
329
+ // - "already exists": expected idempotent re-create on existing DBs
330
+ // - "could not set lock on file": LadybugDB v0.16.1 emits this on
331
+ // Windows when CREATE NODE TABLE runs against a path that was
332
+ // just opened (the WAL handle from a fresh Database briefly
333
+ // contests the table's first-write lock). The table is created
334
+ // anyway and any genuine cross-process lock contention surfaces
335
+ // on the next operation via withLbugDb's retry. Logging it here
336
+ // would just be noise in CI.
337
+ if (!msg.includes('already exists') && !isDbBusyError(err)) {
338
+ logger.warn(`⚠️ Schema creation warning: ${msg.slice(0, 120)}`);
339
+ }
340
+ }
341
+ }
342
+ // FTS powers baseline search, so initialize it with the core DB. VECTOR is
343
+ // only required for semantic embeddings and is probed lazily there.
344
+ await loadFTSExtension();
345
+ currentDbPath = dbPath;
346
+ return { db, conn };
347
+ };
348
+ export const loadGraphToLbug = async (graph, repoPath, storagePath, onProgress) => {
349
+ if (!conn) {
350
+ throw new Error('LadybugDB not initialized. Call initLbug first.');
351
+ }
352
+ const log = onProgress || (() => { });
353
+ const csvDir = path.join(storagePath, 'csv');
354
+ log('Streaming CSVs to disk...');
355
+ const csvResult = await streamAllCSVsToDisk(graph, repoPath, csvDir);
356
+ const validTables = new Set(NODE_TABLES);
357
+ const getNodeLabel = (nodeId) => {
358
+ if (nodeId.startsWith('comm_'))
359
+ return 'Community';
360
+ if (nodeId.startsWith('proc_'))
361
+ return 'Process';
362
+ return nodeId.split(':')[0];
363
+ };
364
+ // Bulk COPY all node CSVs (sequential — LadybugDB allows only one write txn at a time)
365
+ const nodeFiles = [...csvResult.nodeFiles.entries()];
366
+ const totalSteps = nodeFiles.length + 1; // +1 for relationships
367
+ let stepsDone = 0;
368
+ for (const [table, { csvPath, rows }] of nodeFiles) {
369
+ stepsDone++;
370
+ log(`Loading nodes ${stepsDone}/${totalSteps}: ${table} (${rows.toLocaleString()} rows)`);
371
+ const normalizedPath = normalizeCopyPath(csvPath);
372
+ const copyQuery = getCopyQuery(table, normalizedPath);
373
+ try {
374
+ await queryAndDrain(conn, copyQuery);
375
+ }
376
+ catch (err) {
377
+ try {
378
+ const retryQuery = copyQuery.replace('auto_detect=false)', 'auto_detect=false, IGNORE_ERRORS=true)');
379
+ await queryAndDrain(conn, retryQuery);
380
+ }
381
+ catch (retryErr) {
382
+ const retryMsg = retryErr instanceof Error ? retryErr.message : String(retryErr);
383
+ throw new Error(`COPY failed for ${table}: ${retryMsg.slice(0, 200)}`);
384
+ }
385
+ }
386
+ }
387
+ // Bulk COPY relationships — split by FROM→TO label pair (LadybugDB requires it)
388
+ const { relHeader, relsByPairMeta, pairWriteStreams, skippedRels, totalValidRels } = await splitRelCsvByLabelPair(csvResult.relCsvPath, csvDir, validTables, getNodeLabel);
389
+ // Close all per-pair write streams before COPY. `stream/promises.finished`
390
+ // resolves on the stream's 'finish' event and rejects on 'error' — replaces
391
+ // a hand-rolled promisification with the stdlib primitive.
392
+ await Promise.all(Array.from(pairWriteStreams.values()).map(async (ws) => {
393
+ ws.end();
394
+ await finished(ws);
395
+ }));
396
+ const insertedRels = totalValidRels;
397
+ const warnings = [];
398
+ if (insertedRels > 0) {
399
+ log(`Loading edges: ${insertedRels.toLocaleString()} across ${relsByPairMeta.size} types`);
400
+ let pairIdx = 0;
401
+ let failedPairEdges = 0;
402
+ const failedPairCsvPaths = new Set();
403
+ for (const [pairKey, { csvPath: pairCsvPath, rows }] of relsByPairMeta) {
404
+ pairIdx++;
405
+ const [fromLabel, toLabel] = pairKey.split('|');
406
+ const normalizedPath = normalizeCopyPath(pairCsvPath);
407
+ const copyQuery = `COPY ${REL_TABLE_NAME} FROM "${normalizedPath}" (from="${fromLabel}", to="${toLabel}", HEADER=true, ESCAPE='"', DELIM=',', QUOTE='"', PARALLEL=false, auto_detect=false)`;
408
+ if (pairIdx % 5 === 0 || rows > 1000) {
409
+ log(`Loading edges: ${pairIdx}/${relsByPairMeta.size} types (${fromLabel} -> ${toLabel})`);
410
+ }
411
+ try {
412
+ await queryAndDrain(conn, copyQuery);
413
+ }
414
+ catch (err) {
415
+ try {
416
+ const retryQuery = copyQuery.replace('auto_detect=false)', 'auto_detect=false, IGNORE_ERRORS=true)');
417
+ await queryAndDrain(conn, retryQuery);
418
+ }
419
+ catch (retryErr) {
420
+ const retryMsg = retryErr instanceof Error ? retryErr.message : String(retryErr);
421
+ warnings.push(`${fromLabel}->${toLabel} (${rows} edges): ${retryMsg.slice(0, 80)}`);
422
+ failedPairEdges += rows;
423
+ failedPairCsvPaths.add(pairCsvPath);
424
+ }
425
+ }
426
+ // Only delete if not in failedPairCsvPaths (needed for fallback)
427
+ if (!failedPairCsvPaths.has(pairCsvPath)) {
428
+ try {
429
+ await fs.unlink(pairCsvPath);
430
+ }
431
+ catch { }
432
+ }
433
+ }
434
+ if (failedPairCsvPaths.size > 0) {
435
+ log(`Inserting ${failedPairEdges} edges individually (missing schema pairs)`);
436
+ // Read failed pair files and merge for fallback inserts
437
+ const allLines = [relHeader];
438
+ for (const failedPath of failedPairCsvPaths) {
439
+ try {
440
+ const content = await fs.readFile(failedPath, 'utf-8');
441
+ const lines = content.split('\n');
442
+ // Skip header line (first) and empty lines
443
+ for (let i = 1; i < lines.length; i++) {
444
+ if (lines[i].trim())
445
+ allLines.push(lines[i]);
446
+ }
447
+ }
448
+ catch { }
449
+ try {
450
+ await fs.unlink(failedPath);
451
+ }
452
+ catch { }
453
+ }
454
+ if (allLines.length > 1) {
455
+ await fallbackRelationshipInserts(allLines, validTables, getNodeLabel);
456
+ }
457
+ }
458
+ }
459
+ // Cleanup all CSVs
460
+ try {
461
+ await fs.unlink(csvResult.relCsvPath);
462
+ }
463
+ catch { }
464
+ for (const [, { csvPath }] of csvResult.nodeFiles) {
465
+ try {
466
+ await fs.unlink(csvPath);
467
+ }
468
+ catch { }
469
+ }
470
+ try {
471
+ const remaining = await fs.readdir(csvDir);
472
+ for (const f of remaining) {
473
+ try {
474
+ await fs.unlink(path.join(csvDir, f));
475
+ }
476
+ catch { }
477
+ }
478
+ }
479
+ catch { }
480
+ try {
481
+ await fs.rmdir(csvDir);
482
+ }
483
+ catch { }
484
+ return { success: true, insertedRels, skippedRels, warnings };
485
+ };
486
+ // LadybugDB default ESCAPE is '\' (backslash), but our CSV uses RFC 4180 escaping ("" for literal quotes).
487
+ // Source code content is full of backslashes which confuse the auto-detection.
488
+ // We MUST explicitly set ESCAPE='"' to use RFC 4180 escaping, and disable auto_detect to prevent
489
+ // LadybugDB from overriding our settings based on sample rows.
490
+ const COPY_CSV_OPTS = `(HEADER=true, ESCAPE='"', DELIM=',', QUOTE='"', PARALLEL=false, auto_detect=false)`;
491
+ // Multi-language table names that were created with backticks in CODE_ELEMENT_BASE
492
+ // and must always be referenced with backticks in queries
493
+ const BACKTICK_TABLES = new Set([
494
+ 'Struct',
495
+ 'Enum',
496
+ 'Macro',
497
+ 'Typedef',
498
+ 'Union',
499
+ 'Namespace',
500
+ 'Trait',
501
+ 'Impl',
502
+ 'TypeAlias',
503
+ 'Const',
504
+ 'Static',
505
+ 'Property',
506
+ 'Record',
507
+ 'Delegate',
508
+ 'Annotation',
509
+ 'Constructor',
510
+ 'Template',
511
+ 'Module',
512
+ ]);
513
+ const escapeTableName = (table) => {
514
+ return BACKTICK_TABLES.has(table) ? `\`${table}\`` : table;
515
+ };
516
+ /** Fallback: insert relationships one-by-one if COPY fails */
517
+ const fallbackRelationshipInserts = async (validRelLines, validTables, getNodeLabel) => {
518
+ if (!conn)
519
+ return;
520
+ const escapeLabel = (label) => {
521
+ return BACKTICK_TABLES.has(label) ? `\`${label}\`` : label;
522
+ };
523
+ for (let i = 1; i < validRelLines.length; i++) {
524
+ const line = validRelLines[i];
525
+ try {
526
+ const match = line.match(/"([^"]*)","([^"]*)","([^"]*)",([0-9.]+),"([^"]*)",([0-9-]+)/);
527
+ if (!match)
528
+ continue;
529
+ const [, fromId, toId, relType, confidenceStr, reason, stepStr] = match;
530
+ const fromLabel = getNodeLabel(fromId);
531
+ const toLabel = getNodeLabel(toId);
532
+ if (!validTables.has(fromLabel) || !validTables.has(toLabel))
533
+ continue;
534
+ const confidence = parseFloat(confidenceStr) || 1.0;
535
+ const step = parseInt(stepStr) || 0;
536
+ const esc = (s) => s.replace(/'/g, "''").replace(/\\/g, '\\\\').replace(/\n/g, '\\n').replace(/\r/g, '\\r');
537
+ await queryAndDrain(conn, `
538
+ MATCH (a:${escapeLabel(fromLabel)} {id: '${esc(fromId)}' }),
539
+ (b:${escapeLabel(toLabel)} {id: '${esc(toId)}' })
540
+ CREATE (a)-[:${REL_TABLE_NAME} {type: '${esc(relType)}', confidence: ${confidence}, reason: '${esc(reason)}', step: ${step}}]->(b)
541
+ `);
542
+ }
543
+ catch {
544
+ // skip
545
+ }
546
+ }
547
+ };
548
+ /** Tables with isExported column (TypeScript/JS-native types) */
549
+ const TABLES_WITH_EXPORTED = new Set([
550
+ 'Function',
551
+ 'Class',
552
+ 'Interface',
553
+ 'Method',
554
+ 'CodeElement',
555
+ ]);
556
+ const getCopyQuery = (table, filePath) => {
557
+ const t = escapeTableName(table);
558
+ if (table === 'File') {
559
+ return `COPY ${t}(id, name, filePath, content) FROM "${filePath}" ${COPY_CSV_OPTS}`;
560
+ }
561
+ if (table === 'Folder') {
562
+ return `COPY ${t}(id, name, filePath) FROM "${filePath}" ${COPY_CSV_OPTS}`;
563
+ }
564
+ if (table === 'Community') {
565
+ return `COPY ${t}(id, label, heuristicLabel, keywords, description, enrichedBy, cohesion, symbolCount) FROM "${filePath}" ${COPY_CSV_OPTS}`;
566
+ }
567
+ if (table === 'Process') {
568
+ return `COPY ${t}(id, label, heuristicLabel, processType, stepCount, communities, entryPointId, terminalId) FROM "${filePath}" ${COPY_CSV_OPTS}`;
569
+ }
570
+ if (table === 'Section') {
571
+ return `COPY ${t}(id, name, filePath, startLine, endLine, level, content, description) FROM "${filePath}" ${COPY_CSV_OPTS}`;
572
+ }
573
+ if (table === 'Route') {
574
+ return `COPY ${t}(id, name, filePath, responseKeys, errorKeys, middleware) FROM "${filePath}" ${COPY_CSV_OPTS}`;
575
+ }
576
+ if (table === 'Tool') {
577
+ return `COPY ${t}(id, name, filePath, description) FROM "${filePath}" ${COPY_CSV_OPTS}`;
578
+ }
579
+ if (table === 'Method') {
580
+ return `COPY ${t}(id, name, filePath, startLine, endLine, isExported, content, description, parameterCount, returnType) FROM "${filePath}" ${COPY_CSV_OPTS}`;
581
+ }
582
+ if (table === 'Property') {
583
+ return `COPY ${t}(id, name, filePath, startLine, endLine, content, description, declaredType) FROM "${filePath}" ${COPY_CSV_OPTS}`;
584
+ }
585
+ // TypeScript/JS code element tables have isExported; multi-language tables do not
586
+ if (TABLES_WITH_EXPORTED.has(table)) {
587
+ return `COPY ${t}(id, name, filePath, startLine, endLine, isExported, content, description) FROM "${filePath}" ${COPY_CSV_OPTS}`;
588
+ }
589
+ // Multi-language tables (Struct, Impl, Trait, Macro, etc.)
590
+ return `COPY ${t}(id, name, filePath, startLine, endLine, content, description) FROM "${filePath}" ${COPY_CSV_OPTS}`;
591
+ };
592
+ /**
593
+ * Insert a single node to LadybugDB
594
+ * @param label - Node type (File, Function, Class, etc.)
595
+ * @param properties - Node properties
596
+ * @param dbPath - Path to LadybugDB database (optional if already initialized)
597
+ */
598
+ export const insertNodeToLbug = async (label, properties, dbPath) => {
599
+ // Use provided dbPath or fall back to module-level db
600
+ const targetDbPath = dbPath || (db ? undefined : null);
601
+ if (!targetDbPath && !db) {
602
+ throw new Error('LadybugDB not initialized. Provide dbPath or call initLbug first.');
603
+ }
604
+ try {
605
+ const escapeValue = (v) => {
606
+ if (v === null || v === undefined)
607
+ return 'NULL';
608
+ if (typeof v === 'number')
609
+ return String(v);
610
+ // Escape backslashes first (for Windows paths), then single quotes
611
+ return `'${String(v).replace(/\\/g, '\\\\').replace(/'/g, "''").replace(/\n/g, '\\n').replace(/\r/g, '\\r')}'`;
612
+ };
613
+ // Build INSERT query based on node type
614
+ const t = escapeTableName(label);
615
+ let query;
616
+ if (label === 'File') {
617
+ query = `CREATE (n:File {id: ${escapeValue(properties.id)}, name: ${escapeValue(properties.name)}, filePath: ${escapeValue(properties.filePath)}, content: ${escapeValue(properties.content || '')}})`;
618
+ }
619
+ else if (label === 'Folder') {
620
+ query = `CREATE (n:Folder {id: ${escapeValue(properties.id)}, name: ${escapeValue(properties.name)}, filePath: ${escapeValue(properties.filePath)}})`;
621
+ }
622
+ else if (label === 'Section') {
623
+ const descPart = properties.description
624
+ ? `, description: ${escapeValue(properties.description)}`
625
+ : '';
626
+ query = `CREATE (n:Section {id: ${escapeValue(properties.id)}, name: ${escapeValue(properties.name)}, filePath: ${escapeValue(properties.filePath)}, startLine: ${properties.startLine || 0}, endLine: ${properties.endLine || 0}, level: ${properties.level || 1}, content: ${escapeValue(properties.content || '')}${descPart}})`;
627
+ }
628
+ else if (TABLES_WITH_EXPORTED.has(label)) {
629
+ const descPart = properties.description
630
+ ? `, description: ${escapeValue(properties.description)}`
631
+ : '';
632
+ query = `CREATE (n:${t} {id: ${escapeValue(properties.id)}, name: ${escapeValue(properties.name)}, filePath: ${escapeValue(properties.filePath)}, startLine: ${properties.startLine || 0}, endLine: ${properties.endLine || 0}, isExported: ${!!properties.isExported}, content: ${escapeValue(properties.content || '')}${descPart}})`;
633
+ }
634
+ else if (label === 'Property') {
635
+ const descPart = properties.description
636
+ ? `, description: ${escapeValue(properties.description)}`
637
+ : '';
638
+ query = `CREATE (n:${t} {id: ${escapeValue(properties.id)}, name: ${escapeValue(properties.name)}, filePath: ${escapeValue(properties.filePath)}, startLine: ${properties.startLine || 0}, endLine: ${properties.endLine || 0}, content: ${escapeValue(properties.content || '')}${descPart}, declaredType: ${escapeValue(properties.declaredType || '')}})`;
639
+ }
640
+ else {
641
+ // Multi-language tables (Struct, Impl, Trait, Macro, etc.) — no isExported
642
+ const descPart = properties.description
643
+ ? `, description: ${escapeValue(properties.description)}`
644
+ : '';
645
+ query = `CREATE (n:${t} {id: ${escapeValue(properties.id)}, name: ${escapeValue(properties.name)}, filePath: ${escapeValue(properties.filePath)}, startLine: ${properties.startLine || 0}, endLine: ${properties.endLine || 0}, content: ${escapeValue(properties.content || '')}${descPart}})`;
646
+ }
647
+ // Use per-query connection if dbPath provided (avoids lock conflicts)
648
+ if (targetDbPath) {
649
+ const tempHandle = await openLbugConnection(lbug, targetDbPath);
650
+ try {
651
+ await queryAndDrain(tempHandle.conn, query);
652
+ return true;
653
+ }
654
+ finally {
655
+ await closeLbugConnection(tempHandle);
656
+ }
657
+ }
658
+ else if (conn) {
659
+ // Use existing persistent connection (when called from analyze)
660
+ await queryAndDrain(conn, query);
661
+ return true;
662
+ }
663
+ return false;
664
+ }
665
+ catch (e) {
666
+ // Node may already exist or other error
667
+ logger.error({ err: e.message }, `Failed to insert ${label} node:`);
668
+ return false;
669
+ }
670
+ };
671
+ /**
672
+ * Batch insert multiple nodes to LadybugDB using a single connection
673
+ * @param nodes - Array of {label, properties} to insert
674
+ * @param dbPath - Path to LadybugDB database
675
+ * @returns Object with success count and error count
676
+ */
677
+ export const batchInsertNodesToLbug = async (nodes, dbPath) => {
678
+ if (nodes.length === 0)
679
+ return { inserted: 0, failed: 0 };
680
+ const escapeValue = (v) => {
681
+ if (v === null || v === undefined)
682
+ return 'NULL';
683
+ if (typeof v === 'number')
684
+ return String(v);
685
+ // Escape backslashes first (for Windows paths), then single quotes, then newlines
686
+ return `'${String(v).replace(/\\/g, '\\\\').replace(/'/g, "''").replace(/\n/g, '\\n').replace(/\r/g, '\\r')}'`;
687
+ };
688
+ // Open a single connection for all inserts
689
+ const tempHandle = await openLbugConnection(lbug, dbPath);
690
+ const tempConn = tempHandle.conn;
691
+ let inserted = 0;
692
+ let failed = 0;
693
+ try {
694
+ for (const { label, properties } of nodes) {
695
+ try {
696
+ let query;
697
+ // Use MERGE instead of CREATE for upsert behavior (handles duplicates gracefully)
698
+ const t = escapeTableName(label);
699
+ if (label === 'File') {
700
+ query = `MERGE (n:File {id: ${escapeValue(properties.id)}}) SET n.name = ${escapeValue(properties.name)}, n.filePath = ${escapeValue(properties.filePath)}, n.content = ${escapeValue(properties.content || '')}`;
701
+ }
702
+ else if (label === 'Folder') {
703
+ query = `MERGE (n:Folder {id: ${escapeValue(properties.id)}}) SET n.name = ${escapeValue(properties.name)}, n.filePath = ${escapeValue(properties.filePath)}`;
704
+ }
705
+ else if (label === 'Section') {
706
+ const descPart = properties.description
707
+ ? `, n.description = ${escapeValue(properties.description)}`
708
+ : '';
709
+ query = `MERGE (n:Section {id: ${escapeValue(properties.id)}}) SET n.name = ${escapeValue(properties.name)}, n.filePath = ${escapeValue(properties.filePath)}, n.startLine = ${properties.startLine || 0}, n.endLine = ${properties.endLine || 0}, n.level = ${properties.level || 1}, n.content = ${escapeValue(properties.content || '')}${descPart}`;
710
+ }
711
+ else if (TABLES_WITH_EXPORTED.has(label)) {
712
+ const descPart = properties.description
713
+ ? `, n.description = ${escapeValue(properties.description)}`
714
+ : '';
715
+ query = `MERGE (n:${t} {id: ${escapeValue(properties.id)}}) SET n.name = ${escapeValue(properties.name)}, n.filePath = ${escapeValue(properties.filePath)}, n.startLine = ${properties.startLine || 0}, n.endLine = ${properties.endLine || 0}, n.isExported = ${!!properties.isExported}, n.content = ${escapeValue(properties.content || '')}${descPart}`;
716
+ }
717
+ else if (label === 'Property') {
718
+ const descPart = properties.description
719
+ ? `, n.description = ${escapeValue(properties.description)}`
720
+ : '';
721
+ query = `MERGE (n:${t} {id: ${escapeValue(properties.id)}}) SET n.name = ${escapeValue(properties.name)}, n.filePath = ${escapeValue(properties.filePath)}, n.startLine = ${properties.startLine || 0}, n.endLine = ${properties.endLine || 0}, n.content = ${escapeValue(properties.content || '')}${descPart}, n.declaredType = ${escapeValue(properties.declaredType || '')}`;
722
+ }
723
+ else {
724
+ const descPart = properties.description
725
+ ? `, n.description = ${escapeValue(properties.description)}`
726
+ : '';
727
+ query = `MERGE (n:${t} {id: ${escapeValue(properties.id)}}) SET n.name = ${escapeValue(properties.name)}, n.filePath = ${escapeValue(properties.filePath)}, n.startLine = ${properties.startLine || 0}, n.endLine = ${properties.endLine || 0}, n.content = ${escapeValue(properties.content || '')}${descPart}`;
728
+ }
729
+ await queryAndDrain(tempConn, query);
730
+ inserted++;
731
+ }
732
+ catch (e) {
733
+ // Don't console.error here - it corrupts MCP JSON-RPC on stderr
734
+ failed++;
735
+ }
736
+ }
737
+ }
738
+ finally {
739
+ await closeLbugConnection(tempHandle);
740
+ }
741
+ return { inserted, failed };
742
+ };
743
+ export const executeQuery = async (cypher) => {
744
+ if (!conn) {
745
+ throw new Error('LadybugDB not initialized. Call initLbug first.');
746
+ }
747
+ const queryResult = await conn.query(cypher);
748
+ return await readQueryRows(queryResult);
749
+ };
750
+ export const streamQuery = async (cypher, onRow) => {
751
+ if (!conn) {
752
+ throw new Error('LadybugDB not initialized. Call initLbug first.');
753
+ }
754
+ const queryResult = await conn.query(cypher);
755
+ const results = Array.isArray(queryResult) ? queryResult : [queryResult];
756
+ const result = results[0];
757
+ let rowCount = 0;
758
+ let streamError;
759
+ try {
760
+ while (await result.hasNext()) {
761
+ const row = await result.getNext();
762
+ await onRow(row);
763
+ rowCount++;
764
+ }
765
+ return rowCount;
766
+ }
767
+ catch (err) {
768
+ streamError = err;
769
+ throw err;
770
+ }
771
+ finally {
772
+ try {
773
+ await drainQueryResult(results);
774
+ }
775
+ catch (err) {
776
+ if (streamError === undefined)
777
+ throw err;
778
+ }
779
+ }
780
+ };
781
+ /**
782
+ * Execute a single parameterized query (prepare/execute pattern).
783
+ * Prevents Cypher injection by binding values as parameters.
784
+ */
785
+ export const executePrepared = async (cypher, params) => {
786
+ if (!conn) {
787
+ throw new Error('LadybugDB not initialized. Call initLbug first.');
788
+ }
789
+ const stmt = await conn.prepare(cypher);
790
+ if (!stmt.isSuccess()) {
791
+ const errMsg = await stmt.getErrorMessage();
792
+ throw new Error(`Prepare failed: ${errMsg}`);
793
+ }
794
+ const queryResult = await conn.execute(stmt, params);
795
+ return await readQueryRows(queryResult);
796
+ };
797
+ export const executeWithReusedStatement = async (cypher, paramsList) => {
798
+ if (!conn) {
799
+ throw new Error('LadybugDB not initialized. Call initLbug first.');
800
+ }
801
+ if (paramsList.length === 0)
802
+ return;
803
+ const SUB_BATCH_SIZE = 4;
804
+ for (let i = 0; i < paramsList.length; i += SUB_BATCH_SIZE) {
805
+ const subBatch = paramsList.slice(i, i + SUB_BATCH_SIZE);
806
+ const stmt = await conn.prepare(cypher);
807
+ if (!stmt.isSuccess()) {
808
+ const errMsg = await stmt.getErrorMessage();
809
+ throw new Error(`Prepare failed: ${errMsg}`);
810
+ }
811
+ try {
812
+ for (const params of subBatch) {
813
+ await drainQueryResult(await conn.execute(stmt, params));
814
+ }
815
+ }
816
+ catch (e) {
817
+ const msg = e instanceof Error ? e.message : String(e);
818
+ const queryPreview = cypher.replace(/\s+/g, ' ').slice(0, 120);
819
+ throw new Error(`Batch execution failed for rows ${i + 1}-${i + subBatch.length}: ${msg} (${queryPreview})`);
820
+ }
821
+ // Note: LadybugDB PreparedStatement doesn't require explicit close()
822
+ }
823
+ };
824
+ export const getLbugStats = async () => {
825
+ if (!conn)
826
+ return { nodes: 0, edges: 0 };
827
+ let totalNodes = 0;
828
+ for (const tableName of NODE_TABLES) {
829
+ try {
830
+ const queryResult = await conn.query(`MATCH (n:${escapeTableName(tableName)}) RETURN count(n) AS cnt`);
831
+ const nodeRows = await readQueryRows(queryResult);
832
+ if (nodeRows.length > 0) {
833
+ totalNodes += Number(nodeRows[0]?.cnt ?? nodeRows[0]?.[0] ?? 0);
834
+ }
835
+ }
836
+ catch {
837
+ // ignore
838
+ }
839
+ }
840
+ let totalEdges = 0;
841
+ try {
842
+ const queryResult = await conn.query(`MATCH ()-[r:${REL_TABLE_NAME}]->() RETURN count(r) AS cnt`);
843
+ const edgeRows = await readQueryRows(queryResult);
844
+ if (edgeRows.length > 0) {
845
+ totalEdges = Number(edgeRows[0]?.cnt ?? edgeRows[0]?.[0] ?? 0);
846
+ }
847
+ }
848
+ catch {
849
+ // ignore
850
+ }
851
+ return { nodes: totalNodes, edges: totalEdges };
852
+ };
853
+ /**
854
+ * Load cached embeddings from LadybugDB before a rebuild.
855
+ * Returns all embedding vectors so they can be re-inserted after the graph is reloaded,
856
+ * avoiding expensive re-embedding of unchanged nodes.
857
+ *
858
+ * Detects old schema (no chunkIndex column) and returns empty cache to trigger rebuild.
859
+ */
860
+ export const loadCachedEmbeddings = async () => {
861
+ if (!conn) {
862
+ return { embeddingNodeIds: new Set(), embeddings: [] };
863
+ }
864
+ const embeddingNodeIds = new Set();
865
+ const embeddings = [];
866
+ try {
867
+ // Schema migration detection: query with new columns to verify schema version.
868
+ // Old schema only had (nodeId, embedding); new schema adds (id, chunkIndex, startLine, endLine, contentHash).
869
+ // If the query fails (column missing), we return empty cache to force a full rebuild.
870
+ try {
871
+ const check = await conn.query(`MATCH (e:${EMBEDDING_TABLE_NAME}) RETURN e.nodeId AS nodeId, e.chunkIndex AS chunkIndex LIMIT 1`);
872
+ await readQueryRows(check);
873
+ }
874
+ catch {
875
+ return { embeddingNodeIds: new Set(), embeddings: [] };
876
+ }
877
+ // Try to read contentHash alongside chunk columns
878
+ let rows;
879
+ let hasContentHash = true;
880
+ try {
881
+ rows = await conn.query(`MATCH (e:${EMBEDDING_TABLE_NAME}) RETURN e.nodeId AS nodeId, e.chunkIndex AS chunkIndex, e.startLine AS startLine, e.endLine AS endLine, e.embedding AS embedding, e.contentHash AS contentHash`);
882
+ }
883
+ catch (err) {
884
+ // Fallback for legacy DBs without contentHash column
885
+ const msg = err?.message ?? '';
886
+ if (isMissingColumnOrTableError(msg)) {
887
+ hasContentHash = false;
888
+ rows = await conn.query(`MATCH (e:${EMBEDDING_TABLE_NAME}) RETURN e.nodeId AS nodeId, e.chunkIndex AS chunkIndex, e.startLine AS startLine, e.endLine AS endLine, e.embedding AS embedding`);
889
+ }
890
+ else {
891
+ throw err;
892
+ }
893
+ }
894
+ for (const row of await readQueryRows(rows)) {
895
+ const nodeId = String(row.nodeId ?? row[0] ?? '');
896
+ if (!nodeId)
897
+ continue;
898
+ embeddingNodeIds.add(nodeId);
899
+ const embedding = row.embedding ?? row[4];
900
+ if (embedding) {
901
+ embeddings.push({
902
+ nodeId,
903
+ chunkIndex: Number(row.chunkIndex ?? row[1] ?? 0),
904
+ startLine: Number(row.startLine ?? row[2] ?? 0),
905
+ endLine: Number(row.endLine ?? row[3] ?? 0),
906
+ embedding: Array.isArray(embedding)
907
+ ? embedding.map(Number)
908
+ : Array.from(embedding).map(Number),
909
+ contentHash: hasContentHash ? (row.contentHash ?? row[5] ?? undefined) : undefined,
910
+ });
911
+ }
912
+ }
913
+ }
914
+ catch {
915
+ /* embedding table may not exist */
916
+ }
917
+ return { embeddingNodeIds, embeddings };
918
+ };
919
+ /**
920
+ * Fetch existing embedding hashes from CodeEmbedding table for incremental embedding.
921
+ * Returns a Map<nodeId, contentHash> suitable for passing to `runEmbeddingPipeline`.
922
+ * Handles legacy DBs without the `contentHash` column (all rows treated as stale with empty hash).
923
+ * Returns undefined if the CodeEmbedding table does not exist.
924
+ *
925
+ * @param execQuery - Cypher query executor (typically pool-adapter's `executeQuery`)
926
+ */
927
+ export const fetchExistingEmbeddingHashes = async (execQuery) => {
928
+ try {
929
+ const rows = await execQuery(`MATCH (e:${EMBEDDING_TABLE_NAME}) RETURN e.nodeId AS nodeId, e.chunkIndex AS chunkIndex, e.startLine AS startLine, e.endLine AS endLine, e.contentHash AS contentHash`);
930
+ if (!rows || rows.length === 0)
931
+ return undefined;
932
+ const map = new Map();
933
+ for (const r of rows) {
934
+ const nodeId = r.nodeId ?? r[0];
935
+ const chunkIndex = r.chunkIndex ?? r[1];
936
+ const startLine = r.startLine ?? r[2];
937
+ const endLine = r.endLine ?? r[3];
938
+ const hash = r.contentHash ?? r[4] ?? STALE_HASH_SENTINEL;
939
+ if (nodeId) {
940
+ const hasChunkMetadata = chunkIndex !== undefined &&
941
+ chunkIndex !== null &&
942
+ startLine !== undefined &&
943
+ startLine !== null &&
944
+ endLine !== undefined &&
945
+ endLine !== null;
946
+ // Empty/null contentHash or missing chunk metadata means legacy row — treat as stale.
947
+ map.set(nodeId, hasChunkMetadata && hash ? hash : STALE_HASH_SENTINEL);
948
+ }
949
+ }
950
+ return map;
951
+ }
952
+ catch (err) {
953
+ const msg = err?.message ?? '';
954
+ if (isMissingColumnOrTableError(msg)) {
955
+ // Legacy rows missing chunk-aware columns — treat every row as stale.
956
+ try {
957
+ const rows = await execQuery(`MATCH (e:${EMBEDDING_TABLE_NAME}) RETURN e.nodeId AS nodeId`);
958
+ if (!rows || rows.length === 0)
959
+ return undefined;
960
+ const map = new Map();
961
+ for (const r of rows) {
962
+ const nodeId = r.nodeId ?? r[0];
963
+ if (nodeId)
964
+ map.set(nodeId, STALE_HASH_SENTINEL);
965
+ }
966
+ logger.info(`[embed] ${map.size} nodes in legacy DB (missing chunk-aware columns) — all treated as stale`);
967
+ return map;
968
+ }
969
+ catch (fallbackErr) {
970
+ const fallbackMsg = fallbackErr?.message ?? '';
971
+ if (isMissingColumnOrTableError(fallbackMsg)) {
972
+ logger.info(`[embed] CodeEmbedding table not yet present — full embedding run (${fallbackMsg})`);
973
+ return undefined;
974
+ }
975
+ throw fallbackErr;
976
+ }
977
+ }
978
+ throw err;
979
+ }
980
+ };
981
+ /**
982
+ * Flush the WAL so all pending writes are visible to subsequent readers.
983
+ *
984
+ * Best-effort: swallows errors from older LadybugDB versions or schemaless
985
+ * databases that do not support the CHECKPOINT command. A no-op when there
986
+ * is nothing pending, so safe (and cheap) to call unconditionally after any
987
+ * write path.
988
+ *
989
+ * Use this instead of safeClose when the connection must stay open
990
+ * (e.g. the /api/embed handler that keeps serving queries after flushing).
991
+ *
992
+ * @see safeClose — CHECKPOINT + connection/database close
993
+ */
994
+ export const flushWAL = async () => {
995
+ if (!conn)
996
+ return;
997
+ try {
998
+ const checkpointResult = await conn.query('CHECKPOINT');
999
+ await drainQueryResult(checkpointResult);
1000
+ }
1001
+ catch {
1002
+ /* ignore — older LadybugDB or schemaless DB may not accept it */
1003
+ }
1004
+ };
1005
+ /**
1006
+ * Flush the WAL and close the connection and database handles.
1007
+ *
1008
+ * Consolidates the CHECKPOINT + close pattern into a single function so
1009
+ * callers never call conn.close() or db.close() directly (#1376).
1010
+ * An ESLint no-restricted-syntax rule enforces this — see eslint.config.mjs.
1011
+ *
1012
+ * @see flushWAL — CHECKPOINT-only (connection stays open)
1013
+ * @see closeLbug — safeClose + module state reset (full teardown)
1014
+ */
1015
+ export const safeClose = async () => {
1016
+ await flushWAL();
1017
+ // Capture before close — currentDbPath stays set so the Windows post-close
1018
+ // probe below knows which file to wait on.
1019
+ const closingDbPath = currentDbPath;
1020
+ if (conn) {
1021
+ try {
1022
+ // eslint-disable-next-line no-restricted-syntax -- sole authorised close site
1023
+ await conn.close();
1024
+ }
1025
+ catch {
1026
+ /* best-effort */
1027
+ }
1028
+ conn = null;
1029
+ }
1030
+ if (db) {
1031
+ try {
1032
+ // eslint-disable-next-line no-restricted-syntax -- sole authorised close site
1033
+ await db.close();
1034
+ }
1035
+ catch {
1036
+ /* best-effort */
1037
+ }
1038
+ db = null;
1039
+ }
1040
+ // Windows: libuv reports `db.close()` resolved before the kernel has
1041
+ // released the file handle. A subsequent `new Database(samePath)` in
1042
+ // the same process can race the release. The probe (lbug-config.ts)
1043
+ // forces any residual lock to surface as EBUSY/EPERM/EACCES so the
1044
+ // open-time retry absorbs the lag.
1045
+ if (process.platform === 'win32' && closingDbPath) {
1046
+ const released = await waitForWindowsHandleRelease(closingDbPath);
1047
+ if (!released) {
1048
+ // Probe exhausted with a lock code still in flight. The next
1049
+ // openLbugConnection will absorb whatever residual lag remains, but
1050
+ // a chronic warning helps operators spot AV interference (Windows
1051
+ // Defender holding the file far past the 250ms budget).
1052
+ logger.warn({ dbPath: closingDbPath }, '⚠️ LadybugDB file handle still locked after close (Windows). If this repeats, check antivirus/Defender exclusions for the Arceus storage directory.');
1053
+ }
1054
+ }
1055
+ };
1056
+ export const closeLbug = async () => {
1057
+ await safeClose();
1058
+ currentDbPath = null;
1059
+ ftsLoaded = false;
1060
+ vectorExtensionLoaded = false;
1061
+ ensuredFTSIndexes.clear();
1062
+ };
1063
+ export const isLbugReady = () => conn !== null && db !== null;
1064
+ /**
1065
+ * Delete all nodes (and their relationships) for a specific file from LadybugDB
1066
+ * @param filePath - The file path to delete nodes for
1067
+ * @param dbPath - Optional path to LadybugDB for per-query connection
1068
+ * @returns Object with counts of deleted nodes
1069
+ */
1070
+ export const deleteNodesForFile = async (filePath, dbPath) => {
1071
+ const usePerQuery = !!dbPath;
1072
+ // Set up connection (either use existing or create per-query)
1073
+ let tempHandle = null;
1074
+ let tempConn = null;
1075
+ let targetConn = conn;
1076
+ if (usePerQuery) {
1077
+ tempHandle = await openLbugConnection(lbug, dbPath);
1078
+ tempConn = tempHandle.conn;
1079
+ targetConn = tempConn;
1080
+ }
1081
+ else if (!conn) {
1082
+ throw new Error('LadybugDB not initialized. Provide dbPath or call initLbug first.');
1083
+ }
1084
+ try {
1085
+ let deletedNodes = 0;
1086
+ const escapedPath = filePath.replace(/'/g, "''");
1087
+ // Delete nodes from each table that has filePath
1088
+ // DETACH DELETE removes the node and all its relationships
1089
+ for (const tableName of NODE_TABLES) {
1090
+ // Skip tables that don't have filePath (Community, Process)
1091
+ if (tableName === 'Community' || tableName === 'Process')
1092
+ continue;
1093
+ try {
1094
+ // First count how many we'll delete
1095
+ const tn = escapeTableName(tableName);
1096
+ const countResult = await targetConn.query(`MATCH (n:${tn}) WHERE n.filePath = '${escapedPath}' RETURN count(n) AS cnt`);
1097
+ const rows = await readQueryRows(countResult);
1098
+ const count = Number(rows[0]?.cnt ?? rows[0]?.[0] ?? 0);
1099
+ if (count > 0) {
1100
+ // Delete nodes (and implicitly their relationships via DETACH)
1101
+ await queryAndDrain(targetConn, `MATCH (n:${tn}) WHERE n.filePath = '${escapedPath}' DETACH DELETE n`);
1102
+ deletedNodes += count;
1103
+ }
1104
+ }
1105
+ catch (e) {
1106
+ // Some tables may not support this query, skip
1107
+ }
1108
+ }
1109
+ // Also delete any embeddings for nodes in this file
1110
+ try {
1111
+ await queryAndDrain(targetConn, `MATCH (e:${EMBEDDING_TABLE_NAME}) WHERE e.nodeId STARTS WITH '${escapedPath}' DELETE e`);
1112
+ }
1113
+ catch {
1114
+ // Embedding table may not exist or nodeId format may differ
1115
+ }
1116
+ return { deletedNodes };
1117
+ }
1118
+ finally {
1119
+ // Close per-query connection if used
1120
+ if (tempHandle)
1121
+ await closeLbugConnection(tempHandle);
1122
+ }
1123
+ };
1124
+ export const getEmbeddingTableName = () => EMBEDDING_TABLE_NAME;
1125
+ /**
1126
+ * Return the distinct repo-relative paths of files that import
1127
+ * `targetFilePath` according to the IMPORTS edges currently in the
1128
+ * DB. Used by the incremental writeback path to expand the
1129
+ * "files-to-rewrite" set so that files importing a changed file get
1130
+ * their edges (which may have been refined by cross-file resolution)
1131
+ * re-emitted, rather than left stale in the DB.
1132
+ *
1133
+ * The DB query reads the *previous* run's state — pre-pipeline, before
1134
+ * any nodes are deleted — so the returned importers are "files that
1135
+ * USED TO import the target". That's the right set to invalidate:
1136
+ * those are the files whose edges in the DB might no longer match
1137
+ * what cross-file resolution produces given the changed file's new
1138
+ * exports.
1139
+ */
1140
+ export const queryImporters = async (targetFilePath) => {
1141
+ if (!conn) {
1142
+ throw new Error('LadybugDB not initialized. Call initLbug first.');
1143
+ }
1144
+ const escaped = targetFilePath.replace(/'/g, "''");
1145
+ const cypher = `
1146
+ MATCH (a)-[r:${REL_TABLE_NAME}]->(b)
1147
+ WHERE r.type = 'IMPORTS' AND b.filePath = '${escaped}'
1148
+ RETURN DISTINCT a.filePath AS importer
1149
+ `;
1150
+ try {
1151
+ const queryResult = await conn.query(cypher);
1152
+ const result = Array.isArray(queryResult) ? queryResult[0] : queryResult;
1153
+ const rows = await result.getAll();
1154
+ const out = [];
1155
+ for (const row of rows) {
1156
+ const v = row.importer;
1157
+ if (typeof v === 'string' && v.length > 0)
1158
+ out.push(v);
1159
+ }
1160
+ return out;
1161
+ }
1162
+ catch {
1163
+ return [];
1164
+ }
1165
+ };
1166
+ /**
1167
+ * Drop every Community and Process node (and their MEMBER_OF /
1168
+ * STEP_IN_PROCESS edges via DETACH DELETE). Used at the start of an
1169
+ * incremental run so the communities and processes phases regenerate
1170
+ * them from scratch on the merged graph — required for the
1171
+ * "Leiden runs on the FULL graph" correctness invariant.
1172
+ */
1173
+ export const deleteAllCommunitiesAndProcesses = async () => {
1174
+ if (!conn) {
1175
+ throw new Error('LadybugDB not initialized. Call initLbug first.');
1176
+ }
1177
+ let nodesDeleted = 0;
1178
+ for (const label of ['Community', 'Process']) {
1179
+ try {
1180
+ const countResult = await conn.query(`MATCH (n:${label}) RETURN count(n) AS cnt`);
1181
+ const result = Array.isArray(countResult) ? countResult[0] : countResult;
1182
+ const rows = await result.getAll();
1183
+ const count = Number(rows[0]?.cnt ?? rows[0]?.[0] ?? 0);
1184
+ if (count > 0) {
1185
+ await conn.query(`MATCH (n:${label}) DETACH DELETE n`);
1186
+ nodesDeleted += count;
1187
+ }
1188
+ }
1189
+ catch {
1190
+ // Table may not exist yet on a freshly-initialized DB — fine.
1191
+ }
1192
+ }
1193
+ return { nodesDeleted };
1194
+ };
1195
+ // ============================================================================
1196
+ // Full-Text Search (FTS) Functions
1197
+ // ============================================================================
1198
+ /**
1199
+ * Load the FTS extension on the supplied connection (or the singleton
1200
+ * writable connection when none is given).
1201
+ *
1202
+ * Delegates to the shared `ExtensionManager` so install policy (auto /
1203
+ * load-only / never), out-of-process bounded INSTALL, and capability
1204
+ * caching are owned in one place. The module-level `ftsLoaded` flag is
1205
+ * kept purely as a per-call short-circuit on the singleton writable
1206
+ * connection so repeated callers (e.g. createFTSIndex) avoid an extra
1207
+ * `LOAD` round-trip per invocation. Pool adapter callers pass
1208
+ * `{ policy: 'load-only' }` so query paths never block on a network install.
1209
+ */
1210
+ export const loadFTSExtension = async (targetConn, opts = {}) => {
1211
+ const useModuleState = targetConn === undefined;
1212
+ if (useModuleState && ftsLoaded)
1213
+ return true;
1214
+ const c = targetConn ?? conn;
1215
+ if (!c) {
1216
+ throw new Error('LadybugDB not initialized. Call initLbug first.');
1217
+ }
1218
+ const loaded = await extensionManager.ensure((sql) => queryAndDrain(c, sql), 'fts', 'FTS', opts);
1219
+ if (loaded && useModuleState)
1220
+ ftsLoaded = true;
1221
+ return loaded;
1222
+ };
1223
+ /**
1224
+ * Load the VECTOR extension on the supplied connection (or the singleton
1225
+ * writable connection when none is given). Returns false when VECTOR is
1226
+ * unavailable so semantic search can fall back to exact scan.
1227
+ */
1228
+ export const loadVectorExtension = async (targetConn, opts = {}) => {
1229
+ const useModuleState = targetConn === undefined;
1230
+ if (useModuleState && vectorExtensionLoaded)
1231
+ return true;
1232
+ // INSTALL VECTOR crashes with SIGSEGV on Windows: the KuzuDB native extension
1233
+ // installer has an unhandled error path on Windows that raises a fatal signal
1234
+ // that JS try/catch cannot intercept. Skip loading — vector/embedding search
1235
+ // is unavailable but all graph index queries still work. Do NOT set
1236
+ // vectorExtensionLoaded here: the flag means "successfully loaded", and a
1237
+ // subsequent call would otherwise short-circuit to `return true` at the top.
1238
+ if (process.platform === 'win32')
1239
+ return false;
1240
+ if (!isVectorExtensionSupportedByPlatform())
1241
+ return false;
1242
+ const c = targetConn ?? conn;
1243
+ if (!c) {
1244
+ throw new Error('LadybugDB not initialized. Call initLbug first.');
1245
+ }
1246
+ const loaded = await extensionManager.ensure((sql) => queryAndDrain(c, sql), 'VECTOR', 'VECTOR', opts);
1247
+ if (loaded && useModuleState)
1248
+ vectorExtensionLoaded = true;
1249
+ return loaded;
1250
+ };
1251
+ /**
1252
+ * Create a full-text search index on a table
1253
+ * @param tableName - The node table name (e.g., 'File', 'CodeSymbol')
1254
+ * @param indexName - Name for the FTS index
1255
+ * @param properties - List of properties to index (e.g., ['name', 'code'])
1256
+ * @param stemmer - Stemming algorithm (default: 'porter')
1257
+ */
1258
+ export const createFTSIndex = async (tableName, indexName, properties, stemmer = 'porter') => {
1259
+ if (!conn) {
1260
+ throw new Error('LadybugDB not initialized. Call initLbug first.');
1261
+ }
1262
+ const key = ftsIndexKey(tableName, indexName);
1263
+ if (ensuredFTSIndexes.has(key))
1264
+ return;
1265
+ if (!(await loadFTSExtension())) {
1266
+ return;
1267
+ }
1268
+ const propList = properties.map((p) => `'${p}'`).join(', ');
1269
+ const query = `CALL CREATE_FTS_INDEX('${tableName}', '${indexName}', [${propList}], stemmer := '${stemmer}')`;
1270
+ try {
1271
+ await queryAndDrain(conn, query);
1272
+ ensuredFTSIndexes.add(key);
1273
+ }
1274
+ catch (e) {
1275
+ if (e.message?.includes('already exists')) {
1276
+ ensuredFTSIndexes.add(key);
1277
+ return;
1278
+ }
1279
+ throw e;
1280
+ }
1281
+ };
1282
+ /**
1283
+ * Lazy-create an FTS index, caching the fact in-process.
1284
+ *
1285
+ * Kept for writable maintenance paths that need to lazily materialize an
1286
+ * index. Read-only query paths must not call this; production analysis owns
1287
+ * creating the configured search indexes before the database is served.
1288
+ *
1289
+ * Safe to call repeatedly — the in-process Set guarantees only the first
1290
+ * call hits LadybugDB. `closeLbug` clears the cache so re-init starts fresh.
1291
+ *
1292
+ * Defense in depth: if the active connection is read-only (e.g. the MCP
1293
+ * pool adapter), `CREATE_FTS_INDEX` will fail with "Cannot execute write
1294
+ * operations in a read-only database". Treat that as a no-op and cache
1295
+ * the key so callers don't loop on a path that can never succeed here —
1296
+ * the index is owned by `arc analyze` (writable) and either already
1297
+ * exists or will be created on the next analyze.
1298
+ */
1299
+ export const ensureFTSIndex = async (tableName, indexName, properties, stemmer = 'porter') => {
1300
+ const key = ftsIndexKey(tableName, indexName);
1301
+ if (ensuredFTSIndexes.has(key))
1302
+ return;
1303
+ try {
1304
+ await createFTSIndex(tableName, indexName, properties, stemmer);
1305
+ }
1306
+ catch (e) {
1307
+ // Read-only DB: writable analyze owns index creation; silently skip
1308
+ // and cache so callers don't loop on a path that can never succeed
1309
+ // here (the MCP query pool opens DBs read-only by design).
1310
+ if (isReadOnlyDbError(e)) {
1311
+ ensuredFTSIndexes.add(key);
1312
+ return;
1313
+ }
1314
+ throw e;
1315
+ }
1316
+ };
1317
+ /**
1318
+ * Query a full-text search index
1319
+ * @param tableName - The node table name
1320
+ * @param indexName - FTS index name
1321
+ * @param query - Search query string
1322
+ * @param limit - Maximum results
1323
+ * @param conjunctive - If true, all terms must match (AND); if false, any term matches (OR)
1324
+ * @returns Array of { node properties, score }
1325
+ */
1326
+ export const queryFTS = async (tableName, indexName, query, limit = 20, conjunctive = false) => {
1327
+ if (!conn) {
1328
+ throw new Error('LadybugDB not initialized. Call initLbug first.');
1329
+ }
1330
+ // Escape backslashes and single quotes to prevent Cypher injection
1331
+ const escapedQuery = query.replace(/\\/g, '\\\\').replace(/'/g, "''");
1332
+ const cypher = `
1333
+ CALL QUERY_FTS_INDEX('${tableName}', '${indexName}', '${escapedQuery}', conjunctive := ${conjunctive})
1334
+ RETURN node, score
1335
+ ORDER BY score DESC
1336
+ LIMIT ${limit}
1337
+ `;
1338
+ try {
1339
+ const queryResult = await conn.query(cypher);
1340
+ const rows = await readQueryRows(queryResult);
1341
+ return rows.map((row) => {
1342
+ const node = row.node || row[0] || {};
1343
+ const score = row.score ?? row[1] ?? 0;
1344
+ return {
1345
+ nodeId: node.nodeId || node.id || '',
1346
+ name: node.name || '',
1347
+ filePath: node.filePath || '',
1348
+ score: typeof score === 'number' ? score : parseFloat(score) || 0,
1349
+ ...node,
1350
+ };
1351
+ });
1352
+ }
1353
+ catch (e) {
1354
+ // Return empty if index doesn't exist yet
1355
+ if (e.message?.includes('does not exist')) {
1356
+ return [];
1357
+ }
1358
+ throw e;
1359
+ }
1360
+ };
1361
+ /**
1362
+ * Drop an FTS index
1363
+ */
1364
+ export const dropFTSIndex = async (tableName, indexName) => {
1365
+ if (!conn) {
1366
+ throw new Error('LadybugDB not initialized. Call initLbug first.');
1367
+ }
1368
+ try {
1369
+ await queryAndDrain(conn, `CALL DROP_FTS_INDEX('${tableName}', '${indexName}')`);
1370
+ }
1371
+ catch {
1372
+ // Index may not exist
1373
+ }
1374
+ finally {
1375
+ ensuredFTSIndexes.delete(ftsIndexKey(tableName, indexName));
1376
+ }
1377
+ };