@optave/codegraph 3.4.0 → 3.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (410) hide show
  1. package/README.md +7 -7
  2. package/dist/ast-analysis/engine.d.ts.map +1 -1
  3. package/dist/ast-analysis/engine.js +3 -9
  4. package/dist/ast-analysis/engine.js.map +1 -1
  5. package/dist/ast-analysis/shared.d.ts.map +1 -1
  6. package/dist/ast-analysis/shared.js +0 -1
  7. package/dist/ast-analysis/shared.js.map +1 -1
  8. package/dist/ast-analysis/visitors/cfg-conditionals.d.ts +5 -0
  9. package/dist/ast-analysis/visitors/cfg-conditionals.d.ts.map +1 -0
  10. package/dist/ast-analysis/visitors/cfg-conditionals.js +166 -0
  11. package/dist/ast-analysis/visitors/cfg-conditionals.js.map +1 -0
  12. package/dist/ast-analysis/visitors/cfg-loops.d.ts +7 -0
  13. package/dist/ast-analysis/visitors/cfg-loops.d.ts.map +1 -0
  14. package/dist/ast-analysis/visitors/cfg-loops.js +73 -0
  15. package/dist/ast-analysis/visitors/cfg-loops.js.map +1 -0
  16. package/dist/ast-analysis/visitors/cfg-shared.d.ts +56 -0
  17. package/dist/ast-analysis/visitors/cfg-shared.d.ts.map +1 -0
  18. package/dist/ast-analysis/visitors/cfg-shared.js +107 -0
  19. package/dist/ast-analysis/visitors/cfg-shared.js.map +1 -0
  20. package/dist/ast-analysis/visitors/cfg-try-catch.d.ts +4 -0
  21. package/dist/ast-analysis/visitors/cfg-try-catch.d.ts.map +1 -0
  22. package/dist/ast-analysis/visitors/cfg-try-catch.js +100 -0
  23. package/dist/ast-analysis/visitors/cfg-try-catch.js.map +1 -0
  24. package/dist/ast-analysis/visitors/cfg-visitor.d.ts +2 -2
  25. package/dist/ast-analysis/visitors/cfg-visitor.d.ts.map +1 -1
  26. package/dist/ast-analysis/visitors/cfg-visitor.js +11 -445
  27. package/dist/ast-analysis/visitors/cfg-visitor.js.map +1 -1
  28. package/dist/ast-analysis/visitors/complexity-visitor.d.ts.map +1 -1
  29. package/dist/ast-analysis/visitors/complexity-visitor.js.map +1 -1
  30. package/dist/ast-analysis/visitors/dataflow-visitor.d.ts.map +1 -1
  31. package/dist/ast-analysis/visitors/dataflow-visitor.js.map +1 -1
  32. package/dist/cli/commands/batch.d.ts.map +1 -1
  33. package/dist/cli/commands/batch.js +4 -3
  34. package/dist/cli/commands/batch.js.map +1 -1
  35. package/dist/cli/commands/branch-compare.js +1 -1
  36. package/dist/cli/commands/branch-compare.js.map +1 -1
  37. package/dist/cli/commands/build.js +1 -1
  38. package/dist/cli/commands/build.js.map +1 -1
  39. package/dist/cli/commands/info.d.ts.map +1 -1
  40. package/dist/cli/commands/info.js +1 -2
  41. package/dist/cli/commands/info.js.map +1 -1
  42. package/dist/cli/commands/path.d.ts.map +1 -1
  43. package/dist/cli/commands/path.js +7 -2
  44. package/dist/cli/commands/path.js.map +1 -1
  45. package/dist/cli/commands/plot.d.ts.map +1 -1
  46. package/dist/cli/commands/plot.js +2 -2
  47. package/dist/cli/commands/plot.js.map +1 -1
  48. package/dist/cli/commands/watch.js +1 -1
  49. package/dist/cli/commands/watch.js.map +1 -1
  50. package/dist/cli/index.js +2 -2
  51. package/dist/cli/index.js.map +1 -1
  52. package/dist/cli/shared/open-graph.d.ts +2 -2
  53. package/dist/cli/shared/open-graph.d.ts.map +1 -1
  54. package/dist/cli/shared/open-graph.js.map +1 -1
  55. package/dist/cli/types.d.ts +1 -1
  56. package/dist/cli/types.d.ts.map +1 -1
  57. package/dist/cli.js +2 -3
  58. package/dist/cli.js.map +1 -1
  59. package/dist/db/connection.d.ts +17 -0
  60. package/dist/db/connection.d.ts.map +1 -1
  61. package/dist/db/connection.js +91 -2
  62. package/dist/db/connection.js.map +1 -1
  63. package/dist/db/index.d.ts +1 -1
  64. package/dist/db/index.d.ts.map +1 -1
  65. package/dist/db/index.js +1 -1
  66. package/dist/db/index.js.map +1 -1
  67. package/dist/db/migrations.d.ts.map +1 -1
  68. package/dist/db/migrations.js +7 -0
  69. package/dist/db/migrations.js.map +1 -1
  70. package/dist/domain/analysis/brief.d.ts.map +1 -1
  71. package/dist/domain/analysis/brief.js +1 -3
  72. package/dist/domain/analysis/brief.js.map +1 -1
  73. package/dist/domain/analysis/context.d.ts.map +1 -1
  74. package/dist/domain/analysis/context.js +2 -4
  75. package/dist/domain/analysis/context.js.map +1 -1
  76. package/dist/domain/analysis/dependencies.d.ts +49 -0
  77. package/dist/domain/analysis/dependencies.d.ts.map +1 -1
  78. package/dist/domain/analysis/dependencies.js +145 -0
  79. package/dist/domain/analysis/dependencies.js.map +1 -1
  80. package/dist/domain/analysis/diff-impact.d.ts +76 -0
  81. package/dist/domain/analysis/diff-impact.d.ts.map +1 -0
  82. package/dist/domain/analysis/diff-impact.js +282 -0
  83. package/dist/domain/analysis/diff-impact.js.map +1 -0
  84. package/dist/domain/analysis/exports.d.ts.map +1 -1
  85. package/dist/domain/analysis/exports.js +0 -1
  86. package/dist/domain/analysis/exports.js.map +1 -1
  87. package/dist/domain/analysis/fn-impact.d.ts +66 -0
  88. package/dist/domain/analysis/fn-impact.d.ts.map +1 -0
  89. package/dist/domain/analysis/fn-impact.js +189 -0
  90. package/dist/domain/analysis/fn-impact.js.map +1 -0
  91. package/dist/domain/analysis/impact.d.ts +8 -148
  92. package/dist/domain/analysis/impact.d.ts.map +1 -1
  93. package/dist/domain/analysis/impact.js +8 -568
  94. package/dist/domain/analysis/impact.js.map +1 -1
  95. package/dist/domain/analysis/module-map.d.ts.map +1 -1
  96. package/dist/domain/analysis/module-map.js +1 -3
  97. package/dist/domain/analysis/module-map.js.map +1 -1
  98. package/dist/domain/graph/builder/context.d.ts +2 -3
  99. package/dist/domain/graph/builder/context.d.ts.map +1 -1
  100. package/dist/domain/graph/builder/context.js.map +1 -1
  101. package/dist/domain/graph/builder/helpers.d.ts +4 -5
  102. package/dist/domain/graph/builder/helpers.d.ts.map +1 -1
  103. package/dist/domain/graph/builder/helpers.js +1 -2
  104. package/dist/domain/graph/builder/helpers.js.map +1 -1
  105. package/dist/domain/graph/builder/incremental.d.ts +2 -3
  106. package/dist/domain/graph/builder/incremental.d.ts.map +1 -1
  107. package/dist/domain/graph/builder/incremental.js.map +1 -1
  108. package/dist/domain/graph/builder/pipeline.d.ts.map +1 -1
  109. package/dist/domain/graph/builder/pipeline.js +6 -0
  110. package/dist/domain/graph/builder/pipeline.js.map +1 -1
  111. package/dist/domain/graph/builder/stages/build-edges.d.ts.map +1 -1
  112. package/dist/domain/graph/builder/stages/build-edges.js +12 -2
  113. package/dist/domain/graph/builder/stages/build-edges.js.map +1 -1
  114. package/dist/domain/graph/builder/stages/build-structure.d.ts.map +1 -1
  115. package/dist/domain/graph/builder/stages/build-structure.js +155 -59
  116. package/dist/domain/graph/builder/stages/build-structure.js.map +1 -1
  117. package/dist/domain/graph/builder/stages/detect-changes.d.ts.map +1 -1
  118. package/dist/domain/graph/builder/stages/detect-changes.js +6 -6
  119. package/dist/domain/graph/builder/stages/detect-changes.js.map +1 -1
  120. package/dist/domain/graph/builder/stages/finalize.d.ts.map +1 -1
  121. package/dist/domain/graph/builder/stages/finalize.js +85 -61
  122. package/dist/domain/graph/builder/stages/finalize.js.map +1 -1
  123. package/dist/domain/graph/builder/stages/insert-nodes.d.ts.map +1 -1
  124. package/dist/domain/graph/builder/stages/insert-nodes.js.map +1 -1
  125. package/dist/domain/graph/builder/stages/resolve-imports.d.ts.map +1 -1
  126. package/dist/domain/graph/builder/stages/resolve-imports.js +58 -11
  127. package/dist/domain/graph/builder/stages/resolve-imports.js.map +1 -1
  128. package/dist/domain/graph/cycles.js +2 -2
  129. package/dist/domain/graph/cycles.js.map +1 -1
  130. package/dist/domain/graph/resolve.d.ts.map +1 -1
  131. package/dist/domain/graph/resolve.js +10 -8
  132. package/dist/domain/graph/resolve.js.map +1 -1
  133. package/dist/domain/graph/watcher.d.ts.map +1 -1
  134. package/dist/domain/graph/watcher.js +1 -3
  135. package/dist/domain/graph/watcher.js.map +1 -1
  136. package/dist/domain/parser.d.ts.map +1 -1
  137. package/dist/domain/parser.js +11 -12
  138. package/dist/domain/parser.js.map +1 -1
  139. package/dist/domain/queries.d.ts +3 -2
  140. package/dist/domain/queries.d.ts.map +1 -1
  141. package/dist/domain/queries.js +3 -2
  142. package/dist/domain/queries.js.map +1 -1
  143. package/dist/domain/search/generator.d.ts.map +1 -1
  144. package/dist/domain/search/generator.js.map +1 -1
  145. package/dist/extractors/csharp.js +2 -2
  146. package/dist/extractors/csharp.js.map +1 -1
  147. package/dist/extractors/go.js +2 -2
  148. package/dist/extractors/go.js.map +1 -1
  149. package/dist/extractors/helpers.d.ts +5 -0
  150. package/dist/extractors/helpers.d.ts.map +1 -1
  151. package/dist/extractors/helpers.js +5 -0
  152. package/dist/extractors/helpers.js.map +1 -1
  153. package/dist/extractors/javascript.js +58 -60
  154. package/dist/extractors/javascript.js.map +1 -1
  155. package/dist/extractors/php.js +2 -2
  156. package/dist/extractors/php.js.map +1 -1
  157. package/dist/extractors/python.js +2 -2
  158. package/dist/extractors/python.js.map +1 -1
  159. package/dist/extractors/rust.js +2 -2
  160. package/dist/extractors/rust.js.map +1 -1
  161. package/dist/features/audit.d.ts.map +1 -1
  162. package/dist/features/audit.js +1 -2
  163. package/dist/features/audit.js.map +1 -1
  164. package/dist/features/branch-compare.d.ts.map +1 -1
  165. package/dist/features/branch-compare.js +2 -3
  166. package/dist/features/branch-compare.js.map +1 -1
  167. package/dist/features/cfg.d.ts.map +1 -1
  168. package/dist/features/cfg.js +2 -4
  169. package/dist/features/cfg.js.map +1 -1
  170. package/dist/features/cochange.js +4 -4
  171. package/dist/features/cochange.js.map +1 -1
  172. package/dist/features/communities.js +4 -4
  173. package/dist/features/communities.js.map +1 -1
  174. package/dist/features/complexity-query.d.ts +37 -0
  175. package/dist/features/complexity-query.d.ts.map +1 -0
  176. package/dist/features/complexity-query.js +263 -0
  177. package/dist/features/complexity-query.js.map +1 -0
  178. package/dist/features/complexity.d.ts +2 -30
  179. package/dist/features/complexity.d.ts.map +1 -1
  180. package/dist/features/complexity.js +7 -261
  181. package/dist/features/complexity.js.map +1 -1
  182. package/dist/features/dataflow.d.ts.map +1 -1
  183. package/dist/features/dataflow.js +8 -24
  184. package/dist/features/dataflow.js.map +1 -1
  185. package/dist/features/export.d.ts +7 -8
  186. package/dist/features/export.d.ts.map +1 -1
  187. package/dist/features/export.js.map +1 -1
  188. package/dist/features/flow.d.ts.map +1 -1
  189. package/dist/features/flow.js.map +1 -1
  190. package/dist/features/graph-enrichment.d.ts.map +1 -1
  191. package/dist/features/graph-enrichment.js +1 -3
  192. package/dist/features/graph-enrichment.js.map +1 -1
  193. package/dist/features/manifesto.js +8 -8
  194. package/dist/features/manifesto.js.map +1 -1
  195. package/dist/features/snapshot.d.ts.map +1 -1
  196. package/dist/features/snapshot.js +0 -1
  197. package/dist/features/snapshot.js.map +1 -1
  198. package/dist/features/structure-query.d.ts +76 -0
  199. package/dist/features/structure-query.d.ts.map +1 -0
  200. package/dist/features/structure-query.js +245 -0
  201. package/dist/features/structure-query.js.map +1 -0
  202. package/dist/features/structure.d.ts +12 -67
  203. package/dist/features/structure.d.ts.map +1 -1
  204. package/dist/features/structure.js +188 -244
  205. package/dist/features/structure.js.map +1 -1
  206. package/dist/features/triage.js +2 -2
  207. package/dist/features/triage.js.map +1 -1
  208. package/dist/graph/algorithms/leiden/adapter.d.ts.map +1 -1
  209. package/dist/graph/algorithms/leiden/adapter.js +2 -9
  210. package/dist/graph/algorithms/leiden/adapter.js.map +1 -1
  211. package/dist/graph/classifiers/roles.d.ts +5 -1
  212. package/dist/graph/classifiers/roles.d.ts.map +1 -1
  213. package/dist/graph/classifiers/roles.js +20 -12
  214. package/dist/graph/classifiers/roles.js.map +1 -1
  215. package/dist/index.d.ts +1 -0
  216. package/dist/index.d.ts.map +1 -1
  217. package/dist/index.js.map +1 -1
  218. package/dist/infrastructure/config.d.ts.map +1 -1
  219. package/dist/infrastructure/config.js +12 -11
  220. package/dist/infrastructure/config.js.map +1 -1
  221. package/dist/infrastructure/native.d.ts.map +1 -1
  222. package/dist/infrastructure/native.js +7 -3
  223. package/dist/infrastructure/native.js.map +1 -1
  224. package/dist/infrastructure/registry.d.ts.map +1 -1
  225. package/dist/infrastructure/registry.js +1 -1
  226. package/dist/infrastructure/registry.js.map +1 -1
  227. package/dist/infrastructure/update-check.js +3 -3
  228. package/dist/infrastructure/update-check.js.map +1 -1
  229. package/dist/mcp/server.d.ts.map +1 -1
  230. package/dist/mcp/server.js +2 -8
  231. package/dist/mcp/server.js.map +1 -1
  232. package/dist/mcp/tool-registry.d.ts.map +1 -1
  233. package/dist/mcp/tool-registry.js +9 -4
  234. package/dist/mcp/tool-registry.js.map +1 -1
  235. package/dist/mcp/tools/audit.js +1 -1
  236. package/dist/mcp/tools/audit.js.map +1 -1
  237. package/dist/mcp/tools/cfg.js +1 -1
  238. package/dist/mcp/tools/cfg.js.map +1 -1
  239. package/dist/mcp/tools/check.js +2 -2
  240. package/dist/mcp/tools/check.js.map +1 -1
  241. package/dist/mcp/tools/dataflow.js +2 -2
  242. package/dist/mcp/tools/dataflow.js.map +1 -1
  243. package/dist/mcp/tools/export-graph.js +1 -1
  244. package/dist/mcp/tools/export-graph.js.map +1 -1
  245. package/dist/mcp/tools/index.d.ts.map +1 -1
  246. package/dist/mcp/tools/index.js.map +1 -1
  247. package/dist/mcp/tools/path.d.ts +1 -0
  248. package/dist/mcp/tools/path.d.ts.map +1 -1
  249. package/dist/mcp/tools/path.js +9 -0
  250. package/dist/mcp/tools/path.js.map +1 -1
  251. package/dist/mcp/tools/query.js +1 -1
  252. package/dist/mcp/tools/query.js.map +1 -1
  253. package/dist/mcp/tools/semantic-search.js +1 -1
  254. package/dist/mcp/tools/semantic-search.js.map +1 -1
  255. package/dist/mcp/tools/sequence.js +1 -1
  256. package/dist/mcp/tools/sequence.js.map +1 -1
  257. package/dist/mcp/tools/symbol-children.js +1 -1
  258. package/dist/mcp/tools/symbol-children.js.map +1 -1
  259. package/dist/mcp/tools/triage.js +1 -1
  260. package/dist/mcp/tools/triage.js.map +1 -1
  261. package/dist/presentation/audit.d.ts.map +1 -1
  262. package/dist/presentation/audit.js +0 -1
  263. package/dist/presentation/audit.js.map +1 -1
  264. package/dist/presentation/diff-impact-mermaid.d.ts +11 -0
  265. package/dist/presentation/diff-impact-mermaid.d.ts.map +1 -0
  266. package/dist/presentation/diff-impact-mermaid.js +105 -0
  267. package/dist/presentation/diff-impact-mermaid.js.map +1 -0
  268. package/dist/presentation/flow.d.ts.map +1 -1
  269. package/dist/presentation/flow.js +0 -2
  270. package/dist/presentation/flow.js.map +1 -1
  271. package/dist/presentation/manifesto.d.ts.map +1 -1
  272. package/dist/presentation/manifesto.js +0 -1
  273. package/dist/presentation/manifesto.js.map +1 -1
  274. package/dist/presentation/queries-cli/inspect.d.ts.map +1 -1
  275. package/dist/presentation/queries-cli/inspect.js.map +1 -1
  276. package/dist/presentation/queries-cli/path.d.ts.map +1 -1
  277. package/dist/presentation/queries-cli/path.js +45 -1
  278. package/dist/presentation/queries-cli/path.js.map +1 -1
  279. package/dist/presentation/result-formatter.d.ts.map +1 -1
  280. package/dist/presentation/result-formatter.js +1 -3
  281. package/dist/presentation/result-formatter.js.map +1 -1
  282. package/dist/presentation/sequence.d.ts.map +1 -1
  283. package/dist/presentation/sequence.js +0 -1
  284. package/dist/presentation/sequence.js.map +1 -1
  285. package/dist/presentation/structure.d.ts.map +1 -1
  286. package/dist/presentation/structure.js.map +1 -1
  287. package/dist/presentation/triage.d.ts.map +1 -1
  288. package/dist/presentation/triage.js +0 -1
  289. package/dist/presentation/triage.js.map +1 -1
  290. package/dist/shared/constants.d.ts +9 -3
  291. package/dist/shared/constants.d.ts.map +1 -1
  292. package/dist/shared/constants.js +6 -3
  293. package/dist/shared/constants.js.map +1 -1
  294. package/dist/shared/errors.d.ts +2 -0
  295. package/dist/shared/errors.d.ts.map +1 -1
  296. package/dist/shared/errors.js +4 -0
  297. package/dist/shared/errors.js.map +1 -1
  298. package/dist/shared/version.d.ts +2 -0
  299. package/dist/shared/version.d.ts.map +1 -0
  300. package/dist/shared/version.js +5 -0
  301. package/dist/shared/version.js.map +1 -0
  302. package/dist/types.d.ts +2 -2
  303. package/dist/types.d.ts.map +1 -1
  304. package/package.json +8 -7
  305. package/src/ast-analysis/engine.ts +3 -9
  306. package/src/ast-analysis/shared.ts +0 -1
  307. package/src/ast-analysis/visitors/cfg-conditionals.ts +227 -0
  308. package/src/ast-analysis/visitors/cfg-loops.ts +136 -0
  309. package/src/ast-analysis/visitors/cfg-shared.ts +196 -0
  310. package/src/ast-analysis/visitors/cfg-try-catch.ts +142 -0
  311. package/src/ast-analysis/visitors/cfg-visitor.ts +34 -655
  312. package/src/ast-analysis/visitors/complexity-visitor.ts +0 -1
  313. package/src/ast-analysis/visitors/dataflow-visitor.ts +0 -1
  314. package/src/cli/commands/batch.ts +4 -3
  315. package/src/cli/commands/branch-compare.ts +1 -1
  316. package/src/cli/commands/build.ts +1 -1
  317. package/src/cli/commands/info.ts +1 -2
  318. package/src/cli/commands/path.ts +7 -2
  319. package/src/cli/commands/plot.ts +2 -2
  320. package/src/cli/commands/watch.ts +1 -1
  321. package/src/cli/index.ts +2 -2
  322. package/src/cli/shared/open-graph.ts +2 -2
  323. package/src/cli/types.ts +1 -1
  324. package/src/cli.ts +2 -3
  325. package/src/db/connection.ts +97 -13
  326. package/src/db/index.ts +2 -0
  327. package/src/db/migrations.ts +7 -0
  328. package/src/domain/analysis/brief.ts +0 -1
  329. package/src/domain/analysis/context.ts +2 -6
  330. package/src/domain/analysis/dependencies.ts +165 -0
  331. package/src/domain/analysis/diff-impact.ts +354 -0
  332. package/src/domain/analysis/exports.ts +0 -2
  333. package/src/domain/analysis/fn-impact.ts +241 -0
  334. package/src/domain/analysis/impact.ts +8 -718
  335. package/src/domain/analysis/module-map.ts +1 -5
  336. package/src/domain/graph/builder/context.ts +2 -2
  337. package/src/domain/graph/builder/helpers.ts +14 -11
  338. package/src/domain/graph/builder/incremental.ts +33 -28
  339. package/src/domain/graph/builder/pipeline.ts +8 -0
  340. package/src/domain/graph/builder/stages/build-edges.ts +17 -4
  341. package/src/domain/graph/builder/stages/build-structure.ts +205 -76
  342. package/src/domain/graph/builder/stages/detect-changes.ts +11 -12
  343. package/src/domain/graph/builder/stages/finalize.ts +100 -81
  344. package/src/domain/graph/builder/stages/insert-nodes.ts +12 -8
  345. package/src/domain/graph/builder/stages/resolve-imports.ts +75 -10
  346. package/src/domain/graph/cycles.ts +2 -2
  347. package/src/domain/graph/resolve.ts +14 -8
  348. package/src/domain/graph/watcher.ts +2 -4
  349. package/src/domain/parser.ts +11 -13
  350. package/src/domain/queries.ts +2 -2
  351. package/src/domain/search/generator.ts +3 -4
  352. package/src/extractors/csharp.ts +2 -2
  353. package/src/extractors/go.ts +2 -2
  354. package/src/extractors/helpers.ts +6 -0
  355. package/src/extractors/javascript.ts +58 -61
  356. package/src/extractors/php.ts +2 -2
  357. package/src/extractors/python.ts +2 -2
  358. package/src/extractors/rust.ts +2 -2
  359. package/src/features/audit.ts +1 -2
  360. package/src/features/branch-compare.ts +3 -9
  361. package/src/features/cfg.ts +2 -4
  362. package/src/features/cochange.ts +4 -4
  363. package/src/features/communities.ts +4 -4
  364. package/src/features/complexity-query.ts +370 -0
  365. package/src/features/complexity.ts +6 -365
  366. package/src/features/dataflow.ts +48 -70
  367. package/src/features/export.ts +12 -16
  368. package/src/features/flow.ts +0 -1
  369. package/src/features/graph-enrichment.ts +1 -3
  370. package/src/features/manifesto.ts +8 -8
  371. package/src/features/snapshot.ts +1 -2
  372. package/src/features/structure-query.ts +387 -0
  373. package/src/features/structure.ts +231 -376
  374. package/src/features/triage.ts +2 -2
  375. package/src/graph/algorithms/leiden/adapter.ts +2 -9
  376. package/src/graph/classifiers/roles.ts +22 -13
  377. package/src/index.ts +1 -0
  378. package/src/infrastructure/config.ts +12 -13
  379. package/src/infrastructure/native.ts +7 -3
  380. package/src/infrastructure/registry.ts +1 -1
  381. package/src/infrastructure/update-check.ts +3 -3
  382. package/src/mcp/server.ts +2 -10
  383. package/src/mcp/tool-registry.ts +11 -4
  384. package/src/mcp/tools/audit.ts +1 -1
  385. package/src/mcp/tools/cfg.ts +1 -1
  386. package/src/mcp/tools/check.ts +2 -2
  387. package/src/mcp/tools/dataflow.ts +2 -2
  388. package/src/mcp/tools/export-graph.ts +1 -1
  389. package/src/mcp/tools/index.ts +0 -1
  390. package/src/mcp/tools/path.ts +10 -0
  391. package/src/mcp/tools/query.ts +1 -1
  392. package/src/mcp/tools/semantic-search.ts +1 -1
  393. package/src/mcp/tools/sequence.ts +1 -1
  394. package/src/mcp/tools/symbol-children.ts +1 -1
  395. package/src/mcp/tools/triage.ts +1 -1
  396. package/src/presentation/audit.ts +0 -1
  397. package/src/presentation/diff-impact-mermaid.ts +127 -0
  398. package/src/presentation/flow.ts +0 -2
  399. package/src/presentation/manifesto.ts +0 -1
  400. package/src/presentation/queries-cli/inspect.ts +0 -1
  401. package/src/presentation/queries-cli/path.ts +71 -1
  402. package/src/presentation/result-formatter.ts +0 -1
  403. package/src/presentation/sequence.ts +0 -1
  404. package/src/presentation/structure.ts +0 -12
  405. package/src/presentation/triage.ts +0 -1
  406. package/src/shared/constants.ts +33 -19
  407. package/src/shared/errors.ts +5 -0
  408. package/src/shared/version.ts +10 -0
  409. package/src/types.ts +4 -10
  410. package/src/vendor.d.ts +0 -39
@@ -0,0 +1,370 @@
1
+ /**
2
+ * Complexity query functions — read-only DB queries for complexity metrics.
3
+ *
4
+ * Split from complexity.ts to separate query-time concerns (DB reads, filtering,
5
+ * pagination) from compute-time concerns (AST traversal, metric algorithms).
6
+ */
7
+
8
+ import { openReadonlyOrFail } from '../db/index.js';
9
+ import { buildFileConditionSQL } from '../db/query-builder.js';
10
+ import { loadConfig } from '../infrastructure/config.js';
11
+ import { debug } from '../infrastructure/logger.js';
12
+ import { isTestFile } from '../infrastructure/test-filter.js';
13
+ import { paginateResult } from '../shared/paginate.js';
14
+ import type { CodegraphConfig } from '../types.js';
15
+
16
+ // ─── Query-Time Functions ─────────────────────────────────────────────────
17
+
18
+ interface ComplexityRow {
19
+ name: string;
20
+ kind: string;
21
+ file: string;
22
+ line: number;
23
+ end_line: number | null;
24
+ cognitive: number;
25
+ cyclomatic: number;
26
+ max_nesting: number;
27
+ loc: number;
28
+ sloc: number;
29
+ maintainability_index: number;
30
+ halstead_volume: number;
31
+ halstead_difficulty: number;
32
+ halstead_effort: number;
33
+ halstead_bugs: number;
34
+ }
35
+
36
+ export function complexityData(
37
+ customDbPath?: string,
38
+ opts: {
39
+ target?: string;
40
+ limit?: number;
41
+ sort?: string;
42
+ aboveThreshold?: boolean;
43
+ file?: string;
44
+ kind?: string;
45
+ noTests?: boolean;
46
+ config?: CodegraphConfig;
47
+ offset?: number;
48
+ } = {},
49
+ ): Record<string, unknown> {
50
+ const db = openReadonlyOrFail(customDbPath);
51
+ try {
52
+ const sort = opts.sort || 'cognitive';
53
+ const noTests = opts.noTests || false;
54
+ const aboveThreshold = opts.aboveThreshold || false;
55
+ const target = opts.target || null;
56
+ const fileFilter = opts.file || null;
57
+ const kindFilter = opts.kind || null;
58
+
59
+ // Load thresholds from config
60
+ const config = opts.config || loadConfig(process.cwd());
61
+ const thresholds: any = config.manifesto?.rules || {
62
+ cognitive: { warn: 15, fail: null },
63
+ cyclomatic: { warn: 10, fail: null },
64
+ maxNesting: { warn: 4, fail: null },
65
+ maintainabilityIndex: { warn: 20, fail: null },
66
+ };
67
+
68
+ // Build query
69
+ let where = "WHERE n.kind IN ('function','method')";
70
+ const params: unknown[] = [];
71
+
72
+ if (noTests) {
73
+ where += ` AND n.file NOT LIKE '%.test.%'
74
+ AND n.file NOT LIKE '%.spec.%'
75
+ AND n.file NOT LIKE '%__test__%'
76
+ AND n.file NOT LIKE '%__tests__%'
77
+ AND n.file NOT LIKE '%.stories.%'`;
78
+ }
79
+ if (target) {
80
+ where += ' AND n.name LIKE ?';
81
+ params.push(`%${target}%`);
82
+ }
83
+ {
84
+ const fc = buildFileConditionSQL(fileFilter as string, 'n.file');
85
+ where += fc.sql;
86
+ params.push(...fc.params);
87
+ }
88
+ if (kindFilter) {
89
+ where += ' AND n.kind = ?';
90
+ params.push(kindFilter);
91
+ }
92
+
93
+ const isValidThreshold = (v: unknown): v is number =>
94
+ typeof v === 'number' && Number.isFinite(v);
95
+
96
+ let having = '';
97
+ if (aboveThreshold) {
98
+ const conditions: string[] = [];
99
+ if (isValidThreshold(thresholds.cognitive?.warn)) {
100
+ conditions.push(`fc.cognitive >= ${thresholds.cognitive.warn}`);
101
+ }
102
+ if (isValidThreshold(thresholds.cyclomatic?.warn)) {
103
+ conditions.push(`fc.cyclomatic >= ${thresholds.cyclomatic.warn}`);
104
+ }
105
+ if (isValidThreshold(thresholds.maxNesting?.warn)) {
106
+ conditions.push(`fc.max_nesting >= ${thresholds.maxNesting.warn}`);
107
+ }
108
+ if (isValidThreshold(thresholds.maintainabilityIndex?.warn)) {
109
+ conditions.push(
110
+ `fc.maintainability_index > 0 AND fc.maintainability_index <= ${thresholds.maintainabilityIndex.warn}`,
111
+ );
112
+ }
113
+ if (conditions.length > 0) {
114
+ having = `AND (${conditions.join(' OR ')})`;
115
+ }
116
+ }
117
+
118
+ const orderMap: Record<string, string> = {
119
+ cognitive: 'fc.cognitive DESC',
120
+ cyclomatic: 'fc.cyclomatic DESC',
121
+ nesting: 'fc.max_nesting DESC',
122
+ mi: 'fc.maintainability_index ASC',
123
+ volume: 'fc.halstead_volume DESC',
124
+ effort: 'fc.halstead_effort DESC',
125
+ bugs: 'fc.halstead_bugs DESC',
126
+ loc: 'fc.loc DESC',
127
+ };
128
+ const orderBy = orderMap[sort] || 'fc.cognitive DESC';
129
+
130
+ let rows: ComplexityRow[];
131
+ try {
132
+ rows = db
133
+ .prepare<ComplexityRow>(
134
+ `SELECT n.name, n.kind, n.file, n.line, n.end_line,
135
+ fc.cognitive, fc.cyclomatic, fc.max_nesting,
136
+ fc.loc, fc.sloc, fc.maintainability_index,
137
+ fc.halstead_volume, fc.halstead_difficulty, fc.halstead_effort, fc.halstead_bugs
138
+ FROM function_complexity fc
139
+ JOIN nodes n ON fc.node_id = n.id
140
+ ${where} ${having}
141
+ ORDER BY ${orderBy}`,
142
+ )
143
+ .all(...params);
144
+ } catch (e: unknown) {
145
+ debug(`complexity query failed (table may not exist): ${(e as Error).message}`);
146
+ // Check if graph has nodes even though complexity table is missing/empty
147
+ let hasGraph = false;
148
+ try {
149
+ hasGraph = (db.prepare<{ c: number }>('SELECT COUNT(*) as c FROM nodes').get()?.c ?? 0) > 0;
150
+ } catch (e2: unknown) {
151
+ debug(`nodes table check failed: ${(e2 as Error).message}`);
152
+ }
153
+ return { functions: [], summary: null, thresholds, hasGraph };
154
+ }
155
+
156
+ // Post-filter test files if needed (belt-and-suspenders for isTestFile)
157
+ const filtered = noTests ? rows.filter((r) => !isTestFile(r.file)) : rows;
158
+
159
+ const functions = filtered.map((r) => {
160
+ const exceeds: string[] = [];
161
+ if (
162
+ isValidThreshold(thresholds.cognitive?.warn) &&
163
+ r.cognitive >= (thresholds.cognitive?.warn ?? 0)
164
+ )
165
+ exceeds.push('cognitive');
166
+ if (
167
+ isValidThreshold(thresholds.cyclomatic?.warn) &&
168
+ r.cyclomatic >= (thresholds.cyclomatic?.warn ?? 0)
169
+ )
170
+ exceeds.push('cyclomatic');
171
+ if (
172
+ isValidThreshold(thresholds.maxNesting?.warn) &&
173
+ r.max_nesting >= (thresholds.maxNesting?.warn ?? 0)
174
+ )
175
+ exceeds.push('maxNesting');
176
+ if (
177
+ isValidThreshold(thresholds.maintainabilityIndex?.warn) &&
178
+ r.maintainability_index > 0 &&
179
+ r.maintainability_index <= (thresholds.maintainabilityIndex?.warn ?? 0)
180
+ )
181
+ exceeds.push('maintainabilityIndex');
182
+
183
+ return {
184
+ name: r.name,
185
+ kind: r.kind,
186
+ file: r.file,
187
+ line: r.line,
188
+ endLine: r.end_line || null,
189
+ cognitive: r.cognitive,
190
+ cyclomatic: r.cyclomatic,
191
+ maxNesting: r.max_nesting,
192
+ loc: r.loc || 0,
193
+ sloc: r.sloc || 0,
194
+ maintainabilityIndex: r.maintainability_index || 0,
195
+ halstead: {
196
+ volume: r.halstead_volume || 0,
197
+ difficulty: r.halstead_difficulty || 0,
198
+ effort: r.halstead_effort || 0,
199
+ bugs: r.halstead_bugs || 0,
200
+ },
201
+ exceeds: exceeds.length > 0 ? exceeds : undefined,
202
+ };
203
+ });
204
+
205
+ // Summary stats
206
+ let summary: Record<string, unknown> | null = null;
207
+ try {
208
+ const allRows = db
209
+ .prepare<{
210
+ cognitive: number;
211
+ cyclomatic: number;
212
+ max_nesting: number;
213
+ maintainability_index: number;
214
+ }>(
215
+ `SELECT fc.cognitive, fc.cyclomatic, fc.max_nesting, fc.maintainability_index
216
+ FROM function_complexity fc JOIN nodes n ON fc.node_id = n.id
217
+ WHERE n.kind IN ('function','method')
218
+ ${noTests ? `AND n.file NOT LIKE '%.test.%' AND n.file NOT LIKE '%.spec.%' AND n.file NOT LIKE '%__test__%' AND n.file NOT LIKE '%__tests__%' AND n.file NOT LIKE '%.stories.%'` : ''}`,
219
+ )
220
+ .all();
221
+
222
+ if (allRows.length > 0) {
223
+ const miValues = allRows.map((r) => r.maintainability_index || 0);
224
+ summary = {
225
+ analyzed: allRows.length,
226
+ avgCognitive: +(allRows.reduce((s, r) => s + r.cognitive, 0) / allRows.length).toFixed(1),
227
+ avgCyclomatic: +(allRows.reduce((s, r) => s + r.cyclomatic, 0) / allRows.length).toFixed(
228
+ 1,
229
+ ),
230
+ maxCognitive: Math.max(...allRows.map((r) => r.cognitive)),
231
+ maxCyclomatic: Math.max(...allRows.map((r) => r.cyclomatic)),
232
+ avgMI: +(miValues.reduce((s, v) => s + v, 0) / miValues.length).toFixed(1),
233
+ minMI: +Math.min(...miValues).toFixed(1),
234
+ aboveWarn: allRows.filter(
235
+ (r) =>
236
+ (isValidThreshold(thresholds.cognitive?.warn) &&
237
+ r.cognitive >= (thresholds.cognitive?.warn ?? 0)) ||
238
+ (isValidThreshold(thresholds.cyclomatic?.warn) &&
239
+ r.cyclomatic >= (thresholds.cyclomatic?.warn ?? 0)) ||
240
+ (isValidThreshold(thresholds.maxNesting?.warn) &&
241
+ r.max_nesting >= (thresholds.maxNesting?.warn ?? 0)) ||
242
+ (isValidThreshold(thresholds.maintainabilityIndex?.warn) &&
243
+ r.maintainability_index > 0 &&
244
+ r.maintainability_index <= (thresholds.maintainabilityIndex?.warn ?? 0)),
245
+ ).length,
246
+ };
247
+ }
248
+ } catch (e: unknown) {
249
+ debug(`complexity summary query failed: ${(e as Error).message}`);
250
+ }
251
+
252
+ // When summary is null (no complexity rows), check if graph has nodes
253
+ let hasGraph = false;
254
+ if (summary === null) {
255
+ try {
256
+ hasGraph = (db.prepare<{ c: number }>('SELECT COUNT(*) as c FROM nodes').get()?.c ?? 0) > 0;
257
+ } catch (e: unknown) {
258
+ debug(`nodes table check failed: ${(e as Error).message}`);
259
+ }
260
+ }
261
+
262
+ const base = { functions, summary, thresholds, hasGraph };
263
+ return paginateResult(base, 'functions', { limit: opts.limit, offset: opts.offset });
264
+ } finally {
265
+ db.close();
266
+ }
267
+ }
268
+
269
+ interface IterComplexityRow {
270
+ name: string;
271
+ kind: string;
272
+ file: string;
273
+ line: number;
274
+ end_line: number | null;
275
+ cognitive: number;
276
+ cyclomatic: number;
277
+ max_nesting: number;
278
+ loc: number;
279
+ sloc: number;
280
+ }
281
+
282
+ export function* iterComplexity(
283
+ customDbPath?: string,
284
+ opts: {
285
+ noTests?: boolean;
286
+ file?: string;
287
+ target?: string;
288
+ kind?: string;
289
+ sort?: string;
290
+ } = {},
291
+ ): Generator<{
292
+ name: string;
293
+ kind: string;
294
+ file: string;
295
+ line: number;
296
+ endLine: number | null;
297
+ cognitive: number;
298
+ cyclomatic: number;
299
+ maxNesting: number;
300
+ loc: number;
301
+ sloc: number;
302
+ }> {
303
+ const db = openReadonlyOrFail(customDbPath);
304
+ try {
305
+ const noTests = opts.noTests || false;
306
+ const sort = opts.sort || 'cognitive';
307
+
308
+ let where = "WHERE n.kind IN ('function','method')";
309
+ const params: unknown[] = [];
310
+
311
+ if (noTests) {
312
+ where += ` AND n.file NOT LIKE '%.test.%'
313
+ AND n.file NOT LIKE '%.spec.%'
314
+ AND n.file NOT LIKE '%__test__%'
315
+ AND n.file NOT LIKE '%__tests__%'
316
+ AND n.file NOT LIKE '%.stories.%'`;
317
+ }
318
+ if (opts.target) {
319
+ where += ' AND n.name LIKE ?';
320
+ params.push(`%${opts.target}%`);
321
+ }
322
+ {
323
+ const fc = buildFileConditionSQL(opts.file as string, 'n.file');
324
+ where += fc.sql;
325
+ params.push(...fc.params);
326
+ }
327
+ if (opts.kind) {
328
+ where += ' AND n.kind = ?';
329
+ params.push(opts.kind);
330
+ }
331
+
332
+ const orderMap: Record<string, string> = {
333
+ cognitive: 'fc.cognitive DESC',
334
+ cyclomatic: 'fc.cyclomatic DESC',
335
+ nesting: 'fc.max_nesting DESC',
336
+ mi: 'fc.maintainability_index ASC',
337
+ volume: 'fc.halstead_volume DESC',
338
+ effort: 'fc.halstead_effort DESC',
339
+ bugs: 'fc.halstead_bugs DESC',
340
+ loc: 'fc.loc DESC',
341
+ };
342
+ const orderBy = orderMap[sort] || 'fc.cognitive DESC';
343
+
344
+ const stmt = db.prepare<IterComplexityRow>(
345
+ `SELECT n.name, n.kind, n.file, n.line, n.end_line,
346
+ fc.cognitive, fc.cyclomatic, fc.max_nesting, fc.loc, fc.sloc
347
+ FROM function_complexity fc
348
+ JOIN nodes n ON fc.node_id = n.id
349
+ ${where}
350
+ ORDER BY ${orderBy}`,
351
+ );
352
+ for (const r of stmt.iterate(...params)) {
353
+ if (noTests && isTestFile(r.file)) continue;
354
+ yield {
355
+ name: r.name,
356
+ kind: r.kind,
357
+ file: r.file,
358
+ line: r.line,
359
+ endLine: r.end_line || null,
360
+ cognitive: r.cognitive,
361
+ cyclomatic: r.cyclomatic,
362
+ maxNesting: r.max_nesting,
363
+ loc: r.loc || 0,
364
+ sloc: r.sloc || 0,
365
+ };
366
+ }
367
+ } finally {
368
+ db.close();
369
+ }
370
+ }