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