@saluzi/codegraph 0.2.0 → 0.2.1

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 (657) hide show
  1. package/dist/bin/codegraph.d.ts +26 -0
  2. package/dist/bin/codegraph.d.ts.map +1 -0
  3. package/dist/bin/codegraph.js +2248 -0
  4. package/dist/bin/codegraph.js.map +1 -0
  5. package/dist/bin/command-supervision.d.ts +49 -0
  6. package/dist/bin/command-supervision.d.ts.map +1 -0
  7. package/dist/bin/command-supervision.js +95 -0
  8. package/dist/bin/command-supervision.js.map +1 -0
  9. package/dist/bin/fatal-handler.d.ts +20 -0
  10. package/dist/bin/fatal-handler.d.ts.map +1 -0
  11. package/dist/bin/fatal-handler.js +118 -0
  12. package/dist/bin/fatal-handler.js.map +1 -0
  13. package/dist/bin/node-version-check.d.ts +37 -0
  14. package/dist/bin/node-version-check.d.ts.map +1 -0
  15. package/dist/bin/node-version-check.js +79 -0
  16. package/dist/bin/node-version-check.js.map +1 -0
  17. package/dist/bin/uninstall.d.ts +14 -0
  18. package/dist/bin/uninstall.d.ts.map +1 -0
  19. package/dist/bin/uninstall.js +36 -0
  20. package/dist/bin/uninstall.js.map +1 -0
  21. package/dist/context/formatter.d.ts +30 -0
  22. package/dist/context/formatter.d.ts.map +1 -0
  23. package/dist/context/formatter.js +263 -0
  24. package/dist/context/formatter.js.map +1 -0
  25. package/dist/context/index.d.ts +119 -0
  26. package/dist/context/index.d.ts.map +1 -0
  27. package/dist/context/index.js +1296 -0
  28. package/dist/context/index.js.map +1 -0
  29. package/dist/context/markers.d.ts +19 -0
  30. package/dist/context/markers.d.ts.map +1 -0
  31. package/dist/context/markers.js +22 -0
  32. package/dist/context/markers.js.map +1 -0
  33. package/dist/db/index.d.ts +201 -0
  34. package/dist/db/index.d.ts.map +1 -0
  35. package/dist/db/index.js +493 -0
  36. package/dist/db/index.js.map +1 -0
  37. package/dist/db/migrations.d.ts +44 -0
  38. package/dist/db/migrations.d.ts.map +1 -0
  39. package/dist/db/migrations.js +212 -0
  40. package/dist/db/migrations.js.map +1 -0
  41. package/dist/db/queries.d.ts +513 -0
  42. package/dist/db/queries.d.ts.map +1 -0
  43. package/dist/db/queries.js +1886 -0
  44. package/dist/db/queries.js.map +1 -0
  45. package/dist/db/schema.sql +194 -0
  46. package/dist/db/sqlite-adapter.d.ts +53 -0
  47. package/dist/db/sqlite-adapter.d.ts.map +1 -0
  48. package/dist/db/sqlite-adapter.js +117 -0
  49. package/dist/db/sqlite-adapter.js.map +1 -0
  50. package/dist/db/wal-valve.d.ts +106 -0
  51. package/dist/db/wal-valve.d.ts.map +1 -0
  52. package/dist/db/wal-valve.js +208 -0
  53. package/dist/db/wal-valve.js.map +1 -0
  54. package/dist/directory.d.ts +183 -0
  55. package/dist/directory.d.ts.map +1 -0
  56. package/dist/directory.js +797 -0
  57. package/dist/directory.js.map +1 -0
  58. package/dist/errors.d.ts +136 -0
  59. package/dist/errors.d.ts.map +1 -0
  60. package/dist/errors.js +219 -0
  61. package/dist/errors.js.map +1 -0
  62. package/dist/extraction/astro-extractor.d.ts +79 -0
  63. package/dist/extraction/astro-extractor.d.ts.map +1 -0
  64. package/dist/extraction/astro-extractor.js +320 -0
  65. package/dist/extraction/astro-extractor.js.map +1 -0
  66. package/dist/extraction/cfml-extractor.d.ts +107 -0
  67. package/dist/extraction/cfml-extractor.d.ts.map +1 -0
  68. package/dist/extraction/cfml-extractor.js +494 -0
  69. package/dist/extraction/cfml-extractor.js.map +1 -0
  70. package/dist/extraction/dfm-extractor.d.ts +31 -0
  71. package/dist/extraction/dfm-extractor.d.ts.map +1 -0
  72. package/dist/extraction/dfm-extractor.js +151 -0
  73. package/dist/extraction/dfm-extractor.js.map +1 -0
  74. package/dist/extraction/extraction-version.d.ts +25 -0
  75. package/dist/extraction/extraction-version.d.ts.map +1 -0
  76. package/dist/extraction/extraction-version.js +28 -0
  77. package/dist/extraction/extraction-version.js.map +1 -0
  78. package/dist/extraction/function-ref.d.ts +118 -0
  79. package/dist/extraction/function-ref.d.ts.map +1 -0
  80. package/dist/extraction/function-ref.js +727 -0
  81. package/dist/extraction/function-ref.js.map +1 -0
  82. package/dist/extraction/generated-detection.d.ts +30 -0
  83. package/dist/extraction/generated-detection.d.ts.map +1 -0
  84. package/dist/extraction/generated-detection.js +83 -0
  85. package/dist/extraction/generated-detection.js.map +1 -0
  86. package/dist/extraction/grammars.d.ts +138 -0
  87. package/dist/extraction/grammars.d.ts.map +1 -0
  88. package/dist/extraction/grammars.js +631 -0
  89. package/dist/extraction/grammars.js.map +1 -0
  90. package/dist/extraction/index.d.ts +232 -0
  91. package/dist/extraction/index.d.ts.map +1 -0
  92. package/dist/extraction/index.js +2409 -0
  93. package/dist/extraction/index.js.map +1 -0
  94. package/dist/extraction/languages/arkts.d.ts +3 -0
  95. package/dist/extraction/languages/arkts.d.ts.map +1 -0
  96. package/dist/extraction/languages/arkts.js +127 -0
  97. package/dist/extraction/languages/arkts.js.map +1 -0
  98. package/dist/extraction/languages/c-cpp.d.ts +110 -0
  99. package/dist/extraction/languages/c-cpp.d.ts.map +1 -0
  100. package/dist/extraction/languages/c-cpp.js +837 -0
  101. package/dist/extraction/languages/c-cpp.js.map +1 -0
  102. package/dist/extraction/languages/cfquery.d.ts +12 -0
  103. package/dist/extraction/languages/cfquery.d.ts.map +1 -0
  104. package/dist/extraction/languages/cfquery.js +28 -0
  105. package/dist/extraction/languages/cfquery.js.map +1 -0
  106. package/dist/extraction/languages/cfscript.d.ts +3 -0
  107. package/dist/extraction/languages/cfscript.d.ts.map +1 -0
  108. package/dist/extraction/languages/cfscript.js +73 -0
  109. package/dist/extraction/languages/cfscript.js.map +1 -0
  110. package/dist/extraction/languages/cobol.d.ts +33 -0
  111. package/dist/extraction/languages/cobol.d.ts.map +1 -0
  112. package/dist/extraction/languages/cobol.js +499 -0
  113. package/dist/extraction/languages/cobol.js.map +1 -0
  114. package/dist/extraction/languages/csharp.d.ts +25 -0
  115. package/dist/extraction/languages/csharp.d.ts.map +1 -0
  116. package/dist/extraction/languages/csharp.js +175 -0
  117. package/dist/extraction/languages/csharp.js.map +1 -0
  118. package/dist/extraction/languages/dart.d.ts +3 -0
  119. package/dist/extraction/languages/dart.d.ts.map +1 -0
  120. package/dist/extraction/languages/dart.js +374 -0
  121. package/dist/extraction/languages/dart.js.map +1 -0
  122. package/dist/extraction/languages/erlang.d.ts +3 -0
  123. package/dist/extraction/languages/erlang.d.ts.map +1 -0
  124. package/dist/extraction/languages/erlang.js +350 -0
  125. package/dist/extraction/languages/erlang.js.map +1 -0
  126. package/dist/extraction/languages/go.d.ts +3 -0
  127. package/dist/extraction/languages/go.d.ts.map +1 -0
  128. package/dist/extraction/languages/go.js +111 -0
  129. package/dist/extraction/languages/go.js.map +1 -0
  130. package/dist/extraction/languages/index.d.ts +10 -0
  131. package/dist/extraction/languages/index.d.ts.map +1 -0
  132. package/dist/extraction/languages/index.js +71 -0
  133. package/dist/extraction/languages/index.js.map +1 -0
  134. package/dist/extraction/languages/java.d.ts +3 -0
  135. package/dist/extraction/languages/java.d.ts.map +1 -0
  136. package/dist/extraction/languages/java.js +315 -0
  137. package/dist/extraction/languages/java.js.map +1 -0
  138. package/dist/extraction/languages/javascript.d.ts +3 -0
  139. package/dist/extraction/languages/javascript.d.ts.map +1 -0
  140. package/dist/extraction/languages/javascript.js +106 -0
  141. package/dist/extraction/languages/javascript.js.map +1 -0
  142. package/dist/extraction/languages/kotlin.d.ts +3 -0
  143. package/dist/extraction/languages/kotlin.d.ts.map +1 -0
  144. package/dist/extraction/languages/kotlin.js +379 -0
  145. package/dist/extraction/languages/kotlin.js.map +1 -0
  146. package/dist/extraction/languages/lua.d.ts +3 -0
  147. package/dist/extraction/languages/lua.d.ts.map +1 -0
  148. package/dist/extraction/languages/lua.js +150 -0
  149. package/dist/extraction/languages/lua.js.map +1 -0
  150. package/dist/extraction/languages/luau.d.ts +3 -0
  151. package/dist/extraction/languages/luau.d.ts.map +1 -0
  152. package/dist/extraction/languages/luau.js +37 -0
  153. package/dist/extraction/languages/luau.js.map +1 -0
  154. package/dist/extraction/languages/nix.d.ts +3 -0
  155. package/dist/extraction/languages/nix.d.ts.map +1 -0
  156. package/dist/extraction/languages/nix.js +294 -0
  157. package/dist/extraction/languages/nix.js.map +1 -0
  158. package/dist/extraction/languages/objc.d.ts +3 -0
  159. package/dist/extraction/languages/objc.d.ts.map +1 -0
  160. package/dist/extraction/languages/objc.js +175 -0
  161. package/dist/extraction/languages/objc.js.map +1 -0
  162. package/dist/extraction/languages/pascal.d.ts +3 -0
  163. package/dist/extraction/languages/pascal.d.ts.map +1 -0
  164. package/dist/extraction/languages/pascal.js +77 -0
  165. package/dist/extraction/languages/pascal.js.map +1 -0
  166. package/dist/extraction/languages/php.d.ts +3 -0
  167. package/dist/extraction/languages/php.d.ts.map +1 -0
  168. package/dist/extraction/languages/php.js +196 -0
  169. package/dist/extraction/languages/php.js.map +1 -0
  170. package/dist/extraction/languages/python.d.ts +3 -0
  171. package/dist/extraction/languages/python.d.ts.map +1 -0
  172. package/dist/extraction/languages/python.js +56 -0
  173. package/dist/extraction/languages/python.js.map +1 -0
  174. package/dist/extraction/languages/r.d.ts +3 -0
  175. package/dist/extraction/languages/r.d.ts.map +1 -0
  176. package/dist/extraction/languages/r.js +314 -0
  177. package/dist/extraction/languages/r.js.map +1 -0
  178. package/dist/extraction/languages/ruby.d.ts +3 -0
  179. package/dist/extraction/languages/ruby.d.ts.map +1 -0
  180. package/dist/extraction/languages/ruby.js +149 -0
  181. package/dist/extraction/languages/ruby.js.map +1 -0
  182. package/dist/extraction/languages/rust.d.ts +3 -0
  183. package/dist/extraction/languages/rust.d.ts.map +1 -0
  184. package/dist/extraction/languages/rust.js +142 -0
  185. package/dist/extraction/languages/rust.js.map +1 -0
  186. package/dist/extraction/languages/scala.d.ts +3 -0
  187. package/dist/extraction/languages/scala.d.ts.map +1 -0
  188. package/dist/extraction/languages/scala.js +209 -0
  189. package/dist/extraction/languages/scala.js.map +1 -0
  190. package/dist/extraction/languages/solidity.d.ts +3 -0
  191. package/dist/extraction/languages/solidity.d.ts.map +1 -0
  192. package/dist/extraction/languages/solidity.js +293 -0
  193. package/dist/extraction/languages/solidity.js.map +1 -0
  194. package/dist/extraction/languages/swift.d.ts +3 -0
  195. package/dist/extraction/languages/swift.d.ts.map +1 -0
  196. package/dist/extraction/languages/swift.js +152 -0
  197. package/dist/extraction/languages/swift.js.map +1 -0
  198. package/dist/extraction/languages/terraform.d.ts +3 -0
  199. package/dist/extraction/languages/terraform.d.ts.map +1 -0
  200. package/dist/extraction/languages/terraform.js +641 -0
  201. package/dist/extraction/languages/terraform.js.map +1 -0
  202. package/dist/extraction/languages/typescript.d.ts +16 -0
  203. package/dist/extraction/languages/typescript.d.ts.map +1 -0
  204. package/dist/extraction/languages/typescript.js +167 -0
  205. package/dist/extraction/languages/typescript.js.map +1 -0
  206. package/dist/extraction/languages/vbnet.d.ts +11 -0
  207. package/dist/extraction/languages/vbnet.d.ts.map +1 -0
  208. package/dist/extraction/languages/vbnet.js +141 -0
  209. package/dist/extraction/languages/vbnet.js.map +1 -0
  210. package/dist/extraction/liquid-extractor.d.ts +59 -0
  211. package/dist/extraction/liquid-extractor.d.ts.map +1 -0
  212. package/dist/extraction/liquid-extractor.js +357 -0
  213. package/dist/extraction/liquid-extractor.js.map +1 -0
  214. package/dist/extraction/mybatis-extractor.d.ts +68 -0
  215. package/dist/extraction/mybatis-extractor.d.ts.map +1 -0
  216. package/dist/extraction/mybatis-extractor.js +300 -0
  217. package/dist/extraction/mybatis-extractor.js.map +1 -0
  218. package/dist/extraction/parse-pool.d.ts +152 -0
  219. package/dist/extraction/parse-pool.d.ts.map +1 -0
  220. package/dist/extraction/parse-pool.js +387 -0
  221. package/dist/extraction/parse-pool.js.map +1 -0
  222. package/dist/extraction/parse-worker.d.ts +8 -0
  223. package/dist/extraction/parse-worker.d.ts.map +1 -0
  224. package/dist/extraction/parse-worker.js +104 -0
  225. package/dist/extraction/parse-worker.js.map +1 -0
  226. package/dist/extraction/razor-extractor.d.ts +42 -0
  227. package/dist/extraction/razor-extractor.d.ts.map +1 -0
  228. package/dist/extraction/razor-extractor.js +285 -0
  229. package/dist/extraction/razor-extractor.js.map +1 -0
  230. package/dist/extraction/svelte-extractor.d.ts +56 -0
  231. package/dist/extraction/svelte-extractor.d.ts.map +1 -0
  232. package/dist/extraction/svelte-extractor.js +275 -0
  233. package/dist/extraction/svelte-extractor.js.map +1 -0
  234. package/dist/extraction/tree-sitter-helpers.d.ts +28 -0
  235. package/dist/extraction/tree-sitter-helpers.d.ts.map +1 -0
  236. package/dist/extraction/tree-sitter-helpers.js +153 -0
  237. package/dist/extraction/tree-sitter-helpers.js.map +1 -0
  238. package/dist/extraction/tree-sitter-types.d.ts +258 -0
  239. package/dist/extraction/tree-sitter-types.d.ts.map +1 -0
  240. package/dist/extraction/tree-sitter-types.js +10 -0
  241. package/dist/extraction/tree-sitter-types.js.map +1 -0
  242. package/dist/extraction/tree-sitter.d.ts +706 -0
  243. package/dist/extraction/tree-sitter.d.ts.map +1 -0
  244. package/dist/extraction/tree-sitter.js +6506 -0
  245. package/dist/extraction/tree-sitter.js.map +1 -0
  246. package/dist/extraction/vue-extractor.d.ts +51 -0
  247. package/dist/extraction/vue-extractor.d.ts.map +1 -0
  248. package/dist/extraction/vue-extractor.js +254 -0
  249. package/dist/extraction/vue-extractor.js.map +1 -0
  250. package/dist/extraction/wasm/tree-sitter-arkts.wasm +0 -0
  251. package/dist/extraction/wasm/tree-sitter-c_sharp.wasm +0 -0
  252. package/dist/extraction/wasm/tree-sitter-cfml.wasm +0 -0
  253. package/dist/extraction/wasm/tree-sitter-cfquery.wasm +0 -0
  254. package/dist/extraction/wasm/tree-sitter-cfscript.wasm +0 -0
  255. package/dist/extraction/wasm/tree-sitter-cobol.wasm +0 -0
  256. package/dist/extraction/wasm/tree-sitter-erlang.wasm +0 -0
  257. package/dist/extraction/wasm/tree-sitter-lua.wasm +0 -0
  258. package/dist/extraction/wasm/tree-sitter-luau.wasm +0 -0
  259. package/dist/extraction/wasm/tree-sitter-nix.wasm +0 -0
  260. package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  261. package/dist/extraction/wasm/tree-sitter-r.wasm +0 -0
  262. package/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
  263. package/dist/extraction/wasm/tree-sitter-terraform.wasm +0 -0
  264. package/dist/extraction/wasm/tree-sitter-vbnet.wasm +0 -0
  265. package/dist/extraction/wasm-runtime-flags.d.ts +38 -0
  266. package/dist/extraction/wasm-runtime-flags.d.ts.map +1 -0
  267. package/dist/extraction/wasm-runtime-flags.js +106 -0
  268. package/dist/extraction/wasm-runtime-flags.js.map +1 -0
  269. package/dist/graph/index.d.ts +8 -0
  270. package/dist/graph/index.d.ts.map +1 -0
  271. package/dist/graph/index.js +13 -0
  272. package/dist/graph/index.js.map +1 -0
  273. package/dist/graph/queries.d.ts +106 -0
  274. package/dist/graph/queries.d.ts.map +1 -0
  275. package/dist/graph/queries.js +339 -0
  276. package/dist/graph/queries.js.map +1 -0
  277. package/dist/graph/traversal.d.ts +127 -0
  278. package/dist/graph/traversal.d.ts.map +1 -0
  279. package/dist/graph/traversal.js +599 -0
  280. package/dist/graph/traversal.js.map +1 -0
  281. package/dist/index.d.ts +643 -0
  282. package/dist/index.d.ts.map +1 -0
  283. package/dist/index.js +1491 -0
  284. package/dist/index.js.map +1 -0
  285. package/dist/installer/config-writer.d.ts +28 -0
  286. package/dist/installer/config-writer.d.ts.map +1 -0
  287. package/dist/installer/config-writer.js +91 -0
  288. package/dist/installer/config-writer.js.map +1 -0
  289. package/dist/installer/index.d.ts +142 -0
  290. package/dist/installer/index.d.ts.map +1 -0
  291. package/dist/installer/index.js +619 -0
  292. package/dist/installer/index.js.map +1 -0
  293. package/dist/installer/instructions-template.d.ts +41 -0
  294. package/dist/installer/instructions-template.d.ts.map +1 -0
  295. package/dist/installer/instructions-template.js +53 -0
  296. package/dist/installer/instructions-template.js.map +1 -0
  297. package/dist/installer/targets/antigravity.d.ts +57 -0
  298. package/dist/installer/targets/antigravity.d.ts.map +1 -0
  299. package/dist/installer/targets/antigravity.js +308 -0
  300. package/dist/installer/targets/antigravity.js.map +1 -0
  301. package/dist/installer/targets/claude.d.ts +62 -0
  302. package/dist/installer/targets/claude.d.ts.map +1 -0
  303. package/dist/installer/targets/claude.js +454 -0
  304. package/dist/installer/targets/claude.js.map +1 -0
  305. package/dist/installer/targets/codex.d.ts +18 -0
  306. package/dist/installer/targets/codex.d.ts.map +1 -0
  307. package/dist/installer/targets/codex.js +185 -0
  308. package/dist/installer/targets/codex.js.map +1 -0
  309. package/dist/installer/targets/cursor.d.ts +35 -0
  310. package/dist/installer/targets/cursor.d.ts.map +1 -0
  311. package/dist/installer/targets/cursor.js +254 -0
  312. package/dist/installer/targets/cursor.js.map +1 -0
  313. package/dist/installer/targets/gemini.d.ts +26 -0
  314. package/dist/installer/targets/gemini.d.ts.map +1 -0
  315. package/dist/installer/targets/gemini.js +165 -0
  316. package/dist/installer/targets/gemini.js.map +1 -0
  317. package/dist/installer/targets/hermes.d.ts +18 -0
  318. package/dist/installer/targets/hermes.d.ts.map +1 -0
  319. package/dist/installer/targets/hermes.js +359 -0
  320. package/dist/installer/targets/hermes.js.map +1 -0
  321. package/dist/installer/targets/kiro.d.ts +27 -0
  322. package/dist/installer/targets/kiro.d.ts.map +1 -0
  323. package/dist/installer/targets/kiro.js +178 -0
  324. package/dist/installer/targets/kiro.js.map +1 -0
  325. package/dist/installer/targets/opencode.d.ts +38 -0
  326. package/dist/installer/targets/opencode.d.ts.map +1 -0
  327. package/dist/installer/targets/opencode.js +288 -0
  328. package/dist/installer/targets/opencode.js.map +1 -0
  329. package/dist/installer/targets/registry.d.ts +35 -0
  330. package/dist/installer/targets/registry.d.ts.map +1 -0
  331. package/dist/installer/targets/registry.js +91 -0
  332. package/dist/installer/targets/registry.js.map +1 -0
  333. package/dist/installer/targets/shared.d.ts +101 -0
  334. package/dist/installer/targets/shared.d.ts.map +1 -0
  335. package/dist/installer/targets/shared.js +264 -0
  336. package/dist/installer/targets/shared.js.map +1 -0
  337. package/dist/installer/targets/toml.d.ts +52 -0
  338. package/dist/installer/targets/toml.d.ts.map +1 -0
  339. package/dist/installer/targets/toml.js +147 -0
  340. package/dist/installer/targets/toml.js.map +1 -0
  341. package/dist/installer/targets/types.d.ts +108 -0
  342. package/dist/installer/targets/types.d.ts.map +1 -0
  343. package/dist/installer/targets/types.js +16 -0
  344. package/dist/installer/targets/types.js.map +1 -0
  345. package/dist/mcp/daemon-manager.d.ts +42 -0
  346. package/dist/mcp/daemon-manager.d.ts.map +1 -0
  347. package/dist/mcp/daemon-manager.js +129 -0
  348. package/dist/mcp/daemon-manager.js.map +1 -0
  349. package/dist/mcp/daemon-paths.d.ts +73 -0
  350. package/dist/mcp/daemon-paths.d.ts.map +1 -0
  351. package/dist/mcp/daemon-paths.js +165 -0
  352. package/dist/mcp/daemon-paths.js.map +1 -0
  353. package/dist/mcp/daemon-registry.d.ts +47 -0
  354. package/dist/mcp/daemon-registry.d.ts.map +1 -0
  355. package/dist/mcp/daemon-registry.js +233 -0
  356. package/dist/mcp/daemon-registry.js.map +1 -0
  357. package/dist/mcp/daemon.d.ts +290 -0
  358. package/dist/mcp/daemon.d.ts.map +1 -0
  359. package/dist/mcp/daemon.js +862 -0
  360. package/dist/mcp/daemon.js.map +1 -0
  361. package/dist/mcp/dynamic-boundaries.d.ts +41 -0
  362. package/dist/mcp/dynamic-boundaries.d.ts.map +1 -0
  363. package/dist/mcp/dynamic-boundaries.js +360 -0
  364. package/dist/mcp/dynamic-boundaries.js.map +1 -0
  365. package/dist/mcp/early-ppid.d.ts +26 -0
  366. package/dist/mcp/early-ppid.d.ts.map +1 -0
  367. package/dist/mcp/early-ppid.js +29 -0
  368. package/dist/mcp/early-ppid.js.map +1 -0
  369. package/dist/mcp/engine.d.ts +122 -0
  370. package/dist/mcp/engine.d.ts.map +1 -0
  371. package/dist/mcp/engine.js +350 -0
  372. package/dist/mcp/engine.js.map +1 -0
  373. package/dist/mcp/index.d.ts +113 -0
  374. package/dist/mcp/index.d.ts.map +1 -0
  375. package/dist/mcp/index.js +506 -0
  376. package/dist/mcp/index.js.map +1 -0
  377. package/dist/mcp/liveness-watchdog.d.ts +35 -0
  378. package/dist/mcp/liveness-watchdog.d.ts.map +1 -0
  379. package/dist/mcp/liveness-watchdog.js +267 -0
  380. package/dist/mcp/liveness-watchdog.js.map +1 -0
  381. package/dist/mcp/ppid-watchdog.d.ts +62 -0
  382. package/dist/mcp/ppid-watchdog.d.ts.map +1 -0
  383. package/dist/mcp/ppid-watchdog.js +64 -0
  384. package/dist/mcp/ppid-watchdog.js.map +1 -0
  385. package/dist/mcp/proxy.d.ts +87 -0
  386. package/dist/mcp/proxy.d.ts.map +1 -0
  387. package/dist/mcp/proxy.js +667 -0
  388. package/dist/mcp/proxy.js.map +1 -0
  389. package/dist/mcp/query-pool.d.ts +108 -0
  390. package/dist/mcp/query-pool.d.ts.map +1 -0
  391. package/dist/mcp/query-pool.js +315 -0
  392. package/dist/mcp/query-pool.js.map +1 -0
  393. package/dist/mcp/query-worker.d.ts +24 -0
  394. package/dist/mcp/query-worker.d.ts.map +1 -0
  395. package/dist/mcp/query-worker.js +87 -0
  396. package/dist/mcp/query-worker.js.map +1 -0
  397. package/dist/mcp/server-instructions.d.ts +34 -0
  398. package/dist/mcp/server-instructions.d.ts.map +1 -0
  399. package/dist/mcp/server-instructions.js +106 -0
  400. package/dist/mcp/server-instructions.js.map +1 -0
  401. package/dist/mcp/session.d.ts +93 -0
  402. package/dist/mcp/session.d.ts.map +1 -0
  403. package/dist/mcp/session.js +357 -0
  404. package/dist/mcp/session.js.map +1 -0
  405. package/dist/mcp/startup-handshake.d.ts +44 -0
  406. package/dist/mcp/startup-handshake.d.ts.map +1 -0
  407. package/dist/mcp/startup-handshake.js +73 -0
  408. package/dist/mcp/startup-handshake.js.map +1 -0
  409. package/dist/mcp/stdin-teardown.d.ts +27 -0
  410. package/dist/mcp/stdin-teardown.d.ts.map +1 -0
  411. package/dist/mcp/stdin-teardown.js +49 -0
  412. package/dist/mcp/stdin-teardown.js.map +1 -0
  413. package/dist/mcp/tools.d.ts +613 -0
  414. package/dist/mcp/tools.d.ts.map +1 -0
  415. package/dist/mcp/tools.js +4477 -0
  416. package/dist/mcp/tools.js.map +1 -0
  417. package/dist/mcp/transport.d.ts +188 -0
  418. package/dist/mcp/transport.d.ts.map +1 -0
  419. package/dist/mcp/transport.js +377 -0
  420. package/dist/mcp/transport.js.map +1 -0
  421. package/dist/mcp/version.d.ts +19 -0
  422. package/dist/mcp/version.d.ts.map +1 -0
  423. package/dist/mcp/version.js +71 -0
  424. package/dist/mcp/version.js.map +1 -0
  425. package/dist/project-config.d.ts +94 -0
  426. package/dist/project-config.d.ts.map +1 -0
  427. package/dist/project-config.js +374 -0
  428. package/dist/project-config.js.map +1 -0
  429. package/dist/resolution/c-fnptr-synthesizer.d.ts +6 -0
  430. package/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -0
  431. package/dist/resolution/c-fnptr-synthesizer.js +1062 -0
  432. package/dist/resolution/c-fnptr-synthesizer.js.map +1 -0
  433. package/dist/resolution/callback-synthesizer.d.ts +15 -0
  434. package/dist/resolution/callback-synthesizer.d.ts.map +1 -0
  435. package/dist/resolution/callback-synthesizer.js +3938 -0
  436. package/dist/resolution/callback-synthesizer.js.map +1 -0
  437. package/dist/resolution/cooperative-yield.d.ts +32 -0
  438. package/dist/resolution/cooperative-yield.d.ts.map +1 -0
  439. package/dist/resolution/cooperative-yield.js +42 -0
  440. package/dist/resolution/cooperative-yield.js.map +1 -0
  441. package/dist/resolution/frameworks/astro.d.ts +9 -0
  442. package/dist/resolution/frameworks/astro.d.ts.map +1 -0
  443. package/dist/resolution/frameworks/astro.js +169 -0
  444. package/dist/resolution/frameworks/astro.js.map +1 -0
  445. package/dist/resolution/frameworks/cargo-workspace.d.ts +18 -0
  446. package/dist/resolution/frameworks/cargo-workspace.d.ts.map +1 -0
  447. package/dist/resolution/frameworks/cargo-workspace.js +225 -0
  448. package/dist/resolution/frameworks/cargo-workspace.js.map +1 -0
  449. package/dist/resolution/frameworks/cics.d.ts +20 -0
  450. package/dist/resolution/frameworks/cics.d.ts.map +1 -0
  451. package/dist/resolution/frameworks/cics.js +90 -0
  452. package/dist/resolution/frameworks/cics.js.map +1 -0
  453. package/dist/resolution/frameworks/csharp.d.ts +8 -0
  454. package/dist/resolution/frameworks/csharp.d.ts.map +1 -0
  455. package/dist/resolution/frameworks/csharp.js +241 -0
  456. package/dist/resolution/frameworks/csharp.js.map +1 -0
  457. package/dist/resolution/frameworks/drupal.d.ts +51 -0
  458. package/dist/resolution/frameworks/drupal.d.ts.map +1 -0
  459. package/dist/resolution/frameworks/drupal.js +367 -0
  460. package/dist/resolution/frameworks/drupal.js.map +1 -0
  461. package/dist/resolution/frameworks/expo-modules.d.ts +3 -0
  462. package/dist/resolution/frameworks/expo-modules.d.ts.map +1 -0
  463. package/dist/resolution/frameworks/expo-modules.js +148 -0
  464. package/dist/resolution/frameworks/expo-modules.js.map +1 -0
  465. package/dist/resolution/frameworks/express.d.ts +8 -0
  466. package/dist/resolution/frameworks/express.d.ts.map +1 -0
  467. package/dist/resolution/frameworks/express.js +308 -0
  468. package/dist/resolution/frameworks/express.js.map +1 -0
  469. package/dist/resolution/frameworks/fabric.d.ts +3 -0
  470. package/dist/resolution/frameworks/fabric.d.ts.map +1 -0
  471. package/dist/resolution/frameworks/fabric.js +354 -0
  472. package/dist/resolution/frameworks/fabric.js.map +1 -0
  473. package/dist/resolution/frameworks/go.d.ts +8 -0
  474. package/dist/resolution/frameworks/go.d.ts.map +1 -0
  475. package/dist/resolution/frameworks/go.js +161 -0
  476. package/dist/resolution/frameworks/go.js.map +1 -0
  477. package/dist/resolution/frameworks/goframe.d.ts +41 -0
  478. package/dist/resolution/frameworks/goframe.d.ts.map +1 -0
  479. package/dist/resolution/frameworks/goframe.js +112 -0
  480. package/dist/resolution/frameworks/goframe.js.map +1 -0
  481. package/dist/resolution/frameworks/index.d.ts +50 -0
  482. package/dist/resolution/frameworks/index.d.ts.map +1 -0
  483. package/dist/resolution/frameworks/index.js +175 -0
  484. package/dist/resolution/frameworks/index.js.map +1 -0
  485. package/dist/resolution/frameworks/java.d.ts +8 -0
  486. package/dist/resolution/frameworks/java.d.ts.map +1 -0
  487. package/dist/resolution/frameworks/java.js +517 -0
  488. package/dist/resolution/frameworks/java.js.map +1 -0
  489. package/dist/resolution/frameworks/laravel.d.ts +13 -0
  490. package/dist/resolution/frameworks/laravel.d.ts.map +1 -0
  491. package/dist/resolution/frameworks/laravel.js +257 -0
  492. package/dist/resolution/frameworks/laravel.js.map +1 -0
  493. package/dist/resolution/frameworks/nestjs.d.ts +26 -0
  494. package/dist/resolution/frameworks/nestjs.d.ts.map +1 -0
  495. package/dist/resolution/frameworks/nestjs.js +698 -0
  496. package/dist/resolution/frameworks/nestjs.js.map +1 -0
  497. package/dist/resolution/frameworks/play.d.ts +19 -0
  498. package/dist/resolution/frameworks/play.d.ts.map +1 -0
  499. package/dist/resolution/frameworks/play.js +111 -0
  500. package/dist/resolution/frameworks/play.js.map +1 -0
  501. package/dist/resolution/frameworks/python.d.ts +10 -0
  502. package/dist/resolution/frameworks/python.d.ts.map +1 -0
  503. package/dist/resolution/frameworks/python.js +400 -0
  504. package/dist/resolution/frameworks/python.js.map +1 -0
  505. package/dist/resolution/frameworks/react-native.d.ts +3 -0
  506. package/dist/resolution/frameworks/react-native.d.ts.map +1 -0
  507. package/dist/resolution/frameworks/react-native.js +410 -0
  508. package/dist/resolution/frameworks/react-native.js.map +1 -0
  509. package/dist/resolution/frameworks/react.d.ts +8 -0
  510. package/dist/resolution/frameworks/react.d.ts.map +1 -0
  511. package/dist/resolution/frameworks/react.js +334 -0
  512. package/dist/resolution/frameworks/react.js.map +1 -0
  513. package/dist/resolution/frameworks/ruby.d.ts +8 -0
  514. package/dist/resolution/frameworks/ruby.d.ts.map +1 -0
  515. package/dist/resolution/frameworks/ruby.js +302 -0
  516. package/dist/resolution/frameworks/ruby.js.map +1 -0
  517. package/dist/resolution/frameworks/rust.d.ts +8 -0
  518. package/dist/resolution/frameworks/rust.d.ts.map +1 -0
  519. package/dist/resolution/frameworks/rust.js +304 -0
  520. package/dist/resolution/frameworks/rust.js.map +1 -0
  521. package/dist/resolution/frameworks/svelte.d.ts +9 -0
  522. package/dist/resolution/frameworks/svelte.d.ts.map +1 -0
  523. package/dist/resolution/frameworks/svelte.js +253 -0
  524. package/dist/resolution/frameworks/svelte.js.map +1 -0
  525. package/dist/resolution/frameworks/swift-objc.d.ts +37 -0
  526. package/dist/resolution/frameworks/swift-objc.d.ts.map +1 -0
  527. package/dist/resolution/frameworks/swift-objc.js +252 -0
  528. package/dist/resolution/frameworks/swift-objc.js.map +1 -0
  529. package/dist/resolution/frameworks/swift.d.ts +10 -0
  530. package/dist/resolution/frameworks/swift.d.ts.map +1 -0
  531. package/dist/resolution/frameworks/swift.js +400 -0
  532. package/dist/resolution/frameworks/swift.js.map +1 -0
  533. package/dist/resolution/frameworks/terraform.d.ts +38 -0
  534. package/dist/resolution/frameworks/terraform.d.ts.map +1 -0
  535. package/dist/resolution/frameworks/terraform.js +277 -0
  536. package/dist/resolution/frameworks/terraform.js.map +1 -0
  537. package/dist/resolution/frameworks/vue.d.ts +9 -0
  538. package/dist/resolution/frameworks/vue.d.ts.map +1 -0
  539. package/dist/resolution/frameworks/vue.js +303 -0
  540. package/dist/resolution/frameworks/vue.js.map +1 -0
  541. package/dist/resolution/go-module.d.ts +26 -0
  542. package/dist/resolution/go-module.d.ts.map +1 -0
  543. package/dist/resolution/go-module.js +78 -0
  544. package/dist/resolution/go-module.js.map +1 -0
  545. package/dist/resolution/goframe-synthesizer.d.ts +29 -0
  546. package/dist/resolution/goframe-synthesizer.d.ts.map +1 -0
  547. package/dist/resolution/goframe-synthesizer.js +163 -0
  548. package/dist/resolution/goframe-synthesizer.js.map +1 -0
  549. package/dist/resolution/import-resolver.d.ts +85 -0
  550. package/dist/resolution/import-resolver.d.ts.map +1 -0
  551. package/dist/resolution/import-resolver.js +1974 -0
  552. package/dist/resolution/import-resolver.js.map +1 -0
  553. package/dist/resolution/index.d.ts +258 -0
  554. package/dist/resolution/index.d.ts.map +1 -0
  555. package/dist/resolution/index.js +1746 -0
  556. package/dist/resolution/index.js.map +1 -0
  557. package/dist/resolution/lru-cache.d.ts +24 -0
  558. package/dist/resolution/lru-cache.d.ts.map +1 -0
  559. package/dist/resolution/lru-cache.js +62 -0
  560. package/dist/resolution/lru-cache.js.map +1 -0
  561. package/dist/resolution/name-matcher.d.ts +112 -0
  562. package/dist/resolution/name-matcher.d.ts.map +1 -0
  563. package/dist/resolution/name-matcher.js +1830 -0
  564. package/dist/resolution/name-matcher.js.map +1 -0
  565. package/dist/resolution/path-aliases.d.ts +68 -0
  566. package/dist/resolution/path-aliases.d.ts.map +1 -0
  567. package/dist/resolution/path-aliases.js +238 -0
  568. package/dist/resolution/path-aliases.js.map +1 -0
  569. package/dist/resolution/strip-comments.d.ts +27 -0
  570. package/dist/resolution/strip-comments.d.ts.map +1 -0
  571. package/dist/resolution/strip-comments.js +492 -0
  572. package/dist/resolution/strip-comments.js.map +1 -0
  573. package/dist/resolution/swift-objc-bridge.d.ts +134 -0
  574. package/dist/resolution/swift-objc-bridge.d.ts.map +1 -0
  575. package/dist/resolution/swift-objc-bridge.js +256 -0
  576. package/dist/resolution/swift-objc-bridge.js.map +1 -0
  577. package/dist/resolution/types.d.ts +262 -0
  578. package/dist/resolution/types.d.ts.map +1 -0
  579. package/dist/resolution/types.js +8 -0
  580. package/dist/resolution/types.js.map +1 -0
  581. package/dist/resolution/workspace-packages.d.ts +58 -0
  582. package/dist/resolution/workspace-packages.d.ts.map +1 -0
  583. package/dist/resolution/workspace-packages.js +346 -0
  584. package/dist/resolution/workspace-packages.js.map +1 -0
  585. package/dist/search/identifier-segments.d.ts +60 -0
  586. package/dist/search/identifier-segments.d.ts.map +1 -0
  587. package/dist/search/identifier-segments.js +176 -0
  588. package/dist/search/identifier-segments.js.map +1 -0
  589. package/dist/search/query-parser.d.ts +57 -0
  590. package/dist/search/query-parser.d.ts.map +1 -0
  591. package/dist/search/query-parser.js +177 -0
  592. package/dist/search/query-parser.js.map +1 -0
  593. package/dist/search/query-utils.d.ts +87 -0
  594. package/dist/search/query-utils.d.ts.map +1 -0
  595. package/dist/search/query-utils.js +449 -0
  596. package/dist/search/query-utils.js.map +1 -0
  597. package/dist/sync/git-hooks.d.ts +45 -0
  598. package/dist/sync/git-hooks.d.ts.map +1 -0
  599. package/dist/sync/git-hooks.js +227 -0
  600. package/dist/sync/git-hooks.js.map +1 -0
  601. package/dist/sync/index.d.ts +19 -0
  602. package/dist/sync/index.d.ts.map +1 -0
  603. package/dist/sync/index.js +35 -0
  604. package/dist/sync/index.js.map +1 -0
  605. package/dist/sync/watch-policy.d.ts +48 -0
  606. package/dist/sync/watch-policy.d.ts.map +1 -0
  607. package/dist/sync/watch-policy.js +124 -0
  608. package/dist/sync/watch-policy.js.map +1 -0
  609. package/dist/sync/watcher.d.ts +355 -0
  610. package/dist/sync/watcher.d.ts.map +1 -0
  611. package/dist/sync/watcher.js +848 -0
  612. package/dist/sync/watcher.js.map +1 -0
  613. package/dist/sync/worktree.d.ts +63 -0
  614. package/dist/sync/worktree.d.ts.map +1 -0
  615. package/dist/sync/worktree.js +182 -0
  616. package/dist/sync/worktree.js.map +1 -0
  617. package/dist/telemetry/index.d.ts +143 -0
  618. package/dist/telemetry/index.d.ts.map +1 -0
  619. package/dist/telemetry/index.js +541 -0
  620. package/dist/telemetry/index.js.map +1 -0
  621. package/dist/types.d.ts +415 -0
  622. package/dist/types.d.ts.map +1 -0
  623. package/dist/types.js +91 -0
  624. package/dist/types.js.map +1 -0
  625. package/dist/ui/glyphs.d.ts +42 -0
  626. package/dist/ui/glyphs.d.ts.map +1 -0
  627. package/dist/ui/glyphs.js +78 -0
  628. package/dist/ui/glyphs.js.map +1 -0
  629. package/dist/ui/shimmer-progress.d.ts +11 -0
  630. package/dist/ui/shimmer-progress.d.ts.map +1 -0
  631. package/dist/ui/shimmer-progress.js +90 -0
  632. package/dist/ui/shimmer-progress.js.map +1 -0
  633. package/dist/ui/shimmer-worker.d.ts +2 -0
  634. package/dist/ui/shimmer-worker.d.ts.map +1 -0
  635. package/dist/ui/shimmer-worker.js +118 -0
  636. package/dist/ui/shimmer-worker.js.map +1 -0
  637. package/dist/ui/types.d.ts +17 -0
  638. package/dist/ui/types.d.ts.map +1 -0
  639. package/dist/ui/types.js +3 -0
  640. package/dist/ui/types.js.map +1 -0
  641. package/dist/upgrade/index.d.ts +164 -0
  642. package/dist/upgrade/index.d.ts.map +1 -0
  643. package/dist/upgrade/index.js +646 -0
  644. package/dist/upgrade/index.js.map +1 -0
  645. package/dist/upgrade/remove-binary.d.ts +87 -0
  646. package/dist/upgrade/remove-binary.d.ts.map +1 -0
  647. package/dist/upgrade/remove-binary.js +289 -0
  648. package/dist/upgrade/remove-binary.js.map +1 -0
  649. package/dist/upgrade/update-check.d.ts +92 -0
  650. package/dist/upgrade/update-check.d.ts.map +1 -0
  651. package/dist/upgrade/update-check.js +258 -0
  652. package/dist/upgrade/update-check.js.map +1 -0
  653. package/dist/utils.d.ts +224 -0
  654. package/dist/utils.d.ts.map +1 -0
  655. package/dist/utils.js +583 -0
  656. package/dist/utils.js.map +1 -0
  657. package/package.json +1 -1
@@ -0,0 +1,3938 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.synthesizeCallbackEdges = synthesizeCallbackEdges;
4
+ const generated_detection_1 = require("../extraction/generated-detection");
5
+ const strip_comments_1 = require("./strip-comments");
6
+ const c_fnptr_synthesizer_1 = require("./c-fnptr-synthesizer");
7
+ const goframe_synthesizer_1 = require("./goframe-synthesizer");
8
+ const cooperative_yield_1 = require("./cooperative-yield");
9
+ const REGISTRAR_NAME = /^(on[A-Z]\w*|subscribe|addListener|addEventListener|register|watch|listen|addCallback)$/;
10
+ const DISPATCHER_NAME = /(emit|trigger|notify|dispatch|fire|publish|flush)/i;
11
+ const MAX_CALLBACKS_PER_CHANNEL = 40;
12
+ const EVENT_FANOUT_CAP = 6; // skip events with more handlers/dispatchers than this (too generic without type info)
13
+ const ON_RE = /\.(?:on|once|addListener)\(\s*['"]([^'"]+)['"]\s*,\s*(?:function\s+(\w+)|(?:this\.)?(\w+))/g;
14
+ const EMIT_RE = /\.(?:emit|fire|dispatchEvent)\(\s*['"]([^'"]+)['"]/g;
15
+ const SETSTATE_RE = /this\.setState\s*\(/;
16
+ const FLUTTER_SETSTATE_RE = /\bsetState\s*\(/; // Flutter: setState((){…}) / this.setState
17
+ const JSX_TAG_RE = /<([A-Z][A-Za-z0-9_]*)[\s/>]/g;
18
+ const MAX_JSX_CHILDREN = 30;
19
+ // Vue SFC templates: kebab-case child components (<el-button> → ElButton) and
20
+ // event bindings (@click="fn" / v-on:click="fn"). PascalCase children (<VPNav/>)
21
+ // are already caught by JSX_TAG_RE via the SFC component node.
22
+ const VUE_KEBAB_RE = /<([a-z][a-z0-9]*(?:-[a-z0-9]+)+)[\s/>]/g;
23
+ // PascalCase component tags — `<MediaCard ...>`, `<NavBar/>`. HTML elements are
24
+ // lowercase, so an uppercase-initial tag is a component usage; built-ins
25
+ // (`<NuxtLink>`, `<Transition>`) simply resolve to nothing and emit no edge.
26
+ const VUE_PASCAL_RE = /<([A-Z][A-Za-z0-9]*)[\s/>]/g;
27
+ const VUE_HANDLER_RE = /(?:@|v-on:)([a-zA-Z][\w-]*)(?:\.[\w]+)*\s*=\s*"([^"]+)"/g;
28
+ // Composable/hook destructure: `const { close: closeSidebar } = useSidebarControl()`.
29
+ // Captures the destructure body + the called composable; only `use*` calls qualify.
30
+ const VUE_DESTRUCTURE_RE = /(?:const|let|var)\s*\{([^}]+)\}\s*=\s*(\w+)\s*\(/g;
31
+ // Closure-collection dynamic dispatch (language-agnostic, Swift-first). A method
32
+ // appends a closure to a collection property; another method iterates that
33
+ // property *invoking each element* (`coll.forEach { $0() }` / `{ it() }`). The
34
+ // element-invoke (`$0(` / `it(`) PROVES the collection holds closures, so pairing
35
+ // a dispatcher to same-named registrars (`.append`/`.add`/`.push`/`.insert`,
36
+ // incl. Swift `prop.write { $0.append }`) is high-precision. Cross-file/class by
37
+ // design: Alamofire appends in `DataRequest.validate` but iterates in the base
38
+ // `Request.didCompleteTask` — neither same-file nor same-class pairing reaches it.
39
+ const CC_DISPATCH_RE = /(\w+)\.forEach\s*\{\s*(?:\$0|it)\s*\(/g;
40
+ const CC_APPEND_WRITE_RE = /(\w+)\.write\s*\{\s*\$0(?:\.(\w+))?\.(?:append|add|push|insert)\s*\(/g;
41
+ const CC_APPEND_DIRECT_RE = /(\w+)\.(?:append|add|push|insert)\s*\(/g;
42
+ const CC_FANOUT_CAP = 8; // skip a field name with more dispatchers/registrars than this (too generic to pair confidently)
43
+ // The dispatcher gate — `{ $0( ` / `{ it( ` element-invocation — is Swift/Kotlin
44
+ // trailing-closure syntax, so ONLY those languages can ever contribute a
45
+ // dispatcher, and a cross-language registrar pairing (a JS `.push(` against a
46
+ // Swift dispatcher's field name) would be a wrong edge, not a missed one.
47
+ // Gating both sides here isn't just precision: `.push(`/`.add(` is everywhere
48
+ // in JS/PHP, so an ungated scan slices + regexes nearly every function on repos
49
+ // where the pass cannot emit a single edge — on a 12k-file PHP/JS app that was
50
+ // 20+ minutes of the "Resolving refs" tail and a #850 watchdog kill (#1235).
51
+ const CC_LANGUAGES = new Set(['swift', 'kotlin']);
52
+ function kebabToPascal(s) {
53
+ return s.split('-').map((p) => p.charAt(0).toUpperCase() + p.slice(1)).join('');
54
+ }
55
+ /**
56
+ * Nuxt auto-import name for a component, derived from its path UNDER `components/`:
57
+ * `components/media/Card.vue` → `MediaCard`, `components/base/foo/Bar.vue` →
58
+ * `BaseFooBar`. Each directory segment and the filename is PascalCased and
59
+ * concatenated; a directory whose PascalCase name prefixes the next segment is
60
+ * collapsed (Nuxt's de-dup: `base/BaseButton.vue` → `BaseButton`, not
61
+ * `BaseBaseButton`). Returns null for a flat component (`components/NavBar.vue`)
62
+ * — its node is already named by basename, so a direct tag match finds it.
63
+ */
64
+ function nuxtComponentName(filePath) {
65
+ const marker = filePath.lastIndexOf('components/');
66
+ if (marker === -1)
67
+ return null;
68
+ const rel = filePath.slice(marker + 'components/'.length).replace(/\.(vue|ts|tsx|js|jsx)$/i, '');
69
+ const segs = rel.split('/').filter(Boolean).map(kebabToPascal);
70
+ if (segs.length < 2)
71
+ return null;
72
+ const out = [];
73
+ for (const s of segs) {
74
+ const prev = out[out.length - 1];
75
+ if (prev && s.startsWith(prev))
76
+ out[out.length - 1] = s;
77
+ else
78
+ out.push(s);
79
+ }
80
+ return out.join('');
81
+ }
82
+ function sliceLines(content, startLine, endLine) {
83
+ if (!startLine || !endLine)
84
+ return null;
85
+ return content.split('\n').slice(startLine - 1, endLine).join('\n');
86
+ }
87
+ /**
88
+ * Per-match line resolver over `src`, 1-based at `baseLine`. The inline
89
+ * `src.slice(0, idx).split('\n').length` idiom is O(source-length) PER MATCH,
90
+ * which goes quadratic on a match-dense source (a generated function full of
91
+ * `.push(` calls re-scanned tens of thousands of times was most of the #1235
92
+ * indexing wedge). Builds the newline index once — lazily, since most sources
93
+ * never produce a match — then answers each call with a binary search.
94
+ */
95
+ function makeLineAt(src, baseLine) {
96
+ let nl = null;
97
+ return (idx) => {
98
+ if (!nl) {
99
+ nl = [];
100
+ for (let i = src.indexOf('\n'); i !== -1; i = src.indexOf('\n', i + 1))
101
+ nl.push(i);
102
+ }
103
+ // Count newlines strictly before idx.
104
+ let lo = 0;
105
+ let hi = nl.length;
106
+ while (lo < hi) {
107
+ const mid = (lo + hi) >> 1;
108
+ if (nl[mid] < idx)
109
+ lo = mid + 1;
110
+ else
111
+ hi = mid;
112
+ }
113
+ return baseLine + lo;
114
+ };
115
+ }
116
+ function registrarField(src) {
117
+ const m = src.match(/this\.(\w+)\.(?:add|push|set)\(/);
118
+ return m ? m[1] : null;
119
+ }
120
+ function dispatcherField(src) {
121
+ const forOf = src.match(/\bof\s+(?:Array\.from\(\s*)?this\.(\w+)/);
122
+ if (forOf && /\b\w+\s*\(/.test(src))
123
+ return forOf[1];
124
+ const forEach = src.match(/this\.(\w+)\.forEach\(/);
125
+ if (forEach)
126
+ return forEach[1];
127
+ return null;
128
+ }
129
+ const FN_KINDS = new Set(['method', 'function', 'component']);
130
+ /** Innermost function/method node whose line range contains `line`. */
131
+ function enclosingFn(nodesInFile, line) {
132
+ let best = null;
133
+ for (const n of nodesInFile) {
134
+ if (!FN_KINDS.has(n.kind))
135
+ continue;
136
+ const end = n.endLine ?? n.startLine;
137
+ if (n.startLine <= line && end >= line) {
138
+ if (!best || n.startLine >= best.startLine)
139
+ best = n; // prefer the tightest (latest-starting) encloser
140
+ }
141
+ }
142
+ return best;
143
+ }
144
+ /**
145
+ * Stream method + function nodes lazily. The synthesizers only scan-and-filter
146
+ * down to a tiny matched subset, so materializing every function/method (which
147
+ * is gigabytes on a symbol-dense project) just to iterate it once is what OOM'd
148
+ * #610. Iterating keeps memory O(1) in the node count.
149
+ */
150
+ function* methodAndFunctionNodes(queries) {
151
+ yield* queries.iterateNodesByKind('method');
152
+ yield* queries.iterateNodesByKind('function');
153
+ }
154
+ /** Phase 1: field-backed observer channels (registrar/dispatcher share a store). */
155
+ async function fieldChannelEdges(queries, ctx, onYield) {
156
+ const registrars = [];
157
+ const dispatchers = [];
158
+ let scanned = 0;
159
+ for (const m of methodAndFunctionNodes(queries)) {
160
+ if ((++scanned & 255) === 0)
161
+ await onYield(); // #1091: yield mid-scan on huge graphs
162
+ const isReg = REGISTRAR_NAME.test(m.name);
163
+ const isDisp = DISPATCHER_NAME.test(m.name);
164
+ if (!isReg && !isDisp)
165
+ continue;
166
+ const content = ctx.readFile(m.filePath);
167
+ const src = content && sliceLines(content, m.startLine, m.endLine);
168
+ if (!src)
169
+ continue;
170
+ if (isReg) {
171
+ const f = registrarField(src);
172
+ if (f)
173
+ registrars.push({ node: m, field: f });
174
+ }
175
+ if (isDisp) {
176
+ const f = dispatcherField(src);
177
+ if (f)
178
+ dispatchers.push({ node: m, field: f });
179
+ }
180
+ }
181
+ const edges = [];
182
+ const seen = new Set();
183
+ for (const reg of registrars) {
184
+ const chDispatchers = dispatchers.filter((d) => d.node.filePath === reg.node.filePath && d.field === reg.field);
185
+ if (chDispatchers.length === 0)
186
+ continue;
187
+ const argRe = new RegExp(`${reg.node.name}\\s*\\(\\s*(?:this\\.)?(\\w+)`);
188
+ let added = 0;
189
+ for (const e of queries.getIncomingEdges(reg.node.id, ['calls'])) {
190
+ if (added >= MAX_CALLBACKS_PER_CHANNEL)
191
+ break;
192
+ if (!e.line)
193
+ continue;
194
+ const caller = queries.getNodeById(e.source);
195
+ if (!caller)
196
+ continue;
197
+ const line = ctx.readFile(caller.filePath)?.split('\n')[e.line - 1];
198
+ const am = line?.match(argRe);
199
+ if (!am)
200
+ continue;
201
+ const fn = ctx.getNodesByName(am[1]).find((n) => n.kind === 'method' || n.kind === 'function');
202
+ if (!fn)
203
+ continue;
204
+ for (const disp of chDispatchers) {
205
+ if (disp.node.id === fn.id)
206
+ continue;
207
+ const key = `${disp.node.id}>${fn.id}`;
208
+ if (seen.has(key))
209
+ continue;
210
+ seen.add(key);
211
+ edges.push({
212
+ source: disp.node.id, target: fn.id, kind: 'calls', line: disp.node.startLine,
213
+ provenance: 'heuristic',
214
+ metadata: {
215
+ synthesizedBy: 'callback', via: reg.node.name, field: reg.field,
216
+ // Where the callback was wired up (`scene.onUpdate(this.triggerRender)`).
217
+ // This is the #1 thing an agent reads/greps to explain the flow — surface
218
+ // it so node/trace/context can show it without a callers() + Read round-trip.
219
+ registeredAt: `${caller.filePath}:${e.line}`,
220
+ },
221
+ });
222
+ added++;
223
+ }
224
+ }
225
+ }
226
+ return edges;
227
+ }
228
+ /**
229
+ * Closure-collection dispatch: dispatcher iterates a closure-collection property
230
+ * invoking each element; registrar appends a closure to the same-named property.
231
+ * Emits dispatcher → registrar so a flow reaches the registration site (where the
232
+ * appended closure's body — and its callers — live). High-precision: the
233
+ * dispatcher's element-invoke is the gate (a `.forEach` that does NOT invoke its
234
+ * element is ignored), so a repo with no closure-collection dispatch yields zero
235
+ * edges regardless of how many `.append`/`.push` sites it has.
236
+ *
237
+ * Pairs globally by field name (cross-file/class is required — see Alamofire's
238
+ * base-class `Request.didCompleteTask` iterating `validators` appended by the
239
+ * subclass `DataRequest.validate`), bounded by a fan-out cap so a generic field
240
+ * name shared across unrelated classes can't fan out into noise.
241
+ */
242
+ async function closureCollectionEdges(queries, ctx, onYield) {
243
+ const dispatchers = new Map(); // field → dispatcher methods + forEach line
244
+ const registrars = new Map(); // field → registrar methods + append line
245
+ const addReg = (field, node, absLine) => {
246
+ if (!field || /^\d+$/.test(field))
247
+ return; // `$0.append` mis-captures the `0`; the write-RE owns that field
248
+ const arr = registrars.get(field) ?? [];
249
+ if (!arr.some((r) => r.node.id === node.id))
250
+ arr.push({ node, line: absLine });
251
+ registrars.set(field, arr);
252
+ };
253
+ // Slices EVERY Swift/Kotlin method/function's source (no cheap name-gate), so
254
+ // on a repo with a huge file this is the heaviest synthesis pass — yield
255
+ // mid-scan (and mid-match-loop below: a single generated function dense with
256
+ // matches must not starve the watchdog either) so it can't wedge the #850
257
+ // watchdog on its own (#1091, #1235).
258
+ let scanned = 0;
259
+ let matchTick = 0;
260
+ for (const m of methodAndFunctionNodes(queries)) {
261
+ if ((++scanned & 127) === 0)
262
+ await onYield();
263
+ if (!CC_LANGUAGES.has(m.language))
264
+ continue;
265
+ const content = ctx.readFile(m.filePath);
266
+ const src = content && sliceLines(content, m.startLine, m.endLine);
267
+ if (!src)
268
+ continue;
269
+ const hasForEach = src.includes('.forEach');
270
+ const hasAppend = src.includes('.append(') || src.includes('.add(') || src.includes('.push(') || src.includes('.insert(');
271
+ if (!hasForEach && !hasAppend)
272
+ continue;
273
+ const lineAt = makeLineAt(src, m.startLine ?? 1);
274
+ if (hasForEach) {
275
+ CC_DISPATCH_RE.lastIndex = 0;
276
+ let d;
277
+ while ((d = CC_DISPATCH_RE.exec(src))) {
278
+ if ((++matchTick & 255) === 0)
279
+ await onYield();
280
+ const arr = dispatchers.get(d[1]) ?? [];
281
+ if (!arr.some((n) => n.node.id === m.id))
282
+ arr.push({ node: m, line: lineAt(d.index) });
283
+ dispatchers.set(d[1], arr);
284
+ }
285
+ }
286
+ if (hasAppend) {
287
+ CC_APPEND_WRITE_RE.lastIndex = 0;
288
+ let w;
289
+ while ((w = CC_APPEND_WRITE_RE.exec(src))) {
290
+ if ((++matchTick & 255) === 0)
291
+ await onYield();
292
+ addReg(w[2] || w[1], m, lineAt(w.index)); // nested `$0.streams` else the `.write` receiver
293
+ }
294
+ CC_APPEND_DIRECT_RE.lastIndex = 0;
295
+ let a;
296
+ while ((a = CC_APPEND_DIRECT_RE.exec(src))) {
297
+ if ((++matchTick & 255) === 0)
298
+ await onYield();
299
+ addReg(a[1], m, lineAt(a.index));
300
+ }
301
+ }
302
+ }
303
+ const edges = [];
304
+ const seen = new Set();
305
+ for (const [field, disps] of dispatchers) {
306
+ const regs = registrars.get(field);
307
+ if (!regs || regs.length === 0)
308
+ continue;
309
+ if (disps.length > CC_FANOUT_CAP || regs.length > CC_FANOUT_CAP)
310
+ continue; // generic field — can't pair confidently
311
+ for (const disp of disps)
312
+ for (const reg of regs) {
313
+ if (disp.node.id === reg.node.id)
314
+ continue;
315
+ const key = `${disp.node.id}>${reg.node.id}`;
316
+ if (seen.has(key))
317
+ continue;
318
+ seen.add(key);
319
+ edges.push({
320
+ source: disp.node.id, target: reg.node.id, kind: 'calls', line: disp.line,
321
+ provenance: 'heuristic',
322
+ metadata: { synthesizedBy: 'closure-collection', field, registeredAt: `${reg.node.filePath}:${reg.line}` },
323
+ });
324
+ }
325
+ }
326
+ return edges;
327
+ }
328
+ /** Phase 2: string-keyed EventEmitter channels (on('e', fn) ↔ emit('e')). */
329
+ async function eventEmitterEdges(ctx, onYield) {
330
+ let scannedFiles = 0;
331
+ const emitsByEvent = new Map(); // event → dispatcher node ids
332
+ const handlersByEvent = new Map(); // event → handler id → registration site (file:line)
333
+ let scanned = 0;
334
+ for (const file of ctx.getAllFiles()) {
335
+ if ((++scannedFiles & 15) === 0)
336
+ await onYield();
337
+ if ((++scanned & 255) === 0)
338
+ await onYield(); // #1091: yield mid-scan on huge graphs
339
+ const content = ctx.readFile(file);
340
+ if (!content)
341
+ continue;
342
+ const hasEmit = content.includes('.emit(') || content.includes('.fire(') || content.includes('.dispatchEvent(');
343
+ const hasOn = content.includes('.on(') || content.includes('.once(') || content.includes('.addListener(');
344
+ if (!hasEmit && !hasOn)
345
+ continue;
346
+ const nodesInFile = ctx.getNodesInFile(file);
347
+ const lineOf = makeLineAt(content, 1);
348
+ if (hasEmit) {
349
+ EMIT_RE.lastIndex = 0;
350
+ let m;
351
+ while ((m = EMIT_RE.exec(content))) {
352
+ const disp = enclosingFn(nodesInFile, lineOf(m.index));
353
+ if (!disp)
354
+ continue;
355
+ const set = emitsByEvent.get(m[1]) ?? new Set();
356
+ set.add(disp.id);
357
+ emitsByEvent.set(m[1], set);
358
+ }
359
+ }
360
+ if (hasOn) {
361
+ ON_RE.lastIndex = 0;
362
+ let m;
363
+ while ((m = ON_RE.exec(content))) {
364
+ const handlerName = m[2] || m[3];
365
+ if (!handlerName)
366
+ continue;
367
+ const handler = ctx.getNodesByName(handlerName).find((n) => n.kind === 'function' || n.kind === 'method');
368
+ if (!handler)
369
+ continue;
370
+ const map = handlersByEvent.get(m[1]) ?? new Map();
371
+ map.set(handler.id, `${file}:${lineOf(m.index)}`);
372
+ handlersByEvent.set(m[1], map);
373
+ }
374
+ }
375
+ }
376
+ const edges = [];
377
+ const seen = new Set();
378
+ for (const [event, dispatchers] of emitsByEvent) {
379
+ const handlers = handlersByEvent.get(event);
380
+ if (!handlers)
381
+ continue;
382
+ // Precision guard: a generic event name with many handlers/dispatchers can't
383
+ // be matched without receiver-type info (Phase 3) — skip rather than over-link.
384
+ if (dispatchers.size > EVENT_FANOUT_CAP || handlers.size > EVENT_FANOUT_CAP)
385
+ continue;
386
+ for (const d of dispatchers)
387
+ for (const [h, registeredAt] of handlers) {
388
+ if (d === h)
389
+ continue;
390
+ const key = `${d}>${h}`;
391
+ if (seen.has(key))
392
+ continue;
393
+ seen.add(key);
394
+ edges.push({ source: d, target: h, kind: 'calls', provenance: 'heuristic', metadata: { synthesizedBy: 'event-emitter', event, registeredAt } });
395
+ }
396
+ }
397
+ return edges;
398
+ }
399
+ /**
400
+ * Phase 4: React class-component re-render. `this.setState(...)` re-runs the
401
+ * component's `render()`, but that hop is React-internal — no static edge — so a
402
+ * flow like "mutation → setState → canvas repaint" dead-ends at setState even
403
+ * though `render → getRenderableElements → …` is fully call-connected after it.
404
+ * Bridge it: for each class that has a `render` method, link every sibling method
405
+ * whose body calls `this.setState(` → `render`. The setState gate keeps this to
406
+ * React class components (a non-React class with a `render` method won't call
407
+ * `this.setState`). Over-approximation (all setState methods reach render) is
408
+ * accepted — it's reachability-correct, like the callback channels.
409
+ */
410
+ async function reactRenderEdges(queries, ctx, onYield) {
411
+ let scanned255 = 0;
412
+ const edges = [];
413
+ const seen = new Set();
414
+ for (const cls of queries.iterateNodesByKind('class')) {
415
+ if ((++scanned255 & 63) === 0)
416
+ await onYield();
417
+ const children = queries.getOutgoingEdges(cls.id, ['contains'])
418
+ .map((e) => queries.getNodeById(e.target))
419
+ .filter((n) => !!n && n.kind === 'method');
420
+ const render = children.find((n) => n.name === 'render');
421
+ if (!render)
422
+ continue;
423
+ let added = 0;
424
+ for (const m of children) {
425
+ if (added >= MAX_CALLBACKS_PER_CHANNEL)
426
+ break;
427
+ if (m.id === render.id)
428
+ continue;
429
+ const content = ctx.readFile(m.filePath);
430
+ const src = content && sliceLines(content, m.startLine, m.endLine);
431
+ if (!src || !SETSTATE_RE.test(src))
432
+ continue;
433
+ const key = `${m.id}>${render.id}`;
434
+ if (seen.has(key))
435
+ continue;
436
+ seen.add(key);
437
+ edges.push({
438
+ source: m.id, target: render.id, kind: 'calls', line: m.startLine,
439
+ provenance: 'heuristic',
440
+ metadata: { synthesizedBy: 'react-render', via: 'setState', registeredAt: `${render.filePath}:${render.startLine}` },
441
+ });
442
+ added++;
443
+ }
444
+ }
445
+ return edges;
446
+ }
447
+ /**
448
+ * Phase 4b: Flutter setState → build (the Dart analog of react-render). In a
449
+ * StatefulWidget's State class, `setState(() {…})` re-runs `build(context)`, but
450
+ * that hop is framework-internal (Flutter calls build), so a flow like
451
+ * "onPressed → _increment → setState → rebuilt UI" dead-ends at setState. Bridge
452
+ * it: for each Dart class with a `build` method, link every sibling method whose
453
+ * body calls `setState(` → `build`. The setState gate + `.dart` file keep this to
454
+ * Flutter State classes. Over-approximation accepted (reachability-correct).
455
+ */
456
+ async function flutterBuildEdges(queries, ctx, onYield) {
457
+ let scanned255 = 0;
458
+ const edges = [];
459
+ const seen = new Set();
460
+ for (const cls of queries.iterateNodesByKind('class')) {
461
+ if ((++scanned255 & 63) === 0)
462
+ await onYield();
463
+ const children = queries.getOutgoingEdges(cls.id, ['contains'])
464
+ .map((e) => queries.getNodeById(e.target))
465
+ .filter((n) => !!n && n.kind === 'method');
466
+ const build = children.find((n) => n.name === 'build');
467
+ if (!build || !build.filePath.endsWith('.dart'))
468
+ continue;
469
+ let added = 0;
470
+ for (const m of children) {
471
+ if (added >= MAX_CALLBACKS_PER_CHANNEL)
472
+ break;
473
+ if (m.id === build.id)
474
+ continue;
475
+ const content = ctx.readFile(m.filePath);
476
+ const src = content && sliceLines(content, m.startLine, m.endLine);
477
+ if (!src || !FLUTTER_SETSTATE_RE.test(src))
478
+ continue;
479
+ const key = `${m.id}>${build.id}`;
480
+ if (seen.has(key))
481
+ continue;
482
+ seen.add(key);
483
+ edges.push({
484
+ source: m.id, target: build.id, kind: 'calls', line: m.startLine,
485
+ provenance: 'heuristic',
486
+ metadata: { synthesizedBy: 'flutter-build', via: 'setState', registeredAt: `${build.filePath}:${build.startLine}` },
487
+ });
488
+ added++;
489
+ }
490
+ }
491
+ return edges;
492
+ }
493
+ /**
494
+ * Reactive ArkUI property decorators: assigning a property carrying one of
495
+ * these re-runs the owning struct's `build()`. Covers both state models —
496
+ * V1 (`@Component`: State/Prop/Link/Provide/Consume/Storage*) and V2
497
+ * (`@ComponentV2`: Local/Provider/Consumer; `@Param` is read-only in V2 so
498
+ * the assignment gate never fires on it, and `@Trace` lives on `@ObservedV2`
499
+ * data classes, not struct properties).
500
+ */
501
+ const ARKUI_REACTIVE_DECORATORS = new Set([
502
+ 'State', 'Prop', 'Link', 'Provide', 'Consume', 'StorageLink', 'StorageProp',
503
+ 'LocalStorageLink', 'LocalStorageProp', 'ObjectLink',
504
+ 'Local', 'Provider', 'Consumer',
505
+ ]);
506
+ /** ArkUI-observed array mutators — `this.todos.push(x)` re-renders like an assignment. */
507
+ const ARKUI_ARRAY_MUTATORS = 'push|pop|shift|unshift|splice|sort|reverse|fill';
508
+ /**
509
+ * Phase 4b-ets: ArkUI state → build (the ArkTS analog of react-render /
510
+ * flutter-build). Assigning a reactive-decorated property (`@State count`,
511
+ * `@Link selected`, …) re-runs the `@Component struct`'s `build()`, but that
512
+ * hop is framework-internal — no static edge — so "onClick → markAllDone →
513
+ * this.todos = […] → rebuilt list" dead-ends at the assignment. Bridge it:
514
+ * for each arkts struct with a `build()` method and at least one reactive
515
+ * property, link every sibling method whose body ASSIGNS (or array-mutates)
516
+ * one of those properties → `build`. Assignment-gated on the struct's OWN
517
+ * reactive property names — a method that merely reads state, or a struct
518
+ * with no reactive properties, gets nothing (this is the precision line the
519
+ * all-sibling-methods design would erase).
520
+ */
521
+ async function arkuiStateBuildEdges(queries, ctx, onYield) {
522
+ let scanned255 = 0;
523
+ const edges = [];
524
+ const seen = new Set();
525
+ for (const struct of queries.iterateNodesByKind('struct')) {
526
+ if ((++scanned255 & 63) === 0)
527
+ await onYield();
528
+ if (struct.language !== 'arkts')
529
+ continue;
530
+ const children = queries.getOutgoingEdges(struct.id, ['contains'])
531
+ .map((e) => queries.getNodeById(e.target))
532
+ .filter((n) => !!n);
533
+ const build = children.find((n) => n.kind === 'method' && n.name === 'build');
534
+ if (!build)
535
+ continue;
536
+ const reactiveProps = children.filter((n) => n.kind === 'property' && (n.decorators ?? []).some((d) => ARKUI_REACTIVE_DECORATORS.has(d)));
537
+ if (reactiveProps.length === 0)
538
+ continue;
539
+ const propAlternation = reactiveProps
540
+ .map((p) => p.name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
541
+ .join('|');
542
+ // `this.count = …` / `+=` / `++` / `--` / `this.todos.push(…)`. The
543
+ // `=(?!=)` keeps `this.done == x` comparisons out.
544
+ const mutationRe = new RegExp(`this\\.(?:${propAlternation})\\s*(?:=(?!=)|\\+\\+|--|[+\\-*/%&|^]=|\\.(?:${ARKUI_ARRAY_MUTATORS})\\s*\\()`);
545
+ let added = 0;
546
+ for (const m of children) {
547
+ if (added >= MAX_CALLBACKS_PER_CHANNEL)
548
+ break;
549
+ if (m.kind !== 'method' || m.id === build.id)
550
+ continue;
551
+ const content = ctx.readFile(m.filePath);
552
+ const src = content && sliceLines(content, m.startLine, m.endLine);
553
+ if (!src || !mutationRe.test((0, strip_comments_1.stripCommentsForRegex)(src, 'typescript')))
554
+ continue;
555
+ const key = `${m.id}>${build.id}`;
556
+ if (seen.has(key))
557
+ continue;
558
+ seen.add(key);
559
+ edges.push({
560
+ source: m.id, target: build.id, kind: 'calls', line: m.startLine,
561
+ provenance: 'heuristic',
562
+ metadata: { synthesizedBy: 'arkui-state', via: 'state assignment', registeredAt: `${build.filePath}:${build.startLine}` },
563
+ });
564
+ added++;
565
+ }
566
+ }
567
+ return edges;
568
+ }
569
+ /** Emit/subscribe call sites of HarmonyOS's `@ohos.events.emitter` bus. */
570
+ const ARKUI_EMITTER_CALL_RE = /\bemitter\s*\.\s*(emit|on|once)\s*\(\s*([A-Za-z_$][\w$.]*|\{[^)]{0,120}?\beventId\s*:\s*[^,}]+[^)]*?\})/g;
571
+ /** Cap per event bucket — a generic key with many parties is dynamic routing, not a static pair. */
572
+ const ARKUI_EMITTER_FANOUT_CAP = 8;
573
+ /**
574
+ * Phase 4b-ets2: HarmonyOS `@ohos.events.emitter` bridge. The cross-component
575
+ * bus — `emitter.emit(eventId)` fires `emitter.on(eventId, cb)` — is
576
+ * framework-internal, so an order flow riding it (OrangeShopping's
577
+ * add-to-cart) dead-ends at the emit. Link emit-site enclosing
578
+ * function/method → on/once-site enclosing function/method when both
579
+ * reference the SAME statically-recoverable event key.
580
+ *
581
+ * Key recovery, per call site (comment-stripped enclosing-file source): the
582
+ * first argument is an `{ eventId: K }` literal, a `Names.Dotted` constant, or
583
+ * a local whose same-file declaration is `new EventsId(K)` / `= K` — chase one
584
+ * level. Precision scoping learned from the samples monorepo (thousands of
585
+ * unrelated samples, most using eventId 1): NUMERIC keys pair within the same
586
+ * FILE only; NAMED keys pair within the same workspace module directory (or
587
+ * the whole project when it declares no modules — the single-app case), both
588
+ * behind a fan-out cap. Inline `on(id, (e) => {…})` arrows need no special
589
+ * handling — their bodies' calls already attribute to the registering method,
590
+ * so targeting that method keeps the chain connected.
591
+ */
592
+ async function arkuiEmitterEdges(ctx, onYield) {
593
+ let scannedFiles = 0;
594
+ // bucket key -> emit sites / handler sites
595
+ const emits = new Map();
596
+ const handlers = new Map();
597
+ const moduleDirs = (() => {
598
+ const ws = ctx.getWorkspacePackages?.();
599
+ return ws ? [...new Set(ws.byName.values())].sort((a, b) => b.length - a.length) : [];
600
+ })();
601
+ const moduleScopeOf = (file) => {
602
+ for (const dir of moduleDirs) {
603
+ if (file === dir || file.startsWith(dir + '/'))
604
+ return dir;
605
+ }
606
+ return '';
607
+ };
608
+ for (const file of ctx.getAllFiles()) {
609
+ if ((++scannedFiles & 15) === 0)
610
+ await onYield();
611
+ if (!file.endsWith('.ets'))
612
+ continue;
613
+ const content = ctx.readFile(file);
614
+ if (!content || !content.includes('emitter.'))
615
+ continue;
616
+ const safe = (0, strip_comments_1.stripCommentsForRegex)(content, 'typescript');
617
+ const nodes = ctx.getNodesInFile(file)
618
+ .filter((n) => n.kind === 'method' || n.kind === 'function');
619
+ ARKUI_EMITTER_CALL_RE.lastIndex = 0;
620
+ let m;
621
+ while ((m = ARKUI_EMITTER_CALL_RE.exec(safe))) {
622
+ const verb = m[1];
623
+ const arg = m[2].trim();
624
+ const line = safe.slice(0, m.index).split('\n').length;
625
+ const encl = nodes
626
+ .filter((n) => n.startLine <= line && n.endLine >= line)
627
+ .sort((a, b) => (a.endLine - a.startLine) - (b.endLine - b.startLine))[0];
628
+ if (!encl)
629
+ continue;
630
+ // Recover the event key from the first argument.
631
+ let key = null;
632
+ const idLit = arg.startsWith('{') ? arg.match(/\beventId\s*:\s*([\w$.]+)/)?.[1] : undefined;
633
+ const token = idLit ?? arg;
634
+ if (token !== undefined) {
635
+ if (/^\d+$/.test(token)) {
636
+ key = `num:${file}:${token}`; // numeric: same-file only
637
+ }
638
+ else if (token.includes('.')) {
639
+ key = `name:${moduleScopeOf(file)}:${token}`;
640
+ }
641
+ else {
642
+ // Local variable — chase its same-file declaration one level:
643
+ // `let x = new EventsId(K)` / `const x = K`.
644
+ const declRe = new RegExp(`\\b${token.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b\\s*(?::[^=\\n]+)?=\\s*(?:new\\s+[\\w$.]+\\(\\s*([^)\\n]+?)\\s*\\)|([\\w$.]+))`);
645
+ const decl = safe.match(declRe);
646
+ const inner = (decl?.[1] ?? decl?.[2])?.trim();
647
+ if (inner && /^\d+$/.test(inner))
648
+ key = `num:${file}:${inner}`;
649
+ else if (inner && /^[\w$.]+$/.test(inner))
650
+ key = `name:${moduleScopeOf(file)}:${inner}`;
651
+ }
652
+ }
653
+ if (!key)
654
+ continue;
655
+ const site = { nodeId: encl.id, file, line };
656
+ if (verb === 'emit') {
657
+ (emits.get(key) ?? emits.set(key, []).get(key)).push(site);
658
+ }
659
+ else {
660
+ (handlers.get(key) ?? handlers.set(key, []).get(key)).push(site);
661
+ }
662
+ }
663
+ }
664
+ const edges = [];
665
+ const seen = new Set();
666
+ for (const [key, emitSites] of emits) {
667
+ const handlerSites = handlers.get(key);
668
+ if (!handlerSites)
669
+ continue;
670
+ if (emitSites.length > ARKUI_EMITTER_FANOUT_CAP || handlerSites.length > ARKUI_EMITTER_FANOUT_CAP)
671
+ continue;
672
+ const eventLabel = key.slice(key.lastIndexOf(':') + 1);
673
+ for (const e of emitSites)
674
+ for (const h of handlerSites) {
675
+ if (e.nodeId === h.nodeId)
676
+ continue;
677
+ const dedupe = `${e.nodeId}>${h.nodeId}`;
678
+ if (seen.has(dedupe))
679
+ continue;
680
+ seen.add(dedupe);
681
+ edges.push({
682
+ source: e.nodeId, target: h.nodeId, kind: 'calls', line: e.line,
683
+ provenance: 'heuristic',
684
+ metadata: { synthesizedBy: 'arkui-emitter', event: eventLabel, registeredAt: `${h.file}:${h.line}` },
685
+ });
686
+ }
687
+ }
688
+ return edges;
689
+ }
690
+ /** `router.pushUrl({ url: 'pages/Detail' })` / replaceUrl — literal urls only. */
691
+ const ARKUI_ROUTER_RE = /\brouter\s*\.\s*(?:pushUrl|replaceUrl)\s*\(\s*\{[^)]{0,200}?\burl\s*:\s*['"]([\w\-./]+)['"]/g;
692
+ /**
693
+ * Phase 4b-ets3: HarmonyOS page navigation. `router.pushUrl({ url:
694
+ * 'pages/Detail' })` reaches the `@Entry struct` of
695
+ * `<module>/src/main/ets/pages/Detail.ets`, but the hop is a string — no
696
+ * static edge — so "tap → openDetail → ???" ends at the router call. Bridge
697
+ * literal urls to the page struct: the url resolves against the standard
698
+ * `src/main/ets/` layout (what main_pages.json entries name); candidates
699
+ * prefer the caller's own workspace module (routes are module-scoped), and
700
+ * anything still ambiguous is dropped rather than guessed. Only `@Entry`
701
+ * structs qualify as targets — the decorator is what makes a file a page.
702
+ */
703
+ async function arkuiRouterEdges(ctx, onYield) {
704
+ const edges = [];
705
+ const seen = new Set();
706
+ const allFiles = ctx.getAllFiles();
707
+ const moduleDirs = (() => {
708
+ const ws = ctx.getWorkspacePackages?.();
709
+ return ws ? [...new Set(ws.byName.values())].sort((a, b) => b.length - a.length) : [];
710
+ })();
711
+ const moduleScopeOf = (file) => {
712
+ for (const dir of moduleDirs) {
713
+ if (file === dir || file.startsWith(dir + '/'))
714
+ return dir;
715
+ }
716
+ return '';
717
+ };
718
+ let scannedFiles = 0;
719
+ for (const file of allFiles) {
720
+ if ((++scannedFiles & 15) === 0)
721
+ await onYield();
722
+ if (!file.endsWith('.ets'))
723
+ continue;
724
+ const content = ctx.readFile(file);
725
+ if (!content || !content.includes('router.'))
726
+ continue;
727
+ const safe = (0, strip_comments_1.stripCommentsForRegex)(content, 'typescript');
728
+ const nodes = ctx.getNodesInFile(file)
729
+ .filter((n) => n.kind === 'method' || n.kind === 'function');
730
+ ARKUI_ROUTER_RE.lastIndex = 0;
731
+ let m;
732
+ while ((m = ARKUI_ROUTER_RE.exec(safe))) {
733
+ const url = m[1];
734
+ const line = safe.slice(0, m.index).split('\n').length;
735
+ const encl = nodes
736
+ .filter((n) => n.startLine <= line && n.endLine >= line)
737
+ .sort((a, b) => (a.endLine - a.startLine) - (b.endLine - b.startLine))[0];
738
+ if (!encl)
739
+ continue;
740
+ const suffix = `/src/main/ets/${url}.ets`;
741
+ let candidates = allFiles.filter((f) => f.endsWith(suffix));
742
+ if (candidates.length > 1) {
743
+ const scope = moduleScopeOf(file);
744
+ const sameModule = candidates.filter((f) => moduleScopeOf(f) === scope);
745
+ if (sameModule.length > 0)
746
+ candidates = sameModule;
747
+ }
748
+ if (candidates.length !== 1)
749
+ continue; // ambiguous or unresolved — never guess
750
+ const page = ctx.getNodesInFile(candidates[0]).find((n) => n.kind === 'struct' && (n.decorators ?? []).includes('Entry'));
751
+ if (!page)
752
+ continue;
753
+ const key = `${encl.id}>${page.id}`;
754
+ if (seen.has(key))
755
+ continue;
756
+ seen.add(key);
757
+ edges.push({
758
+ source: encl.id, target: page.id, kind: 'calls', line,
759
+ provenance: 'heuristic',
760
+ metadata: { synthesizedBy: 'arkui-route', event: url, registeredAt: `${candidates[0]}:${page.startLine}` },
761
+ });
762
+ }
763
+ }
764
+ return edges;
765
+ }
766
+ /**
767
+ * Phase 4c: C++ virtual override. A call through a base/interface pointer
768
+ * (`db->Get(...)`, `iter->Next()`) dispatches at runtime to a subclass override,
769
+ * but that hop is a vtable indirection — no static call edge — so a flow stops at
770
+ * the abstract base method. Bridge it like react-render: for each C++ class that
771
+ * `extends` a base, link each base method → the subclass method of the same name
772
+ * (the override), so trace/callees from the interface method reach the
773
+ * implementation(s). Over-approximation accepted (reachability-correct); capped
774
+ * per class and gated to C++ to avoid touching other languages' dispatch.
775
+ */
776
+ async function cppOverrideEdges(queries, onYield) {
777
+ let scanned255 = 0;
778
+ const edges = [];
779
+ const seen = new Set();
780
+ const methodsOf = (classId) => queries
781
+ .getOutgoingEdges(classId, ['contains'])
782
+ .map((e) => queries.getNodeById(e.target))
783
+ .filter((n) => !!n && n.kind === 'method');
784
+ for (const cls of queries.iterateNodesByKind('class')) {
785
+ if ((++scanned255 & 63) === 0)
786
+ await onYield();
787
+ const subMethods = methodsOf(cls.id).filter((n) => n.language === 'cpp');
788
+ if (subMethods.length === 0)
789
+ continue;
790
+ for (const ext of queries.getOutgoingEdges(cls.id, ['extends'])) {
791
+ const base = queries.getNodeById(ext.target);
792
+ if (!base || base.language !== 'cpp' || base.id === cls.id)
793
+ continue;
794
+ const baseMethods = new Map(methodsOf(base.id).map((m) => [m.name, m]));
795
+ let added = 0;
796
+ for (const m of subMethods) {
797
+ if (added >= MAX_CALLBACKS_PER_CHANNEL)
798
+ break;
799
+ const bm = baseMethods.get(m.name);
800
+ if (!bm || bm.id === m.id)
801
+ continue;
802
+ const key = `${bm.id}>${m.id}`;
803
+ if (seen.has(key))
804
+ continue;
805
+ seen.add(key);
806
+ edges.push({
807
+ source: bm.id,
808
+ target: m.id,
809
+ kind: 'calls',
810
+ line: bm.startLine,
811
+ provenance: 'heuristic',
812
+ metadata: { synthesizedBy: 'cpp-override', via: m.name, registeredAt: `${m.filePath}:${m.startLine}` },
813
+ });
814
+ added++;
815
+ }
816
+ }
817
+ }
818
+ return edges;
819
+ }
820
+ /**
821
+ * Phase 5.5: interface / abstract dispatch (Java, Kotlin). A call through an
822
+ * injected interface (`@Autowired FooService svc; svc.list()`) or an abstract
823
+ * base dispatches at runtime to the implementing class's override — a vtable
824
+ * indirection with no static call edge — so a request→service flow stops at the
825
+ * interface method. Bridge it like cpp-override: for each class that
826
+ * `implements` an interface (or `extends` an abstract base), link each
827
+ * base/interface method → the class's same-name method (the override) so
828
+ * trace/callees reach the implementation. Over-approximation accepted
829
+ * (reachability-correct); capped per class, gated to JVM languages.
830
+ */
831
+ // Languages whose static `implements`/`extends` edges should bridge an
832
+ // interface (or abstract base) method to the matching concrete-class method.
833
+ // The set is "languages with explicit nominal subtyping and a single class
834
+ // kind that holds methods" — i.e. the shape this loop expects. Swift and
835
+ // Scala fit shape-wise (Swift `protocol`/`class`, Scala `trait`/`class`)
836
+ // and are added below; their concrete-side nodes can be a `struct` (Swift)
837
+ // or an `object` (Scala) so the loop also iterates those kinds.
838
+ const IFACE_OVERRIDE_LANGS = new Set([
839
+ 'java', 'kotlin', 'csharp', 'typescript', 'javascript', 'swift', 'scala', 'go', 'rust',
840
+ 'arkts',
841
+ ]);
842
+ /**
843
+ * Go implicit interface satisfaction (#584). Go has no `implements` keyword — a
844
+ * struct satisfies an interface structurally when its method set covers the
845
+ * interface's. Synthesize the missing `implements` edge (struct → interface) by
846
+ * matching method-NAME sets, so impl-navigation works and the interface-dispatch
847
+ * bridge ({@link interfaceOverrideEdges}, now 'go'-enabled) can link an interface
848
+ * method call to the concrete overrides.
849
+ *
850
+ * Name-only matching (signatures ignored) — over-approximation accepted, in line
851
+ * with the other dispatch synthesizers; capped per interface. Empty interfaces
852
+ * (`any`) are skipped so they don't match every struct.
853
+ */
854
+ async function goImplementsEdges(queries, onYield) {
855
+ let scanned255 = 0;
856
+ const edges = [];
857
+ const seen = new Set();
858
+ const methodNameSet = (id) => new Set(queries
859
+ .getOutgoingEdges(id, ['contains'])
860
+ .map((e) => queries.getNodeById(e.target))
861
+ .filter((n) => !!n && n.kind === 'method')
862
+ .map((n) => n.name));
863
+ // Materializes GO structs only (the pass is language-gated by the caller),
864
+ // never the whole struct kind — that array is O(nodes) on struct-heavy
865
+ // repos like the Linux kernel (#1212).
866
+ const goStructs = [];
867
+ for (const s of queries.iterateNodesByKind('struct')) {
868
+ if ((++scanned255 & 63) === 0)
869
+ await onYield();
870
+ if (s.language === 'go')
871
+ goStructs.push(s);
872
+ }
873
+ const structMethods = new Map();
874
+ for (const s of goStructs)
875
+ structMethods.set(s.id, methodNameSet(s.id));
876
+ for (const iface of queries.iterateNodesByKind('interface')) {
877
+ if ((++scanned255 & 63) === 0)
878
+ await onYield();
879
+ if ((++scanned255 & 63) === 0)
880
+ await onYield();
881
+ if (iface.language !== 'go')
882
+ continue;
883
+ const want = methodNameSet(iface.id);
884
+ if (want.size === 0)
885
+ continue; // empty interface (`any`) — would match everything
886
+ let added = 0;
887
+ for (const s of goStructs) {
888
+ if (added >= MAX_CALLBACKS_PER_CHANNEL)
889
+ break;
890
+ const have = structMethods.get(s.id);
891
+ if (!have || have.size < want.size)
892
+ continue;
893
+ let all = true;
894
+ for (const m of want) {
895
+ if (!have.has(m)) {
896
+ all = false;
897
+ break;
898
+ }
899
+ }
900
+ if (!all)
901
+ continue;
902
+ const key = `${s.id}>${iface.id}`;
903
+ if (seen.has(key))
904
+ continue;
905
+ seen.add(key);
906
+ edges.push({
907
+ source: s.id,
908
+ target: iface.id,
909
+ kind: 'implements',
910
+ line: s.startLine,
911
+ provenance: 'heuristic',
912
+ metadata: { synthesizedBy: 'go-implements', via: iface.name, registeredAt: `${s.filePath}:${s.startLine}` },
913
+ });
914
+ added++;
915
+ }
916
+ }
917
+ return edges;
918
+ }
919
+ /**
920
+ * Cross-file Go method → receiver-type `contains` edges. In Go a type's methods
921
+ * are commonly declared in a different file from the `type` declaration itself
922
+ * (`type User struct{…}` in `user.go`, `func (u *User) Save()` in
923
+ * `user_store.go`). Extraction attaches the struct→method `contains` edge only
924
+ * when the receiver type is in the SAME file — the owner lookup in
925
+ * `tree-sitter.ts` is scoped to the file being parsed — so a cross-file method
926
+ * is left orphaned from its type (it's still `contains`ed by its file, just not
927
+ * its struct). That breaks `codegraph_node` member outlines, any
928
+ * callers/callees/impact traversal that goes through the type's `contains`
929
+ * edges, and the {@link goImplementsEdges} method-set computation (which derives
930
+ * a struct's method set from those same edges, so it under-counts interfaces a
931
+ * cross-file struct satisfies).
932
+ *
933
+ * Go guarantees a method's receiver type is declared in the SAME PACKAGE as the
934
+ * method, and a Go package is a single directory — so this is a deterministic
935
+ * structural link, not a heuristic: find the same-named type in the method's own
936
+ * directory and add the missing `contains` edge (no `provenance: 'heuristic'`,
937
+ * matching the same-file edges extraction already emits). Skips methods that
938
+ * already have a type parent (the same-file case). (#583, cross-file half)
939
+ */
940
+ async function goCrossFileMethodContainsEdges(queries, onYield) {
941
+ let scanned255 = 0;
942
+ const edges = [];
943
+ const seen = new Set();
944
+ const TYPE_KINDS = new Set(['struct', 'class', 'interface', 'enum', 'type_alias']);
945
+ const dirOf = (p) => {
946
+ const i = p.replace(/\\/g, '/').lastIndexOf('/');
947
+ return i >= 0 ? p.slice(0, i) : '';
948
+ };
949
+ for (const method of queries.iterateNodesByKind('method')) {
950
+ if ((++scanned255 & 63) === 0)
951
+ await onYield();
952
+ if ((++scanned255 & 63) === 0)
953
+ await onYield();
954
+ if (method.language !== 'go')
955
+ continue;
956
+ // The receiver type is encoded in the method's qualifiedName as `Recv::name`
957
+ // (extraction sets `${receiverType}::${name}` for receiver methods).
958
+ const qn = method.qualifiedName;
959
+ if (!qn)
960
+ continue;
961
+ const sep = qn.lastIndexOf('::');
962
+ if (sep <= 0)
963
+ continue;
964
+ const receiver = qn.slice(0, sep);
965
+ if (!receiver)
966
+ continue;
967
+ // Already attached to its type (same-file case handled at extraction)?
968
+ const hasTypeParent = queries
969
+ .getIncomingEdges(method.id, ['contains'])
970
+ .some((e) => {
971
+ const src = queries.getNodeById(e.source);
972
+ return src != null && TYPE_KINDS.has(src.kind);
973
+ });
974
+ if (hasTypeParent)
975
+ continue;
976
+ // Find the receiver type in the SAME directory (= same Go package). Go forbids
977
+ // duplicate type names within a package, so a same-name same-dir match is
978
+ // unambiguous; scoping to the directory avoids linking to a same-named type
979
+ // in another package.
980
+ const dir = dirOf(method.filePath);
981
+ const owner = queries
982
+ .getNodesByName(receiver)
983
+ .find((n) => n.language === 'go' && TYPE_KINDS.has(n.kind) && dirOf(n.filePath) === dir);
984
+ if (!owner)
985
+ continue;
986
+ const key = `${owner.id}>${method.id}`;
987
+ if (seen.has(key))
988
+ continue;
989
+ seen.add(key);
990
+ edges.push({ source: owner.id, target: method.id, kind: 'contains', line: method.startLine });
991
+ }
992
+ return edges;
993
+ }
994
+ /**
995
+ * Kotlin Multiplatform `expect`/`actual` linking. A `common` source set declares
996
+ * `expect fun foo()` / `expect class Bar`; each platform source set (jvm, native,
997
+ * js, …) provides an `actual` implementation with the IDENTICAL fully-qualified
998
+ * name in a different file. Callers in common code resolve to the `expect`
999
+ * declaration, so every `actual` impl ends up with zero dependents — invisible to
1000
+ * impact/affected even though editing it can break every caller of the API.
1001
+ *
1002
+ * Synthesize a `calls` edge from the common declaration to each platform `actual`
1003
+ * (mirroring the interface-impl bridge: abstract → concrete), so editing a
1004
+ * platform impl surfaces the common `expect` and its callers, and the impl file
1005
+ * participates in the graph.
1006
+ *
1007
+ * `expect`/`actual` are captured onto the node's `decorators` list at extraction
1008
+ * (kotlin.ts `extractModifiers`). Members of an `expect class` are NOT themselves
1009
+ * keyword-marked, so the declaration side is matched as the same-FQN, same-kind
1010
+ * node that is NOT marked `actual`. Requiring an `actual`-marked counterpart also
1011
+ * gates out plain cross-file overloads (neither side is marked).
1012
+ */
1013
+ // Kinds that an `expect`/`actual` pair may legitimately straddle. `expect class`
1014
+ // is routinely fulfilled by an `actual typealias` (e.g. `actual typealias
1015
+ // CancellationException = …`, `actual typealias SchedulerTask = Task`), so a
1016
+ // strict kind match would miss those one-line alias files. Same-FQN + the
1017
+ // `actual` marker already gates out unrelated symbols, so widening to the
1018
+ // type-like kinds is safe.
1019
+ const KMP_TYPE_KINDS = new Set(['class', 'interface', 'struct', 'enum', 'type_alias']);
1020
+ function kmpKindsCompatible(a, b) {
1021
+ return a === b || (KMP_TYPE_KINDS.has(a) && KMP_TYPE_KINDS.has(b));
1022
+ }
1023
+ async function kotlinExpectActualEdges(queries, onYield) {
1024
+ let scanned255 = 0;
1025
+ const edges = [];
1026
+ const seen = new Set();
1027
+ // SQL-side language+decorator pre-filter, streamed. The old
1028
+ // `getAllNodes().filter(...)` hydrated the ENTIRE node table into one array
1029
+ // just to find kotlin `actual` declarations — on a 2M-node graph that alone
1030
+ // exceeded Node's default heap and killed the index (#1212). The LIKE
1031
+ // pre-filter can over-match (substring), so the exact decorator check stays.
1032
+ for (const act of queries.iterateNodesByLanguageWithDecorator('kotlin', 'actual')) {
1033
+ if ((++scanned255 & 63) === 0)
1034
+ await onYield();
1035
+ if (!act.decorators?.includes('actual'))
1036
+ continue;
1037
+ let added = 0;
1038
+ for (const cand of queries.getNodesByQualifiedNameExact(act.qualifiedName)) {
1039
+ if (added >= MAX_CALLBACKS_PER_CHANNEL)
1040
+ break;
1041
+ // The declaration side: same FQN + compatible kind, a different file, NOT
1042
+ // itself an `actual` (that would be a sibling platform impl, not the decl).
1043
+ if (cand.language !== 'kotlin' || cand.id === act.id)
1044
+ continue;
1045
+ if (!kmpKindsCompatible(cand.kind, act.kind) || cand.filePath === act.filePath)
1046
+ continue;
1047
+ if (cand.decorators?.includes('actual'))
1048
+ continue;
1049
+ const key = `${cand.id}>${act.id}`;
1050
+ if (seen.has(key))
1051
+ continue;
1052
+ seen.add(key);
1053
+ edges.push({
1054
+ source: cand.id,
1055
+ target: act.id,
1056
+ kind: 'calls',
1057
+ line: cand.startLine,
1058
+ provenance: 'heuristic',
1059
+ metadata: {
1060
+ synthesizedBy: 'kotlin-expect-actual',
1061
+ via: act.name,
1062
+ registeredAt: `${act.filePath}:${act.startLine}`,
1063
+ },
1064
+ });
1065
+ added++;
1066
+ }
1067
+ }
1068
+ return edges;
1069
+ }
1070
+ async function interfaceOverrideEdges(queries, onYield) {
1071
+ let scanned255 = 0;
1072
+ const edges = [];
1073
+ const seen = new Set();
1074
+ const methodsOf = (classId) => queries
1075
+ .getOutgoingEdges(classId, ['contains'])
1076
+ .map((e) => queries.getNodeById(e.target))
1077
+ .filter((n) => !!n && n.kind === 'method');
1078
+ // Concrete-side kinds vary by language: `class` covers Java / Kotlin /
1079
+ // C# / TS / Swift-classes / Scala-classes; `struct` covers Swift value
1080
+ // types that conform to protocols. Iterate both.
1081
+ const concreteKinds = ['class', 'struct'];
1082
+ for (const kind of concreteKinds) {
1083
+ for (const cls of queries.iterateNodesByKind(kind)) {
1084
+ if ((++scanned255 & 63) === 0)
1085
+ await onYield();
1086
+ const implMethods = methodsOf(cls.id).filter((n) => IFACE_OVERRIDE_LANGS.has(n.language));
1087
+ if (implMethods.length === 0)
1088
+ continue;
1089
+ for (const sup of queries.getOutgoingEdges(cls.id, ['implements', 'extends'])) {
1090
+ const base = queries.getNodeById(sup.target);
1091
+ if (!base || !IFACE_OVERRIDE_LANGS.has(base.language) || base.id === cls.id)
1092
+ continue;
1093
+ // Group impl methods by name to handle OVERLOADS: an interface `list()` and
1094
+ // `list(params)` are distinct nodes and a call may resolve to either, so
1095
+ // link every base overload → every same-name impl overload (keying by name
1096
+ // alone would drop all but one and miss the resolved overload).
1097
+ const implByName = new Map();
1098
+ for (const m of implMethods) {
1099
+ const arr = implByName.get(m.name);
1100
+ if (arr)
1101
+ arr.push(m);
1102
+ else
1103
+ implByName.set(m.name, [m]);
1104
+ }
1105
+ let added = 0;
1106
+ for (const bm of methodsOf(base.id)) {
1107
+ if (added >= MAX_CALLBACKS_PER_CHANNEL)
1108
+ break;
1109
+ for (const m of implByName.get(bm.name) ?? []) {
1110
+ if (added >= MAX_CALLBACKS_PER_CHANNEL)
1111
+ break;
1112
+ if (bm.id === m.id)
1113
+ continue;
1114
+ const key = `${bm.id}>${m.id}`;
1115
+ if (seen.has(key))
1116
+ continue;
1117
+ seen.add(key);
1118
+ edges.push({
1119
+ source: bm.id,
1120
+ target: m.id,
1121
+ kind: 'calls',
1122
+ line: bm.startLine,
1123
+ provenance: 'heuristic',
1124
+ metadata: { synthesizedBy: 'interface-impl', via: m.name, registeredAt: `${m.filePath}:${m.startLine}` },
1125
+ });
1126
+ added++;
1127
+ }
1128
+ }
1129
+ }
1130
+ }
1131
+ }
1132
+ return edges;
1133
+ }
1134
+ /**
1135
+ * Go gRPC stub → impl bridge. The protoc-gen-go-grpc codegen emits an
1136
+ * `UnimplementedXxxServer` struct in `*_grpc.pb.go` carrying one method
1137
+ * per service RPC; the real handler is a hand-written struct in another
1138
+ * file (`x/bank/keeper/msg_server.go::msgServer.Send` in cosmos-sdk).
1139
+ * Go's structural typing means no `implements` edge exists for our
1140
+ * resolver to follow, so `trace("Send","SendCoins")` lands on the
1141
+ * empty stub and reports "no path" (validated empirically — the cosmos
1142
+ * Q1 r1 trace failure that drove this work).
1143
+ *
1144
+ * Bridge: for each `UnimplementedXxxServer` whose RPC-method names are
1145
+ * a SUBSET of some other Go struct's method names, emit `calls` edges
1146
+ * `stub.method → impl.method` (paired by name). Excludes the gRPC
1147
+ * internal markers `mustEmbedUnimplementedXxxServer` and
1148
+ * `testEmbeddedByValue`, and skips candidate impls that themselves
1149
+ * live in a generated file (their `xxxClient` / sibling stubs would
1150
+ * otherwise look like impls).
1151
+ *
1152
+ * Multiple candidates is allowed and capped at MAX_CALLBACKS_PER_CHANNEL —
1153
+ * a service often has both a production impl and one or more test
1154
+ * mocks; linking to all preserves trace utility without false-favoring.
1155
+ *
1156
+ * Provenance: `heuristic`, `synthesizedBy: 'go-grpc-stub-impl'`. The
1157
+ * stub's source line is the wiring site shown in the trace trail.
1158
+ */
1159
+ async function goGrpcStubImplEdges(queries, onYield) {
1160
+ let scanned255 = 0;
1161
+ const edges = [];
1162
+ const seen = new Set();
1163
+ const STUB_RE = /^Unimplemented.*Server$/;
1164
+ // gRPC internal-helper methods that appear on every Unimplemented*Server;
1165
+ // not part of the service contract, so exclude when computing the RPC-method
1166
+ // signature used to match impls.
1167
+ const isInternalMarker = (n) => n.startsWith('mustEmbed') || n === 'testEmbeddedByValue';
1168
+ // Methods directly contained by each Go struct, name-only. Built once.
1169
+ const methodNamesByStruct = new Map();
1170
+ const methodNodesByStruct = new Map();
1171
+ const goStructs = [];
1172
+ for (const s of queries.iterateNodesByKind('struct')) {
1173
+ if ((++scanned255 & 63) === 0)
1174
+ await onYield();
1175
+ if (s.language !== 'go')
1176
+ continue;
1177
+ goStructs.push(s);
1178
+ const ms = queries
1179
+ .getOutgoingEdges(s.id, ['contains'])
1180
+ .map((e) => queries.getNodeById(e.target))
1181
+ .filter((n) => !!n && n.kind === 'method');
1182
+ methodNodesByStruct.set(s.id, ms);
1183
+ methodNamesByStruct.set(s.id, new Set(ms.map((m) => m.name)));
1184
+ }
1185
+ for (const stub of goStructs) {
1186
+ if (!STUB_RE.test(stub.name))
1187
+ continue;
1188
+ // The stub MUST live in a generated file — that's what tells us this is
1189
+ // a protoc-emitted scaffold rather than someone naming a struct
1190
+ // `UnimplementedXxxServer` by hand. Without this gate we'd also bridge
1191
+ // such hand-written structs and create misleading edges.
1192
+ if (!(0, generated_detection_1.isGeneratedFile)(stub.filePath))
1193
+ continue;
1194
+ const stubMethods = (methodNodesByStruct.get(stub.id) ?? []).filter((m) => !isInternalMarker(m.name));
1195
+ if (stubMethods.length === 0)
1196
+ continue;
1197
+ const stubMethodNames = stubMethods.map((m) => m.name);
1198
+ for (const cand of goStructs) {
1199
+ if (cand.id === stub.id)
1200
+ continue;
1201
+ // Skip generated-file candidates — they're siblings (msgClient,
1202
+ // UnsafeMsgServer, …) whose method sets coincidentally match.
1203
+ if ((0, generated_detection_1.isGeneratedFile)(cand.filePath))
1204
+ continue;
1205
+ const candNames = methodNamesByStruct.get(cand.id);
1206
+ if (!candNames)
1207
+ continue;
1208
+ // Subset: every RPC method must exist on the candidate by name.
1209
+ // Signature-level match would tighten this further, but name-match
1210
+ // alone already gives one-to-one pairing in real codebases because
1211
+ // gRPC method-name sets are highly distinctive (Send + MultiSend +
1212
+ // UpdateParams + SetSendEnabled is unique to bank's MsgServer).
1213
+ if (!stubMethodNames.every((n) => candNames.has(n)))
1214
+ continue;
1215
+ const candMethods = methodNodesByStruct.get(cand.id) ?? [];
1216
+ let added = 0;
1217
+ for (const sm of stubMethods) {
1218
+ if (added >= MAX_CALLBACKS_PER_CHANNEL)
1219
+ break;
1220
+ for (const cm of candMethods) {
1221
+ if (added >= MAX_CALLBACKS_PER_CHANNEL)
1222
+ break;
1223
+ if (cm.name !== sm.name)
1224
+ continue;
1225
+ const key = `${sm.id}>${cm.id}`;
1226
+ if (seen.has(key))
1227
+ continue;
1228
+ seen.add(key);
1229
+ edges.push({
1230
+ source: sm.id,
1231
+ target: cm.id,
1232
+ kind: 'calls',
1233
+ line: sm.startLine,
1234
+ provenance: 'heuristic',
1235
+ metadata: {
1236
+ synthesizedBy: 'go-grpc-stub-impl',
1237
+ via: cm.name,
1238
+ registeredAt: `${cm.filePath}:${cm.startLine}`,
1239
+ },
1240
+ });
1241
+ added++;
1242
+ }
1243
+ }
1244
+ }
1245
+ }
1246
+ return edges;
1247
+ }
1248
+ /**
1249
+ * Phase 5: React JSX child rendering. A component that returns `<Child .../>`
1250
+ * mounts Child — React calls it — but JSX instantiation isn't a static call edge,
1251
+ * so a render tree (App.render → StaticCanvas → renderStaticScene) breaks at the
1252
+ * JSX hop. Link parent → each capitalized JSX child it renders. File-oriented
1253
+ * (read each JSX file once). Precision gate: the child name must resolve to a
1254
+ * component/function/class node — TS generics like `Array<Foo>` resolve to a type
1255
+ * (or nothing) and are dropped.
1256
+ */
1257
+ async function reactJsxChildEdges(ctx, onYield) {
1258
+ let scannedFiles = 0;
1259
+ const edges = [];
1260
+ const seen = new Set();
1261
+ const PARENT_KINDS = new Set(['method', 'function', 'component']);
1262
+ let scanned = 0;
1263
+ for (const file of ctx.getAllFiles()) {
1264
+ if ((++scannedFiles & 15) === 0)
1265
+ await onYield();
1266
+ if ((++scanned & 255) === 0)
1267
+ await onYield(); // #1091: yield mid-scan on huge graphs
1268
+ const content = ctx.readFile(file);
1269
+ if (!content || (!content.includes('</') && !content.includes('/>')))
1270
+ continue; // JSX-file gate
1271
+ const parents = ctx.getNodesInFile(file).filter((n) => PARENT_KINDS.has(n.kind));
1272
+ for (const parent of parents) {
1273
+ const src = sliceLines(content, parent.startLine, parent.endLine);
1274
+ if (!src || (!src.includes('</') && !src.includes('/>')))
1275
+ continue;
1276
+ const names = new Set();
1277
+ JSX_TAG_RE.lastIndex = 0;
1278
+ let m;
1279
+ while ((m = JSX_TAG_RE.exec(src)))
1280
+ names.add(m[1]);
1281
+ let added = 0;
1282
+ for (const name of names) {
1283
+ if (added >= MAX_JSX_CHILDREN)
1284
+ break;
1285
+ const child = ctx.getNodesByName(name).find((n) => n.kind === 'component' || n.kind === 'function' || n.kind === 'class');
1286
+ if (!child || child.id === parent.id)
1287
+ continue;
1288
+ const key = `${parent.id}>${child.id}`;
1289
+ if (seen.has(key))
1290
+ continue;
1291
+ seen.add(key);
1292
+ edges.push({
1293
+ source: parent.id, target: child.id, kind: 'calls', line: parent.startLine,
1294
+ provenance: 'heuristic',
1295
+ metadata: { synthesizedBy: 'jsx-render', via: name },
1296
+ });
1297
+ added++;
1298
+ }
1299
+ }
1300
+ }
1301
+ return edges;
1302
+ }
1303
+ /**
1304
+ * Phase 6: Vue SFC templates. The `.vue` extractor only parses `<script>`, so
1305
+ * template usage is invisible — child components and event handlers used ONLY in
1306
+ * the template have no edge to them. PascalCase children (`<VPNav/>`) are already
1307
+ * caught by reactJsxChildEdges (which scans the SFC component node), so this adds
1308
+ * the two Vue-specific shapes:
1309
+ * - kebab-case children: `<el-button>` → `ElButton` component (renders).
1310
+ * - event bindings: `@click="onClick"` / `v-on:submit="save"` → handler method.
1311
+ * Scoped to the `<template>` block of `.vue` files; resolution gate (kebab→
1312
+ * component, handler→function/method) keeps precision; inline arrows / `$emit`
1313
+ * skipped.
1314
+ */
1315
+ async function vueTemplateEdges(ctx, onYield) {
1316
+ let scannedFiles = 0;
1317
+ let scanned255 = 0;
1318
+ const edges = [];
1319
+ const seen = new Set();
1320
+ const COMPONENT_KINDS = new Set(['component', 'function', 'class']);
1321
+ const HANDLER_KINDS = new Set(['method', 'function']);
1322
+ // A composable's returned member may be a fn (`function close(){}`) or an
1323
+ // arrow assigned to a const (`const close = () => {}`).
1324
+ const RETURN_KINDS = new Set(['method', 'function', 'variable', 'constant']);
1325
+ // Nuxt auto-imports nested components by a DIRECTORY-PREFIXED name —
1326
+ // `components/media/Card.vue` is used as `<MediaCard/>`, not `<Card/>` — but
1327
+ // the component node is named by basename (`Card`), so a direct tag match
1328
+ // misses it (flat components match by basename and don't need this). Map each
1329
+ // nested component's Nuxt name → node so those template usages resolve.
1330
+ const nuxtComponents = new Map();
1331
+ for (const c of (ctx.iterateNodesByKind?.('component') ?? ctx.getNodesByKind('component'))) {
1332
+ if ((++scanned255 & 63) === 0)
1333
+ await onYield();
1334
+ const nn = nuxtComponentName(c.filePath);
1335
+ if (nn && !nuxtComponents.has(nn))
1336
+ nuxtComponents.set(nn, c);
1337
+ }
1338
+ for (const file of ctx.getAllFiles()) {
1339
+ if ((++scannedFiles & 15) === 0)
1340
+ await onYield();
1341
+ if (!file.endsWith('.vue'))
1342
+ continue;
1343
+ const content = ctx.readFile(file);
1344
+ const tpl = content && content.match(/<template[^>]*>([\s\S]*)<\/template>/i)?.[1];
1345
+ if (!tpl)
1346
+ continue;
1347
+ const comp = ctx.getNodesInFile(file).find((n) => n.kind === 'component');
1348
+ if (!comp)
1349
+ continue;
1350
+ // Composable-destructure map: alias → { composable, key }. Lets us resolve a
1351
+ // template handler that isn't a local function but a destructured composable
1352
+ // return (`@click="closeSidebar"` ← `const { close: closeSidebar } = useSidebarControl()`).
1353
+ const script = content.match(/<script[^>]*>([\s\S]*?)<\/script>/i)?.[1] ?? '';
1354
+ const destructured = new Map();
1355
+ VUE_DESTRUCTURE_RE.lastIndex = 0;
1356
+ let dm;
1357
+ while ((dm = VUE_DESTRUCTURE_RE.exec(script))) {
1358
+ if (!/^use[A-Z]/.test(dm[2]))
1359
+ continue; // composables / hooks only
1360
+ for (const part of dm[1].split(',')) {
1361
+ const pm = part.trim().match(/^(\w+)\s*(?::\s*(\w+))?$/); // key | key: alias
1362
+ if (pm)
1363
+ destructured.set(pm[2] || pm[1], { composable: dm[2], key: pm[1] });
1364
+ }
1365
+ }
1366
+ let added = 0;
1367
+ const addEdge = (target, meta) => {
1368
+ if (added >= MAX_JSX_CHILDREN || !target || target.id === comp.id)
1369
+ return;
1370
+ const k = `${comp.id}>${target.id}>${meta.synthesizedBy}`;
1371
+ if (seen.has(k))
1372
+ return;
1373
+ seen.add(k);
1374
+ edges.push({ source: comp.id, target: target.id, kind: 'calls', line: comp.startLine, provenance: 'heuristic', metadata: meta });
1375
+ added++;
1376
+ };
1377
+ // Prefer a target in THIS SFC (handlers live in the same file's script) —
1378
+ // avoids cross-file mis-match when a name repeats across a monorepo.
1379
+ const resolve = (name, kinds) => {
1380
+ const matches = ctx.getNodesByName(name).filter((n) => kinds.has(n.kind));
1381
+ return matches.find((n) => n.filePath === file) ?? matches[0];
1382
+ };
1383
+ let m;
1384
+ VUE_KEBAB_RE.lastIndex = 0;
1385
+ while ((m = VUE_KEBAB_RE.exec(tpl))) {
1386
+ const tag = kebabToPascal(m[1]);
1387
+ addEdge(resolve(tag, COMPONENT_KINDS) ?? nuxtComponents.get(tag), { synthesizedBy: 'jsx-render', via: m[1] });
1388
+ }
1389
+ // PascalCase component tags. Try a direct name match first (flat components
1390
+ // and explicit registrations), then the Nuxt dir-prefixed auto-import name
1391
+ // (`<MediaCard>` → components/media/Card.vue). Built-ins match neither → no edge.
1392
+ VUE_PASCAL_RE.lastIndex = 0;
1393
+ while ((m = VUE_PASCAL_RE.exec(tpl))) {
1394
+ const tag = m[1];
1395
+ addEdge(resolve(tag, COMPONENT_KINDS) ?? nuxtComponents.get(tag), { synthesizedBy: 'jsx-render', via: tag });
1396
+ }
1397
+ VUE_HANDLER_RE.lastIndex = 0;
1398
+ while ((m = VUE_HANDLER_RE.exec(tpl))) {
1399
+ const event = m[1];
1400
+ const expr = m[2].trim();
1401
+ if (expr.includes('=>') || expr.startsWith('$'))
1402
+ continue; // inline arrow / $emit
1403
+ const name = expr.match(/^([A-Za-z_]\w*)/)?.[1];
1404
+ if (!name)
1405
+ continue;
1406
+ const direct = resolve(name, HANDLER_KINDS);
1407
+ if (direct) {
1408
+ addEdge(direct, { synthesizedBy: 'vue-handler', event });
1409
+ continue;
1410
+ }
1411
+ // Composable-destructure handler → resolve to the composable's returned fn.
1412
+ const d = destructured.get(name);
1413
+ if (!d)
1414
+ continue;
1415
+ const composable = resolve(d.composable, HANDLER_KINDS);
1416
+ // Resolve to the SPECIFIC returned member (e.g. `close`) defined in the
1417
+ // composable's file. No fallback to the composable itself — the component
1418
+ // already has a static `useX()` call edge, so that would just be redundant
1419
+ // and less precise.
1420
+ const keyFn = composable
1421
+ ? ctx.getNodesByName(d.key).find((n) => RETURN_KINDS.has(n.kind) && n.filePath === composable.filePath)
1422
+ : undefined;
1423
+ if (keyFn)
1424
+ addEdge(keyFn, { synthesizedBy: 'vue-handler', event, via: d.composable });
1425
+ }
1426
+ }
1427
+ return edges;
1428
+ }
1429
+ /**
1430
+ * React Native cross-language event channel (Phase 3 of the mixed-iOS/RN
1431
+ * bridging effort). Same shape as `eventEmitterEdges` but cross-language:
1432
+ *
1433
+ * Native (ObjC, on RCTEventEmitter subclass):
1434
+ * [self sendEventWithName:@"locationUpdate" body:@{...}];
1435
+ *
1436
+ * Native (Java/Kotlin, via the JS module dispatcher):
1437
+ * emitter.emit("locationUpdate", body);
1438
+ * reactContext.getJSModule(RCTDeviceEventEmitter.class).emit("locationUpdate", body);
1439
+ *
1440
+ * JS (subscriber):
1441
+ * new NativeEventEmitter(NativeModules.Geo).addListener("locationUpdate", handler);
1442
+ * DeviceEventEmitter.addListener("locationUpdate", handler);
1443
+ *
1444
+ * Synthesize: native dispatch site → JS handler, keyed by the literal
1445
+ * event name. Only matches NAMED handlers (the existing `ON_RE` named-
1446
+ * capture form). Inline arrow handlers like `addListener('x', d => …)`
1447
+ * aren't named at extraction time and would need link-through-body
1448
+ * support; matches the deliberate scope of the in-language synthesizer.
1449
+ *
1450
+ * Provenance `'heuristic'`, synthesizedBy `'rn-event-channel'`.
1451
+ */
1452
+ // ObjC's `[self sendEventWithName:@"X" body:...]` shape (bracket syntax,
1453
+ // `@` string literals).
1454
+ const RN_OBJC_SEND_RE = /\bsendEventWithName\s*:\s*@"([^"]+)"/g;
1455
+ // Swift's `sendEvent(withName: "X", body: ...)` shape — same RCTEventEmitter
1456
+ // method, different call syntax. Both Objective-C and Swift subclass
1457
+ // RCTEventEmitter so this catches the Swift-side equivalent emission sites
1458
+ // (e.g. RNFusedLocation.swift's `sendEvent(withName: "geolocationDidChange",
1459
+ // body: locationData)`).
1460
+ const RN_SWIFT_SEND_RE = /\bsendEvent\s*\(\s*withName\s*:\s*"([^"]+)"/g;
1461
+ // JVM-side emitter calls: `emitter.emit("X", body)`. Matches both Java
1462
+ // and Kotlin syntax because the call form is identical. Restricted to
1463
+ // JVM source files in the consumer so we don't re-process JS emits
1464
+ // (which `eventEmitterEdges` already handles).
1465
+ const RN_JVM_EMIT_RE = /\.emit\s*\(\s*"([^"]+)"\s*,/g;
1466
+ // Custom `sendEvent(reactContext, "X", body)` wrapper — extremely common
1467
+ // (react-native-device-info and many libs wrap `DeviceEventManagerModule…emit`
1468
+ // behind a helper whose `.emit(eventName, …)` uses a VARIABLE, so RN_JVM_EMIT_RE
1469
+ // misses it; the literal lives in the wrapper CALL instead). Captures the first
1470
+ // string literal inside a `sendEvent(...)` call. `[^;{}]*?` keeps it on one
1471
+ // statement and stops at a block boundary, so the wrapper DEFINITION (whose `(`
1472
+ // is followed by `… ) {`) never matches. Multi-line tolerant. (java/kotlin/swift)
1473
+ const RN_NATIVE_SENDEVENT_RE = /\bsendEvent\s*\([^;{}]*?"([^"]+)"/g;
1474
+ async function rnEventEdges(ctx, onYield) {
1475
+ let scannedFiles = 0;
1476
+ // Native dispatchers (source = the native method whose body sends the
1477
+ // event) and JS handlers (target = the function/method registered as
1478
+ // the listener) keyed by event name.
1479
+ const nativeDispatchersByEvent = new Map();
1480
+ const jsHandlersByEvent = new Map();
1481
+ for (const file of ctx.getAllFiles()) {
1482
+ if ((++scannedFiles & 15) === 0)
1483
+ await onYield();
1484
+ const content = ctx.readFile(file);
1485
+ if (!content)
1486
+ continue;
1487
+ const nodesInFile = ctx.getNodesInFile(file);
1488
+ const lineOf = makeLineAt(content, 1);
1489
+ const addDispatcher = (event, line) => {
1490
+ const disp = enclosingFn(nodesInFile, line);
1491
+ if (!disp)
1492
+ return;
1493
+ const set = nativeDispatchersByEvent.get(event) ?? new Set();
1494
+ set.add(disp.id);
1495
+ nativeDispatchersByEvent.set(event, set);
1496
+ };
1497
+ // ObjC side: `sendEventWithName:@"X"` only fires inside `.m`/`.mm`
1498
+ // files (RCTEventEmitter subclasses).
1499
+ if (file.endsWith('.m') || file.endsWith('.mm')) {
1500
+ RN_OBJC_SEND_RE.lastIndex = 0;
1501
+ let m;
1502
+ while ((m = RN_OBJC_SEND_RE.exec(content))) {
1503
+ if (m[1])
1504
+ addDispatcher(m[1], lineOf(m.index));
1505
+ }
1506
+ }
1507
+ // Swift side: same RCTEventEmitter method, parens/named-args syntax.
1508
+ if (file.endsWith('.swift')) {
1509
+ RN_SWIFT_SEND_RE.lastIndex = 0;
1510
+ let m;
1511
+ while ((m = RN_SWIFT_SEND_RE.exec(content))) {
1512
+ if (m[1])
1513
+ addDispatcher(m[1], lineOf(m.index));
1514
+ }
1515
+ RN_NATIVE_SENDEVENT_RE.lastIndex = 0;
1516
+ while ((m = RN_NATIVE_SENDEVENT_RE.exec(content))) {
1517
+ if (m[1])
1518
+ addDispatcher(m[1], lineOf(m.index));
1519
+ }
1520
+ }
1521
+ // JVM side: `.emit("X", …)` in Java/Kotlin, plus the common
1522
+ // `sendEvent(ctx, "X", body)` wrapper. (We pattern-match anywhere in the
1523
+ // file; the JS in-language path uses a separate emitter object pattern and
1524
+ // is already handled by eventEmitterEdges.)
1525
+ if (file.endsWith('.java') || file.endsWith('.kt')) {
1526
+ let m;
1527
+ RN_JVM_EMIT_RE.lastIndex = 0;
1528
+ while ((m = RN_JVM_EMIT_RE.exec(content))) {
1529
+ if (m[1])
1530
+ addDispatcher(m[1], lineOf(m.index));
1531
+ }
1532
+ RN_NATIVE_SENDEVENT_RE.lastIndex = 0;
1533
+ while ((m = RN_NATIVE_SENDEVENT_RE.exec(content))) {
1534
+ if (m[1])
1535
+ addDispatcher(m[1], lineOf(m.index));
1536
+ }
1537
+ }
1538
+ // JS subscribers (.addListener("X", handler)). Restrict to JS-family
1539
+ // files so a native file's `addListener:` (the ObjC method) doesn't
1540
+ // get mistaken for a JS subscription — they're entirely different
1541
+ // things despite sharing a name.
1542
+ if (file.endsWith('.js') ||
1543
+ file.endsWith('.jsx') ||
1544
+ file.endsWith('.ts') ||
1545
+ file.endsWith('.tsx') ||
1546
+ file.endsWith('.mjs') ||
1547
+ file.endsWith('.cjs')) {
1548
+ // Match BOTH the named-handler form (`.addListener('x', fn)`) and
1549
+ // an unnamed-handler form (`.addListener('x', listener)` where
1550
+ // `listener` is a parameter — common in RN wrapper APIs like
1551
+ // RNFirebase's `messaging().onMessageReceived(listener)`). For the
1552
+ // unnamed case we attribute the subscription to the ENCLOSING JS
1553
+ // function (the abstraction layer), giving a reachability-correct
1554
+ // hop even when the actual user-side handler lives one call up.
1555
+ const ADDLISTENER_ANY = /\.(?:on|once|addListener)\(\s*['"]([^'"]+)['"]\s*,\s*([A-Za-z_][\w.]*)/g;
1556
+ ADDLISTENER_ANY.lastIndex = 0;
1557
+ let m;
1558
+ while ((m = ADDLISTENER_ANY.exec(content))) {
1559
+ const event = m[1];
1560
+ const arg = m[2];
1561
+ if (!event || !arg)
1562
+ continue;
1563
+ const bareName = arg.includes('.') ? arg.slice(arg.lastIndexOf('.') + 1) : arg;
1564
+ // Try a named-symbol match first (matches the in-language semantic).
1565
+ const namedHandler = ctx
1566
+ .getNodesByName(bareName)
1567
+ .find((n) => n.kind === 'function' || n.kind === 'method');
1568
+ let targetId = namedHandler?.id ?? null;
1569
+ if (!targetId) {
1570
+ // Fall back to the enclosing function — the subscribe-wrapper
1571
+ // pattern means the event fires THROUGH this function on its
1572
+ // way to user code. Reachability-correct attribution.
1573
+ const enclosing = enclosingFn(nodesInFile, lineOf(m.index));
1574
+ targetId = enclosing?.id ?? null;
1575
+ }
1576
+ if (!targetId) {
1577
+ // Broader fallback for JS object-literal API shape
1578
+ // (`const Foo = { watchX(...) { … addListener(...) … } }`):
1579
+ // method shorthand inside an object literal isn't extracted
1580
+ // as a method node, so enclosingFn returns null. Attribute to
1581
+ // the smallest enclosing `constant` / `variable` node — that's
1582
+ // the API surface a downstream caller would `import` and
1583
+ // invoke. Reachability-correct.
1584
+ const line = lineOf(m.index);
1585
+ let smallest = null;
1586
+ for (const n of nodesInFile) {
1587
+ if (n.kind !== 'constant' && n.kind !== 'variable')
1588
+ continue;
1589
+ const end = n.endLine ?? n.startLine;
1590
+ if (n.startLine <= line && end >= line) {
1591
+ if (!smallest || n.startLine >= smallest.startLine)
1592
+ smallest = n;
1593
+ }
1594
+ }
1595
+ targetId = smallest?.id ?? null;
1596
+ }
1597
+ if (!targetId)
1598
+ continue;
1599
+ const map = jsHandlersByEvent.get(event) ?? new Map();
1600
+ map.set(targetId, `${file}:${lineOf(m.index)}`);
1601
+ jsHandlersByEvent.set(event, map);
1602
+ }
1603
+ }
1604
+ }
1605
+ const edges = [];
1606
+ const seen = new Set();
1607
+ for (const [event, dispatchers] of nativeDispatchersByEvent) {
1608
+ const handlers = jsHandlersByEvent.get(event);
1609
+ if (!handlers)
1610
+ continue;
1611
+ // Same fan-out guard as the in-language channel: generic event names
1612
+ // (e.g. 'change', 'error', 'data') with many handlers/dispatchers
1613
+ // can't be matched precisely without receiver-type info.
1614
+ if (dispatchers.size > EVENT_FANOUT_CAP || handlers.size > EVENT_FANOUT_CAP)
1615
+ continue;
1616
+ for (const d of dispatchers) {
1617
+ for (const [h, registeredAt] of handlers) {
1618
+ if (d === h)
1619
+ continue;
1620
+ const key = `${d}>${h}`;
1621
+ if (seen.has(key))
1622
+ continue;
1623
+ seen.add(key);
1624
+ edges.push({
1625
+ source: d,
1626
+ target: h,
1627
+ kind: 'calls',
1628
+ provenance: 'heuristic',
1629
+ metadata: { synthesizedBy: 'rn-event-channel', event, registeredAt },
1630
+ });
1631
+ }
1632
+ }
1633
+ }
1634
+ return edges;
1635
+ }
1636
+ /**
1637
+ * Phase 6 — React Native Fabric/Codegen view component bridge.
1638
+ *
1639
+ * The Fabric framework extractor (`frameworks/fabric.ts`) emits
1640
+ * `component` nodes named after the JS-visible component (e.g.
1641
+ * `RNSScreenStack`) from each `codegenNativeComponent<Props>('Name')`
1642
+ * spec declaration. The native implementation lives in an ObjC++/.mm or
1643
+ * Kotlin/Java class whose name follows one of RN's conventions:
1644
+ *
1645
+ * - Exact: `RNSScreenStack`
1646
+ * - With suffix: `RNSScreenStackView`, `RNSScreenStackViewManager`,
1647
+ * `RNSScreenStackComponentView`, `RNSScreenStackManager`
1648
+ *
1649
+ * This synthesizer walks every Fabric component node and looks for a
1650
+ * native class matching one of those names; when found, emits a
1651
+ * `calls` edge `component → native class` (provenance `'heuristic'`,
1652
+ * `synthesizedBy:'fabric-native-impl'`) so trace from JSX usage of the
1653
+ * component continues into native.
1654
+ *
1655
+ * The convention-based suffix lookup is precise: there's no name
1656
+ * collision in RN view-manager codebases by design (Codegen output would
1657
+ * conflict otherwise).
1658
+ */
1659
+ const FABRIC_NATIVE_SUFFIXES = ['', 'View', 'ViewManager', 'ComponentView', 'Manager'];
1660
+ /**
1661
+ * Expo Modules cross-platform pairing. An Expo Module exposes the SAME
1662
+ * JS-visible method (`AsyncFunction("getBatteryLevelAsync")`) from BOTH an iOS
1663
+ * (Swift) and an Android (Kotlin) implementation. A JS callsite name-resolves to
1664
+ * only ONE of them, so the other platform's impl looked like nothing called it
1665
+ * (and editing it showed no blast radius). Link the iOS and Android impls of the
1666
+ * same `<module>.<method>` to each other (both directions), so a JS call that
1667
+ * reaches one platform reaches the other, and editing either surfaces the JS
1668
+ * caller. The Expo method nodes are id-prefixed `expo-module:` and qualified
1669
+ * `<file>::<module>.<method>` by the framework extractor.
1670
+ */
1671
+ async function expoCrossPlatformEdges(queries, onYield) {
1672
+ let scanned255 = 0;
1673
+ const edges = [];
1674
+ const seen = new Set();
1675
+ const byKey = new Map();
1676
+ for (const m of queries.iterateNodesByKind('method')) {
1677
+ if ((++scanned255 & 63) === 0)
1678
+ await onYield();
1679
+ if (!m.id.startsWith('expo-module:'))
1680
+ continue;
1681
+ const key = m.qualifiedName.split('::').pop(); // `<module>.<method>`
1682
+ if (!key)
1683
+ continue;
1684
+ const arr = byKey.get(key);
1685
+ if (arr)
1686
+ arr.push(m);
1687
+ else
1688
+ byKey.set(key, [m]);
1689
+ }
1690
+ for (const group of byKey.values()) {
1691
+ if (group.length < 2)
1692
+ continue;
1693
+ for (const a of group) {
1694
+ for (const b of group) {
1695
+ if (a.id === b.id || a.language === b.language)
1696
+ continue; // cross-platform only
1697
+ const key = `${a.id}>${b.id}`;
1698
+ if (seen.has(key))
1699
+ continue;
1700
+ seen.add(key);
1701
+ edges.push({
1702
+ source: a.id,
1703
+ target: b.id,
1704
+ kind: 'calls',
1705
+ line: a.startLine,
1706
+ provenance: 'heuristic',
1707
+ metadata: { synthesizedBy: 'expo-cross-platform', via: a.name },
1708
+ });
1709
+ }
1710
+ }
1711
+ }
1712
+ return edges;
1713
+ }
1714
+ /**
1715
+ * Classic React Native NativeModules cross-platform pairing. A native module
1716
+ * method (`@ReactMethod` on Android, `RCT_EXPORT_METHOD` on iOS) is implemented
1717
+ * on BOTH platforms, but a JS callsite name-resolves to only ONE — so the other
1718
+ * platform's impl looked like nothing called it. A native method that HAS a JS
1719
+ * caller is a confirmed bridge method; link it to the same-named native method
1720
+ * in another language (the other platform's impl) so a JS call reaching one
1721
+ * platform reaches the other, and editing either surfaces the JS caller.
1722
+ *
1723
+ * Names are normalized to the first selector keyword (`getFreeDiskStorage:` →
1724
+ * `getFreeDiskStorage`) — that's the JS-visible name, and how the iOS selector
1725
+ * lines up with the bare Android method name.
1726
+ */
1727
+ async function rnCrossPlatformEdges(queries, onYield) {
1728
+ let scanned255 = 0;
1729
+ const edges = [];
1730
+ const seen = new Set();
1731
+ const NATIVE = new Set(['java', 'kotlin', 'objc', 'cpp']);
1732
+ const JS = new Set(['typescript', 'tsx', 'javascript', 'jsx']);
1733
+ // RN module INFRASTRUCTURE methods exist on every native module (called by the
1734
+ // RN runtime, not user JS), so pairing them by name would cross-link unrelated
1735
+ // modules in a multi-module repo. Skip them — they aren't user-facing methods.
1736
+ const RN_INFRA = new Set([
1737
+ 'addListener', 'removeListeners', 'getConstants', 'constantsToExport', 'getName',
1738
+ 'invalidate', 'initialize', 'getDefaultEventTypes', 'supportedEvents',
1739
+ 'requiresMainQueueSetup', 'methodQueue',
1740
+ ]);
1741
+ const norm = (name) => {
1742
+ const i = name.indexOf(':');
1743
+ return i >= 0 ? name.slice(0, i) : name;
1744
+ };
1745
+ // Index native methods by their JS-visible (normalized) name. Only names with
1746
+ // impls in ≥2 native languages can pair, so the per-method JS-caller check
1747
+ // below only runs for genuine cross-platform candidates.
1748
+ const byName = new Map();
1749
+ for (const m of queries.iterateNodesByKind('method')) {
1750
+ if ((++scanned255 & 63) === 0)
1751
+ await onYield();
1752
+ if (!NATIVE.has(m.language))
1753
+ continue;
1754
+ const key = norm(m.name);
1755
+ const arr = byName.get(key);
1756
+ if (arr)
1757
+ arr.push(m);
1758
+ else
1759
+ byName.set(key, [m]);
1760
+ }
1761
+ for (const [groupName, group] of byName) {
1762
+ if (RN_INFRA.has(groupName))
1763
+ continue;
1764
+ const langs = new Set(group.map((m) => m.language));
1765
+ if (langs.size < 2)
1766
+ continue; // single-platform — nothing to pair
1767
+ for (const m of group) {
1768
+ // Is m a bridge method? (a JS-language `calls` edge points at it)
1769
+ const incoming = queries.getIncomingEdges(m.id, ['calls']);
1770
+ if (incoming.length === 0)
1771
+ continue;
1772
+ const sources = queries.getNodesByIds(incoming.map((e) => e.source));
1773
+ const isBridge = incoming.some((e) => {
1774
+ const s = sources.get(e.source);
1775
+ return !!s && JS.has(s.language);
1776
+ });
1777
+ if (!isBridge)
1778
+ continue;
1779
+ // Link to the other-platform impls (both directions).
1780
+ for (const sib of group) {
1781
+ if (sib.id === m.id || sib.language === m.language)
1782
+ continue;
1783
+ for (const [a, b] of [[m, sib], [sib, m]]) {
1784
+ const key = `${a.id}>${b.id}`;
1785
+ if (seen.has(key))
1786
+ continue;
1787
+ seen.add(key);
1788
+ edges.push({
1789
+ source: a.id,
1790
+ target: b.id,
1791
+ kind: 'calls',
1792
+ line: a.startLine,
1793
+ provenance: 'heuristic',
1794
+ metadata: { synthesizedBy: 'rn-cross-platform', via: norm(m.name) },
1795
+ });
1796
+ }
1797
+ }
1798
+ }
1799
+ }
1800
+ return edges;
1801
+ }
1802
+ async function fabricNativeImplEdges(ctx, onYield) {
1803
+ let scanned255 = 0;
1804
+ const edges = [];
1805
+ const seen = new Set();
1806
+ // The Fabric extractor IDs are prefixed `fabric-component:` so we can
1807
+ // filter to just those while streaming — never materializing the whole
1808
+ // `component` kind (#1212).
1809
+ const components = [];
1810
+ for (const n of (ctx.iterateNodesByKind?.('component') ?? ctx.getNodesByKind('component'))) {
1811
+ if ((++scanned255 & 63) === 0)
1812
+ await onYield();
1813
+ if (n.id.startsWith('fabric-component:'))
1814
+ components.push(n);
1815
+ }
1816
+ if (components.length === 0)
1817
+ return edges;
1818
+ // Pre-index native classes by name for O(1) lookup.
1819
+ const nativeClassesByName = new Map();
1820
+ for (const n of (ctx.iterateNodesByKind?.('class') ?? ctx.getNodesByKind('class'))) {
1821
+ if ((++scanned255 & 63) === 0)
1822
+ await onYield();
1823
+ if (n.language !== 'objc' && n.language !== 'kotlin' && n.language !== 'java' && n.language !== 'cpp')
1824
+ continue;
1825
+ const arr = nativeClassesByName.get(n.name);
1826
+ if (arr)
1827
+ arr.push(n);
1828
+ else
1829
+ nativeClassesByName.set(n.name, [n]);
1830
+ }
1831
+ for (const component of components) {
1832
+ for (const suffix of FABRIC_NATIVE_SUFFIXES) {
1833
+ const candidate = component.name + suffix;
1834
+ const matches = nativeClassesByName.get(candidate);
1835
+ if (!matches || matches.length === 0)
1836
+ continue;
1837
+ // Link the component node to every matching native class (iOS +
1838
+ // Android each have one).
1839
+ for (const native of matches) {
1840
+ const key = `${component.id}>${native.id}`;
1841
+ if (seen.has(key))
1842
+ continue;
1843
+ seen.add(key);
1844
+ edges.push({
1845
+ source: component.id,
1846
+ target: native.id,
1847
+ kind: 'calls',
1848
+ provenance: 'heuristic',
1849
+ metadata: {
1850
+ synthesizedBy: 'fabric-native-impl',
1851
+ viaSuffix: suffix || '(exact)',
1852
+ componentName: component.name,
1853
+ },
1854
+ });
1855
+ }
1856
+ }
1857
+ }
1858
+ return edges;
1859
+ }
1860
+ /**
1861
+ * MyBatis: link a Java mapper interface method to the XML statement that holds
1862
+ * its SQL. The XML extractor (`src/extraction/mybatis-extractor.ts`) qualifies
1863
+ * each `<select|insert|update|delete|sql id="X">` as `<namespace>::<id>` where
1864
+ * `<namespace>` is the Java FQN of the mapper interface. A Java method's
1865
+ * qualifiedName ends with `<ClassName>::<methodName>`, so we suffix-match the
1866
+ * last two segments of the XML qualified name to find a unique Java method by
1867
+ * `<ClassName>::<methodName>` (`ClassName` = last dotted segment of the XML
1868
+ * namespace). Cross-mapper `<include refid="other.X">` references go through
1869
+ * the normal qualified-name resolver — only the Java↔XML bridge is synthetic.
1870
+ *
1871
+ * Precision over recall: ambiguous mappers (multiple Java classes with the
1872
+ * same simple name) are dropped. We need-not bridge by package because Java
1873
+ * mapper interfaces are typically uniquely named within a project.
1874
+ */
1875
+ async function mybatisJavaXmlEdges(queries, onYield) {
1876
+ let scanned255 = 0;
1877
+ const edges = [];
1878
+ const seen = new Set();
1879
+ // Index Java methods by `<ClassName>::<methodName>` for O(1) lookup.
1880
+ const javaIndex = new Map();
1881
+ for (const m of queries.iterateNodesByKind('method')) {
1882
+ if ((++scanned255 & 63) === 0)
1883
+ await onYield();
1884
+ if (m.language !== 'java' && m.language !== 'kotlin')
1885
+ continue;
1886
+ const parts = m.qualifiedName.split('::');
1887
+ const last = parts[parts.length - 1];
1888
+ const cls = parts[parts.length - 2];
1889
+ if (!last || !cls)
1890
+ continue;
1891
+ const key = `${cls}::${last}`;
1892
+ const arr = javaIndex.get(key);
1893
+ if (arr)
1894
+ arr.push(m);
1895
+ else
1896
+ javaIndex.set(key, [m]);
1897
+ }
1898
+ for (const xml of queries.iterateNodesByKind('method')) {
1899
+ if ((++scanned255 & 63) === 0)
1900
+ await onYield();
1901
+ if (xml.language !== 'xml')
1902
+ continue;
1903
+ // Qualified name: `<namespace>::<id>`. Extract the simple class name.
1904
+ const colonIdx = xml.qualifiedName.lastIndexOf('::');
1905
+ if (colonIdx < 0)
1906
+ continue;
1907
+ const namespace = xml.qualifiedName.slice(0, colonIdx);
1908
+ const id = xml.qualifiedName.slice(colonIdx + 2);
1909
+ if (!namespace || !id)
1910
+ continue;
1911
+ const dotIdx = namespace.lastIndexOf('.');
1912
+ const className = dotIdx >= 0 ? namespace.slice(dotIdx + 1) : namespace;
1913
+ const candidates = javaIndex.get(`${className}::${id}`);
1914
+ if (!candidates || candidates.length === 0)
1915
+ continue;
1916
+ // Drop ambiguous matches (multiple same-name classes); the user can
1917
+ // disambiguate by adding the package-suffix match in a future enhancement.
1918
+ if (candidates.length > 1)
1919
+ continue;
1920
+ const java = candidates[0];
1921
+ const key = `${java.id}>${xml.id}`;
1922
+ if (seen.has(key))
1923
+ continue;
1924
+ seen.add(key);
1925
+ edges.push({
1926
+ source: java.id,
1927
+ target: xml.id,
1928
+ kind: 'calls',
1929
+ line: java.startLine,
1930
+ provenance: 'heuristic',
1931
+ metadata: {
1932
+ synthesizedBy: 'mybatis-java-xml',
1933
+ via: `${className}.${id}`,
1934
+ registeredAt: `${xml.filePath}:${xml.startLine}`,
1935
+ },
1936
+ });
1937
+ }
1938
+ return edges;
1939
+ }
1940
+ /**
1941
+ * Gin middleware chain. Gin runs its entire handler chain through one dynamic
1942
+ * line in `(*Context).Next`:
1943
+ * for c.index < len(c.handlers) { c.handlers[c.index](c); c.index++ }
1944
+ * `c.handlers` is a `HandlersChain` (`[]HandlerFunc`) assembled at registration
1945
+ * time by `combineHandlers` from the funcs passed to `r.Use(...)` /
1946
+ * `r.GET("/path", h...)` / `r.Handle(...)`. Because the call is a computed index
1947
+ * into a runtime-built slice, tree-sitter resolves `c.handlers[c.index](c)` to
1948
+ * NOTHING — so `callees(Next)` is just the `len()` helper and the flow
1949
+ * `ServeHTTP → handleHTTPRequest → Next` dead-ends at the exact symbol the
1950
+ * "how do requests flow through the middleware chain" question is about. The
1951
+ * agent then re-queries Next and falls back to Read/grep (validated: the gin
1952
+ * WITH-arm rabbit-holed on precisely this dead-end).
1953
+ *
1954
+ * Bridge it: find the chain DISPATCHER (a Go method whose body invokes a
1955
+ * `handlers` slice by index) and link it → every HandlerFunc registered via a
1956
+ * gin registration call, so `callees(Next)` and `trace(ServeHTTP, <handler>)`
1957
+ * connect end-to-end. Named handlers only (`gin.Logger()` → `Logger`,
1958
+ * `authMiddleware`); inline closures are anonymous and skipped. Like
1959
+ * react-render / interface-impl this is a deliberate over-approximation —
1960
+ * reachability-correct (any registered handler CAN run for some route), capped,
1961
+ * and gated on the dispatcher existing so it never runs on non-gin Go repos.
1962
+ * Provenance `heuristic`, `synthesizedBy:'gin-middleware-chain'`; `registeredAt`
1963
+ * is the `.Use`/`.GET` site an agent would otherwise grep for.
1964
+ */
1965
+ const GIN_DISPATCH_RE = /\.handlers\s*\[[^\]]*\]\s*\(/; // c.handlers[c.index](c)
1966
+ const GIN_REG_RE = /\.(?:Use|GET|POST|PUT|PATCH|DELETE|OPTIONS|HEAD|Any|Handle)\s*\(/g;
1967
+ /** Balanced `(...)` body starting at the '(' index; null if unbalanced. */
1968
+ function goBalancedArgs(s, openIdx) {
1969
+ let depth = 0;
1970
+ for (let i = openIdx; i < s.length; i++) {
1971
+ const c = s[i];
1972
+ if (c === '(')
1973
+ depth++;
1974
+ else if (c === ')') {
1975
+ depth--;
1976
+ if (depth === 0)
1977
+ return s.slice(openIdx + 1, i);
1978
+ }
1979
+ }
1980
+ return null;
1981
+ }
1982
+ /** Split a top-level comma list, respecting nested () [] {}. */
1983
+ function goSplitArgs(args) {
1984
+ const out = [];
1985
+ let depth = 0, cur = '';
1986
+ for (const c of args) {
1987
+ if (c === '(' || c === '[' || c === '{') {
1988
+ depth++;
1989
+ cur += c;
1990
+ }
1991
+ else if (c === ')' || c === ']' || c === '}') {
1992
+ depth--;
1993
+ cur += c;
1994
+ }
1995
+ else if (c === ',' && depth === 0) {
1996
+ out.push(cur);
1997
+ cur = '';
1998
+ }
1999
+ else
2000
+ cur += c;
2001
+ }
2002
+ if (cur.trim())
2003
+ out.push(cur);
2004
+ return out;
2005
+ }
2006
+ /** Tail ident of a handler arg: `gin.Logger()`→`Logger`, `mw`→`mw`; null for string paths / closures. */
2007
+ function goHandlerIdent(expr) {
2008
+ const cleaned = expr.trim().replace(/\(\s*\)$/, ''); // drop a trailing call ()
2009
+ if (!cleaned || cleaned.startsWith('"') || cleaned.startsWith('`') || cleaned.startsWith('func'))
2010
+ return null;
2011
+ const m = cleaned.match(/(?:\.|^)([A-Za-z_]\w*)$/);
2012
+ return m ? m[1] : null;
2013
+ }
2014
+ async function ginMiddlewareChainEdges(queries, ctx, onYield) {
2015
+ let scanned255 = 0;
2016
+ let scannedFiles = 0;
2017
+ // 1. Find the chain dispatcher(s): a Go method that invokes a `handlers` slice by index.
2018
+ const dispatchers = [];
2019
+ for (const n of queries.iterateNodesByKind('method')) {
2020
+ if ((++scanned255 & 63) === 0)
2021
+ await onYield();
2022
+ if (n.language !== 'go')
2023
+ continue;
2024
+ const content = ctx.readFile(n.filePath);
2025
+ const src = content && sliceLines(content, n.startLine, n.endLine);
2026
+ if (src && GIN_DISPATCH_RE.test(src))
2027
+ dispatchers.push(n);
2028
+ }
2029
+ if (dispatchers.length === 0)
2030
+ return []; // not a gin repo — bail
2031
+ // 2. Collect handler identifiers registered via gin registration calls
2032
+ // (.Use / .GET / … / .Handle). String args (paths/methods) and inline
2033
+ // closures are dropped by goHandlerIdent; the rest are HandlerFuncs.
2034
+ const registered = new Map(); // name → registeredAt (file:line)
2035
+ for (const file of ctx.getAllFiles()) {
2036
+ if ((++scannedFiles & 15) === 0)
2037
+ await onYield();
2038
+ if (!file.endsWith('.go'))
2039
+ continue;
2040
+ const content = ctx.readFile(file);
2041
+ if (!content || (!content.includes('.Use(') && !/\.(?:GET|POST|PUT|PATCH|DELETE|OPTIONS|HEAD|Any|Handle)\(/.test(content)))
2042
+ continue;
2043
+ const safe = (0, strip_comments_1.stripCommentsForRegex)(content, 'go');
2044
+ GIN_REG_RE.lastIndex = 0;
2045
+ let m;
2046
+ while ((m = GIN_REG_RE.exec(safe))) {
2047
+ const parenIdx = m.index + m[0].length - 1;
2048
+ const argStr = goBalancedArgs(safe, parenIdx);
2049
+ if (!argStr)
2050
+ continue;
2051
+ const line = safe.slice(0, m.index).split('\n').length;
2052
+ for (const arg of goSplitArgs(argStr)) {
2053
+ const name = goHandlerIdent(arg);
2054
+ if (name && !registered.has(name))
2055
+ registered.set(name, `${file}:${line}`);
2056
+ }
2057
+ }
2058
+ }
2059
+ if (registered.size === 0)
2060
+ return [];
2061
+ // 3. Link each dispatcher → each registered handler node (dedup, capped).
2062
+ const edges = [];
2063
+ const seen = new Set();
2064
+ for (const disp of dispatchers) {
2065
+ let added = 0;
2066
+ for (const [name, registeredAt] of registered) {
2067
+ if (added >= MAX_CALLBACKS_PER_CHANNEL)
2068
+ break;
2069
+ const handler = ctx.getNodesByName(name).find((n) => (n.kind === 'function' || n.kind === 'method') && n.language === 'go');
2070
+ if (!handler || handler.id === disp.id)
2071
+ continue;
2072
+ const key = `${disp.id}>${handler.id}`;
2073
+ if (seen.has(key))
2074
+ continue;
2075
+ seen.add(key);
2076
+ edges.push({
2077
+ source: disp.id, target: handler.id, kind: 'calls', line: disp.startLine,
2078
+ provenance: 'heuristic',
2079
+ metadata: { synthesizedBy: 'gin-middleware-chain', via: name, registeredAt },
2080
+ });
2081
+ added++;
2082
+ }
2083
+ }
2084
+ return edges;
2085
+ }
2086
+ /**
2087
+ * Delphi form code-behind: a form unit `UFRMAbout.pas` owns its visual form
2088
+ * definition `UFRMAbout.dfm` (VCL) / `.fmx` (FireMonkey) — paired by basename in
2089
+ * the same directory, wired by the `{$R *.dfm}` directive rather than a `uses`
2090
+ * clause. Link the unit → its form so a `.dfm`/`.fmx` used only as a form
2091
+ * definition isn't orphaned, and editing the form surfaces its code-behind unit.
2092
+ */
2093
+ async function pascalFormEdges(ctx, onYield) {
2094
+ let scannedFiles = 0;
2095
+ const edges = [];
2096
+ const allFiles = new Set(ctx.getAllFiles());
2097
+ for (const file of allFiles) {
2098
+ if ((++scannedFiles & 255) === 0)
2099
+ await onYield();
2100
+ if (!/\.(dfm|fmx)$/i.test(file))
2101
+ continue;
2102
+ const pasFile = file.replace(/\.(dfm|fmx)$/i, '.pas');
2103
+ if (!allFiles.has(pasFile))
2104
+ continue;
2105
+ const formNode = ctx.getNodesInFile(file).find((n) => n.kind === 'file');
2106
+ const unitNode = ctx.getNodesInFile(pasFile).find((n) => n.kind === 'file');
2107
+ if (!formNode || !unitNode)
2108
+ continue;
2109
+ edges.push({
2110
+ source: unitNode.id,
2111
+ target: formNode.id,
2112
+ kind: 'references',
2113
+ line: unitNode.startLine,
2114
+ provenance: 'heuristic',
2115
+ metadata: { synthesizedBy: 'pascal-form', registeredAt: pasFile },
2116
+ });
2117
+ }
2118
+ return edges;
2119
+ }
2120
+ /**
2121
+ * SvelteKit file-convention data flow. A route directory's `+page.svelte` (a
2122
+ * `component` node) receives its `data` from the sibling `+page.server.{ts,js}`
2123
+ * / `+page.{ts,js}` `load` function and posts forms to its `actions` — wired by
2124
+ * the framework BY FILE PATH, with no static import between them. So editing a
2125
+ * `load` shows no impact on the page it feeds, and the page looks like it has no
2126
+ * server-side dependency. Link the page component to its sibling loader's
2127
+ * `load` / `actions` (same for `+layout`). The pairing is path-deterministic
2128
+ * (same directory, matching `+page`/`+layout` prefix), so it's precise — but
2129
+ * it's a framework-convention edge, so provenance stays `heuristic`.
2130
+ *
2131
+ * Direction: page → load, so `getImpactRadius(load)` surfaces the page (editing
2132
+ * a loader's data shows the page it feeds) and the page's dependencies include
2133
+ * its loader.
2134
+ */
2135
+ async function svelteKitLoadEdges(ctx, onYield) {
2136
+ let scannedFiles = 0;
2137
+ const edges = [];
2138
+ const allFiles = new Set(ctx.getAllFiles());
2139
+ const HOOKS = new Set(['load', 'actions']);
2140
+ const HOOK_KINDS = new Set(['function', 'method', 'constant', 'variable']);
2141
+ for (const file of allFiles) {
2142
+ if ((++scannedFiles & 255) === 0)
2143
+ await onYield();
2144
+ const m = file.match(/(.*\/)(\+(?:page|layout))\.svelte$/);
2145
+ if (!m)
2146
+ continue;
2147
+ const dir = m[1];
2148
+ const prefix = m[2];
2149
+ const page = ctx.getNodesInFile(file).find((n) => n.kind === 'component');
2150
+ if (!page)
2151
+ continue;
2152
+ for (const ext of ['.server.ts', '.server.js', '.ts', '.js']) {
2153
+ const loaderFile = `${dir}${prefix}${ext}`;
2154
+ if (!allFiles.has(loaderFile))
2155
+ continue;
2156
+ for (const hook of ctx.getNodesInFile(loaderFile)) {
2157
+ if (!HOOK_KINDS.has(hook.kind) || !HOOKS.has(hook.name))
2158
+ continue;
2159
+ edges.push({
2160
+ source: page.id,
2161
+ target: hook.id,
2162
+ kind: 'references',
2163
+ line: page.startLine,
2164
+ provenance: 'heuristic',
2165
+ metadata: {
2166
+ synthesizedBy: 'sveltekit-load',
2167
+ via: hook.name,
2168
+ registeredAt: `${loaderFile}:${hook.startLine ?? 0}`,
2169
+ },
2170
+ });
2171
+ }
2172
+ }
2173
+ }
2174
+ return edges;
2175
+ }
2176
+ /**
2177
+ * Redux-thunk dispatch chain. `export const X = createAsyncThunk(prefix, async (a, api) => {...})`
2178
+ * (or a wrapper like trezor's `createThunk(...)`) passes the async body as an ARGUMENT, so
2179
+ * tree-sitter never extracts it as a function node: `X` is a `constant` whose body's calls are
2180
+ * ORPHANED. The `dispatch(nextThunk(...))` calls that drive a thunk chain forward therefore produce
2181
+ * no edges, so `callees(X)` is empty and a flow `dispatch(X(...)) → X → nextThunk` dead-ends at the
2182
+ * constant (validated on trezor-suite: the signXxxThunk constants had ZERO outgoing edges). Bridge
2183
+ * it: body-scan each thunk constant for `dispatch(Y(...))` and link `X → Y`, so the dispatch chain
2184
+ * connects. High-precision — the `dispatch(` keyword plus `Y` must resolve to a function/constant/
2185
+ * method node; capped; gated on thunk constants existing so it never runs on non-RTK repos.
2186
+ * Cross-file by design (a suite thunk dispatches a wallet-core thunk). Provenance `heuristic`,
2187
+ * `synthesizedBy:'redux-thunk'`; `registeredAt` is the dispatch site.
2188
+ */
2189
+ const THUNK_DECL_RE = /create(?:Async)?Thunk/;
2190
+ const THUNK_DISPATCH_RE = /\bdispatch\s*\(\s*([A-Za-z_]\w*)\s*[(),]/g;
2191
+ const THUNK_FANOUT_CAP = 24;
2192
+ async function reduxThunkEdges(queries, ctx, onYield) {
2193
+ let scanned255 = 0;
2194
+ const edges = [];
2195
+ const seen = new Set();
2196
+ for (const node of queries.iterateNodesByKind('constant')) {
2197
+ if ((++scanned255 & 63) === 0)
2198
+ await onYield();
2199
+ // Cheap gate: the initializer (captured in `signature`) must be a create(Async)Thunk call —
2200
+ // avoids reading every constant's body on a large repo.
2201
+ if (!node.signature || !THUNK_DECL_RE.test(node.signature))
2202
+ continue;
2203
+ const content = ctx.readFile(node.filePath);
2204
+ const src = content && sliceLines(content, node.startLine, node.endLine);
2205
+ if (!src)
2206
+ continue;
2207
+ // Thunks are TS/JS-family (same // and /* */ comment syntax); map to a CommentLang.
2208
+ const safe = (0, strip_comments_1.stripCommentsForRegex)(src, node.language === 'javascript' || node.language === 'jsx' ? 'javascript' : 'typescript');
2209
+ THUNK_DISPATCH_RE.lastIndex = 0;
2210
+ let m;
2211
+ let added = 0;
2212
+ while ((m = THUNK_DISPATCH_RE.exec(safe)) && added < THUNK_FANOUT_CAP) {
2213
+ const name = m[1];
2214
+ if (name === node.name)
2215
+ continue; // self-dispatch (recursive thunk) — skip
2216
+ // Resolve the dispatched name, PREFERRING the thunk/action-creator over a same-named
2217
+ // service function. `dispatch(X(...))` dispatches a thunk or an action-creator (both
2218
+ // `constant`s) — never an unrelated helper that merely shares the name. On octo-call,
2219
+ // `leaveCall` is BOTH a `createAsyncThunk` const AND a service function, and the bare
2220
+ // `.find()` picked the function (wrong). Order: thunk const > other const > same-file
2221
+ // callable > first match. A single candidate (no collision) is unaffected.
2222
+ const cands = ctx
2223
+ .getNodesByName(name)
2224
+ .filter((n) => n.kind === 'constant' || n.kind === 'function' || n.kind === 'method');
2225
+ const target = cands.find((n) => !!n.signature && THUNK_DECL_RE.test(n.signature)) ??
2226
+ cands.find((n) => n.kind === 'constant') ??
2227
+ cands.find((n) => n.filePath === node.filePath) ??
2228
+ cands[0];
2229
+ if (!target || target.id === node.id)
2230
+ continue;
2231
+ const key = `${node.id}>${target.id}`;
2232
+ if (seen.has(key))
2233
+ continue;
2234
+ seen.add(key);
2235
+ const line = node.startLine + safe.slice(0, m.index).split('\n').length - 1;
2236
+ edges.push({
2237
+ source: node.id,
2238
+ target: target.id,
2239
+ kind: 'calls',
2240
+ line,
2241
+ provenance: 'heuristic',
2242
+ metadata: { synthesizedBy: 'redux-thunk', via: name, registeredAt: `${node.filePath}:${line}` },
2243
+ });
2244
+ added++;
2245
+ }
2246
+ }
2247
+ return edges;
2248
+ }
2249
+ // ── Object-literal registry dispatch ─────────────────────────────────────────
2250
+ // A command/handler registry maps string keys → handler class/function symbols in an
2251
+ // object literal, then dispatches by a RUNTIME key static parsing can't follow:
2252
+ // this.commands = { [Cmd.ADD]: AddObjectCommand, ... } // registration
2253
+ // new this.commands[command](args).execute() // dynamic dispatch
2254
+ // Bridge it like gin-middleware-chain: link each dispatching function → each registered
2255
+ // handler's callable entry (a class's execute/run/handle/… method — preferring the method
2256
+ // chained at the dispatch site — or the function value). Scoped to a registry + dispatch in
2257
+ // the SAME file (the cross-file barrel-namespace variant, e.g. trezor's getMethod, is
2258
+ // deferred). Gated on a real object literal with ≥2 entries that RESOLVE to callables (a
2259
+ // `{ width: 5 }` literal resolves to nothing → no edges); fan-out capped.
2260
+ const REGISTRY_ASSIGN_RE = /(?:(?:const|let|var)\s+([A-Za-z_$][\w$]*)|((?:this\.)?[A-Za-z_$][\w$]*))\s*=\s*\{/g;
2261
+ const REGISTRY_DISPATCH_RE = /(?:\bnew\s+)?((?:this\.)?[A-Za-z_$][\w$]*)\s*\[\s*([A-Za-z_$][\w$.]*)\s*\]\s*(?:\(|\.[A-Za-z_$])/g;
2262
+ const REGISTRY_MIN_ENTRIES = 2;
2263
+ const REGISTRY_FANOUT_CAP = 40;
2264
+ const REGISTRY_CLASS_ENTRY = new Set(['execute', 'run', 'handle', 'perform', 'process', 'call', 'apply', 'dispatch']);
2265
+ const REGISTRY_JS_EXT = /\.(?:ts|tsx|js|jsx|mjs|cjs)$/;
2266
+ /** From the index of an opening `{`, return the brace-balanced body up to its matching `}`. */
2267
+ function braceBody(src, openIdx) {
2268
+ let depth = 0;
2269
+ for (let i = openIdx; i < src.length; i++) {
2270
+ if (src[i] === '{')
2271
+ depth++;
2272
+ else if (src[i] === '}' && --depth === 0)
2273
+ return src.slice(openIdx + 1, i);
2274
+ }
2275
+ return null;
2276
+ }
2277
+ /** Top-level `key: Identifier` entries of an object-literal body. DEPTH-AWARE: only depth-0
2278
+ * segments are considered, so method-shorthand bodies (`number(a,b){…}`), arrow values
2279
+ * (`x: () => …`), and nested objects (`x: { … }`) don't leak their inner `k: v` pairs as
2280
+ * bogus handlers. The per-segment anchor (`^… key: Ident …$`) keeps only pure identifier
2281
+ * values — a data value (`x: 5`), call, or arrow fails to match. */
2282
+ function registryEntryNames(body) {
2283
+ const segs = [];
2284
+ let depth = 0;
2285
+ let start = 0;
2286
+ for (let i = 0; i < body.length; i++) {
2287
+ const c = body[i];
2288
+ if (c === '{' || c === '(' || c === '[')
2289
+ depth++;
2290
+ else if (c === '}' || c === ')' || c === ']')
2291
+ depth--;
2292
+ else if (c === ',' && depth === 0) {
2293
+ segs.push(body.slice(start, i));
2294
+ start = i + 1;
2295
+ }
2296
+ }
2297
+ segs.push(body.slice(start));
2298
+ const names = [];
2299
+ for (const seg of segs) {
2300
+ const m = /^\s*(?:\[[^\]]+\]|['"]?[\w$]+['"]?)\s*:\s*([A-Za-z_$][\w$]*)\s*$/.exec(seg);
2301
+ if (m && m[1].length >= 3 && !names.includes(m[1]))
2302
+ names.push(m[1]);
2303
+ }
2304
+ return names;
2305
+ }
2306
+ /** Resolve a registered handler name to its callable entry: a function value, or a class's
2307
+ * `execute`-like method (preferring the method chained at the dispatch site), else the class. */
2308
+ function resolveRegistryHandler(ctx, name, chained) {
2309
+ const cands = ctx.getNodesByName(name);
2310
+ const fn = cands.find((n) => n.kind === 'function');
2311
+ if (fn)
2312
+ return fn;
2313
+ const cls = cands.find((n) => n.kind === 'class' || n.kind === 'struct');
2314
+ if (cls) {
2315
+ const methods = ctx
2316
+ .getNodesInFile(cls.filePath)
2317
+ .filter((n) => n.kind === 'method' && n.startLine >= cls.startLine && n.startLine <= (cls.endLine ?? cls.startLine));
2318
+ const want = chained && REGISTRY_CLASS_ENTRY.has(chained) ? chained : null;
2319
+ const entry = (want && methods.find((m) => m.name === want)) ||
2320
+ methods.find((m) => REGISTRY_CLASS_ENTRY.has(m.name)) ||
2321
+ methods.find((m) => m.name === 'constructor');
2322
+ return entry ?? cls;
2323
+ }
2324
+ // Require a CALLABLE target — a registry dispatched as `reg[k](…)` invokes a function/
2325
+ // method, never a data `constant` (dropping it removes false positives like a `{ x: URL }`
2326
+ // entry resolving to the global URL constant).
2327
+ return cands.find((n) => n.kind === 'method') ?? null;
2328
+ }
2329
+ async function objectRegistryEdges(ctx, onYield) {
2330
+ let scannedFiles = 0;
2331
+ const edges = [];
2332
+ const seen = new Set();
2333
+ let scanned = 0;
2334
+ for (const file of ctx.getAllFiles()) {
2335
+ if ((++scannedFiles & 15) === 0)
2336
+ await onYield();
2337
+ if ((++scanned & 255) === 0)
2338
+ await onYield(); // #1091: yield mid-scan on huge graphs
2339
+ if (!REGISTRY_JS_EXT.test(file))
2340
+ continue;
2341
+ const content = ctx.readFile(file);
2342
+ // Cheap pre-filter: a computed member access BY NAME (`ident[ident`) — the dispatch shape.
2343
+ if (!content || !/[\w$]\s*\[\s*[A-Za-z_$]/.test(content))
2344
+ continue;
2345
+ // Skip minified/generated bundles (draco, three.min, base64…): their pervasive `h[x](...)`
2346
+ // calls + single-letter `{a:b}` literals are a false-positive minefield. Average line
2347
+ // length is the reliable tell — real source ~30–80, minified in the hundreds/thousands.
2348
+ const newlines = (content.match(/\n/g)?.length ?? 0) + 1;
2349
+ if (content.length / newlines > 200)
2350
+ continue;
2351
+ const safe = (0, strip_comments_1.stripCommentsForRegex)(content, /\.(?:jsx?|mjs|cjs)$/.test(file) ? 'javascript' : 'typescript');
2352
+ // 1. Dispatch sites: `(new )?<ref>[<ident-key>]` followed by a call or a chained method.
2353
+ // A quoted-string key (`['save']`) does NOT match — that's a static access, not dispatch.
2354
+ REGISTRY_DISPATCH_RE.lastIndex = 0;
2355
+ const dispatches = [];
2356
+ let dm;
2357
+ while ((dm = REGISTRY_DISPATCH_RE.exec(safe))) {
2358
+ const win = safe.slice(dm.index, dm.index + 160);
2359
+ const cm = /\]\s*\([^)]*\)\s*\.\s*([A-Za-z_$][\w$]*)/.exec(win) || /\]\s*\.\s*([A-Za-z_$][\w$]*)/.exec(win);
2360
+ dispatches.push({ ref: dm[1], line: safe.slice(0, dm.index).split('\n').length, chained: cm ? cm[1] : null });
2361
+ }
2362
+ if (!dispatches.length)
2363
+ continue;
2364
+ // Normalize a leading `this.` so a class FIELD-INITIALIZER registry (`commands = {…}`)
2365
+ // matches a `this.commands[k]` dispatch, not just the constructor form `this.commands = {…}`.
2366
+ const norm = (r) => r.replace(/^this\./, '');
2367
+ const refs = new Set(dispatches.map((d) => norm(d.ref)));
2368
+ // 2. Registries: an object literal assigned to a dispatched ref, ≥2 entries resolving to callables.
2369
+ REGISTRY_ASSIGN_RE.lastIndex = 0;
2370
+ const registries = new Map();
2371
+ let am;
2372
+ while ((am = REGISTRY_ASSIGN_RE.exec(safe))) {
2373
+ const lhs = norm(am[1] ?? am[2]);
2374
+ if (!refs.has(lhs) || registries.has(lhs))
2375
+ continue;
2376
+ const body = braceBody(safe, am.index + am[0].length - 1);
2377
+ if (!body)
2378
+ continue;
2379
+ const names = registryEntryNames(body); // depth-0 `key: Identifier` entries only
2380
+ if (names.length >= REGISTRY_MIN_ENTRIES) {
2381
+ registries.set(lhs, { names, line: safe.slice(0, am.index).split('\n').length });
2382
+ }
2383
+ }
2384
+ if (!registries.size)
2385
+ continue;
2386
+ // 3. Link each dispatcher → each registered handler's callable entry.
2387
+ const nodesInFile = ctx.getNodesInFile(file);
2388
+ for (const d of dispatches) {
2389
+ const reg = registries.get(norm(d.ref));
2390
+ if (!reg)
2391
+ continue;
2392
+ const disp = enclosingFn(nodesInFile, d.line);
2393
+ if (!disp)
2394
+ continue;
2395
+ let added = 0;
2396
+ for (const name of reg.names) {
2397
+ if (added >= REGISTRY_FANOUT_CAP)
2398
+ break;
2399
+ const target = resolveRegistryHandler(ctx, name, d.chained);
2400
+ if (!target || target.id === disp.id)
2401
+ continue;
2402
+ const key = `${disp.id}>${target.id}`;
2403
+ if (seen.has(key))
2404
+ continue;
2405
+ seen.add(key);
2406
+ edges.push({
2407
+ source: disp.id,
2408
+ target: target.id,
2409
+ kind: 'calls',
2410
+ line: d.line,
2411
+ provenance: 'heuristic',
2412
+ metadata: { synthesizedBy: 'object-registry', via: name, registeredAt: `${file}:${reg.line}` },
2413
+ });
2414
+ added++;
2415
+ }
2416
+ }
2417
+ }
2418
+ return edges;
2419
+ }
2420
+ // ── RTK Query generated-hook → endpoint ──────────────────────────────────────
2421
+ // RTK Query generates one `useGetXQuery`/`useUpdateYMutation` hook per endpoint
2422
+ // (`createApi({ endpoints: b => ({ getX: b.query(...) }) })`). Components call the
2423
+ // hook; the fetch logic lives in the endpoint's queryFn. The hook↔endpoint link is
2424
+ // pure NAMING CONVENTION (no static edge): strip `use` + the optional `Lazy`
2425
+ // variant + the `Query|Mutation` suffix, lowercase the head → the endpoint key.
2426
+ // Both are extracted as function nodes (the hook from its `export const {…}=api`
2427
+ // binding, carrying a sentinel signature; the endpoint from the createApi object),
2428
+ // so bridging hook→endpoint connects `component → useGetXQuery → getX → queryFn`.
2429
+ // Gated on the extraction sentinel so it only ever fires on genuinely-generated
2430
+ // hooks (never a hand-written `useFooQuery`), and on a SAME-FILE endpoint (RTK
2431
+ // colocates the hooks and their api in one module) — 0 on any non-RTK repo.
2432
+ const RTK_HOOK_DERIVE_RE = /^use([A-Z][A-Za-z0-9]*?)(?:Query|Mutation)$/;
2433
+ // MUST match the signature set in tree-sitter.ts `extractRtkHookBindings`.
2434
+ const RTK_GENERATED_HOOK_SIGNATURE = '= RTK Query generated hook';
2435
+ /** Derive the endpoint key from a generated-hook name (`useLazyGetRecordsQuery`
2436
+ * → `getRecords`), or null if it doesn't fit the convention. */
2437
+ function rtkEndpointNameFromHook(hook) {
2438
+ const m = RTK_HOOK_DERIVE_RE.exec(hook);
2439
+ if (!m)
2440
+ return null;
2441
+ let mid = m[1];
2442
+ if (mid.startsWith('Lazy'))
2443
+ mid = mid.slice(4); // useLazyGetX → getX (same endpoint)
2444
+ if (!mid)
2445
+ return null;
2446
+ return mid.charAt(0).toLowerCase() + mid.slice(1);
2447
+ }
2448
+ async function rtkQueryEdges(queries, ctx, onYield) {
2449
+ let scanned255 = 0;
2450
+ const edges = [];
2451
+ const seen = new Set();
2452
+ for (const hook of queries.iterateNodesByKind('function')) {
2453
+ if ((++scanned255 & 63) === 0)
2454
+ await onYield();
2455
+ // Only our extracted generated-hook bindings (sentinel) — not a real hook fn.
2456
+ if (hook.signature !== RTK_GENERATED_HOOK_SIGNATURE)
2457
+ continue;
2458
+ const endpointName = rtkEndpointNameFromHook(hook.name);
2459
+ if (!endpointName)
2460
+ continue;
2461
+ // The endpoint is a same-file function by the derived name (RTK colocates the
2462
+ // api definition and its generated-hook exports in one module).
2463
+ const target = ctx
2464
+ .getNodesByName(endpointName)
2465
+ .find((n) => n.kind === 'function' && n.filePath === hook.filePath);
2466
+ if (!target || target.id === hook.id)
2467
+ continue;
2468
+ const key = `${hook.id}>${target.id}`;
2469
+ if (seen.has(key))
2470
+ continue;
2471
+ seen.add(key);
2472
+ edges.push({
2473
+ source: hook.id,
2474
+ target: target.id,
2475
+ kind: 'calls',
2476
+ line: hook.startLine,
2477
+ provenance: 'heuristic',
2478
+ metadata: { synthesizedBy: 'rtk-query', via: endpointName, registeredAt: `${hook.filePath}:${hook.startLine}` },
2479
+ });
2480
+ }
2481
+ return edges;
2482
+ }
2483
+ // ── Pinia useStore().action() dispatch bridge ────────────────────────────────
2484
+ // A Pinia store factory `export const useXStore = defineStore(...)` exposes its
2485
+ // actions as methods on the store instance; a consumer does `const s = useXStore()`
2486
+ // then `s.action()`. The call is a method-on-instance with no static edge to the
2487
+ // action (which lives in the store's module). Bridge it: map each factory → its
2488
+ // file, bind `const <var> = useXStore()` per consumer file, and link the enclosing
2489
+ // function → the `<var>.method()` action node IN THE STORE'S FILE. The same-store-
2490
+ // file gate keeps it precise (a Pinia built-in like `$patch` or an unrelated
2491
+ // same-named method resolves to nothing). Covers both the options and setup store
2492
+ // forms uniformly (the action is a function node in the store file either way).
2493
+ const PINIA_CONSUMER_EXT = /\.(?:ts|tsx|js|jsx|mjs|cjs|vue)$/;
2494
+ const PINIA_FACTORY_RE = /\b(?:export\s+)?const\s+(\w+)\s*=\s*defineStore\s*\(/g;
2495
+ const PINIA_BIND_RE = /\bconst\s+(\w+)\s*=\s*(?:await\s+)?(\w+)\s*\(/g;
2496
+ const PINIA_CALL_RE = /(\w+)\s*\.\s*(\w+)\s*\(/g;
2497
+ const PINIA_FANOUT_CAP = 80;
2498
+ async function piniaStoreEdges(ctx, onYield) {
2499
+ let scannedFiles = 0;
2500
+ // 1. Map each `const useXStore = defineStore(...)` factory → its store file.
2501
+ const factoryFile = new Map();
2502
+ for (const file of ctx.getAllFiles()) {
2503
+ if ((++scannedFiles & 15) === 0)
2504
+ await onYield();
2505
+ if (!PINIA_CONSUMER_EXT.test(file))
2506
+ continue;
2507
+ const content = ctx.readFile(file);
2508
+ if (!content || !content.includes('defineStore'))
2509
+ continue;
2510
+ PINIA_FACTORY_RE.lastIndex = 0;
2511
+ let m;
2512
+ while ((m = PINIA_FACTORY_RE.exec(content)))
2513
+ factoryFile.set(m[1], file);
2514
+ }
2515
+ if (!factoryFile.size)
2516
+ return [];
2517
+ const edges = [];
2518
+ const seen = new Set();
2519
+ for (const file of ctx.getAllFiles()) {
2520
+ if ((++scannedFiles & 15) === 0)
2521
+ await onYield();
2522
+ if (!PINIA_CONSUMER_EXT.test(file))
2523
+ continue;
2524
+ const content = ctx.readFile(file);
2525
+ if (!content || !content.includes('Store'))
2526
+ continue;
2527
+ const safe = (0, strip_comments_1.stripCommentsForRegex)(content, /\.(?:jsx?|mjs|cjs)$/.test(file) ? 'javascript' : 'typescript');
2528
+ // 2. Bind store vars in this file: `const <var> = <known-factory>(...)`.
2529
+ const varStore = new Map();
2530
+ PINIA_BIND_RE.lastIndex = 0;
2531
+ let bm;
2532
+ while ((bm = PINIA_BIND_RE.exec(safe))) {
2533
+ const sf = factoryFile.get(bm[2]);
2534
+ if (sf)
2535
+ varStore.set(bm[1], sf);
2536
+ }
2537
+ if (!varStore.size)
2538
+ continue;
2539
+ // 3. Link `<var>.<method>(` → the action function node in the store's file.
2540
+ const nodesInFile = ctx.getNodesInFile(file);
2541
+ const fallbackDispatcher = nodesInFile.find((n) => n.kind === 'component'); // .vue top-level setup
2542
+ PINIA_CALL_RE.lastIndex = 0;
2543
+ let cm;
2544
+ let added = 0;
2545
+ while ((cm = PINIA_CALL_RE.exec(safe)) && added < PINIA_FANOUT_CAP) {
2546
+ const storeFile = varStore.get(cm[1]);
2547
+ if (!storeFile)
2548
+ continue;
2549
+ const method = cm[2];
2550
+ const line = safe.slice(0, cm.index).split('\n').length;
2551
+ const disp = enclosingFn(nodesInFile, line) ?? fallbackDispatcher;
2552
+ if (!disp)
2553
+ continue;
2554
+ const target = ctx
2555
+ .getNodesByName(method)
2556
+ .find((n) => n.kind === 'function' && n.filePath === storeFile);
2557
+ if (!target || target.id === disp.id)
2558
+ continue;
2559
+ const key = `${disp.id}>${target.id}`;
2560
+ if (seen.has(key))
2561
+ continue;
2562
+ seen.add(key);
2563
+ edges.push({
2564
+ source: disp.id,
2565
+ target: target.id,
2566
+ kind: 'calls',
2567
+ line,
2568
+ provenance: 'heuristic',
2569
+ metadata: { synthesizedBy: 'pinia-store', via: method, registeredAt: `${file}:${line}` },
2570
+ });
2571
+ added++;
2572
+ }
2573
+ }
2574
+ return edges;
2575
+ }
2576
+ // ── Vuex string-keyed dispatch / commit bridge ───────────────────────────────
2577
+ // Vuex dispatches actions/mutations by a runtime STRING key: `dispatch('user/login')`
2578
+ // / `commit('SET_TOKEN')` / `this.$store.dispatch('app/toggleDevice')`. The action
2579
+ // & mutation definitions are object-literal methods in store module files (now
2580
+ // extracted as function nodes). Bridge the string key to its node: the LAST `/`
2581
+ // segment is the action/mutation name; the preceding segment is the namespace
2582
+ // (≈ the store module's file). Resolve the name to a function node IN A STORE FILE
2583
+ // (the store-file gate excludes a same-named `api/` helper — `getInfo`/`login`
2584
+ // commonly collide), disambiguated by the namespace appearing in the path (or, for
2585
+ // a root key, the same file — Vuex's local-module `commit('M')` inside an action).
2586
+ const VUEX_DISPATCH_RE = /\b(?:dispatch|commit)\s*\(\s*['"]([A-Za-z][\w/]*)['"]/g;
2587
+ const VUEX_STORE_SIGNAL = /\bdefineStore\b|\bcreateStore\b|\bVuex\b|\bmutations\b|\bactions\b|\bgetters\b|\bnamespaced\b/g;
2588
+ const VUEX_FANOUT_CAP = 120;
2589
+ /** A path segment (dir or filename stem) equals `seg` — `…/modules/user.js` has
2590
+ * the segment `user` for namespace `user`. */
2591
+ function pathHasSegment(filePath, seg) {
2592
+ return new RegExp('[\\\\/]' + seg.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '[\\\\/.]').test(filePath);
2593
+ }
2594
+ async function vuexDispatchEdges(ctx, onYield) {
2595
+ let scannedFiles = 0;
2596
+ const storeFileCache = new Map();
2597
+ const isStoreFile = (file) => {
2598
+ let v = storeFileCache.get(file);
2599
+ if (v === undefined) {
2600
+ const c = ctx.readFile(file);
2601
+ const seen = new Set();
2602
+ if (c) {
2603
+ VUEX_STORE_SIGNAL.lastIndex = 0;
2604
+ let sm;
2605
+ while ((sm = VUEX_STORE_SIGNAL.exec(c))) {
2606
+ seen.add(sm[0]);
2607
+ if (seen.size >= 2)
2608
+ break;
2609
+ }
2610
+ }
2611
+ v = seen.size >= 2;
2612
+ storeFileCache.set(file, v);
2613
+ }
2614
+ return v;
2615
+ };
2616
+ const resolve = (key, dispatchFile) => {
2617
+ const segs = key.split('/');
2618
+ const action = segs[segs.length - 1];
2619
+ const cands = ctx.getNodesByName(action).filter((n) => n.kind === 'function' && isStoreFile(n.filePath));
2620
+ if (!cands.length)
2621
+ return null;
2622
+ if (segs.length > 1) {
2623
+ const mod = segs[segs.length - 2]; // immediate namespace ≈ the module file
2624
+ return cands.find((c) => pathHasSegment(c.filePath, mod)) ?? (cands.length === 1 ? cands[0] : null);
2625
+ }
2626
+ // Root key: a local `commit('M')` inside an action targets the same module file;
2627
+ // otherwise accept only an unambiguous single store-wide match.
2628
+ return cands.find((c) => c.filePath === dispatchFile) ?? (cands.length === 1 ? cands[0] : null);
2629
+ };
2630
+ const edges = [];
2631
+ const seen = new Set();
2632
+ for (const file of ctx.getAllFiles()) {
2633
+ if ((++scannedFiles & 15) === 0)
2634
+ await onYield();
2635
+ if (!PINIA_CONSUMER_EXT.test(file))
2636
+ continue;
2637
+ const content = ctx.readFile(file);
2638
+ if (!content || (!content.includes('dispatch(') && !content.includes('commit(')))
2639
+ continue;
2640
+ const safe = (0, strip_comments_1.stripCommentsForRegex)(content, /\.(?:jsx?|mjs|cjs)$/.test(file) ? 'javascript' : 'typescript');
2641
+ const nodesInFile = ctx.getNodesInFile(file);
2642
+ const fallback = nodesInFile.find((n) => n.kind === 'component'); // .vue top-level
2643
+ VUEX_DISPATCH_RE.lastIndex = 0;
2644
+ let m;
2645
+ let added = 0;
2646
+ while ((m = VUEX_DISPATCH_RE.exec(safe)) && added < VUEX_FANOUT_CAP) {
2647
+ const key = m[1];
2648
+ const line = safe.slice(0, m.index).split('\n').length;
2649
+ const disp = enclosingFn(nodesInFile, line) ?? fallback;
2650
+ if (!disp)
2651
+ continue;
2652
+ const target = resolve(key, file);
2653
+ if (!target || target.id === disp.id)
2654
+ continue;
2655
+ const edgeKey = `${disp.id}>${target.id}`;
2656
+ if (seen.has(edgeKey))
2657
+ continue;
2658
+ seen.add(edgeKey);
2659
+ edges.push({
2660
+ source: disp.id,
2661
+ target: target.id,
2662
+ kind: 'calls',
2663
+ line,
2664
+ provenance: 'heuristic',
2665
+ metadata: { synthesizedBy: 'vuex-dispatch', via: key, registeredAt: `${file}:${line}` },
2666
+ });
2667
+ added++;
2668
+ }
2669
+ }
2670
+ return edges;
2671
+ }
2672
+ // ── Celery task dispatch (Python) ─────────────────────────────────────────────
2673
+ // Celery decouples a task's call site from its body through async dispatch:
2674
+ // # tasks.py
2675
+ // @shared_task # also @app.task / @celery_app.task / @<app>.task / @task
2676
+ // def process(account_ids): ...
2677
+ // # views.py — a DIFFERENT module
2678
+ // process.apply_async(kwargs={...}) # or process.delay(...) — dynamic, no static edge
2679
+ // Bridge it: link the enclosing function/method at each `.delay(`/`.apply_async(` site → the
2680
+ // task function body. Precision rests on the DECORATOR gate — the dispatched name must resolve
2681
+ // to a Python function carrying a celery task decorator (read from the source lines above its
2682
+ // `def`, since the def's own startLine excludes the decorator). A `.delay()` on a non-task
2683
+ // object resolves to no task node → no edge, so a Celery-free repo yields 0. Same-file /
2684
+ // unique-candidate disambiguation like vuex. (Canvas forms — `group(t).delay()`, `t.s()`/`.si()`
2685
+ // — have no single identifier before `.delay`/`.apply_async`, so they're skipped, not mis-bridged.)
2686
+ const CELERY_DISPATCH_RE = /\b([A-Za-z_]\w*)\s*\.\s*(?:delay|apply_async)\s*\(/g;
2687
+ // A task decorator: bare `@shared_task`/`@task` or attribute `@app.task`/`@celery_app.task`,
2688
+ // each optionally called with args. `\b`-bounded and `@`-anchored so `@mytask`, or a symbol
2689
+ // merely named `task`, can't match. No `/g`, so `.test()` is stateless across reuse.
2690
+ const CELERY_TASK_DECORATOR_RE = /@\s*(?:[A-Za-z_][\w.]*\.)?(?:shared_task|task)\b/;
2691
+ const CELERY_PY_EXT = /\.py$/;
2692
+ const CELERY_FANOUT_CAP = 80;
2693
+ const CELERY_DECORATOR_LOOKBACK = 12; // max lines above a `def` to scan for its decorators
2694
+ async function celeryDispatchEdges(ctx, onYield) {
2695
+ let scannedFiles = 0;
2696
+ // Memoize the decorator check per task-candidate node: it reads the file and scans a few
2697
+ // lines above the def. Only called on names that are actually `.delay`/`.apply_async`
2698
+ // receivers, so the candidate set stays small.
2699
+ const taskCache = new Map();
2700
+ const isCeleryTask = (node) => {
2701
+ let v = taskCache.get(node.id);
2702
+ if (v !== undefined)
2703
+ return v;
2704
+ v = false;
2705
+ if (node.kind === 'function' && CELERY_PY_EXT.test(node.filePath)) {
2706
+ const content = ctx.readFile(node.filePath);
2707
+ if (content) {
2708
+ const lines = content.split('\n');
2709
+ // startLine is the `def` line (decorators sit ABOVE it). Walk upward, stopping at the
2710
+ // previous declaration so a non-task def can never inherit the prior def's decorator.
2711
+ const stop = Math.max(0, node.startLine - 1 - CELERY_DECORATOR_LOOKBACK);
2712
+ for (let i = node.startLine - 2; i >= stop; i--) {
2713
+ const t = (lines[i] ?? '').trim();
2714
+ if (/^(?:async\s+def|def|class)\b/.test(t))
2715
+ break; // previous decl → stop
2716
+ if (CELERY_TASK_DECORATOR_RE.test(t)) {
2717
+ v = true;
2718
+ break;
2719
+ }
2720
+ }
2721
+ }
2722
+ }
2723
+ taskCache.set(node.id, v);
2724
+ return v;
2725
+ };
2726
+ const resolve = (name, dispatchFile) => {
2727
+ const cands = ctx.getNodesByName(name).filter((n) => n.kind === 'function' && isCeleryTask(n));
2728
+ if (!cands.length)
2729
+ return null;
2730
+ if (cands.length === 1)
2731
+ return cands[0];
2732
+ // Cross-module name collision: prefer a task defined in the dispatching file, else bail
2733
+ // (ambiguous — precision over recall, like vuex's root-key resolution).
2734
+ return cands.find((c) => c.filePath === dispatchFile) ?? null;
2735
+ };
2736
+ const edges = [];
2737
+ const seen = new Set();
2738
+ for (const file of ctx.getAllFiles()) {
2739
+ if ((++scannedFiles & 15) === 0)
2740
+ await onYield();
2741
+ if (!CELERY_PY_EXT.test(file))
2742
+ continue;
2743
+ const content = ctx.readFile(file);
2744
+ if (!content || (!content.includes('.delay(') && !content.includes('.apply_async(')))
2745
+ continue;
2746
+ const safe = (0, strip_comments_1.stripCommentsForRegex)(content, 'python');
2747
+ const nodesInFile = ctx.getNodesInFile(file);
2748
+ CELERY_DISPATCH_RE.lastIndex = 0;
2749
+ let m;
2750
+ let added = 0;
2751
+ while ((m = CELERY_DISPATCH_RE.exec(safe)) && added < CELERY_FANOUT_CAP) {
2752
+ const name = m[1];
2753
+ const line = safe.slice(0, m.index).split('\n').length;
2754
+ const disp = enclosingFn(nodesInFile, line);
2755
+ if (!disp)
2756
+ continue; // module-level dispatch — no source symbol to attribute
2757
+ const target = resolve(name, file);
2758
+ if (!target || target.id === disp.id)
2759
+ continue;
2760
+ const key = `${disp.id}>${target.id}`;
2761
+ if (seen.has(key))
2762
+ continue;
2763
+ seen.add(key);
2764
+ edges.push({
2765
+ source: disp.id,
2766
+ target: target.id,
2767
+ kind: 'calls',
2768
+ line,
2769
+ provenance: 'heuristic',
2770
+ metadata: { synthesizedBy: 'celery-dispatch', via: name, registeredAt: `${file}:${line}` },
2771
+ });
2772
+ added++;
2773
+ }
2774
+ }
2775
+ return edges;
2776
+ }
2777
+ // ── Spring application events (Java) ──────────────────────────────────────────
2778
+ // Spring decouples an event PUBLISHER from its LISTENER(s) through the application
2779
+ // event bus, linked by the EVENT TYPE (not a name):
2780
+ // // SomeService.java
2781
+ // eventPublisher.publishEvent(new PasswordChangedEvent(this, username)); // publish
2782
+ // // RememberMeTokenRevoker.java — a DIFFERENT file
2783
+ // @EventListener(PasswordChangedEvent.class) // listen
2784
+ // public void onPasswordChanged(PasswordChangedEvent event) { ... }
2785
+ // Bridge it: link the enclosing method at each `publishEvent(new XEvent(...))` site →
2786
+ // every listener method of XEvent. Listeners are `@EventListener` / `@TransactionalEventListener`
2787
+ // methods (event type = the first param type, or the `@EventListener(X.class)` value form) and
2788
+ // the older `class … implements ApplicationListener<X> { void onApplicationEvent(X e) }`. Keyed
2789
+ // by exact type name, usually cross-file. A repo with no `@EventListener`/`publishEvent` yields 0.
2790
+ // (Java method nodes INCLUDE their leading annotations in the range — startLine is the first
2791
+ // `@…` line — so the annotation block is scanned DOWNWARD from startLine, bounded to consecutive
2792
+ // `@`-lines so it can't bleed into an adjacent method.)
2793
+ const SPRING_PUBLISH_RE = /\.publishEvent\s*\(\s*new\s+([A-Z][A-Za-z0-9_]*)/g;
2794
+ const SPRING_LISTENER_ANNO_RE = /@(?:EventListener|TransactionalEventListener)\b/;
2795
+ const SPRING_ANNO_TYPE_RE = /@(?:EventListener|TransactionalEventListener)\s*\(\s*([A-Z][A-Za-z0-9_]*)\.class/;
2796
+ const SPRING_APP_LISTENER_RE = /\bApplicationListener\s*</;
2797
+ const SPRING_JAVA_EXT = /\.java$/;
2798
+ const SPRING_FANOUT_CAP = 80;
2799
+ /** The first parameter's type from a Java method `signature` (`"void (XEvent e)"` → `XEvent`).
2800
+ * Skips a leading `final`/`@Anno`, strips generics, and requires a PascalCase class name (event
2801
+ * types are classes) — so a no-arg or primitive-param method yields null. */
2802
+ function springFirstParamType(sig) {
2803
+ if (!sig)
2804
+ return null;
2805
+ const open = sig.indexOf('(');
2806
+ if (open < 0)
2807
+ return null;
2808
+ const close = sig.indexOf(')', open);
2809
+ const inner = sig.slice(open + 1, close < 0 ? sig.length : close).trim();
2810
+ if (!inner)
2811
+ return null;
2812
+ const first = inner.split(',')[0].trim();
2813
+ const toks = first.split(/\s+/).filter((t) => t && t !== 'final' && !t.startsWith('@'));
2814
+ if (toks.length < 2)
2815
+ return null; // need `Type name`
2816
+ const type = toks[toks.length - 2].replace(/<.*$/, ''); // drop generic args
2817
+ return /^[A-Z][A-Za-z0-9_]*$/.test(type) ? type : null;
2818
+ }
2819
+ async function springEventEdges(ctx, onYield) {
2820
+ let scannedFiles = 0;
2821
+ // Pass 1 — event-type → listener methods, scanning only event-relevant files.
2822
+ // This is the ONLY full read sweep: publisher files are recorded here so
2823
+ // pass 2 re-reads just those instead of every .java file again (#1212 —
2824
+ // the double full-repo read was one of the tail's longest unyielded spans).
2825
+ const listeners = new Map();
2826
+ const publisherFiles = [];
2827
+ for (const file of ctx.getAllFiles()) {
2828
+ if ((++scannedFiles & 15) === 0)
2829
+ await onYield();
2830
+ if (!SPRING_JAVA_EXT.test(file))
2831
+ continue;
2832
+ const content = ctx.readFile(file);
2833
+ if (!content)
2834
+ continue;
2835
+ if (content.includes('.publishEvent('))
2836
+ publisherFiles.push(file);
2837
+ const hasAnno = content.includes('@EventListener') || content.includes('@TransactionalEventListener');
2838
+ const hasAppListener = SPRING_APP_LISTENER_RE.test(content);
2839
+ if (!hasAnno && !hasAppListener)
2840
+ continue;
2841
+ const lines = content.split('\n');
2842
+ for (const node of ctx.getNodesInFile(file)) {
2843
+ if (node.kind !== 'method')
2844
+ continue;
2845
+ // Collect this method's own leading annotation block (consecutive `@`-lines from startLine).
2846
+ const annoLines = [];
2847
+ for (let i = node.startLine - 1; i < lines.length && i < node.startLine + 7; i++) {
2848
+ const t = (lines[i] ?? '').trim();
2849
+ if (!t.startsWith('@'))
2850
+ break; // reached the declaration → stop (no bleed into next method)
2851
+ annoLines.push(t);
2852
+ }
2853
+ const head = annoLines.join('\n');
2854
+ const annotated = hasAnno && SPRING_LISTENER_ANNO_RE.test(head);
2855
+ const isAppListener = hasAppListener && node.name === 'onApplicationEvent';
2856
+ if (!annotated && !isAppListener)
2857
+ continue;
2858
+ let type = springFirstParamType(node.signature);
2859
+ if (!type && annotated) {
2860
+ const m = SPRING_ANNO_TYPE_RE.exec(head);
2861
+ if (m)
2862
+ type = m[1];
2863
+ }
2864
+ if (!type)
2865
+ continue;
2866
+ let arr = listeners.get(type);
2867
+ if (!arr) {
2868
+ arr = [];
2869
+ listeners.set(type, arr);
2870
+ }
2871
+ arr.push(node);
2872
+ }
2873
+ }
2874
+ if (!listeners.size)
2875
+ return [];
2876
+ // Pass 2 — link each publishEvent(new XEvent(...)) site → every listener of
2877
+ // XEvent. Only the publisher files recorded in pass 1 are (re-)read.
2878
+ const edges = [];
2879
+ const seen = new Set();
2880
+ for (const file of publisherFiles) {
2881
+ if ((++scannedFiles & 15) === 0)
2882
+ await onYield();
2883
+ const content = ctx.readFile(file);
2884
+ if (!content || !content.includes('.publishEvent('))
2885
+ continue;
2886
+ const safe = (0, strip_comments_1.stripCommentsForRegex)(content, 'java');
2887
+ const nodesInFile = ctx.getNodesInFile(file);
2888
+ SPRING_PUBLISH_RE.lastIndex = 0;
2889
+ let m;
2890
+ let added = 0;
2891
+ while ((m = SPRING_PUBLISH_RE.exec(safe)) && added < SPRING_FANOUT_CAP) {
2892
+ const targets = listeners.get(m[1]);
2893
+ if (!targets || !targets.length)
2894
+ continue;
2895
+ const line = safe.slice(0, m.index).split('\n').length;
2896
+ const disp = enclosingFn(nodesInFile, line);
2897
+ if (!disp)
2898
+ continue;
2899
+ for (const target of targets) {
2900
+ if (target.id === disp.id)
2901
+ continue;
2902
+ const key = `${disp.id}>${target.id}`;
2903
+ if (seen.has(key))
2904
+ continue;
2905
+ seen.add(key);
2906
+ edges.push({
2907
+ source: disp.id,
2908
+ target: target.id,
2909
+ kind: 'calls',
2910
+ line,
2911
+ provenance: 'heuristic',
2912
+ metadata: { synthesizedBy: 'spring-event', via: m[1], registeredAt: `${file}:${line}` },
2913
+ });
2914
+ added++;
2915
+ }
2916
+ }
2917
+ }
2918
+ return edges;
2919
+ }
2920
+ // ── MediatR request/notification dispatch (C#/.NET) ───────────────────────────
2921
+ // MediatR decouples a Send/Publish call site from its Handle method through a mediator,
2922
+ // linked by the request/notification TYPE (the IRequestHandler<T,…> generic):
2923
+ // // CancelOrderCommandHandler.cs — the handler
2924
+ // public class CancelOrderCommandHandler : IRequestHandler<CancelOrderCommand, bool> {
2925
+ // public async Task<bool> Handle(CancelOrderCommand request, CancellationToken ct) { … }
2926
+ // // some controller — the dispatch (usually a DIFFERENT file)
2927
+ // var command = new CancelOrderCommand(orderId); await _mediator.Send(command);
2928
+ // Bridge it: link the enclosing method at each mediator `.Send(x)`/`.Publish(x)` site → the
2929
+ // `Handle` method of the handler for x's type. The sent type is resolved from the argument —
2930
+ // inline `new X(…)`, a local `var v = new X(…)`, or a parameter/local declared `X v` — bounded
2931
+ // to the enclosing method. Precision rests on TWO gates: the receiver must be mediator-ish
2932
+ // (`mediator`/`sender`/`publisher`, so MAUI `MessagingCenter.Send` is ignored) AND the resolved
2933
+ // type must be a known handler request type (so a same-named non-request DTO is never bridged).
2934
+ // C# has no `signature` on method nodes, so the handler's request type is read from the class
2935
+ // base-list source (`: IRequestHandler<X,…>`), not a param signature.
2936
+ const MEDIATR_HANDLER_BASE_RE = /(?:IRequestHandler|INotificationHandler)\s*<\s*([A-Za-z_]\w*)/;
2937
+ const MEDIATR_DISPATCH_RE = /([A-Za-z_][\w.]*)\s*\.\s*(?:Send|Publish)\s*\(\s*(new\s+[A-Z]\w*|[A-Za-z_]\w*)/g;
2938
+ const MEDIATR_RECEIVER_RE = /(?:mediator|sender|publisher)/i;
2939
+ const MEDIATR_CS_EXT = /\.cs$/;
2940
+ const MEDIATR_FANOUT_CAP = 80;
2941
+ const MEDIATR_HANDLER_DECL_LOOKAHEAD = 4; // lines from a class startLine to find a wrapped base list
2942
+ /** The type sent at a MediatR `.Send(arg)`/`.Publish(arg)` site: an inline `new X(…)`, else
2943
+ * `arg` as an identifier resolved within the enclosing method — a `… arg = new X(…)` assignment
2944
+ * (wins), or a parameter/local declared `X arg`. Returns null when the type can't be seen. */
2945
+ function resolveMediatrArgType(arg, lines, methodStart, dispatchLine) {
2946
+ const inl = /^new\s+([A-Z]\w*)/.exec(arg);
2947
+ if (inl)
2948
+ return inl[1];
2949
+ if (!/^[A-Za-z_]\w*$/.test(arg))
2950
+ return null;
2951
+ const assignRe = new RegExp(`\\b${arg}\\b\\s*=\\s*new\\s+([A-Z]\\w*)`);
2952
+ const declRe = new RegExp(`\\b([A-Z]\\w*)\\b\\s+${arg}\\b`);
2953
+ let declType = null;
2954
+ for (let i = Math.max(0, methodStart - 1); i < dispatchLine && i < lines.length; i++) {
2955
+ const ln = lines[i] ?? '';
2956
+ const a = assignRe.exec(ln);
2957
+ if (a)
2958
+ return a[1]; // an explicit `arg = new X` is the most specific — take it
2959
+ if (!declType) {
2960
+ const d = declRe.exec(ln);
2961
+ if (d)
2962
+ declType = d[1]; // a `X arg` declaration — remember, but keep scanning for an assignment
2963
+ }
2964
+ }
2965
+ return declType;
2966
+ }
2967
+ async function mediatrDispatchEdges(ctx, onYield) {
2968
+ let scannedFiles = 0;
2969
+ // Pass 1 — request/notification type → the Handle method of each handler class.
2970
+ const handlers = new Map();
2971
+ for (const file of ctx.getAllFiles()) {
2972
+ if ((++scannedFiles & 15) === 0)
2973
+ await onYield();
2974
+ if (!MEDIATR_CS_EXT.test(file))
2975
+ continue;
2976
+ const content = ctx.readFile(file);
2977
+ if (!content || (!content.includes('IRequestHandler<') && !content.includes('INotificationHandler<')))
2978
+ continue;
2979
+ const lines = content.split('\n');
2980
+ const nodesInFile = ctx.getNodesInFile(file);
2981
+ for (const cls of nodesInFile) {
2982
+ if (cls.kind !== 'class')
2983
+ continue;
2984
+ const decl = lines.slice(cls.startLine - 1, cls.startLine - 1 + MEDIATR_HANDLER_DECL_LOOKAHEAD).join('\n');
2985
+ const m = MEDIATR_HANDLER_BASE_RE.exec(decl);
2986
+ if (!m)
2987
+ continue;
2988
+ const type = m[1];
2989
+ const end = cls.endLine ?? cls.startLine;
2990
+ const handle = nodesInFile.find((n) => n.kind === 'method' && n.name === 'Handle' && n.startLine >= cls.startLine && n.startLine <= end);
2991
+ if (!handle)
2992
+ continue;
2993
+ let arr = handlers.get(type);
2994
+ if (!arr) {
2995
+ arr = [];
2996
+ handlers.set(type, arr);
2997
+ }
2998
+ arr.push(handle);
2999
+ }
3000
+ }
3001
+ if (!handlers.size)
3002
+ return [];
3003
+ // Pass 2 — link each mediator-ish .Send(x)/.Publish(x) → the handler of x's type.
3004
+ const edges = [];
3005
+ const seen = new Set();
3006
+ for (const file of ctx.getAllFiles()) {
3007
+ if ((++scannedFiles & 15) === 0)
3008
+ await onYield();
3009
+ if (!MEDIATR_CS_EXT.test(file))
3010
+ continue;
3011
+ const content = ctx.readFile(file);
3012
+ if (!content || (!content.includes('.Send(') && !content.includes('.Publish(')))
3013
+ continue;
3014
+ const safe = (0, strip_comments_1.stripCommentsForRegex)(content, 'csharp');
3015
+ const safeLines = safe.split('\n');
3016
+ const nodesInFile = ctx.getNodesInFile(file);
3017
+ MEDIATR_DISPATCH_RE.lastIndex = 0;
3018
+ let m;
3019
+ let added = 0;
3020
+ while ((m = MEDIATR_DISPATCH_RE.exec(safe)) && added < MEDIATR_FANOUT_CAP) {
3021
+ if (!MEDIATR_RECEIVER_RE.test(m[1]))
3022
+ continue; // not a mediator (MessagingCenter, HttpClient, …)
3023
+ const line = safe.slice(0, m.index).split('\n').length;
3024
+ const disp = enclosingFn(nodesInFile, line);
3025
+ if (!disp)
3026
+ continue;
3027
+ const type = resolveMediatrArgType(m[2], safeLines, disp.startLine, line);
3028
+ if (!type)
3029
+ continue;
3030
+ const targets = handlers.get(type);
3031
+ if (!targets)
3032
+ continue;
3033
+ for (const target of targets) {
3034
+ if (target.id === disp.id)
3035
+ continue;
3036
+ const key = `${disp.id}>${target.id}`;
3037
+ if (seen.has(key))
3038
+ continue;
3039
+ seen.add(key);
3040
+ edges.push({
3041
+ source: disp.id,
3042
+ target: target.id,
3043
+ kind: 'calls',
3044
+ line,
3045
+ provenance: 'heuristic',
3046
+ metadata: { synthesizedBy: 'mediatr-dispatch', via: type, registeredAt: `${file}:${line}` },
3047
+ });
3048
+ added++;
3049
+ }
3050
+ }
3051
+ }
3052
+ return edges;
3053
+ }
3054
+ // ── Sidekiq job dispatch (Ruby) ───────────────────────────────────────────────
3055
+ // Sidekiq decouples a job's enqueue site from the worker's `perform`, linked by the WORKER
3056
+ // CLASS NAME:
3057
+ // # app/workers/destroy_user_worker.rb
3058
+ // class DestroyUserWorker
3059
+ // include Sidekiq::Worker # or Sidekiq::Job (the modern alias)
3060
+ // def perform(user_id) … end
3061
+ // # app/services/… — a DIFFERENT file
3062
+ // DestroyUserWorker.perform_async(user.id) # also .perform_in(t, …) / .perform_at(t, …)
3063
+ // Bridge it: link the enclosing method at each `Worker.perform_async/_in/_at(…)` site → that
3064
+ // worker's instance `perform`. Name-keyed (like Celery): the receiver class must be a Sidekiq
3065
+ // worker — gated by reading `include Sidekiq::Job|Worker` from the class body, since that mixin
3066
+ // is an external gem module that forms no resolvable edge. ActiveJob's `perform_later`/`_now` is
3067
+ // a different shape and deliberately not matched, so an ActiveJob-only app yields 0.
3068
+ const SIDEKIQ_DISPATCH_RE = /([A-Z][A-Za-z0-9_]*(?:::[A-Z][A-Za-z0-9_]*)*)\s*\.\s*perform_(?:async|in|at)\b/g;
3069
+ const SIDEKIQ_WORKER_RE = /\binclude\s+Sidekiq::(?:Job|Worker)\b/;
3070
+ const SIDEKIQ_RB_EXT = /\.rb$/;
3071
+ const SIDEKIQ_FANOUT_CAP = 80;
3072
+ async function sidekiqDispatchEdges(ctx, onYield) {
3073
+ let scannedFiles = 0;
3074
+ // class node id → its instance `perform` method (null if the class isn't a Sidekiq worker),
3075
+ // memoized. Reads the class body for the mixin; only consulted for actual dispatch receivers.
3076
+ const performCache = new Map();
3077
+ const performOf = (cls) => {
3078
+ let v = performCache.get(cls.id);
3079
+ if (v !== undefined)
3080
+ return v;
3081
+ v = null;
3082
+ const content = ctx.readFile(cls.filePath);
3083
+ if (content) {
3084
+ const end = cls.endLine ?? cls.startLine;
3085
+ const body = content.split('\n').slice(cls.startLine - 1, end).join('\n');
3086
+ if (SIDEKIQ_WORKER_RE.test(body)) {
3087
+ v = ctx.getNodesInFile(cls.filePath).find((n) => n.kind === 'method' && n.name === 'perform' && n.startLine >= cls.startLine && n.startLine <= end) ?? null;
3088
+ }
3089
+ }
3090
+ performCache.set(cls.id, v);
3091
+ return v;
3092
+ };
3093
+ // Resolve a (possibly namespaced) worker reference to its `perform`. A namespaced ref is
3094
+ // matched by EXACT qualified name first, so same-named workers in different namespaces
3095
+ // (forem has four `SendEmailNotificationWorker`s) resolve to the right one; an unqualified
3096
+ // ref falls back to the simple name and links only when a single worker bears it — an
3097
+ // ambiguous collision bails (precision over recall).
3098
+ const resolve = (ref) => {
3099
+ if (ref.includes('::')) {
3100
+ const q = ctx.getNodesByQualifiedName(ref).find((n) => n.kind === 'class' && performOf(n));
3101
+ if (q)
3102
+ return performOf(q);
3103
+ }
3104
+ const workers = ctx.getNodesByName(ref.split('::').pop()).filter((n) => n.kind === 'class' && performOf(n));
3105
+ return workers.length === 1 ? performOf(workers[0]) : null;
3106
+ };
3107
+ const edges = [];
3108
+ const seen = new Set();
3109
+ for (const file of ctx.getAllFiles()) {
3110
+ if ((++scannedFiles & 15) === 0)
3111
+ await onYield();
3112
+ if (!SIDEKIQ_RB_EXT.test(file))
3113
+ continue;
3114
+ const content = ctx.readFile(file);
3115
+ if (!content || !/\.perform_(?:async|in|at)\b/.test(content))
3116
+ continue;
3117
+ const safe = (0, strip_comments_1.stripCommentsForRegex)(content, 'ruby');
3118
+ const nodesInFile = ctx.getNodesInFile(file);
3119
+ SIDEKIQ_DISPATCH_RE.lastIndex = 0;
3120
+ let m;
3121
+ let added = 0;
3122
+ while ((m = SIDEKIQ_DISPATCH_RE.exec(safe)) && added < SIDEKIQ_FANOUT_CAP) {
3123
+ const line = safe.slice(0, m.index).split('\n').length;
3124
+ const disp = enclosingFn(nodesInFile, line);
3125
+ if (!disp)
3126
+ continue;
3127
+ const target = resolve(m[1]);
3128
+ if (!target || target.id === disp.id)
3129
+ continue;
3130
+ const key = `${disp.id}>${target.id}`;
3131
+ if (seen.has(key))
3132
+ continue;
3133
+ seen.add(key);
3134
+ edges.push({
3135
+ source: disp.id,
3136
+ target: target.id,
3137
+ kind: 'calls',
3138
+ line,
3139
+ provenance: 'heuristic',
3140
+ metadata: { synthesizedBy: 'sidekiq-dispatch', via: m[1], registeredAt: `${file}:${line}` },
3141
+ });
3142
+ added++;
3143
+ }
3144
+ }
3145
+ return edges;
3146
+ }
3147
+ // ── Erlang behaviour-callback dispatch ────────────────────────────────────────
3148
+ // An Erlang behaviour is a compile-checked callback contract: the behaviour
3149
+ // module declares `-callback init(...) -> ...`, implementers declare
3150
+ // `-behaviour(B)` and export the callbacks, and the framework side dispatches
3151
+ // through a VARIABLE module — cowboy's `Handler:init(Req, Opts)` and
3152
+ // `Middleware:execute(Req, Env)` folds, ejabberd's `Mod:start/2`. Extraction
3153
+ // deliberately leaves var-module calls silent (no static target), so the flow
3154
+ // breaks at exactly the hop agents ask about (request → handler init). Bridge:
3155
+ //
3156
+ // dispatch site `Var:fn(args…)` → every in-repo implementer of the behaviour
3157
+ // declaring `fn` with the SITE's arity — provided exactly ONE in-repo
3158
+ // behaviour declares (fn, arity); a name+arity collision across behaviours
3159
+ // bails (silent beats wrong) — and the implementer defines and exports `fn`.
3160
+ //
3161
+ // Behaviours are discovered by scanning every Erlang file for `-callback`
3162
+ // declarations (not just `implements` targets), so a behaviour with zero
3163
+ // implementers still participates in the ambiguity gate. Fan-out control: a
3164
+ // mega-behaviour (ejabberd's gen_mod, ~200 mod_* implementers) would mint
3165
+ // hundreds of edges per site that READ as complete coverage while being
3166
+ // arbitrary — above the cap the site is skipped entirely and the boundary
3167
+ // stays visibly dynamic (explore's boundary announcer covers it) instead of
3168
+ // silently truncated.
3169
+ const ERLANG_EXT = /\.(?:erl|hrl)$/;
3170
+ // `Var:fn(` — variable (capitalized) module, lowercase function, immediate
3171
+ // open-paren. The leading char class rejects `?MODULE:fn(` (macro), `a:b(`
3172
+ // (static remote call, already linked), and mid-word matches.
3173
+ const ERLANG_DISPATCH_RE = /(^|[^?\w@'])([A-Z][A-Za-z0-9_@]*):([a-z][A-Za-z0-9_@]*)\(/g;
3174
+ const ERLANG_CALLBACK_DECL_RE = /(^|\n)\s*-callback\s+('[^'\n]+'|[a-z][A-Za-z0-9_@]*)\s*\(/g;
3175
+ const ERLANG_BEHAVIOUR_FANOUT_CAP = 24;
3176
+ /**
3177
+ * Argument count of the call/declaration whose `(` sits at `openIdx` —
3178
+ * top-level commas + 1, `()` → 0, unbalanced/oversized → -1. Skips nested
3179
+ * (), [], {}, <<>> content, `"strings"`, `'atoms'`, and `$c` char literals,
3180
+ * so `-callback init(fun((a, b) -> ok), #{k => v}) -> ok.` counts 2.
3181
+ */
3182
+ function erlangArityAt(src, openIdx) {
3183
+ let depth = 1;
3184
+ let commas = 0;
3185
+ let sawArg = false;
3186
+ const limit = Math.min(src.length, openIdx + 4000);
3187
+ for (let i = openIdx + 1; i < limit; i++) {
3188
+ const ch = src[i];
3189
+ if (ch === '"' || ch === "'") {
3190
+ i++;
3191
+ while (i < limit && src[i] !== ch) {
3192
+ if (src[i] === '\\')
3193
+ i++;
3194
+ i++;
3195
+ }
3196
+ sawArg = true;
3197
+ continue;
3198
+ }
3199
+ if (ch === '$') {
3200
+ i++;
3201
+ if (src[i] === '\\')
3202
+ i++;
3203
+ sawArg = true;
3204
+ continue;
3205
+ }
3206
+ if (ch === '(' || ch === '[' || ch === '{') {
3207
+ depth++;
3208
+ sawArg = true;
3209
+ continue;
3210
+ }
3211
+ if (ch === ')' || ch === ']' || ch === '}') {
3212
+ depth--;
3213
+ if (depth === 0)
3214
+ return sawArg ? commas + 1 : 0;
3215
+ continue;
3216
+ }
3217
+ if (ch === ',' && depth === 1) {
3218
+ commas++;
3219
+ continue;
3220
+ }
3221
+ if (!/\s/.test(ch))
3222
+ sawArg = true;
3223
+ }
3224
+ return -1;
3225
+ }
3226
+ /**
3227
+ * Nix module-system option wiring. A NixOS/home-manager/nix-darwin option is
3228
+ * DECLARED in one module (`options.launchd.user.agents = mkOption { ... }`)
3229
+ * and SET in others (`launchd.user.agents.yabai = { ... }` inside a module's
3230
+ * config) — the connection happens by option-path unification inside the
3231
+ * module-system evaluator, so there is no static call/import edge to follow
3232
+ * and flow questions ("how does services.yabai.enable become a launchd
3233
+ * service?") go dark at the module boundary.
3234
+ *
3235
+ * This pass links each config-write binding to the option declaration whose
3236
+ * path is the longest static-segment prefix of the write path. Precision gates:
3237
+ * - only STATIC segments participate: plain identifiers, plus quoted segments
3238
+ * (`"git/config"`, `"com.apple.dock"`) as opaque verbatim tokens that match
3239
+ * only quote-exactly; an interpolated (`${name}`) segment ends the prefix,
3240
+ * so dynamic paths never match beyond their static head;
3241
+ * - matched prefixes must be ≥2 segments: 1-segment paths would wrongly link
3242
+ * every package's `meta = { ... }` attrset to nixos's `options.meta`;
3243
+ * - a prefix declared in more than one file is ambiguous → no edge (a wrong
3244
+ * edge is worse than none);
3245
+ * - writes physically inside an options block are declaration internals
3246
+ * (types, defaults, examples), never config writes → excluded.
3247
+ * Both declaration spellings register: flat (`options.a.b = ...`) by name, and
3248
+ * nested (`options = { a.b = ...; }`) by line-span containment.
3249
+ */
3250
+ function nixLeadingPlainSegments(name) {
3251
+ const segs = [];
3252
+ let i = 0;
3253
+ const n = name.length;
3254
+ while (i < n) {
3255
+ if (name[i] === '"') {
3256
+ // Quoted segment — an opaque verbatim token (quotes kept, so it can
3257
+ // never collide with a plain identifier). `NSGlobalDomain."com.apple.
3258
+ // mouse.tapBehavior"` must match ITS OWN quoted declaration, not
3259
+ // whichever sibling registered the shared plain prefix first.
3260
+ let j = i + 1;
3261
+ while (j < n && name[j] !== '"') {
3262
+ if (name[j] === '\\')
3263
+ j++;
3264
+ j++;
3265
+ }
3266
+ if (j >= n)
3267
+ return segs; // unterminated — stop at the static head
3268
+ const tok = name.slice(i, j + 1);
3269
+ if (tok.includes('${'))
3270
+ return segs; // interpolated → dynamic → stop
3271
+ segs.push(tok);
3272
+ i = j + 1;
3273
+ if (i >= n)
3274
+ break;
3275
+ if (name[i] !== '.')
3276
+ return segs;
3277
+ i++;
3278
+ continue;
3279
+ }
3280
+ let j = i;
3281
+ while (j < n && name[j] !== '.') {
3282
+ if (name[j] === '"' || (name[j] === '$' && name[j + 1] === '{'))
3283
+ return segs;
3284
+ j++;
3285
+ }
3286
+ const seg = name.slice(i, j);
3287
+ if (!/^[A-Za-z_][A-Za-z0-9_'-]*$/.test(seg))
3288
+ return segs;
3289
+ segs.push(seg);
3290
+ i = j + 1;
3291
+ }
3292
+ return segs;
3293
+ }
3294
+ async function nixOptionPathEdges(queries, onYield) {
3295
+ let scanned255 = 0;
3296
+ // One streaming pass over nix bindings (variables + the odd function-valued
3297
+ // option); memory stays O(bindings-kept), not O(all nodes) (#610).
3298
+ const byFile = new Map();
3299
+ let scanned = 0;
3300
+ for (const kind of ['variable', 'function']) {
3301
+ for (const node of queries.iterateNodesByKind(kind)) {
3302
+ if ((++scanned255 & 63) === 0)
3303
+ await onYield();
3304
+ if ((++scanned & 0x3fff) === 0 && onYield)
3305
+ await onYield();
3306
+ if (node.language !== 'nix')
3307
+ continue;
3308
+ const segs = nixLeadingPlainSegments(node.name);
3309
+ if (segs.length === 0)
3310
+ continue;
3311
+ const rec = {
3312
+ id: node.id,
3313
+ filePath: node.filePath,
3314
+ startLine: node.startLine,
3315
+ endLine: node.endLine,
3316
+ segs,
3317
+ };
3318
+ const arr = byFile.get(node.filePath);
3319
+ if (arr)
3320
+ arr.push(rec);
3321
+ else
3322
+ byFile.set(node.filePath, [rec]);
3323
+ }
3324
+ }
3325
+ // Per file: walk bindings outermost-first with a stack of active option
3326
+ // spans, composing nested declaration paths (`options = { services.foo = {
3327
+ // enable = mkOption ...; }; }` registers services.foo AND services.foo.enable).
3328
+ // An `options` binding nested inside another option span is a SUBMODULE's
3329
+ // own namespace (`attrsOf (submodule { options = ...; })`) — its internals
3330
+ // are not globally addressable, so the sentinel blocks registration below it
3331
+ // while still excluding the region from write candidates.
3332
+ const SUBMODULE = 'submodule';
3333
+ const decls = new Map();
3334
+ const writes = [];
3335
+ const register = (path, rec) => {
3336
+ if (path.length < 2 || path.includes(SUBMODULE))
3337
+ return;
3338
+ const key = path.join('.');
3339
+ const arr = decls.get(key);
3340
+ if (arr)
3341
+ arr.push(rec);
3342
+ else
3343
+ decls.set(key, [rec]);
3344
+ };
3345
+ for (const recs of byFile.values()) {
3346
+ recs.sort((a, b) => a.startLine - b.startLine || b.endLine - a.endLine);
3347
+ const stack = [];
3348
+ for (const rec of recs) {
3349
+ while (stack.length > 0 && stack[stack.length - 1].end < rec.startLine)
3350
+ stack.pop();
3351
+ // Strict containment at line granularity: a one-line nested binding is
3352
+ // indistinguishable from its container, so it stays unclassified (rare
3353
+ // in module code, where option blocks are multi-line).
3354
+ const enclosing = stack.length > 0 &&
3355
+ rec.startLine >= stack[stack.length - 1].start &&
3356
+ rec.endLine <= stack[stack.length - 1].end &&
3357
+ !(rec.startLine === stack[stack.length - 1].start && rec.endLine === stack[stack.length - 1].end)
3358
+ ? stack[stack.length - 1]
3359
+ : null;
3360
+ if (rec.segs[0] === 'options') {
3361
+ const ownPath = rec.segs.slice(1); // [] for the bare `options = { ... }` spelling
3362
+ const prefix = enclosing ? [SUBMODULE] : ownPath;
3363
+ register(prefix, rec);
3364
+ stack.push({ start: rec.startLine, end: rec.endLine, prefix });
3365
+ continue;
3366
+ }
3367
+ if (enclosing) {
3368
+ const composed = [...enclosing.prefix, ...rec.segs];
3369
+ register(composed, rec);
3370
+ stack.push({ start: rec.startLine, end: rec.endLine, prefix: composed });
3371
+ continue;
3372
+ }
3373
+ if (rec.segs.length >= 2) {
3374
+ writes.push(rec);
3375
+ }
3376
+ }
3377
+ }
3378
+ if (decls.size === 0 || writes.length === 0)
3379
+ return [];
3380
+ const edges = [];
3381
+ for (const w of writes) {
3382
+ // `config.services.x = ...` spells the same write with an explicit prefix.
3383
+ const segs = w.segs[0] === 'config' ? w.segs.slice(1) : w.segs;
3384
+ if (segs.length < 2)
3385
+ continue;
3386
+ // Longest prefix wins; an ambiguous longest match does NOT fall back to a
3387
+ // shorter one (that would link `services.nginx.virtualHosts.x` to
3388
+ // `options.services.nginx` when virtualHosts is the contested path).
3389
+ for (let len = Math.min(segs.length, 6); len >= 2; len--) {
3390
+ const candidates = decls.get(segs.slice(0, len).join('.'));
3391
+ if (!candidates || candidates.length === 0)
3392
+ continue;
3393
+ const files = new Set(candidates.map((c) => c.filePath));
3394
+ if (files.size === 1) {
3395
+ const target = candidates[0];
3396
+ if (target.id !== w.id) {
3397
+ edges.push({
3398
+ source: w.id,
3399
+ target: target.id,
3400
+ kind: 'references',
3401
+ line: w.startLine,
3402
+ provenance: 'heuristic',
3403
+ metadata: {
3404
+ synthesizedBy: 'nix-option-path',
3405
+ optionPath: segs.slice(0, len).join('.'),
3406
+ registeredAt: `${target.filePath}:${target.startLine}`,
3407
+ },
3408
+ });
3409
+ }
3410
+ }
3411
+ break; // longest hit decides, matched or ambiguous
3412
+ }
3413
+ }
3414
+ return edges;
3415
+ }
3416
+ async function erlangBehaviourDispatchEdges(queries, ctx, onYield) {
3417
+ let scannedFiles = 0;
3418
+ let scanned255 = 0;
3419
+ // Cheap language gate: no Erlang modules → no cost beyond one streamed
3420
+ // kind scan (never a materialized array of every namespace — #1212).
3421
+ const erlangModules = [];
3422
+ for (const n of queries.iterateNodesByKind('namespace')) {
3423
+ if ((++scanned255 & 63) === 0)
3424
+ await onYield();
3425
+ if (n.language === 'erlang')
3426
+ erlangModules.push(n);
3427
+ }
3428
+ if (erlangModules.length === 0)
3429
+ return [];
3430
+ // Pass 1 — scan every Erlang file with `-callback` decls: behaviour module →
3431
+ // its (name, arity) callback set, and the global `name/arity` → declaring
3432
+ // behaviours map that drives the ambiguity gate.
3433
+ const moduleByFile = new Map();
3434
+ for (const ns of erlangModules) {
3435
+ if (!moduleByFile.has(ns.filePath))
3436
+ moduleByFile.set(ns.filePath, ns);
3437
+ }
3438
+ const declaringBehaviours = new Map(); // `fn/arity` → behaviour namespaces
3439
+ const callbackNames = new Set();
3440
+ for (const file of ctx.getAllFiles()) {
3441
+ if ((++scannedFiles & 15) === 0)
3442
+ await onYield();
3443
+ if (!ERLANG_EXT.test(file))
3444
+ continue;
3445
+ const behaviour = moduleByFile.get(file);
3446
+ if (!behaviour)
3447
+ continue; // a .hrl or module-less file can't be a behaviour
3448
+ const content = ctx.readFile(file);
3449
+ if (!content || !content.includes('-callback'))
3450
+ continue;
3451
+ const safe = (0, strip_comments_1.stripCommentsForRegex)(content, 'erlang');
3452
+ ERLANG_CALLBACK_DECL_RE.lastIndex = 0;
3453
+ let m;
3454
+ while ((m = ERLANG_CALLBACK_DECL_RE.exec(safe))) {
3455
+ const name = m[2].replace(/^'|'$/g, '');
3456
+ const arity = erlangArityAt(safe, m.index + m[0].length - 1);
3457
+ if (arity < 0)
3458
+ continue;
3459
+ const key = `${name}/${arity}`;
3460
+ const arr = declaringBehaviours.get(key);
3461
+ if (arr) {
3462
+ if (!arr.some((b) => b.id === behaviour.id))
3463
+ arr.push(behaviour);
3464
+ }
3465
+ else {
3466
+ declaringBehaviours.set(key, [behaviour]);
3467
+ }
3468
+ callbackNames.add(name);
3469
+ }
3470
+ }
3471
+ if (declaringBehaviours.size === 0)
3472
+ return [];
3473
+ // Implementer target lookup, lazy per (behaviour, fn): implementers come
3474
+ // from the `implements` edges extraction resolved, and the target is the
3475
+ // implementer module's own exported `fn` function node.
3476
+ const targetCache = new Map();
3477
+ const targetsOf = (behaviour, fn) => {
3478
+ const cacheKey = `${behaviour.id}#${fn}`;
3479
+ let targets = targetCache.get(cacheKey);
3480
+ if (targets)
3481
+ return targets;
3482
+ targets = [];
3483
+ for (const e of queries.getIncomingEdges(behaviour.id, ['implements'])) {
3484
+ const impl = queries.getNodeById(e.source);
3485
+ if (!impl || impl.language !== 'erlang' || impl.kind !== 'namespace')
3486
+ continue;
3487
+ const fnNode = ctx
3488
+ .getNodesInFile(impl.filePath)
3489
+ .find((n) => n.kind === 'function' && n.name === fn && n.isExported !== false);
3490
+ if (fnNode)
3491
+ targets.push(fnNode);
3492
+ }
3493
+ targetCache.set(cacheKey, targets);
3494
+ return targets;
3495
+ };
3496
+ // Pass 2 — dispatch sites. Only files containing a var-module call shape are
3497
+ // scanned in full.
3498
+ const edges = [];
3499
+ const seen = new Set();
3500
+ for (const file of ctx.getAllFiles()) {
3501
+ if ((++scannedFiles & 15) === 0)
3502
+ await onYield();
3503
+ if (!ERLANG_EXT.test(file))
3504
+ continue;
3505
+ const content = ctx.readFile(file);
3506
+ if (!content || !/[A-Z][A-Za-z0-9_@]*:[a-z]/.test(content))
3507
+ continue;
3508
+ const safe = (0, strip_comments_1.stripCommentsForRegex)(content, 'erlang');
3509
+ const nodesInFile = ctx.getNodesInFile(file);
3510
+ ERLANG_DISPATCH_RE.lastIndex = 0;
3511
+ let m;
3512
+ while ((m = ERLANG_DISPATCH_RE.exec(safe))) {
3513
+ const fn = m[3];
3514
+ if (!callbackNames.has(fn))
3515
+ continue;
3516
+ const openIdx = m.index + m[0].length - 1;
3517
+ const arity = erlangArityAt(safe, openIdx);
3518
+ if (arity < 0)
3519
+ continue;
3520
+ const behaviours = declaringBehaviours.get(`${fn}/${arity}`);
3521
+ if (!behaviours || behaviours.length !== 1)
3522
+ continue; // unknown or ambiguous
3523
+ const behaviour = behaviours[0];
3524
+ const targets = targetsOf(behaviour, fn);
3525
+ if (targets.length === 0 || targets.length > ERLANG_BEHAVIOUR_FANOUT_CAP)
3526
+ continue;
3527
+ const line = safe.slice(0, m.index).split('\n').length;
3528
+ const disp = enclosingFn(nodesInFile, line);
3529
+ if (!disp)
3530
+ continue;
3531
+ for (const target of targets) {
3532
+ if (target.id === disp.id)
3533
+ continue;
3534
+ const key = `${disp.id}>${target.id}`;
3535
+ if (seen.has(key))
3536
+ continue;
3537
+ seen.add(key);
3538
+ edges.push({
3539
+ source: disp.id,
3540
+ target: target.id,
3541
+ kind: 'calls',
3542
+ line,
3543
+ provenance: 'heuristic',
3544
+ metadata: {
3545
+ synthesizedBy: 'erlang-behaviour',
3546
+ via: `${behaviour.name}:${fn}/${arity}`,
3547
+ registeredAt: `${file}:${line}`,
3548
+ },
3549
+ });
3550
+ }
3551
+ }
3552
+ }
3553
+ return edges;
3554
+ }
3555
+ // ── Laravel events (PHP) ──────────────────────────────────────────────────────
3556
+ // Laravel decouples an event dispatch from its listener(s), linked by the EVENT CLASS:
3557
+ // // app/Events/PlaybackStarted.php + app/Listeners/UpdateLastfmNowPlaying.php
3558
+ // class UpdateLastfmNowPlaying { public function handle(PlaybackStarted $event) { … } }
3559
+ // // a controller / service — a DIFFERENT file
3560
+ // event(new PlaybackStarted($song, $user));
3561
+ // Bridge it: link the enclosing method at each `event(new XEvent(...))` site → every listener's
3562
+ // `handle` for XEvent. Listeners come from TWO registration mechanisms (both real, both needed):
3563
+ // (A) auto-discovery — a `handle(EventType $e)` typed first param (also splits a union A|B);
3564
+ // (B) the `protected $listen = [ XEvent::class => [Listener::class, …] ]` map in an
3565
+ // EventServiceProvider, which also covers a listener whose `handle()` is UNTYPED.
3566
+ // Only `event(new X)` is matched — queued JOBS dispatch via `::dispatch()` and their `handle()`
3567
+ // takes an injected service, never an event type, so jobs are excluded by construction.
3568
+ const LARAVEL_DISPATCH_RE = /\bevent\s*\(\s*new\s+\\?([A-Za-z_][\w\\]*)/g;
3569
+ const LARAVEL_PHP_EXT = /\.php$/;
3570
+ const LARAVEL_FANOUT_CAP = 200;
3571
+ // A `$listen` entry: `Event::class => [Listener::class, …]`, key/values as `::class` or strings.
3572
+ const LISTEN_ENTRY_RE = /(?:([A-Za-z_\\][\w\\]*)::class|'([^']+)'|"([^"]+)")\s*=>\s*\[([^\]]*)\]/g;
3573
+ const LISTEN_CLASS_RE = /(?:([A-Za-z_\\][\w\\]*)::class|'([^']+)'|"([^"]+)")/g;
3574
+ /** Short class name from a PHP reference: `\App\Events\Foo` / `App\Events::Foo` → `Foo`. */
3575
+ function phpSimpleName(s) {
3576
+ return s.replace(/^\\/, '').split('\\').pop().split('::').pop().trim();
3577
+ }
3578
+ /** The first-parameter class type(s) of a `handle(...)` declaration — union-split, short-named,
3579
+ * primitives dropped. `handle(A|B $e)` → [A, B]; `handle(string $x)` / `handle()` → []. */
3580
+ function laravelHandleEventTypes(decl) {
3581
+ const m = /function\s+handle\s*\(\s*(?:\.\.\.\s*)?(\??[A-Za-z_\\][\w\\|]*)\s+&?\s*(?:\.\.\.\s*)?\$/.exec(decl);
3582
+ if (!m)
3583
+ return [];
3584
+ return m[1]
3585
+ .replace(/^\?/, '')
3586
+ .split('|')
3587
+ .map((t) => phpSimpleName(t))
3588
+ .filter((t) => /^[A-Z]\w*$/.test(t));
3589
+ }
3590
+ /** From an opening `[`, the bracket-balanced body up to its matching `]`. */
3591
+ function phpArrayBody(src, openIdx) {
3592
+ let depth = 0;
3593
+ for (let i = openIdx; i < src.length; i++) {
3594
+ if (src[i] === '[')
3595
+ depth++;
3596
+ else if (src[i] === ']' && --depth === 0)
3597
+ return src.slice(openIdx + 1, i);
3598
+ }
3599
+ return null;
3600
+ }
3601
+ async function laravelEventEdges(ctx, onYield) {
3602
+ let scannedFiles = 0;
3603
+ // event short name → its listener `handle` methods (deduped by node id).
3604
+ const listeners = new Map();
3605
+ const add = (event, handle) => {
3606
+ let m = listeners.get(event);
3607
+ if (!m) {
3608
+ m = new Map();
3609
+ listeners.set(event, m);
3610
+ }
3611
+ m.set(handle.id, handle);
3612
+ };
3613
+ const handleOf = (cls) => ctx
3614
+ .getNodesInFile(cls.filePath)
3615
+ .find((n) => n.kind === 'method' && n.name === 'handle'
3616
+ && n.startLine >= cls.startLine && n.startLine <= (cls.endLine ?? cls.startLine)) ?? null;
3617
+ // Pass 1 — build the event→handle map from both registration mechanisms.
3618
+ for (const file of ctx.getAllFiles()) {
3619
+ if ((++scannedFiles & 15) === 0)
3620
+ await onYield();
3621
+ if (!LARAVEL_PHP_EXT.test(file))
3622
+ continue;
3623
+ const content = ctx.readFile(file);
3624
+ if (!content)
3625
+ continue;
3626
+ // (A) typed listener handles — node-driven, so a commented-out method can't leak in.
3627
+ if (content.includes('function handle')) {
3628
+ const lines = content.split('\n');
3629
+ for (const node of ctx.getNodesInFile(file)) {
3630
+ if (node.kind !== 'method' || node.name !== 'handle')
3631
+ continue;
3632
+ const decl = lines.slice(node.startLine - 1, node.startLine + 2).join('\n');
3633
+ for (const ev of laravelHandleEventTypes(decl))
3634
+ add(ev, node);
3635
+ }
3636
+ }
3637
+ // (B) the EventServiceProvider `$listen` map — parsed from comment-stripped source so a
3638
+ // fully-commented map (firefly's, on auto-discovery) contributes nothing.
3639
+ if (content.includes('$listen')) {
3640
+ const safe = (0, strip_comments_1.stripCommentsForRegex)(content, 'php');
3641
+ const decl = safe.search(/\$listen\s*=\s*\[/);
3642
+ const body = decl >= 0 ? phpArrayBody(safe, safe.indexOf('[', decl)) : null;
3643
+ if (body) {
3644
+ LISTEN_ENTRY_RE.lastIndex = 0;
3645
+ let em;
3646
+ while ((em = LISTEN_ENTRY_RE.exec(body))) {
3647
+ const event = phpSimpleName(em[1] ?? em[2] ?? em[3] ?? '');
3648
+ LISTEN_CLASS_RE.lastIndex = 0;
3649
+ let lm;
3650
+ while ((lm = LISTEN_CLASS_RE.exec(em[4]))) {
3651
+ const ln = phpSimpleName(lm[1] ?? lm[2] ?? lm[3] ?? '');
3652
+ const cls = ctx.getNodesByName(ln).find((n) => n.kind === 'class' && handleOf(n));
3653
+ if (cls)
3654
+ add(event, handleOf(cls));
3655
+ }
3656
+ }
3657
+ }
3658
+ }
3659
+ }
3660
+ if (!listeners.size)
3661
+ return [];
3662
+ // Pass 2 — link each event(new X(...)) site → every listener of X.
3663
+ const edges = [];
3664
+ const seen = new Set();
3665
+ for (const file of ctx.getAllFiles()) {
3666
+ if ((++scannedFiles & 15) === 0)
3667
+ await onYield();
3668
+ if (!LARAVEL_PHP_EXT.test(file))
3669
+ continue;
3670
+ const content = ctx.readFile(file);
3671
+ if (!content || !content.includes('event('))
3672
+ continue;
3673
+ const safe = (0, strip_comments_1.stripCommentsForRegex)(content, 'php');
3674
+ const nodesInFile = ctx.getNodesInFile(file);
3675
+ LARAVEL_DISPATCH_RE.lastIndex = 0;
3676
+ let m;
3677
+ let added = 0;
3678
+ while ((m = LARAVEL_DISPATCH_RE.exec(safe)) && added < LARAVEL_FANOUT_CAP) {
3679
+ const targets = listeners.get(phpSimpleName(m[1]));
3680
+ if (!targets)
3681
+ continue;
3682
+ const line = safe.slice(0, m.index).split('\n').length;
3683
+ const disp = enclosingFn(nodesInFile, line);
3684
+ if (!disp)
3685
+ continue;
3686
+ for (const target of targets.values()) {
3687
+ if (target.id === disp.id)
3688
+ continue;
3689
+ const key = `${disp.id}>${target.id}`;
3690
+ if (seen.has(key))
3691
+ continue;
3692
+ seen.add(key);
3693
+ edges.push({
3694
+ source: disp.id,
3695
+ target: target.id,
3696
+ kind: 'calls',
3697
+ line,
3698
+ provenance: 'heuristic',
3699
+ metadata: { synthesizedBy: 'laravel-event', via: phpSimpleName(m[1]), registeredAt: `${file}:${line}` },
3700
+ });
3701
+ added++;
3702
+ }
3703
+ }
3704
+ }
3705
+ return edges;
3706
+ }
3707
+ /**
3708
+ * Synthesize dispatcher→callback edges (field observers + EventEmitters +
3709
+ * React re-render + JSX children + Vue templates + SvelteKit load + RN event
3710
+ * channel + Fabric native-impl + MyBatis Java↔XML + Gin middleware chain +
3711
+ * Redux-thunk dispatch chain + object-literal registry dispatch + RTK Query
3712
+ * generated-hook → endpoint + Pinia useStore().action() + Vuex string dispatch +
3713
+ * Celery task .delay()/.apply_async() → task body + Spring publishEvent → @EventListener +
3714
+ * MediatR Send/Publish → IRequestHandler/INotificationHandler +
3715
+ * Sidekiq Worker.perform_async → #perform + Laravel event(new X) → listener handle).
3716
+ * Returns the count added. Never throws into indexing — callers wrap in try/catch.
3717
+ */
3718
+ async function synthesizeCallbackEdges(queries, ctx) {
3719
+ // Each sub-pass below is a whole-graph scan, and there are ~30 of them, all
3720
+ // running synchronously on the indexer's main thread. Their AGGREGATE can run
3721
+ // for well over a minute on a large repo — long enough for the #850 liveness
3722
+ // watchdog to SIGKILL the process mid-index (#1091), since its heartbeat lives
3723
+ // on this same thread. Yield between passes so the heartbeat can fire; a pass
3724
+ // that itself hangs (a real wedge) never reaches the next yield, so the
3725
+ // watchdog still catches that. See ./cooperative-yield.
3726
+ const yieldToLoop = (0, cooperative_yield_1.createYielder)();
3727
+ // Per-pass wall-clock timing to stderr, opt-in via CODEGRAPH_SYNTH_TIMINGS
3728
+ // (=1: passes over 250ms; =all: every pass). This is the diagnostic that
3729
+ // located both the #1091/#1122 watchdog stalls and the #1212 OOM — keep it.
3730
+ const markT = { t: Date.now() };
3731
+ const __mark = (label) => {
3732
+ const now = Date.now();
3733
+ const dt = now - markT.t;
3734
+ markT.t = now;
3735
+ if (process.env.CODEGRAPH_SYNTH_TIMINGS && (dt > 250 || process.env.CODEGRAPH_SYNTH_TIMINGS === 'all')) {
3736
+ console.error(`[synth-timing] ${label}: ${dt}ms`);
3737
+ }
3738
+ };
3739
+ // Language gating: one indexed DISTINCT over the files table lets a pass
3740
+ // whose own filters reference a specific language/extension be skipped
3741
+ // outright when the project has no such files — its result is provably
3742
+ // empty, so skipping is behavior-identical and the cost drops to zero
3743
+ // (the Kotlin pass was the OOM culprit on the pure-C Linux kernel, #1212).
3744
+ // Passes without an explicit language filter always run.
3745
+ const langs = queries.getDistinctFileLanguages();
3746
+ const has = (...ls) => ls.some((l) => langs.has(l));
3747
+ const JS_FAMILY = ['typescript', 'javascript', 'tsx', 'jsx'];
3748
+ const NONE = [];
3749
+ // Cross-file Go method→type `contains` edges must be synthesized AND persisted
3750
+ // FIRST: a method declared in a different file from its receiver type is
3751
+ // otherwise orphaned from the struct, and goImplementsEdges (next) derives a
3752
+ // struct's method set from its `contains` edges — so without this it would
3753
+ // under-count the interfaces a cross-file struct satisfies. (#583)
3754
+ const goMethodContains = has('go') ? await goCrossFileMethodContainsEdges(queries, yieldToLoop) : NONE;
3755
+ for (let i = 0; i < goMethodContains.length; i += 2000) {
3756
+ queries.insertEdges(goMethodContains.slice(i, i + 2000));
3757
+ await yieldToLoop();
3758
+ }
3759
+ await yieldToLoop();
3760
+ __mark('goMethodContains');
3761
+ // Go implicit `implements` edges must be synthesized AND persisted next: the
3762
+ // interface-dispatch bridge below reads `implements` edges from the DB, and
3763
+ // Go has none statically. (Other languages already have static implements
3764
+ // edges from extraction, so they don't need this pre-pass.)
3765
+ const goImpl = has('go') ? await goImplementsEdges(queries, yieldToLoop) : NONE;
3766
+ for (let i = 0; i < goImpl.length; i += 2000) {
3767
+ queries.insertEdges(goImpl.slice(i, i + 2000));
3768
+ await yieldToLoop();
3769
+ }
3770
+ await yieldToLoop();
3771
+ __mark('goImplements');
3772
+ const fieldEdges = await fieldChannelEdges(queries, ctx, yieldToLoop);
3773
+ await yieldToLoop();
3774
+ __mark('fieldEdges');
3775
+ const closureCollEdges = await closureCollectionEdges(queries, ctx, yieldToLoop);
3776
+ await yieldToLoop();
3777
+ __mark('closureCollEdges');
3778
+ const emitterEdges = await eventEmitterEdges(ctx, yieldToLoop);
3779
+ await yieldToLoop();
3780
+ __mark('emitterEdges');
3781
+ const renderEdges = await reactRenderEdges(queries, ctx, yieldToLoop);
3782
+ await yieldToLoop();
3783
+ __mark('renderEdges');
3784
+ const jsxEdges = await reactJsxChildEdges(ctx, yieldToLoop);
3785
+ await yieldToLoop();
3786
+ __mark('jsxEdges');
3787
+ const vueEdges = has('vue') ? await vueTemplateEdges(ctx, yieldToLoop) : NONE;
3788
+ await yieldToLoop();
3789
+ __mark('vueEdges');
3790
+ const svelteKitEdges = has('svelte') ? await svelteKitLoadEdges(ctx, yieldToLoop) : NONE;
3791
+ await yieldToLoop();
3792
+ __mark('svelteKitEdges');
3793
+ const pascalEdges = await pascalFormEdges(ctx, yieldToLoop);
3794
+ await yieldToLoop();
3795
+ __mark('pascalEdges');
3796
+ const flutterEdges = has('dart') ? await flutterBuildEdges(queries, ctx, yieldToLoop) : NONE;
3797
+ await yieldToLoop();
3798
+ __mark('flutterEdges');
3799
+ const arkuiStateEdges = has('arkts') ? await arkuiStateBuildEdges(queries, ctx, yieldToLoop) : NONE;
3800
+ await yieldToLoop();
3801
+ __mark('arkuiStateEdges');
3802
+ const arkuiEmitter = has('arkts') ? await arkuiEmitterEdges(ctx, yieldToLoop) : NONE;
3803
+ await yieldToLoop();
3804
+ __mark('arkuiEmitter');
3805
+ const arkuiRoutes = has('arkts') ? await arkuiRouterEdges(ctx, yieldToLoop) : NONE;
3806
+ await yieldToLoop();
3807
+ __mark('arkuiRoutes');
3808
+ const cppEdges = has('cpp') ? await cppOverrideEdges(queries, yieldToLoop) : NONE;
3809
+ await yieldToLoop();
3810
+ __mark('cppEdges');
3811
+ const ifaceEdges = has('java', 'kotlin', 'csharp', 'swift', 'scala', 'go', 'rust', 'arkts', ...JS_FAMILY)
3812
+ ? await interfaceOverrideEdges(queries, yieldToLoop) : NONE;
3813
+ await yieldToLoop();
3814
+ __mark('ifaceEdges');
3815
+ const kotlinExpectActual = has('kotlin') ? await kotlinExpectActualEdges(queries, yieldToLoop) : NONE;
3816
+ await yieldToLoop();
3817
+ __mark('kotlinExpectActual');
3818
+ const goGrpcEdges = has('go') ? await goGrpcStubImplEdges(queries, yieldToLoop) : NONE;
3819
+ await yieldToLoop();
3820
+ __mark('goGrpcEdges');
3821
+ const rnEventEdgesList = has(...JS_FAMILY) ? await rnEventEdges(ctx, yieldToLoop) : NONE;
3822
+ await yieldToLoop();
3823
+ __mark('rnEventEdgesList');
3824
+ const fabricNativeEdges = await fabricNativeImplEdges(ctx, yieldToLoop);
3825
+ await yieldToLoop();
3826
+ __mark('fabricNativeEdges');
3827
+ const expoXPlatEdges = await expoCrossPlatformEdges(queries, yieldToLoop);
3828
+ await yieldToLoop();
3829
+ __mark('expoXPlatEdges');
3830
+ const rnXPlatEdges = await rnCrossPlatformEdges(queries, yieldToLoop);
3831
+ await yieldToLoop();
3832
+ __mark('rnXPlatEdges');
3833
+ const mybatisEdges = has('java', 'kotlin') && has('xml') ? await mybatisJavaXmlEdges(queries, yieldToLoop) : NONE;
3834
+ await yieldToLoop();
3835
+ __mark('mybatisEdges');
3836
+ const ginEdges = has('go') ? await ginMiddlewareChainEdges(queries, ctx, yieldToLoop) : NONE;
3837
+ await yieldToLoop();
3838
+ __mark('ginEdges');
3839
+ const thunkEdges = has(...JS_FAMILY) ? await reduxThunkEdges(queries, ctx, yieldToLoop) : NONE;
3840
+ await yieldToLoop();
3841
+ __mark('thunkEdges');
3842
+ const registryEdges = await objectRegistryEdges(ctx, yieldToLoop);
3843
+ await yieldToLoop();
3844
+ __mark('registryEdges');
3845
+ const rtkEdges = has(...JS_FAMILY) ? await rtkQueryEdges(queries, ctx, yieldToLoop) : NONE;
3846
+ await yieldToLoop();
3847
+ __mark('rtkEdges');
3848
+ const piniaEdges = has('vue', ...JS_FAMILY) ? await piniaStoreEdges(ctx, yieldToLoop) : NONE;
3849
+ await yieldToLoop();
3850
+ __mark('piniaEdges');
3851
+ const vuexEdges = has('vue', ...JS_FAMILY) ? await vuexDispatchEdges(ctx, yieldToLoop) : NONE;
3852
+ await yieldToLoop();
3853
+ __mark('vuexEdges');
3854
+ const celeryEdges = has('python') ? await celeryDispatchEdges(ctx, yieldToLoop) : NONE;
3855
+ await yieldToLoop();
3856
+ __mark('celeryEdges');
3857
+ const springEdges = has('java') ? await springEventEdges(ctx, yieldToLoop) : NONE;
3858
+ await yieldToLoop();
3859
+ __mark('springEdges');
3860
+ const mediatrEdges = has('csharp') ? await mediatrDispatchEdges(ctx, yieldToLoop) : NONE;
3861
+ await yieldToLoop();
3862
+ __mark('mediatrEdges');
3863
+ const sidekiqEdges = has('ruby') ? await sidekiqDispatchEdges(ctx, yieldToLoop) : NONE;
3864
+ await yieldToLoop();
3865
+ __mark('sidekiqEdges');
3866
+ const erlangBehaviourEdges = has('erlang') ? await erlangBehaviourDispatchEdges(queries, ctx, yieldToLoop) : NONE;
3867
+ await yieldToLoop();
3868
+ __mark('erlangBehaviourEdges');
3869
+ const laravelEdges = has('php') ? await laravelEventEdges(ctx, yieldToLoop) : NONE;
3870
+ await yieldToLoop();
3871
+ __mark('laravelEdges');
3872
+ const cFnPtrEdges = has('c', 'cpp') ? await (0, c_fnptr_synthesizer_1.cFnPointerDispatchEdges)(queries, ctx, yieldToLoop) : NONE;
3873
+ await yieldToLoop();
3874
+ __mark('cFnPtrEdges');
3875
+ const goframeEdges = has('go') ? await (0, goframe_synthesizer_1.goframeRouteEdges)(ctx, yieldToLoop) : NONE;
3876
+ await yieldToLoop();
3877
+ __mark('goframeEdges');
3878
+ const nixOptionEdges = has('nix') ? await nixOptionPathEdges(queries, yieldToLoop) : NONE;
3879
+ await yieldToLoop();
3880
+ __mark('nixOptionEdges');
3881
+ const merged = [];
3882
+ const seen = new Set();
3883
+ for (const e of [
3884
+ ...fieldEdges,
3885
+ ...closureCollEdges,
3886
+ ...emitterEdges,
3887
+ ...renderEdges,
3888
+ ...jsxEdges,
3889
+ ...vueEdges,
3890
+ ...svelteKitEdges,
3891
+ ...pascalEdges,
3892
+ ...flutterEdges,
3893
+ ...arkuiStateEdges,
3894
+ ...arkuiEmitter,
3895
+ ...arkuiRoutes,
3896
+ ...cppEdges,
3897
+ ...ifaceEdges,
3898
+ ...kotlinExpectActual,
3899
+ ...goGrpcEdges,
3900
+ ...rnEventEdgesList,
3901
+ ...fabricNativeEdges,
3902
+ ...expoXPlatEdges,
3903
+ ...rnXPlatEdges,
3904
+ ...mybatisEdges,
3905
+ ...ginEdges,
3906
+ ...thunkEdges,
3907
+ ...registryEdges,
3908
+ ...rtkEdges,
3909
+ ...piniaEdges,
3910
+ ...vuexEdges,
3911
+ ...celeryEdges,
3912
+ ...springEdges,
3913
+ ...mediatrEdges,
3914
+ ...sidekiqEdges,
3915
+ ...erlangBehaviourEdges,
3916
+ ...laravelEdges,
3917
+ ...cFnPtrEdges,
3918
+ ...goframeEdges,
3919
+ ...nixOptionEdges,
3920
+ ]) {
3921
+ const key = `${e.source}>${e.target}`;
3922
+ if (seen.has(key))
3923
+ continue;
3924
+ seen.add(key);
3925
+ merged.push(e);
3926
+ }
3927
+ __mark('dedupe-merge');
3928
+ // Chunked insert with yields: on the Linux kernel the merged synthesized
3929
+ // edge set is ~275k rows, and one transaction for all of them was a 20s
3930
+ // unyielded main-thread span (#1212 follow-up) — the last one in the tail.
3931
+ for (let i = 0; i < merged.length; i += 2000) {
3932
+ queries.insertEdges(merged.slice(i, i + 2000));
3933
+ await yieldToLoop();
3934
+ }
3935
+ __mark('insertMergedEdges');
3936
+ return merged.length + goImpl.length + goMethodContains.length;
3937
+ }
3938
+ //# sourceMappingURL=callback-synthesizer.js.map