@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,1128 @@
1
+ import { FUNCTION_NODE_TYPES, CLASS_CONTAINER_TYPES, genericFuncName, } from './utils/ast-helpers.js';
2
+ import { CALL_EXPRESSION_TYPES } from './utils/call-analysis.js';
3
+ import { TYPED_PARAMETER_TYPES } from './type-extractors/shared.js';
4
+ import { getProvider } from './languages/index.js';
5
+ import { extractSimpleTypeName, extractVarName, stripNullable, extractReturnTypeName, } from './type-extractors/shared.js';
6
+ /** File-level scope key */
7
+ const FILE_SCOPE = '';
8
+ /** Shared empty map for files with no file-scope bindings. */
9
+ /**
10
+ * Create a fresh empty Map for the "no file-scope bindings" fallback.
11
+ *
12
+ * **Why not a shared sentinel**: we previously used a module-level
13
+ * `const EMPTY_FILE_SCOPE = new Map()` typed as `ReadonlyMap` and shared
14
+ * across every TypeEnv instance. That was a latent singleton-poisoning
15
+ * footgun: any caller that did `(fileScope() as Map).set(...)` — or any
16
+ * future refactor that widened the return type — would silently corrupt
17
+ * every subsequent "empty" return for the process lifetime. A Proxy
18
+ * wrapper was considered but broke Map's internal-slot methods (`.size`,
19
+ * iteration protocol). Allocating a fresh empty Map per call is a few
20
+ * bytes per file — immediately GC'd, no measurable cost even at 10k files
21
+ * — and eliminates the shared-mutation hazard entirely.
22
+ */
23
+ const emptyFileScope = () => new Map();
24
+ /** Fallback for languages where class names aren't in a 'name' field (e.g. Kotlin uses type_identifier). */
25
+ const findTypeIdentifierChild = (node) => {
26
+ for (let i = 0; i < node.childCount; i++) {
27
+ const child = node.child(i);
28
+ if (child && child.type === 'type_identifier')
29
+ return child;
30
+ }
31
+ return null;
32
+ };
33
+ /** AST node types that represent mutually exclusive branch containers for pattern bindings.
34
+ * Includes both multi-arm pattern-match branches AND if-statement bodies for null-check narrowing. */
35
+ const NARROWING_BRANCH_TYPES = new Set([
36
+ 'when_entry', // Kotlin when
37
+ 'switch_block_label', // Java switch (enhanced)
38
+ 'if_statement', // TS/JS, Java, C/C++
39
+ 'if_expression', // Kotlin (if is an expression)
40
+ 'statement_block', // TS/JS: { ... } body of if
41
+ 'control_structure_body', // Kotlin: body of if
42
+ ]);
43
+ /** Walk up the AST from a pattern node to find the enclosing branch container. */
44
+ const findNarrowingBranchScope = (node) => {
45
+ let current = node.parent;
46
+ while (current) {
47
+ if (NARROWING_BRANCH_TYPES.has(current.type))
48
+ return current;
49
+ if (FUNCTION_NODE_TYPES.has(current.type))
50
+ return undefined;
51
+ current = current.parent;
52
+ }
53
+ return undefined;
54
+ };
55
+ /** Bare nullable keywords that fastStripNullable must reject. */
56
+ const FAST_NULLABLE_KEYWORDS = new Set(['null', 'undefined', 'void', 'None', 'nil']);
57
+ /**
58
+ * Fast-path nullable check: 90%+ of type names are simple identifiers (e.g. "User")
59
+ * that don't need the full stripNullable parse. Only call stripNullable when the
60
+ * string contains nullable markers ('|' for union types, '?' for nullable suffix).
61
+ */
62
+ const fastStripNullable = (typeName) => {
63
+ if (FAST_NULLABLE_KEYWORDS.has(typeName))
64
+ return undefined;
65
+ return typeName.indexOf('|') === -1 && typeName.indexOf('?') === -1
66
+ ? typeName
67
+ : stripNullable(typeName);
68
+ };
69
+ /** Implementation of the lookup logic — shared between TypeEnvironment and the legacy export. */
70
+ const lookupInEnv = (env, varName, callNode, patternOverrides, enclosingFunctionFinder, extractFunctionNameHook) => {
71
+ // Self/this receiver: resolve to enclosing class name via AST walk
72
+ if (varName === 'self' || varName === 'this' || varName === '$this') {
73
+ return findEnclosingClassName(callNode);
74
+ }
75
+ // Super/base/parent receiver: resolve to the parent class name via AST walk.
76
+ // Walks up to the enclosing class, then extracts the superclass from its heritage node.
77
+ if (varName === 'super' || varName === 'base' || varName === 'parent') {
78
+ return findEnclosingParentClassName(callNode);
79
+ }
80
+ // Determine the enclosing function scope for the call
81
+ const scopeKey = findEnclosingScopeKey(callNode, enclosingFunctionFinder, extractFunctionNameHook);
82
+ // Check position-indexed pattern overrides first (e.g., Kotlin when/is smart casts).
83
+ // These take priority over flat scopeEnv because they represent per-branch narrowing.
84
+ if (scopeKey && patternOverrides) {
85
+ const varOverrides = patternOverrides.get(scopeKey)?.get(varName);
86
+ if (varOverrides) {
87
+ const pos = callNode.startIndex;
88
+ for (const override of varOverrides) {
89
+ if (pos >= override.rangeStart && pos <= override.rangeEnd) {
90
+ return fastStripNullable(override.typeName);
91
+ }
92
+ }
93
+ }
94
+ }
95
+ // Try function-local scope first
96
+ if (scopeKey) {
97
+ const scopeEnv = env.get(scopeKey);
98
+ if (scopeEnv) {
99
+ const result = scopeEnv.get(varName);
100
+ if (result)
101
+ return fastStripNullable(result);
102
+ }
103
+ }
104
+ // Fall back to file-level scope
105
+ const fileEnv = env.get(FILE_SCOPE);
106
+ const raw = fileEnv?.get(varName);
107
+ return raw ? fastStripNullable(raw) : undefined;
108
+ };
109
+ /** Per-file memoization caches for expensive parent-walk functions.
110
+ * Cleared at the start of each buildTypeEnv call (one call per file). */
111
+ const enclosingClassNameCache = new Map();
112
+ const enclosingParentClassNameCache = new Map();
113
+ /**
114
+ * Walk up the AST from a node to find the enclosing class/module name.
115
+ * Used to resolve `self`/`this` receivers to their containing type.
116
+ * Memoized per-file: cache is cleared at buildTypeEnv entry.
117
+ */
118
+ const findEnclosingClassName = (node) => {
119
+ if (enclosingClassNameCache.has(node))
120
+ return enclosingClassNameCache.get(node);
121
+ let current = node.parent;
122
+ while (current) {
123
+ if (CLASS_CONTAINER_TYPES.has(current.type)) {
124
+ const nameNode = current.childForFieldName('name') ?? findTypeIdentifierChild(current);
125
+ if (nameNode) {
126
+ enclosingClassNameCache.set(node, nameNode.text);
127
+ return nameNode.text;
128
+ }
129
+ }
130
+ current = current.parent;
131
+ }
132
+ enclosingClassNameCache.set(node, undefined);
133
+ return undefined;
134
+ };
135
+ /** Keywords that refer to the current instance across languages. */
136
+ const THIS_RECEIVERS = new Set(['this', 'self', '$this', 'Me']);
137
+ /**
138
+ * If a pending assignment's receiver is this/self/$this/Me, substitute the
139
+ * enclosing class name. Returns the item unchanged for non-receiver kinds
140
+ * or when the receiver is not a this-keyword. Properties are readonly in the
141
+ * discriminated union, so a new object is returned when substitution occurs.
142
+ */
143
+ const substituteThisReceiver = (item, node) => {
144
+ if (item.kind !== 'fieldAccess' && item.kind !== 'methodCallResult')
145
+ return item;
146
+ if (!THIS_RECEIVERS.has(item.receiver))
147
+ return item;
148
+ const className = findEnclosingClassName(node);
149
+ if (!className)
150
+ return item;
151
+ return { ...item, receiver: className };
152
+ };
153
+ /**
154
+ * Walk up the AST to find the enclosing class, then extract its parent class name
155
+ * from the heritage/superclass AST node. Used to resolve `super`/`base`/`parent`.
156
+ *
157
+ * Supported patterns per tree-sitter grammar:
158
+ * - Java/Ruby: `superclass` field → type_identifier/constant
159
+ * - Python: `superclasses` field → argument_list → first identifier
160
+ * - TypeScript/JS: unnamed `class_heritage` child → `extends_clause` → identifier
161
+ * - C#: unnamed `base_list` child → first identifier
162
+ * - PHP: unnamed `base_clause` child → name
163
+ * - Kotlin: unnamed `delegation_specifier` child → constructor_invocation → user_type → type_identifier
164
+ * - C++: unnamed `base_class_clause` child → type_identifier
165
+ * - Swift: unnamed `inheritance_specifier` child → user_type → type_identifier
166
+ */
167
+ const findEnclosingParentClassName = (node) => {
168
+ if (enclosingParentClassNameCache.has(node))
169
+ return enclosingParentClassNameCache.get(node);
170
+ let current = node.parent;
171
+ while (current) {
172
+ if (CLASS_CONTAINER_TYPES.has(current.type)) {
173
+ const result = extractParentClassFromNode(current);
174
+ enclosingParentClassNameCache.set(node, result);
175
+ return result;
176
+ }
177
+ current = current.parent;
178
+ }
179
+ enclosingParentClassNameCache.set(node, undefined);
180
+ return undefined;
181
+ };
182
+ /** Extract the parent/superclass name from a class declaration AST node. */
183
+ const extractParentClassFromNode = (classNode) => {
184
+ // 1. Named fields: Java (superclass), Ruby (superclass), Python (superclasses)
185
+ const superclassNode = classNode.childForFieldName('superclass');
186
+ if (superclassNode) {
187
+ // Java: superclass > type_identifier or generic_type, Ruby: superclass > constant
188
+ const inner = superclassNode.childForFieldName('type') ?? superclassNode.firstNamedChild ?? superclassNode;
189
+ return extractSimpleTypeName(inner) ?? inner.text;
190
+ }
191
+ const superclassesNode = classNode.childForFieldName('superclasses');
192
+ if (superclassesNode) {
193
+ // Python: argument_list with identifiers or attribute nodes (e.g. models.Model)
194
+ const first = superclassesNode.firstNamedChild;
195
+ if (first)
196
+ return extractSimpleTypeName(first) ?? first.text;
197
+ }
198
+ // 2. Unnamed children: walk class node's children looking for heritage nodes
199
+ for (let i = 0; i < classNode.childCount; i++) {
200
+ const child = classNode.child(i);
201
+ if (!child)
202
+ continue;
203
+ switch (child.type) {
204
+ // TypeScript: class_heritage > extends_clause > type_identifier
205
+ // JavaScript: class_heritage > identifier (no extends_clause wrapper)
206
+ case 'class_heritage': {
207
+ for (let j = 0; j < child.childCount; j++) {
208
+ const clause = child.child(j);
209
+ if (clause?.type === 'extends_clause') {
210
+ const typeNode = clause.firstNamedChild;
211
+ if (typeNode)
212
+ return extractSimpleTypeName(typeNode) ?? typeNode.text;
213
+ }
214
+ // JS: direct identifier child (no extends_clause wrapper)
215
+ if (clause?.type === 'identifier' || clause?.type === 'type_identifier') {
216
+ return clause.text;
217
+ }
218
+ }
219
+ break;
220
+ }
221
+ // C#: base_list > identifier or generic_name > identifier
222
+ case 'base_list': {
223
+ const first = child.firstNamedChild;
224
+ if (first) {
225
+ // generic_name wraps the identifier: BaseClass<T>
226
+ if (first.type === 'generic_name') {
227
+ const inner = first.childForFieldName('name') ?? first.firstNamedChild;
228
+ if (inner)
229
+ return inner.text;
230
+ }
231
+ return first.text;
232
+ }
233
+ break;
234
+ }
235
+ // PHP: base_clause > name
236
+ case 'base_clause': {
237
+ const name = child.firstNamedChild;
238
+ if (name)
239
+ return name.text;
240
+ break;
241
+ }
242
+ // C++: base_class_clause > type_identifier (with optional access_specifier before it)
243
+ case 'base_class_clause': {
244
+ for (let j = 0; j < child.childCount; j++) {
245
+ const inner = child.child(j);
246
+ if (inner?.type === 'type_identifier')
247
+ return inner.text;
248
+ }
249
+ break;
250
+ }
251
+ // Kotlin: delegation_specifier > constructor_invocation > user_type > type_identifier
252
+ case 'delegation_specifier': {
253
+ const delegate = child.firstNamedChild;
254
+ if (delegate?.type === 'constructor_invocation') {
255
+ const userType = delegate.firstNamedChild;
256
+ if (userType?.type === 'user_type') {
257
+ const typeId = userType.firstNamedChild;
258
+ if (typeId)
259
+ return typeId.text;
260
+ }
261
+ }
262
+ // Also handle plain user_type (interface conformance without parentheses)
263
+ if (delegate?.type === 'user_type') {
264
+ const typeId = delegate.firstNamedChild;
265
+ if (typeId)
266
+ return typeId.text;
267
+ }
268
+ break;
269
+ }
270
+ // Swift: inheritance_specifier > user_type > type_identifier
271
+ case 'inheritance_specifier': {
272
+ const userType = child.childForFieldName('inherits_from') ?? child.firstNamedChild;
273
+ if (userType?.type === 'user_type') {
274
+ const typeId = userType.firstNamedChild;
275
+ if (typeId)
276
+ return typeId.text;
277
+ }
278
+ break;
279
+ }
280
+ }
281
+ }
282
+ return undefined;
283
+ };
284
+ /** Find the enclosing function name for scope lookup.
285
+ * When an `enclosingFunctionFinder` hook is provided (from the language provider),
286
+ * it is consulted for each ancestor before the default FUNCTION_NODE_TYPES check.
287
+ * This handles languages like Dart where the function body is a sibling of the
288
+ * signature instead of a child. */
289
+ const findEnclosingScopeKey = (node, enclosingFunctionFinder, extractFunctionNameHook) => {
290
+ let current = node.parent;
291
+ while (current) {
292
+ if (FUNCTION_NODE_TYPES.has(current.type)) {
293
+ const funcName = extractFunctionNameHook?.(current)?.funcName ?? genericFuncName(current);
294
+ if (funcName)
295
+ return `${funcName}@${current.startIndex}`;
296
+ }
297
+ // Language-specific hook (e.g., Dart function_body → sibling function_signature)
298
+ if (enclosingFunctionFinder) {
299
+ const result = enclosingFunctionFinder(current);
300
+ if (result) {
301
+ const sigNode = current.previousSibling;
302
+ const startIdx = sigNode?.startIndex ?? current.startIndex;
303
+ return `${result.funcName}@${startIdx}`;
304
+ }
305
+ }
306
+ current = current.parent;
307
+ }
308
+ return undefined;
309
+ };
310
+ /**
311
+ * Create a lookup that checks both local AST class names AND the SymbolTable's
312
+ * global index. This allows extractInitializer functions to distinguish
313
+ * constructor calls from function calls (e.g. Kotlin `User()` vs `getUser()`)
314
+ * using cross-file type information when available.
315
+ *
316
+ * Only `.has()` is exposed — the SymbolTable doesn't support iteration.
317
+ * Results are memoized to avoid redundant class-index scans across declarations.
318
+ */
319
+ const createClassNameLookup = (localNames, model) => {
320
+ if (!model)
321
+ return localNames;
322
+ const memo = new Map();
323
+ return {
324
+ has(name) {
325
+ if (localNames.has(name))
326
+ return true;
327
+ const cached = memo.get(name);
328
+ if (cached !== undefined)
329
+ return cached;
330
+ const result = model.types
331
+ .lookupClassByName(name)
332
+ .some((def) => def.type === 'Class' || def.type === 'Enum' || def.type === 'Struct');
333
+ memo.set(name, result);
334
+ return result;
335
+ },
336
+ };
337
+ };
338
+ /**
339
+ * Build a TypeEnvironment from a tree-sitter AST for a given language.
340
+ * Single-pass: collects class/struct names, type bindings, AND constructor
341
+ * bindings that couldn't be resolved locally — all in one AST walk.
342
+ *
343
+ * When a symbolTable is provided (call-processor path), class names from across
344
+ * the project are available for constructor inference in languages like Kotlin
345
+ * where constructors are syntactically identical to function calls.
346
+ */
347
+ /**
348
+ * Node types whose subtrees can NEVER contain type-relevant descendants
349
+ * (declarations, parameters, for-loops, class definitions, pattern bindings).
350
+ * Conservative leaf-only set — verified safe across all 12 supported language grammars.
351
+ * IMPORTANT: Do NOT add expression containers (arguments, binary_expression, etc.) —
352
+ * they can contain arrow functions with typed parameters.
353
+ */
354
+ const SKIP_SUBTREE_TYPES = new Set([
355
+ // Plain string literals (NOT template_string — it contains interpolated expressions
356
+ // that can hold arrow functions with typed parameters, e.g. `${(x: T) => x}`)
357
+ 'string',
358
+ 'string_literal',
359
+ 'string_content',
360
+ 'string_fragment',
361
+ 'heredoc_body',
362
+ // Comments
363
+ 'comment',
364
+ 'line_comment',
365
+ 'block_comment',
366
+ // Numeric/boolean/null literals
367
+ 'number',
368
+ 'integer_literal',
369
+ 'float_literal',
370
+ 'true',
371
+ 'false',
372
+ 'null',
373
+ // Regex
374
+ 'regex',
375
+ 'regex_pattern',
376
+ ]);
377
+ const CLASS_LIKE_TYPES = new Set(['Class', 'Struct', 'Interface']);
378
+ const lookupClassDefsByName = (model, name, allowedTypes = CLASS_LIKE_TYPES) => model.types.lookupClassByName(name).filter((d) => allowedTypes.has(d.type));
379
+ /** Memoize class definition lookups during fixpoint iteration.
380
+ * SymbolTable is immutable during type resolution, so results never change.
381
+ * Eliminates redundant array allocations + filter scans across iterations. */
382
+ const createClassDefCache = (model) => {
383
+ const cache = new Map();
384
+ return (typeName) => {
385
+ let result = cache.get(typeName);
386
+ if (result === undefined) {
387
+ result = model ? lookupClassDefsByName(model, typeName) : [];
388
+ cache.set(typeName, result);
389
+ }
390
+ return result;
391
+ };
392
+ };
393
+ /** AST node types representing constructor expressions across languages.
394
+ * Note: C# also has `implicit_object_creation_expression` (`new()` with type
395
+ * inference) which is NOT captured — the type is inferred, not explicit.
396
+ * Kotlin constructors use `call_expression` (no `new` keyword) — not detected. */
397
+ const CONSTRUCTOR_EXPR_TYPES = new Set([
398
+ 'new_expression', // TS/JS/C++: new Dog()
399
+ 'object_creation_expression', // Java/C#: new Dog()
400
+ ]);
401
+ /** Extract the constructor class name from a declaration node's initializer.
402
+ * Searches for new_expression / object_creation_expression in the node's subtree.
403
+ * Returns the class name or undefined if no constructor is found.
404
+ * Depth-limited to 5 to avoid expensive traversals. */
405
+ const extractConstructorTypeName = (node, depth = 0) => {
406
+ if (depth > 5)
407
+ return undefined;
408
+ if (CONSTRUCTOR_EXPR_TYPES.has(node.type)) {
409
+ // Java/C#: object_creation_expression has 'type' field
410
+ const typeField = node.childForFieldName('type');
411
+ if (typeField)
412
+ return extractSimpleTypeName(typeField);
413
+ // TS/JS: new_expression has 'constructor' field (but tree-sitter often just has identifier child)
414
+ const ctorField = node.childForFieldName('constructor');
415
+ if (ctorField)
416
+ return extractSimpleTypeName(ctorField);
417
+ // Fallback: first named child is often the class identifier
418
+ if (node.firstNamedChild)
419
+ return extractSimpleTypeName(node.firstNamedChild);
420
+ }
421
+ for (let i = 0; i < node.namedChildCount; i++) {
422
+ const child = node.namedChild(i);
423
+ if (!child)
424
+ continue;
425
+ // Don't descend into nested functions/classes or call expressions (prevents
426
+ // finding constructor args inside method calls, e.g. processAll(new Dog()))
427
+ if (FUNCTION_NODE_TYPES.has(child.type) ||
428
+ CLASS_CONTAINER_TYPES.has(child.type) ||
429
+ CALL_EXPRESSION_TYPES.has(child.type))
430
+ continue;
431
+ const result = extractConstructorTypeName(child, depth + 1);
432
+ if (result)
433
+ return result;
434
+ }
435
+ return undefined;
436
+ };
437
+ /** Max depth for MRO parent chain walking. Real-world inheritance rarely exceeds 3-4 levels. */
438
+ const MAX_MRO_DEPTH = 5;
439
+ /** Check if `child` is a subclass of `parent` using the parentMap.
440
+ * BFS up from child, depth-limited (5), cycle-safe. */
441
+ export const isSubclassOf = (child, parent, parentMap) => {
442
+ if (!parentMap || child === parent)
443
+ return false;
444
+ const visited = new Set([child]);
445
+ let current = [child];
446
+ for (let depth = 0; depth < MAX_MRO_DEPTH && current.length > 0; depth++) {
447
+ const next = [];
448
+ for (const cls of current) {
449
+ const parents = parentMap.get(cls);
450
+ if (!parents)
451
+ continue;
452
+ for (const p of parents) {
453
+ if (p === parent)
454
+ return true;
455
+ if (!visited.has(p)) {
456
+ visited.add(p);
457
+ next.push(p);
458
+ }
459
+ }
460
+ }
461
+ current = next;
462
+ }
463
+ return false;
464
+ };
465
+ /** Walk up the parent class chain to find a field or method on an ancestor.
466
+ * BFS-like traversal with depth limit and cycle detection. First match wins.
467
+ * Used by resolveFieldType and resolveMethodReturnType when direct lookup fails. */
468
+ const walkParentChain = (typeName, parentMap, getClassDefs, lookupOnClass) => {
469
+ if (!parentMap)
470
+ return undefined;
471
+ const visited = new Set([typeName]);
472
+ let current = [typeName];
473
+ for (let depth = 0; depth < MAX_MRO_DEPTH && current.length > 0; depth++) {
474
+ const next = [];
475
+ for (const cls of current) {
476
+ const parents = parentMap.get(cls);
477
+ if (!parents)
478
+ continue;
479
+ for (const parent of parents) {
480
+ if (visited.has(parent))
481
+ continue;
482
+ visited.add(parent);
483
+ const parentDefs = getClassDefs(parent);
484
+ if (parentDefs.length === 1) {
485
+ const result = lookupOnClass(parentDefs[0].nodeId);
486
+ if (result !== undefined)
487
+ return result;
488
+ }
489
+ next.push(parent);
490
+ }
491
+ }
492
+ current = next;
493
+ }
494
+ return undefined;
495
+ };
496
+ /** Resolve a field's declared type given a receiver variable and field name.
497
+ * Uses SymbolTable to find the class nodeId for the receiver's type, then
498
+ * looks up the field via the eagerly-populated fieldByOwner index.
499
+ * Falls back to MRO parent chain walking if direct lookup fails (Phase 11A). */
500
+ const resolveFieldType = (receiver, field, scopeEnv, model, getClassDefs, parentMap) => {
501
+ if (!model)
502
+ return undefined;
503
+ const receiverType = scopeEnv.get(receiver);
504
+ if (!receiverType)
505
+ return undefined;
506
+ const lookup = getClassDefs ?? ((name) => lookupClassDefsByName(model, name));
507
+ const classDefs = lookup(receiverType);
508
+ if (classDefs.length !== 1)
509
+ return undefined;
510
+ // Direct lookup first
511
+ const fieldDef = model.fields.lookupFieldByOwner(classDefs[0].nodeId, field);
512
+ if (fieldDef?.declaredType)
513
+ return extractReturnTypeName(fieldDef.declaredType);
514
+ // MRO parent chain walking on miss
515
+ const inherited = walkParentChain(receiverType, parentMap, lookup, (nodeId) => {
516
+ const f = model.fields.lookupFieldByOwner(nodeId, field);
517
+ return f?.declaredType ? extractReturnTypeName(f.declaredType) : undefined;
518
+ });
519
+ return inherited;
520
+ };
521
+ /** Resolve a method's return type given a receiver variable and method name.
522
+ * Uses SymbolTable to find class nodeIds for the receiver's type, then
523
+ * looks up the method via owner-scoped lookupMethodByOwner.
524
+ * Falls back to MRO parent chain walking if direct lookup fails (Phase 11A). */
525
+ const resolveMethodReturnType = (receiver, method, scopeEnv, model, getClassDefs, parentMap) => {
526
+ if (!model)
527
+ return undefined;
528
+ let receiverType = scopeEnv.get(receiver);
529
+ // When substituteThisReceiver replaced $this/self with the enclosing class name,
530
+ // the receiver IS the type — look it up directly as a class name.
531
+ if (!receiverType) {
532
+ const lookup = getClassDefs ?? ((name) => lookupClassDefsByName(model, name));
533
+ if (lookup(receiver).length > 0)
534
+ receiverType = receiver;
535
+ }
536
+ if (!receiverType)
537
+ return undefined;
538
+ const lookup = getClassDefs ?? ((name) => lookupClassDefsByName(model, name));
539
+ const classDefs = lookup(receiverType);
540
+ if (classDefs.length === 0)
541
+ return undefined;
542
+ // Direct lookup first
543
+ const directMethodLookups = classDefs.map((d) => ({
544
+ classDef: d,
545
+ methodDef: model.methods.lookupMethodByOwner(d.nodeId, method),
546
+ }));
547
+ const hasAmbiguousDirectLookup = directMethodLookups.some(({ classDef, methodDef }) => {
548
+ if (methodDef)
549
+ return false;
550
+ return model.symbols
551
+ .lookupExactAll(classDef.filePath, method)
552
+ .some((d) => d.ownerId === classDef.nodeId);
553
+ });
554
+ if (hasAmbiguousDirectLookup)
555
+ return undefined;
556
+ const methods = directMethodLookups
557
+ .map(({ methodDef }) => methodDef)
558
+ .filter((d) => d !== undefined);
559
+ if (methods.length === 1 && methods[0].returnType) {
560
+ return extractReturnTypeName(methods[0].returnType);
561
+ }
562
+ // MRO parent chain walking on miss
563
+ if (methods.length === 0) {
564
+ const inherited = walkParentChain(receiverType, parentMap, lookup, (nodeId) => {
565
+ const parentMethod = model.methods.lookupMethodByOwner(nodeId, method);
566
+ if (!parentMethod?.returnType)
567
+ return undefined;
568
+ return extractReturnTypeName(parentMethod.returnType);
569
+ });
570
+ return inherited;
571
+ }
572
+ return undefined;
573
+ };
574
+ /**
575
+ * Unified fixpoint propagation: iterate over ALL pending items (copy, callResult,
576
+ * fieldAccess, methodCallResult) until no new bindings are produced.
577
+ * Handles arbitrary-depth mixed chains:
578
+ * const user = getUser(); // callResult → User
579
+ * const addr = user.address; // fieldAccess → Address (depends on user)
580
+ * const city = addr.getCity(); // methodCallResult → City (depends on addr)
581
+ * const alias = city; // copy → City (depends on city)
582
+ * Data flow: SymbolTable (immutable) + scopeEnv → resolve → scopeEnv.
583
+ * Termination: finite entries, each bound at most once (first-writer-wins), max 10 iterations.
584
+ */
585
+ const MAX_FIXPOINT_ITERATIONS = 10;
586
+ const resolveFixpointBindings = (pendingItems, env, returnTypeLookup, model, parentMap) => {
587
+ if (pendingItems.length === 0)
588
+ return;
589
+ const getClassDefs = createClassDefCache(model);
590
+ const resolved = new Set();
591
+ for (let iter = 0; iter < MAX_FIXPOINT_ITERATIONS; iter++) {
592
+ let changed = false;
593
+ for (let i = 0; i < pendingItems.length; i++) {
594
+ if (resolved.has(i))
595
+ continue;
596
+ const item = pendingItems[i];
597
+ const scopeEnv = env.get(item.scope);
598
+ if (!scopeEnv || scopeEnv.has(item.lhs)) {
599
+ resolved.add(i);
600
+ continue;
601
+ }
602
+ let typeName;
603
+ switch (item.kind) {
604
+ case 'callResult':
605
+ // Phase 9: Prefer FQN lookup when available for higher precision
606
+ typeName = item.calleeFqn
607
+ ? returnTypeLookup.lookupReturnType(item.calleeFqn)
608
+ : returnTypeLookup.lookupReturnType(item.callee);
609
+ break;
610
+ case 'copy':
611
+ typeName = scopeEnv.get(item.rhs) ?? env.get(FILE_SCOPE)?.get(item.rhs);
612
+ break;
613
+ case 'fieldAccess':
614
+ typeName = resolveFieldType(item.receiver, item.field, scopeEnv, model, getClassDefs, parentMap);
615
+ break;
616
+ case 'methodCallResult':
617
+ typeName = resolveMethodReturnType(item.receiver, item.method, scopeEnv, model, getClassDefs, parentMap);
618
+ break;
619
+ default: {
620
+ // Exhaustive check: TypeScript will error here if a new PendingAssignment
621
+ // kind is added without handling it in the switch.
622
+ const _exhaustive = item;
623
+ break;
624
+ }
625
+ }
626
+ if (typeName) {
627
+ scopeEnv.set(item.lhs, typeName);
628
+ resolved.add(i);
629
+ changed = true;
630
+ }
631
+ }
632
+ if (!changed)
633
+ break;
634
+ if (iter === MAX_FIXPOINT_ITERATIONS - 1 && process.env.CODRAGRAPH_DEBUG) {
635
+ const unresolved = pendingItems.length - resolved.size;
636
+ if (unresolved > 0) {
637
+ console.warn(`[type-env] fixpoint hit iteration cap (${MAX_FIXPOINT_ITERATIONS}), ${unresolved} items unresolved`);
638
+ }
639
+ }
640
+ }
641
+ };
642
+ /** Seed cross-file type bindings into the file scope.
643
+ * MUST be called AFTER walk() completes so that local declarations
644
+ * (Tier 0/1) always take precedence over imported bindings (first-writer-wins). */
645
+ function seedImportedBindings(env, importedBindings) {
646
+ let fileEnv = env.get(FILE_SCOPE);
647
+ if (!fileEnv) {
648
+ fileEnv = new Map();
649
+ env.set(FILE_SCOPE, fileEnv);
650
+ }
651
+ for (const [name, type] of importedBindings) {
652
+ if (!fileEnv.has(name)) {
653
+ fileEnv.set(name, type);
654
+ }
655
+ }
656
+ }
657
+ export const buildTypeEnv = (tree, language, options) => {
658
+ // Clear per-file memoization caches from the previous file.
659
+ enclosingClassNameCache.clear();
660
+ enclosingParentClassNameCache.clear();
661
+ const model = options?.model;
662
+ const parentMap = options?.parentMap;
663
+ const extractFuncNameHook = options?.extractFunctionName;
664
+ const env = new Map();
665
+ let flushed = false;
666
+ const patternOverrides = new Map();
667
+ // Phase P: maps `scope\0varName` → constructor type when a declaration has BOTH
668
+ // a base type annotation AND a more specific constructor initializer.
669
+ // e.g., `Animal a = new Dog()` → constructorTypeMap.set('func@42\0a', 'Dog')
670
+ const constructorTypeMap = new Map();
671
+ const localClassNames = new Set();
672
+ const classNames = createClassNameLookup(localClassNames, model);
673
+ const provider = getProvider(language);
674
+ const config = provider.typeConfig;
675
+ const bindings = [];
676
+ // Build ReturnTypeLookup: SymbolTable is authoritative when it has an unambiguous match.
677
+ // Cross-file importedReturnTypes are consulted ONLY when SymbolTable has 0 matches.
678
+ // Ambiguous (2+) → undefined, no cross-file fallback (conservative, local-first principle).
679
+ // Post-A4 Unit 4: callableByName no longer holds Method/Constructor, so
680
+ // for-loop binding inference must also consult methodsByName to find
681
+ // return types on class methods (e.g. `user.getItems()` iteration).
682
+ // Take `model` as an explicit argument so the non-null precondition
683
+ // is visible at the type level. Callers must enter these via an
684
+ // `if (model)` guard on their side and pass the narrowed reference.
685
+ const getCallableUnionCount = (m, callee) => {
686
+ return (m.symbols.lookupCallableByName(callee).length + m.methods.lookupMethodByName(callee).length);
687
+ };
688
+ const getFirstCallable = (m, callee) => {
689
+ const free = m.symbols.lookupCallableByName(callee);
690
+ if (free.length > 0)
691
+ return free[0];
692
+ const methods = m.methods.lookupMethodByName(callee);
693
+ return methods.length > 0 ? methods[0] : undefined;
694
+ };
695
+ const returnTypeLookup = {
696
+ lookupReturnType(callee) {
697
+ // SymbolTable is authoritative when it has an unambiguous match
698
+ if (model) {
699
+ if (provider.isBuiltInName(callee))
700
+ return undefined;
701
+ const count = getCallableUnionCount(model, callee);
702
+ if (count === 1) {
703
+ const rawReturn = getFirstCallable(model, callee)?.returnType;
704
+ if (rawReturn)
705
+ return extractReturnTypeName(rawReturn);
706
+ }
707
+ // Ambiguous (2+) → return undefined (conservative, no cross-file fallback)
708
+ if (count > 1)
709
+ return undefined;
710
+ }
711
+ // No match (0 results or no symbolTable) → fall back to cross-file
712
+ return options?.importedReturnTypes?.get(callee);
713
+ },
714
+ lookupRawReturnType(callee) {
715
+ if (model) {
716
+ if (provider.isBuiltInName(callee))
717
+ return undefined;
718
+ const count = getCallableUnionCount(model, callee);
719
+ if (count === 1)
720
+ return getFirstCallable(model, callee)?.returnType;
721
+ // Ambiguous (2+) → return undefined (conservative, no cross-file fallback)
722
+ if (count > 1)
723
+ return undefined;
724
+ }
725
+ // Cross-file fallback uses importedRawReturnTypes (raw declared types, e.g., 'User[]')
726
+ // NOT importedReturnTypes (which contains processed/simple types via extractReturnTypeName)
727
+ return options?.importedRawReturnTypes?.get(callee);
728
+ },
729
+ };
730
+ // Pre-compute combined set of node types that need extractTypeBinding.
731
+ // Single Set.has() replaces 3 separate checks per node in walk().
732
+ const interestingNodeTypes = new Set();
733
+ TYPED_PARAMETER_TYPES.forEach((t) => interestingNodeTypes.add(t));
734
+ config.declarationNodeTypes.forEach((t) => interestingNodeTypes.add(t));
735
+ config.forLoopNodeTypes?.forEach((t) => interestingNodeTypes.add(t));
736
+ // Tier 2: unified fixpoint propagation — collects copy, callResult, fieldAccess, and
737
+ // methodCallResult items during walk(), then iterates until no new bindings are produced.
738
+ // Handles arbitrary-depth mixed chains: callResult → fieldAccess → methodCallResult → copy.
739
+ const pendingItems = [];
740
+ // For-loop nodes whose iterable was unresolved at walk-time. Replayed after the fixpoint
741
+ // resolves the iterable's type, bridging the walk-time/fixpoint gap (Phase 10 / ex-9B).
742
+ const pendingForLoops = [];
743
+ // Maps `scope\0varName` → the type annotation AST node from the original declaration.
744
+ // Allows pattern extractors to navigate back to the declaration's generic type arguments
745
+ // (e.g., to extract T from Result<T, E> for `if let Ok(x) = res`).
746
+ // NOTE: This is a SUPERSET of scopeEnv — entries exist even when extractSimpleTypeName
747
+ // returns undefined for container types (User[], []User, List[User]). This is intentional:
748
+ // for-loop Strategy 1 needs the raw AST type node for exactly those container types.
749
+ const declarationTypeNodes = new Map();
750
+ /**
751
+ * Try to extract a (variableName → typeName) binding from a single AST node.
752
+ *
753
+ * Resolution tiers (first match wins):
754
+ * - Tier 0: explicit type annotations via extractDeclaration / extractForLoopBinding
755
+ * - Tier 1: constructor-call inference via extractInitializer (fallback)
756
+ *
757
+ * Side effect: populates declarationTypeNodes for variables that have an explicit
758
+ * type annotation field on the declaration node. This allows pattern extractors to
759
+ * retrieve generic type arguments from the original declaration (e.g., extracting T
760
+ * from Result<T, E> for `if let Ok(x) = res`).
761
+ */
762
+ const extractTypeBinding = (node, scopeEnv, scope) => {
763
+ // This guard eliminates 90%+ of calls before any language dispatch.
764
+ if (TYPED_PARAMETER_TYPES.has(node.type)) {
765
+ // Capture the raw type annotation BEFORE extractParameter.
766
+ // Most languages use 'name' field; Rust uses 'pattern'; TS uses 'pattern' for some param types.
767
+ // Kotlin `parameter` nodes use positional children instead of named fields,
768
+ // so we fall back to scanning children by type when childForFieldName returns null.
769
+ const typeNode = node.childForFieldName('type');
770
+ if (typeNode) {
771
+ const nameNode = node.childForFieldName('name') ??
772
+ node.childForFieldName('pattern') ??
773
+ // Python typed_parameter: name is a positional child (identifier), not a named field
774
+ (node.firstNamedChild?.type === 'identifier' ? node.firstNamedChild : null);
775
+ if (nameNode) {
776
+ const varName = extractVarName(nameNode);
777
+ if (varName && !declarationTypeNodes.has(`${scope}\0${varName}`)) {
778
+ declarationTypeNodes.set(`${scope}\0${varName}`, typeNode);
779
+ }
780
+ }
781
+ }
782
+ else {
783
+ // Fallback: positional children (Kotlin `parameter` → simple_identifier + user_type)
784
+ let fallbackName = null;
785
+ let fallbackType = null;
786
+ for (let i = 0; i < node.namedChildCount; i++) {
787
+ const child = node.namedChild(i);
788
+ if (!child)
789
+ continue;
790
+ if (!fallbackName &&
791
+ (child.type === 'simple_identifier' || child.type === 'identifier')) {
792
+ fallbackName = child;
793
+ }
794
+ if (!fallbackType &&
795
+ (child.type === 'user_type' ||
796
+ child.type === 'type_identifier' ||
797
+ child.type === 'generic_type' ||
798
+ child.type === 'parameterized_type' ||
799
+ child.type === 'nullable_type')) {
800
+ fallbackType = child;
801
+ }
802
+ }
803
+ if (fallbackName && fallbackType) {
804
+ const varName = extractVarName(fallbackName);
805
+ if (varName && !declarationTypeNodes.has(`${scope}\0${varName}`)) {
806
+ declarationTypeNodes.set(`${scope}\0${varName}`, fallbackType);
807
+ }
808
+ }
809
+ }
810
+ config.extractParameter(node, scopeEnv);
811
+ return;
812
+ }
813
+ // For-each loop variable bindings (Java/C#/Kotlin): explicit element types in the AST.
814
+ // Checked before declarationNodeTypes — loop variables are not declarations.
815
+ if (config.forLoopNodeTypes?.has(node.type)) {
816
+ if (config.extractForLoopBinding) {
817
+ const sizeBefore = scopeEnv.size;
818
+ const forLoopCtx = {
819
+ scopeEnv,
820
+ declarationTypeNodes,
821
+ scope,
822
+ returnTypeLookup,
823
+ };
824
+ config.extractForLoopBinding(node, forLoopCtx);
825
+ // If no new binding was produced, the iterable's type may not yet be resolved.
826
+ // Store for post-fixpoint replay (Phase 10 / ex-9B loop-fixpoint bridge).
827
+ if (scopeEnv.size === sizeBefore) {
828
+ pendingForLoops.push({ node, scope });
829
+ }
830
+ }
831
+ return;
832
+ }
833
+ if (config.declarationNodeTypes.has(node.type)) {
834
+ // Capture the raw type annotation AST node BEFORE extractDeclaration.
835
+ // This decouples type node capture from scopeEnv success — container types
836
+ // (User[], []User, List[User]) that fail extractSimpleTypeName still get
837
+ // their AST type node recorded for Strategy 1 for-loop resolution.
838
+ //
839
+ // Prefer language-specific locator when provided (keeps buildTypeEnv generic),
840
+ // then fall back to a small set of safe, cross-grammar heuristics.
841
+ let typeNode = config.getDeclarationTypeNode?.(node) ?? node.childForFieldName('type') ?? null;
842
+ // Fallback: some grammars wrap type annotations in a `type_annotation` child
843
+ // instead of exposing a named `type` field on the declaration node.
844
+ if (!typeNode) {
845
+ for (let i = 0; i < node.namedChildCount; i++) {
846
+ const c = node.namedChild(i);
847
+ if (c?.type === 'type_annotation') {
848
+ typeNode = c.firstNamedChild ?? c;
849
+ break;
850
+ }
851
+ }
852
+ }
853
+ if (typeNode) {
854
+ const nameNode = node.childForFieldName('name') ??
855
+ node.childForFieldName('left') ??
856
+ node.childForFieldName('pattern');
857
+ if (nameNode) {
858
+ const varName = extractVarName(nameNode);
859
+ if (varName && !declarationTypeNodes.has(`${scope}\0${varName}`)) {
860
+ declarationTypeNodes.set(`${scope}\0${varName}`, typeNode);
861
+ }
862
+ }
863
+ }
864
+ // Run the language-specific declaration extractor (may or may not add to scopeEnv).
865
+ const sizeBefore = typeNode ? scopeEnv.size : -1;
866
+ config.extractDeclaration(node, scopeEnv);
867
+ // Fallback: for multi-declarator languages (TS, C#, Java) where the type field
868
+ // is on variable_declarator children, capture newly-added keys.
869
+ // Map preserves insertion order, so new keys are always at the end —
870
+ // skip the first sizeBefore entries to find only newly-added variables.
871
+ if (sizeBefore >= 0 && scopeEnv.size > sizeBefore) {
872
+ let skip = sizeBefore;
873
+ for (const varName of scopeEnv.keys()) {
874
+ if (skip > 0) {
875
+ skip--;
876
+ continue;
877
+ }
878
+ if (!declarationTypeNodes.has(`${scope}\0${varName}`)) {
879
+ declarationTypeNodes.set(`${scope}\0${varName}`, typeNode);
880
+ }
881
+ }
882
+ }
883
+ // Tier 1: constructor-call inference as fallback.
884
+ // Always called when available — each language's extractInitializer
885
+ // internally skips declarators that already have explicit annotations,
886
+ // so this handles mixed cases like `const a: A = x, b = new B()`.
887
+ if (config.extractInitializer) {
888
+ config.extractInitializer(node, scopeEnv, classNames);
889
+ }
890
+ // Phase P: detect constructor-visible virtual dispatch.
891
+ // When a declaration has BOTH a type annotation AND a constructor initializer,
892
+ // record the constructor type for receiver override at call resolution time.
893
+ // e.g., `Animal a = new Dog()` → constructorTypeMap.set('scope\0a', 'Dog')
894
+ if (sizeBefore >= 0 && scopeEnv.size > sizeBefore) {
895
+ let ctorSkip = sizeBefore;
896
+ for (const varName of scopeEnv.keys()) {
897
+ if (ctorSkip > 0) {
898
+ ctorSkip--;
899
+ continue;
900
+ }
901
+ const declaredType = scopeEnv.get(varName);
902
+ if (!declaredType)
903
+ continue;
904
+ const ctorType = extractConstructorTypeName(node) ?? config.detectConstructorType?.(node, classNames);
905
+ if (!ctorType || ctorType === declaredType)
906
+ continue;
907
+ // Unwrap wrapper types (e.g., C++ shared_ptr<Animal> → Animal) for an
908
+ // accurate isSubclassOf comparison. Language-specific via config hook.
909
+ const declTypeNode = declarationTypeNodes.get(`${scope}\0${varName}`);
910
+ const effectiveDeclaredType = declTypeNode && config.unwrapDeclaredType
911
+ ? (config.unwrapDeclaredType(declaredType, declTypeNode) ?? declaredType)
912
+ : declaredType;
913
+ if (ctorType !== effectiveDeclaredType) {
914
+ constructorTypeMap.set(`${scope}\0${varName}`, ctorType);
915
+ }
916
+ }
917
+ }
918
+ }
919
+ };
920
+ const stack = [
921
+ { node: tree.rootNode, scope: FILE_SCOPE },
922
+ ];
923
+ const processNode = (node, currentScope) => {
924
+ // Fast skip: subtrees that can never contain type-relevant nodes (leaf-like literals).
925
+ if (SKIP_SUBTREE_TYPES.has(node.type))
926
+ return;
927
+ // Collect class/struct names as we encounter them (used by extractInitializer
928
+ // to distinguish constructor calls from function calls, e.g. C++ `User()` vs `getUser()`)
929
+ // Currently only C++ uses this locally; other languages rely on the SymbolTable path.
930
+ if (CLASS_CONTAINER_TYPES.has(node.type)) {
931
+ // Most languages use 'name' field; Kotlin uses a type_identifier child instead
932
+ const nameNode = node.childForFieldName('name') ?? findTypeIdentifierChild(node);
933
+ if (nameNode)
934
+ localClassNames.add(nameNode.text);
935
+ }
936
+ // Detect scope boundaries (function/method definitions)
937
+ let scope = currentScope;
938
+ if (FUNCTION_NODE_TYPES.has(node.type)) {
939
+ const funcName = extractFuncNameHook?.(node)?.funcName ?? genericFuncName(node);
940
+ if (funcName)
941
+ scope = `${funcName}@${node.startIndex}`;
942
+ }
943
+ // Only create scope map and call extractTypeBinding for interesting node types.
944
+ // Single Set.has() replaces 3 separate checks inside extractTypeBinding.
945
+ if (interestingNodeTypes.has(node.type)) {
946
+ if (!env.has(scope))
947
+ env.set(scope, new Map());
948
+ const scopeEnv = env.get(scope);
949
+ extractTypeBinding(node, scopeEnv, scope);
950
+ }
951
+ // Pattern binding extraction: handles constructs that introduce NEW typed variables
952
+ // via pattern matching (e.g. `if let Some(x) = opt`, `x instanceof T t`)
953
+ // or narrow existing variables within a branch (null-check narrowing).
954
+ // Runs after Tier 0/1 so scopeEnv already contains the source variable's type.
955
+ // Conservative: extractor returns undefined when source type is unknown.
956
+ if (config.extractPatternBinding &&
957
+ (!config.patternBindingNodeTypes || config.patternBindingNodeTypes.has(node.type))) {
958
+ // Ensure scopeEnv exists for pattern binding reads/writes
959
+ if (!env.has(scope))
960
+ env.set(scope, new Map());
961
+ const scopeEnv = env.get(scope);
962
+ const patternBinding = config.extractPatternBinding(node, scopeEnv, declarationTypeNodes, scope);
963
+ if (patternBinding) {
964
+ if (patternBinding.narrowingRange) {
965
+ // Explicit narrowing range (null-check narrowing): always store in patternOverrides
966
+ // using the extractor-provided range (typically the if-body block).
967
+ if (!patternOverrides.has(scope))
968
+ patternOverrides.set(scope, new Map());
969
+ const varMap = patternOverrides.get(scope);
970
+ if (!varMap.has(patternBinding.varName))
971
+ varMap.set(patternBinding.varName, []);
972
+ varMap.get(patternBinding.varName).push({
973
+ rangeStart: patternBinding.narrowingRange.startIndex,
974
+ rangeEnd: patternBinding.narrowingRange.endIndex,
975
+ typeName: patternBinding.typeName,
976
+ });
977
+ }
978
+ else if (config.allowPatternBindingOverwrite) {
979
+ // Position-indexed: store per-branch binding for smart-cast narrowing.
980
+ // Each when arm / switch case gets its own type for the variable,
981
+ // preventing cross-arm contamination (e.g., Kotlin when/is).
982
+ const branchNode = findNarrowingBranchScope(node);
983
+ if (branchNode) {
984
+ if (!patternOverrides.has(scope))
985
+ patternOverrides.set(scope, new Map());
986
+ const varMap = patternOverrides.get(scope);
987
+ if (!varMap.has(patternBinding.varName))
988
+ varMap.set(patternBinding.varName, []);
989
+ varMap.get(patternBinding.varName).push({
990
+ rangeStart: branchNode.startIndex,
991
+ rangeEnd: branchNode.endIndex,
992
+ typeName: patternBinding.typeName,
993
+ });
994
+ }
995
+ // Also store in flat scopeEnv as fallback (last arm wins — same as before
996
+ // for code that doesn't use position-indexed lookup).
997
+ scopeEnv.set(patternBinding.varName, patternBinding.typeName);
998
+ }
999
+ else if (!scopeEnv.has(patternBinding.varName)) {
1000
+ // First-writer-wins for languages without smart-cast overwrite (Java instanceof, etc.)
1001
+ scopeEnv.set(patternBinding.varName, patternBinding.typeName);
1002
+ }
1003
+ }
1004
+ }
1005
+ // Tier 2: collect plain-identifier RHS assignments for post-walk propagation.
1006
+ // Delegates to per-language extractPendingAssignment — AST shapes differ widely
1007
+ // (JS uses variable_declarator/name/value, Rust uses let_declaration/pattern/value,
1008
+ // Python uses assignment/left/right, Go uses short_var_declaration/expression_list).
1009
+ // May return a single item or an array (for destructuring: N fieldAccess items).
1010
+ if (config.extractPendingAssignment && config.declarationNodeTypes.has(node.type)) {
1011
+ // scopeEnv is guaranteed to exist here because declarationNodeTypes is a subset
1012
+ // of interestingNodeTypes, so extractTypeBinding already created the scope map above.
1013
+ const scopeEnv = env.get(scope);
1014
+ if (scopeEnv) {
1015
+ const pending = config.extractPendingAssignment(node, scopeEnv);
1016
+ if (pending) {
1017
+ const items = Array.isArray(pending) ? pending : [pending];
1018
+ for (const item of items) {
1019
+ // Substitute this/self/$this/Me receivers with enclosing class name
1020
+ const resolved = substituteThisReceiver(item, node);
1021
+ pendingItems.push({ scope, ...resolved });
1022
+ }
1023
+ }
1024
+ }
1025
+ }
1026
+ // Scan for constructor bindings that couldn't be resolved locally.
1027
+ // Only collect if TypeEnv didn't already resolve this binding.
1028
+ if (config.scanConstructorBinding) {
1029
+ const result = config.scanConstructorBinding(node);
1030
+ if (result) {
1031
+ const scopeEnv = env.get(scope);
1032
+ if (!scopeEnv?.has(result.varName)) {
1033
+ bindings.push({ scope, ...result });
1034
+ }
1035
+ }
1036
+ }
1037
+ // Push children onto stack (reverse order so first child is processed first)
1038
+ for (let i = node.childCount - 1; i >= 0; i--) {
1039
+ const child = node.child(i);
1040
+ if (child)
1041
+ stack.push({ node: child, scope });
1042
+ }
1043
+ };
1044
+ // Iterative traversal using explicit stack instead of recursion
1045
+ // to avoid "Maximum call stack size exceeded" on large files (2000+ lines)
1046
+ while (stack.length > 0) {
1047
+ const { node, scope } = stack.pop();
1048
+ processNode(node, scope);
1049
+ }
1050
+ // Phase 14: Seed cross-file bindings from upstream files AFTER walk
1051
+ // (local declarations from walk() take precedence — first-writer-wins)
1052
+ if (options?.importedBindings && options.importedBindings.size > 0) {
1053
+ seedImportedBindings(env, options.importedBindings);
1054
+ }
1055
+ resolveFixpointBindings(pendingItems, env, returnTypeLookup, model, parentMap);
1056
+ // Post-fixpoint for-loop replay (Phase 10 / ex-9B loop-fixpoint bridge):
1057
+ // For-loop nodes whose iterables were unresolved at walk-time may now be
1058
+ // resolvable because the fixpoint bound the iterable's type.
1059
+ // Example: `const users = getUsers(); for (const u of users) { u.save(); }`
1060
+ // - walk-time: users untyped → u unresolved
1061
+ // - fixpoint: users → User[]
1062
+ // - replay: users now typed → u → User
1063
+ if (pendingForLoops.length > 0 && config.extractForLoopBinding) {
1064
+ for (const { node, scope } of pendingForLoops) {
1065
+ if (!env.has(scope))
1066
+ env.set(scope, new Map());
1067
+ const scopeEnv = env.get(scope);
1068
+ config.extractForLoopBinding(node, {
1069
+ scopeEnv,
1070
+ declarationTypeNodes,
1071
+ scope,
1072
+ returnTypeLookup,
1073
+ });
1074
+ }
1075
+ // Re-run the main fixpoint to resolve items that depended on loop variables.
1076
+ // Only needed if replay actually produced new bindings.
1077
+ const unresolvedBefore = pendingItems.filter((item) => {
1078
+ const scopeEnv = env.get(item.scope);
1079
+ return scopeEnv && !scopeEnv.has(item.lhs);
1080
+ });
1081
+ if (unresolvedBefore.length > 0) {
1082
+ resolveFixpointBindings(unresolvedBefore, env, returnTypeLookup, model);
1083
+ }
1084
+ }
1085
+ return {
1086
+ lookup: (varName, callNode) => lookupInEnv(env, varName, callNode, patternOverrides, options?.enclosingFunctionFinder, extractFuncNameHook),
1087
+ constructorBindings: bindings,
1088
+ fileScope: () => env.get(FILE_SCOPE) ?? emptyFileScope(),
1089
+ allScopes: () => env,
1090
+ constructorTypeMap,
1091
+ flush(filePath, accumulator) {
1092
+ if (flushed) {
1093
+ throw new Error(`[TypeEnvironment] flush called twice for ${filePath} — flush is single-use`);
1094
+ }
1095
+ // Narrow flush() to iterate only the FILE_SCOPE entry, mirroring the
1096
+ // worker-path narrowing in parse-worker.ts (commit 803631fe). Before
1097
+ // this change, both execution paths had the same asymmetry bug: the
1098
+ // worker path was fixed but the sequential path (this code) still
1099
+ // wrote function-scope entries into long-lived accumulator storage
1100
+ // that no consumer reads until Phase 9 lands.
1101
+ //
1102
+ // Phase 9 reversion: when a downstream consumer of function-scope
1103
+ // bindings exists, restore the nested iteration:
1104
+ //
1105
+ // for (const [scope, scopeMap] of env) {
1106
+ // for (const [varName, typeName] of scopeMap) {
1107
+ // entries.push({ scope, varName, typeName });
1108
+ // }
1109
+ // }
1110
+ //
1111
+ // See BindingAccumulator class JSDoc and FileScopeBindings JSDoc in
1112
+ // parse-worker.ts for the full reversion checklist.
1113
+ const fileScope = env.get(FILE_SCOPE) ?? emptyFileScope();
1114
+ const entries = [];
1115
+ for (const [varName, typeName] of fileScope) {
1116
+ entries.push({ scope: '', varName, typeName });
1117
+ }
1118
+ if (entries.length > 0) {
1119
+ accumulator.appendFile(filePath, entries);
1120
+ }
1121
+ // Mark the env as flushed AFTER the successful append. If appendFile
1122
+ // throws (e.g., accumulator is already finalized due to a lifecycle
1123
+ // ordering bug), the caller can catch and retry — the single-use
1124
+ // guard now tracks "data was written", not "flush was attempted".
1125
+ flushed = true;
1126
+ },
1127
+ };
1128
+ };