@stupidloud/codegraph 0.9.5 → 0.9.9

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 (302) hide show
  1. package/README.md +252 -116
  2. package/dist/bin/codegraph.js +52 -82
  3. package/dist/bin/codegraph.js.map +1 -1
  4. package/dist/context/formatter.d.ts.map +1 -1
  5. package/dist/context/formatter.js +25 -6
  6. package/dist/context/formatter.js.map +1 -1
  7. package/dist/context/index.d.ts +22 -0
  8. package/dist/context/index.d.ts.map +1 -1
  9. package/dist/context/index.js +257 -6
  10. package/dist/context/index.js.map +1 -1
  11. package/dist/context/markers.d.ts +19 -0
  12. package/dist/context/markers.d.ts.map +1 -0
  13. package/dist/context/markers.js +22 -0
  14. package/dist/context/markers.js.map +1 -0
  15. package/dist/db/queries.d.ts +88 -0
  16. package/dist/db/queries.d.ts.map +1 -1
  17. package/dist/db/queries.js +251 -7
  18. package/dist/db/queries.js.map +1 -1
  19. package/dist/db/sqlite-adapter.d.ts +7 -0
  20. package/dist/db/sqlite-adapter.d.ts.map +1 -1
  21. package/dist/db/sqlite-adapter.js +3 -0
  22. package/dist/db/sqlite-adapter.js.map +1 -1
  23. package/dist/directory.d.ts.map +1 -1
  24. package/dist/directory.js +6 -20
  25. package/dist/directory.js.map +1 -1
  26. package/dist/extraction/generated-detection.d.ts +30 -0
  27. package/dist/extraction/generated-detection.d.ts.map +1 -0
  28. package/dist/extraction/generated-detection.js +80 -0
  29. package/dist/extraction/generated-detection.js.map +1 -0
  30. package/dist/extraction/grammars.d.ts +17 -1
  31. package/dist/extraction/grammars.d.ts.map +1 -1
  32. package/dist/extraction/grammars.js +65 -1
  33. package/dist/extraction/grammars.js.map +1 -1
  34. package/dist/extraction/index.d.ts +15 -2
  35. package/dist/extraction/index.d.ts.map +1 -1
  36. package/dist/extraction/index.js +206 -98
  37. package/dist/extraction/index.js.map +1 -1
  38. package/dist/extraction/languages/c-cpp.d.ts.map +1 -1
  39. package/dist/extraction/languages/c-cpp.js +45 -0
  40. package/dist/extraction/languages/c-cpp.js.map +1 -1
  41. package/dist/extraction/languages/csharp.d.ts.map +1 -1
  42. package/dist/extraction/languages/csharp.js +2 -1
  43. package/dist/extraction/languages/csharp.js.map +1 -1
  44. package/dist/extraction/languages/go.d.ts.map +1 -1
  45. package/dist/extraction/languages/go.js +18 -2
  46. package/dist/extraction/languages/go.js.map +1 -1
  47. package/dist/extraction/languages/index.d.ts.map +1 -1
  48. package/dist/extraction/languages/index.js +2 -0
  49. package/dist/extraction/languages/index.js.map +1 -1
  50. package/dist/extraction/languages/java.d.ts.map +1 -1
  51. package/dist/extraction/languages/java.js +6 -0
  52. package/dist/extraction/languages/java.js.map +1 -1
  53. package/dist/extraction/languages/kotlin.d.ts.map +1 -1
  54. package/dist/extraction/languages/kotlin.js +6 -0
  55. package/dist/extraction/languages/kotlin.js.map +1 -1
  56. package/dist/extraction/languages/objc.d.ts +3 -0
  57. package/dist/extraction/languages/objc.d.ts.map +1 -0
  58. package/dist/extraction/languages/objc.js +133 -0
  59. package/dist/extraction/languages/objc.js.map +1 -0
  60. package/dist/extraction/mybatis-extractor.d.ts +48 -0
  61. package/dist/extraction/mybatis-extractor.d.ts.map +1 -0
  62. package/dist/extraction/mybatis-extractor.js +198 -0
  63. package/dist/extraction/mybatis-extractor.js.map +1 -0
  64. package/dist/extraction/tree-sitter-types.d.ts +14 -0
  65. package/dist/extraction/tree-sitter-types.d.ts.map +1 -1
  66. package/dist/extraction/tree-sitter.d.ts +84 -0
  67. package/dist/extraction/tree-sitter.d.ts.map +1 -1
  68. package/dist/extraction/tree-sitter.js +681 -20
  69. package/dist/extraction/tree-sitter.js.map +1 -1
  70. package/dist/extraction/vue-extractor.d.ts +15 -0
  71. package/dist/extraction/vue-extractor.d.ts.map +1 -1
  72. package/dist/extraction/vue-extractor.js +88 -0
  73. package/dist/extraction/vue-extractor.js.map +1 -1
  74. package/dist/extraction/wasm-runtime-flags.d.ts.map +1 -1
  75. package/dist/extraction/wasm-runtime-flags.js +1 -0
  76. package/dist/extraction/wasm-runtime-flags.js.map +1 -1
  77. package/dist/graph/traversal.d.ts.map +1 -1
  78. package/dist/graph/traversal.js +5 -2
  79. package/dist/graph/traversal.js.map +1 -1
  80. package/dist/index.d.ts +66 -3
  81. package/dist/index.d.ts.map +1 -1
  82. package/dist/index.js +105 -1
  83. package/dist/index.js.map +1 -1
  84. package/dist/installer/config-writer.d.ts +7 -8
  85. package/dist/installer/config-writer.d.ts.map +1 -1
  86. package/dist/installer/config-writer.js +7 -27
  87. package/dist/installer/config-writer.js.map +1 -1
  88. package/dist/installer/index.d.ts +3 -20
  89. package/dist/installer/index.d.ts.map +1 -1
  90. package/dist/installer/index.js +8 -39
  91. package/dist/installer/index.js.map +1 -1
  92. package/dist/installer/instructions-template.d.ts +11 -21
  93. package/dist/installer/instructions-template.d.ts.map +1 -1
  94. package/dist/installer/instructions-template.js +12 -56
  95. package/dist/installer/instructions-template.js.map +1 -1
  96. package/dist/installer/targets/antigravity.d.ts +57 -0
  97. package/dist/installer/targets/antigravity.d.ts.map +1 -0
  98. package/dist/installer/targets/antigravity.js +308 -0
  99. package/dist/installer/targets/antigravity.js.map +1 -0
  100. package/dist/installer/targets/claude.d.ts +10 -1
  101. package/dist/installer/targets/claude.d.ts.map +1 -1
  102. package/dist/installer/targets/claude.js +25 -40
  103. package/dist/installer/targets/claude.js.map +1 -1
  104. package/dist/installer/targets/codex.d.ts.map +1 -1
  105. package/dist/installer/targets/codex.js +15 -13
  106. package/dist/installer/targets/codex.js.map +1 -1
  107. package/dist/installer/targets/cursor.d.ts.map +1 -1
  108. package/dist/installer/targets/cursor.js +9 -38
  109. package/dist/installer/targets/cursor.js.map +1 -1
  110. package/dist/installer/targets/gemini.d.ts +26 -0
  111. package/dist/installer/targets/gemini.d.ts.map +1 -0
  112. package/dist/installer/targets/gemini.js +167 -0
  113. package/dist/installer/targets/gemini.js.map +1 -0
  114. package/dist/installer/targets/hermes.d.ts.map +1 -1
  115. package/dist/installer/targets/hermes.js +57 -3
  116. package/dist/installer/targets/hermes.js.map +1 -1
  117. package/dist/installer/targets/kiro.d.ts +27 -0
  118. package/dist/installer/targets/kiro.d.ts.map +1 -0
  119. package/dist/installer/targets/kiro.js +178 -0
  120. package/dist/installer/targets/kiro.js.map +1 -0
  121. package/dist/installer/targets/opencode.d.ts.map +1 -1
  122. package/dist/installer/targets/opencode.js +15 -13
  123. package/dist/installer/targets/opencode.js.map +1 -1
  124. package/dist/installer/targets/registry.d.ts.map +1 -1
  125. package/dist/installer/targets/registry.js +6 -0
  126. package/dist/installer/targets/registry.js.map +1 -1
  127. package/dist/installer/targets/shared.d.ts.map +1 -1
  128. package/dist/installer/targets/shared.js +3 -2
  129. package/dist/installer/targets/shared.js.map +1 -1
  130. package/dist/installer/targets/types.d.ts +1 -16
  131. package/dist/installer/targets/types.d.ts.map +1 -1
  132. package/dist/mcp/daemon-paths.d.ts +46 -0
  133. package/dist/mcp/daemon-paths.d.ts.map +1 -0
  134. package/dist/mcp/daemon-paths.js +125 -0
  135. package/dist/mcp/daemon-paths.js.map +1 -0
  136. package/dist/mcp/daemon.d.ts +161 -0
  137. package/dist/mcp/daemon.d.ts.map +1 -0
  138. package/dist/mcp/daemon.js +403 -0
  139. package/dist/mcp/daemon.js.map +1 -0
  140. package/dist/mcp/engine.d.ts +105 -0
  141. package/dist/mcp/engine.d.ts.map +1 -0
  142. package/dist/mcp/engine.js +270 -0
  143. package/dist/mcp/engine.js.map +1 -0
  144. package/dist/mcp/index.d.ts +67 -53
  145. package/dist/mcp/index.d.ts.map +1 -1
  146. package/dist/mcp/index.js +315 -388
  147. package/dist/mcp/index.js.map +1 -1
  148. package/dist/mcp/proxy.d.ts +81 -0
  149. package/dist/mcp/proxy.d.ts.map +1 -0
  150. package/dist/mcp/proxy.js +510 -0
  151. package/dist/mcp/proxy.js.map +1 -0
  152. package/dist/mcp/server-instructions.d.ts +1 -1
  153. package/dist/mcp/server-instructions.d.ts.map +1 -1
  154. package/dist/mcp/server-instructions.js +21 -21
  155. package/dist/mcp/session.d.ts +77 -0
  156. package/dist/mcp/session.d.ts.map +1 -0
  157. package/dist/mcp/session.js +294 -0
  158. package/dist/mcp/session.js.map +1 -0
  159. package/dist/mcp/tools.d.ts +160 -14
  160. package/dist/mcp/tools.d.ts.map +1 -1
  161. package/dist/mcp/tools.js +1622 -322
  162. package/dist/mcp/tools.js.map +1 -1
  163. package/dist/mcp/transport.d.ts +111 -29
  164. package/dist/mcp/transport.d.ts.map +1 -1
  165. package/dist/mcp/transport.js +181 -71
  166. package/dist/mcp/transport.js.map +1 -1
  167. package/dist/mcp/version.d.ts +19 -0
  168. package/dist/mcp/version.d.ts.map +1 -0
  169. package/dist/mcp/version.js +71 -0
  170. package/dist/mcp/version.js.map +1 -0
  171. package/dist/resolution/callback-synthesizer.d.ts +10 -0
  172. package/dist/resolution/callback-synthesizer.d.ts.map +1 -0
  173. package/dist/resolution/callback-synthesizer.js +1300 -0
  174. package/dist/resolution/callback-synthesizer.js.map +1 -0
  175. package/dist/resolution/frameworks/csharp.d.ts.map +1 -1
  176. package/dist/resolution/frameworks/csharp.js +36 -8
  177. package/dist/resolution/frameworks/csharp.js.map +1 -1
  178. package/dist/resolution/frameworks/drupal.d.ts.map +1 -1
  179. package/dist/resolution/frameworks/drupal.js +44 -12
  180. package/dist/resolution/frameworks/drupal.js.map +1 -1
  181. package/dist/resolution/frameworks/expo-modules.d.ts +3 -0
  182. package/dist/resolution/frameworks/expo-modules.d.ts.map +1 -0
  183. package/dist/resolution/frameworks/expo-modules.js +143 -0
  184. package/dist/resolution/frameworks/expo-modules.js.map +1 -0
  185. package/dist/resolution/frameworks/express.d.ts.map +1 -1
  186. package/dist/resolution/frameworks/express.js +102 -19
  187. package/dist/resolution/frameworks/express.js.map +1 -1
  188. package/dist/resolution/frameworks/fabric.d.ts +3 -0
  189. package/dist/resolution/frameworks/fabric.d.ts.map +1 -0
  190. package/dist/resolution/frameworks/fabric.js +354 -0
  191. package/dist/resolution/frameworks/fabric.js.map +1 -0
  192. package/dist/resolution/frameworks/go.d.ts.map +1 -1
  193. package/dist/resolution/frameworks/go.js +6 -3
  194. package/dist/resolution/frameworks/go.js.map +1 -1
  195. package/dist/resolution/frameworks/index.d.ts +5 -0
  196. package/dist/resolution/frameworks/index.d.ts.map +1 -1
  197. package/dist/resolution/frameworks/index.js +25 -1
  198. package/dist/resolution/frameworks/index.js.map +1 -1
  199. package/dist/resolution/frameworks/java.d.ts.map +1 -1
  200. package/dist/resolution/frameworks/java.js +339 -12
  201. package/dist/resolution/frameworks/java.js.map +1 -1
  202. package/dist/resolution/frameworks/laravel.d.ts.map +1 -1
  203. package/dist/resolution/frameworks/laravel.js +17 -8
  204. package/dist/resolution/frameworks/laravel.js.map +1 -1
  205. package/dist/resolution/frameworks/nestjs.d.ts.map +1 -1
  206. package/dist/resolution/frameworks/nestjs.js +324 -0
  207. package/dist/resolution/frameworks/nestjs.js.map +1 -1
  208. package/dist/resolution/frameworks/play.d.ts +19 -0
  209. package/dist/resolution/frameworks/play.d.ts.map +1 -0
  210. package/dist/resolution/frameworks/play.js +111 -0
  211. package/dist/resolution/frameworks/play.js.map +1 -0
  212. package/dist/resolution/frameworks/python.d.ts.map +1 -1
  213. package/dist/resolution/frameworks/python.js +134 -16
  214. package/dist/resolution/frameworks/python.js.map +1 -1
  215. package/dist/resolution/frameworks/react-native.d.ts +3 -0
  216. package/dist/resolution/frameworks/react-native.d.ts.map +1 -0
  217. package/dist/resolution/frameworks/react-native.js +360 -0
  218. package/dist/resolution/frameworks/react-native.js.map +1 -0
  219. package/dist/resolution/frameworks/react.d.ts.map +1 -1
  220. package/dist/resolution/frameworks/react.js +96 -3
  221. package/dist/resolution/frameworks/react.js.map +1 -1
  222. package/dist/resolution/frameworks/ruby.d.ts.map +1 -1
  223. package/dist/resolution/frameworks/ruby.js +106 -2
  224. package/dist/resolution/frameworks/ruby.js.map +1 -1
  225. package/dist/resolution/frameworks/rust.d.ts.map +1 -1
  226. package/dist/resolution/frameworks/rust.js +102 -5
  227. package/dist/resolution/frameworks/rust.js.map +1 -1
  228. package/dist/resolution/frameworks/swift-objc.d.ts +37 -0
  229. package/dist/resolution/frameworks/swift-objc.d.ts.map +1 -0
  230. package/dist/resolution/frameworks/swift-objc.js +252 -0
  231. package/dist/resolution/frameworks/swift-objc.js.map +1 -0
  232. package/dist/resolution/frameworks/swift.d.ts.map +1 -1
  233. package/dist/resolution/frameworks/swift.js +30 -6
  234. package/dist/resolution/frameworks/swift.js.map +1 -1
  235. package/dist/resolution/go-module.d.ts +26 -0
  236. package/dist/resolution/go-module.d.ts.map +1 -0
  237. package/dist/resolution/go-module.js +78 -0
  238. package/dist/resolution/go-module.js.map +1 -0
  239. package/dist/resolution/import-resolver.d.ts +28 -0
  240. package/dist/resolution/import-resolver.d.ts.map +1 -1
  241. package/dist/resolution/import-resolver.js +617 -5
  242. package/dist/resolution/import-resolver.js.map +1 -1
  243. package/dist/resolution/index.d.ts +11 -0
  244. package/dist/resolution/index.d.ts.map +1 -1
  245. package/dist/resolution/index.js +156 -3
  246. package/dist/resolution/index.js.map +1 -1
  247. package/dist/resolution/name-matcher.d.ts.map +1 -1
  248. package/dist/resolution/name-matcher.js +212 -0
  249. package/dist/resolution/name-matcher.js.map +1 -1
  250. package/dist/resolution/swift-objc-bridge.d.ts +134 -0
  251. package/dist/resolution/swift-objc-bridge.d.ts.map +1 -0
  252. package/dist/resolution/swift-objc-bridge.js +256 -0
  253. package/dist/resolution/swift-objc-bridge.js.map +1 -0
  254. package/dist/resolution/types.d.ts +44 -0
  255. package/dist/resolution/types.d.ts.map +1 -1
  256. package/dist/resolution/workspace-packages.d.ts +48 -0
  257. package/dist/resolution/workspace-packages.d.ts.map +1 -0
  258. package/dist/resolution/workspace-packages.js +208 -0
  259. package/dist/resolution/workspace-packages.js.map +1 -0
  260. package/dist/search/query-utils.d.ts +18 -0
  261. package/dist/search/query-utils.d.ts.map +1 -1
  262. package/dist/search/query-utils.js +30 -0
  263. package/dist/search/query-utils.js.map +1 -1
  264. package/dist/sync/git-hooks.d.ts.map +1 -1
  265. package/dist/sync/git-hooks.js +2 -0
  266. package/dist/sync/git-hooks.js.map +1 -1
  267. package/dist/sync/index.d.ts +3 -1
  268. package/dist/sync/index.d.ts.map +1 -1
  269. package/dist/sync/index.js +8 -1
  270. package/dist/sync/index.js.map +1 -1
  271. package/dist/sync/watcher.d.ts +212 -8
  272. package/dist/sync/watcher.d.ts.map +1 -1
  273. package/dist/sync/watcher.js +465 -51
  274. package/dist/sync/watcher.js.map +1 -1
  275. package/dist/sync/worktree.d.ts +54 -0
  276. package/dist/sync/worktree.d.ts.map +1 -0
  277. package/dist/sync/worktree.js +137 -0
  278. package/dist/sync/worktree.js.map +1 -0
  279. package/dist/types.d.ts +9 -1
  280. package/dist/types.d.ts.map +1 -1
  281. package/dist/types.js +3 -0
  282. package/dist/types.js.map +1 -1
  283. package/package.json +1 -1
  284. package/scripts/agent-eval/arms-F.sh +21 -0
  285. package/scripts/agent-eval/arms-matrix.sh +37 -0
  286. package/scripts/agent-eval/bench-readme.sh +28 -0
  287. package/scripts/agent-eval/bench-why-repo.sh +22 -0
  288. package/scripts/agent-eval/block-read-hook.sh +19 -0
  289. package/scripts/agent-eval/hook-settings.json +15 -0
  290. package/scripts/agent-eval/itrun.sh +24 -11
  291. package/scripts/agent-eval/parse-arms.mjs +116 -0
  292. package/scripts/agent-eval/parse-bench-readme.mjs +84 -0
  293. package/scripts/agent-eval/probe-context.mjs +21 -0
  294. package/scripts/agent-eval/probe-explore.mjs +40 -0
  295. package/scripts/agent-eval/probe-node.mjs +20 -0
  296. package/scripts/agent-eval/probe-sweep.mjs +119 -0
  297. package/scripts/agent-eval/probe-trace.mjs +20 -0
  298. package/scripts/agent-eval/run-arms.sh +56 -0
  299. package/scripts/agent-eval/seq-matrix.mjs +137 -0
  300. package/scripts/npm-sdk.js +75 -0
  301. package/scripts/pack-npm.sh +25 -1
  302. package/scripts/prepare-release.mjs +270 -0
@@ -0,0 +1,1300 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.synthesizeCallbackEdges = synthesizeCallbackEdges;
4
+ const generated_detection_1 = require("../extraction/generated-detection");
5
+ const strip_comments_1 = require("./strip-comments");
6
+ const REGISTRAR_NAME = /^(on[A-Z]\w*|subscribe|addListener|addEventListener|register|watch|listen|addCallback)$/;
7
+ const DISPATCHER_NAME = /(emit|trigger|notify|dispatch|fire|publish|flush)/i;
8
+ const MAX_CALLBACKS_PER_CHANNEL = 40;
9
+ const EVENT_FANOUT_CAP = 6; // skip events with more handlers/dispatchers than this (too generic without type info)
10
+ const ON_RE = /\.(?:on|once|addListener)\(\s*['"]([^'"]+)['"]\s*,\s*(?:function\s+(\w+)|(?:this\.)?(\w+))/g;
11
+ const EMIT_RE = /\.(?:emit|fire|dispatchEvent)\(\s*['"]([^'"]+)['"]/g;
12
+ const SETSTATE_RE = /this\.setState\s*\(/;
13
+ const FLUTTER_SETSTATE_RE = /\bsetState\s*\(/; // Flutter: setState((){…}) / this.setState
14
+ const JSX_TAG_RE = /<([A-Z][A-Za-z0-9_]*)[\s/>]/g;
15
+ const MAX_JSX_CHILDREN = 30;
16
+ // Vue SFC templates: kebab-case child components (<el-button> → ElButton) and
17
+ // event bindings (@click="fn" / v-on:click="fn"). PascalCase children (<VPNav/>)
18
+ // are already caught by JSX_TAG_RE via the SFC component node.
19
+ const VUE_KEBAB_RE = /<([a-z][a-z0-9]*(?:-[a-z0-9]+)+)[\s/>]/g;
20
+ const VUE_HANDLER_RE = /(?:@|v-on:)([a-zA-Z][\w-]*)(?:\.[\w]+)*\s*=\s*"([^"]+)"/g;
21
+ // Composable/hook destructure: `const { close: closeSidebar } = useSidebarControl()`.
22
+ // Captures the destructure body + the called composable; only `use*` calls qualify.
23
+ const VUE_DESTRUCTURE_RE = /(?:const|let|var)\s*\{([^}]+)\}\s*=\s*(\w+)\s*\(/g;
24
+ // Closure-collection dynamic dispatch (language-agnostic, Swift-first). A method
25
+ // appends a closure to a collection property; another method iterates that
26
+ // property *invoking each element* (`coll.forEach { $0() }` / `{ it() }`). The
27
+ // element-invoke (`$0(` / `it(`) PROVES the collection holds closures, so pairing
28
+ // a dispatcher to same-named registrars (`.append`/`.add`/`.push`/`.insert`,
29
+ // incl. Swift `prop.write { $0.append }`) is high-precision. Cross-file/class by
30
+ // design: Alamofire appends in `DataRequest.validate` but iterates in the base
31
+ // `Request.didCompleteTask` — neither same-file nor same-class pairing reaches it.
32
+ const CC_DISPATCH_RE = /(\w+)\.forEach\s*\{\s*(?:\$0|it)\s*\(/g;
33
+ const CC_APPEND_WRITE_RE = /(\w+)\.write\s*\{\s*\$0(?:\.(\w+))?\.(?:append|add|push|insert)\s*\(/g;
34
+ const CC_APPEND_DIRECT_RE = /(\w+)\.(?:append|add|push|insert)\s*\(/g;
35
+ const CC_FANOUT_CAP = 8; // skip a field name with more dispatchers/registrars than this (too generic to pair confidently)
36
+ function kebabToPascal(s) {
37
+ return s.split('-').map((p) => p.charAt(0).toUpperCase() + p.slice(1)).join('');
38
+ }
39
+ function sliceLines(content, startLine, endLine) {
40
+ if (!startLine || !endLine)
41
+ return null;
42
+ return content.split('\n').slice(startLine - 1, endLine).join('\n');
43
+ }
44
+ function registrarField(src) {
45
+ const m = src.match(/this\.(\w+)\.(?:add|push|set)\(/);
46
+ return m ? m[1] : null;
47
+ }
48
+ function dispatcherField(src) {
49
+ const forOf = src.match(/\bof\s+(?:Array\.from\(\s*)?this\.(\w+)/);
50
+ if (forOf && /\b\w+\s*\(/.test(src))
51
+ return forOf[1];
52
+ const forEach = src.match(/this\.(\w+)\.forEach\(/);
53
+ if (forEach)
54
+ return forEach[1];
55
+ return null;
56
+ }
57
+ const FN_KINDS = new Set(['method', 'function', 'component']);
58
+ /** Innermost function/method node whose line range contains `line`. */
59
+ function enclosingFn(nodesInFile, line) {
60
+ let best = null;
61
+ for (const n of nodesInFile) {
62
+ if (!FN_KINDS.has(n.kind))
63
+ continue;
64
+ const end = n.endLine ?? n.startLine;
65
+ if (n.startLine <= line && end >= line) {
66
+ if (!best || n.startLine >= best.startLine)
67
+ best = n; // prefer the tightest (latest-starting) encloser
68
+ }
69
+ }
70
+ return best;
71
+ }
72
+ /**
73
+ * Stream method + function nodes lazily. The synthesizers only scan-and-filter
74
+ * down to a tiny matched subset, so materializing every function/method (which
75
+ * is gigabytes on a symbol-dense project) just to iterate it once is what OOM'd
76
+ * #610. Iterating keeps memory O(1) in the node count.
77
+ */
78
+ function* methodAndFunctionNodes(queries) {
79
+ yield* queries.iterateNodesByKind('method');
80
+ yield* queries.iterateNodesByKind('function');
81
+ }
82
+ /** Phase 1: field-backed observer channels (registrar/dispatcher share a store). */
83
+ function fieldChannelEdges(queries, ctx) {
84
+ const registrars = [];
85
+ const dispatchers = [];
86
+ for (const m of methodAndFunctionNodes(queries)) {
87
+ const isReg = REGISTRAR_NAME.test(m.name);
88
+ const isDisp = DISPATCHER_NAME.test(m.name);
89
+ if (!isReg && !isDisp)
90
+ continue;
91
+ const content = ctx.readFile(m.filePath);
92
+ const src = content && sliceLines(content, m.startLine, m.endLine);
93
+ if (!src)
94
+ continue;
95
+ if (isReg) {
96
+ const f = registrarField(src);
97
+ if (f)
98
+ registrars.push({ node: m, field: f });
99
+ }
100
+ if (isDisp) {
101
+ const f = dispatcherField(src);
102
+ if (f)
103
+ dispatchers.push({ node: m, field: f });
104
+ }
105
+ }
106
+ const edges = [];
107
+ const seen = new Set();
108
+ for (const reg of registrars) {
109
+ const chDispatchers = dispatchers.filter((d) => d.node.filePath === reg.node.filePath && d.field === reg.field);
110
+ if (chDispatchers.length === 0)
111
+ continue;
112
+ const argRe = new RegExp(`${reg.node.name}\\s*\\(\\s*(?:this\\.)?(\\w+)`);
113
+ let added = 0;
114
+ for (const e of queries.getIncomingEdges(reg.node.id, ['calls'])) {
115
+ if (added >= MAX_CALLBACKS_PER_CHANNEL)
116
+ break;
117
+ if (!e.line)
118
+ continue;
119
+ const caller = queries.getNodeById(e.source);
120
+ if (!caller)
121
+ continue;
122
+ const line = ctx.readFile(caller.filePath)?.split('\n')[e.line - 1];
123
+ const am = line?.match(argRe);
124
+ if (!am)
125
+ continue;
126
+ const fn = ctx.getNodesByName(am[1]).find((n) => n.kind === 'method' || n.kind === 'function');
127
+ if (!fn)
128
+ continue;
129
+ for (const disp of chDispatchers) {
130
+ if (disp.node.id === fn.id)
131
+ continue;
132
+ const key = `${disp.node.id}>${fn.id}`;
133
+ if (seen.has(key))
134
+ continue;
135
+ seen.add(key);
136
+ edges.push({
137
+ source: disp.node.id, target: fn.id, kind: 'calls', line: disp.node.startLine,
138
+ provenance: 'heuristic',
139
+ metadata: {
140
+ synthesizedBy: 'callback', via: reg.node.name, field: reg.field,
141
+ // Where the callback was wired up (`scene.onUpdate(this.triggerRender)`).
142
+ // This is the #1 thing an agent reads/greps to explain the flow — surface
143
+ // it so node/trace/context can show it without a callers() + Read round-trip.
144
+ registeredAt: `${caller.filePath}:${e.line}`,
145
+ },
146
+ });
147
+ added++;
148
+ }
149
+ }
150
+ }
151
+ return edges;
152
+ }
153
+ /**
154
+ * Closure-collection dispatch: dispatcher iterates a closure-collection property
155
+ * invoking each element; registrar appends a closure to the same-named property.
156
+ * Emits dispatcher → registrar so a flow reaches the registration site (where the
157
+ * appended closure's body — and its callers — live). High-precision: the
158
+ * dispatcher's element-invoke is the gate (a `.forEach` that does NOT invoke its
159
+ * element is ignored), so a repo with no closure-collection dispatch yields zero
160
+ * edges regardless of how many `.append`/`.push` sites it has.
161
+ *
162
+ * Pairs globally by field name (cross-file/class is required — see Alamofire's
163
+ * base-class `Request.didCompleteTask` iterating `validators` appended by the
164
+ * subclass `DataRequest.validate`), bounded by a fan-out cap so a generic field
165
+ * name shared across unrelated classes can't fan out into noise.
166
+ */
167
+ function closureCollectionEdges(queries, ctx) {
168
+ const dispatchers = new Map(); // field → dispatcher methods + forEach line
169
+ const registrars = new Map(); // field → registrar methods + append line
170
+ const addReg = (field, node, absLine) => {
171
+ if (!field || /^\d+$/.test(field))
172
+ return; // `$0.append` mis-captures the `0`; the write-RE owns that field
173
+ const arr = registrars.get(field) ?? [];
174
+ if (!arr.some((r) => r.node.id === node.id))
175
+ arr.push({ node, line: absLine });
176
+ registrars.set(field, arr);
177
+ };
178
+ for (const m of methodAndFunctionNodes(queries)) {
179
+ const content = ctx.readFile(m.filePath);
180
+ const src = content && sliceLines(content, m.startLine, m.endLine);
181
+ if (!src)
182
+ continue;
183
+ const hasForEach = src.includes('.forEach');
184
+ const hasAppend = src.includes('.append(') || src.includes('.add(') || src.includes('.push(') || src.includes('.insert(');
185
+ if (!hasForEach && !hasAppend)
186
+ continue;
187
+ const lineAt = (idx) => (m.startLine ?? 1) + src.slice(0, idx).split('\n').length - 1;
188
+ if (hasForEach) {
189
+ CC_DISPATCH_RE.lastIndex = 0;
190
+ let d;
191
+ while ((d = CC_DISPATCH_RE.exec(src))) {
192
+ const arr = dispatchers.get(d[1]) ?? [];
193
+ if (!arr.some((n) => n.node.id === m.id))
194
+ arr.push({ node: m, line: lineAt(d.index) });
195
+ dispatchers.set(d[1], arr);
196
+ }
197
+ }
198
+ if (hasAppend) {
199
+ CC_APPEND_WRITE_RE.lastIndex = 0;
200
+ let w;
201
+ while ((w = CC_APPEND_WRITE_RE.exec(src)))
202
+ addReg(w[2] || w[1], m, lineAt(w.index)); // nested `$0.streams` else the `.write` receiver
203
+ CC_APPEND_DIRECT_RE.lastIndex = 0;
204
+ let a;
205
+ while ((a = CC_APPEND_DIRECT_RE.exec(src)))
206
+ addReg(a[1], m, lineAt(a.index));
207
+ }
208
+ }
209
+ const edges = [];
210
+ const seen = new Set();
211
+ for (const [field, disps] of dispatchers) {
212
+ const regs = registrars.get(field);
213
+ if (!regs || regs.length === 0)
214
+ continue;
215
+ if (disps.length > CC_FANOUT_CAP || regs.length > CC_FANOUT_CAP)
216
+ continue; // generic field — can't pair confidently
217
+ for (const disp of disps)
218
+ for (const reg of regs) {
219
+ if (disp.node.id === reg.node.id)
220
+ continue;
221
+ const key = `${disp.node.id}>${reg.node.id}`;
222
+ if (seen.has(key))
223
+ continue;
224
+ seen.add(key);
225
+ edges.push({
226
+ source: disp.node.id, target: reg.node.id, kind: 'calls', line: disp.line,
227
+ provenance: 'heuristic',
228
+ metadata: { synthesizedBy: 'closure-collection', field, registeredAt: `${reg.node.filePath}:${reg.line}` },
229
+ });
230
+ }
231
+ }
232
+ return edges;
233
+ }
234
+ /** Phase 2: string-keyed EventEmitter channels (on('e', fn) ↔ emit('e')). */
235
+ function eventEmitterEdges(ctx) {
236
+ const emitsByEvent = new Map(); // event → dispatcher node ids
237
+ const handlersByEvent = new Map(); // event → handler id → registration site (file:line)
238
+ for (const file of ctx.getAllFiles()) {
239
+ const content = ctx.readFile(file);
240
+ if (!content)
241
+ continue;
242
+ const hasEmit = content.includes('.emit(') || content.includes('.fire(') || content.includes('.dispatchEvent(');
243
+ const hasOn = content.includes('.on(') || content.includes('.once(') || content.includes('.addListener(');
244
+ if (!hasEmit && !hasOn)
245
+ continue;
246
+ const nodesInFile = ctx.getNodesInFile(file);
247
+ const lineOf = (idx) => content.slice(0, idx).split('\n').length;
248
+ if (hasEmit) {
249
+ EMIT_RE.lastIndex = 0;
250
+ let m;
251
+ while ((m = EMIT_RE.exec(content))) {
252
+ const disp = enclosingFn(nodesInFile, lineOf(m.index));
253
+ if (!disp)
254
+ continue;
255
+ const set = emitsByEvent.get(m[1]) ?? new Set();
256
+ set.add(disp.id);
257
+ emitsByEvent.set(m[1], set);
258
+ }
259
+ }
260
+ if (hasOn) {
261
+ ON_RE.lastIndex = 0;
262
+ let m;
263
+ while ((m = ON_RE.exec(content))) {
264
+ const handlerName = m[2] || m[3];
265
+ if (!handlerName)
266
+ continue;
267
+ const handler = ctx.getNodesByName(handlerName).find((n) => n.kind === 'function' || n.kind === 'method');
268
+ if (!handler)
269
+ continue;
270
+ const map = handlersByEvent.get(m[1]) ?? new Map();
271
+ map.set(handler.id, `${file}:${lineOf(m.index)}`);
272
+ handlersByEvent.set(m[1], map);
273
+ }
274
+ }
275
+ }
276
+ const edges = [];
277
+ const seen = new Set();
278
+ for (const [event, dispatchers] of emitsByEvent) {
279
+ const handlers = handlersByEvent.get(event);
280
+ if (!handlers)
281
+ continue;
282
+ // Precision guard: a generic event name with many handlers/dispatchers can't
283
+ // be matched without receiver-type info (Phase 3) — skip rather than over-link.
284
+ if (dispatchers.size > EVENT_FANOUT_CAP || handlers.size > EVENT_FANOUT_CAP)
285
+ continue;
286
+ for (const d of dispatchers)
287
+ for (const [h, registeredAt] of handlers) {
288
+ if (d === h)
289
+ continue;
290
+ const key = `${d}>${h}`;
291
+ if (seen.has(key))
292
+ continue;
293
+ seen.add(key);
294
+ edges.push({ source: d, target: h, kind: 'calls', provenance: 'heuristic', metadata: { synthesizedBy: 'event-emitter', event, registeredAt } });
295
+ }
296
+ }
297
+ return edges;
298
+ }
299
+ /**
300
+ * Phase 4: React class-component re-render. `this.setState(...)` re-runs the
301
+ * component's `render()`, but that hop is React-internal — no static edge — so a
302
+ * flow like "mutation → setState → canvas repaint" dead-ends at setState even
303
+ * though `render → getRenderableElements → …` is fully call-connected after it.
304
+ * Bridge it: for each class that has a `render` method, link every sibling method
305
+ * whose body calls `this.setState(` → `render`. The setState gate keeps this to
306
+ * React class components (a non-React class with a `render` method won't call
307
+ * `this.setState`). Over-approximation (all setState methods reach render) is
308
+ * accepted — it's reachability-correct, like the callback channels.
309
+ */
310
+ function reactRenderEdges(queries, ctx) {
311
+ const edges = [];
312
+ const seen = new Set();
313
+ for (const cls of queries.getNodesByKind('class')) {
314
+ const children = queries.getOutgoingEdges(cls.id, ['contains'])
315
+ .map((e) => queries.getNodeById(e.target))
316
+ .filter((n) => !!n && n.kind === 'method');
317
+ const render = children.find((n) => n.name === 'render');
318
+ if (!render)
319
+ continue;
320
+ let added = 0;
321
+ for (const m of children) {
322
+ if (added >= MAX_CALLBACKS_PER_CHANNEL)
323
+ break;
324
+ if (m.id === render.id)
325
+ continue;
326
+ const content = ctx.readFile(m.filePath);
327
+ const src = content && sliceLines(content, m.startLine, m.endLine);
328
+ if (!src || !SETSTATE_RE.test(src))
329
+ continue;
330
+ const key = `${m.id}>${render.id}`;
331
+ if (seen.has(key))
332
+ continue;
333
+ seen.add(key);
334
+ edges.push({
335
+ source: m.id, target: render.id, kind: 'calls', line: m.startLine,
336
+ provenance: 'heuristic',
337
+ metadata: { synthesizedBy: 'react-render', via: 'setState', registeredAt: `${render.filePath}:${render.startLine}` },
338
+ });
339
+ added++;
340
+ }
341
+ }
342
+ return edges;
343
+ }
344
+ /**
345
+ * Phase 4b: Flutter setState → build (the Dart analog of react-render). In a
346
+ * StatefulWidget's State class, `setState(() {…})` re-runs `build(context)`, but
347
+ * that hop is framework-internal (Flutter calls build), so a flow like
348
+ * "onPressed → _increment → setState → rebuilt UI" dead-ends at setState. Bridge
349
+ * it: for each Dart class with a `build` method, link every sibling method whose
350
+ * body calls `setState(` → `build`. The setState gate + `.dart` file keep this to
351
+ * Flutter State classes. Over-approximation accepted (reachability-correct).
352
+ */
353
+ function flutterBuildEdges(queries, ctx) {
354
+ const edges = [];
355
+ const seen = new Set();
356
+ for (const cls of queries.getNodesByKind('class')) {
357
+ const children = queries.getOutgoingEdges(cls.id, ['contains'])
358
+ .map((e) => queries.getNodeById(e.target))
359
+ .filter((n) => !!n && n.kind === 'method');
360
+ const build = children.find((n) => n.name === 'build');
361
+ if (!build || !build.filePath.endsWith('.dart'))
362
+ continue;
363
+ let added = 0;
364
+ for (const m of children) {
365
+ if (added >= MAX_CALLBACKS_PER_CHANNEL)
366
+ break;
367
+ if (m.id === build.id)
368
+ continue;
369
+ const content = ctx.readFile(m.filePath);
370
+ const src = content && sliceLines(content, m.startLine, m.endLine);
371
+ if (!src || !FLUTTER_SETSTATE_RE.test(src))
372
+ continue;
373
+ const key = `${m.id}>${build.id}`;
374
+ if (seen.has(key))
375
+ continue;
376
+ seen.add(key);
377
+ edges.push({
378
+ source: m.id, target: build.id, kind: 'calls', line: m.startLine,
379
+ provenance: 'heuristic',
380
+ metadata: { synthesizedBy: 'flutter-build', via: 'setState', registeredAt: `${build.filePath}:${build.startLine}` },
381
+ });
382
+ added++;
383
+ }
384
+ }
385
+ return edges;
386
+ }
387
+ /**
388
+ * Phase 4c: C++ virtual override. A call through a base/interface pointer
389
+ * (`db->Get(...)`, `iter->Next()`) dispatches at runtime to a subclass override,
390
+ * but that hop is a vtable indirection — no static call edge — so a flow stops at
391
+ * the abstract base method. Bridge it like react-render: for each C++ class that
392
+ * `extends` a base, link each base method → the subclass method of the same name
393
+ * (the override), so trace/callees from the interface method reach the
394
+ * implementation(s). Over-approximation accepted (reachability-correct); capped
395
+ * per class and gated to C++ to avoid touching other languages' dispatch.
396
+ */
397
+ function cppOverrideEdges(queries) {
398
+ const edges = [];
399
+ const seen = new Set();
400
+ const methodsOf = (classId) => queries
401
+ .getOutgoingEdges(classId, ['contains'])
402
+ .map((e) => queries.getNodeById(e.target))
403
+ .filter((n) => !!n && n.kind === 'method');
404
+ for (const cls of queries.getNodesByKind('class')) {
405
+ const subMethods = methodsOf(cls.id).filter((n) => n.language === 'cpp');
406
+ if (subMethods.length === 0)
407
+ continue;
408
+ for (const ext of queries.getOutgoingEdges(cls.id, ['extends'])) {
409
+ const base = queries.getNodeById(ext.target);
410
+ if (!base || base.language !== 'cpp' || base.id === cls.id)
411
+ continue;
412
+ const baseMethods = new Map(methodsOf(base.id).map((m) => [m.name, m]));
413
+ let added = 0;
414
+ for (const m of subMethods) {
415
+ if (added >= MAX_CALLBACKS_PER_CHANNEL)
416
+ break;
417
+ const bm = baseMethods.get(m.name);
418
+ if (!bm || bm.id === m.id)
419
+ continue;
420
+ const key = `${bm.id}>${m.id}`;
421
+ if (seen.has(key))
422
+ continue;
423
+ seen.add(key);
424
+ edges.push({
425
+ source: bm.id,
426
+ target: m.id,
427
+ kind: 'calls',
428
+ line: bm.startLine,
429
+ provenance: 'heuristic',
430
+ metadata: { synthesizedBy: 'cpp-override', via: m.name, registeredAt: `${m.filePath}:${m.startLine}` },
431
+ });
432
+ added++;
433
+ }
434
+ }
435
+ }
436
+ return edges;
437
+ }
438
+ /**
439
+ * Phase 5.5: interface / abstract dispatch (Java, Kotlin). A call through an
440
+ * injected interface (`@Autowired FooService svc; svc.list()`) or an abstract
441
+ * base dispatches at runtime to the implementing class's override — a vtable
442
+ * indirection with no static call edge — so a request→service flow stops at the
443
+ * interface method. Bridge it like cpp-override: for each class that
444
+ * `implements` an interface (or `extends` an abstract base), link each
445
+ * base/interface method → the class's same-name method (the override) so
446
+ * trace/callees reach the implementation. Over-approximation accepted
447
+ * (reachability-correct); capped per class, gated to JVM languages.
448
+ */
449
+ // Languages whose static `implements`/`extends` edges should bridge an
450
+ // interface (or abstract base) method to the matching concrete-class method.
451
+ // The set is "languages with explicit nominal subtyping and a single class
452
+ // kind that holds methods" — i.e. the shape this loop expects. Swift and
453
+ // Scala fit shape-wise (Swift `protocol`/`class`, Scala `trait`/`class`)
454
+ // and are added below; their concrete-side nodes can be a `struct` (Swift)
455
+ // or an `object` (Scala) so the loop also iterates those kinds.
456
+ const IFACE_OVERRIDE_LANGS = new Set([
457
+ 'java', 'kotlin', 'csharp', 'typescript', 'javascript', 'swift', 'scala',
458
+ ]);
459
+ function interfaceOverrideEdges(queries) {
460
+ const edges = [];
461
+ const seen = new Set();
462
+ const methodsOf = (classId) => queries
463
+ .getOutgoingEdges(classId, ['contains'])
464
+ .map((e) => queries.getNodeById(e.target))
465
+ .filter((n) => !!n && n.kind === 'method');
466
+ // Concrete-side kinds vary by language: `class` covers Java / Kotlin /
467
+ // C# / TS / Swift-classes / Scala-classes; `struct` covers Swift value
468
+ // types that conform to protocols. Iterate both.
469
+ const concreteKinds = ['class', 'struct'];
470
+ for (const kind of concreteKinds) {
471
+ for (const cls of queries.getNodesByKind(kind)) {
472
+ const implMethods = methodsOf(cls.id).filter((n) => IFACE_OVERRIDE_LANGS.has(n.language));
473
+ if (implMethods.length === 0)
474
+ continue;
475
+ for (const sup of queries.getOutgoingEdges(cls.id, ['implements', 'extends'])) {
476
+ const base = queries.getNodeById(sup.target);
477
+ if (!base || !IFACE_OVERRIDE_LANGS.has(base.language) || base.id === cls.id)
478
+ continue;
479
+ // Group impl methods by name to handle OVERLOADS: an interface `list()` and
480
+ // `list(params)` are distinct nodes and a call may resolve to either, so
481
+ // link every base overload → every same-name impl overload (keying by name
482
+ // alone would drop all but one and miss the resolved overload).
483
+ const implByName = new Map();
484
+ for (const m of implMethods) {
485
+ const arr = implByName.get(m.name);
486
+ if (arr)
487
+ arr.push(m);
488
+ else
489
+ implByName.set(m.name, [m]);
490
+ }
491
+ let added = 0;
492
+ for (const bm of methodsOf(base.id)) {
493
+ if (added >= MAX_CALLBACKS_PER_CHANNEL)
494
+ break;
495
+ for (const m of implByName.get(bm.name) ?? []) {
496
+ if (added >= MAX_CALLBACKS_PER_CHANNEL)
497
+ break;
498
+ if (bm.id === m.id)
499
+ continue;
500
+ const key = `${bm.id}>${m.id}`;
501
+ if (seen.has(key))
502
+ continue;
503
+ seen.add(key);
504
+ edges.push({
505
+ source: bm.id,
506
+ target: m.id,
507
+ kind: 'calls',
508
+ line: bm.startLine,
509
+ provenance: 'heuristic',
510
+ metadata: { synthesizedBy: 'interface-impl', via: m.name, registeredAt: `${m.filePath}:${m.startLine}` },
511
+ });
512
+ added++;
513
+ }
514
+ }
515
+ }
516
+ }
517
+ }
518
+ return edges;
519
+ }
520
+ /**
521
+ * Go gRPC stub → impl bridge. The protoc-gen-go-grpc codegen emits an
522
+ * `UnimplementedXxxServer` struct in `*_grpc.pb.go` carrying one method
523
+ * per service RPC; the real handler is a hand-written struct in another
524
+ * file (`x/bank/keeper/msg_server.go::msgServer.Send` in cosmos-sdk).
525
+ * Go's structural typing means no `implements` edge exists for our
526
+ * resolver to follow, so `trace("Send","SendCoins")` lands on the
527
+ * empty stub and reports "no path" (validated empirically — the cosmos
528
+ * Q1 r1 trace failure that drove this work).
529
+ *
530
+ * Bridge: for each `UnimplementedXxxServer` whose RPC-method names are
531
+ * a SUBSET of some other Go struct's method names, emit `calls` edges
532
+ * `stub.method → impl.method` (paired by name). Excludes the gRPC
533
+ * internal markers `mustEmbedUnimplementedXxxServer` and
534
+ * `testEmbeddedByValue`, and skips candidate impls that themselves
535
+ * live in a generated file (their `xxxClient` / sibling stubs would
536
+ * otherwise look like impls).
537
+ *
538
+ * Multiple candidates is allowed and capped at MAX_CALLBACKS_PER_CHANNEL —
539
+ * a service often has both a production impl and one or more test
540
+ * mocks; linking to all preserves trace utility without false-favoring.
541
+ *
542
+ * Provenance: `heuristic`, `synthesizedBy: 'go-grpc-stub-impl'`. The
543
+ * stub's source line is the wiring site shown in the trace trail.
544
+ */
545
+ function goGrpcStubImplEdges(queries) {
546
+ const edges = [];
547
+ const seen = new Set();
548
+ const STUB_RE = /^Unimplemented.*Server$/;
549
+ // gRPC internal-helper methods that appear on every Unimplemented*Server;
550
+ // not part of the service contract, so exclude when computing the RPC-method
551
+ // signature used to match impls.
552
+ const isInternalMarker = (n) => n.startsWith('mustEmbed') || n === 'testEmbeddedByValue';
553
+ // Methods directly contained by each Go struct, name-only. Built once.
554
+ const methodNamesByStruct = new Map();
555
+ const methodNodesByStruct = new Map();
556
+ const goStructs = [];
557
+ for (const s of queries.getNodesByKind('struct')) {
558
+ if (s.language !== 'go')
559
+ continue;
560
+ goStructs.push(s);
561
+ const ms = queries
562
+ .getOutgoingEdges(s.id, ['contains'])
563
+ .map((e) => queries.getNodeById(e.target))
564
+ .filter((n) => !!n && n.kind === 'method');
565
+ methodNodesByStruct.set(s.id, ms);
566
+ methodNamesByStruct.set(s.id, new Set(ms.map((m) => m.name)));
567
+ }
568
+ for (const stub of goStructs) {
569
+ if (!STUB_RE.test(stub.name))
570
+ continue;
571
+ // The stub MUST live in a generated file — that's what tells us this is
572
+ // a protoc-emitted scaffold rather than someone naming a struct
573
+ // `UnimplementedXxxServer` by hand. Without this gate we'd also bridge
574
+ // such hand-written structs and create misleading edges.
575
+ if (!(0, generated_detection_1.isGeneratedFile)(stub.filePath))
576
+ continue;
577
+ const stubMethods = (methodNodesByStruct.get(stub.id) ?? []).filter((m) => !isInternalMarker(m.name));
578
+ if (stubMethods.length === 0)
579
+ continue;
580
+ const stubMethodNames = stubMethods.map((m) => m.name);
581
+ for (const cand of goStructs) {
582
+ if (cand.id === stub.id)
583
+ continue;
584
+ // Skip generated-file candidates — they're siblings (msgClient,
585
+ // UnsafeMsgServer, …) whose method sets coincidentally match.
586
+ if ((0, generated_detection_1.isGeneratedFile)(cand.filePath))
587
+ continue;
588
+ const candNames = methodNamesByStruct.get(cand.id);
589
+ if (!candNames)
590
+ continue;
591
+ // Subset: every RPC method must exist on the candidate by name.
592
+ // Signature-level match would tighten this further, but name-match
593
+ // alone already gives one-to-one pairing in real codebases because
594
+ // gRPC method-name sets are highly distinctive (Send + MultiSend +
595
+ // UpdateParams + SetSendEnabled is unique to bank's MsgServer).
596
+ if (!stubMethodNames.every((n) => candNames.has(n)))
597
+ continue;
598
+ const candMethods = methodNodesByStruct.get(cand.id) ?? [];
599
+ let added = 0;
600
+ for (const sm of stubMethods) {
601
+ if (added >= MAX_CALLBACKS_PER_CHANNEL)
602
+ break;
603
+ for (const cm of candMethods) {
604
+ if (added >= MAX_CALLBACKS_PER_CHANNEL)
605
+ break;
606
+ if (cm.name !== sm.name)
607
+ continue;
608
+ const key = `${sm.id}>${cm.id}`;
609
+ if (seen.has(key))
610
+ continue;
611
+ seen.add(key);
612
+ edges.push({
613
+ source: sm.id,
614
+ target: cm.id,
615
+ kind: 'calls',
616
+ line: sm.startLine,
617
+ provenance: 'heuristic',
618
+ metadata: {
619
+ synthesizedBy: 'go-grpc-stub-impl',
620
+ via: cm.name,
621
+ registeredAt: `${cm.filePath}:${cm.startLine}`,
622
+ },
623
+ });
624
+ added++;
625
+ }
626
+ }
627
+ }
628
+ }
629
+ return edges;
630
+ }
631
+ /**
632
+ * Phase 5: React JSX child rendering. A component that returns `<Child .../>`
633
+ * mounts Child — React calls it — but JSX instantiation isn't a static call edge,
634
+ * so a render tree (App.render → StaticCanvas → renderStaticScene) breaks at the
635
+ * JSX hop. Link parent → each capitalized JSX child it renders. File-oriented
636
+ * (read each JSX file once). Precision gate: the child name must resolve to a
637
+ * component/function/class node — TS generics like `Array<Foo>` resolve to a type
638
+ * (or nothing) and are dropped.
639
+ */
640
+ function reactJsxChildEdges(ctx) {
641
+ const edges = [];
642
+ const seen = new Set();
643
+ const PARENT_KINDS = new Set(['method', 'function', 'component']);
644
+ for (const file of ctx.getAllFiles()) {
645
+ const content = ctx.readFile(file);
646
+ if (!content || (!content.includes('</') && !content.includes('/>')))
647
+ continue; // JSX-file gate
648
+ const parents = ctx.getNodesInFile(file).filter((n) => PARENT_KINDS.has(n.kind));
649
+ for (const parent of parents) {
650
+ const src = sliceLines(content, parent.startLine, parent.endLine);
651
+ if (!src || (!src.includes('</') && !src.includes('/>')))
652
+ continue;
653
+ const names = new Set();
654
+ JSX_TAG_RE.lastIndex = 0;
655
+ let m;
656
+ while ((m = JSX_TAG_RE.exec(src)))
657
+ names.add(m[1]);
658
+ let added = 0;
659
+ for (const name of names) {
660
+ if (added >= MAX_JSX_CHILDREN)
661
+ break;
662
+ const child = ctx.getNodesByName(name).find((n) => n.kind === 'component' || n.kind === 'function' || n.kind === 'class');
663
+ if (!child || child.id === parent.id)
664
+ continue;
665
+ const key = `${parent.id}>${child.id}`;
666
+ if (seen.has(key))
667
+ continue;
668
+ seen.add(key);
669
+ edges.push({
670
+ source: parent.id, target: child.id, kind: 'calls', line: parent.startLine,
671
+ provenance: 'heuristic',
672
+ metadata: { synthesizedBy: 'jsx-render', via: name },
673
+ });
674
+ added++;
675
+ }
676
+ }
677
+ }
678
+ return edges;
679
+ }
680
+ /**
681
+ * Phase 6: Vue SFC templates. The `.vue` extractor only parses `<script>`, so
682
+ * template usage is invisible — child components and event handlers used ONLY in
683
+ * the template have no edge to them. PascalCase children (`<VPNav/>`) are already
684
+ * caught by reactJsxChildEdges (which scans the SFC component node), so this adds
685
+ * the two Vue-specific shapes:
686
+ * - kebab-case children: `<el-button>` → `ElButton` component (renders).
687
+ * - event bindings: `@click="onClick"` / `v-on:submit="save"` → handler method.
688
+ * Scoped to the `<template>` block of `.vue` files; resolution gate (kebab→
689
+ * component, handler→function/method) keeps precision; inline arrows / `$emit`
690
+ * skipped.
691
+ */
692
+ function vueTemplateEdges(ctx) {
693
+ const edges = [];
694
+ const seen = new Set();
695
+ const COMPONENT_KINDS = new Set(['component', 'function', 'class']);
696
+ const HANDLER_KINDS = new Set(['method', 'function']);
697
+ // A composable's returned member may be a fn (`function close(){}`) or an
698
+ // arrow assigned to a const (`const close = () => {}`).
699
+ const RETURN_KINDS = new Set(['method', 'function', 'variable', 'constant']);
700
+ for (const file of ctx.getAllFiles()) {
701
+ if (!file.endsWith('.vue'))
702
+ continue;
703
+ const content = ctx.readFile(file);
704
+ const tpl = content && content.match(/<template[^>]*>([\s\S]*)<\/template>/i)?.[1];
705
+ if (!tpl)
706
+ continue;
707
+ const comp = ctx.getNodesInFile(file).find((n) => n.kind === 'component');
708
+ if (!comp)
709
+ continue;
710
+ // Composable-destructure map: alias → { composable, key }. Lets us resolve a
711
+ // template handler that isn't a local function but a destructured composable
712
+ // return (`@click="closeSidebar"` ← `const { close: closeSidebar } = useSidebarControl()`).
713
+ const script = content.match(/<script[^>]*>([\s\S]*?)<\/script>/i)?.[1] ?? '';
714
+ const destructured = new Map();
715
+ VUE_DESTRUCTURE_RE.lastIndex = 0;
716
+ let dm;
717
+ while ((dm = VUE_DESTRUCTURE_RE.exec(script))) {
718
+ if (!/^use[A-Z]/.test(dm[2]))
719
+ continue; // composables / hooks only
720
+ for (const part of dm[1].split(',')) {
721
+ const pm = part.trim().match(/^(\w+)\s*(?::\s*(\w+))?$/); // key | key: alias
722
+ if (pm)
723
+ destructured.set(pm[2] || pm[1], { composable: dm[2], key: pm[1] });
724
+ }
725
+ }
726
+ let added = 0;
727
+ const addEdge = (target, meta) => {
728
+ if (added >= MAX_JSX_CHILDREN || !target || target.id === comp.id)
729
+ return;
730
+ const k = `${comp.id}>${target.id}>${meta.synthesizedBy}`;
731
+ if (seen.has(k))
732
+ return;
733
+ seen.add(k);
734
+ edges.push({ source: comp.id, target: target.id, kind: 'calls', line: comp.startLine, provenance: 'heuristic', metadata: meta });
735
+ added++;
736
+ };
737
+ // Prefer a target in THIS SFC (handlers live in the same file's script) —
738
+ // avoids cross-file mis-match when a name repeats across a monorepo.
739
+ const resolve = (name, kinds) => {
740
+ const matches = ctx.getNodesByName(name).filter((n) => kinds.has(n.kind));
741
+ return matches.find((n) => n.filePath === file) ?? matches[0];
742
+ };
743
+ let m;
744
+ VUE_KEBAB_RE.lastIndex = 0;
745
+ while ((m = VUE_KEBAB_RE.exec(tpl)))
746
+ addEdge(resolve(kebabToPascal(m[1]), COMPONENT_KINDS), { synthesizedBy: 'jsx-render', via: m[1] });
747
+ VUE_HANDLER_RE.lastIndex = 0;
748
+ while ((m = VUE_HANDLER_RE.exec(tpl))) {
749
+ const event = m[1];
750
+ const expr = m[2].trim();
751
+ if (expr.includes('=>') || expr.startsWith('$'))
752
+ continue; // inline arrow / $emit
753
+ const name = expr.match(/^([A-Za-z_]\w*)/)?.[1];
754
+ if (!name)
755
+ continue;
756
+ const direct = resolve(name, HANDLER_KINDS);
757
+ if (direct) {
758
+ addEdge(direct, { synthesizedBy: 'vue-handler', event });
759
+ continue;
760
+ }
761
+ // Composable-destructure handler → resolve to the composable's returned fn.
762
+ const d = destructured.get(name);
763
+ if (!d)
764
+ continue;
765
+ const composable = resolve(d.composable, HANDLER_KINDS);
766
+ // Resolve to the SPECIFIC returned member (e.g. `close`) defined in the
767
+ // composable's file. No fallback to the composable itself — the component
768
+ // already has a static `useX()` call edge, so that would just be redundant
769
+ // and less precise.
770
+ const keyFn = composable
771
+ ? ctx.getNodesByName(d.key).find((n) => RETURN_KINDS.has(n.kind) && n.filePath === composable.filePath)
772
+ : undefined;
773
+ if (keyFn)
774
+ addEdge(keyFn, { synthesizedBy: 'vue-handler', event, via: d.composable });
775
+ }
776
+ }
777
+ return edges;
778
+ }
779
+ /**
780
+ * React Native cross-language event channel (Phase 3 of the mixed-iOS/RN
781
+ * bridging effort). Same shape as `eventEmitterEdges` but cross-language:
782
+ *
783
+ * Native (ObjC, on RCTEventEmitter subclass):
784
+ * [self sendEventWithName:@"locationUpdate" body:@{...}];
785
+ *
786
+ * Native (Java/Kotlin, via the JS module dispatcher):
787
+ * emitter.emit("locationUpdate", body);
788
+ * reactContext.getJSModule(RCTDeviceEventEmitter.class).emit("locationUpdate", body);
789
+ *
790
+ * JS (subscriber):
791
+ * new NativeEventEmitter(NativeModules.Geo).addListener("locationUpdate", handler);
792
+ * DeviceEventEmitter.addListener("locationUpdate", handler);
793
+ *
794
+ * Synthesize: native dispatch site → JS handler, keyed by the literal
795
+ * event name. Only matches NAMED handlers (the existing `ON_RE` named-
796
+ * capture form). Inline arrow handlers like `addListener('x', d => …)`
797
+ * aren't named at extraction time and would need link-through-body
798
+ * support; matches the deliberate scope of the in-language synthesizer.
799
+ *
800
+ * Provenance `'heuristic'`, synthesizedBy `'rn-event-channel'`.
801
+ */
802
+ // ObjC's `[self sendEventWithName:@"X" body:...]` shape (bracket syntax,
803
+ // `@` string literals).
804
+ const RN_OBJC_SEND_RE = /\bsendEventWithName\s*:\s*@"([^"]+)"/g;
805
+ // Swift's `sendEvent(withName: "X", body: ...)` shape — same RCTEventEmitter
806
+ // method, different call syntax. Both Objective-C and Swift subclass
807
+ // RCTEventEmitter so this catches the Swift-side equivalent emission sites
808
+ // (e.g. RNFusedLocation.swift's `sendEvent(withName: "geolocationDidChange",
809
+ // body: locationData)`).
810
+ const RN_SWIFT_SEND_RE = /\bsendEvent\s*\(\s*withName\s*:\s*"([^"]+)"/g;
811
+ // JVM-side emitter calls: `emitter.emit("X", body)`. Matches both Java
812
+ // and Kotlin syntax because the call form is identical. Restricted to
813
+ // JVM source files in the consumer so we don't re-process JS emits
814
+ // (which `eventEmitterEdges` already handles).
815
+ const RN_JVM_EMIT_RE = /\.emit\s*\(\s*"([^"]+)"\s*,/g;
816
+ function rnEventEdges(ctx) {
817
+ // Native dispatchers (source = the native method whose body sends the
818
+ // event) and JS handlers (target = the function/method registered as
819
+ // the listener) keyed by event name.
820
+ const nativeDispatchersByEvent = new Map();
821
+ const jsHandlersByEvent = new Map();
822
+ for (const file of ctx.getAllFiles()) {
823
+ const content = ctx.readFile(file);
824
+ if (!content)
825
+ continue;
826
+ const nodesInFile = ctx.getNodesInFile(file);
827
+ const lineOf = (idx) => content.slice(0, idx).split('\n').length;
828
+ const addDispatcher = (event, line) => {
829
+ const disp = enclosingFn(nodesInFile, line);
830
+ if (!disp)
831
+ return;
832
+ const set = nativeDispatchersByEvent.get(event) ?? new Set();
833
+ set.add(disp.id);
834
+ nativeDispatchersByEvent.set(event, set);
835
+ };
836
+ // ObjC side: `sendEventWithName:@"X"` only fires inside `.m`/`.mm`
837
+ // files (RCTEventEmitter subclasses).
838
+ if (file.endsWith('.m') || file.endsWith('.mm')) {
839
+ RN_OBJC_SEND_RE.lastIndex = 0;
840
+ let m;
841
+ while ((m = RN_OBJC_SEND_RE.exec(content))) {
842
+ if (m[1])
843
+ addDispatcher(m[1], lineOf(m.index));
844
+ }
845
+ }
846
+ // Swift side: same RCTEventEmitter method, parens/named-args syntax.
847
+ if (file.endsWith('.swift')) {
848
+ RN_SWIFT_SEND_RE.lastIndex = 0;
849
+ let m;
850
+ while ((m = RN_SWIFT_SEND_RE.exec(content))) {
851
+ if (m[1])
852
+ addDispatcher(m[1], lineOf(m.index));
853
+ }
854
+ }
855
+ // JVM side: `.emit("X", …)` in Java/Kotlin. (We pattern-match
856
+ // anywhere in the file; the JS in-language path uses a separate
857
+ // emitter object pattern and is already handled by eventEmitterEdges.)
858
+ if (file.endsWith('.java') || file.endsWith('.kt')) {
859
+ RN_JVM_EMIT_RE.lastIndex = 0;
860
+ let m;
861
+ while ((m = RN_JVM_EMIT_RE.exec(content))) {
862
+ if (m[1])
863
+ addDispatcher(m[1], lineOf(m.index));
864
+ }
865
+ }
866
+ // JS subscribers (.addListener("X", handler)). Restrict to JS-family
867
+ // files so a native file's `addListener:` (the ObjC method) doesn't
868
+ // get mistaken for a JS subscription — they're entirely different
869
+ // things despite sharing a name.
870
+ if (file.endsWith('.js') ||
871
+ file.endsWith('.jsx') ||
872
+ file.endsWith('.ts') ||
873
+ file.endsWith('.tsx') ||
874
+ file.endsWith('.mjs') ||
875
+ file.endsWith('.cjs')) {
876
+ // Match BOTH the named-handler form (`.addListener('x', fn)`) and
877
+ // an unnamed-handler form (`.addListener('x', listener)` where
878
+ // `listener` is a parameter — common in RN wrapper APIs like
879
+ // RNFirebase's `messaging().onMessageReceived(listener)`). For the
880
+ // unnamed case we attribute the subscription to the ENCLOSING JS
881
+ // function (the abstraction layer), giving a reachability-correct
882
+ // hop even when the actual user-side handler lives one call up.
883
+ const ADDLISTENER_ANY = /\.(?:on|once|addListener)\(\s*['"]([^'"]+)['"]\s*,\s*([A-Za-z_][\w.]*)/g;
884
+ ADDLISTENER_ANY.lastIndex = 0;
885
+ let m;
886
+ while ((m = ADDLISTENER_ANY.exec(content))) {
887
+ const event = m[1];
888
+ const arg = m[2];
889
+ if (!event || !arg)
890
+ continue;
891
+ const bareName = arg.includes('.') ? arg.slice(arg.lastIndexOf('.') + 1) : arg;
892
+ // Try a named-symbol match first (matches the in-language semantic).
893
+ const namedHandler = ctx
894
+ .getNodesByName(bareName)
895
+ .find((n) => n.kind === 'function' || n.kind === 'method');
896
+ let targetId = namedHandler?.id ?? null;
897
+ if (!targetId) {
898
+ // Fall back to the enclosing function — the subscribe-wrapper
899
+ // pattern means the event fires THROUGH this function on its
900
+ // way to user code. Reachability-correct attribution.
901
+ const enclosing = enclosingFn(nodesInFile, lineOf(m.index));
902
+ targetId = enclosing?.id ?? null;
903
+ }
904
+ if (!targetId) {
905
+ // Broader fallback for JS object-literal API shape
906
+ // (`const Foo = { watchX(...) { … addListener(...) … } }`):
907
+ // method shorthand inside an object literal isn't extracted
908
+ // as a method node, so enclosingFn returns null. Attribute to
909
+ // the smallest enclosing `constant` / `variable` node — that's
910
+ // the API surface a downstream caller would `import` and
911
+ // invoke. Reachability-correct.
912
+ const line = lineOf(m.index);
913
+ let smallest = null;
914
+ for (const n of nodesInFile) {
915
+ if (n.kind !== 'constant' && n.kind !== 'variable')
916
+ continue;
917
+ const end = n.endLine ?? n.startLine;
918
+ if (n.startLine <= line && end >= line) {
919
+ if (!smallest || n.startLine >= smallest.startLine)
920
+ smallest = n;
921
+ }
922
+ }
923
+ targetId = smallest?.id ?? null;
924
+ }
925
+ if (!targetId)
926
+ continue;
927
+ const map = jsHandlersByEvent.get(event) ?? new Map();
928
+ map.set(targetId, `${file}:${lineOf(m.index)}`);
929
+ jsHandlersByEvent.set(event, map);
930
+ }
931
+ }
932
+ }
933
+ const edges = [];
934
+ const seen = new Set();
935
+ for (const [event, dispatchers] of nativeDispatchersByEvent) {
936
+ const handlers = jsHandlersByEvent.get(event);
937
+ if (!handlers)
938
+ continue;
939
+ // Same fan-out guard as the in-language channel: generic event names
940
+ // (e.g. 'change', 'error', 'data') with many handlers/dispatchers
941
+ // can't be matched precisely without receiver-type info.
942
+ if (dispatchers.size > EVENT_FANOUT_CAP || handlers.size > EVENT_FANOUT_CAP)
943
+ continue;
944
+ for (const d of dispatchers) {
945
+ for (const [h, registeredAt] of handlers) {
946
+ if (d === h)
947
+ continue;
948
+ const key = `${d}>${h}`;
949
+ if (seen.has(key))
950
+ continue;
951
+ seen.add(key);
952
+ edges.push({
953
+ source: d,
954
+ target: h,
955
+ kind: 'calls',
956
+ provenance: 'heuristic',
957
+ metadata: { synthesizedBy: 'rn-event-channel', event, registeredAt },
958
+ });
959
+ }
960
+ }
961
+ }
962
+ return edges;
963
+ }
964
+ /**
965
+ * Phase 6 — React Native Fabric/Codegen view component bridge.
966
+ *
967
+ * The Fabric framework extractor (`frameworks/fabric.ts`) emits
968
+ * `component` nodes named after the JS-visible component (e.g.
969
+ * `RNSScreenStack`) from each `codegenNativeComponent<Props>('Name')`
970
+ * spec declaration. The native implementation lives in an ObjC++/.mm or
971
+ * Kotlin/Java class whose name follows one of RN's conventions:
972
+ *
973
+ * - Exact: `RNSScreenStack`
974
+ * - With suffix: `RNSScreenStackView`, `RNSScreenStackViewManager`,
975
+ * `RNSScreenStackComponentView`, `RNSScreenStackManager`
976
+ *
977
+ * This synthesizer walks every Fabric component node and looks for a
978
+ * native class matching one of those names; when found, emits a
979
+ * `calls` edge `component → native class` (provenance `'heuristic'`,
980
+ * `synthesizedBy:'fabric-native-impl'`) so trace from JSX usage of the
981
+ * component continues into native.
982
+ *
983
+ * The convention-based suffix lookup is precise: there's no name
984
+ * collision in RN view-manager codebases by design (Codegen output would
985
+ * conflict otherwise).
986
+ */
987
+ const FABRIC_NATIVE_SUFFIXES = ['', 'View', 'ViewManager', 'ComponentView', 'Manager'];
988
+ function fabricNativeImplEdges(ctx) {
989
+ const edges = [];
990
+ const seen = new Set();
991
+ // The Fabric extractor IDs are prefixed `fabric-component:` so we can
992
+ // filter to just those without iterating all `component` nodes.
993
+ const components = ctx.getNodesByKind('component').filter((n) => n.id.startsWith('fabric-component:'));
994
+ if (components.length === 0)
995
+ return edges;
996
+ // Pre-index native classes by name for O(1) lookup.
997
+ const nativeClassesByName = new Map();
998
+ for (const n of ctx.getNodesByKind('class')) {
999
+ if (n.language !== 'objc' && n.language !== 'kotlin' && n.language !== 'java' && n.language !== 'cpp')
1000
+ continue;
1001
+ const arr = nativeClassesByName.get(n.name);
1002
+ if (arr)
1003
+ arr.push(n);
1004
+ else
1005
+ nativeClassesByName.set(n.name, [n]);
1006
+ }
1007
+ for (const component of components) {
1008
+ for (const suffix of FABRIC_NATIVE_SUFFIXES) {
1009
+ const candidate = component.name + suffix;
1010
+ const matches = nativeClassesByName.get(candidate);
1011
+ if (!matches || matches.length === 0)
1012
+ continue;
1013
+ // Link the component node to every matching native class (iOS +
1014
+ // Android each have one).
1015
+ for (const native of matches) {
1016
+ const key = `${component.id}>${native.id}`;
1017
+ if (seen.has(key))
1018
+ continue;
1019
+ seen.add(key);
1020
+ edges.push({
1021
+ source: component.id,
1022
+ target: native.id,
1023
+ kind: 'calls',
1024
+ provenance: 'heuristic',
1025
+ metadata: {
1026
+ synthesizedBy: 'fabric-native-impl',
1027
+ viaSuffix: suffix || '(exact)',
1028
+ componentName: component.name,
1029
+ },
1030
+ });
1031
+ }
1032
+ }
1033
+ }
1034
+ return edges;
1035
+ }
1036
+ /**
1037
+ * MyBatis: link a Java mapper interface method to the XML statement that holds
1038
+ * its SQL. The XML extractor (`src/extraction/mybatis-extractor.ts`) qualifies
1039
+ * each `<select|insert|update|delete|sql id="X">` as `<namespace>::<id>` where
1040
+ * `<namespace>` is the Java FQN of the mapper interface. A Java method's
1041
+ * qualifiedName ends with `<ClassName>::<methodName>`, so we suffix-match the
1042
+ * last two segments of the XML qualified name to find a unique Java method by
1043
+ * `<ClassName>::<methodName>` (`ClassName` = last dotted segment of the XML
1044
+ * namespace). Cross-mapper `<include refid="other.X">` references go through
1045
+ * the normal qualified-name resolver — only the Java↔XML bridge is synthetic.
1046
+ *
1047
+ * Precision over recall: ambiguous mappers (multiple Java classes with the
1048
+ * same simple name) are dropped. We need-not bridge by package because Java
1049
+ * mapper interfaces are typically uniquely named within a project.
1050
+ */
1051
+ function mybatisJavaXmlEdges(queries) {
1052
+ const edges = [];
1053
+ const seen = new Set();
1054
+ // Index Java methods by `<ClassName>::<methodName>` for O(1) lookup.
1055
+ const javaIndex = new Map();
1056
+ for (const m of queries.iterateNodesByKind('method')) {
1057
+ if (m.language !== 'java' && m.language !== 'kotlin')
1058
+ continue;
1059
+ const parts = m.qualifiedName.split('::');
1060
+ const last = parts[parts.length - 1];
1061
+ const cls = parts[parts.length - 2];
1062
+ if (!last || !cls)
1063
+ continue;
1064
+ const key = `${cls}::${last}`;
1065
+ const arr = javaIndex.get(key);
1066
+ if (arr)
1067
+ arr.push(m);
1068
+ else
1069
+ javaIndex.set(key, [m]);
1070
+ }
1071
+ for (const xml of queries.iterateNodesByKind('method')) {
1072
+ if (xml.language !== 'xml')
1073
+ continue;
1074
+ // Qualified name: `<namespace>::<id>`. Extract the simple class name.
1075
+ const colonIdx = xml.qualifiedName.lastIndexOf('::');
1076
+ if (colonIdx < 0)
1077
+ continue;
1078
+ const namespace = xml.qualifiedName.slice(0, colonIdx);
1079
+ const id = xml.qualifiedName.slice(colonIdx + 2);
1080
+ if (!namespace || !id)
1081
+ continue;
1082
+ const dotIdx = namespace.lastIndexOf('.');
1083
+ const className = dotIdx >= 0 ? namespace.slice(dotIdx + 1) : namespace;
1084
+ const candidates = javaIndex.get(`${className}::${id}`);
1085
+ if (!candidates || candidates.length === 0)
1086
+ continue;
1087
+ // Drop ambiguous matches (multiple same-name classes); the user can
1088
+ // disambiguate by adding the package-suffix match in a future enhancement.
1089
+ if (candidates.length > 1)
1090
+ continue;
1091
+ const java = candidates[0];
1092
+ const key = `${java.id}>${xml.id}`;
1093
+ if (seen.has(key))
1094
+ continue;
1095
+ seen.add(key);
1096
+ edges.push({
1097
+ source: java.id,
1098
+ target: xml.id,
1099
+ kind: 'calls',
1100
+ line: java.startLine,
1101
+ provenance: 'heuristic',
1102
+ metadata: {
1103
+ synthesizedBy: 'mybatis-java-xml',
1104
+ via: `${className}.${id}`,
1105
+ registeredAt: `${xml.filePath}:${xml.startLine}`,
1106
+ },
1107
+ });
1108
+ }
1109
+ return edges;
1110
+ }
1111
+ /**
1112
+ * Gin middleware chain. Gin runs its entire handler chain through one dynamic
1113
+ * line in `(*Context).Next`:
1114
+ * for c.index < len(c.handlers) { c.handlers[c.index](c); c.index++ }
1115
+ * `c.handlers` is a `HandlersChain` (`[]HandlerFunc`) assembled at registration
1116
+ * time by `combineHandlers` from the funcs passed to `r.Use(...)` /
1117
+ * `r.GET("/path", h...)` / `r.Handle(...)`. Because the call is a computed index
1118
+ * into a runtime-built slice, tree-sitter resolves `c.handlers[c.index](c)` to
1119
+ * NOTHING — so `callees(Next)` is just the `len()` helper and the flow
1120
+ * `ServeHTTP → handleHTTPRequest → Next` dead-ends at the exact symbol the
1121
+ * "how do requests flow through the middleware chain" question is about. The
1122
+ * agent then re-queries Next and falls back to Read/grep (validated: the gin
1123
+ * WITH-arm rabbit-holed on precisely this dead-end).
1124
+ *
1125
+ * Bridge it: find the chain DISPATCHER (a Go method whose body invokes a
1126
+ * `handlers` slice by index) and link it → every HandlerFunc registered via a
1127
+ * gin registration call, so `callees(Next)` and `trace(ServeHTTP, <handler>)`
1128
+ * connect end-to-end. Named handlers only (`gin.Logger()` → `Logger`,
1129
+ * `authMiddleware`); inline closures are anonymous and skipped. Like
1130
+ * react-render / interface-impl this is a deliberate over-approximation —
1131
+ * reachability-correct (any registered handler CAN run for some route), capped,
1132
+ * and gated on the dispatcher existing so it never runs on non-gin Go repos.
1133
+ * Provenance `heuristic`, `synthesizedBy:'gin-middleware-chain'`; `registeredAt`
1134
+ * is the `.Use`/`.GET` site an agent would otherwise grep for.
1135
+ */
1136
+ const GIN_DISPATCH_RE = /\.handlers\s*\[[^\]]*\]\s*\(/; // c.handlers[c.index](c)
1137
+ const GIN_REG_RE = /\.(?:Use|GET|POST|PUT|PATCH|DELETE|OPTIONS|HEAD|Any|Handle)\s*\(/g;
1138
+ /** Balanced `(...)` body starting at the '(' index; null if unbalanced. */
1139
+ function goBalancedArgs(s, openIdx) {
1140
+ let depth = 0;
1141
+ for (let i = openIdx; i < s.length; i++) {
1142
+ const c = s[i];
1143
+ if (c === '(')
1144
+ depth++;
1145
+ else if (c === ')') {
1146
+ depth--;
1147
+ if (depth === 0)
1148
+ return s.slice(openIdx + 1, i);
1149
+ }
1150
+ }
1151
+ return null;
1152
+ }
1153
+ /** Split a top-level comma list, respecting nested () [] {}. */
1154
+ function goSplitArgs(args) {
1155
+ const out = [];
1156
+ let depth = 0, cur = '';
1157
+ for (const c of args) {
1158
+ if (c === '(' || c === '[' || c === '{') {
1159
+ depth++;
1160
+ cur += c;
1161
+ }
1162
+ else if (c === ')' || c === ']' || c === '}') {
1163
+ depth--;
1164
+ cur += c;
1165
+ }
1166
+ else if (c === ',' && depth === 0) {
1167
+ out.push(cur);
1168
+ cur = '';
1169
+ }
1170
+ else
1171
+ cur += c;
1172
+ }
1173
+ if (cur.trim())
1174
+ out.push(cur);
1175
+ return out;
1176
+ }
1177
+ /** Tail ident of a handler arg: `gin.Logger()`→`Logger`, `mw`→`mw`; null for string paths / closures. */
1178
+ function goHandlerIdent(expr) {
1179
+ const cleaned = expr.trim().replace(/\(\s*\)$/, ''); // drop a trailing call ()
1180
+ if (!cleaned || cleaned.startsWith('"') || cleaned.startsWith('`') || cleaned.startsWith('func'))
1181
+ return null;
1182
+ const m = cleaned.match(/(?:\.|^)([A-Za-z_]\w*)$/);
1183
+ return m ? m[1] : null;
1184
+ }
1185
+ function ginMiddlewareChainEdges(queries, ctx) {
1186
+ // 1. Find the chain dispatcher(s): a Go method that invokes a `handlers` slice by index.
1187
+ const dispatchers = [];
1188
+ for (const n of queries.iterateNodesByKind('method')) {
1189
+ if (n.language !== 'go')
1190
+ continue;
1191
+ const content = ctx.readFile(n.filePath);
1192
+ const src = content && sliceLines(content, n.startLine, n.endLine);
1193
+ if (src && GIN_DISPATCH_RE.test(src))
1194
+ dispatchers.push(n);
1195
+ }
1196
+ if (dispatchers.length === 0)
1197
+ return []; // not a gin repo — bail
1198
+ // 2. Collect handler identifiers registered via gin registration calls
1199
+ // (.Use / .GET / … / .Handle). String args (paths/methods) and inline
1200
+ // closures are dropped by goHandlerIdent; the rest are HandlerFuncs.
1201
+ const registered = new Map(); // name → registeredAt (file:line)
1202
+ for (const file of ctx.getAllFiles()) {
1203
+ if (!file.endsWith('.go'))
1204
+ continue;
1205
+ const content = ctx.readFile(file);
1206
+ if (!content || (!content.includes('.Use(') && !/\.(?:GET|POST|PUT|PATCH|DELETE|OPTIONS|HEAD|Any|Handle)\(/.test(content)))
1207
+ continue;
1208
+ const safe = (0, strip_comments_1.stripCommentsForRegex)(content, 'go');
1209
+ GIN_REG_RE.lastIndex = 0;
1210
+ let m;
1211
+ while ((m = GIN_REG_RE.exec(safe))) {
1212
+ const parenIdx = m.index + m[0].length - 1;
1213
+ const argStr = goBalancedArgs(safe, parenIdx);
1214
+ if (!argStr)
1215
+ continue;
1216
+ const line = safe.slice(0, m.index).split('\n').length;
1217
+ for (const arg of goSplitArgs(argStr)) {
1218
+ const name = goHandlerIdent(arg);
1219
+ if (name && !registered.has(name))
1220
+ registered.set(name, `${file}:${line}`);
1221
+ }
1222
+ }
1223
+ }
1224
+ if (registered.size === 0)
1225
+ return [];
1226
+ // 3. Link each dispatcher → each registered handler node (dedup, capped).
1227
+ const edges = [];
1228
+ const seen = new Set();
1229
+ for (const disp of dispatchers) {
1230
+ let added = 0;
1231
+ for (const [name, registeredAt] of registered) {
1232
+ if (added >= MAX_CALLBACKS_PER_CHANNEL)
1233
+ break;
1234
+ const handler = ctx.getNodesByName(name).find((n) => (n.kind === 'function' || n.kind === 'method') && n.language === 'go');
1235
+ if (!handler || handler.id === disp.id)
1236
+ continue;
1237
+ const key = `${disp.id}>${handler.id}`;
1238
+ if (seen.has(key))
1239
+ continue;
1240
+ seen.add(key);
1241
+ edges.push({
1242
+ source: disp.id, target: handler.id, kind: 'calls', line: disp.startLine,
1243
+ provenance: 'heuristic',
1244
+ metadata: { synthesizedBy: 'gin-middleware-chain', via: name, registeredAt },
1245
+ });
1246
+ added++;
1247
+ }
1248
+ }
1249
+ return edges;
1250
+ }
1251
+ /**
1252
+ * Synthesize dispatcher→callback edges (field observers + EventEmitters +
1253
+ * React re-render + JSX children + Vue templates + RN event channel +
1254
+ * Fabric native-impl + MyBatis Java↔XML + Gin middleware chain). Returns the
1255
+ * count added. Never throws into indexing — callers wrap in try/catch.
1256
+ */
1257
+ function synthesizeCallbackEdges(queries, ctx) {
1258
+ const fieldEdges = fieldChannelEdges(queries, ctx);
1259
+ const closureCollEdges = closureCollectionEdges(queries, ctx);
1260
+ const emitterEdges = eventEmitterEdges(ctx);
1261
+ const renderEdges = reactRenderEdges(queries, ctx);
1262
+ const jsxEdges = reactJsxChildEdges(ctx);
1263
+ const vueEdges = vueTemplateEdges(ctx);
1264
+ const flutterEdges = flutterBuildEdges(queries, ctx);
1265
+ const cppEdges = cppOverrideEdges(queries);
1266
+ const ifaceEdges = interfaceOverrideEdges(queries);
1267
+ const goGrpcEdges = goGrpcStubImplEdges(queries);
1268
+ const rnEventEdgesList = rnEventEdges(ctx);
1269
+ const fabricNativeEdges = fabricNativeImplEdges(ctx);
1270
+ const mybatisEdges = mybatisJavaXmlEdges(queries);
1271
+ const ginEdges = ginMiddlewareChainEdges(queries, ctx);
1272
+ const merged = [];
1273
+ const seen = new Set();
1274
+ for (const e of [
1275
+ ...fieldEdges,
1276
+ ...closureCollEdges,
1277
+ ...emitterEdges,
1278
+ ...renderEdges,
1279
+ ...jsxEdges,
1280
+ ...vueEdges,
1281
+ ...flutterEdges,
1282
+ ...cppEdges,
1283
+ ...ifaceEdges,
1284
+ ...goGrpcEdges,
1285
+ ...rnEventEdgesList,
1286
+ ...fabricNativeEdges,
1287
+ ...mybatisEdges,
1288
+ ...ginEdges,
1289
+ ]) {
1290
+ const key = `${e.source}>${e.target}`;
1291
+ if (seen.has(key))
1292
+ continue;
1293
+ seen.add(key);
1294
+ merged.push(e);
1295
+ }
1296
+ if (merged.length > 0)
1297
+ queries.insertEdges(merged);
1298
+ return merged.length;
1299
+ }
1300
+ //# sourceMappingURL=callback-synthesizer.js.map