@codragraph/cli 1.6.2

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 (909) hide show
  1. package/README.md +341 -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 +55 -0
  7. package/dist/_shared/index.d.ts.map +1 -0
  8. package/dist/_shared/index.js +39 -0
  9. package/dist/_shared/index.js.map +1 -0
  10. package/dist/_shared/language-detection.d.ts +23 -0
  11. package/dist/_shared/language-detection.d.ts.map +1 -0
  12. package/dist/_shared/language-detection.js +139 -0
  13. package/dist/_shared/language-detection.js.map +1 -0
  14. package/dist/_shared/languages.d.ts +26 -0
  15. package/dist/_shared/languages.d.ts.map +1 -0
  16. package/dist/_shared/languages.js +27 -0
  17. package/dist/_shared/languages.js.map +1 -0
  18. package/dist/_shared/lbug/schema-constants.d.ts +16 -0
  19. package/dist/_shared/lbug/schema-constants.d.ts.map +1 -0
  20. package/dist/_shared/lbug/schema-constants.js +67 -0
  21. package/dist/_shared/lbug/schema-constants.js.map +1 -0
  22. package/dist/_shared/mro-strategy.d.ts +41 -0
  23. package/dist/_shared/mro-strategy.d.ts.map +1 -0
  24. package/dist/_shared/mro-strategy.js +2 -0
  25. package/dist/_shared/mro-strategy.js.map +1 -0
  26. package/dist/_shared/pipeline.d.ts +16 -0
  27. package/dist/_shared/pipeline.d.ts.map +1 -0
  28. package/dist/_shared/pipeline.js +5 -0
  29. package/dist/_shared/pipeline.js.map +1 -0
  30. package/dist/_shared/scope-resolution/def-index.d.ts +36 -0
  31. package/dist/_shared/scope-resolution/def-index.d.ts.map +1 -0
  32. package/dist/_shared/scope-resolution/def-index.js +51 -0
  33. package/dist/_shared/scope-resolution/def-index.js.map +1 -0
  34. package/dist/_shared/scope-resolution/evidence-weights.d.ts +69 -0
  35. package/dist/_shared/scope-resolution/evidence-weights.d.ts.map +1 -0
  36. package/dist/_shared/scope-resolution/evidence-weights.js +84 -0
  37. package/dist/_shared/scope-resolution/evidence-weights.js.map +1 -0
  38. package/dist/_shared/scope-resolution/finalize-algorithm.d.ts +139 -0
  39. package/dist/_shared/scope-resolution/finalize-algorithm.d.ts.map +1 -0
  40. package/dist/_shared/scope-resolution/finalize-algorithm.js +479 -0
  41. package/dist/_shared/scope-resolution/finalize-algorithm.js.map +1 -0
  42. package/dist/_shared/scope-resolution/language-classification.d.ts +26 -0
  43. package/dist/_shared/scope-resolution/language-classification.d.ts.map +1 -0
  44. package/dist/_shared/scope-resolution/language-classification.js +44 -0
  45. package/dist/_shared/scope-resolution/language-classification.js.map +1 -0
  46. package/dist/_shared/scope-resolution/method-dispatch-index.d.ts +80 -0
  47. package/dist/_shared/scope-resolution/method-dispatch-index.d.ts.map +1 -0
  48. package/dist/_shared/scope-resolution/method-dispatch-index.js +79 -0
  49. package/dist/_shared/scope-resolution/method-dispatch-index.js.map +1 -0
  50. package/dist/_shared/scope-resolution/module-scope-index.d.ts +46 -0
  51. package/dist/_shared/scope-resolution/module-scope-index.d.ts.map +1 -0
  52. package/dist/_shared/scope-resolution/module-scope-index.js +58 -0
  53. package/dist/_shared/scope-resolution/module-scope-index.js.map +1 -0
  54. package/dist/_shared/scope-resolution/origin-priority.d.ts +14 -0
  55. package/dist/_shared/scope-resolution/origin-priority.d.ts.map +1 -0
  56. package/dist/_shared/scope-resolution/origin-priority.js +21 -0
  57. package/dist/_shared/scope-resolution/origin-priority.js.map +1 -0
  58. package/dist/_shared/scope-resolution/parsed-file.d.ts +76 -0
  59. package/dist/_shared/scope-resolution/parsed-file.d.ts.map +1 -0
  60. package/dist/_shared/scope-resolution/parsed-file.js +54 -0
  61. package/dist/_shared/scope-resolution/parsed-file.js.map +1 -0
  62. package/dist/_shared/scope-resolution/position-index.d.ts +62 -0
  63. package/dist/_shared/scope-resolution/position-index.d.ts.map +1 -0
  64. package/dist/_shared/scope-resolution/position-index.js +134 -0
  65. package/dist/_shared/scope-resolution/position-index.js.map +1 -0
  66. package/dist/_shared/scope-resolution/qualified-name-index.d.ts +44 -0
  67. package/dist/_shared/scope-resolution/qualified-name-index.d.ts.map +1 -0
  68. package/dist/_shared/scope-resolution/qualified-name-index.js +75 -0
  69. package/dist/_shared/scope-resolution/qualified-name-index.js.map +1 -0
  70. package/dist/_shared/scope-resolution/reference-site.d.ts +75 -0
  71. package/dist/_shared/scope-resolution/reference-site.d.ts.map +1 -0
  72. package/dist/_shared/scope-resolution/reference-site.js +24 -0
  73. package/dist/_shared/scope-resolution/reference-site.js.map +1 -0
  74. package/dist/_shared/scope-resolution/registries/class-registry.d.ts +27 -0
  75. package/dist/_shared/scope-resolution/registries/class-registry.d.ts.map +1 -0
  76. package/dist/_shared/scope-resolution/registries/class-registry.js +30 -0
  77. package/dist/_shared/scope-resolution/registries/class-registry.js.map +1 -0
  78. package/dist/_shared/scope-resolution/registries/context.d.ts +69 -0
  79. package/dist/_shared/scope-resolution/registries/context.d.ts.map +1 -0
  80. package/dist/_shared/scope-resolution/registries/context.js +44 -0
  81. package/dist/_shared/scope-resolution/registries/context.js.map +1 -0
  82. package/dist/_shared/scope-resolution/registries/evidence.d.ts +56 -0
  83. package/dist/_shared/scope-resolution/registries/evidence.d.ts.map +1 -0
  84. package/dist/_shared/scope-resolution/registries/evidence.js +150 -0
  85. package/dist/_shared/scope-resolution/registries/evidence.js.map +1 -0
  86. package/dist/_shared/scope-resolution/registries/field-registry.d.ts +26 -0
  87. package/dist/_shared/scope-resolution/registries/field-registry.d.ts.map +1 -0
  88. package/dist/_shared/scope-resolution/registries/field-registry.js +31 -0
  89. package/dist/_shared/scope-resolution/registries/field-registry.js.map +1 -0
  90. package/dist/_shared/scope-resolution/registries/lookup-core.d.ts +81 -0
  91. package/dist/_shared/scope-resolution/registries/lookup-core.d.ts.map +1 -0
  92. package/dist/_shared/scope-resolution/registries/lookup-core.js +332 -0
  93. package/dist/_shared/scope-resolution/registries/lookup-core.js.map +1 -0
  94. package/dist/_shared/scope-resolution/registries/lookup-qualified.d.ts +33 -0
  95. package/dist/_shared/scope-resolution/registries/lookup-qualified.d.ts.map +1 -0
  96. package/dist/_shared/scope-resolution/registries/lookup-qualified.js +56 -0
  97. package/dist/_shared/scope-resolution/registries/lookup-qualified.js.map +1 -0
  98. package/dist/_shared/scope-resolution/registries/method-registry.d.ts +36 -0
  99. package/dist/_shared/scope-resolution/registries/method-registry.d.ts.map +1 -0
  100. package/dist/_shared/scope-resolution/registries/method-registry.js +32 -0
  101. package/dist/_shared/scope-resolution/registries/method-registry.js.map +1 -0
  102. package/dist/_shared/scope-resolution/registries/tie-breaks.d.ts +43 -0
  103. package/dist/_shared/scope-resolution/registries/tie-breaks.d.ts.map +1 -0
  104. package/dist/_shared/scope-resolution/registries/tie-breaks.js +60 -0
  105. package/dist/_shared/scope-resolution/registries/tie-breaks.js.map +1 -0
  106. package/dist/_shared/scope-resolution/resolve-type-ref.d.ts +53 -0
  107. package/dist/_shared/scope-resolution/resolve-type-ref.d.ts.map +1 -0
  108. package/dist/_shared/scope-resolution/resolve-type-ref.js +126 -0
  109. package/dist/_shared/scope-resolution/resolve-type-ref.js.map +1 -0
  110. package/dist/_shared/scope-resolution/scope-id.d.ts +43 -0
  111. package/dist/_shared/scope-resolution/scope-id.d.ts.map +1 -0
  112. package/dist/_shared/scope-resolution/scope-id.js +46 -0
  113. package/dist/_shared/scope-resolution/scope-id.js.map +1 -0
  114. package/dist/_shared/scope-resolution/scope-tree.d.ts +61 -0
  115. package/dist/_shared/scope-resolution/scope-tree.d.ts.map +1 -0
  116. package/dist/_shared/scope-resolution/scope-tree.js +186 -0
  117. package/dist/_shared/scope-resolution/scope-tree.js.map +1 -0
  118. package/dist/_shared/scope-resolution/shadow/aggregate.d.ts +63 -0
  119. package/dist/_shared/scope-resolution/shadow/aggregate.d.ts.map +1 -0
  120. package/dist/_shared/scope-resolution/shadow/aggregate.js +122 -0
  121. package/dist/_shared/scope-resolution/shadow/aggregate.js.map +1 -0
  122. package/dist/_shared/scope-resolution/shadow/diff.d.ts +59 -0
  123. package/dist/_shared/scope-resolution/shadow/diff.d.ts.map +1 -0
  124. package/dist/_shared/scope-resolution/shadow/diff.js +79 -0
  125. package/dist/_shared/scope-resolution/shadow/diff.js.map +1 -0
  126. package/dist/_shared/scope-resolution/symbol-definition.d.ts +34 -0
  127. package/dist/_shared/scope-resolution/symbol-definition.d.ts.map +1 -0
  128. package/dist/_shared/scope-resolution/symbol-definition.js +12 -0
  129. package/dist/_shared/scope-resolution/symbol-definition.js.map +1 -0
  130. package/dist/_shared/scope-resolution/types.d.ts +356 -0
  131. package/dist/_shared/scope-resolution/types.d.ts.map +1 -0
  132. package/dist/_shared/scope-resolution/types.js +17 -0
  133. package/dist/_shared/scope-resolution/types.js.map +1 -0
  134. package/dist/cli/ai-context.d.ts +27 -0
  135. package/dist/cli/ai-context.js +270 -0
  136. package/dist/cli/analyze.d.ts +43 -0
  137. package/dist/cli/analyze.js +312 -0
  138. package/dist/cli/augment.d.ts +13 -0
  139. package/dist/cli/augment.js +33 -0
  140. package/dist/cli/clean.d.ts +10 -0
  141. package/dist/cli/clean.js +78 -0
  142. package/dist/cli/config.d.ts +27 -0
  143. package/dist/cli/config.js +106 -0
  144. package/dist/cli/eval-server.d.ts +37 -0
  145. package/dist/cli/eval-server.js +398 -0
  146. package/dist/cli/graphstore.d.ts +40 -0
  147. package/dist/cli/graphstore.js +639 -0
  148. package/dist/cli/group.d.ts +2 -0
  149. package/dist/cli/group.js +306 -0
  150. package/dist/cli/index-repo.d.ts +15 -0
  151. package/dist/cli/index-repo.js +120 -0
  152. package/dist/cli/index.d.ts +2 -0
  153. package/dist/cli/index.js +236 -0
  154. package/dist/cli/lazy-action.d.ts +6 -0
  155. package/dist/cli/lazy-action.js +18 -0
  156. package/dist/cli/list.d.ts +6 -0
  157. package/dist/cli/list.js +40 -0
  158. package/dist/cli/mcp.d.ts +8 -0
  159. package/dist/cli/mcp.js +36 -0
  160. package/dist/cli/remove.d.ts +30 -0
  161. package/dist/cli/remove.js +99 -0
  162. package/dist/cli/serve.d.ts +4 -0
  163. package/dist/cli/serve.js +37 -0
  164. package/dist/cli/setup.d.ts +8 -0
  165. package/dist/cli/setup.js +543 -0
  166. package/dist/cli/skill-gen.d.ts +26 -0
  167. package/dist/cli/skill-gen.js +555 -0
  168. package/dist/cli/status.d.ts +6 -0
  169. package/dist/cli/status.js +36 -0
  170. package/dist/cli/tool.d.ts +43 -0
  171. package/dist/cli/tool.js +168 -0
  172. package/dist/cli/wiki.d.ts +21 -0
  173. package/dist/cli/wiki.js +579 -0
  174. package/dist/config/ignore-service.d.ts +35 -0
  175. package/dist/config/ignore-service.js +436 -0
  176. package/dist/config/supported-languages.d.ts +13 -0
  177. package/dist/config/supported-languages.js +13 -0
  178. package/dist/core/augmentation/engine.d.ts +26 -0
  179. package/dist/core/augmentation/engine.js +252 -0
  180. package/dist/core/embeddings/ast-utils.d.ts +22 -0
  181. package/dist/core/embeddings/ast-utils.js +105 -0
  182. package/dist/core/embeddings/character-chunk.d.ts +12 -0
  183. package/dist/core/embeddings/character-chunk.js +43 -0
  184. package/dist/core/embeddings/chunker.d.ts +14 -0
  185. package/dist/core/embeddings/chunker.js +239 -0
  186. package/dist/core/embeddings/embedder.d.ts +65 -0
  187. package/dist/core/embeddings/embedder.js +320 -0
  188. package/dist/core/embeddings/embedding-pipeline.d.ts +62 -0
  189. package/dist/core/embeddings/embedding-pipeline.js +486 -0
  190. package/dist/core/embeddings/http-client.d.ts +31 -0
  191. package/dist/core/embeddings/http-client.js +179 -0
  192. package/dist/core/embeddings/index.d.ts +10 -0
  193. package/dist/core/embeddings/index.js +10 -0
  194. package/dist/core/embeddings/line-index.d.ts +7 -0
  195. package/dist/core/embeddings/line-index.js +42 -0
  196. package/dist/core/embeddings/server-mapping.d.ts +15 -0
  197. package/dist/core/embeddings/server-mapping.js +33 -0
  198. package/dist/core/embeddings/structural-extractor.d.ts +15 -0
  199. package/dist/core/embeddings/structural-extractor.js +58 -0
  200. package/dist/core/embeddings/text-generator.d.ts +31 -0
  201. package/dist/core/embeddings/text-generator.js +208 -0
  202. package/dist/core/embeddings/types.d.ts +207 -0
  203. package/dist/core/embeddings/types.js +200 -0
  204. package/dist/core/git-staleness.d.ts +31 -0
  205. package/dist/core/git-staleness.js +137 -0
  206. package/dist/core/graph/graph.d.ts +2 -0
  207. package/dist/core/graph/graph.js +173 -0
  208. package/dist/core/graph/types.d.ts +36 -0
  209. package/dist/core/graph/types.js +1 -0
  210. package/dist/core/graphstore/index.d.ts +46 -0
  211. package/dist/core/graphstore/index.js +80 -0
  212. package/dist/core/graphstore/lbug-row-source.d.ts +19 -0
  213. package/dist/core/graphstore/lbug-row-source.js +141 -0
  214. package/dist/core/group/bridge-db.d.ts +82 -0
  215. package/dist/core/group/bridge-db.js +460 -0
  216. package/dist/core/group/bridge-schema.d.ts +27 -0
  217. package/dist/core/group/bridge-schema.js +55 -0
  218. package/dist/core/group/config-parser.d.ts +7 -0
  219. package/dist/core/group/config-parser.js +100 -0
  220. package/dist/core/group/contract-extractor.d.ts +7 -0
  221. package/dist/core/group/contract-extractor.js +1 -0
  222. package/dist/core/group/cross-impact.d.ts +41 -0
  223. package/dist/core/group/cross-impact.js +441 -0
  224. package/dist/core/group/extractors/fs-utils.d.ts +10 -0
  225. package/dist/core/group/extractors/fs-utils.js +24 -0
  226. package/dist/core/group/extractors/grpc-extractor.d.ts +25 -0
  227. package/dist/core/group/extractors/grpc-extractor.js +401 -0
  228. package/dist/core/group/extractors/grpc-patterns/go.d.ts +2 -0
  229. package/dist/core/group/extractors/grpc-patterns/go.js +97 -0
  230. package/dist/core/group/extractors/grpc-patterns/index.d.ts +19 -0
  231. package/dist/core/group/extractors/grpc-patterns/index.js +46 -0
  232. package/dist/core/group/extractors/grpc-patterns/java.d.ts +2 -0
  233. package/dist/core/group/extractors/grpc-patterns/java.js +173 -0
  234. package/dist/core/group/extractors/grpc-patterns/node.d.ts +4 -0
  235. package/dist/core/group/extractors/grpc-patterns/node.js +290 -0
  236. package/dist/core/group/extractors/grpc-patterns/proto.d.ts +9 -0
  237. package/dist/core/group/extractors/grpc-patterns/proto.js +134 -0
  238. package/dist/core/group/extractors/grpc-patterns/python.d.ts +2 -0
  239. package/dist/core/group/extractors/grpc-patterns/python.js +67 -0
  240. package/dist/core/group/extractors/grpc-patterns/types.d.ts +50 -0
  241. package/dist/core/group/extractors/grpc-patterns/types.js +1 -0
  242. package/dist/core/group/extractors/http-patterns/go.d.ts +2 -0
  243. package/dist/core/group/extractors/http-patterns/go.js +215 -0
  244. package/dist/core/group/extractors/http-patterns/index.d.ts +17 -0
  245. package/dist/core/group/extractors/http-patterns/index.js +44 -0
  246. package/dist/core/group/extractors/http-patterns/java.d.ts +2 -0
  247. package/dist/core/group/extractors/http-patterns/java.js +253 -0
  248. package/dist/core/group/extractors/http-patterns/node.d.ts +4 -0
  249. package/dist/core/group/extractors/http-patterns/node.js +484 -0
  250. package/dist/core/group/extractors/http-patterns/php.d.ts +2 -0
  251. package/dist/core/group/extractors/http-patterns/php.js +178 -0
  252. package/dist/core/group/extractors/http-patterns/python.d.ts +2 -0
  253. package/dist/core/group/extractors/http-patterns/python.js +133 -0
  254. package/dist/core/group/extractors/http-patterns/types.d.ts +61 -0
  255. package/dist/core/group/extractors/http-patterns/types.js +1 -0
  256. package/dist/core/group/extractors/http-route-extractor.d.ts +21 -0
  257. package/dist/core/group/extractors/http-route-extractor.js +421 -0
  258. package/dist/core/group/extractors/manifest-extractor.d.ts +54 -0
  259. package/dist/core/group/extractors/manifest-extractor.js +292 -0
  260. package/dist/core/group/extractors/topic-extractor.d.ts +8 -0
  261. package/dist/core/group/extractors/topic-extractor.js +97 -0
  262. package/dist/core/group/extractors/topic-patterns/go.d.ts +2 -0
  263. package/dist/core/group/extractors/topic-patterns/go.js +120 -0
  264. package/dist/core/group/extractors/topic-patterns/index.d.ts +14 -0
  265. package/dist/core/group/extractors/topic-patterns/index.js +38 -0
  266. package/dist/core/group/extractors/topic-patterns/java.d.ts +2 -0
  267. package/dist/core/group/extractors/topic-patterns/java.js +80 -0
  268. package/dist/core/group/extractors/topic-patterns/node.d.ts +4 -0
  269. package/dist/core/group/extractors/topic-patterns/node.js +155 -0
  270. package/dist/core/group/extractors/topic-patterns/python.d.ts +2 -0
  271. package/dist/core/group/extractors/topic-patterns/python.js +116 -0
  272. package/dist/core/group/extractors/topic-patterns/types.d.ts +25 -0
  273. package/dist/core/group/extractors/topic-patterns/types.js +10 -0
  274. package/dist/core/group/extractors/tree-sitter-scanner.d.ts +113 -0
  275. package/dist/core/group/extractors/tree-sitter-scanner.js +94 -0
  276. package/dist/core/group/group-path-utils.d.ts +17 -0
  277. package/dist/core/group/group-path-utils.js +40 -0
  278. package/dist/core/group/matching.d.ts +13 -0
  279. package/dist/core/group/matching.js +198 -0
  280. package/dist/core/group/normalization.d.ts +3 -0
  281. package/dist/core/group/normalization.js +115 -0
  282. package/dist/core/group/resolve-at-member.d.ts +10 -0
  283. package/dist/core/group/resolve-at-member.js +31 -0
  284. package/dist/core/group/service-boundary-detector.d.ts +8 -0
  285. package/dist/core/group/service-boundary-detector.js +155 -0
  286. package/dist/core/group/service.d.ts +55 -0
  287. package/dist/core/group/service.js +394 -0
  288. package/dist/core/group/storage.d.ts +9 -0
  289. package/dist/core/group/storage.js +91 -0
  290. package/dist/core/group/sync.d.ts +21 -0
  291. package/dist/core/group/sync.js +196 -0
  292. package/dist/core/group/types.d.ts +160 -0
  293. package/dist/core/group/types.js +1 -0
  294. package/dist/core/ingestion/ast-cache.d.ts +26 -0
  295. package/dist/core/ingestion/ast-cache.js +47 -0
  296. package/dist/core/ingestion/binding-accumulator.d.ts +212 -0
  297. package/dist/core/ingestion/binding-accumulator.js +336 -0
  298. package/dist/core/ingestion/call-extractors/configs/c-cpp.d.ts +3 -0
  299. package/dist/core/ingestion/call-extractors/configs/c-cpp.js +8 -0
  300. package/dist/core/ingestion/call-extractors/configs/csharp.d.ts +2 -0
  301. package/dist/core/ingestion/call-extractors/configs/csharp.js +6 -0
  302. package/dist/core/ingestion/call-extractors/configs/dart.d.ts +2 -0
  303. package/dist/core/ingestion/call-extractors/configs/dart.js +5 -0
  304. package/dist/core/ingestion/call-extractors/configs/go.d.ts +2 -0
  305. package/dist/core/ingestion/call-extractors/configs/go.js +5 -0
  306. package/dist/core/ingestion/call-extractors/configs/jvm.d.ts +3 -0
  307. package/dist/core/ingestion/call-extractors/configs/jvm.js +51 -0
  308. package/dist/core/ingestion/call-extractors/configs/php.d.ts +2 -0
  309. package/dist/core/ingestion/call-extractors/configs/php.js +5 -0
  310. package/dist/core/ingestion/call-extractors/configs/python.d.ts +2 -0
  311. package/dist/core/ingestion/call-extractors/configs/python.js +5 -0
  312. package/dist/core/ingestion/call-extractors/configs/ruby.d.ts +2 -0
  313. package/dist/core/ingestion/call-extractors/configs/ruby.js +5 -0
  314. package/dist/core/ingestion/call-extractors/configs/rust.d.ts +2 -0
  315. package/dist/core/ingestion/call-extractors/configs/rust.js +5 -0
  316. package/dist/core/ingestion/call-extractors/configs/swift.d.ts +2 -0
  317. package/dist/core/ingestion/call-extractors/configs/swift.js +5 -0
  318. package/dist/core/ingestion/call-extractors/configs/typescript-javascript.d.ts +3 -0
  319. package/dist/core/ingestion/call-extractors/configs/typescript-javascript.js +8 -0
  320. package/dist/core/ingestion/call-extractors/generic.d.ts +5 -0
  321. package/dist/core/ingestion/call-extractors/generic.js +59 -0
  322. package/dist/core/ingestion/call-processor.d.ts +235 -0
  323. package/dist/core/ingestion/call-processor.js +2639 -0
  324. package/dist/core/ingestion/call-routing.d.ts +55 -0
  325. package/dist/core/ingestion/call-routing.js +95 -0
  326. package/dist/core/ingestion/call-types.d.ts +135 -0
  327. package/dist/core/ingestion/call-types.js +2 -0
  328. package/dist/core/ingestion/class-extractors/configs/c-cpp.d.ts +3 -0
  329. package/dist/core/ingestion/class-extractors/configs/c-cpp.js +11 -0
  330. package/dist/core/ingestion/class-extractors/configs/csharp.d.ts +2 -0
  331. package/dist/core/ingestion/class-extractors/configs/csharp.js +21 -0
  332. package/dist/core/ingestion/class-extractors/configs/dart.d.ts +2 -0
  333. package/dist/core/ingestion/class-extractors/configs/dart.js +7 -0
  334. package/dist/core/ingestion/class-extractors/configs/go.d.ts +2 -0
  335. package/dist/core/ingestion/class-extractors/configs/go.js +20 -0
  336. package/dist/core/ingestion/class-extractors/configs/jvm.d.ts +3 -0
  337. package/dist/core/ingestion/class-extractors/configs/jvm.js +35 -0
  338. package/dist/core/ingestion/class-extractors/configs/php.d.ts +2 -0
  339. package/dist/core/ingestion/class-extractors/configs/php.js +7 -0
  340. package/dist/core/ingestion/class-extractors/configs/python.d.ts +2 -0
  341. package/dist/core/ingestion/class-extractors/configs/python.js +7 -0
  342. package/dist/core/ingestion/class-extractors/configs/ruby.d.ts +2 -0
  343. package/dist/core/ingestion/class-extractors/configs/ruby.js +7 -0
  344. package/dist/core/ingestion/class-extractors/configs/rust.d.ts +2 -0
  345. package/dist/core/ingestion/class-extractors/configs/rust.js +7 -0
  346. package/dist/core/ingestion/class-extractors/configs/swift.d.ts +2 -0
  347. package/dist/core/ingestion/class-extractors/configs/swift.js +18 -0
  348. package/dist/core/ingestion/class-extractors/configs/typescript-javascript.d.ts +4 -0
  349. package/dist/core/ingestion/class-extractors/configs/typescript-javascript.js +28 -0
  350. package/dist/core/ingestion/class-extractors/generic.d.ts +2 -0
  351. package/dist/core/ingestion/class-extractors/generic.js +135 -0
  352. package/dist/core/ingestion/class-types.d.ts +34 -0
  353. package/dist/core/ingestion/class-types.js +1 -0
  354. package/dist/core/ingestion/cluster-enricher.d.ts +38 -0
  355. package/dist/core/ingestion/cluster-enricher.js +168 -0
  356. package/dist/core/ingestion/cobol/cobol-copy-expander.d.ts +57 -0
  357. package/dist/core/ingestion/cobol/cobol-copy-expander.js +392 -0
  358. package/dist/core/ingestion/cobol/cobol-preprocessor.d.ts +210 -0
  359. package/dist/core/ingestion/cobol/cobol-preprocessor.js +1715 -0
  360. package/dist/core/ingestion/cobol/jcl-parser.d.ts +68 -0
  361. package/dist/core/ingestion/cobol/jcl-parser.js +217 -0
  362. package/dist/core/ingestion/cobol/jcl-processor.d.ts +33 -0
  363. package/dist/core/ingestion/cobol/jcl-processor.js +229 -0
  364. package/dist/core/ingestion/cobol-processor.d.ts +54 -0
  365. package/dist/core/ingestion/cobol-processor.js +1232 -0
  366. package/dist/core/ingestion/community-processor.d.ts +39 -0
  367. package/dist/core/ingestion/community-processor.js +318 -0
  368. package/dist/core/ingestion/constants.d.ts +16 -0
  369. package/dist/core/ingestion/constants.js +16 -0
  370. package/dist/core/ingestion/emit-references.d.ts +88 -0
  371. package/dist/core/ingestion/emit-references.js +229 -0
  372. package/dist/core/ingestion/entry-point-scoring.d.ts +58 -0
  373. package/dist/core/ingestion/entry-point-scoring.js +380 -0
  374. package/dist/core/ingestion/export-detection.d.ts +57 -0
  375. package/dist/core/ingestion/export-detection.js +233 -0
  376. package/dist/core/ingestion/field-extractor.d.ts +29 -0
  377. package/dist/core/ingestion/field-extractor.js +25 -0
  378. package/dist/core/ingestion/field-extractors/configs/c-cpp.d.ts +3 -0
  379. package/dist/core/ingestion/field-extractors/configs/c-cpp.js +104 -0
  380. package/dist/core/ingestion/field-extractors/configs/csharp.d.ts +8 -0
  381. package/dist/core/ingestion/field-extractors/configs/csharp.js +116 -0
  382. package/dist/core/ingestion/field-extractors/configs/dart.d.ts +8 -0
  383. package/dist/core/ingestion/field-extractors/configs/dart.js +78 -0
  384. package/dist/core/ingestion/field-extractors/configs/go.d.ts +11 -0
  385. package/dist/core/ingestion/field-extractors/configs/go.js +60 -0
  386. package/dist/core/ingestion/field-extractors/configs/helpers.d.ts +53 -0
  387. package/dist/core/ingestion/field-extractors/configs/helpers.js +158 -0
  388. package/dist/core/ingestion/field-extractors/configs/jvm.d.ts +3 -0
  389. package/dist/core/ingestion/field-extractors/configs/jvm.js +118 -0
  390. package/dist/core/ingestion/field-extractors/configs/php.d.ts +8 -0
  391. package/dist/core/ingestion/field-extractors/configs/php.js +65 -0
  392. package/dist/core/ingestion/field-extractors/configs/python.d.ts +12 -0
  393. package/dist/core/ingestion/field-extractors/configs/python.js +91 -0
  394. package/dist/core/ingestion/field-extractors/configs/ruby.d.ts +16 -0
  395. package/dist/core/ingestion/field-extractors/configs/ruby.js +76 -0
  396. package/dist/core/ingestion/field-extractors/configs/rust.d.ts +9 -0
  397. package/dist/core/ingestion/field-extractors/configs/rust.js +52 -0
  398. package/dist/core/ingestion/field-extractors/configs/swift.d.ts +8 -0
  399. package/dist/core/ingestion/field-extractors/configs/swift.js +65 -0
  400. package/dist/core/ingestion/field-extractors/configs/typescript-javascript.d.ts +3 -0
  401. package/dist/core/ingestion/field-extractors/configs/typescript-javascript.js +56 -0
  402. package/dist/core/ingestion/field-extractors/generic.d.ts +49 -0
  403. package/dist/core/ingestion/field-extractors/generic.js +117 -0
  404. package/dist/core/ingestion/field-extractors/typescript.d.ts +77 -0
  405. package/dist/core/ingestion/field-extractors/typescript.js +291 -0
  406. package/dist/core/ingestion/field-types.d.ts +61 -0
  407. package/dist/core/ingestion/field-types.js +2 -0
  408. package/dist/core/ingestion/filesystem-walker.d.ts +28 -0
  409. package/dist/core/ingestion/filesystem-walker.js +91 -0
  410. package/dist/core/ingestion/finalize-orchestrator.d.ts +63 -0
  411. package/dist/core/ingestion/finalize-orchestrator.js +139 -0
  412. package/dist/core/ingestion/framework-detection.d.ts +150 -0
  413. package/dist/core/ingestion/framework-detection.js +786 -0
  414. package/dist/core/ingestion/heritage-extractors/configs/go.d.ts +13 -0
  415. package/dist/core/ingestion/heritage-extractors/configs/go.js +20 -0
  416. package/dist/core/ingestion/heritage-extractors/configs/ruby.d.ts +18 -0
  417. package/dist/core/ingestion/heritage-extractors/configs/ruby.js +65 -0
  418. package/dist/core/ingestion/heritage-extractors/generic.d.ts +23 -0
  419. package/dist/core/ingestion/heritage-extractors/generic.js +47 -0
  420. package/dist/core/ingestion/heritage-processor.d.ts +54 -0
  421. package/dist/core/ingestion/heritage-processor.js +360 -0
  422. package/dist/core/ingestion/heritage-types.d.ts +73 -0
  423. package/dist/core/ingestion/heritage-types.js +2 -0
  424. package/dist/core/ingestion/import-processor.d.ts +23 -0
  425. package/dist/core/ingestion/import-processor.js +373 -0
  426. package/dist/core/ingestion/import-resolvers/configs/c-cpp.d.ts +7 -0
  427. package/dist/core/ingestion/import-resolvers/configs/c-cpp.js +14 -0
  428. package/dist/core/ingestion/import-resolvers/configs/csharp.d.ts +8 -0
  429. package/dist/core/ingestion/import-resolvers/configs/csharp.js +27 -0
  430. package/dist/core/ingestion/import-resolvers/configs/dart.d.ts +17 -0
  431. package/dist/core/ingestion/import-resolvers/configs/dart.js +54 -0
  432. package/dist/core/ingestion/import-resolvers/configs/go.d.ts +8 -0
  433. package/dist/core/ingestion/import-resolvers/configs/go.js +26 -0
  434. package/dist/core/ingestion/import-resolvers/configs/jvm.d.ts +13 -0
  435. package/dist/core/ingestion/import-resolvers/configs/jvm.js +68 -0
  436. package/dist/core/ingestion/import-resolvers/configs/php.d.ts +8 -0
  437. package/dist/core/ingestion/import-resolvers/configs/php.js +15 -0
  438. package/dist/core/ingestion/import-resolvers/configs/python.d.ts +12 -0
  439. package/dist/core/ingestion/import-resolvers/configs/python.js +41 -0
  440. package/dist/core/ingestion/import-resolvers/configs/ruby.d.ts +8 -0
  441. package/dist/core/ingestion/import-resolvers/configs/ruby.js +16 -0
  442. package/dist/core/ingestion/import-resolvers/configs/rust.d.ts +8 -0
  443. package/dist/core/ingestion/import-resolvers/configs/rust.js +54 -0
  444. package/dist/core/ingestion/import-resolvers/configs/swift.d.ts +8 -0
  445. package/dist/core/ingestion/import-resolvers/configs/swift.js +29 -0
  446. package/dist/core/ingestion/import-resolvers/configs/typescript-javascript.d.ts +9 -0
  447. package/dist/core/ingestion/import-resolvers/configs/typescript-javascript.js +23 -0
  448. package/dist/core/ingestion/import-resolvers/csharp.d.ts +18 -0
  449. package/dist/core/ingestion/import-resolvers/csharp.js +115 -0
  450. package/dist/core/ingestion/import-resolvers/go.d.ts +17 -0
  451. package/dist/core/ingestion/import-resolvers/go.js +46 -0
  452. package/dist/core/ingestion/import-resolvers/jvm.d.ts +27 -0
  453. package/dist/core/ingestion/import-resolvers/jvm.js +106 -0
  454. package/dist/core/ingestion/import-resolvers/php.d.ts +24 -0
  455. package/dist/core/ingestion/import-resolvers/php.js +77 -0
  456. package/dist/core/ingestion/import-resolvers/python.d.ts +22 -0
  457. package/dist/core/ingestion/import-resolvers/python.js +72 -0
  458. package/dist/core/ingestion/import-resolvers/resolver-factory.d.ts +24 -0
  459. package/dist/core/ingestion/import-resolvers/resolver-factory.js +33 -0
  460. package/dist/core/ingestion/import-resolvers/ruby.d.ts +14 -0
  461. package/dist/core/ingestion/import-resolvers/ruby.js +17 -0
  462. package/dist/core/ingestion/import-resolvers/rust.d.ts +17 -0
  463. package/dist/core/ingestion/import-resolvers/rust.js +75 -0
  464. package/dist/core/ingestion/import-resolvers/standard.d.ts +30 -0
  465. package/dist/core/ingestion/import-resolvers/standard.js +142 -0
  466. package/dist/core/ingestion/import-resolvers/types.d.ts +68 -0
  467. package/dist/core/ingestion/import-resolvers/types.js +6 -0
  468. package/dist/core/ingestion/import-resolvers/utils.d.ts +35 -0
  469. package/dist/core/ingestion/import-resolvers/utils.js +149 -0
  470. package/dist/core/ingestion/import-target-adapter.d.ts +73 -0
  471. package/dist/core/ingestion/import-target-adapter.js +95 -0
  472. package/dist/core/ingestion/language-config.d.ts +52 -0
  473. package/dist/core/ingestion/language-config.js +181 -0
  474. package/dist/core/ingestion/language-provider.d.ts +410 -0
  475. package/dist/core/ingestion/language-provider.js +24 -0
  476. package/dist/core/ingestion/languages/c-cpp.d.ts +12 -0
  477. package/dist/core/ingestion/languages/c-cpp.js +329 -0
  478. package/dist/core/ingestion/languages/cobol.d.ts +1 -0
  479. package/dist/core/ingestion/languages/cobol.js +26 -0
  480. package/dist/core/ingestion/languages/csharp/accessor-unwrap.d.ts +21 -0
  481. package/dist/core/ingestion/languages/csharp/accessor-unwrap.js +56 -0
  482. package/dist/core/ingestion/languages/csharp/arity-metadata.d.ts +26 -0
  483. package/dist/core/ingestion/languages/csharp/arity-metadata.js +46 -0
  484. package/dist/core/ingestion/languages/csharp/arity.d.ts +23 -0
  485. package/dist/core/ingestion/languages/csharp/arity.js +37 -0
  486. package/dist/core/ingestion/languages/csharp/cache-stats.d.ts +15 -0
  487. package/dist/core/ingestion/languages/csharp/cache-stats.js +26 -0
  488. package/dist/core/ingestion/languages/csharp/captures.d.ts +19 -0
  489. package/dist/core/ingestion/languages/csharp/captures.js +249 -0
  490. package/dist/core/ingestion/languages/csharp/import-decomposer.d.ts +19 -0
  491. package/dist/core/ingestion/languages/csharp/import-decomposer.js +93 -0
  492. package/dist/core/ingestion/languages/csharp/import-target.d.ts +25 -0
  493. package/dist/core/ingestion/languages/csharp/import-target.js +123 -0
  494. package/dist/core/ingestion/languages/csharp/index.d.ts +82 -0
  495. package/dist/core/ingestion/languages/csharp/index.js +82 -0
  496. package/dist/core/ingestion/languages/csharp/interpret.d.ts +15 -0
  497. package/dist/core/ingestion/languages/csharp/interpret.js +132 -0
  498. package/dist/core/ingestion/languages/csharp/merge-bindings.d.ts +27 -0
  499. package/dist/core/ingestion/languages/csharp/merge-bindings.js +55 -0
  500. package/dist/core/ingestion/languages/csharp/namespace-siblings.d.ts +50 -0
  501. package/dist/core/ingestion/languages/csharp/namespace-siblings.js +374 -0
  502. package/dist/core/ingestion/languages/csharp/query.d.ts +35 -0
  503. package/dist/core/ingestion/languages/csharp/query.js +515 -0
  504. package/dist/core/ingestion/languages/csharp/receiver-binding.d.ts +31 -0
  505. package/dist/core/ingestion/languages/csharp/receiver-binding.js +135 -0
  506. package/dist/core/ingestion/languages/csharp/scope-resolver.d.ts +10 -0
  507. package/dist/core/ingestion/languages/csharp/scope-resolver.js +63 -0
  508. package/dist/core/ingestion/languages/csharp/simple-hooks.d.ts +53 -0
  509. package/dist/core/ingestion/languages/csharp/simple-hooks.js +76 -0
  510. package/dist/core/ingestion/languages/csharp.d.ts +8 -0
  511. package/dist/core/ingestion/languages/csharp.js +152 -0
  512. package/dist/core/ingestion/languages/dart.d.ts +12 -0
  513. package/dist/core/ingestion/languages/dart.js +102 -0
  514. package/dist/core/ingestion/languages/go.d.ts +11 -0
  515. package/dist/core/ingestion/languages/go.js +44 -0
  516. package/dist/core/ingestion/languages/index.d.ts +39 -0
  517. package/dist/core/ingestion/languages/index.js +64 -0
  518. package/dist/core/ingestion/languages/java.d.ts +9 -0
  519. package/dist/core/ingestion/languages/java.js +44 -0
  520. package/dist/core/ingestion/languages/kotlin.d.ts +9 -0
  521. package/dist/core/ingestion/languages/kotlin.js +123 -0
  522. package/dist/core/ingestion/languages/php.d.ts +8 -0
  523. package/dist/core/ingestion/languages/php.js +240 -0
  524. package/dist/core/ingestion/languages/python/arity-metadata.d.ts +24 -0
  525. package/dist/core/ingestion/languages/python/arity-metadata.js +45 -0
  526. package/dist/core/ingestion/languages/python/arity.d.ts +22 -0
  527. package/dist/core/ingestion/languages/python/arity.js +38 -0
  528. package/dist/core/ingestion/languages/python/cache-stats.d.ts +17 -0
  529. package/dist/core/ingestion/languages/python/cache-stats.js +28 -0
  530. package/dist/core/ingestion/languages/python/captures.d.ts +19 -0
  531. package/dist/core/ingestion/languages/python/captures.js +106 -0
  532. package/dist/core/ingestion/languages/python/import-decomposer.d.ts +15 -0
  533. package/dist/core/ingestion/languages/python/import-decomposer.js +112 -0
  534. package/dist/core/ingestion/languages/python/import-target.d.ts +21 -0
  535. package/dist/core/ingestion/languages/python/import-target.js +99 -0
  536. package/dist/core/ingestion/languages/python/index.d.ts +80 -0
  537. package/dist/core/ingestion/languages/python/index.js +80 -0
  538. package/dist/core/ingestion/languages/python/interpret.d.ts +15 -0
  539. package/dist/core/ingestion/languages/python/interpret.js +191 -0
  540. package/dist/core/ingestion/languages/python/merge-bindings.d.ts +16 -0
  541. package/dist/core/ingestion/languages/python/merge-bindings.js +44 -0
  542. package/dist/core/ingestion/languages/python/query.d.ts +9 -0
  543. package/dist/core/ingestion/languages/python/query.js +267 -0
  544. package/dist/core/ingestion/languages/python/receiver-binding.d.ts +21 -0
  545. package/dist/core/ingestion/languages/python/receiver-binding.js +116 -0
  546. package/dist/core/ingestion/languages/python/scope-resolver.d.ts +16 -0
  547. package/dist/core/ingestion/languages/python/scope-resolver.js +53 -0
  548. package/dist/core/ingestion/languages/python/simple-hooks.d.ts +23 -0
  549. package/dist/core/ingestion/languages/python/simple-hooks.js +35 -0
  550. package/dist/core/ingestion/languages/python.d.ts +12 -0
  551. package/dist/core/ingestion/languages/python.js +91 -0
  552. package/dist/core/ingestion/languages/ruby.d.ts +9 -0
  553. package/dist/core/ingestion/languages/ruby.js +210 -0
  554. package/dist/core/ingestion/languages/rust.d.ts +12 -0
  555. package/dist/core/ingestion/languages/rust.js +132 -0
  556. package/dist/core/ingestion/languages/swift.d.ts +12 -0
  557. package/dist/core/ingestion/languages/swift.js +244 -0
  558. package/dist/core/ingestion/languages/typescript.d.ts +11 -0
  559. package/dist/core/ingestion/languages/typescript.js +184 -0
  560. package/dist/core/ingestion/languages/vue.d.ts +13 -0
  561. package/dist/core/ingestion/languages/vue.js +77 -0
  562. package/dist/core/ingestion/markdown-processor.d.ts +17 -0
  563. package/dist/core/ingestion/markdown-processor.js +124 -0
  564. package/dist/core/ingestion/method-extractors/configs/c-cpp.d.ts +3 -0
  565. package/dist/core/ingestion/method-extractors/configs/c-cpp.js +387 -0
  566. package/dist/core/ingestion/method-extractors/configs/csharp.d.ts +2 -0
  567. package/dist/core/ingestion/method-extractors/configs/csharp.js +287 -0
  568. package/dist/core/ingestion/method-extractors/configs/dart.d.ts +2 -0
  569. package/dist/core/ingestion/method-extractors/configs/dart.js +376 -0
  570. package/dist/core/ingestion/method-extractors/configs/go.d.ts +2 -0
  571. package/dist/core/ingestion/method-extractors/configs/go.js +176 -0
  572. package/dist/core/ingestion/method-extractors/configs/jvm.d.ts +3 -0
  573. package/dist/core/ingestion/method-extractors/configs/jvm.js +336 -0
  574. package/dist/core/ingestion/method-extractors/configs/php.d.ts +2 -0
  575. package/dist/core/ingestion/method-extractors/configs/php.js +304 -0
  576. package/dist/core/ingestion/method-extractors/configs/python.d.ts +2 -0
  577. package/dist/core/ingestion/method-extractors/configs/python.js +309 -0
  578. package/dist/core/ingestion/method-extractors/configs/ruby.d.ts +2 -0
  579. package/dist/core/ingestion/method-extractors/configs/ruby.js +286 -0
  580. package/dist/core/ingestion/method-extractors/configs/rust.d.ts +2 -0
  581. package/dist/core/ingestion/method-extractors/configs/rust.js +195 -0
  582. package/dist/core/ingestion/method-extractors/configs/swift.d.ts +2 -0
  583. package/dist/core/ingestion/method-extractors/configs/swift.js +277 -0
  584. package/dist/core/ingestion/method-extractors/configs/typescript-javascript.d.ts +3 -0
  585. package/dist/core/ingestion/method-extractors/configs/typescript-javascript.js +338 -0
  586. package/dist/core/ingestion/method-extractors/generic.d.ts +11 -0
  587. package/dist/core/ingestion/method-extractors/generic.js +204 -0
  588. package/dist/core/ingestion/method-types.d.ts +90 -0
  589. package/dist/core/ingestion/method-types.js +2 -0
  590. package/dist/core/ingestion/model/field-registry.d.ts +18 -0
  591. package/dist/core/ingestion/model/field-registry.js +22 -0
  592. package/dist/core/ingestion/model/heritage-map.d.ts +105 -0
  593. package/dist/core/ingestion/model/heritage-map.js +260 -0
  594. package/dist/core/ingestion/model/index.d.ts +20 -0
  595. package/dist/core/ingestion/model/index.js +43 -0
  596. package/dist/core/ingestion/model/method-registry.d.ts +71 -0
  597. package/dist/core/ingestion/model/method-registry.js +134 -0
  598. package/dist/core/ingestion/model/registration-table.d.ts +138 -0
  599. package/dist/core/ingestion/model/registration-table.js +224 -0
  600. package/dist/core/ingestion/model/resolution-context.d.ts +93 -0
  601. package/dist/core/ingestion/model/resolution-context.js +337 -0
  602. package/dist/core/ingestion/model/resolve.d.ts +61 -0
  603. package/dist/core/ingestion/model/resolve.js +381 -0
  604. package/dist/core/ingestion/model/scope-resolution-indexes.d.ts +59 -0
  605. package/dist/core/ingestion/model/scope-resolution-indexes.js +42 -0
  606. package/dist/core/ingestion/model/semantic-model.d.ts +150 -0
  607. package/dist/core/ingestion/model/semantic-model.js +175 -0
  608. package/dist/core/ingestion/model/symbol-table.d.ts +200 -0
  609. package/dist/core/ingestion/model/symbol-table.js +206 -0
  610. package/dist/core/ingestion/model/type-registry.d.ts +39 -0
  611. package/dist/core/ingestion/model/type-registry.js +62 -0
  612. package/dist/core/ingestion/mro-processor.d.ts +46 -0
  613. package/dist/core/ingestion/mro-processor.js +597 -0
  614. package/dist/core/ingestion/named-bindings/csharp.d.ts +3 -0
  615. package/dist/core/ingestion/named-bindings/csharp.js +37 -0
  616. package/dist/core/ingestion/named-bindings/java.d.ts +3 -0
  617. package/dist/core/ingestion/named-bindings/java.js +29 -0
  618. package/dist/core/ingestion/named-bindings/kotlin.d.ts +3 -0
  619. package/dist/core/ingestion/named-bindings/kotlin.js +36 -0
  620. package/dist/core/ingestion/named-bindings/php.d.ts +3 -0
  621. package/dist/core/ingestion/named-bindings/php.js +61 -0
  622. package/dist/core/ingestion/named-bindings/python.d.ts +3 -0
  623. package/dist/core/ingestion/named-bindings/python.js +49 -0
  624. package/dist/core/ingestion/named-bindings/rust.d.ts +3 -0
  625. package/dist/core/ingestion/named-bindings/rust.js +66 -0
  626. package/dist/core/ingestion/named-bindings/types.d.ts +16 -0
  627. package/dist/core/ingestion/named-bindings/types.js +6 -0
  628. package/dist/core/ingestion/named-bindings/typescript.d.ts +3 -0
  629. package/dist/core/ingestion/named-bindings/typescript.js +58 -0
  630. package/dist/core/ingestion/parsing-processor.d.ts +40 -0
  631. package/dist/core/ingestion/parsing-processor.js +576 -0
  632. package/dist/core/ingestion/pipeline-phases/cobol.d.ts +16 -0
  633. package/dist/core/ingestion/pipeline-phases/cobol.js +45 -0
  634. package/dist/core/ingestion/pipeline-phases/communities.d.ts +16 -0
  635. package/dist/core/ingestion/pipeline-phases/communities.js +62 -0
  636. package/dist/core/ingestion/pipeline-phases/cross-file-impl.d.ts +17 -0
  637. package/dist/core/ingestion/pipeline-phases/cross-file-impl.js +156 -0
  638. package/dist/core/ingestion/pipeline-phases/cross-file.d.ts +37 -0
  639. package/dist/core/ingestion/pipeline-phases/cross-file.js +63 -0
  640. package/dist/core/ingestion/pipeline-phases/index.d.ts +22 -0
  641. package/dist/core/ingestion/pipeline-phases/index.js +23 -0
  642. package/dist/core/ingestion/pipeline-phases/markdown.d.ts +17 -0
  643. package/dist/core/ingestion/pipeline-phases/markdown.js +33 -0
  644. package/dist/core/ingestion/pipeline-phases/mro.d.ts +18 -0
  645. package/dist/core/ingestion/pipeline-phases/mro.js +36 -0
  646. package/dist/core/ingestion/pipeline-phases/orm-extraction.d.ts +22 -0
  647. package/dist/core/ingestion/pipeline-phases/orm-extraction.js +92 -0
  648. package/dist/core/ingestion/pipeline-phases/orm.d.ts +15 -0
  649. package/dist/core/ingestion/pipeline-phases/orm.js +74 -0
  650. package/dist/core/ingestion/pipeline-phases/parse-impl.d.ts +58 -0
  651. package/dist/core/ingestion/pipeline-phases/parse-impl.js +458 -0
  652. package/dist/core/ingestion/pipeline-phases/parse.d.ts +74 -0
  653. package/dist/core/ingestion/pipeline-phases/parse.js +33 -0
  654. package/dist/core/ingestion/pipeline-phases/processes.d.ts +16 -0
  655. package/dist/core/ingestion/pipeline-phases/processes.js +143 -0
  656. package/dist/core/ingestion/pipeline-phases/routes.d.ts +21 -0
  657. package/dist/core/ingestion/pipeline-phases/routes.js +243 -0
  658. package/dist/core/ingestion/pipeline-phases/runner.d.ts +22 -0
  659. package/dist/core/ingestion/pipeline-phases/runner.js +203 -0
  660. package/dist/core/ingestion/pipeline-phases/scan.d.ts +21 -0
  661. package/dist/core/ingestion/pipeline-phases/scan.js +46 -0
  662. package/dist/core/ingestion/pipeline-phases/structure.d.ts +27 -0
  663. package/dist/core/ingestion/pipeline-phases/structure.js +35 -0
  664. package/dist/core/ingestion/pipeline-phases/tools.d.ts +20 -0
  665. package/dist/core/ingestion/pipeline-phases/tools.js +79 -0
  666. package/dist/core/ingestion/pipeline-phases/types.d.ts +79 -0
  667. package/dist/core/ingestion/pipeline-phases/types.js +37 -0
  668. package/dist/core/ingestion/pipeline-phases/wildcard-synthesis.d.ts +70 -0
  669. package/dist/core/ingestion/pipeline-phases/wildcard-synthesis.js +312 -0
  670. package/dist/core/ingestion/pipeline.d.ts +36 -0
  671. package/dist/core/ingestion/pipeline.js +89 -0
  672. package/dist/core/ingestion/process-processor.d.ts +51 -0
  673. package/dist/core/ingestion/process-processor.js +317 -0
  674. package/dist/core/ingestion/registry-primary-flag.d.ts +86 -0
  675. package/dist/core/ingestion/registry-primary-flag.js +111 -0
  676. package/dist/core/ingestion/resolve-references.d.ts +63 -0
  677. package/dist/core/ingestion/resolve-references.js +175 -0
  678. package/dist/core/ingestion/route-extractors/expo.d.ts +1 -0
  679. package/dist/core/ingestion/route-extractors/expo.js +36 -0
  680. package/dist/core/ingestion/route-extractors/middleware.d.ts +47 -0
  681. package/dist/core/ingestion/route-extractors/middleware.js +167 -0
  682. package/dist/core/ingestion/route-extractors/nextjs.d.ts +3 -0
  683. package/dist/core/ingestion/route-extractors/nextjs.js +76 -0
  684. package/dist/core/ingestion/route-extractors/php.d.ts +7 -0
  685. package/dist/core/ingestion/route-extractors/php.js +22 -0
  686. package/dist/core/ingestion/route-extractors/response-shapes.d.ts +20 -0
  687. package/dist/core/ingestion/route-extractors/response-shapes.js +294 -0
  688. package/dist/core/ingestion/scope-extractor-bridge.d.ts +32 -0
  689. package/dist/core/ingestion/scope-extractor-bridge.js +44 -0
  690. package/dist/core/ingestion/scope-extractor.d.ts +86 -0
  691. package/dist/core/ingestion/scope-extractor.js +758 -0
  692. package/dist/core/ingestion/scope-resolution/contract/scope-resolver.d.ts +372 -0
  693. package/dist/core/ingestion/scope-resolution/contract/scope-resolver.js +212 -0
  694. package/dist/core/ingestion/scope-resolution/graph-bridge/edges.d.ts +43 -0
  695. package/dist/core/ingestion/scope-resolution/graph-bridge/edges.js +79 -0
  696. package/dist/core/ingestion/scope-resolution/graph-bridge/ids.d.ts +57 -0
  697. package/dist/core/ingestion/scope-resolution/graph-bridge/ids.js +112 -0
  698. package/dist/core/ingestion/scope-resolution/graph-bridge/imports-to-edges.d.ts +17 -0
  699. package/dist/core/ingestion/scope-resolution/graph-bridge/imports-to-edges.js +46 -0
  700. package/dist/core/ingestion/scope-resolution/graph-bridge/method-dispatch.d.ts +19 -0
  701. package/dist/core/ingestion/scope-resolution/graph-bridge/method-dispatch.js +30 -0
  702. package/dist/core/ingestion/scope-resolution/graph-bridge/node-lookup.d.ts +37 -0
  703. package/dist/core/ingestion/scope-resolution/graph-bridge/node-lookup.js +113 -0
  704. package/dist/core/ingestion/scope-resolution/graph-bridge/references-to-edges.d.ts +38 -0
  705. package/dist/core/ingestion/scope-resolution/graph-bridge/references-to-edges.js +73 -0
  706. package/dist/core/ingestion/scope-resolution/passes/compound-receiver.d.ts +42 -0
  707. package/dist/core/ingestion/scope-resolution/passes/compound-receiver.js +198 -0
  708. package/dist/core/ingestion/scope-resolution/passes/free-call-fallback.d.ts +27 -0
  709. package/dist/core/ingestion/scope-resolution/passes/free-call-fallback.js +131 -0
  710. package/dist/core/ingestion/scope-resolution/passes/imported-return-types.d.ts +48 -0
  711. package/dist/core/ingestion/scope-resolution/passes/imported-return-types.js +130 -0
  712. package/dist/core/ingestion/scope-resolution/passes/mro.d.ts +42 -0
  713. package/dist/core/ingestion/scope-resolution/passes/mro.js +99 -0
  714. package/dist/core/ingestion/scope-resolution/passes/overload-narrowing.d.ts +26 -0
  715. package/dist/core/ingestion/scope-resolution/passes/overload-narrowing.js +61 -0
  716. package/dist/core/ingestion/scope-resolution/passes/receiver-bound-calls.d.ts +46 -0
  717. package/dist/core/ingestion/scope-resolution/passes/receiver-bound-calls.js +327 -0
  718. package/dist/core/ingestion/scope-resolution/pipeline/phase.d.ts +47 -0
  719. package/dist/core/ingestion/scope-resolution/pipeline/phase.js +130 -0
  720. package/dist/core/ingestion/scope-resolution/pipeline/reconcile-ownership.d.ts +68 -0
  721. package/dist/core/ingestion/scope-resolution/pipeline/reconcile-ownership.js +125 -0
  722. package/dist/core/ingestion/scope-resolution/pipeline/registry.d.ts +17 -0
  723. package/dist/core/ingestion/scope-resolution/pipeline/registry.js +21 -0
  724. package/dist/core/ingestion/scope-resolution/pipeline/run.d.ts +66 -0
  725. package/dist/core/ingestion/scope-resolution/pipeline/run.js +157 -0
  726. package/dist/core/ingestion/scope-resolution/scope/namespace-targets.d.ts +36 -0
  727. package/dist/core/ingestion/scope-resolution/scope/namespace-targets.js +52 -0
  728. package/dist/core/ingestion/scope-resolution/scope/walkers.d.ts +127 -0
  729. package/dist/core/ingestion/scope-resolution/scope/walkers.js +349 -0
  730. package/dist/core/ingestion/scope-resolution/workspace-index.d.ts +52 -0
  731. package/dist/core/ingestion/scope-resolution/workspace-index.js +61 -0
  732. package/dist/core/ingestion/shadow-harness.d.ts +113 -0
  733. package/dist/core/ingestion/shadow-harness.js +148 -0
  734. package/dist/core/ingestion/structure-processor.d.ts +2 -0
  735. package/dist/core/ingestion/structure-processor.js +36 -0
  736. package/dist/core/ingestion/tree-sitter-queries.d.ts +16 -0
  737. package/dist/core/ingestion/tree-sitter-queries.js +1338 -0
  738. package/dist/core/ingestion/type-env.d.ts +86 -0
  739. package/dist/core/ingestion/type-env.js +1128 -0
  740. package/dist/core/ingestion/type-extractors/c-cpp.d.ts +7 -0
  741. package/dist/core/ingestion/type-extractors/c-cpp.js +532 -0
  742. package/dist/core/ingestion/type-extractors/csharp.d.ts +2 -0
  743. package/dist/core/ingestion/type-extractors/csharp.js +583 -0
  744. package/dist/core/ingestion/type-extractors/dart.d.ts +15 -0
  745. package/dist/core/ingestion/type-extractors/dart.js +369 -0
  746. package/dist/core/ingestion/type-extractors/go.d.ts +2 -0
  747. package/dist/core/ingestion/type-extractors/go.js +513 -0
  748. package/dist/core/ingestion/type-extractors/jvm.d.ts +3 -0
  749. package/dist/core/ingestion/type-extractors/jvm.js +856 -0
  750. package/dist/core/ingestion/type-extractors/php.d.ts +2 -0
  751. package/dist/core/ingestion/type-extractors/php.js +534 -0
  752. package/dist/core/ingestion/type-extractors/python.d.ts +2 -0
  753. package/dist/core/ingestion/type-extractors/python.js +474 -0
  754. package/dist/core/ingestion/type-extractors/ruby.d.ts +2 -0
  755. package/dist/core/ingestion/type-extractors/ruby.js +377 -0
  756. package/dist/core/ingestion/type-extractors/rust.d.ts +2 -0
  757. package/dist/core/ingestion/type-extractors/rust.js +515 -0
  758. package/dist/core/ingestion/type-extractors/shared.d.ts +131 -0
  759. package/dist/core/ingestion/type-extractors/shared.js +796 -0
  760. package/dist/core/ingestion/type-extractors/swift.d.ts +2 -0
  761. package/dist/core/ingestion/type-extractors/swift.js +484 -0
  762. package/dist/core/ingestion/type-extractors/types.d.ts +172 -0
  763. package/dist/core/ingestion/type-extractors/types.js +1 -0
  764. package/dist/core/ingestion/type-extractors/typescript.d.ts +2 -0
  765. package/dist/core/ingestion/type-extractors/typescript.js +661 -0
  766. package/dist/core/ingestion/utils/ast-helpers.d.ts +89 -0
  767. package/dist/core/ingestion/utils/ast-helpers.js +535 -0
  768. package/dist/core/ingestion/utils/call-analysis.d.ts +75 -0
  769. package/dist/core/ingestion/utils/call-analysis.js +574 -0
  770. package/dist/core/ingestion/utils/env.d.ts +10 -0
  771. package/dist/core/ingestion/utils/env.js +10 -0
  772. package/dist/core/ingestion/utils/event-loop.d.ts +5 -0
  773. package/dist/core/ingestion/utils/event-loop.js +5 -0
  774. package/dist/core/ingestion/utils/graph-sort.d.ts +58 -0
  775. package/dist/core/ingestion/utils/graph-sort.js +100 -0
  776. package/dist/core/ingestion/utils/max-file-size.d.ts +20 -0
  777. package/dist/core/ingestion/utils/max-file-size.js +52 -0
  778. package/dist/core/ingestion/utils/method-props.d.ts +32 -0
  779. package/dist/core/ingestion/utils/method-props.js +147 -0
  780. package/dist/core/ingestion/utils/ruby-self-call.d.ts +52 -0
  781. package/dist/core/ingestion/utils/ruby-self-call.js +59 -0
  782. package/dist/core/ingestion/utils/verbose.d.ts +1 -0
  783. package/dist/core/ingestion/utils/verbose.js +7 -0
  784. package/dist/core/ingestion/variable-extractors/configs/c-cpp.d.ts +3 -0
  785. package/dist/core/ingestion/variable-extractors/configs/c-cpp.js +81 -0
  786. package/dist/core/ingestion/variable-extractors/configs/csharp.d.ts +9 -0
  787. package/dist/core/ingestion/variable-extractors/configs/csharp.js +63 -0
  788. package/dist/core/ingestion/variable-extractors/configs/dart.d.ts +2 -0
  789. package/dist/core/ingestion/variable-extractors/configs/dart.js +94 -0
  790. package/dist/core/ingestion/variable-extractors/configs/go.d.ts +2 -0
  791. package/dist/core/ingestion/variable-extractors/configs/go.js +83 -0
  792. package/dist/core/ingestion/variable-extractors/configs/jvm.d.ts +18 -0
  793. package/dist/core/ingestion/variable-extractors/configs/jvm.js +115 -0
  794. package/dist/core/ingestion/variable-extractors/configs/php.d.ts +14 -0
  795. package/dist/core/ingestion/variable-extractors/configs/php.js +58 -0
  796. package/dist/core/ingestion/variable-extractors/configs/python.d.ts +2 -0
  797. package/dist/core/ingestion/variable-extractors/configs/python.js +101 -0
  798. package/dist/core/ingestion/variable-extractors/configs/ruby.d.ts +11 -0
  799. package/dist/core/ingestion/variable-extractors/configs/ruby.js +52 -0
  800. package/dist/core/ingestion/variable-extractors/configs/rust.d.ts +2 -0
  801. package/dist/core/ingestion/variable-extractors/configs/rust.js +76 -0
  802. package/dist/core/ingestion/variable-extractors/configs/swift.d.ts +2 -0
  803. package/dist/core/ingestion/variable-extractors/configs/swift.js +88 -0
  804. package/dist/core/ingestion/variable-extractors/configs/typescript-javascript.d.ts +3 -0
  805. package/dist/core/ingestion/variable-extractors/configs/typescript-javascript.js +83 -0
  806. package/dist/core/ingestion/variable-extractors/generic.d.ts +5 -0
  807. package/dist/core/ingestion/variable-extractors/generic.js +80 -0
  808. package/dist/core/ingestion/variable-types.d.ts +82 -0
  809. package/dist/core/ingestion/variable-types.js +2 -0
  810. package/dist/core/ingestion/vue-sfc-extractor.d.ts +44 -0
  811. package/dist/core/ingestion/vue-sfc-extractor.js +94 -0
  812. package/dist/core/ingestion/workers/parse-worker.d.ts +198 -0
  813. package/dist/core/ingestion/workers/parse-worker.js +1928 -0
  814. package/dist/core/ingestion/workers/worker-pool.d.ts +16 -0
  815. package/dist/core/ingestion/workers/worker-pool.js +126 -0
  816. package/dist/core/lbug/csv-generator.d.ts +33 -0
  817. package/dist/core/lbug/csv-generator.js +459 -0
  818. package/dist/core/lbug/lbug-adapter.d.ts +173 -0
  819. package/dist/core/lbug/lbug-adapter.js +1188 -0
  820. package/dist/core/lbug/pool-adapter.d.ts +93 -0
  821. package/dist/core/lbug/pool-adapter.js +543 -0
  822. package/dist/core/lbug/schema.d.ts +62 -0
  823. package/dist/core/lbug/schema.js +484 -0
  824. package/dist/core/run-analyze.d.ts +72 -0
  825. package/dist/core/run-analyze.js +315 -0
  826. package/dist/core/search/bm25-index.d.ts +41 -0
  827. package/dist/core/search/bm25-index.js +209 -0
  828. package/dist/core/search/hybrid-search.d.ts +49 -0
  829. package/dist/core/search/hybrid-search.js +118 -0
  830. package/dist/core/search/phase-timer.d.ts +72 -0
  831. package/dist/core/search/phase-timer.js +106 -0
  832. package/dist/core/tree-sitter/parser-loader.d.ts +8 -0
  833. package/dist/core/tree-sitter/parser-loader.js +84 -0
  834. package/dist/core/wiki/cursor-client.d.ts +31 -0
  835. package/dist/core/wiki/cursor-client.js +122 -0
  836. package/dist/core/wiki/generator.d.ts +129 -0
  837. package/dist/core/wiki/generator.js +898 -0
  838. package/dist/core/wiki/graph-queries.d.ts +84 -0
  839. package/dist/core/wiki/graph-queries.js +244 -0
  840. package/dist/core/wiki/html-viewer.d.ts +10 -0
  841. package/dist/core/wiki/html-viewer.js +303 -0
  842. package/dist/core/wiki/llm-client.d.ts +63 -0
  843. package/dist/core/wiki/llm-client.js +234 -0
  844. package/dist/core/wiki/prompts.d.ts +53 -0
  845. package/dist/core/wiki/prompts.js +181 -0
  846. package/dist/lib/utils.d.ts +1 -0
  847. package/dist/lib/utils.js +3 -0
  848. package/dist/mcp/compatible-stdio-transport.d.ts +25 -0
  849. package/dist/mcp/compatible-stdio-transport.js +200 -0
  850. package/dist/mcp/core/embedder.d.ts +27 -0
  851. package/dist/mcp/core/embedder.js +122 -0
  852. package/dist/mcp/core/lbug-adapter.d.ts +5 -0
  853. package/dist/mcp/core/lbug-adapter.js +5 -0
  854. package/dist/mcp/local/graphstore-handler.d.ts +214 -0
  855. package/dist/mcp/local/graphstore-handler.js +272 -0
  856. package/dist/mcp/local/local-backend.d.ts +347 -0
  857. package/dist/mcp/local/local-backend.js +3218 -0
  858. package/dist/mcp/resources.d.ts +62 -0
  859. package/dist/mcp/resources.js +696 -0
  860. package/dist/mcp/server.d.ts +23 -0
  861. package/dist/mcp/server.js +533 -0
  862. package/dist/mcp/staleness.d.ts +5 -0
  863. package/dist/mcp/staleness.js +4 -0
  864. package/dist/mcp/tools.d.ts +27 -0
  865. package/dist/mcp/tools.js +823 -0
  866. package/dist/server/analyze-job.d.ts +55 -0
  867. package/dist/server/analyze-job.js +150 -0
  868. package/dist/server/analyze-worker.d.ts +13 -0
  869. package/dist/server/analyze-worker.js +59 -0
  870. package/dist/server/api.d.ts +47 -0
  871. package/dist/server/api.js +1727 -0
  872. package/dist/server/git-clone.d.ts +26 -0
  873. package/dist/server/git-clone.js +184 -0
  874. package/dist/server/mcp-http.d.ts +13 -0
  875. package/dist/server/mcp-http.js +100 -0
  876. package/dist/storage/git.d.ts +80 -0
  877. package/dist/storage/git.js +190 -0
  878. package/dist/storage/repo-manager.d.ts +458 -0
  879. package/dist/storage/repo-manager.js +766 -0
  880. package/dist/types/pipeline.d.ts +18 -0
  881. package/dist/types/pipeline.js +1 -0
  882. package/hooks/claude/codragraph-hook.cjs +268 -0
  883. package/hooks/claude/pre-tool-use.sh +79 -0
  884. package/hooks/claude/session-start.sh +42 -0
  885. package/package.json +127 -0
  886. package/scripts/bench-scope-resolution.ts +134 -0
  887. package/scripts/build-tree-sitter-proto.cjs +82 -0
  888. package/scripts/build.js +90 -0
  889. package/scripts/ci-list-migrated-languages.ts +24 -0
  890. package/scripts/patch-tree-sitter-swift.cjs +78 -0
  891. package/skills/codragraph-cli.md +82 -0
  892. package/skills/codragraph-debugging.md +89 -0
  893. package/skills/codragraph-exploring.md +78 -0
  894. package/skills/codragraph-guide.md +64 -0
  895. package/skills/codragraph-impact-analysis.md +97 -0
  896. package/skills/codragraph-pr-review.md +163 -0
  897. package/skills/codragraph-refactoring.md +121 -0
  898. package/vendor/leiden/index.cjs +355 -0
  899. package/vendor/leiden/utils.cjs +392 -0
  900. package/vendor/tree-sitter-proto/binding.gyp +30 -0
  901. package/vendor/tree-sitter-proto/bindings/node/binding.cc +20 -0
  902. package/vendor/tree-sitter-proto/bindings/node/index.d.ts +28 -0
  903. package/vendor/tree-sitter-proto/bindings/node/index.js +7 -0
  904. package/vendor/tree-sitter-proto/package.json +12 -0
  905. package/vendor/tree-sitter-proto/src/node-types.json +1145 -0
  906. package/vendor/tree-sitter-proto/src/parser.c +10149 -0
  907. package/vendor/tree-sitter-proto/src/tree_sitter/alloc.h +54 -0
  908. package/vendor/tree-sitter-proto/src/tree_sitter/array.h +291 -0
  909. package/vendor/tree-sitter-proto/src/tree_sitter/parser.h +266 -0
@@ -0,0 +1,2639 @@
1
+ import { CLASS_TYPES, CALL_TARGET_TYPES, lookupMethodByOwnerWithMRO } from './model/index.js';
2
+ /**
3
+ * DAG stage 4 fallback: used when `selectDispatch` is absent or returns null.
4
+ * Preserves pre-DAG dispatch semantics:
5
+ * - 'constructor' → constructor branch
6
+ * - 'free' → free branch (admits Swift/Kotlin class-target fast path)
7
+ * - 'member' or undefined → owner-scoped branch
8
+ *
9
+ * `undefined` callForm MUST route through owner-scoped (not free) so bare
10
+ * identifiers without a classified shape do NOT trigger `resolveFreeCall`'s
11
+ * class-target fast path. Without a `receiverTypeName`, the owner-scoped
12
+ * branch falls through to `resolveModuleAliasedCall` + `singleCandidate`,
13
+ * matching legacy behavior where non-callable symbols (Class, Interface)
14
+ * null-route instead of producing spurious Constructor edges.
15
+ */
16
+ const defaultDispatchDecision = (callForm) => {
17
+ if (callForm === 'constructor')
18
+ return { primary: 'constructor' };
19
+ if (callForm === 'free')
20
+ return { primary: 'free' };
21
+ return { primary: 'owner-scoped' };
22
+ };
23
+ import Parser from 'tree-sitter';
24
+ import { TIER_CONFIDENCE } from './model/resolution-context.js';
25
+ import { isLanguageAvailable, loadParser, loadLanguage } from '../tree-sitter/parser-loader.js';
26
+ import { getProvider } from './languages/index.js';
27
+ import { generateId } from '../../lib/utils.js';
28
+ import { getLanguageFromFilename, SupportedLanguages } from '../../_shared/index.js';
29
+ import { isRegistryPrimary } from './registry-primary-flag.js';
30
+ import { isVerboseIngestionEnabled } from './utils/verbose.js';
31
+ import { yieldToEventLoop } from './utils/event-loop.js';
32
+ import { FUNCTION_NODE_TYPES, findEnclosingClassId, findEnclosingClassInfo, genericFuncName, inferFunctionLabel, } from './utils/ast-helpers.js';
33
+ import { typeTagForId, constTagForId, buildCollisionGroups } from './utils/method-props.js';
34
+ import { countCallArguments, inferCallForm, extractReceiverName, extractReceiverNode, extractMixedChain, extractCallArgTypes, } from './utils/call-analysis.js';
35
+ import { buildTypeEnv, isSubclassOf } from './type-env.js';
36
+ import { getTreeSitterBufferSize } from './constants.js';
37
+ import { normalizeFetchURL, routeMatches } from './route-extractors/nextjs.js';
38
+ import { extractTemplateComponents } from './vue-sfc-extractor.js';
39
+ import { extractReturnTypeName, stripNullable } from './type-extractors/shared.js';
40
+ /**
41
+ * Type labels treated as class-like **method-dispatch receivers** by the call
42
+ * resolver — the set walked by the MRO / heritage path for member and static
43
+ * method calls.
44
+ *
45
+ * Derived from `CLASS_TYPES` (the heritage-index set in symbol-table) plus
46
+ * `Impl` — Rust `impl` blocks are the definition site of methods for a struct
47
+ * and must be walkable as receiver-type candidates even though they are not
48
+ * indexed by `lookupClassByName` (which keys off struct/trait names). Keeping
49
+ * this set a strict superset of `CLASS_TYPES` guarantees that anything
50
+ * reachable via `lookupClassByName` also passes this filter, so the two call
51
+ * paths cannot diverge silently.
52
+ *
53
+ * `Interface` is included even though interfaces cannot be directly
54
+ * instantiated in Java/C#/TypeScript: the resolver still needs to reach
55
+ * interface nodes for static-method dispatch (`Interface.staticMethod()`) and
56
+ * default-method resolution via the MRO walker.
57
+ *
58
+ * **Do not reuse this set for constructor-fallback filtering.** Constructors
59
+ * can only instantiate a narrower subset — see `INSTANTIABLE_CLASS_TYPES`
60
+ * below. `resolveStaticCall`'s step-5 class-node fallback uses the narrower
61
+ * set to prevent false `CALLS` edges from constructor-shaped calls to
62
+ * `Interface`, `Trait`, or `Impl` nodes.
63
+ */
64
+ const CLASS_LIKE_TYPES = new Set([...CLASS_TYPES, 'Impl']);
65
+ /**
66
+ * Type labels that can be the target of a constructor-shaped call when no
67
+ * explicit `Constructor` symbol is indexed — the "return the type itself as
68
+ * the call target" fallback set.
69
+ *
70
+ * Strict subset of both `CLASS_LIKE_TYPES` and `CONSTRUCTOR_TARGET_TYPES`.
71
+ * Excludes:
72
+ * - `Interface` / `Trait` — not instantiable by definition in any
73
+ * supported language.
74
+ * - `Impl` — Rust `impl` blocks are method-definition containers, not
75
+ * the type itself; the owning `Struct` is the correct target.
76
+ * - `Enum` — excluded pending language-specific support with motivating
77
+ * test fixtures (matches `CONSTRUCTOR_TARGET_TYPES`).
78
+ *
79
+ * Used exclusively by `resolveStaticCall`'s step-5 class-node fallback.
80
+ * Keep in sync with `CONSTRUCTOR_TARGET_TYPES` (which additionally contains
81
+ * `'Constructor'` for explicit-constructor-node filtering) when extending.
82
+ */
83
+ const INSTANTIABLE_CLASS_TYPES = new Set(['Class', 'Struct', 'Record']);
84
+ const MAX_EXPORTS_PER_FILE = 500;
85
+ const MAX_TYPE_NAME_LENGTH = 256;
86
+ /** Build a map of imported callee names → return types for cross-file call-result binding.
87
+ * Consulted ONLY when SymbolTable has no unambiguous local match (local-first principle).
88
+ *
89
+ * Overlapping mechanism (1 of 3): this is the SymbolTable-backed path.
90
+ * See also:
91
+ * 2. collectExportedBindings (~line 168) / enrichExportedTypeMap — TypeEnv + graph isExported
92
+ * 3. Phase 9 fallback in verifyConstructorBindings (~line 563) — namedImportMap + BindingAccumulator
93
+ * A future cleanup should merge these into a single resolution pass. */
94
+ export function buildImportedReturnTypes(filePath, namedImportMap, symbolTable) {
95
+ const result = new Map();
96
+ const fileImports = namedImportMap.get(filePath);
97
+ if (!fileImports)
98
+ return result;
99
+ for (const [localName, binding] of fileImports) {
100
+ const def = symbolTable.lookupExactFull(binding.sourcePath, binding.exportedName);
101
+ if (!def?.returnType)
102
+ continue;
103
+ const simpleReturn = extractReturnTypeName(def.returnType);
104
+ if (simpleReturn)
105
+ result.set(localName, simpleReturn);
106
+ }
107
+ return result;
108
+ }
109
+ /** Build cross-file RAW return types for imported callables.
110
+ * Unlike buildImportedReturnTypes (which stores extractReturnTypeName output),
111
+ * this stores the raw declared return type string (e.g., 'User[]', 'List<User>').
112
+ * Used by lookupRawReturnType for for-loop element extraction via extractElementTypeFromString. */
113
+ export function buildImportedRawReturnTypes(filePath, namedImportMap, symbolTable) {
114
+ const result = new Map();
115
+ const fileImports = namedImportMap.get(filePath);
116
+ if (!fileImports)
117
+ return result;
118
+ for (const [localName, binding] of fileImports) {
119
+ const def = symbolTable.lookupExactFull(binding.sourcePath, binding.exportedName);
120
+ if (!def?.returnType)
121
+ continue;
122
+ result.set(localName, def.returnType);
123
+ }
124
+ return result;
125
+ }
126
+ /** Collect resolved type bindings for exported file-scope symbols.
127
+ * Uses graph node isExported flag — does NOT require isExported on SymbolDefinition.
128
+ *
129
+ * **Counterpart**: the worker path populates `exportedTypeMap` via the
130
+ * accumulator enrichment loop in `pipeline.ts` (search for "Worker path
131
+ * quality enrichment"). Both sites populate the same map with subtly
132
+ * different export-check semantics — this site uses SymbolTable +
133
+ * graph lookup, the worker loop uses three-candidate-ID graph lookup.
134
+ * They must stay in sync until unified. If you edit one, check the other.
135
+ *
136
+ * Overlapping mechanism (2 of 3): this is the TypeEnv + graph isExported path.
137
+ * See also:
138
+ * 1. buildImportedReturnTypes (~line 109) — namedImportMap + SymbolTable
139
+ * 3. Phase 9 fallback in verifyConstructorBindings (~line 563) — namedImportMap + BindingAccumulator
140
+ * A future cleanup should merge these into a single resolution pass. */
141
+ function collectExportedBindings(typeEnv, filePath, symbolTable, graph) {
142
+ const fileScope = typeEnv.fileScope();
143
+ if (!fileScope || fileScope.size === 0)
144
+ return null;
145
+ const exported = new Map();
146
+ for (const [varName, typeName] of fileScope) {
147
+ if (exported.size >= MAX_EXPORTS_PER_FILE)
148
+ break;
149
+ if (!typeName || typeName.length > MAX_TYPE_NAME_LENGTH)
150
+ continue;
151
+ const nodeId = symbolTable.lookupExact(filePath, varName);
152
+ if (!nodeId)
153
+ continue;
154
+ const node = graph.getNode(nodeId);
155
+ if (node?.properties?.isExported) {
156
+ exported.set(varName, typeName);
157
+ }
158
+ }
159
+ return exported.size > 0 ? exported : null;
160
+ }
161
+ /** Build ExportedTypeMap from graph nodes — used for worker path where TypeEnv
162
+ * is not available in the main thread. Collects returnType/declaredType from
163
+ * exported symbols that have callables with known return types. */
164
+ export function buildExportedTypeMapFromGraph(graph, symbolTable) {
165
+ const result = new Map();
166
+ graph.forEachNode((node) => {
167
+ if (!node.properties?.isExported)
168
+ return;
169
+ if (!node.properties?.filePath || !node.properties?.name)
170
+ return;
171
+ const filePath = node.properties.filePath;
172
+ const name = node.properties.name;
173
+ if (!name || name.length > MAX_TYPE_NAME_LENGTH)
174
+ return;
175
+ // For callable symbols, use returnType; for properties/variables, use declaredType.
176
+ // Use lookupExactAll + nodeId match to handle same-name methods in different classes.
177
+ const defs = symbolTable.lookupExactAll(filePath, name);
178
+ const def = defs.find((d) => d.nodeId === node.id) ?? defs[0];
179
+ if (!def)
180
+ return;
181
+ const typeName = def.returnType ?? def.declaredType;
182
+ if (!typeName || typeName.length > MAX_TYPE_NAME_LENGTH)
183
+ return;
184
+ // Extract simple type name (strip Promise<>, etc.) — reuse shared utility
185
+ const simpleType = extractReturnTypeName(typeName) ?? typeName;
186
+ if (!simpleType)
187
+ return;
188
+ let fileExports = result.get(filePath);
189
+ if (!fileExports) {
190
+ fileExports = new Map();
191
+ result.set(filePath, fileExports);
192
+ }
193
+ if (fileExports.size < MAX_EXPORTS_PER_FILE) {
194
+ fileExports.set(name, simpleType);
195
+ }
196
+ });
197
+ return result;
198
+ }
199
+ /** Seed cross-file receiver types into pre-extracted call records.
200
+ * Fills missing receiverTypeName for single-hop imported variables
201
+ * using ExportedTypeMap + namedImportMap — zero disk I/O, zero AST re-parsing.
202
+ * Mutates calls in-place. Runs BEFORE processCallsFromExtracted. */
203
+ export function seedCrossFileReceiverTypes(calls, namedImportMap, exportedTypeMap) {
204
+ if (namedImportMap.size === 0 || exportedTypeMap.size === 0) {
205
+ return { enrichedCount: 0 };
206
+ }
207
+ let enrichedCount = 0;
208
+ for (const call of calls) {
209
+ if (call.receiverTypeName || !call.receiverName)
210
+ continue;
211
+ if (call.callForm !== 'member')
212
+ continue;
213
+ const fileImports = namedImportMap.get(call.filePath);
214
+ if (!fileImports)
215
+ continue;
216
+ const binding = fileImports.get(call.receiverName);
217
+ if (!binding)
218
+ continue;
219
+ const upstream = exportedTypeMap.get(binding.sourcePath);
220
+ if (!upstream)
221
+ continue;
222
+ const type = upstream.get(binding.exportedName);
223
+ if (type) {
224
+ call.receiverTypeName = type;
225
+ enrichedCount++;
226
+ }
227
+ }
228
+ return { enrichedCount };
229
+ }
230
+ // Stdlib methods that preserve the receiver's type identity. When TypeEnv already
231
+ // strips nullable wrappers (Option<User> → User), these chain steps are no-ops
232
+ // for type resolution — the current type passes through unchanged.
233
+ const TYPE_PRESERVING_METHODS = new Set([
234
+ 'unwrap',
235
+ 'expect',
236
+ 'unwrap_or',
237
+ 'unwrap_or_default',
238
+ 'unwrap_or_else', // Rust Option/Result
239
+ 'clone',
240
+ 'to_owned',
241
+ 'as_ref',
242
+ 'as_mut',
243
+ 'borrow',
244
+ 'borrow_mut', // Rust clone/borrow
245
+ 'get', // Kotlin/Java Optional.get()
246
+ 'orElseThrow', // Java Optional
247
+ ]);
248
+ /** Cache for method extraction results in findEnclosingFunction fallback path.
249
+ * Keyed by classNode.id to avoid re-extracting the same class body per call site.
250
+ * Cleared between files at line ~611 in the processCalls file loop. */
251
+ const enclosingFnExtractCache = new Map();
252
+ /**
253
+ * Walk up the AST from a node to find the enclosing function/method.
254
+ * Returns null if the call is at module/file level (top-level code).
255
+ */
256
+ const findEnclosingFunction = (node, filePath, ctx, provider) => {
257
+ let current = node.parent;
258
+ while (current) {
259
+ if (FUNCTION_NODE_TYPES.has(current.type)) {
260
+ const efnResult = provider.methodExtractor?.extractFunctionName?.(current);
261
+ const funcName = efnResult?.funcName ?? genericFuncName(current);
262
+ const label = efnResult?.label ?? inferFunctionLabel(current.type);
263
+ if (funcName) {
264
+ const resolved = ctx.resolve(funcName, filePath);
265
+ if (resolved?.tier === 'same-file' && resolved.candidates.length > 0) {
266
+ // Disambiguate by enclosing class when multiple candidates
267
+ if (resolved.candidates.length === 1) {
268
+ return resolved.candidates[0].nodeId;
269
+ }
270
+ const classInfo = findEnclosingClassInfo(current, filePath);
271
+ if (classInfo) {
272
+ const classMatches = resolved.candidates.filter((c) => c.ownerId === classInfo.classId);
273
+ // Unique class match — return it (no same-arity ambiguity)
274
+ if (classMatches.length === 1)
275
+ return classMatches[0].nodeId;
276
+ // Multiple same-class candidates (same-arity overloads) — fall through
277
+ // to the fallback path which computes the exact ID with type-hash.
278
+ if (classMatches.length > 1) {
279
+ /* fall through to manual ID construction below */
280
+ }
281
+ else {
282
+ // No class match — return first candidate as before
283
+ return resolved.candidates[0].nodeId;
284
+ }
285
+ }
286
+ else {
287
+ return resolved.candidates[0].nodeId;
288
+ }
289
+ }
290
+ // Fallback: qualify the generated ID to match definition-phase node IDs
291
+ let finalLabel = label;
292
+ if (provider.labelOverride) {
293
+ const override = provider.labelOverride(current, label);
294
+ if (override !== null)
295
+ finalLabel = override;
296
+ }
297
+ const classInfo2 = findEnclosingClassInfo(current, filePath);
298
+ const qualifiedName = classInfo2 ? `${classInfo2.className}.${funcName}` : funcName;
299
+ // Include #<arity> and ~typeTag suffix to match definition-phase Method/Constructor IDs.
300
+ const language = getLanguageFromFilename(filePath);
301
+ let arity;
302
+ let encTypeTag = '';
303
+ if ((finalLabel === 'Method' || finalLabel === 'Constructor') &&
304
+ provider.methodExtractor &&
305
+ language) {
306
+ // Get class method map (cached per classNode.id) and look up current method
307
+ // by funcName:line. This avoids per-call-site extractFromNode AST walks.
308
+ let classNode = current.parent;
309
+ while (classNode && !provider.methodExtractor.isTypeDeclaration(classNode)) {
310
+ classNode = classNode.parent;
311
+ }
312
+ let info;
313
+ if (classNode) {
314
+ let extracted = enclosingFnExtractCache.get(classNode.id);
315
+ if (extracted === undefined) {
316
+ extracted =
317
+ provider.methodExtractor.extract(classNode, { filePath, language }) ?? null;
318
+ enclosingFnExtractCache.set(classNode.id, extracted);
319
+ }
320
+ if (extracted?.methods?.length) {
321
+ const defLine = current.startPosition.row + 1;
322
+ info = extracted.methods.find((m) => m.name === funcName && m.line === defLine);
323
+ if (info) {
324
+ arity = info.parameters.some((p) => p.isVariadic)
325
+ ? undefined
326
+ : info.parameters.length;
327
+ }
328
+ if (arity !== undefined && info) {
329
+ const methodMap = new Map();
330
+ for (const m of extracted.methods)
331
+ methodMap.set(`${m.name}:${m.line}`, m);
332
+ const groups = buildCollisionGroups(methodMap);
333
+ encTypeTag =
334
+ typeTagForId(methodMap, funcName, arity, info, language, groups) +
335
+ constTagForId(methodMap, funcName, arity, info, groups);
336
+ }
337
+ }
338
+ }
339
+ // Fallback: extractFromNode for top-level methods without a class
340
+ if (!info && provider.methodExtractor.extractFromNode) {
341
+ const nodeInfo = provider.methodExtractor.extractFromNode(current, {
342
+ filePath,
343
+ language,
344
+ });
345
+ if (nodeInfo) {
346
+ arity = nodeInfo.parameters.some((p) => p.isVariadic)
347
+ ? undefined
348
+ : nodeInfo.parameters.length;
349
+ }
350
+ }
351
+ }
352
+ const arityTag = arity !== undefined ? `#${arity}${encTypeTag}` : '';
353
+ return generateId(finalLabel, `${filePath}:${qualifiedName}${arityTag}`);
354
+ }
355
+ }
356
+ // Language-specific enclosing function resolution (e.g., Dart where
357
+ // function_body is a sibling of function_signature, not a child).
358
+ if (provider.enclosingFunctionFinder) {
359
+ const customResult = provider.enclosingFunctionFinder(current);
360
+ if (customResult) {
361
+ const resolved = ctx.resolve(customResult.funcName, filePath);
362
+ if (resolved?.tier === 'same-file' && resolved.candidates.length > 0) {
363
+ if (resolved.candidates.length === 1) {
364
+ return resolved.candidates[0].nodeId;
365
+ }
366
+ const classInfo = findEnclosingClassInfo(current.previousSibling ?? current, filePath);
367
+ if (classInfo) {
368
+ const classMatches = resolved.candidates.filter((c) => c.ownerId === classInfo.classId);
369
+ if (classMatches.length === 1)
370
+ return classMatches[0].nodeId;
371
+ if (classMatches.length > 1) {
372
+ /* fall through to manual ID construction below */
373
+ }
374
+ else {
375
+ return resolved.candidates[0].nodeId;
376
+ }
377
+ }
378
+ else {
379
+ return resolved.candidates[0].nodeId;
380
+ }
381
+ }
382
+ let finalLabel = customResult.label;
383
+ if (provider.labelOverride) {
384
+ const override = provider.labelOverride(current.previousSibling, finalLabel);
385
+ if (override !== null)
386
+ finalLabel = override;
387
+ }
388
+ const classInfo2 = findEnclosingClassInfo(current.previousSibling ?? current, filePath);
389
+ const qualifiedName = classInfo2
390
+ ? `${classInfo2.className}.${customResult.funcName}`
391
+ : customResult.funcName;
392
+ // Include #<arity> and ~typeTag suffix to match definition-phase Method/Constructor IDs.
393
+ const sigNode = current.previousSibling ?? current;
394
+ const language2 = getLanguageFromFilename(filePath);
395
+ let arity2;
396
+ let encTypeTag2 = '';
397
+ if ((finalLabel === 'Method' || finalLabel === 'Constructor') &&
398
+ provider.methodExtractor &&
399
+ language2) {
400
+ let classNode2 = (current.previousSibling ?? current).parent;
401
+ while (classNode2 && !provider.methodExtractor.isTypeDeclaration(classNode2)) {
402
+ classNode2 = classNode2.parent;
403
+ }
404
+ let info2;
405
+ if (classNode2) {
406
+ let extracted2 = enclosingFnExtractCache.get(classNode2.id);
407
+ if (extracted2 === undefined) {
408
+ extracted2 =
409
+ provider.methodExtractor.extract(classNode2, { filePath, language: language2 }) ??
410
+ null;
411
+ enclosingFnExtractCache.set(classNode2.id, extracted2);
412
+ }
413
+ if (extracted2?.methods?.length) {
414
+ const defLine2 = sigNode.startPosition.row + 1;
415
+ info2 = extracted2.methods.find((m) => m.name === customResult.funcName && m.line === defLine2);
416
+ if (info2) {
417
+ arity2 = info2.parameters.some((p) => p.isVariadic)
418
+ ? undefined
419
+ : info2.parameters.length;
420
+ }
421
+ if (arity2 !== undefined && info2) {
422
+ const methodMap = new Map();
423
+ for (const m of extracted2.methods)
424
+ methodMap.set(`${m.name}:${m.line}`, m);
425
+ const groups2 = buildCollisionGroups(methodMap);
426
+ encTypeTag2 =
427
+ typeTagForId(methodMap, customResult.funcName, arity2, info2, language2, groups2) + constTagForId(methodMap, customResult.funcName, arity2, info2, groups2);
428
+ }
429
+ }
430
+ }
431
+ if (!info2 && provider.methodExtractor.extractFromNode) {
432
+ const nodeInfo = provider.methodExtractor.extractFromNode(sigNode, {
433
+ filePath,
434
+ language: language2,
435
+ });
436
+ if (nodeInfo) {
437
+ arity2 = nodeInfo.parameters.some((p) => p.isVariadic)
438
+ ? undefined
439
+ : nodeInfo.parameters.length;
440
+ }
441
+ }
442
+ }
443
+ const arityTag2 = arity2 !== undefined ? `#${arity2}${encTypeTag2}` : '';
444
+ return generateId(finalLabel, `${filePath}:${qualifiedName}${arityTag2}`);
445
+ }
446
+ }
447
+ current = current.parent;
448
+ }
449
+ return null;
450
+ };
451
+ /**
452
+ * Verify constructor bindings against SymbolTable and infer receiver types.
453
+ * Shared between sequential (processCalls) and worker (processCallsFromExtracted) paths.
454
+ */
455
+ const verifyConstructorBindings = (bindings, filePath, ctx, graph, bindingAccumulator) => {
456
+ const verified = new Map();
457
+ for (const { scope, varName, calleeName, receiverClassName } of bindings) {
458
+ const tiered = ctx.resolve(calleeName, filePath);
459
+ const isClass = tiered?.candidates.some((def) => def.type === 'Class') ?? false;
460
+ if (isClass) {
461
+ verified.set(receiverKey(scope, varName), calleeName);
462
+ }
463
+ else {
464
+ let callableDefs = tiered?.candidates.filter((d) => d.type === 'Function' || d.type === 'Method');
465
+ // When receiver class is known (e.g. $this->method() in PHP), narrow
466
+ // candidates to methods owned by that class to avoid false disambiguation failures.
467
+ if (callableDefs && callableDefs.length > 1 && receiverClassName) {
468
+ if (graph) {
469
+ // Worker path: use graph.getNode (fast, already in-memory)
470
+ const narrowed = callableDefs.filter((d) => {
471
+ if (!d.ownerId)
472
+ return false;
473
+ const owner = graph.getNode(d.ownerId);
474
+ return owner?.properties.name === receiverClassName;
475
+ });
476
+ if (narrowed.length > 0)
477
+ callableDefs = narrowed;
478
+ }
479
+ else {
480
+ // Sequential path: use ctx.resolve (no graph available)
481
+ const classResolved = ctx.resolve(receiverClassName, filePath);
482
+ if (classResolved && classResolved.candidates.length > 0) {
483
+ const classNodeIds = new Set(classResolved.candidates.map((c) => c.nodeId));
484
+ const narrowed = callableDefs.filter((d) => d.ownerId && classNodeIds.has(d.ownerId));
485
+ if (narrowed.length > 0)
486
+ callableDefs = narrowed;
487
+ }
488
+ }
489
+ }
490
+ let typeName;
491
+ if (callableDefs && callableDefs.length === 1 && callableDefs[0].returnType) {
492
+ typeName = extractReturnTypeName(callableDefs[0].returnType);
493
+ }
494
+ // Phase 9: BindingAccumulator fallback for cross-file return types.
495
+ // Used when the SymbolTable has no return type for a cross-file callee
496
+ // (e.g., a return type that TypeEnv resolved via fixpoint in the source
497
+ // file but was not stored as a SymbolTable returnType annotation).
498
+ // namedImportMap tells us which source file exported the callee so we
499
+ // can look up its file-scope binding via the O(1) fileScopeGet method.
500
+ //
501
+ // Tier gating: only fall back to the accumulator when resolution is
502
+ // unambiguously import-scoped or global. When tiered.tier is 'same-file',
503
+ // the local definition is authoritative even without a return type
504
+ // annotation — using the accumulator here would let an imported callee
505
+ // with the same name shadow the local one, producing false CALLS edges.
506
+ // When multiple callable candidates exist, the accumulator would pick
507
+ // arbitrarily — skip to avoid fabricated edges.
508
+ //
509
+ // Quality note: worker-path accumulator entries are Tier 0/1 only
510
+ // (annotation-declared + same-file constructor inference) — see the
511
+ // BindingAccumulator class JSDoc. For large repos where the worker
512
+ // path dominates, Phase 9 binding accuracy is structurally lower
513
+ // than for sequential-path repos where Tier 2 cross-file propagation
514
+ // is available.
515
+ //
516
+ // Overlapping mechanism note: this is one of three cross-file
517
+ // return-type resolution paths in the codebase:
518
+ // 1. buildImportedReturnTypes (~line 109) — namedImportMap +
519
+ // SymbolTable.lookupExactFull (structure-processor captured)
520
+ // 2. collectExportedBindings (~line 168) / enrichExportedTypeMap
521
+ // — TypeEnv + graph isExported flag
522
+ // 3. This fallback — namedImportMap + BindingAccumulator
523
+ // A future cleanup should merge these into a single resolution pass.
524
+ const shouldFallback = tiered?.tier !== 'same-file' && (!callableDefs || callableDefs.length <= 1);
525
+ if (!typeName && bindingAccumulator && shouldFallback) {
526
+ const namedImports = ctx.namedImportMap.get(filePath);
527
+ const importBinding = namedImports?.get(calleeName);
528
+ if (importBinding) {
529
+ const rawType = bindingAccumulator.fileScopeGet(importBinding.sourcePath, importBinding.exportedName);
530
+ if (rawType) {
531
+ typeName = extractReturnTypeName(rawType);
532
+ }
533
+ }
534
+ }
535
+ if (typeName) {
536
+ verified.set(receiverKey(scope, varName), typeName);
537
+ }
538
+ }
539
+ }
540
+ return verified;
541
+ };
542
+ /**
543
+ * After resolving a call to an interface method, find additional targets
544
+ * in classes implementing that interface. Returns implementation method
545
+ * results with lower confidence ('interface-dispatch').
546
+ */
547
+ function findInterfaceDispatchTargets(calledName, receiverTypeName, currentFile, ctx, heritageMap, primaryNodeId) {
548
+ const implFiles = heritageMap.getImplementorFiles(receiverTypeName);
549
+ if (implFiles.size === 0)
550
+ return [];
551
+ const typeResolved = ctx.resolve(receiverTypeName, currentFile);
552
+ if (!typeResolved)
553
+ return [];
554
+ if (!typeResolved.candidates.some((c) => c.type === 'Interface'))
555
+ return [];
556
+ const results = [];
557
+ for (const implFile of implFiles) {
558
+ const methods = ctx.model.symbols.lookupExactAll(implFile, calledName);
559
+ for (const method of methods) {
560
+ if (method.nodeId !== primaryNodeId) {
561
+ results.push({
562
+ nodeId: method.nodeId,
563
+ confidence: 0.7,
564
+ reason: 'interface-dispatch',
565
+ });
566
+ }
567
+ }
568
+ }
569
+ return results;
570
+ }
571
+ export const processCalls = async (graph, files, astCache, ctx, onProgress, exportedTypeMap,
572
+ /** Phase 14: pre-resolved cross-file bindings to seed into buildTypeEnv. Keyed by filePath → Map<localName, typeName>. */
573
+ importedBindingsMap,
574
+ /** Phase 14 E3: cross-file return types for imported callables. Keyed by filePath → Map<calleeName, returnType>.
575
+ * Consulted ONLY when SymbolTable has no unambiguous match (local-first principle). */
576
+ importedReturnTypesMap,
577
+ /** Phase 14 E3: cross-file RAW return types for for-loop element extraction. Keyed by filePath → Map<calleeName, rawReturnType>. */
578
+ importedRawReturnTypesMap, heritageMap, bindingAccumulator) => {
579
+ const parser = await loadParser();
580
+ const collectedHeritage = [];
581
+ const pendingWrites = [];
582
+ // Phase P cross-file: accumulate heritage across files for cross-file isSubclassOf.
583
+ // Used as a secondary check when per-file parentMap lacks the relationship — helps
584
+ // when the heritage-declaring file is processed before the call site file.
585
+ // For remaining cases (reverse file order), the SymbolTable class-type fallback applies.
586
+ const globalParentMap = new Map();
587
+ const globalParentSeen = new Map();
588
+ const logSkipped = isVerboseIngestionEnabled();
589
+ const skippedByLang = logSkipped ? new Map() : null;
590
+ const prepared = [];
591
+ for (let i = 0; i < files.length; i++) {
592
+ const file = files[i];
593
+ if (i % 20 === 0)
594
+ await yieldToEventLoop();
595
+ const language = getLanguageFromFilename(file.path);
596
+ if (!language)
597
+ continue;
598
+ // Registry-primary gate: scope-based phase owns CALLS for this lang.
599
+ if (isRegistryPrimary(language))
600
+ continue;
601
+ if (!isLanguageAvailable(language)) {
602
+ if (skippedByLang) {
603
+ skippedByLang.set(language, (skippedByLang.get(language) ?? 0) + 1);
604
+ }
605
+ continue;
606
+ }
607
+ const provider = getProvider(language);
608
+ const queryStr = provider.treeSitterQueries;
609
+ if (!queryStr)
610
+ continue;
611
+ await loadLanguage(language, file.path);
612
+ let tree = astCache.get(file.path);
613
+ if (!tree) {
614
+ try {
615
+ tree = parser.parse(file.content, undefined, {
616
+ bufferSize: getTreeSitterBufferSize(file.content.length),
617
+ });
618
+ }
619
+ catch (parseError) {
620
+ continue;
621
+ }
622
+ astCache.set(file.path, tree);
623
+ }
624
+ let matches;
625
+ try {
626
+ const lang = parser.getLanguage();
627
+ const query = new Parser.Query(lang, queryStr);
628
+ matches = query.matches(tree.rootNode);
629
+ }
630
+ catch (queryError) {
631
+ console.warn(`Query error for ${file.path}:`, queryError);
632
+ continue;
633
+ }
634
+ // Extract heritage from query matches to build parentMap for buildTypeEnv.
635
+ // Heritage-processor runs in PARALLEL, so graph edges don't exist when buildTypeEnv runs.
636
+ const fileParentMap = new Map();
637
+ if (provider.heritageExtractor) {
638
+ for (const match of matches) {
639
+ const captureMap = {};
640
+ match.captures.forEach((c) => (captureMap[c.name] = c.node));
641
+ if (captureMap['heritage.class']) {
642
+ const heritageItems = provider.heritageExtractor.extract(captureMap, {
643
+ filePath: file.path,
644
+ language,
645
+ });
646
+ for (const item of heritageItems) {
647
+ if (item.kind === 'extends') {
648
+ let parents = fileParentMap.get(item.className);
649
+ if (!parents) {
650
+ parents = [];
651
+ fileParentMap.set(item.className, parents);
652
+ }
653
+ if (!parents.includes(item.parentName))
654
+ parents.push(item.parentName);
655
+ }
656
+ }
657
+ }
658
+ }
659
+ }
660
+ const parentMap = fileParentMap;
661
+ // Merge per-file heritage into globalParentMap for cross-file isSubclassOf lookups.
662
+ for (const [cls, parents] of fileParentMap) {
663
+ let global = globalParentMap.get(cls);
664
+ let seen = globalParentSeen.get(cls);
665
+ if (!global) {
666
+ global = [];
667
+ globalParentMap.set(cls, global);
668
+ }
669
+ if (!seen) {
670
+ seen = new Set();
671
+ globalParentSeen.set(cls, seen);
672
+ }
673
+ for (const p of parents) {
674
+ if (!seen.has(p)) {
675
+ seen.add(p);
676
+ global.push(p);
677
+ }
678
+ }
679
+ }
680
+ const importedBindings = importedBindingsMap?.get(file.path);
681
+ const importedReturnTypes = importedReturnTypesMap?.get(file.path);
682
+ const importedRawReturnTypes = importedRawReturnTypesMap?.get(file.path);
683
+ const typeEnv = buildTypeEnv(tree, language, {
684
+ model: ctx.model,
685
+ parentMap,
686
+ importedBindings,
687
+ importedReturnTypes,
688
+ importedRawReturnTypes,
689
+ enclosingFunctionFinder: provider?.enclosingFunctionFinder,
690
+ extractFunctionName: provider?.methodExtractor?.extractFunctionName,
691
+ });
692
+ if (typeEnv && exportedTypeMap) {
693
+ const fileExports = collectExportedBindings(typeEnv, file.path, ctx.model.symbols, graph);
694
+ if (fileExports)
695
+ exportedTypeMap.set(file.path, fileExports);
696
+ }
697
+ if (bindingAccumulator) {
698
+ typeEnv.flush(file.path, bindingAccumulator);
699
+ }
700
+ prepared.push({ file, language, provider, tree, matches, parentMap, typeEnv });
701
+ }
702
+ // ── Resolution loop: verify constructor bindings and resolve calls ──
703
+ // The accumulator (if present) is now fully populated from the preparation
704
+ // loop above, so verifyConstructorBindings sees all provider bindings
705
+ // regardless of file processing order.
706
+ for (let i = 0; i < prepared.length; i++) {
707
+ const { file, language, provider, tree, matches, parentMap, typeEnv } = prepared[i];
708
+ enclosingFnExtractCache.clear();
709
+ onProgress?.(i + 1, files.length);
710
+ if (i % 20 === 0)
711
+ await yieldToEventLoop();
712
+ const callRouter = provider.callRouter;
713
+ const verifiedReceivers = typeEnv.constructorBindings.length > 0
714
+ ? verifyConstructorBindings(typeEnv.constructorBindings, file.path, ctx, undefined, // graph not available on the sequential path here
715
+ bindingAccumulator)
716
+ : new Map();
717
+ const receiverIndex = buildReceiverTypeIndex(verifiedReceivers);
718
+ ctx.enableCache(file.path);
719
+ const widenCache = new Map();
720
+ matches.forEach((match) => {
721
+ const captureMap = {};
722
+ match.captures.forEach((c) => (captureMap[c.name] = c.node));
723
+ // ── Write access: emit ACCESSES {reason: 'write'} for assignments to member fields ──
724
+ if (captureMap['assignment'] &&
725
+ captureMap['assignment.receiver'] &&
726
+ captureMap['assignment.property']) {
727
+ const receiverNode = captureMap['assignment.receiver'];
728
+ const propertyName = captureMap['assignment.property'].text;
729
+ // Resolve receiver type: simple identifier → TypeEnv lookup or class resolution
730
+ let receiverTypeName;
731
+ const receiverText = receiverNode.text;
732
+ if (receiverText && typeEnv) {
733
+ receiverTypeName = typeEnv.lookup(receiverText, captureMap['assignment']);
734
+ }
735
+ // Fall back to verified constructor bindings (mirrors CALLS resolution tier 2)
736
+ if (!receiverTypeName && receiverText && receiverIndex.size > 0) {
737
+ const enclosing = findEnclosingFunction(captureMap['assignment'], file.path, ctx, provider);
738
+ const funcName = enclosing ? extractFuncNameFromSourceId(enclosing) : '';
739
+ receiverTypeName = lookupReceiverType(receiverIndex, funcName, receiverText);
740
+ }
741
+ if (!receiverTypeName && receiverText) {
742
+ const resolved = ctx.resolve(receiverText, file.path);
743
+ if (resolved?.candidates.some((d) => CLASS_LIKE_TYPES.has(d.type))) {
744
+ receiverTypeName = receiverText;
745
+ }
746
+ }
747
+ if (receiverTypeName) {
748
+ const enclosing = findEnclosingFunction(captureMap['assignment'], file.path, ctx, provider);
749
+ const srcId = enclosing || generateId('File', file.path);
750
+ // Defer resolution: Ruby attr_accessor properties are registered during
751
+ // this same loop, so cross-file lookups fail if the declaring file hasn't
752
+ // been processed yet. Collect now, resolve after all files are done.
753
+ pendingWrites.push({ receiverTypeName, propertyName, filePath: file.path, srcId });
754
+ }
755
+ // Assignment-only capture (no @call sibling): skip the rest of this
756
+ // forEach iteration — this acts as a `continue` in the match loop.
757
+ if (!captureMap['call'])
758
+ return;
759
+ }
760
+ if (!captureMap['call'])
761
+ return;
762
+ const callNode = captureMap['call'];
763
+ const callExtractor = provider.callExtractor;
764
+ // ── Language-specific call site (e.g. Java :: method references) ──
765
+ if (callExtractor) {
766
+ const langCallSite = callExtractor.extract(callNode, undefined);
767
+ if (langCallSite) {
768
+ if (provider.isBuiltInName(langCallSite.calledName))
769
+ return;
770
+ const sourceId = findEnclosingFunction(callNode, file.path, ctx, provider) ||
771
+ generateId('File', file.path);
772
+ const receiverName = langCallSite.callForm === 'member' ? langCallSite.receiverName : undefined;
773
+ let receiverTypeName = receiverName && typeEnv ? typeEnv.lookup(receiverName, callNode) : undefined;
774
+ if (langCallSite.typeAsReceiverHeuristic &&
775
+ receiverName !== undefined &&
776
+ receiverTypeName === undefined &&
777
+ langCallSite.callForm === 'member') {
778
+ const c0 = receiverName.charCodeAt(0);
779
+ if (c0 >= 65 && c0 <= 90)
780
+ receiverTypeName = receiverName;
781
+ }
782
+ const resolved = resolveCallTarget({
783
+ calledName: langCallSite.calledName,
784
+ callForm: langCallSite.callForm,
785
+ ...(receiverTypeName !== undefined ? { receiverTypeName } : {}),
786
+ ...(receiverName !== undefined ? { receiverName } : {}),
787
+ }, file.path, ctx, undefined, widenCache, undefined, heritageMap);
788
+ if (!resolved)
789
+ return;
790
+ graph.addRelationship({
791
+ id: generateId('CALLS', `${sourceId}:${langCallSite.calledName}->${resolved.nodeId}`),
792
+ sourceId,
793
+ targetId: resolved.nodeId,
794
+ type: 'CALLS',
795
+ confidence: resolved.confidence,
796
+ reason: resolved.reason,
797
+ });
798
+ if (heritageMap && langCallSite.callForm === 'member' && receiverTypeName) {
799
+ const implTargets = findInterfaceDispatchTargets(langCallSite.calledName, receiverTypeName, file.path, ctx, heritageMap, resolved.nodeId);
800
+ for (const impl of implTargets) {
801
+ graph.addRelationship({
802
+ id: generateId('CALLS', `${sourceId}:${langCallSite.calledName}->${impl.nodeId}`),
803
+ sourceId,
804
+ targetId: impl.nodeId,
805
+ type: 'CALLS',
806
+ confidence: impl.confidence,
807
+ reason: impl.reason,
808
+ });
809
+ }
810
+ }
811
+ return;
812
+ }
813
+ }
814
+ const nameNode = captureMap['call.name'];
815
+ if (!nameNode)
816
+ return;
817
+ const calledName = nameNode.text;
818
+ // Check heritage extractor for call-based heritage (e.g., Ruby include/extend/prepend)
819
+ if (provider.heritageExtractor?.extractFromCall) {
820
+ const heritageItems = provider.heritageExtractor.extractFromCall(calledName, captureMap['call'], { filePath: file.path, language });
821
+ if (heritageItems !== null) {
822
+ for (const item of heritageItems) {
823
+ collectedHeritage.push({
824
+ filePath: file.path,
825
+ className: item.className,
826
+ parentName: item.parentName,
827
+ kind: item.kind,
828
+ });
829
+ }
830
+ return;
831
+ }
832
+ }
833
+ // Dispatch: route language-specific calls (properties, imports)
834
+ // Heritage routing is handled by heritageExtractor.extractFromCall above.
835
+ const routed = callRouter?.(calledName, captureMap['call']);
836
+ if (routed) {
837
+ switch (routed.kind) {
838
+ case 'skip':
839
+ case 'import':
840
+ return;
841
+ case 'properties': {
842
+ const fileId = generateId('File', file.path);
843
+ const propEnclosingClassId = findEnclosingClassId(captureMap['call'], file.path);
844
+ for (const item of routed.items) {
845
+ const nodeId = generateId('Property', `${file.path}:${item.propName}`);
846
+ graph.addNode({
847
+ id: nodeId,
848
+ label: 'Property',
849
+ properties: {
850
+ name: item.propName,
851
+ filePath: file.path,
852
+ startLine: item.startLine,
853
+ endLine: item.endLine,
854
+ language,
855
+ isExported: true,
856
+ description: item.accessorType,
857
+ },
858
+ });
859
+ ctx.model.symbols.add(file.path, item.propName, nodeId, 'Property', {
860
+ ...(propEnclosingClassId ? { ownerId: propEnclosingClassId } : {}),
861
+ ...(item.declaredType ? { declaredType: item.declaredType } : {}),
862
+ });
863
+ const relId = generateId('DEFINES', `${fileId}->${nodeId}`);
864
+ graph.addRelationship({
865
+ id: relId,
866
+ sourceId: fileId,
867
+ targetId: nodeId,
868
+ type: 'DEFINES',
869
+ confidence: 1.0,
870
+ reason: '',
871
+ });
872
+ if (propEnclosingClassId) {
873
+ graph.addRelationship({
874
+ id: generateId('HAS_PROPERTY', `${propEnclosingClassId}->${nodeId}`),
875
+ sourceId: propEnclosingClassId,
876
+ targetId: nodeId,
877
+ type: 'HAS_PROPERTY',
878
+ confidence: 1.0,
879
+ reason: '',
880
+ });
881
+ }
882
+ }
883
+ return;
884
+ }
885
+ case 'call':
886
+ break;
887
+ }
888
+ }
889
+ if (provider.isBuiltInName(calledName))
890
+ return;
891
+ // --- DAG stage 2-3: classify-form + infer-receiver (shared defaults) ---
892
+ // These stages run the shared inference chain. Language providers can
893
+ // customize infer-receiver (stage 3) via the inferImplicitReceiver hook
894
+ // which runs AFTER this default chain (typed-binding → constructor-map →
895
+ // module-alias → class-as-receiver → mixed-chain), and selectDispatch
896
+ // (stage 4) which picks the resolver branch.
897
+ let callForm = inferCallForm(callNode, nameNode);
898
+ let receiverName = callForm === 'member' ? extractReceiverName(nameNode) : undefined;
899
+ let receiverTypeName = receiverName && typeEnv ? typeEnv.lookup(receiverName, callNode) : undefined;
900
+ let receiverSource = receiverTypeName ? 'typed-binding' : 'none';
901
+ // Phase P: virtual dispatch override — when the declared type is a base class but
902
+ // the constructor created a known subclass, prefer the more specific type.
903
+ // Checks per-file parentMap first, then falls back to globalParentMap for
904
+ // cross-file heritage (e.g. Dog extends Animal declared in a different file).
905
+ // Reconstructs the exact scope key (funcName@startIndex\0varName) from the
906
+ // enclosing function AST node for a correct, O(1) map lookup.
907
+ if (receiverTypeName && receiverName && typeEnv && typeEnv.constructorTypeMap.size > 0) {
908
+ // Reconstruct scope key to match constructorTypeMap's scope\0varName format
909
+ let scope = '';
910
+ let p = callNode.parent;
911
+ while (p) {
912
+ if (FUNCTION_NODE_TYPES.has(p.type)) {
913
+ const funcName = provider.methodExtractor?.extractFunctionName?.(p)?.funcName ?? genericFuncName(p);
914
+ if (funcName) {
915
+ scope = `${funcName}@${p.startIndex}`;
916
+ break;
917
+ }
918
+ }
919
+ p = p.parent;
920
+ }
921
+ const ctorType = typeEnv.constructorTypeMap.get(`${scope}\0${receiverName}`);
922
+ if (ctorType && ctorType !== receiverTypeName) {
923
+ // Verify subclass relationship: per-file parentMap first, then cross-file
924
+ // globalParentMap, then fall back to SymbolTable class verification.
925
+ // The SymbolTable fallback handles cross-file cases where heritage is declared
926
+ // in a file not yet processed (e.g. Dog extends Animal in models/Dog.kt when
927
+ // processing services/App.kt). Since constructorTypeMap only records entries
928
+ // when a type annotation AND constructor are both present (val x: Base = Sub()),
929
+ // confirming both are class-like types is sufficient — the original code would
930
+ // not compile if Sub didn't extend Base.
931
+ if (isSubclassOf(ctorType, receiverTypeName, parentMap) ||
932
+ isSubclassOf(ctorType, receiverTypeName, globalParentMap) ||
933
+ (ctx.model.types.lookupClassByName(ctorType).length > 0 &&
934
+ ctx.model.types.lookupClassByName(receiverTypeName).length > 0)) {
935
+ receiverTypeName = ctorType;
936
+ receiverSource = 'constructor-map';
937
+ }
938
+ }
939
+ }
940
+ // Fall back to verified constructor bindings for return type inference
941
+ if (!receiverTypeName && receiverName && receiverIndex.size > 0) {
942
+ const enclosingFunc = findEnclosingFunction(callNode, file.path, ctx, provider);
943
+ const funcName = enclosingFunc ? extractFuncNameFromSourceId(enclosingFunc) : '';
944
+ receiverTypeName = lookupReceiverType(receiverIndex, funcName, receiverName);
945
+ if (receiverTypeName)
946
+ receiverSource = 'constructor-map';
947
+ }
948
+ // Fall back to class-as-receiver for static method calls (e.g. UserService.find_user(),
949
+ // Greetable.format()). When the receiver name is not a variable in TypeEnv but
950
+ // resolves to a class-like symbol (Class / Interface / Struct / Enum / Trait) via
951
+ // tiered resolution, use it directly as the receiver type. `Trait` is included so
952
+ // Ruby module class-method calls flow through the class-as-receiver path and reach
953
+ // the `selectDispatch` hook's singleton branch.
954
+ if (!receiverTypeName && receiverName && callForm === 'member') {
955
+ const typeResolved = ctx.resolve(receiverName, file.path);
956
+ if (typeResolved &&
957
+ typeResolved.candidates.some((d) => d.type === 'Class' ||
958
+ d.type === 'Interface' ||
959
+ d.type === 'Struct' ||
960
+ d.type === 'Enum' ||
961
+ d.type === 'Trait')) {
962
+ receiverTypeName = receiverName;
963
+ receiverSource = 'class-as-receiver';
964
+ }
965
+ }
966
+ // Hoist sourceId so it's available for ACCESSES edge emission during chain walk.
967
+ const enclosingFuncId = findEnclosingFunction(callNode, file.path, ctx, provider);
968
+ const sourceId = enclosingFuncId || generateId('File', file.path);
969
+ // Fall back to mixed chain resolution when the receiver is a complex expression
970
+ // (field chain, call chain, or interleaved — e.g. user.address.city.save() or
971
+ // svc.getUser().address.save()). Handles all cases with a single unified walk.
972
+ if (callForm === 'member' && !receiverTypeName && !receiverName) {
973
+ const receiverNode = extractReceiverNode(nameNode);
974
+ if (receiverNode) {
975
+ const extracted = extractMixedChain(receiverNode);
976
+ if (extracted && extracted.chain.length > 0) {
977
+ let currentType = extracted.baseReceiverName && typeEnv
978
+ ? typeEnv.lookup(extracted.baseReceiverName, callNode)
979
+ : undefined;
980
+ if (!currentType && extracted.baseReceiverName && receiverIndex.size > 0) {
981
+ const funcName = enclosingFuncId ? extractFuncNameFromSourceId(enclosingFuncId) : '';
982
+ currentType = lookupReceiverType(receiverIndex, funcName, extracted.baseReceiverName);
983
+ }
984
+ if (!currentType && extracted.baseReceiverName) {
985
+ const cr = ctx.resolve(extracted.baseReceiverName, file.path);
986
+ if (cr?.candidates.some((d) => d.type === 'Class' ||
987
+ d.type === 'Interface' ||
988
+ d.type === 'Struct' ||
989
+ d.type === 'Enum')) {
990
+ currentType = extracted.baseReceiverName;
991
+ }
992
+ }
993
+ if (currentType) {
994
+ receiverTypeName = walkMixedChain(extracted.chain, currentType, file.path, ctx, makeAccessEmitter(graph, sourceId), heritageMap);
995
+ if (receiverTypeName)
996
+ receiverSource = 'mixed-chain';
997
+ }
998
+ }
999
+ }
1000
+ }
1001
+ // --- DAG stage 3: infer-receiver (provider hook) ---
1002
+ // Synthesize implicit receivers for languages that omit them (e.g., Ruby bare-call).
1003
+ // This hook runs AFTER the shared inference chain so explicit receivers /
1004
+ // typed bindings always take precedence. Output (if non-null) overlays onto
1005
+ // the ReceiverEnriched for the next stage.
1006
+ let dispatchHint;
1007
+ if (provider.inferImplicitReceiver) {
1008
+ const override = provider.inferImplicitReceiver({
1009
+ calledName,
1010
+ callForm,
1011
+ receiverName,
1012
+ receiverTypeName,
1013
+ callNode,
1014
+ filePath: file.path,
1015
+ });
1016
+ if (override) {
1017
+ callForm = override.callForm;
1018
+ receiverName = override.receiverName;
1019
+ receiverTypeName = override.receiverTypeName;
1020
+ receiverSource = override.receiverSource;
1021
+ dispatchHint = override.hint;
1022
+ }
1023
+ }
1024
+ // --- DAG stage 4: select-dispatch (provider hook + default fallback) ---
1025
+ // Decide which resolver path to try first (primary) and fallback strategy.
1026
+ // Language providers can customize dispatch via selectDispatch hook; all
1027
+ // others use the shared defaultDispatchDecision. Always non-null after this
1028
+ // block so downstream resolvers are table-driven.
1029
+ const dispatchDecision = provider.selectDispatch?.({
1030
+ calledName,
1031
+ callForm,
1032
+ receiverName,
1033
+ receiverTypeName,
1034
+ receiverSource,
1035
+ hint: dispatchHint,
1036
+ }) ?? defaultDispatchDecision(callForm);
1037
+ // Build overload hints for languages with inferLiteralType (Java/Kotlin/C#/C++).
1038
+ // Only used when multiple candidates survive arity filtering — ~1-3% of calls.
1039
+ const langConfig = provider.typeConfig;
1040
+ const hints = langConfig?.inferLiteralType
1041
+ ? { callNode, inferLiteralType: langConfig.inferLiteralType, typeEnv }
1042
+ : undefined;
1043
+ const resolved = resolveCallTarget({
1044
+ calledName,
1045
+ argCount: countCallArguments(callNode),
1046
+ callForm,
1047
+ receiverTypeName,
1048
+ receiverName,
1049
+ }, file.path, ctx, hints, widenCache, undefined, heritageMap, dispatchDecision);
1050
+ if (!resolved)
1051
+ return;
1052
+ const relId = generateId('CALLS', `${sourceId}:${calledName}->${resolved.nodeId}`);
1053
+ graph.addRelationship({
1054
+ id: relId,
1055
+ sourceId,
1056
+ targetId: resolved.nodeId,
1057
+ type: 'CALLS',
1058
+ confidence: resolved.confidence,
1059
+ reason: resolved.reason,
1060
+ });
1061
+ if (heritageMap && callForm === 'member' && receiverTypeName) {
1062
+ const implTargets = findInterfaceDispatchTargets(calledName, receiverTypeName, file.path, ctx, heritageMap, resolved.nodeId);
1063
+ for (const impl of implTargets) {
1064
+ graph.addRelationship({
1065
+ id: generateId('CALLS', `${sourceId}:${calledName}->${impl.nodeId}`),
1066
+ sourceId,
1067
+ targetId: impl.nodeId,
1068
+ type: 'CALLS',
1069
+ confidence: impl.confidence,
1070
+ reason: impl.reason,
1071
+ });
1072
+ }
1073
+ }
1074
+ });
1075
+ // Vue: emit CALLS edges for PascalCase components used in <template>.
1076
+ // Template components are default-imported (not named), so we match the
1077
+ // component name against imported .vue file basenames via the import map.
1078
+ if (language === SupportedLanguages.Vue) {
1079
+ const templateComponents = extractTemplateComponents(file.content);
1080
+ if (templateComponents.length > 0) {
1081
+ const fileId = generateId('File', file.path);
1082
+ const importedFiles = ctx.importMap.get(file.path);
1083
+ if (importedFiles) {
1084
+ for (const componentName of templateComponents) {
1085
+ for (const importedPath of importedFiles) {
1086
+ if (!importedPath.endsWith('.vue'))
1087
+ continue;
1088
+ const basename = importedPath.slice(importedPath.lastIndexOf('/') + 1, importedPath.lastIndexOf('.'));
1089
+ if (basename !== componentName)
1090
+ continue;
1091
+ const targetFileId = generateId('File', importedPath);
1092
+ if (graph.getNode(targetFileId)) {
1093
+ graph.addRelationship({
1094
+ id: generateId('CALLS', `${fileId}:${componentName}->${targetFileId}`),
1095
+ sourceId: fileId,
1096
+ targetId: targetFileId,
1097
+ type: 'CALLS',
1098
+ confidence: 0.9,
1099
+ reason: 'vue-template-component',
1100
+ });
1101
+ }
1102
+ break;
1103
+ }
1104
+ }
1105
+ }
1106
+ }
1107
+ }
1108
+ ctx.clearCache();
1109
+ }
1110
+ // ── Resolve deferred write-access edges ──
1111
+ // All properties (including Ruby attr_accessor) are now registered.
1112
+ for (const pw of pendingWrites) {
1113
+ const fieldOwner = resolveFieldOwnership(pw.receiverTypeName, pw.propertyName, pw.filePath, ctx);
1114
+ if (fieldOwner) {
1115
+ graph.addRelationship({
1116
+ id: generateId('ACCESSES', `${pw.srcId}:${fieldOwner.nodeId}:write`),
1117
+ sourceId: pw.srcId,
1118
+ targetId: fieldOwner.nodeId,
1119
+ type: 'ACCESSES',
1120
+ confidence: 1.0,
1121
+ reason: 'write',
1122
+ });
1123
+ }
1124
+ }
1125
+ if (skippedByLang && skippedByLang.size > 0) {
1126
+ for (const [lang, count] of skippedByLang.entries()) {
1127
+ console.warn(`[ingestion] Skipped ${count} ${lang} file(s) in call processing — ${lang} parser not available.`);
1128
+ }
1129
+ }
1130
+ return collectedHeritage;
1131
+ };
1132
+ // FREE_CALLABLE_TYPES imported from symbol-table.ts — single source of truth.
1133
+ const CONSTRUCTOR_TARGET_TYPES = new Set(['Constructor', 'Class', 'Struct', 'Record']);
1134
+ const filterCallableCandidates = (candidates, argCount, callForm) => {
1135
+ let kindFiltered;
1136
+ if (callForm === 'constructor') {
1137
+ const constructors = candidates.filter((c) => c.type === 'Constructor');
1138
+ if (constructors.length > 0) {
1139
+ kindFiltered = constructors;
1140
+ }
1141
+ else {
1142
+ const types = candidates.filter((c) => CONSTRUCTOR_TARGET_TYPES.has(c.type));
1143
+ kindFiltered =
1144
+ types.length > 0 ? types : candidates.filter((c) => CALL_TARGET_TYPES.has(c.type));
1145
+ }
1146
+ }
1147
+ else {
1148
+ // CALL_TARGET_TYPES (not FREE_CALLABLE_TYPES) — the post-A4 filter must
1149
+ // also admit Method and Constructor candidates, which are now unioned
1150
+ // into the pool from `model.methods.lookupMethodByName` rather than
1151
+ // `symbols.lookupCallableByName`.
1152
+ kindFiltered = candidates.filter((c) => CALL_TARGET_TYPES.has(c.type));
1153
+ }
1154
+ if (kindFiltered.length === 0)
1155
+ return [];
1156
+ if (argCount === undefined)
1157
+ return kindFiltered;
1158
+ const hasParameterMetadata = kindFiltered.some((candidate) => candidate.parameterCount !== undefined);
1159
+ if (!hasParameterMetadata)
1160
+ return kindFiltered;
1161
+ return kindFiltered.filter((candidate) => candidate.parameterCount === undefined ||
1162
+ (argCount >= (candidate.requiredParameterCount ?? candidate.parameterCount) &&
1163
+ argCount <= candidate.parameterCount));
1164
+ };
1165
+ /**
1166
+ * Count callable candidates matching the kind + arity filter without
1167
+ * allocating an intermediate array. Short-circuits once count exceeds
1168
+ * `threshold` (default 1) — used by the dispatcher's `skipMember` check
1169
+ * where we only need to know "more than one survivor".
1170
+ */
1171
+ const countCallableCandidates = (candidates, argCount, callForm, threshold = 1) => {
1172
+ let count = 0;
1173
+ for (const c of candidates) {
1174
+ // Kind filter (mirrors filterCallableCandidates)
1175
+ const typeOk = callForm === 'constructor'
1176
+ ? CONSTRUCTOR_TARGET_TYPES.has(c.type)
1177
+ : CALL_TARGET_TYPES.has(c.type);
1178
+ if (!typeOk)
1179
+ continue;
1180
+ // Arity filter
1181
+ if (argCount !== undefined &&
1182
+ c.parameterCount !== undefined &&
1183
+ (argCount < (c.requiredParameterCount ?? c.parameterCount) || argCount > c.parameterCount)) {
1184
+ continue;
1185
+ }
1186
+ count++;
1187
+ if (count > threshold)
1188
+ return count; // early exit
1189
+ }
1190
+ return count;
1191
+ };
1192
+ const toResolveResult = (definition, tier) => ({
1193
+ nodeId: definition.nodeId,
1194
+ confidence: TIER_CONFIDENCE[tier],
1195
+ reason: tier === 'same-file' ? 'same-file' : tier === 'import-scoped' ? 'import-resolved' : 'global',
1196
+ returnType: definition.returnType,
1197
+ });
1198
+ /**
1199
+ * Kotlin often declares parameters with boxed names (`Int`, `Boolean`, …) while
1200
+ * literal inference yields JVM primitives (`int`, `boolean`). This map aligns
1201
+ * those for overload matching. Java parameter text is usually already primitive
1202
+ * spellings, so lookups here are typically unchanged.
1203
+ */
1204
+ const KOTLIN_BOXED_TO_PRIMITIVE = {
1205
+ Int: 'int',
1206
+ Long: 'long',
1207
+ Short: 'short',
1208
+ Byte: 'byte',
1209
+ Float: 'float',
1210
+ Double: 'double',
1211
+ Boolean: 'boolean',
1212
+ Char: 'char',
1213
+ };
1214
+ const normalizeJvmTypeName = (name) => KOTLIN_BOXED_TO_PRIMITIVE[name] ?? name;
1215
+ const matchCandidatesByArgTypes = (candidates, argTypes) => {
1216
+ if (!candidates.some((c) => c.parameterTypes))
1217
+ return null;
1218
+ const matched = candidates.filter((c) => {
1219
+ // Keep candidates without type info — conservative: partially-annotated codebases
1220
+ // (e.g. C++ with some missing declarations) may have mixed typed/untyped overloads.
1221
+ // If one typed and one untyped both survive, matched.length > 1 → returns null (no edge).
1222
+ if (!c.parameterTypes)
1223
+ return true;
1224
+ return c.parameterTypes.every((pType, i) => {
1225
+ if (i >= argTypes.length || !argTypes[i])
1226
+ return true;
1227
+ // Normalise Kotlin boxed type names (Int→int, Boolean→boolean, etc.) so
1228
+ // that the stored declaration type matches the inferred literal type.
1229
+ return normalizeJvmTypeName(pType) === argTypes[i];
1230
+ });
1231
+ });
1232
+ if (matched.length === 1)
1233
+ return matched[0];
1234
+ // Multiple survivors may share the same nodeId (e.g. TypeScript overload signatures +
1235
+ // implementation body all collide via generateId). Deduplicate by nodeId — if all
1236
+ // matched candidates resolve to the same graph node, disambiguation succeeded.
1237
+ if (matched.length > 1) {
1238
+ const uniqueIds = new Set(matched.map((c) => c.nodeId));
1239
+ if (uniqueIds.size === 1)
1240
+ return matched[0];
1241
+ }
1242
+ return null;
1243
+ };
1244
+ /**
1245
+ * Try to disambiguate overloaded candidates using argument literal types.
1246
+ * Only invoked when filteredCandidates.length > 1 and at least one has parameterTypes.
1247
+ * Returns the single matching candidate, or null if ambiguous/inconclusive.
1248
+ */
1249
+ const tryOverloadDisambiguation = (candidates, hints) => {
1250
+ const argTypes = extractCallArgTypes(hints.callNode, hints.inferLiteralType, hints.typeEnv ? (varName, cn) => hints.typeEnv.lookup(varName, cn) : undefined);
1251
+ if (!argTypes)
1252
+ return null;
1253
+ return matchCandidatesByArgTypes(candidates, argTypes);
1254
+ };
1255
+ /**
1256
+ * Apply overload-hint or arg-type disambiguation to a pre-filtered candidate
1257
+ * pool. Returns the unique survivor, or null when neither signal is present,
1258
+ * neither can disambiguate, or the pool remains ambiguous.
1259
+ *
1260
+ * Precedence rule: `overloadHints` wins over `preComputedArgTypes` when both
1261
+ * are supplied. The AST-based disambiguator has access to live type inference
1262
+ * hooks, whereas `preComputedArgTypes` is a worker-path pre-computation that
1263
+ * may be coarser-grained.
1264
+ *
1265
+ * Single source of truth for the narrowing-signal precedence used by member
1266
+ * and constructor resolution paths. Add a new narrowing signal here once, not
1267
+ * at each call site.
1268
+ */
1269
+ const disambiguateByOverloadOrArgTypes = (pool, overloadHints, preComputedArgTypes) => {
1270
+ if (!overloadHints && !preComputedArgTypes)
1271
+ return null;
1272
+ if (overloadHints)
1273
+ return tryOverloadDisambiguation(pool, overloadHints);
1274
+ if (preComputedArgTypes)
1275
+ return matchCandidatesByArgTypes(pool, preComputedArgTypes);
1276
+ return null;
1277
+ };
1278
+ /**
1279
+ * Collapse Swift-extension duplicate Class/Struct candidates to the primary
1280
+ * definition, preferring the shortest file path.
1281
+ *
1282
+ * Swift extensions (`extension User { ... }` in a separate file) create
1283
+ * multiple `Class` nodes sharing the same symbol name — one for the primary
1284
+ * declaration and one per extension file. When overload disambiguation and
1285
+ * receiver narrowing both fail to converge on a single candidate, this
1286
+ * heuristic picks the primary definition based on the assumption that it
1287
+ * lives at the shortest file path (e.g. `User.swift` over `UserExtensions.swift`).
1288
+ *
1289
+ * Intentionally narrower than {@link INSTANTIABLE_CLASS_TYPES}: only `Class`
1290
+ * and `Struct` are considered, not `Record`. Swift extensions only produce
1291
+ * `Class` duplicates in practice, and C#/Kotlin records do not exhibit the
1292
+ * same multi-file-definition pattern, so widening this set risks accidental
1293
+ * dedup of legitimately distinct record types.
1294
+ *
1295
+ * Returns a `ResolveResult` when the heuristic fires, `null` when the
1296
+ * candidate pool does not match the shape (mixed types, non-Class/Struct
1297
+ * kinds, or `length <= 1`). Callers should fall through to their own null
1298
+ * return when this helper returns `null`.
1299
+ *
1300
+ * Used by `resolveFreeCall`. Having a single source of truth prevents
1301
+ * duplication if the heuristic is ever tuned.
1302
+ */
1303
+ const dedupSwiftExtensionCandidates = (candidates, tier) => {
1304
+ if (candidates.length <= 1)
1305
+ return null;
1306
+ const allSameType = candidates.every((c) => c.type === candidates[0].type);
1307
+ if (!allSameType)
1308
+ return null;
1309
+ if (candidates[0].type !== 'Class' && candidates[0].type !== 'Struct')
1310
+ return null;
1311
+ const sorted = [...candidates].sort((a, b) => a.filePath.length - b.filePath.length);
1312
+ return toResolveResult(sorted[0], tier);
1313
+ };
1314
+ /**
1315
+ * Thin dispatcher that routes a call to the appropriate specialized resolver.
1316
+ *
1317
+ * - `free` → {@link resolveFreeCall}
1318
+ * - `constructor` → {@link resolveStaticCall} (with pre-resolved tiered pool)
1319
+ * - `member` with a known receiver type → {@link resolveMemberCall}, with
1320
+ * file-based fallback for traits/interfaces
1321
+ * - `member` without receiver type → module-alias check, then tiered lookup
1322
+ *
1323
+ * Replaces the former 200+ line function (SM-19: fuzzy-free call resolution).
1324
+ */
1325
+ /**
1326
+ * Module-alias resolution for member calls without a receiver type.
1327
+ *
1328
+ * Handles Python/Ruby `import mod; mod.Symbol()` patterns where the receiver
1329
+ * is a module name, not a typed variable. Uses `moduleAliasMap` to scope
1330
+ * candidates to the correct module file.
1331
+ */
1332
+ const resolveModuleAliasedCall = (call, currentFile, ctx, widenCache, tieredOverride) => {
1333
+ if (!call.receiverName)
1334
+ return null;
1335
+ const aliasMap = ctx.moduleAliasMap?.get(currentFile);
1336
+ if (!aliasMap)
1337
+ return null;
1338
+ const moduleFile = aliasMap.get(call.receiverName);
1339
+ if (!moduleFile)
1340
+ return null;
1341
+ // Reuse the caller's pre-computed tiered result when available —
1342
+ // the dispatcher already called ctx.resolve(call.calledName, currentFile).
1343
+ const tiered = tieredOverride ?? ctx.resolve(call.calledName, currentFile);
1344
+ if (!tiered)
1345
+ return null;
1346
+ // Try member-form, then constructor-form (for `module.ClassName()` patterns)
1347
+ let filtered = filterCallableCandidates(tiered.candidates, call.argCount, call.callForm).filter((c) => c.filePath === moduleFile);
1348
+ if (filtered.length === 0) {
1349
+ filtered = filterCallableCandidates(tiered.candidates, call.argCount, 'constructor').filter((c) => c.filePath === moduleFile);
1350
+ }
1351
+ if (filtered.length === 0) {
1352
+ // Widen to global callable+method indexes scoped to the aliased module
1353
+ // file. Function+ownerId (Python/Rust/Kotlin) is still routed to both
1354
+ // indexes until Unit 5 unblocks, so dedup by nodeId.
1355
+ const cacheKey = `${call.calledName}\0${moduleFile}`;
1356
+ let defs = widenCache?.get(cacheKey);
1357
+ if (!defs) {
1358
+ const rawCallable = ctx.model.symbols.lookupCallableByName(call.calledName);
1359
+ const rawMethods = ctx.model.methods.lookupMethodByName(call.calledName);
1360
+ const widenCombined = [];
1361
+ const widenSeen = new Set();
1362
+ for (const d of rawCallable) {
1363
+ if (widenSeen.has(d.nodeId))
1364
+ continue;
1365
+ widenSeen.add(d.nodeId);
1366
+ widenCombined.push(d);
1367
+ }
1368
+ for (const d of rawMethods) {
1369
+ if (widenSeen.has(d.nodeId))
1370
+ continue;
1371
+ widenSeen.add(d.nodeId);
1372
+ widenCombined.push(d);
1373
+ }
1374
+ defs = widenCombined;
1375
+ widenCache?.set(cacheKey, defs);
1376
+ }
1377
+ filtered = filterCallableCandidates(defs, call.argCount, call.callForm).filter((c) => c.filePath === moduleFile);
1378
+ if (filtered.length === 0) {
1379
+ filtered = filterCallableCandidates(defs, call.argCount, 'constructor').filter((c) => c.filePath === moduleFile);
1380
+ }
1381
+ }
1382
+ return filtered.length === 1 ? toResolveResult(filtered[0], tiered.tier) : null;
1383
+ };
1384
+ /**
1385
+ * File-based fallback for member calls where owner-scoped resolution fails.
1386
+ *
1387
+ * Resolves the receiver type via `ctx.resolve()` and narrows all callable
1388
+ * symbols with the method name to the receiver type's defining file(s),
1389
+ * then applies ownerId filtering and overload disambiguation.
1390
+ *
1391
+ * Handles Rust trait dispatch (`repo.find()` where `find` is on a trait impl),
1392
+ * cross-file overloaded methods, and similar patterns where ownerId
1393
+ * relationships may not be established on all candidates.
1394
+ */
1395
+ const resolveMemberCallByFile = (calledName, receiverTypeName, currentFile, ctx, argCount, callForm, overloadHints, preComputedArgTypes) => {
1396
+ const typeResolved = ctx.resolve(receiverTypeName, currentFile);
1397
+ if (!typeResolved || typeResolved.candidates.length === 0)
1398
+ return null;
1399
+ const typeNodeIds = new Set(typeResolved.candidates.map((d) => d.nodeId));
1400
+ const typeFiles = new Set(typeResolved.candidates.map((d) => d.filePath));
1401
+ // A4 (plan 006, Unit 4): consult both indexes. Strictly-labeled
1402
+ // Method/Constructor are disjoint, but Function+ownerId (Python/Rust/
1403
+ // Kotlin) is routed into BOTH indexes by `wrappedAdd` until Unit 5
1404
+ // unblocks — dedup by nodeId so overload disambiguation doesn't see
1405
+ // phantom duplicates.
1406
+ const rawCallablePool = ctx.model.symbols.lookupCallableByName(calledName);
1407
+ const rawMethodPool = ctx.model.methods.lookupMethodByName(calledName);
1408
+ const combinedPool = [];
1409
+ const combinedSeen = new Set();
1410
+ for (const def of rawCallablePool) {
1411
+ if (combinedSeen.has(def.nodeId))
1412
+ continue;
1413
+ combinedSeen.add(def.nodeId);
1414
+ combinedPool.push(def);
1415
+ }
1416
+ for (const def of rawMethodPool) {
1417
+ if (combinedSeen.has(def.nodeId))
1418
+ continue;
1419
+ combinedSeen.add(def.nodeId);
1420
+ combinedPool.push(def);
1421
+ }
1422
+ const methodPool = filterCallableCandidates(combinedPool, argCount, callForm);
1423
+ const fileFiltered = methodPool.filter((c) => typeFiles.has(c.filePath));
1424
+ if (fileFiltered.length === 1) {
1425
+ return toResolveResult(fileFiltered[0], typeResolved.tier);
1426
+ }
1427
+ // ownerId fallback: narrow by ownerId matching the type's nodeId
1428
+ const pool = fileFiltered.length > 0 ? fileFiltered : methodPool;
1429
+ const ownerFiltered = pool.filter((c) => c.ownerId && typeNodeIds.has(c.ownerId));
1430
+ if (ownerFiltered.length === 1)
1431
+ return toResolveResult(ownerFiltered[0], typeResolved.tier);
1432
+ // Overload disambiguation on the narrowed pool
1433
+ if (fileFiltered.length > 1 || ownerFiltered.length > 1) {
1434
+ const overloadPool = ownerFiltered.length > 1 ? ownerFiltered : fileFiltered;
1435
+ const disambiguated = disambiguateByOverloadOrArgTypes(overloadPool, overloadHints, preComputedArgTypes);
1436
+ if (disambiguated)
1437
+ return toResolveResult(disambiguated, typeResolved.tier);
1438
+ }
1439
+ // Zero-match null-route: receiver type resolved but no candidate matched
1440
+ // after file-based and owner-based narrowing. Refuse to emit a CALLS edge
1441
+ // rather than guess — matches the SM-10 R3 null-route contract.
1442
+ return null;
1443
+ };
1444
+ /** Return the sole survivor from a tiered pool after callable + arity filtering, or null. */
1445
+ const singleCandidate = (tiered, argCount, callForm) => {
1446
+ const filtered = filterCallableCandidates(tiered.candidates, argCount, callForm);
1447
+ return filtered.length === 1 ? toResolveResult(filtered[0], tiered.tier) : null;
1448
+ };
1449
+ /** @internal Exported for unit tests. Do not use outside tests. */
1450
+ export const _resolveCallTargetForTesting = (call, currentFile, ctx, opts) => resolveCallTarget(call, currentFile, ctx, opts?.overloadHints, opts?.widenCache, opts?.preComputedArgTypes, opts?.heritageMap);
1451
+ const resolveCallTarget = (call, currentFile, ctx, overloadHints, widenCache, preComputedArgTypes, heritageMap, dispatchDecision) => {
1452
+ const tiered = ctx.resolve(call.calledName, currentFile);
1453
+ if (!tiered)
1454
+ return null;
1455
+ // DAG dispatch: use decision.primary to pick the resolver branch.
1456
+ // Callers that own the DAG (processCalls + crossFile deferred paths)
1457
+ // pass a decision; other callers use the shared default ladder.
1458
+ // Language-specific primary / fallback / ancestryView overrides come from
1459
+ // the provider's `selectDispatch` hook.
1460
+ const decision = dispatchDecision ?? defaultDispatchDecision(call.callForm);
1461
+ const primary = decision.primary;
1462
+ if (primary === 'free') {
1463
+ return resolveFreeCall(call.calledName, currentFile, ctx, call.argCount, tiered, overloadHints, preComputedArgTypes);
1464
+ }
1465
+ if (primary === 'constructor') {
1466
+ return (resolveStaticCall(call.calledName, currentFile, ctx, call.argCount, tiered, overloadHints, preComputedArgTypes) ?? singleCandidate(tiered, call.argCount, 'constructor'));
1467
+ }
1468
+ // primary === 'owner-scoped'
1469
+ if (call.receiverTypeName) {
1470
+ // Skip the owner-scoped MRO path when the tiered pool has genuine
1471
+ // overload ambiguity that needs D1-D4+E handling, not D0.
1472
+ const skipMember = (!!overloadHints || !!preComputedArgTypes) &&
1473
+ countCallableCandidates(tiered.candidates, call.argCount, call.callForm) > 1;
1474
+ // Try owner-scoped (resolveMemberCall) then file-scoped (resolveMemberCallByFile).
1475
+ // DAG: dispatchDecision.ancestryView selects instance vs singleton ancestry
1476
+ // for kind-aware MRO strategies. Ruby `Account.log` flows via 'singleton'.
1477
+ //
1478
+ // Singleton-ancestry miss MUST NOT degrade to the file-scoped fallback:
1479
+ // resolveMemberCallByFile matches by ownerId and would happily pick an
1480
+ // instance method defined on the same class, leaking instance dispatch
1481
+ // onto what was declared a class-method call. For singleton dispatch,
1482
+ // a miss either null-routes or falls through to `decision.fallback`.
1483
+ const singletonDispatch = decision.ancestryView === 'singleton';
1484
+ const memberResult = (!skipMember
1485
+ ? resolveMemberCall(call.receiverTypeName, call.calledName, currentFile, ctx, heritageMap, call.argCount, decision.ancestryView)
1486
+ : null) ??
1487
+ (singletonDispatch
1488
+ ? null
1489
+ : resolveMemberCallByFile(call.calledName, call.receiverTypeName, currentFile, ctx, call.argCount, call.callForm, overloadHints, preComputedArgTypes));
1490
+ if (memberResult)
1491
+ return memberResult;
1492
+ // Module-alias narrowing runs as a FALLBACK, after owner/file-scoped
1493
+ // resolvers have returned null. This ordering is load-bearing: placing
1494
+ // alias narrowing first would short-circuit unique owner-scoped answers
1495
+ // when a local variable coincidentally matches an alias name, leaking
1496
+ // unrelated homonyms from the aliased file onto the wrong receiver type.
1497
+ //
1498
+ // The type-file verification guard is load-bearing for SM-10 R3: an
1499
+ // alias is only a VALID narrowing signal when the alias target file is
1500
+ // among the receiver type's defining files. If the alias points at a
1501
+ // file that does not hold `receiverTypeName`, any candidate we would
1502
+ // pick from there would belong to an unrelated class — a cross-type
1503
+ // false positive. ctx.resolve is cached per (name, file), so resolving
1504
+ // the receiver type a second time here is free.
1505
+ const typeResolves = ctx.resolve(call.receiverTypeName, currentFile);
1506
+ const aliasMap = ctx.moduleAliasMap?.get(currentFile);
1507
+ const aliasTargetFile = call.receiverName && aliasMap ? aliasMap.get(call.receiverName) : undefined;
1508
+ if (aliasTargetFile &&
1509
+ typeResolves &&
1510
+ typeResolves.candidates.some((c) => c.filePath === aliasTargetFile)) {
1511
+ const aliasResult = resolveModuleAliasedCall(call, currentFile, ctx, widenCache, tiered);
1512
+ if (aliasResult)
1513
+ return aliasResult;
1514
+ }
1515
+ // SM-10 R3 null-route: when the receiver type resolves to indexed types
1516
+ // but no scoped resolver (nor the guarded alias fallback) produced a
1517
+ // match, that's a genuine miss — refuse to emit a CALLS edge rather
1518
+ // than guess via an unscoped singleCandidate that ignores the class
1519
+ // hierarchy. When the type is NOT in the index (PHP `mixed`, dynamic
1520
+ // types, unresolvable aliases), the scoped resolvers had nothing to
1521
+ // work with and singleCandidate is the correct last resort.
1522
+ //
1523
+ // DAG fallback override: when `select-dispatch` returned
1524
+ // `fallback: 'free-arity-narrowed'` (today: Ruby implicit-self bare
1525
+ // calls whose enclosing class doesn't define the method), fall through
1526
+ // to free-call resolution instead of null-routing. This preserves
1527
+ // existing free-call arity-narrowing heuristics for bare calls that
1528
+ // happen to target methods on unrelated classes.
1529
+ if (typeResolves && typeResolves.candidates.length > 0) {
1530
+ if (decision.fallback === 'free-arity-narrowed') {
1531
+ const free = resolveFreeCall(call.calledName, currentFile, ctx, call.argCount, tiered, overloadHints, preComputedArgTypes);
1532
+ if (free)
1533
+ return free;
1534
+ }
1535
+ return null; // null-route: type resolved, no candidate matched
1536
+ }
1537
+ return singleCandidate(tiered, call.argCount, call.callForm);
1538
+ }
1539
+ // Member call with no inferred receiver type — e.g. Python `mod.fn()`
1540
+ // where `mod` is a module alias. Module-alias narrowing is the primary
1541
+ // disambiguation signal here. Also consulted from the typed-member
1542
+ // branch above as a guarded fallback after owner/file-scoped resolvers.
1543
+ return (resolveModuleAliasedCall(call, currentFile, ctx, widenCache, tiered) ??
1544
+ singleCandidate(tiered, call.argCount, call.callForm));
1545
+ };
1546
+ // ── Scope key helpers ────────────────────────────────────────────────────
1547
+ // Scope keys use the format "funcName@startIndex" (produced by type-env.ts).
1548
+ // Source IDs use "Label:filepath:funcName" (produced by parse-worker.ts).
1549
+ // NUL (\0) is used as a composite-key separator because it cannot appear
1550
+ // in source-code identifiers, preventing ambiguous concatenation.
1551
+ //
1552
+ // receiverKey stores the FULL scope (funcName@startIndex) to prevent
1553
+ // collisions between overloaded methods with the same name in different
1554
+ // classes (e.g. User.save@100 and Repo.save@200 are distinct keys).
1555
+ // Lookup uses a secondary funcName-only index built in lookupReceiverType.
1556
+ /** Extract the bare function name from a sourceId.
1557
+ * Handles both unqualified ("Function:filepath:funcName" → "funcName")
1558
+ * and qualified ("Function:filepath:ClassName.funcName" → "funcName").
1559
+ * Strips any trailing #<arity> suffix from Method/Constructor IDs. */
1560
+ const extractFuncNameFromSourceId = (sourceId) => {
1561
+ const lastColon = sourceId.lastIndexOf(':');
1562
+ const segment = lastColon >= 0 ? sourceId.slice(lastColon + 1) : '';
1563
+ const dotIdx = segment.lastIndexOf('.');
1564
+ const raw = dotIdx >= 0 ? segment.slice(dotIdx + 1) : segment;
1565
+ // Strip #<arity> suffix (e.g. "save#2" → "save")
1566
+ const hashIdx = raw.indexOf('#');
1567
+ return hashIdx >= 0 ? raw.slice(0, hashIdx) : raw;
1568
+ };
1569
+ /**
1570
+ * Build a composite key for receiver type storage.
1571
+ * Uses the full scope string (e.g. "save@100") to distinguish overloaded
1572
+ * methods with the same name in different classes.
1573
+ */
1574
+ const receiverKey = (scope, varName) => `${scope}\0${varName}`;
1575
+ /**
1576
+ * Build a two-level secondary index from the verified receiver map.
1577
+ * The verified map is keyed by `scope\0varName` where scope is either
1578
+ * "funcName@startIndex" (inside a function) or "" (file level).
1579
+ * Index structure: Map<funcName, Map<varName, ReceiverTypeEntry>>
1580
+ *
1581
+ * Known limitation: the index collapses scope keys to bare funcName,
1582
+ * so two same-arity overloads with the same local variable name but
1583
+ * different types will mark that variable as ambiguous. A future
1584
+ * enhancement should key by full scope (funcName@startIndex) and carry
1585
+ * scope keys through findEnclosingFunction's return type.
1586
+ */
1587
+ const buildReceiverTypeIndex = (map) => {
1588
+ const index = new Map();
1589
+ for (const [key, typeName] of map) {
1590
+ const nul = key.indexOf('\0');
1591
+ if (nul < 0)
1592
+ continue;
1593
+ const scope = key.slice(0, nul);
1594
+ const varName = key.slice(nul + 1);
1595
+ if (!varName)
1596
+ continue;
1597
+ if (scope !== '' && !scope.includes('@'))
1598
+ continue;
1599
+ const funcName = scope === '' ? '' : scope.slice(0, scope.indexOf('@'));
1600
+ let varMap = index.get(funcName);
1601
+ if (!varMap) {
1602
+ varMap = new Map();
1603
+ index.set(funcName, varMap);
1604
+ }
1605
+ const existing = varMap.get(varName);
1606
+ if (existing === undefined) {
1607
+ varMap.set(varName, { kind: 'resolved', value: typeName });
1608
+ }
1609
+ else if (existing.kind === 'resolved' && existing.value !== typeName) {
1610
+ varMap.set(varName, { kind: 'ambiguous' });
1611
+ }
1612
+ }
1613
+ return index;
1614
+ };
1615
+ /**
1616
+ * O(1) receiver type lookup using the pre-built secondary index.
1617
+ * Returns the unique type name if unambiguous. Falls back to file-level scope.
1618
+ */
1619
+ const lookupReceiverType = (index, funcName, varName) => {
1620
+ const funcBucket = index.get(funcName);
1621
+ if (funcBucket) {
1622
+ const entry = funcBucket.get(varName);
1623
+ if (entry?.kind === 'resolved')
1624
+ return entry.value;
1625
+ if (entry?.kind === 'ambiguous') {
1626
+ // Ambiguous in this function scope — try file-level fallback
1627
+ const fileEntry = index.get('')?.get(varName);
1628
+ return fileEntry?.kind === 'resolved' ? fileEntry.value : undefined;
1629
+ }
1630
+ }
1631
+ // Fallback: file-level scope (funcName "")
1632
+ if (funcName !== '') {
1633
+ const fileEntry = index.get('')?.get(varName);
1634
+ if (fileEntry?.kind === 'resolved')
1635
+ return fileEntry.value;
1636
+ }
1637
+ return undefined;
1638
+ };
1639
+ /**
1640
+ * Resolve the type that results from accessing `receiverName.fieldName`.
1641
+ * Requires declaredType on the Property node (needed for chain walking continuation).
1642
+ */
1643
+ const resolveFieldAccessType = (receiverName, fieldName, filePath, ctx) => {
1644
+ const fieldDef = resolveFieldOwnership(receiverName, fieldName, filePath, ctx);
1645
+ if (!fieldDef?.declaredType)
1646
+ return undefined;
1647
+ // Use stripNullable (not extractReturnTypeName) — field types like List<User>
1648
+ // should be preserved as-is, not unwrapped to User. Only strip nullable wrappers.
1649
+ return {
1650
+ typeName: stripNullable(fieldDef.declaredType),
1651
+ fieldNodeId: fieldDef.nodeId,
1652
+ };
1653
+ };
1654
+ /**
1655
+ * Resolve a field's Property node given a receiver type name and field name.
1656
+ * Does NOT require declaredType — used by write-access tracking where only the
1657
+ * fieldNodeId is needed (no chain continuation).
1658
+ */
1659
+ const resolveFieldOwnership = (receiverName, fieldName, filePath, ctx) => {
1660
+ const typeResolved = ctx.resolve(receiverName, filePath);
1661
+ if (!typeResolved)
1662
+ return undefined;
1663
+ const classDef = typeResolved.candidates.find((d) => CLASS_LIKE_TYPES.has(d.type));
1664
+ if (!classDef)
1665
+ return undefined;
1666
+ return ctx.model.fields.lookupFieldByOwner(classDef.nodeId, fieldName) ?? undefined;
1667
+ };
1668
+ /**
1669
+ * Resolve a method by owner type name using the eagerly-populated methodByOwner index.
1670
+ * Returns `{ def, tier }` when an unambiguous method is found, `undefined` otherwise.
1671
+ *
1672
+ * **Multi-candidate iteration (homonym disambiguation):** when `ctx.resolve(ownerType)`
1673
+ * returns multiple class-like candidates (e.g. two classes named `User` in different
1674
+ * files reachable from the call site), each is probed with `lookupMethodByOwnerWithMRO`.
1675
+ * Results are deduplicated by `nodeId` so that:
1676
+ *
1677
+ * - homonym classes that both walk up to the SAME ancestor's method collapse to 1 hit
1678
+ * - aliased re-exports that produce two candidates pointing at the same def collapse too
1679
+ *
1680
+ * After deduplication:
1681
+ *
1682
+ * - 0 unique matches → `undefined` (owner-scoped path has no answer)
1683
+ * - 1 unique match → return it
1684
+ * - ≥2 unique matches → `undefined` (genuine homonym ambiguity; don't silently pick one)
1685
+ *
1686
+ * The returned `tier` reflects how the owner TYPE was resolved (not the method name).
1687
+ * Threaded out here so callers don't need a second `ctx.resolve(ownerType, ...)` call —
1688
+ * this decouples callers from `ctx.resolve`'s per-file caching contract.
1689
+ */
1690
+ const resolveMethodByOwner = (receiverTypeName, methodName, filePath, ctx, heritageMap, argCount,
1691
+ /**
1692
+ * DAG-sourced ancestry selector. `'singleton'` routes through
1693
+ * `heritageMap.getSingletonAncestry(owner)` for class-method dispatch
1694
+ * (Ruby `Account.log` via `extend LoggerMixin`). Default / undefined
1695
+ * uses the walker's instance-dispatch behavior.
1696
+ */
1697
+ ancestryView) => {
1698
+ const typeResolved = ctx.resolve(receiverTypeName, filePath);
1699
+ if (!typeResolved)
1700
+ return undefined;
1701
+ // MRO walking needs a language hint so we can derive the per-language
1702
+ // strategy; compute it once and reuse for every candidate. Unknown
1703
+ // extension → fall back to plain direct lookup (D1-D4 still runs on miss).
1704
+ const language = heritageMap ? getLanguageFromFilename(filePath) : null;
1705
+ const mroStrategy = language != null ? getProvider(language).mroStrategy : null;
1706
+ const canWalkMRO = heritageMap != null && mroStrategy != null;
1707
+ // Iterate all class-like candidates tracking the first unambiguous hit.
1708
+ // Zero-allocation fast path: the common case is exactly one class candidate,
1709
+ // so we avoid building a Map. A second hit with a different `nodeId` flips
1710
+ // `ambiguous` and short-circuits the loop. Diamond MRO convergence on the
1711
+ // same inherited method collapses to one hit because `nodeId` matches.
1712
+ //
1713
+ // firstDef === undefined → owner-scoped resolution found nothing
1714
+ // firstDef && !ambiguous → unambiguous answer
1715
+ // ambiguous → genuine homonym ambiguity — refuse to pick
1716
+ //
1717
+ // argCount is threaded through so arity-differing overloads
1718
+ // (e.g. C++ `greet()` vs `greet(string)`) are disambiguated inside the
1719
+ // owner-scoped lookup rather than collapsing to an arbitrary first pick.
1720
+ let firstDef;
1721
+ let ambiguous = false;
1722
+ for (const candidate of typeResolved.candidates) {
1723
+ if (!CLASS_LIKE_TYPES.has(candidate.type))
1724
+ continue;
1725
+ // Singleton dispatch: when the DAG decision requested the singleton
1726
+ // ancestry view, pass `heritageMap.getSingletonAncestry` as the walker's
1727
+ // ancestry override. Kind-aware strategies (e.g. MroStrategy 'ruby-mixin')
1728
+ // honor the override by scanning it linearly in place of their default walk.
1729
+ const singletonOverride = ancestryView === 'singleton' && canWalkMRO && heritageMap
1730
+ ? heritageMap.getSingletonAncestry(candidate.nodeId).map((e) => e.parentId)
1731
+ : undefined;
1732
+ const def = canWalkMRO
1733
+ ? lookupMethodByOwnerWithMRO(candidate.nodeId, methodName, heritageMap, ctx.model, mroStrategy, argCount, singletonOverride)
1734
+ : ctx.model.methods.lookupMethodByOwner(candidate.nodeId, methodName, argCount);
1735
+ if (!def)
1736
+ continue;
1737
+ if (!firstDef) {
1738
+ firstDef = def;
1739
+ }
1740
+ else if (def.nodeId !== firstDef.nodeId) {
1741
+ ambiguous = true;
1742
+ break;
1743
+ }
1744
+ }
1745
+ if (!firstDef || ambiguous)
1746
+ return undefined;
1747
+ return { def: firstDef, tier: typeResolved.tier };
1748
+ };
1749
+ // ---------------------------------------------------------------------------
1750
+ // SM-11: Owner-scoped + MRO member-call resolution (no fuzzy lookup)
1751
+ // ---------------------------------------------------------------------------
1752
+ /**
1753
+ * Resolve a member call using owner-scoped + MRO resolution only (no fuzzy lookup).
1754
+ * Used for `obj.method()` calls where the receiver type is known.
1755
+ *
1756
+ * Delegates to {@link resolveMethodByOwner} which performs an O(1) owner-scoped
1757
+ * method lookup and, when a {@link HeritageMap} is provided, walks the MRO chain
1758
+ * via {@link lookupMethodByOwnerWithMRO}.
1759
+ *
1760
+ * {@link resolveCallTarget} delegates here for member calls.
1761
+ *
1762
+ * **SEMANTIC CHANGE (2026-04-09):** The confidence tier reflects how the
1763
+ * owner TYPE was resolved, not how the method NAME was resolved globally.
1764
+ * more accurate for owner-scoped resolution (the discriminant IS the class,
1765
+ * not the method name). Downstream consumers that filter CALLS edges by
1766
+ * confidence threshold may see shifted values on otherwise-unchanged code.
1767
+ * See the "returns result with correct confidence tier" tests below for the
1768
+ * locked-in behavior.
1769
+ *
1770
+ * **Performance:** Callers that only need the return type (e.g. `walkMixedChain`)
1771
+ * should call {@link resolveMethodByOwner} directly and use the `.def.returnType`
1772
+ * field instead, to avoid building a throwaway `ResolveResult`.
1773
+ *
1774
+ * @param ownerType - The receiver's type name (e.g. 'User')
1775
+ * @param methodName - The method being called (e.g. 'save')
1776
+ * @param currentFile - File path of the call site
1777
+ * @param ctx - Resolution context
1778
+ * @param heritageMap - Optional heritage map for MRO-aware ancestor walking
1779
+ */
1780
+ export const resolveMemberCall = (ownerType, methodName, currentFile, ctx, heritageMap, argCount, ancestryView) => {
1781
+ const resolved = resolveMethodByOwner(ownerType, methodName, currentFile, ctx, heritageMap, argCount, ancestryView);
1782
+ if (!resolved)
1783
+ return null;
1784
+ return toResolveResult(resolved.def, resolved.tier);
1785
+ };
1786
+ // ---------------------------------------------------------------------------
1787
+ // SM-13: Free-function call resolution
1788
+ // ---------------------------------------------------------------------------
1789
+ /**
1790
+ * Resolve a free-function call using `lookupExact` (same-file) + import-scoped
1791
+ * resolution via `ctx.resolve()`.
1792
+ *
1793
+ * Used for `foo()`, `doStuff()` — unqualified calls with no receiver.
1794
+ * Also handles Swift/Kotlin implicit constructors (`User()` without `new`)
1795
+ * by delegating to {@link resolveStaticCall} when the tiered pool contains
1796
+ * class-like targets.
1797
+ *
1798
+ * {@link resolveCallTarget} delegates here for `callForm === 'free'`.
1799
+ *
1800
+ * `resolveFreeCall` does not take a `widenCache` parameter. Free calls
1801
+ * have no receiver type and rely exclusively on the tiered pool
1802
+ * from `ctx.resolve()`.
1803
+ *
1804
+ * @param calledName - The called function name (e.g. 'doStuff')
1805
+ * @param filePath - File path of the call site
1806
+ * @param ctx - Resolution context
1807
+ * @param argCount - Optional argument count for arity filtering
1808
+ * @param tieredOverride - Pre-computed tiered candidates from an upstream
1809
+ * `ctx.resolve` call. When provided, skips the redundant
1810
+ * lookup inside this function.
1811
+ * @param overloadHints - Optional AST-based overload disambiguation hints
1812
+ * @param preComputedArgTypes - Optional pre-computed argument types (worker path)
1813
+ */
1814
+ export const resolveFreeCall = (calledName, filePath, ctx, argCount, tieredOverride, overloadHints, preComputedArgTypes) => {
1815
+ const tiered = tieredOverride ?? ctx.resolve(calledName, filePath);
1816
+ if (!tiered)
1817
+ return null;
1818
+ let filteredCandidates = filterCallableCandidates(tiered.candidates, argCount, 'free');
1819
+ // Class-target fast path: Swift/Kotlin `User()` — free-form call targeting a
1820
+ // class. Delegates to resolveStaticCall for O(1) class + constructor lookup.
1821
+ // The `.some()` trigger must stay aligned with `INSTANTIABLE_CLASS_TYPES` —
1822
+ // any type admitted here that is not in that set will cause resolveStaticCall
1823
+ // to return null, wasting two lookup passes per call. `Enum` is deliberately
1824
+ // excluded; `Record` is included so C# records and Kotlin data classes reach
1825
+ // the fast path.
1826
+ // Align with INSTANTIABLE_CLASS_TYPES by reusing the set directly rather
1827
+ // than enumerating literal strings. This converts an invariant that was
1828
+ // previously enforced by a comment ("keep this list aligned with
1829
+ // INSTANTIABLE_CLASS_TYPES") into one enforced structurally — any future
1830
+ // extension of the set (e.g. Kotlin `object`) propagates here automatically.
1831
+ // The `dedupSwiftExtensionCandidates` helper used in the tail of this
1832
+ // function deliberately uses a narrower literal `'Class' | 'Struct'` check
1833
+ // — Swift extensions only produce Class duplicates in practice, so Record
1834
+ // is excluded there by design. Do not collapse that helper into
1835
+ // INSTANTIABLE_CLASS_TYPES.
1836
+ const hasClassTarget = filteredCandidates.length === 0 &&
1837
+ tiered.candidates.some((c) => INSTANTIABLE_CLASS_TYPES.has(c.type));
1838
+ if (hasClassTarget) {
1839
+ const staticResult = resolveStaticCall(calledName, filePath, ctx, argCount, tiered);
1840
+ if (staticResult)
1841
+ return staticResult;
1842
+ // Retry with constructor form: Swift/Kotlin constructor calls look like
1843
+ // free function calls (no `new` keyword). If resolveStaticCall didn't
1844
+ // match, re-filter with constructor form so CONSTRUCTOR_TARGET_TYPES
1845
+ // applies.
1846
+ //
1847
+ // The retry fires for every null return from `resolveStaticCall`, which
1848
+ // can happen for three distinct reasons — all three are handled below:
1849
+ //
1850
+ // (a) No explicit `Constructor` node found and zero instantiable
1851
+ // class candidates (e.g. Interface/Trait/Impl only — the SM-12
1852
+ // null-route contract). `filterCallableCandidates` with
1853
+ // `'constructor'` form will also return nothing → we fall
1854
+ // through to the final null return. Correct.
1855
+ //
1856
+ // (b) Homonym ambiguity — two or more instantiable class candidates
1857
+ // share the name (e.g. `User` in two files, same tier). The
1858
+ // retry repopulates `filteredCandidates` with both Classes and
1859
+ // they flow into `dedupSwiftExtensionCandidates` below, which
1860
+ // either picks the shortest-path primary or null-routes.
1861
+ // Covered by the R7 Swift-extension dedup test.
1862
+ //
1863
+ // (c) `resolveStaticCall` step 4 bailed because the tiered pool
1864
+ // contains ownerless `Constructor` nodes (some extractors emit
1865
+ // constructors without `ownerId`). Those `Constructor` nodes
1866
+ // survive the constructor-form filter below and reach overload
1867
+ // disambiguation, giving the existing filter path a chance to
1868
+ // pick the right one. Correct but currently uncovered by a
1869
+ // dedicated test — the R5 `preComputedArgTypes` path exercises
1870
+ // overload disambiguation for Functions, which is structurally
1871
+ // the same code.
1872
+ filteredCandidates = filterCallableCandidates(tiered.candidates, argCount, 'constructor');
1873
+ }
1874
+ // E. Overload disambiguation
1875
+ if (filteredCandidates.length > 1) {
1876
+ const disambiguated = overloadHints
1877
+ ? tryOverloadDisambiguation(filteredCandidates, overloadHints)
1878
+ : preComputedArgTypes
1879
+ ? matchCandidatesByArgTypes(filteredCandidates, preComputedArgTypes)
1880
+ : null;
1881
+ if (disambiguated)
1882
+ return toResolveResult(disambiguated, tiered.tier);
1883
+ }
1884
+ if (filteredCandidates.length !== 1) {
1885
+ // See `dedupSwiftExtensionCandidates` — shared helper, single source of
1886
+ // truth for the Swift-extension same-name collision heuristic.
1887
+ const deduped = dedupSwiftExtensionCandidates(filteredCandidates, tiered.tier);
1888
+ if (deduped)
1889
+ return deduped;
1890
+ return null;
1891
+ }
1892
+ return toResolveResult(filteredCandidates[0], tiered.tier);
1893
+ };
1894
+ // ---------------------------------------------------------------------------
1895
+ // SM-12: Constructor/static call resolution (no fuzzy lookup)
1896
+ // ---------------------------------------------------------------------------
1897
+ /**
1898
+ * Resolve a constructor or static call using class-scoped lookup (no fuzzy lookup).
1899
+ * Used for `new User()` / `User()` calls where the calledName targets a class.
1900
+ *
1901
+ * Uses {@link TypeRegistry.lookupClassByName} for O(1) class lookup and
1902
+ * {@link MethodRegistry.lookupMethodByOwner} for constructor resolution.
1903
+ * {@link resolveCallTarget} delegates here for constructor and free-form calls
1904
+ * that target a class.
1905
+ *
1906
+ * Resolution strategy:
1907
+ * 1. `lookupClassByName(className)` — O(1) pre-check; bail early if no class exists.
1908
+ * 2. `ctx.resolve(className, currentFile)` — import-scoped tier for confidence.
1909
+ * 3. Filter to class-like candidates via `CLASS_LIKE_TYPES` and walk each
1910
+ * with `lookupMethodByOwner(classNodeId, className, argCount)` — O(1)
1911
+ * constructor lookup. Only accept results with `type === 'Constructor'`.
1912
+ * 4. If step 3 found nothing and the tiered pool contains ownerless
1913
+ * `Constructor` nodes (common in some extractors), bail out so
1914
+ * `filterCallableCandidates` downstream handles Constructor-vs-Class
1915
+ * preference correctly.
1916
+ * 5. Class-node fallback: filter `classCandidates` through
1917
+ * `INSTANTIABLE_CLASS_TYPES` and return the sole survivor when there is
1918
+ * exactly one. Null-route on zero survivors (Interface / Trait / Impl
1919
+ * stripped) or multiple (homonym ambiguity).
1920
+ *
1921
+ * @param className - The class name (e.g. 'User'). Also used as the method
1922
+ * name for the `lookupMethodByOwner` scan, because the
1923
+ * only constructor-shaped call we handle today is
1924
+ * `ClassName(...)` / `new ClassName(...)`. Named
1925
+ * constructors like Dart `User.fromJson()` arrive as
1926
+ * member calls and route through `resolveMemberCall`,
1927
+ * so this function does not yet need a separate
1928
+ * `methodName` parameter. Revisit if a language surfaces
1929
+ * a static-method-shaped call with a distinct member
1930
+ * name.
1931
+ * @param currentFile - File path of the call site
1932
+ * @param ctx - Resolution context
1933
+ * @param argCount - Optional argument count for arity filtering
1934
+ * @param tieredOverride - Pre-computed tiered candidates for `className` from
1935
+ * an upstream `ctx.resolve` call. When provided, skips
1936
+ * the redundant lookup inside this function. Leave
1937
+ * unset for direct callers without a prior resolution.
1938
+ */
1939
+ export const resolveStaticCall = (className, currentFile, ctx, argCount, tieredOverride, overloadHints, preComputedArgTypes) => {
1940
+ // 1. Pre-check: does a class with this name exist at all? (O(1))
1941
+ // This guards against the expensive `ctx.resolve` walk when the name
1942
+ // is clearly not class-like (e.g. plain functions). When `tieredOverride`
1943
+ // is supplied, the caller has already paid for the tiered lookup, so this
1944
+ // pre-check still prevents the class-candidate filter + lookupMethodByOwner
1945
+ // loop from running on obviously non-class targets.
1946
+ const allClasses = ctx.model.types.lookupClassByName(className);
1947
+ if (allClasses.length === 0)
1948
+ return null;
1949
+ // 2. Scope via ctx.resolve for import-tier information. Reuse the caller's
1950
+ // tiered result when provided — it is computed from the same name and
1951
+ // file context, so re-running the walk would be a pure waste.
1952
+ const typeResolved = tieredOverride ?? ctx.resolve(className, currentFile);
1953
+ if (!typeResolved)
1954
+ return null;
1955
+ const classCandidates = typeResolved.candidates.filter((c) => CLASS_LIKE_TYPES.has(c.type));
1956
+ if (classCandidates.length === 0)
1957
+ return null;
1958
+ // 3. Try lookupMethodByOwner for explicit Constructor nodes.
1959
+ // Only accept results with type === 'Constructor' — a Method or Function
1960
+ // that happens to share the class name (e.g. C++ methods named after
1961
+ // their class) is not a constructor for resolution purposes.
1962
+ // Same dedup logic as resolveMethodByOwner: diamond inheritance converging
1963
+ // on the same constructor collapses to one hit.
1964
+ //
1965
+ // Same-name assumption: the lookup key is `${candidate.nodeId}\0${className}`,
1966
+ // so this finds Constructor nodes whose symbol name equals the class name
1967
+ // (`class User` with a `Constructor` named `User`). Constructors indexed
1968
+ // under a different name (e.g. Python `__init__`) will not be found here —
1969
+ // but they also won't appear in the tiered pool for `ctx.resolve(className)`
1970
+ // for the same reason, so step 4's Constructor-presence check will not
1971
+ // see them either. The two miss cases are symmetric. If a future extractor
1972
+ // indexes Constructor nodes under an alternative name while still setting
1973
+ // `ownerId`, this assumption will need revisiting.
1974
+ let firstDef;
1975
+ let ambiguous = false;
1976
+ for (const candidate of classCandidates) {
1977
+ const def = ctx.model.methods.lookupMethodByOwner(candidate.nodeId, className, argCount);
1978
+ if (!def || def.type !== 'Constructor')
1979
+ continue;
1980
+ if (!firstDef) {
1981
+ firstDef = def;
1982
+ }
1983
+ else if (def.nodeId !== firstDef.nodeId) {
1984
+ ambiguous = true;
1985
+ break;
1986
+ }
1987
+ }
1988
+ if (firstDef && !ambiguous) {
1989
+ return toResolveResult(firstDef, typeResolved.tier);
1990
+ }
1991
+ // 4. lookupMethodByOwner found nothing — check whether the tiered pool
1992
+ // contains Constructor nodes that lack ownerId (common in some extractors).
1993
+ // If so, bail out so the existing filterCallableCandidates path handles
1994
+ // Constructor-vs-Class preference correctly.
1995
+ //
1996
+ // This branch also catches the step-3 ambiguous case (`ambiguous = true`
1997
+ // with two distinct Constructor nodes across multiple class candidates):
1998
+ // the same Constructor nodes are indexed under the class name in the
1999
+ // tiered pool, so `.some(Constructor)` is true here and we defer to
2000
+ // step 4.5 (overload/arg-type disambiguation) or the caller's fallback.
2001
+ // Do not remove this check without also handling the ambiguous step-3
2002
+ // path explicitly.
2003
+ if (typeResolved.candidates.some((c) => c.type === 'Constructor')) {
2004
+ // 4.5. Overload / arg-type disambiguation for ambiguous or ownerless
2005
+ // Constructor pools. When the caller supplied a narrowing signal
2006
+ // (AST-based overload hints from the sequential path, or pre-
2007
+ // computed arg types from the worker path), give disambiguation a
2008
+ // chance before null-routing. Symmetric with resolveMemberCallByFile's
2009
+ // disambiguation pass — both resolvers now share the same signal
2010
+ // precedence via disambiguateByOverloadOrArgTypes. Only fires when
2011
+ // at least one narrowing signal is present; preserves SM-10 R3 for
2012
+ // genuinely ambiguous cases with no disambiguating input.
2013
+ if (overloadHints || preComputedArgTypes) {
2014
+ const ctorPool = filterCallableCandidates(typeResolved.candidates, argCount, 'constructor');
2015
+ if (ctorPool.length > 1) {
2016
+ const disambiguated = disambiguateByOverloadOrArgTypes(ctorPool, overloadHints, preComputedArgTypes);
2017
+ if (disambiguated)
2018
+ return toResolveResult(disambiguated, typeResolved.tier);
2019
+ }
2020
+ }
2021
+ return null;
2022
+ }
2023
+ // 5. No constructor nodes at all — fall back to the class node itself, but
2024
+ // ONLY when it is actually instantiable. Interface / Trait / Impl / Enum
2025
+ // are deliberately excluded via `INSTANTIABLE_CLASS_TYPES` to prevent
2026
+ // false `CALLS` edges from constructor-shaped calls to non-instantiable
2027
+ // nodes. This also disambiguates the Rust same-file shadowing case
2028
+ // (`struct User` + `impl User` both present at same-file tier): the
2029
+ // Impl is stripped, leaving the Struct as the sole instantiable target.
2030
+ // Addresses Codex review finding on PR #754.
2031
+ const instantiableCandidates = classCandidates.filter((c) => INSTANTIABLE_CLASS_TYPES.has(c.type));
2032
+ // Three outcomes below, in order of likelihood after the fix:
2033
+ // length === 0 → all candidates were stripped as non-instantiable (e.g.
2034
+ // Interface / Trait / Impl). Null-route via the fall-through `return
2035
+ // null` — this is the dominant Codex-fix case.
2036
+ // length === 1 → a single instantiable candidate remains, return it.
2037
+ // length > 1 → two or more instantiable classes share the name (e.g.
2038
+ // homonym classes across files with no import narrowing). Fall through
2039
+ // to `return null` so the caller null-routes rather than guess.
2040
+ if (instantiableCandidates.length === 1) {
2041
+ return toResolveResult(instantiableCandidates[0], typeResolved.tier);
2042
+ }
2043
+ return null;
2044
+ };
2045
+ /**
2046
+ * Create a deduplicated ACCESSES edge emitter for a single source node.
2047
+ * Each (sourceId, fieldNodeId) pair is emitted at most once per source.
2048
+ */
2049
+ const makeAccessEmitter = (graph, sourceId) => {
2050
+ const emitted = new Set();
2051
+ return (fieldNodeId) => {
2052
+ const key = `${sourceId}\0${fieldNodeId}`;
2053
+ if (emitted.has(key))
2054
+ return;
2055
+ emitted.add(key);
2056
+ graph.addRelationship({
2057
+ id: generateId('ACCESSES', `${sourceId}:${fieldNodeId}:read`),
2058
+ sourceId,
2059
+ targetId: fieldNodeId,
2060
+ type: 'ACCESSES',
2061
+ confidence: 1.0,
2062
+ reason: 'read',
2063
+ });
2064
+ };
2065
+ };
2066
+ const walkMixedChain = (chain, startType, filePath, ctx, onFieldResolved, heritageMap) => {
2067
+ let currentType = startType;
2068
+ for (const step of chain) {
2069
+ if (!currentType)
2070
+ break;
2071
+ if (step.kind === 'field') {
2072
+ const resolved = resolveFieldAccessType(currentType, step.name, filePath, ctx);
2073
+ if (!resolved) {
2074
+ currentType = undefined;
2075
+ break;
2076
+ }
2077
+ onFieldResolved?.(resolved.fieldNodeId);
2078
+ currentType = resolved.typeName;
2079
+ }
2080
+ else {
2081
+ // Ruby/Python: property access is syntactically identical to method calls.
2082
+ // Try field resolution first — if the name is a known property with declaredType,
2083
+ // use that type directly. Otherwise fall back to method call resolution.
2084
+ const fieldResolved = resolveFieldAccessType(currentType, step.name, filePath, ctx);
2085
+ if (fieldResolved) {
2086
+ onFieldResolved?.(fieldResolved.fieldNodeId);
2087
+ currentType = fieldResolved.typeName;
2088
+ continue;
2089
+ }
2090
+ // Fast path: O(1) owner-scoped method lookup via methodByOwner index.
2091
+ // Note: CALLS edges for intermediate chain steps are NOT emitted here — walkMixedChain
2092
+ // only threads types. CALLS edges come from the outer per-call-expression loop in processCalls.
2093
+ //
2094
+ // We call `resolveMethodByOwner` directly (NOT `resolveMemberCall`) because this is
2095
+ // a hot path — called per chain step per call expression — and we only need the
2096
+ // return type string. Going through `resolveMemberCall` would allocate a throwaway
2097
+ // `ResolveResult` with confidence/reason that we immediately discard.
2098
+ const owned = resolveMethodByOwner(currentType, step.name, filePath, ctx, heritageMap);
2099
+ if (owned?.def.returnType) {
2100
+ const fastRetType = extractReturnTypeName(owned.def.returnType);
2101
+ if (fastRetType) {
2102
+ currentType = fastRetType;
2103
+ continue;
2104
+ }
2105
+ }
2106
+ // Fallback: resolve via resolveCallTarget dispatcher (delegates to resolveMemberCall)
2107
+ const resolved = resolveCallTarget({ calledName: step.name, callForm: 'member', receiverTypeName: currentType }, filePath, ctx, undefined, undefined, undefined, heritageMap);
2108
+ if (!resolved) {
2109
+ // Stdlib passthrough: unwrap(), clone(), etc. preserve the receiver type
2110
+ if (TYPE_PRESERVING_METHODS.has(step.name))
2111
+ continue;
2112
+ currentType = undefined;
2113
+ break;
2114
+ }
2115
+ if (!resolved.returnType) {
2116
+ currentType = undefined;
2117
+ break;
2118
+ }
2119
+ const retType = extractReturnTypeName(resolved.returnType);
2120
+ if (!retType) {
2121
+ currentType = undefined;
2122
+ break;
2123
+ }
2124
+ currentType = retType;
2125
+ }
2126
+ }
2127
+ return currentType;
2128
+ };
2129
+ /**
2130
+ * Fast path: resolve pre-extracted call sites from workers.
2131
+ * No AST parsing — workers already extracted calledName + sourceId.
2132
+ *
2133
+ * @param bindingAccumulator Phase 9: optional accumulator carrying file-scope
2134
+ * TypeEnv bindings from all worker-processed files. When the SymbolTable has
2135
+ * no return type for a cross-file callee, `verifyConstructorBindings` falls
2136
+ * back to the accumulator via `namedImportMap` to bind the variable to the
2137
+ * callee's resolved type (e.g. `var x = getUser()` → `x: User`).
2138
+ */
2139
+ export const processCallsFromExtracted = async (graph, extractedCalls, ctx, onProgress, constructorBindings, heritageMap, bindingAccumulator) => {
2140
+ // Scope-aware receiver types: keyed by filePath → "funcName\0varName" → typeName.
2141
+ // The scope dimension prevents collisions when two functions in the same file
2142
+ // have same-named locals pointing to different constructor types.
2143
+ const fileReceiverTypes = new Map();
2144
+ if (constructorBindings) {
2145
+ for (const { filePath, bindings } of constructorBindings) {
2146
+ const verified = verifyConstructorBindings(bindings, filePath, ctx, graph, bindingAccumulator);
2147
+ if (verified.size > 0) {
2148
+ fileReceiverTypes.set(filePath, buildReceiverTypeIndex(verified));
2149
+ }
2150
+ }
2151
+ }
2152
+ const byFile = new Map();
2153
+ for (const call of extractedCalls) {
2154
+ let list = byFile.get(call.filePath);
2155
+ if (!list) {
2156
+ list = [];
2157
+ byFile.set(call.filePath, list);
2158
+ }
2159
+ list.push(call);
2160
+ }
2161
+ const totalFiles = byFile.size;
2162
+ let filesProcessed = 0;
2163
+ for (const [filePath, calls] of byFile) {
2164
+ filesProcessed++;
2165
+ if (filesProcessed % 100 === 0) {
2166
+ onProgress?.(filesProcessed, totalFiles);
2167
+ await yieldToEventLoop();
2168
+ }
2169
+ // Registry-primary gate: skip Python (etc.) entirely when the
2170
+ // scope-based phase owns CALLS for this language.
2171
+ const fileLanguage = getLanguageFromFilename(filePath);
2172
+ if (fileLanguage && isRegistryPrimary(fileLanguage))
2173
+ continue;
2174
+ ctx.enableCache(filePath);
2175
+ const widenCache = new Map();
2176
+ const receiverMap = fileReceiverTypes.get(filePath);
2177
+ for (const call of calls) {
2178
+ let effectiveCall = call;
2179
+ // Step 1: resolve receiver type from constructor bindings
2180
+ if (!call.receiverTypeName && call.receiverName && receiverMap) {
2181
+ const callFuncName = extractFuncNameFromSourceId(call.sourceId);
2182
+ const resolvedType = lookupReceiverType(receiverMap, callFuncName, call.receiverName);
2183
+ if (resolvedType) {
2184
+ effectiveCall = { ...call, receiverTypeName: resolvedType };
2185
+ }
2186
+ }
2187
+ // Step 1b: class-as-receiver for static method calls (e.g. UserService.find_user())
2188
+ if (!effectiveCall.receiverTypeName &&
2189
+ effectiveCall.receiverName &&
2190
+ effectiveCall.callForm === 'member') {
2191
+ const typeResolved = ctx.resolve(effectiveCall.receiverName, effectiveCall.filePath);
2192
+ if (typeResolved &&
2193
+ typeResolved.candidates.some((d) => d.type === 'Class' ||
2194
+ d.type === 'Interface' ||
2195
+ d.type === 'Struct' ||
2196
+ d.type === 'Enum')) {
2197
+ effectiveCall = { ...effectiveCall, receiverTypeName: effectiveCall.receiverName };
2198
+ }
2199
+ }
2200
+ // Step 1c: mixed chain resolution (field, call, or interleaved — e.g. svc.getUser().address.save()).
2201
+ // Runs whenever receiverMixedChain is present. Steps 1/1b may have resolved the base receiver
2202
+ // type already; that type is used as the chain's starting point.
2203
+ if (effectiveCall.receiverMixedChain?.length) {
2204
+ // Use the already-resolved base type (from Steps 1/1b) or look it up now.
2205
+ let currentType = effectiveCall.receiverTypeName;
2206
+ if (!currentType && effectiveCall.receiverName && receiverMap) {
2207
+ const callFuncName = extractFuncNameFromSourceId(effectiveCall.sourceId);
2208
+ currentType = lookupReceiverType(receiverMap, callFuncName, effectiveCall.receiverName);
2209
+ }
2210
+ if (!currentType && effectiveCall.receiverName) {
2211
+ const typeResolved = ctx.resolve(effectiveCall.receiverName, effectiveCall.filePath);
2212
+ if (typeResolved?.candidates.some((d) => d.type === 'Class' ||
2213
+ d.type === 'Interface' ||
2214
+ d.type === 'Struct' ||
2215
+ d.type === 'Enum')) {
2216
+ currentType = effectiveCall.receiverName;
2217
+ }
2218
+ }
2219
+ if (currentType) {
2220
+ const walkedType = walkMixedChain(effectiveCall.receiverMixedChain, currentType, effectiveCall.filePath, ctx, makeAccessEmitter(graph, effectiveCall.sourceId), heritageMap);
2221
+ if (walkedType) {
2222
+ effectiveCall = { ...effectiveCall, receiverTypeName: walkedType };
2223
+ }
2224
+ }
2225
+ }
2226
+ const resolved = resolveCallTarget(effectiveCall, effectiveCall.filePath, ctx, undefined, widenCache, effectiveCall.argTypes, heritageMap);
2227
+ if (!resolved) {
2228
+ // Vue template component fallback: match calledName against imported .vue basenames
2229
+ if (effectiveCall.filePath.endsWith('.vue') && effectiveCall.sourceId.startsWith('File:')) {
2230
+ const importedFiles = ctx.importMap.get(effectiveCall.filePath);
2231
+ if (importedFiles) {
2232
+ for (const importedPath of importedFiles) {
2233
+ if (!importedPath.endsWith('.vue'))
2234
+ continue;
2235
+ const basename = importedPath.slice(importedPath.lastIndexOf('/') + 1, importedPath.lastIndexOf('.'));
2236
+ if (basename !== effectiveCall.calledName)
2237
+ continue;
2238
+ const targetFileId = generateId('File', importedPath);
2239
+ if (graph.getNode(targetFileId)) {
2240
+ graph.addRelationship({
2241
+ id: generateId('CALLS', `${effectiveCall.sourceId}:${effectiveCall.calledName}->${targetFileId}`),
2242
+ sourceId: effectiveCall.sourceId,
2243
+ targetId: targetFileId,
2244
+ type: 'CALLS',
2245
+ confidence: 0.9,
2246
+ reason: 'vue-template-component',
2247
+ });
2248
+ }
2249
+ break;
2250
+ }
2251
+ }
2252
+ }
2253
+ continue;
2254
+ }
2255
+ const relId = generateId('CALLS', `${effectiveCall.sourceId}:${effectiveCall.calledName}->${resolved.nodeId}`);
2256
+ graph.addRelationship({
2257
+ id: relId,
2258
+ sourceId: effectiveCall.sourceId,
2259
+ targetId: resolved.nodeId,
2260
+ type: 'CALLS',
2261
+ confidence: resolved.confidence,
2262
+ reason: resolved.reason,
2263
+ });
2264
+ if (heritageMap && effectiveCall.callForm === 'member' && effectiveCall.receiverTypeName) {
2265
+ const implTargets = findInterfaceDispatchTargets(effectiveCall.calledName, effectiveCall.receiverTypeName, effectiveCall.filePath, ctx, heritageMap, resolved.nodeId);
2266
+ for (const impl of implTargets) {
2267
+ graph.addRelationship({
2268
+ id: generateId('CALLS', `${effectiveCall.sourceId}:${effectiveCall.calledName}->${impl.nodeId}`),
2269
+ sourceId: effectiveCall.sourceId,
2270
+ targetId: impl.nodeId,
2271
+ type: 'CALLS',
2272
+ confidence: impl.confidence,
2273
+ reason: impl.reason,
2274
+ });
2275
+ }
2276
+ }
2277
+ }
2278
+ ctx.clearCache();
2279
+ }
2280
+ onProgress?.(totalFiles, totalFiles);
2281
+ };
2282
+ /**
2283
+ * Resolve pre-extracted field write assignments to ACCESSES {reason: 'write'} edges.
2284
+ * Accepts optional constructorBindings for return-type-aware receiver inference,
2285
+ * mirroring processCallsFromExtracted's verified binding lookup.
2286
+ */
2287
+ export const processAssignmentsFromExtracted = (graph, assignments, ctx, constructorBindings, bindingAccumulator) => {
2288
+ // Build per-file receiver type indexes from verified constructor bindings
2289
+ const fileReceiverTypes = new Map();
2290
+ if (constructorBindings) {
2291
+ for (const { filePath, bindings } of constructorBindings) {
2292
+ const verified = verifyConstructorBindings(bindings, filePath, ctx, graph, bindingAccumulator);
2293
+ if (verified.size > 0) {
2294
+ fileReceiverTypes.set(filePath, buildReceiverTypeIndex(verified));
2295
+ }
2296
+ }
2297
+ }
2298
+ for (const asn of assignments) {
2299
+ // Resolve the receiver type
2300
+ let receiverTypeName = asn.receiverTypeName;
2301
+ // Tier 2: verified constructor bindings (return-type inference)
2302
+ if (!receiverTypeName && fileReceiverTypes.size > 0) {
2303
+ const receiverMap = fileReceiverTypes.get(asn.filePath);
2304
+ if (receiverMap) {
2305
+ const funcName = extractFuncNameFromSourceId(asn.sourceId);
2306
+ receiverTypeName = lookupReceiverType(receiverMap, funcName, asn.receiverText);
2307
+ }
2308
+ }
2309
+ // Tier 3: static class-as-receiver fallback
2310
+ if (!receiverTypeName) {
2311
+ const resolved = ctx.resolve(asn.receiverText, asn.filePath);
2312
+ if (resolved?.candidates.some((d) => CLASS_LIKE_TYPES.has(d.type))) {
2313
+ receiverTypeName = asn.receiverText;
2314
+ }
2315
+ }
2316
+ if (!receiverTypeName)
2317
+ continue;
2318
+ const fieldOwner = resolveFieldOwnership(receiverTypeName, asn.propertyName, asn.filePath, ctx);
2319
+ if (!fieldOwner)
2320
+ continue;
2321
+ graph.addRelationship({
2322
+ id: generateId('ACCESSES', `${asn.sourceId}:${fieldOwner.nodeId}:write`),
2323
+ sourceId: asn.sourceId,
2324
+ targetId: fieldOwner.nodeId,
2325
+ type: 'ACCESSES',
2326
+ confidence: 1.0,
2327
+ reason: 'write',
2328
+ });
2329
+ }
2330
+ };
2331
+ /**
2332
+ * Resolve pre-extracted Laravel routes to CALLS edges from route files to controller methods.
2333
+ */
2334
+ export const processRoutesFromExtracted = async (graph, extractedRoutes, ctx, onProgress) => {
2335
+ for (let i = 0; i < extractedRoutes.length; i++) {
2336
+ const route = extractedRoutes[i];
2337
+ if (i % 50 === 0) {
2338
+ onProgress?.(i, extractedRoutes.length);
2339
+ await yieldToEventLoop();
2340
+ }
2341
+ if (!route.controllerName || !route.methodName)
2342
+ continue;
2343
+ const controllerResolved = ctx.resolve(route.controllerName, route.filePath);
2344
+ if (!controllerResolved || controllerResolved.candidates.length === 0)
2345
+ continue;
2346
+ if (controllerResolved.tier === 'global' && controllerResolved.candidates.length > 1)
2347
+ continue;
2348
+ const controllerDef = controllerResolved.candidates[0];
2349
+ const confidence = TIER_CONFIDENCE[controllerResolved.tier];
2350
+ const methodResolved = ctx.resolve(route.methodName, controllerDef.filePath);
2351
+ const methodId = methodResolved?.tier === 'same-file' ? methodResolved.candidates[0]?.nodeId : undefined;
2352
+ const sourceId = generateId('File', route.filePath);
2353
+ if (!methodId) {
2354
+ const guessedId = generateId('Method', `${controllerDef.filePath}:${route.methodName}`);
2355
+ const relId = generateId('CALLS', `${sourceId}:route->${guessedId}`);
2356
+ graph.addRelationship({
2357
+ id: relId,
2358
+ sourceId,
2359
+ targetId: guessedId,
2360
+ type: 'CALLS',
2361
+ confidence: confidence * 0.8,
2362
+ reason: 'laravel-route',
2363
+ });
2364
+ continue;
2365
+ }
2366
+ const relId = generateId('CALLS', `${sourceId}:route->${methodId}`);
2367
+ graph.addRelationship({
2368
+ id: relId,
2369
+ sourceId,
2370
+ targetId: methodId,
2371
+ type: 'CALLS',
2372
+ confidence,
2373
+ reason: 'laravel-route',
2374
+ });
2375
+ }
2376
+ onProgress?.(extractedRoutes.length, extractedRoutes.length);
2377
+ };
2378
+ /**
2379
+ * Extract property access keys from a consumer file's source code near fetch calls.
2380
+ *
2381
+ * Looks for three patterns after a fetch/response variable assignment:
2382
+ * 1. Destructuring: `const { data, pagination } = await res.json()`
2383
+ * 2. Property access: `response.data`, `result.items`
2384
+ * 3. Optional chaining: `data?.key1?.key2`
2385
+ *
2386
+ * Returns deduplicated top-level property names accessed on the response.
2387
+ *
2388
+ * NOTE: This scans the entire file content, not just code near a specific fetch call.
2389
+ * If a file has multiple fetch calls to different routes, all accessed keys are
2390
+ * attributed to each fetch. This is an acceptable tradeoff for regex-based extraction.
2391
+ */
2392
+ /** Common method names on response/data objects that are NOT property accesses */
2393
+ // Properties/methods to ignore when extracting consumer accessed keys from `data.X` patterns.
2394
+ // Avoids false positives from Fetch API, Array, Object, Promise, and DOM access on variables
2395
+ // that happen to share names with response variables (data, result, response, etc.).
2396
+ const RESPONSE_ACCESS_BLOCKLIST = new Set([
2397
+ // Fetch/Response API
2398
+ 'json',
2399
+ 'text',
2400
+ 'blob',
2401
+ 'arrayBuffer',
2402
+ 'formData',
2403
+ 'ok',
2404
+ 'status',
2405
+ 'headers',
2406
+ 'clone',
2407
+ // Promise
2408
+ 'then',
2409
+ 'catch',
2410
+ 'finally',
2411
+ // Array
2412
+ 'map',
2413
+ 'filter',
2414
+ 'forEach',
2415
+ 'reduce',
2416
+ 'find',
2417
+ 'some',
2418
+ 'every',
2419
+ 'push',
2420
+ 'pop',
2421
+ 'shift',
2422
+ 'unshift',
2423
+ 'splice',
2424
+ 'slice',
2425
+ 'concat',
2426
+ 'join',
2427
+ 'sort',
2428
+ 'reverse',
2429
+ 'includes',
2430
+ 'indexOf',
2431
+ // Object
2432
+ 'length',
2433
+ 'toString',
2434
+ 'valueOf',
2435
+ 'keys',
2436
+ 'values',
2437
+ 'entries',
2438
+ // DOM methods — file-download patterns often reuse `data`/`response` variable names
2439
+ 'appendChild',
2440
+ 'removeChild',
2441
+ 'insertBefore',
2442
+ 'replaceChild',
2443
+ 'replaceChildren',
2444
+ 'createElement',
2445
+ 'getElementById',
2446
+ 'querySelector',
2447
+ 'querySelectorAll',
2448
+ 'setAttribute',
2449
+ 'getAttribute',
2450
+ 'removeAttribute',
2451
+ 'hasAttribute',
2452
+ 'addEventListener',
2453
+ 'removeEventListener',
2454
+ 'dispatchEvent',
2455
+ 'classList',
2456
+ 'className',
2457
+ 'parentNode',
2458
+ 'parentElement',
2459
+ 'childNodes',
2460
+ 'children',
2461
+ 'nextSibling',
2462
+ 'previousSibling',
2463
+ 'firstChild',
2464
+ 'lastChild',
2465
+ 'click',
2466
+ 'focus',
2467
+ 'blur',
2468
+ 'submit',
2469
+ 'reset',
2470
+ 'innerHTML',
2471
+ 'outerHTML',
2472
+ 'textContent',
2473
+ 'innerText',
2474
+ ]);
2475
+ export const extractConsumerAccessedKeys = (content) => {
2476
+ const keys = new Set();
2477
+ // Pattern 1: Destructuring from .json() — const { key1, key2 } = await res.json()
2478
+ // Also matches: const { key1, key2 } = await (await fetch(...)).json()
2479
+ const destructurePattern = /(?:const|let|var)\s+\{([^}]+)\}\s*=\s*(?:await\s+)?(?:\w+\.json\s*\(\)|(?:await\s+)?(?:fetch|axios|got)\s*\([^)]*\)(?:\.then\s*\([^)]*\))?(?:\.json\s*\(\))?)/g;
2480
+ let match;
2481
+ while ((match = destructurePattern.exec(content)) !== null) {
2482
+ const destructuredBody = match[1];
2483
+ // Extract identifiers from destructuring, handling renamed bindings (key: alias)
2484
+ const keyPattern = /(\w+)\s*(?::\s*\w+)?/g;
2485
+ let keyMatch;
2486
+ while ((keyMatch = keyPattern.exec(destructuredBody)) !== null) {
2487
+ keys.add(keyMatch[1]);
2488
+ }
2489
+ }
2490
+ // Pattern 2: Destructuring from a data/result/response/json variable
2491
+ // e.g., const { items, total } = data; or const { error } = result;
2492
+ const dataVarDestructure = /(?:const|let|var)\s+\{([^}]+)\}\s*=\s*(?:data|result|response|json|body|res)\b/g;
2493
+ while ((match = dataVarDestructure.exec(content)) !== null) {
2494
+ const destructuredBody = match[1];
2495
+ const keyPattern = /(\w+)\s*(?::\s*\w+)?/g;
2496
+ let keyMatch;
2497
+ while ((keyMatch = keyPattern.exec(destructuredBody)) !== null) {
2498
+ keys.add(keyMatch[1]);
2499
+ }
2500
+ }
2501
+ // Pattern 3: Property access on common response variable names
2502
+ // Matches: data.key, response.key, result.key, json.key, body.key
2503
+ // Also matches optional chaining: data?.key
2504
+ const propAccessPattern = /\b(?:data|response|result|json|body|res)\s*(?:\?\.|\.)(\w+)/g;
2505
+ while ((match = propAccessPattern.exec(content)) !== null) {
2506
+ const key = match[1];
2507
+ // Skip common method calls that aren't property accesses
2508
+ if (!RESPONSE_ACCESS_BLOCKLIST.has(key)) {
2509
+ keys.add(key);
2510
+ }
2511
+ }
2512
+ return [...keys];
2513
+ };
2514
+ /**
2515
+ * Create FETCHES edges from extracted fetch() calls to matching Route nodes.
2516
+ * When consumerContents is provided, extracts property access patterns from
2517
+ * consumer files and encodes them in the edge reason field.
2518
+ */
2519
+ export const processNextjsFetchRoutes = (graph, fetchCalls, routeRegistry, // routeURL → handlerFilePath
2520
+ consumerContents) => {
2521
+ // Pre-count how many routes each consumer file matches (for confidence attribution)
2522
+ const routeCountByFile = new Map();
2523
+ for (const call of fetchCalls) {
2524
+ const normalized = normalizeFetchURL(call.fetchURL);
2525
+ if (!normalized)
2526
+ continue;
2527
+ for (const [routeURL] of routeRegistry) {
2528
+ if (routeMatches(normalized, routeURL)) {
2529
+ routeCountByFile.set(call.filePath, (routeCountByFile.get(call.filePath) ?? 0) + 1);
2530
+ break;
2531
+ }
2532
+ }
2533
+ }
2534
+ for (const call of fetchCalls) {
2535
+ const normalized = normalizeFetchURL(call.fetchURL);
2536
+ if (!normalized)
2537
+ continue;
2538
+ for (const [routeURL] of routeRegistry) {
2539
+ if (routeMatches(normalized, routeURL)) {
2540
+ const sourceId = generateId('File', call.filePath);
2541
+ const routeNodeId = generateId('Route', routeURL);
2542
+ // Extract consumer accessed keys if file content is available
2543
+ let reason = 'fetch-url-match';
2544
+ if (consumerContents) {
2545
+ const content = consumerContents.get(call.filePath);
2546
+ if (content) {
2547
+ const accessedKeys = extractConsumerAccessedKeys(content);
2548
+ if (accessedKeys.length > 0) {
2549
+ reason = `fetch-url-match|keys:${accessedKeys.join(',')}`;
2550
+ }
2551
+ }
2552
+ }
2553
+ // Encode multi-fetch count so downstream can set confidence
2554
+ const fetchCount = routeCountByFile.get(call.filePath) ?? 1;
2555
+ if (fetchCount > 1) {
2556
+ reason = `${reason}|fetches:${fetchCount}`;
2557
+ }
2558
+ graph.addRelationship({
2559
+ id: generateId('FETCHES', `${sourceId}->${routeNodeId}`),
2560
+ sourceId,
2561
+ targetId: routeNodeId,
2562
+ type: 'FETCHES',
2563
+ confidence: 0.9,
2564
+ reason,
2565
+ });
2566
+ break;
2567
+ }
2568
+ }
2569
+ }
2570
+ };
2571
+ /**
2572
+ * Extract fetch() calls from source files (sequential path).
2573
+ * Workers handle this via tree-sitter captures in parse-worker; this function
2574
+ * provides the same extraction for the sequential fallback path.
2575
+ */
2576
+ export const extractFetchCallsFromFiles = async (files, astCache) => {
2577
+ const parser = await loadParser();
2578
+ const result = [];
2579
+ for (const file of files) {
2580
+ const language = getLanguageFromFilename(file.path);
2581
+ if (!language)
2582
+ continue;
2583
+ if (!isLanguageAvailable(language))
2584
+ continue;
2585
+ const provider = getProvider(language);
2586
+ const queryStr = provider.treeSitterQueries;
2587
+ if (!queryStr)
2588
+ continue;
2589
+ await loadLanguage(language, file.path);
2590
+ let tree = astCache.get(file.path);
2591
+ if (!tree) {
2592
+ try {
2593
+ tree = parser.parse(file.content, undefined, {
2594
+ bufferSize: getTreeSitterBufferSize(file.content.length),
2595
+ });
2596
+ }
2597
+ catch {
2598
+ continue;
2599
+ }
2600
+ astCache.set(file.path, tree);
2601
+ }
2602
+ let matches;
2603
+ try {
2604
+ const lang = parser.getLanguage();
2605
+ const query = new Parser.Query(lang, queryStr);
2606
+ matches = query.matches(tree.rootNode);
2607
+ }
2608
+ catch {
2609
+ continue;
2610
+ }
2611
+ for (const match of matches) {
2612
+ const captureMap = {};
2613
+ match.captures.forEach((c) => (captureMap[c.name] = c.node));
2614
+ if (captureMap['route.fetch']) {
2615
+ const urlNode = captureMap['route.url'] ?? captureMap['route.template_url'];
2616
+ if (urlNode) {
2617
+ result.push({
2618
+ filePath: file.path,
2619
+ fetchURL: urlNode.text,
2620
+ lineNumber: captureMap['route.fetch'].startPosition.row,
2621
+ });
2622
+ }
2623
+ }
2624
+ else if (captureMap['http_client'] && captureMap['http_client.url']) {
2625
+ const method = captureMap['http_client.method']?.text;
2626
+ const url = captureMap['http_client.url'].text;
2627
+ const HTTP_CLIENT_ONLY = new Set(['head', 'options', 'request', 'ajax']);
2628
+ if (method && HTTP_CLIENT_ONLY.has(method) && url.startsWith('/')) {
2629
+ result.push({
2630
+ filePath: file.path,
2631
+ fetchURL: url,
2632
+ lineNumber: captureMap['http_client'].startPosition.row,
2633
+ });
2634
+ }
2635
+ }
2636
+ }
2637
+ }
2638
+ return result;
2639
+ };