projscan 0.11.0 → 0.14.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 (278) hide show
  1. package/README.md +57 -33
  2. package/dist/analyzers/crossPackageImportCheck.d.ts +13 -0
  3. package/dist/analyzers/crossPackageImportCheck.js +136 -0
  4. package/dist/analyzers/crossPackageImportCheck.js.map +1 -0
  5. package/dist/analyzers/cycleCheck.d.ts +12 -0
  6. package/dist/analyzers/cycleCheck.js +65 -0
  7. package/dist/analyzers/cycleCheck.js.map +1 -0
  8. package/dist/analyzers/unusedDependencyCheck.js +69 -17
  9. package/dist/analyzers/unusedDependencyCheck.js.map +1 -1
  10. package/dist/cli/_shared.d.ts +16 -0
  11. package/dist/cli/_shared.js +210 -0
  12. package/dist/cli/_shared.js.map +1 -0
  13. package/dist/cli/commands/analyze.d.ts +1 -0
  14. package/dist/cli/commands/analyze.js +87 -0
  15. package/dist/cli/commands/analyze.js.map +1 -0
  16. package/dist/cli/commands/audit.d.ts +1 -0
  17. package/dist/cli/commands/audit.js +53 -0
  18. package/dist/cli/commands/audit.js.map +1 -0
  19. package/dist/cli/commands/badge.d.ts +1 -0
  20. package/dist/cli/commands/badge.js +45 -0
  21. package/dist/cli/commands/badge.js.map +1 -0
  22. package/dist/cli/commands/ci.d.ts +1 -0
  23. package/dist/cli/commands/ci.js +57 -0
  24. package/dist/cli/commands/ci.js.map +1 -0
  25. package/dist/cli/commands/coupling.d.ts +1 -0
  26. package/dist/cli/commands/coupling.js +83 -0
  27. package/dist/cli/commands/coupling.js.map +1 -0
  28. package/dist/cli/commands/coverage.d.ts +1 -0
  29. package/dist/cli/commands/coverage.js +63 -0
  30. package/dist/cli/commands/coverage.js.map +1 -0
  31. package/dist/cli/commands/dependencies.d.ts +1 -0
  32. package/dist/cli/commands/dependencies.js +46 -0
  33. package/dist/cli/commands/dependencies.js.map +1 -0
  34. package/dist/cli/commands/diagram.d.ts +1 -0
  35. package/dist/cli/commands/diagram.js +45 -0
  36. package/dist/cli/commands/diagram.js.map +1 -0
  37. package/dist/cli/commands/diff.d.ts +1 -0
  38. package/dist/cli/commands/diff.js +70 -0
  39. package/dist/cli/commands/diff.js.map +1 -0
  40. package/dist/cli/commands/doctor.d.ts +1 -0
  41. package/dist/cli/commands/doctor.js +62 -0
  42. package/dist/cli/commands/doctor.js.map +1 -0
  43. package/dist/cli/commands/explain.d.ts +1 -0
  44. package/dist/cli/commands/explain.js +42 -0
  45. package/dist/cli/commands/explain.js.map +1 -0
  46. package/dist/cli/commands/explainIssue.d.ts +1 -0
  47. package/dist/cli/commands/explainIssue.js +49 -0
  48. package/dist/cli/commands/explainIssue.js.map +1 -0
  49. package/dist/cli/commands/file.d.ts +1 -0
  50. package/dist/cli/commands/file.js +45 -0
  51. package/dist/cli/commands/file.js.map +1 -0
  52. package/dist/cli/commands/fix.d.ts +1 -0
  53. package/dist/cli/commands/fix.js +70 -0
  54. package/dist/cli/commands/fix.js.map +1 -0
  55. package/dist/cli/commands/fixSuggest.d.ts +1 -0
  56. package/dist/cli/commands/fixSuggest.js +71 -0
  57. package/dist/cli/commands/fixSuggest.js.map +1 -0
  58. package/dist/cli/commands/help.d.ts +1 -0
  59. package/dist/cli/commands/help.js +11 -0
  60. package/dist/cli/commands/help.js.map +1 -0
  61. package/dist/cli/commands/hotspots.d.ts +1 -0
  62. package/dist/cli/commands/hotspots.js +74 -0
  63. package/dist/cli/commands/hotspots.js.map +1 -0
  64. package/dist/cli/commands/mcp.d.ts +1 -0
  65. package/dist/cli/commands/mcp.js +21 -0
  66. package/dist/cli/commands/mcp.js.map +1 -0
  67. package/dist/cli/commands/outdated.d.ts +1 -0
  68. package/dist/cli/commands/outdated.js +51 -0
  69. package/dist/cli/commands/outdated.js.map +1 -0
  70. package/dist/cli/commands/prDiff.d.ts +1 -0
  71. package/dist/cli/commands/prDiff.js +59 -0
  72. package/dist/cli/commands/prDiff.js.map +1 -0
  73. package/dist/cli/commands/review.d.ts +1 -0
  74. package/dist/cli/commands/review.js +66 -0
  75. package/dist/cli/commands/review.js.map +1 -0
  76. package/dist/cli/commands/search.d.ts +1 -0
  77. package/dist/cli/commands/search.js +233 -0
  78. package/dist/cli/commands/search.js.map +1 -0
  79. package/dist/cli/commands/structure.d.ts +1 -0
  80. package/dist/cli/commands/structure.js +58 -0
  81. package/dist/cli/commands/structure.js.map +1 -0
  82. package/dist/cli/commands/upgrade.d.ts +1 -0
  83. package/dist/cli/commands/upgrade.js +44 -0
  84. package/dist/cli/commands/upgrade.js.map +1 -0
  85. package/dist/cli/commands/workspaces.d.ts +1 -0
  86. package/dist/cli/commands/workspaces.js +35 -0
  87. package/dist/cli/commands/workspaces.js.map +1 -0
  88. package/dist/cli/index.js +51 -1416
  89. package/dist/cli/index.js.map +1 -1
  90. package/dist/core/ast.d.ts +20 -0
  91. package/dist/core/ast.js +190 -0
  92. package/dist/core/ast.js.map +1 -1
  93. package/dist/core/auditRunner.d.ts +8 -0
  94. package/dist/core/auditRunner.js +50 -1
  95. package/dist/core/auditRunner.js.map +1 -1
  96. package/dist/core/codeGraph.d.ts +7 -1
  97. package/dist/core/codeGraph.js +2 -0
  98. package/dist/core/codeGraph.js.map +1 -1
  99. package/dist/core/couplingAnalyzer.d.ts +1 -1
  100. package/dist/core/couplingAnalyzer.js +3 -3
  101. package/dist/core/dependencyAnalyzer.d.ts +15 -1
  102. package/dist/core/dependencyAnalyzer.js +115 -18
  103. package/dist/core/dependencyAnalyzer.js.map +1 -1
  104. package/dist/core/explainIssue.d.ts +9 -0
  105. package/dist/core/explainIssue.js +106 -0
  106. package/dist/core/explainIssue.js.map +1 -0
  107. package/dist/core/fileInspector.js +12 -0
  108. package/dist/core/fileInspector.js.map +1 -1
  109. package/dist/core/fixSuggest.d.ts +41 -0
  110. package/dist/core/fixSuggest.js +327 -0
  111. package/dist/core/fixSuggest.js.map +1 -0
  112. package/dist/core/hotspotAnalyzer.js +2 -2
  113. package/dist/core/indexCache.js +5 -1
  114. package/dist/core/indexCache.js.map +1 -1
  115. package/dist/core/issueEngine.js +18 -0
  116. package/dist/core/issueEngine.js.map +1 -1
  117. package/dist/core/languages/LanguageAdapter.d.ts +1 -1
  118. package/dist/core/languages/goAdapter.js +12 -5
  119. package/dist/core/languages/goAdapter.js.map +1 -1
  120. package/dist/core/languages/goCallSites.d.ts +20 -0
  121. package/dist/core/languages/goCallSites.js +42 -0
  122. package/dist/core/languages/goCallSites.js.map +1 -0
  123. package/dist/core/languages/goCyclomatic.d.ts +1 -1
  124. package/dist/core/languages/goCyclomatic.js +2 -2
  125. package/dist/core/languages/goExports.d.ts +1 -1
  126. package/dist/core/languages/goExports.js +1 -1
  127. package/dist/core/languages/goFunctions.d.ts +24 -0
  128. package/dist/core/languages/goFunctions.js +99 -0
  129. package/dist/core/languages/goFunctions.js.map +1 -0
  130. package/dist/core/languages/goManifests.d.ts +1 -1
  131. package/dist/core/languages/goManifests.js +2 -2
  132. package/dist/core/languages/javaAdapter.d.ts +2 -0
  133. package/dist/core/languages/javaAdapter.js +153 -0
  134. package/dist/core/languages/javaAdapter.js.map +1 -0
  135. package/dist/core/languages/javaCallSites.d.ts +16 -0
  136. package/dist/core/languages/javaCallSites.js +45 -0
  137. package/dist/core/languages/javaCallSites.js.map +1 -0
  138. package/dist/core/languages/javaCyclomatic.d.ts +21 -0
  139. package/dist/core/languages/javaCyclomatic.js +49 -0
  140. package/dist/core/languages/javaCyclomatic.js.map +1 -0
  141. package/dist/core/languages/javaExports.d.ts +25 -0
  142. package/dist/core/languages/javaExports.js +80 -0
  143. package/dist/core/languages/javaExports.js.map +1 -0
  144. package/dist/core/languages/javaFunctions.d.ts +22 -0
  145. package/dist/core/languages/javaFunctions.js +87 -0
  146. package/dist/core/languages/javaFunctions.js.map +1 -0
  147. package/dist/core/languages/javaImports.d.ts +25 -0
  148. package/dist/core/languages/javaImports.js +49 -0
  149. package/dist/core/languages/javaImports.js.map +1 -0
  150. package/dist/core/languages/javaManifests.d.ts +25 -0
  151. package/dist/core/languages/javaManifests.js +86 -0
  152. package/dist/core/languages/javaManifests.js.map +1 -0
  153. package/dist/core/languages/pythonAdapter.js +8 -1
  154. package/dist/core/languages/pythonAdapter.js.map +1 -1
  155. package/dist/core/languages/pythonCallSites.d.ts +19 -0
  156. package/dist/core/languages/pythonCallSites.js +40 -0
  157. package/dist/core/languages/pythonCallSites.js.map +1 -0
  158. package/dist/core/languages/pythonFunctions.d.ts +23 -0
  159. package/dist/core/languages/pythonFunctions.js +87 -0
  160. package/dist/core/languages/pythonFunctions.js.map +1 -0
  161. package/dist/core/languages/registry.js +3 -1
  162. package/dist/core/languages/registry.js.map +1 -1
  163. package/dist/core/languages/rubyAdapter.d.ts +2 -0
  164. package/dist/core/languages/rubyAdapter.js +136 -0
  165. package/dist/core/languages/rubyAdapter.js.map +1 -0
  166. package/dist/core/languages/rubyCallSites.d.ts +16 -0
  167. package/dist/core/languages/rubyCallSites.js +34 -0
  168. package/dist/core/languages/rubyCallSites.js.map +1 -0
  169. package/dist/core/languages/rubyCyclomatic.d.ts +19 -0
  170. package/dist/core/languages/rubyCyclomatic.js +47 -0
  171. package/dist/core/languages/rubyCyclomatic.js.map +1 -0
  172. package/dist/core/languages/rubyExports.d.ts +24 -0
  173. package/dist/core/languages/rubyExports.js +53 -0
  174. package/dist/core/languages/rubyExports.js.map +1 -0
  175. package/dist/core/languages/rubyFunctions.d.ts +22 -0
  176. package/dist/core/languages/rubyFunctions.js +91 -0
  177. package/dist/core/languages/rubyFunctions.js.map +1 -0
  178. package/dist/core/languages/rubyImports.d.ts +12 -0
  179. package/dist/core/languages/rubyImports.js +75 -0
  180. package/dist/core/languages/rubyImports.js.map +1 -0
  181. package/dist/core/languages/rubyManifests.d.ts +20 -0
  182. package/dist/core/languages/rubyManifests.js +55 -0
  183. package/dist/core/languages/rubyManifests.js.map +1 -0
  184. package/dist/core/languages/treeSitterLoader.js +3 -1
  185. package/dist/core/languages/treeSitterLoader.js.map +1 -1
  186. package/dist/core/monorepo.js +5 -5
  187. package/dist/core/outdatedDetector.d.ts +13 -2
  188. package/dist/core/outdatedDetector.js +86 -16
  189. package/dist/core/outdatedDetector.js.map +1 -1
  190. package/dist/core/prDiff.d.ts +1 -1
  191. package/dist/core/prDiff.js +2 -2
  192. package/dist/core/review.d.ts +21 -0
  193. package/dist/core/review.js +457 -0
  194. package/dist/core/review.js.map +1 -0
  195. package/dist/grammars/tree-sitter-java.wasm +0 -0
  196. package/dist/grammars/tree-sitter-ruby.wasm +0 -0
  197. package/dist/index.d.ts +5 -1
  198. package/dist/index.js +3 -0
  199. package/dist/index.js.map +1 -1
  200. package/dist/mcp/server.js +0 -22
  201. package/dist/mcp/server.js.map +1 -1
  202. package/dist/mcp/tools/_shared.d.ts +24 -0
  203. package/dist/mcp/tools/_shared.js +82 -0
  204. package/dist/mcp/tools/_shared.js.map +1 -0
  205. package/dist/mcp/tools/analyze.d.ts +2 -0
  206. package/dist/mcp/tools/analyze.js +55 -0
  207. package/dist/mcp/tools/analyze.js.map +1 -0
  208. package/dist/mcp/tools/audit.d.ts +2 -0
  209. package/dist/mcp/tools/audit.js +37 -0
  210. package/dist/mcp/tools/audit.js.map +1 -0
  211. package/dist/mcp/tools/coupling.d.ts +2 -0
  212. package/dist/mcp/tools/coupling.js +67 -0
  213. package/dist/mcp/tools/coupling.js.map +1 -0
  214. package/dist/mcp/tools/coverage.d.ts +2 -0
  215. package/dist/mcp/tools/coverage.js +53 -0
  216. package/dist/mcp/tools/coverage.js.map +1 -0
  217. package/dist/mcp/tools/dependencies.d.ts +2 -0
  218. package/dist/mcp/tools/dependencies.js +22 -0
  219. package/dist/mcp/tools/dependencies.js.map +1 -0
  220. package/dist/mcp/tools/doctor.d.ts +2 -0
  221. package/dist/mcp/tools/doctor.js +30 -0
  222. package/dist/mcp/tools/doctor.js.map +1 -0
  223. package/dist/mcp/tools/explain.d.ts +2 -0
  224. package/dist/mcp/tools/explain.js +30 -0
  225. package/dist/mcp/tools/explain.js.map +1 -0
  226. package/dist/mcp/tools/explainIssue.d.ts +2 -0
  227. package/dist/mcp/tools/explainIssue.js +30 -0
  228. package/dist/mcp/tools/explainIssue.js.map +1 -0
  229. package/dist/mcp/tools/file.d.ts +2 -0
  230. package/dist/mcp/tools/file.js +22 -0
  231. package/dist/mcp/tools/file.js.map +1 -0
  232. package/dist/mcp/tools/fixSuggest.d.ts +2 -0
  233. package/dist/mcp/tools/fixSuggest.js +57 -0
  234. package/dist/mcp/tools/fixSuggest.js.map +1 -0
  235. package/dist/mcp/tools/graph.d.ts +2 -0
  236. package/dist/mcp/tools/graph.js +69 -0
  237. package/dist/mcp/tools/graph.js.map +1 -0
  238. package/dist/mcp/tools/hotspots.d.ts +2 -0
  239. package/dist/mcp/tools/hotspots.js +103 -0
  240. package/dist/mcp/tools/hotspots.js.map +1 -0
  241. package/dist/mcp/tools/outdated.d.ts +2 -0
  242. package/dist/mcp/tools/outdated.js +36 -0
  243. package/dist/mcp/tools/outdated.js.map +1 -0
  244. package/dist/mcp/tools/prDiff.d.ts +2 -0
  245. package/dist/mcp/tools/prDiff.js +38 -0
  246. package/dist/mcp/tools/prDiff.js.map +1 -0
  247. package/dist/mcp/tools/review.d.ts +2 -0
  248. package/dist/mcp/tools/review.js +54 -0
  249. package/dist/mcp/tools/review.js.map +1 -0
  250. package/dist/mcp/tools/search.d.ts +2 -0
  251. package/dist/mcp/tools/search.js +167 -0
  252. package/dist/mcp/tools/search.js.map +1 -0
  253. package/dist/mcp/tools/structure.d.ts +2 -0
  254. package/dist/mcp/tools/structure.js +34 -0
  255. package/dist/mcp/tools/structure.js.map +1 -0
  256. package/dist/mcp/tools/upgrade.d.ts +2 -0
  257. package/dist/mcp/tools/upgrade.js +38 -0
  258. package/dist/mcp/tools/upgrade.js.map +1 -0
  259. package/dist/mcp/tools/workspaces.d.ts +2 -0
  260. package/dist/mcp/tools/workspaces.js +13 -0
  261. package/dist/mcp/tools/workspaces.js.map +1 -0
  262. package/dist/mcp/tools.d.ts +12 -6
  263. package/dist/mcp/tools.js +46 -854
  264. package/dist/mcp/tools.js.map +1 -1
  265. package/dist/reporters/consoleReporter.d.ts +9 -1
  266. package/dist/reporters/consoleReporter.js +177 -0
  267. package/dist/reporters/consoleReporter.js.map +1 -1
  268. package/dist/reporters/jsonReporter.d.ts +9 -1
  269. package/dist/reporters/jsonReporter.js +9 -0
  270. package/dist/reporters/jsonReporter.js.map +1 -1
  271. package/dist/reporters/markdownReporter.d.ts +9 -1
  272. package/dist/reporters/markdownReporter.js +141 -0
  273. package/dist/reporters/markdownReporter.js.map +1 -1
  274. package/dist/tool-manifest.json +446 -0
  275. package/dist/types.d.ts +235 -5
  276. package/dist/utils/config.js +26 -9
  277. package/dist/utils/config.js.map +1 -1
  278. package/package.json +8 -3
package/dist/mcp/tools.js CHANGED
@@ -1,844 +1,52 @@
1
- import path from 'node:path';
2
- import fs from 'node:fs/promises';
3
- import { scanRepository } from '../core/repositoryScanner.js';
4
- import { detectLanguages } from '../core/languageDetector.js';
5
- import { detectFrameworks } from '../core/frameworkDetector.js';
6
- import { analyzeDependencies } from '../core/dependencyAnalyzer.js';
7
- import { collectIssues } from '../core/issueEngine.js';
8
- import { analyzeHotspots } from '../core/hotspotAnalyzer.js';
9
- import { detectOutdated } from '../core/outdatedDetector.js';
10
- import { runAudit } from '../core/auditRunner.js';
11
- import { previewUpgrade } from '../core/upgradePreview.js';
12
- import { parseCoverage, coverageMap } from '../core/coverageParser.js';
13
- import { joinCoverageWithHotspots } from '../core/coverageJoin.js';
14
- import { buildCodeGraph, filesImportingFile, filesImportingPackage, filesDefiningSymbol, exportsOf, importsOf, } from '../core/codeGraph.js';
15
- import { loadCachedGraph, saveCachedGraph } from '../core/indexCache.js';
16
- import { computeCoupling, filterCoupling } from '../core/couplingAnalyzer.js';
17
- import { computePrDiff } from '../core/prDiff.js';
18
- import { detectWorkspaces, filterFilesByPackage } from '../core/monorepo.js';
19
- import { describeTelemetryConfig, aggregateTelemetry } from '../core/telemetry.js';
20
- import { loadConfig } from '../utils/config.js';
21
- import { buildSearchIndex, search as searchIndex, attachExcerpts, expandQuery } from '../core/searchIndex.js';
22
- import { buildSemanticIndex, semanticSearch, reciprocalRankFusion, } from '../core/semanticSearch.js';
23
- import { isSemanticAvailable } from '../core/embeddings.js';
24
- import { paginate, listChecksum, readPageParams } from './pagination.js';
25
- import { emitProgress } from './progress.js';
26
- import { inspectFile, extractImports, extractExports, inferPurpose, detectFileIssues, } from '../core/fileInspector.js';
27
- import { calculateScore } from '../utils/scoreCalculator.js';
28
1
  /**
29
- * A repo is "Python-dominated" if it has a pyproject.toml OR setup.py AND
30
- * either no node_modules directory or no package.json. Used by the upgrade
31
- * handler to short-circuit cleanly rather than return a confusing "not found"
32
- * for a package that would never live in node_modules to begin with.
2
+ * MCP tool registry - barrel that aggregates the per-tool modules under
3
+ * `src/mcp/tools/`. New tools live in their own file under that directory and
4
+ * are added to the `tools` array below.
5
+ *
6
+ * The shape exposed here (`getToolDefinitions`, `getToolHandler`,
7
+ * `McpToolHandler`) is consumed by `src/mcp/server.ts`. Re-export `McpTool`
8
+ * + `McpToolHandler` so external callers don't need to know about the
9
+ * directory split.
33
10
  */
34
- async function isPythonDominated(rootPath, files) {
35
- const hasPython = files.some((f) => f.extension === '.py' || f.extension === '.pyw');
36
- if (!hasPython)
37
- return false;
38
- const manifests = ['pyproject.toml', 'setup.py', 'setup.cfg'];
39
- let hasPyManifest = false;
40
- for (const m of manifests) {
41
- try {
42
- await fs.access(path.join(rootPath, m));
43
- hasPyManifest = true;
44
- break;
45
- }
46
- catch {
47
- // next
48
- }
49
- }
50
- if (!hasPyManifest)
51
- return false;
52
- try {
53
- await fs.access(path.join(rootPath, 'package.json'));
54
- return false; // has JS manifest, not Python-dominated
55
- }
56
- catch {
57
- return true;
58
- }
59
- }
60
- /**
61
- * Resolve the `package` arg to a (file -> boolean) filter, or null when
62
- * scoping wasn't requested. Returns a "rejects everything" filter when the
63
- * package name doesn't match any workspace — agents get an empty result
64
- * with a diagnostic surface rather than a confusing whole-repo response.
65
- */
66
- async function resolvePackageFilter(rootPath, args) {
67
- const name = typeof args.package === 'string' && args.package.length > 0 ? args.package : null;
68
- if (!name)
69
- return null;
70
- const ws = await detectWorkspaces(rootPath);
71
- const pkg = ws.packages.find((p) => p.name === name);
72
- if (!pkg)
73
- return () => false;
74
- if (pkg.isRoot)
75
- return () => true;
76
- const prefix = pkg.relativePath + '/';
77
- return (file) => file === pkg.relativePath || file.startsWith(prefix);
78
- }
79
- const PACKAGE_ARG_SCHEMA = {
80
- type: 'string',
81
- description: 'Optional. Workspace package name (from projscan_workspaces) to scope results to one package only.',
82
- };
83
- /** Walk a DirectoryNode tree to find the node whose `path` equals targetPath. */
84
- function sliceTree(node, targetPath) {
85
- if (node.path === targetPath)
86
- return node;
87
- for (const child of node.children) {
88
- const hit = sliceTree(child, targetPath);
89
- if (hit)
90
- return hit;
91
- }
92
- return null;
93
- }
11
+ import { analyzeTool } from './tools/analyze.js';
12
+ import { doctorTool } from './tools/doctor.js';
13
+ import { hotspotsTool } from './tools/hotspots.js';
14
+ import { explainTool } from './tools/explain.js';
15
+ import { fileTool } from './tools/file.js';
16
+ import { structureTool } from './tools/structure.js';
17
+ import { dependenciesTool } from './tools/dependencies.js';
18
+ import { outdatedTool } from './tools/outdated.js';
19
+ import { auditTool } from './tools/audit.js';
20
+ import { upgradeTool } from './tools/upgrade.js';
21
+ import { coverageTool } from './tools/coverage.js';
22
+ import { graphTool } from './tools/graph.js';
23
+ import { couplingTool } from './tools/coupling.js';
24
+ import { workspacesTool } from './tools/workspaces.js';
25
+ import { prDiffTool } from './tools/prDiff.js';
26
+ import { reviewTool } from './tools/review.js';
27
+ import { fixSuggestTool } from './tools/fixSuggest.js';
28
+ import { explainIssueTool } from './tools/explainIssue.js';
29
+ import { searchTool } from './tools/search.js';
94
30
  const tools = [
95
- {
96
- name: 'projscan_analyze',
97
- description: 'Run a full projscan analysis of the project: languages, frameworks, dependencies, issues, and health score. Use this to understand a codebase before making changes.',
98
- inputSchema: {
99
- type: 'object',
100
- properties: {
101
- package: PACKAGE_ARG_SCHEMA,
102
- },
103
- },
104
- handler: async (args, rootPath) => {
105
- emitProgress(0, 5, 'scanning repository');
106
- const scan = await scanRepository(rootPath);
107
- emitProgress(1, 5, 'detecting languages + frameworks');
108
- const languages = detectLanguages(scan.files);
109
- const frameworks = await detectFrameworks(rootPath, scan.files);
110
- emitProgress(2, 5, 'analyzing dependencies');
111
- const dependencies = await analyzeDependencies(rootPath);
112
- emitProgress(3, 5, 'running analyzers');
113
- let issues = await collectIssues(rootPath, scan.files);
114
- // 0.11 monorepo: --package scopes the issue list (analysis runs over
115
- // the whole repo; the report drops issues outside the chosen package).
116
- const passes = await resolvePackageFilter(rootPath, args);
117
- if (passes) {
118
- issues = issues.filter((i) => {
119
- const locs = i.locations ?? [];
120
- if (locs.length === 0)
121
- return false;
122
- return locs.some((l) => l.file && passes(l.file));
123
- });
124
- }
125
- emitProgress(4, 5, 'scoring');
126
- const health = calculateScore(issues);
127
- emitProgress(5, 5, 'done');
128
- const report = {
129
- projectName: path.basename(rootPath),
130
- rootPath,
131
- scan: { ...scan, files: [], directoryTree: scan.directoryTree },
132
- languages,
133
- frameworks,
134
- dependencies,
135
- issues,
136
- timestamp: new Date().toISOString(),
137
- health,
138
- };
139
- return report;
140
- },
141
- },
142
- {
143
- name: 'projscan_doctor',
144
- description: 'Run a health check on the project. Returns a 0-100 score, letter grade, and the list of issues (linting, formatting, tests, security, architecture).',
145
- inputSchema: {
146
- type: 'object',
147
- properties: {
148
- package: PACKAGE_ARG_SCHEMA,
149
- },
150
- },
151
- handler: async (args, rootPath) => {
152
- const scan = await scanRepository(rootPath);
153
- let issues = await collectIssues(rootPath, scan.files);
154
- const passes = await resolvePackageFilter(rootPath, args);
155
- if (passes) {
156
- issues = issues.filter((i) => {
157
- const locs = i.locations ?? [];
158
- if (locs.length === 0)
159
- return false;
160
- return locs.some((l) => l.file && passes(l.file));
161
- });
162
- }
163
- const health = calculateScore(issues);
164
- return {
165
- health,
166
- issues,
167
- };
168
- },
169
- },
170
- {
171
- name: 'projscan_hotspots',
172
- description: 'Rank files by risk using git churn × AST cyclomatic complexity × open issues. Returns the most dangerous files to touch. Each hotspot includes `cyclomaticComplexity` (null for non-AST languages, where line count is used as fallback). Supports cursor-based pagination: pass the `nextCursor` from a previous response back as `cursor` to fetch the next page.',
173
- inputSchema: {
174
- type: 'object',
175
- properties: {
176
- limit: {
177
- type: 'number',
178
- description: 'Cap on total hotspots ranked (default 100). For paging the returned set, use `page_size` + `cursor` instead.',
179
- },
180
- since: {
181
- type: 'string',
182
- description: 'Git history window. Examples: "12 months ago", "2024-01-01". Default: "12 months ago".',
183
- },
184
- cursor: {
185
- type: 'string',
186
- description: 'Opaque cursor from a previous response. Omit for the first page.',
187
- },
188
- page_size: {
189
- type: 'number',
190
- description: 'Items per page (default 50, max 500).',
191
- },
192
- max_tokens: {
193
- type: 'number',
194
- description: 'Cap response to roughly this many tokens.',
195
- },
196
- package: {
197
- type: 'string',
198
- description: 'Optional. Workspace package name (from projscan_workspaces) to scope hotspots to one package only.',
199
- },
200
- },
201
- },
202
- handler: async (args, rootPath) => {
203
- emitProgress(0, 5, 'scanning repository');
204
- const scan = await scanRepository(rootPath);
205
- emitProgress(1, 5, 'collecting issues');
206
- const issues = await collectIssues(rootPath, scan.files);
207
- const limit = typeof args.limit === 'number' ? args.limit : 100;
208
- const since = typeof args.since === 'string' ? args.since : undefined;
209
- emitProgress(2, 5, 'building code graph');
210
- // Graph powers AST cyclomatic complexity in the risk score (0.11).
211
- // Cache hit makes this nearly free on repeat runs.
212
- const cached = await loadCachedGraph(rootPath);
213
- const graph = await buildCodeGraph(rootPath, scan.files, cached);
214
- await saveCachedGraph(rootPath, graph);
215
- emitProgress(3, 5, 'analyzing git churn + risk');
216
- const report = await analyzeHotspots(rootPath, scan.files, issues, { limit, since, graph });
217
- // Optional --package scoping (0.13 monorepo).
218
- if (typeof args.package === 'string' && args.package.length > 0) {
219
- const ws = await detectWorkspaces(rootPath);
220
- const allowed = new Set(filterFilesByPackage(ws, args.package, report.hotspots.map((h) => h.relativePath)));
221
- report.hotspots = report.hotspots.filter((h) => allowed.has(h.relativePath));
222
- }
223
- emitProgress(4, 5, 'paginating');
224
- const page = paginate(report.hotspots, readPageParams(args), listChecksum(report.hotspots));
225
- emitProgress(5, 5, 'done');
226
- return {
227
- available: report.available,
228
- reason: report.reason,
229
- window: report.window,
230
- hotspots: page.items,
231
- totalFilesRanked: report.totalFilesRanked,
232
- nextCursor: page.nextCursor,
233
- total: page.total,
234
- };
235
- },
236
- },
237
- {
238
- name: 'projscan_explain',
239
- description: 'Explain a single file: purpose, imports, exports, and potential issues. Useful for understanding unfamiliar code before editing.',
240
- inputSchema: {
241
- type: 'object',
242
- properties: {
243
- file: {
244
- type: 'string',
245
- description: 'Path to the file relative to the project root.',
246
- },
247
- },
248
- required: ['file'],
249
- },
250
- handler: async (args, rootPath) => {
251
- const rel = typeof args.file === 'string' ? args.file : '';
252
- if (!rel)
253
- throw new Error('file argument is required');
254
- const absolutePath = path.resolve(rootPath, rel);
255
- const resolvedRoot = path.resolve(rootPath);
256
- if (!absolutePath.startsWith(resolvedRoot + path.sep) && absolutePath !== resolvedRoot) {
257
- throw new Error('file must be inside the project root');
258
- }
259
- const content = await fs.readFile(absolutePath, 'utf-8');
260
- return explainFile(absolutePath, content, rootPath);
261
- },
262
- },
263
- {
264
- name: 'projscan_file',
265
- description: 'Drill into a single file: purpose, imports, exports, churn/risk/ownership, related health issues, AST cyclomatic complexity, and coupling (fan-in / fan-out). Use this after projscan_hotspots when deciding how to approach a specific risky file.',
266
- inputSchema: {
267
- type: 'object',
268
- properties: {
269
- file: {
270
- type: 'string',
271
- description: 'Path to the file relative to the project root.',
272
- },
273
- },
274
- required: ['file'],
275
- },
276
- handler: async (args, rootPath) => {
277
- const rel = typeof args.file === 'string' ? args.file : '';
278
- if (!rel)
279
- throw new Error('file argument is required');
280
- return await inspectFile(rootPath, rel);
281
- },
282
- },
283
- {
284
- name: 'projscan_structure',
285
- description: 'Return the project directory tree with file counts.',
286
- inputSchema: {
287
- type: 'object',
288
- properties: {
289
- package: PACKAGE_ARG_SCHEMA,
290
- },
291
- },
292
- handler: async (args, rootPath) => {
293
- const scan = await scanRepository(rootPath);
294
- const pkgName = typeof args.package === 'string' && args.package.length > 0 ? args.package : null;
295
- if (!pkgName) {
296
- return { structure: scan.directoryTree, totalFiles: scan.totalFiles };
297
- }
298
- const ws = await detectWorkspaces(rootPath);
299
- const pkg = ws.packages.find((p) => p.name === pkgName);
300
- if (!pkg || pkg.isRoot || !pkg.relativePath) {
301
- return { structure: scan.directoryTree, totalFiles: scan.totalFiles };
302
- }
303
- // Walk the existing tree to find the package subdir. Returning the
304
- // sub-node preserves all the existing fileCount/totalFileCount math.
305
- const sliced = sliceTree(scan.directoryTree, pkg.relativePath);
306
- if (!sliced) {
307
- return {
308
- structure: { name: pkg.name, path: pkg.relativePath, children: [], fileCount: 0, totalFileCount: 0 },
309
- totalFiles: 0,
310
- };
311
- }
312
- return { structure: sliced, totalFiles: sliced.totalFileCount };
313
- },
314
- },
315
- {
316
- name: 'projscan_dependencies',
317
- description: 'Analyze package.json dependencies and return counts and risks (deprecated packages, wildcard versions, etc.).',
318
- inputSchema: {
319
- type: 'object',
320
- properties: {},
321
- },
322
- handler: async (_args, rootPath) => {
323
- const report = await analyzeDependencies(rootPath);
324
- if (!report)
325
- return { available: false, reason: 'No package.json found' };
326
- return { available: true, ...report };
327
- },
328
- },
329
- {
330
- name: 'projscan_outdated',
331
- description: 'Compare declared vs installed versions of every package. Reports drift (patch/minor/major). Offline - does not hit the npm registry. Supports cursor pagination.',
332
- inputSchema: {
333
- type: 'object',
334
- properties: {
335
- cursor: { type: 'string', description: 'Opaque cursor from a previous response.' },
336
- page_size: { type: 'number', description: 'Items per page (default 50).' },
337
- max_tokens: { type: 'number', description: 'Cap response size.' },
338
- },
339
- },
340
- handler: async (args, rootPath) => {
341
- const report = await detectOutdated(rootPath);
342
- if (!report.available)
343
- return report;
344
- const page = paginate(report.packages, readPageParams(args), listChecksum(report.packages));
345
- return {
346
- available: true,
347
- totalPackages: report.totalPackages,
348
- packages: page.items,
349
- total: page.total,
350
- nextCursor: page.nextCursor,
351
- };
352
- },
353
- },
354
- {
355
- name: 'projscan_audit',
356
- description: 'Run `npm audit` and return a normalized summary of vulnerabilities (critical / high / moderate / low / info). Requires package-lock.json. Supports cursor pagination on the findings array.',
357
- inputSchema: {
358
- type: 'object',
359
- properties: {
360
- cursor: { type: 'string', description: 'Opaque cursor from a previous response.' },
361
- page_size: { type: 'number', description: 'Items per page (default 50).' },
362
- max_tokens: { type: 'number', description: 'Cap response size.' },
363
- },
364
- },
365
- handler: async (args, rootPath) => {
366
- emitProgress(0, 2, 'running npm audit');
367
- const report = await runAudit(rootPath);
368
- if (!report.available)
369
- return report;
370
- emitProgress(1, 2, 'normalizing findings');
371
- const page = paginate(report.findings, readPageParams(args), listChecksum(report.findings));
372
- emitProgress(2, 2, 'done');
373
- return {
374
- available: true,
375
- summary: report.summary,
376
- findings: page.items,
377
- total: page.total,
378
- nextCursor: page.nextCursor,
379
- };
380
- },
381
- },
382
- {
383
- name: 'projscan_upgrade',
384
- description: 'Preview the impact of upgrading a package: semver drift, breaking-change markers from the local CHANGELOG, and the files in your repo that import it. Offline.',
385
- inputSchema: {
386
- type: 'object',
387
- properties: {
388
- package: {
389
- type: 'string',
390
- description: 'Name of the package to preview.',
391
- },
392
- },
393
- required: ['package'],
394
- },
395
- handler: async (args, rootPath) => {
396
- const pkgName = typeof args.package === 'string' ? args.package : '';
397
- if (!pkgName)
398
- throw new Error('package argument is required');
399
- const scan = await scanRepository(rootPath);
400
- // Python-dominated repos have no node_modules CHANGELOG to slice.
401
- // Short-circuit with a clear reason rather than returning
402
- // available:false with a misleading "not found" message.
403
- if (await isPythonDominated(rootPath, scan.files)) {
404
- return {
405
- available: false,
406
- reason: 'Upgrade preview is currently supported only for Node.js packages. Python support is planned for a future release.',
407
- name: pkgName,
408
- declared: null,
409
- installed: null,
410
- latest: null,
411
- drift: 'unknown',
412
- breakingMarkers: [],
413
- importers: [],
414
- };
415
- }
416
- return await previewUpgrade(rootPath, pkgName, scan.files);
417
- },
418
- },
419
- {
420
- name: 'projscan_coverage',
421
- description: 'Join test coverage with hotspot risk. Returns files ranked by "risk × uncovered fraction" - the scariest untested files. Requires a coverage file at coverage/lcov.info, coverage/coverage-final.json, or coverage/coverage-summary.json.',
422
- inputSchema: {
423
- type: 'object',
424
- properties: {
425
- limit: {
426
- type: 'number',
427
- description: 'How many entries to return (default: 30, max: 200).',
428
- },
429
- max_tokens: {
430
- type: 'number',
431
- description: 'Cap the response size to roughly this many tokens (~4 chars/token). Truncates the entries array to fit.',
432
- },
433
- package: PACKAGE_ARG_SCHEMA,
434
- },
435
- },
436
- handler: async (args, rootPath) => {
437
- const coverage = await parseCoverage(rootPath);
438
- const scan = await scanRepository(rootPath);
439
- const issues = await collectIssues(rootPath, scan.files);
440
- const rawLimit = typeof args.limit === 'number' ? args.limit : 200;
441
- const limit = Math.max(1, Math.min(500, rawLimit));
442
- const hotspots = await analyzeHotspots(rootPath, scan.files, issues, {
443
- limit,
444
- coverage: coverage.available ? coverageMap(coverage) : undefined,
445
- });
446
- const joined = joinCoverageWithHotspots(hotspots, coverage);
447
- if (!joined.available)
448
- return joined;
449
- const passes = await resolvePackageFilter(rootPath, args);
450
- const filteredEntries = passes
451
- ? joined.entries.filter((e) => passes(e.relativePath))
452
- : joined.entries;
453
- const page = paginate(filteredEntries, readPageParams(args), listChecksum(filteredEntries));
454
- return {
455
- available: true,
456
- coverageSource: joined.coverageSource,
457
- coverageSourceFile: joined.coverageSourceFile,
458
- entries: page.items,
459
- total: page.total,
460
- nextCursor: page.nextCursor,
461
- };
462
- },
463
- },
464
- {
465
- name: 'projscan_graph',
466
- description: 'Query the AST-based code graph directly. Returns imports, exports, importers, or symbol definitions for a file or symbol. Agents should prefer this over analyze/doctor/explain for targeted structural questions - it is much cheaper and more accurate.',
467
- inputSchema: {
468
- type: 'object',
469
- properties: {
470
- file: {
471
- type: 'string',
472
- description: 'File path (relative to project root) to query.',
473
- },
474
- symbol: {
475
- type: 'string',
476
- description: 'Symbol name to query (e.g. a function or class). Use instead of `file` to find where a symbol is defined.',
477
- },
478
- direction: {
479
- type: 'string',
480
- description: 'What to return: "imports" (what the file imports), "exports" (what the file exports), "importers" (who imports the file), "symbol_defs" (files defining the symbol), "package_importers" (files importing a package by name).',
481
- enum: ['imports', 'exports', 'importers', 'symbol_defs', 'package_importers'],
482
- },
483
- limit: {
484
- type: 'number',
485
- description: 'Max entries returned (default 50).',
486
- },
487
- max_tokens: {
488
- type: 'number',
489
- description: 'Cap the response to roughly this many tokens.',
490
- },
491
- },
492
- required: ['direction'],
493
- },
494
- handler: async (args, rootPath) => {
495
- const scan = await scanRepository(rootPath);
496
- const cached = await loadCachedGraph(rootPath);
497
- const graph = await buildCodeGraph(rootPath, scan.files, cached);
498
- await saveCachedGraph(rootPath, graph);
499
- const direction = String(args.direction);
500
- const file = typeof args.file === 'string' ? args.file : undefined;
501
- const symbol = typeof args.symbol === 'string' ? args.symbol : undefined;
502
- const limit = Math.max(1, Math.min(500, typeof args.limit === 'number' ? args.limit : 50));
503
- switch (direction) {
504
- case 'imports': {
505
- if (!file)
506
- throw new Error('file argument is required for direction=imports');
507
- return { file, imports: importsOf(graph, file).slice(0, limit) };
508
- }
509
- case 'exports': {
510
- if (!file)
511
- throw new Error('file argument is required for direction=exports');
512
- return { file, exports: exportsOf(graph, file).slice(0, limit) };
513
- }
514
- case 'importers': {
515
- if (!file)
516
- throw new Error('file argument is required for direction=importers');
517
- return { file, importers: filesImportingFile(graph, file).slice(0, limit) };
518
- }
519
- case 'symbol_defs': {
520
- if (!symbol)
521
- throw new Error('symbol argument is required for direction=symbol_defs');
522
- return { symbol, definedIn: filesDefiningSymbol(graph, symbol).slice(0, limit) };
523
- }
524
- case 'package_importers': {
525
- const pkg = symbol ?? file;
526
- if (!pkg)
527
- throw new Error('symbol (or file) argument is required for direction=package_importers');
528
- return { package: pkg, importers: filesImportingPackage(graph, pkg).slice(0, limit) };
529
- }
530
- default:
531
- throw new Error(`unknown direction: ${direction}`);
532
- }
533
- },
534
- },
535
- {
536
- name: 'projscan_coupling',
537
- description: 'Per-file coupling metrics (fan-in, fan-out, instability) and circular-import cycles, derived from the AST code graph. Use `direction` to focus the result: "all" returns every file sorted by fan-in; "high_fan_in" / "high_fan_out" sort accordingly; "cycles_only" returns just the files participating in import cycles. Cycles are reported separately as strongly-connected components of size >= 2.',
538
- inputSchema: {
539
- type: 'object',
540
- properties: {
541
- file: {
542
- type: 'string',
543
- description: 'Optional. When set, the response includes only this file\'s coupling row (cycles list still returned in full).',
544
- },
545
- direction: {
546
- type: 'string',
547
- description: 'Filter/sort applied to `files`. Default "all".',
548
- enum: ['all', 'high_fan_in', 'high_fan_out', 'cycles_only'],
549
- },
550
- limit: {
551
- type: 'number',
552
- description: 'Max file rows returned (default 25, max 500).',
553
- },
554
- max_tokens: {
555
- type: 'number',
556
- description: 'Cap the response to roughly this many tokens.',
557
- },
558
- package: {
559
- type: 'string',
560
- description: 'Optional. Workspace package name (from projscan_workspaces) to scope coupling rows to one package only.',
561
- },
562
- },
563
- },
564
- handler: async (args, rootPath) => {
565
- emitProgress(0, 3, 'building code graph');
566
- const scan = await scanRepository(rootPath);
567
- const cached = await loadCachedGraph(rootPath);
568
- const graph = await buildCodeGraph(rootPath, scan.files, cached);
569
- await saveCachedGraph(rootPath, graph);
570
- emitProgress(1, 3, 'computing coupling + cycles');
571
- // Cross-package edges only meaningful in monorepos. detectWorkspaces
572
- // returns kind='none' otherwise; computeCoupling no-ops the section.
573
- const ws = await detectWorkspaces(rootPath);
574
- const report = computeCoupling(graph, ws);
575
- const direction = (typeof args.direction === 'string' ? args.direction : 'all');
576
- const limit = Math.max(1, Math.min(500, typeof args.limit === 'number' ? args.limit : 25));
577
- const file = typeof args.file === 'string' ? args.file : undefined;
578
- let files = filterCoupling(report, direction);
579
- if (file)
580
- files = files.filter((f) => f.relativePath === file);
581
- if (typeof args.package === 'string' && args.package.length > 0) {
582
- const ws = await detectWorkspaces(rootPath);
583
- const allowed = new Set(filterFilesByPackage(ws, args.package, files.map((f) => f.relativePath)));
584
- files = files.filter((f) => allowed.has(f.relativePath));
585
- }
586
- files = files.slice(0, limit);
587
- emitProgress(2, 3, 'paginating');
588
- const page = paginate(files, readPageParams(args), listChecksum(files));
589
- emitProgress(3, 3, 'done');
590
- return {
591
- files: page.items,
592
- cycles: report.cycles,
593
- crossPackageEdges: report.crossPackageEdges,
594
- totalFiles: report.totalFiles,
595
- totalCycles: report.totalCycles,
596
- totalCrossPackageEdges: report.totalCrossPackageEdges,
597
- nextCursor: page.nextCursor,
598
- total: page.total,
599
- };
600
- },
601
- },
602
- {
603
- name: 'projscan_telemetry',
604
- description: 'Inspect projscan telemetry state: whether it is enabled, where events are written, and what overrides are active. Telemetry is opt-in (off by default), records only tool name + duration + success/version/timestamp (never source content or paths), and writes to a local JSONL file the user controls. Pass `aggregate: true` to read the sink and return per-tool latency histograms (count, p50/p95/p99, error rate) instead of just the config.',
605
- inputSchema: {
606
- type: 'object',
607
- properties: {
608
- aggregate: {
609
- type: 'boolean',
610
- description: 'When true, read the sink and return per-tool histograms instead of just config state.',
611
- },
612
- },
613
- },
614
- handler: async (args, rootPath) => {
615
- const { config } = await loadConfig(rootPath);
616
- if (args.aggregate === true) {
617
- return await aggregateTelemetry(config.telemetry);
618
- }
619
- return describeTelemetryConfig(config.telemetry);
620
- },
621
- },
622
- {
623
- name: 'projscan_workspaces',
624
- description: 'List monorepo workspace packages (npm/yarn workspaces, pnpm-workspace.yaml, Nx/Turbo/Lerna fallback). Returns one row per package with name, relative path, and version. Use the package `name` as the `package` argument on projscan_hotspots / projscan_coupling to scope those tools to a single package.',
625
- inputSchema: {
626
- type: 'object',
627
- properties: {},
628
- },
629
- handler: async (_args, rootPath) => {
630
- return await detectWorkspaces(rootPath);
631
- },
632
- },
633
- {
634
- name: 'projscan_pr_diff',
635
- description: 'Structural (AST) diff between two refs — what changed in exports, imports, call sites, cyclomatic complexity, and fan-in. Not a text diff: this surfaces the symbols and edges that an agent reviewing a PR actually cares about. Defaults: base=origin/main (falls back to main/master/HEAD~1), head=HEAD. Spins up a throwaway git worktree at the base ref to get a clean second graph.',
636
- inputSchema: {
637
- type: 'object',
638
- properties: {
639
- base: {
640
- type: 'string',
641
- description: 'Base ref (branch, tag, sha). Default: origin/main, falling back to main/master/HEAD~1.',
642
- },
643
- head: {
644
- type: 'string',
645
- description: 'Head ref. Default: HEAD.',
646
- },
647
- max_tokens: {
648
- type: 'number',
649
- description: 'Cap the response to roughly this many tokens.',
650
- },
651
- package: PACKAGE_ARG_SCHEMA,
652
- },
653
- },
654
- handler: async (args, rootPath) => {
655
- emitProgress(0, 3, 'resolving refs');
656
- const base = typeof args.base === 'string' ? args.base : undefined;
657
- const head = typeof args.head === 'string' ? args.head : undefined;
658
- emitProgress(1, 3, 'building base + head graphs');
659
- const report = await computePrDiff(rootPath, { base, head });
660
- emitProgress(2, 3, 'diffing');
661
- const passes = await resolvePackageFilter(rootPath, args);
662
- if (passes) {
663
- report.filesAdded = report.filesAdded.filter(passes);
664
- report.filesRemoved = report.filesRemoved.filter(passes);
665
- report.filesModified = report.filesModified.filter((f) => passes(f.relativePath));
666
- report.totalFilesChanged =
667
- report.filesAdded.length + report.filesRemoved.length + report.filesModified.length;
668
- }
669
- emitProgress(3, 3, 'done');
670
- return report;
671
- },
672
- },
673
- {
674
- name: 'projscan_search',
675
- description: 'Ranked search across the project. Lexical (BM25) by default; optional semantic (vector) and hybrid (RRF fusion) modes available when the @xenova/transformers peer dependency is installed. Scope controls what to search: "auto"/"content" (ranked content matches with excerpts), "symbols" (exported names), "files" (path substring).',
676
- inputSchema: {
677
- type: 'object',
678
- properties: {
679
- query: {
680
- type: 'string',
681
- description: 'Search string. Multi-word queries are treated as OR across BM25 terms; semantic mode embeds the full query.',
682
- },
683
- scope: {
684
- type: 'string',
685
- description: 'What to search over: "auto" (= content), "symbols", "files", "content".',
686
- enum: ['auto', 'symbols', 'files', 'content'],
687
- },
688
- mode: {
689
- type: 'string',
690
- description: '"lexical" (default, BM25) | "semantic" (embeddings, requires peer dep) | "hybrid" (BM25 + semantic via reciprocal rank fusion). Ignored for "symbols" and "files" scopes.',
691
- enum: ['lexical', 'semantic', 'hybrid'],
692
- },
693
- limit: {
694
- type: 'number',
695
- description: 'Max matches returned (default 30).',
696
- },
697
- max_tokens: {
698
- type: 'number',
699
- description: 'Cap the response to roughly this many tokens.',
700
- },
701
- package: PACKAGE_ARG_SCHEMA,
702
- },
703
- required: ['query'],
704
- },
705
- handler: async (args, rootPath) => {
706
- const query = String(args.query ?? '').trim();
707
- if (!query)
708
- throw new Error('query argument is required and must be non-empty');
709
- const scope = String(args.scope ?? 'auto');
710
- const limit = Math.max(1, Math.min(500, typeof args.limit === 'number' ? args.limit : 30));
711
- const scan = await scanRepository(rootPath);
712
- const cached = await loadCachedGraph(rootPath);
713
- const graph = await buildCodeGraph(rootPath, scan.files, cached);
714
- await saveCachedGraph(rootPath, graph);
715
- const passes = await resolvePackageFilter(rootPath, args);
716
- // Files scope - simple substring scan; ranking adds no value
717
- if (scope === 'files') {
718
- const q = query.toLowerCase();
719
- const all = scan.files
720
- .filter((f) => f.relativePath.toLowerCase().includes(q))
721
- .filter((f) => !passes || passes(f.relativePath))
722
- .map((f) => ({ file: f.relativePath, sizeBytes: f.sizeBytes }));
723
- const page = paginate(all, readPageParams(args), listChecksum(all));
724
- return { scope, query, matches: page.items, total: page.total, nextCursor: page.nextCursor };
725
- }
726
- // Symbols scope - walk the graph's export table; rank exact/prefix/substring
727
- if (scope === 'symbols') {
728
- const q = query.toLowerCase();
729
- const rawMatches = [];
730
- for (const [file, entry] of graph.files) {
731
- if (passes && !passes(file))
732
- continue;
733
- for (const exp of entry.exports) {
734
- const name = exp.name.toLowerCase();
735
- if (!name.includes(q))
736
- continue;
737
- const rank = name === q ? 0 : name.startsWith(q) ? 1 : 2;
738
- rawMatches.push({ symbol: exp.name, kind: exp.kind, file, line: exp.line, rank });
739
- }
740
- }
741
- rawMatches.sort((a, b) => a.rank - b.rank);
742
- const cleaned = rawMatches.map((m) => ({
743
- symbol: m.symbol,
744
- kind: m.kind,
745
- file: m.file,
746
- line: m.line,
747
- }));
748
- const page = paginate(cleaned, readPageParams(args), listChecksum(cleaned));
749
- return { scope, query, matches: page.items, total: page.total, nextCursor: page.nextCursor };
750
- }
751
- // Content or auto scope - lexical BM25 by default, optionally semantic or hybrid
752
- const mode = String(args.mode ?? 'lexical');
753
- const index = await buildSearchIndex(rootPath, scan.files, graph);
754
- const lexicalHitsAll = searchIndex(index, query, { limit });
755
- const lexicalHits = passes ? lexicalHitsAll.filter((h) => passes(h.file)) : lexicalHitsAll;
756
- const tokens = expandQuery(query);
757
- if (mode === 'lexical') {
758
- const withExcerpts = await attachExcerpts(rootPath, lexicalHits, tokens);
759
- const page = paginate(withExcerpts, readPageParams(args), listChecksum(withExcerpts));
760
- return {
761
- scope: scope === 'auto' ? 'content' : scope,
762
- mode: 'lexical',
763
- query,
764
- queryTokens: tokens,
765
- matches: page.items,
766
- total: page.total,
767
- nextCursor: page.nextCursor,
768
- };
769
- }
770
- // Semantic or hybrid - both require the peer
771
- const hasSemantic = await isSemanticAvailable();
772
- if (!hasSemantic) {
773
- return {
774
- scope: scope === 'auto' ? 'content' : scope,
775
- mode,
776
- query,
777
- error: 'Semantic search requires the optional peer dependency @xenova/transformers. Install it with: npm install @xenova/transformers',
778
- available: false,
779
- matches: [],
780
- total: 0,
781
- };
782
- }
783
- const semIndex = await buildSemanticIndex(rootPath, scan.files);
784
- if (!semIndex) {
785
- return {
786
- scope: scope === 'auto' ? 'content' : scope,
787
- mode,
788
- query,
789
- error: 'Semantic index build failed (peer loaded but model not usable).',
790
- available: false,
791
- matches: [],
792
- total: 0,
793
- };
794
- }
795
- const semHitsAll = await semanticSearch(semIndex, query, { limit });
796
- const semHits = passes ? semHitsAll.filter((h) => passes(h.file)) : semHitsAll;
797
- if (mode === 'semantic') {
798
- const enriched = await attachExcerpts(rootPath, semHits.map((h) => ({
799
- file: h.file,
800
- score: h.score,
801
- matched: [],
802
- symbolMatch: false,
803
- pathMatch: false,
804
- excerpt: '',
805
- line: 0,
806
- })), tokens);
807
- const page = paginate(enriched, readPageParams(args), listChecksum(enriched));
808
- return {
809
- scope: scope === 'auto' ? 'content' : scope,
810
- mode: 'semantic',
811
- query,
812
- model: semIndex.model,
813
- matches: page.items,
814
- total: page.total,
815
- nextCursor: page.nextCursor,
816
- };
817
- }
818
- // Hybrid - reciprocal rank fusion
819
- const fused = reciprocalRankFusion([lexicalHits, semHits]).slice(0, limit);
820
- const enriched = await attachExcerpts(rootPath, fused.map((f) => ({
821
- file: f.file,
822
- score: f.score,
823
- matched: [],
824
- symbolMatch: false,
825
- pathMatch: false,
826
- excerpt: '',
827
- line: 0,
828
- })), tokens);
829
- const page = paginate(enriched, readPageParams(args), listChecksum(enriched));
830
- return {
831
- scope: scope === 'auto' ? 'content' : scope,
832
- mode: 'hybrid',
833
- query,
834
- queryTokens: tokens,
835
- model: semIndex.model,
836
- matches: page.items,
837
- total: page.total,
838
- nextCursor: page.nextCursor,
839
- };
840
- },
841
- },
31
+ analyzeTool,
32
+ doctorTool,
33
+ hotspotsTool,
34
+ explainTool,
35
+ fileTool,
36
+ structureTool,
37
+ dependenciesTool,
38
+ outdatedTool,
39
+ auditTool,
40
+ upgradeTool,
41
+ coverageTool,
42
+ graphTool,
43
+ couplingTool,
44
+ workspacesTool,
45
+ prDiffTool,
46
+ reviewTool,
47
+ fixSuggestTool,
48
+ explainIssueTool,
49
+ searchTool,
842
50
  ];
843
51
  export function getToolDefinitions() {
844
52
  return tools.map(({ name, description, inputSchema }) => ({ name, description, inputSchema }));
@@ -846,20 +54,4 @@ export function getToolDefinitions() {
846
54
  export function getToolHandler(name) {
847
55
  return tools.find((t) => t.name === name)?.handler;
848
56
  }
849
- // ── File Explanation (used by projscan_explain) ──────────
850
- function explainFile(absolutePath, content, rootPath) {
851
- const lines = content.split('\n');
852
- const imports = extractImports(content);
853
- const exports = extractExports(content);
854
- const purpose = inferPurpose(absolutePath, exports);
855
- const potentialIssues = detectFileIssues(content, lines.length);
856
- return {
857
- filePath: path.relative(rootPath, absolutePath),
858
- purpose,
859
- imports,
860
- exports,
861
- potentialIssues,
862
- lineCount: lines.length,
863
- };
864
- }
865
57
  //# sourceMappingURL=tools.js.map