@kkvcrobatz107/codegraph 0.9.6-pkm.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (501) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +595 -0
  3. package/dist/bin/codegraph.d.ts +25 -0
  4. package/dist/bin/codegraph.d.ts.map +1 -0
  5. package/dist/bin/codegraph.js +1563 -0
  6. package/dist/bin/codegraph.js.map +1 -0
  7. package/dist/bin/node-version-check.d.ts +37 -0
  8. package/dist/bin/node-version-check.d.ts.map +1 -0
  9. package/dist/bin/node-version-check.js +79 -0
  10. package/dist/bin/node-version-check.js.map +1 -0
  11. package/dist/bin/uninstall.d.ts +14 -0
  12. package/dist/bin/uninstall.d.ts.map +1 -0
  13. package/dist/bin/uninstall.js +36 -0
  14. package/dist/bin/uninstall.js.map +1 -0
  15. package/dist/context/formatter.d.ts +30 -0
  16. package/dist/context/formatter.d.ts.map +1 -0
  17. package/dist/context/formatter.js +244 -0
  18. package/dist/context/formatter.js.map +1 -0
  19. package/dist/context/index.d.ts +110 -0
  20. package/dist/context/index.d.ts.map +1 -0
  21. package/dist/context/index.js +1169 -0
  22. package/dist/context/index.js.map +1 -0
  23. package/dist/db/index.d.ts +101 -0
  24. package/dist/db/index.d.ts.map +1 -0
  25. package/dist/db/index.js +251 -0
  26. package/dist/db/index.js.map +1 -0
  27. package/dist/db/migrations.d.ts +44 -0
  28. package/dist/db/migrations.d.ts.map +1 -0
  29. package/dist/db/migrations.js +131 -0
  30. package/dist/db/migrations.js.map +1 -0
  31. package/dist/db/queries.d.ts +281 -0
  32. package/dist/db/queries.d.ts.map +1 -0
  33. package/dist/db/queries.js +1300 -0
  34. package/dist/db/queries.js.map +1 -0
  35. package/dist/db/schema.sql +151 -0
  36. package/dist/db/sqlite-adapter.d.ts +46 -0
  37. package/dist/db/sqlite-adapter.d.ts.map +1 -0
  38. package/dist/db/sqlite-adapter.js +114 -0
  39. package/dist/db/sqlite-adapter.js.map +1 -0
  40. package/dist/directory.d.ts +57 -0
  41. package/dist/directory.d.ts.map +1 -0
  42. package/dist/directory.js +264 -0
  43. package/dist/directory.js.map +1 -0
  44. package/dist/errors.d.ts +136 -0
  45. package/dist/errors.d.ts.map +1 -0
  46. package/dist/errors.js +219 -0
  47. package/dist/errors.js.map +1 -0
  48. package/dist/extraction/dfm-extractor.d.ts +31 -0
  49. package/dist/extraction/dfm-extractor.d.ts.map +1 -0
  50. package/dist/extraction/dfm-extractor.js +151 -0
  51. package/dist/extraction/dfm-extractor.js.map +1 -0
  52. package/dist/extraction/grammars.d.ts +90 -0
  53. package/dist/extraction/grammars.d.ts.map +1 -0
  54. package/dist/extraction/grammars.js +407 -0
  55. package/dist/extraction/grammars.js.map +1 -0
  56. package/dist/extraction/index.d.ts +138 -0
  57. package/dist/extraction/index.d.ts.map +1 -0
  58. package/dist/extraction/index.js +1378 -0
  59. package/dist/extraction/index.js.map +1 -0
  60. package/dist/extraction/languages/c-cpp.d.ts +4 -0
  61. package/dist/extraction/languages/c-cpp.d.ts.map +1 -0
  62. package/dist/extraction/languages/c-cpp.js +171 -0
  63. package/dist/extraction/languages/c-cpp.js.map +1 -0
  64. package/dist/extraction/languages/csharp.d.ts +3 -0
  65. package/dist/extraction/languages/csharp.d.ts.map +1 -0
  66. package/dist/extraction/languages/csharp.js +73 -0
  67. package/dist/extraction/languages/csharp.js.map +1 -0
  68. package/dist/extraction/languages/dart.d.ts +3 -0
  69. package/dist/extraction/languages/dart.d.ts.map +1 -0
  70. package/dist/extraction/languages/dart.js +192 -0
  71. package/dist/extraction/languages/dart.js.map +1 -0
  72. package/dist/extraction/languages/go.d.ts +3 -0
  73. package/dist/extraction/languages/go.d.ts.map +1 -0
  74. package/dist/extraction/languages/go.js +70 -0
  75. package/dist/extraction/languages/go.js.map +1 -0
  76. package/dist/extraction/languages/index.d.ts +10 -0
  77. package/dist/extraction/languages/index.d.ts.map +1 -0
  78. package/dist/extraction/languages/index.js +51 -0
  79. package/dist/extraction/languages/index.js.map +1 -0
  80. package/dist/extraction/languages/java.d.ts +3 -0
  81. package/dist/extraction/languages/java.d.ts.map +1 -0
  82. package/dist/extraction/languages/java.js +70 -0
  83. package/dist/extraction/languages/java.js.map +1 -0
  84. package/dist/extraction/languages/javascript.d.ts +3 -0
  85. package/dist/extraction/languages/javascript.d.ts.map +1 -0
  86. package/dist/extraction/languages/javascript.js +90 -0
  87. package/dist/extraction/languages/javascript.js.map +1 -0
  88. package/dist/extraction/languages/kotlin.d.ts +3 -0
  89. package/dist/extraction/languages/kotlin.d.ts.map +1 -0
  90. package/dist/extraction/languages/kotlin.js +259 -0
  91. package/dist/extraction/languages/kotlin.js.map +1 -0
  92. package/dist/extraction/languages/lua.d.ts +3 -0
  93. package/dist/extraction/languages/lua.d.ts.map +1 -0
  94. package/dist/extraction/languages/lua.js +150 -0
  95. package/dist/extraction/languages/lua.js.map +1 -0
  96. package/dist/extraction/languages/luau.d.ts +3 -0
  97. package/dist/extraction/languages/luau.d.ts.map +1 -0
  98. package/dist/extraction/languages/luau.js +37 -0
  99. package/dist/extraction/languages/luau.js.map +1 -0
  100. package/dist/extraction/languages/objc.d.ts +3 -0
  101. package/dist/extraction/languages/objc.d.ts.map +1 -0
  102. package/dist/extraction/languages/objc.js +133 -0
  103. package/dist/extraction/languages/objc.js.map +1 -0
  104. package/dist/extraction/languages/pascal.d.ts +3 -0
  105. package/dist/extraction/languages/pascal.d.ts.map +1 -0
  106. package/dist/extraction/languages/pascal.js +66 -0
  107. package/dist/extraction/languages/pascal.js.map +1 -0
  108. package/dist/extraction/languages/php.d.ts +3 -0
  109. package/dist/extraction/languages/php.d.ts.map +1 -0
  110. package/dist/extraction/languages/php.js +107 -0
  111. package/dist/extraction/languages/php.js.map +1 -0
  112. package/dist/extraction/languages/python.d.ts +3 -0
  113. package/dist/extraction/languages/python.d.ts.map +1 -0
  114. package/dist/extraction/languages/python.js +56 -0
  115. package/dist/extraction/languages/python.js.map +1 -0
  116. package/dist/extraction/languages/ruby.d.ts +3 -0
  117. package/dist/extraction/languages/ruby.d.ts.map +1 -0
  118. package/dist/extraction/languages/ruby.js +114 -0
  119. package/dist/extraction/languages/ruby.js.map +1 -0
  120. package/dist/extraction/languages/rust.d.ts +3 -0
  121. package/dist/extraction/languages/rust.d.ts.map +1 -0
  122. package/dist/extraction/languages/rust.js +109 -0
  123. package/dist/extraction/languages/rust.js.map +1 -0
  124. package/dist/extraction/languages/scala.d.ts +3 -0
  125. package/dist/extraction/languages/scala.d.ts.map +1 -0
  126. package/dist/extraction/languages/scala.js +139 -0
  127. package/dist/extraction/languages/scala.js.map +1 -0
  128. package/dist/extraction/languages/swift.d.ts +3 -0
  129. package/dist/extraction/languages/swift.d.ts.map +1 -0
  130. package/dist/extraction/languages/swift.js +91 -0
  131. package/dist/extraction/languages/swift.js.map +1 -0
  132. package/dist/extraction/languages/typescript.d.ts +3 -0
  133. package/dist/extraction/languages/typescript.d.ts.map +1 -0
  134. package/dist/extraction/languages/typescript.js +129 -0
  135. package/dist/extraction/languages/typescript.js.map +1 -0
  136. package/dist/extraction/liquid-extractor.d.ts +52 -0
  137. package/dist/extraction/liquid-extractor.d.ts.map +1 -0
  138. package/dist/extraction/liquid-extractor.js +313 -0
  139. package/dist/extraction/liquid-extractor.js.map +1 -0
  140. package/dist/extraction/mybatis-extractor.d.ts +48 -0
  141. package/dist/extraction/mybatis-extractor.d.ts.map +1 -0
  142. package/dist/extraction/mybatis-extractor.js +198 -0
  143. package/dist/extraction/mybatis-extractor.js.map +1 -0
  144. package/dist/extraction/parse-worker.d.ts +8 -0
  145. package/dist/extraction/parse-worker.d.ts.map +1 -0
  146. package/dist/extraction/parse-worker.js +94 -0
  147. package/dist/extraction/parse-worker.js.map +1 -0
  148. package/dist/extraction/svelte-extractor.d.ts +56 -0
  149. package/dist/extraction/svelte-extractor.d.ts.map +1 -0
  150. package/dist/extraction/svelte-extractor.js +272 -0
  151. package/dist/extraction/svelte-extractor.js.map +1 -0
  152. package/dist/extraction/tree-sitter-helpers.d.ts +28 -0
  153. package/dist/extraction/tree-sitter-helpers.d.ts.map +1 -0
  154. package/dist/extraction/tree-sitter-helpers.js +103 -0
  155. package/dist/extraction/tree-sitter-helpers.js.map +1 -0
  156. package/dist/extraction/tree-sitter-types.d.ts +193 -0
  157. package/dist/extraction/tree-sitter-types.d.ts.map +1 -0
  158. package/dist/extraction/tree-sitter-types.js +10 -0
  159. package/dist/extraction/tree-sitter-types.js.map +1 -0
  160. package/dist/extraction/tree-sitter.d.ts +291 -0
  161. package/dist/extraction/tree-sitter.d.ts.map +1 -0
  162. package/dist/extraction/tree-sitter.js +2961 -0
  163. package/dist/extraction/tree-sitter.js.map +1 -0
  164. package/dist/extraction/vue-extractor.d.ts +36 -0
  165. package/dist/extraction/vue-extractor.d.ts.map +1 -0
  166. package/dist/extraction/vue-extractor.js +163 -0
  167. package/dist/extraction/vue-extractor.js.map +1 -0
  168. package/dist/extraction/wasm/tree-sitter-lua.wasm +0 -0
  169. package/dist/extraction/wasm/tree-sitter-luau.wasm +0 -0
  170. package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  171. package/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
  172. package/dist/extraction/wasm-runtime-flags.d.ts +38 -0
  173. package/dist/extraction/wasm-runtime-flags.d.ts.map +1 -0
  174. package/dist/extraction/wasm-runtime-flags.js +105 -0
  175. package/dist/extraction/wasm-runtime-flags.js.map +1 -0
  176. package/dist/graph/index.d.ts +8 -0
  177. package/dist/graph/index.d.ts.map +1 -0
  178. package/dist/graph/index.js +13 -0
  179. package/dist/graph/index.js.map +1 -0
  180. package/dist/graph/queries.d.ts +106 -0
  181. package/dist/graph/queries.d.ts.map +1 -0
  182. package/dist/graph/queries.js +366 -0
  183. package/dist/graph/queries.js.map +1 -0
  184. package/dist/graph/traversal.d.ts +127 -0
  185. package/dist/graph/traversal.d.ts.map +1 -0
  186. package/dist/graph/traversal.js +528 -0
  187. package/dist/graph/traversal.js.map +1 -0
  188. package/dist/index.d.ts +460 -0
  189. package/dist/index.d.ts.map +1 -0
  190. package/dist/index.js +863 -0
  191. package/dist/index.js.map +1 -0
  192. package/dist/installer/claude-md-template.d.ts +14 -0
  193. package/dist/installer/claude-md-template.d.ts.map +1 -0
  194. package/dist/installer/claude-md-template.js +21 -0
  195. package/dist/installer/claude-md-template.js.map +1 -0
  196. package/dist/installer/config-writer.d.ts +29 -0
  197. package/dist/installer/config-writer.d.ts.map +1 -0
  198. package/dist/installer/config-writer.js +111 -0
  199. package/dist/installer/config-writer.js.map +1 -0
  200. package/dist/installer/index.d.ts +117 -0
  201. package/dist/installer/index.d.ts.map +1 -0
  202. package/dist/installer/index.js +528 -0
  203. package/dist/installer/index.js.map +1 -0
  204. package/dist/installer/instructions-template.d.ts +28 -0
  205. package/dist/installer/instructions-template.d.ts.map +1 -0
  206. package/dist/installer/instructions-template.js +65 -0
  207. package/dist/installer/instructions-template.js.map +1 -0
  208. package/dist/installer/targets/antigravity.d.ts +57 -0
  209. package/dist/installer/targets/antigravity.d.ts.map +1 -0
  210. package/dist/installer/targets/antigravity.js +307 -0
  211. package/dist/installer/targets/antigravity.js.map +1 -0
  212. package/dist/installer/targets/claude.d.ts +47 -0
  213. package/dist/installer/targets/claude.d.ts.map +1 -0
  214. package/dist/installer/targets/claude.js +401 -0
  215. package/dist/installer/targets/claude.js.map +1 -0
  216. package/dist/installer/targets/codex.d.ts +18 -0
  217. package/dist/installer/targets/codex.d.ts.map +1 -0
  218. package/dist/installer/targets/codex.js +185 -0
  219. package/dist/installer/targets/codex.js.map +1 -0
  220. package/dist/installer/targets/cursor.d.ts +35 -0
  221. package/dist/installer/targets/cursor.d.ts.map +1 -0
  222. package/dist/installer/targets/cursor.js +283 -0
  223. package/dist/installer/targets/cursor.js.map +1 -0
  224. package/dist/installer/targets/gemini.d.ts +26 -0
  225. package/dist/installer/targets/gemini.d.ts.map +1 -0
  226. package/dist/installer/targets/gemini.js +165 -0
  227. package/dist/installer/targets/gemini.js.map +1 -0
  228. package/dist/installer/targets/hermes.d.ts +18 -0
  229. package/dist/installer/targets/hermes.d.ts.map +1 -0
  230. package/dist/installer/targets/hermes.js +359 -0
  231. package/dist/installer/targets/hermes.js.map +1 -0
  232. package/dist/installer/targets/kiro.d.ts +27 -0
  233. package/dist/installer/targets/kiro.d.ts.map +1 -0
  234. package/dist/installer/targets/kiro.js +196 -0
  235. package/dist/installer/targets/kiro.js.map +1 -0
  236. package/dist/installer/targets/opencode.d.ts +30 -0
  237. package/dist/installer/targets/opencode.d.ts.map +1 -0
  238. package/dist/installer/targets/opencode.js +235 -0
  239. package/dist/installer/targets/opencode.js.map +1 -0
  240. package/dist/installer/targets/registry.d.ts +35 -0
  241. package/dist/installer/targets/registry.d.ts.map +1 -0
  242. package/dist/installer/targets/registry.js +91 -0
  243. package/dist/installer/targets/registry.js.map +1 -0
  244. package/dist/installer/targets/shared.d.ts +77 -0
  245. package/dist/installer/targets/shared.d.ts.map +1 -0
  246. package/dist/installer/targets/shared.js +246 -0
  247. package/dist/installer/targets/shared.js.map +1 -0
  248. package/dist/installer/targets/toml.d.ts +52 -0
  249. package/dist/installer/targets/toml.d.ts.map +1 -0
  250. package/dist/installer/targets/toml.js +147 -0
  251. package/dist/installer/targets/toml.js.map +1 -0
  252. package/dist/installer/targets/types.d.ts +116 -0
  253. package/dist/installer/targets/types.d.ts.map +1 -0
  254. package/dist/installer/targets/types.js +16 -0
  255. package/dist/installer/targets/types.js.map +1 -0
  256. package/dist/mcp/daemon-paths.d.ts +46 -0
  257. package/dist/mcp/daemon-paths.d.ts.map +1 -0
  258. package/dist/mcp/daemon-paths.js +125 -0
  259. package/dist/mcp/daemon-paths.js.map +1 -0
  260. package/dist/mcp/daemon.d.ts +161 -0
  261. package/dist/mcp/daemon.d.ts.map +1 -0
  262. package/dist/mcp/daemon.js +403 -0
  263. package/dist/mcp/daemon.js.map +1 -0
  264. package/dist/mcp/engine.d.ts +100 -0
  265. package/dist/mcp/engine.d.ts.map +1 -0
  266. package/dist/mcp/engine.js +291 -0
  267. package/dist/mcp/engine.js.map +1 -0
  268. package/dist/mcp/index.d.ts +109 -0
  269. package/dist/mcp/index.d.ts.map +1 -0
  270. package/dist/mcp/index.js +470 -0
  271. package/dist/mcp/index.js.map +1 -0
  272. package/dist/mcp/proxy.d.ts +46 -0
  273. package/dist/mcp/proxy.d.ts.map +1 -0
  274. package/dist/mcp/proxy.js +276 -0
  275. package/dist/mcp/proxy.js.map +1 -0
  276. package/dist/mcp/server-instructions.d.ts +19 -0
  277. package/dist/mcp/server-instructions.d.ts.map +1 -0
  278. package/dist/mcp/server-instructions.js +73 -0
  279. package/dist/mcp/server-instructions.js.map +1 -0
  280. package/dist/mcp/session.d.ts +67 -0
  281. package/dist/mcp/session.d.ts.map +1 -0
  282. package/dist/mcp/session.js +276 -0
  283. package/dist/mcp/session.js.map +1 -0
  284. package/dist/mcp/tools.d.ts +385 -0
  285. package/dist/mcp/tools.d.ts.map +1 -0
  286. package/dist/mcp/tools.js +2545 -0
  287. package/dist/mcp/tools.js.map +1 -0
  288. package/dist/mcp/transport.d.ts +188 -0
  289. package/dist/mcp/transport.d.ts.map +1 -0
  290. package/dist/mcp/transport.js +343 -0
  291. package/dist/mcp/transport.js.map +1 -0
  292. package/dist/mcp/version.d.ts +19 -0
  293. package/dist/mcp/version.d.ts.map +1 -0
  294. package/dist/mcp/version.js +71 -0
  295. package/dist/mcp/version.js.map +1 -0
  296. package/dist/resolution/callback-synthesizer.d.ts +10 -0
  297. package/dist/resolution/callback-synthesizer.d.ts.map +1 -0
  298. package/dist/resolution/callback-synthesizer.js +924 -0
  299. package/dist/resolution/callback-synthesizer.js.map +1 -0
  300. package/dist/resolution/frameworks/cargo-workspace.d.ts +18 -0
  301. package/dist/resolution/frameworks/cargo-workspace.d.ts.map +1 -0
  302. package/dist/resolution/frameworks/cargo-workspace.js +225 -0
  303. package/dist/resolution/frameworks/cargo-workspace.js.map +1 -0
  304. package/dist/resolution/frameworks/csharp.d.ts +8 -0
  305. package/dist/resolution/frameworks/csharp.d.ts.map +1 -0
  306. package/dist/resolution/frameworks/csharp.js +241 -0
  307. package/dist/resolution/frameworks/csharp.js.map +1 -0
  308. package/dist/resolution/frameworks/drupal.d.ts +51 -0
  309. package/dist/resolution/frameworks/drupal.d.ts.map +1 -0
  310. package/dist/resolution/frameworks/drupal.js +367 -0
  311. package/dist/resolution/frameworks/drupal.js.map +1 -0
  312. package/dist/resolution/frameworks/expo-modules.d.ts +3 -0
  313. package/dist/resolution/frameworks/expo-modules.d.ts.map +1 -0
  314. package/dist/resolution/frameworks/expo-modules.js +143 -0
  315. package/dist/resolution/frameworks/expo-modules.js.map +1 -0
  316. package/dist/resolution/frameworks/express.d.ts +8 -0
  317. package/dist/resolution/frameworks/express.d.ts.map +1 -0
  318. package/dist/resolution/frameworks/express.js +308 -0
  319. package/dist/resolution/frameworks/express.js.map +1 -0
  320. package/dist/resolution/frameworks/fabric.d.ts +3 -0
  321. package/dist/resolution/frameworks/fabric.d.ts.map +1 -0
  322. package/dist/resolution/frameworks/fabric.js +354 -0
  323. package/dist/resolution/frameworks/fabric.js.map +1 -0
  324. package/dist/resolution/frameworks/go.d.ts +8 -0
  325. package/dist/resolution/frameworks/go.d.ts.map +1 -0
  326. package/dist/resolution/frameworks/go.js +161 -0
  327. package/dist/resolution/frameworks/go.js.map +1 -0
  328. package/dist/resolution/frameworks/index.d.ts +48 -0
  329. package/dist/resolution/frameworks/index.d.ts.map +1 -0
  330. package/dist/resolution/frameworks/index.js +161 -0
  331. package/dist/resolution/frameworks/index.js.map +1 -0
  332. package/dist/resolution/frameworks/java.d.ts +8 -0
  333. package/dist/resolution/frameworks/java.d.ts.map +1 -0
  334. package/dist/resolution/frameworks/java.js +504 -0
  335. package/dist/resolution/frameworks/java.js.map +1 -0
  336. package/dist/resolution/frameworks/laravel.d.ts +13 -0
  337. package/dist/resolution/frameworks/laravel.d.ts.map +1 -0
  338. package/dist/resolution/frameworks/laravel.js +257 -0
  339. package/dist/resolution/frameworks/laravel.js.map +1 -0
  340. package/dist/resolution/frameworks/nestjs.d.ts +26 -0
  341. package/dist/resolution/frameworks/nestjs.d.ts.map +1 -0
  342. package/dist/resolution/frameworks/nestjs.js +698 -0
  343. package/dist/resolution/frameworks/nestjs.js.map +1 -0
  344. package/dist/resolution/frameworks/play.d.ts +19 -0
  345. package/dist/resolution/frameworks/play.d.ts.map +1 -0
  346. package/dist/resolution/frameworks/play.js +111 -0
  347. package/dist/resolution/frameworks/play.js.map +1 -0
  348. package/dist/resolution/frameworks/python.d.ts +10 -0
  349. package/dist/resolution/frameworks/python.d.ts.map +1 -0
  350. package/dist/resolution/frameworks/python.js +396 -0
  351. package/dist/resolution/frameworks/python.js.map +1 -0
  352. package/dist/resolution/frameworks/react-native.d.ts +3 -0
  353. package/dist/resolution/frameworks/react-native.d.ts.map +1 -0
  354. package/dist/resolution/frameworks/react-native.js +360 -0
  355. package/dist/resolution/frameworks/react-native.js.map +1 -0
  356. package/dist/resolution/frameworks/react.d.ts +8 -0
  357. package/dist/resolution/frameworks/react.d.ts.map +1 -0
  358. package/dist/resolution/frameworks/react.js +365 -0
  359. package/dist/resolution/frameworks/react.js.map +1 -0
  360. package/dist/resolution/frameworks/ruby.d.ts +8 -0
  361. package/dist/resolution/frameworks/ruby.d.ts.map +1 -0
  362. package/dist/resolution/frameworks/ruby.js +302 -0
  363. package/dist/resolution/frameworks/ruby.js.map +1 -0
  364. package/dist/resolution/frameworks/rust.d.ts +8 -0
  365. package/dist/resolution/frameworks/rust.d.ts.map +1 -0
  366. package/dist/resolution/frameworks/rust.js +304 -0
  367. package/dist/resolution/frameworks/rust.js.map +1 -0
  368. package/dist/resolution/frameworks/svelte.d.ts +9 -0
  369. package/dist/resolution/frameworks/svelte.d.ts.map +1 -0
  370. package/dist/resolution/frameworks/svelte.js +249 -0
  371. package/dist/resolution/frameworks/svelte.js.map +1 -0
  372. package/dist/resolution/frameworks/swift-objc.d.ts +37 -0
  373. package/dist/resolution/frameworks/swift-objc.d.ts.map +1 -0
  374. package/dist/resolution/frameworks/swift-objc.js +252 -0
  375. package/dist/resolution/frameworks/swift-objc.js.map +1 -0
  376. package/dist/resolution/frameworks/swift.d.ts +10 -0
  377. package/dist/resolution/frameworks/swift.d.ts.map +1 -0
  378. package/dist/resolution/frameworks/swift.js +400 -0
  379. package/dist/resolution/frameworks/swift.js.map +1 -0
  380. package/dist/resolution/frameworks/vue.d.ts +9 -0
  381. package/dist/resolution/frameworks/vue.d.ts.map +1 -0
  382. package/dist/resolution/frameworks/vue.js +306 -0
  383. package/dist/resolution/frameworks/vue.js.map +1 -0
  384. package/dist/resolution/go-module.d.ts +26 -0
  385. package/dist/resolution/go-module.d.ts.map +1 -0
  386. package/dist/resolution/go-module.js +78 -0
  387. package/dist/resolution/go-module.js.map +1 -0
  388. package/dist/resolution/import-resolver.d.ts +68 -0
  389. package/dist/resolution/import-resolver.d.ts.map +1 -0
  390. package/dist/resolution/import-resolver.js +1231 -0
  391. package/dist/resolution/import-resolver.js.map +1 -0
  392. package/dist/resolution/index.d.ts +116 -0
  393. package/dist/resolution/index.d.ts.map +1 -0
  394. package/dist/resolution/index.js +878 -0
  395. package/dist/resolution/index.js.map +1 -0
  396. package/dist/resolution/lru-cache.d.ts +24 -0
  397. package/dist/resolution/lru-cache.d.ts.map +1 -0
  398. package/dist/resolution/lru-cache.js +62 -0
  399. package/dist/resolution/lru-cache.js.map +1 -0
  400. package/dist/resolution/name-matcher.d.ts +32 -0
  401. package/dist/resolution/name-matcher.d.ts.map +1 -0
  402. package/dist/resolution/name-matcher.js +596 -0
  403. package/dist/resolution/name-matcher.js.map +1 -0
  404. package/dist/resolution/path-aliases.d.ts +68 -0
  405. package/dist/resolution/path-aliases.d.ts.map +1 -0
  406. package/dist/resolution/path-aliases.js +238 -0
  407. package/dist/resolution/path-aliases.js.map +1 -0
  408. package/dist/resolution/strip-comments.d.ts +27 -0
  409. package/dist/resolution/strip-comments.d.ts.map +1 -0
  410. package/dist/resolution/strip-comments.js +441 -0
  411. package/dist/resolution/strip-comments.js.map +1 -0
  412. package/dist/resolution/swift-objc-bridge.d.ts +134 -0
  413. package/dist/resolution/swift-objc-bridge.d.ts.map +1 -0
  414. package/dist/resolution/swift-objc-bridge.js +256 -0
  415. package/dist/resolution/swift-objc-bridge.js.map +1 -0
  416. package/dist/resolution/types.d.ts +209 -0
  417. package/dist/resolution/types.d.ts.map +1 -0
  418. package/dist/resolution/types.js +8 -0
  419. package/dist/resolution/types.js.map +1 -0
  420. package/dist/search/query-parser.d.ts +57 -0
  421. package/dist/search/query-parser.d.ts.map +1 -0
  422. package/dist/search/query-parser.js +177 -0
  423. package/dist/search/query-parser.js.map +1 -0
  424. package/dist/search/query-utils.d.ts +53 -0
  425. package/dist/search/query-utils.d.ts.map +1 -0
  426. package/dist/search/query-utils.js +350 -0
  427. package/dist/search/query-utils.js.map +1 -0
  428. package/dist/sync/git-hooks.d.ts +45 -0
  429. package/dist/sync/git-hooks.d.ts.map +1 -0
  430. package/dist/sync/git-hooks.js +223 -0
  431. package/dist/sync/git-hooks.js.map +1 -0
  432. package/dist/sync/index.d.ts +19 -0
  433. package/dist/sync/index.d.ts.map +1 -0
  434. package/dist/sync/index.js +35 -0
  435. package/dist/sync/index.js.map +1 -0
  436. package/dist/sync/watch-policy.d.ts +48 -0
  437. package/dist/sync/watch-policy.d.ts.map +1 -0
  438. package/dist/sync/watch-policy.js +124 -0
  439. package/dist/sync/watch-policy.js.map +1 -0
  440. package/dist/sync/watcher.d.ts +191 -0
  441. package/dist/sync/watcher.d.ts.map +1 -0
  442. package/dist/sync/watcher.js +398 -0
  443. package/dist/sync/watcher.js.map +1 -0
  444. package/dist/sync/worktree.d.ts +54 -0
  445. package/dist/sync/worktree.d.ts.map +1 -0
  446. package/dist/sync/worktree.js +136 -0
  447. package/dist/sync/worktree.js.map +1 -0
  448. package/dist/types.d.ts +369 -0
  449. package/dist/types.d.ts.map +1 -0
  450. package/dist/types.js +78 -0
  451. package/dist/types.js.map +1 -0
  452. package/dist/ui/glyphs.d.ts +42 -0
  453. package/dist/ui/glyphs.d.ts.map +1 -0
  454. package/dist/ui/glyphs.js +78 -0
  455. package/dist/ui/glyphs.js.map +1 -0
  456. package/dist/ui/shimmer-progress.d.ts +11 -0
  457. package/dist/ui/shimmer-progress.d.ts.map +1 -0
  458. package/dist/ui/shimmer-progress.js +90 -0
  459. package/dist/ui/shimmer-progress.js.map +1 -0
  460. package/dist/ui/shimmer-worker.d.ts +2 -0
  461. package/dist/ui/shimmer-worker.d.ts.map +1 -0
  462. package/dist/ui/shimmer-worker.js +118 -0
  463. package/dist/ui/shimmer-worker.js.map +1 -0
  464. package/dist/ui/types.d.ts +17 -0
  465. package/dist/ui/types.d.ts.map +1 -0
  466. package/dist/ui/types.js +3 -0
  467. package/dist/ui/types.js.map +1 -0
  468. package/dist/utils.d.ts +205 -0
  469. package/dist/utils.d.ts.map +1 -0
  470. package/dist/utils.js +549 -0
  471. package/dist/utils.js.map +1 -0
  472. package/package.json +59 -0
  473. package/scripts/add-lang/bench.sh +60 -0
  474. package/scripts/add-lang/check-grammar.mjs +75 -0
  475. package/scripts/add-lang/dump-ast.mjs +103 -0
  476. package/scripts/add-lang/verify-extraction.mjs +70 -0
  477. package/scripts/agent-eval/arms-F.sh +21 -0
  478. package/scripts/agent-eval/arms-matrix.sh +37 -0
  479. package/scripts/agent-eval/audit.sh +68 -0
  480. package/scripts/agent-eval/bench-readme.sh +28 -0
  481. package/scripts/agent-eval/block-read-hook.sh +19 -0
  482. package/scripts/agent-eval/hook-settings.json +15 -0
  483. package/scripts/agent-eval/itrun.sh +107 -0
  484. package/scripts/agent-eval/parse-arms.mjs +116 -0
  485. package/scripts/agent-eval/parse-bench-readme.mjs +67 -0
  486. package/scripts/agent-eval/parse-run.mjs +45 -0
  487. package/scripts/agent-eval/parse-session.mjs +93 -0
  488. package/scripts/agent-eval/probe-context.mjs +21 -0
  489. package/scripts/agent-eval/probe-explore.mjs +40 -0
  490. package/scripts/agent-eval/probe-node.mjs +20 -0
  491. package/scripts/agent-eval/probe-trace.mjs +20 -0
  492. package/scripts/agent-eval/run-agent.sh +34 -0
  493. package/scripts/agent-eval/run-all.sh +67 -0
  494. package/scripts/agent-eval/run-arms.sh +56 -0
  495. package/scripts/agent-eval/seq-matrix.mjs +137 -0
  496. package/scripts/build-bundle.sh +118 -0
  497. package/scripts/extract-release-notes.mjs +130 -0
  498. package/scripts/local-install.sh +41 -0
  499. package/scripts/npm-shim.js +246 -0
  500. package/scripts/pack-npm.sh +95 -0
  501. package/scripts/prepare-release.mjs +270 -0
@@ -0,0 +1,1169 @@
1
+ "use strict";
2
+ /**
3
+ * Context Builder
4
+ *
5
+ * Builds rich context for tasks by combining FTS search with graph traversal.
6
+ * Outputs structured context ready to inject into Claude.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.formatContextAsJson = exports.formatContextAsMarkdown = exports.ContextBuilder = void 0;
43
+ exports.createContextBuilder = createContextBuilder;
44
+ const fs = __importStar(require("fs"));
45
+ const path = __importStar(require("path"));
46
+ const formatter_1 = require("./formatter");
47
+ const errors_1 = require("../errors");
48
+ const utils_1 = require("../utils");
49
+ const query_utils_1 = require("../search/query-utils");
50
+ /**
51
+ * Extract likely symbol names from a natural language query
52
+ *
53
+ * Identifies potential code symbols using patterns:
54
+ * - CamelCase: UserService, signInWithGoogle
55
+ * - snake_case: user_service, sign_in
56
+ * - SCREAMING_SNAKE: MAX_RETRIES
57
+ * - dot.notation: app.isPackaged (extracts both sides)
58
+ * - Single words that look like identifiers (no spaces, not common English words)
59
+ *
60
+ * @param query - Natural language query
61
+ * @returns Array of potential symbol names
62
+ */
63
+ function extractSymbolsFromQuery(query) {
64
+ const symbols = new Set();
65
+ // Extract CamelCase identifiers (2+ chars, starts with letter)
66
+ const camelCasePattern = /\b([A-Z][a-z]+(?:[A-Z][a-z]*)*|[a-z]+(?:[A-Z][a-z]*)+)\b/g;
67
+ let match;
68
+ while ((match = camelCasePattern.exec(query)) !== null) {
69
+ if (match[1] && match[1].length >= 2) {
70
+ symbols.add(match[1]);
71
+ }
72
+ }
73
+ // Extract snake_case identifiers
74
+ const snakeCasePattern = /\b([a-z][a-z0-9]*(?:_[a-z0-9]+)+)\b/gi;
75
+ while ((match = snakeCasePattern.exec(query)) !== null) {
76
+ if (match[1] && match[1].length >= 3) {
77
+ symbols.add(match[1]);
78
+ }
79
+ }
80
+ // Extract SCREAMING_SNAKE_CASE
81
+ const screamingPattern = /\b([A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+)\b/g;
82
+ while ((match = screamingPattern.exec(query)) !== null) {
83
+ if (match[1]) {
84
+ symbols.add(match[1]);
85
+ }
86
+ }
87
+ // Extract ALL_CAPS acronyms (2+ chars, e.g., REST, HTTP, LRU, API)
88
+ const acronymPattern = /\b([A-Z]{2,})\b/g;
89
+ while ((match = acronymPattern.exec(query)) !== null) {
90
+ if (match[1]) {
91
+ symbols.add(match[1]);
92
+ }
93
+ }
94
+ // Extract dot.notation and split into parts (e.g., "app.isPackaged" -> ["app", "isPackaged"])
95
+ const dotPattern = /\b([a-zA-Z][a-zA-Z0-9]*(?:\.[a-zA-Z][a-zA-Z0-9]*)+)\b/g;
96
+ while ((match = dotPattern.exec(query)) !== null) {
97
+ if (match[1]) {
98
+ // Add both the full path and individual parts
99
+ symbols.add(match[1]);
100
+ const parts = match[1].split('.');
101
+ for (const part of parts) {
102
+ if (part.length >= 2) {
103
+ symbols.add(part);
104
+ }
105
+ }
106
+ }
107
+ }
108
+ // Extract plain lowercase identifiers (3+ chars, not already matched)
109
+ // Catches symbol names like "undo", "redo", "history", "render", "parse"
110
+ const lowercasePattern = /\b([a-z][a-z0-9]{2,})\b/g;
111
+ while ((match = lowercasePattern.exec(query)) !== null) {
112
+ if (match[1]) {
113
+ symbols.add(match[1]);
114
+ }
115
+ }
116
+ // Filter out common English words that aren't likely symbol names
117
+ const commonWords = new Set([
118
+ 'the', 'and', 'for', 'with', 'from', 'this', 'that', 'have', 'been',
119
+ 'will', 'would', 'could', 'should', 'does', 'done', 'make', 'made',
120
+ 'use', 'used', 'using', 'work', 'works', 'find', 'found', 'show',
121
+ 'call', 'called', 'calling', 'get', 'set', 'add', 'all', 'any',
122
+ 'how', 'what', 'when', 'where', 'which', 'who', 'why',
123
+ 'not', 'but', 'are', 'was', 'were', 'has', 'had', 'its',
124
+ 'can', 'did', 'may', 'also', 'into', 'than', 'then', 'them',
125
+ 'each', 'other', 'some', 'such', 'only', 'same', 'about',
126
+ 'after', 'before', 'between', 'through', 'during', 'without',
127
+ 'again', 'further', 'once', 'here', 'there', 'both', 'just',
128
+ 'more', 'most', 'very', 'being', 'having', 'doing',
129
+ 'system', 'need', 'needs', 'want', 'wants', 'like', 'look',
130
+ 'change', 'changes', 'changed', 'changing',
131
+ // Common English nouns/verbs that match thousands of unrelated code symbols
132
+ 'layer', 'handle', 'handles', 'handling', 'incoming', 'outgoing',
133
+ 'data', 'flow', 'flows', 'level', 'levels', 'request', 'requests',
134
+ 'response', 'responses', 'implement', 'implements', 'implementation',
135
+ 'interface', 'interfaces', 'class', 'classes', 'method', 'methods',
136
+ 'trigger', 'triggers', 'affected', 'affect', 'affects',
137
+ 'else', 'code', 'failing', 'failed', 'silently', 'decide', 'decides',
138
+ 'return', 'returns', 'returned', 'take', 'takes', 'taken',
139
+ 'check', 'checks', 'checked', 'create', 'creates', 'created',
140
+ 'read', 'reads', 'write', 'writes', 'written',
141
+ 'start', 'starts', 'stop', 'stops', 'run', 'runs', 'running',
142
+ ]);
143
+ return Array.from(symbols).filter(s => !commonWords.has(s.toLowerCase()));
144
+ }
145
+ /**
146
+ * Default options for context building
147
+ *
148
+ * Tuned for minimal context usage while still providing useful results:
149
+ * - Fewer nodes and code blocks by default
150
+ * - Smaller code block size limit
151
+ * - Shallower traversal
152
+ */
153
+ const DEFAULT_BUILD_OPTIONS = {
154
+ maxNodes: 20, // Reduced from 50 - most tasks don't need 50 symbols
155
+ maxCodeBlocks: 5, // Reduced from 10 - only show most relevant code
156
+ maxCodeBlockSize: 1500, // Reduced from 2000
157
+ includeCode: true,
158
+ format: 'markdown',
159
+ searchLimit: 3, // Reduced from 5 - fewer entry points
160
+ traversalDepth: 1, // Reduced from 2 - shallower graph expansion
161
+ minScore: 0.3,
162
+ };
163
+ /**
164
+ * Node kinds that provide high information value in context results.
165
+ * Imports/exports are excluded because they have near-zero information density -
166
+ * they tell you something exists, not how it works.
167
+ */
168
+ const HIGH_VALUE_NODE_KINDS = [
169
+ 'function', 'method', 'class', 'interface', 'type_alias', 'struct', 'trait',
170
+ 'component', 'route', 'variable', 'constant', 'enum', 'module', 'namespace',
171
+ ];
172
+ /**
173
+ * Default options for finding relevant context
174
+ */
175
+ const DEFAULT_FIND_OPTIONS = {
176
+ searchLimit: 3, // Reduced from 5
177
+ traversalDepth: 1, // Reduced from 2
178
+ maxNodes: 20, // Reduced from 50
179
+ minScore: 0.3,
180
+ edgeKinds: [],
181
+ nodeKinds: HIGH_VALUE_NODE_KINDS, // Filter out imports/exports by default
182
+ };
183
+ /**
184
+ * Context Builder
185
+ *
186
+ * Coordinates semantic search and graph traversal to build
187
+ * comprehensive context for tasks.
188
+ */
189
+ class ContextBuilder {
190
+ projectRoot;
191
+ queries;
192
+ traverser;
193
+ constructor(projectRoot, queries, traverser) {
194
+ this.projectRoot = projectRoot;
195
+ this.queries = queries;
196
+ this.traverser = traverser;
197
+ }
198
+ /**
199
+ * Build context for a task
200
+ *
201
+ * Pipeline:
202
+ * 1. Parse task input (string or {title, description})
203
+ * 2. Run semantic search to find entry points
204
+ * 3. Expand graph around entry points
205
+ * 4. Extract code blocks for key nodes
206
+ * 5. Format output for Claude
207
+ *
208
+ * @param input - Task description or object with title/description
209
+ * @param options - Build options
210
+ * @returns TaskContext (structured) or formatted string
211
+ */
212
+ async buildContext(input, options = {}) {
213
+ const opts = { ...DEFAULT_BUILD_OPTIONS, ...options };
214
+ // Parse input
215
+ const query = typeof input === 'string' ? input : `${input.title}${input.description ? `: ${input.description}` : ''}`;
216
+ // Find relevant context (semantic search + graph expansion)
217
+ const subgraph = await this.findRelevantContext(query, {
218
+ searchLimit: opts.searchLimit,
219
+ traversalDepth: opts.traversalDepth,
220
+ maxNodes: opts.maxNodes,
221
+ minScore: opts.minScore,
222
+ });
223
+ // Get entry points (nodes from semantic search)
224
+ const entryPoints = this.getEntryPoints(subgraph);
225
+ // Extract code blocks for key nodes
226
+ const codeBlocks = opts.includeCode
227
+ ? await this.extractCodeBlocks(subgraph, opts.maxCodeBlocks, opts.maxCodeBlockSize)
228
+ : [];
229
+ // Get related files
230
+ const relatedFiles = this.getRelatedFiles(subgraph);
231
+ // Generate summary
232
+ const summary = this.generateSummary(query, subgraph, entryPoints);
233
+ // Calculate stats
234
+ const stats = {
235
+ nodeCount: subgraph.nodes.size,
236
+ edgeCount: subgraph.edges.length,
237
+ fileCount: relatedFiles.length,
238
+ codeBlockCount: codeBlocks.length,
239
+ totalCodeSize: codeBlocks.reduce((sum, block) => sum + block.content.length, 0),
240
+ };
241
+ const context = {
242
+ query,
243
+ subgraph,
244
+ entryPoints,
245
+ codeBlocks,
246
+ relatedFiles,
247
+ summary,
248
+ stats,
249
+ };
250
+ // Return formatted output or raw context
251
+ if (opts.format === 'markdown') {
252
+ return (0, formatter_1.formatContextAsMarkdown)(context) + this.buildCallPathsSection(subgraph);
253
+ }
254
+ else if (opts.format === 'json') {
255
+ return (0, formatter_1.formatContextAsJson)(context);
256
+ }
257
+ return context;
258
+ }
259
+ /**
260
+ * Surface short call-paths among the symbols this context already found,
261
+ * derived in-memory from the subgraph's `calls` edges (no extra queries).
262
+ *
263
+ * This bakes the value of path-finding INTO the always-loaded `context` tool.
264
+ * Agents reliably read context's output but do NOT discover/adopt a standalone
265
+ * trace tool (in deferred-MCP harnesses they only ToolSearch-select tools they
266
+ * already know). Delivering the flow here means "how does X reach Y" is
267
+ * answered without the agent needing to find, load, or choose a new tool.
268
+ * Chains stop where the static call graph ends (e.g. dynamic dispatch) — that
269
+ * truncation is honest, and the agent can codegraph_node the last hop to bridge.
270
+ */
271
+ buildCallPathsSection(subgraph) {
272
+ const adj = new Map();
273
+ for (const e of subgraph.edges) {
274
+ if (e.kind !== 'calls')
275
+ continue;
276
+ if (!subgraph.nodes.has(e.source) || !subgraph.nodes.has(e.target))
277
+ continue;
278
+ const list = adj.get(e.source);
279
+ if (list)
280
+ list.push(e.target);
281
+ else
282
+ adj.set(e.source, [e.target]);
283
+ }
284
+ if (adj.size === 0)
285
+ return '';
286
+ const MAX_HOPS = 6;
287
+ const chains = [];
288
+ let budget = 2000; // bound DFS work on dense subgraphs
289
+ const dfs = (id, path, seen) => {
290
+ if (budget-- <= 0)
291
+ return;
292
+ const next = (adj.get(id) ?? []).filter((t) => !seen.has(t));
293
+ if (next.length === 0 || path.length >= MAX_HOPS) {
294
+ if (path.length >= 3)
295
+ chains.push([...path]); // >=3 nodes = a real flow, not a single call
296
+ return;
297
+ }
298
+ for (const t of next) {
299
+ seen.add(t);
300
+ dfs(t, [...path, t], seen);
301
+ seen.delete(t);
302
+ }
303
+ };
304
+ const starts = (subgraph.roots.length > 0
305
+ ? subgraph.roots.filter((id) => adj.has(id))
306
+ : [...adj.keys()]).slice(0, 5);
307
+ for (const s of starts)
308
+ dfs(s, [s], new Set([s]));
309
+ if (chains.length === 0)
310
+ return '';
311
+ // Keep only chains that connect TWO OR MORE query-relevant symbols (roots).
312
+ // A chain from a root into an arbitrary callee (render → onMagicFrameGenerate)
313
+ // is structurally valid but tangential to the question; requiring ≥2 roots
314
+ // keeps the chain anchored to what the user actually asked about. Rank by
315
+ // #roots then length, and drop any that are a sub-path of a longer kept chain.
316
+ const rootSet = new Set(subgraph.roots);
317
+ const rootCount = (c) => c.reduce((n, id) => n + (rootSet.has(id) ? 1 : 0), 0);
318
+ const relevant = chains.filter((c) => rootCount(c) >= 2);
319
+ relevant.sort((a, b) => rootCount(b) - rootCount(a) || b.length - a.length);
320
+ const kept = [];
321
+ for (const c of relevant) {
322
+ const key = c.join('>');
323
+ if (kept.some((k) => k.join('>').includes(key)))
324
+ continue;
325
+ kept.push(c);
326
+ if (kept.length >= 3)
327
+ break;
328
+ }
329
+ if (kept.length === 0)
330
+ return '';
331
+ const name = (id) => subgraph.nodes.get(id)?.name ?? id;
332
+ // Synthesized (dynamic-dispatch) hops are real `calls` edges but invisible to
333
+ // static parsing — mark them inline so the agent sees WHERE the callback was
334
+ // wired up (`registered @file:line`) instead of grepping for it. Keyed by
335
+ // "source>target".
336
+ const synthByPair = new Map();
337
+ for (const e of subgraph.edges) {
338
+ if (e.kind !== 'calls' || e.provenance !== 'heuristic')
339
+ continue;
340
+ const m = e.metadata;
341
+ if (!m?.synthesizedBy)
342
+ continue;
343
+ const at = typeof m.registeredAt === 'string' ? ` @${m.registeredAt}` : '';
344
+ const label = m.synthesizedBy === 'callback'
345
+ ? `callback via ${m.via ? `\`${String(m.via)}\`` : 'registrar'}${at}`
346
+ : m.synthesizedBy === 'react-render'
347
+ ? `React re-render via setState${at}`
348
+ : m.synthesizedBy === 'jsx-render'
349
+ ? `renders <${String(m.via || 'child')}>`
350
+ : m.synthesizedBy === 'vue-handler'
351
+ ? `Vue @${String(m.event || 'event')} handler`
352
+ : `event ${m.event ? `\`${String(m.event)}\`` : ''}${at}`;
353
+ synthByPair.set(`${e.source}>${e.target}`, label);
354
+ }
355
+ const renderChain = (c) => {
356
+ let s = name(c[0]);
357
+ for (let i = 1; i < c.length; i++) {
358
+ const synth = synthByPair.get(`${c[i - 1]}>${c[i]}`);
359
+ s += synth ? ` →[${synth}] ${name(c[i])}` : ` → ${name(c[i])}`;
360
+ }
361
+ return s;
362
+ };
363
+ const hasSynth = kept.some((c) => c.some((_, i) => i > 0 && synthByPair.has(`${c[i - 1]}>${c[i]}`)));
364
+ const lines = [
365
+ '',
366
+ '## Call paths',
367
+ '',
368
+ 'Execution flow among the key symbols (traced through the call graph):',
369
+ '',
370
+ ...kept.map((c) => `- ${renderChain(c)}`),
371
+ '',
372
+ hasSynth
373
+ ? '_Hops marked `[callback/event …]` are dynamic dispatch bridged by codegraph (with the registration site); the rest are direct calls. codegraph_node any symbol for its body._'
374
+ : '_codegraph_node any symbol above for its source + its own callers/callees._',
375
+ ];
376
+ return '\n' + lines.join('\n') + '\n';
377
+ }
378
+ /**
379
+ * Find relevant subgraph for a query
380
+ *
381
+ * Uses hybrid search combining exact symbol lookup with semantic search:
382
+ * 1. Extract potential symbol names from query
383
+ * 2. Look up exact matches for those symbols (high confidence)
384
+ * 3. Use semantic search for concept matching
385
+ * 4. Merge results, prioritizing exact matches
386
+ * 5. Traverse graph from entry points
387
+ *
388
+ * @param query - Natural language query
389
+ * @param options - Search and traversal options
390
+ * @returns Subgraph of relevant nodes and edges
391
+ */
392
+ async findRelevantContext(query, options = {}) {
393
+ const opts = { ...DEFAULT_FIND_OPTIONS, ...options };
394
+ // Start with empty subgraph
395
+ const nodes = new Map();
396
+ const edges = [];
397
+ const roots = [];
398
+ // Handle empty query - return empty subgraph
399
+ if (!query || query.trim().length === 0) {
400
+ return { nodes, edges, roots };
401
+ }
402
+ // === HYBRID SEARCH ===
403
+ // Step 1: Extract potential symbol names from query
404
+ const symbolsFromQuery = extractSymbolsFromQuery(query);
405
+ (0, errors_1.logDebug)('Extracted symbols from query', { query, symbols: symbolsFromQuery });
406
+ // Step 2: Look up exact matches for extracted symbols
407
+ let exactMatches = [];
408
+ if (symbolsFromQuery.length > 0) {
409
+ try {
410
+ // Get more results so we can apply co-location boosting before trimming
411
+ exactMatches = this.queries.findNodesByExactName(symbolsFromQuery, {
412
+ limit: Math.ceil(opts.searchLimit * 5),
413
+ kinds: opts.nodeKinds && opts.nodeKinds.length > 0 ? opts.nodeKinds : undefined,
414
+ });
415
+ // Co-location boost: when multiple extracted symbols appear in the same file,
416
+ // those results are much more likely to be what the user is looking for.
417
+ // E.g., "scrapeLoop" + "run" both in scrape/scrape.go → boost both.
418
+ if (exactMatches.length > 1) {
419
+ // Build a map of files → how many distinct symbol names matched in that file
420
+ const fileSymbolCounts = new Map();
421
+ for (const r of exactMatches) {
422
+ const names = fileSymbolCounts.get(r.node.filePath) || new Set();
423
+ names.add(r.node.name.toLowerCase());
424
+ fileSymbolCounts.set(r.node.filePath, names);
425
+ }
426
+ // Boost results in files where multiple query symbols co-occur
427
+ exactMatches = exactMatches.map(r => {
428
+ const symbolCount = fileSymbolCounts.get(r.node.filePath)?.size || 1;
429
+ return {
430
+ ...r,
431
+ score: symbolCount > 1 ? r.score + (symbolCount - 1) * 20 : r.score,
432
+ };
433
+ });
434
+ exactMatches.sort((a, b) => b.score - a.score);
435
+ }
436
+ // Trim back to reasonable size
437
+ exactMatches = exactMatches.slice(0, Math.ceil(opts.searchLimit * 2));
438
+ (0, errors_1.logDebug)('Exact symbol matches', { count: exactMatches.length });
439
+ }
440
+ catch (error) {
441
+ (0, errors_1.logDebug)('Exact symbol lookup failed', { error: String(error) });
442
+ }
443
+ }
444
+ // Step 2b: Search for extracted symbols as definition (class/interface) prefixes.
445
+ // When the user writes "REST", "bulk", or "allocation", they usually mean classes
446
+ // like RestController, BulkRequest, AllocationService — not nodes named exactly that.
447
+ // Also tries stem variants: "caching" → "cache" finds Cache, CacheBuilder.
448
+ if (symbolsFromQuery.length > 0) {
449
+ const definitionKinds = ['class', 'interface', 'struct', 'trait',
450
+ 'protocol', 'enum', 'type_alias'];
451
+ // Expand symbols with stem variants for broader definition matching
452
+ const expandedSymbols = new Set(symbolsFromQuery);
453
+ for (const sym of symbolsFromQuery) {
454
+ for (const variant of (0, query_utils_1.getStemVariants)(sym)) {
455
+ expandedSymbols.add(variant);
456
+ }
457
+ }
458
+ for (const sym of expandedSymbols) {
459
+ // Title-case the symbol: "REST" → "Rest", "bulk" → "Bulk", "allocation" → "Allocation"
460
+ const titleCased = sym.charAt(0).toUpperCase() + sym.slice(1).toLowerCase();
461
+ if (titleCased === sym)
462
+ continue; // already title-case (e.g., "Engine") — handled by exact match
463
+ // Fetch more results since popular prefixes have many matches
464
+ const prefixResults = this.queries.searchNodes(titleCased, {
465
+ limit: 30,
466
+ kinds: definitionKinds,
467
+ });
468
+ const matched = [];
469
+ for (const r of prefixResults) {
470
+ if (r.node.name.toLowerCase().startsWith(titleCased.toLowerCase())) {
471
+ // Favor shorter names: "AllocationService" (18 chars) over
472
+ // "AllocationBalancingRoundMetrics" (31 chars). Core classes tend
473
+ // to have concise names; test/helper classes are verbose.
474
+ const brevityBonus = Math.max(0, 10 - (r.node.name.length - titleCased.length) / 3);
475
+ matched.push({ ...r, score: r.score + 15 + brevityBonus });
476
+ }
477
+ }
478
+ matched.sort((a, b) => b.score - a.score);
479
+ for (const r of matched.slice(0, Math.ceil(opts.searchLimit))) {
480
+ const existing = exactMatches.find(e => e.node.id === r.node.id);
481
+ if (!existing) {
482
+ exactMatches.push(r);
483
+ }
484
+ }
485
+ }
486
+ exactMatches.sort((a, b) => b.score - a.score);
487
+ exactMatches = exactMatches.slice(0, Math.ceil(opts.searchLimit * 3));
488
+ }
489
+ // Step 3: Run text search for natural language term matching
490
+ // This catches file-name and node-name matches that semantic search may miss,
491
+ // which is critical for template-heavy codebases (e.g., Liquid/Shopify themes)
492
+ // where file names are the primary identifiers.
493
+ let textResults = [];
494
+ try {
495
+ const searchTerms = (0, query_utils_1.extractSearchTerms)(query);
496
+ if (searchTerms.length > 0) {
497
+ // Search each term individually to get broader coverage,
498
+ // then boost results that match multiple terms
499
+ const termResultsMap = new Map();
500
+ // When no explicit kind filter is set, exclude imports — they flood FTS
501
+ // results with qualified name matches (e.g., "REST" matches 445K import paths)
502
+ // but are almost never what exploration queries want.
503
+ const searchKinds = opts.nodeKinds && opts.nodeKinds.length > 0
504
+ ? opts.nodeKinds
505
+ : ['file', 'module', 'class', 'struct', 'interface', 'trait', 'protocol',
506
+ 'function', 'method', 'property', 'field', 'variable', 'constant',
507
+ 'enum', 'enum_member', 'type_alias', 'namespace', 'export',
508
+ 'route', 'component'];
509
+ for (const term of searchTerms) {
510
+ const termResults = this.queries.searchNodes(term, {
511
+ limit: opts.searchLimit * 2,
512
+ kinds: searchKinds,
513
+ });
514
+ for (const r of termResults) {
515
+ const existing = termResultsMap.get(r.node.id);
516
+ if (existing) {
517
+ existing.termHits++;
518
+ existing.result.score = Math.max(existing.result.score, r.score);
519
+ }
520
+ else {
521
+ termResultsMap.set(r.node.id, { result: r, termHits: 1 });
522
+ }
523
+ }
524
+ }
525
+ // Boost results matching multiple terms and sort
526
+ textResults = Array.from(termResultsMap.values())
527
+ .map(({ result, termHits }) => ({
528
+ ...result,
529
+ score: result.score + (termHits - 1) * 5,
530
+ }))
531
+ .sort((a, b) => b.score - a.score)
532
+ .slice(0, opts.searchLimit * 2);
533
+ }
534
+ (0, errors_1.logDebug)('Text search results', { count: textResults.length });
535
+ }
536
+ catch (error) {
537
+ (0, errors_1.logDebug)('Text search failed', { query, error: String(error) });
538
+ }
539
+ // Step 4: Merge results, taking the max score when duplicates appear
540
+ // across search channels. Exact matches may have lower scores than FTS
541
+ // results for the same node — use the best score from any channel.
542
+ const resultById = new Map();
543
+ let searchResults = [];
544
+ // Add exact matches first
545
+ for (const result of exactMatches) {
546
+ const existing = resultById.get(result.node.id);
547
+ if (existing) {
548
+ existing.score = Math.max(existing.score, result.score);
549
+ }
550
+ else {
551
+ resultById.set(result.node.id, result);
552
+ searchResults.push(result);
553
+ }
554
+ }
555
+ // Add text search results, upgrading scores for duplicates
556
+ for (const result of textResults) {
557
+ const existing = resultById.get(result.node.id);
558
+ if (existing) {
559
+ existing.score = Math.max(existing.score, result.score);
560
+ }
561
+ else {
562
+ resultById.set(result.node.id, result);
563
+ searchResults.push(result);
564
+ }
565
+ }
566
+ const queryLower = query.toLowerCase();
567
+ const isTestQuery = queryLower.includes('test') || queryLower.includes('spec');
568
+ // Deprioritize test files early so they don't take multi-term boost slots
569
+ if (!isTestQuery) {
570
+ for (const result of searchResults) {
571
+ if ((0, query_utils_1.isTestFile)(result.node.filePath)) {
572
+ result.score *= 0.3;
573
+ }
574
+ }
575
+ }
576
+ // Step 5a: Multi-term co-occurrence re-ranking (applied BEFORE truncation).
577
+ // For multi-word queries like "search execution from request to shard",
578
+ // nodes matching 2+ query terms in their name or path are far more relevant
579
+ // than nodes matching just one generic term. Without this, "ExecutionUtils"
580
+ // (matches only "execution") fills budget slots meant for "ShardSearchRequest"
581
+ // (matches "shard" + "search" + "request").
582
+ const queryTermsForBoost = (0, query_utils_1.extractSearchTerms)(query);
583
+ if (queryTermsForBoost.length >= 2) {
584
+ // Group terms that are substrings of each other (stem variants of the same
585
+ // root word). "indexed", "indexe", "index" should count as ONE concept match,
586
+ // not three. Without this, stem variants inflate matchCount and give false
587
+ // multi-term boosts to symbols matching one root word multiple times.
588
+ const termGroups = [];
589
+ const sorted = [...queryTermsForBoost].sort((a, b) => b.length - a.length);
590
+ const assigned = new Set();
591
+ for (const term of sorted) {
592
+ if (assigned.has(term))
593
+ continue;
594
+ const group = [term];
595
+ assigned.add(term);
596
+ for (const other of sorted) {
597
+ if (assigned.has(other))
598
+ continue;
599
+ if (term.includes(other) || other.includes(term)) {
600
+ group.push(other);
601
+ assigned.add(other);
602
+ }
603
+ }
604
+ termGroups.push(group);
605
+ }
606
+ // Build a set of exact-match node IDs so we can exempt them from dampening.
607
+ // When the query is "LiveEditMode DevServerPreview", these are specific
608
+ // symbols the user asked for — dampening them because they only match 1
609
+ // term group is counter-productive.
610
+ const exactMatchIds = new Set(exactMatches.map(r => r.node.id));
611
+ for (const result of searchResults) {
612
+ // Check term matches in name (substring) and path DIRECTORIES (exact).
613
+ // Directory segments must match exactly — "search" matches directory
614
+ // "search/" but NOT "elasticsearch/". The class name is checked
615
+ // separately via substring match on the node name.
616
+ const nameLower = result.node.name.toLowerCase();
617
+ const dirSegments = path.dirname(result.node.filePath).toLowerCase().split('/');
618
+ let matchCount = 0;
619
+ for (const group of termGroups) {
620
+ const groupMatches = group.some(term => {
621
+ const inName = nameLower.includes(term);
622
+ const inDir = dirSegments.some(seg => seg === term);
623
+ return inName || inDir;
624
+ });
625
+ if (groupMatches)
626
+ matchCount++;
627
+ }
628
+ if (matchCount >= 2) {
629
+ // Multiplicative boost — 2 terms → 2x, 3 terms → 2.5x
630
+ result.score *= 1 + matchCount * 0.5;
631
+ }
632
+ else if (!exactMatchIds.has(result.node.id)) {
633
+ // Mild dampen for single-term matches — they might be generic
634
+ // but could also be the right result (e.g., "Protocol" class for an IPC query).
635
+ // Exempt exact name matches: they are specific symbols the user queried for.
636
+ result.score *= 0.6;
637
+ }
638
+ }
639
+ searchResults.sort((a, b) => b.score - a.score);
640
+ }
641
+ // Step 5b: CamelCase-boundary matching via LIKE query.
642
+ // FTS can't find "Search" inside "TransportSearchAction" (one FTS token).
643
+ // LIKE reliably finds these substring matches. Results are appended with
644
+ // guaranteed slots so they don't compete with higher-scoring prefix matches.
645
+ if (symbolsFromQuery.length > 0) {
646
+ const camelDefinitionKinds = ['class', 'interface', 'struct', 'trait',
647
+ 'protocol', 'enum', 'type_alias'];
648
+ const camelSearchedTerms = new Set();
649
+ const searchIdSet = new Set(searchResults.map(r => r.node.id));
650
+ // Track per-node term hits for multi-term boosting
651
+ const camelNodeTerms = new Map();
652
+ const maxCamelPerTerm = Math.ceil(opts.searchLimit / 2);
653
+ for (const sym of symbolsFromQuery) {
654
+ const titleCased = sym.charAt(0).toUpperCase() + sym.slice(1).toLowerCase();
655
+ if (titleCased.length < 3)
656
+ continue;
657
+ const termKey = titleCased.toLowerCase();
658
+ if (camelSearchedTerms.has(termKey))
659
+ continue;
660
+ camelSearchedTerms.add(termKey);
661
+ // Fetch a large batch — popular terms like "Search" in Elasticsearch
662
+ // have hundreds of substring matches. The LIKE scan cost is the same
663
+ // regardless of LIMIT (SQLite scans all matches to sort), so we fetch
664
+ // generously and let path-relevance scoring pick the best ones.
665
+ const likeResults = this.queries.findNodesByNameSubstring(titleCased, {
666
+ limit: 200,
667
+ kinds: camelDefinitionKinds,
668
+ excludePrefix: true,
669
+ });
670
+ // Filter to CamelCase boundaries, score by path relevance, and take top N
671
+ const termCandidates = [];
672
+ for (const r of likeResults) {
673
+ const name = r.node.name;
674
+ const idx = name.indexOf(titleCased);
675
+ if (idx <= 0)
676
+ continue;
677
+ // Accept CamelCase boundary (lowercase before match) OR
678
+ // acronym boundary (uppercase before match, e.g., RPCProtocol)
679
+ if (!/[a-zA-Z]/.test(name.charAt(idx - 1)))
680
+ continue;
681
+ if (searchIdSet.has(r.node.id))
682
+ continue;
683
+ if ((0, query_utils_1.isTestFile)(r.node.filePath) && !isTestQuery)
684
+ continue;
685
+ const pathScore = (0, query_utils_1.scorePathRelevance)(r.node.filePath, query);
686
+ const brevityBonus = Math.max(0, 6 - (name.length - titleCased.length) / 4);
687
+ termCandidates.push({ node: r.node, score: 8 + brevityBonus + pathScore });
688
+ }
689
+ termCandidates.sort((a, b) => b.score - a.score);
690
+ // Widen the per-term pool for accumulation so multi-term co-occurrences
691
+ // can be discovered. A class matching 3 query terms at CamelCase boundaries
692
+ // is far more relevant than one matching just 1, but it needs to survive
693
+ // the per-term cut for EACH term to accumulate its count.
694
+ const accumPerTerm = maxCamelPerTerm * 4;
695
+ for (const r of termCandidates.slice(0, accumPerTerm)) {
696
+ const existing = camelNodeTerms.get(r.node.id);
697
+ if (existing) {
698
+ existing.termCount++;
699
+ }
700
+ else {
701
+ camelNodeTerms.set(r.node.id, {
702
+ result: r,
703
+ termCount: 1,
704
+ });
705
+ }
706
+ }
707
+ }
708
+ // Append CamelCase matches with multi-term boost.
709
+ // These are structurally important (class names containing query terms at
710
+ // CamelCase boundaries) but score much lower than FTS results. Scale their
711
+ // scores up so multi-term CamelCase matches can compete with FTS results.
712
+ const camelResults = [];
713
+ for (const [, info] of camelNodeTerms) {
714
+ // Multi-term CamelCase matches are extremely relevant — a class matching
715
+ // 3+ query terms in its name (e.g., ExtensionHostProcess) is almost
716
+ // certainly what the user wants. Scale aggressively.
717
+ info.result.score = info.result.score * (1 + info.termCount) + (info.termCount - 1) * 30;
718
+ camelResults.push(info.result);
719
+ }
720
+ camelResults.sort((a, b) => b.score - a.score);
721
+ const maxCamelTotal = opts.searchLimit;
722
+ for (const r of camelResults.slice(0, maxCamelTotal)) {
723
+ searchResults.push(r);
724
+ searchIdSet.add(r.node.id);
725
+ }
726
+ // Step 5c: Compound term matching — find classes whose name contains 2+
727
+ // query terms at ANY position (not just CamelCase boundaries).
728
+ // The CamelCase step above requires idx > 0, which misses classes that
729
+ // START with a query term (e.g., "SearchShardsRequest" starts with "Search").
730
+ // For multi-word queries, a class matching multiple query terms in its name
731
+ // is almost certainly relevant regardless of position.
732
+ if (symbolsFromQuery.length >= 2) {
733
+ // Collect ALL LIKE results per term (reusing findNodesByNameSubstring)
734
+ // but without the CamelCase boundary or prefix exclusion filters.
735
+ const compoundTermMap = new Map();
736
+ for (const sym of symbolsFromQuery) {
737
+ const titleCased = sym.charAt(0).toUpperCase() + sym.slice(1).toLowerCase();
738
+ if (titleCased.length < 3)
739
+ continue;
740
+ const likeResults = this.queries.findNodesByNameSubstring(titleCased, {
741
+ limit: 200,
742
+ kinds: camelDefinitionKinds,
743
+ excludePrefix: false,
744
+ });
745
+ for (const r of likeResults) {
746
+ if (searchIdSet.has(r.node.id))
747
+ continue;
748
+ if ((0, query_utils_1.isTestFile)(r.node.filePath) && !isTestQuery)
749
+ continue;
750
+ const entry = compoundTermMap.get(r.node.id);
751
+ if (entry) {
752
+ entry.terms.add(titleCased);
753
+ }
754
+ else {
755
+ compoundTermMap.set(r.node.id, { node: r.node, terms: new Set([titleCased]) });
756
+ }
757
+ }
758
+ }
759
+ // Keep only nodes matching 2+ distinct terms
760
+ const compoundResults = [];
761
+ for (const [, entry] of compoundTermMap) {
762
+ if (entry.terms.size >= 2) {
763
+ const pathScore = (0, query_utils_1.scorePathRelevance)(entry.node.filePath, query);
764
+ const brevityBonus = Math.max(0, 6 - entry.node.name.length / 8);
765
+ compoundResults.push({
766
+ node: entry.node,
767
+ score: 10 + (entry.terms.size - 1) * 20 + pathScore + brevityBonus,
768
+ });
769
+ }
770
+ }
771
+ compoundResults.sort((a, b) => b.score - a.score);
772
+ const maxCompound = Math.ceil(opts.searchLimit / 2);
773
+ for (const r of compoundResults.slice(0, maxCompound)) {
774
+ searchResults.push(r);
775
+ searchIdSet.add(r.node.id);
776
+ }
777
+ }
778
+ }
779
+ // Final sort and truncation — all search channels (exact, text, CamelCase,
780
+ // compound) have now contributed. Sort by score so multi-term matches from
781
+ // later steps can outrank dampened single-term matches from earlier steps.
782
+ searchResults.sort((a, b) => b.score - a.score);
783
+ searchResults = searchResults.slice(0, opts.searchLimit * 3);
784
+ // Filter by minimum score
785
+ let filteredResults = searchResults.filter((r) => r.score >= opts.minScore);
786
+ // Resolve imports/exports to their actual definitions
787
+ // If someone searches "terminal" and finds `import { TerminalPanel }`,
788
+ // they want the TerminalPanel class, not the import statement
789
+ filteredResults = this.resolveImportsToDefinitions(filteredResults);
790
+ // Cap entry points so traversal budget isn't spread too thin.
791
+ // With 36 entry points and maxNodes=120, each gets only 3 nodes — useless.
792
+ // Cap to searchLimit so each entry point gets a meaningful traversal budget.
793
+ if (filteredResults.length > opts.searchLimit) {
794
+ filteredResults = filteredResults.slice(0, opts.searchLimit);
795
+ }
796
+ // Add entry points to subgraph
797
+ for (const result of filteredResults) {
798
+ nodes.set(result.node.id, result.node);
799
+ roots.push(result.node.id);
800
+ }
801
+ // Expand type hierarchy for class/interface entry points.
802
+ // BFS often exhausts its per-entry-point budget on contained methods
803
+ // before reaching extends/implements neighbors. This dedicated step
804
+ // ensures subclasses and superclasses always appear in results.
805
+ // Budget: up to maxNodes/4 hierarchy nodes to avoid flooding.
806
+ const typeHierarchyKinds = new Set(['class', 'interface', 'struct', 'trait', 'protocol']);
807
+ const maxHierarchyNodes = Math.ceil(opts.maxNodes / 4);
808
+ let hierarchyNodesAdded = 0;
809
+ for (const result of filteredResults) {
810
+ if (hierarchyNodesAdded >= maxHierarchyNodes)
811
+ break;
812
+ if (typeHierarchyKinds.has(result.node.kind)) {
813
+ const hierarchy = this.traverser.getTypeHierarchy(result.node.id);
814
+ for (const [id, node] of hierarchy.nodes) {
815
+ if (!nodes.has(id)) {
816
+ nodes.set(id, node);
817
+ hierarchyNodesAdded++;
818
+ }
819
+ }
820
+ for (const edge of hierarchy.edges) {
821
+ const exists = edges.some((e) => e.source === edge.source && e.target === edge.target && e.kind === edge.kind);
822
+ if (!exists) {
823
+ edges.push(edge);
824
+ }
825
+ }
826
+ }
827
+ }
828
+ // Pass 2: expand hierarchy of newly-discovered parent types to find siblings.
829
+ // E.g., InternalEngine → Engine (parent, from pass 1) → ReadOnlyEngine (sibling).
830
+ if (hierarchyNodesAdded > 0) {
831
+ const pass2Candidates = [...nodes.values()].filter(n => typeHierarchyKinds.has(n.kind) && !roots.includes(n.id));
832
+ for (const candidate of pass2Candidates) {
833
+ if (hierarchyNodesAdded >= maxHierarchyNodes)
834
+ break;
835
+ const siblingHierarchy = this.traverser.getTypeHierarchy(candidate.id);
836
+ for (const [id, node] of siblingHierarchy.nodes) {
837
+ if (!nodes.has(id) && hierarchyNodesAdded < maxHierarchyNodes) {
838
+ nodes.set(id, node);
839
+ hierarchyNodesAdded++;
840
+ }
841
+ }
842
+ for (const edge of siblingHierarchy.edges) {
843
+ if (nodes.has(edge.source) && nodes.has(edge.target)) {
844
+ const exists = edges.some((e) => e.source === edge.source && e.target === edge.target && e.kind === edge.kind);
845
+ if (!exists) {
846
+ edges.push(edge);
847
+ }
848
+ }
849
+ }
850
+ }
851
+ }
852
+ // Traverse from each entry point
853
+ for (const result of filteredResults) {
854
+ const traversalResult = this.traverser.traverseBFS(result.node.id, {
855
+ maxDepth: opts.traversalDepth,
856
+ edgeKinds: opts.edgeKinds && opts.edgeKinds.length > 0 ? opts.edgeKinds : undefined,
857
+ nodeKinds: opts.nodeKinds && opts.nodeKinds.length > 0 ? opts.nodeKinds : undefined,
858
+ direction: 'both',
859
+ limit: Math.ceil(opts.maxNodes / Math.max(1, filteredResults.length)),
860
+ });
861
+ // Merge nodes
862
+ for (const [id, node] of traversalResult.nodes) {
863
+ if (!nodes.has(id)) {
864
+ nodes.set(id, node);
865
+ }
866
+ }
867
+ // Merge edges (avoid duplicates)
868
+ for (const edge of traversalResult.edges) {
869
+ const exists = edges.some((e) => e.source === edge.source && e.target === edge.target && e.kind === edge.kind);
870
+ if (!exists) {
871
+ edges.push(edge);
872
+ }
873
+ }
874
+ }
875
+ // Trim to max nodes if needed
876
+ let finalNodes = nodes;
877
+ let finalEdges = edges;
878
+ if (nodes.size > opts.maxNodes) {
879
+ // Prioritize entry points and their direct neighbors
880
+ const priorityIds = new Set(roots);
881
+ for (const edge of edges) {
882
+ if (priorityIds.has(edge.source)) {
883
+ priorityIds.add(edge.target);
884
+ }
885
+ if (priorityIds.has(edge.target)) {
886
+ priorityIds.add(edge.source);
887
+ }
888
+ }
889
+ // Keep priority nodes, then fill remaining slots
890
+ finalNodes = new Map();
891
+ for (const id of priorityIds) {
892
+ const node = nodes.get(id);
893
+ if (node && finalNodes.size < opts.maxNodes) {
894
+ finalNodes.set(id, node);
895
+ }
896
+ }
897
+ // Fill remaining from other nodes
898
+ for (const [id, node] of nodes) {
899
+ if (finalNodes.size >= opts.maxNodes)
900
+ break;
901
+ if (!finalNodes.has(id)) {
902
+ finalNodes.set(id, node);
903
+ }
904
+ }
905
+ // Filter edges to only include kept nodes
906
+ finalEdges = edges.filter((e) => finalNodes.has(e.source) && finalNodes.has(e.target));
907
+ }
908
+ // Per-file diversity cap: prevent any single file from monopolizing the
909
+ // node budget. When BFS traverses from a method, it follows `contains`
910
+ // to the parent class, then back down to all sibling methods. With
911
+ // multiple entry points in the same class, one file can consume 30-40%
912
+ // of maxNodes. Cap each file to ~20% to ensure cross-file diversity.
913
+ const maxPerFile = Math.max(5, Math.ceil(opts.maxNodes * 0.2));
914
+ const fileCounts = new Map();
915
+ for (const [id, node] of finalNodes) {
916
+ const ids = fileCounts.get(node.filePath) || [];
917
+ ids.push(id);
918
+ fileCounts.set(node.filePath, ids);
919
+ }
920
+ const rootSet = new Set(roots);
921
+ for (const [, nodeIds] of fileCounts) {
922
+ if (nodeIds.length <= maxPerFile)
923
+ continue;
924
+ // Sort: entry points first, then classes/interfaces, then others
925
+ const kindPriority = {
926
+ class: 3, interface: 3, struct: 3, trait: 3, protocol: 3, enum: 3,
927
+ method: 1, function: 1, property: 0, field: 0, variable: 0,
928
+ };
929
+ nodeIds.sort((a, b) => {
930
+ const aRoot = rootSet.has(a) ? 10 : 0;
931
+ const bRoot = rootSet.has(b) ? 10 : 0;
932
+ const aKind = kindPriority[finalNodes.get(a).kind] ?? 0;
933
+ const bKind = kindPriority[finalNodes.get(b).kind] ?? 0;
934
+ return (bRoot + bKind) - (aRoot + aKind);
935
+ });
936
+ // Remove excess nodes (keep the highest-priority ones)
937
+ for (const id of nodeIds.slice(maxPerFile)) {
938
+ finalNodes.delete(id);
939
+ }
940
+ }
941
+ // Non-production node cap: limit test/sample/integration/example files to
942
+ // at most 15% of the budget. Many codebases have dozens of near-identical
943
+ // test implementations (e.g., 6 Guard classes in integration tests) that
944
+ // individually survive score dampening but collectively flood the result.
945
+ // Test entry points are NOT exempt — they should be evicted too.
946
+ if (!isTestQuery) {
947
+ const maxNonProd = Math.max(3, Math.ceil(opts.maxNodes * 0.15));
948
+ const nonProdIds = [];
949
+ for (const [id, node] of finalNodes) {
950
+ if ((0, query_utils_1.isTestFile)(node.filePath)) {
951
+ nonProdIds.push(id);
952
+ }
953
+ }
954
+ if (nonProdIds.length > maxNonProd) {
955
+ for (const id of nonProdIds.slice(maxNonProd)) {
956
+ finalNodes.delete(id);
957
+ // Also remove from roots — test file entry points shouldn't anchor results
958
+ const rootIdx = roots.indexOf(id);
959
+ if (rootIdx !== -1)
960
+ roots.splice(rootIdx, 1);
961
+ }
962
+ }
963
+ }
964
+ // Re-filter edges after per-file and non-production caps
965
+ finalEdges = finalEdges.filter((e) => finalNodes.has(e.source) && finalNodes.has(e.target));
966
+ // Edge recovery: BFS with many entry points leaves most nodes disconnected.
967
+ // Discover edges between already-selected nodes to recover connectivity.
968
+ const recoveryKinds = ['calls', 'extends', 'implements', 'references', 'overrides'];
969
+ const recoveredEdges = this.queries.findEdgesBetweenNodes([...finalNodes.keys()], recoveryKinds);
970
+ const existingEdgeKeys = new Set(finalEdges.map((e) => `${e.source}:${e.target}:${e.kind}`));
971
+ for (const edge of recoveredEdges) {
972
+ const key = `${edge.source}:${edge.target}:${edge.kind}`;
973
+ if (!existingEdgeKeys.has(key)) {
974
+ finalEdges.push(edge);
975
+ existingEdgeKeys.add(key);
976
+ }
977
+ }
978
+ return { nodes: finalNodes, edges: finalEdges, roots };
979
+ }
980
+ /**
981
+ * Get the source code for a node
982
+ *
983
+ * Reads the file and extracts the code between startLine and endLine.
984
+ *
985
+ * @param nodeId - ID of the node
986
+ * @returns Code string or null if not found
987
+ */
988
+ async getCode(nodeId) {
989
+ const node = this.queries.getNodeById(nodeId);
990
+ if (!node) {
991
+ return null;
992
+ }
993
+ return this.extractNodeCode(node);
994
+ }
995
+ /**
996
+ * Extract code from a node's source file
997
+ */
998
+ async extractNodeCode(node) {
999
+ const filePath = (0, utils_1.validatePathWithinRoot)(this.projectRoot, node.filePath);
1000
+ if (!filePath || !fs.existsSync(filePath)) {
1001
+ return null;
1002
+ }
1003
+ try {
1004
+ const content = fs.readFileSync(filePath, 'utf-8');
1005
+ const lines = content.split('\n');
1006
+ // Extract lines (1-indexed to 0-indexed)
1007
+ const startIdx = Math.max(0, node.startLine - 1);
1008
+ const endIdx = Math.min(lines.length, node.endLine);
1009
+ return lines.slice(startIdx, endIdx).join('\n');
1010
+ }
1011
+ catch (error) {
1012
+ (0, errors_1.logDebug)('Failed to extract code from node', { nodeId: node.id, filePath: node.filePath, error: String(error) });
1013
+ return null;
1014
+ }
1015
+ }
1016
+ /**
1017
+ * Get entry points from a subgraph (the root nodes)
1018
+ */
1019
+ getEntryPoints(subgraph) {
1020
+ return subgraph.roots
1021
+ .map((id) => subgraph.nodes.get(id))
1022
+ .filter((n) => n !== undefined);
1023
+ }
1024
+ /**
1025
+ * Extract code blocks for key nodes in the subgraph
1026
+ */
1027
+ async extractCodeBlocks(subgraph, maxBlocks, maxBlockSize) {
1028
+ const blocks = [];
1029
+ // Prioritize entry points, then functions/methods
1030
+ const priorityNodes = [];
1031
+ // First: entry points
1032
+ for (const id of subgraph.roots) {
1033
+ const node = subgraph.nodes.get(id);
1034
+ if (node) {
1035
+ priorityNodes.push(node);
1036
+ }
1037
+ }
1038
+ // Then: functions and methods
1039
+ for (const node of subgraph.nodes.values()) {
1040
+ if (!subgraph.roots.includes(node.id)) {
1041
+ if (node.kind === 'function' || node.kind === 'method') {
1042
+ priorityNodes.push(node);
1043
+ }
1044
+ }
1045
+ }
1046
+ // Then: classes
1047
+ for (const node of subgraph.nodes.values()) {
1048
+ if (!subgraph.roots.includes(node.id)) {
1049
+ if (node.kind === 'class') {
1050
+ priorityNodes.push(node);
1051
+ }
1052
+ }
1053
+ }
1054
+ // Extract code for priority nodes
1055
+ for (const node of priorityNodes) {
1056
+ if (blocks.length >= maxBlocks)
1057
+ break;
1058
+ const code = await this.extractNodeCode(node);
1059
+ if (code) {
1060
+ // Truncate if too long. Language-neutral marker (no `//` — not a
1061
+ // comment in Python, Ruby, etc.); this renders inside a fenced
1062
+ // source block whose language varies.
1063
+ const truncated = code.length > maxBlockSize
1064
+ ? code.slice(0, maxBlockSize) + '\n... (truncated) ...'
1065
+ : code;
1066
+ blocks.push({
1067
+ content: truncated,
1068
+ filePath: node.filePath,
1069
+ startLine: node.startLine,
1070
+ endLine: node.endLine,
1071
+ language: node.language,
1072
+ node,
1073
+ });
1074
+ }
1075
+ }
1076
+ return blocks;
1077
+ }
1078
+ /**
1079
+ * Get unique files from a subgraph
1080
+ */
1081
+ getRelatedFiles(subgraph) {
1082
+ const files = new Set();
1083
+ for (const node of subgraph.nodes.values()) {
1084
+ files.add(node.filePath);
1085
+ }
1086
+ return Array.from(files).sort();
1087
+ }
1088
+ /**
1089
+ * Generate a summary of the context
1090
+ */
1091
+ generateSummary(_query, subgraph, entryPoints) {
1092
+ const nodeCount = subgraph.nodes.size;
1093
+ const edgeCount = subgraph.edges.length;
1094
+ const files = this.getRelatedFiles(subgraph);
1095
+ const entryPointNames = entryPoints
1096
+ .slice(0, 3)
1097
+ .map((n) => n.name)
1098
+ .join(', ');
1099
+ const remaining = entryPoints.length > 3 ? ` and ${entryPoints.length - 3} more` : '';
1100
+ return `Found ${nodeCount} relevant code symbols across ${files.length} files. ` +
1101
+ `Key entry points: ${entryPointNames}${remaining}. ` +
1102
+ `${edgeCount} relationships identified.`;
1103
+ }
1104
+ /**
1105
+ * Resolve import/export nodes to their actual definitions
1106
+ *
1107
+ * When search returns `import { TerminalPanel }`, users want the TerminalPanel
1108
+ * class definition, not the import statement. This follows the `imports` edge
1109
+ * to find and return the actual definition instead.
1110
+ *
1111
+ * @param results - Search results that may include import/export nodes
1112
+ * @returns Results with imports resolved to definitions where possible
1113
+ */
1114
+ resolveImportsToDefinitions(results) {
1115
+ const resolved = [];
1116
+ const seenIds = new Set();
1117
+ for (const result of results) {
1118
+ const { node, score } = result;
1119
+ // If it's not an import/export, keep it as-is
1120
+ if (node.kind !== 'import' && node.kind !== 'export') {
1121
+ if (!seenIds.has(node.id)) {
1122
+ seenIds.add(node.id);
1123
+ resolved.push(result);
1124
+ }
1125
+ continue;
1126
+ }
1127
+ // For imports/exports, try to find what they reference
1128
+ // Imports have outgoing 'imports' edges to the definition
1129
+ // Exports have outgoing 'exports' edges to the definition
1130
+ const edgeKind = node.kind === 'import' ? 'imports' : 'exports';
1131
+ const outgoingEdges = this.queries.getOutgoingEdges(node.id, [edgeKind]);
1132
+ let foundDefinition = false;
1133
+ for (const edge of outgoingEdges) {
1134
+ const targetNode = this.queries.getNodeById(edge.target);
1135
+ if (targetNode && !seenIds.has(targetNode.id)) {
1136
+ // Found the definition - use it instead of the import
1137
+ seenIds.add(targetNode.id);
1138
+ resolved.push({
1139
+ node: targetNode,
1140
+ score: score, // Preserve the original score
1141
+ });
1142
+ foundDefinition = true;
1143
+ (0, errors_1.logDebug)('Resolved import to definition', {
1144
+ import: node.name,
1145
+ definition: targetNode.name,
1146
+ kind: targetNode.kind,
1147
+ });
1148
+ }
1149
+ }
1150
+ // If we couldn't resolve the import, skip it (it's low-value on its own)
1151
+ if (!foundDefinition) {
1152
+ (0, errors_1.logDebug)('Skipping unresolved import', { name: node.name, file: node.filePath });
1153
+ }
1154
+ }
1155
+ return resolved;
1156
+ }
1157
+ }
1158
+ exports.ContextBuilder = ContextBuilder;
1159
+ /**
1160
+ * Create a context builder
1161
+ */
1162
+ function createContextBuilder(projectRoot, queries, traverser) {
1163
+ return new ContextBuilder(projectRoot, queries, traverser);
1164
+ }
1165
+ // Re-export formatter
1166
+ var formatter_2 = require("./formatter");
1167
+ Object.defineProperty(exports, "formatContextAsMarkdown", { enumerable: true, get: function () { return formatter_2.formatContextAsMarkdown; } });
1168
+ Object.defineProperty(exports, "formatContextAsJson", { enumerable: true, get: function () { return formatter_2.formatContextAsJson; } });
1169
+ //# sourceMappingURL=index.js.map