@colbymchenry/codegraph 0.7.10 → 0.9.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 (362) hide show
  1. package/README.md +70 -54
  2. package/npm-shim.js +43 -0
  3. package/package.json +13 -51
  4. package/LICENSE +0 -21
  5. package/dist/bin/codegraph.d.ts +0 -21
  6. package/dist/bin/codegraph.d.ts.map +0 -1
  7. package/dist/bin/codegraph.js +0 -1232
  8. package/dist/bin/codegraph.js.map +0 -1
  9. package/dist/bin/node-version-check.d.ts +0 -20
  10. package/dist/bin/node-version-check.d.ts.map +0 -1
  11. package/dist/bin/node-version-check.js +0 -42
  12. package/dist/bin/node-version-check.js.map +0 -1
  13. package/dist/bin/uninstall.d.ts +0 -14
  14. package/dist/bin/uninstall.d.ts.map +0 -1
  15. package/dist/bin/uninstall.js +0 -36
  16. package/dist/bin/uninstall.js.map +0 -1
  17. package/dist/config.d.ts +0 -51
  18. package/dist/config.d.ts.map +0 -1
  19. package/dist/config.js +0 -321
  20. package/dist/config.js.map +0 -1
  21. package/dist/context/formatter.d.ts +0 -30
  22. package/dist/context/formatter.d.ts.map +0 -1
  23. package/dist/context/formatter.js +0 -244
  24. package/dist/context/formatter.js.map +0 -1
  25. package/dist/context/index.d.ts +0 -97
  26. package/dist/context/index.d.ts.map +0 -1
  27. package/dist/context/index.js +0 -1048
  28. package/dist/context/index.js.map +0 -1
  29. package/dist/db/index.d.ts +0 -72
  30. package/dist/db/index.d.ts.map +0 -1
  31. package/dist/db/index.js +0 -200
  32. package/dist/db/index.js.map +0 -1
  33. package/dist/db/migrations.d.ts +0 -44
  34. package/dist/db/migrations.d.ts.map +0 -1
  35. package/dist/db/migrations.js +0 -131
  36. package/dist/db/migrations.js.map +0 -1
  37. package/dist/db/queries.d.ts +0 -253
  38. package/dist/db/queries.d.ts.map +0 -1
  39. package/dist/db/queries.js +0 -1207
  40. package/dist/db/queries.js.map +0 -1
  41. package/dist/db/schema.sql +0 -151
  42. package/dist/db/sqlite-adapter.d.ts +0 -52
  43. package/dist/db/sqlite-adapter.d.ts.map +0 -1
  44. package/dist/db/sqlite-adapter.js +0 -237
  45. package/dist/db/sqlite-adapter.js.map +0 -1
  46. package/dist/directory.d.ts +0 -57
  47. package/dist/directory.d.ts.map +0 -1
  48. package/dist/directory.js +0 -264
  49. package/dist/directory.js.map +0 -1
  50. package/dist/errors.d.ts +0 -136
  51. package/dist/errors.d.ts.map +0 -1
  52. package/dist/errors.js +0 -219
  53. package/dist/errors.js.map +0 -1
  54. package/dist/extraction/dfm-extractor.d.ts +0 -31
  55. package/dist/extraction/dfm-extractor.d.ts.map +0 -1
  56. package/dist/extraction/dfm-extractor.js +0 -151
  57. package/dist/extraction/dfm-extractor.js.map +0 -1
  58. package/dist/extraction/grammars.d.ts +0 -78
  59. package/dist/extraction/grammars.d.ts.map +0 -1
  60. package/dist/extraction/grammars.js +0 -322
  61. package/dist/extraction/grammars.js.map +0 -1
  62. package/dist/extraction/index.d.ts +0 -130
  63. package/dist/extraction/index.d.ts.map +0 -1
  64. package/dist/extraction/index.js +0 -1279
  65. package/dist/extraction/index.js.map +0 -1
  66. package/dist/extraction/languages/c-cpp.d.ts +0 -4
  67. package/dist/extraction/languages/c-cpp.d.ts.map +0 -1
  68. package/dist/extraction/languages/c-cpp.js +0 -126
  69. package/dist/extraction/languages/c-cpp.js.map +0 -1
  70. package/dist/extraction/languages/csharp.d.ts +0 -3
  71. package/dist/extraction/languages/csharp.d.ts.map +0 -1
  72. package/dist/extraction/languages/csharp.js +0 -72
  73. package/dist/extraction/languages/csharp.js.map +0 -1
  74. package/dist/extraction/languages/dart.d.ts +0 -3
  75. package/dist/extraction/languages/dart.d.ts.map +0 -1
  76. package/dist/extraction/languages/dart.js +0 -192
  77. package/dist/extraction/languages/dart.js.map +0 -1
  78. package/dist/extraction/languages/go.d.ts +0 -3
  79. package/dist/extraction/languages/go.d.ts.map +0 -1
  80. package/dist/extraction/languages/go.js +0 -58
  81. package/dist/extraction/languages/go.js.map +0 -1
  82. package/dist/extraction/languages/index.d.ts +0 -10
  83. package/dist/extraction/languages/index.d.ts.map +0 -1
  84. package/dist/extraction/languages/index.js +0 -45
  85. package/dist/extraction/languages/index.js.map +0 -1
  86. package/dist/extraction/languages/java.d.ts +0 -3
  87. package/dist/extraction/languages/java.d.ts.map +0 -1
  88. package/dist/extraction/languages/java.js +0 -64
  89. package/dist/extraction/languages/java.js.map +0 -1
  90. package/dist/extraction/languages/javascript.d.ts +0 -3
  91. package/dist/extraction/languages/javascript.d.ts.map +0 -1
  92. package/dist/extraction/languages/javascript.js +0 -90
  93. package/dist/extraction/languages/javascript.js.map +0 -1
  94. package/dist/extraction/languages/kotlin.d.ts +0 -3
  95. package/dist/extraction/languages/kotlin.d.ts.map +0 -1
  96. package/dist/extraction/languages/kotlin.js +0 -253
  97. package/dist/extraction/languages/kotlin.js.map +0 -1
  98. package/dist/extraction/languages/pascal.d.ts +0 -3
  99. package/dist/extraction/languages/pascal.d.ts.map +0 -1
  100. package/dist/extraction/languages/pascal.js +0 -66
  101. package/dist/extraction/languages/pascal.js.map +0 -1
  102. package/dist/extraction/languages/php.d.ts +0 -3
  103. package/dist/extraction/languages/php.d.ts.map +0 -1
  104. package/dist/extraction/languages/php.js +0 -107
  105. package/dist/extraction/languages/php.js.map +0 -1
  106. package/dist/extraction/languages/python.d.ts +0 -3
  107. package/dist/extraction/languages/python.d.ts.map +0 -1
  108. package/dist/extraction/languages/python.js +0 -56
  109. package/dist/extraction/languages/python.js.map +0 -1
  110. package/dist/extraction/languages/ruby.d.ts +0 -3
  111. package/dist/extraction/languages/ruby.d.ts.map +0 -1
  112. package/dist/extraction/languages/ruby.js +0 -114
  113. package/dist/extraction/languages/ruby.js.map +0 -1
  114. package/dist/extraction/languages/rust.d.ts +0 -3
  115. package/dist/extraction/languages/rust.d.ts.map +0 -1
  116. package/dist/extraction/languages/rust.js +0 -109
  117. package/dist/extraction/languages/rust.js.map +0 -1
  118. package/dist/extraction/languages/scala.d.ts +0 -3
  119. package/dist/extraction/languages/scala.d.ts.map +0 -1
  120. package/dist/extraction/languages/scala.js +0 -139
  121. package/dist/extraction/languages/scala.js.map +0 -1
  122. package/dist/extraction/languages/swift.d.ts +0 -3
  123. package/dist/extraction/languages/swift.d.ts.map +0 -1
  124. package/dist/extraction/languages/swift.js +0 -91
  125. package/dist/extraction/languages/swift.js.map +0 -1
  126. package/dist/extraction/languages/typescript.d.ts +0 -3
  127. package/dist/extraction/languages/typescript.d.ts.map +0 -1
  128. package/dist/extraction/languages/typescript.js +0 -129
  129. package/dist/extraction/languages/typescript.js.map +0 -1
  130. package/dist/extraction/liquid-extractor.d.ts +0 -52
  131. package/dist/extraction/liquid-extractor.d.ts.map +0 -1
  132. package/dist/extraction/liquid-extractor.js +0 -313
  133. package/dist/extraction/liquid-extractor.js.map +0 -1
  134. package/dist/extraction/parse-worker.d.ts +0 -8
  135. package/dist/extraction/parse-worker.d.ts.map +0 -1
  136. package/dist/extraction/parse-worker.js +0 -94
  137. package/dist/extraction/parse-worker.js.map +0 -1
  138. package/dist/extraction/svelte-extractor.d.ts +0 -56
  139. package/dist/extraction/svelte-extractor.d.ts.map +0 -1
  140. package/dist/extraction/svelte-extractor.js +0 -272
  141. package/dist/extraction/svelte-extractor.js.map +0 -1
  142. package/dist/extraction/tree-sitter-helpers.d.ts +0 -28
  143. package/dist/extraction/tree-sitter-helpers.d.ts.map +0 -1
  144. package/dist/extraction/tree-sitter-helpers.js +0 -103
  145. package/dist/extraction/tree-sitter-helpers.js.map +0 -1
  146. package/dist/extraction/tree-sitter-types.d.ts +0 -179
  147. package/dist/extraction/tree-sitter-types.d.ts.map +0 -1
  148. package/dist/extraction/tree-sitter-types.js +0 -10
  149. package/dist/extraction/tree-sitter-types.js.map +0 -1
  150. package/dist/extraction/tree-sitter.d.ts +0 -233
  151. package/dist/extraction/tree-sitter.d.ts.map +0 -1
  152. package/dist/extraction/tree-sitter.js +0 -2393
  153. package/dist/extraction/tree-sitter.js.map +0 -1
  154. package/dist/extraction/vue-extractor.d.ts +0 -36
  155. package/dist/extraction/vue-extractor.d.ts.map +0 -1
  156. package/dist/extraction/vue-extractor.js +0 -163
  157. package/dist/extraction/vue-extractor.js.map +0 -1
  158. package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  159. package/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
  160. package/dist/graph/index.d.ts +0 -8
  161. package/dist/graph/index.d.ts.map +0 -1
  162. package/dist/graph/index.js +0 -13
  163. package/dist/graph/index.js.map +0 -1
  164. package/dist/graph/queries.d.ts +0 -106
  165. package/dist/graph/queries.d.ts.map +0 -1
  166. package/dist/graph/queries.js +0 -366
  167. package/dist/graph/queries.js.map +0 -1
  168. package/dist/graph/traversal.d.ts +0 -127
  169. package/dist/graph/traversal.d.ts.map +0 -1
  170. package/dist/graph/traversal.js +0 -493
  171. package/dist/graph/traversal.js.map +0 -1
  172. package/dist/index.d.ts +0 -447
  173. package/dist/index.d.ts.map +0 -1
  174. package/dist/index.js +0 -825
  175. package/dist/index.js.map +0 -1
  176. package/dist/installer/claude-md-template.d.ts +0 -14
  177. package/dist/installer/claude-md-template.d.ts.map +0 -1
  178. package/dist/installer/claude-md-template.js +0 -21
  179. package/dist/installer/claude-md-template.js.map +0 -1
  180. package/dist/installer/config-writer.d.ts +0 -29
  181. package/dist/installer/config-writer.d.ts.map +0 -1
  182. package/dist/installer/config-writer.js +0 -109
  183. package/dist/installer/config-writer.js.map +0 -1
  184. package/dist/installer/index.d.ts +0 -53
  185. package/dist/installer/index.d.ts.map +0 -1
  186. package/dist/installer/index.js +0 -338
  187. package/dist/installer/index.js.map +0 -1
  188. package/dist/installer/instructions-template.d.ts +0 -28
  189. package/dist/installer/instructions-template.d.ts.map +0 -1
  190. package/dist/installer/instructions-template.js +0 -63
  191. package/dist/installer/instructions-template.js.map +0 -1
  192. package/dist/installer/targets/claude.d.ts +0 -27
  193. package/dist/installer/targets/claude.d.ts.map +0 -1
  194. package/dist/installer/targets/claude.js +0 -246
  195. package/dist/installer/targets/claude.js.map +0 -1
  196. package/dist/installer/targets/codex.d.ts +0 -18
  197. package/dist/installer/targets/codex.d.ts.map +0 -1
  198. package/dist/installer/targets/codex.js +0 -185
  199. package/dist/installer/targets/codex.js.map +0 -1
  200. package/dist/installer/targets/cursor.d.ts +0 -35
  201. package/dist/installer/targets/cursor.d.ts.map +0 -1
  202. package/dist/installer/targets/cursor.js +0 -229
  203. package/dist/installer/targets/cursor.js.map +0 -1
  204. package/dist/installer/targets/opencode.d.ts +0 -30
  205. package/dist/installer/targets/opencode.d.ts.map +0 -1
  206. package/dist/installer/targets/opencode.js +0 -235
  207. package/dist/installer/targets/opencode.js.map +0 -1
  208. package/dist/installer/targets/registry.d.ts +0 -35
  209. package/dist/installer/targets/registry.d.ts.map +0 -1
  210. package/dist/installer/targets/registry.js +0 -83
  211. package/dist/installer/targets/registry.js.map +0 -1
  212. package/dist/installer/targets/shared.d.ts +0 -77
  213. package/dist/installer/targets/shared.d.ts.map +0 -1
  214. package/dist/installer/targets/shared.js +0 -246
  215. package/dist/installer/targets/shared.js.map +0 -1
  216. package/dist/installer/targets/toml.d.ts +0 -52
  217. package/dist/installer/targets/toml.d.ts.map +0 -1
  218. package/dist/installer/targets/toml.js +0 -147
  219. package/dist/installer/targets/toml.js.map +0 -1
  220. package/dist/installer/targets/types.d.ts +0 -116
  221. package/dist/installer/targets/types.d.ts.map +0 -1
  222. package/dist/installer/targets/types.js +0 -16
  223. package/dist/installer/targets/types.js.map +0 -1
  224. package/dist/mcp/index.d.ts +0 -86
  225. package/dist/mcp/index.d.ts.map +0 -1
  226. package/dist/mcp/index.js +0 -355
  227. package/dist/mcp/index.js.map +0 -1
  228. package/dist/mcp/server-instructions.d.ts +0 -19
  229. package/dist/mcp/server-instructions.d.ts.map +0 -1
  230. package/dist/mcp/server-instructions.js +0 -59
  231. package/dist/mcp/server-instructions.js.map +0 -1
  232. package/dist/mcp/tools.d.ts +0 -200
  233. package/dist/mcp/tools.d.ts.map +0 -1
  234. package/dist/mcp/tools.js +0 -1319
  235. package/dist/mcp/tools.js.map +0 -1
  236. package/dist/mcp/transport.d.ts +0 -89
  237. package/dist/mcp/transport.d.ts.map +0 -1
  238. package/dist/mcp/transport.js +0 -170
  239. package/dist/mcp/transport.js.map +0 -1
  240. package/dist/resolution/frameworks/cargo-workspace.d.ts +0 -18
  241. package/dist/resolution/frameworks/cargo-workspace.d.ts.map +0 -1
  242. package/dist/resolution/frameworks/cargo-workspace.js +0 -225
  243. package/dist/resolution/frameworks/cargo-workspace.js.map +0 -1
  244. package/dist/resolution/frameworks/csharp.d.ts +0 -8
  245. package/dist/resolution/frameworks/csharp.d.ts.map +0 -1
  246. package/dist/resolution/frameworks/csharp.js +0 -213
  247. package/dist/resolution/frameworks/csharp.js.map +0 -1
  248. package/dist/resolution/frameworks/express.d.ts +0 -8
  249. package/dist/resolution/frameworks/express.d.ts.map +0 -1
  250. package/dist/resolution/frameworks/express.js +0 -225
  251. package/dist/resolution/frameworks/express.js.map +0 -1
  252. package/dist/resolution/frameworks/go.d.ts +0 -8
  253. package/dist/resolution/frameworks/go.d.ts.map +0 -1
  254. package/dist/resolution/frameworks/go.js +0 -158
  255. package/dist/resolution/frameworks/go.js.map +0 -1
  256. package/dist/resolution/frameworks/index.d.ts +0 -41
  257. package/dist/resolution/frameworks/index.d.ts.map +0 -1
  258. package/dist/resolution/frameworks/index.js +0 -129
  259. package/dist/resolution/frameworks/index.js.map +0 -1
  260. package/dist/resolution/frameworks/java.d.ts +0 -8
  261. package/dist/resolution/frameworks/java.d.ts.map +0 -1
  262. package/dist/resolution/frameworks/java.js +0 -177
  263. package/dist/resolution/frameworks/java.js.map +0 -1
  264. package/dist/resolution/frameworks/laravel.d.ts +0 -13
  265. package/dist/resolution/frameworks/laravel.d.ts.map +0 -1
  266. package/dist/resolution/frameworks/laravel.js +0 -248
  267. package/dist/resolution/frameworks/laravel.js.map +0 -1
  268. package/dist/resolution/frameworks/python.d.ts +0 -10
  269. package/dist/resolution/frameworks/python.d.ts.map +0 -1
  270. package/dist/resolution/frameworks/python.js +0 -278
  271. package/dist/resolution/frameworks/python.js.map +0 -1
  272. package/dist/resolution/frameworks/react.d.ts +0 -8
  273. package/dist/resolution/frameworks/react.d.ts.map +0 -1
  274. package/dist/resolution/frameworks/react.js +0 -272
  275. package/dist/resolution/frameworks/react.js.map +0 -1
  276. package/dist/resolution/frameworks/ruby.d.ts +0 -8
  277. package/dist/resolution/frameworks/ruby.d.ts.map +0 -1
  278. package/dist/resolution/frameworks/ruby.js +0 -198
  279. package/dist/resolution/frameworks/ruby.js.map +0 -1
  280. package/dist/resolution/frameworks/rust.d.ts +0 -8
  281. package/dist/resolution/frameworks/rust.d.ts.map +0 -1
  282. package/dist/resolution/frameworks/rust.js +0 -207
  283. package/dist/resolution/frameworks/rust.js.map +0 -1
  284. package/dist/resolution/frameworks/svelte.d.ts +0 -9
  285. package/dist/resolution/frameworks/svelte.d.ts.map +0 -1
  286. package/dist/resolution/frameworks/svelte.js +0 -249
  287. package/dist/resolution/frameworks/svelte.js.map +0 -1
  288. package/dist/resolution/frameworks/swift.d.ts +0 -10
  289. package/dist/resolution/frameworks/swift.d.ts.map +0 -1
  290. package/dist/resolution/frameworks/swift.js +0 -376
  291. package/dist/resolution/frameworks/swift.js.map +0 -1
  292. package/dist/resolution/frameworks/vue.d.ts +0 -9
  293. package/dist/resolution/frameworks/vue.d.ts.map +0 -1
  294. package/dist/resolution/frameworks/vue.js +0 -306
  295. package/dist/resolution/frameworks/vue.js.map +0 -1
  296. package/dist/resolution/import-resolver.d.ts +0 -40
  297. package/dist/resolution/import-resolver.d.ts.map +0 -1
  298. package/dist/resolution/import-resolver.js +0 -663
  299. package/dist/resolution/import-resolver.js.map +0 -1
  300. package/dist/resolution/index.d.ts +0 -106
  301. package/dist/resolution/index.d.ts.map +0 -1
  302. package/dist/resolution/index.js +0 -709
  303. package/dist/resolution/index.js.map +0 -1
  304. package/dist/resolution/name-matcher.d.ts +0 -32
  305. package/dist/resolution/name-matcher.d.ts.map +0 -1
  306. package/dist/resolution/name-matcher.js +0 -384
  307. package/dist/resolution/name-matcher.js.map +0 -1
  308. package/dist/resolution/path-aliases.d.ts +0 -68
  309. package/dist/resolution/path-aliases.d.ts.map +0 -1
  310. package/dist/resolution/path-aliases.js +0 -238
  311. package/dist/resolution/path-aliases.js.map +0 -1
  312. package/dist/resolution/strip-comments.d.ts +0 -27
  313. package/dist/resolution/strip-comments.d.ts.map +0 -1
  314. package/dist/resolution/strip-comments.js +0 -441
  315. package/dist/resolution/strip-comments.js.map +0 -1
  316. package/dist/resolution/types.d.ts +0 -172
  317. package/dist/resolution/types.d.ts.map +0 -1
  318. package/dist/resolution/types.js +0 -8
  319. package/dist/resolution/types.js.map +0 -1
  320. package/dist/search/query-parser.d.ts +0 -57
  321. package/dist/search/query-parser.d.ts.map +0 -1
  322. package/dist/search/query-parser.js +0 -177
  323. package/dist/search/query-parser.js.map +0 -1
  324. package/dist/search/query-utils.d.ts +0 -53
  325. package/dist/search/query-utils.d.ts.map +0 -1
  326. package/dist/search/query-utils.js +0 -347
  327. package/dist/search/query-utils.js.map +0 -1
  328. package/dist/sync/index.d.ts +0 -13
  329. package/dist/sync/index.d.ts.map +0 -1
  330. package/dist/sync/index.js +0 -17
  331. package/dist/sync/index.js.map +0 -1
  332. package/dist/sync/watcher.d.ts +0 -81
  333. package/dist/sync/watcher.d.ts.map +0 -1
  334. package/dist/sync/watcher.js +0 -184
  335. package/dist/sync/watcher.js.map +0 -1
  336. package/dist/types.d.ts +0 -423
  337. package/dist/types.d.ts.map +0 -1
  338. package/dist/types.js +0 -256
  339. package/dist/types.js.map +0 -1
  340. package/dist/ui/glyphs.d.ts +0 -42
  341. package/dist/ui/glyphs.d.ts.map +0 -1
  342. package/dist/ui/glyphs.js +0 -78
  343. package/dist/ui/glyphs.js.map +0 -1
  344. package/dist/ui/shimmer-progress.d.ts +0 -11
  345. package/dist/ui/shimmer-progress.d.ts.map +0 -1
  346. package/dist/ui/shimmer-progress.js +0 -90
  347. package/dist/ui/shimmer-progress.js.map +0 -1
  348. package/dist/ui/shimmer-worker.d.ts +0 -2
  349. package/dist/ui/shimmer-worker.d.ts.map +0 -1
  350. package/dist/ui/shimmer-worker.js +0 -118
  351. package/dist/ui/shimmer-worker.js.map +0 -1
  352. package/dist/ui/types.d.ts +0 -17
  353. package/dist/ui/types.d.ts.map +0 -1
  354. package/dist/ui/types.js +0 -3
  355. package/dist/ui/types.js.map +0 -1
  356. package/dist/utils.d.ts +0 -205
  357. package/dist/utils.d.ts.map +0 -1
  358. package/dist/utils.js +0 -549
  359. package/dist/utils.js.map +0 -1
  360. package/scripts/local-install.sh +0 -41
  361. package/scripts/patch-tree-sitter-dart.js +0 -112
  362. package/scripts/release.sh +0 -70
@@ -1,1048 +0,0 @@
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);
253
- }
254
- else if (opts.format === 'json') {
255
- return (0, formatter_1.formatContextAsJson)(context);
256
- }
257
- return context;
258
- }
259
- /**
260
- * Find relevant subgraph for a query
261
- *
262
- * Uses hybrid search combining exact symbol lookup with semantic search:
263
- * 1. Extract potential symbol names from query
264
- * 2. Look up exact matches for those symbols (high confidence)
265
- * 3. Use semantic search for concept matching
266
- * 4. Merge results, prioritizing exact matches
267
- * 5. Traverse graph from entry points
268
- *
269
- * @param query - Natural language query
270
- * @param options - Search and traversal options
271
- * @returns Subgraph of relevant nodes and edges
272
- */
273
- async findRelevantContext(query, options = {}) {
274
- const opts = { ...DEFAULT_FIND_OPTIONS, ...options };
275
- // Start with empty subgraph
276
- const nodes = new Map();
277
- const edges = [];
278
- const roots = [];
279
- // Handle empty query - return empty subgraph
280
- if (!query || query.trim().length === 0) {
281
- return { nodes, edges, roots };
282
- }
283
- // === HYBRID SEARCH ===
284
- // Step 1: Extract potential symbol names from query
285
- const symbolsFromQuery = extractSymbolsFromQuery(query);
286
- (0, errors_1.logDebug)('Extracted symbols from query', { query, symbols: symbolsFromQuery });
287
- // Step 2: Look up exact matches for extracted symbols
288
- let exactMatches = [];
289
- if (symbolsFromQuery.length > 0) {
290
- try {
291
- // Get more results so we can apply co-location boosting before trimming
292
- exactMatches = this.queries.findNodesByExactName(symbolsFromQuery, {
293
- limit: Math.ceil(opts.searchLimit * 5),
294
- kinds: opts.nodeKinds && opts.nodeKinds.length > 0 ? opts.nodeKinds : undefined,
295
- });
296
- // Co-location boost: when multiple extracted symbols appear in the same file,
297
- // those results are much more likely to be what the user is looking for.
298
- // E.g., "scrapeLoop" + "run" both in scrape/scrape.go → boost both.
299
- if (exactMatches.length > 1) {
300
- // Build a map of files → how many distinct symbol names matched in that file
301
- const fileSymbolCounts = new Map();
302
- for (const r of exactMatches) {
303
- const names = fileSymbolCounts.get(r.node.filePath) || new Set();
304
- names.add(r.node.name.toLowerCase());
305
- fileSymbolCounts.set(r.node.filePath, names);
306
- }
307
- // Boost results in files where multiple query symbols co-occur
308
- exactMatches = exactMatches.map(r => {
309
- const symbolCount = fileSymbolCounts.get(r.node.filePath)?.size || 1;
310
- return {
311
- ...r,
312
- score: symbolCount > 1 ? r.score + (symbolCount - 1) * 20 : r.score,
313
- };
314
- });
315
- exactMatches.sort((a, b) => b.score - a.score);
316
- }
317
- // Trim back to reasonable size
318
- exactMatches = exactMatches.slice(0, Math.ceil(opts.searchLimit * 2));
319
- (0, errors_1.logDebug)('Exact symbol matches', { count: exactMatches.length });
320
- }
321
- catch (error) {
322
- (0, errors_1.logDebug)('Exact symbol lookup failed', { error: String(error) });
323
- }
324
- }
325
- // Step 2b: Search for extracted symbols as definition (class/interface) prefixes.
326
- // When the user writes "REST", "bulk", or "allocation", they usually mean classes
327
- // like RestController, BulkRequest, AllocationService — not nodes named exactly that.
328
- // Also tries stem variants: "caching" → "cache" finds Cache, CacheBuilder.
329
- if (symbolsFromQuery.length > 0) {
330
- const definitionKinds = ['class', 'interface', 'struct', 'trait',
331
- 'protocol', 'enum', 'type_alias'];
332
- // Expand symbols with stem variants for broader definition matching
333
- const expandedSymbols = new Set(symbolsFromQuery);
334
- for (const sym of symbolsFromQuery) {
335
- for (const variant of (0, query_utils_1.getStemVariants)(sym)) {
336
- expandedSymbols.add(variant);
337
- }
338
- }
339
- for (const sym of expandedSymbols) {
340
- // Title-case the symbol: "REST" → "Rest", "bulk" → "Bulk", "allocation" → "Allocation"
341
- const titleCased = sym.charAt(0).toUpperCase() + sym.slice(1).toLowerCase();
342
- if (titleCased === sym)
343
- continue; // already title-case (e.g., "Engine") — handled by exact match
344
- // Fetch more results since popular prefixes have many matches
345
- const prefixResults = this.queries.searchNodes(titleCased, {
346
- limit: 30,
347
- kinds: definitionKinds,
348
- });
349
- const matched = [];
350
- for (const r of prefixResults) {
351
- if (r.node.name.toLowerCase().startsWith(titleCased.toLowerCase())) {
352
- // Favor shorter names: "AllocationService" (18 chars) over
353
- // "AllocationBalancingRoundMetrics" (31 chars). Core classes tend
354
- // to have concise names; test/helper classes are verbose.
355
- const brevityBonus = Math.max(0, 10 - (r.node.name.length - titleCased.length) / 3);
356
- matched.push({ ...r, score: r.score + 15 + brevityBonus });
357
- }
358
- }
359
- matched.sort((a, b) => b.score - a.score);
360
- for (const r of matched.slice(0, Math.ceil(opts.searchLimit))) {
361
- const existing = exactMatches.find(e => e.node.id === r.node.id);
362
- if (!existing) {
363
- exactMatches.push(r);
364
- }
365
- }
366
- }
367
- exactMatches.sort((a, b) => b.score - a.score);
368
- exactMatches = exactMatches.slice(0, Math.ceil(opts.searchLimit * 3));
369
- }
370
- // Step 3: Run text search for natural language term matching
371
- // This catches file-name and node-name matches that semantic search may miss,
372
- // which is critical for template-heavy codebases (e.g., Liquid/Shopify themes)
373
- // where file names are the primary identifiers.
374
- let textResults = [];
375
- try {
376
- const searchTerms = (0, query_utils_1.extractSearchTerms)(query);
377
- if (searchTerms.length > 0) {
378
- // Search each term individually to get broader coverage,
379
- // then boost results that match multiple terms
380
- const termResultsMap = new Map();
381
- // When no explicit kind filter is set, exclude imports — they flood FTS
382
- // results with qualified name matches (e.g., "REST" matches 445K import paths)
383
- // but are almost never what exploration queries want.
384
- const searchKinds = opts.nodeKinds && opts.nodeKinds.length > 0
385
- ? opts.nodeKinds
386
- : ['file', 'module', 'class', 'struct', 'interface', 'trait', 'protocol',
387
- 'function', 'method', 'property', 'field', 'variable', 'constant',
388
- 'enum', 'enum_member', 'type_alias', 'namespace', 'export',
389
- 'route', 'component'];
390
- for (const term of searchTerms) {
391
- const termResults = this.queries.searchNodes(term, {
392
- limit: opts.searchLimit * 2,
393
- kinds: searchKinds,
394
- });
395
- for (const r of termResults) {
396
- const existing = termResultsMap.get(r.node.id);
397
- if (existing) {
398
- existing.termHits++;
399
- existing.result.score = Math.max(existing.result.score, r.score);
400
- }
401
- else {
402
- termResultsMap.set(r.node.id, { result: r, termHits: 1 });
403
- }
404
- }
405
- }
406
- // Boost results matching multiple terms and sort
407
- textResults = Array.from(termResultsMap.values())
408
- .map(({ result, termHits }) => ({
409
- ...result,
410
- score: result.score + (termHits - 1) * 5,
411
- }))
412
- .sort((a, b) => b.score - a.score)
413
- .slice(0, opts.searchLimit * 2);
414
- }
415
- (0, errors_1.logDebug)('Text search results', { count: textResults.length });
416
- }
417
- catch (error) {
418
- (0, errors_1.logDebug)('Text search failed', { query, error: String(error) });
419
- }
420
- // Step 4: Merge results, taking the max score when duplicates appear
421
- // across search channels. Exact matches may have lower scores than FTS
422
- // results for the same node — use the best score from any channel.
423
- const resultById = new Map();
424
- let searchResults = [];
425
- // Add exact matches first
426
- for (const result of exactMatches) {
427
- const existing = resultById.get(result.node.id);
428
- if (existing) {
429
- existing.score = Math.max(existing.score, result.score);
430
- }
431
- else {
432
- resultById.set(result.node.id, result);
433
- searchResults.push(result);
434
- }
435
- }
436
- // Add text search results, upgrading scores for duplicates
437
- for (const result of textResults) {
438
- const existing = resultById.get(result.node.id);
439
- if (existing) {
440
- existing.score = Math.max(existing.score, result.score);
441
- }
442
- else {
443
- resultById.set(result.node.id, result);
444
- searchResults.push(result);
445
- }
446
- }
447
- const queryLower = query.toLowerCase();
448
- const isTestQuery = queryLower.includes('test') || queryLower.includes('spec');
449
- // Deprioritize test files early so they don't take multi-term boost slots
450
- if (!isTestQuery) {
451
- for (const result of searchResults) {
452
- if ((0, query_utils_1.isTestFile)(result.node.filePath)) {
453
- result.score *= 0.3;
454
- }
455
- }
456
- }
457
- // Step 5a: Multi-term co-occurrence re-ranking (applied BEFORE truncation).
458
- // For multi-word queries like "search execution from request to shard",
459
- // nodes matching 2+ query terms in their name or path are far more relevant
460
- // than nodes matching just one generic term. Without this, "ExecutionUtils"
461
- // (matches only "execution") fills budget slots meant for "ShardSearchRequest"
462
- // (matches "shard" + "search" + "request").
463
- const queryTermsForBoost = (0, query_utils_1.extractSearchTerms)(query);
464
- if (queryTermsForBoost.length >= 2) {
465
- // Group terms that are substrings of each other (stem variants of the same
466
- // root word). "indexed", "indexe", "index" should count as ONE concept match,
467
- // not three. Without this, stem variants inflate matchCount and give false
468
- // multi-term boosts to symbols matching one root word multiple times.
469
- const termGroups = [];
470
- const sorted = [...queryTermsForBoost].sort((a, b) => b.length - a.length);
471
- const assigned = new Set();
472
- for (const term of sorted) {
473
- if (assigned.has(term))
474
- continue;
475
- const group = [term];
476
- assigned.add(term);
477
- for (const other of sorted) {
478
- if (assigned.has(other))
479
- continue;
480
- if (term.includes(other) || other.includes(term)) {
481
- group.push(other);
482
- assigned.add(other);
483
- }
484
- }
485
- termGroups.push(group);
486
- }
487
- // Build a set of exact-match node IDs so we can exempt them from dampening.
488
- // When the query is "LiveEditMode DevServerPreview", these are specific
489
- // symbols the user asked for — dampening them because they only match 1
490
- // term group is counter-productive.
491
- const exactMatchIds = new Set(exactMatches.map(r => r.node.id));
492
- for (const result of searchResults) {
493
- // Check term matches in name (substring) and path DIRECTORIES (exact).
494
- // Directory segments must match exactly — "search" matches directory
495
- // "search/" but NOT "elasticsearch/". The class name is checked
496
- // separately via substring match on the node name.
497
- const nameLower = result.node.name.toLowerCase();
498
- const dirSegments = path.dirname(result.node.filePath).toLowerCase().split('/');
499
- let matchCount = 0;
500
- for (const group of termGroups) {
501
- const groupMatches = group.some(term => {
502
- const inName = nameLower.includes(term);
503
- const inDir = dirSegments.some(seg => seg === term);
504
- return inName || inDir;
505
- });
506
- if (groupMatches)
507
- matchCount++;
508
- }
509
- if (matchCount >= 2) {
510
- // Multiplicative boost — 2 terms → 2x, 3 terms → 2.5x
511
- result.score *= 1 + matchCount * 0.5;
512
- }
513
- else if (!exactMatchIds.has(result.node.id)) {
514
- // Mild dampen for single-term matches — they might be generic
515
- // but could also be the right result (e.g., "Protocol" class for an IPC query).
516
- // Exempt exact name matches: they are specific symbols the user queried for.
517
- result.score *= 0.6;
518
- }
519
- }
520
- searchResults.sort((a, b) => b.score - a.score);
521
- }
522
- // Step 5b: CamelCase-boundary matching via LIKE query.
523
- // FTS can't find "Search" inside "TransportSearchAction" (one FTS token).
524
- // LIKE reliably finds these substring matches. Results are appended with
525
- // guaranteed slots so they don't compete with higher-scoring prefix matches.
526
- if (symbolsFromQuery.length > 0) {
527
- const camelDefinitionKinds = ['class', 'interface', 'struct', 'trait',
528
- 'protocol', 'enum', 'type_alias'];
529
- const camelSearchedTerms = new Set();
530
- const searchIdSet = new Set(searchResults.map(r => r.node.id));
531
- // Track per-node term hits for multi-term boosting
532
- const camelNodeTerms = new Map();
533
- const maxCamelPerTerm = Math.ceil(opts.searchLimit / 2);
534
- for (const sym of symbolsFromQuery) {
535
- const titleCased = sym.charAt(0).toUpperCase() + sym.slice(1).toLowerCase();
536
- if (titleCased.length < 3)
537
- continue;
538
- const termKey = titleCased.toLowerCase();
539
- if (camelSearchedTerms.has(termKey))
540
- continue;
541
- camelSearchedTerms.add(termKey);
542
- // Fetch a large batch — popular terms like "Search" in Elasticsearch
543
- // have hundreds of substring matches. The LIKE scan cost is the same
544
- // regardless of LIMIT (SQLite scans all matches to sort), so we fetch
545
- // generously and let path-relevance scoring pick the best ones.
546
- const likeResults = this.queries.findNodesByNameSubstring(titleCased, {
547
- limit: 200,
548
- kinds: camelDefinitionKinds,
549
- excludePrefix: true,
550
- });
551
- // Filter to CamelCase boundaries, score by path relevance, and take top N
552
- const termCandidates = [];
553
- for (const r of likeResults) {
554
- const name = r.node.name;
555
- const idx = name.indexOf(titleCased);
556
- if (idx <= 0)
557
- continue;
558
- // Accept CamelCase boundary (lowercase before match) OR
559
- // acronym boundary (uppercase before match, e.g., RPCProtocol)
560
- if (!/[a-zA-Z]/.test(name.charAt(idx - 1)))
561
- continue;
562
- if (searchIdSet.has(r.node.id))
563
- continue;
564
- if ((0, query_utils_1.isTestFile)(r.node.filePath) && !isTestQuery)
565
- continue;
566
- const pathScore = (0, query_utils_1.scorePathRelevance)(r.node.filePath, query);
567
- const brevityBonus = Math.max(0, 6 - (name.length - titleCased.length) / 4);
568
- termCandidates.push({ node: r.node, score: 8 + brevityBonus + pathScore });
569
- }
570
- termCandidates.sort((a, b) => b.score - a.score);
571
- // Widen the per-term pool for accumulation so multi-term co-occurrences
572
- // can be discovered. A class matching 3 query terms at CamelCase boundaries
573
- // is far more relevant than one matching just 1, but it needs to survive
574
- // the per-term cut for EACH term to accumulate its count.
575
- const accumPerTerm = maxCamelPerTerm * 4;
576
- for (const r of termCandidates.slice(0, accumPerTerm)) {
577
- const existing = camelNodeTerms.get(r.node.id);
578
- if (existing) {
579
- existing.termCount++;
580
- }
581
- else {
582
- camelNodeTerms.set(r.node.id, {
583
- result: r,
584
- termCount: 1,
585
- });
586
- }
587
- }
588
- }
589
- // Append CamelCase matches with multi-term boost.
590
- // These are structurally important (class names containing query terms at
591
- // CamelCase boundaries) but score much lower than FTS results. Scale their
592
- // scores up so multi-term CamelCase matches can compete with FTS results.
593
- const camelResults = [];
594
- for (const [, info] of camelNodeTerms) {
595
- // Multi-term CamelCase matches are extremely relevant — a class matching
596
- // 3+ query terms in its name (e.g., ExtensionHostProcess) is almost
597
- // certainly what the user wants. Scale aggressively.
598
- info.result.score = info.result.score * (1 + info.termCount) + (info.termCount - 1) * 30;
599
- camelResults.push(info.result);
600
- }
601
- camelResults.sort((a, b) => b.score - a.score);
602
- const maxCamelTotal = opts.searchLimit;
603
- for (const r of camelResults.slice(0, maxCamelTotal)) {
604
- searchResults.push(r);
605
- searchIdSet.add(r.node.id);
606
- }
607
- // Step 5c: Compound term matching — find classes whose name contains 2+
608
- // query terms at ANY position (not just CamelCase boundaries).
609
- // The CamelCase step above requires idx > 0, which misses classes that
610
- // START with a query term (e.g., "SearchShardsRequest" starts with "Search").
611
- // For multi-word queries, a class matching multiple query terms in its name
612
- // is almost certainly relevant regardless of position.
613
- if (symbolsFromQuery.length >= 2) {
614
- // Collect ALL LIKE results per term (reusing findNodesByNameSubstring)
615
- // but without the CamelCase boundary or prefix exclusion filters.
616
- const compoundTermMap = new Map();
617
- for (const sym of symbolsFromQuery) {
618
- const titleCased = sym.charAt(0).toUpperCase() + sym.slice(1).toLowerCase();
619
- if (titleCased.length < 3)
620
- continue;
621
- const likeResults = this.queries.findNodesByNameSubstring(titleCased, {
622
- limit: 200,
623
- kinds: camelDefinitionKinds,
624
- excludePrefix: false,
625
- });
626
- for (const r of likeResults) {
627
- if (searchIdSet.has(r.node.id))
628
- continue;
629
- if ((0, query_utils_1.isTestFile)(r.node.filePath) && !isTestQuery)
630
- continue;
631
- const entry = compoundTermMap.get(r.node.id);
632
- if (entry) {
633
- entry.terms.add(titleCased);
634
- }
635
- else {
636
- compoundTermMap.set(r.node.id, { node: r.node, terms: new Set([titleCased]) });
637
- }
638
- }
639
- }
640
- // Keep only nodes matching 2+ distinct terms
641
- const compoundResults = [];
642
- for (const [, entry] of compoundTermMap) {
643
- if (entry.terms.size >= 2) {
644
- const pathScore = (0, query_utils_1.scorePathRelevance)(entry.node.filePath, query);
645
- const brevityBonus = Math.max(0, 6 - entry.node.name.length / 8);
646
- compoundResults.push({
647
- node: entry.node,
648
- score: 10 + (entry.terms.size - 1) * 20 + pathScore + brevityBonus,
649
- });
650
- }
651
- }
652
- compoundResults.sort((a, b) => b.score - a.score);
653
- const maxCompound = Math.ceil(opts.searchLimit / 2);
654
- for (const r of compoundResults.slice(0, maxCompound)) {
655
- searchResults.push(r);
656
- searchIdSet.add(r.node.id);
657
- }
658
- }
659
- }
660
- // Final sort and truncation — all search channels (exact, text, CamelCase,
661
- // compound) have now contributed. Sort by score so multi-term matches from
662
- // later steps can outrank dampened single-term matches from earlier steps.
663
- searchResults.sort((a, b) => b.score - a.score);
664
- searchResults = searchResults.slice(0, opts.searchLimit * 3);
665
- // Filter by minimum score
666
- let filteredResults = searchResults.filter((r) => r.score >= opts.minScore);
667
- // Resolve imports/exports to their actual definitions
668
- // If someone searches "terminal" and finds `import { TerminalPanel }`,
669
- // they want the TerminalPanel class, not the import statement
670
- filteredResults = this.resolveImportsToDefinitions(filteredResults);
671
- // Cap entry points so traversal budget isn't spread too thin.
672
- // With 36 entry points and maxNodes=120, each gets only 3 nodes — useless.
673
- // Cap to searchLimit so each entry point gets a meaningful traversal budget.
674
- if (filteredResults.length > opts.searchLimit) {
675
- filteredResults = filteredResults.slice(0, opts.searchLimit);
676
- }
677
- // Add entry points to subgraph
678
- for (const result of filteredResults) {
679
- nodes.set(result.node.id, result.node);
680
- roots.push(result.node.id);
681
- }
682
- // Expand type hierarchy for class/interface entry points.
683
- // BFS often exhausts its per-entry-point budget on contained methods
684
- // before reaching extends/implements neighbors. This dedicated step
685
- // ensures subclasses and superclasses always appear in results.
686
- // Budget: up to maxNodes/4 hierarchy nodes to avoid flooding.
687
- const typeHierarchyKinds = new Set(['class', 'interface', 'struct', 'trait', 'protocol']);
688
- const maxHierarchyNodes = Math.ceil(opts.maxNodes / 4);
689
- let hierarchyNodesAdded = 0;
690
- for (const result of filteredResults) {
691
- if (hierarchyNodesAdded >= maxHierarchyNodes)
692
- break;
693
- if (typeHierarchyKinds.has(result.node.kind)) {
694
- const hierarchy = this.traverser.getTypeHierarchy(result.node.id);
695
- for (const [id, node] of hierarchy.nodes) {
696
- if (!nodes.has(id)) {
697
- nodes.set(id, node);
698
- hierarchyNodesAdded++;
699
- }
700
- }
701
- for (const edge of hierarchy.edges) {
702
- const exists = edges.some((e) => e.source === edge.source && e.target === edge.target && e.kind === edge.kind);
703
- if (!exists) {
704
- edges.push(edge);
705
- }
706
- }
707
- }
708
- }
709
- // Pass 2: expand hierarchy of newly-discovered parent types to find siblings.
710
- // E.g., InternalEngine → Engine (parent, from pass 1) → ReadOnlyEngine (sibling).
711
- if (hierarchyNodesAdded > 0) {
712
- const pass2Candidates = [...nodes.values()].filter(n => typeHierarchyKinds.has(n.kind) && !roots.includes(n.id));
713
- for (const candidate of pass2Candidates) {
714
- if (hierarchyNodesAdded >= maxHierarchyNodes)
715
- break;
716
- const siblingHierarchy = this.traverser.getTypeHierarchy(candidate.id);
717
- for (const [id, node] of siblingHierarchy.nodes) {
718
- if (!nodes.has(id) && hierarchyNodesAdded < maxHierarchyNodes) {
719
- nodes.set(id, node);
720
- hierarchyNodesAdded++;
721
- }
722
- }
723
- for (const edge of siblingHierarchy.edges) {
724
- if (nodes.has(edge.source) && nodes.has(edge.target)) {
725
- const exists = edges.some((e) => e.source === edge.source && e.target === edge.target && e.kind === edge.kind);
726
- if (!exists) {
727
- edges.push(edge);
728
- }
729
- }
730
- }
731
- }
732
- }
733
- // Traverse from each entry point
734
- for (const result of filteredResults) {
735
- const traversalResult = this.traverser.traverseBFS(result.node.id, {
736
- maxDepth: opts.traversalDepth,
737
- edgeKinds: opts.edgeKinds && opts.edgeKinds.length > 0 ? opts.edgeKinds : undefined,
738
- nodeKinds: opts.nodeKinds && opts.nodeKinds.length > 0 ? opts.nodeKinds : undefined,
739
- direction: 'both',
740
- limit: Math.ceil(opts.maxNodes / Math.max(1, filteredResults.length)),
741
- });
742
- // Merge nodes
743
- for (const [id, node] of traversalResult.nodes) {
744
- if (!nodes.has(id)) {
745
- nodes.set(id, node);
746
- }
747
- }
748
- // Merge edges (avoid duplicates)
749
- for (const edge of traversalResult.edges) {
750
- const exists = edges.some((e) => e.source === edge.source && e.target === edge.target && e.kind === edge.kind);
751
- if (!exists) {
752
- edges.push(edge);
753
- }
754
- }
755
- }
756
- // Trim to max nodes if needed
757
- let finalNodes = nodes;
758
- let finalEdges = edges;
759
- if (nodes.size > opts.maxNodes) {
760
- // Prioritize entry points and their direct neighbors
761
- const priorityIds = new Set(roots);
762
- for (const edge of edges) {
763
- if (priorityIds.has(edge.source)) {
764
- priorityIds.add(edge.target);
765
- }
766
- if (priorityIds.has(edge.target)) {
767
- priorityIds.add(edge.source);
768
- }
769
- }
770
- // Keep priority nodes, then fill remaining slots
771
- finalNodes = new Map();
772
- for (const id of priorityIds) {
773
- const node = nodes.get(id);
774
- if (node && finalNodes.size < opts.maxNodes) {
775
- finalNodes.set(id, node);
776
- }
777
- }
778
- // Fill remaining from other nodes
779
- for (const [id, node] of nodes) {
780
- if (finalNodes.size >= opts.maxNodes)
781
- break;
782
- if (!finalNodes.has(id)) {
783
- finalNodes.set(id, node);
784
- }
785
- }
786
- // Filter edges to only include kept nodes
787
- finalEdges = edges.filter((e) => finalNodes.has(e.source) && finalNodes.has(e.target));
788
- }
789
- // Per-file diversity cap: prevent any single file from monopolizing the
790
- // node budget. When BFS traverses from a method, it follows `contains`
791
- // to the parent class, then back down to all sibling methods. With
792
- // multiple entry points in the same class, one file can consume 30-40%
793
- // of maxNodes. Cap each file to ~20% to ensure cross-file diversity.
794
- const maxPerFile = Math.max(5, Math.ceil(opts.maxNodes * 0.2));
795
- const fileCounts = new Map();
796
- for (const [id, node] of finalNodes) {
797
- const ids = fileCounts.get(node.filePath) || [];
798
- ids.push(id);
799
- fileCounts.set(node.filePath, ids);
800
- }
801
- const rootSet = new Set(roots);
802
- for (const [, nodeIds] of fileCounts) {
803
- if (nodeIds.length <= maxPerFile)
804
- continue;
805
- // Sort: entry points first, then classes/interfaces, then others
806
- const kindPriority = {
807
- class: 3, interface: 3, struct: 3, trait: 3, protocol: 3, enum: 3,
808
- method: 1, function: 1, property: 0, field: 0, variable: 0,
809
- };
810
- nodeIds.sort((a, b) => {
811
- const aRoot = rootSet.has(a) ? 10 : 0;
812
- const bRoot = rootSet.has(b) ? 10 : 0;
813
- const aKind = kindPriority[finalNodes.get(a).kind] ?? 0;
814
- const bKind = kindPriority[finalNodes.get(b).kind] ?? 0;
815
- return (bRoot + bKind) - (aRoot + aKind);
816
- });
817
- // Remove excess nodes (keep the highest-priority ones)
818
- for (const id of nodeIds.slice(maxPerFile)) {
819
- finalNodes.delete(id);
820
- }
821
- }
822
- // Non-production node cap: limit test/sample/integration/example files to
823
- // at most 15% of the budget. Many codebases have dozens of near-identical
824
- // test implementations (e.g., 6 Guard classes in integration tests) that
825
- // individually survive score dampening but collectively flood the result.
826
- // Test entry points are NOT exempt — they should be evicted too.
827
- if (!isTestQuery) {
828
- const maxNonProd = Math.max(3, Math.ceil(opts.maxNodes * 0.15));
829
- const nonProdIds = [];
830
- for (const [id, node] of finalNodes) {
831
- if ((0, query_utils_1.isTestFile)(node.filePath)) {
832
- nonProdIds.push(id);
833
- }
834
- }
835
- if (nonProdIds.length > maxNonProd) {
836
- for (const id of nonProdIds.slice(maxNonProd)) {
837
- finalNodes.delete(id);
838
- // Also remove from roots — test file entry points shouldn't anchor results
839
- const rootIdx = roots.indexOf(id);
840
- if (rootIdx !== -1)
841
- roots.splice(rootIdx, 1);
842
- }
843
- }
844
- }
845
- // Re-filter edges after per-file and non-production caps
846
- finalEdges = finalEdges.filter((e) => finalNodes.has(e.source) && finalNodes.has(e.target));
847
- // Edge recovery: BFS with many entry points leaves most nodes disconnected.
848
- // Discover edges between already-selected nodes to recover connectivity.
849
- const recoveryKinds = ['calls', 'extends', 'implements', 'references', 'overrides'];
850
- const recoveredEdges = this.queries.findEdgesBetweenNodes([...finalNodes.keys()], recoveryKinds);
851
- const existingEdgeKeys = new Set(finalEdges.map((e) => `${e.source}:${e.target}:${e.kind}`));
852
- for (const edge of recoveredEdges) {
853
- const key = `${edge.source}:${edge.target}:${edge.kind}`;
854
- if (!existingEdgeKeys.has(key)) {
855
- finalEdges.push(edge);
856
- existingEdgeKeys.add(key);
857
- }
858
- }
859
- return { nodes: finalNodes, edges: finalEdges, roots };
860
- }
861
- /**
862
- * Get the source code for a node
863
- *
864
- * Reads the file and extracts the code between startLine and endLine.
865
- *
866
- * @param nodeId - ID of the node
867
- * @returns Code string or null if not found
868
- */
869
- async getCode(nodeId) {
870
- const node = this.queries.getNodeById(nodeId);
871
- if (!node) {
872
- return null;
873
- }
874
- return this.extractNodeCode(node);
875
- }
876
- /**
877
- * Extract code from a node's source file
878
- */
879
- async extractNodeCode(node) {
880
- const filePath = (0, utils_1.validatePathWithinRoot)(this.projectRoot, node.filePath);
881
- if (!filePath || !fs.existsSync(filePath)) {
882
- return null;
883
- }
884
- try {
885
- const content = fs.readFileSync(filePath, 'utf-8');
886
- const lines = content.split('\n');
887
- // Extract lines (1-indexed to 0-indexed)
888
- const startIdx = Math.max(0, node.startLine - 1);
889
- const endIdx = Math.min(lines.length, node.endLine);
890
- return lines.slice(startIdx, endIdx).join('\n');
891
- }
892
- catch (error) {
893
- (0, errors_1.logDebug)('Failed to extract code from node', { nodeId: node.id, filePath: node.filePath, error: String(error) });
894
- return null;
895
- }
896
- }
897
- /**
898
- * Get entry points from a subgraph (the root nodes)
899
- */
900
- getEntryPoints(subgraph) {
901
- return subgraph.roots
902
- .map((id) => subgraph.nodes.get(id))
903
- .filter((n) => n !== undefined);
904
- }
905
- /**
906
- * Extract code blocks for key nodes in the subgraph
907
- */
908
- async extractCodeBlocks(subgraph, maxBlocks, maxBlockSize) {
909
- const blocks = [];
910
- // Prioritize entry points, then functions/methods
911
- const priorityNodes = [];
912
- // First: entry points
913
- for (const id of subgraph.roots) {
914
- const node = subgraph.nodes.get(id);
915
- if (node) {
916
- priorityNodes.push(node);
917
- }
918
- }
919
- // Then: functions and methods
920
- for (const node of subgraph.nodes.values()) {
921
- if (!subgraph.roots.includes(node.id)) {
922
- if (node.kind === 'function' || node.kind === 'method') {
923
- priorityNodes.push(node);
924
- }
925
- }
926
- }
927
- // Then: classes
928
- for (const node of subgraph.nodes.values()) {
929
- if (!subgraph.roots.includes(node.id)) {
930
- if (node.kind === 'class') {
931
- priorityNodes.push(node);
932
- }
933
- }
934
- }
935
- // Extract code for priority nodes
936
- for (const node of priorityNodes) {
937
- if (blocks.length >= maxBlocks)
938
- break;
939
- const code = await this.extractNodeCode(node);
940
- if (code) {
941
- // Truncate if too long
942
- const truncated = code.length > maxBlockSize
943
- ? code.slice(0, maxBlockSize) + '\n// ... truncated ...'
944
- : code;
945
- blocks.push({
946
- content: truncated,
947
- filePath: node.filePath,
948
- startLine: node.startLine,
949
- endLine: node.endLine,
950
- language: node.language,
951
- node,
952
- });
953
- }
954
- }
955
- return blocks;
956
- }
957
- /**
958
- * Get unique files from a subgraph
959
- */
960
- getRelatedFiles(subgraph) {
961
- const files = new Set();
962
- for (const node of subgraph.nodes.values()) {
963
- files.add(node.filePath);
964
- }
965
- return Array.from(files).sort();
966
- }
967
- /**
968
- * Generate a summary of the context
969
- */
970
- generateSummary(_query, subgraph, entryPoints) {
971
- const nodeCount = subgraph.nodes.size;
972
- const edgeCount = subgraph.edges.length;
973
- const files = this.getRelatedFiles(subgraph);
974
- const entryPointNames = entryPoints
975
- .slice(0, 3)
976
- .map((n) => n.name)
977
- .join(', ');
978
- const remaining = entryPoints.length > 3 ? ` and ${entryPoints.length - 3} more` : '';
979
- return `Found ${nodeCount} relevant code symbols across ${files.length} files. ` +
980
- `Key entry points: ${entryPointNames}${remaining}. ` +
981
- `${edgeCount} relationships identified.`;
982
- }
983
- /**
984
- * Resolve import/export nodes to their actual definitions
985
- *
986
- * When search returns `import { TerminalPanel }`, users want the TerminalPanel
987
- * class definition, not the import statement. This follows the `imports` edge
988
- * to find and return the actual definition instead.
989
- *
990
- * @param results - Search results that may include import/export nodes
991
- * @returns Results with imports resolved to definitions where possible
992
- */
993
- resolveImportsToDefinitions(results) {
994
- const resolved = [];
995
- const seenIds = new Set();
996
- for (const result of results) {
997
- const { node, score } = result;
998
- // If it's not an import/export, keep it as-is
999
- if (node.kind !== 'import' && node.kind !== 'export') {
1000
- if (!seenIds.has(node.id)) {
1001
- seenIds.add(node.id);
1002
- resolved.push(result);
1003
- }
1004
- continue;
1005
- }
1006
- // For imports/exports, try to find what they reference
1007
- // Imports have outgoing 'imports' edges to the definition
1008
- // Exports have outgoing 'exports' edges to the definition
1009
- const edgeKind = node.kind === 'import' ? 'imports' : 'exports';
1010
- const outgoingEdges = this.queries.getOutgoingEdges(node.id, [edgeKind]);
1011
- let foundDefinition = false;
1012
- for (const edge of outgoingEdges) {
1013
- const targetNode = this.queries.getNodeById(edge.target);
1014
- if (targetNode && !seenIds.has(targetNode.id)) {
1015
- // Found the definition - use it instead of the import
1016
- seenIds.add(targetNode.id);
1017
- resolved.push({
1018
- node: targetNode,
1019
- score: score, // Preserve the original score
1020
- });
1021
- foundDefinition = true;
1022
- (0, errors_1.logDebug)('Resolved import to definition', {
1023
- import: node.name,
1024
- definition: targetNode.name,
1025
- kind: targetNode.kind,
1026
- });
1027
- }
1028
- }
1029
- // If we couldn't resolve the import, skip it (it's low-value on its own)
1030
- if (!foundDefinition) {
1031
- (0, errors_1.logDebug)('Skipping unresolved import', { name: node.name, file: node.filePath });
1032
- }
1033
- }
1034
- return resolved;
1035
- }
1036
- }
1037
- exports.ContextBuilder = ContextBuilder;
1038
- /**
1039
- * Create a context builder
1040
- */
1041
- function createContextBuilder(projectRoot, queries, traverser) {
1042
- return new ContextBuilder(projectRoot, queries, traverser);
1043
- }
1044
- // Re-export formatter
1045
- var formatter_2 = require("./formatter");
1046
- Object.defineProperty(exports, "formatContextAsMarkdown", { enumerable: true, get: function () { return formatter_2.formatContextAsMarkdown; } });
1047
- Object.defineProperty(exports, "formatContextAsJson", { enumerable: true, get: function () { return formatter_2.formatContextAsJson; } });
1048
- //# sourceMappingURL=index.js.map