@vizalice/codegraph 1.5.0

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