@lzehrung/codegraph 2.1.1 → 2.2.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 (494) hide show
  1. package/README.md +2 -2
  2. package/codegraph-skill/codegraph/SKILL.md +25 -7
  3. package/dist/agent/artifact.d.ts.map +1 -1
  4. package/dist/agent/artifact.js +105 -14
  5. package/dist/agent/artifact.js.map +1 -1
  6. package/dist/agent/explain.d.ts +3 -0
  7. package/dist/agent/explain.d.ts.map +1 -1
  8. package/dist/agent/explain.js +8 -0
  9. package/dist/agent/explain.js.map +1 -1
  10. package/dist/agent/explore.d.ts.map +1 -1
  11. package/dist/agent/explore.js +8 -1
  12. package/dist/agent/explore.js.map +1 -1
  13. package/dist/agent/handles.d.ts.map +1 -1
  14. package/dist/agent/handles.js +2 -8
  15. package/dist/agent/handles.js.map +1 -1
  16. package/dist/agent/orient.js +2 -16
  17. package/dist/agent/orient.js.map +1 -1
  18. package/dist/agent/packet.d.ts.map +1 -1
  19. package/dist/agent/packet.js +5 -12
  20. package/dist/agent/packet.js.map +1 -1
  21. package/dist/agent/query-index/content.d.ts +1 -1
  22. package/dist/agent/query-index/content.js +4 -4
  23. package/dist/agent/query-index/content.js.map +1 -1
  24. package/dist/agent/query-index/store.d.ts +5 -4
  25. package/dist/agent/query-index/store.d.ts.map +1 -1
  26. package/dist/agent/query-index/store.js +56 -18
  27. package/dist/agent/query-index/store.js.map +1 -1
  28. package/dist/agent/query-index/update.d.ts.map +1 -1
  29. package/dist/agent/query-index/update.js +24 -9
  30. package/dist/agent/query-index/update.js.map +1 -1
  31. package/dist/agent/renamePreview.d.ts.map +1 -1
  32. package/dist/agent/renamePreview.js +51 -2
  33. package/dist/agent/renamePreview.js.map +1 -1
  34. package/dist/agent/search.d.ts +3 -1
  35. package/dist/agent/search.d.ts.map +1 -1
  36. package/dist/agent/search.js +64 -18
  37. package/dist/agent/search.js.map +1 -1
  38. package/dist/agent/session.d.ts.map +1 -1
  39. package/dist/agent/session.js +4 -4
  40. package/dist/agent/session.js.map +1 -1
  41. package/dist/agent-tools.js +6 -6
  42. package/dist/agent-tools.js.map +1 -1
  43. package/dist/bin/cli.js +9242 -6344
  44. package/dist/bin/queryIndexWorker.js +437 -86
  45. package/dist/bin/rawQueryWorker.js +26 -2
  46. package/dist/chunking/chunkSplit.js +0 -15
  47. package/dist/chunking/chunkSplit.js.map +1 -1
  48. package/dist/cli/callHierarchy.d.ts.map +1 -1
  49. package/dist/cli/callHierarchy.js +9 -2
  50. package/dist/cli/callHierarchy.js.map +1 -1
  51. package/dist/cli/commandCatalog.d.ts.map +1 -1
  52. package/dist/cli/commandCatalog.js +1 -0
  53. package/dist/cli/commandCatalog.js.map +1 -1
  54. package/dist/cli/commandTable.d.ts.map +1 -1
  55. package/dist/cli/commandTable.js +18 -1
  56. package/dist/cli/commandTable.js.map +1 -1
  57. package/dist/cli/compileCache.d.ts +5 -0
  58. package/dist/cli/compileCache.d.ts.map +1 -1
  59. package/dist/cli/compileCache.js +18 -0
  60. package/dist/cli/compileCache.js.map +1 -1
  61. package/dist/cli/context.d.ts.map +1 -1
  62. package/dist/cli/context.js +0 -1
  63. package/dist/cli/context.js.map +1 -1
  64. package/dist/cli/graph.d.ts.map +1 -1
  65. package/dist/cli/graph.js +52 -16
  66. package/dist/cli/graph.js.map +1 -1
  67. package/dist/cli/grep.d.ts +1 -1
  68. package/dist/cli/grep.d.ts.map +1 -1
  69. package/dist/cli/grep.js +14 -4
  70. package/dist/cli/grep.js.map +1 -1
  71. package/dist/cli/help.d.ts +2 -1
  72. package/dist/cli/help.d.ts.map +1 -1
  73. package/dist/cli/help.js +23 -2
  74. package/dist/cli/help.js.map +1 -1
  75. package/dist/cli/indexPolicy.d.ts.map +1 -1
  76. package/dist/cli/indexPolicy.js +1 -0
  77. package/dist/cli/indexPolicy.js.map +1 -1
  78. package/dist/cli/inspect.d.ts.map +1 -1
  79. package/dist/cli/inspect.js +5 -2
  80. package/dist/cli/inspect.js.map +1 -1
  81. package/dist/cli/install.js +1 -1
  82. package/dist/cli/install.js.map +1 -1
  83. package/dist/cli/options.d.ts +1 -1
  84. package/dist/cli/options.d.ts.map +1 -1
  85. package/dist/cli/options.js +54 -5
  86. package/dist/cli/options.js.map +1 -1
  87. package/dist/cli/renamePreview.d.ts.map +1 -1
  88. package/dist/cli/renamePreview.js +7 -1
  89. package/dist/cli/renamePreview.js.map +1 -1
  90. package/dist/cli/rootPolicy.d.ts.map +1 -1
  91. package/dist/cli/rootPolicy.js +36 -3
  92. package/dist/cli/rootPolicy.js.map +1 -1
  93. package/dist/cli/server.d.ts +59 -0
  94. package/dist/cli/server.d.ts.map +1 -0
  95. package/dist/cli/server.js +906 -0
  96. package/dist/cli/server.js.map +1 -0
  97. package/dist/cli/skill.js +1 -1
  98. package/dist/cli/skill.js.map +1 -1
  99. package/dist/cli/sql.js +1 -1
  100. package/dist/cli/symbols.d.ts.map +1 -1
  101. package/dist/cli/symbols.js +4 -2
  102. package/dist/cli/symbols.js.map +1 -1
  103. package/dist/cli.d.ts +1 -1
  104. package/dist/cli.d.ts.map +1 -1
  105. package/dist/cli.js +37 -16
  106. package/dist/cli.js.map +1 -1
  107. package/dist/documentLinks/check.d.ts.map +1 -1
  108. package/dist/documentLinks/check.js +20 -9
  109. package/dist/documentLinks/check.js.map +1 -1
  110. package/dist/documentLinks.d.ts.map +1 -1
  111. package/dist/documentLinks.js +0 -1
  112. package/dist/documentLinks.js.map +1 -1
  113. package/dist/drift/snapshot.js +1 -1
  114. package/dist/drift/snapshot.js.map +1 -1
  115. package/dist/duplicates/scoring.d.ts.map +1 -1
  116. package/dist/duplicates/scoring.js.map +1 -1
  117. package/dist/duplicates/types.d.ts +2 -0
  118. package/dist/duplicates/types.d.ts.map +1 -1
  119. package/dist/duplicates/unitCache.d.ts.map +1 -1
  120. package/dist/duplicates/unitCache.js +1 -1
  121. package/dist/duplicates/unitCache.js.map +1 -1
  122. package/dist/duplicates/units.d.ts.map +1 -1
  123. package/dist/duplicates/units.js +8 -5
  124. package/dist/duplicates/units.js.map +1 -1
  125. package/dist/duplicates.d.ts.map +1 -1
  126. package/dist/duplicates.js +59 -6
  127. package/dist/duplicates.js.map +1 -1
  128. package/dist/graph-edge-collector.d.ts +0 -2
  129. package/dist/graph-edge-collector.d.ts.map +1 -1
  130. package/dist/graph-edge-collector.js +2 -4
  131. package/dist/graph-edge-collector.js.map +1 -1
  132. package/dist/graphs/edgeResolution.d.ts.map +1 -1
  133. package/dist/graphs/specifiers.d.ts +1 -1
  134. package/dist/graphs/specifiers.d.ts.map +1 -1
  135. package/dist/graphs/specifiers.js +1 -1
  136. package/dist/graphs/specifiers.js.map +1 -1
  137. package/dist/graphs/symbol-graph-detailed.d.ts +10 -1
  138. package/dist/graphs/symbol-graph-detailed.d.ts.map +1 -1
  139. package/dist/graphs/symbol-graph-detailed.js +18 -5
  140. package/dist/graphs/symbol-graph-detailed.js.map +1 -1
  141. package/dist/impact/analyzer.d.ts.map +1 -1
  142. package/dist/impact/analyzer.js +4 -1
  143. package/dist/impact/analyzer.js.map +1 -1
  144. package/dist/impact/budgets.d.ts.map +1 -1
  145. package/dist/impact/budgets.js +5 -3
  146. package/dist/impact/budgets.js.map +1 -1
  147. package/dist/impact/callCompatibility.d.ts +8 -1
  148. package/dist/impact/callCompatibility.d.ts.map +1 -1
  149. package/dist/impact/callCompatibility.js +55 -17
  150. package/dist/impact/callCompatibility.js.map +1 -1
  151. package/dist/impact/context.d.ts.map +1 -1
  152. package/dist/impact/context.js +4 -1
  153. package/dist/impact/context.js.map +1 -1
  154. package/dist/impact/direct.d.ts +1 -1
  155. package/dist/impact/direct.d.ts.map +1 -1
  156. package/dist/impact/parse.d.ts.map +1 -1
  157. package/dist/impact/parse.js +10 -1
  158. package/dist/impact/parse.js.map +1 -1
  159. package/dist/impact/report-suggestions.d.ts.map +1 -1
  160. package/dist/impact/report-suggestions.js +17 -11
  161. package/dist/impact/report-suggestions.js.map +1 -1
  162. package/dist/impact/report.d.ts.map +1 -1
  163. package/dist/impact/report.js +13 -2
  164. package/dist/impact/report.js.map +1 -1
  165. package/dist/impact/reportCompact.d.ts.map +1 -1
  166. package/dist/impact/reportCompact.js +1 -0
  167. package/dist/impact/reportCompact.js.map +1 -1
  168. package/dist/impact/reportFull.d.ts.map +1 -1
  169. package/dist/impact/reportFull.js +1 -0
  170. package/dist/impact/reportFull.js.map +1 -1
  171. package/dist/impact/reportParts.d.ts +9 -0
  172. package/dist/impact/reportParts.d.ts.map +1 -1
  173. package/dist/impact/severity.d.ts +3 -2
  174. package/dist/impact/severity.d.ts.map +1 -1
  175. package/dist/impact/severity.js +16 -5
  176. package/dist/impact/severity.js.map +1 -1
  177. package/dist/impact/streaming.d.ts.map +1 -1
  178. package/dist/impact/streaming.js +5 -5
  179. package/dist/impact/streaming.js.map +1 -1
  180. package/dist/impact/transitive.d.ts.map +1 -1
  181. package/dist/impact/transitive.js +13 -5
  182. package/dist/impact/transitive.js.map +1 -1
  183. package/dist/impact/types.d.ts +14 -0
  184. package/dist/impact/types.d.ts.map +1 -1
  185. package/dist/impact/types.js.map +1 -1
  186. package/dist/index.d.ts +1 -1
  187. package/dist/index.d.ts.map +1 -1
  188. package/dist/index.js.map +1 -1
  189. package/dist/indexer/build-cache/manifest.d.ts +5 -3
  190. package/dist/indexer/build-cache/manifest.d.ts.map +1 -1
  191. package/dist/indexer/build-cache/manifest.js +122 -15
  192. package/dist/indexer/build-cache/manifest.js.map +1 -1
  193. package/dist/indexer/build-cache/module-cache.d.ts +1 -0
  194. package/dist/indexer/build-cache/module-cache.d.ts.map +1 -1
  195. package/dist/indexer/build-cache/module-cache.js +7 -1
  196. package/dist/indexer/build-cache/module-cache.js.map +1 -1
  197. package/dist/indexer/build-cache/options.d.ts.map +1 -1
  198. package/dist/indexer/build-cache/options.js +0 -2
  199. package/dist/indexer/build-cache/options.js.map +1 -1
  200. package/dist/indexer/build-cache/project-snapshot.d.ts +15 -11
  201. package/dist/indexer/build-cache/project-snapshot.d.ts.map +1 -1
  202. package/dist/indexer/build-cache/project-snapshot.js +167 -79
  203. package/dist/indexer/build-cache/project-snapshot.js.map +1 -1
  204. package/dist/indexer/build-cache/resolver-environment.d.ts +2 -2
  205. package/dist/indexer/build-cache/resolver-environment.d.ts.map +1 -1
  206. package/dist/indexer/build-cache/resolver-environment.js +33 -6
  207. package/dist/indexer/build-cache/resolver-environment.js.map +1 -1
  208. package/dist/indexer/build-cache.d.ts +2 -2
  209. package/dist/indexer/build-cache.d.ts.map +1 -1
  210. package/dist/indexer/build-cache.js +2 -2
  211. package/dist/indexer/build-cache.js.map +1 -1
  212. package/dist/indexer/build-index.d.ts.map +1 -1
  213. package/dist/indexer/build-index.js +164 -84
  214. package/dist/indexer/build-index.js.map +1 -1
  215. package/dist/indexer/build-manifest.d.ts.map +1 -1
  216. package/dist/indexer/build-manifest.js +3 -0
  217. package/dist/indexer/build-manifest.js.map +1 -1
  218. package/dist/indexer/build-workers.d.ts +30 -3
  219. package/dist/indexer/build-workers.d.ts.map +1 -1
  220. package/dist/indexer/build-workers.js +111 -45
  221. package/dist/indexer/build-workers.js.map +1 -1
  222. package/dist/indexer/call-hierarchy.d.ts.map +1 -1
  223. package/dist/indexer/import-types.d.ts +8 -0
  224. package/dist/indexer/import-types.d.ts.map +1 -1
  225. package/dist/indexer/imports/python.d.ts.map +1 -1
  226. package/dist/indexer/imports/python.js +13 -8
  227. package/dist/indexer/imports/python.js.map +1 -1
  228. package/dist/indexer/imports.d.ts +0 -3
  229. package/dist/indexer/imports.d.ts.map +1 -1
  230. package/dist/indexer/imports.js +1 -1
  231. package/dist/indexer/imports.js.map +1 -1
  232. package/dist/indexer/incremental-plan.d.ts +2 -1
  233. package/dist/indexer/incremental-plan.d.ts.map +1 -1
  234. package/dist/indexer/incremental-plan.js +7 -4
  235. package/dist/indexer/incremental-plan.js.map +1 -1
  236. package/dist/indexer/locals-and-exports.d.ts +2 -2
  237. package/dist/indexer/locals-and-exports.d.ts.map +1 -1
  238. package/dist/indexer/locals-and-exports.js +27 -3
  239. package/dist/indexer/locals-and-exports.js.map +1 -1
  240. package/dist/indexer/navigation-local.d.ts +2 -2
  241. package/dist/indexer/navigation-local.d.ts.map +1 -1
  242. package/dist/indexer/navigation-local.js +2 -2
  243. package/dist/indexer/navigation-local.js.map +1 -1
  244. package/dist/indexer/navigation-references.d.ts +1 -2
  245. package/dist/indexer/navigation-references.d.ts.map +1 -1
  246. package/dist/indexer/navigation-references.js +8 -2
  247. package/dist/indexer/navigation-references.js.map +1 -1
  248. package/dist/indexer/navigation.d.ts.map +1 -1
  249. package/dist/indexer/navigation.js +12 -4
  250. package/dist/indexer/navigation.js.map +1 -1
  251. package/dist/indexer/parse-context.d.ts +2 -5
  252. package/dist/indexer/parse-context.d.ts.map +1 -1
  253. package/dist/indexer/parse-context.js +34 -8
  254. package/dist/indexer/parse-context.js.map +1 -1
  255. package/dist/indexer/scope.d.ts +2 -2
  256. package/dist/indexer/scope.d.ts.map +1 -1
  257. package/dist/indexer/scope.js +1 -1
  258. package/dist/indexer/scope.js.map +1 -1
  259. package/dist/indexer/types.d.ts +5 -1
  260. package/dist/indexer/types.d.ts.map +1 -1
  261. package/dist/indexer.d.ts +3 -6
  262. package/dist/indexer.d.ts.map +1 -1
  263. package/dist/indexer.js +5 -8
  264. package/dist/indexer.js.map +1 -1
  265. package/dist/installer/locks.d.ts.map +1 -1
  266. package/dist/installer/locks.js +1 -3
  267. package/dist/installer/locks.js.map +1 -1
  268. package/dist/installer/registry.d.ts.map +1 -1
  269. package/dist/installer/registry.js +63 -32
  270. package/dist/installer/registry.js.map +1 -1
  271. package/dist/languages/definitions/c.d.ts.map +1 -1
  272. package/dist/languages/definitions/c.js +0 -1
  273. package/dist/languages/definitions/c.js.map +1 -1
  274. package/dist/languages/definitions/cFamily.d.ts +0 -1
  275. package/dist/languages/definitions/cFamily.d.ts.map +1 -1
  276. package/dist/languages/definitions/cFamily.js +0 -2
  277. package/dist/languages/definitions/cFamily.js.map +1 -1
  278. package/dist/languages/definitions/cpp.d.ts.map +1 -1
  279. package/dist/languages/definitions/cpp.js +0 -1
  280. package/dist/languages/definitions/cpp.js.map +1 -1
  281. package/dist/languages/definitions/csharp.d.ts.map +1 -1
  282. package/dist/languages/definitions/csharp.js +0 -2
  283. package/dist/languages/definitions/csharp.js.map +1 -1
  284. package/dist/languages/definitions/css.d.ts.map +1 -1
  285. package/dist/languages/definitions/css.js +0 -2
  286. package/dist/languages/definitions/css.js.map +1 -1
  287. package/dist/languages/definitions/go.d.ts.map +1 -1
  288. package/dist/languages/definitions/go.js +0 -2
  289. package/dist/languages/definitions/go.js.map +1 -1
  290. package/dist/languages/definitions/html.d.ts.map +1 -1
  291. package/dist/languages/definitions/html.js +0 -2
  292. package/dist/languages/definitions/html.js.map +1 -1
  293. package/dist/languages/definitions/htmlStub.d.ts.map +1 -1
  294. package/dist/languages/definitions/htmlStub.js +0 -2
  295. package/dist/languages/definitions/htmlStub.js.map +1 -1
  296. package/dist/languages/definitions/java.d.ts.map +1 -1
  297. package/dist/languages/definitions/java.js +0 -2
  298. package/dist/languages/definitions/java.js.map +1 -1
  299. package/dist/languages/definitions/javascript.d.ts.map +1 -1
  300. package/dist/languages/definitions/javascript.js +0 -2
  301. package/dist/languages/definitions/javascript.js.map +1 -1
  302. package/dist/languages/definitions/kotlin.d.ts.map +1 -1
  303. package/dist/languages/definitions/kotlin.js +0 -2
  304. package/dist/languages/definitions/kotlin.js.map +1 -1
  305. package/dist/languages/definitions/less.d.ts.map +1 -1
  306. package/dist/languages/definitions/less.js +0 -2
  307. package/dist/languages/definitions/less.js.map +1 -1
  308. package/dist/languages/definitions/php.d.ts.map +1 -1
  309. package/dist/languages/definitions/php.js +0 -2
  310. package/dist/languages/definitions/php.js.map +1 -1
  311. package/dist/languages/definitions/python.d.ts.map +1 -1
  312. package/dist/languages/definitions/python.js +0 -2
  313. package/dist/languages/definitions/python.js.map +1 -1
  314. package/dist/languages/definitions/ruby.d.ts.map +1 -1
  315. package/dist/languages/definitions/ruby.js +0 -2
  316. package/dist/languages/definitions/ruby.js.map +1 -1
  317. package/dist/languages/definitions/rust.d.ts.map +1 -1
  318. package/dist/languages/definitions/rust.js +0 -2
  319. package/dist/languages/definitions/rust.js.map +1 -1
  320. package/dist/languages/definitions/scss.d.ts.map +1 -1
  321. package/dist/languages/definitions/scss.js +0 -2
  322. package/dist/languages/definitions/scss.js.map +1 -1
  323. package/dist/languages/definitions/sql.d.ts.map +1 -1
  324. package/dist/languages/definitions/sql.js +0 -2
  325. package/dist/languages/definitions/sql.js.map +1 -1
  326. package/dist/languages/definitions/svelte.d.ts.map +1 -1
  327. package/dist/languages/definitions/svelte.js +0 -2
  328. package/dist/languages/definitions/svelte.js.map +1 -1
  329. package/dist/languages/definitions/swift.d.ts.map +1 -1
  330. package/dist/languages/definitions/swift.js +0 -2
  331. package/dist/languages/definitions/swift.js.map +1 -1
  332. package/dist/languages/definitions/typescript.d.ts.map +1 -1
  333. package/dist/languages/definitions/typescript.js +0 -3
  334. package/dist/languages/definitions/typescript.js.map +1 -1
  335. package/dist/languages/definitions/vue.d.ts.map +1 -1
  336. package/dist/languages/definitions/vue.js +0 -2
  337. package/dist/languages/definitions/vue.js.map +1 -1
  338. package/dist/languages/definitions/zig.d.ts.map +1 -1
  339. package/dist/languages/definitions/zig.js +0 -2
  340. package/dist/languages/definitions/zig.js.map +1 -1
  341. package/dist/languages/filePrep.d.ts +0 -2
  342. package/dist/languages/filePrep.d.ts.map +1 -1
  343. package/dist/languages/filePrep.js +0 -1
  344. package/dist/languages/filePrep.js.map +1 -1
  345. package/dist/languages/types.d.ts +19 -5
  346. package/dist/languages/types.d.ts.map +1 -1
  347. package/dist/languages.d.ts +1 -3
  348. package/dist/languages.d.ts.map +1 -1
  349. package/dist/languages.js +0 -7
  350. package/dist/languages.js.map +1 -1
  351. package/dist/lifecycle/manifest.d.ts.map +1 -1
  352. package/dist/lifecycle/manifest.js +21 -4
  353. package/dist/lifecycle/manifest.js.map +1 -1
  354. package/dist/mcp/handlers.d.ts +275 -0
  355. package/dist/mcp/handlers.d.ts.map +1 -0
  356. package/dist/mcp/handlers.js +657 -0
  357. package/dist/mcp/handlers.js.map +1 -0
  358. package/dist/mcp/httpTransport.d.ts +14 -0
  359. package/dist/mcp/httpTransport.d.ts.map +1 -0
  360. package/dist/mcp/httpTransport.js +185 -0
  361. package/dist/mcp/httpTransport.js.map +1 -0
  362. package/dist/mcp/legacySessions.d.ts +38 -0
  363. package/dist/mcp/legacySessions.d.ts.map +1 -0
  364. package/dist/mcp/legacySessions.js +264 -0
  365. package/dist/mcp/legacySessions.js.map +1 -0
  366. package/dist/mcp/lifecycleHealth.d.ts +12 -0
  367. package/dist/mcp/lifecycleHealth.d.ts.map +1 -0
  368. package/dist/mcp/lifecycleHealth.js +37 -0
  369. package/dist/mcp/lifecycleHealth.js.map +1 -0
  370. package/dist/mcp/protocol.d.ts +35 -0
  371. package/dist/mcp/protocol.d.ts.map +1 -0
  372. package/dist/mcp/protocol.js +577 -0
  373. package/dist/mcp/protocol.js.map +1 -0
  374. package/dist/mcp/server.d.ts +9 -291
  375. package/dist/mcp/server.d.ts.map +1 -1
  376. package/dist/mcp/server.js +13 -1517
  377. package/dist/mcp/server.js.map +1 -1
  378. package/dist/mcp/tools.d.ts.map +1 -1
  379. package/dist/mcp/tools.js +8 -1
  380. package/dist/mcp/tools.js.map +1 -1
  381. package/dist/native/bindingLoader.d.ts +27 -0
  382. package/dist/native/bindingLoader.d.ts.map +1 -1
  383. package/dist/native/bindingLoader.js +18 -1
  384. package/dist/native/bindingLoader.js.map +1 -1
  385. package/dist/native/contracts.d.ts +59 -12
  386. package/dist/native/contracts.d.ts.map +1 -1
  387. package/dist/native/execution.d.ts +10 -1
  388. package/dist/native/execution.d.ts.map +1 -1
  389. package/dist/native/execution.js +59 -3
  390. package/dist/native/execution.js.map +1 -1
  391. package/dist/native/projectedTree.d.ts +20 -5
  392. package/dist/native/projectedTree.d.ts.map +1 -1
  393. package/dist/native/projectedTree.js +100 -48
  394. package/dist/native/projectedTree.js.map +1 -1
  395. package/dist/native/runtime.d.ts +47 -1
  396. package/dist/native/runtime.d.ts.map +1 -1
  397. package/dist/native/runtime.js +151 -8
  398. package/dist/native/runtime.js.map +1 -1
  399. package/dist/native/runtimeCache.d.ts +92 -0
  400. package/dist/native/runtimeCache.d.ts.map +1 -1
  401. package/dist/native/runtimeCache.js +443 -13
  402. package/dist/native/runtimeCache.js.map +1 -1
  403. package/dist/native/treeShape.d.ts +21 -0
  404. package/dist/native/treeShape.d.ts.map +1 -0
  405. package/dist/native/treeShape.js +28 -0
  406. package/dist/native/treeShape.js.map +1 -0
  407. package/dist/native/treeSitterNative.d.ts +3 -3
  408. package/dist/native/treeSitterNative.d.ts.map +1 -1
  409. package/dist/native/treeSitterNative.js +2 -2
  410. package/dist/native/treeSitterNative.js.map +1 -1
  411. package/dist/presets.d.ts +7 -1
  412. package/dist/presets.d.ts.map +1 -1
  413. package/dist/presets.js +4 -0
  414. package/dist/presets.js.map +1 -1
  415. package/dist/review/candidates.d.ts.map +1 -1
  416. package/dist/review/candidates.js +4 -1
  417. package/dist/review/candidates.js.map +1 -1
  418. package/dist/review/deleted.js +2 -2
  419. package/dist/review/deleted.js.map +1 -1
  420. package/dist/review/summaries.d.ts +5 -0
  421. package/dist/review/summaries.d.ts.map +1 -1
  422. package/dist/review/summaries.js +19 -11
  423. package/dist/review/summaries.js.map +1 -1
  424. package/dist/review/types.d.ts +3 -1
  425. package/dist/review/types.d.ts.map +1 -1
  426. package/dist/review/types.js +8 -1
  427. package/dist/review/types.js.map +1 -1
  428. package/dist/review.d.ts.map +1 -1
  429. package/dist/review.js +7 -3
  430. package/dist/review.js.map +1 -1
  431. package/dist/sql/extractFacts.d.ts.map +1 -1
  432. package/dist/sql/extractFacts.js +1 -1
  433. package/dist/sql/extractFacts.js.map +1 -1
  434. package/dist/sqlite/schema.d.ts +2 -1
  435. package/dist/sqlite/schema.d.ts.map +1 -1
  436. package/dist/sqlite/schema.js +15 -1
  437. package/dist/sqlite/schema.js.map +1 -1
  438. package/dist/sqlite/write.d.ts.map +1 -1
  439. package/dist/sqlite/write.js +15 -0
  440. package/dist/sqlite/write.js.map +1 -1
  441. package/dist/sqlite-driver.d.ts +11 -0
  442. package/dist/sqlite-driver.d.ts.map +1 -1
  443. package/dist/sqlite-driver.js +27 -2
  444. package/dist/sqlite-driver.js.map +1 -1
  445. package/dist/util/concurrency.d.ts +1 -0
  446. package/dist/util/concurrency.d.ts.map +1 -1
  447. package/dist/util/concurrency.js +9 -2
  448. package/dist/util/concurrency.js.map +1 -1
  449. package/dist/util/confinedFile.d.ts +1 -0
  450. package/dist/util/confinedFile.d.ts.map +1 -1
  451. package/dist/util/confinedFile.js +17 -5
  452. package/dist/util/confinedFile.js.map +1 -1
  453. package/dist/util/errors.d.ts +2 -0
  454. package/dist/util/errors.d.ts.map +1 -1
  455. package/dist/util/errors.js +18 -0
  456. package/dist/util/errors.js.map +1 -1
  457. package/dist/util/git.d.ts.map +1 -1
  458. package/dist/util/git.js +72 -7
  459. package/dist/util/git.js.map +1 -1
  460. package/dist/util/lazySymbols.js +1 -1
  461. package/dist/util/lazySymbols.js.map +1 -1
  462. package/dist/util/paths.d.ts.map +1 -1
  463. package/dist/util/paths.js +45 -9
  464. package/dist/util/paths.js.map +1 -1
  465. package/dist/util/resolution/jvm.d.ts.map +1 -1
  466. package/dist/util/resolution/jvm.js +14 -8
  467. package/dist/util/resolution/jvm.js.map +1 -1
  468. package/dist/util/resolution/php.d.ts.map +1 -1
  469. package/dist/util/resolution/php.js +0 -1
  470. package/dist/util/resolution/php.js.map +1 -1
  471. package/dist/util/resolution/tsconfig.d.ts.map +1 -1
  472. package/dist/util/resolution/tsconfig.js +26 -12
  473. package/dist/util/resolution/tsconfig.js.map +1 -1
  474. package/dist/util/resolution.d.ts.map +1 -1
  475. package/dist/util/resolution.js +5 -5
  476. package/dist/util/resolution.js.map +1 -1
  477. package/dist/worker/nativeExtractWorker.d.ts +14 -6
  478. package/dist/worker/nativeExtractWorker.d.ts.map +1 -1
  479. package/dist/worker/nativeExtractWorker.js +67 -14
  480. package/dist/worker/nativeExtractWorker.js.map +1 -1
  481. package/dist/worker/nativeWorkerPool.d.ts +4 -0
  482. package/dist/worker/nativeWorkerPool.d.ts.map +1 -1
  483. package/dist/worker/nativeWorkerPool.js +6 -1
  484. package/dist/worker/nativeWorkerPool.js.map +1 -1
  485. package/docs/mcp.md +22 -6
  486. package/package.json +3 -3
  487. package/dist/languages/definitions/loadLanguage.d.ts +0 -2
  488. package/dist/languages/definitions/loadLanguage.d.ts.map +0 -1
  489. package/dist/languages/definitions/loadLanguage.js +0 -2
  490. package/dist/languages/definitions/loadLanguage.js.map +0 -1
  491. package/dist/parserBackend.d.ts +0 -57
  492. package/dist/parserBackend.d.ts.map +0 -1
  493. package/dist/parserBackend.js +0 -33
  494. package/dist/parserBackend.js.map +0 -1
@@ -0,0 +1,657 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { buildCodegraphArtifactWithSession } from "../agent/artifact.js";
4
+ import { explainCodegraphTargetWithSession } from "../agent/explain.js";
5
+ import { getCodegraphFileViewWithSession } from "../agent/fileView.js";
6
+ import { exploreCodegraphWithSession } from "../agent/explore.js";
7
+ import { orientCodegraphWithSession } from "../agent/orient.js";
8
+ import { getCodegraphPacketWithSession } from "../agent/packet.js";
9
+ import { searchCodegraphWithSession } from "../agent/search.js";
10
+ import { workspaceSymbolsWithSession } from "../agent/workspaceSymbols.js";
11
+ import { findImplementationsWithSession, findSubtypesWithSession, findSupertypesWithSession, } from "../agent/typeHierarchy.js";
12
+ import { findCalleesWithSession, findCallersWithSession } from "../agent/callHierarchy.js";
13
+ import { previewRenameWithSession } from "../agent/renamePreview.js";
14
+ import { buildRefactorPlanWithSession } from "../agent/refactorPlan.js";
15
+ import { parseAgentSymbolHandle } from "../agent/handles.js";
16
+ import { requireSemanticSymbol, resolveSemanticSymbol } from "../agent/semanticSymbols.js";
17
+ import { getDependencies, getReverseDependencies, getShortestPath } from "../graphs/queries.js";
18
+ import { findReferences, goToDefinition } from "../indexer/navigation.js";
19
+ import { parseQualifiedSymbolPath } from "../indexer/symbols.js";
20
+ import { analyzeImpactFromDiff } from "../impact/index.js";
21
+ import { DEFAULT_BOUNDED_IMPACT_BUDGETS } from "../impact/budgets.js";
22
+ import { buildReviewReport } from "../review.js";
23
+ import { boundReviewReportForTransport } from "../review/types.js";
24
+ import { SQLITE_ARTIFACT_FILE_SIGNATURES_METADATA_KEY, queryGraphSqliteRaw } from "../sqlite.js";
25
+ import { boundList, countOmitted } from "../presentation/bounds.js";
26
+ import { isPlainRecord } from "../util/guards.js";
27
+ import { toProjectDisplayPath } from "../util/paths.js";
28
+ import { assertNoPrebuiltSessionWithBuildOptions, createAgentSession, listAgentSessionFiles, } from "../agent/session.js";
29
+ import { mapLimit } from "../util/concurrency.js";
30
+ import { assertRealPathCandidateWithinRoot, resolveProjectFile } from "../util/confinedFile.js";
31
+ import { SymbolKind } from "../indexer/types.js";
32
+ import { DEFAULT_WORKSPACE_SYMBOL_LIMIT, MAX_WORKSPACE_SYMBOL_LIMIT } from "../indexer/workspace-symbols.js";
33
+ import { assertMcpSqliteQueryResourceBounded, DEFAULT_SQLITE_BYTE_LIMIT, normalizeSqliteRowLimit, } from "./sqliteGuard.js";
34
+ import { DEFAULT_CALL_HIERARCHY_LIMIT, MAX_CALL_HIERARCHY_LIMIT, DEFAULT_MCP_COLLECTION_LIMIT, DEFAULT_TYPE_HIERARCHY_LIMIT, MAX_TYPE_HIERARCHY_LIMIT, MAX_MCP_COLLECTION_LIMIT, } from "./tools.js";
35
+ import {} from "../runtimeIdentity.js";
36
+ import { assertWritableDirectoryRealPathWithinRoot, resolveArtifactSqlitePathCandidate } from "./security.js";
37
+ const MAX_MCP_FRESHNESS_CHANGED_FILES = 25;
38
+ const MAX_MCP_FRESHNESS_RETRIES = 3;
39
+ const SQLITE_ARTIFACT_STAT_CONCURRENCY = 64;
40
+ function assertMcpSessionOptions(options) {
41
+ assertNoPrebuiltSessionWithBuildOptions(options, "MCP server options");
42
+ }
43
+ function createCodegraphMcpSession(options, root) {
44
+ assertMcpSessionOptions(options);
45
+ return (options.session ??
46
+ createAgentSession({
47
+ root,
48
+ ...(options.buildOptions ? { buildOptions: options.buildOptions } : {}),
49
+ freshness: { policy: "auto" },
50
+ }));
51
+ }
52
+ function startCodegraphMcpWarmup(session, warmup) {
53
+ if (warmup === "base") {
54
+ return session.loadProject({ symbolGraph: "skip" });
55
+ }
56
+ if (warmup === "symbols") {
57
+ return session.loadProject();
58
+ }
59
+ return undefined;
60
+ }
61
+ export async function createWarmedCodegraphMcpResources(options) {
62
+ const root = path.resolve(options.root);
63
+ const session = createCodegraphMcpSession(options, root);
64
+ await startCodegraphMcpWarmup(session, options.warmup);
65
+ const { warmup, host, port, onHttpListen, ...handlerOptions } = options;
66
+ void warmup;
67
+ void host;
68
+ void port;
69
+ void onHttpListen;
70
+ return {
71
+ handlers: createCodegraphMcpHandlersForSession({ ...handlerOptions, root }, session),
72
+ session,
73
+ };
74
+ }
75
+ export function createCodegraphMcpHandlers(options) {
76
+ const root = path.resolve(options.root);
77
+ const session = createCodegraphMcpSession(options, root);
78
+ return createCodegraphMcpHandlersForSession(options, session);
79
+ }
80
+ function createCodegraphMcpHandlersForSession(options, session) {
81
+ const root = path.resolve(options.root);
82
+ const readOnly = options.readOnly ?? true;
83
+ const realRoot = fs.realpath(root);
84
+ const configuredSqlitePath = options.artifactPath
85
+ ? resolveArtifactSqlitePathCandidate(root, options.artifactPath)
86
+ : undefined;
87
+ const configuredSqliteOutDir = configuredSqlitePath ? path.dirname(configuredSqlitePath) : undefined;
88
+ const configuredSqliteCanRefresh = options.artifactPath ? !/\.(sqlite|db)$/i.test(options.artifactPath) : false;
89
+ let sqlitePath = configuredSqlitePath;
90
+ let sqliteOutDir = configuredSqliteOutDir;
91
+ let sqliteCanRefresh = configuredSqliteCanRefresh;
92
+ let refreshPromise;
93
+ let refreshEpoch = 0;
94
+ let artifactWritePromise;
95
+ const withArtifactWriteLock = async (operation) => {
96
+ const previous = artifactWritePromise;
97
+ const complete = Promise.withResolvers();
98
+ artifactWritePromise = complete.promise;
99
+ try {
100
+ if (previous)
101
+ await previous.catch(() => undefined);
102
+ return await operation();
103
+ }
104
+ finally {
105
+ complete.resolve();
106
+ if (artifactWritePromise === complete.promise)
107
+ artifactWritePromise = undefined;
108
+ }
109
+ };
110
+ const relative = (file) => toProjectDisplayPath(root, file);
111
+ const boundedLimit = (limit, fallback, max) => {
112
+ if (typeof limit !== "number" || !Number.isFinite(limit))
113
+ return fallback;
114
+ return Math.min(max, Math.max(0, Math.floor(limit)));
115
+ };
116
+ const staleFreshness = (files, reason) => {
117
+ const changedFiles = [...files].sort();
118
+ const boundedChangedFiles = changedFiles.slice(0, MAX_MCP_FRESHNESS_CHANGED_FILES);
119
+ return {
120
+ state: "stale",
121
+ changedFiles: boundedChangedFiles,
122
+ changedFileCount: changedFiles.length,
123
+ omittedChangedFileCount: countOmitted(changedFiles.length, boundedChangedFiles.length),
124
+ reason,
125
+ };
126
+ };
127
+ const checkMcpFreshness = async () => {
128
+ if (session.checkFreshness)
129
+ return await session.checkFreshness();
130
+ return { state: "fresh" };
131
+ };
132
+ const withFreshness = async (run) => {
133
+ for (let attempt = 0; attempt < MAX_MCP_FRESHNESS_RETRIES; attempt += 1) {
134
+ if (refreshPromise)
135
+ await refreshPromise;
136
+ const epoch = refreshEpoch;
137
+ const freshness = await checkMcpFreshness();
138
+ const result = await run();
139
+ if (epoch === refreshEpoch && !refreshPromise)
140
+ return { ...result, freshness };
141
+ }
142
+ throw new Error("Workspace refresh changed repeatedly while serving the request; retry after refresh completes.");
143
+ };
144
+ const formatSqliteFreshnessError = (freshness) => {
145
+ if (freshness.state === "fresh")
146
+ return "SQLite artifact freshness check unexpectedly failed.";
147
+ const reason = freshness.state === "stale" ? freshness.reason : "workspace changed after artifact build";
148
+ const changed = freshness.changedFiles.length ? ` Changed files: ${freshness.changedFiles.join(", ")}.` : "";
149
+ const omitted = freshness.state === "stale" && freshness.omittedChangedFileCount
150
+ ? ` Omitted changed files: ${freshness.omittedChangedFileCount}.`
151
+ : "";
152
+ let action = "run artifact_build";
153
+ if (readOnly) {
154
+ action = "rebuild the artifact with write access enabled";
155
+ }
156
+ if (freshness.state === "stale") {
157
+ action = `run refresh_index, then ${action}`;
158
+ }
159
+ return `SQLite artifact is stale; ${action} before query_sqlite. ${reason}.${changed}${omitted}`;
160
+ };
161
+ const canRefreshSqliteArtifact = () => {
162
+ if (!sqlitePath || !sqliteOutDir || readOnly || !sqliteCanRefresh)
163
+ return false;
164
+ return path.basename(sqlitePath) === "codegraph.sqlite";
165
+ };
166
+ const rebuildSqliteArtifactForQuery = async () => await withArtifactWriteLock(async () => {
167
+ if (!sqliteOutDir)
168
+ throw new Error("SQLite artifact output directory is unavailable.");
169
+ const outDir = await assertWritableDirectoryRealPathWithinRoot(await realRoot, root, sqliteOutDir, "Artifact output directory");
170
+ const result = await buildCodegraphArtifactWithSession(session, {
171
+ root,
172
+ outDir,
173
+ filterOutDir: outDir,
174
+ sqlite: true,
175
+ force: true,
176
+ });
177
+ const sqliteArtifact = result.artifacts.sqlite;
178
+ if (!sqliteArtifact)
179
+ throw new Error("SQLite artifact refresh did not produce a SQLite file.");
180
+ sqlitePath = path.join(result.outDir, sqliteArtifact);
181
+ sqliteOutDir = result.outDir;
182
+ });
183
+ const refreshSqliteArtifactForQuery = async (freshness, refreshOptions) => {
184
+ if (freshness.state === "fresh")
185
+ return freshness;
186
+ if (freshness.state === "stale" && !refreshOptions?.allowStaleRebuild) {
187
+ throw new Error(formatSqliteFreshnessError(freshness));
188
+ }
189
+ if (!canRefreshSqliteArtifact())
190
+ throw new Error(formatSqliteFreshnessError(freshness));
191
+ await rebuildSqliteArtifactForQuery();
192
+ return { state: "refreshed", changedFiles: freshness.changedFiles };
193
+ };
194
+ const readSqliteArtifactSignatures = async (realSqlitePath) => {
195
+ const result = await queryGraphSqliteRaw(realSqlitePath, "SELECT value FROM graph_metadata WHERE key = ?;", [SQLITE_ARTIFACT_FILE_SIGNATURES_METADATA_KEY], { maxRows: 1 });
196
+ const rawValue = result.rows[0]?.[0];
197
+ if (typeof rawValue !== "string")
198
+ return null;
199
+ let parsed;
200
+ try {
201
+ parsed = JSON.parse(rawValue);
202
+ }
203
+ catch {
204
+ return null;
205
+ }
206
+ if (!Array.isArray(parsed))
207
+ return null;
208
+ const signatures = [];
209
+ for (const value of parsed) {
210
+ if (!isPlainRecord(value))
211
+ continue;
212
+ if (typeof value.path !== "string")
213
+ continue;
214
+ if (typeof value.size !== "number" || typeof value.mtimeMs !== "number")
215
+ continue;
216
+ signatures.push({ path: value.path, size: value.size, mtimeMs: value.mtimeMs });
217
+ }
218
+ return signatures;
219
+ };
220
+ const isFileInsideDirectory = (file, directory) => {
221
+ const relativeFile = path.relative(directory, file);
222
+ if (!relativeFile)
223
+ return true;
224
+ return !relativeFile.startsWith("..") && !path.isAbsolute(relativeFile);
225
+ };
226
+ const collectCurrentSqliteArtifactSignatures = async () => {
227
+ const outputDirectories = [];
228
+ if (sqliteOutDir) {
229
+ outputDirectories.push(sqliteOutDir);
230
+ const lexicalOutDir = path.resolve(root, path.relative(await realRoot, sqliteOutDir));
231
+ outputDirectories.push(lexicalOutDir);
232
+ }
233
+ let discoveredFiles;
234
+ if (session.discoverFiles) {
235
+ discoveredFiles = await session.discoverFiles();
236
+ }
237
+ else if (options.session) {
238
+ throw new Error("MCP session does not expose live file discovery for SQLite freshness.");
239
+ }
240
+ else {
241
+ discoveredFiles = await listAgentSessionFiles({
242
+ root,
243
+ ...(options.buildOptions ? { buildOptions: options.buildOptions } : {}),
244
+ });
245
+ }
246
+ const currentFiles = discoveredFiles.filter((file) => !outputDirectories.some((directory) => isFileInsideDirectory(file, directory)));
247
+ const signatures = new Map();
248
+ await mapLimit(currentFiles, SQLITE_ARTIFACT_STAT_CONCURRENCY, async (file) => {
249
+ try {
250
+ const stat = await fs.stat(file);
251
+ if (!stat.isFile())
252
+ return;
253
+ signatures.set(relative(file), { path: file, size: stat.size, mtimeMs: stat.mtimeMs });
254
+ }
255
+ catch (error) {
256
+ if (error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR")) {
257
+ return;
258
+ }
259
+ throw error;
260
+ }
261
+ });
262
+ return signatures;
263
+ };
264
+ const checkSqliteArtifactFreshness = async (realSqlitePath) => {
265
+ const storedSignatures = await readSqliteArtifactSignatures(realSqlitePath);
266
+ if (!storedSignatures)
267
+ return staleFreshness([], "SQLite artifact has no freshness baseline");
268
+ const storedByFile = new Map();
269
+ for (const signature of storedSignatures) {
270
+ storedByFile.set(relative(signature.path), signature);
271
+ }
272
+ const currentByFile = await collectCurrentSqliteArtifactSignatures();
273
+ const changedFiles = [];
274
+ for (const [file, currentSignature] of currentByFile.entries()) {
275
+ const storedSignature = storedByFile.get(file);
276
+ if (!storedSignature) {
277
+ changedFiles.push(file);
278
+ continue;
279
+ }
280
+ if (storedSignature.size !== currentSignature.size || storedSignature.mtimeMs !== currentSignature.mtimeMs) {
281
+ changedFiles.push(file);
282
+ }
283
+ }
284
+ for (const file of storedByFile.keys()) {
285
+ if (currentByFile.has(file))
286
+ continue;
287
+ changedFiles.push(file);
288
+ }
289
+ if (!changedFiles.length)
290
+ return { state: "fresh" };
291
+ return staleFreshness(changedFiles, "SQLite artifact is older than files on disk");
292
+ };
293
+ const collectMcpDependencyEntries = async (request, collectEntries) => {
294
+ const snapshot = await session.loadProject({ symbolGraph: "skip" });
295
+ const limit = boundedLimit(request.limit, DEFAULT_MCP_COLLECTION_LIMIT, MAX_MCP_COLLECTION_LIMIT);
296
+ const queryOptions = {
297
+ ...(request.depth !== undefined ? { depth: request.depth } : {}),
298
+ // Probe one entry past the display limit so `truncated` is exact
299
+ // rather than a `results.length === limit` heuristic (which cannot
300
+ // tell "exactly limit reachable files" apart from "more exist"),
301
+ // without re-walking the whole reachable graph for an exact total -
302
+ // see finding #44.
303
+ limit: limit + 1,
304
+ };
305
+ const resolvedSymbol = resolveSemanticSymbol(snapshot, request.file);
306
+ let targetFile;
307
+ if (resolvedSymbol) {
308
+ targetFile = resolvedSymbol.def.file;
309
+ }
310
+ else if (parseAgentSymbolHandle(request.file) || parseQualifiedSymbolPath(request.file)) {
311
+ targetFile = requireSemanticSymbol(snapshot, request.file).def.file;
312
+ }
313
+ else {
314
+ targetFile = await resolveProjectFile(await realRoot, root, request.file);
315
+ }
316
+ const collected = collectEntries(snapshot.fileGraph, targetFile, queryOptions);
317
+ const { items, omitted } = boundList(collected, limit);
318
+ const entries = items.map((dependency) => ({
319
+ file: relative(dependency.file),
320
+ depth: dependency.depth,
321
+ }));
322
+ return {
323
+ entries,
324
+ limit,
325
+ totalSeen: collected.length,
326
+ truncated: Boolean(omitted),
327
+ omitted,
328
+ };
329
+ };
330
+ const calls = async (request) => {
331
+ const findCalls = request.direction === "callers" ? findCallersWithSession : findCalleesWithSession;
332
+ return await findCalls(session, {
333
+ root,
334
+ handle: request.handle,
335
+ ...(request.depth !== undefined ? { depth: request.depth } : {}),
336
+ limit: boundedLimit(request.limit, DEFAULT_CALL_HIERARCHY_LIMIT, MAX_CALL_HIERARCHY_LIMIT),
337
+ ...(request.includeHeuristic !== undefined ? { includeHeuristic: request.includeHeuristic } : {}),
338
+ });
339
+ };
340
+ const typeHierarchy = async (request) => {
341
+ const findTypes = request.direction === "supertypes" ? findSupertypesWithSession : findSubtypesWithSession;
342
+ return await findTypes(session, {
343
+ root,
344
+ handle: request.handle,
345
+ ...(request.depth !== undefined ? { depth: request.depth } : {}),
346
+ limit: boundedLimit(request.limit, DEFAULT_TYPE_HIERARCHY_LIMIT, MAX_TYPE_HIERARCHY_LIMIT),
347
+ });
348
+ };
349
+ const boundedReferencesFromResult = (result, limit) => {
350
+ if (result.status !== "ok") {
351
+ return { references: [], limit, totalSeen: 0, truncated: false, omitted: 0 };
352
+ }
353
+ const { items, omitted } = boundList(result.references, limit);
354
+ const references = items.map((reference) => ({ file: relative(reference.file), range: reference.range }));
355
+ return {
356
+ references,
357
+ limit,
358
+ totalSeen: result.references.length,
359
+ truncated: Boolean(omitted),
360
+ omitted,
361
+ };
362
+ };
363
+ const fileDeps = async (request) => await withFreshness(async () => {
364
+ const { entries, ...meta } = await collectMcpDependencyEntries(request, request.direction === "deps" ? getDependencies : getReverseDependencies);
365
+ return request.direction === "deps"
366
+ ? { dependencies: entries, ...meta }
367
+ : { reverseDependencies: entries, ...meta };
368
+ });
369
+ const searchHandlers = {
370
+ search: async (request) => await withFreshness(async () => await searchCodegraphWithSession(session, {
371
+ root,
372
+ query: request.query,
373
+ ...(request.mode !== undefined ? { mode: request.mode } : {}),
374
+ ...(request.from !== undefined ? { from: request.from } : {}),
375
+ ...(request.depth !== undefined ? { depth: request.depth } : {}),
376
+ ...(request.limit !== undefined ? { limit: request.limit } : {}),
377
+ })),
378
+ workspace_symbols: async (request) => await workspaceSymbolsWithSession(session, {
379
+ root,
380
+ query: request.query,
381
+ ...(request.kinds !== undefined ? { kinds: request.kinds } : {}),
382
+ ...(request.exportedOnly !== undefined ? { exportedOnly: request.exportedOnly } : {}),
383
+ ...(request.includeImports !== undefined ? { includeImports: request.includeImports } : {}),
384
+ ...(request.fileGlob !== undefined ? { fileGlob: request.fileGlob } : {}),
385
+ limit: boundedLimit(request.limit, DEFAULT_WORKSPACE_SYMBOL_LIMIT, MAX_WORKSPACE_SYMBOL_LIMIT),
386
+ }),
387
+ rename_preview: async (request) => await previewRenameWithSession(session, {
388
+ root,
389
+ handle: request.handle,
390
+ newName: request.newName,
391
+ ...(request.includeComments !== undefined ? { includeComments: request.includeComments } : {}),
392
+ ...(request.includeStrings !== undefined ? { includeStrings: request.includeStrings } : {}),
393
+ ...(request.includeFilenames !== undefined ? { includeFilenames: request.includeFilenames } : {}),
394
+ ...(request.maxEdits !== undefined ? { maxEdits: request.maxEdits } : {}),
395
+ }),
396
+ refactor_plan: async (request) => await buildRefactorPlanWithSession(session, {
397
+ root,
398
+ handle: request.handle,
399
+ ...(request.renameTo !== undefined ? { renameTo: request.renameTo } : {}),
400
+ ...(request.maxReferences !== undefined ? { maxReferences: request.maxReferences } : {}),
401
+ ...(request.maxCallers !== undefined ? { maxCallers: request.maxCallers } : {}),
402
+ ...(request.maxHierarchy !== undefined ? { maxHierarchy: request.maxHierarchy } : {}),
403
+ ...(request.includeSource !== undefined ? { includeSource: request.includeSource } : {}),
404
+ }),
405
+ calls,
406
+ type_hierarchy: typeHierarchy,
407
+ file_deps: fileDeps,
408
+ callers: async (request) => await calls({ direction: "callers", ...request }),
409
+ callees: async (request) => await calls({ direction: "callees", ...request }),
410
+ supertypes: async (request) => await typeHierarchy({ direction: "supertypes", ...request }),
411
+ subtypes: async (request) => await typeHierarchy({ direction: "subtypes", ...request }),
412
+ implementations: async (request) => await findImplementationsWithSession(session, {
413
+ root,
414
+ handle: request.handle,
415
+ limit: boundedLimit(request.limit, DEFAULT_TYPE_HIERARCHY_LIMIT, MAX_TYPE_HIERARCHY_LIMIT),
416
+ }),
417
+ };
418
+ const navigationHandlers = {
419
+ explore: async (request) => await withFreshness(async () => await exploreCodegraphWithSession(session, {
420
+ root,
421
+ query: request.query,
422
+ ...(request.limit !== undefined ? { limit: request.limit } : {}),
423
+ ...(request.maxPackets !== undefined ? { maxPackets: request.maxPackets } : {}),
424
+ ...(request.maxPaths !== undefined ? { maxPaths: request.maxPaths } : {}),
425
+ ...(request.includeSource !== undefined ? { includeSource: request.includeSource } : {}),
426
+ })),
427
+ orient: async (request) => await withFreshness(async () => await orientCodegraphWithSession(session, {
428
+ root,
429
+ ...(request.includeRoots !== undefined ? { includeRoots: request.includeRoots } : {}),
430
+ ...(request.budget !== undefined ? { budget: request.budget } : {}),
431
+ })),
432
+ packet_get: async (request) => await withFreshness(async () => await getCodegraphPacketWithSession(session, {
433
+ root,
434
+ target: request.target,
435
+ ...(request.maxSymbols !== undefined ? { maxSymbols: request.maxSymbols } : {}),
436
+ ...(request.maxSnippets !== undefined ? { maxSnippets: request.maxSnippets } : {}),
437
+ ...(request.maxDuplicates !== undefined ? { maxDuplicates: request.maxDuplicates } : {}),
438
+ })),
439
+ get_file: async (request) => await getCodegraphFileViewWithSession(session, {
440
+ root,
441
+ file: request.file,
442
+ ...(request.offset !== undefined ? { offset: request.offset } : {}),
443
+ ...(request.limit !== undefined ? { limit: request.limit } : {}),
444
+ ...(request.maxBytes !== undefined ? { maxBytes: request.maxBytes } : {}),
445
+ ...(request.includeGraphContext !== undefined ? { includeGraphContext: request.includeGraphContext } : {}),
446
+ ...(request.allowSensitive !== undefined ? { allowSensitive: request.allowSensitive } : {}),
447
+ ...(options.buildOptions ? { buildOptions: options.buildOptions } : {}),
448
+ }),
449
+ get_symbol: async (request) => await withFreshness(async () => {
450
+ const explanation = await explainCodegraphTargetWithSession(session, { root, target: request.handle });
451
+ return explanation.target;
452
+ }),
453
+ goto: async (request) => await withFreshness(async () => {
454
+ const snapshot = await session.loadProject({ symbolGraph: "skip" });
455
+ if ("handle" in request) {
456
+ const resolved = requireSemanticSymbol(snapshot, request.handle);
457
+ return { status: "ok", definition: resolved.def };
458
+ }
459
+ return await goToDefinition(snapshot.index, {
460
+ file: await resolveProjectFile(await realRoot, root, request.file),
461
+ line: request.line,
462
+ column: request.column,
463
+ });
464
+ }),
465
+ refs: async (request) => await withFreshness(async () => {
466
+ const handle = "handle" in request ? request.handle : undefined;
467
+ const file = "file" in request ? request.file : undefined;
468
+ const line = "line" in request ? request.line : undefined;
469
+ const column = "column" in request ? request.column : undefined;
470
+ const hasAnyPosition = file !== undefined || line !== undefined || column !== undefined;
471
+ const hasCompletePosition = file !== undefined && line !== undefined && column !== undefined;
472
+ if (handle !== undefined && hasAnyPosition) {
473
+ throw new Error("refs requires either handle or file, line, and column.");
474
+ }
475
+ if (handle === undefined && !hasCompletePosition) {
476
+ throw new Error("refs requires either handle or file, line, and column.");
477
+ }
478
+ const limit = boundedLimit(request.limit, DEFAULT_MCP_COLLECTION_LIMIT, MAX_MCP_COLLECTION_LIMIT);
479
+ if (handle !== undefined) {
480
+ if (parseQualifiedSymbolPath(handle)) {
481
+ const snapshot = await session.loadProject({ symbolGraph: "skip" });
482
+ const resolved = requireSemanticSymbol(snapshot, handle);
483
+ // Probe one reference past the display limit so `truncated` is exact - see
484
+ // `collectMcpDependencyEntries` for the rationale (finding #44).
485
+ const result = await findReferences(snapshot.index, { def: resolved.def }, { maxReferences: limit + 1 });
486
+ return boundedReferencesFromResult(result, limit);
487
+ }
488
+ const explanation = await explainCodegraphTargetWithSession(session, {
489
+ root,
490
+ target: handle,
491
+ maxReferences: limit,
492
+ });
493
+ return {
494
+ references: explanation.references,
495
+ limit: explanation.limits.references,
496
+ totalSeen: explanation.references.length + explanation.omittedCounts.references,
497
+ truncated: explanation.omittedCounts.references > 0,
498
+ omitted: explanation.omittedCounts.references,
499
+ };
500
+ }
501
+ if (file === undefined || line === undefined || column === undefined) {
502
+ throw new Error("refs requires either handle or file, line, and column.");
503
+ }
504
+ const snapshot = await session.loadProject({ symbolGraph: "skip" });
505
+ const result = await findReferences(snapshot.index, {
506
+ file: await resolveProjectFile(await realRoot, root, file),
507
+ line,
508
+ column,
509
+ }, { maxReferences: limit + 1 });
510
+ return boundedReferencesFromResult(result, limit);
511
+ }),
512
+ deps: async (request) => await withFreshness(async () => {
513
+ const { entries, ...meta } = await collectMcpDependencyEntries(request, getDependencies);
514
+ return { dependencies: entries, ...meta };
515
+ }),
516
+ rdeps: async (request) => await withFreshness(async () => {
517
+ const { entries, ...meta } = await collectMcpDependencyEntries(request, getReverseDependencies);
518
+ return { reverseDependencies: entries, ...meta };
519
+ }),
520
+ path: async (request) => await withFreshness(async () => {
521
+ const snapshot = await session.loadProject({ symbolGraph: "skip" });
522
+ const result = getShortestPath(snapshot.fileGraph, await resolveProjectFile(await realRoot, root, request.from), await resolveProjectFile(await realRoot, root, request.to));
523
+ return {
524
+ path: result ? result.map(relative) : null,
525
+ };
526
+ }),
527
+ };
528
+ const reviewHandlers = {
529
+ impact: async (request) => await withFreshness(async () => {
530
+ const snapshot = await session.loadProject({ symbolGraph: "skip" });
531
+ return (await analyzeImpactFromDiff(root, snapshot.index, {
532
+ ...options.buildOptions,
533
+ provider: "git",
534
+ base: request.base,
535
+ head: request.head,
536
+ cwd: root,
537
+ compact: true,
538
+ depth: 2,
539
+ maxRefs: 200,
540
+ ...DEFAULT_BOUNDED_IMPACT_BUDGETS,
541
+ }));
542
+ }),
543
+ review: async (request) => await withFreshness(async () => {
544
+ const report = await buildReviewReport(root, {
545
+ ...options.buildOptions,
546
+ gitBase: request.base,
547
+ gitHead: request.head,
548
+ ...(request.reviewDepth !== undefined ? { reviewDepth: request.reviewDepth } : {}),
549
+ }, {
550
+ ...(session.loadProject
551
+ ? {
552
+ loadIndex: async () => (await session.loadProject({ symbolGraph: "skip" })).index,
553
+ }
554
+ : {}),
555
+ ...(session.loadDuplicateAnalysis ? { loadDuplicateAnalysis: session.loadDuplicateAnalysis } : {}),
556
+ });
557
+ // MCP is a bounded transport (finding #45); library callers that need the
558
+ // complete, unbounded report should call `buildReviewReport` directly.
559
+ return boundReviewReportForTransport(report);
560
+ }),
561
+ };
562
+ const artifactHandlers = {
563
+ query_sqlite: async (request, executionOptions) => {
564
+ if (!sqlitePath) {
565
+ throw new Error("No SQLite artifact is available. Run artifact_build first or pass artifactPath.");
566
+ }
567
+ assertMcpSqliteQueryResourceBounded(request.query);
568
+ // The artifact's own baseline decides whether the query can be served; session freshness
569
+ // only decides whether an automatic rebuild is safe. A fresh artifact is served even when
570
+ // the in-memory session snapshot is stale, and an unsafe session refresh burst blocks the
571
+ // automatic rebuild instead of silently rebuilding from stale in-memory state.
572
+ let realSqlitePath = await assertRealPathCandidateWithinRoot(await realRoot, sqlitePath, "SQLite artifact");
573
+ let artifactFreshness = await checkSqliteArtifactFreshness(realSqlitePath);
574
+ if (artifactFreshness.state !== "fresh") {
575
+ const sessionFreshness = await checkMcpFreshness();
576
+ if (sessionFreshness.state === "stale") {
577
+ throw new Error(formatSqliteFreshnessError(sessionFreshness));
578
+ }
579
+ artifactFreshness = await refreshSqliteArtifactForQuery(artifactFreshness, { allowStaleRebuild: true });
580
+ realSqlitePath = await assertRealPathCandidateWithinRoot(await realRoot, sqlitePath, "SQLite artifact");
581
+ }
582
+ const result = await queryGraphSqliteRaw(realSqlitePath, request.query, request.params ?? [], {
583
+ maxRows: normalizeSqliteRowLimit(request.limit),
584
+ maxBytes: DEFAULT_SQLITE_BYTE_LIMIT,
585
+ ...(executionOptions?.signal ? { signal: executionOptions.signal } : {}),
586
+ });
587
+ return { ...result, truncated: Boolean(result.truncated), freshness: artifactFreshness };
588
+ },
589
+ refresh_index: async (request) => await withArtifactWriteLock(async () => {
590
+ const warmup = request.warmup ?? "off";
591
+ const previousRefresh = refreshPromise;
592
+ const refresh = (async () => {
593
+ if (previousRefresh)
594
+ await previousRefresh.catch(() => undefined);
595
+ ++refreshEpoch;
596
+ session.invalidate();
597
+ sqlitePath = configuredSqlitePath;
598
+ sqliteOutDir = configuredSqliteOutDir;
599
+ sqliteCanRefresh = configuredSqliteCanRefresh;
600
+ await startCodegraphMcpWarmup(session, warmup);
601
+ })();
602
+ refreshPromise = refresh;
603
+ try {
604
+ await refresh;
605
+ }
606
+ finally {
607
+ if (refreshPromise === refresh)
608
+ refreshPromise = undefined;
609
+ }
610
+ return { refreshed: true, warmup };
611
+ }),
612
+ artifact_build: async (request) => await withArtifactWriteLock(async () => {
613
+ if (readOnly) {
614
+ throw new Error("artifact_build is disabled in read-only MCP mode.");
615
+ }
616
+ const freshness = await checkMcpFreshness();
617
+ if (freshness.state === "stale") {
618
+ const changed = freshness.changedFiles.length ? ` Changed files: ${freshness.changedFiles.join(", ")}.` : "";
619
+ const omitted = freshness.omittedChangedFileCount
620
+ ? ` Omitted changed files: ${freshness.omittedChangedFileCount}.`
621
+ : "";
622
+ throw new Error(`Cannot build artifacts from a stale MCP index; run refresh_index first. ${freshness.reason}.${changed}${omitted}`);
623
+ }
624
+ const outDir = request.outDir !== undefined
625
+ ? await assertWritableDirectoryRealPathWithinRoot(await realRoot, root, request.outDir, "Artifact output directory")
626
+ : undefined;
627
+ const result = await buildCodegraphArtifactWithSession(session, {
628
+ root,
629
+ ...(outDir !== undefined ? { outDir } : {}),
630
+ ...(request.outDir !== undefined ? { filterOutDir: request.outDir } : {}),
631
+ ...(request.sqlite !== undefined ? { sqlite: request.sqlite } : {}),
632
+ ...(request.graphJson !== undefined ? { graphJson: request.graphJson } : {}),
633
+ ...(request.report !== undefined ? { report: request.report } : {}),
634
+ ...(request.questions !== undefined ? { questions: request.questions } : {}),
635
+ ...(request.force !== undefined ? { force: request.force } : {}),
636
+ });
637
+ const sqliteArtifact = result.artifacts.sqlite;
638
+ if (sqliteArtifact) {
639
+ sqlitePath = path.join(result.outDir, sqliteArtifact);
640
+ sqliteOutDir = result.outDir;
641
+ sqliteCanRefresh = true;
642
+ }
643
+ return { ...result, freshness };
644
+ }),
645
+ dispose: () => {
646
+ if (!options.session)
647
+ session.invalidate();
648
+ },
649
+ };
650
+ return {
651
+ ...searchHandlers,
652
+ ...navigationHandlers,
653
+ ...reviewHandlers,
654
+ ...artifactHandlers,
655
+ };
656
+ }
657
+ //# sourceMappingURL=handlers.js.map