@ruverd/julius 0.0.0-stage → 0.24.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 (704) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/CREDITS.md +25 -0
  3. package/LICENSE +21 -0
  4. package/PROVENANCE.md +9 -0
  5. package/README.md +225 -2
  6. package/dist/ai/crux.d.ts +60 -0
  7. package/dist/ai/crux.d.ts.map +1 -0
  8. package/dist/ai/crux.js +141 -0
  9. package/dist/ai/crux.js.map +1 -0
  10. package/dist/ai/failure.d.ts +60 -0
  11. package/dist/ai/failure.d.ts.map +1 -0
  12. package/dist/ai/failure.js +86 -0
  13. package/dist/ai/failure.js.map +1 -0
  14. package/dist/ai/llm/anthropic.d.ts +37 -0
  15. package/dist/ai/llm/anthropic.d.ts.map +1 -0
  16. package/dist/ai/llm/anthropic.js +144 -0
  17. package/dist/ai/llm/anthropic.js.map +1 -0
  18. package/dist/ai/llm/factory.d.ts +28 -0
  19. package/dist/ai/llm/factory.d.ts.map +1 -0
  20. package/dist/ai/llm/factory.js +36 -0
  21. package/dist/ai/llm/factory.js.map +1 -0
  22. package/dist/ai/llm/litellm.d.ts +34 -0
  23. package/dist/ai/llm/litellm.d.ts.map +1 -0
  24. package/dist/ai/llm/litellm.js +45 -0
  25. package/dist/ai/llm/litellm.js.map +1 -0
  26. package/dist/ai/llm/openai.d.ts +44 -0
  27. package/dist/ai/llm/openai.d.ts.map +1 -0
  28. package/dist/ai/llm/openai.js +239 -0
  29. package/dist/ai/llm/openai.js.map +1 -0
  30. package/dist/ai/llm/orcarouter.d.ts +34 -0
  31. package/dist/ai/llm/orcarouter.d.ts.map +1 -0
  32. package/dist/ai/llm/orcarouter.js +45 -0
  33. package/dist/ai/llm/orcarouter.js.map +1 -0
  34. package/dist/ai/llm/recover-tool.d.ts +19 -0
  35. package/dist/ai/llm/recover-tool.d.ts.map +1 -0
  36. package/dist/ai/llm/recover-tool.js +109 -0
  37. package/dist/ai/llm/recover-tool.js.map +1 -0
  38. package/dist/ai/llm/types.d.ts +122 -0
  39. package/dist/ai/llm/types.d.ts.map +1 -0
  40. package/dist/ai/llm/types.js +33 -0
  41. package/dist/ai/llm/types.js.map +1 -0
  42. package/dist/ai/providers.d.ts +59 -0
  43. package/dist/ai/providers.d.ts.map +1 -0
  44. package/dist/ai/providers.js +54 -0
  45. package/dist/ai/providers.js.map +1 -0
  46. package/dist/ai/summarize.d.ts +25 -0
  47. package/dist/ai/summarize.d.ts.map +1 -0
  48. package/dist/ai/summarize.js +34 -0
  49. package/dist/ai/summarize.js.map +1 -0
  50. package/dist/ai/synthesize.d.ts +40 -0
  51. package/dist/ai/synthesize.d.ts.map +1 -0
  52. package/dist/ai/synthesize.js +131 -0
  53. package/dist/ai/synthesize.js.map +1 -0
  54. package/dist/app/checkout.d.ts +46 -0
  55. package/dist/app/checkout.d.ts.map +1 -0
  56. package/dist/app/checkout.js +223 -0
  57. package/dist/app/checkout.js.map +1 -0
  58. package/dist/app/events.d.ts +44 -0
  59. package/dist/app/events.d.ts.map +1 -0
  60. package/dist/app/events.js +64 -0
  61. package/dist/app/events.js.map +1 -0
  62. package/dist/app/identity.d.ts +54 -0
  63. package/dist/app/identity.d.ts.map +1 -0
  64. package/dist/app/identity.js +96 -0
  65. package/dist/app/identity.js.map +1 -0
  66. package/dist/app/main.d.ts +2 -0
  67. package/dist/app/main.d.ts.map +1 -0
  68. package/dist/app/main.js +62 -0
  69. package/dist/app/main.js.map +1 -0
  70. package/dist/app/pages.d.ts +56 -0
  71. package/dist/app/pages.d.ts.map +1 -0
  72. package/dist/app/pages.js +193 -0
  73. package/dist/app/pages.js.map +1 -0
  74. package/dist/app/queue.d.ts +40 -0
  75. package/dist/app/queue.d.ts.map +1 -0
  76. package/dist/app/queue.js +68 -0
  77. package/dist/app/queue.js.map +1 -0
  78. package/dist/app/review-process.d.ts +66 -0
  79. package/dist/app/review-process.d.ts.map +1 -0
  80. package/dist/app/review-process.js +200 -0
  81. package/dist/app/review-process.js.map +1 -0
  82. package/dist/app/review-worker.d.ts +2 -0
  83. package/dist/app/review-worker.d.ts.map +1 -0
  84. package/dist/app/review-worker.js +108 -0
  85. package/dist/app/review-worker.js.map +1 -0
  86. package/dist/app/review.d.ts +23 -0
  87. package/dist/app/review.d.ts.map +1 -0
  88. package/dist/app/review.js +142 -0
  89. package/dist/app/review.js.map +1 -0
  90. package/dist/app/server.d.ts +49 -0
  91. package/dist/app/server.d.ts.map +1 -0
  92. package/dist/app/server.js +123 -0
  93. package/dist/app/server.js.map +1 -0
  94. package/dist/ask/ask.d.ts +195 -0
  95. package/dist/ask/ask.d.ts.map +1 -0
  96. package/dist/ask/ask.js +1252 -0
  97. package/dist/ask/ask.js.map +1 -0
  98. package/dist/ask/file-rank.d.ts +72 -0
  99. package/dist/ask/file-rank.d.ts.map +1 -0
  100. package/dist/ask/file-rank.js +160 -0
  101. package/dist/ask/file-rank.js.map +1 -0
  102. package/dist/ask/file-selection.d.ts +22 -0
  103. package/dist/ask/file-selection.d.ts.map +1 -0
  104. package/dist/ask/file-selection.js +66 -0
  105. package/dist/ask/file-selection.js.map +1 -0
  106. package/dist/ask/fuse.d.ts +195 -0
  107. package/dist/ask/fuse.d.ts.map +1 -0
  108. package/dist/ask/fuse.js +344 -0
  109. package/dist/ask/fuse.js.map +1 -0
  110. package/dist/ask/graphrank.d.ts +61 -0
  111. package/dist/ask/graphrank.d.ts.map +1 -0
  112. package/dist/ask/graphrank.js +130 -0
  113. package/dist/ask/graphrank.js.map +1 -0
  114. package/dist/ask/index-file.d.ts +44 -0
  115. package/dist/ask/index-file.d.ts.map +1 -0
  116. package/dist/ask/index-file.js +128 -0
  117. package/dist/ask/index-file.js.map +1 -0
  118. package/dist/bin/julius.d.ts +3 -0
  119. package/dist/bin/julius.d.ts.map +1 -0
  120. package/dist/bin/julius.js +4 -0
  121. package/dist/bin/julius.js.map +1 -0
  122. package/dist/blast/blast-cli.d.ts +35 -0
  123. package/dist/blast/blast-cli.d.ts.map +1 -0
  124. package/dist/blast/blast-cli.js +155 -0
  125. package/dist/blast/blast-cli.js.map +1 -0
  126. package/dist/blast/blast.d.ts +128 -0
  127. package/dist/blast/blast.d.ts.map +1 -0
  128. package/dist/blast/blast.js +383 -0
  129. package/dist/blast/blast.js.map +1 -0
  130. package/dist/blast/diff.d.ts +53 -0
  131. package/dist/blast/diff.d.ts.map +1 -0
  132. package/dist/blast/diff.js +193 -0
  133. package/dist/blast/diff.js.map +1 -0
  134. package/dist/blast/evidence.d.ts +51 -0
  135. package/dist/blast/evidence.d.ts.map +1 -0
  136. package/dist/blast/evidence.js +162 -0
  137. package/dist/blast/evidence.js.map +1 -0
  138. package/dist/blast/modules.d.ts +33 -0
  139. package/dist/blast/modules.d.ts.map +1 -0
  140. package/dist/blast/modules.js +83 -0
  141. package/dist/blast/modules.js.map +1 -0
  142. package/dist/blast/name.d.ts +74 -0
  143. package/dist/blast/name.d.ts.map +1 -0
  144. package/dist/blast/name.js +269 -0
  145. package/dist/blast/name.js.map +1 -0
  146. package/dist/blast/owners.d.ts +85 -0
  147. package/dist/blast/owners.d.ts.map +1 -0
  148. package/dist/blast/owners.js +272 -0
  149. package/dist/blast/owners.js.map +1 -0
  150. package/dist/blast/render.d.ts +46 -0
  151. package/dist/blast/render.d.ts.map +1 -0
  152. package/dist/blast/render.js +422 -0
  153. package/dist/blast/render.js.map +1 -0
  154. package/dist/blast/viz.d.ts +37 -0
  155. package/dist/blast/viz.d.ts.map +1 -0
  156. package/dist/blast/viz.js +180 -0
  157. package/dist/blast/viz.js.map +1 -0
  158. package/dist/brand.d.ts +13 -0
  159. package/dist/brand.d.ts.map +1 -0
  160. package/dist/brand.js +43 -0
  161. package/dist/brand.js.map +1 -0
  162. package/dist/check/learning-edits.d.ts +9 -0
  163. package/dist/check/learning-edits.d.ts.map +1 -0
  164. package/dist/check/learning-edits.js +62 -0
  165. package/dist/check/learning-edits.js.map +1 -0
  166. package/dist/check/local-check.d.ts +104 -0
  167. package/dist/check/local-check.d.ts.map +1 -0
  168. package/dist/check/local-check.js +830 -0
  169. package/dist/check/local-check.js.map +1 -0
  170. package/dist/check/types.d.ts +31 -0
  171. package/dist/check/types.d.ts.map +1 -0
  172. package/dist/check/types.js +2 -0
  173. package/dist/check/types.js.map +1 -0
  174. package/dist/claude/build-progress.d.ts +29 -0
  175. package/dist/claude/build-progress.d.ts.map +1 -0
  176. package/dist/claude/build-progress.js +76 -0
  177. package/dist/claude/build-progress.js.map +1 -0
  178. package/dist/claude/format.d.ts +131 -0
  179. package/dist/claude/format.d.ts.map +1 -0
  180. package/dist/claude/format.js +328 -0
  181. package/dist/claude/format.js.map +1 -0
  182. package/dist/claude/hook-layers.d.ts +8 -0
  183. package/dist/claude/hook-layers.d.ts.map +1 -0
  184. package/dist/claude/hook-layers.js +74 -0
  185. package/dist/claude/hook-layers.js.map +1 -0
  186. package/dist/claude/hooks.d.ts +101 -0
  187. package/dist/claude/hooks.d.ts.map +1 -0
  188. package/dist/claude/hooks.js +849 -0
  189. package/dist/claude/hooks.js.map +1 -0
  190. package/dist/claude/init.d.ts +70 -0
  191. package/dist/claude/init.d.ts.map +1 -0
  192. package/dist/claude/init.js +207 -0
  193. package/dist/claude/init.js.map +1 -0
  194. package/dist/claude/note-signals.d.ts +28 -0
  195. package/dist/claude/note-signals.d.ts.map +1 -0
  196. package/dist/claude/note-signals.js +325 -0
  197. package/dist/claude/note-signals.js.map +1 -0
  198. package/dist/claude/paths.d.ts +9 -0
  199. package/dist/claude/paths.d.ts.map +1 -0
  200. package/dist/claude/paths.js +22 -0
  201. package/dist/claude/paths.js.map +1 -0
  202. package/dist/claude/session-metrics.d.ts +73 -0
  203. package/dist/claude/session-metrics.d.ts.map +1 -0
  204. package/dist/claude/session-metrics.js +209 -0
  205. package/dist/claude/session-metrics.js.map +1 -0
  206. package/dist/claude/settings-merge.d.ts +66 -0
  207. package/dist/claude/settings-merge.d.ts.map +1 -0
  208. package/dist/claude/settings-merge.js +249 -0
  209. package/dist/claude/settings-merge.js.map +1 -0
  210. package/dist/claude/shim-template.d.ts +18 -0
  211. package/dist/claude/shim-template.d.ts.map +1 -0
  212. package/dist/claude/shim-template.js +226 -0
  213. package/dist/claude/shim-template.js.map +1 -0
  214. package/dist/claude/skill-template.d.ts +12 -0
  215. package/dist/claude/skill-template.d.ts.map +1 -0
  216. package/dist/claude/skill-template.js +294 -0
  217. package/dist/claude/skill-template.js.map +1 -0
  218. package/dist/claude/state.d.ts +73 -0
  219. package/dist/claude/state.d.ts.map +1 -0
  220. package/dist/claude/state.js +33 -0
  221. package/dist/claude/state.js.map +1 -0
  222. package/dist/claude/stats.d.ts +5 -0
  223. package/dist/claude/stats.d.ts.map +1 -0
  224. package/dist/claude/stats.js +24 -0
  225. package/dist/claude/stats.js.map +1 -0
  226. package/dist/claude/statusline.d.ts +14 -0
  227. package/dist/claude/statusline.d.ts.map +1 -0
  228. package/dist/claude/statusline.js +45 -0
  229. package/dist/claude/statusline.js.map +1 -0
  230. package/dist/claude/sync-run.d.ts +3 -0
  231. package/dist/claude/sync-run.d.ts.map +1 -0
  232. package/dist/claude/sync-run.js +46 -0
  233. package/dist/claude/sync-run.js.map +1 -0
  234. package/dist/claude/tally.d.ts +50 -0
  235. package/dist/claude/tally.d.ts.map +1 -0
  236. package/dist/claude/tally.js +211 -0
  237. package/dist/claude/tally.js.map +1 -0
  238. package/dist/cli-epilogue.d.ts +12 -0
  239. package/dist/cli-epilogue.d.ts.map +1 -0
  240. package/dist/cli-epilogue.js +55 -0
  241. package/dist/cli-epilogue.js.map +1 -0
  242. package/dist/cli-meta.d.ts +45 -0
  243. package/dist/cli-meta.d.ts.map +1 -0
  244. package/dist/cli-meta.js +145 -0
  245. package/dist/cli-meta.js.map +1 -0
  246. package/dist/cli-picker.d.ts +129 -0
  247. package/dist/cli-picker.d.ts.map +1 -0
  248. package/dist/cli-picker.js +432 -0
  249. package/dist/cli-picker.js.map +1 -0
  250. package/dist/cli.d.ts +3 -0
  251. package/dist/cli.d.ts.map +1 -0
  252. package/dist/cli.js +2213 -0
  253. package/dist/cli.js.map +1 -0
  254. package/dist/cloud/diff.d.ts +20 -0
  255. package/dist/cloud/diff.d.ts.map +1 -0
  256. package/dist/cloud/diff.js +59 -0
  257. package/dist/cloud/diff.js.map +1 -0
  258. package/dist/cloud/nudge.d.ts +66 -0
  259. package/dist/cloud/nudge.d.ts.map +1 -0
  260. package/dist/cloud/nudge.js +268 -0
  261. package/dist/cloud/nudge.js.map +1 -0
  262. package/dist/cloud/workspace-sync.d.ts +58 -0
  263. package/dist/cloud/workspace-sync.d.ts.map +1 -0
  264. package/dist/cloud/workspace-sync.js +268 -0
  265. package/dist/cloud/workspace-sync.js.map +1 -0
  266. package/dist/cloud/workspace.d.ts +159 -0
  267. package/dist/cloud/workspace.d.ts.map +1 -0
  268. package/dist/cloud/workspace.js +134 -0
  269. package/dist/cloud/workspace.js.map +1 -0
  270. package/dist/context/build.d.ts +52 -0
  271. package/dist/context/build.d.ts.map +1 -0
  272. package/dist/context/build.js +362 -0
  273. package/dist/context/build.js.map +1 -0
  274. package/dist/context/check.d.ts +42 -0
  275. package/dist/context/check.d.ts.map +1 -0
  276. package/dist/context/check.js +162 -0
  277. package/dist/context/check.js.map +1 -0
  278. package/dist/context/map-dir.d.ts +4 -0
  279. package/dist/context/map-dir.d.ts.map +1 -0
  280. package/dist/context/map-dir.js +6 -0
  281. package/dist/context/map-dir.js.map +1 -0
  282. package/dist/context/node-file.d.ts +109 -0
  283. package/dist/context/node-file.d.ts.map +1 -0
  284. package/dist/context/node-file.js +362 -0
  285. package/dist/context/node-file.js.map +1 -0
  286. package/dist/context/price.d.ts +49 -0
  287. package/dist/context/price.d.ts.map +1 -0
  288. package/dist/context/price.js +83 -0
  289. package/dist/context/price.js.map +1 -0
  290. package/dist/context/savings.d.ts +26 -0
  291. package/dist/context/savings.d.ts.map +1 -0
  292. package/dist/context/savings.js +59 -0
  293. package/dist/context/savings.js.map +1 -0
  294. package/dist/economy/cli.d.ts +3 -0
  295. package/dist/economy/cli.d.ts.map +1 -0
  296. package/dist/economy/cli.js +52 -0
  297. package/dist/economy/cli.js.map +1 -0
  298. package/dist/economy/delivery.d.ts +49 -0
  299. package/dist/economy/delivery.d.ts.map +1 -0
  300. package/dist/economy/delivery.js +176 -0
  301. package/dist/economy/delivery.js.map +1 -0
  302. package/dist/economy/index.d.ts +67 -0
  303. package/dist/economy/index.d.ts.map +1 -0
  304. package/dist/economy/index.js +519 -0
  305. package/dist/economy/index.js.map +1 -0
  306. package/dist/engine.d.ts +83 -0
  307. package/dist/engine.d.ts.map +1 -0
  308. package/dist/engine.js +122 -0
  309. package/dist/engine.js.map +1 -0
  310. package/dist/evaluation/index.d.ts +41 -0
  311. package/dist/evaluation/index.d.ts.map +1 -0
  312. package/dist/evaluation/index.js +61 -0
  313. package/dist/evaluation/index.js.map +1 -0
  314. package/dist/graph/bindings.d.ts +64 -0
  315. package/dist/graph/bindings.d.ts.map +1 -0
  316. package/dist/graph/bindings.js +713 -0
  317. package/dist/graph/bindings.js.map +1 -0
  318. package/dist/graph/build.d.ts +88 -0
  319. package/dist/graph/build.d.ts.map +1 -0
  320. package/dist/graph/build.js +375 -0
  321. package/dist/graph/build.js.map +1 -0
  322. package/dist/graph/cards.d.ts +46 -0
  323. package/dist/graph/cards.d.ts.map +1 -0
  324. package/dist/graph/cards.js +280 -0
  325. package/dist/graph/cards.js.map +1 -0
  326. package/dist/graph/check.d.ts +25 -0
  327. package/dist/graph/check.d.ts.map +1 -0
  328. package/dist/graph/check.js +192 -0
  329. package/dist/graph/check.js.map +1 -0
  330. package/dist/graph/container.d.ts +63 -0
  331. package/dist/graph/container.d.ts.map +1 -0
  332. package/dist/graph/container.js +190 -0
  333. package/dist/graph/container.js.map +1 -0
  334. package/dist/graph/enrich.d.ts +62 -0
  335. package/dist/graph/enrich.d.ts.map +1 -0
  336. package/dist/graph/enrich.js +253 -0
  337. package/dist/graph/enrich.js.map +1 -0
  338. package/dist/graph/extract-cache.d.ts +101 -0
  339. package/dist/graph/extract-cache.d.ts.map +1 -0
  340. package/dist/graph/extract-cache.js +199 -0
  341. package/dist/graph/extract-cache.js.map +1 -0
  342. package/dist/graph/extract.d.ts +85 -0
  343. package/dist/graph/extract.d.ts.map +1 -0
  344. package/dist/graph/extract.js +2376 -0
  345. package/dist/graph/extract.js.map +1 -0
  346. package/dist/graph/fingerprint.d.ts +76 -0
  347. package/dist/graph/fingerprint.d.ts.map +1 -0
  348. package/dist/graph/fingerprint.js +160 -0
  349. package/dist/graph/fingerprint.js.map +1 -0
  350. package/dist/graph/generic.d.ts +74 -0
  351. package/dist/graph/generic.d.ts.map +1 -0
  352. package/dist/graph/generic.js +580 -0
  353. package/dist/graph/generic.js.map +1 -0
  354. package/dist/graph/invariants.d.ts +33 -0
  355. package/dist/graph/invariants.d.ts.map +1 -0
  356. package/dist/graph/invariants.js +52 -0
  357. package/dist/graph/invariants.js.map +1 -0
  358. package/dist/graph/load.d.ts +29 -0
  359. package/dist/graph/load.d.ts.map +1 -0
  360. package/dist/graph/load.js +97 -0
  361. package/dist/graph/load.js.map +1 -0
  362. package/dist/graph/lsp/client.d.ts +43 -0
  363. package/dist/graph/lsp/client.d.ts.map +1 -0
  364. package/dist/graph/lsp/client.js +179 -0
  365. package/dist/graph/lsp/client.js.map +1 -0
  366. package/dist/graph/lsp/enrich.d.ts +11 -0
  367. package/dist/graph/lsp/enrich.d.ts.map +1 -0
  368. package/dist/graph/lsp/enrich.js +155 -0
  369. package/dist/graph/lsp/enrich.js.map +1 -0
  370. package/dist/graph/lsp/registry.d.ts +15 -0
  371. package/dist/graph/lsp/registry.d.ts.map +1 -0
  372. package/dist/graph/lsp/registry.js +46 -0
  373. package/dist/graph/lsp/registry.js.map +1 -0
  374. package/dist/graph/map.d.ts +107 -0
  375. package/dist/graph/map.d.ts.map +1 -0
  376. package/dist/graph/map.js +239 -0
  377. package/dist/graph/map.js.map +1 -0
  378. package/dist/graph/native.d.ts +38 -0
  379. package/dist/graph/native.d.ts.map +1 -0
  380. package/dist/graph/native.js +169 -0
  381. package/dist/graph/native.js.map +1 -0
  382. package/dist/graph/queries/c.scm +13 -0
  383. package/dist/graph/queries/c_sharp.scm +19 -0
  384. package/dist/graph/queries/clojure.scm +58 -0
  385. package/dist/graph/queries/cpp.scm +23 -0
  386. package/dist/graph/queries/dart.scm +42 -0
  387. package/dist/graph/queries/elixir.scm +54 -0
  388. package/dist/graph/queries/java.scm +20 -0
  389. package/dist/graph/queries/kotlin.scm +43 -0
  390. package/dist/graph/queries/lua.scm +36 -0
  391. package/dist/graph/queries/nix.scm +32 -0
  392. package/dist/graph/queries/php.scm +40 -0
  393. package/dist/graph/queries/ruby.scm +65 -0
  394. package/dist/graph/queries/rust.scm +41 -0
  395. package/dist/graph/queries/scala.scm +66 -0
  396. package/dist/graph/queries/solidity.scm +43 -0
  397. package/dist/graph/queries/swift.scm +51 -0
  398. package/dist/graph/refresh.d.ts +49 -0
  399. package/dist/graph/refresh.d.ts.map +1 -0
  400. package/dist/graph/refresh.js +255 -0
  401. package/dist/graph/refresh.js.map +1 -0
  402. package/dist/graph/relations.d.ts +14 -0
  403. package/dist/graph/relations.d.ts.map +1 -0
  404. package/dist/graph/relations.js +8 -0
  405. package/dist/graph/relations.js.map +1 -0
  406. package/dist/graph/resolve.d.ts +17 -0
  407. package/dist/graph/resolve.d.ts.map +1 -0
  408. package/dist/graph/resolve.js +654 -0
  409. package/dist/graph/resolve.js.map +1 -0
  410. package/dist/graph/root.d.ts +11 -0
  411. package/dist/graph/root.d.ts.map +1 -0
  412. package/dist/graph/root.js +40 -0
  413. package/dist/graph/root.js.map +1 -0
  414. package/dist/graph/scopes.d.ts +42 -0
  415. package/dist/graph/scopes.d.ts.map +1 -0
  416. package/dist/graph/scopes.js +342 -0
  417. package/dist/graph/scopes.js.map +1 -0
  418. package/dist/graph/seed.d.ts +38 -0
  419. package/dist/graph/seed.d.ts.map +1 -0
  420. package/dist/graph/seed.js +226 -0
  421. package/dist/graph/seed.js.map +1 -0
  422. package/dist/graph/source-files.d.ts +40 -0
  423. package/dist/graph/source-files.d.ts.map +1 -0
  424. package/dist/graph/source-files.js +85 -0
  425. package/dist/graph/source-files.js.map +1 -0
  426. package/dist/graph/traverse-cli.d.ts +55 -0
  427. package/dist/graph/traverse-cli.d.ts.map +1 -0
  428. package/dist/graph/traverse-cli.js +189 -0
  429. package/dist/graph/traverse-cli.js.map +1 -0
  430. package/dist/graph/traverse.d.ts +112 -0
  431. package/dist/graph/traverse.d.ts.map +1 -0
  432. package/dist/graph/traverse.js +192 -0
  433. package/dist/graph/traverse.js.map +1 -0
  434. package/dist/graph/types.d.ts +78 -0
  435. package/dist/graph/types.d.ts.map +1 -0
  436. package/dist/graph/types.js +14 -0
  437. package/dist/graph/types.js.map +1 -0
  438. package/dist/graph/workspace-cli.d.ts +48 -0
  439. package/dist/graph/workspace-cli.d.ts.map +1 -0
  440. package/dist/graph/workspace-cli.js +102 -0
  441. package/dist/graph/workspace-cli.js.map +1 -0
  442. package/dist/graph/workspace.d.ts +135 -0
  443. package/dist/graph/workspace.d.ts.map +1 -0
  444. package/dist/graph/workspace.js +598 -0
  445. package/dist/graph/workspace.js.map +1 -0
  446. package/dist/graph/write.d.ts +13 -0
  447. package/dist/graph/write.d.ts.map +1 -0
  448. package/dist/graph/write.js +86 -0
  449. package/dist/graph/write.js.map +1 -0
  450. package/dist/hosts/antigravity.d.ts +8 -0
  451. package/dist/hosts/antigravity.d.ts.map +1 -0
  452. package/dist/hosts/antigravity.js +42 -0
  453. package/dist/hosts/antigravity.js.map +1 -0
  454. package/dist/hosts/claude-global.d.ts +36 -0
  455. package/dist/hosts/claude-global.d.ts.map +1 -0
  456. package/dist/hosts/claude-global.js +153 -0
  457. package/dist/hosts/claude-global.js.map +1 -0
  458. package/dist/hosts/codex-hooks.d.ts +11 -0
  459. package/dist/hosts/codex-hooks.d.ts.map +1 -0
  460. package/dist/hosts/codex-hooks.js +80 -0
  461. package/dist/hosts/codex-hooks.js.map +1 -0
  462. package/dist/hosts/config-write.d.ts +36 -0
  463. package/dist/hosts/config-write.d.ts.map +1 -0
  464. package/dist/hosts/config-write.js +64 -0
  465. package/dist/hosts/config-write.js.map +1 -0
  466. package/dist/hosts/cursor-hooks.d.ts +21 -0
  467. package/dist/hosts/cursor-hooks.d.ts.map +1 -0
  468. package/dist/hosts/cursor-hooks.js +103 -0
  469. package/dist/hosts/cursor-hooks.js.map +1 -0
  470. package/dist/hosts/init.d.ts +26 -0
  471. package/dist/hosts/init.d.ts.map +1 -0
  472. package/dist/hosts/init.js +82 -0
  473. package/dist/hosts/init.js.map +1 -0
  474. package/dist/hosts/install.d.ts +12 -0
  475. package/dist/hosts/install.d.ts.map +1 -0
  476. package/dist/hosts/install.js +347 -0
  477. package/dist/hosts/install.js.map +1 -0
  478. package/dist/hosts/instructions.d.ts +7 -0
  479. package/dist/hosts/instructions.d.ts.map +1 -0
  480. package/dist/hosts/instructions.js +71 -0
  481. package/dist/hosts/instructions.js.map +1 -0
  482. package/dist/hosts/investigation-instructions.d.ts +2 -0
  483. package/dist/hosts/investigation-instructions.d.ts.map +1 -0
  484. package/dist/hosts/investigation-instructions.js +2 -0
  485. package/dist/hosts/investigation-instructions.js.map +1 -0
  486. package/dist/hosts/mcp-config.d.ts +59 -0
  487. package/dist/hosts/mcp-config.d.ts.map +1 -0
  488. package/dist/hosts/mcp-config.js +229 -0
  489. package/dist/hosts/mcp-config.js.map +1 -0
  490. package/dist/hosts/plan.d.ts +32 -0
  491. package/dist/hosts/plan.d.ts.map +1 -0
  492. package/dist/hosts/plan.js +77 -0
  493. package/dist/hosts/plan.js.map +1 -0
  494. package/dist/hosts/registry.d.ts +35 -0
  495. package/dist/hosts/registry.d.ts.map +1 -0
  496. package/dist/hosts/registry.js +157 -0
  497. package/dist/hosts/registry.js.map +1 -0
  498. package/dist/hosts/retract.d.ts +47 -0
  499. package/dist/hosts/retract.d.ts.map +1 -0
  500. package/dist/hosts/retract.js +541 -0
  501. package/dist/hosts/retract.js.map +1 -0
  502. package/dist/hosts/sections.d.ts +46 -0
  503. package/dist/hosts/sections.d.ts.map +1 -0
  504. package/dist/hosts/sections.js +126 -0
  505. package/dist/hosts/sections.js.map +1 -0
  506. package/dist/index.d.ts +43 -0
  507. package/dist/index.d.ts.map +1 -0
  508. package/dist/index.js +33 -0
  509. package/dist/index.js.map +1 -0
  510. package/dist/ingest/fs.d.ts +79 -0
  511. package/dist/ingest/fs.d.ts.map +1 -0
  512. package/dist/ingest/fs.js +307 -0
  513. package/dist/ingest/fs.js.map +1 -0
  514. package/dist/init-guard.d.ts +11 -0
  515. package/dist/init-guard.d.ts.map +1 -0
  516. package/dist/init-guard.js +21 -0
  517. package/dist/init-guard.js.map +1 -0
  518. package/dist/investigation/index.d.ts +57 -0
  519. package/dist/investigation/index.d.ts.map +1 -0
  520. package/dist/investigation/index.js +315 -0
  521. package/dist/investigation/index.js.map +1 -0
  522. package/dist/mcp/compact.d.ts +9 -0
  523. package/dist/mcp/compact.d.ts.map +1 -0
  524. package/dist/mcp/compact.js +133 -0
  525. package/dist/mcp/compact.js.map +1 -0
  526. package/dist/mcp/instructions.d.ts +5 -0
  527. package/dist/mcp/instructions.d.ts.map +1 -0
  528. package/dist/mcp/instructions.js +57 -0
  529. package/dist/mcp/instructions.js.map +1 -0
  530. package/dist/mcp/server.d.ts +7 -0
  531. package/dist/mcp/server.d.ts.map +1 -0
  532. package/dist/mcp/server.js +128 -0
  533. package/dist/mcp/server.js.map +1 -0
  534. package/dist/mcp/tool-names.d.ts +20 -0
  535. package/dist/mcp/tool-names.d.ts.map +1 -0
  536. package/dist/mcp/tool-names.js +36 -0
  537. package/dist/mcp/tool-names.js.map +1 -0
  538. package/dist/mcp/tools.d.ts +22 -0
  539. package/dist/mcp/tools.d.ts.map +1 -0
  540. package/dist/mcp/tools.js +300 -0
  541. package/dist/mcp/tools.js.map +1 -0
  542. package/dist/notes/ask-notes.d.ts +8 -0
  543. package/dist/notes/ask-notes.d.ts.map +1 -0
  544. package/dist/notes/ask-notes.js +19 -0
  545. package/dist/notes/ask-notes.js.map +1 -0
  546. package/dist/notes/branches.d.ts +102 -0
  547. package/dist/notes/branches.d.ts.map +1 -0
  548. package/dist/notes/branches.js +304 -0
  549. package/dist/notes/branches.js.map +1 -0
  550. package/dist/notes/cold-start.d.ts +177 -0
  551. package/dist/notes/cold-start.d.ts.map +1 -0
  552. package/dist/notes/cold-start.js +537 -0
  553. package/dist/notes/cold-start.js.map +1 -0
  554. package/dist/notes/edit-overlap.d.ts +62 -0
  555. package/dist/notes/edit-overlap.d.ts.map +1 -0
  556. package/dist/notes/edit-overlap.js +202 -0
  557. package/dist/notes/edit-overlap.js.map +1 -0
  558. package/dist/notes/git-facts.d.ts +21 -0
  559. package/dist/notes/git-facts.d.ts.map +1 -0
  560. package/dist/notes/git-facts.js +121 -0
  561. package/dist/notes/git-facts.js.map +1 -0
  562. package/dist/notes/home.d.ts +87 -0
  563. package/dist/notes/home.d.ts.map +1 -0
  564. package/dist/notes/home.js +430 -0
  565. package/dist/notes/home.js.map +1 -0
  566. package/dist/notes/learning-fields.d.ts +102 -0
  567. package/dist/notes/learning-fields.d.ts.map +1 -0
  568. package/dist/notes/learning-fields.js +217 -0
  569. package/dist/notes/learning-fields.js.map +1 -0
  570. package/dist/notes/note-gate.d.ts +42 -0
  571. package/dist/notes/note-gate.d.ts.map +1 -0
  572. package/dist/notes/note-gate.js +181 -0
  573. package/dist/notes/note-gate.js.map +1 -0
  574. package/dist/notes/notes.d.ts +214 -0
  575. package/dist/notes/notes.d.ts.map +1 -0
  576. package/dist/notes/notes.js +591 -0
  577. package/dist/notes/notes.js.map +1 -0
  578. package/dist/notes/pr-reviews.d.ts +108 -0
  579. package/dist/notes/pr-reviews.d.ts.map +1 -0
  580. package/dist/notes/pr-reviews.js +325 -0
  581. package/dist/notes/pr-reviews.js.map +1 -0
  582. package/dist/notes/repo-julius.d.ts +18 -0
  583. package/dist/notes/repo-julius.d.ts.map +1 -0
  584. package/dist/notes/repo-julius.js +111 -0
  585. package/dist/notes/repo-julius.js.map +1 -0
  586. package/dist/notes/session-cost.d.ts +35 -0
  587. package/dist/notes/session-cost.d.ts.map +1 -0
  588. package/dist/notes/session-cost.js +276 -0
  589. package/dist/notes/session-cost.js.map +1 -0
  590. package/dist/search/grep-cli.d.ts +35 -0
  591. package/dist/search/grep-cli.d.ts.map +1 -0
  592. package/dist/search/grep-cli.js +115 -0
  593. package/dist/search/grep-cli.js.map +1 -0
  594. package/dist/search/grep.d.ts +60 -0
  595. package/dist/search/grep.d.ts.map +1 -0
  596. package/dist/search/grep.js +176 -0
  597. package/dist/search/grep.js.map +1 -0
  598. package/dist/search/ignored-code.d.ts +9 -0
  599. package/dist/search/ignored-code.d.ts.map +1 -0
  600. package/dist/search/ignored-code.js +73 -0
  601. package/dist/search/ignored-code.js.map +1 -0
  602. package/dist/skills/skills.d.ts +118 -0
  603. package/dist/skills/skills.d.ts.map +1 -0
  604. package/dist/skills/skills.js +370 -0
  605. package/dist/skills/skills.js.map +1 -0
  606. package/dist/telemetry/contract.d.ts +103 -0
  607. package/dist/telemetry/contract.d.ts.map +1 -0
  608. package/dist/telemetry/contract.js +270 -0
  609. package/dist/telemetry/contract.js.map +1 -0
  610. package/dist/telemetry/flush.d.ts +21 -0
  611. package/dist/telemetry/flush.d.ts.map +1 -0
  612. package/dist/telemetry/flush.js +85 -0
  613. package/dist/telemetry/flush.js.map +1 -0
  614. package/dist/telemetry/gate.d.ts +30 -0
  615. package/dist/telemetry/gate.d.ts.map +1 -0
  616. package/dist/telemetry/gate.js +81 -0
  617. package/dist/telemetry/gate.js.map +1 -0
  618. package/dist/telemetry/identity.d.ts +40 -0
  619. package/dist/telemetry/identity.d.ts.map +1 -0
  620. package/dist/telemetry/identity.js +80 -0
  621. package/dist/telemetry/identity.js.map +1 -0
  622. package/dist/telemetry/index.d.ts +18 -0
  623. package/dist/telemetry/index.d.ts.map +1 -0
  624. package/dist/telemetry/index.js +16 -0
  625. package/dist/telemetry/index.js.map +1 -0
  626. package/dist/telemetry/key.d.ts +4 -0
  627. package/dist/telemetry/key.d.ts.map +1 -0
  628. package/dist/telemetry/key.js +4 -0
  629. package/dist/telemetry/key.js.map +1 -0
  630. package/dist/telemetry/notice.d.ts +19 -0
  631. package/dist/telemetry/notice.d.ts.map +1 -0
  632. package/dist/telemetry/notice.js +93 -0
  633. package/dist/telemetry/notice.js.map +1 -0
  634. package/dist/telemetry/queue.d.ts +35 -0
  635. package/dist/telemetry/queue.d.ts.map +1 -0
  636. package/dist/telemetry/queue.js +162 -0
  637. package/dist/telemetry/queue.js.map +1 -0
  638. package/dist/telemetry/send.d.ts +19 -0
  639. package/dist/telemetry/send.d.ts.map +1 -0
  640. package/dist/telemetry/send.js +84 -0
  641. package/dist/telemetry/send.js.map +1 -0
  642. package/dist/telemetry/sessions.d.ts +25 -0
  643. package/dist/telemetry/sessions.d.ts.map +1 -0
  644. package/dist/telemetry/sessions.js +104 -0
  645. package/dist/telemetry/sessions.js.map +1 -0
  646. package/dist/telemetry/track.d.ts +62 -0
  647. package/dist/telemetry/track.d.ts.map +1 -0
  648. package/dist/telemetry/track.js +142 -0
  649. package/dist/telemetry/track.js.map +1 -0
  650. package/dist/upkeep-run.d.ts +15 -0
  651. package/dist/upkeep-run.d.ts.map +1 -0
  652. package/dist/upkeep-run.js +71 -0
  653. package/dist/upkeep-run.js.map +1 -0
  654. package/dist/upkeep.d.ts +125 -0
  655. package/dist/upkeep.d.ts.map +1 -0
  656. package/dist/upkeep.js +255 -0
  657. package/dist/upkeep.js.map +1 -0
  658. package/dist/util/browser.d.ts +3 -0
  659. package/dist/util/browser.d.ts.map +1 -0
  660. package/dist/util/browser.js +14 -0
  661. package/dist/util/browser.js.map +1 -0
  662. package/dist/util/front-matter.d.ts +19 -0
  663. package/dist/util/front-matter.d.ts.map +1 -0
  664. package/dist/util/front-matter.js +21 -0
  665. package/dist/util/front-matter.js.map +1 -0
  666. package/dist/util/id.d.ts +7 -0
  667. package/dist/util/id.d.ts.map +1 -0
  668. package/dist/util/id.js +14 -0
  669. package/dist/util/id.js.map +1 -0
  670. package/dist/util/paths.d.ts +29 -0
  671. package/dist/util/paths.d.ts.map +1 -0
  672. package/dist/util/paths.js +71 -0
  673. package/dist/util/paths.js.map +1 -0
  674. package/dist/util/source.d.ts +4 -0
  675. package/dist/util/source.d.ts.map +1 -0
  676. package/dist/util/source.js +12 -0
  677. package/dist/util/source.js.map +1 -0
  678. package/dist/util/spinner.d.ts +15 -0
  679. package/dist/util/spinner.d.ts.map +1 -0
  680. package/dist/util/spinner.js +52 -0
  681. package/dist/util/spinner.js.map +1 -0
  682. package/dist/util/state.d.ts +100 -0
  683. package/dist/util/state.d.ts.map +1 -0
  684. package/dist/util/state.js +186 -0
  685. package/dist/util/state.js.map +1 -0
  686. package/dist/viewer/app.js +2 -0
  687. package/dist/viewer/index.html +49 -0
  688. package/dist/viewer/style.css +154 -0
  689. package/dist/viz/assemble.d.ts +83 -0
  690. package/dist/viz/assemble.d.ts.map +1 -0
  691. package/dist/viz/assemble.js +101 -0
  692. package/dist/viz/assemble.js.map +1 -0
  693. package/dist/viz/export.d.ts +39 -0
  694. package/dist/viz/export.d.ts.map +1 -0
  695. package/dist/viz/export.js +98 -0
  696. package/dist/viz/export.js.map +1 -0
  697. package/dist/viz/serve.d.ts +12 -0
  698. package/dist/viz/serve.d.ts.map +1 -0
  699. package/dist/viz/serve.js +129 -0
  700. package/dist/viz/serve.js.map +1 -0
  701. package/docs/assets/context-benchmark.svg +31 -0
  702. package/docs/assets/julius-hero.png +0 -0
  703. package/docs/upstream-changelog.md +785 -0
  704. package/package.json +138 -4
@@ -0,0 +1,2376 @@
1
+ import { basename } from "node:path";
2
+ import { contentHash } from "../util/id.js";
3
+ import { collectBindings, goReceiverVarOf, resolveRecvType } from "./bindings.js";
4
+ import { nativeParser } from "./native.js";
5
+ /**
6
+ * Extension → the tree-sitter grammar that parses it, and the label a human expects
7
+ * to see for it.
8
+ *
9
+ * The two are not the same, and conflating them under-reported coverage: `.mjs` is
10
+ * parsed by the typescript grammar, so a JS repo's build banner read `[typescript]`
11
+ * and a `.jsx` one read `[tsx]`. Both are true about the *parser* and misleading
12
+ * about the repo — people went looking for why their JavaScript hadn't been indexed
13
+ * when it had, and could not tell a language that was merely unlabelled from one
14
+ * that really was skipped (see issue #36).
15
+ *
16
+ * One table, both readings derived from it, so adding an extension cannot fix
17
+ * extraction and forget the label. Ordered longest-suffix-first: `.tsx` has to be
18
+ * tested before `.ts` would match it.
19
+ */
20
+ const EXTENSIONS = [
21
+ { ext: ".tsx", grammar: "tsx", label: "tsx" },
22
+ { ext: ".jsx", grammar: "tsx", label: "jsx" },
23
+ { ext: ".mts", grammar: "typescript", label: "typescript" },
24
+ { ext: ".cts", grammar: "typescript", label: "typescript" },
25
+ { ext: ".ts", grammar: "typescript", label: "typescript" },
26
+ { ext: ".mjs", grammar: "typescript", label: "javascript" },
27
+ { ext: ".cjs", grammar: "typescript", label: "javascript" },
28
+ { ext: ".js", grammar: "typescript", label: "javascript" },
29
+ { ext: ".pyi", grammar: "python", label: "python" },
30
+ { ext: ".py", grammar: "python", label: "python" },
31
+ { ext: ".go", grammar: "go", label: "go" },
32
+ { ext: ".java", grammar: "java", label: "java" },
33
+ { ext: ".kt", grammar: "kotlin", label: "kotlin" },
34
+ { ext: ".kts", grammar: "kotlin", label: "kotlin" },
35
+ { ext: ".swift", grammar: "swift", label: "swift" },
36
+ { ext: ".php", grammar: "php", label: "php" },
37
+ // `entryFor` lower-cases the path before matching, so this one entry covers
38
+ // both `.R` (the conventional case in real R codebases) and `.r`.
39
+ { ext: ".r", grammar: "r", label: "r" },
40
+ ];
41
+ function entryFor(path) {
42
+ const p = path.toLowerCase();
43
+ return EXTENSIONS.find((e) => p.endsWith(e.ext));
44
+ }
45
+ /** Every file extension a depth-tier (hand-written) extractor claims. */
46
+ export function depthExtensions() {
47
+ return EXTENSIONS.map((e) => e.ext);
48
+ }
49
+ /** Map a file path to a supported language, or null if unsupported. */
50
+ export function languageOf(path) {
51
+ return entryFor(path)?.grammar ?? null;
52
+ }
53
+ /**
54
+ * What to *call* the language of this file, for a banner or a repo map — or null when
55
+ * the file isn't indexed at all, which is the distinction {@link languageOf} shares
56
+ * and the one that matters to a reader checking coverage.
57
+ */
58
+ export function languageLabelOf(path) {
59
+ return entryFor(path)?.label ?? null;
60
+ }
61
+ /** Max chars of normalized body stored per symbol for search. Large enough that
62
+ * essentially every real definition is stored whole — only a rare giant function
63
+ * is clipped — while bounding how much the committed graph can grow. */
64
+ const MAX_BODY_CHARS = 5000;
65
+ /** Cap for a file node's module-level residual (imports, constants, module
66
+ * docstring — everything not inside a symbol). Higher than the per-symbol cap
67
+ * because a data-heavy module (constant tables, big config dicts) is legitimate
68
+ * residual, and it's the recall play — but still bounded. */
69
+ const MAX_FILE_BODY_CHARS = 16000;
70
+ /** The searchable body of a definition: its source text, whitespace-collapsed
71
+ * so every identifier becomes a token, capped at `max`. Search-only — the agent
72
+ * still reads verbatim source via `ask --source`, which slices the file from
73
+ * disk, so nothing here reaches the agent's context. */
74
+ function searchBody(text, max = MAX_BODY_CHARS) {
75
+ const norm = text.replace(/\s+/g, " ").trim();
76
+ return norm.length > max ? norm.slice(0, max) : norm;
77
+ }
78
+ /** A file's module-level residual: the lines NOT covered by any symbol span.
79
+ * Symbol bodies are already indexed on their own nodes, so this captures only
80
+ * what they miss — top-of-file imports, module constants, module docstrings —
81
+ * making a file findable by a term that lives outside every function/class.
82
+ * `symbols` are the file's emitted nodes (with `Lx-Ly` spans); `source` is the
83
+ * whole file. Far leaner than storing full-file bodies (no symbol duplication). */
84
+ function fileResidual(source, symbols) {
85
+ const lines = source.split("\n");
86
+ const covered = new Uint8Array(lines.length + 2);
87
+ for (const s of symbols) {
88
+ const m = s.span.match(/^L(\d+)-L(\d+)$/);
89
+ if (!m)
90
+ continue;
91
+ for (let r = Number(m[1]); r <= Number(m[2]) && r < covered.length; r++)
92
+ covered[r] = 1;
93
+ }
94
+ const kept = [];
95
+ for (let i = 0; i < lines.length; i++)
96
+ if (!covered[i + 1])
97
+ kept.push(lines[i]);
98
+ return searchBody(kept.join(" "), MAX_FILE_BODY_CHARS);
99
+ }
100
+ const TS_KINDS = {
101
+ class_declaration: "class",
102
+ abstract_class_declaration: "class",
103
+ function_declaration: "function",
104
+ generator_function_declaration: "function",
105
+ method_definition: "method",
106
+ interface_declaration: "interface",
107
+ type_alias_declaration: "type",
108
+ enum_declaration: "enum",
109
+ };
110
+ const PY_KINDS = {
111
+ class_definition: "class",
112
+ function_definition: "function", // → "method" inside a class (resolved in the walk)
113
+ };
114
+ // Go: `type_spec` is intentionally absent — its kind (struct/interface/type) depends on
115
+ // the named type's shape, so it's resolved dynamically in describe().
116
+ const GO_KINDS = {
117
+ function_declaration: "function",
118
+ method_declaration: "method",
119
+ };
120
+ // R: `function_definition` carries no name field at all (unlike every other
121
+ // supported language) — its identifier always comes from context (an
122
+ // assignment's other side), resolved dynamically in describeR(). Empty, like
123
+ // Go's own table — never consulted, kept only to satisfy KINDS_BY_LANG's type.
124
+ const R_KINDS = {};
125
+ // Java: a record is a nominal data carrier, so it takes "struct" — the same role
126
+ // Go's struct plays — rather than "class", which would make a service and a DTO
127
+ // indistinguishable in a repo where DTOs are most of the type surface.
128
+ const JAVA_KINDS = {
129
+ class_declaration: "class",
130
+ interface_declaration: "interface",
131
+ enum_declaration: "enum",
132
+ record_declaration: "struct",
133
+ annotation_type_declaration: "interface",
134
+ annotation_type_element_declaration: "method",
135
+ method_declaration: "method",
136
+ constructor_declaration: "method",
137
+ };
138
+ /** Java type declarations: they set `enclosingClass` for the methods nested in them,
139
+ * which "class"-only logic would miss for a record's or interface's members. */
140
+ const JAVA_TYPE_KINDS = new Set(["class", "interface", "enum", "struct"]);
141
+ const KOTLIN_KINDS = {
142
+ class_declaration: "class", // → "interface" / "enum" / "interface" (annotation) in describeKotlin
143
+ object_declaration: "class", // a singleton object is class-like (companion objects included)
144
+ function_declaration: "function", // → "method" inside a type (resolved in the walk)
145
+ secondary_constructor: "method", // the class's own secondary constructor
146
+ type_alias: "type",
147
+ property_declaration: "variable", // top-level `val`/`var` only (fields resolved in the walk)
148
+ };
149
+ /** Kotlin type declarations: they set `enclosingClass` for the members nested in them.
150
+ * "class" also covers object_declaration (it maps to "class"); interface/enum are the
151
+ * same class_declaration node rekinded in describeKotlin, so all three land in the set. */
152
+ const KOTLIN_TYPE_KINDS = new Set(["class", "interface", "enum"]);
153
+ const SWIFT_KINDS = {
154
+ class_declaration: "class", // → "struct" / "enum" in describeSwift (one node type covers all five keywords)
155
+ protocol_declaration: "interface",
156
+ function_declaration: "function", // → "method" inside a type (resolved in the walk)
157
+ protocol_function_declaration: "method", // a protocol requirement is always a member
158
+ init_declaration: "method", // the type's own initializer (named after it, like a Java constructor)
159
+ typealias_declaration: "type",
160
+ property_declaration: "variable", // top-level `let`/`var` only (fields resolved in the walk)
161
+ };
162
+ /** Swift type declarations: they set `enclosingClass` for the members nested in them.
163
+ * class/struct/enum are the same class_declaration node rekinded in describeSwift
164
+ * (an actor takes "class"); protocols are "interface". "module" is an extension
165
+ * body — a member-contributing scope named after the extended type, deliberately
166
+ * NOT a type kind in the graph so it can never make the real declaration's name
167
+ * ambiguous (see describeSwift's extension branch) — but its members still
168
+ * promote to methods owned by that type, which is why it belongs in this set. */
169
+ const SWIFT_TYPE_KINDS = new Set([
170
+ "class",
171
+ "struct",
172
+ "enum",
173
+ "interface",
174
+ "module",
175
+ ]);
176
+ // PHP: definition node types are all distinct (no py-style function→method
177
+ // promotion needed — a class body uses `method_declaration`, not
178
+ // `function_definition`). `trait_declaration` maps to the PHP-only `trait` kind.
179
+ const PHP_KINDS = {
180
+ function_definition: "function",
181
+ method_declaration: "method",
182
+ class_declaration: "class",
183
+ interface_declaration: "interface",
184
+ trait_declaration: "trait",
185
+ enum_declaration: "enum",
186
+ };
187
+ const KINDS_BY_LANG = {
188
+ typescript: TS_KINDS,
189
+ tsx: TS_KINDS,
190
+ python: PY_KINDS,
191
+ go: GO_KINDS,
192
+ r: R_KINDS,
193
+ java: JAVA_KINDS,
194
+ kotlin: KOTLIN_KINDS,
195
+ swift: SWIFT_KINDS,
196
+ php: PHP_KINDS,
197
+ };
198
+ /**
199
+ * The node type(s) that constitute a call site, per language.
200
+ *
201
+ * Java is the reason this is a set rather than a string: `method_invocation` and
202
+ * `object_creation_expression` (`new Foo()`) are separate node types, and a Java
203
+ * codebase's constructor calls are a large share of its real edges. PHP is
204
+ * likewise multi-shape: a call is a function / member / nullsafe-member / scoped
205
+ * call, never a single `call_expression`.
206
+ */
207
+ const CALL_TYPES = {
208
+ typescript: new Set(["call_expression"]),
209
+ tsx: new Set(["call_expression"]),
210
+ python: new Set(["call"]),
211
+ go: new Set(["call_expression"]),
212
+ java: new Set(["method_invocation", "object_creation_expression"]),
213
+ kotlin: new Set(["call_expression"]),
214
+ swift: new Set(["call_expression"]),
215
+ php: new Set([
216
+ "function_call_expression",
217
+ "member_call_expression",
218
+ "nullsafe_member_call_expression",
219
+ "scoped_call_expression",
220
+ ]),
221
+ r: new Set(["call"]),
222
+ };
223
+ const FUNCTION_VALUE_TYPES = new Set([
224
+ "arrow_function",
225
+ "function",
226
+ "function_expression",
227
+ "generator_function",
228
+ ]);
229
+ const EMPTY_SET = new Set();
230
+ /** tree-sitter's string `parse()` fails with "Invalid argument" on any input
231
+ * ≥ 32 KB, which silently drops large files — often the most important ones (a
232
+ * 2000-line command module, a core tab implementation). The callback form has
233
+ * no such limit as long as each returned chunk is under 32 KB, so we always feed
234
+ * the source in <32 KB slices. Code-unit indexing matches `String.slice`. */
235
+ const PARSE_CHUNK = 16384;
236
+ function parseSource(parser, source) {
237
+ return parser.parse((index) => source.slice(index, index + PARSE_CHUNK)).rootNode;
238
+ }
239
+ /** Throws when `lang`'s native grammar is unavailable: callers check `nativeReady`
240
+ * (native.ts) first and hand such a file to its breadth-tier stand-in instead. */
241
+ export function extractFile(rel, source, lang) {
242
+ const root = parseSource(nativeParser(lang), source);
243
+ const bindings = collectBindings(root, lang);
244
+ const importedSymbols = collectImportedSymbols(root, lang);
245
+ const rGenerics = lang === "r" ? collectRGenerics(root) : EMPTY_SET;
246
+ const nodes = [
247
+ {
248
+ id: rel,
249
+ name: basename(rel),
250
+ kind: "file",
251
+ path: rel,
252
+ span: `L1-L${root.endPosition.row + 1}`,
253
+ signature: null,
254
+ exported: true,
255
+ origin: "ast",
256
+ body_hash: contentHash(source),
257
+ chars: source.length,
258
+ summary_state: "pending",
259
+ summary: null,
260
+ crux: null,
261
+ },
262
+ ];
263
+ const rawEdges = [];
264
+ const ctx = {
265
+ rel,
266
+ source,
267
+ lang,
268
+ kinds: KINDS_BY_LANG[lang],
269
+ scope: [],
270
+ enclosingKind: null,
271
+ parentId: rel,
272
+ bindings,
273
+ enclosingClass: null,
274
+ goReceiverVar: null,
275
+ importedSymbols,
276
+ rR6Access: null,
277
+ rGenerics,
278
+ rSuperClass: null,
279
+ };
280
+ // Every id minted this file, seeded with the file node's own id (`rel`) so a
281
+ // top-level definition can never collide with it. Threaded as its own
282
+ // parameter rather than living on WalkCtx — WalkCtx is spread into every
283
+ // childCtx, so a by-ref Set there would read as ordinary inherited context
284
+ // when it's actually accidental shared mutable state across the whole walk.
285
+ const minted = new Set([rel]);
286
+ walkNamedChildren(root.namedChildren, ctx, nodes, rawEdges, minted);
287
+ // nodes[0] is the file node; the rest are its symbols. Index the module-level
288
+ // residual on the file node so a term outside every symbol still surfaces it.
289
+ nodes[0].body_text = fileResidual(source, nodes.slice(1));
290
+ return { nodes, rawEdges };
291
+ }
292
+ /** Mint-time uniqueness: a document-order duplicate (same name reopened, or two
293
+ * sibling defs that happen to collide) gets `~2`, `~3`, ... instead of silently
294
+ * shadowing the first. The while-loop (not a single `~2` guess) is what makes
295
+ * this collision-proof: a source name that itself ends in ~N would collide
296
+ * with a single-guess suffix, so this keeps incrementing until it finds a
297
+ * truly free id rather than trusting one candidate suffix is unused. */
298
+ export function mintId(base, minted) {
299
+ let id = base;
300
+ let k = 2;
301
+ while (minted.has(id))
302
+ id = `${base}~${k++}`;
303
+ minted.add(id);
304
+ return id;
305
+ }
306
+ /**
307
+ * tree-sitter-php 0.23.x cannot parse a `const` inside an enum body (#145). An
308
+ * array initializer collapses the whole `enum_declaration` into ERROR; the
309
+ * method is recovered as a sibling `function_definition`. The current 0.24.2
310
+ * grammar parses this natively on the ABI-15-capable Tree-sitter 0.25 runtime.
311
+ * Keep recovery for malformed input with the same collapsed shape.
312
+ *
313
+ * Bound: only an ERROR that already contains `enum_case` + `name` is treated as
314
+ * a collapsed enum. Only `const_declaration` / `function_definition` /
315
+ * `method_declaration` / ERROR siblings are absorbed, stopping at a `}` ERROR.
316
+ * Unknown ERROR nodes are still walked, never mapped to a type. Clean
317
+ * class/enum trees are `class_declaration` / `enum_declaration` and skip this.
318
+ */
319
+ function phpCollapsedEnumName(node) {
320
+ if (node.type !== "ERROR")
321
+ return null;
322
+ if (!node.namedChildren.some((c) => c.type === "enum_case"))
323
+ return null;
324
+ return node.namedChildren.find((c) => c.type === "name")?.text ?? null;
325
+ }
326
+ function phpCollapsedEnumHold(node) {
327
+ return (node.type === "const_declaration" ||
328
+ node.type === "function_definition" ||
329
+ node.type === "method_declaration" ||
330
+ node.type === "ERROR");
331
+ }
332
+ function phpCollapsedEnumClose(node) {
333
+ return node.type === "ERROR" && node.text.trim() === "}";
334
+ }
335
+ function walkNamedChildren(children, ctx, out, edges, minted) {
336
+ if (ctx.lang !== "php") {
337
+ for (const child of children)
338
+ walk(child, ctx, out, edges, minted);
339
+ return;
340
+ }
341
+ for (let i = 0; i < children.length;) {
342
+ const n = children[i];
343
+ const enumName = phpCollapsedEnumName(n);
344
+ if (enumName) {
345
+ const group = [n];
346
+ let j = i + 1;
347
+ while (j < children.length && phpCollapsedEnumHold(children[j])) {
348
+ const next = children[j];
349
+ group.push(next);
350
+ j++;
351
+ if (phpCollapsedEnumClose(next))
352
+ break;
353
+ }
354
+ emitPhpCollapsedEnum(enumName, n, group, ctx, out, edges, minted);
355
+ i = j;
356
+ continue;
357
+ }
358
+ walk(n, ctx, out, edges, minted);
359
+ i++;
360
+ }
361
+ }
362
+ function emitPhpCollapsedEnum(name, errorNode, group, ctx, out, edges, minted) {
363
+ const last = group[group.length - 1];
364
+ const id = mintId(`${ctx.rel}#${[...ctx.scope, name].join(".")}`, minted);
365
+ const body = ctx.source.slice(errorNode.startIndex, last.endIndex);
366
+ out.push({
367
+ id,
368
+ name,
369
+ kind: "enum",
370
+ path: ctx.rel,
371
+ span: `L${errorNode.startPosition.row + 1}-L${last.endPosition.row + 1}`,
372
+ signature: `enum ${name}`,
373
+ exported: true,
374
+ origin: "ast",
375
+ body_hash: contentHash(body),
376
+ body_text: searchBody(body),
377
+ summary_state: "pending",
378
+ summary: null,
379
+ crux: null,
380
+ });
381
+ edges.push({ source: ctx.parentId, relation: "contains", targetId: id, file: ctx.rel });
382
+ const childCtx = {
383
+ ...ctx,
384
+ scope: [...ctx.scope, name],
385
+ enclosingKind: "enum",
386
+ parentId: id,
387
+ };
388
+ for (const g of group) {
389
+ if (phpCollapsedEnumClose(g))
390
+ continue;
391
+ if (phpCollapsedEnumName(g)) {
392
+ walkNamedChildren(g.namedChildren, childCtx, out, edges, minted);
393
+ continue;
394
+ }
395
+ walk(g, childCtx, out, edges, minted);
396
+ }
397
+ }
398
+ function walk(node, ctx, out, edges, minted) {
399
+ const desc = describe(node, ctx);
400
+ if (desc) {
401
+ // `idName` scopes the id (e.g. a Go method under its receiver: `#DB.Count`) while
402
+ // `name` stays the bare symbol name so member-call resolution matches it.
403
+ const idPart = desc.idName ?? desc.name;
404
+ const base = `${ctx.rel}#${[...ctx.scope, idPart].join(".")}`;
405
+ const id = mintId(base, minted);
406
+ const isGoMethod = ctx.lang === "go" && node.type === "method_declaration";
407
+ // The bare name of this node's OWN immediate enclosing class/receiver — for a
408
+ // Go method that's its receiver type (methods aren't nested, so ctx.enclosingClass
409
+ // wouldn't see it); for an R S3/S4 method it's the qualifier/class describeR
410
+ // already resolved (desc.owner — these don't lexically nest inside their class
411
+ // either); for every other method it's simply what the nearest ancestor class
412
+ // already set as ctx.enclosingClass. Only method nodes carry it — resolve.ts's
413
+ // ownerMethod index is the sole consumer (see NodeV1.owner's doc comment).
414
+ const owner = desc.kind === "method"
415
+ ? (isGoMethod ? (goReceiverType(node) ?? undefined) : (desc.owner ?? ctx.enclosingClass ?? undefined))
416
+ : undefined;
417
+ out.push({
418
+ id,
419
+ name: desc.name,
420
+ kind: desc.kind,
421
+ path: ctx.rel,
422
+ span: `L${desc.hashNode.startPosition.row + 1}-L${desc.hashNode.endPosition.row + 1}`,
423
+ signature: clean(ctx.source.slice(desc.hashNode.startIndex, desc.headerEnd)),
424
+ exported: ctx.lang === "python"
425
+ ? !desc.name.startsWith("_")
426
+ : ctx.lang === "go"
427
+ ? goExported(desc.name)
428
+ : ctx.lang === "r"
429
+ ? rExported(desc.name, ctx, node)
430
+ : ctx.lang === "java"
431
+ ? javaExported(node)
432
+ : ctx.lang === "kotlin"
433
+ ? kotlinExported(node)
434
+ : ctx.lang === "swift"
435
+ ? swiftExported(node)
436
+ : ctx.lang === "php"
437
+ ? phpExported(node)
438
+ : tsExported(node),
439
+ origin: "ast",
440
+ body_hash: contentHash(desc.hashNode.text),
441
+ body_text: searchBody(desc.hashNode.text),
442
+ summary_state: "pending",
443
+ summary: null,
444
+ crux: null,
445
+ ...(owner !== undefined ? { owner } : {}),
446
+ ...(desc.arity !== undefined ? { arity: desc.arity } : {}),
447
+ ...(desc.variadic ? { variadic: true } : {}),
448
+ });
449
+ // structural containment
450
+ edges.push({ source: ctx.parentId, relation: "contains", targetId: id, file: ctx.rel });
451
+ // class heritage — in Java an interface may also `extends`, and a record/enum
452
+ // may `implements`, so every type declaration is a heritage site, not just a class.
453
+ const javaTypeDecl = ctx.lang === "java" && JAVA_TYPE_KINDS.has(desc.kind);
454
+ const kotlinTypeDecl = ctx.lang === "kotlin" && KOTLIN_TYPE_KINDS.has(desc.kind);
455
+ const swiftTypeDecl = ctx.lang === "swift" && SWIFT_TYPE_KINDS.has(desc.kind);
456
+ if (desc.kind === "class" || javaTypeDecl || kotlinTypeDecl || swiftTypeDecl)
457
+ edges.push(...heritageEdges(node, id, ctx));
458
+ if (ctx.lang === "php")
459
+ edges.push(...phpAttributeReferenceEdges(node, id, ctx));
460
+ if (ctx.lang === "java")
461
+ edges.push(...javaAnnotationReferenceEdges(node, id, ctx));
462
+ const enclosingClass = desc.kind === "class" || javaTypeDecl || kotlinTypeDecl || swiftTypeDecl
463
+ ? desc.name
464
+ : isGoMethod
465
+ ? goReceiverType(node)
466
+ : (desc.owner ?? ctx.enclosingClass);
467
+ const childCtx = {
468
+ ...ctx,
469
+ scope: [...ctx.scope, idPart],
470
+ enclosingKind: desc.kind,
471
+ parentId: id,
472
+ enclosingClass,
473
+ goReceiverVar: isGoMethod ? goReceiverVarOf(node) : ctx.goReceiverVar,
474
+ importedSymbols: desc.kind === "function" || desc.kind === "method"
475
+ ? withoutShadowedImports(ctx.importedSymbols, node)
476
+ : ctx.importedSymbols,
477
+ // Reset on every new definition — this is a purely local marker for "we're
478
+ // still inside THIS class-defining call's own public=/private=/active=
479
+ // argument chain," not something that should leak into a nested definition
480
+ // (a method's own body, or — vanishingly rare but possible — another class
481
+ // defined inside one).
482
+ rR6Access: null,
483
+ // Unlike rR6Access, only reset when entering a genuinely new class (so it
484
+ // stays live through a method's whole body, where super$ / super. calls
485
+ // actually happen) — inherited unchanged for every other definition kind.
486
+ // Swift reads it off the declaration's own `:` clause, so `super.ping()`
487
+ // resolves against the PARENT type, not the overriding current one.
488
+ rSuperClass: desc.kind === "class"
489
+ ? ctx.lang === "r"
490
+ ? rR6ParentClass(node)
491
+ : ctx.lang === "swift"
492
+ ? swiftSuperClassName(node)
493
+ : null
494
+ : ctx.rSuperClass,
495
+ };
496
+ walkNamedChildren(node.namedChildren, childCtx, out, edges, minted);
497
+ return;
498
+ }
499
+ // R6 (Phase 2): `public =`/`private =`/`active =` inside an R6Class(...) call's
500
+ // own arguments is a `list(...)` call whose named entries become methods —
501
+ // this is R's version of a class body, but structurally it's several levels of
502
+ // ordinary call/argument nodes rather than a dedicated grammar construct, so it
503
+ // needs its own interception (mirrors how every other stateful/pattern-matched
504
+ // R construct in this walk needs one). `ctx.enclosingKind === "class"` scopes
505
+ // this to the class-defining call's own direct structure — once we're inside
506
+ // an actual method's body, enclosingKind has moved on to "method" and an
507
+ // unrelated nested `list(public = list(fn = function() {}))` elsewhere won't
508
+ // be misread as another class body.
509
+ if (ctx.lang === "r" &&
510
+ ctx.enclosingKind === "class" &&
511
+ ctx.rR6Access === null &&
512
+ node.type === "argument") {
513
+ const argName = node.childForFieldName("name");
514
+ const value = node.childForFieldName("value");
515
+ if (argName?.type === "identifier" &&
516
+ (argName.text === "public" || argName.text === "private" || argName.text === "active") &&
517
+ value?.type === "call" &&
518
+ rCalleeName(value) === "list") {
519
+ const access = argName.text;
520
+ for (const entry of rCallArgs(value)) {
521
+ walk(entry, { ...ctx, rR6Access: access }, out, edges, minted);
522
+ }
523
+ return;
524
+ }
525
+ }
526
+ // not a definition — capture calls/imports/references, then descend with the same context
527
+ // R's `call` node is also its ONLY vehicle for library()/require()/source() —
528
+ // there's no separate import-statement grammar construct to key off, so isImport
529
+ // must be checked before the generic calls path or every import call would be
530
+ // captured as a (harmlessly unresolvable, but wrong) `calls` edge instead.
531
+ const callTypes = CALL_TYPES[ctx.lang];
532
+ if (isImport(node, ctx.lang)) {
533
+ const spec = importSpecifier(node, ctx.lang);
534
+ if (spec)
535
+ edges.push({ source: ctx.rel, relation: "imports", specifier: spec, file: ctx.rel });
536
+ // Imported identifiers are declarations, not uses. The import-binding pass
537
+ // above already recorded them, so do not descend and emit false references.
538
+ return;
539
+ }
540
+ else if (callTypes.has(node.type)) {
541
+ // R6Class(...) / a Phase-5 mixin list(...) is already consumed by its
542
+ // enclosing binary_operator as the class definition (see describeR) — the
543
+ // walk still reaches this SAME call node again, recursing generically to
544
+ // find its public=/private=/active= arguments (there's no other path to
545
+ // them), and it must not ALSO be treated as an ordinary call to a
546
+ // function literally named "R6Class"/"list".
547
+ const consumedCallee = ctx.lang === "r" && node.type === "call" ? rCalleeName(node) : null;
548
+ const isConsumedRClassCall = consumedCallee === "R6Class" || (consumedCallee === "list" && rIsMixinContainer(node));
549
+ const callee = isConsumedRClassCall ? null : calleeName(node, ctx.lang);
550
+ if (callee) {
551
+ const callEdge = {
552
+ source: ctx.parentId,
553
+ relation: "calls",
554
+ name: callee.name,
555
+ viaMember: callee.viaMember,
556
+ file: ctx.rel,
557
+ ...(callee.kinds ? { kinds: callee.kinds } : {}),
558
+ };
559
+ // Overloading languages: the call site's argument count, to pick the right
560
+ // overload (see RawEdge.argCount).
561
+ const argCount = ctx.lang === "java" ? javaArgCount(node) : ctx.lang === "swift" ? swiftArgCount(node) : undefined;
562
+ if (argCount !== undefined)
563
+ callEdge.argCount = argCount;
564
+ // Swift: a bare lowercase call inside a type body may be an implicit-`self`
565
+ // member call (`walk()` for `self.walk()`), syntactically indistinguishable
566
+ // from a free-function call — and Swift's own lookup is member-FIRST (inner
567
+ // scope wins). So the edge is emitted as the member reading, typed to the
568
+ // enclosing class — resolved through the owner-qualified method index and
569
+ // the class's in-repo ancestor chain (`clearLogs()` in a test subclass
570
+ // finds the base class's method) — with `implicitSelf` letting resolve.ts
571
+ // fall back to the free-function reading only when no member exists on the
572
+ // chain. One edge, both readings, language-order precedence. This is
573
+ // deliberately NOT a bare-name kind widening: dogfooding on
574
+ // swift-composable-architecture, a global unique-name match bound
575
+ // `contains(element)` inside `extension Set` — a stdlib call — to an
576
+ // unrelated type's only in-repo `contains`. And not for an UpperCamelCase
577
+ // callee: that is an initializer call (`Text("hi")`), which takes
578
+ // resolve.ts's class/struct/enum fallback instead — extension nodes (kind
579
+ // "module") can never false-match it.
580
+ const swiftImplicitSelf = ctx.lang === "swift" &&
581
+ !callee.viaMember &&
582
+ !callee.kinds &&
583
+ ctx.enclosingClass &&
584
+ !/^[A-Z]/.test(callee.name);
585
+ if (swiftImplicitSelf) {
586
+ edges.push({
587
+ ...callEdge,
588
+ viaMember: true,
589
+ recvType: ctx.enclosingClass,
590
+ implicitSelf: true,
591
+ });
592
+ }
593
+ else {
594
+ const recvType = resolveRecvType(callee.receiver, ctx);
595
+ edges.push(recvType ? { ...callEdge, recvType } : callEdge);
596
+ }
597
+ }
598
+ }
599
+ else if (ctx.lang === "php" && node.type === "use_declaration") {
600
+ // Trait composition inside a class body (`use HasFactory, Notifiable;`).
601
+ // Modelled as `implements`: like an interface, a trait is a contract of
602
+ // behaviour the class mixes in (Julius's Relation set has no `uses`).
603
+ for (const t of node.namedChildren) {
604
+ if (t.type === "name" || t.type === "qualified_name") {
605
+ edges.push({ source: ctx.parentId, relation: "implements", name: t.text.replace(/^.*\\/, ""), file: ctx.rel });
606
+ }
607
+ }
608
+ return;
609
+ }
610
+ else if (node.type === "identifier" &&
611
+ !isDirectCallee(node, callTypes) &&
612
+ !isDeclarationName(node)) {
613
+ const imported = ctx.importedSymbols.get(node.text);
614
+ if (imported) {
615
+ edges.push({
616
+ source: ctx.parentId,
617
+ relation: "references",
618
+ name: imported.name,
619
+ specifier: imported.specifier,
620
+ file: ctx.rel,
621
+ });
622
+ }
623
+ }
624
+ // Java anonymous class (`new Type() { … }`): tree-sitter-java has no
625
+ // `anonymous_class` node (unlike PHP) — the body is an optional `class_body`
626
+ // on `object_creation_expression`. Mint `{anonymous}` (mirroring PHP #144 /
627
+ // `{closure}`) so nested methods take that owner instead of the enclosing
628
+ // type's, which otherwise pollutes `ownerMethod` and steals real call edges
629
+ // (#161). The constructor call edge above still fires for `new Type()`.
630
+ if (ctx.lang === "java" && node.type === "object_creation_expression") {
631
+ const body = node.namedChildren.find((c) => c.type === "class_body");
632
+ if (body) {
633
+ const idPart = "{anonymous}";
634
+ const base = `${ctx.rel}#${[...ctx.scope, idPart].join(".")}`;
635
+ const id = mintId(base, minted);
636
+ out.push({
637
+ id,
638
+ name: "{anonymous}",
639
+ kind: "class",
640
+ path: ctx.rel,
641
+ span: `L${node.startPosition.row + 1}-L${node.endPosition.row + 1}`,
642
+ signature: clean(ctx.source.slice(node.startIndex, body.startIndex)),
643
+ exported: false,
644
+ origin: "ast",
645
+ body_hash: contentHash(node.text),
646
+ body_text: searchBody(node.text),
647
+ summary_state: "pending",
648
+ summary: null,
649
+ crux: null,
650
+ });
651
+ edges.push({ source: ctx.parentId, relation: "contains", targetId: id, file: ctx.rel });
652
+ // Single supertype from `new Type()`: emit `implements` so an interface
653
+ // target resolves (adapters are the common case; a class target drops
654
+ // under resolve's implements kind filter — drop-not-guess).
655
+ const superName = javaConstructedTypeName(node.childForFieldName("type"));
656
+ if (superName) {
657
+ edges.push({ source: id, relation: "implements", name: superName, file: ctx.rel });
658
+ }
659
+ const anonCtx = {
660
+ ...ctx,
661
+ scope: [...ctx.scope, idPart],
662
+ enclosingKind: "class",
663
+ parentId: id,
664
+ enclosingClass: "{anonymous}",
665
+ };
666
+ for (const child of node.namedChildren) {
667
+ walk(child, child.type === "class_body" ? anonCtx : ctx, out, edges, minted);
668
+ }
669
+ return;
670
+ }
671
+ }
672
+ for (const child of node.namedChildren)
673
+ walk(child, ctx, out, edges, minted);
674
+ }
675
+ /**
676
+ * Named imports whose local binding can be recognized later as a symbol use.
677
+ * Namespace/default imports are intentionally excluded: they do not tell us
678
+ * the exported symbol name, so wiring them would require guessing.
679
+ */
680
+ function collectImportedSymbols(root, lang) {
681
+ if (lang === "typescript" || lang === "tsx") {
682
+ const out = new Map();
683
+ const visit = (node) => {
684
+ if (node.type === "import_statement") {
685
+ const specifier = importSpecifier(node, lang);
686
+ if (!specifier)
687
+ return;
688
+ collectTsImportBindings(node, specifier, out);
689
+ return;
690
+ }
691
+ for (const child of node.namedChildren)
692
+ visit(child);
693
+ };
694
+ visit(root);
695
+ return out;
696
+ }
697
+ if (lang === "php")
698
+ return collectPhpImportedSymbols(root);
699
+ return new Map();
700
+ }
701
+ /** PHP `use` bindings: local alias → { exported name, FQN specifier }. */
702
+ function collectPhpImportedSymbols(root) {
703
+ const out = new Map();
704
+ const visit = (node) => {
705
+ if (node.type === "namespace_use_declaration") {
706
+ collectPhpUseDeclaration(node, out);
707
+ return;
708
+ }
709
+ for (const child of node.namedChildren)
710
+ visit(child);
711
+ };
712
+ visit(root);
713
+ return out;
714
+ }
715
+ function collectPhpUseDeclaration(decl, out) {
716
+ const prefix = decl.namedChildren.find((c) => c.type === "namespace_name")?.text.replace(/\\$/, "") ?? "";
717
+ const clauses = [];
718
+ for (const child of decl.namedChildren) {
719
+ if (child.type === "namespace_use_clause")
720
+ clauses.push(child);
721
+ if (child.type === "namespace_use_group") {
722
+ for (const c of child.namedChildren) {
723
+ if (c.type === "namespace_use_clause")
724
+ clauses.push(c);
725
+ }
726
+ }
727
+ }
728
+ for (const clause of clauses) {
729
+ const binding = phpUseClauseBinding(clause, prefix);
730
+ if (binding)
731
+ out.set(binding.local, { name: binding.name, specifier: binding.specifier });
732
+ }
733
+ }
734
+ function phpUseClauseBinding(clause, prefix) {
735
+ const names = clause.namedChildren.filter((c) => c.type === "name");
736
+ const qualified = clause.namedChildren.find((c) => c.type === "qualified_name");
737
+ let fqn;
738
+ let importedName;
739
+ if (qualified) {
740
+ fqn = qualified.text.replace(/^\\/, "");
741
+ importedName = fqn.replace(/^.*\\/, "");
742
+ }
743
+ else if (names[0]) {
744
+ importedName = names[0].text;
745
+ fqn = prefix ? `${prefix}\\${importedName}` : importedName;
746
+ }
747
+ else {
748
+ return null;
749
+ }
750
+ const alias = qualified && names.length >= 1
751
+ ? names[names.length - 1].text
752
+ : names.length >= 2
753
+ ? names[1].text
754
+ : undefined;
755
+ const local = alias ?? importedName;
756
+ return { local, name: importedName, specifier: fqn };
757
+ }
758
+ /** PHP 8 attributes on a definition → `references` edges to the attribute class. */
759
+ function phpAttributeReferenceEdges(node, sourceId, ctx) {
760
+ const edges = [];
761
+ for (const child of node.namedChildren) {
762
+ if (child.type !== "attribute_list")
763
+ continue;
764
+ for (const group of child.namedChildren) {
765
+ if (group.type !== "attribute_group")
766
+ continue;
767
+ for (const attr of group.namedChildren) {
768
+ if (attr.type !== "attribute")
769
+ continue;
770
+ const ref = phpAttributeClassRef(attr, ctx);
771
+ if (ref) {
772
+ edges.push({
773
+ source: sourceId,
774
+ relation: "references",
775
+ name: ref.name,
776
+ ...(ref.specifier ? { specifier: ref.specifier } : {}),
777
+ file: ctx.rel,
778
+ });
779
+ }
780
+ }
781
+ }
782
+ }
783
+ return edges;
784
+ }
785
+ function phpAttributeClassRef(attr, ctx) {
786
+ const nameNode = attr.childForFieldName("name") ??
787
+ attr.namedChildren.find((c) => c.type === "name" || c.type === "qualified_name");
788
+ if (!nameNode)
789
+ return null;
790
+ if (nameNode.type === "qualified_name") {
791
+ const fqn = nameNode.text.replace(/^\\/, "");
792
+ return { name: fqn.replace(/^.*\\/, ""), specifier: fqn };
793
+ }
794
+ const bare = nameNode.text;
795
+ const imported = ctx.importedSymbols.get(bare);
796
+ if (imported)
797
+ return { name: imported.name, specifier: imported.specifier };
798
+ return { name: bare };
799
+ }
800
+ /** Java annotations on a definition → `references` edges to the annotation type. */
801
+ function javaAnnotationReferenceEdges(node, sourceId, ctx) {
802
+ const edges = [];
803
+ const mods = node.namedChildren.find((c) => c.type === "modifiers");
804
+ if (!mods)
805
+ return edges;
806
+ for (const child of mods.namedChildren) {
807
+ if (child.type !== "marker_annotation" && child.type !== "annotation")
808
+ continue;
809
+ const name = javaAnnotationTypeName(child);
810
+ if (name) {
811
+ edges.push({
812
+ source: sourceId,
813
+ relation: "references",
814
+ name,
815
+ file: ctx.rel,
816
+ });
817
+ }
818
+ }
819
+ return edges;
820
+ }
821
+ /** The type named by `@Foo` / `@a.b.Foo(...)`. Arguments are ignored (issue #89).
822
+ * A scoped name is kept whole, matching heritage: a bare last segment would
823
+ * false-match an unrelated in-repo type (#103). */
824
+ function javaAnnotationTypeName(anno) {
825
+ const nameNode = anno.childForFieldName("name");
826
+ if (!nameNode)
827
+ return null;
828
+ if (nameNode.type === "identifier" || nameNode.type === "scoped_identifier")
829
+ return nameNode.text;
830
+ return null;
831
+ }
832
+ function collectTsImportBindings(node, specifier, out) {
833
+ if (node.type === "import_specifier") {
834
+ const name = node.childForFieldName("name")?.text;
835
+ const local = node.childForFieldName("alias")?.text ?? name;
836
+ if (name && local)
837
+ out.set(local, { name, specifier });
838
+ return;
839
+ }
840
+ for (const child of node.namedChildren)
841
+ collectTsImportBindings(child, specifier, out);
842
+ }
843
+ /**
844
+ * Do these two wrappers stand for the same syntax node? `===` does not answer that:
845
+ * node-tree-sitter materializes `SyntaxNode` objects on demand and caches them
846
+ * weakly, so reaching one node twice can return two different JS objects. Comparing
847
+ * wrappers makes a purely syntactic question depend on collector timing — two cold
848
+ * builds of unchanged source then disagree on `references` edges (#116).
849
+ *
850
+ * `id` is the stable identity, unique within one tree, so the tree is compared too.
851
+ * A `Tree` is one object per parse (unlike its nodes), so `===` is right for it.
852
+ */
853
+ function sameSyntaxNode(a, b) {
854
+ return !!a && !!b && a.tree === b.tree && a.id === b.id;
855
+ }
856
+ /**
857
+ * A parameter or local declaration wins over an import inside that function.
858
+ * Drop that imported binding for the whole function rather than create a false
859
+ * dependency. Nested functions are separate scopes and filter themselves.
860
+ */
861
+ function withoutShadowedImports(imports, definition) {
862
+ if (imports.size === 0)
863
+ return imports;
864
+ const shadowed = new Set();
865
+ const definitionValue = definition.childForFieldName("value");
866
+ const visit = (node) => {
867
+ if (!sameSyntaxNode(node, definition) && !sameSyntaxNode(node, definitionValue) && isFunctionBoundary(node)) {
868
+ const name = node.childForFieldName("name");
869
+ if (name?.type === "identifier")
870
+ shadowed.add(name.text);
871
+ return;
872
+ }
873
+ if (node.type === "variable_declarator") {
874
+ const name = node.childForFieldName("name");
875
+ if (name?.type === "identifier")
876
+ shadowed.add(name.text);
877
+ }
878
+ else if (node.type === "required_parameter" || node.type === "optional_parameter") {
879
+ const pattern = node.childForFieldName("pattern");
880
+ if (pattern?.type === "identifier")
881
+ shadowed.add(pattern.text);
882
+ }
883
+ else if (node.type === "identifier" && node.parent?.type === "formal_parameters") {
884
+ shadowed.add(node.text);
885
+ }
886
+ for (const child of node.namedChildren)
887
+ visit(child);
888
+ };
889
+ visit(definition);
890
+ if (![...shadowed].some((name) => imports.has(name)))
891
+ return imports;
892
+ return new Map([...imports].filter(([local]) => !shadowed.has(local)));
893
+ }
894
+ function isFunctionBoundary(node) {
895
+ return (node.type === "function_declaration" ||
896
+ node.type === "generator_function_declaration" ||
897
+ node.type === "method_definition" ||
898
+ node.type === "arrow_function" ||
899
+ node.type === "function_expression" ||
900
+ node.type === "function");
901
+ }
902
+ /** A direct invocation already emits a stronger `calls` edge. Java names the callee
903
+ * in a `name` field (there is no `function` field on `method_invocation`), so both
904
+ * spellings count. */
905
+ function isDirectCallee(node, callTypes) {
906
+ const parent = node.parent;
907
+ if (!parent || !callTypes.has(parent.type))
908
+ return false;
909
+ return (sameSyntaxNode(parent.childForFieldName("function"), node) ||
910
+ sameSyntaxNode(parent.childForFieldName("name"), node));
911
+ }
912
+ /** Definition/declaration identifiers name a new binding; they do not use one. */
913
+ function isDeclarationName(node) {
914
+ const parent = node.parent;
915
+ return sameSyntaxNode(parent?.childForFieldName("name"), node);
916
+ }
917
+ /** Recognize the definition shapes: mapped node types, Go's type/method forms, and
918
+ * TS arrow-consts. */
919
+ function describe(node, ctx) {
920
+ if (ctx.lang === "go")
921
+ return describeGo(node, ctx);
922
+ if (ctx.lang === "r")
923
+ return describeR(node, ctx);
924
+ if (ctx.lang === "java")
925
+ return describeJava(node, ctx);
926
+ if (ctx.lang === "kotlin")
927
+ return describeKotlin(node, ctx);
928
+ if (ctx.lang === "swift")
929
+ return describeSwift(node, ctx);
930
+ // PHP closures: `$h = function () {…}` / `fn() => …`, and bare callbacks
931
+ // (`$routes->get('/x', function () {…})`). Captured as function nodes so a
932
+ // closure-only file (a routing table, a DI container) keeps its structure
933
+ // and the calls inside attribute to the closure, not the file.
934
+ if (ctx.lang === "php" && (node.type === "anonymous_function" || node.type === "arrow_function")) {
935
+ const body = node.childForFieldName("body");
936
+ return {
937
+ name: phpClosureName(node),
938
+ kind: "function",
939
+ headerEnd: body ? body.startIndex : node.endIndex,
940
+ hashNode: node,
941
+ };
942
+ }
943
+ // PHP anonymous classes (`new class implements I {…}`): minted as a class
944
+ // node named `{anonymous}` (mirroring `{closure}`, deduplicated per file by
945
+ // mintId). Without this the type vanished — no node, no heritage edge — and
946
+ // its methods mis-attributed to the enclosing function (issue #144). The
947
+ // class kind makes the walk emit heritageEdges (base_clause /
948
+ // class_interface_clause are direct children) and own the nested methods.
949
+ if (ctx.lang === "php" && node.type === "anonymous_class") {
950
+ const body = node.childForFieldName("body");
951
+ return {
952
+ name: "{anonymous}",
953
+ kind: "class",
954
+ headerEnd: body ? body.startIndex : node.endIndex,
955
+ hashNode: node,
956
+ };
957
+ }
958
+ const mapped = ctx.kinds[node.type];
959
+ if (mapped) {
960
+ const name = node.childForFieldName("name")?.text;
961
+ if (!name)
962
+ return null;
963
+ let kind = mapped;
964
+ if (ctx.lang === "python" && mapped === "function" && ctx.enclosingKind === "class") {
965
+ kind = "method";
966
+ }
967
+ // tree-sitter-php 0.23.x recovers a collapsed enum method as function_definition
968
+ // at program scope; walkNamedChildren reparents it under the enum, and this
969
+ // promotion is what keeps the kind `method` rather than a leaked `function`.
970
+ if (ctx.lang === "php" && mapped === "function" && ctx.enclosingKind === "enum") {
971
+ kind = "method";
972
+ }
973
+ const body = node.childForFieldName("body");
974
+ return { name, kind, headerEnd: body ? body.startIndex : node.endIndex, hashNode: node };
975
+ }
976
+ // TS: `const foo = (…) => …` / `const foo = function () {}`
977
+ if ((ctx.lang === "typescript" || ctx.lang === "tsx") && node.type === "variable_declarator") {
978
+ const value = node.childForFieldName("value");
979
+ if (value && FUNCTION_VALUE_TYPES.has(value.type)) {
980
+ const name = node.childForFieldName("name")?.text;
981
+ if (!name)
982
+ return null;
983
+ const vbody = value.childForFieldName("body");
984
+ return {
985
+ name,
986
+ kind: "function",
987
+ headerEnd: vbody ? vbody.startIndex : node.endIndex,
988
+ hashNode: node,
989
+ };
990
+ }
991
+ }
992
+ return null;
993
+ }
994
+ /** Go definition shapes: top-level funcs, receiver methods, and named types
995
+ * (struct / interface / type alias). Methods carry no nesting — they're qualified
996
+ * by their receiver type (`User.Save`) so calls can resolve and cards read clearly. */
997
+ function describeGo(node, _ctx) {
998
+ if (node.type === "function_declaration") {
999
+ const name = node.childForFieldName("name")?.text;
1000
+ if (!name)
1001
+ return null;
1002
+ const body = node.childForFieldName("body");
1003
+ return { name, kind: "function", headerEnd: body ? body.startIndex : node.endIndex, hashNode: node };
1004
+ }
1005
+ if (node.type === "method_declaration") {
1006
+ const name = node.childForFieldName("name")?.text;
1007
+ if (!name)
1008
+ return null;
1009
+ const recv = goReceiverType(node);
1010
+ const body = node.childForFieldName("body");
1011
+ // Bare `name` (so `recv.Method()` calls resolve); receiver-qualified `idName`
1012
+ // (so the id is `file.go#Receiver.Method` and stays unique per receiver).
1013
+ return {
1014
+ name,
1015
+ idName: recv ? `${recv}.${name}` : name,
1016
+ kind: "method",
1017
+ headerEnd: body ? body.startIndex : node.endIndex,
1018
+ hashNode: node,
1019
+ };
1020
+ }
1021
+ // `type Name <shape>` — one type_spec per name (grouped `type ( … )` yields several).
1022
+ if (node.type === "type_spec") {
1023
+ const name = node.childForFieldName("name")?.text;
1024
+ if (!name)
1025
+ return null;
1026
+ const type = node.childForFieldName("type");
1027
+ const kind = type?.type === "struct_type" ? "struct" : type?.type === "interface_type" ? "interface" : "type";
1028
+ // Header ends where the body opens (`{`) for struct/interface, else the whole node
1029
+ // (a one-line alias like `type ID int`).
1030
+ const headerEnd = type && (kind === "struct" || kind === "interface") ? type.startIndex : node.endIndex;
1031
+ return { name, kind, headerEnd, hashNode: node };
1032
+ }
1033
+ return null;
1034
+ }
1035
+ /**
1036
+ * R definition shapes. `function_definition` carries no name field at all, so
1037
+ * unlike every other supported language the name always comes from an
1038
+ * enclosing assignment, detected here. The plain-function assignment check
1039
+ * (op-filtering `binary_operator`, the right-assign body-swap) is duplicated
1040
+ * in bindings.ts's own `rDefName` rather than imported — same reasoning as
1041
+ * this file's Go receiver helpers: bindings.ts can't take a value import back
1042
+ * on extract.ts. bindings.ts doesn't need the S3/S4/R6 half of this at all
1043
+ * (no handleR binding collector exists — see bindings.ts's own doc comment).
1044
+ *
1045
+ * Phase 1 (flat extraction — every named function is a plain `function` node)
1046
+ * plus Phase 2 (S3/S4/R6 class awareness, R's class systems being library
1047
+ * *convention* rather than grammar syntax, unlike every other language julius
1048
+ * supports):
1049
+ * - left-assign (`<-`/`<<-`/`=`) / right-assign (`->`/`->>`) function
1050
+ * assignment — Phase 1's shape, see the two `binary_operator`/
1051
+ * `function_definition` branches below. Right-assign's AST shape does NOT
1052
+ * mirror left-assign's the way it looks like it should (confirmed
1053
+ * empirically, not assumed — R's `->` has low enough precedence that it's
1054
+ * absorbed into the function's own `body` field as a `binary_operator`
1055
+ * instead of the function sitting inside an outer wrapper); only an
1056
+ * explicitly parenthesized `(function() {}) -> foo` produces the
1057
+ * "expected" outer-wrapping shape, which isn't specially handled (falls
1058
+ * through as an anonymous function).
1059
+ * - `name.Class <- function() {}` — an S3 method, IF `name` is a known
1060
+ * generic (registered locally via `UseMethod()` in this file, or one of a
1061
+ * curated set of common base-R generics — see `rS3Split`'s doc comment
1062
+ * for the false-positive risk this guards against).
1063
+ * - `Foo <- R6::R6Class("Foo", public = list(...), private = list(...))` —
1064
+ * an R6 class; its `public =`/`private =`/`active =` list entries become
1065
+ * methods, handled by walk()'s own `argument`-node interception (this
1066
+ * function only recognizes the class itself; the "a call defines a
1067
+ * symbol" list-walking lives in walk() since it needs to mint several
1068
+ * nodes, not describe a single one).
1069
+ * - `Foo <- list(public = list(...), private = list(...))` (Phase 5) — a
1070
+ * plain-list "mixin"/"extension" bundle, NOT wrapped in `R6::R6Class(...)`
1071
+ * at all: a real, deliberate convention found dogfooding against a real
1072
+ * R6-heavy corpus (25 files, 11 of them entirely invisible to the graph
1073
+ * without this) for sharing method bundles across classes via splicing
1074
+ * (`public = c(Foo$public, list(...))`) rather than `inherit =`. Only
1075
+ * recognized when the list actually has a `public =`/`private =` entry
1076
+ * (see `rIsMixinContainer`) — an ordinary data/config list never matches.
1077
+ * Reuses kind "class" (nothing better-fitting exists, and everything
1078
+ * downstream — the method-list walking, visibility — only cares that
1079
+ * ctx.enclosingKind is "class", not how the container was spelled); no
1080
+ * heritage edge, since splicing isn't `inherit =`-based inheritance.
1081
+ * - `setClass("Foo", ...)` / `setMethod("generic", "Foo", function() {})`
1082
+ * — S4 class/method calls, recognized as bare top-level `call` nodes
1083
+ * (setClass/setMethod have side effects registering with the S4 system;
1084
+ * they're essentially never assigned to a variable). `setGeneric()` is
1085
+ * NOT specially extracted — it doesn't naturally map to a class or method
1086
+ * kind, and the plan flags it as a case not worth the design risk.
1087
+ */
1088
+ function describeR(node, ctx) {
1089
+ if (node.type === "binary_operator") {
1090
+ const op = node.childForFieldName("operator")?.text;
1091
+ if (!op || !R_ASSIGN_OPS.has(op))
1092
+ return null;
1093
+ const lhs = node.childForFieldName("lhs");
1094
+ const rhs = node.childForFieldName("rhs");
1095
+ if (lhs?.type !== "identifier")
1096
+ return null;
1097
+ if (rhs?.type === "function_definition") {
1098
+ return rFunctionDescriptor(lhs.text, rhs, rhs.childForFieldName("body"), ctx);
1099
+ }
1100
+ if (rhs?.type === "call" && rCalleeName(rhs) === "R6Class") {
1101
+ // The class node itself; its public=/private=/active= method lists are
1102
+ // handled by walk()'s own `argument`-node interception, not here.
1103
+ return { name: lhs.text, kind: "class", headerEnd: rhs.endIndex, hashNode: rhs };
1104
+ }
1105
+ if (rhs?.type === "call" && rCalleeName(rhs) === "list" && rIsMixinContainer(rhs)) {
1106
+ // Phase 5: a plain-list mixin/extension bundle — same treatment as R6Class.
1107
+ return { name: lhs.text, kind: "class", headerEnd: rhs.endIndex, hashNode: rhs };
1108
+ }
1109
+ return null;
1110
+ }
1111
+ if (node.type === "function_definition") {
1112
+ // Right-assign (`function() {} -> foo`): see this function's own doc
1113
+ // comment for why this doesn't mirror the binary_operator branch above.
1114
+ const body = node.childForFieldName("body");
1115
+ if (body?.type !== "binary_operator")
1116
+ return null;
1117
+ const op = body.childForFieldName("operator")?.text;
1118
+ if (!op || !R_RIGHT_ASSIGN_OPS.has(op))
1119
+ return null;
1120
+ const rhs = body.childForFieldName("rhs");
1121
+ if (rhs?.type !== "identifier")
1122
+ return null;
1123
+ return rFunctionDescriptor(rhs.text, node, body.childForFieldName("lhs"), ctx);
1124
+ }
1125
+ if (node.type === "call") {
1126
+ return describeRTopLevelCall(node);
1127
+ }
1128
+ // R6 (Phase 2): reached via walk()'s own `argument`-node interception for a
1129
+ // `public =`/`private =`/`active =` list entry — see the special case there
1130
+ // for why this can't just be a flat kind-table/node-type check like every
1131
+ // other definition shape.
1132
+ if (node.type === "argument" && ctx.rR6Access !== null) {
1133
+ const argName = node.childForFieldName("name");
1134
+ const value = node.childForFieldName("value");
1135
+ if (argName?.type !== "identifier" || value?.type !== "function_definition")
1136
+ return null;
1137
+ const body = value.childForFieldName("body");
1138
+ return {
1139
+ name: argName.text,
1140
+ kind: "method",
1141
+ headerEnd: body ? body.startIndex : value.endIndex,
1142
+ hashNode: value,
1143
+ // owner deliberately unset — R6 methods DO lexically nest inside the
1144
+ // class-defining call, so ctx.enclosingClass already has it.
1145
+ };
1146
+ }
1147
+ return null;
1148
+ }
1149
+ const R_ASSIGN_OPS = new Set(["<-", "<<-", "="]);
1150
+ const R_RIGHT_ASSIGN_OPS = new Set(["->", "->>"]);
1151
+ /** A plain function assignment (left- or right-assign), OR — if `name` matches
1152
+ * a known S3 generic's `generic.Class` pattern — an S3 method instead. `body`
1153
+ * is the function's REAL content node (already resolved by the caller for
1154
+ * either assignment direction), used only for `headerEnd`; `hashNode` is
1155
+ * always the `function_definition` itself. */
1156
+ function rFunctionDescriptor(name, hashNode, body, ctx) {
1157
+ const headerEnd = body ? body.startIndex : hashNode.endIndex;
1158
+ const s3 = rS3Split(name, ctx.rGenerics);
1159
+ if (s3) {
1160
+ return {
1161
+ name: s3.generic,
1162
+ idName: `${s3.className}.${s3.generic}`,
1163
+ kind: "method",
1164
+ headerEnd,
1165
+ hashNode,
1166
+ owner: s3.className,
1167
+ };
1168
+ }
1169
+ return { name, kind: "function", headerEnd, hashNode };
1170
+ }
1171
+ /**
1172
+ * S3 dispatch detection: does `name` split as `generic.Class` for some KNOWN
1173
+ * generic? Tries the longest possible generic prefix first (so a dotted
1174
+ * generic itself, like `as.character`, is found before a shorter false match)
1175
+ * and only ever matches a generic that's either registered locally via
1176
+ * `UseMethod()` in this file (see `collectRGenerics`) or in the small curated
1177
+ * `R_BASE_GENERICS` set below.
1178
+ *
1179
+ * This is the genuinely ambiguous part of R support the plan calls out:
1180
+ * `read.csv`, `data.frame`, and `as.character` used as an ordinary helper
1181
+ * name are NOT S3 dispatch, and nothing in the grammar distinguishes them
1182
+ * from `print.MyClass`. Erring toward the curated set staying small — a
1183
+ * missed S3 method (false negative, falls back to an ordinary `function`
1184
+ * node) is a much smaller problem than a false positive misfiling an
1185
+ * unrelated dotted-name function as some other class's method.
1186
+ */
1187
+ function rS3Split(name, generics) {
1188
+ const parts = name.split(".");
1189
+ if (parts.length < 2)
1190
+ return null;
1191
+ for (let i = parts.length - 1; i >= 1; i--) {
1192
+ const generic = parts.slice(0, i).join(".");
1193
+ if (generics.has(generic) || R_BASE_GENERICS.has(generic)) {
1194
+ return { generic, className: parts.slice(i).join(".") };
1195
+ }
1196
+ }
1197
+ return null;
1198
+ }
1199
+ /** Common base-R S3 generics worth assuming even without local evidence —
1200
+ * print.Foo/format.Foo etc. are the single most common real-world S3
1201
+ * pattern, and a local `UseMethod()` call will never exist for them (they
1202
+ * ship in base/methods/stats, not the user's own repo). Deliberately small
1203
+ * and unsurprising rather than exhaustive — see `rS3Split`'s doc comment. */
1204
+ const R_BASE_GENERICS = new Set([
1205
+ "print",
1206
+ "format",
1207
+ "summary",
1208
+ "plot",
1209
+ "str",
1210
+ "toString",
1211
+ "as.character",
1212
+ "as.list",
1213
+ "as.data.frame",
1214
+ "as.vector",
1215
+ "as.numeric",
1216
+ "as.matrix",
1217
+ "length",
1218
+ "dim",
1219
+ "names",
1220
+ "rev",
1221
+ "sort",
1222
+ "unique",
1223
+ "predict",
1224
+ "coef",
1225
+ "residuals",
1226
+ "fitted",
1227
+ "update",
1228
+ "merge",
1229
+ "all.equal",
1230
+ "anova",
1231
+ "confint",
1232
+ "vcov",
1233
+ "logLik",
1234
+ ]);
1235
+ /** Every S3 generic THIS file registers via a local `UseMethod()` call, so
1236
+ * `rS3Split` can recognize `generic.Class` methods for a repo's own generics,
1237
+ * not just the base-R ones. Runs once per file, ahead of the main walk (same
1238
+ * pre-pass shape as `collectImportedSymbols`). Cross-file generics — a
1239
+ * generic defined in one file, dispatched on in another — aren't found this
1240
+ * way; that would need a whole-repo pass extractFile has no visibility into,
1241
+ * the same limitation Go/C++'s per-file bindings already accept. */
1242
+ function collectRGenerics(root) {
1243
+ const generics = new Set();
1244
+ const visit = (node) => {
1245
+ let fnDef = null;
1246
+ let ownName = null;
1247
+ if (node.type === "binary_operator") {
1248
+ const op = node.childForFieldName("operator")?.text;
1249
+ const lhs = node.childForFieldName("lhs");
1250
+ const rhs = node.childForFieldName("rhs");
1251
+ if (op && R_ASSIGN_OPS.has(op) && lhs?.type === "identifier" && rhs?.type === "function_definition") {
1252
+ fnDef = rhs;
1253
+ ownName = lhs.text;
1254
+ }
1255
+ }
1256
+ else if (node.type === "function_definition") {
1257
+ const body = node.childForFieldName("body");
1258
+ if (body?.type === "binary_operator") {
1259
+ const op = body.childForFieldName("operator")?.text;
1260
+ const rhs = body.childForFieldName("rhs");
1261
+ if (op && R_RIGHT_ASSIGN_OPS.has(op) && rhs?.type === "identifier") {
1262
+ fnDef = node;
1263
+ ownName = rhs.text;
1264
+ }
1265
+ }
1266
+ }
1267
+ if (fnDef && ownName) {
1268
+ const arg = findUseMethodArg(fnDef.childForFieldName("body"));
1269
+ if (arg !== undefined)
1270
+ generics.add(arg || ownName); // "" means UseMethod() with no args
1271
+ }
1272
+ for (const child of node.namedChildren)
1273
+ visit(child);
1274
+ };
1275
+ visit(root);
1276
+ return generics;
1277
+ }
1278
+ /** Searches a function body for a `UseMethod(...)` call and returns its
1279
+ * string-literal generic-name argument, `""` if called with no arguments
1280
+ * (defaults to the enclosing function's own name), or `undefined` if no
1281
+ * `UseMethod` call is found at all. */
1282
+ function findUseMethodArg(node) {
1283
+ if (!node)
1284
+ return undefined;
1285
+ if (node.type === "call" && rCalleeName(node) === "UseMethod") {
1286
+ const first = rCallArgs(node)[0]?.childForFieldName("value");
1287
+ return first?.type === "string" ? (rStringContent(first) ?? "") : "";
1288
+ }
1289
+ for (const child of node.namedChildren) {
1290
+ const found = findUseMethodArg(child);
1291
+ if (found !== undefined)
1292
+ return found;
1293
+ }
1294
+ return undefined;
1295
+ }
1296
+ /** S4: `setClass("Foo", ...)` → a class; `setMethod("generic", "Foo",
1297
+ * function() {})` → a method owned by "Foo". Both are ordinary top-level
1298
+ * `call` nodes — S4's registration functions have side effects and are
1299
+ * essentially never assigned to a variable, unlike R6Class. */
1300
+ function describeRTopLevelCall(node) {
1301
+ const callee = rCalleeName(node);
1302
+ if (callee === "setClass") {
1303
+ const first = rCallArgs(node)[0]?.childForFieldName("value");
1304
+ const name = first?.type === "string" ? rStringContent(first) : null;
1305
+ if (!name)
1306
+ return null;
1307
+ return { name, kind: "class", headerEnd: node.endIndex, hashNode: node };
1308
+ }
1309
+ if (callee === "setMethod") {
1310
+ const args = rCallArgs(node);
1311
+ const generic = args[0] ? rStringContent(args[0].childForFieldName("value") ?? null) : null;
1312
+ const className = args[1] ? rStringContent(args[1].childForFieldName("value") ?? null) : null;
1313
+ const defArg = args.find((a) => a.childForFieldName("name")?.text === "definition") ?? args[2];
1314
+ const fnDef = defArg?.childForFieldName("value");
1315
+ if (!generic || !className || fnDef?.type !== "function_definition")
1316
+ return null;
1317
+ const body = fnDef.childForFieldName("body");
1318
+ return {
1319
+ name: generic,
1320
+ idName: `${className}.${generic}`,
1321
+ kind: "method",
1322
+ headerEnd: body ? body.startIndex : fnDef.endIndex,
1323
+ hashNode: fnDef,
1324
+ owner: className,
1325
+ };
1326
+ }
1327
+ return null;
1328
+ }
1329
+ /** A call's callee name, whether bare (`R6Class(...)`) or namespace-qualified
1330
+ * (`R6::R6Class(...)`). Null if the callee isn't a simple name (e.g. itself a
1331
+ * call, or a `$`-based access). */
1332
+ function rCalleeName(node) {
1333
+ const fn = node.childForFieldName("function");
1334
+ if (fn?.type === "identifier")
1335
+ return fn.text;
1336
+ if (fn?.type === "namespace_operator") {
1337
+ const rhs = fn.childForFieldName("rhs");
1338
+ return rhs?.type === "identifier" ? rhs.text : null;
1339
+ }
1340
+ return null;
1341
+ }
1342
+ /** A call's positional/named `argument` children (skipping the `,`/`(`/`)`
1343
+ * punctuation tokens that share the `arguments` node's child list). */
1344
+ function rCallArgs(node) {
1345
+ return node.childForFieldName("arguments")?.namedChildren.filter((c) => c.type === "argument") ?? [];
1346
+ }
1347
+ /** An R `string` node's unquoted text, or null if `node` isn't a string. */
1348
+ function rStringContent(node) {
1349
+ if (node?.type !== "string")
1350
+ return null;
1351
+ const content = node.namedChildren.find((c) => c.type === "string_content");
1352
+ return content?.text ?? null;
1353
+ }
1354
+ /** The value of a call's named argument (`setClass("Foo", contains = "Base")`
1355
+ * → the `contains` argument), or null if absent. */
1356
+ function rNamedArg(node, argName) {
1357
+ const arg = rCallArgs(node).find((a) => a.childForFieldName("name")?.text === argName);
1358
+ return arg?.childForFieldName("value") ?? null;
1359
+ }
1360
+ /** An R6 class-defining node's `inherit =` parent class name (a bare
1361
+ * identifier — the parent's own generator variable, not a string), for
1362
+ * `super$` call resolution (Phase 3). `node` is whatever describeR matched: a
1363
+ * binary_operator for R6 (`Foo <- R6::R6Class(...)`) or, for any other kind of
1364
+ * class (S4's setClass, which has no `super`), the call itself — always null
1365
+ * there since `rCalleeName(call) !== "R6Class"`. */
1366
+ function rR6ParentClass(node) {
1367
+ const call = node.type === "binary_operator" ? node.childForFieldName("rhs") : node;
1368
+ if (call?.type !== "call" || rCalleeName(call) !== "R6Class")
1369
+ return null;
1370
+ const value = rNamedArg(call, "inherit");
1371
+ return value?.type === "identifier" ? value.text : null;
1372
+ }
1373
+ /** Does this `list(...)` call look like a Phase-5 mixin/extension bundle —
1374
+ * i.e. does it have a `public =` or `private =` entry whose own value is
1375
+ * itself a `list(...)` call? This is the one check standing between "class-
1376
+ * like container" and an ordinary data/config list (`list(a = 1, b = 2)`,
1377
+ * or even one that happens to have a field named "public" holding something
1378
+ * else) — real code never coincidentally shapes plain data this way, so it's
1379
+ * a safe, precise signal without needing a naming-convention heuristic. */
1380
+ function rIsMixinContainer(node) {
1381
+ return rCallArgs(node).some((a) => {
1382
+ const name = a.childForFieldName("name")?.text;
1383
+ if (name !== "public" && name !== "private")
1384
+ return false;
1385
+ const value = a.childForFieldName("value");
1386
+ return value?.type === "call" && rCalleeName(value) === "list";
1387
+ });
1388
+ }
1389
+ /** A base-class name list from either a bare string (`contains = "Base"`) or
1390
+ * a `c(...)` call of strings (`contains = c("Base1", "Base2")`) — S4's
1391
+ * multiple-inheritance form. */
1392
+ function rStringOrCVector(value) {
1393
+ if (!value)
1394
+ return [];
1395
+ const single = rStringContent(value);
1396
+ if (single)
1397
+ return [single];
1398
+ if (value.type === "call" && rCalleeName(value) === "c") {
1399
+ return rCallArgs(value)
1400
+ .map((a) => rStringContent(a.childForFieldName("value")))
1401
+ .filter((s) => !!s);
1402
+ }
1403
+ return [];
1404
+ }
1405
+ /** R6 visibility follows the `public =`/`private =`/`active =` section a
1406
+ * method was declared in (see walk()'s `argument`-node interception) —
1407
+ * `ctx.rR6Access` is only set for that direct span, so a plain function or an
1408
+ * S3/S4 method (neither of which has a real visibility concept) checks for a
1409
+ * roxygen `@export` tag next (Phase 3), falling back to the leading-dot naming
1410
+ * convention only when there's no roxygen evidence to go on at all. `node` is
1411
+ * the exact node describeR matched — see `rRoxygenExported`'s doc comment for
1412
+ * why that's always the right one to check for a preceding comment block. */
1413
+ function rExported(name, ctx, node) {
1414
+ if (ctx.rR6Access !== null)
1415
+ return ctx.rR6Access !== "private";
1416
+ const roxygen = rRoxygenExported(node);
1417
+ if (roxygen !== null)
1418
+ return roxygen;
1419
+ return !name.startsWith(".");
1420
+ }
1421
+ /**
1422
+ * Roxygen `@export` detection (Phase 3): does `node` — a top-level definition
1423
+ * statement (a `binary_operator` assignment, a right-assigned
1424
+ * `function_definition`, or an S4 `setClass`/`setMethod` call) — have a
1425
+ * roxygen doc block immediately preceding it, and if so, is it tagged
1426
+ * `@export`?
1427
+ *
1428
+ * `comment` is a grammar EXTRA in this grammar (floats loosely between
1429
+ * sibling nodes rather than attaching to "the next statement" via a field),
1430
+ * so this walks backward through `previousNamedSibling` collecting a
1431
+ * contiguous run of `comment` nodes — the run ends at the first non-comment
1432
+ * sibling, or at the first comment that isn't itself a roxygen (`#'`) line,
1433
+ * either of which is roxygen's own "this block documents the next statement"
1434
+ * boundary.
1435
+ *
1436
+ * Returns:
1437
+ * - `true` — a roxygen block was found and it contains `@export`.
1438
+ * - `false` — a roxygen block was found but it does NOT contain `@export`.
1439
+ * This is deliberately a confident "not exported," not "unknown": roxygen
1440
+ * generates a package's NAMESPACE from exactly its `@export`-tagged items,
1441
+ * so a documented-but-untagged function is an explicit "internal, for
1442
+ * maintainers only" signal, not an absence of evidence.
1443
+ * - `null` — no roxygen block at all, so the caller should fall back to the
1444
+ * leading-dot naming convention instead of guessing.
1445
+ */
1446
+ function rRoxygenExported(node) {
1447
+ let sib = node.previousNamedSibling;
1448
+ let sawRoxygen = false;
1449
+ let exported = false;
1450
+ while (sib?.type === "comment") {
1451
+ const text = sib.text.trim();
1452
+ if (!text.startsWith("#'"))
1453
+ break; // an ordinary # comment ends the roxygen block
1454
+ sawRoxygen = true;
1455
+ if (/^#'\s*@export\b/.test(text))
1456
+ exported = true;
1457
+ sib = sib.previousNamedSibling;
1458
+ }
1459
+ return sawRoxygen ? exported : null;
1460
+ }
1461
+ /** Java definition shapes. Uniform in a way Go's are not: every declaration carries
1462
+ * a `name` field and (for types and most members) a `body`, so one mapped lookup
1463
+ * covers classes, interfaces, enums, records, methods, and constructors. Methods are
1464
+ * lexically nested in their type, so — unlike Go — they need no receiver qualification. */
1465
+ function describeJava(node, ctx) {
1466
+ const mapped = ctx.kinds[node.type];
1467
+ if (!mapped)
1468
+ return null;
1469
+ const name = node.childForFieldName("name")?.text;
1470
+ if (!name)
1471
+ return null;
1472
+ const body = node.childForFieldName("body");
1473
+ const desc = {
1474
+ name,
1475
+ kind: mapped,
1476
+ headerEnd: body ? body.startIndex : node.endIndex,
1477
+ hashNode: node,
1478
+ };
1479
+ // Only callables carry arity. A record declaration also has a `parameters` node,
1480
+ // but its components are not an overload set and must never be filtered against.
1481
+ if (node.type === "method_declaration" || node.type === "constructor_declaration") {
1482
+ const params = node.childForFieldName("parameters");
1483
+ if (params) {
1484
+ const declared = params.namedChildren.filter((c) => c.type === "formal_parameter" || c.type === "spread_parameter");
1485
+ desc.arity = declared.length;
1486
+ if (declared.some((c) => c.type === "spread_parameter"))
1487
+ desc.variadic = true;
1488
+ }
1489
+ }
1490
+ return desc;
1491
+ }
1492
+ /** Kotlin definition shapes. Unlike Java's, tree-sitter-kotlin exposes no `name`
1493
+ * or `body` fields: a definition's name is an unnamed `simple_identifier` (functions)
1494
+ * or `type_identifier` (types) child, and its body is a `class_body` / `function_body`
1495
+ * / `statements` child. `class_declaration` also folds classes, interfaces, and enum
1496
+ * classes into one node type — the kind is read off the declaration's own keywords. */
1497
+ function describeKotlin(node, ctx) {
1498
+ // The first direct `type_identifier` is the declared name (type parameters, primary
1499
+ // constructor parameters and delegation specifiers are all nested beneath it).
1500
+ const typeName = () => node.namedChildren.find((c) => c.type === "type_identifier")?.text ?? null;
1501
+ // The first direct `simple_identifier` is the function name (receiver type, params
1502
+ // and type parameters are all nested beneath other child nodes).
1503
+ const funcName = () => node.namedChildren.find((c) => c.type === "simple_identifier")?.text ?? null;
1504
+ // `class X : A, B()` heritage lives in `delegation_specifier` children; a nested
1505
+ // type parameter's identifier is one of the same node type, so only direct children
1506
+ // count as the declared name.
1507
+ const headEnd = (type) => {
1508
+ const body = node.namedChildren.find((c) => c.type === type);
1509
+ return body ? body.startIndex : node.endIndex;
1510
+ };
1511
+ if (node.type === "class_declaration") {
1512
+ const name = typeName();
1513
+ if (!name)
1514
+ return null;
1515
+ let kind = "class";
1516
+ if (node.namedChildren.some((c) => c.type === "enum_class_body"))
1517
+ kind = "enum";
1518
+ else if (node.children.some((c) => c.type === "interface"))
1519
+ kind = "interface";
1520
+ else {
1521
+ const mods = node.namedChildren.find((c) => c.type === "modifiers");
1522
+ // `annotation class` → the interface role Java's annotation_type_declaration plays.
1523
+ if (mods?.namedChildren.some((c) => c.type === "class_modifier" && c.text === "annotation"))
1524
+ kind = "interface";
1525
+ }
1526
+ const body = node.namedChildren.find((c) => c.type === "class_body" || c.type === "enum_class_body");
1527
+ return { name, kind, headerEnd: body ? body.startIndex : node.endIndex, hashNode: node };
1528
+ }
1529
+ if (node.type === "object_declaration") {
1530
+ const name = typeName();
1531
+ if (!name)
1532
+ return null;
1533
+ return { name, kind: "class", headerEnd: headEnd("class_body"), hashNode: node };
1534
+ }
1535
+ if (node.type === "function_declaration") {
1536
+ const name = funcName();
1537
+ if (!name)
1538
+ return null;
1539
+ const kind = KOTLIN_TYPE_KINDS.has(ctx.enclosingKind ?? "file") ? "method" : "function";
1540
+ return { name, kind, headerEnd: headEnd("function_body"), hashNode: node };
1541
+ }
1542
+ if (node.type === "secondary_constructor") {
1543
+ // Constructors carry no name of their own — they are the class's own, so scope the
1544
+ // node under the enclosing class the same way Java's constructor_declaration does.
1545
+ if (!ctx.enclosingClass)
1546
+ return null;
1547
+ return {
1548
+ name: ctx.enclosingClass,
1549
+ kind: "method",
1550
+ headerEnd: headEnd("statements"),
1551
+ hashNode: node,
1552
+ };
1553
+ }
1554
+ if (node.type === "type_alias") {
1555
+ const name = typeName();
1556
+ if (!name)
1557
+ return null;
1558
+ return { name, kind: "type", headerEnd: node.endIndex, hashNode: node };
1559
+ }
1560
+ if (node.type === "property_declaration") {
1561
+ // Top-level `val`/`var` only — a class property is a field, not a definition node
1562
+ // (no depth tier emits fields), so it must not become one.
1563
+ if (ctx.enclosingKind !== null)
1564
+ return null;
1565
+ const decl = node.namedChildren.find((c) => c.type === "variable_declaration");
1566
+ const name = decl?.namedChildren.find((c) => c.type === "simple_identifier")?.text;
1567
+ if (!name)
1568
+ return null;
1569
+ return { name, kind: "variable", headerEnd: node.endIndex, hashNode: node };
1570
+ }
1571
+ return null;
1572
+ }
1573
+ /** Swift definition shapes. Like Kotlin's, tree-sitter-swift exposes no `name` or
1574
+ * `body` fields: a definition's name is a direct `type_identifier` (types) or
1575
+ * `simple_identifier` (functions) child, and its body is a `class_body` /
1576
+ * `enum_class_body` / `protocol_body` / `function_body` child. One
1577
+ * `class_declaration` node type covers `class`, `struct`, `enum`, `actor` AND
1578
+ * `extension` — the declaration's own keyword token tells them apart. */
1579
+ function describeSwift(node, ctx) {
1580
+ // The first direct `type_identifier` is the declared name (generic parameters and
1581
+ // inheritance specifiers are all nested beneath other child nodes).
1582
+ const typeName = () => node.namedChildren.find((c) => c.type === "type_identifier")?.text ?? null;
1583
+ // The first direct `simple_identifier` is the function name (parameters and
1584
+ // generic parameters are all nested beneath other child nodes).
1585
+ const funcName = () => node.namedChildren.find((c) => c.type === "simple_identifier")?.text ?? null;
1586
+ const headEnd = (...types) => {
1587
+ const body = node.namedChildren.find((c) => types.includes(c.type));
1588
+ return body ? body.startIndex : node.endIndex;
1589
+ };
1590
+ if (node.type === "class_declaration") {
1591
+ const kw = node.children.find((c) => c.type === "class" ||
1592
+ c.type === "struct" ||
1593
+ c.type === "enum" ||
1594
+ c.type === "actor" ||
1595
+ c.type === "extension")?.type;
1596
+ let name;
1597
+ if (kw === "extension") {
1598
+ // `extension Point { … }` has no name of its own — the extended type's IS its
1599
+ // identity, so the node takes that name: members mint as `Point.method`,
1600
+ // `enclosingClass` becomes `Point`, and a member call on a Point receiver
1601
+ // resolves to them exactly as if they were declared on the type. A qualified
1602
+ // target (`extension Swift.Array`) reduces to its last component, matching
1603
+ // how the extended type is itself named in the graph.
1604
+ //
1605
+ // Its KIND is "module", not "class": the type usually already has a real
1606
+ // declaration, and a second same-named "class" node would make the name
1607
+ // AMBIGUOUS to resolveName — every `Point(...)` initializer call and every
1608
+ // `: Point` heritage target would then drop instead of resolving (resolve
1609
+ // never guesses between same-named candidates). "module" keeps the node out
1610
+ // of type-name resolution entirely while SWIFT_TYPE_KINDS still makes it
1611
+ // own its members; typed member calls are untouched either way, since they
1612
+ // go through the owner-qualified method index, not the type's own node.
1613
+ const ut = node.namedChildren.find((c) => c.type === "user_type");
1614
+ const ids = ut?.namedChildren.filter((c) => c.type === "type_identifier") ?? [];
1615
+ name = ids.length ? ids[ids.length - 1].text : null;
1616
+ }
1617
+ else {
1618
+ name = typeName();
1619
+ }
1620
+ if (!name)
1621
+ return null;
1622
+ // An actor is class-like (reference semantics, methods) and there is no
1623
+ // dedicated actor kind, so it takes "class".
1624
+ const kind = kw === "extension" ? "module" : kw === "struct" ? "struct" : kw === "enum" ? "enum" : "class";
1625
+ return { name, kind, headerEnd: headEnd("class_body", "enum_class_body"), hashNode: node };
1626
+ }
1627
+ if (node.type === "protocol_declaration") {
1628
+ const name = typeName();
1629
+ if (!name)
1630
+ return null;
1631
+ return { name, kind: "interface", headerEnd: headEnd("protocol_body"), hashNode: node };
1632
+ }
1633
+ // A protocol requirement (`protocol_function_declaration`) has no body and is
1634
+ // always a member; an ordinary `function_declaration` is a method exactly when
1635
+ // it is nested in a type (or an extension of one).
1636
+ if (node.type === "function_declaration" || node.type === "protocol_function_declaration") {
1637
+ const name = funcName();
1638
+ if (!name)
1639
+ return null;
1640
+ const kind = node.type === "protocol_function_declaration" ||
1641
+ SWIFT_TYPE_KINDS.has(ctx.enclosingKind ?? "file")
1642
+ ? "method"
1643
+ : "function";
1644
+ return {
1645
+ name,
1646
+ kind,
1647
+ headerEnd: headEnd("function_body"),
1648
+ hashNode: node,
1649
+ ...swiftArity(node),
1650
+ };
1651
+ }
1652
+ if (node.type === "init_declaration") {
1653
+ // Initializers carry no name of their own — they are the type's own, so scope
1654
+ // the node under the enclosing type the same way Java's constructor_declaration
1655
+ // does. (A protocol's `init` requirement lands here too, owned by the protocol.)
1656
+ if (!ctx.enclosingClass)
1657
+ return null;
1658
+ return {
1659
+ name: ctx.enclosingClass,
1660
+ kind: "method",
1661
+ headerEnd: headEnd("function_body"),
1662
+ hashNode: node,
1663
+ ...swiftArity(node),
1664
+ };
1665
+ }
1666
+ if (node.type === "typealias_declaration") {
1667
+ const name = typeName();
1668
+ if (!name)
1669
+ return null;
1670
+ return { name, kind: "type", headerEnd: node.endIndex, hashNode: node };
1671
+ }
1672
+ if (node.type === "property_declaration") {
1673
+ // Top-level `let`/`var` only — a stored/computed property inside a type is a
1674
+ // field, not a definition node (no depth tier emits fields), so it must not
1675
+ // become one. `deinit` and `subscript` are likewise skipped: neither is ever
1676
+ // the target of a resolvable call edge, and neither carries a usable name.
1677
+ if (ctx.enclosingKind !== null)
1678
+ return null;
1679
+ const name = node.namedChildren
1680
+ .find((c) => c.type === "pattern")
1681
+ ?.namedChildren.find((c) => c.type === "simple_identifier")?.text;
1682
+ if (!name)
1683
+ return null;
1684
+ return { name, kind: "variable", headerEnd: node.endIndex, hashNode: node };
1685
+ }
1686
+ return null;
1687
+ }
1688
+ /** Java visibility: `public` (or `protected`) on the declaration's own modifier list.
1689
+ * A package-private or private member is not part of the API surface. Read off the
1690
+ * `modifiers` child's tokens, ignoring annotations, which live in the same node. */
1691
+ function javaExported(node) {
1692
+ const mods = node.namedChildren.find((c) => c.type === "modifiers");
1693
+ if (!mods)
1694
+ return false;
1695
+ return mods.children.some((c) => c.type === "public" || c.type === "protected");
1696
+ }
1697
+ /** Kotlin visibility: exported by default (`public` is implicit); only an explicit
1698
+ * `internal` / `private` / `protected` visibility modifier hides a definition. */
1699
+ function kotlinExported(node) {
1700
+ const mods = node.namedChildren.find((c) => c.type === "modifiers");
1701
+ if (!mods)
1702
+ return true;
1703
+ const vis = mods.namedChildren.find((c) => c.type === "visibility_modifier");
1704
+ return !vis || vis.text === "public";
1705
+ }
1706
+ /** Declared parameter count for a Swift callable, for overload disambiguation
1707
+ * (the same role Java's `arity`/`argCount` pair plays). `parameter` nodes are
1708
+ * direct children of the declaration; a default value's `=` sits as a SIBLING
1709
+ * token after its parameter, and a variadic `...` sits inside its parameter.
1710
+ * `arity` is the REQUIRED minimum (parameters minus defaults) and `variadic`
1711
+ * marks any default or variadic parameter, so `narrowByArity`'s at-least
1712
+ * semantics keeps every overload a call of that shape could reach. */
1713
+ function swiftArity(node) {
1714
+ const params = node.children.filter((c) => c.type === "parameter");
1715
+ const defaults = node.children.filter((c) => c.type === "=").length;
1716
+ const hasVariadic = params.some((p) => p.children.some((c) => c.type === "..."));
1717
+ const arity = Math.max(0, params.length - defaults);
1718
+ return hasVariadic || defaults > 0 ? { arity, variadic: true } : { arity };
1719
+ }
1720
+ /** Argument count at a Swift call site: the `value_argument`s plus one for a
1721
+ * trailing closure (`run(x) { … }` calls a two-parameter function). */
1722
+ function swiftArgCount(node) {
1723
+ const suffix = node.namedChildren.find((c) => c.type === "call_suffix");
1724
+ if (!suffix)
1725
+ return undefined;
1726
+ const args = suffix.namedChildren
1727
+ .find((c) => c.type === "value_arguments")
1728
+ ?.namedChildren.filter((c) => c.type === "value_argument").length ?? 0;
1729
+ const trailing = suffix.namedChildren.some((c) => c.type === "lambda_literal") ? 1 : 0;
1730
+ return args + trailing;
1731
+ }
1732
+ /** Swift visibility: the default (`internal`) is module-wide, and a repo is
1733
+ * typically one module — so `public` / `open` / `package` / `internal` all count
1734
+ * as API surface, and only an explicit `private` / `fileprivate` hides a
1735
+ * definition. A setter-only restriction (`private(set)`) leaves the getter
1736
+ * visible, so it does not hide the symbol either. */
1737
+ function swiftExported(node) {
1738
+ const mods = node.namedChildren.find((c) => c.type === "modifiers");
1739
+ const vis = mods?.namedChildren.find((c) => c.type === "visibility_modifier");
1740
+ return !vis || (vis.text !== "private" && vis.text !== "fileprivate");
1741
+ }
1742
+ /** The superclass a Swift class declaration names: its FIRST inheritance
1743
+ * specifier — Swift's grammar requires the superclass to precede any protocol
1744
+ * in the `:` list, so when a superclass exists it is always this entry. A
1745
+ * class conforming only to protocols yields that protocol's name instead, but
1746
+ * `super` is illegal in such a class, so no call site ever consults it. Null
1747
+ * for a bare `class Foo` (and for an extension, whose declaration carries no
1748
+ * heritage for the original type — `super` inside one stays unresolved). */
1749
+ function swiftSuperClassName(node) {
1750
+ const spec = node.namedChildren.find((c) => c.type === "inheritance_specifier");
1751
+ const ids = spec?.namedChildren
1752
+ .find((c) => c.type === "user_type")
1753
+ ?.namedChildren.filter((c) => c.type === "type_identifier");
1754
+ return ids?.length ? ids[ids.length - 1].text : null;
1755
+ }
1756
+ /** The receiver's base type name for a Go method, unwrapping a pointer receiver
1757
+ * (`func (u *User) …` → `User`). Null if it can't be read. */
1758
+ function goReceiverType(node) {
1759
+ const recv = node.childForFieldName("receiver"); // parameter_list
1760
+ const param = recv?.namedChildren.find((c) => c.type === "parameter_declaration");
1761
+ let type = param?.childForFieldName("type");
1762
+ if (type?.type === "pointer_type")
1763
+ type = type.namedChildren.at(-1) ?? null;
1764
+ return type?.type === "type_identifier" ? type.text : null;
1765
+ }
1766
+ /** Go visibility: a symbol is exported iff its own name starts with an uppercase
1767
+ * letter. For a receiver-qualified method name, the own name is the part after the dot. */
1768
+ function goExported(name) {
1769
+ const own = name.includes(".") ? name.slice(name.lastIndexOf(".") + 1) : name;
1770
+ const first = own[0] ?? "";
1771
+ return first !== first.toLowerCase() && first === first.toUpperCase();
1772
+ }
1773
+ /** PHP visibility: a class member is "exported" unless it is `private`/`protected`.
1774
+ * Top-level functions/classes carry no visibility modifier and are always visible. */
1775
+ function phpExported(node) {
1776
+ const vis = node.namedChildren.find((c) => c.type === "visibility_modifier");
1777
+ return vis ? vis.text === "public" : true;
1778
+ }
1779
+ /** Name for a PHP closure / arrow-fn: the variable it's assigned to
1780
+ * (`$handler = fn(...)` -> `handler`, mirroring how TS names arrow-consts),
1781
+ * else the anonymous `{closure}` (deduplicated per file by mintId).
1782
+ *
1783
+ * The "is this the assignment's right-hand side" check compares tree-sitter node
1784
+ * `.id` (a stable per-tree node identity) rather than `===` on the wrapper
1785
+ * objects: the binding does not guarantee that two traversals to the same
1786
+ * underlying node hand back the same JS wrapper, so `right === node` can be false
1787
+ * even when they are the same node — producing a stray `{closure}` name that
1788
+ * makes `julius check` report the graph STALE against its own stored output. */
1789
+ function phpClosureName(node) {
1790
+ const parent = node.parent;
1791
+ if (parent?.type === "assignment_expression" && parent.childForFieldName("right")?.id === node.id) {
1792
+ const left = parent.childForFieldName("left");
1793
+ if (left?.type === "variable_name")
1794
+ return left.text.replace(/^\$/, "");
1795
+ }
1796
+ return "{closure}";
1797
+ }
1798
+ function heritageEdges(node, classId, ctx) {
1799
+ const edges = [];
1800
+ if (ctx.lang === "java") {
1801
+ // `superclass` holds `extends X`; `super_interfaces` holds `implements A, B`
1802
+ // (and, on an interface declaration, `extends A, B` — which tree-sitter-java
1803
+ // still spells `extends_interfaces`).
1804
+ const typeParams = javaTypeParameterNames(node);
1805
+ for (const child of node.namedChildren) {
1806
+ const relation = child.type === "superclass"
1807
+ ? "extends"
1808
+ : child.type === "super_interfaces" || child.type === "extends_interfaces"
1809
+ ? "implements"
1810
+ : null;
1811
+ if (!relation)
1812
+ continue;
1813
+ for (const entry of javaSupertypeEntries(child)) {
1814
+ const name = javaSupertypeName(entry);
1815
+ // Belt-and-braces. A type VARIABLE is never a supertype, and erasing the
1816
+ // arguments already removes every case measured on gson and spring-petclinic
1817
+ // (identical output with this filter removed) — Java cannot extend or implement
1818
+ // a type variable, so a surviving `T` would have to come from a shape neither
1819
+ // repo contains. Kept because a wrong supertype is not a cosmetic edge: it
1820
+ // feeds `classParents` and from there call resolution.
1821
+ if (!name || typeParams.has(name))
1822
+ continue;
1823
+ edges.push({ source: classId, relation, name, file: ctx.rel });
1824
+ }
1825
+ }
1826
+ return edges;
1827
+ }
1828
+ if (ctx.lang === "kotlin") {
1829
+ // The `:` clause is a list of `delegation_specifier`s — a superclass construction
1830
+ // (`class A : B()`), an interface, or `by` delegation. The first `type_identifier`
1831
+ // under each names the type; everything else (type args, delegation target) is not
1832
+ // the heritage target, so only the head type counts.
1833
+ for (const child of node.namedChildren) {
1834
+ if (child.type !== "delegation_specifier")
1835
+ continue;
1836
+ const t = child.namedChildren.find((c) => c.type === "user_type")?.namedChildren.find((c) => c.type === "type_identifier");
1837
+ if (t)
1838
+ edges.push({ source: classId, relation: "extends", name: t.text, file: ctx.rel });
1839
+ }
1840
+ return edges;
1841
+ }
1842
+ if (ctx.lang === "swift") {
1843
+ // `class A: B, C` — each `inheritance_specifier` (a direct child of the
1844
+ // declaration; protocols and extensions carry them too) wraps a `user_type`
1845
+ // whose LAST direct `type_identifier` is the bare supertype name: a
1846
+ // module-qualified `Foundation.NSObject` reduces to `NSObject`, and generic
1847
+ // arguments live in nested nodes so they never leak in. Swift cannot say
1848
+ // syntactically whether a specifier is the superclass or a protocol
1849
+ // conformance (that needs the target's kind), so every edge is `extends` —
1850
+ // the same collapse Kotlin's delegation specifiers make.
1851
+ for (const child of node.namedChildren) {
1852
+ if (child.type !== "inheritance_specifier")
1853
+ continue;
1854
+ const ids = child.namedChildren
1855
+ .find((c) => c.type === "user_type")
1856
+ ?.namedChildren.filter((c) => c.type === "type_identifier");
1857
+ const t = ids?.length ? ids[ids.length - 1] : undefined;
1858
+ if (t)
1859
+ edges.push({ source: classId, relation: "extends", name: t.text, file: ctx.rel });
1860
+ }
1861
+ return edges;
1862
+ }
1863
+ if (ctx.lang === "python") {
1864
+ const supers = node.childForFieldName("superclasses"); // argument_list
1865
+ for (const c of supers?.namedChildren ?? []) {
1866
+ if (c.type === "identifier") {
1867
+ edges.push({ source: classId, relation: "extends", name: c.text, file: ctx.rel });
1868
+ }
1869
+ }
1870
+ return edges;
1871
+ }
1872
+ if (ctx.lang === "r") {
1873
+ // `node` is whatever describeR matched: a binary_operator for R6
1874
+ // (`Foo <- R6::R6Class(...)`) or the call itself for S4 (`setClass(...)`
1875
+ // is a bare top-level statement, essentially never assigned).
1876
+ const call = node.type === "binary_operator" ? node.childForFieldName("rhs") : node;
1877
+ if (call?.type !== "call")
1878
+ return edges;
1879
+ const callee = rCalleeName(call);
1880
+ if (callee === "R6Class") {
1881
+ // `inherit = ParentClass` — a bare identifier (the parent's own
1882
+ // generator variable), not a string; R6 supports single inheritance only.
1883
+ const value = rNamedArg(call, "inherit");
1884
+ if (value?.type === "identifier") {
1885
+ edges.push({ source: classId, relation: "extends", name: value.text, file: ctx.rel });
1886
+ }
1887
+ }
1888
+ else if (callee === "setClass") {
1889
+ // `contains = "Base"` or `contains = c("Base1", "Base2")` — S4 supports
1890
+ // multiple inheritance.
1891
+ for (const name of rStringOrCVector(rNamedArg(call, "contains"))) {
1892
+ edges.push({ source: classId, relation: "extends", name, file: ctx.rel });
1893
+ }
1894
+ }
1895
+ return edges;
1896
+ }
1897
+ if (ctx.lang === "php") {
1898
+ // `class C extends B implements I, J` → base_clause (extends) +
1899
+ // class_interface_clause (implements); names may be namespace-qualified.
1900
+ for (const clause of node.namedChildren) {
1901
+ const relation = clause.type === "base_clause" ? "extends" : clause.type === "class_interface_clause" ? "implements" : null;
1902
+ if (!relation)
1903
+ continue;
1904
+ for (const t of clause.namedChildren) {
1905
+ if (t.type === "name" || t.type === "qualified_name") {
1906
+ edges.push({ source: classId, relation, name: t.text.replace(/^.*\\/, ""), file: ctx.rel });
1907
+ }
1908
+ }
1909
+ }
1910
+ return edges;
1911
+ }
1912
+ const heritage = node.namedChildren.find((c) => c.type === "class_heritage");
1913
+ for (const clause of heritage?.namedChildren ?? []) {
1914
+ const relation = clause.type === "implements_clause"
1915
+ ? "implements"
1916
+ : clause.type === "extends_clause"
1917
+ ? "extends"
1918
+ : null;
1919
+ if (!relation)
1920
+ continue;
1921
+ for (const t of clause.namedChildren) {
1922
+ if (t.type === "identifier" || t.type === "type_identifier") {
1923
+ edges.push({ source: classId, relation, name: t.text, file: ctx.rel });
1924
+ }
1925
+ }
1926
+ }
1927
+ return edges;
1928
+ }
1929
+ /**
1930
+ * The supertypes a heritage clause names, one node each — NOT every `type_identifier`
1931
+ * beneath it.
1932
+ *
1933
+ * `superclass` wraps a single type; `super_interfaces`/`extends_interfaces` wrap a
1934
+ * `type_list` of them. Descending blindly instead walked into `type_arguments`, so
1935
+ * `implements Comparable<Item>` reported `Item` as a supertype too.
1936
+ */
1937
+ function javaSupertypeEntries(clause) {
1938
+ const list = clause.namedChildren.find((c) => c.type === "type_list");
1939
+ return list ? [...list.namedChildren] : [...clause.namedChildren];
1940
+ }
1941
+ /**
1942
+ * What a supertype entry is CALLED, or null when this pass cannot say.
1943
+ *
1944
+ * Type arguments are erased, because they are not part of the supertype's identity:
1945
+ *
1946
+ * Base | Base<Item> -> Base
1947
+ *
1948
+ * A qualified name is kept WHOLE rather than reduced to its final segment:
1949
+ *
1950
+ * Outer.Inner | Outer.Inner<K> -> Outer.Inner
1951
+ *
1952
+ * Heritage keeps an unresolved base as the edge target by design ("usually an
1953
+ * external/imported type — keep the name"), so the full string is both truthful and
1954
+ * unable to false-match a node id, where a bare `Inner` could collide with an
1955
+ * unrelated in-repo type. That differs from construction (#103), which drops a
1956
+ * qualified name instead — construction has no keep-the-name contract to fall back on.
1957
+ */
1958
+ function javaSupertypeName(node) {
1959
+ if (!node)
1960
+ return null;
1961
+ if (node.type === "generic_type")
1962
+ return javaSupertypeName(node.namedChildren[0]);
1963
+ if (node.type === "scoped_type_identifier")
1964
+ return node.text;
1965
+ return node.type === "type_identifier" ? node.text : null;
1966
+ }
1967
+ /** The names a declaration binds as its own type parameters (`class C<T, U>` → T, U),
1968
+ * so they can never be mistaken for supertypes. */
1969
+ function javaTypeParameterNames(decl) {
1970
+ const params = decl.childForFieldName("type_parameters");
1971
+ if (!params)
1972
+ return new Set();
1973
+ const out = new Set();
1974
+ const visit = (n) => {
1975
+ if (n.type === "type_identifier")
1976
+ out.add(n.text);
1977
+ for (const c of n.namedChildren)
1978
+ visit(c);
1979
+ };
1980
+ visit(params);
1981
+ return out;
1982
+ }
1983
+ function calleeName(node, lang) {
1984
+ // Java first: `method_invocation` has NO `function` field (it splits the callee
1985
+ // into `object` + `name`), so the shared lookup below would return null for every
1986
+ // Java call site and the language would extract nodes with no call edges at all.
1987
+ if (lang === "java") {
1988
+ if (node.type === "object_creation_expression") {
1989
+ // `new Foo()` — the constructed type is the call target, named as the graph
1990
+ // names it.
1991
+ const name = javaConstructedTypeName(node.childForFieldName("type"));
1992
+ return name ? { name, viaMember: false } : null;
1993
+ }
1994
+ const nameNode = node.childForFieldName("name");
1995
+ if (!nameNode)
1996
+ return null;
1997
+ const obj = node.childForFieldName("object");
1998
+ // No `object` means an implicit-`this` call (`decorate(name)`), which in Java is a
1999
+ // method call, not a free function — Java has none. Reporting it as a plain call
2000
+ // would send it to the function-only resolver and drop it, losing the most common
2001
+ // intra-class edge there is. Spelling it as a `this` member call routes it through
2002
+ // owner-qualified resolution, which also walks the superclass chain and stays
2003
+ // conservative: an unmatched name (e.g. a static import) resolves to nothing.
2004
+ if (!obj)
2005
+ return { name: nameNode.text, viaMember: true, receiver: "this" };
2006
+ return { name: nameNode.text, viaMember: true, receiver: javaReceiver(obj) };
2007
+ }
2008
+ if (lang === "kotlin") {
2009
+ // `call_expression` = callee expression + `call_suffix`. A bare `foo()` names a
2010
+ // plain call; `obj.foo()` is a `navigation_expression` whose trailing
2011
+ // `navigation_suffix` holds the method name and whose object is the receiver.
2012
+ const target = node.namedChildren[0];
2013
+ if (target?.type === "simple_identifier")
2014
+ return { name: target.text, viaMember: false };
2015
+ if (target?.type === "navigation_expression") {
2016
+ const suffix = target.namedChildren.find((c) => c.type === "navigation_suffix");
2017
+ const name = suffix?.namedChildren.find((c) => c.type === "simple_identifier");
2018
+ const receiver = target.namedChildren[0];
2019
+ if (!name)
2020
+ return null;
2021
+ if (receiver?.type === "simple_identifier")
2022
+ return { name: name.text, viaMember: true, receiver: receiver.text };
2023
+ if (receiver?.type === "this_expression" || receiver?.type === "super_expression")
2024
+ return { name: name.text, viaMember: true, receiver: receiver.type === "this_expression" ? "this" : "super" };
2025
+ }
2026
+ return null;
2027
+ }
2028
+ if (lang === "swift") {
2029
+ // Same shape as Kotlin's: `call_expression` = callee expression + `call_suffix`.
2030
+ // A bare `foo()` names a plain call (this also covers `Animal()` initializer
2031
+ // calls, which have no distinguishing syntax); `obj.foo()` is a
2032
+ // `navigation_expression` whose trailing `navigation_suffix` holds the member
2033
+ // name and whose head is the receiver.
2034
+ const target = node.namedChildren[0];
2035
+ if (target?.type === "simple_identifier")
2036
+ return { name: target.text, viaMember: false };
2037
+ if (target?.type === "navigation_expression") {
2038
+ const suffix = target.namedChildren.find((c) => c.type === "navigation_suffix");
2039
+ const name = suffix?.namedChildren.find((c) => c.type === "simple_identifier");
2040
+ const receiver = target.namedChildren[0];
2041
+ if (!name)
2042
+ return null;
2043
+ if (receiver?.type === "simple_identifier")
2044
+ return { name: name.text, viaMember: true, receiver: receiver.text };
2045
+ if (receiver?.type === "self_expression" || receiver?.type === "super_expression")
2046
+ return {
2047
+ name: name.text,
2048
+ viaMember: true,
2049
+ receiver: receiver.type === "self_expression" ? "self" : "super",
2050
+ };
2051
+ if (receiver?.type === "navigation_expression") {
2052
+ // `self.repo.save()` — one hop off self is a field access and binds like
2053
+ // TS's `this.x`. Deeper chains and call-result receivers carry no
2054
+ // confident local clue, so those fall through with no receiver.
2055
+ const head = receiver.namedChildren[0];
2056
+ const field = receiver.namedChildren
2057
+ .find((c) => c.type === "navigation_suffix")
2058
+ ?.namedChildren.find((c) => c.type === "simple_identifier");
2059
+ if (head?.type === "self_expression" && field)
2060
+ return { name: name.text, viaMember: true, receiver: `self.${field.text}` };
2061
+ }
2062
+ // Still a member call even with an unknowable receiver (a chained call, a
2063
+ // literal, a subscript): recvType stays unset and resolve drops it rather
2064
+ // than guessing — same contract as Java's and TS's unknown receivers.
2065
+ return { name: name.text, viaMember: true };
2066
+ }
2067
+ return null;
2068
+ }
2069
+ if (lang === "php")
2070
+ return phpCallee(node);
2071
+ const fn = node.childForFieldName("function");
2072
+ if (!fn)
2073
+ return null;
2074
+ if (fn.type === "identifier")
2075
+ return { name: fn.text, viaMember: false };
2076
+ if (lang === "python" && fn.type === "attribute") {
2077
+ const a = fn.childForFieldName("attribute") ?? fn.namedChildren.at(-1);
2078
+ return a ? { name: a.text, viaMember: true, receiver: pyReceiver(fn) } : null;
2079
+ }
2080
+ if (lang === "go" && fn.type === "selector_expression") {
2081
+ // `pkg.Fn()` / `recv.Method()` — the called name is the trailing field.
2082
+ const p = fn.childForFieldName("field") ?? fn.namedChildren.at(-1);
2083
+ const operand = fn.childForFieldName("operand");
2084
+ const receiver = operand?.type === "identifier" ? operand.text : undefined;
2085
+ return p ? { name: p.text, viaMember: true, receiver } : null;
2086
+ }
2087
+ if ((lang === "typescript" || lang === "tsx") && fn.type === "member_expression") {
2088
+ const p = fn.childForFieldName("property") ?? fn.namedChildren.at(-1);
2089
+ return p ? { name: p.text, viaMember: true, receiver: tsReceiver(fn) } : null;
2090
+ }
2091
+ if (lang === "r" && (fn.type === "extract_operator" || fn.type === "namespace_operator")) {
2092
+ const rhs = fn.childForFieldName("rhs");
2093
+ if (rhs?.type !== "identifier")
2094
+ return null;
2095
+ if (fn.type === "extract_operator") {
2096
+ const lhs = fn.childForFieldName("lhs");
2097
+ if (lhs?.type === "identifier" && (lhs.text === "self" || lhs.text === "private")) {
2098
+ // R6 (Phase 2): `self$method()` / `private$method()` — resolves directly to
2099
+ // the enclosing class via ctx.enclosingClass, same mechanism (and same
2100
+ // magic receiver string) as Python/TS's self/cls/this — see
2101
+ // resolveRecvType, which already special-cases "self" generically.
2102
+ return { name: rhs.text, viaMember: true, receiver: "self" };
2103
+ }
2104
+ if (lhs?.type === "identifier" && lhs.text === "super") {
2105
+ // R6 (Phase 3): `super$method()` — R6's inheritance-dispatch keyword,
2106
+ // resolves directly to the PARENT class via ctx.rSuperClass (NOT
2107
+ // ctx.enclosingClass — that would wrongly find the current class's own
2108
+ // same-named override instead of climbing to the parent).
2109
+ return { name: rhs.text, viaMember: true, receiver: "super" };
2110
+ }
2111
+ // Any other `obj$method()` (Phase 4): still a PLAIN name match, not a
2112
+ // typed member call — there's no general field-type-binding table for
2113
+ // R6 composition (`private$other_obj$method()`), and a real codebase's
2114
+ // dominant field-assignment shape (constructor-parameter pass-through,
2115
+ // `do.call(class_var$new, ...)` dynamic dispatch) turned out to defeat
2116
+ // the simple "field <- SomeClass$new()" pattern every other language's
2117
+ // binding table relies on anyway — see plan_r_language_support.md's
2118
+ // Phase 2 "known gaps" and the follow-up investigation against a real
2119
+ // R6-heavy corpus. What DOES help: bare-name resolution must be allowed
2120
+ // to match a "method" node here, not just "function" — R6 methods are
2121
+ // always kind "method", so without `kinds` below, EVERY untyped `$`
2122
+ // call would be unconditionally unresolvable rather than just
2123
+ // occasionally ambiguous (resolve.ts already drops a genuinely
2124
+ // ambiguous bare-name match rather than guessing, so this only adds
2125
+ // resolutions for uniquely-named methods, never a wrong-class guess).
2126
+ return { name: rhs.text, viaMember: false, kinds: ["function", "method"] };
2127
+ }
2128
+ // `pkg::fun()` (qualified call) — always a real function/exported symbol,
2129
+ // never an R6 method (those are only ever reached via `$` on an instance),
2130
+ // so no need to widen the match kinds here.
2131
+ return { name: rhs.text, viaMember: false };
2132
+ }
2133
+ return null;
2134
+ }
2135
+ /** The number of arguments at a Java call site (`method_invocation` or
2136
+ * `object_creation_expression`), read off the `arguments` list. Undefined when the
2137
+ * list is absent, which keeps resolution at its previous name-only behavior rather
2138
+ * than filtering on a count we never established. */
2139
+ function javaArgCount(node) {
2140
+ const args = node.childForFieldName("arguments");
2141
+ return args ? args.namedChildren.length : undefined;
2142
+ }
2143
+ /**
2144
+ * The name a `new` CONSTRUCTS, as the graph names it — or null when this pass cannot
2145
+ * say, in which case the construction resolves to nothing.
2146
+ *
2147
+ * Erasing type arguments is the only transformation here, because it is the only one
2148
+ * that provably does not change which type is being named:
2149
+ *
2150
+ * Box -> Box
2151
+ * Box<String> -> Box (the node is `Box`; the arguments are not part of it)
2152
+ * Box<> -> Box
2153
+ *
2154
+ * A QUALIFIED name is deliberately dropped rather than reduced to its final segment:
2155
+ *
2156
+ * java.io.File -> null (not the repo's own `File`)
2157
+ * Beta.Builder -> null (not `Alpha.Builder` in the same file)
2158
+ *
2159
+ * Collapsing those was the first attempt at this fix, and it traded lost edges for
2160
+ * WRONG ones — `new java.io.File(…)` resolved to an unrelated in-repo `File`, and a
2161
+ * nested `Beta.Builder` bound to a sibling `Alpha.Builder` at `extracted` confidence,
2162
+ * because the same-file tiebreak takes the first candidate. Dropping keeps this pass
2163
+ * on the resolver's own rule: resolve precisely, or not at all.
2164
+ *
2165
+ * Deliberately NOT shared with bindings.ts's `javaTypeName`. That one answers "what
2166
+ * type does this variable HOLD", where reducing `java.util.List` to `List` is a local
2167
+ * heuristic with different stakes; this one answers "what type is being constructed",
2168
+ * and the two questions do not have the same safe answer. Supporting qualified
2169
+ * construction properly needs an import-aware type index, not a longer helper.
2170
+ */
2171
+ function javaConstructedTypeName(node) {
2172
+ if (!node)
2173
+ return null;
2174
+ if (node.type === "generic_type")
2175
+ return javaConstructedTypeName(node.namedChildren[0]);
2176
+ return node.type === "type_identifier" ? node.text : null;
2177
+ }
2178
+ /** A Java call's receiver text: a bare identifier (`repo.save()`), `this`, or
2179
+ * `this.x` for a field access (`this.repo.save()`). A chained call or a qualified
2180
+ * static reference yields none — there is no confident local clue to bind. */
2181
+ function javaReceiver(obj) {
2182
+ if (!obj)
2183
+ return undefined;
2184
+ if (obj.type === "identifier")
2185
+ return obj.text;
2186
+ if (obj.type === "this")
2187
+ return "this";
2188
+ if (obj.type === "field_access") {
2189
+ const inner = obj.childForFieldName("object");
2190
+ const field = obj.childForFieldName("field");
2191
+ if (inner?.type === "this" && field)
2192
+ return `this.${field.text}`;
2193
+ }
2194
+ return undefined;
2195
+ }
2196
+ /** py `attribute` node's receiver text: bare identifier, or `self.x` for a
2197
+ * chained `self.x.y()`. Anything else (e.g. a chained call `f().g()`) → none. */
2198
+ function pyReceiver(fn) {
2199
+ const obj = fn.childForFieldName("object");
2200
+ if (obj?.type === "identifier")
2201
+ return obj.text;
2202
+ if (obj?.type === "attribute") {
2203
+ const innerObj = obj.childForFieldName("object");
2204
+ const innerAttr = obj.childForFieldName("attribute");
2205
+ if (innerObj?.type === "identifier" && innerObj.text === "self" && innerAttr)
2206
+ return `self.${innerAttr.text}`;
2207
+ }
2208
+ return undefined;
2209
+ }
2210
+ /**
2211
+ * PHP call shapes: `foo()` (function_call_expression), `$obj->m()` /
2212
+ * `$obj?->m()` (member/nullsafe_member_call_expression), and `Cls::m()`
2213
+ * (scoped_call_expression). The called name is the trailing `name`; the
2214
+ * receiver, when locally knowable (`$this`, `self`/`static`/`parent`), feeds
2215
+ * receiver-typed resolution the same way Python's `self` and Go's receiver do.
2216
+ */
2217
+ function phpCallee(node) {
2218
+ if (node.type === "function_call_expression") {
2219
+ const fn = node.childForFieldName("function");
2220
+ const name = fn ? phpName(fn) : null;
2221
+ return name ? { name, viaMember: false } : null;
2222
+ }
2223
+ const nameNode = node.childForFieldName("name");
2224
+ if (!nameNode)
2225
+ return null;
2226
+ if (node.type === "scoped_call_expression") {
2227
+ return { name: nameNode.text, viaMember: true, receiver: phpScopeReceiver(node.childForFieldName("scope")) };
2228
+ }
2229
+ // member_call_expression / nullsafe_member_call_expression
2230
+ return { name: nameNode.text, viaMember: true, receiver: phpObjReceiver(node.childForFieldName("object")) };
2231
+ }
2232
+ /** A PHP callee identifier: bare `name`, or the trailing segment of a
2233
+ * `qualified_name` (`\App\helpers\slug` → `slug`). Dynamic calls (`$fn()`) → null. */
2234
+ function phpName(node) {
2235
+ if (node.type === "name")
2236
+ return node.text;
2237
+ if (node.type === "qualified_name")
2238
+ return node.text.replace(/^.*\\/, "") || null;
2239
+ return null;
2240
+ }
2241
+ /** `$obj->m()` receiver: `$this` normalizes to `this` (→ enclosing class); any
2242
+ * other variable is returned verbatim for a bindings lookup. */
2243
+ function phpObjReceiver(obj) {
2244
+ if (obj?.type !== "variable_name")
2245
+ return undefined;
2246
+ return obj.text === "$this" ? "this" : obj.text;
2247
+ }
2248
+ /** `Cls::m()` receiver: `self`/`static`/`parent` normalize to `self` (→ enclosing
2249
+ * class); an explicit class name is the trailing segment of its qualified path. */
2250
+ function phpScopeReceiver(scope) {
2251
+ if (!scope)
2252
+ return undefined;
2253
+ const text = scope.text;
2254
+ if (scope.type === "relative_scope" || text === "self" || text === "static" || text === "parent")
2255
+ return "self";
2256
+ if (scope.type === "name")
2257
+ return text;
2258
+ if (scope.type === "qualified_name")
2259
+ return text.replace(/^.*\\/, "");
2260
+ return undefined;
2261
+ }
2262
+ /** ts `member_expression` node's receiver text: `this`, `this.x`, or a bare identifier. */
2263
+ function tsReceiver(fn) {
2264
+ const obj = fn.childForFieldName("object");
2265
+ if (obj?.type === "this")
2266
+ return "this";
2267
+ if (obj?.type === "identifier")
2268
+ return obj.text;
2269
+ if (obj?.type === "member_expression") {
2270
+ const innerObj = obj.childForFieldName("object");
2271
+ const innerProp = obj.childForFieldName("property");
2272
+ if (innerObj?.type === "this" && innerProp)
2273
+ return `this.${innerProp.text}`;
2274
+ }
2275
+ return undefined;
2276
+ }
2277
+ /** R has no import statement at the grammar level — `library(x)`, `require(x)`,
2278
+ * and `source("f.R")` are ordinary `call` nodes, indistinguishable from any other
2279
+ * call except by their callee name. This is call-SITE pattern matching, a first
2280
+ * for this function's normal node-type switch — every other language's import
2281
+ * shape is a dedicated grammar construct. */
2282
+ const R_IMPORT_CALLS = new Set(["library", "require", "source"]);
2283
+ function isImport(node, lang) {
2284
+ // Go: match the per-import leaf, so single (`import "fmt"`) and grouped
2285
+ // (`import ( … )`) forms each yield one edge as the walk recurses into the list.
2286
+ if (lang === "go")
2287
+ return node.type === "import_spec";
2288
+ if (lang === "r") {
2289
+ if (node.type !== "call")
2290
+ return false;
2291
+ const fn = node.childForFieldName("function");
2292
+ return fn?.type === "identifier" && R_IMPORT_CALLS.has(fn.text);
2293
+ }
2294
+ if (lang === "java")
2295
+ return node.type === "import_declaration";
2296
+ if (lang === "kotlin")
2297
+ return node.type === "import_header";
2298
+ if (lang === "swift")
2299
+ return node.type === "import_declaration";
2300
+ // PHP: one edge per imported symbol — the clause leaf inside a (possibly
2301
+ // grouped) `use A\B, C\D;` / `use A\{B, C};` declaration.
2302
+ if (lang === "php")
2303
+ return node.type === "namespace_use_clause";
2304
+ return node.type === "import_statement" || node.type === "import_from_statement";
2305
+ }
2306
+ function importSpecifier(node, lang) {
2307
+ if (lang === "php") {
2308
+ // namespace_use_clause → its `qualified_name`/`name`, e.g. `App\Models\Animal`.
2309
+ const q = node.namedChildren.find((c) => c.type === "qualified_name" || c.type === "name");
2310
+ return q ? q.text.replace(/^\\/, "") : null;
2311
+ }
2312
+ if (lang === "python") {
2313
+ const m = node.childForFieldName("module_name") ??
2314
+ node.namedChildren.find((c) => c.type === "dotted_name" || c.type === "relative_import");
2315
+ return m?.text ?? null;
2316
+ }
2317
+ if (lang === "go") {
2318
+ // import_spec's `path` is an interpreted_string_literal, e.g. `"mymod/pkg/util"`.
2319
+ const path = node.childForFieldName("path") ?? node.namedChildren.at(-1);
2320
+ return path ? path.text.replace(/^["`]|["`]$/g, "") : null;
2321
+ }
2322
+ if (lang === "r") {
2323
+ // library(pkg) / library("pkg") / require(pkg) / source("f.R") — the target is
2324
+ // always the first (and normally only) positional argument, bare symbol or string.
2325
+ const value = rCallArgs(node)[0]?.childForFieldName("value") ?? null;
2326
+ if (value?.type === "identifier")
2327
+ return value.text;
2328
+ return rStringContent(value);
2329
+ }
2330
+ if (lang === "java") {
2331
+ // `import a.b.C;` / `import static a.b.C.d;` / `import a.b.*;` — the fully
2332
+ // qualified name is the scoped_identifier; a wildcard `*` is a separate token
2333
+ // and is dropped, leaving the package as the import target.
2334
+ const id = node.namedChildren.find((c) => c.type === "scoped_identifier" || c.type === "identifier");
2335
+ return id?.text ?? null;
2336
+ }
2337
+ if (lang === "kotlin") {
2338
+ // `import com.example.Foo` — the dotted path is the `identifier` child. A
2339
+ // wildcard (`import a.b.*`) and an `as` alias are separate children, so the
2340
+ // identifier text is already the module path (wildcards dropped, like Java).
2341
+ return node.namedChildren.find((c) => c.type === "identifier")?.text ?? null;
2342
+ }
2343
+ if (lang === "swift") {
2344
+ // `import UIKit` / `import struct Foundation.Date` — the dotted path is the
2345
+ // `identifier` child (an import-kind keyword like `struct` is a separate
2346
+ // token). Swift imports name MODULES, not files, so the specifier resolves
2347
+ // to a repo file only when a same-named module target exists; external
2348
+ // frameworks stay as unresolved (but truthful) import intents.
2349
+ return node.namedChildren.find((c) => c.type === "identifier")?.text ?? null;
2350
+ }
2351
+ const str = node.namedChildren.find((c) => c.type === "string");
2352
+ if (!str)
2353
+ return null;
2354
+ const frag = str.namedChildren.find((c) => c.type === "string_fragment");
2355
+ return frag?.text ?? str.text.replace(/^['"]|['"]$/g, "");
2356
+ }
2357
+ /** Signature = the definition header, whitespace-collapsed, trailing punctuation stripped. */
2358
+ function clean(raw) {
2359
+ const sig = raw
2360
+ .replace(/\s+/g, " ")
2361
+ .trim()
2362
+ .replace(/(=>|[{:=])\s*$/, "")
2363
+ .trim();
2364
+ return sig || null;
2365
+ }
2366
+ /** TS: a definition is exported if any ancestor is an `export` statement. */
2367
+ function tsExported(node) {
2368
+ let p = node.parent;
2369
+ while (p) {
2370
+ if (p.type === "export_statement")
2371
+ return true;
2372
+ p = p.parent;
2373
+ }
2374
+ return false;
2375
+ }
2376
+ //# sourceMappingURL=extract.js.map